annotate src/plugins/plugin_misc_imap.py @ 381:1f7a14d0343d

primitivus: added forgotten gettext i18n call
author Goffi <goffi@goffi.org>
date Sat, 27 Aug 2011 17:24:17 +0200
parents 0ecd9c33fa3a
children 62b17854254e
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 """
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
5 SàT plugin for managing imap server
253
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
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
24 from twisted.internet import protocol,defer
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import error as jab_error
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
26 from twisted.cred import portal,checkers,credentials
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
27 from twisted.cred import error as cred_error
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.mail import imap4
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents: 257
diff changeset
29 from twisted.python import failure
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from email.parser import Parser
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 import email.message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 import os,os.path
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from cStringIO import StringIO
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from twisted.internet import reactor
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 import pdb
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
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 from zope.interface import implements
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 PLUGIN_INFO = {
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 "name": "IMAP server Plugin",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "import_name": "IMAP",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 "type": "Misc",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 "protocols": [],
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 "dependencies": ["Maildir"],
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 "main": "IMAP_server",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 "handler": "no",
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 "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
50 }
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 class IMAP_server():
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 params = """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 <params>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 <general>
261
0ecd9c33fa3a IMAP & SMTP Port parameters are now merged in "Mail Server" category
Goffi <goffi@goffi.org>
parents: 260
diff changeset
57 <category name="Mail Server">
0ecd9c33fa3a IMAP & SMTP Port parameters are now merged in "Mail Server" category
Goffi <goffi@goffi.org>
parents: 260
diff changeset
58 <param name="IMAP Port" value="10143" type="string" />
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 </category>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 </general>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 </params>
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 def __init__(self, host):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 info(_("Plugin Imap Server initialization"))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.host = host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 #parameters
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 host.memory.importParams(self.params)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70
261
0ecd9c33fa3a IMAP & SMTP Port parameters are now merged in "Mail Server" category
Goffi <goffi@goffi.org>
parents: 260
diff changeset
71 port = int(self.host.memory.getParamA("IMAP Port", "Mail Server"))
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 info(_("Launching IMAP server on port %d"), port)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.server_factory = ImapServerFactory(self.host)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 reactor.listenTCP(port, self.server_factory)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 class Message():
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 implements(imap4.IMessage)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
80 def __init__(self, uid, flags, mess_fp):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 debug('Message Init')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.uid=uid
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
83 self.flags=flags
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.mess_fp=mess_fp
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.message=Parser().parse(mess_fp)
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 def getUID(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 """Retrieve the unique identifier associated with this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 debug('getUID (message)')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 return self.uid
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def getFlags(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 """Retrieve the flags associated with this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 @return: The flags, represented as strings.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 debug('getFlags')
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
98 return self.flags
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 def getInternalDate(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 """Retrieve the date internally associated with this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 @return: An RFC822-formatted date string.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 debug('getInternalDate')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 return self.message['Date']
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 def getHeaders(self, negate, *names):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 """Retrieve a group of message headers.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 @param names: The names of the headers to retrieve or omit.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 @param negate: If True, indicates that the headers listed in names
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 should be omitted from the return value, rather than included.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 @return: A mapping of header field names to header field values
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 debug('getHeaders %s - %s' % (negate, names))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 final_dict={}
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 to_check=[name.lower() for name in names]
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 for header in self.message.keys():
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 if (negate and not header.lower() in to_check) or \
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 (not negate and header.lower() in to_check):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 final_dict[header]=self.message[header]
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 return final_dict
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 def getBodyFile(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 """Retrieve a file object containing only the body of this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 debug('getBodyFile')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 return StringIO(self.message.get_payload())
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 def getSize(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 """Retrieve the total size, in octets, of this message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 debug('getSize')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self.mess_fp.seek(0,os.SEEK_END)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 return self.mess_fp.tell()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138 def isMultipart(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 """Indicate whether this message has subparts.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 debug('isMultipart')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 return False
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def getSubPart(self,part):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 """Retrieve a MIME sub-message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 @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
147 @return: The specified sub-part.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 debug('getSubPart')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 return TypeError
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 class SatMailbox:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 implements(imap4.IMailbox)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
156 def __init__(self,host,name,profile):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 self.host = host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self.listeners=set()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159 debug ('Mailbox init (%s)', name)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 if name!="INBOX":
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161 raise imap4.MailboxException("Only INBOX is managed for the moment")
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
162 self.mailbox=self.host.plugins["Maildir"].accessMessageBox(name,self.newMessage, profile)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164 def newMessage(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 """Called when a new message is in the mailbox"""
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166 debug ("newMessage signal received")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 nb_messages=self.getMessageCount()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 for listener in self.listeners:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 listener.newMessages(nb_messages,None)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 def getUIDValidity(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
172 """Return the unique validity identifier for this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 debug ('getUIDValidity')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175 return 0
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177 def getUIDNext(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
178 """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
179 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
180 debug ('getUIDNext')
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
181 return self.mailbox.getNextUid()
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 def getUID(self,message):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
184 """Return the UID of a message in the mailbox
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
185 @param message: The message sequence number
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 @return: The UID of the message.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
187 """
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
188 debug ('getUID (%i)' % message)
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
189 #return self.mailbox.getUid(message-1) #XXX: it seems that this method get uid and not message sequence number
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
190 return message
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
192 def getMessageCount(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
193 """Return the number of messages in this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
195 debug('getMessageCount')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
196 ret = self.mailbox.getMessageCount()
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
197 debug("count = %i" % ret)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
198 return ret
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
199
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
200 def getRecentCount(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
201 """Return the number of messages with the 'Recent' flag.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
202 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
203 debug('getRecentCount')
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
204 return len(self.mailbox.getMessageIdsWithFlag('\\Recent'))
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
205
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
206 def getUnseenCount(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
207 """Return the number of messages with the 'Unseen' flag.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
208 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
209 debug('getUnseenCount')
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
210 return self.getMessageCount()-len(self.mailbox.getMessageIdsWithFlag('\\SEEN'))
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
211
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
212 def isWriteable(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
213 """Get the read/write status of the mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
214 @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
215 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
216 debug('isWriteable')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
217 return True
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
219 def destroy(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
220 """Called before this mailbox is deleted, permanently.
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 debug('destroy')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
223
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
224
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
225 def requestStatus(self, names):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
226 """Return status information about this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
227 @param names: The status names to return information regarding.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
228 The possible values for each name are: MESSAGES, RECENT, UIDNEXT,
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
229 UIDVALIDITY, UNSEEN.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
230 @return: A dictionary containing status information about the
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
231 requested names is returned. If the process of looking this
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
232 information up would be costly, a deferred whose callback will
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
233 eventually be passed this dictionary is returned instead.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
234 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
235 debug('requestStatus')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
236 return imap4.statusRequestHelper(self, names)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
237
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
238 def addListener(self, listener):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
239 """Add a mailbox change listener
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
240
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
241 @type listener: Any object which implements C{IMailboxListener}
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
242 @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
243 be notified when the contents of this mailbox change.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
244 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
245 debug('addListener %s' % listener)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
246 self.listeners.add(listener)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
247
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
248 def removeListener(self, listener):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
249 """Remove a mailbox change listener
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
250
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
251 @type listener: Any object previously added to and not removed from
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
252 this mailbox as a listener.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
253 @param listener: The object to remove from the set of listeners.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
254
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
255 @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
256 this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
257 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
258 debug('removeListener')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
259 if listener in self.listeners:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
260 self.listeners.remove(listener)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
261 else:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
262 raise imap4.MailboxException('Trying to remove an unknown listener')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
263
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
264 def addMessage(self, message, flags = (), date = None):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
265 """Add the given message to this mailbox.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
266 @param message: The RFC822 formatted message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
267 @param flags: The flags to associate with this message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
268 @param date: If specified, the date to associate with this
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
269 @return: A deferred whose callback is invoked with the message
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
270 id if the message is added successfully and whose errback is
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
271 invoked otherwise.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
272 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
273 debug('addMessage')
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
274 raise imap4.MailboxException("Client message addition not implemented yet")
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
275
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
276 def expunge(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
277 """Remove all messages flagged \\Deleted.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
278 @return: The list of message sequence numbers which were deleted,
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
279 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
280 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
281 debug('expunge')
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
282 self.mailbox.removeDeleted()
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
283
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
284 def fetch(self, messages, uid):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
285 """Retrieve one or more messages.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
286 @param messages: The identifiers of messages to retrieve information
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
287 about
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
288 @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
289 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
290 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
291 if uid:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
292 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
293 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
294 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
295 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
296 debug ('stopping iteration')
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
297 raise StopIteration
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
298 try:
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
299 yield (mess_uid,Message(mess_uid,self.mailbox.getFlagsUid(mess_uid), self.mailbox.getMessageUid(mess_uid)))
254
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
300 except IndexError:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
301 continue
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
302 else:
9fc32d1d9046 Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
Goffi <goffi@goffi.org>
parents: 253
diff changeset
303 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
304 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
305 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
306 raise StopIteration
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
307 yield (mess_idx,Message(mess_idx,self.mailbox.getFlags(mess_idx),self.mailbox.getMessage(mess_idx-1)))
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
308
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
309 def store(self, messages, flags, mode, uid):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
310 """Set the flags of one or more messages.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
311 @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
312 @param flags: The flags to set, unset, or add.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
313 @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
314 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
315 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
316 cleared and these flags should be added.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
317 @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
318 otherwise they are message sequence IDs.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
319 @return: A dict mapping message sequence numbers to sequences of str
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
320 representing the flags set on the message after this operation has
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
321 been performed, or a Deferred whose callback will be invoked with
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
322 such a dict.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
323 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
324 debug('store')
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
325
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
326 flags=[flag.upper() for flag in flags]
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
327
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
328 def updateFlags(getF,setF):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
329 ret = {}
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
330 for mess_id in messages:
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
331 if (uid and mess_id == None) or (not uid and mess_id>self.getMessageCount()):
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
332 break
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
333 _flags=set(getF(mess_id) if mode else [])
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
334 if mode==-1:
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
335 _flags.difference_update(set(flags))
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
336 else:
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
337 _flags.update(set(flags))
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
338 new_flags=list(_flags)
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
339 setF(mess_id, new_flags)
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
340 ret[mess_id] = tuple(new_flags)
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
341 return ret
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
342
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
343 if uid:
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
344 messages.last = self.mailbox.getMaxUid()
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
345 messages.getnext = self.mailbox.getNextExistingUid
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
346 ret = updateFlags(self.mailbox.getFlagsUid,self.mailbox.setFlagsUid)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
347 for listener in self.listeners:
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
348 listener.flagsChanged(ret)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
349 return ret
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
350
255
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
351 else:
55b750017b71 plugin IMAP, plugin Maildir: added flag, IMAP's uid management
Goffi <goffi@goffi.org>
parents: 254
diff changeset
352 messages.last = self.getMessageCount()
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
353 ret = updateFlags(self.mailbox.getFlags,self.mailbox.setFlags)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
354 newFlags={}
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
355 for idx in ret:
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
356 #we have to convert idx to uid for the listeners
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
357 newFlags[self.mailbox.getUid(idx)] = ret[idx]
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
358 for listener in self.listeners:
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
359 listener.flagsChanged(newFlags)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
360 return ret
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
361
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
362 def getFlags(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
363 """Return the flags defined in this mailbox
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
364 Flags with the \\ prefix are reserved for use as system flags.
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
365 @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
366 """
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
367 debug('getFlags')
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
368 return ['\\SEEN','\\ANSWERED','\\FLAGGED','\\DELETED','\\DRAFT'] #TODO: add '\\RECENT'
253
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 def getHierarchicalDelimiter(self):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
371 """Get the character which delimits namespaces for in this mailbox.
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 debug('getHierarchicalDelimiter')
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
374 return '.'
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
375
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
376 class ImapSatAccount(imap4.MemoryAccount):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
377 #implements(imap4.IAccount)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
378
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
379 def __init__(self, host, profile):
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
380 debug("ImapAccount init")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
381 self.host=host
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
382 self.profile=profile
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
383 imap4.MemoryAccount.__init__(self,profile)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
384 self.addMailbox("Inbox") #We only manage Inbox for the moment
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
385 debug ('INBOX added')
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 _emptyMailbox(self, name, id):
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
388 return SatMailbox(self.host,name,self.profile)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
389
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
390
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
391 class ImapRealm:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
392 implements(portal.IRealm)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
393
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
394 def __init__(self,host):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
395 self.host = host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
396
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
397 def requestAvatar(self, avatarID, mind, *interfaces):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
398 debug('requestAvatar')
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
399 profile=avatarID.decode('utf-8')
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
400 if imap4.IAccount not in interfaces:
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
401 raise NotImplementedError
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
402 return imap4.IAccount, ImapSatAccount(self.host,profile), lambda:None
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
403
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
404 class SatProfileCredentialChecker:
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
405 """
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
406 This credential checker check against SàT's profile and associated jabber's password
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
407 Check if the profile exists, and if the password is OK
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
408 Return the profile as avatarId
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
409 """
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
410 implements(checkers.ICredentialsChecker)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
411 credentialInterfaces = (credentials.IUsernamePassword,
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
412 credentials.IUsernameHashedPassword)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
413
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
414
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
415 def __init__(self, host):
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
416 self.host = host
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
417
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
418 def _cbPasswordMatch(self, matched, profile):
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
419 if matched:
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
420 return profile.encode('utf-8')
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
421 else:
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
422 return failure.Failure(cred_error.UnauthorizedLogin())
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
423
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
424 def requestAvatarId(self, credentials):
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
425 profiles = self.host.memory.getProfilesList()
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
426 if not credentials.username in profiles:
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
427 return defer.fail(cred_error.UnauthorizedLogin())
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
428 password = self.host.memory.getParamA("Password", "Connection", profile_key=credentials.username)
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
429 return defer.maybeDeferred(
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
430 credentials.checkPassword,
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
431 password).addCallback(
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
432 self._cbPasswordMatch, credentials.username)
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
433
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
434 class ImapServerFactory(protocol.ServerFactory):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
435 protocol = imap4.IMAP4Server
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
436
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
437 def __init__(self, host):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
438 self.host=host
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
439
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
440 def startedConnecting(self, connector):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
441 debug (_("IMAP server connection started"))
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
442
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
443 def clientConnectionLost(self, connector, reason):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
444 debug (_("IMAP server connection lost (reason: %s)"), reason)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
445
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
446 def buildProtocol(self, addr):
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
447 debug ("Building protocole")
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
448 prot = protocol.ServerFactory.buildProtocol(self, addr)
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
449 prot.portal = portal.Portal(ImapRealm(self.host))
257
012c38b56cdd plugin IMAP, plugin Maildir: profile management
Goffi <goffi@goffi.org>
parents: 255
diff changeset
450 prot.portal.registerChecker(SatProfileCredentialChecker(self.host))
253
f45ffbf211e9 MAILDIR + IMAP plugins: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
451 return prot