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