35 RE_ASCII_CHARS = """^[\x20-\x7E]*$""" |
35 RE_ASCII_CHARS = """^[\x20-\x7E]*$""" |
36 RE_DOMAIN = """^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$""" |
36 RE_DOMAIN = """^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$""" |
37 RE_DOMAIN_SRCH = """^[a-z0-9-\.]+$""" |
37 RE_DOMAIN_SRCH = """^[a-z0-9-\.]+$""" |
38 RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]""" |
38 RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]""" |
39 RE_MAILLOCATION = """^[\w]{1,20}$""" |
39 RE_MAILLOCATION = """^[\w]{1,20}$""" |
|
40 RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$""" |
40 |
41 |
41 class VirtualMailManager: |
42 class VirtualMailManager: |
42 """The main class for vmm""" |
43 """The main class for vmm""" |
43 def __init__(self): |
44 def __init__(self): |
44 """Creates a new VirtualMailManager instance. |
45 """Creates a new VirtualMailManager instance. |
276 os.umask(0007) |
277 os.umask(0007) |
277 self.__makedir(domdirdirs[1], self.__Cfg.getint('domdir', 'mode'), 0, |
278 self.__makedir(domdirdirs[1], self.__Cfg.getint('domdir', 'mode'), 0, |
278 gid) |
279 gid) |
279 os.chdir(oldpwd) |
280 os.chdir(oldpwd) |
280 |
281 |
|
282 def __subscribeFL(self, folderlist, uid, gid): |
|
283 fname = self.__Cfg.get('maildir', 'name') + '/subscriptions' |
|
284 sf = file(fname, 'w') |
|
285 for f in folderlist: |
|
286 sf.write(f+'\n') |
|
287 sf.flush() |
|
288 sf.close() |
|
289 os.chown(fname, uid, gid) |
|
290 os.chmod(fname, 384) |
|
291 |
281 def __mailDirMake(self, domdir, uid, gid): |
292 def __mailDirMake(self, domdir, uid, gid): |
282 """Creates maildirs and maildir subfolders. |
293 """Creates maildirs and maildir subfolders. |
283 |
294 |
284 Keyword arguments: |
295 Keyword arguments: |
|
296 domdir -- the path to the domain directory |
285 uid -- user id from the account |
297 uid -- user id from the account |
286 gid -- group id from the account |
298 gid -- group id from the account |
287 """ |
299 """ |
288 os.umask(0007) |
300 os.umask(0007) |
289 oldpwd = os.getcwd() |
301 oldpwd = os.getcwd() |
290 os.chdir(domdir) |
302 os.chdir(domdir) |
291 |
303 |
292 maildir = '%s' % self.__Cfg.get('maildir', 'folder') |
304 re.compile(RE_MBOX_NAMES) |
293 folders = [maildir , maildir+'/.Drafts', maildir+'/.Sent', |
305 maildir = self.__Cfg.get('maildir', 'name') |
294 maildir+'/.Templates', maildir+'/.Trash'] |
306 folders = [maildir] |
|
307 for folder in self.__Cfg.get('maildir', 'folders').split(':'): |
|
308 folder = folder.strip() |
|
309 if len(folder) and not folder.count('..')\ |
|
310 and re.match(RE_MBOX_NAMES, folder): |
|
311 folders.append('%s/.%s' % (maildir, folder)) |
295 subdirs = ['cur', 'new', 'tmp'] |
312 subdirs = ['cur', 'new', 'tmp'] |
296 mode = self.__Cfg.getint('maildir', 'mode') |
313 mode = self.__Cfg.getint('maildir', 'mode') |
297 |
314 |
298 self.__makedir('%s' % uid, mode, uid, gid) |
315 self.__makedir('%s' % uid, mode, uid, gid) |
299 os.chdir('%s' % uid) |
316 os.chdir('%s' % uid) |
300 for folder in folders: |
317 for folder in folders: |
301 self.__makedir(folder, mode, uid, gid) |
318 self.__makedir(folder, mode, uid, gid) |
302 for subdir in subdirs: |
319 for subdir in subdirs: |
303 self.__makedir(folder+'/'+subdir, mode, uid, gid) |
320 self.__makedir(folder+'/'+subdir, mode, uid, gid) |
|
321 self.__subscribeFL([f.replace(maildir+'/.', '') for f in folders[1:]], |
|
322 uid, gid) |
304 os.chdir(oldpwd) |
323 os.chdir(oldpwd) |
305 |
324 |
306 def __userDirDelete(self, domdir, uid, gid): |
325 def __userDirDelete(self, domdir, uid, gid): |
307 if uid > 0 and gid > 0: |
326 if uid > 0 and gid > 0: |
308 userdir = '%s' % uid |
327 userdir = '%s' % uid |
558 def userAdd(self, emailaddress, password): |
577 def userAdd(self, emailaddress, password): |
559 acc = self.__getAccount(emailaddress, password) |
578 acc = self.__getAccount(emailaddress, password) |
560 if password is None: |
579 if password is None: |
561 password = self._readpass() |
580 password = self._readpass() |
562 acc.setPassword(self.__pwhash(password)) |
581 acc.setPassword(self.__pwhash(password)) |
563 acc.save(self.__Cfg.get('maildir', 'folder'), |
582 acc.save(self.__Cfg.get('maildir', 'name'), |
564 self.__Cfg.getboolean('services', 'smtp'), |
583 self.__Cfg.getboolean('services', 'smtp'), |
565 self.__Cfg.getboolean('services', 'pop3'), |
584 self.__Cfg.getboolean('services', 'pop3'), |
566 self.__Cfg.getboolean('services', 'imap'), |
585 self.__Cfg.getboolean('services', 'imap'), |
567 self.__Cfg.getboolean('services', 'managesieve')) |
586 self.__Cfg.getboolean('services', 'managesieve')) |
568 self.__mailDirMake(acc.getDir('domain'), acc.getUID(), acc.getGID()) |
587 self.__mailDirMake(acc.getDir('domain'), acc.getUID(), acc.getGID()) |