|
|
|
@ -21,8 +21,8 @@ using qi::_1;
|
|
|
|
|
|
|
|
|
|
struct ContentType
|
|
|
|
|
{
|
|
|
|
|
std::string type;
|
|
|
|
|
std::string subtype;
|
|
|
|
|
std::string type = "text";
|
|
|
|
|
std::string subtype = "plain";
|
|
|
|
|
std::vector<pEpMIME::NameValue> params;
|
|
|
|
|
void tolower(); // only for ASCII chars, but that's sufficient here.
|
|
|
|
|
void unwrap(); // reverses the wrapping of overlong (andtherefore split) parameter values.
|
|
|
|
@ -249,7 +249,7 @@ char* create_string(const BodyLines& body, const sv& charset, Decoder decoder)
|
|
|
|
|
}else{
|
|
|
|
|
// Sigh, the hard way. At the moment with a lot of unecessary copying. :-/
|
|
|
|
|
// Rule1: Make it work. Profile. Make it fast. In this order.
|
|
|
|
|
const std::string converted = to_utf8(charset, std::string(decoded, decoded+decoded_size) ); // 1st copy...
|
|
|
|
|
const std::string converted = to_utf8((charset.empty() ? "us-ascii" : charset), std::string(decoded, decoded+decoded_size) ); // 1st copy...
|
|
|
|
|
return new_string( converted.data(), converted.size() ); // copy again. :'-(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -264,26 +264,27 @@ void add_attachment(message* msg, const BodyLines& body, const ContentType& ct,
|
|
|
|
|
// parses the header and fill the parts in msg
|
|
|
|
|
void parse_body(message* msg, const HeaderSection& headers, const BodyLines& body)
|
|
|
|
|
{
|
|
|
|
|
if( header_value(headers, "mime-version") == "1.0" ) // TODO: According to RFC 2048 there can be comments in the header field value. -.-
|
|
|
|
|
const std::string mime_version = header_value(headers, "mime-version").to_string();
|
|
|
|
|
const std::string cts = header_value(headers, "content-type").to_string();
|
|
|
|
|
ContentType ct;
|
|
|
|
|
auto begin = cts.cbegin();
|
|
|
|
|
const bool okay = qi::parse(begin, cts.cend(), content_type, ct);
|
|
|
|
|
if(!okay)
|
|
|
|
|
{
|
|
|
|
|
LOG << "Cannot parse \"" + std::string{cts} + "\" as ContentType.\n";
|
|
|
|
|
}
|
|
|
|
|
LOG << "<<< CT raw: " << ct << ">>>\n";
|
|
|
|
|
ct.sanitize();
|
|
|
|
|
LOG << "<<< CT san: " << ct << ">>>\n";
|
|
|
|
|
|
|
|
|
|
if( mime_version == "1.0" ) // TODO: According to RFC 2048 there can be comments in the header field value. -.-
|
|
|
|
|
{
|
|
|
|
|
// TODO: for whatever reason "string_view cts" does not work with qi::parse(). WTF!
|
|
|
|
|
const std::string cts = header_value(headers, "content-type").to_string();
|
|
|
|
|
ContentType ct;
|
|
|
|
|
|
|
|
|
|
auto begin = cts.cbegin();
|
|
|
|
|
|
|
|
|
|
const bool okay = qi::parse(begin, cts.cend(), content_type, ct);
|
|
|
|
|
if(!okay)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error( "Cannot parse \"" + std::string{cts} + "\" as ContentType");
|
|
|
|
|
}
|
|
|
|
|
LOG << "<<< CT raw: " << ct << ">>>\n";
|
|
|
|
|
ct.sanitize();
|
|
|
|
|
LOG << "<<< CT san: " << ct << ">>>\n";
|
|
|
|
|
if(ct.type == "text")
|
|
|
|
|
{
|
|
|
|
|
const sv charset = header_value( ct.params, "charset" );
|
|
|
|
|
Decoder decoder = getDecoder( header_value( headers, "Content-Transfer-Encoding" ) );
|
|
|
|
|
Decoder decoder = getDecoder( header_value( headers, "content-transfer-encoding" ) );
|
|
|
|
|
if(ct.subtype == "plain")
|
|
|
|
|
{
|
|
|
|
|
// put it in msg->longmsg
|
|
|
|
|