Summary description for Coding.
Example #1
0
        /// <summary>
        /// z 'ala="123"'
        /// </summary>
        /// <param name="key">ala=</param>
        /// <returns>123</returns>
        protected string GetValueEqualFromHeader2(string key)
        {
            bool noQuotes = false;
            int  end      = -1;
            int  start    = header.IndexOf(key);

            if (start == -1)
            {
                return("");
            }
            start = header.IndexOf('"', start);
            if (start == -1)
            {
                noQuotes = true;
                start    = header.IndexOf('=', header.IndexOf(key));
            }
            if (noQuotes)
            {
                end = header.IndexOf("\r\n", start + 1);
            }
            else
            {
                end = header.IndexOf('"', start + 1);
            }
            if (start == -1 || end == -1)
            {
                return("");
            }
            return(QuotedCoding.Decode(header.Substring(start + 1, end - start - 1)));
        }
Example #2
0
        public Attachment(string buffer) : base(buffer)
        {
            this.contentDisposition = this.GetValueFromHeader("Content-Disposition: ");
            this.fileName           = GetValueEqualFromHeader("name=");
            this.contentID          = GetValueFromHeader("Content-ID: ");

            if (contentDisposition.IndexOf("attachment") != -1)
            {
                this.fileName         = GetValueEqualFromHeader("filename=");
                this.isRealAttachment = true;
            }

            if (contentType.IndexOf("multipart") != -1)
            {
                string boundary = "--" + GetValueEqualFromHeader("boundary=");
                hasAttachments = true;
                ParseMixedMessage(buffer, boundary);
            }
            else
            {
                hasAttachments = false;

                //data
                int start = buffer.IndexOf("\r\n\r\n");
                if (start == -1)
                {
                    throw new Exception("could not find beginning of MIME body");
                }

                start += 4;
                if (this.contentTransferEncoding.ToLower().IndexOf("base64") != -1)
                {
                    this.data = Convert.FromBase64String(buffer.Substring(start));
                }
                else
                if (this.contentTransferEncoding.IndexOf("quoted-printable") != -1)
                {
                    this.data = QuotedCoding.GetByteArray(buffer.Substring(start));
                }
                else
                {
                    //change charset if contentTransferEncoding is 8bit
                    if (this.contentTransferEncoding.IndexOf("8bit") != -1)
                    {
                        this.data = StringOperations.GetByteArray(StringOperations.Change(buffer.Substring(start), charset));
                    }
                    else
                    {
                        this.data = StringOperations.GetByteArray(buffer.Substring(start));
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// z 'ala="123"'
        /// </summary>
        /// <param name="key">ala=</param>
        /// <returns>123</returns>
        protected string GetValueEqualFromHeader(string key)
        {
            int start = header.IndexOf(key);

            if (start == -1)
            {
                return("");
            }
            start = header.IndexOf('"', start);
            int end = header.IndexOf('"', start + 1);

            if (start == -1 || end == -1)
            {
                return("");
            }
            return(QuotedCoding.Decode(header.Substring(start + 1, end - start - 1)));
        }
Example #4
0
        protected string GetValueFromHeader(string key)
        {
            int start = header.ToLower().IndexOf(key.ToLower());

            if (start < 0)
            {
                return("");
            }
            start = header.IndexOf(' ', start);
            if (start < 0)
            {
                return("");
            }
            int end = header.IndexOf("\r\n", start);

            if (end <= 0)
            {
                return("");
            }
            return(QuotedCoding.Decode(header.Substring(start + 1, end - start - 1).Trim()));
        }