comparison src/plugins/plugin_misc_maildir.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents 2a072735e459
children beaf6bec2fcd
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
55 55
56 class MaildirError(Exception): 56 class MaildirError(Exception):
57 pass 57 pass
58 58
59 class MaildirBox(): 59 class MaildirBox():
60 60
61 def __init__(self, host): 61 def __init__(self, host):
62 info(_("Plugin Maildir initialization")) 62 info(_("Plugin Maildir initialization"))
63 self.host = host 63 self.host = host
64 64
65 self.__observed={} 65 self.__observed={}
182 while self.getIdFromUid(boxname, idx, profile) == None: #TODO: this is highly inefficient because getIdfromUid is inefficient, fix this 182 while self.getIdFromUid(boxname, idx, profile) == None: #TODO: this is highly inefficient because getIdfromUid is inefficient, fix this
183 idx+=1 183 idx+=1
184 if idx>box_data['cur_idx']: 184 if idx>box_data['cur_idx']:
185 return None 185 return None
186 return idx 186 return idx
187 187
188 def getMaxUid(self, boxname, profile): 188 def getMaxUid(self, boxname, profile):
189 """Give the max existing uid 189 """Give the max existing uid
190 @param boxname: name of the box where the message is 190 @param boxname: name of the box where the message is
191 @return: uid""" 191 @return: uid"""
192 box_data = self.__getBoxData(boxname, profile) 192 box_data = self.__getBoxData(boxname, profile)
193 return box_data['cur_idx'] 193 return box_data['cur_idx']
194 194
195 def getIdFromUid(self, boxname, message_uid, profile): 195 def getIdFromUid(self, boxname, message_uid, profile):
196 """Return the message unique id from it's integer UID 196 """Return the message unique id from it's integer UID
197 @param boxname: name of the box where the message is 197 @param boxname: name of the box where the message is
198 @param message_uid: unique integer identifier 198 @param message_uid: unique integer identifier
199 @return: unique id of the message as given by MaildirMailbox or None if not found""" 199 @return: unique id of the message as given by MaildirMailbox or None if not found"""
249 """Remove data for messages with flag "\\Deleted" 249 """Remove data for messages with flag "\\Deleted"
250 @param boxname: name of the box where the message is 250 @param boxname: name of the box where the message is
251 """ 251 """
252 box_data = self.__getBoxData(boxname, profile) 252 box_data = self.__getBoxData(boxname, profile)
253 for mess_id in self.getMessageIdsWithFlag(boxname,"\\Deleted", profile): 253 for mess_id in self.getMessageIdsWithFlag(boxname,"\\Deleted", profile):
254 del(box_data[mess_id]) 254 del(box_data[mess_id])
255 self.data[profile].force(boxname) 255 self.data[profile].force(boxname)
256 256
257 def cleanTable(self, boxname, existant_id, profile): 257 def cleanTable(self, boxname, existant_id, profile):
258 """Remove mails which no longuer exist from the table 258 """Remove mails which no longuer exist from the table
259 @param boxname: name of the box to clean 259 @param boxname: name of the box to clean
260 @param existant_id: list of id which actually exist""" 260 @param existant_id: list of id which actually exist"""
261 box_data = self.__getBoxData(boxname, profile) 261 box_data = self.__getBoxData(boxname, profile)
263 for key in box_data: 263 for key in box_data:
264 if key not in existant_id and key!="cur_idx": 264 if key not in existant_id and key!="cur_idx":
265 to_remove.append(key) 265 to_remove.append(key)
266 for key in to_remove: 266 for key in to_remove:
267 del box_data[key] 267 del box_data[key]
268 268
269 def addObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"): 269 def addObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"):
270 """Add an observer for maildir box changes 270 """Add an observer for maildir box changes
271 @param callback: method to call when the the box is updated 271 @param callback: method to call when the the box is updated
272 @param boxname: name of the box to observe 272 @param boxname: name of the box to observe
273 @param signal: which signal is observed by the caller""" 273 @param signal: which signal is observed by the caller"""
325 if e.name == "body": 325 if e.name == "body":
326 mail.set_payload(e.children[0].encode('utf-8')) 326 mail.set_payload(e.children[0].encode('utf-8'))
327 elif e.name == "subject": 327 elif e.name == "subject":
328 mail['Subject'] = e.children[0].encode('utf-8') 328 mail['Subject'] = e.children[0].encode('utf-8')
329 return mail.as_string() 329 return mail.as_string()
330 330
331 def __init__(self, _maildir, name, observer=None, profile="@NONE@"): 331 def __init__(self, _maildir, name, observer=None, profile="@NONE@"):
332 """@param _maildir: the main MaildirBox instance 332 """@param _maildir: the main MaildirBox instance
333 @param name: name of the mailbox 333 @param name: name of the mailbox
334 @param profile: real profile (ie not a profile_key) 334 @param profile: real profile (ie not a profile_key)
335 THIS OBJECT MUST NOT BE USED DIRECTLY: use MaildirBox.accessMessageBox instead""" 335 THIS OBJECT MUST NOT BE USED DIRECTLY: use MaildirBox.accessMessageBox instead"""
348 mailbox_path = os.path.join(full_profile_path, MAILDIR_PATH) 348 mailbox_path = os.path.join(full_profile_path, MAILDIR_PATH)
349 self.mailbox_path=mailbox_path 349 self.mailbox_path=mailbox_path
350 self.mailbox = maildir.MaildirMailbox(mailbox_path) 350 self.mailbox = maildir.MaildirMailbox(mailbox_path)
351 self.observer=observer 351 self.observer=observer
352 self.__uid_table_update() 352 self.__uid_table_update()
353 353
354 if observer: 354 if observer:
355 debug("adding observer for %s (%s)" % (name,profile)) 355 debug("adding observer for %s (%s)" % (name,profile))
356 self.maildir.addObserver(observer, profile, name, "NEW_MESSAGE") 356 self.maildir.addObserver(observer, profile, name, "NEW_MESSAGE")
357 357
358 def __uid_table_update(self): 358 def __uid_table_update(self):
360 for mess_idx in range (self.getMessageCount()): 360 for mess_idx in range (self.getMessageCount()):
361 #we update the uid table 361 #we update the uid table
362 existant_id.append(self.getId(mess_idx)) 362 existant_id.append(self.getId(mess_idx))
363 self.getUid(mess_idx) 363 self.getUid(mess_idx)
364 self.maildir.cleanTable(self.name, existant_id, profile=self.profile) 364 self.maildir.cleanTable(self.name, existant_id, profile=self.profile)
365 365
366 366
367 def __del__(self): 367 def __del__(self):
368 if observer: 368 if observer:
369 debug("removing observer for %s" % self.name) 369 debug("removing observer for %s" % self.name)
370 self._maildir.removeObserver(observer, self.name, "NEW_MESSAGE") 370 self._maildir.removeObserver(observer, self.name, "NEW_MESSAGE")
415 @return: message index, as managed by MaildirMailbox""" 415 @return: message index, as managed by MaildirMailbox"""
416 for mess_idx in range (self.getMessageCount()): 416 for mess_idx in range (self.getMessageCount()):
417 if self.getUid(mess_idx) == mess_uid: 417 if self.getUid(mess_idx) == mess_uid:
418 return mess_idx 418 return mess_idx
419 raise IndexError 419 raise IndexError
420 420
421 def getIdxFromId(self, mess_id): 421 def getIdxFromId(self, mess_id):
422 """Return the message index from the unique index 422 """Return the message index from the unique index
423 @param mess_id: message unique index as given by MaildirMailbox 423 @param mess_id: message unique index as given by MaildirMailbox
424 @return: message sequence index""" 424 @return: message sequence index"""
425 for mess_idx in range (self.getMessageCount()): 425 for mess_idx in range (self.getMessageCount()):
426 if self.mailbox.getUidl(mess_idx) == mess_id: 426 if self.mailbox.getUidl(mess_idx) == mess_id:
427 return mess_idx 427 return mess_idx
428 raise IndexError 428 raise IndexError
429 429
430 def getMessage(self, mess_idx): 430 def getMessage(self, mess_idx):
431 """Return the full message 431 """Return the full message
432 @param mess_idx: message index""" 432 @param mess_idx: message index"""
433 return self.mailbox.getMessage(mess_idx) 433 return self.mailbox.getMessage(mess_idx)
434 434
441 """Return the flags of the message 441 """Return the flags of the message
442 @param mess_idx: message index 442 @param mess_idx: message index
443 @return: list of strings""" 443 @return: list of strings"""
444 id = self.getId(mess_idx) 444 id = self.getId(mess_idx)
445 return self.maildir.getFlags(self.name, id, profile=self.profile) 445 return self.maildir.getFlags(self.name, id, profile=self.profile)
446 446
447 def getFlagsUid(self, mess_uid): 447 def getFlagsUid(self, mess_uid):
448 """Return the flags of the message 448 """Return the flags of the message
449 @param mess_uid: message unique identifier 449 @param mess_uid: message unique identifier
450 @return: list of strings""" 450 @return: list of strings"""
451 id = self.maildir.getIdFromUid(self.name,mess_uid, profile=self.profile) 451 id = self.maildir.getIdFromUid(self.name,mess_uid, profile=self.profile)
485 485
486 def emptyTrash(self): 486 def emptyTrash(self):
487 """Delete everything in the .Trash dir""" 487 """Delete everything in the .Trash dir"""
488 import shutils 488 import shutils
489 pdb.set_trace() 489 pdb.set_trace()
490 490