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 サーバーから別の 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 に答える