/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MimeEntity"/> class /// based on the <see cref="MimeEntityConstructorArgs"/>. /// </summary> /// <remarks> /// Custom <see cref="MimeEntity"/> subclasses MUST implement this constructor /// in order to register it using <see cref="ParserOptions.RegisterMimeType"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> protected MimeEntity (MimeEntityConstructorArgs args) { if (args == null) throw new ArgumentNullException (nameof (args)); Headers = new HeaderList (args.ParserOptions); ContentType = args.ContentType; ContentType.Changed += ContentTypeChanged; Headers.Changed += HeadersChanged; foreach (var header in args.Headers) { if (args.IsTopLevel && !header.Field.StartsWith ("Content-", StringComparison.OrdinalIgnoreCase)) continue; Headers.Add (header); } }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.TextPart"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public TextPart (MimeEntityConstructorArgs args) : base (args) { }
internal MimeEntity CreateEntity (ContentType contentType, IList<Header> headers, bool toplevel) { var args = new MimeEntityConstructorArgs (this, contentType, headers, toplevel); var subtype = contentType.MediaSubtype.ToLowerInvariant (); var type = contentType.MediaType.ToLowerInvariant (); if (mimeTypes.Count > 0) { var mimeType = string.Format ("{0}/{1}", type, subtype); ConstructorInfo ctor; if (mimeTypes.TryGetValue (mimeType, out ctor)) return (MimeEntity) ctor.Invoke (new object[] { args }); } // Note: message/rfc822 and message/partial are not allowed to be encoded according to rfc2046 // (sections 5.2.1 and 5.2.2, respectively). Since some broken clients will encode them anyway, // it is necessary for us to treat those as opaque blobs instead, and thus the parser should // parse them as normal MimeParts instead of MessageParts. // // Technically message/disposition-notification is only allowed to have use the 7bit encoding // as well, but since MessageDispositionNotification is a MImePart subclass rather than a // MessagePart subclass, it means that the content won't be parsed until later and so we can // actually handle that w/o any problems. if (type == "message") { switch (subtype) { case "disposition-notification": return new MessageDispositionNotification (args); case "delivery-status": return new MessageDeliveryStatus (args); case "partial": if (!IsEncoded (headers)) return new MessagePartial (args); break; case "external-body": case "rfc2822": case "rfc822": case "news": if (!IsEncoded (headers)) return new MessagePart (args); break; } } if (type == "multipart") { switch (subtype) { case "alternative": return new MultipartAlternative (args); case "related": return new MultipartRelated (args); case "report": return new MultipartReport (args); #if ENABLE_CRYPTO case "encrypted": return new MultipartEncrypted (args); case "signed": return new MultipartSigned (args); #endif default: return new Multipart (args); } } if (type == "application") { switch (subtype) { #if ENABLE_CRYPTO case "x-pkcs7-signature": case "pkcs7-signature": return new ApplicationPkcs7Signature (args); case "x-pgp-encrypted": case "pgp-encrypted": return new ApplicationPgpEncrypted (args); case "x-pgp-signature": case "pgp-signature": return new ApplicationPgpSignature (args); case "x-pkcs7-mime": case "pkcs7-mime": return new ApplicationPkcs7Mime (args); #endif case "vnd.ms-tnef": case "ms-tnef": return new TnefPart (args); case "rtf": return new TextPart (args); } } if (type == "text") return new TextPart (args); return new MimePart (args); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MessageDeliveryStatus"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MessageDeliveryStatus (MimeEntityConstructorArgs args) : base (args) { }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MultipartAlternative"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MultipartAlternative (MimeEntityConstructorArgs args) : base (args) { }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MessageDispositionNotification"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MessageDispositionNotification (MimeEntityConstructorArgs args) : base (args) { }
/// <summary> /// Initialize a new instance of the <see cref="TextRfc822Headers"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public TextRfc822Headers(MimeEntityConstructorArgs args) : base(args) { }
/// <summary> /// Initialize a new instance of the <see cref="MultipartReport"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MultipartReport(MimeEntityConstructorArgs args) : base(args) { }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Multipart"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public Multipart(MimeEntityConstructorArgs args) : base(args) { children = new List <MimeEntity> (); }
/// <summary> /// Initialize a new instance of the <see cref="MessagePartial"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MessagePartial(MimeEntityConstructorArgs args) : base(args) { }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MessageDeliveryStatus"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MessageDeliveryStatus(MimeEntityConstructorArgs args) : base(args) { }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MessageDispositionNotification"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MessageDispositionNotification(MimeEntityConstructorArgs args) : base(args) { }
internal MimeEntity CreateEntity(ContentType contentType, IList <Header> headers, bool toplevel) { var args = new MimeEntityConstructorArgs(this, contentType, headers, toplevel); var subtype = contentType.MediaSubtype.ToLowerInvariant(); var type = contentType.MediaType.ToLowerInvariant(); if (mimeTypes.Count > 0) { var mimeType = string.Format("{0}/{1}", type, subtype); ConstructorInfo ctor; if (mimeTypes.TryGetValue(mimeType, out ctor)) { return((MimeEntity)ctor.Invoke(new object[] { args })); } } // Note: message/rfc822 and message/partial are not allowed to be encoded according to rfc2046 // (sections 5.2.1 and 5.2.2, respectively). Since some broken clients will encode them anyway, // it is necessary for us to treat those as opaque blobs instead, and thus the parser should // parse them as normal MimeParts instead of MessageParts. // // Technically message/disposition-notification is only allowed to have use the 7bit encoding // as well, but since MessageDispositionNotification is a MImePart subclass rather than a // MessagePart subclass, it means that the content won't be parsed until later and so we can // actually handle that w/o any problems. if (type == "message") { switch (subtype) { case "disposition-notification": return(new MessageDispositionNotification(args)); case "delivery-status": return(new MessageDeliveryStatus(args)); case "partial": if (!IsEncoded(headers)) { return(new MessagePartial(args)); } break; case "external-body": case "rfc2822": case "rfc822": case "news": if (!IsEncoded(headers)) { return(new MessagePart(args)); } break; } } if (type == "multipart") { switch (subtype) { case "alternative": return(new MultipartAlternative(args)); case "related": return(new MultipartRelated(args)); case "report": return(new MultipartReport(args)); #if ENABLE_CRYPTO case "encrypted": return(new MultipartEncrypted(args)); case "signed": return(new MultipartSigned(args)); #endif default: return(new Multipart(args)); } } if (type == "application") { switch (subtype) { #if ENABLE_CRYPTO case "x-pkcs7-signature": case "pkcs7-signature": return(new ApplicationPkcs7Signature(args)); case "x-pgp-encrypted": case "pgp-encrypted": return(new ApplicationPgpEncrypted(args)); case "x-pgp-signature": case "pgp-signature": return(new ApplicationPgpSignature(args)); case "x-pkcs7-mime": case "pkcs7-mime": return(new ApplicationPkcs7Mime(args)); #endif case "vnd.ms-tnef": case "ms-tnef": return(new TnefPart(args)); case "rtf": return(new TextPart(args)); } } if (type == "text") { return(new TextPart(args)); } return(new MimePart(args)); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MultipartRelated"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MultipartRelated (MimeEntityConstructorArgs args) : base (args) { }
/// <summary> /// Initialize a new instance of the <see cref="MimePart"/> class /// based on the <see cref="MimeEntityConstructorArgs"/>. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MimePart(MimeEntityConstructorArgs args) : base(args) { }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MessagePart"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MessagePart (MimeEntityConstructorArgs args) : base (args) { }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.MultipartAlternative"/> class. /// </summary> /// <remarks> /// This constructor is used by <see cref="MimeKit.MimeParser"/>. /// </remarks> /// <param name="args">Information used by the constructor.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="args"/> is <c>null</c>. /// </exception> public MultipartAlternative(MimeEntityConstructorArgs args) : base(args) { }