Adding
attachments to messages
The messaging framework allows you to add attachments to messages.
A message attachment,
once it has been created, must be added to its message in a separate procedure
explained in this document.
-
Create an active object implementation. All the
MMsvAttachmentManager
functions
that modify attachments for an entry are asynchronous, so a request must be
called with an active object implementation.
//* Active object request function to add an attachment.
Arguments:
aEntry - entry to make attachment for
aAttachPath - path of file to attach
aSize - size of attachment in bytes
*/
void CFoo::AttachFileL(CMsvEntry& aEntry, const TFileName& aAttachPath, TInt aSize)
{
...
// Wait for request to complete
User::WaitForRequest(status);
CleanupStack::PopAndDestroy(store);
}
-
Get the details
of the message to which you want to add an attachment using
CMsvEntry::EditStoreL()
.
This function returns
CMsvStore
in writable mode.
// Get store
CMsvStore* store = aEntry.EditStoreL();
CleanupStack::PushL(store);
-
Get an
MMsvAttachmentManager
attachment
manager for the message entry, using
CMsvStore::AttachmentManagerL()
.
// Get attachment manager from the entry's store
MMsvAttachmentManager& attManager = store->AttachmentManagerL();
-
Create a new attachment attributes object using the
CMsvAttachment::NewL()
function.
// Create a new attachment attributes object
CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
CleanupStack::PushL(attachment);
-
Set the attachments name and size attributes using the functions of
the
CMsvAttachment
class.
// Set the attachment name and size attributes
TParse fparse;
User::LeaveIfError(fparse.Set(aAttachPath,NULL,NULL));
attachment->SetAttachmentNameL(fparse.NameAndExt());
attachment->SetSize(aSize);
-
Add the attachment using any of the following functions:
-
For copied attachments, use the
MMsvAttachmentManager::AddAttachmentL()
function.
-
For linked attachments, use the
MMsvAttachmentManager::AddLinkedAttachmentL()
function.
Note: For OBEX MTM, to add headers to an attachment, use the
CObexHeaderList::ExportToAttachmentL()
function.
Headers can be retrieved using the
CObexHeaderList::ImportFromAttachmentL()
function.
TRequestStatus status;
// Ownership of attachment will transfer to attachManager
CleanupStack::Pop(attachment);
// Add the attachment
attManager.AddAttachmentL(aAttachPath, attachment, status);
-
Commit the store.
You now have an
attachment added to its message.
You can now retrieve
and modify the message attachment.
Related information
Attachment
Tutorial
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.