NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #3924 most downloaded on PyPI
Easy-to-use, Pythonic and complete IMAP client library
Last release 16 days ago
18 Sep 2026
Release timing varies
gaps range from 4 weeks to 2.4 years
Nearly every release is documented
notes for 32 of 35 stable releases
Nothing withdrawn
no release was ever pulled
13 years old
35 releases · first in 2013
Fix starttls() compatibility with Python 3.14 by @LarsArtmann in #663
Full Changelog: 4.0.1...4.1.0
Date : Sep 18, 2026 Homepage : http://imapclient.freshfoo.com Download : http://pypi.python.org/pypi/IMAPClient/ Source code : https://github.com/mjs/imapclient Documentation : http://imapclient.readthedocs.io/ License : New BSD License Forum/Support : https://github.com/mjs/imapclient/discussions
IMAPClient is an easy-to-use, Pythonic and complete IMAP client library.
Although IMAPClient actually uses the imaplib module from the Python standard library under the hood, it provides a different API. Instead of requiring that the caller performs extra parsing work, return values are full parsed, readily usable and use sensible Python types. Exceptions are raised when problems occur (no error checking of return values is required).
IMAPClient is straightforward to use, but it can be useful to have at least a general understanding of the IMAP protocol. RFC 3501 explains IMAP in detail. Other RFCs also apply to various extensions to the base protocol. These are referred to in the documentation below where relevant.
Python versions 3.8 through 3.14 are officially supported.
Install IMAPClient:
$ uv add imapclient
See Installation for more details.
The core of the IMAPClient API is the IMAPClient class. Instantiating this class, creates a connection to an IMAP account. Calling methods on the IMAPClient instance interacts with the server.
The following example shows a simple interaction with an IMAP server. It displays the message ID, subject and date of the message for all messages in the INBOX folder.
from imapclient import IMAPClient >>> server = IMAPClient ( 'imap.mailserver.com' , use_uid = True ) >>> server . login ( 'someuser' , 'somepassword' ) b'[CAPABILITY IMAP4rev1 LITERAL+ SASL-IR [...] LIST-STATUS QUOTA] Logged in' >>> select_info = server . select_folder ( 'INBOX' ) >>> print ( ' %d messages in INBOX' % select_info [ b 'EXISTS' ]) 34 messages in INBOX >>> messages = server . search ([ 'FROM' , 'best-friend@domain.com' ]) >>> print ( " %d messages from our best friend" % len ( messages )) 5 messages from our best friend >>> for msgid , data in server . fetch ( messages , [ 'ENVELOPE' ]) . items (): >>> envelope = data [ b 'ENVELOPE' ] >>> print ( 'ID # %d : " %s " received %s ' % ( msgid , envelope . subject . decode (), envelope . date )) ID #62: "Our holidays photos" received 2017-07-20 21:47:42 ID #55: "Re: did you book the hotel?" received 2017-06-26 10:38:09 ID #53: "Re: did you book the hotel?" received 2017-06-25 22:02:58 ID #44: "See that fun article about lobsters in Pacific ocean!" received 2017-06-09 09:49:47 ID #46: "Planning for our next vacations" received 2017-05-12 10:29:30 >>> server . logout () b'Logging out'
This section describes how IMAPClient works and gives some examples to help you start.
Installation
uv
From Source
Other versions
IMAPClient Concepts
Message Identifiers
Message Flags
Folder Name Encoding
Working With Fetched Messages
TLS/SSL
Logging
Advanced Usage
Cleaning Up Connections
Watching a Mailbox Using IDLE
Interactive Sessions
This section describes public functions and classes of IMAPClient library.
IMAPClient Class
IMAPClient
SocketTimeout
Fetch Response Types
Address
BodyData
Envelope
SearchIds
Exceptions
CapabilityError
IllegalStateError
InvalidCriteriaError
LoginError
ProtocolError
Utilities
MockIMAP4
TestableIMAPClient
TLS Support
IMAP4_TLS
Thread Safety
Contributing to IMAPClient
Source Code
Unit Tests
Documentation
The Unofficial IMAP Protocol Wiki is very useful when writing IMAP related software and is highly recommended.
IMAPClient was created by Menno Finlay-Smits < inbox @ menno . io >. The project is now maintained by Nicolas Le Manchet and Menno Finlay-Smits.
Many thanks go to the following people for their help with this project:
Maxime Lorant
Mathieu Agopian
Chris Arndt
Jp Calderone
John Louis del Rosario
Dave Eckhardt
Eben Freeman
Helder Guerreiro
Mark Hammond
Johannes Heckel
Thomas Jost
Lukasz Mierzwa
Naveen Nathan
Brian Neal
Phil Peterson
Aviv Salem
Andrew Scheller
Thomas Steinacher
Zac Witte
Hans-Peter Jansen
Carson Ip
Jonny Hatch
Jasper Spaans
Fabio Manganiello
Samir M
Devin Bayer
Mantas Mikulėnas
@zrose584
Michał Górny
François Deppierraz
Jasper Spaans
Boni Lindsley
Tobias Kölling
@pinoatrome
Shoaib Ahmed
John Villalovos
Claude Paroz
Stefan Wójcik
Andrzej Bartosiński
@axoroll7
Sean Whalen
Peter Wienemann
Arnout Engelen
Lars Artmann
From release 3.0.0 onwards, release notes are maintained on Github .
Release notes for older versions can be found in these docs .
IMAPClient
Introduction
Getting Started
User Guide
API Reference
Contributor Guide
External Documentation
Authors
Release History
Installation
modules
next |
IMAPClient 4.1.0 documentation »
IMAPClient
© Copyright 2014, Menno Smits.
One column per quarter.
only build for published releases by @mjs in #660
Date : Sep 11, 2026 Homepage : http://imapclient.freshfoo.com Download : http://pypi.python.org/pypi/IMAPClient/ Source code : https://github.com/mjs/imapclient Documentation : http://imapclient.readthedocs.io/ License : New BSD License Forum/Support : https://github.com/mjs/imapclient/discussions
IMAPClient is an easy-to-use, Pythonic and complete IMAP client library.
Although IMAPClient actually uses the imaplib module from the Python standard library under the hood, it provides a different API. Instead of requiring that the caller performs extra parsing work, return values are full parsed, readily usable and use sensible Python types. Exceptions are raised when problems occur (no error checking of return values is required).
IMAPClient is straightforward to use, but it can be useful to have at least a general understanding of the IMAP protocol. RFC 3501 explains IMAP in detail. Other RFCs also apply to various extensions to the base protocol. These are referred to in the documentation below where relevant.
Python versions 3.8 through 3.14 are officially supported.
Install IMAPClient:
$ uv add imapclient
See Installation for more details.
The core of the IMAPClient API is the IMAPClient class. Instantiating this class, creates a connection to an IMAP account. Calling methods on the IMAPClient instance interacts with the server.
The following example shows a simple interaction with an IMAP server. It displays the message ID, subject and date of the message for all messages in the INBOX folder.
from imapclient import IMAPClient >>> server = IMAPClient ( 'imap.mailserver.com' , use_uid = True ) >>> server . login ( 'someuser' , 'somepassword' ) b'[CAPABILITY IMAP4rev1 LITERAL+ SASL-IR [...] LIST-STATUS QUOTA] Logged in' >>> select_info = server . select_folder ( 'INBOX' ) >>> print ( ' %d messages in INBOX' % select_info [ b 'EXISTS' ]) 34 messages in INBOX >>> messages = server . search ([ 'FROM' , 'best-friend@domain.com' ]) >>> print ( " %d messages from our best friend" % len ( messages )) 5 messages from our best friend >>> for msgid , data in server . fetch ( messages , [ 'ENVELOPE' ]) . items (): >>> envelope = data [ b 'ENVELOPE' ] >>> print ( 'ID # %d : " %s " received %s ' % ( msgid , envelope . subject . decode (), envelope . date )) ID #62: "Our holidays photos" received 2017-07-20 21:47:42 ID #55: "Re: did you book the hotel?" received 2017-06-26 10:38:09 ID #53: "Re: did you book the hotel?" received 2017-06-25 22:02:58 ID #44: "See that fun article about lobsters in Pacific ocean!" received 2017-06-09 09:49:47 ID #46: "Planning for our next vacations" received 2017-05-12 10:29:30 >>> server . logout () b'Logging out'
This section describes how IMAPClient works and gives some examples to help you start.
Installation
uv
From Source
Other versions
IMAPClient Concepts
Message Identifiers
Message Flags
Folder Name Encoding
Working With Fetched Messages
TLS/SSL
Logging
Advanced Usage
Cleaning Up Connections
Watching a Mailbox Using IDLE
Interactive Sessions
This section describes public functions and classes of IMAPClient library.
IMAPClient Class
IMAPClient
SocketTimeout
Fetch Response Types
Address
BodyData
Envelope
SearchIds
Exceptions
CapabilityError
IllegalStateError
InvalidCriteriaError
LoginError
ProtocolError
Utilities
MockIMAP4
TestableIMAPClient
TLS Support
IMAP4_TLS
Thread Safety
Contributing to IMAPClient
Source Code
Unit Tests
Documentation
The Unofficial IMAP Protocol Wiki is very useful when writing IMAP related software and is highly recommended.
IMAPClient was created by Menno Finlay-Smits < inbox @ menno . io >. The project is now maintained by Nicolas Le Manchet and Menno Finlay-Smits.
Many thanks go to the following people for their help with this project:
Maxime Lorant
Mathieu Agopian
Chris Arndt
Jp Calderone
John Louis del Rosario
Dave Eckhardt
Eben Freeman
Helder Guerreiro
Mark Hammond
Johannes Heckel
Thomas Jost
Lukasz Mierzwa
Naveen Nathan
Brian Neal
Phil Peterson
Aviv Salem
Andrew Scheller
Thomas Steinacher
Zac Witte
Hans-Peter Jansen
Carson Ip
Jonny Hatch
Jasper Spaans
Fabio Manganiello
Samir M
Devin Bayer
Mantas Mikulėnas
@zrose584
Michał Górny
François Deppierraz
Jasper Spaans
Boni Lindsley
Tobias Kölling
@pinoatrome
Shoaib Ahmed
John Villalovos
Claude Paroz
Stefan Wójcik
Andrzej Bartosiński
@axoroll7
Sean Whalen
Peter Wienemann
Arnout Engelen
From release 3.0.0 onwards, release notes are maintained on Github .
Release notes for older versions can be found in these docs .
IMAPClient
Introduction
Getting Started
User Guide
API Reference
Contributor Guide
External Documentation
Authors
Release History
Installation
modules
next |
IMAPClient 4.0.1 documentation »
IMAPClient
© Copyright 2014, Menno Smits.
chore: convert project to uv by @mjs in #654 . This felt like a significant and risky enough change to warrant a major version bump.
Full Changelog: 3.1.0...4.0.0
Simplify IMAP4_TLS class and fix Python 3.14+ compatibility by @seanthegeek in #629
setuptools to requirements-dev.txt by @JohnVillalovos in #590Full Changelog: 3.0.1...3.1.0
chore(deps-dev): bump black from 23.10.0 to 23.11.0 by @dependabot in #562
Full Changelog: 3.0.0...3.0.1
Remove configparser deprecation warnings by @claudep in #487
uid_expunge, which requires the capability UIDPLUS. by @axoroll7 in #508black for CI by @JohnVillalovos in #477flake8, fix issues, & add to CI by @JohnVillalovos in #478get() & getboolean() by @JohnVillalovos in #486optparse to argparse by @JohnVillalovos in #492isort linter by @JohnVillalovos in #515envdir settings from tox.ini by @JohnVillalovos in #514version.py by @JohnVillalovos in #518dependabot.yml to enable automatic PRs by @JohnVillalovos in #516pylint check by @JohnVillalovos in #524black==23.7.0 check passes by @JohnVillalovos in #523pylint issues by @JohnVillalovos in #525pop_with_default() function by @JohnVillalovos in #532response_*.py by @JohnVillalovos in #530namedtuple to dataclass by @JohnVillalovos in #534setup.py and imapclient/config.py. Also use argparse.Namespace instead of Bunch by @JohnVillalovos in #537imapclient/interact.py by @JohnVillalovos in #538Full Changelog: 2.3.1...3.0.0
Date : Oct 27, 2023 Homepage : http://imapclient.freshfoo.com Download : http://pypi.python.org/pypi/IMAPClient/ Source code : https://github.com/mjs/imapclient Documentation : http://imapclient.readthedocs.io/ License : New BSD License Forum/Support : https://github.com/mjs/imapclient/discussions
IMAPClient is an easy-to-use, Pythonic and complete IMAP client library.
Although IMAPClient actually uses the imaplib module from the Python standard library under the hood, it provides a different API. Instead of requiring that the caller performs extra parsing work, return values are full parsed, readily usable and use sensible Python types. Exceptions are raised when problems occur (no error checking of return values is required).
IMAPClient is straightforward to use, but it can be useful to have at least a general understanding of the IMAP protocol. RFC 3501 explains IMAP in detail. Other RFCs also apply to various extensions to the base protocol. These are referred to in the documentation below where relevant.
Python versions 3.4 through 3.9 are officially supported.
Install IMAPClient:
$ pip install imapclient
See Installation for more details.
The core of the IMAPClient API is the IMAPClient class. Instantiating this class, creates a connection to an IMAP account. Calling methods on the IMAPClient instance interacts with the server.
The following example shows a simple interaction with an IMAP server. It displays the message ID, subject and date of the message for all messages in the INBOX folder.
from imapclient import IMAPClient >>> server = IMAPClient ( 'imap.mailserver.com' , use_uid = True ) >>> server . login ( 'someuser' , 'somepassword' ) b'[CAPABILITY IMAP4rev1 LITERAL+ SASL-IR [...] LIST-STATUS QUOTA] Logged in' >>> select_info = server . select_folder ( 'INBOX' ) >>> print ( ' %d messages in INBOX' % select_info [ b 'EXISTS' ]) 34 messages in INBOX >>> messages = server . search ([ 'FROM' , 'best-friend@domain.com' ]) >>> print ( " %d messages from our best friend" % len ( messages )) 5 messages from our best friend >>> for msgid , data in server . fetch ( messages , [ 'ENVELOPE' ]) . items (): >>> envelope = data [ b 'ENVELOPE' ] >>> print ( 'ID # %d : " %s " received %s ' % ( msgid , envelope . subject . decode (), envelope . date )) ID #62: "Our holidays photos" received 2017-07-20 21:47:42 ID #55: "Re: did you book the hotel?" received 2017-06-26 10:38:09 ID #53: "Re: did you book the hotel?" received 2017-06-25 22:02:58 ID #44: "See that fun article about lobsters in Pacific ocean!" received 2017-06-09 09:49:47 ID #46: "Planning for our next vacations" received 2017-05-12 10:29:30 >>> server . logout () b'Logging out'
This section describes how IMAPClient works and gives some examples to help you start.
Installation
Pip
From Source
Other versions
IMAPClient Concepts
Message Identifiers
Message Flags
Folder Name Encoding
Working With Fetched Messages
TLS/SSL
Logging
Advanced Usage
Cleaning Up Connections
Watching a Mailbox Using IDLE
Interactive Sessions
This section describes public functions and classes of IMAPClient library.
IMAPClient Class
IMAPClient
SocketTimeout
Fetch Response Types
Address
BodyData
Envelope
SearchIds
Exceptions
CapabilityError
IllegalStateError
InvalidCriteriaError
LoginError
ProtocolError
Utilities
MockIMAP4
TestableIMAPClient
TLS Support
IMAP4_TLS
Thread Safety
Contributing to IMAPClient
Source Code
Unit Tests
Documentation
The Unofficial IMAP Protocol Wiki is very useful when writing IMAP related software and is highly recommended.
IMAPClient was created by Menno Finlay-Smits < inbox @ menno . io >. The project is now maintained by Nicolas Le Manchet and Menno Finlay-Smits.
Many thanks go to the following people for their help with this project:
Maxime Lorant
Mathieu Agopian
Chris Arndt
Jp Calderone
John Louis del Rosario
Dave Eckhardt
Eben Freeman
Helder Guerreiro
Mark Hammond
Johannes Heckel
Thomas Jost
Lukasz Mierzwa
Naveen Nathan
Brian Neal
Phil Peterson
Aviv Salem
Andrew Scheller
Thomas Steinacher
Zac Witte
Hans-Peter Jansen
Carson Ip
Jonny Hatch
Jasper Spaans
Fabio Manganiello
Samir M
Devin Bayer
Mantas Mikulėnas
@zrose584
Michał Górny
François Deppierraz
Jasper Spaans
Boni Lindsley
Tobias Kölling
@pinoatrome
Shoaib Ahmed
John Villalovos
Claude Paroz
Stefan Wójcik
Andrzej Bartosiński
@axoroll7
From release 3.0.0 onwards, release notes are maintained on Github .
Release notes for older versions can be found in these docs .
IMAPClient
Introduction
Getting Started
User Guide
API Reference
Contributor Guide
External Documentation
Authors
Release History
Installation
modules
next |
IMAPClient 3.0.0 documentation »
IMAPClient
© Copyright 2014, Menno Smits.
Bump versions for 2.3.1
Bump versions for 2.3.1
Bump version numbers for 2.3.0
Bump version numbers for 2.3.0
Note: This will be the last release to support Python 2.
Many thanks to Boni Lindsley for many of the changes in this release. Changes below are by them unless otherwise specified.
Use GitHub Actions instead of TravisCI
Improvements to code examples (thanks shoaib30)
Run tests with unittest instead of setup.py
New socket() method which provides access to the underlying network socket. This is useful for allowing the socket to be polled.
Allow flags and internaldate to be specified for MULTIAPPEND (thanks Tobias Kölling)
Default SSL contexts are now created with correct purpose (thanks pinoatrome)
Fixed undiscoverable tests due to name shadowing
Fixed missing code block directives in documentation
Fixed typo in tox envlist
Fixed formatting in release notes
Performance improvements (thanks Carson Ip!)
Performance improvements (thanks Carson Ip!)
2x faster _maybe_int_to_bytes for Python 2 (#375)
Fix _proc_folder_list quadratic runtime (#374)
Faster utf7 encode (#373). ~40% faster for input with a mix of unicode and ASCII chars.
Cache regex in _process_select_response
poll() when available to surpass 1024 file descriptor limit with select() (#377) (thanks Jonny Hatch)
Use next instead of six.next as imapclient doesn't claim Python 2.5 support. (#396) (thanks Jasper Spaans)
Moved "Logged in/out" traces from INFO to DEBUG level (thanks Fabio Manganiello)
Run tests on Python 3.8 and 3.9
Support the Deleted special folder used by Outlook (thanks Samir M)
Clean up timeout handling
Run the Black code formatter over the entire project
MULTIAPPEND and LITERAL+ support (#399) (thanks Devin Bayer)
Use ptpython for interactive shell if available (#272)
Allow any custom SASL mechanism to be provided. This allows mechanisms such as EXTERNAL, GSSAPI or SCRAM-SHA-256 to be used in the same way as with imaplib. (thanks Mantas Mikulėnas)
Add SASL OAUTHBEARER support
add optional timeout parameter to IMAP4_TLS.open (thanks zrose584)
fixed special folder searching
Catch the right exception in folder_status (#371)
test_imapclient: Fix LoggerAdapter version check (#383) (thanks Michał Górny)
Fix config file parsing for None attributes (#393) (thanks François Deppierraz)
Fix useless ref cycle in lexer
Protocol parsing: Prevent converting numbers with leading zeroes to int. (#390) (#405) (thanks Jasper Spaans)
Prevent UnicodeDecodeError in IMAPlibLoggerAdapter (#367)
Fix invalid string escape sequences (#397)
Ensure timeout is used on Python 2.7. _create_socket isn't used with the Python 2 version of imaplib so the open method has been overrided to make it consistent across Python version (#380).
Fix IMAP4_TLS for imaplib in Python 3.9+ (thanks Christopher Arndt, marmarek and link2xt)
Bump the version number to 2.1.0
Bump the version number to 2.1.0
TravisCI now runs tests against PyPy
Python 3.7 is now officially supported
Cleaned up server capability checks
Use TLS by default for interactive sessions
Support the QUOTA extension
Support for locating special folders (find_special_folder())
Document usage of client TLS certificates
Added documentation & example for parsing retrieved emails using the standard library email package.
Handle NIL values for INTERNALDATE
Nothing published for this version
Search now supports nested criteria so that more complex criteria can be expressed. IMAPClient will add parentheses in the right place.
Search now supports nested criteria so that more complex criteria can be expressed. IMAPClient will add parentheses in the right place.
PLAIN authentication support (via plain_login method)
unselect_folder() method, for servers with the UNSELECT capability (#200)
Add ENABLE support (#136)
UID EXPUNGE support (#287)
the mock package is no longer installed by default (just as a test dependency)
handle NIL date values in INTERNALDATE
add silent option to all flags methods (improves performance by avoiding unnecessary parsing)
simplify Gmail label functionality
folder_status is more robust
various livetest reliability improvements
don't quote search criteria when sent as IMAP literals. Fixes #249.
Modified UTF-7 encoding function had quirks in its original algorithm, leading to incorrect encoded output in some cases. The algorithm, described in RFC 3501, has been reimplemented to fix #187 and is better documented.
use fixed month names when formatting INTERNALDATES (don't rely on locale)
handle address without mailbox name or host in Address namedtuple. Fixes #242.
Use cryptography < 2.0 on Python 3.3. Fixes #305.
Documented the livetest/interact INI file format.
Documented the livetest/interact INI file format.
Documented handling of RFC2822 group syntax.
Explicitly check that the required pyOpenSSL version is installed
Start testing against Python 3.5
Update doc links from readthedocs.org to readthedocs.io
Rearranged README so that project essentials are right at the top.
Allow installation from alternate directories
Minimum backports.ssl dependency is now 0.0.9 (an important performance issue was addressed)
Minimum backports.ssl dependency is now 0.0.9 (an important performance issue was addressed)
setuptools 18.8.1 now used due to strange zip file error for 17.1
Unit test for version strings were updated to now always include the patch version.
Fresh capabilities now retrieved between STARTTLS and authentication (#195).
The way that IMAPClient establishes TLS/SSL connections has been completely reworked. By default IMAPClient will attempt certificate verification, cer
The way that IMAPClient establishes TLS/SSL connections has been completely reworked. By default IMAPClient will attempt certificate verification, certificate hostname checking, and will not use known-insecure TLS settings and protocols. In addition, TLS parameters are now highly configurable.
By leveraging pyOpenSSL and backports.ssl, all Python versions supported by IMAPClient enjoy the same TLS functionality and API.
These packages mean that IMAPClient now has a number of new dependencies. These should be installed automatically as required but there will no doubt be complications.
Compatibility breaks:
Due to lack of support in some of the dependent libraries, IMAPClient no longer supports Python 3.2.
The passthrough keyword arguments that the IMAPClient constructor took in past versions are no longer accepted. These were in place to provide access to imaplib's SSL arguments which are no longer relevant. Please pass a SSL context object instead.
When using the default SSL context that IMAPClient creates (recommended), certificate verification is enabled. This means that IMAPClient connections to servers that used to work before, may fail now (especially if a self-signed certificate is used by the server). Refer to the documentation for details of how to supply alternate CA certificates or disable verification.
There are some new exceptions that might be raised in response to network issues or TLS protocol failures. Refer to the Exceptions section of the manual for more details.
Please refer to the "TLS/SSL" section of the manual for more details on all of the above.
Many thanks to Chris Arndt and Marc-Antoine Parent for their input into these TLS improvements.
When the server supports it, IMAPClient can now establish an encrypted connection after initially starting with an unencrypted connection using the STARTTLS command. The starttls method takes an SSL context object for controlling the parameters of the TLS negotiation.
Many thanks to Chris Arndt for his extensive initial work on this.
IMAPClient's methods that accept search criteria (search, sort, thread, gmail_search) have been changed to provide take criteria in a more straightforward and robust way. In addition, the way the charset argument interacts with search criteria has been improved. These changes make it easier to pass search criteria and have them handled correctly but unfortunately also mean that small changes may be required to existing code that uses IMAPClient.
The preferred way to specify criteria now is as a list of strings, ints and dates (where relevant). The list should be flat with all the criteria parts run together. Where a criteria takes an argument, just provide it as the next element in the list.
Some valid examples:
c.search(['DELETED']) c.search(['NOT', 'DELETED']) c.search(['FLAGGED', 'SUBJECT', 'foo', 'BODY', 'hello world']) c.search(['NOT', 'DELETED', 'SMALLER', 1000]) c.search(['SINCE', date(2006, 5, 3)])
IMAPClient will perform all required conversion, quoting and encoding. Callers do not need to and should not attempt to do this themselves. IMAPClient will automatically send criteria parts as IMAP literals when required (i.e. when the encoded part is 8-bit).
Some previously accepted ways of passing search criteria will not work as they did in previous versions of IMAPClient. Small changes will be required in these cases. Here are some examples of how to update code written against older versions of IMAPClient:
c.search(['NOT DELETED']) # Before c.search(['NOT', 'DELETED']) # After c.search(['TEXT "foo"']) # Before c.search(['TEXT', 'foo']) # After (IMAPClient will add the quotes) c.search(['DELETED', 'TEXT "foo"']) # Before c.search(['DELETED', 'TEXT', 'foo']) # After c.search(['SMALLER 1000']) # Before c.search(['SMALLER', 1000]) # After
It is also possible to pass a single string as the search criteria. IMAPClient will not attempt quoting in this case, allowing the caller to specify search criteria at a lower level. Specifying criteria using a sequence of strings is preferable however. The following examples (equivalent to those further above) are valid:
c.search('DELETED')
c.search('NOT DELETED')
c.search('FLAGGED SUBJECT "foo" BODY "hello world"')
c.search('NOT DELETED SMALLER 1000')
c.search('SINCE 03-May-2006')
The way that the search charset argument is handled has also changed.
Any unicode criteria arguments will now be encoded by IMAPClient using the supplied charset. The charset must refer to an encoding that is capable of handling the criteria's characters or an error will occur. The charset must obviously also be one that the server supports! (UTF-8 is common)
Any criteria given as bytes will not be changed by IMAPClient, but the provided charset will still be passed to the IMAP server. This allows already encoding criteria to be passed through as-is. The encoding referred to by charset should match the actual encoding used for the criteria.
The following are valid examples:
c.search(['TEXT', u'\u263a'], 'utf-8') # IMAPClient will apply UTF-8 encoding c.search([b'TEXT', b'\xe2\x98\xba'], 'utf-8') # Caller has already applied UTF-8 encoding
The documentation and tests for search, gmail_search, sort and thread has updated to account for these changes and have also been generally improved.
IMAPClient now accepts a timeout at creation time. The timeout applies while establishing the connection and for all operations on the socket connected to the IMAP server.
In order to better indicate version compatibility to users, IMAPClient will now strictly adhere to the Semantic Versioning scheme.
A short circuit is now used when parsing a list of message ids which greatly speeds up parsing time.
Perform quoting of Gmail labels. Thanks to Pawel Sz for the fix.
The type of the various flag constants was fixed. Thanks to Thomi Richards for pointing this out.
Now using mock 1.3.0. Thanks to Thomi Richards for the patch.
Fixed handling of very long numeric only folder names. Thanks to Paweł Gorzelany for the patch.
The default charset for gmail_search is now UTF-8. This makes it easier to use any unicode string as a search string and is safe because Gmail supports UTF-8 search criteria.
PEP8 compliance fixed (except for some occasional long lines)
Added a "shutdown" method.
The embedded six package has been removed in favour of using an externally installed instance.
Fixed handling of literals in STATUS responses.
Only use the untagged post-login CAPABILITY response once (if sent by server).
Release history made part of the main documentation.
Clarified how message ids work in the docs.
Livetest infrastructure now works with Yahoo's OAUTH2
Fixed bytes handling in Address.__str__
Added support for the ID command [NEW]
As per RFC2971. Thanks to Eben Freeman from Nylas.
Thanks to Thomas Steinacher for this fix.
Fixed a regression in the handling of NIL/None SEARCH responses. Thanks again to Thomas Steinacher.
Don't traceback when an unparsable date is seen in ENVELOPE responses. None is returned instead.
Support quirky timestamp strings which use dots for the time separator.
Removed horrible INTERNALDATE parsing code (use parse_to_datetime instead).
datetime_to_imap has been moved to the datetime_util module and is now called datetime_to_INTERNALDATE. This will only affect you in the unlikely case that you were importing this function out of the IMAPClient package.
The docs for various IMAPClient methods, and the HACKING.rst file have been updated.
CONDSTORE live test is now more reliable (especially when running against Gmail)
The deprecated get_folder_delimiter() method has been removed.
During the work to support Python 3, IMAPClient was changed to do return unicode for most responses. This was a bad decision, especially because it effectively breaks content that uses multiple encodings (e.g. RFC822 responses). This release includes major changes so that most responses are returned as bytes (Python 3) or str (Python 2). This means that correct handling of response data is now possible by code using IMAPClient.
Folder name handling has also been cleaned up as part of this work. If the folder_encode attribute is True (the default) then folder names will always be returned as unicode. If folder_encode is False then folder names will always be returned as bytes/strs.
Code using IMAPClient will most likely need to be updated to account these unicode handling changes.
Many thanks to Inbox (now Nilas, https://nilas.com/) for sponsoring this work.
Any unused keyword arguments passed to the IMAPClient initialiser will now be passed through to the underlying imaplib IMAP4, IMAP4_SSL or IMAP4_stream class. This is specifically to allow the use of imaplib features that control certificate validation (if available with the version of Python being used).
Thanks to Chris Arndt for this change.
If the CONDSTORE extension is supported by a server and a MODSEQ criteria was used with search(), a TypeError could occur. This has now been fixed and the MODSEQ value returned by the server is now available via an attribute on the returned list of ids.
Small tweaks to support Python 3.4.
The deprecated get_folder_delimiter() method has been removed.
More control over OAUTH2 parameters. Thanks to Phil Peterson for this.
Fixed livetest/interact OAUTH handling under Python 3.
Support for raw Gmail searching [NEW]
The new gmail_search methods allows direct Gmail queries using the X-GM-RAW search extension. Thanks to John Louis del Rosario for the patch.
ENVELOPE FETCH responses are now returned as Envelope instances. These objects are namedtuples providing convenient attribute and positional based access to envelope fields. The Date field is also now converted to a datetime instance.
As part of this change various date and time related utilities were moved to a new module at imapclient.datetime_util.
Thanks to Naveen Nathan for the work on this feature.
BODY and BODYSTRUCTURE responses are now processed recusively so multipart sections within other multipart sections are returned correctly. This also means that each the part of the response now has a is_multipart property available.
NOTE: code that expects the old (broken) behaviour will need to be updated.
Thanks to Brandon Rhodes for the bug report.
Handle square brackets in flags returned in SELECT response. Previously these would cause parsing errors. Thanks to Benjamin Morrise for the bug report.
Copyright date update for 2014.
Switch back to setuptools now that distribute and setuptools have merged back. Some users were reporting problems with distribute and the newer versio
Switch back to setuptools now that distribute and setuptools have merged back. Some users were reporting problems with distribute and the newer versions of setuptools.
Fixed regressions in several cases when binary data (i.e. normal strings under Python 2) are used as arguments to some methods. Also refactored input
Fixed regressions in several cases when binary data (i.e. normal strings under Python 2) are used as arguments to some methods. Also refactored input normalisation functions somewhat.
Fixed buggy method for extracting flags and Gmail labels from STORE responses.
Python 3 support (#22) [API CHANGE]
Python 3.2 and 3.3 are now officially supported. This release also means that Python versions older than 2.6 are no longer supported.
A single source approach has been used, with no conversion step required.
A big thank you to Mathieu Agopian for his massive contribution to getting the Python 3 port finished. His changes and ideas feature heavily in this release.
IMPORTANT: Under Python 2, all strings returned by IMAPClient are now returned as unicode objects. With the exception of folder names, these unicode objects will only contain characters in the ASCII range so this shouldn't break existing code, however there is always a chance that there will be a problem. Please test your existing applications thoroughly with this verison of IMAPClient before deploying to production situations.
"python setup.py test" now runs the unit tests
Mock library is now longer included (listed as external test dependency)
live tests that aren't UID related are now only run once
live tests now perform far less logins to the server under test
Unit tests can now be run for all supported Python versions using tox.
Improved documentation regarding working on the project.
Many documentation fixes and improvements.
HIGHESTMODSEQ in SELECT response is now parsed correctly
Fixed daylight saving handling in FixedOffset class
Fixed --port command line bug in imapclient.interact when SSL connections are made.
The IMAP THREAD command is now supported. Thanks to Lukasz Mierzwa for the patches.
The IMAP THREAD command is now supported. Thanks to Lukasz Mierzwa for the patches.
Previously only the pre-authentication server capabilities were returned by the capabilities() method. Now, if the connection is authenticated, the post-authentication capabilities will be returned. If the server sent an untagged CAPABILITY response after authentication, that will be used, avoiding an unnecessary CAPABILITY command call.
All this ensures that the client sees all available server capabilities.
Better documentation for contributers (see HACKING file)
Copyright date update for 2013.
It is now possible to have IMAPClient run an external command to establish a connection to the IMAP server via a new *stream* keyword argument to the
It is now possible to have IMAPClient run an external command to establish a connection to the IMAP server via a new stream keyword argument to the initialiser. This is useful for exotic connection or authentication setups. The host argument is used as the command to run.
Thanks to Dave Eckhardt for the original patch.
OAUTH2 authentication (as supported by Gmail's IMAP) is now available via the new oauth2_login method. Thanks to Zac Witte for the original patch.
Gmail's IMAP implementation recently started requiring a NOOP command before new messages become visible after delivery or an APPEND. The livetest suite has been updated to deal with this.
New methods have been added for interacting with Gmail's label API: get_gmail_labels, add_gmail_labels, set_gmail_labels, remove_gmail_labels. Thanks
New methods have been added for interacting with Gmail's label API: get_gmail_labels, add_gmail_labels, set_gmail_labels, remove_gmail_labels. Thanks to Brian Neal for the patches.
A signficant amount of duplicated code has been removed by abstracting out common command handling code. This will make the Python 3 port and future maintenance easier.
Up until this release the tests in imapclient.livetest could only be run against a dummy IMAP account (all data in the account would be lost during testing). The tests are now limited to a sub-folder created by the tests so it is ok to run them against an account that contains real messages. These messages will be left alone.
Don't traceback when an IMAP server returns a all-digit folder name without quotes. Thanks to Rhett Garber for the bug report. (#107)
More tests for ACL related methods (#89)
More tests for namespace()
Added test for read-only select_folder()
Fixed rename live test so that it uses folder namespaces (#100).
Parse STATUS responses robustly - fixes folder_status() with MS Exchange.
Numerous livetest fixes to work around oddities with the MS Exchange IMAP implementation.
IMAPClient wasn't installing on Windows due to an extra trailing slash in MANIFEST.in (#102). This is a bug in distutils.
IMAPClient wasn't installing on Windows due to an extra trailing slash in MANIFEST.in (#102). This is a bug in distutils.
MANIFEST.in was fixed so that the main documentation index file is included the source distribution.
distribute_setup.py was updated to the 0.6.24 version.
This release also contains some small documentation fixes.
OAUTH authentication is now supported using the oauth_login method. This requires the 3rd party oauth2 package is installed. Thanks to Johannes Heckel
OAUTH authentication is now supported using the oauth_login method. This requires the 3rd party oauth2 package is installed. Thanks to Johannes Heckel for contributing the patch to this.
The IDLE extension is now supported through the new idle(), idle_check() and idle_done() methods. See the example in imapclient/examples/idle_example.py.
The NOOP command is now supported. It returns parsed untagged server responses in the same format as idle_check() and idle_done().
Full documentation is now available under doc/html in the source distribution and at http://imapclient.readthedocs.io/ online.
Renaming of folders was an obvious omission!
interact.py can now read livetest.py INI files (#66)
interact.py can now embed shells from ipython 0.10 and 0.11 (#98)
interact.py and livetest.py are now inside the imapclient package so they can be used even when IMAClient has been installed from PyPI (#82)
Added "debug" propety and setting of a log file (#90)
"normalise_times" attribute allows caller to select whether datetimes returned by fetch() are native or not (#96) (Thanks Andrew Scheller)
Added imapclient.version_info - a tuple that contains the IMAPClient version number broken down into it's parts.
getacl() was using wrong lexing class (#85) (Thanks josephhh)
Removed special handling for response tuples without whitespace between them. Post-process BODY/BODYSTRUCTURE responses instead. This should not affect the external API. (#91) (Thanks daishi)
Fix incorrect msg_id for UID fetch when use_uid is False (#99)
namespace() method added and get_folder_delimiter() has been deprecated.
The response values for BODY and BODYSTRUCTURE responses may include a sequence of tuples which are not separated by whitespace. These should be treated as a single item (a list of multiple arbitrarily nested tuples) but IMAPClient was treating them as separate items. IMAPClient now returns these tuples in a list to allow for consistent parsing.
A BODYSTRUCTURE response for a multipart email with 2 parts would have previously looked something like this:
(('text', 'html', ('charset', 'us-ascii'), None, None, 'quoted-printable', 55, 3),
('text', 'plain', ('charset', 'us-ascii'), None, None, '7bit', 26, 1),
'mixed', ('boundary', '===============1534046211=='))
The response is now returned like this:
([
('text', 'html', ('charset', 'us-ascii'), None, None, 'quoted-printable', 55, 3),
('text', 'plain', ('charset', 'us-ascii'), None, None, '7bit', 26, 1)
],
'mixed', ('boundary', '===============1534046211=='))
The behaviour for single part messages is unchanged. In this case the first element of the tuple is a string specifying the major content type of the message (eg "text").
An is_multipart boolean property now exists on BODY and BODYSTRUCTURE responses to allow the caller to easily determine whether the response is for a multipart message.
Code that expects the previous response handling behaviour needs to be updated.
livetest.py now uses the unittest2 package to run the tests. This provides much more flexibility that the custom approach that was used before. Dependencies between tests are gone - each test uses a fresh IMAP connection and is preceeded by the same setup.
unittest2.main() is used to provide a number of useful command line options and the ability to run a subset of tests.
IMAP account parameters are now read using a configuration file instead of command line arguments. See livetest-sample.ini for an example.
namespace() method added and get_folder_delimiter() has been deprecated.
The fetch method now takes optional modifiers as the last argument. These are required for extensions such as RFC 4551 (conditional store). Thanks to Thomas Jost for the patch.
Square brackets in responses now parsed correctly
This fixes response handling for FETCH items such as BODY[HEADER.FIELDS (from subject)].
The example has been moved to imapclient/examples directory and is included when the IMAPClient is installed from PyPI.
The project is now packaged using Distribute instead of setuptools. There should be no real functional change.
Automatically patch a bug in imaplib which can cause hangs when using SSL (Python Issue 5949). The patch is only applied when the running Python versi
Automatically patch a bug in imaplib which can cause hangs when using SSL (Python Issue 5949). The patch is only applied when the running Python version is known to be affected by the problem.
Updated the README to better reflect the current state of the project.
Command response lexing and parsing code rewritten from stratch to deal with various bugs that surfaced when dealing with more complex responses (eg.
Command response lexing and parsing code rewritten from stratch to deal with various bugs that surfaced when dealing with more complex responses (eg. BODYSTRUCTURE and ENVELOPE). This change also fixes various problems when interacting with Gmail and MS Exchange.
Where the server supports it, xlist_folders() will return a mapping of various common folder names to the actual server folder names. Gmail's IMAP server supports this.
New copy() method.
A script for interactive IMAPClient sessions. Useful for debugging and exploration. Uses IPython if installed.
select_folder() now returns a dictionary with the full (parsed) SELECT command response instead of just the message count.
The return value from list_folders(), list_sub_folders() and xlist_folders() now include the IMAP folder flags and delimiter.
Bytes that are greater than 0x7f in folder names are will cause an exception when passed to methods that accept folder name arguments because there is no unambigous way to handle these. Callers should encode such folder names to unicode objects first.
Folder names are now always returned as unicode objects.
Fetch responses now include a "SEQ" element which gives the message (non-UID) sequence number. This allows for easy mapping between UIDs and standard sequence IDs.
Various folder name handling bugs fixed.
Folder name quoting and escaping fixes
Correctly handle double quotes and backslashes in folder names when parsing LIST and LSUB responses.
Fixed problem with parsing responses where a literal followed another literal.
Changed license from GPL to new BSD.
Changed license from GPL to new BSD.
Support for SSL based connections by passing ssl=True when constructing an IMAPClient instance.
Support for SSL based connections by passing ssl=True when constructing an IMAPClient instance.
Folder names are now encoded and decoded transparently if required (using modified UTF-7). This means that any methods that return folder names may return unicode objects as well as normal strings [API CHANGE]. Additionally, any method that takes a folder name now accepts unicode object too. Use the folder_encode attribute to control whether encode/decoding is performed.
Unquoted folder names in server responses are now handled correctly. Thanks to Neil Martinsen-Burrell for reporting this bug.
Fixed a bug with handling of unusual characters in folder names.
Timezones are now handled correctly for datetimes passed as input and for server responses. This fixes a number of bugs with timezones. Returned datetimes are always in the client's local timezone.
Many more unit tests added, some using Michael Foord's excellent mock.py. (http://www.voidspace.org.uk/python/mock/)
Nothing published for this version
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →