* [StGIT PATCH] Allow e-mails to be sent with the Unix sendmail tool
@ 2008-06-14 7:28 Catalin Marinas
2008-06-14 9:05 ` Karl Hasselström
0 siblings, 1 reply; 2+ messages in thread
From: Catalin Marinas @ 2008-06-14 7:28 UTC (permalink / raw)
To: git
If the stgit.smtpserver configuration option does not have a host:port
format, it is assumed to be an external tool. For example, to use
sendmail just set this variable to "/usr/sbin/sendmail -t -i" (see the
examples/gitconfig file).
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
examples/gitconfig | 1 +
stgit/commands/mail.py | 29 ++++++++++++++++++++++++-----
stgit/config.py | 4 ++--
3 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/examples/gitconfig b/examples/gitconfig
index c16f786..28d94af 100644
--- a/examples/gitconfig
+++ b/examples/gitconfig
@@ -19,6 +19,7 @@
#autoresolved = no
# SMTP server for sending patches
+ #smtpserver = /usr/sbin/sendmail -t -i
#smtpserver = localhost:25
# Set to 'yes' to use SMTP over TLS
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index b4d4e18..67b94c1 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -24,6 +24,7 @@ from stgit.utils import *
from stgit.out import *
from stgit import stack, git, version, templates
from stgit.config import config
+from stgit.run import Run
help = 'send a patch or series of patches by e-mail'
@@ -184,8 +185,14 @@ def __parse_addresses(msg):
return (from_addr_list[0], to_addr_list)
-def __send_message(smtpserver, from_addr, to_addr_list, msg, sleep,
- smtpuser, smtppassword, use_tls):
+def __send_message_sendmail(sendmail, msg):
+ """Send the message using the sendmail command.
+ """
+ cmd = sendmail.split()
+ Run(*cmd).raw_input(msg).discard_output()
+
+def __send_message_smtp(smtpserver, from_addr, to_addr_list, msg,
+ smtpuser, smtppassword, use_tls):
"""Send the message using the given SMTP server
"""
try:
@@ -207,13 +214,25 @@ def __send_message(smtpserver, from_addr, to_addr_list, msg, sleep,
result = s.sendmail(from_addr, to_addr_list, msg)
if len(result):
print "mail server refused delivery for the following recipients: %s" % result
- # give recipients a chance of receiving patches in the correct order
- time.sleep(sleep)
except Exception, err:
raise CmdException, str(err)
s.quit()
+def __send_message(smtpserver, from_addr, to_addr_list, msg,
+ sleep, smtpuser, smtppassword, use_tls):
+ """Message sending dispatcher.
+ """
+ if smtpserver.startswith('/'):
+ # Use the sendmail tool
+ __send_message_sendmail(smtpserver, msg)
+ else:
+ # Use the SMTP server (we have host and port information)
+ __send_message_smtp(smtpserver, from_addr, to_addr_list, msg,
+ smtpuser, smtppassword, use_tls)
+ # give recipients a chance of receiving patches in the correct order
+ time.sleep(sleep)
+
def __build_address_headers(msg, options, extra_cc = []):
"""Build the address headers and check existing headers in the
template.
@@ -338,7 +357,7 @@ def __build_cover(tmpl, patches, msg_id, options):
prefix_str = confprefix + ' '
else:
prefix_str = ''
-
+
total_nr_str = str(len(patches))
patch_nr_str = '0'.zfill(len(total_nr_str))
if len(patches) > 1:
diff --git a/stgit/config.py b/stgit/config.py
index 9bfdd52..fcf3a5d 100644
--- a/stgit/config.py
+++ b/stgit/config.py
@@ -29,7 +29,7 @@ class GitConfigException(StgException):
class GitConfig:
__defaults={
'stgit.autoresolved': 'no',
- 'stgit.smtpserver': 'localhost:25',
+ 'stgit.smtpserver': '/usr/sbin/sendmail -t -i',
'stgit.smtpdelay': '5',
'stgit.pullcmd': 'git pull',
'stgit.fetchcmd': 'git fetch',
@@ -102,7 +102,7 @@ class GitConfig:
if m:
result.append(m.group(1))
return result
-
+
config=GitConfig()
def config_setup():
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [StGIT PATCH] Allow e-mails to be sent with the Unix sendmail tool
2008-06-14 7:28 [StGIT PATCH] Allow e-mails to be sent with the Unix sendmail tool Catalin Marinas
@ 2008-06-14 9:05 ` Karl Hasselström
0 siblings, 0 replies; 2+ messages in thread
From: Karl Hasselström @ 2008-06-14 9:05 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
On 2008-06-14 08:28:24 +0100, Catalin Marinas wrote:
> If the stgit.smtpserver configuration option does not have a
> host:port format, it is assumed to be an external tool. For example,
> to use sendmail just set this variable to "/usr/sbin/sendmail -t -i"
> (see the examples/gitconfig file).
Looks good, except that the new feature (and the fact that it's
magically triggered if the smtpserver starts with a /) is not
documented. Maybe add something like this to the patch:
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index 4027170..2b1b92c 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -31,10 +31,13 @@ usage = r"""%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
Send a patch or a range of patches by e-mail using the SMTP server
specified by the 'stgit.smtpserver' configuration option, or the
-'--smtp-server' command line option. The From address and the e-mail
-format are generated from the template file passed as argument to
-'--template' (defaulting to '.git/patchmail.tmpl' or
-'~/.stgit/templates/patchmail.tmpl' or
+'--smtp-server' command line option. (You may give the absolute path
+to sendmail instead, followed by any sendmail options you wish to
+use.)
+
+The From address and the e-mail format are generated from the template
+file passed as argument to '--template' (defaulting to
+'.git/patchmail.tmpl' or '~/.stgit/templates/patchmail.tmpl' or
'/usr/share/stgit/templates/patchmail.tmpl'). A patch can be sent as
attachment using the --attach option in which case the 'mailattch.tmpl'
template will be used instead of 'patchmail.tmpl'.
@@ -133,8 +136,10 @@ options = [make_option('-a', '--all',
help = 'sleep for SECONDS between e-mails sending'),
make_option('--refid',
help = 'use REFID as the reference id'),
- make_option('--smtp-server', metavar = 'HOST[:PORT]',
- help = 'SMTP server to use for sending mail'),
+ make_option('--smtp-server',
+ metavar = 'HOST[:PORT] or "/path/to/sendmail -t -i"',
+ help = ('SMTP server (or sendmail program) to use for'
+ ' sending mail')),
make_option('-u', '--smtp-user', metavar = 'USER',
help = 'username for SMTP authentication'),
make_option('-p', '--smtp-password', metavar = 'PASSWORD',
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-06-14 9:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-14 7:28 [StGIT PATCH] Allow e-mails to be sent with the Unix sendmail tool Catalin Marinas
2008-06-14 9:05 ` Karl Hasselström
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox