Mailcommon

expirecollectionattribute.h
1 /*
2 
3  SPDX-FileCopyrightText: 2011-2022 Laurent Montel <[email protected]>
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 
16 namespace MailCommon
17 {
18 class MAILCOMMON_EXPORT ExpireCollectionAttribute : public Akonadi::Attribute
19 {
20 public:
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 { ExpireNever = 0, ExpireDays = 1, ExpireWeeks = 2, ExpireMonths = 3, ExpireMaxUnits = 4 };
29 
30  enum ExpireAction { ExpireDelete = 0, ExpireMove = 1 };
31 
32  Q_REQUIRED_RESULT QByteArray type() const override;
33  ExpireCollectionAttribute *clone() const override;
34  Q_REQUIRED_RESULT QByteArray serialized() const override;
35  void deserialize(const QByteArray &data) override;
36 
37  void daysToExpire(int &unreadDays, int &readDays) const;
38 
39  /**
40  * Sets whether this folder automatically expires messages.
41  */
42  void setAutoExpire(bool enabled);
43 
44  /**
45  * Returns true if this folder automatically expires old messages.
46  */
47  Q_REQUIRED_RESULT bool isAutoExpire() const;
48 
49  /**
50  * Sets the maximum age for unread messages in this folder.
51  * Age should not be negative. Units are set using
52  * setUnreadExpireUnits().
53  */
54  void setUnreadExpireAge(int age);
55 
56  /**
57  * Sets the units to use for expiry of unread messages.
58  * Values are 1 = days, 2 = weeks, 3 = months.
59  */
60  void setUnreadExpireUnits(ExpireUnits units);
61 
62  /**
63  * Sets the maximum age for read messages in this folder.
64  * Age should not be negative. Units are set using
65  * setReadExpireUnits().
66  */
67  void setReadExpireAge(int age);
68 
69  /**
70  * Sets the units to use for expiry of read messages.
71  * Values are 1 = days, 2 = weeks, 3 = months.
72  */
73  void setReadExpireUnits(ExpireUnits units);
74 
75  /**
76  * Returns the age at which unread messages are expired.
77  * Units are determined by unreadExpireUnits().
78  */
79  Q_REQUIRED_RESULT int unreadExpireAge() const;
80 
81  /**
82  * Returns the age at which read messages are expired.
83  * Units are determined by readExpireUnits().
84  */
85  Q_REQUIRED_RESULT int readExpireAge() const;
86 
87  /**
88  * What should expiry do? Delete or move to another folder?
89  */
90  Q_REQUIRED_RESULT ExpireAction expireAction() const;
91  void setExpireAction(ExpireAction a);
92 
93  /**
94  * If expiry should move to folder, return the ID of that folder
95  */
96  Akonadi::Collection::Id expireToFolderId() const;
97  void setExpireToFolderId(Akonadi::Collection::Id id);
98 
99  /**
100  * Units getUnreadExpireAge() is returned in.
101  * 1 = days, 2 = weeks, 3 = months.
102  */
103  Q_REQUIRED_RESULT ExpireUnits unreadExpireUnits() const;
104 
105  /**
106  * Units getReadExpireAge() is returned in.
107  * 1 = days, 2 = weeks, 3 = months.
108  */
109  Q_REQUIRED_RESULT ExpireUnits readExpireUnits() const;
110 
111  bool operator==(const ExpireCollectionAttribute &other) const;
112  Q_REQUIRED_RESULT bool expireMessagesWithValidDate() const;
113  void setExpireMessagesWithValidDate(bool expireMessagesWithValidDate);
114 
115 private:
116  static int daysToExpire(int number, ExpireCollectionAttribute::ExpireUnits units);
117  bool mExpireMessages = false; // true if old messages are expired
118  int mUnreadExpireAge = 28; // Given in unreadExpireUnits
119  int mReadExpireAge = 14; // Given in readExpireUnits
120  ExpireCollectionAttribute::ExpireUnits mUnreadExpireUnits = ExpireNever;
121  ExpireCollectionAttribute::ExpireUnits mReadExpireUnits = ExpireNever;
122  ExpireCollectionAttribute::ExpireAction mExpireAction = ExpireDelete;
123  Akonadi::Collection::Id mExpireToFolderId = -1;
124  bool mExpireMessagesWithValidDate = false;
125 };
126 }
127 MAILCOMMON_EXPORT QDebug operator<<(QDebug d, const MailCommon::ExpireCollectionAttribute &t);
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.