annotate src/plugins/plugin_misc_imap.py @ 254:9fc32d1d9046

Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
author Goffi <goffi@goffi.org>
date Mon, 17 Jan 2011 04:23:31 +0100
parents f45ffbf211e9
children 55b750017b71
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
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT plugin for managing imap server
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from logging import debug, info, error
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import warnings
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.internet import protocol
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import error as jab_error
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.cred import portal,checkers
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.mail import imap4
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from email.parser import Parser
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import email.message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 import os,os.path
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from cStringIO import StringIO
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from twisted.internet import reactor
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 import pdb
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from zope.interface import implements
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 PLUGIN_INFO = {
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 "name": "IMAP server Plugin",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 "import_name": "IMAP",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 "type": "Misc",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "protocols": [],
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 "dependencies": ["Maildir"],
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 "main": "IMAP_server",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 "handler": "no",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 "description": _("""Create an Imap server that you can use to read your "normal" type messages""")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 }
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 class IMAP_server():
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 params = """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 <params>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 <general>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 <category name="IMAP Server">
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 <param name="Port" value="10143" type="string" />
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 </category>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 </general>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 </params>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def __init__(self, host):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 info(_("Plugin Imap Server initialization"))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.host = host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 #parameters
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 host.memory.importParams(self.params)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 port = int(self.host.memory.getParamA("Port", "IMAP Server"))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 info(_("Launching IMAP server on port %d"), port)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.server_factory = ImapServerFactory(self.host)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 reactor.listenTCP(port, self.server_factory)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 class Message():
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 implements(imap4.IMessage)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def __init__(self, uid, mess_fp):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 debug('Message Init')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.uid=uid
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 self.mess_fp=mess_fp
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.message=Parser().parse(mess_fp)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def getUID(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 """Retrieve the unique identifier associated with this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 debug('getUID (message)')
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
88 debug ('===>%i', self.uid)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 return self.uid
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 def getFlags(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 """Retrieve the flags associated with this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 @return: The flags, represented as strings.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 debug('getFlags')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 return []
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 def getInternalDate(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 """Retrieve the date internally associated with this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 @return: An RFC822-formatted date string.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 debug('getInternalDate')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 return self.message['Date']
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 def getHeaders(self, negate, *names):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 """Retrieve a group of message headers.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 @param names: The names of the headers to retrieve or omit.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 @param negate: If True, indicates that the headers listed in names
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 should be omitted from the return value, rather than included.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 @return: A mapping of header field names to header field values
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 debug('getHeaders %s - %s' % (negate, names))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 final_dict={}
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 to_check=[name.lower() for name in names]
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 for header in self.message.keys():
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 if (negate and not header.lower() in to_check) or \
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 (not negate and header.lower() in to_check):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 final_dict[header]=self.message[header]
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 return final_dict
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 def getBodyFile(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 """Retrieve a file object containing only the body of this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 debug('getBodyFile')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 return StringIO(self.message.get_payload())
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def getSize(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 """Retrieve the total size, in octets, of this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 debug('getSize')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self.mess_fp.seek(0,os.SEEK_END)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 return self.mess_fp.tell()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 def isMultipart(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 """Indicate whether this message has subparts.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 debug('isMultipart')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 return False
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 def getSubPart(self,part):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 """Retrieve a MIME sub-message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 @param part: The number of the part to retrieve, indexed from 0.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 @return: The specified sub-part.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 debug('getSubPart')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 return TypeError
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 class SatMailbox:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 implements(imap4.IMailbox)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 def __init__(self,host,name):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155 self.host = host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 self.listeners=set()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 debug ('Mailbox init (%s)', name)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 if name!="INBOX":
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159 raise imap4.MailboxException("Only INBOX is managed for the moment")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 self.name=name
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self.mailbox=self.host.plugins["Maildir"].accessMessageBox("INBOX",self.newMessage)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 def newMessage(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164 """Called when a new message is in the mailbox"""
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 debug ("newMessage signal received")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166 nb_messages=self.getMessageCount()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 for listener in self.listeners:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 listener.newMessages(nb_messages,None)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170 def getUIDValidity(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 """Return the unique validity identifier for this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
172 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 debug ('getUIDValidity')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 return 0
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176 def getUIDNext(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177 """Return the likely UID for the next message added to this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
178 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 debug ('getUIDNext')
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
180 return self.mailbox.getNextUid()
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 def getUID(self,message):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 """Return the UID of a message in the mailbox
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
184 @param message: The message sequence number
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
185 @return: The UID of the message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
187 debug ('getUID')
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
188 return self.mailbox.getUid(message)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 def getMessageCount(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191 """Return the number of messages in this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
192 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
193 debug('getMessageCount')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194 ret = self.mailbox.getMessageCount()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
195 debug("count = %i" % ret)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
196 return ret
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
197
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
198 def getRecentCount(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
199 """Return the number of messages with the 'Recent' flag.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
200 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
201 debug('getRecentCount')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
202 return 0
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
203
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
204 def getUnseenCount(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
205 """Return the number of messages with the 'Unseen' flag.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
206 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
207 debug('getUnseenCount')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
208 return 1
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
209
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
210 def isWriteable(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
211 """Get the read/write status of the mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
212 @return: A true value if write permission is allowed, a false value otherwise.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
213 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
214 debug('isWriteable')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
215 return True
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
216
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
217 def destroy(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218 """Called before this mailbox is deleted, permanently.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
219 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
220 debug('destroy')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
221
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
222
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
223 def requestStatus(self, names):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
224 """Return status information about this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
225 @param names: The status names to return information regarding.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
226 The possible values for each name are: MESSAGES, RECENT, UIDNEXT,
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
227 UIDVALIDITY, UNSEEN.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
228 @return: A dictionary containing status information about the
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
229 requested names is returned. If the process of looking this
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
230 information up would be costly, a deferred whose callback will
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
231 eventually be passed this dictionary is returned instead.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
232 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
233 debug('requestStatus')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
234 return imap4.statusRequestHelper(self, names)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
235
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
236 def addListener(self, listener):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
237 """Add a mailbox change listener
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
238
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
239 @type listener: Any object which implements C{IMailboxListener}
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
240 @param listener: An object to add to the set of those which will
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
241 be notified when the contents of this mailbox change.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
242 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
243 debug('addListener %s' % listener)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
244 self.listeners.add(listener)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
245
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
246 def removeListener(self, listener):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
247 """Remove a mailbox change listener
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
248
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
249 @type listener: Any object previously added to and not removed from
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
250 this mailbox as a listener.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
251 @param listener: The object to remove from the set of listeners.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
252
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
253 @raise ValueError: Raised when the given object is not a listener for
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
254 this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
255 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
256 debug('removeListener')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
257 if listener in self.listeners:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
258 self.listeners.remove(listener)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
259 else:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
260 raise imap4.MailboxException('Trying to remove an unknown listener')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
261
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
262 def addMessage(self, message, flags = (), date = None):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
263 """Add the given message to this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
264 @param message: The RFC822 formatted message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
265 @param flags: The flags to associate with this message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
266 @param date: If specified, the date to associate with this
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
267 @return: A deferred whose callback is invoked with the message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
268 id if the message is added successfully and whose errback is
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
269 invoked otherwise.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
270 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
271 debug('addMessage')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
272 raise NotImplementedError
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
273
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
274 def expunge(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
275 """Remove all messages flagged \\Deleted.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
276 @return: The list of message sequence numbers which were deleted,
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
277 or a Deferred whose callback will be invoked with such a list.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
278 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
279 debug('expunge')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
280 raise NotImplementedError
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
281
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
282 def fetch(self, messages, uid):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
283 """Retrieve one or more messages.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
284 @param messages: The identifiers of messages to retrieve information
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
285 about
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
286 @param uid: If true, the IDs specified in the query are UIDs;
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
287 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
288 debug('fetch (%s, %s)'%(messages,uid))
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
289 if uid:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
290 messages.last = self.mailbox.getMaxUid()
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
291 messages.getnext = self.mailbox.getNextExistingUid
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
292 for mess_uid in messages:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
293 if mess_uid == None:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
294 debug ('stopping iteration')
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
295 raise StopIteration
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
296 try:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
297 debug ('yielding (%s,%s)' % (mess_uid,Message(mess_uid,self.mailbox.getMessageUid(mess_uid))))
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
298 yield (mess_uid,Message(mess_uid,self.mailbox.getMessageUid(mess_uid)))
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
299 except IndexError:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
300 continue
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
301 else:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
302 messages.last = self.getMessageCount()
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
303 for mess_idx in messages:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
304 if mess_idx>self.getMessageCount():
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
305 raise StopIteration
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
306 yield (mess_idx,Message(mess_idx,self.mailbox.getMessage(mess_idx-1)))
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
307
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
308 def store(self, messages, flags, mode, uid):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
309 """Set the flags of one or more messages.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
310 @param messages: The identifiers of the messages to set the flags of.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
311 @param flags: The flags to set, unset, or add.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
312 @param mode: If mode is -1, these flags should be removed from the
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
313 specified messages. If mode is 1, these flags should be added to
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
314 the specified messages. If mode is 0, all existing flags should be
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
315 cleared and these flags should be added.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
316 @param uid: If true, the IDs specified in the query are UIDs;
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
317 otherwise they are message sequence IDs.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
318 @return: A dict mapping message sequence numbers to sequences of str
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
319 representing the flags set on the message after this operation has
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
320 been performed, or a Deferred whose callback will be invoked with
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
321 such a dict.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
322 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
323 debug('store')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
324 raise NotImplementedError
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
325
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
326 def getFlags(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
327 """Return the flags defined in this mailbox
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
328 Flags with the \\ prefix are reserved for use as system flags.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
329 @return: A list of the flags that can be set on messages in this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
330 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
331 debug('getFlags')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
332 #return ['\Seen','\Answered','\Flagged','\Deleted','\Draft', '\Recent']
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
333 return []
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
334
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
335 def getHierarchicalDelimiter(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
336 """Get the character which delimits namespaces for in this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
337 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
338 debug('getHierarchicalDelimiter')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
339 return '.'
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
340
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
341
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
342
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
343 class ImapAccount(imap4.MemoryAccount):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
344 #implements(imap4.IAccount)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
345 # Actually implement the interface here
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
346
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
347 def __init__(self, host, name):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
348 debug("ImapAccount init")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
349 self.host=host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
350 imap4.MemoryAccount.__init__(self,name)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
351 self.addMailbox("Inbox") #We only manage Inbox for the moment
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
352 debug ('INBOX added')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
353
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
354 def _emptyMailbox(self, name, id):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
355 return SatMailbox(self.host,name)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
356
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
357
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
358 class ImapRealm:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
359 implements(portal.IRealm)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
360
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
361 def __init__(self,host):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
362 self.host = host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
363
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
364 def requestAvatar(self, avatarID, mind, *interfaces):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
365 debug('requestAvatar')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
366 if imap4.IAccount not in interfaces:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
367 raise NotImplementedError
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
368 return imap4.IAccount, ImapAccount(self.host,avatarID), lambda:None
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
369
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
370 class ImapServerFactory(protocol.ServerFactory):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
371 protocol = imap4.IMAP4Server
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
372
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
373 def __init__(self, host):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
374 self.host=host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
375
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
376 def startedConnecting(self, connector):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
377 debug (_("IMAP server connection started"))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
378
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
379 def clientConnectionLost(self, connector, reason):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
380 debug (_("IMAP server connection lost (reason: %s)"), reason)
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 buildProtocol(self, addr):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
383 debug ("Building protocole")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
384 prot = protocol.ServerFactory.buildProtocol(self, addr)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
385 prot.portal = portal.Portal(ImapRealm(self.host))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
386 prot.portal.registerChecker(checkers.InMemoryUsernamePasswordDatabaseDontUse(goffi="toto"))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
387 return prot