[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * The IMP_IMAP:: class facilitates connections to the IMAP/POP3 server 4 * via the c-client PHP extensions. 5 * 6 * $Horde: imp/lib/IMAP.php,v 1.11.10.15 2007/01/02 13:54:56 jan Exp $ 7 * 8 * Copyright 2003-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 9 * 10 * See the enclosed file COPYING for license information (GPL). If you 11 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 12 * 13 * @author Michael Slusarz <slusarz@bigworm.colorado.edu> 14 * @since IMP 4.0 15 * @package IMP 16 */ 17 class IMP_IMAP { 18 19 /** 20 * The server string. 21 * 22 * @var string 23 */ 24 var $_serverString; 25 26 /** 27 * The username for the server. 28 * 29 * @var string 30 */ 31 var $_user; 32 33 /** 34 * The password for the mail server. 35 * 36 * @var string 37 */ 38 var $_pass; 39 40 /** 41 * The currently open mailbox. 42 * 43 * @var string 44 */ 45 var $_openMbox = null; 46 47 /** 48 * The IMAP flags set in the currently open mailbox. 49 * 50 * @var integer 51 */ 52 var $_mboxFlags = null; 53 54 /** 55 * Attempts to return a reference to a concrete IMP_IMAP instance. 56 * It will only create a new instance if no IMP_IMAP instance currently 57 * exists. 58 * 59 * This method must be invoked as: 60 * $imp_imap = &IMP_IMAP::singleton(); 61 * 62 * @param array $params Parameters needed. 63 * 64 * @return IMP_IMAP The concrete IMP_IMAP reference, or false on error. 65 */ 66 function &singleton($params = array()) 67 { 68 static $instance; 69 70 if (!isset($instance)) { 71 $instance = new IMP_IMAP($params); 72 } 73 74 return $instance; 75 } 76 77 /** 78 * Constructor. 79 * 80 * @param array $params Any additional parameters needed. 81 */ 82 function IMP_IMAP($params = array()) 83 { 84 $this->_serverString = IMP::serverString(null, $_SESSION['imp']['protocol']); 85 $this->_user = $_SESSION['imp']['user']; 86 $this->_pass = Secret::read(Secret::getKey('imp'), $_SESSION['imp']['pass']); 87 } 88 89 /** 90 * Open an IMAP stream. 91 * 92 * @param string $mbox A mailbox to open. 93 * @param integer $flags Any flags that need to be passed to imap_open(). 94 * 95 * @return resource The return from the imap_open() call. 96 */ 97 function openIMAPStream($mbox = null, $flags = 0) 98 { 99 $i = -1; 100 $ret = false; 101 if (empty($mbox)) { 102 $flags |= OP_HALFOPEN; 103 } 104 105 while (($ret === false) && 106 !strstr(strtolower(imap_last_error()), 'login failure') && 107 (++$i < $_SESSION['imp']['login_tries'])) { 108 if ($i != 0) { 109 sleep(1); 110 } 111 $ret = @imap_open($this->_serverString . $mbox, $this->_user, $this->_pass, $flags); 112 } 113 return $ret; 114 } 115 116 /** 117 * Change the currently active IMP IMAP stream to a new mailbox 118 * (if necessary). 119 * 120 * @param string $mbox The new mailbox. 121 * @param integer $flags Any flags that need to be passed to 122 * imap_reopen(). 123 * 124 * @return boolean True on success, false on error. 125 */ 126 function changeMbox($mbox, $flags = 0) 127 { 128 /* Open a connection if none exists. */ 129 if (empty($_SESSION['imp']['stream'])) { 130 if (($_SESSION['imp']['stream'] = $this->openIMAPStream($mbox, $flags))) { 131 $this->_openMbox = $mbox; 132 $this->_mboxFlags = $flags; 133 if (empty($mbox)) { 134 $this->_mboxFlags |= OP_HALFOPEN; 135 } 136 137 if (!empty($_SESSION['imp']['imap_server']['timeout'])) { 138 foreach ($_SESSION['imp']['imap_server']['timeout'] as $key => $val) { 139 imap_timeout($key, $val); 140 } 141 } 142 return true; 143 } else { 144 return false; 145 } 146 } 147 148 if ($_SESSION['imp']['base_protocol'] == 'pop3') { 149 return true; 150 } 151 152 /* Only reopen mailbox if we need to - either we are changing 153 mailboxes or the flags for the current mailbox has changed. */ 154 if (($this->_openMbox != $mbox) || ($this->_mboxFlags != $flags)) { 155 $result = @imap_reopen($_SESSION['imp']['stream'], $this->_serverString . $mbox, $flags); 156 if ($result) { 157 $this->_openMbox = $mbox; 158 $this->_mboxFlags = $flags; 159 return true; 160 } else { 161 return false; 162 } 163 } 164 165 return true; 166 } 167 168 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |