void ComposerTest::testAttachments() { Composer *composer = new Composer; fillComposerData(composer); AttachmentPart::Ptr attachment = AttachmentPart::Ptr(new AttachmentPart); attachment->setData("abc"); attachment->setMimeType("x-some/x-type"); composer->addAttachmentPart(attachment); QVERIFY(composer->exec()); QCOMPARE(composer->resultMessages().size(), 1); KMime::Message::Ptr message = composer->resultMessages().first(); delete composer; composer = Q_NULLPTR; // multipart/mixed { QVERIFY(message->contentType(false)); QCOMPARE(message->contentType()->mimeType(), QByteArray("multipart/mixed")); QCOMPARE(message->contents().count(), 2); // text/plain { Content *plain = message->contents().at(0); QVERIFY(plain->contentType(false)); QCOMPARE(plain->contentType()->mimeType(), QByteArray("text/plain")); } // x-some/x-type (attachment) { Content *plain = message->contents().at(1); QVERIFY(plain->contentType(false)); QCOMPARE(plain->contentType()->mimeType(), QByteArray("x-some/x-type")); } } }
void ContentTest::testImplicitMultipartGeneration() { Content *c1 = new Content(); c1->contentType()->from7BitString( "text/plain" ); c1->setBody( "textpart" ); Content *c2 = new Content(); c2->contentType()->from7BitString( "text/html" ); c2->setBody( "htmlpart" ); c1->addContent( c2 ); // c1 implicitly converted into a multipart/mixed node. QVERIFY( c1->contentType( false ) ); QCOMPARE( c1->contentType()->mimeType(), QByteArray( "multipart/mixed" ) ); QVERIFY( c1->body().isEmpty() ); QCOMPARE( c1->contents().count(), 2 ); Content *c = c1->contents().at( 0 ); // Former c1. QVERIFY( c->contentType( false ) ); QCOMPARE( c->contentType()->mimeType(), QByteArray( "text/plain" ) ); QCOMPARE( c->body(), QByteArray( "textpart" ) ); QCOMPARE( c1->contents().at( 1 ), c2 ); // Now remove c2. c1 should be converted back to a text/plain content. c1->removeContent( c2, false ); QVERIFY( c1->contents().isEmpty() ); QVERIFY( c1->contentType( false ) ); QCOMPARE( c1->contentType()->mimeType(), QByteArray( "text/plain" ) ); QCOMPARE( c1->body(), QByteArray( "textpart" ) ); // c2 should not have been touched. QVERIFY( c2->contents().isEmpty() ); QVERIFY( c2->contentType( false ) ); QCOMPARE( c2->contentType()->mimeType(), QByteArray( "text/html" ) ); QCOMPARE( c2->body(), QByteArray( "htmlpart" ) ); // Clean up. delete c1; delete c2; }