From a3d64d05f62e034b85ba265f061995d973e5ea2d Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 13 Jun 2016 15:39:57 -0400 Subject: [PATCH] (feat) now possible to set vacation message start date (fixes #3679) --- Documentation/SOGoInstallationGuide.asciidoc | 8 +-- NEWS | 1 + Scripts/sogo.cron | 2 +- Tools/GNUmakefile | 2 +- ...eAutoReply.m => SOGoToolUpdateAutoReply.m} | 72 ++++++++++++------- UI/Templates/PreferencesUI/UIxPreferences.wox | 12 ++++ .../js/Preferences/Preferences.service.js | 15 ++++ 7 files changed, 82 insertions(+), 30 deletions(-) rename Tools/{SOGoToolExpireAutoReply.m => SOGoToolUpdateAutoReply.m} (75%) diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index 6ace3ee05..75afd3e51 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -2509,11 +2509,11 @@ If your mail server requires use of SMTP AUTH, specify a credential file using `-p /path/to/credFile`. This file should contain the username and password, separated by a colon (`username:password`) -_Cronjob_ — Vacation messages expiration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +_Cronjob_ — Vacation messages activation and expiration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When vacation messages are enabled (see the parameter -_SOGoVacationEnabled_), users can set an expiration date to messages +_SOGoVacationEnabled_), users can set an activation or expiration date to messages auto-reply. For this feature to work, you must run a _cronjob_ under the "sogo" user. @@ -2527,7 +2527,7 @@ contain the username and password, separated by a colon The _cronjob_ should look like this: ---- -0 0 * * * sogo /usr/sbin/sogo-tool expire-autoreply -p /etc/sogo/sieve.creds +0 0 * * * sogo /usr/sbin/sogo-tool update-autoreply -p /etc/sogo/sieve.creds ---- Managing User Accounts diff --git a/NEWS b/NEWS index 71e32e4b0..1e5bcb04a 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ New features - [core] now possible to define default Sieve filters (#2949) + - [core] now possible to set vacation message start date (#3679) Enhancements - [web] always display name of month in week view (#3724) diff --git a/Scripts/sogo.cron b/Scripts/sogo.cron index 08aaa96bb..31e90edfa 100644 --- a/Scripts/sogo.cron +++ b/Scripts/sogo.cron @@ -2,7 +2,7 @@ # Vacation messages expiration # The credentials file should contain the sieve admin credentials (username:passwd) -#0 0 * * * sogo /usr/sbin/sogo-tool expire-autoreply -p /etc/sogo/sieve.creds +#0 0 * * * sogo /usr/sbin/sogo-tool update-autoreply -p /etc/sogo/sieve.creds # Session cleanup - runs every minute # - Ajust the nbMinutes parameter to suit your needs diff --git a/Tools/GNUmakefile b/Tools/GNUmakefile index 32f9119e4..0f84aad14 100644 --- a/Tools/GNUmakefile +++ b/Tools/GNUmakefile @@ -16,7 +16,7 @@ $(SOGO_TOOL)_OBJC_FILES += \ SOGoToolBackup.m \ SOGoToolCheckDoubles.m \ SOGoToolDumpDefaults.m \ - SOGoToolExpireAutoReply.m \ + SOGoToolUpdateAutoReply.m \ SOGoToolExpireUserSessions.m \ SOGoToolRemove.m \ SOGoToolRemoveDoubles.m \ diff --git a/Tools/SOGoToolExpireAutoReply.m b/Tools/SOGoToolUpdateAutoReply.m similarity index 75% rename from Tools/SOGoToolExpireAutoReply.m rename to Tools/SOGoToolUpdateAutoReply.m index 69d7235ce..2a0b2f707 100644 --- a/Tools/SOGoToolExpireAutoReply.m +++ b/Tools/SOGoToolUpdateAutoReply.m @@ -1,8 +1,6 @@ -/* SOGoToolUserPreferences.m - this file is part of SOGo +/* SOGoToolUpdateAutoReply.m - this file is part of SOGo * - * Copyright (C) 2011-2013 Inverse inc. - * - * Author: Francis Lachapelle + * Copyright (C) 2011-2016 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,10 +43,10 @@ #import "SOGoTool.h" -@interface SOGoToolExpireAutoReply : SOGoTool +@interface SOGoToolUpdateAutoReply : SOGoTool @end -@implementation SOGoToolExpireAutoReply +@implementation SOGoToolUpdateAutoReply + (void) initialize { @@ -56,27 +54,28 @@ + (NSString *) command { - return @"expire-autoreply"; + return @"update-autoreply"; } + (NSString *) description { - return @"disable auto reply for reached end dates"; + return @"enable or disable auto reply for reached start/end dates"; } - (void) usage { - fprintf (stderr, "expire-autoreply -p credentialFile\n\n" + fprintf (stderr, "update-autoreply -p credentialFile\n\n" " -p credentialFile Specify the file containing the sieve admin credentials\n" " The file should contain a single line:\n" " username:password\n" "\n" - "The expire-autoreply action should be configured as a daily cronjob.\n"); + "The update-autoreply action should be configured as a daily cronjob.\n"); } -- (BOOL) removeAutoReplyForLogin: (NSString *) theLogin +- (BOOL) updateAutoReplyForLogin: (NSString *) theLogin withSieveUsername: (NSString *) theUsername andPassword: (NSString *) thePassword + disabling: (BOOL) disabling { NSMutableDictionary *vacationOptions; SOGoUserDefaults *userDefaults; @@ -88,7 +87,15 @@ vacationOptions = [[userDefaults vacationOptions] mutableCopy]; [vacationOptions autorelease]; - [vacationOptions setObject: [NSNumber numberWithBool: NO] forKey: @"enabled"]; + if (disabling) + { + [vacationOptions setObject: [NSNumber numberWithBool: NO] forKey: @"enabled"]; + } + else + { + [vacationOptions setObject: [NSNumber numberWithBool: NO] forKey: @"startDateEnabled"]; + } + [userDefaults setVacationOptions: vacationOptions]; result = [userDefaults synchronize]; @@ -115,7 +122,10 @@ if (!result) { // Can't update Sieve script -- Reactivate auto-reply - [vacationOptions setObject: [NSNumber numberWithBool: YES] forKey: @"enabled"]; + if (disabling) + [vacationOptions setObject: [NSNumber numberWithBool: YES] forKey: @"enabled"]; + else + [vacationOptions setObject: [NSNumber numberWithBool: YES] forKey: @"startDateEnabled"]; [userDefaults setVacationOptions: vacationOptions]; [userDefaults synchronize]; } @@ -124,7 +134,7 @@ return result; } -- (void) expireAutoReplyWithUsername: (NSString *) theUsername +- (void) updateAutoReplyWithUsername: (NSString *) theUsername andPassword: (NSString *) thePassword { GCSChannelManager *cm; @@ -134,8 +144,7 @@ NSString *sql, *profileURL, *user, *c_defaults; NSURL *tableURL; SOGoSystemDefaults *sd; - BOOL enabled; - unsigned int endTime, now; + unsigned int endTime, startTime, now; now = [[NSCalendarDate calendarDate] timeIntervalSince1970]; sd = [SOGoSystemDefaults sharedSystemDefaults]; @@ -169,18 +178,33 @@ { defaults = [c_defaults objectFromJSONString]; vacationOptions = (NSDictionary *) [defaults objectForKey: @"Vacation"]; - enabled = [[vacationOptions objectForKey: @"enabled"] boolValue]; - if (enabled) + if ([[vacationOptions objectForKey: @"enabled"] boolValue]) { - enabled = [[vacationOptions objectForKey: @"endDateEnabled"] boolValue]; - if (enabled) + // We handle the start date + if ([[vacationOptions objectForKey: @"startDateEnabled"] boolValue]) + { + startTime = [[vacationOptions objectForKey: @"startDate"] intValue]; + if (now >= startTime) + { + if ([self updateAutoReplyForLogin: user + withSieveUsername: theUsername + andPassword: thePassword + disabling: NO]) + NSLog(@"Enabled auto-reply of user %@", user); + else + NSLog(@"An error occured while enabling auto-reply of user %@", user); + } + } + // We handle the end date + if ([[vacationOptions objectForKey: @"endDateEnabled"] boolValue]) { endTime = [[vacationOptions objectForKey: @"endDate"] intValue]; if (endTime <= now) { - if ([self removeAutoReplyForLogin: user - withSieveUsername: theUsername - andPassword: thePassword]) + if ([self updateAutoReplyForLogin: user + withSieveUsername: theUsername + andPassword: thePassword + disabling: YES]) NSLog(@"Removed auto-reply of user %@", user); else NSLog(@"An error occured while removing auto-reply of user %@", user); @@ -238,7 +262,7 @@ if (authname && authpwd) { - [self expireAutoReplyWithUsername: authname andPassword: authpwd]; + [self updateAutoReplyWithUsername: authname andPassword: authpwd]; rc = YES; } diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index 8364b4630..5887d6eb0 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -858,6 +858,18 @@ +
+ + + + +
+