def test_body_line_iterator(self): eq = self.assertEqual # First a simple non-multipart message msg = self._msgobj('msg_01.txt') it = Iterators.body_line_iterator(msg) lines = list(it) eq(len(lines), 6) eq(EMPTYSTRING.join(lines), msg.get_payload()) # Now a more complicated multipart msg = self._msgobj('msg_02.txt') it = Iterators.body_line_iterator(msg) lines = list(it) eq(len(lines), 43) eq(EMPTYSTRING.join(lines), openfile('msg_19.txt').read())
def test_typed_subpart_iterator(self): eq = self.assertEqual msg = self._msgobj('msg_04.txt') it = Iterators.typed_subpart_iterator(msg, 'text') lines = [subpart.get_payload() for subpart in it] eq(len(lines), 2) eq(EMPTYSTRING.join(lines), """\ a simple kind of mirror to reflect upon our own a simple kind of mirror to reflect upon our own """)
def test_typed_subpart_iterator(self): eq = self.assertEqual msg = self._msgobj('msg_04.txt') it = Iterators.typed_subpart_iterator(msg, 'text') lines = [subpart.get_payload() for subpart in it] eq(len(lines), 2) eq( EMPTYSTRING.join(lines), """\ a simple kind of mirror to reflect upon our own a simple kind of mirror to reflect upon our own """)
def test_typed_subpart_iterator_default_type(self): eq = self.assertEqual msg = self._msgobj('msg_03.txt') it = Iterators.typed_subpart_iterator(msg, 'text', 'plain') lines = [] subparts = 0 for subpart in it: subparts += 1 lines.append(subpart.get_payload()) eq(subparts, 1) eq(EMPTYSTRING.join(lines), """\ Hi, Do you like this message? -Me """)
def process(msg): if msg.get('from', '').lower() <> '*****@*****.**': print 'out 1' return [] if not msg.is_multipart(): print 'out 2' return [] # The interesting bits are in the first text/plain multipart part = None try: part = msg.get_payload(0) except IndexError: pass if not part: print 'out 3' return [] addrs = {} for line in Iterators.body_line_iterator(part): mo = acre.match(line) if mo: addrs[mo.group('addr')] = 1 return addrs.keys()
# Copyright (C) 2001 Python Software Foundation