Mail::IMAPClient - An IMAP Client API use Mail::IMAPClient; my $imap = Mail::IMAPClient->new( Server => 'imaphost', User => 'memememe', Password => 'secret', ); $imap->Debug($opt_d); my @folders = $imap->folders; foreach my $f (@folders) { print "$f is a folder with ", $imap->message_count($f), " messages.\n"; } This module provides methods implementing the IMAP protocol. It allows perl scripts to interact with IMAP message stores. The module is used by constructing or instantiating a new IMAPClient object via the new constructor method. Once the object has been instantiated, the connect method is either implicitly or explicitly called. At that point methods are available that implement the IMAP client commands as specified in RFC2060. When processing is complete, the logoff object method is called, either explicitly by the program or implicitly when the object goes out of scope (or at program termination). This documentation is not meant to be a replacement for RFC2060, and the wily programmer will have a copy of that document handy when coding IMAP clients. Note that this documentation uses the term folder in place of RFC2060's use of mailbox. This documentation reserves the use of the term mailbox to refer to the set of folders owned by a specific IMAP id. RFC2060 defines four possible states for an IMAP connection: not authenticated, authenticated, selected, and logged out. These correspond to the IMAPClient constants Connected, Authenticated, Selected, and Unconnected, respectively. These constants are implemented as class methods, and can be used in conjunction with the Status method to determine the status of an IMAPClient object and its underlying IMAP session. Note that an IMAPClient object can be in the Unconnected state both before a server connection is made and after it has ended. This differs slightly from RFC2060, which does not define a pre-connection status. For a discussion of the methods available for examining the IMAPClient object's status, see the section labeled "Status Methods", below.

Errors
If you attempt an operation that results in an error, then you can retrieve the text of the error message by using the LastError method. However, since the LastError method is an object method (and not a class method) you will only be able to use this method if you've successfully created your object. Errors in the new method can prevent your object from ever being created. Additionally, if you supply the Server, User, and Password parameters to new, it will attempt to call connect and login, either of which could fail and cause your new method call to return undef (in which case your object will have been created but its reference will have been discarded before ever being returned to you). If this happens to you, you can always check `$@'. Mail::IMAPClient will populate that variable with something useful if either of the new, connect, or login methods fail. In fact, as of version 2, the `$@' variable will always contain error info from the last error, so you can print that instead of calling LastError if you wish. If you run your script with warnings turned on (which I'm sure you'll do at some point because it's such a good idea) then any error message that gets placed into the LastError slot (and/or in `$@') will automatically generate a warning.

Transactions
RFC2060 requires that each line in an IMAP conversation be prefixed with a tag. A typical conversation consists of the client issuing a tag-prefixed command string, and the server replying with one of more lines of output. Those lines of output will include a command completion status code prefixed by the same tag as the original command string. The IMAPClient module uses a simple counter to ensure that each client command is issued with a unique tag value. This tag value is referred to by the IMAPClient module as the transaction number. A history is maintained by the IMAPClient object documenting each transaction. The Transaction method returns the number of the last transaction, and can be used to retrieve lines of text from the object's history. The Clear parameter is used to control the size of the session history so that long-running sessions do not eat up unreasonable amounts of memory. See the discussion of Clear under the section on "parameters" for more information. The Report transaction returns the history of the entire IMAP session since the initial connection or for the last Clear transactions. This provides a record of the entire conversation, including client command strings and server responses, and is a wonderful debugging tool as well as a useful source of raw data for custom parsing.

Class Methods
There are a couple of methods that can be invoked as class methods. Generally they can be invoked as an object method as well, as a convenience to the programmer. (That is, as a convenience to the programmer who wrote this module, as well as the programmers using it. It's easier not to enforce a class method's classiness.) Note that if the new method is called as an object method, the object returned is identical to what have would been returned if new had been called as a class method. It doesn't give you a copy of the original object or anything like that. The new method creates a new instance of an IMAPClient object. If the Server parameter is passed as an argument to new, then new will implicitly call the connect method, placing the new object in the Connected state. If User and Password values are also provided, then connect will in turn call login, and the resulting object will be returned from new in the Authenticated state. If the Server parameter is not supplied then the IMAPClient object is created in the Unconnected state. If the new method is passed arguments then those arguments will be treated as a list of key=>value pairs. The key should be one of the parameters as documented under the section on "parameters", below. Here are some examples: use Mail::IMAPClient; my $imap = Mail::IMAPClient->new; # returns an unconnected Mail::IMAPClient object # ... # intervening code using the 1st object, then: $imap = Mail::IMAPClient->new( # returns a new, authenticated Mail::IMAPClient object Server => $host, User => $id, Password=> $pass, Clear => 5, # Unnecessary since '5' is the default # ... # Other key=>value pairs go here ) or die "Cannot connect to $host as $id: $@"; See also the section on "parameters", below, and the section on "connect" and the section on "login" for information on how to manually connect and login after new. returns a value equal to the numerical value associated with an object in the Unconnected state. returns a value equal to the numerical value associated with an object in the Connected state. returns a value equal to the numerical value associated with an object in the Authenticated state. returns a value equal to the numerical value associated with an object in the Selected state. The Strip_cr method strips carriage returns from IMAP client command output. Although RFC2060 specifies that lines in an IMAP conversation end with <CR><LF>, it is often cumbersome to have the carriage returns in the returned data. This method accepts one or more lines of text as arguments, and returns those lines with all <CR><LF> sequences changed to <LF>. Any input argument with no carriage returns is returned unchanged. If the first argument (not counting the class name or object reference) is an array reference, then members of that array are processed as above and subsequent arguments are ignored. If the method is called in scalar context then an array reference is returned instead of an array of results. Taken together, these last two lines mean that you can do something like: my @list = $imap->some_imap_method ; @list = $imap->Strip_cr(@list) ; # or: my $list = [ $imap->some_imap_method ] ; # returns an array ref $list = $imap->Strip_cr($list); NOTE: Strip_cr does not remove new line characters. The Rfc2060_date method accepts one input argument, a number of seconds since the epoch date. It returns an RFC2060 compliant date string for that date (as required in date-related arguments to SEARCH, such as "since", "before", etc.). The Rfc822_date method accepts one input argument, a number of seconds since the epoch date. It returns an RFC822 compliant date string for that date (without the 'Date:' prefix). Useful for putting dates in message strings before calling append.

Parameters
There are several parameters that influence the behavior of an IMAPClient object. Each is set by specifying a named value pair during new method invocation as follows: my $imap = Mail::IMAPClient->new ( parameter => "value", parameter2 => "value", ... ); Parameters can also be set after an object has been instantiated by using the parameter's eponymous accessor method like this: my $imap = Mail::IMAPClient->new; $imap->parameter( "value"); $imap->parameter2("value"); The eponymous accessor methods can also be used without arguments to obtain the current value of the parameter as follows: my $imap = Mail::IMAPClient->new; $imap->parameter( "value"); $imap->parameter2("value"); ... # A whole bunch of awesome perl code, # omitted for brevity my $forgot = $imap->parameter; my $forgot2 = $imap->parameter2; Note that in these examples I'm using 'parameter' and 'parameter2' as generic parameter names. The IMAPClient object doesn't actually have parameters named 'parameter' and 'parameter2'. On the contrary, the available parameters are: The Buffer parameter sets the size of a block of I/O. It is ignored unless Fast_io, below, is set to a true value. It's value should be the number of bytes to attempt to read in one I/O operation. The default value is 4096. The name of this parameter, for historical reasons, is somewhat misleading. It should be named Wrap, because it specifies how many transactions are stored in the wrapped history buffer. But it didn't always work that way; the buffer used to actually get cleared. The name though remains the same in the interests of backwards compatibility. Clear specifies that the object's history buffer should be wrapped after every n transactions, where n is the value specified for the Clear parameter. Calling the eponymous Clear method without an argument will return the current value of the Clear parameter but will not cause clear the history buffer to wrap. Setting Clear to 0 turns off automatic history buffer wrapping, and setting it to 1 turns off the history buffer facility (except for the last transaction, which cannot be disabled without breaking the IMAPClient module). Setting Clear to 0 will not cause an immediate clearing of the history buffer; setting it to 1 (or any other number) will (except of course for that inevitable last transaction). The default Clear value is set to five in order to conserve memory. Sets the debugging flag to either a true or false value. Can be supplied with the new method call or separately by calling the Debug object method. Use of this parameter is strongly recommended when debugging scripts and required when reporting bugs. Specifies the filehandle to which debugging information should be printed. It can either a filehandle object reference or a filehandle glob. The default is to print debugging info to STDERR. For example, you can: use Mail::IMAPClient; use IO::File; # set $user, $pass, and $server here my $dh = IO::File->new(">debugging.output") or die "Can't open debugging.output: $!\n"; my $imap = Mail::IMAPClient->new( User=>$user, Password=>$pass, Server=>$server, Debug=> "yes, please", Debug_fh => $dh ); Or you can: use Mail::IMAPClient; # set $user, $pass, and $server here open(DBG,">debugging.output") or die "Can't open debugging.output: $!\n"; my $imap = Mail::IMAPClient->new( User=>$user, Password=>$pass, Server=>$server, Debug=> 1, Debug_fh => *DBG ); The Folder parameter returns the name of the currently-selected folder (in case you forgot). It can also be used to set the name of the currently selected folder, which is completely unnecessary if you used the select method (or select's read-only equivalent, the examine method) to select it. Note that setting the Folder parameter does not automatically select a new folder; you use the select or examine object methods for that. Generally, the Folder parameter should only be queried (by using the no-argument form of the Folder method). You will only need to set the Folder parameter if you use some mysterious technique of your own for selecting a folder, which you probably won't do. The MaxTempErrors parameter specifies the number of times a write operation is allowed to fail on a "Resource Temporarily Available" error. These errors can occur from time to time if the server is too busy to empty out its read buffer (which is logically the "other end" of the client's write buffer). By default, Mail::IMAPClient will retry 10 times, but you can adjust this behavior by setting MaxTempErrors. Note that after each temporary error, the server will wait for a number of seconds equal to the number of consecutive temporary errors times .25, so very high values for MaxTempErrors can slow you down in a big way if your "temporary error" is not all that temporary. Generally you won't have to set this value, unless you are doing very large appends on a relatively small, slow, or busy server. Specifies the password to use when logging into the IMAP service on the host specified in the Server parameter as the user specified in the User parameter. Can be supplied with the new method call or separately by calling the Password object method. If Server, User, and Password are all provided to the new method, then the newly instantiated object will be connected to the host specified in Server (at either the port specified in Port or the default port 143) and then logged on as the user specified in the User parameter (using the password provided in the Password parameter). See the discussion of the new method, below. Setting Peek to a true value will prevent the body_string, message_string and message_to_file methods from automatically setting the \Seen flag. Setting Peek to 0 (zero) will force body_string, message_string, message_to_file, and parse_headers to always set the \Seen flag. The default is to set the seen flag whenever you fetch the body of a message but not when you just fetch the headers. Passing undef to the eponymous Peek method will reset the Peek parameter to its pristine, default state. Specifies the port on which the IMAP server is listening. The default is 143, which is the standard IMAP port. Can be supplied with the new method call or separately by calling the Port object method. Specifies the hostname or IP address of the host running the IMAP server. If provided as part of the new method call, then the new IMAP object will automatically be connected at the time of instantiation. (See the new method, below.) Can be supplied with the new method call or separately by calling the Server object method. The Socket method can be used to obtain the socket handle of the current connection (say, to do I/O on the connection that is not otherwise supported by Mail::IMAPClient) or to replace the current socket with a new handle (perhaps an SSL handle, for example). If you supply a socket handle yourself, either by doing something like: $imap=Mail::IMAPClient->new(Socket=>$sock, User => ... ); or by doing something like: $imap=Mail::IMAPClient->new(User => $user, Password => $pass, Server => $host); # blah blah blah $imap->Socket($ssl); then it will be up to you to establish the connection AND to authenticate, either via the login method, or the fancier authenticate, or, since you know so much anyway, by just doing raw I/O against the socket until you're logged in. If you do any of this then you should also set the State parameter yourself to reflect the current state of the object (i.e. Connected, Authenticated, etc). Specifies the timeout value in seconds for reads. Specifying a true value for Timeout will prevent Mail::IMAPClient from blocking in a read. Since timeouts are implemented via the perl select operator, the Timeout parameter may be set to a fractional number of seconds. Not supplying a Timeout, or (re)setting it to zero, disables the timeout feature. If Uid is set to a true value (i.e. 1) then the behavior of the fetch, search, copy, and store methods (and their derivatives) is changed so that arguments that would otherwise be message sequence numbers are treated as message UID's and so that return values (in the case of the search method and its derivatives) that would normally be message sequence numbers are instead message UID's. Internally this is implemented as a switch that, if turned on, causes methods that would otherwise issue an IMAP FETCH, STORE, SEARCH, or COPY client command to instead issue UID FETCH, UID STORE, UID SEARCH, or UID COPY, respectively. The main difference between message sequence numbers and message UID's is that, according to RFC2060, UID's must not change during a session and should not change between sessions, and must never be reused. Sequence numbers do not have that same guarantee and in fact may be reused right away. Since foldernames also have a unique identifier (UIDVALIDITY), which is provided when the folder is selected or examined or by doing something like "$imap->status($folder,"UIDVALIDITY"), it is possible to uniquely identify every message on the server, although normally you won't need to bother. The methods currently affected by turning on the Uid flag are: copy fetch search store message_string message_uid body_string flags move size parse_headers Note that if for some reason you only want the Uid parameter turned on for one command, then you can choose between the following two snippets, which are equivalent: Example 1: $imap->Uid(1); my @uids = $imap->search('SUBJECT',"Just a silly test"); # $imap->Uid(0); Example 2: my @uids; foreach $r ($imap->UID("SEARCH","SUBJECT","Just a silly test") { chomp $r; $r =~ s/\r$//; $r =~ s/^\*\s+SEARCH\s+// or next; push @uids, grep(/\d/,(split(/\s+/,$r))); } In the second example, we used the default method to issue the UID IMAP Client command, being careful to use an all-uppercase method name so as not to inadvertently call the Uid accessor method. Then we parsed out the message UIDs manually, since we don't have the benefit of the built-in search method doing it for us. Please be very careful when turning the Uid parameter on and off throughout a script. If you loose track of whether you've got the Uid parameter turned on you might do something sad, like deleting the wrong message. Remember, like all eponymous accessor methods, the Uid method without arguments will return the current value for the Uid parameter, so do yourself a favor and check. The safest approach is probably to turn it on at the beginning and then leave it on. (Remember that leaving it turned off can lead to problems if changes to a folder's contents cause resequencing.) By default, the Uid parameter is turned on. Specifies the userid to use when logging into the IMAP service. Can be supplied with the new method call or separately by calling the User object method. Parameters can be set during new method invocation by passing named parameter/value pairs to the method, or later by calling the parameter's eponymous object method.

Object Methods
Object methods must be invoked against objects created via the new method. They cannot be invoked as class methods, which is why they are "object methods" and not "class methods". There are basically two types of object methods--those that participate in the IMAP session's conversation (i.e. they issue IMAP client commands) and those that do not. Methods that do not result in new IMAP client commands being issued (such as the Transaction, Status, and History methods) all begin with an uppercase letter, to distinguish themselves from methods that do correspond to IMAP client commands. (Class methods and eponymous parameter methods likewise begin with an uppercase letter because they also do not correspond to an IMAP client command.) The IMAPClient object methods are: The append method adds a message to the specified folder. It takes two arguments, the name of the folder to append the message to, and the text of the message (including headers). Additional arguments are added to the message text, separated with <CR><LF>. The append method returns the UID of the new message (a true value) if successful, or undef if not, if the IMAP server has the UIDPLUS capability. If it doesn't then you just get true on success and undef on failure. Note that many servers will get really ticked off if you try to append a message that contains "bare newlines", which is the titillating term given to newlines that are not preceded by a carrage return. To protect against this, append will insert a carrage return before any newline that is "bare". If you don't like this behavior then you can avoid it by not passing naked newlines to append. The append_file method adds a message to the specified folder. It takes two arguments, the name of the folder to append the message to, and the file name of an RFC822-formatted message. An optional third argument is the value to use for `input_record_separator'. The default is to use "" for the first read (to get the headers) and "\n" for the rest. Any valid value for `$/' is acceptable, even the funky stuff, like `\1024'. (See the perlvar manpage for more information on `$/'). The append_file method returns the UID of the new message (a true value) if successful, or undef if not, if the IMAP server has the UIDPLUS capability. If it doesn't then you just get true on success and undef on failure. If you supply a filename that doesn't exist then you get an automatic undef. The LastError method will remind you of this if you forget that your file doesn't exist but somehow manage to remember to check LastError. In case you're wondering, append_file is provided mostly as a way to allow large messages to be appended without having to have the whole file in memory. It uses the `-s' operator to obtain the size of the file and then reads and sends the contents line by line (or not, depending on whether you supplied that optional third argument). The authenticate method accepts two arguments, an authentication type to be used (ie CRAM-MD5) and a code or subroutine reference to execute to obtain a response. The authenticate assumes that the authentication type specified in the first argument follows a challenge-response flow. The authenticate method issues the IMAP Client AUTHENTICATE command and receives a challenge from the server. That challenge (minus any tag prefix or enclosing '+' characters but still in the original base64 encoding) is passed as the only argument to the code or subroutine referenced in the second argument. The return value from the 2nd argument's code is written to the server as is, except that a <CR><NL> sequence is appended if neccessary. The before method works just like the the section on "since" method, below, except it returns a list of messages whose internal system dates are before the date supplied as the argument to the before method. The body_string method accepts a message sequence number (or a message UID, if the Uid parameter is set to true) as an argument and returns the message body as a string. The returned value contains the entire message in one scalar variable, without the message headers. The capability method returns an array of capabilities as returned by the CAPABILITY IMAP Client command, or a reference to an array of capabilities if called in scalar context. If the CAPABILITY IMAP Client command fails for any reason then the capability method will return undef. The close method is implemented via the default method and is used to close the currently selected folder via the CLOSE IMAP client command. According to RFC2060, the CLOSE command performs an implicit EXPUNGE, which means that any messages that you've flagged as \Deleted (say, with the delete_message method) will now be deleted. If you haven't deleted any messages then close can be thought of as an "unselect". See also delete_message, expunge, and your tattered copy of RFC2060. The connect method connects an imap object to the server. It returns `undef' if it fails to connect for any reason. If values are available for the User and Password parameters at the time that connect is invoked, then connect will call the login method after connecting and return the result of the login method to connect's caller. If either or both of the User and Password parameters are unavailable but the connection to the server succeeds then connect returns a pointer to the IMAPClient object. The Server parameter must be set (either during new method invocation or via the Server object method) before invoking connect. If the Server parameter is supplied to the new method then connect is implicitly called during object construction. The connect method sets the state of the object to connected if it successfully connects to the server. The copy method requires a folder name as the first argument, and a list of one or more messages sequence numbers (or messages UID's, if the UID parameter is set to a true value). The message sequence numbers or UID's should refer to messages in the currenly selected folder. Those messages will be copied into the folder named in the first argument. The copy method returns undef on failure and a true value if successful. If the server to which the current Mail::IMAPClient object is connected supports the UIDPLUS capability then the true value returned by copy will be a comma separated list of UID's, which are the UID's of the newly copied messages in the target folder. The create method accepts one argument, the name of a folder (or what RFC2060 calls a "mailbox") to create. If you specifiy additional arguments to the create method and your server allows additional arguments to the CREATE IMAP client command then the extra argument(s) will be passed to your server. If you specifiy additional arguments to the create method and your server does not allow additional arguments to the CREATE IMAP client command then the extra argument(s) will still be passed to your server and the create will fail, so don't do that. create returns a true value on success and undef on failure, as you've probably guessed. The delete method accepts a single argument, the name of a folder to delete. It returns a true value on success and undef on failure. The delete_message method accepts a list of arguments. If the Uid parameter is not set to a true value, then each item in the list should be either: If the Uid parameter is set to a true value, then each item in the list should be either: The messages identified by the sequence numbers or UID's will be deleted. delete_message returns the number of messages it was told to delete. However, since the delete is done by issuing the +FLAGS.SILENT option of the STORE IMAP client command, there is no guarantee that the delete was successful for every message. In this manner the delete_message method sacrifices accuracy for speed. If you must have guaranteed results then use the IMAP STORE client command (via the default method) and use the +FLAGS (\Deleted) option, and then parse your results manually. Eg: $imap->store($msg_id,'+FLAGS (\Deleted)'); my @results = $imap->History($imap->Transaction); ... # code to parse output goes here The IMAPClient object must be in Selected status to use the delete_message method. NOTE: All the messages identified in the input argument(s) must be in the currently selected folder. Failure to comply to this requirement will almost certainly result in the wrong message(s) being deleted. This would be a crying shame. NOTE SOME MORE: In the grand tradition of the IMAP protocol, deleting a message doesn't actually delete the message. Really. If you want to make sure the message has been deleted, you need to expunge the folder (via the expunge method, which is implemented via the default method). Or at least close it. This is generally considered a feature, since after deleting a message, you can change your mind and undelete it at any time before your expunge or close. See also: The delete method, to delete a folder, the expunge method, to expunge a folder, the restore_message method to undelete a message, and the close method (implemented here via the default method) to close a folder. Oh, and don't forget about RFC2060. The deny_seeing method accepts a list of one or more message sequence numbers, or a single reference to an array of one or more message sequence numbers, as its argument(s). It then unsets the "\Seen" flag for those messages. Of course, if the Uid parameter is set to a true value then those message sequence numbers had better be unique message id's. didn't you? Note that specifying `$imap-'deny_seeing(@msgs)> is just a shortcut for specifying `$imap-'unset_flag("Seen",@msgs)>. Disconnects the IMAPClient object from the server. Functionally equivalent to the logout method. The examine method selects a folder in read-only mode and changes the object's state to "Selected". The folder selected via the examine method can be examined but no changes can be made unless it is first selected via the select method. The examine method accepts one argument, which is the name of the folder to select. Accepts one argument, a folder name. Returns true if the folder exists or false if it does not exist. The expunge method accepts one optional argument, a folder name. It expunges the folder specified as the argument, or the currently selected folder if no argument is supplied. Although RFC2060 does not permit optional arguments (like a folder name) to the EXPUNGE client command, the expunge method does, which is especially interesting given that the expunge method doesn't technically exist. In case you're curious, expunging a folder deletes the messages that you thought were already deleted via delete_message but really weren't, which means you have to use a method that doesn't exist to delete messages that you thought didn't exist. (Seriously, I'm not making any of this stuff up.) Or you could use the close method, which de-selects as well as expunges and which likewise doesn't technically exist. As with any IMAP client command, that fact that these methods don't exist will not stop them from working anyway. This is a feature of the Mail::IMAPClient module. (See the section on "Other IMAP Client Commands and the Default Method" if you still don't believe me.) The fetch method implements the FETCH IMAP client command. It accepts a list of arguments, which will be converted into a space-delimited list of arguments to the FETCH IMAP client command. If no arguments are supplied then fetch does a FETCH ALL. If the Uid parameter is set to a true value then the first argument will be treated as a UID or list of UID's, which means that the UID FETCH IMAP client command will be run instead of FETCH. (It would really be a good idea at this point to review RFC2060.) If called in array context, fetch will return an array of output lines. The output lines will be returned just as they were received from the server, so your script will have to be prepared to parse out the bits you want. The only exception to this is literal strings, which will be inserted into the output line at the point at which they were encountered (without the {nnn} literal field indicator). See RFC2060 for a description of literal fields, and don't blame me if you're still confused by them. (I read that rfc just about every day and didn't really understand those literal fields for about a year.) If fetch is called in a scalar context, then a reference to an array (as described above) is returned instead of the entire array. The flags method implements the FETCH IMAP client command to list a single message's flags. It accepts one argument, a message sequence number (or a message UID, if the Uid parameter is true), and returns an array (or a reference to an array, if called in scalar context) listing the flags that have been set. Flag names are provided with leading backslashes. As of version 1.11, you can supply either a list of message id's or a reference to an array of of message id's (which means either sequence number, if the Uid parameter is false, or message UID's, if the Uid parameter is true) instead of supplying a single message sequence number or UID. If you do, then the return value will not be an array or array reference; instead, it will be a hash reference, with each key being a message sequence number (or UID) and each value being a reference to an array of flags set for that message. For example, if you want to display the flags for every message in the folder where you store e-mail related to your plans for world domination, you could do something like this: use Mail::IMAPClient; my $imap = Mail::IMAPClient->new( Server => $imaphost, User => $login, Password=> $pass, Uid => 1, # optional ); $imap->select("World Domination"); # get the flags for every message in my 'World Domination' folder $flaghash = $imap->flags( scalar($imap->search("ALL"))) ; # pump through sorted hash keys to print results: for my $k (sort { $flaghash->{$a} <=> $flaghash->{$b} } keys %$flaghash) { # print: Message 1: \Flag1, \Flag2, \Flag3 print "Message $k:\t",join(", ",@{$flaghash->{$k}}),"\n"; } The folders method returns an array listing the available folders. It will only be successful if the object is in the Authenticated or Selected states. Returns true if the IMAP server to which the IMAPClient object is connected has the capability specified as an argument to has_capability. Returns true if the IMAP server to which the IMAPClient object is connected has the IMAP4REV1 capability. internaldate accepts one argument, a message id (or UID if the Uid parameter is true), and returns that message's internal date. getacl accepts one argument, the name of a folder. If no argument is provided then the currently selected folder is used as the default. It returns a reference to a hash. The keys of the hash are userids that have access to the folder, and the value of each element are the permissions for that user. The permissions are listed in a string in the order returned from the server with no whitespace or punctuation between them. The is_parent method accepts one argument, the name of a folder. It returns a value that indicates whether or not the folder has children. The value it returns is either 1) a true value (indicating that the folder has children), 2) 0 if the folder has no children at this time, or 3) undef if the folder is not permitted to have children. Eg: my $parenthood = $imap->is_parent($folder); if (defined($parenthood)) { if ($parenthood) { print "$folder has children.\n" ; } else { print "$folder is permitted children, but has none.\n"; } } else { print "$folder is not permitted to have children.\n"; } The list method implements the IMAP LIST client command. Arguments are passed to the IMAP server as received, separated from each other by spaces. If no arguments are supplied then the default list command `tag LIST "" '*'' is issued. The list method returns an array (or an array reference, if called in a scalar context). The array is the unaltered output of the LIST command. (If you want your output altered then see the folders method, above.) The listrights method implements the IMAP LISTRIGHTS client command (the RFC2086 manpage). The login method uses the IMAP LOGIN client command (as defined in RFC2060) to log into the server. The User and Password parameters must be set before the login method can be invoked. If successful, the login method returns a pointer to the IMAPClient object and sets the object status to Authenticated. If unsuccessful, it returns undef. The logout method issues the LOGOUT IMAP client commmand. Since the LOGOUT IMAP client command causes the server to end the connection, this also results in the IMAPClient client entering the Unconnected state. This method does not, however, destroy the IMAPClient object, so a program can re-invoke the connect and login methods if it wishes to reestablish a session later in the program. The lsub method implements the IMAP LSUB client command. Arguments are passed to the IMAP server as received, separated from each other by spaces. If no arguments are supplied then the default lsub command `tag LSUB "" '*'' is issued. The lsub method returns an array (or an array reference, if called in a scalar context). The array is the unaltered output of the LSUB command. If you want an array of subscribed folders then see the subscribed method, below. The mark method accepts a list of one or more messages sequence numbers, or a single reference to an array of one or more message sequence numbers, as its argument(s). It then sets the "\Flagged" flag for those message(s). Of course, if the Uid parameter is set to a true value then those message sequence numbers had better be unique message id's. Note that specifying `$imap-'see(@msgs)> is just a shortcut for specifying `$imap-'set_flag("Flagged",@msgs)>. The message_count method accepts the name of a folder as an argument and returns the number of messages in that folder. Internally, it invokes the status method (see above) and parses out the results to obtain the number of messages. If you don't supply an argument to message_count then it will return the number of messages in the currently selected folder (assuming of course that you've used the select or examine method to select it instead of trying something funky). The message_string method accepts a message sequence number (or message UID if Uid is true) as an argument and returns the message as a string. The returned value contains the entire message in one scalar variable, including the message headers. Note that using this method will set the message's "\Seen" flag as a side effect, unless Peek is set to a true value. The message_to_file method accepts a filename or file handle and one or more message sequence numbers (or message UIDs if Uid is true) as arguments and places the message string(s) (including RFC822 headers) into the file named in the first argument (or prints them to the filehandle, if a filehandle is passed). The returned value is true on succes and undef on failure. If the first argument is a reference, it is assumed to be an open filehandle and will not be closed when the method completes, If it is a file, it is opened in append mode, written to, then closed. Note that using this method will set the message's "\Seen" flag as a side effect. But you can use the deny_seeing method to set it back, or set the Peek parameter to a true value to prevent setting the "\Seen" flag at all. This method currently works by making some basic assumptions about the server's behavior, notably that the message text will be returned as a literal string but that nothing else will be. If you have a better idea then I'd like to hear it. The message_uid method accepts a message sequence number (or message UID if Uid is true) as an argument and returns the message's UID. Yes, if Uid is true then it will use the IMAP UID FETCH UID client command to obtain and return the very same argument you supplied. This is an IMAP feature so don't complain to me about it. The move method moves messages from the currently selected folder to the folder specified in the first argument to move. If the Uid parameter is not true, then the rest of the arguments should be either: If the Uid parameter is true, then the arguments should be: If the target folder does not exist then it will be created. If move is sucessful, then it returns a true value. Furthermore, if the Mail::IMAPClient object is connected to a server that has the UIDPLUS capability, then the true value will be the comma-separated list of UID's for the newly copied messages. The list will be in the order in which the messages were moved. (Since move uses the copy method, the messages will be moved in numerical order.) If the move is not successful then move returns undef. Note that a move really just involves copying the message to the new folder and then setting the \Deleted flag. To actually delete the original message you will need to run expunge (or close). The namespace method runs the NAMESPACE IMAP command (as defined in RFC 2342). When called in a list context, it returns a list of three references. Each reference looks like this: [ [ $prefix_1, $separator_1 ] , [ $prefix_2, $separator_2], [ $prefix_n , $separator_n] ] The first reference provides a list of prefices and separator charactors for the available personal namespaces. The second reference provides a list of prefices and separator charactors for the available shared namespaces. The third reference provides a list of prefices and separator charactors for the available public namespaces. If any of the three namespaces are unavailable on the current server then an 'undef' is returned instead of a reference. So for example if shared folders were not supported on the server but personal and public namespaces were both available (with one namespace each), the returned value might resemble this: ( [ "", "/" ] , undef, [ "#news", "." ] ) ; If the namespace method is called in scalar context, it returns a reference to the above-mentioned list of three references, thus creating a single structure that would pretty-print something like this: $VAR1 = [ [ [ $user_prefix_1, $user_separator_1 ] , [ $user_prefix_2, $user_separator_2], [ $user_prefix_n , $user_separator_n] ] , # or undef [ [ $shared_prefix_1, $shared_separator_1 ] , [ $shared_prefix_2, $shared_separator_2], [ $shared_prefix_n , $shared_separator_n] ] , # or undef [ [ $public_prefix_1, $public_separator_1 ] , [ $public_prefix_2, $public_separator_2], [ $public_prefix_n , $public_separator_n] ] , # or undef ]; Or, to look at our previous example (where shared folders are unsupported) called in scalar context: $VAR1 = [ [ [ "" , "/", ], ], undef, [ [ "#news", "." ], ], ]; The on method works just like the since method, below, except it returns a list of messages whose internal system dates are the same as the date supplied as the argument. The parse_headers method accepts as arguments a message sequence number and a list of header fields. It returns a hash reference in which the keys are the header field names (without the colon) and the values are references to arrays of values. A picture would look something like this: $hashref = $imap->parse_headers(1,"Date","Received","Subject","To"); $hashref = { "Date" => [ "Thu, 09 Sep 1999 09:49:04 -0400" ] , "Received" => [ q/ from mailhub ([111.11.111.111]) by mailhost.bigco.com (Netscape Messaging Server 3.6) with ESMTP id AAA527D for <bigshot@bigco.com>; Fri, 18 Jun 1999 16:29:07 +0000 /, q/ from directory-daemon by mailhub.bigco.com (PMDF V5.2-31 #38473) id <0FDJ0010174HF7@mailhub.bigco.com> for bigshot@bigco.com (ORCPT rfc822;big.shot@bigco.com); Fri, 18 Jun 1999 16:29:05 +0000 (GMT) /, q/ from someplace ([999.9.99.99]) by smtp-relay.bigco.com (PMDF V5.2-31 #38473) with ESMTP id <0FDJ0000P74H0W@smtp-relay.bigco.com> for big.shot@bigco.com; Fri, 18 Jun 1999 16:29:05 +0000 (GMT) /] , "Subject" => [ qw/ Help! I've fallen and I can't get up!/ ] , "To" => [ "Big Shot <big.shot@bigco.com> ] , } ; The text in the example for the "Received" array has been formated to make reading the example easier. The actual values returned are just strings of words separated by spaces and with newlines and carriage returns stripped off. The Received header is probably the main reason that the parse_headers method creates a hash of lists rather than a hash of values. If the second argument to parse_headers is 'ALL' or if it is unspecified then all available headers are included in the returned hash of lists. If you're not emotionally prepared to deal with a hash of lists then you can always call the fetch method yourself with the appropriate parameters and parse the data out any way you want to. If the Uid parameter is true then the first argument will be treated as a message UID. If the first argument is a reference to an array of message sequence numbers (or UID's if Uid is true), then parse_headers will be run against each message in the array. In this case the return value is a hash, in which the key is the message sequence number (or UID) and the value is a reference to a hash as described above. An example of using parse_headers to print the date and subject of every message in your smut folder could look like this: use Mail::IMAPClient; my $imap = Mail::IMAPClient->new( Server => $imaphost, User => $login, Password=> $pass, Uid => 1, # optional ); $imap->select("smut"); for my $h ( # grab the Subject and Date from every message in my (fictional!) smut folder; # the first argument is a reference to an array listing all messages in the folder # (which is what gets returned by the $imap->search("ALL") method when called in # scalar context) and the remaining arguments are the fields to parse out # The key is the message number, which in this case we don't care about: values %{$imap->parse_headers( scalar($imap->search("ALL")) , "Subject", "Date")} ) { # $h is the value of each element in the hash ref returned from parse_headers, # and $h is also a reference to a hash. # We'll only print the first occurance of each field because we don't expect more # than one Date: or Subject: line per message. print map { "$_:\t$h->{$_}[0]\n"} keys %$h ; } The recent method performs an IMAP SEARCH RECENT search against the selected folder and returns an array of sequence numbers (or UID's, if the Uid parameter is true) of messages that are recent. The recent_count method accepts as an argument a folder name. It returns the number of recent messages in the folder (as returned by the IMAP client command "STATUS folder RECENT"), or undef in the case of an error. The recent_count method was contributed by Rob Deker (deker@ikimbo.com). The rename method accepts two arguments: the name of an existing folder, and a new name for the folder. The existing folder will be renamed to the new name using the RENAME IMAP client command. rename will return a true value if successful, or undef if unsuccessful. The restore_message method is used to undo a previous delete_message operation (but not if there has been an intervening expunge or close). The IMAPClient object must be in Selected status to use the restore_message method. The restore_message method accepts a list of arguments. If the Uid parameter is not set to a true value, then each item in the list should be either: If the Uid parameter is set to a true value, then each item in the list should be either: The messages identified by the sequence numbers or UID's will have their \Deleted flags cleared, effectively "undeleting" the messages. restore_message returns the number of messages it was able to restore. Note that restore_messages is similar to calling unset_flag("\Deleted",@msgs), except that restore_messages returns a more meaningful value. Like Perl itself, the Mail::IMAPClient module is designed to make common things easy and uncommon things possible. The run method is provided to make those uncommon things possible. The run method excepts one or two arguments. The first argument is a string containing an IMAP Client command, including a tag and all required arguments. The optional second argument is a string to look for that will indicate success. (The default is `/OK.*/'). The run method returns an array of output lines from the command, which you are free to parse as you see fit. The run method does not do any syntax checking, other than rudimentary checking for a tag. When run processes the command, it increments the transaction count and saves the command and responses in the History buffer in the same way other commands do. However, it also creates a special entry in the History buffer named after the tag supplied in the string passed as the first argument. If you supply a numeric value as the tag then you may risk overwriting a previous transaction's entry in the History buffer. If you want the control of run but you don't want to worry about the damn tags then see the section on "tag_and_run", below. The search method implements the SEARCH IMAP client command. Any argument supplied to search is prefixed with a space and appended to the SEARCH IMAP client command. This method is another one of those situations where it will really help to have your copy of RFC2060 handy, since the SEARCH IMAP client command contains a plethora of options and possible arguments. I'm not going to repeat them here. Remember that if your argument needs quotes around it then you must make sure that the quotes will be preserved when passing the argument. I.e. use `qq/"$arg"/' instead of `"$arg"'. The search method returns an array containing sequence numbers of messages that passed the SEARCH IMAP client command's search criteria. If the Uid parameter is true then the array will contain message UID's. If search is called in scalar context then a pointer to the array will be passed, instead of the array itself. The sort method is just like the search method, only different. It implements the SORT extension as described in http://search.ietf.org/internet-drafts/draft-ietf-imapext-sort-06.txt. It would be wise to use the has_capability method to verify that the SORT capability is available on your server before trying to use the sort method. If you forget to check and you're connecting to a server that doesn't have the SORT capability then sort will return undef. LastError will then say you are "BAD". If your server doesn't support the SORT capability then you'll have to use search and then sort the results yourself. The first argument to sort is a space-delimited list of sorting criteria. The Internet Draft that describes SORT requires that this list be wrapped in parentheses, even if there is only one sort criterion. If you forget the parentheses then the sort method will add them. But you have to forget both of them, or none. I'm not CMS running under VM! The second argument is a character set to use for sorting. Different character sets use different sorting orders, so this argument is important. Since all servers must support UTF-8 and US-ASCII if they support the SORT capability at all, use one of those if you don't have some other preferred character set in mind. The rest of the arguments are searching criteria, just as you would supply to the search method. These are all documented in RFC2060. If you just want all of the messages in the currently selected folder returned to you in sorted order, use ALL as your only search criterion. The sort method returns an array containing sequence numbers of messages that passed the SORT IMAP client command's search criteria. If the Uid parameter is true then the array will contain message UID's. If sort is called in scalar context then a pointer to the array will be passed, instead of the array itself. The message sequence numbers or unique identifiers are ordered according to the sort criteria specified. The sort criteria are nested in the order specified; that is, items are sorted first by the first criterion, and within the first criterion they are sorted by the second criterion, and so on. The see method accepts a list of one or more messages sequence numbers, or a single reference to an array of one or more message sequence numbers, as its argument(s). It then sets the "\Seen" flag for those message(s). Of course, if the Uid parameter is set to a true value then those message sequence numbers had better be unique message id's, but then you already knew that, didn't you? Note that specifying `$imap-'see(@msgs)> is just a shortcut for specifying `$imap-'set_flag("Seen",@msgs)>. The seen method performs an IMAP SEARCH SEEN search against the selected folder and returns an array of sequence numbers of messages that have already been seen (ie their SEEN flag is set). If the Uid parameter is true then an array of message UID's will be returned instead. If called in scalar context than a pointer to the array (rather than the array itself) will be returned. The select method selects a folder and changes the object's state to "Selected". It accepts one argument, which is the name of the folder to select. The sentbefore works just like the section on "sentsince", below, except it searches for messages that were sent before the date supplied as an argument to the method. The senton works just like the section on "sentsince", below, except it searches for messages that were sent on the exact date supplied as an argument to the method. The sentsince method accepts one argument, a date in either standard perl format (seconds since 1/1/1970, or as output by time and as accepted by localtime) or in the date_text format as defined in RFC2060 (dd-Mon-yyyy, where Mon is the English-language three-letter abbreviation for the month). It searches for items in the currently selected folder for messages sent since the day whose date is provided as the argument. It uses the RFC822 Date: header to determine the sentsince date. In the case of arguments supplied as a number of seconds, the returned result list will include items sent on or after that day, regardless of whether they arrived before the specified time on that day. The IMAP protocol does not support searches at a granularity finer than a day, so neither do I. On the other hand, the only thing I check for in a date_text argument is that it matches the pattern `/\d\d-\D\D\D-\d\d\d\d/' (notice the lack of anchors), so if your server lets you add something extra to a date_text string then so will Mail::IMAPClient. The separator method returns the character used as a separator character in folder hierarchies. On unix-based servers, this is often a forward slash (/). It accepts one argument, the name of a folder whose hierarchy's separator should be returned. If no folder name is supplied then the separator for the INBOX is returned, which probably is good enough. The set_flag method accepts the name of a flag as its first argument and a list of one or more messages sequence numbers, or a single reference to an array of one or more message sequence numbers, as its next argument(s). It then sets the flag specified for those message(s). Of course, if the Uid parameter is set to a true value then those message sequence numbers had better be unique message id's, just as you'd expect. Note that when specifying the flag in question, the preceding backslash (\) is entirely optional. (For you, that is. Mail::IMAPClient still has remember to stick it in there before passing the command to the server. This is in fact so important that the method checks its argument and adds the backslash when necessary, which is why you don't have to worry about it overly much.) The setacl method accepts three input arguments, a folder name, a user id (or authentication identifier, to use the terminology of RFC2086), and an access rights modification string. See RFC2086 for more information. (This is somewhat experimental and its implementation may change.) The since method accepts a date in either standard perl format (seconds since 1/1/1970, or as output by the time entry in the perlfunc manpage and as accepted by the localtime entry in the perlfunc manpage) or in the date_text format as defined in RFC2060 (dd-Mon-yyyy, where Mon is the English-language three-letter abbreviation for the month). It searches for items in the currently selected folder for messages whose internal dates are on or after the day whose date is provided as the argument. It uses the internal system date for a message to determine if that message was sent since the given date. In the case of arguments supplied as a number of seconds, the returned result list will include items whose internal date is on or after that day, regardless of whether they arrived before the specified time on that day. The size method accepts one input argument, a sequence number (or message UID if the Uid parameter is true). It returns the size of the message in the currently selected folder with the supplied sequence number (or UID). The IMAPClient object must be in a Selected state in order to use this method. The status method accepts one argument, the name of a folder (or mailbox, to use RFC2060's terminology), and returns an array containing the results of running the IMAP STATUS client command against that folder. If additional arguments are supplied then they are appended to the IMAP STATUS client command string, separated from the rest of the string and each other with spaces. If status is not called in an array context then it returns a reference to an array rather than the array itself. The status method should not be confused with the Status method (with an uppercase 'S'), which returns information about the IMAPClient object. (See the section labeled the section on "Status Methods", below). The store method accepts a message sequence number or comma-separated list of message sequence numbers as a first argument, a message data item name, and a value for the message data item. Currently, data items are the word "FLAGS" followed by a space and a list of flags (in parens). The word "FLAGS" can be modified by prefixing it with either a "+" or a "-" (to indicate "add these flags" or "remove these flags") and by suffixing it with ".SILENT" (which reduces the amount of output from the server; very useful with large message sets). Normally you won't need to call store because there are oodles of methods that will invoke store for you with the correct arguments. Furthermore, these methods are friendlier and more flexible with regards to how you specify your arguments. See for example the see manpage, the deny_seeing manpage, the delete_message manpage, and the restore_message manpage. Or the mark manpage, the unmark manpage, the set_flag manpage, and the unset_flag manpage. The subscribed method works like the folders method, above, except that the returned list (or array reference, if called in scalar context) contains only the subscribed folders. The tag_and_run method accepts one or two arguments. The first argument is a string containing an IMAP Client command, without a tag but with all required arguments. The optional second argument is a string to look for that will indicate success (without pattern delimiters). The default is `OK.*'. The tag_and_run method will prefix your string (from the first argument) with the next transaction number and run the command. It returns an array of output lines from the command, which you are free to parse as you see fit. Using this method instead of run (above) will free you from having to worry about handling the tags (and from worrying about the side affects of naming your own tags). The uidnext method accepts one argument, the name of a folder, and returns the numeric string that is the next available message UID for that folder. The uidvalidity method accepts one argument, the name of a folder, and returns the numeric string that is the unique identifier validity value for the folder. The unmark method accepts a list of one or more messages sequence numbers, or a single reference to an array of one or more message sequence numbers, as its argument(s). It then unsets the "\Flagged" flag for those message(s). Of course, if the Uid parameter is set to a true value then those message sequence numbers should really be unique message id's. Note that specifying `$imap-'see(@msgs)> is just a shortcut for specifying `$imap-'unset_flag("Flagged",@msgs)>. The unseen method performs an IMAP SEARCH UNSEEN search against the selected folder and returns an array of sequence numbers of messages that have not yet been seen (ie their SEEN flag is not set). If the Uid parameter is true then an array of message UID's will be returned instead. If called in scalar context than a pointer to the array (rather than the array itself) will be returned. Note that when specifying the flag in question, the preceding backslash (\) is entirely optional. The unseen_count method accepts the name of a folder as an argument and returns the number of unseen messages in that folder. If no folder argument is provided then it returns the number of unseen messages in the currently selected Folder. The unset_flag method accepts the name of a flag as its first argument and a list of one or more messages sequence numbers, or a single reference to an array of one or more message sequence numbers, as its next argument(s). It then unsets the flag specified for those message(s). Of course, if the Uid parameter is set to a true value then those message sequence numbers had better be unique message id's, just as you'd expect. IMAP Client Commands not otherwise documented have been implemented via an AUTOLOAD hack and use a default method. If a program calls a method that is not defined (or inherited) by the IMAPClient module then the IMAPClient module will assume that it is an IMAP client command. It will prefix the command with the next available transaction number (or tag value), and append to it the space-delimited list of arguments supplied to the unimplemented method (if any). It will then read lines of output from the imap session until it finds a line containing the strings "OK" and "Completed", and return an array containing all of the lines of output (or, if called in scalar context, an array reference). If it finds "BAD" or "NO" instead of "OK" it returns undef. Eg: $imap->FOO("bar","an example","of the default"); results in: "99 FOO bar an example of the default\r\n" being sent to the IMAP server (assuming that 99 is the current transaction number). Notice that we used an uppercase method name "FOO" so as not to conflict with future implementations of that IMAP command. If you run your script with warnings turned on (always a good idea, at least during testing), then you will receive warnings whenever you use a lowercase method name that has not been implemented. An exception to this is when you use certain common (yet unimplemented) methods that, if ever explicitly implemented, are guaranteed to behave just like the default method. To date, those methods are either documented in the section labeled the Object Methods entry elsewhere in this document, above, or listed here: Copy a message into a folder. Subscribe to a folder CAUTION: Once again, remember to quote your quotes if you want quotes to be part of the IMAP command string. You can also use the default method to override the behavior of implemented IMAP methods by changing the case of the method name, preferably to all-uppercase so as not to conflict with the Class method and accessor method namespace. For example, if you don't want the search method's behavior (which returns a list of message numbers) but would rather have an array of raw data returned from your search operation, you can issue the following snippet: my @raw = $imap->SEARCH("SUBJECT","Whatever..."); which is slightly more efficient than the equivalent: $imap->search("SUBJECT","Whatever..."); my @raw = $imap->Results; There are several object methods that return the status of the object. They can be used at any time to check the status of an IMAPClient object, but are particularly useful for determining the cause of failure when a connection and login are attempted as part of a single new method invocation. The status methods are: The History method is almost identical to the Results method. Unlike the Results method, however, the IMAP command that was issued to create the results being returned is not included in the returned results. If called in a scalar context, History returns an array reference rather than an array. returns a true value if the object is currently in an Unconnected state. returns a true value if the object is currently in either a Connected, Authenticated, or Selected state. returns a true value if the object is currently in either an Authenticated or Selected state. returns a true value if the object is currently in a Selected state. Internally LastError is implemented just like a parameter (as described in the section on "Parameters", above). There is a LastError attribute and an eponymous accessor method which returns the LastError text string describing the last error condition encountered by the server. Note that some errors are more serious than others, so LastError's value is only meaningful if you encounter an error condition that you don't like. For example, if you use the exists method to see if a folder exists and the folder does not exist, then an error message will be recorded in LastError even though this is not a particularly serious error. On the other hand, if you didn't use exists and just tried to select a non-existing folder, then select would return undef after setting LastError to something like "NO SELECT failed: Can't open mailbox <mailbox>: no such mailbox". At this point it would be useful to print out the contents of LastError as you die. New in version 2.0.4, LastIMAPCommand returns the exact IMAP command string to be sent to the server. Useful mainly in constructing error messages when LastError just isn't enough. The Report method returns an array containing a history of the IMAP session up to the point that Report was called. It is primarily meant to assist in debugging but can also be used to retrieve raw output for manual parsing. The value of the Clear parameter controls how many transactions are in the report. (See the discussion of Clear in the section on "parameters", above.) The Results method returns an array containing the results of one IMAP client command. It accepts one argument, the transaction number of the command whose results are to be returned. If transaction number is unspecified then Results returns the results of the last IMAP client command issued. If called in a scalar context, Results returns an array reference rather than an array. The State method returns a numerical value that indicates the current status of the IMAPClient object. If invoked with an argument, it will set the object's state to that value. If invoked without an argument, it behaves just like Status, below. Normally you will not have to invoke this function. An exception is if you are bypassing the Mail::IMAPClient module's connect and/or login modules to set up your own connection (say, for example, over a secure socket), in which case you must manually do what the connect and login methods would otherwise do for you. The Status method returns a numerical value that indicates the current status of the IMAPClient object. (Not to be confused with the status method, all lower-case, which is the implementation of the STATUS IMAP client command.) The Transaction method returns the tag value (or transaction number) of the last IMAP client command. Please feel free to e-mail the author at the below address if you encounter any strange behaviors. When reporting a bug, please be sure to include the following: - As much information about your environment as possible. I especially need to know which version of Mail::IMAPClient you are running and the type/version of IMAP server to which you are connecting. - As detailed a description of the problem as possible. (What are you doing? What happens?) - An example script that demonstrates the problem (preferably with as few lines of code as possible!) and which calls the Mail::IMAPClient's new method with the Debug parameter set to "1". - Output from the example script when it's running with the Debug parameter turned on. You can edit the output to remove (or preferably to "X" out) sensitive data, such as hostnames, user names, and passwords, but PLEASE do not remove the text that identifies the TYPE of IMAP server to which you are connecting. Note that in the latest versions of Mail::IMAPClient, debugging does not print out the user or password from the login command line. However, if you use some other means of authenticating then you may need to edit the debugging output with an eye to security. - Don't be surprised if I come back asking for a trace of the problem. To provide this, you should create a file called .perldb in your current working directory and include the following line of text in that file: `&parse_options("NonStop=1 LineInfo=mail_imapclient_db.out");' For your debugging convenience, a sample .perldb file, which was randomly assigned the name sample.perldb, is provided in the distribution. Next, without changing your working directory, debug the example script like this: `perl -d example_script.pl [ args ]' Note that in these examples, the script that demonstrates your problem is named "example_script.pl" and the trace output will be saved in "mail_imapclient_db.out". You should change these to suite your needs. David J. Kernen The Kernen Consulting Group, Inc david.kernen@erols.com Copyright 1999, 2000 The Kernen Group, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of either: This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the Artistic License for more details.