Emailer::Emailer (string from, list<string> to, string subject, string body)
: _from (from)
Emailer::Emailer (string from, list<string> to, string subject, string body)
: _from (from)
static size_t
curl_data_shim (void* ptr, size_t size, size_t nmemb, void* userp)
{
return reinterpret_cast<Emailer*>(userp)->get_data (ptr, size, nmemb);
}
static size_t
curl_data_shim (void* ptr, size_t size, size_t nmemb, void* userp)
{
return reinterpret_cast<Emailer*>(userp)->get_data (ptr, size, nmemb);
}
static int
curl_debug_shim (CURL* curl, curl_infotype type, char* data, size_t size, void* userp)
{
return reinterpret_cast<Emailer*>(userp)->debug (curl, type, data, size);
}
static int
curl_debug_shim (CURL* curl, curl_infotype type, char* data, size_t size, void* userp)
{
return reinterpret_cast<Emailer*>(userp)->debug (curl, type, data, size);
}
-Emailer::send (string server, int port, string user, string password)
+Emailer::send (string server, int port, EmailProtocol protocol, string user, string password)
- strftime (date_buffer, sizeof(date_buffer), "%a, %d %b %Y %H:%M:%S ", localtime (&now));
+ strftime (date_buffer, sizeof(date_buffer), "%a, %d %b %Y %H:%M:%S ", localtime(&now));
- boost::posix_time::ptime const utc_now = boost::posix_time::second_clock::universal_time ();
- boost::posix_time::ptime const local_now = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local (utc_now);
- boost::posix_time::time_duration offset = local_now - utc_now;
- sprintf (date_buffer + strlen(date_buffer), "%s%02d%02d", (offset.hours() >= 0 ? "+" : "-"), abs (offset.hours()), offset.minutes());
+ auto const utc_now = boost::posix_time::second_clock::universal_time ();
+ auto const local_now = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local (utc_now);
+ auto offset = local_now - utc_now;
+ sprintf (date_buffer + strlen(date_buffer), "%s%02d%02d", (offset.hours() >= 0 ? "+" : "-"), int(abs(offset.hours())), int(offset.minutes()));
_email = "Date: " + string(date_buffer) + "\r\n"
"To: " + address_list (_to) + "\r\n"
"From: " + _from + "\r\n";
_email = "Date: " + string(date_buffer) + "\r\n"
"To: " + address_list (_to) + "\r\n"
"From: " + _from + "\r\n";
_email += "\r\n\r\n--" + boundary + "\r\n"
"Content-Type: " + i.mime_type + "; name=" + i.name + "\r\n"
"Content-Transfer-Encoding: Base64\r\n"
"Content-Disposition: attachment; filename=" + i.name + "\r\n\r\n";
_email += "\r\n\r\n--" + boundary + "\r\n"
"Content-Type: " + i.mime_type + "; name=" + i.name + "\r\n"
"Content-Transfer-Encoding: Base64\r\n"
"Content-Disposition: attachment; filename=" + i.name + "\r\n\r\n";
- Data data (i.file);
- BIO_write (bio, data.data().get(), data.size());
+ ArrayData data (i.file);
+ BIO_write (bio, data.data(), data.size());
- if (port == 465) {
- /* "Implicit TLS"; I think curl wants us to use smtps here */
- curl_easy_setopt (curl, CURLOPT_URL, String::compose ("smtps://%1:465", server).c_str());
+ if ((protocol == EmailProtocol::AUTO && port == 465) || protocol == EmailProtocol::SSL) {
+ /* "SSL" or "Implicit TLS"; I think curl wants us to use smtps here */
+ curl_easy_setopt (curl, CURLOPT_URL, String::compose("smtps://%1:%2", server, port).c_str());
- curl_easy_setopt (curl, CURLOPT_URL, String::compose ("smtp://%1:%2", server, port).c_str());
+ curl_easy_setopt (curl, CURLOPT_URL, String::compose("smtp://%1:%2", server, port).c_str());
curl_easy_setopt (curl, CURLOPT_READDATA, this);
curl_easy_setopt (curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt (curl, CURLOPT_READDATA, this);
curl_easy_setopt (curl, CURLOPT_UPLOAD, 1L);
- curl_easy_setopt (curl, CURLOPT_USE_SSL, (long) CURLUSESSL_TRY);
+ if (protocol == EmailProtocol::AUTO || protocol == EmailProtocol::STARTTLS) {
+ curl_easy_setopt (curl, CURLOPT_USE_SSL, (long) CURLUSESSL_TRY);
+ }
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION, curl_debug_shim);
curl_easy_setopt (curl, CURLOPT_DEBUGDATA, this);
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION, curl_debug_shim);
curl_easy_setopt (curl, CURLOPT_DEBUGDATA, this);
int
Emailer::debug (CURL *, curl_infotype type, char* data, size_t size)
{
int
Emailer::debug (CURL *, curl_infotype type, char* data, size_t size)
{