mirror of
https://github.com/pulb/mailnag.git
synced 2026-05-06 23:47:11 +02:00
Don't allow to re-open accounts (hack, not needed anymore)
This commit is contained in:
@@ -39,10 +39,8 @@ class MailboxBackend(object):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def open(self, reopen):
|
||||
"""Opens the mailbox.
|
||||
If reopen is true, mailbox should first be closed and then opened.
|
||||
"""
|
||||
def open(self):
|
||||
"""Opens the mailbox."""
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@@ -32,6 +32,7 @@ import re
|
||||
from Mailnag.backends.base import MailboxBackend
|
||||
import Mailnag.common.imaplib2 as imaplib
|
||||
from Mailnag.common.imaplib2 import AUTH
|
||||
from Mailnag.common.exceptions import InvalidOperationException
|
||||
|
||||
|
||||
class IMAPMailboxBackend(MailboxBackend):
|
||||
@@ -51,12 +52,11 @@ class IMAPMailboxBackend(MailboxBackend):
|
||||
self._conn_closed = True
|
||||
|
||||
|
||||
def open(self, reopen):
|
||||
# try to reuse existing connection
|
||||
if not reopen and self.is_open():
|
||||
return
|
||||
def open(self):
|
||||
if self._conn != None:
|
||||
raise InvalidOperationException("Account is aready open")
|
||||
|
||||
self._conn = conn = None
|
||||
conn = None
|
||||
|
||||
try:
|
||||
if self.ssl:
|
||||
@@ -149,7 +149,7 @@ class IMAPMailboxBackend(MailboxBackend):
|
||||
|
||||
# Always create a new connection as an existing one may
|
||||
# be used for IMAP IDLE.
|
||||
self.open(reopen = True)
|
||||
self.open()
|
||||
|
||||
try:
|
||||
status, data = self._conn.list('', '*')
|
||||
|
||||
@@ -30,6 +30,7 @@ import logging
|
||||
import poplib
|
||||
|
||||
from Mailnag.backends.base import MailboxBackend
|
||||
from Mailnag.common.exceptions import InvalidOperationException
|
||||
|
||||
|
||||
class POP3MailboxBackend(MailboxBackend):
|
||||
@@ -47,12 +48,11 @@ class POP3MailboxBackend(MailboxBackend):
|
||||
self._conn = None
|
||||
|
||||
|
||||
def open(self, reopen):
|
||||
# try to reuse existing connection
|
||||
if not reopen and self.is_open():
|
||||
return
|
||||
|
||||
self._conn = conn = None
|
||||
def open(self):
|
||||
if self._conn != None:
|
||||
raise InvalidOperationException("Account is aready open")
|
||||
|
||||
conn = None
|
||||
|
||||
try:
|
||||
if self.ssl:
|
||||
|
||||
@@ -67,9 +67,9 @@ class Account:
|
||||
self.backend = backend
|
||||
|
||||
|
||||
def open(self, reopen = True):
|
||||
def open(self):
|
||||
"""Open mailbox for the account."""
|
||||
self.backend.open(reopen = reopen)
|
||||
self.backend.open()
|
||||
|
||||
|
||||
def close(self):
|
||||
@@ -79,11 +79,6 @@ class Account:
|
||||
|
||||
# Indicates whether the account
|
||||
# holds an active existing connection.
|
||||
# Note: this method only indicates if the
|
||||
# account *holds* (caches) an existing connection.
|
||||
# There may be further, but no longer
|
||||
# associated connections if open()
|
||||
# was called multiple times (with reopen set to False).
|
||||
def is_open(self):
|
||||
"""Returns true if the mailbox is opened."""
|
||||
return self.backend.is_open()
|
||||
|
||||
@@ -62,9 +62,9 @@ class Idler(object):
|
||||
|
||||
# idle thread
|
||||
def _idle(self):
|
||||
# reopen = False:
|
||||
# mailbox has been opened in mailnagdaemon.py already (immediate check)
|
||||
self._account.open(reopen = False)
|
||||
if not self._account.is_open():
|
||||
self._account.open()
|
||||
|
||||
while True:
|
||||
# if the event is set here,
|
||||
@@ -110,7 +110,7 @@ class Idler(object):
|
||||
while (not self._account.is_open()) and (not self._event.isSet()):
|
||||
logging.info("Trying to reconnect Idler thread for account '%s'." % self._account.name)
|
||||
try:
|
||||
self._account.open(reopen = True)
|
||||
self._account.open()
|
||||
logging.info("Successfully reconnected Idler thread for account '%s'." % self._account.name)
|
||||
except Exception as ex:
|
||||
logging.error("Failed to reconnect Idler thread for account '%s' (%s)." % (self._account.name, ex))
|
||||
|
||||
@@ -62,9 +62,10 @@ class MailCollector:
|
||||
mail_ids = {}
|
||||
|
||||
for acc in self._accounts:
|
||||
# open mailbox for this account
|
||||
# open mailbox for this account
|
||||
try:
|
||||
acc.open(reopen = False)
|
||||
if not acc.is_open():
|
||||
acc.open()
|
||||
except Exception as ex:
|
||||
logging.error("Failed to open mailbox for account '%s' (%s)." % (acc.name, ex))
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user