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

* Re: [StGit PATCH] mail: Ask for the SMTP credentials before sending the messages
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Pavel Roskin @ 2010-02-12 22:42 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git, Karl Wiberg, Alex Chiang

On Fri, 2010-02-12 at 16:11 +0000, Catalin Marinas wrote:
> 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>

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

-- 
Regards,
Pavel Roskin

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

* Re: [StGit PATCH] mail: Ask for the SMTP credentials before sending the messages
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Pavel Roskin @ 2010-02-12 22:56 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git, Karl Wiberg, Alex Chiang

On Fri, 2010-02-12 at 16:11 +0000, Catalin Marinas wrote:
> 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.

I don't have time to investigate at the moment, but "make test" fails in
t1900-mail.sh on the "proposed" branch, which includes this patch:

*** t1900-mail.sh ***
*   ok 1: Initialize the StGIT repository
*   ok 2: Put all the patches in an mbox
*   ok 3: Import the mbox and compare
* FAIL 4: Put all the patches in an mbox with patch attachments
        stg mail --to="Inge Ström <inge@example.com>" -a -m \
               -t ../../templates/mailattch.tmpl > mbox1
* FAIL 5: Import the mbox containing patch attachments and compare

            t1=$(git cat-file -p $(stg id) | grep ^tree)
            stg pop -a &&
            stg import -M mbox1 &&
            t2=$(git cat-file -p $(stg id) | grep ^tree) &&
            [ "$t1" = "$t2" ]
            
* FAIL 6: Check the To:, Cc: and Bcc: headers

            stg mail --to=a@a --cc="b@b, c@c" --bcc=d@d $(stg top) -m \
                -t ../../templates/patchmail.tmpl > mbox &&
            test "$(cat mbox | grep -e "^To:")" = "To: a@a" &&
            test "$(cat mbox | grep -e "^Cc:")" = "Cc: b@b, c@c" &&
            test "$(cat mbox | grep -e "^Bcc:")" = "Bcc: d@d"
            
* FAIL 7: Check the --auto option

            stg edit --sign &&
            stg mail --to=a@a --cc="b@b, c@c" --bcc=d@d --auto $(stg top) -m \
                -t ../../templates/patchmail.tmpl > mbox &&
            test "$(cat mbox | grep -e "^To:")" = "To: a@a" &&
            test "$(cat mbox | grep -e "^Cc:")" = \
                "Cc: C O Mitter <committer@example.com>, b@b, c@c" &&
            test "$(cat mbox | grep -e "^Bcc:")" = "Bcc: d@d"
            
* FAIL 8: Check the e-mail address duplicates

            stg mail --to="a@a, b b <b@b>" --cc="b@b, c@c" \
                --bcc="c@c, d@d, committer@example.com" --auto $(stg top) -m \
                -t ../../templates/patchmail.tmpl > mbox &&
            test "$(cat mbox | grep -e "^To:")" = "To: b b <b@b>, a@a" &&
            test "$(cat mbox | grep -e "^Cc:")" = "Cc: c@c" &&
            test "$(cat mbox | grep -e "^Bcc:")" = "Bcc: committer@example.com, d@d"
            
* failed 5 among 8 test(s)
make[1]: *** [t1900-mail.sh] Error 1
make[1]: Leaving directory `/home/proski/src/stgit/t'
make: *** [test] Error 2

-- 
Regards,
Pavel Roskin

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

* Re: [StGit PATCH] mail: Ask for the SMTP credentials before sending  the messages
  2010-02-12 22:56 ` Pavel Roskin
@ 2010-03-01 15:46   ` Catalin Marinas
  0 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2010-03-01 15:46 UTC (permalink / raw)
  To: Pavel Roskin; +Cc: git, Karl Wiberg, Alex Chiang

On 12 February 2010 22:56, Pavel Roskin <proski@gnu.org> wrote:
> On Fri, 2010-02-12 at 16:11 +0000, Catalin Marinas wrote:
>> 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.
>
> I don't have time to investigate at the moment, but "make test" fails in
> t1900-mail.sh on the "proposed" branch, which includes this patch:

The patch was converting the message headers to Header objects rather
than strings so that the long-line folding is done using "\n " rather
than "\n\t" (Outlook cannot handle the latter correctly). But it looks
like the Python library assumes that they are strings and getting
"content-type" fails (I would say Python bug).

Anyway, I change the patch so that it only converts the the Subject
header which is the one that bothers me most:


commit 1b0c0113861681974b8905dbe10a57f6831ecb87
Author: Catalin Marinas <catalin.marinas@gmail.com>
Date:   Fri Feb 12 15:36:37 2010 +0000

    mail: Use space rather than tab for long subject header folding

    The default Python implementation (at least 2.5 and earlier) fold long
    e-mail header lines by inserting "\n\t". This causes issues with some
    e-mail clients that remove both "\n\t". The RFC2822 shows that folding
    should be done with "\n ". The Python workaround is to use a Header
    object instead of a string when setting the message headers.

    Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>

diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index d0334b4..ed55fd9 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -426,6 +426,13 @@ def __encode_message(msg):
         new_val = ' '.join(words)
         msg.replace_header(header, new_val)

+    # replace the Subject string with a Header() object otherwise the long
+    # line folding is done using "\n\t" rather than "\n ", causing issues with
+    # some e-mail clients
+    subject = msg.get('subject', '')
+    msg.replace_header('subject',
+                       email.Header.Header(subject, header_name = 'subject'))
+
     # encode the body and set the MIME and encoding headers
     if msg.is_multipart():
         for p in msg.get_payload():



-- 
Catalin

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