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


Python Utils.getaddresses方法代碼示例

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


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

示例1: addr_header_encode

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import getaddresses [as 別名]
def addr_header_encode(text, header_name=None):
    """Encode and line-wrap the value of an email header field containing
    email addresses."""

    # Convert to unicode, if required.
    if not isinstance(text, unicode):
        text = unicode(text, "utf-8")

    text = ", ".join(
        formataddr((header_encode(name), emailaddr))
        for name, emailaddr in getaddresses([text])
    )

    if is_ascii(text):
        charset = "ascii"
    else:
        charset = "utf-8"

    return Header(
        text, header_name=header_name, charset=Charset(charset)
    ).encode() 
開發者ID:Pagure,項目名稱:pagure,代碼行數:23,代碼來源:git_multimail_upstream.py

示例2: forbid_multi_line_headers

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import getaddresses [as 別名]
def forbid_multi_line_headers(name, val, encoding):
    """Forbids multi-line headers, to prevent header injection."""
    encoding = encoding or settings.DEFAULT_CHARSET
    val = force_unicode(val)
    if '\n' in val or '\r' in val:
        raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name))
    try:
        val = val.encode('ascii')
    except UnicodeEncodeError:
        if name.lower() in ADDRESS_HEADERS:
            val = ', '.join(sanitize_address(addr, encoding)
                for addr in getaddresses((val,)))
        else:
            val = str(Header(val, encoding))
    else:
        if name.lower() == 'subject':
            val = Header(val)
    return name, val 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:20,代碼來源:message.py

示例3: set_recipients

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import getaddresses [as 別名]
def set_recipients(self, name, value):
        self.unset_all(name)
        for pair in getaddresses([value]):
            self.add(name, formataddr(pair)) 
開發者ID:Pagure,項目名稱:pagure,代碼行數:6,代碼來源:git_multimail_upstream.py

示例4: send

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import getaddresses [as 別名]
def send(self, lines, to_addrs):
        try:
            if self.username or self.password:
                self.smtp.login(self.username, self.password)
            msg = "".join(lines)
            # turn comma-separated list into Python list if needed.
            if is_string(to_addrs):
                to_addrs = [
                    email for (name, email) in getaddresses([to_addrs])
                ]
            self.smtp.sendmail(self.envelopesender, to_addrs, msg)
        except smtplib.SMTPResponseException:
            err = sys.exc_info()[1]
            self.environment.get_logger().error(
                "*** Error sending email ***\n"
                "*** Error %d: %s\n"
                % (err.smtp_code, bytes_to_str(err.smtp_error))
            )
            try:
                smtp = self.smtp
                # delete the field before quit() so that in case of
                # error, self.smtp is deleted anyway.
                del self.smtp
                smtp.quit()
            except:
                self.environment.get_logger().error(
                    "*** Error closing the SMTP connection ***\n"
                    "*** Exiting anyway ... ***\n"
                    "*** %s\n" % sys.exc_info()[1]
                )
            sys.exit(1) 
開發者ID:Pagure,項目名稱:pagure,代碼行數:33,代碼來源:git_multimail_upstream.py

示例5: test_getaddresses

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import getaddresses [as 別名]
def test_getaddresses(self):
        eq = self.assertEqual
        eq(Utils.getaddresses(['aperson@dom.ain (Al Person)',
                               'Bud Person <bperson@dom.ain>']),
           [('Al Person', 'aperson@dom.ain'),
            ('Bud Person', 'bperson@dom.ain')]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_email.py

示例6: test_getaddresses_nasty

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import getaddresses [as 別名]
def test_getaddresses_nasty(self):
        eq = self.assertEqual
        eq(Utils.getaddresses(['foo: ;']), [('', '')])
        eq(Utils.getaddresses(
           ['[]*-- =~$']),
           [('', ''), ('', ''), ('', '*--')])
        eq(Utils.getaddresses(
           ['foo: ;', '"Jason R. Mastaler" <jason@dom.ain>']),
           [('', ''), ('Jason R. Mastaler', 'jason@dom.ain')]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_email.py

示例7: test_getaddresses_embedded_comment

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import getaddresses [as 別名]
def test_getaddresses_embedded_comment(self):
        """Test proper handling of a nested comment"""
        eq = self.assertEqual
        addrs = Utils.getaddresses(['User ((nested comment)) <foo@bar.com>'])
        eq(addrs[0][1], 'foo@bar.com') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_email.py


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