email/imap4mtm/imapsession/test/src/ctestimapfetchsinglebodystructure.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 "ctestimapfetchsinglebodystructure.h"
       
    17 
       
    18 #include "cfakeinputstream.h"
       
    19 #include "cfakeoutputstream.h"
       
    20 #include "cactivewaiter.h"
       
    21 
       
    22 #include "moutputstream.h"
       
    23 #include "cimapsession.h"
       
    24 #include "cimapfolderinfo.h"
       
    25 
       
    26 #include "cimapfetchresponse.h"
       
    27 #include "cimaprfc822headerfields.h"
       
    28 #include "cimapbodystructure.h"
       
    29 
       
    30 CTestImapFetchSingleBodyStructure::CTestImapFetchSingleBodyStructure()
       
    31 	{}
       
    32 
       
    33 CTestImapFetchSingleBodyStructure::~CTestImapFetchSingleBodyStructure()
       
    34 	{}
       
    35 
       
    36 TBool CTestImapFetchSingleBodyStructure::DescriptorsMatch(const TDesC8& aFirst, const TDesC8& aSecond)
       
    37 	{
       
    38 	return (aFirst == aSecond);
       
    39 	}
       
    40 
       
    41 // Tests
       
    42 void CTestImapFetchSingleBodyStructure::TestTextBodyFetchL()
       
    43 	{
       
    44 	INFO_PRINTF1(_L("TestTextBodyFetchL"));
       
    45 	
       
    46 	iInputStream->ResetInputStrings();
       
    47 	iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 284 FLAGS (\\Seen) BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"charset\" \"iso-8859-1\") NIL NIL \"7BIT\" 194 4 NIL NIL NIL) BODY[HEADER.FIELDS (Received Date Subject From)] {111}\r\n"));
       
    48 	iInputStream->AppendInputStringL(_L8("Date: Thu, 27 May 2004 14:57:46 +0100\r\n"));
       
    49 	iInputStream->AppendInputStringL(_L8("Subject: test_mail_1\r\n"));
       
    50 	iInputStream->AppendInputStringL(_L8("From: <matthewf@msexchange2k.closedtest.intra>\r\n"));
       
    51 	iInputStream->AppendInputStringL(_L8("\r\n"));
       
    52 	iInputStream->AppendInputStringL(_L8(")\r\n"));
       
    53 	iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n"));
       
    54 	/*
       
    55 	iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 284 FLAGS (\\Seen) BODY[HEADER.FIELDS (Received Date Subject From)] {111}\r\n"));
       
    56 	iInputStream->AppendInputStringL(_L8("Date: Thu, 27 May 2004 14:57:46 +0100\r\n"));
       
    57 	iInputStream->AppendInputStringL(_L8("Subject: test_mail_1\r\n"));
       
    58 	iInputStream->AppendInputStringL(_L8("From: <matthewf@msexchange2k.closedtest.intra>\r\n"));
       
    59 	iInputStream->AppendInputStringL(_L8("\r\n"));
       
    60 	iInputStream->AppendInputStringL(_L8(" BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"charset\" \"iso-8859-1\") NIL NIL \"7BIT\" 194 4 NIL NIL NIL))\r\n"));
       
    61 	iInputStream->AppendInputStringL(_L8("4 OK FETCH completed.\r\n"));
       
    62 	*/		
       
    63 	
       
    64 	TUint messageUid = 284;
       
    65 	CImapFetchResponse* fetchResponse = CImapFetchResponse::NewL();
       
    66 	CleanupStack::PushL(fetchResponse);
       
    67 	_LIT8(KFieldNames, "Received Date Subject From");
       
    68 	
       
    69 	iImapSession->FetchBodyStructureAndHeadersL(iActiveWaiter->iStatus, messageUid, KFieldNames, *fetchResponse);
       
    70 	iActiveWaiter->WaitActive();
       
    71 	
       
    72 	CImapRfc822HeaderFields* headerFields = fetchResponse->HeaderFields();
       
    73 	ASSERT_NOT_NULL(headerFields);
       
    74 				
       
    75 	TPtrC8 ptrReceived = headerFields->FieldValue(CImapRfc822HeaderFields::EImapReceived);
       
    76 	TPtrC8 ptrDate = headerFields->FieldValue(CImapRfc822HeaderFields::EImapDate);
       
    77 	TPtrC8 ptrSubject = headerFields->FieldValue(CImapRfc822HeaderFields::EImapSubject);
       
    78 	TPtrC8 ptrFrom = headerFields->FieldValue(CImapRfc822HeaderFields::EImapFrom);
       
    79 				
       
    80 	ASSERT_EQUALS(ptrReceived, _L8(""));
       
    81 	ASSERT_EQUALS(ptrDate, _L8("Thu, 27 May 2004 14:57:46 +0100"));
       
    82 	ASSERT_EQUALS(ptrSubject, _L8("test_mail_1"));
       
    83 	ASSERT_EQUALS(ptrFrom, _L8("<matthewf@msexchange2k.closedtest.intra>"));
       
    84 	
       
    85 	CImapBodyStructure* bodyStructure = fetchResponse->BodyStructure();
       
    86 	ASSERT_NOT_NULL(bodyStructure);
       
    87 	
       
    88 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->Type(), _L8("TEXT")));
       
    89 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->SubType(), _L8("PLAIN")));
       
    90 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->BodyEncoding(), _L8("7BIT")));
       
    91 	
       
    92 	ASSERT_EQUALS(fetchResponse->MessageUid(), messageUid);
       
    93 	ASSERT_TRUE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::ESeen));
       
    94 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EAnswered));
       
    95 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EFlagged));
       
    96 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EDeleted));
       
    97 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EDraft));
       
    98 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::ERecent));
       
    99 	
       
   100 	CImapFolderInfo* folderInfo = iImapSession->SelectedFolderInfo();
       
   101 	ASSERT_NOT_NULL(folderInfo);
       
   102 	ASSERT_FALSE(folderInfo->MessageFlagsChanged());
       
   103 						
       
   104 	CleanupStack::PopAndDestroy(fetchResponse);
       
   105 	
       
   106 	INFO_PRINTF1(_L("Complete"));
       
   107 	}
       
   108 	
       
   109 	//new
       
   110 void CTestImapFetchSingleBodyStructure::TestBasicBodyFetchL()
       
   111 	{
       
   112 	INFO_PRINTF1(_L("TestBasicBodyFetchL"));
       
   113 	
       
   114 	iInputStream->ResetInputStrings();
       
   115 	iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 284 FLAGS (\\Seen) BODYSTRUCTURE (\"APPLICATION\" \"X-ZIP-COMPRESSED\" (\"name\" \" \") NIL NIL \"BASE64\" 13684 NIL (\"attachment\" (\"filename\" \" \")) NIL) BODY[HEADER.FIELDS (Received Date Subject From)] {111}\r\n"));
       
   116 	iInputStream->AppendInputStringL(_L8("Date: Thu, 27 May 2004 14:57:46 +0100\r\n"));
       
   117 	iInputStream->AppendInputStringL(_L8("Subject: test_mail_1\r\n"));
       
   118 	iInputStream->AppendInputStringL(_L8("From: <matthewf@msexchange2k.closedtest.intra>\r\n"));
       
   119 	iInputStream->AppendInputStringL(_L8("\r\n"));
       
   120 	iInputStream->AppendInputStringL(_L8(")\r\n"));
       
   121 	iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n"));
       
   122 		
       
   123 	TUint messageUid = 284;
       
   124 	CImapFetchResponse* fetchResponse = CImapFetchResponse::NewL();
       
   125 	CleanupStack::PushL(fetchResponse);
       
   126 	_LIT8(KFieldNames, "Received Date Subject From");
       
   127 	
       
   128 	iImapSession->FetchBodyStructureAndHeadersL(iActiveWaiter->iStatus, messageUid, KFieldNames, *fetchResponse);
       
   129 	iActiveWaiter->WaitActive();
       
   130 	
       
   131 	CImapRfc822HeaderFields* headerFields = fetchResponse->HeaderFields();
       
   132 	ASSERT_NOT_NULL(headerFields);
       
   133 				
       
   134 	TPtrC8 ptrReceived = headerFields->FieldValue(CImapRfc822HeaderFields::EImapReceived);
       
   135 	TPtrC8 ptrDate = headerFields->FieldValue(CImapRfc822HeaderFields::EImapDate);
       
   136 	TPtrC8 ptrSubject = headerFields->FieldValue(CImapRfc822HeaderFields::EImapSubject);
       
   137 	TPtrC8 ptrFrom = headerFields->FieldValue(CImapRfc822HeaderFields::EImapFrom);
       
   138 				
       
   139 	ASSERT_EQUALS(ptrReceived, _L8(""));
       
   140 	ASSERT_EQUALS(ptrDate, _L8("Thu, 27 May 2004 14:57:46 +0100"));
       
   141 	ASSERT_EQUALS(ptrSubject, _L8("test_mail_1"));
       
   142 	ASSERT_EQUALS(ptrFrom, _L8("<matthewf@msexchange2k.closedtest.intra>"));
       
   143 	
       
   144 	CImapBodyStructure* bodyStructure = fetchResponse->BodyStructure();
       
   145 	ASSERT_NOT_NULL(bodyStructure);
       
   146 	
       
   147 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->Type(), _L8("APPLICATION")));
       
   148 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->SubType(), _L8("X-ZIP-COMPRESSED")));
       
   149 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->BodyEncoding(), _L8("BASE64")));
       
   150 	
       
   151 	ASSERT_EQUALS(fetchResponse->MessageUid(), messageUid);
       
   152 	ASSERT_TRUE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::ESeen));
       
   153 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EAnswered));
       
   154 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EFlagged));
       
   155 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EDeleted));
       
   156 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EDraft));
       
   157 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::ERecent));
       
   158 	
       
   159 	CleanupStack::PopAndDestroy(fetchResponse);
       
   160 	
       
   161 	INFO_PRINTF1(_L("Complete"));
       
   162 	}
       
   163 	//new
       
   164 
       
   165 void CTestImapFetchSingleBodyStructure::TestMultipartL()
       
   166 	{
       
   167 	INFO_PRINTF1(_L("TestMultipartL"));
       
   168 	
       
   169 	iInputStream->ResetInputStrings();
       
   170 	iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 32475 FLAGS () BODYSTRUCTURE ((\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\") NIL NIL \"7BIT\" 9 1 NIL NIL NIL)(\"IMAGE\" \"JPEG\" (\"x-mac-type\" \"4A504547\" \"x-mac-creator\" \"4A565752\" \"name\" \"screen.jpg\") NIL NIL \"X-UUENCODE\" 201017 NIL (\"attachment\" (\"filename\" \"screen.jpg\")) NIL) \"mixed\" (\"boundary\" \"=====================_11834497==_\") NIL NIL) BODY[HEADER.FIELDS (Received Date Subject From Reply-to To Cc Bcc Message-ID Return-Receipt-To X-Return-Receipt-To Disposition-Notification-To Disposition-Notification-Options Priority X-Priority X-MSMail-Priority Importance Precedence)] {922}\r\n"));
       
   171 	iInputStream->AppendInputStringL(_L8("Received: from [127.0.0.1] ([10.23.179.168]) by lon-cn-exchng2k.msexchange2k.closedtest.intra with Microsoft SMTPSVC(5.0.2195.5329);\r\n"));
       
   172 	iInputStream->AppendInputStringL(_L8("\t Mon, 11 Jul 2005 15:41:16 +0100\r\n"));
       
   173 	iInputStream->AppendInputStringL(_L8("Received: from mx3.messagingengine.com (mx3.internal [10.202.2.202])\r\n"));
       
   174 	iInputStream->AppendInputStringL(_L8("\t by server2.messagingengine.com (Cyrus v2.3-alpha) with LMTPA;\r\n"));
       
   175 	iInputStream->AppendInputStringL(_L8("\t Tue, 05 Apr 2005 07:47:35 -0400\r\n"));
       
   176 	iInputStream->AppendInputStringL(_L8("Received: from smtp003.mail.ukl.yahoo.com (smtp003.mail.ukl.yahoo.com [217.12.11.34])\r\n"));
       
   177 	iInputStream->AppendInputStringL(_L8("\t\r\n"));
       
   178 	iInputStream->AppendInputStringL(_L8("by mx3.messagingengine.com (Postfix) with SMTP id A956E5A0CB3\r\n"));
       
   179  	iInputStream->AppendInputStringL(_L8("\tfor <l_luchford@fastmail.co.uk>; Tue,  5 Apr 2005 07:47:34 -0400 (EDT)\r\n"));
       
   180 	iInputStream->AppendInputStringL(_L8("Received: from unknown (HELO lon-leel03.yahoo.co.uk) (l?luchford@80.7.227.13 with login)\r\n"));
       
   181 	iInputStream->AppendInputStringL(_L8("  by smtp003.mail.ukl.yahoo.com with SMTP; 5 Apr 2005 11:47:22 -0000\r\n"));
       
   182 	iInputStream->AppendInputStringL(_L8("Date: Tue, 05 Apr 2005 12:47:19 +0100\r\n"));
       
   183 	iInputStream->AppendInputStringL(_L8("Subject:\r\n"));
       
   184 	iInputStream->AppendInputStringL(_L8("From: Lee Luchford <l_luchford@yahoo.co.uk>\r\n"));
       
   185 	iInputStream->AppendInputStringL(_L8("To: l_luchford@fastmail.co.uk\r\n"));
       
   186 	iInputStream->AppendInputStringL(_L8("Message-Id: <6.2.1.2.0.20050405124701.0274a008@pop.mail.yahoo.co.uk>\r\n"));
       
   187 	iInputStream->AppendInputStringL(_L8("\r\n"));
       
   188 	iInputStream->AppendInputStringL(_L8(")\r\n"));
       
   189 	iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n"));
       
   190 	
       
   191 	TUint messageUid = 32475;
       
   192 	CImapFetchResponse* fetchResponse = CImapFetchResponse::NewL();
       
   193 	CleanupStack::PushL(fetchResponse);
       
   194 	_LIT8(KFieldNames, "Received Date Subject From");
       
   195 	
       
   196 	iImapSession->FetchBodyStructureAndHeadersL(iActiveWaiter->iStatus, messageUid, KFieldNames, *fetchResponse);
       
   197 	iActiveWaiter->WaitActive();
       
   198 	
       
   199 	CImapRfc822HeaderFields* headerFields = fetchResponse->HeaderFields();
       
   200 	ASSERT_NOT_NULL(headerFields);
       
   201 	
       
   202 	TPtrC8 ptrReceived = headerFields->FieldValue(CImapRfc822HeaderFields::EImapReceived);
       
   203 	TPtrC8 ptrDate = headerFields->FieldValue(CImapRfc822HeaderFields::EImapDate);
       
   204 	TPtrC8 ptrSubject = headerFields->FieldValue(CImapRfc822HeaderFields::EImapSubject);
       
   205 	TPtrC8 ptrFrom = headerFields->FieldValue(CImapRfc822HeaderFields::EImapFrom);
       
   206 	TPtrC8 ptrMsgId = headerFields->FieldValue(CImapRfc822HeaderFields::EImapMessageId);
       
   207 	
       
   208 	ASSERT_EQUALS(ptrReceived, _L8("from unknown (HELO lon-leel03.yahoo.co.uk) (l?luchford@80.7.227.13 with login)  by smtp003.mail.ukl.yahoo.com with SMTP; 5 Apr 2005 11:47:22 -0000"));
       
   209 	ASSERT_EQUALS(ptrDate, _L8("Tue, 05 Apr 2005 12:47:19 +0100"));
       
   210 	ASSERT_EQUALS(ptrSubject, _L8(""));
       
   211 	ASSERT_EQUALS(ptrFrom, _L8("Lee Luchford <l_luchford@yahoo.co.uk>"));
       
   212 	ASSERT_EQUALS(ptrMsgId, _L8("<6.2.1.2.0.20050405124701.0274a008@pop.mail.yahoo.co.uk>"));
       
   213 	
       
   214 	CImapBodyStructure* bodyStructure = fetchResponse->BodyStructure();
       
   215 	ASSERT_NOT_NULL(bodyStructure);
       
   216 	
       
   217 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->Type(), _L8("MULTIPART")));
       
   218 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->SubType(), _L8("mixed")));
       
   219 	ASSERT_EQUALS(bodyStructure->BodyStructureType(), CImapBodyStructure::ETypeMultipart);
       
   220 	
       
   221 	ASSERT_EQUALS(bodyStructure->EmbeddedBodyStructureList().Count(), 2);
       
   222 	
       
   223 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->EmbeddedBodyStructureList()[0]->Type(), _L8("TEXT")));
       
   224 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->EmbeddedBodyStructureList()[0]->SubType(), _L8("PLAIN")));
       
   225 	ASSERT_EQUALS(bodyStructure->EmbeddedBodyStructureList()[0]->BodyStructureType(), CImapBodyStructure::ETypeText);
       
   226 	
       
   227 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->EmbeddedBodyStructureList()[1]->Type(), _L8("IMAGE")));
       
   228 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->EmbeddedBodyStructureList()[1]->SubType(), _L8("JPEG")));
       
   229 	ASSERT_EQUALS(bodyStructure->EmbeddedBodyStructureList()[1]->BodyStructureType(), CImapBodyStructure::ETypeBasic);
       
   230 		
       
   231 	ASSERT_EQUALS(fetchResponse->MessageUid(), messageUid);
       
   232 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::ESeen));
       
   233 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EAnswered));
       
   234 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EFlagged));
       
   235 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EDeleted));
       
   236 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::EDraft));
       
   237 	ASSERT_FALSE(fetchResponse->MessageFlagInfo().QueryFlag(TMessageFlagInfo::ERecent));
       
   238 	
       
   239 	CleanupStack::PopAndDestroy(fetchResponse);
       
   240 	
       
   241 	INFO_PRINTF1(_L("Complete"));
       
   242 	}
       
   243 	//new
       
   244 
       
   245 void CTestImapFetchSingleBodyStructure::TestRFC822BodyFetchL()
       
   246 	{
       
   247 	INFO_PRINTF1(_L("TestRFC822BodyFetchL"));
       
   248 	
       
   249 	iInputStream->ResetInputStrings();
       
   250 	iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 871 FLAGS (\\Seen) BODYSTRUCTURE (\"MESSAGE\" \"RFC822\" NIL NIL \"HTML Message with attachment - no images\" \"7bit\" 596 (\"Wed, 13 Oct 1999 12:11:11 +0100\" \"HTML Message with attachment - no images\" ((\"matthewf\" NIL \"matthewf\" \"msexchange2k.closedtest.intra\")) ((\"matthewf\" NIL \"matthewf\" \"msexchange2k.closedtest.intra\")) ((\"matthewf\" NIL \"matthewf\" \"msexchange2k.closedtest.intra\")) ((\"matthewf\" NIL \"matthewf\" \"msexchange2k.closedtest.intra\")) NIL NIL NIL \"<01fc01bf156b$a82fc490$5f0c970a@lon-kevalp.plc.psion.com>\") (\"TEXT\" \"PLAIN\" NIL NIL NIL \"8bit\" 0 0 NIL NIL NIL) 10 NIL (\"inline\" NIL) NIL) NIL NIL) BODY[HEADER.FIELDS (Received Date Subject From Reply-to To Cc Bcc Message-ID Return-Receipt-To X-Return-Receipt-To Disposition-Notification-To Disposition-Notification-Options Priority X-Priority X-MSMail-Priority Importance Precedence)] {111}\r\n"));
       
   251 	
       
   252 	iInputStream->AppendInputStringL(_L8("Date: Wed, 13 Oct 1999 12:11:11 +0100\r\n"));
       
   253 	iInputStream->AppendInputStringL(_L8("Subject: test_mail_1\r\n"));
       
   254 	iInputStream->AppendInputStringL(_L8("From: <matthewf@msexchange2k.closedtest.intra>\r\n"));
       
   255 	iInputStream->AppendInputStringL(_L8("\r\n"));
       
   256 	iInputStream->AppendInputStringL(_L8(")\r\n"));
       
   257 	iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n"));
       
   258 	
       
   259 	TUint messageUid = 596;
       
   260 	CImapFetchResponse* fetchResponse = CImapFetchResponse::NewL();
       
   261 	CleanupStack::PushL(fetchResponse);
       
   262 	_LIT8(KFieldNames, "Received Date Subject From Reply-to To Cc Bcc Message-ID Return-Receipt-To X-Return-Receipt-To Disposition-Notification-To Disposition-Notification-Options Priority X-Priority X-MSMail-Priority Importance Precedence");
       
   263 	
       
   264 	iImapSession->FetchBodyStructureAndHeadersL(iActiveWaiter->iStatus, messageUid, KFieldNames, *fetchResponse);
       
   265 	iActiveWaiter->WaitActive();
       
   266 	
       
   267 	CImapBodyStructure* bodyStructure = fetchResponse->BodyStructure();
       
   268 	ASSERT_NOT_NULL(bodyStructure);
       
   269 	
       
   270 
       
   271 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->Type(), _L8("MESSAGE")));
       
   272 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->SubType(), _L8("RFC822")));
       
   273 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->BodyDescription(), _L8("HTML Message with attachment - no images")));
       
   274 
       
   275 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->BodyId(), _L8("")));
       
   276 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->BodyEncoding(), _L8("7bit")));
       
   277 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->BodySizeOctets(), _L8("596")));
       
   278 	ASSERT_EQUALS(bodyStructure->ParameterList().Count(), 0);
       
   279  
       
   280 	// Check its envelope
       
   281 	CImapEnvelope& envelope = bodyStructure->GetRfc822EnvelopeStructureL();
       
   282 	ASSERT_TRUE(DescriptorsMatch(envelope.EnvDate(), _L8("Wed, 13 Oct 1999 12:11:11 +0100")));
       
   283 	ASSERT_TRUE(DescriptorsMatch(envelope.EnvSubject(), _L8("HTML Message with attachment - no images")));
       
   284 	ASSERT_EQUALS(envelope.EnvFrom().Count(), 1);
       
   285 	CheckAddressL(envelope.EnvFrom()[0], _L16("\"matthewf\" <matthewf@msexchange2k.closedtest.intra>"));
       
   286 
       
   287 	ASSERT_EQUALS(envelope.EnvSender().Count(), 1);
       
   288 	CheckAddressL(envelope.EnvSender()[0], _L16("\"matthewf\" <matthewf@msexchange2k.closedtest.intra>"));
       
   289 	ASSERT_EQUALS(envelope.EnvReplyTo().Count(), 1);
       
   290 	CheckAddressL(envelope.EnvReplyTo()[0], _L16("\"matthewf\" <matthewf@msexchange2k.closedtest.intra>"));
       
   291 	ASSERT_EQUALS(envelope.EnvTo().Count(), 1);
       
   292 	CheckAddressL(envelope.EnvTo()[0], _L16("\"matthewf\" <matthewf@msexchange2k.closedtest.intra>"));
       
   293 	ASSERT_EQUALS(envelope.EnvCc().Count(), 0);
       
   294 	ASSERT_EQUALS(envelope.EnvBcc().Count(), 0);	
       
   295 	ASSERT_TRUE(DescriptorsMatch(envelope.EnvInReplyTo(), _L8("")));
       
   296 	ASSERT_TRUE(DescriptorsMatch(envelope.EnvMessageId(), _L8("<01fc01bf156b$a82fc490$5f0c970a@lon-kevalp.plc.psion.com>")));
       
   297 	
       
   298 	// Check the embedded bodystructure
       
   299 	ASSERT_EQUALS(bodyStructure->EmbeddedBodyStructureList().Count(), 1);
       
   300 	CImapBodyStructure* bodyStructureEmbedded = bodyStructure->EmbeddedBodyStructureList()[0];
       
   301 	
       
   302 	ASSERT_TRUE(DescriptorsMatch(bodyStructureEmbedded->Type(), _L8("TEXT")));
       
   303 	ASSERT_TRUE(DescriptorsMatch(bodyStructureEmbedded->SubType(), _L8("PLAIN")));
       
   304 	ASSERT_EQUALS(bodyStructureEmbedded->ParameterList().Count(), 0);
       
   305  	ASSERT_TRUE(DescriptorsMatch(bodyStructureEmbedded->BodyId(), _L8("")));
       
   306 	ASSERT_TRUE(DescriptorsMatch(bodyStructureEmbedded->BodyDescription(), _L8("")));
       
   307 	ASSERT_TRUE(DescriptorsMatch(bodyStructureEmbedded->BodyEncoding(), _L8("8bit")));
       
   308 	ASSERT_TRUE(DescriptorsMatch(bodyStructureEmbedded->BodySizeOctets(), _L8("0")));
       
   309 	ASSERT_TRUE(DescriptorsMatch(bodyStructureEmbedded->BodyLines(), _L8("0")));
       
   310 	CleanupStack::PopAndDestroy(fetchResponse);
       
   311 	INFO_PRINTF1(_L("Complete"));
       
   312 	}
       
   313 	
       
   314 void CTestImapFetchSingleBodyStructure::TestPipexFetchL()
       
   315 	{
       
   316 	INFO_PRINTF1(_L("TestPipexFetchL"));
       
   317 
       
   318 	iInputStream->ResetInputStrings();	
       
   319 	iInputStream->AppendInputStringL(_L8("* 1 FETCH (UID 1361 FLAGS (\\Draft \\Seen) BODYSTRUCTURE (\"text\" \"plain\" (\"charset\" \"iso-8859-1\") NIL NIL \"7bit\" 1040 15 NIL NIL NIL) BODY[HEADER.FIELDS (\"Received\" \"Date\" \"Subject\" \"From\" \"Priority\" \"X-MSMail-Priority\")] {152}\r\n"));
       
   320 	iInputStream->AppendInputStringL(_L8("From: \"IMAP\" <davids@msexchange2k.closedtest.intra>\r\n"));
       
   321 	iInputStream->AppendInputStringL(_L8("Subject: message for test 4.2.2\r\n"));
       
   322 	iInputStream->AppendInputStringL(_L8("Date: Fri, 12 May 2006 09:34:30 +0100\r\n"));
       
   323 	iInputStream->AppendInputStringL(_L8("X-MSMail-Priority: Normal\r\n"));
       
   324 	iInputStream->AppendInputStringL(_L8(")\r\n"));
       
   325 	iInputStream->AppendInputStringL(_L8("3 OK FETCH completed.\r\n"));
       
   326 		
       
   327 	TUint messageUid = 1361;
       
   328 	CImapFetchResponse* fetchResponse = CImapFetchResponse::NewL();
       
   329 	CleanupStack::PushL(fetchResponse);
       
   330 	_LIT8(KFieldNames, "Received Date Subject From Priority X-MSMail-Priority");
       
   331 	
       
   332 	iImapSession->FetchBodyStructureAndHeadersL(iActiveWaiter->iStatus, messageUid, KFieldNames, *fetchResponse);
       
   333 	iActiveWaiter->WaitActive();
       
   334 	
       
   335 	CImapBodyStructure* bodyStructure = fetchResponse->BodyStructure();
       
   336 	ASSERT_NOT_NULL(bodyStructure);
       
   337 	
       
   338 	ASSERT_EQUALS(bodyStructure->BodyStructureType(), CImapBodyStructure::ETypeText);
       
   339 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->Type(), _L8("text")));
       
   340 	ASSERT_TRUE(DescriptorsMatch(bodyStructure->SubType(), _L8("plain")));
       
   341 	
       
   342 	CleanupStack::PopAndDestroy(fetchResponse);
       
   343 	INFO_PRINTF1(_L("Complete"));
       
   344 	}
       
   345 	
       
   346 void CTestImapFetchSingleBodyStructure::CheckAddressL(const CImapEnvelope::TAddress& aAddress, const TDesC16& aExpectedAddressString)
       
   347 	{
       
   348 	HBufC16* addressString = aAddress.CreateAddressStringL();
       
   349 	CleanupStack::PushL(addressString);
       
   350 	
       
   351 	ASSERT_EQUALS((TDesC16&)*addressString, aExpectedAddressString);
       
   352 	
       
   353 	CleanupStack::PopAndDestroy(addressString);
       
   354 	}
       
   355 	
       
   356 CTestSuite* CTestImapFetchSingleBodyStructure::CreateSuiteL(const TDesC& aName)
       
   357 // static
       
   358 	{
       
   359 	SUB_SUITE;
       
   360 	ADD_ASYNC_TEST_STEP(TestTextBodyFetchL);
       
   361 	ADD_ASYNC_TEST_STEP(TestBasicBodyFetchL);
       
   362 	ADD_ASYNC_TEST_STEP(TestRFC822BodyFetchL);
       
   363 	ADD_ASYNC_TEST_STEP(TestMultipartL);
       
   364 	ADD_ASYNC_TEST_STEP(TestPipexFetchL);
       
   365 	END_SUITE;
       
   366 	}