Skip to content
Advertisement

Laravel imap get messages sorted by most recent

I am using laravel-imap to retrieve messages from a mailbox:

JavaScript

On default the most recent messages are on the highest page. If I simply get all messages and display them as they are I see the old ones first (page 1).

What I tried so far:

After I call ->get() the results can be treated as a normal laravel collection, but I had no success with these methods:

JavaScript

I am sure the methods above do not work because I use ->limit(40, $highest_page), which means the collection has a size of 40.

If I dont limit the results and use slice I encounter a timeout error, because there are too many messages in the mailbox:

JavaScript

I also tried laravel-imap’s method paginate(). The results were the same as with limit().

At this point I am sure I have to sort somehow before the results turn into a collection. I also found:

JavaScript

The options are added to the Client. I tried asc and desc. I also cleared config cache, but nothing works.

I still see the oldest results on page 1 and the most recent at the end.

Someone has more ideas?

Advertisement

Answer

After playing around with several solutions I decided to go into the vendor file (config/imap.php) and change the fetch_order there:

JavaScript

It was asc on default. It seems that changing the fetch_order when creating the client does not override the config. I had this before and it did not work, also no errors were thrown:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement