| 1 |
#!/usr/bin/perl -w
|
| 2 |
|
| 3 |
# mixmaster-filter (c) 2002 Peter Palfrader <peter@palfrader.org>
|
| 4 |
# $Id: mixmaster-filter 459 2007-11-21 10:12:30Z weasel $
|
| 5 |
#
|
| 6 |
# This program is free software. you can redistribute it and/or modify
|
| 7 |
# it under the terms of the GNU General Public License as published by
|
| 8 |
# the Free Software Foundation; either version 2 of the License, or
|
| 9 |
# (at your option) any later version.
|
| 10 |
#
|
| 11 |
# This program is distributed in the hope that it will be useful,
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
# GNU General Public License for more details.
|
| 15 |
#
|
| 16 |
# You should have received a copy of the GNU General Public License
|
| 17 |
# along with this program; if not, write to the Free Software
|
| 18 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 19 |
|
| 20 |
=pod
|
| 21 |
|
| 22 |
=head1 NAME
|
| 23 |
|
| 24 |
mixmaster-filter - Wrapper around mixmaster that removes unwanted header lines
|
| 25 |
|
| 26 |
=over
|
| 27 |
|
| 28 |
=head1 SYNOPSIS
|
| 29 |
|
| 30 |
=item B<mixmaster-filter>
|
| 31 |
|
| 32 |
=back
|
| 33 |
|
| 34 |
=head1 DESCRIPTION
|
| 35 |
|
| 36 |
B<mixmaster-filter> is a wrapper around mixmaster. It will filter out
|
| 37 |
header lines which may endager your anonymity.
|
| 38 |
|
| 39 |
All but a few options are passed on to mixmaster as is. If you specify B<-m>,
|
| 40 |
B<-g>, B<-l> or B<-n> (see mixmaster(1)) then STDIN is filtered, otherwise
|
| 41 |
mixmaster is executed as is.
|
| 42 |
|
| 43 |
It is intented to be used from Mail User Agents like the mutt(1) email reader.
|
| 44 |
|
| 45 |
=head1 OPTIONS
|
| 46 |
|
| 47 |
=over
|
| 48 |
|
| 49 |
=item B<--mixmaster>=I<MIXMASTER>
|
| 50 |
|
| 51 |
Set the path to the mixmaster binary.
|
| 52 |
|
| 53 |
=item B<--configfile>=I<FILTERCONFIGFILE>
|
| 54 |
|
| 55 |
Set a config file for B<mixmaster-filter>.
|
| 56 |
|
| 57 |
=item B<--help>
|
| 58 |
|
| 59 |
Print a brief help message and exit successfully.
|
| 60 |
|
| 61 |
=item B<--version>
|
| 62 |
|
| 63 |
Print a version information and exit successfully.
|
| 64 |
|
| 65 |
=back
|
| 66 |
|
| 67 |
All other options are passed through to mixmaster.
|
| 68 |
|
| 69 |
=head1 FILES
|
| 70 |
|
| 71 |
=over
|
| 72 |
|
| 73 |
=item B<--configfile> parameter
|
| 74 |
|
| 75 |
=item MIXMASTER_FILTER_CONF environment
|
| 76 |
|
| 77 |
=item B<~/.Mix/filter.conf>
|
| 78 |
|
| 79 |
=item B</etc/mixmaster/filter.conf>
|
| 80 |
|
| 81 |
=back
|
| 82 |
|
| 83 |
The first file that is found is used.
|
| 84 |
|
| 85 |
|
| 86 |
=head1 FILEFORMAT
|
| 87 |
|
| 88 |
The configuration file for B<mixmaster-filter> is simple. Lines with whitespace
|
| 89 |
only are ignored as are lines that have the hash our pound (C<#>) sign as their
|
| 90 |
first non whitespace character.
|
| 91 |
|
| 92 |
Lines are always truncated at the first hash our pound (C<#>) sign.
|
| 93 |
|
| 94 |
The first logical line gives the filtering policy. It's either C<FILTER> or C<ALLOW>.
|
| 95 |
|
| 96 |
All other lines are taken as a list of Headers.
|
| 97 |
|
| 98 |
If your policy is C<FILTER> headers in your list will get removed from messages.
|
| 99 |
|
| 100 |
If your policy is C<ALLOW> only headers in your list will be passed to mixmaster.
|
| 101 |
|
| 102 |
=head1 ENVIRONMENT
|
| 103 |
|
| 104 |
=over
|
| 105 |
|
| 106 |
=item MIXMASTER_FILTER_CONF
|
| 107 |
|
| 108 |
Config file to use
|
| 109 |
|
| 110 |
=item HOME
|
| 111 |
|
| 112 |
Your homedirectory. Used for finding your user configuration file. Also the
|
| 113 |
default destination directory is $HOME/.Mix/
|
| 114 |
|
| 115 |
=back
|
| 116 |
|
| 117 |
|
| 118 |
=head1 SEE ALSO
|
| 119 |
|
| 120 |
B<mixmaster>(1)
|
| 121 |
|
| 122 |
=head1 BUGS
|
| 123 |
|
| 124 |
It is far from perfect but should handle most standard cases satisfactorily.
|
| 125 |
|
| 126 |
Please report them to the Debian Bug Tracking System as described at
|
| 127 |
C<http://bugs.debian.org/> or use a tool like reportbug(1).
|
| 128 |
|
| 129 |
=head1 AUTHOR
|
| 130 |
|
| 131 |
Peter Palfrader, E<lt>peter@palfrader.orgE<gt>
|
| 132 |
|
| 133 |
=cut
|
| 134 |
|
| 135 |
use strict;
|
| 136 |
use Getopt::Long;
|
| 137 |
use English;
|
| 138 |
use Mail::Internet;
|
| 139 |
|
| 140 |
my $VERSION = '$Revision: 459 $';
|
| 141 |
my @configfiles = ( '/etc/mixmaster/filter.conf',
|
| 142 |
$ENV{'HOME'}.'/.Mix/filter.conf');
|
| 143 |
|
| 144 |
|
| 145 |
my $params;
|
| 146 |
Getopt::Long::config('bundling');
|
| 147 |
Getopt::Long::config('pass_through');
|
| 148 |
GetOptions (
|
| 149 |
'--help' => \$params->{'help'},
|
| 150 |
'--version' => \$params->{'version'},
|
| 151 |
'--configfile=s' => \$params->{'configfile'},
|
| 152 |
'--mixmaster=s' => \$params->{'mixmaster'},
|
| 153 |
);
|
| 154 |
|
| 155 |
if ($params->{'help'}) {
|
| 156 |
print "Usage: $PROGRAM_NAME [options]\n";
|
| 157 |
print "mixmaster-filter $VERSION - (c) 2002 Peter Palfrader <peter\@palfrader.org>\n";
|
| 158 |
print " --configfile FILE Also source this config file.\n";
|
| 159 |
print " --mixmaster Path to the mixmaster binary.\n";
|
| 160 |
print " --help Print this message.\n";
|
| 161 |
print " --version Print version information.\n";
|
| 162 |
print "\n";
|
| 163 |
print "ENVIRONMENT VARIABLES:\n";
|
| 164 |
print " MIXMASTER_FILTER_CONF Also source this config file.\n";
|
| 165 |
print " HOME Home directory (base for user config\n";
|
| 166 |
print " file and destination).\n";
|
| 167 |
exit 0;
|
| 168 |
};
|
| 169 |
if ($params->{'version'}) {
|
| 170 |
print ("mixmaster-filter $VERSION\n");
|
| 171 |
print ("(c) 2002 Peter Palfrader <peter\@palfrader.org>\n");
|
| 172 |
exit 0;
|
| 173 |
};
|
| 174 |
$params->{'mixmaster'} = 'mixmaster' unless defined $params->{'mixmaster'};
|
| 175 |
|
| 176 |
my $wrap = 0;
|
| 177 |
|
| 178 |
for my $arg (@ARGV) {
|
| 179 |
if ($arg eq '-n' ||
|
| 180 |
$arg eq '-p' ||
|
| 181 |
$arg eq '-m' ||
|
| 182 |
$arg eq '-l' ||
|
| 183 |
$arg eq '-'
|
| 184 |
) {
|
| 185 |
$wrap = 1;
|
| 186 |
last;
|
| 187 |
};
|
| 188 |
};
|
| 189 |
|
| 190 |
# If neither -n nor -m was passed, simply call mixmaster
|
| 191 |
unless ($wrap) {
|
| 192 |
exec ($params->{'mixmaster'}, @ARGV) or
|
| 193 |
die "Can't exec $params->{'mixmaster'}: $!\n";
|
| 194 |
};
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
# Otherwise read our config.
|
| 199 |
|
| 200 |
if (defined $params->{'configfile'}) {
|
| 201 |
open F, $params->{'configfile'} or
|
| 202 |
die ("Cannot open $params->{'configfile'}: $!\n");
|
| 203 |
} elsif (defined $ENV{'MIXMASTER_FILTER_CONF'}) {
|
| 204 |
open F, $ENV{'MIXMASTER_FILTER_CONF'} or
|
| 205 |
die ("Cannot open $ENV{'MIXMASTER_FILTER_CONF'}: $!\n");
|
| 206 |
} else {
|
| 207 |
my $conffile;
|
| 208 |
for my $file (reverse @configfiles) {
|
| 209 |
if ( -e $file) {
|
| 210 |
$conffile = $file;
|
| 211 |
last;
|
| 212 |
}
|
| 213 |
};
|
| 214 |
die ("Cannot find a config file\n") unless defined $conffile;
|
| 215 |
open F, $conffile or
|
| 216 |
die ("Cannot open $conffile: $!\n");
|
| 217 |
};
|
| 218 |
|
| 219 |
my @lines = <F>;
|
| 220 |
close F;
|
| 221 |
|
| 222 |
@lines = grep { ! /^\s*#/ } @lines;
|
| 223 |
@lines = map { s/\s*(#.*)?$//s; $_ } @lines;
|
| 224 |
@lines = grep { ! /^\s*$/ } @lines;
|
| 225 |
|
| 226 |
|
| 227 |
die ("Filtering policy not defined\n") unless (scalar @lines);
|
| 228 |
my $policy = lc(shift @lines);
|
| 229 |
die ("Filtering policy '$policy' invalid\n") unless ($policy eq 'filter' || $policy eq 'allow');
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
my $mail = new Mail::Internet( \*STDIN );
|
| 237 |
my $head = $mail->head();
|
| 238 |
my $body = $mail->body();
|
| 239 |
|
| 240 |
if ($policy eq 'filter') {
|
| 241 |
for my $header_line (@lines) {
|
| 242 |
$head->delete($header_line);
|
| 243 |
};
|
| 244 |
} else {
|
| 245 |
my @head;
|
| 246 |
my $new_header = new Mail::Header;
|
| 247 |
for my $header_line (@lines) {
|
| 248 |
for my $value ($head->get($header_line)) {
|
| 249 |
$new_header->add($header_line, $value);
|
| 250 |
};
|
| 251 |
};
|
| 252 |
$head = $new_header;
|
| 253 |
};
|
| 254 |
$mail = new Mail::Internet( Header => $head, Body => $body );
|
| 255 |
|
| 256 |
|
| 257 |
my $pid;
|
| 258 |
die "Can't fork: $!" unless defined($pid = open(KID, "|-"));
|
| 259 |
if ($pid) {
|
| 260 |
print KID $mail->as_string();
|
| 261 |
close(KID);
|
| 262 |
} else {
|
| 263 |
exec ($params->{'mixmaster'}, @ARGV) or
|
| 264 |
die "Can't exec $params->{'mixmaster'}: $!\n";
|
| 265 |
}
|
| 266 |
|
| 267 |
wait();
|
| 268 |
|
| 269 |
# vim:set ts=4:
|
| 270 |
# vim:set shiftwidth=4:
|