|
1 // Copyright (c) 2007-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @file |
|
15 // [TestStep Name] |
|
16 // SmtpCreateNewMessageWithPlainBodyText |
|
17 // [Paramaters] |
|
18 // Subject : Subject line of the message. |
|
19 // FolderName : Destination local folder where message is to be created. |
|
20 // RecipientsAddress: Recepient's address. |
|
21 // EmailFileName : Plain text file name from which body text part would be populated. |
|
22 // Creates a new message entry with plain body text. For creating the message entry it uses |
|
23 // CImEmailOperation::CreateNewL() static metod. After creating the message entry |
|
24 // it populates the body part with the contents of a plain text file. |
|
25 // [APIs Used] |
|
26 // CImPlainBodyText::CommitL |
|
27 // CImPlainBodyText::StoreChunkL |
|
28 // CImEmailOperation::CreateNewL |
|
29 // CImEmailMessage::OpenPlainBodyTextForWriteL |
|
30 // |
|
31 // |
|
32 |
|
33 |
|
34 |
|
35 // User includes |
|
36 #include "t_smtpcreatenewmessagewithplainbodytext.h" |
|
37 #include <t_utilscentralrepository.h> |
|
38 #include <t_utilsenumconverter.h> |
|
39 #include <t_utils.h> |
|
40 |
|
41 // Epoc includes |
|
42 #include <miutmsg.h> |
|
43 #include <cimplainbodytext.h> |
|
44 |
|
45 // Literals Used |
|
46 _LIT(KSubject, "Subject"); |
|
47 _LIT(KFolderName, "FolderName"); |
|
48 _LIT(KEmailFileName, "EmailFileName"); |
|
49 _LIT(KRecipientsAddress, "RecipientsAddress"); |
|
50 |
|
51 const TInt KChunkSize = 1024; |
|
52 |
|
53 /** |
|
54 Function : CT_SmtpCreateNewMessageWithPlainBodyText |
|
55 Description : Constructor |
|
56 @param : aSharedDataSMTP Reference to CT_MsgSharedDataSmtp |
|
57 @return : N/A |
|
58 */ |
|
59 CT_SmtpCreateNewMessageWithPlainBodyText::CT_SmtpCreateNewMessageWithPlainBodyText(CT_MsgSharedDataSmtp& aSharedDataSMTP) |
|
60 : CT_MsgAsyncStepSMTP(aSharedDataSMTP) |
|
61 , iOperation(NULL) |
|
62 { |
|
63 SetTestStepName(KSmtpCreateNewMessageWithPlainBodyText); |
|
64 } |
|
65 |
|
66 |
|
67 /** |
|
68 Function : NewL |
|
69 Description : Creates an object of CT_SmtpCreateNewMessageWithPlainBodyText |
|
70 @return : N/A |
|
71 */ |
|
72 CT_SmtpCreateNewMessageWithPlainBodyText* CT_SmtpCreateNewMessageWithPlainBodyText::NewL(CT_MsgSharedDataSmtp& aSharedDataSMTP) |
|
73 { |
|
74 CT_SmtpCreateNewMessageWithPlainBodyText* self = new(ELeave) CT_SmtpCreateNewMessageWithPlainBodyText(aSharedDataSMTP); |
|
75 CleanupStack::PushL(self); |
|
76 self->ConstructL(); |
|
77 CleanupStack::Pop(self); |
|
78 return self; |
|
79 } |
|
80 |
|
81 |
|
82 /** |
|
83 Function : ~CT_SmtpCreateNewMessageWithPlainBodyText |
|
84 Description : Destructor |
|
85 @return : N/A |
|
86 */ |
|
87 CT_SmtpCreateNewMessageWithPlainBodyText::~CT_SmtpCreateNewMessageWithPlainBodyText() |
|
88 { |
|
89 delete iRecipientAddress; |
|
90 delete iOperation; |
|
91 } |
|
92 |
|
93 /** |
|
94 Function : ProgressL |
|
95 Description : Displays the status of the asynchronous operation |
|
96 @return : N/A |
|
97 */ |
|
98 void CT_SmtpCreateNewMessageWithPlainBodyText::ProgressL(TBool /*bFinal*/) |
|
99 {} |
|
100 |
|
101 |
|
102 /** |
|
103 Function : CancelStep |
|
104 Description : Cancels the asynchronous operation |
|
105 @return : N/A |
|
106 */ |
|
107 void CT_SmtpCreateNewMessageWithPlainBodyText::CancelStep() |
|
108 { |
|
109 iOperation->Cancel(); |
|
110 } |
|
111 |
|
112 |
|
113 /** |
|
114 Function : doTestStepL |
|
115 Description : Reads the SMTP account name, folder names, download limts and the command name from |
|
116 the ini file. A selection of the entries uner the remote folder is obtained and passed to |
|
117 InvokeAsyncFunctionL based on the command. |
|
118 @return : TVerdict - Test step result |
|
119 */ |
|
120 TVerdict CT_SmtpCreateNewMessageWithPlainBodyText::doTestStepL() |
|
121 { |
|
122 INFO_PRINTF1(_L("TestStep: SmtpCreateNewMessageWithPlainBodyText")); |
|
123 |
|
124 // Read the name of the target folder from the ini file |
|
125 TPtrC folderName; |
|
126 if(!GetStringFromConfig( ConfigSection(), KFolderName, folderName)) |
|
127 { |
|
128 ERR_PRINTF1(_L("Folder name is not specified")); |
|
129 SetTestStepResult(EFail); |
|
130 } |
|
131 |
|
132 TMsvId folderId; |
|
133 // Get the Id of the local folder |
|
134 folderId= CT_MsgUtilsEnumConverter::FindFolderIdByName(folderName); |
|
135 iSharedDataSMTP.iMtm->SwitchCurrentEntryL(folderId); |
|
136 TImCreateMessageOptions createMessageOptions; |
|
137 createMessageOptions.iMsvPartList = KMsvMessagePartBody; |
|
138 createMessageOptions.iMessageType = KUidMsgTypeSMTP; |
|
139 |
|
140 TPckgBuf<TImCreateMessageOptions> paramPack(createMessageOptions); |
|
141 |
|
142 CT_MsgActive& active=Active(); |
|
143 delete iOperation; |
|
144 iOperation = NULL; |
|
145 TRAPD(err2, iOperation = CImEmailOperation::CreateNewL(active.iStatus, *iSharedDataSMTP.iSession, folderId,KMsvNullIndexEntryId, paramPack().iMsvPartList, paramPack().iMsvEmailTypeList, paramPack().iMessageType, CActive::EPriorityStandard, ETrue)); |
|
146 active.Activate(); |
|
147 CActiveScheduler::Start(); |
|
148 |
|
149 SetHeaderPartL(); |
|
150 PopulateBodyPartL(); |
|
151 User::LeaveIfError(active.Result()); |
|
152 INFO_PRINTF2(_L("err2 : %d"), err2); |
|
153 return TestStepResult(); |
|
154 } |
|
155 |
|
156 |
|
157 /** |
|
158 Function : PopulateBodyPartL |
|
159 Description : Populates body part with the contents of a plain text file. |
|
160 @return : N/A |
|
161 */ |
|
162 void CT_SmtpCreateNewMessageWithPlainBodyText::PopulateBodyPartL() |
|
163 { |
|
164 //Get the message ID from the CMsvOperation object |
|
165 TMsvId temp; |
|
166 TPckgC<TMsvId> paramPack(temp); |
|
167 const TDesC8& progBuf = iOperation->ProgressL(); |
|
168 paramPack.Set(progBuf); |
|
169 TMsvId newMessageId = paramPack(); |
|
170 if (newMessageId!=NULL) |
|
171 { |
|
172 CMsvEntry *entry = CMsvEntry::NewL(*(iSharedDataSMTP.iSession), newMessageId, TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue)); |
|
173 CleanupStack::PushL(entry); |
|
174 entry->SetEntryL(newMessageId); |
|
175 CImEmailMessage *emailMessage = CImEmailMessage::NewLC(*entry); |
|
176 CImPlainBodyText* bodytext = emailMessage->OpenPlainBodyTextForWriteL(); |
|
177 CleanupStack::PushL(bodytext); |
|
178 |
|
179 |
|
180 TPtrC emailFileName; |
|
181 // Read the name of the email file from the ini |
|
182 if(!GetStringFromConfig(ConfigSection(),KEmailFileName,emailFileName)) |
|
183 { |
|
184 ERR_PRINTF1(_L("Email file name not specified")); |
|
185 SetTestStepResult(EFail); |
|
186 } |
|
187 else |
|
188 { |
|
189 RFs fs; |
|
190 User::LeaveIfError(fs.Connect()); |
|
191 CleanupClosePushL(fs); |
|
192 |
|
193 RFile file; |
|
194 User::LeaveIfError(file.Open(fs,emailFileName,EFileRead)); |
|
195 CleanupClosePushL(file); |
|
196 |
|
197 |
|
198 TBuf8<KChunkSize> line; |
|
199 TBuf8<1> aChar; // To read one character from the file |
|
200 TBool finished = FALSE; |
|
201 |
|
202 // Read text from the file |
|
203 do |
|
204 { |
|
205 line.FillZ(); |
|
206 line.SetLength(0); |
|
207 // Read one line from email file |
|
208 do |
|
209 { |
|
210 file.Read(aChar, 1); |
|
211 if(aChar.Length()) |
|
212 { |
|
213 line.Append(aChar); |
|
214 } |
|
215 else |
|
216 { |
|
217 finished = TRUE; |
|
218 } |
|
219 }while(aChar.Length() && aChar[0] != 0x0A); |
|
220 if(!line.Length()) |
|
221 { |
|
222 break; |
|
223 } |
|
224 CT_MsgActive& active=Active(); |
|
225 bodytext->StoreChunkL(line,active.iStatus); |
|
226 active.Activate(); |
|
227 CActiveScheduler::Start(); |
|
228 }while(!finished); |
|
229 |
|
230 CT_MsgActive& active=Active(); |
|
231 bodytext->CommitL(active.iStatus); |
|
232 active.Activate(); |
|
233 CActiveScheduler::Start(); |
|
234 |
|
235 CleanupStack::PopAndDestroy(2); // delete file,fs |
|
236 } |
|
237 CleanupStack::PopAndDestroy(3, entry); // delete bodytext,emailMessage,entry |
|
238 } |
|
239 } |
|
240 |
|
241 |
|
242 /** |
|
243 Function : GetDefaultAddressL |
|
244 Description : Retrieve the default email address from the default SMTP service. |
|
245 @return : N/A |
|
246 */ |
|
247 void CT_SmtpCreateNewMessageWithPlainBodyText::GetDefaultAddressL() |
|
248 { |
|
249 CImSmtpSettings* settings = new(ELeave) CImSmtpSettings(); |
|
250 CleanupStack::PushL(settings); |
|
251 |
|
252 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
253 TSmtpAccount smtpAccount; |
|
254 smtpAccount.iSmtpService = KMsvNullIndexEntryId; |
|
255 accounts->DefaultSmtpAccountL(smtpAccount); |
|
256 accounts->LoadSmtpSettingsL(smtpAccount, *settings); |
|
257 CleanupStack::PopAndDestroy(accounts); // accounts |
|
258 iRecipientAddress = settings->EmailAddress().AllocL(); |
|
259 INFO_PRINTF2(_L("Default Email Address is %s"),iRecipientAddress->Ptr()); |
|
260 CleanupStack::PopAndDestroy(settings); // settings |
|
261 } |
|
262 |
|
263 |
|
264 /** |
|
265 Function : SetHeaderPartL |
|
266 Description : Sets the message header fields. If the field values are not provided |
|
267 as input, it takes the default values. |
|
268 @return : N/A |
|
269 */ |
|
270 void CT_SmtpCreateNewMessageWithPlainBodyText::SetHeaderPartL() |
|
271 { |
|
272 //check progress |
|
273 TMsvId temp; |
|
274 TPckgC<TMsvId> paramPack(temp); |
|
275 const TDesC8& progBuf = iOperation->ProgressL(); |
|
276 paramPack.Set(progBuf); |
|
277 TMsvId newMessageId = paramPack(); |
|
278 if (newMessageId!=NULL) |
|
279 { |
|
280 CMsvEntry *entry = CMsvEntry::NewL(*(iSharedDataSMTP.iSession), newMessageId, TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue)); |
|
281 CleanupStack::PushL(entry); |
|
282 entry->SetEntryL(newMessageId); // |
|
283 CMsvStore* store = entry->EditStoreL(); |
|
284 CleanupStack::PushL(store); |
|
285 |
|
286 CImHeader* header = CImHeader::NewLC(); |
|
287 header->RestoreL(*store); // Retrieves the email message header part from the message store |
|
288 TPtrC subject; |
|
289 if(GetStringFromConfig(ConfigSection(), KSubject, subject)) |
|
290 { |
|
291 header->SetSubjectL(subject); |
|
292 } |
|
293 TPtrC recipientsAddress; |
|
294 if(GetStringFromConfig(ConfigSection(), KRecipientsAddress, recipientsAddress)) |
|
295 { |
|
296 header->ToRecipients().AppendL(recipientsAddress); |
|
297 } |
|
298 else |
|
299 { |
|
300 GetDefaultAddressL(); |
|
301 header->ToRecipients().AppendL(*iRecipientAddress); |
|
302 } |
|
303 header->StoreL(*store); |
|
304 store->CommitL(); // Saves the modifications to message store |
|
305 TMsvEntry indexEntry = entry->Entry(); |
|
306 indexEntry.iDescription.Set(header->Subject()); |
|
307 INFO_PRINTF2(_L("Subject field created message : %S"), &(indexEntry.iDescription)); |
|
308 indexEntry.SetVisible(ETrue); |
|
309 entry->ChangeL(indexEntry); // Modify the corresponding index entry permanently |
|
310 |
|
311 CleanupStack::PopAndDestroy(3,entry); // header, store, entry |
|
312 } |
|
313 } |