The messaging framework allows you to retrieve and modify attachments to messages.
The following code uses the MMsvAttachmentManager::AttachmentCount() and GetattachmentL() functions to get attachment information. It then calls the various CMsvAttachment accessor functions to get the attachment attributes, and to access the attachment file itself:
void CFoo::GetAttachmentInfoL(MMsvAttachmentManager& attManager) { // get number of attachments TInt numAttach = attManager.AttachmentCount(); if ( numAttach == 0 ) { // no attachments return; } // Get attachment attributes for the first attachment (index 0) CMsvAttachment* attachInfo = attManager.GetAttachmentInfoL(0); // Ownership of attachInfo is transferred to the caller - so push it onto the CleanupStack CleanupStack::PushL(attachInfo); // Get attachment's name const TDesC& attachName = attachInfo->AttachmentName(); // Get attachment's size TInt attachSize = attachInfo->Size(); // Get attachment's type CMsvAttachment::TMsvAttachmentType attachType = attachInfo->Type(); // Get MIME type const TDesC8& attachMType = attachInfo->MimeType(); // Get completeness flag TBool complete = attachInfo->Complete(); ... // Destroy attachInfo when finished. CleanupStack::PopAndDestroy(attachInfo); }
You can modify attachment information for an existing attachment using the ModifyattachmentL() function. The attachment information object passed in replaces the existing attachment information object.
void CFoo::ModifyAttachmentInfoL(CMsvEntry& aEntry) { // Get the store CMsvStore* store = aEntry.EditStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& attManager = store->AttachmentManagerL(); // Get number of attachments TInt numAttach = attManager.AttachmentCount(); if ( numAttach == 0 ) { // no attachments CleanupStack::PopAndDestroy() ; // store return; } // Get attachment attributes for the first attachment (index 0) CMsvAttachment* attachment = attManager.GetAttachmentInfoL(0); CleanupStack::PushL( attachment ) ; // Rename the file TRequestStatus status; _LIT(KFileName, "hello.txt"); attachment->SetAttachmentNameL(KFileName); attachment->SetComplete(EFalse); // Modify attachment info attManager.ModifyAttachmentInfoL(attachment, status); // Wait for request to complete User::WaitForRequest(status); attachment->SetComplete(ETrue); store->CommitL(); CleanupStack::PopAndDestroy(2, store); // attachment, store }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.