From: Kevin McCarthy Date: Mon, 24 Dec 2018 00:32:52 +0000 (-0800) Subject: Finish protected header write support. X-Git-Tag: mutt-1-12-rel~165 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=66e0958411fb4477f51528921836f41a61075daf;p=mutt 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. --- diff --git a/crypt.c b/crypt.c index f68d4f55..e1ab409e 100644 --- a/crypt.c +++ b/crypt.c @@ -926,6 +926,17 @@ static void crypt_fetch_signatures (BODY ***signatures, BODY *a, int *n) } } +int mutt_should_hide_protected_subject (HEADER *h) +{ + if (option (OPTCRYPTPROTHDRSWRITE) && + (h->security & ENCRYPT) && + !(h->security & INLINE) && + ProtHdrSubject && *ProtHdrSubject) + return 1; + + return 0; +} + int mutt_protected_headers_handler (BODY *a, STATE *s) { if (option (OPTCRYPTPROTHDRSREAD) && a->mime_headers) diff --git a/headers.c b/headers.c index e9cf4153..9b60023c 100644 --- a/headers.c +++ b/headers.c @@ -53,7 +53,7 @@ void mutt_edit_headers (const char *editor, } mutt_env_to_local (msg->env); - mutt_write_rfc822_header (ofp, msg->env, NULL, MUTT_WRITE_HEADER_EDITHDRS, 0); + mutt_write_rfc822_header (ofp, msg->env, NULL, MUTT_WRITE_HEADER_EDITHDRS, 0, 0); fputc ('\n', ofp); /* tie off the header. */ /* now copy the body of the message. */ diff --git a/main.c b/main.c index 6f7b4a11..347521ea 100644 --- a/main.c +++ b/main.c @@ -1228,7 +1228,9 @@ int main (int argc, char **argv, char **environ) } mutt_write_rfc822_header (fout, msg->env, msg->content, - MUTT_WRITE_HEADER_POSTPONE, 0); + MUTT_WRITE_HEADER_POSTPONE, 0, + option (OPTCRYPTPROTHDRSREAD) && + mutt_should_hide_protected_subject (msg)); if (option (OPTRESUMEEDITEDDRAFTFILES)) fprintf (fout, "X-Mutt-Resume-Draft: 1\n"); fputc ('\n', fout); diff --git a/mutt_crypt.h b/mutt_crypt.h index 1fa3f359..2a368d1a 100644 --- a/mutt_crypt.h +++ b/mutt_crypt.h @@ -122,6 +122,8 @@ int mutt_is_application_pgp (BODY *); int mutt_is_application_smime (BODY *); +int mutt_should_hide_protected_subject (HEADER *); + int mutt_protected_headers_handler (BODY *, STATE *); int mutt_signed_handler (BODY *, STATE *); diff --git a/protos.h b/protos.h index 2e4d851f..b3a6e426 100644 --- a/protos.h +++ b/protos.h @@ -389,7 +389,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char int mutt_write_mime_body (BODY *, FILE *); int mutt_write_mime_header (BODY *, FILE *); int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, int flags); -int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, mutt_write_header_mode, int); +int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, mutt_write_header_mode, int, int); void mutt_write_references (LIST *, FILE *, int); int mutt_yesorno (const char *, int); void mutt_set_header_color(CONTEXT *, HEADER *); diff --git a/send.c b/send.c index 8d6b28a5..16dad8d5 100644 --- a/send.c +++ b/send.c @@ -1000,11 +1000,13 @@ static int send_message (HEADER *msg) #endif #ifdef MIXMASTER mutt_write_rfc822_header (tempfp, msg->env, msg->content, - MUTT_WRITE_HEADER_NORMAL, msg->chain ? 1 : 0); + MUTT_WRITE_HEADER_NORMAL, msg->chain ? 1 : 0, + mutt_should_hide_protected_subject (msg)); #endif #ifndef MIXMASTER mutt_write_rfc822_header (tempfp, msg->env, msg->content, - MUTT_WRITE_HEADER_NORMAL, 0); + MUTT_WRITE_HEADER_NORMAL, 0, + mutt_should_hide_protected_subject (msg)); #endif #ifdef USE_SMTP if (old_write_bcc) @@ -1079,7 +1081,11 @@ static int save_fcc (HEADER *msg, char *fcc, size_t fcc_len, return rc; if (WithCrypto && (msg->security & (ENCRYPT | SIGN)) && option (OPTFCCCLEAR)) + { msg->content = clear_content; + msg->security &= ~(ENCRYPT | SIGN); + mutt_free_envelope (&msg->content->mime_headers); + } /* check to see if the user wants copies of all attachments */ if (query_quadoption (OPT_FCCATTACH, _("Save attachments in Fcc?")) != MUTT_YES && @@ -1391,6 +1397,7 @@ static int postpone_message (HEADER *msg, HEADER *cur, char *fcc, int flags) mutt_free_body (&msg->content); msg->content = clear_content; } + mutt_free_envelope (&msg->content->mime_headers); /* protected headers */ msg->content = mutt_remove_multipart (msg->content); decode_descriptions (msg->content); mutt_unprepare_envelope (msg->env); @@ -2033,6 +2040,7 @@ main_loop: msg->content = mutt_remove_multipart (msg->content); } + mutt_free_envelope (&msg->content->mime_headers); /* protected headers */ msg->content = mutt_remove_multipart (msg->content); decode_descriptions (msg->content); mutt_unprepare_envelope (msg->env); @@ -2051,9 +2059,9 @@ main_loop: mutt_message (i == 0 ? _("Mail sent.") : _("Sending in background.")); - if (WithCrypto && (msg->security & ENCRYPT)) + if (WithCrypto) FREE (&pgpkeylist); - + if (WithCrypto && free_clear_content) mutt_free_body (&clear_content); diff --git a/sendlib.c b/sendlib.c index f7f2fd9e..9e0cc65c 100644 --- a/sendlib.c +++ b/sendlib.c @@ -400,6 +400,9 @@ int mutt_write_mime_header (BODY *a, FILE *f) if (a->encoding != ENC7BIT) fprintf(f, "Content-Transfer-Encoding: %s\n", ENCODING (a->encoding)); + if (option (OPTCRYPTPROTHDRSWRITE) && a->mime_headers) + mutt_write_rfc822_header (f, a->mime_headers, NULL, MUTT_WRITE_HEADER_MIME, 0, 0); + /* Do NOT add the terminator here!!! */ return (ferror (f) ? -1 : 0); } @@ -1965,12 +1968,13 @@ out: * 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_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, - mutt_write_header_mode mode, int privacy) + mutt_write_header_mode mode, int privacy, + int hide_protected_subject) { char buffer[LONG_STRING]; char *p, *q; @@ -2027,7 +2031,14 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, fputs ("Bcc: \n", fp); 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", ProtHdrSubject, 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); @@ -2795,7 +2806,9 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, * */ mutt_write_rfc822_header (msg->fp, hdr->env, hdr->content, post ? MUTT_WRITE_HEADER_POSTPONE : MUTT_WRITE_HEADER_NORMAL, - 0); + 0, + option (OPTCRYPTPROTHDRSREAD) && + mutt_should_hide_protected_subject (hdr)); /* (postponment) if this was a reply of some sort, contains the * Message-ID: of message replied to. Save it using a special X-Mutt-