diff options
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/partnodebodypart.cpp')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/partnodebodypart.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/partnodebodypart.cpp b/framework/src/domain/mime/mimetreeparser/partnodebodypart.cpp new file mode 100644 index 00000000..47e1fe24 --- /dev/null +++ b/framework/src/domain/mime/mimetreeparser/partnodebodypart.cpp | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | partnodebodypart.cpp | ||
3 | |||
4 | This file is part of KMail, the KDE mail client. | ||
5 | Copyright (c) 2004 Marc Mutz <mutz@kde.org>, | ||
6 | Ingo Kloecker <kloecker@kde.org> | ||
7 | |||
8 | KMail is free software; you can redistribute it and/or modify it | ||
9 | under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | KMail is distributed in the hope that it will be useful, but | ||
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | |||
22 | In addition, as a special exception, the copyright holders give | ||
23 | permission to link the code of this program with any edition of | ||
24 | the Qt library by Trolltech AS, Norway (or with modified versions | ||
25 | of Qt that use the same license as Qt), and distribute linked | ||
26 | combinations including the two. You must obey the GNU General | ||
27 | Public License in all respects for all of the code used other than | ||
28 | Qt. If you modify this file, you may extend this exception to | ||
29 | your version of the file, but you are not obligated to do so. If | ||
30 | you do not wish to do so, delete this exception statement from | ||
31 | your version. | ||
32 | */ | ||
33 | |||
34 | #include "partnodebodypart.h" | ||
35 | #include "nodehelper.h" | ||
36 | #include "objecttreeparser.h" | ||
37 | #include "mimetreeparser_debug.h" | ||
38 | #include <KMime/Content> | ||
39 | |||
40 | #include <QTextCodec> | ||
41 | #include <QUrl> | ||
42 | |||
43 | using namespace MimeTreeParser; | ||
44 | |||
45 | static int serial = 0; | ||
46 | |||
47 | PartNodeBodyPart::PartNodeBodyPart(ObjectTreeParser *otp, KMime::Content *topLevelContent, KMime::Content *content, | ||
48 | NodeHelper *nodeHelper) | ||
49 | : Interface::BodyPart() | ||
50 | , mTopLevelContent(topLevelContent) | ||
51 | , mContent(content) | ||
52 | , mNodeHelper(nodeHelper) | ||
53 | , mObjectTreeParser(otp) | ||
54 | {} | ||
55 | |||
56 | QString PartNodeBodyPart::makeLink(const QString &path) const | ||
57 | { | ||
58 | // FIXME: use a PRNG for the first arg, instead of a serial number | ||
59 | return QStringLiteral("x-kmail:/bodypart/%1/%2/%3") | ||
60 | .arg(serial++).arg(mContent->index().toString()) | ||
61 | .arg(QString::fromLatin1(QUrl::toPercentEncoding(path, "/"))); | ||
62 | } | ||
63 | |||
64 | QString PartNodeBodyPart::asText() const | ||
65 | { | ||
66 | if (!mContent->contentType()->isText()) { | ||
67 | return QString(); | ||
68 | } | ||
69 | return mContent->decodedText(); | ||
70 | } | ||
71 | |||
72 | QByteArray PartNodeBodyPart::asBinary() const | ||
73 | { | ||
74 | return mContent->decodedContent(); | ||
75 | } | ||
76 | |||
77 | QString PartNodeBodyPart::contentTypeParameter(const char *param) const | ||
78 | { | ||
79 | return mContent->contentType()->parameter(QString::fromLatin1(param)); | ||
80 | } | ||
81 | |||
82 | QString PartNodeBodyPart::contentDescription() const | ||
83 | { | ||
84 | return mContent->contentDescription()->asUnicodeString(); | ||
85 | } | ||
86 | |||
87 | QString PartNodeBodyPart::contentDispositionParameter(const char *param) const | ||
88 | { | ||
89 | return mContent->contentDisposition()->parameter(QString::fromLatin1(param)); | ||
90 | } | ||
91 | |||