|
1 /* |
|
2 * Copyright (c) 2007-2008 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: common mailbox object |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <nmcommonheaders.h> |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include "CFSMailPlugin.h" |
|
22 #include "CFSMailBox.h" |
|
23 #include "CFSMailRequestObserver.h" |
|
24 // <qmail> |
|
25 #include "CFSMailFolder.h" |
|
26 #include "CFSMailAddress.h" |
|
27 // </qmail> |
|
28 |
|
29 const TInt KMaxMruEntries( 150 ); |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ========================================== |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CFSMailBox::NewLC |
|
34 // ----------------------------------------------------------------------------- |
|
35 EXPORT_C CFSMailBox* CFSMailBox::NewLC( TFSMailMsgId aMailBoxId ) |
|
36 { |
|
37 FUNC_LOG; |
|
38 CFSMailBox* api = new (ELeave) CFSMailBox(); |
|
39 CleanupStack:: PushL(api); |
|
40 api->ConstructL(aMailBoxId); |
|
41 return api; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CFSMailBox::NewL |
|
46 // ----------------------------------------------------------------------------- |
|
47 EXPORT_C CFSMailBox* CFSMailBox::NewL( TFSMailMsgId aMailBoxId ) |
|
48 { |
|
49 FUNC_LOG; |
|
50 CFSMailBox* api = CFSMailBox::NewLC(aMailBoxId); |
|
51 CleanupStack:: Pop(api); |
|
52 return api; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CFSMailBox::CFSMailBox |
|
57 // ----------------------------------------------------------------------------- |
|
58 CFSMailBox::CFSMailBox() |
|
59 { |
|
60 FUNC_LOG; |
|
61 // get requesthandler pointer |
|
62 iRequestHandler = static_cast<CFSMailRequestHandler*>(Dll::Tls()); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CFSMailBox::~CFSMailBox |
|
67 // ----------------------------------------------------------------------------- |
|
68 EXPORT_C CFSMailBox::~CFSMailBox() |
|
69 { |
|
70 FUNC_LOG; |
|
71 iFolders.ResetAndDestroy(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CFSMailBox::ConstructL |
|
76 // ----------------------------------------------------------------------------- |
|
77 void CFSMailBox::ConstructL( TFSMailMsgId aMailBoxId ) |
|
78 { |
|
79 FUNC_LOG; |
|
80 CFSMailBoxBase::ConstructL(aMailBoxId); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CFSMailBox::GoOnlineL |
|
85 // ----------------------------------------------------------------------------- |
|
86 EXPORT_C void CFSMailBox::GoOnlineL() |
|
87 { |
|
88 FUNC_LOG; |
|
89 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
90 { |
|
91 plugin->GoOnlineL( GetId() ); |
|
92 } |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CFSMailBox::GoOfflineL |
|
97 // ----------------------------------------------------------------------------- |
|
98 EXPORT_C void CFSMailBox::GoOfflineL() |
|
99 { |
|
100 FUNC_LOG; |
|
101 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
102 { |
|
103 plugin->GoOfflineL( GetId() ); |
|
104 } |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CFSMailBox::CancelSyncL |
|
109 // ----------------------------------------------------------------------------- |
|
110 EXPORT_C void CFSMailBox::CancelSyncL() |
|
111 { |
|
112 FUNC_LOG; |
|
113 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
114 { |
|
115 plugin->CancelSyncL( GetId() ); |
|
116 } |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CFSMailBox::GetLastSyncStatusL |
|
121 // ----------------------------------------------------------------------------- |
|
122 EXPORT_C TFSProgress CFSMailBox::GetLastSyncStatusL() |
|
123 { |
|
124 FUNC_LOG; |
|
125 TFSProgress progress; |
|
126 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
127 { |
|
128 progress = plugin->GetLastSyncStatusL( GetId() ); |
|
129 } |
|
130 return progress; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CFSMailBox::RefreshNowL |
|
135 // ----------------------------------------------------------------------------- |
|
136 EXPORT_C TInt CFSMailBox::RefreshNowL( |
|
137 MFSMailRequestObserver& aOperationObserver ) |
|
138 { |
|
139 FUNC_LOG; |
|
140 |
|
141 TFSPendingRequest request; |
|
142 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
143 { |
|
144 // init asynchronous request |
|
145 request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(), |
|
146 aOperationObserver ); |
|
147 MFSMailRequestObserver* observer = request.iObserver; |
|
148 TRAPD(err,plugin->RefreshNowL( GetId(), *observer, request.iRequestId)); |
|
149 if(err != KErrNone) |
|
150 { |
|
151 iRequestHandler->CompleteRequest(request.iRequestId); |
|
152 User::Leave(err); |
|
153 } |
|
154 } |
|
155 return request.iRequestId; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CFSMailBox::RefreshNowL |
|
160 // ----------------------------------------------------------------------------- |
|
161 EXPORT_C TInt CFSMailBox::RefreshNowL() |
|
162 { |
|
163 FUNC_LOG; |
|
164 |
|
165 TFSPendingRequest request; |
|
166 MFSMailRequestObserver* observer = NULL; |
|
167 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
168 { |
|
169 // init asynchronous request |
|
170 request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(), *observer ); |
|
171 |
|
172 observer = request.iObserver; |
|
173 TRAPD(err,plugin->RefreshNowL( GetId(), *observer, request.iRequestId)); |
|
174 if(err != KErrNone) |
|
175 { |
|
176 iRequestHandler->CompleteRequest(request.iRequestId); |
|
177 User::Leave(err); |
|
178 } |
|
179 } |
|
180 return request.iRequestId; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CFSMailBox::CreateMessageToSend |
|
185 // ----------------------------------------------------------------------------- |
|
186 EXPORT_C CFSMailMessage* CFSMailBox::CreateMessageToSend() |
|
187 { |
|
188 FUNC_LOG; |
|
189 |
|
190 CFSMailMessage* message = NULL; |
|
191 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
192 { |
|
193 TRAPD(err,message = plugin->CreateMessageToSendL( GetId() )); |
|
194 if(err != KErrNone) |
|
195 { |
|
196 message = NULL; |
|
197 } |
|
198 } |
|
199 return message; |
|
200 } |
|
201 |
|
202 // <qmail> |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CFSMailBox::CreateMessageToSendL |
|
205 // ----------------------------------------------------------------------------- |
|
206 EXPORT_C TInt CFSMailBox::CreateMessageToSendL( |
|
207 MFSMailRequestObserver& aOperationObserver ) |
|
208 { |
|
209 TFSPendingRequest request; |
|
210 |
|
211 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ); |
|
212 |
|
213 if ( plugin ) |
|
214 { |
|
215 // init asynchronous request |
|
216 request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(), |
|
217 aOperationObserver ); |
|
218 |
|
219 MFSMailRequestObserver* observer = request.iObserver; |
|
220 |
|
221 TRAPD( err, plugin->CreateMessageToSendL( |
|
222 GetId(), *observer, request.iRequestId ) ); |
|
223 |
|
224 if( err != KErrNone ) |
|
225 { |
|
226 iRequestHandler->CompleteRequest( request.iRequestId ); |
|
227 User::Leave( err ); |
|
228 } |
|
229 } |
|
230 else |
|
231 { |
|
232 User::Leave( KErrNotFound ); |
|
233 } |
|
234 |
|
235 return request.iRequestId; |
|
236 } |
|
237 // </qmail> |
|
238 |
|
239 //<qmail> |
|
240 EXPORT_C int CFSMailBox::UpdateMessageFlagsL( |
|
241 const TFSMailMsgId aMailboxId, |
|
242 RPointerArray<CFSMailMessage> &messages, |
|
243 MFSMailRequestObserver& aOperationObserver) |
|
244 { |
|
245 Q_UNUSED(aMailboxId); |
|
246 TFSPendingRequest request; |
|
247 |
|
248 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ); |
|
249 |
|
250 if ( plugin ) |
|
251 { |
|
252 // init asynchronous request |
|
253 request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(), |
|
254 aOperationObserver ); |
|
255 |
|
256 MFSMailRequestObserver* observer = request.iObserver; |
|
257 |
|
258 TRAPD( err, plugin->StoreMessagesL( |
|
259 GetId(), |
|
260 messages, |
|
261 *observer, request.iRequestId ) ); |
|
262 |
|
263 if( err != KErrNone ) |
|
264 { |
|
265 iRequestHandler->CompleteRequest( request.iRequestId ); |
|
266 User::Leave( err ); |
|
267 } |
|
268 } |
|
269 else |
|
270 { |
|
271 User::Leave( KErrNotFound ); |
|
272 } |
|
273 |
|
274 return request.iRequestId; |
|
275 |
|
276 } |
|
277 //</qmail> |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CFSMailBox::CreateForwardMessage |
|
281 // ----------------------------------------------------------------------------- |
|
282 EXPORT_C CFSMailMessage* CFSMailBox::CreateForwardMessage( TFSMailMsgId aOriginalMessageId, |
|
283 const TDesC& aHeaderDescriptor ) |
|
284 { |
|
285 FUNC_LOG; |
|
286 CFSMailMessage* message = NULL; |
|
287 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
288 { |
|
289 TRAPD(err,message = plugin->CreateForwardMessageL( GetId(), |
|
290 aOriginalMessageId, |
|
291 aHeaderDescriptor )); |
|
292 if(err != KErrNone) |
|
293 { |
|
294 message = NULL; |
|
295 } |
|
296 } |
|
297 return message; |
|
298 } |
|
299 |
|
300 // <qmail> |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CFSMailBox::CreateForwardMessageL |
|
303 // ----------------------------------------------------------------------------- |
|
304 EXPORT_C TInt CFSMailBox::CreateForwardMessageL( const TFSMailMsgId aOriginalMessageId, |
|
305 MFSMailRequestObserver& aOperationObserver, |
|
306 const TDesC& aHeaderDescriptor ) |
|
307 { |
|
308 TFSPendingRequest request; |
|
309 |
|
310 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ); |
|
311 |
|
312 if ( plugin ) |
|
313 { |
|
314 // init asynchronous request |
|
315 request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(), |
|
316 aOperationObserver ); |
|
317 |
|
318 MFSMailRequestObserver* observer = request.iObserver; |
|
319 |
|
320 TRAPD( err, plugin->CreateForwardMessageL( |
|
321 GetId(), aOriginalMessageId, *observer, request.iRequestId, aHeaderDescriptor ) ); |
|
322 |
|
323 if( err != KErrNone ) |
|
324 { |
|
325 iRequestHandler->CompleteRequest( request.iRequestId ); |
|
326 User::Leave( err ); |
|
327 } |
|
328 } |
|
329 else |
|
330 { |
|
331 User::Leave( KErrNotFound ); |
|
332 } |
|
333 |
|
334 return request.iRequestId; |
|
335 } |
|
336 // </qmail> |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CFSMailBox::CreateReplyMessage |
|
340 // ----------------------------------------------------------------------------- |
|
341 EXPORT_C CFSMailMessage* CFSMailBox::CreateReplyMessage( TFSMailMsgId aOriginalMessageId, |
|
342 TBool aReplyToAll, |
|
343 const TDesC& aHeaderDescriptor ) |
|
344 { |
|
345 FUNC_LOG; |
|
346 CFSMailMessage* message = NULL; |
|
347 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
348 { |
|
349 TRAPD(err,message = plugin->CreateReplyMessageL( GetId(), |
|
350 aOriginalMessageId, |
|
351 aReplyToAll, |
|
352 aHeaderDescriptor )); |
|
353 if(err != KErrNone) |
|
354 { |
|
355 message = NULL; |
|
356 } |
|
357 } |
|
358 return message; |
|
359 } |
|
360 |
|
361 // <qmail> |
|
362 // ----------------------------------------------------------------------------- |
|
363 // CFSMailBox::CreateReplyMessageL |
|
364 // ----------------------------------------------------------------------------- |
|
365 EXPORT_C TInt CFSMailBox::CreateReplyMessageL( const TFSMailMsgId aOriginalMessageId, |
|
366 const TBool aReplyToAll, |
|
367 MFSMailRequestObserver& aOperationObserver, |
|
368 const TDesC& aHeaderDescriptor ) |
|
369 { |
|
370 TFSPendingRequest request; |
|
371 |
|
372 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ); |
|
373 |
|
374 if ( plugin ) |
|
375 { |
|
376 // init asynchronous request |
|
377 request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(), |
|
378 aOperationObserver ); |
|
379 |
|
380 MFSMailRequestObserver* observer = request.iObserver; |
|
381 |
|
382 TRAPD( err, plugin->CreateReplyMessageL( |
|
383 GetId(), aOriginalMessageId, aReplyToAll, *observer, request.iRequestId, aHeaderDescriptor ) ); |
|
384 |
|
385 if( err != KErrNone ) |
|
386 { |
|
387 iRequestHandler->CompleteRequest( request.iRequestId ); |
|
388 User::Leave( err ); |
|
389 } |
|
390 } |
|
391 else |
|
392 { |
|
393 User::Leave( KErrNotFound ); |
|
394 } |
|
395 |
|
396 return request.iRequestId; |
|
397 } |
|
398 // </qmail> |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CFSMailBox::GetStandardFolderId |
|
402 // ----------------------------------------------------------------------------- |
|
403 EXPORT_C TFSMailMsgId CFSMailBox::GetStandardFolderId( TFSFolderType aFolderType ) |
|
404 { |
|
405 FUNC_LOG; |
|
406 |
|
407 TFSMailMsgId folderId; |
|
408 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
409 { |
|
410 TRAPD(err, folderId = plugin->GetStandardFolderIdL(GetId(), aFolderType )); |
|
411 if(err != KErrNone) |
|
412 { |
|
413 folderId.SetNullId(); |
|
414 } |
|
415 } |
|
416 return folderId; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CFSMailBox::SendMessageL |
|
421 // ----------------------------------------------------------------------------- |
|
422 EXPORT_C void CFSMailBox::SendMessageL( CFSMailMessage& aMessage ) |
|
423 { |
|
424 FUNC_LOG; |
|
425 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
426 { |
|
427 // <qmail> Not activated yet. |
|
428 //UpdateMrusL( aMessage.GetToRecipients(), |
|
429 // aMessage.GetCCRecipients(), |
|
430 // aMessage.GetBCCRecipients() ); |
|
431 // </qmail> |
|
432 plugin->SendMessageL( aMessage ); |
|
433 } |
|
434 } |
|
435 |
|
436 // <qmail> |
|
437 // ----------------------------------------------------------------------------- |
|
438 // CFSMailBox::SendMessageL |
|
439 // ----------------------------------------------------------------------------- |
|
440 EXPORT_C TInt CFSMailBox::SendMessageL( |
|
441 CFSMailMessage& aMessage, |
|
442 MFSMailRequestObserver& aOperationObserver ) |
|
443 { |
|
444 FUNC_LOG; |
|
445 |
|
446 TFSPendingRequest request; |
|
447 |
|
448 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ); |
|
449 |
|
450 if ( plugin ) |
|
451 { |
|
452 // <qmail> Not activated yet. |
|
453 //UpdateMrusL( aMessage.GetToRecipients(), |
|
454 // aMessage.GetCCRecipients(), |
|
455 // aMessage.GetBCCRecipients() ); |
|
456 // </qmail> |
|
457 |
|
458 // init asynchronous request |
|
459 request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(), |
|
460 aOperationObserver ); |
|
461 |
|
462 MFSMailRequestObserver* observer = request.iObserver; |
|
463 |
|
464 TRAPD( err, plugin->SendMessageL( |
|
465 aMessage, *observer, request.iRequestId ) ); |
|
466 |
|
467 if( err != KErrNone ) |
|
468 { |
|
469 iRequestHandler->CompleteRequest( request.iRequestId ); |
|
470 User::Leave( err ); |
|
471 } |
|
472 } |
|
473 else |
|
474 { |
|
475 User::Leave( KErrNotFound ); |
|
476 } |
|
477 |
|
478 return request.iRequestId; |
|
479 } |
|
480 // </qmail> |
|
481 |
|
482 // ----------------------------------------------------------------------------- |
|
483 // CFSMailBox::ListFolders |
|
484 // ----------------------------------------------------------------------------- |
|
485 EXPORT_C void CFSMailBox::ListFolders( TFSMailMsgId aFolder, |
|
486 RPointerArray<CFSMailFolder>& aFolderList ) |
|
487 { |
|
488 FUNC_LOG; |
|
489 |
|
490 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
491 { |
|
492 TRAPD(err, plugin->ListFoldersL(GetId(),aFolder,aFolderList)); |
|
493 if(err != KErrNone) |
|
494 { |
|
495 aFolderList.ResetAndDestroy(); |
|
496 } |
|
497 } |
|
498 } |
|
499 |
|
500 // ----------------------------------------------------------------------------- |
|
501 // CFSMailBox::ListFolders |
|
502 // ----------------------------------------------------------------------------- |
|
503 EXPORT_C RPointerArray<CFSMailFolder>& CFSMailBox::ListFolders() |
|
504 { |
|
505 iFolders.ResetAndDestroy(); |
|
506 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
507 { |
|
508 TRAPD(err,plugin->ListFoldersL(GetId(),iFolders)); |
|
509 if(err != KErrNone) |
|
510 { |
|
511 iFolders.ResetAndDestroy(); |
|
512 } |
|
513 } |
|
514 return iFolders; |
|
515 } |
|
516 |
|
517 // ----------------------------------------------------------------------------- |
|
518 // CFSMailBox::GetBrandingIdL |
|
519 // ----------------------------------------------------------------------------- |
|
520 EXPORT_C TDesC& CFSMailBox::GetBrandingIdL() |
|
521 { |
|
522 FUNC_LOG; |
|
523 return BrandingId(); |
|
524 } |
|
525 |
|
526 // ----------------------------------------------------------------------------- |
|
527 // CFSMailBox::MoveMessagesL |
|
528 // ----------------------------------------------------------------------------- |
|
529 EXPORT_C void CFSMailBox::MoveMessagesL( const RArray<TFSMailMsgId>& aMessageIds, |
|
530 const TFSMailMsgId aSourceFolderId, |
|
531 const TFSMailMsgId aDestinationFolderId ) |
|
532 { |
|
533 FUNC_LOG; |
|
534 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
535 { |
|
536 plugin->MoveMessagesL(GetId(), aMessageIds, aSourceFolderId, aDestinationFolderId); |
|
537 } |
|
538 } |
|
539 |
|
540 // ----------------------------------------------------------------------------- |
|
541 // CFSMailBox::CopyMessagesL |
|
542 // ----------------------------------------------------------------------------- |
|
543 EXPORT_C void CFSMailBox::CopyMessagesL( const RArray<TFSMailMsgId>& aMessageIds, |
|
544 RArray<TFSMailMsgId>& aNewMessages, |
|
545 const TFSMailMsgId aSourceFolderId, |
|
546 const TFSMailMsgId aDestinationFolderId ) |
|
547 { |
|
548 FUNC_LOG; |
|
549 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
550 { |
|
551 plugin->CopyMessagesL(GetId(), aMessageIds, aNewMessages, |
|
552 aSourceFolderId, aDestinationFolderId ); |
|
553 } |
|
554 } |
|
555 |
|
556 // ----------------------------------------------------------------------------- |
|
557 // CFSMailBox::SearchL |
|
558 // ----------------------------------------------------------------------------- |
|
559 EXPORT_C void CFSMailBox::SearchL( const RPointerArray<TDesC>& /*aSearchStrings*/, |
|
560 const TFSMailSortCriteria& /*aSortCriteria*/, |
|
561 MFSMailBoxSearchObserver& /*aSearchObserver*/, |
|
562 const RArray<TFSMailMsgId> /*aFolderIds */ ) |
|
563 { |
|
564 FUNC_LOG; |
|
565 } |
|
566 |
|
567 // ----------------------------------------------------------------------------- |
|
568 // CFSMailBox::SearchL |
|
569 // ----------------------------------------------------------------------------- |
|
570 EXPORT_C void CFSMailBox::SearchL( const RPointerArray<TDesC>& aSearchStrings, |
|
571 const TFSMailSortCriteria& aSortCriteria, |
|
572 MFSMailBoxSearchObserver& aSearchObserver ) |
|
573 { |
|
574 FUNC_LOG; |
|
575 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
576 { |
|
577 // get mailbox folder list |
|
578 iFolders.ResetAndDestroy(); |
|
579 plugin->ListFoldersL(GetId(),iFolders); |
|
580 |
|
581 TFSMailMsgId draftsFolderId = GetStandardFolderId( EFSDraftsFolder ); |
|
582 TFSMailMsgId outboxId = GetStandardFolderId( EFSOutbox ); |
|
583 |
|
584 // remove outbox, drafts folder from folder list |
|
585 RArray<TFSMailMsgId> folderIds; |
|
586 folderIds.Reset(); |
|
587 for(TInt i=0;i<iFolders.Count();i++) |
|
588 { |
|
589 TFSMailMsgId id = iFolders[i]->GetFolderId(); |
|
590 if( id != draftsFolderId && id != outboxId ) |
|
591 { |
|
592 folderIds.Append(id); |
|
593 } |
|
594 } |
|
595 |
|
596 // start search |
|
597 plugin->SearchL( GetId(), folderIds, aSearchStrings, aSortCriteria, aSearchObserver ); |
|
598 folderIds.Reset(); |
|
599 } |
|
600 } |
|
601 |
|
602 // ----------------------------------------------------------------------------- |
|
603 // CFSMailBox::CancelSearch |
|
604 // ----------------------------------------------------------------------------- |
|
605 EXPORT_C void CFSMailBox::CancelSearch() |
|
606 { |
|
607 FUNC_LOG; |
|
608 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
609 { |
|
610 plugin->CancelSearch( GetId() ); |
|
611 } |
|
612 } |
|
613 |
|
614 // ----------------------------------------------------------------------------- |
|
615 // CFSMailBox::ClearSearchResultCache |
|
616 // ----------------------------------------------------------------------------- |
|
617 EXPORT_C void CFSMailBox::ClearSearchResultCache() |
|
618 { |
|
619 FUNC_LOG; |
|
620 if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId())) |
|
621 { |
|
622 plugin->ClearSearchResultCache( GetId() ); |
|
623 } |
|
624 } |
|
625 |
|
626 // ----------------------------------------------------------------------------- |
|
627 // CFSMailBox::ListMrusL |
|
628 // ----------------------------------------------------------------------------- |
|
629 EXPORT_C MDesCArray* CFSMailBox::ListMrusL() const |
|
630 { |
|
631 FUNC_LOG; |
|
632 MDesCArray* mruList(0); |
|
633 if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId() ) ) |
|
634 { |
|
635 mruList = plugin->GetMrusL( GetId() ); |
|
636 } |
|
637 return mruList; |
|
638 } |
|
639 |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // CFSMailBox::CurrentSyncState |
|
643 // ----------------------------------------------------------------------------- |
|
644 EXPORT_C TSSMailSyncState CFSMailBox::CurrentSyncState() const |
|
645 { |
|
646 FUNC_LOG; |
|
647 TSSMailSyncState syncState(Idle); |
|
648 if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) ) |
|
649 { |
|
650 syncState = plugin->CurrentSyncState( GetId() ); |
|
651 } |
|
652 return syncState; |
|
653 } |
|
654 |
|
655 // ----------------------------------------------------------------------------- |
|
656 // CFSMailBox::HasCapability |
|
657 // ----------------------------------------------------------------------------- |
|
658 EXPORT_C TBool CFSMailBox::HasCapability( const TFSMailBoxCapabilities aCapability ) const |
|
659 { |
|
660 FUNC_LOG; |
|
661 TBool capability = EFalse; |
|
662 if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) ) |
|
663 { |
|
664 TRAPD( err,capability = plugin->MailboxHasCapabilityL( aCapability,GetId() )) ; |
|
665 if ( err != KErrNone ) |
|
666 { |
|
667 capability = EFalse; |
|
668 } |
|
669 } |
|
670 return capability; |
|
671 } |
|
672 |
|
673 // ----------------------------------------------------------------------------- |
|
674 // CFSMailBox::GetMailBoxStatus |
|
675 // ----------------------------------------------------------------------------- |
|
676 EXPORT_C TFSMailBoxStatus CFSMailBox::GetMailBoxStatus() |
|
677 { |
|
678 FUNC_LOG; |
|
679 TFSMailBoxStatus status(EFSMailBoxOffline); |
|
680 if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId() ) ) |
|
681 { |
|
682 status = plugin->GetMailBoxStatus( GetId() ); |
|
683 } |
|
684 return status; |
|
685 } |
|
686 |
|
687 // ----------------------------------------------------------------------------- |
|
688 // CFSMailBox::SetCredentialsL |
|
689 // ----------------------------------------------------------------------------- |
|
690 EXPORT_C void CFSMailBox::SetCredentialsL( const TDesC& aUsername, const TDesC& aPassword ) |
|
691 { |
|
692 FUNC_LOG; |
|
693 if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId() ) ) |
|
694 { |
|
695 plugin->SetCredentialsL( GetId(), aUsername, aPassword ); |
|
696 } |
|
697 } |
|
698 |
|
699 // ----------------------------------------------------------------------------- |
|
700 // CFSMailBox::RemoveDownLoadedAttachmentsL |
|
701 // ----------------------------------------------------------------------------- |
|
702 EXPORT_C void CFSMailBox::RemoveDownLoadedAttachmentsL() |
|
703 { |
|
704 FUNC_LOG; |
|
705 |
|
706 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ); |
|
707 if ( plugin ) |
|
708 { |
|
709 // get inbox folder from plugin |
|
710 TFSMailMsgId folderId = GetStandardFolderId( EFSInbox ); |
|
711 CFSMailFolder* folder = plugin->GetFolderByUidL( GetId(), folderId ); |
|
712 if ( folder ) |
|
713 { |
|
714 folder->RemoveDownLoadedAttachmentsL(); |
|
715 delete folder; |
|
716 } |
|
717 } |
|
718 } |
|
719 |
|
720 // ----------------------------------------------------------------------------- |
|
721 // CFSMailBox::GetConnectionId |
|
722 // ----------------------------------------------------------------------------- |
|
723 EXPORT_C TInt CFSMailBox::GetConnectionId( TUint32& aConnectionId ) |
|
724 { |
|
725 FUNC_LOG; |
|
726 TInt rcode = KErrNotSupported; |
|
727 if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) ) |
|
728 { |
|
729 rcode = plugin->GetConnectionId( GetId(), aConnectionId ); |
|
730 } |
|
731 return rcode; |
|
732 } |
|
733 |
|
734 // ----------------------------------------------------------------------------- |
|
735 // CFSMailBox::IsConnectionAllowedWhenRoaming |
|
736 // ----------------------------------------------------------------------------- |
|
737 EXPORT_C TInt CFSMailBox::IsConnectionAllowedWhenRoaming( TBool& aConnectionAllowed ) |
|
738 { |
|
739 FUNC_LOG; |
|
740 TInt rcode = KErrNotSupported; |
|
741 if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) ) |
|
742 { |
|
743 rcode = plugin->IsConnectionAllowedWhenRoaming( GetId(), aConnectionAllowed ); |
|
744 } |
|
745 return rcode; |
|
746 } |
|
747 |
|
748 // ----------------------------------------------------------------------------- |
|
749 // CFSMailBox::UpdateMrusL |
|
750 // ----------------------------------------------------------------------------- |
|
751 void CFSMailBox::UpdateMrusL( |
|
752 const RPointerArray<CFSMailAddress>& aRecipients, |
|
753 const RPointerArray<CFSMailAddress>& aCCRecipients, |
|
754 const RPointerArray<CFSMailAddress>& aBCCRecipients ) const |
|
755 { |
|
756 FUNC_LOG; |
|
757 |
|
758 // First lets make a copy of the current mru list |
|
759 // whose content we can later alter as we wish |
|
760 MDesCArray* currentMruList( NULL ); |
|
761 |
|
762 CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()); |
|
763 if ( !plugin ) |
|
764 { |
|
765 User::Leave( KErrGeneral ); |
|
766 } |
|
767 currentMruList = plugin->GetMrusL( GetId() ); |
|
768 if ( !currentMruList ) |
|
769 { |
|
770 // This should not happen because previous function |
|
771 // should leave in error cases and if there are no |
|
772 // entries then the pointer should still be pointing |
|
773 // to valid array. |
|
774 User::Leave( KErrGeneral ); |
|
775 } |
|
776 |
|
777 CDesCArraySeg* newMruList( NULL ); |
|
778 TRAPD( error, newMruList = CopyArrayL( *currentMruList ) ); |
|
779 |
|
780 delete currentMruList; |
|
781 |
|
782 if ( error != KErrNone ) |
|
783 { |
|
784 User::Leave( error ); |
|
785 } |
|
786 |
|
787 CleanupStack::PushL( newMruList ); |
|
788 |
|
789 // Now check that all given recipients are found from the |
|
790 // mru list. |
|
791 |
|
792 // Notice that the order here has a meaning. For example |
|
793 // if the latest used address is appended to the end, then |
|
794 // the aRecipients' addresses are found from the end because |
|
795 // they are updated after cc and bcc recipients. |
|
796 UpdateMruListL( *newMruList, aBCCRecipients ); |
|
797 UpdateMruListL( *newMruList, aCCRecipients ); |
|
798 UpdateMruListL( *newMruList, aRecipients ); |
|
799 |
|
800 // Finally update the new mru list to the plugin |
|
801 plugin->SetMrusL( GetId(), newMruList ); |
|
802 |
|
803 CleanupStack::PopAndDestroy( newMruList ); |
|
804 } |
|
805 |
|
806 // ----------------------------------------------------------------------------- |
|
807 // CFSMailBox::CopyArrayL |
|
808 // ----------------------------------------------------------------------------- |
|
809 CDesCArraySeg* CFSMailBox::CopyArrayL( MDesCArray& aArrayToBeCopied ) const |
|
810 { |
|
811 FUNC_LOG; |
|
812 CDesCArraySeg* newArray = new (ELeave) CDesCArraySeg( 10 ); |
|
813 CleanupStack::PushL( newArray ); |
|
814 |
|
815 TInt itemCount( aArrayToBeCopied.MdcaCount() ); |
|
816 TInt index( 0 ); |
|
817 while ( index < itemCount ) |
|
818 { |
|
819 newArray->AppendL( aArrayToBeCopied.MdcaPoint( index ) ); |
|
820 ++index; |
|
821 } |
|
822 |
|
823 CleanupStack::Pop( newArray ); |
|
824 return newArray; |
|
825 } |
|
826 |
|
827 // ----------------------------------------------------------------------------- |
|
828 // CFSMailBox::UpdateMruListL |
|
829 // ----------------------------------------------------------------------------- |
|
830 void CFSMailBox::UpdateMruListL( |
|
831 CDesCArraySeg& aMruList, |
|
832 const RPointerArray<CFSMailAddress>& aNewRecentlyUsedOnes ) const |
|
833 { |
|
834 FUNC_LOG; |
|
835 TUint newCount( aNewRecentlyUsedOnes.Count() ); |
|
836 TUint newIndexer( 0 ); |
|
837 |
|
838 while ( newIndexer < newCount ) |
|
839 { |
|
840 if ( aNewRecentlyUsedOnes[newIndexer] ) |
|
841 { |
|
842 // The address is used as a search string because every |
|
843 // address does not have a display name |
|
844 TDesC& searchedAddress( |
|
845 aNewRecentlyUsedOnes[newIndexer]->GetEmailAddress() ); |
|
846 TInt position( -1 ); |
|
847 |
|
848 TInt found( |
|
849 FindAddressFromMruList( aMruList, searchedAddress, position ) ); |
|
850 |
|
851 if ( found != 0 ) |
|
852 { |
|
853 AddAndRemoveExcessMruL( aMruList, |
|
854 *aNewRecentlyUsedOnes[newIndexer] ); |
|
855 } |
|
856 else |
|
857 { |
|
858 SetAsMostRecentMruL( aMruList, |
|
859 position, |
|
860 *aNewRecentlyUsedOnes[newIndexer] ); |
|
861 } |
|
862 } |
|
863 |
|
864 ++newIndexer; |
|
865 } |
|
866 } |
|
867 |
|
868 // ----------------------------------------------------------------------------- |
|
869 // CFSMailBox::FindAddressFromMruList |
|
870 // ----------------------------------------------------------------------------- |
|
871 TInt CFSMailBox::FindAddressFromMruList( CDesCArraySeg& aMruList, |
|
872 TDesC& searchedAddress, |
|
873 TInt& aPos ) const |
|
874 { |
|
875 FUNC_LOG; |
|
876 // CDesCArray::Find() is not used here because there is |
|
877 // possibility that we have to go through the whole array |
|
878 // and return the index for one specific match. Find() returns |
|
879 // only the index of the first match and searching for the rest |
|
880 // using Find() would cause undesired complexity. |
|
881 |
|
882 |
|
883 const TInt KMruListCount( aMruList.Count() ); |
|
884 // Start indexing from 1 because the first |
|
885 // address is on that index if it exists. |
|
886 TInt mruListIndexer( 1 ); |
|
887 while( mruListIndexer < KMruListCount ) |
|
888 { |
|
889 TPtrC address( aMruList[mruListIndexer] ); |
|
890 if ( address == searchedAddress ) |
|
891 { |
|
892 aPos = mruListIndexer; |
|
893 return 0; |
|
894 } |
|
895 |
|
896 // We are only interested of the addresses so let's |
|
897 // check only every other descriptor. |
|
898 // (the addresses) |
|
899 mruListIndexer = mruListIndexer + 2; |
|
900 } |
|
901 |
|
902 aPos = aMruList.Count(); |
|
903 return 1; |
|
904 } |
|
905 |
|
906 // ----------------------------------------------------------------------------- |
|
907 // CFSMailBox::AddAndRemoveExcessMruL |
|
908 // ----------------------------------------------------------------------------- |
|
909 void CFSMailBox::AddAndRemoveExcessMruL( CDesCArraySeg& aMruList, |
|
910 CFSMailAddress& aToBeAdded ) const |
|
911 { |
|
912 FUNC_LOG; |
|
913 if ( aMruList.Count() == KMaxMruEntries ) |
|
914 { |
|
915 // Remove the oldest entry pair from the beginning |
|
916 aMruList.Delete( 0, 2 ); |
|
917 } |
|
918 // Latest address is always found from the end. |
|
919 AppendMruItemL( aMruList, aToBeAdded ); |
|
920 } |
|
921 |
|
922 // ----------------------------------------------------------------------------- |
|
923 // CFSMailBox::SetAsMostRecentMruL |
|
924 // ----------------------------------------------------------------------------- |
|
925 void CFSMailBox::SetAsMostRecentMruL( CDesCArraySeg& aMruList, |
|
926 TInt aPosition, |
|
927 CFSMailAddress& aMostRecent ) const |
|
928 { |
|
929 FUNC_LOG; |
|
930 // Position of the address is given so the possible display name is |
|
931 // in the previous slot. Delete both. |
|
932 aMruList.Delete( aPosition - 1, 2 ); |
|
933 // Latest address is always found from the end. |
|
934 AppendMruItemL( aMruList, aMostRecent ); |
|
935 } |
|
936 |
|
937 // ----------------------------------------------------------------------------- |
|
938 // CFSMailBox::AppendMruItemL |
|
939 // ----------------------------------------------------------------------------- |
|
940 void CFSMailBox::AppendMruItemL( CDesCArraySeg& aMruList, |
|
941 CFSMailAddress& aToBeAppended ) const |
|
942 { |
|
943 FUNC_LOG; |
|
944 // In the array, display name is always the first and then comes |
|
945 // the actual address. |
|
946 |
|
947 // <cmail> avoid setting email address as display name so it won't |
|
948 // be displayed twice in the list |
|
949 TDesC* displayName = &aToBeAppended.GetDisplayName(); |
|
950 TDesC* emailAddress = &aToBeAppended.GetEmailAddress(); |
|
951 |
|
952 if( displayName->Length() > 0 && displayName->Compare(*emailAddress) == 0 ) |
|
953 { |
|
954 aMruList.AppendL( KNullDesC ); |
|
955 } |
|
956 else |
|
957 { |
|
958 aMruList.AppendL( *displayName ); |
|
959 } |
|
960 |
|
961 aMruList.AppendL( *emailAddress ); |
|
962 // </cmail> |
|
963 } |
|
964 |