summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2018-07-24 12:39:43 +0800
committerSean Whitton <spwhitton@spwhitton.name>2018-07-24 12:39:43 +0800
commit505ac26c4ca50b9f7bdf62595d679b2f32d48d82 (patch)
tree3b8690ace05373d1e11872211e92e1a237b1f907
parent252886ca8408a3a4ab787effa1a064d35f802923 (diff)
downloadmailscripts-505ac26c4ca50b9f7bdf62595d679b2f32d48d82.tar.gz
new script: notmuch-slurp-debbug
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--Makefile2
-rw-r--r--debian/control2
-rw-r--r--debian/install1
-rw-r--r--debian/manpages1
-rwxr-xr-xnotmuch-slurp-debbug64
-rw-r--r--notmuch-slurp-debbug.1.pod28
6 files changed, 96 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index bcd734e..9491e13 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-MANPAGES=mdmv.1 mbox2maildir.1
+MANPAGES=mdmv.1 mbox2maildir.1 notmuch-slurp-debbug.1
all: $(MANPAGES)
diff --git a/debian/control b/debian/control
index ca8767e..15486f3 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,7 @@ Vcs-Browser: https://git.spwhitton.name/mailscripts
Package: mailscripts
Depends: ${misc:Depends}, python3
-Recommends: notmuch
+Recommends: notmuch, devscripts
Architecture: all
Description: collection of scripts for manipulating e-mail on Debian
This package provides a collection of scripts for manipulating e-mail
diff --git a/debian/install b/debian/install
index 6912f70..dc29eb0 100644
--- a/debian/install
+++ b/debian/install
@@ -1,2 +1,3 @@
mdmv /usr/bin
mbox2maildir /usr/bin
+notmuch-slurp-debbug /usr/bin
diff --git a/debian/manpages b/debian/manpages
index 70548a8..fbbffb4 100644
--- a/debian/manpages
+++ b/debian/manpages
@@ -1,2 +1,3 @@
mdmv.1
mbox2maildir.1
+notmuch-slurp-debbug.1
diff --git a/notmuch-slurp-debbug b/notmuch-slurp-debbug
new file mode 100755
index 0000000..f92beda
--- /dev/null
+++ b/notmuch-slurp-debbug
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# notmuch-slurp-debbug -- add messages from a Debian bug to notmuch
+
+# Copyright (C) 2018 Sean Whitton
+#
+# 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 <http://www.gnu.org/licenses/>.
+
+set -e
+
+if [ $# != 1 ]; then
+ echo >&2 "$0: usage: $0 BUGNUMBER"
+ exit 1
+fi
+
+if ! which notmuch >/dev/null 2>&1; then
+ echo >&2 "$0: error: this script requires notmuch to be installed"
+ exit 1
+fi
+
+if ! which bts >/dev/null 2>&1; then
+ echo >&2 "$0: error: this script requires the devscripts package"
+ exit 1
+fi
+
+bug="$1"
+dest="$(notmuch config get database.path)"
+# ^ this is guaranteed to be a maildir, despite the name
+
+bts --mbox --mailreader 'true %s' show "$bug"
+# ^ see #904182 (try using this script ;))
+
+temp="$(mktemp -d)"
+mkdir $temp/new $temp/cur $temp/tmp
+
+# note that mb2md won't work; it thinks Debian BTS mboxes contain just
+# a single message
+mbox2maildir "${XDG_CACHE_HOME:-$HOME/.cache}"/devscripts/bts/"$bug".mbox \
+ "$temp"
+
+for f in $temp/*/*; do
+ message_id="$(grep -E -i -m 1 -e '^Message-ID:' $f \
+ | cut -d\ -f2 \
+ | sed -e 's/<//' -e 's/>//')"
+ match="$(notmuch search --limit=1 id:$message_id | wc -l)"
+ if [ "$match" = "0" ]; then
+ mdmv "$f" "$DEST"
+ fi
+done
+
+rm -rf "$temp"
+
+notmuch new
diff --git a/notmuch-slurp-debbug.1.pod b/notmuch-slurp-debbug.1.pod
new file mode 100644
index 0000000..5767778
--- /dev/null
+++ b/notmuch-slurp-debbug.1.pod
@@ -0,0 +1,28 @@
+=head1 NAME
+
+notmuch-slurp-debbug - add messages from a Debian bug to notmuch
+
+=head1 SYNOPSIS
+
+notmuch-slurp-debbug BUGNUMBER
+
+=head1 DESCRIPTION
+
+B<notmuch-slurp-debbug> adds to your notmuch database any messages
+from a given Debian bug that it does not already contain.
+
+The script adds the messages to your maildir, and then calls B<notmuch
+new>.
+
+=head1 OPTIONS
+
+None.
+
+=head1 SEE ALSO
+
+bts(1), notmuch(1)
+
+=head1 AUTHOR
+
+B<notmuch-slurp-debbug> was written by Sean Whitton
+<spwhitton@spwhitton.name>.