Joshi.Utils.Imap.Imap.SetFlag C# (CSharp) Method

SetFlag() public method

Store flag
public SetFlag ( string sUid, string flag, bool removeFlag = false ) : void
sUid string
flag string E.g \Deleted
removeFlag bool Remove the flaf
return void
        public void SetFlag(string sUid, string flag, bool removeFlag=false)
        {
            if (String.IsNullOrEmpty(sUid))
            {
                throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_INVALIDPARAM, "Invalid uid");
            }
            if (String.IsNullOrEmpty(flag))
            {
                throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_INVALIDPARAM, "Invalid flag");
            }
            ImapResponseEnum eImapResponse = ImapResponseEnum.IMAP_SUCCESS_RESPONSE;

            if (!m_bIsLoggedIn)
            {
                try
                {
                    Restore(false);
                }
                catch (ImapException e)
                {
                    if (e.Type != ImapException.ImapErrorEnum.IMAP_ERR_INSUFFICIENT_DATA)
                        throw e;

                    throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_NOTCONNECTED);
                }
            }
            if (!m_bIsFolderSelected && !m_bIsFolderExamined)
            {
                throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_NOTSELECTED);
            }

            ArrayList asResultArray = new ArrayList();
            string sCommand = IMAP_UIDSTORE_COMMAND;
            sCommand += " " + sUid + " " + (removeFlag?IMAP_REMOVEFLAGS_COMMAND:IMAP_SETFLAGS_COMMAND) + " " + flag + IMAP_COMMAND_EOL;
            try
            {
                eImapResponse = SendAndReceive(sCommand, ref asResultArray);
                if (eImapResponse != ImapResponseEnum.IMAP_SUCCESS_RESPONSE)
                {
                    throw new ImapException(ImapException.ImapErrorEnum.IMAP_ERR_SEARCH, asResultArray[0].ToString());
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }