Share: how to create a SMS with attachment in inbox

Login to reply to this topic.
Thu, 2007-09-20 13:19
Joined: 2007-05-30
Forum posts: 7

I followed the instruction from the link below: http://www.symbian.com/developer/techlib/v9.2docs/doc_source/faqsdk/faq_1151.html
But it doesn't work on 6630, 6600.

And I found a solution to it.



Thu, 2007-09-20 13:19
Joined: 2007-05-30
Forum posts: 7
Re: Share: how to create a SMS with attachment in inbox

CMsvSession* messageSession;
CClientMtmRegistry* registry;
TFileName details;
TFileName description;
TFileName fileName;
TEntryInfoHolder infoHolder;

messageSession = CMsvSession::OpenSyncL(*this);
CleanupStack::PushL(messageSession);

registry = CClientMtmRegistry::NewL( *messageSession );
CleanupStack::PushL( registry );

infoHolder.messageSession = messageSession;
infoHolder.iEntryId = 0; // No entry yet !
CleanupStack::PushL( TCleanupItem( DeleteEntry, &infoHolder ) );

// Subject
_LIT(KSub, "InterGrafx");
details.Copy( KSub() );

// Description
description.Copy( igpFileName );

// Get message inbox
CMsvEntry* inbox=messageSession->GetEntryL( KMsvGlobalInBoxIndexEntryIdValue );
CleanupStack::PushL( inbox );

TMsvEntry newEntry;

// Child entry of inbox
// TMsvEntry


Thu, 2007-09-20 13:20
Joined: 2007-05-30
Forum posts: 7
Re: Share: how to create a SMS with attachment in inbox

#ifdef __UIQV21__
newEntry.iMtm = TUid::Uid( KUidMsgTypeBT );
#endif

#ifdef __S60V12__
newEntry.iMtm = TUid::Uid( KUidMsgTypeBt );
#endif //
#ifdef __S60V22__
newEntry.iMtm = TUid::Uid( KUidMsgTypeBt.iUid );
#endif //__S60V22__
newEntry.SetVisible( EFalse );
newEntry.SetInPreparation( ETrue );
newEntry.iType = KUidMsvMessageEntry;
newEntry.iServiceId = KMsvUnknownServiceIndexEntryId;
newEntry.iDate.HomeTime();
newEntry.iSize = 120553;//todo
newEntry.iDetails.Set( details );
newEntry.iDescription.Set( description );

// For bio
// For future usage
//newEntry.iBioType = 0x101F3CD9;
//newEntry.iMtmData3 = 1;
//KMmsMessageMRetrieveConf | KMmsMessageMobileTerminated; // this defines MT message
//newEntry.iMtmData1 = 0;
//newEntry.iMtmData2 = 0;
//TUid aTypeUid;
//aTypeUid.iUid = 0x10000F6A;
//newEntry.iType = aTypeUid;
//TUid aMtmUid;
//aMtmUid.iUid = 0x10001262;
//newEntry.iMtm = aMtmUid;

inbox->CreateL(newEntry);
infoHolder.iEntryId=newEntry.Id();

CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL( *messageSession );
CleanupStack::PushL( mtmReg );

// Child entry of inbox
// CMsvEntry
CMsvEntry* entry = messageSession->GetEntryL( newEntry.Id() );
CleanupStack::PushL( entry );

CBaseMtm *mtm = mtmReg->NewMtmL( entry->Entry().iMtm );
// takes ownership
// The attachment will belong to it
mtm->SetCurrentEntryL( entry );
CleanupStack::Pop(); // entry
CleanupStack::PushL( mtm );

// Create an empty attachment
// On return, we get values of attachmentId, tempfileName
TFileName tempfileName;
TMsvId attachmentId;
mtm->CreateAttachmentL( attachmentId, tempfileName );

// Construct the path of the file to be created as attachment
HBufC* completeFilePath = HBufC::NewLC( 500 );
TPtr completeFilePathPtr = completeFilePath->Des();
completeFilePathPtr.Append( tempfileName );
completeFilePathPtr.Append( description );


Thu, 2007-09-20 13:20
Joined: 2007-05-30
Forum posts: 7
Re: Share: how to create a SMS with attachment in inbox

// Move igp file from c:\ to bt message attachment dir
// When download completes, igp is stored temporarily stored in c:\ //
RFs session;
session.Connect();
CleanupClosePushL( session );
CFileMan* fman = CFileMan::NewL( session );
fman->Move( igpFileName, *completeFilePath );
//TInt err =fman->Copy( igpFileName, *completeFilePath );

delete fman;
CleanupStack::PopAndDestroy(); // completeFilePath
CleanupStack::PopAndDestroy(); // session

// Process attachment
CMsvEntry* attachment=messageSession->GetEntryL( attachmentId );
TMsvEntry attachmentEntry=attachment->Entry();
CleanupStack::PushL( attachment );

// Set attachment attributes
fileName.Append( description );
TEntry fileEntry;
messageSession->FileSession().Entry( fileName, fileEntry );
attachmentEntry.iDetails.Set( description );
attachmentEntry.iDate.HomeTime();
attachmentEntry.iSize = fileEntry.iSize;

#ifdef __UIQV21__
ExternaliseAndCommit1FileNameL( attachment, TUid::Uid( KUidMsgTypeBT), &description );
#endif

#ifdef __S60V12__
ExternaliseAndCommit1FileNameL( attachment, TUid::Uid( KUidMsgTypeBt), &description );
#endif
#ifdef __S60V22__
ExternaliseAndCommit1FileNameL( attachment, TUid::Uid( KUidMsgTypeBt.iUid ), &description );
#endif

attachment->ChangeL( attachmentEntry );
CleanupStack::PopAndDestroy(); // attachment

newEntry = entry->Entry();
newEntry.iSize = fileEntry.iSize;
newEntry.SetVisible( ETrue );
newEntry.SetInPreparation( EFalse );
newEntry.SetUnread( ETrue );
entry->ChangeL( newEntry );

CleanupStack::PopAndDestroy(3); // inbox, mtmReg and mtm
CleanupStack::Pop(); // TCleanupItem(DeleteEntry, &infoHolder
CleanupStack::PopAndDestroy(2); // messageSession, registry

// For symbian v8 only


Thu, 2007-09-20 13:20
Joined: 2007-05-30
Forum posts: 7
Re: Share: how to create a SMS with attachment in inbox

#ifdef __S60V22__
#ifndef __S60V21__
// Open description file of the attachment
tempfileName.ZeroTerminate ();
TFileName desfileName = tempfileName.Left( tempfileName.Length () - 3 );
desfileName.ZeroTerminate ();

RFs fs;
User::LeaveIfError( fs.Connect() );

RFile attchDesFile;

// Unknown fields
TUint8 aUnkownFileds1[] = {0x68, 0x3C, 0x00, 0x10, 0x68, 0x3C, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x4B, 0x8E, 0x8D, 0x00, 0x02, 0xC5, 0xAA, 0x00, 0x10 };
TUint8 aUnkownFields2[] = {0x00 , 0x10 , 0x00 , 0x00 };
TUint8 aUnkownFields3[] = {0x00 , 0x00 , 0x00};
TUint8 aTrailingBytes[] = {0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

// Replace the automated generated description file
attchDesFile.Replace( fs, desfileName, EFileWrite | EFileStream );

RFileWriteStream stream(attchDesFile);

// Unknown fields
for ( TUint i = 0; i < sizeof( aUnkownFileds1 ) / sizeof ( TUint8 ); i ++ )
{
stream.WriteUint8L ( aUnkownFileds1[i] );
}

// 66 + attach file name length
// Increment by 8 when file length increments 1
stream.WriteUint8L ( 66 + igpFileName.Length() * 8 );

// Unknown fields
for ( i = 0; i < sizeof( aUnkownFields2 ) / sizeof ( TUint8 ); i ++ )
{
stream.WriteUint8L ( aUnkownFields2[i] );
}

// This field indicates the file name length
stream.WriteUint8L ( igpFileName.Length () );

// Unknown fields
for ( i = 0; i < sizeof( aUnkownFields3 ) / sizeof ( TUint8 ); i ++ )
{
stream.WriteUint8L ( aUnkownFields3[i] );
}

// attachment file name
stream.WriteL( igpFileName );

// Unknown fields
for ( i = 0; i < sizeof( aTrailingBytes ) / sizeof ( TUint8 ); i ++ )
{
stream.WriteUint8L ( aTrailingBytes[i] );
}

stream.Close ();
attchDesFile.Close ();
fs.Close();
#endif //#ifndef __S60V21__
#endif //#ifdef __S60V22__

#ifdef __S60V21__
// Open description file of the attachment
tempfileName.ZeroTerminate ();
TFileName desfileName21 = tempfileName.Left( tempfileName.Length () - 3 );
desfileName21.ZeroTerminate ();

RFs fs21;
User::LeaveIfError( fs21.Connect() );

RFile attchDesFile21;

// Unknown fields
TUint8 aUnkownFileds1_21[] = {0x68, 0x3C, 0x00, 0x10, 0x68, 0x3C, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x4B, 0x8E, 0x8D, 0x00, 0x02, 0xC5, 0xAA, 0x00, 0x10 };
TUint8 aUnkownFields2_21[] = {0x00 ,0x00 , 0x00 };
//TUint8 aUnkownFields3[] = {0x00 , 0x00 , 0x00};
TUint8 aTrailingBytes_21[] = {0x00, 0x00, 0x00, 0x00};

// Replace the automated generated description file
attchDesFile21.Replace( fs21, desfileName21, EFileWrite | EFileStream );

RFileWriteStream stream21(attchDesFile21);

// Unknown fields
for ( TUint i = 0; i < sizeof( aUnkownFileds1_21 ) / sizeof ( TUint8 ); i ++ )
{
stream21.WriteUint8L ( aUnkownFileds1_21[i] );
}

// 66 + attach file name length
// Increment by 8 when file length increments 1
stream21.WriteUint8L ( 34 + igpFileName.Length() * 8 );

// This field indicates the file name length
stream21.WriteUint8L ( igpFileName.Length () );

// Unknown fields
for ( i = 0; i < sizeof( aUnkownFields2_21 ) / sizeof ( TUint8 ); i ++ )
{
stream21.WriteUint8L ( aUnkownFields2_21[i] );
}

// Unknown fields
//for ( TUint i = 0; i < sizeof( aUnkownFields3 ) / sizeof ( TUint8 ); i ++ )
// {
// stream.WriteUint8L ( aUnkownFields3[i] );
// }

// attachment file name
stream21.WriteL( igpFileName );

// Unknown fields
for ( i = 0; i < sizeof( aTrailingBytes_21 ) / sizeof ( TUint8 ); i ++ )
{
stream21.WriteUint8L ( aTrailingBytes_21[i] );
}

stream21.Close ();
attchDesFile21.Close ();
fs21.Close();
#endif

#ifdef __UIQV21__
// Open description file of the attachment
tempfileName.ZeroTerminate ();
TFileName desfileNameUiq = tempfileName.Left( tempfileName.Length () - 3 );
desfileNameUiq.ZeroTerminate ();

RFs fsUiq;
User::LeaveIfError( fsUiq.Connect() );

RFile attchDesFileUiq;

// Unknown fields
TUint8 aUnkownFileds1Uiq[] = {0x68, 0x3C, 0x00, 0x10, 0x68, 0x3C, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x4B, 0x8E, 0x8D, 0x00, 0x02, 0xA4, 0x53, 0x00, 0x10 };

TUint8 aUnknownFileds2Uiq[] = { 0x00, 0x00, 0x00 };
// Replace the automated generated description file
attchDesFileUiq.Replace( fsUiq, desfileNameUiq, EFileWrite | EFileStream );

RFileWriteStream streamUiq(attchDesFileUiq);

// Unknown fields
for ( TUint i = 0; i < sizeof( aUnkownFileds1Uiq ) / sizeof ( TUint8 ); i ++ )
{
streamUiq.WriteUint8L ( aUnkownFileds1Uiq[i] );
}

// 66 + attach file name length
// Increment by 8 when file length increments 1
streamUiq.WriteUint8L ( 18 + igpFileName.Length() * 8 );

// This field indicates the file name length
streamUiq.WriteUint8L ( igpFileName.Length () );

for ( i = 0; i < sizeof( aUnknownFileds2Uiq ) / sizeof ( TUint8 ); i ++ )
{
streamUiq.WriteUint8L ( aUnknownFileds2Uiq[i] );
}

// attachment file name
streamUiq.WriteL( igpFileName );

// Unknown fields

streamUiq.Close ();
attchDesFileUiq.Close ();
fsUiq.Close();

#endif


Thu, 2007-09-20 15:34
Forum Nokia Champion
Joined: 2004-05-26
Forum posts: 732
Re: Share: how to create a SMS with attachment in inbox

What about creating a neat article on NewLC Tutorils section about your solution?


  • Login to reply to this topic.