From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 637C9431FBD for ; Mon, 26 Mar 2012 03:37:29 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aI0TTzHDlbuS for ; Mon, 26 Mar 2012 03:37:27 -0700 (PDT) Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A2C53431FAE for ; Mon, 26 Mar 2012 03:37:27 -0700 (PDT) Received: from fctnnbsc30w-142166230117.dhcp-dynamic.fibreop.nb.bellaliant.net ([142.166.230.117] helo=zancas.localnet) by tesseract.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1SC7Ij-00085s-NM; Mon, 26 Mar 2012 07:37:26 -0300 Received: from bremner by zancas.localnet with local (Exim 4.77) (envelope-from ) id 1SC7Ie-0005BK-DO; Mon, 26 Mar 2012 07:37:20 -0300 From: David Bremner To: notmuch@notmuchmail.org Subject: [Stefano Zacchiroli] Bug#628018: [PATCH] notmuch-mutt utility for notmuch/contrib/ In-Reply-To: <87haxbr6tv.fsf@zancas.localnet> User-Agent: Notmuch/0.12 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Mon, 26 Mar 2012 07:37:20 -0300 Message-ID: <87ehsfr6lb.fsf@zancas.localnet> MIME-Version: 1.0 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam_bar: - X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2012 10:37:29 -0000 Return-path: Envelope-to: david@tethera.net Delivery-date: Mon, 26 Mar 2012 06:39:14 -0300 Received: from yantan.tethera.net ([67.202.105.224]) by tesseract.cs.unb.ca with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1SC6OO-00083z-Gx for david@tethera.net; Mon, 26 Mar 2012 06:39:14 -0300 Received: from quantz.debian.org ([206.12.19.122]) by yantan.tethera.net with esmtp (Exim 4.72) (envelope-from ) id 1SC6OL-00028f-Rv for david@tethera.net; Mon, 26 Mar 2012 06:39:10 -0300 Received: from qa by quantz.debian.org with local (Exim 4.72) (envelope-from ) id 1SC6OK-0007gg-HH for david@tethera.net; Mon, 26 Mar 2012 09:39:08 +0000 Received: from busoni.debian.org ([140.211.15.34]) from C=NA,ST=NA, L=Ankh Morpork,O=Debian SMTP,OU=Debian SMTP CA,CN=busoni.debian.org, EMAIL=hostmaster@busoni.debian.org (verified) by quantz.debian.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1SC6OK-0007g8-4K for notmuch@packages.qa.debian.org; Mon, 26 Mar 2012 09:39:08 +0000 Received: from debbugs by busoni.debian.org with local (Exim 4.72) (envelope-from ) id 1SC6OJ-0003wK-8d; Mon, 26 Mar 2012 09:39:07 +0000 X-Loop: owner@bugs.debian.org Subject: Bug#628018: [PATCH] notmuch-mutt utility for notmuch/contrib/ Reply-To: Stefano Zacchiroli , 628018@bugs.debian.org Resent-From: Stefano Zacchiroli Resent-To: debian-bugs-dist@lists.debian.org Resent-CC: Carl Worth X-Loop: owner@bugs.debian.org Resent-Date: Mon, 26 Mar 2012 09:39:05 +0000 Resent-Message-ID: X-Debian-PR-Message: followup 628018 X-Debian-PR-Package: notmuch X-Debian-PR-Keywords: patch X-Debian-PR-Source: notmuch Received: via spool by 628018-submit@bugs.debian.org id=B628018.133275457414603 (code B ref 628018); Mon, 26 Mar 2012 09:39:05 +0000 Received: (at 628018) by bugs.debian.org; 26 Mar 2012 09:36:14 +0000 X-Spam-Checker-Version: SpamAssassin 3.3.1-bugs.debian.org_2005_01_02 (2010-03-16) on busoni.debian.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=4.0 tests=BAYES_00,FOURLA,FROMDEVELOPER, IMPRONONCABLE_2,MONEY,MURPHY_DRUGS_REL8,PGPSIGNATURE,STOCKLIKE autolearn=ham version=3.3.1-bugs.debian.org_2005_01_02 X-Spam-Bayes: score:0.0000 Tokens: new, 19; hammy, 151; neutral, 575; spammy, 0. spammytokens: hammytokens:0.000-+--H*c:pgp-sha256, 0.000-+--manpage, 0.000-+--H*u:1.5.21, 0.000-+--H*UA:1.5.21, 0.000-+--H*u:2010-09-15 Received: from upsilon.hackadomia.org ([91.121.245.170]) by busoni.debian.org with esmtp (Exim 4.72) (envelope-from ) id 1SC6LU-0003mg-9Y for 628018@bugs.debian.org; Mon, 26 Mar 2012 09:36:14 +0000 Received: from usha.takhisis.invalid (zack.inria.fr [128.93.60.82]) by upsilon.hackadomia.org (Postfix) with ESMTPSA id C4CD81012D for <628018@bugs.debian.org>; Mon, 26 Mar 2012 11:36:06 +0200 (CEST) Received: by usha.takhisis.invalid (Postfix, from userid 1000) id AC24F6811BA; Mon, 26 Mar 2012 11:36:06 +0200 (CEST) Date: Mon, 26 Mar 2012 11:36:06 +0200 From: Stefano Zacchiroli To: 628018@bugs.debian.org Message-ID: <20120326093606.GA3086@upsilon.cc> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="R3G7APHDIzY6R/pk" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Delivered-To: notmuch@packages.qa.debian.org Precedence: list X-Loop: notmuch@packages.qa.debian.org X-Debian: PTS X-Debian-Package: notmuch X-PTS-Package: notmuch X-PTS-Keyword: bts List-Unsubscribe: Resent-Sender: Debian QA X-Spam-Score: 0.0 X-Spam_bar: / --R3G7APHDIzY6R/pk Content-Type: multipart/mixed; boundary="82I3+IH0IqGh5yIs" Content-Disposition: inline --82I3+IH0IqGh5yIs Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Here is an updated patch set that ships the notmuch-mutt utility and updated the Debian packaging for it. It is now better integrated with notmuch: it has been renamed to "notmuch-mutt" (to match the naming convention of other notmuch interfaces) and stores all its data under ~/.cache/notmuch/mutt/ to avoid polluting user $HOME with other directories. I've also fixed the Debian packaging to generate the manpage during build. The first patch in the set adds notmuch-mutt to contrib/, the second updates debian/ to build a new "notmuch-mutt" binary package. The full story is available at http://bugs.debian.org/628018 David: I'm still unable to get through the moderation queue of the notmuch mailing list. Would you be so kind to forward this mail there, for patch review? TIA, Cheers. --=20 Stefano Zacchiroli zack@{upsilon.cc,pps.jussieu.fr,debian.org} . o . Ma=EEtre de conf=E9rences ...... http://upsilon.cc/zack ...... . . o Debian Project Leader ....... @zack on identi.ca ....... o o o =AB the first rule of tautology club is the first rule of tautology club =BB --82I3+IH0IqGh5yIs Content-Type: text/x-diff; charset=iso-8859-1 Content-Disposition: attachment; filename="0001-contrib-new-mutt-notmuch-utility-for-Mutt-integratio.patch" Content-Transfer-Encoding: quoted-printable =46rom cbb43be7d163e7662c0aa4fcb69f173074bb947d Mon Sep 17 00:00:00 2001 =46rom: Stefano Zacchiroli Date: Mon, 26 Mar 2012 10:45:58 +0200 Subject: [PATCH 1/2] contrib: new mutt-notmuch utility for Mutt integration --- contrib/notmuch-mutt/.gitignore | 2 + contrib/notmuch-mutt/Makefile | 12 ++ contrib/notmuch-mutt/README | 59 +++++++++ contrib/notmuch-mutt/notmuch-mutt | 234 ++++++++++++++++++++++++++++++= ++++ contrib/notmuch-mutt/notmuch-mutt.rc | 9 ++ 5 files changed, 316 insertions(+), 0 deletions(-) create mode 100644 contrib/notmuch-mutt/.gitignore create mode 100644 contrib/notmuch-mutt/Makefile create mode 100644 contrib/notmuch-mutt/README create mode 100755 contrib/notmuch-mutt/notmuch-mutt create mode 100644 contrib/notmuch-mutt/notmuch-mutt.rc diff --git a/contrib/notmuch-mutt/.gitignore b/contrib/notmuch-mutt/.gitign= ore new file mode 100644 index 0000000..682a577 --- /dev/null +++ b/contrib/notmuch-mutt/.gitignore @@ -0,0 +1,2 @@ +notmuch-mutt.1 +README.html diff --git a/contrib/notmuch-mutt/Makefile b/contrib/notmuch-mutt/Makefile new file mode 100644 index 0000000..87f9031 --- /dev/null +++ b/contrib/notmuch-mutt/Makefile @@ -0,0 +1,12 @@ +NAME =3D notmuch-mutt + +all: $(NAME) $(NAME).1 + +$(NAME).1: $(NAME) + pod2man $< > $@ + +README.html: README + markdown $< > $@ + +clean: + rm -f notmuch-mutt.1 README.html diff --git a/contrib/notmuch-mutt/README b/contrib/notmuch-mutt/README new file mode 100644 index 0000000..382ac91 --- /dev/null +++ b/contrib/notmuch-mutt/README @@ -0,0 +1,59 @@ +notmuch-mutt: Notmuch (of a) helper for Mutt +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +notmuch-mutt provide integration among the [Mutt] [1] mail user agent and = the +[Notmuch] [2] mail indexer. + +notmuch-mutt offer two main integration features. The first one is the abi= lity +of stating a **search query interactively** and then jump to a fresh Maild= ir +containing its search results only. The second one is the ability to +**reconstruct threads on the fly** starting from the currently highlighted +mail, which comes handy when a thread has been split across different mail= dirs, +archived, or the like. + +notmuch-mutt enables to trigger mail searches via a Mutt macro (usually F8= ) and +reconstruct threads via another (usually F9). Check the manpage for the 2-= liner +configuration snippet for your Mutt configuration files (~/.muttrc, +/etc/Muttrc, or a /etc/Muttrc.d snippet). + +A [blog style introduction] [3] to notmuch-mutt is available and includes = some +more rationale for its existence. + +Arguably, some of the logics of notmuch-mutt could disappear by adding sup= port +for a --output=3Dsymlinks flag to notmuch. + + +[1]: http://www.mutt.org/ +[2]: http://notmuchmail.org/ +[3]: http://upsilon.cc/~zack/blog/posts/2011/01/how_to_use_Notmuch_with_Mu= tt/ + + +Requirements +------------ + +To *run* notmuch-mutt you will need Perl with the following libraries: + +- Mail::Box + (Debian package: libmail-box-perl) +- Mail::Internet + (Debian package: libmailtools-perl) +- String::ShellQuote + (Debian package: libstring-shellquote-perl) +- Term::ReadLine + (Debian package: libterm-readline-gnu-perl) + +To *build* notmuch-mutt documentation you will need: + +- pod2man (coming with Perl) to generate the manpage +- markdown to generate README.html out of this file + + +License +------- + +notmuch-mutt is copyright (C) 2011-2012 Stefano Zacchiroli . + +notmuch-mutt is released under the terms of the GNU General Public License +(GPL), version 3 or above. A copy of the license is available online at +. + diff --git a/contrib/notmuch-mutt/notmuch-mutt b/contrib/notmuch-mutt/notmu= ch-mutt new file mode 100755 index 0000000..29674ec --- /dev/null +++ b/contrib/notmuch-mutt/notmuch-mutt @@ -0,0 +1,234 @@ +#!/usr/bin/perl -w +# +# notmuch-mutt - notmuch (of a) helper for Mutt +# +# Copyright: =A9 2011-2012 Stefano Zacchiroli =20 +# License: GNU General Public License (GPL), version 3 or above +# +# See the bottom of this file for more documentation. +# A manpage can be obtained by running "pod2man notmuch-mutt > notmuch-mut= t.1" + +use strict; +use warnings; + +use File::Path; +use Getopt::Long qw(:config no_getopt_compat); +use Mail::Internet; +use Mail::Box::Maildir; +use Pod::Usage; +use String::ShellQuote; +use Term::ReadLine; + + +my $cache_dir =3D "$ENV{HOME}/.cache/notmuch/mutt"; + + +# create an empty maildir (if missing) or empty an existing maildir" +sub empty_maildir($) { + my ($maildir) =3D (@_); + rmtree($maildir) if (-d $maildir); + my $folder =3D new Mail::Box::Maildir(folder =3D> $maildir, + create =3D> 1); + $folder->close(); +} + +# search($maildir, $query) +# search mails according to $query with notmuch; store results in $maildir +sub search($$) { + my ($maildir, $query) =3D @_; + $query =3D shell_quote($query); + + empty_maildir($maildir); + system("notmuch search --output=3Dfiles $query" + . " | sed -e 's: :\\\\ :g'" + . " | xargs --no-run-if-empty ln -s -t $maildir/cur/"); +} + +sub prompt($$) { + my ($text, $default) =3D @_; + my $query =3D ""; + my $term =3D Term::ReadLine->new( "notmuch-mutt" ); + my $histfile =3D "$cache_dir/history"; + + $term->ornaments( 0 ); + $term->unbind_key( ord( "\t" ) ); + $term->MinLine( 3 ); + $histfile =3D $ENV{MUTT_NOTMUCH_HISTFILE} if $ENV{MUTT_NOTMUCH_HISTFIL= E}; + $term->ReadHistory($histfile) if (-r $histfile); + while (1) { + chomp($query =3D $term->readline($text, $default)); + if ($query eq "?") { + system("man", "notmuch"); + } else { + $term->WriteHistory($histfile); + return $query; + } + } +} + +sub get_message_id() { + my $mail =3D Mail::Internet->new(\*STDIN); + $mail->head->get("message-id") =3D~ /^<(.*)>$/; # get message-id + return $1; +} + +sub search_action($$@) { + my ($interactive, $results_dir, @params) =3D @_; + + if (! $interactive) { + search($results_dir, join(' ', @params)); + } else { + my $query =3D prompt("search ('?' for man): ", join(' ', @params)); + if ($query ne "") { + search($results_dir,$query); + } + } +} + +sub thread_action(@) { + my ($results_dir, @params) =3D @_; + my $mid =3D get_message_id(); + my $tid =3D `notmuch search --output=3Dthreads id:$mid`;# get thread id + chomp($tid); + + search($results_dir, $tid); +} + +sub tag_action(@) { + my $mid =3D get_message_id(); + + system("notmuch tag " + . shell_quote(join(' ', @_)) + . " id:$mid"); +} + +sub die_usage() { + my %podflags =3D ( "verbose" =3D> 1, + "exitval" =3D> 2 ); + pod2usage(%podflags); +} + +sub main() { + mkpath($cache_dir) unless (-d $cache_dir); + + my $results_dir =3D "$cache_dir/results"; + my $interactive =3D 0; + my $help_needed =3D 0; + + my $getopt =3D GetOptions( + "h|help" =3D> \$help_needed, + "o|output-dir=3Ds" =3D> \$results_dir, + "p|prompt" =3D> \$interactive); + if (! $getopt || $#ARGV < 0) { die_usage() }; + my ($action, @params) =3D ($ARGV[0], @ARGV[1..$#ARGV]); + + foreach my $param (@params) { + $param =3D~ s/folder:=3D/folder:/g; + } + + if ($help_needed) { + die_usage(); + } elsif ($action eq "search" && $#ARGV =3D=3D 0 && ! $interactive) { + print STDERR "Error: no search term provided\n\n"; + die_usage(); + } elsif ($action eq "search") { + search_action($interactive, $results_dir, @params); + } elsif ($action eq "thread") { + thread_action($results_dir, @params); + } elsif ($action eq "tag") { + tag_action(@params); + } else { + die_usage(); + } +} + +main(); + +__END__ + +=3Dhead1 NAME + +notmuch-mutt - notmuch (of a) helper for Mutt + +=3Dhead1 SYNOPSIS + +=3Dover + +=3Ditem B [I