MailBee.NET Objects 6.0

Imap.SetMessageFlags Method (String, Boolean, SystemMessageFlags, MessageFlagAction)

Sets or resets the specified flags for the specified messages in the currently selected folder.

public bool SetMessageFlags(
   string messageIndexSet,
   bool indexIsUid,
   SystemMessageFlags systemFlags,
   MessageFlagAction action
);

Parameters

messageIndexSet
A message sequence string containing ordinal message numbers or UIDs. Can be composed manually or using ToString.
indexIsUid
If true, messageIndexSet is treated as a sequence of UIDs; otherwise, as a sequence of ordinal message numbers.
systemFlags
A set of flags to be set or reset.
action
The action to perform with the specified flags (set, reset, etc).

Return Value

true if the message flags have been updated successfully; otherwise, false.

Remarks

To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes topic.

Exceptions

Exception Type Condition
MailBeeException An error occurred and ThrowExceptions is true.

Example

This sample undeletes all messages marked as deleted in the inbox folder.

[C#]
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Connect("imap4.server.com");
        imp.Login("jdoe@server.com", "secret");
        imp.SelectFolder("INBOX");

        // Get UIDs of deleted messages. We could have also skipped this
        // stage and just tell the server to remove \Deleted flag for
        // all messages (even for those message which do not have this
        // flag set - such messages won't be affected). We call Search()
        // method and then consume its results in SetMessageFlags() just
        // for purposes of illustration.
        UidCollection uids = (UidCollection)imp.Search(true, "DELETED", null);

        if (uids.Count > 0)
        {
            // Remove \Deleted flag from the deleted messages.
            imp.SetMessageFlags(uids.ToString(), true,
                SystemMessageFlags.Deleted, MessageFlagAction.Remove);
        }

        // Disconnect from the server.
        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main(ByVal args As String())
        Dim imp As New Imap

        ' Connect to the server, login and select inbox.
        imp.Connect("imap4.server.com")
        imp.Login("jdoe@server.com", "secret")
        imp.SelectFolder("INBOX")

        ' Get UIDs of deleted messages. We could have also skipped this
        ' stage and just tell the server to remove \Deleted flag for
        ' all messages (even for those message which do not have this
        ' flag set - such messages won't be affected). We call Search()
        ' method and then consume its results in SetMessageFlags() just
        ' for purposes of illustration.
        Dim uids As UidCollection = CType(imp.Search(True, "DELETED", Nothing), UidCollection)

        If uids.Count > 0 Then
            ' Remove \Deleted flag from the deleted messages.
            imp.SetMessageFlags(uids.ToString(), True, SystemMessageFlags.Deleted, MessageFlagAction.Remove)
        End If

        ' Disconnect from the server.
        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | Imap.SetMessageFlags Overload List