[RCD] Help trying to do a search with only the framework.

Rodrigo Santellan rsantellan at gmail.com
Mon Apr 20 16:20:08 CEST 2015


Thomas,

Now the search is working, but is bringing all the mbox content not only
the search. If I run per example 'delivery' on roundcube in my ISP I get 6
result but on my search bring all the stuff.

This is my search method:
































































































































































* public function search($folder, $criteria, $pager = 1, $quantity = 1000)
{    $searchStringFound = true;    $searchString = '';    $aux =
$criteria;    if(substr_count($criteria, 'FROM:'))    {
$searchStringFound = false;      $searchString = str_replace('FROM  ',
'FROM ', str_replace('FROM:', 'FROM ', $criteria));    }
if($searchStringFound && substr_count($criteria, 'TEXT:'))    {
$searchStringFound = false;      $searchString = str_replace('TEXT:', 'TEXT
', $criteria);    }        if($searchStringFound && substr_count($criteria,
'SUBJECT:'))    {      $searchStringFound = false;      $searchString =
str_replace('SUBJECT:', 'SUBJECT ', $criteria);    }        /**     *
* @param  array  $set  Search set, result from
rcube_imap::get_search_set():     *                      0 - searching
criteria, string     *                      1 - search result,
rcube_result_index|rcube_result_thread     *                      2 -
searching character set, string     *                      3 - sorting
field, string     *                      4 - true if sorted, bool     */
$folderList = array($folder);    $sort_column = 'date';        $result =
$this->rcube->get_storage()->search($folderList, $searchString, null,
$sort_column);    //$searchRcube = new
\rcube_imap_search(array('skip_deleted' => true),
$this->rcube->get_storage()->conn);    //$data =
$searchRcube->exec(array($folder), $criteria, null, 'date');
//var_dump($result);    $result_h = array();    //$searchRcube->run();
// Get the headers    if (!$result->incomplete) {        $result_h =
$this->rcube->get_storage()->list_messages($folder, 1, $sort_column,
$sort_column);    }    // Make sure we got the headers    if
(!empty($result_h)) {        $count =
$this->rcube->get_storage()->count($folder,
$this->rcube->get_storage()->get_threading() ? 'THREADS' : 'ALL');
//var_dump($result_h);        //var_dump($count);
//rcmail_js_message_list($result_h, false);            }
$a_show_cols = ReceiveHelper::retrieveShowColumns($this->rcube);    $data =
array();    $multifolder = false;        foreach ($result_h as $header)
{            if (empty($header))                continue;            //
make message UIDs unique by appending the folder name            if
($multifolder) {                $header->uid .=
'-'.$header->folder;                $header->flags['skip_mbox_check'] =
true;                if ($header->parent_uid)
$header->parent_uid .= '-'.$header->folder;            }
$a_msg_cols  = array();            $a_msg_flags = array();            //
format each col; similar as in rcmail_message_list()            foreach
($a_show_cols as $col) {                $col_name = $col;// == 'fromto' ?
$smart_col : $col;                if($col == 'fromto')
{                 if($folder != 'INBOX'){                    $col_name =
'to';                  }else{                    $col_name =
'from';                  }                }                if
(in_array($col_name, array('from', 'to', 'cc', 'replyto')))
{                  $cont =
FormatHelper::rcmail_address_string($this->rcube, $header->$col_name, 3,
false, null, $header->charset);                }                else if
($col == 'subject') {                    $cont =
trim(rcube_mime::decode_header($header->$col,
$header->charset));                    if (!$cont) $cont =
$this->rcube->gettext('nosubject');                    $cont =
rcube::Q($cont);                }                else if ($col ==
'size')                    $cont = FormatHelper::show_bytes($this->rcube,
$header->$col);                else if ($col == 'date'){
$cont = FormatHelper::format_date($this->rcube,
$header->date);                }                else if ($col ==
'folder'){                  $cont =
rcube::Q(rcube_charset::convert($header->folder,
'UTF7-IMAP'));                }                else
{                  if(isset($header->$col))
{                    $cont = rcube::Q($header->$col);
}                  else                  {                    $cont =
'';                  }                }                $a_msg_cols[$col] =
$cont;            }            $a_msg_flags =
array_change_key_case(array_map('intval', (array)
$header->flags));            if (isset($header->depth))
$a_msg_flags['depth'] = $header->depth;            else if
(isset($header->has_children))                $roots[] =
$header->uid;            if (isset($header->parent_uid))
$a_msg_flags['parent_uid'] = $header->parent_uid;            if
(isset($header->has_children))                $a_msg_flags['has_children']
= $header->has_children;            if
(isset($header->unread_children))
$a_msg_flags['unread_children'] = $header->unread_children;            if
(isset($header->others['list-post']))                $a_msg_flags['ml'] =
1;            if (isset($header->priority))
$a_msg_flags['prio'] = (int) $header->priority;
$a_msg_flags['ctype'] = rcube::Q($header->ctype);
$a_msg_flags['mbox']  = $header->folder;            $data[] =
array(                'data' => $a_msg_cols,                'flags' =>
$a_msg_flags,                'uid' => $header->uid            );    }
return array(          'pages' => 0,          'page' => 0,
'exists' => true,          'data' => $data,          'headers' =>
$a_show_cols,      );            return
ReceiveHelper::processData($this->rcube, $result_h, $a_show_cols,
$folder);    //return $result_h;    //die;
//$this->rcube->get_storage()->set_search_set($search);    //return
ReceiveHelper::readMessages($this->rcube, $folder, $pager, $quantity);  }*

Regards.

Rodrigo

On Fri, Apr 17, 2015 at 5:00 AM, Thomas Bruederli <thomas at roundcube.net>
wrote:

> On Tue, Apr 14, 2015 at 9:45 PM, Rodrigo Santellan <rsantellan at gmail.com>
> wrote:
> > Hi,
>
> Hello Rodrigo
> >
> > I'm trying to do a search with only the framework framework. I has been
> > trying to separate the component so they can be used on another
> framework,
> > I'm using it now in Symonfony2 but planing to use in another ones.
> >
> > So far I identified the class rcube_imap_search that will do the search.
>
> Please note that this class is only a helper class for internal use.
> >
> > I created a helper with static methods that I'm rewriting to not use
> > globals.
> >
> >
> > On the file RouncubeHelper I create a connection to the IMAP server. My
> > problem is that when I try to do the actual search with the method
> search it
> > always come empty.
> >
> > What I'm missing? If I'm using only one folder is a good practice to call
> > to:
> > $searchRcube = new \rcube_imap_search(array('skip_deleted' => true),
> > $this->rcube->get_storage()->conn);
> > $data = $searchRcube->exec(array($folder), $criteria, null, 'date');
> >
> > Like that?
>
> In order to execute a search (or any other IMAP operation), you should
> use the methods of the rcube_imap instance you get via
> rcube::get_storage(). For searching that would be rcube_imap::search()
> [1]. See an example how to execute the search in the Roundcube webmail
> code [2].
>
> Kind regards,
> Thomas
>
>
> [1]
> https://github.com/roundcube/roundcubemail/blob/master/program/lib/Roundcube/rcube_imap.php#L1513
> [2]
> https://github.com/roundcube/roundcubemail/blob/master/program/steps/mail/search.inc#L121
> _______________________________________________
> Roundcube Development discussion mailing list
> dev at lists.roundcube.net
> http://lists.roundcube.net/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.roundcube.net/pipermail/dev/attachments/20150420/b55df34e/attachment.html>


More information about the dev mailing list