示例#1
0
    def mail_home(self):
        """Retrieve the home directory of this mailbox.

        The home directory refers to the place on the file system
        where the mailbox data is stored.

        We ask dovecot to give us this information because there are
        several patterns to understand and we don't want to implement
        them.
        """
        admin_params = dict(param_tools.get_global_parameters("admin"))
        if not admin_params.get("handle_mailboxes"):
            return None
        if self.__mail_home is None:
            curuser = pwd.getpwuid(os.getuid()).pw_name
            mbowner = admin_params["mailboxes_owner"]
            options = {}
            if curuser != mbowner:
                options["sudo_user"] = mbowner
            code, output = doveadm_cmd(
                "user -f home %s" % self.full_address, **options
            )
            if code:
                raise lib_exceptions.InternalError(
                    _("Failed to retrieve mailbox location (%s)") % output)
            self.__mail_home = output.strip()
        return self.__mail_home
示例#2
0
    def mail_home(self):
        """Retrieve the home directory of this mailbox.

        The home directory refers to the place on the file system
        where the mailbox data is stored.

        We ask dovecot to give us this information because there are
        several patterns to understand and we don't want to implement
        them.
        """
        admin_params = dict(param_tools.get_global_parameters("admin"))
        if not admin_params.get("handle_mailboxes"):
            return None
        if self.__mail_home is None:
            curuser = pwd.getpwuid(os.getuid()).pw_name
            mbowner = admin_params["mailboxes_owner"]
            options = {}
            if curuser != mbowner:
                options["sudo_user"] = mbowner
            code, output = doveadm_cmd("user -f home %s" % self.full_address,
                                       **options)
            if code:
                raise lib_exceptions.InternalError(
                    _("Failed to retrieve mailbox location (%s)") % output)
            self.__mail_home = output.strip()
        return self.__mail_home
示例#3
0
def get_dovecot_schemes():
    """Return schemes supported by dovecot"""
    supported_schemes = None
    try:
        _, schemes = doveadm_cmd("pw -l")
    except OSError:
        pass
    else:
        supported_schemes = ["{{{}}}".format(smart_text(scheme))
                             for scheme in schemes.split()]

    if not supported_schemes:
        supported_schemes = ['{PLAIN}']

    return supported_schemes
示例#4
0
文件: __init__.py 项目: tsabi/modoboa
def get_dovecot_schemes():
    """Return schemes supported by Dovecot.

    It first try to get supported schemes fron the settings, then from the
    doveadm output, and fallback to {MD5-CRYPT} and {PLAIN} if the command
    is not found.

    :return: A list of supported '{SCHEME}'
    """
    schemes = getattr(settings, "DOVECOT_SUPPORTED_SCHEMES", None)
    default_schemes = "MD5-CRYPT PLAIN"

    if not schemes:
        try:
            retcode, schemes = doveadm_cmd("pw -l")
        except OSError:
            schemes = default_schemes
        else:
            if retcode:
                schemes = default_schemes

    return ["{{{}}}".format(smart_text(scheme))
            for scheme in schemes.split()]