Email-Abstract

 view release on metacpan or  search on metacpan

lib/Email/Abstract.pm  view on Meta::CPAN

All of these methods may be called either as object methods or as class
methods.  When called as class methods, the email object (of any class
supported by Email::Abstract) must be prepended to the list of arguments, like
so:

  my $return = Email::Abstract->method($message, @args);

This is provided primarily for backwards compatibility.

=head2 new

  my $email = Email::Abstract->new($message);

Given a message, either as a string or as an object for which an adapter is
installed, this method will return a Email::Abstract object wrapping the
message.

If the message is given as a string, it will be used to construct an object,
which will then be wrapped.

=head2 get_header

  my $header  = $email->get_header($header_name);

  my @headers = $email->get_header($header_name);

This returns the values for the given header.  In scalar context, it returns
the first value.

=head2 set_header

  $email->set_header($header => @values);

This sets the C<$header> header to the given one or more values.

=head2 get_body

  my $body = $email->get_body;

This returns the body as a string.

=head2 set_body

  $email->set_body($string);

This changes the body of the email to the given string.

B<WARNING!>  You probably don't want to call this method, despite what you may
think.  Email message bodies are complicated, and rely on things like content
type, encoding, and various MIME requirements.  If you call C<set_body> on a
message more complicated than a single-part seven-bit plain-text message, you
are likely to break something.  If you need to do this sort of thing, you
should probably use a specific message class from end to end.

This method is left in place for backwards compatibility.

=head2 as_string

  my $string = $email->as_string;

This returns the whole email as a decoded string.

=head2 cast

  my $mime_entity = $email->cast('MIME::Entity');

This method will convert a message from one message class to another.  It will
throw an exception if no adapter for the target class is known, or if the
adapter does not provide a C<construct> method.

=head2 object

  my $message = $email->object;

This method returns the message object wrapped by Email::Abstract.  If called
as a class method, it returns false.

Note that, because strings are converted to message objects before wrapping,
this method will return an object when the Email::Abstract was constructed from
a string.

=head1 AUTHORS

=over 4

=item *

Ricardo SIGNES <cpan@semiotic.systems>

=item *

Simon Cozens <simon@cpan.org>

=item *

Casey West <casey@geeknest.com>

=back

=head1 CONTRIBUTORS

=for stopwords Dave Rolsky Ricardo Signes William Yardley

=over 4

=item *

Dave Rolsky <autarch@urth.org>

=item *

Ricardo Signes <rjbs@semiotic.systems>

=item *

William Yardley <pep@veggiechinese.net>

=back

=head1 COPYRIGHT AND LICENSE

lib/Email/Abstract.pm  view on Meta::CPAN

#pod All of these methods may be called either as object methods or as class
#pod methods.  When called as class methods, the email object (of any class
#pod supported by Email::Abstract) must be prepended to the list of arguments, like
#pod so:
#pod
#pod   my $return = Email::Abstract->method($message, @args);
#pod
#pod This is provided primarily for backwards compatibility.
#pod
#pod =head2 new
#pod
#pod   my $email = Email::Abstract->new($message);
#pod
#pod Given a message, either as a string or as an object for which an adapter is
#pod installed, this method will return a Email::Abstract object wrapping the
#pod message.
#pod
#pod If the message is given as a string, it will be used to construct an object,
#pod which will then be wrapped.
#pod
#pod =head2 get_header
#pod
#pod   my $header  = $email->get_header($header_name);
#pod
#pod   my @headers = $email->get_header($header_name);
#pod
#pod This returns the values for the given header.  In scalar context, it returns
#pod the first value.
#pod
#pod =head2 set_header
#pod
#pod   $email->set_header($header => @values);
#pod
#pod This sets the C<$header> header to the given one or more values.
#pod
#pod =head2 get_body
#pod
#pod   my $body = $email->get_body;
#pod
#pod This returns the body as a string.
#pod
#pod =head2 set_body
#pod
#pod   $email->set_body($string);
#pod
#pod This changes the body of the email to the given string.
#pod
#pod B<WARNING!>  You probably don't want to call this method, despite what you may
#pod think.  Email message bodies are complicated, and rely on things like content
#pod type, encoding, and various MIME requirements.  If you call C<set_body> on a
#pod message more complicated than a single-part seven-bit plain-text message, you
#pod are likely to break something.  If you need to do this sort of thing, you
#pod should probably use a specific message class from end to end.
#pod
#pod This method is left in place for backwards compatibility.
#pod
#pod =head2 as_string
#pod
#pod   my $string = $email->as_string;
#pod
#pod This returns the whole email as a decoded string.
#pod
#pod =head2 cast
#pod
#pod   my $mime_entity = $email->cast('MIME::Entity');
#pod
#pod This method will convert a message from one message class to another.  It will
#pod throw an exception if no adapter for the target class is known, or if the
#pod adapter does not provide a C<construct> method.
#pod
#pod =head2 object
#pod
#pod   my $message = $email->object;
#pod
#pod This method returns the message object wrapped by Email::Abstract.  If called
#pod as a class method, it returns false.
#pod
#pod Note that, because strings are converted to message objects before wrapping,
#pod this method will return an object when the Email::Abstract was constructed from
#pod a string.
#pod
#pod =cut



( run in 0.423 second using v1.01-cache-2.11-cpan-2398b32b56e )