chadxz / imap-simple

Wrapper over node-imap, providing a simpler api for common use cases
MIT License
243 stars 80 forks source link

Sort mail by decending #68

Closed tecnodev closed 3 years ago

tecnodev commented 5 years ago

I'm fetching emails by offset. the results not ordered in DateTime. i tried sort()but it throws "Sort() not a function" .here my code

 var searchCriteria = [`${from}:${to}`];

                var fetchOptions = {
                  bodies: [""],
                  markSeen: false
                };

                let results = await connection.sort(['-ARRIVAL']
                  searchCriteria,
                  fetchOptions
                );
melitus commented 4 years ago

You can try this const searchCriteria = [`${flags}`, ["SINCE", `${from}`], ["BEFORE", `${to}`],["SUBJECT",`${subject}`]]

ghost commented 4 years ago

Or, you can parse your emails into structured data in an array, then sort them yourself.