KTnef

ktnefmessage.cpp
Go to the documentation of this file.
1/*
2 ktnefmessage.cpp
3
4 SPDX-FileCopyrightText: 2002 Michael Goffioul <kdeprint@swing.be>
5
6 This file is part of KTNEF, the KDE TNEF support library/program.
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10/**
11 * @file
12 * This file is part of the API for handling TNEF data and
13 * defines the KTNEFMessage class.
14 *
15 * @author Michael Goffioul
16 */
17
18#include "ktnefmessage.h"
19#include "ktnefattach.h"
20#include "lzfu.h"
21
22#include <QBuffer>
23#include <QDebug>
24
25using namespace KTnef;
26
27/**
28 * Private class that helps to provide binary compatibility between releases.
29 * @internal
30 */
31//@cond PRIVATE
32class KTnef::KTNEFMessage::MessagePrivate
33{
34public:
35 MessagePrivate() = default;
36 ~MessagePrivate();
37
38 void clearAttachments();
39
40 QList<KTNEFAttach *> attachments_;
41};
42
43KTNEFMessage::MessagePrivate::~MessagePrivate()
44{
45 clearAttachments();
46}
47
48void KTNEFMessage::MessagePrivate::clearAttachments()
49{
50 while (!attachments_.isEmpty()) {
51 delete attachments_.takeFirst();
52 }
53}
54//@endcond
55
57 : d(new KTnef::KTNEFMessage::MessagePrivate)
58{
59}
60
62
64{
65 return d->attachments_;
66}
67
69{
70 QList<KTNEFAttach *>::const_iterator it = d->attachments_.constBegin();
71 const QList<KTNEFAttach *>::const_iterator end = d->attachments_.constEnd();
72 for (; it != end; ++it) {
73 if ((*it)->name() == filename) {
74 return *it;
75 }
76 }
77 return nullptr;
78}
79
81{
82 d->attachments_.append(attach);
83}
84
86{
87 d->clearAttachments();
88}
89
91{
92 QVariant prop = property(0x1009);
93 if (prop.isNull() || prop.metaType().id() != QMetaType::QByteArray) {
94 return {};
95 } else {
96 QByteArray rtf;
97 QByteArray propArray(prop.toByteArray());
98 QBuffer input(&propArray);
99 QBuffer output(&rtf);
100 if (input.open(QIODevice::ReadOnly) && output.open(QIODevice::WriteOnly)) {
101 if (KTnef::lzfu_decompress(&input, &output) == 0) {
102 qWarning() << "Error when decompress data";
103 }
104 }
105 return QString::fromLatin1(rtf);
106 }
107}
Represents a TNEF attachment.
Definition ktnefattach.h:38
Represents a TNEF message.
void clearAttachments()
Clear the attachments list.
QString rtfString() const
Returns the Rich Text Format (RTF) data contained in the message.
void addAttachment(KTNEFAttach *attach)
Append an attachment to the message.
~KTNEFMessage()
Destroys a KTNEFMessage message object.
const QList< KTNEFAttach * > & attachmentList() const
Return a QList containing all the message's attachments.
KTNEFAttach * attachment(const QString &filename) const
Find the attachment associated to the specified file name.
KTNEFMessage()
Creates a KTNEFMessage message object.
QVariant property(int key) const
Returns the property associated with the specified key.
This file is part of the API for handling TNEF data and defines the KTNEFAttach class.
This file is part of the API for handling TNEF data and defines the KTNEFMessage class.
This file is part of the API for handling TNEF data and provides the LZFU decompression functionality...
int lzfu_decompress(QIODevice *input, QIODevice *output)
LZFU decompress data in compressed Rich Text Format (RTF).
Definition lzfu.cpp:63
virtual bool open(OpenMode flags) override
int id() const const
QString fromLatin1(QByteArrayView str)
bool isNull() const const
QMetaType metaType() const const
QByteArray toByteArray() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.