<?PHP
/* 13.09.2011 можно спамить сюда testtesttest73гав-гавgmail.com это алиас рабочего ящика
это моя первая попытка написать класc пэхапэ дополняющий Zend_Mail_Protocol_Imap (версия $Id: Imap.php 18977 2009-11-14 14:15:59Z yoshida@zend.co.jp )
т.е. сам по себе этот клас не работает, только вместе с зендом.
require_once "Zend/Mail/Protocol/Imap.php";
первым делом добавим сюда hex2dec and vice versa
http://code.google.com/intl/ru-RU/apis/gmail/imap/
*/
class shkur_IMAP_class_Extends_Zend_Mail_Protocol_Imap extends Zend_Mail_Protocol_Imap {
/**
* set flags label to threads
*
* @param string|array $flags flags to set, add or remove - see $mode
* @param int $from message for items or start message if $to !== null
* @param int|null $to if null only one message ($from) is fetched, else it's the
* last message, INF means last message avaible
* @param string|null $mode 'null' and '+' to add flags, '-' to remove flags, everything else sets the flags as given
* @param bool $silent if false the return values are the new flags for the wanted messages
* @return bool|array new flags if $silent is false, else true or false depending on success
* @throws Zend_Mail_Protocol_Exception
*/
public function gmailLabel($flags, $from, $to = null, $mode = null, $silent = true){
$item = 'X-GM-LABELS';
($mode == null ? $mode = '+' : null);
if ($mode == '+' || $mode == '-') {
$item = $mode . $item;
}
$flags = $this->escapeList($flags);
} else if ($to === null) {
$set = (int)$from;
} else if ($to === INF) {
$set = (int)$from . ':*';
} else {
$set = (int)$from . ':' . (int)$to;
}
$result = $this->requestAndResponse('STORE', array($set, $item, $flags), $silent);
if ($silent) {
return $result ? true : false;
}
$tokens = $result;
foreach ($tokens as $token) {
if ($token[1] != 'FETCH' || $token[2][0] != 'X-GM-LABELS') {
continue;
}
$result[$token[0]] = $token[2][1];
}
return $result;
}
/**
* Gets the parent stack of a string array element if it is found within the
* parent array
*
* This will not search objects within an array, though I suspect you could
* tweak it easily enough to do that
*
* @param string $child The string array element to search for
* @param array $stack The stack to search within for the child
* @return array An array containing the parent stack for the child if found,
* false otherwise
*/
function getParentStack($child, $stack) {
foreach ($stack as $k => $v) {
// If the current element of the array is an array, recurse it and capture the return
$return = $this->getParentStack($child, $v);
// If the return is an array, stack it and return it
return array($k => $return); }
} else {
// Since we are not on an array, compare directly
if ($v == $child) {
// And if we match, stack it and return it
return array($k => $child); }
}
}
// Return false since there was nothing found
return false;
}
/**
* Gets the complete parent stack of a string array element if it is found
* within the parent array
*
* This will not search objects within an array, though I suspect you could
* tweak it easily enough to do that
*
* @param string $child The string array element to search for
* @param array $stack The stack to search within for the child
* @return array An array containing the parent stack for the child if found,
* false otherwise
*/
function getParentStackComplete($child, $stack){
foreach ($stack as $k => $v) {
// If the current element of the array is an array, recurse it
// and capture the return stack
$stack = $this->getParentStackComplete($child, $v);
// If the return stack is an array, add it to the return
$return[$k] = $stack;
}
} else {
// Since we are not on an array, compare directly
if ($v == $child){
// And if we match, stack it and return it
$return[$k] = $child;
}
}
}
// Return the stack
return empty($return) ?
false: $return; }
/** list переделанный в Xlist
* get mailbox list
*
* this method can't be named after the IMAP command 'LIST', as list is a reserved keyword
*
* @param string $reference mailbox reference for list
* @param string $mailbox mailbox name match with wildcards
* @return array mailboxes that matched $mailbox as array(globalName => array('delim' => .., 'flags' => ..))
* @throws Zend_Mail_Protocol_Exception
*/
public function xlist($reference = '', $mailbox = '*'){
$list = $this->requestAndResponse('XLIST', $this->escapeString($reference, $mailbox));
if (!$list || $list === true){
return $result;
}
foreach ($list as $item){
if (count($item) != 4
|| $item[0] != 'XLIST'){ continue;
}
$result[$item[3
]] = array('delim' => $item[2], 'flags' => $item[1
]); }
return $result;
}
/* Input: A decimal number as a String.
Output: The equivalent hexadecimal number as a String.*/
function dec2hex($number){
$hexvalues = array('0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f');
$hexval = '';
while($number != '0') {
$hexval = $hexvalues[bcmod($number,'16')].$hexval; $number = bcdiv($number,'16',0
); }
return $hexval;
}
/* Input: A hexadecimal number as a String.
Output: The equivalent decimal number as a String. */
function hex2dec($number){
$decvalues = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5',
'6' => '6', '7' => '7', '8' => '8',
'9' => '9', 'a' => '10', 'b' => '11',
'c' => '12', 'd' => '13', 'e' => '14',
'f' => '15');
$decval = '0';
for($i = 0; $i < strlen($number); $i++){ }
return $decval;
}
/** так как эта функция будет исключена в следующих версиях Zend я пихну её сюда.
* do a search request
*
* This method is currently marked as internal as the API might change and is not
* safe if you don't take precautions.
*
* @internal
* @return array message ids array($this->escapeString($params)) - непонятная херня
*/
public function search
(array $params){ $response = $this->requestAndResponse('SEARCH', $params);
if (!$response) {
return 'gotohell';//$response;
}
foreach ($response as $ids) {
if ($ids[0] == 'SEARCH') {
return $ids;
}
}
}
}
?>