本文整理汇总了Python中email.Header.Header方法的典型用法代码示例。如果您正苦于以下问题:Python Header.Header方法的具体用法?Python Header.Header怎么用?Python Header.Header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.Header
的用法示例。
在下文中一共展示了Header.Header方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addr_header_encode
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [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()
示例2: sendfailmail
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def sendfailmail():
try:
SUBJECT = 'QQ点赞机下线提醒'
TO = [sendtomail]
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(SUBJECT, 'utf-8')
msg['From'] = mailsig+'<'+mailuser+'>'
msg['To'] = ', '.join(TO)
part = MIMEText("Fatal error occured. Please go to the website and login again!", 'plain', 'utf-8')
msg.attach(part)
server = smtplib.SMTP(mailserver, 25)
server.login(mailuser, mailpass)
server.login(mailuser, mailpass)
server.sendmail(mailuser, TO, msg.as_string())
server.quit()
return True
except Exception , e:
logging.error("发送程序错误邮件失败:"+str(e))
return False
示例3: sendfailmail
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def sendfailmail():
global QQUserName, MyUIN
try:
SUBJECT = 'QQ挂机下线提醒: '+str(QQUserName)+'[QQ号:'+str(MyUIN)+']'
TO = [sendtomail]
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(SUBJECT, 'utf-8')
msg['From'] = mailsig+'<'+mailuser+'>'
msg['To'] = ', '.join(TO)
part = MIMEText("Fatal error occured. Please restart the program and login again!", 'plain', 'utf-8')
msg.attach(part)
server = smtplib.SMTP(mailserver, 25)
server.login(mailuser, mailpass)
server.login(mailuser, mailpass)
server.sendmail(mailuser, TO, msg.as_string())
server.quit()
return True
except Exception , e:
logging.error("发送程序错误邮件失败:"+str(e))
return False
示例4: smtpmail
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def smtpmail(self,subinfo):
try:
SUBJECT = '来自 '+subinfo+'的留言'
TO = [sendtomail]
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(SUBJECT, 'utf-8')
msg['From'] = mailsig+'<'+mailuser+'>'
msg['To'] = ', '.join(TO)
part = MIMEText(self.content, 'plain', 'utf-8')
msg.attach(part)
server = smtplib.SMTP(mailserver, 25)
server.login(mailuser, mailpass)
server.login(mailuser, mailpass)
server.sendmail(mailuser, TO, msg.as_string())
server.quit()
return True
except Exception, e:
logging.error("error sending msg:"+str(e))
return False
示例5: sendfailmail
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def sendfailmail():
try:
SUBJECT = 'QQ小黄鸡下线提醒'
TO = [sendtomail]
msg = MIMEMultipart('alternative')
msg['Subject'] = Header(SUBJECT, 'utf-8')
msg['From'] = mailsig+'<'+mailuser+'>'
msg['To'] = ', '.join(TO)
part = MIMEText("Fatal error occured. Please go to the website and login again!", 'plain', 'utf-8')
msg.attach(part)
server = smtplib.SMTP(mailserver, 25)
server.login(mailuser, mailpass)
server.login(mailuser, mailpass)
server.sendmail(mailuser, TO, msg.as_string())
server.quit()
return True
except Exception , e:
logging.error("发送程序错误邮件失败:"+str(e))
return False
示例6: receivedHeader
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def receivedHeader(self, helo, origin, recipients):
"""
Generate the 'Received:' header for a message.
:param helo: The argument to the HELO command and the client's IP
address.
:type helo: (str, str)
:param origin: The address the message is from.
:type origin: twisted.mail.smtp.Address
:param recipients: A list of the addresses for which this message is
bound.
:type: list of twisted.mail.smtp.User
@return: The full "Received" header string.
:type: str
"""
myHostname, clientIP = helo
headerValue = "by bitmask.local from %s with ESMTP ; %s" % (
clientIP, smtp.rfc822date())
# email.Header.Header used for automatic wrapping of long lines
return "Received: %s" % Header(s=headerValue, header_name='Received')
示例7: test_get_param
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def test_get_param(self):
eq = self.assertEqual
msg = email.message_from_string(
"X-Header: foo=one; bar=two; baz=three\n")
eq(msg.get_param('bar', header='x-header'), 'two')
eq(msg.get_param('quuz', header='x-header'), None)
eq(msg.get_param('quuz'), None)
msg = email.message_from_string(
'X-Header: foo; bar="one"; baz=two\n')
eq(msg.get_param('foo', header='x-header'), '')
eq(msg.get_param('bar', header='x-header'), 'one')
eq(msg.get_param('baz', header='x-header'), 'two')
# XXX: We are not RFC-2045 compliant! We cannot parse:
# msg["Content-Type"] = 'text/plain; weird="hey; dolly? [you] @ <\\"home\\">?"'
# msg.get_param("weird")
# yet.
示例8: test_splitting_multiple_long_lines
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def test_splitting_multiple_long_lines(self):
eq = self.ndiffAssertEqual
hstr = """\
from babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
\tfrom babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
\tfrom babylon.socal-raves.org (localhost [127.0.0.1]); by babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81; for <mailman-admin@babylon.socal-raves.org>; Sat, 2 Feb 2002 17:00:06 -0800 (PST)
"""
h = Header(hstr, continuation_ws='\t')
eq(h.encode(), """\
from babylon.socal-raves.org (localhost [127.0.0.1]);
\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
\tfor <mailman-admin@babylon.socal-raves.org>;
\tSat, 2 Feb 2002 17:00:06 -0800 (PST)
\tfrom babylon.socal-raves.org (localhost [127.0.0.1]);
\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
\tfor <mailman-admin@babylon.socal-raves.org>;
\tSat, 2 Feb 2002 17:00:06 -0800 (PST)
\tfrom babylon.socal-raves.org (localhost [127.0.0.1]);
\tby babylon.socal-raves.org (Postfix) with ESMTP id B570E51B81;
\tfor <mailman-admin@babylon.socal-raves.org>;
\tSat, 2 Feb 2002 17:00:06 -0800 (PST)""")
示例9: test_long_lines_with_different_header
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def test_long_lines_with_different_header(self):
eq = self.ndiffAssertEqual
h = """\
List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
<mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>"""
msg = Message()
msg['List'] = h
msg['List'] = Header(h, header_name='List')
eq(msg.as_string(), """\
List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
<mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
List: List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/spamassassin-talk>,
<mailto:spamassassin-talk-request@lists.sourceforge.net?subject=unsubscribe>
""")
# Test mangling of "From " lines in the body of a message
示例10: test__all__
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def test__all__(self):
module = __import__('email')
all = module.__all__
all.sort()
self.assertEqual(all, [
# Old names
'Charset', 'Encoders', 'Errors', 'Generator',
'Header', 'Iterators', 'MIMEAudio', 'MIMEBase',
'MIMEImage', 'MIMEMessage', 'MIMEMultipart',
'MIMENonMultipart', 'MIMEText', 'Message',
'Parser', 'Utils', 'base64MIME',
# new names
'base64mime', 'charset', 'encoders', 'errors', 'generator',
'header', 'iterators', 'message', 'message_from_file',
'message_from_string', 'mime', 'parser',
'quopriMIME', 'quoprimime', 'utils',
])
示例11: header_encode
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def header_encode(text, header_name=None):
"""Encode and line-wrap the value of an email header field."""
# Convert to unicode, if required.
if not isinstance(text, unicode):
text = unicode(text, "utf-8")
if is_ascii(text):
charset = "ascii"
else:
charset = "utf-8"
return Header(
text, header_name=header_name, charset=Charset(charset)
).encode()
示例12: test_get_params
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def test_get_params(self):
eq = self.assertEqual
msg = email.message_from_string(
'X-Header: foo=one; bar=two; baz=three\n')
eq(msg.get_params(header='x-header'),
[('foo', 'one'), ('bar', 'two'), ('baz', 'three')])
msg = email.message_from_string(
'X-Header: foo; bar=one; baz=two\n')
eq(msg.get_params(header='x-header'),
[('foo', ''), ('bar', 'one'), ('baz', 'two')])
eq(msg.get_params(), None)
msg = email.message_from_string(
'X-Header: foo; bar="one"; baz=two\n')
eq(msg.get_params(header='x-header'),
[('foo', ''), ('bar', 'one'), ('baz', 'two')])
示例13: test_has_key
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def test_has_key(self):
msg = email.message_from_string('Header: exists')
self.assertTrue(msg.has_key('header'))
self.assertTrue(msg.has_key('Header'))
self.assertTrue(msg.has_key('HEADER'))
self.assertFalse(msg.has_key('headeri'))
示例14: test_embedded_header_via_Header_rejected
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def test_embedded_header_via_Header_rejected(self):
msg = Message()
msg['Dummy'] = Header('dummy\nX-Injected-Header: test')
self.assertRaises(Errors.HeaderParseError, msg.as_string)
示例15: test_embedded_header_via_string_rejected
# 需要导入模块: from email import Header [as 别名]
# 或者: from email.Header import Header [as 别名]
def test_embedded_header_via_string_rejected(self):
msg = Message()
msg['Dummy'] = 'dummy\nX-Injected-Header: test'
self.assertRaises(Errors.HeaderParseError, msg.as_string)
# Test the email.Encoders module