imap_sort
(PHP 4, PHP 5)
imap_sort — Gets and sort messages
Описание
array imap_sort
( resource
$imap_stream
, int $criteria
, int $reverse
[, int $options
= 0
[, string $search_criteria
= NULL
[, string $charset
= NIL
]]] )Gets and sorts message numbers by the given parameters.
Список параметров
-
imap_stream
-
Поток IMAP, полученный из imap_open().
-
criteria
-
Criteria can be one (and only one) of the following:
-
SORTDATE
- message Date -
SORTARRIVAL
- arrival date -
SORTFROM
- mailbox in first From address -
SORTSUBJECT
- message subject -
SORTTO
- mailbox in first To address -
SORTCC
- mailbox in first cc address -
SORTSIZE
- size of message in octets
-
-
reverse
-
Set this to 1 for reverse sorting
-
options
-
The
options
are a bitmask of one or more of the following:-
SE_UID
- Return UIDs instead of sequence numbers -
SE_NOPREFETCH
- Don't prefetch searched messages
-
-
search_criteria
-
-
charset
-
Возвращаемые значения
Returns an array of message numbers sorted by the given parameters.
Список изменений
Версия | Описание |
---|---|
4.3.3 |
The charset parameter was added
|
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с почтой
- IMAP, POP3 и NNTP
- imap_8bit
- imap_alerts
- imap_append
- imap_base64
- imap_binary
- imap_body
- imap_bodystruct
- imap_check
- imap_clearflag_full
- imap_close
- imap_create
- imap_createmailbox
- imap_delete
- imap_deletemailbox
- imap_errors
- imap_expunge
- imap_fetch_overview
- imap_fetchbody
- imap_fetchheader
- imap_fetchmime
- imap_fetchstructure
- imap_fetchtext
- imap_gc
- imap_get_quota
- imap_get_quotaroot
- imap_getacl
- imap_getmailboxes
- imap_getsubscribed
- imap_header
- imap_headerinfo
- imap_headers
- imap_last_error
- imap_list
- imap_listmailbox
- imap_listscan
- imap_listsubscribed
- imap_lsub
- imap_mail_compose
- imap_mail_copy
- imap_mail_move
- imap_mail
- imap_mailboxmsginfo
- imap_mime_header_decode
- imap_msgno
- imap_num_msg
- imap_num_recent
- imap_open
- imap_ping
- imap_qprint
- imap_rename
- imap_renamemailbox
- imap_reopen
- imap_rfc822_parse_adrlist
- imap_rfc822_parse_headers
- imap_rfc822_write_address
- imap_savebody
- imap_scan
- imap_scanmailbox
- imap_search
- imap_set_quota
- imap_setacl
- imap_setflag_full
- imap_sort
- imap_status
- imap_subscribe
- imap_thread
- imap_timeout
- imap_uid
- imap_undelete
- imap_unsubscribe
- imap_utf7_decode
- imap_utf7_encode
- imap_utf8
Коментарии
I worked a lot with IMAP functions since I wrote a complete webmail and I've got a little tip about the imap_sort function :
There is a big difference between :
<?php
imap_sort($imap, SORTDATE, 1);
// and
imap_sort($imap, SORTARRIVAL, 1);
?>
The first command will issue a
>> FETCH 1:last (UID ENVELOPE BODY.PEEK[HEADER.FIELDS (Newsgroups Content-MD5 Content-Disposition Content-Language Content-Location Followup-To References)] INTERNALDATE RFC822.SIZE FLAGS)
While the second resulted in
>> FETCH 1:last (UID INTERNALDATE RFC822.SIZE FLAGS)
As a result, using SORTDATE took 3 seconds longer to complete on a 800-emails mailbox, while the results are quite the same (except if you have to deal with forged dates or timezones, but the arrival order is far more logical)
My advice if you sort your emails by arrival is to actually use SORTARRIVAL, or better don't use imap_sort and go straight with message numbers (not UIDs). On large mailboxes, if you display messages per page, you will have significant performance increases (by avoiding 5 seconds of sorting).