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