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
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
}
}
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
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
}
}
Share
Improve this question
asked Feb 21 at 5:07
Ahmed ZaidanAhmed Zaidan
711 gold badge9 silver badges24 bronze badges
1 Answer
Reset to default 2Modify your UID fetch range to "*" or use SORT if supported:
uids, err := im.GetUIDs("50:*") // Fetch last 50 UIDs
or
uids, err := im.GetSortedUIDs("REVERSE DATE", 50) // If sorting is supported
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745166625a4614672.html
评论列表(0条)