File indexing completed on 2025-03-09 04:54:12

0001 /*
0002   SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "messagecore_export.h"
0010 
0011 #include <KMime/Headers>
0012 
0013 #include <QList>
0014 #include <QMetaType>
0015 #include <QSharedPointer>
0016 
0017 class QUrl;
0018 namespace MessageCore
0019 {
0020 /**
0021  * @short A class that encapsulates an attachment.
0022  *
0023  * @author Constantin Berzan <exit3219@gmail.com>
0024  */
0025 class MESSAGECORE_EXPORT AttachmentPart
0026 {
0027 public:
0028     /**
0029      * Defines a pointer to an attachment object.
0030      */
0031     using Ptr = QSharedPointer<AttachmentPart>;
0032 
0033     /**
0034      * Defines a list of pointers to attachment objects.
0035      */
0036     using List = QList<Ptr>;
0037 
0038     /**
0039      * Creates a new attachment part.
0040      */
0041     AttachmentPart();
0042 
0043     /**
0044      * Destroys the attachment part.
0045      */
0046     virtual ~AttachmentPart();
0047 
0048     /**
0049      * Sets the @p name of the attachment.
0050      *
0051      * The name will be used in the 'name=' part of
0052      * the Content-Type header.
0053      */
0054     void setName(const QString &name);
0055 
0056     /**
0057      * Returns the name of the attachment.
0058      */
0059     [[nodiscard]] QString name() const;
0060 
0061     /**
0062      * Sets the file @p name of the attachment.
0063      *
0064      * The name will be used in the 'filename=' part of
0065      * the Content-Disposition header.
0066      */
0067     void setFileName(const QString &name);
0068 
0069     /**
0070      * Returns the file name of the attachment.
0071      */
0072     [[nodiscard]] QString fileName() const;
0073 
0074     /**
0075      * Sets the @p description of the attachment.
0076      */
0077     void setDescription(const QString &description);
0078 
0079     /**
0080      * Returns the description of the attachment.
0081      */
0082     [[nodiscard]] QString description() const;
0083 
0084     /**
0085      * Sets whether the attachment will be displayed inline the message.
0086      */
0087     void setInline(bool value);
0088 
0089     /**
0090      * Returns whether the attachment will be displayed inline the message.
0091      */
0092     [[nodiscard]] bool isInline() const;
0093 
0094     /**
0095      * Sets whether encoding of the attachment will be determined automatically.
0096      */
0097     void setAutoEncoding(bool enabled);
0098 
0099     /**
0100      * Returns whether encoding of the attachment will be determined automatically.
0101      */
0102     [[nodiscard]] bool isAutoEncoding() const;
0103 
0104     /**
0105      * Sets the @p encoding that will be used for the attachment.
0106      *
0107      * @note only applies if isAutoEncoding is @c false
0108      */
0109     void setEncoding(KMime::Headers::contentEncoding encoding);
0110 
0111     /**
0112      * Returns the encoding that will be used for the attachment.
0113      */
0114     [[nodiscard]] KMime::Headers::contentEncoding encoding() const;
0115 
0116     /**
0117      * Sets the @p charset that will be used for the attachment.
0118      */
0119     void setCharset(const QByteArray &charset);
0120 
0121     /**
0122      * Returns the charset that will be used for the attachment.
0123      */
0124     [[nodiscard]] QByteArray charset() const;
0125 
0126     /**
0127      * Sets the @p mimeType of the attachment.
0128      */
0129     void setMimeType(const QByteArray &mimeType);
0130 
0131     /**
0132      * Returns the mime type of the attachment.
0133      */
0134     [[nodiscard]] QByteArray mimeType() const;
0135 
0136     /**
0137      * Sets whether the attachment is @p compressed.
0138      */
0139     void setCompressed(bool compressed);
0140 
0141     /**
0142      * Returns whether the attachment is compressed.
0143      */
0144     [[nodiscard]] bool isCompressed() const;
0145 
0146     /**
0147      * Sets whether the attachment is @p encrypted.
0148      */
0149     void setEncrypted(bool encrypted);
0150 
0151     /**
0152      * Returns whether the attachment is encrypted.
0153      */
0154     [[nodiscard]] bool isEncrypted() const;
0155 
0156     /**
0157      * Sets whether the attachment is @p signed.
0158      */
0159     void setSigned(bool sign);
0160 
0161     /**
0162      * Returns whether the attachment is signed.
0163      */
0164     [[nodiscard]] bool isSigned() const;
0165 
0166     /**
0167      * Sets the payload @p data of the attachment.
0168      */
0169     void setData(const QByteArray &data);
0170 
0171     /**
0172      * Returns the payload data of the attachment.
0173      */
0174     [[nodiscard]] QByteArray data() const;
0175 
0176     /**
0177      * Returns the size of the attachment.
0178      */
0179     [[nodiscard]] qint64 size() const;
0180 
0181     /**
0182      * Returns whether the specified attachment part is an encapsulated message
0183      * (message/rfc822) or a collection of encapsulated messages (multipart/digest)
0184      */
0185     [[nodiscard]] bool isMessageOrMessageCollection() const;
0186 
0187     void setUrl(const QUrl &url);
0188     [[nodiscard]] QUrl url() const;
0189 
0190     size_t qHash(const QSharedPointer<MessageCore::AttachmentPart> &, size_t seed = 0);
0191 
0192 private:
0193     //@cond PRIVATE
0194     class AttachmentPartPrivate;
0195     AttachmentPartPrivate *const d;
0196     //@endcond
0197 };
0198 }
0199 
0200 Q_DECLARE_METATYPE(MessageCore::AttachmentPart::Ptr)