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

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

go imap: bad sequence set value ""

问题

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

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

  1. seq-number = nz-number / "*"
  2. ; 消息序列号(COPYFETCHSTORE命令)或唯一标识符(UID COPYUID FETCHUID STORE命令)。
  3. ; * 表示正在使用的最大数字。对于消息序列号,它是非空邮箱中的消息数量。
  4. ; 对于唯一标识符,它是邮箱中最后一条消息的唯一标识符,或者如果邮箱为空,则是邮箱的当前 UIDNEXT 值。
  5. ; 如果命令使用大于所选邮箱中的消息数量的消息序列号,服务器应该以标记为 BAD 的响应进行响应。如果所选邮箱为空,则包括“*”。
  6. seq-range = seq-number ":" seq-number
  7. ; 两个 seq-number 值及其之间的所有值,无论顺序如何。
  8. ; 示例:2:4 4:2 是等价的,表示值 23 4
  9. ; 示例:3291:* 的唯一标识符序列范围包括邮箱中最后一条消息的 UID,即使该值小于 3291
  10. sequence-set = (seq-number / seq-range) *("," sequence-set)
  11. ; 无论顺序如何,seq-number 值的集合。
  12. ; 服务器可以合并重叠并/或以任何顺序执行序列。
  13. ; 示例:对于具有 15 条消息的邮箱,消息序列号集合 2,4:7,9,12:* 等价于 2,4,5,6,7,9,12,13,14,15
  14. ; 示例:对于具有 10 条消息的邮箱,消息序列号集合 *:4,5:7 等价于 10,9,8,7,6,5,4,5,6,7,并且可以重新排序和合并重叠为 4,5,6,7,8,9,10
  15. status = "STATUS" SP mailbox SP
  16. "(" 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

  1. seq-number = nz-number / "*"
  2. ; message sequence number (COPY, FETCH, STORE
  3. ; commands) or unique identifier (UID COPY,
  4. ; UID FETCH, UID STORE commands).
  5. ; * represents the largest number in use. In
  6. ; the case of message sequence numbers, it is
  7. ; the number of messages in a non-empty mailbox.
  8. ; In the case of unique identifiers, it is the
  9. ; unique identifier of the last message in the
  10. ; mailbox or, if the mailbox is empty, the
  11. ; mailbox's current UIDNEXT value.
  12. ; The server should respond with a tagged BAD
  13. ; response to a command that uses a message
  14. ; sequence number greater than the number of
  15. ; messages in the selected mailbox. This
  16. ; includes "*" if the selected mailbox is empty.
  17. seq-range = seq-number ":" seq-number
  18. ; two seq-number values and all values between
  19. ; these two regardless of order.
  20. ; Example: 2:4 and 4:2 are equivalent and indicate
  21. ; values 2, 3, and 4.
  22. ; Example: a unique identifier sequence range of
  23. ; 3291:* includes the UID of the last message in
  24. ; the mailbox, even if that value is less than 3291.
  25. sequence-set = (seq-number / seq-range) *("," sequence-set)
  26. ; set of seq-number values, regardless of order.
  27. ; Servers MAY coalesce overlaps and/or execute the
  28. ; sequence in any order.
  29. ; Example: a message sequence number set of
  30. ; 2,4:7,9,12:* for a mailbox with 15 messages is
  31. ; equivalent to 2,4,5,6,7,9,12,13,14,15
  32. ; Example: a message sequence number set of *:4,5:7
  33. ; for a mailbox with 10 messages is equivalent to
  34. ; 10,9,8,7,6,5,4,5,6,7 and MAY be reordered and
  35. ; overlap coalesced to be 4,5,6,7,8,9,10.
  36. status = "STATUS" SP mailbox SP
  37. "(" 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.

  1. // Fetch the headers of the 10 most recent messages
  2. set, _ := imap.NewSeqSet("")
  3. if c.Mailbox.Messages >= 10 {
  4. set.AddRange(c.Mailbox.Messages-9, c.Mailbox.Messages)
  5. } else {
  6. set.Add("1:*")
  7. }
  8. 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:

确定