email/mail/UtilsSrc/MsgMailDocument.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Base class for document classes of the 
       
    15 *                 mail viewer and editor applications
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "MailLog.h"
       
    22 #include "MailUtils.h"
       
    23 #include <miutset.h>                    // KMsvEmailTypeListXX enums
       
    24 #include <miuthdr.h>                    // CIMHeader
       
    25 #include <miutmsg.h>                    // CImEmailMessage
       
    26 #include <smtpset.h>                    // Smtp Settings
       
    27 #include <MuiuMsgEditorLauncher.h>      // launch parameter constants
       
    28 #include <akninputblock.h>              // CAknInputBlock
       
    29 #include <MuiuOperationWait.h>          // CMuiuOperationWait
       
    30 #include <MuiuMsvUiServiceUtilities.h>	// MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL
       
    31 #include <miutconv.h>                   // TImEmailTransformingInfo
       
    32 #include <eikenv.h>
       
    33 #include <mmsvattachmentmanager.h>
       
    34 #include <StringLoader.h>
       
    35 
       
    36 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS  
       
    37 #include <cimconvertcharconv.h>
       
    38 #endif
       
    39 
       
    40 #include <MsgMailUtils.rsg>
       
    41 #include "MsgMailDocument.h"            // header
       
    42 #include "MsgMailPreferences.h"         // Message preferences
       
    43 #include <CMailMessage.h>
       
    44 #include <apmrec.h>
       
    45 
       
    46 
       
    47 // ================= MEMBER FUNCTIONS =======================
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // C++ default constructor cannot contain any code that might leave.
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C CMsgMailDocument::CMsgMailDocument(CEikApplication& aApp)
       
    54     : CMsgEditorDocument(aApp), iMessage(NULL), iHeader(NULL),
       
    55     iIdle(NULL)
       
    56     {
       
    57     }
       
    58 
       
    59     
       
    60 // Destructor
       
    61 EXPORT_C CMsgMailDocument::~CMsgMailDocument()
       
    62     {
       
    63     iApaSession.Close();    
       
    64     delete iHeader;
       
    65     delete iMessage;
       
    66     delete iMessageCEntry;
       
    67     delete iIdle;
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 //  CMsgMailDocument::EntryChangedL()
       
    72 //  Called after entry is changed by SetEntry Function. Deletes current
       
    73 //  header and body and reads the new ones from message store. 
       
    74 // ----------------------------------------------------------------------------
       
    75 //
       
    76 EXPORT_C void CMsgMailDocument::EntryChangedL()
       
    77     {    
       
    78     delete iHeader;
       
    79     delete iMessage;
       
    80     delete iMessageCEntry;
       
    81     iHeader = NULL;
       
    82     iMessage = NULL;
       
    83     iMessageCEntry = NULL;
       
    84 
       
    85     iHeader = CImHeader::NewLC();
       
    86     CleanupStack::Pop();
       
    87     //CMsvEntry& messageEntry = CurrentEntry();
       
    88     iMessageID = CurrentEntry().EntryId();
       
    89     LOG1("CMsgMailDocument::EntryChangedL %08x", iMessageID);
       
    90     iMessageCEntry = CurrentEntry().Session().GetEntryL(
       
    91     	iMessageID);
       
    92     iMessage = CImEmailMessage::NewL(*iMessageCEntry);
       
    93     if (iMessageCEntry->HasStoreL())
       
    94         {
       
    95         CMsvStore* msvStore = iMessageCEntry->ReadStoreL();
       
    96         CleanupStack::PushL(msvStore);
       
    97         TRAP_IGNORE(iHeader->RestoreL(*msvStore));
       
    98         // get body encoding
       
    99         if (msvStore->IsPresentL( KUidMsgFileTransformingInfo))
       
   100         	{        	
       
   101 	    	TImEmailTransformingInfo info;
       
   102 	    	// use defaults if fails
       
   103 	    	TRAP_IGNORE(info.RestoreL(*msvStore));
       
   104 	    	TUid charset;
       
   105 	    	charset.iUid = info.BodyTextCharset();
       
   106 	    	SendOptions().SetSendingCharacterSet(charset);
       
   107         	}
       
   108         CleanupStack::PopAndDestroy(); // store
       
   109         }
       
   110     }
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 //  CMsgMailDocument::CreateReplyL()
       
   114 // ----------------------------------------------------------------------------
       
   115 //    
       
   116 EXPORT_C CMsvOperation* CMsgMailDocument::CreateReplyL( 
       
   117     TMsvId aDest, TMsvPartList aParts, TRequestStatus& aStatus)
       
   118     {
       
   119     LOG1("CMsgMailDocument::CreateReplyL %08x", 
       
   120         CurrentEntry().Entry().Id() );
       
   121     
       
   122     CImEmailMessage* mailMessage = CImEmailMessage::NewLC( CurrentEntry() );    
       
   123     
       
   124     TBool plainHTMLEntry =  IsPlainHTMLMessageL( mailMessage );
       
   125     HBufC* attachmentNames = GetAttachmentNamesFromMessageL( mailMessage );
       
   126     CleanupStack::PopAndDestroy( mailMessage );
       
   127     CleanupStack::PushL( attachmentNames );
       
   128     
       
   129     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   130     CMsvOperation* oper = Mtm().ReplyL( aDest, aParts, wait->iStatus );    
       
   131     wait->Start();
       
   132     TInt status( wait->iStatus.Int() );
       
   133     CleanupStack::PopAndDestroy( wait );
       
   134     
       
   135     TMsvId replyMessage = GetOperId( *oper );
       
   136     CleanupStack::PushL( oper );
       
   137     SetEntryWithoutNotificationL( replyMessage );
       
   138     
       
   139     AddAttachmentNamesToMessageBodyL( *attachmentNames );
       
   140     CleanupStack::Pop( oper );
       
   141     CleanupStack::PopAndDestroy( attachmentNames ); // attachmentNames
       
   142         
       
   143     TRequestStatus* myStatus=&aStatus;
       
   144     User::RequestComplete( myStatus, status );
       
   145     
       
   146     if(plainHTMLEntry)
       
   147         {
       
   148         //Create Idle object so we can show note 
       
   149         //after options menu is closed and editor is opened.
       
   150         
       
   151         iIdle = CIdle::NewL(CActive::EPriorityStandard);
       
   152         
       
   153         iShowNoteCallBack = TCallBack( ShowHtmlNoteCallBackL, this );
       
   154         
       
   155         iIdle->Start(iShowNoteCallBack); // CSI: 10 #     
       
   156         }
       
   157    
       
   158     return oper;
       
   159     }
       
   160     
       
   161 
       
   162 // ----------------------------------------------------------------------------
       
   163 //  CMsgMailDocument::ShowHtmlNoteCallBackL()
       
   164 // ----------------------------------------------------------------------------
       
   165 //
       
   166 TInt CMsgMailDocument::ShowHtmlNoteCallBackL( TAny* /*aCaller*/ )	// CSI: 40 # We must return 
       
   167 																	// the integer value although this 
       
   168 																	// is a leaving method.
       
   169     {    
       
   170     MailUtils::InformationNoteL( R_QTN_MAIL_INFO_HTML_ATTACH );
       
   171     return 0;
       
   172     } 
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 //  CMsgMailDocument::CreateForwardL()
       
   176 // ----------------------------------------------------------------------------
       
   177 //     
       
   178 EXPORT_C CMsvOperation* CMsgMailDocument::CreateForwardL(
       
   179     TMsvId aDest, TMsvPartList aParts, TRequestStatus& aStatus )
       
   180     {
       
   181     LOG1("CMsgMailDocument::CreateForwardL %08x", 
       
   182         CurrentEntry().Entry().Id() );
       
   183     CImEmailMessage* mailMessage = CImEmailMessage::NewLC( CurrentEntry() );    
       
   184     
       
   185     if(IsPlainHTMLMessageL( mailMessage ))
       
   186         {
       
   187         MailUtils::InformationNoteL( R_QTN_MAIL_INFO_HTML_ATTACH );
       
   188         }
       
   189     
       
   190     CleanupStack::PopAndDestroy( mailMessage );    
       
   191     
       
   192     return CMsgEditorDocument::CreateForwardL( aDest, aParts, aStatus );          
       
   193     }
       
   194     
       
   195 // ----------------------------------------------------------------------------
       
   196 //  CMsgMailDocument::TMsvEMailEntryL()
       
   197 // ----------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C const TMsvEmailEntry& CMsgMailDocument::TMsvEMailEntryL()
       
   200 	{
       
   201 	// context might be wrong
       
   202 	iMessageCEntry->SetEntryL(iMessageID);
       
   203 		
       
   204 	return static_cast<const TMsvEmailEntry&> (CMsgEditorDocument::Entry());
       
   205 	}
       
   206 
       
   207 // ----------------------------------------------------------------------------
       
   208 //  CMsgMailDocument::MessageL()
       
   209 // ----------------------------------------------------------------------------
       
   210 //
       
   211 EXPORT_C CImEmailMessage& CMsgMailDocument::MessageL()
       
   212 	{
       
   213 	// context might be wrong
       
   214 	iMessageCEntry->SetEntryL(iMessageID);
       
   215 	return *iMessage;
       
   216 	}
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 //  CMsgMailDocument::CreateNewL()
       
   220 // ----------------------------------------------------------------------------
       
   221 //
       
   222 EXPORT_C TMsvId CMsgMailDocument::CreateNewL(TMsvId aServiceType, 
       
   223     TMsvId aTarget, TInt /*aTypeList*/, TUid aMtm)
       
   224     {
       
   225     // Check that we're not under critical level
       
   226     DiskSpaceBelowCriticalLevelL( 0 );
       
   227 	CAknInputBlock::NewLC();
       
   228 	// Set context to target
       
   229 	TMsvEntry serviceTEntry;
       
   230 	TMsvId serviceID;
       
   231 	
       
   232 	TInt error = Session().GetEntry(aServiceType, serviceID, serviceTEntry);
       
   233 	// if fails use default service (SMTP)
       
   234 	if (error == KErrNone)
       
   235 		{
       
   236 		aMtm = serviceTEntry.iMtm;
       
   237 		}
       
   238 	PrepareMtmL(aMtm);
       
   239 	Mtm().SwitchCurrentEntryL(aTarget);
       
   240 	Mtm().CreateMessageL(aServiceType);
       
   241 	CMsvEntry& newEntry = Mtm().Entry();
       
   242 	
       
   243 	TMsvId newId = newEntry.EntryId();
       
   244 	CleanupStack::PopAndDestroy(); // CAknInputBlock
       
   245 	
       
   246 	return newId;
       
   247     }
       
   248 
       
   249 // ----------------------------------------------------------------------------
       
   250 //  CMsgMailDocument::CreateNewEntryL()
       
   251 // ----------------------------------------------------------------------------
       
   252 //
       
   253 TMsvId CMsgMailDocument::CreateNewEntryL( TMsvEmailEntry& aEntry )
       
   254 	{
       
   255     CImHeader& header = HeaderL();
       
   256     CDesCArrayFlat* toArray = new(ELeave) CDesCArrayFlat(3);		// CSI: 47 # <insert a comment here>
       
   257     CleanupStack::PushL(toArray);
       
   258     CDesCArrayFlat* ccArray = new(ELeave) CDesCArrayFlat(3);		// CSI: 47 # <insert a comment here>
       
   259     CleanupStack::PushL(ccArray);
       
   260 
       
   261     const TInt toCount(header.ToRecipients().Count());
       
   262     TInt i(0);
       
   263     for (; i < toCount; i++)
       
   264         {
       
   265         toArray->AppendL(header.ToRecipients()[i]);
       
   266         }
       
   267     const TInt ccCount(header.CcRecipients().Count());
       
   268     for (i=0; i < ccCount; i++)
       
   269         {
       
   270         ccArray->AppendL(header.CcRecipients()[i]);
       
   271         }
       
   272 
       
   273     // we'll preserve all data from original message
       
   274     const TMsvId serviceId(aEntry.iServiceId);
       
   275     const TMsvId relatedId(aEntry.iRelatedId);
       
   276     const TUid type(aEntry.iType);
       
   277     const TUid mtm(aEntry.iMtm);
       
   278     const TInt32 mtmData1(aEntry.iMtmData1);
       
   279     const TInt32 mtmData2(aEntry.iMtmData2);
       
   280     const TTime time(aEntry.iDate);
       
   281 
       
   282     TMsvEmailTypeList msvEmailTypeList(KMsvEmailTypeListMessageInPreparation);
       
   283     TMsvId newMessageId( CreateNewL(serviceId, 
       
   284         DefaultMsgFolder(), msvEmailTypeList, mtm) );
       
   285            
       
   286     CMsvEntry* centry = CMsvEntry::NewL( Session(), 
       
   287         newMessageId, TMsvSelectionOrdering() );
       
   288     CleanupStack::PushL(centry);
       
   289     aEntry = centry->Entry();
       
   290     aEntry.iServiceId = serviceId;
       
   291     aEntry.iRelatedId = relatedId;
       
   292     aEntry.iType = type;
       
   293     aEntry.iMtm = mtm;
       
   294     aEntry.iMtmData1 = mtmData1;
       
   295     aEntry.iMtmData2 = mtmData2;
       
   296     aEntry.SetMHTMLEmail(EFalse); // make sure that old flag is not copied
       
   297     aEntry.SetBodyTextComplete(ETrue);
       
   298     aEntry.SetComplete(ETrue);
       
   299     aEntry.SetInPreparation(aEntry.InPreparation());    
       
   300     // set visible if not in preparation state
       
   301     aEntry.SetVisible(!aEntry.InPreparation());
       
   302     aEntry.iDate = time;
       
   303     centry->ChangeL(aEntry);                
       
   304     CleanupStack::PopAndDestroy(); // centry
       
   305     SetEntryL(newMessageId);
       
   306 
       
   307     aEntry = Entry();
       
   308     CImHeader& newHeader = HeaderL();
       
   309     
       
   310     for (i=0; i < toCount; i++)
       
   311         {
       
   312         newHeader.ToRecipients().AppendL((*toArray)[i]);	// CSI: 2 # No need to check because of the i goes from 0 to toCount.
       
   313         }
       
   314     for (i=0; i < ccCount; i++)
       
   315         {
       
   316         newHeader.CcRecipients().AppendL((*ccArray)[i]);	// CSI: 2 # No need to check because of the i goes from 0 to ccCount.
       
   317         }
       
   318     CleanupStack::PopAndDestroy(2);			// CSI: 47 # toArray, ccArray
       
   319 
       
   320 	return newMessageId;
       
   321 	}
       
   322 	
       
   323 // ----------------------------------------------------------------------------
       
   324 //  CMsgMailDocument::SaveHeaderToStoreL()
       
   325 // ----------------------------------------------------------------------------
       
   326 //
       
   327 void CMsgMailDocument::SaveHeaderToStoreL()
       
   328     {
       
   329     ASSERT( iMessageID == CurrentEntry().Entry().Id() );
       
   330     	
       
   331     // get store for the message
       
   332     CMsvStore* store = CurrentEntry().EditStoreL();
       
   333     CleanupStack::PushL(store);
       
   334 
       
   335     // set header and body encoding
       
   336     TImEmailTransformingInfo info;
       
   337     info.SetToDefault(ESendAsMimeEmail);
       
   338     TUint charset = SendOptions().SendingCharacterSet().iUid;
       
   339     info.SetHeaderAndBodyCharset( charset );
       
   340     
       
   341     info.StoreL(*store);
       
   342     // store message header
       
   343     iHeader->StoreL(*store);
       
   344     store->CommitL();
       
   345     CleanupStack::PopAndDestroy(); // store    
       
   346     }
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 //  CMsgMailDocument::IsSyncMLMail()
       
   350 //	@deprecated
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C TBool CMsgMailDocument::IsSyncMLMail()
       
   354     {
       
   355     return EFalse;
       
   356     }
       
   357 
       
   358 // ----------------------------------------------------------------------------
       
   359 // CMsgMailDocument::ResolveMimeType
       
   360 // ----------------------------------------------------------------------------
       
   361 EXPORT_C TDataType CMsgMailDocument::ResolveMimeType( RFile aFile )
       
   362 	{
       
   363     LOG(">CMsgMailDocument::ResolveMimeType");              	
       
   364 	TDataType dataType;
       
   365     if ( aFile.SubSessionHandle() )
       
   366         {
       
   367         TUid appUid( KNullUid );
       
   368         TInt error(0);
       
   369         
       
   370         if (!iApaSession.Handle())
       
   371         	{
       
   372         	error = iApaSession.Connect();
       
   373         	}
       
   374 		if ( error == KErrNone )
       
   375 			{
       
   376 		    TDataRecognitionResult recognitionResult;
       
   377 		    
       
   378 		    error = iApaSession.RecognizeData(aFile, recognitionResult);
       
   379 	    	if(recognitionResult.iConfidence != CApaDataRecognizerType::ENotRecognized &&
       
   380 	    	    error == KErrNone)
       
   381 	    	    {
       
   382 	    	    dataType = recognitionResult.iDataType;
       
   383 	    	    }
       
   384 	    	else
       
   385 	    	    {
       
   386 	    	    LOG1("CMsgMailDocument::ResolveMimeTypeL error:%d or not ENotRecognized", 
       
   387 				error);        
       
   388 	    	    }
       
   389 			}
       
   390 
       
   391         }
       
   392     LOG("<CMsgMailDocument::ResolveMimeType");
       
   393     return dataType;    
       
   394 	}
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 //  CMsgMailDocument::SetReceivedIntL()
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 TInt CMsgMailDocument::SetReceivedIntL(				// CSI: 40 # We must return 
       
   401 													// the integer value although this 
       
   402 													// is a leaving method.
       
   403     const TUint aMessageType, const TInt aAmount )
       
   404 	{
       
   405 	// Check that the index has correct value
       
   406 	if( aMessageType >= EIndexLast )
       
   407 		{
       
   408 	    return KErrOverflow;
       
   409 	    }
       
   410 
       
   411 	switch(aMessageType)
       
   412 		{
       
   413 		case EIndexAddHeaders:
       
   414 			{
       
   415 			iPrefs->SetAdditionalHeaders(aAmount);
       
   416 			break;
       
   417 			}
       
   418 		default:
       
   419 			{
       
   420 			break;
       
   421 			}
       
   422 		}
       
   423 	return KErrNone;
       
   424 	}
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 //  CMsgMailDocument::SetReceivedRealL()
       
   428 // -----------------------------------------------------------------------------
       
   429 //	
       
   430 TInt CMsgMailDocument::SetReceivedRealL(				// CSI: 40 # We must return 
       
   431 														// the integer value although this 
       
   432 														// is a leaving method.
       
   433     const TUint aMessageType, const TReal /*aValue*/ )
       
   434 	{
       
   435 	// Check that the index has correct value
       
   436 	if( aMessageType >= EIndexLast )
       
   437 		{
       
   438 	    return KErrOverflow;
       
   439 	    }
       
   440 	return KErrNone;
       
   441 	}
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 //  CMsgMailDocument::SetReceivedBinaryL()
       
   445 // -----------------------------------------------------------------------------
       
   446 //	
       
   447 TInt CMsgMailDocument::SetReceivedBinaryL(				// CSI: 40 # We must return 
       
   448 														// the integer value although this 
       
   449 														// is a leaving method.
       
   450     const TUint aMessageType, const TDesC8 /*aValue*/ )    
       
   451 	{
       
   452 	// Check that the index has correct value
       
   453 	if( aMessageType >= EIndexLast )
       
   454 		{
       
   455 	    return KErrOverflow;
       
   456 	    }
       
   457 	return KErrNone;
       
   458 	}
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 //  CMsgMailDocument::SetReceivedStringL()
       
   462 // -----------------------------------------------------------------------------
       
   463 //	
       
   464 TInt CMsgMailDocument::SetReceivedStringL(				// CSI: 40 # We must return 
       
   465 														// the integer value although this 
       
   466 															// is a leaving method.
       
   467     const TUint aMessageType, const TDesC16 /*aValue*/)
       
   468 	{
       
   469 	// Check that the index has correct value
       
   470 	if( aMessageType >= EIndexLast )
       
   471 		{
       
   472 	    return KErrOverflow;
       
   473 	    }
       
   474 	return KErrNone;
       
   475 	}
       
   476 	
       
   477 // -----------------------------------------------------------------------------
       
   478 //  CMsgMailDocument::DiskSpaceBelowCriticalLevelL()
       
   479 // -----------------------------------------------------------------------------
       
   480 //	
       
   481 TBool CMsgMailDocument::DiskSpaceBelowCriticalLevelL( TInt aBytesToWrite )
       
   482     {
       
   483     // Check that we're not under critical level
       
   484     if ( MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL(
       
   485         Session(), aBytesToWrite) )
       
   486         {
       
   487         User::Leave(KErrDiskFull);
       
   488         }
       
   489     return ETrue;        
       
   490     }
       
   491     
       
   492 // -----------------------------------------------------------------------------
       
   493 //  CMsgMailDocument::AddAttachmentNamesToMessageBodyL()
       
   494 // -----------------------------------------------------------------------------
       
   495 //	
       
   496 void CMsgMailDocument::AddAttachmentNamesToMessageBodyL( const TDesC& aString )
       
   497     {
       
   498     if ( aString.Length() )
       
   499         {            
       
   500         CImEmailMessage* mailMessage = CImEmailMessage::NewLC( CurrentEntry() );
       
   501         const TMsvId messageId = CurrentEntry().Entry().Id();
       
   502        
       
   503         CParaFormatLayer* globalParaLayer = CParaFormatLayer::NewL();
       
   504         CleanupStack::PushL( globalParaLayer );
       
   505         CCharFormatLayer* globalCharLayer = CCharFormatLayer::NewL();
       
   506         CleanupStack::PushL( globalCharLayer );
       
   507         
       
   508         CRichText* bodyText = CRichText::NewL(
       
   509             globalParaLayer,
       
   510             globalCharLayer);            
       
   511         CleanupStack::PushL( bodyText );
       
   512         
       
   513         CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();                        
       
   514         mailMessage->GetBodyTextL(
       
   515                 wait->iStatus,
       
   516                 messageId,
       
   517                 CImEmailMessage::EThisMessageOnly,
       
   518                 *bodyText,
       
   519                 *globalParaLayer,
       
   520                 *globalCharLayer );
       
   521         
       
   522         wait->Start();
       
   523         User::LeaveIfError( wait->iStatus.Int() );
       
   524         
       
   525         CleanupStack::PopAndDestroy();  // wait  
       
   526         
       
   527         // Add the file name into the body
       
   528         bodyText->InsertL( bodyText->DocumentLength(), aString);
       
   529         
       
   530         wait = CMuiuOperationWait::NewLC();    
       
   531         mailMessage->StoreBodyTextL( messageId, *bodyText, wait->iStatus );
       
   532         wait->Start();
       
   533         User::LeaveIfError( wait->iStatus.Int() );
       
   534         // wait, globalParaLayer, globalCharLayer, bodyText
       
   535         CleanupStack::PopAndDestroy(5, mailMessage);			// CSI: 47 # See a comment above.
       
   536         }
       
   537     }
       
   538 
       
   539 // -----------------------------------------------------------------------------
       
   540 //  CMsgMailDocument::GetAttachmentNamesFromMessageL()
       
   541 // -----------------------------------------------------------------------------
       
   542 //    
       
   543 HBufC* CMsgMailDocument::GetAttachmentNamesFromMessageL(
       
   544     CImEmailMessage* aMailMessage )
       
   545     {
       
   546     ASSERT( aMailMessage );
       
   547         
       
   548     const TMsvId messageId = CurrentEntry().Entry().Id();           
       
   549     aMailMessage->GetAttachmentsListL( 
       
   550         messageId,
       
   551         CImEmailMessage::EAllAttachments,
       
   552         CImEmailMessage::EThisMessageOnly );
       
   553     MMsvAttachmentManager& attachmentManager = 
       
   554         aMailMessage->AttachmentManager();
       
   555     
       
   556     HBufC* namesString = KNullDesC().AllocLC();        
       
   557     TInt count( attachmentManager.AttachmentCount() );    
       
   558     for ( TInt index(0); index < count; ++index )
       
   559         {
       
   560         CMsvAttachment* info = 
       
   561             attachmentManager.GetAttachmentInfoL( index );
       
   562         CleanupStack::PushL( info );
       
   563 
       
   564         // <<filename>>
       
   565         HBufC* filename = StringLoader::LoadLC(
       
   566             R_MAIL_REPLYATTA, info->AttachmentName() );
       
   567         
       
   568         namesString = namesString->ReAllocL( 
       
   569                 namesString->Length() + 
       
   570                 filename->Length() + 1 ); // +1 for linebreak
       
   571         
       
   572         TPtr ptr = namesString->Des();
       
   573         ptr.Append( CEditableText::ELineBreak );
       
   574         ptr.Append( *filename );
       
   575         
       
   576         CleanupStack::PopAndDestroy(2);				// CSI: 47 # info, filename
       
   577         
       
   578         // refresh namesString pointer on stack
       
   579         CleanupStack::Pop(); // namesString
       
   580         CleanupStack::PushL( namesString );
       
   581         }
       
   582         
       
   583     SetEntryWithoutNotificationL( messageId );
       
   584     CleanupStack::Pop(); // namesString
       
   585     return namesString;
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 //  CMsgMailDocument::IsPlainHTMLMessageL()
       
   590 // -----------------------------------------------------------------------------
       
   591 //  
       
   592 TBool CMsgMailDocument::IsPlainHTMLMessageL( 
       
   593     CImEmailMessage* aMailMessage )
       
   594     {
       
   595     ASSERT( aMailMessage );
       
   596     
       
   597     TBool retVal = EFalse;
       
   598         
       
   599     TMsvEmailEntry mailEntry( CurrentEntry().Entry() );  
       
   600     if ( mailEntry.MHTMLEmail() )
       
   601         {
       
   602         CParaFormatLayer* globalParaLayer = CParaFormatLayer::NewL();
       
   603         CleanupStack::PushL( globalParaLayer );
       
   604         CCharFormatLayer* globalCharLayer = CCharFormatLayer::NewL();
       
   605         CleanupStack::PushL( globalCharLayer );
       
   606         
       
   607         CRichText* bodyText = CRichText::NewL(
       
   608             globalParaLayer,
       
   609             globalCharLayer);            
       
   610         CleanupStack::PushL( bodyText );
       
   611         
       
   612         CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();                        
       
   613         aMailMessage->GetBodyTextL(
       
   614                 wait->iStatus,
       
   615                 mailEntry.Id(),
       
   616                 CImEmailMessage::EThisMessageOnly,
       
   617                 *bodyText,
       
   618                 *globalParaLayer,
       
   619                 *globalCharLayer );
       
   620   
       
   621         wait->Start();
       
   622         CleanupStack::PopAndDestroy( wait );
       
   623         
       
   624         
       
   625         
       
   626         if ( !bodyText->DocumentLength() )
       
   627             {
       
   628             retVal = ETrue;
       
   629             }
       
   630         else
       
   631             {
       
   632             retVal = EFalse;
       
   633             }
       
   634         
       
   635         // 3 globalParaLayer, globalCharLayer, bodyText     
       
   636         CleanupStack::PopAndDestroy( 3 );			// CSI: 47 # See a comment above.
       
   637         }
       
   638         
       
   639     return retVal;
       
   640     }
       
   641 	
       
   642 //  End of File
       
   643