table of contents
Mail::Transport::IMAP4(3pm) | User Contributed Perl Documentation | Mail::Transport::IMAP4(3pm) |
NAME¶
Mail::Transport::IMAP4 - proxy to Mail::IMAPClient
INHERITANCE¶
Mail::Transport::IMAP4 is a Mail::Transport::Receive is a Mail::Transport is a Mail::Reporter
SYNOPSIS¶
my $imap = Mail::Transport::IMAP4->new(...); my $message = $imap->receive($id); $imap->send($message);
DESCRIPTION¶
The IMAP4 protocol is quite complicated: it is feature rich and allowsverious asynchronous actions. The main document describing IMAP isrfc3501 (which obsoleted the original specification of protocol 4r1in rfc2060 in March 2003).
This package, as part of MailBox, does not implement the actualprotocol itself but uses Mail::IMAPClient to do the work. The taskfor this package is to hide as many differences between that module'sinterface and the common MailBox folder types. MultipleMail::Box::IMAP4 folders can share one Mail::Transport::IMAP4connection.
The Mail::IMAPClient module is the best IMAP4 implementation forPerl5, but is not maintained. There are many known problems with themodule, and solving those is outside the scope of MailBox. Seehttp://rt.cpan.org/Public/Dist/Display.html?Name=Mail-IMAPClient for all the reported bugs.
Extends "DESCRIPTION" in Mail::Transport::Receive.
METHODS¶
Extends "METHODS" in Mail::Transport::Receive.
- $obj->url()
- Represent this imap4 connection as URL.
Constructors¶
Extends "Constructors" in Mail::Transport::Receive.
- Mail::Transport::IMAP4->new(%options)
- Create the IMAP connection to the server. IMAP servers can handlemultiple
folders for a single user, which means that connectionsmay get shared.
This is sharing is hidden for the user.
When an "imap_client" is specified, then the options "hostname", "port", "username", and "password" are extracted from it.
-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 log Mail::Reporter 'WARNINGS' password Mail::Transport undef port Mail::Transport 143 proxy Mail::Transport undef retry Mail::Transport <false> starttls false timeout Mail::Transport 120 trace Mail::Reporter 'WARNINGS' username Mail::Transport undef via Mail::Transport 'imap'
- authenticate => TYPE|ARRAY
- Authenthication method to login(), which will be passed to Mail::IMAPClient subroutine authenticate. See the latter method for the available types. You may provide an ARRAY of types.
- domain => WINDOWS_DOMAIN
- Used for NTLM authentication.
- executable => FILENAME
- hostname => HOSTNAME|ARRAY
- imap_client => OBJECT|CLASS
- When an OBJECT is supplied, that client will be used for the
implementationof the IMAP4 protocol. Information about server and such are
extracted fromthe OBJECT to have the accessors to produce correct results.
The OBJECTshall be a Mail::IMAPClient.
When a CLASS is given, an object of that type is created for you. The createdobject can be retrieved via imapClient(), and than configured as defined by Mail::IMAPClient.
- interval => SECONDS
- log => LEVEL
- password => STRING
- port => INTEGER
- proxy => PATH
- retry => NUMBER|undef
- starttls => BOOLEAN
- tart Transport Security Layer (TLS).
- timeout => SECONDS
- trace => LEVEL
- username => STRING
- via => CLASS|NAME
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.
- $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
Attributes¶
- $obj->authentication( ['AUTO'|$type|$types] )
- Returns a LIST of ARRAYS, each describing one possible way to contactthe
server. Each pair contains a mechanism name and a challenge callback(which
may be "undef").
The settings are used by login() to get server access. The initial value origins from new(authenticate), but may be changed later.
Available basic $types are "CRAM-MD5", "NTLM", and "PLAIN". With "AUTO", all available types will be tried. When the Authen::NTLM is not installed, the "NTLM" option will silently be skipped. Be warned that, because of "PLAIN", erroneous username/password combinations will be passed readible as 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, $challange) = @$pair; ... }
- $obj->domain( [$domain] )
- Used in NTLM authentication to define the Windows domain which isaccessed. Initially set by new(domain) and defaults to theserver's name.
Exchanging Information¶
Protocol [internals]¶
The follow methods handle protocol internals, and should not be usedby a normal user of this class.
- $obj->appendMessage( $message, $foldername, [$date] )
- Write the message to the server.The optional DATA can be a RFC-822 date or a timestamp.
- $obj->createFolder($name)
- Add a folder.
- $obj->createImapClient($class, %options)
- Create an object of $class, which extends
Mail::IMAPClient.
All %options will be passed to the constructor (new) of $class.
- $obj->currentFolder( [$foldername] )
- Be sure that the specific FOLDER is the current one selected. If thefolder
is already selected, no IMAP traffic will be produced.
The boolean return value indicates whether the folder is selectable. Itwill return undef if it does not exist.
- $obj->deleteFolder($name)
- Remove one folder.
- $obj->destroyDeleted($folder)
- Command the server to delete for real all messages which are flagged tobe deleted.
- $obj->fetch(ARRAY-$of-$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. Whenthe 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.
- $obj->flagsToLabels($what|$flags)
- Mail::Transport::IMAP4->flagsToLabels($what|$flags)
- In SCALAR context, a hash with labels is returned. In LIST context,
pairsare returned.
The $what parameter can be 'SET', 'CLEAR', or 'REPLACE'. With the latter, all standard imap flags do not appear in the list will be ignored: their value may either by set or cleared. See getFlags()
Unknown flags in LIST are stripped from their backslash and lower-cased.For instance, '\SomeWeirdFlag' will become `someweirdflag => 1'.
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 headerfields are returned as list of Mail::Message::Field::Fast objects.When the name is "ALL", the whole header is returned.
- $obj->getFlags($folder, $id)
- Returns the values of all flags which are related to the message with
thespecified $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 providea 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.
- $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 instanceof a
Mail::IMAPClient, which is logged-in and ready to use.
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.
- $obj->labelsToFlags(HASH|PAIRS)
- Mail::Transport::IMAP4->labelsToFlags(HASH|PAIRS)
- Convert MailBox labels into IMAP flags. Returned is a string. Unsupportedlabels are ignored.
- $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.
Thevalue which can be related to the label will be lost, because IMAP
onlydefines a boolean value, where MailBox labels can contain strings.
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->addReport($object)
- Inherited, see "Error handling" in Mail::Reporter
- $obj->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level, $callback] )
- Mail::Transport::IMAP4->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level, $callback] )
- Inherited, see "Error handling" in Mail::Reporter
- $obj->errors()
- Inherited, see "Error handling" in Mail::Reporter
- $obj->log( [$level, [$strings]] )
- Mail::Transport::IMAP4->log( [$level, [$strings]] )
- Inherited, see "Error handling" in Mail::Reporter
- $obj->logPriority($level)
- Mail::Transport::IMAP4->logPriority($level)
- Inherited, see "Error handling" in Mail::Reporter
- $obj->logSettings()
- Inherited, see "Error handling" in Mail::Reporter
- $obj->notImplemented()
- Inherited, see "Error handling" in Mail::Reporter
- $obj->report( [$level] )
- Inherited, see "Error handling" in Mail::Reporter
- $obj->reportAll( [$level] )
- Inherited, see "Error handling" in Mail::Reporter
- $obj->trace( [$level] )
- Inherited, see "Error handling" in Mail::Reporter
- $obj->warnings()
- Inherited, see "Error handling" in Mail::Reporter
Cleanup¶
Extends "Cleanup" in Mail::Transport::Receive.
- $obj->DESTROY()
- The connection is cleanly terminated when the program isterminated.
DIAGNOSTICS¶
- Error: Cannot connect to $host:$port for IMAP4: $!
- Error: IMAP cannot connect to $host: $@
- Notice: IMAP4 authenication $mechanism to $host:$port successful
- Error: IMAP4 requires a username and password
- Error: IMAP4 username $username requires a password
- Error: Package $package does not implement $method.
- Fatal error: the specific package (or one of its superclasses) does notimplement this method where it should. This message means that some otherrelated classes do implement this method however the class at hand doesnot. Probably you should investigate this and probably inform the authorof the package.
SEE ALSO¶
This module is part of Mail-Box distribution version 2.120,built on September 21, 2016. Website: http://perl.overmeer.net/mailbox/
LICENSE¶
Copyrights 2001-2016 by [Mark Overmeer]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify itunder the same terms as Perl itself.See http://www.perl.com/perl/misc/Artistic.html
2016-12-27 | perl v5.24.1 |