add new mailbox handling tasks

This commit is contained in:
Jan Dittberner 2014-12-27 14:48:18 +01:00
parent 3bdf634703
commit a285133f75
2 changed files with 57 additions and 0 deletions

View file

@ -1,6 +1,9 @@
Changelog Changelog
========= =========
* :feature:`-` add new mailbox handling tasks
:py:func:`osusers.tasks.create_file_mailbox` and
:py:func:`osusers.tasks.delete_file_mailbox`
* :support:`-` move celery routers into gvacommon that is in it's own * :support:`-` move celery routers into gvacommon that is in it's own
repository to be used by others (gva, gvaldap) repository to be used by others (gva, gvaldap)
* :bug:`-` sftp directories are now owned by root instead of user * :bug:`-` sftp directories are now owned by root instead of user

View file

@ -143,3 +143,57 @@ def delete_file_mail_userdir(username):
raise GVAFileException( raise GVAFileException(
"could not remove mail base directory of user %s" % username) "could not remove mail base directory of user %s" % username)
return mail_directory return mail_directory
@shared_task
def create_file_mailbox(username, mailboxname):
"""
This task creates a new mailbox directory for the given user and mailbox
name.
:param str username: the user name
:param str mailboxname: the mailbox name
:raises GVAFileException: if the mailbox directory cannot be created
:return: the created mailbox directory name
:rtype: str
"""
mailbox_directory = os.path.join(
_build_mail_directory_name(username), mailboxname)
try:
subprocess.check_output([
SUDO_CMD, INSTALL_CMD, '-o', username, '-g', username,
'-m', '0700', '-d', mailbox_directory], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
_logger.exception(
'could not create mailbox %s for user %s', mailboxname, username)
raise GVAFileException(
"could not create mailbox %s for user %s" % (mailboxname, username)
)
return mailbox_directory
@shared_task
def delete_file_mailbox(username, mailboxname):
"""
This task deletes the given mailbox of the given user.
:param str username: the user name
:param str mailboxname: the mailbox name
:raises GVAFileException: if the mailbox directory cannot be deleted
:return: the deleted mailbox directory name
:rtype: str
"""
mailbox_directory = os.path.join(
_build_mail_directory_name(username), mailboxname)
try:
subprocess.check_output([
SUDO_CMD, RM_CMD, '-r', '-f', mailbox_directory],
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
_logger.exception(
'could not remove mailbox %s of user %s', mailboxname, username)
raise GVAFileException(
"could not remove mailbox %s of user %s" % (mailboxname, username))
return mailbox_directory