Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update examples to reflect recent changes
- Loading branch information
Nicolas Le Manchet
committed
Aug 31, 2017
1 parent
6330970
commit 826ab8e
Showing
5 changed files
with
58 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
# This example is a lot more interesting if you have an active client | ||
# connected to the same IMAP account! | ||
|
||
from __future__ import unicode_literals | ||
|
||
from imapclient import IMAPClient | ||
|
||
HOST = 'imap.host.com' | ||
USERNAME = 'someuser' | ||
PASSWORD = 'password' | ||
ssl = True | ||
|
||
server = IMAPClient(HOST, use_uid=True, ssl=ssl) | ||
server.login(USERNAME, PASSWORD) | ||
server.select_folder('INBOX') | ||
|
||
# Start IDLE mode | ||
server.idle() | ||
|
||
# Wait for up to 30 seconds for an IDLE response | ||
responses = server.idle_check(timeout=30) | ||
print(responses) | ||
|
||
# Come out of IDLE mode | ||
text, responses = server.idle_done() | ||
print('IDLE done. Server said %r' % text) | ||
print('Final responses: ', responses) | ||
|
||
print(server.logout()) | ||
# Open a connection in IDLE mode and wait for notifications from the server | ||
|
||
from imapclient import IMAPClient | ||
|
||
HOST = 'imap.host.com' | ||
USERNAME = 'someuser' | ||
PASSWORD = 'password' | ||
|
||
server = IMAPClient(HOST) | ||
server.login(USERNAME, PASSWORD) | ||
server.select_folder('INBOX') | ||
|
||
# Start IDLE mode | ||
server.idle() | ||
print("Connection is now in IDLE mode, send yourself an email or quit with ^c") | ||
|
||
while True: | ||
try: | ||
# Wait for up to 30 seconds for an IDLE response | ||
responses = server.idle_check(timeout=30) | ||
print("Server sent:", responses if responses else "nothing") | ||
except KeyboardInterrupt: | ||
break | ||
|
||
server.idle_done() | ||
print("\nIDLE mode done") | ||
server.logout() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
# Copyright (c) 2015, Menno Smits | ||
# Released subject to the New BSD License | ||
# Please see http://en.wikipedia.org/wiki/BSD_licenses | ||
# | ||
# Establish a secure connection to a server that does not have a certificate | ||
# signed by a trusted authority. | ||
|
||
from __future__ import unicode_literals | ||
import imapclient | ||
import ssl | ||
|
||
from imapclient import IMAPClient | ||
|
||
HOST = 'imap.host.com' | ||
USERNAME = 'someuser' | ||
PASSWORD = 'secret' | ||
|
||
context = imapclient.create_default_context(cafile="/path/to/cacert.pem") | ||
ssl_context = ssl.create_default_context(cafile="/path/to/cacert.pem") | ||
|
||
server = imapclient.IMAPClient(HOST, use_uid=True, ssl=True, ssl_context=context) | ||
server.login(USERNAME, PASSWORD) | ||
# ... | ||
with IMAPClient(HOST, ssl_context=ssl_context) as server: | ||
server.login(USERNAME, PASSWORD) | ||
# ...do something... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
# Copyright (c) 2015, Menno Smits | ||
# Released subject to the New BSD License | ||
# Please see http://en.wikipedia.org/wiki/BSD_licenses | ||
# | ||
# Establish an encrypted connection to a server without checking its | ||
# certificate. This setup is insecure, DO NOT USE to connect to servers | ||
# over the Internet. | ||
|
||
from __future__ import unicode_literals | ||
import imapclient | ||
from backports import ssl | ||
import ssl | ||
|
||
from imapclient import IMAPClient | ||
|
||
HOST = 'imap.host.com' | ||
USERNAME = 'someuser' | ||
PASSWORD = 'secret' | ||
|
||
context = imapclient.create_default_context() | ||
ssl_context = ssl.create_default_context() | ||
|
||
# don't check if certificate hostname doesn't match target hostname | ||
context.check_hostname = False | ||
ssl_context.check_hostname = False | ||
|
||
# don't check if the certificate is trusted by a certificate authority | ||
context.verify_mode = ssl.CERT_NONE | ||
ssl_context.verify_mode = ssl.CERT_NONE | ||
|
||
server = imapclient.IMAPClient(HOST, use_uid=True, ssl=True, ssl_context=context) | ||
server.login(USERNAME, PASSWORD) | ||
# ... | ||
with IMAPClient(HOST, ssl_context=ssl_context) as server: | ||
server.login(USERNAME, PASSWORD) | ||
# ...do something... |