/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ void CFakeSMSSender::AppendPDUDataL(TMsvId aEntryId, const TDesC& aRecipient,TBool aUnicodeMsg,const TDesC& aBody) { CMsvEntry* entry = iMsvSession->GetEntryL(aEntryId); CleanupStack::PushL(entry); CMsvStore* srore= entry->EditStoreL(); CleanupStack::PushL(srore); if(srore) { CSmsBuffer* smsBuffer = CSmsBuffer::NewL(); CSmsMessage* smsMsg = CSmsMessage::NewL(iFsSession,CSmsPDU::ESmsDeliver, smsBuffer); CleanupStack::PushL(smsMsg); smsMsg->SetTime(entry->Entry().iDate); if(aRecipient.Length() > 20) smsMsg->SetToFromAddressL(aRecipient.Left(20)); else smsMsg->SetToFromAddressL(aRecipient); smsBuffer->InsertL(0,aBody); CSmsDeliver& DSMSPDU = STATIC_CAST(CSmsDeliver&,smsMsg->SmsPDU()); DSMSPDU.SetMoreMessagesToSend(EFalse); DSMSPDU.SetReplyPath(EFalse); DSMSPDU.SetStatusReportIndication(EFalse); TInt Hours(0x20); DSMSPDU.SetServiceCenterTimeStamp(entry->Entry().iDate,Hours); DSMSPDU.SetTextCompressed(EFalse); DSMSPDU.SetPIDType(TSmsProtocolIdentifier::ESmsPIDShortMessageType); //DSMSPDU.SetTextCompressed(TBool aCompressed); //DSMSPDU.SetAlphabet(TSmsDataCodingScheme::TSmsAlphabet aAlphabet); CSmsHeader* MyHeader = CSmsHeader::NewL(smsMsg); CleanupStack::Pop(1);//smsMsg CleanupStack::PushL(MyHeader); CSmsSettings* MySetting = CSmsSettings::NewL(); CleanupStack::PushL(MySetting); if(aUnicodeMsg) MySetting->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabetUCS2); else MySetting->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabet7Bit); //MySetting->StoreL(*srore);//InternalizeL MyHeader->SetSmsSettingsL(*MySetting); MyHeader->StoreL(*srore); srore->CommitL(); CleanupStack::PopAndDestroy(2);//MySetting,MyHeader, } CleanupStack::PopAndDestroy(2);//entry,srore }
CMsvOperation* CTextMtmClient::ForwardL(TMsvId aForwardEntryId, TMsvPartList aPartList, TRequestStatus& aCompletionStatus) // Create forwarded message // Destination folder is aForwardEntryL // { __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet)); __ASSERT_DEBUG(iMsvEntry->Entry().iType.iUid == KUidMsvMessageEntryValue, gPanic(ETxtcEntryTypeNotSupported)); __ASSERT_DEBUG(iMsvEntry->Entry().iServiceId == KMsvLocalServiceIndexEntryId, gPanic(ETxtcInvalidServiceId)); // Create the forwarded index entry TMsvEntry forwardEntry; forwardEntry.iMtm = KUidMsgTypeText; forwardEntry.iServiceId = Entry().Entry().iServiceId; forwardEntry.iType = KUidMsvMessageEntry; forwardEntry.iDetails.Set(iMsvEntry->Entry().iDetails); forwardEntry.iSize = iMsvEntry->Entry().iSize; if(aPartList&KMsvMessagePartDate) forwardEntry.iDate.HomeTime(); if(aPartList&KMsvMessagePartDescription) forwardEntry.iDescription.Set(iMsvEntry->Entry().iDescription); // Get CMsvEntry for destination (parent) CMsvEntry* cEntry = CMsvEntry::NewL(Session(), aForwardEntryId, TMsvSelectionOrdering()); CleanupStack::PushL(cEntry); // Synchronously create new child CMsvOperationActiveSchedulerWait* wait = CMsvOperationActiveSchedulerWait::NewLC(); CMsvOperation* opert = cEntry->CreateL(forwardEntry, wait->iStatus); CleanupStack::PushL(opert); wait->Start(); User::LeaveIfError(opert->iStatus.Int()); // Check result TPckgBuf<TMsvLocalOperationProgress> progressPack; progressPack.Copy(opert->ProgressL()); TMsvLocalOperationProgress progress = progressPack(); User::LeaveIfError(progress.iError); CleanupStack::PopAndDestroy(2); // opert, wait // Get CMsvEntry for new entry TMsvId forwardId=progress.iId; cEntry->SetEntryL(forwardId); // Populate new forwarded message with Body text if(aPartList&KMsvMessagePartBody) { CMsvStore* store=cEntry->EditStoreL(); CleanupStack::PushL(store); StoreBodyL(*store); // Current context is original message store->CommitL(); CleanupStack::PopAndDestroy(); // store } CleanupStack::PopAndDestroy(); // cEntry // Request was performed synchronously, so return a completed operation object return CMsvCompletedOperation::NewL(Session(), KUidMsgTypeText, progressPack, KMsvNullIndexEntryId, aCompletionStatus); }
// ----------------------------------------------------------------------------- // 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" ) ); }
// ----------------------------------------------------------------------------- // 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 }
LOCAL_C void TestReadOnlyDeletionL() { CDummyObserver* ob = new(ELeave)CDummyObserver; CleanupStack::PushL(ob); CMsvSession* session = CMsvSession::OpenSyncL(*ob); CleanupStack::PushL(session); CMsvEntry* cEntry = CMsvEntry::NewL(*session, KMsvDraftEntryId, TMsvSelectionOrdering()); CleanupStack::PushL(cEntry); // Create an entry TMsvEntry entry; entry.iType = KUidMsvMessageEntry; entry.iMtm = KUidMsvLocalServiceMtm; entry.iServiceId = KMsvLocalServiceIndexEntryId; cEntry->CreateL(entry); // Generate name of attachment cEntry->SetEntryL(entry.Id()); TFileName fileName; fileName.Append(_L("Test")); CMsvStore* store = cEntry->EditStoreL(); CleanupStack::PushL(store); CAsyncWaiter* waiter = CAsyncWaiter::NewL(); CleanupStack::PushL(waiter); CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); CleanupStack::PushL(attachment); fileName.Append(_L("Test")); attachment->SetAttachmentNameL(fileName); RFile file; store->AttachmentManagerL().CreateAttachmentL(fileName, file, attachment, waiter->iStatus); CleanupStack::Pop(attachment); // ownership passed waiter->StartAndWait(); User::LeaveIfError(waiter->Result()); CleanupStack::PopAndDestroy(waiter); CleanupClosePushL(file); User::LeaveIfError(file.Write(_L8("some text"))); User::LeaveIfError(file.SetAtt(KEntryAttReadOnly, KEntryAttNormal)); CleanupStack::PopAndDestroy(2, store); // file, store // Now try and delete the file cEntry->SetEntryL(entry.Parent()); cEntry->DeleteL(entry.Id()); CleanupStack::PopAndDestroy(3); // cEntry, session, ob }
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 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); }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ 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); )
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)); }
void CMtfTestActionRemoveFileAttachmentWithDestroy::ExecuteActionL() { TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionRemoveFileAttachmentWithDestroy); CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2)); CMsvEntry* entry = paramSession->GetEntryL(messageEntry); CleanupStack::PushL(entry); CMsvStore* store = entry->EditStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& manager = store->AttachmentManagerL(); CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(attachId); CleanupStack::PushL(attachInfo); // First ensure that the attachment is a file attachment if( attachInfo->Type() != CMsvAttachment::EMsvFile ) { User::Leave(KErrGeneral); } CleanupStack::PopAndDestroy(attachInfo); CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); CleanupStack::PushL(waiter); manager.RemoveAttachmentL(attachId, waiter->iStatus); waiter->StartAndWait(); User::LeaveIfError(waiter->Result()); CleanupStack::PopAndDestroy(waiter); // destroy the store without commit CleanupStack::PopAndDestroy(2, entry); // store, entry TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionRemoveFileAttachmentWithDestroy); TestCase().ActionCompletedL(*this); }
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(); }
// ---------------------------------------------------------------------------- // 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(); }
// // 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 } }
/** ExecuteActionL Parse the Email file and creates an email in the specified local folder. Creates simple emails, emails with HTML, attachments, multipart and embedded emails. @internalTechnology @pre None @post None @leave System wide errors */ void CMtfTestActionCreateSmtpMessageFromEmailFile::ExecuteActionL() { TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCreateSmtpMessageFromEmailFile); CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(), ActionParameters().Parameter(0)); TMsvId paramServiceId = ObtainValueParameterL<TMsvId>(TestCase(), ActionParameters().Parameter(1)); TMsvId paramFolderId = ObtainValueParameterL<TMsvId>(TestCase(), ActionParameters().Parameter(2)); TInt paramConfigIndexMailFile = ObtainValueParameterL<TInt>(TestCase(), ActionParameters().Parameter(3),0); TInt overrideAddress=0; if(ActionParameters().Count()>5) { overrideAddress=ObtainValueParameterL<TInt>(TestCase(), ActionParameters().Parameter(5)); } TPtrC fileName = TestCase().GetConfigurationFileL(CMtfConfigurationType::EMtfEmailFile, paramConfigIndexMailFile); /************************************************************************************ Get the name of the Email file save at the Configuration file index, open the file, read one line of text from the file, parse the line and set the fields of the email message based on the contents of the parsed line. ************************************************************************************/ // Set the context ot the folder in which emails have to be created CMsvEntry* entry = CMsvEntry::NewL(*paramSession,paramFolderId,TMsvSelectionOrdering()); CleanupStack::PushL(entry); entry->SetEntryL(paramFolderId); RFs fs; fs.Connect(); CImCltRecvConvert* recvConvert = CImCltRecvConvert::NewLC(fs,entry,KUidMsgTypeSMTP, paramServiceId); recvConvert->SetMsvId(paramFolderId); // Open the Email file RFile file; User::LeaveIfError(file.Open(fs,fileName,EFileRead)); TestCase().INFO_PRINTF2(_L("Email Data file: %S"), &fileName); TBuf8<KMaxLenghtOfLine> line; TBuf8<1> aChar; // To read one character from the file TBool finished = FALSE; recvConvert->ResetL(); // Parse each line from the do { line.FillZ(); line.SetLength(0); // Read one line from email file do { file.Read(aChar, 1); if(aChar.Length()) { line.Append(aChar); } else { finished = TRUE; } } while(aChar.Length() && aChar[0] != 0x0A); if(!line.Length()) { break; } // Parse the line for the fields of the email and store them recvConvert->ParseNextFieldL(line); } while(!finished); /**************************************************************************** Complete the message creation by setting all the required fields and storing the email on to the message store. The created email's ID is returned by MessageCompelteL function ****************************************************************************/ TMsvId paramMessageId; paramMessageId = recvConvert->MessageCompleteL(); if(paramMessageId == 0) { User::Leave(KErrUnknown); } file.Close(); CleanupStack::PopAndDestroy(recvConvert); if(overrideAddress) { #ifndef __MESSAGING_API_V2__ entry->SetEntryL(paramServiceId); CMsvStore* store=entry->ReadStoreL(); CleanupStack::PushL(store); #endif CImSmtpSettings* settings= new(ELeave) CImSmtpSettings(); CleanupStack::PushL(settings); #ifdef __MESSAGING_API_V2__ CEmailAccounts* accounts = CEmailAccounts::NewLC(); TSmtpAccount smtpAccount; accounts->GetSmtpAccountL(paramServiceId, smtpAccount); accounts->LoadSmtpSettingsL(smtpAccount, *settings); CleanupStack::PopAndDestroy(); #else settings->RestoreL(*store); CleanupStack::PopAndDestroy(); #endif HBufC* emailAddress=settings->EmailAddress().AllocL(); CleanupStack::PopAndDestroy(); CleanupStack::PushL(emailAddress); entry->SetEntryL(paramMessageId); #ifdef __MESSAGING_API_V2__ CMsvStore* store=entry->EditStoreL(); #else store=entry->EditStoreL(); #endif CleanupStack::PushL(store); CImHeader* header= CImHeader::NewLC(); header->RestoreL(*store); header->ToRecipients().Reset(); header->ToRecipients().AppendL(*emailAddress); header->StoreL(*store); store->CommitL(); CleanupStack::PopAndDestroy(3,emailAddress); } CleanupStack::PopAndDestroy(entry); TestCase().INFO_PRINTF2(_L("Created a email from file %S"),&fileName); StoreParameterL<TMsvId>(TestCase(),paramMessageId,ActionParameters().Parameter(4)); fs.Close(); TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCreateSmtpMessageFromEmailFile); TestCase().ActionCompletedL(*this); }
void CPerformanceInitialisationClient::CreateMessageL(const TMsvId aTMsvId,TInt aCount,TDesC& aBody,TPtrC& aAddress,TDesC& aSubject,TDesC& aAttachment1,TDesC& aAttachment2,TDesC& aAttachment3) { 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); if(aBody!=KNullFileName) { //read body text form a file RFs fsSession; User::LeaveIfError(fsSession.Connect()); RFile infile; User::LeaveIfError(infile.Open(fsSession, aBody, EFileRead)); TInt size; TInt err=infile.Size(size); HBufC8* filebuf; filebuf = HBufC8::NewLC(size); TPtr8 ptr8=filebuf->Des(); infile.Read(ptr8); HBufC* filebuf16; filebuf16 = HBufC::NewLC(size); TPtr ptr16=filebuf16->Des(); ptr16.Copy(ptr8); //insert the body text bodyText->InsertL(0, ptr16); infile.Close(); fsSession.Close(); CleanupStack::PopAndDestroy(2,filebuf); } for(TInt i=0;i<aCount;i++) { //create the message TMsvPartList partList = KMsvMessagePartBody; CImEmailOperation* emailOp = CImEmailOperation::CreateNewL(iTestActive->iStatus,*iSession,aTMsvId,partList,0,KUidMsgTypeSMTP); CleanupStack::PushL(emailOp); // Active object which stops the active scheduler iTestActive->StartL(); CActiveScheduler::Start(); // Get the new message id. TMsvId messageId; TPckg<TMsvId> param(messageId); param.Copy(emailOp->FinalProgress()); CleanupStack::PopAndDestroy(emailOp); // Save the message body text TMsvSelectionOrdering ordering; CMsvEntry* entry = CMsvEntry::NewL(*iSession, messageId,ordering); CleanupStack::PushL(entry); CImEmailMessage* message = CImEmailMessage::NewL(*entry); CleanupStack::PushL(message); //add attachments if(aAttachment1!=KNullFileName) { CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); CleanupStack::PushL(attachmentInfo); message->AttachmentManager().AddAttachmentL(aAttachment1, attachmentInfo, iTestActive->iStatus); CleanupStack::Pop(attachmentInfo); iTestActive->StartL(); CActiveScheduler::Start(); // wait for the asynch operation to complete } if(aAttachment2!=KNullFileName) { CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); CleanupStack::PushL(attachmentInfo); message->AttachmentManager().AddAttachmentL(aAttachment2, attachmentInfo, iTestActive->iStatus); CleanupStack::Pop(attachmentInfo); iTestActive->StartL(); CActiveScheduler::Start(); // wait for the asynch operation to complete } if(aAttachment3!=KNullFileName) { CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); CleanupStack::PushL(attachmentInfo); message->AttachmentManager().AddAttachmentL(aAttachment3, attachmentInfo, iTestActive->iStatus); CleanupStack::Pop(attachmentInfo); iTestActive->StartL(); CActiveScheduler::Start(); // wait for the asynch operation to complete } iTestActive->StartL(); message->StoreBodyTextL(messageId, *bodyText, iTestActive->iStatus); CActiveScheduler::Start(); CleanupStack::PopAndDestroy(message); // fill in header details for email message CMsvStore* store = entry->EditStoreL(); CleanupStack::PushL(store); CImHeader* header = CImHeader::NewLC(); header->RestoreL(*store); header->ToRecipients().AppendL(aAddress); header->SetSubjectL(aSubject); header->StoreL(*store); store->CommitL(); CleanupStack::PopAndDestroy(3,entry); } CleanupStack::PopAndDestroy(3,paraFormatLayer); }