2014-12-28 07:12:09 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2020-03-23 09:44:29 -04:00
|
|
|
* Copyright (C) 2014 - 2020, Steve Holme, <steve_holme@hotmail.com>.
|
2014-12-28 07:12:09 -05:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2014-12-28 07:12:09 -05:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the list of basic details you need to tweak to get things right.
|
|
|
|
*/
|
2014-12-28 07:46:17 -05:00
|
|
|
#define TO "<recipient@example.com>"
|
2014-12-28 07:12:09 -05:00
|
|
|
#define FROM "<sender@example.com>"
|
|
|
|
|
|
|
|
static const char *payload_text[] = {
|
2014-12-28 08:01:11 -05:00
|
|
|
"From: different\r\n",
|
|
|
|
"To: another\r\n",
|
|
|
|
"\r\n",
|
|
|
|
"\r\n",
|
|
|
|
".\r\n",
|
|
|
|
".\r\n",
|
|
|
|
"\r\n",
|
|
|
|
".\r\n",
|
|
|
|
"\r\n",
|
|
|
|
"body",
|
|
|
|
NULL
|
2014-12-28 07:12:09 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct upload_status {
|
|
|
|
int lines_read;
|
|
|
|
};
|
|
|
|
|
|
|
|
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
|
|
|
|
{
|
|
|
|
struct upload_status *upload_ctx = (struct upload_status *)userp;
|
|
|
|
const char *data;
|
|
|
|
|
|
|
|
if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = payload_text[upload_ctx->lines_read];
|
|
|
|
|
|
|
|
if(data) {
|
|
|
|
size_t len = strlen(data);
|
|
|
|
memcpy(ptr, data, len);
|
|
|
|
upload_ctx->lines_read++;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
2014-12-28 07:46:17 -05:00
|
|
|
CURLcode res;
|
2014-12-28 07:12:09 -05:00
|
|
|
CURL *curl;
|
2014-12-28 07:46:17 -05:00
|
|
|
struct curl_slist *rcpt_list = NULL;
|
|
|
|
struct upload_status upload_ctx = {0};
|
2014-12-28 07:12:09 -05:00
|
|
|
|
|
|
|
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
|
|
|
fprintf(stderr, "curl_global_init() failed\n");
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
2016-12-13 19:29:44 -05:00
|
|
|
curl = curl_easy_init();
|
|
|
|
if(!curl) {
|
2014-12-28 07:12:09 -05:00
|
|
|
fprintf(stderr, "curl_easy_init() failed\n");
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
rcpt_list = curl_slist_append(rcpt_list, TO);
|
|
|
|
/* more addresses can be added here
|
|
|
|
rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>");
|
|
|
|
*/
|
|
|
|
|
|
|
|
test_setopt(curl, CURLOPT_URL, URL);
|
|
|
|
test_setopt(curl, CURLOPT_UPLOAD, 1L);
|
|
|
|
test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
|
|
|
|
test_setopt(curl, CURLOPT_READDATA, &upload_ctx);
|
|
|
|
test_setopt(curl, CURLOPT_MAIL_FROM, FROM);
|
|
|
|
test_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
|
|
|
|
test_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
|
|
|
test_cleanup:
|
|
|
|
|
2014-12-28 08:01:11 -05:00
|
|
|
curl_slist_free_all(rcpt_list);
|
2014-12-28 07:12:09 -05:00
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
|
|
|
return (int)res;
|
|
|
|
}
|