~ubuntu-branches/ubuntu/natty/spamassassin/natty

« back to all changes in this revision

Viewing changes to .pc/10_change_config_paths/t/data/testplugin.pm

  • Committer: Package Import Robot
  • Author(s): Noah Meyerhans
  • Date: 2010-03-21 23:20:31 UTC
  • mfrom: (0.4.1) (1.4.1) (29.2.1 maverick)
  • Revision ID: package-import@ubuntu.com-20100321232031-ryqjxh9cx27epnka
Tags: 3.3.1-1
* New upstream version.
* Update several patches now that bugfixes have been incorporated
  upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=head1 testplugin.pm
 
2
 
 
3
To try this out, write these lines to /etc/mail/spamassassin/plugintest.cf:
 
4
 
 
5
  loadplugin     myTestPlugin
 
6
  header         MY_TEST_PLUGIN eval:check_test_plugin()
 
7
 
 
8
=cut
 
9
 
 
10
package myTestPlugin;
 
11
 
 
12
use Mail::SpamAssassin::Plugin;
 
13
use Mail::SpamAssassin::Logger;
 
14
use strict;
 
15
use bytes;
 
16
 
 
17
our @ISA = qw(Mail::SpamAssassin::Plugin);
 
18
 
 
19
# constructor: register the eval rule
 
20
sub new {
 
21
  my $class = shift;
 
22
  my $mailsaobject = shift;
 
23
 
 
24
  # some boilerplate...
 
25
  $class = ref($class) || $class;
 
26
  my $self = $class->SUPER::new($mailsaobject);
 
27
  bless ($self, $class);
 
28
 
 
29
  # the important bit!
 
30
  $self->register_eval_rule ("check_test_plugin");
 
31
  $self->register_eval_rule ("check_return_2");
 
32
  $self->register_eval_rule ("sleep_based_on_header");
 
33
 
 
34
  print "registered myTestPlugin: $self\n";
 
35
  return $self;
 
36
}
 
37
 
 
38
# and the eval rule itself
 
39
sub check_test_plugin {
 
40
  my ($self, $permsgstatus) = @_;
 
41
  print "myTestPlugin eval test called: $self\n";
 
42
 
 
43
  print "test: plugins loaded: ".
 
44
        join(" ", sort $self->{main}->get_loaded_plugins_list()).
 
45
        "\n";
 
46
 
 
47
  my $file = $ENV{'SPAMD_PLUGIN_COUNTER_FILE'};
 
48
  if ($file) {
 
49
    open (IN, "<$file") or warn;
 
50
    my $count = <IN>; $count += 0;
 
51
    close IN;
 
52
 
 
53
    dbg("test: called myTestPlugin, round $count");
 
54
 
 
55
    open (OUT, ">$file") or warn;
 
56
    print OUT ++$count;
 
57
    close OUT or warn;
 
58
  }
 
59
 
 
60
  return 1;
 
61
}
 
62
 
 
63
sub sleep_based_on_header {
 
64
  my ($self, $permsgstatus) = @_;
 
65
  my $secs = $permsgstatus->{msg}->get_header("Sleep-Time");
 
66
  chop $secs;
 
67
 
 
68
  if ($secs) {
 
69
    warn "sleeping for $secs seconds...";
 
70
    sleep ($secs+0);
 
71
  }
 
72
 
 
73
  return 1;
 
74
}
 
75
 
 
76
sub check_return_2 {
 
77
  return 2;
 
78
}
 
79
 
 
80
sub extract_metadata {
 
81
  my ($self, $opts) = @_;
 
82
  my $msg = $opts->{msg};
 
83
  print "myTestPlugin extract_metadata: $self\n";
 
84
  $msg->put_metadata("Plugin-Meta-Test", "bar");
 
85
  return 1;
 
86
}
 
87
 
 
88
sub per_msg_finish {
 
89
  my ($self, $permsgstatus) = @_;
 
90
  print "myTestPlugin finishing: $self\n";
 
91
  return 1;
 
92
}
 
93
 
 
94
1;