|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // __ACTION_INFO_BEGIN__ |
|
15 // [Action Name] |
|
16 // SmtpAddLinkedAttachment |
|
17 // [Action Parameters] |
|
18 // Session <input>: Reference to the session. |
|
19 // MsgId <input>: Value of the message Id. |
|
20 // FilePath <input>: File path of the attachment file to add as linked. |
|
21 // MimeType <input>: Mime-type of the attachment. |
|
22 // AttachmentId <output>: Value of the created attachment id. |
|
23 // ErrorCode <output>: (Optional) Returned error code, if not requested then code will |
|
24 // leave if not KErrNone |
|
25 // [Action Description] |
|
26 // Adds the specified file as a linked attachment to the specified message |
|
27 // entry. |
|
28 // [APIs Used] |
|
29 // CMsvSession::GetEntryL |
|
30 // CImEmailMessage::AttachmentManagerL |
|
31 // CMsvAttachment::NewL |
|
32 // CMsvAttachment::SetMimeType |
|
33 // MMsvAttachmentManager::AddLinkedAttachmentL |
|
34 // __ACTION_INFO_END__ |
|
35 // |
|
36 // |
|
37 |
|
38 |
|
39 #include "CMtfTestActionSmtpAddLinkedAttachment.h" |
|
40 #include "CMtfAsyncWaiter.h" |
|
41 #include "CMtfTestCase.h" |
|
42 #include "CMtfTestActionParameters.h" |
|
43 #include "MtfTestActionUtilsUser.h" |
|
44 |
|
45 #include <miutset.h> |
|
46 #include <cmsvattachment.h> |
|
47 #include <mmsvattachmentmanager.h> |
|
48 #include <miutmsg.h> |
|
49 |
|
50 CMtfTestAction* CMtfTestActionSmtpAddLinkedAttachment::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
51 { |
|
52 CMtfTestActionSmtpAddLinkedAttachment* self = new(ELeave) CMtfTestActionSmtpAddLinkedAttachment(aTestCase); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(aActionParameters); |
|
55 CleanupStack::Pop(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 CMtfTestActionSmtpAddLinkedAttachment::CMtfTestActionSmtpAddLinkedAttachment(CMtfTestCase& aTestCase) |
|
61 : CMtfSynchronousTestAction(aTestCase) |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 CMtfTestActionSmtpAddLinkedAttachment::~CMtfTestActionSmtpAddLinkedAttachment() |
|
67 { |
|
68 } |
|
69 |
|
70 void CMtfTestActionSmtpAddLinkedAttachment::ExecuteActionL() |
|
71 { |
|
72 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpAddLinkedAttachment); |
|
73 TRAPD(err, RunTestL()); |
|
74 |
|
75 if( ActionParameters().Count() < 6 ) |
|
76 { |
|
77 User::LeaveIfError(err); |
|
78 } |
|
79 else |
|
80 { |
|
81 StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(5)); |
|
82 } |
|
83 |
|
84 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSmtpAddLinkedAttachment); |
|
85 TestCase().ActionCompletedL(*this); |
|
86 } |
|
87 |
|
88 void CMtfTestActionSmtpAddLinkedAttachment::RunTestL() |
|
89 { |
|
90 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
91 TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
92 HBufC* paramFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(2)); |
|
93 HBufC8* paramMimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(3)); |
|
94 |
|
95 CMsvEntry* entry = paramSession->GetEntryL(messageEntry); |
|
96 CleanupStack::PushL(entry); |
|
97 |
|
98 CImEmailMessage* emailMsg = CImEmailMessage::NewL(*entry); |
|
99 CleanupStack::PushL(emailMsg); |
|
100 |
|
101 CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); |
|
102 CleanupStack::PushL(waiter); |
|
103 |
|
104 CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvLinkedFile); |
|
105 CleanupStack::PushL(attachment); |
|
106 |
|
107 attachment->SetMimeTypeL(*paramMimeType); |
|
108 |
|
109 TParse fileNameParser; |
|
110 User::LeaveIfError(fileNameParser.Set(*paramFilePath, NULL, NULL)); |
|
111 attachment->SetAttachmentNameL(fileNameParser.NameAndExt()); |
|
112 |
|
113 TEntry fileEntry; |
|
114 User::LeaveIfError(paramSession->FileSession().Entry( fileNameParser.FullName(), fileEntry)); |
|
115 attachment->SetSize(fileEntry.iSize); |
|
116 |
|
117 MMsvAttachmentManager& manager = emailMsg->AttachmentManager(); |
|
118 |
|
119 manager.AddLinkedAttachmentL(*paramFilePath, attachment, waiter->iStatus); |
|
120 CleanupStack::Pop(attachment); // ownership passed to manager |
|
121 waiter->StartAndWait(); |
|
122 User::LeaveIfError(waiter->Result()); |
|
123 CleanupStack::PopAndDestroy(waiter); |
|
124 |
|
125 attachment = NULL; |
|
126 |
|
127 TInt attachmentCount = manager.AttachmentCount(); |
|
128 attachment = manager.GetAttachmentInfoL(attachmentCount - 1); |
|
129 CleanupStack::PushL(attachment); |
|
130 |
|
131 TMsvAttachmentId attachmentId = attachment->Id(); |
|
132 |
|
133 CleanupStack::PopAndDestroy(attachment); |
|
134 |
|
135 CleanupStack::PopAndDestroy(2, entry); // emailMsg, entry |
|
136 |
|
137 StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(4)); |
|
138 } |