3
from quotient import im
4
from quotient import grabbers
5
from quotient import formless
7
from twisted.internet import reactor
9
from twisted.python import components
12
class IDomainAdmin(formless.TypedInterface):
13
users = formless.List()
16
class CantRemove(list):
18
return "Sorry, can't remove domains yet."
21
class DeleteUser(list):
27
__implements__ = IDomainAdmin,
29
def __init__(self, domain):
34
## Need a better way to figure out the domain name
35
return '.'.join(self.domain.dirname.split('/')[-1].split('.')[:-1])
40
return DeleteUser(iter(self.domain))
41
users = property(_getUsers)
44
class IRealmAdmin(formless.TypedInterface):
45
def addDomain(self, domainName = formless.String()):
48
Add a domain name to the domains which quotient will handle.
51
addDomain = formless.autocallable(addDomain)
53
domains = formless.List()
57
Shut down the quotient server.
60
shutdown = formless.autocallable(shutdown,action="Shutdown")
63
class IRealmAdminSipChoice(formless.TypedInterface):
64
def addDomain(self,domainName=formless.String(), sip=formless.Boolean()):
67
Add a domain name to the domains for which quotient will recieve mail.
68
You can also choose to have quotient serve as a sip registrar for this domain.
71
addDomain = formless.autocallable(addDomain)
73
domains = formless.List()
77
Shut down the quotient server.
80
shutdown = formless.autocallable(shutdown,action="Shutdown")
83
class IQuotientUser(formless.TypedInterface):
84
fullname = formless.String(label="Name", description="Your full real name.")
85
replyTo = formless.String(
87
description="The address to use as the From address when replying to messages.")
89
def addPopGrabber(self,
90
username = grabbers.username, password = grabbers.password,
91
host = grabbers.host, port = grabbers.popport, msgsPer = grabbers.msgsPer,
95
Add a POP3 email account to be checked by this Quotient account.
97
return grabbers.IGrabberObject
98
addPopGrabber = formless.autocallable(addPopGrabber)
100
def addIMAPGrabber(self,
101
username = grabbers.username, password = grabbers.password,
102
host = grabbers.host, port = grabbers.imapport, msgsPer = grabbers.msgsPer,
106
Add an IMAP email account to be checked by this Quotient account.
108
return grabbers.IGrabberObject
109
addIMAPGrabber = formless.autocallable(addIMAPGrabber)
111
def addInstantMessagingPresence(self,
112
inboundUsername = im.iUser,
113
inboundPassword = im.iPass,
114
inboundProtocol = im.iProto,
115
# account = im.IInstantMessagingObject):
116
outboundUsername = im.oUser,
117
outboundPassword = im.oPass,
118
outboundProtocol = im.oProto,
119
host = grabbers.host,
120
port = grabbers.port):
123
Add an instant messaging presence on an IRC network"""
124
return im.IInstantMessagingObject
125
addInstantMessagingPresence = formless.autocallable(addInstantMessagingPresence)
127
def importDirectory(self,
128
d = formless.Directory(
130
description="The directory on the server's filesystem to import.")):
133
Import a directory full of email messages into this Quotient account.
136
importDirectory = formless.autocallable(importDirectory)
138
def importMailbox(self,
141
description="The mailbox on the server's filesystem to import.")):
144
Import an mbox-format file into this Quotient account.
147
importMailbox = formless.autocallable(importMailbox)
149
tasks = formless.List()
152
class CheckDuplicateUser(formless.Compound):
153
def coerceWithBinding(self, data, binding):
155
binding.getAvatarByEmail('%s@%s' % tuple(data))
158
raise formless.InputError('Sorry, the user %s@%s already exists. Please try again.' % tuple(data))
161
class IRealmSignup(formless.TypedInterface):
164
req=formless.Request(), # the web request
165
localpartAndDomain=CheckDuplicateUser(
166
[formless.String(label="Username"),
167
formless.Choice(label="Domain", choicesAttribute="domainNames")],
170
password=formless.Password(label="Password"),
171
fullname=formless.String(label="Full name")):
174
Fill in the relevant information to create a new quotient account.
176
return formless.Object(IQuotientUser, label="New user")
177
webSignUp = formless.autocallable(webSignUp)
181
__implements__ = IRealmSignup, IRealmAdmin
183
def __init__(self, original, sipRegistrar=True):
184
self.original = original
185
for forward in ['webSignUp', 'getAvatarByEmail']:
186
setattr(self, forward, getattr(self.original, forward))
187
self.sipRegistrar = sipRegistrar
189
def addDomain(self, domainName):
190
self.original.addDomain(domainName)
191
if self.sipRegistrar:
192
sip = self.original.service.getServiceNamed("SIP-Registrar")
193
sip.registry.addDomain(domainName)
196
reactor.callLater(2, reactor.stop)
197
return "The server will shut down in 2 seconds."
199
domains = property(lambda self: CantRemove([DomainAdmin(x) for x in iter(self.original.domains)]))
201
domainNames = property(lambda self: self.original.domainNames)
204
class SipChoiceAdministrator(Administrator):
205
__implements__ = IRealmSignup, IRealmAdminSipChoice
207
def addDomain(self, domainName, sip):
208
self.sipRegistrar = sip
209
Administrator.addDomain(self, domainName)