Re: Applying patches directly from emails?
[notmuch-archives.git] / ee / 0a27c1e09adaeb6005d63068c0b884fcd1300e
1 Return-Path: <imain@stemwinder.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 3860D431FBC\r
6         for <notmuch@notmuchmail.org>; Tue, 30 Sep 2014 14:09:07 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id NgVhOElQvE4R for <notmuch@notmuchmail.org>;\r
16         Tue, 30 Sep 2014 14:09:01 -0700 (PDT)\r
17 Received: from cmta17.telus.net (cmta17.telus.net [209.171.16.90])\r
18         by olra.theworths.org (Postfix) with ESMTP id 8340A431FB6\r
19         for <notmuch@notmuchmail.org>; Tue, 30 Sep 2014 14:09:01 -0700 (PDT)\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta17.telus.net with TELUS\r
21         id xZ8z1o00D1LiWEf01Z8zdN; Tue, 30 Sep 2014 15:09:01 -0600\r
22 X-Authority-Analysis: v=2.0 cv=ea3jic4H c=1 sm=2\r
23         a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8\r
24         a=UU_U-eNNhth3WP-8HIIA:9 a=EcQDfIwDZEqJA1f7rVUV8Q==:117\r
25 X-Telus-Outbound-IP: 207.102.88.62\r
26 From: Ian Main <imain@stemwinder.org>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH] Make patch saving in vim a little better.\r
29 Date: Tue, 30 Sep 2014 14:08:51 -0700\r
30 Message-Id: <1412111331-18823-1-git-send-email-imain@stemwinder.org>\r
31 X-Mailer: git-send-email 1.9.3\r
32 X-BeenThere: notmuch@notmuchmail.org\r
33 X-Mailman-Version: 2.1.13\r
34 Precedence: list\r
35 List-Id: "Use and development of the notmuch mail system."\r
36         <notmuch.notmuchmail.org>\r
37 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
38         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
39 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
40 List-Post: <mailto:notmuch@notmuchmail.org>\r
41 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
42 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
44 X-List-Received-Date: Tue, 30 Sep 2014 21:09:07 -0000\r
45 \r
46 It seems like there was some bitrot on the previous version of this\r
47 which made it not work correctly.  This fixes the bitrot and also\r
48 updates how it works.\r
49 \r
50 - Sometimes [PATCH.*] isn't at the beginning of the message (often on\r
51   lists I'm on).\r
52 - It now goes through all the messages in the thread.  for some reason\r
53   the toplevel messages didn't usually contain all the patches in my\r
54   testing.\r
55 - Check for 'Re:' at the beginning and skip if it's there.\r
56 - Save patches to filesystem-safe filename containing the subject\r
57   (unfortunately we use system()...)\r
58 \r
59     Ian\r
60 ---\r
61  vim/notmuch.vim | 14 ++++++++++----\r
62  1 file changed, 10 insertions(+), 4 deletions(-)\r
63 \r
64 diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
65 index b33c6c6..d80f22f 100644\r
66 --- a/vim/notmuch.vim\r
67 +++ b/vim/notmuch.vim\r
68 @@ -182,12 +182,18 @@ ruby << EOF\r
69         q = $curbuf.query($cur_thread)\r
70         t = q.search_threads.first\r
71         n = 0\r
72 -       t.toplevel_messages.first.replies.each do |m|\r
73 -               next if not m['subject'] =~ /^\[PATCH.*\]/\r
74 -               file = "%04d.patch" % [n += 1]\r
75 +       t.messages.each do |m|\r
76 +               next if not m['subject'] =~ /\[PATCH.*\]/\r
77 +               next if m['subject'] =~ /^Re:/\r
78 +               file = "#{m['subject']}-%04d.patch" % [n += 1]\r
79 +               # Sanitize for the filesystem\r
80 +               file.gsub!(/[^0-9A-Za-z.\-]/, '_')\r
81 +               # Remove leading underscores.\r
82 +               file.gsub!(/^_+/, '')\r
83 +               vim_puts "Saving patch to #{file}"\r
84                 system "notmuch show --format=mbox id:#{m.message_id} > #{file}"\r
85         end\r
86 -       vim_puts "Saved #{n} patches"\r
87 +       vim_puts "Saved #{n} patch(es)"\r
88  EOF\r
89  endfunction\r
90  \r
91 -- \r
92 1.9.3\r
93 \r