Cyrus::IMAP − Interface to Cyrus imclient library


  use Cyrus::IMAP;
  my $client = Cyrus::IMAP−>new('mailhost'[, $flags]);
  ($server, $mailbox) = Cyrus::IMAP−>fromURL($url);
  $url = Cyrus::IMAP−>toURL($server, $mailbox);
  $flags = $client−>flags;
  $server = $client−>servername;
  $client−>addcallback({−trigger => $str, −flags => $flags,
                        −callback => \&cb, −rock => \$var}, ...);
  $client−>send(\&callback, \&cbdata, $format, ...);
  ($result, $text) = $client−>send(undef, undef, $format, ...);
  ($fd, $writepending) = $client−>getselectinfo;


The Cyrus::IMAP module provides an interface to the Cyrus imclient library. These are primarily useful for implementing cyradm operations within a Perl script; there are easier ways to implement general client operations, although they may be more limited in terms of authentication options when talking to a Cyrus imapd.

In the normal case, one will attach to a Cyrus server and authenticate using the best available method:

        my $client = Cyrus::IMAP::new('imap');
        if (!$client−>send('', '', 'CREATE %s', 'user.' . $username)) {
          warn "createmailbox user.$username: $@";

In simple mode as used above, "send()" is invoked with "undef", 0, or '' for the callback and rock (callback data) arguments; it returns a list of "($result, $text)" from the command. If invoked in scalar context, it returns $result and places $text in $@. In this mode, there is no need to use "processoneevent()". If more control is desired, use the callback and rock arguments and invoke "processoneevent()" regularly to receive results from the IMAP server. If still more control is needed, the "getselectinfo()" method returns a list containing a file descriptor (not Perl filehandle) which can be passed to select(); if the second element of the list is true, you should include it in the write mask as well as the read mask because the imclient library needs to perform queued output.

For more information, consult the Cyrus documentation.


"send()" behaves as if the "Cyrus::IMAP::CONN_NONSYNCLITERAL" flag is always set. This is because it is a wrapper for the C version, which cannot be made directly available from Perl, and synchronous literals require interaction with the IMAP server while parsing the format string. This is planned to be fixed in the future.

The 'LOGIN' mechanism can be used to authenticate with a plaintext username and password. This is intended as a workaround for a bug in early SASL implementations; use of Cyrus::IMAP with non-Cyrus servers is not recommended, primarily because there are easier ways to implement IMAP client functionality in Perl. (However, if you need SASL support, "Cyrus::IMAP" is currently the only way to get it.)

The file descriptor returned by "getselectinfo()" should not be used for anything other than "select()". In particular, I/O on the file descriptor will almost certainly cause more problems than whatever problem you think you are trying to solve.

The toURL and fromURL routines are to ease conversion between URLs and IMAP mailbox and server combinations, and are a simple frontend for the libcyrus functions of the same name.

The imparse library routines are not implemented, because they are little more than a (failed) attempt to make parsing as simple in C as it is in Perl.

This module exists primarily so we can integrate Cyrus administration into our Perl-based account management system, and secondarily so that we can rewrite cyradm in a sensible language instead of Tcl. Usability for other purposes is not guaranteed.


Brandon S. Allbery <>, Rob Siemborski <>


Cyrus::IMAP::Admin perl(1), cyradm(1), imclient(3), imapd(8).


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.

Free Software

Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.

Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.

Free Books

The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.

Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.

Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.