| 1 | # (c)2000 Matthew MacKenzie <matt@xmlglobal.com> | ||
| 2 | # License: Artistic or LGPL, your choice. | ||
| 3 | |||
| 4 | package Mail::XML; | ||
| 5 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 0 | ▶ | use Mail::Internet; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | use XML::Writer; | ||
| 8 | use IO::Scalar; | ||
| 9 | use Carp; | ||
| 10 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||
| 11 | |||
| 12 | require Exporter; | ||
| 13 | |||
| 14 | @ISA = qw(Exporter Mail::Internet); | ||
| 15 | $VERSION = '0.03'; | ||
| 16 | |||
| 17 | sub toXML { | ||
| 18 | my ($self) = shift; | ||
| 19 | my $head = $self->head() || croak; | ||
| 20 | my $body = $self->body() || croak; | ||
| 21 | |||
| 22 | my $data = ""; | ||
| 23 | my $hdl = new IO::Scalar(\$data); | ||
| 24 | my $w = new XML::Writer(OUTPUT => $hdl); | ||
| 25 | $w->xmlDecl("ISO-8859-1"); | ||
| 26 | $w->comment("Mail::XML version " . $VERSION); | ||
| 27 | $w->startTag("Message"); | ||
| 28 | $w->startTag("Head"); | ||
| 29 | foreach my $tag ($head->tags()) { | ||
| 30 | chomp(my $c = $head->get($tag)); | ||
| 31 | if ($tag =~ m!From\s!) { | ||
| 32 | $tag = "MTA_From"; | ||
| 33 | } | ||
| 34 | $w->startTag($tag); | ||
| 35 | $w->characters($c); | ||
| 36 | $w->endTag($tag); | ||
| 37 | } | ||
| 38 | $w->endTag("Head"); | ||
| 39 | $w->startTag("Body"); | ||
| 40 | |||
| 41 | foreach (@$body) { | ||
| 42 | $w->characters($_); | ||
| 43 | } | ||
| 44 | $w->endTag("Body"); | ||
| 45 | $w->endTag("Message"); | ||
| 46 | $w->end(); | ||
| 47 | $hdl->close(); | ||
| 48 | return $data; | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; | ||
| 52 | __END__ | ||