Exemplo n.º 1
0
        public static void ConstructParts(StructureBuilder builder, MIME_Entity entity, bool includeExtensions)
        {
            var wordEncoder = new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.B, Encoding.UTF8);

            wordEncoder.Split = false;

            if (entity.Body is MIME_b_Multipart)
            {
                // Recursive build for multipart
                builder.StartBracket();

                foreach (MIME_Entity child in ((MIME_b_Multipart)entity.Body).BodyParts)
                {
                    ConstructParts(builder, child, includeExtensions);
                }

                if (entity.ContentType != null && entity.ContentType.SubType != null)
                {
                    builder.SpaceNQuoted(entity.ContentType.SubType.ToUpperInvariant());
                }
                else
                {
                    builder.AppendQuoted("PLAIN");
                }

                if (includeExtensions)
                {
                    // conentTypeParameters - Syntax: {("name" SP "value" *(SP "name" SP "value"))}
                    ConstructTypeParameters(builder, entity, wordEncoder);

                    // body disposition  Syntax: {(disposition-type [ SP ("name" SP "value" *(SP "name" SP "value"))])}
                    ConstructBodyDisposition(builder, entity, wordEncoder);

                    // body language
                    builder.AppendNil();

                    // body location
                    builder.AppendNil();
                }

                builder.Append(")");
            }
            else
            {
                ConstructSinglePart(builder, entity, wordEncoder, includeExtensions);
            }
        }
Exemplo n.º 2
0
        public static void ConstructSinglePart(StructureBuilder builder, MIME_Entity entity, MIME_Encoding_EncodedWord wordEncoder, bool includeExtensions)
        {
            builder.Append("(");

            // NOTE: all header fields and parameters must in ENCODED form !!!

            // Add contentTypeMainMediaType
            if (entity.ContentType != null && entity.ContentType.Type != null)
            {
                builder.AppendQuoted(entity.ContentType.Type.ToUpperInvariant());
            }
            else
            {
                builder.AppendQuoted("TEXT");
            }

            // Add contentTypeSubMediaType
            if (entity.ContentType != null && entity.ContentType.SubType != null)
            {
                builder.SpaceNQuoted(entity.ContentType.SubType.ToUpperInvariant());
            }
            else
            {
                builder.SpaceNQuoted("PLAIN");
            }

            // conentTypeParameters - Syntax: {("name" SP "value" *(SP "name" SP "value"))}
            ConstructTypeParameters(builder, entity, wordEncoder);

            // contentID
            string contentID = entity.ContentID;

            if (contentID != null)
            {
                builder.SpaceNQuoted(wordEncoder.Encode(contentID));
            }
            else
            {
                builder.AppendNil();
            }

            // contentDescription
            string contentDescription = entity.ContentDescription;

            if (contentDescription != null)
            {
                builder.SpaceNQuoted(wordEncoder.Encode(contentDescription));
            }
            else
            {
                builder.AppendNil();
            }

            // contentEncoding
            if (entity.ContentTransferEncoding != null)
            {
                builder.SpaceNQuoted(entity.ContentTransferEncoding.ToUpperInvariant());
            }
            else
            {
                // If not specified, then must be 7bit.
                builder.SpaceNQuoted("7bit");
            }

            // contentSize
            if (entity.Body is MIME_b_SinglepartBase)
            {
                builder.Append(" ").Append(((MIME_b_SinglepartBase)entity.Body).EncodedData.Length.ToString());
            }
            else
            {
                builder.Append(" 0");
            }

            // envelope --->FOR ContentType: message / rfc822 ONLY ###
            if (entity.Body is MIME_b_MessageRfc822)
            {
                builder.Append(" ");
                ENVELOPE.ConstructEnvelope(builder, ((MIME_b_MessageRfc822)entity.Body).Message);

                // BODYSTRUCTURE
                builder.AppendNil();

                // LINES
                builder.AppendNil();
            }

            // contentLines ---> FOR ContentType: text/xxx ONLY ###
            if (entity.Body is MIME_b_Text)
            {
                builder.Append(" ").Append(GetLines(entity).ToString());
            }


            #region BODYSTRUCTURE extention fields

            if (includeExtensions)
            {
                // body MD5
                builder.AppendNil();

                // body disposition  Syntax: {(disposition-type [ SP ("name" SP "value" *(SP "name" SP "value"))])}
                ConstructBodyDisposition(builder, entity, wordEncoder);

                // body language
                builder.AppendNil();

                // body location
                builder.AppendNil();
            }

            #endregion

            builder.EndBracket();
        }