Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / Mail / DotAtomReader.cs / 1305376 / DotAtomReader.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net.Mail { using System; using System.Diagnostics; using System.Net.Mime; using System.Text; // // RFC 2822 Section 3.2.4 - Atom, Dot-Atom // // A Dot-Atom is a string of ASCII characters separated by dots. Dots would normally not be allowed at the start // or end, but we do allow dots at the end for compatibility with other mail clients. We also allow // multiple consecutive dots, which would normally be invalid. // internal static class DotAtomReader { // Reads a Dot Atom in reverse. // // Preconditions: // - Index must be within the bounds of the data string. // // Return value: // - The first index of of a character not valid in a dot-atom. It is then up to the caller to // determine if the next character is a valid delimiter. // e.g. "user.name@domain.com", starting at index 19 (m) returns 9 (@). // e.g. "user.name@dom in.com", starting at index 19 (m) returns 13 (space). // - -1 if the dot-atom section terminated at the start of the data string. // e.g. "user.name@domain.com", starting at index 8 (e) returns -1. // // A FormatException will be thrown if: // - The initial character at data[index] is invalid in a dot-atom. // e.g. "a@b.com", starting at index 1 (@). // - The leading character is a dot. // e.g. "a@.b.com", starting at index 7 (m), throws because the leading char (index 2) is a dot. // internal static int ReadReverse(string data, int index) { Debug.Assert(0 <= index && index < data.Length, "index was outside the bounds of the string: " + index); int startIndex = index; // Scan for the first Unicode or invalid chars (including whitespace) for ( ; 0 <= index; index--) { if (data[index] > MailBnfHelper.Ascii7bitMaxValue // Unicode || (data[index] != MailBnfHelper.Dot && !MailBnfHelper.Atext[data[index]])) // Invalid char { break; } } // Check for empty/invalid dot-atom if (startIndex == index) { throw new FormatException(SR.GetString(SR.MailHeaderFieldInvalidCharacter, data[index])); } // Check for leading dot else if (data[index + 1] == MailBnfHelper.Dot) { throw new FormatException(SR.GetString(SR.MailHeaderFieldInvalidCharacter, MailBnfHelper.Dot)); } return index; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net.Mail { using System; using System.Diagnostics; using System.Net.Mime; using System.Text; // // RFC 2822 Section 3.2.4 - Atom, Dot-Atom // // A Dot-Atom is a string of ASCII characters separated by dots. Dots would normally not be allowed at the start // or end, but we do allow dots at the end for compatibility with other mail clients. We also allow // multiple consecutive dots, which would normally be invalid. // internal static class DotAtomReader { // Reads a Dot Atom in reverse. // // Preconditions: // - Index must be within the bounds of the data string. // // Return value: // - The first index of of a character not valid in a dot-atom. It is then up to the caller to // determine if the next character is a valid delimiter. // e.g. "user.name@domain.com", starting at index 19 (m) returns 9 (@). // e.g. "user.name@dom in.com", starting at index 19 (m) returns 13 (space). // - -1 if the dot-atom section terminated at the start of the data string. // e.g. "user.name@domain.com", starting at index 8 (e) returns -1. // // A FormatException will be thrown if: // - The initial character at data[index] is invalid in a dot-atom. // e.g. "a@b.com", starting at index 1 (@). // - The leading character is a dot. // e.g. "a@.b.com", starting at index 7 (m), throws because the leading char (index 2) is a dot. // internal static int ReadReverse(string data, int index) { Debug.Assert(0 <= index && index < data.Length, "index was outside the bounds of the string: " + index); int startIndex = index; // Scan for the first Unicode or invalid chars (including whitespace) for ( ; 0 <= index; index--) { if (data[index] > MailBnfHelper.Ascii7bitMaxValue // Unicode || (data[index] != MailBnfHelper.Dot && !MailBnfHelper.Atext[data[index]])) // Invalid char { break; } } // Check for empty/invalid dot-atom if (startIndex == index) { throw new FormatException(SR.GetString(SR.MailHeaderFieldInvalidCharacter, data[index])); } // Check for leading dot else if (data[index + 1] == MailBnfHelper.Dot) { throw new FormatException(SR.GetString(SR.MailHeaderFieldInvalidCharacter, MailBnfHelper.Dot)); } return index; } } } // 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
- Repeater.cs
- ProxyGenerator.cs
- LOSFormatter.cs
- InputProcessorProfiles.cs
- IgnoreSectionHandler.cs
- DbMetaDataCollectionNames.cs
- LinkedResourceCollection.cs
- DomNameTable.cs
- RichTextBoxConstants.cs
- PageAsyncTaskManager.cs
- TcpHostedTransportConfiguration.cs
- DetailsViewUpdateEventArgs.cs
- GeneralTransform.cs
- SchemaNames.cs
- cache.cs
- WebPartConnectionsConnectVerb.cs
- File.cs
- UpdatableWrapper.cs
- DetectEofStream.cs
- StyleXamlParser.cs
- HttpPostedFile.cs
- DecoderBestFitFallback.cs
- HGlobalSafeHandle.cs
- UniqueEventHelper.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- ScaleTransform3D.cs
- ReachPageContentCollectionSerializerAsync.cs
- ExecutionPropertyManager.cs
- IgnoreFlushAndCloseStream.cs
- DateTimeUtil.cs
- WebServiceData.cs
- FontFamilyValueSerializer.cs
- DocumentSequence.cs
- NativeMethods.cs
- StrokeRenderer.cs
- XmlChoiceIdentifierAttribute.cs
- OdbcDataReader.cs
- LayoutTable.cs
- CaseInsensitiveComparer.cs
- CommandHelper.cs
- XmlAttributes.cs
- AnimationException.cs
- NameObjectCollectionBase.cs
- TableSectionStyle.cs
- UInt32Converter.cs
- SqlProfileProvider.cs
- NullPackagingPolicy.cs
- ColumnMap.cs
- TrackingServices.cs
- HtmlEncodedRawTextWriter.cs
- MethodBody.cs
- DotExpr.cs
- GeometryModel3D.cs
- TempEnvironment.cs
- NotifyCollectionChangedEventArgs.cs
- CommandLibraryHelper.cs
- Thread.cs
- GreaterThanOrEqual.cs
- HistoryEventArgs.cs
- ProcessManager.cs
- CollectionChangeEventArgs.cs
- EntityViewGenerationAttribute.cs
- FastPropertyAccessor.cs
- baseaxisquery.cs
- TreeViewHitTestInfo.cs
- DataBoundControlParameterTarget.cs
- CdpEqualityComparer.cs
- TextTreeNode.cs
- WindowsButton.cs
- UriTemplateLiteralPathSegment.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- BufferBuilder.cs
- DeobfuscatingStream.cs
- QilPatternVisitor.cs
- DataGridAutoFormatDialog.cs
- documentation.cs
- TimelineCollection.cs
- WmlSelectionListAdapter.cs
- DBSqlParserTableCollection.cs
- ClientSideQueueItem.cs
- LogReservationCollection.cs
- StdValidatorsAndConverters.cs
- HttpInputStream.cs
- XmlBaseReader.cs
- FileInfo.cs
- ImageList.cs
- TextBlockAutomationPeer.cs
- StylusCollection.cs
- TextTrailingCharacterEllipsis.cs
- DesignerOptions.cs
- APCustomTypeDescriptor.cs
- SecurityState.cs
- CommentEmitter.cs
- ProcessModelSection.cs
- MobileErrorInfo.cs
- grammarelement.cs
- FlowDocument.cs
- DeviceContext.cs
- BuildProvider.cs
- XmlSchemaComplexContentExtension.cs