1

我想为目标 IMAP 邮箱创建一个深层文件夹结构的镜像。直接创建子深层文件夹是非法的,所以我似乎需要以类似于以下方式创建它:添加 Imap 文件夹 Mailkit

我的 C# 是有限的,所以我试图弄清楚如何利用 'HasChildren' IMailFolder 属性循环遍历所有文件夹并在创建文件夹时保持对父文件夹的引用。

希望这是有道理的!

我这样做总是可以创建顶层,但我不知道如何构建逻辑:

var toplevel = ExchangeConnection.GetFolder(ExchangeConnection.PersonalNamespaces[0]);

string foldertocreate = UserSharedBox.FullName.Replace('.', '/').Replace((string.Format("{0}/{1}", "user", sharedmailbox)), "").Replace("/","");

var CreationFolder = toplevel.Create( foldertocreate,true);

谢谢

4

1 回答 1

0

将文件夹结构从一台 IMAP 服务器镜像到另一台的最简单方法可能是使用递归方法,如下所示:

public void Mirror (IMailFolder src, IMailFolder dest)
{
    // if the folder is selectable, mirror any messages that it contains
    if ((src.Attributes & (FolderAttributes.NoSelect | FolderAttributes.NonExistent)) == 0) {
        src.Open (FolderAccess.ReadOnly);

        // we fetch the flags and the internal date so that we can use these values in the APPEND command
        foreach (var item in src.Fetch (0, -1, MessageSummaryItems.Flags | MessageSummaryItems.InternalDate | MessageSummaryItems.UniqueId)) {
            var message = src.GetMessage (item.UniqueId);

            dest.Append (message, item.Flags.Value, item.InternalDate.Value); 
        }
    }

    // now mirror any subfolders that our current folder has
    foreach (var subfolder in src.GetSubfolders (false)) {
        // if the subfolder is selectable, that means it can contain messages
        var folder = dest.Create (subfolder.Name, (subfolder.Attributes & FolderAttributes.NoSelect) == 0);

        Mirror (subfolder, folder);
    }
}
于 2015-11-24T15:08:42.593 回答