Browse Source

implement new engine mime.h API

MIME-13
Roker 2 years ago
parent
commit
5ac4397ef5
3 changed files with 15 additions and 43 deletions
  1. +5
    -36
      src/pEpEngine_mime.cc
  2. +6
    -3
      src/pEpMIME.cc
  3. +4
    -4
      src/pEpMIME.hh

+ 5
- 36
src/pEpEngine_mime.cc View File

@ -14,41 +14,10 @@
extern "C"
{
DYNAMIC_API PEP_STATUS mime_decode_message(
const char *mimetext,
size_t size,
message **msg
)
{
assert(msg);
assert(mimetext);
if (!(msg && mimetext))
return PEP_ILLEGAL_VALUE;
PEP_STATUS status = PEP_STATUS_OK;
*msg = nullptr;
try{
message* m = pEpMIME::parse_message(mimetext, size);
if(m)
{
*msg = m;
}else{
status = PEP_OUT_OF_MEMORY;
}
}catch(...)
{
status = PEP_UNKNOWN_ERROR;
}
return status;
}
DYNAMIC_API PEP_STATUS _mime_decode_message_internal(
const char *mimetext,
size_t size,
message **msg,
bool* raise_msg_attachment
bool* has_possible_pEp_msg
)
{
assert(msg);
@ -61,7 +30,7 @@ extern "C"
*msg = nullptr;
try{
message* m = pEpMIME::parse_message(mimetext, size, raise_msg_attachment);
message* m = pEpMIME::parse_message(mimetext, size, has_possible_pEp_msg);
if(!m)
{
*msg = m;
@ -76,11 +45,11 @@ extern "C"
}
PEP_STATUS _mime_encode_message_internal(
PEP_STATUS mime_encode_message(
const message * msg,
bool omit_fields,
char **mimetext,
bool transport_encode
bool has_pEp_msg_attachment
)
{
assert(msg);
@ -93,7 +62,7 @@ extern "C"
*mimetext = nullptr;
try{
char* t = pEpMIME::generate_message(msg, omit_fields, transport_encode);
char* t = pEpMIME::generate_message(msg, omit_fields, has_pEp_msg_attachment);
if (t)
{
*mimetext = t;


+ 6
- 3
src/pEpMIME.cc View File

@ -153,12 +153,12 @@ message* parse_message(const char* mime_text, size_t length, bool* raise_attachm
}
char* generate_message(const message* msg, bool omit_fields, bool transport_encode)
char* generate_message(const message* msg, bool omit_fields, bool has_pEp_msg_attachment)
{
if(msg == nullptr)
return nullptr;
LOG << "GEN_MSG omit=" << omit_fields << ", te=" << transport_encode << std::endl;
LOG << "GEN_MSG omit=" << omit_fields << ", has_pEp_msg_att=" << has_pEp_msg_attachment << std::endl;
const auto attachments = parse_attachments(msg->attachments);
const unsigned inline_attachments = std::count_if(
@ -176,11 +176,14 @@ char* generate_message(const message* msg, bool omit_fields, bool transport_enco
std::string smsg;
if(omit_fields == false)
{
generate_header(smsg, msg, transport_encode);
generate_header(smsg, msg);
}
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


+ 4
- 4
src/pEpMIME.hh View File

@ -31,12 +31,12 @@ const unsigned MaxMultipartNestingLevel = 100;
// parameters:
// mime_text (in) : an "Internet Message"
// length (in) : length of the mime_text, because it might contain NUL bytes
// raise_attachment(out): if not nullptr, the value is set to true if the attachment needs to be raised (pEp message format 2.x)
// has_possible_pEp_msg(out): if not nullptr, the value is set to true if the attachment needs to be raised (pEp message format 2.x)
//
// return value:
// a message struct that must be freed via free_message() or NULL on error.
//
message* parse_message(const char* mime_text, size_t length, bool* raise_attachment = nullptr);
message* parse_message(const char* mime_text, size_t length, bool* has_possible_pEp_msg = nullptr);
// Generates an RFC 5322 compliant Internet Message from the given message struct.
@ -44,13 +44,13 @@ message* parse_message(const char* mime_text, size_t length, bool* raise_attachm
// parameters:
// msg (in) : the message that shall be serialized.
// omit_fields(in) : only encode message body and attachments
// transport_encode (in) : apply transport encoding (UTF-8 otherwise)
// has_pEp_msg_attachment(in) : set forwared="no" to 1st attachment, if mime_type=="message/rfc822"
//
// return value:
// a string holding an RFC-compliant "Internet Message", or NULL on error.
// the string must be freed via pEp_free().
//
char* generate_message(const message* msg, bool omit_fields, bool transport_encode=true);
char* generate_message(const message* msg, bool omit_fields, bool has_pEp_msg_attachment=false);
} // end of namespace pEpMIME


Loading…
Cancel
Save