Messagelib

attachmentpart.h
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "messagecore_export.h"
10 
11 #include <KMime/Headers>
12 
13 #include <QList>
14 #include <QMetaType>
15 #include <QSharedPointer>
16 
17 class QUrl;
18 namespace MessageCore
19 {
20 /**
21  * @short A class that encapsulates an attachment.
22  *
23  * @author Constantin Berzan <[email protected]>
24  */
25 class MESSAGECORE_EXPORT AttachmentPart
26 {
27 public:
28  /**
29  * Defines a pointer to an attachment object.
30  */
32 
33  /**
34  * Defines a list of pointers to attachment objects.
35  */
36  using List = QList<Ptr>;
37 
38  /**
39  * Creates a new attachment part.
40  */
42 
43  /**
44  * Destroys the attachment part.
45  */
46  virtual ~AttachmentPart();
47 
48  /**
49  * Sets the @p name of the attachment.
50  *
51  * The name will be used in the 'name=' part of
52  * the Content-Type header.
53  */
54  void setName(const QString &name);
55 
56  /**
57  * Returns the name of the attachment.
58  */
59  Q_REQUIRED_RESULT QString name() const;
60 
61  /**
62  * Sets the file @p name of the attachment.
63  *
64  * The name will be used in the 'filename=' part of
65  * the Content-Disposition header.
66  */
67  void setFileName(const QString &name);
68 
69  /**
70  * Returns the file name of the attachment.
71  */
72  Q_REQUIRED_RESULT QString fileName() const;
73 
74  /**
75  * Sets the @p description of the attachment.
76  */
77  void setDescription(const QString &description);
78 
79  /**
80  * Returns the description of the attachment.
81  */
82  Q_REQUIRED_RESULT QString description() const;
83 
84  /**
85  * Sets whether the attachment will be displayed inline the message.
86  */
87  void setInline(bool value);
88 
89  /**
90  * Returns whether the attachment will be displayed inline the message.
91  */
92  Q_REQUIRED_RESULT bool isInline() const;
93 
94  /**
95  * Sets whether encoding of the attachment will be determined automatically.
96  */
97  void setAutoEncoding(bool enabled);
98 
99  /**
100  * Returns whether encoding of the attachment will be determined automatically.
101  */
102  Q_REQUIRED_RESULT bool isAutoEncoding() const;
103 
104  /**
105  * Sets the @p encoding that will be used for the attachment.
106  *
107  * @note only applies if isAutoEncoding is @c false
108  */
109  void setEncoding(KMime::Headers::contentEncoding encoding);
110 
111  /**
112  * Returns the encoding that will be used for the attachment.
113  */
114  Q_REQUIRED_RESULT KMime::Headers::contentEncoding encoding() const;
115 
116  /**
117  * Sets the @p charset that will be used for the attachment.
118  */
119  void setCharset(const QByteArray &charset);
120 
121  /**
122  * Returns the charset that will be used for the attachment.
123  */
124  Q_REQUIRED_RESULT QByteArray charset() const;
125 
126  /**
127  * Sets the @p mimeType of the attachment.
128  */
129  void setMimeType(const QByteArray &mimeType);
130 
131  /**
132  * Returns the mime type of the attachment.
133  */
134  Q_REQUIRED_RESULT QByteArray mimeType() const;
135 
136  /**
137  * Sets whether the attachment is @p compressed.
138  */
139  void setCompressed(bool compressed);
140 
141  /**
142  * Returns whether the attachment is compressed.
143  */
144  Q_REQUIRED_RESULT bool isCompressed() const;
145 
146  /**
147  * Sets whether the attachment is @p encrypted.
148  */
149  void setEncrypted(bool encrypted);
150 
151  /**
152  * Returns whether the attachment is encrypted.
153  */
154  Q_REQUIRED_RESULT bool isEncrypted() const;
155 
156  /**
157  * Sets whether the attachment is @p signed.
158  */
159  void setSigned(bool sign);
160 
161  /**
162  * Returns whether the attachment is signed.
163  */
164  Q_REQUIRED_RESULT bool isSigned() const;
165 
166  /**
167  * Sets the payload @p data of the attachment.
168  */
169  void setData(const QByteArray &data);
170 
171  /**
172  * Returns the payload data of the attachment.
173  */
174  Q_REQUIRED_RESULT QByteArray data() const;
175 
176  /**
177  * Returns the size of the attachment.
178  */
179  Q_REQUIRED_RESULT qint64 size() const;
180 
181  /**
182  * Returns whether the specified attachment part is an encapsulated message
183  * (message/rfc822) or a collection of encapsulated messages (multipart/digest)
184  */
185  Q_REQUIRED_RESULT bool isMessageOrMessageCollection() const;
186 
187  void setUrl(const QUrl &url);
188  Q_REQUIRED_RESULT QUrl url() const;
189 
190 private:
191  //@cond PRIVATE
192  class AttachmentPartPrivate;
193  AttachmentPartPrivate *const d;
194  //@endcond
195 };
196 
197 // FIXME I don't understand why this doesn't work if I put it outside namespace KPIM.
198 MESSAGECORE_EXPORT uint qHash(const QSharedPointer<MessageCore::AttachmentPart> &);
199 }
200 
201 Q_DECLARE_METATYPE(MessageCore::AttachmentPart::Ptr)
A class that encapsulates an attachment.
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Mar 26 2023 04:08:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.