[Jifty-commit] r3683 - in jifty/trunk: lib/Jifty t/TestApp/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Jul 13 01:12:46 EDT 2007
Author: ternus
Date: Fri Jul 13 01:12:32 2007
New Revision: 3683
Modified:
jifty/trunk/ (props changed)
jifty/trunk/Makefile.PL
jifty/trunk/lib/Jifty/Notification.pm
jifty/trunk/t/TestApp/t/08-notifications.t
Log:
HTML branch merge
Modified: jifty/trunk/Makefile.PL
==============================================================================
--- jifty/trunk/Makefile.PL (original)
+++ jifty/trunk/Makefile.PL Fri Jul 13 01:12:32 2007
@@ -25,6 +25,7 @@
requires('Email::MIME');
requires('Email::MIME::Creator');
requires('Email::MIME::ContentType');
+requires('Email::MIME::CreateHTML');
requires('Email::Send' => '1.99_01'); # Email::Send::Jifty::Test
requires('Email::Simple');
requires('Email::Simple::Creator');
Modified: jifty/trunk/lib/Jifty/Notification.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Notification.pm (original)
+++ jifty/trunk/lib/Jifty/Notification.pm Fri Jul 13 01:12:32 2007
@@ -6,9 +6,10 @@
use base qw/Jifty::Object Class::Accessor::Fast/;
use Email::Send ();
use Email::MIME::Creator;
+use Email::MIME::CreateHTML;
__PACKAGE__->mk_accessors(
- qw/body preface footer subject from _recipients _to_list to/);
+ qw/body html_body preface footer subject from _recipients _to_list to/);
=head1 NAME
@@ -17,9 +18,9 @@
=head1 USAGE
It is recommended that you subclass L<Jifty::Notification> and
-override C<body>, C<subject>, C<recipients>, and C<from> for each
-message. (You may want a base class to provide C<from>, C<preface>
-and C<footer> for example.) This lets you keep all of your
+override C<body>, C<html-body>, C<subject>, C<recipients>, and C<from>
+for each message. (You may want a base class to provide C<from>,
+C<preface> and C<footer> for example.) This lets you keep all of your
notifications in the same place.
However, if you really want to make a notification type in code
@@ -78,8 +79,13 @@
if mail was actually sent. Note errors are not the only cause of mail
not being sent -- for example, the recipients list could be empty.
-Be aware that if you haven't set C<recipients>, this will fail silently
-and return without doing anything useful.
+If you wish to send HTML mail, set C<html_body>. If this is not set
+(for backwards compatibility) a plain-text email is sent. If
+C<html_body> and C<body> are both set, a multipart mail is sent. See
+L<Email::MIME::CreateHTML> for how this is done.
+
+Be aware that if you haven't set C<recipients>, this will fail
+silently and return without doing anything useful.
=cut
@@ -90,18 +96,31 @@
map { ( $_->can('email') ? $_->email : $_ ) } grep {$_} @recipients );
$self->log->debug("Sending a ".ref($self)." to $to");
return unless ($to);
-
+ my $message = "";
my $appname = Jifty->config->framework('ApplicationName');
-
- my $message = Email::MIME->create(
- header => [
- From => ($self->from || _('%1 <%2>' , $appname, Jifty->config->framework('AdminEmail'))) ,
- To => $to,
- Subject => Encode::encode('MIME-Header', $self->subject || _("A notification from %1!",$appname )),
- ],
- attributes => { charset => 'UTF-8' },
- parts => $self->parts
- );
+ if ($self->html_body) {
+ $message = Email::MIME->create_html(
+ header => [
+ From => ($self->from || _('%1 <%2>' , $appname, Jifty->config->framework('AdminEmail'))) ,
+ To => $to,
+ Subject => Encode::encode('MIME-Header', $self->subject || _("A notification from %1!",$appname )),
+ ],
+ attributes => { charset => 'UTF-8' },
+ text_body => $self->full_body,
+ body => $self->full_html
+ );
+ } else {
+ $message = Email::MIME->create(
+ header => [
+ From => ($self->from || _('%1 <%2>' , $appname, Jifty->config->framework('AdminEmail'))) ,
+ To => $to,
+ Subject => Encode::encode('MIME-Header', $self->subject || _("A notification from %1!",$appname )),
+ ],
+ attributes => { charset => 'UTF-8' },
+
+ body => $self->full_body
+ );
+ }
$message->encoding_set('8bit')
if (scalar $message->parts == 1);
$self->set_headers($message);
@@ -263,6 +282,17 @@
return join( "\n", grep { defined } $self->preface, $self->body, $self->footer );
}
+=head2 full_html
+
+Same as full_body, but with HTML.
+
+=cut
+
+sub full_html {
+ my $self = shift;
+ return join( "\n", grep { defined } $self->preface, $self->html_body, $self->footer );
+}
+
=head2 parts
The parts of the message. You want to override this if you want to
Modified: jifty/trunk/t/TestApp/t/08-notifications.t
==============================================================================
--- jifty/trunk/t/TestApp/t/08-notifications.t (original)
+++ jifty/trunk/t/TestApp/t/08-notifications.t Fri Jul 13 01:12:32 2007
@@ -5,9 +5,29 @@
use lib 't/lib';
use Jifty::SubTest;
-use Jifty::Test tests => 2;
+use Jifty::Test tests => 4;
+
use_ok('Jifty::Notification');
+use_ok('Email::MIME::CreateHTML');
+use_ok('Email::MIME');
+use_ok('Email::Send');
+
+my $html = "<html><body>This is the HTML portion of the test email</body></html>";
+
+my $text = "This is the text portion of the text email";
+
+my $test_email = Email::MIME->create_html(
+ header => [
+ From => 'test at test',
+ To => 'test2 at test2',
+ Subject => 'This is a test email',
+ ],
+ body => $html,
+ text_body => $text
+ );
+
+
-TODO: {local $TODO = "Actually write tests"; ok(0, "Test notifications")};
+# TODO: {local $TODO = "Actually write tests"; ok(0, "Test notifications")};
1;
More information about the Jifty-commit
mailing list