From: Kevin McCarthy Date: Mon, 24 Dec 2018 00:32:52 +0000 (-0800) Subject: Finish protected header write support X-Git-Tag: 2019-10-25~396^2~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85fba328ae05e1048a447d69312b8eb9b9434e92;p=neomutt Finish protected header write support Write out the protected headers when writing the mime header part. Hide protected subjects with $crypt_protected_headers_subject, for outgoing, postponed, and fcc'ed messages. Don't hide in postponed and fcc'ed if $crypt_protected_headers_read isn't set. Add a few missing cases where mime_headers needed to be cleaned up on error. Remove the protected headers for $fcc_clear. Co-authored-by: Richard Russon --- diff --git a/main.c b/main.c index b909879c8..09e0f1eef 100644 --- a/main.c +++ b/main.c @@ -1094,8 +1094,9 @@ int main(int argc, char *argv[], char *envp[]) mutt_env_to_intl(msg->env, NULL, NULL); } - mutt_rfc822_write_header(fout, msg->env, msg->content, - MUTT_WRITE_HEADER_POSTPONE, false); + mutt_rfc822_write_header( + fout, msg->env, msg->content, MUTT_WRITE_HEADER_POSTPONE, false, + CryptProtectedHeadersRead && mutt_should_hide_protected_subject(msg)); if (ResumeEditedDraftFiles) fprintf(fout, "X-Mutt-Resume-Draft: 1\n"); fputc('\n', fout); diff --git a/mutt_header.c b/mutt_header.c index 097969b97..01b45323e 100644 --- a/mutt_header.c +++ b/mutt_header.c @@ -203,7 +203,7 @@ void mutt_edit_headers(const char *editor, const char *body, struct Email *msg, } mutt_env_to_local(msg->env); - mutt_rfc822_write_header(ofp, msg->env, NULL, MUTT_WRITE_HEADER_EDITHDRS, false); + mutt_rfc822_write_header(ofp, msg->env, NULL, MUTT_WRITE_HEADER_EDITHDRS, false, false); fputc('\n', ofp); /* tie off the header. */ /* now copy the body of the message. */ diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 417501700..0995cd0f8 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -1083,6 +1083,17 @@ static void crypt_fetch_signatures(struct Body ***signatures, struct Body *a, in } } +bool mutt_should_hide_protected_subject(struct Email *e) +{ + if (CryptProtectedHeadersWrite && (e->security & ENCRYPT) && !(e->security & INLINE) && + CryptProtectedHeadersSubject && *CryptProtectedHeadersSubject) + { + return true; + } + + return false; +} + /** * mutt_protected_headers_handler - Process a protected header - Implements ::handler_t */ diff --git a/ncrypt/ncrypt.h b/ncrypt/ncrypt.h index 9657a9e63..cf45f27a8 100644 --- a/ncrypt/ncrypt.h +++ b/ncrypt/ncrypt.h @@ -192,6 +192,7 @@ int mutt_is_multipart_signed(struct Body *b); int mutt_is_valid_multipart_pgp_encrypted(struct Body *b); int mutt_protect(struct Email *msg, char *keylist); int mutt_protected_headers_handler(struct Body *m, struct State *s); +bool mutt_should_hide_protected_subject(struct Email *e); int mutt_signed_handler(struct Body *a, struct State *s); /* cryptglue.c */ diff --git a/send.c b/send.c index b21677e4e..026ad138d 100644 --- a/send.c +++ b/send.c @@ -1273,10 +1273,12 @@ static int send_message(struct Email *msg) #endif #ifdef MIXMASTER mutt_rfc822_write_header(tempfp, msg->env, msg->content, - MUTT_WRITE_HEADER_NORMAL, !STAILQ_EMPTY(&msg->chain)); + MUTT_WRITE_HEADER_NORMAL, !STAILQ_EMPTY(&msg->chain), + mutt_should_hide_protected_subject(msg)); #endif #ifndef MIXMASTER - mutt_rfc822_write_header(tempfp, msg->env, msg->content, MUTT_WRITE_HEADER_NORMAL, false); + mutt_rfc822_write_header(tempfp, msg->env, msg->content, MUTT_WRITE_HEADER_NORMAL, + false, mutt_should_hide_protected_subject(msg)); #endif #ifdef USE_SMTP if (old_write_bcc) @@ -1517,7 +1519,11 @@ static int save_fcc(struct Email *msg, char *fcc, size_t fcc_len, struct Body *c struct Body *save_parts = NULL; if ((WithCrypto != 0) && (msg->security & (ENCRYPT | SIGN)) && FccClear) + { msg->content = clear_content; + msg->security &= ~(ENCRYPT | SIGN); + mutt_env_free(&msg->content->mime_headers); + } /* check to see if the user wants copies of all attachments */ if (msg->content->type == TYPE_MULTIPART) @@ -1715,6 +1721,7 @@ static int postpone_message(struct Email *msg, struct Email *cur, char *fcc, int mutt_body_free(&msg->content); msg->content = clear_content; } + mutt_env_free(&msg->content->mime_headers); /* protected headers */ msg->content = mutt_remove_multipart(msg->content); decode_descriptions(msg->content); mutt_unprepare_envelope(msg->env); @@ -2438,6 +2445,7 @@ int ci_send_message(int flags, struct Email *msg, const char *tempfile, msg->content = mutt_remove_multipart(msg->content); } + mutt_env_free(&msg->content->mime_headers); /* protected headers */ msg->content = mutt_remove_multipart(msg->content); decode_descriptions(msg->content); mutt_unprepare_envelope(msg->env); @@ -2464,7 +2472,7 @@ int ci_send_message(int flags, struct Email *msg, const char *tempfile, #endif } - if ((WithCrypto != 0) && (msg->security & ENCRYPT)) + if (WithCrypto) FREE(&pgpkeylist); if ((WithCrypto != 0) && free_clear_content) diff --git a/sendlib.c b/sendlib.c index 7d3dd993c..9d19a3ead 100644 --- a/sendlib.c +++ b/sendlib.c @@ -463,6 +463,9 @@ int mutt_write_mime_header(struct Body *a, FILE *f) if (a->encoding != ENC_7BIT) fprintf(f, "Content-Transfer-Encoding: %s\n", ENCODING(a->encoding)); + if (CryptProtectedHeadersWrite && a->mime_headers) + mutt_rfc822_write_header(f, a->mime_headers, NULL, MUTT_WRITE_HEADER_MIME, false, false); + /* Do NOT add the terminator here!!! */ return ferror(f) ? -1 : 0; } @@ -2204,9 +2207,13 @@ out: * privacy true => will omit any headers which may identify the user. * Output generated is suitable for being sent through * anonymous remailer chains. + * + * hide_protected_subject: replaces the Subject header with + * $crypt_protected_headers_subject in NORMAL or POSTPONE mode. */ -int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach, - enum MuttWriteHeaderMode mode, bool privacy) +int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, + struct Body *attach, enum MuttWriteHeaderMode mode, + bool privacy, bool hide_protected_subject) { char buf[LONG_STRING]; char *p = NULL, *q = NULL; @@ -2287,7 +2294,13 @@ int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach #endif if (env->subject) - mutt_write_one_header(fp, "Subject", env->subject, NULL, 0, 0); + { + if (hide_protected_subject && + (mode == MUTT_WRITE_HEADER_NORMAL || mode == MUTT_WRITE_HEADER_POSTPONE)) + mutt_write_one_header(fp, "Subject", CryptProtectedHeadersSubject, NULL, 0, 0); + else + mutt_write_one_header(fp, "Subject", env->subject, NULL, 0, 0); + } else if (mode == MUTT_WRITE_HEADER_EDITHDRS) fputs("Subject:\n", fp); @@ -3201,9 +3214,9 @@ int mutt_write_fcc(const char *path, struct Email *e, const char *msgid, /* post == 1 => postpone message. * post == 0 => Normal mode. */ - mutt_rfc822_write_header(msg->fp, e->env, e->content, - post ? MUTT_WRITE_HEADER_POSTPONE : MUTT_WRITE_HEADER_NORMAL, - false); + mutt_rfc822_write_header( + msg->fp, e->env, e->content, post ? MUTT_WRITE_HEADER_POSTPONE : MUTT_WRITE_HEADER_NORMAL, + false, CryptProtectedHeadersRead && mutt_should_hide_protected_subject(e)); /* (postponement) if this was a reply of some sort, contains the * Message-ID: of message replied to. Save it using a special X-Mutt- diff --git a/sendlib.h b/sendlib.h index a37d02029..b598a0c54 100644 --- a/sendlib.h +++ b/sendlib.h @@ -78,7 +78,7 @@ void mutt_message_to_7bit(struct Body *a, FILE *fp); void mutt_prepare_envelope(struct Envelope *env, bool final); struct Address *mutt_addrlist_dedupe(struct Address *addr); struct Body * mutt_remove_multipart(struct Body *b); -int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach, enum MuttWriteHeaderMode mode, bool privacy); +int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach, enum MuttWriteHeaderMode mode, bool privacy, bool hide_protected_subject); void mutt_stamp_attachment(struct Body *a); void mutt_unprepare_envelope(struct Envelope *env); void mutt_update_encoding(struct Body *a);