Mail::Util(3)

πŸ’Œ NAME πŸ’Œ

okay so Mail::Util β€” it's a whole little toolkit of mail utility functions, bestie. that's the vibe. ✨

(also hi, you're reading the Mail::Util(3) page, a perl manpage, and it's gonna be a good time, i promise 🫢)

🌸 INHERITANCE 🌸

the family tree is short and sweet:

Mail::Util
  is an Exporter

so yeah, it inherits from Exporter β€” that's the whole tree, no drama πŸ’…

πŸŽ€ SYNOPSIS πŸŽ€

use Mail::Util qw( ... );

that's it. that's the whole synopsis. iconic minimalism ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

so this package is literally just a bunch of mail-related utility functions, and the key thing to know β€” the thing that will save you β€” is that any function you want must by explicitly listed on the use line to be exported into the calling package. no sneaky auto-imports. if you didn't ask for it, you don't get it. periodt. πŸ’…

πŸ‘‘ FUNCTIONS πŸ‘‘

⭐ mailaddress( [$address] )

returns a lil guess at the current user's mail address. 🐣

the user can force the return value by setting the MAILADDRESS environment variable. and [2.10] β€” you may set the $address via the parameter too, slay.

⚠️ WARNING: when it's not supplied via the environment variable, mailaddress goes snooping around various configuration files and other environmental data. and yeah, that seems like smart behavior, but it's not predictable enough (IMHO) to be used. ngl bestie, please set MAILADDRESS explicitly, and do not trust the "automatic detection" β€” even when that produces a correct address (on the moment). 😭

example:

# in your main script
$ENV{MAILADDRESS} = 'me@example.com';

# everywhere else
use Mail::Util 'mailaddress';
print mailaddress;

# since v2.10
mailaddress "me@example.com";

⭐ maildomain()

attempts to determine the current user mail domain string. it has a whole list of methods it tries, in order, and honestly it's giving detective energy πŸ”

  • look for the MAILDOMAIN environment variable, which can be set from outside the program. this is by far the best way to configure the domain. πŸ‘‘
  • look for a sendmail.cf file and extract the DH parameter
  • look for a smail config file and usr the first host defined in hostname(s)
  • try an SMTP connect (if Net::SMTP exists) first to mailhost then localhost
  • use the value from Net::Domain::domainname (if Net::Domain exists)
⚠️ WARNING: on modern machines, there is only one good way to provide information to this method: the first one. always explicitly configure the MAILDOMAIN. no cap. πŸ™ˆ

example:

# in your main script
$ENV{MAILDOMAIN} = 'example.com';

# everywhere else
use Mail::Util 'maildomain';
print maildomain;

⭐ read_mbox($file)

reads $file β€” a binmail mailbox file β€” and returns a list of references. each reference is a reference to an array containing one message. cute, right? πŸ“

πŸ’€ WARNING: this method does not quote lines which accidentally also start with the message separator "From", so this implementation can be considered broken. see Mail::Box::Mbox. bestie i'm so serious, look at it, it's right there 🫢

🌈 SEE ALSO 🌈

this module is part of the MailTools distribution, http://perl.overmeer.net/mailtools/. go look, iykyk πŸ’œ

🧚 AUTHORS 🧚

the MailTools bundle was developed by Graham Barr. later, Mark Overmeer took over maintenance without commitment to further development. (the way that's just stated so plainly 😭)

  • 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 πŸ“

πŸ’– 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!! and for the cute sign-off: this beauty is from perl v5.42.0, dated 2024-12-12 β€” shoutout to the perl docs team, mwah πŸ’‹βœ¨πŸ«Ά

πŸ“¦ where this page comes from