Line # Revision Author
1 37 ahitrov@rambler.ru <%args>
2
3 $email => undef
4 66 ahitrov@rambler.ru $etype => 'mixed'
5 402 ahitrov $smtp => undef
6 37 ahitrov@rambler.ru
7 </%args>
8 <%init>
9
10 return unless ref $email;
11
12 use MIME::Lite;
13 use MIME::Base64;
14
15 my $subject = $email->{subject};
16 $subject = MIME::Base64::encode($subject);
17 74 ahitrov@rambler.ru $subject =~ s/\s//sgi;
18 37 ahitrov@rambler.ru $subject = '=?koi8-r?B?'.$subject.'?=';
19
20 my $emailfrom;
21 my ($from, $efrom) = $email->{from} =~ /^(.*?)<(.*?)>/ ? ($1, $2) : $email->{from} =~ /<(.*?)>/ ? ('',$1) : ('',$email->{from});
22 if ( $from ) {
23 $from = MIME::Base64::encode($from);
24 $from =~ s/\s+$//si;
25 $from = '=?koi8-r?B?'.$from.'?=';
26 $emailfrom = $from.' <'.$efrom.'>';
27 } else {
28 $emailfrom = $efrom;
29 }
30
31 my $emailto;
32 my ($to, $eto) = $email->{to} =~ /^(.*?)<(.*?)>/ ? ($1, $2) : $email->{to} =~ /<(.*?)>/ ? ('',$1) : ('',$email->{to});
33 if ( $to ) {
34 $to = MIME::Base64::encode($to);
35 $to =~ s/\s+$//si;
36 $to = '=?koi8-r?B?'.$to.'?=';
37 $emailto = $to.' <'.$eto.'>';
38 } else {
39 $emailto = $eto;
40 }
41 my $ccmail;
42 if ( exists $email->{cc} && ref $email->{cc} eq 'ARRAY' ) {
43 foreach my $cc ( @{ $email->{cc} } ) {
44 my ($cce, $ecce) = $cc =~ /^(.*?)<(.*?)>/ ? ($1, $2) : $cc =~ /<(.*?)>/ ? ('',$1) : ('',$cc);
45 $cc = $ecce;
46 }
47 $ccmail = join ', ', @{$email->{cc}};
48 } elsif ( exists $email->{cc} && $email->{cc} ) {
49 my ($cce, $ecce) = $email->{cc} =~ /^(.*?)<(.*?)>/ ? ($1, $2) : $email->{cc} =~ /<(.*?)>/ ? ('',$1) : ('',$email->{cc});
50 $ccmail = $ecce;
51 }
52
53
54 my $body = $email->{body};
55 warn Dumper($email);
56 my $dt = Contenido::DateTime->new;
57 $dt->set_locale('en_EN');
58 my $pdate = $dt->strftime("%a, %d %b %Y %H:%M:%S %z");
59 my $msg = MIME::Lite->new(
60 To => $emailto,
61 From => $emailfrom,
62 $ccmail ? ( Cc => $ccmail ) : (),
63 Subject => $subject,
64 66 ahitrov@rambler.ru # Encoding=> 'binary',
65 37 ahitrov@rambler.ru Date => $pdate,
66 66 ahitrov@rambler.ru Type => ($etype eq 'mixed' ? 'multipart/mixed' : $etype eq 'related' ? 'multipart/related;type="multipart/alternative";charset="koi8-r"' : $etype),
67 37 ahitrov@rambler.ru );
68 $msg->attach(
69 'Type' => 'text/html;charset="koi8-r"',
70 'Data' => $body,
71 'Disposition' => '',
72 );
73
74 402 ahitrov if ( $smtp ) {
75 $msg->send('smtp', $smtp, Debug => 0)
76 } else {
77 $msg->send();
78 }
79 37 ahitrov@rambler.ru
80 </%init>