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.

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

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行