The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

# Copyrights 2001-2008 by Mark Overmeer.
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 1.03.
use strict;
use vars '$VERSION';
$VERSION = '2.081';
use Carp;
sub export($@)
{ my ($thing, $message) = (shift, shift);
croak "Export message must be a Mail::Message, but is a ".ref($message)."."
unless $message->isa('Mail::Message');
my $mi_head = Mail::Header->new;
my $head = $message->head;
foreach my $field ($head->orderedFields)
{ $mi_head->add($field->Name, scalar $field->foldedBody);
}
Mail::Internet->new
( Header => $mi_head
, Body => [ $message->body->lines ]
, @_
);
}
#------------------------------------------
my @pref_order = qw/From To Cc Subject Date In-Reply-To References
Content-Type/;
sub from($@)
{ my ($thing, $mi) = (shift, shift);
croak "Converting from Mail::Internet but got a ".ref($mi).'.'
unless $mi->isa('Mail::Internet');
my $head = Mail::Message::Head::Complete->new;
my $body = Mail::Message::Body::Lines->new(data => [ @{$mi->body} ]);
my $mi_head = $mi->head;
# The tags of Mail::Header are unordered, but we prefer some ordering.
my %tags = map {lc $_ => ucfirst $_} $mi_head->tags;
my @tags;
foreach (@pref_order)
{ push @tags, $_ if delete $tags{lc $_};
}
push @tags, sort values %tags;
foreach my $name (@tags)
{ $head->add($name, $_)
foreach $mi_head->get($name);
}
Mail::Message->new(head => $head, body => $body, @_);
}
#------------------------------------------
1;