Browse Source

remove transport_encode, because it was b0rken

MIME-13
Roker 2 years ago
parent
commit
c213736043
2 changed files with 32 additions and 32 deletions
  1. +28
    -28
      src/header_generator.cc
  2. +4
    -4
      src/header_generator.hh

+ 28
- 28
src/header_generator.cc View File

@ -54,7 +54,7 @@ namespace
}
std::string encode_if_necessary(const Rule& rule, sv name, sv value, HeaderType type)
std::string encode_header_if_necessary(const Rule& rule, sv name, sv value, HeaderType type)
{
if(value.empty())
return std::string();
@ -81,18 +81,18 @@ namespace
return s;
}
static const TransportEncoder encoder[2] = { &dont_encode, &encode_if_necessary };
// static const TransportEncoder encoder[2] = { &dont_encode, &encode_header_if_necessary };
static const std::string CRLF = "\r\n"s;
}
void generate(std::string& out, sv header_name, const pEp_identity* id, bool transport_encode)
void generate(std::string& out, sv header_name, const pEp_identity* id)
{
LOG << "GEN_ID: " << id->username << " | " << id->address << std::endl;
static BasicRules br;
out += exists(id->username) ? encoder[transport_encode](br.phrase, header_name, id->username, qp::Word) + " " : std::string() ;
out += exists(id->username) ? encode_header_if_necessary(br.phrase, header_name, id->username, qp::Word) + " " : std::string() ;
if(!exists(id->address))
return;
@ -112,40 +112,40 @@ void generate(std::string& out, sv header_name, const pEp_identity* id, bool tra
}
void generate(std::string& out, sv header_name, const identity_list* il, bool transport_encode)
void generate(std::string& out, sv header_name, const identity_list* il)
{
LOG << "GEN_IDList: " << identity_list_length(il) << " entries. " << std::endl;
if( identity_list_length(il) == 0)
return;
generate(out, header_name, il->ident, transport_encode);
generate(out, header_name, il->ident);
il = il->next;
while(il)
{
out += (transport_encode ? ",\r\n\t" : ", ");
generate(out, std::string(), il->ident, transport_encode);
out += ",\r\n\t";
generate(out, sv{}, il->ident);
il = il->next;
}
}
void generate(std::string& out, const Rule& rule, sv header_name, const stringlist_t* sl, bool transport_encode)
void generate(std::string& out, const Rule& rule, sv header_name, const stringlist_t* sl)
{
if( stringlist_length(sl) == 0)
return;
out += encoder[transport_encode](rule, header_name, sl->value, qp::Word);
out += encode_header_if_necessary(rule, header_name, sl->value, qp::Word);
sl = sl->next;
while(sl)
{
out += (transport_encode ? ",\r\n\t" : ", ") + encoder[transport_encode](rule, "", sl->value, qp::Word);
out += ",\r\n\t" + encode_header_if_necessary(rule, "", sl->value, qp::Word);
sl = sl->next;
}
}
void generate_msgids(std::string& out, sv header_name, const stringlist_t* sl, bool transport_encode)
void generate_msgids(std::string& out, sv header_name, const stringlist_t* sl)
{
if( stringlist_length(sl) == 0)
return;
@ -157,38 +157,37 @@ void generate_msgids(std::string& out, sv header_name, const stringlist_t* sl, b
sl = sl->next;
while(sl)
{
out += std::string(transport_encode ? "\r\n\t<" : " <") + sl->value + ">";
out += std::string("\r\n\t<") + sl->value + ">";
sl = sl->next;
}
}
void generate_header(std::string& smsg, const message* msg, bool transport_encode)
void generate_header(std::string& smsg, const message* msg)
{
TransportEncoder E = transport_encode ? &encode_if_necessary : &dont_encode;
LOG << "GEN_HDR: te = " << transport_encode << std::endl;
LOG << "GEN_HDR:" << std::endl;
static BasicRules br;
if(msg->id) smsg += "Message-ID: <"s + msg->id + ">\r\n";
if(msg->shortmsg) smsg += E(br.phrase, "Subject", msg->shortmsg, qp::Text) + CRLF;
if(msg->shortmsg) smsg += encode_header_if_necessary(br.phrase, "Subject", msg->shortmsg, qp::Text) + CRLF;
LOG << "\t smsg so far: " << smsg << std::endl;
// FIXME: msg->sent , msg->received
if(msg->from) { generate(smsg, "From", msg->from, transport_encode); smsg += CRLF; }
if(msg->to) { generate(smsg, "To" , msg->to , transport_encode); smsg += CRLF; }
if(msg->cc) { generate(smsg, "Cc" , msg->cc , transport_encode); smsg += CRLF; }
if(msg->bcc) { generate(smsg, "Bcc" , msg->bcc , transport_encode); smsg += CRLF; }
if(msg->from) { generate(smsg, "From", msg->from); smsg += CRLF; }
if(msg->to) { generate(smsg, "To" , msg->to ); smsg += CRLF; }
if(msg->cc) { generate(smsg, "Cc" , msg->cc ); smsg += CRLF; }
if(msg->bcc) { generate(smsg, "Bcc" , msg->bcc ); smsg += CRLF; }
LOG << "\t smgs2 so far: " << smsg << std::endl;
if(msg->recv_by) { generate(smsg, "Received-By", msg->recv_by , transport_encode); smsg += CRLF; }
if(msg->reply_to) { generate(smsg, "Reply-To" , msg->reply_to , transport_encode); smsg += CRLF; }
if(msg->in_reply_to) { generate_msgids(smsg, "In-Reply-To", msg->in_reply_to, transport_encode); smsg += CRLF; }
if(msg->references ) { generate_msgids(smsg, "References" , msg->references , transport_encode); smsg += CRLF; }
if(msg->keywords) { generate(smsg, br.phrase, "Keywords" , msg->keywords , transport_encode); smsg += CRLF; }
if(msg->recv_by) { generate(smsg, "Received-By", msg->recv_by ); smsg += CRLF; }
if(msg->reply_to) { generate(smsg, "Reply-To" , msg->reply_to ); smsg += CRLF; }
if(msg->in_reply_to) { generate_msgids(smsg, "In-Reply-To", msg->in_reply_to); smsg += CRLF; }
if(msg->references ) { generate_msgids(smsg, "References" , msg->references ); smsg += CRLF; }
if(msg->keywords) { generate(smsg, br.phrase, "Keywords" , msg->keywords); smsg += CRLF; }
const stringpair_list_t* spl = msg->opt_fields;
LOG << "GEN_HDR: " << stringpair_list_length( spl ) << " opt_fields.\n";
@ -196,6 +195,7 @@ void generate_header(std::string& smsg, const message* msg, bool transport_encod
while(spl)
{
const char* const key = spl->value->key;
// header keys starting with ':' are pseudo headers for pEp-internal use only.
// Don't emit them in the MIME output
if(key[0]==':')
@ -209,11 +209,11 @@ void generate_header(std::string& smsg, const message* msg, bool transport_encod
{
// unknown header: only encode if contained control characters or non-ASCII characters
LOG << "\t UNKNWON HDR: " << spl->value->key << " :: " << spl->value->value << " <<< \n";
smsg += E( *(br.vchar | br.ws), spl->value->key, spl->value->value, qp::Text);
smsg += encode_header_if_necessary( *(br.vchar | br.ws), spl->value->key, spl->value->value, qp::Text);
smsg += CRLF;
}else{
LOG << "\t KNWON HDR: " << spl->value->key << " :: low_key: " << q->first << " name(): " << q->second->name() << " <<< \n";
q->second->output(smsg, msg, transport_encode);
q->second->output(smsg, msg);
}
}


+ 4
- 4
src/header_generator.hh View File

@ -8,13 +8,13 @@
namespace pEpMIME
{
void generate(std::string& out, sv header_name, const pEp_identity* id , bool transport_encode);
void generate(std::string& out, sv header_name, const identity_list* il, bool transport_encode);
void generate(std::string& out, sv header_name, const pEp_identity* id );
void generate(std::string& out, sv header_name, const identity_list* il);
// different header fields must fulfill different syntax rules. :-/
void generate(std::string& out, const Rule& rule, sv header_name, const stringlist_t* sl , bool transport_encode);
void generate(std::string& out, const Rule& rule, sv header_name, const stringlist_t* sl);
void generate_header(std::string& smsg, const message* msg, bool transport_encode);
void generate_header(std::string& smsg, const message* msg);
} // end of namespace pEpMIME


Loading…
Cancel
Save