Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Net / System / Net / Mail / MailHeaderInfo.cs / 1 / 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 HeaderInfo(MailHeaderID id, string name, bool isSingleton) {
ID = id;
NormalizedName = name;
IsSingleton = isSingleton;
}
}
// Table of well-known mail headers.
// Keep the initializers in [....] with the enum above.
private static readonly HeaderInfo[] m_HeaderInfo = {
// ID NormalizedString IsSingleton
new HeaderInfo(MailHeaderID.Bcc, "Bcc", true),
new HeaderInfo(MailHeaderID.Cc, "Cc", true),
new HeaderInfo(MailHeaderID.Comments, "Comments", false),
new HeaderInfo(MailHeaderID.ContentDescription, "Content-Description", true),
new HeaderInfo(MailHeaderID.ContentDisposition, "Content-Disposition", true),
new HeaderInfo(MailHeaderID.ContentID, "Content-ID", true),
new HeaderInfo(MailHeaderID.ContentLocation, "Content-Location", true),
new HeaderInfo(MailHeaderID.ContentTransferEncoding, "Content-Transfer-Encoding", true),
new HeaderInfo(MailHeaderID.ContentType, "Content-Type", true),
new HeaderInfo(MailHeaderID.Date, "Date", true),
new HeaderInfo(MailHeaderID.From, "From", true),
new HeaderInfo(MailHeaderID.Importance, "Importance", true),
new HeaderInfo(MailHeaderID.InReplyTo, "In-Reply-To", true),
new HeaderInfo(MailHeaderID.Keywords, "Keywords", false),
new HeaderInfo(MailHeaderID.Max, "Max", false),
new HeaderInfo(MailHeaderID.MessageID, "Message-ID", true),
new HeaderInfo(MailHeaderID.MimeVersion, "MIME-Version", true),
new HeaderInfo(MailHeaderID.Priority, "Priority", true),
new HeaderInfo(MailHeaderID.References, "References", true),
new HeaderInfo(MailHeaderID.ReplyTo, "Reply-To", true),
new HeaderInfo(MailHeaderID.ResentBcc, "Resent-Bcc", false),
new HeaderInfo(MailHeaderID.ResentCc, "Resent-Cc", false),
new HeaderInfo(MailHeaderID.ResentDate, "Resent-Date", false),
new HeaderInfo(MailHeaderID.ResentFrom, "Resent-From", false),
new HeaderInfo(MailHeaderID.ResentMessageID, "Resent-Message-ID", false),
new HeaderInfo(MailHeaderID.ResentSender, "Resent-Sender", false),
new HeaderInfo(MailHeaderID.ResentTo, "Resent-To", false),
new HeaderInfo(MailHeaderID.Sender, "Sender", true),
new HeaderInfo(MailHeaderID.Subject, "Subject", true),
new HeaderInfo(MailHeaderID.To, "To", true),
new HeaderInfo(MailHeaderID.XPriority, "X-Priority", true),
new HeaderInfo(MailHeaderID.XReceiver, "X-Receiver", false),
new HeaderInfo(MailHeaderID.XSender, "X-Sender", 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 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 HeaderInfo(MailHeaderID id, string name, bool isSingleton) {
ID = id;
NormalizedName = name;
IsSingleton = isSingleton;
}
}
// Table of well-known mail headers.
// Keep the initializers in [....] with the enum above.
private static readonly HeaderInfo[] m_HeaderInfo = {
// ID NormalizedString IsSingleton
new HeaderInfo(MailHeaderID.Bcc, "Bcc", true),
new HeaderInfo(MailHeaderID.Cc, "Cc", true),
new HeaderInfo(MailHeaderID.Comments, "Comments", false),
new HeaderInfo(MailHeaderID.ContentDescription, "Content-Description", true),
new HeaderInfo(MailHeaderID.ContentDisposition, "Content-Disposition", true),
new HeaderInfo(MailHeaderID.ContentID, "Content-ID", true),
new HeaderInfo(MailHeaderID.ContentLocation, "Content-Location", true),
new HeaderInfo(MailHeaderID.ContentTransferEncoding, "Content-Transfer-Encoding", true),
new HeaderInfo(MailHeaderID.ContentType, "Content-Type", true),
new HeaderInfo(MailHeaderID.Date, "Date", true),
new HeaderInfo(MailHeaderID.From, "From", true),
new HeaderInfo(MailHeaderID.Importance, "Importance", true),
new HeaderInfo(MailHeaderID.InReplyTo, "In-Reply-To", true),
new HeaderInfo(MailHeaderID.Keywords, "Keywords", false),
new HeaderInfo(MailHeaderID.Max, "Max", false),
new HeaderInfo(MailHeaderID.MessageID, "Message-ID", true),
new HeaderInfo(MailHeaderID.MimeVersion, "MIME-Version", true),
new HeaderInfo(MailHeaderID.Priority, "Priority", true),
new HeaderInfo(MailHeaderID.References, "References", true),
new HeaderInfo(MailHeaderID.ReplyTo, "Reply-To", true),
new HeaderInfo(MailHeaderID.ResentBcc, "Resent-Bcc", false),
new HeaderInfo(MailHeaderID.ResentCc, "Resent-Cc", false),
new HeaderInfo(MailHeaderID.ResentDate, "Resent-Date", false),
new HeaderInfo(MailHeaderID.ResentFrom, "Resent-From", false),
new HeaderInfo(MailHeaderID.ResentMessageID, "Resent-Message-ID", false),
new HeaderInfo(MailHeaderID.ResentSender, "Resent-Sender", false),
new HeaderInfo(MailHeaderID.ResentTo, "Resent-To", false),
new HeaderInfo(MailHeaderID.Sender, "Sender", true),
new HeaderInfo(MailHeaderID.Subject, "Subject", true),
new HeaderInfo(MailHeaderID.To, "To", true),
new HeaderInfo(MailHeaderID.XPriority, "X-Priority", true),
new HeaderInfo(MailHeaderID.XReceiver, "X-Receiver", false),
new HeaderInfo(MailHeaderID.XSender, "X-Sender", 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 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
- CodeTypeOfExpression.cs
- ClaimComparer.cs
- TemplateInstanceAttribute.cs
- DesignerPerfEventProvider.cs
- NonVisualControlAttribute.cs
- FileInfo.cs
- GridViewColumnCollectionChangedEventArgs.cs
- BitmapEffectInputData.cs
- SynthesizerStateChangedEventArgs.cs
- SizeConverter.cs
- Rotation3DKeyFrameCollection.cs
- DelimitedListTraceListener.cs
- VirtualPathUtility.cs
- DataError.cs
- DescendantQuery.cs
- WebPartTransformer.cs
- AlgoModule.cs
- ProviderCollection.cs
- StringFunctions.cs
- MaterializeFromAtom.cs
- PagedDataSource.cs
- CodeMemberField.cs
- XamlWriter.cs
- RuntimeEnvironment.cs
- CommandHelpers.cs
- SortedList.cs
- MultiSelectRootGridEntry.cs
- ThreadInterruptedException.cs
- IpcChannelHelper.cs
- XmlMapping.cs
- CodeObject.cs
- DateTimeFormatInfoScanner.cs
- MembershipPasswordException.cs
- StyleXamlParser.cs
- TraceListeners.cs
- BaseDataBoundControl.cs
- CodeChecksumPragma.cs
- ReaderWriterLockWrapper.cs
- CompleteWizardStep.cs
- DocumentSchemaValidator.cs
- GenerateDerivedKeyRequest.cs
- SafeSecurityHandles.cs
- DispatchChannelSink.cs
- Collection.cs
- DataGridTablesFactory.cs
- ClientScriptManager.cs
- NetNamedPipeSecurityMode.cs
- ParserStreamGeometryContext.cs
- Vector.cs
- XmlNavigatorStack.cs
- TraceSection.cs
- DataPagerFieldItem.cs
- FileDialogCustomPlace.cs
- DataServiceRequestOfT.cs
- BitmapEncoder.cs
- Message.cs
- TextParagraphCache.cs
- UnionExpr.cs
- CheckBoxStandardAdapter.cs
- XPathAncestorQuery.cs
- WebResourceAttribute.cs
- Converter.cs
- ImageUrlEditor.cs
- CleanUpVirtualizedItemEventArgs.cs
- DataGridViewCellParsingEventArgs.cs
- GregorianCalendar.cs
- _RequestCacheProtocol.cs
- QuaternionAnimation.cs
- MetadataArtifactLoaderFile.cs
- _LazyAsyncResult.cs
- Aggregates.cs
- HuffmanTree.cs
- PageParserFilter.cs
- ToolStripDropDownClosedEventArgs.cs
- ObjectAssociationEndMapping.cs
- XmlException.cs
- CollectionDataContractAttribute.cs
- CommandEventArgs.cs
- HttpListenerPrefixCollection.cs
- TouchPoint.cs
- FilterableAttribute.cs
- ListItemConverter.cs
- UserMapPath.cs
- DbProviderFactoriesConfigurationHandler.cs
- IImplicitResourceProvider.cs
- DateTimeFormatInfo.cs
- AutomationPatternInfo.cs
- WindowsBrush.cs
- DynamicMethod.cs
- AttributeProviderAttribute.cs
- IndexExpression.cs
- StreamingContext.cs
- BamlLocalizabilityResolver.cs
- WebBrowserUriTypeConverter.cs
- CollectionViewSource.cs
- DragDeltaEventArgs.cs
- Int16Animation.cs
- XmlnsDictionary.cs
- transactioncontext.cs
- DataColumnMappingCollection.cs