| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Egg::View::Mail::Mailer::CMD; |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# $Id: CMD.pm 285 2008-02-28 04:20:55Z lushe $ |
|
6
|
|
|
|
|
|
|
# |
|
7
|
2
|
|
|
2
|
|
704
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
103
|
|
|
8
|
2
|
|
|
2
|
|
15
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
91
|
|
|
9
|
2
|
|
|
2
|
|
14
|
use Carp qw/ croak /; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
369
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _setup { |
|
14
|
0
|
|
|
0
|
|
|
my($class, $e)= @_; |
|
15
|
0
|
|
|
|
|
|
my $c= $class->config; |
|
16
|
0
|
|
0
|
|
|
|
$c->{cmd_path} ||= do { |
|
17
|
0
|
0
|
|
|
|
|
-e '/usr/sbin/sendmail' ? '/usr/sbin/sendmail' |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
: -e '/usr/local/sbin/sendmail' ? '/usr/local/sbin/sendmail' |
|
19
|
|
|
|
|
|
|
: -e '/usr/bin/sendmail' ? '/usr/bin/sendmail' |
|
20
|
|
|
|
|
|
|
: die q{'sendmail' command is not found.}; |
|
21
|
|
|
|
|
|
|
}; |
|
22
|
0
|
|
0
|
|
|
|
$c->{cmd_option} ||= '-t -i'; |
|
23
|
0
|
0
|
|
|
|
|
unless ($class->can('valid_to_address')) { |
|
24
|
2
|
|
|
2
|
|
14
|
no strict 'refs'; ## no critic. |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
64
|
|
|
25
|
2
|
|
|
2
|
|
52
|
no warnings 'redefine'; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
4512
|
|
|
26
|
0
|
|
0
|
|
|
|
my $regexp= $c->{email_regexp} || qr{^[\w\d\-_]+@[\w\d\.\-_]+$}; |
|
27
|
0
|
|
|
|
|
|
*{"${class}::valid_to_address"}= |
|
28
|
0
|
0
|
|
0
|
|
|
sub { $_[1]=~m{$regexp} || croak qq"'$_[1]' is bad address." }; |
|
|
0
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
|
30
|
0
|
|
|
|
|
|
$class->next::method($e); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
sub mail_send { |
|
33
|
0
|
|
|
0
|
1
|
|
my $self= shift; |
|
34
|
0
|
0
|
|
|
|
|
my $data= $_[0] ? ($_[1] ? {@_}: $_[0]) : croak q{I want mail data.}; |
|
|
|
0
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $c= $self->config; |
|
36
|
0
|
0
|
|
|
|
|
$self->valid_to_address($data->{to}) || return 0; |
|
37
|
0
|
|
|
|
|
|
my $cmd_line= "$c->{cmd_path} $c->{cmd_option} $data->{to}"; |
|
38
|
0
|
0
|
|
|
|
|
if ($data->{debug}) { |
|
39
|
0
|
|
|
|
|
|
$self->e->debug_out("# + mailsend : $cmd_line\n${$data->{body}}"); |
|
|
0
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} else { |
|
41
|
0
|
|
|
|
|
|
open MSEND, "| $cmd_line"; ## no critic |
|
42
|
0
|
|
|
|
|
|
print MSEND ${$data->{body}}; |
|
|
0
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
close MSEND; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
0
|
|
|
|
|
|
1; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Egg::View::Mail::Mailer::CMD - Mail is transmitted by using the sendmail command. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package MyApp::View::Mail::MyComp; |
|
59
|
|
|
|
|
|
|
use base qw/ Egg::View::Mail::Base /; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
........... |
|
62
|
|
|
|
|
|
|
..... |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__PACKAGE__->setup_mailer('CMD'); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
It is Mailer system component to transmit mail by using the sendmail command. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Use is enabled specifying 'CMD' for the first argument of 'setup_mailer' method. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head3 cmd_path |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
PATH of sendmail command. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
It is set if the whereabouts of '/usr/sbin/sendmail', '/usr/local/sbin/sendmail', |
|
79
|
|
|
|
|
|
|
'/usr/bin/sendmail' is confirmed and it is found at the unspecification. |
|
80
|
|
|
|
|
|
|
The exception is generated when not found anywhere. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head3 cmd_option |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Start option to pass to command line. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Default is '-t -i'. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head3 email_regexp |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Regular expression for easy format check in mail address. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This stays in an easy check so that there is no obstacle to pass the mail address |
|
93
|
|
|
|
|
|
|
to the command line. Please check the check on the format of a detailed mail |
|
94
|
|
|
|
|
|
|
address beforehand by the module such as L<Email::Valid>. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Default is '^[\w\d\-_]+@[\w\d\.\-_]+$'. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Moreover, it is possible to check it there making 'Valid_to_address' method for |
|
99
|
|
|
|
|
|
|
the MAIL controller. Please look at the source code in detail. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head3 debug |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
It operates by debug mode. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
When an effective value is given, the content of mail comes to be sent to 'debug_out' |
|
106
|
|
|
|
|
|
|
of the project without doing actual Mail Sending. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
It tried to send the content of what mail by outputting 'debug_out' can be checked. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 METHODS |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 mail_send ([MAIL_DATA_HASH]) |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This method is what 'send' method of L<Egg::View::Mail::Base> calls it internally. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The obstacle is generated by operating the component built in when calling |
|
117
|
|
|
|
|
|
|
directly. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L<Egg::Release>, |
|
122
|
|
|
|
|
|
|
L<Egg::View::Mail>, |
|
123
|
|
|
|
|
|
|
L<Egg::View::Mail::Base>, |
|
124
|
|
|
|
|
|
|
L<Egg::View::Mail::Mailer::SMTP>, |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>, All Rights Reserved. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
135
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
|
136
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
|
139
|
|
|
|
|
|
|
|