3 # Wrapper to call ispell on mail messages, ignoring quoted portions
5 # By Brendan O'Dea <bod@debian.org>, public domain.
6 # Usage: set ispell = /usr/lib/mutt/mailspell
11 use File::Copy 'move';
15 my $ISPELL = 'ispell';
19 # make sure that we don't inherit SIGCHLD
20 $SIG{CHLD} = 'DEFAULT';
22 # ignore -x ispell option
23 shift if $ARGV[0] eq '-x';
24 die "Usage: $0 [-x] FILE\n" unless @ARGV == 1;
28 # create temporary files
32 unlink $ed{path} if $ed{path};
33 unlink $orig{path} if $orig{path};
36 foreach (\%orig, \%ed) {
38 $_->{fd} = IO::File->new($_->{path}, O_RDWR|O_CREAT|O_EXCL, 0600)
39 or die "$0: can't create $_->{path} ($!)";
46 # drop quoted text and attribution
47 $orig{fd}->print($_) unless /^>/ or /^On \w{3}, \w{3} \d{2}, \d{4} at \d/;
53 die "$0: can't fork ($!)\n" unless defined $pid;
55 open STDOUT, '>&=' . $ed{fd}->fileno
56 or die "$0: can't dup stdout to ed script ($!)\n";
58 exec $DIFF, '-e', $orig{path}, $msg;
59 die "$0: can't exec $DIFF ($!)\n";
62 die "$0: can't reap child ($!)\n" unless wait == $pid;
63 system $ISPELL, '-x', $orig{path}
64 and die "$0: problem with $ISPELL ($?)\n";
66 $ed{fd}->seek(0, SEEK_END);
67 $ed{fd}->print("w\nq\n");
68 $ed{fd}->seek(0, SEEK_SET);
70 open STDIN, '<&=' . $ed{fd}->fileno
71 or die "$0: can't dup stdin from ed script ($!)\n";
73 system $ED, '-s', $orig{path} and die "$0: problem with $ED ($?)\n";
74 move $orig{path}, $msg or die "$0: can't replace $msg ($!)\n";