From: Catalin Marinas <catalin.marinas@gmail.com>
To: "Karl Hasselström" <kha@treskal.com>, git@vger.kernel.org
Subject: [PATCH 1/4] Allow e-mails to be sent with the Unix sendmail tool
Date: Sun, 13 Jul 2008 12:40:26 +0100 [thread overview]
Message-ID: <20080713114026.18845.77979.stgit@localhost.localdomain> (raw)
In-Reply-To: <20080713113853.18845.37686.stgit@localhost.localdomain>
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 | 46 ++++++++++++++++++++++++++++++++++------------
2 files changed, 35 insertions(+), 12 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..c87d67e 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'
@@ -31,13 +32,15 @@ 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. This option can also be an
+absolute path to 'sendmail' followed by command line arguments.
+
+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'.
+attachment using the --attach option in which case the
+'mailattch.tmpl' template will be used instead of 'patchmail.tmpl'.
The To/Cc/Bcc addresses can either be added to the template file or
passed via the corresponding command line options. They can be e-mail
@@ -133,8 +136,9 @@ 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 command to use for sending mail'),
make_option('-u', '--smtp-user', metavar = 'USER',
help = 'username for SMTP authentication'),
make_option('-p', '--smtp-password', metavar = 'PASSWORD',
@@ -184,8 +188,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 +217,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.
next prev parent reply other threads:[~2008-07-13 11:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-13 11:40 [PATCH 0/4] Proposed patches Catalin Marinas
2008-07-13 11:40 ` Catalin Marinas [this message]
2008-07-15 12:22 ` [PATCH 1/4] Allow e-mails to be sent with the Unix sendmail tool Mark Brown
2008-07-15 12:34 ` Karl Hasselström
2008-07-15 21:47 ` Catalin Marinas
2008-07-13 11:40 ` [PATCH 2/4] Implement a new patch identification scheme and id command Catalin Marinas
2008-07-14 6:58 ` Karl Hasselström
2008-07-13 11:40 ` [PATCH 3/4] Convert git_id() to the new id format Catalin Marinas
2008-07-14 7:07 ` Karl Hasselström
2008-08-21 21:39 ` Catalin Marinas
2008-07-25 0:47 ` [StGit PATCH] Fix some remaining old-style stg id calls Karl Hasselström
2008-07-27 8:24 ` Catalin Marinas
2008-07-13 11:40 ` [PATCH 4/4] Remove the applied/unapplied commands Catalin Marinas
2008-07-13 11:42 ` [PATCH 0/4] Proposed patches Catalin Marinas
2008-07-13 18:57 ` Lukas Sandström
2008-07-13 21:10 ` Catalin Marinas
2008-07-14 7:11 ` Karl Hasselström
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080713114026.18845.77979.stgit@localhost.localdomain \
--to=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
--cc=kha@treskal.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).