email/imum/Utils/Src/EmailUtils.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 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: 
       
    15 *       Static functions for imum
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <bldvariant.hrh>
       
    22 #include <miutset.h>
       
    23 #include <s32file.h>
       
    24 #include <eikenv.h>
       
    25 #include <eikrutil.h>
       
    26 #include <eikbtgpc.h>
       
    27 #include <iapprefs.h>
       
    28 #include <StringLoader.h>
       
    29 #include <aknnotewrappers.h>
       
    30 #include <AknGlobalNote.h>
       
    31 #include <sendui.h>
       
    32 #include <ErrorUI.h>                    // CErrorUI
       
    33 #include <AknQueryDialog.h>
       
    34 #include <aknnotedialog.h>
       
    35 #include <StringLoader.h>
       
    36 #include <MuiuOperationWait.h>          // CMuiuOperationWait
       
    37 #include <MuiuMsvUiServiceUtilities.h>  // MsvUiServiceUtilities
       
    38 #include <imapset.h>
       
    39 #include <pop3set.h>
       
    40 #include <smtpset.h>
       
    41 #include <MTMStore.h>                   // CMtmStore
       
    42 #include <mtmuibas.h>                   // BaseMtmUi
       
    43 #include <messaginginternalcrkeys.h>    // Messaging keys
       
    44 #include <centralrepository.h>          // CRepository
       
    45 #include <CoreApplicationUIsSDKCRKeys.h>
       
    46 #include <cemailaccounts.h>
       
    47 #include <bldvariant.hrh>
       
    48 #include <messagingvariant.hrh>
       
    49 #include <MNcnInternalNotification.h>
       
    50 #include <data_caging_path_literals.hrh>    // KDC_MTM_RESOURCE_DIR
       
    51 #include <ImumUtils.rsg>
       
    52 #include <bautils.h>
       
    53 #include <muiuemailtools.h>
       
    54 #include "ImumInMailboxUtilitiesImpl.h"
       
    55 #include "ImumInMailboxServicesImpl.h"
       
    56 
       
    57 #include "SenduiMtmUids.h"
       
    58 #include "ImumMboxManager.h"
       
    59 #include "ImumMboxData.h"
       
    60 #include "EmailFeatureUtils.h"
       
    61 #include "EmailUtils.H"
       
    62 #include "ImumUtilsLogging.h"
       
    63 #include "ImumPanic.h"
       
    64 #include <ImumUtils.rsg>
       
    65 #include "ImumMboxSettingsCtrl.h"
       
    66 #include "ImumUtilsLogging.h"
       
    67 #include "IMSSettingsNoteUi.h"
       
    68 #include "ImumInternalApiImpl.h"
       
    69 #include "ImumDaSettingsKeys.h"
       
    70 #include "ImumInSettingsData.h"             // CImumInSettingsData
       
    71 
       
    72 // EXTERNAL DATA STRUCTURES
       
    73 // EXTERNAL FUNCTION PROTOTYPES
       
    74 // CONSTANTS
       
    75 const TInt KBytesInKiloByte = 1024;
       
    76 const TInt KImumSizeBufferSize = 32;
       
    77 const TInt KImumReplaceCharacterCount = 2;
       
    78 const TInt KIMSMaxAoMailboxes = 2;
       
    79 const TInt KImumExtraStringLength = 4;
       
    80 _LIT( KImumDefaultNameFormat, "%S(%02d)" );
       
    81 _LIT(KEmailUtilsComma, ",");
       
    82 _LIT(KEmailUtilsSpace, " ");
       
    83 _LIT( KIMSDirAndResFileName,"z:ImumUtils.rsc" );
       
    84 
       
    85 // MACROS
       
    86 // LOCAL CONSTANTS AND MACROS
       
    87 // MODULE DATA STRUCTURES
       
    88 // LOCAL FUNCTION PROTOTYPES
       
    89 // FORWARD DECLARATIONS
       
    90 
       
    91 // ============================ MEMBER FUNCTIONS ===============================
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // MsvEmailMtmUiUtils::CheckAvailableDiskSpaceForDownloadL
       
    95 // This is static function
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C TBool MsvEmailMtmUiUtils::CheckAvailableDiskSpaceForDownloadL(
       
    99     TInt aMsgSize,
       
   100     CEikonEnv& aEikonEnv,
       
   101     CMsvSession& aSession )
       
   102 //
       
   103 // Check there is enough disk space on the specified drive to fetch a message
       
   104 // of aMsgSize bytes. If not, display a message and return EFalse.
       
   105 // static
       
   106     {
       
   107     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::CheckAvailableDiskSpaceForDownloadL, 0, utils, KLogUi );
       
   108     
       
   109     if ( MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL(
       
   110         aSession, aMsgSize ) )
       
   111         {
       
   112         CErrorUI* errorUi = CErrorUI::NewLC( aEikonEnv );
       
   113         errorUi->ShowGlobalErrorNoteL( KErrDiskFull );
       
   114         CleanupStack::PopAndDestroy( errorUi );
       
   115         return EFalse;
       
   116         }
       
   117     return ETrue;
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // MsvEmailMtmUiUtils::CheckActiveAOLimitsL()
       
   122 //
       
   123 // This function goes through all the mailboxes and checks, if there are any
       
   124 // Always Online enabled boxes around. The included mailbox id is ignored
       
   125 // during the search. If less than 2 ( <2 ) always online mailboxes are found,
       
   126 // ETrue is returned, otherwise EFalse is returned.
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 TBool MsvEmailMtmUiUtils::CheckActiveAOLimitsL(
       
   130     CImumInternalApi& aEmailApi,    
       
   131     const TMsvId aMailboxId )
       
   132     {
       
   133     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::CheckActiveAOLimitsL, 0, utils, KLogUi );
       
   134     
       
   135     // Get the list of healthy mailboxes from the API
       
   136     TInt count = 0;    
       
   137     const MImumInHealthServices& healthApi = aEmailApi.HealthServicesL();
       
   138     MImumInHealthServices::RMailboxIdArray mailboxes;
       
   139     
       
   140     // Get the list of mailboxes in array. Gather the list based on the smtpId, 
       
   141     // since the aMailboxId is actually also the smtpId
       
   142     if ( healthApi.GetMailboxList( mailboxes, 
       
   143     		MImumInHealthServices::EFlagIncludeSmtp | 
       
   144     		MImumInHealthServices::EFlagGetHealthy ) == KErrNone )
       
   145     	{
       
   146     	for ( TInt mbox = mailboxes.Count(); --mbox >= 0; )
       
   147     		{           
       
   148             if ( aMailboxId != mailboxes[mbox] )
       
   149                 {
       
   150                 // Create object for the extended mail settings
       
   151                 CImumInSettingsData* settings = 
       
   152                     aEmailApi.MailboxServicesL().LoadMailboxSettingsL( 
       
   153                         mailboxes[mbox] );
       
   154                 CleanupStack::PushL( settings );
       
   155                 
       
   156                 TInt aoState = 0;
       
   157                 if ( settings )
       
   158                 	{
       
   159 	                settings->GetAttr(
       
   160 	                    TImumDaSettings::EKeyAutoRetrieval, aoState );
       
   161 
       
   162 					// If always online is on, increase the count
       
   163 					if ( aoState != TImumDaSettings::EValueAutoOff )
       
   164 						{
       
   165 						count++;
       
   166 						}
       
   167                 	}
       
   168                 CleanupStack::PopAndDestroy( settings );
       
   169                 settings = NULL;                         
       
   170                 }                
       
   171             }
       
   172         }
       
   173     
       
   174     mailboxes.Reset();
       
   175 
       
   176     return count < KIMSMaxAoMailboxes;
       
   177     }
       
   178 
       
   179 // ----------------------------------------------------------------------------
       
   180 // MsvEmailMtmUiUtils::DoCEntryCopyMoveL
       
   181 // This is static function
       
   182 // ----------------------------------------------------------------------------
       
   183 //
       
   184 EXPORT_C CMsvOperation* MsvEmailMtmUiUtils::DoCEntryCopyMoveL(
       
   185     CMsvEntry& aEntry, const CMsvEntrySelection& aSel, TMsvId aTargetId, 
       
   186     TRequestStatus& aCompletionStatus, TBool aCopy)
       
   187     {
       
   188     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::DoCEntryCopyMoveL, 0, utils, KLogUi );
       
   189     
       
   190     CMsvOperation* op = NULL;
       
   191     if(aCopy)
       
   192         {
       
   193         op = aEntry.CopyL(aSel, aTargetId, aCompletionStatus);
       
   194         }
       
   195     else
       
   196         {
       
   197         op = aEntry.MoveL(aSel, aTargetId, aCompletionStatus);
       
   198         }
       
   199     return op;
       
   200     }
       
   201 
       
   202 // ----------------------------------------------------------------------------
       
   203 // MsvEmailMtmUiUtils::StripCompleteEntriesLC
       
   204 // This is static function
       
   205 // ----------------------------------------------------------------------------
       
   206 //
       
   207 EXPORT_C CMsvEntrySelection* MsvEmailMtmUiUtils::StripCompleteEntriesLC(
       
   208     const CMsvEntry& aParent, const CMsvEntrySelection& aSelection)
       
   209     {
       
   210     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::StripCompleteEntriesLC, 0, utils, KLogUi );
       
   211     
       
   212     CMsvEntrySelection* entries=aSelection.CopyLC();
       
   213     TInt cc = entries->Count();
       
   214     TMsvEntry tEntry;
       
   215     while(cc--)
       
   216         {
       
   217         tEntry = aParent.ChildDataL((*entries)[cc]);
       
   218         TMsvEmailEntry eEntry( tEntry );
       
   219 
       
   220         TBool complete = tEntry.Complete();
       
   221         TBool partial = eEntry.PartialDownloaded();
       
   222 
       
   223         if( complete && !partial )
       
   224             {
       
   225             entries->Delete(cc);
       
   226             }
       
   227         }
       
   228     return entries;
       
   229     }
       
   230 
       
   231 // ----------------------------------------------------------------------------
       
   232 // MsvEmailMtmUiUtils::StripDeletedEntriesLC
       
   233 // This is static function
       
   234 // ----------------------------------------------------------------------------
       
   235 //
       
   236 EXPORT_C CMsvEntrySelection* MsvEmailMtmUiUtils::StripDeletedEntriesLC(
       
   237     const CMsvEntry& aParent, const CMsvEntrySelection& aSelection)
       
   238     {
       
   239     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::StripDeletedEntriesLC, 0, utils, KLogUi );
       
   240      // static
       
   241     CMsvEntrySelection* entries=aSelection.CopyLC();
       
   242     TInt cc = entries->Count();
       
   243     while(cc--)
       
   244         {
       
   245         const TMsvEmailEntry mailEntry(aParent.ChildDataL((*entries)[cc]));
       
   246         if(EDisconnectedDeleteOperation == mailEntry.DisconnectedOperation())
       
   247             {
       
   248             entries->Delete(cc);
       
   249             }
       
   250         }
       
   251     return entries;
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // MsvEmailMtmUiUtils::SetMessageInfoDataLCCCCC
       
   256 // This is static function
       
   257 // sets fields in the message info data array using TMsvEntry and CImHeader
       
   258 // information; the TDes parameters are needed so that the strings have
       
   259 // persisted memory to live in since the info data elements are all TPtrs
       
   260 // ----------------------------------------------------------------------------
       
   261 //
       
   262 EXPORT_C void MsvEmailMtmUiUtils::SetMessageInfoDataLCCCCC(
       
   263     TMsgInfoMessageInfoData& aInfoData,
       
   264     CBaseMtm& aMtm,
       
   265     CCoeEnv& aEnv,
       
   266     TDes& /* aDateBuf */,
       
   267     TDes& /* aTimeBuf */,
       
   268     TDes& aSizeBuf,
       
   269     TDes& aPriorityBuf )
       
   270     {
       
   271     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::SetMessageInfoDataLCCCCC, 0, utils, KLogUi );
       
   272     
       
   273     //retrieve header
       
   274     CMsvStore* store = aMtm.Entry().ReadStoreL();
       
   275     CleanupStack::PushL( store );
       
   276     CImHeader* header = CImHeader::NewLC();
       
   277     header->RestoreL( *store );
       
   278 
       
   279     //subject
       
   280     HBufC* tmpSubj = header->Subject().AllocLC();
       
   281     aInfoData.iSubject.Set( *tmpSubj );
       
   282 
       
   283     //date and time
       
   284     TMsvEntry tentry = aMtm.Entry().Entry();
       
   285     aInfoData.iDateTime = tentry.iDate;
       
   286 
       
   287     //size
       
   288     TInt size = tentry.iSize / KBytesInKiloByte; //in bytes
       
   289     if ( tentry.iSize % KBytesInKiloByte )
       
   290         {
       
   291         size++;
       
   292         }
       
   293     TBuf<KImumSizeBufferSize> kB;
       
   294     StringLoader::Load( kB, R_IMAS_MESSAGE_INFO_KB, &aEnv );
       
   295     StringLoader::Format( aSizeBuf, kB, -1, size );
       
   296     aInfoData.iSize.Set( aSizeBuf );
       
   297 
       
   298     //Priority
       
   299     MsvEmailMtmUiUtils::GetPriorityString(tentry,aEnv,aPriorityBuf );             
       
   300     aInfoData.iPriority.Set( aPriorityBuf );  
       
   301 
       
   302     //to field
       
   303     HBufC* toList = TurnArrayIntoCommaSeparatedStringLC(
       
   304         header->ToRecipients() );
       
   305     aInfoData.iTo.Set( *toList );
       
   306 
       
   307     //cc field
       
   308     HBufC* ccList = TurnArrayIntoCommaSeparatedStringLC(
       
   309         header->CcRecipients() );
       
   310     aInfoData.iCC.Set( *ccList );
       
   311 
       
   312     //bcc field
       
   313     HBufC* bccList = TurnArrayIntoCommaSeparatedStringLC(
       
   314         header->BccRecipients() );
       
   315     aInfoData.iBCC.Set( *bccList );
       
   316 
       
   317     //from field
       
   318     HBufC* tmpFrom = header->From().AllocLC();
       
   319     aInfoData.iFrom.Set( *tmpFrom );
       
   320 
       
   321     //take HBufCs out
       
   322     CleanupStack::Pop( 5 ); // CSI: 47 # tmpFrom, bccList, ccList, toList, tmpSubj.
       
   323     //destroy store and header. if not, message info in outbox prevents
       
   324     //mail sending!
       
   325     CleanupStack::PopAndDestroy( 2 ); // CSI: 47 # header, store.
       
   326     //put HBufCs back, so no need to change function name.
       
   327     CleanupStack::PushL( tmpSubj );
       
   328     CleanupStack::PushL( toList );
       
   329     CleanupStack::PushL( ccList );
       
   330     CleanupStack::PushL( bccList );
       
   331     CleanupStack::PushL( tmpFrom );
       
   332     }
       
   333 
       
   334 // ----------------------------------------------------------------------------
       
   335 // MsvEmailMtmUiUtils::SetMessageInfoDataLCC
       
   336 // This is static function
       
   337 // sets fields in the message info data array using TMsvEntry and CImHeader
       
   338 // information; the TDes parameters are needed so that the strings have
       
   339 // persisted memory to live in since the info data elements are all TPtrs
       
   340 // ----------------------------------------------------------------------------
       
   341 //
       
   342 EXPORT_C TBool MsvEmailMtmUiUtils::SetMessageInfoDataLCC(
       
   343     TMsgInfoMessageInfoData& aInfoData,
       
   344     CBaseMtm& aMtm,
       
   345     CCoeEnv& aEnv,
       
   346     TDes& /* aDateBuf */,
       
   347     TDes& /* aTimeBuf */,
       
   348     TDes& aSizeBuf,
       
   349     TDes& aPriorityBuf )
       
   350     {
       
   351     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::SetMessageInfoDataLCC, 0, utils, KLogUi );
       
   352             
       
   353     //retrieve header
       
   354     CMsvStore* store = NULL;
       
   355     CImHeader* header = NULL;
       
   356     TRAPD( storeError, store = aMtm.Entry().ReadStoreL() );
       
   357     if ( storeError == KErrNone )
       
   358         {
       
   359         CleanupStack::PushL( store );
       
   360         header = CImHeader::NewLC();
       
   361         TRAP( storeError, header->RestoreL( *store ) );
       
   362         // if restore leaves then we can find out lots of info from
       
   363         // TMsvEntry's fields.
       
   364         if ( storeError != KErrNone )
       
   365             {
       
   366             CleanupStack::PopAndDestroy( 2, store ); // CSI: 47 # header, store.
       
   367             header = NULL;
       
   368             store = NULL;
       
   369             }
       
   370         // if no errors, then store and header should be left to cleanup stack.
       
   371         }
       
   372 
       
   373     TMsvEntry tentry = aMtm.Entry().Entry();
       
   374 
       
   375     //subject
       
   376     if ( header )
       
   377         {
       
   378         aInfoData.iSubject.Set( header->Subject() );
       
   379         }
       
   380     else
       
   381         {
       
   382         aInfoData.iSubject.Set( tentry.iDescription );
       
   383         }
       
   384 
       
   385     //date and time
       
   386     aInfoData.iDateTime = tentry.iDate;
       
   387 
       
   388     //size
       
   389     TInt size = tentry.iSize / KBytesInKiloByte; //in bytes
       
   390     if ( tentry.iSize % KBytesInKiloByte )
       
   391         {
       
   392         size++;
       
   393         }
       
   394     TBuf<KImumSizeBufferSize> kB;
       
   395     StringLoader::Load( kB, R_IMAS_MESSAGE_INFO_KB, &aEnv );
       
   396     StringLoader::Format( aSizeBuf, kB, -1, size );
       
   397     aInfoData.iSize.Set( aSizeBuf );
       
   398 
       
   399      //Priority
       
   400      MsvEmailMtmUiUtils::GetPriorityString(tentry,aEnv,aPriorityBuf );             
       
   401     aInfoData.iPriority.Set( aPriorityBuf );  
       
   402 
       
   403     if ( header )
       
   404         {
       
   405         //to field
       
   406         HBufC* toList = TurnArrayIntoCommaSeparatedStringLC(
       
   407             header->ToRecipients() );
       
   408         aInfoData.iTo.Set( *toList );
       
   409 
       
   410         //cc field
       
   411         HBufC* ccList = TurnArrayIntoCommaSeparatedStringLC(
       
   412             header->CcRecipients() );
       
   413         aInfoData.iCC.Set( *ccList );
       
   414 
       
   415         //from field
       
   416         aInfoData.iFrom.Set( header->From() );
       
   417         }
       
   418     else
       
   419         {
       
   420         // to field
       
   421         HBufC* toList = HBufC::NewLC( 0 );
       
   422         aInfoData.iTo.Set( *toList );
       
   423 
       
   424         // cc field
       
   425         HBufC* ccList = HBufC::NewLC( 0 );
       
   426         aInfoData.iCC.Set( *ccList );
       
   427 
       
   428         // from field
       
   429         aInfoData.iFrom.Set( tentry.iDetails );
       
   430         }
       
   431 
       
   432     return ( header != NULL );
       
   433     }
       
   434 
       
   435 // ----------------------------------------------------------------------------
       
   436 // MsvEmailMtmUiUtils::TurnArrayIntoCommaSeparatedStringLC
       
   437 // This is static function
       
   438 // returns an HBufC* which contains all of the lines in aTextArray concaternated
       
   439 // together with commas separating them
       
   440 // ----------------------------------------------------------------------------
       
   441 //
       
   442 HBufC* MsvEmailMtmUiUtils::TurnArrayIntoCommaSeparatedStringLC(CDesCArray& aTextArray)
       
   443     {
       
   444     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::TurnArrayIntoCommaSeparatedStringLC, 0, utils, KLogUi );
       
   445     
       
   446     TInt totalLength=0;
       
   447     //first calculate the length of string required
       
   448     TInt index = 0;
       
   449     for(index=0;index<aTextArray.Count();index++)
       
   450         {
       
   451         totalLength += aTextArray[index].Length();
       
   452 
       
   453         //don't count comma and space for last item
       
   454         if(index != ( aTextArray.Count() - 1 ) )
       
   455             {
       
   456             totalLength+=2; // CSI: 47 # comma and space.
       
   457             }
       
   458         }
       
   459 
       
   460     HBufC* list = HBufC::NewLC(totalLength);
       
   461     //now fill out the string
       
   462     for(index=0;index<aTextArray.Count();index++)
       
   463         {
       
   464         list->Des().Append(aTextArray[index]);
       
   465 
       
   466         //don't add for last item
       
   467         if(index != ( aTextArray.Count() - 1 ) )
       
   468             {
       
   469             list->Des().Append(KEmailUtilsComma);
       
   470             list->Des().Append(KEmailUtilsSpace);
       
   471             }
       
   472         }
       
   473 
       
   474     return list;
       
   475     }
       
   476 
       
   477 
       
   478 // ----------------------------------------------------------------------------
       
   479 // MsvEmailMtmUiUtils::ReplaceCharacters
       
   480 // This is static function
       
   481 // ----------------------------------------------------------------------------
       
   482 //
       
   483 void MsvEmailMtmUiUtils::ReplaceCharacters( TDes& aText )
       
   484     {
       
   485     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::ReplaceCharacters, 0, utils, KLogUi );
       
   486     
       
   487     TBuf<KImumReplaceCharacterCount> replaceChars;
       
   488     replaceChars.Zero();
       
   489     replaceChars.Append( CEditableText::EParagraphDelimiter );
       
   490     replaceChars.Append( CEditableText::ETabCharacter );
       
   491     AknTextUtils::ReplaceCharacters(
       
   492         aText,
       
   493         replaceChars,
       
   494         CEditableText::ESpace );
       
   495     }
       
   496 
       
   497 // ----------------------------------------------------------------------------
       
   498 // MsvEmailMtmUiUtils::StripCharacters
       
   499 // This is static function
       
   500 // ----------------------------------------------------------------------------
       
   501 //
       
   502 void MsvEmailMtmUiUtils::StripCharacters( TDes& aText )
       
   503     {
       
   504     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::StripCharacters, 0, utils, KLogUi );
       
   505     
       
   506     TBuf<KImumReplaceCharacterCount> stripChars;
       
   507     stripChars.Zero();
       
   508     stripChars.Append( CEditableText::EParagraphDelimiter );
       
   509     stripChars.Append( CEditableText::ETabCharacter );
       
   510     AknTextUtils::StripCharacters(
       
   511         aText,
       
   512         stripChars );
       
   513     }
       
   514 
       
   515 
       
   516 // ----------------------------------------------------------------------------
       
   517 // DisconnectMailboxL
       
   518 // ----------------------------------------------------------------------------
       
   519 //
       
   520 EXPORT_C TBool MsvEmailMtmUiUtils::DisconnectMailboxL(
       
   521     const TMsvEntry& aService, CMsvSession& aSession )
       
   522     {
       
   523     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::DisconnectMailboxL, 0, utils, KLogUi );
       
   524     
       
   525     __ASSERT_DEBUG( aService.iMtm != KSenduiMtmSmtpUid,
       
   526         User::Panic( KImumMtmUiPanic, EPanicRcvServiceMustBePOP3OrIMAP4) );
       
   527 
       
   528     if ( CIMSSettingsNoteUi::ShowQueryL(
       
   529         R_IMAS_SETTINGS_DIALOG_MAILSET_DISCON, R_EMAIL_CONFIRMATION_QUERY ) )
       
   530         {
       
   531         CMtmStore* mtmStore = CMtmStore::NewL( aSession );
       
   532         CleanupStack::PushL(mtmStore);
       
   533         CBaseMtmUi& relatedMtmUi = mtmStore->GetMtmUiAndSetContextLC(aService);
       
   534         CMuiuOperationWait* wait =
       
   535             CMuiuOperationWait::NewLC( EActivePriorityWsEvents + 10 ); // CSI: 47 # <Insert comment here>.
       
   536         CMsvOperation* op = relatedMtmUi.CloseL(wait->iStatus);
       
   537         wait->Start();
       
   538         CleanupStack::PopAndDestroy( wait );
       
   539         delete op;
       
   540         CleanupStack::PopAndDestroy( 2, mtmStore ); // CSI: 47 # release mtmui.
       
   541 
       
   542         return ETrue; // did disconnect succeed?
       
   543         }
       
   544     else
       
   545         {
       
   546         return EFalse;
       
   547         }
       
   548     }
       
   549 
       
   550 // ----------------------------------------------------------------------------
       
   551 // MsvEmailMtmUiUtils::DoOfflineChecksL()
       
   552 // Function to check offline mode
       
   553 // ----------------------------------------------------------------------------
       
   554 //
       
   555 EXPORT_C TBool MsvEmailMtmUiUtils::DoOfflineChecksL( TMsvId /*aService*/ )
       
   556     {
       
   557     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::DoOfflineChecksL, 0, utils, KLogUi );
       
   558     
       
   559     if ( !MsvEmailMtmUiFeatureUtils::LocalFeatureL(
       
   560         KCRUidCoreApplicationUIs, KCoreAppUIsNetworkConnectionAllowed, 1 ) )
       
   561         {
       
   562         // offline mode has been set
       
   563         HBufC* text = StringLoader::LoadLC(
       
   564             R_IMUM_OFFLINE_NOT_POSSIBLE, CCoeEnv::Static()  );
       
   565         CAknInformationNote* note = new (ELeave)
       
   566         CAknInformationNote();
       
   567         note->ExecuteLD( *text );
       
   568         CleanupStack::PopAndDestroy( text ); 
       
   569 
       
   570         return ETrue;
       
   571         }
       
   572 
       
   573     return EFalse;
       
   574     }
       
   575 
       
   576 // ----------------------------------------------------------------------------
       
   577 // MsvEmailMtmUiUtils::RemoveOfflineDeleteL()
       
   578 // ----------------------------------------------------------------------------
       
   579 //
       
   580 EXPORT_C TInt MsvEmailMtmUiUtils::RemoveOfflineDeleteL(
       
   581     CBaseMtm& aBaseMtm,
       
   582     TInt aFunctionId,
       
   583     TMsvId aEntryId )
       
   584     {
       
   585     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::RemoveOfflineDeleteL, 0, utils, KLogUi );
       
   586     
       
   587     TBuf8<1> params;
       
   588     params.Zero();
       
   589 
       
   590     // Create the selection and add the id into it
       
   591     CMsvEntrySelection* selection = new(ELeave) CMsvEntrySelection;
       
   592     CleanupStack::PushL( selection );
       
   593     selection->AppendL( aEntryId );
       
   594 
       
   595     // Create waiting operation and the main operation
       
   596     CMuiuOperationWait* wait = CMuiuOperationWait::NewLC();
       
   597     CMsvOperation* op = aBaseMtm.InvokeAsyncFunctionL(
       
   598         aFunctionId,
       
   599         *selection,
       
   600         params,
       
   601         wait->iStatus );
       
   602 
       
   603     // Start the waiter operation
       
   604     wait->Start();
       
   605 
       
   606     // Get the error from waiter
       
   607     TInt error = wait->iStatus.Int();
       
   608 
       
   609     // Cleanup the objects
       
   610     delete op;
       
   611     op = NULL;    
       
   612     CleanupStack::PopAndDestroy( 2, selection ); // CSI: 47 # wait, selection.
       
   613     wait = NULL;
       
   614     selection = NULL;
       
   615 
       
   616     return error;
       
   617     }
       
   618 
       
   619 // ----------------------------------------------------------------------------
       
   620 // MsvEmailMtmUiUtils::AcquireDiskSpace()
       
   621 // ----------------------------------------------------------------------------
       
   622 //
       
   623 EXPORT_C TInt MsvEmailMtmUiUtils::AcquireDiskSpace(
       
   624     RFs& aFileSession,
       
   625     const TInt aDriveNo,
       
   626     const TInt aSize )
       
   627     {
       
   628     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::AcquireDiskSpace, 0, utils, KLogUi );
       
   629     
       
   630     // Try to reserve diskspace
       
   631     TInt error = aFileSession.ReserveDriveSpace(
       
   632         aDriveNo, aSize );
       
   633 
       
   634     // If reserving ok, get access
       
   635     if ( error == KErrNone )
       
   636         {
       
   637         error = aFileSession.GetReserveAccess( aDriveNo );
       
   638         }
       
   639 
       
   640     return error;
       
   641     }
       
   642 
       
   643 // ----------------------------------------------------------------------------
       
   644 // MsvEmailMtmUiUtils::SendAOCommandL()
       
   645 // ----------------------------------------------------------------------------
       
   646 //
       
   647 EXPORT_C void MsvEmailMtmUiUtils::SendAOCommandL(
       
   648     const TAlwaysOnlineServerAPICommands aCommand,
       
   649     TMsvId aMailboxId )
       
   650     {
       
   651     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::SendAOCommandL, 0, utils, KLogUi );
       
   652     
       
   653     // Create connection to Always Online
       
   654 	RAlwaysOnlineClientSession aoclient;
       
   655 	CleanupClosePushL(aoclient);
       
   656 	User::LeaveIfError(aoclient.Connect());
       
   657 
       
   658 	// Prepare the parameters to be forwarded to AO-server
       
   659 	TPckg<TMsvId> param = aMailboxId;
       
   660 
       
   661 	// Send message to server and close it
       
   662 	aoclient.RelayCommandL(aCommand, param);
       
   663 	CleanupStack::PopAndDestroy();
       
   664     }
       
   665 
       
   666 // ----------------------------------------------------------------------------
       
   667 // MsvEmailMtmUiUtils::GetAccountId()
       
   668 // ----------------------------------------------------------------------------
       
   669 //
       
   670 TUint32 MsvEmailMtmUiUtils::GetAccountId(
       
   671     const CImumMboxData& aAccountSettings )
       
   672     {
       
   673     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::GetAccountId, 0, utils, KLogUi );
       
   674     
       
   675     if ( aAccountSettings.iIsImap4 )
       
   676         {
       
   677         return aAccountSettings.iImap4AccountId.iImapAccountId;
       
   678         }
       
   679     else
       
   680         {
       
   681         return aAccountSettings.iPop3AccountId.iPopAccountId;
       
   682         }
       
   683     }
       
   684 
       
   685 // ----------------------------------------------------------------------------
       
   686 // CImumMboxSettingsCtrl::CreateCenRepConnectionL()
       
   687 // ----------------------------------------------------------------------------
       
   688 //
       
   689 void MsvEmailMtmUiUtils::CreateCenRepConnectionL(
       
   690     CRepository*& aRepository,
       
   691     TUid aRepositoryUid )
       
   692     {
       
   693     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::CreateCenRepConnectionL, 0, utils, KLogUi );
       
   694     
       
   695     // If session doesn't exist, create one
       
   696     if ( !aRepository )
       
   697         {
       
   698         aRepository = CRepository::NewL( aRepositoryUid );
       
   699         }
       
   700     }
       
   701 // ----------------------------------------------------------------------------
       
   702 // MsvEmailMtmUiUtils::StoreSecuritySettings()
       
   703 // ----------------------------------------------------------------------------
       
   704 //
       
   705 void MsvEmailMtmUiUtils::StoreSecuritySettings(
       
   706     CImBaseEmailSettings& aSettings,
       
   707     const TIMASMailSecurity& aSecurity )
       
   708     {
       
   709     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::StoreSecuritySettings, 0, utils, KLogUi );
       
   710     
       
   711     switch( aSecurity )
       
   712         {        
       
   713         case EImumSecurityOn:
       
   714             aSettings.SetSecureSockets( ETrue );
       
   715             aSettings.SetSSLWrapper( EFalse );
       
   716             break;
       
   717             
       
   718         case EImumSecurityMs:
       
   719             aSettings.SetSecureSockets( EFalse );
       
   720             aSettings.SetSSLWrapper( ETrue );
       
   721             break;
       
   722                 
       
   723         case EImumSecurityOff:
       
   724             aSettings.SetSecureSockets( EFalse );
       
   725             aSettings.SetSSLWrapper( EFalse );
       
   726             break;
       
   727 
       
   728         default:
       
   729             break;
       
   730         }
       
   731     }
       
   732 
       
   733 // ----------------------------------------------------------------------------
       
   734 // MsvEmailMtmUiUtils::StoreSecuritySettings()
       
   735 // ----------------------------------------------------------------------------
       
   736 //
       
   737 void MsvEmailMtmUiUtils::StoreSecuritySettings(
       
   738     CImBaseEmailSettings& aSettings,
       
   739     const TImumDaSettings::TSecurityValues& aSecurity )
       
   740     {
       
   741     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::StoreSecuritySettings, 0, utils, KLogUi );
       
   742     
       
   743     switch( aSecurity )
       
   744         {
       
   745         case TImumDaSettings::EValueSecurityTls:        
       
   746             aSettings.SetSecureSockets( ETrue );
       
   747             aSettings.SetSSLWrapper( EFalse );
       
   748             break;
       
   749     
       
   750         case TImumDaSettings::EValueSecuritySsl:        
       
   751             aSettings.SetSecureSockets( EFalse );
       
   752             aSettings.SetSSLWrapper( ETrue );
       
   753             break;
       
   754         
       
   755         case TImumDaSettings::EValueSecurityOff:        
       
   756             aSettings.SetSecureSockets( EFalse );
       
   757             aSettings.SetSSLWrapper( EFalse );
       
   758             break;
       
   759 
       
   760         default:
       
   761             break;
       
   762         }
       
   763     }
       
   764 
       
   765 
       
   766 // ---------------------------------------------------------------------------
       
   767 // MsvEmailMtmUiUtils::RestoreSecuritySettings()
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 TInt MsvEmailMtmUiUtils::RestoreSecuritySettings(
       
   771     const CImBaseEmailSettings& aSettings )
       
   772     {
       
   773     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::RestoreSecuritySettings, 0, utils, KLogUi );
       
   774     
       
   775     TInt security = 0;
       
   776     
       
   777     // Security: TLS
       
   778     if( aSettings.SecureSockets() )
       
   779         {
       
   780         security = TImumDaSettings::EValueSecurityTls;
       
   781         }
       
   782     // Security: MS
       
   783     else if( aSettings.SSLWrapper() )
       
   784         {
       
   785         security = TImumDaSettings::EValueSecuritySsl;
       
   786         }
       
   787     // Security Off
       
   788     else
       
   789         {
       
   790         security = TImumDaSettings::EValueSecurityOff;
       
   791         }    
       
   792         
       
   793     return security;                
       
   794     }
       
   795 
       
   796 // ----------------------------------------------------------------------------
       
   797 // MsvEmailMtmUiUtils::GetDefaultSecurityPort()
       
   798 // ----------------------------------------------------------------------------
       
   799 //
       
   800 TUint32 MsvEmailMtmUiUtils::GetDefaultSecurityPort(
       
   801     const TIMASMailSecurity aSecurity,
       
   802     const TBool aIncoming,
       
   803     const TBool aIsImap4 )
       
   804     {
       
   805     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::GetDefaultSecurityPort, 0, utils, KLogUi );
       
   806     
       
   807     TUint32 port( 0 ); // this should never be returned
       
   808 
       
   809     switch( aSecurity )
       
   810         {
       
   811         case EImumSecurityOn:
       
   812         case EImumSecurityOff:
       
   813             {
       
   814             if ( aIncoming )
       
   815                 {
       
   816                 port = aIsImap4 ? KIMASDefaultPortImap4 :
       
   817                     KIMASDefaultPortPop3;
       
   818                 }
       
   819             else
       
   820                 {
       
   821                 port = KIMASDefaultPortSmtp;
       
   822                 }
       
   823             }
       
   824             break;
       
   825         case EImumSecurityMs:
       
   826             {
       
   827             if ( aIncoming )
       
   828                 {
       
   829                 port = aIsImap4 ? KIMASDefaultSecurityPortImap4 :
       
   830                     KIMASDefaultSecurityPortPop3;
       
   831                 }
       
   832             else
       
   833                 {
       
   834                 port = KIMASDefaultSecurityPortSmtp;
       
   835                 }
       
   836             }
       
   837             break;
       
   838         default:
       
   839             break;
       
   840         }
       
   841     return port;
       
   842     }
       
   843     
       
   844 // ----------------------------------------------------------------------------
       
   845 // MsvEmailMtmUiUtils::CallNewMessagesL()
       
   846 // ----------------------------------------------------------------------------
       
   847 //
       
   848 EXPORT_C void MsvEmailMtmUiUtils::CallNewMessagesL( const TMsvId aMailboxId )
       
   849     {
       
   850     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::CallNewMessagesL, 0, utils, KLogUi );
       
   851     
       
   852     MNcnInternalNotification* notification = NULL;
       
   853 
       
   854     // Create a dummy array. It is not currently used to anything.
       
   855     CDesCArrayFlat* dummyArray = new (ELeave) CDesCArrayFlat( 1 );
       
   856     CleanupStack::PushL( dummyArray );
       
   857 
       
   858     // No need to tell user, that we could not connect to NCN
       
   859     TRAP_IGNORE( notification =
       
   860         MNcnInternalNotification::CreateMNcnInternalNotificationL() );
       
   861 
       
   862     if ( notification )
       
   863         {
       
   864         // Ignore result, user is not interested about it, hopefully.
       
   865         TInt result = notification->NewMessages(
       
   866             EMailMessage, aMailboxId, *dummyArray );
       
   867         }
       
   868     else
       
   869         {
       
   870         }
       
   871 
       
   872     CleanupStack::PopAndDestroy( dummyArray );
       
   873     dummyArray = NULL;
       
   874     delete notification;
       
   875     notification = NULL;
       
   876 
       
   877     }
       
   878 
       
   879 // ----------------------------------------------------------------------------
       
   880 // MsvEmailMtmUiUtils::LoadResourceFileL()
       
   881 // ----------------------------------------------------------------------------
       
   882 //
       
   883 EXPORT_C void MsvEmailMtmUiUtils::LoadResourceFileL(
       
   884     RConeResourceLoader& aResourceLoader )
       
   885     {
       
   886     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::LoadResourceFileL, 0, utils, KLogUi );
       
   887     
       
   888     RFs fs;
       
   889     CleanupClosePushL(fs);
       
   890     User::LeaveIfError(fs.Connect());
       
   891     TFileName resourceFileName(KIMSDirAndResFileName);
       
   892     BaflUtils::NearestLanguageFile(fs,resourceFileName);
       
   893     CleanupStack::PopAndDestroy( 1 );
       
   894     
       
   895     TFileName fileName;
       
   896     TParse parse;
       
   897     parse.Set( resourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   898     fileName.Copy( parse.FullName() );
       
   899 
       
   900     // Attempt to load the resource
       
   901     aResourceLoader.OpenL( fileName );
       
   902     
       
   903     }
       
   904 
       
   905 // ----------------------------------------------------------------------------
       
   906 // MsvEmailMtmUiUtils::GetMailboxName()
       
   907 // ----------------------------------------------------------------------------
       
   908 //
       
   909 void MsvEmailMtmUiUtils::GetMailboxName(
       
   910     TDes& aDest,
       
   911     CMsvSession& aMsvSession,
       
   912     TMsvId aMailboxId )
       
   913     {
       
   914     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::GetMailboxName, 0, utils, KLogUi );
       
   915     
       
   916     aDest.Zero();
       
   917 
       
   918     // Get mailbox
       
   919     TMsvEntry mailbox;
       
   920     TMsvId serviceId;
       
   921     TInt error = aMsvSession.GetEntry( aMailboxId, serviceId, mailbox );
       
   922 
       
   923     if ( error == KErrNone )
       
   924         {
       
   925         aDest.Copy( mailbox.iDetails.Left( KIMASMaxMailboxNameLength ) );
       
   926         }
       
   927     }
       
   928 
       
   929 // ----------------------------------------------------------------------------
       
   930 // MsvEmailMtmUiUtils::CreateConnectingToText()
       
   931 // ----------------------------------------------------------------------------
       
   932 //
       
   933 EXPORT_C void MsvEmailMtmUiUtils::CreateConnectingToText(
       
   934     TDes& aDest,
       
   935     CMsvSession& aMsvSession,
       
   936     TMsvId aMailboxId )
       
   937     {
       
   938     IMUM_STATIC_CONTEXT( CBaseMtmUi::EProgressStringMaxLen, 0, utils, KLogUi );
       
   939 
       
   940     // Get mailbox name
       
   941     TBuf<KIMASMaxMailboxNameLength> name;
       
   942     MsvEmailMtmUiUtils::GetMailboxName( name,
       
   943         aMsvSession, aMailboxId );
       
   944     
       
   945     // Combine mailbox name with a resource string
       
   946     TRAP_IGNORE( CIMSSettingsNoteUi::MakeStringL( aDest, R_EMAIL_CONNECTING_SERVER,name ) );
       
   947     }
       
   948 
       
   949 // ----------------------------------------------------------------------------
       
   950 // MsvEmailMtmUiUtils::ContinueRenamingL()
       
   951 // ----------------------------------------------------------------------------
       
   952 //
       
   953 TBool MsvEmailMtmUiUtils::ContinueRenamingL( 
       
   954     CImumInternalApi& aMailboxApi,
       
   955     TInt& aResult,
       
   956     TDes& aAccountName, 
       
   957     const TMsvId aOwningMailbox,
       
   958     const TInt aNumber,
       
   959     const CMsvEntry& aAccount,
       
   960     const TBool aGenerate )
       
   961     {
       
   962     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::ContinueRenamingL, 0, utils, KLogUi );
       
   963     
       
   964     // Max number of mailboxes is checked
       
   965     // Allow name generating. This is for Email Wizard, which attempts
       
   966     // to generate the mailbox name. 
       
   967     TBool doContinue = ( aNumber <= KImumMaxMailboxes );
       
   968     
       
   969     // Check if the name is already used
       
   970     if ( doContinue )
       
   971         {
       
   972         doContinue = IsAccountNameUsedL( 
       
   973             aMailboxApi, aResult, aAccountName, aOwningMailbox, aAccount );
       
   974         }         
       
   975     
       
   976     return doContinue && aGenerate;                   
       
   977     }
       
   978     
       
   979 // ----------------------------------------------------------------------------
       
   980 // MsvEmailMtmUiUtils::CheckAccountNameL()
       
   981 // ----------------------------------------------------------------------------
       
   982 //
       
   983 void MsvEmailMtmUiUtils::CheckAccountNameL( 
       
   984     CImumInternalApi& aMailboxApi,      
       
   985     TDes& aAccountName, 
       
   986     const TMsvId aOwningMailbox,   
       
   987     const TBool& aGenerate )
       
   988     {
       
   989     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::CheckAccountNameL, 0, utils, KLogUi );
       
   990     
       
   991     // Remove illegal characters from the name, such as tabulators and enters
       
   992     ReplaceCharacters( aAccountName );
       
   993     
       
   994     // Get entrypoint of the root
       
   995     int result = KErrNone;
       
   996     CMsvSession& session = aMailboxApi.MsvSession();
       
   997     CMsvEntry* root = session.GetEntryL( 
       
   998         KMsvRootIndexEntryIdValue );
       
   999     CleanupStack::PushL( root );
       
  1000 
       
  1001     // Sort the root
       
  1002     root->SetSortTypeL( TMsvSelectionOrdering(
       
  1003         KMsvGroupByType | KMsvGroupByStandardFolders,
       
  1004         EMsvSortByDetailsReverse, ETrue ) );
       
  1005 
       
  1006     // This is the first suggested name of the mailbox
       
  1007     TMuiuSettingsText originalName;
       
  1008     originalName.Copy( aAccountName );
       
  1009 
       
  1010     // Find an account name
       
  1011     TInt mailbox = 0;
       
  1012     for ( TInt number = 1; ContinueRenamingL( 
       
  1013             aMailboxApi, result, aAccountName, aOwningMailbox, 
       
  1014             number, *root, aGenerate );
       
  1015          ++number )
       
  1016         {
       
  1017         // Rename and set the result
       
  1018         result = ChangeAccountNameL(
       
  1019             originalName, aAccountName, ++mailbox );
       
  1020         }
       
  1021 
       
  1022     // User must be notified, when invalid name is offered
       
  1023     if ( result == KErrAlreadyExists && aGenerate )
       
  1024         {
       
  1025         result = KErrNone;
       
  1026         }
       
  1027 
       
  1028     CleanupStack::PopAndDestroy( root );
       
  1029     root = NULL;
       
  1030 
       
  1031     User::LeaveIfError( result ); 
       
  1032     }
       
  1033 
       
  1034 // ----------------------------------------------------------------------------
       
  1035 // MsvEmailMtmUiUtils::IsAccountNameUsedL()
       
  1036 // ----------------------------------------------------------------------------
       
  1037 //
       
  1038 TBool MsvEmailMtmUiUtils::IsAccountNameUsedL(
       
  1039     CImumInternalApi& aMailboxApi,
       
  1040     TInt& aResult,
       
  1041     const TDesC& aAccountName,  
       
  1042     const TMsvId aOwningMailbox,  
       
  1043     const CMsvEntry& aAccount )
       
  1044     {
       
  1045     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::IsAccountNameUsedL, 0, utils, KLogUi );
       
  1046 
       
  1047     FeatureManager::InitializeLibL();
       
  1048 
       
  1049     if(FeatureManager::FeatureSupported(KFeatureIdSelectableEmail))
       
  1050     	{
       
  1051     	// Because the unhealthy mailbox's name is not used.
       
  1052     	// So try to filter the unhealthy mailbox's name.
       
  1053     	aResult = KErrNone;
       
  1054     	}
       
  1055 
       
  1056     const MImumInHealthServices& healthServices = aMailboxApi.HealthServicesL();
       
  1057 
       
  1058     // Search through all the mail account entries until duplicate name
       
  1059     // is found, or all entries are searched through    
       
  1060     TInt item = aAccount.Count();
       
  1061     while ( --item >= 0 && !aResult )
       
  1062         {
       
  1063         const TMsvEntry& entry = aAccount[item];
       
  1064 
       
  1065     	if(FeatureManager::FeatureSupported(KFeatureIdSelectableEmail))
       
  1066     		{
       
  1067     		// If the mailbox is unhealthy, ignore it.
       
  1068     		if ( ( !healthServices.IsMailboxHealthy( entry.Id() ) ) &&
       
  1069     				( !( ( entry.iType == KUidMsvServiceEntry) && 
       
  1070     						( entry.Id() != KMsvLocalServiceIndexEntryId ) && 
       
  1071     						( !MuiuEmailTools::IsMailMtm( entry.iMtm, ETrue ) ) ) ) )
       
  1072     			{
       
  1073     			continue;
       
  1074     			}
       
  1075     		}
       
  1076 
       
  1077         // Interrupt the search if mailbox entry with same name is found
       
  1078         if ( !aAccountName.CompareC( entry.iDetails ) &&
       
  1079              aMailboxApi.MailboxUtilitiesL().IsMailbox( entry ) &&
       
  1080              entry.Id() != aOwningMailbox && 
       
  1081              entry.iRelatedId != aOwningMailbox )
       
  1082             {
       
  1083             aResult = KErrAlreadyExists;
       
  1084             }
       
  1085         else
       
  1086             {
       
  1087             aResult = KErrNone;
       
  1088             }                 
       
  1089         }
       
  1090 
       
  1091     FeatureManager::UnInitializeLib();
       
  1092     
       
  1093     // If mailbox account with the same name is found, return ETrue
       
  1094     return ( aResult == KErrAlreadyExists );
       
  1095     }
       
  1096 
       
  1097 // ----------------------------------------------------------------------------
       
  1098 // MsvEmailMtmUiUtils::ChangeAccountNameL()
       
  1099 // ----------------------------------------------------------------------------
       
  1100 //
       
  1101 TInt MsvEmailMtmUiUtils::ChangeAccountNameL(
       
  1102     const TDesC& aOriginalAccountName,
       
  1103     TDes& aAccountName,    
       
  1104     const TInt aNumber )
       
  1105     {
       
  1106     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::ChangeAccountNameL, 0, utils, KLogUi );
       
  1107     
       
  1108     // Make sure the is enough room in the mailbox name for the string "(%d)"    
       
  1109     const TInt maxLength = 
       
  1110         KImasImailServiceNameLength - KImumExtraStringLength;
       
  1111 
       
  1112     // Remove KISIAExtraStringLength amount of letters from the string in
       
  1113     // case the max length has been exceeded.
       
  1114     if ( aOriginalAccountName.Length() > maxLength )
       
  1115         {
       
  1116         aAccountName.Copy( aAccountName.Left( maxLength ) );
       
  1117         }
       
  1118 
       
  1119     // Add the brackets with number inside to the end of the string
       
  1120     TMuiuSettingsText tempText;
       
  1121     tempText.Copy( aAccountName );
       
  1122     tempText.Format( KImumDefaultNameFormat, &aOriginalAccountName, aNumber );
       
  1123     aAccountName.Copy( tempText );
       
  1124 
       
  1125     return KErrNone;
       
  1126     }    
       
  1127 
       
  1128 // ----------------------------------------------------------------------------
       
  1129 // MsvEmailMtmUiUtils::GetPriorityString()
       
  1130 // ----------------------------------------------------------------------------
       
  1131 //    
       
  1132 void MsvEmailMtmUiUtils::GetPriorityString(
       
  1133     const TMsvEntry& aEntry,
       
  1134     CCoeEnv& aEnv,
       
  1135     TDes& aPriorityBuf ) 
       
  1136     {
       
  1137     IMUM_STATIC_CONTEXT( MsvEmailMtmUiUtils::GetPriorityString, 0, utils, KLogUi );
       
  1138     
       
  1139     TInt emailPriority = EMsvMediumPriority;
       
  1140     emailPriority = aEntry.Priority();
       
  1141         
       
  1142     if ( emailPriority == EMsvHighPriority )
       
  1143         {
       
  1144         StringLoader::Load( aPriorityBuf, R_IMAS_MESSAGE_INFO_PRIORITY_HIGH, &aEnv );
       
  1145         }
       
  1146     else if ( emailPriority == EMsvLowPriority )
       
  1147         {                                          
       
  1148         StringLoader::Load( aPriorityBuf, R_IMAS_MESSAGE_INFO_PRIORITY_LOW, &aEnv );
       
  1149         }
       
  1150     else
       
  1151         { 
       
  1152         StringLoader::Load( aPriorityBuf, R_IMAS_MESSAGE_INFO_PRIORITY_NORMAL, &aEnv );
       
  1153         }    
       
  1154     }
       
  1155 
       
  1156 // End of File
       
  1157 
       
  1158