go imap: 错误的序列集值 “”

huangapple go评论150阅读模式
英文:

go imap: bad sequence set value ""

问题

我正在尝试按照IMAP示例进行操作,但是我遇到了这个错误imap: bad sequence set value "",对应于示例中的set, _ := imap.NewSeqSet("")这一行。这是库中的一个错误还是文档中的一个拼写错误?

我试图获取所有的消息,所以将序列设置为通配符(*)似乎也不起作用。我还尝试阅读RFC,但收效甚微。关于序列值,我只找到了以下内容:

seq-number      = nz-number / "*"
                    ; 消息序列号(COPY、FETCH、STORE命令)或唯一标识符(UID COPY、UID FETCH、UID STORE命令)。
                    ; * 表示正在使用的最大数字。对于消息序列号,它是非空邮箱中的消息数量。
                    ; 对于唯一标识符,它是邮箱中最后一条消息的唯一标识符,或者如果邮箱为空,则是邮箱的当前 UIDNEXT 值。
                    ; 如果命令使用大于所选邮箱中的消息数量的消息序列号,服务器应该以标记为 BAD 的响应进行响应。如果所选邮箱为空,则包括“*”。

seq-range       = seq-number ":" seq-number
                    ; 两个 seq-number 值及其之间的所有值,无论顺序如何。
                    ; 示例:2:4 和 4:2 是等价的,表示值 2、3 和 4。
                    ; 示例:3291:* 的唯一标识符序列范围包括邮箱中最后一条消息的 UID,即使该值小于 3291。

sequence-set    = (seq-number / seq-range) *("," sequence-set)
                    ; 无论顺序如何,seq-number 值的集合。
                    ; 服务器可以合并重叠并/或以任何顺序执行序列。
                    ; 示例:对于具有 15 条消息的邮箱,消息序列号集合 2,4:7,9,12:* 等价于 2,4,5,6,7,9,12,13,14,15。
                    ; 示例:对于具有 10 条消息的邮箱,消息序列号集合 *:4,5:7 等价于 10,9,8,7,6,5,4,5,6,7,并且可以重新排序和合并重叠为 4,5,6,7,8,9,10。

status          = "STATUS" SP mailbox SP
                  "(" status-att *(SP status-att) ")"
英文:

I'm trying to follow the IMAP example but I get this error imap: bad sequence set value "" which corresponds with the line set, _ := imap.NewSeqSet("") from the example. Is it a bug in the lib or a typo in the documentation ?

I'm trying to fetch all the messages so setting the sequence to wildcard ( * ) doesn't seem to work either. I've also tried to read RFC with little success. All I could find about the sequence values is this

seq-number      = nz-number / "*"
                    ; message sequence number (COPY, FETCH, STORE
                    ; commands) or unique identifier (UID COPY,
                    ; UID FETCH, UID STORE commands).
                    ; * represents the largest number in use.  In
                    ; the case of message sequence numbers, it is
                    ; the number of messages in a non-empty mailbox.
                    ; In the case of unique identifiers, it is the
                    ; unique identifier of the last message in the
                    ; mailbox or, if the mailbox is empty, the
                    ; mailbox's current UIDNEXT value.
                    ; The server should respond with a tagged BAD
                    ; response to a command that uses a message
                    ; sequence number greater than the number of
                    ; messages in the selected mailbox.  This
                    ; includes "*" if the selected mailbox is empty.

seq-range       = seq-number ":" seq-number
                    ; two seq-number values and all values between
                    ; these two regardless of order.
                    ; Example: 2:4 and 4:2 are equivalent and indicate
                    ; values 2, 3, and 4.
                    ; Example: a unique identifier sequence range of
                    ; 3291:* includes the UID of the last message in
                    ; the mailbox, even if that value is less than 3291.

sequence-set    = (seq-number / seq-range) *("," sequence-set)
                    ; set of seq-number values, regardless of order.
                    ; Servers MAY coalesce overlaps and/or execute the
                    ; sequence in any order.
                    ; Example: a message sequence number set of
                    ; 2,4:7,9,12:* for a mailbox with 15 messages is
                    ; equivalent to 2,4,5,6,7,9,12,13,14,15
                    ; Example: a message sequence number set of *:4,5:7
                    ; for a mailbox with 10 messages is equivalent to
                    ; 10,9,8,7,6,5,4,5,6,7 and MAY be reordered and
                    ; overlap coalesced to be 4,5,6,7,8,9,10.

status          = "STATUS" SP mailbox SP
                  "(" status-att *(SP status-att) ")"

答案1

得分: 2

以下是你要翻译的内容:

这是你要复制的代码。

// 获取最近10条消息的头部
set, _ := imap.NewSeqSet("")
if c.Mailbox.Messages >= 10 {
set.AddRange(c.Mailbox.Messages-9, c.Mailbox.Messages)
} else {
set.Add("1:*")
}
cmd, _ = c.Fetch(set, "RFC822.HEADER")

该代码将一个变量设置为"",但从未使用该值。它使用另一个值,该值取决于c.Mailbox对象的状态。

这里的教训是,仅仅复制文档中的一行代码是不够的,你需要看看周围的代码。

英文:

Here's the code you're copying from.

// Fetch the headers of the 10 most recent messages
set, _ := imap.NewSeqSet("")
if c.Mailbox.Messages >= 10 {
    set.AddRange(c.Mailbox.Messages-9, c.Mailbox.Messages)
} else {
    set.Add("1:*")
}
cmd, _ = c.Fetch(set, "RFC822.HEADER")

That code sets a variable to "" but never uses that value. It uses another value, which depends on the state of the c.Mailbox object.

The lesson here is that copying a single line from the documentation isn't enough, you need to look at the surroundings.

答案2

得分: -1

似乎在 Go 文档中有一个拼写错误。set, err := imap.NewSeqSet("1:*") 修复了这个问题。

英文:

It seems there is a typo in the Go doc. set, err := imap.NewSeqSet("1:*") fixes the issue.

huangapple
  • 本文由 发表于 2014年7月22日 16:07:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/24881981.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定