Re: imap sort localization in subject field

From: Date: Sun, 08 May 2005 15:45:06 +0000
Subject: Re: imap sort localization in subject field
Groups: php.i18n 
Request: Send a blank email to php-i18n+get-865@lists.php.net to get a copy of this message
Hello, We used MIME and NLS libraries in our previous code that are part of PEAR and Horde projects, and so our function was so specific. Here is the general (pure php) code for this function: function imap_locale_sort($stream,$criteria,$reverse,$locale,$options) { if ($criteria!=SORTSUBJECT) return (imap_sort($stream,$criteria,$reverse,$options)); $unsorted = array(); $sortresult = array(); $MC=imap_check($stream); $MN=$MC->Nmsgs; $overview = imap_fetch_overview($stream,"1:$MN",0); $k=0; while( list($key,$val) = each($overview)) { $unsorted[$k]["uid"]=$val->uid; $unsorted[$k]["subject"]=imap_utf8($val->subject); $k++; } usort ($unsorted, create_function('$a,$b','setlocale (LC_ALL,$locale);return strcoll($a["subject"],$b["subject"]);')); for ($m=0;$m<count($unsorted);$m++) array_push($sortresult,$unsorted[$m]["uid"]); if ($reverse) $sortresult = array_reverse($sortresult); return $sortresult; } Sample usage: $mbox = imap_open("{localhost:143}INBOX.sent-mail","usrname","password"); if ($mbox) echo ("Connection Successful!"); $sorted = imap_locale_sort($mbox,SORTSUBJECT,0,'fa_IR',0); print_r($sorted); print ("\n\n"); $sorted = imap_sort($mbox,SORTSUBJECT,SE_UID); print_r($sorted); imap_close($mbox); <persian-horde@metanetworking.com> wrote in message news:22680.213.217.50.221.1115505416.squirrel@www.metanetworking.com... > Hello all, > > imap_sort uses the c-client library to sort messages. This library > currently does not support locale-based sort for foreign languages > (Although it has charset option). > They are working on this(http://www.washington.edu/imap/IMAP-FAQs/#1.12), > but you can use the following function which uses strcoll() for locale- > based sorting.Pease note that this is required for SUBJECT field sorting, > because most of other fields are sorted correctly by imap_sort in any > locale: > Thanks persian-horde team

« previous php.i18n (#865) next »