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,mailaddressgoes 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 setMAILADDRESSexplicitly, 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
MAILDOMAINenvironment variable, which can be set from outside the program. this is by far the best way to configure the domain. π - look for a
sendmail.cffile and extract theDHparameter - look for a
smailconfig file and usr the first host defined inhostname(s) - try an SMTP connect (if
Net::SMTPexists) first tomailhostthenlocalhost - use the value from
Net::Domain::domainname(ifNet::Domainexists)
β οΈ 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. seeMail::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::Capby Gisle Aas<aas@oslonett.no>π¦Mail::Field::AddrListby Peter Orbaek<poe@cit.dk>πΈMail::MailerandMail::Sendby 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
- opensuse-leap 16.0: perl-MailTools 2.220.0-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms