mmsengine/mmscodec/src/mmsencode.cpp
changeset 79 2981cb3aa489
parent 23 238255e8b033
equal deleted inserted replaced
25:84d9eb65b26f 79:2981cb3aa489
   851     TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: start") );
   851     TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: start") );
   852 #endif /* _NO_MMSS_LOGGING_ */
   852 #endif /* _NO_MMSS_LOGGING_ */
   853     User::LeaveIfError( iEntryWrapper->SetCurrentEntry( iCurrentMessageId ) );
   853     User::LeaveIfError( iEntryWrapper->SetCurrentEntry( iCurrentMessageId ) );
   854     
   854     
   855     /* Korean req: 415-5434
   855     /* Korean req: 415-5434
   856      * Get the target encoding MIB enum from cenrep and encode MMS text objects using corresponding conversion plugins
   856      * Get the target encoding MIB enum from cenrep and encode MMS text objects using coresponding conversion plugins
   857      */
   857      */
   858     TInt temp;
   858     TInt temp;
   859     iTargetEncodingType = 0;
   859     iTargetEncodingType = 0;
   860     CRepository* repository = CRepository::NewLC( KUidMmsServerMtm );    
   860     CRepository* repository = CRepository::NewLC( KUidMmsServerMtm );    
   861     if ( repository->Get( KMmsEncodingType, temp ) == KErrNone )
   861     if ( repository->Get( KMmsEncodingType, temp ) == KErrNone )
   867     TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: target encoding type: %d"), iTargetEncodingType );
   867     TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: target encoding type: %d"), iTargetEncodingType );
   868 #endif /* _NO_MMSS_LOGGING_ */
   868 #endif /* _NO_MMSS_LOGGING_ */
   869 
   869 
   870     if( iTargetEncodingType != 0 )
   870     if( iTargetEncodingType != 0 )
   871         {
   871         {
       
   872 #ifndef _NO_MMSS_LOGGING_
   872         TRAPD( err, PreProcessAttachmentDataL() );
   873         TRAPD( err, PreProcessAttachmentDataL() );
   873 
       
   874 #ifndef _NO_MMSS_LOGGING_
       
   875     /* if any error, korean specific encoding failed, But this should not stop from sending MMS using
   874     /* if any error, korean specific encoding failed, But this should not stop from sending MMS using
   876      * existing default encoding. Hence just log the error and continue in any case
   875      * existing default encoding. Hence just log the error and continue in any case
   877      */
   876      */
   878         if( err != KErrNone )
   877         if( err != KErrNone )
   879             {
   878             {
   880             TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: PreProcessAttachmentDataL error: %d"), err );
   879             TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: PreProcessAttachmentDataL error: %d"), err );
   881             }
   880             }
       
   881 #else
       
   882 				TRAP_IGNORE( PreProcessAttachmentDataL() );            
   882 #endif /* _NO_MMSS_LOGGING_ */
   883 #endif /* _NO_MMSS_LOGGING_ */
   883         }
   884         }
   884     
   885     
   885     //Open store for read-only purpose
   886     //Open store for read-only purpose
   886     CMsvStore* store = iEntryWrapper->ReadStoreL();
   887     CMsvStore* store = iEntryWrapper->ReadStoreL();
   939     if ( iOnlyOneChunk )
   940     if ( iOnlyOneChunk )
   940         {
   941         {
   941 #ifndef _NO_MMSS_LOGGING_
   942 #ifndef _NO_MMSS_LOGGING_
   942         TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: only one chunk") );
   943         TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: only one chunk") );
   943 #endif /* _NO_MMSS_LOGGING_ */        // The message is small enough to be sent as one chunk
   944 #endif /* _NO_MMSS_LOGGING_ */        // The message is small enough to be sent as one chunk
   944         for ( i = 0; ( i < iNumberOfAttachments ) && ( iError == KErrNone ); ++i )
   945         for ( i = 0; ( i < iNumberOfAttachments ) && ( iError == KErrNone ); i++ )
   945             {
   946             {
   946             iCurrentAttachment = i;
   947             iCurrentAttachment = i;
   947             // encode attachments, too, as we have decided that our message
   948             // encode attachments, too, as we have decided that our message
   948             // is small enough to fit into the buffer as one chunk
   949             // is small enough to fit into the buffer as one chunk
   949             // DoEncodeAttachment always encodes iCurrentAttachment
   950             // DoEncodeAttachment always encodes iCurrentAttachment
   961         TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: Multiple chunks") );
   962         TMmsLogger::Log( _L("CMmsEncode::EncodeHeadersChunkedL:: Multiple chunks") );
   962 #endif /* _NO_MMSS_LOGGING_ */        // The message is small enough to be sent as one chunk
   963 #endif /* _NO_MMSS_LOGGING_ */        // The message is small enough to be sent as one chunk
   963         // chunked sending - but it should be possible to calculate data size
   964         // chunked sending - but it should be possible to calculate data size
   964         iOverallDataSize = iPosition; // This is the amount taken by headers
   965         iOverallDataSize = iPosition; // This is the amount taken by headers
   965         // The message is small enough to be sent as one chunk
   966         // The message is small enough to be sent as one chunk
   966         for ( i = 0; ( i < iNumberOfAttachments ) && ( iError == KErrNone ); ++i )
   967         for ( i = 0; ( i < iNumberOfAttachments ) && ( iError == KErrNone ); i++ )
   967             {
   968             {
   968             iCurrentAttachment = i;
   969             iCurrentAttachment = i;
   969             // encode attachments, too, as we have decided that our message
   970             // encode attachments, too, as we have decided that our message
   970             // is small enough to fit into the buffer as one chunk
   971             // is small enough to fit into the buffer as one chunk
   971             // DoEncodeAttachment always encodes iCurrentAttachment
   972             // DoEncodeAttachment always encodes iCurrentAttachment
  1257         CleanupStack::PopAndDestroy( tempContentType );
  1258         CleanupStack::PopAndDestroy( tempContentType );
  1258         aContentTypeString.Set( aAttachmentInfo.MimeType() );
  1259         aContentTypeString.Set( aAttachmentInfo.MimeType() );
  1259         }
  1260         }
  1260         
  1261         
  1261     TInt8 i;
  1262     TInt8 i;
  1262     for ( i = 0; i < KNumberContentTypes && aContentType < 0; ++i )
  1263     for ( i = 0; i < KNumberContentTypes && aContentType < 0; i++ )
  1263         {
  1264         {
  1264         if ( aContentTypeString.CompareF(
  1265         if ( aContentTypeString.CompareF(
  1265             TPtrC8( KContentTypeTable[i] ) ) == 0 )
  1266             TPtrC8( KContentTypeTable[i] ) ) == 0 )
  1266             {
  1267             {
  1267             aContentType = i;
  1268             aContentType = i;
  1292         // Extension media
  1293         // Extension media
  1293         aHeaderLength += aContentTypeString.Length();
  1294         aHeaderLength += aContentTypeString.Length();
  1294         aHeaderLength += 1; // terminating zero
  1295         aHeaderLength += 1; // terminating zero
  1295         }
  1296         }
  1296 
  1297 
  1297     // If we have parameters, we must calculate their length.
  1298     // If we have paramters, we must calculate their length.
  1298     if ( iMimeHeaders->MimeCharset() != 0 )
  1299     if ( iMimeHeaders->MimeCharset() != 0 )
  1299         {
  1300         {
  1300         // charset has well-known encoding
  1301         // charset has well-known encoding
  1301         aHeaderLength += 1;
  1302         aHeaderLength += 1;
  1302         if ( iMimeHeaders->MimeCharset() <= KMmsShortIntegerLimit127 )
  1303         if ( iMimeHeaders->MimeCharset() <= KMmsShortIntegerLimit127 )
  1380                 }
  1381                 }
  1381             }
  1382             }
  1382         }
  1383         }
  1383     if ( ( iMimeHeaders->ContentTypeParams().MdcaCount() % 2 ) == 1 )
  1384     if ( ( iMimeHeaders->ContentTypeParams().MdcaCount() % 2 ) == 1 )
  1384         {
  1385         {
  1385         // Odd number. Obviously last parameter has no value.
  1386         // Odd number. Obviously last paramter has no value.
  1386         // Add the "no value" token
  1387         // Add the "no value" token
  1387         aHeaderLength++;
  1388         aHeaderLength++;
  1388         }
  1389         }
  1389 
  1390 
  1390     // include name parameter to content-type
  1391     // include name parameter to content-type
  1497             {
  1498             {
  1498             // if version is <= 1.2, the filename must be us-ascii
  1499             // if version is <= 1.2, the filename must be us-ascii
  1499             // replace all illegal characters by underscore
  1500             // replace all illegal characters by underscore
  1500             buf8 = HBufC8::NewL( nameLength );
  1501             buf8 = HBufC8::NewL( nameLength );
  1501             CleanupStack::PushL( buf8 );
  1502             CleanupStack::PushL( buf8 );
  1502             for ( j = 0; j < nameLength; ++j )
  1503             for ( j = 0; j < nameLength; j++ )
  1503                 {
  1504                 {
  1504                 oneCharacter.Copy( originalName.Mid( j, 1 ) );
  1505                 oneCharacter.Copy( originalName.Mid( j, 1 ) );
  1505                 if ( !IsStringSafe( oneCharacter ) )
  1506                 if ( !IsStringSafe( oneCharacter ) )
  1506                     {
  1507                     {
  1507                     _LIT( KMmsUnderscore, "_" );
  1508                     _LIT( KMmsUnderscore, "_" );
  1620     // x-type parameters
  1621     // x-type parameters
  1621     // Must be stored as name/value pairs like content-type parameters
  1622     // Must be stored as name/value pairs like content-type parameters
  1622     // X-parameter[i] = parameter name
  1623     // X-parameter[i] = parameter name
  1623     // X-parameter[i+1] = parameter value
  1624     // X-parameter[i+1] = parameter value
  1624     
  1625     
  1625     for ( i = 0; i < iMimeHeaders->XTypeParams().MdcaCount(); ++i )
  1626     for ( i = 0; i < iMimeHeaders->XTypeParams().MdcaCount(); i++ )
  1626         {
  1627         {
  1627         // If we have corrupted parameters (length of name is zero)
  1628         // If we have corrupted parameters (length of name is zero)
  1628         // we skip the name/value pair.
  1629         // we skip the name/value pair.
  1629         // value may be zero, it will be encoded as just the terminating zero
  1630         // value may be zero, it will be encoded as just the terminating zero
  1630         if ( i%2 == 0 &&
  1631         if ( i%2 == 0 &&
  1642             aHeaderLength += iMimeHeaders->XTypeParams().MdcaPoint( i ).Length() + 1;
  1643             aHeaderLength += iMimeHeaders->XTypeParams().MdcaPoint( i ).Length() + 1;
  1643             }
  1644             }
  1644         }
  1645         }
  1645     if ( ( iMimeHeaders->XTypeParams().MdcaCount() % 2 ) == 1 )
  1646     if ( ( iMimeHeaders->XTypeParams().MdcaCount() % 2 ) == 1 )
  1646         {
  1647         {
  1647         // Odd number. Obviously last parameter has no value.
  1648         // Odd number. Obviously last paramter has no value.
  1648         // Add the "no value" token
  1649         // Add the "no value" token
  1649         aHeaderLength++;
  1650         aHeaderLength++;
  1650         }
  1651         }
  1651         
  1652         
  1652     // THESE ARE NOT IMPLEMENTED
  1653     // THESE ARE NOT IMPLEMENTED
  1736     // but maybe something else, too
  1737     // but maybe something else, too
  1737 
  1738 
  1738     temp = KWspCharset | KMms0x80; // encode as short integer
  1739     temp = KWspCharset | KMms0x80; // encode as short integer
  1739     EncodeOptionalInteger( temp, iMimeHeaders->MimeCharset() );
  1740     EncodeOptionalInteger( temp, iMimeHeaders->MimeCharset() );
  1740 
  1741 
  1741     // if we didn't find "Name" parameter among our parameters, we
  1742     // if we didn't find "Name" parameter among our paramters, we
  1742     // put it first.
  1743     // put it first.
  1743 
  1744 
  1744     // we need the name later anyway...
  1745     // we need the name later anyway...
  1745 
  1746 
  1746     if ( !aFoundName )
  1747     if ( !aFoundName )
  1751 
  1752 
  1752     // Then the rest of content type parameters, just text strings.
  1753     // Then the rest of content type parameters, just text strings.
  1753     
  1754     
  1754     TInt i = 0;
  1755     TInt i = 0;
  1755     
  1756     
  1756     for ( i = 0; i < iMimeHeaders->ContentTypeParams().MdcaCount(); ++i )
  1757     for ( i = 0; i < iMimeHeaders->ContentTypeParams().MdcaCount(); i++ )
  1757         {
  1758         {
  1758         // If we have corrupted parameters (length of name is zero)
  1759         // If we have corrupted parameters (length of name is zero)
  1759         // we skip the name/value pair.
  1760         // we skip the name/value pair.
  1760         // value may be zero, it will be encoded as just the terminating zero
  1761         // value may be zero, it will be encoded as just the terminating zero
  1761         if ( i%2 == 0 &&
  1762         if ( i%2 == 0 &&
  1794                 }
  1795                 }
  1795             }
  1796             }
  1796         }
  1797         }
  1797     if ( ( iMimeHeaders->ContentTypeParams().MdcaCount() % 2 ) == 1 )
  1798     if ( ( iMimeHeaders->ContentTypeParams().MdcaCount() % 2 ) == 1 )
  1798         {
  1799         {
  1799         // Odd number. Obviously last parameter has no value.
  1800         // Odd number. Obviously last paramter has no value.
  1800         // Add the "no value" token
  1801         // Add the "no value" token
  1801         iEncodeBuffer->Write( iPosition, &KMmsNull, 1 );
  1802         iEncodeBuffer->Write( iPosition, &KMmsNull, 1 );
  1802         iPosition++;
  1803         iPosition++;
  1803         }
  1804         }
  1804 
  1805 
  1841      // filename should be text-string, not quoted
  1842      // filename should be text-string, not quoted
  1842      EncodeHeaderAndTextString( temp, buf8->Des() );
  1843      EncodeHeaderAndTextString( temp, buf8->Des() );
  1843 #endif
  1844 #endif
  1844 
  1845 
  1845         // x-type parameters
  1846         // x-type parameters
  1846     for ( i = 0; i < iMimeHeaders->XTypeParams().MdcaCount(); ++i )
  1847     for ( i = 0; i < iMimeHeaders->XTypeParams().MdcaCount(); i++ )
  1847         {
  1848         {
  1848         // If we have corrupted parameters (length of name is zero)
  1849         // If we have corrupted parameters (length of name is zero)
  1849         // we skip the name/value pair.
  1850         // we skip the name/value pair.
  1850         // value may be zero, it will be encoded as just the terminating zero
  1851         // value may be zero, it will be encoded as just the terminating zero
  1851         if ( i%2 == 0 &&
  1852         if ( i%2 == 0 &&
  1868             EncodeTextString( iMimeHeaders->XTypeParams().MdcaPoint( i ) );
  1869             EncodeTextString( iMimeHeaders->XTypeParams().MdcaPoint( i ) );
  1869             }
  1870             }
  1870         }
  1871         }
  1871     if ( ( iMimeHeaders->XTypeParams().MdcaCount() % 2 ) == 1 )
  1872     if ( ( iMimeHeaders->XTypeParams().MdcaCount() % 2 ) == 1 )
  1872         {
  1873         {
  1873         // Odd number. Obviously last parameter has no value.
  1874         // Odd number. Obviously last paramter has no value.
  1874         // Add the "no value" token
  1875         // Add the "no value" token
  1875         iEncodeBuffer->Write( iPosition, &KMmsNull, 1 );
  1876         iEncodeBuffer->Write( iPosition, &KMmsNull, 1 );
  1876         iPosition++;
  1877         iPosition++;
  1877         }
  1878         }
  1878         
  1879         
  2310 
  2311 
  2311     // previously sent by array
  2312     // previously sent by array
  2312     TInt i;
  2313     TInt i;
  2313     TUint oldPosition;
  2314     TUint oldPosition;
  2314     TUint length;
  2315     TUint length;
  2315     for ( i = 0; i < iMmsHeaders->PreviouslySentList().Count(); ++i )
  2316     for ( i = 0; i < iMmsHeaders->PreviouslySentList().Count(); i++ )
  2316         {
  2317         {
  2317         oldPosition = iPosition;
  2318         oldPosition = iPosition;
  2318         length = 0;
  2319         length = 0;
  2319         // Encode once just to find out filed length
  2320         // Encode once just to find out filed length
  2320         EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() );
  2321         EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() );
  3199         iMmsHeaders->ReplyChargingId() );
  3200         iMmsHeaders->ReplyChargingId() );
  3200 
  3201 
  3201     TInt i;
  3202     TInt i;
  3202     TUint oldPosition;
  3203     TUint oldPosition;
  3203     TUint length;
  3204     TUint length;
  3204     for ( i = 0; i < iMmsHeaders->PreviouslySentList().Count(); ++i )
  3205     for ( i = 0; i < iMmsHeaders->PreviouslySentList().Count(); i++ )
  3205         {
  3206         {
  3206         oldPosition = iPosition;
  3207         oldPosition = iPosition;
  3207         length = 0;
  3208         length = 0;
  3208         // Encode once just to find out field length
  3209         // Encode once just to find out field length
  3209         EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() );
  3210         EncodeInteger( iMmsHeaders->PreviouslySentList()[i]->Order() );
  3313         {
  3314         {
  3314         TUint8 character;
  3315         TUint8 character;
  3315         // No need to check if we need a quote - if we are safe, we have 
  3316         // No need to check if we need a quote - if we are safe, we have 
  3316         // no characters >= 128.
  3317         // no characters >= 128.
  3317 
  3318 
  3318         for ( i = 0; i < aString.Length(); ++i )
  3319         for ( i = 0; i < aString.Length(); i++ )
  3319             {
  3320             {
  3320             character = TUint8( aString[i] & KMms0xFF );
  3321             character = TUint8( aString[i] & KMms0xFF );
  3321             iEncodeBuffer->Write( iPosition, &character, 1 );
  3322             iEncodeBuffer->Write( iPosition, &character, 1 );
  3322             iPosition++;
  3323             iPosition++;
  3323             }
  3324             }
  3409 
  3410 
  3410     TInt64 temp = aLongInteger;
  3411     TInt64 temp = aLongInteger;
  3411     TInt i = 0;
  3412     TInt i = 0;
  3412     TInt64 reminder = 0;
  3413     TInt64 reminder = 0;
  3413 
  3414 
  3414     for ( i = 7; i >= 0; --i )
  3415     for ( i = 7; i >= 0; i-- )
  3415         {
  3416         {
  3416         reminder = temp % 0x100;
  3417         reminder = temp % 0x100;
  3417         temp = temp / 0x100;
  3418         temp = temp / 0x100;
  3418         array[i] = TInt8 ( I64INT( reminder ) ) ;
  3419         array[i] = TInt8 ( I64INT( reminder ) ) ;
  3419         }
  3420         }
  3482         temp = temp << KMms8;
  3483         temp = temp << KMms8;
  3483         byte = TInt8( ( temp >> KMms24 ) & KMms0xFF );
  3484         byte = TInt8( ( temp >> KMms24 ) & KMms0xFF );
  3484         }
  3485         }
  3485 
  3486 
  3486     TUint i = 0;
  3487     TUint i = 0;
  3487     for ( i = 0; i < length; ++i )
  3488     for ( i = 0; i < length; i++ )
  3488         {
  3489         {
  3489         array[i] = TInt8( ( temp >> ( KMms8 * ( KMms3 - i ) ) ) & KMms0xFF );
  3490         array[i] = TInt8( ( temp >> ( KMms8 * ( KMms3 - i ) ) ) & KMms0xFF );
  3490         }
  3491         }
  3491 
  3492 
  3492     // write short length
  3493     // write short length
  3640         // All legal characters present in a phone number are ASCII
  3641         // All legal characters present in a phone number are ASCII
  3641 
  3642 
  3642         TInt i = 0;
  3643         TInt i = 0;
  3643         TUint8 character = 0;
  3644         TUint8 character = 0;
  3644         realAddressPointer = realAddress->Des();
  3645         realAddressPointer = realAddress->Des();
  3645         for ( i = 0; i < realAddress->Length(); ++i )
  3646         for ( i = 0; i < realAddress->Length(); i++ )
  3646             {
  3647             {
  3647             // The array index is safe because i is always < realAddress->Length().
  3648             // The array index is safe because i is always < realAddress->Length().
  3648             character = TUint8( realAddressPointer[i] & KMms0xFF );
  3649             character = TUint8( realAddressPointer[i] & KMms0xFF );
  3649             iEncodeBuffer->Write( iPosition, &character, 1 );
  3650             iEncodeBuffer->Write( iPosition, &character, 1 );
  3650             iPosition++;
  3651             iPosition++;
  3696     // No more than 5 bytes will be produced
  3697     // No more than 5 bytes will be produced
  3697     TUint8 buffer[KMms5];
  3698     TUint8 buffer[KMms5];
  3698     TUint temp = aInteger;
  3699     TUint temp = aInteger;
  3699     TInt i;
  3700     TInt i;
  3700 
  3701 
  3701     for ( i = 0; i < KMms5; ++i )            
  3702     for ( i = 0; i < KMms5; i++ )            
  3702         {
  3703         {
  3703         buffer[KMms4 - i] = TUint8( temp & KMms0x7F );
  3704         buffer[KMms4 - i] = TUint8( temp & KMms0x7F );
  3704         temp >>= KMms7;
  3705         temp >>= KMms7;
  3705         }
  3706         }
  3706 
  3707 
  3711         i++;
  3712         i++;
  3712         }
  3713         }
  3713     
  3714     
  3714     TInt j;
  3715     TInt j;
  3715 
  3716 
  3716     for ( j = i; j < KMms4; ++j )
  3717     for ( j = i; j < KMms4; j++ )
  3717         {
  3718         {
  3718         // buffer indexes are safe because the buffer has been defined long enough.
  3719         // buffer indexes are safe because the buffer has been defined long enough.
  3719         buffer[j] |= KMms0x80; // set Continue bit, but never to last
  3720         buffer[j] |= KMms0x80; // set Continue bit, but never to last
  3720         }
  3721         }
  3721 
  3722 
  3738     // No more than 5 bytes will be produced
  3739     // No more than 5 bytes will be produced
  3739     TUint8 buffer[KMms5];
  3740     TUint8 buffer[KMms5];
  3740     TUint temp = aInteger;
  3741     TUint temp = aInteger;
  3741     TInt i;
  3742     TInt i;
  3742 
  3743 
  3743     for (i = 0; i < KMms5; ++i )            
  3744     for (i = 0; i < KMms5; i++ )            
  3744         {
  3745         {
  3745         buffer[KMms4 - i] = TUint8( temp & KMms0x7F );
  3746         buffer[KMms4 - i] = TUint8( temp & KMms0x7F );
  3746         temp >>= KMms7;
  3747         temp >>= KMms7;
  3747         }
  3748         }
  3748 
  3749 
  3787             break;
  3788             break;
  3788         default:
  3789         default:
  3789             break;
  3790             break;
  3790         }
  3791         }
  3791 
  3792 
  3792     for ( i = 0; i < size; ++i )
  3793     for ( i = 0; i < size; i++ )
  3793         {
  3794         {
  3794         // check for fakes
  3795         // check for fakes
  3795         if ( aRecipientList[i].Length() > 0 )
  3796         if ( aRecipientList[i].Length() > 0 )
  3796             {
  3797             {
  3797             iEncodeBuffer->Write( iPosition, &recipientType, 1 );
  3798             iEncodeBuffer->Write( iPosition, &recipientType, 1 );
  3992     // Used for headers, which are short strings
  3993     // Used for headers, which are short strings
  3993 
  3994 
  3994     TInt i;
  3995     TInt i;
  3995     TBool safe = ETrue;
  3996     TBool safe = ETrue;
  3996 
  3997 
  3997     for ( i = 0; i < aString.Length() && safe; ++i )
  3998     for ( i = 0; i < aString.Length() && safe; i++ )
  3998         {
  3999         {
  3999         if ( aString[i] < KMmsLowestAscii || aString[i] >= KMmsHighestAscii )
  4000         if ( aString[i] < KMmsLowestAscii || aString[i] >= KMmsHighestAscii )
  4000             {
  4001             {
  4001             safe = EFalse;
  4002             safe = EFalse;
  4002             }
  4003             }
  4022     
  4023     
  4023     TInt i;
  4024     TInt i;
  4024     aNumNonSafe = 0;
  4025     aNumNonSafe = 0;
  4025     TBool safe = ETrue;
  4026     TBool safe = ETrue;
  4026 
  4027 
  4027     for ( i = 0; i < aString.Length()/* && safe*/; ++i )
  4028     for ( i = 0; i < aString.Length()/* && safe*/; i++ )
  4028         {
  4029         {
  4029         if ( aString[i] < KMmsLowestAscii || aString[i] >= KMmsHighestAscii )
  4030         if ( aString[i] < KMmsLowestAscii || aString[i] >= KMmsHighestAscii )
  4030             {
  4031             {
  4031             safe = EFalse;
  4032             safe = EFalse;
  4032             aNumNonSafe++;
  4033             aNumNonSafe++;
  4150         }
  4151         }
  4151     // Check if we have well-known media.
  4152     // Check if we have well-known media.
  4152     TInt8 rootContentType = -1;
  4153     TInt8 rootContentType = -1;
  4153 
  4154 
  4154     TInt8 i = 0;
  4155     TInt8 i = 0;
  4155     for ( i = 0; i < KNumberContentTypes && rootContentType < 0; ++i )
  4156     for ( i = 0; i < KNumberContentTypes && rootContentType < 0; i++ )
  4156         {
  4157         {
  4157         if ( contentTypeString.CompareF( TPtrC8( KContentTypeTable[i] ) ) == 0 )
  4158         if ( contentTypeString.CompareF( TPtrC8( KContentTypeTable[i] ) ) == 0 )
  4158             {
  4159             {
  4159             rootContentType = i;
  4160             rootContentType = i;
  4160             }
  4161             }
  4318     TInt i = 0;
  4319     TInt i = 0;
  4319     TInt length = 0;
  4320     TInt length = 0;
  4320 
  4321 
  4321     // caller must check that iMmsHeaders->ReadOnlyMMBoxMessageHeaders() is not NULL
  4322     // caller must check that iMmsHeaders->ReadOnlyMMBoxMessageHeaders() is not NULL
  4322     CMmsMMBoxMessageHeaders& temp = iMmsHeaders->MMBoxMessageHeadersL();
  4323     CMmsMMBoxMessageHeaders& temp = iMmsHeaders->MMBoxMessageHeadersL();
  4323     for ( i = 0; i < temp.KeywordArray().Count(); ++i )
  4324     for ( i = 0; i < temp.KeywordArray().Count(); i++ )
  4324         {
  4325         {
  4325         length = temp.KeywordArray()[i]->Keyword().Length();
  4326         length = temp.KeywordArray()[i]->Keyword().Length();
  4326         if ( length > 0 )
  4327         if ( length > 0 )
  4327             {
  4328             {
  4328             iEncodeBuffer->Write( iPosition, &KMmsAssignedMMFlags, 1 );
  4329             iEncodeBuffer->Write( iPosition, &KMmsAssignedMMFlags, 1 );
  4373 //
  4374 //
  4374 void CMmsEncode::EncodeAttributes( RArray<TUint>& aAttributeArray )
  4375 void CMmsEncode::EncodeAttributes( RArray<TUint>& aAttributeArray )
  4375     {
  4376     {
  4376     TInt i;
  4377     TInt i;
  4377 
  4378 
  4378     for ( i = 0; i < aAttributeArray.Count(); ++i )
  4379     for ( i = 0; i < aAttributeArray.Count(); i++ )
  4379         {
  4380         {
  4380         EncodeMandatoryByte( KMmsAssignedAttributes, aAttributeArray[i] );
  4381         EncodeMandatoryByte( KMmsAssignedAttributes, aAttributeArray[i] );
  4381         }
  4382         }
  4382     }
  4383     }
  4383 
  4384 
  4387 //
  4388 //
  4388 void CMmsEncode::EncodeMMBoxStates( RArray<TInt>& aStateArray )
  4389 void CMmsEncode::EncodeMMBoxStates( RArray<TInt>& aStateArray )
  4389     {
  4390     {
  4390     TInt i;
  4391     TInt i;
  4391 
  4392 
  4392     for ( i = 0; i < aStateArray.Count(); ++i )
  4393     for ( i = 0; i < aStateArray.Count(); i++ )
  4393         {
  4394         {
  4394         EncodeMandatoryByte( KMmsAssignedMMState, aStateArray[i] );
  4395         EncodeMandatoryByte( KMmsAssignedMMState, aStateArray[i] );
  4395         }
  4396         }
  4396     }
  4397     }
  4397 
  4398 
  4724 
  4725 
  4725         retVal = CheckAndUpdateAttachmentL(*attachmentInfo, *iMimeHeaders);
  4726         retVal = CheckAndUpdateAttachmentL(*attachmentInfo, *iMimeHeaders);
  4726 
  4727 
  4727         if( retVal )
  4728         if( retVal )
  4728             {
  4729             {
  4729             TRAPD( 
       
  4730                     err,
       
  4731                     attachManagerSync.ModifyAttachmentInfoL(attachmentInfo);
       
  4732                     editStore->CommitL();
       
  4733                   );
       
  4734 #ifndef _NO_MMSS_LOGGING_
  4730 #ifndef _NO_MMSS_LOGGING_
       
  4731             TRAPD( err,attachManagerSync.ModifyAttachmentInfoL(attachmentInfo);
       
  4732                     editStore->CommitL(););
  4735             if(err != KErrNone)
  4733             if(err != KErrNone)
  4736                 {
  4734                 {
  4737                 TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentData:: store commit error: %d"), err );
  4735                 TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentData:: store commit error: %d"), err );
  4738                 }
  4736                 }
  4739             else
  4737             else
  4740                 {
  4738                 {
  4741                 TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentData:: store commit success") );                
  4739                 TMmsLogger::Log( _L("CMmsEncode::PreProcessAttachmentData:: store commit success") );                
  4742                 }
  4740                 }
       
  4741 #else
       
  4742 				    TRAP_IGNORE( attachManagerSync.ModifyAttachmentInfoL(attachmentInfo);
       
  4743                     editStore->CommitL(););	                
  4743 #endif /* _NO_MMSS_LOGGING_ */
  4744 #endif /* _NO_MMSS_LOGGING_ */
  4744             /*  attachmentInfo ownership is transferred to attachment manager
  4745             /*  attachmentInfo ownership is transfered to attachment manager
  4745              *  Hence, JUST pop attachmentInfo, DO NOT Destroy.
  4746              *  Hence, JUST pop attachmentInfo, DO NOT Destroy.
  4746              */
  4747              */
  4747             CleanupStack::Pop( attachmentInfo );
  4748             CleanupStack::Pop( attachmentInfo );
  4748             }
  4749             }
  4749         else
  4750         else
  4846     }
  4847     }
  4847     
  4848     
  4848 // ---------------------------------------------------------
  4849 // ---------------------------------------------------------
  4849 // CMmsEncode::ProcessAndConvertAttachmentDataL
  4850 // CMmsEncode::ProcessAndConvertAttachmentDataL
  4850 // converts of attachment data from source to target encoding type.
  4851 // converts of attachment data from source to target encoding type.
  4851 // |src charset buffer| --->converted to ---> |unicode buffer| ---> converted to ---> |target charset|
  4852 // |src charset buffer| --->coverted to ---> |unicode buffer| ---> converted to ---> |target charset|
  4852 // Returns false if data is already int target format, or plugins are missing, or file operation issues.
  4853 // Returns false if data is already int target format, or plugins are missing, or file operation issues.
  4853 // ---------------------------------------------------------
  4854 // ---------------------------------------------------------
  4854 TBool CMmsEncode::ProcessAndConvertAttachmentDataL( TUint aSrcCharSetMIBEnum,
  4855 TBool CMmsEncode::ProcessAndConvertAttachmentDataL( TUint aSrcCharSetMIBEnum,
  4855                                                     TUint aTargetCharSetMIBEnum, 
  4856                                                     TUint aTargetCharSetMIBEnum, 
  4856                                                     CMsvAttachment& aAttachmentInfo)
  4857                                                     CMsvAttachment& aAttachmentInfo)