Save password passing and normal local connection enabled
[imap-restore-mail] / src / mail_iterator.py
index e7c7f8f..12ed42d 100644 (file)
@@ -24,6 +24,8 @@ MAILBOX_RESP = re.compile(r'\((?P<flags>.*?)\) "(?P<delimiter>.*)" (?P<name>.*)'
 UIDVAL_RESP = re.compile(r'(?P<name>.*) \(UIDVALIDITY (?P<uidval>.*)\)')
 ACLS_RESP = re.compile(b'(?P<user>.*) (?P<acls>.*)')
 
+SERVER = "localhost"
+
 class MailIterator:
     """This class communicates with the e-mail server."""
 
@@ -35,27 +37,33 @@ class MailIterator:
     # logged in status
     logged_in = None
 
-    def __init__(self, username, server = "intranator.m.i2n"):
+    def __init__(self, username, password):
         """Creates a connection and a user session."""
 
         # connect to server
         try:
-            self.mail_con = imaplib.IMAP4(server)
-            # MODIFIED
-            imap_socket = socket.socket(socket.AF_UNIX)
-            imap_socket.connect("/var/imap/socket/imap")
-            self.mail_con.sock = imap_socket
-            self.mail_con.file = self.mail_con.sock.makefile('rb')
-            logging.info("Connected to mail server %s", server)
+            self.mail_con = imaplib.IMAP4(SERVER)
+
+            # socket functionality (currently unavailable)
+            #imap_socket = socket.socket(socket.AF_UNIX)
+            #imap_socket.connect("/var/imap/socket/imap")
+            #self.mail_con.sock = imap_socket
+            #self.mail_con.file = self.mail_con.sock.makefile('rb')
+
+            logging.info("Connected to %s", SERVER)
         except (socket.error, self.mail_con.error) as ex:
             logging.error("Could not connect to host: %s", ex)
             sys.exit()
 
         # log in
         try:
-            self.mail_con.login("cyrus", "geheim")
-            self.logged_in = True
+
+            # proxy authentication
+            #self.mail_con.login("cyrus", "geheim")
             #self.mail_con.proxyauth(username)
+
+            self.mail_con.login(username, password)
+            self.logged_in = True
             logging.info("Logged in as %s.", username)
         except self.mail_con.error as ex:
             self.logged_in = False