本文整理匯總了Python中mailbox.BabylMessage方法的典型用法代碼示例。如果您正苦於以下問題:Python mailbox.BabylMessage方法的具體用法?Python mailbox.BabylMessage怎麽用?Python mailbox.BabylMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mailbox
的用法示例。
在下文中一共展示了mailbox.BabylMessage方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_labels
# 需要導入模塊: import mailbox [as 別名]
# 或者: from mailbox import BabylMessage [as 別名]
def test_labels(self):
# Get labels from the mailbox
self.assertEqual(self._box.get_labels(), [])
msg0 = mailbox.BabylMessage(self._template % 0)
msg0.add_label('foo')
key0 = self._box.add(msg0)
self.assertEqual(self._box.get_labels(), ['foo'])
msg1 = mailbox.BabylMessage(self._template % 1)
msg1.set_labels(['bar', 'answered', 'foo'])
key1 = self._box.add(msg1)
self.assertEqual(set(self._box.get_labels()), set(['foo', 'bar']))
msg0.set_labels(['blah', 'filed'])
self._box[key0] = msg0
self.assertEqual(set(self._box.get_labels()),
set(['foo', 'bar', 'blah']))
self._box.remove(key1)
self.assertEqual(set(self._box.get_labels()), set(['blah']))
示例2: test_visible
# 需要導入模塊: import mailbox [as 別名]
# 或者: from mailbox import BabylMessage [as 別名]
def test_visible(self):
# Get, set, and update visible headers
msg = mailbox.BabylMessage(_sample_message)
visible = msg.get_visible()
self.assertEqual(visible.keys(), [])
self.assertIsNone(visible.get_payload())
visible['User-Agent'] = 'FooBar 1.0'
visible['X-Whatever'] = 'Blah'
self.assertEqual(msg.get_visible().keys(), [])
msg.set_visible(visible)
visible = msg.get_visible()
self.assertEqual(visible.keys(), ['User-Agent', 'X-Whatever'])
self.assertEqual(visible['User-Agent'], 'FooBar 1.0')
self.assertEqual(visible['X-Whatever'], 'Blah')
self.assertIsNone(visible.get_payload())
msg.update_visible()
self.assertEqual(visible.keys(), ['User-Agent', 'X-Whatever'])
self.assertIsNone(visible.get_payload())
visible = msg.get_visible()
self.assertEqual(visible.keys(), ['User-Agent', 'Date', 'From', 'To',
'Subject'])
for header in ('User-Agent', 'Date', 'From', 'To', 'Subject'):
self.assertEqual(visible[header], msg[header])
示例3: test_babyl_to_maildir
# 需要導入模塊: import mailbox [as 別名]
# 或者: from mailbox import BabylMessage [as 別名]
def test_babyl_to_maildir(self):
# Convert BabylMessage to MaildirMessage
pairs = (('unseen', ''), ('deleted', 'ST'), ('filed', 'S'),
('answered', 'RS'), ('forwarded', 'PS'), ('edited', 'S'),
('resent', 'PS'))
for setting, result in pairs:
msg = mailbox.BabylMessage(_sample_message)
msg.add_label(setting)
self.assertEqual(mailbox.MaildirMessage(msg).get_flags(), result)
self.assertEqual(mailbox.MaildirMessage(msg).get_subdir(), 'cur')
msg = mailbox.BabylMessage(_sample_message)
for label in ('unseen', 'deleted', 'filed', 'answered', 'forwarded',
'edited', 'resent'):
msg.add_label(label)
self.assertEqual(mailbox.MaildirMessage(msg).get_flags(), 'PRT')
self.assertEqual(mailbox.MaildirMessage(msg).get_subdir(), 'cur')
示例4: test_visible
# 需要導入模塊: import mailbox [as 別名]
# 或者: from mailbox import BabylMessage [as 別名]
def test_visible(self):
# Get, set, and update visible headers
msg = mailbox.BabylMessage(_sample_message)
visible = msg.get_visible()
self.assertEqual(visible.keys(), [])
self.assertIs(visible.get_payload(), None)
visible['User-Agent'] = 'FooBar 1.0'
visible['X-Whatever'] = 'Blah'
self.assertEqual(msg.get_visible().keys(), [])
msg.set_visible(visible)
visible = msg.get_visible()
self.assertEqual(visible.keys(), ['User-Agent', 'X-Whatever'])
self.assertEqual(visible['User-Agent'], 'FooBar 1.0')
self.assertEqual(visible['X-Whatever'], 'Blah')
self.assertIs(visible.get_payload(), None)
msg.update_visible()
self.assertEqual(visible.keys(), ['User-Agent', 'X-Whatever'])
self.assertIs(visible.get_payload(), None)
visible = msg.get_visible()
self.assertEqual(visible.keys(), ['User-Agent', 'Date', 'From', 'To',
'Subject'])
for header in ('User-Agent', 'Date', 'From', 'To', 'Subject'):
self.assertEqual(visible[header], msg[header])
示例5: test_labels
# 需要導入模塊: import mailbox [as 別名]
# 或者: from mailbox import BabylMessage [as 別名]
def test_labels(self):
# Get labels from the mailbox
self.assertEqual(self._box.get_labels(), [])
msg0 = mailbox.BabylMessage(self._template % 0)
msg0.add_label('foo')
key0 = self._box.add(msg0)
self.assertEqual(self._box.get_labels(), ['foo'])
msg1 = mailbox.BabylMessage(self._template % 1)
msg1.set_labels(['bar', 'answered', 'foo'])
key1 = self._box.add(msg1)
self.assertEqual(set(self._box.get_labels()), set(['foo', 'bar']))
msg0.set_labels(['blah', 'filed'])
self._box[key0] = msg0
self.assertEqual(set(self._box.get_labels()),
set(['foo', 'bar', 'blah']))
self._box.remove(key1)
self.assertEqual(set(self._box.get_labels()), set(['blah']))
示例6: test_babyl_to_mboxmmdf
# 需要導入模塊: import mailbox [as 別名]
# 或者: from mailbox import BabylMessage [as 別名]
def test_babyl_to_mboxmmdf(self):
# Convert BabylMessage to mboxMessage and MMDFMessage
pairs = (('unseen', 'O'), ('deleted', 'ROD'), ('filed', 'RO'),
('answered', 'ROA'), ('forwarded', 'RO'), ('edited', 'RO'),
('resent', 'RO'))
for setting, result in pairs:
for class_ in (mailbox.mboxMessage, mailbox.MMDFMessage):
msg = mailbox.BabylMessage(_sample_message)
msg.add_label(setting)
self.assertEqual(class_(msg).get_flags(), result)
msg = mailbox.BabylMessage(_sample_message)
for label in ('unseen', 'deleted', 'filed', 'answered', 'forwarded',
'edited', 'resent'):
msg.add_label(label)
for class_ in (mailbox.mboxMessage, mailbox.MMDFMessage):
self.assertEqual(class_(msg).get_flags(), 'ODA')