void testAddAttachment2() { vmime::string data = "Content-Type: multipart/mixed; boundary=\"foo\"\r\n" "\r\n" "--foo\r\n" "Content-Type: text/plain\r\n" "\r\n" "The text\r\n" "--foo\r\n" "Content-Type: application/octet-stream\r\n" "\r\n" "Blah\r\n" "--foo--\r\n" ""; vmime::ref <vmime::message> msg = vmime::create <vmime::message>(); msg->parse(data); vmime::ref <vmime::attachment> att = vmime::create <vmime::defaultAttachment> (vmime::create <vmime::stringContentHandler>("test"), vmime::mediaType("image/jpeg")); vmime::attachmentHelper::addAttachment(msg, att); VASSERT_EQ("1", "multipart/mixed[text/plain,application/octet-stream,image/jpeg]", getStructure(msg)); VASSERT_EQ("2", "The text", extractBodyContents(msg->getBody()->getPartAt(0))); VASSERT_EQ("3", "Blah", extractBodyContents(msg->getBody()->getPartAt(1))); VASSERT_EQ("4", "test", extractBodyContents(msg->getBody()->getPartAt(2))); }
void testAddAttachmentMessage1() { const vmime::string data = "Subject: Test message\r\n" "Content-Type: text/plain\r\n" "\r\n" "Message body"; std::shared_ptr<vmime::message> msg = vmime::factory<vmime::message>::create(); msg->parse(data); const vmime::string attData = "Subject: Attached message\r\n" "Content-Type: text/plain\r\n" "Content-Transfer-Encoding: base64\r\n" "\r\n" "QXR0YWNoZWQgbWVzc2FnZSBib2R5"; std::shared_ptr<vmime::message> amsg = vmime::factory<vmime::message>::create(); amsg->parse(attData); vmime::attachmentHelper::addAttachment(msg, amsg); VASSERT_EQ("1", "multipart/mixed[text/plain,message/rfc822]", getStructure(msg)); VASSERT_EQ("2", "Message body", extractBodyContents(msg->getBody()->getPartAt(0))); // Ensure message has been encoded properly std::shared_ptr<const vmime::bodyPart> attPart = msg->getBody()->getPartAt(1); std::shared_ptr<const vmime::contentHandler> attCth = attPart->getBody()->getContents(); vmime::string attDataOut; vmime::utility::outputStreamStringAdapter attDataOutOs(attDataOut); attCth->extract(attDataOutOs); std::shared_ptr<vmime::message> amsgOut = vmime::factory<vmime::message>::create(); amsgOut->parse(attDataOut); std::shared_ptr<vmime::header> hdr = amsgOut->getHeader(); // VASSERT_EQ("3", "Attached message", // hdr->Subject()->getValue().dynamicCast // <vmime::text>()->generate()); TODO shared VASSERT_EQ("3", "Attached message", std::dynamic_pointer_cast<vmime::text>(hdr->Subject()->getValue())->generate()); VASSERT_EQ("4", "Attached message body", extractBodyContents(amsgOut)); }
void testGetBodyPartAttachmentMessage() { const vmime::string data = "Subject: Test message\r\n" "Content-Type: multipart/mixed; boundary=\"foo\"\r\n" "\r\n" "--foo\r\n" "Content-Type: message/rfc822\r\n" "\r\n" "Subject: Attached message\r\n" "\r\n" "Attached message body\r\n" "--foo\r\n" "Content-Type: text/plain\r\n" "\r\n" "FooBar\r\n" "--foo--\r\n"; std::shared_ptr<vmime::message> msg = vmime::factory<vmime::message>::create(); msg->parse(data); VASSERT_EQ("0", 2, msg->getBody()->getPartCount()); std::shared_ptr<const vmime::attachment> att = vmime::attachmentHelper:: getBodyPartAttachment(msg->getBody()->getPartAt(0)); VASSERT("1", att != NULL); std::shared_ptr<const vmime::messageAttachment> msgAtt = // att.dynamicCast <const vmime::messageAttachment>(); TODO shared std::dynamic_pointer_cast<const vmime::messageAttachment>(att); VASSERT("2", msgAtt != NULL); std::shared_ptr<vmime::message> amsg = msgAtt->getMessage(); std::shared_ptr<vmime::header> hdr = amsg->getHeader(); // VASSERT_EQ("3", "Attached message", // hdr->Subject()->getValue().dynamicCast // <vmime::text>()->generate()); TODO shared VASSERT_EQ("3", "Attached message", std::dynamic_pointer_cast<vmime::text>(hdr->Subject()->getValue())->generate()); VASSERT_EQ("4", "Attached message body", extractBodyContents(amsg)); }
void testAddAttachment1() { vmime::string data = "Content-Type: text/plain\r\n" "\r\n" "The text\r\n" ""; vmime::ref <vmime::message> msg = vmime::create <vmime::message>(); msg->parse(data); vmime::ref <vmime::attachment> att = vmime::create <vmime::defaultAttachment> (vmime::create <vmime::stringContentHandler>("test"), vmime::mediaType("image/jpeg")); vmime::attachmentHelper::addAttachment(msg, att); VASSERT_EQ("1", "multipart/mixed[text/plain,image/jpeg]", getStructure(msg)); VASSERT_EQ("2", "The text\r\n", extractBodyContents(msg->getBody()->getPartAt(0))); }
// Initial part is encoded void testAddAttachment3() { vmime::string data = "Content-Type: text/plain\r\n" "Content-Transfer-Encoding: base64\r\n" "\r\n" "TWVzc2FnZSBib2R5"; vmime::shared_ptr <vmime::message> msg = vmime::make_shared <vmime::message>(); msg->parse(data); vmime::shared_ptr <vmime::attachment> att = vmime::make_shared <vmime::defaultAttachment> (vmime::make_shared <vmime::stringContentHandler>("test"), vmime::mediaType("image/jpeg")); vmime::attachmentHelper::addAttachment(msg, att); VASSERT_EQ("1", "multipart/mixed[text/plain,image/jpeg]", getStructure(msg)); VASSERT_EQ("2", "Message body", extractBodyContents(msg->getBody()->getPartAt(0))); }