コード例 #1
0
        public static void ConstructBodyDisposition(StructureBuilder builder, MIME_Entity entity, MIME_Encoding_EncodedWord wordEncoder)
        {
            if (entity.ContentDisposition != null && entity.ContentDisposition.Parameters.Count > 0)
            {
                builder.SpaceNBracket().AppendQuoted(entity.ContentDisposition.DispositionType.ToUpperInvariant());

                if (entity.ContentDisposition.Parameters.Count > 0)
                {
                    builder.SpaceNBracket();

                    bool first = true;
                    foreach (MIME_h_Parameter parameter in entity.ContentDisposition.Parameters)
                    {
                        if (String.IsNullOrEmpty(parameter.Name))
                        {
                            continue;
                        }

                        // For the first item, don't add SP.
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            builder.Append(" ");
                        }

                        builder.AppendQuoted(parameter.Name.ToUpperInvariant()).SpaceNQuoted(wordEncoder.Encode(parameter.Value));
                    }
                    builder.EndBracket();
                }
                else
                {
                    builder.AppendNil();
                }

                builder.EndBracket();
            }
            else
            {
                builder.AppendNil();
            }
        }
コード例 #2
0
ファイル: ENVELOPE.cs プロジェクト: xhute/Kooboo
        public static void ConstructAddresses(StructureBuilder builder, Mail_t_Mailbox[] mailboxes, MIME_Encoding_EncodedWord wordEncoder)
        {
            builder.StartBracket();

            foreach (Mail_t_Mailbox address in mailboxes)
            {
                ConstructAddress(builder, address, wordEncoder);
            }

            builder.EndBracket();
        }
コード例 #3
0
ファイル: ENVELOPE.cs プロジェクト: xhute/Kooboo
        public static void ConstructAddress(StructureBuilder builder, Mail_t_Mailbox address, MIME_Encoding_EncodedWord wordEncoder)
        {
            /* An address structure is a parenthesized list that describes an
             *             electronic mail address.  The fields of an address structure
             *             are in the following order: personal name, [SMTP]
             *             at-domain-list (source route), mailbox name, and host name.
             */

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

            builder.StartBracket();

            // personal name
            if (address.DisplayName != null)
            {
                builder.Append(TextUtils.QuoteString(wordEncoder.Encode(RemoveCrlf(address.DisplayName))));
            }
            else
            {
                builder.Append("NIL");
            }

            // source route, always NIL (not used nowdays)
            builder.AppendNil();

            // mailbox name
            builder.Append(" ").Append(TextUtils.QuoteString(wordEncoder.Encode(RemoveCrlf(address.LocalPart))));

            // host name
            if (address.Domain != null)
            {
                builder.Append(" ").Append(TextUtils.QuoteString(wordEncoder.Encode(RemoveCrlf(address.Domain))));
            }
            else
            {
                builder.AppendNil();
            }

            builder.EndBracket();
        }
コード例 #4
0
ファイル: ENVELOPE.cs プロジェクト: xhute/Kooboo
        public static void ConstructEnvelope(StructureBuilder builder, Mail_Message entity)
        {
            // date, subject, from, sender, reply-to, to, cc, bcc, in-reply-to, and message-id
            var wordEncoder = new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.B, Encoding.UTF8);

            wordEncoder.Split = false;

            builder.Append("ENVELOPE").SpaceNBracket();

            // date
            try
            {
                if (entity.Date != DateTime.MinValue)
                {
                    builder.Append(TextUtils.QuoteString(MIME_Utils.DateTimeToRfc2822(entity.Date)));
                }
                else
                {
                    builder.Append("NIL");
                }
            }
            catch
            {
                builder.Append("NIL");
            }

            // subject
            if (entity.Subject != null)
            {
                builder.Append(" " + TextUtils.QuoteString(wordEncoder.Encode(entity.Subject)));
                //string val = wordEncoder.Encode(entity.Subject);
                //builder.Append(" {").Append(val.Length).Append("}\r\n").Append(val);
            }
            else
            {
                builder.AppendNil();
            }

            // from
            if (entity.From != null && entity.From.Count > 0)
            {
                builder.Append(" ");
                ConstructAddresses(builder, entity.From.ToArray(), wordEncoder);
            }
            else
            {
                builder.AppendNil();
            }

            // sender
            //	NOTE: There is confusing part, according rfc 2822 Sender: is MailboxAddress and not AddressList.
            if (entity.Sender != null)
            {
                builder.SpaceNBracket();

                ConstructAddress(builder, entity.Sender, wordEncoder);

                builder.EndBracket();
            }
            else
            {
                builder.AppendNil();
            }

            // reply-to
            if (entity.ReplyTo != null)
            {
                builder.Append(" ");
                ConstructAddresses(builder, entity.ReplyTo.Mailboxes, wordEncoder);
            }
            else
            {
                builder.Append(" NIL");
            }

            // to
            if (entity.To != null && entity.To.Count > 0)
            {
                builder.Append(" ");
                ConstructAddresses(builder, entity.To.Mailboxes, wordEncoder);
            }
            else
            {
                builder.Append(" NIL");
            }

            // cc
            if (entity.Cc != null && entity.Cc.Count > 0)
            {
                builder.Append(" ");
                ConstructAddresses(builder, entity.Cc.Mailboxes, wordEncoder);
            }
            else
            {
                builder.AppendNil();
            }

            // bcc
            if (entity.Bcc != null && entity.Bcc.Count > 0)
            {
                builder.Append(" ");
                ConstructAddresses(builder, entity.Bcc.Mailboxes, wordEncoder);
            }
            else
            {
                builder.AppendNil();
            }

            // in-reply-to
            if (entity.InReplyTo != null)
            {
                builder.Append(" ").Append(TextUtils.QuoteString(wordEncoder.Encode(entity.InReplyTo)));
            }
            else
            {
                builder.AppendNil();
            }

            // message-id
            if (entity.MessageID != null)
            {
                builder.Append(" ").Append(TextUtils.QuoteString(wordEncoder.Encode(entity.MessageID)));
            }
            else
            {
                builder.AppendNil();
            }

            builder.EndBracket();
        }
コード例 #5
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();
        }