// Token: 0x0600022B RID: 555 RVA: 0x000098F4 File Offset: 0x00007AF4 public Header FindFirst(HeaderId headerId) { if (headerId < HeaderId.Unknown || headerId > (HeaderId)MimeData.nameIndex.Length) { throw new ArgumentException(Strings.InvalidHeaderId, "headerId"); } if (this.headerMap[(int)headerId] == 0) { return(null); } Header header = base.FirstChild as Header; int num = 0; while (header != null) { if (headerId == header.HeaderId) { return(header); } num++; this.CheckLoopCount(num); header = (header.NextSibling as Header); } this.headerMap[(int)headerId] = 0; return(null); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Header"/> class. /// </summary> /// <remarks> /// Creates a new message or entity header for the specified field and /// value pair. The encoding is used to determine which charset to use /// when encoding the value according to the rules of rfc2047. /// </remarks> /// <param name="charset">The charset that should be used to encode the /// header value.</param> /// <param name="id">The header identifier.</param> /// <param name="value">The value of the header.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="charset"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="value"/> is <c>null</c>.</para> /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>. /// </exception> /// <exception cref="System.ArgumentException"> /// <paramref name="charset"/> cannot be empty. /// </exception> /// <exception cref="System.NotSupportedException"> /// <paramref name="charset"/> is not supported. /// </exception> public Header(string charset, HeaderId id, string value) { if (charset == null) { throw new ArgumentNullException("charset"); } if (charset.Length == 0) { throw new ArgumentException("The charset name cannot be empty.", "charset"); } if (id == HeaderId.Unknown) { throw new ArgumentOutOfRangeException("id"); } if (value == null) { throw new ArgumentNullException("value"); } var encoding = CharsetUtils.GetEncoding(charset); Options = ParserOptions.Default.Clone(); Field = id.ToHeaderName(); Id = id; SetValue(encoding, value); }
public RCFileItem GetStringResourceByName(string aStringResourceName) { if (!HeaderContent.NameToID.ContainsKey(aStringResourceName)) { return(null); } var currentResourceID = new HeaderId(HeaderContent.NameToID[aStringResourceName]); if (IDValidator.IsRecurrentCase(currentResourceID, HeaderContent)) { IDNormalizer.NormalizeRecurrenceForID(currentResourceID, HeaderContent); } if (IDValidator.IsHexaRepresentation(currentResourceID)) { IDNormalizer.NormalizeHexaID(currentResourceID); } if (!IDValidator.IsValid(currentResourceID, HeaderContent)) { return(null); } return(mRCFileContent.GetStringLineForName(aStringResourceName, currentResourceID)); }
public void WriteHeader(HeaderId headerId, string value) { this.AssertOpen(); this.StartHeader(headerId); this.WriteHeaderValue(value); this.FlushHeader(); }
internal static Type TypeFromHeaderId(HeaderId headerId) { switch (MimeData.headerNames[(int)MimeData.nameIndex[(int)headerId]].headerType) { case HeaderType.AsciiText: return(typeof(AsciiTextHeader)); case HeaderType.Date: return(typeof(DateHeader)); case HeaderType.Received: return(typeof(ReceivedHeader)); case HeaderType.ContentType: return(typeof(ContentTypeHeader)); case HeaderType.ContentDisposition: return(typeof(ContentDispositionHeader)); case HeaderType.Address: return(typeof(AddressHeader)); default: return(typeof(TextHeader)); } }
internal Header(ParserOptions options, HeaderId id, string field, byte[] value) { Options = options; rawValue = value; Field = field; Id = id; }
/// <summary> /// Converts the enum value into the equivalent header field name. /// </summary> /// <remarks> /// Converts the enum value into the equivalent header field name. /// </remarks> /// <returns>The header name.</returns> /// <param name="value">The enum value.</param> public static string ToHeaderName(this HeaderId value) { var name = value.ToString(); #if NETSTANDARD1_3 || NETSTANDARD1_6 var field = typeof(HeaderId).GetTypeInfo().GetDeclaredField(name); var attrs = field.GetCustomAttributes(typeof(HeaderNameAttribute), false).ToArray(); #else var field = typeof(HeaderId).GetField(name); var attrs = field.GetCustomAttributes(typeof(HeaderNameAttribute), false); #endif if (attrs != null && attrs.Length == 1) { return(((HeaderNameAttribute)attrs[0]).HeaderName); } var builder = new StringBuilder(name); for (int i = 1; i < builder.Length; i++) { if (char.IsUpper(builder[i])) { builder.Insert(i++, '-'); } } return(builder.ToString()); }
// Token: 0x0600022F RID: 559 RVA: 0x00009B88 File Offset: 0x00007D88 public void RemoveAll(HeaderId headerId) { Header header = this.FindFirst(headerId); if (header != null) { if (this.headerMap[(int)headerId] == 1) { base.RemoveChild(header); return; } int num = 0; do { Header header2 = header.NextSibling as Header; num++; this.CheckLoopCount(num); if (header.HeaderId == headerId) { base.RemoveChild(header); } header = header2; }while (header != null); this.headerMap[(int)headerId] = 0; } }
// Token: 0x0600022A RID: 554 RVA: 0x0000988C File Offset: 0x00007A8C public Header FindFirst(string name) { if (name != null) { HeaderId headerId = Header.GetHeaderId(name, false); if (headerId != HeaderId.Unknown) { return(this.FindFirst(headerId)); } if (this.headerMap[(int)headerId] == 0) { return(null); } Header header = base.FirstChild as Header; int num = 0; while (header != null) { if (header.IsName(name)) { return(header); } num++; this.CheckLoopCount(num); header = (header.NextSibling as Header); } } return(null); }
void IMimeHandlerInternal.HeaderStart(HeaderId headerId, string name, out HeaderParseOptionInternal headerParseOption) { HeaderParseOption headerParseOption2; this.handler.HeaderStart(headerId, name, out headerParseOption2); headerParseOption = (HeaderParseOptionInternal)headerParseOption2; }
// Token: 0x06000238 RID: 568 RVA: 0x00009D80 File Offset: 0x00007F80 internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild) { Header header = newChild as Header; if (header == null) { throw new ArgumentException(Strings.NewChildNotMimeHeader, "newChild"); } HeaderId headerId = header.HeaderId; if (Header.IsRestrictedHeader(headerId)) { if (this.headerMap[(int)headerId] != 0) { Header header2 = this.FindFirst(headerId); if (header2 == refChild) { refChild = header2.PreviousSibling; } base.InternalRemoveChild(header2); } byte[] array = this.headerMap; HeaderId headerId2 = headerId; array[(int)headerId2] = array[(int)headerId2] + 1; } else if (this.headerMap[(int)headerId] != 255) { byte[] array2 = this.headerMap; HeaderId headerId3 = headerId; array2[(int)headerId3] = array2[(int)headerId3] + 1; } return(refChild); }
// Token: 0x0600026C RID: 620 RVA: 0x0000DC0C File Offset: 0x0000BE0C public HeaderNameDef(int hash, string name, HeaderType headerType, HeaderId publicHeaderId, bool restricted) { this.hash = (byte)hash; this.restricted = restricted; this.headerType = headerType; this.name = name; this.publicHeaderId = publicHeaderId; }
// Token: 0x0600022D RID: 557 RVA: 0x00009A18 File Offset: 0x00007C18 public Header[] FindAll(HeaderId headerId) { Header header = this.FindFirst(headerId); if (header == null) { return(new Header[0]); } int num = (int)this.headerMap[(int)headerId]; Header header2; int num2; if (num == 255) { header2 = header; num = 1; num2 = 0; for (;;) { header2 = (header2.NextSibling as Header); if (header2 == null) { break; } num2++; this.CheckLoopCount(num2); if (headerId == header2.HeaderId) { num++; } } if (num < 255) { this.headerMap[(int)headerId] = (byte)num; } } Header[] array = new Header[num]; header2 = header; array[0] = header2; num2 = 0; int i = 1; while (i < num) { header2 = (header2.NextSibling as Header); num2++; this.CheckLoopCount(num2); if (header2 == null) { break; } if (headerId == header2.HeaderId) { array[i++] = header2; } } return(array); }
/// <summary> /// Parses a string header to its corresponding enum value. Only needed for .NET 3.5 since it is natively supported in 4.0 and above. /// </summary> /// <param name="strEnumValue">The string value of the enum field</param> /// <param name="defaultValue"></param> /// <returns></returns> public static bool TryParseHeader(string strEnumValue, out HeaderId parsedHeaderId) { parsedHeaderId = HeaderId.Unknown; if (!Enum.IsDefined(typeof(HeaderId), strEnumValue)) return false; parsedHeaderId = (HeaderId) Enum.Parse(typeof (HeaderId), strEnumValue); return true; }
/// <summary> /// Checks if the <see cref="MimeKit.HeaderList"/> contains a header with the specified field name. /// </summary> /// <remarks> /// Determines whether or not the header list contains the specified header. /// </remarks> /// <returns><value>true</value> if the requested header exists; /// otherwise <value>false</value>.</returns> /// <param name="id">The header identifier.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>. /// </exception> public bool Contains(HeaderId id) { if (id == HeaderId.Unknown) { throw new ArgumentOutOfRangeException("id"); } return(table.ContainsKey(id.ToHeaderName())); }
/// <summary> /// Inserts a header with the specified field and value at the given index. /// </summary> /// <remarks> /// Inserts the header at the specified index in the list. /// </remarks> /// <param name="index">The index to insert the header.</param> /// <param name="id">The header identifier.</param> /// <param name="value">The header value.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="value"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <para><paramref name="id"/> is not a valid <see cref="HeaderId"/>.</para> /// <para>-or-</para> /// <para><paramref name="index"/> is out of range.</para> /// </exception> public void Insert(int index, HeaderId id, string value) { if (index < 0 || index > Count) { throw new ArgumentOutOfRangeException("index"); } Insert(index, new Header(id, value)); }
/// <summary> /// Check if the set of headers contains the specified header. /// </summary> /// <remarks> /// Determines whether or not the set of headers contains the specified header. /// </remarks> /// <returns><value>true</value> if the specified header exists; /// otherwise <value>false</value>.</returns> /// <param name="header">The header identifier.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="header"/> is not a valid <see cref="HeaderId"/>. /// </exception> public bool Contains(HeaderId header) { if (header == HeaderId.Unknown) { throw new ArgumentOutOfRangeException(nameof(header)); } return(hash.Contains(header.ToHeaderName().ToUpperInvariant())); }
public Header this[HeaderId id] { get { EnumValidator.ThrowIfInvalid <HeaderId>(id, "id"); Header result; this.headerByIdDictionary.TryGetValue(id, out result); return(result); } }
internal static string GetHeaderValue(MimePart part, HeaderId headerId) { Header header = part.Headers.FindFirst(headerId); if (header == null) { return(null); } return(Utility.GetHeaderValue(header)); }
internal static Header FindLastHeader(MimePart part, HeaderId headerId) { Header result = null; for (Header header = part.Headers.FindFirst(headerId); header != null; header = part.Headers.FindNext(header)) { result = header; } return(result); }
internal static bool TryGetFileNameFromHeader(MimePart mimePart, HeaderId headerId, string parameterName, ref string fileName) { string parameterValue = Utility.GetParameterValue(mimePart, headerId, parameterName); if (string.IsNullOrEmpty(parameterValue)) { return(false); } fileName = parameterValue; return(true); }
public override void FromBytes(byte[] bytes) { if (HeaderId.Equals(HeaderId.ConnectionId)) { Value = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, 0)); } else { Value = BitConverter.ToInt32(bytes, 0); } }
internal void WriteHeader(HeaderId id, ExDateTime data) { if (this.hasAllHeaders) { return; } DateHeader header = (DateHeader)Header.Create(id); MimeInternalHelpers.SetDateHeaderValue(header, data.UniversalTime, data.Bias); this.WriteHeader(header); }
private static void CopyAddressList(MailAddressCollection sourceList, InternetAddressList targetList, MimeMessage message, HeaderId headerId) { if (sourceList == null || sourceList.Count == 0) { return; } message.Headers.Replace(headerId, string.Empty); targetList.AddRange(sourceList.Select(ToMailboxAddress).Where(t => t != null)); }
// Token: 0x0600022E RID: 558 RVA: 0x00009AD4 File Offset: 0x00007CD4 public Header[] FindAll(string name) { HeaderId headerId = Header.GetHeaderId(name, false); if (headerId != HeaderId.Unknown) { return(this.FindAll(headerId)); } Header header = this.FindFirst(name); if (header == null) { return(new Header[0]); } Header header2 = header; int num = 1; int num2 = 0; for (;;) { header2 = (header2.NextSibling as Header); num2++; this.CheckLoopCount(num2); if (header2 == null) { break; } if (header2.IsName(name)) { num++; } } Header[] array = new Header[num]; header2 = header; array[0] = header2; num2 = 0; int i = 1; while (i < num) { header2 = (header2.NextSibling as Header); num2++; this.CheckLoopCount(num2); if (header2 == null) { break; } if (header2.IsName(name)) { array[i++] = header2; } } return(array); }
/// <summary> /// Remove the specified header. /// </summary> /// <remarks> /// Removes the specified header if it exists. /// </remarks> /// <returns><c>true</c> if the specified header was removed; /// otherwise <c>false</c>.</returns> /// <param name="header">The header.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="header"/> is not a valid <see cref="HeaderId"/>. /// </exception> /// <exception cref="InvalidOperationException"> /// The operation is invalid because the <see cref="HeaderSet"/> is read-only. /// </exception> public bool Remove(HeaderId header) { if (header == HeaderId.Unknown) { throw new ArgumentOutOfRangeException(nameof(header)); } CheckReadOnly(); return(hash.Remove(header.ToHeaderName().ToUpperInvariant())); }
/// <summary> /// Parses a string header to its corresponding enum value. Only needed for .NET 3.5 since it is natively supported in 4.0 and above. /// </summary> /// <param name="strEnumValue">The string value of the enum field</param> /// <param name="defaultValue"></param> /// <returns></returns> public static bool TryParseHeader(string strEnumValue, out HeaderId parsedHeaderId) { parsedHeaderId = HeaderId.Unknown; if (!Enum.IsDefined(typeof(HeaderId), strEnumValue)) { return(false); } parsedHeaderId = (HeaderId)Enum.Parse(typeof(HeaderId), strEnumValue); return(true); }
internal static string GetParameterValue(MimePart part, HeaderId headerId, string parameterName) { string result = null; ComplexHeader complexHeader = part.Headers.FindFirst(headerId) as ComplexHeader; if (complexHeader != null) { result = Utility.GetParameterValue(complexHeader, parameterName); } return(result); }
// Token: 0x06000239 RID: 569 RVA: 0x00009E24 File Offset: 0x00008024 internal override void ChildRemoved(MimeNode oldChild) { Header header = oldChild as Header; HeaderId headerId = header.HeaderId; if (this.headerMap[(int)headerId] != 255) { byte[] array = this.headerMap; HeaderId headerId2 = headerId; array[(int)headerId2] = array[(int)headerId2] - 1; } }
internal static bool TryGetFileNameFromHeader(MimePart mimePart, HeaderId headerId, ref string fileName) { Header header = mimePart.Headers.FindFirst(headerId); string headerValue = Utility.GetHeaderValue(header); if (string.IsNullOrEmpty(headerValue)) { return(false); } fileName = headerValue; return(true); }
static void TestDkimSignVerify(MimeMessage message, DkimSignatureAlgorithm signatureAlgorithm, DkimCanonicalizationAlgorithm headerAlgorithm, DkimCanonicalizationAlgorithm bodyAlgorithm) { var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date }; var signer = CreateSigner(signatureAlgorithm); message.Sign(signer, headers, headerAlgorithm, bodyAlgorithm); var dkim = message.Headers[0]; Assert.IsTrue(message.Verify(dkim, new DummyPublicKeyLocator(DkimKeys.Public)), "Failed to verify DKIM-Signature."); message.Headers.RemoveAt(0); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Header"/> class. /// </summary> /// <remarks> /// Creates a new message or entity header for the specified field and /// value pair. The encoding is used to determine which charset to use /// when encoding the value according to the rules of rfc2047. /// </remarks> /// <param name="charset">The charset that should be used to encode the /// header value.</param> /// <param name="id">The header identifier.</param> /// <param name="value">The value of the header.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="charset"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="value"/> is <c>null</c>.</para> /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>. /// </exception> public Header (Encoding charset, HeaderId id, string value) { if (charset == null) throw new ArgumentNullException ("charset"); if (id == HeaderId.Unknown) throw new ArgumentOutOfRangeException ("id"); if (value == null) throw new ArgumentNullException ("value"); Options = ParserOptions.Default.Clone (); Field = id.ToHeaderName (); Id = id; SetValue (charset, value); }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Header"/> class. /// </summary> /// <remarks> /// Creates a new message or entity header for the specified field and /// value pair. The encoding is used to determine which charset to use /// when encoding the value according to the rules of rfc2047. /// </remarks> /// <param name="encoding">The character encoding that should be used to /// encode the header value.</param> /// <param name="id">The header identifier.</param> /// <param name="value">The value of the header.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="encoding"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="value"/> is <c>null</c>.</para> /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>. /// </exception> public Header (Encoding encoding, HeaderId id, string value) { if (encoding == null) throw new ArgumentNullException ("encoding"); if (id == HeaderId.Unknown) throw new ArgumentOutOfRangeException ("id"); if (value == null) throw new ArgumentNullException ("value"); Options = ParserOptions.Default.Clone (); Field = id.ToHeaderName (); Id = id; rawField = Encoding.ASCII.GetBytes (Field); SetValue (encoding, value); }
internal static Header Create(string name, HeaderId headerId) { if (headerId < HeaderId.Unknown || headerId > (HeaderId) MimeData.nameIndex.Length) throw new System.ArgumentException(Resources.Strings.InvalidHeaderId, nameof(headerId)); if (headerId == HeaderId.Unknown) throw new System.ArgumentException(Resources.Strings.CannotDetermineHeaderNameFromId, nameof(headerId)); Header header; switch (MimeData.headerNames[(int) MimeData.nameIndex[(int) headerId]].headerType) { case HeaderType.AsciiText: header = new AsciiTextHeader(MimeData.headerNames[(int) MimeData.nameIndex[(int) headerId]].name, headerId); break; case HeaderType.Date: header = new DateHeader(MimeData.headerNames[(int) MimeData.nameIndex[(int) headerId]].name, headerId); break; case HeaderType.Received: header = new ReceivedHeader(); break; case HeaderType.ContentType: header = new ContentTypeHeader(); break; case HeaderType.ContentDisposition: header = new ContentDispositionHeader(); break; case HeaderType.Address: header = new AddressHeader(MimeData.headerNames[(int) MimeData.nameIndex[(int) headerId]].name, headerId); break; default: header = new TextHeader(MimeData.headerNames[(int) MimeData.nameIndex[(int) headerId]].name, headerId); break; } if (!string.IsNullOrEmpty(name) && !header.MatchName(name)) throw new System.ArgumentException("name"); return header; }
internal static string GetHeaderName(HeaderId headerId) { return MimeData.headerNames[(int) MimeData.nameIndex[(int) headerId]].name; }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Header"/> class. /// </summary> /// <remarks> /// Creates a new message or entity header for the specified field and /// value pair. The encoding is used to determine which charset to use /// when encoding the value according to the rules of rfc2047. /// </remarks> /// <param name="charset">The charset that should be used to encode the /// header value.</param> /// <param name="id">The header identifier.</param> /// <param name="value">The value of the header.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="charset"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="value"/> is <c>null</c>.</para> /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>. /// </exception> /// <exception cref="System.NotSupportedException"> /// <paramref name="charset"/> is not supported. /// </exception> public Header (string charset, HeaderId id, string value) { if (charset == null) throw new ArgumentNullException (nameof (charset)); if (id == HeaderId.Unknown) throw new ArgumentOutOfRangeException (nameof (id)); if (value == null) throw new ArgumentNullException (nameof (value)); var encoding = CharsetUtils.GetEncoding (charset); Options = ParserOptions.Default.Clone (); Field = id.ToHeaderName (); Id = id; rawField = Encoding.ASCII.GetBytes (Field); SetValue (encoding, value); }
public static Header Create(HeaderId headerId) { return Header.Create(null, headerId); }
internal Header(ParserOptions options, HeaderId id, string field, byte[] value) { Options = options; RawValue = value; Field = field; Id = id; }
void ReplaceHeader (HeaderId id, string name, byte[] raw) { Headers.Changed -= HeadersChanged; try { Headers.Replace (new Header (Headers.Options, id, name, raw)); } finally { Headers.Changed += HeadersChanged; } }
internal static System.Type TypeFromHeaderId(HeaderId headerId) { switch (MimeData.headerNames[(int) MimeData.nameIndex[(int) headerId]].headerType) { case HeaderType.AsciiText: return typeof (AsciiTextHeader); case HeaderType.Date: return typeof (DateHeader); case HeaderType.Received: return typeof (ReceivedHeader); case HeaderType.ContentType: return typeof (ContentTypeHeader); case HeaderType.ContentDisposition: return typeof (ContentDispositionHeader); case HeaderType.Address: return typeof (AddressHeader); default: return typeof (TextHeader); } }
void ReloadHeader(HeaderId id, string field) { if (id == HeaderId.Unknown) return; if (id == HeaderId.References) { references.Changed -= ReferencesChanged; references.Clear (); references.Changed += ReferencesChanged; } else if (id == HeaderId.InReplyTo) { inreplyto = null; } foreach (var header in Headers) { if (header.Id != id) continue; switch (id) { case HeaderId.MimeVersion: if (MimeUtils.TryParseVersion (header.RawValue, 0, header.RawValue.Length, out version)) return; break; case HeaderId.References: references.Changed -= ReferencesChanged; foreach (var msgid in MimeUtils.EnumerateReferences (header.RawValue, 0, header.RawValue.Length)) references.Add (msgid); references.Changed += ReferencesChanged; break; case HeaderId.InReplyTo: inreplyto = MimeUtils.EnumerateReferences (header.RawValue, 0, header.RawValue.Length).FirstOrDefault (); break; case HeaderId.MessageId: messageId = MimeUtils.EnumerateReferences (header.RawValue, 0, header.RawValue.Length).FirstOrDefault (); if (messageId != null) return; break; case HeaderId.Date: if (DateUtils.TryParseDateTime (header.RawValue, 0, header.RawValue.Length, out date)) return; break; } } }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Header"/> class. /// </summary> /// <remarks> /// Creates a new message or entity header for the specified field and /// value pair with the UTF-8 encoding. /// </remarks> /// <param name="id">The header identifier.</param> /// <param name="value">The value of the header.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="value"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>. /// </exception> public Header (HeaderId id, string value) : this (Encoding.UTF8, id, value) { }
// Note: this .ctor is only used by Clone() internal Header (ParserOptions options, HeaderId id, string name, byte[] field, byte[] value) { Options = options; rawField = field; rawValue = value; Field = name; Id = id; }
static void TestDkimSignVerify (MimeMessage message, DkimSignatureAlgorithm signatureAlgorithm, DkimCanonicalizationAlgorithm headerAlgorithm, DkimCanonicalizationAlgorithm bodyAlgorithm) { var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date }; var signer = CreateSigner (signatureAlgorithm); message.Sign (signer, headers, headerAlgorithm, bodyAlgorithm); var dkim = message.Headers[0]; Assert.IsTrue (message.Verify (dkim, new DummyPublicKeyLocator (DkimKeys.Public)), "Failed to verify DKIM-Signature."); message.Headers.RemoveAt (0); }
void ReloadHeader (HeaderId id) { if (id == HeaderId.Unknown) return; switch (id) { case HeaderId.ResentMessageId: resentMessageId = null; break; case HeaderId.ResentSender: resentSender = null; break; case HeaderId.ResentDate: resentDate = DateTimeOffset.MinValue; break; case HeaderId.References: references.Changed -= ReferencesChanged; references.Clear (); references.Changed += ReferencesChanged; break; case HeaderId.InReplyTo: inreplyto = null; break; case HeaderId.MessageId: messageId = null; break; case HeaderId.Sender: sender = null; break; case HeaderId.Date: date = DateTimeOffset.MinValue; break; } foreach (var header in Headers) { if (header.Id != id) continue; var rawValue = header.RawValue; InternetAddress address; int index = 0; switch (id) { case HeaderId.MimeVersion: if (MimeUtils.TryParseVersion (rawValue, 0, rawValue.Length, out version)) return; break; case HeaderId.References: references.Changed -= ReferencesChanged; foreach (var msgid in MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length)) references.Add (msgid); references.Changed += ReferencesChanged; break; case HeaderId.InReplyTo: inreplyto = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault (); break; case HeaderId.ResentMessageId: resentMessageId = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault (); if (resentMessageId != null) return; break; case HeaderId.MessageId: messageId = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault (); if (messageId != null) return; break; case HeaderId.ResentSender: if (InternetAddress.TryParse (Headers.Options, rawValue, ref index, rawValue.Length, false, out address)) resentSender = address as MailboxAddress; if (resentSender != null) return; break; case HeaderId.Sender: if (InternetAddress.TryParse (Headers.Options, rawValue, ref index, rawValue.Length, false, out address)) sender = address as MailboxAddress; if (sender != null) return; break; case HeaderId.ResentDate: if (DateUtils.TryParseDateTime (rawValue, 0, rawValue.Length, out resentDate)) return; break; case HeaderId.Date: if (DateUtils.TryParseDateTime (rawValue, 0, rawValue.Length, out date)) return; break; } } }
internal static bool IsRestrictedHeader(HeaderId headerId) { return MimeData.headerNames[(int) MimeData.nameIndex[(int) headerId]].restricted; }
void ReloadAddressList (HeaderId id, InternetAddressList list) { // clear the address list and reload list.Changed -= InternetAddressListChanged; list.Clear (); foreach (var header in Headers) { if (header.Id != id) continue; int length = header.RawValue.Length; List<InternetAddress> parsed; int index = 0; if (!InternetAddressList.TryParse (Headers.Options, header.RawValue, ref index, length, false, false, out parsed)) continue; list.AddRange (parsed); } list.Changed += InternetAddressListChanged; }
internal Header(string name, HeaderId headerId) { this.Name = name; this.HeaderId = headerId; }
void ReloadHeader (HeaderId id) { if (id == HeaderId.Unknown) return; switch (id) { case HeaderId.ResentMessageId: resentMessageId = null; break; case HeaderId.ResentSender: resentSender = null; break; case HeaderId.ResentDate: resentDate = DateTimeOffset.MinValue; break; case HeaderId.References: references.Changed -= ReferencesChanged; references.Clear (); references.Changed += ReferencesChanged; break; case HeaderId.InReplyTo: inreplyto = null; break; case HeaderId.MessageId: messageId = null; break; case HeaderId.Sender: sender = null; break; case HeaderId.Importance: importance = MessageImportance.Normal; break; case HeaderId.Priority: priority = MessagePriority.Normal; break; case HeaderId.Date: date = DateTimeOffset.MinValue; break; } foreach (var header in Headers) { if (header.Id != id) continue; var rawValue = header.RawValue; InternetAddress address; int index = 0; switch (id) { case HeaderId.MimeVersion: if (MimeUtils.TryParse (rawValue, 0, rawValue.Length, out version)) return; break; case HeaderId.References: references.Changed -= ReferencesChanged; foreach (var msgid in MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length)) references.Add (msgid); references.Changed += ReferencesChanged; break; case HeaderId.InReplyTo: inreplyto = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault (); break; case HeaderId.ResentMessageId: resentMessageId = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault (); if (resentMessageId != null) return; break; case HeaderId.MessageId: messageId = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault (); if (messageId != null) return; break; case HeaderId.ResentSender: if (InternetAddress.TryParse (Headers.Options, rawValue, ref index, rawValue.Length, false, out address)) resentSender = address as MailboxAddress; if (resentSender != null) return; break; case HeaderId.Sender: if (InternetAddress.TryParse (Headers.Options, rawValue, ref index, rawValue.Length, false, out address)) sender = address as MailboxAddress; if (sender != null) return; break; case HeaderId.ResentDate: if (DateUtils.TryParse (rawValue, 0, rawValue.Length, out resentDate)) return; break; case HeaderId.Importance: switch (header.Value.ToLowerInvariant ().Trim ()) { case "high": importance = MessageImportance.High; break; case "low": importance = MessageImportance.Low; break; default: importance = MessageImportance.Normal; break; } break; case HeaderId.Priority: switch (header.Value.ToLowerInvariant ().Trim ()) { case "non-urgent": priority = MessagePriority.NonUrgent; break; case "urgent": priority = MessagePriority.Urgent; break; default: priority = MessagePriority.Normal; break; } break; case HeaderId.Date: if (DateUtils.TryParse (rawValue, 0, rawValue.Length, out date)) return; break; } } }
internal TextHeader(string name, HeaderId headerId) : base(name, headerId) { }
internal DateHeader(string name, HeaderId headerId) : base(name, headerId) { }
public void StartHeader(HeaderId headerId) { this.AssertOpen(); this.WriteHeader(Header.Create(headerId)); }
public HeaderNameDef(int hash, string name, HeaderType headerType, HeaderId publicHeaderId, bool restricted) { this.hash = (byte) hash; this.restricted = restricted; this.headerType = headerType; this.name = name; this.publicHeaderId = publicHeaderId; }
void RemoveHeader (HeaderId id) { Headers.Changed -= HeadersChanged; try { Headers.RemoveAll (id); } finally { Headers.Changed += HeadersChanged; } }
internal Header (ParserOptions options, HeaderId id, string field, byte[] value) { Options = options; rawField = Encoding.ASCII.GetBytes (field); rawValue = value; Field = field; Id = id; }
/// <summary> /// Initializes a new instance of the <see cref="MimeKit.Header"/> class. /// </summary> /// <remarks> /// Creates a new message or entity header for the specified field and /// value pair. The encoding is used to determine which charset to use /// when encoding the value according to the rules of rfc2047. /// </remarks> /// <param name="charset">The charset that should be used to encode the /// header value.</param> /// <param name="id">The header identifier.</param> /// <param name="value">The value of the header.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="charset"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="value"/> is <c>null</c>.</para> /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>. /// </exception> /// <exception cref="System.ArgumentException"> /// <paramref name="charset"/> cannot be empty. /// </exception> /// <exception cref="System.NotSupportedException"> /// <paramref name="charset"/> is not supported. /// </exception> public Header (string charset, HeaderId id, string value) { if (charset == null) throw new ArgumentNullException ("charset"); if (charset.Length == 0) throw new ArgumentException ("The charset name cannot be empty.", "charset"); if (id == HeaderId.Unknown) throw new ArgumentOutOfRangeException ("id"); if (value == null) throw new ArgumentNullException ("value"); var encoding = CharsetUtils.GetEncoding (charset); Options = ParserOptions.Default.Clone (); Field = id.ToHeaderName (); Id = id; rawField = Encoding.ASCII.GetBytes (Field); SetValue (encoding, value); }
public HeaderNameDef(int hash) { this.hash = (byte) hash; restricted = false; headerType = HeaderType.Text; name = null; publicHeaderId = HeaderId.Unknown; }