Mailcommon

expirecollectionattribute.h
1/*
2
3 SPDX-FileCopyrightText: 2011-2024 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "mailcommon_export.h"
11
12#include <Akonadi/Attribute>
13#include <Akonadi/Collection>
14#include <QDebug>
15
16namespace MailCommon
17{
18class MAILCOMMON_EXPORT ExpireCollectionAttribute : public Akonadi::Attribute
19{
20public:
21 ExpireCollectionAttribute();
22
23 /*
24 * Define the possible units to use for measuring message expiry.
25 * expireNever is used to switch off message expiry, and expireMaxUnits
26 * must always be the last in the list (for bounds checking).
27 */
28 enum ExpireUnits {
29 ExpireNever = 0,
30 ExpireDays = 1,
31 ExpireWeeks = 2,
32 ExpireMonths = 3,
33 ExpireMaxUnits = 4,
34 };
35
36 enum ExpireAction {
37 ExpireDelete = 0,
38 ExpireMove = 1,
39 };
40
41 [[nodiscard]] QByteArray type() const override;
42 ExpireCollectionAttribute *clone() const override;
43 [[nodiscard]] QByteArray serialized() const override;
44 void deserialize(const QByteArray &data) override;
45
46 void daysToExpire(int &unreadDays, int &readDays) const;
47
48 /**
49 * Sets whether this folder automatically expires messages.
50 */
51 void setAutoExpire(bool enabled);
52
53 /**
54 * Returns true if this folder automatically expires old messages.
55 */
56 [[nodiscard]] bool isAutoExpire() const;
57
58 /**
59 * Sets the maximum age for unread messages in this folder.
60 * Age should not be negative. Units are set using
61 * setUnreadExpireUnits().
62 */
63 void setUnreadExpireAge(int age);
64
65 /**
66 * Sets the units to use for expiry of unread messages.
67 * Values are 1 = days, 2 = weeks, 3 = months.
68 */
69 void setUnreadExpireUnits(ExpireUnits units);
70
71 /**
72 * Sets the maximum age for read messages in this folder.
73 * Age should not be negative. Units are set using
74 * setReadExpireUnits().
75 */
76 void setReadExpireAge(int age);
77
78 /**
79 * Sets the units to use for expiry of read messages.
80 * Values are 1 = days, 2 = weeks, 3 = months.
81 */
82 void setReadExpireUnits(ExpireUnits units);
83
84 /**
85 * Returns the age at which unread messages are expired.
86 * Units are determined by unreadExpireUnits().
87 */
88 [[nodiscard]] int unreadExpireAge() const;
89
90 /**
91 * Returns the age at which read messages are expired.
92 * Units are determined by readExpireUnits().
93 */
94 [[nodiscard]] int readExpireAge() const;
95
96 /**
97 * What should expiry do? Delete or move to another folder?
98 */
99 [[nodiscard]] ExpireAction expireAction() const;
100 void setExpireAction(ExpireAction a);
101
102 /**
103 * If expiry should move to folder, return the ID of that folder
104 */
105 [[nodiscard]] Akonadi::Collection::Id expireToFolderId() const;
106 void setExpireToFolderId(Akonadi::Collection::Id id);
107
108 /**
109 * Units getUnreadExpireAge() is returned in.
110 * 1 = days, 2 = weeks, 3 = months.
111 */
112 [[nodiscard]] ExpireUnits unreadExpireUnits() const;
113
114 /**
115 * Units getReadExpireAge() is returned in.
116 * 1 = days, 2 = weeks, 3 = months.
117 */
118 [[nodiscard]] ExpireUnits readExpireUnits() const;
119
120 [[nodiscard]] bool operator==(const ExpireCollectionAttribute &other) const;
121 [[nodiscard]] bool expireMessagesWithValidDate() const;
122 void setExpireMessagesWithValidDate(bool expireMessagesWithValidDate);
123
124private:
125 static MAILCOMMON_NO_EXPORT int daysToExpire(int number, ExpireCollectionAttribute::ExpireUnits units);
126 bool mExpireMessages = false; // true if old messages are expired
127 int mUnreadExpireAge = 28; // Given in unreadExpireUnits
128 int mReadExpireAge = 14; // Given in readExpireUnits
129 ExpireCollectionAttribute::ExpireUnits mUnreadExpireUnits = ExpireNever;
130 ExpireCollectionAttribute::ExpireUnits mReadExpireUnits = ExpireNever;
131 ExpireCollectionAttribute::ExpireAction mExpireAction = ExpireDelete;
132 Akonadi::Collection::Id mExpireToFolderId = -1;
133 bool mExpireMessagesWithValidDate = false;
134};
135}
136MAILCOMMON_EXPORT QDebug operator<<(QDebug d, const MailCommon::ExpireCollectionAttribute &t);
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.