| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PHP::Functions::Mail; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
26887
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use vars qw(@ISA @EXPORT_OK $VERSION); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
107
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
9
|
|
|
|
|
|
|
@EXPORT_OK = qw(mail mb_send_mail); |
|
10
|
|
|
|
|
|
|
$VERSION = '0.04'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Carp qw(carp croak); |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
88
|
|
|
13
|
1
|
|
|
1
|
|
989
|
use Net::SMTP; |
|
|
1
|
|
|
|
|
54587
|
|
|
|
1
|
|
|
|
|
994
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub mail { |
|
16
|
0
|
|
|
0
|
1
|
|
my $to = shift; |
|
17
|
0
|
|
|
|
|
|
my $subject = shift; |
|
18
|
0
|
|
|
|
|
|
my $body = shift; |
|
19
|
0
|
|
|
|
|
|
my $headers = shift; |
|
20
|
0
|
|
|
|
|
|
my $options = shift; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
eval { |
|
23
|
0
|
0
|
|
|
|
|
my $option = $options->{NetSmtpOption} ? $options->{NetSmtpOption} : undef; |
|
24
|
0
|
0
|
|
|
|
|
my $host = $options->{Host} ? $options->{Host} : 'localhost'; |
|
25
|
0
|
|
|
|
|
|
my $smtp = Net::SMTP->new($host); |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $send_header; |
|
28
|
0
|
|
|
|
|
|
my $in_subject = 0; |
|
29
|
0
|
|
|
|
|
|
my $in_from = 0; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#From head check |
|
32
|
0
|
|
|
|
|
|
foreach my $header (split("\n", $headers)) { |
|
33
|
0
|
0
|
|
|
|
|
unless ($header =~ /^([^:]+):(.+)$/) { |
|
34
|
0
|
|
|
|
|
|
next; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
0
|
|
|
|
|
|
my $name = $1; |
|
37
|
0
|
|
|
|
|
|
my $value = $2; |
|
38
|
0
|
|
|
|
|
|
my $ns_value = $value; |
|
39
|
0
|
|
|
|
|
|
$ns_value =~ s/\s/ /g; |
|
40
|
0
|
|
|
|
|
|
$ns_value =~ s|\=\?ISO-2022-JP\?B\?.*?\?\=||g; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if (uc($name) eq 'FROM') { |
|
43
|
0
|
|
|
|
|
|
$smtp->mail(split(",", $ns_value)); |
|
44
|
0
|
|
|
|
|
|
$in_from = 1; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
0
|
0
|
|
|
|
|
$in_subject = 1 if uc($name) eq 'SUBJECT'; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
0
|
|
|
|
|
unless ($in_from) { |
|
49
|
0
|
|
|
|
|
|
croak "no From header"; |
|
50
|
0
|
|
|
|
|
|
return 1; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$send_header .= "To: $to\n"; |
|
54
|
0
|
0
|
|
|
|
|
$send_header .= "Subject: $subject\n"unless $in_subject; |
|
55
|
0
|
|
|
|
|
|
$smtp->to($to); |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$headers =~ s/\n\t/\t/mg; |
|
58
|
0
|
|
|
|
|
|
foreach my $header (split("\n", $headers)) { |
|
59
|
0
|
0
|
|
|
|
|
unless ($header =~ /^([^:]+):(.+)$/) { |
|
60
|
0
|
|
|
|
|
|
carp "header format error: $header"; |
|
61
|
0
|
|
|
|
|
|
next; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
0
|
|
|
|
|
|
my $name = $1; |
|
64
|
0
|
|
|
|
|
|
my $value = $2; |
|
65
|
0
|
|
|
|
|
|
my $ns_value = $value; |
|
66
|
0
|
|
|
|
|
|
$ns_value =~ s/\s/ /g; |
|
67
|
0
|
|
|
|
|
|
$ns_value =~ s|\=\?ISO-2022-JP\?B\?.*?\?\=||ig; |
|
68
|
0
|
0
|
|
|
|
|
$smtp->to(split(",", $ns_value)) if uc($name) eq 'TO'; |
|
69
|
0
|
0
|
|
|
|
|
$smtp->cc(split(",", $ns_value)) if uc($name) eq 'CC'; |
|
70
|
0
|
0
|
|
|
|
|
$smtp->bcc(split(",", $ns_value)) if uc($name) eq 'BCC'; |
|
71
|
0
|
|
|
|
|
|
$value =~ s/\t/\n\t/g; |
|
72
|
0
|
|
|
|
|
|
$send_header .= "$name:$value\n"; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
|
|
|
|
|
$smtp->data; |
|
75
|
0
|
|
|
|
|
|
$body =~ s/\n\r/\n/g; |
|
76
|
0
|
|
|
|
|
|
$smtp->datasend("$send_header\n$body"); |
|
77
|
0
|
|
|
|
|
|
$smtp->dataend; |
|
78
|
0
|
|
|
|
|
|
$smtp->quit; |
|
79
|
|
|
|
|
|
|
}; |
|
80
|
0
|
0
|
|
|
|
|
croak "mail error: $@" if $@; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return 0; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub mb_send_mail { |
|
86
|
0
|
|
|
0
|
1
|
|
my $to = shift; |
|
87
|
0
|
|
|
|
|
|
my $subject = shift; |
|
88
|
0
|
|
|
|
|
|
my $body = shift; |
|
89
|
0
|
|
|
|
|
|
my $headers = shift; |
|
90
|
0
|
|
|
|
|
|
my $options = shift; |
|
91
|
1
|
|
|
1
|
|
1057
|
use Jcode; |
|
|
1
|
|
|
|
|
81707
|
|
|
|
1
|
|
|
|
|
381
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $send_header; |
|
94
|
0
|
|
|
|
|
|
$headers =~ s/\n\t/\t/mg; |
|
95
|
0
|
|
|
|
|
|
foreach my $header (split("\n", $headers)) { |
|
96
|
0
|
0
|
|
|
|
|
unless ($header =~ /^([^:]+):(.+)$/) { |
|
97
|
0
|
|
|
|
|
|
carp "header format error: $header"; |
|
98
|
0
|
|
|
|
|
|
next; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
0
|
|
|
|
|
|
my $name = $1; |
|
101
|
0
|
|
|
|
|
|
my $value = $2; |
|
102
|
0
|
|
|
|
|
|
my $len = 76 - (length($name) + 1); |
|
103
|
0
|
0
|
|
|
|
|
$len = 32 if $len < 32; |
|
104
|
0
|
|
|
|
|
|
$send_header .= "$name:" . mime_encode($value, $len) . "\n"; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
0
|
|
|
|
|
|
$send_header .= "Content-type: text/plain; charset=iso-2022-jp\n"; |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
mail(mime_encode($to, 72), |
|
109
|
|
|
|
|
|
|
mime_encode($subject, 66), |
|
110
|
|
|
|
|
|
|
Jcode->new($body)->iso_2022_jp, |
|
111
|
|
|
|
|
|
|
$send_header, |
|
112
|
|
|
|
|
|
|
$options); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub mime_encode { |
|
116
|
1
|
|
|
1
|
|
11
|
use Jcode; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
292
|
|
|
117
|
0
|
|
|
0
|
0
|
|
my $str = Jcode->new(shift)->euc; |
|
118
|
0
|
|
|
|
|
|
my $len = shift; |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$str =~ s/([\x80-\xff]+)/Jcode->new($1)->mime_encode("\n", $len)/eg; |
|
|
0
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$str =~ s/\n /\n\t/g; |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$str =~ s|(\=\?ISO-2022-JP\?B\?)|\n$1|ig; |
|
124
|
0
|
|
|
|
|
|
$str =~ s|(\?\=)|$1\n|ig; |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
$str =~ s/^\s+//m; |
|
127
|
0
|
|
|
|
|
|
$str =~ s/\s+$//m; |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$str =~ s/\n\n/\n/gm; |
|
130
|
0
|
|
|
|
|
|
$str =~ s/\n\t\n/\n/gm; |
|
131
|
0
|
|
|
|
|
|
$str =~ s/\n/\n\t/gm; |
|
132
|
0
|
|
|
|
|
|
$str =~ s/\n\t$//m; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return $str; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
|
138
|
|
|
|
|
|
|
__END__ |