--- /dev/null
+Return-Path: <imain@stemwinder.org>\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 3860D431FBC\r
+ for <notmuch@notmuchmail.org>; Tue, 30 Sep 2014 14:09:07 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 NgVhOElQvE4R for <notmuch@notmuchmail.org>;\r
+ Tue, 30 Sep 2014 14:09:01 -0700 (PDT)\r
+Received: from cmta17.telus.net (cmta17.telus.net [209.171.16.90])\r
+ by olra.theworths.org (Postfix) with ESMTP id 8340A431FB6\r
+ for <notmuch@notmuchmail.org>; Tue, 30 Sep 2014 14:09:01 -0700 (PDT)\r
+Received: from ovo.mains.priv ([207.102.88.62]) by cmta17.telus.net with TELUS\r
+ id xZ8z1o00D1LiWEf01Z8zdN; Tue, 30 Sep 2014 15:09:01 -0600\r
+X-Authority-Analysis: v=2.0 cv=ea3jic4H c=1 sm=2\r
+ a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8\r
+ a=UU_U-eNNhth3WP-8HIIA:9 a=EcQDfIwDZEqJA1f7rVUV8Q==:117\r
+X-Telus-Outbound-IP: 207.102.88.62\r
+From: Ian Main <imain@stemwinder.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] Make patch saving in vim a little better.\r
+Date: Tue, 30 Sep 2014 14:08:51 -0700\r
+Message-Id: <1412111331-18823-1-git-send-email-imain@stemwinder.org>\r
+X-Mailer: git-send-email 1.9.3\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: Tue, 30 Sep 2014 21:09:07 -0000\r
+\r
+It seems like there was some bitrot on the previous version of this\r
+which made it not work correctly. This fixes the bitrot and also\r
+updates how it works.\r
+\r
+- Sometimes [PATCH.*] isn't at the beginning of the message (often on\r
+ lists I'm on).\r
+- It now goes through all the messages in the thread. for some reason\r
+ the toplevel messages didn't usually contain all the patches in my\r
+ testing.\r
+- Check for 'Re:' at the beginning and skip if it's there.\r
+- Save patches to filesystem-safe filename containing the subject\r
+ (unfortunately we use system()...)\r
+\r
+ Ian\r
+---\r
+ vim/notmuch.vim | 14 ++++++++++----\r
+ 1 file changed, 10 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
+index b33c6c6..d80f22f 100644\r
+--- a/vim/notmuch.vim\r
++++ b/vim/notmuch.vim\r
+@@ -182,12 +182,18 @@ ruby << EOF\r
+ q = $curbuf.query($cur_thread)\r
+ t = q.search_threads.first\r
+ n = 0\r
+- t.toplevel_messages.first.replies.each do |m|\r
+- next if not m['subject'] =~ /^\[PATCH.*\]/\r
+- file = "%04d.patch" % [n += 1]\r
++ t.messages.each do |m|\r
++ next if not m['subject'] =~ /\[PATCH.*\]/\r
++ next if m['subject'] =~ /^Re:/\r
++ file = "#{m['subject']}-%04d.patch" % [n += 1]\r
++ # Sanitize for the filesystem\r
++ file.gsub!(/[^0-9A-Za-z.\-]/, '_')\r
++ # Remove leading underscores.\r
++ file.gsub!(/^_+/, '')\r
++ vim_puts "Saving patch to #{file}"\r
+ system "notmuch show --format=mbox id:#{m.message_id} > #{file}"\r
+ end\r
+- vim_puts "Saved #{n} patches"\r
++ vim_puts "Saved #{n} patch(es)"\r
+ EOF\r
+ endfunction\r
+ \r
+-- \r
+1.9.3\r
+\r