src/message_api.c
changeset 301 d8b44dc4b0c8
parent 300 55e8daedd030
child 304 c4976f5c95c2
     1.1 --- a/src/message_api.c	Sat May 30 12:47:37 2015 +0200
     1.2 +++ b/src/message_api.c	Sun May 31 13:22:22 2015 +0200
     1.3 @@ -59,23 +59,23 @@
     1.4      assert(msg);
     1.5  
     1.6      bloblist_t *bl;
     1.7 -    for (bl = msg->attachments; bl && bl->data; bl = bl->next) {
     1.8 -        assert(bl && bl->data && bl->size);
     1.9 +    for (bl = msg->attachments; bl && bl->value; bl = bl->next) {
    1.10 +        assert(bl && bl->value && bl->size);
    1.11  
    1.12          if (bl->mime_type == NULL ||
    1.13                      is_mime_type(bl, "application/octet-stream")) {
    1.14              if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
    1.15                      is_fileending(bl, ".key") ||
    1.16                      string_equality(bl->filename, "key.asc"))
    1.17 -                import_key(session, bl->data, bl->size);
    1.18 +                import_key(session, bl->value, bl->size);
    1.19          }
    1.20          else if (is_mime_type(bl, "application/pgp-keys")) {
    1.21 -            import_key(session, bl->data, bl->size);
    1.22 +            import_key(session, bl->value, bl->size);
    1.23          }
    1.24          else if (is_mime_type(bl, "text/plain")) {
    1.25              if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
    1.26                      is_fileending(bl, ".key") || is_fileending(bl, ".asc"))
    1.27 -                import_key(session, bl->data, bl->size);
    1.28 +                import_key(session, bl->value, bl->size);
    1.29          }
    1.30      }
    1.31  }
    1.32 @@ -136,7 +136,7 @@
    1.33      }
    1.34      else if (msg->attachments && msg->attachments->next &&
    1.35              is_mime_type(msg->attachments, "application/pgp-encrypted") &&
    1.36 -            is_PGP_message_text(msg->attachments->next->data)
    1.37 +            is_PGP_message_text(msg->attachments->next->value)
    1.38          ) {
    1.39          msg->enc_format = PEP_enc_PGP_MIME;
    1.40          return PEP_crypt_OpenPGP;
    1.41 @@ -540,9 +540,9 @@
    1.42          bloblist_t *_s = src->attachments;
    1.43          bloblist_t *_d = dst->attachments;
    1.44  
    1.45 -        for (int n = 0; _s && _s->data; _s = _s->next) {
    1.46 +        for (int n = 0; _s && _s->value; _s = _s->next) {
    1.47              int psize = _s->size;
    1.48 -            char *ptext = _s->data;
    1.49 +            char *ptext = _s->value;
    1.50              status = encrypt_and_sign(session, keys, ptext, psize, &ctext,
    1.51                      &csize);
    1.52              if (ctext) {
    1.53 @@ -675,7 +675,12 @@
    1.54          }
    1.55      }
    1.56  
    1.57 -    if (dest_keys_found) {
    1.58 +    if (!dest_keys_found) {
    1.59 +        free_stringlist(keys);
    1.60 +        attach_own_key(session, src);
    1.61 +        return PEP_UNENCRYPTED;
    1.62 +    }
    1.63 +    else {
    1.64          msg = clone_to_empty_message(src);
    1.65          if (msg == NULL)
    1.66              goto enomem;
    1.67 @@ -704,9 +709,6 @@
    1.68              goto pep_error;
    1.69          }
    1.70      }
    1.71 -    else {
    1.72 -        attach_own_key(session, src);
    1.73 -    }
    1.74  
    1.75      free_stringlist(keys);
    1.76  
    1.77 @@ -981,11 +983,12 @@
    1.78   
    1.79      switch (src->enc_format) {
    1.80          case PEP_enc_none:
    1.81 -            status = PEP_UNENCRYPTED;
    1.82 -            break;
    1.83 +            import_attached_keys(session, src);
    1.84 +            *color = PEP_rating_unencrypted;
    1.85 +            return PEP_UNENCRYPTED;
    1.86  
    1.87          case PEP_enc_PGP_MIME:
    1.88 -            ctext = src->attachments->next->data;
    1.89 +            ctext = src->attachments->next->value;
    1.90              csize = src->attachments->next->size;
    1.91  
    1.92              status = cryptotech[crypto].decrypt_and_verify(session, ctext,
    1.93 @@ -1052,7 +1055,7 @@
    1.94                  for (_s = src->attachments; _s; _s = _s->next) {
    1.95                      if (is_encrypted_attachment(_s)) {
    1.96                          stringlist_t *_keylist = NULL;
    1.97 -                        ctext = _s->data;
    1.98 +                        ctext = _s->value;
    1.99                          csize = _s->size;
   1.100  
   1.101                          status = decrypt_and_verify(session, ctext, csize,