Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. function fetch_gmail_inbox()
  2. {
  3.  
  4. $res=array();
  5. /* connect to gmail */
  6. $hostname = '{imap.enlighten-energy.net:143/imap}';
  7. $username = 'abc@enlighten-energy.net';
  8. $password = '*******';
  9.  
  10. /* try to connect */
  11. $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
  12.  
  13. /* grab emails */
  14. $emails = imap_search($inbox,'UNSEEN');
  15.  
  16. /* if emails are returned, cycle through each... */
  17. if($emails) {
  18.  
  19. /* put the newest emails on top */
  20. rsort($emails);
  21.  
  22. /* for every email... */
  23. foreach($emails as $email_number) {
  24.  
  25. /* get information specific to this email */
  26. $overview = imap_fetch_overview($inbox,$email_number,0);
  27. $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1));
  28. $structure = imap_fetchstructure($inbox,$email_number);
  29. if($structure->parts[0]->encoding == 3 ||$structure->encoding == 3 )
  30. {
  31. $message=imap_base64($message);
  32.  
  33. }
  34. if($structure->parts[0]->encoding == 4 ||$structure->encoding == 4)
  35. {
  36. $message = imap_qprint($message);
  37. }
  38. $message2= quoted_printable_decode(imap_fetchbody($inbox,$email_number,0));
  39. $date=explode(':',$message2);
  40. $date2= date('d-m-Y h:i:s',strtotime($date[8].':00:00'));
  41.  
  42.  
  43. if($overview[0]->subject=="USR:Site01_Comms Complete")
  44. {
  45. $res['date']=$date2;
  46. $res['body']=$message;
  47. }else
  48. {
  49. echo "not a correct mail";
  50. }
  51. }
  52.  
  53. return $res;
  54. }
  55.  
  56. /* close the connection */
  57. imap_close($inbox);
  58.  
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement