Ejemplo n.º 1
0
/**
Creates a new entry as a child of the current context.

Ownership of the created entry is given to the process with the specified SID.

The parent ID and entry ID are set by the Message Server.

@param	aEntry
Index entry value for the new entry

@param	aOwnerId
The SID of the process that will own the create entry.

@param aBulk
A boolean value to indicate whether this is part of a bulk operation. (ETrue = bulk)

@return
KErrNone - success; KErrNoMemory - a memory allocation failed;
KErrNotSupported - aEntry is invalid
*/
EXPORT_C TInt CMsvServerEntry::CreateEntry(TMsvEntry& aEntry, TSecureId aOwnerId, TBool aBulk)
	{
	__ASSERT_DEBUG(iEntry.Id()!=KMsvNullIndexEntryId, PanicServer(EMsvEntryWithNoContext2));
	aEntry.SetParent(iEntry.Id());
	__ASSERT_DEBUG(MsvUtils::ValidEntry(aEntry, ETrue), PanicServer(EMsvBadEntryContents));

	// if valid - try to create the new child
	TInt error;
	if (iEntry.Id()==KMsvNullIndexEntryId || !MsvUtils::ValidEntry(aEntry, ETrue))
		error = KErrNotSupported;
	else
		{
		error = iServer.AddEntry(aEntry, aOwnerId, ETrue, aBulk);

		// if the child was created,then notify everyone, otherwise reset the parent
		if (error)
			aEntry.SetParent(KMsvNullIndexEntryId);
		else
			{
			if (!aBulk)
				{
				iServer.NotifyChanged(EMsvEntriesCreated, aEntry.Id(), aEntry.Parent());
				}
			iEntry.SetOwner(ETrue);
			}
		}

	return error;
	}
Ejemplo n.º 2
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CSMSSender::DeleteEntryL(TMsvEntry& aMsvEntry)
    {
    // Take a handle to the parent entry
    CMsvEntry* parentEntry = CMsvEntry::NewL(*iSession, aMsvEntry.Parent(), TMsvSelectionOrdering());

    CleanupStack::PushL(parentEntry);

    // here parentEntry is the Sent folder (must be so that we can call DeleteL) 
    iOperation = parentEntry->DeleteL(aMsvEntry.Id(), iStatus);

    CleanupStack::PopAndDestroy(parentEntry);

    SetActive();
    }
Ejemplo n.º 3
0
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
	}
// -----------------------------------------------------------------------------
// CMmsAdapterMsvApi::DeleteUserFolderL
// -----------------------------------------------------------------------------
//
 TInt CMmsAdapterMsvApi::DeleteUserFolderL( TMsvId aUid )
    {
    TRACE_FUNC_ENTRY;
    
    CMsvEntry* entry = iSession.GetEntryL(aUid);
    CleanupStack::PushL(entry);
    
    TMsvEntry tEntry = entry->Entry();
    TMsvId parent = tEntry.Parent();        
    
    if ( tEntry.iType != KUidMsvFolderEntry || parent != KMsvMyFoldersEntryIdValue )
        {
        LOGGER_WRITE( "Not correct folder" );
        CleanupStack::PopAndDestroy(entry);
        LOGGER_LEAVEFN( "MsvApi::DeleteUserFolderL" );
        return KErrNotSupported;
        }
        
    CMsvEntrySelection* children = entry->ChildrenL();
    TInt count = children->Count();
    delete children;
    
    if ( count > 0 )
        {
        LOGGER_WRITE( "Folder not empty" );
        CleanupStack::PopAndDestroy( entry );
        LOGGER_LEAVEFN( "MsvApi::DeleteUserFolderL" );
        return KErrInUse;
        }
        
    tEntry.SetReadOnly( EFalse );
    entry->ChangeL( tEntry );
    
    entry->SetEntryL( parent );
    entry->DeleteL( aUid );
    
    CleanupStack::PopAndDestroy( entry );
    TRACE_FUNC_EXIT;
    return KErrNone;
    }   
// ----------------------------------------------------------------------------
// 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();
    }