Commits

Josh VanderLinden committed c9ab023

Refactored some of the default port guessing code for articles from email

Comments (0)

Files changed (1)

articles/management/commands/check_for_articles_from_email.py

         self.ssl = ssl
         self._handle = None
 
+        if self.port is None:
+            if self.ssl:
+                self.port = self.secure_port
+            else:
+                self.port = self.unsecure_port
+
     @property
     def handle(self):
         if not self._handle:
 
 class IMAPHandler(MailboxHandler):
 
+    @property
+    def secure_port(self):
+        return 993
+
+    @property
+    def unsecure_port(self):
+        return 143
+
     def connect(self):
         """Connects to and authenticates with an IMAP4 mail server"""
 
 
 class POPHandler(MailboxHandler):
 
+    @property
+    def secure_port(self):
+        return 995
+
+    @property
+    def unsecure_port(self):
+        return 110
+
     def connect(self):
         """Connects to and authenticates with a POP3 mail server"""
 
 
         self.verbosity = int(options.get('verbosity', 1))
 
-        # try to guess if we don't have a port
-        if port is None:
-            if protocol == MB_IMAP4:
-                if ssl:
-                    port = 993
-                else:
-                    port = 143
-            elif protocol == MB_POP3:
-                if ssl:
-                    port = 995
-                else:
-                    port = 110
-
         handle = None
         try:
             handle = self.get_mail_handle(protocol, host, port, username, password, keyfile, certfile, ssl)