=encoding utf8 =head1 NAME Mail::Internet - manipulate email messages =head1 SYNOPSIS use Mail::Internet; my $msg = Mail::Internet->new(\*STDIN); =head1 DESCRIPTION This package implements reading, creating, manipulating, and writing email messages. Sometimes, the implementation tries to be too smart, but in the general case it works as expected. If you start writing a B, you should use the L distribution, which has more features and handles messages much better according to the RFCs. See L. You may also chose L, to get at least some multipart support in your application. =head1 METHODS =head2 Constructors =over 4 =item $obj-EB() Duplicate the message as a whole. Both header and body will be deep-copied: a new L object is returned. =item $obj-EB(\@lines) Extract header and body from an ARRAY of message lines. Requires an object already created with L, which contents will get overwritten. =item $obj-EB( [$arg], [%options] ) =item Mail::Internet-EB( [$arg], [%options] ) $arg is optional and may be either a file descriptor (reference to a GLOB) or a reference to an array. If given the new object will be initialized with headers and body either from the array of read from the file descriptor. The L %options C, C and C may also be given. -Option--Default Body [] Header undef =over 2 =item Body => ARRAY-of-LINES The value of this option should be a reference to an array which contains the lines for the body of the message. Each line should be terminated with C<\n> (LF). If Body is given then C will not attempt to read the body from C<$arg> (even if it is specified). =item Header => Mail::Header The value of this option should be a L object. If given then C will not attempt to read a mail header from C<$arg>, if it was specified. =back =item $obj-EB($fh) Read a message from the $fh into an already existing message object. Better use L with the $fh as first argument. =back =head2 Accessors =over 4 =item $obj-EB( [$body] ) Returns the body of the message. This is a reference to an array. Each entry in the array represents a single line in the message. If I<$body> is given, it can be a reference to an array or an array, then the body will be replaced. If a reference is passed, it is used directly and not copied, so any subsequent changes to the array will change the contents of the body. =item $obj-EB() Returns the C object which holds the headers for the current message =back =head2 Processing the message as a whole =over 4 =item $obj-EB( [$already_escaped] ) Returns the message as a string in mbox format. C<$already_escaped>, if given and true, indicates that L has already been called on this object. =item $obj-EB() Returns the message as a single string. =item $obj-EB( [$fh] ) Print the header, body or whole message to file descriptor I<$fh>. I<$fd> should be a reference to a GLOB. If I<$fh> is not given the output will be sent to STDOUT. example: $mail->print( \*STDOUT ); # Print message to STDOUT =item $obj-EB( [$fh] ) Print only the body to the $fh (default STDOUT). =item $obj-EB( [$fh] ) Print only the header to the $fh (default STDOUT). =back =head2 Processing the header Most of these methods are simply wrappers around methods provided by L. =over 4 =item $obj-EB(PAIRS) The PAIRS are field-name and field-content. For each PAIR, L is called. All fields are added after existing fields. The last addition is returned. =item $obj-EB( $tag, [$with] ) See L. =item $obj-EB( $tag, [$tags] ) Delete all fields with the name $tag. L is doing the work. =item $obj-EB( [$length] ) See L. =item $obj-EB( [$tag], [$length] ) See L. =item $obj-EB( $tag, [$tags] ) In LIST context, all fields with the name $tag are returned. In SCALAR context, only the first field which matches the earliest $tag is returned. L is called to collect the data. =item $obj-EB
(\@lines) See L. =item $obj-EB(PAIRS) The PAIRS are field-name and field-content. For each PAIR, L is called with index 0. If a $field is already in the header, it will be removed first. Do not specified the same field-name twice. =back =head2 Processing the body =over 4 =item $obj-EB( [$nlines] ) Attempts to remove a user's signature from the body of a message. It does this by looking for a line equal to C<'-- '> within the last C<$nlines> of the message. If found then that line and all lines after it will be removed. If C<$nlines> is not given a default value of 10 will be used. This would be of most use in auto-reply scripts. =item $obj-EB(%options) Add your signature to the body. L will strip existing signatures first. -Option --Default File undef Signature [] =over 2 =item File => FILEHANDLE Take from the FILEHANDLE all lines starting from the first C<< -- >>. =item Signature => STRING|ARRAY-of-LINES =back =item $obj-EB() Removes all leading and trailing lines from the body that only contain white spaces. =back =head2 High-level functionality =over 4 =item $obj-EB() It can cause problems with some applications if a message contains a line starting with C<`From '>, in particular when attempting to split a folder. This method inserts a leading C<`>'> on any line that matches the regular expression C*From/> =item $obj-EB( [%options] ) Post an article via NNTP. Requires Net::NNTP to be installed. -Option--Default Debug Host Port 119 =over 2 =item Debug => BOOLEAN Debug value to pass to Net::NNTP, see L =item Host => HOSTNAME|Net::NNTP object Name of NNTP server to connect to, or a Net::NNTP object to use. =item Port => INTEGER Port number to connect to on remote host =back =item $obj-EB(%options) Create a new object with header initialised for a reply to the current object. And the body will be a copy of the current message indented. The C<.mailhdr> file in your home directory (if exists) will be read first, to provide defaults. -Option --Default Exclude [] Indent '>' Keep [] ReplyAll false =over 2 =item Exclude => ARRAY-of-FIELDS Remove the listed FIELDS from the produced message. =item Indent => STRING Use as indentation string. The string may contain C<%%> to get a single C<%>, C<%f> to get the first from name, C<%F> is the first character of C<%f>, C<%l> is the last name, C<%L> its first character, C<%n> the whole from string, and C<%I> the first character of each of the names in the from string. =item Keep => ARRAY-of-FIELDS Copy the listed FIELDS from the original message. =item ReplyAll => BOOLEAN Automatically include all To and Cc addresses of the original mail, excluding those mentioned in the Bcc list. =back =item $obj-EB( [$type, [$args...]] ) Send a Mail::Internet message using L. $type and $args are passed on to L. =item $obj-EB( [%options] ) Send a Mail::Internet message using direct SMTP to the given ADDRESSES, each can be either a string or a reference to a list of email addresses. If none of C, or C are given then the addresses are extracted from the message being sent. The return value will be a list of email addresses that the message was sent to. If the message was not sent the list will be empty. Requires Net::SMTP and Net::Domain to be installed. -Option --Default Bcc undef Cc undef Debug Hello localhost.localdomain Host $ENV{SMTPHOSTS} MailFrom Mail::Util::mailaddress() Port 25 To undef =over 2 =item Bcc => ADDRESSES =item Cc => ADDRESSES =item Debug => BOOLEAN Debug value to pass to Net::SMTP, see =item Hello => STRING Send a HELO (or EHLO) command to the server with the given name. =item Host => HOSTNAME Name of the SMTP server to connect to, or a Net::SMTP object to use If C is not given then the SMTP host is found by attempting connections first to hosts specified in C<$ENV{SMTPHOSTS}>, a colon separated list, then C and C. =item MailFrom => ADDRESS The e-mail address which is used as sender. By default, L provides the address of the sender. =item Port => INTEGER Port number to connect to on remote host =item To => ADDRESSES =back =item $obj-EB(()) Remove the escaping added by L. =back =head1 SEE ALSO This module is part of the MailTools distribution, F. =head1 AUTHORS The MailTools bundle was developed by Graham Barr. Later, Mark Overmeer took over maintenance without commitment to further development. Mail::Cap by Gisle Aas Eaas@oslonett.noE. Mail::Field::AddrList by Peter Orbaek Epoe@cit.dkE. Mail::Mailer and Mail::Send by Tim Bunce ETim.Bunce@ig.co.ukE. For other contributors see ChangeLog. =head1 LICENSE Copyrights 1995-2000 Graham Barr Egbarr@pobox.comE and 2001-2017 Mark Overmeer Eperl@overmeer.netE. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F