From 2ccfaae0ea4ce8ab691f1b1a0e8481e9b43dbe1c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 3 May 2019 21:10:08 -0700 Subject: new scripts: maildir-import-patch(1), notmuch-import-patch(1) Signed-off-by: Sean Whitton --- notmuch-import-patch | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 notmuch-import-patch (limited to 'notmuch-import-patch') diff --git a/notmuch-import-patch b/notmuch-import-patch new file mode 100755 index 0000000..ea61634 --- /dev/null +++ b/notmuch-import-patch @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +# notmuch-import-patch -- import a git patch series into notmuch + +# Copyright (C) 2019 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 . + +use strict; +use warnings; + +use Config::Tiny; +use File::Spec::Functions qw(catfile); +use File::Which; +use IPC::System::Simple qw(systemx); + +my $Config = Config::Tiny->new; + +die "notmuch-import-patch: this script requires git to be installed" + unless defined which "git"; +die "notmuch-import-patch: this script requires notmuch to be installed" + unless defined which "notmuch"; + +my $maildir; + +my $mailscripts_conf_dir = defined $ENV{'XDG_CONFIG_HOME'} + ? catfile $ENV{'XDG_CONFIG_HOME'}, "/mailscripts" + : catfile $ENV{'HOME'}, "/.config/mailscripts"; + +my $notmuch_import_patch_conf = "$mailscripts_conf_dir/notmuch-import-patch"; +if (-f $notmuch_import_patch_conf) { + $Config = Config::Tiny->read($notmuch_import_patch_conf); + $maildir = $Config->{_}->{maildir}; +} else { + # user probably doesn't want our generated patches, which are not + # real e-mails, to go into their inbox + my $database_path = `notmuch config get database.path`; + chomp $database_path; + $maildir = catfile $database_path, "patches"; +} + +die "notmuch-import-patch: $maildir does not look to be a maildir" + unless (-d catfile($maildir, "cur") + && -d catfile($maildir, "new") + && -d catfile($maildir, "tmp")); + +systemx("maildir-import-patch", $maildir, @ARGV); + +systemx(qw(notmuch new)); -- cgit v1.2.3