From 152d5e483a3e00fdd6280e060056dd6bdbbfa756 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sat, 4 Feb 2012 19:07:59 +0000 Subject: [PATCH] Re: [PATCH 1/2] cli: add --from option to reply to restrict guessing of the From: header. --- 8a/058e415e3a48e43a06c74a6bebbf2891b76075 | 235 ++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 8a/058e415e3a48e43a06c74a6bebbf2891b76075 diff --git a/8a/058e415e3a48e43a06c74a6bebbf2891b76075 b/8a/058e415e3a48e43a06c74a6bebbf2891b76075 new file mode 100644 index 000000000..48abb9166 --- /dev/null +++ b/8a/058e415e3a48e43a06c74a6bebbf2891b76075 @@ -0,0 +1,235 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 3786C431FAF + for ; Sat, 4 Feb 2012 11:06:57 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id ldqmnheLicv9 for ; + Sat, 4 Feb 2012 11:06:56 -0800 (PST) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 1B346431FAE + for ; Sat, 4 Feb 2012 11:06:56 -0800 (PST) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1Rtkwj-0001wS-Gq; Sat, 04 Feb 2012 19:06:52 +0000 +Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] + helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1Rtkwj-0002Sp-0w; Sat, 04 Feb 2012 19:06:49 +0000 +From: Mark Walters +To: Jani Nikula , notmuch@notmuchmail.org +Subject: Re: [PATCH 1/2] cli: add --from option to reply to restrict guessing + of the From: header. +In-Reply-To: <87lioio4wx.fsf@nikula.org> +References: <1328375350-10352-1-git-send-email-markwalters1009@gmail.com> + <1328375350-10352-2-git-send-email-markwalters1009@gmail.com> + <87lioio4wx.fsf@nikula.org> +User-Agent: Notmuch/0.11+152~ge29a32b (http://notmuchmail.org) Emacs/23.2.1 + (i486-pc-linux-gnu) +Date: Sat, 04 Feb 2012 19:07:59 +0000 +Message-ID: <87k442h0xc.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 94.192.233.223 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: 8b51cd1e9fa2de4fa0dd70298a1ea87c (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay + * domain + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 04 Feb 2012 19:06:57 -0000 + + +On Sat, 04 Feb 2012 19:59:58 +0200, Jani Nikula wrote: +> On Sat, 4 Feb 2012 17:09:09 +0000, Mark Walters wrote: +> > Add an option --from= to notmuch-reply.c to restrict guessing of the +> > From: header. The existing logic looks as the main headers, then at +> > the delivery headers, and finally defaults to the config file address. +> > +> > This patch allows the user to restrict which of these guesses are +> > made. Currently the supported values are: +> > default|fallback-all current behaviour +> > fallback-received fallback to delivery headers but not config file +> > fallback-none only look at from/reply-to/to/cc/ headers +> > none From: header is always left empty +> +> As discussed on IRC, --from=primary is a natural extension to always use +> the primary address from config, but that can be a later patch. + +Ok, I will probably add that. + +> > +> > If the code does not find an allowed address it outputs an empty From: +> > line and the caller can decide how to respond. +> > --- +> > notmuch-reply.c | 39 ++++++++++++++++++++++++++++++--------- +> > 1 files changed, 30 insertions(+), 9 deletions(-) +> > +> > diff --git a/notmuch-reply.c b/notmuch-reply.c +> > index f55b1d2..f660749 100644 +> > --- a/notmuch-reply.c +> > +++ b/notmuch-reply.c +> > @@ -24,6 +24,13 @@ +> > #include "gmime-filter-reply.h" +> > #include "gmime-filter-headers.h" +> > +> +> I think it would be good to have a comment here reminding later +> developers that the order matters in this enum. + +Have fixed + +> > +enum { +> > + FROM_FALLBACK_ALL, +> > + FROM_FALLBACK_RECEIVED, +> > + FROM_FALLBACK_NONE, +> > + FROM_NONE +> > +}; +> > + +> > static void +> > reply_headers_message_part (GMimeMessage *message); +> > +> > @@ -510,7 +517,8 @@ notmuch_reply_format_default(void *ctx, +> > notmuch_config_t *config, +> > notmuch_query_t *query, +> > notmuch_show_params_t *params, +> > - notmuch_bool_t reply_all) +> > + notmuch_bool_t reply_all, +> > + int from_guess) +> +> Hrmh, I'd like this to sound more deterministic than +> "guessing". from_select? from_use? from? + +I have gone for from_select. + +> > { +> > GMimeMessage *reply; +> > notmuch_messages_t *messages; +> > @@ -542,15 +550,19 @@ notmuch_reply_format_default(void *ctx, +> > from_addr = add_recipients_from_message (reply, config, message, +> > reply_all); +> > +> > - if (from_addr == NULL) +> > + if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_RECEIVED)) +> +> Please drop the extra braces here and below. + +Have fixed. (Indeed in a sense this was a bug see below!) +> +> > from_addr = guess_from_received_header (config, message); +> > +> > - if (from_addr == NULL) +> > + if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_ALL )) +> > from_addr = notmuch_config_get_user_primary_email (config); +> > +> > - from_addr = talloc_asprintf (ctx, "%s <%s>", +> > - notmuch_config_get_user_name (config), +> > - from_addr); +> > + if ((from_addr != NULL) || (from_guess = FROM_NONE)) { +> +> Should that be (from_addr != NULL && from_guess != FROM_NONE)? +> Definitely the assignment is an error! + +You are quite right. And if I didn't have the superfluous brackets the +compiler would probably have given a warning. I have fixed it. + +> +> > + from_addr = talloc_asprintf (ctx, "%s <%s>", +> > + notmuch_config_get_user_name (config), +> > + from_addr); +> > + } else { +> > + from_addr = talloc_strdup (ctx, ""); +> > + } +> > g_mime_object_set_header (GMIME_OBJECT (reply), +> > "From", from_addr); +> > +> > @@ -590,7 +602,8 @@ notmuch_reply_format_headers_only(void *ctx, +> > notmuch_config_t *config, +> > notmuch_query_t *query, +> > unused (notmuch_show_params_t *params), +> > - notmuch_bool_t reply_all) +> > + notmuch_bool_t reply_all, +> > + unused (int from_guess)) +> > { +> > GMimeMessage *reply; +> > notmuch_messages_t *messages; +> > @@ -657,10 +670,11 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) +> > notmuch_query_t *query; +> > char *query_string; +> > int opt_index, ret = 0; +> > - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all); +> > + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all, int from_guess); +> > notmuch_show_params_t params = { .part = -1 }; +> > int format = FORMAT_DEFAULT; +> > int reply_all = TRUE; +> > + int from_guess = FROM_FALLBACK_ALL; +> > notmuch_bool_t decrypt = FALSE; +> > +> > notmuch_opt_desc_t options[] = { +> > @@ -672,6 +686,13 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) +> > (notmuch_keyword_t []){ { "all", TRUE }, +> > { "sender", FALSE }, +> > { 0, 0 } } }, +> > + { NOTMUCH_OPT_KEYWORD, &from_guess, "from", 'F', +> > + (notmuch_keyword_t []){ { "default", FROM_FALLBACK_ALL }, +> > + { "fallback-all", FROM_FALLBACK_ALL }, +> > + { "fallback-received", FROM_FALLBACK_RECEIVED }, +> > + { "fallback-none", FROM_FALLBACK_NONE }, +> > + { "none", FROM_NONE }, +> > + { 0, 0 } } }, +> > { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 }, +> > { 0, 0, 0, 0, 0 } +> > }; +> > @@ -732,7 +753,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) +> > return 1; +> > } +> > +> > - if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0) +> > + if (reply_format_func (ctx, config, query, ¶ms, reply_all, from_guess) != 0) +> > return 1; +> > +> > notmuch_query_destroy (query); +> > -- +> > 1.7.2.3 +> > +> > _______________________________________________ +> > notmuch mailing list +> > notmuch@notmuchmail.org +> > http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2