init(); } // public function connect( $config ) // { // $this->init(); // } public function find( $URI, $justthese = false, $criteria = false ) { $context = $justthese['context']; $URI = $URI['concept']; switch( $URI ) { case 'folder': { $result = $this->to_utf8($this->get_folders_list()); foreach ($result as $res) { $response[] = array( 'id' => $res['folder_id'], 'commonName' => $res['folder_name'], 'parentFolder' => $res['folder_parent'], 'messageCount' => array('unseen' => isset($res['folder_unseen']) ? $res['folder_unseen'] : null, 'total' => null) ); } break; } case 'message': { //begin: for grid $page = $criteria['page']; //{1} get the requested page $limit = $criteria['rows']; //{10} get how many rows we want to have into the grid $sidx = $criteria['sidx']; //{id} get index row - i.e. user click to sort $sord = $criteria['sord']; //{desc} get the direction $filter = $criteria['filter']; if( !$sidx ) $sidx = 1; $folder_name = str_replace( '.', $this->imap_delimiter, $context['folder'] ); $count = imap_num_msg( $this->open_mbox( $folder_name ) ); $total_pages = $count > 0 ? ceil( $count/$limit ) : 0; if( $page > $total_pages ) $page = $total_pages; $start = $limit * $page - $limit; // do not put $limit*($page - 1) //end: for grid if( $filter ) { if( $filter[0] !== 'msgNumber' ) { for( $i = 0; $i < count($filter); $i++ ) { if( count( $filter[$i] ) === 4 ) $criteria['isExact'] = ( array_shift( $filter[$i] ) === 'AND' ); $criteria[ $filter[$i][0] ] = array( 'criteria' => $filter[$i][2], 'filter' => $filter[$i][1] ); } return $this->searchSieveRule($criteria); } $msgNumber = array(); for( $i = $start; $i < $start + $limit && isset( $filter[2][$i] ); $i++ ) $msgNumber[] = $filter[2][$i]; if( empty( $msgNumber ) ) return( false ); $result = $this->get_info_msgs( array( 'folder' => $folder_name, 'msgs_number' => implode( ',', $msgNumber ) ) ); foreach( $result as $i => $val ) $result[$i] = unserialize( $val ); } else { $result = $this->get_range_msgs2( array( 'folder' => $folder_name, //INBOX 'msg_range_begin' => $start + 1, //?? 'msg_range_end' => $start + $limit, //$limit = $_GET['rows']; // get how many rows we want to have into the grid 'sort_box_type' => 'SORTARRIVAL', 'search_box_type' => 'ALL', 'sort_box_reverse' => 1 ) ); } //return var_export($result); $response = array( "page" => $page, "total" => $total_pages, "records" => $count ); for ($i=0; $i $flag) { if ( !isset($result[$i][$flag]) || !trim($result[$i][$flag]) || trim($result[$i][$flag]) == '') unset($flags_enum[$key]); unset($result[$i][$flag]); } if (array_key_exists($i, $result)) { $response["rows"][$i] = $result[$i]; $response["rows"][$i]['timestamp'] = ( ( $result[$i]['udate'] + $this->functions->CalculateDateOffset() ) * 1000 ); $response["rows"][$i]['flags'] = implode(',', $flags_enum); $response["rows"][$i]['size'] = $response["rows"][$i]['Size']; // $response["rows"][$i]['udate'] = ( $result[$i]['udate'] + $this->functions->CalculateDateOffset() * 1000 ); unset($response["rows"][$i]['Size']); } } $response = $this->to_utf8($response); break; } } return $response; } // public function retrieve( $concept, $id, $parents, $justthese = false, $criteria = false ) // { // return $this->read( array( 'id' => $id, // 'concept' => $concept, // 'context' => $parents ), $justthese ); // } public function read( $URI, $justthese = false ) { return $this->to_utf8( $this->get_info_msg( array('msg_number'=>$URI['id'], 'msg_folder'=>str_replace( '.', $this->imap_delimiter, $justthese['context']['folder'] )) ) ); } public function create( $URI, $data ) {} public function delete( $URI, $justthese = false, $criteria = false ) {} public function deleteAll( $URI, $justthese = false, $criteria = false ) // avaliar {} public function update( $URI, $data, $criteria = false ) {} public function replace( $URI, $data, $criteria = false ) {} public function close() {} public function setup() {} public function commit( $uri ) { return( true ); } public function rollback( $uri ) {} public function begin( $uri ) {} public function teardown() {} function to_utf8($in) { if (is_array($in)) { foreach ($in as $key => $value) { $out[$this->to_utf8($key)] = $this->to_utf8($value); } } elseif(is_string($in)) { return mb_convert_encoding( $in , 'UTF-8' , 'UTF-8 , ISO-8859-1' ); } else { return $in; } return $out; } }