[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Issue 3227 - adding some extra "custom" headers to the email

From: Arfrever Frehtes Taifersar Arahesis <Arfrever.FTA_at_GMail.Com>
Date: Fri, 16 Jan 2009 21:09:25 +0100

2009-01-16 15:21:06 Jon Bendtsen napisaƂ(a):
> Hi
>
> This PATCH is one way of doing what issue 3227 requests.
> http://subversion.tigris.org/issues/show_bug.cgi?id=3227
> The method used in is patch is to add up to 5 different types
> of extra headers.
> group
> module
> branch
> submodule
> file
>
> The group is the name from the mailer.conf file. The other 4 are
> from the path in SVN. Thinking like:
>
> <module> / <branch> / <submodule> / ... / <file>
>
> The PATCH is robust against shorter paths and will not crash.
> But with a special path, the branch and submodule may be switched.
> File will always be the file.
>
> The PATCH will naturally both accept a default list in the mailer.conf
> and a list for each group in the mailer.conf.

> Index: mailer.py
> ===================================================================
> --- mailer.py (revision 35283)
> +++ mailer.py (working copy)
> @@ -54,6 +54,7 @@
> import re
> import tempfile
> import types
> +import string

It is needless.

>
> # Minimal version of Subversion's bindings required
> _MIN_SVN_VERSION = [1, 5, 0]
> @@ -223,7 +224,7 @@
> def __init__(self, cfg, repos, prefix_param):
> OutputBase.__init__(self, cfg, repos, prefix_param)
>
> - def start(self, group, params):
> + def start(self, group, params, header_list):
> # whitespace (or another character) separated list of addresses
> # which must be split into a clean list
> to_addr_in = self.cfg.get('to_addr', group, params)
> @@ -250,7 +251,13 @@
> and self.reply_to[2] == ']':
> self.reply_to = self.reply_to[3:]
>
> - def mail_headers(self, group, params):
> + def mail_headers(self, group, params, header_list):
> + header_detail = header_list[0]
> + modules = header_list[1]
> + branches = header_list[2]
> + submodules = header_list[3]
> + files = header_list[4]
> +
> subject = self.make_subject(group, params)
> try:
> subject.encode('ascii')
> @@ -262,23 +269,38 @@
> 'Subject: %s\n' \
> 'MIME-Version: 1.0\n' \
> 'Content-Type: text/plain; charset=UTF-8\n' \
> - 'Content-Transfer-Encoding: 8bit\n' \
> + 'Content-Transfer-Encoding: 8bit' \
> % (self.from_addr, ', '.join(self.to_addrs), subject)
> if self.reply_to:
> - hdrs = '%sReply-To: %s\n' % (hdrs, self.reply_to)
> + hdrs = '%s\nReply-To: %s' % (hdrs, self.reply_to)
> + for header in header_detail:
> + if 'group' == header:
> + hdrs = '%s\nX-group: %s' % (hdrs, group)
> + if 'module' == header:
> + for m in modules:
> + hdrs = '%s\nX-module: %s' % (hdrs, m)
> + if 'branch' == header:
> + for b in branches:
> + hdrs = '%s\nX-branch: %s' % (hdrs, b)
> + if 'submodule' == header:
> + for s in submodules:
> + hdrs = '%s\nX-submod: %s' % (hdrs, s)
> + if 'file' == header:
> + for f in files:
> + hdrs = '%s\nX-file: %s' % (hdrs, f)
> return hdrs + '\n'
>
>
> class SMTPOutput(MailedOutput):
> "Deliver a mail message to an MTA using SMTP."
>
> - def start(self, group, params):
> + def start(self, group, params, header_list):
> MailedOutput.start(self, group, params)
>
> self.buffer = StringIO()
> self.write = self.buffer.write
>
> - self.write(self.mail_headers(group, params))
> + self.write(self.mail_headers(group, params, header_list))
>
> def finish(self):
> server = smtplib.SMTP(self.cfg.general.smtp_hostname)
> @@ -313,8 +335,8 @@
> # figure out the command for delivery
> self.cmd = cfg.general.mail_command.split()
>
> - def start(self, group, params):
> - MailedOutput.start(self, group, params)
> + def start(self, group, params, header_list):
> + MailedOutput.start(self, group, params, header_list)
>
> ### gotta fix this. this is pretty specific to sendmail and qmail's
> ### mailwrapper program. should be able to use option param substitution
> @@ -333,7 +355,7 @@
> self.pipe.fromchild.close()
>
> # start writing out the mail message
> - self.write(self.mail_headers(group, params))
> + self.write(self.mail_headers(group, params, header_list))
>
> def finish(self):
> # signal that we're done sending content
> @@ -429,7 +451,44 @@
> renderer = TextCommitRenderer(self.output)
>
> for (group, param_tuple), (params, paths) in self.groups.items():
> - self.output.start(group, params)
> + header_list = []
> + module = []
> + branch = []
> + submodule = []
> + file = []
> + h_detail = self.cfg.get('header_detail', group, params)
> + if len(h_detail) >= 3 and h_detail[0] == '[' \
> + and h_detail[2] == ']':
> + header_detail = \
> + [_f for _f in h_detail[3:].split(h_detail[1]) if _f]
> + else:
> + header_detail = [_f for _f in h_detail.split() if _f]
> + # we should only generate the header details we truely want, but
> + # since we split the entire path, we might as well make all sets
> + for p in paths:
> + plist = string.split(p, '/')

plist = p.split('/')

> + try:
> + module = module[:] + [plist[0]]
> + except IndexError:
> + dummy = 0
> + try:
> + branch = branch[:] + [plist[1]]
> + except IndexError:
> + dummy = 0
> + try:
> + submodule = submodule[:] + [plist[2]]
> + except IndexError:
> + dummy = 0
> + try:
> + file = file[:] + [plist[-1]]
> + except IndexError:
> + dummy = 0
> + module = set(module)
> + branch = set(branch)
> + submodule = set(submodule)
> + file = set(file)
> + header_list = [header_detail, module, branch, submodule, file]
> + self.output.start(group, params, header_list)
>
> # generate the content for this group and set of params
> generate_content(renderer, self.cfg, self.repos, self.changelist,
>

-- 
Arfrever Frehtes Taifersar Arahesis

Received on 2009-01-16 21:10:55 CET

This is an archived mail posted to the Subversion Dev mailing list.