Commit 23b5f991 authored by Laurent Montel's avatar Laurent Montel 😁

Allow to expire message without date

parent 5d29271d
Pipeline #37876 passed with stage
in 59 minutes and 1 second
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.15.49")
set(PIM_VERSION "5.15.50")
project(mailcommon VERSION ${PIM_VERSION})
......
......@@ -33,6 +33,7 @@ ExpireCollectionAttribute *ExpireCollectionAttribute::clone() const
expireAttr->setReadExpireUnits(mReadExpireUnits);
expireAttr->setExpireAction(mExpireAction);
expireAttr->setExpireToFolderId(mExpireToFolderId);
expireAttr->setExpireMessagesWithValidDate(mExpireMessagesWithValidDate);
return expireAttr;
}
......@@ -122,7 +123,8 @@ bool ExpireCollectionAttribute::operator==(const ExpireCollectionAttribute &othe
&& (mUnreadExpireUnits == other.unreadExpireUnits())
&& (mReadExpireUnits == other.readExpireUnits())
&& (mExpireAction == other.expireAction())
&& (mExpireToFolderId == other.expireToFolderId());
&& (mExpireToFolderId == other.expireToFolderId())
&& (mExpireMessagesWithValidDate == other.expireMessagesWithValidDate());
}
int ExpireCollectionAttribute::daysToExpire(int number, ExpireCollectionAttribute::ExpireUnits units)
......@@ -141,6 +143,16 @@ int ExpireCollectionAttribute::daysToExpire(int number, ExpireCollectionAttribut
return -1;
}
bool ExpireCollectionAttribute::expireMessagesWithValidDate() const
{
return mExpireMessagesWithValidDate;
}
void ExpireCollectionAttribute::setExpireMessagesWithValidDate(bool expireMessagesWithValidDate)
{
mExpireMessagesWithValidDate = expireMessagesWithValidDate;
}
void ExpireCollectionAttribute::daysToExpire(int &unreadDays, int &readDays) const
{
unreadDays = ExpireCollectionAttribute::daysToExpire(unreadExpireAge(), unreadExpireUnits());
......@@ -159,6 +171,7 @@ QByteArray ExpireCollectionAttribute::serialized() const
s << static_cast<int>(mUnreadExpireUnits);
s << mUnreadExpireAge;
s << mExpireMessages;
s << mExpireMessagesWithValidDate;
return result;
}
......@@ -179,6 +192,7 @@ void ExpireCollectionAttribute::deserialize(const QByteArray &data)
mUnreadExpireUnits = static_cast<ExpireCollectionAttribute::ExpireUnits>(valUnitUnread);
s >> mUnreadExpireAge;
s >> mExpireMessages;
s >> mExpireMessagesWithValidDate;
}
QDebug operator <<(QDebug d, const ExpireCollectionAttribute &t)
......@@ -190,5 +204,6 @@ QDebug operator <<(QDebug d, const ExpireCollectionAttribute &t)
d << " mReadExpireUnits " << t.readExpireUnits();
d << " mExpireAction " << t.expireAction();
d << " mExpireToFolderId " << t.expireToFolderId();
d << " mExpireMessagesWithValidDate " << t.expireMessagesWithValidDate();
return d;
}
......@@ -38,9 +38,9 @@ public:
ExpireMove = 1
};
QByteArray type() const override;
Q_REQUIRED_RESULT QByteArray type() const override;
ExpireCollectionAttribute *clone() const override;
QByteArray serialized() const override;
Q_REQUIRED_RESULT QByteArray serialized() const override;
void deserialize(const QByteArray &data) override;
void daysToExpire(int &unreadDays, int &readDays) const;
......@@ -53,7 +53,7 @@ public:
/**
* Returns true if this folder automatically expires old messages.
*/
bool isAutoExpire() const;
Q_REQUIRED_RESULT bool isAutoExpire() const;
/**
* Sets the maximum age for unread messages in this folder.
......@@ -85,18 +85,18 @@ public:
* Returns the age at which unread messages are expired.
* Units are determined by unreadExpireUnits().
*/
int unreadExpireAge() const;
Q_REQUIRED_RESULT int unreadExpireAge() const;
/**
* Returns the age at which read messages are expired.
* Units are determined by readExpireUnits().
*/
int readExpireAge() const;
Q_REQUIRED_RESULT int readExpireAge() const;
/**
* What should expiry do? Delete or move to another folder?
*/
ExpireAction expireAction() const;
Q_REQUIRED_RESULT ExpireAction expireAction() const;
void setExpireAction(ExpireAction a);
/**
......@@ -109,15 +109,18 @@ public:
* Units getUnreadExpireAge() is returned in.
* 1 = days, 2 = weeks, 3 = months.
*/
ExpireUnits unreadExpireUnits() const;
Q_REQUIRED_RESULT ExpireUnits unreadExpireUnits() const;
/**
* Units getReadExpireAge() is returned in.
* 1 = days, 2 = weeks, 3 = months.
*/
ExpireUnits readExpireUnits() const;
Q_REQUIRED_RESULT ExpireUnits readExpireUnits() const;
bool operator==(const ExpireCollectionAttribute &other) const;
Q_REQUIRED_RESULT bool expireMessagesWithValidDate() const;
void setExpireMessagesWithValidDate(bool expireMessagesWithValidDate);
private:
static int daysToExpire(int number, ExpireCollectionAttribute::ExpireUnits units);
bool mExpireMessages = false; // true if old messages are expired
......@@ -127,6 +130,7 @@ private:
ExpireCollectionAttribute::ExpireUnits mReadExpireUnits = ExpireNever;
ExpireCollectionAttribute::ExpireAction mExpireAction = ExpireDelete;
Akonadi::Collection::Id mExpireToFolderId = -1;
bool mExpireMessagesWithValidDate = false;
};
}
MAILCOMMON_EXPORT QDebug operator <<(QDebug d, const MailCommon::ExpireCollectionAttribute &t);
......
......@@ -33,29 +33,31 @@ CollectionExpiryWidget::CollectionExpiryWidget(QWidget *parent)
QGridLayout *daysBox = new QGridLayout;
expireReadMailCB = new QCheckBox(this);
expireReadMailCB->setText(i18n("Expire read messages after"));
connect(expireReadMailCB, &QCheckBox::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
daysBox->addWidget(expireReadMailCB, 0, 0);
expireReadMailSB = new KPluralHandlingSpinBox(this);
expireReadMailSB->setMaximum(999999);
expireReadMailSB->setValue(30);
expireReadMailSB->setSuffix(ki18ncp("Expire messages after %1", " day", " days"));
daysBox->addWidget(expireReadMailSB, 0, 1);
connect(expireReadMailSB, QOverload<int>::of(&KPluralHandlingSpinBox::valueChanged), this, &CollectionExpiryWidget::slotChanged);
expireUnreadMailCB = new QCheckBox(this);
expireUnreadMailCB->setText(i18n("Expire unread messages after"));
connect(expireUnreadMailCB, &QCheckBox::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
daysBox->addWidget(expireUnreadMailCB, 1, 0);
expireUnreadMailSB = new KPluralHandlingSpinBox(this);
expireUnreadMailSB->setMaximum(99999);
expireUnreadMailSB->setValue(30);
expireUnreadMailSB->setSuffix(ki18ncp("Expire messages after %1", " day", " days"));
daysBox->addWidget(expireUnreadMailSB, 1, 1);
connect(expireUnreadMailSB, QOverload<int>::of(&KPluralHandlingSpinBox::valueChanged), this, &CollectionExpiryWidget::slotChanged);
mExpireReadMailCB = new QCheckBox(i18n("Expire read messages after"), this);
connect(mExpireReadMailCB, &QCheckBox::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
daysBox->addWidget(mExpireReadMailCB, 0, 0);
mExpireReadMailSB = new KPluralHandlingSpinBox(this);
mExpireReadMailSB->setMaximum(999999);
mExpireReadMailSB->setValue(30);
mExpireReadMailSB->setSuffix(ki18ncp("Expire messages after %1", " day", " days"));
daysBox->addWidget(mExpireReadMailSB, 0, 1);
connect(mExpireReadMailSB, QOverload<int>::of(&KPluralHandlingSpinBox::valueChanged), this, &CollectionExpiryWidget::slotChanged);
mExpireUnreadMailCB = new QCheckBox(i18n("Expire unread messages after"), this);
connect(mExpireUnreadMailCB, &QCheckBox::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
daysBox->addWidget(mExpireUnreadMailCB, 1, 0);
mExpireUnreadMailSB = new KPluralHandlingSpinBox(this);
mExpireUnreadMailSB->setMaximum(99999);
mExpireUnreadMailSB->setValue(30);
mExpireUnreadMailSB->setSuffix(ki18ncp("Expire messages after %1", " day", " days"));
daysBox->addWidget(mExpireUnreadMailSB, 1, 1);
connect(mExpireUnreadMailSB, QOverload<int>::of(&KPluralHandlingSpinBox::valueChanged), this, &CollectionExpiryWidget::slotChanged);
mExpireMailWithInvalidDateCB = new QCheckBox(i18n("Expire messages with invalid date"), this);
connect(mExpireMailWithInvalidDateCB, &QCheckBox::toggled, this, &CollectionExpiryWidget::slotChanged);
daysBox->addWidget(mExpireMailWithInvalidDateCB, 2, 0);
daysBox->setColumnStretch(3, 1);
globalVBox->addLayout(daysBox);
......@@ -69,32 +71,32 @@ CollectionExpiryWidget::CollectionExpiryWidget(QWidget *parent)
moveToHBox->setContentsMargins(0, 0, 0, 0);
moveToHBox->setSpacing(6);
moveToRB = new QRadioButton(actionsGroup);
moveToRB->setText(i18n("Move expired messages to:"));
connect(moveToRB, &QRadioButton::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
moveToHBox->addWidget(moveToRB);
mMoveToRB = new QRadioButton(actionsGroup);
mMoveToRB->setText(i18n("Move expired messages to:"));
connect(mMoveToRB, &QRadioButton::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
moveToHBox->addWidget(mMoveToRB);
folderSelector = new FolderRequester(this);
folderSelector->setMustBeReadWrite(true);
folderSelector->setShowOutbox(false);
moveToHBox->addWidget(folderSelector);
mFolderSelector = new FolderRequester(this);
mFolderSelector->setMustBeReadWrite(true);
mFolderSelector->setShowOutbox(false);
moveToHBox->addWidget(mFolderSelector);
globalVBox->addLayout(moveToHBox);
connect(folderSelector, &FolderRequester::folderChanged, this, &CollectionExpiryWidget::slotChanged);
connect(mFolderSelector, &FolderRequester::folderChanged, this, &CollectionExpiryWidget::slotChanged);
deletePermanentlyRB = new QRadioButton(actionsGroup);
deletePermanentlyRB->setText(i18n("Delete expired messages permanently"));
connect(deletePermanentlyRB, &QRadioButton::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
mDeletePermanentlyRB = new QRadioButton(actionsGroup);
mDeletePermanentlyRB->setText(i18n("Delete expired messages permanently"));
connect(mDeletePermanentlyRB, &QRadioButton::toggled, this, &CollectionExpiryWidget::slotUpdateControls);
globalVBox->addWidget(deletePermanentlyRB);
globalVBox->addWidget(mDeletePermanentlyRB);
globalVBox->addSpacing(30);
expireNowPB = new QPushButton(i18n("Save Settings and Expire Now"), this);
connect(expireNowPB, &QPushButton::clicked, this, &CollectionExpiryWidget::saveAndExpireRequested);
globalVBox->addWidget(expireNowPB, 0, Qt::AlignRight);
mExpireNowPB = new QPushButton(i18n("Save Settings and Expire Now"), this);
connect(mExpireNowPB, &QPushButton::clicked, this, &CollectionExpiryWidget::saveAndExpireRequested);
globalVBox->addWidget(mExpireNowPB, 0, Qt::AlignRight);
globalVBox->addStretch(100); // eat all superfluous space
deletePermanentlyRB->setChecked(true);
mDeletePermanentlyRB->setChecked(true);
slotUpdateControls();
}
......@@ -104,7 +106,7 @@ CollectionExpiryWidget::~CollectionExpiryWidget()
void CollectionExpiryWidget::hideExpireNowButton()
{
expireNowPB->setVisible(false);
mExpireNowPB->setVisible(false);
}
void CollectionExpiryWidget::slotChanged()
......@@ -114,15 +116,15 @@ void CollectionExpiryWidget::slotChanged()
void CollectionExpiryWidget::slotUpdateControls()
{
const bool showExpiryActions = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
moveToRB->setEnabled(showExpiryActions);
folderSelector->setEnabled(showExpiryActions && moveToRB->isChecked());
deletePermanentlyRB->setEnabled(showExpiryActions);
const bool showExpiryActions = mExpireReadMailCB->isChecked() || mExpireUnreadMailCB->isChecked();
mMoveToRB->setEnabled(showExpiryActions);
mFolderSelector->setEnabled(showExpiryActions && mMoveToRB->isChecked());
mDeletePermanentlyRB->setEnabled(showExpiryActions);
expireReadMailSB->setEnabled(expireReadMailCB->isChecked());
expireUnreadMailSB->setEnabled(expireUnreadMailCB->isChecked());
mExpireReadMailSB->setEnabled(mExpireReadMailCB->isChecked());
mExpireUnreadMailSB->setEnabled(mExpireUnreadMailCB->isChecked());
expireNowPB->setEnabled(showExpiryActions);
mExpireNowPB->setEnabled(showExpiryActions);
Q_EMIT configChanged();
}
......@@ -134,43 +136,44 @@ void CollectionExpiryWidget::load(const MailCommon::CollectionExpirySettings &se
if (expiryGloballyOn
&& settings.mReadExpireUnits != ExpireCollectionAttribute::ExpireNever
&& settings.daysToExpireRead >= 0) {
expireReadMailCB->setChecked(true);
expireReadMailSB->setValue(settings.daysToExpireRead);
mExpireReadMailCB->setChecked(true);
mExpireReadMailSB->setValue(settings.daysToExpireRead);
}
if (expiryGloballyOn
&& settings.mUnreadExpireUnits != ExpireCollectionAttribute::ExpireNever
&& settings.daysToExpireUnread >= 0) {
expireUnreadMailCB->setChecked(true);
expireUnreadMailSB->setValue(settings.daysToExpireUnread);
mExpireUnreadMailCB->setChecked(true);
mExpireUnreadMailSB->setValue(settings.daysToExpireUnread);
}
if (settings.mExpireAction == ExpireCollectionAttribute::ExpireDelete) {
deletePermanentlyRB->setChecked(true);
mDeletePermanentlyRB->setChecked(true);
} else {
moveToRB->setChecked(true);
mMoveToRB->setChecked(true);
}
mExpireMailWithInvalidDateCB->setChecked(settings.expiryMessagesWithInvalidDate);
Akonadi::Collection::Id destFolderID = settings.mExpireToFolderId;
if (destFolderID > 0) {
Akonadi::Collection destFolder = Kernel::self()->collectionFromId(destFolderID);
if (destFolder.isValid()) {
folderSelector->setCollection(destFolder);
mFolderSelector->setCollection(destFolder);
}
}
} else {
deletePermanentlyRB->setChecked(true);
mDeletePermanentlyRB->setChecked(true);
}
slotUpdateControls();
}
bool CollectionExpiryWidget::validateExpireFolder(bool expireNow)
{
const bool enableGlobally = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
const Akonadi::Collection expireToFolder = folderSelector->collection();
if (enableGlobally && moveToRB->isChecked() && !expireToFolder.isValid()) {
const bool enableGlobally = mExpireReadMailCB->isChecked() || mExpireUnreadMailCB->isChecked();
const Akonadi::Collection expireToFolder = mFolderSelector->collection();
if (enableGlobally && mMoveToRB->isChecked() && !expireToFolder.isValid()) {
KMessageBox::error(this, i18n("Please select a folder to expire messages into.\nIf this is not done, expired messages will be permanently deleted."),
i18n("No Folder Selected"));
deletePermanentlyRB->setChecked(true);
mDeletePermanentlyRB->setChecked(true);
expireNow = false; // settings are not valid
}
return expireNow;
......@@ -178,13 +181,13 @@ bool CollectionExpiryWidget::validateExpireFolder(bool expireNow)
MailCommon::ExpireCollectionAttribute *CollectionExpiryWidget::assignFolderAttribute(Akonadi::Collection &collection, bool &expireNow)
{
const Akonadi::Collection expireToFolder = folderSelector->collection();
const Akonadi::Collection expireToFolder = mFolderSelector->collection();
MailCommon::ExpireCollectionAttribute *attribute = nullptr;
if (expireToFolder.isValid() && moveToRB->isChecked()) {
if (expireToFolder.isValid() && mMoveToRB->isChecked()) {
if (expireToFolder.id() == collection.id()) {
KMessageBox::error(this, i18n("Please select a different folder than the current folder to expire messages into.\nIf this is not done, expired messages will be permanently deleted."),
i18n("Wrong Folder Selected"));
deletePermanentlyRB->setChecked(true);
mDeletePermanentlyRB->setChecked(true);
expireNow = false; // settings are not valid
} else {
attribute = collection.attribute<MailCommon::ExpireCollectionAttribute>(Akonadi::Collection::AddIfMissing);
......@@ -200,14 +203,15 @@ MailCommon::ExpireCollectionAttribute *CollectionExpiryWidget::assignFolderAttri
CollectionExpirySettings CollectionExpiryWidget::settings() const
{
CollectionExpirySettings settings;
settings.expiryGloballyOn = expireReadMailCB->isChecked() || expireUnreadMailCB->isChecked();
settings.expiryGloballyOn = mExpireReadMailCB->isChecked() || mExpireUnreadMailCB->isChecked();
settings.expiryMessagesWithInvalidDate = mExpireMailWithInvalidDateCB->isChecked();
// we always write out days now
settings.daysToExpireRead = expireReadMailSB->value();
settings.daysToExpireUnread = expireUnreadMailSB->value();
settings.mReadExpireUnits = expireReadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays : MailCommon::ExpireCollectionAttribute::ExpireNever;
settings.mUnreadExpireUnits = expireUnreadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays : MailCommon::ExpireCollectionAttribute::ExpireNever;
settings.daysToExpireRead = mExpireReadMailSB->value();
settings.daysToExpireUnread = mExpireUnreadMailSB->value();
settings.mReadExpireUnits = mExpireReadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays : MailCommon::ExpireCollectionAttribute::ExpireNever;
settings.mUnreadExpireUnits = mExpireUnreadMailCB->isChecked() ? MailCommon::ExpireCollectionAttribute::ExpireDays : MailCommon::ExpireCollectionAttribute::ExpireNever;
if (deletePermanentlyRB->isChecked()) {
if (mDeletePermanentlyRB->isChecked()) {
settings.mExpireAction = ExpireCollectionAttribute::ExpireDelete;
} else {
settings.mExpireAction = ExpireCollectionAttribute::ExpireMove;
......
......@@ -30,6 +30,7 @@ struct MAILCOMMON_EXPORT CollectionExpirySettings
}
bool expiryGloballyOn = false;
bool expiryMessagesWithInvalidDate = false;
int daysToExpireRead = -1;
int daysToExpireUnread = -1;
ExpireCollectionAttribute::ExpireUnits mUnreadExpireUnits = ExpireCollectionAttribute::ExpireNever;
......@@ -60,14 +61,15 @@ private:
Q_REQUIRED_RESULT MailCommon::ExpireCollectionAttribute *assignFolderAttribute(Akonadi::Collection &collection, bool &expireNow);
void slotChanged();
void slotUpdateControls();
QCheckBox *expireReadMailCB = nullptr;
KPluralHandlingSpinBox *expireReadMailSB = nullptr;
QCheckBox *expireUnreadMailCB = nullptr;
KPluralHandlingSpinBox *expireUnreadMailSB = nullptr;
QRadioButton *moveToRB = nullptr;
FolderRequester *folderSelector = nullptr;
QRadioButton *deletePermanentlyRB = nullptr;
QPushButton *expireNowPB = nullptr;
QCheckBox *mExpireReadMailCB = nullptr;
KPluralHandlingSpinBox *mExpireReadMailSB = nullptr;
QCheckBox *mExpireUnreadMailCB = nullptr;
KPluralHandlingSpinBox *mExpireUnreadMailSB = nullptr;
QRadioButton *mMoveToRB = nullptr;
FolderRequester *mFolderSelector = nullptr;
QRadioButton *mDeletePermanentlyRB = nullptr;
QPushButton *mExpireNowPB = nullptr;
QCheckBox *mExpireMailWithInvalidDateCB = nullptr;
};
}
......
......@@ -38,7 +38,7 @@ using PimCommon::BroadcastStatus;
- Expire All Folders [KMMainWidget::slotExpireAll()]
*/
namespace MailCommon {
using namespace MailCommon;
ExpireJob::ExpireJob(const Akonadi::Collection &folder, bool immediate)
: ScheduledJob(folder, immediate)
{
......@@ -62,6 +62,7 @@ void ExpireJob::execute()
const MailCommon::ExpireCollectionAttribute *expirationAttribute = mSrcFolder.attribute<MailCommon::ExpireCollectionAttribute>();
if (expirationAttribute) {
int unreadDays, readDays;
mExpireMessagesWithoutInvalidDate = expirationAttribute->expireMessagesWithValidDate();
expirationAttribute->daysToExpire(unreadDays, readDays);
if (unreadDays > 0) {
......@@ -119,12 +120,14 @@ void ExpireJob::itemFetchResult(KJob *job)
auto mailDate = mb->date(false);
if (!mailDate) {
continue;
}
const time_t maxTime = status.isRead() ? mMaxReadTime : mMaxUnreadTime;
if (mailDate->dateTime().toSecsSinceEpoch() < maxTime) {
mRemovedMsgs.append(item);
if (mExpireMessagesWithoutInvalidDate) {
mRemovedMsgs.append(item);
}
} else {
const time_t maxTime = status.isRead() ? mMaxReadTime : mMaxUnreadTime;
if (mailDate->dateTime().toSecsSinceEpoch() < maxTime) {
mRemovedMsgs.append(item);
}
}
}
......@@ -267,4 +270,3 @@ void ExpireJob::slotExpireDone(KJob *job)
}
deleteLater();
}
}
......@@ -36,6 +36,7 @@ private:
Akonadi::Item::List mRemovedMsgs;
qint64 mMaxUnreadTime = 0;
qint64 mMaxReadTime = 0;
bool mExpireMessagesWithoutInvalidDate = false;
Akonadi::Collection mMoveToFolder;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment