49 } |
48 } |
50 |
49 |
51 /** |
50 /** |
52 * |
51 * |
53 */ |
52 */ |
|
53 /*public*/ void CDelayedOp::StartOp() |
|
54 { |
|
55 iStatus = KRequestPending; |
|
56 SetActive(); |
|
57 TRequestStatus* pStatus = &iStatus; |
|
58 User::RequestComplete( pStatus, KErrNone ); |
|
59 } |
54 /*protected*/ CDelayedOp::CDelayedOp() |
60 /*protected*/ CDelayedOp::CDelayedOp() |
55 : CAsyncOneShot( CActive::EPriorityIdle ) |
61 : CActive( CActive::EPriorityIdle ) |
56 { |
62 { |
|
63 CActiveScheduler::Add( this ); |
57 } |
64 } |
58 |
65 |
59 /** |
66 /** |
60 * |
67 * |
61 */ |
68 */ |
62 /*private virtual*/ void CDelayedOp::RunL() |
69 /*private virtual*/ void CDelayedOp::RunL() |
63 { |
70 { |
64 __LOG_ENTER_SUPPRESS( "Run" ); |
71 __LOG_ENTER_SUPPRESS( "Run" ); |
65 TRAPD( err, ExecuteOpL() ); |
72 TBool again( EFalse ); |
|
73 |
|
74 TRAPD( err, again = ExecuteOpL() ); |
66 |
75 |
67 if ( KErrNone != err ) |
76 if ( KErrNone != err ) |
68 { |
77 { |
69 __LOG_WRITE8_FORMAT1_INFO( |
78 __LOG_WRITE8_FORMAT1_INFO( |
70 "Error while executing delayed operation: %d.", err ); |
79 "Error while executing delayed operation: %d.", err ); |
71 } |
80 } |
72 |
81 |
73 //self-destroy. |
82 if ( again ) |
74 iManager->DequeueOp( *this ); |
83 { |
75 |
84 StartOp(); |
76 //Remove this from iDelayedOpReqs as well. |
85 } |
77 for ( TInt i = 0; i < iPlugin->iDelayedOpReqs.Count(); i++ ) |
86 else |
78 { |
87 { |
79 if ( iPlugin->iDelayedOpReqs[i] == this ) |
88 //self-destroy. |
80 { |
89 iManager->DequeueOp( *this ); |
81 iPlugin->iDelayedOpReqs.Remove( i ); |
90 //<qmail> |
82 break; |
91 //Remove this from iDelayedOpReqs as well. |
83 } |
92 for ( TInt i = 0; i < iPlugin->iDelayedOpReqs.Count(); i++ ) |
84 } |
93 { |
85 delete this; |
94 if ( iPlugin->iDelayedOpReqs[i] == this ) |
|
95 { |
|
96 iPlugin->iDelayedOpReqs.Remove( i ); |
|
97 break; |
|
98 } |
|
99 } |
|
100 //</qmail> |
|
101 delete this; |
|
102 } |
86 } |
103 } |
87 |
104 |
88 /** |
105 /** |
89 * |
106 * |
90 */ |
107 */ |
244 } |
261 } |
245 |
262 |
246 /** |
263 /** |
247 * |
264 * |
248 */ |
265 */ |
249 /*public virtual*/TBool CDelayedDeleteMessagesOp::DeleteMessagesInChunksL( TInt aStartIndex ) |
266 /*private*/ |
250 { |
267 void CDelayedDeleteMessagesOp::ConstructL( |
251 __LOG_ENTER( "DeleteMessagesInChunksL" ); |
268 const RArray<TFSMailMsgId>& aMessages ) |
252 TBool done=EFalse; |
269 { |
253 TInt endIndex; |
270 __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" ); |
254 //<qmail> |
271 |
|
272 TInt count = aMessages.Count(); |
|
273 for ( TInt i = 0; i < count; ++i ) |
|
274 { |
|
275 iMessages.AppendL( aMessages[i].Id() ); |
|
276 } |
|
277 } |
|
278 |
|
279 /** |
|
280 * |
|
281 */ |
|
282 /*private*/ |
|
283 void CDelayedDeleteMessagesOp::ConstructL( |
|
284 TMsgStoreId aMsgId ) |
|
285 { |
|
286 __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" ); |
|
287 iImmediateDelete = ETrue; |
|
288 iMessages.AppendL( aMsgId ); |
|
289 } |
|
290 |
|
291 /** |
|
292 * |
|
293 */ |
|
294 /*private*/ CDelayedDeleteMessagesOp::CDelayedDeleteMessagesOp( |
|
295 TMsgStoreId aMailBoxId, |
|
296 TMsgStoreId aFolderId ) |
|
297 : |
|
298 iMailBoxId( aMailBoxId ), iFolderId( aFolderId ) |
|
299 { |
|
300 } |
|
301 |
|
302 /** |
|
303 * |
|
304 */ |
|
305 /*private*/ TBool CDelayedDeleteMessagesOp::ExecuteOpL() |
|
306 { |
|
307 __LOG_ENTER( "ExecuteOpL" ); |
|
308 |
|
309 //Maximum number of messages deleted in one go |
|
310 const TInt KNumOfDeletesBeforeYield = 30; |
|
311 |
|
312 //<qmail> |
255 TInt result(KErrNone); |
313 TInt result(KErrNone); |
256 if( aStartIndex + KSizeOfChunk < iMessages.Count() ) |
314 |
257 { |
315 TBool runAgain = ETrue; |
258 endIndex = aStartIndex + KSizeOfChunk; |
316 TInt endIndex = iIndex + KNumOfDeletesBeforeYield; |
259 } |
317 |
260 else |
318 if (endIndex >= iMessages.Count()) |
261 { |
319 { |
262 endIndex = iMessages.Count(); |
320 endIndex = iMessages.Count(); |
263 done=ETrue; |
321 runAgain = EFalse; // last time, no need to run again. |
264 } |
322 } |
265 CMailboxInfo& mailBoxInfo |
323 |
266 = GetPlugin().GetMailboxInfoL( iMailBoxId ); |
324 CMailboxInfo& mailBoxInfo = GetPlugin().GetMailboxInfoL(iMailBoxId); |
267 CMsgStoreMailBox& mailBox = mailBoxInfo(); |
325 CMsgStoreMailBox& mailBox = mailBoxInfo(); |
268 |
326 |
269 for ( TInt i = aStartIndex; i < endIndex; ++i ) |
327 for (; iIndex < endIndex; iIndex++) |
270 { |
328 { |
271 TMsgStoreId msgId = iMessages[i]; |
329 TMsgStoreId msgId = iMessages[iIndex]; |
272 |
330 |
273 if ( EFalse == iImmediateDelete ) |
331 if (EFalse == iImmediateDelete) |
274 { |
332 { |
275 //try to find the message |
333 //try to find the message |
276 CMsgStoreMessage* theMessage = NULL; |
334 CMsgStoreMessage* theMessage = NULL; |
277 theMessage = mailBox.FetchMessageL( |
335 theMessage = mailBox.FetchMessageL(msgId, KMsgStoreInvalidId); |
278 msgId, KMsgStoreInvalidId ) ; |
|
279 //save parentId |
336 //save parentId |
280 TMsgStoreId msgParentId; |
337 TMsgStoreId msgParentId; |
281 msgParentId =theMessage->ParentId(); |
338 msgParentId = theMessage->ParentId(); |
282 //check if message is in deleted folder or not. |
339 //check if message is in deleted folder or not. |
283 if ( msgParentId != mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ) |
340 if (msgParentId != mailBoxInfo.iRootFolders.iFolders[EFSDeleted]) |
284 { |
341 { |
285 //if not in deleted items then move it there. |
342 //if not in deleted items then move it there. |
286 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId ); |
343 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId ); |
287 TRAP(result,mailBox.MoveMessageL( |
344 TRAP(result,mailBox.MoveMessageL( |
288 msgId, KMsgStoreInvalidId, |
345 msgId, KMsgStoreInvalidId, |
289 mailBoxInfo.iRootFolders.iFolders[EFSDeleted] )); |
346 mailBoxInfo.iRootFolders.iFolders[EFSDeleted] )); |
290 if(result == KErrNone) |
347 if (result == KErrNone) |
291 { |
348 { |
292 GetPlugin().NotifyEventL( iMailBoxId, msgId, KMsgStoreInvalidId , TFSEventMailMoved, msgParentId); |
349 GetPlugin().NotifyEventL(iMailBoxId, msgId, |
|
350 KMsgStoreInvalidId, TFSEventMailMoved, |
|
351 msgParentId); |
293 } |
352 } |
294 else |
353 else |
295 { |
354 { |
296 User::Leave(result); |
355 User::Leave(result); |
297 } |
356 } |
298 |
357 |
299 } |
358 } |
300 else |
359 else |
301 { |
360 { |
302 //in deleted items, really delete it. |
361 //in deleted items, really delete it. |
303 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId ); |
362 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId ); |
304 |
363 |
305 delete theMessage; |
364 delete theMessage; |
306 TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId )); |
365 TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId )); |
307 if(result == KErrNone) |
366 if (result == KErrNone) |
308 { |
367 { |
309 GetPlugin().NotifyEventL( iMailBoxId, msgId, KMsgStoreInvalidId, TFSEventMailDeleted, iFolderId ); |
368 GetPlugin().NotifyEventL(iMailBoxId, msgId, |
|
369 KMsgStoreInvalidId, TFSEventMailDeleted, |
|
370 iFolderId); |
310 } |
371 } |
311 else |
372 else |
312 { |
373 { |
313 User::Leave(result); |
374 User::Leave(result); |
314 } |
375 } |
315 } |
376 } |
316 } |
377 } |
317 else |
378 else |
318 { |
379 { |
319 TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId )); |
380 TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId )); |
320 if(result == KErrNone) |
381 if (result == KErrNone) |
321 { |
382 { |
322 GetPlugin().NotifyEventL( iMailBoxId, msgId, KMsgStoreInvalidId, TFSEventMailDeleted, iFolderId ); |
383 GetPlugin().NotifyEventL(iMailBoxId, msgId, |
|
384 KMsgStoreInvalidId, TFSEventMailDeleted, iFolderId); |
323 } |
385 } |
324 else |
386 else |
325 { |
387 { |
326 User::Leave(result); |
388 User::Leave(result); |
327 } |
389 } |
328 } |
390 } |
329 //</qmail> |
391 //</qmail> |
330 } |
392 } |
331 __LOG_EXIT; |
393 __LOG_EXIT; |
332 return done; |
394 return runAgain; |
333 } |
|
334 /** |
|
335 * |
|
336 */ |
|
337 /*private*/ |
|
338 void CDelayedDeleteMessagesOp::ConstructL( |
|
339 const RArray<TFSMailMsgId>& aMessages ) |
|
340 { |
|
341 __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" ); |
|
342 |
|
343 TInt count = aMessages.Count(); |
|
344 for ( TInt i = 0; i < count; ++i ) |
|
345 { |
|
346 iMessages.AppendL( aMessages[i].Id() ); |
|
347 } |
|
348 } |
|
349 |
|
350 /** |
|
351 * |
|
352 */ |
|
353 /*private*/ |
|
354 void CDelayedDeleteMessagesOp::ConstructL( |
|
355 TMsgStoreId aMsgId ) |
|
356 { |
|
357 __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" ); |
|
358 iImmediateDelete = ETrue; |
|
359 iMessages.AppendL( aMsgId ); |
|
360 } |
|
361 |
|
362 /** |
|
363 * |
|
364 */ |
|
365 /*private*/ CDelayedDeleteMessagesOp::CDelayedDeleteMessagesOp( |
|
366 TMsgStoreId aMailBoxId, |
|
367 TMsgStoreId aFolderId ) |
|
368 : |
|
369 iMailBoxId( aMailBoxId ), iFolderId( aFolderId ), |
|
370 iImmediateDelete( EFalse ), iState ( EFree ) |
|
371 { |
|
372 } |
|
373 |
|
374 /** |
|
375 * |
|
376 */ |
|
377 /*private*/ void CDelayedDeleteMessagesOp::ExecuteOpL() |
|
378 { |
|
379 __LOG_ENTER( "ExecuteOpL" ); |
|
380 if ( iState != EFree ) |
|
381 { |
|
382 //this code becomes re-entrant now because we use nested AS. |
|
383 // so if we are already authenticating, return right away. |
|
384 return; |
|
385 } |
|
386 iState=EInProgress; |
|
387 CNestedAO* nestedAO = CNestedAO::NewL( *this ); |
|
388 //this is a blocking call with nested active scheduler |
|
389 //This method makes a callback periodically to DeleteMessagesInChunks |
|
390 //to delete the messages one chunk at a time |
|
391 nestedAO->DeleteMessagesAsync(); |
|
392 //continue execution here |
|
393 delete nestedAO; |
|
394 iState = EFree; |
|
395 __LOG_EXIT; |
|
396 } |
395 } |
397 |
396 |
398 |
397 |
399 /////////////////////////////////////////////////// |
398 /////////////////////////////////////////////////// |
400 // CDelayedStorePropertiesOp // |
399 // CDelayedStorePropertiesOp // |