|
1 /* |
|
2 * Copyright (c) 2007-2009 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 for ESMR Email Manager |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include "cesmrfsemailmanager.h" |
|
20 |
|
21 #include <cmrmailboxutils.h> |
|
22 //<cmail> |
|
23 #include "CFSMailClient.h" |
|
24 #include "CFSMailBox.h" |
|
25 #include "CFSMailMessage.h" |
|
26 #include "CFSMailMessagePart.h" |
|
27 #include "mmrinfoprocessor.h" |
|
28 #include "CFSMailCommon.h" |
|
29 #include "CFSMailPlugin.h" |
|
30 //</cmail> |
|
31 #include <implementationinformation.h> |
|
32 #include "tesmrinputparams.h" |
|
33 #include "esmrconfig.hrh" |
|
34 #include "esmrhelper.h" |
|
35 #include "esmrinternaluid.h" |
|
36 |
|
37 // Unnamed namespace for local definitions |
|
38 namespace { |
|
39 |
|
40 // Definition for mime types |
|
41 _LIT(KMimeTextCalRequest, "text/calendar; method=REQUEST; name=\"meeting.ics\""); |
|
42 _LIT(KMimeTextCalResponse, "text/calendar; method=RESPONSE; name=\"response.ics\""); |
|
43 _LIT(KMimeTextCalCancel, "text/calendar; method=CANCEL; name=\"cancel.ics\""); |
|
44 _LIT(KMimeTextCalContentClass, "urn:content-classes:calendarmessage" ); |
|
45 |
|
46 // Definition for temporary calendar file |
|
47 //<cmail> hardcoded paths removal |
|
48 //_LIT(KFileAndPath, "c:\\temp\\temp.ics"); //codescanner::driveletters |
|
49 _LIT(KTempFileName, "temp\\temp.ics"); |
|
50 //</cmail> |
|
51 |
|
52 // Definition for email address comparison |
|
53 const TInt KEqualEmailAddress(0); |
|
54 |
|
55 // Definition for first index |
|
56 const TInt KFirstIndex(0); |
|
57 |
|
58 /** |
|
59 * Cleanup operations for RPointerArray. |
|
60 * |
|
61 * @param aArray Pointer to RPointerArray. |
|
62 */ |
|
63 void MessagePartPointerArrayCleanup( TAny* aArray ) |
|
64 { |
|
65 RPointerArray<CFSMailMessagePart>* messagePartArray = |
|
66 static_cast<RPointerArray<CFSMailMessagePart>*>( aArray ); |
|
67 |
|
68 messagePartArray->ResetAndDestroy(); |
|
69 messagePartArray->Close(); |
|
70 } |
|
71 |
|
72 #ifdef _DEBUG |
|
73 |
|
74 // Definition for panic text |
|
75 _LIT( KEMailManagerPanicTxt, "EMailManager" ); |
|
76 |
|
77 /** Enumeration for email manager panic codes */ |
|
78 enum TESMREMailManagerPanic |
|
79 { |
|
80 EESMRMailboxNotFound = 0, |
|
81 EESMRMailClientNotExist, |
|
82 EESMRMessageNotExist, |
|
83 EESMRInvalidCalMethod |
|
84 }; |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Panic wrapper method |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void Panic( TESMREMailManagerPanic aPanic ) |
|
91 { |
|
92 |
|
93 User::Panic( KEMailManagerPanicTxt, aPanic ); |
|
94 } |
|
95 |
|
96 #endif // _DEBUG |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // Leave wrapper method |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 inline void DoLeaveIfErrorL( TInt aLeaveCode ) |
|
103 { |
|
104 if ( KErrNone != aLeaveCode ) |
|
105 { |
|
106 |
|
107 User::Leave( aLeaveCode ); |
|
108 } |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Cleanup operation for RPointerArray. |
|
113 // @param aArray Pointer to RPointerArray. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void MailboxPointerArrayCleanup( TAny* aArray ) |
|
117 { |
|
118 RPointerArray<CFSMailBox>* entryArray = |
|
119 static_cast<RPointerArray<CFSMailBox>*>( aArray ); |
|
120 |
|
121 entryArray->ResetAndDestroy(); |
|
122 entryArray->Close(); |
|
123 } |
|
124 } // namespace |
|
125 |
|
126 |
|
127 // ======== MEMBER FUNCTIONS ======== |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CESMRFSEMailManager::CESMRFSEMailManager |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 inline CESMRFSEMailManager::CESMRFSEMailManager( |
|
134 CMRMailboxUtils& aMRMailboxUtils ) |
|
135 : iMRMailboxUtils( aMRMailboxUtils ) |
|
136 { |
|
137 FUNC_LOG; |
|
138 //do nothing |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CESMRFSEMailManager::§CESMRFSEMailManager |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 CESMRFSEMailManager::~CESMRFSEMailManager() |
|
146 { |
|
147 FUNC_LOG; |
|
148 delete iParentPart; |
|
149 delete iMessage; |
|
150 delete iMailBox; |
|
151 if ( iMailClient ) |
|
152 { |
|
153 iMailClient->Close(); |
|
154 iMailClient = NULL; |
|
155 } |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CESMRFSEMailManager::NewL |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 CESMRFSEMailManager* CESMRFSEMailManager::NewL( |
|
163 CMRMailboxUtils& aMRMailboxUtils ) |
|
164 { |
|
165 FUNC_LOG; |
|
166 |
|
167 CESMRFSEMailManager* self = |
|
168 new (ELeave) CESMRFSEMailManager(aMRMailboxUtils); |
|
169 CleanupStack::PushL(self); |
|
170 self->ConstructL(); |
|
171 CleanupStack::Pop(self); |
|
172 |
|
173 |
|
174 return self; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CESMRFSEMailManager::ConstructL |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CESMRFSEMailManager::ConstructL() |
|
182 { |
|
183 FUNC_LOG; |
|
184 //do nothing |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CESMRFSEMailManager::PrepareForSendingL |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CESMRFSEMailManager::PrepareForSendingL( |
|
192 const TDesC& aMailboxOwnerAddr ) |
|
193 { |
|
194 FUNC_LOG; |
|
195 |
|
196 iMailClient = CFSMailClient::NewL(); |
|
197 |
|
198 TPtrC emailAddr( |
|
199 ESMRHelper::AddressWithoutMailtoPrefix( aMailboxOwnerAddr ) ); |
|
200 |
|
201 iMailBox = SelectMailBoxL( emailAddr ); |
|
202 iMessage = CreateMessageL(); |
|
203 iParentPart = CreateParentPartL(); |
|
204 |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // CESMRFSEMailManager::PrepareForSendingreplyL |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 void CESMRFSEMailManager::PrepareForSendingReplyL( |
|
212 const TDesC& aMailboxOwnerAddr, const TFSMailMsgId& aMsgId, TBool aReplyAll ) |
|
213 { |
|
214 FUNC_LOG; |
|
215 |
|
216 iMailClient = CFSMailClient::NewL(); |
|
217 |
|
218 TPtrC emailAddr( |
|
219 ESMRHelper::AddressWithoutMailtoPrefix( aMailboxOwnerAddr ) ); |
|
220 |
|
221 iMailBox = SelectMailBoxL( emailAddr ); |
|
222 |
|
223 iMessage = iMailBox->CreateReplyMessage(aMsgId, aReplyAll ); |
|
224 |
|
225 iParentPart = CreateParentPartL(); |
|
226 |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // CESMRFSEMailManager::SetSenderL |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CESMRFSEMailManager::SetSenderL( |
|
235 const TDesC& aAddress, |
|
236 const TDesC& aCommonName ) |
|
237 { |
|
238 FUNC_LOG; |
|
239 |
|
240 CFSMailAddress* sender = CFSMailAddress::NewLC(); |
|
241 |
|
242 TPtrC emailAddr( |
|
243 ESMRHelper::AddressWithoutMailtoPrefix( aAddress ) ); |
|
244 |
|
245 sender->SetEmailAddress( emailAddr ); |
|
246 sender->SetDisplayName( aCommonName ); |
|
247 iMessage->SetSender( sender ); // takes ownership |
|
248 CleanupStack::Pop( sender ); |
|
249 |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // CESMRFSEMailManager::SetReplyToAddressL |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CESMRFSEMailManager::SetReplyToAddressL( |
|
257 const TDesC& aAddress, |
|
258 const TDesC& aCommonName ) |
|
259 { |
|
260 FUNC_LOG; |
|
261 |
|
262 CFSMailAddress* replyToAddress = CFSMailAddress::NewLC(); |
|
263 |
|
264 TPtrC emailAddr( |
|
265 ESMRHelper::AddressWithoutMailtoPrefix( aAddress ) ); |
|
266 |
|
267 replyToAddress->SetEmailAddress( emailAddr ); |
|
268 replyToAddress->SetDisplayName( aCommonName ); |
|
269 iMessage->SetReplyToAddress( replyToAddress ); // takes ownership |
|
270 CleanupStack::Pop( replyToAddress ); |
|
271 |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CESMRFSEMailManager::AppendToRecipientL |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void CESMRFSEMailManager::AppendToRecipientL( |
|
279 const TDesC& aAddress, |
|
280 const TDesC& aCommonName ) |
|
281 { |
|
282 FUNC_LOG; |
|
283 |
|
284 CFSMailAddress* toRecipient = CFSMailAddress::NewLC(); |
|
285 |
|
286 TPtrC emailAddr( |
|
287 ESMRHelper::AddressWithoutMailtoPrefix( aAddress ) ); |
|
288 |
|
289 toRecipient->SetEmailAddress( emailAddr ); |
|
290 toRecipient->SetDisplayName( aCommonName ); |
|
291 iMessage->AppendToRecipient( toRecipient ); // takes ownership |
|
292 CleanupStack::Pop( toRecipient ); |
|
293 |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // CESMRFSEMailManager::AppendCCRecipientL |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 void CESMRFSEMailManager::AppendCCRecipientL( |
|
301 const TDesC& aAddress, |
|
302 const TDesC& aCommonName ) |
|
303 { |
|
304 FUNC_LOG; |
|
305 |
|
306 CFSMailAddress* ccRecipient = CFSMailAddress::NewLC(); |
|
307 |
|
308 TPtrC emailAddr( |
|
309 ESMRHelper::AddressWithoutMailtoPrefix( aAddress ) ); |
|
310 |
|
311 ccRecipient->SetEmailAddress( emailAddr ); |
|
312 ccRecipient->SetDisplayName( aCommonName ); |
|
313 iMessage->AppendCCRecipient( ccRecipient ); // takes ownership |
|
314 CleanupStack::Pop( ccRecipient ); |
|
315 |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // CESMRFSEMailManager::SetSubjectL |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CESMRFSEMailManager::SetSubjectL(const TDesC& aSubject) |
|
323 { |
|
324 FUNC_LOG; |
|
325 |
|
326 iMessage->SetSubject( aSubject ); |
|
327 |
|
328 } |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // CESMRFSEMailManager::CreateTextPlainPartL |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 void CESMRFSEMailManager::CreateTextPlainPartL(const TDesC& aPlainText) |
|
335 { |
|
336 FUNC_LOG; |
|
337 |
|
338 AddPlainTextPartL( aPlainText ); |
|
339 |
|
340 } |
|
341 |
|
342 // --------------------------------------------------------------------------- |
|
343 // CESMRFSEMailManager::CreateTextCalendarPartL |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 void CESMRFSEMailManager::CreateTextCalendarPartL( |
|
347 TESMRMethod aCalendarMethod ) |
|
348 { |
|
349 FUNC_LOG; |
|
350 //<cmail> removing hardcoded paths |
|
351 TFileName fileName(KTempFileName); |
|
352 User::LeaveIfError(ESMRHelper::CreateAndAppendPrivateDirToFileName(fileName)); |
|
353 CreateTextCalendarPartL( aCalendarMethod, fileName ); |
|
354 //</cmail> |
|
355 |
|
356 } |
|
357 |
|
358 // --------------------------------------------------------------------------- |
|
359 // CESMRFSEMailManager::CreateTextCalendarPartL |
|
360 // --------------------------------------------------------------------------- |
|
361 // |
|
362 void CESMRFSEMailManager::CreateTextCalendarPartL( |
|
363 TESMRMethod aCalendarMethod, |
|
364 const TDesC& aFilename ) |
|
365 { |
|
366 FUNC_LOG; |
|
367 |
|
368 TPtrC contentType; |
|
369 switch ( aCalendarMethod ) |
|
370 { |
|
371 case EESMRMethodRequest: |
|
372 { |
|
373 contentType.Set(KMimeTextCalRequest()); |
|
374 } |
|
375 break; |
|
376 |
|
377 case EESMRMethodResponse: |
|
378 { |
|
379 contentType.Set(KMimeTextCalResponse()); |
|
380 } |
|
381 break; |
|
382 |
|
383 case EESMRMethodCancel: |
|
384 { |
|
385 contentType.Set(KMimeTextCalCancel()); |
|
386 } |
|
387 break; |
|
388 |
|
389 default: |
|
390 __ASSERT_DEBUG( EFalse, Panic(EESMRInvalidCalMethod) ); |
|
391 } |
|
392 |
|
393 AddMessagePartFromFileL( |
|
394 contentType, |
|
395 KMimeTextCalContentClass, |
|
396 KNullDesC(), |
|
397 KNullDesC(), |
|
398 aFilename ); |
|
399 |
|
400 } |
|
401 |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // CESMRFSEMailManager::SetAttachmentL |
|
405 // --------------------------------------------------------------------------- |
|
406 // |
|
407 void CESMRFSEMailManager::SetAttachmentL(const TDesC& aAttachmentFile ) |
|
408 { |
|
409 FUNC_LOG; |
|
410 |
|
411 TFSMailMsgId nullId; |
|
412 CFSMailMessagePart* attachmentPart = |
|
413 iMessage->AddNewAttachmentL(aAttachmentFile, nullId ); |
|
414 CleanupStack::PushL( attachmentPart ); |
|
415 attachmentPart->SaveL(); |
|
416 iMessage->SaveMessageL(); |
|
417 |
|
418 CleanupStack::PopAndDestroy( attachmentPart ); |
|
419 |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // CESMRFSEMailManager::StoreMessageL |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 TInt CESMRFSEMailManager::StoreMessageToDraftsFolderL() |
|
427 { |
|
428 FUNC_LOG; |
|
429 // Stores message automatically to drafts folder |
|
430 // check that msg is not in drafts folder already |
|
431 TFSMailMsgId draftsFolderId = |
|
432 iMailBox->GetStandardFolderId( EFSDraftsFolder ); |
|
433 TFSMailMsgId msgFolderId = iMessage->GetFolderId(); |
|
434 if ( draftsFolderId != msgFolderId ) |
|
435 { |
|
436 RArray<TFSMailMsgId> ids; |
|
437 CleanupClosePushL( ids ); |
|
438 ids.Append( iMessage->GetMessageId() ); |
|
439 iMailBox->MoveMessagesL( ids, msgFolderId, draftsFolderId ); |
|
440 CleanupStack::PopAndDestroy(); // ids |
|
441 } |
|
442 |
|
443 iMessage->SaveMessageL(); |
|
444 return KErrNone; |
|
445 } |
|
446 |
|
447 // --------------------------------------------------------------------------- |
|
448 // CESMRFSEMailManager::SendMessageL |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 TInt CESMRFSEMailManager::SendMessageL() |
|
452 { |
|
453 FUNC_LOG; |
|
454 |
|
455 TRAPD( ret, iMailBox->SendMessageL( *iMessage ) ); |
|
456 |
|
457 |
|
458 return ret; |
|
459 } |
|
460 |
|
461 // --------------------------------------------------------------------------- |
|
462 // CESMRFSEMailManager::MailboxId |
|
463 // --------------------------------------------------------------------------- |
|
464 // |
|
465 TFSMailMsgId CESMRFSEMailManager::MailboxId() const |
|
466 { |
|
467 FUNC_LOG; |
|
468 return iMailBox->GetId(); |
|
469 } |
|
470 |
|
471 // --------------------------------------------------------------------------- |
|
472 // CESMRFSEMailManager::SendMailViaSyncL |
|
473 // --------------------------------------------------------------------------- |
|
474 // |
|
475 void CESMRFSEMailManager::SendMailViaSyncL( |
|
476 TESMRInputParams& aParams, |
|
477 MMRInfoObject& aInfoObject, |
|
478 MMRInfoProcessor::TMRInfoResponseMode aResponseMode, |
|
479 const TDesC& aFreeResponseText ) |
|
480 { |
|
481 FUNC_LOG; |
|
482 |
|
483 CFSMailBox* mailBox = |
|
484 aParams.iMailClient->GetMailBoxByUidL( |
|
485 aParams.iMailMessage->GetMailBoxId() ); |
|
486 CleanupStack::PushL( mailBox ); |
|
487 |
|
488 if ( mailBox->IsMRInfoProcessorSet() ) |
|
489 { |
|
490 MMRInfoProcessor& infoProcessor( |
|
491 mailBox->MRInfoProcessorL() ); |
|
492 |
|
493 |
|
494 TRAPD(err, { |
|
495 infoProcessor.ReplyToMeetingRequestL( |
|
496 aParams.iMailMessage->GetMailBoxId(), |
|
497 aParams.iMailMessage->GetMessageId(), |
|
498 aInfoObject, |
|
499 aResponseMode, |
|
500 aFreeResponseText ); |
|
501 } ); |
|
502 |
|
503 |
|
504 |
|
505 User::LeaveIfError( err ); |
|
506 } |
|
507 |
|
508 CleanupStack::PopAndDestroy( mailBox ); |
|
509 |
|
510 } |
|
511 |
|
512 // --------------------------------------------------------------------------- |
|
513 // CESMRFSEMailManager::MessageId |
|
514 // --------------------------------------------------------------------------- |
|
515 // |
|
516 TFSMailMsgId CESMRFSEMailManager::MessageId() const |
|
517 { |
|
518 FUNC_LOG; |
|
519 __ASSERT_DEBUG( iMessage, Panic(EESMRMessageNotExist) ); |
|
520 return iMessage->GetMessageId(); |
|
521 } |
|
522 |
|
523 // --------------------------------------------------------------------------- |
|
524 // CESMRFSEMailManager::MessageFolderId |
|
525 // --------------------------------------------------------------------------- |
|
526 // |
|
527 TFSMailMsgId CESMRFSEMailManager::MessageFolderId() const |
|
528 { |
|
529 FUNC_LOG; |
|
530 __ASSERT_DEBUG( iMessage, Panic(EESMRMessageNotExist) ); |
|
531 return iMessage->GetFolderId(); |
|
532 } |
|
533 |
|
534 // --------------------------------------------------------------------------- |
|
535 // CESMRFSEMailManager::CreateMessageL |
|
536 // --------------------------------------------------------------------------- |
|
537 // |
|
538 CFSMailMessage* CESMRFSEMailManager::CreateMessageL() |
|
539 { |
|
540 FUNC_LOG; |
|
541 |
|
542 CFSMailMessage* msg = iMailBox->CreateMessageToSend(); |
|
543 |
|
544 msg->SetFlag( EFSMsgFlag_CalendarMsg ); |
|
545 msg->SaveMessageL(); |
|
546 |
|
547 return msg; |
|
548 } |
|
549 |
|
550 // --------------------------------------------------------------------------- |
|
551 // CESMRFSEMailManager::CreateParentPartL |
|
552 // --------------------------------------------------------------------------- |
|
553 // |
|
554 CFSMailMessagePart* CESMRFSEMailManager::CreateParentPartL() |
|
555 { |
|
556 FUNC_LOG; |
|
557 __ASSERT_DEBUG( iMessage, Panic(EESMRMessageNotExist) ); |
|
558 |
|
559 CFSMailMessagePart* parent = NULL; |
|
560 RPointerArray<CFSMailMessagePart> messageParts; |
|
561 CleanupStack::PushL( |
|
562 TCleanupItem( |
|
563 MessagePartPointerArrayCleanup, |
|
564 &messageParts ) ); |
|
565 |
|
566 iMessage->ChildPartsL( messageParts ); |
|
567 |
|
568 if( messageParts.Count() ) |
|
569 { |
|
570 parent = messageParts[ KFirstIndex ]; |
|
571 messageParts.Remove( KFirstIndex ); |
|
572 } |
|
573 else |
|
574 { |
|
575 // Message does not contain body part --> Create it |
|
576 TFSMailMsgId id; |
|
577 parent = iMessage->NewChildPartL( |
|
578 id, |
|
579 KFSMailContentTypeMultipartAlternative ); |
|
580 } |
|
581 |
|
582 CleanupStack::PopAndDestroy(); // messageParts |
|
583 CleanupStack::PushL( parent ); |
|
584 |
|
585 parent->SetContentType( KFSMailContentTypeMultipartAlternative ); |
|
586 parent->SaveL(); |
|
587 iMessage->SaveMessageL(); |
|
588 |
|
589 CleanupStack::Pop( parent ); |
|
590 return parent; |
|
591 } |
|
592 |
|
593 // --------------------------------------------------------------------------- |
|
594 // CESMRFSEMailManager::SelectMailBoxL |
|
595 // --------------------------------------------------------------------------- |
|
596 // |
|
597 CFSMailBox* CESMRFSEMailManager::SelectMailBoxL( |
|
598 const TDesC& aMailboxOwnerAddr ) |
|
599 { |
|
600 FUNC_LOG; |
|
601 |
|
602 __ASSERT_DEBUG( iMailClient, Panic(EESMRMailClientNotExist) ); |
|
603 |
|
604 CFSMailBox* mailbox = NULL; |
|
605 |
|
606 // Loop throug all mailboxes in this plug-in |
|
607 RPointerArray<CFSMailBox> mailboxes; |
|
608 CleanupStack::PushL( |
|
609 TCleanupItem( |
|
610 MailboxPointerArrayCleanup, |
|
611 &mailboxes ) ); |
|
612 |
|
613 // With null uid we get all mailboxes |
|
614 TFSMailMsgId msgId; |
|
615 iMailClient->ListMailBoxes( |
|
616 msgId, mailboxes ); |
|
617 |
|
618 TInt mailboxCount( mailboxes.Count() ); |
|
619 for (TInt j(0); j < mailboxCount && !mailbox; ++j ) |
|
620 { |
|
621 TPtrC mailboxOwnerAddName( |
|
622 mailboxes[j]->OwnMailAddress().GetEmailAddress() ); |
|
623 if ( KEqualEmailAddress == mailboxOwnerAddName.CompareF(aMailboxOwnerAddr) ) |
|
624 { |
|
625 // Correct mailbox is found |
|
626 mailbox = mailboxes[j]; |
|
627 mailboxes.Remove(j); |
|
628 } |
|
629 } |
|
630 CleanupStack::PopAndDestroy( &mailboxes ); |
|
631 |
|
632 __ASSERT_DEBUG( mailbox, Panic(EESMRMailboxNotFound) ); |
|
633 |
|
634 if ( !mailbox ) |
|
635 { |
|
636 DoLeaveIfErrorL( KErrNotFound ); |
|
637 } |
|
638 |
|
639 |
|
640 return mailbox; |
|
641 } |
|
642 |
|
643 // --------------------------------------------------------------------------- |
|
644 // CESMRFSEMailManager::AddMessagePartFromFileL |
|
645 // --------------------------------------------------------------------------- |
|
646 // |
|
647 void CESMRFSEMailManager::AddMessagePartFromFileL( |
|
648 const TDesC& aContentType, |
|
649 const TDesC& aContentClass, |
|
650 const TDesC& aContentDescription, |
|
651 const TDesC& aContentDisposition, |
|
652 const TDesC& aFileAndPath ) |
|
653 { |
|
654 FUNC_LOG; |
|
655 |
|
656 __ASSERT_DEBUG( iParentPart, Panic(EESMRMessageNotExist) ); |
|
657 |
|
658 TFSMailMsgId nullId; |
|
659 |
|
660 CFSMailMessagePart* messagePart = |
|
661 iParentPart->AddNewAttachmentL( |
|
662 aFileAndPath, |
|
663 nullId, |
|
664 aContentType ); |
|
665 |
|
666 CleanupStack::PushL( messagePart ); |
|
667 |
|
668 messagePart->SetMailBoxId( iMailBox->GetId() ); |
|
669 messagePart->SetContentDescription( KNullDesC() ); |
|
670 messagePart->SetContentType( KNullDesC() ); |
|
671 messagePart->SetContentDisposition( KNullDesC() ); |
|
672 messagePart->SetContentClass( KNullDesC() ); |
|
673 |
|
674 if ( aContentType.Length() ) |
|
675 { |
|
676 messagePart->SetContentType( aContentType ); |
|
677 } |
|
678 |
|
679 if ( aContentDescription.Length() ) |
|
680 { |
|
681 messagePart->SetContentDescription( aContentDescription ); |
|
682 } |
|
683 |
|
684 if ( aContentDisposition.Length() ) |
|
685 { |
|
686 messagePart->SetContentDisposition( aContentDisposition ); |
|
687 } |
|
688 |
|
689 if ( aContentClass.Length() ) |
|
690 { |
|
691 messagePart->SetContentClass( aContentClass ); |
|
692 } |
|
693 |
|
694 messagePart->SaveL(); |
|
695 iMessage->SaveMessageL(); |
|
696 |
|
697 CleanupStack::PopAndDestroy( messagePart ); |
|
698 |
|
699 } |
|
700 // --------------------------------------------------------------------------- |
|
701 // CESMRFSEMailManager::AddPlainTextPartL |
|
702 // --------------------------------------------------------------------------- |
|
703 // |
|
704 void CESMRFSEMailManager::AddPlainTextPartL( |
|
705 const TDesC& aContent ) |
|
706 { |
|
707 FUNC_LOG; |
|
708 TFSMailMsgId id; |
|
709 CFSMailMessagePart* plainTextPart = |
|
710 iParentPart->FindBodyPartL(KFSMailContentTypeTextPlain); |
|
711 |
|
712 if ( !plainTextPart ) |
|
713 { |
|
714 // text/plain part does not exist --> Create it to body part |
|
715 plainTextPart = |
|
716 iParentPart->NewChildPartL(id, KFSMailContentTypeTextPlain ); |
|
717 } |
|
718 |
|
719 CleanupStack::PushL( plainTextPart ); |
|
720 |
|
721 plainTextPart->SetMailBoxId( iMailBox->GetId() ); |
|
722 |
|
723 TUint currentContentSize = plainTextPart->ContentSize(); |
|
724 TUint contentBufferSize = currentContentSize + aContent.Length(); |
|
725 |
|
726 // Buffer for current content |
|
727 HBufC* currentContentBuffer = HBufC::NewLC( currentContentSize ); |
|
728 TPtr currentContent( currentContentBuffer->Des() ); |
|
729 |
|
730 // Buffer for content containing calendar information and current content |
|
731 HBufC* contentBuffer = HBufC::NewLC( contentBufferSize ); |
|
732 TPtr content( contentBuffer->Des() ); |
|
733 |
|
734 // Appending calendar information to content |
|
735 content.Copy( aContent ); |
|
736 if ( currentContentSize ) |
|
737 { |
|
738 // Appending current content if needed |
|
739 plainTextPart->GetContentToBufferL( currentContent, 0 ); |
|
740 content.Append( currentContent ); |
|
741 } |
|
742 |
|
743 plainTextPart->SetContent(content); |
|
744 CleanupStack::PopAndDestroy( contentBuffer ); contentBuffer = NULL; |
|
745 CleanupStack::PopAndDestroy( currentContentBuffer ); currentContentBuffer = NULL; |
|
746 |
|
747 plainTextPart->SaveL(); |
|
748 iMessage->SaveMessageL(); |
|
749 |
|
750 CleanupStack::PopAndDestroy( plainTextPart ); |
|
751 |
|
752 } |
|
753 |
|
754 // EOF |
|
755 |