summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--DEVELOPER-CERTIFICATE38
-rw-r--r--Makefile11
-rw-r--r--debian/changelog5
-rw-r--r--debian/compat1
-rw-r--r--debian/control49
-rw-r--r--debian/copyright64
-rw-r--r--debian/elpa-mailscripts.elpa1
-rw-r--r--debian/mailscripts.install3
-rw-r--r--debian/mailscripts.manpages3
-rwxr-xr-xdebian/rules4
-rw-r--r--debian/source/format1
-rw-r--r--mailscripts.el46
-rwxr-xr-xmbox2maildir46
-rw-r--r--mbox2maildir.1.pod35
-rwxr-xr-xmdmv70
-rw-r--r--mdmv.1.pod31
-rw-r--r--notmuch-extract-patch/LICENSE (renamed from LICENSE)0
-rw-r--r--notmuch-extract-patch/README.md (renamed from README.md)0
-rwxr-xr-xnotmuch-extract-patch/notmuch-extract-patch (renamed from notmuch-extract-patch)0
-rwxr-xr-xnotmuch-slurp-debbug98
-rw-r--r--notmuch-slurp-debbug.1.pod55
22 files changed, 564 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c3bfb3f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*\.1
+debian/mailscripts
+debian/elpa-mailscripts
diff --git a/DEVELOPER-CERTIFICATE b/DEVELOPER-CERTIFICATE
new file mode 100644
index 0000000..912d22e
--- /dev/null
+++ b/DEVELOPER-CERTIFICATE
@@ -0,0 +1,38 @@
+Developer Certificate of Origin
+Version 1.1
+
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
+1 Letterman Drive
+Suite D4700
+San Francisco, CA, 94129
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+
+Developer's Certificate of Origin 1.1
+
+By making a contribution to this project, I certify that:
+
+(a) The contribution was created in whole or in part by me and I
+ have the right to submit it under the open source license
+ indicated in the file; or
+
+(b) The contribution is based upon previous work that, to the best
+ of my knowledge, is covered under an appropriate open source
+ license and I have the right under that license to submit that
+ work with modifications, whether created in whole or in part
+ by me, under the same open source license (unless I am
+ permitted to submit under a different license), as indicated
+ in the file; or
+
+(c) The contribution was provided directly to me by some other
+ person who certified (a), (b) or (c) and I have not modified
+ it.
+
+(d) I understand and agree that this project and the contribution
+ are public and that a record of the contribution (including all
+ personal information I submit with it, including my sign-off) is
+ maintained indefinitely and may be redistributed consistent with
+ this project or the open source license(s) involved.
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9491e13
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+MANPAGES=mdmv.1 mbox2maildir.1 notmuch-slurp-debbug.1
+
+all: $(MANPAGES)
+
+clean:
+ rm -f $(MANPAGES)
+
+%.1: %.1.pod
+ pod2man --section=1 --date="Debian Project" --center="User Commands" \
+ --name=$(subst .1,,$@) \
+ $^ $@
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..aa24a1f
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+mailscripts (0.1-1) experimental; urgency=medium
+
+ * Initial release.
+
+ -- Sean Whitton <spwhitton@spwhitton.name> Tue, 24 Jul 2018 17:33:34 +0800
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..f599e28
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+10
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..bae18f9
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,49 @@
+Source: mailscripts
+Section: mail
+Priority: optional
+Maintainer: Sean Whitton <spwhitton@spwhitton.name>
+Standards-Version: 4.1.5
+Build-Depends:
+ debhelper (>= 10),
+ dh-elpa,
+ perl,
+Vcs-Git: https://git.spwhitton.name/mailscripts
+Vcs-Browser: https://git.spwhitton.name/mailscripts
+
+Package: elpa-mailscripts
+Architecture: all
+Depends:
+ emacsen-common (>= 2.0.8),
+ mailscripts,
+ ${elpa:Depends},
+ ${misc:Depends},
+Recommends:
+ emacs (>= 46.0),
+Enhances:
+ emacs,
+ emacs25,
+Description: Emacs functions for accessing tools in the mailscripts package
+ This package adds to Emacs functions to access tools in the
+ mailscripts package from Emacs.
+
+Package: mailscripts
+Depends:
+ libconfig-tiny-perl,
+ libfile-which-perl,
+ libmime-tools-perl,
+ python3,
+ ${misc:Depends},
+ ${perl:Depends},
+Recommends:
+ devscripts,
+ notmuch,
+Architecture: all
+Description: collection of scripts for manipulating e-mail on Debian
+ This package provides a collection of scripts for manipulating e-mail
+ stored on Debian systems.
+ .
+ mdmv -- safely move messages between maildirs
+ .
+ mbox2maildir -- convert an mbox to a maildir using Python's libraries
+ .
+ notmuch-slurp-debbug -- add messages from a Debian bug to notmuch
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..7a8f35a
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,64 @@
+mailscripts
+Collection of scripts for manipulating e-mail on Debian
+
+Copyright (C)2017-2018 Sean Whitton
+
+These programs are 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.
+
+These programs are distributed in the hope that they 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.
+
+A copy of the GNU General Public License v3 can be found in
+/usr/share/common-licenses/GPL-3.
+
+
+Contributions are accepted upstram under the same terms; please sign
+off your patches (by writing an approprite Signed-Off-By tag in your
+commit message or patch submission) to indicate your attestation that
+the Developer Certificate of Origin (version 1.1) applies.
+
+
+-8<-
+
+Developer Certificate of Origin
+Version 1.1
+
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
+1 Letterman Drive
+Suite D4700
+San Francisco, CA, 94129
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+
+Developer's Certificate of Origin 1.1
+
+By making a contribution to this project, I certify that:
+
+(a) The contribution was created in whole or in part by me and I
+ have the right to submit it under the open source license
+ indicated in the file; or
+
+(b) The contribution is based upon previous work that, to the best
+ of my knowledge, is covered under an appropriate open source
+ license and I have the right under that license to submit that
+ work with modifications, whether created in whole or in part
+ by me, under the same open source license (unless I am
+ permitted to submit under a different license), as indicated
+ in the file; or
+
+(c) The contribution was provided directly to me by some other
+ person who certified (a), (b) or (c) and I have not modified
+ it.
+
+(d) I understand and agree that this project and the contribution
+ are public and that a record of the contribution (including all
+ personal information I submit with it, including my sign-off) is
+ maintained indefinitely and may be redistributed consistent with
+ this project or the open source license(s) involved.
diff --git a/debian/elpa-mailscripts.elpa b/debian/elpa-mailscripts.elpa
new file mode 100644
index 0000000..78d1c42
--- /dev/null
+++ b/debian/elpa-mailscripts.elpa
@@ -0,0 +1 @@
+mailscripts.el
diff --git a/debian/mailscripts.install b/debian/mailscripts.install
new file mode 100644
index 0000000..b2b2ce8
--- /dev/null
+++ b/debian/mailscripts.install
@@ -0,0 +1,3 @@
+mbox2maildir /usr/bin
+mdmv /usr/bin
+notmuch-slurp-debbug /usr/bin
diff --git a/debian/mailscripts.manpages b/debian/mailscripts.manpages
new file mode 100644
index 0000000..3bf8027
--- /dev/null
+++ b/debian/mailscripts.manpages
@@ -0,0 +1,3 @@
+mbox2maildir.1
+mdmv.1
+notmuch-slurp-debbug.1
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..e8e22ba
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,4 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@ --with elpa
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..163aaf8
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (quilt)
diff --git a/mailscripts.el b/mailscripts.el
new file mode 100644
index 0000000..1d8d406
--- /dev/null
+++ b/mailscripts.el
@@ -0,0 +1,46 @@
+;;; mailscripts.el --- functions to access tools in the mailscripts package
+
+;; Author: Sean Whitton <spwhitton@spwhitton.name>
+;; Version: 0.1
+
+;; 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/>.
+
+;;; Code:
+
+(require 'notmuch)
+
+;;;###autoload
+(defun notmuch-slurp-debbug (bug &optional no-open)
+ "Slurp Debian bug with bug number BUG and open the thread in notmuch.
+
+If NO-OPEN, don't open the thread."
+ (interactive "sBug number: ")
+ (call-process-shell-command (concat "notmuch-slurp-debbug " bug))
+ (unless no-open
+ (notmuch-show (concat "Bug#" bug))))
+
+;;;###autoload
+(defun notmuch-slurp-this-debbug ()
+ "When viewing a Debian bug in notmuch, download any missing messages."
+ (interactive)
+ (let ((subject (notmuch-show-get-subject)))
+ (when (string-match "Bug#\\([0-9]+\\):" subject)
+ (notmuch-slurp-debbug (match-string 1 subject) t))
+ (notmuch-refresh-this-buffer)))
+
+(provide 'mailscripts)
+
+;;; mailscripts.el ends here
diff --git a/mbox2maildir b/mbox2maildir
new file mode 100755
index 0000000..25f68df
--- /dev/null
+++ b/mbox2maildir
@@ -0,0 +1,46 @@
+#!/usr/bin/python3
+
+# mbox2maildir -- convert an mbox to a maildir using Python's libraries
+
+# 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/>.
+
+# Credits:
+
+# Daniel Kahn Gillmor made the suggestion in Debian bug #863570 that
+# Python's mailbox library could be used for the purpose of converting
+# a mbox to a maildir.
+
+import os
+import sys
+import mailbox
+
+def eprint(*args, **kwargs):
+ print(*args, file=sys.stderr, **kwargs)
+
+us = os.path.basename(sys.argv[0])
+
+if len(sys.argv) != 3:
+ eprint(us + ": usage: " + us + " MBOX MAILDIR")
+ sys.exit(1)
+
+source_path = sys.argv[1]
+dest_path = sys.argv[2]
+
+source = mailbox.mbox(source_path)
+dest = mailbox.Maildir(dest_path)
+
+for message in source:
+ dest.add(message)
diff --git a/mbox2maildir.1.pod b/mbox2maildir.1.pod
new file mode 100644
index 0000000..6e0522e
--- /dev/null
+++ b/mbox2maildir.1.pod
@@ -0,0 +1,35 @@
+=head1 NAME
+
+mbox2maildir - convert an mbox to a maildir using Python's libraries
+
+=head1 SYNOPSIS
+
+mbox2maildir MBOX MAILDIR
+
+=head1 DESCRIPTION
+
+B<mbox2maildir> converts an mbox to a maildir. It is a very simple
+wrapper around Python's mailbox library. The maildir may already
+exist, in which case the messages in the mbox are added to the
+maildir.
+
+B<mbox2maildir> is an alternative to the venerable B<mb2md>, which
+fails to process some mboxes that are out there.
+
+=head1 OPTIONS
+
+None.
+
+=head1 BUGS
+
+Hopefully different to those of B<mb2md>.
+
+=head1 SEE ALSO
+
+mb2md(1), mbox(5), maildir(5)
+
+=head1 AUTHOR
+
+B<mbox2maildir> was written by Sean Whitton
+<spwhitton@spwhitton.name>. The suggestion of using the Python
+mailbox library for this purpose is due to Daniel Kahn Gillmor.
diff --git a/mdmv b/mdmv
new file mode 100755
index 0000000..c81e52d
--- /dev/null
+++ b/mdmv
@@ -0,0 +1,70 @@
+#!/usr/bin/python3
+
+# mdmv -- safely move messages between maildirs
+
+# Copyright (C) 2017-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/>.
+
+import os
+import sys
+import time
+import shutil
+import socket
+
+def eprint(*args, **kwargs):
+ print(*args, file=sys.stderr, **kwargs)
+
+us = os.path.basename(sys.argv[0])
+
+if len(sys.argv) < 3:
+ eprint(us + ": usage: " + us + " MSG [MSG..] DEST")
+ sys.exit(1)
+
+dest = sys.argv[-1]
+
+for msg in sys.argv[1:-1]:
+ if not os.path.isfile(msg):
+ eprint(us + ": " + msg + " does not exist")
+ sys.exit(1)
+
+for d in [os.path.join(dest, "cur"), os.path.join(dest, "new"), os.path.join(dest, "tmp")]:
+ if not os.path.isdir(d):
+ eprint(us + ": " + dest + " doesn't look like a Maildir")
+ sys.exit(1)
+
+counter = 0
+
+for msg in sys.argv[1:-1]:
+ msg_name = os.path.basename(msg)
+ parts = msg_name.split(':')
+ if len(parts) == 2:
+ flags = parts[1]
+ else:
+ flags = None
+ name_prefix = "%d.%d_%d.%s" % (int(time.time()), os.getpid(),
+ counter, socket.gethostname())
+
+ if flags:
+ msg_dest = os.path.join(os.path.join(dest, 'cur'), name_prefix + ':' + flags)
+ else:
+ msg_dest = os.path.join(os.path.join(dest, 'cur'), name_prefix)
+
+ if os.path.exists(msg_dest):
+ eprint(us + ": somehow, dest " + msg_dest + " already exists")
+ sys.exit(1)
+ else:
+ shutil.move(msg, msg_dest)
+
+ counter = counter + 1
diff --git a/mdmv.1.pod b/mdmv.1.pod
new file mode 100644
index 0000000..6a7b391
--- /dev/null
+++ b/mdmv.1.pod
@@ -0,0 +1,31 @@
+=head1 NAME
+
+mdmv - safely move messages between maildirs
+
+=head1 SYNOPSIS
+
+mdmv MSG [MSG..] DEST
+
+=head1 DESCRIPTION
+
+B<mdmv> moves one or more messages, from one or more maildirs, to a
+single destination maildir. It does this in a way that should not
+confuse maildir synchronisation tools.
+
+B<mdmv> tries to be sure not to overwrite any existing files, but it
+does not try as hard to "deliver" the mail to the destination maildir
+as a real MDA would, giving up rather earlier. Thus, B<mdmv> is
+intended to be used by scripts running on the same host upon which the
+maildirs are actually stored.
+
+=head1 OPTIONS
+
+None.
+
+=head1 SEE ALSO
+
+maildir(5)
+
+=head1 AUTHOR
+
+B<mdmv> was written by Sean Whitton <spwhitton@spwhitton.name>.
diff --git a/LICENSE b/notmuch-extract-patch/LICENSE
index 94a9ed0..94a9ed0 100644
--- a/LICENSE
+++ b/notmuch-extract-patch/LICENSE
diff --git a/README.md b/notmuch-extract-patch/README.md
index ecd1ba7..ecd1ba7 100644
--- a/README.md
+++ b/notmuch-extract-patch/README.md
diff --git a/notmuch-extract-patch b/notmuch-extract-patch/notmuch-extract-patch
index df87a6c..df87a6c 100755
--- a/notmuch-extract-patch
+++ b/notmuch-extract-patch/notmuch-extract-patch
diff --git a/notmuch-slurp-debbug b/notmuch-slurp-debbug
new file mode 100755
index 0000000..226a095
--- /dev/null
+++ b/notmuch-slurp-debbug
@@ -0,0 +1,98 @@
+#!/usr/bin/perl
+
+# 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/>.
+
+use strict;
+use warnings;
+
+use Config::Tiny;
+use File::Spec::Functions 'catfile';
+use File::Which;
+use File::Temp;
+use Getopt::Long;
+use MIME::Head;
+
+my $Config = Config::Tiny->new;
+
+my $bts_server = undef;
+GetOptions('bts-server=s' => \$bts_server);
+die "notmuch-slurp-debbug: usage: notmuch-slurp-debbug [--bts-server=SERVER] BUG"
+ if (scalar @ARGV != 1);
+
+die "notmuch-slurp-debbug: this script requires notmuch to be installed"
+ unless defined which "notmuch";
+die "notmuch-slurp-debbug: this script requires the 'devscripts' apt package"
+ unless defined which "bts";
+
+my $maildir;
+my $bug = pop @ARGV;
+
+my $mailscripts_conf_dir = defined $ENV{'XDG_CONFIG_HOME'}
+ ? catfile $ENV{'XDG_CONFIG_HOME'}, "/mailscripts"
+ : catfile $ENV{'HOME'}, "/.config/mailscripts";
+
+my $notmuch_slurp_debbug_conf = "$mailscripts_conf_dir/notmuch-slurp-debbug";
+if (-f $notmuch_slurp_debbug_conf) {
+ $Config = Config::Tiny->read($notmuch_slurp_debbug_conf);
+ $maildir = $Config->{_}->{maildir};
+} else {
+ # default to where a lot of people have their inbox
+ my $database_path = `notmuch config get database.path`;
+ chomp $database_path;
+ $maildir = catfile $database_path, "inbox";
+}
+
+die "notmuch-slurp-debbug: $maildir does not look to be a maildir"
+ unless (-d catfile($maildir, "cur")
+ && -d catfile($maildir, "new")
+ && -d catfile($maildir, "tmp"));
+
+my $bts_server_arg = defined $bts_server
+ ? "--bts-server $bts_server"
+ : "";
+
+# see #904182 (try using this script ;))
+system("bts $bts_server_arg --mbox --mailreader 'true %s' show $bug") == 0
+ or die "notmuch-slurp-debbug: bts failed";
+
+my $dir = File::Temp->newdir();
+mkdir catfile($dir, "cur");
+mkdir catfile($dir, "new");
+mkdir catfile($dir, "tmp");
+
+my $devscripts_cache = defined $ENV{'XDG_CACHE_HOME'}
+ ? catfile $ENV{'XDG_CACHE_HOME'}, "devscripts", "bts"
+ : catfile $ENV{'HOME'}, ".cache", "devscripts", "bts";
+
+my $mbox = catfile $devscripts_cache, "$bug.mbox";
+
+# note that mb2md won't work; it thinks Debian BTS mboxes contain just
+# a single message
+system("mbox2maildir $mbox $dir") == 0
+ or die "notmuch-slurp-debbug: mbox2maildir failed";
+
+foreach my $message (glob "$dir/*/*") {
+ my $message_head = MIME::Head->from_file($message);
+ my $mid = $message_head->get('Message-ID');
+ $mid =~ s/(<|>)//g;
+ my $match = `notmuch search id:$mid`;
+ my $match_lines = $match =~ tr/\n//;
+ system "mdmv $message $maildir" if ($match_lines == 0);
+}
+
+system "notmuch new";
diff --git a/notmuch-slurp-debbug.1.pod b/notmuch-slurp-debbug.1.pod
new file mode 100644
index 0000000..c0f9a0a
--- /dev/null
+++ b/notmuch-slurp-debbug.1.pod
@@ -0,0 +1,55 @@
+=head1 NAME
+
+notmuch-slurp-debbug - add messages from a Debian bug to notmuch
+
+=head1 SYNOPSIS
+
+B<notmuch-slurp-debbug> [B<--bts-server=>I<SERVER>] I<BUGNUMBER>
+
+=head1 DESCRIPTION
+
+B<notmuch-slurp-debbug> adds to your notmuch database any messages
+from a given Debian bug that the database does not already contain.
+
+The script adds the messages to your maildir, and then calls B<notmuch
+new>.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--bts-server=>I<SERVER>
+
+Passed straight through to B<bts>; see bts(1).
+
+=back
+
+=head1 CONFIGURATION
+
+B<notmuch-slurp-debbug> tries to read configuration from the file
+B<$XDG_CONFIG_HOME/mailscripts/notmuch-slurp-debbug>, or if
+XDG_CONFIG_HOME is not set, it falls back to trying to read
+B<~/.config/mailscripts/notmuch-slurp-debbug>.
+
+The format is I<key = value>, one per line. The following
+configuration key is supported:
+
+=over 4
+
+=item B<maildir>
+
+The full path to a maildir indexed by notmuch into which
+B<notmuch-slurp-debbug> will insert new messages. Defaults to the
+"inbox" subdirectory of the B<database.path> key in your notmuch
+configuration.
+
+=back
+
+=head1 SEE ALSO
+
+bts(1), notmuch(1)
+
+=head1 AUTHOR
+
+B<notmuch-slurp-debbug> was written by Sean Whitton
+<spwhitton@spwhitton.name>.