|
1 // Copyright (c) 2003-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 // This test action was created from CMtfTestActionCreateSmtpMessageVariable. It adds a fifth parameter |
|
15 // which is a length so that emails with body text of any size can be sent (in multiples of 1024 characters). |
|
16 // The original has not been changed for this due to the file being independently modified - and those |
|
17 // modifications include a fifth parameter - which is different to this fifth parameter. |
|
18 // __ACTION_INFO_BEGIN__ |
|
19 // [Action Name] |
|
20 // CreateSmtpMessageFromEmailFile |
|
21 // [Action Parameters] |
|
22 // Session <input>: Reference to the session. |
|
23 // ServiceId <input>: Value of the SMTP service id. |
|
24 // FolderId <input>: Value of the local folder id where the message will be created. |
|
25 // (ConfigIndexEmailFile) <input>: Value of config index for email file. Default is 0. |
|
26 // MessageId <output>: Value of the created SMTP message id. |
|
27 // KBExtra <input>: Number of lines of 1024 characters to add to body text |
|
28 // OverrideAddress <input>: Override the To: address in the email to the current SMTP settings |
|
29 // [Action Description] |
|
30 // Creates a SMTP message on one of the local folders. |
|
31 // [APIs Used] |
|
32 // CMsvEntry::SetEntryL |
|
33 // CMsvEntry::Entry |
|
34 // TMsvId::Id |
|
35 // CImCltRecvConvert::SetMsvId |
|
36 // CImCltRecvConvert::ResetL |
|
37 // CImCltRecvConvert::MessageCompleteL |
|
38 // __ACTION_INFO_END__ |
|
39 // |
|
40 // |
|
41 |
|
42 /** |
|
43 @file |
|
44 */ |
|
45 |
|
46 |
|
47 #include "CMtfTestActionCreateSmtpMessageVariable.h" |
|
48 #include "CMtfTestCase.h" |
|
49 #include "CMtfTestActionParameters.h" |
|
50 |
|
51 #include <msvapi.h> |
|
52 #include <miutset.h> |
|
53 #ifdef __MESSAGING_API_V2__ |
|
54 #include <cemailaccounts.h> |
|
55 #endif // __MESSAGING_API_V2__ |
|
56 #include "ImCltCvRecv.h" |
|
57 |
|
58 // Maximum length of a line read from Email file |
|
59 const TInt KMaxLengthOfLine = 1024; |
|
60 |
|
61 CMtfTestAction* CMtfTestActionCreateSmtpMessageVariable::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
62 { |
|
63 CMtfTestActionCreateSmtpMessageVariable* self = new (ELeave) CMtfTestActionCreateSmtpMessageVariable(aTestCase); |
|
64 CleanupStack::PushL(self); |
|
65 self->ConstructL(aActionParameters); |
|
66 CleanupStack::Pop(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 |
|
71 CMtfTestActionCreateSmtpMessageVariable::CMtfTestActionCreateSmtpMessageVariable(CMtfTestCase& aTestCase) |
|
72 : CMtfSynchronousTestAction(aTestCase) |
|
73 { |
|
74 } |
|
75 |
|
76 |
|
77 CMtfTestActionCreateSmtpMessageVariable::~CMtfTestActionCreateSmtpMessageVariable() |
|
78 { |
|
79 } |
|
80 |
|
81 |
|
82 void CMtfTestActionCreateSmtpMessageVariable::ExecuteActionL() |
|
83 { |
|
84 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCreateSmtpMessageVariable); |
|
85 CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); |
|
86 TMsvId paramServiceId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); |
|
87 TMsvId paramFolderId = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(2)); |
|
88 TInt paramConfigIndexMailFile = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(3),0); |
|
89 TInt numKilobytesExtra = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(5)); |
|
90 |
|
91 |
|
92 TInt overrideAddress=1; |
|
93 if(ActionParameters().Count()>6) |
|
94 { |
|
95 overrideAddress=ObtainValueParameterL<TInt>(TestCase(), |
|
96 ActionParameters().Parameter(6)); |
|
97 } |
|
98 |
|
99 TPtrC fileName = TestCase().GetConfigurationFileL(CMtfConfigurationType::EMtfEmailFile,paramConfigIndexMailFile); |
|
100 |
|
101 CMsvEntry* entry = CMsvEntry::NewL(*paramSession,paramFolderId,TMsvSelectionOrdering()); |
|
102 CleanupStack::PushL(entry); |
|
103 entry->SetEntryL(paramServiceId); |
|
104 |
|
105 RFs fs; |
|
106 fs.Connect(); |
|
107 |
|
108 CImCltRecvConvert* recvConvert = CImCltRecvConvert::NewLC(fs,entry,entry->Entry().iMtm,paramServiceId); |
|
109 recvConvert->SetMsvId(paramFolderId); |
|
110 |
|
111 RFile file; |
|
112 User::LeaveIfError(file.Open(fs,fileName,EFileRead)); |
|
113 |
|
114 TestCase().INFO_PRINTF2(_L("Email Data file: %S"), &fileName); |
|
115 |
|
116 TBuf8<KMaxLengthOfLine> line; |
|
117 TBuf8<1> aChar; |
|
118 TBool finished = FALSE; |
|
119 |
|
120 recvConvert->ResetL(); |
|
121 |
|
122 do { |
|
123 line.FillZ(); |
|
124 line.SetLength(0); |
|
125 // Read one line from email file |
|
126 do { |
|
127 file.Read(aChar, 1); |
|
128 if(aChar.Length()) |
|
129 { |
|
130 line.Append(aChar); |
|
131 } |
|
132 else |
|
133 { |
|
134 finished = TRUE; |
|
135 } |
|
136 } while(aChar.Length() && aChar[0] != 0x0A); |
|
137 |
|
138 if(!line.Length()) |
|
139 { |
|
140 break; |
|
141 } |
|
142 // Parse the line for the fields of the email and store them |
|
143 recvConvert->ParseNextFieldL(line); |
|
144 } while(!finished); |
|
145 |
|
146 // For a large email, pad the email with extra characters |
|
147 if(numKilobytesExtra > 0) |
|
148 { |
|
149 const TChar padChar = 'L'; |
|
150 line.Fill(padChar, 1024); |
|
151 for(TInt i = 0; i < numKilobytesExtra; i++) |
|
152 { |
|
153 recvConvert->ParseNextFieldL(line); |
|
154 } |
|
155 } |
|
156 |
|
157 TMsvId paramMessageId = recvConvert->MessageCompleteL(); |
|
158 if(paramMessageId == 0) |
|
159 { |
|
160 User::Leave(KErrUnknown); |
|
161 } |
|
162 |
|
163 |
|
164 file.Close(); |
|
165 CleanupStack::PopAndDestroy(recvConvert); |
|
166 |
|
167 //***** |
|
168 if(overrideAddress) |
|
169 { |
|
170 #ifndef __MESSAGING_API_V2__ |
|
171 entry->SetEntryL(paramServiceId); |
|
172 CMsvStore* store=entry->ReadStoreL(); |
|
173 CleanupStack::PushL(store); |
|
174 #endif |
|
175 CImSmtpSettings* settings= new(ELeave) CImSmtpSettings(); |
|
176 CleanupStack::PushL(settings); |
|
177 #ifdef __MESSAGING_API_V2__ |
|
178 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
179 TSmtpAccount smtpAccount; |
|
180 accounts->GetSmtpAccountL(paramServiceId, smtpAccount); |
|
181 accounts->LoadSmtpSettingsL(smtpAccount, *settings); |
|
182 CleanupStack::PopAndDestroy(); |
|
183 #else |
|
184 settings->RestoreL(*store); |
|
185 CleanupStack::PopAndDestroy(); |
|
186 #endif |
|
187 HBufC* emailAddress=settings->EmailAddress().AllocL(); |
|
188 CleanupStack::PopAndDestroy(); |
|
189 CleanupStack::PushL(emailAddress); |
|
190 entry->SetEntryL(paramMessageId); |
|
191 #ifdef __MESSAGING_API_V2__ |
|
192 CMsvStore* store=entry->EditStoreL(); |
|
193 #else |
|
194 |
|
195 #endif |
|
196 CleanupStack::PushL(store); |
|
197 |
|
198 CImHeader* header= CImHeader::NewLC(); |
|
199 header->RestoreL(*store); |
|
200 |
|
201 header->ToRecipients().Reset(); |
|
202 header->ToRecipients().AppendL(*emailAddress); |
|
203 |
|
204 header->StoreL(*store); |
|
205 store->CommitL(); |
|
206 |
|
207 CleanupStack::PopAndDestroy(3,emailAddress); |
|
208 } |
|
209 //***** |
|
210 |
|
211 CleanupStack::PopAndDestroy(entry); |
|
212 |
|
213 TestCase().INFO_PRINTF2(_L("Created a email from file %S"),&fileName); |
|
214 |
|
215 StoreParameterL<TMsvId>(TestCase(),paramMessageId,ActionParameters().Parameter(4)); |
|
216 fs.Close(); |
|
217 |
|
218 TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCreateSmtpMessageVariable); |
|
219 TestCase().ActionCompletedL(*this); |
|
220 } |
|
221 |