MimeKit.MimeMessage.Load C# (CSharp) Method

Load() public static method

Load a MimeMessage from the specified stream.

Loads a MimeMessage from the given stream, using the specified ParserOptions.

If persistent is true and stream is seekable, then the MimeParser will not copy the content of MimeParts into memory. Instead, it will use a MimeKit.IO.BoundStream to reference a substream of stream. This has the potential to not only save mmeory usage, but also improve MimeParser performance.

/// is null. /// -or- /// is null. /// /// The operation was canceled via the cancellation token. /// /// There was an error parsing the entity. /// /// An I/O error occurred. ///
public static Load ( ParserOptions options, Stream stream, bool persistent, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
options ParserOptions The parser options.
stream Stream The stream.
persistent bool true if the stream is persistent; otherwise false.
cancellationToken System.Threading.CancellationToken A cancellation token.
return MimeMessage
		public static MimeMessage Load (ParserOptions options, Stream stream, bool persistent, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (options == null)
				throw new ArgumentNullException (nameof (options));

			if (stream == null)
				throw new ArgumentNullException (nameof (stream));

			var parser = new MimeParser (options, stream, MimeFormat.Entity, persistent);

			return parser.ParseMessage (cancellationToken);
		}

Same methods

MimeMessage::Load ( ParserOptions options, Stream stream, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
MimeMessage::Load ( ParserOptions options, string fileName, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
MimeMessage::Load ( Stream stream, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
MimeMessage::Load ( Stream stream, bool persistent, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage
MimeMessage::Load ( string fileName, CancellationToken cancellationToken = default(CancellationToken) ) : MimeMessage

Usage Example

Example #1
0
        MimeEntity CreateAttachment(ContentType contentType, string path, Stream stream)
        {
            var        fileName = GetFileName(path);
            MimeEntity attachment;

            if (contentType.IsMimeType("message", "rfc822"))
            {
                var message = MimeMessage.Load(stream);

                attachment = new MessagePart {
                    Message = message
                };
            }
            else
            {
                MimePart part;

                if (contentType.IsMimeType("text", "*"))
                {
                    // TODO: should we try to auto-detect charsets if no charset parameter is specified?
                    part = new TextPart(contentType);
                }
                else
                {
                    part = new MimePart(contentType);
                }

                LoadContent(part, stream);
                attachment = part;
            }

            attachment.ContentDisposition          = new ContentDisposition(linked ? ContentDisposition.Inline : ContentDisposition.Attachment);
            attachment.ContentDisposition.FileName = fileName;
            attachment.ContentType.Name            = fileName;

            if (linked)
            {
                attachment.ContentLocation = new Uri(fileName, UriKind.Relative);
            }

            return(attachment);
        }