java邮件:IMAP,重命名有孩子的文件夹
Posted
技术标签:
【中文标题】java邮件:IMAP,重命名有孩子的文件夹【英文标题】:java mail: IMAP, renaming a folder which has children 【发布时间】:2015-08-18 00:36:36 【问题描述】:我使用最新的 java 邮件 api。我想重命名包含子文件夹(子文件夹)的 IMAP 文件夹。假设我们有收件箱,并且收件箱有一个子文件夹 inbox.folder1。 folder1 有一个子文件夹,其全名是 inbox.folder1.subfolder1
我想将文件夹 1 重命名为文件夹 2,我希望看到:
inbox.folder2.subfolder1
但在代码之后
// folder instance corresponds to folder1
newFolder = folder.getFolder(newName); //newName = "folder2"
folder.renameTo(newFolder);
如果您使用 Outlook 或 Thunderbird 连接,我有
inbox.folder1.subfolder1
inbox.folder2
我们有两个文件夹,但我希望有一个。而且 subfolder1 仍然位于 folder1 中。并且你不能进入文件夹或子文件夹1,它们会产生错误信息:Reason Given: Mailbox does not exist, or must be subscribed.
我应该使用 setSubscripbed(true/false) 吗?我必须通过迭代每个子文件夹来分别处理子文件夹吗?
【问题讨论】:
这是特定于服务器的:但通常当您重命名文件夹时,它的所有子文件夹都应为其父级/重命名。发生这种情况时,您确实需要刷新或修复您拥有的任何文件夹名称缓存。在 Thunderbird 中,这通常意味着重新启动它。根据个人经验,雅虎在这方面存在实施问题。 当我使用 Outlook 和 Thunderbird 连接到邮件服务器时,重命名操作正确执行。只有当我尝试用 java 端重命名时,才会出现问题。据我了解,我必须照顾子文件夹和/或添加一些检查步骤,只有 folder.renameTo(folder) 不够? 当我尝试重命名没有子文件夹的文件夹时,该过程可以顺利完成。 【参考方案1】:我解决了。首先我打开了雷鸟的调试模式,如下所述:
https://wiki.mozilla.org/MailNews:Logging#Environment_Variables_to_set
然后我重命名了一个包含许多子文件夹的文件夹。
如您所见,您必须按照日志文件中指定的顺序调用以新名称订阅文件夹并以旧名称取消订阅。
无需调用订阅/取消订阅方法调用,您就可以在邮件服务器控制台中获得消息
68 OK 文件夹重命名。
但这还不够,您的文件夹结构已损坏。
9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 68 重命名“INBOX.folder1”“INBOX.folder2” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=23 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 68 OK 文件夹重命名。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 69 订阅 "INBOX.folder2" 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=26 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 69 OK 文件夹已订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 70 取消订阅“INBOX.folder1” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=28 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 70 OK 文件夹取消订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 71 订阅“INBOX.folder2.subfolder1.subsubfolder1.subsubsubfolder1b” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=26 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 71 OK 文件夹已订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 72 取消订阅 "INBOX.folder1.subfolder1.subsubfolder1.subsubsubfolder1b" 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=28 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 72 OK 文件夹取消订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 73 订阅 "INBOX.folder2.subfolder1.subsubfolder1.subsubsubfolder1a" 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=26 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 73 OK 文件夹已订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 74 取消订阅“INBOX.folder1.subfolder1.subsubfolder1.subsubsubfolder1a” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=28 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 74 OK 文件夹取消订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 75 订阅“INBOX.folder2.subfolder3.subsubfolder3” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=26 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 75 OK 文件夹已订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 76 取消订阅“INBOX.folder1.subfolder3.subsubfolder3” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=28 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 76 OK 文件夹取消订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 77 订阅“INBOX.folder2.subfolder3” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=26 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 77 OK 文件夹已订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 78 取消订阅“INBOX.folder1.subfolder3” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=28 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 78 OK 文件夹取消订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 79 订阅“INBOX.folder2.subfolder1.subsubfolder1” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=26 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 79 OK 文件夹已订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 80 取消订阅“INBOX.folder1.subfolder1.subsubfolder1” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=28 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 80 OK 文件夹取消订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 81 订阅“INBOX.folder2.subfolder2” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=26 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 81 OK 文件夹已订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 82 取消订阅“INBOX.folder1.subfolder2” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=28 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 82 OK 文件夹取消订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 83 订阅“INBOX.folder2.subfolder1” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=26 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 83 OK 文件夹已订阅。 9944[ab79a70]: 7cea000:192.168.0.104:A:SendData: 84 取消订阅“INBOX.folder1.subfolder1” 9944[ab79a70]:ReadNextLine [stream=a6db068 nb=28 needmore=0] 9944[ab79a70]: 7cea000:192.168.0.104:A:CreateNewLineFromSocket: 84 OK 文件夹取消订阅。
【讨论】:
以上是关于java邮件:IMAP,重命名有孩子的文件夹的主要内容,如果未能解决你的问题,请参考以下文章