From 7700d68b47228a206033c7a40d4e29cef5cb0bfe Mon Sep 17 00:00:00 2001
From: Patrick Simpson
Date: Mon, 20 Mar 2017 11:29:24 +0100
Subject: [PATCH] [KOE-89] Improved handling of expired time-based
Out-of-Office
---
.../OutOfOffice/FeatureOutOfOffice.cs | 42 ++++++++++++++++---
.../Features/OutOfOffice/OutOfOfficeDialog.cs | 24 +++++++----
2 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/OutOfOffice/FeatureOutOfOffice.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/OutOfOffice/FeatureOutOfOffice.cs
index a9864dc..3148295 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/OutOfOffice/FeatureOutOfOffice.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/OutOfOffice/FeatureOutOfOffice.cs
@@ -26,6 +26,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
+using static Acacia.DebugOptions;
namespace Acacia.Features.OutOfOffice
{
@@ -34,6 +35,19 @@ namespace Acacia.Features.OutOfOffice
:
Feature, FeatureWithRibbon
{
+ #region Debug options
+
+ [AcaciaOption("Enables or disables the handling of expired time-based Out-of-Office. If enabled (the default) " +
+ "an expired Out-of-Office is treated as disabled. Otherwise it's treated as enabled.")]
+ public bool IgnoreExpired
+ {
+ get { return GetOption(OPTION_IGNORE_EXPIRED); }
+ set { SetOption(OPTION_IGNORE_EXPIRED, value); }
+ }
+ private static readonly BoolOption OPTION_IGNORE_EXPIRED = new BoolOption("IgnoreExpired", true);
+
+ #endregion
+
private RibbonToggleButton _button;
public FeatureOutOfOffice()
@@ -53,11 +67,29 @@ namespace Acacia.Features.OutOfOffice
caps.Add("ooftime");
}
- private static bool IsOOFEnabled(ActiveSync.SettingsOOF settings)
+ internal bool IsOOFEnabled(ActiveSync.SettingsOOF settings)
{
+ return GetEffectiveState(settings) != ActiveSync.OOFState.Disabled;
+ }
+
+ internal ActiveSync.OOFState GetEffectiveState(ActiveSync.SettingsOOF settings)
+ {
if (settings == null)
- return false;
- return settings.State != ActiveSync.OOFState.Disabled;
+ return ActiveSync.OOFState.Disabled;
+
+ if (settings.State == ActiveSync.OOFState.Disabled)
+ return ActiveSync.OOFState.Disabled;
+
+ // If there's a time-based OOF, and it has expired, OOF if effectively disabled
+ if (settings.State == ActiveSync.OOFState.EnabledTimeBased && IgnoreExpired)
+ {
+ if (settings.Till != null && settings.Till.Value.CompareTo(DateTime.Now) < 0)
+ {
+ return ActiveSync.OOFState.Disabled;
+ }
+ }
+
+ return settings.State;
}
private void Watcher_ZPushAccountChange(ZPushAccount account)
@@ -135,7 +167,7 @@ namespace Acacia.Features.OutOfOffice
{
// Show dialog
- if (new OutOfOfficeDialog(account, settings).ShowDialog() != DialogResult.OK)
+ if (new OutOfOfficeDialog(this, account, settings).ShowDialog() != DialogResult.OK)
return;
try
@@ -229,7 +261,7 @@ namespace Acacia.Features.OutOfOffice
StoreOOFSettings(account, oof);
// Show a message if OOF is enabled
- if (oof.State != ActiveSync.OOFState.Disabled)
+ if (IsOOFEnabled(oof))
{
if (MessageBox.Show(
string.Format(Properties.Resources.OOFStartup_Message, account.Account.SmtpAddress),
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/OutOfOffice/OutOfOfficeDialog.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/OutOfOffice/OutOfOfficeDialog.cs
index 3e0a8f7..9f483dc 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/OutOfOffice/OutOfOfficeDialog.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/OutOfOffice/OutOfOfficeDialog.cs
@@ -34,9 +34,13 @@ namespace Acacia.Features.OutOfOffice
public partial class OutOfOfficeDialog : KopanoDialog
{
private ActiveSync.SettingsOOF _settings;
- private readonly bool haveTimes;
+ private readonly bool _haveTimes;
+ ///
+ /// Set if an old date is fetched from the settings. In this case, the date limit is relaxed to allow setting it.
+ ///
+ private readonly bool _haveOldDate;
- public OutOfOfficeDialog(ZPushAccount account, ActiveSync.SettingsOOF settings)
+ public OutOfOfficeDialog(FeatureOutOfOffice owner, ZPushAccount account, ActiveSync.SettingsOOF settings)
{
this._settings = settings;
@@ -64,14 +68,14 @@ namespace Acacia.Features.OutOfOffice
radioTime_CheckedChanged(radioTime, null);
// Hide time options, only if it is known that these are not supported
- haveTimes = _settings.SupportsTimes != false;
- if (!haveTimes)
+ _haveTimes = _settings.SupportsTimes != false;
+ if (!_haveTimes)
{
tableDates.Visible = false;
}
// Load settings
- switch(settings.State)
+ switch(owner.GetEffectiveState(settings))
{
case ActiveSync.OOFState.Disabled:
chkEnable.Checked = false;
@@ -83,8 +87,11 @@ namespace Acacia.Features.OutOfOffice
case ActiveSync.OOFState.EnabledTimeBased:
chkEnable.Checked = true;
radioTime.Checked = true;
+
+ _haveOldDate = settings.Till.Value.CompareTo(DateTime.Today) <= 0;
dateFrom.Value = settings.From.Value;
timeFrom.Value = settings.From.Value;
+
dateTill.Value = settings.Till.Value;
timeTill.Value = settings.Till.Value;
break;
@@ -116,7 +123,7 @@ namespace Acacia.Features.OutOfOffice
if (chkEnable.Checked)
{
- if (radioNoTime.Checked || !haveTimes)
+ if (radioNoTime.Checked || !_haveTimes)
{
_settings.State = ActiveSync.OOFState.Enabled;
}
@@ -174,8 +181,9 @@ namespace Acacia.Features.OutOfOffice
private void SetTillTimeLimit()
{
- // Don't allow setting till to before from, or before now
- dateTill.MinDate = new DateTime(Math.Max(dateFrom.Value.Ticks, DateTime.Today.Ticks));
+ // Don't allow setting till to before from, or before now (unless we got an old date from the server).
+ DateTime minDate = _haveOldDate ? dateFrom.Value : new DateTime(Math.Max(dateFrom.Value.Ticks, DateTime.Today.Ticks));
+ dateTill.MinDate = minDate;
if (dateTill.Value.Date == dateFrom.Value.Date)
{