719
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
872
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
719
|
5 |
// which accompanies this distribution, and is available
|
872
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
719
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// [TestStep Name]
|
|
15 |
// CreateSmtpMessageFromEmailFile
|
|
16 |
// [Paramaters]
|
|
17 |
// ParentFolderName : Name of the local folder under which the message
|
|
18 |
// needs to be created
|
|
19 |
// EmailFileName : Email file from which the message is to be created
|
|
20 |
// KilobytesExtra : Number of lines of 1024 characters to add to body text
|
|
21 |
// Default value is 0.
|
|
22 |
// [Test Step Description]
|
|
23 |
// Creates an Email message reading the contents from the email file specified
|
|
24 |
// from the config file.
|
|
25 |
// [APIs Used]
|
|
26 |
// CMsvEntry::SetEntryL
|
|
27 |
//
|
|
28 |
//
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
/**
|
|
33 |
@file
|
|
34 |
*/
|
|
35 |
|
|
36 |
// User include
|
|
37 |
#include "ImCltCvRecv.h"
|
|
38 |
#include <t_utilscentralrepository.h>
|
|
39 |
#include "T_CreateSmtpMessageFromEmailFile.h"
|
|
40 |
#include <t_utilsenumconverter.h>
|
|
41 |
|
|
42 |
|
|
43 |
// Literals Used
|
|
44 |
_LIT(KEmailFileName, "EmailFileName");
|
|
45 |
_LIT(KParentFolderName,"ParentFolderName");
|
|
46 |
_LIT(KKilobytesExtra, "KilobytesExtra");
|
|
47 |
_LIT(KOverRideAddress, "OverRideAddress");
|
|
48 |
|
|
49 |
// Maximum length of a line read from Email file
|
|
50 |
const TInt KMaxLenghtOfLine = 1024;
|
|
51 |
const TInt KMaxLenghtOfChar = 1;
|
|
52 |
|
|
53 |
/**
|
|
54 |
CT_MsgCreateSmtpMessageFromEmailFile()
|
|
55 |
Sets the test step name to KCreateSmtpMessageFromEmailFile
|
|
56 |
|
|
57 |
@param aSharedDataSMTP
|
|
58 |
|
|
59 |
*/
|
|
60 |
CT_MsgCreateSmtpMessageFromEmailFile::CT_MsgCreateSmtpMessageFromEmailFile(CT_MsgSharedDataSmtp& aSharedDataSMTP)
|
|
61 |
: CT_MsgSyncStepSMTP(aSharedDataSMTP)
|
|
62 |
{
|
|
63 |
SetTestStepName(KCreateSmtpMessageFromEmailFile);
|
|
64 |
}
|
|
65 |
|
|
66 |
|
|
67 |
/**
|
|
68 |
NewL()
|
|
69 |
Static factory constructor. Uses two phase
|
|
70 |
construction.
|
|
71 |
|
|
72 |
@param aSharedDataSMTP
|
|
73 |
@leave KErrNoMemory
|
|
74 |
@return
|
|
75 |
A pointer to the newly created CT_MsgCreateSmtpMessageFromEmailFile object.
|
|
76 |
*/
|
|
77 |
CT_MsgCreateSmtpMessageFromEmailFile* CT_MsgCreateSmtpMessageFromEmailFile::NewL(CT_MsgSharedDataSmtp& aSharedDataSMTP)
|
|
78 |
{
|
|
79 |
CT_MsgCreateSmtpMessageFromEmailFile* self = new(ELeave) CT_MsgCreateSmtpMessageFromEmailFile(aSharedDataSMTP);
|
|
80 |
CleanupStack::PushL(self);
|
|
81 |
CleanupStack::Pop(self);
|
|
82 |
return self;
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
/**
|
|
87 |
~CT_MsgCreateSmtpMessageFromEmailFile()
|
|
88 |
Destructor
|
|
89 |
*/
|
|
90 |
CT_MsgCreateSmtpMessageFromEmailFile::~CT_MsgCreateSmtpMessageFromEmailFile()
|
|
91 |
{
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
/**
|
|
96 |
doTestStepL()
|
|
97 |
Reads the name of the email file,parent foldername from the ini file
|
|
98 |
Parses the email file to generate a message under the parent folder
|
|
99 |
mentioned.If the number of lines is mentioned in the ini file then adds it to the
|
|
100 |
message.If not mentioned takes a default of 0.
|
|
101 |
|
|
102 |
@return
|
|
103 |
Returns the test step result
|
|
104 |
*/
|
|
105 |
TVerdict CT_MsgCreateSmtpMessageFromEmailFile::doTestStepL()
|
|
106 |
{
|
|
107 |
INFO_PRINTF1(_L("Test Step: CreateSmtpMessageFrom email file"));
|
|
108 |
TPtrC emailFileName;
|
|
109 |
// Read the name of the email file from the ini
|
|
110 |
if(!GetStringFromConfig(ConfigSection(),KEmailFileName,emailFileName))
|
|
111 |
{
|
|
112 |
ERR_PRINTF1(_L("Email file name not specified"));
|
|
113 |
SetTestStepResult(EFail);
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
TInt numKilobytesExtra = 0;
|
|
118 |
GetIntFromConfig( ConfigSection(), KKilobytesExtra, numKilobytesExtra);
|
|
119 |
|
|
120 |
TPtrC parentFolderName;
|
|
121 |
if(!GetStringFromConfig( ConfigSection(), KParentFolderName, parentFolderName))
|
|
122 |
{
|
|
123 |
ERR_PRINTF1(_L("Parent Folder is not specified"));
|
|
124 |
SetTestStepResult(EFail);
|
|
125 |
}
|
|
126 |
else
|
|
127 |
{
|
|
128 |
// Retrieves the folder Id based on the local folder name read from the ini file
|
|
129 |
TMsvId parentFolderId = CT_MsgUtilsEnumConverter::FindFolderIdByName(parentFolderName);
|
|
130 |
if( parentFolderId == KErrNotFound)
|
|
131 |
{
|
|
132 |
ERR_PRINTF1(_L("Invalid local folder name specified"));
|
|
133 |
SetTestStepResult(EFail);
|
|
134 |
}
|
|
135 |
else
|
|
136 |
{
|
|
137 |
INFO_PRINTF2(_L("The parent folder Id is %d"),parentFolderId );
|
|
138 |
|
|
139 |
// Retrieve the default Smtp service Id
|
|
140 |
TMsvId smtpServiceId(0);
|
|
141 |
TRAPD(err,smtpServiceId = CT_MsgUtilsCentralRepository::GetDefaultSmtpServiceIdL());
|
|
142 |
if(smtpServiceId == KMsvNullIndexEntryId)
|
|
143 |
{
|
|
144 |
ERR_PRINTF1(_L("Invalid account name specified"));
|
|
145 |
SetTestStepResult(EFail);
|
|
146 |
}
|
|
147 |
else
|
|
148 |
{
|
|
149 |
if(err != KErrNone)
|
|
150 |
{
|
|
151 |
ERR_PRINTF2(_L("Failure while getting the default SMTP Service Id. error = %d"),err);
|
|
152 |
SetTestStepResult(EFail);
|
|
153 |
}
|
|
154 |
else
|
|
155 |
{
|
|
156 |
INFO_PRINTF2(_L("The default Smtp serviceId is %d"),smtpServiceId );
|
|
157 |
|
|
158 |
// Set the context to the folder in which message has to be created
|
|
159 |
CMsvEntry* entry = CMsvEntry::NewL(*iSharedDataSMTP.iSession,parentFolderId,TMsvSelectionOrdering());
|
|
160 |
CleanupStack::PushL(entry);
|
|
161 |
entry->SetEntryL(parentFolderId);
|
|
162 |
|
|
163 |
RFs fs;
|
|
164 |
User::LeaveIfError(fs.Connect());
|
|
165 |
CleanupClosePushL(fs);
|
|
166 |
|
|
167 |
CImCltRecvConvert* recvConvert = CImCltRecvConvert::NewLC(fs,entry,KUidMsgTypeSMTP,
|
|
168 |
smtpServiceId);
|
|
169 |
recvConvert->SetMsvId(parentFolderId);
|
|
170 |
|
|
171 |
// Read one line of text from the file, parse the line and set the fields of the email
|
|
172 |
// message based on the contents of the parsed line.
|
|
173 |
|
|
174 |
// Open the Email file in read mode
|
|
175 |
RFile file;
|
|
176 |
User::LeaveIfError(file.Open(fs,emailFileName,EFileRead));
|
|
177 |
CleanupClosePushL(file);
|
|
178 |
|
|
179 |
TBuf8<KMaxLenghtOfLine> line;
|
|
180 |
TBuf8<KMaxLenghtOfChar> aChar; // To read one character from the file
|
|
181 |
TBool finished = FALSE;
|
|
182 |
|
|
183 |
recvConvert->ResetL();
|
|
184 |
|
|
185 |
// Parse each line from the
|
|
186 |
|
|
187 |
do
|
|
188 |
{
|
|
189 |
line.FillZ();
|
|
190 |
line.SetLength(0);
|
|
191 |
// Read one line from email file
|
|
192 |
do
|
|
193 |
{
|
|
194 |
file.Read(aChar, 1);
|
|
195 |
if(aChar.Length())
|
|
196 |
{
|
|
197 |
line.Append(aChar);
|
|
198 |
}
|
|
199 |
else
|
|
200 |
{
|
|
201 |
finished = TRUE;
|
|
202 |
}
|
|
203 |
}while(aChar.Length() && aChar[0] != 0x0A);
|
|
204 |
if(!line.Length())
|
|
205 |
{
|
|
206 |
break;
|
|
207 |
}
|
|
208 |
// Parse the line for the fields of the email and store them
|
|
209 |
recvConvert->ParseNextFieldL(line);
|
|
210 |
}while(!finished);
|
|
211 |
|
|
212 |
// For a large email, pad the email with extra characters
|
|
213 |
if(numKilobytesExtra > 0)
|
|
214 |
{
|
|
215 |
const TChar KPadChar = 'L';
|
|
216 |
line.Fill(KPadChar, 1024);
|
|
217 |
for(TInt i = 0; i < numKilobytesExtra; i++)
|
|
218 |
{
|
|
219 |
recvConvert->ParseNextFieldL(line);
|
|
220 |
}
|
|
221 |
}
|
|
222 |
|
|
223 |
// Complete the message creation by setting all the required fields and
|
|
224 |
// storing the email on to the message store.
|
|
225 |
// The created email's ID is returned by MessageCompelteL function
|
|
226 |
//
|
|
227 |
|
|
228 |
TMsvId messageId;
|
|
229 |
messageId = recvConvert->MessageCompleteL();
|
|
230 |
|
|
231 |
if(messageId == 0)
|
|
232 |
{
|
|
233 |
User::Leave(KErrUnknown);
|
|
234 |
}
|
|
235 |
TBool overrideAddr = ETrue; // Default is to override.
|
|
236 |
GetBoolFromConfig(ConfigSection(), KOverRideAddress, overrideAddr);
|
|
237 |
// If the recipients email address in the message need to be changed to SMTP service's
|
|
238 |
// email address field, "overrideAddr" should be set to ETrue.
|
|
239 |
if(overrideAddr)
|
|
240 |
{
|
|
241 |
CImSmtpSettings* settings = new(ELeave) CImSmtpSettings();
|
|
242 |
CleanupStack::PushL(settings);
|
|
243 |
|
|
244 |
CEmailAccounts* accounts = CEmailAccounts::NewLC();
|
|
245 |
TSmtpAccount smtpAccount;
|
|
246 |
accounts->GetSmtpAccountL(smtpServiceId, smtpAccount);
|
|
247 |
accounts->LoadSmtpSettingsL(smtpAccount, *settings);
|
|
248 |
CleanupStack::PopAndDestroy(accounts);
|
|
249 |
|
|
250 |
HBufC* emailAddress=settings->EmailAddress().AllocL();
|
|
251 |
CleanupStack::PushL(emailAddress);
|
|
252 |
|
|
253 |
entry->SetEntryL(messageId);
|
|
254 |
CMsvStore* store = entry->EditStoreL();
|
|
255 |
CleanupStack::PushL(store);
|
|
256 |
|
|
257 |
CImHeader* header = CImHeader::NewLC();
|
|
258 |
|
|
259 |
header->RestoreL(*store); // Retrieves the email message header
|
|
260 |
|
|
261 |
header->ToRecipients().Reset();
|
|
262 |
header->ToRecipients().AppendL(*emailAddress); // Modification of the e-mail ID
|
|
263 |
|
|
264 |
header->StoreL(*store);
|
|
265 |
store->CommitL();
|
|
266 |
|
|
267 |
CleanupStack::PopAndDestroy(3, emailAddress);
|
|
268 |
CleanupStack::PopAndDestroy(settings);
|
|
269 |
}
|
|
270 |
INFO_PRINTF2(_L("Created a email from file %S"),&emailFileName);
|
|
271 |
INFO_PRINTF2(_L("The id of the message created is %d"),messageId);
|
|
272 |
|
|
273 |
CleanupStack::PopAndDestroy(4, entry); // file, recvConvert, fs, entry
|
|
274 |
}
|
|
275 |
}
|
|
276 |
}
|
|
277 |
}
|
|
278 |
}
|
|
279 |
return TestStepResult();
|
|
280 |
}
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|