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