File indexing completed on 2024-04-14 05:12:20

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 /**
0007   @file
0008   This file is part of the API for handling @ref MIME data and
0009   defines the ContentIndex class.
0010 
0011   @brief
0012   Defines the ContentIndex class.
0013 
0014   @authors Volker Krause \<vkrause@kde.org\>
0015 
0016   @glossary @anchor RFC3501 @anchor rfc3501 @b RFC @b 3501:
0017   RFC that defines the <a href="https://tools.ietf.org/html/rfc3501">
0018   Internet Message Access Protocol (IMAP)</a>.
0019 */
0020 
0021 #pragma once
0022 
0023 #include "kmime_export.h"
0024 
0025 #include <QSharedDataPointer>
0026 #include <QString>
0027 #include <QMetaType>
0028 
0029 namespace KMime
0030 {
0031 
0032 /**
0033   @brief
0034   A class to uniquely identify message parts (Content) in a hierarchy.
0035 
0036   This class is implicitly shared.
0037 
0038   Based on @ref RFC3501 section 6.4.5 and thus compatible with @acronym IMAP.
0039 */
0040 class KMIME_EXPORT ContentIndex
0041 {
0042 public:
0043     /**
0044       Creates an empty content index.
0045     */
0046     ContentIndex();
0047 
0048     /**
0049       Creates a content index based on the specified string representation.
0050 
0051       @param index is a string representation of a message part index according
0052       to @ref RFC3501 section 6.4.5.
0053     */
0054     explicit ContentIndex(QStringView index);
0055 
0056     /**
0057       Copy constructor.
0058     */
0059     ContentIndex(const ContentIndex &other);
0060     ContentIndex(ContentIndex &&) noexcept;
0061 
0062     /**
0063       Destructor.
0064     */
0065     ~ContentIndex();
0066 
0067     /**
0068       Returns true if this index is non-empty (valid).
0069     */
0070     [[nodiscard]] bool isValid() const;
0071 
0072     /**
0073       Removes and returns the top-most index. Used to recursively
0074       descend into the message part hierarchy.
0075 
0076       @see push(), up().
0077     */
0078     [[nodiscard]] unsigned int pop();
0079 
0080     /**
0081       Adds @p index to the content index. Used when ascending the message
0082       part hierarchy.
0083 
0084       @param index is the top-most content index part.
0085 
0086       @see pop(), up().
0087     */
0088     void push(unsigned int index);
0089 
0090     /**
0091       Removes and returns the bottom-most index. Used to navigate to
0092       the parent part.
0093 
0094       @see push(), pop().
0095     */
0096     unsigned int up();
0097 
0098     /**
0099       Returns a string representation of this content index according
0100       to @ref RFC3501 section 6.4.5.
0101     */
0102     [[nodiscard]] QString toString() const;
0103 
0104     /**
0105       Compares this with @p index for equality.
0106 
0107       @param index is the content index to compare.
0108     */
0109     [[nodiscard]] bool operator==(const ContentIndex &index) const;
0110 
0111     /**
0112       Compares this with @p index for inequality.
0113 
0114       @param index is the content index to compare.
0115     */
0116     [[nodiscard]] bool operator!=(const ContentIndex &index) const;
0117 
0118     /**
0119       Assignment operator.
0120     */
0121     ContentIndex &operator=(const ContentIndex &other);
0122     ContentIndex &operator=(ContentIndex &&) noexcept;
0123 
0124 private:
0125     //@cond PRIVATE
0126     class Private;
0127     QSharedDataPointer<Private> d;
0128     //@endcond
0129 };
0130 
0131 KMIME_EXPORT size_t qHash(const KMime::ContentIndex &, size_t seed = 0) noexcept;
0132 
0133 }  //namespace KMime
0134 
0135 Q_DECLARE_METATYPE(KMime::ContentIndex)
0136