1 // Copyright (c) 2003-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.
20 #include <msvapi.h> // TMsvEntry, CMsvOperation etc
21 #include <mentact.h> // CMsgActive
22 #include <miuthdr.h> // CImHeader, CImMimeHeader
23 #include <txtrich.h> // CRichText etc
24 #include <miutdef.h> // CImHeader, CImMimeHeader
28 #include <miutpars.h> // TImMessageField
30 #include <barsc.h> // RResourceFile
38 //#include <mmsvattachmentmanager.h>
41 //Content-Transfer-Encoding: types
42 _LIT8(KMimeQuotedPrintable, " quoted-printable");
43 _LIT8(KMimeApplOctet, " application/octet-stream");
44 _LIT8(KMime7Bit, " 7-bit");
45 _LIT8(KMimeBase64, " base64");
46 _LIT8(KMimeMime, "MIME*");
47 // Content-Disposition: types
48 _LIT8(KMimeInline, "inline");
49 _LIT8(KMimeAttachment, "attachment");
50 // Content-Type: types
51 _LIT8(KMimeMultipart, "multipart");
52 _LIT8(KMimeText, "text");
53 _LIT8(KMimeImage, "image");
54 _LIT8(KMimeAudio, "audio");
55 _LIT8(KMimeVideo, "video");
56 _LIT8(KMimeApplication, "application");
57 _LIT8(KMimeMessage, "message");
58 // Content-Type: Multipart types
59 _LIT8(KMimeMixed, "mixed");
60 _LIT8(KMimeRelated, "related");
61 _LIT8(KMimeAlternative, "alternative");
62 _LIT8(KMimeEncrypted, "encrypted");
63 _LIT8(KMimeParallel, "parallel");
64 _LIT8(KMimeDigest, "digest");
65 _LIT8(KMimeSigned, "signed");
66 // Content-Type: Text types
67 _LIT8(KMimeHtml, "html");
68 _LIT8(KMimePlain, "plain");
69 _LIT8(KMimeDirectory, "directory");
70 // Content-Type: Message types
71 _LIT8(KMimePartial, "partial");
72 _LIT8(KMimeExternal, "external-body");
73 _LIT8(KMimeRfc822, "rfc822");
74 // Content-Type: Directory types
75 _LIT8(KMimeProfile, "profile");
76 _LIT(KMimeVCardExtension, ".vcf");
77 _LIT8(KMimeVCalender, "vcalendar");
78 // Content-Type: Image, Audio, Video, Application types
79 _LIT8(KMimeBmp, "bmp");
80 _LIT8(KMimeGif, "gif");
81 _LIT8(KMimeJpeg, "jpeg");
82 _LIT8(KMimeTiff, "tiff");
83 _LIT8(KMimeWav, "wav");
84 _LIT8(KMimeZip, "x-gzip");
85 _LIT(KMimeHtmlExtension, ".html");
86 _LIT(KMiutMsgDefaultHtmlFileName, "attachment.html");
87 const TUid KUidMimeHeaders = {0x10204281};
89 class CImHtmlConverter;
91 class CImAttachmentManager;
92 class CMsvMimeHeaders;
93 class CMsvPlainBodyText;
94 class CImPlainBodyText;
96 class TImCreateMessageOptions
103 TMsvPartList iMsvPartList;
104 TMsvEmailTypeList iMsvEmailTypeList;
108 // Mixin provides interface to Browser control to resolve MHTML URIs.
110 class MImURITranslator
111 /** Translates a URI in an MHTML message into a message body part file name.
113 MHTML messages may contain multiple HTML body parts. Each of these body parts
114 is able to reference another body part within the same multipart structure,
115 or a body part within a parent multipart structure [RFC2110]. These references
118 When an MHTML message is parsed by the message engine, the HTML body of each
119 part is stored as a binary file. This interface provides a means of finding
120 the file name of the body part that corresponds to a given a URI.
122 The URI resolving process has the potential to become time consuming, therefore
123 it is broken into two steps:
125 Resolve asynchronously the relative URI into an absolute URI. The message
126 body parts are recursively searched in order to find an absolute base for
127 the relative URI [RFC2110, RFC1808].
129 Once a relative URI has been resolved in to an absolute URI, then the message
130 is searched for a body part that corresponds to it [RFC2110].
132 If no matching body part can be found, then the absolute URI is returned to
133 the caller in place of the filename. This absolute URI should be used to search
134 for the required data externally, for example by using HTTP.
142 /** Starts an asynchronous operation to resolve a specified URI.
144 @param aMessageId The ID of the body part containing the URI which is to be
145 resolved. CImEmailMessage::FindFirstHTMLPageL() can be used to find the aMessageId
146 parameter for the first HTML page in a message.
147 @param rBase The base parameter from the HTML part that contains the URI to
148 be resolved. If there is no base parameter in the HTML, then an empty descriptor
150 @param rURI The URI to be resolved.
151 @param aStatus Asynchronous status word */
152 virtual void FindUniversalResourceIdentifierL(TMsvId aMessageId, const TDesC& rBase, const TDesC& rURI, TRequestStatus &aStatus) = 0;
154 /** Gets the results after a search.
156 @param aLinkedEntryId On return, the message ID of the linked body part, providing
157 one is found. Note that you should keep a record of the returned message ID
158 as it is required for resolving any URI's that may be found in the linked
160 @param aFileFound On return, true if a linked body part has been found. It
161 is set to false otherwise.
162 @return If successful, the filename that corresponds to the URI, or the absolute
163 URI if no matching file can be found. If failed, NULL. */
164 virtual HBufC* GetUniversalResourceIdentifierL(TMsvId& aLinkedEntryId, TBool& aFileFound) const = 0;
166 /** Starts an asynchronous operation to resolve a specified URI.
168 @param aMessageId The ID of the body part containing the URI which is to be
169 resolved. CImEmailMessage::FindFirstHTMLPageFileHandleL() can be used to find the aMessageId
170 parameter for the first HTML page in a message.
171 @param aBase The base parameter from the HTML part that contains the URI to
172 be resolved. If there is no base parameter in the HTML, then an empty descriptor
174 @param aURI The URI to be resolved.
175 @param aStatus Asynchronous status word */
176 virtual void FindUniversalResourceIdentifierFileHandleL(TMsvId aMessageId, const TDesC& aBase, const TDesC& aURI, TRequestStatus &aStatus) = 0;
178 /** Gets the results after a search.
180 @param aLinkedEntryId On return, the message ID of the linked body part, providing
181 one is found. Note that you should keep a record of the returned message ID
182 as it is required for resolving any URI's that may be found in the linked
185 @param aFile On return, the file handle corresponding to the URI if successful.
186 If not successful, then this is not valid.
188 @return KErrNone if successful and therefore aFile contains the filehandle
189 that corresponds to the URI. An error code if unsuccessful and therefore
190 aFile is not valid. */
191 virtual TInt GetUniversalResourceIdentifierFileHandle(TMsvId& aLinkedEntryId, RFile& aFile) const = 0;
197 class CImMhtmlUriResolver;
198 class CImRemoveMessagePart;
199 class CImStoreMessagePart;
202 class CImEmailMessage : public CMsgActive , public MImURITranslator
204 This class can be used to manipulate new emails that
205 have been created using CImEmailOperation when composing a message.
207 Use an instance of this class to add attachments, MHTML parts, body
208 text, and existing messages to a new message before it is to be sent.
210 This class can also be used to retrieve the body text, list of attachments,
211 and embedded messages from emails that have been downloaded and stored within
214 If the store_8bit_body_text flag in imcm.rss is enabled, an instance of this class
215 can be used to retrieve the original body text character set for a particular message.
216 It can also be used to override the original body text character set so it will
217 be decoded in a new character set next time it is viewed.
219 @see CImEmailOperation
226 /** Flags that specify to process on any messages embedded in this message. */
227 enum TImEmailEntryType
229 /** Do not process embedded messages. */
231 /** Process embedded messages. */
232 EThisMessageAndEmbeddedMessages // i.e messages with in a message
234 /** Flags to specify types of attachment. */
235 enum TImAttachmentType
237 /** All attachments. */
238 EAllAttachments=0, // all attachment files contained within this message (but not inside messages within this message)
243 /** VCards, VCalendars and ICalendars. */
244 EVEntries, // ie VCards, VCalendars or ICalendars (or all three)
250 ESecure, // ie Encrypted or signed (or both)
253 //.. add new items here
256 IMPORT_C static CImEmailMessage* NewL(CMsvEntry& aEntry);
257 IMPORT_C static CImEmailMessage* NewLC(CMsvEntry& aEntry);
258 IMPORT_C ~CImEmailMessage();
260 IMPORT_C void GetAttachmentsListL(TRequestStatus& aStatus, TMsvId aMessageId, TImAttachmentType aAttachmentType,TImEmailEntryType aEntryType);
261 IMPORT_C void GetAttachmentsListL(TMsvId aMessageId, TImAttachmentType aAttachmentType,TImEmailEntryType aEntryType);
262 void DoGetAttachmentsListL(TMsvId aMessageId, TImAttachmentType aAttachmentType,TImEmailEntryType aEntryType);
264 IMPORT_C void FindFirstHTMLPageL(TMsvId aMessageId, TRequestStatus& aStatus);
266 IMPORT_C const CMsvEntrySelection& Selection() const; // return selection
267 IMPORT_C const TDesC8& ProgressL() const;
269 IMPORT_C void GetBodyTextL(TRequestStatus& aStatus, TMsvId aMessageId, TImEmailEntryType aEntryType, CRichText& aRichText,CParaFormatLayer& aParaLayer,CCharFormatLayer& aCharLayer);
270 IMPORT_C void GetBodyTextL(TMsvId aMessageId, TImEmailEntryType aEntryType, CRichText& aRichText,CParaFormatLayer& aParaLayer,CCharFormatLayer& aCharLayer);
271 void DoGetBodyTextInitL(TMsvId aMessageId, TImEmailEntryType aEntryType, CRichText& aRichText,CParaFormatLayer& aParaLayer, CCharFormatLayer& aCharLayer);
273 IMPORT_C void GetBodyTextEntryIdL(TRequestStatus& aStatus, TMsvId aMessageId, TImEmailEntryType aEntryType);
274 IMPORT_C void GetBodyTextEntryIdL(TMsvId aMessageId, TImEmailEntryType aEntryType);
276 IMPORT_C CImPlainBodyText* OpenPlainBodyTextForWriteL();
278 IMPORT_C CImPlainBodyText* OpenPlainBodyTextForReadL(TImEmailEntryType aEntryType, TInt aChunkLength);
280 IMPORT_C virtual void FindUniversalResourceIdentifierL(TMsvId aMessageId, const TDesC& aBase, const TDesC& aURI, TRequestStatus &aStatus);
281 IMPORT_C virtual HBufC* GetUniversalResourceIdentifierL(TMsvId& aLinkedEntryId, TBool& aFileFound) const;
282 IMPORT_C void FindUniversalResourceIdentifierFileHandleL(TMsvId aMessageId, const TDesC& aBase, const TDesC& aURI, TRequestStatus &aStatus);
283 IMPORT_C void FindFirstHTMLPageFileHandleL(TMsvId aMessageId, TRequestStatus& aStatus);
284 IMPORT_C virtual TInt GetUniversalResourceIdentifierFileHandle(TMsvId& aLinkedEntryId, RFile& aFile) const;
285 IMPORT_C MMsvAttachmentManager& AttachmentManager() const;
286 void AddAttachmentL(const TDesC& aFilePath, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
287 void AddAttachmentL(RFile& aFileHandle, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
288 void AddLinkedAttachmentL(const TDesC& aFilePath, CMsvAttachment* aAttachmentInfo,TRequestStatus& aStatus);
289 void AddEntryAsAttachmentL(TMsvId aAttachmentEntryId, CMsvAttachment* aAttachmentInfo,TRequestStatus& aStatus);
290 const RPointerArray<CMsvAttachment>& AttachmentInfoSelection() const;
291 void RemoveAttachmentL(TMsvAttachmentId aAttachmentId,TRequestStatus& aStatus) ;
292 void RemoveAttachedMessageL(TMsvAttachmentId aAttachmentId,TRequestStatus& aStatus) ;
293 void CreateAttachmentL(const TDesC& aFileName, RFile& aAttachmentFile, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
294 void CheckEntryAndResetStoreMessageL(TMsvId aMessageId);
295 void CheckEntryAndResetRemoveMessageL(TMsvId aMessageId);
296 void DoSetActive(TRequestStatus& aStatus);
297 CImMimeHeader* ConvertToImMimeHeadersL(CMsvMimeHeaders* aMimeHeaders);
298 CMsvMimeHeaders* ConvertToMsvMimeHeadersL(CImMimeHeader* aMimeHeader);
299 void AppendEntryAttachmentInfoL();
300 IMPORT_C void AddRelatedPartL(TMsvId aMessageId, const TDesC& aAttachmentFullName, TRequestStatus& aStatus, TMsvId aRelatedPartId, const TDesC8& aContentId);
301 IMPORT_C void StoreBodyTextL(TMsvId aMessageId, CRichText& aRichText, TRequestStatus& aStatus);
302 IMPORT_C void StoreBodyTextL(TMsvId aMessageId, CRichText& aRichText, TRequestStatus& aStatus, TBool aUsePlainTextStorage);
303 IMPORT_C void GetMessageDigestEntriesL(TRequestStatus& aStatus, TMsvId aMessageId);
304 IMPORT_C void GetCharacterSetL(TMsvId aMessageId, TUint& aCharacterSetId, TBool& aOverride);
305 IMPORT_C void SetCharacterSetL(TMsvId aMessageId, TUint aCharacterSetId);
306 IMPORT_C void StoreBodyTextWithMimeHeaderL(TMsvId aMessageId, CRichText& aRichText, const CImMimeHeader& aMimeHeader, TRequestStatus& aStatus);
308 TMsvId EmailEntryId();
313 CImEmailMessage(CMsvEntry& aEntry);
315 void DoComplete(TInt&);
318 void Start(TRequestStatus& aStatus);
322 void ChangeMessageContextL();
323 void CompareChildrenAndPopulateSelL();
324 void AttachmentInfoL();
325 void AssembleBodyTextL();
326 void CheckAndInitialiseL(TMsvId aMessageId);
328 void AppendAttachmentL();
329 TBool MessageDigestEntry();
330 TBool HandleDifferentFolderTypesL();
331 void GetTextForAlternateFolderL();
332 void GetTextForRelatedFolderL();
333 void GetAttachmentsForRelatedFolderL();
334 TBool GetBodyTextCharacterSetL();
335 TUint GetOverrideCharacterSetL();
336 TInt FindFilename(const CImMimeHeader& aMimeInfo, TPtrC8& aFilename);
337 void FindFilenameDecodeL(
338 const CImMimeHeader& aMimeInfo, TFileName& aFileName, TUint aCharset);
339 void AppendAttachmentNameL();
340 void SetBodyTextCharacterSetL(TMsvId aEntryId, TUint8 aNewCharacterSetId);
341 void FindFirstBodyTextPartL(TMsvId aEntryId, TBool& found);
343 CImMimeHeader* FindAttachmentMimeHeaderL();
344 TMsvEntry FindIdEntryL(TMsvId aMessageId);
346 void DoGetBodyTextEntryIdL(TMsvId aMessageId, TImEmailEntryType aEntryType);
349 enum TImEmailMessageStates
354 ETextEntryIdForThisMsg,
355 ETextEntryIdMsgDigest,
356 ETextForThisMsgGetCharacterSet,
357 EAttachmentsForThisMsg,
358 EAttachmentsForMsgDigest,
365 CMsvEntry& iClientEntry;
366 CMsvEntrySelection* iCompleteSel;
367 CMsvEntrySelection* iResultSel;
369 CRichText* iRichText;
370 CParaFormatLayer* iParaLayer;
371 CCharFormatLayer* iCharLayer;
372 TMsvId iParentMsgId; // the Id passed into Getxxx() function representing the 'parent' message ID
373 TImEmailMessageStates iState;
374 TImAttachmentType iAttachmentType;
375 TMsvEmailEntry iEntry;
376 CImMhtmlUriResolver* iUriResolver;
378 CImStoreMessagePart* iStoreMessagePart;
379 CImRemoveMessagePart* iRemoveMessagePart;
380 TPckgBuf<TMsvId> iProgress;
381 TImEmailEntryType iEntryType;
382 TBool iIsAMHTMLmessage;
383 TUint iCharacterSetId;
385 CDesCArray* iAttachmentNameList;
386 CImAttachmentManager* iAttachmentManager;
389 // This is the entry Id using which the CImEmailMessage was created.
390 // store this , so that when the message id to which attachment is
391 // retrieved then the CIMEmailMessage is reset with this Id.
392 TMsvId iEmailEntryId;
393 enum TImAttachmentStates
400 TInt iAttachmentState;
404 class CImRemoveMessagePart : public CMsvOperation
411 static CImRemoveMessagePart* DeleteAttachmentL(TRequestStatus &aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId, TMsvId aAttachmentId);
412 static CImRemoveMessagePart* DeleteAttachedMessageL(TRequestStatus &aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId, TMsvId aAttachedMessageId);
413 ~CImRemoveMessagePart();
414 const TDesC8& FinalProgress();
417 const TDesC8& ProgressL(); // returns NULL until operation completed - then returns MessageId
418 TMsvId RemovedAttachmentId();
420 CImRemoveMessagePart(TRequestStatus& aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId);
421 void ConstructL(TMsvId aAttachmentId);
422 void ErrorRecovery(TInt aError);
423 void SelectNextStateL(); // selects next state to go to
424 void ChangeStateL(); // initiates the next state operation
425 void SelectAndChangeToNextStateL();
426 void RequestComplete(TInt aError);
427 void Recover(); // leave message in a 'good' state
429 void CheckAttachmentParentTypeL();
430 void MoveOtherEntryToParentOfFolderL();
431 void DeleteAttachmentEntryL();
432 void DeleteFolderEntryL();
433 void CompleteRemoveMessagePartL();
435 enum TImRemoveMessagePartState
437 ECheckAttachmentParentType,
438 EMoveOtherEntryToParentOfFolder,
439 EDeleteAttachmentEntry,
441 ECompleteRemoveMessagePart,
444 CMsvEntry& iMsvEntry;
445 CMsvOperation* iMsvOperation;
447 CMsvEntrySelection* iMessageEntrySelection;
448 CImEmailMessage* iEmailMessage;
451 TPckgBuf<TMsvId> iDataMember;
453 TMsvId iFolderToDeleteId;
454 TInt iAttachmentSize;
455 TMsvId iAttachmentId;
456 TMsvId iEntryToMoveId;
459 class CImStoreMessagePart : public CMsvOperation
466 static CImStoreMessagePart* AddAttachmentL(TMsvId aMessageId, const TDesC& aFilePath, CMsvEntry& aMsvEntry,CMsvAttachment* aAttachmentInfo,TRequestStatus& aStatus );
467 static CImStoreMessagePart* AddEntryAsAttachmentL(TMsvId aMessageId,TMsvId aAttachmentMessageId, CMsvEntry& aMsvEntry, CMsvAttachment* aAttachmentInfo,TRequestStatus& aStatus);
468 static CImStoreMessagePart* AddAttachmentL(TMsvId aMessageId,RFile& aFile, CMsvEntry& aMsvEntry, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
469 static CImStoreMessagePart* AddLinkedAttachmentL(TMsvId aMessageId,const TDesC& aFilePath, CMsvEntry& aMsvEntry,CMsvAttachment* aAttachmentInfo,TRequestStatus& aStatus );
470 static CImStoreMessagePart* CreateAttachmentL(TMsvId aMessageId,const TDesC& aFileName, RFile& aAttachmentFile,CMsvEntry& aMsvEntry, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
471 static CImStoreMessagePart* AddRelatedPartL(TRequestStatus &aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId, const TDesC& aAttachmentFullName, TMsvId aRelatedPartId, const TDesC8& aContentId);
472 static CImStoreMessagePart* StoreBodyTextL(TRequestStatus& aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId, CRichText& aRichText, TBool aUsePlainTextStorage = EFalse);
473 static CImStoreMessagePart* StoreBodyTextWithMimeHeaderL(TRequestStatus& aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId, CRichText& aRichText, const CImMimeHeader& aMimeHeader, TBool aUsePlainTextStorage = EFalse);
474 static CImStoreMessagePart* StorePlainBodyTextL(TRequestStatus& aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId, TBool aUsePlainTextStorage = ETrue);
475 static CImStoreMessagePart* StorePlainBodyTextL(TRequestStatus& aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId, CImMimeHeader& aMimeHeader, TBool aUsePlainTextStorage = ETrue);
476 ~CImStoreMessagePart();
477 const TDesC8& FinalProgress();
480 const TDesC8& ProgressL();
484 EMessagePartAttachment,
486 EMessagePartMessageAttachment
488 void ConstructL(RFile& aFile);
489 void ConstructL(RFile& aFile,const TDesC& aAttachmentName);
490 void ConstructL(const TDesC& aAttachmentFullName, const TDesC8& aContentId);
491 void ConstructAttachmentInfo(CMsvAttachment* aAttachmentInfo,TInt aAttachmentCreationState);
492 CImStoreMessagePart(TRequestStatus& aStatus, CMsvEntry& aMsvEntry, TMsvId aMessageId, TBool aUsePlainTextStorage = EFalse);
495 void ConstructL(const TDesC& aAttachmentFullName);
496 void ConstructL(TMsvId aAttachmentMessageId);
497 void ConstructL(const TDesC& aAttachmentFullName, TMsvId aRelatedPartId, const TDesC8& aContentId);
498 void ConstructL(CRichText& aRichText);
499 void ConstructL(CRichText& aRichText, const CImMimeHeader& aMimeHeader);
500 void ConstructL(CImMimeHeader& aMimeHeader);
501 void ConstructL(TImMessagePart aMessagePart);
502 void ErrorRecovery(TInt error);
503 void SelectNextStateL(); // selects next state to go to
504 void ChangeStateL(); // initiates the next state operation
505 void SelectAndChangeToNextStateL();
506 void RequestComplete(TInt aError);
509 TBool HTMLMessage() const;
510 void SetHTMLMessage(TBool aFlag);
511 TBool MultipartMixedExists() const;
512 void SetMultipartMixedExists(TBool aFlag);
513 TBool MultipartMixedCreated() const;
514 void SetMultipartMixedCreated(TBool aFlag);
515 TBool MultipartAlternativeExists() const;
516 void SetMultipartAlternativeExists(TBool aFlag);
517 TBool MultipartAlternativeCreated() const;
518 void SetMultipartAlternativeCreated(TBool aFlag);
519 TBool MultipartRelatedExists() const;
520 void SetMultipartRelatedExists(TBool aFlag);
521 TBool MultipartRelatedCreated() const;
522 void SetMultipartRelatedCreated(TBool aFlag);
523 TBool TextPartExists() const;
524 void SetTextPartExists(TBool aFlag);
525 TBool TextPartCreated() const;
526 void SetTextPartCreated(TBool aFlag);
527 TBool AttachmentEntryCreated() const;
528 void SetAttachmentEntryCreated(TBool aFlag);
530 void FindMultipartRelatedFolderL();
531 void CheckForSubfolderL();
532 void CreateAttachmentEntryL();
533 void CopyOrigMessageToMessageL();
534 void CreateMultipartMixedFolderEntryL();
535 void CreateMultipartAlternativeFolderEntryL();
536 void CreateMultipartRelatedFolderEntryL();
537 void MoveOriginalMessageEntryChildrenToNewFolderL();
538 void CreateTextEntryL();
539 void StoreRichTextL();
540 void CompleteStoreMessagePartL();
541 void CreateHTMLEntryL();
542 void PrepareToStoreHTMLEntryTextL();
543 void StoreHTMLEntryTextL();
544 void RemoveHTMLEntryL();
545 void MoveTextEntryToAltFolderL();
546 TPtrC GetDefaultAttachmentName();
547 void OpenAndReadResourceFileL();
548 void StoreMimeHeaderL();
549 TBool CreateAttachmentMimeHeaderL(CImMimeHeader& aMimeHeader, const TDesC& aDetails);
550 void CreateFolderMimeHeaderL(CImMimeHeader& aMimeHeader);
551 void CreateMessageMimeHeaderL(CImMimeHeader& aMimeHeader);
552 void AddAttachmentL();
553 void AddAttachmentUsingFileHandleL();
554 void AddLinkedAttachmentL();
555 void AddEntryAsAttachmentL();
556 void CreateAttachmentL();
557 void DoAttachmentStoreL();
558 TInt CheckMimeInAttachmentInfoL(CMsvMimeHeaders& aMsvMimeHeaders);
559 CImMimeHeader* ProcessAttachmentMimeHeadersL();
560 void SetEntryDetailsL(TMsvEntry& aEntry);
561 void StorePlainTextL();
563 enum TImStoreMessagePartState
565 EFindMultipartRelatedFolder,
567 ECreateAttachmentEntry,
569 ECopyOrigMessageToMessage,
570 ECreateMultipartMixedFolderEntry,
571 ECreateMultipartRelatedFolderEntry,
572 ECreateMultipartAlternativeFolderEntry,
573 EMoveOriginalMessageEntryChildrenToNewFolder,
577 EMoveTextToAlternativeFolder,
579 EPrepareToStoreHTMLEntryText,
581 ECompleteStoreMessage,
583 ,EStoreHTMLTextInEntry,
587 enum TImStoreMessagePartFlags
589 KStoreMessagePartClearFlag = 0x00000000,
590 KStoreMessagePartHTMLMessage = 0x00000001,
591 KStoreMessagePartMultipartMixedExists = 0x00000002,
592 KStoreMessagePartMultipartMixedCreated = 0x00000004,
593 KStoreMessagePartMultipartAlternativeExists = 0x00000008,
594 KStoreMessagePartMultipartAlternativeCreated = 0x00000010,
595 KStoreMessagePartTextPartExists = 0x00000020,
596 KStoreMessagePartTextPartCreated = 0x00000040,
597 KStoreMessagePartAttachmentEntryCreated = 0x00000080,
598 KStoreMessagePartOrigMessageEntryChildrenCopied = 0x00000100,
599 KStoreMessagePartOrigMessageEntryChildrenDeleted = 0x00000200,
600 KStoreMessagePartMultipartRelatedExists = 0x00000400,
601 KStoreMessagePartMultipartRelatedCreated = 0x00000800
603 CMsvEntry& iMsvEntry;
604 CMsvOperation* iMsvOperation;
606 CRichText* iRichTextToStore; // I don't own this object!
607 CImMimeHeader* iMimeHeaderOfBodyText;
608 CRichText* iRichText;
610 CMsvEntrySelection* iMessageEntrySelection;
613 TPckgBuf<TMsvId> iDataMember;
615 TImMessagePart iMessagePart;
619 HBufC* iAttachmentFullName;
620 TInt iAttachmentSize;
621 TMsvId iAttachmentId;
624 TMsvId iRelatedPartId;
625 TMsvId iAttachmentMessageId;
628 CImEmailMessage* iEmailMessage;
630 // Used when converting rich text to html
631 CParaFormatLayer* iParaLayer;
632 CCharFormatLayer* iCharLayer;
633 CImHtmlConverter* iHtmlConverter;
634 TBool iFinishedConvertingHTML;
635 CMsvAttachment* iAttachmentInfo;
637 TInt iAttachmentCreateState;
638 TBool iIsAddByFileHandle;
641 // Indicates whether to store message body as CRichText or plaintext.
642 TBool iUsePlainTextStorage;
643 // Size of the plain text body.
645 // Size of the Fwd'ed/ReplyTo plaintext body part.
646 TInt iSizeFwdReplyBody;
647 // The error value returned when CRichText is populated with message body text.
649 enum TImAttachmentCreation
652 EAddAttachmentUsingFileHandle,
653 EAddLinkedAttachment,
654 EAddEntryAsAttachment,
659 class CImEmailOperation : public CMsvOperation
660 /** Provides simple email messages creation functions, including creation of new
661 messages, replies, forwarded messages, and receipts.
663 Both plain-text and HTML messages, with or without attachments, can be created.
669 IMPORT_C static CImEmailOperation* CreateNewL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
670 IMPORT_C static CImEmailOperation* CreateNewL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aDestination, TMsvId aSmtpServiceId, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority = EPriorityStandard);
672 IMPORT_C static CImEmailOperation* CreateNewL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aDestination, TMsvId aSmtpServiceId, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority , TBool aUsePlainTextStorage);
674 IMPORT_C static CImEmailOperation* CreateReplyL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TDesC& aFormatString, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
675 IMPORT_C static CImEmailOperation* CreateReplyL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
676 IMPORT_C static CImEmailOperation* CreateReplyL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority);
677 IMPORT_C static CImEmailOperation* CreateReplyL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority, TBool aUsePlainTextStorage);
678 IMPORT_C static CImEmailOperation* CreateForwardL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TDesC& aFormatString, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
679 IMPORT_C static CImEmailOperation* CreateForwardL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
680 IMPORT_C static CImEmailOperation* CreateForwardL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvId aSmtpServiceId, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority = EPriorityStandard);
681 IMPORT_C static CImEmailOperation* CreateForwardL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvId aSmtpServiceId, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority, TBool aUsePlainTextStorage);
682 IMPORT_C static CImEmailOperation* CreateForwardAsAttachmentL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
683 IMPORT_C static CImEmailOperation* CreateForwardAsAttachmentL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aSmtpServiceId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority = EPriorityStandard);
684 IMPORT_C static CImEmailOperation* CreateReceiptL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TDesC& aFormatString, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
685 IMPORT_C static CImEmailOperation* CreateReceiptL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
686 IMPORT_C static CImEmailOperation* CreateReceiptL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority);
687 IMPORT_C static CImEmailOperation* CreateReceiptL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority, TBool aUsePlainTextStorage);
688 IMPORT_C ~CImEmailOperation();
689 IMPORT_C const TDesC8& FinalProgress();
692 const TDesC8& ProgressL();
694 static CImEmailOperation* CreateCopyL(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aMessageId, TMsvId aDestination, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType);
697 enum TImEmailOperation
703 EDeletingBadEmail = 4,
705 EAttachOriginal = 0x80,
706 EForwardAsAttachment = EForward | EAttachOriginal,
707 EReplyAsAttachment = EReply | EAttachOriginal
711 CImEmailOperation(TRequestStatus& aObserverRequestStatus, CMsvSession& aMsvSession, TMsvId aDestination, TMsvId aSmtpServiceId, TMsvPartList aPartList, const TMsvEmailTypeList& aMsvEmailTypeList, TUid aMsgType, TInt aPriority, TBool aUsePlainTextStorage);
712 void ConstructL(TMsvId aMessageId, const TDesC& aFormatString, TImEmailOperation aOperation);
713 void ConstructL(TMsvId aMessageId, TImEmailOperation aOperation);
714 void ConstructL(TImEmailOperation aOperation);
715 void OpenAndReadResourceFileL();
716 void SetSmtpServiceFromDefaultsL();
717 void SetSmtpServiceFromOriginalMessageL();
718 void ErrorRecovery(TInt error);
719 void SelectNextStateL();
720 void ProcessStateL();
721 void SelectAndProcessNextStateL();
722 void RequestComplete(TInt aError);
723 void CreateNewHeaderL();
725 TInt RemoveIncompleteAttachments();
726 void CreateEntryDetails(TMsvEmailEntry& aMsvEmailEntry);
727 void CreateNewMessageL(TMsvId aDestinationId);
728 void CreateMultipartMixedFolderEntryL();
729 void CreateTextEntryL(TMsvId aFolderId);
731 void StorePlainBodyL();
732 void CheckForSignatureOrVCardL();
733 void CreateAttachmentEntryL();
734 void StoreAttachmentL();
735 void CreateMultipartAlternativeFolderEntryL();
736 void AppendHtmlAttachmentL();
737 void AttachOriginalMessageToNewMessageL();
738 void CompleteEmailOperationL();
739 void CreateHTMLEntryL();
740 void PrepareToStoreHTMLEntryTextL();
741 void StoreHTMLEntryTextL();
742 void CreateVCardAttachmentL();
743 void AddVCardAttachmentL();
744 void AddMessageAsAttachmentL();
745 TPtrC GetDefaultAttachmentName();
746 void RestoreSmtpSettingsL();
748 TBool NeedMultipartMixedFolder() const;
749 void ReadDefaultHtmlAttachmentNameL(TDes& aFileName);
750 void CreateDefaultAttachmentL();
751 void AddMessageAttachmentInfoL(TMsvId aAttachmentMessageId);
753 void CreateAddressListStringL(HBufC*& aListBuffer, const CDesCArray& aAddressArray);
754 void RestoreOriginalHeaderL();
755 void SetBodyHeaderFormatL();
756 static void ClosePlainBodyTextArray(TAny* aPtr);
757 void StorePlainTextL();
758 TInt GetPlainBodyTextSizeL();
761 enum TImEmailOperationState
767 ECreateNewMessageEntry,
768 ECheckMultipartMixedFolderRequired,
769 ECreateMultipartMixedFolderEntry,
770 ECheckMultipartAlternativeFolderRequired,
771 ECreateMultipartAlternativeFolderEntry,
772 ECheckTextEntryRequired,
776 ECreateVCardAttachment,
778 ECheckHTMLEntryRequired,
780 EPrepareToStoreHTMLEntryText,
782 ECheckAttachOriginalMessageRequired,
783 EAttachOriginalMessage,
784 ECheckHTMLPageRequired,
786 ECopyHTMLPartToAttachment,
787 ECheckAttachmentsRequired,
788 ECreateAttachmentEntry,
790 ECheckEmbeddedMessagesRequired,
791 EAddEmbeddedMessagesAsAttachments,
792 ECompleteEmailOperation,
794 ,ECreateDefaultHtmlAttachment,
795 EStoreHTMLTextInEntry,
796 EAddMessageAttachmentInfo
799 // Flags specifying format of body header information to include
800 // in reply and forwarded email addresses
801 enum TImBodyHeaderFormat
809 CMsvEntry* iMsvEntry;
810 CMsvOperation* iMsvOperation;
812 CImHeader* iNewHeader;
813 CParaFormatLayer* iParaLayer;
814 CCharFormatLayer* iCharLayer;
815 CRichText* iRichText;
816 CImEmailMessage* iEmailMessage;
817 HBufC* iFormatString;
819 CImSmtpSettings* iSmtpSettings;
821 TImEmailOperation iOperation;
822 TMsvId iDestinationId;
823 TMsvId iMultipartMixedId;
824 TMsvId iMultipartAlternativeId;
825 TMsvId iOrigMessageId;
826 TMsvId iNewMessageId;
827 TMsvId iSmtpServiceId;
828 TMsvId iAttachedMessageId;
830 TMsvPartList iPartList;
831 TMsvEmailTypeList iMsvEmailTypeList;
832 TInt iAttachmentCount;
833 TInt iTotalAttachments;
834 TPckgBuf<TMsvId> iDataMember;
835 HBufC* iBodyHeaderFormatString;
836 HBufC* iBodyHeaderDateTimeFormatString;
837 HBufC* iBodyHeaderToString;
838 HBufC* iBodyHeaderCcString;
840 HBufC* iUserEmailAddress;
842 TInt iVCardAndHtmlSize;
843 TBool iOrigMessageHtml;
844 TBool iHtmlNoTextAlt;
845 TInt iEmbeddedMessagesToProcess;
846 TImMessageField iMessageField;
848 // for MIME messages:
849 TBool iCreateHtmlMessage;
850 TBool iMultipartMixedFolderCreated;
851 TBool iMultipartAlternativeFolderCreated;
856 // Used when converting rich text to html
857 CImHtmlConverter* iHtmlConverter;
858 TBool iFinishedConvertingHTML;
860 // Relating to adding Signature and/or Vcard to an email
861 TBool iNeedToAddVCardAttachment;
862 HBufC* iDefaultVCardNameFormatString;
863 TStreamId iVcardStoreId;
864 CStreamStore* iVcardStore;
865 CRichText* iSignatureText;
867 TImAttachmentFile iAttachmentFile;
870 TMsvId iPCMailServiceId;
871 RPointerArray<CMsvAttachment> iAttachmentInfoList;
872 // set this anytime during the object life cycle attachment manager was used
873 TBool iAttachmentMgrUsed;
877 TImBodyHeaderFormat iBodyHeaderFormat;
878 CImHeader* iOriginalHeader;
879 /** Indicates if the body text entry is plain text */
880 TBool iUsePlainTextStorage;
881 // The error value returned when CRichText is populated with message body text.
886 class CImHtmlConverter : public CBase
893 static CImHtmlConverter* CImHtmlConverter::NewL(CMsvEntry& aMsvEntry,
894 CParaFormatLayer& aParaLayer, CCharFormatLayer& aCharLayer);
896 void PrepareToStoreHTMLEntryTextL(TMsvId& aHtmlId, const TMsvId aTextId);
898 void ResetStoreWithoutCommit();
899 TBool StoreHTMLEntryTextAL(TRequestStatus& aStatus);
900 CMsvOperation* ChangeHTMLTextInEnrtyL(TRequestStatus& aStatus);
902 void ReadDefaultAttachmentNameL( RResourceFile& resourceFile);
906 CImHtmlConverter(CMsvEntry& aMsvEntry, CParaFormatLayer& aParaLayer, CCharFormatLayer& aCharLayer);
907 TFileName HtmlFilename(CMsvEntry& aEntry, TPtrC aFileName);
908 TPtrC GetDefaultAttachmentName();
912 CMsvEntry& iMsvEntry;
913 CParaFormatLayer& iParaLayer;
914 CCharFormatLayer& iCharLayer;
916 CConverterBase* iToHTMLConverter;
917 CCnaConverterList* iConverterList;
922 HBufC* iDefaultAttachmentName;
923 CRichText* iRichText;
924 RDesReadStream iSourceStream;
925 RFileWriteStream iTargetStream;
930 class CImStoreResolver : public CBase, public MRichTextStoreResolver
937 CImStoreResolver(CStreamStore* aStore);
941 const CStreamStore& StreamStoreL(TInt aPos)const;
944 CStreamStore* iStore;
950 #endif // __MIUTMSG_H__