Imap.SetMessageFlags Method (String, Boolean, String, MessageFlagAction, Boolean) |
Namespace: MailBee.ImapMail
public bool SetMessageFlags( string messageIndexSet, bool indexIsUid, string flags, MessageFlagAction action, bool silentMode )
Exception | Condition |
---|---|
MailBeeException | An error occurred and ThrowExceptions is true. |
To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes(String, Boolean) topic.
To clear flag list for certain message(s), call this method passing a null reference or empty string as flags value and Replace as action value.
MailBee ignores the FETCH response returned by the server when silentMode is false. If the application needs to process this data, the developer can use GetServerResponses(String) method to analyze the server response.
Another reason to set silentMode to false is to determine if the server really applied the specified flags by examining the log file (see the sample code below).
Other overloads of SetMessageFlags(String, Boolean, String, MessageFlagAction, Boolean) method set silentMode to true.
This sample replaces all flags of the last message in the inbox with the non-standard "$Spam" flag. Also demonstrates how to quickly check if the server really applied the specified flags using log file or console output.
Note |
---|
This sample may throw an exception or do nothing if the mail server forbids using non-standard message flags. Or, the server may set the flag in memory but discard the state change when the current session ends. See the sample in UploadMessage(MailMessage, String, String, String) topic on how to programmatically determine whether the server allows using non-standard flags. |
using System; using MailBee; using MailBee.ImapMail; class Sample { static void Main(string[] args) { Imap imp = new Imap(); // Set where to save log file. However, we do // not enable logging here. We'll enable it // later for a single moment of setting flags. imp.Log.Filename = @"C:\Temp\log.txt"; // Connect to the server, login and select inbox. imp.Connect("imap.somedomain.com"); imp.Login("jdoe", "secret"); imp.SelectFolder("INBOX"); if (imp.MessageCount > 0) { // Enable logging into a file to track // the status of setting flags. imp.Log.Enabled = true; // Replace all flags of the last message with "$Spam" flag. // The developer can then take a look at C:\Temp\log.txt file // to find out if untagged "* FETCH (FLAGS)" response to // STORE command contains "$Spam" element. If it does, the // server indeed applied this flag to the message. imp.SetMessageFlags(imp.MessageCount.ToString(), false, "$Spam", MessageFlagAction.Replace, false); // Disable logging again. Thus, the log file will be pretty // small, and the developer will be able to read it easily. imp.Log.Enabled = false; // Demonstrate alternative way of analyzing FETCH responses. string[] flagResponses = imp.GetServerResponses("FETCH"); foreach (string response in flagResponses) { Console.WriteLine(response); } } else { Console.WriteLine("The inbox is empty"); } // Disconnect from the server. imp.Disconnect(); } }