|
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 send MR via fs email task |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cesmrsendmrfsmailtask.h" |
|
20 |
|
21 #include "cesmrcaldbmgr.h" |
|
22 #include "mesmrmeetingrequestentry.h" |
|
23 #include "cesmrfsemailmanager.h" |
|
24 #include "cesmrmailplaitextformatter.h" |
|
25 #include "cesmrcalimportexporter.h" |
|
26 #include "cesmrcaluserutil.h" |
|
27 #include "cesmrguilistquery.h" |
|
28 #include "esmrhelper.h" |
|
29 #include "cesmrfsmailboxutils.h" |
|
30 |
|
31 #include <coemain.h> |
|
32 #include <utf.h> |
|
33 #include <bautils.h> |
|
34 #include <caluser.h> |
|
35 #include <cmrmailboxutils.h> |
|
36 #include <calentry.h> |
|
37 #include <calentryview.h> |
|
38 #include <calattachment.h> |
|
39 |
|
40 #include "emailtrace.h" |
|
41 |
|
42 |
|
43 // Unnamed namespace for local definitions |
|
44 namespace { // codescanner::namespace |
|
45 |
|
46 /** |
|
47 * Adds updated label into summary field. |
|
48 */ |
|
49 void UpdateSummaryL( |
|
50 CCalEntry& aEntry, |
|
51 CESMRMailPlainTextFormatter& aPlainTextFormatter ) |
|
52 { |
|
53 FUNC_LOG; |
|
54 TPtrC currentSummary( aEntry.SummaryL() ); |
|
55 |
|
56 CCalEntry::TMethod method( aEntry.MethodL() ); |
|
57 if ( CCalEntry::EMethodRequest == method && aEntry.SequenceNumberL() ) |
|
58 { |
|
59 // This is update |
|
60 HBufC* updateStr = aPlainTextFormatter.UpdatedStringLC(); |
|
61 HBufC* summary = HBufC::NewLC( |
|
62 updateStr->Length() + currentSummary.Length() ); |
|
63 |
|
64 if ( currentSummary.Find(*updateStr) == KErrNotFound ) |
|
65 { |
|
66 TPtr summaryPtr( summary->Des() ); |
|
67 summaryPtr.Append( *updateStr ); |
|
68 summaryPtr.Append( currentSummary ); |
|
69 aEntry.SetSummaryL( summaryPtr ); |
|
70 } |
|
71 CleanupStack::PopAndDestroy( summary ); |
|
72 summary = NULL; |
|
73 |
|
74 CleanupStack::PopAndDestroy( updateStr ); |
|
75 updateStr = NULL; |
|
76 } |
|
77 else if ( CCalEntry::EMethodCancel == method ) |
|
78 { |
|
79 // This is cancellation |
|
80 HBufC* cancelStr = aPlainTextFormatter.CanceledStringLC(); |
|
81 HBufC* summary = HBufC::NewLC( |
|
82 cancelStr->Length() + currentSummary.Length() ); |
|
83 |
|
84 if ( currentSummary.Find(*cancelStr) == KErrNotFound ) |
|
85 { |
|
86 TPtr summaryPtr( summary->Des() ); |
|
87 summaryPtr.Append( *cancelStr ); |
|
88 summaryPtr.Append( currentSummary ); |
|
89 aEntry.SetSummaryL( summaryPtr ); |
|
90 } |
|
91 CleanupStack::PopAndDestroy( summary ); |
|
92 summary = NULL; |
|
93 |
|
94 CleanupStack::PopAndDestroy( cancelStr ); |
|
95 cancelStr = NULL; |
|
96 } |
|
97 } |
|
98 |
|
99 /** |
|
100 * Cleanup operation for RPointerArray. |
|
101 * |
|
102 * @param aArray Pointer to RPointerArray. |
|
103 */ |
|
104 void CalAttendeePointerArrayCleanup( TAny* aArray ) |
|
105 { |
|
106 RPointerArray<CCalAttendee>* attendeeArray = |
|
107 static_cast<RPointerArray<CCalAttendee>*>( aArray ); |
|
108 |
|
109 attendeeArray->ResetAndDestroy(); |
|
110 attendeeArray->Close(); |
|
111 } |
|
112 |
|
113 #ifdef _DEBUG |
|
114 |
|
115 // Literal for panics |
|
116 _LIT( ESMRSendMRRespMailPanicTxt, "ESMRSendMRFSEMailTask" ); |
|
117 |
|
118 // Panic codes |
|
119 enum TESMRSendMRFSMailTaskPanic |
|
120 { |
|
121 EESMRSendMRFSMailInvalidMethod, // Entry has invalid method |
|
122 EESMRSendMRFSAttendeesMissing, // There are no any attendees in entry to be sent |
|
123 EESMRSendMRNoEntriesToSend, // There are no entries to be sent |
|
124 EESMRSendMRPhoneOwnerNotSet // Phone owner is not set |
|
125 }; |
|
126 |
|
127 // ======== LOCAL FUNCTIONS ======== |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // Panic wrapper method |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void Panic( TESMRSendMRFSMailTaskPanic aPanic ) |
|
134 { |
|
135 User::Panic( ESMRSendMRRespMailPanicTxt, aPanic ); |
|
136 } |
|
137 |
|
138 #endif // _DEBUG |
|
139 |
|
140 |
|
141 // Definition for temporary calendar file |
|
142 //<cmail> remove hard coded paths |
|
143 //_LIT( KPath, "c:\\temp\\" ); //codescanner::driveletters |
|
144 //_LIT( KFileAndPath, "c:\\temp\\meeting.ics" ); //codescanner::driveletters |
|
145 //_LIT( KCancellationFile, "c:\\temp\\cancel.ics" ); //codescanner::driveletters |
|
146 _LIT( KFile, "temp\\meeting.ics" ); |
|
147 _LIT( KCancelFile, "temp\\cancel.ics" ); |
|
148 //</cmail> |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // Leave wrapper method |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 inline void DoLeaveIfErrorL( TInt aLeaveCode ) |
|
155 { |
|
156 if ( KErrNone != aLeaveCode ) |
|
157 { |
|
158 |
|
159 User::Leave( aLeaveCode ); |
|
160 } |
|
161 } |
|
162 } // namespace |
|
163 |
|
164 // ======== MEMBER FUNCTIONS ======== |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CESMRSendMRFSMailTask::CESMRSendMRFSMailTask |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 CESMRSendMRFSMailTask::CESMRSendMRFSMailTask( |
|
171 MESMRCalDbMgr& aCalDbMgr, |
|
172 MESMRMeetingRequestEntry& aEntry, |
|
173 CMRMailboxUtils& aMRMailboxUtils, |
|
174 TESMRCommand aCommand ) |
|
175 : CESMRTaskBase( aCalDbMgr, aEntry, aMRMailboxUtils ), |
|
176 iCommand( aCommand ) |
|
177 { |
|
178 FUNC_LOG; |
|
179 //do nothing |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CESMRSendMRFSMailTask::~CESMRSendMRFSMailTask |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 CESMRSendMRFSMailTask::~CESMRSendMRFSMailTask() |
|
187 { |
|
188 FUNC_LOG; |
|
189 iEntriesToSend.ResetAndDestroy(); |
|
190 delete iCaluserUtil; |
|
191 delete iEmailMgr; |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CESMRSendMRFSMailTask::NewL |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 CESMRSendMRFSMailTask* CESMRSendMRFSMailTask::NewL( |
|
199 MESMRCalDbMgr& aCalDbMgr, |
|
200 MESMRMeetingRequestEntry& aEntry, |
|
201 CMRMailboxUtils& aMRMailboxUtils, |
|
202 TESMRCommand aCommand ) |
|
203 { |
|
204 FUNC_LOG; |
|
205 |
|
206 CESMRSendMRFSMailTask* self = |
|
207 new (ELeave) CESMRSendMRFSMailTask( |
|
208 aCalDbMgr, |
|
209 aEntry, |
|
210 aMRMailboxUtils, |
|
211 aCommand ); |
|
212 |
|
213 CleanupStack::PushL(self); |
|
214 self->ConstructL(); |
|
215 CleanupStack::Pop(self); |
|
216 |
|
217 return self; |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // CESMRSendMRFSMailTask::ConstructL |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 void CESMRSendMRFSMailTask::ConstructL() |
|
225 { |
|
226 FUNC_LOG; |
|
227 BaseConstructL(); |
|
228 iEmailMgr = CESMRFSEMailManager::NewL( MailboxUtils() ); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // CESMRSendMRFSMailTask::ExecuteTaskL |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 void CESMRSendMRFSMailTask::ExecuteTaskL() |
|
236 { |
|
237 FUNC_LOG; |
|
238 CCalEntry* entry = ESMREntry().ValidateEntryL(); |
|
239 CleanupStack::PushL( entry ); |
|
240 |
|
241 iCaluserUtil = CESMRCalUserUtil::NewL( *entry ); |
|
242 |
|
243 CCalEntry::TMethod method( entry->MethodL() ); |
|
244 |
|
245 // Checking input paramters |
|
246 if( !(CCalEntry::EMethodRequest == method || |
|
247 CCalEntry::EMethodCancel == method) || |
|
248 CCalEntry::EAppt != entry->EntryTypeL() ) |
|
249 { |
|
250 DoLeaveIfErrorL( KErrArgument ); |
|
251 } |
|
252 |
|
253 // Get entries to be sent |
|
254 GetEntriesToBeSentL(); |
|
255 ResolveSendTypeL(); |
|
256 |
|
257 if ( NeedToSendInvitationL() ) |
|
258 { |
|
259 TInt entryCount( iEntriesToSend.Count() ); |
|
260 for (TInt i(0); i < entryCount; ++i ) |
|
261 { |
|
262 iEntryToSend = iEntriesToSend[i]; |
|
263 ConstructMailL(); |
|
264 TInt ret = iEmailMgr->SendMessageL(); |
|
265 User::LeaveIfError(ret); |
|
266 } |
|
267 } |
|
268 |
|
269 if ( EESMRCmdSendMRUpdate == iCommand && |
|
270 NeedToSendCancellationL() ) |
|
271 { |
|
272 delete iEmailMgr; iEmailMgr = NULL; |
|
273 iEmailMgr = CESMRFSEMailManager::NewL( MailboxUtils() ); |
|
274 |
|
275 TInt entryCount( iEntriesToSend.Count() ); |
|
276 for (TInt i(0); i < entryCount; ++i ) |
|
277 { |
|
278 // Sending cancellation to removed attendees |
|
279 iEntryToSend = iEntriesToSend[i]; |
|
280 iEntryToSend->SetMethodL( CCalEntry::EMethodCancel ); |
|
281 |
|
282 ConstructMailL(); |
|
283 TInt ret = iEmailMgr->SendMessageL(); |
|
284 User::LeaveIfError(ret); |
|
285 } |
|
286 } |
|
287 |
|
288 CleanupStack::PopAndDestroy( entry ); |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // CESMRSendMRRespFSMailTask::ConstructMailL |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void CESMRSendMRFSMailTask::ConstructMailL() |
|
296 { |
|
297 FUNC_LOG; |
|
298 |
|
299 // create text formatter: |
|
300 CESMRMailPlainTextFormatter* textFormatter = |
|
301 CESMRMailPlainTextFormatter::NewLC( MailboxUtils() ); |
|
302 |
|
303 // Prepare email manager for sending |
|
304 HBufC* mbOwnerAddr = ResolveUsedMailboxUserAddressLC(); |
|
305 TPtrC emailAddr( ESMRHelper::AddressWithoutMailtoPrefix( *mbOwnerAddr ) ); |
|
306 iEmailMgr->PrepareForSendingL( emailAddr ); |
|
307 |
|
308 TBool isForwarded( ESMREntry().IsForwardedL() ); |
|
309 if ( isForwarded ) |
|
310 { |
|
311 CCalUser* organizer = iEntryToSend->OrganizerL(); |
|
312 CCalUser* forwardOrganizer = |
|
313 CCalUser::NewL( |
|
314 organizer->Address(), |
|
315 emailAddr ); |
|
316 CleanupStack::PushL( forwardOrganizer ); |
|
317 forwardOrganizer->SetCommonNameL( organizer->CommonName() ); |
|
318 |
|
319 // Ownership is transferred to entry |
|
320 iEntryToSend->SetOrganizerL( forwardOrganizer ); |
|
321 CleanupStack::Pop( forwardOrganizer ); |
|
322 |
|
323 iEmailMgr->SetSenderL( |
|
324 forwardOrganizer->Address(),forwardOrganizer->CommonName() ); |
|
325 |
|
326 iEmailMgr->SetReplyToAddressL( |
|
327 forwardOrganizer->Address(), forwardOrganizer->CommonName() ); |
|
328 |
|
329 organizer = NULL; |
|
330 forwardOrganizer = NULL; |
|
331 } |
|
332 |
|
333 CleanupStack::PopAndDestroy( mbOwnerAddr ); |
|
334 |
|
335 // set the email subject: |
|
336 HBufC* subject = NULL; |
|
337 if ( CCalEntry::EMethodRequest == iEntryToSend->MethodL() ) |
|
338 { |
|
339 subject = textFormatter->Subject16LC( |
|
340 *iEntryToSend, |
|
341 ESMREntry().IsForwardedL(), |
|
342 EESMRCmdSendMRUpdate == iCommand ); |
|
343 } |
|
344 else |
|
345 { |
|
346 subject = textFormatter->Subject16LC( |
|
347 *iEntryToSend, |
|
348 ESMREntry().IsForwardedL(), |
|
349 EFalse ); |
|
350 } |
|
351 |
|
352 iEmailMgr->SetSubjectL( *subject ); |
|
353 CleanupStack::PopAndDestroy( subject ); |
|
354 subject = NULL; |
|
355 |
|
356 AddAttendeesL(); |
|
357 |
|
358 // Set text/plain part: |
|
359 HBufC* body = textFormatter->Body16LC( *iEntryToSend ); |
|
360 iEmailMgr->CreateTextPlainPartL( *body ); |
|
361 CleanupStack::PopAndDestroy(body); |
|
362 body = NULL; |
|
363 |
|
364 // export the calendar entry in iCal format: |
|
365 UpdateSummaryL( *iEntryToSend, *textFormatter ); |
|
366 |
|
367 TInt priority( iEntryToSend->PriorityL() ); |
|
368 SetCorrectAttendeesToEntryL(); |
|
369 CESMRCalImportExporter* calExporter = CESMRCalImportExporter::NewLC(); |
|
370 HBufC* calendarPart = calExporter->ExportToICal16LC( *iEntryToSend ); |
|
371 |
|
372 // Set text/calendar part: |
|
373 CESMRFSEMailManager::TESMRMethod method( |
|
374 CESMRFSEMailManager::EESMRMethodRequest); |
|
375 |
|
376 CCalEntry::TMethod entryMethod( iEntryToSend->MethodL() ); |
|
377 switch ( entryMethod ) |
|
378 { |
|
379 case CCalEntry::EMethodRequest: |
|
380 { |
|
381 method = CESMRFSEMailManager::EESMRMethodRequest; |
|
382 } |
|
383 break; |
|
384 case CCalEntry::EMethodCancel: |
|
385 { |
|
386 method = CESMRFSEMailManager::EESMRMethodCancel; |
|
387 } |
|
388 break; |
|
389 case CCalEntry::EMethodReply://fallthrough, EMethodReply not needed |
|
390 default: |
|
391 break; |
|
392 } |
|
393 |
|
394 if ( CCalEntry::EMethodCancel == entryMethod ) |
|
395 { |
|
396 TFileName fileName(KCancelFile); |
|
397 User::LeaveIfError(ESMRHelper::CreateAndAppendPrivateDirToFileName(fileName)); |
|
398 SaveICalToFileL( *calendarPart, fileName ); |
|
399 iEmailMgr->CreateTextCalendarPartL(method, fileName); |
|
400 } |
|
401 else |
|
402 { |
|
403 TFileName fileName(KFile); |
|
404 User::LeaveIfError(ESMRHelper::CreateAndAppendPrivateDirToFileName(fileName)); |
|
405 SaveICalToFileL( *calendarPart, fileName ); |
|
406 iEmailMgr->CreateTextCalendarPartL(method, fileName); |
|
407 |
|
408 AddAttachmentsL(); |
|
409 } |
|
410 |
|
411 CleanupStack::PopAndDestroy(3, textFormatter); |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------------------------- |
|
415 // CESMRSendMRFSMailTask::SaveICalToFileL |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 TInt CESMRSendMRFSMailTask::SaveICalToFileL( const TDesC& aICal, |
|
419 const TDesC& aFilename ) |
|
420 { |
|
421 FUNC_LOG; |
|
422 //create 8 bit buffer for temp file content |
|
423 TInt length = aICal.Length() * 2; |
|
424 HBufC8* buffer = HBufC8::NewLC( length ); |
|
425 TPtr8 des = buffer->Des(); |
|
426 |
|
427 // covert the 16 bit iCal to 8 bit iCal: |
|
428 TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8(des, aICal); |
|
429 |
|
430 RFs& fs( CCoeEnv::Static()->FsSession() ); |
|
431 |
|
432 // ensure the path exists: |
|
433 //<cmail>remove hardcoded paths |
|
434 //BaflUtils::EnsurePathExistsL(fs, KPath); |
|
435 //</cmail> |
|
436 |
|
437 // delete previous file |
|
438 fs.Delete( aFilename ); |
|
439 |
|
440 // save the iCal to file system: |
|
441 RFile file; |
|
442 User::LeaveIfError(file.Create(fs, aFilename, EFileWrite)); |
|
443 CleanupClosePushL(file); |
|
444 User::LeaveIfError(file.Write(*buffer)); |
|
445 |
|
446 // clean up: |
|
447 CleanupStack::PopAndDestroy(2, buffer); // file, fs, buffer |
|
448 |
|
449 return KErrNone; |
|
450 } |
|
451 |
|
452 // --------------------------------------------------------------------------- |
|
453 // CESMRSendMRFSMailTask::AddAttendeesL |
|
454 // --------------------------------------------------------------------------- |
|
455 // |
|
456 void CESMRSendMRFSMailTask::AddAttendeesL() |
|
457 { |
|
458 FUNC_LOG; |
|
459 |
|
460 RArray<CCalAttendee*> requiredAttendees; |
|
461 CleanupClosePushL( requiredAttendees ); |
|
462 |
|
463 RArray<CCalAttendee*> optionalAttendees; |
|
464 CleanupClosePushL( optionalAttendees ); |
|
465 |
|
466 GetAttendeesToBeSentL( requiredAttendees, optionalAttendees ); |
|
467 |
|
468 // Add recipients and cc-recipients |
|
469 TInt attendeeCount( requiredAttendees.Count() ); |
|
470 TInt optAttendeeCount( optionalAttendees.Count() ); |
|
471 |
|
472 __ASSERT_DEBUG( attendeeCount || optAttendeeCount, Panic(EESMRSendMRFSAttendeesMissing) ); |
|
473 |
|
474 if ( !attendeeCount && !optAttendeeCount) |
|
475 { |
|
476 DoLeaveIfErrorL( KErrArgument ); |
|
477 } |
|
478 |
|
479 for (TInt i(0); i < attendeeCount; ++i) |
|
480 { |
|
481 TPtrC emailAddr( requiredAttendees[i]->Address() ); |
|
482 |
|
483 |
|
484 iEmailMgr->AppendToRecipientL( |
|
485 emailAddr, |
|
486 requiredAttendees[i]->CommonName() ); |
|
487 } |
|
488 |
|
489 for (TInt i(0); i < optAttendeeCount; ++i) |
|
490 { |
|
491 TPtrC emailAddr( optionalAttendees[i]->Address() ); |
|
492 |
|
493 |
|
494 iEmailMgr->AppendCCRecipientL( |
|
495 emailAddr, |
|
496 optionalAttendees[i]->CommonName() ); |
|
497 } |
|
498 |
|
499 CleanupStack::PopAndDestroy(2, &requiredAttendees ); |
|
500 |
|
501 } |
|
502 |
|
503 // --------------------------------------------------------------------------- |
|
504 // CESMRSendMRFSMailTask::ResolveUsedMailboxUserAddressLC |
|
505 // --------------------------------------------------------------------------- |
|
506 // |
|
507 HBufC* CESMRSendMRFSMailTask::ResolveUsedMailboxUserAddressLC() |
|
508 { |
|
509 FUNC_LOG; |
|
510 |
|
511 HBufC* mailboxUserAddress = NULL; |
|
512 MESMRMeetingRequestEntry& mrEntry( ESMREntry()); |
|
513 if ( mrEntry.IsForwardedL() ) |
|
514 { |
|
515 // Entry is forwarded --> Use default mailbox |
|
516 CMRMailboxUtils::TMailboxInfo mbInfo; |
|
517 CMRMailboxUtils& mbUtils( MailboxUtils() ); |
|
518 mbUtils.GetDefaultMRMailBoxL( mbInfo ); |
|
519 mailboxUserAddress = mbInfo.iEmailAddress.AllocLC(); |
|
520 } |
|
521 else |
|
522 { |
|
523 mailboxUserAddress = mrEntry.CalendarOwnerAddressL().AllocLC(); |
|
524 } |
|
525 |
|
526 return mailboxUserAddress; |
|
527 } |
|
528 |
|
529 |
|
530 // --------------------------------------------------------------------------- |
|
531 // CESMRSendMRFSMailTask::ResolveSendTypeL |
|
532 // --------------------------------------------------------------------------- |
|
533 // |
|
534 void CESMRSendMRFSMailTask::ResolveSendTypeL() |
|
535 { |
|
536 FUNC_LOG; |
|
537 |
|
538 if ( EESMRCmdSendMRUpdate == iCommand ) |
|
539 { |
|
540 RArray<CCalAttendee*> addedAttendees; |
|
541 CleanupClosePushL( addedAttendees ); |
|
542 |
|
543 RArray<CCalAttendee*> removedAttendees; |
|
544 CleanupClosePushL( removedAttendees ); |
|
545 |
|
546 ESMREntry().GetAddedAttendeesL( |
|
547 addedAttendees, |
|
548 EESMRRoleRequiredAttendee | EESMRRoleOptionalAttendee ); |
|
549 ESMREntry().GetRemovedAttendeesL( |
|
550 removedAttendees, |
|
551 EESMRRoleRequiredAttendee | EESMRRoleOptionalAttendee ); |
|
552 |
|
553 if ( addedAttendees.Count() || removedAttendees.Count() ) |
|
554 { |
|
555 TInt sendType = CESMRGUIListQuery::ExecuteL( |
|
556 CESMRGUIListQuery::EESMRSendUpdateToAllQuery ); |
|
557 |
|
558 if ( KErrCancel == sendType ) |
|
559 { |
|
560 User::Leave( KErrCancel ); |
|
561 } |
|
562 |
|
563 iSendType = static_cast<TESMRSendType>(sendType ); |
|
564 } |
|
565 |
|
566 CleanupStack::PopAndDestroy( &removedAttendees ); |
|
567 CleanupStack::PopAndDestroy( &addedAttendees ); |
|
568 } |
|
569 |
|
570 } |
|
571 |
|
572 // --------------------------------------------------------------------------- |
|
573 // CESMRSendMRFSMailTask::NeedToSendInvitationL |
|
574 // --------------------------------------------------------------------------- |
|
575 // |
|
576 TBool CESMRSendMRFSMailTask::NeedToSendInvitationL() |
|
577 { |
|
578 FUNC_LOG; |
|
579 |
|
580 TBool retValue( ETrue ); |
|
581 |
|
582 RArray<CCalAttendee*> addedAttendees; |
|
583 CleanupClosePushL( addedAttendees ); |
|
584 |
|
585 if ( EESMRCmdSendMRUpdate == iCommand && |
|
586 ESentToAddedAndRemoved == iSendType ) |
|
587 { |
|
588 ESMREntry().GetAddedAttendeesL( |
|
589 addedAttendees, |
|
590 EESMRRoleRequiredAttendee | EESMRRoleOptionalAttendee ); |
|
591 |
|
592 if ( !addedAttendees.Count() ) |
|
593 { |
|
594 retValue = EFalse; |
|
595 } |
|
596 } |
|
597 |
|
598 CleanupStack::PopAndDestroy( &addedAttendees ); |
|
599 |
|
600 |
|
601 return retValue; |
|
602 } |
|
603 |
|
604 // --------------------------------------------------------------------------- |
|
605 // CESMRSendMRFSMailTask::NeedToSendCancellationL |
|
606 // --------------------------------------------------------------------------- |
|
607 // |
|
608 TBool CESMRSendMRFSMailTask::NeedToSendCancellationL() |
|
609 { |
|
610 FUNC_LOG; |
|
611 |
|
612 TBool retValue( EFalse ); |
|
613 |
|
614 RArray<CCalAttendee*> removedAttendees; |
|
615 CleanupClosePushL( removedAttendees ); |
|
616 |
|
617 if ( EESMRCmdSendMRUpdate == iCommand ) |
|
618 { |
|
619 ESMREntry().GetRemovedAttendeesL( |
|
620 removedAttendees, |
|
621 EESMRRoleRequiredAttendee | EESMRRoleOptionalAttendee ); |
|
622 |
|
623 if ( removedAttendees.Count() ) |
|
624 { |
|
625 retValue = ETrue; |
|
626 } |
|
627 } |
|
628 |
|
629 CleanupStack::PopAndDestroy( &removedAttendees ); |
|
630 |
|
631 |
|
632 return retValue; |
|
633 } |
|
634 |
|
635 // --------------------------------------------------------------------------- |
|
636 // CESMRSendMRFSMailTask::NeedToSendCancellationL |
|
637 // --------------------------------------------------------------------------- |
|
638 // |
|
639 void CESMRSendMRFSMailTask::SetCorrectAttendeesToEntryL() |
|
640 { |
|
641 FUNC_LOG; |
|
642 if ( EESMRCmdSendMRUpdate == iCommand ) |
|
643 { |
|
644 TESMRMailPlugin plugin( ESMREntry().CurrentPluginL() ); |
|
645 |
|
646 CCalEntry::TMethod method( iEntryToSend->MethodL() ); |
|
647 |
|
648 RArray<CCalAttendee*> requiredAttendees; |
|
649 CleanupClosePushL( requiredAttendees ); |
|
650 |
|
651 RArray<CCalAttendee*> optionalAttendees; |
|
652 CleanupClosePushL( optionalAttendees ); |
|
653 |
|
654 GetAttendeesToBeSentL( requiredAttendees, optionalAttendees ); |
|
655 |
|
656 RPointerArray<CCalAttendee> attendees; |
|
657 CleanupStack::PushL( |
|
658 TCleanupItem( |
|
659 CalAttendeePointerArrayCleanup, |
|
660 &attendees ) ); |
|
661 |
|
662 |
|
663 TInt attendeeCount( requiredAttendees.Count() ); |
|
664 for ( TInt i(0); i < attendeeCount; ++i ) |
|
665 { |
|
666 // Make copy of the attendees |
|
667 CCalAttendee* attendee = ESMRHelper::CopyAttendeeL(*requiredAttendees[i] ); |
|
668 User::LeaveIfError( |
|
669 attendees.Append( attendee ) ); |
|
670 } |
|
671 |
|
672 TInt optionalAttendeeCount( optionalAttendees.Count() ); |
|
673 for ( TInt i(0); i < optionalAttendeeCount; ++i ) |
|
674 { |
|
675 // Make copy of the attendees |
|
676 CCalAttendee* attendee = ESMRHelper::CopyAttendeeL(*optionalAttendees[i] ); |
|
677 User::LeaveIfError( |
|
678 attendees.Append( attendee ) ); |
|
679 } |
|
680 |
|
681 // Clean attendee array |
|
682 while ( iEntryToSend->AttendeesL().Count() ) |
|
683 { |
|
684 iEntryToSend->DeleteAttendeeL( 0 ); |
|
685 } |
|
686 |
|
687 while ( attendees.Count() ) |
|
688 { |
|
689 CCalAttendee* attendee = attendees[0]; |
|
690 iEntryToSend->AddAttendeeL( attendee ); |
|
691 attendees.Remove(0); |
|
692 } |
|
693 |
|
694 CleanupStack::PopAndDestroy( &attendees ); |
|
695 CleanupStack::PopAndDestroy( &optionalAttendees ); |
|
696 CleanupStack::PopAndDestroy( &requiredAttendees ); |
|
697 } |
|
698 } |
|
699 |
|
700 // --------------------------------------------------------------------------- |
|
701 // CESMRSendMRFSMailTask::NeedToSendCancellationL |
|
702 // --------------------------------------------------------------------------- |
|
703 // |
|
704 void CESMRSendMRFSMailTask::GetAttendeesToBeSentL( |
|
705 RArray<CCalAttendee*>& aRequiredAttendees, |
|
706 RArray<CCalAttendee*>& aOptionalAttendees ) |
|
707 { |
|
708 FUNC_LOG; |
|
709 CCalEntry::TMethod method( iEntryToSend->MethodL() ); |
|
710 |
|
711 if ( EESMRCmdSendMRUpdate == iCommand && |
|
712 ESentToAddedAndRemoved == iSendType && |
|
713 CCalEntry::EMethodRequest == method ) |
|
714 { |
|
715 ESMREntry().GetAddedAttendeesL( |
|
716 aRequiredAttendees, |
|
717 EESMRRoleRequiredAttendee ); |
|
718 ESMREntry().GetAddedAttendeesL( |
|
719 aOptionalAttendees, |
|
720 EESMRRoleOptionalAttendee ); |
|
721 } |
|
722 else if (EESMRCmdSendMRUpdate == iCommand && |
|
723 CCalEntry::EMethodCancel == method ) |
|
724 { |
|
725 ESMREntry().GetRemovedAttendeesL( |
|
726 aRequiredAttendees, |
|
727 EESMRRoleRequiredAttendee ); |
|
728 ESMREntry().GetRemovedAttendeesL( |
|
729 aOptionalAttendees, |
|
730 EESMRRoleOptionalAttendee ); |
|
731 } |
|
732 else |
|
733 { |
|
734 iCaluserUtil->GetAttendeesL( |
|
735 aRequiredAttendees, |
|
736 EESMRRoleRequiredAttendee ); |
|
737 iCaluserUtil->GetAttendeesL( |
|
738 aOptionalAttendees, |
|
739 EESMRRoleOptionalAttendee ); |
|
740 } |
|
741 } |
|
742 |
|
743 // --------------------------------------------------------------------------- |
|
744 // CESMRSendMRFSMailTask::GetEntriesToBeSentL |
|
745 // --------------------------------------------------------------------------- |
|
746 // |
|
747 void CESMRSendMRFSMailTask::GetEntriesToBeSentL() |
|
748 { |
|
749 FUNC_LOG; |
|
750 // Clear the entry array |
|
751 iEntriesToSend.ResetAndDestroy(); |
|
752 |
|
753 if ( EESMRCmdSendMRUpdate == iCommand ) |
|
754 { |
|
755 // We are sending update and we need to send all the entries |
|
756 CCalEntry* mainEntry = ESMREntry().ValidateEntryL(); |
|
757 CleanupStack::PushL( mainEntry ); |
|
758 |
|
759 if ( MESMRCalEntry::EESMRAllInSeries == ESMREntry().RecurrenceModRule() ) |
|
760 { |
|
761 // Update child entries sequence number |
|
762 ESMREntry().UpdateChildEntriesSeqNumbersL(); |
|
763 |
|
764 // We are sending update to series |
|
765 // Also the modifying entries need to be sent |
|
766 // Otherwise the modifying entries may disappear from the |
|
767 // attendees calendar. |
|
768 CalDbMgr().EntryViewL( *mainEntry )->FetchL( |
|
769 mainEntry->UidL(), |
|
770 iEntriesToSend ); |
|
771 // set the phone owner for the series |
|
772 CESMRFsMailboxUtils* fsMbUtils =CESMRFsMailboxUtils::NewL( MailboxUtils() ); |
|
773 CleanupStack::PushL( fsMbUtils ); |
|
774 for (TInt i =0 ; i < iEntriesToSend.Count(); i++) |
|
775 { |
|
776 fsMbUtils->SetPhoneOwnerL( *iEntriesToSend[i] ); |
|
777 } |
|
778 CleanupStack::PopAndDestroy( fsMbUtils ); |
|
779 fsMbUtils = NULL; |
|
780 CleanupStack::PopAndDestroy( mainEntry ); |
|
781 } |
|
782 else |
|
783 { |
|
784 // Ownership transferred |
|
785 TInt err = iEntriesToSend.Append( mainEntry ); |
|
786 User::LeaveIfError( err ); |
|
787 |
|
788 CleanupStack::Pop( mainEntry ); |
|
789 } |
|
790 |
|
791 mainEntry = NULL; |
|
792 } |
|
793 else |
|
794 { |
|
795 // We are sending either: |
|
796 // a) Single entry |
|
797 // b) Modified instance from series |
|
798 // c) First invitation to series |
|
799 // d) forwarding entry |
|
800 TInt err = iEntriesToSend.Append( ESMREntry().ValidateEntryL() ); |
|
801 User::LeaveIfError( err ); |
|
802 } |
|
803 |
|
804 __ASSERT_DEBUG( iEntriesToSend.Count(), Panic(EESMRSendMRNoEntriesToSend ) ); |
|
805 } |
|
806 |
|
807 // --------------------------------------------------------------------------- |
|
808 // CESMRSendMRFSMailTask::AddAttachmentsL |
|
809 // --------------------------------------------------------------------------- |
|
810 // |
|
811 void CESMRSendMRFSMailTask::AddAttachmentsL() |
|
812 { |
|
813 FUNC_LOG; |
|
814 |
|
815 RFs fsSession; |
|
816 User::LeaveIfError( fsSession.Connect() ); |
|
817 CleanupClosePushL( fsSession ); |
|
818 |
|
819 User::LeaveIfError( fsSession.ShareProtected() ); |
|
820 |
|
821 TInt attachmentCount( iEntryToSend->AttachmentCountL() ); |
|
822 |
|
823 for ( TInt i(0); i < attachmentCount; ++i ) |
|
824 { |
|
825 CCalAttachment* attachment = iEntryToSend->AttachmentL( i ); |
|
826 |
|
827 if ( CCalAttachment::EFile == attachment->Type() ) |
|
828 { |
|
829 // Adding file attachment to MR email message |
|
830 CCalAttachmentFile* fileAttachment = attachment->FileAttachment(); |
|
831 |
|
832 RFile file; |
|
833 CleanupClosePushL( file ); |
|
834 fileAttachment->FetchFileHandleL( file ); |
|
835 |
|
836 iEmailMgr->SetAttachmentL( |
|
837 file, |
|
838 attachment->MimeType() ); |
|
839 |
|
840 TESMRMailPlugin plugin( ESMREntry().CurrentPluginL() ); |
|
841 if ( EESMRImapPop == plugin ) |
|
842 { |
|
843 CleanupStack::Pop( &file ); |
|
844 } |
|
845 else |
|
846 { |
|
847 CleanupStack::PopAndDestroy( &file ); |
|
848 } |
|
849 } |
|
850 } |
|
851 |
|
852 CleanupStack::PopAndDestroy( &fsSession ); |
|
853 } |
|
854 |
|
855 // EOF |