Having created an object of the mailbox, now we can create a for loop to cull out the 'To' field of each email message.
for message in box:The mailbox relies on a cornucopia of other Python modules; best to see the source code for which ones. The second line of the above code uses the getaddr() method of the class rfc822.Message (from the module rfc822). This method returns a single line from an email header in the form of a tuple. Consequently, we must use subscript a '1' in order to assign only the email address, not the name of the addressee, to variable recip.
recip = message.getaddr('To')[1]
addresses.add(recip)
Finally, we use the built-in method of the addresses dictionary to add the value to our list.
