[PATCH 13/21] vim: refactor open_reply()
authorFelipe Contreras <felipe.contreras@gmail.com>
Sat, 2 Nov 2013 13:55:46 +0000 (07:55 +1800)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:57:54 +0000 (09:57 -0800)
b8/39fa0a0040361a10c79befd5639f1b5b662c00 [new file with mode: 0644]

diff --git a/b8/39fa0a0040361a10c79befd5639f1b5b662c00 b/b8/39fa0a0040361a10c79befd5639f1b5b662c00
new file mode 100644 (file)
index 0000000..46158f0
--- /dev/null
@@ -0,0 +1,193 @@
+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 5556B431FAF\r
+       for <notmuch@notmuchmail.org>; Sat,  2 Nov 2013 07:03:52 -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 R7WjF3S+pRCg for <notmuch@notmuchmail.org>;\r
+       Sat,  2 Nov 2013 07:03:47 -0700 (PDT)\r
+Received: from mail-oa0-f47.google.com (mail-oa0-f47.google.com\r
+       [209.85.219.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id D5947429E2F\r
+       for <notmuch@notmuchmail.org>; Sat,  2 Nov 2013 07:03:09 -0700 (PDT)\r
+Received: by mail-oa0-f47.google.com with SMTP id i1so5600758oag.20\r
+       for <notmuch@notmuchmail.org>; Sat, 02 Nov 2013 07:03:09 -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=nUfpfnyEzVAgubSTNofFIM/3EdIsp9KtsuFNEDp4SOU=;\r
+       b=sAK5o+tEj6oraTSBusDpfG79PUgRF2gy9sKwR3hCq4Wb6vuiUMMrBOtJKzzW19ELFB\r
+       6Y67tvu8nRYuT/AkWUk9uLCejZUQBOtFVKgOc/XNhQYxSjjnUzfYqwm85mCvHZHdmgf6\r
+       Wbq+gOWQgkhBxvJ0eGDcRL3MQICIrEVGNyuyjoX7Vz+Q9TPwqCPa0Hk+mZ86zmgOlzgi\r
+       wdADofOfZHPpincZRhsEw49LCCIBd5jvJf+dkE3Jgp9dLu3gpq7fm64tLYemI2vm9Pme\r
+       H2OAb6BbkZjK7yJB7mHviC6hrAl7XqB4Sehw6XITONZQJaj+9EVOgd03ZMD+EHNMc1eI\r
+       +f2w==\r
+X-Received: by 10.60.116.230 with SMTP id jz6mr6619934oeb.21.1383400989318;\r
+       Sat, 02 Nov 2013 07:03:09 -0700 (PDT)\r
+Received: from localhost (187-162-140-241.static.axtel.net. [187.162.140.241])\r
+       by mx.google.com with ESMTPSA id\r
+       ru3sm19958939obc.2.2013.11.02.07.03.07 for <multiple recipients>\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Sat, 02 Nov 2013 07:03:08 -0700 (PDT)\r
+From: Felipe Contreras <felipe.contreras@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 13/21] vim: refactor open_reply()\r
+Date: Sat,  2 Nov 2013 07:55:46 -0600\r
+Message-Id: <1383400554-1832-14-git-send-email-felipe.contreras@gmail.com>\r
+X-Mailer: git-send-email 1.8.4.2+fc1\r
+In-Reply-To: <1383400554-1832-1-git-send-email-felipe.contreras@gmail.com>\r
+References: <1383400554-1832-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: Sat, 02 Nov 2013 14:03:52 -0000\r
+\r
+In preparation for composing new messages.\r
+\r
+Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\r
+---\r
+ vim/notmuch.vim | 92 ++++++++++++++++++++++++++++++---------------------------\r
+ 1 file changed, 49 insertions(+), 43 deletions(-)\r
+\r
+diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
+index 9a45300..8383fd6 100644\r
+--- a/vim/notmuch.vim\r
++++ b/vim/notmuch.vim\r
+@@ -504,12 +504,37 @@ ruby << EOF\r
+               return "<#{random_tag}@#{Socket.gethostname}.notmuch>"\r
+       end\r
\r
+-      def open_reply(orig)\r
++      def open_compose_helper(lines, cur)\r
+               help_lines = [\r
+                       'Notmuch-Help: Type in your message here; to help you use these bindings:',\r
+                       'Notmuch-Help:   ,s    - send the message (Notmuch-Help lines will be removed)',\r
+                       'Notmuch-Help:   ,q    - abort the message',\r
+                       ]\r
++\r
++              dir = File.expand_path('~/.notmuch/compose')\r
++              FileUtils.mkdir_p(dir)\r
++              Tempfile.open(['nm-', '.mail'], dir) do |f|\r
++                      f.puts(help_lines)\r
++                      f.puts\r
++                      f.puts(lines)\r
++\r
++                      sig_file = File.expand_path('~/.signature')\r
++                      if File.exists?(sig_file)\r
++                              f.puts("-- ")\r
++                              f.write(File.read(sig_file))\r
++                      end\r
++\r
++                      f.flush\r
++\r
++                      cur += help_lines.size + 1\r
++\r
++                      VIM::command("let s:reply_from='%s'" % $email_address)\r
++                      VIM::command("call s:new_file_buffer('compose', '#{f.path}')")\r
++                      VIM::command("call cursor(#{cur}, 0)")\r
++              end\r
++      end\r
++\r
++      def open_reply(orig)\r
+               reply = orig.reply do |m|\r
+                       # fix headers\r
+                       if not m[:reply_to]\r
+@@ -522,54 +547,35 @@ ruby << EOF\r
+                       m.content_transfer_encoding = '7bit'\r
+               end\r
\r
+-              dir = File.expand_path('~/.notmuch/compose')\r
+-              FileUtils.mkdir_p(dir)\r
+-              Tempfile.open(['nm-', '.mail'], dir) do |f|\r
+-                      lines = []\r
+-\r
+-                      lines += help_lines\r
+-                      lines << ''\r
+-\r
+-                      body_lines = []\r
+-                      if $mail_installed\r
+-                              addr = Mail::Address.new(orig[:from].value)\r
+-                              name = addr.name\r
+-                              name = addr.local + "@" if name.nil? && !addr.local.nil?\r
+-                      else\r
+-                              name = orig[:from]\r
+-                      end\r
+-                      name = "somebody" if name.nil?\r
+-\r
+-                      body_lines << "%s wrote:" % name\r
+-                      part = orig.find_first_text\r
+-                      part.convert.each_line do |l|\r
+-                              body_lines << "> %s" % l.chomp\r
+-                      end\r
+-                      body_lines << ""\r
+-                      body_lines << ""\r
+-                      body_lines << ""\r
+-\r
+-                      reply.body = body_lines.join("\n")\r
++              lines = []\r
\r
+-                      lines += reply.to_s.lines.map { |e| e.chomp }\r
+-                      lines << ""\r
++              body_lines = []\r
++              if $mail_installed\r
++                      addr = Mail::Address.new(orig[:from].value)\r
++                      name = addr.name\r
++                      name = addr.local + "@" if name.nil? && !addr.local.nil?\r
++              else\r
++                      name = orig[:from]\r
++              end\r
++              name = "somebody" if name.nil?\r
\r
+-                      old_count = lines.count - 1\r
++              body_lines << "%s wrote:" % name\r
++              part = orig.find_first_text\r
++              part.convert.each_line do |l|\r
++                      body_lines << "> %s" % l.chomp\r
++              end\r
++              body_lines << ""\r
++              body_lines << ""\r
++              body_lines << ""\r
\r
+-                      f.puts(lines)\r
++              reply.body = body_lines.join("\n")\r
\r
+-                      sig_file = File.expand_path('~/.signature')\r
+-                      if File.exists?(sig_file)\r
+-                              f.puts("-- ")\r
+-                              f.write(File.read(sig_file))\r
+-                      end\r
++              lines += reply.to_s.lines.map { |e| e.chomp }\r
++              lines << ""\r
\r
+-                      f.flush\r
++              cur = lines.count - 1\r
\r
+-                      VIM::command("let s:reply_from='%s'" % $email_address)\r
+-                      VIM::command("call s:new_file_buffer('compose', '#{f.path}')")\r
+-                      VIM::command("call cursor(#{old_count}, 0)")\r
+-              end\r
++              open_compose_helper(lines, cur)\r
+       end\r
\r
+       def folders_render()\r
+-- \r
+1.8.4.2+fc1\r
+\r