/***************************************************************************
   *                                  _   _ ____  _
   *  Project                     ___| | | |  _ \| |
   *                             / __| | | | |_) | |
   *                            | (__| |_| |  _ <| |___
   *                             \___|\___/|_| \_\_____|
   *
   * $Id: ftpget.c,v 1.7 2008-02-27 09:06:15 bagder Exp $
   */
  
  #include <iostream>
  

  #include <curl/curl.h>
  #include <curl/types.h>
  #include <curl/easy.h>

  using namespace std;
  
  /*
   * This is an example showing how to send an email via SMTP
   */
  
  
static const char *text[]={
  "one ",
  "two ",
  "three ",
  "this is CURL email from gmail ",
  NULL
};

 struct WriteThis {
  int counter;
};

static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
{
  struct WriteThis *pooh = (struct WriteThis *)userp;
  const char *data;

  if(size*nmemb < 1)
    return 0;

  data = text[pooh->counter];

  if(data) {
    size_t len = strlen(data);
    memcpy(ptr, data, len);
    pooh->counter++; /* advance pointer */
    return len;
  }
  return 0;                         /* no more data left to deliver */
}
 
  
  int main(void)
  {
    CURL *curl;
    CURLcode res;
    struct WriteThis pooh;
    pooh.counter = 0;

    curl_global_init(CURL_GLOBAL_DEFAULT);
  
    curl = curl_easy_init();
    if(curl) {

      struct curl_slist* rcpt_list = NULL;
      rcpt_list = curl_slist_append(rcpt_list, "arossen@opentext.com");
      rcpt_list = curl_slist_append(rcpt_list, "arossen@rogers.com");


curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);

      curl_easy_setopt(curl, CURLOPT_READDATA, &pooh);

	curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,  14);
  curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.gmail.com:587/smtp%5Ftest%2Etxt");
  curl_easy_setopt(curl, CURLOPT_PROXY, NULL);
  curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
  curl_easy_setopt(curl, CURLOPT_HEADER, 0);
  curl_easy_setopt(curl, CURLOPT_FAILONERROR, 0);
  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  curl_easy_setopt(curl, CURLOPT_DIRLISTONLY, 0);
  curl_easy_setopt(curl, CURLOPT_APPEND, 0);
  curl_easy_setopt(curl, CURLOPT_NETRC, 0);
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);
  curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 0);
  curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 0);
  curl_easy_setopt(curl, CURLOPT_USERPWD, "XXXXXXXXX:XXXXXXXXX");
  curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, NULL);
  curl_easy_setopt(curl, CURLOPT_NOPROXY, NULL);
  curl_easy_setopt(curl, CURLOPT_RANGE, NULL);
  /* curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, 0xffbfe628); [REMARK] */
  curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);
  curl_easy_setopt(curl, CURLOPT_REFERER, NULL);
  curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 0);
  curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.21.0 (sparc-sun-solaris2.9) libcurl/7.21.0 OpenSSL/0.9.8ezlib/1.1.3 libssh2/1.2.6");
  curl_easy_setopt(curl, CURLOPT_FTPPORT, NULL);
  curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 0);
  curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 0);
  curl_easy_setopt(curl, CURLOPT_MAX_SEND_SPEED_LARGE,  0);
  curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE,  0);
  curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE,  0);
  curl_easy_setopt(curl, CURLOPT_COOKIE, NULL);
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
  curl_easy_setopt(curl, CURLOPT_SSLCERT, NULL);
  curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, NULL);
  curl_easy_setopt(curl, CURLOPT_SSLKEY, NULL);
  curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, NULL);
  curl_easy_setopt(curl, CURLOPT_KEYPASSWD, NULL);
  curl_easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, NULL);
  curl_easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, NULL);
  curl_easy_setopt(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, NULL);
  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1);
  curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50);
  curl_easy_setopt(curl, CURLOPT_CRLF, 0);
  curl_easy_setopt(curl, CURLOPT_QUOTE, NULL);
  curl_easy_setopt(curl, CURLOPT_POSTQUOTE, NULL);
  curl_easy_setopt(curl, CURLOPT_PREQUOTE, NULL);
  curl_easy_setopt(curl, CURLOPT_HEADERDATA, NULL);
  curl_easy_setopt(curl, CURLOPT_COOKIEFILE, NULL);
  curl_easy_setopt(curl, CURLOPT_COOKIESESSION, 0);
  curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0);
  curl_easy_setopt(curl, CURLOPT_TIMECONDITION, 0);
  curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 0);
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 0);
  curl_easy_setopt(curl, CURLOPT_INTERFACE, NULL);
  curl_easy_setopt(curl, CURLOPT_KRBLEVEL, NULL);
  curl_easy_setopt(curl, CURLOPT_TELNETOPTIONS, NULL);
  curl_easy_setopt(curl, CURLOPT_RANDOM_FILE, NULL);
  curl_easy_setopt(curl, CURLOPT_EGDSOCKET, NULL);
  curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 0);
  /* curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, 0x163f0); [REMARK] */
  /* curl_easy_setopt(curl, CURLOPT_DEBUGDATA, 0xffbfe7d8); [REMARK] */
  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  curl_easy_setopt(curl, CURLOPT_ENCODING, NULL);
  curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 0);
  curl_easy_setopt(curl, CURLOPT_IPRESOLVE, 0);
  curl_easy_setopt(curl, CURLOPT_USE_SSL, 3);
  curl_easy_setopt(curl, CURLOPT_FTP_ACCOUNT, NULL);
  curl_easy_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 0);
  curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 0);
  curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, 0);
  curl_easy_setopt(curl, CURLOPT_FTP_ALTERNATIVE_TO_USER, NULL);
  curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 1);
  /* curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, 0x131fc); [REMARK] */
  /* curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, 0xffbfe7d8); [REMARK] */
  curl_easy_setopt(curl, CURLOPT_POSTREDIR, 0);
  curl_easy_setopt(curl, CURLOPT_MAIL_FROM, "<alona.rossen@gmail.com>");


      res = curl_easy_perform(curl);


      curl_slist_free_all(rcpt_list);

      curl_easy_cleanup(curl);
  
      curl_global_cleanup();
  
    return 0;
  }

    return -1;
}

