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 20675431FAF for ; Mon, 26 Mar 2012 03:32:23 -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 kOKsp0-mdRHT for ; Mon, 26 Mar 2012 03:32:21 -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 C4563431FAE for ; Mon, 26 Mar 2012 03:32:20 -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 1SC7Dm-00085e-7r; Mon, 26 Mar 2012 07:32:19 -0300 Received: from bremner by zancas.localnet with local (Exim 4.77) (envelope-from ) id 1SC7Dg-000586-Qv; Mon, 26 Mar 2012 07:32:12 -0300 From: David Bremner To: notmuch@notmuchmail.org Subject: [Stefano Zacchiroli] Bug#628018: [PATCH] mutt-notmuch in notmuch contrib User-Agent: Notmuch/0.12 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Mon, 26 Mar 2012 07:32:12 -0300 Message-ID: <87haxbr6tv.fsf@zancas.localnet> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam_bar: - Cc: Stefano Zacchiroli 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:32:23 -0000 --=-=-= Hi, this will probably eventually make it to the list, but until then, here is a forwarded version. Please keep Stefano in CC, I don't think he's subscribed. --=-=-= Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 8bit Return-path: Envelope-to: david@tethera.net Delivery-date: Sun, 25 Mar 2012 11:29:53 -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 1SBoS6-0007Ps-Gz for david@tethera.net; Sun, 25 Mar 2012 11:29:53 -0300 Received: from quantz.debian.org ([206.12.19.122]) by yantan.tethera.net with esmtp (Exim 4.72) (envelope-from ) id 1SBoS5-0001U1-C0 for david@tethera.net; Sun, 25 Mar 2012 11:29:49 -0300 Received: from qa by quantz.debian.org with local (Exim 4.72) (envelope-from ) id 1SBoS4-0005Po-Gi for david@tethera.net; Sun, 25 Mar 2012 14:29:48 +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 1SBoS4-0005PY-4y for notmuch@packages.qa.debian.org; Sun, 25 Mar 2012 14:29:48 +0000 Received: from debbugs by busoni.debian.org with local (Exim 4.72) (envelope-from ) id 1SBoS2-0003w7-D7; Sun, 25 Mar 2012 14:29:47 +0000 X-Loop: owner@bugs.debian.org Subject: Bug#628018: [PATCH] mutt-notmuch in notmuch contrib Reply-To: Stefano Zacchiroli , 628018-quiet@bugs.debian.org Resent-From: Stefano Zacchiroli Resent-To: Resent-Date: Sun, 25 Mar 2012 14:29:45 +0000 Resent-Message-ID: X-Loop: owner@bugs.debian.org X-Debian-PR-Message: followup 628018 X-Debian-PR-Package: notmuch X-Debian-PR-Keywords: X-Debian-PR-Source: notmuch Received: via spool by 628018-quiet@bugs.debian.org id=Q628018.13326841347285 (code Q ref 628018); Sun, 25 Mar 2012 14:29:45 +0000 Received: (at 628018-quiet) by bugs.debian.org; 25 Mar 2012 14:02: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, 148; hammy, 151; neutral, 665; 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 1SBo15-0001rp-N4 for 628018-quiet@bugs.debian.org; Sun, 25 Mar 2012 14:02:05 +0000 Received: from usha.takhisis.invalid (did75-22-78-236-196-47.fbx.proxad.net [78.236.196.47]) by upsilon.hackadomia.org (Postfix) with ESMTPSA id 41A3A1012D; Sun, 25 Mar 2012 16:01:52 +0200 (CEST) Received: by usha.takhisis.invalid (Postfix, from userid 1000) id B01B5681E70; Sun, 25 Mar 2012 16:01:51 +0200 (CEST) Date: Sun, 25 Mar 2012 16:01:51 +0200 From: Stefano Zacchiroli To: notmuch@notmuchmail.org CC: 628018-quiet@bugs.debian.org, David Bremner , Ben Boeckel Message-ID: <20120325140151.GA12546@upsilon.cc> References: <87iphszuv1.fsf@zancas.localnet> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CdrF4e02JqNVZeln" Content-Disposition: inline In-Reply-To: <87iphszuv1.fsf@zancas.localnet> 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: / --CdrF4e02JqNVZeln Content-Type: multipart/mixed; boundary="M9NhX3UHpAaciwkO" Content-Disposition: inline --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable [ please Cc:-me on follow-ups, as I'm not subscribed to the notmuch@notmuchmail.org mailing list ] On Sun, Mar 25, 2012 at 10:13:38AM -0300, David Bremner wrote: > In the mean time, we at least have a contrib directory, and I think > mutt-notmuch would be welcome there. Could you (or somebody) make a > reasonable size patch series that adds it to contrib/mutt-notmuch > against current master. The patch series should be sent to the > upstream mailing list notmuch@notmuchmail.org for review. Hi David, thanks for the tip. Dear notmuch list, please find attached a proposed patch that add a new contrib utility called mutt-notmuch for integration with Mutt. Its full rationale can be found in the contained README. Background for this submission, including previous discussions to ship mutt-notmuch as part of notmuch, can be found at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D628018 I welcome your comments on how to adapt the patch to your preferences for contrib/, err, contributions. > On the debian side your patch series could also include the necessary > changes to make a new binary package. I'll be pleased to do so when/if mutt-notmuch is accepted in contrib/, just out of general laziness for potentially useless work :-) Thanks, 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 --M9NhX3UHpAaciwkO Content-Type: text/x-diff; charset=iso-8859-1 Content-Disposition: attachment; filename="0001-contrib-new-utility-mutt-notmuch-for-Mutt-integratio.patch" Content-Transfer-Encoding: quoted-printable =46rom 8f5be32912920c2c5eca7084885c0e2498540311 Mon Sep 17 00:00:00 2001 =46rom: Stefano Zacchiroli Date: Sun, 25 Mar 2012 15:55:44 +0200 Subject: [PATCH] contrib: new utility mutt-notmuch for Mutt integration --- contrib/mutt-notmuch/Makefile | 12 ++ contrib/mutt-notmuch/README | 58 +++++++++ contrib/mutt-notmuch/mutt-notmuch | 234 +++++++++++++++++++++++++++++++= ++++ contrib/mutt-notmuch/mutt-notmuch.1 | 210 +++++++++++++++++++++++++++++++ 4 files changed, 514 insertions(+), 0 deletions(-) create mode 100644 contrib/mutt-notmuch/Makefile create mode 100644 contrib/mutt-notmuch/README create mode 100755 contrib/mutt-notmuch/mutt-notmuch create mode 100644 contrib/mutt-notmuch/mutt-notmuch.1 diff --git a/contrib/mutt-notmuch/Makefile b/contrib/mutt-notmuch/Makefile new file mode 100644 index 0000000..b78953d --- /dev/null +++ b/contrib/mutt-notmuch/Makefile @@ -0,0 +1,12 @@ +NAME =3D mutt-notmuch + +all: $(NAME) $(NAME).1 + +$(NAME).1: $(NAME) + pod2man $< > $@ + +README.html: README + markdown $< > $@ + +clean: + rm -f mutt-notmuch.1 README.html diff --git a/contrib/mutt-notmuch/README b/contrib/mutt-notmuch/README new file mode 100644 index 0000000..e72aa91 --- /dev/null +++ b/contrib/mutt-notmuch/README @@ -0,0 +1,58 @@ +mutt-notmuch: 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 + +mutt-notmuch provide integration among the [Mutt] [1] mail user agent and = the +[Notmuch] [2] mail indexer. + +mutt-notmuch offer two basic integration features. The first one is the ab= ility +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. + +mutt-notmuch enables to trigger mail searches via a Mutt macro (F8 being my +choice) and reconstruct threads via another (F9). Check the manpage for the +2-liner configuration snippet for your ~/.muttrc. + +A [blog style introduction] [3] to mutt-notmuch is available and includes = some +more rationale for its existence. + +Arguably, some of the logics of mutt-notmuch 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* mutt-notmuch 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* mutt-notmuch documentation you will need: + +- pod2man (coming with Perl) to generate the manpage +- markdown to generate README.html out of this file + + +License +------- + +mutt-notmuch is copyright (C) 2011-2012 Stefano Zacchiroli . + +mutt-notmuch 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/mutt-notmuch/mutt-notmuch b/contrib/mutt-notmuch/mutt-= notmuch new file mode 100755 index 0000000..31cb539 --- /dev/null +++ b/contrib/mutt-notmuch/mutt-notmuch @@ -0,0 +1,234 @@ +#!/usr/bin/perl -w +# +# mutt-notmuch - 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 mutt-notmuch > mutt-notmuc= h.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; + + +# 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( "mutt-notmuch" ); + $term->ornaments( 0 ); + $term->unbind_key( ord( "\t" ) ); + $term->MinLine( 3 ); + if ($ENV{MUTT_NOTMUCH_HISTFILE} && -r "$ENV{MUTT_NOTMUCH_HISTFILE}") { + $term->ReadHistory("$ENV{MUTT_NOTMUCH_HISTFILE}"); + } elsif (-r "$ENV{HOME}/.mutt-notmuch.history") { + $term->ReadHistory("$ENV{HOME}/.mutt-notmuch.history"); + } + while (1) { + chomp($query =3D $term->readline($text, $default)); + if ($query eq "?") { + system("man", "notmuch"); + } else { + if (!$ENV{MUTT_NOTMUCH_HISTFILE} || + !$term->WriteHistory("$ENV{MUTT_NOTMUCH_HISTFILE}")) { + $term->WriteHistory("$ENV{HOME}/.mutt-notmuch.history"); + } + 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() { + my $results_dir =3D "$ENV{HOME}/.cache/mutt_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 + +mutt-notmuch - notmuch (of a) helper for Mutt + +=3Dhead1 SYNOPSIS + +=3Dover + +=3Ditem B [I