cvs: pear /Net_IMAP IMAP.php IMAPProtocol.php

From: Date: Sun, 26 Mar 2006 22:08:44 +0000
Subject: cvs: pear /Net_IMAP IMAP.php IMAPProtocol.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-39338@lists.php.net to get a copy of this message
amistry Sun Mar 26 22:08:44 2006 UTC Modified files: /pear/Net_IMAP IMAP.php IMAPProtocol.php Log: Add STARTTLS support for PHP 5.1 and above. Add the ability to create and rename users in partitions. eg. $options = array("PARTITION" => "Server1:Partition1", "TYPE" => "Calendar"); createMailbox("newuser", $options); Currently only the PARTITION argument is used, but if the createparams working draft is approved an implemented then adding more options will be trivial. http://cvs.php.net/viewcvs.cgi/pear/Net_IMAP/IMAP.php?r1=1.2&r2=1.3&diff_format=u Index: pear/Net_IMAP/IMAP.php diff -u pear/Net_IMAP/IMAP.php:1.2 pear/Net_IMAP/IMAP.php:1.3 --- pear/Net_IMAP/IMAP.php:1.2 Fri Apr 8 01:39:15 2005 +++ pear/Net_IMAP/IMAP.php Sun Mar 26 22:08:44 2006 @@ -67,6 +67,15 @@ { $ret=$this->cmdConnect($host,$port); if($ret === true ){ + // Determine server capabilities + $res = $this->cmdCapability(); + + // check if we can enable TLS via STARTTLS + if($this->hasCapability('STARTTLS') === true && function_exists('stream_socket_enable_crypto') === true) { + if (PEAR::isError($res = $this->cmdStartTLS())) { + return $res; + } + } return $ret; } if(empty($ret)){ @@ -80,6 +89,7 @@ return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]); } } + return $ret; } @@ -935,13 +945,14 @@ * Creates the mailbox $mailbox * * @param string $mailbox mailbox name to create + * @param array $options options to pass to create * * @return mixed true on Success/PearError on Failure * @since 1.0 */ - function createMailbox($mailbox) + function createMailbox($mailbox, $options = null) { - $ret=$this->cmdCreate($mailbox); + $ret=$this->cmdCreate($mailbox, $options); if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){ return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]); } @@ -950,7 +961,6 @@ - /** * Deletes the mailbox $mailbox * @@ -981,13 +991,14 @@ * Renames the mailbox $mailbox * * @param string $mailbox mailbox name to rename + * @param array $options options to pass to rename * * @return mixed true on Success/PearError on Failure * @since 1.0 */ - function renameMailbox($oldmailbox, $newmailbox) + function renameMailbox($oldmailbox, $newmailbox, $options = null) { - $ret=$this->cmdRename($oldmailbox,$newmailbox); + $ret=$this->cmdRename($oldmailbox,$newmailbox,$options); if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){ return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]); } http://cvs.php.net/viewcvs.cgi/pear/Net_IMAP/IMAPProtocol.php?r1=1.5&r2=1.6&diff_format=u Index: pear/Net_IMAP/IMAPProtocol.php diff -u pear/Net_IMAP/IMAPProtocol.php:1.5 pear/Net_IMAP/IMAPProtocol.php:1.6 --- pear/Net_IMAP/IMAPProtocol.php:1.5 Wed Mar 22 05:00:20 2006 +++ pear/Net_IMAP/IMAPProtocol.php Sun Mar 26 22:08:44 2006 @@ -311,7 +311,7 @@ function _putCMD($commandId , $command, $args = '') { if ( !empty( $args ) ) { - return $this->_send( $commandId . " " . $command . ' ' . $args . "\r\n" ); + return $this->_send( $commandId . " " . $command . " " . $args . "\r\n" ); } return $this->_send( $commandId . " " . $command . "\r\n" ); } @@ -808,49 +808,41 @@ /** * Send the CREATE Mailbox Command * - * @param string The mailbox to create. + * @param string $mailbox The mailbox to create. + * @param array $options options to pass to create * @return array Returns an array containing the response * * @access public * @since 1.0 */ - function cmdCreate($mailbox) + function cmdCreate($mailbox, $options = null) { - $mailbox_name=sprintf("\"%s\"",$this->utf_7_encode($mailbox) ); - return $this->_genericCommand('CREATE', $mailbox_name); + $args = ""; + $mailbox_name = sprintf("\"%s\"",$this->utf_7_encode($mailbox)); + $args = $this->_getCreateParams($options); + return $this->_genericCommand('CREATE', $mailbox_name.$args); } - - - - - - /** * Send the RENAME Mailbox Command * - * @param string The old mailbox name. - * @param string The new (renamed) mailbox name. + * @param string $mailbox The old mailbox name. + * @param string $new_mailbox The new (renamed) mailbox name. + * @param array $options options to pass to create * * @return array Returns an array containing the response * * @access public * @since 1.0 */ - function cmdRename($mailbox, $new_mailbox) + function cmdRename($mailbox, $new_mailbox, $options = null) { $mailbox_name=sprintf("\"%s\"",$this->utf_7_encode($mailbox) ); $new_mailbox_name=sprintf("\"%s\"",$this->utf_7_encode($new_mailbox) ); - return $this->_genericCommand('RENAME', "$mailbox_name $new_mailbox_name" ); + $args = $this->_getCreateParams($options); + return $this->_genericCommand('RENAME', "$mailbox_name $new_mailbox_name".$args ); } - - - - - - - /** * Send the DELETE Mailbox Command * @@ -3058,7 +3050,61 @@ return $decoded_utf7; } + /** + * Make CREATE/RENAME compatible option params + * + * @param array $options options to format + * @return string Returns a string for formatted parameters + * + * @access private + * @since 1.1 + */ + function _getCreateParams($options) + { + $args = ""; + if(is_null($options) === false && is_array($options) === true) { + foreach($options as $opt => $data) { + switch(strtoupper($opt)) { + case "PARTITION": + $args .= sprintf(" %s",$this->utf_7_encode($data)); + break; + default: + // ignore any unknown options + break; + } + } + } + return $args; + } + + /** + * Return true if the TLS negotiation was successful + * + * @access public + * @return mixed true on success, PEAR_Error on failure + */ + function cmdStartTLS() + { + if (PEAR::isError($res = $this->_genericCommand("STARTTLS"))) { + return $res; + } + + if(stream_socket_enable_crypto($this->_socket->fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT) == false) { + $msg = 'Failed to establish TLS connection'; + return new PEAR_Error($msg); + } + + if($this->_debug === true) { + echo "STARTTLS Negotiation Successful\n"; + } + // RFC says we need to query the server capabilities again + if(PEAR::isError($res = $this->cmdCapability() )) { + $msg = 'Failed to connect, server said: ' . $res->getMessage(); + return new PEAR_Error($msg); + } + return true; + } }//Class ?>

« previous php.pear.cvs (#39338) next »