Skip to content

Commit

Permalink
Include plain text in RFC822 email output
Browse files Browse the repository at this point in the history
  • Loading branch information
emk committed Jun 30, 2010
1 parent 6d7e217 commit 0ceec9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 13 additions & 6 deletions rfc822.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,21 @@ void document_to_rfc822(ostream &out, const document &d) {
out << "X-Note: See load file metadata for original headers" << crlf;
out << crlf;

if (d.has_text()) {
out << "--=_boundary" << crlf
<< "Content-Type: text/plain; charset=UTF-8" << crlf
<< "Content-Transfer-Encoding: base64" << crlf
<< crlf
<< base64_wrapped(wstring_to_utf8(d.text()));
}

out << "--=_boundary" << crlf
<< "Content-Type: text/plain; charset=UTF-8" << crlf
<< "Content-Transfer-Encoding: base64" << crlf
<< crlf
<< "--=_boundary" << crlf
<< "Content-Type: text/html" << crlf
<< "Content-Transfer-Encoding: base64" << crlf
<< crlf
<< "--=_boundary--" << crlf;
<< crlf;

// TODO: Warn about messages with no text or HTML body.

out << "--=_boundary--" << crlf;
}

12 changes: 11 additions & 1 deletion rfc822_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
using namespace std;
using namespace boost::posix_time;

const wchar_t *long_wchar_t_string =
L"The quick brown fox jumped over the lazy dog\u2014or did she? "
L"The quick brown fox jumped over the lazy dog\u2014or did she? "
L"The quick brown fox jumped over the lazy dog\u2014or did she?";

const char *long_utf8_string =
"The quick brown fox jumped over the lazy dog\xE2\x80\x94or did she? "
"The quick brown fox jumped over the lazy dog\xE2\x80\x94or did she? "
Expand Down Expand Up @@ -154,7 +159,8 @@ void document_to_rfc822_should_include_headers_text_and_html() {
d[L"#DateSent"] = from_iso_string("20020131T235959Z");
d[L"#Header"] = wstring(L"Subject: Re: the fridge\r\n");

// TODO: Text body
d.set_text(long_wchar_t_string);

// TODO: HTML body

const char *expected =
Expand All @@ -175,6 +181,10 @@ void document_to_rfc822_should_include_headers_text_and_html() {
"Content-Type: text/plain; charset=UTF-8\r\n"
"Content-Transfer-Encoding: base64\r\n"
"\r\n"
"VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2figJRvciBkaWQg\r\n"
"c2hlPyAgVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2figJRv\r\n"
"ciBkaWQgc2hlPyAgVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBk\r\n"
"b2figJRvciBkaWQgc2hlPw==\r\n"
"--=_boundary\r\n"
"Content-Type: text/html\r\n"
"Content-Transfer-Encoding: base64\r\n"
Expand Down

0 comments on commit 0ceec9e

Please sign in to comment.