当前位置: 首页>>代码示例>>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;未经允许,请勿转载。