emailservices/emailclientapi/src/emailmessage.cpp
changeset 47 f83bd4ae1fe3
child 62 a8c646b56683
equal deleted inserted replaced
45:780f926bc26c 47:f83bd4ae1fe3
       
     1 /*
       
     2 * Copyright (c) 2010 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: This file implements class CEmailMessage.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    19 #include <viewclipartner.h>
       
    20 #include <vwsdefpartner.h>
       
    21 #else
       
    22 #include <viewcli.h>
       
    23 #include <vwsdef.h>
       
    24 #endif // SYMBIAN_ENABLE_SPLIT_HEADERS
       
    25 
       
    26 #include "emailmessage.h"
       
    27 #include "emailaddress.h"
       
    28 #include "emailapiutils.h"
       
    29 #include "emailclientapi.hrh"
       
    30 #include "emailapiutils.h"
       
    31 #include "emailinterfacefactoryimpl.h"
       
    32 #include "emailcontent.h"
       
    33 #include "emailtextcontent.h"
       
    34 #include "emailmultipart.h"
       
    35 #include "emailattachment.h"
       
    36 #include "cfsmailplugin.h"
       
    37 #include "cfsmailclient.h"
       
    38 
       
    39 #include <XQServiceRequest.h>
       
    40 #include "email_services_api.h"
       
    41 
       
    42 const TInt KSendMessageRequestId = 100;
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // 
       
    46 // -----------------------------------------------------------------------------
       
    47 CEmailMessage* CEmailMessage::NewL( CPluginData& aPluginData,
       
    48                                     CFSMailMessage* aFsMessage,
       
    49                                     const TDataOwner aOwner )
       
    50     {
       
    51     CEmailMessage* message = new ( ELeave ) CEmailMessage( aPluginData, aFsMessage, aOwner );
       
    52     CleanupStack::PushL( message );
       
    53     message->ConstructL();
       
    54     CleanupStack::Pop( message );
       
    55     return message;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // 
       
    60 // -----------------------------------------------------------------------------
       
    61 CEmailMessage::CEmailMessage(
       
    62         CPluginData& aPluginData,
       
    63         CFSMailMessage *aFsMessage,
       
    64         const TDataOwner aOwner)
       
    65         : iPluginData( aPluginData ), iPluginMessage( aFsMessage ), iOwner( aOwner )
       
    66     {
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // 
       
    71 // -----------------------------------------------------------------------------
       
    72 void CEmailMessage::ConstructL()
       
    73     {
       
    74     User::LeaveIfNull( iPluginMessage );
       
    75     iPlugin = iPluginData.ClaimInstanceL();
       
    76     if ( iPluginMessage )
       
    77         {
       
    78         iMessageId = TMessageId( 
       
    79             iPluginMessage->GetMessageId().Id(),
       
    80             iPluginMessage->GetFolderId().Id(), 
       
    81             iPluginMessage->GetMailBoxId().Id() );
       
    82 
       
    83         // Copy the message flags
       
    84         InitializeFlagValues();
       
    85         }
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // 
       
    90 // -----------------------------------------------------------------------------
       
    91 CEmailMessage::~CEmailMessage()
       
    92     {
       
    93     delete iPluginMessage;
       
    94     delete iSender;
       
    95     delete iReplyTo;
       
    96     delete iTextContent;
       
    97     delete iContent;
       
    98     iPluginData.ReleaseInstance();
       
    99     iAttachments.ResetAndDestroy();
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // 
       
   104 // -----------------------------------------------------------------------------
       
   105 TEmailTypeId CEmailMessage::InterfaceId() const
       
   106     {
       
   107     return KEmailIFUidMessage;
       
   108     }
       
   109     
       
   110 // -----------------------------------------------------------------------------
       
   111 // 
       
   112 // -----------------------------------------------------------------------------
       
   113 void CEmailMessage::Release()
       
   114     {
       
   115     if ( iOwner == EClientOwns )
       
   116         {
       
   117         delete this;
       
   118         }
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // 
       
   123 // -----------------------------------------------------------------------------
       
   124 const TMessageId& CEmailMessage::MessageId() const
       
   125     {
       
   126     return iMessageId;
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // 
       
   131 // -----------------------------------------------------------------------------
       
   132 MEmailAddress* CEmailMessage::SenderAddressL() const
       
   133     {
       
   134     User::LeaveIfNull( iPluginMessage );
       
   135 
       
   136     CFSMailAddress* fsAddress = iPluginMessage->GetSender();
       
   137     if ( fsAddress )
       
   138         {
       
   139         if ( !iSender )
       
   140             {
       
   141             iSender = CEmailAddress::NewL( MEmailAddress::ESender, EAPIOwns );
       
   142             }
       
   143         iSender->SetAddressL(fsAddress->GetEmailAddress());
       
   144         iSender->SetDisplayNameL(fsAddress->GetDisplayName());
       
   145         }
       
   146     else
       
   147         {
       
   148         // Sender address not defined. Delete client object as well
       
   149         delete iSender;
       
   150         iSender = NULL;
       
   151         }
       
   152     return iSender;
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // 
       
   157 // -----------------------------------------------------------------------------
       
   158 MEmailAddress* CEmailMessage::ReplyToAddressL() const
       
   159     {
       
   160     User::LeaveIfNull( iPluginMessage );
       
   161 
       
   162     const CFSMailAddress& fsAddress = iPluginMessage->GetReplyToAddress();
       
   163     if ( &fsAddress )
       
   164         {
       
   165         if ( !iReplyTo )
       
   166             {
       
   167             iReplyTo = CEmailAddress::NewL( MEmailAddress::EReplyTo, EAPIOwns );
       
   168             }
       
   169         iReplyTo->SetAddressL( fsAddress.GetEmailAddress() );
       
   170         iReplyTo->SetDisplayNameL( fsAddress.GetDisplayName() );
       
   171         }
       
   172     else
       
   173         {
       
   174         delete iReplyTo;
       
   175         iReplyTo = NULL;
       
   176         }
       
   177     return iReplyTo;
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // 
       
   182 // -----------------------------------------------------------------------------
       
   183 void CEmailMessage::SetReplyToAddressL( const MEmailAddress& aSender )
       
   184     {
       
   185     User::LeaveIfNull( iPluginMessage );
       
   186     
       
   187     CFSMailAddress *fsAddress = CFSMailAddress::NewLC();
       
   188     if ( !iReplyTo )
       
   189         {
       
   190         iReplyTo = CEmailAddress::NewL( MEmailAddress::EReplyTo, EAPIOwns );
       
   191         }
       
   192     fsAddress->SetDisplayName( aSender.DisplayName() );
       
   193     fsAddress->SetEmailAddress( aSender.Address() );
       
   194     iPluginMessage->SetReplyToAddress( fsAddress );
       
   195     iReplyTo->SetAddressL( fsAddress->GetEmailAddress() );
       
   196     iReplyTo->SetDisplayNameL( fsAddress->GetDisplayName() );
       
   197     CleanupStack::Pop();
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // 
       
   202 // -----------------------------------------------------------------------------
       
   203 TInt CEmailMessage::GetRecipientsL( const MEmailAddress::TRole aRole,
       
   204         REmailAddressArray& aRecipients ) const
       
   205     {
       
   206     if( aRole == MEmailAddress::EReplyTo ||
       
   207         aRole == MEmailAddress::ESender )
       
   208         {
       
   209         User::Leave( KErrArgument );
       
   210         }
       
   211     else 
       
   212         {
       
   213         User::LeaveIfNull( iPluginMessage );
       
   214         
       
   215         if( aRole == MEmailAddress::ETo || 
       
   216             aRole == MEmailAddress::EUndefined )
       
   217             {
       
   218             const RPointerArray<CFSMailAddress>& toRecipients =
       
   219                 iPluginMessage->GetToRecipients();
       
   220             ConvertAddressArrayL( 
       
   221                     MEmailAddress::ETo, 
       
   222                     toRecipients, aRecipients );
       
   223             }
       
   224         if( aRole == MEmailAddress::ECc || 
       
   225             aRole == MEmailAddress::EUndefined )
       
   226             {
       
   227             const RPointerArray<CFSMailAddress>& ccRecipients =
       
   228                 iPluginMessage->GetCCRecipients();
       
   229             ConvertAddressArrayL( 
       
   230                     MEmailAddress::ECc, 
       
   231                     ccRecipients, aRecipients );
       
   232             }
       
   233         if( aRole == MEmailAddress::EBcc || 
       
   234             aRole == MEmailAddress::EUndefined )
       
   235             {
       
   236             const RPointerArray<CFSMailAddress>& bccRecipients =
       
   237                 iPluginMessage->GetBCCRecipients();
       
   238             ConvertAddressArrayL( 
       
   239                     MEmailAddress::EBcc, 
       
   240                     bccRecipients, aRecipients );
       
   241             }
       
   242         }
       
   243     return aRecipients.Count();
       
   244     }
       
   245     
       
   246 // -----------------------------------------------------------------------------
       
   247 // 
       
   248 // -----------------------------------------------------------------------------
       
   249 void CEmailMessage::SetRecipientsL( const MEmailAddress::TRole aRole,
       
   250         REmailAddressArray& aRecipients )
       
   251     {
       
   252     TInt count( aRecipients.Count() );
       
   253 
       
   254     for( TInt i=0;i<count;i++ )
       
   255         {
       
   256         const MEmailAddress* address = aRecipients[i];
       
   257         CFSMailAddress* fsAddress = CFSMailAddress::NewLC();
       
   258         fsAddress->SetEmailAddress( address->Address() );
       
   259         fsAddress->SetDisplayName( address->DisplayName() );
       
   260         
       
   261         User::LeaveIfNull( iPluginMessage );
       
   262         
       
   263         if( aRole == MEmailAddress::ETo )
       
   264             {
       
   265             iPluginMessage->AppendToRecipient( fsAddress );
       
   266             }
       
   267         else if( aRole == MEmailAddress::ECc )
       
   268             {
       
   269             iPluginMessage->AppendCCRecipient( fsAddress );
       
   270             }
       
   271         else if( aRole == MEmailAddress::EBcc )
       
   272             {
       
   273             iPluginMessage->AppendBCCRecipient( fsAddress );
       
   274             }
       
   275         else
       
   276             {
       
   277             User::Leave( KErrArgument );
       
   278             }
       
   279         CleanupStack::Pop( fsAddress );
       
   280         }
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // 
       
   285 // -----------------------------------------------------------------------------
       
   286 void CEmailMessage::RemoveRecipientL( const MEmailAddress& /*aRecipient*/ )
       
   287     {
       
   288     User::Leave( KErrNotSupported );
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // 
       
   293 // -----------------------------------------------------------------------------
       
   294 TPtrC CEmailMessage::Subject() const
       
   295     {
       
   296     if ( !iPluginMessage )
       
   297         return KNullDesC();
       
   298     return iPluginMessage->GetSubject();
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // 
       
   303 // -----------------------------------------------------------------------------
       
   304 void  CEmailMessage::SetSubjectL( const TPtrC& aSubject )
       
   305     {
       
   306     User::LeaveIfNull( iPluginMessage );
       
   307     iPluginMessage->SetSubject( aSubject );
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // 
       
   312 // -----------------------------------------------------------------------------
       
   313 TTime CEmailMessage::Date() const
       
   314     {
       
   315     TTime time;
       
   316 
       
   317     if ( iPluginMessage ) {
       
   318         time = iPluginMessage->GetDate();
       
   319     }
       
   320 
       
   321     return time;
       
   322     }
       
   323 
       
   324 // -----------------------------------------------------------------------------
       
   325 // 
       
   326 // -----------------------------------------------------------------------------
       
   327 TInt CEmailMessage::Flags() const
       
   328     {
       
   329     return iFlags;
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // 
       
   334 // -----------------------------------------------------------------------------
       
   335 void CEmailMessage::SetFlag( const TUint aFlag )
       
   336     {
       
   337     iFlags |= aFlag;
       
   338     TUint flag = MapFlags( aFlag );
       
   339     if ( iPluginMessage )
       
   340         iPluginMessage->SetFlag( flag );
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // 
       
   345 // -----------------------------------------------------------------------------
       
   346 void CEmailMessage::ResetFlag( const TUint aFlag )
       
   347     {
       
   348     iFlags &= ~aFlag;
       
   349     TUint flag = MapFlags( aFlag );
       
   350     if ( iPluginMessage )
       
   351         iPluginMessage->ResetFlag( flag );
       
   352     }
       
   353 
       
   354 // -----------------------------------------------------------------------------
       
   355 // 
       
   356 // -----------------------------------------------------------------------------
       
   357 void CEmailMessage::InitializeFlagValues()
       
   358     {
       
   359     if ( !iPluginMessage )
       
   360         return;
       
   361     // 1st reset member value, then start copying different flags
       
   362     iFlags = 0;
       
   363     
       
   364     // EFlag_Read
       
   365     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_Read ) )
       
   366         {
       
   367         iFlags |= EFlag_Read;
       
   368         }
       
   369     else
       
   370         {
       
   371         iFlags &= ~EFlag_Read;
       
   372         }
       
   373     //    EFlag_Read_Locally
       
   374     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_Read_Locally ) )
       
   375         {
       
   376         iFlags |= EFlag_Read_Locally;
       
   377         }
       
   378     else
       
   379         {
       
   380         iFlags &= ~EFlag_Read_Locally;
       
   381         }    
       
   382     // EFlag_Low
       
   383     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_Low ) )
       
   384         {
       
   385         iFlags |= EFlag_Low;
       
   386         }
       
   387     else
       
   388         {
       
   389         iFlags &= ~EFlag_Low;
       
   390         }
       
   391     // EFlag_Important
       
   392     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_Important ) )
       
   393         {
       
   394         iFlags |= EFlag_Important;
       
   395         }
       
   396     else
       
   397         {
       
   398         iFlags &= ~EFlag_Important;
       
   399         }
       
   400     // EFlag_FollowUpComplete
       
   401     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_FollowUpComplete ) )
       
   402         {
       
   403         iFlags |= EFlag_FollowUpComplete;
       
   404         }
       
   405     else
       
   406         {
       
   407         iFlags &= ~EFlag_FollowUpComplete;
       
   408         }
       
   409     // EFlag_FollowUp
       
   410     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_FollowUp ) )
       
   411         {
       
   412         iFlags |= EFlag_FollowUp;
       
   413         }
       
   414     else
       
   415         {
       
   416         iFlags &= ~EFlag_FollowUp;
       
   417         }
       
   418     // EFlag_Attachments
       
   419     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_Attachments ) )
       
   420         {
       
   421         iFlags |= EFlag_Attachments;
       
   422         }
       
   423     else
       
   424         {
       
   425         iFlags &= ~EFlag_Attachments;
       
   426         }
       
   427     // EFlag_Multiple
       
   428     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_Multiple ) )
       
   429         {
       
   430         iFlags |= EFlag_Multiple;
       
   431         }
       
   432     else
       
   433         {
       
   434         iFlags &= ~EFlag_Multiple;
       
   435         }
       
   436     // EFlag_CalendarMsg
       
   437     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_CalendarMsg ) )
       
   438         {
       
   439         iFlags |= EFlag_CalendarMsg;
       
   440         }
       
   441     else
       
   442         {
       
   443         iFlags &= ~EFlag_CalendarMsg;
       
   444         }
       
   445     // EFlag_Answered
       
   446     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_Answered ) )
       
   447         {
       
   448         iFlags |= EFlag_Answered;
       
   449         }
       
   450     else
       
   451         {
       
   452         iFlags &= ~EFlag_Answered;
       
   453         }
       
   454     // EFlag_Forwarded
       
   455     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_Forwarded ) )
       
   456         {
       
   457         iFlags |= EFlag_Forwarded;
       
   458         }
       
   459     else
       
   460         {
       
   461         iFlags &= ~EFlag_Forwarded;
       
   462         }
       
   463     // EFlag_OnlyToMe
       
   464     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_OnlyToMe ) )
       
   465         {
       
   466         iFlags |= EFlag_OnlyToMe;
       
   467         }
       
   468     else
       
   469         {
       
   470         iFlags &= ~EFlag_OnlyToMe;
       
   471         }
       
   472     // EFlag_RemoteDeleted
       
   473     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_RemoteDeleted ) )
       
   474         {
       
   475         iFlags |= EFlag_RemoteDeleted;
       
   476         }
       
   477     else
       
   478         {
       
   479         iFlags &= ~EFlag_RemoteDeleted;
       
   480         }
       
   481     // EFlag_HasMsgSender 
       
   482     if ( iPluginMessage->IsFlagSet( EFSMsgFlag_HasMsgSender ) )
       
   483         {
       
   484         iFlags |= EFlag_HasMsgSender;
       
   485         }
       
   486     else
       
   487         {
       
   488         iFlags &= ~EFlag_HasMsgSender;
       
   489         }
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // 
       
   494 // -----------------------------------------------------------------------------
       
   495 MEmailMessageContent* CEmailMessage::ContentL() const
       
   496     {
       
   497     if ( iTextContent )
       
   498         {
       
   499         return iTextContent;
       
   500         }
       
   501     if ( iContent )
       
   502         {
       
   503         return iContent;
       
   504         }
       
   505 
       
   506     User::LeaveIfNull( iPluginMessage );
       
   507     
       
   508     RPointerArray<CFSMailMessagePart> parts;
       
   509     CleanupResetAndDestroyPushL( parts );
       
   510     iPluginMessage->ChildPartsL( parts );
       
   511     TInt count( parts.Count() );
       
   512     if( count == 0 )
       
   513         {
       
   514         /* No content, return NULL */
       
   515         CleanupStack::PopAndDestroy( &parts ); // in case heap allocated but not used
       
   516         return NULL;
       
   517         }
       
   518     CFSMailMessagePart* part = parts[0];
       
   519     TContentType contentType( part->GetContentType() );
       
   520     TMessageContentId msgContentId = TMessageContentId(
       
   521                         part->GetPartId().Id(),
       
   522                         iMessageId.iId,
       
   523                         iMessageId.iFolderId.iId,
       
   524                         iMessageId.iFolderId.iMailboxId );
       
   525 
       
   526     if ( contentType.Equals( KFSMailContentTypeTextPlain ) ||
       
   527         contentType.Equals( KFSMailContentTypeTextHtml ) )
       
   528         {                                
       
   529         iTextContent = CEmailTextContent::NewL(iPluginData, msgContentId, part, EAPIOwns );
       
   530         parts[0] = NULL; // ownership of part transferred
       
   531         }
       
   532     else if ( contentType.Equals( KFSMailContentTypeMultipartMixed ) ||
       
   533               contentType.Equals( KFSMailContentTypeMultipartAlternative ) ||
       
   534               contentType.Equals( KFSMailContentTypeMultipartDigest ) ||
       
   535               contentType.Equals( KFSMailContentTypeMultipartRelated ) ||
       
   536               contentType.Equals( KFSMailContentTypeMultipartParallel ) )
       
   537         {
       
   538         iContent = CEmailMultipart::NewL(iPluginData, msgContentId, part, EAPIOwns);
       
   539         parts[0] = NULL; // ownership of part transferred
       
   540         }
       
   541 
       
   542     CleanupStack::PopAndDestroy( &parts ); // parts
       
   543 
       
   544     if (iTextContent)
       
   545         {
       
   546         return iTextContent;
       
   547         }
       
   548     return iContent;
       
   549     }
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // 
       
   553 // -----------------------------------------------------------------------------
       
   554 void CEmailMessage::SetContentL( const MEmailMessageContent*  aContent )
       
   555     {
       
   556     User::LeaveIfNull( aContent );
       
   557     MEmailTextContent* textContent = aContent->AsTextContentOrNull();
       
   558     if ( textContent )
       
   559         {
       
   560         if ( iTextContent )
       
   561             {
       
   562             delete iTextContent; // Destroy old content
       
   563             }
       
   564         iTextContent = dynamic_cast<CEmailTextContent*>( textContent );
       
   565         if ( iTextContent )
       
   566             {
       
   567             iTextContent->SetOwner( EAPIOwns );
       
   568             }
       
   569         return;
       
   570         }
       
   571     MEmailMultipart* mPart = aContent->AsMultipartOrNull();
       
   572     if ( mPart )
       
   573         {
       
   574         if ( iContent )
       
   575             {
       
   576             delete iContent;
       
   577             }
       
   578         iContent = dynamic_cast<CEmailMultipart*>( mPart );
       
   579         if ( iContent )
       
   580             {
       
   581             iContent->SetOwner( EAPIOwns );
       
   582             }
       
   583         }    
       
   584     }
       
   585 
       
   586 // -----------------------------------------------------------------------------
       
   587 // 
       
   588 // -----------------------------------------------------------------------------
       
   589 void CEmailMessage::SetPlainTextBodyL( const TDesC& aPlainText )
       
   590     {
       
   591     if ( iTextContent )
       
   592         {
       
   593         iTextContent->SetTextL( MEmailTextContent::EPlainText, aPlainText );
       
   594         return;
       
   595         }
       
   596 
       
   597     User::LeaveIfNull( iPluginMessage );
       
   598 
       
   599     CFSMailMessagePart* msgTextPart = iPluginMessage->PlainTextBodyPartL();
       
   600     
       
   601     if( !msgTextPart )
       
   602         {
       
   603         msgTextPart = iPluginMessage->NewChildPartL( TFSMailMsgId(), KFSMailContentTypeTextPlain );
       
   604         }
       
   605     CleanupStack::PushL( msgTextPart );
       
   606 
       
   607     TMessageContentId msgContentId = MessageContentId( msgTextPart->GetPartId().Id() );
       
   608 
       
   609     msgTextPart->SetContentType( KFSMailContentTypeTextPlain );
       
   610     iTextContent = CEmailTextContent::NewL( iPluginData, msgContentId, msgTextPart, EAPIOwns );
       
   611     if (iTextContent)
       
   612         {
       
   613         iTextContent->SetTextL( MEmailTextContent::EPlainText, aPlainText );
       
   614         }
       
   615     CleanupStack::Pop( msgTextPart );
       
   616 
       
   617     return;
       
   618 
       
   619     }
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // 
       
   623 // -----------------------------------------------------------------------------
       
   624 MEmailAttachment* CEmailMessage::AddAttachmentL( const TDesC& aFullPath )
       
   625     {
       
   626     User::LeaveIfNull( iPluginMessage );
       
   627 
       
   628     CFSMailMessagePart* part = iPluginMessage->AddNewAttachmentL( aFullPath, TFSMailMsgId() );
       
   629     CleanupStack::PushL( part );    
       
   630     CEmailAttachment* att = CEmailAttachment::NewLC( iPluginData, iMsgContentId, part, EAPIOwns );
       
   631     iAttachments.AppendL( att );
       
   632     CleanupStack::Pop( 2, part );
       
   633 
       
   634     return att;
       
   635     }
       
   636 
       
   637 // -----------------------------------------------------------------------------
       
   638 // 
       
   639 // -----------------------------------------------------------------------------
       
   640 MEmailAttachment* CEmailMessage::AddAttachmentL( RFile& aFile )
       
   641     {
       
   642     User::LeaveIfNull( iPluginMessage );
       
   643     TBufC8 <1> mime;
       
   644     CFSMailMessagePart* part = iPluginMessage->AddNewAttachmentL( aFile, mime );
       
   645     CleanupStack::PushL( part );
       
   646     CEmailAttachment* att = CEmailAttachment::NewLC( iPluginData, iMsgContentId, part, EAPIOwns );
       
   647     iAttachments.AppendL( att );
       
   648 
       
   649     CleanupStack::Pop( 2, part );
       
   650 
       
   651     return att;
       
   652     }
       
   653 
       
   654 // -----------------------------------------------------------------------------
       
   655 // 
       
   656 // -----------------------------------------------------------------------------
       
   657 TInt CEmailMessage::GetAttachmentsL( REmailAttachmentArray& aAttachments )
       
   658     {
       
   659     User::LeaveIfNull( iPluginMessage );
       
   660 
       
   661     RPointerArray<CFSMailMessagePart> attachments;
       
   662     CleanupResetAndDestroyPushL( attachments );
       
   663     iPluginMessage->AttachmentListL( attachments );
       
   664     const TInt count( attachments.Count() );
       
   665     for (TInt i = 0; i < count; i++)
       
   666         {
       
   667         TMessageContentId msgContentId = MessageContentId( attachments[i]->GetPartId().Id() );
       
   668 
       
   669         CEmailAttachment* att = CEmailAttachment::NewL( 
       
   670             iPluginData, msgContentId, attachments[i], EClientOwns );
       
   671 
       
   672         aAttachments.AppendL( att );
       
   673         }
       
   674     CleanupStack::Pop( &attachments );
       
   675     return count;
       
   676     }
       
   677 
       
   678 // -----------------------------------------------------------------------------
       
   679 // 
       
   680 // -----------------------------------------------------------------------------
       
   681 void CEmailMessage::RemoveAttachmentL( const MEmailAttachment& /*aAttachment*/ )
       
   682     {
       
   683     User::Leave( KErrNotSupported );
       
   684     }
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // 
       
   688 // -----------------------------------------------------------------------------
       
   689 const TFolderId& CEmailMessage::ParentFolderId() const
       
   690     {
       
   691     return iMessageId.iFolderId;
       
   692     }
       
   693 
       
   694 // -----------------------------------------------------------------------------
       
   695 // 
       
   696 // -----------------------------------------------------------------------------
       
   697 void CEmailMessage::SaveChangesL()
       
   698     {
       
   699     User::LeaveIfNull( iPluginMessage );
       
   700     
       
   701     TFSMailMsgId mailboxId( 
       
   702             FsMsgId( iPluginData, iMessageId.iFolderId.iMailboxId ) );
       
   703     
       
   704     iPlugin->StoreMessageL( mailboxId, *iPluginMessage );
       
   705     }
       
   706 
       
   707 // -----------------------------------------------------------------------------
       
   708 // 
       
   709 // -----------------------------------------------------------------------------
       
   710 void CEmailMessage::SendL()
       
   711     {
       
   712     User::LeaveIfNull( iPluginMessage );
       
   713     
       
   714     if ( iEventLoop.isRunning() )
       
   715         User::Leave( KErrInUse );
       
   716     
       
   717     SaveChangesL();
       
   718     iError = KErrNone;
       
   719     iPlugin->SendMessageL( *iPluginMessage, *this, KSendMessageRequestId );
       
   720     iEventLoop.exec();
       
   721 
       
   722     User::LeaveIfError( iError );
       
   723     }
       
   724 
       
   725 // -----------------------------------------------------------------------------
       
   726 // 
       
   727 // -----------------------------------------------------------------------------
       
   728 void CEmailMessage::RequestResponseL( TFSProgress aEvent, TInt aRequestId )
       
   729     {
       
   730     iError = aEvent.iError;
       
   731 
       
   732     if ( aRequestId == KSendMessageRequestId &&
       
   733             aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
   734         iEventLoop.quit();
       
   735     }
       
   736 
       
   737 // -----------------------------------------------------------------------------
       
   738 // 
       
   739 // -----------------------------------------------------------------------------
       
   740 void CEmailMessage::ConvertAddressArrayL(
       
   741         const MEmailAddress::TRole aRole,
       
   742         const RPointerArray<CFSMailAddress>& aSrc,
       
   743         REmailAddressArray& aDst ) const
       
   744     {
       
   745     for ( TInt i=0; i<aSrc.Count(); i++ )
       
   746         {
       
   747         CEmailAddress* recipient = CreateAddressLC( aRole, *aSrc[i] );
       
   748         aDst.AppendL( recipient );
       
   749         CleanupStack::Pop( recipient );
       
   750         }
       
   751     }
       
   752 
       
   753 // -----------------------------------------------------------------------------
       
   754 //
       
   755 // -----------------------------------------------------------------------------
       
   756 CEmailAddress* CEmailMessage::CreateAddressLC(
       
   757         const MEmailAddress::TRole aRole, 
       
   758         CFSMailAddress& aFsAddress ) const
       
   759     {
       
   760     CEmailAddress* address = CEmailAddress::NewLC( aRole, EClientOwns );
       
   761     TDesC& temp1 = aFsAddress.GetEmailAddress();
       
   762     if ( &temp1 )
       
   763         {
       
   764         address->SetAddressL( temp1 );
       
   765         }
       
   766     TDesC& temp2 = aFsAddress.GetDisplayName();
       
   767     if ( &temp2 )
       
   768         {
       
   769         address->SetDisplayNameL( temp2 );
       
   770         }   
       
   771     return address;
       
   772     }
       
   773 
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 // -----------------------------------------------------------------------------
       
   777 TUint CEmailMessage::MapFlags( const TUint& aFlag )
       
   778     {
       
   779     TUint flag = 0;
       
   780     switch( aFlag )
       
   781         {
       
   782         case EFlag_Read:
       
   783             flag = EFSMsgFlag_Read;
       
   784             break;
       
   785         case EFlag_Read_Locally:
       
   786             flag = EFSMsgFlag_Read_Locally;
       
   787             break;
       
   788         case EFlag_Low:
       
   789             flag = EFSMsgFlag_Low;
       
   790             break;
       
   791         case EFlag_Important:
       
   792             flag = EFSMsgFlag_Important;
       
   793             break;
       
   794         case EFlag_FollowUpComplete:
       
   795             flag = EFSMsgFlag_FollowUpComplete;
       
   796             break;
       
   797         case EFlag_FollowUp:
       
   798             flag = EFSMsgFlag_FollowUp;
       
   799             break;
       
   800         case EFlag_Attachments:
       
   801             flag = EFSMsgFlag_Attachments;
       
   802             break;
       
   803         case EFlag_Multiple:
       
   804             flag = EFSMsgFlag_Multiple;
       
   805             break;
       
   806         case EFlag_CalendarMsg:
       
   807             flag = EFSMsgFlag_CalendarMsg;
       
   808             break;
       
   809         case EFlag_Answered:
       
   810             flag = EFSMsgFlag_Answered;
       
   811             break;
       
   812         case EFlag_Forwarded:
       
   813             flag = EFSMsgFlag_Forwarded;
       
   814             break;
       
   815         case EFlag_OnlyToMe:
       
   816             flag = EFSMsgFlag_OnlyToMe;
       
   817             break;
       
   818         case EFlag_RemoteDeleted:
       
   819             flag = EFSMsgFlag_RemoteDeleted;
       
   820             break;
       
   821         case EFlag_HasMsgSender:
       
   822             flag = EFSMsgFlag_HasMsgSender;
       
   823             break;
       
   824         default:
       
   825             break;
       
   826         }
       
   827     return flag;
       
   828     }
       
   829 
       
   830 // -----------------------------------------------------------------------------
       
   831 //
       
   832 // -----------------------------------------------------------------------------
       
   833 void CEmailMessage::ShowMessageViewerL()
       
   834     {   
       
   835     bool syncronous;
       
   836 
       
   837     XQServiceRequest request(
       
   838        emailInterfaceNameMessage,
       
   839        emailOperationViewMessage,
       
   840        syncronous );
       
   841 
       
   842     TFSMailMsgId mailboxId = FsMsgId( iPluginData, iMessageId.iFolderId.iMailboxId );
       
   843     TFSMailMsgId folderId = FsMsgId( iPluginData, iMessageId.iFolderId );
       
   844     TFSMailMsgId messageId = FsMsgId( iPluginData, iMessageId );
       
   845 
       
   846     QList<QVariant> list;
       
   847     list.append( mailboxId.Id() );
       
   848     list.append( folderId.Id() );
       
   849     list.append( messageId.Id() );
       
   850     request.setArguments( list );
       
   851 
       
   852     QVariant returnValue;
       
   853     if ( !request.send( returnValue ) )
       
   854         User::Leave( KErrGeneral );
       
   855     }
       
   856 
       
   857 // -----------------------------------------------------------------------------
       
   858 // Launches Email application and new reply message in editor. 
       
   859 // The method follows "fire and forget" pattern, returns immediately.
       
   860 // -----------------------------------------------------------------------------
       
   861 void CEmailMessage::ReplyToMessageL( const TBool /*aReplyToAll*/ )
       
   862     {
       
   863     User::Leave( KErrNotSupported );
       
   864     }
       
   865 
       
   866 // -----------------------------------------------------------------------------
       
   867 //
       
   868 // -----------------------------------------------------------------------------
       
   869 void CEmailMessage::ForwardMessageL()
       
   870     {
       
   871     User::Leave( KErrNotSupported );
       
   872     }
       
   873 
       
   874 // -----------------------------------------------------------------------------
       
   875 //
       
   876 // -----------------------------------------------------------------------------
       
   877 TMessageContentId CEmailMessage::MessageContentId( TEntryId aContentId ) const
       
   878     {
       
   879     TMessageContentId msgContentId = TMessageContentId( 
       
   880                     aContentId,
       
   881                     iMessageId.iId,
       
   882                     iMessageId.iFolderId.iId,
       
   883                     iMessageId.iFolderId.iMailboxId );
       
   884     return msgContentId;
       
   885     }
       
   886 
       
   887 // -----------------------------------------------------------------------------
       
   888 //
       
   889 // -----------------------------------------------------------------------------
       
   890 TContentType::TContentType( const TDesC& aContentType ) : iContentType( aContentType )
       
   891     {
       
   892     _LIT( KSeparator, ";" );
       
   893     TInt end = aContentType.Find( KSeparator );
       
   894     if ( end != KErrNotFound )
       
   895         {
       
   896         iContentType.Set( aContentType.Left( end ) );
       
   897         }
       
   898     }
       
   899 
       
   900 // -----------------------------------------------------------------------------
       
   901 //
       
   902 // -----------------------------------------------------------------------------
       
   903 TBool TContentType::Equals( const TDesC& aContentType )
       
   904     {
       
   905     TBool ret = iContentType.CompareF( aContentType );
       
   906     if ( ret == 0  )
       
   907         return ETrue;
       
   908     else
       
   909         return EFalse;
       
   910     }
       
   911 
       
   912 // End of file