[PATCH 3/3] Improve the way messages are sent
authorFelipe Contreras <felipe.contreras@gmail.com>
Wed, 23 Apr 2014 21:49:44 +0000 (16:49 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:01:54 +0000 (10:01 -0800)
57/47b9452017a15847d22fd91f1674a036467f9c [new file with mode: 0644]

diff --git a/57/47b9452017a15847d22fd91f1674a036467f9c b/57/47b9452017a15847d22fd91f1674a036467f9c
new file mode 100644 (file)
index 0000000..67f4675
--- /dev/null
@@ -0,0 +1,161 @@
+Return-Path: <felipe.contreras@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 10762431FC9\r
+       for <notmuch@notmuchmail.org>; Wed, 23 Apr 2014 15:00:27 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 6c2cbsoe-EyT for <notmuch@notmuchmail.org>;\r
+       Wed, 23 Apr 2014 15:00:19 -0700 (PDT)\r
+Received: from mail-oa0-f51.google.com (mail-oa0-f51.google.com\r
+       [209.85.219.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 118BA431FC0\r
+       for <notmuch@notmuchmail.org>; Wed, 23 Apr 2014 15:00:19 -0700 (PDT)\r
+Received: by mail-oa0-f51.google.com with SMTP id i4so1744627oah.10\r
+       for <notmuch@notmuchmail.org>; Wed, 23 Apr 2014 15:00:18 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+       bh=5WZrBGwG+Wq/OIRrgoXg0bUVHp8n8sI5fjDkKl0vLcE=;\r
+       b=uVkI9/AGQKAq6+991s0LF9bSa4bhze0Utf6+6ZjekeunRmPOomBNRrGsIfe9gRIOkP\r
+       ioKqwnUZyfetohPh4qk/CVDAIQczcY4HEYTadq+Qsfy+Fhl+rawEPTTfJDJVu3UMZxbR\r
+       bdHcrpUzJnV0A4LAezYUokdiAnknbXBmYS1/ugD1BjyJBantD3dF6NkpmBVFxTCYFfn8\r
+       uqRxNWzse6Kalhu+jtwYbCOi4kSyxvDUrNflbHoGpZe+mgpNu0kboCLYqO/Op2i1K55M\r
+       v/nQC99K4L+aQFDKcQXjpEqRrSK2YI/TkoD9N2d/b156AwfQhMyikmvKYxxckr9GY82Q\r
+       hTNA==\r
+X-Received: by 10.60.159.36 with SMTP id wz4mr45262159oeb.30.1398290418554;\r
+       Wed, 23 Apr 2014 15:00:18 -0700 (PDT)\r
+Received: from localhost (189-211-224-40.static.axtel.net. [189.211.224.40])\r
+       by mx.google.com with ESMTPSA id pa3sm4331609obb.6.2014.04.23.15.00.16\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Wed, 23 Apr 2014 15:00:17 -0700 (PDT)\r
+From: Felipe Contreras <felipe.contreras@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] Improve the way messages are sent\r
+Date: Wed, 23 Apr 2014 16:49:44 -0500\r
+Message-Id: <1398289784-18203-4-git-send-email-felipe.contreras@gmail.com>\r
+X-Mailer: git-send-email 1.9.2+fc1.2.gfbaae8c\r
+In-Reply-To: <1398289784-18203-1-git-send-email-felipe.contreras@gmail.com>\r
+References: <1398289784-18203-1-git-send-email-felipe.contreras@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 23 Apr 2014 22:00:27 -0000\r
+\r
+We want the proper encoding and content-type to be set when sending the\r
+mail, but human-readable plain-text for composing. So split the code in\r
+two parts: the presentation and the transport conversion.\r
+\r
+Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\r
+---\r
+ vim/notmuch.vim | 34 +++++++++++++++++++++-------------\r
+ 1 file changed, 21 insertions(+), 13 deletions(-)\r
+\r
+diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
+index 0cb94f6..331e930 100644\r
+--- a/vim/notmuch.vim\r
++++ b/vim/notmuch.vim\r
+@@ -86,17 +86,22 @@ endfunction\r
+ function! s:compose_send()\r
+       let b:compose_done = 1\r
+       let fname = expand('%')\r
++      let lines = getline(5, '$')\r
\r
+-      " remove headers\r
+-      0,4d\r
+-      write\r
++ruby << EOF\r
++      # Generate proper mail to send\r
++      text = VIM::evaluate('lines').join("\n")\r
++      fname = VIM::evaluate('fname')\r
++      transport = Mail.new(text)\r
++      transport.message_id = generate_message_id\r
++      transport.charset = 'utf-8'\r
++      File.write(fname, transport.to_s)\r
++EOF\r
\r
+       let cmdtxt = g:notmuch_sendmail . ' -t -f ' . s:reply_from . ' < ' . fname\r
+       let out = system(cmdtxt)\r
+       let err = v:shell_error\r
+       if err\r
+-              undo\r
+-              write\r
+               echohl Error\r
+               echo 'Eeek! unable to send mail'\r
+               echo out\r
+@@ -572,9 +577,7 @@ ruby << EOF\r
+                       end\r
+                       m.cc = orig[:cc]\r
+                       m.from = $email\r
+-                      m.message_id = generate_message_id\r
+                       m.charset = 'utf-8'\r
+-                      m.content_transfer_encoding = '7bit'\r
+               end\r
\r
+               lines = []\r
+@@ -600,7 +603,7 @@ ruby << EOF\r
\r
+               reply.body = body_lines.join("\n")\r
\r
+-              lines += reply.to_s.lines.map { |e| e.chomp }\r
++              lines += reply.present.lines.map { |e| e.chomp }\r
+               lines << ""\r
\r
+               cur = lines.count - 1\r
+@@ -611,18 +614,13 @@ ruby << EOF\r
+       def open_compose()\r
+               lines = []\r
\r
+-              lines << "Date: #{Time.now().strftime('%a, %-d %b %Y %T %z')}"\r
+               lines << "From: #{$email}"\r
+               lines << "To: "\r
+               cur = lines.count\r
\r
+               lines << "Cc: "\r
+               lines << "Bcc: "\r
+-              lines << "Message-Id: #{generate_message_id}"\r
+               lines << "Subject: "\r
+-              lines << "Mime-Version: 1.0"\r
+-              lines << "Content-Type: text/plain; charset=utf-8"\r
+-              lines << "Content-Transfer-Encoding: 7bit"\r
+               lines << ""\r
+               lines << ""\r
+               lines << ""\r
+@@ -928,6 +926,16 @@ ruby << EOF\r
+                               end\r
+                               text\r
+                       end\r
++\r
++                      def present\r
++                              buffer = ''\r
++                              header.fields.each do |f|\r
++                                      buffer << "%s: %s\r\n" % [f.name, f.to_s]\r
++                              end\r
++                              buffer << "\r\n"\r
++                              buffer << body.to_s\r
++                              buffer\r
++                      end\r
+               end\r
+       end\r
\r
+-- \r
+1.9.2+fc1.2.gfbaae8c\r
+\r