htiui/HtiServicePlugins/HtiMessagesServicePlugin/src/MessageMgmntHandler.cpp
branchRCL_3
changeset 6 69ec17276f52
parent 3 2703485a934c
child 11 454d022d514b
equal deleted inserted replaced
5:685c7418c584 6:69ec17276f52
   372         }
   372         }
   373     HBufC16* attPath = ExtractDesLC( aData, position, 1 );
   373     HBufC16* attPath = ExtractDesLC( aData, position, 1 );
   374     TBool isNew = (TBool)aData[position];
   374     TBool isNew = (TBool)aData[position];
   375     TBool isUnread = (TBool)aData[position+1];
   375     TBool isUnread = (TBool)aData[position+1];
   376     TFolder folder = (TFolder)aData[position+2];
   376     TFolder folder = (TFolder)aData[position+2];
       
   377     TInt extraAttNum;
       
   378     position += 3;
       
   379     TInt len = aData.Length();
       
   380     if( aData.Length() > position )
       
   381         {
       
   382         extraAttNum = (TInt)aData[position];
       
   383         }
       
   384     else
       
   385         {
       
   386         extraAttNum = 0;
       
   387         }
       
   388     position++;
   377 
   389 
   378     HTI_LOG_TEXT( "Creating MMS Client MTM" );
   390     HTI_LOG_TEXT( "Creating MMS Client MTM" );
   379     CMmsClientMtm* mmsMtm = NULL;
   391     CMmsClientMtm* mmsMtm = NULL;
   380     TRAPD( err , mmsMtm = ( CMmsClientMtm* )iMtmReg->NewMtmL(
   392     TRAPD( err , mmsMtm = ( CMmsClientMtm* )iMtmReg->NewMtmL(
   381             KUidMsgTypeMultimedia ) );
   393             KUidMsgTypeMultimedia ) );
   537         tentry.iBioType = KUidMsgSubTypeMmsAudioMsg.iUid;
   549         tentry.iBioType = KUidMsgSubTypeMmsAudioMsg.iUid;
   538         }
   550         }
   539 
   551 
   540     // handle attachment
   552     // handle attachment
   541     TBool attachmentsExist = EFalse;
   553     TBool attachmentsExist = EFalse;
   542     if ( attPath->Length() > 0 )
   554 	if ( attPath->Length() > 0 )
   543         {
   555 		{
   544         HTI_LOG_TEXT( "Handling attachment..." );
   556 		HTI_LOG_TEXT( "Handling attachment..." );
   545         // check that attachment exists
   557 		// check that attachment exists
   546         RFs fsSession;
   558 		RFs fsSession;
   547         if ( fsSession.Connect() != KErrNone )
   559 		if ( fsSession.Connect() != KErrNone )
   548             {
   560 			{
   549             HTI_LOG_FORMAT( "Error in connecting to file server session: %d", err );
   561 			HTI_LOG_FORMAT( "Error in connecting to file server session: %d", err );
   550             SendErrorMessageL( KErrCouldNotConnect, KErrorRfsConnectFailed );
   562 			SendErrorMessageL( KErrCouldNotConnect, KErrorRfsConnectFailed );
   551             CleanupStack::PopAndDestroy( store );
   563 			CleanupStack::PopAndDestroy( store );
   552             CleanupStack::PopAndDestroy( mmsMtm );
   564 			CleanupStack::PopAndDestroy( mmsMtm );
   553             CleanupStack::PopAndDestroy( attPath );
   565 			CleanupStack::PopAndDestroy( attPath );
   554             CleanupStack::PopAndDestroy( body );
   566 			CleanupStack::PopAndDestroy( body );
   555             CleanupStack::PopAndDestroy( description );
   567 			CleanupStack::PopAndDestroy( description );
   556             CleanupStack::PopAndDestroy( fromTo );
   568 			CleanupStack::PopAndDestroy( fromTo );
   557             return;
   569 			return;
   558             }
   570 			}
   559 
   571 
   560         TBool fileExists = BaflUtils::FileExists( fsSession, attPath->Des() );
   572 		TBool fileExists = BaflUtils::FileExists( fsSession, attPath->Des() );
   561         fsSession.Close();
   573 		fsSession.Close();
   562         if ( !fileExists )
   574 		if ( !fileExists )
   563             {
   575 			{
   564             HTI_LOG_TEXT( "Attachment file not found" );
   576 			HTI_LOG_TEXT( "Attachment file not found" );
   565             SendErrorMessageL( KErrPathNotFound, KErrorAttachmentNotFound );
   577 			SendErrorMessageL( KErrPathNotFound, KErrorAttachmentNotFound );
   566             store->RevertL();
   578 			store->RevertL();
   567             CleanupStack::PopAndDestroy( store );
   579 			CleanupStack::PopAndDestroy( store );
   568             CleanupStack::PopAndDestroy( mmsMtm );
   580 			CleanupStack::PopAndDestroy( mmsMtm );
   569             CleanupStack::PopAndDestroy( attPath );
   581 			CleanupStack::PopAndDestroy( attPath );
   570             CleanupStack::PopAndDestroy( body );
   582 			CleanupStack::PopAndDestroy( body );
   571             CleanupStack::PopAndDestroy( description );
   583 			CleanupStack::PopAndDestroy( description );
   572             CleanupStack::PopAndDestroy( fromTo );
   584 			CleanupStack::PopAndDestroy( fromTo );
   573             return;
   585 			return;
       
   586 			}
       
   587 		else
       
   588 			{
       
   589 			// save the attachment
       
   590 			TParse parser;
       
   591 			parser.Set( *attPath, NULL, NULL);
       
   592 			TFileName shortFileName = parser.NameAndExt();
       
   593 
       
   594 			// get the mime type
       
   595 			RApaLsSession ls;
       
   596 			User::LeaveIfError( ls.Connect() );
       
   597 			CleanupClosePushL( ls );
       
   598 			TUid appUid;
       
   599 			TDataType dataType;
       
   600 			ls.AppForDocument( *attPath, appUid, dataType );
       
   601 			CleanupStack::PopAndDestroy(); // ls
       
   602 			TPtrC8 mimeType = dataType.Des8();
       
   603 
       
   604 			// attachment settings
       
   605 			// ownership of attachment will be transferred
       
   606 			CMsvAttachment* attachment = CMsvAttachment::NewL(
       
   607 					CMsvAttachment::EMsvFile );
       
   608 			attachment->SetAttachmentNameL( shortFileName );
       
   609 			attachment->SetMimeTypeL( mimeType );
       
   610 
       
   611 			// save
       
   612 			CWaiter* waiter = CWaiter::NewLC();
       
   613 			attachMan.AddAttachmentL( *attPath, attachment, waiter->iStatus );
       
   614 			waiter->StartAndWait();
       
   615 			CleanupStack::PopAndDestroy( waiter );
       
   616 			attachmentsExist = ETrue;
       
   617 			}
       
   618 		}
       
   619 
       
   620     do
       
   621 		{
       
   622 		HBufC16* attPath2;
       
   623        if(extraAttNum-- > 0)
       
   624             {
       
   625             attPath2 = ExtractDesLC( aData, position, 1 );
   574             }
   626             }
   575         else
   627         else
   576             {
   628             {
   577             // save the attachment
   629             break;
   578             TParse parser;
   630             }
   579             parser.Set( *attPath, NULL, NULL);
   631 
   580             TFileName shortFileName = parser.NameAndExt();
   632 		if ( attPath2->Length() > 0 )
   581 
   633 			{
   582             // get the mime type
   634 			HTI_LOG_TEXT( "Handling attachment..." );
   583             RApaLsSession ls;
   635 			// check that attachment exists
   584             User::LeaveIfError( ls.Connect() );
   636 			RFs fsSession;
   585             CleanupClosePushL( ls );
   637 			if ( fsSession.Connect() != KErrNone )
   586             TUid appUid;
   638 				{
   587             TDataType dataType;
   639 				HTI_LOG_FORMAT( "Error in connecting to file server session: %d", err );
   588             ls.AppForDocument( *attPath, appUid, dataType );
   640 				SendErrorMessageL( KErrCouldNotConnect, KErrorRfsConnectFailed );
   589             CleanupStack::PopAndDestroy(); // ls
   641 				CleanupStack::PopAndDestroy( store );
   590             TPtrC8 mimeType = dataType.Des8();
   642 				CleanupStack::PopAndDestroy( mmsMtm );
   591 
   643 				CleanupStack::PopAndDestroy( attPath );
   592             // attachment settings
   644 				CleanupStack::PopAndDestroy( body );
   593             // ownership of attachment will be transferred
   645 				CleanupStack::PopAndDestroy( description );
   594             CMsvAttachment* attachment = CMsvAttachment::NewL(
   646 				CleanupStack::PopAndDestroy( fromTo );
   595                     CMsvAttachment::EMsvFile );
   647 				CleanupStack::PopAndDestroy( attPath2 );
   596             attachment->SetAttachmentNameL( shortFileName );
   648 				return;
   597             attachment->SetMimeTypeL( mimeType );
   649 				}
   598 
   650 	
   599             // save
   651 			TBool fileExists = BaflUtils::FileExists( fsSession, attPath2->Des() );
   600             CWaiter* waiter = CWaiter::NewLC();
   652 			fsSession.Close();
   601             attachMan.AddAttachmentL( *attPath, attachment, waiter->iStatus );
   653 			if ( !fileExists )
   602             waiter->StartAndWait();
   654 				{
   603             CleanupStack::PopAndDestroy( waiter );
   655 				HTI_LOG_TEXT( "Attachment file not found" );
   604             attachmentsExist = ETrue;
   656 				SendErrorMessageL( KErrPathNotFound, KErrorAttachmentNotFound );
   605             }
   657 				store->RevertL();
   606         }
   658 				CleanupStack::PopAndDestroy( store );
   607 
   659 				CleanupStack::PopAndDestroy( mmsMtm );
       
   660 				CleanupStack::PopAndDestroy( attPath );
       
   661 				CleanupStack::PopAndDestroy( body );
       
   662 				CleanupStack::PopAndDestroy( description );
       
   663 				CleanupStack::PopAndDestroy( fromTo );
       
   664 				CleanupStack::PopAndDestroy( attPath2 );
       
   665 				return;
       
   666 				}
       
   667 			else
       
   668 				{
       
   669 				// save the attachment
       
   670 				TParse parser;
       
   671 				parser.Set( *attPath2, NULL, NULL);
       
   672 				TFileName shortFileName = parser.NameAndExt();
       
   673 	
       
   674 				// get the mime type
       
   675 				RApaLsSession ls;
       
   676 				User::LeaveIfError( ls.Connect() );
       
   677 				CleanupClosePushL( ls );
       
   678 				TUid appUid;
       
   679 				TDataType dataType;
       
   680 				ls.AppForDocument( *attPath2, appUid, dataType );
       
   681 				CleanupStack::PopAndDestroy(); // ls
       
   682 				TPtrC8 mimeType = dataType.Des8();
       
   683 	
       
   684 				// attachment settings
       
   685 				// ownership of attachment will be transferred
       
   686 				CMsvAttachment* attachment = CMsvAttachment::NewL(
       
   687 						CMsvAttachment::EMsvFile );
       
   688 				attachment->SetAttachmentNameL( shortFileName );
       
   689 				attachment->SetMimeTypeL( mimeType );
       
   690 	
       
   691 				// save
       
   692 				CWaiter* waiter = CWaiter::NewLC();
       
   693 				attachMan.AddAttachmentL( *attPath2, attachment, waiter->iStatus );
       
   694 				waiter->StartAndWait();
       
   695 				CleanupStack::PopAndDestroy( waiter );
       
   696 				attachmentsExist = ETrue;
       
   697 				}
       
   698 
       
   699 			CleanupStack::PopAndDestroy( attPath2 );
       
   700 			}
       
   701 		} while(ETrue);
   608     // save the changes made to the message store
   702     // save the changes made to the message store
   609     store->CommitL();
   703     store->CommitL();
   610     CleanupStack::PopAndDestroy( store );
   704     CleanupStack::PopAndDestroy( store );
   611 
   705 
   612     // save the message
   706     // save the message
   689         HBufC16* body = ExtractDesLC( aData, position, 2 );
   783         HBufC16* body = ExtractDesLC( aData, position, 2 );
   690         HBufC16* attPath = ExtractDesLC( aData, position, 1 );
   784         HBufC16* attPath = ExtractDesLC( aData, position, 1 );
   691         TBool isNew = (TBool)aData[position];
   785         TBool isNew = (TBool)aData[position];
   692         TBool isUnread = (TBool)aData[position+1];
   786         TBool isUnread = (TBool)aData[position+1];
   693         TFolder folder = (TFolder)aData[position+2];
   787         TFolder folder = (TFolder)aData[position+2];
       
   788 	    TInt extraAttNum;
       
   789 	    position += 3;
       
   790 	    TInt len = aData.Length();
       
   791 	    if( aData.Length() > position )
       
   792 	        {
       
   793 	        extraAttNum = (TInt)aData[position];
       
   794 	        }
       
   795 	    else
       
   796 	        {
       
   797 	        extraAttNum = 0;
       
   798 	        }
       
   799 	    position++;
   694 
   800 
   695         HTI_LOG_TEXT( "Creating SMTP Client MTM" );
   801         HTI_LOG_TEXT( "Creating SMTP Client MTM" );
   696         CSmtpClientMtm* smtpMtm = NULL;
   802         CSmtpClientMtm* smtpMtm = NULL;
   697         TRAPD( err, smtpMtm = ( CSmtpClientMtm* )iMtmReg->NewMtmL(
   803         TRAPD( err, smtpMtm = ( CSmtpClientMtm* )iMtmReg->NewMtmL(
   698                 KUidMsgTypeSMTP ) );
   804                 KUidMsgTypeSMTP ) );
   843                 }
   949                 }
   844 
   950 
   845             CleanupStack::PopAndDestroy(); // fsSession
   951             CleanupStack::PopAndDestroy(); // fsSession
   846             }
   952             }
   847 
   953 
       
   954 		do
       
   955 			{
       
   956 			HBufC16* attPath2;
       
   957 			if(extraAttNum-- > 0)
       
   958 	            {
       
   959 	            attPath2 = ExtractDesLC( aData, position, 1 );
       
   960 	            }
       
   961 	        else
       
   962 	            {
       
   963 	            break;
       
   964 	            }
       
   965             // check that attachment exists
       
   966             RFs fsSession;
       
   967             if ( fsSession.Connect() != KErrNone )
       
   968                 {
       
   969                 HTI_LOG_FORMAT( "Error in connecting to file server session: %d", err );
       
   970                 SendErrorMessageL( KErrCouldNotConnect, KErrorRfsConnectFailed );
       
   971                 CleanupStack::PopAndDestroy( smtpMtm );
       
   972                 CleanupStack::PopAndDestroy( attPath );
       
   973                 CleanupStack::PopAndDestroy( body );
       
   974                 CleanupStack::PopAndDestroy( description );
       
   975                 CleanupStack::PopAndDestroy( fromTo );
       
   976                 CleanupStack::PopAndDestroy( attPath2 );
       
   977                 return;
       
   978                 }
       
   979             CleanupClosePushL( fsSession );
       
   980 
       
   981             TBool fileExists = BaflUtils::FileExists( fsSession, attPath2->Des() );
       
   982             if ( !fileExists )
       
   983                 {
       
   984                 HTI_LOG_TEXT( "Attachment file not found" );
       
   985                 SendErrorMessageL( KErrPathNotFound, KErrorAttachmentNotFound );
       
   986                 CleanupStack::PopAndDestroy(); // fsSession
       
   987                 CleanupStack::PopAndDestroy( smtpMtm );
       
   988                 CleanupStack::PopAndDestroy( attPath );
       
   989                 CleanupStack::PopAndDestroy( body );
       
   990                 CleanupStack::PopAndDestroy( description );
       
   991                 CleanupStack::PopAndDestroy( fromTo );
       
   992                 CleanupStack::PopAndDestroy( attPath2 );
       
   993                 return;
       
   994                 }
       
   995             else
       
   996                 {
       
   997                 // get the mime type
       
   998                 HTI_LOG_TEXT( "Getting the attachment's mime type" );
       
   999                 RApaLsSession ls;
       
  1000                 User::LeaveIfError( ls.Connect() );
       
  1001                 TUid appUid;
       
  1002                 TDataType dataType;
       
  1003                 ls.AppForDocument( *attPath2, appUid, dataType );
       
  1004                 TPtrC8 mimeType = dataType.Des8();
       
  1005 
       
  1006                 HTI_LOG_TEXT( "Adding the attachment" );
       
  1007                 CWaiter* waiter = CWaiter::NewLC();
       
  1008                 smtpMtm->AddAttachmentL( attPath2->Des(), mimeType, charset,
       
  1009                         waiter->iStatus );
       
  1010                 waiter->StartAndWait();
       
  1011                 CleanupStack::PopAndDestroy( waiter );
       
  1012                 HTI_LOG_TEXT( "Attachment added succesfully" );
       
  1013                 ls.Close();
       
  1014                 attachmentsExist = ETrue;
       
  1015                 }
       
  1016 
       
  1017             CleanupStack::PopAndDestroy(); // fsSession
       
  1018 			CleanupStack::PopAndDestroy( attPath2 );
       
  1019 		} while(ETrue);
       
  1020 
   848         // save the message
  1021         // save the message
   849         smtpMtm->SaveMessageL();
  1022         smtpMtm->SaveMessageL();
   850 
  1023 
   851         // final fine tuning
  1024         // final fine tuning
   852         TMsvEmailEntry temailEntry = static_cast<TMsvEmailEntry>( tentry );
  1025         TMsvEmailEntry temailEntry = static_cast<TMsvEmailEntry>( tentry );
  1572                        fromToLength + descrLength +  bodyLength + attPathLength +
  1745                        fromToLength + descrLength +  bodyLength + attPathLength +
  1573                        1 + // is new
  1746                        1 + // is new
  1574                        1 + // is unread
  1747                        1 + // is unread
  1575                        1;  // folder
  1748                        1;  // folder
  1576 
  1749 
       
  1750     TInt extraAttPathLength = 0;
       
  1751     TInt extraAttNum = 0;
       
  1752     TInt extraNumLen = 0;
       
  1753     if( wholeLength < aData.Length() )
       
  1754     	{
       
  1755     	offset = wholeLength;
       
  1756         extraAttNum = aData[offset];
       
  1757         offset ++;
       
  1758 
       
  1759         extraNumLen = 1;
       
  1760 
       
  1761 	    while( offset < aData.Length() && extraAttNum > 0)
       
  1762 	    	{
       
  1763 	        extraAttPathLength += aData[offset];
       
  1764 	        extraAttPathLength ++;
       
  1765 	        extraAttNum --;
       
  1766 	        offset += 1 + aData[offset];
       
  1767 	    	}
       
  1768 	    }
       
  1769 
       
  1770 	wholeLength += extraNumLen + extraAttPathLength;
       
  1771 	
  1577     if ( wholeLength != aData.Length() )
  1772     if ( wholeLength != aData.Length() )
  1578         {
  1773         {
  1579         HTI_LOG_TEXT( "Error: wrong length of data (wholeLength)" );
  1774         HTI_LOG_TEXT( "Error: wrong length of data (wholeLength)" );
  1580         HTI_LOG_FORMAT( "Expected: %d", wholeLength );
  1775         HTI_LOG_FORMAT( "Expected: %d", wholeLength );
  1581         HTI_LOG_FORMAT( "Was:      %d", aData.Length() );
  1776         HTI_LOG_FORMAT( "Was:      %d", aData.Length() );