diff --git a/ChangeLog b/ChangeLog index 1f0ab2025..b649df921 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-11-21 Francis Lachapelle + + * UI/WebServerResources/UIxPreferences.js (initPreferences): + initialize calendar for the new vacation end date optional parameter. + + * UI/PreferencesUI/UIxPreferences.m (-enableVacationEndDate) + (-disableVacationEndDate, -setEnableVacationEndDate:) + (-vacationEndDate, -setVacationEndDate:): getters/setters for the + new optional vacation end date. + 2011-11-16 Ludovic Marcotte * SoObjects/SOGo/SOGoSieveManager.m (-updateFiltersForLogin:...) diff --git a/Tools/GNUmakefile b/Tools/GNUmakefile index ceb7af2ba..920ad2d82 100644 --- a/Tools/GNUmakefile +++ b/Tools/GNUmakefile @@ -16,7 +16,8 @@ $(SOGO_TOOL)_OBJC_FILES += \ SOGoToolRemoveDoubles.m \ SOGoToolRemove.m \ SOGoToolRenameUser.m \ - SOGoToolUserPreferences.m + SOGoToolUserPreferences.m \ + SOGoToolExpireAutoReply.m SOGO_SLAPD_SOCKD = sogo-slapd-sockd $(SOGO_SLAPD_SOCKD)_INSTALL_DIR = $(SOGO_ADMIN_TOOLS) diff --git a/Tools/SOGoToolExpireAutoReply.m b/Tools/SOGoToolExpireAutoReply.m new file mode 100644 index 000000000..7bfabb844 --- /dev/null +++ b/Tools/SOGoToolExpireAutoReply.m @@ -0,0 +1,198 @@ +/* SOGoToolUserPreferences.m - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc. + * + * Author: Francis Lachapelle + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import +#import +#import +#import +#import + +#import + +#import +#import + +#import + +#import +#import +#import +#import +#import + +#import "SOGoTool.h" + +@interface SOGoToolExpireAutoReply : SOGoTool +@end + +@implementation SOGoToolExpireAutoReply + ++ (void) initialize +{ +} + ++ (NSString *) command +{ + return @"expire-autoreply"; +} + ++ (NSString *) description +{ + return @"disable auto reply for reached end dates"; +} + +- (void) usage +{ + fprintf (stderr, "expire-autoreply authname:authpassword\n\n" + " authname administrator username of the Sieve server\n" + " authpassword administrator password of the Sieve server\n"); +} + +- (BOOL) removeAutoReplyForLogin: (NSString *) theLogin + withSieveUsername: (NSString *) theUsername + andPassword: (NSString *) thePassword +{ + NSMutableDictionary *vacationOptions; + SOGoUserDefaults *userDefaults; + SOGoSieveManager *manager; + SOGoUser *user; + BOOL result; + + user = [SOGoUser userWithLogin: theLogin]; + manager = [SOGoSieveManager sieveManagerForUser: user]; + userDefaults = [user userDefaults]; + vacationOptions = [[userDefaults vacationOptions] mutableCopy]; + [vacationOptions autorelease]; + + [vacationOptions setObject: [NSNumber numberWithBool: NO] forKey: @"enabled"]; + [userDefaults setVacationOptions: vacationOptions]; + result = [userDefaults synchronize]; + + if (result) + { + result = [manager updateFiltersForLogin: theLogin + authname: theUsername + password: thePassword + account: nil]; + if (!result) + { + // Can't update Sieve script -- Reactivate auto-reply + [vacationOptions setObject: [NSNumber numberWithBool: YES] forKey: @"enabled"]; + [userDefaults setVacationOptions: vacationOptions]; + [userDefaults synchronize]; + } + } + + return result; +} + +- (void) expireAutoReplyWithUsername: (NSString *) theUsername + andPassword: (NSString *) thePassword +{ + GCSChannelManager *cm; + EOAdaptorChannel *channel; + NSArray *attrs; + NSDictionary *infos, *defaults, *vacationOptions; + NSString *sql, *profileURL, *user, *c_defaults; + NSURL *tableURL; + SOGoSystemDefaults *sd; + BOOL enabled; + unsigned int endTime, now; + + now = [[NSCalendarDate calendarDate] timeIntervalSince1970]; + sd = [SOGoSystemDefaults sharedSystemDefaults]; + profileURL = [sd profileURL]; + if (profileURL) + { + tableURL = [[NSURL alloc] initWithString: profileURL]; + cm = [GCSChannelManager defaultChannelManager]; + channel = [cm acquireOpenChannelForURL: tableURL]; + if (channel) + { + sql = [NSString stringWithFormat: @"SELECT c_uid, c_defaults FROM %@", + [tableURL gcsTableName]]; + [channel evaluateExpressionX: sql]; + attrs = [channel describeResults: NO]; + while ((infos = [channel fetchAttributes: attrs withZone: NULL])) + { + user = [infos objectForKey: @"c_uid"]; + c_defaults = [infos objectForKey: @"c_defaults"]; + if ([c_defaults isNotNull]) + { + defaults = [c_defaults objectFromJSONString]; + vacationOptions = (NSDictionary *) [defaults objectForKey: @"Vacation"]; + enabled = [[vacationOptions objectForKey: @"enabled"] boolValue]; + if (enabled) + { + enabled = [[vacationOptions objectForKey: @"endDateEnabled"] boolValue]; + if (enabled) + { + endTime = [[vacationOptions objectForKey: @"endDate"] intValue]; + if (endTime <= now) + { + if ([self removeAutoReplyForLogin: user + withSieveUsername: theUsername + andPassword: thePassword]) + NSLog(@"Removed auto-reply of user %@", user); + else + NSLog(@"An error occured while removing auto-reply of user %@", user); + } + } + } + } + } + } + } +} + + +- (BOOL) run +{ + NSRange r; + NSString *creds, *authname, *authpwd; + BOOL rc; + int max; + + max = [arguments count]; + rc = NO; + + if (max > 0) + { + creds = [arguments objectAtIndex: 0]; + r = [creds rangeOfString: @":"]; + if (r.location != NSNotFound) + { + authname = [creds substringToIndex: r.location]; + authpwd = [creds substringFromIndex: r.location+1]; + [self expireAutoReplyWithUsername: authname andPassword: authpwd]; + rc = YES; + } + } + + if (!rc) + [self usage]; + + return rc; +} + +@end diff --git a/UI/PreferencesUI/English.lproj/Localizable.strings b/UI/PreferencesUI/English.lproj/Localizable.strings index 237719fb0..54063fd78 100644 --- a/UI/PreferencesUI/English.lproj/Localizable.strings +++ b/UI/PreferencesUI/English.lproj/Localizable.strings @@ -27,8 +27,11 @@ "Add default email addresses" = "Add default email addresses"; "Days between responses :" = "Days between responses :"; "Do not send responses to mailing lists" = "Do not send responses to mailing lists"; +"Disable auto reply on" = "Disable auto reply on"; "Please specify your message and your email addresses for which you want to enable auto reply." = "Please specify your message and your email addresses for which you want to enable auto reply."; +"End date of your auto reply must be in the future." += "End date of your auto reply must be in the future."; /* forward messages */ "Forward incoming messages" = "Forward incoming messages"; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 5548a97c4..c68246962 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -883,6 +883,40 @@ return ignore; } +- (BOOL) enableVacationEndDate +{ + return [[vacationOptions objectForKey: @"endDateEnabled"] boolValue]; +} + +- (BOOL) disableVacationEndDate +{ + return ![self enableVacationEndDate]; +} + +- (void) setEnableVacationEndDate: (BOOL) enableVacationEndDate +{ + [vacationOptions setObject: [NSNumber numberWithBool: enableVacationEndDate] + forKey: @"endDateEnabled"]; +} + +- (void) setVacationEndDate: (NSCalendarDate *) endDate +{ + NSNumber *time; + + time = [NSNumber numberWithInt: [endDate timeIntervalSince1970]]; + + [vacationOptions setObject: time forKey: @"endDate"]; +} + +- (NSCalendarDate *) vacationEndDate +{ + int time; + + time = [[vacationOptions objectForKey: @"endDate"] intValue]; + + return [NSCalendarDate dateWithTimeIntervalSince1970: time]; +} + /* mail forward */ - (BOOL) isForwardEnabled diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index e12d1db71..2b3cce7e4 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -10,7 +10,7 @@ className="UIxPageFrame" title="title" const:popup="YES" - const:jsFiles="RowEditionController.js,PasswordPolicy.js,ckeditor/ckeditor.js" + const:jsFiles="RowEditionController.js,PasswordPolicy.js,ckeditor/ckeditor.js,skycalendar.js" >