public function connect() { if (empty($this->_connectionString)) { $this->_connectionType = $this->_config['type']; switch ($this->_config['type']) { case 'imap': $this->_connectionString = sprintf('{%s:%s%s%s}%s', $this->_config['server'], $this->_config['port'], '/' . $this->_config['type'], @$this->_config['ssl'] ? '/ssl' : '', !empty($this->_config['mailbox']) ? $this->_config['mailbox'] : ''); break; case 'pop3': $this->_connectionString = sprintf('{%s:%s/pop3%s}%s', $this->_config['server'], $this->_config['port'], @$this->_config['ssl'] ? '/ssl' : '', !empty($this->_config['mailbox']) ? $this->_config['mailbox'] : ''); break; } } try { $this->thread = null; $retries = 0; while ($retries++ < $this->_config['retry'] && !$this->thread) { $this->Stream = imap_open($this->_connectionString, $this->_config['username'], $this->_config['password']); $this->thread = @imap_thread($this->Stream); } if (!$this->thread) { throw new \Exception('Unable to get imap_thread'); } if (!$this->Stream) { throw new \Exception('Connection error: ' . imap_last_error()); } } catch (Exception $e) { debug($e->getMessage); } return $this->_isConnected = true; }
/** * connect to the mail server */ public function connect($Model, $query) { if ($this->_isConnected) { return true; } $this->_connectionType = $this->config['type']; switch ($this->config['type']) { case 'imap': $this->_connectionString = sprintf('{%s:%s%s%s}', $this->config['server'], $this->config['port'], @$this->config['ssl'] ? '/ssl' : '', @$this->config['connect'] ? '/' . @$this->config['connect'] : ''); break; case 'pop3': $this->_connectionString = sprintf('{%s:%s/pop3%s%s}', $this->config['server'], $this->config['port'], @$this->config['ssl'] ? '/ssl' : '', @$this->config['connect'] ? '/' . @$this->config['connect'] : ''); break; } try { $this->thread = null; $retries = 0; while ($retries++ < $this->config['retry'] && !$this->thread) { $this->Stream = imap_open($this->_connectionString, $this->config['username'], $this->config['password']); $this->thread = @imap_thread($this->Stream); } if (!$this->thread) { return $this->err($Model, 'Unable to get imap_thread after %s retries. %s', $retries, imap_last_error()); } } catch (Exception $Exception) { return $this->err($Model, 'Unable to get imap_thread after %s retries. %s', $retries, $Exception->getMessage() . ' ' . imap_last_error()); } return $this->_isConnected = true; }
/** * connect to the mail server */ public function connect($Model, $query) { if ($this->_isConnected) { return true; } $this->_connectionType = $this->config['type']; /** * checking whether mailbox key found in conditions or not. * If found, add the mailbox in the $this->_connectionString */ if (isset($query['conditions']['mailbox'])) { $mailbox = $query['conditions']['mailbox']; } else { $mailbox = null; } switch ($this->config['type']) { case 'imap': $this->_connectionString = sprintf('{%s:%s%s%s}%s', $this->config['server'], $this->config['port'], @$this->config['ssl'] ? '/ssl' : '', @$this->config['connect'] ? '/' . @$this->config['connect'] : '', $mailbox); break; case 'pop3': $this->_connectionString = sprintf('{%s:%s/pop3%s%s}%s', $this->config['server'], $this->config['port'], @$this->config['ssl'] ? '/ssl' : '', @$this->config['connect'] ? '/' . @$this->config['connect'] : '', $mailbox); break; } try { $this->thread = null; $retries = 0; while ($retries++ < $this->config['retry'] && !$this->thread) { $this->Stream = imap_open($this->_connectionString, $this->config['username'], $this->config['password']); $this->thread = @imap_thread($this->Stream); } if (!$this->thread) { return $this->err($Model, 'Unable to get imap_thread after %s retries. %s', $retries, imap_last_error()); } } catch (Exception $Exception) { return $this->err($Model, 'Unable to get imap_thread after %s retries. %s', $retries, $Exception->getMessage() . ' ' . imap_last_error()); } return $this->_isConnected = true; }
function getTotalMails() { if (!$this->marubox) { return false; } $headers = imap_thread($this->marubox); foreach ($headers as $key => $val) { $tree = explode('.', $key); if ($tree[1] == 'num') { $return[] = $val; } } return $return; }
/** * connect to the mail server */ private function __connectToServer($Model, $query) { if ($this->__isConnected) { return true; } if (!isset($query['conditions'][$Model->alias . '.account'])) { return false; } if (empty($Model->server)) { $Model->server = ClassRegistry::init('Emails.EmailAccount')->getConnectionDetails($query['conditions'][$Model->alias . '.account']); if (empty($Model->server)) { return false; } } $Model->server['type'] = isset($Model->server['type']) && !empty($Model->server['type']) ? $Model->server['type'] : 'pop3'; if ($Model->server['type'] == 'default' || !in_array($Model->server['type'], array_keys($this->__baseConfigs))) { // throw error bad config. } $config = array_merge($this->__baseConfigs['global'], $this->__baseConfigs[$Model->server['type']], $Model->server); $config['email'] = !empty($config['email']) ? $config['email'] : $config['username']; $this->__connectionType = $config['type']; $config['ssl'] = $config['ssl'] ? '/ssl' : ''; switch ($config['type']) { case 'imap': $this->__connectionString = sprintf('{%s:%s%s}', $config['server'], $config['port'], $config['ssl']); break; case 'pop3': $this->__connectionString = sprintf('{%s:%s/pop3%s}', $config['server'], $config['port'], $config['ssl']); break; } try { $this->MailServer = imap_open($this->__connectionString, $config['username'], $config['password']); $this->thread = imap_thread($this->MailServer, SE_UID); } catch (Exception $error) { pr(imap_last_error()); pr($error); exit; } return $this->__isConnected = true; }
public function thread() { return imap_thread($this->imapStream, SE_UID); }
function debug_info($client, $id) { $data['header'] = imap_fetchheader($client, $id, FT_UID); $data['body'] = imap_fetchbody($client, $id, '', FT_UID); $data['structure'] = imap_fetchstructure($client, $id, FT_UID); $data['folders'] = imap_getmailboxes($client, '{imap.gmail.com:993/imap/ssl/novalidate-cert}', '*'); $data['threads'] = imap_thread($client, SE_UID); return $data; }