Copyright (c) 2012 Intra2net AG
'''
-import imaplib
+import socket, imaplib_private as imaplib
import re
MAILBOX_RESP = re.compile(r'\((?P<flags>.*?)\) "(?P<delimiter>.*)" (?P<name>.*)')
# logged in status
logged_in = None
- def __init__(self, server, username, password):
+ def __init__(self, username):
"""Creates a connection and a user session."""
# connect to server
try:
- self.mail_con = imaplib.IMAP4_SSL(server)
- print("Connected to %s." % server)
+ self.mail_con = imaplib.IMAP4("intranator.m.i2n")
+ #imap_socket = socket.socket(socket.AF_UNIX)
+ #imap_socket.connect("/var/imap/socket/imap")
+ #self.mail_con.socket = imap_socket
+ print("Connected to mail server.")
except Exception as ex:
- raise UserWarning("Could not connect to host %s: %s" % (server, ex))
+ #raise UserWarning("Could not connect to host: %s" % (ex))
+ raise
# log in
try:
- self.mail_con.login(username, password)
+ self.mail_con.login("cyrus", "geheim")
self.logged_in = True
+ #self.mail_con.proxyauth(username)
print("Logged in as %s." % username)
except:
self.logged_in = False
def inject_message(self, message, mailbox, internal_date):
"""Inject a message into a mailbox."""
- result, data = self.mail_con.append(mailbox, "\\Seen", internal_date, message)
+ result, data = self.mail_con.append(mailbox, "\\Seen", internal_date, message.encode())
if result == "OK":
print("Appending message to mailbox %s" % mailbox)
else: