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