|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This file implements class CIpsPlgImap4Plugin. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include "ipsplgheaders.h" |
|
22 |
|
23 const TInt KConnectOpPriority = CActive::EPriorityStandard; |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // CIpsPlgImap4Plugin::CIpsPlgImap4Plugin() |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 CIpsPlgImap4Plugin::CIpsPlgImap4Plugin() |
|
30 : CIpsPlgSosBasePlugin( KIpsPlgImap4PluginUidValue ) |
|
31 { |
|
32 FUNC_LOG; |
|
33 // none |
|
34 } |
|
35 |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CIpsPlgImap4Plugin::ConstructL() |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 void CIpsPlgImap4Plugin::ConstructL() |
|
42 { |
|
43 FUNC_LOG; |
|
44 BaseConstructL(); |
|
45 } |
|
46 |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CIpsPlgImap4Plugin::NewL() |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 EXPORT_C CIpsPlgImap4Plugin* CIpsPlgImap4Plugin::NewL() |
|
53 { |
|
54 FUNC_LOG; |
|
55 CIpsPlgImap4Plugin* self = CIpsPlgImap4Plugin::NewLC(); |
|
56 CleanupStack::Pop( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CIpsPlgImap4Plugin::NewLC() |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CIpsPlgImap4Plugin* CIpsPlgImap4Plugin::NewLC() |
|
66 { |
|
67 FUNC_LOG; |
|
68 CIpsPlgImap4Plugin* self = new( ELeave ) CIpsPlgImap4Plugin; |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CIpsPlgImap4Plugin::~CIpsPlgImap4Plugin() |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 CIpsPlgImap4Plugin::~CIpsPlgImap4Plugin() |
|
80 { |
|
81 FUNC_LOG; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CIpsPlgImap4Plugin::MailboxHasCapabilityL |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 TBool CIpsPlgImap4Plugin::MailboxHasCapabilityL( |
|
89 TFSMailBoxCapabilities aCapability, |
|
90 TFSMailMsgId /* aMailBoxId */ ) |
|
91 { |
|
92 FUNC_LOG; |
|
93 TBool result( EFalse ); |
|
94 |
|
95 switch ( aCapability ) |
|
96 { |
|
97 // These should be clear |
|
98 case EFSMBoxCapaCanBeDeleted: |
|
99 case EFSMBoxCapaSupportsSaveToDrafts: |
|
100 case EFSMBoxCapaMeetingRequestRespond: |
|
101 case EFSMboxCapaSupportsAttahmentsInMR: |
|
102 case EFSMBoxCapaMeetingRequestCreate: |
|
103 case EFSMBoxCapaCanUpdateMeetingRequest: |
|
104 case EFSMBoxCapaMoveToFolder: |
|
105 case EFSMBoxCapaCopyToFolder: |
|
106 case EFSMBoxCapaSupportsSync: |
|
107 case EFSMBoxCapaRemoveFromCalendar: |
|
108 case EFSMBoxCapaMoveMessageNoConnectNeeded: |
|
109 { |
|
110 result = ETrue; |
|
111 break; |
|
112 } |
|
113 // These are positively not supported |
|
114 case EFSMBoxCapaCreateSubfolder: |
|
115 case EFSMBoxCapaManipulateUserFolders: |
|
116 case EFSMBoxCapaMoveMessageToUserFolder: |
|
117 case EFSMBoxCapaSmartReply: |
|
118 case EFSMBoxCapaSmartForward: |
|
119 case EFSMBoxCapaSupportsMRU: |
|
120 case EFSMBoxCapaSymbianMsgIntegration: |
|
121 case EFSMBoxCapaNewEmailNotifications: |
|
122 default: |
|
123 { |
|
124 result = EFalse; |
|
125 break; |
|
126 } |
|
127 } |
|
128 |
|
129 return result; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CIpsPlgImap4Plugin::RefreshNowL( ) |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 TInt CIpsPlgImap4Plugin::RefreshNowL( ) |
|
137 { |
|
138 FUNC_LOG; |
|
139 return KErrNone; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CIpsPlgImap4Plugin::RefreshNowL() |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CIpsPlgImap4Plugin::RefreshNowL( |
|
147 const TFSMailMsgId& aMailBoxId, |
|
148 MFSMailRequestObserver& aOperationObserver, |
|
149 TInt aRequestId ) |
|
150 { |
|
151 FUNC_LOG; |
|
152 |
|
153 TMsvId service = aMailBoxId.Id(); |
|
154 |
|
155 CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL( *this ); |
|
156 CleanupStack::PushL( watcher ); |
|
157 |
|
158 CIpsPlgBaseOperation* op = CIpsPlgImap4ConnectOp::NewL( |
|
159 *iSession, |
|
160 KConnectOpPriority, |
|
161 watcher->iStatus, |
|
162 service, |
|
163 ActivityTimerL( aMailBoxId ), |
|
164 aMailBoxId, |
|
165 aOperationObserver, |
|
166 aRequestId, |
|
167 iEventHandler ); |
|
168 |
|
169 watcher->SetOperation( op ); |
|
170 iOperations.AppendL( watcher ); |
|
171 CleanupStack::Pop( watcher ); |
|
172 |
|
173 // send part of refresh |
|
174 EmptyOutboxL( aMailBoxId ); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CIpsPlgImap4Plugin::ListFoldersL() |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CIpsPlgImap4Plugin::ListFoldersL( |
|
182 const TFSMailMsgId& aMailBoxId, |
|
183 const TFSMailMsgId& aFolderId, |
|
184 RPointerArray<CFSMailFolder>& aFolderList) |
|
185 { |
|
186 FUNC_LOG; |
|
187 DoListFoldersL( aMailBoxId, aFolderId, aFolderList, ETrue ); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CIpsPlgImap4Plugin::ListFoldersL() |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void CIpsPlgImap4Plugin::ListFoldersL( |
|
195 const TFSMailMsgId& aMailBoxId, |
|
196 RPointerArray<CFSMailFolder>& aFolderList) |
|
197 { |
|
198 FUNC_LOG; |
|
199 DoListFoldersL( aMailBoxId, TFSMailMsgId(), aFolderList, EFalse ); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CIpsPlgImap4Plugin::GetStandardFolderIdL() |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 TFSMailMsgId CIpsPlgImap4Plugin::GetStandardFolderIdL( |
|
207 const TFSMailMsgId& aMailBoxId, |
|
208 const TFSFolderType aFolderType ) |
|
209 { |
|
210 FUNC_LOG; |
|
211 TFSMailMsgId ret; |
|
212 |
|
213 if( aFolderType == EFSInbox ) |
|
214 { |
|
215 CMsvEntry* cEntry = iSession->GetEntryL( aMailBoxId.Id() ); |
|
216 CleanupStack::PushL( cEntry ); |
|
217 |
|
218 TInt i( 0 ); |
|
219 TInt count( cEntry->Count() ); |
|
220 while ( i < count && ret.IsNullId() ) |
|
221 { |
|
222 if ( (*cEntry)[i].iType == KUidMsvFolderEntry && |
|
223 (*cEntry)[i].iDetails.CompareF( KIpsPlgInbox ) == 0 ) |
|
224 { |
|
225 ret.SetId( (*cEntry)[i].Id() ); |
|
226 } |
|
227 i++; |
|
228 } |
|
229 CleanupStack::PopAndDestroy( cEntry ); |
|
230 } |
|
231 else if( aFolderType == EFSOutbox ) |
|
232 { |
|
233 ret.SetId( KMsvGlobalOutBoxIndexEntryId ); |
|
234 } |
|
235 else if( aFolderType == EFSDraftsFolder ) |
|
236 { |
|
237 ret.SetId( KMsvDraftEntryId ); |
|
238 } |
|
239 else if( aFolderType == EFSSentFolder ) |
|
240 { |
|
241 ret.SetId( KMsvSentEntryId ); |
|
242 } |
|
243 else if( aFolderType == EFSDeleted ) |
|
244 { |
|
245 ret.SetId( KMsvDeletedEntryFolderEntryId ); |
|
246 } |
|
247 else if( aFolderType == EFSOther ) |
|
248 { |
|
249 ret.SetId( KMsvUnknownServiceIndexEntryId ); |
|
250 } |
|
251 if ( !ret.IsNullId() ) |
|
252 { |
|
253 ret.SetPluginId( KIpsPlgImap4PluginUid ); |
|
254 } |
|
255 |
|
256 return ret; |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CIpsPlgImap4Plugin::FetchMessagesL() |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void CIpsPlgImap4Plugin::FetchMessagesL( |
|
264 const TFSMailMsgId& aMailBoxId, |
|
265 const TFSMailMsgId& aFolderId, |
|
266 const RArray<TFSMailMsgId>& aMessageIds, |
|
267 TFSMailDetails /*aDetails*/, |
|
268 MFSMailRequestObserver& aObserver, |
|
269 TInt aRequestId) |
|
270 { |
|
271 FUNC_LOG; |
|
272 |
|
273 CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this); |
|
274 CleanupStack::PushL( watcher ); |
|
275 |
|
276 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
277 CleanupStack::PushL(sel); |
|
278 sel->AppendL( aMailBoxId.Id() ); |
|
279 |
|
280 TInt count = aMessageIds.Count(); |
|
281 |
|
282 if ( count == 0 ) |
|
283 { |
|
284 User::Leave( KErrArgument ); |
|
285 } |
|
286 for ( TInt i(0); i < count; i++ ) |
|
287 { |
|
288 sel->AppendL( aMessageIds[i].Id() ); |
|
289 } |
|
290 |
|
291 |
|
292 // fetch body texts only (text/plain, text/html) |
|
293 TImImap4GetPartialMailInfo info; |
|
294 info.iMaxEmailSize = KMaxTInt32; |
|
295 info.iGetMailBodyParts = EGetImap4EmailBodyText; |
|
296 info.iPartialMailOptions = EBodyTextOnly; |
|
297 info.iTotalSizeLimit = KMaxTInt32; |
|
298 info.iBodyTextSizeLimit = KMaxTInt32; |
|
299 info.iAttachmentSizeLimit = 0; |
|
300 info.iDestinationFolder = aFolderId.Id(); |
|
301 |
|
302 CIpsPlgBaseOperation* op = CIpsPlgImap4PopulateOp::NewL( |
|
303 *iSession, |
|
304 watcher->iStatus, |
|
305 CActive::EPriorityStandard, |
|
306 aMailBoxId.Id(), |
|
307 ActivityTimerL( aMailBoxId ), |
|
308 info, |
|
309 *sel, |
|
310 aMailBoxId, |
|
311 aObserver, |
|
312 aRequestId, |
|
313 iEventHandler, |
|
314 EFalse ); // do not filter mail selection |
|
315 |
|
316 watcher->SetOperation( op ); |
|
317 CleanupStack::PopAndDestroy( sel ); |
|
318 iOperations.AppendL( watcher ); |
|
319 CleanupStack::Pop( watcher ); |
|
320 |
|
321 } |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // CIpsPlgImap4Plugin::MoveMessagesL( ) |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 void CIpsPlgImap4Plugin::MoveMessagesL( |
|
328 const TFSMailMsgId& aMailBoxId, |
|
329 const RArray<TFSMailMsgId>& aMessageIds, |
|
330 const TFSMailMsgId& aSourceFolderId, |
|
331 const TFSMailMsgId& aDestinationFolderId ) |
|
332 { |
|
333 FUNC_LOG; |
|
334 if( aDestinationFolderId.Id() == KMsvDraftEntryId ) |
|
335 { |
|
336 // Move to Drafts folder |
|
337 MoveMessagesToDraftL( aMailBoxId, |
|
338 aMessageIds, |
|
339 aSourceFolderId, |
|
340 aDestinationFolderId ); |
|
341 } |
|
342 else if( aDestinationFolderId.Id() != aSourceFolderId.Id() ) |
|
343 { |
|
344 TMsvId service = aMailBoxId.Id(); |
|
345 |
|
346 CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this); |
|
347 CleanupStack::PushL( watcher ); |
|
348 |
|
349 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
350 CleanupStack::PushL(sel); |
|
351 sel->AppendL( service ); |
|
352 |
|
353 TInt msgIdCount( aMessageIds.Count() ); |
|
354 for ( TInt i(0); i< msgIdCount; i++ ) |
|
355 { |
|
356 sel->AppendL( aMessageIds[i].Id() ); |
|
357 } |
|
358 |
|
359 TPckgBuf<TImImap4GetMailInfo> optionsBuf; |
|
360 TImImap4GetMailInfo& options = optionsBuf(); |
|
361 options.iMaxEmailSize = KMaxTInt32; |
|
362 options.iGetMailBodyParts = EGetImap4EmailBodyTextAndAttachments; |
|
363 options.iDestinationFolder = aDestinationFolderId.Id(); |
|
364 |
|
365 CIpsPlgImap4MoveRemoteOpObserver* observer = |
|
366 CIpsPlgImap4MoveRemoteOpObserver::NewL( *iSession, *iEventHandler, |
|
367 aSourceFolderId, aMessageIds ); |
|
368 watcher->SetRequestObserver( observer ); |
|
369 |
|
370 // Synchronous operation |
|
371 CIpsPlgBaseOperation* op = CIpsPlgImap4MoveRemoteOp::NewL( |
|
372 *iSession, |
|
373 watcher->iStatus, |
|
374 KIMAP4MTMMoveMailSelectionWhenAlreadyConnected, |
|
375 service, |
|
376 ActivityTimerL( aMailBoxId ), |
|
377 options, |
|
378 *sel, |
|
379 aMailBoxId, |
|
380 *observer, // async not supported |
|
381 0 ); // async not supported |
|
382 |
|
383 watcher->SetOperation( op ); |
|
384 CleanupStack::PopAndDestroy( sel ); |
|
385 iOperations.AppendL( watcher ); |
|
386 CleanupStack::Pop( watcher ); |
|
387 } |
|
388 else |
|
389 { |
|
390 //do nothing |
|
391 } |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // CIpsPlgImap4Plugin::MoveMessagesL() |
|
396 // asynchronic move message function |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 TInt CIpsPlgImap4Plugin::MoveMessagesL( |
|
400 const TFSMailMsgId& aMailBoxId, |
|
401 const RArray<TFSMailMsgId>& aMessageIds, |
|
402 const TFSMailMsgId& aSourceFolderId, |
|
403 const TFSMailMsgId& aDestinationFolderId, |
|
404 MFSMailRequestObserver& aOperationObserver, |
|
405 TInt aRequestId ) |
|
406 { |
|
407 FUNC_LOG; |
|
408 TInt ret = KErrNone; |
|
409 if( aDestinationFolderId.Id() == KMsvDraftEntryId ) |
|
410 { |
|
411 // Move to Drafts folder |
|
412 MoveMessagesToDraftL( aMailBoxId, |
|
413 aMessageIds, |
|
414 aSourceFolderId, |
|
415 aDestinationFolderId ); |
|
416 TFSProgress progress = { |
|
417 TFSProgress::EFSStatus_RequestComplete, 0, 0, ret }; |
|
418 aOperationObserver.RequestResponseL( |
|
419 progress, aRequestId ); |
|
420 } |
|
421 else if( aDestinationFolderId.Id() != aSourceFolderId.Id() ) |
|
422 { |
|
423 TMsvId service = aMailBoxId.Id(); |
|
424 |
|
425 CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this); |
|
426 CleanupStack::PushL( watcher ); |
|
427 |
|
428 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
429 CleanupStack::PushL(sel); |
|
430 sel->AppendL( service ); |
|
431 |
|
432 TInt msgIdCount( aMessageIds.Count() ); |
|
433 for ( TInt i(0); i< msgIdCount; i++ ) |
|
434 { |
|
435 sel->AppendL( aMessageIds[i].Id() ); |
|
436 } |
|
437 |
|
438 TPckgBuf<TImImap4GetMailInfo> optionsBuf; |
|
439 TImImap4GetMailInfo& options = optionsBuf(); |
|
440 options.iMaxEmailSize = KMaxTInt32; |
|
441 options.iGetMailBodyParts = EGetImap4EmailBodyTextAndAttachments; |
|
442 options.iDestinationFolder = aDestinationFolderId.Id(); |
|
443 |
|
444 CIpsPlgBaseOperation* op = CIpsPlgImap4MoveRemoteOp::NewL( |
|
445 *iSession, |
|
446 watcher->iStatus, |
|
447 KIMAP4MTMMoveMailSelectionWhenAlreadyConnected, |
|
448 service, |
|
449 ActivityTimerL( aMailBoxId ), |
|
450 options, |
|
451 *sel, |
|
452 aMailBoxId, |
|
453 aOperationObserver, |
|
454 aRequestId ); |
|
455 |
|
456 watcher->SetOperation( op ); |
|
457 CleanupStack::PopAndDestroy( sel ); |
|
458 iOperations.AppendL( watcher ); |
|
459 CleanupStack::Pop( watcher ); |
|
460 } |
|
461 else |
|
462 { |
|
463 ret = KErrNotSupported; |
|
464 TFSProgress progress = { |
|
465 TFSProgress::EFSStatus_RequestComplete, 0, 0, ret }; |
|
466 aOperationObserver.RequestResponseL( |
|
467 progress, aRequestId ); |
|
468 } |
|
469 return ret; |
|
470 } |
|
471 |
|
472 // --------------------------------------------------------------------------- |
|
473 // CIpsPlgImap4Plugin::FetchMessagePartsL() |
|
474 // --------------------------------------------------------------------------- |
|
475 // |
|
476 void CIpsPlgImap4Plugin::FetchMessagePartsL( |
|
477 const TFSMailMsgId& aMailBoxId, |
|
478 const TFSMailMsgId& aFolderId, |
|
479 const TFSMailMsgId& aMessageId, |
|
480 const RArray<TFSMailMsgId>& aMessagePartIds, |
|
481 MFSMailRequestObserver& aOperationObserver, |
|
482 const TInt aRequestId, |
|
483 const TUint /*aPreferredByteCount*/) |
|
484 { |
|
485 FUNC_LOG; |
|
486 |
|
487 TInt count( aMessagePartIds.Count() ); |
|
488 if ( 0 == count ) |
|
489 { |
|
490 User::Leave( KErrArgument ); |
|
491 } |
|
492 |
|
493 CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL( *this ); |
|
494 CleanupStack::PushL( watcher ); |
|
495 |
|
496 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
497 CleanupStack::PushL( sel ); |
|
498 |
|
499 TMsvEntry tEntry; |
|
500 TMsvId service; |
|
501 |
|
502 for ( TInt i(0); i < count; i++ ) |
|
503 { |
|
504 sel->AppendL( aMessagePartIds[i].Id() ); |
|
505 |
|
506 iSession->GetEntry( aMessagePartIds[i].Id(), service, tEntry ); |
|
507 |
|
508 if ( tEntry.iType.iUid == KUidMsvEmailHtmlEntryValue || |
|
509 tEntry.iType.iUid == KUidMsvEmailExternalBodyEntryValue || |
|
510 tEntry.iType.iUid == KUidMsvEmailRtfEntryValue ) |
|
511 { |
|
512 CleanupStack::PopAndDestroy(2);//sel, watcher |
|
513 |
|
514 //we need to fetch the whole message in these cases, because |
|
515 //symbian components ignore these types of parts currently |
|
516 RArray<TFSMailMsgId> messages(1); |
|
517 messages.Append( aMessageId ); |
|
518 |
|
519 // not used in function |
|
520 TFSMailDetails dymmy = EFSMsgDataStructure; |
|
521 |
|
522 FetchMessagesL( aMailBoxId, |
|
523 aFolderId, |
|
524 messages, |
|
525 dymmy, |
|
526 aOperationObserver, |
|
527 aRequestId ); |
|
528 |
|
529 messages.Close(); |
|
530 |
|
531 return; |
|
532 } |
|
533 |
|
534 } |
|
535 |
|
536 TPckgBuf<TImImap4GetMailInfo> optionsBuf; |
|
537 TImImap4GetMailInfo& options = optionsBuf(); |
|
538 options.iMaxEmailSize = KMaxTInt32; |
|
539 options.iGetMailBodyParts = EGetImap4EmailAttachments; |
|
540 options.iDestinationFolder = 0; // not used |
|
541 |
|
542 CIpsPlgBaseOperation* op = CIpsPlgImap4FetchAttachmentOp::NewL( |
|
543 *iSession, watcher->iStatus, KIMAP4MTMPopulate, aMailBoxId.Id(), |
|
544 ActivityTimerL( aMailBoxId ), options, *sel, aMailBoxId, |
|
545 aOperationObserver, aRequestId ); |
|
546 |
|
547 watcher->SetOperation( op ); |
|
548 CleanupStack::PopAndDestroy( sel ); |
|
549 iOperations.AppendL( watcher ); |
|
550 CleanupStack::Pop( watcher ); |
|
551 } |
|
552 |
|
553 // ---------------------------------------------------------------------------- |
|
554 // CIpsPlgImap4Plugin::PopulateNewMailL( ) |
|
555 // ---------------------------------------------------------------------------- |
|
556 // |
|
557 void CIpsPlgImap4Plugin::PopulateNewMailL( |
|
558 const TFSMailMsgId& aMailboxId, TMsvId aNewId, TMsvId /*aParentId*/ ) |
|
559 { |
|
560 FUNC_LOG; |
|
561 if ( aMailboxId.PluginId().iUid != PluginId() ) |
|
562 { |
|
563 return; |
|
564 } |
|
565 else if ( iSyncStateHandler->GetMailboxIpsState( aMailboxId.Id() ) |
|
566 == KIpsSosEmailSyncStarted ) |
|
567 { |
|
568 return; |
|
569 } |
|
570 |
|
571 |
|
572 TMsvEntry tEntry; |
|
573 TMsvId serv; |
|
574 iSession->GetEntry( aMailboxId.Id(), serv, tEntry ); |
|
575 if ( !tEntry.Connected() ) |
|
576 { |
|
577 return; |
|
578 } |
|
579 |
|
580 CImImap4Settings* settings = new ( ELeave ) CImImap4Settings(); |
|
581 CleanupStack::PushL( settings ); |
|
582 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
583 TImapAccount imapAcc; |
|
584 accounts->GetImapAccountL( aMailboxId.Id(), imapAcc ); |
|
585 accounts->LoadImapSettingsL( imapAcc, *settings ); |
|
586 TImImap4GetPartialMailInfo info; |
|
587 CIpsSetDataApi::ConstructImapPartialFetchInfo( info, *settings ); |
|
588 CleanupStack::PopAndDestroy( 2, settings ); |
|
589 |
|
590 if ( info.iTotalSizeLimit == KIpsSetDataHeadersOnly ) |
|
591 { |
|
592 return; |
|
593 } |
|
594 |
|
595 TPckgBuf<TImImap4GetPartialMailInfo> package(info); |
|
596 |
|
597 CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this); |
|
598 CleanupStack::PushL( watcher ); |
|
599 |
|
600 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
601 CleanupStack::PushL(sel); |
|
602 sel->AppendL( aMailboxId.Id() ); |
|
603 sel->AppendL( aNewId ); |
|
604 |
|
605 CIpsPlgBaseOperation* op = CIpsPlgImap4PopulateOp::NewL( |
|
606 *iSession, |
|
607 watcher->iStatus, |
|
608 KIMAP4MTMPopulateMailSelectionWhenAlreadyConnected, |
|
609 aMailboxId.Id(), |
|
610 ActivityTimerL( aMailboxId ), |
|
611 info, |
|
612 *sel, |
|
613 aMailboxId, |
|
614 *this, |
|
615 KErrNotFound, |
|
616 iEventHandler, |
|
617 EFalse ); // do not block entry changed and created events |
|
618 |
|
619 watcher->SetOperation( op ); |
|
620 CleanupStack::PopAndDestroy( sel ); |
|
621 iOperations.AppendL( watcher ); |
|
622 CleanupStack::Pop( watcher ); |
|
623 |
|
624 iEventHandler->SetNewPropertyEvent( |
|
625 aMailboxId.Id(), KIpsSosEmailSyncStarted, KErrNone ); |
|
626 |
|
627 } |
|
628 |
|
629 |
|
630 // --------------------------------------------------------------------------- |
|
631 // CIpsPlgImap4Plugin::HandleOpCompletedL() |
|
632 // --------------------------------------------------------------------------- |
|
633 // |
|
634 void CIpsPlgImap4Plugin::HandleOpCompletedL( |
|
635 CIpsPlgSingleOpWatcher& /*aOpWatcher*/, |
|
636 TInt /*aCompletionCode*/ ) |
|
637 { |
|
638 FUNC_LOG; |
|
639 |
|
640 } |
|
641 |
|
642 // --------------------------------------------------------------------------- |
|
643 // CIpsPlgImap4Plugin::DoListFoldersL( ) |
|
644 // --------------------------------------------------------------------------- |
|
645 // |
|
646 void CIpsPlgImap4Plugin::DoListFoldersL( |
|
647 TFSMailMsgId aMailBoxId, |
|
648 TFSMailMsgId aFolderId, |
|
649 RPointerArray<CFSMailFolder>& aFolderList, |
|
650 TBool aOnlyDirect ) |
|
651 |
|
652 { |
|
653 FUNC_LOG; |
|
654 CFSMailFolder* folder( NULL ); |
|
655 CMsvEntrySelection* folders = new (ELeave) CMsvEntrySelection; |
|
656 CleanupStack::PushL( folders ); |
|
657 |
|
658 if( aFolderId.IsNullId() ) |
|
659 { |
|
660 folder = GetFolderByUidL( aMailBoxId, |
|
661 GetStandardFolderIdL( |
|
662 aMailBoxId, EFSOutbox ) ); |
|
663 if( folder ) |
|
664 { |
|
665 CleanupStack::PushL( folder ); |
|
666 aFolderList.Append( folder ); |
|
667 CleanupStack::Pop( folder ); |
|
668 } |
|
669 |
|
670 folder = GetFolderByUidL( aMailBoxId, |
|
671 GetStandardFolderIdL( |
|
672 aMailBoxId, EFSDraftsFolder ) ); |
|
673 if( folder ) |
|
674 { |
|
675 CleanupStack::PushL( folder ); |
|
676 aFolderList.Append( folder ); |
|
677 CleanupStack::Pop( folder ); |
|
678 } |
|
679 |
|
680 folder = GetFolderByUidL( aMailBoxId, |
|
681 GetStandardFolderIdL( |
|
682 aMailBoxId, EFSSentFolder ) ); |
|
683 if( folder ) |
|
684 { |
|
685 CleanupStack::PushL( folder ); |
|
686 aFolderList.Append( folder ); |
|
687 CleanupStack::Pop( folder ); |
|
688 } |
|
689 |
|
690 // List root level (aOnlyDirect==ETrue) or all subfolders of |
|
691 // given mailbox (aOnlyDirect==EFalse) |
|
692 HandleFoldersL( aMailBoxId, *folders, aOnlyDirect ); |
|
693 } |
|
694 else |
|
695 { |
|
696 // Folder id defined, list direct subfolders of given |
|
697 // folder |
|
698 HandleFoldersL( aFolderId, *folders, aOnlyDirect ); |
|
699 } |
|
700 TInt folderCount( folders->Count() ); |
|
701 for( TInt i(0); i < folderCount; i++ ) |
|
702 { |
|
703 aFolderId.SetId( (*folders).At(i) ); |
|
704 aFolderId.SetPluginId( KIpsPlgImap4PluginUid ); |
|
705 |
|
706 folder = GetFolderByUidL( aMailBoxId, aFolderId ); |
|
707 |
|
708 CleanupStack::PushL( folder ); |
|
709 aFolderList.AppendL( folder ); |
|
710 CleanupStack::Pop( folder ); |
|
711 } |
|
712 CleanupStack::PopAndDestroy( folders ); |
|
713 } |
|
714 |
|
715 // --------------------------------------------------------------------------- |
|
716 // CIpsPlgImap4Plugin::HandleFoldersL( ) |
|
717 // --------------------------------------------------------------------------- |
|
718 // |
|
719 void CIpsPlgImap4Plugin::HandleFoldersL( |
|
720 TFSMailMsgId aId, |
|
721 CMsvEntrySelection& aFolders, |
|
722 TBool aOnlyDirect ) |
|
723 { |
|
724 FUNC_LOG; |
|
725 if( HasChildFoldersL( aId.Id() ) ) |
|
726 { |
|
727 // GetChildrenL is recursive, so we set CMsvEntry once and pass it |
|
728 // forward instead of creating it several times before the first one |
|
729 // is deleted. |
|
730 CMsvEntry* cEntry = iSession->GetEntryL( aId.Id() ); |
|
731 CleanupStack::PushL( cEntry ); |
|
732 CMsvEntrySelection* folderEntries = |
|
733 GetChildrenL( aId.Id(), *cEntry, aOnlyDirect ); |
|
734 CleanupStack::PopAndDestroy( cEntry ); |
|
735 CleanupStack::PushL( folderEntries ); |
|
736 |
|
737 TInt count = folderEntries->Count(); |
|
738 for( TInt i(0); i < count; i++ ) |
|
739 { |
|
740 aFolders.AppendL( folderEntries->At(i) ); |
|
741 } |
|
742 |
|
743 CleanupStack::PopAndDestroy( folderEntries ); |
|
744 } |
|
745 else |
|
746 { |
|
747 // Do nothing, only subfolders of given folder will be added to array |
|
748 } |
|
749 } |
|
750 |
|
751 // --------------------------------------------------------------------------- |
|
752 // CIpsPlgImap4Plugin::GetChildrenL( ) |
|
753 // --------------------------------------------------------------------------- |
|
754 // |
|
755 CMsvEntrySelection* CIpsPlgImap4Plugin::GetChildrenL( |
|
756 TMsvId aId, |
|
757 CMsvEntry& aEntry, |
|
758 TBool aOnlyDirect ) const |
|
759 { |
|
760 FUNC_LOG; |
|
761 aEntry.SetEntryL( aId ); |
|
762 CMsvEntrySelection* children = |
|
763 aEntry.ChildrenWithTypeL( KUidMsvFolderEntry ); |
|
764 CleanupStack::PushL( children ); |
|
765 |
|
766 if( !aOnlyDirect ) |
|
767 { |
|
768 TInt count = children->Count(); |
|
769 for( TInt i = 0; i < count; i++ ) |
|
770 { |
|
771 if( HasChildFoldersL( children->At(i) ) ) |
|
772 { |
|
773 // Recursive |
|
774 CMsvEntrySelection* grandChildren = |
|
775 GetChildrenL( children->At(i), aEntry, aOnlyDirect ); |
|
776 CleanupStack::PushL( grandChildren ); |
|
777 |
|
778 TInt count = grandChildren->Count(); |
|
779 for( TInt k(0); k < count; k++ ) |
|
780 { |
|
781 children->AppendL( grandChildren->At(k) ); |
|
782 } |
|
783 CleanupStack::PopAndDestroy( grandChildren ); |
|
784 } |
|
785 } |
|
786 } |
|
787 CleanupStack::Pop( children ); |
|
788 return children; |
|
789 } |
|
790 |
|
791 // --------------------------------------------------------------------------- |
|
792 // CIpsPlgImap4Plugin::HasChildFoldersL( ) |
|
793 // --------------------------------------------------------------------------- |
|
794 // |
|
795 TBool CIpsPlgImap4Plugin::HasChildFoldersL( TMsvId aId ) const |
|
796 { |
|
797 FUNC_LOG; |
|
798 CMsvEntry* cEntry = iSession->GetEntryL( aId ); |
|
799 CleanupStack::PushL( cEntry ); |
|
800 TInt index = cEntry->Count()-1; |
|
801 while ( index >= 0 && (*cEntry)[index].iType != KUidMsvFolderEntry ) |
|
802 { |
|
803 index--; |
|
804 } |
|
805 CleanupStack::PopAndDestroy( cEntry ); |
|
806 |
|
807 return ( index != -1 ); |
|
808 } |
|
809 |
|
810 // End of File |
|
811 |