|
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 // SmtpAddFileAttachmentByHandleSync |
|
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. |
|
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 // Creates a file handle from the specified file and synchronously adds the open |
|
27 // file handle as an attachment to the specified message entry. |
|
28 // [APIs Used] |
|
29 // CMsvSession::GetEntryL |
|
30 // CImEmailMessage::AttachmentManagerL |
|
31 // CMsvAttachment::NewL |
|
32 // CMsvAttachment::SetMimeType |
|
33 // MMsvAttachmentManager::AddAttachmentL |
|
34 // __ACTION_INFO_END__ |
|
35 // |
|
36 // |
|
37 |
|
38 |
|
39 #include "CMtfTestActionSmtpAddFileAttachmentByHandleSync.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* CMtfTestActionSmtpAddFileAttachmentByHandleSync::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
51 { |
|
52 CMtfTestActionSmtpAddFileAttachmentByHandleSync* self = new(ELeave) CMtfTestActionSmtpAddFileAttachmentByHandleSync(aTestCase); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(aActionParameters); |
|
55 CleanupStack::Pop(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 CMtfTestActionSmtpAddFileAttachmentByHandleSync::CMtfTestActionSmtpAddFileAttachmentByHandleSync(CMtfTestCase& aTestCase) |
|
61 : CMtfSynchronousTestAction(aTestCase) |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 CMtfTestActionSmtpAddFileAttachmentByHandleSync::~CMtfTestActionSmtpAddFileAttachmentByHandleSync() |
|
67 { |
|
68 } |
|
69 |
|
70 void CMtfTestActionSmtpAddFileAttachmentByHandleSync::ExecuteActionL() |
|
71 { |
|
72 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpAddFileAttachmentByHandleSync); |
|
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."), &KTestActionSmtpAddFileAttachmentByHandleSync); |
|
85 TestCase().ActionCompletedL(*this); |
|
86 } |
|
87 |
|
88 void CMtfTestActionSmtpAddFileAttachmentByHandleSync::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::EMsvFile); |
|
105 CleanupStack::PushL(attachment); |
|
106 |
|
107 attachment->SetMimeTypeL(*paramMimeType); |
|
108 |
|
109 MMsvAttachmentManager& manager = emailMsg->AttachmentManager(); |
|
110 |
|
111 RFile fileHandle = OpenFileLC(paramSession->FileSession(), *paramFilePath); |
|
112 |
|
113 TFileName fileName; |
|
114 User::LeaveIfError(fileHandle.Name(fileName)); |
|
115 attachment->SetAttachmentNameL(fileName); |
|
116 |
|
117 TInt fileSize = 0; |
|
118 User::LeaveIfError(fileHandle.Size(fileSize)); |
|
119 attachment->SetSize(fileSize); |
|
120 |
|
121 manager.AddAttachmentL(fileHandle, attachment, waiter->iStatus); |
|
122 CleanupStack::Pop(2, attachment); // fileHandle, attachment, ownership passed to manager |
|
123 waiter->StartAndWait(); |
|
124 User::LeaveIfError(waiter->Result()); |
|
125 CleanupStack::PopAndDestroy(waiter); |
|
126 |
|
127 TInt attachmentCount = manager.AttachmentCount(); |
|
128 |
|
129 attachment = NULL; |
|
130 |
|
131 attachment = manager.GetAttachmentInfoL(attachmentCount - 1); |
|
132 CleanupStack::PushL(attachment); |
|
133 |
|
134 TMsvAttachmentId attachmentId = attachment->Id(); |
|
135 |
|
136 CleanupStack::PopAndDestroy(attachment); |
|
137 |
|
138 CleanupStack::PopAndDestroy(2, entry); // emailMsg, entry |
|
139 |
|
140 StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(4)); |
|
141 } |
|
142 |
|
143 |
|
144 RFile CMtfTestActionSmtpAddFileAttachmentByHandleSync::OpenFileLC(RFs& aFs, const TDesC& aFilePath) |
|
145 { |
|
146 RFile fileHandle; |
|
147 User::LeaveIfError(fileHandle.Open(aFs, aFilePath, EFileRead)); |
|
148 CleanupClosePushL(fileHandle); |
|
149 return fileHandle; |
|
150 } |