annotate src/plugins/plugin_misc_maildir.py @ 1894:116a55865364

frontends (jp / blog): pass the profile to subprocess when using option --preview
author souliane <souliane@mailoo.org>
date Mon, 07 Mar 2016 19:58:33 +0100
parents 7a8a19e4fa6c
children 2daf7b4c6756
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 445
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
35 "name": "Maildir Plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
36 "import_name": "Maildir",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
37 "type": "Misc",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
38 "protocols": [],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
39 "dependencies": [],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
40 "main": "MaildirBox",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
41 "handler": "no",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
42 "description": _("""Intercept "normal" type messages, and put them in a Maildir type box""")
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 }
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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')
7a8a19e4fa6c plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
48 # FIXME: (very) old and (very) experimental code, need a big cleaning/review
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
50
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class MaildirError(Exception):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 pass
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84
439
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
85 def profileConnected(self, profile):
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
86 """Called on profile connection, create profile data"""
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
87 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
88 self.__mailboxes[profile] = {}
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
89
439
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
90 def dataLoaded(ignore):
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
91 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
92 #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
93 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
94 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
95
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
96 def profileDisconnected(self, profile):
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
97 """Called on profile disconnection, free profile's resources"""
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
98 del self.__mailboxes[profile]
866dbb0d7d87 plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data
Goffi <goffi@goffi.org>
parents: 365
diff changeset
99 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
100
663
8004c7d4aba7 core: Deferred in onMessage.
Goffi <goffi@goffi.org>
parents: 622
diff changeset
101 def messageReceivedTrigger(self, message, post_treat, profile):
259
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 257
diff changeset
102 """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
103 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
104 @param message: message xmlstrem
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 257
diff changeset
105 @return: False if it's a normal message, True else"""
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 257
diff changeset
106 for e in message.elements():
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 257
diff changeset
107 if e.name == "body":
264
27bc5d7732a3 core: fixed default message type
Goffi <goffi@goffi.org>
parents: 259
diff changeset
108 mess_type = message['type'] if message.hasAttribute('type') else 'normal'
27bc5d7732a3 core: fixed default message type
Goffi <goffi@goffi.org>
parents: 259
diff changeset
109 if mess_type != 'normal':
259
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 257
diff changeset
110 return True
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 257
diff changeset
111 self.accessMessageBox("INBOX", profile_key=profile).addMessage(message)
1837
7a8a19e4fa6c plugin maildir: added an option to block intercepted normal messages:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
112 return not self.host.memory.getParamA(NAME, CATEGORY, profile_key=profile)
259
11f71187d5e4 core, plugin Maildir: added "ProfileCreation" Trigger
Goffi <goffi@goffi.org>
parents: 257
diff changeset
113
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 771
diff changeset
114 def accessMessageBox(self, boxname, observer=None, profile_key=C.PROF_KEY_NONE):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 """Create and return a MailboxUser instance
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 @param boxname: name of the box
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 @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
118 profile = self.host.memory.getProfileName(profile_key)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
119 if not profile:
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 445
diff changeset
120 raise ProfileUnknownError(profile_key)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
121 if boxname not in self.__mailboxes[profile]:
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
122 self.__mailboxes[profile][boxname] = MailboxUser(self, boxname, observer, profile=profile)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 else:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 if observer:
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
125 self.addObserver(observer, profile, boxname)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
126 return self.__mailboxes[profile][boxname]
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
128 def _getProfilePath(self, profile):
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
129 """Return a unique path for profile's mailbox
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
130 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
131 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
132
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
133 def _removeBoxAccess(self, boxname, mailboxUser, profile):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 """Remove a reference to a box
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 @param name: name of the box
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 @param mailboxUser: MailboxUser instance"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
137 if boxname not in self.__mailboxes:
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
138 err_msg = _("Trying to remove an mailboxUser not referenced")
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
139 log.error(_(u"INTERNAL ERROR: ") + err_msg)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 raise MaildirError(err_msg)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
141 assert self.__mailboxes[profile][boxname] == mailboxUser
622
9a8fbf0e8691 pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
142 del self.__mailboxes[profile][boxname]
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
144 def _checkBoxReference(self, boxname, profile):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 """Check if there is a reference on a box, and return it
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 @param boxname: name of the box to check
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 @return: MailboxUser instance or None"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
148 if profile in self.__mailboxes:
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
149 if boxname in self.__mailboxes[profile]:
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
150 return self.__mailboxes[profile][boxname]
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
152 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
153 """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
154 try:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
155 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
156 except KeyError:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
157 err_msg = _("Boxname doesn't exist in internal data")
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
158 log.error(_(u"INTERNAL ERROR: ") + err_msg)
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
159 raise MaildirError(err_msg)
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
160
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
161 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
162 """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
163 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
164 @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
165 @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
166 @return: Integer UID"""
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
167 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
168 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
169 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
170 else:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
171 box_data['cur_idx'] += 1
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
172 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
173 ret = box_data[message_id]
445
1c1d1a4994c4 plugin maildir: replaced forgotten setPrivate by PersistentBinaryDict.force
Goffi <goffi@goffi.org>
parents: 439
diff changeset
174 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
175 return ret
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
177 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
178 """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
179 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
180 @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
181 @return: Integer UID"""
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
182 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
183 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
184
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
185 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
186 """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
187 @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
188 @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
189 @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
190 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
191 idx = uid + 1
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
192 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
193 idx += 1
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
194 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
195 return None
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
196 return idx
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
197
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
198 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
199 """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
200 @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
201 @return: uid"""
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
202 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
203 return box_data['cur_idx']
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
204
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
205 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
206 """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
207 @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
208 @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
209 @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
210 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
211 for message_id in 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
212 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
213 continue
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
214 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
215 return message_id
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
216 return None
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
217
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
218 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
219 """Return the messages flags
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
220 @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
221 @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
222 @return: list of strings"""
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
223 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
224 if mess_id not in box_data:
622
9a8fbf0e8691 pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
225 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
226 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
227
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
228 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
229 """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
230 @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
231 @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
232 @param flags: list of strings
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
233 """
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
234 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
235 assert(type(flags) == list)
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
236 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
237 if mess_id not in box_data:
622
9a8fbf0e8691 pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
238 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
239 box_data[mess_id][1] = flags
445
1c1d1a4994c4 plugin maildir: replaced forgotten setPrivate by PersistentBinaryDict.force
Goffi <goffi@goffi.org>
parents: 439
diff changeset
240 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
241
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
242 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
243 """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
244 @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
245 @param flag: flag to check
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
246 @return: list of id (as given by MaildirMailbox)"""
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
247 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
248 assert(isinstance(flag, basestring))
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
249 flag = flag.upper()
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
250 result = []
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
251 for key in box_data:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
252 if key == 'cur_idx':
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
253 continue
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
254 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
255 result.append(key)
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
256 return result
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
257
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
258 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
259 """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
260 @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
261 """
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
262 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
263 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
264 del(box_data[mess_id])
445
1c1d1a4994c4 plugin maildir: replaced forgotten setPrivate by PersistentBinaryDict.force
Goffi <goffi@goffi.org>
parents: 439
diff changeset
265 self.data[profile].force(boxname)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
266
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
267 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
268 """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
269 @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
270 @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
271 box_data = self.__getBoxData(boxname, profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
272 to_remove = []
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
273 for key in box_data:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
274 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
275 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
276 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
277 del box_data[key]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
278
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
279 def addObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
280 """Add an observer for maildir box changes
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
281 @param callback: method to call when the the box is updated
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
282 @param boxname: name of the box to observe
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
283 @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
284 if (profile, boxname) not in self.__observed:
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
285 self.__observed[(profile, boxname)] = {}
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
286 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
287 self.__observed[(profile, boxname)][signal] = set()
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
288 self.__observed[(profile, boxname)][signal].add(callback)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
289
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
290 def removeObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
291 """Remove an observer of maildir box changes
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
292 @param callback: method to remove from obervers
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
293 @param boxname: name of the box which was observed
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
294 @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
295 if (profile, boxname) not in self.__observed:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
296 err_msg = _(u"Trying to remove an observer for an inexistant mailbox")
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
297 log.error(_(u"INTERNAL ERROR: ") + err_msg)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
298 raise MaildirError(err_msg)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
299 if signal not in self.__observed[(profile, boxname)]:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
300 err_msg = _(u"Trying to remove an inexistant observer, no observer for this signal")
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
301 log.error(_(u"INTERNAL ERROR: ") + err_msg)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
302 raise MaildirError(err_msg)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
303 if not callback in self.__observed[(profile, boxname)][signal]:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
304 err_msg = _(u"Trying to remove an inexistant observer")
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
305 log.error(_(u"INTERNAL ERROR: ") + err_msg)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
306 raise MaildirError(err_msg)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
307 self.__observed[(profile, boxname)][signal].remove(callback)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
308
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
309 def emitSignal(self, profile, boxname, signal_name):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
310 """Emit the signal to observer"""
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
311 log.debug(u'emitSignal %s %s %s' % (profile, boxname, signal_name))
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
312 try:
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
313 for observer_cb in self.__observed[(profile, boxname)][signal_name]:
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
314 observer_cb()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
315 except KeyError:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
316 pass
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
317
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
318
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
319 class MailboxUser(object):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
320 """This class is used to access a mailbox"""
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
321
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
322 def xmppMessage2mail(self, message):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
323 """Convert the XMPP's XML message to a basic rfc2822 message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
324 @param xml: domish.Element of the message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
325 @return: string email"""
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
326 mail = email.message.Message()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
327 mail['MIME-Version'] = "1.0"
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
328 mail['Content-Type'] = "text/plain; charset=UTF-8; format=flowed"
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
329 mail['Content-Transfer-Encoding'] = "8bit"
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
330 mail['From'] = message['from'].encode('utf-8')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
331 mail['To'] = message['to'].encode('utf-8')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
332 mail['Date'] = email.utils.formatdate().encode('utf-8')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
333 #TODO: save thread id
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
334 for e in message.elements():
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
335 if e.name == "body":
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
336 mail.set_payload(e.children[0].encode('utf-8'))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
337 elif e.name == "subject":
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
338 mail['Subject'] = e.children[0].encode('utf-8')
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
339 return mail.as_string()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
340
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 771
diff changeset
341 def __init__(self, _maildir, name, observer=None, profile=C.PROF_KEY_NONE):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
342 """@param _maildir: the main MaildirBox instance
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
343 @param name: name of the mailbox
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
344 @param profile: real profile (ie not a profile_key)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
345 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
346 if _maildir._checkBoxReference(name, profile):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
347 log.error(u"INTERNAL ERROR: MailboxUser MUST NOT be instancied directly")
622
9a8fbf0e8691 pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
348 raise MaildirError('double MailboxUser instanciation')
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
349 if name != "INBOX":
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
350 raise NotImplementedError
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
351 self.name = name
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
352 self.profile = profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
353 self.maildir = _maildir
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
354 profile_path = self.maildir._getProfilePath(profile)
622
9a8fbf0e8691 pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
355 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
356 if not os.path.exists(full_profile_path):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
357 os.makedirs(full_profile_path, 0700)
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
358 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
359 self.mailbox_path = mailbox_path
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
360 self.mailbox = maildir.MaildirMailbox(mailbox_path)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
361 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
362 self.__uid_table_update()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
363
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
364 if observer:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
365 log.debug(u"adding observer for %s (%s)" % (name, profile))
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
366 self.maildir.addObserver(observer, profile, name, "NEW_MESSAGE")
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
367
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
368 def __uid_table_update(self):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
369 existant_id = []
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
370 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
371 #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
372 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
373 self.getUid(mess_idx)
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
374 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
375
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
376 def __del__(self):
622
9a8fbf0e8691 pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
377 if self.observer:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1218
diff changeset
378 log.debug(u"removing observer for %s" % self.name)
622
9a8fbf0e8691 pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
379 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
380 self.maildir._removeBoxAccess(self.name, self, profile=self.profile)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
381
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
382 def addMessage(self, message):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
383 """Add a message to the box
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
384 @param message: XMPP XML message"""
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
385 self.mailbox.appendMessage(self.xmppMessage2mail(message)).addCallback(self.emitSignal, "NEW_MESSAGE")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
386
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
387 def emitSignal(self, ignore, signal):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
388 """Emit the signal to the observers"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
389 if signal == "NEW_MESSAGE":
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
390 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
391 self.maildir.emitSignal(self.profile, self.name, signal)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
392
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
393 def getId(self, mess_idx):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
394 """Return the Unique ID of the message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
395 @mess_idx: message index"""
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
396 return self.mailbox.getUidl(mess_idx)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
397
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
398 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
399 """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
400 mess_id = self.getId(mess_idx)
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
401 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
402
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
403 def getNextUid(self):
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
404 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
405
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
406 def getNextExistingUid(self, uid):
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
407 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
408
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
409 def getMaxUid(self):
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
410 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
411
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
412 def getMessageCount(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
413 """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
414 return len(self.mailbox.list)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
415
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
416 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
417 """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
418 @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
419 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
420
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
421 def getIdxFromUid(self, mess_uid):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
422 """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
423 @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
424 @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
425 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
426 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
427 return mess_idx
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
428 raise IndexError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
429
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
430 def getIdxFromId(self, mess_id):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
431 """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
432 @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
433 @return: message sequence index"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
434 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
435 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
436 return mess_idx
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
437 raise IndexError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
438
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
439 def getMessage(self, mess_idx):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
440 """Return the full message
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
441 @param mess_idx: message index"""
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
442 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
443
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
444 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
445 """Return the full message
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
446 @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
447 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
448
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
449 def getFlags(self, mess_idx):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
450 """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
451 @param mess_idx: message index
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
452 @return: list of strings"""
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
453 id = self.getId(mess_idx)
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
454 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
455
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
456 def getFlagsUid(self, mess_uid):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
457 """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
458 @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
459 @return: list of strings"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
460 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
461 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
462
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
463 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
464 """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
465 @param mess_idx: message index
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
466 @param flags: list of strings
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
467 """
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
468 id = self.getId(mess_idx)
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
469 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
470
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
471 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
472 """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
473 @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
474 @param flags: list of strings
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
475 """
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
476 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
477 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
478
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
479 def getMessageIdsWithFlag(self, flag):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
480 """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
481 @param flag: flag to check
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
482 @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
483 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
484
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
485 def removeDeleted(self):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
486 """Actually delete message flagged "\\Deleted"
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
487 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
488 """
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
489 for mess_id in self.getMessageIdsWithFlag("\\Deleted"):
338
6dcdc4cf8622 plugin maildir: fixed typo
Goffi <goffi@goffi.org>
parents: 264
diff changeset
490 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
491 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
492 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
493 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
494
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
495 def emptyTrash(self):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
496 """Delete everything in the .Trash dir"""
622
9a8fbf0e8691 pluging maildir: some trivial fixes:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
497 pass #TODO