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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #if !defined(__IMCVCODC_H__)
18 #define __IMCVCODC_H__
26 #include <mentact.h> // CMsgActive
32 #define KBase64 _L("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=")
33 #define KCharFormat _L("%c")
35 // Maximum length allowed for an 'encoded-word' rfc2047
36 const TInt KEncodedWordMaxLength = 75;
38 // All encoding information except data and charset name length. =?B?=? => 7
39 const TInt KMaxEncodedInformationLength = 7;
41 // Length of the field name, eg "Subject: ". This may change as other fields are processed.
42 const TInt KMaxHeaderFieldNameLength = 12;
44 const TInt KImCvFinished=(-1);
45 const TInt KImCvAdvance=(1);
48 // error states involved in sending attachments etc.
64 enum TImBodyConvAlgorithm
75 // Used in CImSendConvert
86 struct SAttachmentInfo
98 // Shared implementation code
99 //----------------------------------------------------------------------------------------
101 //----------------------------------------------------------------------------------------
108 // base64 and UU coding defines.
109 enum EMaskValues{ ESixBitMask = 0x3F, EEightBitMask = 0xFF };
110 enum EMaskShiftValues{ ESix = 6, EFour = 4, ETwo = 2, EZero = 0 };
113 virtual TInt Encode( const TDesC8& aSrcString, TDes8& rDestString)=0 ;
114 virtual TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine)=0;
118 inline TBool IsDigit( TChar aChar );
122 // Interface for sending file data.
123 //----------------------------------------------------------------------------------------
124 class TImFileCodec : public TImCodec
125 //----------------------------------------------------------------------------------------
132 virtual TInt PrefixNextLineL( TDes8& rOutputLine, const TFileName& aName, TInt& rPaddingCount );
133 virtual TInt PostfixNextLine( TDes8& rOutputLine, TInt& rPaddingCount );
134 virtual void Initialise();
141 // Dummy, just copies
142 //----------------------------------------------------------------------------------------
143 class TImCodecNull : public TImFileCodec
144 //----------------------------------------------------------------------------------------
151 TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
152 TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine);
155 // Quoted-printable encoding/decoding
157 //----------------------------------------------------------------------------------------
158 class TImCodecQP : public TImFileCodec
159 //----------------------------------------------------------------------------------------
166 IMPORT_C TImCodecQP();
167 IMPORT_C TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
168 IMPORT_C TBool Decode( const TDesC8& aInputLine, TDes8& rOutputLine);
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 );
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);
180 inline TUint8 ReplacementChar( TChar aControlChar );
181 inline TBool IsPlain( TChar aChar );
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);
191 TPtrC8 iPlainCharList;
192 TPtrC8 iEncodeCharList;
199 // Base64 coding/decoding
201 //----------------------------------------------------------------------------------------
202 class TImCodecB64 : public TImFileCodec
203 //----------------------------------------------------------------------------------------
210 // base64 coding defines
211 enum{ EPadChar = 64 };
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();
220 TInt DoEncode(const TDesC8& aSrcString, TDes8& rDestString, TBool aInsertLineBreaks);
224 TInt iMaskShiftStored;
227 class TImCodecB64WithLineBreaks : public TImCodecB64
234 TInt Encode(const TDesC8& aSrcString, TDes8& rDestString);
238 // UU coding/decoding
240 //----------------------------------------------------------------------------------------
241 class TImCodecUU : public TImFileCodec
242 //----------------------------------------------------------------------------------------
251 enum{ ESpace = 32, EBackQuote = 96 };
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 );
267 void AppendFilenameL( TDes8& rOutputLine, const TFileName& aName );
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.
278 //----------------------------------------------------------------------------------------
279 class CImConvertHeader : public CBase
280 //----------------------------------------------------------------------------------------
287 IMPORT_C static CImConvertHeader* NewL(CImConvertCharconv& aConverter);
290 IMPORT_C void SetMessageType(TBool aIsMIME);
291 IMPORT_C void DecodeAllHeaderFieldsL(CImHeader& rHeader);
293 // Functions for decoding & converting descriptors
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);
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);
304 IMPORT_C void EncodeHeaderFieldL(const TDesC& aBufIn, RBuf8& aBufOut,
305 const TUint aCharset, const TImHeaderEncodingInfo::TEncodingType aType, TBool aIsAddressField);
307 IMPORT_C TBool FindEncodedWord(TPtrC8& aData, TInt& aInit,TInt& rStart, TInt& rEnd);
309 void Append(TDes& aBuffer, const TDesC8& aAddition);
310 inline CImConvertCharconv& CharConv();
312 IMPORT_C TUint OverrideCharset() const;
313 IMPORT_C void SetOverrideCharset(TUint aCharset);
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);
323 TBool DecodeWordL(const TDesC8& aBufIn, TDes& aBufOut, TInt rRemainder);
324 void DecodeRecipientListL( CDesCArray& aArray);
325 void DecodeFieldL(const TDesC& aField);
327 TBool DoCharsetConversionL(const TDesC& aDataToConvert, RBuf8& aEncodedWord);
329 void DoEncodingL(RBuf8& aEncodedWord, TImHeaderEncodingInfo& aInfo);
331 TInt AddEncodedWordInfoL(const TDesC8& aEncodedWord, RBuf8& aBufOut,
332 TImHeaderEncodingInfo& aInfo, const TDesC8& aCharsetName);
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);
339 TImHeaderEncodingInfo iEncodingInfo;
340 CImConvertCharconv& iCharConv;
342 // Get access to QP/ Base64 encoding/decoding functions
343 TImCodecB64 iB64Codec;
346 // Need in the narrow build, to check if possible to convert to/from
347 // the machines character set.
348 TUint iCharacterSetId;
352 // Converted static variables used in EncodeWordL()
353 TBool isMIMEMessageHeader;
354 TUint iOverrideCharset;
358 #include <imcvcodc.inl>