Lesnikowski.Pawel.Mail.Pop3.Attachment.Attachment C# (CSharp) Method

Attachment() public method

public Attachment ( string buffer ) : System
buffer string
return System
        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));
                }
            }
        }