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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!