Exemplo n.º 1
0
        /// <summary>
        /// Parses LSUB response from lsub-response string.
        /// </summary>
        /// <param name="lSubResponse">LSub response string.</param>
        /// <returns>Returns parsed lsub response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>lSubResponse</b> is null reference.</exception>
        public static IMAP_r_u_LSub Parse(string lSubResponse)
        {
            if (lSubResponse == null)
            {
                throw new ArgumentNullException("lSubResponse");
            }

            /* RFC 3501 7.2.3. LSUB Response.
             *  Contents:   name attributes
             *              hierarchy delimiter
             *              name
             *
             *  The LSUB response occurs as a result of an LSUB command.  It
             *  returns a single name that matches the LSUB specification.  There
             *  can be multiple LSUB responses for a single LSUB command.  The
             *  data is identical in format to the LIST response.
             *
             *  Example:    S: * LSUB () "." #news.comp.mail.misc
             */

            StringReader r = new StringReader(lSubResponse);

            // Eat "*"
            r.ReadWord();
            // Eat "LSUB"
            r.ReadWord();

            string attributes = r.ReadParenthesized();
            string delimiter  = r.ReadWord();
            string folder     = TextUtils.UnQuoteString(IMAP_Utils.DecodeMailbox(r.ReadToEnd().Trim()));

            return(new IMAP_r_u_LSub(folder, delimiter[0], attributes == string.Empty ? new string[0] : attributes.Split(' ')));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses LIST response from list-response string.
        /// </summary>
        /// <param name="listResponse">List response string.</param>
        /// <returns>Returns parsed list response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>listResponse</b> is null reference.</exception>
        public static IMAP_r_u_List Parse(string listResponse)
        {
            if (listResponse == null)
            {
                throw new ArgumentNullException("listResponse");
            }

            /* RFC 3501 7.2.2. LIST Response.
             *  Contents:   name attributes
             *              hierarchy delimiter
             *              name
             *
             *  The LIST response occurs as a result of a LIST command.  It
             *  returns a single name that matches the LIST specification.  There
             *  can be multiple LIST responses for a single LIST command.
             *
             *  Four name attributes are defined:
             *
             *  \Noinferiors
             *      It is not possible for any child levels of hierarchy to exist
             *      under this name; no child levels exist now and none can be
             *      created in the future.
             *
             *  \Noselect
             *      It is not possible to use this name as a selectable mailbox.
             *
             *  \Marked
             *      The mailbox has been marked "interesting" by the server; the
             *      mailbox probably contains messages that have been added since
             *      the last time the mailbox was selected.
             *
             *  \Unmarked
             *      The mailbox does not contain any additional messages since the
             *      last time the mailbox was selected.
             *
             *  If it is not feasible for the server to determine whether or not
             *  the mailbox is "interesting", or if the name is a \Noselect name,
             *  the server SHOULD NOT send either \Marked or \Unmarked.
             *
             *  The hierarchy delimiter is a character used to delimit levels of
             *  hierarchy in a mailbox name.  A client can use it to create child
             *  mailboxes, and to search higher or lower levels of naming
             *  hierarchy.  All children of a top-level hierarchy node MUST use
             *  the same separator character.  A NIL hierarchy delimiter means
             *  that no hierarchy exists; the name is a "flat" name.
             *
             *  The name represents an unambiguous left-to-right hierarchy, and
             *  MUST be valid for use as a reference in LIST and LSUB commands.
             *  Unless \Noselect is indicated, the name MUST also be valid as an
             *  argument for commands, such as SELECT, that accept mailbox names.
             *
             *  Example:    S: * LIST (\Noselect) "/" ~/Mail/foo
             */

            StringReader r = new StringReader(listResponse);

            // Eat "*"
            r.ReadWord();
            // Eat "LIST"
            r.ReadWord();

            string attributes = r.ReadParenthesized();
            string delimiter  = r.ReadWord();
            string folder     = IMAP_Utils.DecodeMailbox(r.ReadToEnd().Trim());

            return(new IMAP_r_u_List(folder, delimiter[0], attributes == string.Empty ? new string[0] : attributes.Split(' ')));
        }