{"thread":{"id":"22631","subject":"[StGit PATCH] mail: Ask for the SMTP credentials before sending the messages","startedAt":"2010-02-12T16:11:51Z","lastAt":"2010-03-01T15:46:13Z","messageCount":4,"participants":["Catalin Marinas","Pavel Roskin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"134352","messageId":"20100212161150.12036.62592.stgit@pc1117.cambridge.arm.com","threadId":"22631","inReplyTo":null,"subject":"[StGit PATCH] mail: Ask for the SMTP credentials before sending the messages","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@arm.com","sentAt":"2010-02-12T16:11:51Z","receivedAt":"2010-02-12T16:11:51Z","isPatch":true,"sender":{"key":"catalin.marinas@arm.com","avatar":null},"body":"The original implementation was asking for the SMTP password on every\npatch sent. This patch only asks the password once before sending or\neven editing the cover message and patches.\n\nSigned-off-by: Catalin Marinas <catalin.marinas@gmail.com>\nCc: Pavel Roskin <proski@gnu.org>\nCc: Alex Chiang <achiang@hp.com>\n---\n stgit/commands/mail.py |   22 ++++++++++++++++++++--\n 1 files changed, 20 insertions(+), 2 deletions(-)\n\ndiff --git a/stgit/commands/mail.py b/stgit/commands/mail.py\nindex 34262d3..b0a8f13 100644\n--- a/stgit/commands/mail.py\n+++ b/stgit/commands/mail.py\n@@ -192,9 +192,18 @@ def __send_message_sendmail(sendmail, msg):\n     cmd = sendmail.split()\n     Run(*cmd).raw_input(msg).discard_output()\n \n-def __send_message_smtp(smtpserver, from_addr, to_addr_list, msg, options):\n-    \"\"\"Send the message using the given SMTP server\n+__smtp_credentials = None\n+\n+def __set_smtp_credentials(options):\n+    \"\"\"Set the (smtpuser, smtppassword, smtpusetls) credentials if the method\n+    of sending is SMTP.\n     \"\"\"\n+    global __smtp_credentials\n+\n+    smtpserver = options.smtp_server or config.get('stgit.smtpserver')\n+    if options.git or smtpserver.startswith('/'):\n+        return\n+\n     smtppassword = options.smtp_password or config.get('stgit.smtppassword')\n     smtpuser = options.smtp_user or config.get('stgit.smtpuser')\n     smtpusetls = options.smtp_tls or config.get('stgit.smtptls') == 'yes'\n@@ -206,6 +215,13 @@ def __send_message_smtp(smtpserver, from_addr, to_addr_list, msg, options):\n     if (smtpuser and not smtppassword):\n         smtppassword = getpass.getpass(\"Please enter SMTP password: \")\n \n+    __smtp_credentials = (smtpuser, smtppassword, smtpusetls)\n+\n+def __send_message_smtp(smtpserver, from_addr, to_addr_list, msg, options):\n+    \"\"\"Send the message using the given SMTP server\n+    \"\"\"\n+    smtpuser, smtppassword, smtpusetls = __smtp_credentials\n+\n     try:\n         s = smtplib.SMTP(smtpserver)\n     except Exception, err:\n@@ -652,6 +668,8 @@ def func(parser, options, args):\n     else:\n         ref_id = None\n \n+    # get username/password if sending by SMTP\n+    __set_smtp_credentials(options)\n \n     # send the cover message (if any)\n     if options.cover or options.edit_cover:\n"},{"id":"134393","messageId":"1266014578.25535.9.camel@mj","threadId":"22631","inReplyTo":"20100212161150.12036.62592.stgit@pc1117.cambridge.arm.com","subject":"Re: [StGit PATCH] mail: Ask for the SMTP credentials before sending the messages","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2010-02-12T22:42:58Z","receivedAt":"2010-02-12T22:42:58Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"On Fri, 2010-02-12 at 16:11 +0000, Catalin Marinas wrote:\n> The original implementation was asking for the SMTP password on every\n> patch sent. This patch only asks the password once before sending or\n> even editing the cover message and patches.\n> \n> Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n> Cc: Pavel Roskin <proski@gnu.org>\n> Cc: Alex Chiang <achiang@hp.com>\n\nTested-by: Pavel Roskin <proski@gnu.org>\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"134396","messageId":"1266015411.25535.21.camel@mj","threadId":"22631","inReplyTo":"20100212161150.12036.62592.stgit@pc1117.cambridge.arm.com","subject":"Re: [StGit PATCH] mail: Ask for the SMTP credentials before sending the messages","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2010-02-12T22:56:51Z","receivedAt":"2010-02-12T22:56:51Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"On Fri, 2010-02-12 at 16:11 +0000, Catalin Marinas wrote:\n> The original implementation was asking for the SMTP password on every\n> patch sent. This patch only asks the password once before sending or\n> even editing the cover message and patches.\n\nI don't have time to investigate at the moment, but \"make test\" fails in\nt1900-mail.sh on the \"proposed\" branch, which includes this patch:\n\n*** t1900-mail.sh ***\n*   ok 1: Initialize the StGIT repository\n*   ok 2: Put all the patches in an mbox\n*   ok 3: Import the mbox and compare\n* FAIL 4: Put all the patches in an mbox with patch attachments\n        stg mail --to=\"Inge StrÃ¶m <inge@example.com>\" -a -m \\\n               -t ../../templates/mailattch.tmpl > mbox1\n* FAIL 5: Import the mbox containing patch attachments and compare\n\n            t1=$(git cat-file -p $(stg id) | grep ^tree)\n            stg pop -a &&\n            stg import -M mbox1 &&\n            t2=$(git cat-file -p $(stg id) | grep ^tree) &&\n            [ \"$t1\" = \"$t2\" ]\n            \n* FAIL 6: Check the To:, Cc: and Bcc: headers\n\n            stg mail --to=a@a --cc=\"b@b, c@c\" --bcc=d@d $(stg top) -m \\\n                -t ../../templates/patchmail.tmpl > mbox &&\n            test \"$(cat mbox | grep -e \"^To:\")\" = \"To: a@a\" &&\n            test \"$(cat mbox | grep -e \"^Cc:\")\" = \"Cc: b@b, c@c\" &&\n            test \"$(cat mbox | grep -e \"^Bcc:\")\" = \"Bcc: d@d\"\n            \n* FAIL 7: Check the --auto option\n\n            stg edit --sign &&\n            stg mail --to=a@a --cc=\"b@b, c@c\" --bcc=d@d --auto $(stg top) -m \\\n                -t ../../templates/patchmail.tmpl > mbox &&\n            test \"$(cat mbox | grep -e \"^To:\")\" = \"To: a@a\" &&\n            test \"$(cat mbox | grep -e \"^Cc:\")\" = \\\n                \"Cc: C O Mitter <committer@example.com>, b@b, c@c\" &&\n            test \"$(cat mbox | grep -e \"^Bcc:\")\" = \"Bcc: d@d\"\n            \n* FAIL 8: Check the e-mail address duplicates\n\n            stg mail --to=\"a@a, b b <b@b>\" --cc=\"b@b, c@c\" \\\n                --bcc=\"c@c, d@d, committer@example.com\" --auto $(stg top) -m \\\n                -t ../../templates/patchmail.tmpl > mbox &&\n            test \"$(cat mbox | grep -e \"^To:\")\" = \"To: b b <b@b>, a@a\" &&\n            test \"$(cat mbox | grep -e \"^Cc:\")\" = \"Cc: c@c\" &&\n            test \"$(cat mbox | grep -e \"^Bcc:\")\" = \"Bcc: committer@example.com, d@d\"\n            \n* failed 5 among 8 test(s)\nmake[1]: *** [t1900-mail.sh] Error 1\nmake[1]: Leaving directory `/home/proski/src/stgit/t'\nmake: *** [test] Error 2\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"135949","messageId":"b0943d9e1003010746l1d4208bas48fcfba36efa5605@mail.gmail.com","threadId":"22631","inReplyTo":"1266015411.25535.21.camel@mj","subject":"Re: [StGit PATCH] mail: Ask for the SMTP credentials before sending the messages","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2010-03-01T15:46:13Z","receivedAt":"2010-03-01T15:46:13Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 12 February 2010 22:56, Pavel Roskin <proski@gnu.org> wrote:\n> On Fri, 2010-02-12 at 16:11 +0000, Catalin Marinas wrote:\n>> The original implementation was asking for the SMTP password on every\n>> patch sent. This patch only asks the password once before sending or\n>> even editing the cover message and patches.\n>\n> I don't have time to investigate at the moment, but \"make test\" fails in\n> t1900-mail.sh on the \"proposed\" branch, which includes this patch:\n\nThe patch was converting the message headers to Header objects rather\nthan strings so that the long-line folding is done using \"\\n \" rather\nthan \"\\n\\t\" (Outlook cannot handle the latter correctly). But it looks\nlike the Python library assumes that they are strings and getting\n\"content-type\" fails (I would say Python bug).\n\nAnyway, I change the patch so that it only converts the the Subject\nheader which is the one that bothers me most:\n\n\ncommit 1b0c0113861681974b8905dbe10a57f6831ecb87\nAuthor: Catalin Marinas <catalin.marinas@gmail.com>\nDate:   Fri Feb 12 15:36:37 2010 +0000\n\n    mail: Use space rather than tab for long subject header folding\n\n    The default Python implementation (at least 2.5 and earlier) fold long\n    e-mail header lines by inserting \"\\n\\t\". This causes issues with some\n    e-mail clients that remove both \"\\n\\t\". The RFC2822 shows that folding\n    should be done with \"\\n \". The Python workaround is to use a Header\n    object instead of a string when setting the message headers.\n\n    Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n\ndiff --git a/stgit/commands/mail.py b/stgit/commands/mail.py\nindex d0334b4..ed55fd9 100644\n--- a/stgit/commands/mail.py\n+++ b/stgit/commands/mail.py\n@@ -426,6 +426,13 @@ def __encode_message(msg):\n         new_val = ' '.join(words)\n         msg.replace_header(header, new_val)\n\n+    # replace the Subject string with a Header() object otherwise the long\n+    # line folding is done using \"\\n\\t\" rather than \"\\n \", causing issues with\n+    # some e-mail clients\n+    subject = msg.get('subject', '')\n+    msg.replace_header('subject',\n+                       email.Header.Header(subject, header_name = 'subject'))\n+\n     # encode the body and set the MIME and encoding headers\n     if msg.is_multipart():\n         for p in msg.get_payload():\n\n\n\n-- \nCatalin\n"}]}