ENGINE-309: fix non-pEp recip attachments
authorKrista Bennett <krista@pep-project.org>
Tue, 07 Nov 2017 16:16:11 +0100
changeset 2280fd04614429ad
parent 2279 41b26d4e30ee
child 2281 7f826b2f0abd
ENGINE-309: fix non-pEp recip attachments
src/message_api.c
     1.1 --- a/src/message_api.c	Tue Nov 07 14:29:11 2017 +0100
     1.2 +++ b/src/message_api.c	Tue Nov 07 16:16:11 2017 +0100
     1.3 @@ -20,6 +20,50 @@
     1.4  #define _MAX(A, B) ((B) > (A) ? (B) : (A))
     1.5  #endif
     1.6  
     1.7 +static bool is_a_pEpmessage(const message *msg)
     1.8 +{
     1.9 +    for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
    1.10 +        if (strcasecmp(i->value->key, "X-pEp-Version") == 0)
    1.11 +            return true;
    1.12 +    }
    1.13 +    return false;
    1.14 +}
    1.15 +
    1.16 +// update comm_type to pEp_ct_pEp if needed
    1.17 +
    1.18 +static bool is_wrapper(message* src) {
    1.19 +    bool retval = false;
    1.20 +    
    1.21 +    if (src) {
    1.22 +        unsigned char pepstr[] = PEP_SUBJ_STRING;
    1.23 +        if (is_a_pEpmessage(src) || (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0 ||
    1.24 +            _unsigned_signed_strcmp(pepstr, src->shortmsg, PEP_SUBJ_BYTELEN) == 0) ||
    1.25 +            (strcmp(src->shortmsg, "p=p") == 0)) {
    1.26 +            char* plaintext = src->longmsg;
    1.27 +            if (plaintext) {
    1.28 +                const char *line_end = strchr(plaintext, '\n');
    1.29 +
    1.30 +                if (line_end != NULL) {
    1.31 +                    size_t n = line_end - plaintext;
    1.32 +                    
    1.33 +                    char* copycat = calloc(n + 1, 1);
    1.34 +                    
    1.35 +                    if (copycat) {
    1.36 +                        strlcpy(copycat, plaintext, n+1);
    1.37 +                        
    1.38 +                        if (strstr(copycat, PEP_MSG_WRAP_KEY) && strstr(copycat, "OUTER"))
    1.39 +                            retval = true;
    1.40 +                        
    1.41 +                        free(copycat);
    1.42 +                    }
    1.43 +                }
    1.44 +            }
    1.45 +        }
    1.46 +    }
    1.47 +    return retval;
    1.48 +}
    1.49 +
    1.50 +
    1.51  static const stringpair_t* search_optfields(message* msg, const char* key) {
    1.52      stringpair_list_t* opt_fields = msg->opt_fields;
    1.53      
    1.54 @@ -877,7 +921,8 @@
    1.55      _src->longmsg_formatted = src->longmsg_formatted;
    1.56      _src->attachments = src->attachments;
    1.57      _src->enc_format = PEP_enc_none;
    1.58 -    status = _mime_encode_message_internal(_src, true, &mimetext, false);
    1.59 +    bool mime_encode = !is_wrapper(_src);
    1.60 +    status = _mime_encode_message_internal(_src, true, &mimetext, mime_encode);
    1.61      assert(status == PEP_STATUS_OK);
    1.62      if (status != PEP_STATUS_OK)
    1.63          goto pep_error;
    1.64 @@ -1670,17 +1715,6 @@
    1.65      return ADD_TO_LOG(status);
    1.66  }
    1.67  
    1.68 -static bool is_a_pEpmessage(const message *msg)
    1.69 -{
    1.70 -    for (stringpair_list_t *i = msg->opt_fields; i && i->value ; i=i->next) {
    1.71 -        if (strcasecmp(i->value->key, "X-pEp-Version") == 0)
    1.72 -            return true;
    1.73 -    }
    1.74 -    return false;
    1.75 -}
    1.76 -
    1.77 -// update comm_type to pEp_ct_pEp if needed
    1.78 -
    1.79  static PEP_STATUS _update_identity_for_incoming_message(
    1.80          PEP_SESSION session,
    1.81          const message *src
    1.82 @@ -1942,6 +1976,8 @@
    1.83      return false;
    1.84  }
    1.85  
    1.86 +
    1.87 +
    1.88  static PEP_STATUS unencapsulate_hidden_fields(message* src, message* msg,
    1.89                                                char** msg_wrap_info) {
    1.90      if (!src)