Example #1
0
        /// <summary>
        /// Returns this as string.
        /// </summary>
        /// <param name="encode">If true, folder name is encoded with IMAP UTF-7 encoding.</param>
        /// <returns>Returns this as string.</returns>
        public string ToString(bool encode)
        {
            // Example:    S: * LSUB (\Noselect) "/" ~/Mail/foo

            StringBuilder retVal = new StringBuilder();

            retVal.Append("* LSUB (");
            if (m_pFolderAttributes != null)
            {
                for (int i = 0; i < m_pFolderAttributes.Length; i++)
                {
                    if (i > 0)
                    {
                        retVal.Append(" ");
                    }
                    retVal.Append(m_pFolderAttributes[i]);
                }
            }
            retVal.Append(") ");
            retVal.Append("\"" + m_Delimiter + "\" ");
            if (encode)
            {
                retVal.Append("\"" + IMAP_Utils.Encode_IMAP_UTF7_String(m_FolderName) + "\"\r\n");
            }
            else
            {
                retVal.Append("\"" + m_FolderName + "\"\r\n");
            }

            return(retVal.ToString());
        }
Example #2
0
        /// <summary>
        /// Encodes mailbox name.
        /// </summary>
        /// <param name="mailbox">Mailbox name.</param>
        /// <param name="encoding">Mailbox name encoding mechanism.</param>
        /// <returns>Renturns encoded mailbox name.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>mailbox</b> is null reference.</exception>
        public static string EncodeMailbox(string mailbox, IMAP_Mailbox_Encoding encoding)
        {
            if (mailbox == null)
            {
                throw new ArgumentNullException("mailbox");
            }

            /* RFC 6855 3.
             *  quoted        = DQUOTE *uQUOTED-CHAR DQUOTE
             *  uQUOTED-CHAR  = QUOTED-CHAR / UTF8-2 / UTF8-3 / UTF8-4
             */

            if (encoding == IMAP_Mailbox_Encoding.ImapUtf7)
            {
                return("\"" + IMAP_Utils.Encode_IMAP_UTF7_String(mailbox) + "\"");
            }
            else if (encoding == IMAP_Mailbox_Encoding.ImapUtf8)
            {
                return("\"" + mailbox + "\"");
            }
            else
            {
                return("\"" + mailbox + "\"");
            }
        }