...
authorvb
Mon, 23 Feb 2015 14:32:12 +0100
changeset 6765cc950ce03d
parent 66 805bfae3cdc4
child 68 3cbe911b2538
...
src/message_api.c
src/pEpEngine.c
src/transport.h
     1.1 --- a/src/message_api.c	Sun Feb 22 15:49:02 2015 +0100
     1.2 +++ b/src/message_api.c	Mon Feb 23 14:32:12 2015 +0100
     1.3 @@ -48,7 +48,12 @@
     1.4      assert(src);
     1.5      assert(dst);
     1.6      *dst = NULL;
     1.7 -    assert(format != PEP_enc_none);
     1.8 +    assert(format != PEP_enc_none && format != PEP_enc_none_MIME);
     1.9 +
    1.10 +    // TODO: we don't yet support re-encrypting already encrypted messages
    1.11 +    if ((int) src->format >= (int) PEP_enc_pieces) {
    1.12 +        NOT_IMPLEMENTED   
    1.13 +    }
    1.14  
    1.15      pEp_identity *from = identity_dup(src->from);
    1.16      if (from == NULL)
    1.17 @@ -109,7 +114,6 @@
    1.18  
    1.19          switch (format) {
    1.20          case PEP_enc_MIME_multipart: {
    1.21 -            char *resulttext = NULL;
    1.22              bool free_ptext = false;
    1.23  
    1.24              msg->enc_format = PEP_enc_MIME_multipart;
    1.25 @@ -124,18 +128,31 @@
    1.26                  ptext = src->longmsg;
    1.27              }
    1.28  
    1.29 -            status = mime_encode_text(ptext, src->longmsg_formatted,
    1.30 -                    src->attachments, &resulttext);
    1.31 -            assert(status == PEP_STATUS_OK);
    1.32 +            if (src->format == PEP_enc_none) {
    1.33 +                char *_ptext = ptext;
    1.34 +                status = mime_encode_text(_ptext, src->longmsg_formatted,
    1.35 +                        src->attachments, &ptext);
    1.36 +                assert(status == PEP_STATUS_OK);
    1.37 +                if (free_ptext)
    1.38 +                    free(_ptext);
    1.39 +                assert(ptext);
    1.40 +                if (ptext == NULL)
    1.41 +                    goto pep_error;
    1.42 +                free_ptext = true;
    1.43 +            }
    1.44 +            else if (src->format == PEP_enc_none_MIME) {
    1.45 +                assert(src->longmsg);
    1.46 +                if (src->longmsg == NULL) {
    1.47 +                    status = PEP_ILLEGAL_VALUE;
    1.48 +                    goto pep_error;
    1.49 +                }
    1.50 +                ptext = src->longmsg;
    1.51 +            }
    1.52 +
    1.53 +            status = encrypt_and_sign(session, keys, ptext, strlen(ptext),
    1.54 +                    &ctext, &csize);
    1.55              if (free_ptext)
    1.56                  free(ptext);
    1.57 -            assert(resulttext);
    1.58 -            if (resulttext == NULL)
    1.59 -                goto pep_error;
    1.60 -            
    1.61 -            status = encrypt_and_sign(session, keys, resulttext, strlen(resulttext),
    1.62 -                    &ctext, &csize);
    1.63 -            free(resulttext);
    1.64              if (ctext) {
    1.65                  msg->longmsg = strdup(ctext);
    1.66                  if (msg->longmsg == NULL)
    1.67 @@ -150,6 +167,11 @@
    1.68          case PEP_enc_pieces:
    1.69              msg->enc_format = PEP_enc_pieces;
    1.70  
    1.71 +            // TODO: decoding MIME
    1.72 +            if (src->format == PEP_enc_none_MIME) {
    1.73 +                NOT_IMPLEMENTED
    1.74 +            }
    1.75 +
    1.76              if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
    1.77                  ptext = combine_short_and_long(src);
    1.78                  if (ptext == NULL)
     2.1 --- a/src/pEpEngine.c	Sun Feb 22 15:49:02 2015 +0100
     2.2 +++ b/src/pEpEngine.c	Mon Feb 23 14:32:12 2015 +0100
     2.3 @@ -26,9 +26,8 @@
     2.4      // removed by calling caveat (see documentation)
     2.5  
     2.6      ++init_count;
     2.7 -    if (init_count == 0) {
     2.8 +    if (init_count == 0)
     2.9          in_first = true;
    2.10 -    }
    2.11  
    2.12  	assert(session);
    2.13  	*session = NULL;
     3.1 --- a/src/transport.h	Sun Feb 22 15:49:02 2015 +0100
     3.2 +++ b/src/transport.h	Mon Feb 23 14:32:12 2015 +0100
     3.3 @@ -154,8 +154,10 @@
     3.4                                              // encrypted
     3.5      PEP_enc_pieces,                         // message is encrypted but not
     3.6                                              // MIME encoded
     3.7 -    PEP_enc_MIME_multipart                  // message is encrypted and MIME
     3.8 -                                            // encoded
     3.9 +    PEP_enc_MIME_multipart,                 // message is encrypted and MIME
    3.10 +                                            // encoded; this is being used for
    3.11 +                                            // PGP/MIME as well as S/MIME
    3.12 +    PEP_enc_PEP                             // pEp encryption format
    3.13  } PEP_enc_format;
    3.14  
    3.15  struct _message_ref_list;