|
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 |
|
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 // |
|
15 |
|
16 #include "ctestimapfetchbody.h" |
|
17 #include "cfakeinputstream.h" |
|
18 #include "cfakeoutputstream.h" |
|
19 #include "cactivewaiter.h" |
|
20 #include "moutputstream.h" |
|
21 #include "cimapsession.h" |
|
22 #include <msvids.h> |
|
23 #include <msvuids.h> |
|
24 #include <miuthdr.h> |
|
25 #include <miutset.h> |
|
26 #include "emailtestutils.h" |
|
27 #include "MSVSERV.H" |
|
28 #include "cimapfetchbodyresponse.h" |
|
29 #include "cimaputils.h" |
|
30 #include "cimapfolderinfo.h" |
|
31 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT) |
|
32 #include "cimapcapabilityinfo.h" |
|
33 #endif |
|
34 |
|
35 _LIT(KImapFetchBodyTest,"t_imapfetchbody"); |
|
36 _LIT(KBodyDetails,"testbody"); |
|
37 _LIT(KCDrive,"c:\\"); |
|
38 RTest test(KImapFetchBodyTest); |
|
39 |
|
40 CTestImapFetchBody::CTestImapFetchBody() |
|
41 : iInputStream(NULL) |
|
42 , iOutputStream(NULL) |
|
43 , iActiveWaiter(NULL) |
|
44 , iImapSession(NULL) |
|
45 , iFetchBodyInfo(NULL) |
|
46 , iMsvMessageEntry(0) |
|
47 , iAttMessageEntry(0) |
|
48 , iBodyMessageEntry(0) |
|
49 , iFolderId(0) |
|
50 , iImapSettings(NULL) |
|
51 , iImapMailStore(NULL) |
|
52 , iServerEntry(NULL) |
|
53 , iFetchBodyResponse(NULL) |
|
54 , iMsvServer(NULL) |
|
55 {} |
|
56 |
|
57 CTestImapFetchBody::~CTestImapFetchBody() |
|
58 { |
|
59 delete iImapSession; |
|
60 delete iActiveWaiter; |
|
61 delete iOutputStream; |
|
62 delete iInputStream; |
|
63 delete iFetchBodyInfo; |
|
64 delete iImapMailStore; |
|
65 delete iImapSettings; |
|
66 delete iFetchBodyResponse; |
|
67 delete iServerEntry; |
|
68 CImapUtils::Delete(); |
|
69 delete iMsvServer; |
|
70 } |
|
71 |
|
72 |
|
73 void CTestImapFetchBody::CreateMessageStructureL(TMsvId aId) |
|
74 { |
|
75 //message root entry |
|
76 TMsvEntry entry1; |
|
77 entry1.iType = KUidMsvMessageEntry; |
|
78 entry1.iServiceId = KMsvLocalServiceIndexEntryId; |
|
79 entry1.iMtm = KUidMsgTypeIMAP4; |
|
80 iServerEntry->SetEntry(aId); |
|
81 iServerEntry->CreateEntry(entry1); |
|
82 iServerEntry->SetEntry(entry1.Id()); |
|
83 iMsvMessageEntry=entry1.Id(); |
|
84 |
|
85 //folder entry |
|
86 TMsvEntry folder; |
|
87 folder.iType = KUidMsvFolderEntry; |
|
88 folder.iMtm = KUidMsvLocalServiceMtm; |
|
89 folder.iServiceId = KMsvLocalServiceIndexEntryId; |
|
90 iServerEntry->SetEntry(iMsvMessageEntry); |
|
91 iServerEntry->CreateEntry(folder); |
|
92 iServerEntry->SetEntry(folder.Id()); |
|
93 iFolderId=folder.Id(); |
|
94 |
|
95 //body entry |
|
96 TMsvEntry bodyentry; |
|
97 bodyentry.iType = KUidMsvEmailTextEntry; |
|
98 bodyentry.iServiceId = KMsvLocalServiceIndexEntryId; |
|
99 bodyentry.iMtm = KUidMsgTypeIMAP4; |
|
100 bodyentry.iDetails.Set(KBodyDetails); |
|
101 iServerEntry->SetEntry(iFolderId); |
|
102 iServerEntry->CreateEntry(bodyentry); |
|
103 iServerEntry->SetEntry(bodyentry.Id()); |
|
104 iBodyMessageEntry=bodyentry.Id(); |
|
105 } |
|
106 |
|
107 |
|
108 void CTestImapFetchBody::SetupL() |
|
109 { |
|
110 ASSERT(iInputStream == NULL); |
|
111 ASSERT(iOutputStream == NULL); |
|
112 ASSERT(iActiveWaiter == NULL); |
|
113 ASSERT(iImapSession == NULL); |
|
114 ASSERT(iMsvServer == NULL); |
|
115 |
|
116 //clear the messaging folder |
|
117 CEmailTestUtils* testUtils; |
|
118 testUtils = CEmailTestUtils::NewL(test); |
|
119 CleanupStack::PushL(testUtils); |
|
120 testUtils->FileSession().SetSessionPath(KCDrive); |
|
121 |
|
122 // TODO: How to clean the message folders or close the messaging server without a PANIC ???? |
|
123 // testUtils->CleanMessageFolderL(); |
|
124 |
|
125 testUtils->ClearEmailAccountsL(); |
|
126 |
|
127 testUtils->CreateAllTestDirectories( ); |
|
128 testUtils->FileSession( ).SetSessionPath( _L( "C:\\" ) ); |
|
129 |
|
130 CleanupStack::PopAndDestroy(testUtils); |
|
131 |
|
132 iMsvServer = CMsvServer::NewL(); |
|
133 |
|
134 // wait a couple of seconds |
|
135 CTestTimer* timer = CTestTimer::NewL(); |
|
136 timer->After(5000000); |
|
137 CActiveScheduler::Start(); |
|
138 delete timer; |
|
139 iServerEntry = CMsvServerEntry::NewL(*iMsvServer, KMsvRootIndexEntryId); |
|
140 CImapUtils::CreateL(); |
|
141 iImapMailStore = CImapMailStore::NewL(*iServerEntry); |
|
142 iImapSettings = CImapSettings::NewL(*iServerEntry); |
|
143 |
|
144 iInputStream = CFakeInputStream::NewL(Logger()); |
|
145 iOutputStream = CFakeOutputStream::NewL(Logger()); |
|
146 iActiveWaiter = new(ELeave)CActiveWaiter(Logger()); |
|
147 iImapSession = CImapSession::NewL(*iImapSettings,*iImapMailStore,*iInputStream, *iOutputStream); |
|
148 |
|
149 //create the test environment |
|
150 CreateMessageStructureL(KMsvGlobalOutBoxIndexEntryIdValue); |
|
151 |
|
152 |
|
153 INFO_PRINTF1(_L("Setup: ServerGreeting")); |
|
154 iInputStream->ResetInputStrings(); |
|
155 iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n")); |
|
156 |
|
157 ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState()); |
|
158 |
|
159 iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus); |
|
160 iActiveWaiter->WaitActive(); |
|
161 |
|
162 INFO_PRINTF1(_L("...Login")); |
|
163 iInputStream->ResetInputStrings(); |
|
164 iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n")); |
|
165 |
|
166 iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password")); |
|
167 iActiveWaiter->WaitActive(); |
|
168 |
|
169 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
170 |
|
171 |
|
172 INFO_PRINTF1(_L("...Select inbox")); |
|
173 iInputStream->ResetInputStrings(); |
|
174 iInputStream->AppendInputStringL(_L8("2 OK [READ-WRITE] SELECT completed\r\n")); |
|
175 |
|
176 CImapFolderInfo* folderInfo = CImapFolderInfo::NewL(); |
|
177 CleanupStack::PushL(folderInfo); |
|
178 |
|
179 folderInfo->SetNameL(_L16("inbox")); |
|
180 CleanupStack::Pop();//folderInfo |
|
181 iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo); |
|
182 iActiveWaiter->WaitActive(); |
|
183 |
|
184 ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState()); |
|
185 ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo()); |
|
186 |
|
187 |
|
188 INFO_PRINTF1(_L("Setup: Complete")); |
|
189 } |
|
190 |
|
191 void CTestImapFetchBody::TearDownL() |
|
192 { |
|
193 delete iImapSession; |
|
194 iImapSession = NULL; |
|
195 |
|
196 delete iActiveWaiter; |
|
197 iActiveWaiter = NULL; |
|
198 |
|
199 delete iOutputStream; |
|
200 iOutputStream = NULL; |
|
201 |
|
202 delete iInputStream; |
|
203 iInputStream = NULL; |
|
204 |
|
205 delete iServerEntry; |
|
206 iServerEntry = NULL; |
|
207 |
|
208 delete iImapMailStore; |
|
209 iImapMailStore = NULL; |
|
210 |
|
211 delete iImapSettings; |
|
212 iImapSettings = NULL; |
|
213 |
|
214 delete iServerEntry; |
|
215 iServerEntry = NULL; |
|
216 |
|
217 CImapUtils::Delete(); |
|
218 |
|
219 delete iMsvServer; |
|
220 iMsvServer = NULL; |
|
221 } |
|
222 |
|
223 // Tests |
|
224 void CTestImapFetchBody::TestFetchBodyL() |
|
225 { |
|
226 INFO_PRINTF1(_L("TestFetchBodyL")); |
|
227 |
|
228 iInputStream->ResetInputStrings(); |
|
229 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BODY[1]<0> {19}\r\n")); |
|
230 iInputStream->AppendInputStringL(_L8("a small test body\r\n")); |
|
231 iInputStream->AppendInputStringL(_L8("UID 2717 FLAGS (\\Seen))\r\n")); |
|
232 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed\r\n")); |
|
233 |
|
234 //some test values for the info class |
|
235 _LIT8(KBodySection,"1"); |
|
236 const TDesC8& bodySection(KBodySection); |
|
237 TInt messageSize=19; |
|
238 |
|
239 //more test values |
|
240 TUint messageUid=45; |
|
241 TBool peek=ETrue; |
|
242 |
|
243 CFetchBodyInfo* iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
244 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
245 iFetchBodyInfo->SetIsText(ETrue); |
|
246 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
247 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
248 |
|
249 delete iFetchBodyResponse; |
|
250 iFetchBodyResponse = NULL; |
|
251 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
252 iImapSession->FetchBodyL(iActiveWaiter->iStatus,messageUid,peek,*iFetchBodyInfo, *iFetchBodyResponse); |
|
253 iActiveWaiter->WaitActive(); |
|
254 |
|
255 INFO_PRINTF1(_L("Complete")); |
|
256 } |
|
257 |
|
258 void CTestImapFetchBody::TestFetchBodyWithMimeL() |
|
259 { |
|
260 INFO_PRINTF1(_L("TestFetchBodyWithMimeL")); |
|
261 |
|
262 iInputStream->ResetInputStrings(); |
|
263 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BODY[1]<0> {10}\r\n")); |
|
264 iInputStream->AppendInputStringL(_L8("the end.\r\n")); |
|
265 iInputStream->AppendInputStringL(_L8(" BODY[1.MIME] {417}\r\n")); |
|
266 iInputStream->AppendInputStringL(_L8("From: \"pipex\" <mdgi05@imap.dial.pipex.com>\r\n")); |
|
267 iInputStream->AppendInputStringL(_L8("To: \"David Test Account\" <davids@msexchange2k.closedtest.intra>\r\n")); |
|
268 iInputStream->AppendInputStringL(_L8("Subject: t1\r\n")); |
|
269 iInputStream->AppendInputStringL(_L8("Date: Wed, 10 May 2006 10:23:50 +0100\r\n")); |
|
270 iInputStream->AppendInputStringL(_L8("MIME-Version: 1.0\r\n")); |
|
271 iInputStream->AppendInputStringL(_L8("Content-Type: text/plain;\r\n")); |
|
272 iInputStream->AppendInputStringL(_L8(" charset=\"iso-8859-1\"\r\n")); |
|
273 iInputStream->AppendInputStringL(_L8("Content-Transfer-Encoding: 7bit\r\n")); |
|
274 iInputStream->AppendInputStringL(_L8("X-Priority: 3\r\n")); |
|
275 iInputStream->AppendInputStringL(_L8("X-MSMail-Priority: Normal\r\n")); |
|
276 iInputStream->AppendInputStringL(_L8("X-Mailer: Microsoft Outlook Express 6.00.2800.1807\r\n")); |
|
277 iInputStream->AppendInputStringL(_L8("X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807\r\n")); |
|
278 iInputStream->AppendInputStringL(_L8(" UID 3120 FLAGS (\\Seen \\Draft))\r\n")); |
|
279 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n")); |
|
280 |
|
281 //some test values for the info class |
|
282 _LIT8(KBodySection,"1"); |
|
283 const TDesC8& bodySection(KBodySection); |
|
284 TInt messageSize=19; |
|
285 |
|
286 //more test values |
|
287 TUint messageUid=45; |
|
288 TBool peek=ETrue; |
|
289 |
|
290 delete iFetchBodyInfo; |
|
291 iFetchBodyInfo=NULL; |
|
292 iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
293 TImEncodingType encoding = EEncodingTypeNone; |
|
294 iFetchBodyInfo->SetCharsetId(KCharacterSetIdentifierAscii); |
|
295 iFetchBodyInfo->SetContentTransferEncoding(encoding); |
|
296 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
297 iFetchBodyInfo->SetIsText(ETrue); |
|
298 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
299 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
300 |
|
301 delete iFetchBodyResponse; |
|
302 iFetchBodyResponse = NULL; |
|
303 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
304 iImapSession->FetchBodyL(iActiveWaiter->iStatus,messageUid,peek,*iFetchBodyInfo, *iFetchBodyResponse); |
|
305 iActiveWaiter->WaitActive(); |
|
306 |
|
307 INFO_PRINTF1(_L("Complete")); |
|
308 } |
|
309 |
|
310 void CTestImapFetchBody::TestFetchBodyWithMime2L() |
|
311 { |
|
312 INFO_PRINTF1(_L("TestFetchBodyWithMime2L")); |
|
313 |
|
314 iInputStream->ResetInputStrings(); |
|
315 iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 3120 BODY[1]<0> {10}\r\n")); |
|
316 iInputStream->AppendInputStringL(_L8("the end.\r\n")); |
|
317 iInputStream->AppendInputStringL(_L8(" BODY[1.MIME] {417}\r\n")); |
|
318 iInputStream->AppendInputStringL(_L8("From: \"pipex\" <mdgi05@imap.dial.pipex.com>\r\n")); |
|
319 iInputStream->AppendInputStringL(_L8("To: \"David Test Account\" <davids@msexchange2k.closedtest.intra>\r\n")); |
|
320 iInputStream->AppendInputStringL(_L8("Subject: t1\r\n")); |
|
321 iInputStream->AppendInputStringL(_L8("Date: Wed, 10 May 2006 10:23:50 +0100\r\n")); |
|
322 iInputStream->AppendInputStringL(_L8("MIME-Version: 1.0\r\n")); |
|
323 iInputStream->AppendInputStringL(_L8("Content-Type: text/plain;\r\n")); |
|
324 iInputStream->AppendInputStringL(_L8(" charset=\"iso-8859-1\"\r\n")); |
|
325 iInputStream->AppendInputStringL(_L8("Content-Transfer-Encoding: 7bit\r\n")); |
|
326 iInputStream->AppendInputStringL(_L8("X-Priority: 3\r\n")); |
|
327 iInputStream->AppendInputStringL(_L8("X-MSMail-Priority: Normal\r\n")); |
|
328 iInputStream->AppendInputStringL(_L8("X-Mailer: Microsoft Outlook Express 6.00.2800.1807\r\n")); |
|
329 iInputStream->AppendInputStringL(_L8("X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807\r\n")); |
|
330 iInputStream->AppendInputStringL(_L8(" FLAGS (\\Seen \\Draft))\r\n")); |
|
331 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n")); |
|
332 |
|
333 //some test values for the info class |
|
334 _LIT8(KBodySection,"1"); |
|
335 const TDesC8& bodySection(KBodySection); |
|
336 TInt messageSize=19; |
|
337 |
|
338 //more test values |
|
339 TUint messageUid=45; |
|
340 TBool peek=ETrue; |
|
341 |
|
342 delete iFetchBodyInfo; |
|
343 iFetchBodyInfo=NULL; |
|
344 iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
345 TImEncodingType encoding = EEncodingTypeNone; |
|
346 iFetchBodyInfo->SetCharsetId(KCharacterSetIdentifierAscii); |
|
347 iFetchBodyInfo->SetContentTransferEncoding(encoding); |
|
348 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
349 iFetchBodyInfo->SetIsText(ETrue); |
|
350 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
351 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
352 |
|
353 delete iFetchBodyResponse; |
|
354 iFetchBodyResponse = NULL; |
|
355 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
356 iImapSession->FetchBodyL(iActiveWaiter->iStatus, messageUid, peek,*iFetchBodyInfo, *iFetchBodyResponse); |
|
357 iActiveWaiter->WaitActive(); |
|
358 |
|
359 INFO_PRINTF1(_L("Complete")); |
|
360 } |
|
361 |
|
362 // When server responses with no body length |
|
363 void CTestImapFetchBody::TestFetchBodyWithNoBodyLengthInServerResponseL() |
|
364 { |
|
365 INFO_PRINTF1(_L("TestFetchBodyWithNoBodyLengthInServerResponseL")); |
|
366 |
|
367 iInputStream->ResetInputStrings(); |
|
368 iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 3120 BODY[1]<0> \"text is written here\" BODY[1.MIME] {417}\r\n")); |
|
369 iInputStream->AppendInputStringL(_L8("From: \"pipex\" <mdgi05@imap.dial.pipex.com>\r\n")); |
|
370 iInputStream->AppendInputStringL(_L8("To: \"David Test Account\" <davids@msexchange2k.closedtest.intra>\r\n")); |
|
371 iInputStream->AppendInputStringL(_L8("Subject: t1\r\n")); |
|
372 iInputStream->AppendInputStringL(_L8("Date: Wed, 10 May 2006 10:23:50 +0100\r\n")); |
|
373 iInputStream->AppendInputStringL(_L8("MIME-Version: 1.0\r\n")); |
|
374 iInputStream->AppendInputStringL(_L8("Content-Type: text/plain;\r\n")); |
|
375 iInputStream->AppendInputStringL(_L8(" charset=\"iso-8859-1\"\r\n")); |
|
376 iInputStream->AppendInputStringL(_L8("Content-Transfer-Encoding: 7bit\r\n")); |
|
377 iInputStream->AppendInputStringL(_L8("X-Priority: 3\r\n")); |
|
378 iInputStream->AppendInputStringL(_L8("X-MSMail-Priority: Normal\r\n")); |
|
379 iInputStream->AppendInputStringL(_L8("X-Mailer: Microsoft Outlook Express 6.00.2800.1807\r\n")); |
|
380 iInputStream->AppendInputStringL(_L8("X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807\r\n")); |
|
381 iInputStream->AppendInputStringL(_L8(" FLAGS (\\Seen \\Draft))\r\n")); |
|
382 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n")); |
|
383 |
|
384 //some test values for the info class |
|
385 _LIT8(KBodySection,"1"); |
|
386 const TDesC8& bodySection(KBodySection); |
|
387 TInt messageSize=19; |
|
388 |
|
389 //more test values |
|
390 TUint messageUid=45; |
|
391 TBool peek=ETrue; |
|
392 |
|
393 delete iFetchBodyInfo; |
|
394 iFetchBodyInfo=NULL; |
|
395 iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
396 TImEncodingType encoding = EEncodingTypeNone; |
|
397 iFetchBodyInfo->SetCharsetId(KCharacterSetIdentifierAscii); |
|
398 iFetchBodyInfo->SetContentTransferEncoding(encoding); |
|
399 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
400 iFetchBodyInfo->SetIsText(ETrue); |
|
401 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
402 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
403 |
|
404 delete iFetchBodyResponse; |
|
405 iFetchBodyResponse = NULL; |
|
406 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
407 iImapSession->FetchBodyL(iActiveWaiter->iStatus, messageUid, peek,*iFetchBodyInfo, *iFetchBodyResponse); |
|
408 iActiveWaiter->WaitActive(); |
|
409 |
|
410 INFO_PRINTF1(_L("Complete")); |
|
411 } |
|
412 |
|
413 /** |
|
414 The server might explicitly state that there is no MIME data by using NIL |
|
415 */ |
|
416 void CTestImapFetchBody::TestFetchBodyWithNilMimeL() |
|
417 { |
|
418 INFO_PRINTF1(_L("TestFetchBodyWithNilMimeL")); |
|
419 |
|
420 iInputStream->ResetInputStrings(); |
|
421 iInputStream->AppendInputStringL(_L8("* 1 FETCH (FLAGS (\\Seen \\Draft)")); |
|
422 iInputStream->AppendInputStringL(_L8("UID 3120 BODY[1]<0> {10}\r\n")); |
|
423 iInputStream->AppendInputStringL(_L8("the end.\r\n")); |
|
424 iInputStream->AppendInputStringL(_L8(" BODY[1.MIME] nil)\r\n")); |
|
425 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n")); |
|
426 |
|
427 //some test values for the info class |
|
428 _LIT8(KBodySection,"1"); |
|
429 const TDesC8& bodySection(KBodySection); |
|
430 TInt messageSize=19; |
|
431 |
|
432 //more test values |
|
433 TUint messageUid=45; |
|
434 TBool peek=ETrue; |
|
435 |
|
436 delete iFetchBodyInfo; |
|
437 iFetchBodyInfo=NULL; |
|
438 iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
439 TImEncodingType encoding = EEncodingTypeNone; |
|
440 iFetchBodyInfo->SetCharsetId(KCharacterSetIdentifierAscii); |
|
441 iFetchBodyInfo->SetContentTransferEncoding(encoding); |
|
442 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
443 iFetchBodyInfo->SetIsText(ETrue); |
|
444 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
445 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
446 |
|
447 delete iFetchBodyResponse; |
|
448 iFetchBodyResponse = NULL; |
|
449 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
450 iImapSession->FetchBodyL(iActiveWaiter->iStatus, messageUid, peek, *iFetchBodyInfo, *iFetchBodyResponse); |
|
451 iActiveWaiter->WaitActive(); |
|
452 |
|
453 INFO_PRINTF1(_L("Complete")); |
|
454 } |
|
455 |
|
456 /** |
|
457 The server might explicitly state that there is no MIME data by using an empty string. |
|
458 This is what the WU server does. |
|
459 */ |
|
460 void CTestImapFetchBody::TestFetchBodyWithEmptyMimeL() |
|
461 { |
|
462 INFO_PRINTF1(_L("TestFetchBodyWithEmptyMimeL")); |
|
463 |
|
464 iInputStream->ResetInputStrings(); |
|
465 iInputStream->AppendInputStringL(_L8("* 1 FETCH (FLAGS (\\Seen \\Draft)")); |
|
466 iInputStream->AppendInputStringL(_L8("UID 3120 BODY[1]<0> {10}\r\n")); |
|
467 iInputStream->AppendInputStringL(_L8("the end.\r\n")); |
|
468 iInputStream->AppendInputStringL(_L8(" BODY[1.MIME] \"\")\r\n")); |
|
469 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n")); |
|
470 |
|
471 //some test values for the info class |
|
472 _LIT8(KBodySection,"1"); |
|
473 const TDesC8& bodySection(KBodySection); |
|
474 TInt messageSize=19; |
|
475 |
|
476 //more test values |
|
477 TUint messageUid=45; |
|
478 TBool peek=ETrue; |
|
479 |
|
480 delete iFetchBodyInfo; |
|
481 iFetchBodyInfo=NULL; |
|
482 iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
483 TImEncodingType encoding = EEncodingTypeNone; |
|
484 iFetchBodyInfo->SetCharsetId(KCharacterSetIdentifierAscii); |
|
485 iFetchBodyInfo->SetContentTransferEncoding(encoding); |
|
486 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
487 iFetchBodyInfo->SetIsText(ETrue); |
|
488 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
489 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
490 |
|
491 delete iFetchBodyResponse; |
|
492 iFetchBodyResponse = NULL; |
|
493 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
494 iImapSession->FetchBodyL(iActiveWaiter->iStatus, messageUid, peek, *iFetchBodyInfo, *iFetchBodyResponse); |
|
495 iActiveWaiter->WaitActive(); |
|
496 |
|
497 INFO_PRINTF1(_L("Complete")); |
|
498 } |
|
499 void CTestImapFetchBody::TestFetchBodyWithMimeZeroAngelBracketL() |
|
500 { |
|
501 INFO_PRINTF1(_L("TestFetchBodyWithMimeZeroAngelBracketL")); |
|
502 |
|
503 iInputStream->ResetInputStrings(); |
|
504 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BODY[1]<0> {10}\r\n")); |
|
505 iInputStream->AppendInputStringL(_L8("the end.\r\n")); |
|
506 iInputStream->AppendInputStringL(_L8(" BODY[1.MIME]<0> {417}\r\n")); |
|
507 iInputStream->AppendInputStringL(_L8("From: \"pipex\" <mdgi05@imap.dial.pipex.com>\r\n")); |
|
508 iInputStream->AppendInputStringL(_L8("To: \"David Test Account\" <davids@msexchange2k.closedtest.intra>\r\n")); |
|
509 iInputStream->AppendInputStringL(_L8("Subject: t1\r\n")); |
|
510 iInputStream->AppendInputStringL(_L8("Date: Wed, 10 May 2006 10:23:50 +0100\r\n")); |
|
511 iInputStream->AppendInputStringL(_L8("MIME-Version: 1.0\r\n")); |
|
512 iInputStream->AppendInputStringL(_L8("Content-Type: text/plain;\r\n")); |
|
513 iInputStream->AppendInputStringL(_L8(" charset=\"iso-8859-1\"\r\n")); |
|
514 iInputStream->AppendInputStringL(_L8("Content-Transfer-Encoding: 7bit\r\n")); |
|
515 iInputStream->AppendInputStringL(_L8("X-Priority: 3\r\n")); |
|
516 iInputStream->AppendInputStringL(_L8("X-MSMail-Priority: Normal\r\n")); |
|
517 iInputStream->AppendInputStringL(_L8("X-Mailer: Microsoft Outlook Express 6.00.2800.1807\r\n")); |
|
518 iInputStream->AppendInputStringL(_L8("X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807\r\n")); |
|
519 iInputStream->AppendInputStringL(_L8(" UID 3120 FLAGS (\\Seen \\Draft))\r\n")); |
|
520 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n")); |
|
521 |
|
522 //some test values for the info class |
|
523 _LIT8(KBodySection,"1"); |
|
524 const TDesC8& bodySection(KBodySection); |
|
525 TInt messageSize=19; |
|
526 |
|
527 //more test values |
|
528 TUint messageUid=45; |
|
529 TBool peek=ETrue; |
|
530 |
|
531 delete iFetchBodyInfo; |
|
532 iFetchBodyInfo=NULL; |
|
533 iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
534 TImEncodingType encoding = EEncodingTypeNone; |
|
535 iFetchBodyInfo->SetCharsetId(KCharacterSetIdentifierAscii); |
|
536 iFetchBodyInfo->SetContentTransferEncoding(encoding); |
|
537 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
538 iFetchBodyInfo->SetIsText(ETrue); |
|
539 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
540 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
541 |
|
542 delete iFetchBodyResponse; |
|
543 iFetchBodyResponse = NULL; |
|
544 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
545 iImapSession->FetchBodyL(iActiveWaiter->iStatus,messageUid,peek,*iFetchBodyInfo, *iFetchBodyResponse); |
|
546 iActiveWaiter->WaitActive(); |
|
547 |
|
548 INFO_PRINTF1(_L("Complete")); |
|
549 } |
|
550 |
|
551 void CTestImapFetchBody::TestFetchBodyWithCancelL() |
|
552 { |
|
553 INFO_PRINTF1(_L("TestFetchBodyWithCancelL")); |
|
554 |
|
555 iInputStream->ResetInputStrings(); |
|
556 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BODY[1]<0> {19}\r\n")); |
|
557 iInputStream->AppendInputStringL(_L8("a small test body\r\n")); |
|
558 |
|
559 iInputStream->NotifyWhenStreamIsEmpty(*this); |
|
560 |
|
561 //some test values for the info class |
|
562 _LIT8(KBodySection,"1"); |
|
563 const TDesC8& bodySection(KBodySection); |
|
564 TInt messageSize=19; |
|
565 |
|
566 //more test values |
|
567 TUint messageUid=45; |
|
568 TBool peek=ETrue; |
|
569 |
|
570 CFetchBodyInfo* iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
571 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
572 iFetchBodyInfo->SetIsText(ETrue); |
|
573 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
574 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
575 |
|
576 delete iFetchBodyResponse; |
|
577 iFetchBodyResponse = NULL; |
|
578 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
579 iImapSession->FetchBodyL(iActiveWaiter->iStatus,messageUid,peek,*iFetchBodyInfo, *iFetchBodyResponse); |
|
580 |
|
581 // OnInputStreamIsEmptyL will be called during WaitActive, causing FetchBodyL to be cancelled |
|
582 iActiveWaiter->WaitActive(KErrCancel); |
|
583 |
|
584 // Simulate the rest of the response being returned (after the cancel) |
|
585 iInputStream->ResetInputStrings(); |
|
586 iInputStream->AppendInputStringL(_L8("UID 2717 FLAGS (\\Seen))\r\n")); |
|
587 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed\r\n")); |
|
588 |
|
589 |
|
590 // Flush the rest of the response |
|
591 iImapSession->FlushCancelledCommand(iActiveWaiter->iStatus); |
|
592 iActiveWaiter->WaitActive(); |
|
593 |
|
594 // Response data should now be flushed. |
|
595 // Try to do a simple list command using the same input stream. |
|
596 iInputStream->ResetInputStrings(); |
|
597 iInputStream->AppendInputStringL(_L8("* LIST (\\UnMarked) \"/\" Drafts\r\n")); |
|
598 iInputStream->AppendInputStringL(_L8("* LIST (\\Marked) \"/\" INBOX\r\n")); |
|
599 iInputStream->AppendInputStringL(_L8("4 OK LIST completed\r\n")); |
|
600 |
|
601 RArrayImapListFolderInfo folderList; |
|
602 iImapSession->ListL(iActiveWaiter->iStatus, _L(""), _L("%"), folderList); |
|
603 iActiveWaiter->WaitActive(); |
|
604 |
|
605 ASSERT_EQUALS(folderList.Count(), 2); |
|
606 |
|
607 ASSERT_EQUALS(folderList[0]->iHierarchySeperator, (TChar)'/'); |
|
608 ASSERT_EQUALS(folderList[0]->FolderName(), _L16("Drafts")); |
|
609 ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::ENoinferiors)); |
|
610 ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::ENoselect)); |
|
611 ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::EMarked)); |
|
612 ASSERT_TRUE(folderList[0]->QueryFlag(CImapListFolderInfo::EUnmarked)); |
|
613 |
|
614 ASSERT_EQUALS(folderList[1]->iHierarchySeperator, (TChar)'/'); |
|
615 ASSERT_EQUALS(folderList[1]->FolderName(), _L16("INBOX")); |
|
616 ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::ENoinferiors)); |
|
617 ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::ENoselect)); |
|
618 ASSERT_TRUE(folderList[1]->QueryFlag(CImapListFolderInfo::EMarked)); |
|
619 ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::EUnmarked)); |
|
620 |
|
621 folderList.ResetAndDestroy(); |
|
622 |
|
623 INFO_PRINTF1(_L("Complete")); |
|
624 } |
|
625 |
|
626 |
|
627 // Tests |
|
628 void CTestImapFetchBody::TestFetchMultiChunkBodyL() |
|
629 { |
|
630 INFO_PRINTF1(_L("TestFetchMultiChunkBodyL")); |
|
631 |
|
632 |
|
633 iInputStream->ResetInputStrings(); |
|
634 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BODY[1] {19}\r\n")); |
|
635 iInputStream->AppendInputStringL(_L8("a small test body\r\n")); |
|
636 iInputStream->AppendInputStringL(_L8("UID 2717 FLAGS (\\Seen))\r\n")); |
|
637 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed\r\n")); |
|
638 |
|
639 //some test values for the info class |
|
640 _LIT8(KBodySection,"1"); |
|
641 const TDesC8& bodySection(KBodySection); |
|
642 TInt messageSize=19; |
|
643 |
|
644 //more test values |
|
645 TUint messageUid=45; |
|
646 TBool peek=ETrue; |
|
647 |
|
648 CFetchBodyInfo* fetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
649 TImEncodingType encoding = EEncodingTypeNone; |
|
650 fetchBodyInfo->SetCharsetId(KCharacterSetIdentifierAscii); |
|
651 fetchBodyInfo->SetContentTransferEncoding(encoding); |
|
652 fetchBodyInfo->SetSizeToFetch(messageSize); |
|
653 fetchBodyInfo->SetIsText(ETrue); |
|
654 fetchBodyInfo->SetRelativePathL(bodySection); |
|
655 fetchBodyInfo->SetBodyPartRemainingSize(0); |
|
656 |
|
657 delete iFetchBodyResponse; |
|
658 iFetchBodyResponse = NULL; |
|
659 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
660 iImapSession->FetchBodyL(iActiveWaiter->iStatus,messageUid,peek,*fetchBodyInfo, *iFetchBodyResponse); |
|
661 delete fetchBodyInfo; |
|
662 |
|
663 iActiveWaiter->WaitActive(); |
|
664 |
|
665 INFO_PRINTF1(_L("Complete")); |
|
666 } |
|
667 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT) |
|
668 void CTestImapFetchBody::TestFetchBinaryBodyL() |
|
669 { |
|
670 INFO_PRINTF1(_L("TestFetchBinaryBodyL")); |
|
671 |
|
672 iInputStream->ResetInputStrings(); |
|
673 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BINARY[1]<0> {19}\r\n")); |
|
674 iInputStream->AppendInputStringL(_L8("a small test body\r\n")); |
|
675 iInputStream->AppendInputStringL(_L8("UID 2717 FLAGS (\\Seen))\r\n")); |
|
676 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed\r\n")); |
|
677 |
|
678 //some test values for the info class |
|
679 _LIT8(KBodySection,"1"); |
|
680 const TDesC8& bodySection(KBodySection); |
|
681 TInt messageSize=19; |
|
682 |
|
683 //more test values |
|
684 TUint messageUid=45; |
|
685 TBool peek=ETrue; |
|
686 |
|
687 // Set BINARY capability |
|
688 CImapCapabilityInfo& capabilityInfo = const_cast<CImapCapabilityInfo&>(iImapSession->CapabilityInfo()); |
|
689 capabilityInfo.SetFlag(CImapCapabilityInfo::EBinaryCap, ETrue); |
|
690 |
|
691 CFetchBodyInfo* iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
692 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
693 iFetchBodyInfo->SetIsText(ETrue); |
|
694 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
695 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
696 |
|
697 delete iFetchBodyResponse; |
|
698 iFetchBodyResponse = NULL; |
|
699 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
700 iImapSession->FetchBodyL(iActiveWaiter->iStatus,messageUid,peek,*iFetchBodyInfo, *iFetchBodyResponse); |
|
701 iActiveWaiter->WaitActive(); |
|
702 |
|
703 INFO_PRINTF1(_L("Complete")); |
|
704 } |
|
705 |
|
706 void CTestImapFetchBody::TestFetchBinaryBodyWithCancelL() |
|
707 { |
|
708 INFO_PRINTF1(_L("TestFetchBinaryBodyWithCancelL")); |
|
709 |
|
710 iInputStream->ResetInputStrings(); |
|
711 iInputStream->AppendInputStringL(_L8("* 1 FETCH (BINARY[1]<0> {19}\r\n")); |
|
712 iInputStream->AppendInputStringL(_L8("a small test body\r\n")); |
|
713 |
|
714 iInputStream->NotifyWhenStreamIsEmpty(*this); |
|
715 |
|
716 //some test values for the info class |
|
717 _LIT8(KBodySection,"1"); |
|
718 const TDesC8& bodySection(KBodySection); |
|
719 TInt messageSize=19; |
|
720 |
|
721 //more test values |
|
722 TUint messageUid=45; |
|
723 TBool peek=ETrue; |
|
724 |
|
725 // Set BINARY capability |
|
726 CImapCapabilityInfo& capabilityInfo = const_cast<CImapCapabilityInfo&>(iImapSession->CapabilityInfo()); |
|
727 capabilityInfo.SetFlag(CImapCapabilityInfo::EBinaryCap, ETrue); |
|
728 |
|
729 CFetchBodyInfo* iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry); |
|
730 iFetchBodyInfo->SetSizeToFetch(messageSize); |
|
731 iFetchBodyInfo->SetIsText(ETrue); |
|
732 iFetchBodyInfo->SetRelativePathL(bodySection); |
|
733 iFetchBodyInfo->SetBodyPartRemainingSize(0); |
|
734 |
|
735 delete iFetchBodyResponse; |
|
736 iFetchBodyResponse = NULL; |
|
737 iFetchBodyResponse = CImapFetchBodyResponse::NewL(); |
|
738 iImapSession->FetchBodyL(iActiveWaiter->iStatus,messageUid,peek,*iFetchBodyInfo, *iFetchBodyResponse); |
|
739 |
|
740 // OnInputStreamIsEmptyL will be called during WaitActive, causing FetchBodyL to be cancelled |
|
741 iActiveWaiter->WaitActive(KErrCancel); |
|
742 |
|
743 // Simulate the rest of the response being returned (after the cancel) |
|
744 iInputStream->ResetInputStrings(); |
|
745 iInputStream->AppendInputStringL(_L8("UID 2717 FLAGS (\\Seen))\r\n")); |
|
746 iInputStream->AppendInputStringL(_L8("3 OK FETCH completed\r\n")); |
|
747 |
|
748 |
|
749 // Flush the rest of the response |
|
750 iImapSession->FlushCancelledCommand(iActiveWaiter->iStatus); |
|
751 iActiveWaiter->WaitActive(); |
|
752 |
|
753 // Response data should now be flushed. |
|
754 // Try to do a simple list command using the same input stream. |
|
755 iInputStream->ResetInputStrings(); |
|
756 iInputStream->AppendInputStringL(_L8("* LIST (\\UnMarked) \"/\" Drafts\r\n")); |
|
757 iInputStream->AppendInputStringL(_L8("* LIST (\\Marked) \"/\" INBOX\r\n")); |
|
758 iInputStream->AppendInputStringL(_L8("4 OK LIST completed\r\n")); |
|
759 |
|
760 RArrayImapListFolderInfo folderList; |
|
761 iImapSession->ListL(iActiveWaiter->iStatus, _L(""), _L("%"), folderList); |
|
762 iActiveWaiter->WaitActive(); |
|
763 |
|
764 ASSERT_EQUALS(folderList.Count(), 2); |
|
765 |
|
766 ASSERT_EQUALS(folderList[0]->iHierarchySeperator, (TChar)'/'); |
|
767 ASSERT_EQUALS(folderList[0]->FolderName(), _L16("Drafts")); |
|
768 ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::ENoinferiors)); |
|
769 ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::ENoselect)); |
|
770 ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::EMarked)); |
|
771 ASSERT_TRUE(folderList[0]->QueryFlag(CImapListFolderInfo::EUnmarked)); |
|
772 |
|
773 ASSERT_EQUALS(folderList[1]->iHierarchySeperator, (TChar)'/'); |
|
774 ASSERT_EQUALS(folderList[1]->FolderName(), _L16("INBOX")); |
|
775 ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::ENoinferiors)); |
|
776 ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::ENoselect)); |
|
777 ASSERT_TRUE(folderList[1]->QueryFlag(CImapListFolderInfo::EMarked)); |
|
778 ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::EUnmarked)); |
|
779 |
|
780 folderList.ResetAndDestroy(); |
|
781 |
|
782 INFO_PRINTF1(_L("Complete")); |
|
783 } |
|
784 #endif |
|
785 |
|
786 void CTestImapFetchBody::OnInputStreamIsEmptyL() |
|
787 { |
|
788 iActiveWaiter->CancelWaitActive(*this); |
|
789 } |
|
790 |
|
791 void CTestImapFetchBody::DoCancel() |
|
792 { |
|
793 iImapSession->Cancel(); |
|
794 } |
|
795 |
|
796 CTestSuite* CTestImapFetchBody::CreateSuiteL(const TDesC& aName) |
|
797 // static |
|
798 { |
|
799 SUB_SUITE; |
|
800 ADD_ASYNC_TEST_STEP(TestFetchBodyL); |
|
801 ADD_ASYNC_TEST_STEP(TestFetchBodyWithCancelL); |
|
802 // ADD_ASYNC_TEST_STEP(TestFetchMultiChunkBodyL); |
|
803 ADD_ASYNC_TEST_STEP(TestFetchBodyWithMimeL); |
|
804 ADD_ASYNC_TEST_STEP(TestFetchBodyWithMimeZeroAngelBracketL); |
|
805 ADD_ASYNC_TEST_STEP(TestFetchBodyWithMime2L); |
|
806 ADD_ASYNC_TEST_STEP(TestFetchBodyWithNoBodyLengthInServerResponseL); |
|
807 ADD_ASYNC_TEST_STEP(TestFetchBodyWithNilMimeL); |
|
808 ADD_ASYNC_TEST_STEP(TestFetchBodyWithEmptyMimeL); |
|
809 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT) |
|
810 // repeate the above test cases using FETCH BINARY |
|
811 ADD_ASYNC_TEST_STEP(TestFetchBinaryBodyL); |
|
812 ADD_ASYNC_TEST_STEP(TestFetchBinaryBodyWithCancelL); |
|
813 #endif |
|
814 END_SUITE; |
|
815 } |