Subscriber.pm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/perl
  2. # $Id:$
  3. =head1 NAME
  4. Subscriber - plugin for checking if a user is in the subscriber list
  5. =head1 INSTALLATION
  6. Just copy Subscriber.pm into your SpamAssassin Plugin path
  7. (e.g /usr/share/perl5/Mail/SpamAssassin/Plugin/) and
  8. add a loadplugin call into your init.pre file.
  9. =head1 SYNOPSIS
  10. loadplugin Mail::SpamAssassin::Plugin::Subscriber
  11. =head1 USER SETTINGS
  12. =over 4
  13. =item subscriber_file [ file ]
  14. Where to find the subscribers
  15. Subscribers are E-Mail adresses one per line
  16. =cut
  17. =back
  18. =cut
  19. =head1 DESCRIPTION
  20. Checks if one of the from addresses is in the subscriber file.
  21. If you want to use this plugin load it from a config file (e.g. init.pre):
  22. B<loadplugin Mail::SpamAssassin::Plugin::Subscriber>
  23. Afterwards you have to define the test:
  24. B<header IS_SUBSCRIBER eval:check_for_subscriber('subscriberfile')>
  25. check_for_subscriber accepts a filename which will be checked instead of the default file or the one specified
  26. in the config.
  27. B<score IS_SUBSCRIBER -50>
  28. =head1 AUTHOR
  29. Alexander Wirt <formorer@formorer.de>
  30. =head1 COPYRIGHT
  31. Copyright 2006 Alexander Wirt <formorer@formorer.de>
  32. Licensed under the Apache License, Version 2.0 (the "License");
  33. you may not use this file except in compliance
  34. with the License. You may obtain a copy of the License at
  35. http://www.apache.org/licenses/LICENSE-2.0 Unless required
  36. by applicable law or agreed to in writing, software distributed
  37. under the License is distributed on an "AS IS" BASIS, WITHOUT
  38. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  39. See the License for the specific language governing permissions
  40. and limitations under the License.
  41. =cut
  42. package Mail::SpamAssassin::Plugin::Subscriber;
  43. use Mail::SpamAssassin::Plugin;
  44. use Mail::SpamAssassin::Logger;
  45. use strict;
  46. use warnings;
  47. use Data::Dumper;
  48. use vars qw(@ISA);
  49. @ISA = qw(Mail::SpamAssassin::Plugin);
  50. sub new {
  51. my ($class, $mailsa) = @_;
  52. # the usual perlobj boilerplate to create a subclass object
  53. $class = ref($class) || $class;
  54. my $self = $class->SUPER::new($mailsa);
  55. bless ($self, $class);
  56. # register our config options
  57. $self->set_config($mailsa->{conf});
  58. $self->register_eval_rule ("check_for_subscriber");
  59. # and return the new plugin object
  60. return $self;
  61. }
  62. sub set_config {
  63. my ($self, $conf) = @_;
  64. my @cmds = ();
  65. push (@cmds, {
  66. setting => 'subscriber_file',
  67. default => '',
  68. type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
  69. });
  70. $conf->{parser}->register_commands(\@cmds);
  71. }
  72. sub check_for_subscriber {
  73. my ($self, $message_status, $filename) = @_;
  74. my $subscribers = $filename || $message_status->{main}->{conf}->{subscriber_file};
  75. return 0 unless $subscribers;
  76. my %subscribers;
  77. if (-f $subscribers) {
  78. if (open (my $fh,'<', $subscribers)) {
  79. while (<$fh>) {
  80. chomp;
  81. $subscribers { $_ } = 1;
  82. }
  83. close($fh);
  84. } else {
  85. dbg("subscribers: could not open subscriber file $subscribers: $!");
  86. return 0;
  87. }
  88. } else {
  89. dbg("subscribers: subscribers file '$subscribers' does not exist");
  90. return 0;
  91. }
  92. foreach my $from (@{$message_status->{all_from_addrs}}) {
  93. return 1 if exists $subscribers{ $from };
  94. }
  95. return 0;
  96. }
  97. 1;
  98. # vim: syntax=perl sw=4 ts=4 noet shiftround