Mercurial > libervia-backend
diff src/plugins/plugin_misc_imap.py @ 993:301b342c697a
core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 19:19:19 +0200 |
parents | bfabeedbf32e |
children | f91e7028e2c3 |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_imap.py Sat Apr 19 16:48:26 2014 +0200 +++ b/src/plugins/plugin_misc_imap.py Sat Apr 19 19:19:19 2014 +0200 @@ -18,20 +18,17 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from sat.core.i18n import _ -from logging import debug, info, error -import warnings +from sat.core.log import getLogger +log = getLogger(__name__) from twisted.internet import protocol, defer -from twisted.words.protocols.jabber import error as jab_error from twisted.cred import portal, checkers, credentials from twisted.cred import error as cred_error from twisted.mail import imap4 from twisted.python import failure from email.parser import Parser -import email.message import os from cStringIO import StringIO from twisted.internet import reactor -import pdb from zope.interface import implements @@ -61,14 +58,14 @@ """ def __init__(self, host): - info(_("Plugin Imap Server initialization")) + log.info(_("Plugin Imap Server initialization")) self.host = host #parameters host.memory.updateParams(self.params) port = int(self.host.memory.getParamA("IMAP Port", "Mail Server")) - info(_("Launching IMAP server on port %d"), port) + log.info(_("Launching IMAP server on port %d") % port) self.server_factory = ImapServerFactory(self.host) reactor.listenTCP(port, self.server_factory) @@ -78,7 +75,7 @@ implements(imap4.IMessage) def __init__(self, uid, flags, mess_fp): - debug('Message Init') + log.debug('Message Init') self.uid = uid self.flags = flags self.mess_fp = mess_fp @@ -87,21 +84,21 @@ def getUID(self): """Retrieve the unique identifier associated with this message. """ - debug('getUID (message)') + log.debug('getUID (message)') return self.uid def getFlags(self): """Retrieve the flags associated with this message. @return: The flags, represented as strings. """ - debug('getFlags') + log.debug('getFlags') return self.flags def getInternalDate(self): """Retrieve the date internally associated with this message. @return: An RFC822-formatted date string. """ - debug('getInternalDate') + log.debug('getInternalDate') return self.message['Date'] def getHeaders(self, negate, *names): @@ -111,7 +108,7 @@ should be omitted from the return value, rather than included. @return: A mapping of header field names to header field values """ - debug('getHeaders %s - %s' % (negate, names)) + log.debug('getHeaders %s - %s' % (negate, names)) final_dict = {} to_check = [name.lower() for name in names] for header in self.message.keys(): @@ -123,20 +120,20 @@ def getBodyFile(self): """Retrieve a file object containing only the body of this message. """ - debug('getBodyFile') + log.debug('getBodyFile') return StringIO(self.message.get_payload()) def getSize(self): """Retrieve the total size, in octets, of this message. """ - debug('getSize') + log.debug('getSize') self.mess_fp.seek(0, os.SEEK_END) return self.mess_fp.tell() def isMultipart(self): """Indicate whether this message has subparts. """ - debug('isMultipart') + log.debug('isMultipart') return False def getSubPart(self, part): @@ -144,7 +141,7 @@ @param part: The number of the part to retrieve, indexed from 0. @return: The specified sub-part. """ - debug('getSubPart') + log.debug('getSubPart') return TypeError @@ -154,14 +151,14 @@ def __init__(self, host, name, profile): self.host = host self.listeners = set() - debug('Mailbox init (%s)', name) + log.debug('Mailbox init (%s)', name) if name != "INBOX": raise imap4.MailboxException("Only INBOX is managed for the moment") self.mailbox = self.host.plugins["Maildir"].accessMessageBox(name, self.newMessage, profile) def newMessage(self): """Called when a new message is in the mailbox""" - debug("newMessage signal received") + log.debug("newMessage signal received") nb_messages = self.getMessageCount() for listener in self.listeners: listener.newMessages(nb_messages, None) @@ -169,13 +166,13 @@ def getUIDValidity(self): """Return the unique validity identifier for this mailbox. """ - debug('getUIDValidity') + log.debug('getUIDValidity') return 0 def getUIDNext(self): """Return the likely UID for the next message added to this mailbox. """ - debug('getUIDNext') + log.debug('getUIDNext') return self.mailbox.getNextUid() def getUID(self, message): @@ -183,41 +180,41 @@ @param message: The message sequence number @return: The UID of the message. """ - debug('getUID (%i)' % message) + log.debug('getUID (%i)' % message) #return self.mailbox.getUid(message-1) #XXX: it seems that this method get uid and not message sequence number return message def getMessageCount(self): """Return the number of messages in this mailbox. """ - debug('getMessageCount') + log.debug('getMessageCount') ret = self.mailbox.getMessageCount() - debug("count = %i" % ret) + log.debug("count = %i" % ret) return ret def getRecentCount(self): """Return the number of messages with the 'Recent' flag. """ - debug('getRecentCount') + log.debug('getRecentCount') return len(self.mailbox.getMessageIdsWithFlag('\\Recent')) def getUnseenCount(self): """Return the number of messages with the 'Unseen' flag. """ - debug('getUnseenCount') + log.debug('getUnseenCount') return self.getMessageCount() - len(self.mailbox.getMessageIdsWithFlag('\\SEEN')) def isWriteable(self): """Get the read/write status of the mailbox. @return: A true value if write permission is allowed, a false value otherwise. """ - debug('isWriteable') + log.debug('isWriteable') return True def destroy(self): """Called before this mailbox is deleted, permanently. """ - debug('destroy') + log.debug('destroy') def requestStatus(self, names): """Return status information about this mailbox. @@ -229,7 +226,7 @@ information up would be costly, a deferred whose callback will eventually be passed this dictionary is returned instead. """ - debug('requestStatus') + log.debug('requestStatus') return imap4.statusRequestHelper(self, names) def addListener(self, listener): @@ -239,7 +236,7 @@ @param listener: An object to add to the set of those which will be notified when the contents of this mailbox change. """ - debug('addListener %s' % listener) + log.debug('addListener %s' % listener) self.listeners.add(listener) def removeListener(self, listener): @@ -252,7 +249,7 @@ @raise ValueError: Raised when the given object is not a listener for this mailbox. """ - debug('removeListener') + log.debug('removeListener') if listener in self.listeners: self.listeners.remove(listener) else: @@ -267,7 +264,7 @@ id if the message is added successfully and whose errback is invoked otherwise. """ - debug('addMessage') + log.debug('addMessage') raise imap4.MailboxException("Client message addition not implemented yet") def expunge(self): @@ -275,7 +272,7 @@ @return: The list of message sequence numbers which were deleted, or a Deferred whose callback will be invoked with such a list. """ - debug('expunge') + log.debug('expunge') self.mailbox.removeDeleted() def fetch(self, messages, uid): @@ -284,13 +281,13 @@ about @param uid: If true, the IDs specified in the query are UIDs; """ - debug('fetch (%s, %s)' % (messages, uid)) + log.debug('fetch (%s, %s)' % (messages, uid)) if uid: messages.last = self.mailbox.getMaxUid() messages.getnext = self.mailbox.getNextExistingUid for mess_uid in messages: if mess_uid is None: - debug('stopping iteration') + log.debug('stopping iteration') raise StopIteration try: yield (mess_uid, Message(mess_uid, self.mailbox.getFlagsUid(mess_uid), self.mailbox.getMessageUid(mess_uid))) @@ -318,7 +315,7 @@ been performed, or a Deferred whose callback will be invoked with such a dict. """ - debug('store') + log.debug('store') flags = [flag.upper() for flag in flags] @@ -361,13 +358,13 @@ Flags with the \\ prefix are reserved for use as system flags. @return: A list of the flags that can be set on messages in this mailbox. """ - debug('getFlags') + log.debug('getFlags') return ['\\SEEN', '\\ANSWERED', '\\FLAGGED', '\\DELETED', '\\DRAFT'] # TODO: add '\\RECENT' def getHierarchicalDelimiter(self): """Get the character which delimits namespaces for in this mailbox. """ - debug('getHierarchicalDelimiter') + log.debug('getHierarchicalDelimiter') return '.' @@ -375,12 +372,12 @@ #implements(imap4.IAccount) def __init__(self, host, profile): - debug("ImapAccount init") + log.debug("ImapAccount init") self.host = host self.profile = profile imap4.MemoryAccount.__init__(self, profile) self.addMailbox("Inbox") # We only manage Inbox for the moment - debug('INBOX added') + log.debug('INBOX added') def _emptyMailbox(self, name, id): return SatMailbox(self.host, name, self.profile) @@ -393,7 +390,7 @@ self.host = host def requestAvatar(self, avatarID, mind, *interfaces): - debug('requestAvatar') + log.debug('requestAvatar') profile = avatarID.decode('utf-8') if imap4.IAccount not in interfaces: raise NotImplementedError @@ -436,13 +433,13 @@ self.host = host def startedConnecting(self, connector): - debug(_("IMAP server connection started")) + log.debug(_("IMAP server connection started")) def clientConnectionLost(self, connector, reason): - debug(_("IMAP server connection lost (reason: %s)"), reason) + log.debug(_("IMAP server connection lost (reason: %s)"), reason) def buildProtocol(self, addr): - debug("Building protocol") + log.debug("Building protocol") prot = protocol.ServerFactory.buildProtocol(self, addr) prot.portal = portal.Portal(ImapRealm(self.host)) prot.portal.registerChecker(SatProfileCredentialChecker(self.host))