简体   繁体   English

如何搜索所有未读邮件IMAP CMD / go

[英]How to search ALL Unread messages IMAP CMD / go

I'm developing an email client and for some reasons the IMAP server doesn't send me back all the unread messages. 我正在开发电子邮件客户端,由于某些原因,IMAP服务器不会将所有未读邮件发送回我。 Out of 2915 emails it sends back only 2888. I've tried to mark them as read/unread consecutively and it seems that the "Read" command works and marks them all read, unread works too but when I search for unread messages I get don't get 27 of them. 在2915封电子邮件中,它仅发送回2888。我试图将它们连续地标记为已读/未读,并且似乎“已读”命令也可以将它们都标记为已读,未读,但是当我搜索未读邮件时,我得到了不要得到其中的27个。

Any hint as to why that happens? 有什么暗示为什么会发生吗? I suspect there is an IMAP glitch. 我怀疑存在IMAP故障。

Some code 一些代码

const (
    //serch
    SearchUnseen = "UNSEEN"
    SearchSeen   = "SEEN"
    SearchALL    = "ALL"
)
const (
    FlagSeen   = `\Seen`
    FlagUnseen = `\Unseen`
)

const (
    //flag types
    FlagSet    = "+FLAGS"
    FlagRemove = "-FLAGS"
)

type Request struct {
    Label string //label: INBOX, Sent
    Attr  string //attr: RFC822.HEADER , []BODY if is Fetch
    //OR "ALL", "UNSEEN" if is SEARCH
    //http://tools.ietf.org/html/rfc3501#section-6.4.4
    SqID string //sequences 1:44 , 1:*, 1,2,3 (UID)
}

cmd, err = c.UIDSearch(set, r.Attr)



cmd, err := imap.Wait(c.UIDStore(set, flagAction, imap.NewFlagSet(flag)))
    if err != nil {
        log.Error(err)
        return
    }

You're doing some really weird things and you should read how Imap and the lib work. 您正在做一些非常奇怪的事情,应该阅读Imap和lib的工作方式。

To sum up. 总结一下。

You have to select your mailbox depending on what you will want to achieve. 您必须根据要实现的目的来选择邮箱。 If you want to only download email select it as read only. 如果只想下载电子邮件,请选择只读。 If you want to update some emails(seen, deleted) select it as writable. 如果要更新某些电子邮件(已看到,已删除),请选择可写。 See my answer here . 在这里查看我的答案。

If you want to download a list of UIDS, simply use UIDSearch with only one arg specifying the range you want to get. 如果要下载UIDS列表,只需将UIDSearch与仅一个arg一起使用UIDSearch指定要获取的范围。 You can use UIDSearch("1:*") 您可以使用UIDSearch("1:*")

If you want to get the UIDs of the unread emails: UIDSearch("1:* NOT SEEN") 如果要获取未读电子邮件的UID,请执行以下操作: UIDSearch("1:* NOT SEEN")

UIDSearch does NOT care about Attr since it will only get UIDS and not bodys. UIDSearch并不关心Attr因为它只会获取UIDS而不是正文。

If you want the body, use UIDFetch and give it a *imap.SeqSet with the differents attributes you want to get. 如果需要主体,请使用UIDFetch并为其提供*imap.SeqSet其中包含要获取的differents属性。 Example: UIDFetch(set, "RFC822.HEADER", "UID") 示例: UIDFetch(set, "RFC822.HEADER", "UID")

To sum up, read the documentation or browse the code with sourceGraph (really awesome) 总而言之,请阅读文档或使用sourceGraph浏览代码(真棒)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM