/** * select given folder * * folder must be selectable! * * @param Zend_Mail_Storage_Folder|string $globalName global name of folder or instance for subfolder * @return null * @throws Zend_Mail_Storage_Exception * @throws Zend_Mail_Protocol_Exception */ public function selectFolder($globalName) { $this->_currentFolder = $globalName; if (!$this->_protocol->select($this->_currentFolder)) { $this->_currentFolder = ''; throw new Zend_Mail_Storage_Exception('cannot change folder, maybe it does not exist'); } }
public function index() { $this->id = "content"; $this->template = "import/list.tpl"; $this->layout = "common/layout"; require_once 'Zend/Mail/Protocol/Imap.php'; require_once 'Zend/Mail/Protocol/Pop3.php'; $request = Registry::get('request'); $db = Registry::get('db'); $lang = Registry::get('language'); if ($this->request->post['type'] == 'pop3') { try { $conn = new Zend_Mail_Protocol_Pop3($this->request->post['server'], '110', false); } catch (Zend_Mail_Protocol_Exception $e) { print "<span class=\"text-error\">" . $this->request->post['server'] . ": " . $lang->data['text_connection_failed'] . "</span> "; } if ($conn) { $s = $conn->connect($this->request->post['server']); if ($s) { try { $conn->login($this->request->post['username'], $this->request->post['password']); print "<span class=\"text-success\">" . $lang->data['text_connection_ok'] . "</span> "; } catch (Zend_Mail_Protocol_Exception $e) { print "<span class=\"text-error\">" . $this->request->post['username'] . ": " . $lang->data['text_login_failed'] . "</span> "; } } } } else { if ($this->request->post['type'] == 'imap') { try { $conn = new Zend_Mail_Protocol_Imap($this->request->post['server'], '143', false); $login = $conn->login($this->request->post['username'], $this->request->post['password']); if ($login) { print "<span class=\"text-success\">" . $lang->data['text_connection_ok'] . "</span> "; } else { print "<span class=\"text-error\">" . $this->request->post['username'] . ": " . $lang->data['text_login_failed'] . "</span> "; } } catch (Zend_Mail_Protocol_Exception $e) { print "<span class=\"text-error\">" . $this->request->post['server'] . ": " . $lang->data['text_connection_failed'] . "</span> "; } } else { print "<span class=\"text-error\">" . $lang->data['text_error'] . "</span> "; } } }
/** * set flags for message * * NOTE: this method can't set the recent flag. * * @param int $id number of message * @param array $flags new flags for message * @throws Zend_Mail_Storage_Exception */ public function setFlags($id, $flags) { if (!$this->_protocol->store($flags, $id)) { /** * @see Zend_Mail_Storage_Exception */ throw new Zend_Mail_Storage_Exception('cannot set flags, have you tried to set the recent flag or special chars?'); } }
/** * set flags for message * * NOTE: this method can't set the recent flag. * * @param int $id number of message * @param array $flags new flags for message * @throws Zend_Mail_Storage_Exception */ public function setFlags($id, $flags) { if (!$this->_protocol->store($flags, $id)) { /** * @see Zend_Mail_Storage_Exception */ require_once 'include/Zend/Mail/Storage/Exception.php'; throw new Zend_Mail_Storage_Exception('cannot set flags, have you tried to set the recent flag or special chars?'); } }
/** * get imap connection * * @return Zend_Mail_Protocol_Imap * @throws Tinebase_Exception_AccessDenied */ protected function _getImapConnection() { if (!$this->_imap instanceof Zend_Mail_Protocol_Imap) { $this->_imap = new Zend_Mail_Protocol_Imap($this->_config['host'], $this->_config['port'], $this->_config['ssl']); $loginResult = $this->_imap->login($this->_config['admin'], $this->_config['password']); if (!$loginResult) { throw new Tinebase_Exception_AccessDenied('Could not login to cyrus server ' . $this->_config['host'] . ' with user ' . $this->_config['admin']); } } return $this->_imap; }
public function testStore() { $protocol = new Zend_Mail_Protocol_Imap($this->_params['host']); $protocol->login($this->_params['user'], $this->_params['password']); $protocol->select('INBOX'); $this->assertTrue($protocol->store(array('\\Flagged'), 1)); $this->assertTrue($protocol->store(array('\\Flagged'), 1, null, '-')); $this->assertTrue($protocol->store(array('\\Flagged'), 1, null, '+')); $result = $protocol->store(array('\\Flagged'), 1, null, '', false); $this->assertTrue(in_array('\\Flagged', $result[1])); $result = $protocol->store(array('\\Flagged'), 1, null, '-', false); $this->assertFalse(in_array('\\Flagged', $result[1])); $result = $protocol->store(array('\\Flagged'), 1, null, '+', false); $this->assertTrue(in_array('\\Flagged', $result[1])); }
/** * 检查未读邮件 */ public function checkAction() { //$address = $this->_request->getQuery('address'); $emails = $this->_daoEmail->getEmails(array('orgid' => $this->_user->orgId, 'userid' => $this->_user->userId)); $result = array(); foreach ($emails as $email) { if (null != $email && $email->protocol == 'imap' && $email->host) { $port = $email->port ? $email->port : ($email->isSsl ? 993 : 143); $imap = new Zend_Mail_Protocol_Imap(); try { $connect = $imap->connect($email->host, $port, $email->isSsl); } catch (Zend_Mail_Protocol_Exception $e) { continue; } $login = $imap->login($email->address, $email->password); // 登录邮箱 if (!$login) { $result[$email->address] = array('msg' => sprintf($this->lang['mailbox_login_failure'], $email->address, $email->address)); continue; } // 打开INBOX $ret = $imap->examineOrSelect(); if (false !== $ret && isset($ret['recent'])) { $email->unreadNum = (int) $ret['recent']; // 查找新邮件 /*$records = $imap->search('RECENT'); if (false !== $records) { }*/ $result[$email->address] = array('recent' => $email->unreadNum); $this->_daoEmail->updateEmail($email->orgId, $email->userId, $email->address, array('lastcheckinfo' => implode("\n", array($email->unreadNum, $email->lastMailId, $email->lastMailSubject, $email->lastMailFrom)), 'lastchecktime' => time())); } $imap->logout(); } } $this->json(true, null, $result); }
$oauthParams .= ','; } $oauthParams .= $key . '="' . urlencode($value) . '"'; $first = false; } } /** * Generate SASL client request, using base64 encoded * OAuth params */ $initClientRequest = 'GET ' . $urlWithXoauth . ' ' . $oauthParams; $initClientRequestEncoded = base64_encode($initClientRequest); /** * Make the IMAP connection and send the auth request */ $imap = new Zend_Mail_Protocol_Imap('imap.gmail.com', '993', true); $authenticateParams = array('XOAUTH', $initClientRequestEncoded); $imap->requestAndResponse('AUTHENTICATE', $authenticateParams); /** * Print the INBOX message count and the subject of all messages * in the INBOX */ $storage = new Zend_Mail_Storage_Imap($imap); include 'header.php'; echo '<h1>Total messages: ' . $storage->countMessages() . ' for ' . $TWO_LEGGED_EMAIL_ADDRESS . "</h1>\n"; /** * Retrieve first 5 messages. If retrieving more, you'll want * to directly use Zend_Mail_Protocol_Imap and do a batch retrieval, * plus retrieve only the headers */ echo 'First five messages: <ul>';
public function testWithInstanceConstruction() { $protocol = new Zend_Mail_Protocol_Imap($this->_params['host']); $protocol->login($this->_params['user'], $this->_params['password']); // if $protocol is invalid the constructor fails while selecting INBOX $mail = new Zend_Mail_Storage_Imap($protocol); }
private function checkLoginAgainstIMAP($username = '', $password = '') { $session = Registry::get('session'); $emails = array($username); if (!strchr($username, '@')) { return 0; } $imap = new Zend_Mail_Protocol_Imap(IMAP_HOST, IMAP_PORT, IMAP_SSL); if ($imap->login($username, $password)) { $imap->logout(); $extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails); $emails = array_merge($emails, $extra_emails); $this->add_session_vars($username, $username, $emails, 0); $session->set("password", $password); return 1; } return 0; }
/** * Set an IMAP connection * * @param Zend_Mail_Protocol_Imap $imao An existing IMAP object * @return Zend_Auth_Adapter_Imap Provides a fluent interface */ public function setImap(Zend_Mail_Protocol_Imap $imap) { $this->_imap = $imap; //@todo check imap->getOptions() $this->setOptions(array($imap->getOptions())); return $this; }
/** * return the status message id * @param array $flag * */ public function getStatusMessage($flag) { return $this->_protocol->search($flag); }