[PATCH v2 3/3] vim: improve the way messages are sent
authorFelipe Contreras <felipe.contreras@gmail.com>
Thu, 1 May 2014 22:57:54 +0000 (17:57 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:02:03 +0000 (10:02 -0800)
55/a06619968953de7025c792bb2f25c88b244a0d [new file with mode: 0644]

diff --git a/55/a06619968953de7025c792bb2f25c88b244a0d b/55/a06619968953de7025c792bb2f25c88b244a0d
new file mode 100644 (file)
index 0000000..f55c574
--- /dev/null
@@ -0,0 +1,164 @@
+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 95AC4431FC7\r
+       for <notmuch@notmuchmail.org>; Thu,  1 May 2014 16:09:06 -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 Zq3qBGSF5S94 for <notmuch@notmuchmail.org>;\r
+       Thu,  1 May 2014 16:08:59 -0700 (PDT)\r
+Received: from mail-oa0-f46.google.com (mail-oa0-f46.google.com\r
+       [209.85.219.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 58382431FCF\r
+       for <notmuch@notmuchmail.org>; Thu,  1 May 2014 16:08:46 -0700 (PDT)\r
+Received: by mail-oa0-f46.google.com with SMTP id i4so3635589oah.33\r
+       for <notmuch@notmuchmail.org>; Thu, 01 May 2014 16:08:45 -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=nPvjm+fSKBytOKLMOx75NLA3uuT451ifQo99d8PTe/c=;\r
+       b=PUD0I7+ruz/vuNKhKwAivuyjptWvG9tUmQoU6Umz3fCcD73aoC/3X+vUilSzDtEKqz\r
+       l2xHmCp8DIeUwGJNzCdbVUj6o0NfGyKsuiavN7ofz56EaWy5Ib8LXXrgDGpkx6XT5/IG\r
+       esItSM7ibfcSOXKswV9IUailo1mplXZIHfjLxSDRpKfLAtUvMtL2qx14HFFvpGcaz7/v\r
+       OrcDtG3OydRtRuaPw+Vky5XjCCSGE4vdIv0rw5wfRRGbOtBZi46ieewHrUUrKd86L/zJ\r
+       NgZ62rcH69h8/Y6skFxJibInud06//0rxn2qFCj2Ao1FU5EswxcKWRG+Or3kTPiy5NRh\r
+       GPQQ==\r
+X-Received: by 10.60.51.136 with SMTP id k8mr13555298oeo.33.1398985725880;\r
+       Thu, 01 May 2014 16:08:45 -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\r
+       cq1sm122272455oeb.4.2014.05.01.16.08.43 for <multiple recipients>\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Thu, 01 May 2014 16:08:44 -0700 (PDT)\r
+From: Felipe Contreras <felipe.contreras@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 3/3] vim: improve the way messages are sent\r
+Date: Thu,  1 May 2014 17:57:54 -0500\r
+Message-Id: <1398985074-17646-4-git-send-email-felipe.contreras@gmail.com>\r
+X-Mailer: git-send-email 1.9.2+fc1.19.g85b6256\r
+In-Reply-To: <1398985074-17646-1-git-send-email-felipe.contreras@gmail.com>\r
+References: <1398985074-17646-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: Thu, 01 May 2014 23:09:06 -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
+This fixes an issue while sending non-ascii mails to strict servers; the\r
+mail needs to be encoded.\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.19.g85b6256\r
+\r