static byte[] EncodeContentType(ParserOptions options, FormatOptions format, Encoding charset, string field, string value) { var contentType = ContentType.Parse(options, value); var encoded = contentType.Encode(format, charset); return(Encoding.UTF8.GetBytes(encoded)); }
private static MimePart GetMimePart(AttachmentBase item) { var mimeType = item.ContentType.ToString(); var contentType = ContentType.Parse(mimeType); var attachment = item as Attachment; var part = new MimePart(contentType); // if (attachment != null) { var disposition = attachment.ContentDisposition.ToString(); part.ContentDisposition = ContentDisposition.Parse(disposition); } // Adjust the transfer encoding switch (item.TransferEncoding) { case TransferEncoding.QuotedPrintable: part.ContentTransferEncoding = ContentEncoding.QuotedPrintable; break; case TransferEncoding.Base64: part.ContentTransferEncoding = ContentEncoding.Base64; break; case TransferEncoding.SevenBit: part.ContentTransferEncoding = ContentEncoding.SevenBit; break; case TransferEncoding.EightBit: part.ContentTransferEncoding = ContentEncoding.EightBit; break; case TransferEncoding.Unknown: break; default: throw new ArgumentOutOfRangeException(); } // Adjust the attachment content identifier if (item.ContentId != null) { part.ContentId = item.ContentId; } // Copy the content of the attachment var stream = new MemoryBlockStream(); item.ContentStream.CopyTo(stream); stream.Position = 0; part.Content = new MimeContent(stream); // Done return(part); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MimePart"/> class /// with the specified content type. /// </summary> /// <remarks> /// Creates a new <see cref="MimePart"/> with the specified Content-Type value. /// </remarks> /// <param name="contentType">The content type.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="contentType"/> is <c>null</c>. /// </exception> /// <exception cref="MimeKit.ParseException"> /// <paramref name="contentType"/> could not be parsed. /// </exception> public MimePart(string contentType) : base(ContentType.Parse(contentType)) { }
static ContentType GetMimeType(string fileName) { var mimeType = MimeTypes.GetMimeType(fileName); return(ContentType.Parse(mimeType)); }