Beispiel #1
0
        /// <summary>
        /// Parses MYRIGHTS response from MYRIGHTS-response string.
        /// </summary>
        /// <param name="myRightsResponse">MYRIGHTS response line.</param>
        /// <returns>Returns parsed MYRIGHTS response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>myRightsResponse</b> is null reference.</exception>
        public static IMAP_r_u_MyRights Parse(string myRightsResponse)
        {
            if (myRightsResponse == null)
            {
                throw new ArgumentNullException("myRightsResponse");
            }

            /* RFC 4314 3.8. MYRIGHTS Response.
             *  Data:       mailbox name
             *              rights
             *
             *  The MYRIGHTS response occurs as a result of a MYRIGHTS command.  The
             *  first string is the mailbox name for which these rights apply.  The
             *  second string is the set of rights that the client has.
             *
             *  Section 2.1.1 details additional server requirements related to
             *  handling of the virtual "d" and "c" rights.
             *
             *  Example:    C: A003 MYRIGHTS INBOX
             *              S: * MYRIGHTS INBOX rwiptsldaex
             *              S: A003 OK Myrights complete
             */

            StringReader r = new StringReader(myRightsResponse);

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

            string folder = IMAP_Utils.Decode_IMAP_UTF7_String(r.ReadWord(true));
            string rights = r.ReadToEnd().Trim();

            return(new IMAP_r_u_MyRights(folder, rights));
        }
        /// <summary>
        /// Parses STATUS response from status-response string.
        /// </summary>
        /// <param name="response">Satatus response string.</param>
        /// <returns>Returns parsed STATUS response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>response</b> is null reference.</exception>
        public static IMAP_r_u_Status Parse(string response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            /* RFC 3501 7.2.4 STATUS Response.
             *  Contents:   name
             *              status parenthesized list
             *
             *  The STATUS response occurs as a result of an STATUS command.  It
             *  returns the mailbox name that matches the STATUS specification and
             *  the requested mailbox status information.
             *
             *  Example:    S: * STATUS blurdybloop (MESSAGES 231 UIDNEXT 44292)
             */

            StringReader r = new StringReader(response);

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

            int  messages  = 0;
            int  recent    = 0;
            long uidNext   = 0;
            long folderUid = 0;
            int  unseen    = 0;

            string folder = TextUtils.UnQuoteString(IMAP_Utils.Decode_IMAP_UTF7_String(r.ReadWord()));

            string[] items = r.ReadParenthesized().Split(' ');
            for (int i = 0; i < items.Length; i += 2)
            {
                if (items[i].Equals("MESSAGES", StringComparison.InvariantCultureIgnoreCase))
                {
                    messages = Convert.ToInt32(items[i + 1]);
                }
                else if (items[i].Equals("RECENT", StringComparison.InvariantCultureIgnoreCase))
                {
                    recent = Convert.ToInt32(items[i + 1]);
                }
                else if (items[i].Equals("UIDNEXT", StringComparison.InvariantCultureIgnoreCase))
                {
                    uidNext = Convert.ToInt64(items[i + 1]);
                }
                else if (items[i].Equals("UIDVALIDITY", StringComparison.InvariantCultureIgnoreCase))
                {
                    folderUid = Convert.ToInt64(items[i + 1]);
                }
                else if (items[i].Equals("UNSEEN", StringComparison.InvariantCultureIgnoreCase))
                {
                    unseen = Convert.ToInt32(items[i + 1]);
                }
            }

            return(new IMAP_r_u_Status(folder, messages, recent, uidNext, folderUid, unseen));
        }
        /// <summary>
        /// Parses LISTRIGHTS response from LISTRIGHTS-response string.
        /// </summary>
        /// <param name="listRightsResponse">LISTRIGHTS response line.</param>
        /// <returns>Returns parsed LISTRIGHTS response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>listRightsResponse</b> is null reference.</exception>
        public static IMAP_r_u_ListRights Parse(string listRightsResponse)
        {
            if (listRightsResponse == null)
            {
                throw new ArgumentNullException("listRightsResponse");
            }

            /* RFC 4314 3.7. LISTRIGHTS Response.
             *  Data:       mailbox name
             *              identifier
             *              required rights
             *              list of optional rights
             *
             *  The LISTRIGHTS response occurs as a result of a LISTRIGHTS command.
             *  The first two strings are the mailbox name and identifier for which
             *  this rights list applies.  Following the identifier is a string
             *  containing the (possibly empty) set of rights the identifier will
             *  always be granted in the mailbox.
             *
             *  Following this are zero or more strings each containing a set of
             *  rights the identifier can be granted in the mailbox.  Rights
             *  mentioned in the same string are tied together.  The server MUST
             *  either grant all tied rights to the identifier in the mailbox or
             *  grant none.  Section 2.1.1 details additional server requirements
             *  related to handling of the virtual "d" and "c" rights.
             *
             *  The same right MUST NOT be listed more than once in the LISTRIGHTS
             *  command.
             *
             *  Example:    C: a001 LISTRIGHTS ~/Mail/saved smith
             *              S: * LISTRIGHTS ~/Mail/saved smith la r swicdkxte
             *              S: a001 OK Listrights completed
             */

            StringReader r = new StringReader(listRightsResponse);

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

            string folder     = IMAP_Utils.Decode_IMAP_UTF7_String(r.ReadWord(true));
            string identifier = r.ReadWord(true);
            string reqRights  = r.ReadWord(true);
            string optRights  = r.ReadWord(true);

            return(new IMAP_r_u_ListRights(folder, identifier, reqRights, optRights));
        }
        /// <summary>
        /// Parses QUOTAROOT response from quotaRoot-response string.
        /// </summary>
        /// <param name="response">QUOTAROOT response string.</param>
        /// <returns>Returns parsed QUOTAROOT response.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>response</b> is null reference.</exception>
        public static IMAP_r_u_QuotaRoot Parse(string response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            /* RFC 2087 5.2. QUOTAROOT Response.
             *  Data:       mailbox name
             *              zero or more quota root names
             *
             *  This response occurs as a result of a GETQUOTAROOT command.  The
             *  first string is the mailbox and the remaining strings are the
             *  names of the quota roots for the mailbox.
             *
             *  Example:    S: * QUOTAROOT INBOX ""
             *              S: * QUOTAROOT comp.mail.mime
             */

            StringReader r = new StringReader(response);

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

            string        folderName = TextUtils.UnQuoteString(IMAP_Utils.Decode_IMAP_UTF7_String(r.ReadWord()));
            List <string> quotaRoots = new List <string>();

            while (r.Available > 0)
            {
                string quotaRoot = r.ReadWord();
                if (quotaRoot != null)
                {
                    quotaRoots.Add(quotaRoot);
                }
                else
                {
                    break;
                }
            }

            return(new IMAP_r_u_QuotaRoot(folderName, quotaRoots.ToArray()));
        }
Beispiel #5
0
        /// <summary>
        /// Parses ACL response from acl-response string.
        /// </summary>
        /// <param name="aclResponse">ACL response.</param>
        /// <returns>Returns parsed ACL response.</returns>
        /// <exception cref="ArgumentNullException">Is raised wehn <b>aclResponse</b> is null reference.</exception>
        public static IMAP_r_u_Acl Parse(string aclResponse)
        {
            if (aclResponse == null)
            {
                throw new ArgumentNullException("aclResponse");
            }

            /* RFC 4314 3.6. ACL Response.
             *  Data:       mailbox name
             *              zero or more identifier rights pairs
             *
             *  The ACL response occurs as a result of a GETACL command.  The first
             *  string is the mailbox name for which this ACL applies.  This is
             *  followed by zero or more pairs of strings; each pair contains the
             *  identifier for which the entry applies followed by the set of rights
             *  that the identifier has.
             *
             *  Example:    C: A002 GETACL INBOX
             *              S: * ACL INBOX Fred rwipsldexta
             *              S: A002 OK Getacl complete
             */

            StringReader r = new StringReader(aclResponse);

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

            string folderName = TextUtils.UnQuoteString(IMAP_Utils.Decode_IMAP_UTF7_String(r.ReadWord()));

            string[] items = r.ReadToEnd().Split(' ');
            List <IMAP_Acl_Entry> entries = new List <IMAP_Acl_Entry>();

            for (int i = 0; i < items.Length; i += 2)
            {
                entries.Add(new IMAP_Acl_Entry(items[i], items[i + 1]));
            }

            return(new IMAP_r_u_Acl(folderName, entries.ToArray()));
        }