php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

Using limit i need order by date (not by id)

Open freddy1988 opened this issue 2 years ago • 1 comments

I am making

$messages = $folder->query()->all()->limit(6, 1)->setFetchOrder('desc')->get();

That order by ID but not by date;

But when a message was moved from other folder to currently folder, the message obtain a new ID then looks like a recent message when that is not true. In the example the first 2 messages are old but with new ID then they are in the top.

Example Output:

0 => array:8 [
    "id" => 25433
    "date" => Carbon\Carbon @1684227520 {#2208
      date: 2023-05-16 08:58:40.0 +00:00
    }
  ]
  1 => array:8 [
    "id" => 25432
    "date" => Carbon\Carbon @1681287830 {#2113
      date: 2023-04-12 04:23:50.0 -04:00
    }
  ]
  2 => array:8 [
    "id" => 25430
    "date" => Carbon\Carbon @1684331240 {#2032
      date: 2023-05-17 15:47:20.0 +02:00
    }
  ]
  3 => array:8 [
    "id" => 25418
    "date" => Carbon\Carbon @1684317137 {#1958
      date: 2023-05-17 11:52:17.0 +02:00
    }
  ]
  4 => array:8 [
    "id" => 25416
    "date" => Carbon\Carbon @1684316137 {#1884
      date: 2023-05-17 11:35:37.0 +02:00
    }
  ]
  5 => array:8 [
    "id" => 25414
    "date" => Carbon\Carbon @1684311561 {#1802
      date: 2023-05-17 01:19:21.0 -07:00
    }
  ]

freddy1988 avatar May 17 '23 16:05 freddy1988

Hi @freddy1988,

Thanks a lot for your question. Unfortunately, it's not possible to sort by date - at least not without fetching every message first, which would add a huge overhead. This is limited by the IMAP protocol itself. Sorting by anything else (except for the message number / uid) is not possible without fetching the messages first.

I know this is not the answer you were hoping for, but I hope this helps you to understand the issue.

Best regards and happy coding,

Webklex avatar Jun 23 '23 20:06 Webklex