ENGINE-74: ENGINE-118: #comment Encrypted text that is put into the first two attachments as application/pgp-encrypted + application/octet-stream is now decrypted correctly and ends up in the longtext portions of the message appropriately. ENGINE-74
authorKrista Grothoff <krista@pep-project.org>
Mon, 14 Nov 2016 13:32:35 +0100
branchENGINE-74
changeset 139626ae3f0cea22
parent 1391 2979c93f1c5b
child 1397 0a64816a6e37
ENGINE-74: ENGINE-118: #comment Encrypted text that is put into the first two attachments as application/pgp-encrypted + application/octet-stream is now decrypted correctly and ends up in the longtext portions of the message appropriately.
src/bloblist.c
src/bloblist.h
src/message_api.c
     1.1 --- a/src/bloblist.c	Sun Nov 13 11:39:03 2016 +0100
     1.2 +++ b/src/bloblist.c	Mon Nov 14 13:32:35 2016 +0100
     1.3 @@ -166,3 +166,14 @@
     1.4      return len;
     1.5  }
     1.6  
     1.7 +bloblist_t* consume_bloblist_head(bloblist_t *bloblist_head) {
     1.8 +    if (!bloblist_head)
     1.9 +        return NULL;
    1.10 +    
    1.11 +    bloblist_t* next = bloblist_head->next;
    1.12 +        
    1.13 +    free(bloblist_head->value);
    1.14 +    free(bloblist_head->mime_type);
    1.15 +    free(bloblist_head->filename);
    1.16 +    free(bloblist_head);
    1.17 +}
     2.1 --- a/src/bloblist.h	Sun Nov 13 11:39:03 2016 +0100
     2.2 +++ b/src/bloblist.h	Mon Nov 14 13:32:35 2016 +0100
     2.3 @@ -91,6 +91,17 @@
     2.4  
     2.5  DYNAMIC_API int bloblist_length(const bloblist_t *bloblist);
     2.6  
     2.7 +// consume_bloblist_head() - internal function to delete head of the bloblist
     2.8 +//
     2.9 +//  parameters:
    2.10 +//      bloblist (in)   bloblist to delete head from
    2.11 +//
    2.12 +//  return value:
    2.13 +//      new head of the bloblist 
    2.14 +//
    2.15 +
    2.16 +bloblist_t* consume_bloblist_head(bloblist_t *bloblist_head);
    2.17 +
    2.18  
    2.19  #ifdef __cplusplus
    2.20  }
     3.1 --- a/src/message_api.c	Sun Nov 13 11:39:03 2016 +0100
     3.2 +++ b/src/message_api.c	Mon Nov 14 13:32:35 2016 +0100
     3.3 @@ -1397,6 +1397,32 @@
     3.4      if(status != PEP_STATUS_OK)
     3.5          return status;
     3.6  
     3.7 +    // Check for encryption stuck in the first 2 attachments instead of the body
     3.8 +    // (This is currently based on AppleMail and a couple of other things
     3.9 +    //  which are broken for us - we may find a more general case to deal with)
    3.10 +    if (!src->longmsg && !src->longmsg_formatted) {
    3.11 +        bloblist_t* attached_head = src->attachments;
    3.12 +        if (attached_head && strcasecmp(attached_head->mime_type, "application/pgp-encrypted")) {
    3.13 +            bloblist_t* enc_att_txt = attached_head->next;
    3.14 +            if (enc_att_txt && strcasecmp(enc_att_txt->mime_type, "application/octet-stream")) {
    3.15 +                size_t enc_att_len = enc_att_txt->size;
    3.16 +                char* newlongmsg = calloc(1, enc_att_len + 1);
    3.17 +                if (newlongmsg == NULL)
    3.18 +                    goto enomem;
    3.19 +                
    3.20 +                memcpy(newlongmsg, enc_att_txt, enc_att_len);
    3.21 +                newlongmsg[enc_att_len] = '\0';
    3.22 +                
    3.23 +                src->longmsg = newlongmsg;
    3.24 +                
    3.25 +                // TODO: delete attachments here
    3.26 +                src->attachments = enc_att_txt->next;
    3.27 +                consume_bloblist_head(attached_head);
    3.28 +                consume_bloblist_head(attached_head);
    3.29 +            }
    3.30 +        }
    3.31 +    }
    3.32 +    
    3.33      PEP_cryptotech crypto = determine_encryption_format(src);
    3.34  
    3.35      *dst = NULL;