epoc32/include/imcvcodc.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
     1.1 --- a/epoc32/include/imcvcodc.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/imcvcodc.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,360 @@
     1.4 -imcvcodc.h
     1.5 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +// All rights reserved.
     1.7 +// This component and the accompanying materials are made available
     1.8 +// 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
     1.9 +// which accompanies this distribution, and is available
    1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.11 +//
    1.12 +// Initial Contributors:
    1.13 +// Nokia Corporation - initial contribution.
    1.14 +//
    1.15 +// Contributors:
    1.16 +//
    1.17 +// Description:
    1.18 +//
    1.19 +
    1.20 +
    1.21 +#if !defined(__IMCVCODC_H__)
    1.22 +#define __IMCVCODC_H__
    1.23 +
    1.24 +#include <s32buf.h>
    1.25 +#include <s32stor.h>
    1.26 +#include <txtrich.h>
    1.27 +#include <miutatch.h>
    1.28 +#include <miutconv.h>
    1.29 +#include <miuthdr.h>
    1.30 +#include <mentact.h>		// CMsgActive
    1.31 +
    1.32 +#include <imcvdata.h>
    1.33 +#include <imcvtext.h>
    1.34 +#include <imutdll.h>
    1.35 +
    1.36 +#define KBase64 _L("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=")
    1.37 +#define KCharFormat _L("%c")
    1.38 +
    1.39 + // Maximum length allowed for an 'encoded-word' rfc2047
    1.40 +const TInt KEncodedWordMaxLength = 75;
    1.41 +
    1.42 +// All encoding information except data and charset name length. =?B?=?    => 7
    1.43 +const TInt KMaxEncodedInformationLength = 7;
    1.44 +
    1.45 +// Length of the field name, eg "Subject: ". This may change as other fields are processed.  
    1.46 +const TInt KMaxHeaderFieldNameLength = 12;
    1.47 +
    1.48 +const TInt KImCvFinished=(-1);
    1.49 +const TInt KImCvAdvance=(1);
    1.50 +
    1.51 +
    1.52 +// error states involved in sending attachments etc.
    1.53 +/**
    1.54 +@internalComponent
    1.55 +@deprecated
    1.56 +*/
    1.57 +enum TIattErrorCode
    1.58 +	{
    1.59 +	KImAttNoError = 0,
    1.60 +	KImAttFinished = 1
    1.61 +	};
    1.62 +
    1.63 +
    1.64 +/**
    1.65 +@internalComponent
    1.66 +@released
    1.67 +*/
    1.68 +enum TImBodyConvAlgorithm
    1.69 +	{
    1.70 +	ENoAlgorithm,
    1.71 +	EQPEncode,
    1.72 +	EQPDecode,
    1.73 +	EBase64Encode,
    1.74 +	EBase64Decode,
    1.75 +	EUUEncode,
    1.76 +	EUUDecode
    1.77 +	};
    1.78 +	
    1.79 +// Used in CImSendConvert
    1.80 +/**
    1.81 +@internalComponent
    1.82 +@deprecated
    1.83 +*/
    1.84 +enum TImSendEncoding 
    1.85 +	{ 
    1.86 +	ESendNoAlgorithm,
    1.87 +	ESendMimeAlgorithm
    1.88 +	};	
    1.89 +
    1.90 +struct SAttachmentInfo
    1.91 +/**
    1.92 +@internalComponent
    1.93 +@released
    1.94 +*/
    1.95 +	{
    1.96 +	TInt iSize;
    1.97 +	TFileName iName;
    1.98 +	TFileName iPath;
    1.99 +	TBool iComplete;
   1.100 +	};
   1.101 +
   1.102 +// Shared implementation code	
   1.103 +//----------------------------------------------------------------------------------------
   1.104 +class TImCodec
   1.105 +//----------------------------------------------------------------------------------------
   1.106 +/**
   1.107 +@internalAll
   1.108 +@released
   1.109 +*/
   1.110 +	{
   1.111 +protected:
   1.112 +	// base64 and UU coding defines.
   1.113 +	enum EMaskValues{ ESixBitMask = 0x3F, EEightBitMask = 0xFF };
   1.114 +	enum EMaskShiftValues{ ESix = 6, EFour = 4, ETwo = 2, EZero = 0 };
   1.115 +
   1.116 +public:
   1.117 +	virtual TInt Encode( const TDesC8& aSrcString, TDes8& rDestString)=0 ;
   1.118 +	virtual TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine)=0;
   1.119 +
   1.120 +protected:
   1.121 +	// TImCodec();
   1.122 +	inline TBool IsDigit( TChar aChar );
   1.123 +	};
   1.124 +
   1.125 +
   1.126 +// Interface for sending file data.
   1.127 +//----------------------------------------------------------------------------------------
   1.128 +class TImFileCodec : public TImCodec
   1.129 +//----------------------------------------------------------------------------------------
   1.130 +/**
   1.131 +@internalAll
   1.132 +@released
   1.133 +*/
   1.134 +	{
   1.135 +public:
   1.136 +	virtual TInt PrefixNextLineL( TDes8& rOutputLine, const TFileName& aName, TInt& rPaddingCount );
   1.137 +	virtual TInt PostfixNextLine( TDes8& rOutputLine, TInt& rPaddingCount );
   1.138 +	virtual void Initialise();
   1.139 +
   1.140 +protected:
   1.141 +	TInt iPrefixState;
   1.142 +	TInt iPostfixState;
   1.143 +	};	
   1.144 +
   1.145 +// Dummy, just copies
   1.146 +//----------------------------------------------------------------------------------------
   1.147 +class TImCodecNull :  public TImFileCodec
   1.148 +//----------------------------------------------------------------------------------------
   1.149 +/**
   1.150 +@internalComponent
   1.151 +@released
   1.152 +*/
   1.153 +	{
   1.154 +public:
   1.155 +	TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
   1.156 +	TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine);
   1.157 +	};
   1.158 +	
   1.159 +// Quoted-printable encoding/decoding
   1.160 +
   1.161 +//----------------------------------------------------------------------------------------
   1.162 +class TImCodecQP : public TImFileCodec
   1.163 +//----------------------------------------------------------------------------------------
   1.164 +/**
   1.165 +@internalAll
   1.166 +@released
   1.167 +*/
   1.168 +	{
   1.169 +public:
   1.170 +	IMPORT_C TImCodecQP();
   1.171 +	IMPORT_C TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
   1.172 +	IMPORT_C TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine);
   1.173 +
   1.174 +	// Not to be used anymore..
   1.175 +	IMPORT_C TInt EncodeRichText( const TDesC8& aInputLine, TDes8& rOutputLine);
   1.176 +	IMPORT_C TInt DecodeRichText( const TDesC8& aSrcString, TDes& rDestString );
   1.177 +
   1.178 +	// Functions which allow flexiblity. Can replace the '=' char or add characters..
   1.179 +	// to what is defined as 'plain.
   1.180 +	inline void AddPlainChar(const TDesC8&  aCharList );
   1.181 +	inline void AddEncodeChar(const TDesC8&  aCharList );
   1.182 +	inline void SetQPChar( TUint8 aChar);
   1.183 +
   1.184 +	inline TUint8 ReplacementChar( TChar aControlChar );
   1.185 +	inline TBool IsPlain( TChar aChar );
   1.186 +
   1.187 +private:
   1.188 +	TBool SmartBreak( TInt written, const TDesC8& pSource );
   1.189 +	inline TBool IsBreakable( TChar aChar);
   1.190 +	inline void AddSoftLineBreak(TDes8& aPtr, TInt& aPadding, TInt& aWritten);
   1.191 +	inline void AddSoftLineBreak(const TUint8* apEnd, TUint8* aPtr, TInt& aPadding, TInt& aWritten);
   1.192 +
   1.193 +private:
   1.194 +	TUint8 iQPCharacter;
   1.195 +	TPtrC8 iPlainCharList;  
   1.196 +	TPtrC8 iEncodeCharList;  
   1.197 +
   1.198 +	TInt iPaddingCount;
   1.199 +	};
   1.200 +
   1.201 +
   1.202 +
   1.203 +// Base64 coding/decoding
   1.204 +
   1.205 +//----------------------------------------------------------------------------------------
   1.206 +class TImCodecB64 : public TImFileCodec
   1.207 +//----------------------------------------------------------------------------------------
   1.208 +/**
   1.209 +@publishedAll
   1.210 +@released
   1.211 +*/
   1.212 +	{
   1.213 +private:
   1.214 +	// base64 coding defines
   1.215 +	enum{ EPadChar = 64 };
   1.216 +
   1.217 +public:
   1.218 +	IMPORT_C TImCodecB64();
   1.219 +	IMPORT_C TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
   1.220 +	IMPORT_C TBool Decode( const TDesC8& aSrcString, TDes8& rDestString);
   1.221 + 	IMPORT_C void  Initialise();
   1.222 +
   1.223 +protected:
   1.224 +	TInt DoEncode(const TDesC8& aSrcString, TDes8& rDestString, TBool aInsertLineBreaks);
   1.225 +
   1.226 +private:
   1.227 +	TInt iShiftStored;
   1.228 +	TInt iMaskShiftStored;
   1.229 +	};
   1.230 +
   1.231 +class TImCodecB64WithLineBreaks : public TImCodecB64
   1.232 +/**
   1.233 +@internalComponent
   1.234 +@released
   1.235 +*/
   1.236 +	{
   1.237 +public:
   1.238 +	TInt Encode(const TDesC8& aSrcString, TDes8& rDestString);
   1.239 +	};
   1.240 +
   1.241 +
   1.242 +// UU coding/decoding
   1.243 +
   1.244 +//----------------------------------------------------------------------------------------
   1.245 +class TImCodecUU : public TImFileCodec
   1.246 +//----------------------------------------------------------------------------------------
   1.247 +/**
   1.248 +@publishedAll
   1.249 +@released
   1.250 +*/
   1.251 +	{
   1.252 +private:
   1.253 +	// UU coding defines
   1.254 +
   1.255 +	enum{ ESpace = 32, EBackQuote = 96 };
   1.256 +
   1.257 +	enum TImBodyPostfix
   1.258 +		{
   1.259 +		EInvertedComma = 0,
   1.260 +		EEndString,
   1.261 +		EEndOfPostfix
   1.262 +		};
   1.263 +
   1.264 +public:
   1.265 +	IMPORT_C TImCodecUU();
   1.266 +	IMPORT_C TInt Encode( const TDesC8& aSrcString, TDes8& rDestString );
   1.267 +	IMPORT_C TBool Decode( const TDesC8& aSrcString, TDes8& rDestString );
   1.268 +	TInt PrefixNextLineL( TDes8& rOutputLine, const TFileName& aName, TInt& rPaddingCount );
   1.269 +	TInt PostfixNextLine( TDes8& rOutputLine, TInt& rPaddingCount );
   1.270 +private:
   1.271 +	void AppendFilenameL( TDes8& rOutputLine, const TFileName& aName );
   1.272 +	
   1.273 +	};
   1.274 +
   1.275 +
   1.276 +
   1.277 +
   1.278 +// For converting a text string to/from encoded form
   1.279 +// Note: 'Word' here has special meaning derived from the one defined in rfc2047.
   1.280 +// It refers to one encoding instance.
   1.281 +
   1.282 +//----------------------------------------------------------------------------------------
   1.283 +class CImConvertHeader : public CBase
   1.284 +//----------------------------------------------------------------------------------------
   1.285 +/**
   1.286 +@internalTechnology
   1.287 +@released
   1.288 +*/
   1.289 +	{
   1.290 +public:
   1.291 +	IMPORT_C static CImConvertHeader* NewL(CImConvertCharconv& aConverter);
   1.292 +	~CImConvertHeader();
   1.293 +
   1.294 +	IMPORT_C void SetMessageType(TBool aIsMIME); 
   1.295 +	IMPORT_C void DecodeAllHeaderFieldsL(CImHeader& rHeader); 
   1.296 +
   1.297 +	// Functions for decoding & converting descriptors
   1.298 +
   1.299 +	IMPORT_C void DecodeNonMIMEHeaderFieldL(const TDesC8& aBufIn, TDes& aBufOut); 
   1.300 +	IMPORT_C void DecodeHeaderFieldL(const TDesC8& aBufIn, TDes& aBufOut); 
   1.301 +	IMPORT_C void DecodeHeaderFieldL(const TDesC16& aBufIn, TDes& aBufOut); 
   1.302 +	IMPORT_C void ConvertHeaderFieldL(const TDesC16& aBufIn, RBuf8& aBufOut, TBool aIsAddressField); 
   1.303 +	
   1.304 +	// Header needed for retrieving encoding information, used in Send code.
   1.305 +    IMPORT_C void EncodeHeaderFieldL(const TDesC& aBufIn, RBuf8& aBufOut, 
   1.306 +            CArrayFix<TImHeaderEncodingInfo>* aInfoArray, TInt aState, TInt aArrayVal = 0);
   1.307 +
   1.308 +	IMPORT_C void EncodeHeaderFieldL(const TDesC& aBufIn, RBuf8& aBufOut,  
   1.309 +		                             const TUint aCharset, const TImHeaderEncodingInfo::TEncodingType aType, TBool aIsAddressField);
   1.310 +	
   1.311 +	IMPORT_C TBool FindEncodedWord(TPtrC8& aData, TInt& aInit,TInt& rStart, TInt& rEnd);
   1.312 +
   1.313 +	void Append(TDes& aBuffer, const TDesC8& aAddition);
   1.314 +	inline CImConvertCharconv& CharConv();
   1.315 +
   1.316 +	IMPORT_C TUint OverrideCharset() const;
   1.317 +	IMPORT_C void SetOverrideCharset(TUint aCharset);
   1.318 +
   1.319 +private:
   1.320 +	void ConstructL();
   1.321 +	CImConvertHeader(CImConvertCharconv&);
   1.322 +	// Functions dealing only with single 'encoded-word's
   1.323 +	void GetCharsetAndEncodeDataL(const TDesC& aBufIn, RBuf8& aBufOut, TImHeaderEncodingInfo& aInfo);
   1.324 +	void EncodeWordL(const TDesC& aBufIn, RBuf8& aBufOut, TImHeaderEncodingInfo& aInfo,
   1.325 +						const TDesC8& aCharsetName, RBuf8& aEncodedWord);
   1.326 +
   1.327 +	TBool DecodeWordL(const TDesC8& aBufIn, TDes& aBufOut, TInt rRemainder); 
   1.328 +	void DecodeRecipientListL( CDesCArray& aArray);
   1.329 +	void DecodeFieldL(const TDesC& aField);
   1.330 +
   1.331 +	TBool DoCharsetConversionL(const TDesC& aDataToConvert, RBuf8& aEncodedWord);
   1.332 +
   1.333 +	void DoEncodingL(RBuf8& aEncodedWord, TImHeaderEncodingInfo& aInfo);
   1.334 +
   1.335 +	TInt AddEncodedWordInfoL(const TDesC8& aEncodedWord, RBuf8& aBufOut, 
   1.336 +							 TImHeaderEncodingInfo& aInfo, const TDesC8& aCharsetName);
   1.337 +
   1.338 +	TBool IsAscii( TUint aChar ) const;
   1.339 +	TBool ExtractTextToEncode(const TDesC& aBufIn, TInt& rStart, TInt& rEnd, TBool aIsAddressField);
   1.340 +	void Insert(TDes8& aBuffer, const TDesC16& aInsert);
   1.341 +
   1.342 +private:
   1.343 +	TImHeaderEncodingInfo iEncodingInfo;
   1.344 +	CImConvertCharconv& iCharConv;
   1.345 +
   1.346 +	// Get access to QP/ Base64 encoding/decoding functions
   1.347 +	TImCodecB64	 iB64Codec;
   1.348 +	TImCodecQP	 iQPCodec;
   1.349 +
   1.350 +	// Need in the narrow build, to check if possible to convert to/from
   1.351 +	// the machines character set.
   1.352 +	TUint iCharacterSetId; 
   1.353 +
   1.354 +	CImHeader* iHeader;	
   1.355 +
   1.356 +	// Converted static variables used in EncodeWordL()
   1.357 +	TBool	isMIMEMessageHeader;
   1.358 +	TUint   iOverrideCharset;
   1.359 +	};
   1.360 +
   1.361 +
   1.362 +#include <imcvcodc.inl>
   1.363 +
   1.364 +#endif