Re: [PATCH 1/2] cli: add --from option to reply to restrict guessing of the From...
authorMark Walters <markwalters1009@gmail.com>
Sat, 4 Feb 2012 19:07:59 +0000 (19:07 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:06 +0000 (09:44 -0800)
8a/058e415e3a48e43a06c74a6bebbf2891b76075 [new file with mode: 0644]

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