/// <summary>
 /// Loads the message
 /// </summary>
 /// <param name="Input">string containing the message</param>
 public void LoadMessage(string Input)
 {
     _Content = Input;
     int HeaderEnd = Input.IndexOf("\r\n\r\n");
     Header = new MIMEHeader(Input.Substring(0, HeaderEnd + 2));
     Input = Input.Substring(HeaderEnd + 2);
     Body = new MIMEBody(Input, Header);
 }
        public MIMEBody(string Input,MIMEHeader Header)
        {
            if (string.IsNullOrEmpty(Input))
                throw new ArgumentNullException("Input");
            this.Boundries = new List<MIMEMessage>();
            MediaEnum ContentType;
            ContentType=GetMediaType(Header);
            if(MediaEnum.MEDIA_MULTIPART==ContentType)
            {
                string CurrentBoundry=GetBoundryMarker(Header);
                if (string.IsNullOrEmpty(CurrentBoundry))
                    return;
                CurrentBoundry = CurrentBoundry.Replace("\"", "");

                string BoundryStart = "--"+CurrentBoundry;
                string BoundryEnd = BoundryStart+"--";

                int StartIndex = Input.IndexOf(BoundryStart, 0, StringComparison.InvariantCulture);
                if (StartIndex == -1) return;
                int EndIndex = Input.IndexOf(BoundryEnd, 0, StringComparison.InvariantCulture);
                if (EndIndex == -1) EndIndex = Input.Length;

                Content = Input.Substring(0, StartIndex);
                while (StartIndex < EndIndex)
                {
                    StartIndex += BoundryStart.Length + 2;
                    if (StartIndex >= EndIndex)
                        break;
                    int TempIndex = Input.IndexOf(BoundryStart, StartIndex, StringComparison.InvariantCulture);
                    if (TempIndex != -1)
                    {
                        Boundries.Add(new MIMEMessage(Input.Substring(StartIndex, TempIndex - StartIndex)));
                    }
                    else
                        break;
                    StartIndex = TempIndex;
                }
            }
            else
            {
                Content = Input;
            }
            string Encoding = "";
            try
            {
                Encoding = Header[Constants.TransferEncoding].Attributes[0].Value;
            }
            catch
            {
                Encoding = Constants.Encoding7Bit;
            }
            Code CodeUsing = CodeManager.Instance[Encoding];
            CodeUsing.CharacterSet = Header[Constants.ContentType][Constants.Charset];
            string TempContent = "";
            CodeUsing.Decode(Content, out TempContent);
            Content = TempContent;
        }
        public void LoadMessage(string Input)
        {
            _Content = Input;
            int HeaderEnd = Input.IndexOf("\r\n\r\n", StringComparison.InvariantCulture);

            Header = new MIMEHeader(Input.Substring(0, HeaderEnd + 2));
            Input  = Input.Substring(HeaderEnd + 2);
            Body   = new MIMEBody(Input, Header);
        }
 /// <summary>
 /// Gets the media type for the body
 /// </summary>
 /// <param name="Header">The header of the message</param>
 /// <returns>An enum value indicating the media type of the boundary</returns>
 private MediaEnum GetMediaType(MIMEHeader Header)
 {
     string ContentType = GetContentType(Header);
     int x = 0;
     foreach (string TempType in MIMEType.TypeTable)
     {
         if (TempType.Equals(ContentType, StringComparison.InvariantCultureIgnoreCase))
         {
             return (MediaEnum)x;
         }
         ++x;
     }
     return (MediaEnum)MIMEType.TypeTable.Length - 1;
 }
Beispiel #5
0
 /// <summary>
 /// Gets the content type
 /// </summary>
 /// <param name="Header">Header of the message</param>
 /// <returns>A string containing the content type</returns>
 private string GetContentType(MIMEHeader Header)
 {
     if (Header != null && Header[Constants.ContentType] != null && Header[Constants.ContentType].Attributes.Count > 0)
     {
         string ContentType = Header[Constants.ContentType].Attributes[0].Value;
         if (null != ContentType)
         {
             int Index = ContentType.IndexOf('/', 0);
             if (Index != -1)
             {
                 return(ContentType.Substring(0, Index));
             }
             else
             {
                 return(ContentType);
             }
         }
     }
     return("text");
 }
 private static MediaEnum GetMediaType(MIMEHeader Header)
 {
     string ContentType = GetContentType(Header);
     int x=0;
     foreach (string TempType in MIMEType.TypeTable)
     {
         if (TempType.Equals(ContentType, StringComparison.InvariantCultureIgnoreCase))
         {
             return (MediaEnum)x;
         }
         ++x;
     }
     return (MediaEnum)MIMEType.TypeTable.Length - 1;
 }
 /// <summary>
 /// Gets the content type
 /// </summary>
 /// <param name="Header">Header of the message</param>
 /// <returns>A string containing the content type</returns>
 private static string GetContentType(MIMEHeader Header)
 {
     if (Header != null && Header[Constants.ContentType] != null && Header[Constants.ContentType].Attributes.Count > 0)
     {
         string ContentType = Header[Constants.ContentType].Attributes[0].Value;
         if (null != ContentType)
         {
             int Index = ContentType.IndexOf('/', 0);
             if (Index != -1)
             {
                 return ContentType.Substring(0, Index);
             }
             else
             {
                 return ContentType;
             }
         }
     }
     return "text";
 }
 /// <summary>
 /// Gets the boundary marker
 /// </summary>
 /// <param name="Header">Header of the message</param>
 /// <returns>A string containing the boundary marker</returns>
 private static string GetBoundryMarker(MIMEHeader Header)
 {
     return Header[Constants.ContentType][Constants.Boundary];
 }
Beispiel #9
0
 /// <summary>
 /// Loads the message
 /// </summary>
 /// <param name="Input">string containing the message</param>
 public void LoadMessage(string Input)
 {
     _Content = Input;
     int HeaderEnd = Input.IndexOf("\r\n\r\n");
     Header = new MIMEHeader(Input.Substring(0, HeaderEnd + 2));
     Input = Input.Substring(HeaderEnd + 2);
     Body = new MIMEBody(Input, Header);
 }
Beispiel #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Input">Body text</param>
        /// <param name="Header">Header of the message</param>
        public MIMEBody(string Input, MIMEHeader Header)
        {
            if (string.IsNullOrEmpty(Input))
            {
                throw new ArgumentNullException("Input can not be null");
            }
            MediaEnum ContentType;

            ContentType = GetMediaType(Header);
            if (MediaEnum.MEDIA_MULTIPART == ContentType)
            {
                string CurrentBoundry = GetBoundryMarker(Header);
                if (string.IsNullOrEmpty(CurrentBoundry))
                {
                    return;
                }
                CurrentBoundry = CurrentBoundry.Replace("\"", "");

                string BoundryStart = "--" + CurrentBoundry;
                string BoundryEnd   = BoundryStart + "--";

                int StartIndex = Input.IndexOf(BoundryStart, 0);
                if (StartIndex == -1)
                {
                    return;
                }
                int EndIndex = Input.IndexOf(BoundryEnd, 0);
                if (EndIndex == -1)
                {
                    EndIndex = Input.Length;
                }

                Content = Input.Substring(0, StartIndex);
                while (StartIndex < EndIndex)
                {
                    StartIndex += BoundryStart.Length + 2;
                    if (StartIndex >= EndIndex)
                    {
                        break;
                    }
                    int TempIndex = Input.IndexOf(BoundryStart, StartIndex);
                    if (TempIndex != -1)
                    {
                        Boundries.Add(new MIMEMessage(Input.Substring(StartIndex, TempIndex - StartIndex)));
                    }
                    else
                    {
                        break;
                    }
                    StartIndex = TempIndex;
                }
            }
            else
            {
                Content = Input;
            }
            string Encoding = "";

            try
            {
                Encoding = Header[Constants.TransferEncoding].Attributes[0].Value;
            }
            catch
            {
                Encoding = Constants.Encoding7Bit;
            }
            Code CodeUsing = CodeManager.Instance[Encoding];

            CodeUsing.CharacterSet = Header[Constants.ContentType][Constants.Charset];
            CodeUsing.Decode(Content, out _Content);
        }
Beispiel #11
0
 /// <summary>
 /// Gets the boundary marker
 /// </summary>
 /// <param name="Header">Header of the message</param>
 /// <returns>A string containing the boundary marker</returns>
 private string GetBoundryMarker(MIMEHeader Header)
 {
     return(Header[Constants.ContentType][Constants.Boundary]);
 }
 public void LoadMessage(string Input)
 {
     _Content = Input;
     int HeaderEnd = Input.IndexOf("\r\n\r\n", StringComparison.InvariantCulture);
     Header = new MIMEHeader(Input.Substring(0, HeaderEnd + 2));
     Input = Input.Substring(HeaderEnd + 2);
     Body = new MIMEBody(Input, Header);
 }