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 "ktnef_debug.h"
20#include "ktnefattach.h"
21#include "lzfu.h"
22
23#include <QBuffer>
24#include <QDebug>
25
26using namespace KTnef;
27
28/**
29 * Private class that helps to provide binary compatibility between releases.
30 * @internal
31 */
32//@cond PRIVATE
33class KTnef::KTNEFMessage::MessagePrivate
34{
35public:
36 MessagePrivate() = default;
37 ~MessagePrivate();
38
39 void clearAttachments();
40
41 QList<KTNEFAttach *> attachments_;
42};
43
44KTNEFMessage::MessagePrivate::~MessagePrivate()
45{
46 clearAttachments();
47}
48
49void KTNEFMessage::MessagePrivate::clearAttachments()
50{
51 while (!attachments_.isEmpty()) {
52 delete attachments_.takeFirst();
53 }
54}
55//@endcond
56
58 : d(new KTnef::KTNEFMessage::MessagePrivate)
59{
60}
61
63
65{
66 return d->attachments_;
67}
68
70{
71 QList<KTNEFAttach *>::const_iterator it = d->attachments_.constBegin();
72 const QList<KTNEFAttach *>::const_iterator end = d->attachments_.constEnd();
73 for (; it != end; ++it) {
74 if ((*it)->name() == filename) {
75 return *it;
76 }
77 }
78 return nullptr;
79}
80
82{
83 d->attachments_.append(attach);
84}
85
87{
88 d->clearAttachments();
89}
90
92{
93 QVariant prop = property(0x1009);
94 if (prop.isNull() || prop.metaType().id() != QMetaType::QByteArray) {
95 return {};
96 } else {
97 QByteArray rtf;
98 QByteArray propArray(prop.toByteArray());
99 QBuffer input(&propArray);
100 QBuffer output(&rtf);
101 if (input.open(QIODevice::ReadOnly) && output.open(QIODevice::WriteOnly)) {
102 if (KTnef::lzfu_decompress(&input, &output) == 0) {
103 qCWarning(KTNEF_LOG) << "Error when decompress data";
104 }
105 }
106 return QString::fromLatin1(rtf);
107 }
108}
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 Mon Nov 18 2024 12:13:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.