~ubuntu-branches/ubuntu/utopic/spamassassin/utopic-proposed

« back to all changes in this revision

Viewing changes to spamassassin.raw

  • Committer: Bazaar Package Importer
  • Author(s): Noah Meyerhans
  • Date: 2010-01-26 22:53:12 UTC
  • mfrom: (1.1.13 upstream) (5.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100126225312-wkftb10idc1kz2aq
Tags: 3.3.0-1
* New upstream version.
* Switch to dpkg-source 3.0 (quilt) format

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
use strict;
21
21
use warnings;
 
22
use re 'taint';
22
23
 
23
24
use File::Spec;
24
25
 
111
112
 
112
113
sub print_version {
113
114
  print "SpamAssassin version " . Mail::SpamAssassin::Version() . "\n"
114
 
      . "  running on Perl version " . join(".", map { $_||=0; $_*1 } ($] =~ /(\d)\.(\d{3})(\d{3})?/ )) . "\n";
 
115
      . "  running on Perl version " . join(".", map { $_||=0; $_*1 } ($] =~ /(\d)\.(\d{3})(\d{3})?/ )) . "\n"
 
116
    or die "error writing: $!";
115
117
}
116
118
 
117
119
sub print_usage_and_exit {
120
122
 
121
123
  if ($respnam eq 'EX_OK' ) {
122
124
    print_version();
123
 
    print("\n");
 
125
    print("\n")  or die "error writing: $!";
124
126
  }
125
127
  pod2usage(
126
128
    -verbose => 0,
137
139
  my ( $verbose, $message ) = @_;
138
140
  my $ver = Mail::SpamAssassin::Version();
139
141
 
140
 
  print "SpamAssassin version $ver\n";
 
142
  print "SpamAssassin version $ver\n"  or die "error writing: $!";
141
143
  pod2usage( -verbose => $verbose, -message => $message, -exitval => 64, -input => "spamassassin-run.pod", -pathlist => \@INC );
142
144
 
143
145
}
234
236
}
235
237
 
236
238
if (Mail::SpamAssassin::Util::am_running_on_windows()) {
237
 
  binmode(STDIN);       # bug 4363
238
 
  binmode(STDOUT);
 
239
  binmode(STDIN)  or die "cannot set binmode on STDIN: $!";  # bug 4363
 
240
  binmode(STDOUT) or die "cannot set binmode on STDOUT: $!";
239
241
}
240
242
 
241
243
# bug 5048: --lint should not cause network accesses
252
254
    debug               => $opt{'debug'},
253
255
    dont_copy_prefs     => ( $opt{'create-prefs'} ? 0 : 1 ),
254
256
    post_config_text    => join("\n", @{$opt{'cf'}})."\n",
 
257
    require_rules       => 1,
255
258
    PREFIX              => $PREFIX,
256
259
    DEF_RULES_DIR       => $DEF_RULES_DIR,
257
260
    LOCAL_RULES_DIR     => $LOCAL_RULES_DIR,
263
266
  $spamtest->debug_diagnostics();
264
267
  my $res = $spamtest->lint_rules();
265
268
  warn "lint: $res issues detected, please rerun with debug enabled for more information\n" if ($res);
 
269
  # make sure we notice any write errors while flushing output buffer
 
270
  close STDOUT  or die "error closing STDOUT: $!";
 
271
  close STDIN   or die "error closing STDIN: $!";
266
272
  exit $res ? 1 : 0;
267
273
}
268
274
 
273
279
  $spamtest->init(1);
274
280
 
275
281
  if ( $opt{'add-addr-to-whitelist'} ) {
276
 
    $spamtest->add_address_to_whitelist( $opt{'add-addr-to-whitelist'} );
 
282
    $spamtest->add_address_to_whitelist($opt{'add-addr-to-whitelist'}, 1);
277
283
  }
278
284
  elsif ( $opt{'remove-addr-from-whitelist'} ) {
279
 
    $spamtest->remove_address_from_whitelist(
280
 
      $opt{'remove-addr-from-whitelist'} );
 
285
    $spamtest->remove_address_from_whitelist($opt{'remove-addr-from-whitelist'}, 1);
281
286
  }
282
287
  elsif ( $opt{'add-addr-to-blacklist'} ) {
283
 
    $spamtest->add_address_to_blacklist( $opt{'add-addr-to-blacklist'} );
 
288
    $spamtest->add_address_to_blacklist($opt{'add-addr-to-blacklist'}, 1);
284
289
  }
285
290
  else {
286
291
    die "spamassassin: oops! unhandled whitelist operation";
287
292
  }
288
293
 
 
294
  $spamtest->finish();
 
295
  # make sure we notice any write errors while flushing output buffer
 
296
  close STDOUT  or die "error closing STDOUT: $!";
 
297
  close STDIN   or die "error closing STDIN: $!";
289
298
  exit(0);
290
299
}
291
300
 
327
336
    }
328
337
    else {
329
338
      my $handle;
330
 
 
331
 
      local $/ = undef;    # go into slurp mode
332
339
      ( $tempfile, $handle ) = Mail::SpamAssassin::Util::secure_tmpfile();
333
 
      binmode $handle;
334
 
      print {$handle} <STDIN>;
335
 
      close $handle;
 
340
      binmode $handle  or die "cannot set binmode on file $tempfile: $!";
 
341
 
 
342
      # avoid slurping the whole file into memory, copy chunk by chunk
 
343
      my($inbuf,$nread);
 
344
      while ( $nread=sysread(STDIN,$inbuf,16384) )
 
345
        { print {$handle} $inbuf  or die "error writing to $tempfile: $!" }
 
346
      defined $nread  or die "error reading from STDIN: $!";
 
347
      close $handle   or die "cannot close $tempfile: $!";
336
348
 
337
349
      # re-aim the targets at the tempfile instead of STDIN
338
350
      $targets[$elem] =~ s/-$/$tempfile/;
364
376
# bug 4930: use a temp variable since "||=" decides whether or not to set the
365
377
# value before the RHS is actually run, so if the RHS separately sets the LHS
366
378
# variable, things don't work right.  Stupid global variables. ;)
367
 
eval { my $runreturn = !$iter->run(@targets);  $exitvalue ||= $runreturn; };
 
379
my $eval_stat;
 
380
eval {
 
381
  my $runreturn = !$iter->run(@targets);  $exitvalue ||= $runreturn;  1;
 
382
} or do {
 
383
  $eval_stat = $@ ne '' ? $@ : "errno=$!";  chomp $eval_stat;
 
384
};
368
385
 
369
386
$progress->final() if ($opt{progress} && $progress);
370
387
 
371
388
# If we needed to make a tempfile, go delete it now.
372
 
if ( defined $tempfile ) {
373
 
  unlink $tempfile;
 
389
if (defined $tempfile) {
 
390
  unlink $tempfile  or die "cannot unlink temporary file $tempfile: $!";
 
391
  undef $tempfile;
374
392
}
375
393
 
376
394
# Let folks know how many messages were handled, as long as the handling
377
395
# didn't produce output (ala: check, test, or remove_markup ...)
378
396
if ( $opt{'report'} || $opt{'revoke'} || $doing_whitelist_operation ) {
379
 
  print "$count message(s) examined.\n";
 
397
  print "$count message(s) examined.\n"  or die "error writing: $!";
380
398
}
381
399
 
382
400
# if the eval died from something, report it here and return an error.
383
 
if ($@) { die $@; }
384
 
 
 
401
if (defined $eval_stat) { die $eval_stat; }
 
402
 
 
403
$spamtest->finish()  if $spamtest;
 
404
 
 
405
# make sure we notice any write errors while flushing output buffer
 
406
close STDOUT  or die "error closing STDOUT: $!";
 
407
close STDIN   or die "error closing STDIN: $!";
385
408
# Ok, exit!
386
409
exit( $exitvalue || 0 );
387
410
 
421
444
  # This is a short cut -- doing white/black-list?  Do it and return quickly.
422
445
  if ($doing_whitelist_operation) {
423
446
    if ( $opt{'add-to-whitelist'} ) {
424
 
      $spamtest->add_all_addresses_to_whitelist($mail);
 
447
      $spamtest->add_all_addresses_to_whitelist($mail, 1);
425
448
    }
426
449
    elsif ( $opt{'remove-from-whitelist'} ) {
427
 
      $spamtest->remove_all_addresses_from_whitelist($mail);
 
450
      $spamtest->remove_all_addresses_from_whitelist($mail, 1);
428
451
    }
429
452
    elsif ( $opt{'add-to-blacklist'} ) {
430
 
      $spamtest->add_all_addresses_to_blacklist($mail);
 
453
      $spamtest->add_all_addresses_to_blacklist($mail, 1);
431
454
    }
432
455
    else {
433
456
      warn "spamassassin: oops! unhandled whitelist operation";
492
515
 
493
516
  # OK, do checks and put out the message.
494
517
  my $status = $spamtest->check($mail);
495
 
  print $status->rewrite_mail ();
 
518
  print $status->rewrite_mail()  or die "error writing: $!";
496
519
 
497
520
  if ( $opt{'test-mode'} ) {
498
521
    use bytes;
499
 
    print $status->get_report();
 
522
    print $status->get_report()  or die "error writing: $!";
500
523
  }
501
524
 
502
525
  # if this message was spam, set the exit value appropriately.
520
543
  $SIG{HUP}  = \&kill_handler;
521
544
  $SIG{INT}  = \&kill_handler;
522
545
  $SIG{TERM} = \&kill_handler;
523
 
  $SIG{PIPE} = \&kill_handler;
 
546
# $SIG{PIPE} = \&kill_handler;
 
547
  $SIG{PIPE} = 'IGNORE';
524
548
}
525
549
 
526
550
sub kill_handler {
530
554
    $mail->finish();      # bug 5626: remove temp files etc.
531
555
    $mail = undef;
532
556
  }
533
 
  exit 0;
 
557
  if (defined $tempfile) {      # bug 5557: additional paranoia about tmpfiles
 
558
    unlink $tempfile  or warn "cannot unlink temporary file $tempfile: $!";
 
559
    undef $tempfile;
 
560
  }
 
561
  close STDOUT; close STDIN;  # ignoring status
 
562
  exit 15;
534
563
}
535
564
 
536
565
# ---------------------------------------------------------------------------
537
566
 
 
567
=pod
 
568
 
538
569
=cut
539
570
 
540
571
=head1 NAME