void CAddObexAttachmentAsEntryState::StartL(TRequestStatus& aStatus)
    {
    // Add an attachment as a child entry

    CBaseMtm& clientMtm = iClientTest.ObexTestUtils().GetCurrentObexClientMtm();

	CMsvEntry& entry = clientMtm.Entry();
	CMsvStore* store = entry.EditStoreL();
	CleanupStack::PushL(store);
	
	CAsyncWaiter* waiter = CAsyncWaiter::NewL();
	CleanupStack::PushL(waiter);
	CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
	CleanupStack::PushL(attachment);
	TParse fileNameParser;
	User::LeaveIfError(fileNameParser.Set(iFileName, NULL, NULL));
	attachment->SetAttachmentNameL(fileNameParser.NameAndExt());
	store->AttachmentManagerL().AddAttachmentL(iFileName, attachment, waiter->iStatus);
	CleanupStack::Pop(attachment);
	waiter->StartAndWait();
	User::LeaveIfError(waiter->Result());
	CleanupStack::PopAndDestroy(waiter);
	
	store->CommitL();
	CleanupStack::PopAndDestroy(store);

    TRequestStatus* status = &aStatus;
	User::RequestComplete(status, KErrNone);
    }
/**
Schedules aMessage on the schedule referred to by aRef.

Updates the message entry and the schedule data using the utility function 
UpdateEntryAfterSchedule().

@see	CMsvScheduleSend::UpdateEntryAfterSchedule

@param	aMessage
The message to be scheduled.

@param	aFinalState
The sending state to set to the messages to if the message is successfully 
scheduled.

@param	aFromTime
The time to schedule the messages for sending.

@param	aRef
The ID of the schedule to add this task to.

@param	aPendingConditions
A flag indicating whether this message is schedule for conditions.
*/
void CMsvScheduleSend::ScheduleEntryL(CMsvScheduledEntry& aMessage, const TInt aFinalState, const TTime& aStartTime, const TSchedulerItemRef& aRef, TBool aPendingConditions)
	{
	//Create a new task to associate with the schedule
	TTaskInfo taskInfo;
	iPackage.iId = aMessage.Id();
	
	ScheduleEntryL(iScheduler, aRef, iPackage, taskInfo);

	// Change the scheduled flag and sending state of the message
	if( iServerEntry.SetEntry(aMessage.Id()) == KErrNone )
		{
		TMsvEntry entry(iServerEntry.Entry());

		aMessage.Entry(entry);
		UpdateEntryAfterSchedule(aRef, taskInfo, aStartTime, aFinalState, entry, aMessage.iData);
		entry.SetPendingConditions(aPendingConditions);

		SCHSENDLOG(FLog(_L8("\t\tScheduled msg %d (Mtm=%d, State=%d, Sch=%d, Task=%d, Pending=%d)"), entry.Id(), entry.iMtm.iUid, aFinalState, aMessage.iData.iRef.iHandle, aMessage.iData.iTaskId, entry.PendingConditions()));

		User::LeaveIfError(iServerEntry.ChangeEntry(entry));

		//Store the message data
		CMsvStore* store = iServerEntry.EditStoreL();
		CleanupStack::PushL(store);
		aMessage.StoreL(*store);
		store->CommitL();
		CleanupStack::PopAndDestroy(store);
		iServerEntry.SetEntry(KMsvNullIndexEntryId);
		}
	}
void CMsgImOutboxSend::RestoreBccRecipientsToHeaderL()
	{
	if (!iServerEntry.HasStoreL() || !iBccRcptArray || iBccRcptArray->Count()==0)
		return; // no recipients to restore.

	CMsvStore* store = iServerEntry.EditStoreL();
	CleanupStack::PushL(store);
	
	// Must have an rfc822 header.
	CImHeader* header = CImHeader::NewLC();
	if (store->IsPresentL( KUidMsgFileIMailHeader) )
		{
		header->RestoreL(*store);
		header->BccRecipients().Reset();

		TInt ii = iBccRcptArray->Count(); 
		while (ii-- > 0)
			header->BccRecipients().InsertL(0, (*iBccRcptArray)[ii]);
		header->StoreL(*store);	
		store->CommitL();
		}

	// To stop the array growing, delete and recreate.
	iBccRcptArray->Reset();
	delete iBccRcptArray;
	iBccRcptArray=0;
	iBccRcptArray = new (ELeave) CDesCArrayFlat(KBccArraySegment);

	CleanupStack::PopAndDestroy(header);
	CleanupStack::PopAndDestroy(store); 
	}
void CMtfTestActionAddAttachmentAsLink::RunTestL()
	{
	CMsvStore* paramStore = ObtainParameterReferenceL<CMsvStore>(TestCase(),ActionParameters().Parameter(0));
	HBufC* paramFilePath   = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(1));
	HBufC8* paramMimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(2));
	
	
	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
	CleanupStack::PushL(waiter);
	
	CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvLinkedFile);
	CleanupStack::PushL(attachment);
	
	attachment->SetMimeTypeL(*paramMimeType);
	
	TParse fileNameParser;
	User::LeaveIfError(fileNameParser.Set(*paramFilePath, NULL, NULL));
	attachment->SetAttachmentNameL(fileNameParser.NameAndExt());
	
	MMsvAttachmentManager& manager = paramStore->AttachmentManagerL();
	
	manager.AddLinkedAttachmentL(*paramFilePath, attachment, waiter->iStatus);
	CleanupStack::Pop(attachment); // ownership passed to manager

	waiter->StartAndWait();
	User::LeaveIfError(waiter->Result());
	CleanupStack::PopAndDestroy(waiter);
	
	TMsvAttachmentId attachmentId = attachment->Id();
	
	paramStore->CommitL();
	
	StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(3));	
	}
Exemple #5
0
void CTextMtmClient::SaveMessageL()
// Store entry data 
// If it is a service entry, store the current settings. Otherwise it has to be
// a message. 
//
	{
	__ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
	// get an editable message store
	CMsvStore* store = iMsvEntry->EditStoreL();
	CleanupStack::PushL(store);

	switch (iMsvEntry->Entry().iType.iUid)
		{
		case KUidMsvServiceEntryValue:
			iSettings->SaveSettingsL(iMsvEntry->Entry().Id(), iTxtSettings);
			break;
		case KUidMsvMessageEntryValue:
			StoreBodyL(*store);	
			break;
		default:
			__ASSERT_DEBUG(EFalse, gPanic(ETxtcEntryTypeNotSupported));
			break;
		}

	store->CommitL();
	CleanupStack::PopAndDestroy(); // store
	}
// ---------------------------------------------------------
// CUniObjectList::EnsureAllObjectsHaveContentLocationL
//
// EnsureAllObjectsHaveContentLocationL
// ---------------------------------------------------------
//
EXPORT_C void CUniObjectList::EnsureAllObjectsHaveContentLocationL()
    {
    CMsvStore* store = iMtm.Entry().EditStoreL();
    CleanupStack::PushL( store );
    MMsvAttachmentManager& manager = store->AttachmentManagerL();
    MMsvAttachmentManagerSync& managerSync = store->AttachmentManagerExtensionsL();
    TBool commit( EFalse );
	TInt a = iObjectArray->Count();
    while ( a-- )
        {
        CUniObject* obj = iObjectArray->At( a );
        if ( !obj->MimeInfo()->ContentLocation().Length()
        	&& obj->AttachmentId( ) )
            {
            CMsvAttachment* attachment = manager.GetAttachmentInfoL( obj->AttachmentId() );
            CleanupStack::PushL( attachment );
            TParsePtrC parse( obj->MediaInfo()->FullFilePath() );
            TPtrC nameAndExt( parse.NameAndExt() );
            obj->MimeInfo()->EnsureContentLocationL(
                manager,
                *attachment,
                nameAndExt );
            managerSync.ModifyAttachmentInfoL( attachment );
            CleanupStack::Pop( attachment );
            commit = ETrue;
            }
		}
    if ( commit )
        {
        store->CommitL();
        }
    CleanupStack::PopAndDestroy( store );
	}
// -----------------------------------------------------------------------------
// CWPMessage::StoreMsgL
// -----------------------------------------------------------------------------
//
void CWPMessage::StoreMsgL()
    {
    FLOG( _L( "CWPMessage::StoreMsgL" ) );
    
    // create an invisible blank entry 
    TMsvEntry entry;
    PrepareEntryLC( entry ); // details on cleanup stack
    entry.iBioType = iBioUID.iUid;
    entry.iMtm = KUidBIOMessageTypeMtm;
    
    // Look up and set the description
    FLOG( _L( "CWPMessage::StoreMsgL 1" ) );
    
    TInt index;
    CBIODatabase* bioDB = CBIODatabase::NewLC( iSession->FileSession() );
    FLOG( _L( "CWPMessage::StoreMsgL 2" ) );
    TRAPD( err, bioDB->GetBioIndexWithMsgIDL( iBioUID, index ) );
    if (err ==KErrNone)
        {
        FLOG( _L( "CWPMessage::StoreMsgL 3" ) );
        HBufC* description = bioDB->BifReader(index).Description().AllocL();
        FLOG( _L( "CWPMessage::StoreMsgL 4" ) );
        entry.iDescription.Set(*description);
        FLOG( _L( "CWPMessage::StoreMsgL 5" ) );
        CleanupStack::PopAndDestroy();  // bioDB
        CleanupStack::PushL( description );
        }
    else
        {
        FTRACE(RDebug::Print(_L(" CWPMessage::StoreMsgL err (%d)"), err));
        CleanupStack::PopAndDestroy();  // bioDB
        }
        
    FLOG( _L( "CWPMessage::StoreMsgL 6" ) );
    // Store entry in inbox
    CMsvEntry* msvEntry = iSession->GetEntryL( KMsvGlobalInBoxIndexEntryId );
    FLOG( _L( "CWPMessage::StoreMsgL 7" ) );
    CleanupStack::PushL(msvEntry);
    msvEntry->CreateL(entry);
    msvEntry->Session().CleanupEntryPushL(entry.Id());
    msvEntry->SetEntryL(entry.Id());
    FLOG( _L( "CWPMessage::StoreMsgL 8" ) );
    // Save the message
    CMsvStore* store = msvEntry->EditStoreL();
    CleanupStack::PushL(store);
    FLOG( _L( "CWPMessage::StoreMsgL 9" ) );
    iMessage->StoreL( *store );
    store->CommitL();
    
    // Complete processing the message
    PostprocessEntryL( *msvEntry, entry );

    CleanupStack::PopAndDestroy(); //store
    msvEntry->Session().CleanupEntryPop(); //entry
    CleanupStack::PopAndDestroy(3); //description, details, msvEntry
    FLOG( _L( "CWPMessage::StoreMsgL Done" ) );
    }
void CSmsReplyToStep::CreateMessageL()
	{
	INFO_PRINTF1(_L("Creating message..."));
	
	TMsvEntry entry;
	entry.SetVisible(ETrue); 
	entry.SetInPreparation(ETrue); 
	entry.iServiceId = iTestUtils->iSmsServiceId; 
	entry.iType = KUidMsvMessageEntry; 
	entry.iMtm = KUidMsgTypeSMS; 
	entry.iDate.HomeTime(); 
	entry.iSize = 0; 
	entry.iDescription.Set(KNullDesC); 
	entry.iDetails.Set(KNullDesC); 
	entry.SetSendingState(KMsvSendStateScheduled);

	// Create the SMS header object...
	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *iTestUtils->iRichText);
	CleanupStack::PushL(header);
	
	// Set the body text...
	iTestUtils->iRichText->Reset();
	iTestUtils->iRichText->InsertL(0, KMessageData);
	
	// Copy the message settings...
	header->SetSmsSettingsL(*iTestUtils->iServiceSettings); 
	
	// Set the service centre
	TInt defaultIndex = iTestUtils->iServiceSettings->DefaultServiceCenter();
	header->SetServiceCenterAddressL(iTestUtils->iServiceSettings->GetServiceCenter(defaultIndex).Address());

	// Set recipient - ask derived class
	SetRecipientsL(*header);
	
	// Update entry description and details...
	CArrayPtrFlat<CSmsNumber>& recipient = header->Recipients();
	entry.iDetails.Set(recipient[0]->Address());
	entry.iDescription.Set(iTestUtils->iRichText->Read(0, iTestUtils->iServiceSettings->DescriptionLength()));
	entry.SetInPreparation(EFalse);
	
	// Create the entry - set context to the global outbox.
	iTestUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
	iTestUtils->iMsvEntry->CreateL(entry);

	// Create new store and save header information 
	iTestUtils->iMsvEntry->SetEntryL(entry.Id()); 
	CMsvStore* store = iTestUtils->iMsvEntry->EditStoreL(); 
	CleanupStack::PushL(store); 
	header->StoreL(*store);
	store->StoreBodyTextL(*iTestUtils->iRichText);
	store->CommitL(); 
	CleanupStack::PopAndDestroy(2, header); 
	
	iMessageId = entry.Id();

	}
// -----------------------------------------------------------------------------
// CWPMessage::StoreMsgL
// -----------------------------------------------------------------------------
//
void CWPMessage::StoreMsgL( TInt aResource )
    {
    FLOG( _L( "CWPMessage::StoreMsgL(aResource)" ) );
    
    // create an invisible blank entry 
    TMsvEntry entry;
    PrepareEntryLC( entry ); // details on cleanup stack
    entry.iMtm = KUidMsgTypeSMS;     

    // Store entry in inbox
    CMsvEntry* msvEntry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
    CleanupStack::PushL(msvEntry);
    msvEntry->CreateL(entry);
    msvEntry->Session().CleanupEntryPushL(entry.Id());
    msvEntry->SetEntryL(entry.Id());

    // Save the message body
    CMsvStore* store = msvEntry->EditStoreL();
    CleanupStack::PushL(store);
    CParaFormatLayer* paraFormat = CParaFormatLayer::NewL();
    CleanupStack::PushL( paraFormat );
    CCharFormatLayer* charFormat = CCharFormatLayer::NewL();
    CleanupStack::PushL( charFormat );
    CRichText* body = CRichText::NewL( paraFormat, charFormat );
    CleanupStack::PushL( body );
    HBufC* text = LoadStringLC( aResource );
    body->InsertL( body->DocumentLength(), *text );
    store->StoreBodyTextL( *body );

    // Store the actual message for post-mortem analysis
    iMessage->StoreL( *store );

    // Save the SMS header and create a description field
    CSmsHeader* header = CSmsHeader::NewL( CSmsPDU::ESmsDeliver, *body );
    CleanupStack::PushL( header );
    TBuf<KSmsDescriptionLength> description;

    CSmsGetDetDescInterface* smsPlugin = CSmsGetDetDescInterface::NewL();
    CleanupStack::PushL( smsPlugin );
    smsPlugin->GetDescription( header->Message(), description );
    CleanupStack::PopAndDestroy( smsPlugin );

    entry.iDescription.Set( description );
    header->StoreL( *store );
    store->CommitL();
    CleanupStack::PopAndDestroy( 5 ); // header, text, body, charformat, paraFormat

    // Complete processing the message
    PostprocessEntryL( *msvEntry, entry );

    CleanupStack::PopAndDestroy(); //store
    msvEntry->Session().CleanupEntryPop(); //entry
    CleanupStack::PopAndDestroy(2); //details, msvEntry
    }
EXPORT_C void CImSSmtpSettings::StoreL(CMsvStore& aMsvStore) const
	{
	RMsvWriteStream out;
	out.AssignLC( aMsvStore, KUidMsvServiceEntry ); // pushes 'out' to the stack
	TRAPD(error, ExternalizeL(out));
	if (error==KErrNone)
		out.CommitL();
	out.Close(); // make sure we close the file
	User::LeaveIfError(error);
	aMsvStore.CommitL();
	CleanupStack::PopAndDestroy();
	}
LOCAL_C void CreateNewPlaintextMessageL()
	{
	CTestActive* testActive = new(ELeave) CTestActive();
	CleanupStack::PushL(testActive);
	TMsvEmailTypeList msvEmailTypeList = 0;
	TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments);
	CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(testActive->iStatus, *(testUtils->iMsvSession),KMsvGlobalOutBoxIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP);
	CleanupStack::PushL(emailOperation);
	TestMsvOperationTimer* testMsvOperationTimer = TestMsvOperationTimer::NewLC(test.Console(), emailOperation, test);
	testActive->StartL();
	testMsvOperationTimer->IssueRequest();
	CActiveScheduler::Start();
	//check progress
	TMsvId temp;
	TPckgC<TMsvId> paramPack(temp);
	const TDesC8& progBuf = emailOperation->ProgressL();
	paramPack.Set(progBuf);
	TMsvId newMessageId;
	newMessageId = paramPack();
	test(newMessageId != NULL);
	testUtils->WriteComment(_L("\t Created New plaintext message"));
	testUtils->iMsvEntry->SetEntryL(newMessageId);
    CMsvStore* store = testUtils->iMsvEntry->EditStoreL();
	CleanupStack::PushL(store);
	CImHeader* header = CImHeader::NewLC();
	header->RestoreL(*store);
	
	TInt serverLength = testUtils->MachineName().Length();
	HBufC* serverad = HBufC::NewL(serverLength + 7 ); // 7 is the length of KServerAddress
	CleanupStack::PushL(serverad);
	serverad->Des().Copy(testUtils->MachineName());
	serverad->Des().Append(KServer);	
    HBufC* emailaddress = HBufC::NewL(serverLength + 8 + serverad->Des().Length() + 1 );
   	CleanupStack::PushL(emailaddress);
   	emailaddress->Des().Copy(testUtils->MachineName());
   	emailaddress->Des().Append(KAt);
   	emailaddress->Des().Append(*serverad);
   	header->ToRecipients().AppendL(*emailaddress);
   	
	header->SetSubjectL(_L("Test sending message using CMsvEntry::CopyL!!"));
	header->StoreL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy(emailaddress);
	CleanupStack::PopAndDestroy(serverad);
	CleanupStack::PopAndDestroy(5,testActive); // header,store,testMsvOperationTimer,emailOperation,testActive
	
		
	}
void CMsvSendExe::UpdateEntryL(CMsvEntry& aMsvEntry, TMsvEntry& aEntry, const TSchedulerItemRef& aRef, const TTaskInfo& aInfo, const TTime& aStartTime)
	{
	CMsvStore* store = aMsvEntry.EditStoreL();
	CleanupStack::PushL(store);

	TMsvEntryScheduleData data;
	data.RestoreL(*store);

	CMsvScheduleSend::UpdateEntryAfterSchedule(aRef, aInfo, aStartTime, KMsvSendStateResend, aEntry, data);

	data.StoreL(*store);
	store->CommitL();

	CleanupStack::PopAndDestroy(store);
	aMsvEntry.ChangeL(aEntry);
	}
void CImOperationQueueList::StoreQueuedListL(CImQueuedList &aList)
//
// Store contents of aList back in current entry (pointed to by iServiceEntry)
// to aList.
//	
	{
	__ASSERT_DEBUG( iServiceEntry->Entry().iMtm  == KUidMsgTypeIMAP4, gPanic(EOffOpBadMtmTypeUid));
	__ASSERT_DEBUG( iServiceEntry->Entry().iType == KUidMsvFolderEntry ||
				    iServiceEntry->Entry().iType == KUidMsvServiceEntry, gPanic(EOffOpEntryShouldBeFolder));
	CMsvStore* store = iServiceEntry->EditStoreL();
	CleanupStack::PushL(store);
    CImOffLineArrayStore externaliser(aList);
    externaliser.StoreL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy();//store
	}
void CMtfTestActionRemoveAllAttachments::ExecuteActionL()
	{
	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionRemoveAllAttachments);
	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
	TInt attachIdFlag = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(2), 0);

	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
	CleanupStack::PushL(entry);
	
	CMsvStore* store = entry->EditStoreL();
	CleanupStack::PushL(store);
	
	MMsvAttachmentManager& manager = store->AttachmentManagerL();
	
	TInt attachmentCount = manager.AttachmentCount();
		
	for ( ; attachmentCount > 0 ; attachmentCount-- )
	{
	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
	CleanupStack::PushL(waiter);
		
	if( attachIdFlag == 1 )
		{
		CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(0);
		CleanupStack::PushL(attachInfo);
				
		manager.RemoveAttachmentL(attachInfo->Id(), waiter->iStatus);
		CleanupStack::PopAndDestroy(attachInfo);
		}
	else
		{
		manager.RemoveAttachmentL(0, waiter->iStatus);
		}
	waiter->StartAndWait();
	User::LeaveIfError(waiter->Result());
	CleanupStack::PopAndDestroy(waiter);
	}
	
	store->CommitL();
	
	CleanupStack::PopAndDestroy(2, entry); // store, entry

	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionRemoveAllAttachments);
	TestCase().ActionCompletedL(*this);
	}
Exemple #15
0
/* 
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CFakeSMSSender::FinalizeMessageL(TMsvId aEntryId,const TDesC& aBody,const TDesC& aRecipientName,TTime aMsgTime)
{
 	CMsvEntry* entry = iMsvSession->GetEntryL(aEntryId);
    CleanupStack::PushL(entry);
	
	TMsvEntry newEntry(entry->Entry());              // This represents an entry in the Message Server index
   	newEntry.SetInPreparation(EFalse);                       // a flag that this message is in preparation
	newEntry.iDetails.Set(aRecipientName);
	newEntry.SetUnread(ETrue);
	newEntry.iDate = aMsgTime;
	newEntry.SetReadOnly(ETrue);				

	CMsvStore* srore = entry->EditStoreL();
	CleanupStack::PushL(srore);
	if(srore)
	{		
		CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
		CleanupStack::PushL(paraFormatLayer);
		CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
		CleanupStack::PushL(charFormatLayer);
		CRichText* messageBodyContent = CRichText::NewL(paraFormatLayer, charFormatLayer);
		CleanupStack::PushL(messageBodyContent);
					
		messageBodyContent->InsertL(0,aBody);
		
		srore->StoreBodyTextL(*messageBodyContent);
		srore->CommitL();
			
		CleanupStack::PopAndDestroy(3); // messageBodyContent, charFormatLayer,paraFormatLayer

		if(aBody.Length() > 50)
			newEntry.iDescription.Set(aBody.Left(50));
		else
			newEntry.iDescription.Set(aBody);
	}
	
	CleanupStack::PopAndDestroy(srore);
	
	entry->ChangeL(newEntry);	
	entry->MoveL(aEntryId,KMsvGlobalInBoxIndexEntryId);

	CleanupStack::PopAndDestroy(entry);
}
/**
Stores the Unknown Push message in the message store.

Saves the message data in a new attachment file. This makes it more efficient for the UI
to read the data.

@param	aSession		
Message server session

@param	aParent	
ID of the parent for the new entry. It is the caller's responsibility to ensure 
that the parent ID is correct.

@return	
ID of the new message server entry.

@see	CPushMsgEntryBase::SaveL()
*/
EXPORT_C TMsvId CUnknownPushMsgEntry::SaveL(CMsvSession& aSession, TMsvId aParent)

	{
	CMsvEntry* entryPtr = aSession.GetEntryL(KMsvRootIndexEntryId);
	CleanupStack::PushL(entryPtr);

	// This tidies itself up
	TMsvId newEntry = CPushMsgEntryBase::SaveL(aSession, aParent);
	
#ifdef __MESSAGING_API_V2__
	TRAPD(
		saveError,
		TFileName fileName = ContentFileNameL();
		entryPtr->SetEntryL(newEntry);
		CMsvStore* store = entryPtr->EditStoreL();
		CleanupStack::PushL(store);
		SaveMessageBodyL(store->AttachmentManagerL(), fileName);
		store->CommitL();
		CleanupStack::PopAndDestroy(store);
		)
/*
	Sets the message's scheduled flag to EFalse
	Resets the schedule data associated with each message
	Resets the number of retries for each recipient
	Stores the data and recipients (in a stream associated with the TMsvEntry)
*/
void CMsvScheduleSend::SendingCompleteL(CMsvScheduledEntry& aMessage, const TBool aChangeEntry)
	{
	__ASSERT_DEBUG(iServerEntry.Entry().Id() == aMessage.Id(), gPanic(EServerEntryNotSetToCorrectEntry));
	
	aMessage.SetScheduled(EFalse);
	aMessage.iData.Reset();
	aMessage.RecipientsResetRetries();

	if (aChangeEntry)
		{
		TMsvEntry entry = iServerEntry.Entry();
		aMessage.Entry(entry);
		User::LeaveIfError(iServerEntry.ChangeEntry(entry));
		}

	CMsvStore* store = iServerEntry.EditStoreL();
	CleanupStack::PushL(store);
	aMessage.StoreL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy(store); 
	}
void CMtfTestActionAddEntryAttachment::RunTestL()
{
    CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
    TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
    TMsvId attachmentMessageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(2));

    CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
    CleanupStack::PushL(entry);

    CMsvStore* store = entry->EditStoreL();
    CleanupStack::PushL(store);

    CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
    CleanupStack::PushL(waiter);

    CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvMessageEntry);
    CleanupStack::PushL(attachment);

    TMsvEntry attachmentEntry;
    TMsvId attachmentServiceEntry;
    User::LeaveIfError(paramSession->GetEntry(attachmentMessageEntry, attachmentServiceEntry, attachmentEntry));
    attachment->SetSize(attachmentEntry.iSize);

    MMsvAttachmentManager& manager = store->AttachmentManagerL();

    manager.AddEntryAsAttachmentL(attachmentMessageEntry, attachment, waiter->iStatus);
    CleanupStack::Pop(attachment); // ownership passed to manager
    waiter->StartAndWait();
    User::LeaveIfError(waiter->Result());
    CleanupStack::PopAndDestroy(waiter);

    TMsvAttachmentId attachmentId = attachment->Id();

    store->CommitL();

    CleanupStack::PopAndDestroy(2, entry); // store, entry

    StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(3));
}
// Static functions that do the whole process in one go:
EXPORT_C  void CObexMtmFileNameExternaliser::ExternaliseAndCommit1FileNameL(CMsvEntry* aEntry, const TDesC16* aFileName)
/**
* Static function to write one and only one filename to the message store, then finalise and commit it. This function
* should be called ONCE ONLY. To externalise more than one filename, instantiate this class and use ExternaliseFileNameL()
* followed by CommitStoreL().
* @param aEntry the entry whose store is to be written to
* @param aFileName The filename to write to the store
* @leave KErrXXX system-wide error codes
*/	
	{
	CMsvStore* messageStore = aEntry->EditStoreL();
	CleanupStack::PushL(messageStore);

	RMsvWriteStream messageWriteStream;
	CleanupClosePushL(messageWriteStream);

	messageWriteStream.AssignL(*messageStore, KObexFileNameStreamUid);

	// write the identifier so we know we are internalizing a stream later
#ifndef TEST_INC042468
	messageWriteStream.WriteInt32L(KObexFileNameStreamFileNameUid);
#endif
	messageWriteStream.WriteInt32L(aFileName->Length());  
	messageWriteStream.WriteL(*aFileName);

#ifndef TEST_INC042468
	messageWriteStream.WriteInt32L(KObexFileNameStreamFileNameUid);
#endif
	messageWriteStream.WriteInt32L(0);		//Mark the end of the filename list

	messageWriteStream.CommitL();

	CleanupStack::PopAndDestroy(); // trigger a call to Close(); on messageWriteStream as well as removing from the stack

	messageStore->CommitL();
	CleanupStack::PopAndDestroy(messageStore);
	}
//---------------------------------------------------------------
// TestUniDataModelPlugin::createMMS
//---------------------------------------------------------------
void TestUniDataModelMMSPlugin::createMMS(TMsvId pId, TBool subjectField)
    {
    TMsvEntry indexEntry;
    indexEntry.iType = KUidMsvMessageEntry;
    indexEntry.iMtm = KUidMsgTypeMultimedia;
    indexEntry.iServiceId = iServiceId;
    indexEntry.iDate.HomeTime();
    
    // Convert TTime to QDateTime , this will be used for comparing the time of mesage 
    // when fetched from datamodel
    TTime unixEpoch(KUnixEpoch);
    TTimeIntervalSeconds seconds;
    TTime timeStamp = indexEntry.iDate;
    timeStamp.SecondsFrom(unixEpoch, seconds);
    retTimeStamp.setTime_t(seconds.Int());

    TMsvId parentId = pId;
    CMsvEntry* entry = CMsvEntry::NewL(*iMSession,parentId,TMsvSelectionOrdering());
    CleanupStack::PushL(entry);

    entry->SetEntryL(parentId);
    entry->CreateL(indexEntry);
    entry->SetEntryL(indexEntry.Id());
    iMmsClientMtm->SwitchCurrentEntryL(entry->EntryId());

    CMsvStore* store = iMmsClientMtm->Entry().EditStoreL();
    CleanupStack::PushL(store);
      
    //MMS Message ID Saved
    iMessageId = indexEntry.Id();
    
    //Adding Subject
    if(subjectField)
        {
        QString subject(TEST_MSG_SUBJECT);
        HBufC* subj = XQConversions::qStringToS60Desc(subject);
        iMmsClientMtm->SetSubjectL(*subj);
        }

    //Adding Sender
    QString sender(TEST_MSG_FROM1);
    HBufC* addr = XQConversions::qStringToS60Desc(sender);
    
    if (addr)
        {
        CleanupStack::PushL(addr);
        TBuf<32> name;
        name.Copy(addr->Left(32));
        indexEntry.iDetails.Set(name);
        
        iMmsClientMtm->SetSenderL(*addr);
        
        CleanupStack::PopAndDestroy(addr);
        }
    
    //Adding Recipient
    QString recipient(TEST_MSG_RECIEPIENT1);
    HBufC* addr2 = XQConversions::qStringToS60Desc(recipient);
    if (addr2)
        {
        CleanupStack::PushL(addr2);
        iMmsClientMtm->AddAddresseeL(EMsvRecipientTo,*addr2);
        CleanupStack::PopAndDestroy(addr2);
        }
    
    //Adding cCRecipient
    QString recipient2(TEST_MSG_RECIEPIENT2);
    HBufC* addr3 = XQConversions::qStringToS60Desc(recipient2);
    if (addr3)
        {
        CleanupStack::PushL(addr3);
        iMmsClientMtm->AddAddresseeL(EMsvRecipientCc,*addr3);
        CleanupStack::PopAndDestroy(addr3);
        }
      
    //Adding bCCRecipient
    QString recipient3(TEST_MSG_RECIEPIENT3);
	HBufC* addr4 = XQConversions::qStringToS60Desc(recipient3);
	if (addr4)
		{
		CleanupStack::PushL(addr4);
		iMmsClientMtm->AddAddresseeL(EMsvRecipientBcc,*addr4);
		CleanupStack::PopAndDestroy(addr4);
		}
	
    //Create Text Attachment
    TMsvAttachmentId attaId = 0;
    TFileName attachmentFile( _L("story.txt") );
    TBufC<12> story = _L( "Hello world!" );
    
    iMmsClientMtm->CreateTextAttachmentL(*store, attaId, story, attachmentFile, ETrue );
    qDebug() << "Text Attachment id" << attaId;
    
    //Image Attachment added to the message entry
    RFile attaFile;
	// Set filename of attachment
	TFileName name( KPictureFileName );
   
	CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL();
	CleanupStack::PushL( mimeHeaders );
   
	// Set values to mime headers
	mimeHeaders->SetContentTypeL( _L8( "image") );
	mimeHeaders->SetContentSubTypeL( _L8( "jpeg" ) );
   
	_LIT8(KMimeType, "image/jpeg");
	TBufC8<10> mimeType(KMimeType);
	// CreateAttachment2L will set the content type to attachment Info
   
	// Open the attachment file for reading
	attaFile.Open( iFs, name, EFileShareReadersOnly | EFileRead );
	CleanupClosePushL(attaFile);
   
	CMsvAttachment* attaInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
	// attaInfo ownerhip will be transferred to Attachment Manager.
	// It must not be pushed onto the cleanupStack before calling 
	// CreateAttachment2L.
   
	iMmsClientMtm->CreateAttachment2L(*store, attaFile,mimeType,*mimeHeaders,attaInfo,attaId);
	qDebug() << "Image Attachment id" << attaId;
	
	// Now Attachment Manager owns the attaInfo
	CleanupStack::Pop(); // attaFile.Close()
	CleanupStack::PopAndDestroy(); // mimeHeaders
        
    store->CommitL();
    
    CleanupStack::PopAndDestroy(store); // store
    
    iMmsClientMtm->SaveMessageL();
    
    //Saving the message size for future checking
    msgSize = iMmsClientMtm->MessageSize();
    
    CleanupStack::Pop(entry); // entry
    }
LOCAL_C void CreateNewPlaintextMessageL()
	{
	CTestActive* testActive = new(ELeave) CTestActive();
	CleanupStack::PushL(testActive);
	TMsvEmailTypeList msvEmailTypeList = 0;
	TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments);
	CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(testActive->iStatus, *(testUtils->iMsvSession),KMsvGlobalOutBoxIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP);
	CleanupStack::PushL(emailOperation);
	TestMsvOperationTimer* testMsvOperationTimer = TestMsvOperationTimer::NewLC(test.Console(), emailOperation, test);
	testActive->StartL();
	testMsvOperationTimer->IssueRequest();
	CActiveScheduler::Start();
	//check progress
	TMsvId temp;
	TPckgC<TMsvId> paramPack(temp);
	const TDesC8& progBuf = emailOperation->ProgressL();
	paramPack.Set(progBuf);
	TMsvId newMessageId;
	newMessageId = paramPack();
	test(newMessageId != NULL);
	CImEmailMessage* imEmailMessage = CImEmailMessage::NewLC(*(testUtils->iMsvEntry));
	// Make sure you are set on the Message Id
	testUtils->iMsvEntry->SetEntryL(newMessageId);
	CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
	CleanupStack::PushL(attachmentInfo);
	attachmentInfo->SetAttachmentNameL(KAttachmentFileName1());
	CleanupStack::Pop(attachmentInfo);	 // ownership passed to attachment manager
	imEmailMessage->AttachmentManager().AddAttachmentL(KAttachment1, attachmentInfo, testActive->iStatus);
	testActive->StartL();
	CActiveScheduler::Start();	// wait for the asynch operation to complete
	if (testActive->iStatus.Int())
		{
		testUtils->WriteComment(_L("CreateNewPlaintextMessageWithIncompleteAttachmentL failed"));
		testUtils->TestHarnessFailed(testActive->iStatus.Int());
		}
	testUtils->iMsvEntry->SetEntryL(newMessageId);
	CMsvAttachment* attachmentInfo1 = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
	CleanupStack::PushL(attachmentInfo1);
	attachmentInfo1->SetAttachmentNameL(KAttachmentFileName2());
    CleanupStack::Pop(attachmentInfo1);	 // ownership passed to attachment manager
	imEmailMessage->AttachmentManager().AddAttachmentL(KAttachment2, attachmentInfo1, testActive->iStatus);
	testActive->StartL();
	CActiveScheduler::Start();	// wait for the asynch operation to complete
	if (testActive->iStatus.Int())
		{
		testUtils->WriteComment(_L("CreateNewPlaintextMessageWithIncompleteAttachmentL failed"));
		testUtils->TestHarnessFailed(testActive->iStatus.Int());
		}
	testUtils->iMsvEntry->SetEntryL(newMessageId);
	CMsvAttachment* attachmentInfo2 = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
	CleanupStack::PushL(attachmentInfo2);
	attachmentInfo2->SetAttachmentNameL(KAttachmentFileName3());
    CleanupStack::Pop(attachmentInfo2);	 // ownership passed to attachment manager
	imEmailMessage->AttachmentManager().AddAttachmentL(KAttachment3, attachmentInfo2, testActive->iStatus);
	testActive->StartL();
	CActiveScheduler::Start();	// wait for the asynch operation to complete
	if (testActive->iStatus.Int())
		{
		testUtils->WriteComment(_L("CreateNewPlaintextMessageWithIncompleteAttachmentL failed"));
		testUtils->TestHarnessFailed(testActive->iStatus.Int());
		}	
	const TDesC8& progBuf2 = imEmailMessage->ProgressL();	
	paramPack.Set(progBuf2);
	TMsvId attachmentId = paramPack();
	testUtils->WriteComment(_L("\t Created New plaintext message"));
	testUtils->iMsvEntry->SetEntryL(attachmentId);
	
    imEmailMessage->GetAttachmentsListL(testActive->iStatus, newMessageId, CImEmailMessage::EAllAttachments, CImEmailMessage::EThisMessageOnly);	
  	testActive->StartL();
	CActiveScheduler::Start();	// wait for the asynch operation to complete
    const CMsvEntrySelection& selection = imEmailMessage->Selection();
	testUtils->Printf(KTotalNoOfAttachment , selection.Count());
	imEmailMessage->GetBodyTextEntryIdL(testActive->iStatus,newMessageId,CImEmailMessage::EThisMessageOnly);
	testActive->StartL();
	CActiveScheduler::Start();	// wait for the asynch operation to complete
	const CMsvEntrySelection& selection1 = imEmailMessage->Selection();
	TInt count = imEmailMessage->Selection().Count();
    if( count > 0)
			{
			// Get the Id of the body text
			// The body text part Id is present at index 0.  Not checking for other
			//  Ids, as currently only Plain text part is verified.
			TMsvId	iBodyTextId = imEmailMessage->Selection().At(0);
			testUtils->Printf(KBodytextId, iBodyTextId);
			}
	CleanupStack::PopAndDestroy(); // imEmailMessage  
		testUtils->iMsvEntry->SetEntryL(attachmentId);
    CMsvStore* store1 = testUtils->iMsvEntry->EditStoreL();
	CleanupStack::PushL(store1);
	CImMimeHeader *Head1 = CImMimeHeader::NewLC();
    Head1->RestoreL(*store1);
	const TPtrC8 contentSubType = Head1->ContentSubType();
	store1->CommitL();
    
    if(contentSubType.Size() == 0 )
    {
    testUtils->Printf(_L("ContentSubType Has NO SUB CONTENT****") );
    test(contentSubType.Size() != 0);
    }
    else
    {
    testUtils->Printf(_L("ContentSubType Has ****SUB CONTENT****"));	
    }
   	CleanupStack::PopAndDestroy(2, store1);//store1,Head1,Buffer
    testUtils->iMsvEntry->SetEntryL(newMessageId);
    CMsvStore* store = testUtils->iMsvEntry->EditStoreL();
	CleanupStack::PushL(store);
	CImHeader* header = CImHeader::NewLC();
	header->RestoreL(*store);
	TInt serverLength = testUtils->MachineName().Length();
	HBufC* serverad = HBufC::NewL(serverLength + 7 ); // 7 is the length of KServerAddress
	CleanupStack::PushL(serverad);
	serverad->Des().Copy(testUtils->MachineName());
	serverad->Des().Append(KServer);	
    HBufC* emailaddress = HBufC::NewL(serverLength + 8 + serverad->Des().Length() + 1 );
   	CleanupStack::PushL(emailaddress);
   	emailaddress->Des().Copy(testUtils->MachineName());
   	emailaddress->Des().Append(KAt);
   	emailaddress->Des().Append(*serverad);
   	header->ToRecipients().AppendL(*emailaddress);
	header->SetSubjectL(_L("Test sending message using CMsvEntry::CopyL!!"));
	header->StoreL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy(emailaddress);
	CleanupStack::PopAndDestroy(serverad);
	CleanupStack::PopAndDestroy(5,testActive); // header,store,testMsvOperationTimer,emailOperation,testActive
	
		
	}
LOCAL_C void CreateMessageL()
	{	
	testUtils->TestStart(testNo++);
	testUtils->WriteComment(_L("CreateMessageL"));
	CTestActive* testActive = new (ELeave) CTestActive();
	CleanupStack::PushL(testActive);

	TMsvPartList partList = KMsvMessagePartBody | KMsvMessagePartAttachments | KMsvMessagePartDescription | KMsvMessagePartOriginator;
	TMsvEmailTypeList msvEmailTypeList = 0;
	CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(testActive->iStatus, *(testUtils->iMsvSession), KMsvGlobalOutBoxIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP);
	CleanupStack::PushL(emailOperation);

	TestUiTimer* testUiTimer = TestUiTimer::NewLC(test.Console(), emailOperation);
	testActive->StartL();
	testUiTimer->IssueRequest();
	CActiveScheduler::Start();

	TMsvId temp;	
	TPckgC<TMsvId> paramPack(temp);
	const TDesC8& progBuf = emailOperation->ProgressL();
	paramPack.Set(progBuf);
	TMsvId messageId=paramPack();
	TInt error = emailOperation->iStatus.Int();

	CleanupStack::PopAndDestroy(3, testActive); // testActive, emailOperation, testUiTimer
	testUtils->TestFinish(testNo-1, error);

	// fill in details for email message
	testUtils->iMsvEntry->SetEntryL(messageId);
	CMsvStore* store = testUtils->iMsvEntry->EditStoreL();
	CleanupStack::PushL(store);
	CImHeader* header = CImHeader::NewLC();
	header->RestoreL(*store);
	header->ToRecipients().AppendL(_L("*****@*****.**"));
	header->SetSubjectL(_L("Message from T_SMTC Typhoon!!"));
	header->StoreL(*store);
	store->CommitL();
 	CleanupStack::PopAndDestroy(2, store); // header, store

	//store some body text!!
	CParaFormatLayer* paraFormatLayer=CParaFormatLayer::NewL();
	CleanupStack::PushL(paraFormatLayer);

	CCharFormatLayer* charFormatLayer=CCharFormatLayer::NewL(); 
	CleanupStack::PushL(charFormatLayer);

	CRichText* bodyText=CRichText::NewL(paraFormatLayer, charFormatLayer, CEditableText::EFlatStorage, 256);
	CleanupStack::PushL(bodyText);

	TBuf<100> bodyContents = _L("Test body contents so that we can test the store body text code.");
	bodyText->InsertL(0, bodyContents);

	// store the body text
	testActive = new (ELeave) CTestActive();
	CleanupStack::PushL(testActive);

	CImEmailMessage* imEmailMessage = CImEmailMessage::NewLC(*(testUtils->iMsvEntry));
	imEmailMessage->StoreBodyTextL(messageId, *bodyText, testActive->iStatus);
	testActive->StartL();
	CActiveScheduler::Start();	// wait for the asynch operation to complete
	CleanupStack::PopAndDestroy(5, paraFormatLayer); // imEmailMessage, testActive, bodyText, charFormatLayer, paraFormatLayer
	}
TVerdict CCreateSmsMessageTestStep::doTestStepL()
	{

	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
	CActiveScheduler::Install(scheduler);
	CleanupStack::PushL(scheduler);

	CSessionObserver* sessionObserver = new (ELeave) CSessionObserver;
	CleanupStack::PushL(sessionObserver);
	CMsvSession* session = CMsvSession::OpenSyncL(*sessionObserver);
	CleanupStack::PushL(session);
	
	_LIT(KFileName,"FileName");
	TPtrC tag;
	if ( !GetStringFromConfig(ConfigSection(),KFileName,tag))
		{
		ERR_PRINTF1(_L("No Input for FileName in CreateSmsMessage"));
		User::Leave(KErrNotReady);
		}
	
	HBufC* fileName = tag.AllocLC();
	

	// Create a Rich Text object
	CPlainText::TTextOrganisation ttOrg = {CPlainText::EOrganiseByLine};

	CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL();
	CleanupStack::PushL(paraFormatLayer);
	CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL();
	CleanupStack::PushL(charFormatLayer);
	CRichText* bodyRichText = CRichText::NewL(paraFormatLayer, charFormatLayer);
	CleanupStack::PushL(bodyRichText);
	
	// Store the file contents into the CRichText object
	bodyRichText->ImportTextFileL(0, fileName->Des(), ttOrg);
	
	
	// Create the SMS header object...
	CSmsHeader* header = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *bodyRichText);
	CleanupStack::PushL(header);
	
	// Set the body text...
	CSmsSettings* smsSettings = CSmsSettings::NewL();
	CleanupStack::PushL(smsSettings);

	CSmsAccount* account = CSmsAccount::NewLC();
	account->LoadSettingsL(*smsSettings);
	// Copy the message settings...
	header->SetSmsSettingsL(*smsSettings); 
	
	// Set the service centre
	TInt defaultIndex = smsSettings->DefaultServiceCenter();
	header->SetServiceCenterAddressL(smsSettings->GetServiceCenter(defaultIndex).Address());

	// Set recipient - ask derived class
	SetRecipientsL(*header);
	CArrayPtrFlat<CSmsNumber>& recipient = header->Recipients();

	INFO_PRINTF1(_L("Creating message..."));
	
	TMsvEntry entry;
	entry.SetVisible(ETrue); 
	entry.SetInPreparation(ETrue);
	TMsvId srvcId=0;
	TSmsUtilities::ServiceIdL(*session, srvcId);
	entry.iServiceId = srvcId;
	entry.iType = KUidMsvMessageEntry; 
	entry.iMtm = KUidMsgTypeSMS; 
	entry.iDate.UniversalTime();
	entry.iSize = 0; 
	entry.iDescription.Set(KNullDesC); 
	entry.iDetails.Set(KNullDesC); 
	entry.SetSendingState(KMsvSendStateWaiting);

	// Update entry description and details...
	entry.iDetails.Set(recipient[0]->Address());
	entry.iDescription.Set(recipient[0]->Address());
	entry.SetInPreparation(EFalse);

	//TPtrC tag;
	_LIT(KParent,"Parent");
	TPtrC parentTag;
	if ( !GetStringFromConfig(ConfigSection(),KParent,parentTag))
		{
		ERR_PRINTF1(_L("No Input for Outbox"));
		User::Leave(KErrNotReady);
		}
	// Create the entry - set context to the global outbox.
	TMsvId paramParentId =	MsgingUtils::GetLocalFolderId(parentTag);//KMsvGlobalOutBoxIndexEntryId;

	CMsvEntry* newEntry = CMsvEntry::NewL(*session,paramParentId,TMsvSelectionOrdering());
	CleanupStack::PushL(newEntry);
	newEntry->SetEntryL(paramParentId);
	
	newEntry->CreateL(entry);

	// Create new store and save header information
	newEntry->SetEntryL(entry.Id());
	CMsvStore* store = newEntry->EditStoreL();
	CleanupStack::PushL(store);
	header->StoreL(*store);
	store->StoreBodyTextL(*bodyRichText);
	store->CommitL();

//store,newEntry,account, smsSettings, header, bodyRichText,charFormatLayer, paraFormatLayer,fileName
	CleanupStack::PopAndDestroy(9,fileName); 
	
	CleanupStack::PopAndDestroy(3, scheduler);
	
	SetTestStepResult(EPass);
	
	return TestStepResult();
	}
void CImSmtpSession::SendFileL()
	{
	// Start the 'file mailer' object
	__ASSERT_DEBUG(!iSmtpFile,gPanic(EImsmSmtpFileObjectAlreadyExists));
	// log the info of the message to be sent
	if (iLogMessage)
		iLogMessage->Reset();
	//  Update the header info for this message..
	CImHeader* header = CImHeader::NewLC();
	CMsvStore* store = iServerEntry.EditStoreL();
	CleanupStack::PushL(store);
	header->RestoreL(*store);

	TBool isBccRcpt = EFalse;
	CDesCArray* rcptArray = NULL;
	TBool sendBccNow = iToRcptHeaderUpdated;

	if(!iToRcptHeaderUpdated)
		{
		//  Set the new info...
		//set from address
		HBufC* formatedAddress = CreateFormattedAddressLC(iSettings.EmailAddress(), iSettings.EmailAlias());//Format the address fields
		header->SetFromL(*formatedAddress);
		CleanupStack::PopAndDestroy(formatedAddress);
		formatedAddress = NULL;

		// set ReceiptAddress if one exists in the settings
		if( header->ReceiptAddress().Length() == 0 && iSettings.ReceiptAddress().Length() > 0 )
			{
			formatedAddress=CreateFormattedAddressLC(iSettings.ReceiptAddress(),iSettings.EmailAlias());//Format the address fields
			header->SetReceiptAddressL(*formatedAddress);
			CleanupStack::PopAndDestroy(formatedAddress);
			formatedAddress = NULL;
			}

		if(header->ToRecipients().Count()==0 && header->CcRecipients().Count()==0)
			{
			sendBccNow=ETrue;
			}

		// ReplyToAddress
		if ((header->ReplyTo().Length() == 0 || header->ReplyTo() == iSettings.ReplyToAddress()) &&
		    (iSettings.ReplyToAddress().Length() > 0))
			{
			formatedAddress= CreateFormattedAddressLC(iSettings.ReplyToAddress(),iSettings.EmailAlias());//Format the address fields
			header->SetReplyToL(*formatedAddress);
			CleanupStack::PopAndDestroy(formatedAddress);
			formatedAddress = NULL;
			}
		
		//make a copy of 'Bcc' recipients then remove from Msg header
		rcptArray= &(header->BccRecipients());
		if (iSettings.SendCopyToSelf()==ESendCopyAsBccRecipient)
			{
			if ( header->ReceiptAddress().Length() )
				rcptArray->AppendL(header->ReceiptAddress());
			else if ( header->ReplyTo().Length() )
				rcptArray->AppendL(header->ReplyTo());
			}

		if(rcptArray->Count() > 0)
			{
			iBccRcptFound=ETrue; // 'Bcc' recipients exists
			iBccRcptIndex=0;	  //reset the counter
			iFinishedWithBccRcpts=EFalse;

			iSendFiles->ResetBccRcptArrayL();

			TInt numberRcpts = rcptArray->Count();
			if(numberRcpts)
			{
			iSendFiles->BccRcptArray().AppendL((*rcptArray)[0]);
			CDesCArray& tempArr = iSendFiles->BccRcptArray();
			for(TInt counter=1; counter<numberRcpts; counter++)
				{
				TInt aPos = 0;
				tempArr.Find((*rcptArray)[counter],aPos,ECmpFolded16);			
				if(aPos > 0)	
				iSendFiles->BccRcptArray().AppendL((*rcptArray)[counter]);
				}
				}
			rcptArray->Reset();
			}

		iToRcptHeaderUpdated=ETrue;
		isBccRcpt=EFalse;
		}

	// Reset the number of Sent Messages, if all previous messages have been sent
	if (iNumMsgsSent >= iNumMsgsToSend)
		{
		iNumMsgsSent = 0;
		}

	// Calc the num of messages we're sending. If there is a To or CC,
	// recipient then there will be a message sent
	if(header->ToRecipients().Count()>0 || header->CcRecipients().Count()>0)
		iNumMsgsToSend = 1;
	else
		iNumMsgsToSend = 0;

	// If there are BCC recipients, then we will be sending a message to each
	if (iBccRcptFound)
		iNumMsgsToSend += iSendFiles->BccRcptArray().Count();

	// Make sure there are recipients to send to.
	__ASSERT_ALWAYS(iNumMsgsToSend,gPanic(EImsmZeroRecipientsInMessage));

	// sending Msg to 'Bcc' recipients so update header
	if (sendBccNow && iBccRcptFound)
		{
		rcptArray= &(header->BccRecipients());
		rcptArray->Reset();
		header->BccRecipients().AppendL(iSendFiles->BccRcptArray()[iBccRcptIndex]);

		++iBccRcptIndex;//for the next recipient
		if(iBccRcptIndex < iSendFiles->BccRcptArray().Count())
			iFinishedWithBccRcpts=EFalse;
		else
			iFinishedWithBccRcpts=ETrue;

		isBccRcpt=ETrue;
		}

	header->StoreL(*store);
	store->CommitL();
	if (iLogMessage)
		{
		iLogMessage->LogEvent().SetEventType(KLogMailEventTypeUid);
		if ((header->ToRecipients().Count()
 			+ header->CcRecipients().Count()
 			+ header->BccRecipients().Count()) > 1)
 		// If there are multiple recipients then set the recipient to 'multiple'
 			{
 			TBuf<KLogMaxSharedStringLength> multipleRecipientsString;
 			iLogMessage->GetString(multipleRecipientsString, R_LOG_REMOTE_MULTIPLE);
 			iLogMessage->LogEvent().SetRemoteParty(multipleRecipientsString);
 			}
 		else
 		// If there is only one recipient then set the recipient name
 			{
			if (header->ToRecipients().Count())
				iLogMessage->LogEvent().SetRemoteParty(header->ToRecipients()[0]);

			else if (header->CcRecipients().Count())
				iLogMessage->LogEvent().SetRemoteParty(header->CcRecipients()[0]);

			else if (header->BccRecipients().Count())
				iLogMessage->LogEvent().SetRemoteParty(header->BccRecipients()[0]);
			}

		iLogMessage->LogEvent().SetSubject(header->Subject());

		TBuf<KLogMaxSharedStringLength> outString;
		iLogMessage->GetString(outString, R_LOG_DIR_OUT);
		iLogMessage->LogEvent().SetDirection(outString);

		iLogMessage->LogEvent().SetLink(iServerEntry.Entry().Id());
		}

	CleanupStack::PopAndDestroy(2, header);

	iTimeNow.UniversalTime();	// Set time/date of sending this message file
	if (iLogMessage)
		iLogMessage->LogEvent().SetTime(iTimeNow);
	TRAPD(error,iSmtpFile = CImSmtpFile::NewL(	*iSocket,
                                                iServerEntry,
												iTimeNow,
												iSmtpBuffer,
												iSettings,
												isBccRcpt)); // Create the file mailing object

	if(error == KErrNone)
		{
		// If this is the first message to send, then calc the total bytes to send
		if (iNumMsgsSent == 0)
			{
			iTotalBytesToSend =  iSmtpFile->TotalMsgSizeL() * iNumMsgsToSend;
			}

		// Tell the file how many bytes it will be sending.  This is just a
		// rough estimate for progress
		iSmtpFile->SetBytesToSend(iTotalBytesToSend/iNumMsgsToSend);

		// Increment the number of messages sent
		++iNumMsgsSent;

		iSmtpFile->StartL(iStatus);		// start sending the message
		MOBILITY_TEST_MTM_STATE(iServiceId, KMobilityTestMtmStateSmtpSendFile);
		}
	else
		{
		iCompleted=error;
		RequestComplete(iStatus,0-error);	// Failed to create File object, but don't want to stop session prematurely, so negate error code
		}
	}
Exemple #25
0
//
//  StoreL() - Store bookmarks as an attachment file 
//	in the .eBM format. If the system runs out of memory while
//  the bookmarks are being written to the file, the file will be
//	deleted. For example, if 2 bookmarks have already been written
//	to the file, and the writing of the third bookmark fails, the
//	file will be deleted. Otherwise, a failure of file writing would
//	need to be handled differently from memory allocation failure.
//
void CWWWHotlistParser::StoreL(CMsvEntry& aEntry)
{
	TInt numberOfItems = iHotlistItemList->Count();
	
	if (numberOfItems>0)  // Only create a file if there is something to save!
	{

		// Generate fileName from msgId and bookmark file extension.
		// The file name consists of the msgId in hex format 
		// followed by .eBM. Sizeof operator returns the size of msgId
		// in bytes and each byte requires 2 hex digits to represent it,
		// hence sizeof is multipled by 2. Didn't want to make
		// fileNameLength constant because the size of TMsvId may change
		// in the future.

		TMsvId entryId = aEntry.Entry().Id();

		TInt fileNameLength = 2*sizeof(entryId) + 
				KEBookmarkExtension().Length();

		HBufC *fileName = HBufC::NewLC(fileNameLength);
			
		TPtr fileNameDes = fileName->Des();

		// The file name uses the hex representation of the entry Id.
		// If this changes to some other representation then
		// fileNameLength will need to be calculated differently.

		fileNameDes.Num(entryId,EHex);
			
		fileNameDes.Append(KEBookmarkExtension);

		// Get the attachment manager and create an empty attachment file
		CMsvStore* store = aEntry.EditStoreL();
		CleanupStack::PushL(store);
		
		MMsvAttachmentManagerSync& managerSync = store->AttachmentManagerExtensionsL();
		CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
		CleanupStack::PushL(attachment);
		attachment->SetAttachmentNameL(*fileName);
		RFile file;
		managerSync.CreateAttachmentL(*fileName, file, attachment);
		CleanupStack::Pop(attachment); // ownership passed
		CleanupClosePushL(file);

#ifdef SYMBIAN_BOOKMARK_DATABASE
		// Open the bookmark database ready to add the bookmarks
		RBkDatabase bookmarkDb;
		bookmarkDb.OpenL();
		CleanupClosePushL(bookmarkDb);
#endif // SYMBIAN_BOOKMARK_DATABASE

		// Stream each bookmark into the file.
		// The eBookmark file must contain only 8bit ascii.
		// Add a linefeed to the end of each line.
			
		for(TInt count=0; count < numberOfItems; count++)
			{
			CWWWHotlistItem &item = *iHotlistItemList->At(count);
			
			// Allocate enough space to hold the full bookmark entry.

			TInt length =	item.Name().Length() + 
							item.Url().Length()  + 
							KEBookmarkConstantChars;
			
			HBufC8 *writeBuf = HBufC8::NewLC(length);
			
			TPtr8 des = writeBuf->Des();

			des.Append(KEBookmarkItemBegin);
			des.Append(KEBookmarkItemURL);
			des.Append(item.Url());
			des.Append(KCRLinefeed);
			des.Append(KEBookmarkItemName);
			des.Append(item.Name());
			des.Append(KCRLinefeed);
			des.Append(KEBookmarkType);
			des.Append(KEBookmarkItemEnd);

			User::LeaveIfError(file.Write(des));
			
			CleanupStack::PopAndDestroy();
			
#ifdef SYMBIAN_BOOKMARK_DATABASE
			// Add the bookmark to the bookmark database
			RBkBookmark bookmark = bookmarkDb.CreateBookmarkL();
			CleanupClosePushL(bookmark);
			bookmark.SetTitleL(item.Name());
			// Convert Uri to 8-bit
			HBufC8* bookmarkUri = HBufC8::NewLC(item.Url().Length());
			bookmarkUri->Des().Copy(item.Url());
			bookmark.SetUriL(*bookmarkUri);
			CleanupStack::PopAndDestroy(2, &bookmark); // bookmarkUri, bookmark
#endif // SYMBIAN_BOOKMARK_DATABASE
			}
			
#ifdef SYMBIAN_BOOKMARK_DATABASE			
		// Commit all the added bookmarks and close bookmark db
		bookmarkDb.CommitL();
		CleanupStack::PopAndDestroy(&bookmarkDb);
#endif // SYMBIAN_BOOKMARK_DATABASE

		// File writing has completed, set the size in the attachment
		TInt fileSize = 0;
		User::LeaveIfError(file.Size(fileSize));
		attachment->SetSize(fileSize);
		
		// commit the changes
		store->CommitL();
		CleanupStack::PopAndDestroy(3, fileName); // file, store, fileName
	}
}
void CSmtpClientMtm::StoreEmailMessageL()
	{
	__ASSERT_DEBUG(KUidMsvMessageEntryValue==iMsvEntry->Entry().iType.iUid, gPanic(ESmtcMTMNotAMessageEntry));
	CMsvStore* store = iMsvEntry->EditStoreL();
	CleanupStack::PushL(store);

	// Save the Email header stream...
	iHeader->SetSubjectL(SubjectL());
	const TInt numberOfRecipients=iAddresseeList->Count();
	// put all addressees in the To: field...
	for (TInt n=0 ; n < numberOfRecipients ; ++n)
		{
		// validation done by ValidateMessage()
		switch(iAddresseeList->Type(n))
			{
		case EMsvRecipientTo:
			iHeader->ToRecipients().AppendL(AddresseeList()[n]);
			break;
		case EMsvRecipientCc:
			iHeader->CcRecipients().AppendL(AddresseeList()[n]);
			break;
		case EMsvRecipientBcc:
			iHeader->BccRecipients().AppendL(AddresseeList()[n]);
			break;
			}
		}

	iHeader->StoreL(*store);
	store->CommitL();

	// NB the From field will be set by server MTM when the email message is sent

	CleanupStack::PopAndDestroy();

	TMsvEntry messageEntry=iMsvEntry->Entry();
	CImEmailMessage* emailMessage = CImEmailMessage::NewLC(*iMsvEntry);

	// now store the body text
	emailMessage->StoreBodyTextL(messageEntry.Id(), Body(), iWait->iStatus);
	iWait->Start();		// wait for the asynch operation to complete
	
	// 
	// I have stored away all the email data,
	// now update the TMsventry that represents
	// the email to ensure that it is up to date
	//
	TInt32 totalSizeOfAllAttachments = GetAttachmentSizeL(*emailMessage, messageEntry.Id());

	messageEntry.iSize = iHeader->DataSize() + Body().DocumentLength() + totalSizeOfAllAttachments;
	messageEntry.iDescription.Set(iHeader->Subject());
	messageEntry.iDate.UniversalTime();

	// fix for DEF051564 - SMTP client MTM CreateMessageL not creating message in correct state
	//
	// since CreateMessageL creates message as in preparation and non-visible, the SaveMessageL
	// must now make it visible and not in preparation
	messageEntry.SetVisible(ETrue);
	messageEntry.SetInPreparation(EFalse);

	if (iHeader->ToRecipients().Count()>0)
		messageEntry.iDetails.Set(iHeader->ToRecipients()[0]);
	else if (iHeader->CcRecipients().Count())
		messageEntry.iDetails.Set(iHeader->CcRecipients()[0]);
	else if (iHeader->BccRecipients().Count())
		messageEntry.iDetails.Set(iHeader->BccRecipients()[0]);
	//else do nothing as there are no recipients yet!

	if (totalSizeOfAllAttachments>0)
		messageEntry.SetAttachment(ETrue);

	// if there are multiple recipients then set the flag
	if ((iHeader->ToRecipients().Count() + iHeader->CcRecipients().Count() + iHeader->BccRecipients().Count()) >=2)
		messageEntry.SetMultipleRecipients(ETrue);

	// update the contents of the message entry
	iMsvEntry->ChangeL(messageEntry);

	CleanupStack::PopAndDestroy();	// emailMessage
	}
// ----------------------------------------------------------------------------
// CIpsPlgNewChildPartFromFileOperation::PrepareStoreL
// ----------------------------------------------------------------------------
//
void CIpsPlgNewChildPartFromFileOperation::PrepareStoreL()
    {
    CMsvEntry* cAtta = iMsvSession.GetEntryL( iNewAttachmentId );
    CleanupStack::PushL( cAtta );
    TBool parentToMultipartAlternative( EFalse );
    if( cAtta->HasStoreL() )
        {
        CMsvStore* store = cAtta->EditStoreL();
        CleanupStack::PushL( store );
        CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
        
        if( store->IsPresentL( KUidMsgFileMimeHeader ) )
            {
            mimeHeader->RestoreL( *store );
            CDesC8Array& array = mimeHeader->ContentTypeParams();
            array.AppendL( KMethod );
            parentToMultipartAlternative = ETrue;
            
            if( iContentType->Des().Find( KMimeTextCalRequest ) != KErrNotFound )
                {    
                array.AppendL( KRequest );
                }
            else if( iContentType->Des().Find( KMimeTextCalResponse ) != KErrNotFound )
                {
                array.AppendL( KResponse );
                }
            else if( iContentType->Des().Find( KMimeTextCalCancel ) != KErrNotFound ) 
                {
                array.AppendL( KCancel );
                }
            else
                {
                parentToMultipartAlternative = EFalse;
                }
            mimeHeader->StoreWithoutCommitL( *store );
            store->CommitL();
            }
        
        CleanupStack::PopAndDestroy( 2, store );
        }

    if( parentToMultipartAlternative &&
        iFilePath->Find( KFileExtensionICS ) != KErrNotFound )
        {        
        TMsvEntry tAttaEntry = cAtta->Entry();
        TMsvId id = tAttaEntry.Parent();
        CMsvEntry* cParent = iMsvSession.GetEntryL( id );
        CleanupStack::PushL( cParent );
        
        TMsvEmailEntry tEntry = cParent->Entry();
        tEntry.SetMessageFolderType( EFolderTypeAlternative );
        
        // Do async again if needed

        iOperation = cParent->ChangeL( tEntry, iStatus );
        CleanupStack::PopAndDestroy( cParent );
        CleanupStack::PopAndDestroy( cAtta );
        }
    else
        {
        CleanupStack::PopAndDestroy( cAtta );
        iStatus = KRequestPending;
        TRequestStatus* status = &iStatus;
        User::RequestComplete(status,KErrNone);
        }
    iStep = EStoreMessagePart; // Next step
    SetActive();
    }
void TestUniDataModelVCalPlugin::CreateBioEntryClientSideL(TMsvEntry& aEntry,
                                                           CRichText& aBody)
{
		if (inbox)
			{
				iMsvEntry->SetEntryL(KMsvGlobalInBoxIndexEntryId);
			}
		else if (drafts)
			{
				iMsvEntry->SetEntryL(KMsvDraftEntryId);
			}
		//  Get the global inbox.   

		iMsvEntry->CreateL(aEntry);
		iMsvEntry->SetEntryL(aEntry.Id());

		// Save all the changes
		CMsvStore* store = iMsvEntry->EditStoreL();
		CleanupStack::PushL(store);

		if (store->HasBodyTextL())
			{
				store->DeleteBodyTextL();
			}

		CPlainText* pText = CPlainText::NewL();
		CleanupStack::PushL(pText);

		if (inbox)
			{
				CSmsHeader* smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, *pText);
				CleanupStack::PushL(smsHeader);
				smsHeader->SetFromAddressL(*tempNumber);
				smsHeader->StoreL(*store);
				
			}
		else if (drafts)
			{

			QString recepient(TEST_MSG_FROM1);
			QString recepient2(TEST_MSG_FROM2);
			QString alias(TEST_MSG_ALIAS1);

			HBufC* addr = XQConversions::qStringToS60Desc(recepient);
			HBufC* addr2 = XQConversions::qStringToS60Desc(recepient2);
			HBufC* alias1 = XQConversions::qStringToS60Desc(alias);

			CSmsHeader* smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit, *pText);
			CleanupStack::PushL(smsHeader);

			CSmsNumber* number1 = CSmsNumber::NewL(); // create the instance
			CleanupStack::PushL(number1);

			number1->SetNameL(TPtrC());
			number1->SetAddressL(*addr);
			smsHeader->Recipients().AppendL(number1);
			CleanupStack::Pop(number1);

			CSmsNumber* number2 = CSmsNumber::NewL();
			CleanupStack::PushL(number2);

			number2->SetNameL(*alias1);
			number2->SetAddressL(*addr2);

			smsHeader->Recipients().AppendL(number2);
			CleanupStack::Pop(number2);
			smsHeader->StoreL(*store);

			}

    store->StoreBodyTextL(aBody);
    store->CommitL();

    CleanupStack::PopAndDestroy(3); //store - close the store

    aEntry.SetComplete(ETrue);
    // Update the entry
    iMsvEntry->ChangeL(aEntry);
    iMsvEntry->SetEntryL(KMsvRootIndexEntryId);
}
LOCAL_C TBool TestGetBodyTextL()
	{
	__UHEAP_MARK;
	// Retrieve the store from the current context... 
	CMsvStore* store = pContext->EditStoreL();
	CleanupStack::PushL(store);
	
	// Populate CMsvBodyText from the data in the store...
	CMsvBodyText* obj = CMsvBodyText::NewLC();
	obj->RestoreL(*store);
	
	// Create a rich text object...
	CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
	CleanupStack::PushL(paraLayer);
	CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
	CleanupStack::PushL(charLayer);
	CRichText* richText = CRichText::NewL(paraLayer, charLayer);
	CleanupStack::PushL(richText);
	
	// Create an array of available character sets...
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* charSets;
	CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewL();
	CleanupStack::PushL(converter);
	charSets = converter->CreateArrayOfCharacterSetsAvailableLC(gFs);
	
	// For each available character set, call GetBodyTextL...
	TInt i;
	for (i = 0; i < charSets->Count(); i++)
		{
		// Over-ride the stored character set.
		obj->SetCharacterSet((*charSets)[i].Identifier());
		// Convert the 8 bit data to the specified character set.
		obj->GetBodyTextL(gFs, *store, *richText);
		test(richText->HasChanged());
		richText->Reset();
		}
	
	// Instead of decoding 10 bytes of data, increase the amount of data to 4000 bytes.
	obj->SetCharacterSet(0);
	obj->SetDefaultCharacterSet((*charSets)[0].Identifier());
	const TInt KTextBufferSize=4000;
	CBufBase *buffer=CBufFlat::NewL(KTextBufferSize);
	CleanupStack::PushL(buffer);
	while(buffer->Size()<KTextBufferSize)
		{
		buffer->InsertL(buffer->Size(),K10BytesData);
		}

	obj->StoreL(*store, *buffer);
	CleanupStack::PopAndDestroy(buffer);
	store->CommitL();
	obj->RestoreL(*store);
	obj->GetBodyTextL(gFs, *store, *richText);
	test(richText->HasChanged());
	
	// Clean up and release resources...
	CleanupStack::PopAndDestroy(charSets);
	CleanupStack::PopAndDestroy(converter);
	CleanupStack::PopAndDestroy(richText);
	CleanupStack::PopAndDestroy(charLayer);
	CleanupStack::PopAndDestroy(paraLayer);
	CleanupStack::PopAndDestroy(obj);
	CleanupStack::PopAndDestroy(store);
	__UHEAP_MARKEND;
		
	return ETrue;
	}
LOCAL_C TBool TestStoreL()
	{
	__UHEAP_MARK;
	// Retrieve the store from the current context... 
	CMsvStore* store = pContext->EditStoreL();
	CleanupStack::PushL(store);
	CMsvBodyText* obj = CMsvBodyText::NewLC();
	obj->SetCharacterSet(KCharSetUid);
	obj->SetDefaultCharacterSet(KDefCharSetUid);
	// Add 10 bytes of data...
	CBufFlat *buffer=CBufFlat::NewL(K10BytesData().Size());
	CleanupStack::PushL(buffer);
	buffer->InsertL(0,K10BytesData);
	obj->StoreL(*store, *buffer);
	CleanupStack::PopAndDestroy(buffer);
	store->CommitL();
	CleanupStack::PopAndDestroy(obj);
	obj = CMsvBodyText::NewLC();
	obj->SetCharacterSet(0);
	obj->SetDefaultCharacterSet(0);
	obj->RestoreL(*store);
	test(obj->CharacterSet() == KCharSetUid);
	test(obj->DefaultCharacterSet() == KDefCharSetUid);
	CleanupStack::PopAndDestroy(obj);
	CleanupStack::PopAndDestroy(store);
	__UHEAP_MARKEND;

	__UHEAP_MARK;
	// Retrieve the store from the current context... 
	store = pContext->EditStoreL();
	CleanupStack::PushL(store);
	obj = CMsvBodyText::NewLC();
	obj->SetCharacterSet(KCharSetUid);
	obj->SetDefaultCharacterSet(KDefCharSetUid);
	// Add no data - just store character sets...
	obj->StoreL(*store);
	store->CommitL();
	CleanupStack::PopAndDestroy(obj);
	obj = CMsvBodyText::NewLC();
	obj->SetCharacterSet(0);
	obj->SetDefaultCharacterSet(0);
	obj->RestoreL(*store);
	test(obj->CharacterSet() == KCharSetUid);
	test(obj->DefaultCharacterSet() == KDefCharSetUid);
	CleanupStack::PopAndDestroy(obj);
	CleanupStack::PopAndDestroy(store);
	__UHEAP_MARKEND;

	__UHEAP_MARK;
	// Retrieve the store from the current context in read-only mode... 
	store = pContext->ReadStoreL();
	CleanupStack::PushL(store);
	obj = CMsvBodyText::NewLC();
	obj->SetCharacterSet(KCharSetUid);
	obj->SetDefaultCharacterSet(KDefCharSetUid);
	// Add 10 bytes of data...

	CBufFlat *buffer2=CBufFlat::NewL(K10BytesData().Size());
	CleanupStack::PushL(buffer2);
	buffer2->InsertL(0,K10BytesData);
	TRAPD(err, obj->StoreL(*store, *buffer2));
	test(err == KErrAccessDenied);
	CleanupStack::PopAndDestroy(buffer2);
	CleanupStack::PopAndDestroy(obj);
	CleanupStack::PopAndDestroy(store);
	__UHEAP_MARKEND;

	return ETrue;
	}