LumiSoft.Net.IMAP.Server.IMAP_Folders.Add C# (CSharp) Method

Add() public method

Adds folder to folders list.
public Add ( string folder, bool selectable ) : void
folder string Full path to folder, path separator = '/'. Eg. Inbox/myFolder .
selectable bool Gets or sets if folder is selectable(SELECT command can select this folder).
return void
        public void Add(string folder,bool selectable)
        {
            if(m_RefName.Length > 0){
                // Check if starts with reference name
                if(!folder.ToLower().StartsWith(m_RefName.ToLower())){
                    return;
                }
            }

            // !!! This row probably can be removed, regex below handles it.
            // REMOVE ME:
            // Eg. "INBOX", exact mailbox wanted.
            if(m_Mailbox.IndexOf("*") == -1 && m_Mailbox.IndexOf("%") == -1 && m_Mailbox.ToLower() != folder.ToLower()){
                return;
            }

            // Mailbox wildchar handling.
            // * - ALL
            // % - won't take sub folders, only current
            // * *mailbox* *mailbox% *mailbox mailbox* mailbox%

            // convert IMAP pattern into regex pattern
            // escape everything fishy, then convert * -> .* and % to [^/]* (ie anything other than a separator)
            string rePattern = "^" + m_RefName + Regex.Replace(m_Mailbox, "([^a-zA-Z0-9*% ])","\\$1").Replace("*", ".*").Replace("%","[^/]*") + "$";

            if(Regex.IsMatch(folder,rePattern,RegexOptions.IgnoreCase)){
                m_Mailboxes.Add(new IMAP_Folder(folder,selectable));
                return;
            }
        }

Usage Example

        private void IMAP_Server_GetSubscribedFolders(object sender, IMAP_Folders e)
        {
            IMAP_Session ses = (IMAP_Session)sender;

            string[] folders = m_pAPI.GetSubscribedFolders(ses.UserName);
            foreach(string folder in folders){
                e.Add(folder);
            }
        }
All Usage Examples Of LumiSoft.Net.IMAP.Server.IMAP_Folders::Add