+
+
+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 + "?=";
+}
+