ipsservices/ipssosplugin/src/ipsplgcreatereplymessageoperation.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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 CIpsPlgCreateReplyMessageOperation.
       
    15 *
       
    16 */
       
    17 
       
    18 // <qmail>
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "emailtrace.h"
       
    23 #include "ipsplgheaders.h"
       
    24 
       
    25 // LOCAL CONSTANTS AND MACROS
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // CIpsPlgCreateReplyMessageOperation::CIpsPlgCreateReplyMessageOperation
       
    31 // ----------------------------------------------------------------------------
       
    32 //
       
    33 CIpsPlgCreateReplyMessageOperation::CIpsPlgCreateReplyMessageOperation(
       
    34     CIpsPlgSmtpService* aSmtpService,
       
    35     CMsvSession& aMsvSession,
       
    36     TRequestStatus& aObserverRequestStatus,
       
    37     TMsvPartList aPartList,
       
    38     TMsvId aMailBoxId,
       
    39     TMsvId aOriginalMessageId, 
       
    40     MFSMailRequestObserver& aOperationObserver,
       
    41     const TInt aRequestId ) 
       
    42     :
       
    43     CIpsPlgCreateMessageOperation(
       
    44         aSmtpService,
       
    45         aMsvSession,
       
    46         aObserverRequestStatus,
       
    47         KMsvNullIndexEntryId,
       
    48         aPartList,
       
    49         aMailBoxId,
       
    50         aOperationObserver,
       
    51         aRequestId),
       
    52     iOriginalMessageId(aOriginalMessageId)
       
    53     {
       
    54     FUNC_LOG;
       
    55     }
       
    56 
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // CIpsPlgCreateReplyMessageOperation::NewL
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 CIpsPlgCreateReplyMessageOperation* CIpsPlgCreateReplyMessageOperation::NewL(
       
    63     CIpsPlgSmtpService* aSmtpService,
       
    64     CMsvSession& aMsvSession,
       
    65     TRequestStatus& aObserverRequestStatus,
       
    66     TMsvPartList aPartList,
       
    67     TMsvId aMailBoxId,
       
    68     TMsvId aOriginalMessageId, 
       
    69     MFSMailRequestObserver& aOperationObserver,
       
    70     const TInt aRequestId )
       
    71     {
       
    72     FUNC_LOG;
       
    73     CIpsPlgCreateReplyMessageOperation* self =
       
    74         new (ELeave) CIpsPlgCreateReplyMessageOperation(
       
    75             aSmtpService, 
       
    76             aMsvSession, 
       
    77             aObserverRequestStatus,
       
    78             aPartList, 
       
    79             aMailBoxId, 
       
    80             aOriginalMessageId, 
       
    81             aOperationObserver, 
       
    82             aRequestId );
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85     CleanupStack::Pop( self ); 
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CIpsPlgCreateReplyMessageOperation::~CIpsPlgCreateReplyMessageOperation
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 CIpsPlgCreateReplyMessageOperation::~CIpsPlgCreateReplyMessageOperation()
       
    94     {
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // CIpsPlgCreateReplyMessageOperation::RunL
       
    99 // ----------------------------------------------------------------------------
       
   100 //
       
   101 void CIpsPlgCreateReplyMessageOperation::RunL()
       
   102     {
       
   103     FUNC_LOG;
       
   104 
       
   105     if( iStatus.Int() == KErrNone )
       
   106         {
       
   107         CFSMailMessage* newMessage = NULL;
       
   108         
       
   109         // new message creation has finished and we have an id...
       
   110         TMsvId msgId = TMsvId();
       
   111         TRAPD( err, msgId = GetIdFromProgressL( iOperation->FinalProgress() ) );
       
   112             
       
   113         if( err == KErrNone )
       
   114             {
       
   115             //  ...so we can create an FS type message
       
   116             newMessage = iSmtpService->CreateFSMessageAndSetFlagsL( 
       
   117                     msgId, iOriginalMessageId, iMailBoxId );
       
   118             CleanupStack::PushL( newMessage ); // ***
       
   119         
       
   120             // dig out new reply message's header
       
   121             CMsvEntry* cEntry = iMsvSession.GetEntryL( msgId );
       
   122             CleanupStack::PushL( cEntry ); // ***
       
   123             CMsvStore* store = cEntry->ReadStoreL();
       
   124             CleanupStack::PushL( store ); // ***
       
   125             if( store->IsPresentL( KUidMsgFileIMailHeader ) == EFalse )
       
   126                  {
       
   127                  User::Leave(KErrCorrupt);
       
   128                  }
       
   129             CImHeader* header = CImHeader::NewLC(); // ***
       
   130             header->RestoreL( *store );
       
   131             
       
   132             // Start handling recipients
       
   133             HBufC* emailAddr( NULL );
       
   134             CFSMailAddress* fsAddr( NULL );
       
   135             
       
   136             // copy to recipients            
       
   137             TInt toRecipientCount( header->ToRecipients().Count() );
       
   138             for( TInt i = 0; i < toRecipientCount; i++ )
       
   139                 {
       
   140                 emailAddr = header->ToRecipients()[i].AllocLC(); // ***
       
   141                 fsAddr = CFSMailAddress::NewLC(); // ***
       
   142                 fsAddr->SetEmailAddress( *emailAddr ); // Copy created
       
   143                 newMessage->AppendToRecipient( fsAddr ); // No copy
       
   144                 CleanupStack::Pop( fsAddr ); // fsAddr belong now to fsMsg
       
   145                 CleanupStack::PopAndDestroy( emailAddr ); // emailAddr not used
       
   146                 }
       
   147 
       
   148             // get additional recipients (reply all case)
       
   149             if( iPartList & KMsvMessagePartRecipient )
       
   150                 {
       
   151                 // check if CC recipient read from header was present in To field
       
   152                 // of original message. If so, copy it into To recipients.
       
   153                 // 
       
   154                 CMsvEntry* tmpEntry = iMsvSession.GetEntryL( iOriginalMessageId );
       
   155                 CleanupStack::PushL( tmpEntry ); // ***
       
   156                 CMsvStore* tmpStore = tmpEntry->ReadStoreL();
       
   157                 CleanupStack::PushL( tmpStore ); // ***
       
   158                 if( tmpStore->IsPresentL( KUidMsgFileIMailHeader ) )
       
   159                     {
       
   160                     CImHeader* tmpHeader = CImHeader::NewLC(); // ***
       
   161                     tmpHeader->RestoreL( *tmpStore );
       
   162                     
       
   163                     TInt originalToRecipientsCount = tmpHeader->ToRecipients().Count(); 
       
   164                     TBool present = EFalse;
       
   165                     for( TInt i = 0; i < header->CcRecipients().Count(); i++ )
       
   166                         {
       
   167                         emailAddr = header->CcRecipients()[i].AllocLC(); // ***
       
   168                         fsAddr = CFSMailAddress::NewLC(); // ***
       
   169                         fsAddr->SetEmailAddress( *emailAddr ); // Copy created
       
   170                         
       
   171                         present = EFalse;
       
   172                         for( TInt j = 0; j < originalToRecipientsCount; j++ )
       
   173                             {
       
   174                             if( emailAddr->Find( tmpHeader->ToRecipients()[j]) != KErrNotFound )
       
   175                                 {
       
   176                                 present = ETrue;
       
   177                                 break;
       
   178                                 }
       
   179                             }
       
   180                         
       
   181                         if( present )
       
   182                             {
       
   183                             newMessage->AppendToRecipient( fsAddr ); // No copy
       
   184                             }
       
   185                         else
       
   186                             {
       
   187                             newMessage->AppendCCRecipient( fsAddr ); // No copy
       
   188                             }
       
   189                         
       
   190                         CleanupStack::Pop( fsAddr ); // fsAddr belong now to fsMsg
       
   191                         CleanupStack::PopAndDestroy( emailAddr ); // emailAddr not used
       
   192                         }
       
   193                     CleanupStack::PopAndDestroy( tmpHeader );
       
   194                     }
       
   195                 CleanupStack::PopAndDestroy( 2, tmpEntry );
       
   196                 
       
   197                 // copy bcc recipients
       
   198                 for( TInt i = 0; i < header->BccRecipients().Count(); i++ )
       
   199                     {
       
   200                     emailAddr = header->BccRecipients()[i].AllocLC(); // ***
       
   201                     fsAddr = CFSMailAddress::NewLC(); // ***
       
   202                     fsAddr->SetEmailAddress( *emailAddr ); // Copy created
       
   203                     newMessage->AppendBCCRecipient( fsAddr ); // No copy
       
   204                     CleanupStack::Pop( fsAddr ); // fsAddr belong now to fsMsg
       
   205                     CleanupStack::PopAndDestroy( emailAddr ); // emailAddr not used
       
   206                     }
       
   207                 }
       
   208                         
       
   209             CleanupStack::PopAndDestroy( 3, cEntry ); // header, store, cEntry
       
   210             CleanupStack::Pop( newMessage ); // fsMsg is given to client
       
   211             
       
   212             // save the added recipients to the message
       
   213             newMessage->SaveMessageL();
       
   214             }
       
   215         
       
   216         // relay the created message (observer takes ownership)
       
   217         SignalFSObserver( iStatus.Int(), newMessage );        
       
   218         }
       
   219     
       
   220     // nothing left to process, so complete the observer
       
   221     TRequestStatus* status = &iObserverRequestStatus;
       
   222     User::RequestComplete( status, iStatus.Int() );
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CIpsPlgCreateReplyMessageOperation::StartMessageCreationL
       
   227 // ----------------------------------------------------------------------------
       
   228 //
       
   229 void CIpsPlgCreateReplyMessageOperation::StartMessageCreationL()
       
   230     {
       
   231     FUNC_LOG;
       
   232     delete iOperation;
       
   233     iOperation = NULL;
       
   234     
       
   235     // Start a new operation, execution continues in RunL 
       
   236     // once the operation has finished.
       
   237     iOperation = CImEmailOperation::CreateReplyL(
       
   238             iStatus, 
       
   239             iMsvSession,
       
   240             iOriginalMessageId,
       
   241             KMsvDraftEntryId, 
       
   242             iPartList, 
       
   243             KIpsPlgReplySubjectFormat,
       
   244             KMsvEmailTypeListMHTMLMessage,
       
   245             //0,
       
   246             KUidMsgTypeSMTP);
       
   247     }
       
   248 
       
   249 //  End of File
       
   250 
       
   251 // </qmail>