Mail::...:IMAP4(3pm)
πΈ Mail::Transport::IMAP4 β the perl manpage but make it β¨immaculateβ¨
okay bestie, so this is Mail::...:IMAP4(3pm) from the User Contributed Perl Documentation, and it's literally the glow-up server edition of your mail folder story. sit down, hydrate, let's go π
π NAME π
Mail::Transport::IMAP4 β she's a proxy to Mail::IMAPClient, no cap π«Ά
π¦ INHERITANCE π¦
this is the family tree and it's giving legacy royalty:
Mail::Transport::IMAP4
is a Mail::Transport::Receive
is a Mail::Transport
is a Mail::Reporter
so she inherits from <purple>Mail::Transport::Receive</purple>, who inherits from <purple>Mail::Transport</purple>, who inherits from <purple>Mail::Reporter</purple>. generational excellence fr fr π
β¨ SYNOPSIS β¨
here's the vibe, copy-paste ready, character for character:
my $imap = Mail::Transport::IMAP4->new(...);
my $message = $imap->receive($id);
$imap->send($message);
my Mail::Box::Manager $mgr = Mail::Box::Manager->new;
$mgr->open(
# Generic folder options
folder => 'imaps://...',
access => 'rw',
extract => 'ALWAYS',
# Mail::IMAPClient options start with [A-Z]
IgnoreSizeErrors => 1,
Ssl => 1,
);
lowkey iconic. notice how the generic folder options are all lowercase and the Mail::IMAPClient options start with a capital letter β that's the whole trick iykyk π€«
π DESCRIPTION π
okay so here's the tea β the IMAP4 protocol is quite complicated β she's feature rich and she looooves letting you do a bunch of asynchronous actions all at once, main character energy honestly. the main document that describes IMAP is rfc3501, which obsoleted the original spec of protocol 4r1 that lived in rfc2060 back in March 2003. so rfc2060? she's retired bestie, respectfully πͺ¦
now, plot twist: this package, as part of MailBox, does not implement the actual protocol itself. nope! she outsources the whole thing to Mail::IMAPClient to do the work π. the job of this package is to hide as many differences as possible between that module's interface and the common MailBox folder types. and here's a fun fact: multiple Mail::Box::IMAP4 folders can share one Mail::Transport::IMAP4 connection π β one connection, many folders, efficiency queen.
and now the part where i have to be real with you π: the Mail::IMAPClient module is the best IMAP4 implementation for Perl5, but β and i am so sorry β it is not maintained. there are many known problems with the module, and solving those is outside the scope of MailBox. so do not come for MailBox about it, she is simply not the one. if you want all the reported bugs, they're living at:
https://rt.cpan.org/Public/Dist/Display.html?Name=Mail-IMAPClient
π«Ά just so you know: this section extends "DESCRIPTION" in Mail::Transport::Receive, so go read that one too when you're done here.
part 1 done, but we are NOT done β more incoming π
ποΈ Constructors
cute, so Constructors in Mail::Transport::Receive? yeah we extend that. slay.
π
$class->new(%options)
bestie this one creates the IMAP connection to the server. that's the whole vibe. β¨
so like, IMAP servers can handle multiple folders for a single user, which means connections may get shared. and this sharing? it's hidden from you. it's giving invisible. you don't see it, you don't manage it, you just vibe. π¦
when you specify an imap_client, then the options hostname, port, username, and password get extracted from it. free real estate.
every %options that starts with a capital letter gets passed as initiation to Mail::IMAPClient. go read that manual for the huge pile of parameters, no cap, it's a lot. when you're talking to Microsoft Exchange, you probabaly need the IgnoreSizeErros. also probably you need Ssl or StartTLS too. and as a little feature β¨ you may also pass a HASH to Ssl, where Mail::IMAPClient only accepts an ARRAY. we're generous like that.
for backwards compatibility, ssl is an alternative for Ssl, and starttls for StartTLS. improves base, see Constructors in Mail::Reporter.
here's the whole option menu, lowkey iconic:
-Option --Defined in --Default
authenticate 'AUTO'
domain <server_name>
executable Mail::Transport undef
hostname Mail::Transport 'localhost'
imap_client Mail::IMAPClient
interval Mail::Transport 30
password Mail::Transport undef
port Mail::Transport 143
proxy Mail::Transport undef
retry Mail::Transport <unlimited>
timeout Mail::Transport 120
username Mail::Transport undef
via Mail::Transport 'imap'
now let's do them one by one, obviously π
authenticate => TYPE|ARRAYβ the Authenthication method tologin(), which gets passed to theMail::IMAPClientsubroutineauthenticate. go look at that method for the available types. and yes you may provide an ARRAY of types. multiple? we love options.domain => WINDOWS_DOMAINβ used for NTLM authentication. windows coded fr.executable => $fileβ take it away,Mail::Transport.hostname => $host|\@hostsβ yup,Mail::Transportagain.imap_client => OBJECT|CLASSβ when an OBJECT is supplied, that client gets used for the implementation of the IMAP4 protocol. info about server and stuff is extracted from the OBJECT so the accessors produce correct results. the OBJECT shall be aMail::IMAPClient. π«Ά
when a CLASS is given, an object of that type gets created for you. the created object can be grabbed via imapClient(), and than configured as defined by Mail::IMAPClient.
interval => $spanβMail::Transportmoment.password => $passwordβ yeah.Mail::Transport.port => $portβMail::Transport, as always.proxy => $pathβMail::Transport.retry => $count|undefβMail::Transportbestie.timeout => $spanβMail::Transport.username => $usernameβMail::Transport.via => CLASS|$nameβMail::Transport.
π Attributes
extends Attributes in Mail::Transport::Receive. says so right there.
πΈ $obj->authentication( ['AUTO'|$type|$types] )
returns a LIST of ARRAYS, each one describing one possible way to contact the server. each pair contains a mechanism name and a challenge callback (which may be undef). like a lil matching game β¨
these settings get used by login() to get server access. the initial value origins from new(authenticate), but you may change it later. glow up.
the available basic $types are CRAM-MD5, NTLM, and PLAIN. with AUTO, all available types will be tried. when the Authen::NTLM isn't installed, the NTLM option quietly gets skipped. but be warned π β because of PLAIN, erroneous username/password combinations will be passed readible as the last attempt!
the NTLM authentication requires Authen::NTLM to be installed. other methods may be added later. besides, you may also specify a CODE reference which implements some authentication.
an ARRAY as $type can be used to specify both mechanism as callback. when no array is used, callback of the pair is set to undef. see authenticate in Mail::IMAPClient for the gory details. π
Β» example:
$transporter->authentication('CRAM-MD5', [MY_AUTH => \&c], 'PLAIN');
foreach my $pair ($transporter->authentication)
{ my ($mechanism, $challenge) = @$pair;
...
}
π¦ $obj->domain( [$domain] )
used in NTLM authentication to define the Windows domain which is accessed. initially set by new(domain) and defaults to the server's name. π
π $obj->usesSSL()
returns a boolean. that's it. that's the method.
π¬ Receiving mail
extends Receiving mail in Mail::Transport::Receive.
β $obj->receive( [$unique_message_id] )
inherited, see Receiving mail in Mail::Transport::Receive.
π Server connection
extends Server connection in Mail::Transport::Receive. we stay connected bestie.
π§ $obj->findBinary( $name, [@directories] )
inherited, see Server connection in Mail::Transport.
π $obj->remoteHost()
inherited, see Server connection in Mail::Transport.
π $obj->retry()
inherited, see Server connection in Mail::Transport.
π¬ Exchanging Information
π οΈ Protocol [internals]
the follow methods handle protocol internals, and should not be used by a normal user of this class. so like, hands off unless you know what you're doing, iykyk. π
π $obj->appendMessage( $message, $foldername, [$date] )
write the message to the server. the optional DATA can be an RFC-822 date or a timestamp. π
π $obj->createFolder($name)
add a folder. one and done.
π $obj->createImapClient($class, %options)
create an object of $class, which extends Mail::IMAPClient.
π $obj->currentFolder( [$foldername] )
be sure that the specific FOLDER is the current one selected. and literally, if the folder is already selected, no IMAP traffic will be produced. zero. none. efficient queen. β¨
the boolean return value indicates whether the folder is selectable. it will return undef if it does not exist. π
π $obj->deleteFolder($name)
remove one folder. bye bestie π
π $obj->destroyDeleted($folder)
command the server to delete for real all messages which are flagged to be deleted. like, for real for real.
π $obj->fetch(\@messages, $info)
get some $info about the @messages from the server. the specified messages shall extend Mail::Box::Net::Message, returned is a list of hashes, each info about one result. the contents of the hash differs per $info, but at least a message field will be present, to relate to the message in question.
the right folder should be selected before this method is called. when the connection was lost, undef is returned. without any messages, and empty array is returned. the retrieval is done by Mail::IMAPClient method fetch(), which is then parsed. πΈ
π $any->flagsToLabels($what, @flags)
in SCALAR context, a hash with labels is returned. in LIST context, pairs are returned.
the $what parameter can be 'SET', 'CLEAR', or 'REPLACE'. with the latter, all standard imap flags which do not appear in the list will be ignored: their value may either by set or cleared. see getFlags()
unknown flags in @flags are stripped from their backslash and lower-cased. for instance, '\SomeWeirdFlag' will become someweirdflag => 1. it will be set to '1' for SET, and '0' in case of CLEAR.
Β» example: translating IMAP4 flags into MailBox flags
my @flags = ('\Seen', '\Flagged');
my $labels = Mail::Transport::IMAP4->flags2labels(SET => @flags);
π $obj->folders( [$foldername] )
returns a list of folder names which are sub-folders of the specified $foldername. without $foldername, the top-level foldernames are returned. π
π $obj->getFields( $uid, $name, [$name, ...] )
get the records with the specified NAMES from the header. the header fields are returned as list of Mail::Message::Field::Fast objects. when the name is ALL, the whole header is returned. the whole thing. periodt.
π $obj->getFlags($folder, $id)
returns the values of all flags which are related to the message with the specified $id. these flags are translated into the names which are standard for the MailBox suite.
a HASH is returned. names which do not appear will also provide a value in the returned: the negative for the value is it was present. π«Ά
π $obj->getMessageAsString($message|$uid)
returns the whole text of the specified message: the head and the body. both. iconic.
π $obj->ids()
returns a list of UIDs which are defined by the IMAP server. β¨
π $obj->imapClient()
returns the object which implements the IMAP4 protocol, an instance of a Mail::IMAPClient, which is logged-in and ready to use. main character energy fr.
if the contact to the server was still present or could be established, an Mail::IMAPClient object is returned. else, undef is returned and no further actions should be tried on the object. π
π $any->labelsToFlags(HASH|PAIRS)
convert MailBox labels into IMAP flags. returned is a string. unsupported labels are ignored. we don't talk about them π
π $obj->listFlags()
returns all predefined flags as list.
π $obj->login()
establish a new connection to the IMAP4 server, using username and password. π₯
π $obj->setFlags($id, $label, $value, [$label, $value], ...)
change the flags on the message which are represented by the label. the value which can be related to the label will be lost, because IMAP only defines a boolean value, where MailBox labels can contain strings. π gone. reduced. sad.
returned is a list of ($label => $value) pairs which could not be send to the IMAP server. these values may be cached in a different way.
π¨ Error handling
extends Error handling in Mail::Transport::Receive.
π $obj->AUTOLOAD()
inherited, see Error handling in Mail::Reporter.
π $obj->notImplemented()
inherited, see Error handling in Mail::Reporter.
π§Ή Cleanup
extends Cleanup in Mail::Transport::Receive.
π«§ $obj->DESTROY()
the connection is cleanly terminated when the program is terminated. improves base, see Cleanup in Mail::Reporter. we leave tidy, always π
β¨
π©Ί DIAGNOSTICS π©Ί
okay bestie, these are the little messages this module casts into the void when stuff happens. some are cute lil notices, some are warnings, and some are full-on fatal errors π. here's the whole lineup, no skips:
Notice: IMAP4 authenication $type to $service successfulβ cast bylogin(). yes, the spelling isauthenication, i'm just the messenger π . anyway, it means your login went through, slay.Error: IMAP4 cannot connect to $service: $@β cast bylogin(). the connection said no and gave you the reason in$@.Error: IMAP4 requires a username and passwordβ cast bylogin(). you gotta give it both, no half-sending.Error: IMAP4 username $user requires a passwordβ cast bylogin(). you gave a username but forgot the password, bestie. not the vibe.Error: cannot create imap client: {error}β cast bycreateImapClient(). the imap client did not get born, and{error}spills the tea about why.Error: class $package does not implement method $method.β cast bynotImplemented(). this one is fatal, so pay attention π. here's the whole situation:$packageβ or one of its superclasses β doesn't implement this method where it's supposed to. but lowkey, some other related classes do implement it, and this class justβ¦ doesn't. probably you should look into that, and probably you should tell the author of the package about it. it's giving "somebody forgot something" energy.Error: couldn't contact to IMAP4 $serviceβ cast bylogin(). it tried to reach$serviceand could not. no contact, no connection.Notice: couldn't select folder $name but it does exist.β cast bycurrentFolder(). the folder is real, it's there, but selecting it still didn't work. the audacity π.Warning: failed attempt to login $user, retrying $retries times.β cast bylogin(). login flopped, but it's gonna retry β$retriestimes total.Notice: folder $name does not exist!β cast bycurrentFolder(). that folder is not a thing. it's not there, periodt.Notice: selected IMAP4 folder $name.β cast bycurrentFolder(). you successfully selected$name. iconic, we love a working folder selection π.
π SEE ALSO π
this module is part of Mail-Box-IMAP4 version 4.01, built on December 13, 2025. if you wanna peek at the website, it's right here: http://perl.overmeer.net/CPAN/.
π LICENSE π
for all the contributors out there, check the file ChangeLog π.
this software is copyright (c) 2001-2025 by Mark Overmeer.
and here's the legal cutie patootie part: this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so yeah, go off, but respectfully π«Ά.
and that's the whole page, bestie!! this was perl v5.40.1, dated 2026-01-21, and it's the Mail::...:IMAP4(3pm) manual β you made it to the end, main character energy fr fr β¨ππ
π¦ where this page comes from
- ubuntu resolute: libmail-box-imap4-perl 4.01-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmail-box-imap4-perl 4.01-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms