Exemplo n.º 1
0
	// For Apple iCloud/Exchange IMAP server
	void testContinueReqWithoutSpace()
	{
		// continue_req   ::= "+" SPACE (resp_text / base64)
		//
		// Some servers do not send SPACE when response text is empty.
		// IMAP parser should allow this in non-strict mode.
		//
		// Eg:
		//
		//   C: a002 AUTHENTICATE xxx[CR][LF]
		//   S: +[CR][LF]

		vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
		vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();

		vmime::shared_ptr <vmime::net::imap::IMAPTag> tag =
				vmime::make_shared <vmime::net::imap::IMAPTag>();

		socket->localSend("+\r\n");

		vmime::shared_ptr <vmime::net::imap::IMAPParser> parser =
				vmime::make_shared <vmime::net::imap::IMAPParser>
						(tag, vmime::dynamicCast <vmime::net::socket>(socket), toh);

		parser->setStrict(false);
		VASSERT_NO_THROW("non-strict mode", parser->readResponse());

		++(*tag);

		socket->localSend("+\r\n");

		parser->setStrict(true);
		VASSERT_THROW("strict mode", parser->readResponse(), vmime::exceptions::invalid_response);
	}
Exemplo n.º 2
0
	// When an IMAP4 client sends a FETCH (bodystructure) request to a server
	// that is running the Exchange Server 2007 IMAP4 service, a corrupted
	// response is sent as a reply
	// --> http://support.microsoft.com/kb/975918/en-us
	void testNILValueInBodyFldEnc()
	{
		vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
		vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();

		vmime::shared_ptr <vmime::net::imap::IMAPTag> tag =
				vmime::make_shared <vmime::net::imap::IMAPTag>();

		const char* resp = "* 7970 FETCH (UID 8036 FLAGS () BODYSTRUCTURE (\"text\" \"html\" (\"charset\" \"utf-8\") NIL NIL NIL 175501 1651 NIL NIL NIL NIL) RFC822.HEADER {3}\r\nx\r\n)\r\na001 OK FETCH complete\r\n";

		socket->localSend(resp);

		vmime::shared_ptr <vmime::net::imap::IMAPParser> parser =
			vmime::make_shared <vmime::net::imap::IMAPParser>();

		parser->setTag(tag);
		parser->setSocket(socket);
		parser->setTimeoutHandler(toh);

		parser->setStrict(false);
		VASSERT_NO_THROW("non-strict mode", parser->readResponse());

		++(*tag);

		socket->localSend(resp);

		parser->setStrict(true);
		VASSERT_THROW("strict mode", parser->readResponse(), vmime::exceptions::invalid_response);
	}
Exemplo n.º 3
0
	VMIME_TEST_LIST_END


	// For Apple iCloud IMAP server
	void testExtraSpaceInCapaResponse()
	{
		vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
		vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();

		vmime::shared_ptr <vmime::net::imap::IMAPTag> tag =
			vmime::make_shared <vmime::net::imap::IMAPTag>();

		socket->localSend(
			"* CAPABILITY IMAP4rev1 AUTH=ATOKEN AUTH=PLAIN \r\n"  // extra space at end
			"a001 OK Capability completed.\r\n");

		vmime::shared_ptr <vmime::net::imap::IMAPParser> parser =
			vmime::make_shared <vmime::net::imap::IMAPParser>
				(tag, vmime::dynamicCast <vmime::net::socket>(socket), toh);

		parser->setStrict(false);
		VASSERT_NO_THROW("non-strict mode", parser->readResponse(/* literalHandler */ NULL));

		++(*tag);

		socket->localSend(
			"* CAPABILITY IMAP4rev1 AUTH=ATOKEN AUTH=PLAIN \r\n"  // extra space at end
			"a002 OK Capability completed.\r\n");

		parser->setStrict(true);
		VASSERT_THROW("strict mode", parser->readResponse(/* literalHandler */ NULL), vmime::exceptions::invalid_response);
	}
Exemplo n.º 4
0
	void testSize_NoChunking()
	{
		vmime::shared_ptr <vmime::net::session> session =
			vmime::make_shared <vmime::net::session>();

		vmime::shared_ptr <vmime::net::transport> tr = session->getTransport
			(vmime::utility::url("smtp://localhost"));

		tr->setSocketFactory(vmime::make_shared <testSocketFactory <bigMessageSMTPTestSocket <false> > >());
		tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>());

		tr->connect();

		VASSERT("Test server should report it supports the SIZE extension!",
			vmime::dynamicCast <vmime::net::smtp::SMTPTransport>(tr)->getConnection()->hasExtension("SIZE"));

		vmime::mailbox exp("*****@*****.**");

		vmime::mailboxList recips;
		recips.appendMailbox(vmime::make_shared <vmime::mailbox>("*****@*****.**"));

		vmime::shared_ptr <vmime::message> msg = vmime::make_shared <SMTPBigTestMessage4MB>();

		VASSERT_THROW("Connection", tr->send(msg, exp, recips),
			vmime::net::smtp::SMTPMessageSizeExceedsMaxLimitsException);
	}
Exemplo n.º 5
0
	void testConnectToInvalidServer()
	{
		vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create();

		vmime::utility::url url("pop3://invalid-pop3-server");
		vmime::shared_ptr <vmime::net::store> store = sess->getStore(url);

		VASSERT_THROW("connect", store->connect(), vmime::exceptions::connection_error);
	}
	VMIME_TEST_LIST_END


	// resetImportance

	void testResetImportance()
	{
		vmime::ref <vmime::header> hdr = vmime::create <vmime::header>();

		hdr->getField("Importance")->setValue("xxx");
		hdr->getField("X-Priority")->setValue("yyy");

		VASSERT_NO_THROW("1", hdr->findField("Importance"));
		VASSERT_NO_THROW("2", hdr->findField("X-Priority"));

		vmime::misc::importanceHelper::resetImportanceHeader(hdr);

		VASSERT_THROW("3", hdr->findField("Importance"), vmime::exceptions::no_such_field);
		VASSERT_THROW("4", hdr->findField("X-Priority"), vmime::exceptions::no_such_field);
	}
Exemplo n.º 7
0
	VMIME_TEST_LIST_END


	void testConnectToInvalidServer()
	{
		vmime::shared_ptr <vmime::net::session> sess
			= vmime::make_shared <vmime::net::session>();

		vmime::utility::url url("smtp://invalid-smtp-server");
		vmime::shared_ptr <vmime::net::transport> store = sess->getTransport(url);

		VASSERT_THROW("connect", store->connect(), vmime::exceptions::connection_error);
	}
Exemplo n.º 8
0
	void testGreetingError()
	{
		vmime::shared_ptr <vmime::net::session> session =
			vmime::make_shared <vmime::net::session>();

		vmime::shared_ptr <vmime::net::transport> tr = session->getTransport
			(vmime::utility::url("smtp://localhost"));

		tr->setSocketFactory(vmime::make_shared <testSocketFactory <greetingErrorSMTPTestSocket> >());
		tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>());

		VASSERT_THROW("Connection", tr->connect(),
			vmime::exceptions::connection_greeting_error);
	}
Exemplo n.º 9
0
	void testIncompleteMultiLineResponse()
	{
		std::shared_ptr<testSocket> socket =
			vmime::factory<testSocket>::create();
		std::shared_ptr<vmime::net::timeoutHandler> toh =
			vmime::factory<testTimeoutHandler>::create(1);

		socket->localSend
		(
			"123-Response\r\n"
			"123-Text\r\n"
			// Missing data
		);

		VASSERT_THROW("Incomplete response",
			vmime::net::smtp::SMTPResponse::readResponse(socket, toh),
			vmime::exceptions::operation_timed_out);
	}
	void testIncompleteMultiLineResponse()
	{
		vmime::ref <testSocket> socket = vmime::create <testSocket>();
		vmime::ref <vmime::net::timeoutHandler> toh =
			vmime::create <testTimeoutHandler>(1);

		socket->localSend
		(
			"123-Response\r\n"
			"123-Text\r\n"
			// Missing data
		);

		vmime::net::smtp::SMTPResponse::state responseState;

		VASSERT_THROW("Incomplete response",
			vmime::net::smtp::SMTPResponse::readResponse(socket, toh, responseState),
			vmime::exceptions::operation_timed_out);
	}
Exemplo n.º 11
0
	VMIME_TEST_LIST_END


	void testBadValueType()
	{
		vmime::headerFieldFactory *hfactory = vmime::headerFieldFactory::getInstance();

		// "To" header field accepts values of type "addressList"
		vmime::ref <vmime::headerField> to = hfactory->create(vmime::fields::TO);
		VASSERT_THROW("to",
			to->setValue(vmime::mailbox("*****@*****.**")),
			vmime::exceptions::bad_field_value_type);

		// Unregistered header field accepts any value type
		vmime::ref <vmime::headerField> custom = hfactory->create("X-MyCustomHeader");
		VASSERT_NO_THROW("custom/1",
			custom->setValue(vmime::mailbox("*****@*****.**")));
		VASSERT_NO_THROW("custom/2",
			custom->setValue(vmime::text("field value text")));
	}