I am using this IMAP Golang package to fetch recent emails from my gmail. I would like to only get the 50 most recent messages. My current approach is fetching every single email uid. I am using imap.gmail.com is there anyway to get the most recent messages, or the 50 highest UID's?
func getCode(findEmail string) (string, error) {
uids, err := im.GetUIDs("1:*")
if err != nil {
imapLock.RUnlock()
return "", err
}
if len(uids) > 50 {
uids = uids[len(uids)-50:]
}
emails, err := im.GetEmails(uids...)
if err != nil {
return "", err
}
for _, email := range emails {
// do something
}
}