attachments knew their position in the attachment vector

MIME-13
Roker 3 years ago
parent 4b3b9d323b
commit b57fb0331a

@ -93,11 +93,13 @@ void Attachment::write_mime_headers(std::string& out) const
SAttachments parse_attachments(const bloblist_t* b)
{
unsigned nr_in_bloblist = 0;
SAttachments ret;
while(b)
{
ret.emplace_back(b);
ret.emplace_back(b, nr_in_bloblist);
b = b->next;
++nr_in_bloblist;
}
return ret;
}

@ -17,12 +17,13 @@ namespace pEpMIME
// refers to data in a bloblist_t. Does NOT any data!
struct Attachment
{
explicit Attachment(const bloblist_t* b)
explicit Attachment(const bloblist_t* b, unsigned nr_in_bloblist)
: data{b->size ? sv{b->value, b->size} : sv{}}
, mime_type{b->mime_type}
, filename{exists(b->filename) ? b->filename : sv{}}
, dtype{b->disposition}
, need_te{need_transport_encoding(data)}
, nr{nr_in_bloblist}
{
if(::pEpMIME::is_inline(b))
{
@ -30,12 +31,13 @@ namespace pEpMIME
}
}
Attachment(sv _data, sv _mime_type)
Attachment(sv _data, sv _mime_type, unsigned nr_in_bloblist)
: data{_data}
, mime_type{_mime_type}
, filename{}
, dtype{ PEP_CONTENT_DISP_OTHER }
, need_te{ need_transport_encoding(data) }
, nr{ nr_in_bloblist }
{ }
@ -51,6 +53,7 @@ namespace pEpMIME
sv filename;
content_disposition_type dtype;
bool need_te; // need transport encoding
unsigned nr;
};
typedef std::vector<Attachment> SAttachments;

@ -101,7 +101,7 @@ void generate_ma_body(std::string& smsg, sv plain_mimetype, sv plain, sv html)
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);
a2.emplace_back(body, mime_type, a2.size());
const std::string delimiter = create_delimiter(a2);
@ -126,10 +126,10 @@ void generate_complex_body(std::string& smsg, unsigned det, const message* msg,
std::vector<Attachment> a2{a};
if(msg->longmsg)
a2.emplace_back(msg->longmsg, longmsg_mimetype);
a2.emplace_back(msg->longmsg, longmsg_mimetype, a2.size());
if(msg->longmsg_formatted)
a2.emplace_back(msg->longmsg_formatted, "text/html");
a2.emplace_back(msg->longmsg_formatted, "text/html", a2.size());
// basic delimiter:
const std::string delimiter = create_delimiter(a2) + "/" + std::to_string(det) + "/";

Loading…
Cancel
Save