aboutsummaryrefslogtreecommitdiff
path: root/docs/examples
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2014-01-01 18:31:42 +0000
committerSteve Holme <steve_holme@hotmail.com>2014-01-01 18:44:53 +0000
commit0757a9b941f2f14622a9c3ee345cd967dc2521ba (patch)
treeb5f220d9f57c52810824da8da3d7b5c866c61cc2 /docs/examples
parent83ae98c6c62fc19538b7b936439d3ebf5e9cca0e (diff)
examples: Update SMTP TLS example mail content to be RFC-2821 compliant
...and made some minor coding style changes to better match the curl coding standards as well as the other email related examples.
Diffstat (limited to 'docs/examples')
-rw-r--r--docs/examples/smtp-tls.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c
index 072d6b0f5..1ab7e205b 100644
--- a/docs/examples/smtp-tls.c
+++ b/docs/examples/smtp-tls.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -32,18 +32,18 @@
#define TO "<addressee@example.net>"
#define CC "<info@example.org>"
-static const char *payload_text[]={
- "Date: Mon, 29 Nov 2010 21:54:29 +1100\n",
- "To: " TO "\n",
- "From: " FROM "(Example User)\n",
- "Cc: " CC "(Another example User)\n",
- "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\n",
- "Subject: SMTP TLS example message\n",
- "\n", /* empty line to divide headers from body, see RFC5322 */
- "The body of the message starts here.\n",
- "\n",
- "It could be a lot of lines, could be MIME encoded, whatever.\n",
- "Check RFC5322.\n",
+static const char *payload_text[] = {
+ "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n",
+ "To: " TO "\r\n",
+ "From: " FROM "(Example User)\r\n",
+ "Cc: " CC "(Another example User)\r\n",
+ "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n",
+ "Subject: SMTP TLS example message\r\n",
+ "\r\n", /* empty line to divide headers from body, see RFC5322 */
+ "The body of the message starts here.\r\n",
+ "\r\n",
+ "It could be a lot of lines, could be MIME encoded, whatever.\r\n",
+ "Check RFC5322.\r\n",
NULL
};
@@ -56,25 +56,27 @@ static size_t payload_source(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)) {
+ if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
return 0;
}
data = payload_text[upload_ctx->lines_read];
- if (data) {
+ if(data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
- upload_ctx->lines_read ++;
+ upload_ctx->lines_read++;
+
return len;
}
+
return 0;
}
int main(void)
{
CURL *curl;
- CURLcode res;
+ CURLcode res = CURLE_OK;
struct curl_slist *recipients = NULL;
struct upload_status upload_ctx;
@@ -105,8 +107,7 @@ int main(void)
* Instead, you should get the issuer certificate (or the host certificate
* if the certificate is self-signed) and add it to the set of certificates
* that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See
- * docs/SSLCERTS for more information.
- */
+ * docs/SSLCERTS for more information. */
curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");
/* A common reason for requiring transport security is to protect
@@ -115,7 +116,7 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_USERNAME, "user@example.net");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "P@ssw0rd");
- /* value for envelope reverse-path */
+ /* Value for envelope reverse-path */
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
/* Add two recipients, in this particular case they correspond to the
@@ -127,8 +128,7 @@ int main(void)
/* In this case, we're using a callback function to specify the data. You
* could just use the CURLOPT_READDATA option to specify a FILE pointer to
- * read from.
- */
+ * read from. */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
@@ -138,17 +138,20 @@ int main(void)
*/
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
- /* send the message (including headers) */
+ /* Send the message */
res = curl_easy_perform(curl);
+
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
- /* free the list of recipients and clean up */
+ /* Free the list of recipients */
curl_slist_free_all(recipients);
+
+ /* Always cleanup */
curl_easy_cleanup(curl);
}
- return 0;
+ return (int)res;
}