1.1 --- a/src/message_api.c Mon Feb 22 13:56:31 2016 +0100
1.2 +++ b/src/message_api.c Mon Feb 22 14:24:28 2016 +0100
1.3 @@ -305,10 +305,18 @@
1.4 dst->enc_format = PEP_enc_PGP_MIME;
1.5
1.6 if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
1.7 - ptext = combine_short_and_long(src->shortmsg, src->longmsg);
1.8 - if (ptext == NULL)
1.9 - goto enomem;
1.10 - free_ptext = true;
1.11 + if (session->unencrypted_subject) {
1.12 + dst->shortmsg = strdup(src->shortmsg);
1.13 + if (dst->shortmsg == NULL)
1.14 + goto enomem;
1.15 + ptext = src->longmsg;
1.16 + }
1.17 + else {
1.18 + ptext = combine_short_and_long(src->shortmsg, src->longmsg);
1.19 + if (ptext == NULL)
1.20 + goto enomem;
1.21 + free_ptext = true;
1.22 + }
1.23 }
1.24 else if (src->longmsg) {
1.25 ptext = src->longmsg;
1.26 @@ -389,6 +397,8 @@
1.27 PEP_STATUS status = PEP_STATUS_OK;
1.28 char *ctext;
1.29 size_t csize;
1.30 + char *ptext;
1.31 + bool free_ptext = false;
1.32
1.33 assert(dst->longmsg == NULL);
1.34 assert(dst->attachments == NULL);
1.35 @@ -396,13 +406,24 @@
1.36 dst->enc_format = PEP_enc_pieces;
1.37
1.38 if (src->shortmsg && src->shortmsg[0] && strcmp(src->shortmsg, "pEp") != 0) {
1.39 - char *ptext = combine_short_and_long(src->shortmsg, src->longmsg);
1.40 - if (ptext == NULL)
1.41 - goto enomem;
1.42 + if (session->unencrypted_subject) {
1.43 + dst->shortmsg = strdup(src->shortmsg);
1.44 + if (dst->shortmsg == NULL)
1.45 + goto enomem;
1.46 + ptext = src->longmsg;
1.47 + }
1.48 + else {
1.49 + ptext = combine_short_and_long(src->shortmsg, src->longmsg);
1.50 + if (ptext == NULL)
1.51 + goto enomem;
1.52 + free_ptext = true;
1.53 + }
1.54
1.55 status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext,
1.56 &csize);
1.57 - free(ptext);
1.58 + if (free_ptext)
1.59 + free(ptext);
1.60 + free_ptext = false;
1.61 if (ctext) {
1.62 dst->longmsg = strndup(ctext, csize);
1.63 assert(dst->longmsg);
1.64 @@ -414,7 +435,7 @@
1.65 }
1.66 }
1.67 else if (src->longmsg && src->longmsg[0]) {
1.68 - char *ptext = src->longmsg;
1.69 + ptext = src->longmsg;
1.70 status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext,
1.71 &csize);
1.72 if (ctext) {
1.73 @@ -434,7 +455,7 @@
1.74 }
1.75
1.76 if (src->longmsg_formatted && src->longmsg_formatted[0]) {
1.77 - char *ptext = src->longmsg_formatted;
1.78 + ptext = src->longmsg_formatted;
1.79 status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext,
1.80 &csize);
1.81 if (ctext) {
1.82 @@ -468,7 +489,7 @@
1.83
1.84 for (int n = 0; _s && _s->value; _s = _s->next) {
1.85 size_t psize = _s->size;
1.86 - char *ptext = _s->value;
1.87 + ptext = _s->value;
1.88 status = encrypt_and_sign(session, keys, ptext, psize, &ctext,
1.89 &csize);
1.90 if (ctext) {
1.91 @@ -516,6 +537,8 @@
1.92 status = PEP_OUT_OF_MEMORY;
1.93
1.94 pep_error:
1.95 + if (free_ptext)
1.96 + free(ptext);
1.97 return status;
1.98 }
1.99