269 uid = account.uid |
269 uid = account.uid |
270 os.chdir(domdir) |
270 os.chdir(domdir) |
271 os.mkdir('%s' % uid, self._cfg.dget('account.directory_mode')) |
271 os.mkdir('%s' % uid, self._cfg.dget('account.directory_mode')) |
272 os.chown('%s' % uid, uid, account.gid) |
272 os.chown('%s' % uid, uid, account.gid) |
273 |
273 |
|
274 def _make_account_dirs(self, account): |
|
275 """Create all necessary directories for the account.""" |
|
276 oldpwd = os.getcwd() |
|
277 self._make_home(account) |
|
278 mailbox = new_mailbox(account) |
|
279 mailbox.create() |
|
280 folders = self._cfg.dget('mailbox.folders').split(':') |
|
281 if any(folders): |
|
282 bad = mailbox.add_boxes(folders, |
|
283 self._cfg.dget('mailbox.subscribe')) |
|
284 if bad: |
|
285 self._warnings.append(_(u"Skipped mailbox folders:") + |
|
286 '\n\t- ' + '\n\t- '.join(bad)) |
|
287 os.chdir(oldpwd) |
|
288 |
274 def _delete_home(self, domdir, uid, gid): |
289 def _delete_home(self, domdir, uid, gid): |
275 """Delete a user's home directory. |
290 """Delete a user's home directory. |
276 |
291 |
277 Arguments: |
292 Arguments: |
278 |
293 |
492 return search(self._dbh, pattern=pattern, like=like) |
507 return search(self._dbh, pattern=pattern, like=like) |
493 |
508 |
494 def user_add(self, emailaddress, password): |
509 def user_add(self, emailaddress, password): |
495 """Wrapper around Account.set_password() and Account.save().""" |
510 """Wrapper around Account.set_password() and Account.save().""" |
496 acc = self._get_account(emailaddress) |
511 acc = self._get_account(emailaddress) |
|
512 if acc: |
|
513 raise VMMError(_(u"The account '%s' already exists.") % |
|
514 acc.address, ACCOUNT_EXISTS) |
497 acc.set_password(password) |
515 acc.set_password(password) |
498 acc.save() |
516 acc.save() |
499 oldpwd = os.getcwd() |
517 self._make_account_dirs(acc) |
500 self._make_home(acc) |
|
501 mailbox = new_mailbox(acc) |
|
502 mailbox.create() |
|
503 folders = self._cfg.dget('mailbox.folders').split(':') |
|
504 if any(folders): |
|
505 bad = mailbox.add_boxes(folders, |
|
506 self._cfg.dget('mailbox.subscribe')) |
|
507 if bad: |
|
508 self._warnings.append(_(u"Skipped mailbox folders:") + |
|
509 '\n\t- ' + '\n\t- '.join(bad)) |
|
510 os.chdir(oldpwd) |
|
511 |
518 |
512 def alias_add(self, aliasaddress, *targetaddresses): |
519 def alias_add(self, aliasaddress, *targetaddresses): |
513 """Creates a new `Alias` entry for the given *aliasaddress* with |
520 """Creates a new `Alias` entry for the given *aliasaddress* with |
514 the given *targetaddresses*.""" |
521 the given *targetaddresses*.""" |
515 alias = self._get_alias(aliasaddress) |
522 alias = self._get_alias(aliasaddress) |