#!/usr/bin/perl # # extract headers from mail stream on STDIN. # For use with mutt, .e.g # # macro index "\em" ":set pipe_decode=no\nmairix-copy-message ids\n:set pipe_decode\n" use strict; use warnings; use Getopt::Long; use Mairix; my %opts; GetOptions( \%opts, 'help', 'ids', 'threads', ) or usage(); usage() if @ARGV or $opts{help}; sub usage { warn @_, "\n" if @_; (my $me = $0) =~ s,.*/,,; die <) { chomp; if ($opts{ids} && /^message-id:\s+(.+)\s*$/i) { my $value = $1; if ($value =~ /^<(.+)>$/) { push @found, "m:$1"; } else { warn "WARNING: Message-ID '$value' violates RFC.\n"; push @found, "m:$value"; } next; } if ($opts{threads}) { if ($subject) { if (/^\s+(.+)/) { # continuation line $subject .= " " . $1; next; } # next header push @found, join ' ', Mairix::subject_query($subject); undef $subject; next; } elsif (/^Subject:\s+(.+)\s*$/i) { $subject = $1; } } } # xclip doesn't work :-( if (! @found) { warn "No Message-ID header found! Press a key...\n"; my $read_key = ; exit 1; } open(FAKECLIP, ">$ENV{HOME}/.clip-mairix") or die "Couldn't open($ENV): $!\n"; foreach (@found) { my $URL = ""; print FAKECLIP "$URL\n"; print "$URL\n"; } close(FAKECLIP); # print "Press enter to continue ... "; # my $read_key = ; sleep 1; exit 0; # for mutt wait_key