emailuis/emailui/src/FreestyleEmailUiUtilities.cpp
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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 : General utilities for FS Email UI.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <msvapi.h>
       
    21 #include <msvids.h>
       
    22 #include <eikenv.h>
       
    23 #include <gulicon.h>
       
    24 #include <SendUiConsts.h>
       
    25 #include <MuiuMsvUiServiceUtilities.h>
       
    26 #include <StringLoader.h>
       
    27 #include <AknIconUtils.h>
       
    28 #include <aknlists.h>
       
    29 #include <aknPopup.h>
       
    30 #include <AknGlobalConfirmationQuery.h>
       
    31 #include <aknnotewrappers.h>
       
    32 #include <AknWaitDialog.h>
       
    33 #include <AknGlobalNote.h>
       
    34 #include <commonphoneparser.h>
       
    35 #include <apgcli.h> // RApaLsSession
       
    36 
       
    37 #ifndef FF_CMAIL_INTEGRATION
       
    38 #include <txtclipboard.h>
       
    39 #endif // FF_CMAIL_INTEGRATION
       
    40 
       
    41 // <cmail>
       
    42 //#ifdef __SERIES60_32__
       
    43 // </cmail>
       
    44 #include <AiwDialDataTypes.h>
       
    45 #include <AiwGenericParam.h>
       
    46 #include <AiwServiceHandler.h>
       
    47 #include <settingsinternalcrkeys.h>
       
    48 
       
    49 // <cmail>
       
    50 //#else
       
    51 //#include <CPhCltDialer.h>
       
    52 //#include <TPhCltExtPhoneDialData.h>
       
    53 //#endif
       
    54 // </cmail>
       
    55 
       
    56 #include <aknPopup.h>
       
    57 #include <AknCommonDialogsDynMem.h>
       
    58 #include <CommonDialogs.rsg>
       
    59 #include <pathinfo.h>
       
    60 #include <AknIconArray.h>
       
    61 #include <baclipb.h> // for clipboard copy
       
    62 #include <DocumentHandler.h>
       
    63 #include <bautils.h>
       
    64 
       
    65 #include <sendui.h>			// CSendUi
       
    66 #include <coreapplicationuisdomainpskeys.h> // P&S key for email notification
       
    67 #include <e32property.h>					// RPoperty
       
    68 #include <SendUiConsts.h>	// Constants for sendui
       
    69 #include <CMessageData.h>	// CMessageData
       
    70 #include <CSendingServiceInfo.h>
       
    71 #include <CoreApplicationUIsSDKCRKeys.h> // offline mode keys
       
    72 #include <data_caging_path_literals.hrh>
       
    73 
       
    74 
       
    75 // <cmail> Removed DISABLE_DEFAULT_EMAIL
       
    76 //#ifndef DISABLE_DEFAULT_EMAIL
       
    77 //#include <MessagingDomainCRKeys.h>
       
    78 //#include <centralrepository.h>
       
    79 //#endif
       
    80 //</cmail>
       
    81 
       
    82 //<cmail>
       
    83 #include "cfsccontactactionservice.h"
       
    84 #include "cfsccontactactionmenu.h"
       
    85 #include "cfsccontactactionmenuitem.h"
       
    86 #include "mfsccontactactionmenumodel.h"
       
    87 //</cmail>
       
    88 
       
    89 #include <FreestyleEmailUi.rsg>
       
    90 #include <freestyleemailui.mbg>
       
    91 
       
    92 //<cmail>
       
    93 #include "CFSMailCommon.h"
       
    94 #include "CFSMailClient.h"
       
    95 #include "CFSMailBox.h"
       
    96 #include "CFSMailMessage.h"
       
    97 #include "cesmricalviewer.h"
       
    98 //</cmail>
       
    99 
       
   100 #include "FreestyleEmailUiUtilities.h"
       
   101 #include "FreestyleEmailUiConstants.h"
       
   102 #include "FreestyleEmailUiLiterals.h"
       
   103 #include "FreestyleEmailUiAppui.h"
       
   104 #include "FSDelayedLoader.h"
       
   105 #include "FSEmail.pan"
       
   106 
       
   107 // CONSTANTS
       
   108 _LIT( KFsEmailIconFileName, "FreestyleEmailUi.mif" );
       
   109 _LIT( KFsEmailTempDirName, "temp\\" );
       
   110 static const TUint KSecondSeparator = 1;
       
   111 _LIT( KTimeFormatBefore, "%-B" );
       
   112 _LIT( KTimeFormatAfter, "%+B" );
       
   113 _LIT( KTimeFormatHour, "%J" );
       
   114 _LIT( KTimeFormatMinutes, "%T" );
       
   115 _LIT( KTimeFormatSpace, " ");
       
   116 
       
   117 // MIME types
       
   118 _LIT( KPdfMimeString, "application/pdf" );
       
   119 _LIT( KRtfMimeString, "application/rtf" );
       
   120 _LIT( KDocMimeString, "application/msword" );
       
   121 _LIT( KDocMimeString2, "application/vnd.ms-word" );
       
   122 _LIT( KPptMimeString, "application/vnd.ms-powerpoint" );
       
   123 _LIT( KXlsMimeString, "application/vnd.ms-excel" );
       
   124 _LIT( KImageMimeString, "image/" );
       
   125 _LIT( KHtmlMimeString, "text/html" );
       
   126 _LIT( KPlainTextMimeString, "text/plain" );
       
   127 _LIT( KVCalMimeString, "text/x-vcalendar" );
       
   128 _LIT( KMessageMimeString, "message/rfc822" );
       
   129 
       
   130 // File name extensions
       
   131 _LIT( KDocFileExtension, ".doc" );
       
   132 _LIT( KRtfFileExtension, ".rtf" );
       
   133 _LIT( KPptFileExtension, ".ppt" );
       
   134 _LIT( KXlsFileExtension, ".xls" );
       
   135 _LIT( KPdfFileExtension, ".pdf" );
       
   136 _LIT( KJpgFileExtension, ".jpg" );
       
   137 _LIT( KJpegFileExtension, ".jpeg" );
       
   138 _LIT( KJpgeFileExtension, ".jpge" );
       
   139 _LIT( KPngFileExtension, ".png" );
       
   140 _LIT( KGifFileExtension, ".gif" );
       
   141 _LIT( KBmpFileExtension, ".bmp" );
       
   142 _LIT( KHtmlFileExtension, ".html" );
       
   143 _LIT( KHtmFileExtension, ".htm" );
       
   144 _LIT( KTxtFileExtension, ".txt" );
       
   145 _LIT( KVCalFileExtension, ".vcs" );
       
   146 _LIT( KEmailFileExtension, ".eml" );
       
   147 
       
   148 // If the fetched body size (in bytes) is more than these limits,
       
   149 // a wait note is used when opening, replying, or forwarding the message
       
   150 static const TInt KLargePlainTextSizeLimit = 20000;
       
   151 static const TInt KLargeHtmlTextSizeLimit = 50000;
       
   152 
       
   153 //<cmail> id is different in cmail
       
   154 const TUid KFSMailServerUid = { 0x2001F40A };
       
   155 _LIT( KFSMailServerExe, "\\sys\\bin\\fsmailserver.exe" );
       
   156 //</cmail>
       
   157 
       
   158 // Define static members
       
   159 CAknGlobalNote* TFsEmailUiUtility::iGlobalWaitNote = NULL;
       
   160 // <cmail>
       
   161 CESMRIcalViewer* TFsEmailUiUtility::iMrViewer = NULL;
       
   162 TFsEmailUiUtility::CMrViewerEmptyCallback* TFsEmailUiUtility::iMrViewerCallback = NULL;
       
   163 CAknWaitDialog* TFsEmailUiUtility::iOpeningWaitNote = NULL;
       
   164 // </cmail>
       
   165 
       
   166 // FUNCTION DEFINITIONS
       
   167 void TFsEmailUiUtility::LaunchHelpL( const TDesC& aContext )
       
   168 	{
       
   169     FUNC_LOG;
       
   170     CArrayFix< TCoeHelpContext >* cntx = new( ELeave ) CArrayFixFlat< TCoeHelpContext >( 1 );
       
   171     CleanupStack::PushL( cntx );
       
   172     cntx->AppendL( TCoeHelpContext( KFSEmailUiUid, aContext ) );
       
   173     CleanupStack::Pop( cntx );
       
   174     HlpLauncher::LaunchHelpApplicationL( CEikonEnv::Static()->WsSession(), cntx );
       
   175 	}
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Two-phased constructor.
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 CFsEmailFileHandleShutter* CFsEmailFileHandleShutter::NewL(
       
   182     CDocumentHandler& aDocumentHandler )
       
   183     {
       
   184     FUNC_LOG;
       
   185     CFsEmailFileHandleShutter* self = new (ELeave) CFsEmailFileHandleShutter;
       
   186     CleanupStack::PushL( self );
       
   187     self->ConstructL( aDocumentHandler );
       
   188     CleanupStack::Pop( self );
       
   189     return self;
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // Destructor. File handle is closed, if it has been left open.
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 CFsEmailFileHandleShutter::~CFsEmailFileHandleShutter()
       
   197     {
       
   198     FUNC_LOG;
       
   199     if (iHandleOpen)
       
   200         {
       
   201         iFileHandle.Close();
       
   202         }
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // Stores the give file handle.
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void CFsEmailFileHandleShutter::SetFile( RFile aFile )
       
   210     {
       
   211     FUNC_LOG;
       
   212     // Close previously set handle, if necessary.
       
   213     if ( iHandleOpen )
       
   214         {
       
   215         iFileHandle.Close();
       
   216         }
       
   217 
       
   218     iFileHandle = aFile;
       
   219     iHandleOpen = ETrue;
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Handles the exit of embedded viewer application.
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CFsEmailFileHandleShutter::HandleServerAppExit( TInt aReason )
       
   227     {
       
   228     FUNC_LOG;
       
   229     if (iHandleOpen)
       
   230         {
       
   231         // Close open file handle.
       
   232         iFileHandle.Close();
       
   233         iHandleOpen = EFalse;
       
   234         }
       
   235     MAknServerAppExitObserver::HandleServerAppExit( aReason );
       
   236 
       
   237     // Clear the temp directory since the closed file might have been copied there
       
   238     TFsEmailUiUtility::EraseTempDir();
       
   239     }
       
   240 
       
   241 CFsEmailFileHandleShutter::CFsEmailFileHandleShutter()
       
   242     : iHandleOpen(EFalse)
       
   243     {
       
   244     FUNC_LOG;
       
   245     }
       
   246 
       
   247 void CFsEmailFileHandleShutter::ConstructL(
       
   248     CDocumentHandler& aDocumentHandler )
       
   249     {
       
   250     FUNC_LOG;
       
   251     aDocumentHandler.SetExitObserver(this);
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // Clean up any static variables of the class
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void TFsEmailUiUtility::DeleteStaticData()
       
   259     {
       
   260     FUNC_LOG;
       
   261     delete iGlobalWaitNote;
       
   262     iGlobalWaitNote = NULL;
       
   263 
       
   264     // <cmail>
       
   265     delete iMrViewer;
       
   266     iMrViewer = NULL;
       
   267 
       
   268     delete iMrViewerCallback;
       
   269     iMrViewerCallback = NULL;
       
   270     // </cmail>
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // GetMceDefaultMailboxL
       
   275 // Returrn the default mailbox. If one the FS account is set as default return
       
   276 // it else return the first FS account. If no FS account then returns NULL.
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 CFSMailBox* TFsEmailUiUtility::GetMceDefaultMailboxL( CFSMailClient& aClient, CMsvSession& aMsvSession )
       
   280 	{
       
   281     FUNC_LOG;
       
   282 // <cmail> S60 UID update
       
   283 	const TUid KUidMsgValTypeFsMtmVal = { 0x2001F406 };
       
   284 // </cmail> S60 UID update
       
   285 	TFSMailMsgId id;
       
   286     TBool getFirstInList = EFalse;
       
   287 
       
   288     CMsvEntry* root = CMsvEntry::NewL( aMsvSession, KMsvRootIndexEntryId,
       
   289 	        TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) );
       
   290     CleanupStack::PushL( root );
       
   291 
       
   292 // <cmail> Removed DISABLE_DEFAULT_EMAIL
       
   293 /*#ifndef DISABLE_DEFAULT_EMAIL
       
   294     TInt entryId;
       
   295     TInt rval;
       
   296     CRepository* repository = NULL;
       
   297     TRAPD( ret, repository = CRepository::NewL(KCRUidSelectableDefaultEmailSettings) );
       
   298     if ( ret == KErrNone )
       
   299         {
       
   300         CleanupStack::PushL( repository );
       
   301         rval = repository->Get( KSelectableDefaultMailAccount, entryId );
       
   302         if( rval == KErrNone && entryId != -1 )
       
   303         	{
       
   304 	   		root->SetEntryL( entryId );
       
   305 	        if ( root->Entry().iMtm == KUidMsgValTypeFsMtmVal )
       
   306 	        	{
       
   307 	        	// One of The FS is default e-mail account.
       
   308 	        	id = TFSMailMsgId( root->Entry().iMtmData1, root->Entry().iMtmData2 );
       
   309 	        	}
       
   310 	        else
       
   311 	        	{
       
   312 	            // If FS is not default then get the first one in the list
       
   313 	        	getFirstInList = ETrue;
       
   314 	        	}
       
   315         	}
       
   316         else
       
   317         	{
       
   318             // If no mail box is set as default, then get the first one in the list
       
   319         	getFirstInList = ETrue;
       
   320         	}
       
   321         CleanupStack::PopAndDestroy( repository );
       
   322         }
       
   323     else
       
   324     	{
       
   325         // If Failed to create repository, then get the first one in the list
       
   326     	getFirstInList = ETrue;
       
   327     	}
       
   328 #else*/
       
   329     // If the SDK doesn't have default mail box concept.
       
   330     getFirstInList = ETrue;
       
   331 //#endif
       
   332 // </cmail>
       
   333     if( getFirstInList )
       
   334     	{
       
   335     	// Get the list and return the first one.
       
   336     	root->SetEntryL( KMsvRootIndexEntryId );
       
   337     	CMsvEntrySelection* childSelection = root->ChildrenWithMtmL(
       
   338         	KUidMsgValTypeFsMtmVal );
       
   339         CleanupStack::PushL( childSelection );
       
   340 
       
   341         if ( childSelection->Count() > 0)
       
   342         	{
       
   343         	root->SetEntryL( childSelection->At( 0 ) );
       
   344         	id = TFSMailMsgId( root->Entry().iMtmData1, root->Entry().iMtmData2 );
       
   345         	}
       
   346         else
       
   347         	{
       
   348         	// No FS Mail box.
       
   349         	//id.SetNullId();
       
   350         	}
       
   351         CleanupStack::PopAndDestroy( childSelection );
       
   352     	}
       
   353     CleanupStack::PopAndDestroy( root );
       
   354     if( id.IsNullId() )
       
   355     	{
       
   356     	// If No FS Mailbox then return NULL.
       
   357     	return NULL;
       
   358     	}
       
   359     else
       
   360     	{
       
   361     	CFSMailBox* mailbox = aClient.GetMailBoxByUidL( id );
       
   362     	return mailbox;
       
   363     	}
       
   364 	}
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // GetMailboxForMtmIdL
       
   368 // Return the mailbox based on mtm id. If there is an mtm account with aMtmId
       
   369 // return the mail box of it else returns NULL
       
   370 // ---------------------------------------------------------------------------
       
   371 //
       
   372 CFSMailBox* TFsEmailUiUtility::GetMailboxForMtmIdL( CFSMailClient& aClient,
       
   373     CMsvSession& aMsvSession, TMsvId  aMtmId )
       
   374 	{
       
   375     FUNC_LOG;
       
   376 // <cmail> S60 UID update
       
   377 	const TUid KUidMsgValTypeFsMtmVal = { 0x2001F406 };
       
   378 // </cmail> S60 UID update
       
   379 	CMsvEntry* accountEntry = NULL;
       
   380 	TRAPD(err, accountEntry = CMsvEntry::NewL( aMsvSession, aMtmId,
       
   381             TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue )));
       
   382     if(err == KErrNotFound || err == KErrNoMemory ||
       
   383         accountEntry->Entry().iMtm != KUidMsgValTypeFsMtmVal)
       
   384         {
       
   385         // This Mtm Id is not found or the found entry is not FS entry
       
   386         return NULL;
       
   387         }
       
   388 	CleanupStack::PushL( accountEntry );
       
   389     TFSMailMsgId id = TFSMailMsgId( accountEntry->Entry().MtmData1(),
       
   390         accountEntry->Entry().MtmData2() );
       
   391     CleanupStack::PopAndDestroy( accountEntry );
       
   392     CFSMailBox* mailbox = aClient.GetMailBoxByUidL( id );
       
   393     return mailbox;
       
   394 	}
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // TFsEmailUiUtility::IsRemoteLookupSupported
       
   398 // -----------------------------------------------------------------------------
       
   399 TBool TFsEmailUiUtility::IsRemoteLookupSupported( CFSMailBox& aMailBox )
       
   400 	{
       
   401     FUNC_LOG;
       
   402 
       
   403 	TBool r = aMailBox.HasCapability( EFSMBoxCapaSupportsRCL );
       
   404 
       
   405 	return r;
       
   406 	}
       
   407 
       
   408 // -----------------------------------------------------------------------------
       
   409 // TFsEmailUiUtility::ShowConfirmationQuery
       
   410 // -----------------------------------------------------------------------------
       
   411 TInt TFsEmailUiUtility::ShowConfirmationQueryL( TInt aResourceStringId,
       
   412 												const TDesC& aResourceParameter )
       
   413     {
       
   414     FUNC_LOG;
       
   415     CFSEmailUiCallDialog* queryNote = new ( ELeave ) CFSEmailUiCallDialog();
       
   416     CleanupStack::PushL( queryNote );
       
   417     HBufC* resourceString = NULL;
       
   418     if ( aResourceParameter != KNullDesC )
       
   419     	{
       
   420     	resourceString = StringLoader::LoadLC( aResourceStringId,
       
   421                                                aResourceParameter );
       
   422     	}
       
   423     else
       
   424     	{
       
   425     	resourceString = StringLoader::LoadLC( aResourceStringId );
       
   426     	}
       
   427     queryNote->SetPromptL( *resourceString );
       
   428     CleanupStack::PopAndDestroy( resourceString );
       
   429     CleanupStack::Pop( queryNote );
       
   430     return queryNote->ExecuteLD( R_FSEMAIL_QUERY_DIALOG );
       
   431     }
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // TFsEmailUiUtility::ShowConfirmationQuery
       
   435 // -----------------------------------------------------------------------------
       
   436 TInt TFsEmailUiUtility::ShowConfirmationQueryL( const TDesC& aPromptText )
       
   437     {
       
   438     FUNC_LOG;
       
   439     CFSEmailUiCallDialog* queryNote = new ( ELeave ) CFSEmailUiCallDialog();
       
   440     CleanupStack::PushL( queryNote );
       
   441     queryNote->SetPromptL( aPromptText );
       
   442     CleanupStack::Pop( queryNote );
       
   443     return queryNote->ExecuteLD( R_FSEMAIL_QUERY_DIALOG );
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // TFsEmailUiUtility::ShowErrorNoteL
       
   448 // -----------------------------------------------------------------------------
       
   449 void TFsEmailUiUtility::ShowErrorNoteL( TInt aResourceStringId, TBool aWaitingDialog )
       
   450 	{
       
   451     FUNC_LOG;
       
   452 	HBufC* errMessage = StringLoader::LoadLC( aResourceStringId );
       
   453 	CAknErrorNote* note = new (ELeave) CAknErrorNote( aWaitingDialog );
       
   454 	note->ExecuteLD( *errMessage );
       
   455 	CleanupStack::PopAndDestroy( errMessage );
       
   456 	}
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // TFsEmailUiUtility::ShowInfoNoteL
       
   460 // -----------------------------------------------------------------------------
       
   461 void TFsEmailUiUtility::ShowInfoNoteL( TInt aResourceStringId, TBool aWaitingDialog )
       
   462     {
       
   463     FUNC_LOG;
       
   464 	HBufC* message = StringLoader::LoadLC( aResourceStringId );
       
   465 	CAknInformationNote* note = new (ELeave) CAknInformationNote( aWaitingDialog );
       
   466 	note->ExecuteLD( *message );
       
   467 	CleanupStack::PopAndDestroy( message );
       
   468     }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // TFsEmailUiUtility::ShowGlobalErrorNoteL
       
   472 // -----------------------------------------------------------------------------
       
   473 void TFsEmailUiUtility::ShowGlobalErrorNoteL( TInt aResourceStringId )
       
   474     {
       
   475     FUNC_LOG;
       
   476     HBufC* noteText = StringLoader::LoadLC( aResourceStringId );
       
   477     CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
       
   478     globalNote->ShowNoteL( EAknGlobalErrorNote, *noteText );
       
   479     CleanupStack::PopAndDestroy( globalNote );
       
   480     CleanupStack::PopAndDestroy( noteText );
       
   481     }
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // TFsEmailUiUtility::ShowGlobalInfoNoteL
       
   485 // -----------------------------------------------------------------------------
       
   486 void TFsEmailUiUtility::ShowGlobalInfoNoteL( TInt aResourceStringId )
       
   487     {
       
   488     FUNC_LOG;
       
   489     HBufC* noteText = StringLoader::LoadLC( aResourceStringId );
       
   490     CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
       
   491     globalNote->ShowNoteL( EAknGlobalInformationNote, *noteText );
       
   492     CleanupStack::PopAndDestroy( globalNote );
       
   493     CleanupStack::PopAndDestroy( noteText );
       
   494     }
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // TFsEmailUiUtility::ShowWaitNoteL
       
   498 // -----------------------------------------------------------------------------
       
   499 void TFsEmailUiUtility::ShowWaitNoteL( CAknWaitDialog*& aDialog, TInt aTextResourceId,
       
   500         TBool aAllowCancel, TBool aVisibilityDelayOff /*= EFalse*/ )
       
   501     {
       
   502     FUNC_LOG;
       
   503     if ( !aDialog )
       
   504         {
       
   505         aDialog = new (ELeave) CAknWaitDialog(
       
   506                 reinterpret_cast<CEikDialog**>(&aDialog), aVisibilityDelayOff );
       
   507         }
       
   508 
       
   509     if ( aAllowCancel )
       
   510         {
       
   511         aDialog->PrepareLC( R_FSE_WAIT_DIALOG );
       
   512         }
       
   513     else
       
   514         {
       
   515         aDialog->PrepareLC( R_FSE_WAIT_DIALOG_NO_CANCEL );
       
   516         }
       
   517 
       
   518     HBufC* noteText = StringLoader::LoadLC( aTextResourceId );
       
   519     aDialog->SetTextL( *noteText );
       
   520     CleanupStack::PopAndDestroy( noteText );
       
   521 
       
   522     aDialog->RunLD();
       
   523     }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // TFsEmailUiUtility::ShowGlobalWaitNoteLC
       
   527 // -----------------------------------------------------------------------------
       
   528 TInt TFsEmailUiUtility::ShowGlobalWaitNoteLC( TInt aTextResourceId )
       
   529     {
       
   530     FUNC_LOG;
       
   531     if ( !iGlobalWaitNote )
       
   532         {
       
   533         iGlobalWaitNote = CAknGlobalNote::NewL();
       
   534         iGlobalWaitNote->SetSoftkeys( R_AVKON_SOFTKEYS_EMPTY );
       
   535         }
       
   536 
       
   537     HBufC* noteText = StringLoader::LoadLC( aTextResourceId );
       
   538     TInt waitNoteId = iGlobalWaitNote->ShowNoteL( EAknGlobalWaitNote, *noteText );
       
   539     CleanupStack::PopAndDestroy( noteText );
       
   540 
       
   541     TCleanupItem closeNoteItem( CloseGlobalWaitNote,
       
   542                                 reinterpret_cast<TAny*>(waitNoteId) );
       
   543     CleanupStack::PushL( closeNoteItem );
       
   544 
       
   545     return waitNoteId;
       
   546     }
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // TFsEmailUiUtility::CloseGlobalWaitNote
       
   550 // -----------------------------------------------------------------------------
       
   551 void TFsEmailUiUtility::CloseGlobalWaitNote( TAny* aNoteId )
       
   552     {
       
   553     FUNC_LOG;
       
   554     if ( iGlobalWaitNote )
       
   555         {
       
   556         TInt noteId = reinterpret_cast<TInt>( aNoteId );
       
   557         TRAP_IGNORE( iGlobalWaitNote->CancelNoteL( noteId ) );
       
   558         }
       
   559     }
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // TFsEmailUiUtility::ShowSelectFileDialogL
       
   563 // -----------------------------------------------------------------------------
       
   564 //
       
   565 TBool TFsEmailUiUtility::ShowSelectFileDialogL( TDes& aFileName )
       
   566     {
       
   567     FUNC_LOG;
       
   568     return ShowFileDialogL( ECFDDialogTypeSelect, aFileName );
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // TFsEmailUiUtility::ShowSaveFolderDialogL
       
   573 // -----------------------------------------------------------------------------
       
   574 TBool TFsEmailUiUtility::ShowSaveFolderDialogL( TDes& aFileName )
       
   575 	{
       
   576     FUNC_LOG;
       
   577     return ShowFileDialogL( ECFDDialogTypeSave, aFileName );
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // TFsEmailUiUtility::ShowSaveFolderDialogL
       
   582 // -----------------------------------------------------------------------------
       
   583 TBool TFsEmailUiUtility::ShowFileDialogL( TInt aType, TDes& aFileName )
       
   584 	{
       
   585     FUNC_LOG;
       
   586 	TInt retVal = EFalse;
       
   587 
       
   588 	TInt allDrives =
       
   589         AknCommonDialogsDynMem::EMemoryTypePhone |
       
   590         AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage |
       
   591         AknCommonDialogsDynMem::EMemoryTypeMMCExternal |
       
   592         AknCommonDialogsDynMem::EMemoryTypeRemote;
       
   593 
       
   594 	if ( aType == ECFDDialogTypeSelect )
       
   595 	    {
       
   596 	    retVal = AknCommonDialogsDynMem::RunSelectDlgLD( allDrives, aFileName, 0 );
       
   597 	    }
       
   598 	else if ( aType == ECFDDialogTypeSave )
       
   599 	    {
       
   600 	    // We can't use the SaveDlg of CommonDialogs because it launches also the file name query
       
   601 	    // which we do not want. Instead, we use move-to-folder dialog with the title and softkeys
       
   602 	    // of the save dialog.
       
   603 	    retVal = AknCommonDialogsDynMem::RunMoveDlgLD( allDrives, aFileName,
       
   604 	            R_CFD_DEFAULT_SAVE_MEMORY_SELECTION, R_CFD_DEFAULT_SAVE_FILE_SELECTION );
       
   605 	    }
       
   606 	else
       
   607 	    {
       
   608 	    __ASSERT_DEBUG( EFalse, Panic(EFSEmailUiUnexpectedValue) );
       
   609 	    }
       
   610 
       
   611 	return retVal;
       
   612 	}
       
   613 
       
   614 
       
   615 // -----------------------------------------------------------------------------
       
   616 // TFsEmailUiUtility::OkToSaveFileL
       
   617 // -----------------------------------------------------------------------------
       
   618 TBool TFsEmailUiUtility::OkToSaveFileL( const TDesC& aFilePath, CFSMailMessagePart& aAttachmentPart )
       
   619 	{
       
   620     FUNC_LOG;
       
   621 	TBool ret( ETrue );
       
   622 	TDesC& name = aAttachmentPart.AttachmentNameL();
       
   623 	HBufC* realFilePath = HBufC::NewLC( aFilePath.Length() + name.Length() );
       
   624 	realFilePath->Des().Append( aFilePath);
       
   625 	realFilePath->Des().Append( name);
       
   626 	if ( BaflUtils::FileExists( CEikonEnv::Static()->FsSession(), *realFilePath ) )
       
   627 		{
       
   628 		if ( !TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_UI_OVERWRITE_QUERY, name  )	)
       
   629 			{
       
   630 			ret = EFalse;
       
   631 			}
       
   632 		}
       
   633 	CleanupStack::PopAndDestroy( realFilePath );
       
   634 	return ret;
       
   635 	}
       
   636 
       
   637 // -----------------------------------------------------------------------------
       
   638 // <cmail>
       
   639 // TFsEmailUiUtility::ShowFileSavedToFolderNoteL
       
   640 // -----------------------------------------------------------------------------
       
   641 void TFsEmailUiUtility::ShowFilesSavedToFolderNoteL( TInt aCount )
       
   642     {
       
   643     FUNC_LOG;
       
   644     CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
       
   645     if ( aCount == 1 )
       
   646         {
       
   647         HBufC* noteText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_ONE_ATTACHMENT_SAVED );
       
   648         globalNote->ShowNoteL( EAknGlobalInformationNote, *noteText );
       
   649         CleanupStack::PopAndDestroy( noteText );
       
   650         }
       
   651     else if ( aCount > 1 )
       
   652         {
       
   653         HBufC* noteText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_MULTIPLE_ATTACHMENT_SAVED, aCount );
       
   654         globalNote->ShowNoteL( EAknGlobalInformationNote, *noteText );
       
   655         CleanupStack::PopAndDestroy( noteText );
       
   656         }
       
   657     CleanupStack::PopAndDestroy( globalNote );
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // TFsEmailUiUtility::OpenFileL
       
   662 // -----------------------------------------------------------------------------
       
   663 void TFsEmailUiUtility::OpenFileL( RFile& aFileToOpen, TBool aAllowSave  )
       
   664     {
       
   665     FUNC_LOG;
       
   666     TDataType emptyDataType;
       
   667     OpenFileL( aFileToOpen, emptyDataType,aAllowSave );
       
   668     }
       
   669 
       
   670 // -----------------------------------------------------------------------------
       
   671 // TFsEmailUiUtility::OpenFileL
       
   672 // -----------------------------------------------------------------------------
       
   673 void TFsEmailUiUtility::OpenFileL( RFile& aFileToOpen, TDataType& aDataType, TBool aAllowSave )
       
   674     {
       
   675     FUNC_LOG;
       
   676     CFreestyleEmailUiAppUi* appUi = (CFreestyleEmailUiAppUi*)CCoeEnv::Static()->AppUi();
       
   677 
       
   678     // Set file handle shutter to close the file handle after the embedded
       
   679     // viewer application exits.
       
   680     appUi->FileHandleShutter().SetFile( aFileToOpen );
       
   681 
       
   682     CDocumentHandler& docHandler = appUi->DocumentHandler();
       
   683    	CAiwGenericParamList& paramList = docHandler.InParamListL();
       
   684 
       
   685    	// Set allow save to parameter.
       
   686    	if ( aAllowSave )
       
   687    	    {
       
   688         TAiwVariant allowSaveVariant( ETrue );
       
   689         TAiwGenericParam genericParamAllowSave( EGenericParamAllowSave,
       
   690                 allowSaveVariant );
       
   691         paramList.AppendL( genericParamAllowSave );
       
   692    	    }
       
   693 
       
   694     TInt res = KErrNone;
       
   695     TRAPD( err, res = docHandler.OpenFileEmbeddedL( aFileToOpen, aDataType, paramList ) );
       
   696 
       
   697     // Try again with an empty data type if opening using the given data type fails
       
   698     if ( err != KErrNone || res != KErrNone )
       
   699         {
       
   700         TDataType emptyType;
       
   701 
       
   702         // Open file embedded
       
   703  	    TRAP( err, res = docHandler.OpenFileEmbeddedL( aFileToOpen, emptyType, paramList ) );
       
   704 
       
   705         // Show an error note if opening the file still didn't succeed
       
   706         // Ensure also that the file handle got closed.
       
   707         if ( err != KErrNone || res != KErrNone )
       
   708             {
       
   709             ShowErrorNoteL( R_FREESTYLE_EMAIL_INFO_NOTE_UNABLE_TO_OPEN, EFalse );
       
   710             appUi->FileHandleShutter().HandleServerAppExit( KErrCancel );
       
   711             }
       
   712         }
       
   713 	}
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 // TFsEmailUiUtility::OpenAttachmentL
       
   717 // -----------------------------------------------------------------------------
       
   718 void TFsEmailUiUtility::OpenAttachmentL( const TPartData& aAttachmentPart )
       
   719     {
       
   720     FUNC_LOG;
       
   721     CFreestyleEmailUiAppUi* appUi = (CFreestyleEmailUiAppUi*)CCoeEnv::Static()->AppUi();
       
   722     CFSMailMessage* mailMessage = appUi->GetMailClient()->GetMessageByUidL(
       
   723         aAttachmentPart.iMailBoxId, aAttachmentPart.iFolderId,
       
   724         aAttachmentPart.iMessageId, EFSMsgDataStructure );
       
   725 
       
   726     CleanupStack::PushL( mailMessage );
       
   727     CFSMailMessagePart* messagePart = mailMessage->ChildPartL(
       
   728         aAttachmentPart.iMessagePartId );
       
   729     CleanupStack::PushL( messagePart );
       
   730 
       
   731     OpenAttachmentL( *messagePart );
       
   732 
       
   733     CleanupStack::PopAndDestroy( messagePart );
       
   734     CleanupStack::PopAndDestroy( mailMessage );
       
   735     }
       
   736 
       
   737 // -----------------------------------------------------------------------------
       
   738 // TFsEmailUiUtility::OpenAttachmentL
       
   739 // -----------------------------------------------------------------------------
       
   740 void TFsEmailUiUtility::OpenAttachmentL( CFSMailMessagePart& aAttachmentPart,
       
   741         TBool aAllowSave /*= ETrue*/)
       
   742     {
       
   743     FUNC_LOG;
       
   744     const TDesC& attName = aAttachmentPart.AttachmentNameL();
       
   745     const TDesC* mimeType16 = &aAttachmentPart.GetContentType();
       
   746     TFileType fileType = GetFileType( attName, *mimeType16 );
       
   747 
       
   748     // Check if attachment is actually an embedded message object. In that case we try to
       
   749     // open it using mail viewer.
       
   750     TBool openedAsMessage = EFalse;
       
   751     if ( fileType == EMessageType )
       
   752         {
       
   753         CFreestyleEmailUiAppUi* appUi =
       
   754             static_cast<CFreestyleEmailUiAppUi*>( CCoeEnv::Static()->AppUi() );
       
   755 
       
   756         // First, try to get the message object directly from mail client using the UIDs.
       
   757         CFSMailMessage* message = NULL;
       
   758         TRAP_IGNORE( message = appUi->GetMailClient()->GetMessageByUidL(
       
   759                 aAttachmentPart.GetMailBoxId(),
       
   760                 aAttachmentPart.GetFolderId(),
       
   761                 aAttachmentPart.GetPartId(),
       
   762                 EFSMsgDataEnvelope ) );
       
   763 
       
   764         // If we still have no message, then try to convert the attachment file to message object (Activesync case).
       
   765         if ( !message ) 
       
   766             {
       
   767             // This takes some time so we show a wait dialog.
       
   768             if ( iOpeningWaitNote )
       
   769                 {
       
   770                 iOpeningWaitNote->ProcessFinishedL();
       
   771                 iOpeningWaitNote = NULL;
       
   772                 }
       
   773             ShowWaitNoteL( iOpeningWaitNote, R_FSE_WAIT_OPENING_TEXT, EFalse, ETrue );
       
   774 
       
   775             RFile attFile = aAttachmentPart.GetContentFileL();
       
   776             CleanupClosePushL( attFile );
       
   777             CFSMailBox* mailbox = appUi->GetMailClient()->GetMailBoxByUidL( aAttachmentPart.GetMailBoxId() );
       
   778             CleanupStack::PushL( mailbox );
       
   779             TRAP_IGNORE( message = mailbox->CreateMessageFromFileL( attFile ) );
       
   780             CleanupStack::PopAndDestroy( mailbox );
       
   781             CleanupStack::PopAndDestroy( &attFile );
       
   782 
       
   783             iOpeningWaitNote->ProcessFinishedL();
       
   784             }
       
   785 
       
   786         // Open message to viewer if we got it. Otherwise continue with the standard file opening logic.
       
   787         if ( message )
       
   788             {
       
   789             // Check that the embedded message has text body part or html body part. 
       
   790             // Otherwise we cannot display it viewer and needs to be handled as a normal attachment.
       
   791             
       
   792             CFSMailMessagePart* htmlPart = message->HtmlBodyPartL();
       
   793             CFSMailMessagePart* textPart = message->PlainTextBodyPartL();
       
   794             
       
   795             if ( htmlPart || textPart  )
       
   796                 {
       
   797                 THtmlViewerActivationData htmlData; 
       
   798                 htmlData.iActivationDataType = THtmlViewerActivationData::EmbeddedEmailMessage;
       
   799                 htmlData.iMailBoxId = aAttachmentPart.GetMailBoxId();
       
   800                 htmlData.iFolderId = aAttachmentPart.GetFolderId();
       
   801                 htmlData.iMessageId = aAttachmentPart.GetPartId();
       
   802                 // ownership of message gets transfered to html viewer.
       
   803                 htmlData.iEmbeddedMessage = message;
       
   804                 htmlData.iEmbeddedMessageMode = ETrue;
       
   805                 TPckgBuf<THtmlViewerActivationData> pckgData( htmlData );
       
   806                 
       
   807                 appUi->EnterFsEmailViewL( HtmlViewerId, KStartViewerWithEmbeddedMsgPtr, pckgData );
       
   808                 openedAsMessage = ETrue;
       
   809                 }
       
   810             else
       
   811                 {
       
   812                 //delete message object owned by us.
       
   813                 delete message;
       
   814                 }
       
   815             
       
   816             if( htmlPart )
       
   817                 {
       
   818                 delete htmlPart;
       
   819                 }
       
   820             if( textPart )
       
   821                 {
       
   822                 delete textPart;
       
   823                 }
       
   824             
       
   825             }
       
   826         }
       
   827 
       
   828     // Normal attachment file opening
       
   829     if ( !openedAsMessage )
       
   830         {
       
   831         RFile attachmentFile;
       
   832 
       
   833         // Get the temp file provided by plugin
       
   834         RFile pluginTempFile = aAttachmentPart.GetContentFileL();
       
   835         CleanupClosePushL( pluginTempFile );
       
   836 
       
   837         // Check if the temp file has diffrent file extension than the attachment name.
       
   838         TFileName tempFileName;
       
   839         pluginTempFile.Name( tempFileName );
       
   840         const TDesC& attName = aAttachmentPart.AttachmentNameL();
       
   841         if ( !DoFileExtensionsMatchL( tempFileName, attName ) )
       
   842             {
       
   843             // Make a new temporary copy of the attachment file if the temp file
       
   844             // provided by the plugin does not have a proper file extension.
       
   845             // This is needed because some applications may not
       
   846             // allow opening files with improper file extension.
       
   847             attachmentFile = CopyFileToTempDirL( pluginTempFile, attName );
       
   848             CleanupStack::PopAndDestroy( &pluginTempFile );
       
   849             }
       
   850         else
       
   851             {
       
   852             // Otherwise we may use the temp file provided by plugin directly
       
   853             attachmentFile = pluginTempFile;
       
   854             CleanupStack::Pop( &pluginTempFile );
       
   855             }
       
   856         CleanupClosePushL( attachmentFile );
       
   857 
       
   858         // Use given MIME type if present
       
   859         TDataType dataType;
       
   860         const TDesC* mimeType16 = &aAttachmentPart.GetContentType();
       
   861         if ( mimeType16->Length() )
       
   862             {
       
   863             // V-calendar attachments sent from MS Outlook seem to have wrong MIME type. Work around
       
   864             // this by overriding the MIME type in case the file can be identified to be VCal object
       
   865             if ( GetFileType( attName, *mimeType16 ) == EVCalType )
       
   866                 {
       
   867                 mimeType16 = &KVCalMimeString;
       
   868                 }
       
   869 
       
   870             // The MIME type must be converted to 8 bit buffer. Just assume it's ASCII data
       
   871             // and forget the upper bytes.
       
   872             HBufC8* mimeType8 = HBufC8::NewLC( mimeType16->Length() );
       
   873             mimeType8->Des().Append( *mimeType16 );
       
   874             //cut extra data from MIME string
       
   875             TInt pos = mimeType8->Locate( ';' );
       
   876             if ( pos >= 0 )
       
   877                 {
       
   878                 mimeType8->Des().SetLength(pos);
       
   879                 }
       
   880             dataType = TDataType( *mimeType8 );
       
   881             CleanupStack::PopAndDestroy( mimeType8 );
       
   882             }
       
   883 
       
   884         CleanupStack::Pop( &attachmentFile ); // next function takes ownershp of the handle
       
   885         OpenFileL( attachmentFile, dataType, aAllowSave );
       
   886         }
       
   887     }
       
   888 
       
   889 // -----------------------------------------------------------------------------
       
   890 // TFsEmailUiUtility::SetMessageFollowupFlagL
       
   891 // -----------------------------------------------------------------------------
       
   892 TFollowUpNewState TFsEmailUiUtility::SetMessageFollowupFlagL( CFSMailMessage& aMsg,
       
   893         TBool aShowFlagCompleted )
       
   894     {
       
   895     FUNC_LOG;
       
   896     TFollowUpNewState newFollowUpState = EFollowUpNoChanges;
       
   897     if ( TFsEmailUiUtility::RunFollowUpListDialogL( newFollowUpState, aShowFlagCompleted ) )
       
   898         {
       
   899         SetMessageFollowupStateL( aMsg, newFollowUpState );
       
   900         }
       
   901     return newFollowUpState;
       
   902     }
       
   903 
       
   904 // -----------------------------------------------------------------------------
       
   905 // TFsEmailUiUtility::SetssageFollowupStateL
       
   906 // -----------------------------------------------------------------------------
       
   907 void TFsEmailUiUtility::SetMessageFollowupStateL( CFSMailMessage& aMsg,
       
   908         TFollowUpNewState aNewFollowUpState )
       
   909     {
       
   910     FUNC_LOG;
       
   911     switch ( aNewFollowUpState )
       
   912         {
       
   913         case EFollowUp:
       
   914             {
       
   915             aMsg.SetFlag( EFSMsgFlag_FollowUp );
       
   916             aMsg.ResetFlag( EFSMsgFlag_FollowUpComplete );
       
   917             }
       
   918             break;
       
   919         case EFollowUpComplete:
       
   920             {
       
   921             aMsg.SetFlag( EFSMsgFlag_FollowUpComplete );
       
   922             aMsg.ResetFlag( EFSMsgFlag_FollowUp );
       
   923             }
       
   924             break;
       
   925         case EFollowUpClear:
       
   926             {
       
   927             aMsg.ResetFlag( EFSMsgFlag_FollowUp | EFSMsgFlag_FollowUpComplete );
       
   928             }
       
   929             break;
       
   930         }
       
   931     aMsg.SaveMessageL(); // Save flag status
       
   932     }
       
   933 
       
   934 // -----------------------------------------------------------------------------
       
   935 // TFsEmailUiUtility::RunFollowUpListDialogL
       
   936 // -----------------------------------------------------------------------------
       
   937 TBool TFsEmailUiUtility::RunFollowUpListDialogL( TFollowUpNewState& aSelectedOption,
       
   938         TBool aShowFlagCompleted )
       
   939 	{
       
   940     FUNC_LOG;
       
   941 	aSelectedOption = EFollowUpNoChanges;
       
   942 
       
   943 	CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat( 2 );
       
   944 	CleanupStack::PushL( array );
       
   945 
       
   946 	// Add follow up text
       
   947 	_LIT( KListItemIcon0, "0\t" );
       
   948 
       
   949     // aShowFlagCompleted is false when we are in the editor/composer view
       
   950     TInt followUpResId =
       
   951         ( aShowFlagCompleted ? R_FREESTYLE_EMAIL_UI_FLAG_FOLLOW_UP :
       
   952                                 R_NCS_FLAG_FOLLOW_UP );
       
   953 
       
   954     HBufC* followUp = StringLoader::LoadLC( followUpResId );
       
   955 
       
   956 	HBufC* followUpText = HBufC::NewLC( KListItemIcon0().Length() + followUp->Length() );
       
   957     followUpText->Des().Append( KListItemIcon0 );
       
   958     followUpText->Des().Append( *followUp );
       
   959     array->AppendL( *followUpText );
       
   960 	CleanupStack::PopAndDestroy( 2, followUp );
       
   961 
       
   962 	// Add flag complete text if requested
       
   963 	if ( aShowFlagCompleted )
       
   964 	    {
       
   965 	    _LIT( KListItemIcon1, "1\t" );
       
   966     	HBufC* completeFlag = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FLAG_COMPLETE );
       
   967     	HBufC* completeFlagText = HBufC::NewLC( KListItemIcon1().Length() + completeFlag->Length() );
       
   968     	completeFlagText->Des().Append( KListItemIcon1 );
       
   969         completeFlagText->Des().Append( *completeFlag );
       
   970         array->AppendL( *completeFlagText );
       
   971     	CleanupStack::PopAndDestroy( 2, completeFlag );
       
   972         }
       
   973 
       
   974 	// Add clear flag text
       
   975 	_LIT( KListItemNoIcon, "\t" );
       
   976 
       
   977     // aShowFlagCompleted is false when we are in the editor/composer view
       
   978     TInt clearResId = ( aShowFlagCompleted ? R_FREESTYLE_EMAIL_UI_FLAG_CLEAR :
       
   979                                              R_NCS_FLAG_CLEAR );
       
   980 
       
   981 	HBufC* clearFlag = StringLoader::LoadLC( clearResId );
       
   982 	HBufC* clearFlagText = HBufC::NewLC( KListItemNoIcon().Length() + clearFlag->Length() );
       
   983 	clearFlagText->Des().Append( KListItemNoIcon );
       
   984 	clearFlagText->Des().Append( *clearFlag );
       
   985 	array->AppendL( *clearFlagText );
       
   986 	CleanupStack::PopAndDestroy( 2, clearFlag );
       
   987 
       
   988 	TInt selectedOption;
       
   989 	CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &selectedOption );
       
   990 
       
   991     // aShowFlagCompleted is false when we are in the editor/composer view
       
   992 	TInt dlgResId = ( aShowFlagCompleted ? R_MAIL_FLAG_QUERY_DIALOG :
       
   993 	                                       R_NCS_MAIL_FLAG_QUERY_DIALOG );
       
   994 
       
   995 	dlg->PrepareLC( dlgResId );
       
   996 
       
   997 	//Create icon array from correct icons
       
   998     TFileName iconFileName;
       
   999     GetFullIconFileNameL( iconFileName );
       
  1000 
       
  1001     CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray( 2 );
       
  1002 	CleanupStack::PushL(icons);
       
  1003     CFbsBitmap* iconBitmap;
       
  1004     CFbsBitmap* iconMaskBitmap;
       
  1005     TSize defaultIconSize(20,20);
       
  1006 
       
  1007 // <cmail> icons changed
       
  1008     // Flag icon "followup"
       
  1009     AknsUtils::CreateColorIconLC(
       
  1010         AknsUtils::SkinInstance(),
       
  1011         KAknsIIDNone,
       
  1012         KAknsIIDQsnIconColors,
       
  1013         EAknsCIQsnIconColorsCG7,
       
  1014         iconBitmap,
       
  1015         iconMaskBitmap,
       
  1016         iconFileName,
       
  1017         EMbmFreestyleemailuiQgn_indi_cmail_viewer_follow_up,
       
  1018         EMbmFreestyleemailuiQgn_indi_cmail_viewer_follow_up_mask,
       
  1019         KRgbBlack );
       
  1020 	AknIconUtils::SetSize(iconBitmap, defaultIconSize );
       
  1021     AknIconUtils::SetSize(iconMaskBitmap, defaultIconSize);
       
  1022     CGulIcon* flagIcon = CGulIcon::NewL(iconBitmap, iconMaskBitmap);
       
  1023     CleanupStack::Pop( 2, iconBitmap );
       
  1024     CleanupStack::PushL( flagIcon );
       
  1025  	icons->AppendL( flagIcon );
       
  1026  	CleanupStack::Pop( flagIcon );
       
  1027 
       
  1028     // Flag icon "completed"
       
  1029  	AknsUtils::CreateColorIconLC(
       
  1030         AknsUtils::SkinInstance(),
       
  1031         KAknsIIDNone,
       
  1032         KAknsIIDQsnIconColors,
       
  1033         EAknsCIQsnIconColorsCG7,
       
  1034         iconBitmap,
       
  1035         iconMaskBitmap,
       
  1036         iconFileName,
       
  1037         EMbmFreestyleemailuiQgn_indi_cmail_viewer_follow_up_complete,
       
  1038         EMbmFreestyleemailuiQgn_indi_cmail_viewer_follow_up_complete_mask,
       
  1039         KRgbBlack );
       
  1040 	AknIconUtils::SetSize(iconBitmap, defaultIconSize );
       
  1041     AknIconUtils::SetSize(iconMaskBitmap, defaultIconSize);
       
  1042     CGulIcon* flagCompleteIcon = CGulIcon::NewL(iconBitmap, iconMaskBitmap);
       
  1043     CleanupStack::Pop( 2, iconBitmap );
       
  1044     CleanupStack::PushL( flagCompleteIcon );
       
  1045 	icons->AppendL( flagCompleteIcon );
       
  1046     CleanupStack::Pop( flagCompleteIcon );
       
  1047 // </cmail>
       
  1048 
       
  1049     // Run the dialog
       
  1050     dlg->SetItemTextArray( array );
       
  1051 	dlg->SetIconArrayL( icons );
       
  1052 	CleanupStack::Pop( icons );
       
  1053 	dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
  1054 	TBool retVal = dlg->RunLD();
       
  1055 	CleanupStack::PopAndDestroy( array );
       
  1056 
       
  1057 	if ( retVal )
       
  1058 	    {
       
  1059     	// Convert the returned index to enumeration. This mapping is different depending
       
  1060     	// if "flag completed" is shown or not
       
  1061         aSelectedOption = static_cast<TFollowUpNewState>( selectedOption );
       
  1062     	if ( !aShowFlagCompleted && aSelectedOption == EFollowUpComplete )
       
  1063     	    {
       
  1064     	    aSelectedOption = EFollowUpClear;
       
  1065     	    }
       
  1066 	    }
       
  1067 
       
  1068 	return retVal;
       
  1069 	}
       
  1070 
       
  1071 
       
  1072 // -----------------------------------------------------------------------------
       
  1073 // TFsEmailUiUtility::ShowCreateMessageQueryL
       
  1074 // -----------------------------------------------------------------------------
       
  1075 void TFsEmailUiUtility::ShowCreateMessageQueryL( const TDesC& aAddressData, TBool aSendingToEmail )
       
  1076 	{
       
  1077     FUNC_LOG;
       
  1078 	if ( aAddressData.Length() ) // Sending needs address data in any case
       
  1079 		{
       
  1080 		CSendUi* sendUi = CSendUi::NewLC();
       
  1081 		TSendingCapabilities noCapabilities(0,0,0);
       
  1082 
       
  1083 		CArrayFix<TUid>* showedServicesUidArray = new( ELeave ) CArrayFixFlat<TUid>(4);
       
  1084 		CleanupStack::PushL( showedServicesUidArray );
       
  1085 
       
  1086 		CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( 2 );
       
  1087 		CleanupStack::PushL( array );
       
  1088 
       
  1089 		if( !aSendingToEmail && sendUi->ValidateServiceL( KSenduiMtmSmsUid, noCapabilities ) )
       
  1090 			{
       
  1091 			HBufC* textMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_TEXT_MESSAGE );
       
  1092 		    array->AppendL( *textMessage );
       
  1093 			CleanupStack::PopAndDestroy( textMessage );
       
  1094 			showedServicesUidArray->AppendL( KSenduiMtmSmsUid );
       
  1095 			}
       
  1096 		if( sendUi->ValidateServiceL( KSenduiMtmMmsUid, noCapabilities ) )
       
  1097 			{
       
  1098 			HBufC* multimediaMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_MULTIMEDIA_MESSAGE );
       
  1099 		    array->AppendL( *multimediaMessage );
       
  1100 			CleanupStack::PopAndDestroy( multimediaMessage );
       
  1101 			showedServicesUidArray->AppendL( KSenduiMtmMmsUid );
       
  1102 			}
       
  1103 		if( sendUi->ValidateServiceL( KSenduiMtmAudioMessageUid, noCapabilities ) )
       
  1104 			{
       
  1105 			HBufC* voiceMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_VOICE_MESSAGE );
       
  1106 		    array->AppendL( *voiceMessage );
       
  1107 			CleanupStack::PopAndDestroy( voiceMessage );
       
  1108 			showedServicesUidArray->AppendL( KSenduiMtmAudioMessageUid );
       
  1109 			}
       
  1110 
       
  1111 		TInt selectedOption;
       
  1112 		CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &selectedOption );
       
  1113 		dlg->PrepareLC( R_MAIL_VIEWER_CREATE_MESSAGE_DIALOG  );
       
  1114 		dlg->SetItemTextArray( array );
       
  1115 		dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
  1116 		if( dlg->RunLD() )
       
  1117 			{
       
  1118 			CMessageData* messageData = CMessageData::NewLC();
       
  1119 			messageData->AppendToAddressL( aAddressData );
       
  1120 			// safety check.
       
  1121 			if( showedServicesUidArray->Count() > selectedOption )
       
  1122 				{
       
  1123 				sendUi->CreateAndSendMessageL( showedServicesUidArray->At( selectedOption ),
       
  1124 												messageData );
       
  1125 				}
       
  1126 			CleanupStack::PopAndDestroy( messageData );
       
  1127 			}
       
  1128 
       
  1129 		CleanupStack::PopAndDestroy( array );
       
  1130 		CleanupStack::PopAndDestroy( showedServicesUidArray );
       
  1131 		CleanupStack::PopAndDestroy( sendUi );
       
  1132 		}
       
  1133 	}
       
  1134 
       
  1135 // -----------------------------------------------------------------------------
       
  1136 // TFsEmailUiUtility::GetFileType
       
  1137 // Figures out the file type based on the MIME type and the file name extension.
       
  1138 // The MIME type is used first and if that doesn't help, then the file extension
       
  1139 // is used as backup solution.
       
  1140 // -----------------------------------------------------------------------------
       
  1141 TFileType TFsEmailUiUtility::GetFileType( const TDesC& aFileName, const TDesC& aMimeType )
       
  1142     {
       
  1143     FUNC_LOG;
       
  1144 	TFileType fileType = EUnidentifiedType;
       
  1145     TPtrC ext = TParsePtrC( aFileName ).Ext();
       
  1146 
       
  1147     // here we make sure that content type does not have extra parameters
       
  1148     TPtrC mimeType( aMimeType );
       
  1149     TInt semiColonPos( aMimeType.Locate(';') );
       
  1150     if( semiColonPos != KErrNotFound )
       
  1151     	{
       
  1152     	mimeType.Set( aMimeType.Left(semiColonPos) );
       
  1153     	}
       
  1154     
       
  1155 	if ( !mimeType.CompareF(KPdfMimeString) )
       
  1156 		{
       
  1157 		fileType = EPdfType;
       
  1158 		}
       
  1159 	else if ( !mimeType.CompareF(KDocMimeString) ||
       
  1160 	          !mimeType.CompareF(KDocMimeString2) )
       
  1161 		{
       
  1162 		fileType = EDocType;
       
  1163 		}
       
  1164 	else if ( !mimeType.CompareF(KRtfMimeString) )
       
  1165 		{
       
  1166 		fileType = ERtfType;
       
  1167 		}
       
  1168 	else if ( !mimeType.CompareF(KPptMimeString) )
       
  1169 		{
       
  1170 		fileType = EPptType;
       
  1171 		}
       
  1172 	else if ( !mimeType.CompareF(KXlsMimeString) )
       
  1173 		{
       
  1174 		fileType = EXlsType;
       
  1175 		}
       
  1176 	else if ( !mimeType.Left( KImageMimeString().Length() ).CompareF(KImageMimeString) )
       
  1177 		{
       
  1178 		fileType = EImageType;
       
  1179 		}
       
  1180 	else if ( !mimeType.CompareF(KHtmlMimeString) )
       
  1181 		{
       
  1182 		fileType = EHtmlType;
       
  1183 		}
       
  1184 	else if ( !mimeType.CompareF(KPlainTextMimeString) )
       
  1185 	    {
       
  1186 	    fileType = EPlainTextType;
       
  1187 	    // When v-cal attachment is sent from MS Outlook, it's received with wrong MIME type.
       
  1188 	    // Following is a workaround for this problem
       
  1189 	    if ( !ext.CompareF(KVCalFileExtension) )
       
  1190 	        {
       
  1191 	        fileType = EVCalType;
       
  1192 	        }
       
  1193 	    }
       
  1194 	else if ( !mimeType.CompareF(KVCalMimeString) )
       
  1195 	    {
       
  1196 	    fileType = EVCalType;
       
  1197 	    }
       
  1198     else if ( !mimeType.CompareF(KMessageMimeString) )
       
  1199         {
       
  1200         fileType = EMessageType;
       
  1201         }
       
  1202 	else
       
  1203 		{
       
  1204 		// File type couldn't be identified from the MIME type. Use the file extension.
       
  1205 
       
  1206     	if ( !ext.CompareF(KDocFileExtension) )
       
  1207     		{
       
  1208     		fileType = EDocType;
       
  1209     		}
       
  1210     	else if ( !ext.CompareF(KRtfFileExtension) )
       
  1211     	    {
       
  1212     	    fileType = ERtfType;
       
  1213     	    }
       
  1214     	else if ( !ext.CompareF(KPptFileExtension) )
       
  1215     		{
       
  1216     		fileType = EPptType;
       
  1217     		}
       
  1218     	else if ( !ext.CompareF(KXlsFileExtension) )
       
  1219     		{
       
  1220     		fileType = EXlsType;
       
  1221     		}
       
  1222     	else if ( !ext.CompareF(KPdfFileExtension) )
       
  1223     		{
       
  1224     		fileType = EPdfType;
       
  1225     		}
       
  1226     	else if ( !ext.CompareF(KHtmlFileExtension) ||
       
  1227     	          !ext.CompareF(KHtmFileExtension) )
       
  1228     	    {
       
  1229     	    fileType = EHtmlType;
       
  1230     	    }
       
  1231     	else if ( !ext.CompareF(KJpgFileExtension)
       
  1232     			  || !ext.CompareF(KJpgeFileExtension)
       
  1233     			  || !ext.CompareF(KJpegFileExtension)
       
  1234     			  || !ext.CompareF(KPngFileExtension)
       
  1235     			  || !ext.CompareF(KGifFileExtension)
       
  1236     			  || !ext.CompareF(KBmpFileExtension) )
       
  1237     	    {
       
  1238     	    fileType = EImageType;
       
  1239     	    }
       
  1240     	else if ( !ext.CompareF(KTxtFileExtension) )
       
  1241     	    {
       
  1242     	    fileType = EPlainTextType;
       
  1243     	    }
       
  1244     	else if ( !ext.CompareF(KVCalFileExtension) )
       
  1245             {
       
  1246             fileType = EVCalType;
       
  1247             }
       
  1248         else if ( !ext.CompareF(KEmailFileExtension) )
       
  1249             {
       
  1250             fileType = EMessageType;
       
  1251             }
       
  1252     	else
       
  1253     	    {
       
  1254     	    fileType = EUnidentifiedType;
       
  1255     	    }
       
  1256 		}
       
  1257 
       
  1258     return fileType;
       
  1259     }
       
  1260 
       
  1261 // -----------------------------------------------------------------------------
       
  1262 // TFsEmailUiUtility::GetAttachmentIcon
       
  1263 // Funtion for getting correct attachment icon
       
  1264 // -----------------------------------------------------------------------------
       
  1265 CAlfTexture& TFsEmailUiUtility::GetAttachmentIcon( TFileType aAttachmentType, CFreestyleEmailUiTextureManager& aTextureManager )
       
  1266     {
       
  1267     FUNC_LOG;
       
  1268 	TFSEmailUiTextures textureId = GetAttachmentIconTextureId( aAttachmentType );
       
  1269 	return aTextureManager.TextureByIndex( textureId );
       
  1270     }
       
  1271 
       
  1272 TFSEmailUiTextures TFsEmailUiUtility::GetAttachmentIconTextureId( TFileType aAttachmentType )
       
  1273     {
       
  1274     FUNC_LOG;
       
  1275     switch( aAttachmentType )
       
  1276     	{
       
  1277 		case EDocType:
       
  1278      		return EAttachmentsDocFile;
       
  1279 		case ERtfType:
       
  1280 			return EAttachmentsRtfFile;
       
  1281         case EPptType:
       
  1282 			return EAttachmentsPptFile;
       
  1283 		case EXlsType:
       
  1284 			return EAttachmentsXls;
       
  1285 		case EPdfType:
       
  1286 			return EAttachmentsPdfFile;
       
  1287 		case EImageType:
       
  1288 			return EAttachmentsImageFile;
       
  1289 		case EHtmlType:
       
  1290 			return EAttachmentsHtmlFile;
       
  1291 		case EPlainTextType:
       
  1292 		case EVCalType:
       
  1293 		case EMessageType:
       
  1294 		case EUnidentifiedType:
       
  1295 			return EAttachmentsUnknownFile;
       
  1296 		default:
       
  1297 			ASSERT( EFalse );
       
  1298     	}
       
  1299     return EAttachmentsUnknownFile;
       
  1300     }
       
  1301 
       
  1302 // -----------------------------------------------------------------------------
       
  1303 // TFsEmailUiUtility::GetMsgIcon
       
  1304 // Funtion for getting correct msg icon, divides into read and unread icons
       
  1305 // -----------------------------------------------------------------------------
       
  1306 CAlfTexture& TFsEmailUiUtility::GetMsgIcon( CFSMailMessage* aMsgPtr,
       
  1307 									 CFreestyleEmailUiTextureManager& aTextureManager )
       
  1308 	{
       
  1309     FUNC_LOG;
       
  1310 	TFSEmailUiTextures textureId = GetMsgIconTextureId( aMsgPtr );
       
  1311 	return aTextureManager.TextureByIndex( textureId );
       
  1312 	}
       
  1313 
       
  1314 TFSEmailUiTextures TFsEmailUiUtility::GetMsgIconTextureId( CFSMailMessage* aMsgPtr )
       
  1315 	{
       
  1316     FUNC_LOG;
       
  1317 	if ( !aMsgPtr->IsFlagSet( EFSMsgFlag_Read ) )
       
  1318 		{
       
  1319 		return GetUnreadMsgIcon( aMsgPtr );
       
  1320 		}
       
  1321 	else
       
  1322 		{
       
  1323 		return GetReadMsgIcon( aMsgPtr );
       
  1324 		}
       
  1325 
       
  1326 	}
       
  1327 
       
  1328 // -----------------------------------------------------------------------------
       
  1329 // TFsEmailUiUtility::MoveMessageToDraftsL
       
  1330 // -----------------------------------------------------------------------------
       
  1331 void TFsEmailUiUtility::MoveMessageToDraftsL( CFSMailBox& aMailBox, CFSMailMessage& aMsg )
       
  1332 	{
       
  1333     FUNC_LOG;
       
  1334 
       
  1335 	// check that msg is not in drafts folder already
       
  1336 	TFSMailMsgId draftsFolderId = aMailBox.GetStandardFolderId( EFSDraftsFolder );
       
  1337 	TFSMailMsgId msgFolderId = aMsg.GetFolderId();
       
  1338 	if ( draftsFolderId != msgFolderId )
       
  1339 		{
       
  1340 		RArray<TFSMailMsgId> ids;
       
  1341 		ids.Append( aMsg.GetMessageId() );
       
  1342 		aMailBox.MoveMessagesL( ids, msgFolderId, draftsFolderId );
       
  1343 		ids.Reset();
       
  1344 		}
       
  1345 
       
  1346 	}
       
  1347 
       
  1348 // -----------------------------------------------------------------------------
       
  1349 // TFsEmailUiUtility::IsMessagePartFullyFetched
       
  1350 // -----------------------------------------------------------------------------
       
  1351 TBool TFsEmailUiUtility::IsMessagePartFullyFetched( const CFSMailMessagePart& aPart )
       
  1352 	{
       
  1353     FUNC_LOG;
       
  1354 
       
  1355 	TFSPartFetchState fetchState = aPart.FetchLoadState();
       
  1356 	TBool isFetched = ( fetchState == EFSFull );
       
  1357 
       
  1358 	return isFetched;
       
  1359 	}
       
  1360 
       
  1361 // -----------------------------------------------------------------------------
       
  1362 // TFsEmailUiUtility::IsMessageStructureKnown
       
  1363 // -----------------------------------------------------------------------------
       
  1364 TBool TFsEmailUiUtility::IsMessageStructureKnown( const CFSMailMessagePart& aPart )
       
  1365 	{
       
  1366     FUNC_LOG;
       
  1367 
       
  1368 	TFSPartFetchState fetchState = aPart.FetchLoadState();
       
  1369 	TBool isKnown = !( fetchState == EFSEmailStructureUnknown );//( fetchState == EFSFull || fetchState == EFSMessagePartsKnown );
       
  1370 
       
  1371 	return isKnown;
       
  1372 	}
       
  1373 
       
  1374 // -----------------------------------------------------------------------------
       
  1375 // TFsEmailUiUtility::CreatePlainTextPartL
       
  1376 // -----------------------------------------------------------------------------
       
  1377 void TFsEmailUiUtility::CreatePlainTextPartL( CFSMailMessage& aMsg, CFSMailMessagePart*& aPart )
       
  1378 	{
       
  1379     FUNC_LOG;
       
  1380 
       
  1381     aPart = aMsg.PlainTextBodyPartL();
       
  1382     if ( !aPart )
       
  1383     	{
       
  1384         // Do message contain HTML body part
       
  1385         CFSMailMessagePart* htmlPart = aMsg.HtmlBodyPartL();
       
  1386         if ( htmlPart )
       
  1387             {
       
  1388             CleanupStack::PushL( htmlPart );
       
  1389             HBufC* htmlData = HBufC::NewLC( htmlPart->FetchedContentSize() );
       
  1390             TPtr pointer = htmlData->Des();
       
  1391             htmlPart->GetContentToBufferL( pointer, 0 );
       
  1392 
       
  1393             HBufC* txtData = TFsEmailUiUtility::ConvertHtmlToTxtL( *htmlData );
       
  1394 
       
  1395             CleanupStack::PopAndDestroy( htmlData );
       
  1396 
       
  1397             CleanupStack::PushL( txtData );
       
  1398 
       
  1399             // create new message part for body text
       
  1400             TFSMailMsgId id;
       
  1401             aPart = aMsg.NewChildPartL( id, KFSMailContentTypeTextPlain );
       
  1402             if ( aPart )
       
  1403                 {
       
  1404                 aPart->SetContentType( KFSMailContentTypeTextPlain );
       
  1405                 pointer.Set( txtData->Des() );
       
  1406                 aPart->SetContent( pointer );
       
  1407                 aPart->SaveL();
       
  1408                 }
       
  1409 
       
  1410             CleanupStack::PopAndDestroy( txtData );
       
  1411             CleanupStack::PopAndDestroy( htmlPart );
       
  1412             }
       
  1413         else
       
  1414             {
       
  1415     		// create new message part for body text
       
  1416     		TFSMailMsgId id;
       
  1417     		aPart = aMsg.NewChildPartL( id, KFSMailContentTypeTextPlain );
       
  1418             if ( aPart )
       
  1419                 {
       
  1420                 aPart->SetContentType( KFSMailContentTypeTextPlain );
       
  1421                 aPart->SaveL();
       
  1422                 }
       
  1423             }
       
  1424     	}
       
  1425 
       
  1426 	}
       
  1427 
       
  1428 // -----------------------------------------------------------------------------
       
  1429 // TFsEmailUiUtility::IsCompleteOrCancelEvent
       
  1430 // -----------------------------------------------------------------------------
       
  1431 TBool TFsEmailUiUtility::IsCompleteOrCancelEvent( TFSProgress aEvent )
       
  1432 	{
       
  1433     FUNC_LOG;
       
  1434     return ( TFSProgress::EFSStatus_RequestComplete == aEvent.iProgressStatus ||
       
  1435     	TFSProgress::EFSStatus_RequestCancelled == aEvent.iProgressStatus );
       
  1436     }
       
  1437 
       
  1438 // -----------------------------------------------------------------------------
       
  1439 // TFsEmailUiUtility::HasUnfetchedAttachmentsL
       
  1440 // -----------------------------------------------------------------------------
       
  1441 TBool TFsEmailUiUtility::HasUnfetchedAttachmentsL( CFSMailMessage& aMsg )
       
  1442 	{
       
  1443     FUNC_LOG;
       
  1444 	RPointerArray<CFSMailMessagePart> attachments;
       
  1445 	aMsg.AttachmentListL( attachments );
       
  1446 	TBool found = EFalse;
       
  1447 	for ( TInt i=0; i<attachments.Count(); i++ )
       
  1448 		{
       
  1449 		if ( !IsMessagePartFullyFetched( *attachments[i] ) )
       
  1450 			{
       
  1451 			found = ETrue;
       
  1452 			break;
       
  1453 			}
       
  1454 		}
       
  1455 	attachments.ResetAndDestroy();
       
  1456 	return found;
       
  1457 	}
       
  1458 
       
  1459 // -----------------------------------------------------------------------------
       
  1460 // TFsEmailUiUtility::IsFollowUpSupported
       
  1461 // -----------------------------------------------------------------------------
       
  1462 TBool TFsEmailUiUtility::IsFollowUpSupported( const CFSMailBox& aMailBox )
       
  1463 	{
       
  1464     FUNC_LOG;
       
  1465 	TBool supported = aMailBox.HasCapability( EFSMBoxCapaSupportsFollowUp );
       
  1466 	return supported;
       
  1467 	}
       
  1468 
       
  1469 // -----------------------------------------------------------------------------
       
  1470 // TFsEmailUiUtility::DateTextFromMsgLC
       
  1471 // -----------------------------------------------------------------------------
       
  1472 HBufC* TFsEmailUiUtility::DateTextFromMsgLC( const CFSMailMessage* aMessage,
       
  1473 	TBool aAddYearNumer )
       
  1474 	{
       
  1475     FUNC_LOG;
       
  1476 	HBufC* ret = HBufC::NewLC( 20 );
       
  1477 	TTime eventTimeInHomeTime = aMessage->GetDate();
       
  1478     TLocale currentLocaleSettings;
       
  1479     eventTimeInHomeTime = eventTimeInHomeTime +
       
  1480     					  (currentLocaleSettings.UniversalTimeOffset());
       
  1481     eventTimeInHomeTime += currentLocaleSettings.QueryHomeHasDaylightSavingOn()
       
  1482     					  ? TTimeIntervalHours(1) : TTimeIntervalHours(0);
       
  1483 	TDateFormat dateFormat = currentLocaleSettings.DateFormat();
       
  1484 	TChar secondDateSeparator = currentLocaleSettings.DateSeparator( 1 );
       
  1485 	TChar thirdDateSeparator = currentLocaleSettings.DateSeparator( 2 );
       
  1486 
       
  1487 	if ( aAddYearNumer )
       
  1488 		{
       
  1489 		switch ( dateFormat )
       
  1490 			{
       
  1491 			case EDateAmerican: // US format (mm/dd/yyyy)
       
  1492 				{
       
  1493 				ret->Des().Format(_L("%02d%c%02d%c%4d"),
       
  1494 			 		eventTimeInHomeTime.DateTime().Month()+1,
       
  1495 			 		(TUint)secondDateSeparator,
       
  1496 			 		eventTimeInHomeTime.DateTime().Day()+1,
       
  1497 			 		(TUint)thirdDateSeparator,
       
  1498 			 		eventTimeInHomeTime.DateTime().Year());
       
  1499 				}
       
  1500 				break;
       
  1501 			case EDateJapanese: // Japanese format (yyyy/mm/dd)
       
  1502 				{
       
  1503 				ret->Des().Format( _L("%4d%c%02d%c%02d"),
       
  1504 			 		eventTimeInHomeTime.DateTime().Year(),
       
  1505 			 		(TUint)secondDateSeparator,
       
  1506 			 		eventTimeInHomeTime.DateTime().Month()+1,
       
  1507 			 		(TUint)thirdDateSeparator,
       
  1508 			 		eventTimeInHomeTime.DateTime().Day()+1 );
       
  1509 				}
       
  1510 				break;
       
  1511 			case EDateEuropean: // European format (dd/mm/yyyy)
       
  1512 			default:
       
  1513 				{
       
  1514 				ret->Des().Format(_L("%02d%c%02d%c%4d"),
       
  1515 			 		eventTimeInHomeTime.DateTime().Day()+1,
       
  1516 			 		(TUint)secondDateSeparator,
       
  1517 			 		eventTimeInHomeTime.DateTime().Month()+1,
       
  1518 			 		(TUint)thirdDateSeparator,
       
  1519 			 		eventTimeInHomeTime.DateTime().Year());
       
  1520 				}
       
  1521 				break;
       
  1522 			}
       
  1523 		}
       
  1524 	else
       
  1525 		{
       
  1526 		switch ( dateFormat )
       
  1527 			{
       
  1528 			case EDateAmerican: // US format (mm/dd/yyyy)
       
  1529 				{
       
  1530 				ret->Des().Format(_L("%02d%c%02d"),
       
  1531 			 		eventTimeInHomeTime.DateTime().Month()+1,
       
  1532 			 		(TUint)secondDateSeparator,
       
  1533 			 		eventTimeInHomeTime.DateTime().Day()+1 );
       
  1534 				}
       
  1535 				break;
       
  1536 			case EDateJapanese: // Japanese format (yyyy/mm/dd)
       
  1537 				{
       
  1538 				ret->Des().Format( _L("%02d%c%02d"),
       
  1539 			 		eventTimeInHomeTime.DateTime().Month()+1,
       
  1540 			 		(TUint)thirdDateSeparator,
       
  1541 			 		eventTimeInHomeTime.DateTime().Day()+1 );
       
  1542 				}
       
  1543 				break;
       
  1544 			case EDateEuropean: // European format (dd/mm/yyyy)
       
  1545 			default:
       
  1546 				{
       
  1547 				ret->Des().Format(_L("%02d%c%02d"),
       
  1548 			 		eventTimeInHomeTime.DateTime().Day()+1,
       
  1549 			 		(TUint)secondDateSeparator,
       
  1550 			 		eventTimeInHomeTime.DateTime().Month()+1 );
       
  1551 				}
       
  1552 				break;
       
  1553 			}
       
  1554 		}
       
  1555    	TPtr dataPtr( ret->Des() );
       
  1556    	AknTextUtils::LanguageSpecificNumberConversion( dataPtr );
       
  1557 	return ret;
       
  1558 	}
       
  1559 
       
  1560 // -----------------------------------------------------------------------------
       
  1561 // TFsEmailUiUtility::TimeTextFromMsgLC
       
  1562 // -----------------------------------------------------------------------------
       
  1563 HBufC* TFsEmailUiUtility::TimeTextFromMsgLC( const CFSMailMessage* aMessage )
       
  1564 	{
       
  1565     FUNC_LOG;
       
  1566     TBuf<20> timeStr;
       
  1567     TBuf<20> timeStrFormat;
       
  1568 	TTime eventTimeInHomeTime = aMessage->GetDate();
       
  1569     TLocale currentLocaleSettings;
       
  1570     eventTimeInHomeTime = eventTimeInHomeTime +
       
  1571     					  (currentLocaleSettings.UniversalTimeOffset());
       
  1572     eventTimeInHomeTime += currentLocaleSettings.QueryHomeHasDaylightSavingOn()
       
  1573     					  ? TTimeIntervalHours(1) : TTimeIntervalHours(0);
       
  1574     if( currentLocaleSettings.AmPmSymbolPosition() == ELocaleBefore )
       
  1575         {
       
  1576         timeStrFormat.Append( KTimeFormatBefore );
       
  1577         timeStrFormat.Append( KTimeFormatSpace );
       
  1578         timeStrFormat.Append( KTimeFormatHour );
       
  1579         timeStrFormat.Append( currentLocaleSettings.TimeSeparator( KSecondSeparator ) );
       
  1580         timeStrFormat.Append( KTimeFormatMinutes );
       
  1581         eventTimeInHomeTime.FormatL( timeStr, timeStrFormat );
       
  1582         }
       
  1583     else
       
  1584         {
       
  1585         timeStrFormat.Append( KTimeFormatHour );
       
  1586         timeStrFormat.Append( currentLocaleSettings.TimeSeparator( KSecondSeparator ) );
       
  1587         timeStrFormat.Append( KTimeFormatMinutes );
       
  1588         timeStrFormat.Append( KTimeFormatSpace );
       
  1589         timeStrFormat.Append( KTimeFormatAfter );
       
  1590         eventTimeInHomeTime.FormatL( timeStr, timeStrFormat );
       
  1591         }
       
  1592     HBufC* dataStr = HBufC::NewL( 1 + timeStr.Length() );
       
  1593     TPtr dataPtr( dataStr->Des() );
       
  1594     dataPtr.Append( timeStr );
       
  1595     CleanupStack::PushL( dataStr );
       
  1596     AknTextUtils::LanguageSpecificNumberConversion( dataPtr );
       
  1597     return dataStr;
       
  1598 	}
       
  1599 
       
  1600 
       
  1601 // -----------------------------------------------------------------------------
       
  1602 // TFsEmailUiUtility::ListMsgTimeTextFromMsgLC
       
  1603 // -----------------------------------------------------------------------------
       
  1604 HBufC* TFsEmailUiUtility::ListMsgTimeTextFromMsgLC( const CFSMailMessage* aMessage, TBool aDividersInUse )
       
  1605 	{
       
  1606     FUNC_LOG;
       
  1607 	// If dividers are in use, returjn normal time text
       
  1608     if ( aDividersInUse )
       
  1609     	{
       
  1610     	return TimeTextFromMsgLC( aMessage );
       
  1611     	}
       
  1612 
       
  1613 	// If dividers are not in use, today's emails need to use time, others need to use date.
       
  1614  	TTime eventTimeInHomeTime = aMessage->GetDate();
       
  1615 	TTime currentTime;
       
  1616 	currentTime.HomeTime();
       
  1617  	TLocale currentLocaleSettings;
       
  1618     eventTimeInHomeTime = eventTimeInHomeTime +
       
  1619     					  (currentLocaleSettings.UniversalTimeOffset());
       
  1620     eventTimeInHomeTime += currentLocaleSettings.QueryHomeHasDaylightSavingOn()
       
  1621     					  ? TTimeIntervalHours(1) : TTimeIntervalHours(0);
       
  1622  	if ( currentTime.DayNoInYear() == eventTimeInHomeTime.DayNoInYear() &&
       
  1623  		 currentTime.DateTime().Year() == eventTimeInHomeTime.DateTime().Year() )
       
  1624  		{
       
  1625 		// Event is today, use time text from msg
       
  1626 		return TimeTextFromMsgLC( aMessage );
       
  1627     	}
       
  1628     else
       
  1629     	{
       
  1630     	// Event is not from today, use date text without year number
       
  1631 		return DateTextFromMsgLC( aMessage, EFalse );
       
  1632     	}
       
  1633 	}
       
  1634 
       
  1635 
       
  1636 // -----------------------------------------------------------------------------
       
  1637 // TFsEmailUiUtility::WeekDayTextFromMsgLC
       
  1638 // -----------------------------------------------------------------------------
       
  1639 HBufC* TFsEmailUiUtility::WeekDayTextFromMsgLC( const CFSMailMessage* aMessage,
       
  1640 													 TBool aUseToday,
       
  1641 													 TBool aUseYesterday,
       
  1642 													 TBool& aWasToday,
       
  1643 													 TBool& aWasYesterday )
       
  1644 	{
       
  1645     FUNC_LOG;
       
  1646 	HBufC* ret(0);
       
  1647 	TTime eventTimeInHomeTime = aMessage->GetDate();
       
  1648 	TTime currentTime;
       
  1649 	currentTime.HomeTime();
       
  1650     TLocale currentLocaleSettings;
       
  1651 
       
  1652 	// Correct current time and event time UTC offset and daylight saving time
       
  1653     eventTimeInHomeTime = eventTimeInHomeTime +
       
  1654     					  (currentLocaleSettings.UniversalTimeOffset());
       
  1655     eventTimeInHomeTime += currentLocaleSettings.QueryHomeHasDaylightSavingOn()
       
  1656     					  ? TTimeIntervalHours(1) : TTimeIntervalHours(0);
       
  1657 
       
  1658  	TBool eventTimeIsToday(EFalse);
       
  1659  	TBool eventTimeIsYesterday(EFalse);
       
  1660  	// Check if year and day number in year are the same, e.g. today
       
  1661  	if ( currentTime.DayNoInYear() == eventTimeInHomeTime.DayNoInYear() &&
       
  1662  		 currentTime.DateTime().Year() == eventTimeInHomeTime.DateTime().Year() )
       
  1663  		{
       
  1664 		eventTimeIsToday = ETrue;
       
  1665   		}
       
  1666  	// Check if year and current day number minus one in year are the same, e.g. yesterday
       
  1667  	else if ( currentTime.DayNoInYear()-1 == eventTimeInHomeTime.DayNoInYear() &&
       
  1668  		currentTime.DateTime().Year() == eventTimeInHomeTime.DateTime().Year() )
       
  1669  		{
       
  1670 		eventTimeIsYesterday = ETrue;
       
  1671 		}
       
  1672 	if ( aUseToday && eventTimeIsToday )
       
  1673 		{
       
  1674 		ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_TODAY );
       
  1675 		aWasToday = ETrue;
       
  1676 		}
       
  1677 	else if ( aUseYesterday && eventTimeIsYesterday )
       
  1678 		{
       
  1679 		ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_YESTERDAY );
       
  1680 		aWasYesterday = ETrue;
       
  1681 		}
       
  1682 	else
       
  1683 		{
       
  1684 		switch ( eventTimeInHomeTime.DayNoInWeek() )
       
  1685 			{
       
  1686 			case EMonday:
       
  1687 				ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_MONDAY );
       
  1688 				break;
       
  1689 			case ETuesday:
       
  1690 				ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_TUESDAY );
       
  1691 				break;
       
  1692 			case EWednesday:
       
  1693 				ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_WEDNESDAY );
       
  1694 				break;
       
  1695 			case EThursday:
       
  1696 				ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_THURSDAY );
       
  1697 				break;
       
  1698 			case EFriday:
       
  1699 				ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_FRIDAY );
       
  1700 				break;
       
  1701 			case ESaturday:
       
  1702 				ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_SATURDAY );
       
  1703 				break;
       
  1704 			case ESunday:
       
  1705 				ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_WEEEKDAY_SUNDAY );
       
  1706 				break;
       
  1707 			}
       
  1708 		}
       
  1709 	return ret;
       
  1710 	}
       
  1711 
       
  1712 
       
  1713 // -----------------------------------------------------------------------------
       
  1714 // TFsEmailUiUtility::CreateSizeDescLC
       
  1715 // -----------------------------------------------------------------------------
       
  1716 HBufC* TFsEmailUiUtility::CreateSizeDescLC( TInt aSizeInBytes,
       
  1717                                             TBool aShowSizeInBytes )
       
  1718     {
       
  1719     FUNC_LOG;
       
  1720     HBufC* sizeDesc = NULL;
       
  1721 
       
  1722     if ( aSizeInBytes >= KMega ) // Show in MB with one decimal
       
  1723         {
       
  1724         // The largest possible file size in 32bit architecture is 2^32 bytes = 4096 MB.
       
  1725         // Thus, we need to reserve 4 characters for the megabyte part, one for decimal
       
  1726         // separator, and one for decimal part.
       
  1727         HBufC* numberBuf = HBufC::NewLC(4+1+1);
       
  1728         TPtr numberDes = numberBuf->Des();
       
  1729 
       
  1730         TInt megaBytePart = aSizeInBytes / KMega;
       
  1731         TInt remainder = aSizeInBytes % KMega;
       
  1732         TInt decimalPart = (remainder*10 + KMega/2) / KMega; // The +KMega/2 is used to get normal rounding rules
       
  1733         // if decimal part gets rounded up to 10, we need to increment the megabyte part
       
  1734         if ( decimalPart == 10 )
       
  1735             {
       
  1736             megaBytePart++;
       
  1737             decimalPart = 0;
       
  1738             }
       
  1739 
       
  1740         TLocale locale;
       
  1741         TChar decimalSeparator = locale.DecimalSeparator();
       
  1742 
       
  1743         numberDes.Num( megaBytePart );
       
  1744         numberDes.Append( decimalSeparator );
       
  1745         numberDes.AppendNum( decimalPart );
       
  1746 
       
  1747         if( aShowSizeInBytes )
       
  1748             {
       
  1749             sizeDesc = StringLoader::LoadL( R_FREESTYLE_EMAIL_UI_SIZE_IN_MB_WITH_BYTES,
       
  1750                                             *numberBuf, aSizeInBytes );
       
  1751             }
       
  1752         else
       
  1753             {
       
  1754             sizeDesc = StringLoader::LoadL( R_FREESTYLE_EMAIL_UI_SIZE_IN_MB, *numberBuf );
       
  1755             }
       
  1756         CleanupStack::PopAndDestroy( numberBuf );
       
  1757         CleanupStack::PushL( sizeDesc );
       
  1758         }
       
  1759     else if ( aSizeInBytes >= KKilo || aSizeInBytes == 0 ) // Show in kB without decimals
       
  1760         {
       
  1761         TInt sizeInKB = (aSizeInBytes + KKilo/2) / KKilo; // The +KKilo/2 is used to get normal rounding rules
       
  1762         if( aShowSizeInBytes )
       
  1763             {
       
  1764             HBufC* numberBuf = HBufC::NewLC(8);
       
  1765             TPtr numberDes = numberBuf->Des();
       
  1766             numberDes.Num( sizeInKB );
       
  1767 
       
  1768             sizeDesc = StringLoader::LoadL( R_FREESTYLE_EMAIL_UI_SIZE_IN_KB_WITH_BYTES,
       
  1769                                             *numberBuf, aSizeInBytes );
       
  1770             CleanupStack::PopAndDestroy( numberBuf );
       
  1771             CleanupStack::PushL( sizeDesc );
       
  1772             }
       
  1773         else
       
  1774             {
       
  1775             sizeDesc = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SIZE_IN_KB, sizeInKB );
       
  1776             }
       
  1777         }
       
  1778     else if ( aSizeInBytes > 0 ) // show "less than kilobyte"
       
  1779         {
       
  1780         if( aShowSizeInBytes )
       
  1781             {
       
  1782             sizeDesc = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SIZE_LESS_THAN_KB_WITH_BYTES,
       
  1783                                             aSizeInBytes );
       
  1784             }
       
  1785         else
       
  1786             {
       
  1787             sizeDesc = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SIZE_LESS_THAN_KB );
       
  1788             }
       
  1789         }
       
  1790     else // negative numbers are not supported
       
  1791         {
       
  1792         __ASSERT_DEBUG( EFalse, Panic(EFSEmailUiUnexpectedValue) );
       
  1793         sizeDesc = KNullDesC().AllocLC();
       
  1794         }
       
  1795 
       
  1796     // Do number conversion to Arabic/Eastern Arabic/Indic digits when necessary
       
  1797     TPtr des = sizeDesc->Des();
       
  1798     AknTextUtils::LanguageSpecificNumberConversion( des );
       
  1799 
       
  1800     return sizeDesc;
       
  1801     }
       
  1802 
       
  1803 // -----------------------------------------------------------------------------
       
  1804 // TFsEmailUiUtility::CompareMailSubjectsL
       
  1805 // -----------------------------------------------------------------------------
       
  1806 TInt TFsEmailUiUtility::CompareMailSubjectsL( const CFSMailMessage* aMessage1,
       
  1807                                               const CFSMailMessage* aMessage2 )
       
  1808 	{
       
  1809     FUNC_LOG;
       
  1810 	TInt result( 0 );
       
  1811 
       
  1812 	if ( aMessage1 &&  aMessage2 )
       
  1813 		{
       
  1814 		HBufC* compareSubject1 = CreateSubjectWithoutLocalisedPrefixLC( aMessage1, ETrue );
       
  1815 		compareSubject1->Des().LowerCase();
       
  1816 		HBufC* compareSubject2 = CreateSubjectWithoutLocalisedPrefixLC( aMessage2, ETrue );
       
  1817 		compareSubject2->Des().LowerCase();
       
  1818 
       
  1819 		result = compareSubject1->CompareC( *compareSubject2 );
       
  1820 
       
  1821 		CleanupStack::PopAndDestroy( compareSubject2 );
       
  1822 		CleanupStack::PopAndDestroy( compareSubject1 );
       
  1823 		}
       
  1824 	// Check if one subject pointer is valid instead of other -> result is non-zero.
       
  1825 	else if ( aMessage1 && !aMessage2  )
       
  1826 	    {
       
  1827 	    result = 1;
       
  1828 	    }
       
  1829 	else if ( !aMessage1 && aMessage2 )
       
  1830 		{
       
  1831 		result = -1;
       
  1832 		}
       
  1833 	return result;
       
  1834 	}
       
  1835 
       
  1836 // -----------------------------------------------------------------------------
       
  1837 // TFsEmailUiUtility::CreateSubjectWithoutLocalisedPrefixLC
       
  1838 // -----------------------------------------------------------------------------
       
  1839 HBufC* TFsEmailUiUtility::CreateSubjectWithoutLocalisedPrefixLC(
       
  1840         const CFSMailMessage* aMessage,
       
  1841         TBool aSuppressNotAvailableText /*= EFalse*/ )
       
  1842 	{
       
  1843     FUNC_LOG;
       
  1844     TDesC* subject = &aMessage->GetSubject();
       
  1845 	TPtrC croppedSubject;
       
  1846     if ( subject )
       
  1847         {
       
  1848         croppedSubject.Set( *subject );
       
  1849         }
       
  1850 
       
  1851 	TBool prefixFound = EFalse;
       
  1852 
       
  1853 	do
       
  1854 	    {
       
  1855 	    prefixFound = EFalse;
       
  1856 
       
  1857 	    // Remove leading white space before trying to find the prefix
       
  1858 	    while( croppedSubject.Length() &&
       
  1859 	           TChar(croppedSubject[0]).IsSpace() )
       
  1860 	        {
       
  1861 	        croppedSubject.Set( croppedSubject.Mid(1) );
       
  1862 	        }
       
  1863 
       
  1864     	// try to find ":" at the beginning
       
  1865 		// Locate : character on location 1,2 and 3
       
  1866 	    static const TInt KPrefixMinLength = 1;
       
  1867 	    static const TInt KPrefixMaxLength = 3;
       
  1868 	    static const TText KPrefixSeparator = ':';
       
  1869 		TInt separatorPosition = croppedSubject.Locate( KPrefixSeparator );
       
  1870 		if ( separatorPosition >= KPrefixMinLength &&
       
  1871 		     separatorPosition <= KPrefixMaxLength )
       
  1872 			{
       
  1873 			TPtrC prefixCandidate = croppedSubject.Left( separatorPosition );
       
  1874 			// Only fully alphabetic prefixes are cropped
       
  1875 			TBool isAlpha = ETrue;
       
  1876 			for ( TInt i = 0 ; i < prefixCandidate.Length() ; ++i )
       
  1877 			    {
       
  1878 			    if ( !TChar( prefixCandidate[i] ).IsAlpha() )
       
  1879 			        {
       
  1880 			        isAlpha = EFalse;
       
  1881 			        }
       
  1882 			    }
       
  1883 			if ( isAlpha )
       
  1884 			    {
       
  1885     			croppedSubject.Set( croppedSubject.Mid( separatorPosition+1 ) );
       
  1886     			prefixFound = ETrue;
       
  1887 			    }
       
  1888 			}
       
  1889 	    }
       
  1890 	while ( prefixFound );
       
  1891 
       
  1892 	HBufC* ret = croppedSubject.AllocLC();
       
  1893 
       
  1894 	// Filter out undesirable characters and remove extra white space
       
  1895 	TPtr retPtr = ret->Des();
       
  1896 	FilterListItemTextL( retPtr );
       
  1897 
       
  1898 	// Use "(no subject available)" text if subject is emtpy and this is not forbidden by caller
       
  1899 	if ( !ret->Length() && !aSuppressNotAvailableText )
       
  1900 	    {
       
  1901 	    CleanupStack::PopAndDestroy( ret );
       
  1902 	    ret = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_NO_SUBJECT );
       
  1903 	    }
       
  1904 
       
  1905 	return ret;
       
  1906 	}
       
  1907 
       
  1908 // -----------------------------------------------------------------------------
       
  1909 // TFsEmailUiUtility::CreateSubjectTextLC
       
  1910 // -----------------------------------------------------------------------------
       
  1911 HBufC* TFsEmailUiUtility::CreateSubjectTextLC( const CFSMailMessage* aMessage )
       
  1912     {
       
  1913     FUNC_LOG;
       
  1914     HBufC* subjectText = NULL;
       
  1915 
       
  1916     if ( aMessage )
       
  1917         {
       
  1918         const TDesC* subject = &aMessage->GetSubject();
       
  1919         if ( subject )
       
  1920             {
       
  1921             subjectText = subject->AllocLC();
       
  1922             TPtr ptr( subjectText->Des() );
       
  1923             FilterListItemTextL( ptr );
       
  1924             // discard the subject text if it's empty after the filtering
       
  1925             if ( !subjectText->Length() )
       
  1926                 {
       
  1927                 CleanupStack::PopAndDestroy( subjectText );
       
  1928                 subjectText = NULL;
       
  1929                 }
       
  1930             }
       
  1931         }
       
  1932 
       
  1933     // Use "(no subject available)" text if no other visible subject got
       
  1934     if ( !subjectText )
       
  1935         {
       
  1936         subjectText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_NO_SUBJECT );
       
  1937         }
       
  1938 
       
  1939     return subjectText;
       
  1940     }
       
  1941 
       
  1942 
       
  1943 // -----------------------------------------------------------------------------
       
  1944 // TFsEmailUiUtility::CreateBodyTextLC
       
  1945 // -----------------------------------------------------------------------------
       
  1946 HBufC* TFsEmailUiUtility::CreateBodyTextLC( const CFSMailMessage* aMessage )
       
  1947     {
       
  1948     FUNC_LOG;
       
  1949     HBufC* bodyText = NULL;
       
  1950 
       
  1951     if ( aMessage )
       
  1952         {
       
  1953         CFSMailMessage* msg = const_cast<CFSMailMessage*> (aMessage);
       
  1954         CFSMailMessagePart* bodyPart = msg->PlainTextBodyPartL();
       
  1955         if ( bodyPart )
       
  1956             {
       
  1957             CleanupStack::PushL( bodyPart );
       
  1958             bodyText = HBufC::NewLC(bodyPart->ContentSize());
       
  1959             TPtr ptr =  bodyText->Des();
       
  1960             bodyPart->GetContentToBufferL(ptr, 0);
       
  1961 
       
  1962             FilterListItemTextL( ptr );
       
  1963             // discard the subject text if it's empty after the filtering
       
  1964             if ( !bodyText->Length() )
       
  1965                 {
       
  1966                 CleanupStack::PopAndDestroy( bodyText );
       
  1967                 bodyText = NULL;
       
  1968                 }
       
  1969             CleanupStack::PopAndDestroy( bodyPart );
       
  1970             }
       
  1971         }
       
  1972 
       
  1973     // Use "(no subject available)" text if no other visible subject got
       
  1974     if ( !bodyText )
       
  1975         {
       
  1976         bodyText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_NO_SUBJECT );
       
  1977         }
       
  1978 
       
  1979     return bodyText;
       
  1980     }
       
  1981 
       
  1982 
       
  1983 
       
  1984 // ---------------------------------------------------------------------------
       
  1985 // TFsEmailUiUtility::FilterPreviewPaneTextL
       
  1986 // This function crops out tabulator and line feed characters from the given data.
       
  1987 // After that, it will makes sure that there are no consecutive space characters for
       
  1988 // preview pane text
       
  1989 // ---------------------------------------------------------------------------
       
  1990 //
       
  1991 void TFsEmailUiUtility::FilterListItemTextL( TDes& aText )
       
  1992     {
       
  1993     FUNC_LOG;
       
  1994     _LIT( KCharsToReplace, "\r\n\t\x2028\x2029" );
       
  1995 
       
  1996     AknTextUtils::ReplaceCharacters( aText, KCharsToReplace, ' ' );
       
  1997     aText.TrimAll();
       
  1998     }
       
  1999 
       
  2000 // -----------------------------------------------------------------------------
       
  2001 // TFsEmailUiUtility::MessageSizeClass
       
  2002 // -----------------------------------------------------------------------------
       
  2003 TMessageSizeClass TFsEmailUiUtility::MessageSizeClass( const CFSMailMessage& aMessage )
       
  2004     {
       
  2005     FUNC_LOG;
       
  2006     TUint msgSize = aMessage.ContentSize();
       
  2007     TMessageSizeClass sizeClass;
       
  2008 
       
  2009     if ( msgSize < ETiny )
       
  2010         {
       
  2011         sizeClass = ETiny;
       
  2012         }
       
  2013     else if ( msgSize < ESmall )
       
  2014         {
       
  2015         sizeClass = ESmall;
       
  2016         }
       
  2017     else if ( msgSize < EMedium )
       
  2018         {
       
  2019         sizeClass = EMedium;
       
  2020         }
       
  2021     else if ( msgSize < ELarge )
       
  2022         {
       
  2023         sizeClass = ELarge;
       
  2024         }
       
  2025     else if ( msgSize < EVeryLarge )
       
  2026         {
       
  2027         sizeClass = EVeryLarge;
       
  2028         }
       
  2029     else if ( msgSize < EHuge )
       
  2030         {
       
  2031         sizeClass = EHuge;
       
  2032         }
       
  2033     else
       
  2034         {
       
  2035         sizeClass = EColossal;
       
  2036         }
       
  2037 
       
  2038     return sizeClass;
       
  2039     }
       
  2040 
       
  2041 // -----------------------------------------------------------------------------
       
  2042 // TFsEmailUiUtility::ConvertHtmlToTxtL
       
  2043 // -----------------------------------------------------------------------------
       
  2044 HBufC* TFsEmailUiUtility::ConvertHtmlToTxtL( const TDesC& aHtml )
       
  2045     {
       
  2046     FUNC_LOG;
       
  2047     enum TPrevious
       
  2048         {
       
  2049         ENone, // Nothing special in previous character
       
  2050         EHeadTag, // We are in head tag
       
  2051         ETagEnd, // Previous character contained tag ending
       
  2052         ESpace // Previous character contained space
       
  2053         };
       
  2054 
       
  2055     _LIT( KTagStart, "<" );
       
  2056     _LIT( KTagEnd, ">" );
       
  2057     _LIT( KHeadStart, "head" );
       
  2058     _LIT( KHeadEnd, "/head>" );
       
  2059 
       
  2060     TInt tagCount = 0; // Amount of nested tags
       
  2061     TInt sizeToParse = aHtml.Length(); // How much we have to parse
       
  2062     TPrevious previous = ENone; // Previous characters type.
       
  2063     HBufC* txtBuffer = HBufC::NewLC( sizeToParse );
       
  2064 
       
  2065     // HTML parsing.
       
  2066     TInt lineFeedCount = 0;
       
  2067     TInt index = 0; // Parsing index
       
  2068     for ( index = 0; index < sizeToParse; index++ )
       
  2069         {
       
  2070         // Get the next character
       
  2071         TPtrC ptr = aHtml.Mid( index, 1 );
       
  2072 
       
  2073         // Are we in header
       
  2074         if ( previous == EHeadTag )
       
  2075             {
       
  2076             // Is this a start of end tag
       
  2077             if ( ptr.Compare( KTagStart ) == 0 &&
       
  2078                     index + KHeadEnd().Length() < sizeToParse )
       
  2079                 {
       
  2080                 ptr.Set( aHtml.Mid( index + 1, KHeadEnd().Length() ) );
       
  2081                 if ( ptr.Compare( KHeadEnd ) == 0 )
       
  2082                     {
       
  2083                     previous = ETagEnd;
       
  2084                     index += KHeadEnd().Length();
       
  2085                     }
       
  2086                 }
       
  2087 
       
  2088             }
       
  2089         // Is this a start of the tag
       
  2090         else if ( ptr.Compare( KTagStart ) == 0 )
       
  2091             {
       
  2092             lineFeedCount = 0;
       
  2093 
       
  2094             if ( index + KHeadStart().Length() < sizeToParse )
       
  2095                 {
       
  2096                 ptr.Set( aHtml.Mid( index + 1, KHeadStart().Length() ) );
       
  2097                 if ( ptr.Compare( KHeadStart ) == 0 )
       
  2098                     {
       
  2099                     previous = EHeadTag;
       
  2100                     index += KHeadStart().Length();
       
  2101                     }
       
  2102                 }
       
  2103 
       
  2104             if ( previous != EHeadTag )
       
  2105                 {
       
  2106                 // Increase the number of nested tags
       
  2107                 tagCount++;
       
  2108                 previous = ENone;
       
  2109                 }
       
  2110             }
       
  2111         // Are we inside of the tag
       
  2112         else if ( tagCount > 0 )
       
  2113             {
       
  2114             // Is this the end of the tag
       
  2115             if ( ptr.Compare( KTagEnd ) == 0 )
       
  2116                 {
       
  2117                 tagCount--;
       
  2118                 if ( tagCount < 0 )
       
  2119                     {
       
  2120                     // To avoid unnecessary errors convert negative
       
  2121                     // values to zero.
       
  2122                     tagCount = 0;
       
  2123                     }
       
  2124                 if ( tagCount == 0 )
       
  2125                     {
       
  2126                     previous = ETagEnd;
       
  2127                     }
       
  2128                 }
       
  2129             }
       
  2130         // We are not inside of the tag
       
  2131         else
       
  2132             {
       
  2133             if ( previous == ETagEnd )
       
  2134                 {
       
  2135                 // Skip multiple line feed and carriage return characters
       
  2136                 if ( ptr.Compare( KCarriageReturn ) != 0 &&
       
  2137                      ptr.Compare( KLineFeed ) != 0 )
       
  2138                     {
       
  2139                     if ( lineFeedCount > 0 )
       
  2140                         {
       
  2141                         txtBuffer->Des().Append( KLineFeed );
       
  2142                         lineFeedCount = 0;
       
  2143                         }
       
  2144                     txtBuffer->Des().Append( ptr );
       
  2145                     previous = ENone;
       
  2146                     }
       
  2147                 else if ( ptr.Compare( KLineFeed ) == 0 )
       
  2148                     {
       
  2149                     lineFeedCount++;
       
  2150                     }
       
  2151                 }
       
  2152             else
       
  2153                 {
       
  2154                 if ( previous == ESpace )
       
  2155                     {
       
  2156                     // Skip consecutive spaces
       
  2157  //                   if ( ptr.Compare( KSpace ) != 0 )
       
  2158  //                       {
       
  2159                             txtBuffer->Des().Append( ptr );
       
  2160  //                       }
       
  2161                     }
       
  2162                 else
       
  2163                     {
       
  2164                     txtBuffer->Des().Append( ptr );
       
  2165                     }
       
  2166                 if ( ptr.Compare( KSpace ) == 0 )
       
  2167                     {
       
  2168                     previous = ESpace;
       
  2169                     }
       
  2170                 else
       
  2171                     {
       
  2172                     previous = ENone;
       
  2173                     }
       
  2174                 }
       
  2175             }
       
  2176         }
       
  2177 
       
  2178     CleanupStack::Pop( txtBuffer );
       
  2179 
       
  2180     return txtBuffer;
       
  2181     }
       
  2182 
       
  2183 // -----------------------------------------------------------------------------
       
  2184 // TFsEmailUiUtility::CompareMailAddressesL
       
  2185 // -----------------------------------------------------------------------------
       
  2186 TInt TFsEmailUiUtility::CompareMailAddressesL( CFSMailAddress* aAddr1,
       
  2187     CFSMailAddress* aAddr2 )
       
  2188 	{
       
  2189     FUNC_LOG;
       
  2190 	TInt result( 0 );
       
  2191 	if ( aAddr1 && aAddr2 )
       
  2192 		{
       
  2193 		HBufC* compareName1 = CreateCompareNameForAddressLC( *aAddr1 );
       
  2194         HBufC* compareName2 = CreateCompareNameForAddressLC( *aAddr2 );
       
  2195 
       
  2196         result = compareName1->CompareC( *compareName2 );
       
  2197 
       
  2198         CleanupStack::PopAndDestroy( compareName2 );
       
  2199         CleanupStack::PopAndDestroy( compareName1 );
       
  2200 		}
       
  2201 		// Check if one address pointer is valid instead of other -> result is non-zero.
       
  2202 	else if ( ( aAddr1 && !aAddr2  ) )
       
  2203 	    {
       
  2204 	    result = 1;
       
  2205 	    }
       
  2206 	else if ( !aAddr1 && aAddr2  )
       
  2207 		{
       
  2208 		result = -1;
       
  2209 		}
       
  2210 	return result;
       
  2211 	}
       
  2212 
       
  2213 // -----------------------------------------------------------------------------
       
  2214 // TFsEmailUiUtility::CreateCompareNameForAddressLC
       
  2215 // -----------------------------------------------------------------------------
       
  2216 HBufC* TFsEmailUiUtility::CreateCompareNameForAddressLC( const CFSMailAddress& aAddress )
       
  2217     {
       
  2218     FUNC_LOG;
       
  2219     HBufC* result = NULL;
       
  2220 
       
  2221     TDesC* displayName = &aAddress.GetDisplayName();
       
  2222     TDesC* emailAddress = &aAddress.GetEmailAddress();
       
  2223 
       
  2224     if ( displayName && displayName->Length() )
       
  2225         {
       
  2226         result = displayName->AllocLC();
       
  2227         }
       
  2228     else if ( emailAddress && emailAddress->Length() )
       
  2229         {
       
  2230         result = emailAddress->AllocLC();
       
  2231         }
       
  2232     else
       
  2233         {
       
  2234         result = KNullDesC().AllocLC();
       
  2235         }
       
  2236 
       
  2237     result->Des().LowerCase();
       
  2238     return result;
       
  2239     }
       
  2240 
       
  2241 // -----------------------------------------------------------------------------
       
  2242 // TFsEmailUiUtility::CountRecepients
       
  2243 // -----------------------------------------------------------------------------
       
  2244 TInt TFsEmailUiUtility::CountRecepients( CFSMailMessage* aMsgPtr )
       
  2245     {
       
  2246     FUNC_LOG;
       
  2247     return aMsgPtr->GetToRecipients().Count() + aMsgPtr->GetCCRecipients().Count();
       
  2248     }
       
  2249 
       
  2250 // -----------------------------------------------------------------------------
       
  2251 // TFsEmailUiUtility::CountRecipientsSmart
       
  2252 // Calculates recipient count from To and Cc recipient as well as tries to 
       
  2253 // see if the message is sent via message list.
       
  2254 // -----------------------------------------------------------------------------
       
  2255 TInt TFsEmailUiUtility::CountRecipientsSmart( CFreestyleEmailUiAppUi& aAppUi, CFSMailMessage* aMsgPtr )
       
  2256     {
       
  2257     FUNC_LOG;
       
  2258     TInt numRecipients( CountRecepients( aMsgPtr ) );
       
  2259     if ( numRecipients == 1 )
       
  2260         {
       
  2261         CFSMailBox* mailBox = NULL;
       
  2262         
       
  2263         TRAPD( error, mailBox = aAppUi.GetMailClient()->GetMailBoxByUidL( aMsgPtr->GetMailBoxId() ) );
       
  2264         
       
  2265         if (mailBox && !error)
       
  2266             {
       
  2267             //check if the malbox ownmailaddress is same as the recipients email address. If not, then assume that the
       
  2268             //email is a distribution list and we need to inc num of Recipients so that "Reply ALL" option appears in UI.
       
  2269             if ( aMsgPtr->GetToRecipients().Count() )
       
  2270                 {
       
  2271                 if ( mailBox->OwnMailAddress().GetEmailAddress().CompareF(aMsgPtr->GetToRecipients()[0]->GetEmailAddress()) )
       
  2272                     {
       
  2273                     numRecipients++;
       
  2274                     }
       
  2275                 }
       
  2276             if ( aMsgPtr->GetCCRecipients().Count() )
       
  2277                 {
       
  2278                 if ( mailBox->OwnMailAddress().GetEmailAddress().CompareF(aMsgPtr->GetCCRecipients()[0]->GetEmailAddress()) )
       
  2279                     {
       
  2280                     numRecipients++;
       
  2281                     }
       
  2282                 }
       
  2283             if ( aMsgPtr->GetBCCRecipients().Count() )
       
  2284                 {
       
  2285                 if ( mailBox->OwnMailAddress().GetEmailAddress().CompareF(aMsgPtr->GetBCCRecipients()[0]->GetEmailAddress()) )
       
  2286                     {
       
  2287                     numRecipients++;
       
  2288                     }
       
  2289                 }
       
  2290             }
       
  2291         
       
  2292         delete mailBox;
       
  2293         }
       
  2294     
       
  2295     return numRecipients;
       
  2296     }
       
  2297 
       
  2298 // -----------------------------------------------------------------------------
       
  2299 // TFsEmailUiUtility::IsMessageBodyLargeL
       
  2300 // -----------------------------------------------------------------------------
       
  2301 TBool TFsEmailUiUtility::IsMessageBodyLargeL( CFSMailMessage* aMessage )
       
  2302     {
       
  2303     FUNC_LOG;
       
  2304     TBool ret = EFalse;
       
  2305     if ( aMessage )
       
  2306         {
       
  2307         CFSMailMessagePart* plainTextBodyPart = aMessage->PlainTextBodyPartL();
       
  2308         CleanupStack::PushL( plainTextBodyPart );
       
  2309         CFSMailMessagePart* htmlBodyPart = aMessage->HtmlBodyPartL();
       
  2310         CleanupStack::PushL( htmlBodyPart );
       
  2311 
       
  2312         if ( (plainTextBodyPart && plainTextBodyPart->FetchedContentSize() > KLargePlainTextSizeLimit) ||
       
  2313              (htmlBodyPart && htmlBodyPart->FetchedContentSize() > KLargeHtmlTextSizeLimit) )
       
  2314             {
       
  2315             ret = ETrue;
       
  2316             }
       
  2317 
       
  2318         CleanupStack::PopAndDestroy( htmlBodyPart );
       
  2319         CleanupStack::PopAndDestroy( plainTextBodyPart );
       
  2320         }
       
  2321     return ret;
       
  2322     }
       
  2323 
       
  2324 // -----------------------------------------------------------------------------
       
  2325 // TFsEmailUiUtility::GetUnreadMsgIconL
       
  2326 // -----------------------------------------------------------------------------
       
  2327 TFSEmailUiTextures TFsEmailUiUtility::GetUnreadMsgIcon( CFSMailMessage* aMsgPtr )
       
  2328 	{
       
  2329     FUNC_LOG;
       
  2330 	TFSEmailUiTextures textureId;
       
  2331 	// Unread calendar invitation
       
  2332 	if ( aMsgPtr->IsFlagSet( EFSMsgFlag_CalendarMsg ))
       
  2333 		{
       
  2334 		if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Important ) )
       
  2335 			{
       
  2336 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2337 				{
       
  2338 				textureId = EMessageCalInvitationAttachmentsHighPrio ;
       
  2339 				}
       
  2340 			else
       
  2341 				{
       
  2342 				textureId = EMessageCalInvitationHighPrio;
       
  2343 				}
       
  2344 			}
       
  2345 		else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Low ) )
       
  2346 			{
       
  2347 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2348 				{
       
  2349 				textureId = EMessageCalInvitationAttachmentsLowPrio;
       
  2350 				}
       
  2351 			else
       
  2352 				{
       
  2353 				textureId = EMessageCalInvitationLowPrio;
       
  2354 				}
       
  2355 			}
       
  2356 		else
       
  2357 			{
       
  2358 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2359 				{
       
  2360 				textureId = EMessageCalInvitationAttachments;
       
  2361 				}
       
  2362 			else
       
  2363 				{
       
  2364 				textureId = EMessageCalInvitation;
       
  2365 				}
       
  2366 			}
       
  2367         // <cmail>
       
  2368 		TBool cancellationMsg = EFalse;
       
  2369 		TRAP_IGNORE( cancellationMsg = IsMrCancellationMsgL( aMsgPtr ) );
       
  2370 		if ( cancellationMsg )
       
  2371 		    {
       
  2372 		    textureId = EMessageCalInvitationCancelled;
       
  2373 		    }
       
  2374         // </cmail>
       
  2375 		}
       
  2376 	else	// Normal message icons
       
  2377 		{
       
  2378 		// Check whether msg has attachment or not
       
  2379 		if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Attachments )) // Has attachments
       
  2380 			{
       
  2381 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Important )) // High priority, has attachments
       
  2382 				{
       
  2383 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2384 					{
       
  2385 					textureId = EMessageUnreadRepliedHighPrioIconAttachment;
       
  2386 					}
       
  2387 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2388 					{
       
  2389 					textureId = EMessageUnreadForwardedHighPrioIconAttachment;
       
  2390 					}
       
  2391 				else
       
  2392 					{
       
  2393 					textureId = EMessageHighPrioUnreadIconAttachment;
       
  2394 					}
       
  2395 				}
       
  2396 			else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Low ) ) // Low priority, has attachments
       
  2397 				{
       
  2398 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2399 					{
       
  2400 					textureId = EMessageUnreadRepliedLowPrioIconAttachment;
       
  2401 					}
       
  2402 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2403 					{
       
  2404 					textureId = EMessageUnreadForwardedLowPrioIconAttachment;
       
  2405 					}
       
  2406 				else
       
  2407 					{
       
  2408 					textureId = EMessageLowPrioUnreadIconAttachment;
       
  2409 					}
       
  2410 				}
       
  2411 			else // Normal priority, has attachments
       
  2412 				{
       
  2413 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2414 					{
       
  2415 					textureId = EMessageUnreadRepliedIconAttachment;
       
  2416 					}
       
  2417 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2418 					{
       
  2419 					textureId = EMessageUnreadForwardedIconAttachment;
       
  2420 					}
       
  2421 				else
       
  2422 					{
       
  2423 					textureId = EMessageUnreadIconAttachment;
       
  2424 					}
       
  2425 				}
       
  2426 			}
       
  2427 
       
  2428 		else // No attachments
       
  2429 			{
       
  2430 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Important )) // High priority, no attachments
       
  2431 				{
       
  2432 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2433 					{
       
  2434 					textureId = EMessageUnreadRepliedHighPrioIcon;
       
  2435 					}
       
  2436 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2437 					{
       
  2438 					textureId = EMessageUnreadForwardedHighPrioIcon;
       
  2439 					}
       
  2440 				else
       
  2441 					{
       
  2442 					textureId = EMessageHighPrioUnreadIcon;
       
  2443 					}
       
  2444 				}
       
  2445 			else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Low ) ) // Low priority, no attachments
       
  2446 				{
       
  2447 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2448 					{
       
  2449 					textureId = EMessageUnreadRepliedLowPrioIcon;
       
  2450 					}
       
  2451 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2452 					{
       
  2453 					textureId = EMessageUnreadForwardedLowPrioIcon;
       
  2454 					}
       
  2455 				else
       
  2456 					{
       
  2457 					textureId = EMessageLowPrioUnreadIcon;
       
  2458 					}
       
  2459 				}
       
  2460 			else // Normal priority, no attachments
       
  2461 				{
       
  2462 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2463 					{
       
  2464 					textureId = EMessageUnreadRepliedIcon;
       
  2465 					}
       
  2466 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2467 					{
       
  2468 					textureId = EMessageUnreadForwardedIcon;
       
  2469 					}
       
  2470 				else
       
  2471 					{
       
  2472 					textureId = EMessageUnreadIcon;
       
  2473 					}
       
  2474 				}
       
  2475 			}
       
  2476 		}
       
  2477 	return textureId;
       
  2478 	}
       
  2479 
       
  2480 
       
  2481 // -----------------------------------------------------------------------------
       
  2482 // TFsEmailUiUtility::GetReadMsgIconL
       
  2483 // -----------------------------------------------------------------------------
       
  2484 TFSEmailUiTextures TFsEmailUiUtility::GetReadMsgIcon( CFSMailMessage* aMsgPtr )
       
  2485 	{
       
  2486     FUNC_LOG;
       
  2487 	TFSEmailUiTextures textureId;
       
  2488 	// Check for calendar invitation first
       
  2489 	if ( aMsgPtr->IsFlagSet( EFSMsgFlag_CalendarMsg ))
       
  2490 		{
       
  2491 		if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Important ) )
       
  2492 			{
       
  2493 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2494 				{
       
  2495 				textureId = EMessageCalInvitationReadAttachmentsHighPrio ;
       
  2496 				}
       
  2497 			else
       
  2498 				{
       
  2499 				textureId = EMessageCalInvitationReadHighPrio;
       
  2500 				}
       
  2501 			}
       
  2502 		else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Low ) )
       
  2503 			{
       
  2504 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2505 				{
       
  2506 				textureId = EMessageCalInvitationReadAttachmentsLowPrio;
       
  2507 				}
       
  2508 			else
       
  2509 				{
       
  2510 				textureId = EMessageCalInvitationReadLowPrio;
       
  2511 				}
       
  2512 			}
       
  2513 		else
       
  2514 			{
       
  2515 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2516 				{
       
  2517 				textureId = EMessageCalInvitationReadAttachments;
       
  2518 				}
       
  2519 			else
       
  2520 				{
       
  2521 				textureId = EMessageCalInvitationRead;
       
  2522 				}
       
  2523 			}
       
  2524 		// <cmail>
       
  2525 		TBool cancellationMsg = EFalse;
       
  2526 		TRAP_IGNORE( cancellationMsg = IsMrCancellationMsgL( aMsgPtr ) );
       
  2527 		if ( cancellationMsg )
       
  2528 		    {
       
  2529             textureId = EMessageCalInvitationCancelled;
       
  2530             }
       
  2531         // </cmail>
       
  2532 		}
       
  2533 	else	// Normal message icons
       
  2534 		{
       
  2535 		// Check whether msg has attachment or not
       
  2536 		if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Attachments )) // Has attachments
       
  2537 			{
       
  2538 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Important )) // High priority, has attachments
       
  2539 				{
       
  2540 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2541 					{
       
  2542 					textureId = EMessageReadRepliedHighPrioIconAttachment;
       
  2543 					}
       
  2544 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2545 					{
       
  2546 					textureId = EMessageReadForwardedHighPrioIconAttachment;
       
  2547 					}
       
  2548 				else
       
  2549 					{
       
  2550 					textureId = EMessageHighPrioReadIconAttachment;
       
  2551 					}
       
  2552 				}
       
  2553 			else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Low ) ) // Low priority, has attachments
       
  2554 				{
       
  2555 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2556 					{
       
  2557 					textureId = EMessageReadRepliedLowPrioIconAttachment;
       
  2558 					}
       
  2559 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2560 					{
       
  2561 					textureId = EMessageReadForwardedLowPrioIconAttachment;
       
  2562 					}
       
  2563 				else
       
  2564 					{
       
  2565 					textureId = EMessageLowPrioReadIconAttachment;
       
  2566 					}
       
  2567 				}
       
  2568 			else // Normal priority, has attachments
       
  2569 				{
       
  2570 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2571 					{
       
  2572 					textureId = EMessageReadRepliedIconAttachment;
       
  2573 					}
       
  2574 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2575 					{
       
  2576 					textureId = EMessageReadForwardedIconAttachment;
       
  2577 					}
       
  2578 				else
       
  2579 					{
       
  2580 					textureId = EMessageReadIconAttachment;
       
  2581 					}
       
  2582 				}
       
  2583 			}
       
  2584 		else // No attachments
       
  2585 			{
       
  2586 			if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Important )) // High priority, no attachments
       
  2587 				{
       
  2588 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2589 					{
       
  2590 					textureId = EMessageReadRepliedHighPrioIcon;
       
  2591 					}
       
  2592 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2593 					{
       
  2594 					textureId = EMessageReadForwardedHighPrioIcon;
       
  2595 					}
       
  2596 				else
       
  2597 					{
       
  2598 					textureId = EMessageHighPrioReadIcon;
       
  2599 					}
       
  2600 				}
       
  2601 			else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Low ) ) // Low priority, no attachments
       
  2602 				{
       
  2603 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2604 					{
       
  2605 					textureId = EMessageReadRepliedLowPrioIcon;
       
  2606 					}
       
  2607 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2608 					{
       
  2609 					textureId = EMessageReadForwardedLowPrioIcon;
       
  2610 					}
       
  2611 				else
       
  2612 					{
       
  2613 					textureId = EMessageLowPrioReadIcon;
       
  2614 					}
       
  2615 				}
       
  2616 			else // Normal priority, no attachments
       
  2617 				{
       
  2618 				if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Answered ) )
       
  2619 					{
       
  2620 					textureId = EMessageReadRepliedIcon;
       
  2621 					}
       
  2622 				else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
  2623 					{
       
  2624 					textureId = EMessageReadForwardedIcon;
       
  2625 					}
       
  2626 				else
       
  2627 					{
       
  2628 					textureId = EMessageReadIcon;
       
  2629 					}
       
  2630 				}
       
  2631 			}
       
  2632 		}
       
  2633 	return textureId;
       
  2634 	}
       
  2635 
       
  2636 // <cmail>
       
  2637 // -----------------------------------------------------------------------------
       
  2638 // TFsEmailUiUtility::IsMrCancellationMsgL
       
  2639 // -----------------------------------------------------------------------------
       
  2640 TBool TFsEmailUiUtility::IsMrCancellationMsgL( CFSMailMessage* aMsgPtr )
       
  2641     {
       
  2642     FUNC_LOG;
       
  2643     TBool isCancel = EFalse;
       
  2644 
       
  2645     if ( !iMrViewer )
       
  2646         {
       
  2647         if ( !iMrViewerCallback )
       
  2648             {
       
  2649             iMrViewerCallback = new (ELeave) CMrViewerEmptyCallback;
       
  2650             }
       
  2651         iMrViewer = CESMRIcalViewer::NewL( *iMrViewerCallback );
       
  2652         }
       
  2653 
       
  2654     TESMRMeetingRequestMethod method = iMrViewer->ResolveMeetingRequestMethodL(*aMsgPtr);
       
  2655     if ( method == EESMRMeetingRequestMethodCancellation )
       
  2656         {
       
  2657         isCancel = ETrue;
       
  2658         }
       
  2659 
       
  2660     return isCancel;
       
  2661     }
       
  2662 // </cmail>
       
  2663 
       
  2664 // -----------------------------------------------------------------------------
       
  2665 // TFsEmailUiUtility::CopyToClipboardL
       
  2666 // -----------------------------------------------------------------------------
       
  2667 void TFsEmailUiUtility::CopyToClipboardL( const TDesC &aBuf )
       
  2668 	{
       
  2669     FUNC_LOG;
       
  2670 	CClipboard* cb = CClipboard::NewForWritingLC( CCoeEnv::Static()->FsSession() );
       
  2671 
       
  2672 	cb->StreamDictionary().At( KClipboardUidTypePlainText );
       
  2673 
       
  2674 	CPlainText* plainText = CPlainText::NewL();
       
  2675 	CleanupStack::PushL( plainText );
       
  2676 
       
  2677 	plainText->InsertL( 0 , aBuf );
       
  2678 
       
  2679 	plainText->CopyToStoreL( cb->Store(), cb->StreamDictionary(), 0, plainText->DocumentLength() );
       
  2680 
       
  2681 	CleanupStack::PopAndDestroy( plainText );
       
  2682 	cb->CommitL();
       
  2683 	CleanupStack::PopAndDestroy( cb );
       
  2684 	}
       
  2685 
       
  2686 // -----------------------------------------------------------------------------
       
  2687 // TFsEmailUiUtility::ToggleEmailIconL
       
  2688 // -----------------------------------------------------------------------------
       
  2689 void TFsEmailUiUtility::ToggleEmailIconL(TBool aIconOn )
       
  2690 	{
       
  2691     FUNC_LOG;
       
  2692 	if(aIconOn)
       
  2693 		{
       
  2694 		RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsNewEmailStatus, ECoreAppUIsNewEmail );
       
  2695 		}
       
  2696 	else
       
  2697 		{
       
  2698 		RProperty::Set( KPSUidCoreApplicationUIs, KCoreAppUIsNewEmailStatus, ECoreAppUIsNoNewEmail );
       
  2699 		}
       
  2700 	}
       
  2701 
       
  2702 // -----------------------------------------------------------------------------
       
  2703 // TFsEmailUiUtility::DisplayMsgsMovedNoteL
       
  2704 // -----------------------------------------------------------------------------
       
  2705 void TFsEmailUiUtility::DisplayMsgsMovedNoteL( TInt aMsgCount, const TFSMailMsgId aDestinationFolderId,
       
  2706 										   	   TBool /*aIsWaitingNote*/ )
       
  2707 	{
       
  2708     FUNC_LOG;
       
  2709 	if ( aDestinationFolderId.Id() != 0 )
       
  2710 		{
       
  2711 		CFreestyleEmailUiAppUi* appUi = (CFreestyleEmailUiAppUi*)CCoeEnv::Static()->AppUi();
       
  2712 		CFSMailFolder* folder = appUi->GetMailClient()->GetFolderByUidL( appUi->GetActiveMailboxId(), aDestinationFolderId );
       
  2713 		if ( folder )
       
  2714 			{
       
  2715 			CleanupStack::PushL( folder );
       
  2716 			HBufC* folderName(0);
       
  2717 			TInt folderType = folder->GetFolderType();
       
  2718 			switch ( folderType )
       
  2719 				{
       
  2720 				case EFSInbox:
       
  2721 					{
       
  2722 					folderName = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FOLDER_LIST_INBOX );
       
  2723 					}
       
  2724 					break;
       
  2725 				case EFSOutbox:
       
  2726 					{
       
  2727 					folderName = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FOLDER_LIST_OUTBOX );
       
  2728 					}
       
  2729 					break;
       
  2730 				case EFSDraftsFolder:
       
  2731 					{
       
  2732 					folderName = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FOLDER_LIST_DRAFTS );
       
  2733 					}
       
  2734 					break;
       
  2735 				case EFSSentFolder:
       
  2736 					{
       
  2737 					folderName = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FOLDER_LIST_SENT );
       
  2738 					}
       
  2739 					break;
       
  2740 				case EFSDeleted:
       
  2741 					{
       
  2742 					folderName = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FOLDER_LIST_DELETED );
       
  2743 					}
       
  2744 					break;
       
  2745 				default:
       
  2746 					{
       
  2747 					folderName = HBufC::NewLC( folder->GetFolderName().Length() );
       
  2748 					folderName->Des().Append( folder->GetFolderName() );
       
  2749 					}
       
  2750 					break;
       
  2751 				}
       
  2752 			if ( aMsgCount == 1)
       
  2753 				{
       
  2754 				HBufC* noteText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_MESSAGE_TO_FOLDER, *folderName  );
       
  2755 				// <cmail> replace global note with aknnote to allow exiting with red key
       
  2756 			    //CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
       
  2757 			    //globalNote->ShowNoteL( EAknGlobalInformationNote, *noteText );
       
  2758             	CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
  2759             	note->ExecuteLD( *noteText );
       
  2760             	CleanupStack::PopAndDestroy( noteText );
       
  2761 			    //CleanupStack::PopAndDestroy( 2 );
       
  2762 			    // </cmail>
       
  2763 				}
       
  2764 			else if ( aMsgCount > 1 )
       
  2765 				{
       
  2766 				HBufC* noteText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_MESSAGES_TO_FOLDER, *folderName, aMsgCount );
       
  2767 			    // <cmail> replace global note with aknnote to allow exiting with red key
       
  2768 			    //CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
       
  2769 			    //globalNote->ShowNoteL( EAknGlobalInformationNote, *noteText );
       
  2770             	CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
  2771             	note->ExecuteLD( *noteText );
       
  2772             	CleanupStack::PopAndDestroy( noteText );
       
  2773 			    // CleanupStack::PopAndDestroy( 2 );
       
  2774 			    // </cmail>
       
  2775 				}
       
  2776 			CleanupStack::PopAndDestroy( folderName );
       
  2777 			CleanupStack::PopAndDestroy( folder );
       
  2778 			}
       
  2779 		}
       
  2780 	}
       
  2781 
       
  2782 // ---------------------------------------------------------------------------
       
  2783 // TFsEmailUiUtility::IsOfflineModeL
       
  2784 // ---------------------------------------------------------------------------
       
  2785 //
       
  2786 TBool TFsEmailUiUtility::IsOfflineModeL()
       
  2787     {
       
  2788     FUNC_LOG;
       
  2789     TBool isOffline( EFalse );
       
  2790     TInt status( ECoreAppUIsNetworkConnectionAllowed );
       
  2791 
       
  2792     CRepository* cenRep = CRepository::NewL( KCRUidCoreApplicationUIs );
       
  2793     if ( cenRep )
       
  2794         {
       
  2795         cenRep->Get( KCoreAppUIsNetworkConnectionAllowed, status );
       
  2796         }
       
  2797     delete cenRep;
       
  2798 
       
  2799     if ( status == ECoreAppUIsNetworkConnectionNotAllowed )
       
  2800 	    {
       
  2801 	    isOffline = ETrue;
       
  2802 	    }
       
  2803 
       
  2804     return isOffline;
       
  2805     }
       
  2806 
       
  2807 // ---------------------------------------------------------------------------
       
  2808 // TFsEmailUiUtility::StripDisplayName
       
  2809 // Drop out unwanted characters from display name such as <> and ""
       
  2810 // ---------------------------------------------------------------------------
       
  2811 void TFsEmailUiUtility::StripDisplayName( HBufC& aDisplayName )
       
  2812 	{
       
  2813     FUNC_LOG;
       
  2814 	// Drop out unwanted chars from display name
       
  2815 	if ( aDisplayName.Length() > 2)
       
  2816 		{
       
  2817 		// Drop out <> and "" characters.
       
  2818 		if ( aDisplayName.Locate('"') == 0 ) // check if  first char is quation mark
       
  2819 			{
       
  2820 			if ( aDisplayName.LocateReverse('"') == aDisplayName.Length()-1 ) // last char
       
  2821 				{
       
  2822 				// Remove first and last
       
  2823 				aDisplayName.Des().Delete(0,1);
       
  2824 				aDisplayName.Des().Delete(aDisplayName.Length()-1,1);
       
  2825 				}
       
  2826 			}
       
  2827 		else if ( aDisplayName.Locate('<') == 0 ) // Else check if first char is bracket
       
  2828 			{
       
  2829 			if ( aDisplayName.LocateReverse('>') == aDisplayName.Length()-1 ) // last char bracket
       
  2830 				{
       
  2831 				// Remove first and last
       
  2832 				aDisplayName.Des().Delete(0,1);
       
  2833 				aDisplayName.Des().Delete(aDisplayName.Length()-1,1);
       
  2834 				}
       
  2835 			}
       
  2836 		}
       
  2837 	}
       
  2838 
       
  2839 // ---------------------------------------------------------------------------
       
  2840 // TFsEmailUiUtility::DisplayCreateMailboxQueryL
       
  2841 // @return ETrue if user answered "Yes", EFalse if user answered "No"
       
  2842 // ---------------------------------------------------------------------------
       
  2843 //
       
  2844 TBool TFsEmailUiUtility::DisplayCreateMailboxQueryL()
       
  2845     {
       
  2846     FUNC_LOG;
       
  2847     // load text from resource
       
  2848     HBufC* question = StringLoader::LoadLC( R_FS_EMAIL_SETTINGS_ADD_MAILBOX_TXT );
       
  2849 
       
  2850     // show dialog
       
  2851     TRequestStatus status = KRequestPending;
       
  2852     CAknGlobalConfirmationQuery* query = CAknGlobalConfirmationQuery::NewL();
       
  2853     CleanupStack::PushL( query );
       
  2854     query->ShowConfirmationQueryL( status, *question, R_AVKON_SOFTKEYS_YES_NO );
       
  2855     User::WaitForRequest( status );
       
  2856 
       
  2857     CleanupStack::PopAndDestroy( 2 ); // query question
       
  2858 
       
  2859     return ( status.Int() == EAknSoftkeyYes );
       
  2860     }
       
  2861 
       
  2862 // -----------------------------------------------------------------------------
       
  2863 // TFsEmailUiUtility::BringFsEmailToForeground
       
  2864 // -----------------------------------------------------------------------------
       
  2865 //
       
  2866 void TFsEmailUiUtility::BringFsEmailToForeground()
       
  2867     {
       
  2868     FUNC_LOG;
       
  2869     TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
       
  2870     TApaTask task = taskList.FindApp( KFSEmailUiUid );
       
  2871     if ( task.Exists() )
       
  2872         {
       
  2873         task.BringToForeground();
       
  2874         }
       
  2875     }
       
  2876 
       
  2877 // -----------------------------------------------------------------------------
       
  2878 // Creates a displayname of firstname and lastname components
       
  2879 // -----------------------------------------------------------------------------
       
  2880 //
       
  2881 HBufC* TFsEmailUiUtility::CreateDisplayNameLC( const TDesC& aFirstname,
       
  2882     const TDesC& aLastname )
       
  2883     {
       
  2884     FUNC_LOG;
       
  2885     return CreateDisplayNameLC( aFirstname, aLastname, KNullDesC );
       
  2886     }
       
  2887 
       
  2888 // -----------------------------------------------------------------------------
       
  2889 // TFsEmailUiUtility::CreateDisplayNameLC
       
  2890 // -----------------------------------------------------------------------------
       
  2891 //
       
  2892 HBufC* TFsEmailUiUtility::CreateDisplayNameLC( const TDesC& aFirstname,
       
  2893     const TDesC& aLastname, const TDesC& aEmailField )
       
  2894 	{
       
  2895     FUNC_LOG;
       
  2896 	HBufC* displayname = NULL;
       
  2897 
       
  2898 	if ( aFirstname.Length() == 0 )
       
  2899 		{
       
  2900 		if ( aLastname.Length() == 0 )
       
  2901 			{
       
  2902 			//There's just the email address for Displayname
       
  2903 			displayname = aEmailField.AllocLC();
       
  2904 			}
       
  2905 		else
       
  2906 			{
       
  2907 			//Lastname = displayname
       
  2908 			displayname = aLastname.AllocLC();
       
  2909 			}
       
  2910 		}
       
  2911 
       
  2912 	else if ( aLastname.Length() == 0 )
       
  2913 		{
       
  2914 		//Firstname = displayname
       
  2915 		displayname = aFirstname.AllocLC();
       
  2916 		}
       
  2917 
       
  2918 	else
       
  2919 		{
       
  2920 		//Displayname = "firstname lastname"
       
  2921 		displayname = HBufC::NewLC( aFirstname.Length() +
       
  2922 									KSpace().Length() +
       
  2923 									aLastname.Length() );
       
  2924 		displayname->Des().Copy( aFirstname );
       
  2925 		displayname->Des().Append( KSpace );
       
  2926 		displayname->Des().Append( aLastname );
       
  2927 		}
       
  2928 
       
  2929 	return displayname;
       
  2930 	}
       
  2931 
       
  2932 // -----------------------------------------------------------------------------
       
  2933 // TFsEmailUiUtility::GetFullIconFileNameL
       
  2934 // -----------------------------------------------------------------------------
       
  2935 void TFsEmailUiUtility::GetFullIconFileNameL( TDes& aFileName )
       
  2936     {
       
  2937     FUNC_LOG;
       
  2938     aFileName.Zero();
       
  2939     aFileName.Copy( KDC_APP_BITMAP_DIR );
       
  2940     aFileName.Append( KFsEmailIconFileName );
       
  2941     User::LeaveIfError( CompleteWithAppPath( aFileName ) );
       
  2942     }
       
  2943 
       
  2944 // -----------------------------------------------------------------------------
       
  2945 // TFsEmailUiUtility::DoFileExtensionsMatchL
       
  2946 // -----------------------------------------------------------------------------
       
  2947 TBool TFsEmailUiUtility::DoFileExtensionsMatchL( const TDesC& aFileName1,
       
  2948                                                  const TDesC& aFileName2 )
       
  2949     {
       
  2950     FUNC_LOG;
       
  2951     TParse parse1;
       
  2952     TParse parse2;
       
  2953 
       
  2954     parse1.Set( aFileName1, NULL, NULL );
       
  2955     parse2.Set( aFileName2, NULL, NULL );
       
  2956 
       
  2957     HBufC* ext1 = parse1.Ext().AllocLC();
       
  2958     HBufC* ext2 = parse2.Ext().AllocLC();
       
  2959 
       
  2960     ext1->Des().LowerCase();
       
  2961     ext2->Des().LowerCase();
       
  2962 
       
  2963     TBool match = (*ext1 == *ext2);
       
  2964 
       
  2965     CleanupStack::PopAndDestroy( ext2 );
       
  2966     CleanupStack::PopAndDestroy( ext1 );
       
  2967 
       
  2968     return match;
       
  2969     }
       
  2970 
       
  2971 // -----------------------------------------------------------------------------
       
  2972 // TFsEmailUiUtility::CopyFileToTempDirL
       
  2973 // Makes a copy of given file to the temp directory of FsEmailUI.
       
  2974 // Caller is reponsible of closing the returned file handle.
       
  2975 // -----------------------------------------------------------------------------
       
  2976 RFile TFsEmailUiUtility::CopyFileToTempDirL( const RFile& aSourceFile,
       
  2977                                              const TDesC& aTargetFileName )
       
  2978     {
       
  2979     FUNC_LOG;
       
  2980     RFs fs( CEikonEnv::Static()->FsSession() );
       
  2981 
       
  2982     // Remove any illegal characters from the target file name
       
  2983     TFileName targetFileName = aTargetFileName.Right( KMaxFileName ); // truncate just in case; make sure that any file extension remains
       
  2984     _LIT( KIllegalCharacters, "*?\\<>:\"/|\r\n\t\x2028\x2029" );
       
  2985     const TText KReplacementChar = '_';
       
  2986     AknTextUtils::ReplaceCharacters( targetFileName, KIllegalCharacters, KReplacementChar );
       
  2987     targetFileName.Trim();
       
  2988     // File name can't begin nor end with dot (.) and cannot be empty
       
  2989     if ( !targetFileName.Length() )
       
  2990         {
       
  2991         targetFileName.Append( KReplacementChar );
       
  2992         }
       
  2993     else
       
  2994         {
       
  2995         if ( targetFileName[0] == '.' )
       
  2996             {
       
  2997             targetFileName[0] = KReplacementChar;
       
  2998             }
       
  2999         if ( targetFileName[ targetFileName.Length()-1 ] == '.' )
       
  3000             {
       
  3001             targetFileName[ targetFileName.Length()-1 ] = KReplacementChar;
       
  3002             }
       
  3003         }
       
  3004 
       
  3005     // If we still couldn't create a legal name, then use the original name as fallback solution
       
  3006     if ( !fs.IsValidName( targetFileName ) )
       
  3007         {
       
  3008         aSourceFile.Name( targetFileName );
       
  3009         }
       
  3010 
       
  3011     // Construct target file full name
       
  3012     TFileName targetFilePath;
       
  3013     GetTempPathL( fs, targetFilePath );
       
  3014     targetFilePath.Append( targetFileName );
       
  3015 
       
  3016     CFileMan* fileMan = CFileMan::NewL( fs );
       
  3017     TInt err = fileMan->Copy( aSourceFile, targetFilePath );
       
  3018     delete fileMan;
       
  3019     // KErrInUse ignoring check is needed because copying might not succeed
       
  3020     // if file already exists and handle remains open.
       
  3021     if ( err != KErrNone && err != KErrInUse )
       
  3022         {
       
  3023         User::LeaveIfError( err );
       
  3024         }
       
  3025 
       
  3026     // Open the copied file
       
  3027     RFile resultFile;
       
  3028     err = resultFile.Open( fs, targetFilePath, EFileRead | EFileShareReadersOnly );
       
  3029     User::LeaveIfError( err );
       
  3030 
       
  3031     return resultFile;
       
  3032     }
       
  3033 
       
  3034 // -----------------------------------------------------------------------------
       
  3035 // TFsEmailUiUtility::EraseTempDir
       
  3036 // Deletes all files from our temporary directory
       
  3037 // -----------------------------------------------------------------------------
       
  3038 void TFsEmailUiUtility::EraseTempDir()
       
  3039     {
       
  3040     FUNC_LOG;
       
  3041     RFs fs( CEikonEnv::Static()->FsSession() );
       
  3042 
       
  3043     TFileName deleteNamePattern;
       
  3044     TRAPD( err, GetTempPathL( fs, deleteNamePattern ) );
       
  3045     if ( !err )
       
  3046         {
       
  3047         deleteNamePattern.Append( '*' );
       
  3048         BaflUtils::DeleteFile( fs, deleteNamePattern );
       
  3049         }
       
  3050     }
       
  3051 
       
  3052 // -----------------------------------------------------------------------------
       
  3053 // TFsEmailUiUtility::GetTempPathL
       
  3054 // Get EmailUI temp directory path. Creates the directory if it does not exist.
       
  3055 // -----------------------------------------------------------------------------
       
  3056 void TFsEmailUiUtility::GetTempPathL( RFs& aFs, TDes& aPath )
       
  3057     {
       
  3058     FUNC_LOG;
       
  3059     _LIT( KDriveCPath, "C:" );
       
  3060 
       
  3061     TInt err = aFs.PrivatePath( aPath );
       
  3062     User::LeaveIfError( err );
       
  3063 
       
  3064     aPath.Insert( 0, KDriveCPath );
       
  3065     aPath.Append( KFsEmailTempDirName );
       
  3066     BaflUtils::EnsurePathExistsL( aFs, aPath );
       
  3067     }
       
  3068 
       
  3069 // -----------------------------------------------------------------------------
       
  3070 // TFsEmailUiUtility::EnsureFsMailServerIsRunning
       
  3071 // Checks if FSMailServer is running. If not, then launches it.
       
  3072 // -----------------------------------------------------------------------------
       
  3073 void TFsEmailUiUtility::EnsureFsMailServerIsRunning( RWsSession& aWsSession )
       
  3074     {
       
  3075     FUNC_LOG;
       
  3076     TRAP_IGNORE( EnsureFsMailServerIsRunningL( aWsSession ) );
       
  3077     }
       
  3078 
       
  3079 // -----------------------------------------------------------------------------
       
  3080 // TFsEmailUiUtility::EnsureFsMailServerIsRunningL
       
  3081 // Checks if FSMailServer is running. If not, then launches it.
       
  3082 // -----------------------------------------------------------------------------
       
  3083 void TFsEmailUiUtility::EnsureFsMailServerIsRunningL( RWsSession& aWsSession )
       
  3084     {
       
  3085     FUNC_LOG;
       
  3086 
       
  3087     TApaTaskList taskList( aWsSession );
       
  3088     TApaTask task = taskList.FindApp( KFSMailServerUid );
       
  3089 
       
  3090     if ( !task.Exists() )
       
  3091         {
       
  3092         // FSMailServer is not running, try to launch it
       
  3093 
       
  3094         // Get this process' file name to get the correct drive letter
       
  3095         RProcess process;
       
  3096         TFileName processFileName = process.FileName();
       
  3097         process.Close();
       
  3098 
       
  3099         // Parse the full path to FSMailServer exe
       
  3100         TParse parse;
       
  3101         User::LeaveIfError( parse.Set( KFSMailServerExe, &processFileName, NULL) );
       
  3102 
       
  3103         // Store the full path
       
  3104         processFileName = parse.FullName();
       
  3105 
       
  3106         CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
  3107         cmdLine->SetExecutableNameL( processFileName );
       
  3108         // Launch FSMailServer in background so that it doesn't steal
       
  3109         // the focus during it's construction
       
  3110         cmdLine->SetCommandL( EApaCommandBackground );
       
  3111 
       
  3112         RApaLsSession ls;
       
  3113         User::LeaveIfError( ls.Connect() );
       
  3114         CleanupClosePushL( ls );
       
  3115 
       
  3116         TThreadId threadId;
       
  3117         // Is there anything we can do in case of error?
       
  3118         //       Try to launch from another drive etc.?
       
  3119         TInt error = ls.StartApp( *cmdLine, threadId );
       
  3120 
       
  3121         CleanupStack::PopAndDestroy( &ls );
       
  3122         CleanupStack::PopAndDestroy( cmdLine );
       
  3123         }
       
  3124     }
       
  3125 
       
  3126 
       
  3127 
       
  3128 /////////////////////////////////////////////////////////////////////////////////
       
  3129 // ACTION MENU HANDLER
       
  3130 //
       
  3131 
       
  3132 //Singleton* Singleton::pinstance = 0;
       
  3133 // Initialize static member variables
       
  3134 CFscContactActionMenu* CFSEmailUiActionMenu::iActionMenu = NULL;
       
  3135 TFileName CFSEmailUiActionMenu::iIconFilePath;
       
  3136 RPointerArray<CGulIcon> CFSEmailUiActionMenu::iIconArray;
       
  3137 
       
  3138 CFSEmailUiActionMenu* CFSEmailUiActionMenu::NewL( CFreestyleEmailUiAppUi* aAppUi )
       
  3139 	{
       
  3140     FUNC_LOG;
       
  3141     CFSEmailUiActionMenu* self = new (ELeave) CFSEmailUiActionMenu( aAppUi );
       
  3142     CleanupStack::PushL( self );
       
  3143     self->ConstructL();
       
  3144     CleanupStack::Pop( self );
       
  3145     return self;
       
  3146 	}
       
  3147 
       
  3148 CFSEmailUiActionMenu::CFSEmailUiActionMenu( CFreestyleEmailUiAppUi* aAppUi )
       
  3149 	: iAppUi( aAppUi )
       
  3150 	{
       
  3151 
       
  3152 	}
       
  3153 
       
  3154 CFSEmailUiActionMenu::~CFSEmailUiActionMenu()
       
  3155 	{
       
  3156     FUNC_LOG;
       
  3157 	if( iActionMenu )
       
  3158 		{
       
  3159 		delete iActionMenu;
       
  3160 		}
       
  3161 	if ( iService )
       
  3162 		{
       
  3163 		delete iService;
       
  3164 		}
       
  3165 	iIconArray.ResetAndDestroy();
       
  3166 	}
       
  3167 
       
  3168 void CFSEmailUiActionMenu::ConstructL()
       
  3169 	{
       
  3170     FUNC_LOG;
       
  3171     if( !iActionMenu )
       
  3172         {
       
  3173         iService = CFscContactActionService::NewL( iAppUi->GetVPbkManagerL() );
       
  3174         iActionMenu = CFscContactActionMenu::NewL( *iService );
       
  3175         }
       
  3176     TFsEmailUiUtility::GetFullIconFileNameL( iIconFilePath );
       
  3177 	}
       
  3178 
       
  3179 CFscContactActionMenu* CFSEmailUiActionMenu::GetActionMenu()
       
  3180 	{
       
  3181 	return iActionMenu;
       
  3182 	}
       
  3183 
       
  3184 void CFSEmailUiActionMenu::RemoveAllL()
       
  3185 	{
       
  3186     FUNC_LOG;
       
  3187     if ( iIconArray.Count() == 0 )
       
  3188         {
       
  3189         CreateIconsL();
       
  3190         }
       
  3191 	iActionMenu->Model().RemoveAll( ETrue );
       
  3192 	}
       
  3193 
       
  3194 void CFSEmailUiActionMenu::AddCustomItemL( TActionMenuCustomItemId aItemId )
       
  3195 	{
       
  3196     FUNC_LOG;
       
  3197     if ( iIconArray.Count() == 0 )
       
  3198         {
       
  3199         CreateIconsL();
       
  3200         }
       
  3201 	HBufC* itemText = NULL;
       
  3202 	CGulIcon* itemIcon = iIconArray[aItemId-1];
       
  3203 	switch( aItemId )
       
  3204 		{
       
  3205 		case FsEActionMenuOpen:
       
  3206 			{
       
  3207 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_OPEN );
       
  3208 			}
       
  3209 			break;
       
  3210 		case FsEActionMenuOpenCalendarEvent:
       
  3211 			{
       
  3212 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_OPEN );
       
  3213 			}
       
  3214 			break;
       
  3215 		case FsEActionMenuReply:
       
  3216 			{
       
  3217 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_REPLY );
       
  3218 			}
       
  3219 			break;
       
  3220 
       
  3221 		case FsEActionMenuReplyAll:
       
  3222 			{
       
  3223 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_REPLY_ALL );
       
  3224 			}
       
  3225 			break;
       
  3226 
       
  3227 		case FsEActionMenuForward:
       
  3228 			{
       
  3229 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_FORWARD );
       
  3230 			}
       
  3231 			break;
       
  3232 
       
  3233 		case FsEActionMenuDelete:
       
  3234 			{
       
  3235 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_DELETE );
       
  3236 			}
       
  3237 			break;
       
  3238 
       
  3239 		case FsEActionMenuAccept:
       
  3240 			{
       
  3241 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ACCEPT );
       
  3242 			}
       
  3243 			break;
       
  3244 
       
  3245 		case FsEActionMenuTentative:
       
  3246 			{
       
  3247 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_TENTATIVE );
       
  3248 			}
       
  3249 			break;
       
  3250 
       
  3251 		case FsEActionMenuDecline:
       
  3252 			{
       
  3253 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_DECLINE );
       
  3254 			}
       
  3255 			break;
       
  3256 
       
  3257 		case FsEActionMenuRemoveFormCal:
       
  3258 			{
       
  3259 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_REM_FROM_CAL );
       
  3260 			}
       
  3261 			break;
       
  3262 
       
  3263 		case FsEActionMenuMarkRead:
       
  3264 			{
       
  3265 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_MARK_READ );
       
  3266 			}
       
  3267 			break;
       
  3268 
       
  3269 		case FsEActionMenuMarkUnread:
       
  3270 			{
       
  3271 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_MARK_UNREAD );
       
  3272 			}
       
  3273 			break;
       
  3274 
       
  3275 		case FsEActionMenuCall:
       
  3276 			{
       
  3277 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_CALL );
       
  3278 			}
       
  3279 			break;
       
  3280         // <cmail> video call
       
  3281         case FsEActionMenuCallVideo:
       
  3282             {
       
  3283             itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_CALL_VIDEO );
       
  3284             }
       
  3285             break;
       
  3286         // </cmail>
       
  3287 		case FsEActionMenuCreateMessage:
       
  3288 			{
       
  3289 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_CREATE_MESSAGE );
       
  3290 			}
       
  3291 			break;
       
  3292 		case FsEActionMenuCreateEmail:
       
  3293 		    {
       
  3294             itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_CREATE_EMAIL );
       
  3295 		    }
       
  3296 			break;
       
  3297 		case FsEActionMenuContactDetails:
       
  3298 			{
       
  3299 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_CONTACT_DETAILS );
       
  3300 			}
       
  3301 			break;
       
  3302 
       
  3303 		case FsEActionMenuAddToContacts:
       
  3304 			{
       
  3305 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ADD_TO_CONTACTS );
       
  3306 			}
       
  3307 			break;
       
  3308 
       
  3309 		case FsEActionMenuRemoteLookup:
       
  3310 			{
       
  3311 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_REMOTE_LOOKUP );
       
  3312 			}
       
  3313 			break;
       
  3314 
       
  3315 		case FsEActionMenuMove:
       
  3316 			{
       
  3317 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_MOVE );
       
  3318 			}
       
  3319 			break;
       
  3320 
       
  3321 		case FsEActionMenuMoveToDrafts:
       
  3322 			{
       
  3323 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_MOVE_TO_DRAFTS );
       
  3324 			}
       
  3325 			break;
       
  3326 		case FsEActionMenuOpenInWeb:
       
  3327 			{
       
  3328 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_OPEN_IN_WEB );
       
  3329 			}
       
  3330 			break;
       
  3331 		case FsEActionMenuOpenInIntranet:
       
  3332 			{
       
  3333 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_OPEN_IN_INTRA );
       
  3334 			}
       
  3335 			break;
       
  3336 		case FsEActionMenuBookmark:
       
  3337 			{
       
  3338 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_BOOKMARK );
       
  3339 			}
       
  3340 			break;
       
  3341 		case FsEActionAttachmentOpen:
       
  3342 			{
       
  3343 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_OPEN );
       
  3344 			}
       
  3345 			break;
       
  3346 		case FsEActionAttachmentDownload:
       
  3347 			{
       
  3348 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_DOWNLOAD );
       
  3349 			}
       
  3350 			break;
       
  3351 		case FsEActionAttachmentCancelDownload:
       
  3352 			{
       
  3353 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_CANCEL );
       
  3354 			}
       
  3355 			break;
       
  3356 		case FsEActionAttachmentSave:
       
  3357 			{
       
  3358 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_SAVE );
       
  3359 			}
       
  3360 			break;
       
  3361         case FsEActionAttachmentAdd:
       
  3362             {
       
  3363             itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_ADD );
       
  3364             }
       
  3365             break;
       
  3366         case FsEActionAttachmentRemove:
       
  3367             {
       
  3368             itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_REMOVE );
       
  3369             }
       
  3370             break;
       
  3371         case FsEActionAttachmentViewAll:
       
  3372             {
       
  3373             itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_VIEW_ALL );
       
  3374             }
       
  3375             break;
       
  3376 		case FsEActionAttachmentDownloadAll:
       
  3377 			{
       
  3378 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_DOWNLOAD_ALL );
       
  3379 			}
       
  3380 			break;
       
  3381 
       
  3382 		case FsEActionAttachmentCancelAllDownloads:
       
  3383 			{
       
  3384 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_CANCEL_ALL );
       
  3385 			}
       
  3386 			break;
       
  3387 		case FsEActionAttachmentSaveAll:
       
  3388 			{
       
  3389 			itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_SAVE_ALL );
       
  3390 			}
       
  3391 			break;
       
  3392 		case FsEActionAttachmentRemoveAll:
       
  3393             {
       
  3394             itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_REMOVE_ALL );
       
  3395             }
       
  3396             break;
       
  3397 		case FsEActionAttachmentClearFetchedContent:
       
  3398 		    {
       
  3399 		    itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_CLEAR_FETCHED );
       
  3400 		    }
       
  3401 		    break;
       
  3402 		case FsEActionAttachmentRemoveUnfetchedAttachment:
       
  3403 		    {
       
  3404 		    itemText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_AM_ATTACH_REMOVE_UNFETCHED );
       
  3405 		    }
       
  3406 		    break;
       
  3407 		default:
       
  3408 		    {
       
  3409 		    itemText = KNullDesC().AllocLC();
       
  3410 		    }
       
  3411 			break;
       
  3412 		}
       
  3413 
       
  3414 	TUid itemUid;
       
  3415 	itemUid.iUid = TInt(aItemId);
       
  3416 
       
  3417     CleanupStack::PushL( itemIcon );
       
  3418 	CFscContactActionMenuItem* menuItem = iActionMenu->Model().NewMenuItemL( *itemText, itemIcon, KActionMenuItemNormalPriority, EFalse, itemUid);
       
  3419     CleanupStack::PushL( menuItem );
       
  3420     iActionMenu->Model().AddItemL( menuItem );
       
  3421     CleanupStack::Pop( menuItem );
       
  3422     CleanupStack::Pop( itemIcon );
       
  3423     CleanupStack::PopAndDestroy( itemText );
       
  3424 	}
       
  3425 
       
  3426 void CFSEmailUiActionMenu::AddCustomItemsL( RFsEActionMenuIdList aItemList )
       
  3427 	{
       
  3428     FUNC_LOG;
       
  3429 	for( TInt i = 0; i < aItemList.Count(); i++ )
       
  3430 		{
       
  3431 		AddCustomItemL( aItemList[i] );
       
  3432 		}
       
  3433 	}
       
  3434 
       
  3435 // <cmail>
       
  3436 void CFSEmailUiActionMenu::Dismiss( TBool aSlide )
       
  3437     {
       
  3438     FUNC_LOG;
       
  3439     if( iActionMenu )
       
  3440         {
       
  3441         iActionMenu->Dismiss( aSlide );
       
  3442         }
       
  3443     }
       
  3444 // </cmail>
       
  3445 
       
  3446 TActionMenuCustomItemId CFSEmailUiActionMenu::ExecuteL(
       
  3447 	TFscContactActionMenuPosition aPosition,
       
  3448 	TInt aIndex,
       
  3449 	MFsActionMenuPositionGiver* aPositionGiver)
       
  3450 	{
       
  3451     FUNC_LOG;
       
  3452     if ( iIconArray.Count() == 0 )
       
  3453         {
       
  3454         CreateIconsL();
       
  3455         }
       
  3456 	TFscActionMenuResult menuResult = iActionMenu->ExecuteL( aPosition, aIndex, aPositionGiver );
       
  3457     if ( menuResult == EFscCustomItemSelected )
       
  3458     	{
       
  3459     	return ResolveSelectedCustomItemIdL();
       
  3460     	}
       
  3461     else if( menuResult == EFscCasItemSelectedAndExecuted )
       
  3462     	{
       
  3463     	return FsEActionMenuCasItemSelectedAndExecuted;
       
  3464     	}
       
  3465     else
       
  3466     	{
       
  3467     	return FsEActionMenuDismissed;
       
  3468     	}
       
  3469 	}
       
  3470 
       
  3471 TActionMenuCustomItemId CFSEmailUiActionMenu::ExecuteL(
       
  3472 	RFsEActionMenuIdList aItemList,
       
  3473 	TFscContactActionMenuPosition aPosition,
       
  3474 	TInt aIndex,
       
  3475 	MFsActionMenuPositionGiver* aPositionGiver)
       
  3476 	{
       
  3477     FUNC_LOG;
       
  3478     if ( iIconArray.Count() == 0 )
       
  3479         {
       
  3480         CreateIconsL();
       
  3481         }
       
  3482 	RemoveAllL();
       
  3483 	AddCustomItemsL( aItemList );
       
  3484 	return ExecuteL( aPosition, aIndex, aPositionGiver );
       
  3485 	}
       
  3486 // </cmail>
       
  3487 
       
  3488 
       
  3489 TActionMenuCustomItemId CFSEmailUiActionMenu::ResolveSelectedCustomItemIdL()
       
  3490 	{
       
  3491     FUNC_LOG;
       
  3492     if ( iIconArray.Count() == 0 )
       
  3493         {
       
  3494         CreateIconsL();
       
  3495         }
       
  3496 	TInt itemIndex = iActionMenu->FocusedItemIndex();
       
  3497 	TUid itemUid = iActionMenu->Model().ItemL( itemIndex ).ImplementationUid();
       
  3498 
       
  3499 	return TActionMenuCustomItemId( itemUid.iUid );
       
  3500 	}
       
  3501 
       
  3502 void CFSEmailUiActionMenu::CreateIconsL()
       
  3503 	{
       
  3504     FUNC_LOG;
       
  3505 	iIconArray.ResetAndDestroy();
       
  3506 
       
  3507 	// UPDATE ICONS!
       
  3508 // <cmail> icons changed
       
  3509 	// NOTE: Must be appended same order as are in TActionMenuCustomItemIds!
       
  3510  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_indi_cmail_read, EMbmFreestyleemailuiQgn_indi_cmail_read_mask ) ); // FsEActionMenuOpen
       
  3511   	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_indi_cmail_calendar_event_read, EMbmFreestyleemailuiQgn_indi_cmail_calendar_event_read_mask ) ); // FsEActionMenuOpen
       
  3512   	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_reply, EMbmFreestyleemailuiQgn_prop_cmail_action_reply_mask ) ); // FsEActionMenuReply
       
  3513  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_reply_all, EMbmFreestyleemailuiQgn_prop_cmail_action_reply_all_mask ) ); // FsEActionMenuReplyAll
       
  3514  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_forward, EMbmFreestyleemailuiQgn_prop_cmail_action_forward_mask ) ); // FsEActionMenuForward
       
  3515  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_delete, EMbmFreestyleemailuiQgn_prop_cmail_action_delete_mask ) ); // FsEActionMenuDelete
       
  3516  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_indi_cmail_calendar_tracking_accept, EMbmFreestyleemailuiQgn_indi_cmail_calendar_tracking_accept_mask  ) ); // FsEActionMenuAccept
       
  3517  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_indi_cmail_calendar_tracking_tentative, EMbmFreestyleemailuiQgn_indi_cmail_calendar_tracking_tentative_mask  ) ); // FsEActionMenuTentative
       
  3518  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_indi_cmail_calendar_tracking_reject, EMbmFreestyleemailuiQgn_indi_cmail_calendar_tracking_reject_mask ) ); // FsEActionMenuDecline
       
  3519  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_indi_cmail_calendar_delete, EMbmFreestyleemailuiQgn_indi_cmail_calendar_delete_mask ) ); // FsEActionMenuDecline
       
  3520  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_mark_read, EMbmFreestyleemailuiQgn_prop_cmail_action_mark_read_mask ) ); // FsEActionMenuMarkRead
       
  3521  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_mark_unread, EMbmFreestyleemailuiQgn_prop_cmail_action_mark_unread_mask ) ); // FsEActionMenuMarkUnread
       
  3522  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_call, EMbmFreestyleemailuiQgn_prop_cmail_action_call_mask ) ); // FsEActionMenuCall
       
  3523     // <cmail> video call
       
  3524     iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_call_video, EMbmFreestyleemailuiQgn_prop_cmail_action_call_video_mask ) ); // FsEActionMenuCallVideo
       
  3525     // </cmail>
       
  3526  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_create_msg, EMbmFreestyleemailuiQgn_prop_cmail_action_create_msg_mask ) ); // FsEActionMenuCreateMessage
       
  3527     iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_email,  EMbmFreestyleemailuiQgn_prop_cmail_action_email_mask) ); // FsEActionMenuCreateEmail
       
  3528  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_contact_detail, EMbmFreestyleemailuiQgn_prop_cmail_action_contact_detail_mask ) ); // FsEActionMenuContactDetails
       
  3529  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_add_to_contacts, EMbmFreestyleemailuiQgn_prop_cmail_action_add_to_contacts_mask ) ); // FsEActionMenuAddToContacts
       
  3530  	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_remote_lookup, EMbmFreestyleemailuiQgn_prop_cmail_action_remote_lookup_mask ) ); // FsEActionMenuRemoteLookup
       
  3531 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_move_msg, EMbmFreestyleemailuiQgn_prop_cmail_action_move_msg_mask ) ); // FsEActionMenuMove
       
  3532 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_move_to_drafts, EMbmFreestyleemailuiQgn_prop_cmail_action_move_to_drafts_mask  ) ); // FsEActionMenuMoveToDrafts
       
  3533 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_menu_browserng, EMbmFreestyleemailuiQgn_menu_browserng_mask ) ); // FsEActionMenuOpenInWeb
       
  3534 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_menu_intranet, EMbmFreestyleemailuiQgn_menu_intranet_mask ) ); // FsEActionMenuOpenInIntranet
       
  3535 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_wml_bookmark, EMbmFreestyleemailuiQgn_prop_cmail_wml_bookmark_mask ) ); // FsEActionMenuBookmark
       
  3536 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_open, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_open_mask ) ); // FsEActionAttachmentOpen
       
  3537 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_download, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_download_mask ) ); // FsEActionAttachmentDownload
       
  3538 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_cancel_download, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_cancel_download_mask ) ); // FsEActionAttachmentCancelDownload
       
  3539 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_save, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_save_mask ) ); // FsEActionAttachmentSave
       
  3540     iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_add, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_add_mask ) ); // FsEActionAttachmentAdd
       
  3541     iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_delete, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_delete_mask ) ); // FsEActionAttachmentRemove
       
  3542     iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_view_all, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_view_all_mask ) ); // FsEActionAttachmentViewAll
       
  3543 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_download_all, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_download_all_mask ) ); // FsEActionAttachmentDownloadAll
       
  3544 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_cancel_all, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_cancel_all_mask ) ); // FsEActionAttachmentCancelAllDownloads
       
  3545 	iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_save_all, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_save_all_mask ) ); // FsEActionAttachmentSaveAll
       
  3546     iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_delete_all, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_delete_all_mask ) ); // FsEActionAttachmentRemoveAll
       
  3547     iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_delete, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_delete_mask ) ); // FsEActionAttachmentClearFetchedContent
       
  3548     iIconArray.AppendL( CreateIconL( EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_delete, EMbmFreestyleemailuiQgn_prop_cmail_action_attachment_list_options_delete_mask ) ); // FsEActionAttachmentRemoveUnfetchedAttachment
       
  3549 // </cmail>
       
  3550 	}
       
  3551 
       
  3552 CGulIcon* CFSEmailUiActionMenu::CreateIconL( TInt aBitmapId, TInt aMaskId )
       
  3553 	{
       
  3554     FUNC_LOG;
       
  3555 	// Define default icon object
       
  3556     CFbsBitmap* iconBitmap;
       
  3557     CFbsBitmap* iconMaskBitmap;
       
  3558     TSize defaultIconSize(30,30);
       
  3559 
       
  3560 	// Create "CALL" Item
       
  3561     AknIconUtils::CreateIconLC(iconBitmap, iconMaskBitmap, iIconFilePath, aBitmapId, aMaskId );
       
  3562     AknIconUtils::SetSize(iconBitmap, defaultIconSize);
       
  3563     AknIconUtils::SetSize(iconMaskBitmap, defaultIconSize);
       
  3564     CGulIcon* icon = CGulIcon::NewL(iconBitmap, iconMaskBitmap);
       
  3565     CleanupStack::Pop(2);
       
  3566     return icon;
       
  3567 	}
       
  3568 
       
  3569 /////////////////////////////////////////////////////////////////////////////////
       
  3570 // GENERIC TIMER
       
  3571 //
       
  3572 
       
  3573 // -----------------------------------------------------------------------------
       
  3574 // CFSEmailUiGenericTimer::NewL
       
  3575 // NewL function. Returns timer object.
       
  3576 // -----------------------------------------------------------------------------
       
  3577 //
       
  3578 CFSEmailUiGenericTimer* CFSEmailUiGenericTimer::NewL(
       
  3579 	MFSEmailUiGenericTimerCallback* aCallback,
       
  3580 	const TInt aPriority )
       
  3581     {
       
  3582     FUNC_LOG;
       
  3583     CFSEmailUiGenericTimer* self = NewLC( aCallback, aPriority );
       
  3584     CleanupStack::Pop( self );
       
  3585     return self;
       
  3586     }
       
  3587 
       
  3588 // -----------------------------------------------------------------------------
       
  3589 // CFSEmailUiGenericTimer::NewL
       
  3590 // NewL function. Returns timer object.
       
  3591 // -----------------------------------------------------------------------------
       
  3592 //
       
  3593 CFSEmailUiGenericTimer* CFSEmailUiGenericTimer::NewLC(
       
  3594 	MFSEmailUiGenericTimerCallback* aCallback,
       
  3595 	const TInt aPriority )
       
  3596     {
       
  3597     FUNC_LOG;
       
  3598     CFSEmailUiGenericTimer* self = new (ELeave) CFSEmailUiGenericTimer( aCallback, aPriority );
       
  3599     CleanupStack::PushL( self );
       
  3600     self->ConstructL();
       
  3601     return self;
       
  3602     }
       
  3603 
       
  3604 // -----------------------------------------------------------------------------
       
  3605 // CFSEmailUiGenericTimer::NewL
       
  3606 // NewL function. Returns timer object.
       
  3607 // -----------------------------------------------------------------------------
       
  3608 //
       
  3609 void CFSEmailUiGenericTimer::ConstructL()
       
  3610     {
       
  3611     FUNC_LOG;
       
  3612     CTimer::ConstructL();
       
  3613     CActiveScheduler::Add( this );
       
  3614     }
       
  3615 
       
  3616 // -----------------------------------------------------------------------------
       
  3617 // CFSEmailUiGenericTimer::~CFSEmailUiGenericTimer
       
  3618 // D'tor
       
  3619 // -----------------------------------------------------------------------------
       
  3620 //
       
  3621 CFSEmailUiGenericTimer::~CFSEmailUiGenericTimer()
       
  3622     {
       
  3623     FUNC_LOG;
       
  3624     Cancel();
       
  3625     iCallback = NULL;
       
  3626     }
       
  3627 
       
  3628 // -----------------------------------------------------------------------------
       
  3629 // CFSEmailUiGenericTimer::CFSEmailUiGenericTimer
       
  3630 // C'tor
       
  3631 // -----------------------------------------------------------------------------
       
  3632 //
       
  3633 CFSEmailUiGenericTimer::CFSEmailUiGenericTimer(
       
  3634 	MFSEmailUiGenericTimerCallback* aCallback,
       
  3635 	const TInt aPriority )
       
  3636 	: CTimer( aPriority ),
       
  3637 	iCallback( aCallback )
       
  3638     {
       
  3639     }
       
  3640 
       
  3641 // -----------------------------------------------------------------------------
       
  3642 // CFSEmailUiGenericTimer::RunL
       
  3643 // Timer trigger function.
       
  3644 // -----------------------------------------------------------------------------
       
  3645 //
       
  3646 void CFSEmailUiGenericTimer::RunL()
       
  3647     {
       
  3648     FUNC_LOG;
       
  3649     if ( iCallback )
       
  3650     	{
       
  3651     	iCallback->TimerEventL( this );
       
  3652     	}
       
  3653     }
       
  3654 
       
  3655 // -----------------------------------------------------------------------------
       
  3656 // CFSEmailUiGenericTimer::Start
       
  3657 // Timer starting function.
       
  3658 // -----------------------------------------------------------------------------
       
  3659 //
       
  3660 void CFSEmailUiGenericTimer::Start( TInt aInterval )
       
  3661     {
       
  3662     FUNC_LOG;
       
  3663     Cancel();
       
  3664     if( aInterval < 0 )
       
  3665     	{
       
  3666     	aInterval = KGenericTimerDefaultInterval;
       
  3667     	}
       
  3668 	After( TTimeIntervalMicroSeconds32( aInterval * 1000 ) );
       
  3669     }
       
  3670 
       
  3671 // -----------------------------------------------------------------------------
       
  3672 // CFSEmailUiGenericTimer::Stop
       
  3673 // Timer stopping function
       
  3674 // -----------------------------------------------------------------------------
       
  3675 //
       
  3676 void CFSEmailUiGenericTimer::Stop()
       
  3677     {
       
  3678     FUNC_LOG;
       
  3679     Cancel();
       
  3680     }
       
  3681 
       
  3682 TKeyResponse CFSEmailUiCallDialog::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
       
  3683     {
       
  3684     if (aKeyEvent.iScanCode == EStdKeyYes )
       
  3685         {
       
  3686         TKeyEvent newEvent;
       
  3687         newEvent.iScanCode = EStdKeyEnter;
       
  3688         newEvent.iCode = EKeyEnter;
       
  3689         return CAknQueryDialog::OfferKeyEventL(newEvent, aType);
       
  3690         }
       
  3691     else
       
  3692         {
       
  3693         return CAknQueryDialog::OfferKeyEventL(aKeyEvent, aType);
       
  3694         }
       
  3695     }
       
  3696 
       
  3697