Posté par Emmanuel Seyman. Approuvé le Vendredi 12 Juillet à 00:08 [M]
Dépt: Presse
Le numéro 41 de Linux Magazine France contient un article sur Mutt.
David Obadia est l'auteur d'un artcle relativement court (une page) mais très intéressant sur la variable query_command de mutt qui permet de completer une adresse e-mail comme un shell complete le nom d'une commande.
David m'a envoyé le script dont il parle dans l'article mais qui n'est pas repris. Merci à lui.
#!/usr/bin/perl
# Mutt Wrapper for searching addresses in the mail directory.
#
# Distributed under the GNU GPL <www.gnu.org/copyleft/gpl.html>
# by David Obadia <david@odav.org>
#
# Add 'set query_command="perl ~/bin/mutt_grep_mailbox_wrapper.pl ~/Mail %s"'
# in your ~/.muttrc, assuming that ~/Mail is your mailbox directory.
#
# If you prefix your search pattern by the word "rehash ", or if the
# $cache_file is older than $expiration, the mailboxes will be
# reprocessed.
#
# The search pattern is a perl regex. If you're looking for David Obadia
# (that's me :)), you can for example use dav.*ob and hit <Ctrl+T> for
# mutt to call the wrapper.
#
# The database (if I may call it so) uses the E-mail addresses as unique
# keys. Therefore, if an E-mail appears with several different names, the
# wrapper will take the last one in the mailbox scanning order. If you are
# not satisfied with it, you can manually edit the database (it's a flat
# file) and change it. The wrapper will *NOT* override your changes during
# the next scan.
#
# Created: Mon, 27 Nov 2000 17:16:02 +0100
# Modified: Mon, 3 Jun 2002 18:21:02 +0200
use strict;
use DirHandle;
use FileHandle;
use MIME::QuotedPrint;
my $mailbox_directory = shift;
my $pattern = join (' ', @ARGV);
my $cache_file = $ENV{'HOME'} . '/.mutt_grep_mailbox_wrapper.db';
my $expiration = 60 * 60 * 24 * 7; # One week
my $rehash = 1;
my $discard = '---';
sub retrieve
{
my $file = new FileHandle shift;
my $data = {};
while (my ($email, $name) = split (/\s/, scalar <$file>, 2))
{
lower_case_email $email;
chomp $name;
$data->{$email} = $name;
}
undef $file;
return $data;
}
sub store
{
my $data = shift;
my $file = new FileHandle '> ' . shift;
foreach my $email (sort keys %$data)
{
print $file $email . "\t" . $data->{$email} . "\n";
}
undef $file;
return 1;
}
sub process_mailbox
{
my $data = shift;
my $tmp_data = shift;
my $mailbox = shift;
return unless -f $mailbox;
my $file = new IO::File $mailbox or die $!;
my $some_more = 0;
while (my $line = <$file>)
{
if ($line =~ /^(From|To|Cc|Bcc): (.*)$/i
or ($some_more and $line =~ /^(.*)$/i))
{