From e9625c5bc6c046a7fbd90149ee48ecfd7e1c8564 Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Tue, 31 Dec 2013 15:45:15 +0000 Subject: examples: Rename before adding additional email examples --- docs/examples/Makefile.inc | 4 +- docs/examples/imap-fetch.c | 44 +++++++++++++++++++++ docs/examples/imap.c | 44 --------------------- docs/examples/simplesmtp.c | 88 ------------------------------------------ docs/examples/smtp-send.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++ docs/examples/smtp-tls.c | 4 +- 6 files changed, 143 insertions(+), 136 deletions(-) create mode 100644 docs/examples/imap-fetch.c delete mode 100644 docs/examples/imap.c delete mode 100644 docs/examples/simplesmtp.c create mode 100644 docs/examples/smtp-send.c (limited to 'docs') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 11b508c26..69f2994ec 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,8 +4,8 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ - smtp-multi simplesmtp smtp-tls smtp-vrfy smtp-expn rtsp externalsocket \ - resolve progressfunc pop3s pop3slist imap url2file sftpget ftpsget \ + smtp-multi smtp-send smtp-tls smtp-vrfy smtp-expn rtsp externalsocket \ + resolve progressfunc pop3s pop3slist imap-fetch url2file sftpget ftpsget \ postinmemory # These examples require external dependencies that may not be commonly diff --git a/docs/examples/imap-fetch.c b/docs/examples/imap-fetch.c new file mode 100644 index 000000000..ba07f022a --- /dev/null +++ b/docs/examples/imap-fetch.c @@ -0,0 +1,44 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * 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 +#include + +int main(void) +{ + CURL *curl; + CURLcode res = CURLE_OK; + + curl = curl_easy_init(); + if(curl) { + /* Set username and password */ + curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password"); + + /* This will fetch the mailbox named "foobar" */ + curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/foobar"); + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return (int)res; +} diff --git a/docs/examples/imap.c b/docs/examples/imap.c deleted file mode 100644 index ba07f022a..000000000 --- a/docs/examples/imap.c +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. - * - * 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 -#include - -int main(void) -{ - CURL *curl; - CURLcode res = CURLE_OK; - - curl = curl_easy_init(); - if(curl) { - /* Set username and password */ - curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password"); - - /* This will fetch the mailbox named "foobar" */ - curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/foobar"); - - res = curl_easy_perform(curl); - - /* always cleanup */ - curl_easy_cleanup(curl); - } - return (int)res; -} diff --git a/docs/examples/simplesmtp.c b/docs/examples/simplesmtp.c deleted file mode 100644 index b10fdc003..000000000 --- a/docs/examples/simplesmtp.c +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2013, Daniel Stenberg, , et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. - * - * 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 -#include -#include - -int main(void) -{ - CURL *curl; - CURLcode res; - struct curl_slist *recipients = NULL; - - /* value for envelope reverse-path */ - static const char *from = ""; - - /* this becomes the envelope forward-path */ - static const char *to = ""; - - curl = curl_easy_init(); - if(curl) { - /* this is the URL for your mailserver - you can also use an smtps:// URL - * here */ - curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.net."); - - /* Note that this option isn't strictly required, omitting it will result in - * libcurl will sent the MAIL FROM command with no sender data. All - * autoresponses should have an empty reverse-path, and should be directed - * to the address in the reverse-path which triggered them. Otherwise, they - * could cause an endless loop. See RFC 5321 Section 4.5.5 for more details. - */ - curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); - - /* Note that the CURLOPT_MAIL_RCPT takes a list, not a char array. */ - recipients = curl_slist_append(recipients, to); - curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); - - /* You provide the payload (headers and the body of the message) as the - * "data" element. There are two choices, either: - * - provide a callback function and specify the function name using the - * CURLOPT_READFUNCTION option; or - * - just provide a FILE pointer that can be used to read the data from. - * The easiest case is just to read from standard input, (which is available - * as a FILE pointer) as shown here. - */ - curl_easy_setopt(curl, CURLOPT_READDATA, stdin); - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); - - /* send the message (including headers) */ - 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 */ - curl_slist_free_all(recipients); - - /* curl won't send the QUIT command until you call cleanup, so you should be - * able to re-use this connection for additional messages (setting - * CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling - * curl_easy_perform() again. It may not be a good idea to keep the - * connection open for a very long time though (more than a few minutes may - * result in the server timing out the connection), and you do want to clean - * up in the end. - */ - curl_easy_cleanup(curl); - } - return 0; -} diff --git a/docs/examples/smtp-send.c b/docs/examples/smtp-send.c new file mode 100644 index 000000000..f343238d4 --- /dev/null +++ b/docs/examples/smtp-send.c @@ -0,0 +1,95 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2013, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * 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 +#include +#include + +/* This is a simple example showing how to send mail using libcurl's SMTP + * capabilities. For an exmaple of using the multi interface please see + * smtp-multi.c. + */ + +int main(void) +{ + CURL *curl; + CURLcode res; + struct curl_slist *recipients = NULL; + + /* value for envelope reverse-path */ + static const char *from = ""; + + /* this becomes the envelope forward-path */ + static const char *to = ""; + + curl = curl_easy_init(); + if(curl) { + /* this is the URL for your mailserver - you can also use an smtps:// URL + * here */ + curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.net."); + + /* Note that this option isn't strictly required, omitting it will result in + * libcurl will sent the MAIL FROM command with no sender data. All + * autoresponses should have an empty reverse-path, and should be directed + * to the address in the reverse-path which triggered them. Otherwise, they + * could cause an endless loop. See RFC 5321 Section 4.5.5 for more details. + */ + curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); + + /* Note that the CURLOPT_MAIL_RCPT takes a list, not a char array. */ + recipients = curl_slist_append(recipients, to); + curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); + + /* You provide the payload (headers and the body of the message) as the + * "data" element. There are two choices, either: + * - provide a callback function and specify the function name using the + * CURLOPT_READFUNCTION option; or + * - just provide a FILE pointer that can be used to read the data from. + * The easiest case is just to read from standard input, (which is available + * as a FILE pointer) as shown here. + */ + curl_easy_setopt(curl, CURLOPT_READDATA, stdin); + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + + /* send the message (including headers) */ + 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 */ + curl_slist_free_all(recipients); + + /* curl won't send the QUIT command until you call cleanup, so you should be + * able to re-use this connection for additional messages (setting + * CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling + * curl_easy_perform() again. It may not be a good idea to keep the + * connection open for a very long time though (more than a few minutes may + * result in the server timing out the connection), and you do want to clean + * up in the end. + */ + curl_easy_cleanup(curl); + } + + return 0; +} diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index 0356500ef..072d6b0f5 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -24,7 +24,7 @@ #include /* This is a simple example showing how to send mail using libcurl's SMTP - * capabilities. It builds on the simplesmtp.c example, adding some + * capabilities. It builds on the smtp-send.c example, adding some * authentication and transport security. */ @@ -71,7 +71,6 @@ static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp) return 0; } - int main(void) { CURL *curl; @@ -150,5 +149,6 @@ int main(void) curl_slist_free_all(recipients); curl_easy_cleanup(curl); } + return 0; } -- cgit v1.2.3