【问题标题】:Mirroring IMAP folder structure to target using Mailkit使用 Mailkit 将 IMAP 文件夹结构镜像到目标
【发布时间】:2015-11-24 23:09:04
【问题描述】:

我想为目标 IMAP 邮箱创建一个深层文件夹结构的镜像。 直接创建子深层文件夹是违法的,所以看来我需要以类似的方式创建它:Add Imap Folder 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);

谢谢

【问题讨论】:

    标签: c# imap mailkit


    【解决方案1】:

    将文件夹结构从一台 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多