#!/Utils/bin/perl # # $Id: flexiblerepl,v 1.3 1995/11/01 16:16:48 belinfan Exp $ # Axel.Belinfante@cs.utwente.nl # # Use and redistribute freely. # Don't claim you wrote it. Don't make money with it. # Please inform me of bugfixes/improvements that you make. # Feedback is welcome. # # --------------------------------------------------------- # # A repl command that is to be used instead the default MH repl - # such that it can be used from the command line, but also via (eg.) xmh. # It reads a config file (~/.replconfig) which contains a mapping of # patterns, to be matched with the To: and Cc: fields of emails, # onto the repl command that is to be used when replying. # This allows you to put appropriate From: and other header lines # automatically if you receive mail via aliases. # # NOTE: it does _not_ call a special variant of repl, it _does_ call # the default repl with a special _name_ which can be used in # your mhconfig file. # # How to use: # - configure this script: you'll have to edit the first line, # and the lines below, in the Config section. # - Use this script instead of repl: put it (or a (symbolic) link to it) in # your bin directory or so, with the name 'repl', such that it is found # before the MH repl command. # - create a ~/.replconfig file, like in the example below. The # mapping patterns are perl regular expressions! # - add the corresponding entries in your ~/.mh_profile # - create the corresponding replcomps and replfilter files # # # Example: #=================================== ## repl config file ## ## format: ## comments are introduced by '#' ## whitespace (spaces, tabs) is ignored ## ## each line contains two white-space separated fields: ## a perl regular expression to be matched with the adresses in the ## to: and cc: fields from the original message, ## and the name under which the repl-command is to be executed when ## the pattern matches. ## those names can be used in the ~/.mh_profile file to specify the ## arguments of that 'version' of the repl command. ## Default action is to execute 'repl' command under its normal name 'repl'. ## ## pattern command-name # ^Firstname\.Familyname(@.*)? fullnamerepl #^Axel\.Belinfante(@.*)? myrepl #^ipstool(s?)(@.*)? ipstoolrepl #===================================== ## from the .mh_config file: #repl: -form replcomps -filter replfilter -annotate -inplace #myrepl: -form myreplcomps -filter replfilter -annotate -inplace #ipstoolrepl: -form ipstoolreplcomps -filter replfilter -annotate -inplace # #============================================================ #============================================================ # Config section $mh_bin_dir = '/Utils/bin/mh'; $mh_lib_dir = '/home/TOOLS/Mh/lib/mh'; #============================================================ #============================================================ $the_repl = $mh_bin_dir . '/' . 'repl'; $mhpath_command = $mh_bin_dir . '/' . 'mhpath'; $ap_command = $mh_lib_dir . '/' . 'ap'; $ap_format = '%<{error}%{error}: %{text}%|%(putstr(addr{text}))%>'; $configfile = '.replconfig'; $home = $ENV{'HOME'} || die 'Environment variable HOME not set'; $configfile = $home . '/' . $configfile; #open(OUT, '>/dev/ttyp3'); #print OUT "@ARGV\n"; #print OUT "$ap_command -format '$ap_format' '$adresses' |\n"; if (open(CONFIG, $configfile)) { while() { chop; s/^[ \t]+//g; s/#.*$//; next if /^$/; /^([^ \t]+)([ \t]+)([^ \t]+)/ && do { $command{$1} = $3; }; } } close(CONFIG); exec $the_repl, @ARGV unless keys %command; foreach (@ARGV) { /^(\+.*)/ && do { $folder = $1; next; }; /^-/ && do { next; }; /^([0-9]+)/ && do { $msg = $1; next; }; } open(MHPATH, "$mhpath_command $folder $msg |") || die "Could not execute $mhpath_command: $!"; while() { chop; $msgfile = $_; } close(MHPATH); open(MSG, $msgfile) || die "Could not open $msgfile: $!"; while() { chop; s/[ \t]+/ /g; if (/^to:(.*)/i) { $to = $1; $status = 'to'; } elsif (/^cc:(.*)/i) { $cc = $1; $status = 'cc'; } elsif (/^[ \t]/i) { if ($status eq 'to') { $to = $to . $_; } elsif ($status eq 'cc') { $cc = $cc . $_; } } else { $status = ''; } last if /^$/ || /^-+$/; } close(MSG); ($adresses = $to . ', ' . $cc) =~ s/[ \t]//g; $adresses =~ s/,/' '/g; # 'enquote' addresses $adresses =~ s/\([^)]*\)//g; # delete (comments) #print OUT "$ap_command -format '$ap_format' '$adresses' |\n"; open(AP, "$ap_command -format '$ap_format' '$adresses' |") || die "Could not execute $ap_command: $!"; while() { chop; push(@adresses, $_); } close(AP); foreach $key (keys %command) { @match = grep(/$key/i, @adresses); # print OUT "$key: @match\n"; exec $the_repl $command{$key}, @ARGV if @match; } exec $the_repl, @ARGV;