localconnectivityservice/obexserviceman/utils/src/vMessageHandler.cpp
changeset 0 c3e98f10fcf4
equal deleted inserted replaced
-1:000000000000 0:c3e98f10fcf4
       
     1 /*
       
     2 * Copyright (c) 2004 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "vMessageHandler.h"
       
    21 #include "obexutilsuilayer.h"
       
    22 #include "obexutilsdebug.h"
       
    23 #include "etelmm.h"
       
    24 #include <BTSapDomainPSKeys.h>
       
    25 #include <smut.h> // KUidMsgTypeSMS
       
    26 #include <smuthdr.h>
       
    27 #include <gsmupdu.h>
       
    28 #include <txtrich.h>
       
    29 #include <msvuids.h>
       
    30 
       
    31 #include <csmsaccount.h>
       
    32 
       
    33 // SMUT Unbranch
       
    34 #include <csmsgetdetdescinterface.h>
       
    35 
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 TBool CSapVMessageParser::HandleMessageL(CObexBufObject*  aReceivedObject, const TUid aMtmID,
       
    39                                         RFile& aFile, CMsvSession* aMsvSession, TTime aTime)
       
    40 {
       
    41     FLOG( _L( " CSapVMessageParser: HandleMessageL\t" ) );
       
    42 
       
    43     CSapVMessageParser* parser = CSapVMessageParser::NewLC();
       
    44     TBool isVmsg=parser->ParseMessageL(aReceivedObject, aMtmID, aFile, aTime);
       
    45     if(isVmsg)
       
    46     {
       
    47         parser->SaveSapMessageL(aMsvSession);
       
    48     }
       
    49     CleanupStack::PopAndDestroy(parser);
       
    50 
       
    51     FLOG( _L( " CSapVMessageParser: HandleMessageL: Done\t" ) );
       
    52     
       
    53     return isVmsg;
       
    54 }
       
    55 
       
    56 CSapVMessageParser* CSapVMessageParser::NewLC()
       
    57 {
       
    58     CSapVMessageParser* self = new (ELeave) CSapVMessageParser();
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61     return self;
       
    62 }
       
    63 
       
    64 void CSapVMessageParser::ConstructL()
       
    65 {
       
    66 }
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // Constructor
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 CSapVMessageParser::CSapVMessageParser()
       
    73 {
       
    74 }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // ParseMessageL
       
    78 // Recognises and parses SAP VMessage.
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 TBool CSapVMessageParser::ParseMessageL(CObexBufObject*  aReceivedObject, const TUid aMtmID,
       
    82                                         RFile& aFile, TTime aTime)
       
    83 {
       
    84     FLOG( _L( " CSapVMessageParser: ParseMessageL\t" ) );
       
    85 
       
    86     static const TInt KExpandSize = 16;
       
    87 
       
    88     iType=ESapVMessageUnknown;
       
    89 
       
    90     if( aMtmID != KUidMsgTypeBt ||
       
    91         !CheckMime(aReceivedObject->Type()) ||
       
    92         !CheckName(aReceivedObject->Name()) ||
       
    93         !IsSapConnectionActive())
       
    94     {
       
    95         FLOG( _L( " CSapVMessageParser: ParseMessageL: Unknown\t" ) );
       
    96         return EFalse;
       
    97     }
       
    98 
       
    99     CBufFlat* buffer = CBufFlat::NewL( KExpandSize );
       
   100     CleanupStack::PushL(buffer);            // 1st push
       
   101 
       
   102     TInt fileLength;
       
   103     User::LeaveIfError( aFile.Size( fileLength ) );
       
   104 
       
   105     // Read the file into buffer
       
   106     buffer->ResizeL( fileLength );
       
   107     TPtr8 temp = buffer->Ptr(0);
       
   108     TInt pos = 0;
       
   109     aFile.Seek(ESeekStart, pos);
       
   110     User::LeaveIfError( aFile.Read( temp ) );
       
   111     
       
   112     pos=0;
       
   113     aFile.Seek(ESeekStart, pos); // rewind file
       
   114 
       
   115     SimpleParseL(temp);
       
   116 
       
   117     CleanupStack::PopAndDestroy(buffer); // -1 pop
       
   118     
       
   119     iTimeReceived=aTime;
       
   120     if(aReceivedObject->Time()==TTime(0))
       
   121     {
       
   122         iTimeOriginal = aTime;
       
   123     }
       
   124     else
       
   125     {
       
   126         iTimeOriginal = aReceivedObject->Time();
       
   127     }
       
   128 
       
   129     return (iType!=ESapVMessageUnknown);
       
   130 }
       
   131 
       
   132 // ---------------------------------------------------------
       
   133 // IsSapConnectionActive
       
   134 // Recognises active SAP connection.
       
   135 // ---------------------------------------------------------
       
   136 //
       
   137 TBool CSapVMessageParser::IsSapConnectionActive()
       
   138 {
       
   139     FLOG( _L( " CSapVMessageParser: IsSapConnectionActive\t" ) );
       
   140 
       
   141     TInt state=EBTSapNotConnected;
       
   142     RProperty::Get(KPSUidBluetoothSapConnectionState, KBTSapConnectionState, state);
       
   143     return state==EBTSapConnected;
       
   144 }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------
       
   148 // CheckMime
       
   149 // Check MIME type of vMessage.
       
   150 // ---------------------------------------------------------
       
   151 //
       
   152 TBool CSapVMessageParser::CheckMime(const TDesC8& aType)
       
   153 {
       
   154     FLOG( _L( " CSapVMessageParser: CheckMime\t" ) );
       
   155 
       
   156     _LIT8(KMimeVmsg,"text/x-vmsg\x00");
       
   157 
       
   158     return (aType.Compare(KMimeVmsg)==0);
       
   159 }
       
   160 
       
   161 
       
   162 // ---------------------------------------------------------
       
   163 // CheckName
       
   164 // Check object name of SAP vMessage.
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 TBool CSapVMessageParser::CheckName(const TDesC& aName)
       
   168 {
       
   169     FLOG( _L( " CSapVMessageParser: CheckName\t" ) );
       
   170 
       
   171     _LIT(KNameVmsg, "sap_sms.vmg");
       
   172 
       
   173     return (aName.Compare(KNameVmsg)==0);
       
   174 }
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // Address
       
   178 // Returns address field of parsed message.
       
   179 // ---------------------------------------------------------
       
   180 //
       
   181 const TDesC& CSapVMessageParser::Address() const
       
   182 {
       
   183     if(iType==ESapVMessageTextSMS && iAddress)
       
   184     {
       
   185         return *iAddress;
       
   186     }
       
   187     else
       
   188     {
       
   189         return KNullDesC;
       
   190     }
       
   191 }
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // Message
       
   195 // Returns body text of parsed message.
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 const TDesC& CSapVMessageParser::Message() const
       
   199 {
       
   200     if(iType==ESapVMessageTextSMS && iMessage)
       
   201     {
       
   202         return *iMessage;
       
   203     }
       
   204     else
       
   205     {
       
   206         return KNullDesC;
       
   207     }
       
   208 }
       
   209 
       
   210 // ---------------------------------------------------------
       
   211 // ~CSapVMessageParser
       
   212 // Destructor.
       
   213 // ---------------------------------------------------------
       
   214 //
       
   215 CSapVMessageParser::~CSapVMessageParser()
       
   216 {
       
   217     FLOG( _L( " CSapVMessageParser: ~CSapVMessageParser\t" ) );
       
   218 
       
   219     delete iAddress;
       
   220     delete iMessage;
       
   221 }
       
   222 
       
   223 static TBool Compare(const TDesC8& aData, TInt& aReadBytes, const TDesC8& aToken)
       
   224 {
       
   225     if( (aData.Length() >= aReadBytes + aToken.Length()) &&
       
   226         (aData.Mid(aReadBytes, aToken.Length()).Compare(aToken)==0) )
       
   227     {
       
   228         aReadBytes+=aToken.Length();
       
   229         return ETrue;
       
   230     }
       
   231     else
       
   232     {
       
   233         return EFalse;
       
   234     }
       
   235 }
       
   236 
       
   237 // ---------------------------------------------------------
       
   238 // SimpleParseL
       
   239 // Parses SAP VMessage.
       
   240 // ---------------------------------------------------------
       
   241 //
       
   242 void CSapVMessageParser::SimpleParseL(const TDesC8& aData)
       
   243 {
       
   244     FLOG( _L( " CSapVMessageParser: SimpleParseL\t" ) );
       
   245 
       
   246     // SAP VMessage format definitions
       
   247     _LIT8(KVmsgStatus,  "BEGIN:VMSG\x0d\x0a"
       
   248                         "VERSION:1.1\x0d\x0a"
       
   249                         "X-IRMC-STATUS:");
       
   250     _LIT8(KVmsgBox,     "\x0d\x0a"
       
   251                         "X-IRMC-TYPE:SMS\x0d\x0a"
       
   252                         "X-IRMC-BOX:");
       
   253     _LIT8(KVmsgVCard,   "BEGIN:VCARD\x0d\x0a"
       
   254                         "VERSION:2.1\x0d\x0a");
       
   255     _LIT8(KVmsgName1,   "N:");
       
   256     _LIT8(KVmsgName2,   "N;ENCODING=8BIT;CHARSET=UTF-8:");
       
   257     _LIT8(KVmsgTel,     "\x0d\x0a"
       
   258                         "TEL:");
       
   259     _LIT8(KVmsgVCardEnd,"\x0d\x0a"
       
   260                         "END:VCARD\x0d\x0a");
       
   261     _LIT8(KVmsgVEnv,    "BEGIN:VENV\x0d\x0a");
       
   262     _LIT8(KVmsgVBody,   "BEGIN:VBODY\x0d\x0a"
       
   263                         "X-SMS;TYPE=TEXT;ENCODING=8BIT;CHARSET=UTF-8:");
       
   264     _LIT8(KVmsgEnd,     "\x0d\x0a"
       
   265                         "END:VBODY\x0d\x0a"
       
   266                         "END:VENV\x0d\x0a"
       
   267                         "END:VMSG\x0d\x0a");
       
   268     _LIT8(KVmsgUnread,  "UNREAD");
       
   269     _LIT8(KVmsgRead,    "READ");
       
   270     _LIT8(KVmsgInbox,   "INBOX\x0d\x0a");
       
   271     _LIT8(KVmsgSentbox, "SENTBOX\x0d\x0a");
       
   272     _LIT8(KCrLf,        "\x0d\x0a");
       
   273 
       
   274     // Simple SAP VMessage parsing
       
   275     TInt readBytes=0;
       
   276     if( Compare(aData, readBytes, KVmsgStatus) &&
       
   277         aData.Right(KVmsgEnd().Length()).Compare(KVmsgEnd)==0 )
       
   278     {   // The begin and end of the message are correct
       
   279         if(Compare(aData, readBytes, KVmsgUnread))
       
   280         {   // Status: Unread
       
   281             iStatus=ESapVMessageStatusUnread;
       
   282         }
       
   283         else if(Compare(aData, readBytes, KVmsgRead))
       
   284         {   // Status: Read or Sent
       
   285             iStatus=ESapVMessageStatusRead;
       
   286         }
       
   287         else
       
   288         {   // Unknown status
       
   289             return;
       
   290         }
       
   291         if( Compare(aData, readBytes, KVmsgBox) )
       
   292         {
       
   293             if(iStatus==ESapVMessageStatusRead && Compare(aData, readBytes, KVmsgSentbox))
       
   294             {   // Status: Sent
       
   295                 iStatus=ESapVMessageStatusSent;
       
   296                 if(!Compare(aData, readBytes, KVmsgVEnv))
       
   297                 {
       
   298                     return;
       
   299                 }
       
   300             }
       
   301             else if(! Compare(aData, readBytes, KVmsgInbox) )
       
   302             {
       
   303                 return;
       
   304             }
       
   305             if( Compare(aData, readBytes, KVmsgVCard) &&
       
   306                 ( Compare(aData, readBytes, KVmsgName1) ||
       
   307                     Compare(aData, readBytes, KVmsgName2) ) )
       
   308             {   // The begin of the message is correct
       
   309                 TInt beginOfName=readBytes;
       
   310                 TInt endOfName=aData.Find(KVmsgTel);
       
   311                 TInt endOfFrom=aData.Find(KVmsgVCardEnd);
       
   312                 readBytes=endOfFrom+KVmsgVCardEnd().Length();
       
   313                 if(iStatus!=ESapVMessageStatusSent)
       
   314                 {
       
   315                     if(!Compare(aData, readBytes, KVmsgVEnv))
       
   316                     {
       
   317                         return;
       
   318                     }
       
   319                 }
       
   320                 if(endOfFrom!=KErrNotFound && endOfName!=KErrNotFound &&
       
   321                     endOfName<endOfFrom && Compare(aData, readBytes, KVmsgVBody))
       
   322                 {   // The middle part of the message is correct
       
   323                     TInt beginOfFrom=endOfName+KVmsgTel().Length();
       
   324                     TInt fromLength=endOfFrom-beginOfFrom;
       
   325                     if(fromLength <= RMobilePhone::KMaxMobileTelNumberSize)
       
   326                     {   // The sender field of the message is not too long
       
   327                         TInt beginOfBody=readBytes;
       
   328                         TInt bodyLength=(aData.Length()-KVmsgEnd().Length())-beginOfBody;
       
   329 
       
   330                         TPtrC8 name = aData.Mid(beginOfName, endOfName-beginOfName);
       
   331                         TPtrC8 from = aData.Mid(beginOfFrom, fromLength);
       
   332                         if((name.Find(KCrLf)==KErrNotFound) && (from.Find(KCrLf)==KErrNotFound))
       
   333                         {   // Message is correct
       
   334                             if(from.Length()==0 && name.Length()>0 &&
       
   335                                 name.Length() <= RMobilePhone::KMaxMobileTelNumberSize)
       
   336                             {
       
   337                                 iAddress = CnvUtfConverter::ConvertToUnicodeFromUtf8L(name);
       
   338                             }
       
   339                             else
       
   340                             {
       
   341                                 iAddress = HBufC::NewL(from.Length());
       
   342                                 iAddress->Des().Copy(from);
       
   343                             }
       
   344 
       
   345                             TPtrC8 body = aData.Mid(beginOfBody, bodyLength);
       
   346                             iMessage = CnvUtfConverter::ConvertToUnicodeFromUtf8L(body);
       
   347 
       
   348                             FLOG( _L( " CSapVMessageParser: SimpleParseL: SMS\t" ) );
       
   349                             iType=ESapVMessageTextSMS;
       
   350                         }
       
   351                     }
       
   352                 }
       
   353             }
       
   354         }
       
   355     }
       
   356 }
       
   357 
       
   358 // ---------------------------------------------------------
       
   359 // SaveSapMessageL
       
   360 // Saves parsed VMessage.
       
   361 // ---------------------------------------------------------
       
   362 //
       
   363 void CSapVMessageParser::SaveSapMessageL(CMsvSession* aMsvSession)
       
   364 {
       
   365     FLOG( _L( " CSapVMessageParser: SaveSapMessageL\t" ) );
       
   366 
       
   367     switch(iType)
       
   368     {
       
   369         case ESapVMessageTextSMS:
       
   370             SaveSapSmsL(aMsvSession);
       
   371             break;
       
   372 
       
   373         case ESapVMessageMMSNotificationInd:
       
   374             SaveSapMmsL(aMsvSession);
       
   375             break;
       
   376 
       
   377         default: // Discard message
       
   378             break;
       
   379     }
       
   380 }
       
   381 
       
   382 // ---------------------------------------------------------
       
   383 // SaveSapSmsL
       
   384 // Saves parsed VMessage as SMS.
       
   385 // ---------------------------------------------------------
       
   386 //
       
   387 void CSapVMessageParser::SaveSapSmsL(CMsvSession* aMsvSession)
       
   388 {
       
   389     FLOG( _L( " CSapVMessageParser: SaveSapSmsL\t" ) );
       
   390 
       
   391     CParaFormatLayer* richParaFormatLayer = CParaFormatLayer::NewL();
       
   392     CleanupStack::PushL(richParaFormatLayer); // 1st push
       
   393     CCharFormatLayer* richCharFormatLayer = CCharFormatLayer::NewL(); 
       
   394     CleanupStack::PushL(richCharFormatLayer); // 2nd push
       
   395     CRichText* 
       
   396         richText = CRichText::NewL(richParaFormatLayer,richCharFormatLayer);
       
   397     CleanupStack::PushL(richText); // 3rd push
       
   398 
       
   399     richText->InsertL(0, Message());
       
   400 
       
   401     if(iStatus==ESapVMessageStatusSent)
       
   402     {
       
   403         SaveSmsToSentL(aMsvSession, richText);
       
   404     }
       
   405     else
       
   406     {
       
   407         SaveSmsToInboxL(aMsvSession, richText);
       
   408     }
       
   409 
       
   410     CleanupStack::PopAndDestroy(3, richParaFormatLayer);
       
   411 
       
   412     FLOG( _L( " CSapVMessageParser: SaveSapSmsL: Done\t" ) );
       
   413 }
       
   414 
       
   415 // ---------------------------------------------------------
       
   416 // SaveSapMmsL
       
   417 // Saves parsed VMessage as MMS notification.
       
   418 // ---------------------------------------------------------
       
   419 //
       
   420 void CSapVMessageParser::SaveSapMmsL(CMsvSession* /*aMsvSession*/) const
       
   421 {
       
   422     // This is not supported
       
   423 }
       
   424 
       
   425 // ---------------------------------------------------------
       
   426 // SaveSmsToInboxL
       
   427 // Saves parsed VMessage to Inbox as SMS.
       
   428 // ---------------------------------------------------------
       
   429 //
       
   430 void CSapVMessageParser::SaveSmsToInboxL(CMsvSession* aMsvSession, CRichText* aMessage)
       
   431 {
       
   432     FLOG( _L( " CSapVMessageParser: SaveSmsToInboxL\t" ) );
       
   433 
       
   434     CSmsHeader* header=CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *aMessage );
       
   435     CleanupStack::PushL(header); // 1st push
       
   436     header->SetFromAddressL(Address());
       
   437     header->SetReplyPathProvided(EFalse);
       
   438 
       
   439     TMsvEntry newTEntry;
       
   440 
       
   441     newTEntry.iType = KUidMsvMessageEntry;
       
   442     newTEntry.iMtm = KUidMsgTypeSMS;  
       
   443     newTEntry.SetComplete(EFalse);
       
   444     newTEntry.SetFailed(EFalse);
       
   445     newTEntry.SetOperation(EFalse);
       
   446     newTEntry.SetMultipleRecipients(EFalse);
       
   447     newTEntry.SetVisible(EFalse);  // Make invisible
       
   448     // and in preparation to make sure gets cleaned up on errors.
       
   449     newTEntry.SetInPreparation(ETrue);
       
   450     newTEntry.SetSendingState(KMsvSendStateNotApplicable);
       
   451     newTEntry.iServiceId = KMsvLocalServiceIndexEntryId;
       
   452     newTEntry.iSize = 0;        
       
   453     newTEntry.iDate = iTimeReceived;
       
   454     header->Message().SetTime(iTimeOriginal);
       
   455     ((CSmsDeliver*)&header->Message().SmsPDU())->SetServiceCenterTimeStamp(iTimeOriginal);
       
   456 
       
   457 // SMUT Unbranch
       
   458     CSmsGetDetDescInterface* smsPlugin = CSmsGetDetDescInterface::NewL();
       
   459     CleanupStack::PushL( smsPlugin );
       
   460 
       
   461     TBuf<KSmsDescriptionLength> description;
       
   462     smsPlugin->GetDescription( header->Message(), description );
       
   463     newTEntry.iDescription.Set(description);
       
   464     TBuf<KSmsDetailsLength> details;
       
   465     smsPlugin->GetDetails( aMsvSession->FileSession(), header->Message(), details );
       
   466     newTEntry.iDetails.Set(details);
       
   467 
       
   468     CleanupStack::PopAndDestroy( smsPlugin );
       
   469 
       
   470     // Create new entry to inbox
       
   471     CMsvEntry* inbox = aMsvSession->GetEntryL( KMsvGlobalInBoxIndexEntryId );
       
   472     CleanupStack::PushL( inbox );
       
   473     inbox->CreateL(newTEntry);
       
   474     CleanupStack::PopAndDestroy(inbox);
       
   475 
       
   476     TMsvId newEntryId=newTEntry.Id();
       
   477     aMsvSession->CleanupEntryPushL(newEntryId); //2nd push
       
   478 
       
   479     // Get the created entry
       
   480     CMsvEntry* newEntry = aMsvSession->GetEntryL(newEntryId);
       
   481     CleanupStack::PushL(newEntry);  // 3rd push
       
   482 
       
   483     // Store SMS message to the entry
       
   484     CMsvStore* newMessageStore = newEntry->EditStoreL();
       
   485     CleanupStack::PushL(newMessageStore);   // 4th push
       
   486     header->StoreL(*newMessageStore);
       
   487     newMessageStore->StoreBodyTextL(*aMessage);
       
   488     newMessageStore->CommitL();
       
   489 
       
   490     // Save the size & make visible
       
   491     newTEntry = newEntry->Entry();
       
   492     newTEntry.iSize = newMessageStore->SizeL();
       
   493                     
       
   494     // Saved OK. Make the entry visible and flag it as complete.
       
   495     newTEntry.SetVisible(ETrue);
       
   496     newTEntry.SetInPreparation(EFalse);   
       
   497     newTEntry.SetUnread(iStatus==ESapVMessageStatusUnread);
       
   498     newTEntry.SetNew(iStatus==ESapVMessageStatusRead);
       
   499     newTEntry.SetComplete(ETrue);
       
   500     newTEntry.SetReadOnly(ETrue);
       
   501     newEntry->ChangeL(newTEntry);
       
   502 
       
   503     CleanupStack::PopAndDestroy(2, newEntry);
       
   504     aMsvSession->CleanupEntryPop();             
       
   505     CleanupStack::PopAndDestroy(header);
       
   506 
       
   507     FLOG( _L( " CSapVMessageParser: SaveSmsToInboxL: Done\t" ) );
       
   508 }
       
   509 
       
   510 // ---------------------------------------------------------
       
   511 // SaveSmsToSentL
       
   512 // Saves parsed VMessage to Sent folder as SMS.
       
   513 // ---------------------------------------------------------
       
   514 //
       
   515 void CSapVMessageParser::SaveSmsToSentL(CMsvSession* aMsvSession, CRichText* aMessage)
       
   516 {
       
   517     FLOG( _L( " CSapVMessageParser: SaveSmsToSentL\t" ) );
       
   518 
       
   519     CSmsHeader* header = CSmsHeader::NewL( CSmsPDU::ESmsSubmit, *aMessage );
       
   520     CleanupStack::PushL( header );
       
   521     header->SetFromAddressL(Address());
       
   522 
       
   523     TMsvEntry newTEntry;
       
   524     newTEntry.iType = KUidMsvMessageEntry;
       
   525     newTEntry.iMtm = KUidMsgTypeSMS;  
       
   526     newTEntry.SetComplete(EFalse);
       
   527     newTEntry.SetFailed(EFalse);
       
   528     newTEntry.SetOperation(EFalse);
       
   529     newTEntry.SetMultipleRecipients(EFalse);
       
   530     newTEntry.SetVisible(EFalse);  // Make invisible
       
   531     // and in preparation to make sure gets cleaned up on errors.
       
   532     newTEntry.SetInPreparation(ETrue);
       
   533     newTEntry.SetSendingState(KMsvSendStateSent);
       
   534     newTEntry.iServiceId = KMsvUnknownServiceIndexEntryId;
       
   535     newTEntry.iSize = 0;        
       
   536     newTEntry.iDate=iTimeReceived;
       
   537     header->Message().SetTime(iTimeOriginal);
       
   538 
       
   539 // SMUT Unbranch
       
   540     CSmsGetDetDescInterface* smsPlugin = CSmsGetDetDescInterface::NewL();
       
   541     CleanupStack::PushL( smsPlugin );
       
   542     
       
   543     TBuf<KSmsDescriptionLength> description;
       
   544     smsPlugin->GetDescription( header->Message(), description );
       
   545     newTEntry.iDescription.Set(description);
       
   546     TBuf<KSmsDetailsLength> details;
       
   547     smsPlugin->GetDetails( aMsvSession->FileSession(), header->Message(), details );
       
   548     newTEntry.iDetails.Set(details);
       
   549 
       
   550     CleanupStack::PopAndDestroy( smsPlugin );
       
   551 
       
   552     CSmsSettings* settings = CSmsSettings::NewLC();
       
   553     CSmsAccount* account = CSmsAccount::NewLC();
       
   554     account->LoadSettingsL(*settings);
       
   555     CleanupStack::PopAndDestroy(account);
       
   556     header->SetSmsSettingsL( *settings );
       
   557     TInt scindex = settings->DefaultServiceCenter();
       
   558     if ( scindex != KErrNotFound )
       
   559     {
       
   560        header->SetServiceCenterAddressL( ( settings->GetServiceCenter( scindex ) ).Address() );
       
   561     }
       
   562     CleanupStack::PopAndDestroy(settings);
       
   563 
       
   564     CSmsNumber* rcpt = CSmsNumber::NewL();
       
   565     CleanupStack::PushL( rcpt );
       
   566     rcpt->SetAddressL(Address());
       
   567     if(Address()!=details)
       
   568     {
       
   569         rcpt->SetNameL(details);
       
   570     }
       
   571     header->Recipients().ResetAndDestroy();
       
   572     header->Recipients().AppendL( rcpt );
       
   573     CleanupStack::Pop( rcpt );
       
   574 
       
   575     // Create new entry to Sent folder
       
   576     CMsvEntry* sentFldr = aMsvSession->GetEntryL( KMsvSentEntryId );
       
   577     CleanupStack::PushL( sentFldr );
       
   578     sentFldr->CreateL(newTEntry);
       
   579     CleanupStack::PopAndDestroy(sentFldr);
       
   580 
       
   581     TMsvId newEntryId=newTEntry.Id();
       
   582     aMsvSession->CleanupEntryPushL(newEntryId); //2nd push
       
   583 
       
   584     // Get the created entry
       
   585     CMsvEntry* newEntry = aMsvSession->GetEntryL(newEntryId);
       
   586     CleanupStack::PushL(newEntry);  // 3rd push
       
   587 
       
   588     // Store SMS message to the entry
       
   589     CMsvStore* newMessageStore = newEntry->EditStoreL();
       
   590     CleanupStack::PushL(newMessageStore);   // 4th push
       
   591     header->StoreL(*newMessageStore);
       
   592     newMessageStore->StoreBodyTextL(*aMessage);
       
   593     newMessageStore->CommitL();
       
   594 
       
   595     // Save the size & make visible
       
   596     newTEntry = newEntry->Entry();
       
   597     newTEntry.iSize = newMessageStore->SizeL();
       
   598                     
       
   599     // Saved OK. Make the entry visible and flag it as complete.
       
   600     newTEntry.SetVisible(ETrue);
       
   601     newTEntry.SetInPreparation(EFalse);   
       
   602     newTEntry.SetComplete(ETrue);
       
   603     newEntry->ChangeL(newTEntry);
       
   604 
       
   605     CleanupStack::PopAndDestroy(2, newEntry);
       
   606     aMsvSession->CleanupEntryPop();             
       
   607     CleanupStack::PopAndDestroy(header);
       
   608 
       
   609     FLOG( _L( " CSapVMessageParser: SaveSmsToSentL: Done\t" ) );
       
   610 }
       
   611 
       
   612 //  End of File