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
- FixedNode.cs
- ThreadExceptionDialog.cs
- regiisutil.cs
- DbProviderSpecificTypePropertyAttribute.cs
- XmlEncoding.cs
- SmiSettersStream.cs
- Int64AnimationBase.cs
- ToolStripRenderEventArgs.cs
- HtmlHistory.cs
- WrappedIUnknown.cs
- DependencyObject.cs
- DirectionalLight.cs
- UriTemplateEquivalenceComparer.cs
- DbConnectionFactory.cs
- SystemIPAddressInformation.cs
- FixedSchema.cs
- PageTheme.cs
- TextRangeBase.cs
- HttpCapabilitiesSectionHandler.cs
- ButtonFlatAdapter.cs
- UdpDiscoveryEndpointElement.cs
- SettingsBase.cs
- HwndKeyboardInputProvider.cs
- HtmlControlDesigner.cs
- KnownTypesProvider.cs
- HtmlTable.cs
- UserPersonalizationStateInfo.cs
- MulticastIPAddressInformationCollection.cs
- HebrewCalendar.cs
- XmlSortKeyAccumulator.cs
- DataChangedEventManager.cs
- SchemaTypeEmitter.cs
- SchemaImporterExtensionElementCollection.cs
- AsynchronousChannelMergeEnumerator.cs
- MessageSecurityOverMsmq.cs
- TypeSystem.cs
- PropertyBuilder.cs
- ProgressBar.cs
- CornerRadiusConverter.cs
- DataControlButton.cs
- ToolStripMenuItem.cs
- SrgsText.cs
- LazyInitializer.cs
- TimeSpanStorage.cs
- PartitionedDataSource.cs
- DeclaredTypeElementCollection.cs
- HttpCapabilitiesEvaluator.cs
- ByteAnimation.cs
- SecUtil.cs
- PhysicalFontFamily.cs
- ClientEventManager.cs
- BinHexEncoder.cs
- InfoCardListRequest.cs
- TextLine.cs
- PanelDesigner.cs
- SizeAnimation.cs
- CodeStatement.cs
- EventMappingSettingsCollection.cs
- TaskExceptionHolder.cs
- HierarchicalDataSourceControl.cs
- HttpException.cs
- CompareValidator.cs
- SeparatorAutomationPeer.cs
- EventArgs.cs
- NameValueFileSectionHandler.cs
- DesignSurfaceManager.cs
- ProfileGroupSettingsCollection.cs
- AnchoredBlock.cs
- PropertyMappingExceptionEventArgs.cs
- DuplexChannel.cs
- NativeMethods.cs
- DelegatedStream.cs
- ConfigurationFileMap.cs
- OracleFactory.cs
- WebZone.cs
- InvokePattern.cs
- DrawingBrush.cs
- NotSupportedException.cs
- PropertyEntry.cs
- SplitterPanel.cs
- FixedSOMElement.cs
- GridViewCancelEditEventArgs.cs
- UnicastIPAddressInformationCollection.cs
- NetworkInterface.cs
- ExtractCollection.cs
- AutoSizeToolBoxItem.cs
- Propagator.JoinPropagator.cs
- SmtpSection.cs
- _TLSstream.cs
- NullExtension.cs
- SspiSecurityToken.cs
- RayHitTestParameters.cs
- Form.cs
- ReachVisualSerializer.cs
- Geometry3D.cs
- RecipientInfo.cs
- MethodResolver.cs
- XmlReaderDelegator.cs
- ContentControl.cs
- RC2CryptoServiceProvider.cs