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