def scrapeContacts(self):
if (not self.srv):
return
self.getUIDs()
if (not self.uids):
return None
contacts = []
for uid in self.uids:
resp, data = self.srv.fetch(uid, "(RFC822)")
for response_part in data:
if isinstance(response_part, tuple):
msg = email.message_from_string(response_part[1])
fromaddr = msg['from']
if (fromaddr):
sender = msg['from'].split()[-1]
address = re.sub(r'[<>]','',sender)
# Ignore any occurences of own email address and add to list
if not re.search(r'' + re.escape(self.user),address) and not address in contacts:
contacts.append(address)
print "IDENTIFED new contact [%s]" % (address)
return contacts
评论列表
文章目录