You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Matt Kraai <kr...@alumni.cmu.edu> on 2003/01/10 01:27:51 UTC
[PATCH] mailer.py smtplib support
Howdy,
The following, untested patch adds rudimentary smtplib support to
mailer.py. I would appreciate it if someone would test it.
Matt
* tools/hook-scripts/mailer.py
(main): Send mail with smtplib.
* tools/hook-scripts/mailer.conf.example
(from_addr, to_addr): New.
Index: tools/hook-scripts/mailer.py
===================================================================
--- tools/hook-scripts/mailer.py (revision 4318)
+++ tools/hook-scripts/mailer.py (working copy)
@@ -13,6 +13,8 @@
import string
import ConfigParser
import time
+import cStringIO
+import smtplib
import svn.fs
import svn.util
@@ -37,9 +39,11 @@
1, # use_copy_history
pool)
- ### pipe it to sendmail rather than stdout
- generate_content(sys.stdout, cfg, repos, editor, pool)
-
+ msg = cStringIO.cStringIO()
+ generate_content(msg, cfg, repos, editor, pool)
+ server = smtplib.SMTP()
+ server.sendmail(cfg.general.from_addr, [cfg.general.to_addr], msg.getvalue())
+ server.quit()
def generate_content(output, cfg, repos, editor, pool):
Index: tools/hook-scripts/mailer.conf.example
===================================================================
--- tools/hook-scripts/mailer.conf.example (revision 4318)
+++ tools/hook-scripts/mailer.conf.example (working copy)
@@ -10,3 +10,8 @@
### know how I plan to allow the insertion of spaces)
diff = /usr/bin/diff -u -L "%(label_from)s" -L "%(label_to)s" "%(from)s" "%(to)s"
+### the from address
+from_addr = foo@invalid
+
+### the to address
+to_addr = bar@invalid
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] mailer.py smtplib support
Posted by Greg Stein <gs...@lyra.org>.
On Fri, Jan 10, 2003 at 07:47:58PM -0800, Matt Kraai wrote:
> On Fri, Jan 10, 2003 at 07:21:50PM -0800, Greg Stein wrote:
> > It still isn't quite right, tho, as some headers need to be inserted for it
> > to look right (i.e. the "Author: gstein" is interpreted as a msg header
> > rather than part of the body).
>
> This should be fixed in revision 4338.
Thanks :-)
I fixed it again in 4342 (and got a conflict error when I try to commit :-).
The new code can generate the commit message through one of three means (in
order of preference):
1. via a pipe to an MDA
2. via SMTP to an MDA
3. to stdout
In each case, we also optimize how the "diff" process is run. It is nice an
efficient (Python isn't in the way) for the latter two choices. For SMTP,
though, we read everything into memory, then chunk it all out.
Now for some additional tweaks and for configurability...
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] mailer.py smtplib support
Posted by Matt Kraai <kr...@alumni.cmu.edu>.
On Fri, Jan 10, 2003 at 07:21:50PM -0800, Greg Stein wrote:
> It still isn't quite right, tho, as some headers need to be inserted for it
> to look right (i.e. the "Author: gstein" is interpreted as a msg header
> rather than part of the body).
This should be fixed in revision 4338.
Matt
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] mailer.py smtplib support
Posted by Greg Stein <gs...@lyra.org>.
On Fri, Jan 10, 2003 at 02:18:23PM -0800, Matt Kraai wrote:
>...
> How about the following, which only sends mail if the to and from
> addresses are set?
I checked in a change (rev 4337); go take a look.
A hostname needs to be given to smtplib.SMTP() to actually have it connect
somewhere (or to call the .connect() method). I grabbed that hostname from
cfg.general.smtp_hostname. If that is defined, then the SMTP stuff is used.
It still isn't quite right, tho, as some headers need to be inserted for it
to look right (i.e. the "Author: gstein" is interpreted as a msg header
rather than part of the body).
Note that the test is: hasattr(cfg.general, 'foo') since it uses objects
rather than dictionaries.
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] mailer.py smtplib support
Posted by Matt Kraai <kr...@alumni.cmu.edu>.
On Fri, Jan 10, 2003 at 01:43:33PM -0800, Greg Stein wrote:
> Configuration file. No command line options, please. Note that you'd
> probably want to define an SMTP hostname, too.
>
> In general, the patch looks good. Simpler than I expected, actually!
>
> Oh, on the configuration, it is quite fine to just leave it as something
> like "if an SMTP host is defined, then send the output there; otherwise,
> just dump it to stdout". IOW, don't worry about "needing" to define all the
> varieties. I think the most interesting part of your patch (actually get the
> content sent as email) is the Goodness part to check in.
How about the following, which only sends mail if the to and from
addresses are set?
Matt
Index: tools/hook-scripts/mailer.py
===================================================================
--- tools/hook-scripts/mailer.py (revision 4318)
+++ tools/hook-scripts/mailer.py (working copy)
@@ -13,6 +13,8 @@
import string
import ConfigParser
import time
+import cStringIO
+import smtplib
import svn.fs
import svn.util
@@ -37,9 +39,18 @@
1, # use_copy_history
pool)
- ### pipe it to sendmail rather than stdout
- generate_content(sys.stdout, cfg, repos, editor, pool)
-
+ if cfg.general.has_key('from_addr') and cfg.general.has_key('to_addr'):
+ output = cStringIO.cStringIO()
+ else:
+ output = sys.stdout
+
+ generate_content(output, cfg, repos, editor, pool)
+
+ if cfg.general.has_key('from_addr') and cfg.general.has_key('to_addr'):
+ server = smtplib.SMTP()
+ server.sendmail(cfg.general.from_addr, [cfg.general.to_addr],
+ output.getvalue())
+ server.quit()
def generate_content(output, cfg, repos, editor, pool):
Index: tools/hook-scripts/mailer.conf.example
===================================================================
--- tools/hook-scripts/mailer.conf.example (revision 4318)
+++ tools/hook-scripts/mailer.conf.example (working copy)
@@ -10,3 +10,7 @@
### know how I plan to allow the insertion of spaces)
diff = /usr/bin/diff -u -L "%(label_from)s" -L "%(label_to)s" "%(from)s" "%(to)s"
+### if both from and to addresses are specified, the mail will be sent using
+### smtplib
+from_addr = from@invalid
+to_addr = to@invalid
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] mailer.py smtplib support
Posted by Greg Stein <gs...@lyra.org>.
On Thu, Jan 09, 2003 at 06:18:14PM -0800, Matt Kraai wrote:
> On Thu, Jan 09, 2003 at 05:57:56PM -0800, Greg Stein wrote:
> > It needs to be configurable, first and foremost. The script should be able
> > to continue generating to stdout, with optional smtp or pipe-to-MDA options.
>
> Configuration file options or command line options?
Configuration file. No command line options, please. Note that you'd
probably want to define an SMTP hostname, too.
In general, the patch looks good. Simpler than I expected, actually!
Oh, on the configuration, it is quite fine to just leave it as something
like "if an SMTP host is defined, then send the output there; otherwise,
just dump it to stdout". IOW, don't worry about "needing" to define all the
varieties. I think the most interesting part of your patch (actually get the
content sent as email) is the Goodness part to check in.
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] mailer.py smtplib support
Posted by Matt Kraai <kr...@alumni.cmu.edu>.
On Thu, Jan 09, 2003 at 05:57:56PM -0800, Greg Stein wrote:
> It needs to be configurable, first and foremost. The script should be able
> to continue generating to stdout, with optional smtp or pipe-to-MDA options.
Configuration file options or command line options?
Matt
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] mailer.py smtplib support
Posted by Greg Stein <gs...@lyra.org>.
On Thu, Jan 09, 2003 at 05:27:51PM -0800, Matt Kraai wrote:
> Howdy,
>
> The following, untested patch adds rudimentary smtplib support to
> mailer.py. I would appreciate it if someone would test it.
It needs to be configurable, first and foremost. The script should be able
to continue generating to stdout, with optional smtp or pipe-to-MDA options.
But yes: generate_content() was set up so you could pass something like a
StringIO (or anything else with .write). But that'll change to support the
piping that I mentioned earlier.
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org