Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / Mail / MailHeaderInfo.cs / 1305376 / MailHeaderInfo.cs
using System;
using System.Collections.Specialized;
using System.Net.Mail;
using System.Globalization;
using System.Collections.Generic;
namespace System.Net.Mail {
// Enumeration of the well-known headers.
// If you add to this enum you MUST also add the appropriate initializer in m_HeaderInfo below.
internal enum MailHeaderID {
Bcc = 0,
Cc,
Comments,
ContentDescription,
ContentDisposition,
ContentID,
ContentLocation,
ContentTransferEncoding,
ContentType,
Date,
From,
Importance,
InReplyTo,
Keywords,
Max,
MessageID,
MimeVersion,
Priority,
References,
ReplyTo,
ResentBcc,
ResentCc,
ResentDate,
ResentFrom,
ResentMessageID,
ResentSender,
ResentTo,
Sender,
Subject,
To,
XPriority,
XReceiver,
XSender,
ZMaxEnumValue = XSender, // Keep this to equal to the last "known" enum entry if you add to the end
Unknown = -1
}
internal static class MailHeaderInfo {
// Structure that wraps information about a single mail header
private struct HeaderInfo {
public readonly string NormalizedName;
public readonly bool IsSingleton;
public readonly MailHeaderID ID;
public readonly bool IsUserSettable;
public HeaderInfo(MailHeaderID id, string name, bool isSingleton, bool isUserSettable) {
ID = id;
NormalizedName = name;
IsSingleton = isSingleton;
IsUserSettable = isUserSettable;
}
}
// Table of well-known mail headers.
// Keep the initializers in [....] with the enum above.
private static readonly HeaderInfo[] m_HeaderInfo = {
// ID NormalizedString IsSingleton IsUserSettable
new HeaderInfo(MailHeaderID.Bcc, "Bcc", true, false),
new HeaderInfo(MailHeaderID.Cc, "Cc", true, false),
new HeaderInfo(MailHeaderID.Comments, "Comments", false, true),
new HeaderInfo(MailHeaderID.ContentDescription, "Content-Description", true, true),
new HeaderInfo(MailHeaderID.ContentDisposition, "Content-Disposition", true, true),
new HeaderInfo(MailHeaderID.ContentID, "Content-ID", true, false),
new HeaderInfo(MailHeaderID.ContentLocation, "Content-Location", true, false),
new HeaderInfo(MailHeaderID.ContentTransferEncoding, "Content-Transfer-Encoding", true, false),
new HeaderInfo(MailHeaderID.ContentType, "Content-Type", true, false),
new HeaderInfo(MailHeaderID.Date, "Date", true, false),
new HeaderInfo(MailHeaderID.From, "From", true, false),
new HeaderInfo(MailHeaderID.Importance, "Importance", true, false),
new HeaderInfo(MailHeaderID.InReplyTo, "In-Reply-To", true, true),
new HeaderInfo(MailHeaderID.Keywords, "Keywords", false, true),
new HeaderInfo(MailHeaderID.Max, "Max", false, true),
new HeaderInfo(MailHeaderID.MessageID, "Message-ID", true, true),
new HeaderInfo(MailHeaderID.MimeVersion, "MIME-Version", true, false),
new HeaderInfo(MailHeaderID.Priority, "Priority", true, false),
new HeaderInfo(MailHeaderID.References, "References", true, true),
new HeaderInfo(MailHeaderID.ReplyTo, "Reply-To", true, false),
new HeaderInfo(MailHeaderID.ResentBcc, "Resent-Bcc", false, true),
new HeaderInfo(MailHeaderID.ResentCc, "Resent-Cc", false, true),
new HeaderInfo(MailHeaderID.ResentDate, "Resent-Date", false, true),
new HeaderInfo(MailHeaderID.ResentFrom, "Resent-From", false, true),
new HeaderInfo(MailHeaderID.ResentMessageID, "Resent-Message-ID", false, true),
new HeaderInfo(MailHeaderID.ResentSender, "Resent-Sender", false, true),
new HeaderInfo(MailHeaderID.ResentTo, "Resent-To", false, true),
new HeaderInfo(MailHeaderID.Sender, "Sender", true, false),
new HeaderInfo(MailHeaderID.Subject, "Subject", true, false),
new HeaderInfo(MailHeaderID.To, "To", true, false),
new HeaderInfo(MailHeaderID.XPriority, "X-Priority", true, false),
new HeaderInfo(MailHeaderID.XReceiver, "X-Receiver", false, true),
new HeaderInfo(MailHeaderID.XSender, "X-Sender", true, true)
};
private static readonly Dictionary m_HeaderDictionary;
static MailHeaderInfo() {
#if DEBUG
// Check that enum and header info array are in [....]
for(int i = 0; i < m_HeaderInfo.Length; i++) {
if((int)m_HeaderInfo[i].ID != i) {
throw new Exception("Header info data structures are not in [....]");
}
}
#endif
// Create dictionary for string-to-enum lookup. Ordinal and IgnoreCase are intentional.
m_HeaderDictionary = new Dictionary((int)MailHeaderID.ZMaxEnumValue + 1, StringComparer.OrdinalIgnoreCase);
for(int i = 0; i < m_HeaderInfo.Length; i++) {
m_HeaderDictionary.Add(m_HeaderInfo[i].NormalizedName, i);
}
}
internal static string GetString(MailHeaderID id) {
switch(id) {
case MailHeaderID.Unknown:
case MailHeaderID.ZMaxEnumValue+1:
return null;
default:
return m_HeaderInfo[(int)id].NormalizedName;
}
}
internal static MailHeaderID GetID(string name) {
int id;
if(m_HeaderDictionary.TryGetValue(name, out id)) {
return (MailHeaderID)id;
}
return MailHeaderID.Unknown;
}
internal static bool IsWellKnown(string name) {
int dummy;
return m_HeaderDictionary.TryGetValue(name, out dummy);
}
internal static bool IsUserSettable(string name) {
int index;
if (m_HeaderDictionary.TryGetValue(name, out index)) {
return m_HeaderInfo[index].IsUserSettable;
}
//values not in the list of well-known headers are always user-settable
return true;
}
internal static bool IsSingleton(string name) {
int index;
if(m_HeaderDictionary.TryGetValue(name, out index)) {
return m_HeaderInfo[index].IsSingleton;
}
return false;
}
internal static string NormalizeCase(string name) {
int index;
if(m_HeaderDictionary.TryGetValue(name, out index)) {
return m_HeaderInfo[index].NormalizedName;
}
return name;
}
internal static bool IsMatch(string name, MailHeaderID header) {
int index;
if(m_HeaderDictionary.TryGetValue(name, out index) && (MailHeaderID)index == header) {
return true;
}
return false;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Specialized;
using System.Net.Mail;
using System.Globalization;
using System.Collections.Generic;
namespace System.Net.Mail {
// Enumeration of the well-known headers.
// If you add to this enum you MUST also add the appropriate initializer in m_HeaderInfo below.
internal enum MailHeaderID {
Bcc = 0,
Cc,
Comments,
ContentDescription,
ContentDisposition,
ContentID,
ContentLocation,
ContentTransferEncoding,
ContentType,
Date,
From,
Importance,
InReplyTo,
Keywords,
Max,
MessageID,
MimeVersion,
Priority,
References,
ReplyTo,
ResentBcc,
ResentCc,
ResentDate,
ResentFrom,
ResentMessageID,
ResentSender,
ResentTo,
Sender,
Subject,
To,
XPriority,
XReceiver,
XSender,
ZMaxEnumValue = XSender, // Keep this to equal to the last "known" enum entry if you add to the end
Unknown = -1
}
internal static class MailHeaderInfo {
// Structure that wraps information about a single mail header
private struct HeaderInfo {
public readonly string NormalizedName;
public readonly bool IsSingleton;
public readonly MailHeaderID ID;
public readonly bool IsUserSettable;
public HeaderInfo(MailHeaderID id, string name, bool isSingleton, bool isUserSettable) {
ID = id;
NormalizedName = name;
IsSingleton = isSingleton;
IsUserSettable = isUserSettable;
}
}
// Table of well-known mail headers.
// Keep the initializers in [....] with the enum above.
private static readonly HeaderInfo[] m_HeaderInfo = {
// ID NormalizedString IsSingleton IsUserSettable
new HeaderInfo(MailHeaderID.Bcc, "Bcc", true, false),
new HeaderInfo(MailHeaderID.Cc, "Cc", true, false),
new HeaderInfo(MailHeaderID.Comments, "Comments", false, true),
new HeaderInfo(MailHeaderID.ContentDescription, "Content-Description", true, true),
new HeaderInfo(MailHeaderID.ContentDisposition, "Content-Disposition", true, true),
new HeaderInfo(MailHeaderID.ContentID, "Content-ID", true, false),
new HeaderInfo(MailHeaderID.ContentLocation, "Content-Location", true, false),
new HeaderInfo(MailHeaderID.ContentTransferEncoding, "Content-Transfer-Encoding", true, false),
new HeaderInfo(MailHeaderID.ContentType, "Content-Type", true, false),
new HeaderInfo(MailHeaderID.Date, "Date", true, false),
new HeaderInfo(MailHeaderID.From, "From", true, false),
new HeaderInfo(MailHeaderID.Importance, "Importance", true, false),
new HeaderInfo(MailHeaderID.InReplyTo, "In-Reply-To", true, true),
new HeaderInfo(MailHeaderID.Keywords, "Keywords", false, true),
new HeaderInfo(MailHeaderID.Max, "Max", false, true),
new HeaderInfo(MailHeaderID.MessageID, "Message-ID", true, true),
new HeaderInfo(MailHeaderID.MimeVersion, "MIME-Version", true, false),
new HeaderInfo(MailHeaderID.Priority, "Priority", true, false),
new HeaderInfo(MailHeaderID.References, "References", true, true),
new HeaderInfo(MailHeaderID.ReplyTo, "Reply-To", true, false),
new HeaderInfo(MailHeaderID.ResentBcc, "Resent-Bcc", false, true),
new HeaderInfo(MailHeaderID.ResentCc, "Resent-Cc", false, true),
new HeaderInfo(MailHeaderID.ResentDate, "Resent-Date", false, true),
new HeaderInfo(MailHeaderID.ResentFrom, "Resent-From", false, true),
new HeaderInfo(MailHeaderID.ResentMessageID, "Resent-Message-ID", false, true),
new HeaderInfo(MailHeaderID.ResentSender, "Resent-Sender", false, true),
new HeaderInfo(MailHeaderID.ResentTo, "Resent-To", false, true),
new HeaderInfo(MailHeaderID.Sender, "Sender", true, false),
new HeaderInfo(MailHeaderID.Subject, "Subject", true, false),
new HeaderInfo(MailHeaderID.To, "To", true, false),
new HeaderInfo(MailHeaderID.XPriority, "X-Priority", true, false),
new HeaderInfo(MailHeaderID.XReceiver, "X-Receiver", false, true),
new HeaderInfo(MailHeaderID.XSender, "X-Sender", true, true)
};
private static readonly Dictionary m_HeaderDictionary;
static MailHeaderInfo() {
#if DEBUG
// Check that enum and header info array are in [....]
for(int i = 0; i < m_HeaderInfo.Length; i++) {
if((int)m_HeaderInfo[i].ID != i) {
throw new Exception("Header info data structures are not in [....]");
}
}
#endif
// Create dictionary for string-to-enum lookup. Ordinal and IgnoreCase are intentional.
m_HeaderDictionary = new Dictionary((int)MailHeaderID.ZMaxEnumValue + 1, StringComparer.OrdinalIgnoreCase);
for(int i = 0; i < m_HeaderInfo.Length; i++) {
m_HeaderDictionary.Add(m_HeaderInfo[i].NormalizedName, i);
}
}
internal static string GetString(MailHeaderID id) {
switch(id) {
case MailHeaderID.Unknown:
case MailHeaderID.ZMaxEnumValue+1:
return null;
default:
return m_HeaderInfo[(int)id].NormalizedName;
}
}
internal static MailHeaderID GetID(string name) {
int id;
if(m_HeaderDictionary.TryGetValue(name, out id)) {
return (MailHeaderID)id;
}
return MailHeaderID.Unknown;
}
internal static bool IsWellKnown(string name) {
int dummy;
return m_HeaderDictionary.TryGetValue(name, out dummy);
}
internal static bool IsUserSettable(string name) {
int index;
if (m_HeaderDictionary.TryGetValue(name, out index)) {
return m_HeaderInfo[index].IsUserSettable;
}
//values not in the list of well-known headers are always user-settable
return true;
}
internal static bool IsSingleton(string name) {
int index;
if(m_HeaderDictionary.TryGetValue(name, out index)) {
return m_HeaderInfo[index].IsSingleton;
}
return false;
}
internal static string NormalizeCase(string name) {
int index;
if(m_HeaderDictionary.TryGetValue(name, out index)) {
return m_HeaderInfo[index].NormalizedName;
}
return name;
}
internal static bool IsMatch(string name, MailHeaderID header) {
int index;
if(m_HeaderDictionary.TryGetValue(name, out index) && (MailHeaderID)index == header) {
return true;
}
return false;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PointF.cs
- OleDbParameterCollection.cs
- CommandField.cs
- IsolatedStoragePermission.cs
- Debug.cs
- ExpressionVisitor.cs
- RecordsAffectedEventArgs.cs
- AutomationIdentifierGuids.cs
- X509SecurityTokenParameters.cs
- TypeResolver.cs
- SafeNativeMethodsMilCoreApi.cs
- SubMenuStyleCollection.cs
- PeerConnector.cs
- QilGenerator.cs
- StringUtil.cs
- CompiledQuery.cs
- ObjectRef.cs
- TextElement.cs
- InstanceLockException.cs
- ErrorWebPart.cs
- ServiceObjectContainer.cs
- PerformanceCounter.cs
- OdbcEnvironmentHandle.cs
- SmiEventSink_Default.cs
- DnsPermission.cs
- MultiSelector.cs
- Array.cs
- CustomGrammar.cs
- WhitespaceSignificantCollectionAttribute.cs
- XmlBinaryWriter.cs
- DataGridColumn.cs
- Win32.cs
- DataBoundControlAdapter.cs
- HighlightVisual.cs
- NameNode.cs
- AcceptorSessionSymmetricTransportSecurityProtocol.cs
- FullTextBreakpoint.cs
- AssociationEndMember.cs
- Context.cs
- SystemInformation.cs
- FixedDSBuilder.cs
- MenuRenderer.cs
- XPathNodeIterator.cs
- SmiRequestExecutor.cs
- ScrollBarRenderer.cs
- ipaddressinformationcollection.cs
- RenderCapability.cs
- GridViewSortEventArgs.cs
- ClassicBorderDecorator.cs
- ChunkedMemoryStream.cs
- MonitorWrapper.cs
- AssemblyBuilder.cs
- QuestionEventArgs.cs
- ShapingWorkspace.cs
- InputGestureCollection.cs
- StrokeCollectionConverter.cs
- LocatorManager.cs
- MultitargetUtil.cs
- Profiler.cs
- ReferenceConverter.cs
- StringComparer.cs
- SqlRemoveConstantOrderBy.cs
- WmpBitmapDecoder.cs
- PeerCredentialElement.cs
- DiagnosticTrace.cs
- DefaultTraceListener.cs
- ArgumentException.cs
- XmlnsCompatibleWithAttribute.cs
- EventRoute.cs
- DataGridViewSortCompareEventArgs.cs
- QilTernary.cs
- BitmapMetadata.cs
- WebServiceClientProxyGenerator.cs
- CodeGeneratorAttribute.cs
- ColorConverter.cs
- MetadataItemSerializer.cs
- SmtpFailedRecipientException.cs
- LostFocusEventManager.cs
- LogicalExpr.cs
- XPathBuilder.cs
- DataGridClipboardCellContent.cs
- DataGridViewLinkCell.cs
- InstanceNameConverter.cs
- NameObjectCollectionBase.cs
- RewritingValidator.cs
- BuildProviderUtils.cs
- WebRequestModuleElement.cs
- IfElseDesigner.xaml.cs
- GridViewUpdatedEventArgs.cs
- IndexedGlyphRun.cs
- UnmanagedMemoryStream.cs
- ExpressionBuilderCollection.cs
- GeometryDrawing.cs
- EntityUtil.cs
- columnmapfactory.cs
- XmlAnyElementAttributes.cs
- BasicAsyncResult.cs
- IriParsingElement.cs
- Span.cs
- ClickablePoint.cs