예제 #1
0
 private function _getDriver($driver)
 {
     if ($driver == self::PEAR) {
         /** PEAR-Net_IMAP is not E_STRICT */
         $this->old_error_reporting = error_reporting(E_ALL & ~E_STRICT);
     }
     if (!isset($this->sharedFixture->drivers[$driver])) {
         switch ($driver) {
             case self::MOCK:
                 $connection = new Horde_Kolab_Storage_Driver_Mock($this->group);
                 break;
             case self::CCLIENT:
                 $connection = new Horde_Kolab_Storage_Driver_Cclient($this->group);
                 break;
             case self::PEAR:
                 $client = new Net_IMAP($this->sharedFixture->conf['host'], 143, false);
                 $client->login($this->sharedFixture->conf['user'], $this->sharedFixture->conf['pass']);
                 $connection = new Horde_Kolab_Storage_Driver_Pear($client, $this->group);
                 break;
             case self::IMAP_SOCKET:
                 $params = array('hostspec' => $this->sharedFixture->conf['host'], 'username' => $this->sharedFixture->conf['user'], 'password' => $this->sharedFixture->conf['pass'], 'debug' => $this->sharedFixture->conf['debug'], 'port' => 143, 'secure' => false);
                 $client = Horde_Imap_Client::factory('socket', $params);
                 $client->login();
                 $connection = new Horde_Kolab_Storage_Driver_Imap($client, $this->group);
                 break;
             default:
                 exit("Undefined storage driver!\n");
         }
         $this->sharedFixture->drivers[$driver] = $connection;
     }
     return $this->sharedFixture->drivers[$driver];
 }
예제 #2
0
 function testIMAP()
 {
     $conn = new Net_IMAP(HOST, PORT);
     // we need to login for getting the delimiter
     $conn->login(USER, PASS);
     if (PEAR::isError($this->delimiter = $conn->getHierarchyDelimiter())) {
         $this->fail('Can not get hierarchy delimiter');
     }
     $conn->disconnect();
     $this->reservedFolders = array('INBOX', 'INBOX' . $this->delimiter . 'Trash');
 }
예제 #3
0
파일: Pear.php 프로젝트: raz0rsdge/horde
 /**
  * Create the backend driver.
  *
  * @return mixed The backend driver.
  */
 public function createBackend()
 {
     $config = $this->getParams();
     if (isset($config['secure']) && $config['secure'] == 'ssl') {
         $prefix = 'ssl://';
     } else {
         $prefix = '';
     }
     $client = new Net_IMAP($prefix . $config['host'], $config['port'], isset($config['secure']) && $config['secure'] == 'tls');
     $client->_useUTF_7 = false;
     if (isset($config['debug'])) {
         if ($config['debug'] == 'STDOUT') {
             $client->setDebug(true);
         } else {
             throw new Horde_Kolab_Storage_Exception('This driver does not support debug logging into a file.');
         }
     }
     Horde_Kolab_Storage_Exception_Pear::catchError($client->login($config['username'], $config['password'], true, false));
     return $client;
 }
예제 #4
0
 function authIMAP($login, $pwd, $imapServer, $port = 143)
 {
     // try first "new" imap wrapper
     if (class_exists('Net_IMAP') && $pwd) {
         $imap = new Net_IMAP($imapServer, $port);
         $loginOk = $imap->login($this->localAccount["name"], $pwd, true, false);
         if (PEAR::isError($loginOk)) {
             $loginOk = 0;
         }
         $this->dbg("authIMAP: Net_IMAP", $this->localAccount["name"], $loginOk ? 'OK' : 'FAIL');
         if ($loginOk) {
             return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
         }
         // backwords compatibility - old wrapper
     } else {
         if (function_exists('imap_open')) {
             if ($mbox = imap_open("{" . $imapServer . ":{$port}/novalidate-cert}", $this->localAccount["name"], $pwd, OP_READONLY)) {
                 imap_close($mbox);
                 $this->dbg("authIMAP: imap_open", $this->localAccount["name"], 'OK');
                 return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
             }
             $this->dbg("authIMAP: imap_open", $this->localAccount["name"], 'FAIL');
         } else {
             $this->dbg("authIMAP: imap is not installed");
         }
     }
 }
예제 #5
0
function open_imap(&$arr_mail_account, &$imap, $account_no)
{
    // account list array, from config.php
    global $arrAccountsImap;
    // $account_noの範囲チェック
    if ($account_no <= 0 || $account_no > count($arrAccountsImap)) {
        printf("<p>アカウント指定Noが範囲外です<br/>account=%d</p>\n", $account_no);
        return false;
    }
    // メールアカウント情報(サーバ名、ユーザ名、パスワード等)を得る
    $arr_mail_account = GetMailAccount($arrAccountsImap[$account_no - 1][1], 'imap');
    if (!isset($arr_mail_account['server']) || !isset($arr_mail_account['user']) || !isset($arr_mail_account['password']) || strcmp($arr_mail_account['protocol'], 'imap')) {
        print "<p>メールアカウント管理エラー(server/user/password値が得られないか、protocolがimapでない)</p>\n";
        return false;
    }
    // IMAPサーバに接続する
    if (!strcmp($arr_mail_account['port'], '993')) {
        // IMAP SSL
        $imap = new Net_IMAP('ssl://' . $arr_mail_account['server'], 993);
    } elseif (!strcmp($arr_mail_account['port'], '143')) {
        // IMAP with StartTLS
        $imap = new Net_IMAP($arr_mail_account['server'], 143, true);
    } else {
        printf("<p>このプログラムで利用可能なMAPサーバのポートは993(SSL)もしくは143のみです</p>\n<p>port=%s</p>\n", $arr_mail_account['port']);
        return false;
    }
    if (PEAR::isError($imap->login($arr_mail_account['user'], $arr_mail_account['password']))) {
        print "<p>IMAPサーバへの接続に失敗</p>\n";
        return false;
    }
    printf("<p>IMAPサーバに接続 (%s)</p>\n", htmlspecialchars($arr_mail_account['user']));
    return true;
}
 function deleteMailsFromServer(MailAccount $account)
 {
     $count = 0;
     if ($account->getDelFromServer() > 0) {
         $max_date = DateTimeValueLib::now();
         $max_date->add('d', -1 * $account->getDelFromServer());
         if ($account->getIsImap()) {
             if ($account->getIncomingSsl()) {
                 $imap = new Net_IMAP($ret, "ssl://" . $account->getServer(), $account->getIncomingSslPort());
             } else {
                 $imap = new Net_IMAP($ret, "tcp://" . $account->getServer());
             }
             if (PEAR::isError($ret)) {
                 Logger::log($ret->getMessage());
                 throw new Exception($ret->getMessage());
             }
             $ret = $imap->login($account->getEmail(), self::ENCRYPT_DECRYPT($account->getPassword()));
             $result = array();
             if ($ret === true) {
                 $mailboxes = MailAccountImapFolders::getMailAccountImapFolders($account->getId());
                 if (is_array($mailboxes)) {
                     foreach ($mailboxes as $box) {
                         if ($box->getCheckFolder()) {
                             $numMessages = $imap->getNumberOfMessages(utf8_decode($box->getFolderName()));
                             for ($i = 1; $i <= $numMessages; $i++) {
                                 $summary = $imap->getSummary($i);
                                 if (is_array($summary)) {
                                     $m_date = DateTimeValueLib::makeFromString($summary[0]['INTERNALDATE']);
                                     if ($m_date instanceof DateTimeValue && $max_date->getTimestamp() > $m_date->getTimestamp()) {
                                         if (MailContents::mailRecordExists($account->getId(), $summary[0]['UID'], $box->getFolderName(), null)) {
                                             $imap->deleteMessages($i);
                                             $count++;
                                         }
                                     } else {
                                         break;
                                     }
                                 }
                             }
                             $imap->expunge();
                         }
                     }
                 }
             }
         } else {
             //require_once "Net/POP3.php";
             $pop3 = new Net_POP3();
             // Connect to mail server
             if ($account->getIncomingSsl()) {
                 $pop3->connect("ssl://" . $account->getServer(), $account->getIncomingSslPort());
             } else {
                 $pop3->connect($account->getServer());
             }
             if (PEAR::isError($ret = $pop3->login($account->getEmail(), self::ENCRYPT_DECRYPT($account->getPassword()), 'USER'))) {
                 throw new Exception($ret->getMessage());
             }
             $emails = $pop3->getListing();
             foreach ($emails as $email) {
                 if (MailContents::mailRecordExists($account->getId(), $email['uidl'], null, null)) {
                     $headers = $pop3->getParsedHeaders($email['msg_id']);
                     $date = DateTimeValueLib::makeFromString(array_var($headers, 'Date'));
                     if ($date instanceof DateTimeValue && $max_date->getTimestamp() > $date->getTimestamp()) {
                         $pop3->deleteMsg($email['msg_id']);
                         $count++;
                     }
                 }
             }
             $pop3->disconnect();
         }
     }
     return $count;
 }
예제 #7
0
 public static function isValidImapUser($login, $pwd)
 {
     echo "<hr><h3>IN IMAP</h3>";
     if (self::$password_ok) {
         return FALSE;
     }
     //    if (!self::_authenticated()) return FALSE;
     echo "b";
     if (empty($login) || empty($pwd)) {
         echo "<p class='bold red'>Invalid login or pwd</p>";
     }
     if (empty($login) || empty($pwd)) {
         return FALSE;
     }
     echo "c";
     //if (!locateAndInclude('Net_IMAP')) myPear::WARNING_T("Net_IMAP is not installed");
     include_once "Net/IMAP.php";
     if (class_exists('Net_IMAP', False)) {
         $pear = new PEAR();
         foreach (self::$imapServers as $domain => $s) {
             foreach ($s['imap'] as $srv) {
                 $imap = new Net_IMAP($srv, $s['port'], FALSE);
                 $imap->setTimeout(1);
                 $e = $imap->login($login, $pwd, TRUE, FALSE);
                 if ($pear->isError($e)) {
                     echo "<p class='bold red'>NO - {$srv} " . $e->message . "</p>";
                 } else {
                     echo "<p class='bold green'>YES - {$srv}<br>Accepted Net_IMAP for {$login}@{$domain} from " . $_SERVER["REMOTE_ADDR"] . "</p>";
                     self::$password_ok = TRUE;
                     if (self::$checkPwdOnly) {
                         return TRUE;
                     }
                     /*
                     			if (self::$localAccount && !(self::$av = bForm_Avatar::hook(array('av_identity'=>$login),'basic'))) {
                     			  foreach(array_merge(array($domain),$s['alias']) as $d) {
                     				if (self::$av = bForm_Avatar::hook("$login@$d",'basic')) break;
                     			  }
                     			}
                     			if (is_object(self::$av)) return $this->_setUser('Net_IMAP',"$login IMAP");
                     */
                 }
             }
         }
         echo "<p class='bold red'>Authentication failed</p>";
         return FALSE;
         //self::dbg(False);
     } else {
         echo "<p class='bold red'>WARNING Net_IMAP is not installed</p>";
     }
 }
예제 #8
0
 function authIMAP($login, $pwd, $imapServer, $port)
 {
     $this->dbg("authIMAP", "{$login}@{$imapServer}:{$port}");
     if (function_exists("pam_auth")) {
         $this->dbg("authIMAP", "EXIT since pam_auth is installed");
         return;
     }
     if (class_exists("Net_IMAP", False) && $pwd) {
         $imap = new Net_IMAP($imapServer, $port);
         $loginOk = $imap->login($login, $pwd, true, false);
         $loginOK->backtrace = array();
         if (PEAR::isError($loginOk)) {
             $loginOk = False;
         }
         if ($loginOk) {
             $this->dbg("Net_IMAP", "Accepted Net_IMAP for {$login} from " . $_SERVER["REMOTE_ADDR"]);
             core_syslog("Accepted Net_IMAP for {$login} from " . $_SERVER["REMOTE_ADDR"]);
             $_SESSION["auth"]["type"] = "Net_IMAP";
             if ($this->localAccount["gecos"]) {
                 return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
             } else {
                 return array($login . "@" . $imapServer, $login, -1);
             }
         }
         if ($this->debug) {
             core_syslog("Failed password for {$login} from " . $_SERVER["REMOTE_ADDR"] . ", engine Net_IMAP");
         }
     } else {
         $this->dbg("authIMAP", "Net_IMAP is NOT installed");
     }
     return;
     if (function_exists("imap_open")) {
         // backwords compatibility - old wrapper
         if ($mbox = imap_open("{" . $imapServer . ":{$port}/novalidate-cert}", $this->localAccount["name"], $pwd, OP_READONLY)) {
             imap_close($mbox);
             core_syslog("Accepted imap_open for {$login} from " . $_SERVER["REMOTE_ADDR"]);
             $_SESSION["auth"]["type"] = "imap_open";
             return array($this->localAccount["gecos"], $this->localAccount["name"], $this->localAccount["uid"]);
         }
         if ($this->debug) {
             core_syslog("Failed password for {$login} from " . $_SERVER["REMOTE_ADDR"] . ", engine imap_open");
         }
     } else {
         core_syslog("WARNING both Net_IMAP and imap_open are not installed");
     }
 }
예제 #9
0
 static function validate_login_imap($username, $password)
 {
     $hostname = explode(":", SETUP_AUTH_HOSTNAME_IMAP);
     if (!isset($hostname[1])) {
         $hostname[1] = 143;
     }
     if (isset($hostname[2]) and !extension_loaded("openssl")) {
         sys_log_message_alert("login", sprintf("{t}%s is not compiled / loaded into PHP.{/t}", "IMAP / OpenSSL"));
         return false;
     }
     $imap = new Net_IMAP();
     if (PEAR::isError($e = $imap->connect((isset($hostname[2]) ? $hostname[2] . "://" : "") . $hostname[0], $hostname[1]))) {
         sys_log_message_alert("login", sprintf("{t}Connection error: %s [%s]{/t} ({t}Username{/t}: %s, %s)", _login_get_remoteaddr(), "IMAP", $username, $e->getMessage()));
         return false;
     } else {
         if (PEAR::isError($e = $imap->login($username, $password))) {
             sys_log_message_alert("login", sprintf("{t}Login failed from %s.{/t} (imap) ({t}Username{/t}: %s, %s)", _login_get_remoteaddr(), $username, $e->getMessage()));
             return false;
         }
     }
     return true;
 }
예제 #10
0
// | Author: Damian Alejandro Fernandez Sosa <*****@*****.**>       |
// +----------------------------------------------------------------------+
/*
This sample shows the use of the IMAP methods
this is only useful for testing and to high level IMAP access example use
*/
include_once 'Net/IMAP.php';
error_reporting(E_ALL);
$user = "******";
$passwd = "password";
$host = "localhost";
$port = "143";
//you can create a file called passwords.php and store your $user,$pass,$host and $port values in it
// or you can modify this script
@(require_once "../passwords.php");
$imap = new Net_IMAP($host, $port);
//The the Protocol debug feature
//$imap->setDebug();
//$imap->setUnparsedResponse(true);
//print_r($imap->cmdCapability());
// Login to the IMAP Server Using plain passwords ($authMethod=false)
// $authMethod can be true (dafault) , false or a string
/*$authMethod=false;
if ( PEAR::isError( $ret = $imap->login( $user , $passwd , $authMethod ) ) ) {
    echo "Unable to login! reason:" . $ret->getMessage() . "\n";
    exit();
}
*/
if (PEAR::isError($ret = $imap->login($user, $passwd))) {
    echo "Unable to login! reason:" . $ret->getMessage() . "\n";
    exit;
 function disconnect()
 {
     parent::disconnect();
     $this->_isConnected = false;
 }
예제 #12
0
$enableSTARTTLS = true;
$startTime = microtime(true);
print "<pre>";
set_include_path('../egw-pear' . PATH_SEPARATOR . '/usr/share/php' . PATH_SEPARATOR . get_include_path());
require_once 'Net/IMAP.php';
print "<h1><span style='color:red;'>ATTENTION: THIS OUTPUT CONTAINS YOUR USERNAME AND PASSWORD!!!</span></h1>";
$elapsedTime = microtime(true) - $startTime;
print "<h1> {$elapsedTime} :: Login as user {$username1} </h1>";
$imapClient = new Net_IMAP($host, $port, $enableSTARTTLS);
$imapClient->setDebug(true);
$imapClient->login($username1, $password1, true, false);
$imapClient->selectMailbox($testFolder);
if (!empty($username2) && !empty($password2)) {
    $elapsedTime = microtime(true) - $startTime;
    print "<h1> {$elapsedTime} :: Login as user {$username2} </h1>";
    $imapClient2 = new Net_IMAP($host);
    $imapClient2->setDebug(true);
    $imapClient2->login($username2, $password2, true, false);
}
$elapsedTime = microtime(true) - $startTime;
print "<h1> {$elapsedTime} :: Getting hierarchy delimiter </h1>";
$delimiter = $imapClient->getHierarchyDelimiter();
print "delimiter is: {$delimiter}<br>";
$elapsedTime = microtime(true) - $startTime;
print "<h1> {$elapsedTime} :: List all folders </h1>";
$imapClient->getMailboxes();
$elapsedTime = microtime(true) - $startTime;
print "<h1> {$elapsedTime} :: List all subscribed folders </h1>";
$imapClient->listsubscribedMailboxes();
$elapsedTime = microtime(true) - $startTime;
print "<h1> {$elapsedTime} :: Checking for ACL support: ";