Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / Mail / EncodedStreamFactory.cs / 1305376 / EncodedStreamFactory.cs
namespace System.Net.Mime { using System; using System.IO; using System.Text; internal class EncodedStreamFactory { //RFC 2822: no encoded-word line should be longer than 76 characters not including the soft CRLF //since the header length is unknown (if there even is one) we're going to be slightly more conservative //and cut off at 70. This will also prevent any other folding behavior from being triggered anywhere //in the code private const int defaultMaxLineLength = 70; //default buffer size for encoder private const int initialBufferSize = 1024; internal static int DefaultMaxLineLength { get { return defaultMaxLineLength; } } //get a raw encoder, not for use with header encoding internal IEncodableStream GetEncoder(TransferEncoding encoding, Stream stream) { //raw encoder if (encoding == TransferEncoding.Base64) return new Base64Stream(stream, new Base64WriteStateInfo(initialBufferSize, new byte[0], new byte[0], DefaultMaxLineLength)); //return a QuotedPrintable stream because this is not being used for header encoding if (encoding == TransferEncoding.QuotedPrintable) return new QuotedPrintableStream(stream, true); if (encoding == TransferEncoding.SevenBit) return new SevenBitStream(stream); throw new NotSupportedException("Encoding Stream"); } //use for encoding headers internal IEncodableStream GetEncoderForHeader(Encoding encoding, bool useBase64Encoding, int headerTextLength) { WriteStateInfoBase writeState; byte[] header = CreateHeader(encoding, useBase64Encoding); byte[] footer = CreateFooter(); if (useBase64Encoding) { writeState = new Base64WriteStateInfo(initialBufferSize, header, footer, DefaultMaxLineLength); writeState.MimeHeaderLength = headerTextLength; return new Base64Stream((Base64WriteStateInfo)writeState); } writeState = new QuotedStringWriteStateInfo(initialBufferSize, header, footer, DefaultMaxLineLength); writeState.MimeHeaderLength = headerTextLength; return new QEncodedStream((QuotedStringWriteStateInfo)writeState); } //Create the header for what type of byte encoding is going to be used //based on the encoding type and if base64 encoding should be forced //sample header: =?utf-8?B? protected byte[] CreateHeader(Encoding encoding, bool useBase64Encoding) { //create encoded work header string header = String.Format("=?{0}?{1}?", encoding.HeaderName, useBase64Encoding ? "B" : "Q"); return Encoding.ASCII.GetBytes(header); } //creates the footer that marks the end of a quoted string of some sort protected byte[] CreateFooter() { byte[] footer = {(byte)'?', (byte)'='}; return footer; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Net.Mime { using System; using System.IO; using System.Text; internal class EncodedStreamFactory { //RFC 2822: no encoded-word line should be longer than 76 characters not including the soft CRLF //since the header length is unknown (if there even is one) we're going to be slightly more conservative //and cut off at 70. This will also prevent any other folding behavior from being triggered anywhere //in the code private const int defaultMaxLineLength = 70; //default buffer size for encoder private const int initialBufferSize = 1024; internal static int DefaultMaxLineLength { get { return defaultMaxLineLength; } } //get a raw encoder, not for use with header encoding internal IEncodableStream GetEncoder(TransferEncoding encoding, Stream stream) { //raw encoder if (encoding == TransferEncoding.Base64) return new Base64Stream(stream, new Base64WriteStateInfo(initialBufferSize, new byte[0], new byte[0], DefaultMaxLineLength)); //return a QuotedPrintable stream because this is not being used for header encoding if (encoding == TransferEncoding.QuotedPrintable) return new QuotedPrintableStream(stream, true); if (encoding == TransferEncoding.SevenBit) return new SevenBitStream(stream); throw new NotSupportedException("Encoding Stream"); } //use for encoding headers internal IEncodableStream GetEncoderForHeader(Encoding encoding, bool useBase64Encoding, int headerTextLength) { WriteStateInfoBase writeState; byte[] header = CreateHeader(encoding, useBase64Encoding); byte[] footer = CreateFooter(); if (useBase64Encoding) { writeState = new Base64WriteStateInfo(initialBufferSize, header, footer, DefaultMaxLineLength); writeState.MimeHeaderLength = headerTextLength; return new Base64Stream((Base64WriteStateInfo)writeState); } writeState = new QuotedStringWriteStateInfo(initialBufferSize, header, footer, DefaultMaxLineLength); writeState.MimeHeaderLength = headerTextLength; return new QEncodedStream((QuotedStringWriteStateInfo)writeState); } //Create the header for what type of byte encoding is going to be used //based on the encoding type and if base64 encoding should be forced //sample header: =?utf-8?B? protected byte[] CreateHeader(Encoding encoding, bool useBase64Encoding) { //create encoded work header string header = String.Format("=?{0}?{1}?", encoding.HeaderName, useBase64Encoding ? "B" : "Q"); return Encoding.ASCII.GetBytes(header); } //creates the footer that marks the end of a quoted string of some sort protected byte[] CreateFooter() { byte[] footer = {(byte)'?', (byte)'='}; return footer; } } } // 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
- PropertyAccessVisitor.cs
- ClientUrlResolverWrapper.cs
- UserUseLicenseDictionaryLoader.cs
- CriticalExceptions.cs
- InputLangChangeRequestEvent.cs
- RewritingProcessor.cs
- StringCollectionMarkupSerializer.cs
- SqlClientWrapperSmiStreamChars.cs
- FileEnumerator.cs
- FileDialogPermission.cs
- FontEmbeddingManager.cs
- RolePrincipal.cs
- PageCodeDomTreeGenerator.cs
- IOThreadTimer.cs
- HttpProcessUtility.cs
- SessionStateItemCollection.cs
- DateTimeConverter.cs
- PerformanceCounterCategory.cs
- basevalidator.cs
- RelationshipEnd.cs
- _TimerThread.cs
- SingleStorage.cs
- OleDbCommand.cs
- BatchParser.cs
- XmlSiteMapProvider.cs
- MenuItem.cs
- ScrollItemPattern.cs
- TypeUtils.cs
- TypeSystem.cs
- TargetFrameworkUtil.cs
- EditorPartChrome.cs
- XPathDocumentBuilder.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- CheckBoxPopupAdapter.cs
- XmlElement.cs
- ConnectionInterfaceCollection.cs
- TabItem.cs
- PropertyTabChangedEvent.cs
- ConsoleCancelEventArgs.cs
- JsonCollectionDataContract.cs
- UriSection.cs
- odbcmetadatacolumnnames.cs
- Simplifier.cs
- ContainerSelectorBehavior.cs
- XmlSerializerSection.cs
- ObjectStateEntry.cs
- XmlnsCache.cs
- SystemTcpStatistics.cs
- SerializableAttribute.cs
- TransformerConfigurationWizardBase.cs
- SymLanguageType.cs
- ProviderCommandInfoUtils.cs
- base64Transforms.cs
- PKCS1MaskGenerationMethod.cs
- EntityViewGenerationAttribute.cs
- HttpConfigurationSystem.cs
- GregorianCalendarHelper.cs
- ScriptResourceAttribute.cs
- OlePropertyStructs.cs
- DbParameterCollection.cs
- CancelEventArgs.cs
- DataControlField.cs
- CompilerErrorCollection.cs
- RequestSecurityTokenForGetBrowserToken.cs
- MaskDescriptors.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- MarkupExtensionReturnTypeAttribute.cs
- SmiGettersStream.cs
- CellParaClient.cs
- GridViewColumnHeader.cs
- TransactionScopeDesigner.cs
- AccessKeyManager.cs
- TransformerTypeCollection.cs
- TemplateBindingExpression.cs
- SettingsProviderCollection.cs
- PackWebResponse.cs
- BasicCommandTreeVisitor.cs
- HttpGetServerProtocol.cs
- OracleTimeSpan.cs
- documentsequencetextpointer.cs
- ColorAnimation.cs
- VarRefManager.cs
- HiddenFieldPageStatePersister.cs
- StringKeyFrameCollection.cs
- NestPullup.cs
- BindUriHelper.cs
- TextTreeInsertElementUndoUnit.cs
- ServiceModelSecurityTokenTypes.cs
- SchemaUtility.cs
- TextMetrics.cs
- ProcessRequestArgs.cs
- MetadataProperty.cs
- DBDataPermissionAttribute.cs
- Version.cs
- KeyConverter.cs
- SqlProviderServices.cs
- BinaryConverter.cs
- ReachDocumentPageSerializerAsync.cs
- SectionVisual.cs
- FacetValues.cs