git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [StGit PATCH] mail: Ask for the SMTP credentials before sending the messages
@ 2010-02-12 16:11 Catalin Marinas
  2010-02-12 22:42 ` Pavel Roskin
  2010-02-12 22:56 ` Pavel Roskin
  0 siblings, 2 replies; 4+ messages in thread
From: Catalin Marinas @ 2010-02-12 16:11 UTC (permalink / raw)
  To: git, Karl Wiberg; +Cc: Pavel Roskin, Alex Chiang

The original implementation was asking for the SMTP password on every
patch sent. This patch only asks the password once before sending or
even editing the cover message and patches.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
Cc: Pavel Roskin <proski@gnu.org>
Cc: Alex Chiang <achiang@hp.com>
---
 stgit/commands/mail.py |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index 34262d3..b0a8f13 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -192,9 +192,18 @@ def __send_message_sendmail(sendmail, msg):
     cmd = sendmail.split()
     Run(*cmd).raw_input(msg).discard_output()
 
-def __send_message_smtp(smtpserver, from_addr, to_addr_list, msg, options):
-    """Send the message using the given SMTP server
+__smtp_credentials = None
+
+def __set_smtp_credentials(options):
+    """Set the (smtpuser, smtppassword, smtpusetls) credentials if the method
+    of sending is SMTP.
     """
+    global __smtp_credentials
+
+    smtpserver = options.smtp_server or config.get('stgit.smtpserver')
+    if options.git or smtpserver.startswith('/'):
+        return
+
     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'
@@ -206,6 +215,13 @@ def __send_message_smtp(smtpserver, from_addr, to_addr_list, msg, options):
     if (smtpuser and not smtppassword):
         smtppassword = getpass.getpass("Please enter SMTP password: ")
 
+    __smtp_credentials = (smtpuser, smtppassword, smtpusetls)
+
+def __send_message_smtp(smtpserver, from_addr, to_addr_list, msg, options):
+    """Send the message using the given SMTP server
+    """
+    smtpuser, smtppassword, smtpusetls = __smtp_credentials
+
     try:
         s = smtplib.SMTP(smtpserver)
     except Exception, err:
@@ -652,6 +668,8 @@ def func(parser, options, args):
     else:
         ref_id = None
 
+    # get username/password if sending by SMTP
+    __set_smtp_credentials(options)
 
     # send the cover message (if any)
     if options.cover or options.edit_cover:

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-03-01 15:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-12 16:11 [StGit PATCH] mail: Ask for the SMTP credentials before sending the messages Catalin Marinas
2010-02-12 22:42 ` Pavel Roskin
2010-02-12 22:56 ` Pavel Roskin
2010-03-01 15:46   ` Catalin Marinas

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).