shelving changes to work on gnupg stuff message-2.0
authorKrista Bennett <krista@pep-project.org>
Thu, 06 Jul 2017 15:44:51 +0200
branchmessage-2.0
changeset 19075ae2e838afd6
parent 1906 104b801dc351
child 1976 16aba9c71124
shelving changes to work on gnupg stuff
src/message_api.c
     1.1 --- a/src/message_api.c	Fri Jun 30 08:14:59 2017 +0200
     1.2 +++ b/src/message_api.c	Thu Jul 06 15:44:51 2017 +0200
     1.3 @@ -312,6 +312,84 @@
     1.4      return PEP_STATUS_OK;
     1.5  }
     1.6  
     1.7 +
     1.8 +static message* extract_minimal_envelope(const message* src, 
     1.9 +                                         PEP_msg_direction direct) {
    1.10 +    
    1.11 +    message* envelope = new_message(direct);
    1.12 +    if (!envelope)
    1.13 +        return NULL;
    1.14 +        
    1.15 +    envelope->shortmsg = strdup("pEp");
    1.16 +    if (!envelope->shortmsg)
    1.17 +        return NULL;
    1.18 +
    1.19 +    if (src->from) {
    1.20 +        envelope->from = identity_dup(src->from);
    1.21 +        if (!envelope->from)
    1.22 +            return NULL;
    1.23 +    }
    1.24 +
    1.25 +    if (src->to) {
    1.26 +        envelope->to = identity_list_dup(src->to);
    1.27 +        if (!envelope->to)
    1.28 +            return NULL;
    1.29 +    }
    1.30 +
    1.31 +    if (src->cc) {
    1.32 +        envelope->cc = identity_list_dup(src->cc);
    1.33 +        if (!envelope->cc)
    1.34 +            return NULL;
    1.35 +    }
    1.36 +
    1.37 +    if (src->bcc) {
    1.38 +        envelope->bcc = identity_list_dup(src->bcc);
    1.39 +        if (!envelope->bcc)
    1.40 +            return NULL;
    1.41 +    }
    1.42 +
    1.43 +    /* DO WE WANT TO EXPOSE THIS??? */
    1.44 +    if (src->reply_to) {
    1.45 +        envelope->reply_to = identity_list_dup(src->reply_to);
    1.46 +        if (!envelope->reply_to)
    1.47 +            return NULL;
    1.48 +    }
    1.49 +
    1.50 +    envelope->enc_format = src->enc_format;        
    1.51 +    
    1.52 +    return envelope;
    1.53 +}
    1.54 +
    1.55 +static message* wrap_message_as_attachment(message* envelope, 
    1.56 +    const message* attachment) {
    1.57 +    
    1.58 +    message* _envelope = NULL;
    1.59 +    
    1.60 +    if (!envelope) {
    1.61 +        _envelope = extract_minimal_envelope(attachment, PEP_dir_outgoing);
    1.62 +        envelope = _envelope;
    1.63 +    }
    1.64 +    
    1.65 +    char* message_text = NULL;
    1.66 +    /* Turn message into a MIME-blob */
    1.67 +    PEP_STATUS status = mime_encode_message(attachment, false, &message_text);
    1.68 +    
    1.69 +    if (status != PEP_STATUS_OK) {
    1.70 +        free(_envelope);
    1.71 +        return NULL;
    1.72 +    }
    1.73 +    
    1.74 +    size_t message_len = strlen(message_text);
    1.75 +    
    1.76 +    bloblist_t* message_blob = new_bloblist(message_text, message_len,
    1.77 +                                            "message/rfc822", NULL);
    1.78 +    
    1.79 +    envelope->attachments = message_blob;
    1.80 +    envelope->pep_message_version = "2.0"; // FIXME - macro, elsewhere
    1.81 +    
    1.82 +    return envelope;
    1.83 +}
    1.84 +
    1.85  static message * clone_to_empty_message(const message * src)
    1.86  {
    1.87      PEP_STATUS status;
    1.88 @@ -1094,6 +1172,7 @@
    1.89      PEP_STATUS status = PEP_STATUS_OK;
    1.90      message * msg = NULL;
    1.91      stringlist_t * keys = NULL;
    1.92 +    message* wrapped_src = NULL;
    1.93  
    1.94      assert(session);
    1.95      assert(src);
    1.96 @@ -1221,21 +1300,22 @@
    1.97          return ADD_TO_LOG(PEP_UNENCRYPTED);
    1.98      }
    1.99      else {
   1.100 -        msg = clone_to_empty_message(src);
   1.101 +        wrapped_src = wrap_message_as_attachment(NULL, src);
   1.102 +        msg = clone_to_empty_message(wrapped_src);
   1.103          if (msg == NULL)
   1.104              goto enomem;
   1.105  
   1.106          if (!(flags & PEP_encrypt_flag_force_no_attached_key))
   1.107 -            attach_own_key(session, src);
   1.108 +            attach_own_key(session, wrapped_src);
   1.109  
   1.110          switch (enc_format) {
   1.111          case PEP_enc_PGP_MIME:
   1.112          case PEP_enc_PEP: // BUG: should be implemented extra
   1.113 -            status = encrypt_PGP_MIME(session, src, keys, msg, flags);
   1.114 +            status = encrypt_PGP_MIME(session, wrapped_src, keys, msg, flags);
   1.115              break;
   1.116  
   1.117          case PEP_enc_pieces:
   1.118 -            status = encrypt_PGP_in_pieces(session, src, keys, msg, flags);
   1.119 +            status = encrypt_PGP_in_pieces(session, wrapped_src, keys, msg, flags);
   1.120              break;
   1.121  
   1.122          /* case PEP_enc_PEP:
   1.123 @@ -1257,16 +1337,19 @@
   1.124  
   1.125      free_stringlist(keys);
   1.126  
   1.127 +    // Taken care of in wrap_message
   1.128 +    /*
   1.129      if (msg && msg->shortmsg == NULL) {
   1.130          msg->shortmsg = strdup("pEp");
   1.131          assert(msg->shortmsg);
   1.132          if (msg->shortmsg == NULL)
   1.133              goto enomem;
   1.134      }
   1.135 +    */
   1.136  
   1.137      if (msg) {
   1.138          decorate_message(msg, PEP_rating_undefined, NULL);
   1.139 -        if (src->id) {
   1.140 +        if (wrapped_src->id) {
   1.141              msg->id = strdup(src->id);
   1.142              assert(msg->id);
   1.143              if (msg->id == NULL)
   1.144 @@ -1275,6 +1358,7 @@
   1.145      }
   1.146  
   1.147      *dst = msg;
   1.148 +//    free_message(wrapped_msg);
   1.149      return ADD_TO_LOG(status);
   1.150  
   1.151  enomem:
   1.152 @@ -1283,7 +1367,7 @@
   1.153  pep_error:
   1.154      free_stringlist(keys);
   1.155      free_message(msg);
   1.156 -
   1.157 +    free_message(wrapped_src);
   1.158      return ADD_TO_LOG(status);
   1.159  }
   1.160