| 1 | package Jifty::Plugin::JapaneseNotification::Notification::ISO2022JP; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | Jifty::Plugin::JapaneseNotification::Notification::ISO2022JP - Send emails from Jifty with Japanese character code | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | Add the following to your site_config.yml | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | framework: | ||||||||||||||||||||||||||||||||||||||||||
| 14 | Plugins: | ||||||||||||||||||||||||||||||||||||||||||
| 15 | - JapaneseNotification: {} | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | in your application | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | use utf8; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | my $notification = | ||||||||||||||||||||||||||||||||||||||||||
| 22 | Jifty->app_class('Notification', 'ISO2022JP')->new( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | from => 'Pikari <pi@null.in>', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | to => 'Keronyo <ke@null.in>', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | subject => 'Hello!', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | body => 'FumoFumo--', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | $notification->send; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use base qw/Jifty::Notification/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | =head2 send_one_message | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub send_one_message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_one_message: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my @recipients = $self->recipients; | |||||||||||||||||||||||||||||||||||||||||
| 48 | my $to = join( ', ', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | map { ( ref $_ && $_->can('email') ? $_->email : $_ ) } grep {$_} @recipients ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_ and $_->can("email")
MC/DC0%0/2
ref $_ and $_->can("email")
ref $_
$_->can("email")
Truth table0%0/3
A and B
A= ref $_B= $_->can("email")
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $self->log->debug("Sending a ".ref($self)." to $to"); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return unless ($to); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $message = ""; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $appname = Jifty->config->framework('ApplicationName'); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | #my %attrs = ( charset => 'UTF-8' ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my %attrs = ( charset => 'ISO-2022-JP' ); | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($self->html_body) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $message = Email::MIME->create_html( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->from || _('%1 <%2>', $appname, 'Jifty'->config->framework('AdminEmail'))
$self->subject || _('A notification from %1!', $appname)
MC/DC0%0/2
$self->from || _('%1 <%2>', $appname, 'Jifty'->config->framework('AdminEmail'))
$self->from
_('%1 <%2>', $appname, 'Jifty'->config->framework('AdminEmail'))
MC/DC0%0/2
$self->subject || _('A notification from %1!', $appname)
$self->subject
_('A notification from %1!', $appname)
Truth table0%0/3
A || B
A= $self->fromB= _('%1 <%2>', $appname, 'Jifty'->config->framework('AdminEmail'))
Truth table0%0/3
A || B
A= $self->subjectB= _('A notification from %1!', $appname)
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | header => [ | ||||||||||||||||||||||||||||||||||||||||||
| 61 | From => ($self->from || _('%1 <%2>' , $appname, Jifty->config->framework('AdminEmail'))) , | ||||||||||||||||||||||||||||||||||||||||||
| 62 | To => $to, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | Subject => Encode::encode('MIME-Header', $self->subject || _("A notification from %1!",$appname )), | ||||||||||||||||||||||||||||||||||||||||||
| 64 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 65 | attributes => \%attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | text_body_attributes => \%attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | body_attributes => \%attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | text_body => Encode::encode_utf8($self->full_body), | ||||||||||||||||||||||||||||||||||||||||||
| 69 | body => Encode::encode_utf8($self->full_html), | ||||||||||||||||||||||||||||||||||||||||||
| 70 | embed => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | inline_css => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # Since the containing messsage will still be us-ascii otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $message->charset_set( $attrs{'charset'} ); | |||||||||||||||||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $message = Email::MIME->create( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->from || _('%1 <%2>', $appname, 'Jifty'->config->framework('AdminEmail'))
$self->subject || _('A notification from %1!', $appname)
MC/DC0%0/2
$self->from || _('%1 <%2>', $appname, 'Jifty'->config->framework('AdminEmail'))
$self->from
_('%1 <%2>', $appname, 'Jifty'->config->framework('AdminEmail'))
MC/DC0%0/2
$self->subject || _('A notification from %1!', $appname)
$self->subject
_('A notification from %1!', $appname)
Truth table0%0/3
A || B
A= $self->fromB= _('%1 <%2>', $appname, 'Jifty'->config->framework('AdminEmail'))
Truth table0%0/3
A || B
A= $self->subjectB= _('A notification from %1!', $appname)
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | header => [ | ||||||||||||||||||||||||||||||||||||||||||
| 78 | From => Encode::encode('MIME-Header-ISO_2022_JP', $self->from || _('%1 <%2>' , $appname, Jifty->config->framework('AdminEmail'))) , | ||||||||||||||||||||||||||||||||||||||||||
| 79 | To => Encode::encode('MIME-Header-ISO_2022_JP', $to), | ||||||||||||||||||||||||||||||||||||||||||
| 80 | Subject => Encode::encode('MIME-Header-ISO_2022_JP', $self->subject || _("A notification from %1!",$appname )), | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 82 | attributes => \%attrs, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | parts => $self->parts | ||||||||||||||||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $message->encoding_set('7bit') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | if (scalar $message->parts == 1); | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $self->set_headers($message); | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $method = Jifty->config->framework('Mailer'); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $args_ref = Jifty->config->framework('MailerArgs'); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $args_ref = [] unless defined $args_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $sender | |||||||||||||||||||||||||||||||||||||||||
| 96 | = Email::Send->new( { mailer => $method, mailer_args => $args_ref } ); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $ret = $sender->send($message); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | unless ($ret) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->log->error("Error sending mail: $ret"); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $ret; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =head2 parts | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub parts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parts: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 113 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | Email::MIME->create( | |||||||||||||||||||||||||||||||||||||||||
| 115 | attributes => { charset => 'ISO-2022-JP' }, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | body => Encode::encode('ISO-2022-JP', $self->full_body), | ||||||||||||||||||||||||||||||||||||||||||
| 117 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 118 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =head2 send | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub send { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $currentuser_object_class = Jifty->app_class("CurrentUser"); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | for my $to ( grep {defined} ($self->to, $self->to_list) ) { | |||||||||||||||||||||||||||||||||||||||||
| 129 | # Can't call method "can" without a package or object reference at /opt/local/lib/perl5/site_perl/5.8.8/Jifty/Notification.pm line 248. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | #if ($to->can('id')) { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if (ref $to and $to->can('id')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $to and $to->can("id")
MC/DC0%0/2
ref $to and $to->can("id")
ref $to
$to->can("id")
Truth table0%0/3
A and B
A= ref $toB= $to->can("id")
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | next if $currentuser_object_class->can("nobody") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$currentuser_object_class->can("nobody") and $currentuser_object_class->nobody->id and $to->id == $currentuser_object_class->nobody->id
$currentuser_object_class->can("nobody") and $currentuser_object_class->nobody->id
MC/DC0%0/3
$currentuser_object_class->can("nobody") and $currentuser_object_class->nobody->id and $to->id == $currentuser_object_class->nobody->id
$currentuser_object_class->can("nobody")
$currentuser_object_class->nobody->id
$to->id == $currentuser_object_class->nobody->id
Truth table0%0/4
A and B and C
A= $currentuser_object_class->can("nobody")B= $currentuser_object_class->nobody->idC= $to->id == $currentuser_object_class->nobody->id
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | and $currentuser_object_class->nobody->id | ||||||||||||||||||||||||||||||||||||||||||
| 134 | and $to->id == $currentuser_object_class->nobody->id; | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | next if $to->id == $currentuser_object_class->superuser->id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->to($to); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $self->recipients($to); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->send_one_message(@_); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | Tomohiro Hosaka, C<< <bokutin at bokut.in> >> | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | Copyright 2008 Tomohiro Hosaka, all rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||
| 153 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||