emailservices/emailcommon/src/CFSMailMessage.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 23 2dc6caa42ec3
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    13 *
    13 *
    14 * Description:  common email object
    14 * Description:  common email object
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <nmcommonheaders.h>
       
    19 #include "emailtrace.h"
    18 #include "emailtrace.h"
    20 #include <apgcli.h>
    19 #include <apgcli.h>
    21 #include <apmrec.h>
    20 #include <apmrec.h>
    22 #include <mmf/common/mmfcontrollerpluginresolver.h> // CleanupResetAndDestroy
    21 #include <mmf/common/mmfcontrollerpluginresolver.h> // CleanupResetAndDestroy
    23 
    22 
    27 //</cmail>
    26 //</cmail>
    28 #include "CFSMailRequestHandler.h"
    27 #include "CFSMailRequestHandler.h"
    29 #include "CFSMailRequestObserver.h"
    28 #include "CFSMailRequestObserver.h"
    30 
    29 
    31 //<qmail>
    30 //<qmail>
       
    31 #include <nmcommonheaders.h>
    32 #include "nmmessage.h"
    32 #include "nmmessage.h"
    33 //</qmail>
    33 //</qmail>
    34 
    34 
    35 // ================= MEMBER FUNCTIONS ==========================================
    35 // ================= MEMBER FUNCTIONS ==========================================
    36 
    36 
    37 // -----------------------------------------------------------------------------
    37 // -----------------------------------------------------------------------------
    38 // CFSMailMessage::NewLC
    38 // CFSMailMessage::NewLC
    39 // -----------------------------------------------------------------------------
    39 // -----------------------------------------------------------------------------
    40 EXPORT_C CFSMailMessage * CFSMailMessage::NewLC( TFSMailMsgId aMessageId )
    40 EXPORT_C CFSMailMessage * CFSMailMessage::NewLC(TFSMailMsgId aMessageId)
    41 {
    41 {
    42     FUNC_LOG;
    42     FUNC_LOG;
    43     CFSMailMessage* message = new (ELeave) CFSMailMessage();
    43   	CFSMailMessage* message = new (ELeave) CFSMailMessage();
    44     CleanupStack:: PushL(message);
    44   	CleanupStack:: PushL(message);
    45     message->ConstructL( aMessageId );
    45   	message->ConstructL( aMessageId );
    46     return message;
    46   	return message;
    47 } 
    47 } 
    48 
    48 
    49 // -----------------------------------------------------------------------------
    49 // -----------------------------------------------------------------------------
    50 // CFSMailMessage::NewL
    50 // CFSMailMessage::NewL
    51 // -----------------------------------------------------------------------------
    51 // -----------------------------------------------------------------------------
    52 EXPORT_C CFSMailMessage * CFSMailMessage::NewL( TFSMailMsgId aMessageId )
    52 EXPORT_C CFSMailMessage * CFSMailMessage::NewL(TFSMailMsgId aMessageId)
    53 {
    53 {
    54     FUNC_LOG;
    54     FUNC_LOG;
    55     CFSMailMessage* message =  CFSMailMessage::NewLC(aMessageId);
    55   	CFSMailMessage* message =  CFSMailMessage::NewLC(aMessageId);
    56     CleanupStack:: Pop(message);
    56   	CleanupStack:: Pop(message);
    57     return message;
    57   	return message;
    58 }
    58 }
    59 
    59 
    60 // <qmail>
    60 // <qmail>
    61 // -----------------------------------------------------------------------------
    61 // -----------------------------------------------------------------------------
    62 // CFSMailMessage::NewL
    62 // CFSMailMessage::NewL
    76 // CFSMailMessage::ConstructL
    76 // CFSMailMessage::ConstructL
    77 // -----------------------------------------------------------------------------
    77 // -----------------------------------------------------------------------------
    78 void CFSMailMessage::ConstructL( TFSMailMsgId aMessageId )
    78 void CFSMailMessage::ConstructL( TFSMailMsgId aMessageId )
    79 {
    79 {
    80     FUNC_LOG;
    80     FUNC_LOG;
       
    81 // <qmail>
    81     // Base class initialization
    82     // Base class initialization
    82     CFSMailMessagePart::ConstructL( aMessageId, TFSMailMsgId() );
    83     CFSMailMessagePart::ConstructL( aMessageId, TFSMailMsgId() );
       
    84 // </qmail>
    83 }
    85 }
    84 
    86 
    85 // <qmail>
    87 // <qmail>
    86 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
    87 // CFSMailMessage::ConstructL
    89 // CFSMailMessage::ConstructL
    96 // </qmail>
    98 // </qmail>
    97 
    99 
    98 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
    99 // CFSMailMessage::CFSMailMessage
   101 // CFSMailMessage::CFSMailMessage
   100 // -----------------------------------------------------------------------------
   102 // -----------------------------------------------------------------------------
   101 CFSMailMessage::CFSMailMessage()
   103 CFSMailMessage::CFSMailMessage() : CFSMailMessagePart()
   102 {
   104 {
   103     FUNC_LOG;
   105     FUNC_LOG;
   104     // set request handler pointer
       
   105     iRequestHandler = static_cast<CFSMailRequestHandler*>(Dll::Tls());
       
   106 }
   106 }
   107 
   107 
   108 // -----------------------------------------------------------------------------
   108 // -----------------------------------------------------------------------------
   109 // CFSMailMessage::~CFSMailMessage
   109 // CFSMailMessage::~CFSMailMessage
   110 // -----------------------------------------------------------------------------
   110 // -----------------------------------------------------------------------------
   111 EXPORT_C CFSMailMessage::~CFSMailMessage()
   111 EXPORT_C CFSMailMessage::~CFSMailMessage()
   112 {
   112 {
   113     FUNC_LOG;
   113     FUNC_LOG;
       
   114 // <qmail>
   114     iMessageBufferForAsyncOp.Reset();
   115     iMessageBufferForAsyncOp.Reset();
       
   116 // </qmail>
   115 }
   117 }
   116 
   118 
   117 // -----------------------------------------------------------------------------
   119 // -----------------------------------------------------------------------------
   118 // CFSMailMessage::SaveMessageL
   120 // CFSMailMessage::SaveMessageL
   119 // -----------------------------------------------------------------------------
   121 // -----------------------------------------------------------------------------
   120 EXPORT_C void CFSMailMessage::SaveMessageL()
   122 EXPORT_C void CFSMailMessage::SaveMessageL()
   121 {
   123 	{
   122     FUNC_LOG;
   124     FUNC_LOG;
   123     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
   125 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
   124         {
   126 		{
   125         plugin->StoreMessageL(GetMailBoxId(),*this);
   127 		plugin->StoreMessageL(GetMailBoxId(),*this);
   126         }
   128 		}
   127 }
   129 	}
   128 
   130 
   129 //<qmail>
   131 //<qmail>
   130 // -----------------------------------------------------------------------------
   132 // -----------------------------------------------------------------------------
   131 // CFSMailMessage::SaveMessageL
   133 // CFSMailMessage::SaveMessageL
   132 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
   203 // -----------------------------------------------------------------------------
   205 // -----------------------------------------------------------------------------
   204 // CFSMailMessage::AddNewAttachmentL
   206 // CFSMailMessage::AddNewAttachmentL
   205 // -----------------------------------------------------------------------------
   207 // -----------------------------------------------------------------------------
   206 EXPORT_C CFSMailMessagePart* CFSMailMessage::AddNewAttachmentL( RFile& aFile,
   208 EXPORT_C CFSMailMessagePart* CFSMailMessage::AddNewAttachmentL( RFile& aFile,
   207                                                                 const TDesC8& aMimeType )
   209                                                                 const TDesC8& aMimeType )
   208 {
   210     {
   209     FUNC_LOG;
   211     FUNC_LOG;
   210     
   212     
   211     CFSMailMessagePart* newPart = NULL;
   213     CFSMailMessagePart* newPart = NULL;
   212     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
   214     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
   213         {
   215         {
   247         
   249         
   248         // set flag
   250         // set flag
   249         SetFlag(EFSMsgFlag_Attachments);
   251         SetFlag(EFSMsgFlag_Attachments);
   250         }
   252         }
   251     return newPart;
   253     return newPart;
   252 }
   254     }
   253 
   255 
   254 // -----------------------------------------------------------------------------
   256 // -----------------------------------------------------------------------------
   255 // CFSMailMessage::AddNewAttachmentL
   257 // CFSMailMessage::AddNewAttachmentL
   256 // -----------------------------------------------------------------------------
   258 // -----------------------------------------------------------------------------
   257 EXPORT_C CFSMailMessagePart* CFSMailMessage::AddNewAttachmentL( const TDesC& aFilePath,
   259 EXPORT_C CFSMailMessagePart* CFSMailMessage::AddNewAttachmentL(	const TDesC& aFilePath,
   258                                 const TFSMailMsgId /*aInsertBefore*/ )
   260 																const TFSMailMsgId /*aInsertBefore*/ )
   259 {
   261     {
   260     FUNC_LOG;
   262     FUNC_LOG;
   261 
   263 
   262     CFSMailMessagePart* newPart = NULL;
   264 	CFSMailMessagePart* newPart = NULL;
   263   
   265 	
   264     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
   266 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
   265         {
   267 		{
   266         // use recognizer to find out ContentType 
   268 	    // use recognizer to find out ContentType 
   267         RApaLsSession apaSession;
   269 	    RApaLsSession apaSession;
   268         TDataRecognitionResult dataType;
   270 		TDataRecognitionResult dataType;
   269         TBufC8<KMaxDataTypeLength> buf;
   271 		TBufC8<KMaxDataTypeLength> buf;
   270         User::LeaveIfError(apaSession.Connect());
   272 	    User::LeaveIfError(apaSession.Connect());
   271         User::LeaveIfError(apaSession.RecognizeData(aFilePath, buf, dataType));
   273 	    User::LeaveIfError(apaSession.RecognizeData(aFilePath, buf, dataType));
   272         apaSession.Close();
   274 	    apaSession.Close();
   273 
   275 
   274         // Create new message part with correct Content-Type
   276 	    // Create new message part with correct Content-Type
   275         TBuf<KMaxDataTypeLength> contentType;
   277 		TBuf<KMaxDataTypeLength> contentType;
   276         contentType.Copy(dataType.iDataType.Des());
   278 		contentType.Copy(dataType.iDataType.Des());
   277         newPart = plugin->NewChildPartFromFileL( GetMailBoxId(),
   279 	    newPart = plugin->NewChildPartFromFileL( 	GetMailBoxId(),
   278                             GetFolderId(),
   280 	    											GetFolderId(),
   279                             GetMessageId(),
   281 	    											GetMessageId(),
   280                             GetPartId(),
   282 	    											GetPartId(),
   281                             contentType,
   283 	    											contentType,
   282                             aFilePath );
   284 	    											aFilePath );
   283 
   285 
   284     
   286 		
   285         // Set attachment name
   287 	    // Set attachment name
   286         newPart->SetAttachmentNameL(aFilePath);
   288 	    newPart->SetAttachmentNameL(aFilePath);
   287 
   289 
   288         // store message part
   290 		// store message part
   289         newPart->SaveL();
   291 		newPart->SaveL();
   290 
   292 
   291         // set flag
   293 		// set flag
   292         SetFlag(EFSMsgFlag_Attachments);
   294         SetFlag(EFSMsgFlag_Attachments);
   293     }  
   295 		}
       
   296 		
   294     return newPart;
   297     return newPart;
   295 }
   298 }
   296 
   299 
   297 // <qmail>
   300 // <qmail>
   298 // -----------------------------------------------------------------------------
   301 // -----------------------------------------------------------------------------
   352 // -----------------------------------------------------------------------------
   355 // -----------------------------------------------------------------------------
   353 // CFSMailMessage::AttachmentListL
   356 // CFSMailMessage::AttachmentListL
   354 // -----------------------------------------------------------------------------
   357 // -----------------------------------------------------------------------------
   355 EXPORT_C void CFSMailMessage::AttachmentListL(
   358 EXPORT_C void CFSMailMessage::AttachmentListL(
   356     RPointerArray<CFSMailMessagePart>& aParts )
   359     RPointerArray<CFSMailMessagePart>& aParts )
   357 {
   360     {
   358     FUNC_LOG;
   361     FUNC_LOG;
   359     // First list all message parts
   362     // First list all message parts
   360     AppendAttachmentsL( aParts ); 
   363     AppendAttachmentsL( aParts ); 
   361 
   364 
   362     // special case, if single part content type is not given,
   365     // special case, if single part content type is not given,
   368     else
   371     else
   369         {
   372         {
   370         // find plain text body part from the list
   373         // find plain text body part from the list
   371         CFSMailMessagePart* txtPart = FindBodyPartL(KFSMailContentTypeTextPlain);
   374         CFSMailMessagePart* txtPart = FindBodyPartL(KFSMailContentTypeTextPlain);
   372         CleanupStack::PushL( txtPart );
   375         CleanupStack::PushL( txtPart );
   373         if ( txtPart )
   376         if ( txtPart
       
   377           && txtPart->AttachmentNameL().Length() == 0 ) // real attachments have names
   374             {
   378             {
   375             // remove plain text body part from attachment list
   379             // remove plain text body part from attachment list
   376             for ( TInt ii = aParts.Count() - 1; ii >= 0; --ii )
   380             for ( TInt ii = aParts.Count() - 1; ii >= 0; --ii )
   377                 {
   381                 {
   378                 if ( aParts[ii]->GetPartId() == txtPart->GetPartId() )
   382                 if ( aParts[ii]->GetPartId() == txtPart->GetPartId() )
   386         CleanupStack::PopAndDestroy( txtPart );
   390         CleanupStack::PopAndDestroy( txtPart );
   387 
   391 
   388         // find  html body part from the list
   392         // find  html body part from the list
   389         CFSMailMessagePart* htmlPart = FindBodyPartL(KFSMailContentTypeTextHtml);
   393         CFSMailMessagePart* htmlPart = FindBodyPartL(KFSMailContentTypeTextHtml);
   390         CleanupStack::PushL( htmlPart );
   394         CleanupStack::PushL( htmlPart );
   391         if ( htmlPart )
   395         if ( htmlPart
       
   396           && htmlPart->AttachmentNameL().Length() == 0 ) // real attachments have names
   392             {
   397             {
   393             // remove html body part from attachment list
   398             // remove html body part from attachment list
   394             for ( TInt ii = aParts.Count() - 1; ii >= 0; --ii )
   399             for ( TInt ii = aParts.Count() - 1; ii >= 0; --ii )
   395                 {
   400                 {
   396                 if ( aParts[ii]->GetPartId() == htmlPart->GetPartId() )
   401                 if ( aParts[ii]->GetPartId() == htmlPart->GetPartId() )
   404         CleanupStack::PopAndDestroy( htmlPart );
   409         CleanupStack::PopAndDestroy( htmlPart );
   405         }
   410         }
   406 
   411 
   407     iMessageParts.ResetAndDestroy();
   412     iMessageParts.ResetAndDestroy();
   408     iReadMessageParts = ETrue;
   413     iReadMessageParts = ETrue;
   409 }
   414     }
   410 
   415 
       
   416 // <qmail>
   411 // -----------------------------------------------------------------------------
   417 // -----------------------------------------------------------------------------
   412 // CFSMailMessage::PlainTextBodyPartL
   418 // CFSMailMessage::PlainTextBodyPartL
   413 // -----------------------------------------------------------------------------
   419 // -----------------------------------------------------------------------------
   414 EXPORT_C CFSMailMessagePart* CFSMailMessage::PlainTextBodyPartL(
   420 EXPORT_C CFSMailMessagePart* CFSMailMessage::PlainTextBodyPartL(
   415         TFSMailMessagePartDataSource aDataSource)
   421         TFSMailMessagePartDataSource aDataSource)
   416 {
   422 {
   417     FUNC_LOG;
   423     FUNC_LOG;
   418     CFSMailMessagePart* part = FindBodyPartL(KFSMailContentTypeTextPlain, aDataSource);
   424     CFSMailMessagePart* part = FindBodyPartL(KFSMailContentTypeTextPlain, aDataSource);
   419     
   425     
   420     // special case, single part content type is not given
   426     // special case, single part content type is not given
   421     // <qmail>
   427     if(part == NULL && iMessageParts.Count() == 1 && iMessageParts[0]->GetContentType().Length() == 0)
   422     if(!part && iMessageParts.Count() == 1 && iMessageParts[0]->GetContentType().Length() == 0)
   428     	{
   423     // </qmail>
   429     	part = iMessageParts[0];
   424         {
   430     	iMessageParts.Remove(0);
   425         part = iMessageParts[0];
   431     	}
   426         iMessageParts.Remove(0);
       
   427         }
       
   428     iMessageParts.ResetAndDestroy();
   432     iMessageParts.ResetAndDestroy();
   429     iReadMessageParts = ETrue;
   433 	iReadMessageParts = ETrue;
   430     return part;
   434     return part;
   431 }
   435 }
   432 
   436 // </qmail>
       
   437 
       
   438 // <qmail>
   433 // -----------------------------------------------------------------------------
   439 // -----------------------------------------------------------------------------
   434 // CFSMailMessage::HtmlBodyPartL
   440 // CFSMailMessage::HtmlBodyPartL
   435 // -----------------------------------------------------------------------------
   441 // -----------------------------------------------------------------------------
   436 EXPORT_C CFSMailMessagePart* CFSMailMessage::HtmlBodyPartL(
   442 EXPORT_C CFSMailMessagePart* CFSMailMessage::HtmlBodyPartL(
   437         TFSMailMessagePartDataSource aDataSource)
   443         TFSMailMessagePartDataSource aDataSource)
   438 {
   444 {
   439     FUNC_LOG;
   445     FUNC_LOG;
   440     CFSMailMessagePart* part = FindBodyPartL(KFSMailContentTypeTextHtml, aDataSource);
   446     CFSMailMessagePart* part = FindBodyPartL(KFSMailContentTypeTextHtml, aDataSource);
   441     iMessageParts.ResetAndDestroy();
   447     iMessageParts.ResetAndDestroy();
   442     iReadMessageParts = ETrue;
   448 	iReadMessageParts = ETrue;
   443     return part;
   449     return part;
   444 }
   450 }
   445 
   451 // </qmail>
       
   452 
       
   453 // <qmail>
   446 // -----------------------------------------------------------------------------
   454 // -----------------------------------------------------------------------------
   447 // CFSMailMessage::IsMessageL
   455 // CFSMailMessage::IsMessageL
   448 // -----------------------------------------------------------------------------
   456 // -----------------------------------------------------------------------------
   449 EXPORT_C TBool CFSMailMessage::IsMessageL() const
   457 EXPORT_C TBool CFSMailMessage::IsMessageL() const
   450 {
   458 	{
   451     FUNC_LOG;
   459     FUNC_LOG;
   452     return CFSMailMessagePart::IsMessageL();
   460     return CFSMailMessagePart::IsMessageL();
   453 	}
   461 	}
       
   462 // </qmail>
   454 
   463 
   455 // -----------------------------------------------------------------------------
   464 // -----------------------------------------------------------------------------
   456 // CFSMailMessage::ContentTypeParameters()
   465 // CFSMailMessage::ContentTypeParameters()
   457 // -----------------------------------------------------------------------------
   466 // -----------------------------------------------------------------------------
   458 CDesCArray& CFSMailMessage::ContentTypeParameters()
   467 CDesCArray& CFSMailMessage::ContentTypeParameters()
   459 {
   468 {
   460     FUNC_LOG;
   469     FUNC_LOG;
   461     CDesCArray* faked = NULL;
   470    CDesCArray* faked = NULL;
   462     return *faked;
   471    return *faked;
   463 }
   472 }
   464 
   473 
   465 // -----------------------------------------------------------------------------
   474 // -----------------------------------------------------------------------------
   466 // CFSMailMessage::DoAttachmentListL
   475 // CFSMailMessage::DoAttachmentListL
   467 // -----------------------------------------------------------------------------
   476 // -----------------------------------------------------------------------------
   468 void CFSMailMessage::DoAttachmentListL( RPointerArray<CFSMailMessagePart>& aParts )
   477 void CFSMailMessage::DoAttachmentListL( RPointerArray<CFSMailMessagePart>& aParts )
   469 {
   478     {
   470     FUNC_LOG;
   479     FUNC_LOG;
   471     AttachmentListL(aParts);
   480     AttachmentListL(aParts);
   472 }
   481     }
   473 
   482 
   474 //<qmail>
   483 //<qmail>
   475 // -----------------------------------------------------------------------------
   484 // -----------------------------------------------------------------------------
   476 // CFSMailMessage::GetNmMessage
   485 // CFSMailMessage::GetNmMessage
   477 // It does not fill the list of child parts
   486 // It does not fill the list of child parts