void CMtfTestActionCompareAttachment::ExecuteActionL() { TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCompareAttachment); CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2)); HBufC* dataFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(3)); CMsvEntry* entry = paramSession->GetEntryL(messageEntry); CleanupStack::PushL(entry); CMsvStore* store = entry->ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& manager = store->AttachmentManagerL(); RFile fileAttachment = manager.GetAttachmentFileL(attachId); CleanupClosePushL(fileAttachment); CompareFileL(fileAttachment, *dataFilePath); CleanupStack::PopAndDestroy(&fileAttachment); CleanupStack::PopAndDestroy(2, entry); // store, entry TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCompareAttachment); TestCase().ActionCompletedL(*this); }
// --------------------------------------------------------- // 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 ); }
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)); }
void CMtfTestActionGetAttachmentFileFromIndex::RunTestActionL() { CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); TInt attachIndex = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(2)); HBufC* dataFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(3), NULL); CMsvEntry* entry = paramSession->GetEntryL(messageEntry); CleanupStack::PushL(entry); CMsvStore* store = entry->ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& manager = store->AttachmentManagerL(); RFile fileAttachment = manager.GetAttachmentFileL(attachIndex); CleanupClosePushL(fileAttachment); if( dataFilePath != NULL ) { // check of contents of attachment file is requested CompareFileL(fileAttachment, *dataFilePath); } CleanupStack::PopAndDestroy(3, entry); // fileAttachment, store, entry }
// --------------------------------------------------------- // CUniSmilList::CreateSmilAttachmentL // // Create SMIL from DOM // --------------------------------------------------------- // EXPORT_C void CUniSmilList::CreateSmilAttachmentL( MUniSmilComposeObserver& aObserver, CMsvStore& aEditStore, CMDXMLDocument* aDom ) { iDom = aDom; iObserver = &aObserver; //iSmilAttaId = KMsvNullIndexEntryId; //iSmilAttaFullpath.Zero(); iManager = &( aEditStore.AttachmentManagerL() ); CMsvAttachment* attachment = CMsvAttachment::NewL( CMsvAttachment::EMsvFile ); CleanupStack::PushL( attachment ); //TODO: Set size(?) & complete flag(?) //attachment->SetSize() //attachment->SetComplete( EFalse ); iEditFile = new ( ELeave ) RFile; CMuiuOperationWait* wait = CMuiuOperationWait::NewLC(); iManager->CreateAttachmentL( KPresentationFileName, *iEditFile, attachment, wait->iStatus ); wait->Start(); //manager.AddAttachmentL( aPath, attachment, iStatus ); CleanupStack::PopAndDestroy( wait ); CleanupStack::Pop( attachment ); iAttachment = attachment; //Do self complete to trigger runL RunL(); }
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); }
void CheckNoAttachmentsL() { CDummyObserver* ob1 = new(ELeave) CDummyObserver; CleanupStack::PushL(ob1); CMsvSession* session = CMsvSession::OpenSyncL(*ob1); CleanupStack::PushL(session); CMsvEntry* cEntry = CMsvEntry::NewL(*session, KMsvDraftEntryId, TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue)); CleanupStack::PushL(cEntry); CMsvEntrySelection* selection = cEntry->ChildrenL(); CleanupStack::PushL(selection); test(selection->Count() == 1); cEntry->SetEntryL((*selection)[0]); if (cEntry->HasStoreL()) { CMsvStore* store = cEntry->ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL(); test(attachmentMgr.AttachmentCount() == 0); CleanupStack::PopAndDestroy(store); } CleanupStack::PopAndDestroy(4, ob1); // selection, cEntry, session, ob1 }
// --------------------------------------------------------- // // --------------------------------------------------------- void CMmsAttachmentHandler::RemoveAttachmentL( TMsvAttachmentId aAttaId, CMsvStore& aStore ) { MMsvAttachmentManager& attaMan = aStore.AttachmentManagerL(); MMsvAttachmentManagerSync& attaManSync = aStore.AttachmentManagerExtensionsL(); // can only remove synchronously if index is known. TInt count = attaMan.AttachmentCount(); TInt i = count - 1; TBool found = EFalse; while ( i >= 0 && !found ) { CMsvAttachment* attachmentInfo = attaMan.GetAttachmentInfoL( i ); CleanupStack::PushL( attachmentInfo ); if ( attachmentInfo->Id() == aAttaId ) { found = ETrue; } else { i--; } CleanupStack::PopAndDestroy( attachmentInfo ); attachmentInfo = NULL; } if ( i >= 0 && found ) { attaManSync.RemoveAttachmentL( i ); } }
//--------------------------------------------------------------- // CNativeMmsUtility::ConstructL // @see header //--------------------------------------------------------------- void CNativeMmsUtility::ConstructL(const TMsvId& msgId, CMsvSession& session) { #ifdef _DEBUG_TRACES_ qDebug() << " Enter CNativeMmsUtility::ConstructL"; #endif //Get message entry imsventry = CMsvEntry::NewL(session, msgId, TMsvSelectionOrdering()); CleanupStack::PushL(imsventry); //Read message store CMsvStore* store = imsventry->ReadStoreL(); CleanupStack::PushL(store); //Get message store's attachment manager iattachmanager = &store->AttachmentManagerL(); //get the smil file from attachment manager ismilfilepath = getSmilFileL(); if (!ismilfilepath.isEmpty()) { //get smilfile's handle to parse RFile smilfile; HBufC* path = XQConversions::qStringToS60Desc(ismilfilepath); RFs fsSession; User::LeaveIfError(fsSession.Connect()); if (KErrNone == smilfile.Open(fsSession, *path, EFileRead)) { CleanupClosePushL(smilfile); //create an instance of smil reader ireader = SmilXmlReader::NewL(smilfile); //close smilfile CleanupStack::PopAndDestroy(); } else { //reset the smilfilepath ismilfilepath.clear(); } smilfile.Close(); //close file server session fsSession.Close(); } CleanupStack::Pop(2, imsventry); #ifdef _DEBUG_TRACES_ qDebug() << " Exit CNativeMmsUtility::ConstructL"; #endif }
/* ----------------------------------------------------------------------------- RFile GetAttachmentFileL(TMsvAttachmentId aId) ---------------------------------------------------------------------------- */ void CMailBoxContainer::OpenFileL(TBool /*aOpenWith*/) { if(iSession && iSelectionBox) { TInt CurrItmIndex = iSelectionBox->CurrentItemIndex(); TMsvSelectionOrdering sort; sort.SetShowInvisibleEntries(ETrue); sort.SetSorting(EMsvSortByDate); // Take a handle to the folder entry CMsvEntry* parentEntry = CMsvEntry::NewL(*iSession,iCurrentMailBox,sort); CleanupStack::PushL(parentEntry); // A selection of all BT entries CMsvEntrySelection* entries = parentEntry->ChildrenL();//ChildrenWithMtmL(KUidMsgTypeBt); CleanupStack::PushL(entries); //Process all entries if(CurrItmIndex >= 0 && CurrItmIndex < iIDArray->Count()) { //Get entry CMsvEntry* btEntry = iSession->GetEntryL(iIDArray->At(CurrItmIndex).iEnt); CleanupStack::PushL(btEntry); //Then get entrys child CMsvEntrySelection* btChildren = btEntry->ChildrenL(); CleanupStack::PushL(btChildren); btEntry->SetEntryL(iIDArray->At(CurrItmIndex).iMsg); if (btEntry->HasStoreL()) { CMsvStore* store = btEntry->ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& attMngr = store->AttachmentManagerL(); CMsvAttachment* attachment = attMngr.GetAttachmentInfoL(iIDArray->At(CurrItmIndex).iAtt); if(attachment) { RFile SourceFil(attMngr.GetAttachmentFileL(iIDArray->At(CurrItmIndex).iAtt)); iUtils.GetFileUtils().OpenFileWithHandler(SourceFil); SourceFil.Close(); } CleanupStack::PopAndDestroy(store); } CleanupStack::PopAndDestroy(2); } CleanupStack::PopAndDestroy(2); } }
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 }
// --------------------------------------------------------- // CUniSmilList::GetSmilFullPathByIndex // // GetSmilFullPathByIndex. // --------------------------------------------------------- // EXPORT_C RFile CUniSmilList::GetSmilFileByIndexL( TInt aIndex ) { if ( aIndex < 0 || aIndex >= iSmilAttachmentArray->Count() ) { User::Leave( KErrArgument ); } CMsvStore* store = iMtm.Entry().ReadStoreL(); CleanupStack::PushL( store ); MMsvAttachmentManager& manager = store->AttachmentManagerL(); RFile file = manager.GetAttachmentFileL( iSmilAttachmentArray->At( aIndex ) ); CleanupStack::PopAndDestroy( store ); return file; }
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); }
/** 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 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); }
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)); }
/** CountLinesOfHtmlL() Counts the number of lines of HTML @param aEntry A reference to an object representing the email @return Number of lines of HTML */ TInt CT_MsgComparePopEmailMsgs::CountLinesOfHtmlL(CMsvEntry& aEntry) { TInt lines = 0; aEntry.SetEntryL(aEntry.EntryId()); CMsvStore* store = aEntry.ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& attManager = store->AttachmentManagerL(); RFile htmlFile = attManager.GetAttachmentFileL(0); CleanupClosePushL(htmlFile); _LIT8(KFindData, "\r\n"); TInt htmlSize = 0; User::LeaveIfError(htmlFile.Size(htmlSize)); HBufC8* fBuf = HBufC8::NewLC(htmlSize); TPtr8 p = fBuf->Des(); htmlFile.Read(p); TInt pos = 0; for(;;) { pos = p.Find(KFindData); if(pos < 0) { break; } p = p.Mid(pos+2); lines++; } CleanupStack::PopAndDestroy(fBuf); CleanupStack::PopAndDestroy(); // htmlFile CleanupStack::PopAndDestroy(store); return lines; }
// --------------------------------------------------------- // CMmsAttachmentHandler::AttachmentsSizeL // --------------------------------------------------------- // EXPORT_C TInt CMmsAttachmentHandler::AttachmentsSizeL( CMsvStore& aStore ) { // Caller controls store TInt size = 0; MMsvAttachmentManager& attachMan = aStore.AttachmentManagerL(); TInt numAttachments = attachMan.AttachmentCount(); TInt i; for ( i = 0; i < numAttachments; i++ ) { CMsvAttachment* attachmentInfo = attachMan.GetAttachmentInfoL(i); CleanupStack::PushL( attachmentInfo ); CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL(); CleanupStack::PushL( mimeHeaders ); mimeHeaders->RestoreL( *attachmentInfo ); RFile attaFile = attachMan.GetAttachmentFileL( i ); CleanupClosePushL( attaFile ); TInt fileSize = 0; // If we cannot access the file, we are in trouble User::LeaveIfError( attaFile.Size( fileSize ) ); // This adds up mime header size + actual attachment binary data size += mimeHeaders->Size() + fileSize; CleanupStack::PopAndDestroy( &attaFile ); // close attaFile CleanupStack::PopAndDestroy( mimeHeaders ); CleanupStack::PopAndDestroy( attachmentInfo ); } return size; }
/* ----------------------------------------------------------------------------- ---------------------------------------------------------------------------- */ void CMailBoxContainer::ReadMailFolderL(TMsvId aSelected) { iCurrentMailBox = aSelected; delete iIDArray; iIDArray = NULL; if(iSession && iSelectionBox) { TInt OrgCount = iSelectionBox->Model()->ItemTextArray()->MdcaCount(); STATIC_CAST(CDesCArray*,iSelectionBox->Model()->ItemTextArray())->Reset(); RPointerArray<CFFileTypeItem> ItemTypeArray = iUtils.GetFileUtils().GetItemTypeArray(); iIDArray = new(ELeave)CArrayFixFlat<TMyMailEntry>(10); TMsvSelectionOrdering sort; sort.SetShowInvisibleEntries(ETrue); sort.SetSorting(EMsvSortByDate); // Take a handle to the folder entry CMsvEntry* parentEntry = CMsvEntry::NewL(*iSession,aSelected,sort); CleanupStack::PushL(parentEntry); // A selection of all BT entries CMsvEntrySelection* entries = parentEntry->ChildrenL();//ChildrenWithMtmL(KUidMsgTypeBt); CleanupStack::PushL(entries); //Process all entries for(TInt ii = 0; ii < entries->Count(); ii++) { //Get entry CMsvEntry* btEntry = iSession->GetEntryL((*entries)[ii]); CleanupStack::PushL(btEntry); //Then get entrys child CMsvEntrySelection* btChildren = btEntry->ChildrenL(); CleanupStack::PushL(btChildren); TInt childc = btChildren->Count(); if (childc>0) { for(TInt i=0; i<childc; i++) { TMsvId btAtt = (*btChildren)[i]; btEntry->SetEntryL(btAtt); if(btEntry->Entry().iMtm == KUidMsgTypePOP3) { CImEmailMessage* emailMessage = CImEmailMessage::NewL(*btEntry); CleanupStack::PushL(emailMessage); MMsvAttachmentManager& attMngr = emailMessage->AttachmentManager(); GetAttachmentsL(attMngr,*btEntry,(*entries)[ii],btAtt); CleanupStack::PopAndDestroy(emailMessage); } else if (btEntry->HasStoreL()) { CMsvStore* store = btEntry->ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& attMngr = store->AttachmentManagerL(); GetAttachmentsL(attMngr,*btEntry,(*entries)[ii],btAtt); CleanupStack::PopAndDestroy(store); } } } CleanupStack::PopAndDestroy(2); } CleanupStack::PopAndDestroy(2); CDesCArray* itemArray = STATIC_CAST( CDesCArray* ,iSelectionBox->Model()->ItemTextArray()); if(itemArray->Count() > OrgCount) { iSelectionBox->HandleItemAdditionL(); iSelectionBox->SetCurrentItemIndex(0); } else { iSelectionBox->HandleItemRemovalL(); if(itemArray->Count()) { iSelectionBox->SetCurrentItemIndex(0); } } UpdateScrollBar(iSelectionBox); DrawNow(); }
/* ----------------------------------------------------------------------------- RFile GetAttachmentFileL(TMsvAttachmentId aId) ---------------------------------------------------------------------------- */ void CMailBoxContainer::CopyFileL(const TDesC& aFolderName) { TFileName fileName,FullFilName; if(iSession && iSelectionBox && iListArray) { TInt CurrItmIndex = iSelCopyItemIndex; iSelCopyItemIndex = -1; if(CurrItmIndex < 0 || CurrItmIndex >= iIDArray->Count()) { CurrItmIndex = iSelectionBox->CurrentItemIndex(); } TMsvSelectionOrdering sort; sort.SetShowInvisibleEntries(ETrue); sort.SetSorting(EMsvSortByDate); // Take a handle to the folder entry CMsvEntry* parentEntry = CMsvEntry::NewL(*iSession,iCurrentMailBox,sort); CleanupStack::PushL(parentEntry); // A selection of all BT entries CMsvEntrySelection* entries = parentEntry->ChildrenL();//ChildrenWithMtmL(KUidMsgTypeBt); CleanupStack::PushL(entries); //Process all entries if(CurrItmIndex >= 0 && CurrItmIndex < iIDArray->Count()) { //Get entry CMsvEntry* btEntry = iSession->GetEntryL(iIDArray->At(CurrItmIndex).iEnt); CleanupStack::PushL(btEntry); //Then get entrys child CMsvEntrySelection* btChildren = btEntry->ChildrenL(); CleanupStack::PushL(btChildren); btEntry->SetEntryL(iIDArray->At(CurrItmIndex).iMsg); if (btEntry->HasStoreL()) { CMsvStore* store = btEntry->ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& attMngr = store->AttachmentManagerL(); CMsvAttachment* attachment = attMngr.GetAttachmentInfoL(iIDArray->At(CurrItmIndex).iAtt); if(attachment) { fileName.Copy(attachment->AttachmentName()); delete attachment; attachment = NULL; TBool OkToSave(EFalse),SkipMe(EFalse); do { FullFilName.Zero(); StringLoader::Load(FullFilName,R_SH_STR_FILENAME); CAknTextQueryDialog* Dialog = CAknTextQueryDialog::NewL(fileName,CAknQueryDialog::ENoTone); Dialog->PrepareLC(R_ASK_NAME_DIALOG); Dialog->SetPromptL(FullFilName); if(Dialog->RunLD()) { FullFilName.Copy(aFolderName); FullFilName.Append(fileName); if(BaflUtils::FileExists(CEikonEnv::Static()->FsSession(),FullFilName)) { HBufC* TmpText = StringLoader::LoadLC(R_SH_STR_FILOVERRT); CAknQueryDialog* dlg = CAknQueryDialog::NewL(); if(dlg->ExecuteLD(R_QUERY,*TmpText)) { TInt Err = CEikonEnv::Static()->FsSession().Delete(FullFilName); if(Err == KErrNone) { OkToSave = ETrue; } else { iUtils.GetFileUtils().ShowFileErrorNoteL(FullFilName,Err); } } CleanupStack::PopAndDestroy(TmpText); } else { OkToSave = ETrue; } } else { SkipMe = ETrue; } }while(!SkipMe && !OkToSave); if(OkToSave) { delete iRFileCopier; iRFileCopier = NULL; iRFileCopier = CRFileCopier::NewL(*this,CEikonEnv::Static()->FsSession(),ETrue); RFile SourceFil(attMngr.GetAttachmentFileL(iIDArray->At(CurrItmIndex).iAtt)); iRFileCopier->StartCopyL(SourceFil,FullFilName); SourceFil.Close(); } } CleanupStack::PopAndDestroy(store); } CleanupStack::PopAndDestroy(2); } CleanupStack::PopAndDestroy(2); } }
void CBtMsgViewerUtils::GetMessagePathL(TPtr aMsgPath, const TInt aMessageId ) { CMsvEntry* messageEntry = iMsvSession->GetEntryL(aMessageId); CleanupStack::PushL(messageEntry); TMsvEntry entry = messageEntry->Entry(); if(entry.MtmData1() == KUidMsgTypeBtTInt32) { CMsvStore* store = messageEntry->ReadStoreL(); CleanupStack::PushL(store); TInt attachmentCount = store->AttachmentManagerL().AttachmentCount(); RFile attachmentFile; if(attachmentCount != 0) { //get file handle for the attachment & the complete path of the file attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0); CleanupClosePushL(attachmentFile); User::LeaveIfError(attachmentFile.FullName(aMsgPath)); CleanupStack::PopAndDestroy(&attachmentFile); StoreMessageMimeTypeL(aMsgPath); //mark attachment as Read TMsvEntry attachEntry = messageEntry->Entry(); attachEntry.SetUnread(EFalse); messageEntry->ChangeL(attachEntry); } else { CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL(*iMsvSession); CleanupStack::PushL(mtmReg); //1st Push CBIOClientMtm* bioClientMtm = (CBIOClientMtm*) mtmReg->NewMtmL(KBioUidValueUid); CleanupStack::PushL(bioClientMtm); //2nd Push bioClientMtm->SwitchCurrentEntryL(aMessageId); CMsvEntry* attachmentEntry = CMsvEntry::NewL(bioClientMtm->Session(), aMessageId, TMsvSelectionOrdering()); CleanupStack::PushL(attachmentEntry); //3rd Push bioClientMtm->LoadMessageL(); CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection; CleanupStack::PushL(selection); //4th Push selection->AppendL(aMessageId); TBuf8<1> aParameter; CMsvOperationActiveSchedulerWait* wait = CMsvOperationActiveSchedulerWait::NewLC(); //5th Push CMsvOperation* operation = bioClientMtm->InvokeAsyncFunctionL(KBiosMtmParse, *selection, aParameter, wait->iStatus); wait->Start(); CMsvStore* store = attachmentEntry->ReadStoreL(); CleanupStack::PushL(store); //6th Push MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); attachmentFile = attachMan.GetAttachmentFileL(0); CleanupClosePushL(attachmentFile); //7th Push User::LeaveIfError(attachmentFile.FullName(aMsgPath)); CleanupStack::PopAndDestroy(&attachmentFile); StoreMessageMimeTypeL(aMsgPath); //mark attachment as Read TMsvEntry attachEntry = attachmentEntry->Entry(); attachEntry.SetUnread(EFalse); attachmentEntry->ChangeL(attachEntry); delete operation; CleanupStack::PopAndDestroy(6); } CleanupStack::PopAndDestroy(store); } else { CMsvEntry* attachmentEntry = iMsvSession->GetEntryL((*messageEntry)[0].Id()); CleanupStack::PushL(attachmentEntry); //1st push CMsvStore* store = attachmentEntry->ReadStoreL(); CleanupStack::PushL(store); //2nd push TBuf<KMaxPath> attachmentName(store->AttachmentManagerL().GetAttachmentInfoL(0)->AttachmentName()); RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); TEntry entry; User::LeaveIfError(fs.Entry(attachmentName, entry)); CleanupStack::PopAndDestroy(&fs); //get file handle for the attachment & the complete path of the file RFile attachmentFile; attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0); CleanupClosePushL(attachmentFile); //3rd Push User::LeaveIfError(attachmentFile.FullName(aMsgPath)); CleanupStack::PopAndDestroy(&attachmentFile); StoreMessageMimeTypeL(aMsgPath); //mark attachment as Read TMsvEntry attachEntry = attachmentEntry->Entry(); attachEntry.SetUnread(EFalse); attachmentEntry->ChangeL(attachEntry); CleanupStack::PopAndDestroy(store); CleanupStack::PopAndDestroy(attachmentEntry); } CleanupStack::PopAndDestroy(messageEntry); }
void CheckNewAttachmentL(const TDesC& aFileName, TInt aFileSize, const TDesC8& aMimeType, TUint aCharset, TBool aLinkedAttachment) { // Check that file exists in the store and it matches our control file. CDummyObserver* ob1 = new(ELeave) CDummyObserver; CleanupStack::PushL(ob1); CMsvSession* session = CMsvSession::OpenSyncL(*ob1); CleanupStack::PushL(session); CMsvEntry* cEntry = CMsvEntry::NewL(*session, KMsvDraftEntryId, TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue)); CleanupStack::PushL(cEntry); CMsvEntrySelection* selection = cEntry->ChildrenL(); CleanupStack::PushL(selection); test(selection->Count() == 1); cEntry->SetEntryL((*selection)[0]); CMsvStore* store = cEntry->ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL(); TInt count = attachmentMgr.AttachmentCount(); test(count > 0); TBool found = EFalse; while( count-- > 0 && !found ) { CMsvAttachment* attachmentInfo = attachmentMgr.GetAttachmentInfoL(count); CleanupStack::PushL(attachmentInfo); // Check the attachment info is what we expect. TParse parser1; TParse parser2; parser1.Set(attachmentInfo->FilePath(), NULL, NULL); parser2.Set(aFileName, NULL, NULL); found = ETrue; if (aLinkedAttachment) { found = found && (attachmentInfo->Type() == CMsvAttachment::EMsvLinkedFile); // Check it's a linked file. found = found && (parser1.DriveAndPath() == parser2.DriveAndPath()); } else { found = found && (attachmentInfo->Type() == CMsvAttachment::EMsvFile); // Check it's a file. found = found && (parser1.DriveAndPath() != parser2.DriveAndPath()); } found = found && (attachmentInfo->MimeType().Match(aMimeType) == 0); // Check mime type matches. found = found && (parser1.NameAndExt() == parser2.NameAndExt()); // This necessarily correct? found = found && (attachmentInfo->Size() == aFileSize); // Check size matches. // check charset matches CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewLC(); mimeHeaders->RestoreL(*attachmentInfo); found = found && (mimeHeaders->MimeCharset() == aCharset); CleanupStack::PopAndDestroy(2, attachmentInfo); // mimeHeaders, attachmentInfo } test(found); CleanupStack::PopAndDestroy(5, ob1); // store, selection, cEntry, sesion, ob1 }
// --------------------------------------------------------- // CMmsAttachmentHandler::CreateUTF8TextAttachmentFromFileL // --------------------------------------------------------- EXPORT_C void CMmsAttachmentHandler::CreateUTF8TextAttachmentFromFileL( CMsvStore& aStore, TMsvAttachmentId& aAttachmentId, RFile& aFile, RFs& aFs, TDriveUnit aMessageDrive ) { _LIT8 ( KMmsCrLf8, "\x00D\x00A" ); // 8 bit line feed TInt size = 0; TInt error = KErrNone; error = aFile.Size( size ); User::LeaveIfError( error ); // if can't get file size, we are in trouble TFileName* filename = new( ELeave ) TFileName; CleanupStack::PushL( filename ); // 256 characters for each read HBufC* textBuffer = HBufC::NewL( KMmsTextBufferSize ); CleanupStack::PushL( textBuffer ); TPtr textPtr = textBuffer->Des(); HBufC8* buffer = HBufC8::NewL( KMmsTextBufferSize * KMmsMaxBytesPerCharacter ); // paranoid. TInt fileSize = 0; // we don't know how big the file will be after conversion CleanupStack::PushL( buffer ); TPtr8 buf8 = buffer->Des(); CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL(); CleanupStack::PushL( mimeHeaders ); // attaInfo must be on top of stack because the ownership will be transferred // to attacment manager. CMsvAttachment* attaInfo = CMsvAttachment::NewL( CMsvAttachment::EMsvFile ); CleanupStack::PushL( attaInfo ); TPtrC8 contentType; contentType.Set( KMmsTextPlain ); TInt position = contentType.Find( KMmsSlash8 ); mimeHeaders->SetContentTypeL( contentType.Left( position ) ); mimeHeaders->SetContentSubTypeL( contentType.Mid( position + 1 ) ); attaInfo->SetMimeTypeL( contentType ); filename->Copy( TPtrC() ); aFile.Name( *filename ); // if this returns error, filename should be empty - no suggestion. attaInfo->SetAttachmentNameL( *filename ); mimeHeaders->SetSuggestedFilenameL( *filename ); mimeHeaders->SetMimeCharset( KMmsUtf8 ); if ( TMmsGenUtils::DiskSpaceBelowCriticalLevelL( &aFs, size * KMmsUnicodeToUtf2MaxIncrease + mimeHeaders->Size() + KMmsIndexEntryExtra, aMessageDrive ) ) { // we use standard error code here User::Leave( KErrDiskFull ); } mimeHeaders->StoreL( *attaInfo ); // Mime headers are streamed into atta info MMsvAttachmentManagerSync& attaManSync = aStore.AttachmentManagerExtensionsL(); RFile attaFile; attaManSync.CreateAttachmentL( *filename, attaFile, attaInfo ); CleanupStack::Pop( attaInfo ); // attaInfo ownership was transferred. aAttachmentId = attaInfo->Id(); // Now our file handle is open for writing error = KErrNone; TMmsFileText textFile; textFile.Set( aFile ); while ( error == KErrNone || error == KErrTooBig ) { error = textFile.Read( textPtr ); TBool appendCRLF = ETrue; if ( error == KErrTooBig ) { appendCRLF = EFalse; error = KErrNone; } if ( error != KErrEof ) { // if conversion fails, something is really seriously wrong error = CnvUtfConverter::ConvertFromUnicodeToUtf8( buf8, textPtr ); } if ( error == KErrNone ) { error = attaFile.Write( buf8 ); if ( error == KErrNone ) { fileSize += buf8.Length(); if ( appendCRLF ) { error = attaFile.Write( KMmsCrLf8 ); fileSize += KMmsLengthOfCRlf; // add length of carriage return/line feed } } } } if ( error == KErrEof ) { // end of file has been reached successfully error = KErrNone; } if ( error == KErrNone ) { error = attaFile.Flush(); } attaFile.Close(); if ( error != KErrNone ) { // Something went wrong when we tried to write our data. // We must delete the attachment as it does not contain the // intended data. RemoveAttachmentL( aAttachmentId, aStore ); aAttachmentId = 0; } else { // If data writing was successful, the amount of data written // is now stored in fileSize. // Attachment info structure must be updated MMsvAttachmentManager& attaMan = aStore.AttachmentManagerL(); attaInfo = attaMan.GetAttachmentInfoL( aAttachmentId ); CleanupStack::PushL( attaInfo ); attaInfo->SetSize( fileSize ); attaManSync.ModifyAttachmentInfoL( attaInfo ); // attachment manager now owns the attachment info CleanupStack::Pop( attaInfo ); // attaInfo } CleanupStack::PopAndDestroy( mimeHeaders ); CleanupStack::PopAndDestroy( buffer ); CleanupStack::PopAndDestroy( textBuffer ); CleanupStack::PopAndDestroy( filename ); User::LeaveIfError( error ); }