Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <?php
  2. //function to get unread emails taking username and password as parameters
  3. function check_email($username, $password)
  4. {
  5. //url to connect to
  6. $url = "https://mail.google.com/mail/feed/atom";
  7.  
  8. // sendRequest
  9. $curl = curl_init();
  10. curl_setopt($curl, CURLOPT_URL, $url);
  11. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  12. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  13. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  14. curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
  15. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  16. curl_setopt($curl, CURLOPT_ENCODING, "");
  17. $curlData = curl_exec($curl);
  18. curl_close($curl);
  19. //returning retrieved feed
  20. return $curlData;
  21.  
  22. }
  23.  
  24. //making page to behave like xml document to show feeds
  25. header('Content-Type:text/xml; charset=UTF-8');
  26. //calling function
  27. $feed = check_email("username", "password");
  28. echo $feed;
  29. ?>
  30.  
  31. <?xml version="1.0" encoding="UTF-8"?>
  32. <feed version="0.3" xmlns="http://purl.org/atom/ns#">
  33. <title>Gmail - Inbox for suneth2@gmail.com</title>
  34. <tagline>New messages in your Gmail Inbox</tagline>
  35. <fullcount>1282</fullcount>
  36. <link rel="alternate" href="http://mail.google.com/mail" type="text/html" />
  37. <modified>2012-08-01T12:33:48Z</modified>
  38. <entry>
  39. <title>eBCS Pro 1 August 2012</title>
  40. <summary>bcs logo eBCS Pro 1 August 2012 Video interview Olympic IT The Met Police&#39;s director of IT, Steve</summary>
  41. <link rel="alternate" href="http://mail.google.com/mail?account_id=suneth2@gmail.com&message_id=138e21a3404cc7b2&view=conv&extsrc=atom" type="text/html" />
  42. <modified>2012-08-01T12:12:44Z</modified>
  43. <issued>2012-08-01T12:12:44Z</issued>
  44. <id>tag:gmail.google.com,2004:1409100718455703474</id>
  45. <author>
  46. <name>eBCS Newsletter</name>
  47. <email>e-bulletin@lists.bcs.org.uk</email>
  48. </author>
  49. </entry>
  50. <entry>
  51.  
  52. <fullcount>1282</fullcount>
  53.  
  54. $xmlobjc = new SimpleXMLElement($feed);
  55.  
  56. echo $xmlobjc->fullcount[0];
  57.  
  58. header('Content-Type:text/html; charset=UTF-8');
  59.  
  60. curl -u $(cat username):$(cat password) --silent 'https://mail.google.com/mail/feed/atom' | sed -n 's:.*<fullcount>(.*)</fullcount>.*:1:p'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement