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


Python rfc822.parseaddr方法代碼示例

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


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

示例1: canon_email

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import parseaddr [as 別名]
def canon_email(address):
    address = to_utf8(address)
    address = parseaddr(address)[1]
    if not address:
        raise ValueError("email address must be non-empty")
    if '@' not in address:
        raise ValueError("email address does not contain the required '@' character")
    localpart, hostname = address.split('@')
    hostname = hostname.rstrip('.')
    if not hostname:
        raise ValueError("email address hostname must be non-empty")
    if '.' not in hostname:
        raise ValueError("email address hostname must contain the '.' character and a domain name")
    if not localpart:
        raise ValueError("email address local part must be non-empty")
#   if '+' in localpart:
#       raise ValueError("email address local part must not contain the '+' character.")
    hostname = encode_idna(hostname)
    hostname = hostname.decode('utf-8').lower().encode('utf-8')
    address = '%s@%s' % (localpart, hostname)
    if not _valid_email_re.match(address):
        raise ValueError("email address does not match the permitted pattern")
    return address 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:25,代碼來源:user.py

示例2: _checkStateMX

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import parseaddr [as 別名]
def _checkStateMX(self):
        nextMessages = self.queue.getWaiting()
        nextMessages.reverse()

        exchanges = {}
        for msg in nextMessages:
            from_, to = self.queue.getEnvelope(msg)
            name, addr = rfc822.parseaddr(to)
            parts = addr.split('@', 1)
            if len(parts) != 2:
                log.err("Illegal message destination: " + to)
                continue
            domain = parts[1]

            self.queue.setRelaying(msg)
            exchanges.setdefault(domain, []).append(self.queue.getPath(msg))
            if len(exchanges) >= (self.maxConnections - len(self.managed)):
                break

        if self.mxcalc is None:
            self.mxcalc = MXCalculator()

        relays = []
        for (domain, msgs) in exchanges.iteritems():
            manager = _AttemptManager(self)
            factory = self.factory(msgs, manager, *self.fArgs, **self.fKwArgs)
            self.managed[factory] = map(os.path.basename, msgs)
            relayAttemptDeferred = manager.getCompletionDeferred()
            connectSetupDeferred = self.mxcalc.getMX(domain)
            connectSetupDeferred.addCallback(lambda mx: str(mx.name))
            connectSetupDeferred.addCallback(self._cbExchange, self.PORT, factory)
            connectSetupDeferred.addErrback(lambda err: (relayAttemptDeferred.errback(err), err)[1])
            connectSetupDeferred.addErrback(self._ebExchange, factory, domain)
            relays.append(relayAttemptDeferred)
        return DeferredList(relays) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:37,代碼來源:relaymanager.py

示例3: quoteaddr

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import parseaddr [as 別名]
def quoteaddr(addr):
    """Turn an email address, possibly with realname part etc, into
    a form suitable for and SMTP envelope.
    """

    if isinstance(addr, Address):
        return '<%s>' % str(addr)

    res = rfc822.parseaddr(addr)

    if res == (None, None):
        # It didn't parse, use it as-is
        return '<%s>' % str(addr)
    else:
        return '<%s>' % str(res[1]) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:17,代碼來源:smtp.py

示例4: test_parseaddr

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import parseaddr [as 別名]
def test_parseaddr(self):
        eq = self.assertEqual
        eq(rfc822.parseaddr('<>'), ('', ''))
        eq(rfc822.parseaddr('aperson@dom.ain'), ('', 'aperson@dom.ain'))
        eq(rfc822.parseaddr('bperson@dom.ain (Bea A. Person)'),
           ('Bea A. Person', 'bperson@dom.ain'))
        eq(rfc822.parseaddr('Cynthia Person <cperson@dom.ain>'),
           ('Cynthia Person', 'cperson@dom.ain')) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:10,代碼來源:test_rfc822.py

示例5: _checkStateMX

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import parseaddr [as 別名]
def _checkStateMX(self):
        nextMessages = self.queue.getWaiting()
        nextMessages.reverse()
        
        exchanges = {}
        for msg in nextMessages:
            from_, to = self.queue.getEnvelope(msg)
            name, addr = rfc822.parseaddr(to)
            parts = addr.split('@', 1)
            if len(parts) != 2:
                log.err("Illegal message destination: " + to)
                continue
            domain = parts[1]
            
            self.queue.setRelaying(msg)
            exchanges.setdefault(domain, []).append(self.queue.getPath(msg))
            if len(exchanges) >= (self.maxConnections - len(self.managed)):
                break
        
        if self.mxcalc is None:
            self.mxcalc = MXCalculator()
        
        for (domain, msgs) in exchanges.iteritems():
            factory = self.factory(msgs, self, *self.fArgs, **self.fKwArgs)
            self.managed[factory] = map(os.path.basename, msgs)
            self.mxcalc.getMX(domain
            ).addCallback(lambda mx: str(mx.name),
            ).addCallback(self._cbExchange, self.PORT, factory
            ).addErrback(self._ebExchange, factory, domain
            ) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:32,代碼來源:relaymanager.py

示例6: _process_email_addr

# 需要導入模塊: import rfc822 [as 別名]
# 或者: from rfc822 import parseaddr [as 別名]
def _process_email_addr(self, email_addr):
        from_name, from_email = rfc822.parseaddr(email_addr)

        # Python sendgrid client should improve
        # sendgrid/helpers/mail/mail.py:164
        if not from_name:
            from_name = None

        return Email(from_email, from_name) 
開發者ID:elbuo8,項目名稱:sendgrid-django,代碼行數:11,代碼來源:mail.py


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