public static bool TryAsASCIIAString(string pString, out cCommandPart rResult)
        {
            if (pString == null)
            {
                rResult = null; return(false);
            }

            cTextCommandPart lText;

            if (ZTryAsBytesInCharset(pString, cCharset.AString, false, out lText))
            {
                rResult = lText; return(true);
            }
            if (ZTryAsQuotedASCII(pString, false, out lText))
            {
                rResult = lText; return(true);
            }

            if (TryAsASCIILiteral(pString, false, out var lLiteral))
            {
                rResult = lLiteral; return(true);
            }

            rResult = null;
            return(false);
        }
 public void BeginList(eListBracketing pBracketing, cCommandPart pPrefix = null, cCommandPart pPostfix = null)
 {
     if (mList != null)
     {
         mLists.Push(mList);
     }
     mList = new cList(pBracketing, pPrefix, pPostfix);
 }
 public void Add(cCommandPart pPart)
 {
     if (mAddCount != 0)
     {
         mParts.Add(cCommandPart.Space);
     }
     mParts.Add(pPart);
     mAddCount++;
 }
 public cList(eListBracketing pBracketing, cCommandPart pPrefix, cCommandPart pPostix)
 {
     Bracketing = pBracketing;
     Prefix     = pPrefix;
     Postfix    = pPostix;
     mParts     = new List <cCommandPart>();
     mAddCount  = 0;
     Parts      = new ReadOnlyCollection <cCommandPart>(mParts);
 }
                public void Add(cCommandPart pPart)
                {
                    if (mList == null)
                    {
                        mParts.Add(pPart);
                        return;
                    }

                    mList.Add(pPart);
                }
 public bool TryAsMailbox(string pMailboxPath, char?pDelimiter, out cCommandPart rCommandPart, out string rEncodedMailboxPath)
 {
     if (pMailboxPath == null)
     {
         rCommandPart = null; rEncodedMailboxPath = null; return(false);
     }
     if (pDelimiter != null && !cTools.IsValidDelimiter(pDelimiter.Value))
     {
         rCommandPart = null; rEncodedMailboxPath = null; return(false);
     }
     return(ZTryAsMailbox(pMailboxPath, pDelimiter, cCharset.AString, out rCommandPart, out rEncodedMailboxPath));
 }
 public bool TryAsListMailbox(string pString, char?pDelimiter, out cCommandPart rResult)
 {
     if (pString == null)
     {
         rResult = null; return(false);
     }
     if (pDelimiter != null && !cTools.IsValidDelimiter(pDelimiter.Value))
     {
         rResult = null; return(false);
     }
     return(ZTryAsMailbox(pString, pDelimiter, cCharset.ListMailbox, out rResult, out _));
 }
        public bool TryAsAString(string pString, bool pSecret, out cCommandPart rResult)
        {
            if (pString == null)
            {
                rResult = null; return(false);
            }

            bool                lResult;
            cTextCommandPart    lText;
            cLiteralCommandPart lLiteral;

            if (ZTryAsBytesInCharset(pString, cCharset.AString, pSecret, out lText))
            {
                rResult = lText; return(true);
            }
            if (ZTryAsQuotedASCII(pString, pSecret, out lText))
            {
                rResult = lText; return(true);
            }
            if (TryAsASCIILiteral(pString, pSecret, out lLiteral))
            {
                rResult = lLiteral; return(true);
            }

            if (UTF8Enabled)
            {
                lResult = ZTryAsQuotedUTF8(pString, pSecret, out lText);
                rResult = lText;
                return(lResult);
            }

            if (Encoding == null)
            {
                rResult = null; return(false);
            }

            var lBytes = Encoding.GetBytes(pString);

            if (ZTryAsBytesInCharset(lBytes, cCharset.AString, pSecret, true, out lText))
            {
                rResult = lText; return(true);
            }
            if (ZTryAsQuotedASCII(lBytes, pSecret, true, out lText))
            {
                rResult = lText; return(true);
            }

            lResult = ZTryAsLiteral(lBytes, pSecret, true, out lLiteral);
            rResult = lLiteral;
            return(lResult);
        }
 public static bool TryAsASCIIString(string pString, out cCommandPart rResult)
 {
     if (pString == null)
     {
         rResult = null; return(false);
     }
     if (ZTryAsQuotedASCII(pString, false, out var lText))
     {
         rResult = lText; return(true);
     }
     if (TryAsASCIILiteral(pString, false, out var lLiteral))
     {
         rResult = lLiteral; return(true);
     }
     rResult = null;
     return(false);
 }
Beispiel #10
0
        public bool TryAsNString(string pString, bool pSecret, out cCommandPart rResult)
        {
            if (pString == null)
            {
                if (pSecret)
                {
                    rResult = cCommandPart.NilSecret;
                }
                else
                {
                    rResult = cCommandPart.Nil;
                }
                return(true);
            }

            return(TryAsString(pString, pSecret, out rResult));
        }
Beispiel #11
0
        private bool ZTryAsMailbox(string pString, char?pDelimiter, cCharset pCharset, out cCommandPart rCommandPart, out string rEncodedMailboxPath)
        {
            if (pString.Equals(cMailboxName.InboxString, StringComparison.InvariantCultureIgnoreCase))
            {
                rCommandPart        = cCommandPart.Inbox;
                rEncodedMailboxPath = cMailboxName.InboxString;
            }

            cTextCommandPart    lText;
            cLiteralCommandPart lLiteral;

            if (ZTryAsBytesInCharset(pString, pCharset, false, out lText))
            {
                rCommandPart        = lText;
                rEncodedMailboxPath = pString;
                return(true);
            }

            if (UTF8Enabled)
            {
                if (ZTryAsQuotedUTF8(pString, false, out lText))
                {
                    rCommandPart        = lText;
                    rEncodedMailboxPath = pString;
                    return(true);
                }

                rCommandPart        = null;
                rEncodedMailboxPath = null;
                return(false);
            }

            cByteList lBytes;

            if (pDelimiter == null)
            {
                lBytes = cModifiedUTF7.Encode(pString);
            }
            else
            {
                char lDelimiterChar = pDelimiter.Value;
                byte lDelimiterByte = (byte)lDelimiterChar;

                string[] lSegments = pString.Split(lDelimiterChar);

                lBytes = new cByteList();
                bool lFirst = true;

                foreach (string lSegment in lSegments)
                {
                    if (lFirst)
                    {
                        lFirst = false;
                    }
                    else
                    {
                        lBytes.Add(lDelimiterByte);
                    }
                    lBytes.AddRange(cModifiedUTF7.Encode(lSegment));
                }
            }

            if (ZTryAsBytesInCharset(lBytes, pCharset, false, false, out lText) || ZTryAsQuotedASCII(lBytes, false, false, out lText))
            {
                rCommandPart        = lText;
                rEncodedMailboxPath = cTools.ASCIIBytesToString(lBytes);
                return(true);
            }

            if (ZTryAsASCIILiteral(lBytes, false, out lLiteral))
            {
                rCommandPart        = lLiteral;
                rEncodedMailboxPath = cTools.ASCIIBytesToString(lBytes);
                return(true);
            }

            rCommandPart        = null;
            rEncodedMailboxPath = null;
            return(false);
        }