Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_tls(server):
"""No login should be possible over non-TLS"""
conn = imapclient.IMAPClient(server, 143, ssl=False)
assert login_error_code("obiwan@jedi.local", conn=conn) == "PRIVACYREQUIRED"
def testserver(aserver, aport, auser, apassword):
"""Do work"""
server = IMAPClient(aserver, aport, use_uid=True, ssl=False)
print "Logging in"
try:
server.login(auser, apassword)
except Exception:
print "\n *** Something has gone horribly wrong ***\n"
else:
print "\n Great Success !\n"
pass
select_info = server.select_folder('INBOX')
print '%d messages in INBOX' % select_info['EXISTS']
messages = server.search(['NOT DELETED'])
print "%d messages that aren't deleted" % len(messages)
print "\n Message Summary:"
def main():
try:
hostname, username, foldername = sys.argv[1:]
except ValueError:
print('usage: %s hostname username folder' % sys.argv[0])
sys.exit(2)
c = IMAPClient(hostname, ssl=True)
try:
c.login(username, getpass.getpass())
except c.Error as e:
print('Could not log in:', e)
sys.exit(1)
c.select_folder(foldername, readonly=True)
msgdict = c.fetch('1:*', ['BODY.PEEK[]'])
for message_id, message in list(msgdict.items()):
e = email.message_from_string(message['BODY[]'])
print(message_id, e['From'])
payload = e.get_payload()
if isinstance(payload, list):
part_content_types = [ part.get_content_type() for part in payload ]
print(' Parts:', ' '.join(part_content_types))
else:
try:
notification_folder.login(options.notifications_user, options.notifications_pw)
except:
print("CAN'T LOG IN TO IMAP SERVER")
exit(10)
time.sleep(1)
notification_folder.select_folder(options.notifications_folder_name)
kwargs = {"use_uid": True, "ssl": options.digests_ssl}
if not old_imapclient and options.digests_cert_check_skip:
digests_context = None
digests_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
digests_context.check_hostname = False
digests_context.verify_mode = ssl.CERT_NONE
kwargs["ssl_context"] = digests_context
digests_folder = IMAPClient(options.digests_imap, **kwargs)
try:
digests_folder.login(options.digests_user, options.digests_pw)
except:
time.sleep(5)
digests_folder.login(options.digests_user, options.digests_pw)
digests_folder.select_folder(options.digests_folder_name)
command = get_command()
if command is None:
digesters = []
if os.path.isfile("my_digesters_setup.py"):
from my_digesters_setup import add_digesters
else:
print("#################################################################")
# Login using OAUTH2
from imapclient import IMAPClient
# Populate these with actual values
OAUTH2_USER = '...'
OAUTH2_ACCESS_TOKEN = '...'
HOST = 'imap.host.com'
URL = "https://somedomain.com/someuser/imap/"
with IMAPClient(HOST) as server:
server.oauth2_login(URL, OAUTH2_USER, OAUTH2_ACCESS_TOKEN)
# ...do something...
# 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()
def parse(self):
use_ssl = True if self.config['EMAIL']['useSSL'] else False
server = IMAPClient(self.config['EMAIL']['servername'], ssl=use_ssl)
server.login(self.config['EMAIL']['username'], self.config['EMAIL']['password'])
logging.getLogger().debug("connected to IMAP server")
select_info = server.select_folder('INBOX')
# get list of fitting messages
messages = server.search(['NOT', 'DELETED', 'SUBJECT', self.config['EMAIL']['subject']])
logging.getLogger().info("%d email message(s) found" % len(messages))
# loop through all messages
for msgid in messages:
# download it
response = server.fetch(msgid, ['RFC822'])
msg = email.message_from_bytes(response[msgid][b'RFC822'])
self.__process_message(msg)
# delete messages?
def setup(self, client, hostname, username, password):
self._imap = IMAPClient(hostname, use_uid=True, ssl=True)
# self._imap.debug = True
self._imap.login(username, password)
self._client = client
self._folder = None
def CheckEmail():
server = IMAPClient(HOSTNAME, use_uid=True, ssl=True)
server.login(USERNAME, PASSWORD)
print('Logging in as ' + USERNAME)
select_info = server.select_folder(MAILBOX)
print('%d messages in INBOX' % select_info['EXISTS'])
folder_status = server.folder_status(MAILBOX, 'UNSEEN')
newmails = int(folder_status['UNSEEN'])
print "You have", newmails, "new emails!"
if newmails >= NEWMAIL_OFFSET:
LED_On()
else:
LED_Off()
def setupIMAP():
server = imapclient.IMAPClient(fileconfig.config.get('EMAIL','email_imap_host'), use_uid=False, ssl=True)
server.login(fileconfig.config.get('EMAIL','email_username'), fileconfig.config.get('EMAIL','email_password'))
server.select_folder('INBOX')
return server