| 1 | package MIME::Lite::TT::HTML::Japanese; | ||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 2 | ▶ | use MIME::Lite; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use Template; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Jcode; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use DateTime::Format::Mail; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.06'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | MIME::Lite::TT::HTML::Japanese - Create html mail with MIME::Lite and TT | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | use MIME::Lite::TT::HTML::Japanese; | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | my $msg = MIME::Lite::TT::HTML::Japanese->new( | ||||||||||||||||||||
| 21 | From => 'from@example.com', | ||||||||||||||||||||
| 22 | To => 'to@example.com', | ||||||||||||||||||||
| 23 | Subject => 'Subject', | ||||||||||||||||||||
| 24 | Template => { | ||||||||||||||||||||
| 25 | html => 'mail.html', | ||||||||||||||||||||
| 26 | text => 'mail.txt', | ||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||
| 28 | Icode => 'euc', # input code (Jcode Format) | ||||||||||||||||||||
| 29 | TmplIcode => 'jis', # Template input code (Optional) | ||||||||||||||||||||
| 30 | TmplOptions => \%options, | ||||||||||||||||||||
| 31 | TmplParams => \%params, | ||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | $msg->send; | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | This module provide easy interface to make MIME::Lite object with html formatted mail. | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 METHODS | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head2 new | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | return MIME::Lite object with Japanese html mail format. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||
| 49 | 0 | my $class = shift; | |||||||||||||||||||
| 50 | 0 | ▶ | my $options = @_ > 1 ? {@_} : $_[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | my $template = delete $options->{Template}; | |||||||||||||||||||
| 53 | 0 | ▶ | return croak "html template not defined" unless $template->{html}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | $template->{text} = generate_text( $template->{html} ) | ||||||||||||||||||||
| 56 | 0 | ▶ | unless $template->{text}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | my $icode = delete $options->{Icode}; | |||||||||||||||||||
| 59 | 0 | my $tmpl_icode = delete $options->{TmplIcode}; | |||||||||||||||||||
| 60 | 0 | my $tmpl_params = delete $options->{TmplParams}; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | my $tt = Template->new( delete $options->{TmplOptions} ); | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | my $subject = encode_subject( delete $options->{Subject}, $icode ); | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | my $msg = MIME::Lite->new( | |||||||||||||||||||
| 67 | %$options, | ||||||||||||||||||||
| 68 | Subject => $subject, | ||||||||||||||||||||
| 69 | Type => 'multipart/alternative', | ||||||||||||||||||||
| 70 | Date => DateTime::Format::Mail->format_datetime( | ||||||||||||||||||||
| 71 | DateTime->now->set_time_zone('Asia/Tokyo') | ||||||||||||||||||||
| 72 | ), | ||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | my ( $text, $html ); | |||||||||||||||||||
| 76 | 0 | ▶ | $tt->process( $template->{text}, $tmpl_params, \$text ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | or croak $tt->error; | ||||||||||||||||||||
| 78 | 0 | ▶ | $tt->process( $template->{html}, $tmpl_params, \$html ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | or croak $tt->error; | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | ▶ | $msg->attach( | ||||||||||||||||||
|
Condition0%0/3
$tmpl_icode || $icode
MC/DC0%0/2
$tmpl_icode || $icode
$tmpl_icode
$icode
Truth table0%0/3
A || B
A= $tmpl_icodeB= $icode
| |||||||||||||||||||||
| 82 | Type => 'text/plain; charset=iso-2022-jp', | ||||||||||||||||||||
| 83 | Data => encode_body( $text, $tmpl_icode || $icode ), | ||||||||||||||||||||
| 84 | Encoding => '7bit', | ||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | ▶ | $msg->attach( | ||||||||||||||||||
|
Condition0%0/3
$tmpl_icode || $icode
MC/DC0%0/2
$tmpl_icode || $icode
$tmpl_icode
$icode
Truth table0%0/3
A || B
A= $tmpl_icodeB= $icode
| |||||||||||||||||||||
| 88 | Type => 'text/html; charset=iso-2022-jp', | ||||||||||||||||||||
| 89 | Data => encode_body( $html, $tmpl_icode || $icode ), | ||||||||||||||||||||
| 90 | Encoding => '7bit', | ||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | $msg; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head2 encode_subject | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | ▶ | sub encode_subject { | ||||||||||||||||||
|
Subroutine
encode_subject: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 101 | 0 | my ( $subject, $icode ) = @_; | |||||||||||||||||||
| 102 | 0 | $subject = remove_utf8_flag($subject); | |||||||||||||||||||
| 103 | 0 | Jcode->new( $subject, $icode )->mime_encode; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | =head2 encode_body | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | sub encode_body { | ||||||||||||||||||
|
Subroutine
encode_body: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 111 | 0 | my ( $body, $icode ) = @_; | |||||||||||||||||||
| 112 | 0 | my $str = remove_utf8_flag($body); | |||||||||||||||||||
| 113 | 0 | Jcode->new( $str, $icode )->jis; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head2 generate_text | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | ▶ | sub generate_text { | ||||||||||||||||||
|
Subroutine
generate_text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 121 | 0 | my $str = shift; | |||||||||||||||||||
| 122 | 0 | $str =~ s/<.*?>//gs; | |||||||||||||||||||
| 123 | 0 | $str; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head2 remove_utf8_flag | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 0 | ▶ | sub remove_utf8_flag { | ||||||||||||||||||
|
Subroutine
remove_utf8_flag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 131 | 0 | pack 'C0A*', shift; | |||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head1 SEE ALSO | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | L<MIME::Lite>, L<Template>, L<MIME::Lite::TT::Japanese> | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head1 AUTHOR | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | Daisuke Murase E<lt>typester@cpan.orgE<gt> | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head1 LICENSE | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | This library is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||
| 145 | the same terms as Perl itself. | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 2 | 1; | |||||||||||||||||||