Aby rozwiązać ten problem tak:
1.You może ograniczyć no wyniku zwrócony przez zmniejszenie no danych przy użyciu ponieważ kryteria 2. retreive kilka wiadomości e ostatni zwrócony.g 15
$this->msgCounts = imap_search($imap_resource, 'SUBJECT "hello dolly" SINCE "8 April 2003"', SE_UID);
I to tutaj jest przykładem dla retreive ostatnie 15 powrócił, a następnie przełączać się w przód iw tył, aby wyświetlić więcej wyników lub older.Note ten zakłada, że masz przycisk do przodu i starsze, które wyróżniają $ _GET zmienne.
$this->msgCounts = $messageCounts;
$multiarray=[];
\Session::put('totalmsg',$this->msgCounts); //Sav etotal no of message in folder to session to determine if to allow next or previous
if($this->msgCounts > 15) //MESSAGES IS MORE THAN WE NEED GET 20
{
$offcut = 15; //default offcut
/**
* Viewing previous or next messages
**/
if(isset($_GET['msgs']) && $_GET['msgs'] == 'older')
{
$this->msgCounts = \Cache::has('msgpointer') ? \Cache::get('msgpointer') : $this->msgCounts;
$msgOffset = $this->msgCounts - $offcut; //get +15 messages
if($offcut > $msgOffset) {
$msgOffset = $msgOffset + 5; //if less than 15 get 10
$offcut = 10;
}
if($offcut > $msgOffset) {
$msgOffset = $msgOffset + 5; //if less than 10 get 5
$offcut = 5;
}
if($offcut > $msgOffset) {
$msgOffset = $msgOffset + 3; //if less than 3 get 2
$offcut = 2;
}
if($offcut > $msgOffset) {
$msgOffset = $msgOffset + 2; //if less than 2 get 1
$offcut = 1;
}
\Cache::put('msgpointer',$msgOffset,60 * 60 * 24);
}
if(isset($_GET['msgs']) && $_GET['msgs'] == 'newest')
{
$this->msgCounts = \Cache::has('msgpointer') ? \Cache::get('msgpointer') : $this->msgCounts;
$msgOffset = $this->msgCounts + $offcut; //get +15 messages
if($msgOffset > $messageCounts) {
$msgOffset = $msgOffset - 5; //if not up to 15 get 10
$offcut = 10;
}
if($msgOffset > $messageCounts) {
$msgOffset = $msgOffset - 5; //if not up to 10 get 5
$offcut = 5;
}
if($msgOffset > $messageCounts) {
$msgOffset = $msgOffset - 3; //if not up to 5 get 2
$offcut = 2;
}
if($msgOffset > $messageCounts) {
$msgOffset = $msgOffset - 2; //if not up to 2 get 1
$offcut = 1;
}
\Cache::put('msgpointer',$msgOffset,60 * 60 * 24);
}
// LOOP THROUGH LAST 20 MESSAGES IF THERE MORE THAN 10 MESSAGES
for ($i = $this->msgCounts; $i > $this->msgCounts - $offcut; $i--)
{
$header = imap_header($this->conn,$i); //GET HEADER INFO USING IMAP FUNCTION
$uid = imap_uid($this->conn,$i); //GET UNIQUE MESSAGE ID FOR READING MESSAGE LATER
//SAVE ALL MESSAGE INFO IN ARRAY
$tobox = $header->reply_to[0]->mailbox ? $header->reply_to[0]->mailbox : 'noreply';
$tohost = $header->reply_to[0]->mailbox ? $header->reply_to[0]->host : 'email.com';
$toaddress = $tobox.'@'.$tohost;
$mailbox = isset($header->from[0]->mailbox) ? $header->from[0]->mailbox : 'no-reply';
$host = isset($header->from[0]->host) ? $header->from[0]->host : 'email.com';
$fromaddress = $mailbox.'@'.$host;
$array = ['toaddress' => isset($header->toaddress) ? $header->toaddress : isset($header->to) ? $header->to[0]->mailbox.'@'.$header->to[0]->host : $toaddress,'date' => isset($header->date) ? $header->date : date('Y-m-d'),'subject' => isset($header->subject) ? $header->subject : "no subject" ,'from' => isset($header->from[0]->personal) ? $header->from[0]->personal :$fromaddress,'unseen' => isset($header->Unseen) ? $header->Unseen : 'S', 'uid' => isset($uid) ? $uid : $i,'fromemail' => $fromaddress];
//PASS A MESSAGE INFO INTO A MULTI ARRAY
$multiarray[] = $array;
}
Można ustawić datę dostać od do 90 dni wcześniej, jeśli jego lot.return nim fragmencie przez fragmencie jak przeprosiny above.My korzystania istnieje kilka klas laravel pomocnik, wszystko jest dobrze wypowiedziało się. Mam nadzieję, że to pomoże komuś!
To zawęzi wyszukiwanie, ale czy to ograniczy liczbę wiadomości do zwrotu? –
@Anthony: to jedyny sposób, aby zawęzić to wszystko w inny sposób, o ile wiem. Czy jest jeden? – Sarfraz
Aby go zawęzić, jest to jedyny sposób. Ale jego kryteria to liczba limitów dla, jak zakładam, * wszystkich * wiadomości, których 'imap_search' nie dostarcza. Może być hack, zobacz moją edycję i daj mi znać, co myślisz. –