Guest User

Untitled

a guest
Aug 31st, 2018
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. IMAP search for email address in the from field
  2. print('search with name')
  3. status, results = con.search(None, '(FROM "Shrikant Sharat")')
  4. if status == 'OK':
  5. if results[0]:
  6. mid = results[0].split()[0]
  7. print('mail id', mid)
  8. print(con.fetch(mid, '(UID BODY[HEADER.FIELDS (FROM)])'))
  9. else:
  10. print('No results yielded')
  11. else:
  12. print('unable to search', results)
  13.  
  14. print()
  15. print('search with email')
  16. status, results = con.search(None, '(FROM "shrikantsharat.k@gmail.com")')
  17. if status == 'OK':
  18. if results[0]:
  19. mid = results[0].split()[0]
  20. print('mail id', mid)
  21. print(con.fetch(mid, '(UID BODY[HEADER.FIELDS (FROM)])'))
  22. else:
  23. print('No results yielded')
  24. else:
  25. print('unable to search', results)
  26.  
  27. search with name
  28. mail id 2155
  29. ('OK', [('2155 (UID 5340 BODY[HEADER.FIELDS (FROM)] {54}', 'From: Shrikant Sharat <shrikantsharat.k@gmail.com>rnrn'), ' FLAGS (\Seen))'])
  30.  
  31. search with email
  32. No results yielded
  33.  
  34. (HEADER FROM "shrikantsharat.k@gmail.com")
Add Comment
Please, Sign In to add comment