Exemplo n.º 1
0
 public MimePart()
 {
     ContentDisposition = new ContentDisposition();
     ContentType = new ContentType();
     BinaryContent = new byte[0];
     HeaderFields = new NameValueCollection();
     HeaderFieldNames = new NameValueCollection();
     SubParts = new MimePartCollection();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the content disposition.
 /// </summary>
 /// <param name="input">The input.</param>
 /// <returns></returns>
 private static ContentDisposition GetContentDisposition(string input)
 {
     ContentDisposition field = new ContentDisposition();
     //TODO: include TAB detection in Regex
     field.Disposition = Regex.Match(input.Replace("\t", ""), @"(?<=: ?)\S+?(?=([;\s]|\Z))").Value;
     //TODO: include TAB detection in Regex
     System.Text.RegularExpressions.Match parammatch = System.Text.RegularExpressions.Regex.Match(input.Replace("\t", ""), @"(?<=;[ \t]?)[^;]*=[^;]*(?=(;|\Z))");
     for (; parammatch.Success; parammatch = parammatch.NextMatch()) field.Parameters.Add(FormatFieldName(parammatch.Value.Substring(0, parammatch.Value.IndexOf('='))), parammatch.Value.Substring(parammatch.Value.IndexOf('=') + 1).Replace("\"", "").Trim('\r', '\n'));
     return field;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the content disposition.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public static ContentDisposition GetContentDisposition(string input)
        {
            var field = new ContentDisposition();
            
            input = input.Replace("\t", "");

            field.Disposition = _regxMimeDisposition.Match(input).Value;

            var parammatch = _regxMimeDispositionParams.Match(input);
            
            for (; parammatch.Success; parammatch = parammatch.NextMatch()) 
                field.Parameters.Add(
                    FormatFieldName(
                    parammatch.Value.Substring(0, parammatch.Value.IndexOf('='))), 
                    parammatch.Value.Substring(parammatch.Value.IndexOf('=') + 1).Replace("\"", "").Trim('\r', '\n'));

            return field;
        }
Exemplo n.º 4
0
        /// <summary>
        /// The MIME representation of the header.
        /// </summary>
        /// <param name="removeBlindCopies">if set to <c>true</c> remove blind copies (BCC).</param>
        /// <param name="forceBase64Encoding">if set to <c>true</c> forces inner elements to be base64 encoded</param>
        /// <returns></returns>
        public string ToHeaderString(bool removeBlindCopies, bool forceBase64Encoding = false)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            /*foreach (TraceInfo trace in this.Trace) sb.AppendLine("Received: " + trace.ToString());
             * if (!this.From.Email.Equals(string.Empty)) sb.AppendLine("From: " + this.From.Merged);
             * if (!this.Sender.Email.Equals(string.Empty)) sb.AppendLine("Sender: " + this.Sender.Merged);
             * if (this.To.Count > 0) sb.AppendLine("To: " + this.To.Merged);
             * if (this.Cc.Count > 0) sb.AppendLine("Cc: " + this.Cc.Merged);
             * if (this.Bcc.Count > 0) sb.AppendLine("Bcc: " + this.Bcc.Merged);
             * if (!this.ReplyTo.Email.Equals(string.Empty)) sb.AppendLine("Reply-to: " + this.ReplyTo.Merged);*/

            foreach (TraceInfo trace in Trace)
            {
                AddHeaderField("Received", trace.ToString());
            }
            if (!From.Email.Equals(string.Empty))
            {
                AddHeaderField("From", From.Merged);
            }
            if (!Sender.Email.Equals(string.Empty))
            {
                AddHeaderField("Sender", Sender.Merged);
            }
            if (To.Count > 0)
            {
                AddHeaderField("To", To.Merged);
            }
            if (Cc.Count > 0)
            {
                AddHeaderField("Cc", Cc.Merged);
            }
            if (Bcc.Count > 0 && !removeBlindCopies)
            {
                AddHeaderField("Bcc", Bcc.Merged);
            }
            if (!ReplyTo.Email.Equals(string.Empty))
            {
                AddHeaderField("Reply-To", ReplyTo.Merged);
            }

            if (Date.Equals(DateTime.MinValue))
            {
                Date = DateTime.Now;
            }

            if (string.IsNullOrEmpty(MessageId))
            {
                MessageId = "<AU" + Codec.GetUniqueString() + "@" + System.Net.Dns.GetHostName() + ">";
            }

            if (ContentType.MimeType.Length > 0)
            {
                string contentType = ContentType.ToString();
                contentType = contentType.Substring(contentType.IndexOf(":") + 1).TrimStart(' ');
                AddHeaderField("Content-Type", contentType);
            }

            if (ContentDisposition.Disposition.Length > 0)
            {
                string contentDisposition = ContentDisposition.ToString();
                contentDisposition = contentDisposition.Substring(contentDisposition.IndexOf(":") + 1).TrimStart(' ');
                AddHeaderField("Content-Disposition", contentDisposition);
            }

            if (forceBase64Encoding)
            {
                AddHeaderField("Content-Transfer-Encoding", "base64");
            }
            else if (ContentType.Type.Equals("text"))
            {
                AddHeaderField("Content-Transfer-Encoding", "quoted-printable");
            }

            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            Version v = asm.GetName().Version;

            AddHeaderField("X-Mailer", "ActiveUp.MailSystem " + v.Major + "." + v.Minor + "." + v.Build + " www.activeup.com");

            foreach (string key in HeaderFields.AllKeys)
            {
                for (int i = 0; i < HeaderFields.GetValues(key).Length; i++)
                {
                    sb.Append(HeaderFieldNames.GetValues(key)[i] + ": " + HeaderFields.GetValues(key)[i] + "\r\n");
                }
            }
            return(sb.ToString().TrimEnd('\r', '\n'));
        }