Ejemplo n.º 1
0
TEST(AsyncEmailWriterTest, TestMissingFile)
{
	Email email;
	InitEmail(email);
	
	fprintf(stderr, "Testing missing part file\n");
	
	MojRefCountedPtr<AsyncEmailWriter> writer( new AsyncEmailWriter(email) );

	// Create a body part
	EmailPartList partList;
	partList.push_back( CreateBodyPart("does-not-exist") );
	writer->SetPartList(partList);

	MojRefCountedPtr<ByteBufferOutputStream> bbos( new ByteBufferOutputStream() );
	writer->SetOutputStream(bbos);

	boost::shared_ptr<MockAsyncIOChannelFactory> ioFactory( new MockAsyncIOChannelFactory() );
	writer->SetAsyncIOChannelFactory(ioFactory);
	
	MojRefCountedPtr<AsyncEmailWriterResult> writeResult(new AsyncEmailWriterResult());
	writer->WriteEmail(writeResult->GetSlot());
	
	// Make sure it's done writing
	ASSERT_TRUE( writeResult->Done() );

	// Should have reported an exception
	ASSERT_TRUE( writeResult->GetException() );
}
Ejemplo n.º 2
0
void TestWriteEmail(int numAttachments)
{
	Email email;
	InitEmail(email);
	
	MojRefCountedPtr<AsyncEmailWriter> writer( new AsyncEmailWriter(email) );
	
	// Create a body part
	EmailPartList partList;
	partList.push_back( CreateBodyPart("test1") );
	
	// Create some attachments
	for(int i = 0; i < numAttachments; i++) {
		std::stringstream name;
		name << "attach" << i;
		
		EmailPartPtr attachmentPart( new EmailPart(EmailPart::ATTACHMENT) );
		attachmentPart->SetLocalFilePath(name.str());
		partList.push_back(attachmentPart);
	}
	writer->SetPartList(partList);
	
	// Set up a fake file "test1" in our mock factory
	boost::shared_ptr<MockAsyncIOChannelFactory> ioFactory( new MockAsyncIOChannelFactory() );
	writer->SetAsyncIOChannelFactory(ioFactory);
	ioFactory->SetFileData("test1", "Email body");
	
	// Make some fake attachments
	for(int i = 0; i < numAttachments; i++) {
		std::stringstream name, data;
		name << "attach" << i;
		data << "Attachment data " << i;
		ioFactory->SetFileData(name.str().c_str(), data.str());
	}
	
	std::string output;
	WriteEmail(writer, output);
	
	//fprintf(stderr, "Email:\n%s\n", output.c_str());
}
Ejemplo n.º 3
0
void EmailAdapter::ParseParts(const MojObject& partsArray, EmailPartList& partList)
{
	MojObject::ConstArrayIterator it = partsArray.arrayBegin();

	for (; it != partsArray.arrayEnd(); ++it) {
		const MojObject& partObj = *it;

		EmailPartPtr emailPart = ParseEmailPart(partObj);

		// Add to the part list
		partList.push_back(emailPart);
	}
}