Debian Codegraph @

procmail/cufilter

raw ◀ ▶
1 Debian patch touch this file
1 #!/usr/bin/perl
2
3 =pod
•4
5 =head1 NAME
6
7 cufilter - Filter emails through Mail::CheckUser
8
9 =head1 SYNOPSIS
10
11 Add the following lines to your ~/.procmailrc:
12
13 # Filter mail through Mail::CheckUser
14 :0f
15 | /usr/bin/cufilter
16
17
18 =head1 DESCRIPTION
19
20 When email messages are filtered through this program
21 using the procmail settings as outlined in the SYNOPSYS,
22 the email address in the "From:" header is passed through
23 Mail::CheckUser to ensure validity. If there is a problem
24 with the email address, the "Subject:" header is modified
25 to show which email address failed along with the failure
26 reason. No messages are lost, but it provides an easy way
27 for the mail client to organize, sort, or filter based on
28 the subject tweaks.
29
30 =head1 EXAMPLES
31
32 Lets say a spammer sends a message with the following headers:
33
34 From: [email protected]
35 To: [email protected]
36 Subject: Happy Pill
37
38 Then the new headers might change to the following:
39
40 From: [email protected]
41 To: [email protected]
42 Subject: [[email protected]!DNS failure: SERVFAIL] Happy Pill
43
44 This makes it easy to filter for mail clients.
45
46 =head1 INSTALL
47
48 This file can be installed into /usr/bin/cufilter and
49 is intended to be utilized through the procmail
50 functionality by adding the following lines to your
51 ~/.procmailrc configuration.
52
53 # Filter mail through Mail::CheckUser
54 :0f
55 | /usr/bin/cufilter
56
57 =head1 AUTHORS
58
59 Rob Brown [email protected]
60
61 =head1 COPYRIGHT
62
63 Copyright (c) 2003 Rob Brown [email protected].
64 All rights reserved.
65
66 This program is free software; you can redistribute it and/or modify
67 it under the same terms as Perl itself.
68
69 $Id: cufilter,v 1.3 2003/09/18 15:36:26 hookbot Exp $
70
71 =head1 SEE ALSO
72
73 Mail::CheckUser(3),
74 procmail(1).
75
76 =cut
77
78 use strict;
79 use Mail::CheckUser qw(check_email last_check);
80 use vars qw($VERSION);
81
82 $Mail::CheckUser::Timeout = 300;
83 $Mail::CheckUser::Treat_Timeout_As_Fail = 1;
84 $Mail::CheckUser::Treat_Full_As_Fail = 1;
85
86 $VERSION = "0.03";
87 my $HEAD = "";
88 my %checks = ();
89 while (<STDIN>) {
90 if (/^[\r\n]+$/) {
91 $HEAD .= "Subject: (no subject)\r\n" unless $HEAD =~ /^Subject:/im;
92 if (keys %checks) {
93 foreach my $check (keys %checks) {
94 if ($checks{$check}->[0]) {
95 # Bad email
96 $HEAD =~ s/^(Subject:)/$1 [CU!$check!$checks{$check}->[1]]/im;
97 }
98 }
99 } else {
100 $HEAD =~ s/^(Subject:)/$1 [CU!no sender address found!]/im;
101 }
102 print $HEAD;
103 print "X-CU-Filter: $Mail::CheckUser::VERSION/$VERSION - Checked ".(scalar keys %checks)." addresses\r\n";
104 print "\r\n";
105 while (<STDIN>) {
106 print;
107 }
108 exit;
109 }
110 $HEAD .= $_;
111 if (/^\S*(return-path|from|sender)\S*[: ]+(.+)/i) {
112 my $email = $2;
113 $email = $1 if $email =~ /\<(\S*)\>/;
114 1 while $email =~ s/\([^()]\)//;
115 1 while $email =~ s/"[^\"]"//;
116 $email =~ s/(@\S+)\s.*/$1/;
117 $email =~ s/.*\s(\S+@)/$1/;
118 if ($email =~ /@/) {
119 $email =~ y/A-Z/a-z/;
120 $checks{$email} ||= do {
121 check_email($email);
122 my $l = last_check;
123 [$l->{code}, $l->{reason}];
124 };
125 }
126 } elsif (/^[\w\-]+:.*/ || /^[ \t]/) {
127 # Looks like a valid header
128 } else {
129 $HEAD =~ s/(.*)$/X-Invalid-Header: $1/;
130 }
131 }