diff --git a/messagecomposer/contentjob.cpp b/messagecomposer/contentjob.cpp index 7ae8bca27..69a9c2679 100644 --- a/messagecomposer/contentjob.cpp +++ b/messagecomposer/contentjob.cpp @@ -1,112 +1,127 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contentjob.h" #include "job_p.h" #include #include #include using namespace MessageComposer; using namespace KMime; class MessageComposer::ContentJobPrivate : public JobPrivate { public: ContentJobPrivate( ContentJob *qq ) : JobPrivate( qq ) + , contentDisposition( 0 ) , contentTransferEncoding( 0 ) , contentType( 0 ) { } QByteArray data; + Headers::ContentDisposition *contentDisposition; Headers::ContentTransferEncoding *contentTransferEncoding; Headers::ContentType *contentType; }; ContentJob::ContentJob( QObject *parent ) : Job( *new ContentJobPrivate( this ), parent ) { } ContentJob::~ContentJob() { } QByteArray ContentJob::data() const { Q_D( const ContentJob ); return d->data; } void ContentJob::setData( const QByteArray &data ) { Q_D( ContentJob ); d->data = data; } +Headers::ContentDisposition *ContentJob::contentDisposition() +{ + Q_D( ContentJob ); + if( !d->contentDisposition ) { + d->contentDisposition = new Headers::ContentDisposition; + } + return d->contentDisposition; +} + Headers::ContentTransferEncoding *ContentJob::contentTransferEncoding() { Q_D( ContentJob ); if( !d->contentTransferEncoding ) { d->contentTransferEncoding = new Headers::ContentTransferEncoding; } return d->contentTransferEncoding; } Headers::ContentType *ContentJob::contentType() { Q_D( ContentJob ); if( !d->contentType ) { d->contentType = new Headers::ContentType; } return d->contentType; } void ContentJob::process() { Q_D( ContentJob ); Q_ASSERT( d->resultContent == 0 ); // Not processed before. d->resultContent = new Content; // Headers. + if( d->contentDisposition ) { + d->resultContent->setHeader( d->contentDisposition ); + d->contentDisposition->setParent( d->resultContent ); + } if( d->contentTransferEncoding ) { d->resultContent->setHeader( d->contentTransferEncoding ); d->contentTransferEncoding->setParent( d->resultContent ); kDebug() << "decoded" << d->contentTransferEncoding->decoded() << "needToEncode" << d->contentTransferEncoding->needToEncode(); } if( d->contentType ) { d->resultContent->setHeader( d->contentType ); d->contentType->setParent( d->resultContent ); } // Data. d->resultContent->setBody( d->data ); kDebug() << "encoded content" << d->resultContent->encodedContent(); emitResult(); } #include "contentjob.moc" diff --git a/messagecomposer/contentjob.h b/messagecomposer/contentjob.h index 268afa80e..4fe4a4523 100644 --- a/messagecomposer/contentjob.h +++ b/messagecomposer/contentjob.h @@ -1,63 +1,65 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MESSAGECOMPOSER_CONTENTJOB_H #define MESSAGECOMPOSER_CONTENTJOB_H #include "job.h" #include "messagecomposer_export.h" namespace KMime { namespace Headers { + class ContentDisposition; class ContentTransferEncoding; class ContentType; } } namespace MessageComposer { class ContentJobPrivate; /** */ class MESSAGECOMPOSER_EXPORT ContentJob : public Job { Q_OBJECT public: ContentJob( QObject *parent = 0 ); virtual ~ContentJob(); QByteArray data() const; void setData( const QByteArray &data ); /// created on first call. delete them if you don't use the content + KMime::Headers::ContentDisposition *contentDisposition(); KMime::Headers::ContentTransferEncoding *contentTransferEncoding(); KMime::Headers::ContentType *contentType(); protected Q_SLOTS: virtual void process(); private: Q_DECLARE_PRIVATE( ContentJob ) }; } #endif diff --git a/messagecomposer/tests/contentjobtest.cpp b/messagecomposer/tests/contentjobtest.cpp index 7816d6e8e..b953d52e5 100644 --- a/messagecomposer/tests/contentjobtest.cpp +++ b/messagecomposer/tests/contentjobtest.cpp @@ -1,83 +1,105 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "contentjobtest.h" #include #include #include using namespace KMime; #include #include using namespace MessageComposer; QTEST_KDEMAIN( ContentJobTest, NoGUI ) void ContentJobTest::testContent() { Composer *composer = new Composer; ContentJob *cjob = new ContentJob( composer ); QByteArray data( "birds came flying from the underground"); cjob->setData( data ); QVERIFY( cjob->exec() ); Content *result = cjob->content(); result->assemble(); kDebug() << result->encodedContent(); QCOMPARE( result->body(), data ); + QVERIFY( result->contentDisposition( false ) == 0 ); // Not created unless demanded. QVERIFY( result->contentType( false ) == 0 ); // Not created unless demanded. QVERIFY( result->contentTransferEncoding( false ) ); // KMime gives it a default one (7bit). } +void ContentJobTest::testContentDisposition() +{ + Composer *composer = new Composer; + ContentJob *cjob = new ContentJob( composer ); + QByteArray data( "birds came flying from the underground"); + cjob->setData( data ); + QString filename = QString::fromUtf8( "test_ăîşţâ.txt" ); + cjob->contentDisposition()->setDisposition( Headers::CDattachment ); + cjob->contentDisposition()->setFilename( filename ); + QVERIFY( cjob->exec() ); + Content *result = cjob->content(); + result->assemble(); + kDebug() << result->encodedContent(); + QCOMPARE( result->body(), data ); + QVERIFY( result->contentDisposition( false ) ); + QCOMPARE( result->contentDisposition()->disposition(), Headers::CDattachment ); + QCOMPARE( result->contentDisposition()->filename(), filename ); +} + void ContentJobTest::testContentType() { Composer *composer = new Composer; ContentJob *cjob = new ContentJob( composer ); QByteArray data( "birds came flying from the underground"); cjob->setData( data ); QByteArray mimeType( "text/plain" ); + QByteArray charset( "utf-8" ); cjob->contentType()->setMimeType( mimeType ); + cjob->contentType()->setCharset( charset ); QVERIFY( cjob->exec() ); Content *result = cjob->content(); result->assemble(); kDebug() << result->encodedContent(); QCOMPARE( result->body(), data ); QVERIFY( result->contentType( false ) ); QCOMPARE( result->contentType()->mimeType(), mimeType ); + QCOMPARE( result->contentType()->charset(), charset ); } void ContentJobTest::testContentTransferEncoding() { Composer *composer = new Composer; ContentJob *cjob = new ContentJob( composer ); QByteArray data( "birds came flying from the underground"); cjob->setData( data ); cjob->contentTransferEncoding()->setEncoding( Headers::CEquPr ); QVERIFY( cjob->exec() ); Content *result = cjob->content(); result->assemble(); kDebug() << result->encodedContent(); QCOMPARE( result->body(), data ); - QVERIFY( result->contentType( false ) == 0 ); // Not created unless demanded. QVERIFY( result->contentTransferEncoding( false ) ); QCOMPARE( result->contentTransferEncoding()->encoding(), Headers::CEquPr ); } #include "contentjobtest.moc" diff --git a/messagecomposer/tests/contentjobtest.h b/messagecomposer/tests/contentjobtest.h index b7da81aa5..bcc1f43cb 100644 --- a/messagecomposer/tests/contentjobtest.h +++ b/messagecomposer/tests/contentjobtest.h @@ -1,34 +1,35 @@ /* Copyright (c) 2009 Constantin Berzan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CONTENTJOBTEST_H #define CONTENTJOBTEST_H #include class ContentJobTest : public QObject { Q_OBJECT private Q_SLOTS: void testContent(); + void testContentDisposition(); void testContentType(); void testContentTransferEncoding(); }; #endif