[Rt-commit] r4781 - in Email-MIME-Alternative: . lib/Email/MIME
jesse at bestpractical.com
jesse at bestpractical.com
Mon Mar 20 13:33:42 EST 2006
Author: jesse
Date: Mon Mar 20 13:33:41 2006
New Revision: 4781
Added:
Email-MIME-Alternative/MANIFEST
Email-MIME-Alternative/Makefile.PL
Email-MIME-Alternative/t/
Email-MIME-Alternative/t/parts.t
Removed:
Email-MIME-Alternative/email.html
Email-MIME-Alternative/email.txt
Email-MIME-Alternative/pony.png
Email-MIME-Alternative/test.pl
Modified:
Email-MIME-Alternative/ (props changed)
Email-MIME-Alternative/lib/Email/MIME/Alternative.pm
Log:
r25678 at truegrounds (orig r4): (no author) | 2006-03-07 00:56:14 -0500
r8413 at zoq-fot-pik: chmrr | 2006-03-06 19:45:14 -0800
* Tests, bundling
Added: Email-MIME-Alternative/MANIFEST
==============================================================================
--- (empty file)
+++ Email-MIME-Alternative/MANIFEST Mon Mar 20 13:33:41 2006
@@ -0,0 +1,4 @@
+lib/Email/MIME/Alternative.pm
+Makefile.PL
+MANIFEST This list of files
+t/parts.t
Added: Email-MIME-Alternative/Makefile.PL
==============================================================================
--- (empty file)
+++ Email-MIME-Alternative/Makefile.PL Mon Mar 20 13:33:41 2006
@@ -0,0 +1,13 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile (
+ AUTHOR => 'Alex Vandiver <alexmv at mit.edu>',
+ ABSTRACT => "Email::MIME constructor for creating multipart/alternative attachments",
+ NAME => 'Email::MIME::Alternative',
+ PREREQ_PM => {
+ 'Email::MIME' => '1.82',
+ 'Email::MIME::Creator' => '1.41',
+ 'Email::MIME::ContentType' => '1.01',
+ },
+ VERSION_FROM => 'lib/Email/MIME/Alternative.pm',
+ );
Modified: Email-MIME-Alternative/lib/Email/MIME/Alternative.pm
==============================================================================
--- Email-MIME-Alternative/lib/Email/MIME/Alternative.pm (original)
+++ Email-MIME-Alternative/lib/Email/MIME/Alternative.pm Mon Mar 20 13:33:41 2006
@@ -96,19 +96,19 @@
sub alternative {
my ($class, %args) = @_;
- my @parts = @{$args{parts} || []};
- my %resources = %{$args{resources} || {}};
+ my @parts = @{delete $args{parts} || []};
+ my %resources = %{delete $args{resources} || {}};
# Make real the reousrces which just speicifed mime-types
for my $resource (keys %resources) {
next if UNIVERSAL::isa($resources{$resource}, "Email::MIME");
$resources{$resource} = Email::MIME->create(
attributes => {
- content_type => $resources{$src},
+ content_type => $resources{$resource},
encoding => "base64",
disposition => "inline",
},
- body => IO::All::io( $src )->all,
+ body => IO::All::io( $resource )->all,
);
}
@@ -158,8 +158,7 @@
$part->body_set( $tree->as_HTML );
}
- # Put it all together
- my $email = Email::MIME->create(
+ return Email::MIME->create(
%args,
parts => [
Email::MIME->create(
@@ -172,11 +171,9 @@
],
attributes => {
content_type => 'multipart/related',
+ type => 'multipart/alternative',
},
);
- $email->attribute_set(type => "multipart/alternative");
-
- return $email;
}
=head1 SEE ALSO
Added: Email-MIME-Alternative/t/parts.t
==============================================================================
--- (empty file)
+++ Email-MIME-Alternative/t/parts.t Mon Mar 20 13:33:41 2006
@@ -0,0 +1,61 @@
+use Test::More tests => 20;
+
+use_ok 'Email::MIME';
+use_ok 'Email::MIME::Creator';
+use_ok 'Email::MIME::ContentType';
+use_ok 'Email::MIME::Alternative';
+use IO::All;
+
+my $email = Email::MIME->alternative(
+ parts => [
+ Email::MIME->create(
+ attributes => { content_type => "text/plain" },
+ body => "Some content",
+ ),
+ Email::MIME->create(
+ attributes => { content_type => "text/moose" },
+ body => "Some other content",
+ ),
+ ],
+);
+
+isa_ok( $email, "Email::MIME", "Got back a Email::MIME from Alternative" );
+is( parse_content_type($email->header("Content-Type"))->{discrete}, "multipart" );
+is( parse_content_type($email->header("Content-Type"))->{composite}, "alternative" );
+is( scalar($email->parts), 2, "Got two alternatives" );
+
+$email = Email::MIME->alternative(
+ parts => [
+ Email::MIME->create(
+ attributes => { content_type => "text/plain" },
+ body => "Some content",
+ ),
+ Email::MIME->create(
+ attributes => { content_type => "text/moose" },
+ body => "Some other content",
+ ),
+ ],
+ resources => {
+ "pony.png" => Email::MIME->create(
+ attributes => { content_type => "image/png" },
+ body => "image",
+ ),
+ }
+);
+
+isa_ok( $email, "Email::MIME", "Got back a Email::MIME from Alternative" );
+is( parse_content_type($email->header("Content-Type"))->{discrete}, "multipart" );
+is( parse_content_type($email->header("Content-Type"))->{composite}, "related" );
+is( parse_content_type($email->header("Content-Type"))->{attributes}{type}, "multipart/alternative" );
+is( scalar($email->parts), 2, "Got two top-level parts" );
+
+my $top = ($email->parts)[0];
+isa_ok( $top, "Email::MIME", "Internal part is also an Email::MIME" );
+is( parse_content_type($top->header("Content-Type"))->{discrete}, "multipart" );
+is( parse_content_type($top->header("Content-Type"))->{composite}, "alternative" );
+is( scalar($top->parts), 2, "Got two alternatives" );
+
+my $res = ($email->parts)[1];
+isa_ok( $res, "Email::MIME", "Internal part is also an Email::MIME" );
+is( parse_content_type($res->header("Content-Type"))->{discrete}, "image" );
+is( parse_content_type($res->header("Content-Type"))->{composite}, "png" );
More information about the Rt-commit
mailing list