Warning, file /pim/mailcommon/src/collectionpage/attributes/expirecollectionattribute.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 0003 SPDX-FileCopyrightText: 2011-2024 Laurent Montel <montel@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "mailcommon_export.h" 0011 0012 #include <Akonadi/Attribute> 0013 #include <Akonadi/Collection> 0014 #include <QDebug> 0015 0016 namespace MailCommon 0017 { 0018 class MAILCOMMON_EXPORT ExpireCollectionAttribute : public Akonadi::Attribute 0019 { 0020 public: 0021 ExpireCollectionAttribute(); 0022 0023 /* 0024 * Define the possible units to use for measuring message expiry. 0025 * expireNever is used to switch off message expiry, and expireMaxUnits 0026 * must always be the last in the list (for bounds checking). 0027 */ 0028 enum ExpireUnits { 0029 ExpireNever = 0, 0030 ExpireDays = 1, 0031 ExpireWeeks = 2, 0032 ExpireMonths = 3, 0033 ExpireMaxUnits = 4, 0034 }; 0035 0036 enum ExpireAction { 0037 ExpireDelete = 0, 0038 ExpireMove = 1, 0039 }; 0040 0041 [[nodiscard]] QByteArray type() const override; 0042 ExpireCollectionAttribute *clone() const override; 0043 [[nodiscard]] QByteArray serialized() const override; 0044 void deserialize(const QByteArray &data) override; 0045 0046 void daysToExpire(int &unreadDays, int &readDays) const; 0047 0048 /** 0049 * Sets whether this folder automatically expires messages. 0050 */ 0051 void setAutoExpire(bool enabled); 0052 0053 /** 0054 * Returns true if this folder automatically expires old messages. 0055 */ 0056 [[nodiscard]] bool isAutoExpire() const; 0057 0058 /** 0059 * Sets the maximum age for unread messages in this folder. 0060 * Age should not be negative. Units are set using 0061 * setUnreadExpireUnits(). 0062 */ 0063 void setUnreadExpireAge(int age); 0064 0065 /** 0066 * Sets the units to use for expiry of unread messages. 0067 * Values are 1 = days, 2 = weeks, 3 = months. 0068 */ 0069 void setUnreadExpireUnits(ExpireUnits units); 0070 0071 /** 0072 * Sets the maximum age for read messages in this folder. 0073 * Age should not be negative. Units are set using 0074 * setReadExpireUnits(). 0075 */ 0076 void setReadExpireAge(int age); 0077 0078 /** 0079 * Sets the units to use for expiry of read messages. 0080 * Values are 1 = days, 2 = weeks, 3 = months. 0081 */ 0082 void setReadExpireUnits(ExpireUnits units); 0083 0084 /** 0085 * Returns the age at which unread messages are expired. 0086 * Units are determined by unreadExpireUnits(). 0087 */ 0088 [[nodiscard]] int unreadExpireAge() const; 0089 0090 /** 0091 * Returns the age at which read messages are expired. 0092 * Units are determined by readExpireUnits(). 0093 */ 0094 [[nodiscard]] int readExpireAge() const; 0095 0096 /** 0097 * What should expiry do? Delete or move to another folder? 0098 */ 0099 [[nodiscard]] ExpireAction expireAction() const; 0100 void setExpireAction(ExpireAction a); 0101 0102 /** 0103 * If expiry should move to folder, return the ID of that folder 0104 */ 0105 Akonadi::Collection::Id expireToFolderId() const; 0106 void setExpireToFolderId(Akonadi::Collection::Id id); 0107 0108 /** 0109 * Units getUnreadExpireAge() is returned in. 0110 * 1 = days, 2 = weeks, 3 = months. 0111 */ 0112 [[nodiscard]] ExpireUnits unreadExpireUnits() const; 0113 0114 /** 0115 * Units getReadExpireAge() is returned in. 0116 * 1 = days, 2 = weeks, 3 = months. 0117 */ 0118 [[nodiscard]] ExpireUnits readExpireUnits() const; 0119 0120 bool operator==(const ExpireCollectionAttribute &other) const; 0121 [[nodiscard]] bool expireMessagesWithValidDate() const; 0122 void setExpireMessagesWithValidDate(bool expireMessagesWithValidDate); 0123 0124 private: 0125 static MAILCOMMON_NO_EXPORT int daysToExpire(int number, ExpireCollectionAttribute::ExpireUnits units); 0126 bool mExpireMessages = false; // true if old messages are expired 0127 int mUnreadExpireAge = 28; // Given in unreadExpireUnits 0128 int mReadExpireAge = 14; // Given in readExpireUnits 0129 ExpireCollectionAttribute::ExpireUnits mUnreadExpireUnits = ExpireNever; 0130 ExpireCollectionAttribute::ExpireUnits mReadExpireUnits = ExpireNever; 0131 ExpireCollectionAttribute::ExpireAction mExpireAction = ExpireDelete; 0132 Akonadi::Collection::Id mExpireToFolderId = -1; 0133 bool mExpireMessagesWithValidDate = false; 0134 }; 0135 } 0136 MAILCOMMON_EXPORT QDebug operator<<(QDebug d, const MailCommon::ExpireCollectionAttribute &t);