Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / src / lib / emailer.cc
index 534856ba61f23613ab684e29969a2036fd1bfd38..fe6eb529428b32b90a5275c3b472bc8e87f2762a 100644 (file)
@@ -41,11 +41,18 @@ Emailer::Emailer (string from, list<string> to, string subject, string body)
        : _from (from)
        , _to (to)
        , _subject (subject)
-       , _body (body)
+       , _body (fix (body))
        , _offset (0)
 {
-       boost::algorithm::replace_all (_body, "\n", "\r\n");
-       boost::algorithm::replace_all (_body, "\0", " ");
+
+}
+
+string
+Emailer::fix (string s) const
+{
+       boost::algorithm::replace_all (s, "\n", "\r\n");
+       boost::algorithm::replace_all (s, "\0", " ");
+       return s;
 }
 
 void
@@ -154,7 +161,7 @@ Emailer::send (string server, int port, string user, string password)
 
                char* out;
                long int bytes = BIO_get_mem_data (bio, &out);
-               _email += string (out, bytes);
+               _email += fix (string (out, bytes));
 
                BIO_free_all (b64);
        }
@@ -170,7 +177,12 @@ Emailer::send (string server, int port, string user, string password)
                throw NetworkError ("Could not initialise libcurl");
        }
 
-       curl_easy_setopt (curl, CURLOPT_URL, String::compose ("smtp://%1:%2", server.c_str(), port).c_str());
+       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());
+       } else {
+               curl_easy_setopt (curl, CURLOPT_URL, String::compose ("smtp://%1:%2", server, port).c_str());
+       }
 
        if (!user.empty ()) {
                curl_easy_setopt (curl, CURLOPT_USERNAME, user.c_str ());