Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / Mail / DomainLiteralReader.cs / 1305376 / DomainLiteralReader.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Net.Mail{
using System.Net.Mime;
using System.Diagnostics;
using System.Text;
//
// RFC 2822 Section 3.4.1 - Addr-Spec, Domain-Literals
// A domain literal is a domain identifier that does not conform to the dot-atom format (Section 3.2.4) and must be
// enclosed in brackets '[' ']'. Domain literals may contain quoted-pairs.
//
internal static class DomainLiteralReader
{
//
// Reads a domain literal in reverse
//
// Preconditions:
// - Index must be within the bounds of the data string.
// - The char at the given index is the initial bracket. (data[index] == EndSquareBracket)
//
// Return value:
// - The next index past the terminating bracket (data[index + 1] == StartSquareBracket).
// e.g. In (user@[domain]), starting at index=12 (]) returns index=4 (@).
//
// A FormatException will be thrown if:
// - A non-escaped character is encountered that is not valid in a domain literal, including Unicode.
// - The final bracket is not found.
//
internal static int ReadReverse(string data, int index)
{
Debug.Assert(0 <= index && index < data.Length, "index was outside the bounds of the string: " + index);
Debug.Assert(data[index] == MailBnfHelper.EndSquareBracket, "data did not end with a square bracket");
// Skip the end bracket
index--;
do
{
// Check for valid whitespace
index = WhitespaceReader.ReadFwsReverse(data, index);
if (index < 0)
{
break;
}
// Check for escaped characters
int quotedCharCount = QuotedPairReader.CountQuotedChars(data, index, false);
if (quotedCharCount > 0)
{
// Skip quoted pairs
index = index - quotedCharCount;
}
// Check for the terminating bracket
else if (data[index] == MailBnfHelper.StartSquareBracket)
{
// We're done parsing
return index - 1;
}
// Check for invalid characters
else if (data[index] > MailBnfHelper.Ascii7bitMaxValue || !MailBnfHelper.Dtext[data[index]])
{
throw new FormatException(SR.GetString(SR.MailHeaderFieldInvalidCharacter, data[index]));
}
// Valid char
else
{
index--;
}
}
while (index >= 0);
// We didn't find a matching '[', throw.
throw new FormatException(SR.GetString(SR.MailHeaderFieldInvalidCharacter,
MailBnfHelper.EndSquareBracket));
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Net.Mail{
using System.Net.Mime;
using System.Diagnostics;
using System.Text;
//
// RFC 2822 Section 3.4.1 - Addr-Spec, Domain-Literals
// A domain literal is a domain identifier that does not conform to the dot-atom format (Section 3.2.4) and must be
// enclosed in brackets '[' ']'. Domain literals may contain quoted-pairs.
//
internal static class DomainLiteralReader
{
//
// Reads a domain literal in reverse
//
// Preconditions:
// - Index must be within the bounds of the data string.
// - The char at the given index is the initial bracket. (data[index] == EndSquareBracket)
//
// Return value:
// - The next index past the terminating bracket (data[index + 1] == StartSquareBracket).
// e.g. In (user@[domain]), starting at index=12 (]) returns index=4 (@).
//
// A FormatException will be thrown if:
// - A non-escaped character is encountered that is not valid in a domain literal, including Unicode.
// - The final bracket is not found.
//
internal static int ReadReverse(string data, int index)
{
Debug.Assert(0 <= index && index < data.Length, "index was outside the bounds of the string: " + index);
Debug.Assert(data[index] == MailBnfHelper.EndSquareBracket, "data did not end with a square bracket");
// Skip the end bracket
index--;
do
{
// Check for valid whitespace
index = WhitespaceReader.ReadFwsReverse(data, index);
if (index < 0)
{
break;
}
// Check for escaped characters
int quotedCharCount = QuotedPairReader.CountQuotedChars(data, index, false);
if (quotedCharCount > 0)
{
// Skip quoted pairs
index = index - quotedCharCount;
}
// Check for the terminating bracket
else if (data[index] == MailBnfHelper.StartSquareBracket)
{
// We're done parsing
return index - 1;
}
// Check for invalid characters
else if (data[index] > MailBnfHelper.Ascii7bitMaxValue || !MailBnfHelper.Dtext[data[index]])
{
throw new FormatException(SR.GetString(SR.MailHeaderFieldInvalidCharacter, data[index]));
}
// Valid char
else
{
index--;
}
}
while (index >= 0);
// We didn't find a matching '[', throw.
throw new FormatException(SR.GetString(SR.MailHeaderFieldInvalidCharacter,
MailBnfHelper.EndSquareBracket));
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DetailsViewDeletedEventArgs.cs
- GeneralTransform.cs
- XamlStackWriter.cs
- XmlWhitespace.cs
- CodeAssignStatement.cs
- IPHostEntry.cs
- XmlSchemaGroup.cs
- ObservableDictionary.cs
- Identifier.cs
- QualificationDataAttribute.cs
- OneOfConst.cs
- HttpCacheParams.cs
- ReflectionTypeLoadException.cs
- Module.cs
- BuildManagerHost.cs
- PerformanceCounterPermissionEntryCollection.cs
- InvalidOperationException.cs
- DataRecordInternal.cs
- IdentityReference.cs
- TracingConnectionListener.cs
- TcpDuplicateContext.cs
- ObservableDictionary.cs
- RouteItem.cs
- PropertyGridCommands.cs
- UInt32Converter.cs
- WindowsFormsSynchronizationContext.cs
- TextElementAutomationPeer.cs
- HostingPreferredMapPath.cs
- StrokeCollection.cs
- GlobalProxySelection.cs
- PeerNameRecordCollection.cs
- WrapPanel.cs
- BitmapEffectCollection.cs
- WindowCollection.cs
- SolidColorBrush.cs
- XmlQueryOutput.cs
- StyleSheetRefUrlEditor.cs
- ClientRuntime.cs
- SoapHeaderException.cs
- OdbcErrorCollection.cs
- Geometry3D.cs
- log.cs
- MenuAutomationPeer.cs
- AdapterUtil.cs
- AsmxEndpointPickerExtension.cs
- HebrewNumber.cs
- XamlClipboardData.cs
- WebPartTransformerAttribute.cs
- ActivityStateRecord.cs
- SoapSchemaImporter.cs
- TextEditorThreadLocalStore.cs
- MemberProjectionIndex.cs
- WinEventHandler.cs
- PropertyManager.cs
- XamlWriter.cs
- NullableIntSumAggregationOperator.cs
- SerialPinChanges.cs
- SchemaLookupTable.cs
- ComponentResourceManager.cs
- columnmapfactory.cs
- TextRangeBase.cs
- InternalControlCollection.cs
- IncrementalHitTester.cs
- ReceiveContent.cs
- CodePrimitiveExpression.cs
- SqlCommand.cs
- StructureChangedEventArgs.cs
- PropertyInfoSet.cs
- ModuleBuilderData.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- GroupQuery.cs
- SupportingTokenDuplexChannel.cs
- PrivilegedConfigurationManager.cs
- XmlLanguage.cs
- UnknownBitmapEncoder.cs
- ObjectTag.cs
- SerializationBinder.cs
- SqlNotificationEventArgs.cs
- TextOnlyOutput.cs
- CurrentChangedEventManager.cs
- AuthorizationSection.cs
- XmlSchemaAttribute.cs
- StylusPointProperties.cs
- HMACSHA512.cs
- WindowsGraphicsWrapper.cs
- ReceiveSecurityHeaderEntry.cs
- BehaviorEditorPart.cs
- ScrollPattern.cs
- ListItemParagraph.cs
- objectresult_tresulttype.cs
- ImpersonationContext.cs
- ComPlusSynchronizationContext.cs
- FilteredDataSetHelper.cs
- DocumentViewerHelper.cs
- PackageFilter.cs
- DocumentViewerBase.cs
- Transform.cs
- ProxyHwnd.cs
- EdmFunction.cs
- WindowsListViewScroll.cs