Advertisement
Guest User

Untitled

a guest
Jan 18th, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. set_time_limit(4000);
  2. /* connect to gmail */
  3. $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  4. $username = 'sample@gmail.com';
  5. $password = '123';
  6.  
  7. /* try to connect */
  8. $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
  9.  
  10. /* grab emails */
  11. $emails = imap_search($inbox,'ALL');
  12.  
  13. /* if emails are returned, cycle through each... */
  14. if($emails) {
  15. $output = '';
  16. rsort($emails);
  17. foreach($emails as $email_number) {
  18. $overview = imap_fetch_overview($inbox,$email_number,0);
  19. /* if($overview[0]->from=='sample1@gmail.com')
  20. { */
  21. $structure = imap_fetchstructure($inbox, $email_number);
  22.  
  23. if(isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
  24. $part = $structure->parts[1];
  25. $message = imap_fetchbody($inbox,$email_number,2);
  26.  
  27. if($part->encoding == 3) {
  28. $message = imap_base64($message);
  29. } else if($part->encoding == 1) {
  30. $message = imap_8bit($message);
  31. } else {
  32. $message = imap_qprint($message);
  33. }
  34. }
  35.  
  36. $output.= '<div class="toggle'.($overview[0]->seen ? 'read' : 'unread').'">';
  37. $output.= '<span class="from">From: '.utf8_decode(imap_utf8($overview[0]->from)).'</span>';
  38. $output.= '<span class="date">on '.utf8_decode(imap_utf8($overview[0]->date)).'</span>';
  39. $output.= '<br /><span class="subject">Subject('.$part->encoding.'): '.utf8_decode(imap_utf8($overview[0]->subject)).'</span> ';
  40. $output.= '</div>';
  41. $output.= '<div class="body">'.$message.'</div><hr />';
  42. //}
  43. }
  44. echo $output;
  45. }
  46. imap_close($inbox);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement