6

MailSystem.NETを使用していて、サーバーからメッセージを削除しようとしています。問題は、IndexOnServer プロパティが 0 で、次のエラーが発生することです。

Command "store 0 +flags.silent (\Deleted)" failed : 121031084812790 BAD Error in IMAP command STORE: Invalid messageset

これが私のコードです:

    Imap4Client client = new Imap4Client();
    client.Connect(account.Server, account.Username, account.Password);
    var inbox = client.SelectMailbox("Inbox");
    MessageCollection messages = inbox.SearchParse("SINCE " + DateTime.Now.AddHours(-hours).ToString("dd-MMM-yyyy"));

    foreach (Message newMessage in messages)
    {
        inbox.DeleteMessage(newMessage.IndexOnServer, true);
    }

メッセージを削除できるように、メッセージの正しいインデックスを取得するにはどうすればよいですか?


編集:

標準の 1 ベースのループを使用した提案の問題は、カウンター インデックスがメッセージ インデックスと同期しないことです。これは、私の場合、メッセージの特定のサブセットのみを取得するために検索しているためです (私が理解しているように)。 .

ありがとうございました。

4

4 に答える 4

0

これはドキュメントからの公式の例です。inbox.search("all") の代わりに、検索クエリなどに変更します。

http://mailsystem.codeplex.com/discussions/269304

    //action_id is the Message.MessageId of the email
    //action_flag is the Gmail special folder to move to (Trash)
    //copying to Trash removes the email from the inbox, but it can't be moved back once done, even from the web interface
    public static void move_msg_to(string action_id, string action_flag)
    {
        Imap4Client imap = new Imap4Client();
        imap.ConnectSsl("imap.gmail.com", 993);
        imap.Login("heythatsme@gmail.com", "heythatsmypassword");

        imap.Command("capability");

        Mailbox inbox = imap.SelectMailbox("inbox");
        int[] ids = inbox.Search("ALL");
        if (ids.Length > 0)
        {
            Message msg = null;
            for (var i = 0; i < ids.Length; i++)
            {
                msg = inbox.Fetch.MessageObject(ids[i]);
                if (msg.MessageId == action_id)
                {
                    imap.Command("copy " + ids[i].ToString() + " [Gmail]/" + action_flag);
                    break;
                }
            }
        }
    }
于 2012-11-04T22:29:07.997 に答える