epoc32/include/imcvcodc.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 
    17 #if !defined(__IMCVCODC_H__)
    18 #define __IMCVCODC_H__
    19 
    20 #include <s32buf.h>
    21 #include <s32stor.h>
    22 #include <txtrich.h>
    23 #include <miutatch.h>
    24 #include <miutconv.h>
    25 #include <miuthdr.h>
    26 #include <mentact.h>		// CMsgActive
    27 
    28 #include <imcvdata.h>
    29 #include <imcvtext.h>
    30 #include <imutdll.h>
    31 
    32 #define KBase64 _L("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=")
    33 #define KCharFormat _L("%c")
    34 
    35  // Maximum length allowed for an 'encoded-word' rfc2047
    36 const TInt KEncodedWordMaxLength = 75;
    37 
    38 // All encoding information except data and charset name length. =?B?=?    => 7
    39 const TInt KMaxEncodedInformationLength = 7;
    40 
    41 // Length of the field name, eg "Subject: ". This may change as other fields are processed.  
    42 const TInt KMaxHeaderFieldNameLength = 12;
    43 
    44 const TInt KImCvFinished=(-1);
    45 const TInt KImCvAdvance=(1);
    46 
    47 
    48 // error states involved in sending attachments etc.
    49 /**
    50 @internalComponent
    51 @deprecated
    52 */
    53 enum TIattErrorCode
    54 	{
    55 	KImAttNoError = 0,
    56 	KImAttFinished = 1
    57 	};
    58 
    59 
    60 /**
    61 @internalComponent
    62 @released
    63 */
    64 enum TImBodyConvAlgorithm
    65 	{
    66 	ENoAlgorithm,
    67 	EQPEncode,
    68 	EQPDecode,
    69 	EBase64Encode,
    70 	EBase64Decode,
    71 	EUUEncode,
    72 	EUUDecode
    73 	};
    74 	
    75 // Used in CImSendConvert
    76 /**
    77 @internalComponent
    78 @deprecated
    79 */
    80 enum TImSendEncoding 
    81 	{ 
    82 	ESendNoAlgorithm,
    83 	ESendMimeAlgorithm
    84 	};	
    85 
    86 struct SAttachmentInfo
    87 /**
    88 @internalComponent
    89 @released
    90 */
    91 	{
    92 	TInt iSize;
    93 	TFileName iName;
    94 	TFileName iPath;
    95 	TBool iComplete;
    96 	};
    97 
    98 // Shared implementation code	
    99 //----------------------------------------------------------------------------------------
   100 class TImCodec
   101 //----------------------------------------------------------------------------------------
   102 /**
   103 @internalAll
   104 @released
   105 */
   106 	{
   107 protected:
   108 	// base64 and UU coding defines.
   109 	enum EMaskValues{ ESixBitMask = 0x3F, EEightBitMask = 0xFF };
   110 	enum EMaskShiftValues{ ESix = 6, EFour = 4, ETwo = 2, EZero = 0 };
   111 
   112 public:
   113 	virtual TInt Encode( const TDesC8& aSrcString, TDes8& rDestString)=0 ;
   114 	virtual TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine)=0;
   115 
   116 protected:
   117 	// TImCodec();
   118 	inline TBool IsDigit( TChar aChar );
   119 	};
   120 
   121 
   122 // Interface for sending file data.
   123 //----------------------------------------------------------------------------------------
   124 class TImFileCodec : public TImCodec
   125 //----------------------------------------------------------------------------------------
   126 /**
   127 @internalAll
   128 @released
   129 */
   130 	{
   131 public:
   132 	virtual TInt PrefixNextLineL( TDes8& rOutputLine, const TFileName& aName, TInt& rPaddingCount );
   133 	virtual TInt PostfixNextLine( TDes8& rOutputLine, TInt& rPaddingCount );
   134 	virtual void Initialise();
   135 
   136 protected:
   137 	TInt iPrefixState;
   138 	TInt iPostfixState;
   139 	};	
   140 
   141 // Dummy, just copies
   142 //----------------------------------------------------------------------------------------
   143 class TImCodecNull :  public TImFileCodec
   144 //----------------------------------------------------------------------------------------
   145 /**
   146 @internalComponent
   147 @released
   148 */
   149 	{
   150 public:
   151 	TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
   152 	TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine);
   153 	};
   154 	
   155 // Quoted-printable encoding/decoding
   156 
   157 //----------------------------------------------------------------------------------------
   158 class TImCodecQP : public TImFileCodec
   159 //----------------------------------------------------------------------------------------
   160 /**
   161 @internalAll
   162 @released
   163 */
   164 	{
   165 public:
   166 	IMPORT_C TImCodecQP();
   167 	IMPORT_C TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
   168 	IMPORT_C TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine);
   169 
   170 	// Not to be used anymore..
   171 	IMPORT_C TInt EncodeRichText( const TDesC8& aInputLine, TDes8& rOutputLine);
   172 	IMPORT_C TInt DecodeRichText( const TDesC8& aSrcString, TDes& rDestString );
   173 
   174 	// Functions which allow flexiblity. Can replace the '=' char or add characters..
   175 	// to what is defined as 'plain.
   176 	inline void AddPlainChar(const TDesC8&  aCharList );
   177 	inline void AddEncodeChar(const TDesC8&  aCharList );
   178 	inline void SetQPChar( TUint8 aChar);
   179 
   180 	inline TUint8 ReplacementChar( TChar aControlChar );
   181 	inline TBool IsPlain( TChar aChar );
   182 
   183 private:
   184 	TBool SmartBreak( TInt written, const TDesC8& pSource );
   185 	inline TBool IsBreakable( TChar aChar);
   186 	inline void AddSoftLineBreak(TDes8& aPtr, TInt& aPadding, TInt& aWritten);
   187 	inline void AddSoftLineBreak(const TUint8* apEnd, TUint8* aPtr, TInt& aPadding, TInt& aWritten);
   188 
   189 private:
   190 	TUint8 iQPCharacter;
   191 	TPtrC8 iPlainCharList;  
   192 	TPtrC8 iEncodeCharList;  
   193 
   194 	TInt iPaddingCount;
   195 	};
   196 
   197 
   198 
   199 // Base64 coding/decoding
   200 
   201 //----------------------------------------------------------------------------------------
   202 class TImCodecB64 : public TImFileCodec
   203 //----------------------------------------------------------------------------------------
   204 /**
   205 @publishedAll
   206 @released
   207 */
   208 	{
   209 private:
   210 	// base64 coding defines
   211 	enum{ EPadChar = 64 };
   212 
   213 public:
   214 	IMPORT_C TImCodecB64();
   215 	IMPORT_C TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
   216 	IMPORT_C TBool Decode( const TDesC8& aSrcString, TDes8& rDestString);
   217  	IMPORT_C void  Initialise();
   218 
   219 protected:
   220 	TInt DoEncode(const TDesC8& aSrcString, TDes8& rDestString, TBool aInsertLineBreaks);
   221 
   222 private:
   223 	TInt iShiftStored;
   224 	TInt iMaskShiftStored;
   225 	};
   226 
   227 class TImCodecB64WithLineBreaks : public TImCodecB64
   228 /**
   229 @internalComponent
   230 @released
   231 */
   232 	{
   233 public:
   234 	TInt Encode(const TDesC8& aSrcString, TDes8& rDestString);
   235 	};
   236 
   237 
   238 // UU coding/decoding
   239 
   240 //----------------------------------------------------------------------------------------
   241 class TImCodecUU : public TImFileCodec
   242 //----------------------------------------------------------------------------------------
   243 /**
   244 @publishedAll
   245 @released
   246 */
   247 	{
   248 private:
   249 	// UU coding defines
   250 
   251 	enum{ ESpace = 32, EBackQuote = 96 };
   252 
   253 	enum TImBodyPostfix
   254 		{
   255 		EInvertedComma = 0,
   256 		EEndString,
   257 		EEndOfPostfix
   258 		};
   259 
   260 public:
   261 	IMPORT_C TImCodecUU();
   262 	IMPORT_C TInt Encode( const TDesC8& aSrcString, TDes8& rDestString );
   263 	IMPORT_C TBool Decode( const TDesC8& aSrcString, TDes8& rDestString );
   264 	TInt PrefixNextLineL( TDes8& rOutputLine, const TFileName& aName, TInt& rPaddingCount );
   265 	TInt PostfixNextLine( TDes8& rOutputLine, TInt& rPaddingCount );
   266 private:
   267 	void AppendFilenameL( TDes8& rOutputLine, const TFileName& aName );
   268 	
   269 	};
   270 
   271 
   272 
   273 
   274 // For converting a text string to/from encoded form
   275 // Note: 'Word' here has special meaning derived from the one defined in rfc2047.
   276 // It refers to one encoding instance.
   277 
   278 //----------------------------------------------------------------------------------------
   279 class CImConvertHeader : public CBase
   280 //----------------------------------------------------------------------------------------
   281 /**
   282 @internalTechnology
   283 @released
   284 */
   285 	{
   286 public:
   287 	IMPORT_C static CImConvertHeader* NewL(CImConvertCharconv& aConverter);
   288 	~CImConvertHeader();
   289 
   290 	IMPORT_C void SetMessageType(TBool aIsMIME); 
   291 	IMPORT_C void DecodeAllHeaderFieldsL(CImHeader& rHeader); 
   292 
   293 	// Functions for decoding & converting descriptors
   294 
   295 	IMPORT_C void DecodeNonMIMEHeaderFieldL(const TDesC8& aBufIn, TDes& aBufOut); 
   296 	IMPORT_C void DecodeHeaderFieldL(const TDesC8& aBufIn, TDes& aBufOut); 
   297 	IMPORT_C void DecodeHeaderFieldL(const TDesC16& aBufIn, TDes& aBufOut); 
   298 	IMPORT_C void ConvertHeaderFieldL(const TDesC16& aBufIn, RBuf8& aBufOut, TBool aIsAddressField); 
   299 	
   300 	// Header needed for retrieving encoding information, used in Send code.
   301     IMPORT_C void EncodeHeaderFieldL(const TDesC& aBufIn, RBuf8& aBufOut, 
   302             CArrayFix<TImHeaderEncodingInfo>* aInfoArray, TInt aState, TInt aArrayVal = 0);
   303 
   304 	IMPORT_C void EncodeHeaderFieldL(const TDesC& aBufIn, RBuf8& aBufOut,  
   305 		                             const TUint aCharset, const TImHeaderEncodingInfo::TEncodingType aType, TBool aIsAddressField);
   306 	
   307 	IMPORT_C TBool FindEncodedWord(TPtrC8& aData, TInt& aInit,TInt& rStart, TInt& rEnd);
   308 
   309 	void Append(TDes& aBuffer, const TDesC8& aAddition);
   310 	inline CImConvertCharconv& CharConv();
   311 
   312 	IMPORT_C TUint OverrideCharset() const;
   313 	IMPORT_C void SetOverrideCharset(TUint aCharset);
   314 
   315 private:
   316 	void ConstructL();
   317 	CImConvertHeader(CImConvertCharconv&);
   318 	// Functions dealing only with single 'encoded-word's
   319 	void GetCharsetAndEncodeDataL(const TDesC& aBufIn, RBuf8& aBufOut, TImHeaderEncodingInfo& aInfo);
   320 	void EncodeWordL(const TDesC& aBufIn, RBuf8& aBufOut, TImHeaderEncodingInfo& aInfo,
   321 						const TDesC8& aCharsetName, RBuf8& aEncodedWord);
   322 
   323 	TBool DecodeWordL(const TDesC8& aBufIn, TDes& aBufOut, TInt rRemainder); 
   324 	void DecodeRecipientListL( CDesCArray& aArray);
   325 	void DecodeFieldL(const TDesC& aField);
   326 
   327 	TBool DoCharsetConversionL(const TDesC& aDataToConvert, RBuf8& aEncodedWord);
   328 
   329 	void DoEncodingL(RBuf8& aEncodedWord, TImHeaderEncodingInfo& aInfo);
   330 
   331 	TInt AddEncodedWordInfoL(const TDesC8& aEncodedWord, RBuf8& aBufOut, 
   332 							 TImHeaderEncodingInfo& aInfo, const TDesC8& aCharsetName);
   333 
   334 	TBool IsAscii( TUint aChar ) const;
   335 	TBool ExtractTextToEncode(const TDesC& aBufIn, TInt& rStart, TInt& rEnd, TBool aIsAddressField);
   336 	void Insert(TDes8& aBuffer, const TDesC16& aInsert);
   337 
   338 private:
   339 	TImHeaderEncodingInfo iEncodingInfo;
   340 	CImConvertCharconv& iCharConv;
   341 
   342 	// Get access to QP/ Base64 encoding/decoding functions
   343 	TImCodecB64	 iB64Codec;
   344 	TImCodecQP	 iQPCodec;
   345 
   346 	// Need in the narrow build, to check if possible to convert to/from
   347 	// the machines character set.
   348 	TUint iCharacterSetId; 
   349 
   350 	CImHeader* iHeader;	
   351 
   352 	// Converted static variables used in EncodeWordL()
   353 	TBool	isMIMEMessageHeader;
   354 	TUint   iOverrideCharset;
   355 	};
   356 
   357 
   358 #include <imcvcodc.inl>
   359 
   360 #endif