Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a8d4d5

Browse files
committed
Message.getaddrlist(): Use the AddressList.addresslist attribute
instead of calling the getaddrlist() method, since the latter doesn't work with multiple calls (it will return the empty list for the second and subsequent calls). Closes SF bug #555035. Include a unittest.
1 parent 6cf09f0 commit 0a8d4d5

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lib/rfc822.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def getaddrlist(self, name):
352352
raw.append(addr)
353353
alladdrs = ''.join(raw)
354354
a = AddressList(alladdrs)
355-
return a.getaddrlist()
355+
return a.addresslist
356356

357357
def getdate(self, name):
358358
"""Retrieve a date field from a header.

Lib/test/test_rfc822.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,33 @@ def test_rfc2822_phrases(self):
185185
self.check('To: User J. Person <[email protected]>\n\n',
186186
[('User J. Person', '[email protected]')])
187187

188-
# This takes to long to add to the test suite
188+
# This takes too long to add to the test suite
189189
## def test_an_excrutiatingly_long_address_field(self):
190190
## OBSCENELY_LONG_HEADER_MULTIPLIER = 10000
191191
## oneaddr = ('Person' * 10) + '@' + ('.'.join(['dom']*10)) + '.com'
192192
## addr = ', '.join([oneaddr] * OBSCENELY_LONG_HEADER_MULTIPLIER)
193193
## lst = rfc822.AddrlistClass(addr).getaddrlist()
194194
## self.assertEqual(len(lst), OBSCENELY_LONG_HEADER_MULTIPLIER)
195195

196+
def test_2getaddrlist(self):
197+
eq = self.assertEqual
198+
msg = self.create_message("""\
199+
200+
201+
202+
203+
204+
A test message.
205+
""")
206+
ccs = [('', a) for a in
207+
208+
addrs = msg.getaddrlist('cc')
209+
addrs.sort()
210+
eq(addrs, ccs)
211+
# Try again, this one used to fail
212+
addrs = msg.getaddrlist('cc')
213+
addrs.sort()
214+
eq(addrs, ccs)
196215

197216
def test_main():
198217
test_support.run_unittest(MessageTestCase)

0 commit comments

Comments
 (0)