Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_maildir.py @ 3047:cf843dd7c345
jp (debug): new "theme" command to print colour theme according to `background` value:
fix 321
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 01 Oct 2019 22:49:11 +0200 |
parents | ab2696e34d29 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
253 | 2 # -*- coding: utf-8 -*- |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SàT plugin for managing Maildir type mail boxes |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
5 # Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) |
253 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
253 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
253 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
253 | 19 |
1837
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
20 from sat.core.i18n import D_, _ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
22 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
23 log = getLogger(__name__) |
253 | 24 import warnings |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
25 warnings.filterwarnings('ignore', 'the MimeWriter', DeprecationWarning, 'twisted') # FIXME: to be removed, see http://twistedmatrix.com/trac/ticket/4038 |
1837
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
26 from twisted.mail import maildir |
253 | 27 import email.message |
1218
3b1c5f723c4b
plugin maildir: fixes missing import
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
28 import email.utils |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
29 import os |
471 | 30 from sat.core.exceptions import ProfileUnknownError |
439
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
31 from sat.memory.persistent import PersistentBinaryDict |
253 | 32 |
33 | |
34 PLUGIN_INFO = { | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
35 C.PI_NAME: "Maildir Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
36 C.PI_IMPORT_NAME: "Maildir", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
37 C.PI_TYPE: "Misc", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
38 C.PI_PROTOCOLS: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
39 C.PI_DEPENDENCIES: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
40 C.PI_MAIN: "MaildirBox", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
41 C.PI_HANDLER: "no", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
42 C.PI_DESCRIPTION: _("""Intercept "normal" type messages, and put them in a Maildir type box""") |
253 | 43 } |
44 | |
45 MAILDIR_PATH = "Maildir" | |
1837
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
46 CATEGORY = D_("Mail Server") |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
47 NAME = D_('Block "normal" messages propagation') |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
48 # FIXME: (very) old and (very) experimental code, need a big cleaning/review or to be deprecated |
253 | 49 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
50 |
253 | 51 class MaildirError(Exception): |
52 pass | |
53 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
54 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
55 class MaildirBox(object): |
1837
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
56 params = """ |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
57 <params> |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
58 <individual> |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
59 <category name='{category_name}' label='{category_label}'> |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
60 <param name='{name}' label='{label}' value="false" type="bool" security="4" /> |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
61 </category> |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
62 </individual> |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
63 </params> |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
64 """.format(category_name=CATEGORY, |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
65 category_label=_(CATEGORY), |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
66 name=NAME, |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
67 label=_(NAME), |
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
68 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
69 |
253 | 70 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
71 log.info(_("Plugin Maildir initialization")) |
253 | 72 self.host = host |
1837
7a8a19e4fa6c
plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
73 host.memory.updateParams(self.params) |
253 | 74 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
75 self.__observed = {} |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
76 self.data = {} # list of profile spectific data. key = profile, value = PersistentBinaryDict where key=mailbox name, |
439
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
77 # and value is a dictionnary with the following value |
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
78 # - cur_idx: value of the current unique integer increment (UID) |
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
79 # - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...]) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
80 self.__mailboxes = {} # key: profile, value: {boxname: MailboxUser instance} |
253 | 81 |
259
11f71187d5e4
core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
82 #the triggers |
11f71187d5e4
core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
83 host.trigger.add("MessageReceived", self.messageReceivedTrigger) |
253 | 84 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
85 def profileConnected(self, client): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
86 """Called on client connection, create profile data""" |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
87 profile = client.profile |
439
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
88 self.data[profile] = PersistentBinaryDict("plugin_maildir", profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
89 self.__mailboxes[profile] = {} |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
90 |
439
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
91 def dataLoaded(ignore): |
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
92 if not self.data[profile]: |
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
93 #the mailbox is new, we initiate the data |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
94 self.data[profile]["INBOX"] = {"cur_idx": 0} |
439
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
95 self.data[profile].load().addCallback(dataLoaded) |
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
96 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
97 def profileDisconnected(self, client): |
439
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
98 """Called on profile disconnection, free profile's resources""" |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
99 profile = client.profile |
439
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
100 del self.__mailboxes[profile] |
866dbb0d7d87
plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents:
365
diff
changeset
|
101 del self.data[profile] |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
102 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
103 def messageReceivedTrigger(self, client, message, post_treat): |
259
11f71187d5e4
core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
104 """This trigger catch normal message and put the in the Maildir box. |
11f71187d5e4
core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
105 If the message is not of "normal" type, do nothing |
11f71187d5e4
core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
106 @param message: message xmlstrem |
11f71187d5e4
core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
107 @return: False if it's a normal message, True else""" |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
108 profile = client.profile |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
109 for e in message.elements(C.NS_CLIENT, 'body'): |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
110 mess_type = message.getAttribute('type', 'normal') |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
111 if mess_type != 'normal': |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
112 return True |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
113 self.accessMessageBox("INBOX", profile_key=profile).addMessage(message) |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
114 return not self.host.memory.getParamA(NAME, CATEGORY, profile_key=profile) |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
115 return True |
259
11f71187d5e4
core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents:
257
diff
changeset
|
116 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
117 def accessMessageBox(self, boxname, observer=None, profile_key=C.PROF_KEY_NONE): |
253 | 118 """Create and return a MailboxUser instance |
119 @param boxname: name of the box | |
120 @param observer: method to call when a NewMessage arrive""" | |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
121 profile = self.host.memory.getProfileName(profile_key) |
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
122 if not profile: |
471 | 123 raise ProfileUnknownError(profile_key) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
124 if boxname not in self.__mailboxes[profile]: |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
125 self.__mailboxes[profile][boxname] = MailboxUser(self, boxname, observer, profile=profile) |
253 | 126 else: |
127 if observer: | |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
128 self.addObserver(observer, profile, boxname) |
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
129 return self.__mailboxes[profile][boxname] |
253 | 130 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
131 def _getProfilePath(self, profile): |
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
132 """Return a unique path for profile's mailbox |
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
133 The path must be unique, usable as a dir name, and bijectional""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
134 return profile.replace('/', '_').replace('..', '_') # FIXME: this is too naive to work well, must be improved |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
135 |
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
136 def _removeBoxAccess(self, boxname, mailboxUser, profile): |
253 | 137 """Remove a reference to a box |
138 @param name: name of the box | |
139 @param mailboxUser: MailboxUser instance""" | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
140 if boxname not in self.__mailboxes: |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
141 err_msg = _("Trying to remove an mailboxUser not referenced") |
3028 | 142 log.error(_("INTERNAL ERROR: ") + err_msg) |
253 | 143 raise MaildirError(err_msg) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
144 assert self.__mailboxes[profile][boxname] == mailboxUser |
622
9a8fbf0e8691
pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
145 del self.__mailboxes[profile][boxname] |
253 | 146 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
147 def _checkBoxReference(self, boxname, profile): |
253 | 148 """Check if there is a reference on a box, and return it |
149 @param boxname: name of the box to check | |
150 @return: MailboxUser instance or None""" | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
151 if profile in self.__mailboxes: |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
152 if boxname in self.__mailboxes[profile]: |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
153 return self.__mailboxes[profile][boxname] |
253 | 154 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
155 def __getBoxData(self, boxname, profile): |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
156 """Return the date of a box""" |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
157 try: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
158 return self.data[profile][boxname] # the boxname MUST exist in the data |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
159 except KeyError: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
160 err_msg = _("Boxname doesn't exist in internal data") |
3028 | 161 log.error(_("INTERNAL ERROR: ") + err_msg) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
162 raise MaildirError(err_msg) |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
163 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
164 def getUid(self, boxname, message_id, profile): |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
165 """Return an unique integer, always ascending, for a message |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
166 This is mainly needed for the IMAP protocol |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
167 @param boxname: name of the box where the message is |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
168 @param message_id: unique id of the message as given by MaildirMailbox |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
169 @return: Integer UID""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
170 box_data = self.__getBoxData(boxname, profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
171 if message_id in box_data: |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
172 ret = box_data[message_id][0] |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
173 else: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
174 box_data['cur_idx'] += 1 |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
175 box_data[message_id] = [box_data['cur_idx'], []] |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
176 ret = box_data[message_id] |
445
1c1d1a4994c4
plugin maildir: replaced forgotten setPrivate by PersistentBinaryDict.force
Goffi <goffi@goffi.org>
parents:
439
diff
changeset
|
177 self.data[profile].force(boxname) |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
178 return ret |
253 | 179 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
180 def getNextUid(self, boxname, profile): |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
181 """Return next unique integer that will generated |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
182 This is mainly needed for the IMAP protocol |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
183 @param boxname: name of the box where the message is |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
184 @return: Integer UID""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
185 box_data = self.__getBoxData(boxname, profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
186 return box_data['cur_idx'] + 1 |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
187 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
188 def getNextExistingUid(self, boxname, uid, profile): |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
189 """Give the next uid of existing message |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
190 @param boxname: name of the box where the message is |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
191 @param uid: uid to start from |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
192 @return: uid or None if the is no more message""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
193 box_data = self.__getBoxData(boxname, profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
194 idx = uid + 1 |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
195 while self.getIdFromUid(boxname, idx, profile) is None: # TODO: this is highly inefficient because getIdfromUid is inefficient, fix this |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
196 idx += 1 |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
197 if idx > box_data['cur_idx']: |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
198 return None |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
199 return idx |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
200 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
201 def getMaxUid(self, boxname, profile): |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
202 """Give the max existing uid |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
203 @param boxname: name of the box where the message is |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
204 @return: uid""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
205 box_data = self.__getBoxData(boxname, profile) |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
206 return box_data['cur_idx'] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
207 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
208 def getIdFromUid(self, boxname, message_uid, profile): |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
209 """Return the message unique id from it's integer UID |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
210 @param boxname: name of the box where the message is |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
211 @param message_uid: unique integer identifier |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
212 @return: unique id of the message as given by MaildirMailbox or None if not found""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
213 box_data = self.__getBoxData(boxname, profile) |
3028 | 214 for message_id in list(box_data.keys()): # TODO: this is highly inefficient on big mailbox, must be replaced in the future |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
215 if message_id == 'cur_idx': |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
216 continue |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
217 if box_data[message_id][0] == message_uid: |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
218 return message_id |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
219 return None |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
220 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
221 def getFlags(self, boxname, mess_id, profile): |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
222 """Return the messages flags |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
223 @param boxname: name of the box where the message is |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
224 @param message_idx: message id as given by MaildirMailbox |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
225 @return: list of strings""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
226 box_data = self.__getBoxData(boxname, profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
227 if mess_id not in box_data: |
622
9a8fbf0e8691
pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
228 raise MaildirError("Trying to get flags from an unexisting message") |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
229 return box_data[mess_id][1] |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
230 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
231 def setFlags(self, boxname, mess_id, flags, profile): |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
232 """Change the flags of the message |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
233 @param boxname: name of the box where the message is |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
234 @param message_idx: message id as given by MaildirMailbox |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
235 @param flags: list of strings |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
236 """ |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
237 box_data = self.__getBoxData(boxname, profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
238 assert(type(flags) == list) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
239 flags = [flag.upper() for flag in flags] # we store every flag UPPERCASE |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
240 if mess_id not in box_data: |
622
9a8fbf0e8691
pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
241 raise MaildirError("Trying to set flags for an unexisting message") |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
242 box_data[mess_id][1] = flags |
445
1c1d1a4994c4
plugin maildir: replaced forgotten setPrivate by PersistentBinaryDict.force
Goffi <goffi@goffi.org>
parents:
439
diff
changeset
|
243 self.data[profile].force(boxname) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
244 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
245 def getMessageIdsWithFlag(self, boxname, flag, profile): |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
246 """Return ids of messages where a flag is set |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
247 @param boxname: name of the box where the message is |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
248 @param flag: flag to check |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
249 @return: list of id (as given by MaildirMailbox)""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
250 box_data = self.__getBoxData(boxname, profile) |
3028 | 251 assert(isinstance(flag, str)) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
252 flag = flag.upper() |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
253 result = [] |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
254 for key in box_data: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
255 if key == 'cur_idx': |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
256 continue |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
257 if flag in box_data[key][1]: |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
258 result.append(key) |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
259 return result |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
260 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
261 def purgeDeleted(self, boxname, profile): |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
262 """Remove data for messages with flag "\\Deleted" |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
263 @param boxname: name of the box where the message is |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
264 """ |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
265 box_data = self.__getBoxData(boxname, profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
266 for mess_id in self.getMessageIdsWithFlag(boxname, "\\Deleted", profile): |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
267 del(box_data[mess_id]) |
445
1c1d1a4994c4
plugin maildir: replaced forgotten setPrivate by PersistentBinaryDict.force
Goffi <goffi@goffi.org>
parents:
439
diff
changeset
|
268 self.data[profile].force(boxname) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
269 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
270 def cleanTable(self, boxname, existant_id, profile): |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
271 """Remove mails which no longuer exist from the table |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
272 @param boxname: name of the box to clean |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
273 @param existant_id: list of id which actually exist""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
274 box_data = self.__getBoxData(boxname, profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
275 to_remove = [] |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
276 for key in box_data: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
277 if key not in existant_id and key != "cur_idx": |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
278 to_remove.append(key) |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
279 for key in to_remove: |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
280 del box_data[key] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
281 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
282 def addObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"): |
253 | 283 """Add an observer for maildir box changes |
284 @param callback: method to call when the the box is updated | |
285 @param boxname: name of the box to observe | |
286 @param signal: which signal is observed by the caller""" | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
287 if (profile, boxname) not in self.__observed: |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
288 self.__observed[(profile, boxname)] = {} |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
289 if signal not in self.__observed[(profile, boxname)]: |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
290 self.__observed[(profile, boxname)][signal] = set() |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
291 self.__observed[(profile, boxname)][signal].add(callback) |
253 | 292 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
293 def removeObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"): |
253 | 294 """Remove an observer of maildir box changes |
295 @param callback: method to remove from obervers | |
296 @param boxname: name of the box which was observed | |
297 @param signal: which signal was observed by the caller""" | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
298 if (profile, boxname) not in self.__observed: |
3028 | 299 err_msg = _("Trying to remove an observer for an inexistant mailbox") |
300 log.error(_("INTERNAL ERROR: ") + err_msg) | |
253 | 301 raise MaildirError(err_msg) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
302 if signal not in self.__observed[(profile, boxname)]: |
3028 | 303 err_msg = _("Trying to remove an inexistant observer, no observer for this signal") |
304 log.error(_("INTERNAL ERROR: ") + err_msg) | |
253 | 305 raise MaildirError(err_msg) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
306 if not callback in self.__observed[(profile, boxname)][signal]: |
3028 | 307 err_msg = _("Trying to remove an inexistant observer") |
308 log.error(_("INTERNAL ERROR: ") + err_msg) | |
253 | 309 raise MaildirError(err_msg) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
310 self.__observed[(profile, boxname)][signal].remove(callback) |
253 | 311 |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
312 def emitSignal(self, profile, boxname, signal_name): |
253 | 313 """Emit the signal to observer""" |
3028 | 314 log.debug('emitSignal %s %s %s' % (profile, boxname, signal_name)) |
253 | 315 try: |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
316 for observer_cb in self.__observed[(profile, boxname)][signal_name]: |
253 | 317 observer_cb() |
318 except KeyError: | |
319 pass | |
320 | |
321 | |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
322 class MailboxUser(object): |
253 | 323 """This class is used to access a mailbox""" |
324 | |
325 def xmppMessage2mail(self, message): | |
326 """Convert the XMPP's XML message to a basic rfc2822 message | |
327 @param xml: domish.Element of the message | |
328 @return: string email""" | |
329 mail = email.message.Message() | |
330 mail['MIME-Version'] = "1.0" | |
331 mail['Content-Type'] = "text/plain; charset=UTF-8; format=flowed" | |
332 mail['Content-Transfer-Encoding'] = "8bit" | |
333 mail['From'] = message['from'].encode('utf-8') | |
334 mail['To'] = message['to'].encode('utf-8') | |
335 mail['Date'] = email.utils.formatdate().encode('utf-8') | |
336 #TODO: save thread id | |
337 for e in message.elements(): | |
338 if e.name == "body": | |
339 mail.set_payload(e.children[0].encode('utf-8')) | |
340 elif e.name == "subject": | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
341 mail['Subject'] = e.children[0].encode('utf-8') |
253 | 342 return mail.as_string() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
343 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
344 def __init__(self, _maildir, name, observer=None, profile=C.PROF_KEY_NONE): |
253 | 345 """@param _maildir: the main MaildirBox instance |
346 @param name: name of the mailbox | |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
347 @param profile: real profile (ie not a profile_key) |
253 | 348 THIS OBJECT MUST NOT BE USED DIRECTLY: use MaildirBox.accessMessageBox instead""" |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
349 if _maildir._checkBoxReference(name, profile): |
3028 | 350 log.error("INTERNAL ERROR: MailboxUser MUST NOT be instancied directly") |
622
9a8fbf0e8691
pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
351 raise MaildirError('double MailboxUser instanciation') |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
352 if name != "INBOX": |
253 | 353 raise NotImplementedError |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
354 self.name = name |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
355 self.profile = profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
356 self.maildir = _maildir |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
357 profile_path = self.maildir._getProfilePath(profile) |
622
9a8fbf0e8691
pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
358 full_profile_path = os.path.join(self.maildir.host.memory.getConfig('', 'local_dir'), 'maildir', profile_path) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
359 if not os.path.exists(full_profile_path): |
3028 | 360 os.makedirs(full_profile_path, 0o700) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
361 mailbox_path = os.path.join(full_profile_path, MAILDIR_PATH) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
362 self.mailbox_path = mailbox_path |
253 | 363 self.mailbox = maildir.MaildirMailbox(mailbox_path) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
364 self.observer = observer |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
365 self.__uid_table_update() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
366 |
253 | 367 if observer: |
3028 | 368 log.debug("adding observer for %s (%s)" % (name, profile)) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
369 self.maildir.addObserver(observer, profile, name, "NEW_MESSAGE") |
253 | 370 |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
371 def __uid_table_update(self): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
372 existant_id = [] |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
373 for mess_idx in range(self.getMessageCount()): |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
374 #we update the uid table |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
375 existant_id.append(self.getId(mess_idx)) |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
376 self.getUid(mess_idx) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
377 self.maildir.cleanTable(self.name, existant_id, profile=self.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
378 |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
379 def __del__(self): |
622
9a8fbf0e8691
pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
380 if self.observer: |
3028 | 381 log.debug("removing observer for %s" % self.name) |
622
9a8fbf0e8691
pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
382 self._maildir.removeObserver(self.observer, self.name, "NEW_MESSAGE") |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
383 self.maildir._removeBoxAccess(self.name, self, profile=self.profile) |
253 | 384 |
385 def addMessage(self, message): | |
386 """Add a message to the box | |
387 @param message: XMPP XML message""" | |
388 self.mailbox.appendMessage(self.xmppMessage2mail(message)).addCallback(self.emitSignal, "NEW_MESSAGE") | |
389 | |
390 def emitSignal(self, ignore, signal): | |
391 """Emit the signal to the observers""" | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
392 if signal == "NEW_MESSAGE": |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
393 self.getUid(self.getMessageCount() - 1) # XXX: we make an uid for the last message added |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
394 self.maildir.emitSignal(self.profile, self.name, signal) |
253 | 395 |
396 def getId(self, mess_idx): | |
397 """Return the Unique ID of the message | |
398 @mess_idx: message index""" | |
399 return self.mailbox.getUidl(mess_idx) | |
400 | |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
401 def getUid(self, mess_idx): |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
402 """Return a unique interger id for the message, always ascending""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
403 mess_id = self.getId(mess_idx) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
404 return self.maildir.getUid(self.name, mess_id, profile=self.profile) |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
405 |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
406 def getNextUid(self): |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
407 return self.maildir.getNextUid(self.name, profile=self.profile) |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
408 |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
409 def getNextExistingUid(self, uid): |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
410 return self.maildir.getNextExistingUid(self.name, uid, profile=self.profile) |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
411 |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
412 def getMaxUid(self): |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
413 return self.maildir.getMaxUid(self.name, profile=self.profile) |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
414 |
253 | 415 def getMessageCount(self): |
416 """Return number of mails present in this box""" | |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
417 return len(self.mailbox.list) |
253 | 418 |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
419 def getMessageIdx(self, mess_idx): |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
420 """Return the full message |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
421 @mess_idx: message index""" |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
422 return self.mailbox.getMessage(mess_idx) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
423 |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
424 def getIdxFromUid(self, mess_uid): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
425 """Return the message index from the uid |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
426 @param mess_uid: message unique identifier |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
427 @return: message index, as managed by MaildirMailbox""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
428 for mess_idx in range(self.getMessageCount()): |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
429 if self.getUid(mess_idx) == mess_uid: |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
430 return mess_idx |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
431 raise IndexError |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
432 |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
433 def getIdxFromId(self, mess_id): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
434 """Return the message index from the unique index |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
435 @param mess_id: message unique index as given by MaildirMailbox |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
436 @return: message sequence index""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
437 for mess_idx in range(self.getMessageCount()): |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
438 if self.mailbox.getUidl(mess_idx) == mess_id: |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
439 return mess_idx |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
440 raise IndexError |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
441 |
253 | 442 def getMessage(self, mess_idx): |
443 """Return the full message | |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
444 @param mess_idx: message index""" |
253 | 445 return self.mailbox.getMessage(mess_idx) |
254
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
446 |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
447 def getMessageUid(self, mess_uid): |
9fc32d1d9046
Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents:
253
diff
changeset
|
448 """Return the full message |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
449 @param mess_idx: message unique identifier""" |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
450 return self.mailbox.getMessage(self.getIdxFromUid(mess_uid)) |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
451 |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
452 def getFlags(self, mess_idx): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
453 """Return the flags of the message |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
454 @param mess_idx: message index |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
455 @return: list of strings""" |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
456 id = self.getId(mess_idx) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
457 return self.maildir.getFlags(self.name, id, profile=self.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
480
diff
changeset
|
458 |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
459 def getFlagsUid(self, mess_uid): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
460 """Return the flags of the message |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
461 @param mess_uid: message unique identifier |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
462 @return: list of strings""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
463 id = self.maildir.getIdFromUid(self.name, mess_uid, profile=self.profile) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
464 return self.maildir.getFlags(self.name, id, profile=self.profile) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
465 |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
466 def setFlags(self, mess_idx, flags): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
467 """Change the flags of the message |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
468 @param mess_idx: message index |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
469 @param flags: list of strings |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
470 """ |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
471 id = self.getId(mess_idx) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
472 self.maildir.setFlags(self.name, id, flags, profile=self.profile) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
473 |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
474 def setFlagsUid(self, mess_uid, flags): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
475 """Change the flags of the message |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
476 @param mess_uid: message unique identifier |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
477 @param flags: list of strings |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
478 """ |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
479 id = self.maildir.getIdFromUid(self.name, mess_uid, profile=self.profile) |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
480 return self.maildir.setFlags(self.name, id, flags, profile=self.profile) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
481 |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
482 def getMessageIdsWithFlag(self, flag): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
483 """Return ids of messages where a flag is set |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
484 @param flag: flag to check |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
485 @return: list of id (as given by MaildirMailbox)""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
486 return self.maildir.getMessageIdsWithFlag(self.name, flag, profile=self.profile) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
487 |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
488 def removeDeleted(self): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
489 """Actually delete message flagged "\\Deleted" |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
490 Also purge the internal data of these messages |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
491 """ |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
492 for mess_id in self.getMessageIdsWithFlag("\\Deleted"): |
3028 | 493 print(("Deleting %s" % mess_id)) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
494 self.mailbox.deleteMessage(self.getIdxFromId(mess_id)) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
495 self.mailbox = maildir.MaildirMailbox(self.mailbox_path) # We need to reparse the dir to have coherent indexing |
257
012c38b56cdd
plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents:
255
diff
changeset
|
496 self.maildir.purgeDeleted(self.name, profile=self.profile) |
255
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
497 |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
498 def emptyTrash(self): |
55b750017b71
plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents:
254
diff
changeset
|
499 """Delete everything in the .Trash dir""" |
622
9a8fbf0e8691
pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
500 pass #TODO |