src/mime.c
changeset 260 75481f577114
parent 248 49010f5b2346
child 269 7eb06a6984fe
     1.1 --- a/src/mime.c	Fri May 08 16:53:39 2015 +0200
     1.2 +++ b/src/mime.c	Sat May 09 17:55:02 2015 +0200
     1.3 @@ -694,10 +694,11 @@
     1.4      char *subject;
     1.5      char *plaintext;
     1.6  
     1.7 -    assert(msg->longmsg);
     1.8 +    assert(msg->attachments && msg->attachments->next &&
     1.9 +            msg->attachments->next->data);
    1.10  
    1.11      subject = (msg->shortmsg) ? msg->shortmsg : "pEp";
    1.12 -    plaintext = msg->longmsg;
    1.13 +    plaintext = msg->attachments->next->data;
    1.14  
    1.15      mime = part_multiple_new("multipart/encrypted");
    1.16      assert(mime);
    1.17 @@ -767,10 +768,9 @@
    1.18      int r;
    1.19  
    1.20      assert(msg);
    1.21 -    assert(msg->mime == PEP_MIME_none);
    1.22      assert(mimetext);
    1.23  
    1.24 -    if (!(msg && msg->mime == PEP_MIME_none && mimetext))
    1.25 +    if (!(msg && mimetext))
    1.26          return PEP_ILLEGAL_VALUE;
    1.27  
    1.28      *mimetext = NULL;
    1.29 @@ -1307,6 +1307,25 @@
    1.30                  }
    1.31              }
    1.32          }
    1.33 +        else if (_is_multipart(content, "encrypted")) {
    1.34 +            if (msg->longmsg == NULL)
    1.35 +                msg->longmsg = strdup("");
    1.36 +
    1.37 +            clist *partlist = mime->mm_data.mm_multipart.mm_mp_list;
    1.38 +            if (partlist == NULL)
    1.39 +                return PEP_ILLEGAL_VALUE;
    1.40 +
    1.41 +            clistiter *cur;
    1.42 +            for (cur = clist_begin(partlist); cur; cur = clist_next(cur)) {
    1.43 +                struct mailmime *part= clist_content(cur);
    1.44 +                if (part == NULL)
    1.45 +                    return PEP_ILLEGAL_VALUE;
    1.46 +
    1.47 +                status = interpret_MIME(part, msg);
    1.48 +                if (status != PEP_STATUS_OK)
    1.49 +                    return status;
    1.50 +            }
    1.51 +        }
    1.52          else if (_is_multipart(content, NULL)) {
    1.53              clist *partlist = mime->mm_data.mm_multipart.mm_mp_list;
    1.54              if (partlist == NULL)
    1.55 @@ -1357,10 +1376,12 @@
    1.56  
    1.57                  filename = _get_filename(mime);
    1.58  
    1.59 -                msg->attachments = bloblist_add(msg->attachments, data, size,
    1.60 +                bloblist_t *_a = bloblist_add(msg->attachments, data, size,
    1.61                          mime_type, filename);
    1.62 +                if (_a == NULL)
    1.63 +                    return PEP_OUT_OF_MEMORY;
    1.64                  if (msg->attachments == NULL)
    1.65 -                    return PEP_OUT_OF_MEMORY;
    1.66 +                    msg->attachments = _a;
    1.67              }
    1.68          }
    1.69      }
    1.70 @@ -1368,47 +1389,6 @@
    1.71      return PEP_STATUS_OK;
    1.72  }
    1.73  
    1.74 -static PEP_STATUS interpret_PGP_MIME(struct mailmime *mime, message *msg)
    1.75 -{
    1.76 -    assert(mime);
    1.77 -    assert(msg);
    1.78 -
    1.79 -    clist *partlist = mime->mm_data.mm_multipart.mm_mp_list;
    1.80 -    if (partlist == NULL)
    1.81 -        return PEP_ILLEGAL_VALUE;
    1.82 -
    1.83 -    clistiter *cur = clist_begin(partlist);
    1.84 -    if (cur == NULL)
    1.85 -        return PEP_ILLEGAL_VALUE;
    1.86 -
    1.87 -    cur = clist_next(cur);
    1.88 -    if (cur == NULL)
    1.89 -        return PEP_ILLEGAL_VALUE;
    1.90 -
    1.91 -    struct mailmime *second = clist_content(cur);
    1.92 -    if (second == NULL)
    1.93 -        return PEP_ILLEGAL_VALUE;
    1.94 -
    1.95 -    if (second->mm_body == NULL)
    1.96 -        return PEP_ILLEGAL_VALUE;
    1.97 -
    1.98 -    const char *text = second->mm_body->dt_data.dt_text.dt_data;
    1.99 -    if (text == NULL)
   1.100 -        return PEP_ILLEGAL_VALUE;
   1.101 -
   1.102 -    char *_text = strdup(text);
   1.103 -    if (_text == NULL)
   1.104 -        return PEP_OUT_OF_MEMORY;
   1.105 -
   1.106 -    msg->mime = PEP_MIME_fields_omitted;
   1.107 -    msg->enc_format = PEP_enc_PGP_MIME;
   1.108 -
   1.109 -    free(msg->longmsg);
   1.110 -    msg->longmsg = _text;
   1.111 -
   1.112 -    return PEP_STATUS_OK;
   1.113 -}
   1.114 -
   1.115  DYNAMIC_API PEP_STATUS mime_decode_message(
   1.116          const char *mimetext,
   1.117          message **msg
   1.118 @@ -1454,18 +1434,10 @@
   1.119      struct mailmime_content *content = _get_content(mime);
   1.120  
   1.121      if (content) {
   1.122 -        if (_is_PGP_MIME(content)) {
   1.123 -            status = interpret_PGP_MIME(mime->mm_data.mm_message.mm_msg_mime,
   1.124 -                    _msg);
   1.125 -            if (status != PEP_STATUS_OK)
   1.126 -                goto pep_error;
   1.127 -        }
   1.128 -        else {
   1.129 -            status = interpret_MIME(mime->mm_data.mm_message.mm_msg_mime,
   1.130 -                    _msg);
   1.131 -            if (status != PEP_STATUS_OK)
   1.132 -                goto pep_error;
   1.133 -        }
   1.134 +        status = interpret_MIME(mime->mm_data.mm_message.mm_msg_mime,
   1.135 +                _msg);
   1.136 +        if (status != PEP_STATUS_OK)
   1.137 +            goto pep_error;
   1.138      }
   1.139  
   1.140      mailmime_free(mime);