|
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 CFsSendAsHelper. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "emailtrace.h" |
|
21 #include <s32mem.h> |
|
22 #include <aknappui.h> |
|
23 #include <bautils.h> |
|
24 #include <centralrepository.h> |
|
25 #include <e32const.h> |
|
26 #include <usbman.h> |
|
27 #include <usbpersonalityids.h> |
|
28 #include <aknnotewrappers.h> |
|
29 #include <StringLoader.h> |
|
30 #include <data_caging_path_literals.hrh> |
|
31 #include <FreestyleEmailUi.rsg> |
|
32 |
|
33 //<cmail> |
|
34 #include "cfsmailcommon.h" |
|
35 #include "cfsmailclient.h" |
|
36 #include "cfsmailmessage.h" |
|
37 #include "cfsmailbox.h" |
|
38 #include "cfsmailaddress.h" |
|
39 #include "cfsmailmessagebase.h" |
|
40 #include "cfsmailmessagepart.h" |
|
41 #include "FreestyleEmailUiConstants.h" |
|
42 #include "esmailsettingsplugin.h" |
|
43 //</cmail> |
|
44 #include "cfssendashelper.h" |
|
45 #include "fsmtmsconstants.h" |
|
46 #include "freestyleemailcenrepkeys.h" |
|
47 |
|
48 _LIT( KFreestyleEmailUiResourceFileName, "FreestyleEmailUi.rsc" ); |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CFsSendAsInfo::NewL |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C CFsSendAsHelper* CFsSendAsHelper::NewL() |
|
55 { |
|
56 FUNC_LOG; |
|
57 |
|
58 CFsSendAsHelper* self = new(ELeave) CFsSendAsHelper(); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop( self ); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CFsSendAsHelper::~CFsSendAsHelper |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C CFsSendAsHelper::~CFsSendAsHelper() |
|
71 { |
|
72 FUNC_LOG; |
|
73 |
|
74 delete iSubject; |
|
75 delete iBody; |
|
76 delete iMassStorageNote; |
|
77 |
|
78 for (int i = 0; i < iFiles.Count() && !isPassed; ++i ) |
|
79 { |
|
80 iFiles[i].Close(); |
|
81 } |
|
82 iFiles.Reset(); |
|
83 iFileNames.ResetAndDestroy(); |
|
84 iMimeTypesFile.ResetAndDestroy(); |
|
85 iMimeTypesFileName.ResetAndDestroy(); |
|
86 |
|
87 iToAddresses.ResetAndDestroy(); |
|
88 iCcAddresses.ResetAndDestroy(); |
|
89 iBccAddresses.ResetAndDestroy(); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CFsSendAsHelper::CFsSendAsHelper |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 CFsSendAsHelper::CFsSendAsHelper() : isPassed(EFalse) |
|
97 { |
|
98 FUNC_LOG; |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CFsSendAsHelper::ConstructL |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CFsSendAsHelper::ConstructL() |
|
106 { |
|
107 FUNC_LOG; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CFsSendAsHelper::AddAttachmentL |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C void CFsSendAsHelper::AddAttachmentL(const TDesC& aFileName, |
|
115 const TDesC8& aMimeType, TUint /*aCharSet*/) |
|
116 { |
|
117 FUNC_LOG; |
|
118 |
|
119 if ( !iBody ) |
|
120 { |
|
121 //Create empty body, as body is required |
|
122 iBody = HBufC::NewL(1); |
|
123 } |
|
124 |
|
125 if ( aFileName != KNullDesC ) |
|
126 { |
|
127 iFileNames.AppendL( aFileName.AllocL() ); |
|
128 iMimeTypesFileName.AppendL( aMimeType.AllocL() ); |
|
129 } |
|
130 |
|
131 if ( !iSubject ) |
|
132 { |
|
133 TBuf<KMaxFileName> fileName( aFileName ); |
|
134 TParse parse; |
|
135 User::LeaveIfError(parse.Set( fileName, NULL , NULL) ); |
|
136 iSubject = parse.NameAndExt().AllocL(); |
|
137 } |
|
138 |
|
139 } |
|
140 |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CFsSendAsHelper::AddAttachmentL |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 EXPORT_C void CFsSendAsHelper::AddAttachmentL( RFile& aFile, |
|
147 const TDesC8& aMimeType, TUint /*aCharSet*/) |
|
148 { |
|
149 FUNC_LOG; |
|
150 |
|
151 iFiles.AppendL( aFile ); |
|
152 iMimeTypesFile.AppendL( aMimeType.AllocL() ); |
|
153 |
|
154 if ( !iSubject ) |
|
155 { |
|
156 TBuf<KMaxFileName> fileName; |
|
157 TInt error = aFile.FullName( fileName ); |
|
158 if ( error != KErrNone ) |
|
159 { |
|
160 User::Leave( error ); |
|
161 } |
|
162 TParse parse; |
|
163 User::LeaveIfError(parse.Set( fileName, NULL , NULL) ); |
|
164 iSubject = parse.NameAndExt().AllocL(); |
|
165 |
|
166 if ( !iBody ) |
|
167 { |
|
168 //Create empty body, as body is required |
|
169 iBody = HBufC::NewL(1); |
|
170 } |
|
171 } |
|
172 |
|
173 |
|
174 } |
|
175 |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CFsSendAsHelper::AddRecipientL |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 EXPORT_C void CFsSendAsHelper::AddRecipientL(const TDesC& aAddress, |
|
182 const TDesC& aAlias, TMsvRecipientType aType) |
|
183 { |
|
184 FUNC_LOG; |
|
185 |
|
186 CFSMailAddress* to = CFSMailAddress::NewL(); |
|
187 CleanupStack::PushL( to ); |
|
188 |
|
189 if ( aAddress != KNullDesC ) |
|
190 { |
|
191 to->SetEmailAddress( aAddress ); |
|
192 } |
|
193 |
|
194 if ( aAlias != KNullDesC ) |
|
195 { |
|
196 to->SetDisplayName( aAlias ); |
|
197 } |
|
198 |
|
199 switch ( aType ) |
|
200 { |
|
201 case EMsvRecipientCc: |
|
202 iCcAddresses.AppendL( to ); |
|
203 break; |
|
204 case EMsvRecipientBcc: |
|
205 iBccAddresses.AppendL( to ); |
|
206 break; |
|
207 case EMsvRecipientTo: |
|
208 default: |
|
209 iToAddresses.AppendL( to ); |
|
210 break; |
|
211 } |
|
212 |
|
213 CleanupStack::Pop( to ); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // CFsSendAsHelper::SetSubjectL |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 EXPORT_C void CFsSendAsHelper::SetSubjectL(const TDesC& aSubject) |
|
221 { |
|
222 FUNC_LOG; |
|
223 |
|
224 if ( aSubject != KNullDesC ) |
|
225 { |
|
226 delete iSubject; |
|
227 iSubject = NULL; // <cmail> |
|
228 iSubject = aSubject.AllocL(); |
|
229 } |
|
230 |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CFsSendAsHelper::SetBodyL |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 EXPORT_C void CFsSendAsHelper::SetBodyL(const TDesC& aBody) |
|
238 { |
|
239 FUNC_LOG; |
|
240 |
|
241 if ( aBody != KNullDesC ) |
|
242 { |
|
243 delete iBody; |
|
244 iBody = NULL; // <cmail> |
|
245 iBody = aBody.AllocL(); |
|
246 } |
|
247 |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // CFsSendAsHelper::StoreDataL |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 EXPORT_C void CFsSendAsHelper::StoreDataL( TUint aPluginId, TUint aId ) |
|
255 { |
|
256 FUNC_LOG; |
|
257 |
|
258 User::LeaveIfError( IsMailboxAvailable( aPluginId ) ); |
|
259 |
|
260 CFSMailClient* mailClient = CFSMailClient::NewL(); |
|
261 CleanupClosePushL(*mailClient); // +1 mailClient |
|
262 CFSMailBox* mailBox = mailClient->GetMailBoxByUidL( |
|
263 TFSMailMsgId( aPluginId, aId )); |
|
264 |
|
265 // If there's no mailbox, we can't create a new email |
|
266 User::LeaveIfNull( mailBox ); |
|
267 |
|
268 CleanupStack::PushL( mailBox ); // +2 mailBox |
|
269 CFSMailMessage* newMessage = mailBox->CreateMessageToSend(); |
|
270 CleanupStack::PushL( newMessage ); // +3 newMessage //SCANNER |
|
271 |
|
272 // newMessage->SetContentType( KFSMailContentTypeMultipartMixed ); |
|
273 |
|
274 // set message subject |
|
275 if(iSubject) |
|
276 { |
|
277 newMessage->SetSubject( *iSubject ); |
|
278 } |
|
279 |
|
280 // Append To recipients |
|
281 for ( int i = 0; i < iToAddresses.Count(); ++i ) |
|
282 { |
|
283 newMessage->AppendToRecipient( iToAddresses[i] ); |
|
284 } |
|
285 |
|
286 iToAddresses.Reset(); |
|
287 |
|
288 // Append Cc recipients |
|
289 for ( int i = 0; i < iCcAddresses.Count(); ++i ) |
|
290 { |
|
291 newMessage->AppendCCRecipient( iCcAddresses[i] ); |
|
292 } |
|
293 |
|
294 iCcAddresses.Reset(); |
|
295 |
|
296 // Append Bcc recipients |
|
297 for ( int i = 0; i < iBccAddresses.Count(); ++i ) |
|
298 { |
|
299 newMessage->AppendBCCRecipient( iBccAddresses[i] ); |
|
300 } |
|
301 |
|
302 iBccAddresses.Reset(); |
|
303 |
|
304 // add body |
|
305 if(iBody) |
|
306 { |
|
307 CFSMailMessagePart* newMessageTextPart = newMessage->PlainTextBodyPartL(); |
|
308 if ( !newMessageTextPart ) |
|
309 { |
|
310 // create new message part for body text |
|
311 TFSMailMsgId insertBefore; |
|
312 newMessageTextPart = newMessage->NewChildPartL( insertBefore, KFSMailContentTypeTextPlain ); |
|
313 } |
|
314 |
|
315 if ( newMessageTextPart ) |
|
316 { |
|
317 CleanupStack::PushL( newMessageTextPart ); // +4 newMessageTextPart |
|
318 |
|
319 // Check that whether new part contains data that needs to be appended |
|
320 // for example signature generated by the mailbox |
|
321 HBufC* createdBodyContent = HBufC::NewLC( newMessageTextPart->FetchedContentSize() ); |
|
322 TPtr tempPtr = createdBodyContent->Des(); |
|
323 newMessageTextPart->GetContentToBufferL( tempPtr, 0 ); |
|
324 if ( createdBodyContent->Length() ) |
|
325 { |
|
326 // Store original body |
|
327 HBufC* originalBody = iBody->AllocLC(); |
|
328 delete iBody; |
|
329 iBody = NULL; |
|
330 // Create new body object, deleted either above, in destructor or in setbody |
|
331 iBody = HBufC::NewL( originalBody->Length() + createdBodyContent->Length( )); |
|
332 // append original body and also generated body content |
|
333 iBody->Des().Append( *originalBody ); |
|
334 iBody->Des().Append( *createdBodyContent ); |
|
335 CleanupStack::PopAndDestroy( originalBody ); |
|
336 } |
|
337 CleanupStack::PopAndDestroy( createdBodyContent ); |
|
338 newMessageTextPart->SetContentType( KFSMailContentTypeTextPlain ); |
|
339 newMessageTextPart->SetMailBoxId( mailBox->GetId() ); |
|
340 TPtr bodyPtr = iBody->Des(); |
|
341 newMessageTextPart->SetContent( bodyPtr ); |
|
342 newMessageTextPart->SaveL(); |
|
343 CleanupStack::PopAndDestroy( newMessageTextPart ); // -4 newMessageTextPart |
|
344 } |
|
345 } |
|
346 |
|
347 for( int i = 0; i < iFiles.Count(); ++i ) |
|
348 { |
|
349 CFSMailMessagePart* msgPart = newMessage->AddNewAttachmentL( iFiles[i], *iMimeTypesFile[i] ); |
|
350 delete msgPart; |
|
351 } |
|
352 isPassed = ETrue; |
|
353 |
|
354 for ( int i = 0; i < iFileNames.Count(); ++i ) |
|
355 { |
|
356 TFSMailMsgId nullId; |
|
357 CFSMailMessagePart* msgPart = newMessage->AddNewAttachmentL( *iFileNames[i], nullId ); |
|
358 delete msgPart; |
|
359 } |
|
360 |
|
361 newMessage->SaveMessageL(); |
|
362 TFSMailMsgId msgId = newMessage->GetMessageId(); |
|
363 |
|
364 // <cmail> S60 UID update |
|
365 const TUid KFreestyleEmailCenRep = {0x2001E277}; |
|
366 // </cmail> S60 UID update |
|
367 CRepository* repository( NULL ); |
|
368 TRAPD( ret, repository = CRepository::NewL( KFreestyleEmailCenRep ) ); |
|
369 if ( ret == KErrNone ) |
|
370 { |
|
371 CleanupStack::PushL( repository ); |
|
372 TInt rval; |
|
373 TInt messageId = msgId.Id(); |
|
374 rval = repository->Set( KFreestyleMtmMessageId, messageId ); |
|
375 if( rval != KErrNone) |
|
376 { |
|
377 } |
|
378 CleanupStack::PopAndDestroy( repository ); |
|
379 } |
|
380 // check that msg is not in drafts folder already |
|
381 TFSMailMsgId draftsFolderId = mailBox->GetStandardFolderId( |
|
382 EFSDraftsFolder ); |
|
383 TFSMailMsgId msgFolderId = newMessage->GetFolderId(); |
|
384 if ( draftsFolderId != msgFolderId ) |
|
385 { |
|
386 RArray<TFSMailMsgId> ids; |
|
387 ids.Append( msgId ); |
|
388 mailBox->MoveMessagesL( ids, msgFolderId, draftsFolderId ); |
|
389 ids.Reset(); |
|
390 } |
|
391 |
|
392 CleanupStack::PopAndDestroy( newMessage ); // -3 newMessage |
|
393 CleanupStack::PopAndDestroy( mailBox ); // -2 mailBox |
|
394 CleanupStack::PopAndDestroy( mailClient ); // -1 mailClient, close() will be called |
|
395 mailClient = NULL; |
|
396 |
|
397 } |
|
398 |
|
399 // --------------------------------------------------------------------------- |
|
400 // CFsSendAsHelper::LaunchUiL |
|
401 // --------------------------------------------------------------------------- |
|
402 // |
|
403 EXPORT_C void CFsSendAsHelper::LaunchUiL( TUint aPluginId, TUint aId, |
|
404 TBool aIsEmptyMail, TBool aIsSettings) |
|
405 { |
|
406 FUNC_LOG; |
|
407 |
|
408 CEikAppUi* appUi = CEikonEnv::Static()->EikAppUi(); |
|
409 CCoeAppUi* coeAppUi = static_cast<CCoeAppUi*>( appUi ); |
|
410 |
|
411 if ( aIsSettings ) |
|
412 { |
|
413 |
|
414 CESMailSettingsPlugin::TSubViewActivationData pluginData; |
|
415 pluginData.iAccount = TFSMailMsgId( aPluginId, aId ); |
|
416 pluginData.iLaunchedOutsideFSEmail = ETrue; |
|
417 pluginData.iSubviewId=0; |
|
418 const TPckgBuf<CESMailSettingsPlugin::TSubViewActivationData> pkgOut( pluginData ); |
|
419 coeAppUi->ActivateViewL( TVwsViewId( KFSEmailUiUid, SettingsViewId ), |
|
420 TUid::Uid(KMailSettingsOpenPluginSettings), pkgOut ); |
|
421 } |
|
422 |
|
423 else if ( aIsEmptyMail ) |
|
424 { |
|
425 // While starting the empty editor. This would be the case when |
|
426 // write message - > Email - > Freestle |
|
427 TUid editorCommand = TUid::Uid( KEditorCmdCreateNew ); |
|
428 TEditorLaunchParams params; |
|
429 // ETrue makes editor close application when it exits |
|
430 params.iActivatedExternally = ETrue; |
|
431 params.iMailboxId = TFSMailMsgId( aPluginId, aId ); |
|
432 TPckgBuf<TEditorLaunchParams> buf( params ); |
|
433 coeAppUi->ActivateViewL( TVwsViewId( KFSEmailUiUid, MailEditorId ), |
|
434 editorCommand, buf ); |
|
435 } |
|
436 else |
|
437 { |
|
438 //While starting the editor with some data. This would be the case when |
|
439 // ex: notepadfile-> options- > send -> Email - > Freestle |
|
440 CFSMailClient* mailClient = CFSMailClient::NewL(); |
|
441 CleanupClosePushL(*mailClient); // +1 mailClient |
|
442 CFSMailBox* mailBox = mailClient->GetMailBoxByUidL( |
|
443 TFSMailMsgId( aPluginId, aId )); |
|
444 CleanupStack::PushL( mailBox ); // +2 mailBox |
|
445 |
|
446 TUid editorCommand = TUid::Uid( KEditorCmdOpen ); |
|
447 TEditorLaunchParams params; |
|
448 params.iExtra=NULL; |
|
449 params.iActivatedExternally = ETrue; |
|
450 params.iMailboxId = TFSMailMsgId( aPluginId, aId ); |
|
451 |
|
452 // <cmail> S60 UID update |
|
453 const TUid KFreestyleEmailCenRep = {0x2001E277}; |
|
454 // </cmail> S60 UID update |
|
455 CRepository* repository( NULL ); |
|
456 TUint mId = 0; |
|
457 TRAPD( ret, repository = CRepository::NewL( KFreestyleEmailCenRep ) ); |
|
458 if ( ret == KErrNone ) |
|
459 { |
|
460 CleanupStack::PushL( repository ); |
|
461 TInt rval; |
|
462 TInt messageId; |
|
463 rval = repository->Get( KFreestyleMtmMessageId, messageId ); |
|
464 if( rval != KErrNone) |
|
465 { |
|
466 } |
|
467 mId = messageId; |
|
468 CleanupStack::PopAndDestroy( repository ); |
|
469 } |
|
470 params.iMsgId = TFSMailMsgId( aPluginId, mId ); |
|
471 params.iFolderId = mailBox->GetStandardFolderId( EFSDraftsFolder ); |
|
472 |
|
473 CleanupStack::PopAndDestroy( mailBox ); // -2 mailBox |
|
474 CleanupStack::PopAndDestroy( mailClient ); // -1 mailClient, close() will be called |
|
475 |
|
476 TPckgBuf<TEditorLaunchParams> buf( params ); |
|
477 coeAppUi->ActivateViewL( TVwsViewId( KFSEmailUiUid, MailEditorId ), |
|
478 editorCommand, buf ); |
|
479 |
|
480 } |
|
481 } |
|
482 |
|
483 // --------------------------------------------------------------------------- |
|
484 // CFsSendAsHelper::DisplayMailboxNotAvailableNote |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 void CFsSendAsHelper::DisplayMailboxNotAvailableNoteL() |
|
488 { |
|
489 FUNC_LOG; |
|
490 |
|
491 if ( !iMassStorageNote ) |
|
492 { |
|
493 CEikonEnv* env( CEikonEnv::Static() ); |
|
494 ASSERT( env ); |
|
495 TParse parse; |
|
496 parse.Set( KFreestyleEmailUiResourceFileName, &KDC_APP_RESOURCE_DIR, NULL ); |
|
497 TFileName fileName( parse.FullName() ); |
|
498 BaflUtils::NearestLanguageFile( env->FsSession(), fileName ); |
|
499 TInt offset( env->AddResourceFileL( fileName ) ); |
|
500 TRAPD( error, iMassStorageNote = StringLoader::LoadL( R_MASS_STORAGE_OFFLINE ) ); |
|
501 env->DeleteResourceFile( offset ); |
|
502 User::LeaveIfError( error ); |
|
503 } |
|
504 CAknWarningNote* note = new (ELeave) CAknWarningNote( ETrue ); |
|
505 note->ExecuteLD( *iMassStorageNote ); |
|
506 } |
|
507 |
|
508 // --------------------------------------------------------------------------- |
|
509 // CFsSendAsHelper::IsMailboxAvailable |
|
510 // --------------------------------------------------------------------------- |
|
511 // |
|
512 TInt CFsSendAsHelper::IsMailboxAvailable( TInt aPluginId ) |
|
513 { |
|
514 const TUint KEasPluginId = 0x2000B020; |
|
515 const TUint KOzPluginId = 0x20021362; |
|
516 |
|
517 TInt retVal( KErrNone ); |
|
518 |
|
519 if ( aPluginId == KEasPluginId || aPluginId == KOzPluginId ) |
|
520 { |
|
521 RUsb usb; |
|
522 if ( usb.Connect() == KErrNone ) |
|
523 { |
|
524 TUsbServiceState state = EUsbServiceIdle; |
|
525 usb.GetCurrentState( state ); |
|
526 |
|
527 TInt personalityId( 0 ); |
|
528 usb.GetCurrentPersonalityId( personalityId ); |
|
529 usb.Close(); |
|
530 |
|
531 if ( state == EUsbServiceStarted && |
|
532 personalityId == KUsbPersonalityIdMS ) |
|
533 { |
|
534 // The operation cannot be fulfilled in mass storage mode for |
|
535 // MfE or Ozone boxes, show note detailing the situation. |
|
536 TRAP_IGNORE( DisplayMailboxNotAvailableNoteL() ); |
|
537 retVal = KErrNotSupported; |
|
538 } |
|
539 } |
|
540 } |
|
541 return retVal; |
|
542 } |