=begin pod

=head1 NAME

Email::Simple - Simple email parsing module

=head1 SYNOPSIS

=begin code :lang<raku>
use Email::Simple;

my $eml = Email::Simple.new($raw-mail-text);
say $eml.body;

my $new = Email::Simple.create(
  header => [
    ['To', 'mail@example.com'],
    ['From', 'me@example.com'],
    ['Subject', 'test']
  ],
  body => 'This is a test.',
);
say ~$new;
=end code

=head1 DESCRIPTION

This distribution provides a simple way of composing the raw contents
of an email, given a set of headers and a body.  Or given the raw
contents of an email, provide access to its headers and body.

=head1 CLASS METHODS

=head2 new

=begin code :lang<raku>
my $eml = Email::Simple.new($raw-mail-text);
=end code

Creates a C<Email::Simple> object given a string containing the raw
email text.

=begin code :lang<raku>
my $new = Email::Simple.create(
  header => [
    ['To', 'mail@example.com'],
    ['From', 'me@example.com'],
    ['Subject', 'test']
  ],
  body => 'This is a test.',
);
=end code

Creates an C<Email::Simple> object given an Array of Arrays with
headers, and a body.

=head2 create

This offers the same functionality as C<.new>, but uses a named
arguments interface:

=item :header - an Array of Arrays with headers
=item :body - a string with the email's body
=item :header-class - class to handle headers (default: Email::Simple::Header)

=head1 INSTANCE METHODS

=head2 header($name, :$multi)

Returns the email header with the name C<$name>. If C<:$multi> is not
passed, then this will return the first header found. If C<:$multi> is
set, then this will return a list of all headers with the name C<$name>.

=head2 header-set($name, *@lines)

Sets the header C<$name>. Adds one C<$name> header for each additional
argument passed.

=head2 header-names

Returns a list of header names in the email.

=head2 headers

Alias of C<header-names>

=head2 header-pairs

Returns the full header data for an email.

=begin code :lang<raku>
$eml.header-pairs(); # --> [['Subject', 'test'], ['From', 'me@example.com']]
=end code

=head2 body

Returns the mail body. Note that this module does not try to do any
decoding, it just returns the body as-is.

=head2 body-set($text)

Sets the mail body to C<$text>. Note that this module does not try
to properly encode the body.

=head2 as-string, Str

Returns the full raw email, suitable for piping into sendmail.

=head2 crlf

=head2 header-obj

=head2 header-obj-set($obj)

=head1 AUTHOR

Andrew Egeler

Source can be located at: https://github.com/raku-community-modules/Email-Simple .
Comments and Pull Requests are welcome.

=head1 COPYRIGHT AND LICENSE

Copyright 2012 - 2018 Andrew Egeler

Copyright 2019 - 2022, 2024, 2026 Raku Community

All files in this repository are licensed under the terms of Create Commons License; for details please see the LICENSE file

=end pod

# vim: expandtab shiftwidth=4
