(feat) now possible to set vacation message start date (fixes #3679)

pull/214/head
Ludovic Marcotte 2016-06-13 15:39:57 -04:00
parent 91bd493b82
commit a3d64d05f6
7 changed files with 82 additions and 30 deletions

View File

@ -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

1
NEWS
View File

@ -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)

View File

@ -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

View File

@ -16,7 +16,7 @@ $(SOGO_TOOL)_OBJC_FILES += \
SOGoToolBackup.m \
SOGoToolCheckDoubles.m \
SOGoToolDumpDefaults.m \
SOGoToolExpireAutoReply.m \
SOGoToolUpdateAutoReply.m \
SOGoToolExpireUserSessions.m \
SOGoToolRemove.m \
SOGoToolRemoveDoubles.m \

View File

@ -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 <flachapelle@inverse.ca>
* 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;
}

View File

@ -858,6 +858,18 @@
</md-checkbox>
</div>
<div layout="row">
<md-checkbox
ng-model="app.preferences.defaults.Vacation.startDateEnabled"
ng-true-value="1"
ng-false-value="0">
<var:string label:value="Enable auto reply on" />
</md-checkbox>
<md-datepicker
ng-disabled="app.preferences.defaults.Vacation.startDateEnabled == 0"
ng-model="app.preferences.defaults.Vacation.startDate"><!-- datepicker --></md-datepicker>
</div>
<div layout="row">
<md-checkbox
ng-model="app.preferences.defaults.Vacation.endDateEnabled"

View File

@ -39,6 +39,12 @@
// We also convert our date objects into real date, otherwise we'll have strings
// or undefined values and the md-datepicker does NOT like this.
if (data.Vacation) {
if (data.Vacation.startDate)
data.Vacation.startDate = new Date(parseInt(data.Vacation.startDate) * 1000);
else {
data.Vacation.startDateEnabled = 0;
data.Vacation.startDate = new Date();
}
if (data.Vacation.endDate)
data.Vacation.endDate = new Date(parseInt(data.Vacation.endDate) * 1000);
else {
@ -59,6 +65,11 @@
if (angular.isUndefined(data.Vacation.daysBetweenResponse))
data.Vacation.daysBetweenResponse = 7;
if (angular.isUndefined(data.Vacation.startDate)) {
data.Vacation.startDateEnabled = 0;
data.Vacation.startDate = new Date();
}
if (angular.isUndefined(data.Vacation.endDate)) {
data.Vacation.endDateEnabled = 0;
data.Vacation.endDate = new Date();
@ -218,6 +229,10 @@
delete preferences.defaults.SOGoMailComposeFontSizeEnabled;
if (preferences.defaults.Vacation) {
if (preferences.defaults.Vacation.startDateEnabled)
preferences.defaults.Vacation.startDate = preferences.defaults.Vacation.startDate.getTime()/1000;
else
preferences.defaults.Vacation.startDate = 0;
if (preferences.defaults.Vacation.endDateEnabled)
preferences.defaults.Vacation.endDate = preferences.defaults.Vacation.endDate.getTime()/1000;
else