Mail::Internet(3)

๐Ÿ’Œ Mail::Internet(3) โ€” ok bestie, let's talk email ๐Ÿ’Œ

So likeโ€ฆ this whole page is about Mail::Internet, a Perl module that lets you mess with email messages. Grab a snack, it's gonna be a ride ๐Ÿ“


โœจ NAME โœจ

Mail::Internet โ€” manipulate email messages. That's it. That's the whole vibe. ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

use Mail::Internet;
my $msg = Mail::Internet->new(\*STDIN);

Literally two lines and you're already doing email things. Iconic.


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

Okay so this package implements reading, creating, manipulating, and writing email messages. Sometimes the implementation tries to be too smart for its own good, but in the general case it works as expected. No cap. โœจ

๐Ÿ’€ Real talk though: if you're starting to write a new application, you should use the Mail::Box distribution instead. It has more features and handles messages much better according to the RFCs. See <http://perl.overmeer.net/mailbox/>. You may also chose MIME::Entity, to get at least some multipart support in your application.

(Yes, that "chose" is how it's written, we don't fix, we just vibe ๐Ÿซถ)


๐Ÿ‘‘ METHODS ๐Ÿ‘‘

๐ŸŽ€ Constructors ๐ŸŽ€

  • $obj->dup() โ€” Duplicate the message as a whole. Both header and body get deep-copied: you get a brand-new Mail::Internet object back. It's giving clone drama, in the best way ๐Ÿ’–
  • $obj->extract(\@lines) โ€” Extract header and body from an ARRAY of message lines. Heads up: this requires an object already created with new(), and its contents will get overwritten. So like, don't get attached to whatever was in there before ๐Ÿ™ˆ
  • $obj->new( [$arg], [%options] ) Mail::Internet->new( [$arg], [%options] ) โ€” the main character constructor. $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 or read from the file descriptor. (Yes, original says "of read from the file descriptor" โ€” typos are forever โญ)

The Mail::Header::new() %options "Modify", "MailFrom" and "FoldLength" may also be given. Slay.

Defaults, bestie:

-Option--Default
 Body    []
 Header  undef
  • 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 "\n" (LF). If Body is given then Mail::Internet will not attempt to read the body from $arg (even if it is specified). Rude but fair ๐Ÿ’…
  • Header => Mail::Header โ€” The value of this option should be a Mail::Header object. If given then Mail::Internet will not attempt to read a mail header from $arg, if it was specified. Boundaries. We love them. ๐Ÿฆ‹
  • $obj->read($fh) โ€” Read a message from the $fh into an already existing message object. But honestly? Better use new() with the $fh as first argument. Trust. โœจ

๐Ÿ’œ Accessors ๐Ÿ’œ

  • $obj->body( [$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 $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. Live by the reference, die by the reference, fr fr ๐Ÿ˜ญ

  • $obj->head() โ€” Returns the Mail::Header object which holds the headers for the current message. Just the head, no body, no drama. ๐Ÿ‘‘

๐ŸŒˆ Processing the message as a whole ๐ŸŒˆ

  • $obj->as_mbox_string( [$already_escaped] ) โ€” Returns the message as a string in mbox format. $already_escaped, if given and true, indicates that escape_from() has already been called on this object. iykyk ๐ŸŽ€
  • $obj->as_string() โ€” Returns the message as a single string. One string. Singular. Iconic.
  • $obj->print( [$fh] ) โ€” Print the header, body or whole message to file descriptor $fh. $fd should be a reference to a GLOB. (Yes, it says $fd right there in the prose, we're keeping it ๐Ÿ’€) If $fh is not given the output will be sent to STDOUT.

example:

$mail->print( \*STDOUT );  # Print message to STDOUT
  • $obj->print_body( [$fh] ) โ€” Print only the body to the $fh (default STDOUT). No header, no notes, just body. ๐Ÿซถ
  • $obj->print_header( [$fh] ) โ€” Print only the header to the $fh (default STDOUT). The opposite vibe. ๐Ÿ’…

๐Ÿงš Processing the header ๐Ÿงš

Most of these methods are simply wrappers around methods provided by Mail::Header. So like, don't come for them, they're delegating besties โœจ

  • $obj->add(PAIRS) โ€” The PAIRS are field-name and field-content. For each PAIR, Mail::Header::add() is called. All fields are added after existing fields. The last addition is returned. Last one gets the spotlight ๐Ÿ‘‘
  • $obj->combine( $tag, [$with] ) โ€” See Mail::Header::combine(). Short and sweet.
  • $obj->delete( $tag, [$tags] ) โ€” Delete all fields with the name $tag. Mail::Header::delete() is doing the work. Bye bestie ๐Ÿ‘‹
  • $obj->fold( [$length] ) โ€” See Mail::Header::fold().
  • $obj->fold_length( [$tag], [$length] ) โ€” See Mail::Header::fold_length().
  • $obj->get( $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. Mail::Header::get() is called to collect the data. Context-sensitive king ๐Ÿ’…
  • $obj->header(\@lines) โ€” See Mail::Header::header().
  • $obj->replace(PAIRS) โ€” The PAIRS are field-name and field-content. For each PAIR, Mail::Header::replace() 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. (And yes, "specified" โ€” it's canon now ๐Ÿ˜ญ)

๐Ÿ“ Processing the body ๐Ÿ“

  • $obj->remove_sig( [$nlines] ) โ€” Attempts to remove a user's signature from the body of a message. It does this by looking for a line equal to '-- ' within the last $nlines of the message. If found then that line and all lines after it will be removed. If $nlines is not given a default value of 10 will be used. This would be of most use in auto-reply scripts. Very much the "please stop replying with your full signature block" energy ๐Ÿ™ˆ
  • $obj->sign(%options) โ€” Add your signature to the body. remove_sig() will strip existing signatures first. Clean slate, then glow up ๐Ÿ’–

Defaults:

-Option   --Default
 File       undef
 Signature  []
  • **File => FILEHANDLE** โ€” Take from the FILEHANDLEall lines starting from the first"--"`.
  • Signature => STRING|ARRAY-of-LINES` โ€” your actual sig, as a string or lines.
  • $obj->tidy_body() โ€” Removes all leading and trailing lines from the body that only contain white spaces. Spring cleaning for your message body ๐Ÿงนโœจ

๐Ÿ”ฅ High-level functionality ๐Ÿ”ฅ

  • $obj->escape_from() โ€” It can cause problems with some applications if a message contains a line starting with `From ', in particular when attempting to split a folder. This method inserts a leading ">" on any line that matches the regular expression /^>*From/.
  • $obj->nntppost( [%options] ) โ€” Post an article via NNTP. Requires Net::NNTP to be installed. ๐Ÿ“ฎ

Defaults:

-Option--Default
 Debug   <false>
 Host    <required>
 Port    119
  • **Debug => BOOLEAN** โ€” Debug value to pass to Net::NNTP, see Net::NNTP`.
  • **Host => HOSTNAME|Net::NNTP object** โ€” Name of NNTP server to connect to, or a Net::NNTP` object to use.
  • Port => INTEGER` โ€” Port number to connect to on remote host.
  • $obj->reply(%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 .mailhdr file in your home directory (if exists) will be read first, to provide defaults. Cute. Customisable. Obsessed. ๐ŸŽ€

Defaults:

-Option  --Default
 Exclude   []
 Indent    '>'
 Keep      []
 ReplyAll  false
  • **Exclude => ARRAY-of-FIELDS** โ€” Remove the listed FIELDS` from the produced message. Begone, headers.
  • **Indent => STRING** โ€” Use as indentation string. The string may contain "%%"to get a single"%", %fto get the first from name,%Fis the first character of%f, %lis the last name,%Lits first character,%nthe whole from string, and%I` the first character of each of the names in the from string. It's giving template language, and honestly? Slay. ๐Ÿ’…
  • **Keep => ARRAY-of-FIELDS** โ€” Copy the listed FIELDS` from the original message.
  • **ReplyAll => BOOLEAN** โ€” Automatically include all ToandCcaddresses of the original mail, excluding those mentioned in theBcc` list. Reply-all responsibly bestie ๐Ÿ˜ญ
  • $obj->send( [$type, [$args...]] ) โ€” Send a Mail::Internet message using Mail::Mailer. $type and $args are passed on to Mail::Mailer::new(). Easy. Done. Sent. โœจ
  • $obj->smtpsend( [%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 "To", Cc or "Bcc" 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.

Defaults:

-Option  --Default
 Bcc       undef
 Cc        undef
 Debug     <false>
 Hello     localhost.localdomain
 Host      $ENV{SMTPHOSTS}
 MailFrom  Mail::Util::mailaddress()
 Port      25
 To        undef
  • Bcc => ADDRESSES`
  • Cc => ADDRESSES`
  • **Debug => BOOLEAN** โ€” Debug value to pass to Net::SMTP`, see <Net::SMTP>
  • **Hello => STRING** โ€” Send a HELO(orEHLO`) command to the server with the given name.
  • **Host => HOSTNAME** โ€” Name of the SMTP server to connect to, or a Net::SMTP` object to use.

If "Host" is not given then the SMTP host is found by attempting connections first to hosts specified in $ENV{SMTPHOSTS}, a colon separated list, then "mailhost" and "localhost". Detective work, honestly ๐Ÿ”

  • **MailFrom => ADDRESS** โ€” The e-mail address which is used as sender. By default, Mail::Util::mailaddress()` provides the address of the sender.
  • Port => INTEGER` โ€” Port number to connect to on remote host.
  • To => ADDRESSES`
  • $obj->unescape_from(()) โ€” Remove the escaping added by escape_from(). Undo the chaos ๐ŸŒธ

๐Ÿ’– SEE ALSO ๐Ÿ’–

This module is part of the MailTools distribution, <http://perl.overmeer.net/mailtools/>. Go look, bestie ๐Ÿซถ


โญ AUTHORS โญ

The MailTools bundle was developed by Graham Barr. Later, Mark Overmeer took over maintenance without commitment to further development. (Real ones know ๐Ÿ˜ญ)

Mail::Cap by Gisle Aas <aas@oslonett.no>. Mail::Field::AddrList by Peter Orbaek <poe@cit.dk>. Mail::Mailer and Mail::Send by Tim Bunce <Tim.Bunce@ig.co.uk>. For other contributors see ChangeLog. Legends, all of them ๐Ÿ‘‘


๐ŸŽ€ LICENSE ๐ŸŽ€

Copyrights 1995-2000 Graham Barr <gbarr@pobox.com> and 2001-2024 Mark Overmeer <perl@overmeer.net>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See <http://www.perl.com/perl/misc/Artistic.html>


okay that's the whole page, you made it, I'm so proud of you ๐Ÿฅนโœจ this was Mail::Internet(3), shipped with perl v5.42.0, dated 2024-12-12 โ€” mwah, go send some emails, love u bye ๐Ÿ’…๐Ÿ’–

๐Ÿ“ฆ where this page comes from