|
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: Implementation of the class CFsMtmClient. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "emailtrace.h" |
|
21 #include <txtrich.h> |
|
22 #include <msvids.h> |
|
23 |
|
24 #ifndef FF_CMAIL_INTEGRATION |
|
25 #include <mtmuidsdef.hrh> |
|
26 #endif // FF_CMAIL_INTEGRATION |
|
27 |
|
28 #include <mtmdef.h> |
|
29 #include <msvuids.h> |
|
30 #include <bautils.h> |
|
31 #include <featmgr.h> |
|
32 |
|
33 |
|
34 #include <centralrepository.h> |
|
35 #include "FreestyleEmailCenRepKeys.h" |
|
36 #include <MeetingRequestIds.hrh> |
|
37 #include "cfssendashelper.h" |
|
38 #include "fsmtmsconstants.h" |
|
39 #include "cfsclientmtm.h" |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CFsMtmClient::NewL |
|
44 // Factory function. This will be called by messaging frame work while |
|
45 // creating client side MTM. The ordinal of this function is assigned to |
|
46 // entry_point in fsmtms.rss file. The ordinal can be found in |
|
47 // FsClientMtmU.DEF |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CFsMtmClient* CFsMtmClient::NewL( |
|
51 CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aMsvSession) |
|
52 { |
|
53 FUNC_LOG; |
|
54 |
|
55 CFsMtmClient* self = new (ELeave) CFsMtmClient( aRegisteredMtmDll, |
|
56 aMsvSession ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop( self ); //SCANNER |
|
60 |
|
61 return self; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CFsMtmClient::CFsMtmClient |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CFsMtmClient::CFsMtmClient( CRegisteredMtmDll& aRegisteredMtmDll, |
|
69 CMsvSession& aMsvSession ):CBaseMtm( aRegisteredMtmDll, aMsvSession ) |
|
70 { |
|
71 FUNC_LOG; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CFsMtmClient::ConstructL |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CFsMtmClient::ConstructL() |
|
79 { |
|
80 FUNC_LOG; |
|
81 |
|
82 SwitchCurrentEntryL( KMsvRootIndexEntryId ); |
|
83 iSendAsHelper = CFsSendAsHelper::NewL(); |
|
84 |
|
85 // Check configuration status of "email attached in email" from cenrep |
|
86 // and set flag according to that. |
|
87 CRepository* repository = NULL; |
|
88 TRAPD( ret, repository = CRepository::NewL( KFreestyleEmailCenRep ) ); |
|
89 if ( ret == KErrNone ) |
|
90 { |
|
91 CleanupStack::PushL( repository ); |
|
92 TInt rval = KErrNone; |
|
93 TInt hidefeature = 0; |
|
94 rval = repository->Get( KEmailHideFS205UIFeature, hidefeature ); |
|
95 if( rval == KErrNone && hidefeature == EFalse ) |
|
96 { |
|
97 iEmailAttachedInEmail = ETrue; |
|
98 iActiveSchedulerWait = CMsvOperationActiveSchedulerWait::NewLC(); |
|
99 CleanupStack::Pop(); // iActiveSchedulerWait |
|
100 } |
|
101 CleanupStack::PopAndDestroy( repository ); |
|
102 } |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CFsMtmClient::~CFsMtmClient |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 CFsMtmClient::~CFsMtmClient() |
|
110 { |
|
111 FUNC_LOG; |
|
112 |
|
113 delete iAccountEntry; |
|
114 delete iSendAsHelper; |
|
115 |
|
116 if ( iEmailAttachedInEmail ) |
|
117 { |
|
118 delete iActiveSchedulerWait; |
|
119 } |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CFsMtmClient::AddAddresseeL |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CFsMtmClient::AddAddresseeL( const TDesC& aRealAddress ) |
|
127 { |
|
128 FUNC_LOG; |
|
129 |
|
130 TRAPD( err, iSendAsHelper->AddRecipientL( aRealAddress, KNullDesC, |
|
131 EMsvRecipientTo ) ); |
|
132 if( err != KErrNone ) |
|
133 { |
|
134 } |
|
135 |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CFsMtmClient::AddAddresseeL |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CFsMtmClient::AddAddresseeL( const TDesC& aRealAddress, |
|
143 const TDesC& aAlias ) |
|
144 { |
|
145 FUNC_LOG; |
|
146 |
|
147 TRAPD( err, iSendAsHelper->AddRecipientL( aRealAddress, aAlias, |
|
148 EMsvRecipientTo ) ); |
|
149 if( err != KErrNone ) |
|
150 { |
|
151 } |
|
152 |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CFsMtmClient::AddAddresseeL |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CFsMtmClient::AddAddresseeL( TMsvRecipientType aType, |
|
160 const TDesC& aRealAddress ) |
|
161 { |
|
162 FUNC_LOG; |
|
163 |
|
164 TRAPD( err, iSendAsHelper->AddRecipientL( aRealAddress, KNullDesC, aType ) ); |
|
165 if( err != KErrNone ) |
|
166 { |
|
167 } |
|
168 |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // CFsMtmClient::AddAddresseeL |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 void CFsMtmClient::AddAddresseeL( TMsvRecipientType aType, |
|
176 const TDesC& aRealAddress, const TDesC& aAlias ) |
|
177 { |
|
178 FUNC_LOG; |
|
179 |
|
180 TRAPD( err, iSendAsHelper->AddRecipientL( aRealAddress, aAlias, aType ) ); |
|
181 if( err != KErrNone ) |
|
182 { |
|
183 } |
|
184 |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CFsMtmClient::RemoveAddressee |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CFsMtmClient::RemoveAddressee(TInt /*aIndex*/) |
|
192 { |
|
193 FUNC_LOG; |
|
194 |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // CFsMtmClient::CFsMtmClient |
|
199 // Store entry data. If it is a service entry, store the current settings. |
|
200 // Otherwise it has to be a message. |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CFsMtmClient::SaveMessageL() |
|
204 { |
|
205 FUNC_LOG; |
|
206 |
|
207 HBufC* buf = HBufC::NewL( Body().DocumentLength() ); |
|
208 CleanupStack::PushL( buf ); |
|
209 TPtr ptr = buf->Des(); |
|
210 Body().Extract( ptr, 0 ); |
|
211 // INFO : By default the body will have x2029, so checking for > 1 |
|
212 if ( ptr.Length() > 0 ) |
|
213 { |
|
214 iSendAsHelper->SetBodyL( ptr ); |
|
215 } |
|
216 CleanupStack::PopAndDestroy(buf); |
|
217 |
|
218 // Save the message |
|
219 iAccountId = iMsvEntry->Entry().iServiceId; |
|
220 delete iAccountEntry; |
|
221 iAccountEntry = NULL; |
|
222 iAccountEntry = CMsvEntry::NewL( Session(), iAccountId, |
|
223 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, |
|
224 ETrue )); |
|
225 |
|
226 TUint pluginId = iAccountEntry->Entry().MtmData1(); |
|
227 TUint id = iAccountEntry->Entry().MtmData2(); |
|
228 iSendAsHelper->StoreDataL(pluginId, id); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // CFsMtmClient::LoadMessageL |
|
233 // Restore entry data Operation inverse to StoreL |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 void CFsMtmClient::LoadMessageL() |
|
237 { |
|
238 FUNC_LOG; |
|
239 |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // CFsMtmClient::ReplyL |
|
244 // Not supported |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 CMsvOperation* CFsMtmClient::ReplyL (TMsvId /*aReplyEntryId*/, |
|
248 TMsvPartList /*aPartlist*/, TRequestStatus& /*aCompletionStatus*/ ) |
|
249 { |
|
250 FUNC_LOG; |
|
251 |
|
252 User::Leave( KErrNotSupported ); |
|
253 |
|
254 return NULL; //To statisfy the compiler |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // CFsMtmClient::ReplyL |
|
259 // Not supported |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 CMsvOperation* CFsMtmClient::ForwardL( TMsvId /*aReplyEntryId*/, |
|
263 TMsvPartList /*aPartlist*/, TRequestStatus& /*aCompletionStatus*/ ) |
|
264 { |
|
265 FUNC_LOG; |
|
266 |
|
267 User::Leave( KErrNotSupported ); |
|
268 |
|
269 return NULL; |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CFsMtmClient::ValidateMessage |
|
274 // Not supported |
|
275 // Message validation |
|
276 // The only thing about the message that can be invalid |
|
277 // is the iDescription, which should be an acceptable file name. So, length isn't |
|
278 // allowed to be zero, and backslashes are not allowed in iDescription. |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 TMsvPartList CFsMtmClient::ValidateMessage( TUint /*aPartlist*/ ) |
|
282 { |
|
283 FUNC_LOG; |
|
284 |
|
285 return 0; //SCANNER |
|
286 } |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 // CFsMtmClient::Find |
|
290 // Not supported |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 TMsvPartList CFsMtmClient::Find( const TDesC& /*aTextToFind*/, |
|
294 TMsvPartList /*aPartlist*/ ) |
|
295 { |
|
296 FUNC_LOG; |
|
297 |
|
298 return 0; |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // CFsMtmClient::QueryCapability |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 TInt CFsMtmClient::QueryCapability( TUid aCapability, TInt& aResponse ) |
|
306 { |
|
307 FUNC_LOG; |
|
308 |
|
309 TInt error = KErrNone; |
|
310 switch ( aCapability.iUid ) |
|
311 { |
|
312 case KUidMtmQueryMaxBodySizeValue: |
|
313 case KUidMtmQueryMaxTotalMsgSizeValue: |
|
314 aResponse = KMaxTInt; |
|
315 break; |
|
316 |
|
317 case KUidMtmQuerySupportedBodyValue: |
|
318 aResponse = KMtm7BitBody + KMtm8BitBody + KMtm16BitBody + |
|
319 KMtmBinaryBody; |
|
320 break; |
|
321 |
|
322 case KUidMtmQuerySupportAttachmentsValue: |
|
323 case KUidMtmQueryCanSendMsgValue: |
|
324 aResponse = ETrue; |
|
325 break; |
|
326 // Required to make MTM support the MR |
|
327 case KMtmUiSupportMeetingRequest: |
|
328 aResponse = ETrue; |
|
329 break; |
|
330 default: |
|
331 error = KErrNotSupported; |
|
332 } |
|
333 return error; |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // CFsMtmClient::SetSubjectL |
|
338 // Sets the message context's subject text |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 void CFsMtmClient::SetSubjectL(const TDesC& aSubject) |
|
342 { |
|
343 FUNC_LOG; |
|
344 TRAPD( err, iSendAsHelper->SetSubjectL( aSubject) ); |
|
345 if ( err != KErrNone ) |
|
346 { |
|
347 } |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // CFsMtmClient::AddAttachmentL |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 void CFsMtmClient::AddAttachmentL(const TDesC& aFilePath, |
|
355 const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus) |
|
356 { |
|
357 FUNC_LOG; |
|
358 |
|
359 TRAPD( err, |
|
360 { |
|
361 iSendAsHelper->AddAttachmentL(aFilePath, aMimeType, aCharset ); |
|
362 }); |
|
363 |
|
364 if ( err != KErrNone ) |
|
365 { |
|
366 } |
|
367 //Complete ourselves immediately. |
|
368 TRequestStatus* status = &aStatus; |
|
369 User::RequestComplete( status, KErrNone ); |
|
370 |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------------------------- |
|
374 // CFsMtmClient::AddAttachmentL |
|
375 // --------------------------------------------------------------------------- |
|
376 // |
|
377 void CFsMtmClient::AddAttachmentL(RFile& aFile, const TDesC8& aMimeType, |
|
378 TUint aCharset, TRequestStatus& aStatus) |
|
379 { |
|
380 FUNC_LOG; |
|
381 iSendAsHelper->AddAttachmentL(aFile, aMimeType, aCharset ); |
|
382 |
|
383 //Complete ourselves immediately. |
|
384 TRequestStatus* status = &aStatus; |
|
385 User::RequestComplete( status, KErrNone ); |
|
386 |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // CFsMtmClient::AddLinkedAttachmentL |
|
391 // --------------------------------------------------------------------------- |
|
392 // |
|
393 void CFsMtmClient::AddLinkedAttachmentL(const TDesC& aFilePath, |
|
394 const TDesC8& aMimeType, TUint aCharset, TRequestStatus& aStatus ) |
|
395 { |
|
396 FUNC_LOG; |
|
397 iSendAsHelper->AddAttachmentL(aFilePath, aMimeType, aCharset ); |
|
398 //Complete ourselves immediately. |
|
399 TRequestStatus* status = &aStatus; |
|
400 User::RequestComplete( status, KErrNone ); |
|
401 } |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // CFsMtmClient::AddEntryAsAttachmentL |
|
405 // --------------------------------------------------------------------------- |
|
406 // |
|
407 void CFsMtmClient::AddEntryAsAttachmentL(TMsvId /*aAttachmentId*/, |
|
408 TRequestStatus& /*aStatus*/) |
|
409 { |
|
410 FUNC_LOG; |
|
411 |
|
412 User::Leave( KErrNotSupported ); |
|
413 |
|
414 } |
|
415 |
|
416 // --------------------------------------------------------------------------- |
|
417 // CFsMtmClient::CreateAttachmentL |
|
418 // --------------------------------------------------------------------------- |
|
419 // |
|
420 void CFsMtmClient::CreateAttachmentL( const TDesC& /*aFileName*/, |
|
421 RFile& /*aAttachmentFile*/, const TDesC8& /*aMimeType*/, |
|
422 TUint /*aCharset*/, TRequestStatus& /*aStatus*/) |
|
423 { |
|
424 FUNC_LOG; |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 // CFsMtmClient::InvokeSyncFunctionL |
|
429 // Call MTM-specific operation synchronously |
|
430 // --------------------------------------------------------------------------- |
|
431 // |
|
432 void CFsMtmClient::InvokeSyncFunctionL( TInt aFunctionId, |
|
433 const CMsvEntrySelection& aSelection, TDes8& aParameter ) |
|
434 { |
|
435 FUNC_LOG; |
|
436 if ( aFunctionId == KMTMMailAddressRequestFunctionId && |
|
437 ( &aSelection )->Count() > 0 ) //SCANNER |
|
438 { |
|
439 CMsvEntry* root = CMsvEntry::NewL( Session(), KMsvRootIndexEntryId, |
|
440 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) ); |
|
441 CleanupStack::PushL( root ); |
|
442 root->SetEntryL( ( &aSelection )->At( 0 ) ); |
|
443 // aParameter = |
|
444 aParameter.Copy( root->Entry().iDescription ); |
|
445 CleanupStack::PopAndDestroy( root ); |
|
446 } |
|
447 |
|
448 else if ( iEmailAttachedInEmail && |
|
449 ( aFunctionId == KEasEmailMTMAddEmailAttachment || |
|
450 aFunctionId == KEasEmailMTMDeleteEntry ) ) |
|
451 { |
|
452 TInt error = KErrNone; |
|
453 CMsvOperation* operation = InvokeAsyncFunctionL( aFunctionId, aSelection, aParameter, iActiveSchedulerWait->iStatus ); |
|
454 if ( operation ) |
|
455 { |
|
456 iActiveSchedulerWait->Start(); |
|
457 // for now, the iStatus.Int contains the new entry ID in mtm |
|
458 iMTMAttachmentId = iActiveSchedulerWait->iStatus.Int(); |
|
459 if ( iMTMAttachmentId <= 0 ) |
|
460 { |
|
461 error = iActiveSchedulerWait->iStatus.Int(); |
|
462 } |
|
463 else |
|
464 { |
|
465 error = KErrNone; |
|
466 } |
|
467 |
|
468 delete operation; |
|
469 } |
|
470 else |
|
471 { |
|
472 error = KErrNotSupported; |
|
473 } |
|
474 |
|
475 User::LeaveIfError( error ); |
|
476 } |
|
477 else |
|
478 { |
|
479 User::Leave( KErrNotSupported ); |
|
480 } |
|
481 } |
|
482 |
|
483 // --------------------------------------------------------------------------- |
|
484 // CFsMtmClient::InvokeAsyncFunctionL |
|
485 // Call MTM-specific operation asynchronously |
|
486 // --------------------------------------------------------------------------- |
|
487 // |
|
488 CMsvOperation* CFsMtmClient::InvokeAsyncFunctionL( |
|
489 TInt aFunctionId, |
|
490 const CMsvEntrySelection &aSelection, |
|
491 TDes8 &aParameter, |
|
492 TRequestStatus &aCompletionStatus) |
|
493 { |
|
494 FUNC_LOG; |
|
495 |
|
496 if ( iEmailAttachedInEmail ) |
|
497 { |
|
498 CMsvOperation* operation = 0; |
|
499 if ( aFunctionId == KMTMStandardFunctionsSendMessage ) |
|
500 { |
|
501 operation = CMsvCompletedOperation::NewL( Session(), Type(), KNullDesC8, iAccountId, aCompletionStatus ); |
|
502 } |
|
503 else if ( ( aFunctionId >= 0 ) && ( aFunctionId < KEasEmailMTMLastCommand ) ) |
|
504 { |
|
505 operation = Session().TransferCommandL( aSelection, aFunctionId, aParameter, aCompletionStatus ); |
|
506 } |
|
507 return operation; |
|
508 } |
|
509 else |
|
510 { |
|
511 User::Leave( KErrNotSupported ); |
|
512 } |
|
513 |
|
514 return NULL; |
|
515 } |
|
516 |
|
517 // --------------------------------------------------------------------------- |
|
518 // CFsMtmClient::ContextEntrySwitched |
|
519 // Called by the base class functions SwitchCurrentEntryL() and |
|
520 // SetCurrentEntryL() when the context is changed to another entry. |
|
521 // Implementation should clear iAddresseeList & any MTM specific cache. |
|
522 // --------------------------------------------------------------------------- |
|
523 // |
|
524 void CFsMtmClient::ContextEntrySwitched() |
|
525 { |
|
526 FUNC_LOG; |
|
527 } |
|
528 |
|
529 // --------------------------------------------------------------------------- |
|
530 // CFsMtmClient::RemoveRedundantAccountsL |
|
531 // This function is called by FS Email server every time an instance of |
|
532 // mailserver is started. This function removes redundant mail boxes. |
|
533 // --------------------------------------------------------------------------- |
|
534 // |
|
535 EXPORT_C TInt CFsMtmClient::RemoveRedundantAccountsL(RArray<TFSMailMsgId>& aMailBoxIds) |
|
536 { |
|
537 FUNC_LOG; |
|
538 |
|
539 // Get S60 mailboxes |
|
540 CMsvEntry* root = CMsvEntry::NewL( Session(), KMsvRootIndexEntryId, |
|
541 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) ); |
|
542 CleanupStack::PushL( root ); |
|
543 |
|
544 // Go through MsvEntries and delete account if corresponding |
|
545 // FS account doesn't exist. |
|
546 |
|
547 CMsvEntrySelection* childSelection = root->ChildrenWithMtmL( |
|
548 KUidMsgValTypeFsMtmVal ); |
|
549 CleanupStack::PushL( childSelection ); |
|
550 for ( TInt i = 0; i < childSelection->Count(); i++ ) |
|
551 { |
|
552 TBool accountExistsInFS = EFalse; |
|
553 root->SetEntryL( childSelection->At( i ) ); |
|
554 TUint pluginId = root->Entry().MtmData1(); |
|
555 TUint mailboxId = root->Entry().MtmData2(); |
|
556 |
|
557 // Go through FS mailboxes and check if box is in there |
|
558 for(TInt j = 0; j < aMailBoxIds.Count(); j++ ) |
|
559 { |
|
560 TUint FSid = aMailBoxIds[j].Id(); |
|
561 if( FSid == mailboxId ) |
|
562 { |
|
563 accountExistsInFS = ETrue; |
|
564 break; |
|
565 } |
|
566 } |
|
567 |
|
568 // Remove if not found |
|
569 if( !accountExistsInFS ) |
|
570 { |
|
571 TFSMailMsgId accountId(pluginId, mailboxId); |
|
572 User::LeaveIfError( DeleteAccountL( KNullDesC, accountId ) ); |
|
573 } |
|
574 } |
|
575 |
|
576 CleanupStack::PopAndDestroy( childSelection ); |
|
577 CleanupStack::PopAndDestroy( root ); |
|
578 |
|
579 return KErrNone; |
|
580 |
|
581 } |
|
582 // --------------------------------------------------------------------------- |
|
583 // CFsMtmClient::CreateAccountL |
|
584 // This functions will be called by FS Email server every time a FS account is |
|
585 // is created. For every FS account one MTM account will be created. |
|
586 // --------------------------------------------------------------------------- |
|
587 // |
|
588 TInt CFsMtmClient::CreateAccountL(const TDesC& aAccountName, |
|
589 const TDesC& aOwnAddress, TFSMailMsgId aMsgId) |
|
590 { |
|
591 FUNC_LOG; |
|
592 |
|
593 HBufC* accountName = aAccountName.AllocL(); |
|
594 // +accountName |
|
595 CleanupStack::PushL( accountName ); |
|
596 HBufC* ownAddress = aOwnAddress.AllocL(); |
|
597 // +ownAddress |
|
598 CleanupStack::PushL( ownAddress ); |
|
599 |
|
600 // First phase - create Freestyle account |
|
601 CMsvEntry* root = CMsvEntry::NewL( Session(), KMsvRootIndexEntryId, |
|
602 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) ); |
|
603 // +root |
|
604 CleanupStack::PushL( root ); |
|
605 |
|
606 // Check if account Already exists with this name |
|
607 TBool accountExitsAlready = EFalse; |
|
608 TMsvEntry newAccount; |
|
609 CMsvEntrySelection* childSelection = root->ChildrenWithMtmL( |
|
610 KUidMsgValTypeFsMtmVal ); |
|
611 // childSelection |
|
612 CleanupStack::PushL( childSelection ); |
|
613 for ( TInt i = 0; i < childSelection->Count(); i++ ) |
|
614 { |
|
615 root->SetEntryL( childSelection->At( i ) ); |
|
616 TUint pluginId = root->Entry().MtmData1(); |
|
617 TUint mailboxId = root->Entry().MtmData2(); |
|
618 // Plugin id and Mailbox id are used instead of account name check |
|
619 // because names does not match in case of branded mailbox |
|
620 if ( pluginId == aMsgId.PluginId().iUid && mailboxId == aMsgId.Id() ) |
|
621 { |
|
622 // newAccount = root->Entry(); |
|
623 iAccountId = root->Entry().Id(); |
|
624 accountExitsAlready = ETrue; |
|
625 break; |
|
626 } |
|
627 } |
|
628 if ( !accountExitsAlready ) |
|
629 { |
|
630 root->SetEntryL( KMsvRootIndexEntryId ); |
|
631 newAccount.iMtm = KUidMsgValTypeFsMtmVal; |
|
632 newAccount.iType = KUidMsvServiceEntry; |
|
633 newAccount.iServiceId = KMsvNullIndexEntryId; |
|
634 newAccount.iDate.HomeTime(); |
|
635 newAccount.iDetails.Set( *accountName ); |
|
636 newAccount.iDescription.Set( *ownAddress ); |
|
637 |
|
638 TUid pluginId = aMsgId.PluginId(); |
|
639 TUint id = aMsgId.Id(); |
|
640 // Store the plugin id and mailbox id. |
|
641 newAccount.iMtmData1 = pluginId.iUid; |
|
642 newAccount.iMtmData2 = id; |
|
643 |
|
644 FeatureManager::InitializeLibL(); |
|
645 if (FeatureManager::FeatureSupported(KFeatureIdEmailMceIntegration)) |
|
646 { |
|
647 newAccount.SetVisible( ETrue ); |
|
648 } |
|
649 else |
|
650 { |
|
651 newAccount.SetVisible( EFalse ); |
|
652 } |
|
653 FeatureManager::UnInitializeLib(); |
|
654 |
|
655 root->CreateL( newAccount ); |
|
656 iAccountId = newAccount.Id(); |
|
657 root->SetEntryL( iAccountId ); |
|
658 |
|
659 this->ChangeDefaultServiceL( iAccountId ); |
|
660 } |
|
661 // accountName, ownAddress, root, childSelection |
|
662 CleanupStack::PopAndDestroy( childSelection ); //SCANNER |
|
663 CleanupStack::PopAndDestroy( root ); |
|
664 CleanupStack::PopAndDestroy( ownAddress ); |
|
665 CleanupStack::PopAndDestroy( accountName ); |
|
666 |
|
667 delete iAccountEntry; |
|
668 iAccountEntry = NULL; |
|
669 iAccountEntry = CMsvEntry::NewL( Session(), iAccountId, |
|
670 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) ); |
|
671 SwitchCurrentEntryL( iAccountId ); |
|
672 return KErrNone; |
|
673 } |
|
674 |
|
675 // --------------------------------------------------------------------------- |
|
676 // CFsMtmClient::DeleteAccountL |
|
677 // This functions will be called by FS Email server every time a FS account is |
|
678 // deleted. For every FS account one MTM account will be existing. |
|
679 // Remove unused parameter aAccountName |
|
680 // --------------------------------------------------------------------------- |
|
681 // |
|
682 |
|
683 TInt CFsMtmClient::DeleteAccountL(const TDesC& aAccountName, |
|
684 TFSMailMsgId aMsgId) |
|
685 { |
|
686 FUNC_LOG; |
|
687 iAccountId = NULL; |
|
688 // Set iAccountId and iAccountEntry with proper values |
|
689 SetTMsvIdsL( aAccountName, aMsgId ); |
|
690 // Its done in this way because, else there will be panic MSGS:294 while doing |
|
691 // iMsvEntry->DeleteL operation. |
|
692 iMsvEntry->SetEntryL( KMsvRootIndexEntryId ); |
|
693 if( iAccountId ) |
|
694 { |
|
695 delete iAccountEntry; |
|
696 iAccountEntry = NULL; |
|
697 iMsvEntry->DeleteL( iAccountId ); |
|
698 } |
|
699 |
|
700 // Reset the AccountId to Null so that future calls to the |
|
701 // SetTMsvIdsL will create the account. |
|
702 iAccountId = NULL; |
|
703 |
|
704 return KErrNone; |
|
705 } |
|
706 |
|
707 |
|
708 // --------------------------------------------------------------------------- |
|
709 // CFsMtmClient::RenameAccountL |
|
710 // This functions will be called by FS Email server every time a FS account is |
|
711 // renamed. For every FS account one MTM account will be existing. The |
|
712 // existing is deleted and another account is created with different name. |
|
713 // --------------------------------------------------------------------------- |
|
714 // |
|
715 TInt CFsMtmClient::RenameAccountL( const TDesC& aAccountNewName, |
|
716 const TDesC& aOwnAddress, TFSMailMsgId aMsgId) |
|
717 { |
|
718 FUNC_LOG; |
|
719 CMsvEntry* root = CMsvEntry::NewL( Session(), KMsvRootIndexEntryId, |
|
720 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) ); |
|
721 |
|
722 CleanupStack::PushL( root ); |
|
723 |
|
724 // Get Freestyle services. |
|
725 CMsvEntrySelection* childSelection = root->ChildrenWithMtmL( |
|
726 KUidMsgValTypeFsMtmVal ); |
|
727 CleanupStack::PushL( childSelection ); |
|
728 |
|
729 // Find Freestyle Service. |
|
730 for( TInt i = 0; i < childSelection->Count(); i++ ) |
|
731 { |
|
732 root->SetEntryL( childSelection->At( i ) ); |
|
733 if ( root->Entry().iMtmData1 == aMsgId.PluginId().iUid && |
|
734 root->Entry().iMtmData2 == aMsgId.Id()) |
|
735 { |
|
736 TMsvEntry& tEntry = CONST_CAST( TMsvEntry&, root->Entry() ); |
|
737 if ( aAccountNewName != KNullDesC && tEntry.iDetails != aAccountNewName ) |
|
738 { |
|
739 // Operation is mailbox name change. |
|
740 // We end up here when TFSEventMailboxRenamed event is received by server. |
|
741 tEntry.iDetails.Set( *aAccountNewName.AllocL() ); |
|
742 } |
|
743 if ( aOwnAddress != KNullDesC && tEntry.iDescription != aOwnAddress ) |
|
744 { |
|
745 // Operation is owner email address change. |
|
746 // We end up here when TFSEventMailboxSettingsChanged event is received by server. |
|
747 tEntry.iDescription.Set( *aOwnAddress.AllocL() ); |
|
748 } |
|
749 root->ChangeL( tEntry ); |
|
750 break; |
|
751 } |
|
752 } |
|
753 CleanupStack::PopAndDestroy( childSelection );//SCANNER |
|
754 CleanupStack::PopAndDestroy( root ); |
|
755 return KErrNone; |
|
756 } |
|
757 |
|
758 // --------------------------------------------------------------------------- |
|
759 // CFsMtmClient::SetTMsvIdsL |
|
760 // Set the iAccountId and iAccountEntry to the entry that need to be deleted. |
|
761 // --------------------------------------------------------------------------- |
|
762 // |
|
763 void CFsMtmClient::SetTMsvIdsL(const TDesC& /*aAccountName*/, |
|
764 TFSMailMsgId aMsgId) |
|
765 { |
|
766 FUNC_LOG; |
|
767 |
|
768 CMsvEntry* root = CMsvEntry::NewL( Session(), KMsvRootIndexEntryId, |
|
769 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) ); |
|
770 |
|
771 CleanupStack::PushL( root ); |
|
772 |
|
773 // Check if account Already exist |
|
774 TMsvEntry newAccount; |
|
775 |
|
776 // Get Freestyle services. |
|
777 CMsvEntrySelection* childSelection = root->ChildrenWithMtmL( |
|
778 KUidMsgValTypeFsMtmVal ); |
|
779 CleanupStack::PushL( childSelection ); |
|
780 |
|
781 // Find Freestyle Service. |
|
782 for( TInt i = 0; i < childSelection->Count(); i++ ) |
|
783 { |
|
784 root->SetEntryL( childSelection->At( i ) ); |
|
785 |
|
786 if ( root->Entry().iMtmData1 == aMsgId.PluginId().iUid && |
|
787 root->Entry().iMtmData2 == aMsgId.Id() ) |
|
788 { |
|
789 // newAccount = root->Entry(); |
|
790 iAccountId = root->Entry().Id(); |
|
791 delete iAccountEntry;//SCANNER |
|
792 iAccountEntry = NULL; |
|
793 iAccountEntry = CMsvEntry::NewL( Session(), iAccountId, |
|
794 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, |
|
795 ETrue )); |
|
796 break; |
|
797 } |
|
798 } |
|
799 |
|
800 CleanupStack::PopAndDestroy( childSelection ); //SCANNER |
|
801 CleanupStack::PopAndDestroy( root ); |
|
802 } |
|
803 |
|
804 // --------------------------------------------------------------------------- |
|
805 // CFsMtmClient::AddEmailAsAttachmentL |
|
806 // |
|
807 // --------------------------------------------------------------------------- |
|
808 // |
|
809 EXPORT_C TInt CFsMtmClient::AddEmailAsAttachmentL( const TUint& aPluginId, const TDesC& aAttachmentPath,TMsvId& aNewAttachEntryId ) |
|
810 { |
|
811 FUNC_LOG; |
|
812 |
|
813 if ( iEmailAttachedInEmail ) |
|
814 { |
|
815 TMsvId accountId; |
|
816 |
|
817 // Get S60 mailboxes |
|
818 CMsvEntry* root = CMsvEntry::NewL( Session(), KMsvRootIndexEntryId, |
|
819 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) ); |
|
820 CleanupStack::PushL( root ); |
|
821 |
|
822 // Go through MsvEntries |
|
823 // FS account doesn't exist. |
|
824 CMsvEntrySelection* childSelection = root->ChildrenWithMtmL( |
|
825 KUidMsgValTypeFsMtmVal ); |
|
826 CleanupStack::PushL( childSelection ); |
|
827 for ( TInt i = 0; i < childSelection->Count(); i++ ) |
|
828 { |
|
829 |
|
830 root->SetEntryL( childSelection->At( i ) ); |
|
831 TUint pluginId = root->Entry().MtmData1(); |
|
832 |
|
833 //find mailbox id matching the pluginid |
|
834 if(pluginId==aPluginId) |
|
835 { |
|
836 //mailboxId = root->Entry().MtmData2(); |
|
837 accountId =root->Entry().Id(); |
|
838 break; |
|
839 } |
|
840 } |
|
841 |
|
842 CleanupStack::PopAndDestroy( childSelection ); |
|
843 CleanupStack::PopAndDestroy( root ); |
|
844 |
|
845 //if KUidMsgValTypeFsMtmVal not found we leave |
|
846 if( accountId == 0 ) |
|
847 { |
|
848 User::Leave( KErrNotFound ); |
|
849 } |
|
850 |
|
851 CMsvEntrySelection* selection = new ( ELeave ) CMsvEntrySelection(); |
|
852 CleanupStack::PushL( selection ); |
|
853 selection->AppendL( accountId ); |
|
854 selection->AppendL( accountId ); |
|
855 |
|
856 //Call command |
|
857 TBuf8<256> tmp; |
|
858 tmp.Copy( aAttachmentPath ); |
|
859 |
|
860 InvokeSyncFunctionL( KEasEmailMTMAddEmailAttachment, *selection, tmp ) ; |
|
861 |
|
862 aNewAttachEntryId = iMTMAttachmentId; |
|
863 |
|
864 CleanupStack::PopAndDestroy( selection ); // selection |
|
865 } |
|
866 else |
|
867 { |
|
868 User::Leave( KErrNotSupported ); |
|
869 } |
|
870 |
|
871 return KErrNone; |
|
872 } |
|
873 |
|
874 // --------------------------------------------------------------------------- |
|
875 // CFsMtmClient::DeleteEmailAsAttachmentL |
|
876 // |
|
877 // --------------------------------------------------------------------------- |
|
878 // |
|
879 EXPORT_C TInt CFsMtmClient::DeleteEmailAsAttachmentL( const TMsvId aNewAttachEntryId ) |
|
880 { |
|
881 FUNC_LOG; |
|
882 |
|
883 if ( iEmailAttachedInEmail ) |
|
884 { |
|
885 TMsvId accountId; |
|
886 |
|
887 // Get S60 mailboxes |
|
888 CMsvEntry* root = CMsvEntry::NewL( Session(), KMsvRootIndexEntryId, |
|
889 TMsvSelectionOrdering( KMsvNoGrouping, EMsvSortByNone, ETrue ) ); |
|
890 CleanupStack::PushL( root ); |
|
891 |
|
892 // Go through MsvEntries |
|
893 // FS account doesn't exist. |
|
894 CMsvEntrySelection* childSelection = root->ChildrenWithMtmL( |
|
895 KUidMsgValTypeFsMtmVal ); |
|
896 CleanupStack::PushL( childSelection ); |
|
897 for ( TInt i = 0; i < childSelection->Count(); i++ ) |
|
898 { |
|
899 root->SetEntryL( childSelection->At( i ) ); |
|
900 TUint pluginId = root->Entry().MtmData1(); |
|
901 |
|
902 // find mailbox id matching the pluginid |
|
903 if ( pluginId == 0x2000B020 ) |
|
904 { |
|
905 //mailboxId = root->Entry().MtmData2(); |
|
906 accountId = root->Entry().Id(); |
|
907 break; |
|
908 } |
|
909 } |
|
910 |
|
911 CleanupStack::PopAndDestroy( childSelection ); |
|
912 CleanupStack::PopAndDestroy( root ); |
|
913 |
|
914 //if KUidMsgValTypeFsMtmVal not found we leave |
|
915 if ( accountId == 0 ) |
|
916 { |
|
917 User::Leave( KErrNotFound ); |
|
918 } |
|
919 |
|
920 CMsvEntrySelection* selection = new ( ELeave ) CMsvEntrySelection(); |
|
921 CleanupStack::PushL( selection ); |
|
922 selection->AppendL( accountId ); |
|
923 selection->AppendL( aNewAttachEntryId ); |
|
924 |
|
925 TPckgBuf<TBool> buf( ETrue ); |
|
926 |
|
927 // call command |
|
928 InvokeSyncFunctionL( KEasEmailMTMDeleteEntry, *selection, buf ); |
|
929 |
|
930 CleanupStack::PopAndDestroy( selection ); |
|
931 } |
|
932 else |
|
933 { |
|
934 User::Leave( KErrNotSupported ); |
|
935 } |
|
936 |
|
937 return KErrNone; |
|
938 } |
|
939 |
|
940 // End of file |