dslkchyv673627 2015-09-16 17:45
浏览 380
已采纳

Golang IMAP:将邮件移动到另一个文件夹

I'm lost on where to look in the references to accomplish this; I've tried several iterations of code and each fails. Slightly edited, but enough to get the gist...

// Make connection
imConnection, err := imap.DialTLS(strAddress, nil)

// Defer disconnect
defer func(){
    imConnection.Logout(30*time.Second)
}

// Authenticate
imConnection.Login(strUname, strPass)

//Select the folder with messages I want to move
imConnection.Select(`[Gmail]\Movethese`, false)

// Create a set
set, _ = imap.NewSeqSet("1:*")

// It's my understanding that moving messages means copying them over, then
// deleting the original messages?
cmd, _ := imConnection.UIDCopy(set, `[Gmail]\Destination`)

This seems to silently fail. This to me looked like it should select everything in the "Movethese" folder and copy them to "Destination." What am I missing in properly copying them over? Is there a simple way to move individual messages that match a certain subject line string?

Also I wasn't sure if the source directory would have to be set to False for R/W when selected, but it doesn't seem to make a difference.

This is importing the github.com/mxk/go-imap/imap package

  • 写回答

1条回答 默认 最新

  • dongque8332 2015-09-17 13:00
    关注

    Try to add error checking to the two commands that name mailboxes; the backslash is a special character in source code so I expect gmail is giving you an error such as No such mailbox: [Gmail]Movethese.

    Handling errors is generally a good idea, particularly in cases such as this, when you know there is an error somewhere.

    BTW, the copy/delete sequence is a bit oldfashioned. Most IMAP servers support UID MOVE as an atomic command these days, and IIRC gmail is among the supporters. Can't check now, though, so don't trust me.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 游戏盾如何溯源服务器真实ip?
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥50 win10链接MySQL