You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Mathias Weinert <ma...@gfa-net.de> on 2006/05/30 06:49:22 UTC

[PATCH] mail address handling in mailer.py

Hi there,

I am still hoping that some will commit the following patch to mailer.py
so please let my wishes get true...

This patch adds a new parameter to the configuration file which allows
to use different characters for splitting the to_addr.

This is usefull for using additional name information in the mail
addresses. Example:

 to_addr_split_char = ,
 to_addr = "The great Wallace" <wa...@atanyaddress>, "little Grommit" <gr...@propablyatthesameaddress>

This was the simple example (which doesn't make so much sense).
A more reasonable example is the following one:

 [defaults]
 from_addr = %(author)s
 
 [maps]
 from_addr = [mail_addresses]
 to_addr = [mail_addresses]
 
 [mail_addresses]
 wallace = "SVN: Wallace" <wa...@atanyaddress>
 grommit = "SVN: Grommit" <gr...@propablyatthesameaddress>
 
 [config_for_wallace]
 to_addr = wallace
 ...
 
With this I at least don't use the comma as separator but don't
use the whitespaces any more and am therefor able to use one set
of mail addresses containing blanks which I use for the to_addr
as well as for the from_addr. So I have the mail address only
once in the config file and the mails that are sent can easily
be identified in the mail client by the address which starts with
'SVN: '.
For me this is a really usefull thing.

If there are objections about the new parameter 'to_addr_split_char'
here are some alternatives:

1. Change the default behavior from whitespace to comma
   -> May result in problems for people updating to this version
2. Introduce a new parameter to specify the separator
   -> As I did in my patch
3. Introduce a new parameter for to_addr which will be splitted
   by comma and deprecate the current one
   -> That's what Greg Stein proposed
4. Introduce a new parameter for to_addr which will be splitted
   by comma and then add these mail addresses to the ones given
   by the current to_addr parameter
   -> No deprecation, no update problems, but two parameters for
      the same thing

Mathias

[[[
* tools/hook-scripts/mailer/mailer.py
  - new option 'to_addr_split_char' added which allows to use another character but the default whitespaces to separate different mail addresses

* tools/hook-scripts/mailer/mailer.conf.example
  - new option 'to_addr_split_char' added which allows to use another character but the default whitespaces to separate different mail addresses
]]]

--- mailer.py.orig	2006-05-23 02:17:16.000000000 +0200
+++ mailer.py	2006-05-30 08:39:42.154499700 +0200
@@ -183,7 +183,13 @@
     OutputBase.__init__(self, cfg, repos, prefix_param)
 
   def start(self, group, params):
-    # whitespace-separated list of addresses; split into a clean list:
+    # whitespace (or as set by to_addr_split_char)-separated list
+    # of addresses; split into a clean list:
+    if self.cfg.is_set('general.to_addr_split_char'):
+      self.to_addrs = \
+        filter(None, string.split(self.cfg.get('to_addr', group, params), \
+               self.cfg.general.to_addr_split_char))
+    else:
     self.to_addrs = \
         filter(None, string.split(self.cfg.get('to_addr', group, params)))
     self.from_addr = self.cfg.get('from_addr', group, params) \
--- mailer.conf.example.orig	2005-04-15 16:37:19.000000000 +0200
+++ mailer.conf.example	2006-05-30 08:40:26.626095700 +0200
@@ -27,6 +27,12 @@
 #smtp_username = example
 #smtp_password = example
 
+# If this option is set to a character this character will be used
+# to split the mail addresses given to_addr.
+# If this option is not set all whitespace characters (but no comma)
+# are used for splitting.
+to_addr_split_char = ,
+
 # --------------------------------------------------------------------------
 
 #
@@ -166,7 +172,8 @@
 from_addr = invalid@example.com
 
 # The default To: addresses for message.  One or more addresses,
-# separated by whitespace (no commas):
+# separated by whitespace (no commas) or the character set at
+# to_addr_split_char.
 to_addr = invalid@example.com
 
 # If this is set, then a Reply-To: will be inserted into the message

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] mail address handling in mailer.py

Posted by "C. Michael Pilato" <cm...@collab.net>.
Mathias Weinert wrote:
> Hi there,
> 
> I am still hoping that some will commit the following patch to mailer.py
> so please let my wishes get true...
> 
> This patch adds a new parameter to the configuration file which allows
> to use different characters for splitting the to_addr.
> 
> This is usefull for using additional name information in the mail
> addresses. Example:
> 
>  to_addr_split_char = ,
>  to_addr = "The great Wallace" <wa...@atanyaddress>, "little Grommit" <gr...@propablyatthesameaddress>

I find this two-option setup silly.  Just make the code smart enough to know
that email records are comma-delimited, and any commas in the quoted regions
don't count towards that splitting.  I whipped up the following helper
function for performing such a split, but I'm sure there's probably a
slicker/quicker way to do it:


#!/usr/bin/python
import sys

def parse_addrs(addr_line):
    """Split ADDR_LINE on commas, but don't count commas that enclosed
    in doublequote-delimited regions.  Doublequote characters
    preceeded by a backslash (\) don't count as delimiters for those
    regions, either."""

    quoted = 0
    commas = []
    for i in range(len(addr_line)):
        if addr_line[i] == '"':
            if ((i and addr_line[i-1] != '\\') or (not i)):
                if quoted:
                    quoted = 0
                else:
                    quoted = 1
        elif addr_line[i] == ',':
            if not quoted:
                commas.append(i)
    commas.append(len(addr_line))
    pieces = []
    for i in range(len(commas)):
        comma = commas[i]
        if not i:
            pieces.append(addr_line[:comma].strip())
        else:
            pieces.append(addr_line[commas[i-1]+1:comma].strip())
    if i:
        pieces.append(addr_line[commas[-1]+1:].strip())
    return filter(None, pieces)


if __name__ == "__main__":
    addrs = parse_addrs(sys.argv[1])
    print '\n'.join(addrs)

-- 
C. Michael Pilato <cm...@collab.net>
CollabNet   <>   www.collab.net   <>   Distributed Development On Demand