[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * IMP external API interface. 4 * 5 * This file defines IMP's external API interface. Other applications 6 * can interact with IMP through this API. 7 * 8 * $Horde: imp/lib/api.php,v 1.94.10.14 2006/04/19 14:24:08 jan Exp $ 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 * @package IMP 14 */ 15 16 $_services['perms'] = array( 17 'args' => array(), 18 'type' => '{urn:horde}stringArray'); 19 20 $_services['authenticate'] = array( 21 'args' => array('userID' => 'string', 'credentials' => '{urn:horde}hash', 'params' => '{urn:horde}hash'), 22 'checkperms' => false, 23 'type' => 'boolean' 24 ); 25 26 $_services['getStream'] = array( 27 'args' => array('mailbox' => 'string', 'flags' => 'int'), 28 'type' => 'resource' 29 ); 30 31 $_services['compose'] = array( 32 'args' => array('args' => '{urn:horde}hash', 'extra' => '{urn:horde}hash'), 33 'type' => 'string' 34 ); 35 36 $_services['batchCompose'] = array( 37 'args' => array('args' => '{urn:horde}hash', 'extra' => '{urn:horde}hash'), 38 'type' => 'string' 39 ); 40 41 $_services['folderlist'] = array( 42 'args' => array(), 43 'type' => '{urn:horde}stringArray' 44 ); 45 46 $_services['createFolder'] = array( 47 'args' => array('folder' => 'string'), 48 'type' => 'string' 49 ); 50 51 $_services['server'] = array( 52 'args' => array(), 53 'type' => 'string' 54 ); 55 56 if (!empty($_SESSION['imp']['admin'])) { 57 $_services['userList'] = array( 58 'type' => '{urn:horde}stringArray' 59 ); 60 61 $_services['addUser'] = array( 62 'args' => array('userId' => 'string', 'credentials' => '{urn:horde}hash') 63 ); 64 65 $_services['removeUser'] = array( 66 'args' => array('userId' => 'string', 'credentials' => '{urn:horde}hash') 67 ); 68 } 69 70 71 function _imp_perms() 72 { 73 $perms = array(); 74 75 $perms['tree']['imp']['create_folders'] = false; 76 $perms['title']['imp:create_folders'] = _("Allow Folder Creation?"); 77 $perms['type']['imp:create_folders'] = 'boolean'; 78 $perms['tree']['imp']['max_folders'] = false; 79 $perms['title']['imp:max_folders'] = _("Maximum Number of Folders"); 80 $perms['type']['imp:max_folders'] = 'int'; 81 82 return $perms; 83 } 84 85 /** 86 * TODO 87 * 88 * @param string $userID TODO 89 * @param array $credentials TODO 90 * @param array $params TODO 91 * 92 * @return boolean Whether IMP authentication was successful. 93 */ 94 function _imp_authenticate($userID, $credentials, $params) 95 { 96 $GLOBALS['authentication'] = 'none'; 97 require_once dirname(__FILE__) . '/base.php'; 98 99 if (!empty($params['server'])) { 100 $server = $params['server']; 101 } else { 102 require IMP_BASE . '/config/servers.php'; 103 foreach ($servers as $key => $curServer) { 104 if (!isset($server) && substr($key, 0, 1) != '_') { 105 $server = $key; 106 } 107 if (IMP::isPreferredServer($curServer, $key)) { 108 $server = $key; 109 break; 110 } 111 } 112 } 113 114 require_once IMP_BASE . '/lib/Session.php'; 115 if (IMP_Session::createSession($userID, $credentials['password'], $server)) { 116 global $imp; 117 $entry = sprintf('Login success for %s [%s] to {%s:%s}', $imp['uniquser'], $_SERVER['REMOTE_ADDR'], $imp['server'], $imp['port']); 118 Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_NOTICE); 119 return true; 120 } 121 122 return false; 123 } 124 125 /** 126 * Attempts to authenticate via IMP and return an IMAP stream. 127 * 128 * @param string $mailbox The mailbox name. 129 * @param int $flags IMAP connection flags. 130 * 131 * @return mixed An IMAP resource on success, false on failure. 132 */ 133 function _imp_getStream($mailbox = null, $flags = 0) 134 { 135 $GLOBALS['authentication'] = 'none'; 136 require_once dirname(__FILE__) . '/base.php'; 137 138 if (IMP::checkAuthentication(OP_HALFOPEN, true) === true) { 139 require_once IMP_BASE . '/lib/IMAP.php'; 140 $imap = &IMP_IMAP::singleton(); 141 if ($imap->changeMbox($mailbox, $flags)) { 142 return $_SESSION['imp']['stream']; 143 } 144 } 145 146 return false; 147 } 148 149 /** 150 * Returns a compose window link. 151 * 152 * @param string|array $args List of arguments to pass to compose.php. 153 * If this is passed in as a string, it will be 154 * parsed as a toaddress?subject=foo&cc=ccaddress 155 * (mailto-style) string. 156 * @param array $extra Hash of extra, non-standard arguments to pass to 157 * compose.php. 158 * 159 * @return string The link to the message composition screen. 160 */ 161 function _imp_compose($args = array(), $extra = array()) 162 { 163 $link = _imp_batchCompose(array($args), array($extra)); 164 return $link[0]; 165 } 166 167 /** 168 * Return a list of compose window links. 169 * 170 * @param mixed $args List of lists of arguments to pass to compose.php. If 171 * the lists are passed in as strings, they will be parsed 172 * as toaddress?subject=foo&cc=ccaddress (mailto-style) 173 * strings. 174 * @param array $extra List of hashes of extra, non-standard arguments to pass 175 * to compose.php. 176 * 177 * @return string The list of links to the message composition screen. 178 */ 179 function _imp_batchCompose($args = array(), $extra = array()) 180 { 181 global $prefs; 182 183 $GLOBALS['authentication'] = 'none'; 184 require_once dirname(__FILE__) . '/base.php'; 185 186 $links = array(); 187 foreach ($args as $i => $arg) { 188 $links[$i] = IMP::composeLink($arg, isset($extra[$i]) ? $extra[$i] : null); 189 } 190 191 return $links; 192 } 193 194 /** 195 * Returns the list of folders. 196 * 197 * @return array The list of IMAP folders. 198 */ 199 function _imp_folderlist() 200 { 201 $GLOBALS['authentication'] = 'none'; 202 require_once dirname(__FILE__) . '/base.php'; 203 204 $result = false; 205 206 if (IMP::checkAuthentication(OP_HALFOPEN, true) === true) { 207 if ($_SESSION['imp']['base_protocol'] == 'pop3') { 208 209 $result = array('INBOX' => array('val' => 'INBOX', 'label' => 'INBOX', 'abbrev' => 'INBOX')); 210 } else { 211 require_once IMP_BASE . '/lib/Folder.php'; 212 $imp_folder = &IMP_Folder::singleton(); 213 $result = $imp_folder->flist_IMP(); 214 } 215 } 216 217 return $result; 218 } 219 220 /** 221 * Creates a new folder. 222 * 223 * @param string $folder The UTF7-IMAP encoded name of the folder to create. 224 * 225 * @return string The full folder name created on success, an empty string 226 * on failure. 227 */ 228 function _imp_createFolder($folder) 229 { 230 $GLOBALS['authentication'] = 'none'; 231 require_once dirname(__FILE__) . '/base.php'; 232 require_once IMP_BASE . '/lib/Folder.php'; 233 234 $result = false; 235 236 if (IMP::checkAuthentication(OP_HALFOPEN, true) === true) { 237 $imp_folder = &IMP_Folder::singleton(); 238 $result = $imp_folder->create(IMP::appendNamespace($folder), $GLOBALS['prefs']->getValue('subscribe')); 239 } 240 241 return (empty($result)) ? '' : $folder; 242 } 243 244 /** 245 * Returns the currently logged on IMAP server. 246 * 247 * @return string The server hostname. Returns null if the user has not 248 * authenticated into IMP yet. 249 */ 250 function _imp_server() 251 { 252 $GLOBALS['authentication'] = 'none'; 253 require_once dirname(__FILE__) . '/base.php'; 254 return (IMP::checkAuthentication(OP_HALFOPEN, true) === true) ? $_SESSION['imp']['server'] : null; 255 } 256 257 /** 258 * Adds a set of authentication credentials. 259 * 260 * @param string $userId The userId to add. 261 * @param array $credentials The credentials to use. 262 * 263 * @return boolean True on success or a PEAR_Error object on failure. 264 */ 265 function _imp_addUser($userId, $credentials) 266 { 267 $params = $_SESSION['imp']['admin']['params']; 268 $params['admin_user'] = $params['login']; 269 $params['admin_password'] = Secret::read(Secret::getKey('imp'), $params['password']); 270 require_once 'Horde/IMAP/Admin.php'; 271 $imap = &new IMAP_Admin($params); 272 return $imap->addMailbox(String::convertCharset($userId, NLS::getCharset(), 'utf7-imap')); 273 } 274 275 /** 276 * Deletes a set of authentication credentials. 277 * 278 * @param string $userId The userId to delete. 279 * 280 * @return boolean True on success or a PEAR_Error object on failure. 281 */ 282 function _imp_removeUser($userId) 283 { 284 $params = $_SESSION['imp']['admin']['params']; 285 $params['admin_user'] = $params['login']; 286 $params['admin_password'] = Secret::read(Secret::getKey('imp'), $params['password']); 287 require_once 'Horde/IMAP/Admin.php'; 288 $imap = &new IMAP_Admin($params); 289 return $imap->removeMailbox(String::convertCharset($userId, NLS::getCharset(), 'utf7-imap')); 290 } 291 292 /** 293 * Lists all users in the system. 294 * 295 * @return array The array of userIds, or a PEAR_Error object on failure. 296 */ 297 function _imp_userList() 298 { 299 $params = $_SESSION['imp']['admin']['params']; 300 $params['admin_user'] = $params['login']; 301 $params['admin_password'] = Secret::read(Secret::getKey('imp'), $params['password']); 302 require_once 'Horde/IMAP/Admin.php'; 303 $imap = &new IMAP_Admin($params); 304 return $imap->listMailboxes(); 305 }
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 |
![]() |