emailservices/emailcommon/src/CFSMailFolder.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 30 759dc5235cdb
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    13 *
    13 *
    14 * Description:  common email folder object
    14 * Description:  common email folder object
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 // <qmail>
       
    19 #include <nmcommonheaders.h>
       
    20 // </qmail>
    18 
    21 
    19 //<cmail>
    22 //<cmail>
    20 #include <nmcommonheaders.h>
       
    21 #include "emailtrace.h"
    23 #include "emailtrace.h"
    22 #include "CFSMailFolder.h"
    24 #include "CFSMailFolder.h"
    23 #include "CFSMailPlugin.h"
    25 #include "CFSMailPlugin.h"
    24 //</cmail>
    26 //</cmail>
    25 
    27 
    31 // CFSMailFolder::NewLC
    33 // CFSMailFolder::NewLC
    32 // -----------------------------------------------------------------------------
    34 // -----------------------------------------------------------------------------
    33 EXPORT_C CFSMailFolder* CFSMailFolder::NewLC( TFSMailMsgId aFolderId )
    35 EXPORT_C CFSMailFolder* CFSMailFolder::NewLC( TFSMailMsgId aFolderId )
    34 {
    36 {
    35     FUNC_LOG;
    37     FUNC_LOG;
    36     CFSMailFolder* api = new (ELeave) CFSMailFolder();
    38   CFSMailFolder* api = new (ELeave) CFSMailFolder();
    37     CleanupStack:: PushL(api);
    39   CleanupStack:: PushL(api);
    38     api->ConstructL( aFolderId );
    40   api->ConstructL( aFolderId );
    39     return api;
    41   return api;
    40 } 
    42 } 
    41 
    43 
    42 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    43 // CFSMailFolder::NewL
    45 // CFSMailFolder::NewL
    44 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    45 EXPORT_C CFSMailFolder* CFSMailFolder::NewL( TFSMailMsgId aFolderId )
    47 EXPORT_C CFSMailFolder* CFSMailFolder::NewL( TFSMailMsgId aFolderId )
    46 {
    48 {
    47     FUNC_LOG;
    49     FUNC_LOG;
    48     CFSMailFolder* api =  CFSMailFolder::NewLC( aFolderId );
    50   CFSMailFolder* api =  CFSMailFolder::NewLC( aFolderId );
    49     CleanupStack:: Pop(api);
    51   CleanupStack:: Pop(api);
    50     return api;
    52   return api;
    51 }
    53 }
    52 
    54 
    53 // -----------------------------------------------------------------------------
    55 // -----------------------------------------------------------------------------
    54 // CFSMailFolder::CFSMailFolder
    56 // CFSMailFolder::CFSMailFolder
    55 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    56 CFSMailFolder::CFSMailFolder()
    58 CFSMailFolder::CFSMailFolder()
    57 {
    59 {
    58     FUNC_LOG;
    60     FUNC_LOG;
       
    61 
    59 }
    62 }
    60 
    63 
    61 // -----------------------------------------------------------------------------
    64 // -----------------------------------------------------------------------------
    62 // CFSMailFolder::ConstructL
    65 // CFSMailFolder::ConstructL
    63 // -----------------------------------------------------------------------------
    66 // -----------------------------------------------------------------------------
    64 void CFSMailFolder::ConstructL( TFSMailMsgId aFolderId )
    67 void CFSMailFolder::ConstructL( TFSMailMsgId aFolderId )
    65 {
    68 {
    66     FUNC_LOG;
    69     FUNC_LOG;
       
    70 // <qmail>
    67     CFSMailFolderBase::ConstructL( aFolderId );
    71     CFSMailFolderBase::ConstructL( aFolderId );
    68     
    72 // </qmail>
    69     // get requesthandler pointer
    73     
    70     iRequestHandler = static_cast<CFSMailRequestHandler*>(Dll::Tls());
    74 	// get requesthandler pointer
    71 
    75 	iRequestHandler = static_cast<CFSMailRequestHandler*>(Dll::Tls());
    72     // set folder id
       
    73     iFolderId = aFolderId;
       
    74 }
    76 }
    75 
    77 
    76 // -----------------------------------------------------------------------------
    78 // -----------------------------------------------------------------------------
    77 // CFSMailFolder::~CFSMailFolder
    79 // CFSMailFolder::~CFSMailFolder
    78 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    79 EXPORT_C CFSMailFolder::~CFSMailFolder()
    81 EXPORT_C CFSMailFolder::~CFSMailFolder()
    80 {
    82 {
    81     FUNC_LOG;
    83     FUNC_LOG;
       
    84 
    82 }
    85 }
    83 
    86 
    84 // -----------------------------------------------------------------------------
    87 // -----------------------------------------------------------------------------
    85 // CFSMailFolder::ListMessagesL
    88 // CFSMailFolder::ListMessagesL
    86 // -----------------------------------------------------------------------------
    89 // -----------------------------------------------------------------------------
    87 EXPORT_C MFSMailIterator* CFSMailFolder::ListMessagesL( const TFSMailDetails aDetails,
    90 EXPORT_C MFSMailIterator* CFSMailFolder::ListMessagesL( const TFSMailDetails aDetails,
    88                     const RArray<TFSMailSortCriteria>& aSorting )
    91         						const RArray<TFSMailSortCriteria>& aSorting)
    89 {
    92 {
    90     FUNC_LOG;
    93     FUNC_LOG;
    91 
    94 
    92     CFSMailIterator* iterator = NULL;
    95 	CFSMailIterator* iterator = NULL;
    93     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
    96 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
       
    97 		{
       
    98 		MFSMailIterator* pluginIterator =
       
    99 		plugin->ListMessagesL(GetMailBoxId(),GetFolderId(),aDetails,aSorting);
       
   100 		if(pluginIterator)
       
   101 			{
       
   102 			iterator = CFSMailIterator::NewL(*pluginIterator,iRequestHandler );
       
   103 			}
       
   104 		}
       
   105 	return iterator;
       
   106 }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CFSMailFolder::FetchMessagesL
       
   110 // -----------------------------------------------------------------------------
       
   111 EXPORT_C TInt CFSMailFolder::FetchMessagesL( 	const RArray<TFSMailMsgId>& aMessageIds,
       
   112      							 				TFSMailDetails aDetails,
       
   113      							 				MFSMailRequestObserver& aObserver )
       
   114 	{
       
   115     FUNC_LOG;
       
   116 	// init asynchronous request
       
   117 	CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId());
       
   118     TFSPendingRequest request = 
       
   119     	iRequestHandler->InitAsyncRequestL(	GetFolderId().PluginId(), aObserver );
       
   120 
       
   121     TInt err = KErrNone;
       
   122     
       
   123     if (plugin)
    94         {
   124         {
    95         MFSMailIterator* pluginIterator =
   125         MFSMailRequestObserver* observer = request.iObserver;
    96             plugin->ListMessagesL(GetMailBoxId(),GetFolderId(),aDetails,aSorting);
   126         TRAP(err,plugin->FetchMessagesL(	GetMailBoxId(),
    97         if(pluginIterator)
   127                                             GetFolderId(),
    98             {
   128                                             aMessageIds,
    99             iterator = CFSMailIterator::NewL(*pluginIterator,iRequestHandler );
   129                                             aDetails,
   100             }
   130                                             *observer,
       
   131                                             request.iRequestId));
   101         }
   132         }
   102     return iterator;
   133     else 
   103 }
   134         {
   104 
   135         err = KErrNotFound;        
   105 // -----------------------------------------------------------------------------
   136         }
   106 // CFSMailFolder::FetchMessagesL
   137     
   107 // -----------------------------------------------------------------------------
       
   108 EXPORT_C TInt CFSMailFolder::FetchMessagesL( const RArray<TFSMailMsgId>& aMessageIds,
       
   109                           TFSMailDetails aDetails,
       
   110                           MFSMailRequestObserver& aObserver )
       
   111 {
       
   112     FUNC_LOG;
       
   113     // init asynchronous request
       
   114     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId());
       
   115   
       
   116     TFSPendingRequest request = 
       
   117       iRequestHandler->InitAsyncRequestL( GetFolderId().PluginId(), aObserver );
       
   118       
       
   119     MFSMailRequestObserver* observer = request.iObserver;
       
   120     TRAPD(err,plugin->FetchMessagesL( GetMailBoxId(),
       
   121                       GetFolderId(),
       
   122                       aMessageIds,
       
   123                       aDetails,
       
   124                       *observer,
       
   125                       request.iRequestId));
       
   126     if(err != KErrNone)
   138     if(err != KErrNone)
   127         {
   139         {
   128         iRequestHandler->CompleteRequest(request.iRequestId);
   140         iRequestHandler->CompleteRequest(request.iRequestId);
   129         User::Leave(err);
   141         User::Leave(err);
   130         }
   142         }
   131     return request.iRequestId;  
   143     return request.iRequestId;
   132 }
   144     
       
   145 	}
   133 
   146 
   134 
   147 
   135 // -----------------------------------------------------------------------------
   148 // -----------------------------------------------------------------------------
   136 // CFSMailFolder::GetSubFoldersL
   149 // CFSMailFolder::GetSubFoldersL
   137 // -----------------------------------------------------------------------------
   150 // -----------------------------------------------------------------------------
   138 EXPORT_C void CFSMailFolder::GetSubFoldersL( RPointerArray<CFSMailFolder>& aSubFolders )
   151 EXPORT_C void CFSMailFolder::GetSubFoldersL(RPointerArray<CFSMailFolder>& aSubFolders)
   139 {
   152 {
   140     FUNC_LOG;
   153     FUNC_LOG;
   141     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
   154 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
   142         {
   155 		{
   143         TRAPD(err,plugin->ListFoldersL( GetMailBoxId(), GetFolderId(), aSubFolders));
   156 		TRAPD(err,plugin->ListFoldersL( GetMailBoxId(), GetFolderId(), aSubFolders));
   144         if(err != KErrNone)
   157 		if(err != KErrNone)
   145             {
   158 			{
   146             aSubFolders.ResetAndDestroy();
   159 			aSubFolders.ResetAndDestroy();
   147             }
   160 			}
   148         }
   161 		}
   149 }
   162 }
   150   
   163 	
   151 // -----------------------------------------------------------------------------
   164 // -----------------------------------------------------------------------------
   152 // CFSMailFolder::RemoveMessageL
   165 // CFSMailFolder::RemoveMessageL
   153 // -----------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------
   154 EXPORT_C void CFSMailFolder::RemoveMessageL( TFSMailMsgId aMessage )
   167 EXPORT_C void CFSMailFolder::RemoveMessageL(TFSMailMsgId aMessage)
   155 {
   168 {
   156     FUNC_LOG;
   169     FUNC_LOG;
   157     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
   170 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
   158         {
   171 		{
   159         RArray<TFSMailMsgId> messages;
   172 		RArray<TFSMailMsgId> messages;
   160         messages.Reset();
   173 		messages.Reset();
   161         messages.Append(aMessage);
   174 		messages.Append(aMessage);
   162         plugin->DeleteMessagesByUidL(GetMailBoxId(),GetFolderId(),messages);
   175 		plugin->DeleteMessagesByUidL(GetMailBoxId(),GetFolderId(),messages);
   163         messages.Close();
   176 		messages.Close();
   164         }
   177 		}
   165 }
   178 }
   166 
   179 
   167 // -----------------------------------------------------------------------------
   180 // -----------------------------------------------------------------------------
   168 // CFSMailFolder::SupportsCopyFromL
   181 // CFSMailFolder::SupportsCopyFromL
   169 // -----------------------------------------------------------------------------
   182 // -----------------------------------------------------------------------------
   170 EXPORT_C TBool CFSMailFolder::SupportsCopyFromL( TFSFolderType aFolderType )
   183 EXPORT_C TBool CFSMailFolder::SupportsCopyFromL( TFSFolderType aFolderType )
   171 {
   184 	{
   172     FUNC_LOG;
   185     FUNC_LOG;
   173   
   186 	
   174     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
   187 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
   175         {
   188 		{
   176         TFSMailBoxStatus onlineStatus = plugin->GetMailBoxStatus(GetMailBoxId());
   189 		TFSMailBoxStatus onlineStatus = plugin->GetMailBoxStatus(GetMailBoxId());
   177         if(onlineStatus == EFSMailBoxOnline)
   190 		if(onlineStatus == EFSMailBoxOnline)
   178             {
   191 			{
   179             for(TInt i=0;i<iCopyOnlineBlocked.Count();i++)
   192 			for(TInt i=0;i<iCopyOnlineBlocked.Count();i++)
   180                 {
   193 				{
   181                 if(iCopyOnlineBlocked[i] == aFolderType)
   194 				if(iCopyOnlineBlocked[i] == aFolderType)
   182                     {
   195 					{
   183                     return EFalse;
   196 					return EFalse;
   184                     }     
   197 					}			
   185                 }
   198 				}
   186             }
   199 			}
   187         else if(onlineStatus == EFSMailBoxOffline)
   200 		else if(onlineStatus == EFSMailBoxOffline)
   188             {
   201 			{
   189             for(TInt i=0;i<iCopyOfflineBlocked.Count();i++)
   202 			for(TInt i=0;i<iCopyOfflineBlocked.Count();i++)
   190                 {
   203 				{
   191                 if(iCopyOfflineBlocked[i] == aFolderType)
   204 				if(iCopyOfflineBlocked[i] == aFolderType)
   192                     {
   205 					{
   193                     return EFalse;
   206 					return EFalse;
   194                     }
   207 					}
   195                 }
   208 				}
   196             }
   209 			}
   197     }
   210 		}
   198     return ETrue;
   211 		return ETrue;
   199 }
   212 	}
   200 
   213 
   201 // -----------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
   202 // CFSMailFolder::SupportsMoveFromL
   215 // CFSMailFolder::SupportsMoveFromL
   203 // -----------------------------------------------------------------------------
   216 // -----------------------------------------------------------------------------
   204 EXPORT_C TBool CFSMailFolder::SupportsMoveFromL( TFSFolderType aFolderType )
   217 EXPORT_C TBool CFSMailFolder::SupportsMoveFromL( TFSFolderType aFolderType )
   205 {
   218 	{
   206     FUNC_LOG;
   219     FUNC_LOG;
   207 
   220 
   208     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
   221 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId()))
   209         {
   222 		{
   210         TFSMailBoxStatus onlineStatus = plugin->GetMailBoxStatus(GetMailBoxId());
   223 		TFSMailBoxStatus onlineStatus = plugin->GetMailBoxStatus(GetMailBoxId());
   211         if(onlineStatus == EFSMailBoxOnline)
   224 		if(onlineStatus == EFSMailBoxOnline)
   212             {
   225 			{
   213             for(TInt i=0;i<iMoveOnlineBlocked.Count();i++)
   226 			for(TInt i=0;i<iMoveOnlineBlocked.Count();i++)
   214                 {
   227 				{
   215                 if(iMoveOnlineBlocked[i] == aFolderType)
   228 				if(iMoveOnlineBlocked[i] == aFolderType)
   216                     {
   229 					{
   217                     return EFalse;
   230 					return EFalse;
   218                     }     
   231 					}			
   219                 }
   232 				}
   220             }
   233 			}
   221         else if(onlineStatus == EFSMailBoxOffline)
   234 		else if(onlineStatus == EFSMailBoxOffline)
   222             {
   235 			{
   223             for(TInt i=0;i<iMoveOfflineBlocked.Count();i++)
   236 			for(TInt i=0;i<iMoveOfflineBlocked.Count();i++)
   224                 {
   237 				{
   225                 if(iMoveOfflineBlocked[i] == aFolderType)
   238 				if(iMoveOfflineBlocked[i] == aFolderType)
   226                     {
   239 					{
   227                     return EFalse;
   240 					return EFalse;
   228                     }
   241 					}
   229                 }
   242 				}
   230             }
   243 			}
   231     }
   244 		}
   232     return ETrue;
   245 		return ETrue;
   233 }
   246 	
   234 
   247 	}
   235 // -----------------------------------------------------------------------------
   248 // -----------------------------------------------------------------------------
   236 // CFSMailFolder::RemoveDownLoadedAttachmentsL
   249 // CFSMailFolder::RemoveDownLoadedAttachmentsL
   237 // -----------------------------------------------------------------------------
   250 // -----------------------------------------------------------------------------
   238 EXPORT_C void CFSMailFolder::RemoveDownLoadedAttachmentsL()
   251 EXPORT_C void CFSMailFolder::RemoveDownLoadedAttachmentsL()
   239 {
   252     {
   240     FUNC_LOG;
   253     FUNC_LOG;
   241     
   254     
   242     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId());
   255     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetFolderId());
   243     // <qmail>
   256     if(plugin != NULL)
   244     if(plugin)
       
   245     // </qmail
       
   246         {
   257         {
   247         MFSMailIterator* iterator = NULL;
   258         MFSMailIterator* iterator = NULL;
   248 
   259 
   249         // select message details to be listed
   260         // select message details to be listed
   250         TFSMailDetails details(EFSMsgDataEnvelope);
   261         TFSMailDetails details(EFSMsgDataEnvelope);
   271                 }
   282                 }
   272             messages.ResetAndDestroy();
   283             messages.ResetAndDestroy();
   273             delete iterator;
   284             delete iterator;
   274             }
   285             }
   275         }
   286         }
   276 }
   287     }
   277 
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CFSMailFolder::ReleaseExtension
       
   291 // -----------------------------------------------------------------------------
       
   292 EXPORT_C void CFSMailFolder::ReleaseExtension( CEmailExtension* aExtension )
       
   293     {
       
   294     FUNC_LOG;
       
   295     // no specialized behaviour, call base class
       
   296     CExtendableEmail::ReleaseExtension( aExtension );
       
   297     }
       
   298     
       
   299 // -----------------------------------------------------------------------------
       
   300 // CFSMailFolder::ExtensionL
       
   301 // -----------------------------------------------------------------------------
       
   302 EXPORT_C CEmailExtension* CFSMailFolder::ExtensionL( const TUid& aInterfaceUid )
       
   303     {
       
   304     FUNC_LOG;
       
   305     return CExtendableEmail::ExtensionL( aInterfaceUid );
       
   306     }
       
   307