src/etpan_mime.c
branchENGINE-633
changeset 4079 da3b0627a59c
parent 3983 6cb4eabbccd6
child 4080 2f2d566db998
     1.1 --- a/src/etpan_mime.c	Sun Sep 22 15:02:37 2019 +0200
     1.2 +++ b/src/etpan_mime.c	Sun Sep 22 21:41:35 2019 +0200
     1.3 @@ -1893,6 +1893,77 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 +static PEP_STATUS mime_encode_message_sign_only(
     1.8 +        const message * msg,
     1.9 +        bool omit_fields,
    1.10 +        struct mailmime **result
    1.11 +    )
    1.12 +{
    1.13 +    struct mailmime * mime = NULL;
    1.14 +    struct mailmime * submime = NULL;
    1.15 +	struct mailmime_parameter * param;
    1.16 +    int r;
    1.17 +    PEP_STATUS status;
    1.18 +    char *plaintext;
    1.19 +    size_t plaintext_size;
    1.20 +
    1.21 +    assert(msg->attachments && msg->attachments->next &&
    1.22 +            msg->attachments->next->value);
    1.23 +
    1.24 +    plaintext = msg->attachments->next->value;
    1.25 +    plaintext_size = msg->attachments->next->size;
    1.26 +
    1.27 +    mime = part_multiple_new("multipart/signed");
    1.28 +    assert(mime);
    1.29 +    if (mime == NULL)
    1.30 +        goto enomem;
    1.31 +
    1.32 +    if (msg->attachments && msg->attachments->value && msg->attachments->mime_type) {
    1.33 +        if (strcmp(msg->attachments->mime_type, "multipart/signed")) {
    1.34 +            param = mailmime_param_new_with_data("micalg", strdup(msg->attachments->value));
    1.35 +            clist_append(mime->mm_content_type->ct_parameters, param);    
    1.36 +        }
    1.37 +    }
    1.38 +
    1.39 +    r = mailmime_set_body_text(mime, msg->longmsg, strlen(msg->longmsg));
    1.40 +    if (r != 0)
    1.41 +        goto enomem;
    1.42 +            
    1.43 +    pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "signature.asc");
    1.44 +    submime = get_text_part(resource, "application/pgp-signature", msg->attachments->next->value,
    1.45 +            msg->attachments->next->size, MAILMIME_MECHANISM_7BIT);
    1.46 +            
    1.47 +    free_rid_list(resource);
    1.48 +    
    1.49 +    assert(submime);
    1.50 +    if (submime == NULL)
    1.51 +        goto enomem;
    1.52 +
    1.53 +    r = mailmime_smart_add_part(mime, submime);
    1.54 +    assert(r == MAILIMF_NO_ERROR);
    1.55 +    if (r == MAILIMF_ERROR_MEMORY) {
    1.56 +        goto enomem;
    1.57 +    }
    1.58 +    else {
    1.59 +        // mailmime_smart_add_part() takes ownership of submime
    1.60 +        submime = NULL;
    1.61 +    }
    1.62 +
    1.63 +    *result = mime;
    1.64 +    return PEP_STATUS_OK;
    1.65 +
    1.66 +enomem:
    1.67 +    status = PEP_OUT_OF_MEMORY;
    1.68 +
    1.69 +    if (mime)
    1.70 +        mailmime_free(mime);
    1.71 +
    1.72 +    if (submime)
    1.73 +        mailmime_free(submime);
    1.74 +
    1.75 +    return status;
    1.76 +}
    1.77 +
    1.78  PEP_STATUS _mime_encode_message_internal(
    1.79          const message * msg,
    1.80          bool omit_fields,
    1.81 @@ -1935,6 +2006,10 @@
    1.82  
    1.83          case PEP_enc_PEP:
    1.84              NOT_IMPLEMENTED
    1.85 +            
    1.86 +        case PEP_enc_sign_only:
    1.87 +            status = mime_encode_message_sign_only(msg, omit_fields, &mime);
    1.88 +            break;
    1.89  
    1.90          default:
    1.91              NOT_IMPLEMENTED