pythonmessage用法_Python Message.Message方法代碼示例

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

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

示例1: test_getset_charset

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_getset_charset(self):

eq = self.assertEqual

msg = Message()

eq(msg.get_charset(), None)

charset = Charset('iso-8859-1')

msg.set_charset(charset)

eq(msg['mime-version'], '1.0')

eq(msg.get_content_type(), 'text/plain')

eq(msg['content-type'], 'text/plain; charset="iso-8859-1"')

eq(msg.get_param('charset'), 'iso-8859-1')

eq(msg['content-transfer-encoding'], 'quoted-printable')

eq(msg.get_charset().input_charset, 'iso-8859-1')

# Remove the charset

msg.set_charset(None)

eq(msg.get_charset(), None)

eq(msg['content-type'], 'text/plain')

# Try adding a charset when there's already MIME headers present

msg = Message()

msg['MIME-Version'] = '2.0'

msg['Content-Type'] = 'text/x-weird'

msg['Content-Transfer-Encoding'] = 'quinted-puntable'

msg.set_charset(charset)

eq(msg['mime-version'], '2.0')

eq(msg['content-type'], 'text/x-weird; charset="iso-8859-1"')

eq(msg['content-transfer-encoding'], 'quinted-puntable')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,

示例2: test_set_param

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_set_param(self):

eq = self.assertEqual

msg = Message()

msg.set_param('charset', 'iso-2022-jp')

eq(msg.get_param('charset'), 'iso-2022-jp')

msg.set_param('importance', 'high value')

eq(msg.get_param('importance'), 'high value')

eq(msg.get_param('importance', unquote=False), '"high value"')

eq(msg.get_params(), [('text/plain', ''),

('charset', 'iso-2022-jp'),

('importance', 'high value')])

eq(msg.get_params(unquote=False), [('text/plain', ''),

('charset', '"iso-2022-jp"'),

('importance', '"high value"')])

msg.set_param('charset', 'iso-9999-xx', header='X-Jimmy')

eq(msg.get_param('charset', header='X-Jimmy'), 'iso-9999-xx')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,

示例3: test_replace_header

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_replace_header(self):

eq = self.assertEqual

msg = Message()

msg.add_header('First', 'One')

msg.add_header('Second', 'Two')

msg.add_header('Third', 'Three')

eq(msg.keys(), ['First', 'Second', 'Third'])

eq(msg.values(), ['One', 'Two', 'Three'])

msg.replace_header('Second', 'Twenty')

eq(msg.keys(), ['First', 'Second', 'Third'])

eq(msg.values(), ['One', 'Twenty', 'Three'])

msg.add_header('First', 'Eleven')

msg.replace_header('First', 'One Hundred')

eq(msg.keys(), ['First', 'Second', 'Third', 'First'])

eq(msg.values(), ['One Hundred', 'Twenty', 'Three', 'Eleven'])

self.assertRaises(KeyError, msg.replace_header, 'Fourth', 'Missing')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,

示例4: test_long_lines_with_different_header

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_long_lines_with_different_header(self):

eq = self.ndiffAssertEqual

h = """\

List-Unsubscribe: ,

"""

msg = Message()

msg['List'] = h

msg['List'] = Header(h, header_name='List')

eq(msg.as_string(), """\

List: List-Unsubscribe: ,

List: List-Unsubscribe: ,

""")

# Test mangling of "From " lines in the body of a message

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,

示例5: test_invalid_content_type

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_invalid_content_type(self):

eq = self.assertEqual

neq = self.ndiffAssertEqual

msg = Message()

# RFC 2045, $5.2 says invalid yields text/plain

msg['Content-Type'] = 'text'

eq(msg.get_content_maintype(), 'text')

eq(msg.get_content_subtype(), 'plain')

eq(msg.get_content_type(), 'text/plain')

# Clear the old value and try something /really/ invalid

del msg['content-type']

msg['Content-Type'] = 'foo'

eq(msg.get_content_maintype(), 'text')

eq(msg.get_content_subtype(), 'plain')

eq(msg.get_content_type(), 'text/plain')

# Still, make sure that the message is idempotently generated

s = StringIO()

g = Generator(s)

g.flatten(msg)

neq(s.getvalue(), 'Content-Type: foo\n\n')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,

示例6: test_generate

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_generate(self):

# First craft the message to be encapsulated

m = Message()

m['Subject'] = 'An enclosed message'

m.set_payload('Here is the body of the message.\n')

r = MIMEMessage(m)

r['Subject'] = 'The enclosing message'

s = StringIO()

g = Generator(s)

g.flatten(r)

self.assertEqual(s.getvalue(), """\

Content-Type: message/rfc822

MIME-Version: 1.0

Subject: The enclosing message

Subject: An enclosed message

Here is the body of the message.

""")

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,

示例7: test_epilogue

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_epilogue(self):

eq = self.ndiffAssertEqual

fp = openfile('msg_21.txt')

try:

text = fp.read()

finally:

fp.close()

msg = Message()

msg['From'] = '[email protected]'

msg['To'] = '[email protected]'

msg['Subject'] = 'Test'

msg.preamble = 'MIME message'

msg.epilogue = 'End of MIME message\n'

msg1 = MIMEText('One')

msg2 = MIMEText('Two')

msg.add_header('Content-Type', 'multipart/mixed', boundary='BOUNDARY')

msg.attach(msg1)

msg.attach(msg2)

sfp = StringIO()

g = Generator(sfp)

g.flatten(msg)

eq(sfp.getvalue(), text)

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,

示例8: test_parser

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_parser(self):

eq = self.assertEqual

msg, text = self._msgobj('msg_06.txt')

# Check some of the outer headers

eq(msg.get_content_type(), 'message/rfc822')

# Make sure the payload is a list of exactly one sub-Message, and that

# that submessage has a type of text/plain

payload = msg.get_payload()

self.assertIsInstance(payload, list)

eq(len(payload), 1)

msg1 = payload[0]

self.assertIsInstance(msg1, Message)

eq(msg1.get_content_type(), 'text/plain')

self.assertIsInstance(msg1.get_payload(), str)

eq(msg1.get_payload(), '\n')

# Test various other bits of the package's functionality

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,

示例9: test_message_from_string_with_class

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_message_from_string_with_class(self):

fp = openfile('msg_01.txt')

try:

text = fp.read()

finally:

fp.close()

# Create a subclass

class MyMessage(Message):

pass

msg = email.message_from_string(text, MyMessage)

self.assertIsInstance(msg, MyMessage)

# Try something more complicated

fp = openfile('msg_02.txt')

try:

text = fp.read()

finally:

fp.close()

msg = email.message_from_string(text, MyMessage)

for subpart in msg.walk():

self.assertIsInstance(subpart, MyMessage)

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:23,

示例10: test__all__

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [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',

])

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,

示例11: test_get_body_encoding_with_uppercase_charset

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_get_body_encoding_with_uppercase_charset(self):

eq = self.assertEqual

msg = Message()

msg['Content-Type'] = 'text/plain; charset=UTF-8'

eq(msg['content-type'], 'text/plain; charset=UTF-8')

charsets = msg.get_charsets()

eq(len(charsets), 1)

eq(charsets[0], 'utf-8')

charset = Charset(charsets[0])

eq(charset.get_body_encoding(), 'base64')

msg.set_payload('hello world', charset=charset)

eq(msg.get_payload(), 'aGVsbG8gd29ybGQ=\n')

eq(msg.get_payload(decode=True), 'hello world')

eq(msg['content-transfer-encoding'], 'base64')

# Try another one

msg = Message()

msg['Content-Type'] = 'text/plain; charset="US-ASCII"'

charsets = msg.get_charsets()

eq(len(charsets), 1)

eq(charsets[0], 'us-ascii')

charset = Charset(charsets[0])

eq(charset.get_body_encoding(), Encoders.encode_7or8bit)

msg.set_payload('hello world', charset=charset)

eq(msg.get_payload(), 'hello world')

eq(msg['content-transfer-encoding'], '7bit')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,

示例12: test_whitespace_continuation

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_whitespace_continuation(self):

eq = self.assertEqual

# This message contains a line after the Subject: header that has only

# whitespace, but it is not empty!

msg = email.message_from_string("""\

From: [email protected]

To: [email protected]

Subject: the next line has a space on it

\x20

Date: Mon, 8 Apr 2002 15:09:19 -0400

Message-ID: spam

Here's the message body

""")

eq(msg['subject'], 'the next line has a space on it\n ')

eq(msg['message-id'], 'spam')

eq(msg.get_payload(), "Here's the message body\n")

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,

示例13: test_whitespace_continuation_last_header

​點讚 6

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_whitespace_continuation_last_header(self):

eq = self.assertEqual

# Like the previous test, but the subject line is the last

# header.

msg = email.message_from_string("""\

From: [email protected]

To: [email protected]

Date: Mon, 8 Apr 2002 15:09:19 -0400

Message-ID: spam

Subject: the next line has a space on it

\x20

Here's the message body

""")

eq(msg['subject'], 'the next line has a space on it\n ')

eq(msg['message-id'], 'spam')

eq(msg.get_payload(), "Here's the message body\n")

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,

示例14: _msgobj

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def _msgobj(self, filename):

fp = openfile(findfile(filename))

try:

msg = email.message_from_file(fp)

finally:

fp.close()

return msg

# Test various aspects of the Message class's API

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,

示例15: test_set_charset_from_string

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_set_charset_from_string(self):

eq = self.assertEqual

msg = Message()

msg.set_charset('us-ascii')

eq(msg.get_charset().input_charset, 'us-ascii')

eq(msg['content-type'], 'text/plain; charset="us-ascii"')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,

示例16: test_set_payload_with_charset

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_set_payload_with_charset(self):

msg = Message()

charset = Charset('iso-8859-1')

msg.set_payload('This is a string payload', charset)

self.assertEqual(msg.get_charset().input_charset, 'iso-8859-1')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,

示例17: test_get_decoded_uu_payload

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_get_decoded_uu_payload(self):

eq = self.assertEqual

msg = Message()

msg.set_payload('begin 666 -\n+:&5L;&\\@=V]R;&0 \n \nend\n')

for cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):

msg['content-transfer-encoding'] = cte

eq(msg.get_payload(decode=True), 'hello world')

# Now try some bogus data

msg.set_payload('foo')

eq(msg.get_payload(decode=True), 'foo')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,

示例18: test__contains__

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test__contains__(self):

msg = Message()

msg['From'] = 'Me'

msg['to'] = 'You'

# Check for case insensitivity

self.assertIn('from', msg)

self.assertIn('From', msg)

self.assertIn('FROM', msg)

self.assertIn('to', msg)

self.assertIn('To', msg)

self.assertIn('TO', msg)

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,

示例19: test_get_param_liberal

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_get_param_liberal(self):

msg = Message()

msg['Content-Type'] = 'Content-Type: Multipart/mixed; boundary = "CPIMSSMTPC06p5f3tG"'

self.assertEqual(msg.get_param('boundary'), 'CPIMSSMTPC06p5f3tG')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,

示例20: test_del_param_on_other_header

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_del_param_on_other_header(self):

msg = Message()

msg.add_header('Content-Disposition', 'attachment', filename='bud.gif')

msg.del_param('filename', 'content-disposition')

self.assertEqual(msg['content-disposition'], 'attachment')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,

示例21: test_set_type

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_set_type(self):

eq = self.assertEqual

msg = Message()

self.assertRaises(ValueError, msg.set_type, 'text')

msg.set_type('text/plain')

eq(msg['content-type'], 'text/plain')

msg.set_param('charset', 'us-ascii')

eq(msg['content-type'], 'text/plain; charset="us-ascii"')

msg.set_type('text/html')

eq(msg['content-type'], 'text/html; charset="us-ascii"')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,

示例22: test_get_content_type_missing

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_get_content_type_missing(self):

msg = Message()

self.assertEqual(msg.get_content_type(), 'text/plain')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,

示例23: test_get_content_type_missing_with_default_type

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_get_content_type_missing_with_default_type(self):

msg = Message()

msg.set_default_type('message/rfc822')

self.assertEqual(msg.get_content_type(), 'message/rfc822')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,

示例24: test_get_content_maintype_missing

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_get_content_maintype_missing(self):

msg = Message()

self.assertEqual(msg.get_content_maintype(), 'text')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,

示例25: test_get_content_maintype_missing_with_default_type

​點讚 5

# 需要導入模塊: from email import Message [as 別名]

# 或者: from email.Message import Message [as 別名]

def test_get_content_maintype_missing_with_default_type(self):

msg = Message()

msg.set_default_type('message/rfc822')

self.assertEqual(msg.get_content_maintype(), 'message')

開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,

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

你可能感兴趣的:(pythonmessage用法)