Exemple #1
0
 /// <summary>
 /// Sets the type of the content.
 /// </summary>
 /// <param name="contentType">Type of the content.</param>
 internal void SetContentType(ContentType contentType)
 {
     _contentType           = contentType;
     _contentType.MediaType = MimeReader.GetMediaType(contentType.MediaType);
     _mediaMainType         = MimeReader.GetMediaMainType(contentType.MediaType);
     _mediaSubType          = MimeReader.GetMediaSubType(contentType.MediaType);
 }
Exemple #2
0
        /// <summary>
        /// Processes mime specific headers.
        /// </summary>
        /// <returns>A mime entity with mime specific headers parsed.</returns>
        private void ProcessHeaders()
        {
            foreach (string key in _entity.Headers.AllKeys)
            {
                switch (key)
                {
                case "content-description":
                    _entity.ContentDescription = _entity.Headers[key];
                    break;

                case "content-disposition":
                    _entity.ContentDisposition = new ContentDisposition(_entity.Headers[key]);
                    break;

                case "content-id":
                    _entity.ContentId = _entity.Headers[key];
                    break;

                case "content-transfer-encoding":
                    _entity.TransferEncoding        = _entity.Headers[key];
                    _entity.ContentTransferEncoding = MimeReader.GetTransferEncoding(_entity.Headers[key]);
                    break;

                case "content-type":
                    _entity.SetContentType(MimeReader.GetContentType(_entity.Headers[key]));
                    break;

                case "mime-version":
                    _entity.MimeVersion = _entity.Headers[key];
                    break;
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeEntity"/> class.
 /// </summary>
 public MimeEntity()
 {
     _children       = new List <MimeEntity>();
     _headers        = new NameValueCollection();
     _contentType    = MimeReader.GetContentType(string.Empty);
     _parent         = null;
     _encodedMessage = new StringBuilder();
 }
Exemple #4
0
        /// <summary>
        /// Adds the child entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        private void AddChildEntity(MimeEntity entity, Queue <string> lines)
        {
            /*if (entity == null)
             * {
             *              return;
             * }
             *
             * if (lines == null)
             * {
             *              return;
             * }*/

            MimeReader reader = new MimeReader(entity, lines);

            entity.Children.Add(reader.CreateMimeEntity());
        }
Exemple #5
0
		/// <summary>
		/// Adds the child entity.
		/// </summary>
		/// <param name="entity">The entity.</param>
		private void AddChildEntity(MimeEntity entity, Queue<string> lines)
		{
			/*if (entity == null)
			{
					return;
			}

			if (lines == null)
			{
					return;
			}*/

			MimeReader reader = new MimeReader(entity, lines);
			entity.Children.Add(reader.CreateMimeEntity());
		}
Exemple #6
0
		private static void DATA(Connection connection)
		{
			// Check command order
			if (connection.Session.Sender == null || connection.Session.MailFrom == null || connection.Session.Recipients.Count == 0)
			{
				connection.Send("503 Bad sequence of commands");
				return;
			}

			string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DateTime.Now.ToString("yyyyMMddHHmmssFF") + ".eml");

			try
			{
				var lines = new StringBuilder();

				using (var networkStream = new NetworkStream(connection.Client, false))
				using (var reader = new StreamReader(networkStream))
				{
					connection.Send("354 Start mail input; end with <CRLF>.<CRLF>").AsyncWaitHandle.WaitOne();
					string line;

					while ((line = reader.ReadLine()) != ".")
						lines.AppendLine(line);
				}

				var mimeReader = new MimeReader(lines.ToString().Replace("\r\n", "\n").Split('\n'));
				var entity = mimeReader.CreateMimeEntity();
				var message = entity.ToMailMessageEx();
				OnMessageReceived(connection, message);
			}
			catch(IOException e)
			{
				Logger.WriteWarning("IOException received in Processor.DATA while reading message.  Closing connection.  Message: " + e.Message, connection.ConnectionId);
				connection.Close();
				return;
			}

			connection.Send("250 OK");
		}