Line-break base64 attachments with \r\n rather than just \n
authorCarl Hetherington <cth@carlh.net>
Sun, 21 Aug 2016 22:14:56 +0000 (23:14 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 21 Aug 2016 22:14:56 +0000 (23:14 +0100)
to stop "line too long" errors with some email servers.

ChangeLog
src/lib/emailer.cc
src/lib/emailer.h

index eb9cb0fa15d70f4b1499798e021334dbe846e9a9..2c4f11a306be258f8cf264861bb1aafc975b73c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-08-21  Carl Hetherington  <cth@carlh.net>
+
+       * Fix problems when sending emails on some servers.
+
 2016-08-20  Carl Hetherington  <cth@carlh.net>
 
        * Updated nl_NL translation from Rob van Nieuwkerk.
index 534856ba61f23613ab684e29969a2036fd1bfd38..ceb26caf6ae15e12ea1c42cb93e1d9e358812647 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);
        }
index 7a614019e3c7e7c1a031250f323622d5093d2212..0309b134d17c16fca408fc8daecbb680a4133900 100644 (file)
@@ -48,6 +48,8 @@ public:
 
 private:
 
+       std::string fix (std::string s) const;
+
        std::string _from;
        std::list<std::string> _to;
        std::string _subject;