summaryrefslogtreecommitdiff
path: root/notmuch-extract-patch/notmuch-extract-patch
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-02-20 22:12:52 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-02-20 22:12:52 -0700
commitcc1f96c07dd0612e9ae44e41f889dd40315f0d75 (patch)
treebc960e456d1cba9a4070376d63443b1ec8b8f947 /notmuch-extract-patch/notmuch-extract-patch
parent46cedb673ae6e63724d010d3fb6a47cc209502f5 (diff)
parentbbf1fc63fa1d88ea204a8cf272511ca85a828794 (diff)
downloadmailscripts-cc1f96c07dd0612e9ae44e41f889dd40315f0d75.tar.gz
Merge tag '0.18' into buster-bpo
release 0.18 # gpg: Signature made Sat 15 Feb 2020 03:11:16 PM MST # gpg: using RSA key 9B917007AE030E36E4FC248B695B7AE4BF066240 # gpg: issuer "spwhitton@spwhitton.name" # gpg: Good signature from "Sean Whitton <spwhitton@spwhitton.name>" [ultimate] # Primary key fingerprint: 8DC2 487E 51AB DD90 B5C4 753F 0F56 D055 3B6D 411B # Subkey fingerprint: 9B91 7007 AE03 0E36 E4FC 248B 695B 7AE4 BF06 6240
Diffstat (limited to 'notmuch-extract-patch/notmuch-extract-patch')
-rwxr-xr-xnotmuch-extract-patch/notmuch-extract-patch99
1 files changed, 0 insertions, 99 deletions
diff --git a/notmuch-extract-patch/notmuch-extract-patch b/notmuch-extract-patch/notmuch-extract-patch
deleted file mode 100755
index d67e542..0000000
--- a/notmuch-extract-patch/notmuch-extract-patch
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/usr/bin/env python3
-#
-# Extract git patchset from notmuch emails
-#
-# Copyright (C) 2017 Aurelien Aptel <aurelien.aptel@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-import mailbox
-import sys
-import tempfile
-import subprocess
-import re
-import getopt
-
-def get_body(message):
- body = None
- if message.is_multipart():
- for part in message.walk():
- if part.is_multipart():
- for subpart in part.walk():
- if subpart.get_content_type() == 'text/plain':
- body = subpart.get_payload(decode=True)
- elif part.get_content_type() == 'text/plain':
- body = part.get_payload(decode=True)
- elif message.get_content_type() == 'text/plain':
- body = message.get_payload(decode=True)
-
- if isinstance(body, bytes):
- body = body.decode('utf-8')
- return body
-
-
-def is_git_patch(msg):
- # we want to skip cover letters, hence why we look for @@
- body = get_body(msg)
- match = re.search(r'''\n@@ [0-9 +,-]+ @@''', body)
- # return ("git-send-email" in msg['x-mailer'] and match)
- return match
-
-def has_reroll_count(msg, v):
- subject_prefix = get_subject_prefix(msg['subject'])
- if subject_prefix is not None:
- return "v"+str(v) in subject_prefix \
- or (v == 1 and not any(entry[0] == 'v' for entry in subject_prefix))
-
-def get_subject_prefix(s):
- match = re.search(r'''\[(.*PATCH.*)\]''', s)
- if match:
- return match.group(1).split()
-
-# if Subject: contains [PATCH nn/mm] then any text before that should
-# be stripped, as it should not form part of the commit message. (The
-# debbugs system prepends 'Bug#nnnnnn: ')
-def munge_subject(msg):
- match = re.search(r'''\[(.*PATCH.*)\].*$''', msg['subject'])
- if match:
- del msg['subject']
- msg['subject'] = match.group(0)
-
-def main():
- try:
- opts, query = getopt.getopt(sys.argv[1:], "v:", ["reroll-count="])
- except getopt.GetoptError as err:
- sys.stderr.write(str(err)+"\n")
- sys.exit(2)
- reroll_count = 1
- for o, a in opts:
- if o in ("-v", "--reroll-count"):
- reroll_count = int(a)
- with tempfile.NamedTemporaryFile() as in_mb_file:
- out = subprocess.check_output(['notmuch', 'show', '--format=mbox']+query)
- in_mb_file.write(out)
- in_mb_file.flush()
-
- in_mb = mailbox.mbox(in_mb_file.name)
- with tempfile.NamedTemporaryFile() as out_mb_file:
- out_mb = mailbox.mbox(out_mb_file.name)
- for m in in_mb:
- if is_git_patch(m) and has_reroll_count(m, reroll_count):
- sys.stderr.write(m['subject']+"\n")
- munge_subject(m)
- out_mb.add(m)
- out_mb.flush()
- print(open(out_mb_file.name).read())
-
-if __name__ == '__main__':
- main()