Example #1
0
        private static string ConstructNonMultiPart(MimeEntry ent,bool bodystructure)
        {
            string str =  "(";

            // contentType
            str += "\"" + ent.ContentType.Split('/')[0] + "\" ";

            // conentSubType
            if(ent.ContentType.Split('/').Length == 2){
                str += "\"" + ent.ContentType.Split('/')[1].Replace(";","") + "\" ";
            }
            else{
                str += "NIL ";
            }

            // conentTypeSubFields
            string longContentType = MimeParser.ParseHeaderField("Content-Type:",ent.Headers);
            if(longContentType.IndexOf(";") > -1){
                str += "(";
                string[] fields = longContentType.Split(';');
                for(int i=1;i<fields.Length;i++){
                    string[] nameValue = fields[i].Replace("\"","").Trim().Split(new char[]{'='},2);

                    str += "\"" + nameValue[0] + "\" \"" + nameValue[1] + "\"";

                    if(i < fields.Length - 1){
                        str += " ";
                    }
                }
                str += ") ";
            }
            else{
                // if content is attachment and content type name filed is missing, use filename for it
                string fileName = MimeParser.ParseHeaderFiledSubField("Content-Disposition:","filename",ent.Headers);
                if(fileName.Length > 0){
                    str += "(\"name\" \"" + fileName + "\") ";
                }
                else{
                    str += "NIL ";
                }
            }

            // contentID
            string contentID = MimeParser.ParseHeaderField("Content-ID:",ent.Headers);
            if(contentID.Length > 0){
                str += "\"" + contentID + "\" ";
            }
            else{
                str += "NIL ";
            }

            // contentDescription
            string contentDescription = MimeParser.ParseHeaderField("Content-Description:",ent.Headers);
            if(contentDescription.Length > 0){
                str += "\"" + contentDescription + "\" ";
            }
            else{
                str += "NIL ";
            }

            // contentEncoding
            str += "\"" + ent.ContentEncoding + "\" ";

            // contentSize
            str += ent.DataNonDecoded.Length + " ";

            // envelope NOTE: included only if contentType = "message" !!!

            // contentLines NOTE: included only if contentType = "text" !!!
            if(ent.ContentType.ToLower().IndexOf("text") > -1){
                StreamLineReader r = new StreamLineReader(new MemoryStream(ent.DataNonDecoded));
                int nLines = 0;
                byte[] line = new byte[0];
                while(line != null){
                    line = r.ReadLine();
                    nLines++;
                }
                str += nLines;
            }

            // Need to add extended fields
            if(bodystructure){
                str += " ";

                // md5
                str += "NIL ";

                // contentDisposition
                string contDispos = MimeParser.ParseHeaderField("Content-Disposition:",ent.Headers);
                if(contDispos.Length > 0){
                    str += "(";

                    string[] fields = contDispos.Split(';');

                    str += "\"" + fields[0] + "\" ";

                    if(fields.Length > 1){
                        str += "(";
                        for(int i=1;i<fields.Length;i++){
                            string[] nameValue = fields[i].Replace("\"","").Trim().Split(new char[]{'='},2);

                            str += "\"" + nameValue[0] + "\" \"" + nameValue[1] + "\"";

                            if(i < fields.Length - 1){
                                str += " ";
                            }
                        }
                        str += ")";
                    }
                    else{
                        str += "NIL";
                    }

                    str += ") ";
                }
                else{
                    str += "NIL ";
                }

                // contentLanguage
                str += "NIL";
            }

            str += ")";

            return str;
        }
Example #2
0
        private static string ConstructMultiPart(MimeEntry ent,bool bodystructure)
        {
            string str = "(";

            str += ConstructPart(ent.MimeEntries,bodystructure);

            str += " ";

            // conentSubType
            if(ent.ContentType.Split('/').Length == 2){
                str += "\"" + ent.ContentType.Split('/')[1].Replace(";","") + "\"";
            }
            else{
                str += "NIL";
            }

            // Need to add extended fields
            if(bodystructure){
                str += " ";

                // conentTypeSubFields
                string longContentType = MimeParser.ParseHeaderField("Content-Type:",ent.Headers);
                if(longContentType.IndexOf(";") > -1){
                    str += "(";
                    string[] fields = longContentType.Split(';');
                    for(int i=1;i<fields.Length;i++){
                        string[] nameValue = fields[i].Replace("\"","").Trim().Split(new char[]{'='},2);

                        str += "\"" + nameValue[0] + "\" \"" + nameValue[1] + "\"";

                        if(i < fields.Length - 1){
                            str += " ";
                        }
                    }
                    str += ") ";
                }

                // contentDisposition
                str += "NIL ";

                // contentLanguage
                str += "NIL";
            }

            str += ")";

            return str;
        }