Mercurial > libervia-backend
comparison src/plugins/plugin_misc_maildir.py @ 622:9a8fbf0e8691
pluging maildir: some trivial fixes:
- path is now (local dir)/maildir/(profile name) instead of directly (profile name)
- removed forgotten breakpoint
- use of MaildirError instead of the inexistant MailboxException
- fixed some forgotten "self."
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 20 Jun 2013 12:37:06 +0200 |
parents | 84a6e83157c2 |
children | 8004c7d4aba7 |
comparison
equal
deleted
inserted
replaced
621:0e16288d6816 | 622:9a8fbf0e8691 |
---|---|
28 import email.message | 28 import email.message |
29 from email.charset import Charset | 29 from email.charset import Charset |
30 import os | 30 import os |
31 from cStringIO import StringIO | 31 from cStringIO import StringIO |
32 from twisted.internet import reactor | 32 from twisted.internet import reactor |
33 import pdb | |
34 from sat.core.exceptions import ProfileUnknownError | 33 from sat.core.exceptions import ProfileUnknownError |
35 from sat.memory.persistent import PersistentBinaryDict | 34 from sat.memory.persistent import PersistentBinaryDict |
36 | 35 |
37 from zope.interface import implements | 36 from zope.interface import implements |
38 | 37 |
126 if boxname not in self.__mailboxes: | 125 if boxname not in self.__mailboxes: |
127 err_msg = _("Trying to remove an mailboxUser not referenced") | 126 err_msg = _("Trying to remove an mailboxUser not referenced") |
128 error(_("INTERNAL ERROR: ") + err_msg) | 127 error(_("INTERNAL ERROR: ") + err_msg) |
129 raise MaildirError(err_msg) | 128 raise MaildirError(err_msg) |
130 assert self.__mailboxes[profile][boxname] == mailboxUser | 129 assert self.__mailboxes[profile][boxname] == mailboxUser |
131 del __mailboxes[profile][boxname] | 130 del self.__mailboxes[profile][boxname] |
132 | 131 |
133 def _checkBoxReference(self, boxname, profile): | 132 def _checkBoxReference(self, boxname, profile): |
134 """Check if there is a reference on a box, and return it | 133 """Check if there is a reference on a box, and return it |
135 @param boxname: name of the box to check | 134 @param boxname: name of the box to check |
136 @return: MailboxUser instance or None""" | 135 @return: MailboxUser instance or None""" |
209 @param boxname: name of the box where the message is | 208 @param boxname: name of the box where the message is |
210 @param message_idx: message id as given by MaildirMailbox | 209 @param message_idx: message id as given by MaildirMailbox |
211 @return: list of strings""" | 210 @return: list of strings""" |
212 box_data = self.__getBoxData(boxname, profile) | 211 box_data = self.__getBoxData(boxname, profile) |
213 if mess_id not in box_data: | 212 if mess_id not in box_data: |
214 raise MailboxException("Trying to get flags from an unexisting message") | 213 raise MaildirError("Trying to get flags from an unexisting message") |
215 return box_data[mess_id][1] | 214 return box_data[mess_id][1] |
216 | 215 |
217 def setFlags(self, boxname, mess_id, flags, profile): | 216 def setFlags(self, boxname, mess_id, flags, profile): |
218 """Change the flags of the message | 217 """Change the flags of the message |
219 @param boxname: name of the box where the message is | 218 @param boxname: name of the box where the message is |
222 """ | 221 """ |
223 box_data = self.__getBoxData(boxname, profile) | 222 box_data = self.__getBoxData(boxname, profile) |
224 assert(type(flags) == list) | 223 assert(type(flags) == list) |
225 flags = [flag.upper() for flag in flags] # we store every flag UPPERCASE | 224 flags = [flag.upper() for flag in flags] # we store every flag UPPERCASE |
226 if mess_id not in box_data: | 225 if mess_id not in box_data: |
227 raise MailboxException("Trying to set flags for an unexisting message") | 226 raise MaildirError("Trying to set flags for an unexisting message") |
228 box_data[mess_id][1] = flags | 227 box_data[mess_id][1] = flags |
229 self.data[profile].force(boxname) | 228 self.data[profile].force(boxname) |
230 | 229 |
231 def getMessageIdsWithFlag(self, boxname, flag, profile): | 230 def getMessageIdsWithFlag(self, boxname, flag, profile): |
232 """Return ids of messages where a flag is set | 231 """Return ids of messages where a flag is set |
332 @param name: name of the mailbox | 331 @param name: name of the mailbox |
333 @param profile: real profile (ie not a profile_key) | 332 @param profile: real profile (ie not a profile_key) |
334 THIS OBJECT MUST NOT BE USED DIRECTLY: use MaildirBox.accessMessageBox instead""" | 333 THIS OBJECT MUST NOT BE USED DIRECTLY: use MaildirBox.accessMessageBox instead""" |
335 if _maildir._checkBoxReference(name, profile): | 334 if _maildir._checkBoxReference(name, profile): |
336 error("INTERNAL ERROR: MailboxUser MUST NOT be instancied directly") | 335 error("INTERNAL ERROR: MailboxUser MUST NOT be instancied directly") |
337 raise MailboxException('double MailboxUser instanciation') | 336 raise MaildirError('double MailboxUser instanciation') |
338 if name != "INBOX": | 337 if name != "INBOX": |
339 raise NotImplementedError | 338 raise NotImplementedError |
340 self.name = name | 339 self.name = name |
341 self.profile = profile | 340 self.profile = profile |
342 self.maildir = _maildir | 341 self.maildir = _maildir |
343 profile_path = self.maildir._getProfilePath(profile) | 342 profile_path = self.maildir._getProfilePath(profile) |
344 full_profile_path = os.path.join(self.maildir.host.memory.getConfig('', 'local_dir'), profile_path) | 343 full_profile_path = os.path.join(self.maildir.host.memory.getConfig('', 'local_dir'), 'maildir', profile_path) |
345 if not os.path.exists(full_profile_path): | 344 if not os.path.exists(full_profile_path): |
346 os.makedirs(full_profile_path, 0700) | 345 os.makedirs(full_profile_path, 0700) |
347 mailbox_path = os.path.join(full_profile_path, MAILDIR_PATH) | 346 mailbox_path = os.path.join(full_profile_path, MAILDIR_PATH) |
348 self.mailbox_path = mailbox_path | 347 self.mailbox_path = mailbox_path |
349 self.mailbox = maildir.MaildirMailbox(mailbox_path) | 348 self.mailbox = maildir.MaildirMailbox(mailbox_path) |
361 existant_id.append(self.getId(mess_idx)) | 360 existant_id.append(self.getId(mess_idx)) |
362 self.getUid(mess_idx) | 361 self.getUid(mess_idx) |
363 self.maildir.cleanTable(self.name, existant_id, profile=self.profile) | 362 self.maildir.cleanTable(self.name, existant_id, profile=self.profile) |
364 | 363 |
365 def __del__(self): | 364 def __del__(self): |
366 if observer: | 365 if self.observer: |
367 debug("removing observer for %s" % self.name) | 366 debug("removing observer for %s" % self.name) |
368 self._maildir.removeObserver(observer, self.name, "NEW_MESSAGE") | 367 self._maildir.removeObserver(self.observer, self.name, "NEW_MESSAGE") |
369 self.maildir._removeBoxAccess(self.name, self, profile=self.profile) | 368 self.maildir._removeBoxAccess(self.name, self, profile=self.profile) |
370 | 369 |
371 def addMessage(self, message): | 370 def addMessage(self, message): |
372 """Add a message to the box | 371 """Add a message to the box |
373 @param message: XMPP XML message""" | 372 @param message: XMPP XML message""" |
481 self.mailbox = maildir.MaildirMailbox(self.mailbox_path) # We need to reparse the dir to have coherent indexing | 480 self.mailbox = maildir.MaildirMailbox(self.mailbox_path) # We need to reparse the dir to have coherent indexing |
482 self.maildir.purgeDeleted(self.name, profile=self.profile) | 481 self.maildir.purgeDeleted(self.name, profile=self.profile) |
483 | 482 |
484 def emptyTrash(self): | 483 def emptyTrash(self): |
485 """Delete everything in the .Trash dir""" | 484 """Delete everything in the .Trash dir""" |
486 import shutils | 485 pass #TODO |
487 pdb.set_trace() |