Browse Source

remove 'transport_encode' in body generation, too.

MIME-13
Roker 2 years ago
parent
commit
d63610178c
3 changed files with 39 additions and 41 deletions
  1. +19
    -18
      src/bodygenerator.cc
  2. +4
    -4
      src/bodygenerator.hh
  3. +16
    -19
      src/pEpMIME.cc

+ 19
- 18
src/bodygenerator.cc View File

@ -56,11 +56,11 @@ std::string longmsg_mimetype(const message* msg)
}
void generate_body(std::string& smsg, sv mime_type, sv body, bool transport_encode)
void generate_body(std::string& smsg, sv mime_type, sv body)
{
smsg += "Content-Type: "s + mime_type + "; charset=UTF-8;\r\n"s;
if(transport_encode==false || need_transport_encoding(body)==false)
if(need_transport_encoding(body)==false)
{
smsg += "\r\n"; // end of header section
smsg += body;
@ -72,10 +72,10 @@ void generate_body(std::string& smsg, sv mime_type, sv body, bool transport_enco
}
void generate_ma_body(std::string& smsg, sv plain_mimetype, sv plain, sv html, bool transport_encode)
void generate_ma_body(std::string& smsg, sv plain_mimetype, sv plain, sv html)
{
const bool encode_plain = transport_encode && need_transport_encoding(plain);
const bool encode_html = transport_encode && need_transport_encoding(html);
const bool encode_plain = need_transport_encoding(plain);
const bool encode_html = need_transport_encoding(html);
unsigned long long counter=0;
std::string delimiter = generate_delimiter(counter);
@ -91,14 +91,14 @@ void generate_ma_body(std::string& smsg, sv plain_mimetype, sv plain, sv html, b
"\r\n"; // end of header section
smsg += "--" + delimiter + "\r\n";
generate_body(smsg, plain_mimetype, plain, transport_encode);
generate_body(smsg, plain_mimetype, plain);
smsg += "--" + delimiter + "\r\n";
generate_body(smsg, "text/html", html, transport_encode);
generate_body(smsg, "text/html", html);
smsg += "--" + delimiter + "--\r\n";
}
void generate_mm_body(std::string& smsg, sv mime_type, sv body, const std::vector<Attachment>& a, bool transport_encode)
void generate_mm_body(std::string& smsg, sv mime_type, sv body, const std::vector<Attachment>& a)
{
std::vector<Attachment> a2{a};
a2.emplace_back(body, mime_type);
@ -111,7 +111,7 @@ void generate_mm_body(std::string& smsg, sv mime_type, sv body, const std::vecto
if(mime_type.size())
{
smsg += "--" + delimiter + "\r\n";
generate_body(smsg, mime_type, body, transport_encode);
generate_body(smsg, mime_type, body);
}
generate_attachments(smsg, a, delimiter);
@ -120,7 +120,7 @@ void generate_mm_body(std::string& smsg, sv mime_type, sv body, const std::vecto
// complex MIME structures, depending on "det"
// see: https://dev.pep.foundation/libpEpMIME
void generate_complex_body(std::string& smsg, unsigned det, const message* msg, const std::vector<Attachment>& a, bool transport_encode)
void generate_complex_body(std::string& smsg, unsigned det, const message* msg, const std::vector<Attachment>& a)
{
const std::string longmsg_mimetype = pEpMIME::longmsg_mimetype(msg);
@ -139,7 +139,7 @@ void generate_complex_body(std::string& smsg, unsigned det, const message* msg,
case 6: smsg += "Content-Type: multipart/related; boundary=\"" + delimiter + "\";\r\n"
"\r\n" // end of header section
"--" + delimiter + "\r\n";
generate_body(smsg, "text/html", msg->longmsg_formatted, transport_encode);
generate_body(smsg, "text/html", msg->longmsg_formatted);
generate_attachments(smsg, a, delimiter);
break;
case 7:
@ -148,13 +148,13 @@ void generate_complex_body(std::string& smsg, unsigned det, const message* msg,
smsg += "Content-Type: multipart/alternative; boundary=\"" + delimiter_A + "\";\r\n"
"\r\n"
"--" + delimiter_A + "\r\n";
generate_body(smsg, longmsg_mimetype, msg->longmsg, transport_encode);
generate_body(smsg, longmsg_mimetype, msg->longmsg);
smsg += "--" + delimiter_A + "\r\n";
const std::string delimiter_R = delimiter + "R=";
smsg += "Content-Type: multipart/related; boundary=\"" + delimiter_R + "\";\r\n"
"\r\n"
"--" + delimiter_R + "\r\n";
generate_body(smsg, "text/html", msg->longmsg_formatted, transport_encode);
generate_body(smsg, "text/html", msg->longmsg_formatted);
generate_attachments(smsg, a, delimiter_R);
smsg += "--" + delimiter_A + "--\r\n";
break;
@ -169,9 +169,9 @@ void generate_complex_body(std::string& smsg, unsigned det, const message* msg,
smsg += "Content-Type: multipart/alternative; boundary=\"" + delimiter_A + "\";\r\n"
"\r\n"
"--" + delimiter_A + "\r\n";
generate_body(smsg, longmsg_mimetype, msg->longmsg, transport_encode);
generate_body(smsg, longmsg_mimetype, msg->longmsg);
smsg += "--" + delimiter_A + "\r\n";
generate_body(smsg, "text/html", msg->longmsg_formatted, transport_encode);
generate_body(smsg, "text/html", msg->longmsg_formatted);
smsg += "--" + delimiter_A + "--\r\n"
"\r\n";
generate_attachments(smsg, a, delimiter_M);
@ -187,8 +187,9 @@ void generate_complex_body(std::string& smsg, unsigned det, const message* msg,
smsg += "Content-Type: multipart/related; boundary=\"" + delimiter_R + "\";\r\n"
"\r\n"
"--" + delimiter_R + "\r\n";
generate_body(smsg, "text/html", msg->longmsg_formatted, transport_encode);
generate_body(smsg, "text/html", msg->longmsg_formatted);
generate_attachments(smsg, a, delimiter_R, &is_inline );
// closing of delimiter_R is done in generate_attachments()
generate_attachments(smsg, a, delimiter_M, &is_not_inline );
break;
}
@ -203,12 +204,12 @@ void generate_complex_body(std::string& smsg, unsigned det, const message* msg,
smsg += "Content-Type: multipart/alternative; boundary=\"" + delimiter_A + "\";\r\n"
"\r\n"
"--" + delimiter_A + "\r\n";
generate_body(smsg, longmsg_mimetype, msg->longmsg, transport_encode);
generate_body(smsg, longmsg_mimetype, msg->longmsg);
smsg += "--" + delimiter_A + "\r\n"
"Content-Type: multipart/related; boundary=\"" + delimiter_R + "\";\r\n"
"\r\n"
"--" + delimiter_R + "\r\n";
generate_body(smsg, "text/html", msg->longmsg_formatted, transport_encode);
generate_body(smsg, "text/html", msg->longmsg_formatted);
generate_attachments(smsg, a, delimiter_R, &is_inline );
// closing of delimiter_R is done in generate_attachments()
smsg += "--" + delimiter_A + "--\r\n";


+ 4
- 4
src/bodygenerator.hh View File

@ -9,17 +9,17 @@ namespace pEpMIME
// is "text/plain", optionally annotated with format=... and delsp=...
std::string longmsg_mimetype(const message* msg);
void generate_body(std::string& smsg, sv mime_type, sv body, bool transport_encode);
void generate_body(std::string& smsg, sv mime_type, sv body);
// generate "multipart/alternative" body with "text/plain" and "text/html" parts
void generate_ma_body(std::string& smsg, sv plain_mimetype, sv plain, sv html, bool transport_encode);
void generate_ma_body(std::string& smsg, sv plain_mimetype, sv plain, sv html);
// generate "multipart/mixed" body
void generate_mm_body(std::string& smsg, sv mime_type, sv body, const std::vector<Attachment>& a, bool transport_encode);
void generate_mm_body(std::string& smsg, sv mime_type, sv body, const std::vector<Attachment>& a);
// complex MIME structures, depending on "det"
// see: https://dev.pep.foundation/libpEpMIME
void generate_complex_body(std::string& smsg, unsigned det, const message* msg, const std::vector<Attachment>& a, bool transport_encode);
void generate_complex_body(std::string& smsg, unsigned det, const message* msg, const std::vector<Attachment>& a);
} // end of namespace pEpMIME


+ 16
- 19
src/pEpMIME.cc View File

@ -181,30 +181,27 @@ char* generate_message(const message* msg, bool omit_fields, bool has_pEp_msg_at
const std::string longmsg_mimetype = ::pEpMIME::longmsg_mimetype(msg);
// temporary hack:
static const bool transport_encode = true;
switch(det)
{
case 0 : generate_body(smsg, "text/plain" , "", transport_encode); break; // empty text/plain body
case 1 : generate_body(smsg, longmsg_mimetype , msg->longmsg, transport_encode); break;
case 2 : generate_body(smsg, "text/html" , msg->longmsg_formatted, transport_encode); break;
case 3 : generate_ma_body(smsg, longmsg_mimetype, msg->longmsg, msg->longmsg_formatted, transport_encode); break;
case 0 : generate_body(smsg, "text/plain" , "" ); break; // empty text/plain body
case 1 : generate_body(smsg, longmsg_mimetype , msg->longmsg ); break;
case 2 : generate_body(smsg, "text/html" , msg->longmsg_formatted ); break;
case 3 : generate_ma_body(smsg, longmsg_mimetype, msg->longmsg, msg->longmsg_formatted); break;
case 4 : generate_mm_body(smsg, sv{}, sv{} , attachments, transport_encode); break;
case 5 : generate_mm_body(smsg, longmsg_mimetype, msg->longmsg , attachments, transport_encode); break;
case 6 : generate_complex_body(smsg, det, msg, attachments, transport_encode); break; // FIXME!
case 7 : generate_complex_body(smsg, det, msg, attachments, transport_encode); break; // FIXME!
case 4 : generate_mm_body(smsg, sv{}, sv{} , attachments); break;
case 5 : generate_mm_body(smsg, longmsg_mimetype, msg->longmsg , attachments); break;
case 6 : generate_complex_body(smsg, det, msg, attachments); break; // FIXME!
case 7 : generate_complex_body(smsg, det, msg, attachments); break; // FIXME!
case 8 : generate_mm_body(smsg, sv{}, sv{} , attachments, transport_encode); break;
case 9 : generate_mm_body(smsg, longmsg_mimetype, msg->longmsg , attachments, transport_encode); break;
case 10 : generate_mm_body(smsg, "text/html", msg->longmsg_formatted, attachments, transport_encode); break;
case 11 : generate_complex_body(smsg, det, msg, attachments, transport_encode); break; // FIXME!
case 8 : generate_mm_body(smsg, sv{}, sv{} , attachments); break;
case 9 : generate_mm_body(smsg, longmsg_mimetype, msg->longmsg , attachments); break;
case 10 : generate_mm_body(smsg, "text/html", msg->longmsg_formatted, attachments); break;
case 11 : generate_complex_body(smsg, det, msg, attachments); break; // FIXME!
case 12 : generate_mm_body(smsg, sv{}, sv{} , attachments, transport_encode); break;
case 13 : generate_mm_body(smsg, longmsg_mimetype, msg->longmsg , attachments, transport_encode); break;
case 14 : generate_complex_body(smsg, det, msg, attachments, transport_encode); break; // FIXME!
case 15 : generate_complex_body(smsg, det, msg, attachments, transport_encode); break; // FIXME!
case 12 : generate_mm_body(smsg, sv{}, sv{} , attachments); break;
case 13 : generate_mm_body(smsg, longmsg_mimetype, msg->longmsg , attachments); break;
case 14 : generate_complex_body(smsg, det, msg, attachments); break; // FIXME!
case 15 : generate_complex_body(smsg, det, msg, attachments); break; // FIXME!
default:
throw std::logic_error("Determinant ouf of range 0...15: det=" + std::to_string(det) );


Loading…
Cancel
Save