<<< Date Index >>>     <<< Thread Index >>>

[patch] add "notalternates" functionality



Greetings,

I'm a long-time mutt user, but this is my first attempt to contribute anything
back, so please go easy on me :).

A week ago, I asked on mutt-users about an apparent problem I was having with
the alternates/unalternates functionality.  It turned out mutt didn't actually
support what I thought unalternates was supposed to do.  In a nutshell, I
needed a command to tell mutt "addresses matching the following regex are
/not/ me, despite them matching a regex in the alternates list".

Original thread is here:
http://marc.theaimsgroup.com/?t=108482073000007&r=1&w=2

I've added this functionality, as "notalternates" (and unnotalternates, though
I haven't needed that).  I've tried to keep true to the style of the existing
code and documentation.  This Works For Me (tm); is there any interest in
folding this into mutt cvs?

Patch attached.

Charles

-- 
-----------------------------------------------------------------------
Charles Cazabon                          <muttdev@xxxxxxxxxxxxxxxxxxxx>
-----------------------------------------------------------------------
diff -ur mutt-build/alias.c mutt.notalternates/alias.c
--- mutt-build/alias.c  Sun Feb  1 11:10:43 2004
+++ mutt.notalternates/alias.c  Wed May 26 09:20:30 2004
@@ -568,8 +568,12 @@
 
   if (mutt_match_rx_list (addr->mailbox, Alternates))
   {
-    dprint (5, (debugfile, "mail_addr_is_user: yes, %s matched by 
alternates.\n", addr->mailbox));
-    return 1;
+    if (!mutt_match_rx_list (addr->mailbox, Notalternates))
+    {
+      dprint (5, (debugfile, "mail_addr_is_user: yes, %s matched by alternates 
and not by notalternates.\n", addr->mailbox));
+      return 1;
+    }
+    dprint (5, (debugfile, "mail_addr_is_user: not yet, %s matched by both 
alternates and notalternates.\n", addr->mailbox));
   }
   
   dprint (5, (debugfile, "mail_addr_is_user: no, all failed.\n"));
Binary files mutt-build/alias.o and mutt.notalternates/alias.o differ
diff -ur mutt-build/doc/manual.sgml.head mutt.notalternates/doc/manual.sgml.head
--- mutt-build/doc/manual.sgml.head     Sun Feb  1 11:45:33 2004
+++ mutt.notalternates/doc/manual.sgml.head     Wed May 26 09:20:30 2004
@@ -1185,7 +1185,23 @@
 receive e-mail.
 
 To remove a regular expression from this list, use the
-<tt/unalternates/ command.
+<tt/unalternates/ command.  To exclude otherwise matching addresses,
+see the <tt/notalternates/ command.
+
+<sect1>Excluding alternative addresses<label id="notalternates">
+<p>
+Usage: <tt/&lsqb;un&rsqb;notalternates/ <em/regexp/ &lsqb; <em/regexp/ ... 
&rsqb;<newline>
+
+Many users receive e-mail under a number of different addresses. To
+fully use mutt's features here, the program must be able to
+recognize what e-mail addresses you receive mail under. That's the
+purpose of the <tt/notalternates/ command: It takes a list of regular
+expressions, each of which can identify an address under which you do not
+receive e-mail.  Use this to exclude an address which mutt would otherwise
+consider an alternate address because of the <tt/alternates/ command.
+
+To remove a regular expression from this list, use the
+<tt/unnotalternates/ command.
 
 <sect1>Mailing lists<label id="lists">
 <p>
@@ -1768,8 +1784,8 @@
 ~n [MIN]-[MAX]  messages with a score in the range MIN to MAX *)
 ~N              new messages
 ~O              old messages
-~p              message is addressed to you (consults alternates)
-~P              message is from you (consults alternates)
+~p              message is addressed to you (consults alternates and 
notalternates)
+~P              message is from you (consults alternates and notalternates)
 ~Q              messages which have been replied to
 ~R              read messages
 ~r [MIN]-[MAX]  messages with ``date-received'' in a Date range
@@ -2975,6 +2991,10 @@
 <tt><ref id="alternates" name="alternates"></tt> <em/regexp/ &lsqb; 
<em/regexp/ ... &rsqb;
 <item>
 <tt><ref id="alternates" name="unalternates"></tt> &lsqb; * | <em/regexp/ ... 
&rsqb;
+<item>
+<tt><ref id="notalternates" name="notalternates"></tt> <em/regexp/ &lsqb; 
<em/regexp/ ... &rsqb;
+<item>
+<tt><ref id="notalternates" name="unnotalternates"></tt> &lsqb; * | 
<em/regexp/ ... &rsqb;
 <item>
 <tt><ref id="alternative_order" name="alternative&lowbar;order"></tt> 
<em/mimetype/ &lsqb; <em/mimetype/ ... &rsqb;
 <item>
Only in mutt.notalternates/doc: manual.sgml.head.orig
diff -ur mutt-build/doc/muttrc.man mutt.notalternates/doc/muttrc.man
--- mutt-build/doc/muttrc.man   Mon May 17 11:07:28 2004
+++ mutt.notalternates/doc/muttrc.man   Wed May 26 09:20:42 2004
@@ -87,6 +87,18 @@
 a regular expression from the list of known alternates.
 .PP
 .nf
+\fBnotalternates\fP \fIregexp\fP [ \fB,\fP \fIregexp\fP [ ... ]]
+\fBunnotalternates\fP [\fB * \fP | \fIregexp\fP [ \fB,\fP \fIregexp\fP [ ... 
]] ]
+.fi
+.IP
+\fBnotalternates\fP is used to inform mutt about addresses
+where you do not receive mail; you can use regular expressions to specify
+non-alternate addresses.  This affects mutt's idea about messages
+from you, and messages addressed to you.  \fBunnotalternates\fP removes
+a regular expression from the list of known non-alternates.  The purpose
+of this is to exclude addresses otherwise matched by \fBalternates\fP.
+.PP
+.nf
 \fBalternative_order\fP \fItype\fP[\fB/\fP\fIsubtype\fP] [ ... ]
 \fBunalternative_order\fP [\fB * \fP | \fItype\fP/\fIsubtype\fP] [...]
 .fi
@@ -393,8 +405,8 @@
 ~n \fIMIN\fP-\fIMAX\fP messages with a score in the range \fIMIN\fP to 
\fIMAX\fP
 ~N     new messages
 ~O     old messages
-~p     message is addressed to you (consults $alternates)
-~P     message is from you (consults $alternates)
+~p     message is addressed to you (consults $alternates and $notalternates)
+~P     message is from you (consults $alternates and $notalternates)
 ~Q     messages which have been replied to
 ~R     read messages
 ~r \fIMIN\fP-\fIMAX\fP messages with \(lqdate-received\(rq in a Date range
diff -ur mutt-build/doc/muttrc.man.head mutt.notalternates/doc/muttrc.man.head
--- mutt-build/doc/muttrc.man.head      Sun Feb  1 11:10:43 2004
+++ mutt.notalternates/doc/muttrc.man.head      Wed May 26 09:20:31 2004
@@ -87,6 +87,18 @@
 a regular expression from the list of known alternates.
 .PP
 .nf
+\fBnotalternates\fP \fIregexp\fP [ \fB,\fP \fIregexp\fP [ ... ]]
+\fBunnotalternates\fP [\fB * \fP | \fIregexp\fP [ \fB,\fP \fIregexp\fP [ ... 
]] ]
+.fi
+.IP
+\fBnotalternates\fP is used to inform mutt about addresses
+where you do not receive mail; you can use regular expressions to specify
+non-alternate addresses.  This affects mutt's idea about messages
+from you, and messages addressed to you.  \fBunnotalternates\fP removes
+a regular expression from the list of known non-alternates.  The purpose
+of this is to exclude addresses otherwise matched by \fBalternates\fP.
+.PP
+.nf
 \fBalternative_order\fP \fItype\fP[\fB/\fP\fIsubtype\fP] [ ... ]
 \fBunalternative_order\fP [\fB * \fP | \fItype\fP/\fIsubtype\fP] [...]
 .fi
@@ -393,8 +405,8 @@
 ~n \fIMIN\fP-\fIMAX\fP messages with a score in the range \fIMIN\fP to 
\fIMAX\fP
 ~N     new messages
 ~O     old messages
-~p     message is addressed to you (consults $alternates)
-~P     message is from you (consults $alternates)
+~p     message is addressed to you (consults $alternates and $notalternates)
+~P     message is from you (consults $alternates and $notalternates)
 ~Q     messages which have been replied to
 ~R     read messages
 ~r \fIMIN\fP-\fIMAX\fP messages with \(lqdate-received\(rq in a Date range
Only in mutt.notalternates/doc: muttrc.man.head.orig
diff -ur mutt-build/globals.h mutt.notalternates/globals.h
--- mutt-build/globals.h        Sun Feb  1 11:10:43 2004
+++ mutt.notalternates/globals.h        Wed May 26 09:20:31 2004
@@ -123,6 +123,7 @@
 WHERE LIST *UnIgnore INITVAL(0);
 
 WHERE RX_LIST *Alternates INITVAL(0);
+WHERE RX_LIST *Notalternates INITVAL(0);
 WHERE RX_LIST *MailLists INITVAL(0);
 WHERE RX_LIST *SubscribedLists INITVAL(0);
 
Only in mutt.notalternates: globals.h.orig
diff -ur mutt-build/init.c mutt.notalternates/init.c
--- mutt-build/init.c   Wed Feb 11 02:20:25 2004
+++ mutt.notalternates/init.c   Wed May 26 09:20:31 2004
@@ -865,7 +865,7 @@
 
          pp->rx = safe_calloc (1, sizeof (regex_t));
          pp->pattern = safe_strdup ((char *) p->init);
-         if (mutt_strcmp (p->option, "alternates") == 0)
+         if (mutt_strcmp (p->option, "alternates") == 0 || mutt_strcmp 
(p->option, "notalternates") == 0)
            flags |= REG_ICASE;
          else if (mutt_strcmp (p->option, "mask") != 0)
            flags |= mutt_which_case ((const char *) p->init);
@@ -1096,9 +1096,9 @@
       {
        int not = 0;
 
-       /* $alternates is case-insensitive,
+       /* $alternates and notalternates are case-insensitive,
           $mask is case-sensitive */
-       if (mutt_strcmp (MuttVars[idx].option, "alternates") == 0)
+       if (mutt_strcmp (MuttVars[idx].option, "alternates") == 0 || 
mutt_strcmp (MuttVars[idx].option, "notalternates") == 0)
          flags |= REG_ICASE;
        else if (mutt_strcmp (MuttVars[idx].option, "mask") != 0)
          flags |= mutt_which_case (tmp->data);
diff -ur mutt-build/init.h mutt.notalternates/init.h
--- mutt-build/init.h   Sun Feb  1 11:10:43 2004
+++ mutt.notalternates/init.h   Wed May 26 09:26:35 2004
@@ -2752,6 +2752,8 @@
 struct command_t Commands[] = {
   { "alternates",      parse_rx_list,          UL &Alternates },
   { "unalternates",    parse_rx_unlist,        UL &Alternates },
+  { "notalternates",   parse_rx_list,          UL &Notalternates },
+  { "unnotalternates", parse_rx_unlist,        UL &Notalternates },
 #ifdef USE_SOCKET
   { "account-hook",     mutt_parse_hook,        M_ACCOUNTHOOK },
 #endif
Binary files mutt-build/init.o and mutt.notalternates/init.o differ
Only in mutt-build: mutt