merged 0b_attachment branch
authorEdouard Tisserant
Wed, 29 Jun 2016 12:10:15 +0200
changeset 771c04f54a73ef8
parent 770 265f59c3343f
parent 756 8a06c2465017
child 772 77bafcb71517
child 778 2740958d5401
merged 0b_attachment branch
test/message_api_test.cc
     1.1 --- a/src/message_api.c	Mon Jun 27 11:14:12 2016 +0200
     1.2 +++ b/src/message_api.c	Wed Jun 29 12:10:15 2016 +0200
     1.3 @@ -496,46 +496,53 @@
     1.4          bloblist_t *_s = src->attachments;
     1.5          bloblist_t *_d = dst->attachments;
     1.6  
     1.7 -        for (int n = 0; _s && _s->value; _s = _s->next) {
     1.8 -            size_t psize = _s->size;
     1.9 -            ptext = _s->value;
    1.10 -            status = encrypt_and_sign(session, keys, ptext, psize, &ctext,
    1.11 -                &csize);
    1.12 -            if (ctext) {
    1.13 -                char *filename = NULL;
    1.14 -
    1.15 -                if (_s->filename) {
    1.16 -                    size_t len = strlen(_s->filename);
    1.17 -                    filename = calloc(1, len + 5);
    1.18 -                    if (filename == NULL)
    1.19 -                        goto enomem;
    1.20 -
    1.21 -                    strcpy(filename, _s->filename);
    1.22 -                    strcpy(filename + len, ".pgp");
    1.23 -                }
    1.24 -                else {
    1.25 -                    filename = calloc(1, 20);
    1.26 -                    if (filename == NULL)
    1.27 -                        goto enomem;
    1.28 -
    1.29 -                    ++n;
    1.30 -                    n &= 0xffff;
    1.31 -                    snprintf(filename, 20, "Attachment%d.pgp", n);
    1.32 -                }
    1.33 -
    1.34 -                char *_ctext = malloc(csize);
    1.35 -                assert(_ctext);
    1.36 -                if (_ctext == NULL)
    1.37 -                    goto enomem;
    1.38 -                memcpy(_ctext, ctext, csize);
    1.39 -
    1.40 -                _d = bloblist_add(_d, _ctext, csize, "application/octet-stream",
    1.41 -                    filename);
    1.42 +        for (int n = 0; _s; _s = _s->next) {
    1.43 +            if (_s->value == NULL && _s->size == 0) {
    1.44 +                _d = bloblist_add(_d, NULL, 0, _s->mime_type, _s->filename);
    1.45                  if (_d == NULL)
    1.46                      goto enomem;
    1.47              }
    1.48              else {
    1.49 -                goto pep_error;
    1.50 +                size_t psize = _s->size;
    1.51 +                ptext = _s->value;
    1.52 +                status = encrypt_and_sign(session, keys, ptext, psize, &ctext,
    1.53 +                    &csize);
    1.54 +                if (ctext) {
    1.55 +                    char *filename = NULL;
    1.56 +
    1.57 +                    if (_s->filename) {
    1.58 +                        size_t len = strlen(_s->filename);
    1.59 +                        filename = calloc(1, len + 5);
    1.60 +                        if (filename == NULL)
    1.61 +                            goto enomem;
    1.62 +
    1.63 +                        strcpy(filename, _s->filename);
    1.64 +                        strcpy(filename + len, ".pgp");
    1.65 +                    }
    1.66 +                    else {
    1.67 +                        filename = calloc(1, 20);
    1.68 +                        if (filename == NULL)
    1.69 +                            goto enomem;
    1.70 +
    1.71 +                        ++n;
    1.72 +                        n &= 0xffff;
    1.73 +                        snprintf(filename, 20, "Attachment%d.pgp", n);
    1.74 +                    }
    1.75 +
    1.76 +                    char *_ctext = malloc(csize);
    1.77 +                    assert(_ctext);
    1.78 +                    if (_ctext == NULL)
    1.79 +                        goto enomem;
    1.80 +                    memcpy(_ctext, ctext, csize);
    1.81 +
    1.82 +                    _d = bloblist_add(_d, _ctext, csize, "application/octet-stream",
    1.83 +                        filename);
    1.84 +                    if (_d == NULL)
    1.85 +                        goto enomem;
    1.86 +                }
    1.87 +                else {
    1.88 +                    goto pep_error;
    1.89 +                }
    1.90              }
    1.91          }
    1.92      }
    1.93 @@ -1273,8 +1280,14 @@
    1.94                  }
    1.95  
    1.96                  bloblist_t *_s;
    1.97 -                for (_s = src->attachments; _s && _s->value; _s = _s->next) {
    1.98 -                    if (is_encrypted_attachment(_s)) {
    1.99 +                for (_s = src->attachments; _s; _s = _s->next) {
   1.100 +                    if (_s->value == NULL && _s->size == 0){
   1.101 +                        _m = bloblist_add(_m, NULL, 0, _s->mime_type, _s->filename);
   1.102 +                        if (_m == NULL)
   1.103 +                            goto enomem;
   1.104 +
   1.105 +                    }
   1.106 +                    else if (is_encrypted_attachment(_s)) {
   1.107                          stringlist_t *_keylist = NULL;
   1.108                          char *attctext;
   1.109                          size_t attcsize;
     2.1 --- a/src/mime.c	Mon Jun 27 11:14:12 2016 +0200
     2.2 +++ b/src/mime.c	Wed Jun 29 12:10:15 2016 +0200
     2.3 @@ -693,8 +693,6 @@
     2.4  
     2.5          bloblist_t *_a;
     2.6          for (_a = msg->attachments; _a != NULL; _a = _a->next) {
     2.7 -            //assert(_a->value);
     2.8 -            //assert(_a->size);
     2.9  
    2.10              status = mime_attachment(_a, &submime);
    2.11              if (status != PEP_STATUS_OK)