|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-D8D698FF-08CD-56B4-A6BF-E185A25F6988" xml:lang="en"><title>Retrieving |
|
13 and modifying attachments to messages</title><shortdesc>The messaging framework allows you to retrieve and modify attachments |
|
14 to messages. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
15 <context id="GUID-15885C98-AB41-5250-BC54-8FD519FCC2DB"><p>Attachments may |
|
16 be retrieved and modified after they have been added to a message. </p> </context> |
|
17 <steps id="GUID-8EC42591-32C1-5790-B644-E9DD82F4C767"> |
|
18 <step id="GUID-7FB4A7D1-965F-5E58-9606-0B2BBDFA9781"><cmd>Get the details |
|
19 of the message to which you want to add an attachment using <xref href="GUID-85BBE389-81F7-3E2F-A789-446D9BE2CC49.dita#GUID-85BBE389-81F7-3E2F-A789-446D9BE2CC49/GUID-1864B96D-CB22-3EE1-8E73-023F12C68CB0"><apiname>CMsvEntry::EditStoreL()</apiname></xref>. </cmd> |
|
20 <info>This function returns <xref href="GUID-8CB90FA2-A6CF-3FA2-81FF-7D22EFD9C2CE.dita"><apiname>CMsvStore</apiname></xref> in writable mode. </info> |
|
21 </step> |
|
22 <step id="GUID-BF15138A-9F76-5BD0-A72F-8A125B011CCE"><cmd>Get an <xref href="GUID-4E2B0CEA-1EDA-3452-895D-3CE1B59FD8FD.dita"><apiname>MMsvAttachmentManager</apiname></xref> attachment |
|
23 manager for the message entry, using <xref href="GUID-8CB90FA2-A6CF-3FA2-81FF-7D22EFD9C2CE.dita#GUID-8CB90FA2-A6CF-3FA2-81FF-7D22EFD9C2CE/GUID-73CE27F3-855B-3F87-AE11-4B4F2B8F8825"><apiname>CMsvStore::AttachmentManagerL()</apiname></xref>. </cmd> |
|
24 </step> |
|
25 <step id="GUID-A7041D09-6EA5-54CE-A972-E0D4993C26FC"><cmd/> |
|
26 <info>Find how many attachments a message entry has using the <xref href="GUID-4E2B0CEA-1EDA-3452-895D-3CE1B59FD8FD.dita#GUID-4E2B0CEA-1EDA-3452-895D-3CE1B59FD8FD/GUID-BAA9F4CF-E7F8-3644-8C0D-4387BAB7C432"><apiname>MMsvAttachmentManager::AttachmentCount()</apiname></xref> function. </info> |
|
27 </step> |
|
28 <step id="GUID-A58AFC6B-ADBA-5D3F-824F-A9EBDEBB2A0A"><cmd/> |
|
29 <info>Get attachment attributes using the appropriate <xref href="GUID-8C2B9B89-D6B7-3622-AF26-658F53BCB70F.dita"><apiname>CMsvAttachment</apiname></xref> functions. |
|
30 . </info> |
|
31 </step> |
|
32 <step id="GUID-5574C96C-2E2B-55CC-AE8A-BF44CFD76D4B"><cmd/> |
|
33 <info>Get attachment information using the <xref href="GUID-4E2B0CEA-1EDA-3452-895D-3CE1B59FD8FD.dita#GUID-4E2B0CEA-1EDA-3452-895D-3CE1B59FD8FD/GUID-256088DF-2FD0-32D9-8EEE-EFAC65A8E9AC"><apiname>MMsvAttachmentManager::GetattachmentL()</apiname></xref> function. </info> |
|
34 </step> |
|
35 </steps> |
|
36 <example id="GUID-94880E70-F23F-5F18-8E0F-A29B99C96E4B"><title>Retrieval and |
|
37 modification example</title> <p>The following code uses the <xref href="GUID-4E2B0CEA-1EDA-3452-895D-3CE1B59FD8FD.dita#GUID-4E2B0CEA-1EDA-3452-895D-3CE1B59FD8FD/GUID-BAA9F4CF-E7F8-3644-8C0D-4387BAB7C432"><apiname>MMsvAttachmentManager::AttachmentCount()</apiname></xref> and <xref href="GUID-C7C9E584-2E24-3B65-9E37-F4085F9F7CDB.dita"><apiname>GetattachmentL()</apiname></xref> functions to get attachment information. It then calls the various <xref href="GUID-8C2B9B89-D6B7-3622-AF26-658F53BCB70F.dita"><apiname>CMsvAttachment</apiname></xref> accessor |
|
38 functions to get the attachment attributes, and to access the attachment file |
|
39 itself: </p> <codeblock id="GUID-FEEB49D7-E9D4-59E7-B9EC-CF87DA3140FE" xml:space="preserve">void CFoo::GetAttachmentInfoL(MMsvAttachmentManager& attManager) |
|
40 { |
|
41 // get number of attachments |
|
42 TInt numAttach = attManager.AttachmentCount(); |
|
43 if ( numAttach == 0 ) |
|
44 { // no attachments |
|
45 return; |
|
46 } |
|
47 |
|
48 // Get attachment attributes for the first attachment (index 0) |
|
49 CMsvAttachment* attachInfo = attManager.GetAttachmentInfoL(0); |
|
50 |
|
51 // Ownership of attachInfo is transferred to the caller - so push it onto the CleanupStack |
|
52 CleanupStack::PushL(attachInfo); |
|
53 |
|
54 // Get attachment's name |
|
55 const TDesC& attachName = attachInfo->AttachmentName(); |
|
56 |
|
57 // Get attachment's size |
|
58 TInt attachSize = attachInfo->Size(); |
|
59 |
|
60 // Get attachment's type |
|
61 CMsvAttachment::TMsvAttachmentType attachType = attachInfo->Type(); |
|
62 |
|
63 // Get MIME type |
|
64 const TDesC8& attachMType = attachInfo->MimeType(); |
|
65 |
|
66 // Get completeness flag |
|
67 TBool complete = attachInfo->Complete(); |
|
68 |
|
69 ... |
|
70 |
|
71 // Destroy attachInfo when finished. |
|
72 CleanupStack::PopAndDestroy(attachInfo); |
|
73 }</codeblock> <p>You can modify attachment information for an existing |
|
74 attachment using the <xref href="GUID-ECE58326-D542-3C73-AE6F-959DCF64A875.dita"><apiname>ModifyattachmentL()</apiname></xref> function. The |
|
75 attachment information object passed in replaces the existing attachment information |
|
76 object. </p> <codeblock id="GUID-DDA08731-A761-5D7F-91DF-41DBC0D16583" xml:space="preserve">void CFoo::ModifyAttachmentInfoL(CMsvEntry& aEntry) |
|
77 { |
|
78 // Get the store |
|
79 CMsvStore* store = aEntry.EditStoreL(); |
|
80 CleanupStack::PushL(store); |
|
81 |
|
82 MMsvAttachmentManager& attManager = store->AttachmentManagerL(); |
|
83 |
|
84 // Get number of attachments |
|
85 TInt numAttach = attManager.AttachmentCount(); |
|
86 if ( numAttach == 0 ) |
|
87 { // no attachments |
|
88 CleanupStack::PopAndDestroy() ; // store |
|
89 return; |
|
90 } |
|
91 |
|
92 // Get attachment attributes for the first attachment (index 0) |
|
93 CMsvAttachment* attachment = attManager.GetAttachmentInfoL(0); |
|
94 CleanupStack::PushL( attachment ) ; |
|
95 |
|
96 // Rename the file |
|
97 TRequestStatus status; |
|
98 _LIT(KFileName, "hello.txt"); |
|
99 |
|
100 attachment->SetAttachmentNameL(KFileName); |
|
101 attachment->SetComplete(EFalse); |
|
102 |
|
103 // Modify attachment info |
|
104 attManager.ModifyAttachmentInfoL(attachment, status); |
|
105 |
|
106 // Wait for request to complete |
|
107 User::WaitForRequest(status); |
|
108 attachment->SetComplete(ETrue); |
|
109 |
|
110 store->CommitL(); |
|
111 |
|
112 CleanupStack::PopAndDestroy(2, store); // attachment, store |
|
113 }</codeblock> </example> |
|
114 </taskbody><related-links> |
|
115 <link href="GUID-1963A487-D6A7-4225-8D0C-EC5FAB746854.dita"><linktext>Messaging |
|
116 Attachments Tutorial</linktext></link> |
|
117 <link href="GUID-54AB166A-8B24-5065-92AD-5FC1BF3ED89C.dita"><linktext>Messaging |
|
118 Framework Overview</linktext></link> |
|
119 </related-links></task> |