|
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 sending MR response via fs email |
|
15 * |
|
16 */ |
|
17 #include "emailtrace.h" |
|
18 #include "cesmrsendmrrespfsmailtask.h" |
|
19 |
|
20 #include <caluser.h> |
|
21 #include <calentry.h> |
|
22 #include <utf.h> |
|
23 //<cmail> |
|
24 #include "mmrinfoprocessor.h" |
|
25 //</cmail> |
|
26 #include <f32file.h> |
|
27 #include <coemain.h> |
|
28 #include <bautils.h> |
|
29 #include <cmrmailboxutils.h> |
|
30 |
|
31 #include "cesmrcaldbmgr.h" |
|
32 #include "mesmrmeetingrequestentry.h" |
|
33 #include "cesmrmailplaitextformatter.h" |
|
34 #include "cesmrfsemailmanager.h" |
|
35 #include "cesmrcalimportexporter.h" |
|
36 #include "tesmrinputparams.h" |
|
37 #include "cesmrcaluserutil.h" |
|
38 #include "esmrhelper.h" |
|
39 |
|
40 // Unnamed namespace for local definitions |
|
41 namespace { |
|
42 // Literal for plain text separator |
|
43 _LIT( KPlainTextResponseTxtSeparator, |
|
44 "\n----------------------------------------\n"); |
|
45 |
|
46 |
|
47 // Literal for response iCal file |
|
48 //<cmail> remove hard coded paths |
|
49 //_LIT( KPath, "c:\\temp\\" ); //codescanner::driveletters |
|
50 //_LIT( KFileAndPath, "c:\\temp\\response.ics" ); //codescanner::driveletters |
|
51 //_LIT( KPath, "temp\\" ); |
|
52 _LIT( KFileName, "temp\\response.ics" ); |
|
53 //</cmail> |
|
54 |
|
55 } // namespace |
|
56 |
|
57 // ======== MEMBER FUNCTIONS ======== |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CESMRSendMRRespFSMailTask::CESMRSendMRRespFSMailTask |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CESMRSendMRRespFSMailTask::CESMRSendMRRespFSMailTask( |
|
64 TESMRCommand aCommand, |
|
65 MESMRCalDbMgr& aCalDbMgr, |
|
66 MESMRMeetingRequestEntry& aEntry, |
|
67 CMRMailboxUtils& aMRMailboxUtils, |
|
68 TESMRResponseType aResponseType ) |
|
69 : CESMRTaskBase( aCalDbMgr, aEntry, aMRMailboxUtils ), |
|
70 iCommand( aCommand ), |
|
71 iResponseType( aResponseType ) |
|
72 { |
|
73 FUNC_LOG; |
|
74 //do nothing |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CESMRSendMRRespFSMailTask::~CESMRSendMRRespFSMailTask |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 CESMRSendMRRespFSMailTask::~CESMRSendMRRespFSMailTask() |
|
82 { |
|
83 FUNC_LOG; |
|
84 delete iCaluserUtil; |
|
85 delete iEntryToSend; |
|
86 delete iResponseMessage; |
|
87 delete iEmailMgr; |
|
88 delete iTextFormatter; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CESMRSendMRRespFSMailTask::NewL |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 CESMRSendMRRespFSMailTask* CESMRSendMRRespFSMailTask::NewL( |
|
96 TESMRCommand aCommand, |
|
97 MESMRCalDbMgr& aCalDbMgr, |
|
98 MESMRMeetingRequestEntry& aEntry, |
|
99 CMRMailboxUtils& aMRMailboxUtils, |
|
100 TESMRResponseType aResponseType, |
|
101 const TDesC& aResponseMessage ) |
|
102 { |
|
103 FUNC_LOG; |
|
104 CESMRSendMRRespFSMailTask* self = |
|
105 new (ELeave) CESMRSendMRRespFSMailTask( |
|
106 aCommand, |
|
107 aCalDbMgr, |
|
108 aEntry, |
|
109 aMRMailboxUtils, |
|
110 aResponseType ); |
|
111 |
|
112 CleanupStack::PushL(self); |
|
113 self->ConstructL(aResponseMessage); |
|
114 CleanupStack::Pop(self); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CESMRSendMRRespFSMailTask::ConstructL |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CESMRSendMRRespFSMailTask::ConstructL( |
|
123 const TDesC& aResponseMessage ) |
|
124 { |
|
125 FUNC_LOG; |
|
126 BaseConstructL(); |
|
127 iEmailMgr = CESMRFSEMailManager::NewL( MailboxUtils() ); |
|
128 iTextFormatter = CESMRMailPlainTextFormatter::NewL( MailboxUtils() ); |
|
129 iResponseMessage = aResponseMessage.AllocL(); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CESMRSendMRRespFSMailTask::ExecuteTaskL |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CESMRSendMRRespFSMailTask::ExecuteTaskL() |
|
137 { |
|
138 FUNC_LOG; |
|
139 iEntryToSend = ESMREntry().ValidateEntryL(); |
|
140 |
|
141 // Checking input paramters |
|
142 if( CCalEntry::EMethodReply != iEntryToSend->MethodL() && |
|
143 EESMRCmdRemoveFromCalendar != iCommand ) |
|
144 { |
|
145 User::Leave( KErrArgument ); |
|
146 } |
|
147 |
|
148 if ( ESMREntry().IsSyncObjectPresent( ) ) |
|
149 { |
|
150 SendMailViaSyncL(); |
|
151 } |
|
152 else |
|
153 { |
|
154 iCaluserUtil = CESMRCalUserUtil::NewL( *iEntryToSend ); |
|
155 |
|
156 // create mail message: |
|
157 ConstructMailL(); |
|
158 |
|
159 TInt ret = iEmailMgr->SendMessageL(); |
|
160 User::LeaveIfError(ret); |
|
161 } |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CESMRSendMRRespFSMailTask::ConstructMailL |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void CESMRSendMRRespFSMailTask::ConstructMailL() |
|
169 { |
|
170 FUNC_LOG; |
|
171 // Prepare email manager for sending |
|
172 CCalUser *mailboxUser = ESMREntry().Entry().PhoneOwnerL(); |
|
173 iEmailMgr->PrepareForSendingL( |
|
174 ESMRHelper::AddressWithoutMailtoPrefix( |
|
175 mailboxUser->Address() ) ); |
|
176 |
|
177 // set the email subject |
|
178 HBufC* subject = |
|
179 iTextFormatter->Subject16LC( |
|
180 *iEntryToSend, |
|
181 ESMREntry().IsForwardedL(), |
|
182 ESMREntry().IsEntryEditedL() ); |
|
183 |
|
184 iEmailMgr->SetSubjectL(*subject); |
|
185 CleanupStack::PopAndDestroy(subject); |
|
186 subject = NULL; |
|
187 |
|
188 // Set the To recipient |
|
189 iEmailMgr->AppendToRecipientL( |
|
190 iEntryToSend->OrganizerL()->Address(), |
|
191 iEntryToSend->OrganizerL()->CommonName() ); |
|
192 |
|
193 // Set text/plain part |
|
194 AddPlainTextPartL(); |
|
195 |
|
196 // Set text/calendar part: |
|
197 AddCalendarPartL(); |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // CESMRSendMRRespFSMailTask::AddPlainTextPartL |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 void CESMRSendMRRespFSMailTask::AddPlainTextPartL() |
|
205 { |
|
206 FUNC_LOG; |
|
207 |
|
208 HBufC* plainText = iTextFormatter->Body16LC( *iEntryToSend ); |
|
209 if ( iResponseMessage ) |
|
210 { |
|
211 TPtrC plainTextSeparator( KPlainTextResponseTxtSeparator() ); |
|
212 |
|
213 CleanupStack::Pop( plainText ); |
|
214 |
|
215 plainText = plainText->ReAlloc( |
|
216 plainText->Length() + |
|
217 plainTextSeparator.Length() + |
|
218 iResponseMessage->Length() ); |
|
219 |
|
220 CleanupStack::PushL( plainText ); |
|
221 |
|
222 TPtr ptrPlainText( plainText->Des() ); |
|
223 ptrPlainText.Append( plainTextSeparator ); |
|
224 ptrPlainText.Append( *iResponseMessage ); |
|
225 } |
|
226 |
|
227 iEmailMgr->CreateTextPlainPartL(*plainText); |
|
228 CleanupStack::PopAndDestroy(plainText); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // CESMRSendMRRespFSMailTask::AddCalendarPartL |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 void CESMRSendMRRespFSMailTask::AddCalendarPartL() |
|
236 { |
|
237 FUNC_LOG; |
|
238 SetAttendeesL(); |
|
239 |
|
240 CESMRCalImportExporter* calExporter = |
|
241 CESMRCalImportExporter::NewLC(); |
|
242 |
|
243 HBufC* calendarPart = |
|
244 calExporter->ExportToICal16LC( *iEntryToSend ); |
|
245 |
|
246 //<cmail> removing hardcoded paths |
|
247 TFileName fileName(KFileName); |
|
248 User::LeaveIfError(ESMRHelper::CreateAndAppendPrivateDirToFileName(fileName)); |
|
249 SaveICalToFileL( *calendarPart, fileName ); |
|
250 iEmailMgr->CreateTextCalendarPartL( |
|
251 CESMRFSEMailManager::EESMRMethodResponse, |
|
252 fileName); |
|
253 //</cmail> |
|
254 |
|
255 CleanupStack::PopAndDestroy( calendarPart ); |
|
256 CleanupStack::PopAndDestroy( calExporter ); |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // CESMRSendMRRespFSMailTask::SendMailViaSyncL |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void CESMRSendMRRespFSMailTask::SendMailViaSyncL() |
|
264 { |
|
265 FUNC_LOG; |
|
266 TESMRInputParams startupParams; |
|
267 |
|
268 if ( ESMREntry().StartupParameters(startupParams) ) |
|
269 { |
|
270 MMRInfoProcessor::TMRInfoResponseMode responseMode ( |
|
271 MMRInfoProcessor::EMRInfoResponseSendAndSync ); |
|
272 |
|
273 if ( EESMRResponseDontSend == iResponseType ) |
|
274 { |
|
275 responseMode = MMRInfoProcessor::EMRInfoResponseSync; |
|
276 } |
|
277 else if ( EESMRCmdRemoveFromCalendar == iCommand ) |
|
278 { |
|
279 responseMode = MMRInfoProcessor::EMRInfoRemoveFromCal; |
|
280 } |
|
281 |
|
282 MMRInfoObject& infoObject = ESMREntry().ValidateSyncObjectL(); |
|
283 iEmailMgr->SendMailViaSyncL( |
|
284 startupParams, |
|
285 infoObject, |
|
286 responseMode, |
|
287 *iResponseMessage ); |
|
288 } |
|
289 else |
|
290 { |
|
291 User::Leave( KErrArgument ); |
|
292 } |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // CESMRSendMRRespFSMailTask::SaveICalToFileL |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 TInt CESMRSendMRRespFSMailTask::SaveICalToFileL( |
|
300 const TDesC& aICal, |
|
301 const TDesC& aFilename ) |
|
302 { |
|
303 FUNC_LOG; |
|
304 //create 8 bit buffer for temp file content |
|
305 TInt length = aICal.Length() * 2; |
|
306 HBufC8* buffer = HBufC8::NewLC( length ); |
|
307 TPtr8 des = buffer->Des(); |
|
308 |
|
309 // covert the 16 bit iCal to 8 bit iCal: |
|
310 TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8(des, aICal); |
|
311 |
|
312 RFs& fs( CCoeEnv::Static()->FsSession() ); |
|
313 |
|
314 // ensure the path exists: |
|
315 //<cmail> remove hard coded paths |
|
316 //BaflUtils::EnsurePathExistsL(fs, KPath); |
|
317 //</cmail> |
|
318 |
|
319 // delete previous file |
|
320 fs.Delete( aFilename ); |
|
321 |
|
322 // save the iCal to file system: |
|
323 RFile file; |
|
324 User::LeaveIfError(file.Create(fs, aFilename, EFileWrite)); |
|
325 CleanupClosePushL(file); |
|
326 User::LeaveIfError(file.Write(*buffer)); |
|
327 |
|
328 // clean up: |
|
329 CleanupStack::PopAndDestroy(2, buffer); // file, fs, buffer |
|
330 |
|
331 return KErrNone; |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // CESMRSendMRRespFSMailTask::SetAttendeesL |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 void CESMRSendMRRespFSMailTask::SetAttendeesL() |
|
339 { |
|
340 FUNC_LOG; |
|
341 CCalAttendee* thisAttendee = |
|
342 ESMRHelper::CopyAttendeeLC( |
|
343 *(MailboxUtils().ThisAttendeeL( *iEntryToSend )) ); |
|
344 |
|
345 RPointerArray<CCalAttendee>& attendeeList = iEntryToSend->AttendeesL(); |
|
346 |
|
347 while ( attendeeList.Count() ) |
|
348 { |
|
349 //remove attendees from entry that is to be forwarded |
|
350 iEntryToSend->DeleteAttendeeL( 0 ); |
|
351 } |
|
352 |
|
353 // Ownership is transferred |
|
354 iEntryToSend->AddAttendeeL( thisAttendee ); |
|
355 CleanupStack::Pop( thisAttendee ); |
|
356 } |
|
357 |
|
358 //EOF |
|
359 |