emailservices/emailstore/base_plugin/src/BasePlugin.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 47 f83bd4ae1fe3
child 54 997a02608b3a
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    28 #include "MsgStoreSortCriteria.h"
    28 #include "MsgStoreSortCriteria.h"
    29 #include "MsgStoreSortResultIterator.h"
    29 #include "MsgStoreSortResultIterator.h"
    30 //Freestyle.
    30 //Freestyle.
    31 #include "CFSMailCommon.h"
    31 #include "CFSMailCommon.h"
    32 #include "CFSMailMessage.h"
    32 #include "CFSMailMessage.h"
    33 #include "CFSMailFolder.h"
    33 #include "cmrcalendarinfo.h" 
    34 //</cmail>
    34 //</cmail>
    35 //Base plugin.
    35 //Base plugin.
    36 #include "BasePlugin.h"
    36 #include "BasePlugin.h"
    37 #include "BasePluginPanic.h"
    37 #include "BasePluginPanic.h"
    38 #include "baseplugincommonutils.h"
    38 #include "baseplugincommonutils.h"
    39 #include "MailIterator.h"
    39 #include "MailIterator.h"
    40 #include "baseplugindelayedopsprivate.h"
    40 #include "baseplugindelayedopsprivate.h"
       
    41 
       
    42 //<qmail>
       
    43 #include "CFSMailFolder.h"
    41 #include "baseplugindef.h"
    44 #include "baseplugindef.h"
       
    45 //</qmail>
       
    46 
    42 // Other
    47 // Other
    43 #include <e32base.h>
    48 #include <e32base.h>
    44 #include <utf.h>
    49 #include <utf.h>
       
    50 #include <calsession.h>
    45 
    51 
    46 //<qmail>
    52 //<qmail>
    47 //<cmail>
    53 //<cmail>
    48 //#include "freestyleemailuiconstants.h" // removed from 10.1
    54 //#include "freestyleemailuiconstants.h" // removed from 10.1
    49 //</cmail>
    55 //</cmail>
   110     delete iDelayedOpsManager;
   116     delete iDelayedOpsManager;
   111     
   117     
   112     iMailboxes.ResetAndDestroy();
   118     iMailboxes.ResetAndDestroy();
   113     iMailboxes.Close();
   119     iMailboxes.Close();
   114 
   120 
       
   121 //<qmail>
   115     if ( iObservers.Count() > 0 && iMsgStore )
   122     if ( iObservers.Count() > 0 && iMsgStore )
       
   123 //</qmail>
   116         {
   124         {
   117         TRAP_IGNORE( iMsgStore->RemoveObserverL( this ) );
   125         TRAP_IGNORE( iMsgStore->RemoveObserverL( this ) );
   118         }
   126         }
   119     iObservers.Close();
   127     iObservers.Close();
   120 
   128 
   259     CleanupStack::Pop( ownMailBox );
   267     CleanupStack::Pop( ownMailBox );
   260 
   268 
   261     MMRInfoProcessor* infoProcessor = CBaseMrInfoProcessor::NewL( *this );
   269     MMRInfoProcessor* infoProcessor = CBaseMrInfoProcessor::NewL( *this );
   262     result->SetMRInfoProcessorL( infoProcessor );
   270     result->SetMRInfoProcessorL( infoProcessor );
   263     
   271     
       
   272     //JOJA-83VJ4L Plugins need to set the correct Calendar Database ID for MRUI to work
       
   273     //get the calendar file name from the derived class
       
   274     const TDesC& calFileName = CalendarFileName();
       
   275     if ( calFileName != KNullDesC )
       
   276         {
       
   277         //the derived class does use its own calendar file, check if that file exists
       
   278         //the file may not exist because cal sync was disabled, or the file was deleted from the calendar UI
       
   279         CCalSession* calSession = CCalSession::NewL();
       
   280         CleanupStack::PushL( calSession );
       
   281         
       
   282         TRAPD( error, calSession->OpenL( calFileName ) );
       
   283         if ( error == KErrNone )
       
   284             {
       
   285             //calendar file exists, get its file id, and set it to cMail Celendar Info via the extention
       
   286             TCalFileId fileId = KNullFileId; 
       
   287             calSession->FileIdL( fileId );
       
   288             
       
   289             //get the extention api for the MR info, set the cal db id, and release the extention
       
   290             CEmailExtension* extension = NULL;
       
   291             TRAP( error, extension = result->ExtensionL( KMailboxExtMrCalInfo ) );
       
   292             if ( error == KErrNone )
       
   293                 {
       
   294                 CMRCalendarInfo* calInfo = reinterpret_cast<CMRCalendarInfo*>( extension );
       
   295                 calInfo->SetCalendarDatabaseIdL( fileId ); // cannot actually leave
       
   296                 result->ReleaseExtension( calInfo );
       
   297                 }
       
   298             }
       
   299         
       
   300         CleanupStack::PopAndDestroy( calSession );
       
   301         }
       
   302     
   264     CleanupStack::Pop( result );
   303     CleanupStack::Pop( result );
   265     
   304     
   266     __LOG_EXIT
   305     __LOG_EXIT
   267     return result;
   306     return result;
   268     }
   307     }
   642         mailboxInfo.iRootFolders.iFolders[EFSDraftsFolder], *props );
   681         mailboxInfo.iRootFolders.iFolders[EFSDraftsFolder], *props );
   643 
   682 
   644     CleanupStack::PopAndDestroy( props );
   683     CleanupStack::PopAndDestroy( props );
   645     CleanupStack::PushL( message );
   684     CleanupStack::PushL( message );
   646     
   685     
   647     
   686     //create the body part.
   648     //the body part.
       
   649     props = CMsgStorePropertyContainer::NewL();
   687     props = CMsgStorePropertyContainer::NewL();
   650     CleanupStack::PushL( props );
   688     CleanupStack::PushL( props );
   651     props->AddOrUpdatePropertyL( KMsgStorePropertyContentType, KFSMailContentTypeMultipartAlternative );
   689     
   652     
   690     props->AddOrUpdatePropertyL(
       
   691         KMsgStorePropertyContentType, KFSMailContentTypeMultipartAlternative );
   653     CMsgStoreMessagePart* bodyPart = message->AddChildPartL( *props );
   692     CMsgStoreMessagePart* bodyPart = message->AddChildPartL( *props );
       
   693     
   654     CleanupStack::PopAndDestroy( props );
   694     CleanupStack::PopAndDestroy( props );
   655     CleanupStack::PushL( bodyPart );
   695     CleanupStack::PushL( bodyPart );
   656     
   696     
   657     //the text/plain child.
   697     //create the plain text part.
   658     props = CMsgStorePropertyContainer::NewL();
   698     props = CMsgStorePropertyContainer::NewL();
   659     CleanupStack::PushL( props );
   699     CleanupStack::PushL( props );
   660     
   700 
   661     props->AddPropertyL( KMsgStorePropertyContentType, KFSMailContentTypeTextPlain );
   701     props->AddPropertyL(
   662     
   702         KMsgStorePropertyContentType, KFSMailContentTypeTextPlain );
       
   703 
   663     _LIT(KMessageBodyCharset, "UTF-8");
   704     _LIT(KMessageBodyCharset, "UTF-8");
   664     props->AddPropertyL( KMsgStorePropertyCharset, KMessageBodyCharset );
   705     props->AddPropertyL( KMsgStorePropertyCharset, KMessageBodyCharset );
   665     
   706 
   666     _LIT(KMessageBodyDisposition, "inline");
   707     _LIT(KMessageBodyDisposition, "inline");
   667     props->AddPropertyL( KMsgStorePropertyContentDisposition, KMessageBodyDisposition );
   708     props->AddPropertyL(
   668  
   709         KMsgStorePropertyContentDisposition, KMessageBodyDisposition );
   669     CMsgStoreMessagePart* textPlain = NULL;
   710 
       
   711     HBufC* signature = GetSignatureL( aMailBox );
       
   712     if ( signature )
       
   713         {
       
   714         CleanupStack::PushL( signature );       
       
   715 
       
   716         props->AddPropertyL(
       
   717             KMsgStorePropertySize, static_cast<TUint32>( signature->Length() ) );
       
   718         props->AddPropertyL(
       
   719             KMsgStorePropertyRetrievedSize,
       
   720             static_cast<TUint32>( signature->Length() ) );
       
   721         }
       
   722     
       
   723     CMsgStoreMessagePart* textPlain = bodyPart->AddChildPartL( *props );
       
   724     if ( signature )
       
   725         {
       
   726         CleanupStack::Pop( signature );
       
   727         }
       
   728     CleanupStack::PopAndDestroy( props );           
       
   729     if ( signature )
       
   730         {
       
   731         CleanupStack::PushL( signature );
       
   732         }
       
   733     CleanupStack::PushL( textPlain );
       
   734     
       
   735     //add signature, if it exists
       
   736 	if ( NULL != signature && signature->Length() )
       
   737         {
       
   738         TPtrC8 ptr8(
       
   739             reinterpret_cast<const TUint8*>( signature->Ptr() ),
       
   740             signature->Size() );
   670         
   741         
   671     // Add signature, if it exists
   742         textPlain->ReplaceContentL( ptr8 );
   672     HBufC* signature = GetSignatureL( aMailBox );
   743 		}
   673     
   744 
   674 	if ( NULL != signature )
   745 	CleanupStack::PopAndDestroy( textPlain );
   675         {
   746     if ( signature )
   676         CleanupStack::PushL( signature );       
   747         {
   677 
       
   678         if ( signature->Length() > 0 )
       
   679     		{
       
   680 
       
   681             props->AddPropertyL( KMsgStorePropertySize, static_cast<TUint32>( signature->Length() ) );
       
   682             props->AddPropertyL( KMsgStorePropertyRetrievedSize, static_cast<TUint32>( signature->Length() ) );
       
   683             textPlain = bodyPart->AddChildPartL( *props );
       
   684             CleanupStack::PopAndDestroy( props );
       
   685     
       
   686             TPtrC8 ptr8(
       
   687                     reinterpret_cast<const TUint8*>( signature->Ptr() ),
       
   688                     signature->Size() );
       
   689            
       
   690             CleanupStack::PushL( textPlain );
       
   691             textPlain->ReplaceContentL( ptr8 );
       
   692          
       
   693             }
       
   694         CleanupStack::PopAndDestroy( signature );
   748         CleanupStack::PopAndDestroy( signature );
   695 		}
   749         }
   696 	else{
   750     
   697         textPlain =bodyPart->AddChildPartL( *props );
   751 //<qmail> 
   698 	    CleanupStack::PopAndDestroy( props );           
   752     //create the text/html part.
   699 	    CleanupStack::PushL( textPlain );
       
   700 	    }
       
   701 	
       
   702     CleanupStack::PopAndDestroy( textPlain );
       
   703     
       
   704     
       
   705     //the text/html child.
       
   706     props = CMsgStorePropertyContainer::NewL();
   753     props = CMsgStorePropertyContainer::NewL();
   707     CleanupStack::PushL( props );
   754     CleanupStack::PushL( props );
   708     
   755     
   709     props->AddPropertyL( KMsgStorePropertyContentType, KFSMailContentTypeTextHtml );
   756 	props->AddPropertyL(
   710     
   757         KMsgStorePropertyContentType, KFSMailContentTypeTextHtml );
       
   758 	
   711     props->AddPropertyL( KMsgStorePropertyCharset, KMessageBodyCharset );
   759     props->AddPropertyL( KMsgStorePropertyCharset, KMessageBodyCharset );
   712     
   760 
   713     props->AddPropertyL( KMsgStorePropertyContentDisposition, KMessageBodyDisposition );
   761     props->AddPropertyL(
       
   762         KMsgStorePropertyContentDisposition, KMessageBodyDisposition );
   714     
   763     
   715     CMsgStoreMessagePart* htmlPlain = bodyPart->AddChildPartL( *props );
   764     CMsgStoreMessagePart* htmlPlain = bodyPart->AddChildPartL( *props );
   716     CleanupStack::PopAndDestroy( props );         
   765     CleanupStack::PopAndDestroy( props );         
   717     CleanupStack::PushL( htmlPlain );
   766     CleanupStack::PushL( htmlPlain );
   718     htmlPlain->AppendToContentL(KNullDesC8);
   767     htmlPlain->AppendToContentL(KNullDesC8);
   719     CleanupStack::PopAndDestroy( htmlPlain );
   768     CleanupStack::PopAndDestroy( htmlPlain );
       
   769 //</qmail>
   720     
   770     
   721     //delete body part
   771     //delete body part
   722     CleanupStack::PopAndDestroy( bodyPart );
   772     CleanupStack::PopAndDestroy( bodyPart );
   723     
   773 	
       
   774 	//done.
   724     message->CommitL();
   775     message->CommitL();
   725 
   776     
   726     TFSMailMsgId folderId( GetPluginId(), message->ParentId() );
   777     TFSMailMsgId folderId( GetPluginId(), message->ParentId() );
   727     TFSMailMsgId msgId( GetPluginId(), message->Id() );
   778     TFSMailMsgId msgId( GetPluginId(), message->Id() );
   728     CleanupStack::PopAndDestroy( message );
   779     CleanupStack::PopAndDestroy( message );
   729 
   780 
   730     CFSMailMessage* result = CFSMailMessage::NewL( msgId );    
   781     CFSMailMessage* result = CFSMailMessage::NewL( msgId );    
   761     const TDesC& aHeaderDescriptor )
   812     const TDesC& aHeaderDescriptor )
   762     {
   813     {
   763     return CreateForwardReplyMessageL( aMailBox, aOriginal, EFalse, aHeaderDescriptor, ETrue );
   814     return CreateForwardReplyMessageL( aMailBox, aOriginal, EFalse, aHeaderDescriptor, ETrue );
   764     }
   815     }
   765 
   816 
       
   817 
   766 /**
   818 /**
   767  * Relying on the UI for the subject and recipients.
   819  * Relying on the UI for the subject and recipients.
   768  */
   820  */
   769  CFSMailMessage* CBasePlugin::CreateReplyMessageL(
   821  CFSMailMessage* CBasePlugin::CreateReplyMessageL(
   770     const TFSMailMsgId& aMailBoxId,
   822     const TFSMailMsgId& aMailBoxId,
   772     const TBool aReplyToAll,
   824     const TBool aReplyToAll,
   773     const TDesC& aHeaderDescriptor )
   825     const TDesC& aHeaderDescriptor )
   774     {
   826     {
   775     return CreateForwardReplyMessageL( aMailBoxId, aOriginalMessageId, aReplyToAll, aHeaderDescriptor, EFalse );
   827     return CreateForwardReplyMessageL( aMailBoxId, aOriginalMessageId, aReplyToAll, aHeaderDescriptor, EFalse );
   776     }
   828     }
       
   829 
   777 
   830 
   778 /**
   831 /**
   779  *
   832  *
   780  */
   833  */
   781  CFSMailMessage* CBasePlugin::CreateMrReplyMessageL(
   834  CFSMailMessage* CBasePlugin::CreateMrReplyMessageL(