當前位置: 首頁>>代碼示例>>Python>>正文


Python Auth.find_recipient方法代碼示例

本文整理匯總了Python中pykolab.auth.Auth.find_recipient方法的典型用法代碼示例。如果您正苦於以下問題:Python Auth.find_recipient方法的具體用法?Python Auth.find_recipient怎麽用?Python Auth.find_recipient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pykolab.auth.Auth的用法示例。


在下文中一共展示了Auth.find_recipient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_001_two_johns

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
    def test_001_two_johns(self):
        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        user_add("John", "Doe")

        time.sleep(3)

        auth = Auth()
        auth.connect()

        max_tries = 20
        while max_tries > 0:
            recipient1 = auth.find_recipient('[email protected]')
            recipient2 = auth.find_recipient('[email protected]')

            if not recipient1 or not recipient2:
                time.sleep(1)
                max_tries -= 1
            else:
                break

        imap = IMAP()
        imap.connect()

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "No INBOX found for first John")

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "No INBOX found for second John")
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:31,代碼來源:test_003_two_johns.py

示例2: test_001_user_rename

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
    def test_001_user_rename(self):
        """
            Rename user "Doe, John" to "Sixpack, Joe" and verify the recipient
            policy is applied, and the IMAP INBOX folder for the user is
            renamed.
        """
        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient('[email protected]')
        user_info = wap_client.user_info(recipient)

        if not user_info.has_key('mailhost'):
            from tests.functional.synchronize import synchronize_once
            synchronize_once()

        imap = IMAP()
        imap.connect()
        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1)

        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient("%(local)[email protected]%(domain)s" % (self.user))

        user_info = wap_client.user_info(recipient)
        user_info['sn'] = 'Sixpack'
        user_info['givenname'] = 'Joe'
        user_info['uid'] = 'sixpack'
        user_edit = wap_client.user_edit(recipient, user_info)

        time.sleep(2)

        print imap.lm()

        user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')
        if not user_info['mail'] == '[email protected]':
            from tests.functional.synchronize import synchronize_once
            synchronize_once()
            user_info = wap_client.user_info('uid=sixpack,ou=People,dc=example,dc=org')

        self.assertEqual(user_info['mail'], '[email protected]')

        print imap.lm()

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 0, "INBOX for john.doe still exists")

        folders = imap.lm('user/[email protected]')
        self.assertEqual(len(folders), 1, "INBOX for joe.sixpack does not exist")
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:51,代碼來源:test_002_user_rename.py

示例3: test_002_user_recipient_policy_duplicate

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
    def test_002_user_recipient_policy_duplicate(self):
        from tests.functional.user_add import user_add
        user = {
                'local': 'jane.doe',
                'domain': 'example.org'
            }
        user_add("Jane", "Doe")

        time.sleep(3)

        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient("%(local)[email protected]%(domain)s" % (user))
        if hasattr(self, 'assertIsInstance'):
            self.assertIsInstance(recipient, str)

        self.assertEqual(recipient, "uid=doe2,ou=People,dc=example,dc=org")

        result = wap_client.user_info(recipient)

        if not result.has_key('mailhost'):
            from tests.functional.synchronize import synchronize_once
            synchronize_once()

        result = wap_client.user_info(recipient)

        self.assertEqual(result['mail'], '[email protected]')
        self.assertEqual(result['alias'], ['[email protected]', '[email protected]'])
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:30,代碼來源:test_001_user_sync.py

示例4: execute

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
def execute(*args, **kw):
    """
        Transfer mailbox
    """

    if len(conf.cli_args) > 1:
        mailfolder = conf.cli_args.pop(0)
        target_server = conf.cli_args.pop(0)

    if len(conf.cli_args) > 0:
        target_partition = conf.cli_args.pop(0)

    imap = IMAP()
    imap.connect()

    mbox_parts = imap.parse_mailfolder(mailfolder)

    if mbox_parts['domain'] == None:
        domain = conf.get('kolab', 'primary_domain')
        user_identifier = mbox_parts['path_parts'][1]
    else:
        domain = mbox_parts['domain']
        user_identifier = "%[email protected]%s" % (mbox_parts['path_parts'][1], mbox_parts['domain'])

    auth = Auth(domain=domain)
    auth.connect()

    user = auth.find_recipient(user_identifier)

    source_server = imap.user_mailbox_server(mailfolder)
    imap.connect(server=source_server)
    imap.imap.xfer(mailfolder, target_server)

    if not user == None and not len(user) < 1:
        auth.set_entry_attributes(domain, user, {'mailhost': target_server})
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:37,代碼來源:cmd_transfer_mailbox.py

示例5: execute

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
def execute(*args, **kw):
    try:
        address = conf.cli_args.pop(0)
    except:
        address = utils.ask_question(_("Email Address"))

    script_to_put = conf.cli_args.pop(0)
    
    script_put_name = conf.cli_args.pop(0)

    auth = Auth()
    auth.connect()

    user = auth.find_recipient(address)

    # Get the main, default backend
    backend = conf.get('kolab', 'imap_backend')

    if len(address.split('@')) > 1:
        domain = address.split('@')[1]
    else:
        domain = conf.get('kolab', 'primary_domain')

    if conf.has_section(domain) and conf.has_option(domain, 'imap_backend'):
        backend = conf.get(domain, 'imap_backend')

    if conf.has_section(domain) and conf.has_option(domain, 'imap_uri'):
        uri = conf.get(domain, 'imap_uri')
    else:
        uri = conf.get(backend, 'uri')

    hostname = None
    port = None

    result = urlparse(uri)

    if hasattr(result, 'hostname'):
        hostname = result.hostname
    else:
        scheme = uri.split(':')[0]
        (hostname, port) = uri.split('/')[2].split(':')

    port = 4190

    # Get the credentials
    admin_login = conf.get(backend, 'admin_login')
    admin_password = conf.get(backend, 'admin_password')

    import sievelib.managesieve
 
    sieveclient = sievelib.managesieve.Client(hostname, port, False)
    sieveclient.connect(None, None, True)
    sieveclient._plain_authentication(admin_login, admin_password, address)
    sieveclient.authenticated = True

    sieveclient.putscript(script_put_name, open(script_to_put, "r").read())
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:58,代碼來源:cmd_put.py

示例6: test_001_user_recipient_policy

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
    def test_001_user_recipient_policy(self):
        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient("%(local)[email protected]%(domain)s" % (self.user))
        if hasattr(self, 'assertIsInstance'):
            self.assertIsInstance(recipient, str)

        self.assertEqual(recipient, "uid=doe,ou=People,dc=example,dc=org")

        result = wap_client.user_info(recipient)

        self.assertEqual(result['mail'], '[email protected]')
        self.assertEqual(result['alias'], ['[email protected]', '[email protected]'])
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:15,代碼來源:test_001_user_sync.py

示例7: test_002_fr_FR_user_recipient_policy

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
    def test_002_fr_FR_user_recipient_policy(self):
        auth = Auth()
        auth.connect()
        recipient = auth.find_recipient("%(local)[email protected]%(domain)s" % (self.user))
        if hasattr(self, 'assertIsInstance'):
            self.assertIsInstance(recipient, str)

        self.assertEqual(recipient, "uid=fuentes,ou=People,dc=example,dc=org")

        result = wap_client.user_info(recipient)

        self.assertEqual(result['mail'], '[email protected]')
        self.assertEqual(sorted(result['alias']), ['[email protected]', '[email protected]'])
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:15,代碼來源:test_004_user_add_es_ES.py

示例8: test_001_default

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
    def test_001_default(self):
        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        from tests.functional.synchronize import synchronize_once
        synchronize_once()

        auth = Auth()
        auth.connect()

        user = auth.find_recipient('[email protected]')

        user_info = wap_client.user_info(user)

        self.assertEqual(user_info['uid'], "doe")

        from tests.functional.purge_users import purge_users
        purge_users()
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:19,代碼來源:test_007_policy_uid.py

示例9: test_003_givenname_fc_dot_surname

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
    def test_003_givenname_fc_dot_surname(self):
        self.set('example.org', 'policy_uid', "'%(givenname)s'[0:1].%(surname)s")

        from tests.functional.user_add import user_add
        user_add("John", "Doe")
        from tests.functional.synchronize import synchronize_once
        synchronize_once()

        auth = Auth()
        auth.connect()

        user = auth.find_recipient('[email protected]')

        user_info = wap_client.user_info(user)

        self.assertEqual(user_info['uid'], "J.Doe")

        from tests.functional.purge_users import purge_users
        purge_users()
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:21,代碼來源:test_007_policy_uid.py

示例10: execute

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
def execute(*args, **kw):
    try:
        address = conf.cli_args.pop(0)
    except:
        address = utils.ask_question(_("Email Address"))

    auth = Auth()
    auth.connect()

    user = auth.find_recipient(address)

    # Get the main, default backend
    backend = conf.get('kolab', 'imap_backend')

    if len(address.split('@')) > 1:
        domain = address.split('@')[1]
    else:
        domain = conf.get('kolab', 'primary_domain')

    if conf.has_section(domain) and conf.has_option(domain, 'imap_backend'):
        backend = conf.get(domain, 'imap_backend')

    if conf.has_section(domain) and conf.has_option(domain, 'imap_uri'):
        uri = conf.get(domain, 'imap_uri')
    else:
        uri = conf.get(backend, 'uri')

    hostname = None
    port = None

    result = urlparse(uri)

    if hasattr(result, 'hostname'):
        hostname = result.hostname
    else:
        scheme = uri.split(':')[0]
        (hostname, port) = uri.split('/')[2].split(':')

    port = 4190

    # Get the credentials
    admin_login = conf.get(backend, 'admin_login')
    admin_password = conf.get(backend, 'admin_password')

    import sievelib.managesieve

    sieveclient = sievelib.managesieve.Client(hostname, port, conf.debuglevel > 8)
    sieveclient.connect(None, None, True)
    result = sieveclient._plain_authentication(admin_login, admin_password, address)
    if not result:
        print "LOGIN FAILED??"
    
    sieveclient.authenticated = True

    result = sieveclient.listscripts()
    
    if result == None:
        print "No scripts"
        sys.exit(0)

    (active, scripts) = result

    print "%s (active)" % (active)
    for script in scripts:
        print script
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:67,代碼來源:cmd_list.py

示例11: execute

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
def execute(*args, **kw):
    try:
        email_address = conf.cli_args.pop(0)
    except IndexError, errmsg:
        email_address = utils.ask_question("Email address to remove")

    # Get the domain from the email address
    if len(email_address.split('@')) > 1:
        domain = email_address.split('@')[1]
    else:
        log.error(_("Invalid or unqualified email address."))
        sys.exit(1)

    auth = Auth()
    auth.connect(domain=domain)
    recipients = auth.find_recipient(email_address)

    if len(recipients) == 0:
        log.error(_("No recipient found for email address %r") % (email_address))
        sys.exit(1)

    log.debug(_("Found the following recipient(s): %r") % (recipients), level=8)

    mail_attributes = conf.get_list(domain, 'mail_attributes')
    if mail_attributes == None or len(mail_attributes) < 1:
        mail_attributes = conf.get_list(conf.get('kolab', 'auth_mechanism'), 'mail_attributes')

    log.debug(_("Using the following mail attributes: %r") % (mail_attributes), level=8)

    if isinstance(recipients, basestring):
        recipient = recipients
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:33,代碼來源:cmd_remove_mailaddress.py

示例12: Auth

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
        folders = []

        folders.extend(imap.lm('shared/%%@%s' % (primary)))
        folders.extend(imap.lm('user/%%@%s' % (primary)))

        for secondary in secondaries:
            folders.extend(imap.lm('shared/%%@%s' % (secondary)))
            folders.extend(imap.lm('user/%%@%s' % (secondary)))

        auth = Auth(domain=primary)
        auth.connect()

        for folder in folders:
            server = imap.user_mailbox_server(folder)
            recipient = auth.find_recipient('/'.join(folder.split('/')[1:]))
            if (isinstance(recipient, list)):
                if len(recipient) > 1:
                    log.warning(_("Multiple recipients for '%s'!") % ('/'.join(folder.split('/')[1:])))
                    continue
                elif len(recipient) == 0:
                    if conf.delete:
                        if conf.dry_run:
                            if not folder.split('/')[0] == 'shared':
                                log.warning(_("No recipients for '%s' (would have deleted the mailbox if not for --dry-run)!") % ('/'.join(folder.split('/')[1:])))
                            else:
                                continue
                        else:
                            if not '/'.join(folder.split('/')[0]) == 'shared':
                                log.info(_("Deleting mailbox '%s' because it has no recipients") % (folder))
                                try:
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:32,代碼來源:cmd_sync_mailhost_attrs.py

示例13: execute

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
def execute(*args, **kw):

    try:
        primary_rcpt_address = conf.cli_args.pop(0)
        try:
            secondary_rcpt_address = conf.cli_args.pop(0)
        except:
            print >> sys.stderr, _("Specify the (new) alias address")
            sys.exit(1)
    except:
        print >> sys.stderr, _("Specify the existing recipient address")
        sys.exit(1)

    if len(primary_rcpt_address.split('@')) > 1:
        primary_rcpt_domain = primary_rcpt_address.split('@')[-1]
    else:
        primary_rcpt_domain = conf.get('kolab', 'primary_domain')

    auth = Auth(domain=primary_rcpt_domain)

    domains = auth.list_domains()

    #print domains

    if len(secondary_rcpt_address.split('@')) > 1:
        secondary_rcpt_domain = secondary_rcpt_address.split('@')[-1]
    else:
        secondary_rcpt_domain = conf.get('kolab', 'primary_domain')

    # Check if either is in fact a domain
    if not primary_rcpt_domain.lower() in domains.keys():
        print >> sys.stderr, _("Domain %r is not a local domain") % (primary_rcpt_domain)
        sys.exit(1)

    if not secondary_rcpt_domain.lower() in domains.keys():
        print >> sys.stderr, _("Domain %r is not a local domain") % (secondary_rcpt_domain)
        sys.exit(1)

    if not primary_rcpt_domain == secondary_rcpt_domain:
        if not domains[primary_rcpt_domain] == domains[secondary_rcpt_domain]:
            print >> sys.stderr, _("Primary and secondary domain do not have the same parent domain")
            sys.exit(1)

    primary_recipient_dn = auth.find_recipient(primary_rcpt_address)

    if primary_recipient_dn == [] or len(primary_recipient_dn) == 0:
        print >> sys.stderr, _("No such recipient %r") % (primary_rcpt_address)
        sys.exit(1)

    secondary_recipient_dn = auth.find_recipient(secondary_rcpt_address)

    if not secondary_recipient_dn == [] and not len(secondary_recipient_dn) == 0:
        print >> sys.stderr, _("Recipient for alias %r already exists") % (secondary_rcpt_address)
        sys.exit(1)

    rcpt_attrs = conf.get_list('ldap', 'mail_attributes')

    primary_rcpt_attr = rcpt_attrs[0]

    if len(rcpt_attrs) >= 2:
        secondary_rcpt_attr = rcpt_attrs[1]
    else:
        print >> sys.stderr, _("Environment is not configured for " + \
            "users to hold secondary mail attributes")

        sys.exit(1)

    primary_recipient = auth.get_entry_attributes(primary_rcpt_domain, primary_recipient_dn, rcpt_attrs)

    if not primary_recipient.has_key(primary_rcpt_attr):
        print >> sys.stderr, _("Recipient %r is not the primary recipient for address %r") % (primary_recipient, primary_rcpt_address)
        sys.exit(1)

    if not primary_recipient.has_key(secondary_rcpt_attr):
        auth.set_entry_attributes(primary_rcpt_domain, primary_recipient_dn, {secondary_rcpt_attr: [ secondary_rcpt_address ] })
    else:
        if isinstance(primary_recipient[secondary_rcpt_attr], basestring):
            new_secondary_rcpt_attrs = [
                    primary_recipient[secondary_rcpt_attr],
                    secondary_rcpt_address
                ]

        else:
            new_secondary_rcpt_attrs = \
                    primary_recipient[secondary_rcpt_attr] + \
                    [ secondary_rcpt_address ]

        auth.set_entry_attributes(
                primary_rcpt_domain,
                primary_recipient_dn,
                {
                        secondary_rcpt_attr: new_secondary_rcpt_attrs
                    }
            )
開發者ID:tpokorra,項目名稱:pykolab,代碼行數:96,代碼來源:cmd_add_alias.py

示例14: test_002_add_aliases

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]
    def test_002_add_aliases(self):
        auth = Auth()
        auth.connect()

        recipient = auth.find_recipient('[email protected]')
        wap_client.user_edit(recipient, {'alias': ['[email protected]', '[email protected]', '[email protected]', '[email protected]']})
開發者ID:detrout,項目名稱:pykolab,代碼行數:8,代碼來源:test_004_many_aliases.py

示例15: PolicyRequest

# 需要導入模塊: from pykolab.auth import Auth [as 別名]
# 或者: from pykolab.auth.Auth import find_recipient [as 別名]

#.........這裏部分代碼省略.........
        """
            Verify that the SASL username or lack thereof corresponds with
            allowing or disallowing authenticated users.

            If an SASL username is supplied, use it to obtain the authentication
            database user object including all attributes we may find ourselves
            interested in.
        """

        if self.sasl_username == None:
            if not conf.allow_unauthenticated:
                reject(_("Unauthorized access not allowed"))
            else:
                # If unauthenticated is allowed, I have nothing to do here.
                return True

        sasl_username = self.sasl_username

        # If we have an sasl_username, find the user object in the
        # authentication database, along with the attributes we are
        # interested in.
        if self.sasl_domain == None:
            if len(self.sasl_username.split('@')) > 1:
                self.sasl_domain = self.sasl_username.split('@')[1]
            else:
                self.sasl_domain = conf.get('kolab', 'primary_domain')
                sasl_username = "%[email protected]%s" % (self.sasl_username, self.sasl_domain)

        if self.auth == None:
            self.auth = Auth(self.sasl_domain)
        elif not self.auth.domain == self.sasl_domain:
            self.auth = Auth(self.sasl_domain)

        sasl_users = self.auth.find_recipient(
                sasl_username,
                domain=self.sasl_domain
            )

        if isinstance(sasl_users, list):
            if len(sasl_users) == 0:
                log.error(_("Could not find recipient"))
                return False
            else:
                self.sasl_user = { 'dn': sasl_users[0] }
        elif isinstance(sasl_users, basestring):
            self.sasl_user = { 'dn': sasl_users }

        if not self.sasl_user['dn']:
            # Got a final answer here, do the caching thing.
            cache_update(
                    function='verify_sender',
                    sender=self.sender,
                    recipients=self.recipients,
                    result=(int)(False),
                    sasl_username=self.sasl_username,
                    sasl_sender=self.sasl_sender
                )

            reject(
                    _("Could not find envelope sender user %s") % (
                            self.sasl_username
                        )
                )

        attrs = conf.get_list(self.sasl_domain, 'auth_attributes')
開發者ID:detrout,項目名稱:pykolab,代碼行數:69,代碼來源:kolab_smtp_access_policy.py


注:本文中的pykolab.auth.Auth.find_recipient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。