Guest User

Untitled

a guest
Oct 10th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2.  
  3. $mailbox = '{imap.gmail.com:993/ssl/novalidate-cert}INBOX';
  4. $username = $_GET['username'];
  5. $password = $_GET['password'];
  6. $msg = $_GET['msg'];
  7.  
  8.  
  9. $mbox = imap_open($mailbox, $username, $password);
  10. $n = imap_num_msg($mbox);
  11.  
  12.  
  13. // define a variable for the data file
  14. $myFile = "gmailCount.txt";
  15.  
  16. //$imap_obj = imap_check($mbox);
  17. //var_dump($imap_obj);
  18.  
  19. //echo "<br><hr>";
  20. //echo $n;
  21. //echo " total messages.";
  22. //echo "<br><hr>";
  23. //$body = imap_body($mbox, $msg);
  24.  
  25. $unread = 0;
  26. for ($i = $n; $i >= $n-70; $i--) {
  27. $header = imap_headerinfo($mbox, $i);
  28. if ($header->Unseen == "U"){
  29. $unread ++;
  30. }
  31. }
  32. $fh = fopen($myFile, 'r') or die("can't open file");
  33. // read the last count from the data file
  34. $lastCount = fread($fh, filesize($myFile));
  35. //close
  36. fclose($fh);
  37. // check to see if new count is larger
  38. if($unread>$lastCount){
  39. echo '#';
  40. //and replace lastCount with new count
  41. $fh = fopen($myFile, 'w') or die("can't open file");
  42. fwrite($fh, $unread);
  43. fclose($fh);
  44. }
  45. // check to see if new count is the same… and tell the arduino !
  46. else if($unread == $lastCount){
  47. echo '!';
  48. }
  49. // if for some reason the count is less, reset the count in preparation of the next read
  50. else if($unread < $lastCount){
  51. echo '!';
  52. $fh = fopen($myFile, 'w') or die("can't open file");
  53. fwrite($fh, $unread);
  54. fclose($fh);
  55. }
  56.  
  57. ?>
Add Comment
Please, Sign In to add comment