使用 Mailkit 将 IMAP 文件夹结构镜像到目标
Mirroring IMAP folder structure to target using Mailkit
我想为目标 IMAP 邮箱创建深层文件夹结构的镜像。
直接创建子深层文件夹是非法的,所以我似乎需要以类似于这样的方式创建它:
我的 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);
谢谢
将文件夹结构从一个 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);
}
}
我想为目标 IMAP 邮箱创建深层文件夹结构的镜像。
直接创建子深层文件夹是非法的,所以我似乎需要以类似于这样的方式创建它:
我的 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);
谢谢
将文件夹结构从一个 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);
}
}