Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. function email_check() {
  4.    
  5.     global $db, $mailConfig;
  6.    
  7.     require_once MODELS_PATH . "Options.php";
  8.     require_once MODELS_PATH . "Cache.php";
  9.    
  10.     $authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}";
  11.     $return = imap_open($authhost, $mailConfig['user'], $mailConfig['pass']);
  12.    
  13.     if(cache_expired(option('lastEmailRefresh'), $expires_time = 3600)) {
  14.                
  15.         $hostname = '{imap.googlemail.com:993/imap/ssl/novalidate-cert}INBOX';
  16.         $username = $mailConfig['user'];
  17.         $password = $mailConfig['pass'];
  18.        
  19.         $inbox = imap_open($hostname,$username,$password);
  20.        
  21.         if($inbox === false) {
  22.             return false;
  23.         }
  24.        
  25.         $emails = imap_search($inbox,'UNSEEN');
  26.        
  27.         $emailCount = is_bool($emails) ? 0 : count($emails);
  28.        
  29.         option('lastEmailCount', $emailCount);
  30.         option('lastEmailRefresh', $db->get_var("SELECT NOW()"));
  31.        
  32.         return $emailCount;
  33.        
  34.     } else {
  35.        
  36.         return option('lastEmailCount');
  37.        
  38.     }
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement