1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
| -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
-
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
-
|
!
-
|
!
!
-
|
!
-
|
|
|
|
-
|
|
!
-
!
|
|
-
!
-
!
|
-
!
|
|
-
!
-
|
|
-
|
!
!
-
|
!
-
|
-
-
|
!
|
!
!
-
-
-
|
|
|
|
!
!
!
-
|
|
!
|
use strict;
use Mail::SPF::Query;
my $opt_file = undef;
my $opt_ip = undef;
my $opt_sender = undef;
my $opt_helo = undef;
my $opt_rcpt_to = undef;
my $opt_local = undef;
my $opt_trusted = undef;
my $opt_guess = undef;
my $opt_exp = undef;
my $opt_max_lookup = undef;
my $opt_sanitize = undef;
my $opt_name = "spfquery";
my $opt_debug = 0;
my $opt_keep_comments = 0;
my $opt_fallback = undef;
my $opt_override = undef;
my $opt_dns = undef;
my $opt_help = undef;
my $opt_pcode = 0;
my $opt_fcode = 3;
my @opt_bypass = ();
push(@opt_bypass, "^127\\.0\\.0\\.1\$");
my $mid;
my $opt_tmp = undef;
my $i;
for ($i = 0; $i <= $#ARGV; $i++) {
if ($ARGV[$i] eq "--file") {
if (++$i <= $#ARGV) {
$opt_file = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--tmp") {
if (++$i <= $#ARGV) {
$opt_tmp = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--ip") {
if (++$i <= $#ARGV) {
$opt_ip = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--sender") {
if (++$i <= $#ARGV) {
$opt_sender = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--helo") {
if (++$i <= $#ARGV) {
$opt_helo = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--rcpt-to") {
if (++$i <= $#ARGV) {
$opt_rcpt_to = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--debug") {
if (++$i <= $#ARGV) {
$opt_debug = int($ARGV[$i]);
}
} elsif ($ARGV[$i] eq "--local") {
if (++$i <= $#ARGV) {
$opt_local = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--trusted") {
if (++$i <= $#ARGV) {
$opt_trusted = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--guess") {
if (++$i <= $#ARGV) {
$opt_guess = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--expl") {
if (++$i <= $#ARGV) {
$opt_exp = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--max-lookup") {
if (++$i <= $#ARGV) {
$opt_max_lookup = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--sanitize") {
if (++$i <= $#ARGV) {
$opt_sanitize = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--name") {
if (++$i <= $#ARGV) {
$opt_name = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--fallback") {
if (++$i <= $#ARGV) {
$opt_fallback = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--override") {
if (++$i <= $#ARGV) {
$opt_override = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--dns") {
if (++$i <= $#ARGV) {
$opt_dns = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--pcode") {
if (++$i <= $#ARGV) {
$opt_pcode = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--fcode") {
if (++$i <= $#ARGV) {
$opt_fcode = $ARGV[$i];
}
} elsif ($ARGV[$i] eq "--bypass") {
if (++$i <= $#ARGV) {
push(@opt_bypass, $ARGV[$i]);
}
} elsif ($ARGV[$i] eq "--help") {
$opt_help = 1;
}
}
if ($opt_help) {
exit($opt_pcode);
}
if (defined($opt_file)) {
my $ln;
my @hvars;
if (!open(MFIL, "$opt_file")) {
print STDERR "unable to open ${opt_file}\n";
exit($opt_pcode);
}
$ln = <MFIL>;
chomp($ln);
@hvars = split(/;/, $ln);
$ln = <MFIL>;
$mid = <MFIL>;
chomp($mid);
$ln = <MFIL>;
chomp($ln);
close(MFIL);
($opt_sender = $ln) =~ s/[^<]+<([^>]*)>.*/$1/;
if ($#hvars > 3) {
$opt_helo = $hvars[0];
($opt_ip = $hvars[1]) =~ s/\[([^:]+)\]:[0-9]+/$1/;
} else {
($opt_ip = $hvars[0]) =~ s/\[([^:]+)\]:[0-9]+/$1/;
}
}
if (!defined($opt_helo) && ($opt_sender =~ /\@/)) {
($opt_helo = $opt_sender) =~ s/.*\@(.*)/$1/;
}
my $reg;
for ($i = 0; $i <= $#opt_bypass; $i++) {
$reg = $opt_bypass[$i];
if ($opt_ip =~ /$reg/) {
if ($opt_debug) {
print "whitelist ip ${opt_ip}\n";
}
exit($opt_pcode);
}
}
my $query = new Mail::SPF::Query(ipv4 => $opt_ip,
sender => $opt_sender,
helo => $opt_helo,
local => $opt_local,
trusted => $opt_trusted,
guess => $opt_guess,
default_explanation => $opt_exp,
max_lookup => $opt_max_lookup,
sanitize => $opt_sanitize,
myhostname => $opt_name,
fallback => $opt_fallback,
override => $opt_override,
debug => $opt_debug,
);
my ($result, $smtp_comment, $header_comment, $spf_record, $detail) = $query->result();
my $rcode = ($result eq "fail") ? $opt_fcode: $opt_pcode;
if (defined($opt_file)) {
if ($rcode eq 0) {
if (defined($opt_tmp) && $mid){
open(FILE,">${opt_tmp}/${mid}.SPF");
flock(FILE,2);
print FILE "Received-SPF: ".$result." ( $header_comment )";
close(FILE);
}
}
}
if ($opt_debug) {
print $query->result . "\n";
print $rcode;
}
exit($rcode);
|
Comments list
Posts tree
お世話になります。
XmailにてSPF参照を導入したく貴殿のHPにたどり着いたのですが
どうしてもCPANよりMail::SPF::Queryがエラーとなり困っています。
ほかのサイトを参照したところperlのバージョンによっては
今はMail::SPF::Queryが存在しないと書かれていたのですが
その際は貴殿作成のスクリプトは使用できませんでしょうか?
もし必要な情報があれば全て出しますのでご連絡頂けば
幸いです。
たかちん さん、こんにちは。
Mail::SPF::Query がないとやはり動作は難しいと思います。
cpan で入らなければ yum 使うとできたみたいなことも見かけました。
うまく行くといいですね。
nao-pon さん
ご返信ありがとうございます。
大変恐縮ですがwindowsでyumは可能なのでしょうか?
Mail::SPF:Query 必須とのことでもう少し調べてみます。
ご回答ありがとうございました。