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