2
Copyright (c) 2007 Volker Krause <vkrause@kde.org>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include "mailserializertest.h"
21
#include "mailserializertest.moc"
23
#include "akonadi_serializer_mail.cpp"
25
#include <akonadi/kmime/messageparts.h>
27
#include <qtest_kde.h>
29
QTEST_KDEMAIN( MailSerializerTest, NoGUI )
31
typedef boost::shared_ptr<KMime::Message> MessagePtr;
33
void MailSerializerTest::testEnvelopeDeserialize()
36
i.setMimeType( "message/rfc822" );
38
SerializerPluginMail *serializer = new SerializerPluginMail();
41
QByteArray env( "(\"Wed, 1 Feb 2006 13:37:19 UT\" \"IMPORTANT: Akonadi Test\" ((\"Tobias Koenig\" NIL \"tokoe\" \"kde.org\")) ((\"Tobias Koenig\" NIL \"tokoe\" \"kde.org\")) NIL ((\"Ingo Kloecker\" NIL \"kloecker\" \"kde.org\")) NIL NIL NIL <{7b55527e-77f4-489d-bf18-e805be96718c}@server.kde.org>)" );
43
buffer.setData( env );
44
buffer.open( QIODevice::ReadOnly );
46
serializer->deserialize( i, MessagePart::Envelope, buffer, 0 );
47
QVERIFY( i.hasPayload<MessagePtr>() );
49
MessagePtr msg = i.payload<MessagePtr>();
50
QCOMPARE( msg->subject()->asUnicodeString(), QString::fromUtf8( "IMPORTANT: Akonadi Test" ) );
51
QCOMPARE( msg->from()->asUnicodeString(), QString::fromUtf8( "Tobias Koenig <tokoe@kde.org>" ) );
52
QCOMPARE( msg->to()->asUnicodeString(), QString::fromUtf8( "Ingo Kloecker <kloecker@kde.org>" ) );
57
void MailSerializerTest::testEnvelopeSerialize()
60
i.setMimeType( "message/rfc822" );
61
Message* msg = new Message();
62
msg->date()->from7BitString( "Wed, 1 Feb 2006 13:37:19 UT" );
63
msg->subject()->from7BitString( "IMPORTANT: Akonadi Test" );
64
msg->from()->from7BitString( "Tobias Koenig <tokoe@kde.org>" );
65
msg->sender()->from7BitString( "Tobias Koenig <tokoe@kde.org>" );
66
msg->to()->from7BitString( "Ingo Kloecker <kloecker@kde.org>" );
67
msg->messageID()->from7BitString( "<{7b55527e-77f4-489d-bf18-e805be96718c}@server.kde.org>" );
68
i.setPayload( MessagePtr( msg ) );
70
SerializerPluginMail *serializer = new SerializerPluginMail();
73
QByteArray expEnv( "(\"Wed, 01 Feb 2006 13:37:19 +0000\" \"IMPORTANT: Akonadi Test\" ((\"Tobias Koenig\" NIL \"tokoe\" \"kde.org\")) ((\"Tobias Koenig\" NIL \"tokoe\" \"kde.org\")) NIL ((\"Ingo Kloecker\" NIL \"kloecker\" \"kde.org\")) NIL NIL NIL \"<{7b55527e-77f4-489d-bf18-e805be96718c}@server.kde.org>\")" );
76
buffer.setBuffer( &env );
77
buffer.open( QIODevice::ReadWrite );
80
serializer->serialize( i, MessagePart::Envelope, buffer, version );
81
QCOMPARE( env, expEnv );
87
void MailSerializerTest::testParts()
90
item.setMimeType( "message/rfc822" );
91
KMime::Message *m = new Message;
93
item.setPayload( msg );
95
SerializerPluginMail *serializer = new SerializerPluginMail();
96
QVERIFY( serializer->parts( item ).isEmpty() );
98
msg->setHead( "foo" );
99
QSet<QByteArray> parts = serializer->parts( item );
100
QCOMPARE( parts.count(), 2 );
101
QVERIFY( parts.contains( MessagePart::Envelope ) );
102
QVERIFY( parts.contains( MessagePart::Header ) );
104
msg->setBody( "bar" );
105
parts = serializer->parts( item );
106
QCOMPARE( parts.count(), 3 );
107
QVERIFY( parts.contains( MessagePart::Envelope ) );
108
QVERIFY( parts.contains( MessagePart::Header ) );
109
QVERIFY( parts.contains( MessagePart::Body ) );