X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Femailer.cc;h=f580e3c56a64361a46229a13b8d0c9794ebe3884;hp=6ef23c3e0c03a3e20cd241df9453dddfea8501aa;hb=9f125fddff88bf62d36381f9d3f09e5240b033d5;hpb=689fa55d1529ad88449ca464e9107c4dcc54d1cb diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc index 6ef23c3e0..f580e3c56 100644 --- a/src/lib/emailer.cc +++ b/src/lib/emailer.cc @@ -31,15 +31,15 @@ using std::cout; -using std::list; using std::min; using std::pair; using std::shared_ptr; using std::string; +using std::vector; using dcp::ArrayData; -Emailer::Emailer (string from, list to, string subject, string body) +Emailer::Emailer(string from, vector to, string subject, string body) : _from (from) , _to (to) , _subject (subject) @@ -143,7 +143,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str "Content-Type: multipart/mixed; boundary=" + boundary + "\r\n"; } - _email += "Subject: " + _subject + "\r\n" + _email += "Subject: " + encode_rfc1342(_subject) + "\r\n" "User-Agent: DCP-o-matic\r\n" "\r\n"; @@ -156,13 +156,19 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str for (auto i: _attachments) { _email += "\r\n\r\n--" + boundary + "\r\n" - "Content-Type: " + i.mime_type + "; name=" + i.name + "\r\n" + "Content-Type: " + i.mime_type + "; name=" + encode_rfc1342(i.name) + "\r\n" "Content-Transfer-Encoding: Base64\r\n" - "Content-Disposition: attachment; filename=" + i.name + "\r\n\r\n"; + "Content-Disposition: attachment; filename=" + encode_rfc1342(i.name) + "\r\n\r\n"; auto b64 = BIO_new (BIO_f_base64()); + if (!b64) { + throw std::bad_alloc(); + } auto bio = BIO_new (BIO_s_mem()); + if (!bio) { + throw std::bad_alloc(); + } bio = BIO_push (b64, bio); ArrayData data (i.file); @@ -231,7 +237,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str auto const r = curl_easy_perform (curl); if (r != CURLE_OK) { - throw KDMError (_("Failed to send email"), curl_easy_strerror (r)); + throw NetworkError (_("Failed to send email"), string(curl_easy_strerror(r))); } curl_slist_free_all (recipients); @@ -241,7 +247,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str string -Emailer::address_list (list addresses) +Emailer::address_list(vector addresses) { string o; for (auto i: addresses) { @@ -264,3 +270,31 @@ Emailer::debug (CURL *, curl_infotype type, char* data, size_t size) } return 0; } + + +string +Emailer::encode_rfc1342 (string subject) +{ + auto b64 = BIO_new(BIO_f_base64()); + if (!b64) { + throw std::bad_alloc(); + } + + auto bio = BIO_new(BIO_s_mem()); + if (!bio) { + throw std::bad_alloc(); + } + + bio = BIO_push(b64, bio); + BIO_write(bio, subject.c_str(), subject.length()); + (void) BIO_flush(bio); + + char* out; + long int bytes = BIO_get_mem_data(bio, &out); + string base64_subject(out, bytes); + BIO_free_all(b64); + + boost::algorithm::replace_all(base64_subject, "\n", ""); + return "=?utf-8?B?" + base64_subject + "?="; +} +