- $data =~ s/\AFrom [^\r\n]*\r?\n//s;
- eval {
- my @cmd = (qw(spamc -L), $train);
- my ($r, $w);
- pipe($r, $w) or die "pipe failed: $!";
- open my $null, '>', '/dev/null' or
- die "failed to open /dev/null: $!";
- my $nullfd = fileno($null);
- my %rdr = (0 => fileno($r), 1 => $nullfd, 2 => $nullfd);
- my $pid = spawn(\@cmd, undef, \%rdr);
- close $null;
- close $r or die "close \$r failed: $!";
- print $w $data or die "print \$w failed: $!";
- close $w or die "close \$w failed: $!";
- waitpid($pid, 0);
- die "spamc failed with: $?\n" if $?;
- };
- $err = $@;
+ $data =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
+
+ if ($train ne 'rm') {
+ eval {
+ if ($train eq 'ham') {
+ $spamc->hamlearn(\$data);
+ } elsif ($train eq 'spam') {
+ $spamc->spamlearn(\$data);
+ }
+ die "spamc failed with: $?\n" if $?;
+ };
+ $err = $@;
+ }