git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: Catalin Marinas <catalin.marinas@gmail.com>, git@vger.kernel.org
Subject: [PATCH] Add support for SMTP over Transport Layer Security (TLS)
Date: Mon, 06 Aug 2007 21:16:43 -0400	[thread overview]
Message-ID: <20070807011643.20454.8122.stgit@gx.roinet.com> (raw)

Signed-off-by: Pavel Roskin <proski@gnu.org>
---

 examples/gitconfig     |    1 +
 stgit/commands/mail.py |   22 +++++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/examples/gitconfig b/examples/gitconfig
index bbb943f..3abbe6a 100644
--- a/examples/gitconfig
+++ b/examples/gitconfig
@@ -21,6 +21,7 @@
 	#smtpserver = localhost:25
 	#smtpuser = username
 	#smtppassword = password
+	#smtptls = no
 
 	# delay between messages in seconds (defaults to 5)
 	#smtpdelay = 5
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index cb8dc74..7ed5c27 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -15,7 +15,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-import sys, os, re, time, datetime, smtplib
+import sys, os, re, time, datetime, socket, smtplib
 import email, email.Utils, email.Header
 from optparse import OptionParser, make_option
 
@@ -53,7 +53,8 @@ replies to a different e-mail by using the '--refid' option.
 
 SMTP authentication is also possible with '--smtp-user' and
 '--smtp-password' options, also available as configuration settings:
-'smtpuser' and 'smtppassword'.
+'smtpuser' and 'smtppassword'. TLS encryption can be enabled by
+'--smtp-tls' option and 'smtptls' setting.
 
 The patch e-mail template accepts the following variables:
 
@@ -121,6 +122,9 @@ options = [make_option('-a', '--all',
                        help = 'username for SMTP authentication'),
            make_option('-p', '--smtp-password', metavar = 'PASSWORD',
                        help = 'username for SMTP authentication'),
+           make_option('-T', '--smtp-tls',
+                       help = 'use SMTP with TLS encryption',
+                       action = 'store_true'),
            make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one'),
            make_option('-O', '--diff-opts',
@@ -165,7 +169,7 @@ 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):
+                   smtpuser, smtppassword, use_tls):
     """Send the message using the given SMTP server
     """
     try:
@@ -177,6 +181,11 @@ def __send_message(smtpserver, from_addr, to_addr_list, msg, sleep,
     try:
         if smtpuser and smtppassword:
             s.ehlo()
+            if use_tls:
+                if not hasattr(socket, 'ssl'):
+                    raise CmdException,  "cannot use TLS - no SSL support in Python"
+                s.starttls()
+                s.ehlo()
             s.login(smtpuser, smtppassword)
 
         result = s.sendmail(from_addr, to_addr_list, msg)
@@ -479,11 +488,14 @@ def func(parser, options, args):
 
     smtppassword = options.smtp_password or config.get('stgit.smtppassword')
     smtpuser = options.smtp_user or config.get('stgit.smtpuser')
+    smtpusetls = options.smtp_tls or config.get('stgit.smtptls') == 'yes'
 
     if (smtppassword and not smtpuser):
         raise CmdException, 'SMTP password supplied, username needed'
     if (smtpuser and not smtppassword):
         raise CmdException, 'SMTP username supplied, password needed'
+    if (smtpusetls and not smtpuser):
+        raise CmdException, 'SMTP over TLS requested, username needed'
 
     total_nr = len(patches)
     if total_nr == 0:
@@ -527,7 +539,7 @@ def func(parser, options, args):
         else:
             out.start('Sending the cover message')
             __send_message(smtpserver, from_addr, to_addr_list, msg_string,
-                           sleep, smtpuser, smtppassword)
+                           sleep, smtpuser, smtppassword, smtpusetls)
             out.done()
 
     # send the patches
@@ -555,5 +567,5 @@ def func(parser, options, args):
         else:
             out.start('Sending patch "%s"' % p)
             __send_message(smtpserver, from_addr, to_addr_list, msg_string,
-                           sleep, smtpuser, smtppassword)
+                           sleep, smtpuser, smtppassword, smtpusetls)
             out.done()

                 reply	other threads:[~2007-08-07  1:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070807011643.20454.8122.stgit@gx.roinet.com \
    --to=proski@gnu.org \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).