ipsservices/ipssosplugin/src/ipsplgsosbaseplugin.cpp
branchRCL_3
changeset 24 d189ee25cf9d
parent 23 dcf0eedfc1a3
child 25 3533d4323edc
equal deleted inserted replaced
23:dcf0eedfc1a3 24:d189ee25cf9d
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 #include "emailtrace.h"
    18 #include "emailtrace.h"
    19 #include "ipsplgheaders.h"
    19 #include "ipsplgheaders.h"
    20 #include "FreestyleEmailUiConstants.h"
    20 
    21 
    21 // <qmail> FreestyleEmailUiConstants include removed
    22 #define FREESTYLE_EMAIL_UI_SID 0x2001E277
    22 
       
    23 // <qmail>
       
    24 #include "ipsplgsosbaseplugin.hrh"
       
    25 #include "ipsplgmailstoreroperation.h"
       
    26 #include "ipsplgmessagepartstoreroperation.h"
       
    27 #include "BasePlugin.h" 
       
    28 //<Qmail>
       
    29 #include "ipssosextendedsettingsmanager.h"
       
    30 #include "ipssettingkeys.h"
       
    31 //</Qmail>
       
    32 //</qmail>
       
    33 
       
    34 #define FREESTYLE_EMAIL_UI_SID 0x200255BA
    23 
    35 
    24 const TInt KOpGranularity = 2;
    36 const TInt KOpGranularity = 2;
    25 
    37 
    26 _LIT( KMimeTextCalRequest,  "text/calendar; method=REQUEST;" );
    38 // <qmail> remove unused literals
    27 _LIT( KMimeTextCalResponse, "text/calendar; method=RESPONSE;" );
       
    28 _LIT( KMimeTextCalCancel,   "text/calendar; method=CANCEL;" );
       
    29 _LIT8( KMethod, "method" );
       
    30 _LIT8( KRequest, "REQUEST" );
       
    31 _LIT8( KResponse, "RESPONSE" );
       
    32 _LIT8( KCancel, "CANCEL" );
       
    33 _LIT( KLineFeed, "\r\n");
       
    34 
    39 
    35 #ifdef __WINS__
    40 #ifdef __WINS__
    36 _LIT( KEmulatorIMEI, "123456789012345" );
    41 _LIT( KEmulatorIMEI, "123456789012345" );
    37 #endif // __WINS__
    42 #endif // __WINS__
    38 
    43 
    39 // ----------------------------------------------------------------------------
    44 //<Qmail>
    40 // ----------------------------------------------------------------------------
    45 // ----------------------------------------------------------------------------
    41 //
    46 // ----------------------------------------------------------------------------
       
    47 void CIpsPlgSosBasePlugin::ActiveFolderChanged(
       
    48         const TFSMailMsgId& aActiveMailboxId,
       
    49         const TFSMailMsgId& aActiveFolderId)
       
    50     {
       
    51     TRAP_IGNORE( HandleActiveFolderChangeL(aActiveMailboxId,aActiveFolderId) );
       
    52     }
       
    53 
       
    54 
       
    55 // ----------------------------------------------------------------------------
       
    56 // ----------------------------------------------------------------------------
       
    57 CEmailExtension* CIpsPlgSosBasePlugin::ExtensionL( const TUid& aInterfaceUid )
       
    58     {
       
    59     if(aInterfaceUid != KEmailMailboxStateExtensionUid)
       
    60         {
       
    61         User::Leave(KErrNotSupported);
       
    62         }
       
    63     
       
    64     return iStateExtension;
       
    65     }
       
    66 //</Qmail>
       
    67 // ----------------------------------------------------------------------------
       
    68 // ----------------------------------------------------------------------------
       
    69 // <qmail> iSettingsApi removed
    42 CIpsPlgSosBasePlugin::CIpsPlgSosBasePlugin( const TUint aFSPluginId ) :
    70 CIpsPlgSosBasePlugin::CIpsPlgSosBasePlugin( const TUint aFSPluginId ) :
    43     iFSPluginId( aFSPluginId ),
    71     iFSPluginId( aFSPluginId ),
    44     iSession( NULL ),
    72     iSession( NULL ),
    45     iMsgMapper( NULL ),
    73     iMsgMapper( NULL ),
    46     iOperations( KOpGranularity ),
    74     iOperations( KOpGranularity ),
    48     iSmtpService( NULL ),
    76     iSmtpService( NULL ),
    49     iCachedEntry( NULL ),
    77     iCachedEntry( NULL ),
    50     iCachedEmailMessage( NULL ),
    78     iCachedEmailMessage( NULL ),
    51     iMruList( NULL ),
    79     iMruList( NULL ),
    52     iSearch( NULL ),
    80     iSearch( NULL ),
    53     iSettingsApi( NULL ),
       
    54     iEventHandler( NULL ),
    81     iEventHandler( NULL ),
    55     iSessionOk( ETrue ),
    82     iSessionOk( ETrue ),
    56     iBrandingId( NULL ),
    83     iBrandingId( NULL ),
    57     iIsUnderUiProcess( EFalse )
    84     iIsUnderUiProcess( EFalse )
    58     {
    85     {
    59     FUNC_LOG;
    86     FUNC_LOG;
    60     }
    87     }
    61 
    88 
    62 // ----------------------------------------------------------------------------
    89 // ----------------------------------------------------------------------------
    63 // ----------------------------------------------------------------------------
    90 // ----------------------------------------------------------------------------
    64 //
    91 // <qmail> iSettingsApi, iWait removed
    65 CIpsPlgSosBasePlugin::~CIpsPlgSosBasePlugin()
    92 CIpsPlgSosBasePlugin::~CIpsPlgSosBasePlugin()
    66     {
    93     {
    67     FUNC_LOG;
    94     FUNC_LOG;
    68     if ( iMsvOpDeleteMessage )
       
    69         {
       
    70         iMsvOpDeleteMessage->Cancel();
       
    71         }
       
    72     
       
    73     if ( iWaitDeleteMessage )
       
    74         {
       
    75         iWaitDeleteMessage->Cancel();
       
    76         }
       
    77     
       
    78     delete iMsvOpDeleteMessage;
       
    79     iMsvOpDeleteMessage = NULL;
       
    80     delete iWaitDeleteMessage;
       
    81     iWaitDeleteMessage = NULL;
       
    82     delete icEntry;
       
    83     icEntry = NULL;
       
    84     if ( iWait.IsStarted() )
       
    85         {
       
    86         iWait.AsyncStop();
       
    87         }
       
    88 
       
    89     iOperations.ResetAndDestroy();
    95     iOperations.ResetAndDestroy();
    90     iActivitytimers.ResetAndDestroy();
    96     iActivitytimers.ResetAndDestroy();
    91     iOperations.Close();
    97     iOperations.Close();
    92     iActivitytimers.Close();
    98     iActivitytimers.Close();
    93     delete iSmtpService;
    99     delete iSmtpService;
    94     delete iMruList;
   100     delete iMruList;
    95     if ( iEventHandler )
   101     if ( iEventHandler )
    96         {
   102         {
    97         iEventHandler->UnRegisterPropertyObserver( iSyncStateHandler );
   103         iEventHandler->UnRegisterPropertyObserver( iSyncStateHandler );
    98         }
   104         }
       
   105     delete iStateExtension;
    99     delete iEventHandler;
   106     delete iEventHandler;
   100     delete iCachedEntry;
   107     delete iCachedEntry;
   101     delete iCachedEmailMessage;
   108     delete iCachedEmailMessage;
   102     delete iMsgMapper;
   109     delete iMsgMapper;
   103     delete iSearch;
   110     delete iSearch;
   104     delete iSettingsApi;
       
   105     delete iSyncStateHandler;
   111     delete iSyncStateHandler;
   106     delete iSession;
   112     delete iSession;
   107     delete iBrandingId;
   113     delete iBrandingId;
   108     }
   114     }
   109 
   115 
   110 // ----------------------------------------------------------------------------
   116 // ----------------------------------------------------------------------------
   111 // ----------------------------------------------------------------------------
   117 // ----------------------------------------------------------------------------
   112 void CIpsPlgSosBasePlugin::BaseConstructL()
   118 void CIpsPlgSosBasePlugin::BaseConstructL()
   113     {
   119     {
   114     FUNC_LOG;
   120     FUNC_LOG;
       
   121     iStateExtension = CIpsStateExtension::NewL(*this);
   115     iEventHandler = CIpsPlgEventHandler::NewL( *this );
   122     iEventHandler = CIpsPlgEventHandler::NewL( *this );
   116     iSession = CMsvSession::OpenAsyncL( *iEventHandler );
   123     iSession = CMsvSession::OpenAsyncL( *iEventHandler );
   117     iMsgMapper = CIpsPlgMsgMapper::NewL( *iSession, *this );
   124     iMsgMapper = CIpsPlgMsgMapper::NewL( *iSession, *this );
   118     iSmtpService = CIpsPlgSmtpService::NewL( *iSession, *this );
   125     iSmtpService = CIpsPlgSmtpService::NewL( *iSession, *this );
   119     iMruList = CIpsPlgMruList::NewL( );
   126     iMruList = CIpsPlgMruList::NewL( );
   120     iSearch = CIpsPlgSearch::NewL( *iSession, *this );
   127     iSearch = CIpsPlgSearch::NewL( *iSession, *this );
   121     iSettingsApi = CIpsSetDataApi::NewL( *iSession );
   128 	// <qmail> iSettingsApi removed
   122     iSettingsApi->GetIMEIFromThePhoneL( iIMEI );
       
   123     iSyncStateHandler = CIpsPlgSyncStateHandler::NewL(
   129     iSyncStateHandler = CIpsPlgSyncStateHandler::NewL(
   124             *iSession, *this, iOperations );
   130             *iSession, *this, iOperations );
   125     iEventHandler->RegisterPropertyObserverL( iSyncStateHandler );
   131     iEventHandler->RegisterPropertyObserverL( iSyncStateHandler );
   126 
   132 
   127     RProcess process;
   133     RProcess process;
   131         }
   137         }
   132     else
   138     else
   133         {
   139         {
   134         iIsUnderUiProcess = EFalse;
   140         iIsUnderUiProcess = EFalse;
   135         }
   141         }
       
   142 
       
   143 #ifndef RD_101_EMAIL
   136     RAlwaysOnlineClientSession aosession;
   144     RAlwaysOnlineClientSession aosession;
   137     TInt err = aosession.Connect();
   145     TInt err = aosession.Connect();
   138     if ( err == KErrNone )
   146     if ( err == KErrNone )
   139         {
   147         {
   140         TBuf8<1> dummyBuf;
   148         TBuf8<1> dummyBuf;
   141         TRAP( err, aosession.RelayCommandL(
   149         TRAP( err, aosession.RelayCommandL(
   142                 EServerAPIEmailDisableAOEmailPlugin,
   150                 EServerAPIEmailDisableAOEmailPlugin,
   143                 dummyBuf ) );
   151                 dummyBuf ) );
   144         }
   152         }
   145     aosession.Close();
   153     aosession.Close();
       
   154 #endif    
   146     }
   155     }
   147 
   156 
   148 // ----------------------------------------------------------------------------
   157 // ----------------------------------------------------------------------------
   149 // ----------------------------------------------------------------------------
   158 // ----------------------------------------------------------------------------
   150 void CIpsPlgSosBasePlugin::CompleteConstructL()
   159 void CIpsPlgSosBasePlugin::CompleteConstructL()
   178 
   187 
   179         if ( oper.Id() == opId )
   188         if ( oper.Id() == opId )
   180             {
   189             {
   181             DeleteAndRemoveOperation( i, aCompletionCode );
   190             DeleteAndRemoveOperation( i, aCompletionCode );
   182             }
   191             }
   183         }
   192 
   184     // make draft deletion synchronous so that empty drafts are not left after application close.
   193 // <qmail> iWait removed
   185     if ( iWait.IsStarted() )
       
   186         {
       
   187         iWait.AsyncStop();
       
   188         }
   194         }
   189     }
   195     }
   190 
   196 
   191 // ----------------------------------------------------------------------------
   197 // ----------------------------------------------------------------------------
   192 // ----------------------------------------------------------------------------
   198 // ----------------------------------------------------------------------------
   202         iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
   208         iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
   203 
   209 
   204         if ( tEntry.Connected() )
   210         if ( tEntry.Connected() )
   205             {
   211             {
   206             status = EFSMailBoxOnline;
   212             status = EFSMailBoxOnline;
   207             }			
   213             }
   208 		else
   214         else if ( ConnOpRunning( aMailBoxId ) )
       
   215             {
       
   216             status = EFSMailBoxOnline;
       
   217             }
       
   218         else
   209             {
   219             {
   210             status = EFSMailBoxOffline;
   220             status = EFSMailBoxOffline;
   211             }
   221             }
   212         }
   222         }
   213     else
   223     else
   299         result = CFSMailBox::NewL( aMailBoxId );
   309         result = CFSMailBox::NewL( aMailBoxId );
   300         CleanupStack::PushL( result );   // << result
   310         CleanupStack::PushL( result );   // << result
   301         result->SetName( tEntry.iDetails );
   311         result->SetName( tEntry.iDetails );
   302         result->SetSettingsUid( TUid::Uid( IPS_SET_ECOM_IMPLEMENTATION_UID ) );
   312         result->SetSettingsUid( TUid::Uid( IPS_SET_ECOM_IMPLEMENTATION_UID ) );
   303 
   313 
   304         iSettingsApi->GetMailboxAddressL( tEntry, address );
   314 // <qmail>
       
   315         CEmailAccounts* acc = CEmailAccounts::NewLC();
       
   316         TSmtpAccount smtpAcc;
       
   317         acc->GetSmtpAccountL( tEntry.iRelatedId , smtpAcc );
       
   318         CImSmtpSettings* smtpSet = new (ELeave) CImSmtpSettings();
       
   319         CleanupStack::PushL( smtpSet );
       
   320         acc->LoadSmtpSettingsL( smtpAcc, *smtpSet );
       
   321         address = smtpSet->EmailAddress().AllocL();
       
   322         CleanupStack::PopAndDestroy( 2, acc );
       
   323 // </qmail>
       
   324         
   305         CleanupStack::PushL( address ); // << address
   325         CleanupStack::PushL( address ); // << address
   306         CFSMailAddress* fsAddress = CFSMailAddress::NewLC();    // << fsAddress
   326         CFSMailAddress* fsAddress = CFSMailAddress::NewLC();    // << fsAddress
   307         fsAddress->SetEmailAddress( *address );
   327         fsAddress->SetEmailAddress( *address );
   308         result->SetOwnMailAddressL( fsAddress );
   328         result->SetOwnMailAddressL( fsAddress );
   309         CleanupStack::Pop( fsAddress ); // >> fsAddress
   329         CleanupStack::Pop( fsAddress ); // >> fsAddress
   326     TMsvId service;
   346     TMsvId service;
   327     if( !iSessionOk )
   347     if( !iSessionOk )
   328         {
   348         {
   329         User::Leave( KErrNotReady );
   349         User::Leave( KErrNotReady );
   330         }
   350         }
   331 
   351     
   332     // Create connection to Always Online
   352 // <qmail> RAlwaysOnlineClientSession - related code removed
   333     RAlwaysOnlineClientSession aosess;
       
   334     User::LeaveIfError( aosess.Connect() );
       
   335 
       
   336     // Prepare the parameters to be forwarded to AO-server
   353     // Prepare the parameters to be forwarded to AO-server
   337     TPckg<TMsvId> param = aMailBoxId.Id();
   354     TPckg<TMsvId> param = aMailBoxId.Id();
   338 
   355 
   339     // Send message to server and close it
       
   340     TRAP_IGNORE( aosess.RelayCommandL( EServerAPIEmailAgentRemove, param ) );
       
   341     aosess.Close();
       
   342 
       
   343     // delete MRU list from cen rep
   356     // delete MRU list from cen rep
   344     iMruList->ClearDataL( aMailBoxId );
   357     iMruList->ClearDataL( aMailBoxId );
   345 
   358 
   346     iSyncStateHandler->NotifyMailboxRemove( aMailBoxId.Id() );
   359     iSyncStateHandler->NotifyMailboxRemove( aMailBoxId.Id() );
   347 
   360 
   348     CancelAllOnlineOperations( aMailBoxId );
   361 // <qmail> CancelAllOnlineOperations function call removed
   349 
       
   350     iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
   362     iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
   351     if ( tEntry.Connected() )
   363     if ( tEntry.Connected() )
   352         {
   364         {
   353         DisconnectL( aMailBoxId, aOperationObserver, aRequestId, ETrue );
   365         DisconnectL( aMailBoxId, aOperationObserver, aRequestId, ETrue );
   354 
   366 
   366                 }
   378                 }
   367             }
   379             }
   368         }
   380         }
   369     else
   381     else
   370         {
   382         {
   371         iSettingsApi->RemoveAccountL( tEntry, *iSession );
   383 // <qmail> iSettingsApi removed
   372         TFSProgress progress = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   384         TFSProgress progress = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   373         progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
   385         progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
   374         progress.iError = KErrNone;
   386         progress.iError = KErrNone;
   375         TInt requestId = aRequestId;
   387         TInt requestId = aRequestId;
   376         aOperationObserver.RequestResponseL( progress, requestId );
   388         aOperationObserver.RequestResponseL( progress, requestId );
   386     FUNC_LOG;
   398     FUNC_LOG;
   387     if( !iSessionOk )
   399     if( !iSessionOk )
   388         {
   400         {
   389         User::Leave( KErrNotReady );
   401         User::Leave( KErrNotReady );
   390         }
   402         }
   391     
   403     CMsvEntry* mboxEntry = iSession->GetEntryL( aMailBoxId.Id() );
   392     TMsvEntry tEntry;
   404     CleanupStack::PushL( mboxEntry );
   393     TMsvId serviceId;
   405 
   394     TInt status = iSession->GetEntry( aMailBoxId.Id(), serviceId, tEntry );
   406 // <qmail> iSettingsApi removed, iBrandingId removed
   395  
   407     CleanupStack::PopAndDestroy( mboxEntry );
   396     if ( status == KErrNone )
   408 
   397         {
       
   398         HBufC* address( NULL );
       
   399         iSettingsApi->GetMailboxAddressL( tEntry, address );
       
   400         CleanupStack::PushL( address );
       
   401         TPtrC ptr = address->Des();
       
   402         TInt index = ptr.Locate('@') + 1;
       
   403         if( index > 0 && ptr.Length() > 0 )
       
   404             {
       
   405             if( iBrandingId )
       
   406                 {
       
   407                 delete iBrandingId;
       
   408                 iBrandingId = NULL;
       
   409                 }
       
   410             ptr.Set( ptr.Right( ptr.Length() - index ) );        
       
   411             iBrandingId = HBufC::NewL( ptr.Length() );
       
   412             iBrandingId->Des().Copy( ptr );
       
   413             }
       
   414         CleanupStack::PopAndDestroy( address );
       
   415         }    
       
   416     
       
   417     return *iBrandingId;
   409     return *iBrandingId;
   418     }
   410     }
   419 
   411 
   420 // ----------------------------------------------------------------------------
   412 // ----------------------------------------------------------------------------
   421 // Pop3 has no implementation for this virtual
   413 // Pop3 has no implementation for this virtual
   425     const RArray<TFSMailMsgId>& aMessageIds,
   417     const RArray<TFSMailMsgId>& aMessageIds,
   426     const TFSMailMsgId& aSourceFolderId,
   418     const TFSMailMsgId& aSourceFolderId,
   427     const TFSMailMsgId& aDestinationFolderId )
   419     const TFSMailMsgId& aDestinationFolderId )
   428 	{
   420 	{
   429     FUNC_LOG;
   421     FUNC_LOG;
       
   422 	// Pop3 has no implementation for this virtual
   430 	if( aDestinationFolderId.Id() == KMsvDraftEntryId  )
   423 	if( aDestinationFolderId.Id() == KMsvDraftEntryId  )
   431 	    {
   424 	    {
   432 	    MoveMessagesToDraftL(
   425 	    MoveMessagesToDraftL(
   433 	        aMailBoxId,
   426 	        aMailBoxId,
   434 	        aMessageIds,
   427 	        aMessageIds,
   523             sel->AppendL( tEntry.Id() );
   516             sel->AppendL( tEntry.Id() );
   524             }
   517             }
   525         }
   518         }
   526     if( sel->Count() )
   519     if( sel->Count() )
   527         {
   520         {
   528         CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC();
   521         // <qmail> remove activeschedulerwait
       
   522         TMsvLocalOperationProgress progress;
   529         if( !aSourceFolderId.IsNullId() )
   523         if( !aSourceFolderId.IsNullId() )
   530             {
   524             {
   531             CMsvEntry* cEntry = iSession->GetEntryL( aSourceFolderId.Id() );
   525             CMsvEntry* cEntry = iSession->GetEntryL( aSourceFolderId.Id() );
   532             CleanupStack::PushL( cEntry );
   526             CleanupStack::PushL( cEntry );
   533             cEntry->MoveL(
   527             cEntry->MoveL( *sel, aDestinationFolderId.Id(), progress );
   534                 *sel,
       
   535                            aDestinationFolderId.Id(),//KMsvDraftEntryIdValue
       
   536                            wait->iStatus );
       
   537 
       
   538             CleanupStack::PopAndDestroy( cEntry );
   528             CleanupStack::PopAndDestroy( cEntry );
   539             }
   529             }
   540         else
   530         else
   541             {
   531             {
   542             // Message is in editing state, we can't use parent as entry
   532             // Message is in editing state, we can't use parent as entry
   543             // because it's equal to destination.
   533             // because it's equal to destination.
   544             TMsvId parent = msgEntry->Entry().Parent();
   534             TMsvId parent = msgEntry->Entry().Parent();
   545             msgEntry->SetEntryL( parent );
   535             msgEntry->SetEntryL( parent );
   546             msgEntry->CopyL(
   536             msgEntry->CopyL( *sel, aDestinationFolderId.Id(), progress );
   547                 *sel,
   537             }
   548                              aDestinationFolderId.Id(),//KMsvDraftEntryIdValue
   538         User::LeaveIfError( progress.iError );
   549                              wait->iStatus );
   539         // </qmail>
   550             }
       
   551         wait->Start();
       
   552         CleanupStack::PopAndDestroy( wait ); // wait
       
   553         }
   540         }
   554     CleanupStack::PopAndDestroy( 2, sel ); // msgEntry, sel
   541     CleanupStack::PopAndDestroy( 2, sel ); // msgEntry, sel
   555     }
   542     }
   556 
   543 
   557 // ----------------------------------------------------------------------------
   544 // ----------------------------------------------------------------------------
   616     if( !iSessionOk )
   603     if( !iSessionOk )
   617         {
   604         {
   618         User::Leave( KErrNotReady );
   605         User::Leave( KErrNotReady );
   619         }
   606         }
   620     iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
   607     iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
   621 
   608 // <qmail>
   622     TInt state = iSettingsApi->GetLastSyncStatusL( tEntry );
   609     TInt state(0);
   623 
   610 // </qmail>
   624     switch( state )
   611     switch( state )
   625         {
   612         {
   626         case ESyncFinishedSuccessfully:
   613         case ESyncFinishedSuccessfully:
   627             progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
   614             progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
   628             break;
   615             break;
   653         {
   640         {
   654         const CIpsPlgBaseOperation* baseOp =
   641         const CIpsPlgBaseOperation* baseOp =
   655             iOperations[i]->BaseOperation();
   642             iOperations[i]->BaseOperation();
   656         if ( baseOp && baseOp->FSMailboxId() == aMailBoxId &&
   643         if ( baseOp && baseOp->FSMailboxId() == aMailBoxId &&
   657                ( baseOp->IpsOpType() == EIpsOpTypePop3SyncOp
   644                ( baseOp->IpsOpType() == EIpsOpTypePop3SyncOp
   658                 || baseOp->IpsOpType() == EIpsOpTypePop3PopulateOp		   
       
   659                 || baseOp->IpsOpType() == EIpsOpTypeImap4SyncOp
   645                 || baseOp->IpsOpType() == EIpsOpTypeImap4SyncOp
   660                 || baseOp->IpsOpType() == EIpsOpTypeImap4PopulateOp ) )
   646                 || baseOp->IpsOpType() == EIpsOpTypeImap4PopulateOp ) )
   661             {
   647             {
   662             DeleteAndRemoveOperation( i, KErrCancel );
   648             DeleteAndRemoveOperation( i, KErrCancel );
   663             }
   649             }
   664         }
   650         }
   665 /** <should be commented out until AO Manager API enhancements are back ported>
   651     
       
   652 #ifndef RD_101_EMAIL    
   666     RAlwaysOnlineClientSession aosession;
   653     RAlwaysOnlineClientSession aosession;
   667     err = aosession.Connect();
   654     err = aosession.Connect();
   668     if ( err == KErrNone )
   655     if ( err == KErrNone )
   669         {
   656         {
   670         TPckgBuf<TMsvId> buf(aMailBoxId.Id());
   657         TPckgBuf<TMsvId> buf(aMailBoxId.Id());
   671         TRAP( err, aosession.RelayCommandL(
   658         TRAP( err, aosession.RelayCommandL( 
   672                 EServerAPIEmailCancelAllAndDoNotDisconnect, buf ) );
   659                 EServerAPIEmailCancelAllAndDoNotDisconnect, buf ) );
   673         }
   660         }
   674     aosession.Close();
   661     aosession.Close();
   675     */
   662 #endif    
   676 
   663 
   677     return err;
   664     return err;
   678     }
   665     }
   679 
   666 
   680 // ----------------------------------------------------------------------------
   667 // ----------------------------------------------------------------------------
   836 	}
   823 	}
   837 
   824 
   838 // ----------------------------------------------------------------------------
   825 // ----------------------------------------------------------------------------
   839 // ----------------------------------------------------------------------------
   826 // ----------------------------------------------------------------------------
   840  CFSMailMessage* CIpsPlgSosBasePlugin::CreateMessageToSendL(
   827  CFSMailMessage* CIpsPlgSosBasePlugin::CreateMessageToSendL(
   841     const TFSMailMsgId& aMailBoxId )
   828     const TFSMailMsgId& /*aMailBoxId*/ )
   842 	{
   829 	{
   843     FUNC_LOG;
   830     // <qmail> not used any more
   844     CFSMailMessage* msg = iSmtpService->CreateNewSmtpMessageL( aMailBoxId );
   831     User::Leave(KErrFSMailPluginNotSupported);
   845 	return msg;
   832     return NULL; // prevents compiler warning
   846 	}
   833 	}
   847 
   834 
       
   835 // <qmail>
       
   836 // ----------------------------------------------------------------------------
       
   837 // ----------------------------------------------------------------------------
       
   838 void CIpsPlgSosBasePlugin::CreateMessageToSendL( const TFSMailMsgId& aMailBoxId,
       
   839                                     MFSMailRequestObserver& aOperationObserver,
       
   840                                     const TInt aRequestId )
       
   841     {
       
   842     FUNC_LOG;
       
   843     // asynchronous message creation is started here to enable canceling of the operation
       
   844     TMsvPartList partList( KMsvMessagePartBody );
       
   845     
       
   846     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewLC(*this);
       
   847 
       
   848     //<qmail> removed mboxEntry from parameters + changed iSmtpService to pointer 
       
   849     
       
   850     CIpsPlgCreateMessageOperation* op = CIpsPlgCreateMessageOperation::NewL( 
       
   851         *iSmtpService, 
       
   852         *iSession,
       
   853         watcher->iStatus,
       
   854         partList, 
       
   855         aMailBoxId, 
       
   856         aOperationObserver, 
       
   857         aRequestId );
       
   858     //</qmail>
       
   859     watcher->SetOperation( op );
       
   860 
       
   861     iOperations.AppendL( watcher ); 
       
   862     CleanupStack::Pop( watcher );    
       
   863     }
       
   864 // </qmail> 
       
   865  
   848 // ----------------------------------------------------------------------------
   866 // ----------------------------------------------------------------------------
   849 // ----------------------------------------------------------------------------
   867 // ----------------------------------------------------------------------------
   850 CFSMailMessage* CIpsPlgSosBasePlugin::CreateForwardMessageL(
   868 CFSMailMessage* CIpsPlgSosBasePlugin::CreateForwardMessageL(
       
   869     const TFSMailMsgId& /*aMailBoxId*/,
       
   870     const TFSMailMsgId& /*aOriginalMessageId*/,
       
   871     const TDesC& /*aHeaderDescriptor*/ )
       
   872     {
       
   873     // <qmail> not used any more
       
   874     User::Leave(KErrFSMailPluginNotSupported);
       
   875     return NULL; // prevents compiler warning
       
   876     }
       
   877 
       
   878 // <qmail>
       
   879 // ----------------------------------------------------------------------------
       
   880 // ----------------------------------------------------------------------------
       
   881 void CIpsPlgSosBasePlugin::CreateForwardMessageL( 
   851     const TFSMailMsgId& aMailBoxId,
   882     const TFSMailMsgId& aMailBoxId,
   852     const TFSMailMsgId& aOriginalMessageId,
   883     const TFSMailMsgId& aOriginalMessageId,
   853     const TDesC& aHeaderDescriptor )
   884     MFSMailRequestObserver& aOperationObserver,
   854     {
   885     const TInt aRequestId,
   855     FUNC_LOG;
   886     const TDesC& /*aHeaderDescriptor*/ )
   856     CFSMailMessage* msg = iSmtpService->CreateForwardSmtpMessageL(
   887     {
   857         aMailBoxId, aOriginalMessageId );
   888     FUNC_LOG;
   858     
   889     // asynchronous message creation is started here to enable canceling of the operation
   859     if ( aHeaderDescriptor != KNullDesC )
   890     
   860         {
   891     // 1. part of function checs that body text and all
   861         // Ignoring trap as it is better to provide something in case of the
   892     // attachments are fetched
   862         // below fix method fails than nothing.
   893     TMsvEntry orgMsg;
   863         TRAP_IGNORE( FixReplyForwardHeaderL( 
   894     TMsvId service;
   864                         msg, 
   895     User::LeaveIfError( iSession->GetEntry( 
   865                         aMailBoxId, 
   896             aOriginalMessageId.Id(), service, orgMsg ) );
   866                         aOriginalMessageId, 
   897     
   867                         aHeaderDescriptor ) );
   898     if ( orgMsg.Id() ==  KMsvNullIndexEntryIdValue )
   868         }
   899         {
   869   
   900         User::Leave(KErrNotFound);
   870     return msg;
   901         }
   871     }
   902     
   872 
   903     if ( ( orgMsg.Parent() == KMsvSentEntryIdValue ) && 
   873 // ----------------------------------------------------------------------------
   904          ( orgMsg.iMtm == KSenduiMtmSmtpUid ) )
   874 // ----------------------------------------------------------------------------
   905         {
   875 CFSMailMessage* CIpsPlgSosBasePlugin::CreateReplyMessageL(
   906         iSmtpService->ChangeServiceIdL( orgMsg );
       
   907         }
       
   908     
       
   909     TMsvPartList partList( KMsvMessagePartBody | KMsvMessagePartAttachments );
       
   910     
       
   911     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewLC(*this);
       
   912     
       
   913     //<qmail> changed iSmtpService to pointer
       
   914     CIpsPlgCreateForwardMessageOperation* op = CIpsPlgCreateForwardMessageOperation::NewL( 
       
   915         *iSmtpService, 
       
   916         *iSession,
       
   917         watcher->iStatus,
       
   918         partList, 
       
   919         aMailBoxId, 
       
   920         orgMsg.Id(), 
       
   921         aOperationObserver, 
       
   922         aRequestId );
       
   923     //</qmail>
       
   924     watcher->SetOperation( op );
       
   925 
       
   926     iOperations.AppendL( watcher ); 
       
   927     CleanupStack::Pop( watcher );
       
   928     }
       
   929 // </qmail> 
       
   930 
       
   931 // ----------------------------------------------------------------------------
       
   932 // ---------------------------------------------------------------------------- 	
       
   933 CFSMailMessage* CIpsPlgSosBasePlugin::CreateReplyMessageL( 
       
   934     const TFSMailMsgId& /*aMailBoxId*/,
       
   935     const TFSMailMsgId& /*aOriginalMessageId*/,
       
   936     const TBool /*aReplyToAll*/,
       
   937     const TDesC& /*aHeaderDescriptor*/ )
       
   938     {
       
   939     // <qmail> not used any more
       
   940     User::Leave(KErrFSMailPluginNotSupported);
       
   941     return NULL; // prevents compiler warning
       
   942     }
       
   943 
       
   944 // <qmail>
       
   945 // ----------------------------------------------------------------------------
       
   946 // ---------------------------------------------------------------------------- 	
       
   947 void CIpsPlgSosBasePlugin::CreateReplyMessageL( 
   876     const TFSMailMsgId& aMailBoxId,
   948     const TFSMailMsgId& aMailBoxId,
   877     const TFSMailMsgId& aOriginalMessageId,
   949     const TFSMailMsgId& aOriginalMessageId,
   878     const TBool aReplyToAll,
   950     const TBool aReplyToAll,
   879     const TDesC& aHeaderDescriptor )
   951     MFSMailRequestObserver& aOperationObserver,
   880     {
   952     const TInt aRequestId,
   881     FUNC_LOG;
   953     const TDesC& /* aHeaderDescriptor */ )
   882     CFSMailMessage* msg = iSmtpService->CreateReplySmtpMessageL(
   954     {
   883         aMailBoxId, aOriginalMessageId, aReplyToAll );
   955     FUNC_LOG;
   884 
   956     // asynchronous message creation is started here to enable canceling of the operation
   885     if ( aHeaderDescriptor != KNullDesC )
   957     
   886         {
   958     // find orginal message header and check that body is fetched
   887         // Ignoring trap as it is better to provide something in case of the
   959     TMsvEntry orgMsg;
   888         // below fix method fails than nothing.
   960     TMsvId service;
   889         TRAP_IGNORE( FixReplyForwardHeaderL( 
   961     User::LeaveIfError( 
   890                                 msg, 
   962         iSession->GetEntry( aOriginalMessageId.Id(), service, orgMsg ) );
   891                                 aMailBoxId, 
   963     
   892                                 aOriginalMessageId, 
   964     if ( orgMsg.Id() ==  KMsvNullIndexEntryIdValue )
   893                                 aHeaderDescriptor ) );
   965         {
   894         }
   966         User::Leave(KErrNotFound);
   895 
   967         }
   896     return msg;
   968     
   897     }
   969     if ( ( orgMsg.Parent() == KMsvSentEntryIdValue ) && 
   898 
   970          ( orgMsg.iMtm == KSenduiMtmSmtpUid ) )
   899 // ----------------------------------------------------------------------------
   971         {
   900 // ----------------------------------------------------------------------------
   972         iSmtpService->ChangeServiceIdL( orgMsg );
   901 //
   973         }
   902 void CIpsPlgSosBasePlugin::StoreMessageL(
   974     
       
   975     // partList flags control e.g. what kind of recipient set is created
       
   976     TMsvPartList partList = KMsvMessagePartBody | KMsvMessagePartDescription
       
   977     | KMsvMessagePartOriginator;        
       
   978     if( aReplyToAll )
       
   979         {
       
   980         partList |= KMsvMessagePartRecipient;
       
   981         }
       
   982     
       
   983     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewLC(*this);
       
   984     
       
   985     //<qmail> changed iSmtpService to pointer
       
   986     CIpsPlgCreateReplyMessageOperation* op = CIpsPlgCreateReplyMessageOperation::NewL( 
       
   987         *iSmtpService, 
       
   988         *iSession,
       
   989         watcher->iStatus,
       
   990         partList, 
       
   991         aMailBoxId, 
       
   992         orgMsg.Id(), 
       
   993         aOperationObserver, 
       
   994         aRequestId );
       
   995     //</qmail>
       
   996     watcher->SetOperation( op );
       
   997 
       
   998     iOperations.AppendL( watcher ); 
       
   999     CleanupStack::Pop( watcher );
       
  1000     }
       
  1001 // </qmail>
       
  1002 
       
  1003 // ----------------------------------------------------------------------------
       
  1004 // ---------------------------------------------------------------------------- 	
       
  1005 //	
       
  1006 void CIpsPlgSosBasePlugin::StoreMessageL( 
   903     const TFSMailMsgId& aMailBoxId,
  1007     const TFSMailMsgId& aMailBoxId,
   904     CFSMailMessage& aMessage )
  1008     CFSMailMessage& aMessage )
   905  	{
  1009  	{
   906     FUNC_LOG;
  1010     FUNC_LOG;
   907     TInt status( KErrNone);
  1011     TInt status( KErrNone);
   922             }
  1026             }
   923         }
  1027         }
   924 
  1028 
   925     if ( incoming )
  1029     if ( incoming )
   926         {
  1030         {
   927         // It`s commented because when it`s used heavile cause -16 error
  1031 		// <qmail> Cmail change to synchronous call (UpdateMessageFlagsL) ignored,
   928         // For example when user want to mark as read/unread many messages
  1032         // <qmail> because it causes emulator & HW to freeze on 10.1
   929         // Synchronous method solves this issue
  1033         CIpsPlgSingleOpWatcher* opW = CIpsPlgSingleOpWatcher::NewLC( *this );
   930         iMsgMapper->UpdateMessageFlagsL(msgId.Id(), aMessage);
  1034         CMsvOperation* op = iMsgMapper->UpdateMessageFlagsAsyncL( 
   931         /*CIpsPlgSingleOpWatcher* opW = CIpsPlgSingleOpWatcher::NewLC( *this );
       
   932         CMsvOperation* op = iMsgMapper->UpdateMessageFlagsAsyncL(
       
   933                 msgId.Id(), aMessage, opW->iStatus );
  1035                 msgId.Id(), aMessage, opW->iStatus );
   934 
  1036         
   935         if ( op )
  1037         if ( op )
   936             {
  1038             {
   937             opW->SetOperation( op );
  1039             opW->SetOperation( op );
   938             iOperations.AppendL( opW );
  1040             iOperations.AppendL( opW );
   939             CleanupStack::Pop( opW );
  1041             CleanupStack::Pop( opW );
   940             }
  1042             }
   941         else
  1043         else
   942             {
  1044             {
   943             CleanupStack::PopAndDestroy( opW );
  1045             CleanupStack::PopAndDestroy( opW );
   944             }*/
  1046             }
   945         }
  1047         }
   946     else
  1048     else
   947         {
  1049         {
   948         iSmtpService->StoreMessageL( aMailBoxId, aMessage );
  1050         iSmtpService->StoreMessageL( aMailBoxId, aMessage );
   949         }
  1051         }
   950     }
  1052     }
       
  1053 
       
  1054 // <qmail>
       
  1055 /**
       
  1056  *
       
  1057  * @param aMailBoxId Mailbox id.
       
  1058  * @param aOperationObserver Operation observer.
       
  1059  * @param aRequestId The request id.
       
  1060  */
       
  1061 void CIpsPlgSosBasePlugin::StoreMessagesL(
       
  1062     const TFSMailMsgId& /*aMailBox*/,
       
  1063     RPointerArray<CFSMailMessage> &messages,
       
  1064     MFSMailRequestObserver& aOperationObserver,
       
  1065     const TInt aRequestId )
       
  1066     
       
  1067     {
       
  1068     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
       
  1069     CleanupStack::PushL(watcher);
       
  1070     CIpsPlgMailStorerOperation* op = 
       
  1071             CIpsPlgMailStorerOperation::NewLC(
       
  1072                     *iSession,
       
  1073                     watcher->iStatus,
       
  1074                     *this, 
       
  1075                     messages, 
       
  1076                     aOperationObserver, 
       
  1077                     aRequestId );
       
  1078     
       
  1079     watcher->SetOperation(op);
       
  1080     iOperations.AppendL(watcher);
       
  1081     CleanupStack::Pop( 2, watcher );
       
  1082     }
       
  1083 // </qmail>
   951 
  1084 
   952 // ----------------------------------------------------------------------------
  1085 // ----------------------------------------------------------------------------
   953 // CIpsPlgSosBasePlugin::GetMessagesL()
  1086 // CIpsPlgSosBasePlugin::GetMessagesL()
   954 // ----------------------------------------------------------------------------
  1087 // ----------------------------------------------------------------------------
   955 //
  1088 //
  1005     }
  1138     }
  1006 
  1139 
  1007 // ----------------------------------------------------------------------------
  1140 // ----------------------------------------------------------------------------
  1008 // ----------------------------------------------------------------------------
  1141 // ----------------------------------------------------------------------------
  1009 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1142 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
       
  1143     const TFSMailMsgId& /*aMailBoxId*/,
       
  1144     const TFSMailMsgId& /*aParentFolderId*/,
       
  1145     const TFSMailMsgId& /*aMessageId*/,
       
  1146     const TFSMailMsgId& /*aParentPartId*/,
       
  1147     const TDesC& /*aContentType*/,
       
  1148     const TDesC& /*aFilePath*/ )
       
  1149     {
       
  1150     // <qmail> not used any more
       
  1151     User::Leave(KErrFSMailPluginNotSupported);
       
  1152     return NULL; // prevents compiler warning
       
  1153     }
       
  1154 
       
  1155 // <qmail>
       
  1156 // ----------------------------------------------------------------------------
       
  1157 // ----------------------------------------------------------------------------  
       
  1158 void CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1010     const TFSMailMsgId& aMailBoxId,
  1159     const TFSMailMsgId& aMailBoxId,
  1011     const TFSMailMsgId& /* aParentFolderId */,
  1160     const TFSMailMsgId& /* aParentFolderId */,
  1012     const TFSMailMsgId& aMessageId,
  1161     const TFSMailMsgId& aMessageId,
  1013     const TFSMailMsgId& /* aParentPartId */,
  1162     const TFSMailMsgId& /* aParentPartId */,
  1014     const TDesC& aContentType,
  1163     const TDesC& aContentType,
  1015     const TDesC& aFilePath )
  1164     const TDesC& aFilePath,
  1016     {
  1165     MFSMailRequestObserver& aOperationObserver,
  1017     FUNC_LOG;
  1166     const TInt aRequestId )
  1018     CFSMailMessagePart* result ( NULL );
  1167     {
  1019     CMsvEntry* cEntry( NULL );
  1168     FUNC_LOG;
  1020     CImEmailMessage* message( NULL );
  1169     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewLC(*this);
  1021     RFile file;
  1170     
  1022     TInt fileSize( 0 );
  1171     CIpsPlgNewChildPartFromFileOperation* op = CIpsPlgNewChildPartFromFileOperation::NewL(
  1023     TBool parentToMultipartAlternative( EFalse );
  1172         *iSession, 
  1024 
  1173         watcher->iStatus,
  1025     // Read attachment size
  1174         aMailBoxId,
  1026     User::LeaveIfError( file.Open( iSession->FileSession(), aFilePath, EFileShareReadersOnly ) );
  1175         aMessageId,
  1027 
  1176         aContentType,
  1028     //in rare case that file has disappeared while sending
  1177         aFilePath,
  1029     //we just won't get the size for it
  1178         aOperationObserver, 
  1030     file.Size( fileSize );
  1179         aRequestId,
  1031     file.Close();
  1180         iMsgMapper);
  1032 
  1181     watcher->SetOperation( op );
  1033   // Take ownership of message entry objects since thanks to
  1182 
  1034     // "clever" use of active scheduler waits we can re-enter 
  1183     iOperations.AppendL( watcher ); 
  1035     // this function leading to crashes if somebody clears the cache
  1184     CleanupStack::Pop( watcher );
  1036     // while this iteration still needs them
  1185     }
  1037     TakeMessageEntryLC( aMessageId.Id(), cEntry, message );
  1186 // </qmail> 
  1038 	
  1187 
  1039     // Operation waiter needed to implement synchronous operation
  1188 // ----------------------------------------------------------------------------
  1040     // on the top of async API
  1189 // ----------------------------------------------------------------------------  
  1041     CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
  1042     CleanupStack::PushL( waiter );
       
  1043 
       
  1044     // Initialize CMsvAttachment instance for the attachment creation
       
  1045     CMsvAttachment* info = CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
       
  1046     CleanupStack::PushL( info );
       
  1047     info->SetAttachmentNameL( aFilePath );
       
  1048     info->SetSize( fileSize );
       
  1049 
       
  1050     // Start attachment creation
       
  1051     message->AttachmentManager().AddAttachmentL(
       
  1052         aFilePath, info, waiter->iStatus );
       
  1053     CleanupStack::Pop( info ); // attachment manager takes ownership
       
  1054 
       
  1055     waiter->Start();
       
  1056     CleanupStack::PopAndDestroy( waiter );
       
  1057     	
       
  1058     // Return message entry objects back to cache
       
  1059     CleanupStack::Pop( 2 ); // cEntry, message
       
  1060     ReturnMessageEntry( cEntry, message );
       
  1061 
       
  1062     // Dig out the entry ID of the new attachment (unbelievable that
       
  1063     // there seems to be no better way to do this)
       
  1064     message->GetAttachmentsListL( cEntry->Entry().Id( ),
       
  1065         CImEmailMessage::EAllAttachments, CImEmailMessage::EThisMessageOnly );
       
  1066     TKeyArrayFix key( 0, ECmpTInt32 );
       
  1067     CMsvEntrySelection* attachmentIds = message->Selection().CopyLC();
       
  1068     attachmentIds->Sort( key );
       
  1069     if ( !attachmentIds->Count() )
       
  1070         {
       
  1071         User::Leave( KErrGeneral );
       
  1072         }
       
  1073     TMsvId newAttachmentId = (*attachmentIds)[ attachmentIds->Count()-1 ];
       
  1074     CleanupStack::PopAndDestroy( attachmentIds );
       
  1075 
       
  1076     CMsvEntry* cAtta = iSession->GetEntryL( newAttachmentId );
       
  1077     CleanupStack::PushL( cAtta );
       
  1078 
       
  1079     // Set filename to iDetails
       
  1080     TMsvEntry tEntry = cAtta->Entry();
       
  1081     tEntry.iDetails.Set( aFilePath );
       
  1082     cAtta->ChangeL( tEntry );
       
  1083 
       
  1084     if( cAtta->HasStoreL() )
       
  1085         {
       
  1086         CMsvStore* store = cAtta->EditStoreL();
       
  1087         CleanupStack::PushL( store );
       
  1088         CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
       
  1089 
       
  1090         if( store->IsPresentL( KUidMsgFileMimeHeader ) )
       
  1091             {
       
  1092             mimeHeader->RestoreL( *store );
       
  1093             CDesC8Array& array = mimeHeader->ContentTypeParams();
       
  1094             array.AppendL( KMethod );
       
  1095             parentToMultipartAlternative = ETrue;
       
  1096 
       
  1097             if( aContentType.Find( KMimeTextCalRequest ) != KErrNotFound )
       
  1098                 {
       
  1099                 array.AppendL( KRequest );
       
  1100                 }
       
  1101             else if( aContentType.Find( KMimeTextCalResponse ) != KErrNotFound )
       
  1102                 {
       
  1103                 array.AppendL( KResponse );
       
  1104                 }
       
  1105             else if( aContentType.Find( KMimeTextCalCancel ) != KErrNotFound )
       
  1106                 {
       
  1107                 array.AppendL( KCancel );
       
  1108                 }
       
  1109             else
       
  1110                 {
       
  1111                 parentToMultipartAlternative = EFalse;
       
  1112                 }
       
  1113             mimeHeader->StoreWithoutCommitL( *store );
       
  1114             store->CommitL();
       
  1115             }
       
  1116 
       
  1117         CleanupStack::PopAndDestroy( 2, store );
       
  1118         }
       
  1119 
       
  1120     if( parentToMultipartAlternative &&
       
  1121         aFilePath.Find( _L(".ics")) != KErrNotFound )
       
  1122         {
       
  1123         TMsvEntry tAttaEntry = cAtta->Entry();
       
  1124         TMsvId id = tAttaEntry.Parent();
       
  1125         CMsvEntry* cParent = iSession->GetEntryL( id );
       
  1126         CleanupStack::PushL( cParent );
       
  1127 
       
  1128         TMsvEmailEntry tEntry = cParent->Entry();
       
  1129         tEntry.SetMessageFolderType( EFolderTypeAlternative );
       
  1130         cParent->ChangeL( tEntry );
       
  1131 
       
  1132         CleanupStack::PopAndDestroy( cParent );
       
  1133         }
       
  1134     CleanupStack::PopAndDestroy( cAtta );
       
  1135 
       
  1136     // Delete the message entries to get all the changes to disk and
       
  1137     // possible store locks released
       
  1138     CleanCachedMessageEntries();
       
  1139 
       
  1140     // Create the FS message part object
       
  1141     result = iMsgMapper->GetMessagePartL( newAttachmentId, aMailBoxId,
       
  1142         aMessageId );
       
  1143 
       
  1144     return result;
       
  1145     }
       
  1146 
       
  1147 // ----------------------------------------------------------------------------
       
  1148 // ----------------------------------------------------------------------------
       
  1149 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1190 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
  1150     const TFSMailMsgId& aMailBoxId,
  1191     const TFSMailMsgId& /*aMailBoxId*/,
  1151     const TFSMailMsgId& /* aParentFolderId */,
  1192     const TFSMailMsgId& /*aParentFolderId*/,
  1152     const TFSMailMsgId& aMessageId,
  1193     const TFSMailMsgId& /*aMessageId*/,
  1153     const TFSMailMsgId& /* aParentPartId */,
  1194     const TFSMailMsgId& /*aParentPartId*/,
  1154     const TDesC& aContentType,
  1195     const TDesC& /*aContentType*/,
  1155     RFile& aFile )
  1196     RFile& /*aFile*/ )
  1156     {
  1197     {
  1157     FUNC_LOG;
  1198     // <qmail> not used any more
  1158 
  1199     User::Leave(KErrFSMailPluginNotSupported);
  1159     // Initialize helper variables
  1200     return NULL; // prevents compiler warning
  1160     CFSMailMessagePart* result ( NULL );
       
  1161     CMsvEntry* cEntry( NULL );
       
  1162     CImEmailMessage* message( NULL );
       
  1163     TInt fileSize( 0 );
       
  1164     TBuf<KMaxFileName> fileName;
       
  1165 
       
  1166  // Take ownership of message entry objects since thanks to
       
  1167     // "clever" use of active scheduler waits we can re-enter 
       
  1168     // this function leading to crashes if somebody clears the cache
       
  1169     // while this iteration still needs them
       
  1170     TakeMessageEntryLC( aMessageId.Id(), cEntry, message );
       
  1171 
       
  1172     // Operation waiter needed to implement synchronous operation
       
  1173     // on the top of async API
       
  1174     CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
  1175     CleanupStack::PushL( waiter );
       
  1176 
       
  1177     // Initialize CMsvAttachment instance for the attachment creation
       
  1178     CMsvAttachment* info = CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
       
  1179     CleanupStack::PushL( info );
       
  1180 
       
  1181     // Read attachment size
       
  1182     User::LeaveIfError( aFile.Size( fileSize ) );
       
  1183     info->SetSize( fileSize );
       
  1184 
       
  1185     // Read attachment filename
       
  1186     User::LeaveIfError( aFile.FullName( fileName ) );
       
  1187     info->SetAttachmentNameL( fileName );
       
  1188 
       
  1189     message->AttachmentManager().AddAttachmentL( aFile, info, waiter->iStatus );
       
  1190     CleanupStack::Pop( info ); // attachment manager takes ownership
       
  1191     
       
  1192     waiter->Start();
       
  1193     CleanupStack::PopAndDestroy( waiter );
       
  1194 
       
  1195  	// Return message entry objects back to cache
       
  1196  	CleanupStack::Pop( 2 ); // cEntry, message
       
  1197  	ReturnMessageEntry( cEntry, message );
       
  1198 
       
  1199     // Dig out the entry ID of the new attachment
       
  1200     message->GetAttachmentsListL( cEntry->Entry().Id( ),
       
  1201         CImEmailMessage::EAllAttachments, CImEmailMessage::EThisMessageOnly );
       
  1202     TKeyArrayFix key( 0, ECmpTInt32 );
       
  1203     CMsvEntrySelection* attachmentIds = message->Selection().CopyLC();
       
  1204     attachmentIds->Sort( key );
       
  1205     if ( !attachmentIds->Count() )
       
  1206         {
       
  1207         User::Leave( KErrGeneral );
       
  1208         }
       
  1209     TMsvId newAttachmentId = (*attachmentIds)[ attachmentIds->Count()-1 ];
       
  1210     CleanupStack::PopAndDestroy( attachmentIds );
       
  1211 
       
  1212     // Meeting request related handling
       
  1213     TBool parentToMultipartAlternative( EFalse );
       
  1214     CMsvEntry* cAtta = iSession->GetEntryL( newAttachmentId );
       
  1215     CleanupStack::PushL( cAtta );
       
  1216 
       
  1217     // Set filename to iDetails
       
  1218     TMsvEntry tEntry = cAtta->Entry();
       
  1219     tEntry.iDetails.Set( fileName );
       
  1220     cAtta->ChangeL( tEntry );
       
  1221 
       
  1222     if( cAtta->HasStoreL() )
       
  1223         {
       
  1224         CMsvStore* store = cAtta->EditStoreL();
       
  1225         CleanupStack::PushL( store );
       
  1226         CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
       
  1227 
       
  1228         if( store->IsPresentL( KUidMsgFileMimeHeader ) )
       
  1229             {
       
  1230             mimeHeader->RestoreL( *store );
       
  1231             CDesC8Array& array = mimeHeader->ContentTypeParams();
       
  1232             array.AppendL( KMethod );
       
  1233             parentToMultipartAlternative = ETrue;
       
  1234 
       
  1235             if( aContentType.Find( KMimeTextCalRequest ) != KErrNotFound )
       
  1236                 {
       
  1237                 array.AppendL( KRequest );
       
  1238                 }
       
  1239             else if( aContentType.Find( KMimeTextCalResponse ) != KErrNotFound )
       
  1240                 {
       
  1241                 array.AppendL( KResponse );
       
  1242                 }
       
  1243             else if( aContentType.Find( KMimeTextCalCancel ) != KErrNotFound )
       
  1244                 {
       
  1245                 array.AppendL( KCancel );
       
  1246                 }
       
  1247             else
       
  1248                 {
       
  1249                 parentToMultipartAlternative = EFalse;
       
  1250                 }
       
  1251             mimeHeader->StoreWithoutCommitL( *store );
       
  1252             store->CommitL();
       
  1253             }
       
  1254         CleanupStack::PopAndDestroy( 2, store );
       
  1255         }
       
  1256     if( parentToMultipartAlternative && fileName.Find( _L(".ics")) != KErrNotFound )
       
  1257         {
       
  1258         TMsvEntry tAttaEntry = cAtta->Entry();
       
  1259         TMsvId id = tAttaEntry.Parent();
       
  1260         CMsvEntry* cParent = iSession->GetEntryL( id );
       
  1261         CleanupStack::PushL( cParent );
       
  1262 
       
  1263         TMsvEmailEntry tEntry = cParent->Entry();
       
  1264         tEntry.SetMessageFolderType( EFolderTypeAlternative );
       
  1265         cParent->ChangeL( tEntry );
       
  1266 
       
  1267         CleanupStack::PopAndDestroy( cParent );
       
  1268         }
       
  1269     CleanupStack::PopAndDestroy( cAtta );
       
  1270 
       
  1271     // Delete the message entries to get all the changes to disk and
       
  1272     // possible store locks released
       
  1273     CleanCachedMessageEntries();
       
  1274 
       
  1275     // Create the FS message part object and return it
       
  1276     result = iMsgMapper->GetMessagePartL( newAttachmentId, aMailBoxId,
       
  1277         aMessageId );
       
  1278     return result;
       
  1279     }
  1201     }
  1280 
  1202 
  1281 // ----------------------------------------------------------------------------
  1203 // ----------------------------------------------------------------------------
  1282 // ----------------------------------------------------------------------------
  1204 // ----------------------------------------------------------------------------
  1283 CFSMailMessagePart* CIpsPlgSosBasePlugin::CopyMessageAsChildPartL(
  1205 CFSMailMessagePart* CIpsPlgSosBasePlugin::CopyMessageAsChildPartL(
  1295 // Supports currently deletion of attachments and multipart structures
  1217 // Supports currently deletion of attachments and multipart structures
  1296 // which are represented as folders in Symbian store)
  1218 // which are represented as folders in Symbian store)
  1297 // ----------------------------------------------------------------------------
  1219 // ----------------------------------------------------------------------------
  1298 //
  1220 //
  1299 void CIpsPlgSosBasePlugin::RemoveChildPartL(
  1221 void CIpsPlgSosBasePlugin::RemoveChildPartL(
       
  1222     const TFSMailMsgId& /*aMailBoxId*/,
       
  1223     const TFSMailMsgId& /*aParentFolderId*/,
       
  1224     const TFSMailMsgId& /*aMessageId*/,
       
  1225     const TFSMailMsgId& /*aParentPartId*/,
       
  1226     const TFSMailMsgId& /*aPartId*/)
       
  1227 	{
       
  1228     // <qmail> not used any more
       
  1229     User::Leave(KErrFSMailPluginNotSupported);
       
  1230 	}
       
  1231 
       
  1232 // <qmail>
       
  1233 // ----------------------------------------------------------------------------
       
  1234 // Supports currently deletion of attachments and multipart structures 
       
  1235 // which are represented as folders in Symbian store)
       
  1236 // ----------------------------------------------------------------------------  
       
  1237 //
       
  1238 void CIpsPlgSosBasePlugin::RemoveChildPartL(
  1300     const TFSMailMsgId& /* aMailBoxId */,
  1239     const TFSMailMsgId& /* aMailBoxId */,
  1301     const TFSMailMsgId& /* aParentFolderId */,
  1240     const TFSMailMsgId& /* aParentFolderId */,
  1302     const TFSMailMsgId& aMessageId,
  1241     const TFSMailMsgId& aMessageId,
  1303     const TFSMailMsgId& /* aParentPartId */,
  1242     const TFSMailMsgId& /* aParentPartId */,
  1304     const TFSMailMsgId& aPartId)
  1243     const TFSMailMsgId& aPartId,
  1305 	{
  1244     MFSMailRequestObserver& aOperationObserver,
  1306     FUNC_LOG;
  1245     const TInt aRequestId )
  1307     TInt status( KErrNone );
  1246     {
  1308     CMsvEntry* cEntry( NULL );
  1247     FUNC_LOG;
  1309     TMsvEntry tEntry;
  1248     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewLC(*this);
  1310     TMsvId serviceId;
  1249     
  1311     status = iSession->GetEntry( aPartId.Id(), serviceId, tEntry );
  1250     CIpsPlgRemoveChildPartOperation* op = CIpsPlgRemoveChildPartOperation::NewL(
  1312 
  1251         *iSession, 
  1313     if ( ( status == KErrNone ) &&
  1252         watcher->iStatus,
  1314          ( tEntry.iType == KUidMsvAttachmentEntry ) )
  1253         aMessageId,
  1315         {
  1254         aPartId,
  1316         CImEmailMessage* message( NULL );
  1255         aOperationObserver, 
  1317   
  1256         aRequestId);
  1318         // We trust that the message ID really refers to a message
  1257     watcher->SetOperation( op );
  1319         
  1258 
  1320         // Take ownership of message entry objects since thanks to
  1259     iOperations.AppendL( watcher ); 
  1321         // "clever" use of active scheduler waits we can re-enter 
  1260     CleanupStack::Pop( watcher );
  1322         // this function leading to crashes if somebody clears the cache
  1261 
  1323         // while this iteration still needs them
  1262     }
  1324         TakeMessageEntryLC( aMessageId.Id(), cEntry, message );
  1263 // </qmail>
  1325 
       
  1326         MMsvAttachmentManager& attachmentMgr( message->AttachmentManager() );
       
  1327 
       
  1328         CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
  1329         CleanupStack::PushL( waiter );
       
  1330 
       
  1331         attachmentMgr.RemoveAttachmentL(
       
  1332             (TMsvAttachmentId) aPartId.Id(), waiter->iStatus );
       
  1333 
       
  1334         waiter->Start();
       
  1335         CleanupStack::PopAndDestroy( waiter );
       
  1336         	
       
  1337         // Return message entry objects to cache
       
  1338         CleanupStack::Pop( 2 ); // cEntry, message
       
  1339         ReturnMessageEntry( cEntry, message );
       
  1340         }
       
  1341     else if ( ( status == KErrNone ) &&
       
  1342               ( tEntry.iType == KUidMsvFolderEntry ) )
       
  1343         {
       
  1344         cEntry = iSession->GetEntryL( tEntry.Parent() );
       
  1345         CleanupStack::PushL( cEntry );
       
  1346         cEntry->DeleteL( tEntry.Id() );
       
  1347         CleanupStack::PopAndDestroy( cEntry );
       
  1348         }
       
  1349 	}
       
  1350 
  1264 
  1351 // ----------------------------------------------------------------------------
  1265 // ----------------------------------------------------------------------------
  1352 // The implementation supoorts the atachment and body parts at the moment.
  1266 // The implementation supoorts the atachment and body parts at the moment.
  1353 // ----------------------------------------------------------------------------
  1267 // ----------------------------------------------------------------------------
  1354 //
  1268 //
  1367 
  1281 
  1368 // ----------------------------------------------------------------------------
  1282 // ----------------------------------------------------------------------------
  1369 // The implementation bypass CImEmailMessage and its email's attachment
  1283 // The implementation bypass CImEmailMessage and its email's attachment
  1370 // manager. Instead, it calls Symbian framework classes directly by
  1284 // manager. Instead, it calls Symbian framework classes directly by
  1371 // accessing the attachment entry.
  1285 // accessing the attachment entry.
  1372 // ----------------------------------------------------------------------------
  1286 // Qmail change: returns file handle for read/write
  1373 TInt CIpsPlgSosBasePlugin::GetMessagePartFileL(
  1287 // ----------------------------------------------------------------------------  
       
  1288 TInt CIpsPlgSosBasePlugin::GetMessagePartFileL(  
  1374     const TFSMailMsgId& /* aMailBoxId */,
  1289     const TFSMailMsgId& /* aMailBoxId */,
  1375     const TFSMailMsgId& /* aParentFolderId */,
  1290     const TFSMailMsgId& /* aParentFolderId */,
  1376     const TFSMailMsgId& /* aMessageId */,
  1291     const TFSMailMsgId& /* aMessageId */,
  1377     const TFSMailMsgId& aMessagePartId,
  1292     const TFSMailMsgId& aMessagePartId,
  1378     RFile& aFileHandle)
  1293     RFile& aFileHandle)
  1383     CleanupStack::PushL( cEntry );
  1298     CleanupStack::PushL( cEntry );
  1384     CMsvStore* store = NULL;
  1299     CMsvStore* store = NULL;
  1385     TBool hasStore = cEntry->HasStoreL();
  1300     TBool hasStore = cEntry->HasStoreL();
  1386     if ( hasStore )
  1301     if ( hasStore )
  1387         {
  1302         {
  1388         store = cEntry->ReadStoreL();
  1303 //<qmail>
       
  1304         // We need to open store for edit to support multipart/alternative
       
  1305         // structure: we must have a possibility to modify text/html message part
       
  1306         //store = cEntry->ReadStoreL();
       
  1307         store = cEntry->EditStoreL();
       
  1308 //</qmail>
  1389         }
  1309         }
  1390 
  1310 
  1391     if ( !store || !hasStore )
  1311     if ( !store || !hasStore )
  1392         {
  1312         {
  1393         User::Leave( KErrNotFound );
  1313         User::Leave( KErrNotFound );
  1396     MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL();
  1316     MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL();
  1397 
  1317 
  1398     // It is assumed that the attachment file is always in the index 0
  1318     // It is assumed that the attachment file is always in the index 0
  1399     if ( attachmentMgr.AttachmentCount() )
  1319     if ( attachmentMgr.AttachmentCount() )
  1400         {
  1320         {
  1401         aFileHandle = attachmentMgr.GetAttachmentFileL( 0 );
  1321 //<qmail>
       
  1322         // We need to open store for edit to support multipart/alternative
       
  1323         // structure: we must have a possibility to modify text/html message part
       
  1324         //aFileHandle = attachmentMgr.GetAttachmentFileL( 0 );
       
  1325         aFileHandle = attachmentMgr.GetAttachmentFileForWriteL( 0 );
       
  1326 //</qmail>
  1402         }
  1327         }
  1403     else
  1328     else
  1404         {
  1329         {
  1405         User::Leave( KErrNotFound );
  1330         User::Leave( KErrNotFound );
  1406         }
  1331         }
  1418     const TFSMailMsgId& /*aMessageId*/,
  1343     const TFSMailMsgId& /*aMessageId*/,
  1419     const TFSMailMsgId& aMessagePartId,
  1344     const TFSMailMsgId& aMessagePartId,
  1420     const TDesC& aFilePath)
  1345     const TDesC& aFilePath)
  1421 	{
  1346 	{
  1422     FUNC_LOG;
  1347     FUNC_LOG;
       
  1348     //<qmail>
  1423     CMsvEntry* cEntry = iSession->GetEntryL( aMessagePartId.Id() );
  1349     CMsvEntry* cEntry = iSession->GetEntryL( aMessagePartId.Id() );
  1424     CleanupStack::PushL( cEntry );
  1350     CleanupStack::PushL( cEntry );
  1425     CMsvStore* store = NULL;
  1351     CMsvStore* store = NULL;
  1426     TBool hasStore = cEntry->HasStoreL();
  1352     TBool hasStore = cEntry->HasStoreL();
  1427     if ( hasStore )
  1353     if ( hasStore )
  1450         {
  1376         {
  1451         User::Leave( KErrNotFound );
  1377         User::Leave( KErrNotFound );
  1452         }
  1378         }
  1453     CleanupStack::PopAndDestroy( store );
  1379     CleanupStack::PopAndDestroy( store );
  1454     CleanupStack::PopAndDestroy( cEntry );
  1380     CleanupStack::PopAndDestroy( cEntry );
       
  1381     //</qmail>
  1455 	}
  1382 	}
  1456 
  1383 
  1457 // ----------------------------------------------------------------------------
  1384 // ----------------------------------------------------------------------------
  1458 // The method supports only reading of the plain text body currently.
  1385 // The method supports only reading of the plain text body currently.
  1459 // ----------------------------------------------------------------------------
  1386 // ----------------------------------------------------------------------------
  1508 // ----------------------------------------------------------------------------
  1435 // ----------------------------------------------------------------------------
  1509 void CIpsPlgSosBasePlugin::SetContentL(
  1436 void CIpsPlgSosBasePlugin::SetContentL(
  1510     const TDesC& aBuffer,
  1437     const TDesC& aBuffer,
  1511     const TFSMailMsgId& /* aMailBoxId */,
  1438     const TFSMailMsgId& /* aMailBoxId */,
  1512     const TFSMailMsgId& /* aParentFolderId */,
  1439     const TFSMailMsgId& /* aParentFolderId */,
  1513     const TFSMailMsgId& aMessageId,
  1440     const TFSMailMsgId& /* aMessageId */,
  1514     const TFSMailMsgId& aMessagePartId )
  1441     const TFSMailMsgId& aMessagePartId )
  1515 	{
  1442 	{
  1516     FUNC_LOG;
  1443     FUNC_LOG;
  1517     CMsvEntry* cEntry( NULL );
  1444     
  1518     CImEmailMessage* message( NULL );
  1445 //<qmail> Rewritten in Qmail: CIpsPlgOperationWait is no longer used 
  1519 
  1446     // Notice that SetContentL sets only the content of text/plain message part:
  1520     // Take ownership of message entry objects since thanks to
  1447     // text/html part can be modified directly using GetMessagePartFileL
  1521     // "clever" use of active scheduler waits we can re-enter 
  1448 	CMsvEntry* cEntry( NULL );
  1522     // this function leading to crashes if somebody clears the cache
  1449     CMsvStore* store = NULL;
  1523     // while this iteration still needs them
  1450     
  1524     TakeMessageEntryLC( aMessageId.Id(), cEntry, message );
  1451     // following code should fill text/plain content
  1525     
  1452     cEntry = iSession->GetEntryL( aMessagePartId.Id() );
  1526 	if ( message )
  1453     CleanupStack::PushL( cEntry );
  1527 	    {
  1454     TBool hasStore = cEntry->HasStoreL();
  1528 
  1455     if ( hasStore ) {
  1529 	    message->GetBodyTextEntryIdL(
  1456         store = cEntry->EditStoreL();
  1530 	    		cEntry->Entry().Id(), CImEmailMessage::EThisMessageOnly );
  1457         CleanupStack::PushL(store);
  1531 	    if ( message->Selection().Count() > 0 )
  1458         CParaFormatLayer* globalParaLayer = CParaFormatLayer::NewL();
  1532 	    	{
  1459         CleanupStack::PushL(globalParaLayer);
  1533 	    	TMsvId dummy;
  1460         CCharFormatLayer* globalCharLayer = CCharFormatLayer::NewL();
  1534 	    	TMsvEmailEntry newEmailMsg;
  1461         CleanupStack::PushL(globalCharLayer);
  1535 	    	iSession->GetEntry( aMessageId.Id(), dummy, newEmailMsg );
  1462         CRichText* text = CRichText::NewL( globalParaLayer, globalCharLayer );
  1536 	    	TMsvId parent = newEmailMsg.Parent();
  1463         CleanupStack::PushL( text );
  1537 
  1464         // insert text
  1538 	    	if ( message->Selection()[0] == aMessagePartId.Id() ||
  1465         text->InsertL(0, aBuffer );
  1539 	    		 newEmailMsg.ICalendar() )
  1466         store->StoreBodyTextL(*text);
  1540 	    		{
  1467         store->CommitL();
  1541 	    		CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC( );
  1468         CleanupStack::PopAndDestroy( 4, store );
  1542 	    		CParaFormatLayer* globalParaLayer = CParaFormatLayer::NewL();
  1469     }
  1543 	    		CleanupStack::PushL(globalParaLayer);
  1470     CleanupStack::PopAndDestroy(cEntry);
  1544 	    		CCharFormatLayer* globalCharLayer = CCharFormatLayer::NewL();
  1471 //</qmail>
  1545 	    		CleanupStack::PushL(globalCharLayer);
       
  1546 	    		CRichText* text = CRichText::NewL( globalParaLayer, globalCharLayer );
       
  1547 	    		CleanupStack::PushL( text );
       
  1548 	    		// insert text
       
  1549 	    		text->InsertL(0, aBuffer );
       
  1550 	    		// synchronously
       
  1551 	    		message->StoreBodyTextL(
       
  1552 	    				cEntry->Entry().Id(), *text ,wait->iStatus );
       
  1553 	    		wait->Start();
       
  1554 	    		CleanupStack::PopAndDestroy( 4, wait );
       
  1555 	    		}
       
  1556 	    	}
       
  1557 	    }
       
  1558 	
       
  1559 	// Return message entry objects to cache
       
  1560 	CleanupStack::Pop( 2 ); // cEntry, message
       
  1561 	ReturnMessageEntry( cEntry, message );
       
  1562 	}
  1472 	}
  1563 
  1473 
  1564 // ----------------------------------------------------------------------------
  1474 // ----------------------------------------------------------------------------
  1565 // ----------------------------------------------------------------------------
  1475 // ----------------------------------------------------------------------------
  1566 void CIpsPlgSosBasePlugin::RemovePartContentL(
  1476 void CIpsPlgSosBasePlugin::RemovePartContentL(
  1567     const TFSMailMsgId& /* aMailBoxId */,
  1477     const TFSMailMsgId& /*aMailBoxId*/,
  1568     const TFSMailMsgId& /* aParentFolderId */,
  1478     const TFSMailMsgId& /*aParentFolderId*/,
  1569     const TFSMailMsgId& /* aMessageId */,
  1479     const TFSMailMsgId& /*aMessageId*/,
  1570     const RArray<TFSMailMsgId>& aPartIds )
  1480     const RArray<TFSMailMsgId>& /*aPartIds*/ )
  1571     {
  1481     {
  1572     TInt count( aPartIds.Count() );
  1482     // <qmail>
  1573 
  1483     User::Leave( KErrFSMailPluginNotSupported );
  1574     for( TInt i(0); i < count; i++ )
  1484     // </qmail>
  1575         {
       
  1576         CMsvEntry* cEntry = iSession->GetEntryL( aPartIds[i].Id() );
       
  1577         CleanupStack::PushL( cEntry );
       
  1578         CMsvStore* store = NULL;
       
  1579         TBool hasStore = cEntry->HasStoreL();
       
  1580         if ( hasStore )
       
  1581             {
       
  1582             store = cEntry->EditStoreL();
       
  1583             }
       
  1584 
       
  1585         if ( !store || !hasStore )
       
  1586             {
       
  1587             User::Leave( KErrNotFound );
       
  1588             }
       
  1589         CleanupStack::PushL( store );
       
  1590         MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL();
       
  1591 
       
  1592         // It is assumed that the attachment file is always in the index 0
       
  1593         if ( attachmentMgr.AttachmentCount() )
       
  1594             {
       
  1595             // delete attachment file
       
  1596             CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewLC();
       
  1597             attachmentMgr.RemoveAttachmentL( 0, waiter->iStatus );
       
  1598             waiter->Start();
       
  1599             CleanupStack::PopAndDestroy( waiter );
       
  1600             store->CommitL();
       
  1601 
       
  1602             // clear complete flag
       
  1603             TMsvEntry tEntry( cEntry->Entry() );
       
  1604             tEntry.SetComplete( EFalse );
       
  1605 
       
  1606             waiter = CIpsPlgOperationWait::NewLC();
       
  1607             CMsvOperation* ops = cEntry->ChangeL( tEntry, waiter->iStatus );
       
  1608             CleanupStack::PushL( ops );
       
  1609             waiter->Start();
       
  1610             CleanupStack::PopAndDestroy( 2, waiter );
       
  1611             }
       
  1612         else
       
  1613             {
       
  1614             User::Leave( KErrNotFound );
       
  1615             }
       
  1616         CleanupStack::PopAndDestroy( store );
       
  1617         CleanupStack::PopAndDestroy( cEntry );
       
  1618         }
       
  1619     }
  1485     }
  1620 
  1486 
  1621 // ----------------------------------------------------------------------------
  1487 // ----------------------------------------------------------------------------
  1622 // ----------------------------------------------------------------------------
  1488 // ----------------------------------------------------------------------------
  1623 void CIpsPlgSosBasePlugin::SetPartContentFromFileL(
  1489 void CIpsPlgSosBasePlugin::SetPartContentFromFileL(
  1637     const TFSMailMsgId& /* aMessageId */,
  1503     const TFSMailMsgId& /* aMessageId */,
  1638     CFSMailMessagePart& /* aMessagePart */)
  1504     CFSMailMessagePart& /* aMessagePart */)
  1639     {
  1505     {
  1640     }
  1506     }
  1641 
  1507 
  1642 // ----------------------------------------------------------------------------
  1508 //<qmail>
  1643 // ----------------------------------------------------------------------------
  1509 // ----------------------------------------------------------------------------
       
  1510 // ----------------------------------------------------------------------------     
       
  1511 void CIpsPlgSosBasePlugin::StoreMessagePartsL(
       
  1512     RPointerArray<CFSMailMessagePart>&  aMessageParts,
       
  1513     MFSMailRequestObserver& aOperationObserver,
       
  1514     const TInt aRequestId )
       
  1515     {
       
  1516     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
       
  1517     CleanupStack::PushL(watcher);
       
  1518     CIpsPlgMessagePartStorerOperation* op =
       
  1519             CIpsPlgMessagePartStorerOperation::NewLC(*iSession,
       
  1520                     watcher->iStatus, *this, aMessageParts,
       
  1521                     aOperationObserver, aRequestId);
       
  1522     
       
  1523     watcher->SetOperation(op);
       
  1524     iOperations.AppendL(watcher);
       
  1525     CleanupStack::Pop( 2, watcher );    
       
  1526     }
       
  1527 //<//qmail>
       
  1528 
       
  1529 // ----------------------------------------------------------------------------
       
  1530 // ---------------------------------------------------------------------------- 	
  1644 void CIpsPlgSosBasePlugin::UnregisterRequestObserver( TInt /* aRequestId */)
  1531 void CIpsPlgSosBasePlugin::UnregisterRequestObserver( TInt /* aRequestId */)
  1645     {
  1532     {
  1646     }
  1533     }
  1647 
  1534 
  1648 // ----------------------------------------------------------------------------
  1535 // ----------------------------------------------------------------------------
  1650 void CIpsPlgSosBasePlugin::SendL(TFSMailMsgId aMessageId )
  1537 void CIpsPlgSosBasePlugin::SendL(TFSMailMsgId aMessageId )
  1651  	{
  1538  	{
  1652     FUNC_LOG;
  1539     FUNC_LOG;
  1653  	CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
  1540  	CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
  1654  	CleanupStack::PushL(watcher);
  1541  	CleanupStack::PushL(watcher);
       
  1542 // <qmail>
  1655     CIpsPlgSmtpOperation* op = CIpsPlgSmtpOperation::NewLC(
  1543     CIpsPlgSmtpOperation* op = CIpsPlgSmtpOperation::NewLC(
  1656         *iSession, CActive::EPriorityStandard, watcher->iStatus, ETrue );
  1544         *iSession, watcher->iStatus );
       
  1545 // </qmail>
  1657     op->SetEventHandler(iEventHandler);
  1546     op->SetEventHandler(iEventHandler);
  1658     watcher->SetOperation(op);
  1547     watcher->SetOperation(op);
  1659     CleanupStack::Pop( op ); // op added as member of watcher
  1548     CleanupStack::Pop( op ); // op added as member of watcher
  1660     op->StartSendL( aMessageId.Id() );
  1549     op->StartSendL( aMessageId.Id() );
  1661     iOperations.AppendL(watcher);
  1550     iOperations.AppendL(watcher);
  1662     CleanupStack::Pop( watcher );
  1551     CleanupStack::Pop( watcher );
  1663  	}
  1552  	}
  1664 
  1553 
  1665 // ----------------------------------------------------------------------------
  1554    
  1666 // ----------------------------------------------------------------------------
  1555 // ----------------------------------------------------------------------------
  1667 void CIpsPlgSosBasePlugin::SendMessageL( CFSMailMessage& aMessage )
  1556 // ---------------------------------------------------------------------------- 	
  1668     {
  1557 void CIpsPlgSosBasePlugin::SendMessageL( CFSMailMessage& /*aMessage*/ )
  1669     FUNC_LOG;
  1558     {
       
  1559     FUNC_LOG;
       
  1560     // <qmail>
       
  1561     User::Leave( KErrFSMailPluginNotSupported );
       
  1562     // </qmail>
       
  1563     }
       
  1564 
       
  1565 // <qmail>
       
  1566 // ----------------------------------------------------------------------------
       
  1567 // ----------------------------------------------------------------------------
       
  1568 void CIpsPlgSosBasePlugin::SendMessageL(
       
  1569         CFSMailMessage& aMessage,
       
  1570         MFSMailRequestObserver& aOperationObserver,
       
  1571         const TInt aRequestId )
       
  1572     {
       
  1573     FUNC_LOG;
       
  1574     // <qmail> Not activated yet
  1670     // is EFSMsgFlag_CalendarMsg enabled,
  1575     // is EFSMsgFlag_CalendarMsg enabled,
  1671     // then move send to back ground process
  1576     // then move send to back ground process
  1672     if ( aMessage.GetFlags() & EFSMsgFlag_CalendarMsg )
  1577     //if ( aMessage.GetFlags() & EFSMsgFlag_CalendarMsg )
  1673         {
  1578     //    {
  1674         iEventHandler->SetNewPropertyEvent(
  1579     //    iEventHandler->SetNewPropertyEvent(
  1675                 aMessage.GetMessageId().Id(),
  1580     //            aMessage.GetMessageId().Id(),
  1676                 KIPSSosSmtpEmptyOutboxNow, KErrNone );
  1581     //            KIPSSosSmtpEmptyOutboxNow, KErrNone );
  1677         }
  1582     //    }
  1678     else
  1583     //else
  1679         {
  1584     //    {
  1680         SendL( aMessage.GetMessageId() );
  1585         CIpsPlgSingleOpWatcher* watcher =
  1681         }
  1586             CIpsPlgSingleOpWatcher::NewLC(*this);
  1682     }
  1587 
       
  1588         // <qmail> priority parameter has been removed
       
  1589         CIpsPlgSmtpOperation* op = CIpsPlgSmtpOperation::NewL(
       
  1590             *iSession,
       
  1591             watcher->iStatus,
       
  1592             &aOperationObserver,
       
  1593             aRequestId );
       
  1594         watcher->SetOperation(op); // ownership is transferred
       
  1595         op->StartSendL( aMessage.GetMessageId().Id() );
       
  1596         iOperations.AppendL(watcher);
       
  1597         CleanupStack::Pop( watcher );
       
  1598     //    }
       
  1599     // </qmail>
       
  1600     }
       
  1601 // </qmail>
  1683 
  1602 
  1684 // ----------------------------------------------------------------------------
  1603 // ----------------------------------------------------------------------------
  1685 // ----------------------------------------------------------------------------
  1604 // ----------------------------------------------------------------------------
  1686 TFSProgress CIpsPlgSosBasePlugin::StatusL( TInt aRequestId )
  1605 TFSProgress CIpsPlgSosBasePlugin::StatusL( TInt aRequestId )
  1687 	{
  1606 	{
  1772 // ----------------------------------------------------------------------------
  1691 // ----------------------------------------------------------------------------
  1773 // ----------------------------------------------------------------------------
  1692 // ----------------------------------------------------------------------------
  1774 void CIpsPlgSosBasePlugin::DeleteMessagesByUidL(
  1693 void CIpsPlgSosBasePlugin::DeleteMessagesByUidL(
  1775     const TFSMailMsgId& /*aMailBoxId*/,
  1694     const TFSMailMsgId& /*aMailBoxId*/,
  1776     const TFSMailMsgId& /*aFolderId*/,
  1695     const TFSMailMsgId& /*aFolderId*/,
  1777     const RArray<TFSMailMsgId>& aMessages )
  1696 	const RArray<TFSMailMsgId>& aMessages )
  1778     {
  1697     {
  1779     FUNC_LOG;
  1698     FUNC_LOG;
  1780     CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection;
  1699     CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection;
  1781     CleanupStack::PushL(sel);
  1700     CleanupStack::PushL(sel);
  1782 
  1701 
  1783     TInt count = aMessages.Count();
  1702     TInt count = aMessages.Count();
  1784     TMsvEntry tEntry;
  1703     TMsvEntry tEntry;
  1785     TMsvId service;
  1704     TMsvId service;
  1786 
  1705     
  1787     TMsvEntry parentEntry;
  1706     for(TInt i=0; i<count; i++)
  1788     
  1707         {
  1789     // simulation of canceling deletion operation
  1708         iSession->GetEntry( aMessages[i].Id(), service, tEntry );
  1790     if ( !count ) 
  1709         //make sure that only messages get deleted.
  1791         {
  1710         if( tEntry.iType == KUidMsvMessageEntry )
  1792         if ( iMsvOpDeleteMessage )
  1711             {            
  1793             {
  1712 			// <qmail>    
  1794             iMsvOpDeleteMessage->Cancel();
  1713             sel->AppendL( tEntry.Id() );
  1795             }
  1714 			// </qmail>    
       
  1715             }
       
  1716         }
  1796         
  1717         
  1797         if ( iWaitDeleteMessage )
  1718     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL( *this );
  1798             {
  1719     CleanupStack::PushL( watcher );
  1799             iWaitDeleteMessage->Cancel();
  1720     //<qmail>
  1800             }
  1721     CMsvOperation* op = CIpsPlgDeleteOperation::NewL( *iSession,
       
  1722         watcher->iStatus, sel );
       
  1723     //</qmail>
       
  1724     watcher->SetOperation( op );
       
  1725     iOperations.AppendL( watcher );
       
  1726     CleanupStack::Pop( watcher );
       
  1727     //<qmail>
       
  1728     CleanupStack::Pop( sel );
       
  1729     //</qmail>
       
  1730     }
       
  1731 
       
  1732 // <qmail>
       
  1733 // ----------------------------------------------------------------------------
       
  1734 // ----------------------------------------------------------------------------
       
  1735 void CIpsPlgSosBasePlugin::DeleteMessagesByUidL(
       
  1736     const TFSMailMsgId& /*aMailBoxId*/,
       
  1737     const TFSMailMsgId& /*aFolderId*/,
       
  1738 	const RArray<TFSMailMsgId>& aMessages,
       
  1739     MFSMailRequestObserver& aOperationObserver,
       
  1740     const TInt aRequestId)
       
  1741     {
       
  1742     FUNC_LOG;
       
  1743     CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection;
       
  1744     CleanupStack::PushL(sel);
       
  1745 
       
  1746     TInt count = aMessages.Count();
       
  1747     TMsvEntry tEntry;
       
  1748     TMsvId service;
       
  1749     
       
  1750     for(TInt i=0; i<count; i++)
       
  1751         {
       
  1752         iSession->GetEntry( aMessages[i].Id(), service, tEntry );
       
  1753         //make sure that only messages get deleted.
       
  1754         if( tEntry.iType == KUidMsvMessageEntry )
       
  1755             {            
       
  1756             sel->AppendL( tEntry.Id() );
       
  1757             }
       
  1758         }
  1801         
  1759         
  1802         delete iMsvOpDeleteMessage;
  1760     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL( *this );
  1803         iMsvOpDeleteMessage = NULL;
  1761     CleanupStack::PushL( watcher );
  1804         delete iWaitDeleteMessage;
  1762     CMsvOperation* op = CIpsPlgDeleteOperation::NewL( *iSession,
  1805         iWaitDeleteMessage = NULL;
  1763         watcher->iStatus, sel, aOperationObserver, aRequestId );
  1806         delete icEntry;
  1764     watcher->SetOperation( op );
  1807         icEntry = NULL;
  1765     iOperations.AppendL( watcher );
  1808         }
  1766     CleanupStack::Pop( watcher );
  1809     else
  1767     CleanupStack::Pop( sel );
  1810         {
  1768     }
  1811         for( TInt i = 0; i < count; i++ )
  1769 // </qmail>
  1812             {
       
  1813             iSession->GetEntry( aMessages[i].Id(), service, tEntry );
       
  1814             
       
  1815             //make sure that only messages get deleted.
       
  1816             if( tEntry.iType == KUidMsvMessageEntry )
       
  1817                 {
       
  1818                 if(iMsvOpDeleteMessage)
       
  1819                     {
       
  1820                     iMsvOpDeleteMessage->Cancel();
       
  1821                     delete iMsvOpDeleteMessage;
       
  1822                     iMsvOpDeleteMessage = NULL;
       
  1823                     }
       
  1824                 
       
  1825                 if ( iWaitDeleteMessage )
       
  1826                     {
       
  1827                     iWaitDeleteMessage->Cancel();
       
  1828                     delete iWaitDeleteMessage;
       
  1829                     iWaitDeleteMessage = NULL;
       
  1830                     }
       
  1831 
       
  1832                 delete icEntry;
       
  1833                 icEntry = NULL;
       
  1834             
       
  1835                 iSession->GetEntry( tEntry.Parent( ), service, parentEntry );
       
  1836 
       
  1837                 icEntry = CMsvEntry::NewL( 
       
  1838                         *iSession, tEntry.Id(), TMsvSelectionOrdering() );
       
  1839                 
       
  1840                 
       
  1841                 // priority slightly increased not to pause the function longer than needed
       
  1842                 iWaitDeleteMessage = CIpsPlgOperationWait::NewL( CActive::EPriorityStandard+1 );
       
  1843                 // Sets bit 32 of iMtmData1, used when msg deleted in Offline
       
  1844                 // and status hasn't updated to server (client entry still exists)
       
  1845                 tEntry.SetLocallyDeleted( ETrue );
       
  1846                 
       
  1847                 iMsvOpDeleteMessage = icEntry->ChangeL( tEntry, 
       
  1848                         iWaitDeleteMessage->iStatus );
       
  1849                         
       
  1850                 iWaitDeleteMessage->Start();
       
  1851                 
       
  1852                 sel->AppendL( tEntry.Id() );
       
  1853                 }
       
  1854             }
       
  1855 
       
  1856         CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewLC( *this );
       
  1857 
       
  1858         CMsvOperation* op = CIpsPlgDeleteRemote::NewL( *iSession, 
       
  1859                 watcher->iStatus, *sel );
       
  1860         watcher->SetOperation( op );
       
  1861 
       
  1862         // make draft deletion synchronous so that empty drafts are not left after application close
       
  1863         if ( parentEntry.Id() == KMsvDraftEntryIdValue && count == 1 )
       
  1864             {
       
  1865             iWait.Start();
       
  1866             CleanupStack::PopAndDestroy( watcher );
       
  1867             }
       
  1868         else
       
  1869             {
       
  1870             iOperations.AppendL( watcher );
       
  1871             CleanupStack::Pop( watcher );
       
  1872             }
       
  1873         }
       
  1874     
       
  1875     CleanupStack::PopAndDestroy( sel );
       
  1876     }
       
  1877 
  1770 
  1878 // ----------------------------------------------------------------------------
  1771 // ----------------------------------------------------------------------------
  1879 // ----------------------------------------------------------------------------
  1772 // ----------------------------------------------------------------------------
  1880 void CIpsPlgSosBasePlugin::SubscribeMailboxEventsL(
  1773 void CIpsPlgSosBasePlugin::SubscribeMailboxEventsL(
  1881     const TFSMailMsgId& aMailboxId,
  1774     const TFSMailMsgId& aMailboxId,
  1882     MFSMailEventObserver& aObserver)
  1775     MFSMailEventObserver& aObserver)
  1883     {
  1776     {
  1884     FUNC_LOG;
  1777     FUNC_LOG;
  1885     TUint32 key = iSettingsApi->CreateCenRepKeyL(   // faulty CS warning
  1778 // <qmail>
  1886         aMailboxId.Id(),
  1779     TUint32 key(0);
  1887         MtmId(),
  1780 // </qmail>
  1888         CIpsSetDataStorer::EIpsSetDataLastModifiedH );
       
  1889 
  1781 
  1890     iEventHandler->SubscribeMailboxEventsL( aMailboxId, aObserver, key );
  1782     iEventHandler->SubscribeMailboxEventsL( aMailboxId, aObserver, key );
  1891     }
  1783     }
  1892 
  1784 
  1893 // ----------------------------------------------------------------------------
  1785 // ----------------------------------------------------------------------------
  1913 // ----------------------------------------------------------------------------
  1805 // ----------------------------------------------------------------------------
  1914 TInt CIpsPlgSosBasePlugin::WizardDataAvailableL( )
  1806 TInt CIpsPlgSosBasePlugin::WizardDataAvailableL( )
  1915     {
  1807     {
  1916     FUNC_LOG;
  1808     FUNC_LOG;
  1917     TInt error = KErrNone;
  1809     TInt error = KErrNone;
  1918     error = iSettingsApi->HandleMailboxCreation( MtmId(), *iSession );
  1810 // <qmail> iSettingsApi not available in Qmail
       
  1811     /*error = iSettingsApi->HandleMailboxCreation( MtmId(), *iSession );
  1919     if ( error == KErrNotSupported )
  1812     if ( error == KErrNotSupported )
  1920         {
  1813         {
  1921         // this means that wizard data is not meaned for this plugin (instance)
  1814         // this means that wizard data is not meaned for this plugin (instance)
  1922         // just return KErrNone at the moment
  1815         // just return KErrNone at the moment
  1923         return KErrNone;
  1816         return KErrNone;
  1924         }
  1817         }*/
       
  1818 // </qmail>
  1925     return error;
  1819     return error;
  1926     }
  1820     }
  1927 
  1821 
  1928 // ----------------------------------------------------------------------------
  1822 // ----------------------------------------------------------------------------
  1929 // ----------------------------------------------------------------------------
  1823 // ----------------------------------------------------------------------------
  1953     }
  1847     }
  1954 
  1848 
  1955 // ----------------------------------------------------------------------------
  1849 // ----------------------------------------------------------------------------
  1956 // method sets authentication popup data
  1850 // method sets authentication popup data
  1957 // ----------------------------------------------------------------------------
  1851 // ----------------------------------------------------------------------------
  1958 void CIpsPlgSosBasePlugin::SetCredentialsL( const TFSMailMsgId& aMailBoxId,
  1852 //
  1959 	const TDesC& /*aUsername*/, const TDesC& aPassword )
  1853 void CIpsPlgSosBasePlugin::SetCredentialsL( const TFSMailMsgId& /*aMailBoxId*/,
  1960 	{
  1854 	const TDesC& /*aUsername*/, const TDesC& /*aPassword*/ )
  1961     FUNC_LOG;
  1855 	{
  1962 	TBool cancelled = EFalse;
  1856 // <qmail> not used; should be removed
  1963 
  1857 //    FUNC_LOG;
  1964 	if ( aPassword.Length() > 0 )
  1858 //	TBool cancelled = EFalse;
  1965 	    {
  1859 //	
  1966     	//Set new password and signal (possible) ongoing connect operation
  1860 //	if ( aPassword.Length() > 0 )
  1967     	CIpsSetDataApi* api = CIpsSetDataApi::NewL( *iSession );
  1861 //	    {
  1968         CleanupStack::PushL( api );
  1862 //    	//Set new password and signal (possible) ongoing connect operation
  1969 
  1863 //    	//CIpsSetDataApi* api = CIpsSetDataApi::NewL( *iSession );
  1970         CMsvEntry* cEntry = iSession->GetEntryL( aMailBoxId.Id() );
  1864 //        //CleanupStack::PushL( api );
  1971         CleanupStack::PushL( cEntry );
  1865 //        
  1972 
  1866 //        //CMsvEntry* cEntry = iSession->GetEntryL( aMailBoxId.Id() );
  1973         RProcess process;
  1867 //        //CleanupStack::PushL( cEntry );
  1974         // only email server can set outgoing password
  1868 //        
  1975         if ( process.SecureId() == FREESTYLE_FSSERVER_SID )
  1869 //        //api->SetNewPasswordL( *cEntry, aPassword );
  1976             {
  1870 //        
  1977             if ( !iEventHandler->IncomingPass() )
  1871 //        //CleanupStack::PopAndDestroy( 2, api );//cEntry, api
  1978                 {
  1872 //        
  1979                 CMsvEntry* cTmp = iSession->GetEntryL( cEntry->Entry().iRelatedId );
  1873 //        //now signal through eventhandler that credientials have been set       
  1980                 CleanupStack::PopAndDestroy( 1, cEntry );
  1874 //	    }
  1981                 CleanupStack::PushL( cTmp );
  1875 //	else
  1982                 cEntry = cTmp;
  1876 //	    {
  1983                 }
  1877 //	    cancelled = ETrue;
  1984             }
  1878 //	    }
  1985 
  1879 //	iEventHandler->SignalCredientialsSetL( aMailBoxId.Id(), cancelled );
  1986 		api->SetNewPasswordL( *cEntry, aPassword );
  1880 // </qmail>
  1987 
       
  1988         CleanupStack::PopAndDestroy( 2, api );//cEntry, api
       
  1989 
       
  1990         //now signal through eventhandler that credientials have been set
       
  1991 	    }
       
  1992 	else
       
  1993 	    {
       
  1994 	    cancelled = ETrue;
       
  1995 	    }
       
  1996 	iEventHandler->SignalCredientialsSetL( aMailBoxId.Id(), cancelled );
       
  1997 	}
  1881 	}
  1998 
  1882 
  1999 // ----------------------------------------------------------------------------
  1883 // ----------------------------------------------------------------------------
  2000 // CIpsPlgSosBasePlugin::GetMessageEntryL( )
  1884 // CIpsPlgSosBasePlugin::GetMessageEntryL( )
  2001 // Checks whether the requested message is already cached. If not, the cached
  1885 // Checks whether the requested message is already cached. If not, the cached
  2187 void CIpsPlgSosBasePlugin::DeleteAndRemoveOperation(
  2071 void CIpsPlgSosBasePlugin::DeleteAndRemoveOperation(
  2188         const TInt aOpArrayIndex, TInt aCompleteCode )
  2072         const TInt aOpArrayIndex, TInt aCompleteCode )
  2189     {
  2073     {
  2190     FUNC_LOG;
  2074     FUNC_LOG;
  2191     CIpsPlgSingleOpWatcher* opWatcher = iOperations[aOpArrayIndex];
  2075     CIpsPlgSingleOpWatcher* opWatcher = iOperations[aOpArrayIndex];
  2192 
  2076     
       
  2077 // <qmail> removed; does nothing
  2193     // The operations matches, handle it in protocol plugin...if needed.
  2078     // The operations matches, handle it in protocol plugin...if needed.
  2194     TRAP_IGNORE( HandleOpCompletedL( *opWatcher, aCompleteCode ) );
  2079     //TRAP_IGNORE( HandleOpCompletedL( *opWatcher, aCompleteCode ) );
  2195 
  2080 // </qmail>
  2196     const CIpsPlgBaseOperation* op = opWatcher->BaseOperation();
  2081     const CIpsPlgBaseOperation* op = opWatcher->BaseOperation();
  2197     TMsvId service = KErrNotFound;
  2082     TMsvId service = KErrNotFound;
  2198     TUint pluginId = PluginId();
  2083     TUint pluginId = PluginId();
  2199     if ( op && (
  2084     if ( op && (
  2200             op->IpsOpType() == EIpsOpTypeImap4SyncOp  ||
  2085             op->IpsOpType() == EIpsOpTypeImap4SyncOp  ||
  2201              op->IpsOpType() == EIpsOpTypePop3SyncOp ||
  2086              op->IpsOpType() == EIpsOpTypePop3SyncOp ||
  2202              op->IpsOpType() == EIpsOpTypeImap4PopulateOp ||
  2087              op->IpsOpType() == EIpsOpTypeImap4PopulateOp ) )
  2203              op->IpsOpType() == EIpsOpTypePop3PopulateOp ) )
       
  2204         {
  2088         {
  2205         service = op->Service();
  2089         service = op->Service();
  2206         }
  2090         }
  2207     iOperations.Remove( aOpArrayIndex );
  2091     iOperations.Remove( aOpArrayIndex );
  2208     delete opWatcher;
  2092     delete opWatcher;
  2251                     TPtr hPtr( pckg().iHeader->Des() );
  2135                     TPtr hPtr( pckg().iHeader->Des() );
  2252                     HBufC* body = HBufC::NewLC( 
  2136                     HBufC* body = HBufC::NewLC( 
  2253                             textBodyPart->FetchedContentSize() );
  2137                             textBodyPart->FetchedContentSize() );
  2254                     TPtr bPtr( body->Des() );
  2138                     TPtr bPtr( body->Des() );
  2255                     origMsgTextBodyPart->GetContentToBufferL( bPtr, 0 );
  2139                     origMsgTextBodyPart->GetContentToBufferL( bPtr, 0 );
  2256                     TInt contentLength = hPtr.Length() + bPtr.Length() + 
  2140                     HBufC* content = HBufC::NewLC(
  2257                             KLineFeed().Length();
  2141                             hPtr.Length() + bPtr.Length() );
  2258                     HBufC* signatureText = NULL;
  2142                     TPtr cPtr( content->Des() );                        
  2259                     // if signature resolving leaves, ignore it, i.e., 
       
  2260                     // continue without signature adding
       
  2261                     TRAP_IGNORE( signatureText = 
       
  2262                             ResolveSignatureTextL( aMailBoxId ) );
       
  2263                     if ( signatureText ) 
       
  2264                         {
       
  2265                         CleanupStack::PushL( signatureText );
       
  2266                         contentLength += signatureText->Length() +
       
  2267                                 KLineFeed().Length();
       
  2268                         }
       
  2269                     HBufC* content = HBufC::NewLC( contentLength );
       
  2270                     TPtr cPtr( content->Des() );
       
  2271                     if ( signatureText )
       
  2272                         {
       
  2273                         cPtr.Append( *signatureText );
       
  2274                         // extra empty line between signature and original txt
       
  2275                         cPtr.Append( KLineFeed );
       
  2276                         }
       
  2277                     cPtr.Append( KLineFeed );
       
  2278                     cPtr.Append( hPtr );
  2143                     cPtr.Append( hPtr );
  2279                     cPtr.Append( bPtr );
  2144                     cPtr.Append( bPtr );
  2280                     textBodyPart->SetContent( cPtr );
  2145                     textBodyPart->SetContent( cPtr );
  2281                     textBodyPart->SaveL();
  2146                     textBodyPart->SaveL();
  2282                     CleanupStack::PopAndDestroy( content );
  2147                     CleanupStack::PopAndDestroy( content );
  2283                     if ( signatureText )
       
  2284                         {
       
  2285                         CleanupStack::PopAndDestroy( signatureText );
       
  2286                         }
       
  2287                     CleanupStack::PopAndDestroy( body );
  2148                     CleanupStack::PopAndDestroy( body );
  2288                     CleanupStack::PopAndDestroy( origMsgTextBodyPart );
  2149                     CleanupStack::PopAndDestroy( origMsgTextBodyPart );
  2289                     }
  2150                     }
  2290             CleanupStack::PopAndDestroy( origMsg );
  2151             CleanupStack::PopAndDestroy( origMsg );
  2291             }
  2152             }
  2293         }
  2154         }
  2294     }
  2155     }
  2295 
  2156 
  2296 // ---------------------------------------------------------------------------
  2157 // ---------------------------------------------------------------------------
  2297 // ---------------------------------------------------------------------------
  2158 // ---------------------------------------------------------------------------
  2298 HBufC* CIpsPlgSosBasePlugin::ResolveSignatureTextL( 
       
  2299         const TFSMailMsgId& aMailBoxId )
       
  2300     {
       
  2301     FUNC_LOG;
       
  2302     HBufC* signatureText = NULL;
       
  2303         
       
  2304     if ( iSettingsApi && iSession )
       
  2305         {
       
  2306         TMsvEntry entry;
       
  2307         TMsvId serv;
       
  2308         iSession->GetEntry( aMailBoxId.Id(), serv, entry );
       
  2309         signatureText = iSettingsApi->SignatureTextL( entry );
       
  2310         }
       
  2311 
       
  2312     return signatureText;
       
  2313     }
       
  2314 
       
  2315 // ---------------------------------------------------------------------------
       
  2316 // ---------------------------------------------------------------------------
       
  2317 void CIpsPlgSosBasePlugin::DisconnectL(
  2159 void CIpsPlgSosBasePlugin::DisconnectL(
  2318     const TFSMailMsgId& aMailBoxId,
  2160     const TFSMailMsgId& aMailBoxId,
  2319     MFSMailRequestObserver& aObserver,
  2161     MFSMailRequestObserver& aObserver,
  2320     const TInt aRequestId,
  2162     const TInt aRequestId,
  2321     TBool aRemoveAccountAlso )
  2163     TBool /*aRemoveAccountAlso*/ )
  2322     {
  2164     {
  2323     FUNC_LOG;
  2165     FUNC_LOG;
  2324     TMsvId service = aMailBoxId.Id();
  2166     TMsvId service = aMailBoxId.Id();
  2325     TMsvEntry tEntry;
  2167     TMsvEntry tEntry;
  2326     TMsvId serv;
  2168     TMsvId serv;
  2327     iSession->GetEntry( service, serv, tEntry );
  2169     iSession->GetEntry( service, serv, tEntry );
  2328     
       
  2329     CancelSyncL( aMailBoxId );
       
  2330 
  2170 
  2331     if ( tEntry.Connected() )
  2171     if ( tEntry.Connected() )
  2332         {
  2172         {
  2333         CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
  2173         CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
  2334         CleanupStack::PushL( watcher );
  2174         CleanupStack::PushL( watcher );
  2338         CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection;
  2178         CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection;
  2339         CleanupStack::PushL(sel);
  2179         CleanupStack::PushL(sel);
  2340 
  2180 
  2341         sel->AppendL( service );
  2181         sel->AppendL( service );
  2342 
  2182 
  2343         CIpsPlgBaseOperation* op = CIpsPlgDisconnectOp::NewL( *iSession,
  2183         CIpsPlgBaseOperation* op = CIpsPlgDisconnectOp::NewL(
  2344             watcher->iStatus, service, ActivityTimerL( aMailBoxId ),
  2184             *iSession,
  2345             aMailBoxId, aObserver, aRequestId,
  2185             watcher->iStatus, 
  2346             aRemoveAccountAlso );
  2186             service, 
       
  2187             ActivityTimerL( aMailBoxId ),
       
  2188             aMailBoxId, 
       
  2189             &aObserver, 
       
  2190             aRequestId );
  2347 
  2191 
  2348         watcher->SetOperation( op );
  2192         watcher->SetOperation( op );
  2349         CleanupStack::PopAndDestroy( sel );
  2193         CleanupStack::PopAndDestroy( sel );
  2350         iOperations.AppendL( watcher );
  2194         iOperations.AppendL( watcher );
  2351         CleanupStack::Pop( watcher );
  2195         CleanupStack::Pop( watcher );
  2382 void CIpsPlgSosBasePlugin::EmptyOutboxL( const TFSMailMsgId& aMailBoxId )
  2226 void CIpsPlgSosBasePlugin::EmptyOutboxL( const TFSMailMsgId& aMailBoxId )
  2383     {
  2227     {
  2384     FUNC_LOG;
  2228     FUNC_LOG;
  2385     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
  2229     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
  2386  	CleanupStack::PushL(watcher);
  2230  	CleanupStack::PushL(watcher);
  2387     CIpsPlgSmtpOperation* op = CIpsPlgSmtpOperation::NewLC(
  2231 // <qmail>
  2388         *iSession, CActive::EPriorityStandard, watcher->iStatus, ETrue );
  2232     CIpsPlgSmtpOperation* op = CIpsPlgSmtpOperation::NewLC( *iSession, watcher->iStatus );
       
  2233 // </qmail>
  2389     op->SetEventHandler(iEventHandler);
  2234     op->SetEventHandler(iEventHandler);
  2390     watcher->SetOperation(op);
  2235     watcher->SetOperation(op);
  2391     op->EmptyOutboxFromPendingMessagesL( aMailBoxId.Id() );
  2236     op->EmptyOutboxFromPendingMessagesL( aMailBoxId.Id() );
  2392     iOperations.AppendL(watcher);
  2237     iOperations.AppendL(watcher);
  2393     CleanupStack::Pop( 2, watcher );
  2238     CleanupStack::Pop( 2, watcher );
  2569     return iSyncStateHandler->ConnOpRunning( aMailBoxId );
  2414     return iSyncStateHandler->ConnOpRunning( aMailBoxId );
  2570     }
  2415     }
  2571 
  2416 
  2572 // ---------------------------------------------------------------------------
  2417 // ---------------------------------------------------------------------------
  2573 // ---------------------------------------------------------------------------
  2418 // ---------------------------------------------------------------------------
  2574 void CIpsPlgSosBasePlugin::SetMailboxName(
  2419 void CIpsPlgSosBasePlugin::SetMailboxName( 
  2575         const TFSMailMsgId& aMailboxId,
  2420         const TFSMailMsgId& aMailboxId, 
  2576         const TDesC& aMailboxName )
  2421         const TDesC& /*aMailboxName*/ )
  2577     {
  2422     {
  2578     FUNC_LOG;
  2423     FUNC_LOG;
  2579     TMsvEntry tEntry;
  2424     TMsvEntry tEntry;
  2580     TMsvId service;
  2425     TMsvId service;
  2581     iSession->GetEntry( aMailboxId.Id(), service, tEntry );
  2426     iSession->GetEntry( aMailboxId.Id(), service, tEntry );
  2582     TRAP_IGNORE( iSettingsApi->SetMailboxNameL( tEntry, aMailboxName ) );
  2427 // <qmail> iSettingsApi removed
  2583     }
  2428     }
  2584 
  2429 
  2585 // ---------------------------------------------------------------------------
  2430 // ---------------------------------------------------------------------------
  2586 // ---------------------------------------------------------------------------
  2431 // ---------------------------------------------------------------------------
  2587 TUid CIpsPlgSosBasePlugin::MtmId() const
  2432 TUid CIpsPlgSosBasePlugin::MtmId() const
  2618             timerCount--;
  2463             timerCount--;
  2619             j--;
  2464             j--;
  2620             }
  2465             }
  2621         }
  2466         }
  2622     }
  2467     }
  2623 // ---------------------------------------------------------------------------
  2468 
  2624 // finds and returns extension
  2469 // <qmail> new function
       
  2470 // ---------------------------------------------------------------------------
       
  2471 // ---------------------------------------------------------------------------
       
  2472 TBool CIpsPlgSosBasePlugin::HasOperations( const TFSMailMsgId& aMailboxId )
       
  2473     {
       
  2474     FUNC_LOG;
       
  2475     TBool ret( EFalse );
       
  2476     for ( TInt i = 0; i < iOperations.Count(); i++ )
       
  2477         {
       
  2478         if( iOperations[i]->BaseOperation() && 
       
  2479             iOperations[i]->BaseOperation()->FSMailboxId() == aMailboxId )
       
  2480             {
       
  2481             ret = ETrue;
       
  2482             }
       
  2483         }
       
  2484     return ret;
       
  2485     }
       
  2486 //</Qmail>
       
  2487 //<Qmail>
       
  2488 // ---------------------------------------------------------------------------
       
  2489 // CIpsPlgImap4Plugin::HandleActiveFolderChangeL
  2625 // ---------------------------------------------------------------------------
  2490 // ---------------------------------------------------------------------------
  2626 //
  2491 //
  2627 CEmailExtension* CIpsPlgSosBasePlugin::ExtensionL( const TUid& aInterfaceUid )
  2492 void CIpsPlgSosBasePlugin::HandleActiveFolderChangeL(
  2628     {
  2493         const TFSMailMsgId& aActiveMailboxId,
  2629     FUNC_LOG;
  2494         const TFSMailMsgId& aActiveFolderId)
  2630     
  2495     {
  2631     // search for settings extension
  2496     TMsvId service;
  2632     CEmailExtension* extension = CExtendableEmail::ExtensionL( aInterfaceUid );
  2497     TMsvEntry folder;
  2633     
  2498     iSession->GetEntry( aActiveFolderId.Id(), service, folder );
  2634     // if not found create settings extension
  2499     
  2635     if ( extension == NULL && aInterfaceUid == KEmailSettingExtensionUid)
  2500     
  2636         {
  2501     //currently, no actions unless this is inbox
  2637         extension = new (ELeave) CEmailSettingsExtensionImpl(iSession);
  2502     //also, if id is '0', it means inbox before first sync...it doesn't really exist yet
  2638         CleanupStack::PushL( extension );
  2503     if( folder.iDetails.CompareF( KIpsPlgInbox ) == 0 || folder.Id() == 0 || 
  2639         iExtensions.AddL( extension );
  2504             ( folder.iMtm == KSenduiMtmPop3Uid ) &&
  2640         CleanupStack::Pop(); 
  2505             ( folder.iType == KUidMsvServiceEntry ) &&
  2641         }
  2506             ( folder.iServiceId == aActiveFolderId.Id() ) )
  2642     return extension;
  2507         {
  2643     }
  2508         //folder is inbox
       
  2509         if ( iSyncStateHandler->GetMailboxIpsState( aActiveMailboxId.Id() )
       
  2510                     == KIpsSosEmailSyncStarted )
       
  2511             {
       
  2512             //we won't do anything if sync is already started
       
  2513             return;
       
  2514             }
       
  2515         
       
  2516         //check are we in polling mode
       
  2517         NmIpsSosExtendedSettingsManager* eMgr= 
       
  2518                 new NmIpsSosExtendedSettingsManager(aActiveMailboxId.Id());
       
  2519         
       
  2520         QVariant value;
       
  2521         bool ok = eMgr->readSetting(IpsServices::ReceptionActiveProfile, value);
       
  2522         delete eMgr;
       
  2523         
       
  2524         if ( ok )
       
  2525             {
       
  2526             TInt profile = value.toInt();
       
  2527             if ( profile != IpsServices::EmailSyncProfileManualFetch )
       
  2528                 {
       
  2529                 // let's sync
       
  2530                 GoOnlineL(aActiveMailboxId);
       
  2531                 }
       
  2532             }        
       
  2533         }        
       
  2534     }
       
  2535 // </qmail>