2007-06-19 19:58:21 +02:00
|
|
|
/* UIxPreferences.m - this file is part of SOGo
|
|
|
|
*
|
2019-08-15 18:48:53 +02:00
|
|
|
* Copyright (C) 2007-2019 Inverse inc.
|
2007-06-19 19:58:21 +02:00
|
|
|
*
|
|
|
|
* 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 <Foundation/NSCalendarDate.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <Foundation/NSUserDefaults.h> /* for locale strings */
|
2009-10-09 22:30:42 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
|
2013-11-11 16:49:58 +01:00
|
|
|
#import <NGImap4/NSString+Imap4.h>
|
|
|
|
|
2009-10-14 14:01:59 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2011-03-23 20:18:27 +01:00
|
|
|
#import <NGCards/iCalTimeZone.h>
|
|
|
|
|
2016-05-06 20:14:45 +02:00
|
|
|
#import <SOPE/NGCards/iCalRecurrenceRule.h>
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
2014-07-04 15:51:41 +02:00
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
2014-01-27 21:09:22 +01:00
|
|
|
#import <SOGo/SOGoSieveManager.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoSystemDefaults.h>
|
|
|
|
#import <SOGo/SOGoUserFolder.h>
|
2014-04-09 12:33:02 +02:00
|
|
|
#import <SOGo/SOGoParentFolder.h>
|
2016-06-14 20:10:17 +02:00
|
|
|
#import <SOGo/SOGoTextTemplateFile.h>
|
2011-02-03 17:12:22 +01:00
|
|
|
#import <SOGo/WOResourceManager+SOGo.h>
|
2014-03-10 19:45:10 +01:00
|
|
|
#import <SOGo/SOGoBuild.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <Mailer/SOGoMailAccount.h>
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <Mailer/SOGoMailAccounts.h>
|
2007-06-19 19:58:21 +02:00
|
|
|
|
2014-03-24 18:41:57 +01:00
|
|
|
#import <Contacts/SOGoContactGCSFolder.h>
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
#import "UIxPreferences.h"
|
|
|
|
|
2013-11-20 23:42:11 +01:00
|
|
|
static NSArray *reminderItems = nil;
|
|
|
|
static NSArray *reminderValues = nil;
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
@implementation UIxPreferences
|
|
|
|
|
2013-11-20 23:42:11 +01:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (!reminderItems && !reminderValues)
|
|
|
|
{
|
|
|
|
reminderItems = [NSArray arrayWithObjects:
|
2015-04-10 15:44:30 +02:00
|
|
|
@"NONE",
|
|
|
|
@"5_MINUTES_BEFORE",
|
2018-01-12 20:47:31 +01:00
|
|
|
@"10_MINUTES_BEFORE",
|
|
|
|
@"15_MINUTES_BEFORE",
|
|
|
|
@"30_MINUTES_BEFORE",
|
|
|
|
@"45_MINUTES_BEFORE",
|
|
|
|
@"1_HOUR_BEFORE",
|
|
|
|
@"2_HOURS_BEFORE",
|
|
|
|
@"5_HOURS_BEFORE",
|
|
|
|
@"15_HOURS_BEFORE",
|
|
|
|
@"1_DAY_BEFORE",
|
|
|
|
@"2_DAYS_BEFORE",
|
|
|
|
@"1_WEEK_BEFORE",
|
|
|
|
nil];
|
2013-11-20 23:42:11 +01:00
|
|
|
reminderValues = [NSArray arrayWithObjects:
|
2015-04-10 15:44:30 +02:00
|
|
|
@"NONE",
|
|
|
|
@"-PT5M",
|
2018-01-12 20:47:31 +01:00
|
|
|
@"-PT10M",
|
|
|
|
@"-PT15M",
|
|
|
|
@"-PT30M",
|
|
|
|
@"-PT45M",
|
|
|
|
@"-PT1H",
|
|
|
|
@"-PT2H",
|
|
|
|
@"-PT5H",
|
|
|
|
@"-PT15H",
|
|
|
|
@"-P1D",
|
|
|
|
@"-P2D",
|
|
|
|
@"-P1W",
|
|
|
|
nil];
|
2013-11-20 23:42:11 +01:00
|
|
|
|
|
|
|
[reminderItems retain];
|
|
|
|
[reminderValues retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
2018-08-20 20:01:37 +02:00
|
|
|
NSCalendarDate *referenceDate;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoDomainDefaults *dd;
|
2014-05-01 20:07:25 +02:00
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
item = nil;
|
2014-03-27 20:27:48 +01:00
|
|
|
addressBooksIDWithDisplayName = nil;
|
2014-04-04 21:04:37 +02:00
|
|
|
client = nil;
|
2010-08-06 17:34:05 +02:00
|
|
|
#warning user should be the owner rather than the activeUser
|
2007-06-19 19:58:21 +02:00
|
|
|
ASSIGN (user, [context activeUser]);
|
2018-08-20 20:01:37 +02:00
|
|
|
referenceDate = [NSCalendarDate date];
|
|
|
|
if ([referenceDate dayOfMonth] > 9)
|
|
|
|
referenceDate = [referenceDate addYear:0 month:0 day:(-[referenceDate dayOfMonth] + 1) hour:0 minute:0 second:0];
|
|
|
|
ASSIGN (today, referenceDate);
|
2009-11-29 05:19:32 +01:00
|
|
|
|
2009-12-01 17:53:15 +01:00
|
|
|
calendarCategories = nil;
|
|
|
|
calendarCategoriesColors = nil;
|
|
|
|
category = nil;
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
ASSIGN (daysOfWeek, [locale objectForKey: NSWeekDayNameArray]);
|
2009-10-09 22:30:42 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
dd = [user domainDefaults];
|
2010-03-02 20:57:30 +01:00
|
|
|
if ([dd sieveScriptsEnabled])
|
|
|
|
{
|
|
|
|
sieveFilters = [[userDefaults sieveFilters] copy];
|
|
|
|
if (!sieveFilters)
|
|
|
|
sieveFilters = [NSArray new];
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
if ([dd vacationEnabled])
|
2009-10-09 22:30:42 +02:00
|
|
|
{
|
2009-12-01 15:29:56 +01:00
|
|
|
vacationOptions = [[userDefaults vacationOptions] mutableCopy];
|
2009-10-09 22:30:42 +02:00
|
|
|
if (!vacationOptions)
|
2009-12-07 17:16:01 +01:00
|
|
|
vacationOptions = [NSMutableDictionary new];
|
2009-10-09 22:30:42 +02:00
|
|
|
}
|
2009-11-26 17:59:29 +01:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
if ([dd forwardEnabled])
|
2009-10-09 22:30:42 +02:00
|
|
|
{
|
2009-12-01 15:29:56 +01:00
|
|
|
forwardOptions = [[userDefaults forwardOptions] mutableCopy];
|
2009-10-09 22:30:42 +02:00
|
|
|
if (!forwardOptions)
|
2009-12-07 17:16:01 +01:00
|
|
|
forwardOptions = [NSMutableDictionary new];
|
2009-10-09 22:30:42 +02:00
|
|
|
}
|
2010-03-25 21:17:50 +01:00
|
|
|
|
2012-04-20 15:37:46 +02:00
|
|
|
mailCustomFromEnabled = [dd mailCustomFromEnabled];
|
2016-02-09 20:15:23 +01:00
|
|
|
forwardEnabled = [dd forwardEnabled];
|
2012-04-20 15:37:46 +02:00
|
|
|
|
2010-03-25 21:17:50 +01:00
|
|
|
hasChanged = NO;
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[today release];
|
|
|
|
[item release];
|
|
|
|
[user release];
|
2010-03-02 20:57:30 +01:00
|
|
|
[sieveFilters release];
|
2009-11-26 17:59:29 +01:00
|
|
|
[vacationOptions release];
|
2009-12-01 17:53:15 +01:00
|
|
|
[calendarCategories release];
|
|
|
|
[calendarCategoriesColors release];
|
|
|
|
[category release];
|
2010-10-26 21:26:50 +02:00
|
|
|
[contactsCategories release];
|
2009-11-26 17:59:29 +01:00
|
|
|
[forwardOptions release];
|
2007-06-19 19:58:21 +02:00
|
|
|
[daysOfWeek release];
|
2014-03-28 15:28:33 +01:00
|
|
|
[addressBooksIDWithDisplayName release];
|
2014-03-10 15:33:27 +01:00
|
|
|
[client release];
|
2007-06-19 19:58:21 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2015-09-19 02:30:35 +02:00
|
|
|
- (NSString *) modulePath
|
|
|
|
{
|
|
|
|
return @"Preferences";
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
// - (void) setHasChanged: (BOOL) newHasChanged
|
|
|
|
// {
|
|
|
|
// hasChanged = newHasChanged;
|
|
|
|
// }
|
2010-03-25 21:17:50 +01:00
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
// - (BOOL) hasChanged
|
|
|
|
// {
|
|
|
|
// return hasChanged;
|
|
|
|
// }
|
2010-03-25 21:17:50 +01:00
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
- (void) setItem: (NSString *) newItem
|
|
|
|
{
|
|
|
|
ASSIGN (item, newItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) item
|
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
2015-07-21 21:21:57 +02:00
|
|
|
// Used by wox template, as a var.
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
2015-07-21 21:21:57 +02:00
|
|
|
- (NSString *) timeZonesList
|
2007-06-19 19:58:21 +02:00
|
|
|
{
|
2015-07-21 21:21:57 +02:00
|
|
|
return [[[iCalTimeZone knownTimeZoneNames] sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)] jsonRepresentation];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSArray *) shortDateFormatsList
|
|
|
|
{
|
|
|
|
NSMutableArray *shortDateFormatsList = nil;
|
|
|
|
NSString *key, *currentFormat;
|
|
|
|
unsigned int nbr;
|
|
|
|
BOOL done;
|
|
|
|
|
2015-07-30 01:10:03 +02:00
|
|
|
shortDateFormatsList = [NSMutableArray array];
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
nbr = 0;
|
|
|
|
done = NO;
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
key = [NSString stringWithFormat: @"shortDateFmt_%d", nbr];
|
|
|
|
currentFormat = [self labelForKey: key];
|
|
|
|
if ([currentFormat length] > 0)
|
2009-10-05 17:30:25 +02:00
|
|
|
{
|
|
|
|
[shortDateFormatsList addObject: currentFormat];
|
|
|
|
nbr++;
|
|
|
|
}
|
2007-06-19 19:58:21 +02:00
|
|
|
else
|
2009-10-05 17:30:25 +02:00
|
|
|
done = YES;
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return shortDateFormatsList;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSString *) itemShortDateFormatText
|
|
|
|
{
|
2009-10-08 18:24:31 +02:00
|
|
|
NSString *todayText, *shortDateFormatText;
|
|
|
|
|
|
|
|
if ([item isEqualToString: @"default"])
|
|
|
|
{
|
|
|
|
todayText = [today descriptionWithCalendarFormat: [locale objectForKey: NSShortDateFormatString]
|
|
|
|
locale: locale];
|
|
|
|
shortDateFormatText = [NSString stringWithFormat: @"%@ (%@)",
|
|
|
|
[self labelForKey: item],
|
|
|
|
todayText];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
shortDateFormatText = [today descriptionWithCalendarFormat: item
|
|
|
|
locale: locale];
|
|
|
|
|
|
|
|
return shortDateFormatText;
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
|
|
|
- (NSString *) _userLongDateFormat
|
2007-06-19 19:58:21 +02:00
|
|
|
{
|
2015-03-22 13:00:21 +01:00
|
|
|
NSString *longDateFormat;
|
|
|
|
|
|
|
|
longDateFormat = [userDefaults longDateFormat];
|
|
|
|
if (!longDateFormat)
|
|
|
|
longDateFormat = @"default";
|
|
|
|
|
|
|
|
return longDateFormat;
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSArray *) longDateFormatsList
|
|
|
|
{
|
|
|
|
NSMutableArray *longDateFormatsList = nil;
|
|
|
|
NSString *key, *currentFormat;
|
|
|
|
unsigned int nbr;
|
|
|
|
BOOL done;
|
|
|
|
|
2009-10-08 18:24:31 +02:00
|
|
|
longDateFormatsList = [NSMutableArray arrayWithObject: @"default"];
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
nbr = 0;
|
|
|
|
done = NO;
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
key = [NSString stringWithFormat: @"longDateFmt_%d", nbr];
|
|
|
|
currentFormat = [self labelForKey: key];
|
|
|
|
if ([currentFormat length] > 0)
|
2009-10-05 17:30:25 +02:00
|
|
|
{
|
|
|
|
[longDateFormatsList addObject: currentFormat];
|
|
|
|
nbr++;
|
|
|
|
}
|
2007-06-19 19:58:21 +02:00
|
|
|
else
|
2009-10-05 17:30:25 +02:00
|
|
|
done = YES;
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
if (![longDateFormatsList containsObject: [self _userLongDateFormat]])
|
|
|
|
[longDateFormatsList addObject: [self _userLongDateFormat]];
|
2014-05-01 20:07:25 +02:00
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
return longDateFormatsList;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSString *) itemLongDateFormatText
|
|
|
|
{
|
2009-10-08 18:24:31 +02:00
|
|
|
NSString *todayText, *longDateFormatText;
|
|
|
|
|
|
|
|
if ([item isEqualToString: @"default"])
|
|
|
|
{
|
|
|
|
todayText = [today descriptionWithCalendarFormat: [locale objectForKey: NSDateFormatString]
|
|
|
|
locale: locale];
|
|
|
|
longDateFormatText = [NSString stringWithFormat: @"%@ (%@)",
|
|
|
|
[self labelForKey: item],
|
|
|
|
todayText];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
longDateFormatText = [today descriptionWithCalendarFormat: item
|
|
|
|
locale: locale];
|
2009-10-09 00:04:36 +02:00
|
|
|
|
|
|
|
return longDateFormatText;
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSArray *) timeFormatsList
|
|
|
|
{
|
|
|
|
NSMutableArray *timeFormatsList = nil;
|
|
|
|
NSString *key, *currentFormat;
|
|
|
|
unsigned int nbr;
|
|
|
|
BOOL done;
|
|
|
|
|
2009-10-08 18:24:31 +02:00
|
|
|
timeFormatsList = [NSMutableArray arrayWithObject: @"default"];
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
nbr = 0;
|
|
|
|
done = NO;
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
key = [NSString stringWithFormat: @"timeFmt_%d", nbr];
|
|
|
|
currentFormat = [self labelForKey: key];
|
|
|
|
if ([currentFormat length] > 0)
|
2009-10-05 17:30:25 +02:00
|
|
|
{
|
|
|
|
[timeFormatsList addObject: currentFormat];
|
|
|
|
nbr++;
|
|
|
|
}
|
2007-06-19 19:58:21 +02:00
|
|
|
else
|
2009-10-05 17:30:25 +02:00
|
|
|
done = YES;
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return timeFormatsList;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSString *) itemTimeFormatText
|
|
|
|
{
|
2009-10-08 18:24:31 +02:00
|
|
|
NSString *todayText, *timeFormatText;
|
2010-01-20 15:53:49 +01:00
|
|
|
SOGoDomainDefaults *dd;
|
2009-10-08 18:24:31 +02:00
|
|
|
|
|
|
|
if ([item isEqualToString: @"default"])
|
|
|
|
{
|
2010-01-20 15:53:49 +01:00
|
|
|
dd = [user domainDefaults];
|
|
|
|
todayText = [today descriptionWithCalendarFormat: [dd timeFormat]
|
2009-10-08 18:24:31 +02:00
|
|
|
locale: locale];
|
|
|
|
timeFormatText = [NSString stringWithFormat: @"%@ (%@)",
|
|
|
|
[self labelForKey: item],
|
|
|
|
todayText];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
timeFormatText = [today descriptionWithCalendarFormat: item
|
|
|
|
locale: locale];
|
|
|
|
|
|
|
|
return timeFormatText;
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSArray *) daysList
|
|
|
|
{
|
|
|
|
NSMutableArray *daysList;
|
|
|
|
unsigned int currentDay;
|
|
|
|
|
2009-10-14 14:01:59 +02:00
|
|
|
daysList = [NSMutableArray array];
|
2007-06-19 19:58:21 +02:00
|
|
|
for (currentDay = 0; currentDay < 7; currentDay++)
|
|
|
|
[daysList addObject: [NSString stringWithFormat: @"%d", currentDay]];
|
|
|
|
|
|
|
|
return daysList;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSString *) itemWeekStartDay
|
|
|
|
{
|
|
|
|
return [daysOfWeek objectAtIndex: [item intValue]];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2011-09-23 21:25:56 +02:00
|
|
|
- (NSArray *) defaultCalendarList
|
|
|
|
{
|
|
|
|
NSMutableArray *options;
|
|
|
|
|
|
|
|
options = [NSArray arrayWithObjects: @"selected", @"personal", @"first", nil];
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2011-09-23 21:25:56 +02:00
|
|
|
- (NSString *) itemCalendarText
|
|
|
|
{
|
|
|
|
return [self labelForKey: [NSString stringWithFormat: @"%@Calendar", item]];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2012-02-20 23:25:49 +01:00
|
|
|
- (NSArray *) calendarClassificationsList
|
|
|
|
{
|
|
|
|
static NSArray *classifications = nil;
|
|
|
|
|
|
|
|
if (!classifications)
|
|
|
|
classifications = [[NSArray alloc] initWithObjects:
|
|
|
|
@"PUBLIC",
|
|
|
|
@"CONFIDENTIAL",
|
|
|
|
@"PRIVATE",
|
|
|
|
nil];
|
|
|
|
|
|
|
|
return classifications;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2012-02-20 23:25:49 +01:00
|
|
|
- (NSString *) itemClassificationText
|
|
|
|
{
|
|
|
|
return [self labelForKey: [NSString stringWithFormat: @"%@_item",
|
|
|
|
item]];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2015-04-10 15:44:30 +02:00
|
|
|
- (NSArray *) reminderValues
|
2013-11-20 23:42:11 +01:00
|
|
|
{
|
2015-04-10 15:44:30 +02:00
|
|
|
return reminderValues;
|
2013-11-20 23:42:11 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2013-11-20 23:42:11 +01:00
|
|
|
- (NSString *) itemReminderText
|
|
|
|
{
|
|
|
|
NSString *text;
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if ([item isEqualToString: @""])
|
|
|
|
text = @"-";
|
2013-11-20 23:42:11 +01:00
|
|
|
else
|
2015-04-10 15:44:30 +02:00
|
|
|
{
|
|
|
|
NSUInteger index;
|
|
|
|
|
|
|
|
index = [reminderValues indexOfObject: item];
|
|
|
|
|
|
|
|
if (index != NSNotFound)
|
|
|
|
text = [self labelForKey: [NSString stringWithFormat: @"reminder_%@", [reminderItems objectAtIndex: index]]];
|
|
|
|
else
|
|
|
|
text = @"NONE";
|
|
|
|
}
|
2013-11-20 23:42:11 +01:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSArray *) hoursList
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
static NSMutableArray *hours = nil;
|
2007-06-19 19:58:21 +02:00
|
|
|
unsigned int currentHour;
|
|
|
|
|
|
|
|
if (!hours)
|
|
|
|
{
|
|
|
|
hours = [[NSMutableArray alloc] initWithCapacity: 24];
|
|
|
|
for (currentHour = 0; currentHour < 24; currentHour++)
|
2009-10-05 17:30:25 +02:00
|
|
|
[hours addObject: [NSString stringWithFormat: @"%.2d:00",
|
|
|
|
currentHour]];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hours;
|
|
|
|
}
|
|
|
|
|
2016-05-06 20:14:45 +02:00
|
|
|
- (NSArray *) shortWeekDaysList
|
|
|
|
{
|
|
|
|
static NSArray *shortWeekDaysList = nil;
|
|
|
|
|
|
|
|
if (!shortWeekDaysList)
|
|
|
|
{
|
|
|
|
shortWeekDaysList = [locale objectForKey: NSShortWeekDayNameArray];
|
|
|
|
[shortWeekDaysList retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return shortWeekDaysList;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) valueForWeekDay
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
i = [[self shortWeekDaysList] indexOfObject: item];
|
|
|
|
|
|
|
|
return iCalWeekDayString[i];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSArray *) firstWeekList
|
|
|
|
{
|
2009-10-06 20:12:07 +02:00
|
|
|
return [NSArray arrayWithObjects:
|
2009-10-05 17:30:25 +02:00
|
|
|
SOGoWeekStartJanuary1,
|
|
|
|
SOGoWeekStartFirst4DayWeek,
|
|
|
|
SOGoWeekStartFirstFullWeek,
|
|
|
|
nil];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-06-19 19:58:21 +02:00
|
|
|
- (NSString *) itemFirstWeekText
|
|
|
|
{
|
|
|
|
return [self labelForKey: [NSString stringWithFormat: @"firstWeekOfYear_%@",
|
2009-10-05 17:30:25 +02:00
|
|
|
item]];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2014-03-24 18:41:57 +01:00
|
|
|
- (NSArray *) addressBookList
|
|
|
|
{
|
2015-04-13 15:47:33 +02:00
|
|
|
NSMutableArray *folders, *localAddressBooks;
|
|
|
|
SOGoParentFolder *contactFolder;
|
|
|
|
SOGoContactGCSFolder *addressbook;
|
2014-03-25 19:53:42 +01:00
|
|
|
int i, count;
|
2014-03-27 20:27:48 +01:00
|
|
|
BOOL collectedAlreadyExist;
|
2015-04-13 15:47:33 +02:00
|
|
|
|
|
|
|
// Fetch all addressbooks
|
|
|
|
contactFolder = [[[context activeUser] homeFolderInContext: context]
|
2014-06-30 16:35:55 +02:00
|
|
|
lookupName: @"Contacts"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
2015-04-13 15:47:33 +02:00
|
|
|
folders = [NSMutableArray arrayWithArray: [contactFolder subFolders]];
|
|
|
|
count = [folders count];
|
|
|
|
|
|
|
|
// Remove all public addressbooks
|
|
|
|
for (count--; count >= 0; count--)
|
2014-06-30 16:35:55 +02:00
|
|
|
{
|
|
|
|
if (![[folders objectAtIndex: count] isKindOfClass: [SOGoContactGCSFolder class]])
|
|
|
|
[folders removeObjectAtIndex: count];
|
|
|
|
}
|
2015-04-13 15:47:33 +02:00
|
|
|
|
|
|
|
// Build list of local addressbooks
|
|
|
|
localAddressBooks = [NSMutableArray arrayWithCapacity: [folders count]];
|
|
|
|
count = [folders count];
|
2014-04-09 12:33:02 +02:00
|
|
|
collectedAlreadyExist = NO;
|
2015-04-13 15:47:33 +02:00
|
|
|
|
|
|
|
for (i = 0; i < count ; i++)
|
2014-06-30 16:35:55 +02:00
|
|
|
{
|
2015-04-13 15:47:33 +02:00
|
|
|
addressbook = [folders objectAtIndex: i];
|
|
|
|
[localAddressBooks addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[addressbook nameInContainer], @"id",
|
|
|
|
[addressbook displayName], @"name",
|
|
|
|
nil]];
|
|
|
|
if ([[addressbook nameInContainer] isEqualToString: @"collected"])
|
2014-06-30 16:35:55 +02:00
|
|
|
collectedAlreadyExist = YES;
|
|
|
|
}
|
2014-06-26 22:08:47 +02:00
|
|
|
if (!collectedAlreadyExist)
|
2014-06-30 16:35:55 +02:00
|
|
|
{
|
2015-04-13 15:47:33 +02:00
|
|
|
[localAddressBooks addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"collected", @"id",
|
|
|
|
[self labelForKey: @"Collected Address Book"], @"name",
|
|
|
|
nil]];
|
2014-06-30 16:35:55 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 15:47:33 +02:00
|
|
|
return localAddressBooks;
|
2014-03-24 18:41:57 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2014-08-29 19:16:30 +02:00
|
|
|
- (NSArray *) refreshViewList
|
2007-10-26 17:35:51 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
NSArray *intervalsList;
|
2014-08-29 19:16:30 +02:00
|
|
|
NSMutableArray *refreshViewList;
|
2009-11-29 05:19:32 +01:00
|
|
|
NSString *value;
|
|
|
|
int count, max, interval;
|
2009-07-31 19:52:49 +02:00
|
|
|
|
2014-08-29 19:16:30 +02:00
|
|
|
intervalsList = [[user domainDefaults] refreshViewIntervals];
|
|
|
|
refreshViewList = [NSMutableArray arrayWithObjects: @"manually", nil];
|
2009-11-29 05:19:32 +01:00
|
|
|
max = [intervalsList count];
|
|
|
|
for (count = 0; count < max; count++)
|
2009-07-31 19:52:49 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
interval = [[intervalsList objectAtIndex: count] intValue];
|
|
|
|
value = nil;
|
|
|
|
if (interval == 1)
|
|
|
|
value = @"every_minute";
|
|
|
|
else if (interval == 60)
|
|
|
|
value = @"once_per_hour";
|
2016-05-25 22:04:58 +02:00
|
|
|
else if (interval == 2 || interval == 5 || interval == 10
|
2009-11-29 05:19:32 +01:00
|
|
|
|| interval == 20 || interval == 30)
|
|
|
|
value = [NSString stringWithFormat: @"every_%d_minutes", interval];
|
|
|
|
else
|
2009-07-31 19:52:49 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
[self warnWithFormat: @"interval '%d' not handled", interval];
|
|
|
|
value = nil;
|
2009-07-31 19:52:49 +02:00
|
|
|
}
|
2009-11-29 05:19:32 +01:00
|
|
|
if (value)
|
2014-08-29 19:16:30 +02:00
|
|
|
[refreshViewList addObject: value];
|
2009-07-31 19:52:49 +02:00
|
|
|
}
|
|
|
|
|
2014-08-29 19:16:30 +02:00
|
|
|
return refreshViewList;
|
2007-10-26 17:35:51 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2014-08-29 19:16:30 +02:00
|
|
|
- (NSString *) itemRefreshViewCheckText
|
2007-10-26 17:35:51 +02:00
|
|
|
{
|
2014-08-29 19:16:30 +02:00
|
|
|
return [self labelForKey: [NSString stringWithFormat: @"refreshview_%@", item]];
|
2007-10-26 17:35:51 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-08-22 17:18:01 +02:00
|
|
|
- (NSArray *) messageForwardingList
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects: @"inline", @"attached", nil];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2007-08-22 17:18:01 +02:00
|
|
|
- (NSString *) itemMessageForwardingText
|
|
|
|
{
|
|
|
|
return [self labelForKey:
|
2009-10-05 17:30:25 +02:00
|
|
|
[NSString stringWithFormat: @"messageforward_%@", item]];
|
2007-08-22 17:18:01 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2008-09-28 21:49:17 +02:00
|
|
|
- (NSArray *) replyPlacementList
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects: @"above", @"below", nil];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2008-09-28 21:49:17 +02:00
|
|
|
- (NSString *) itemReplyPlacementText
|
|
|
|
{
|
|
|
|
return [self labelForKey:
|
2009-10-05 17:30:25 +02:00
|
|
|
[NSString stringWithFormat: @"replyplacement_%@", item]];
|
2008-09-28 21:49:17 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2009-11-29 05:19:32 +01:00
|
|
|
- (NSString *) itemSignaturePlacementText
|
|
|
|
{
|
|
|
|
return [self labelForKey:
|
|
|
|
[NSString stringWithFormat: @"signatureplacement_%@", item]];
|
2008-09-28 21:49:17 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2008-09-28 21:49:17 +02:00
|
|
|
- (NSArray *) signaturePlacementList
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects: @"above", @"below", nil];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2009-06-23 19:53:18 +02:00
|
|
|
- (NSArray *) composeMessagesType
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects: @"text", @"html", nil];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2009-06-23 19:53:18 +02:00
|
|
|
- (NSString *) itemComposeMessagesText
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [self labelForKey: [NSString stringWithFormat:
|
|
|
|
@"composemessagestype_%@", item]];
|
2009-06-23 19:53:18 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2012-10-26 19:39:28 +02:00
|
|
|
- (NSArray *) displayRemoteInlineImages
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects: @"never", @"always", nil];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2012-10-26 19:39:28 +02:00
|
|
|
- (NSString *) itemDisplayRemoteInlineImagesText
|
|
|
|
{
|
|
|
|
return [self labelForKey: [NSString stringWithFormat:
|
|
|
|
@"displayremoteinlineimages_%@", item]];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2010-03-02 20:57:30 +01:00
|
|
|
- (BOOL) isSieveScriptsEnabled
|
|
|
|
{
|
|
|
|
return [[user domainDefaults] sieveScriptsEnabled];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2010-03-02 20:57:30 +01:00
|
|
|
- (NSString *) sieveCapabilities
|
|
|
|
{
|
|
|
|
static NSArray *capabilities = nil;
|
|
|
|
|
|
|
|
if (!capabilities)
|
|
|
|
{
|
2015-08-19 14:47:33 +02:00
|
|
|
if ([self isSieveScriptsEnabled] && [self _sieveClient])
|
2015-03-22 13:00:21 +01:00
|
|
|
capabilities = [[self _sieveClient] capabilities];
|
2014-01-27 21:09:22 +01:00
|
|
|
else
|
|
|
|
capabilities = [NSArray array];
|
2014-06-30 16:35:55 +02:00
|
|
|
[capabilities retain];
|
2010-03-02 20:57:30 +01:00
|
|
|
}
|
|
|
|
|
2010-11-02 14:16:05 +01:00
|
|
|
return [capabilities jsonRepresentation];
|
2010-03-02 20:57:30 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2009-10-09 22:30:42 +02:00
|
|
|
- (BOOL) isVacationEnabled
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [[user domainDefaults] vacationEnabled];
|
2009-10-09 22:30:42 +02:00
|
|
|
}
|
|
|
|
|
2019-11-05 21:33:16 +01:00
|
|
|
- (BOOL) isVacationPeriodEnabled
|
|
|
|
{
|
|
|
|
return [[user domainDefaults] vacationPeriodEnabled];
|
|
|
|
}
|
|
|
|
|
2016-06-14 20:10:17 +02:00
|
|
|
- (NSString *) vacationHeader
|
|
|
|
{
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
path = [[user domainDefaults] vacationHeaderTemplateFile];
|
|
|
|
|
|
|
|
return [self _vacationTextForTemplate: path];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) vacationFooter
|
|
|
|
{
|
|
|
|
NSString *path;
|
|
|
|
|
|
|
|
path = [[user domainDefaults] vacationFooterTemplateFile];
|
|
|
|
|
|
|
|
return [self _vacationTextForTemplate: path];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _vacationTextForTemplate: (NSString *) templateFilePath
|
|
|
|
{
|
|
|
|
NSString *text;
|
|
|
|
SOGoTextTemplateFile *templateFile;
|
|
|
|
|
|
|
|
text = nil;
|
|
|
|
if (templateFilePath)
|
|
|
|
{
|
|
|
|
templateFile = [SOGoTextTemplateFile textTemplateFromFile: templateFilePath];
|
|
|
|
if (templateFile)
|
|
|
|
text = [templateFile textForUser: user];
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
|
|
|
- (NSString *) _defaultEmailAddresses
|
2009-10-09 22:30:42 +02:00
|
|
|
{
|
|
|
|
NSArray *addressesList;
|
2009-10-15 00:11:13 +02:00
|
|
|
NSMutableArray *uniqueAddressesList;
|
2009-10-09 22:30:42 +02:00
|
|
|
NSString *address;
|
|
|
|
unsigned int i;
|
|
|
|
|
2009-10-15 00:11:13 +02:00
|
|
|
uniqueAddressesList = [NSMutableArray array];
|
|
|
|
addressesList = [NSMutableArray arrayWithArray: [user allEmails]];
|
2009-11-29 05:19:32 +01:00
|
|
|
for (i = 0; i < [addressesList count]; i++)
|
2009-10-09 22:30:42 +02:00
|
|
|
{
|
2009-10-15 00:11:13 +02:00
|
|
|
address = [addressesList objectAtIndex: i];
|
|
|
|
if (![uniqueAddressesList containsObject: address])
|
|
|
|
[uniqueAddressesList addObject: address];
|
2009-10-09 22:30:42 +02:00
|
|
|
}
|
|
|
|
|
2009-10-15 00:11:13 +02:00
|
|
|
return [uniqueAddressesList componentsJoinedByString: @", "];
|
|
|
|
}
|
|
|
|
|
2019-03-07 17:22:00 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
|
|
|
- (NSDictionary *) _localizedCategoryLabels
|
|
|
|
{
|
|
|
|
NSArray *categoryLabels, *localizedCategoryLabels;
|
|
|
|
NSDictionary *labelsDictionary;
|
|
|
|
|
|
|
|
labelsDictionary = nil;
|
|
|
|
localizedCategoryLabels = [[self labelForKey: @"calendar_category_labels"
|
|
|
|
withResourceManager: [self resourceManager]]
|
|
|
|
componentsSeparatedByString: @","];
|
|
|
|
categoryLabels = [[[self resourceManager]
|
|
|
|
stringForKey: @"calendar_category_labels"
|
|
|
|
inTableNamed: nil
|
|
|
|
withDefaultValue: @""
|
|
|
|
languages: [NSArray arrayWithObject: @"English"]]
|
|
|
|
componentsSeparatedByString: @","];
|
|
|
|
|
|
|
|
if ([localizedCategoryLabels count] == [categoryLabels count])
|
|
|
|
labelsDictionary = [NSDictionary dictionaryWithObjects: localizedCategoryLabels
|
|
|
|
forKeys: categoryLabels];
|
|
|
|
else
|
|
|
|
[self logWithFormat: @"ERROR: localizable strings calendar_category_labels is incorrect for language %@",
|
|
|
|
[[[context activeUser] userDefaults] language]];
|
|
|
|
|
|
|
|
return labelsDictionary;
|
|
|
|
}
|
|
|
|
|
2018-09-08 03:38:31 +02:00
|
|
|
//
|
|
|
|
// Used by templates
|
|
|
|
//
|
|
|
|
- (NSString *) defaultCalendarCategoriesColors
|
|
|
|
{
|
2019-03-07 17:22:00 +01:00
|
|
|
NSArray *labels;
|
|
|
|
NSDictionary *localizedLabels, *colors;
|
2018-09-08 03:38:31 +02:00
|
|
|
NSMutableDictionary *defaultCategoriesColors;
|
2019-03-07 17:22:00 +01:00
|
|
|
NSString *label, *localizedLabel, *color;
|
2018-09-08 03:38:31 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2019-03-07 17:22:00 +01:00
|
|
|
localizedLabels = [self _localizedCategoryLabels];
|
|
|
|
labels = [[SOGoSystemDefaults sharedSystemDefaults] calendarCategories];
|
|
|
|
colors = [[SOGoSystemDefaults sharedSystemDefaults] calendarCategoriesColors];
|
2018-10-18 21:32:08 +02:00
|
|
|
|
|
|
|
if ([colors count] > [labels count])
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"Incomplete calendar_category_labels for translation %@", [[user userDefaults] language]];
|
|
|
|
}
|
|
|
|
|
2018-09-08 03:38:31 +02:00
|
|
|
defaultCategoriesColors = [NSMutableDictionary dictionary];
|
2018-10-18 21:32:08 +02:00
|
|
|
for (i = 0; i < [colors count] && i < [labels count]; i++)
|
2018-09-08 03:38:31 +02:00
|
|
|
{
|
2019-03-07 17:22:00 +01:00
|
|
|
label = [labels objectAtIndex: i];
|
|
|
|
color = [colors objectForKey: label];
|
|
|
|
if (!(localizedLabel = [localizedLabels objectForKey: label]))
|
|
|
|
{
|
|
|
|
localizedLabel = label;
|
|
|
|
}
|
|
|
|
[defaultCategoriesColors setObject: color
|
|
|
|
forKey: localizedLabel];
|
2018-09-08 03:38:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return [defaultCategoriesColors jsonRepresentation];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by templates
|
|
|
|
//
|
2009-10-15 00:11:13 +02:00
|
|
|
- (NSString *) autoReplyEmailAddresses
|
|
|
|
{
|
|
|
|
NSArray *addressesList;
|
2014-05-01 20:07:25 +02:00
|
|
|
|
2009-10-15 00:11:13 +02:00
|
|
|
addressesList = [vacationOptions objectForKey: @"autoReplyEmailAddresses"];
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
return (addressesList
|
|
|
|
? [addressesList componentsJoinedByString: @", "]
|
2015-03-22 13:00:21 +01:00
|
|
|
: [self _defaultEmailAddresses]);
|
2009-10-09 22:30:42 +02:00
|
|
|
}
|
|
|
|
|
2016-02-11 22:45:58 +01:00
|
|
|
//
|
|
|
|
// Used by templates
|
|
|
|
//
|
|
|
|
- (NSArray *) fontSizesList
|
|
|
|
{
|
|
|
|
static NSArray *fontSizes = nil;
|
|
|
|
|
|
|
|
if (!fontSizes)
|
|
|
|
{
|
|
|
|
fontSizes = [NSArray arrayWithObjects: @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"16", @"18",
|
|
|
|
@"20", @"22", @"24", @"26", @"28",
|
|
|
|
@"36",
|
|
|
|
@"48",
|
|
|
|
@"72",
|
|
|
|
nil];
|
|
|
|
[fontSizes retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return fontSizes;
|
|
|
|
}
|
|
|
|
|
2016-06-14 22:11:12 +02:00
|
|
|
- (NSString *) itemFontSizeText
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@ px", item];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by templates
|
|
|
|
//
|
2009-10-09 22:30:42 +02:00
|
|
|
- (NSArray *) daysBetweenResponsesList
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
static NSArray *daysBetweenResponses = nil;
|
2009-10-09 22:30:42 +02:00
|
|
|
|
|
|
|
if (!daysBetweenResponses)
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
daysBetweenResponses = [NSArray arrayWithObjects: @"1", @"2", @"3",
|
|
|
|
@"5", @"7", @"14", @"21", @"30", nil];
|
2009-10-09 22:30:42 +02:00
|
|
|
[daysBetweenResponses retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return daysBetweenResponses;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mail forward */
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by templates
|
|
|
|
//
|
2009-10-09 22:30:42 +02:00
|
|
|
- (BOOL) isForwardEnabled
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [[user domainDefaults] forwardEnabled];
|
2009-10-09 22:30:42 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 15:22:12 +02:00
|
|
|
- (NSString *) forwardConstraints
|
|
|
|
{
|
|
|
|
SOGoDomainDefaults *dd;
|
2015-02-11 20:30:40 +01:00
|
|
|
|
2015-06-29 15:22:12 +02:00
|
|
|
dd = [[context activeUser] domainDefaults];
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%d", [dd forwardConstraints]];
|
|
|
|
}
|
2009-10-09 22:30:42 +02:00
|
|
|
|
2019-08-15 18:48:53 +02:00
|
|
|
- (NSString *) forwardConstraintsDomains
|
|
|
|
{
|
|
|
|
NSMutableArray *domains;
|
|
|
|
SOGoDomainDefaults *dd;
|
|
|
|
|
|
|
|
dd = [[context activeUser] domainDefaults];
|
|
|
|
domains = [NSMutableArray array];
|
|
|
|
[domains addObjectsFromArray: [dd forwardConstraintsDomains]];
|
|
|
|
|
|
|
|
return [domains jsonRepresentation];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by templates
|
|
|
|
//
|
2009-08-19 19:19:32 +02:00
|
|
|
- (NSArray *) availableModules
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
NSMutableArray *availableModules, *modules;
|
|
|
|
NSString *module;
|
|
|
|
int count, max;
|
2009-08-19 19:19:32 +02:00
|
|
|
|
|
|
|
modules = [NSMutableArray arrayWithObjects: @"Calendar", @"Mail", nil];
|
2009-11-29 05:19:32 +01:00
|
|
|
availableModules = [NSMutableArray arrayWithObjects: @"Last", @"Contacts",
|
|
|
|
nil];
|
|
|
|
max = [modules count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
module = [modules objectAtIndex: count];
|
|
|
|
if ([user canAccessModule: module])
|
|
|
|
[availableModules addObject: module];
|
|
|
|
}
|
2009-08-19 19:19:32 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
return availableModules;
|
2009-08-19 19:19:32 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by templates
|
|
|
|
//
|
2009-08-19 19:19:32 +02:00
|
|
|
- (NSString *) itemModuleText
|
|
|
|
{
|
|
|
|
return [self labelForKey: item];
|
|
|
|
}
|
|
|
|
|
2016-05-25 22:04:58 +02:00
|
|
|
- (BOOL) externalAvatarsEnabled
|
|
|
|
{
|
|
|
|
return [[user domainDefaults] externalAvatarsEnabled];
|
|
|
|
}
|
|
|
|
|
2015-11-27 22:04:12 +01:00
|
|
|
- (NSArray *) alternateAvatar
|
|
|
|
{
|
|
|
|
// See: https://en.gravatar.com/site/implement/images/
|
|
|
|
return [NSArray arrayWithObjects: @"none", @"identicon", @"monsterid", @"wavatar", @"retro", nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) itemAlternateAvatarText
|
|
|
|
{
|
|
|
|
return [self labelForKey: item];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by templates
|
|
|
|
//
|
2014-03-10 19:45:10 +01:00
|
|
|
- (NSString *) sogoVersion
|
|
|
|
{
|
2014-04-03 23:09:00 +02:00
|
|
|
// The variable SOGoVersion comes from the import: SOGo/Build.h
|
2014-04-04 14:39:13 +02:00
|
|
|
return [NSString stringWithString: SOGoVersion];
|
2014-03-10 19:45:10 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
|
|
|
- (id) _sieveClient
|
2014-04-04 21:04:37 +02:00
|
|
|
{
|
2014-03-10 15:33:27 +01:00
|
|
|
SOGoMailAccount *account;
|
|
|
|
SOGoMailAccounts *folder;
|
|
|
|
SOGoSieveManager *manager;
|
2014-05-01 20:07:25 +02:00
|
|
|
|
2014-04-09 16:48:47 +02:00
|
|
|
if (!client)
|
2014-06-30 16:35:55 +02:00
|
|
|
{
|
2015-04-28 17:51:39 +02:00
|
|
|
folder = [[[context activeUser] homeFolderInContext: context] mailAccountsFolder: @"Mail" inContext: context];
|
2014-06-30 16:35:55 +02:00
|
|
|
account = [folder lookupName: @"0" inContext: context acquire: NO];
|
|
|
|
manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]];
|
|
|
|
client = [[manager clientForAccount: account] retain];
|
|
|
|
}
|
2014-05-01 20:07:25 +02:00
|
|
|
|
2014-04-04 21:04:37 +02:00
|
|
|
return client;
|
2014-03-10 15:33:27 +01:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
|
|
|
- (BOOL) _isSieveServerAvailable
|
2014-04-04 21:04:37 +02:00
|
|
|
{
|
2015-03-22 13:00:21 +01:00
|
|
|
return (([(NGSieveClient *)[self _sieveClient] isConnected])
|
2014-04-10 14:44:44 +02:00
|
|
|
? YES
|
|
|
|
: NO);
|
2014-03-10 15:33:27 +01:00
|
|
|
}
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
- (BOOL) shouldTakeValuesFromRequest: (WORequest *) request
|
|
|
|
inContext: (WOContext*) context
|
|
|
|
{
|
|
|
|
return [[request method] isEqualToString: @"POST"];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used wox by template
|
|
|
|
//
|
2007-11-26 21:41:59 +01:00
|
|
|
- (BOOL) userHasCalendarAccess
|
|
|
|
{
|
|
|
|
return [user canAccessModule: @"Calendar"];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used wox by template
|
|
|
|
//
|
2007-11-26 21:41:59 +01:00
|
|
|
- (BOOL) userHasMailAccess
|
|
|
|
{
|
|
|
|
return [user canAccessModule: @"Mail"];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used wox by template
|
|
|
|
//
|
2008-08-21 04:36:04 +02:00
|
|
|
- (BOOL) shouldDisplayAdditionalPreferences
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [[SOGoSystemDefaults sharedSystemDefaults]
|
|
|
|
uixAdditionalPreferences];
|
2008-08-21 04:36:04 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used wox by template
|
|
|
|
//
|
2007-07-22 22:17:34 +02:00
|
|
|
- (BOOL) shouldDisplayPasswordChange
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [[SOGoSystemDefaults sharedSystemDefaults]
|
|
|
|
userCanChangePassword];
|
2007-07-22 22:17:34 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2009-10-01 23:41:54 +02:00
|
|
|
- (NSArray *) languages
|
|
|
|
{
|
2015-05-20 18:15:31 +02:00
|
|
|
return [[SOGoSystemDefaults sharedSystemDefaults] supportedLanguages];
|
2009-10-01 23:41:54 +02:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2009-10-01 23:41:54 +02:00
|
|
|
- (NSString *) languageText
|
|
|
|
{
|
|
|
|
return [self labelForKey: item];
|
|
|
|
}
|
|
|
|
|
2017-01-10 16:35:06 +01:00
|
|
|
- (NSDictionary *) languageLocale
|
|
|
|
{
|
|
|
|
WOResourceManager *rm;
|
|
|
|
|
|
|
|
rm = [self pageResourceManager];
|
|
|
|
|
|
|
|
return [rm localeForLanguageNamed: item];
|
|
|
|
}
|
|
|
|
|
2015-03-22 13:00:21 +01:00
|
|
|
//
|
|
|
|
// Used by wox template
|
|
|
|
//
|
2010-08-06 17:34:05 +02:00
|
|
|
- (BOOL) mailAuxiliaryUserAccountsEnabled
|
|
|
|
{
|
|
|
|
return [[user domainDefaults] mailAuxiliaryUserAccountsEnabled];
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
2012-04-20 15:27:21 +02:00
|
|
|
- (void) _extractMainIdentity: (NSDictionary *) identity
|
2015-03-26 18:37:44 +01:00
|
|
|
inDictionary: (NSMutableDictionary *) target
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2010-08-06 17:34:05 +02:00
|
|
|
{
|
|
|
|
/* We perform some validation here as we have no guaranty on the input
|
|
|
|
validity. */
|
2012-04-20 15:27:21 +02:00
|
|
|
NSString *value;
|
2010-08-06 17:34:05 +02:00
|
|
|
|
2012-04-20 15:27:21 +02:00
|
|
|
if ([identity isKindOfClass: [NSDictionary class]])
|
2010-08-06 17:34:05 +02:00
|
|
|
{
|
2012-04-20 15:27:21 +02:00
|
|
|
value = [identity objectForKey: @"signature"];
|
2015-03-26 18:37:44 +01:00
|
|
|
|
|
|
|
if (value)
|
|
|
|
[target setObject: value forKey: @"SOGoMailSignature"];
|
|
|
|
else
|
|
|
|
[target removeObjectForKey: @"SOGoMailSignature"];
|
2012-04-20 15:37:46 +02:00
|
|
|
|
|
|
|
if (mailCustomFromEnabled)
|
|
|
|
{
|
|
|
|
value = [[identity objectForKey: @"email"]
|
|
|
|
stringByTrimmingSpaces];
|
|
|
|
|
2016-10-03 16:29:30 +02:00
|
|
|
/* We make sure that the "custom" value is different from the system email */
|
2016-10-03 18:36:57 +02:00
|
|
|
if ([value length] == 0
|
|
|
|
|| [[user systemEmail] isEqualToString: value])
|
2012-04-25 23:32:18 +02:00
|
|
|
value = nil;
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
if (value)
|
|
|
|
[target setObject: value forKey: @"SOGoMailCustomEmail"];
|
|
|
|
else
|
|
|
|
[target removeObjectForKey: @"SOGoMailCustomEmail"];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2012-04-25 23:32:18 +02:00
|
|
|
value = [[identity objectForKey: @"fullName"]
|
|
|
|
stringByTrimmingSpaces];
|
|
|
|
if ([value length] == 0
|
|
|
|
|| [[user cn] isEqualToString: value])
|
|
|
|
value = nil;
|
2015-03-26 18:37:44 +01:00
|
|
|
|
|
|
|
if (value)
|
|
|
|
[target setObject: value forKey: @"SOGoMailCustomFullName"];
|
|
|
|
else
|
|
|
|
[target removeObjectForKey: @"SOGoMailCustomFullName"];
|
2012-04-20 15:37:46 +02:00
|
|
|
}
|
|
|
|
|
2012-04-20 15:27:21 +02:00
|
|
|
value = [[identity objectForKey: @"replyTo"]
|
|
|
|
stringByTrimmingSpaces];
|
2015-03-26 18:37:44 +01:00
|
|
|
|
|
|
|
if (value && [value length] > 0)
|
|
|
|
[target setObject: value forKey: @"SOGoMailReplyTo"];
|
|
|
|
else
|
|
|
|
[target removeObjectForKey: @"SOGoMailReplyTo"];
|
2010-08-06 17:34:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
2010-09-01 22:27:45 +02:00
|
|
|
- (BOOL) _validateReceiptAction: (NSString *) action
|
|
|
|
{
|
|
|
|
return ([action isKindOfClass: [NSString class]]
|
|
|
|
&& ([action isEqualToString: @"ignore"]
|
|
|
|
|| [action isEqualToString: @"send"]
|
|
|
|
|| [action isEqualToString: @"ask"]));
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
2012-04-20 15:27:21 +02:00
|
|
|
- (void) _extractMainReceiptsPreferences: (NSDictionary *) receipts
|
2015-03-26 18:37:44 +01:00
|
|
|
inDictionary: (NSMutableDictionary *) target
|
|
|
|
|
2010-09-01 22:27:45 +02:00
|
|
|
{
|
|
|
|
/* We perform some validation here as we have no guaranty on the input
|
|
|
|
validity. */
|
|
|
|
NSString *action;
|
|
|
|
|
2012-04-20 15:27:21 +02:00
|
|
|
if ([receipts isKindOfClass: [NSDictionary class]])
|
2010-09-01 22:27:45 +02:00
|
|
|
{
|
2019-08-08 17:35:14 +02:00
|
|
|
action = [[receipts objectForKey: @"receiptAction"] isEqualToString: @"ignore"] ? @"0" : @"1";
|
|
|
|
[target setObject: action forKey: @"SOGoMailReceiptAllow"];
|
2014-05-01 20:07:25 +02:00
|
|
|
|
2012-04-20 15:27:21 +02:00
|
|
|
action = [receipts objectForKey: @"receiptNonRecipientAction"];
|
|
|
|
if ([self _validateReceiptAction: action])
|
2015-03-26 18:37:44 +01:00
|
|
|
[target setObject: action forKey: @"SOGoMailReceiptNonRecipientAction"];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2012-04-20 15:27:21 +02:00
|
|
|
action = [receipts objectForKey: @"receiptOutsideDomainAction"];
|
|
|
|
if ([self _validateReceiptAction: action])
|
2015-03-26 18:37:44 +01:00
|
|
|
[target setObject: action forKey: @"SOGoMailReceiptOutsideDomainAction"];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2012-04-20 15:27:21 +02:00
|
|
|
action = [receipts objectForKey: @"receiptAnyAction"];
|
|
|
|
if ([self _validateReceiptAction: action])
|
2015-03-26 18:37:44 +01:00
|
|
|
[target setObject: action forKey: @"SOGoMailReceiptAnyAction"];
|
2012-04-20 15:27:21 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-01 22:27:45 +02:00
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
|
|
|
- (void) _extractMainSecurityPreferences: (NSDictionary *) security
|
|
|
|
inDictionary: (NSMutableDictionary *) target
|
|
|
|
|
|
|
|
{
|
|
|
|
NSString *action;
|
|
|
|
|
|
|
|
if ([security isKindOfClass: [NSDictionary class]])
|
|
|
|
{
|
|
|
|
action = [security objectForKey: @"alwaysSign"];
|
|
|
|
if (action && [action boolValue])
|
|
|
|
[target setObject: @"1" forKey: @"SOGoMailCertificateAlwaysSign"];
|
|
|
|
|
|
|
|
action = [security objectForKey: @"alwaysEncrypt"];
|
|
|
|
if (action && [action boolValue])
|
|
|
|
[target setObject: @"1" forKey: @"SOGoMailCertificateAlwaysEncrypt"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
2012-04-20 15:27:21 +02:00
|
|
|
- (void) _extractMainCustomFrom: (NSDictionary *) account
|
|
|
|
{
|
|
|
|
}
|
2010-09-01 22:27:45 +02:00
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
2012-04-20 15:27:21 +02:00
|
|
|
- (void) _extractMainReplyTo: (NSDictionary *) account
|
|
|
|
{
|
2010-09-01 22:27:45 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
2010-08-06 17:34:05 +02:00
|
|
|
- (BOOL) _validateAccountIdentities: (NSArray *) identities
|
|
|
|
{
|
|
|
|
static NSString *identityKeys[] = { @"fullName", @"email", nil };
|
|
|
|
static NSArray *knownKeys = nil;
|
|
|
|
NSString **key, *value;
|
|
|
|
NSDictionary *identity;
|
|
|
|
NSMutableDictionary *clone;
|
|
|
|
BOOL valid;
|
|
|
|
int count, max;
|
|
|
|
|
|
|
|
if (!knownKeys)
|
|
|
|
{
|
|
|
|
knownKeys = [NSArray arrayWithObjects: @"fullName", @"email",
|
2012-04-20 15:27:21 +02:00
|
|
|
@"signature", @"replyTo", nil];
|
2010-08-06 17:34:05 +02:00
|
|
|
[knownKeys retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
valid = [identities isKindOfClass: [NSArray class]];
|
|
|
|
if (valid)
|
|
|
|
{
|
|
|
|
max = [identities count];
|
|
|
|
valid = (max > 0);
|
|
|
|
for (count = 0; valid && count < max; count++)
|
|
|
|
{
|
|
|
|
identity = [identities objectAtIndex: count];
|
|
|
|
clone = [identity mutableCopy];
|
|
|
|
[clone removeObjectsForKeys: knownKeys];
|
|
|
|
valid = ([clone count] == 0);
|
|
|
|
[clone autorelease];
|
|
|
|
if (valid)
|
|
|
|
{
|
|
|
|
key = identityKeys;
|
|
|
|
while (valid && *key)
|
|
|
|
{
|
|
|
|
value = [identity objectForKey: *key];
|
|
|
|
if ([value isKindOfClass: [NSString class]]
|
|
|
|
&& [value length] > 0)
|
|
|
|
key++;
|
|
|
|
else
|
|
|
|
valid = NO;
|
|
|
|
}
|
|
|
|
if (valid)
|
|
|
|
{
|
|
|
|
value = [identity objectForKey: @"signature"];
|
|
|
|
valid = (!value || [value isKindOfClass: [NSString class]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
2010-08-06 17:34:05 +02:00
|
|
|
- (BOOL) _validateAccount: (NSDictionary *) account
|
|
|
|
{
|
|
|
|
static NSString *accountKeys[] = { @"name", @"serverName", @"userName",
|
2010-08-06 22:26:47 +02:00
|
|
|
nil };
|
2010-08-06 17:34:05 +02:00
|
|
|
static NSArray *knownKeys = nil;
|
|
|
|
NSMutableDictionary *clone;
|
|
|
|
NSString **key, *value;
|
|
|
|
BOOL valid;
|
|
|
|
|
|
|
|
if (!knownKeys)
|
|
|
|
{
|
2010-09-01 22:27:45 +02:00
|
|
|
knownKeys = [NSArray arrayWithObjects: @"name", @"serverName", @"port",
|
2012-04-20 15:27:21 +02:00
|
|
|
@"userName", @"password", @"encryption", @"replyTo",
|
2010-09-01 22:27:45 +02:00
|
|
|
@"identities", @"mailboxes",
|
2018-02-05 20:37:22 +01:00
|
|
|
@"receipts", @"security", @"isNew",
|
2010-09-01 22:27:45 +02:00
|
|
|
nil];
|
2010-08-06 17:34:05 +02:00
|
|
|
[knownKeys retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
valid = [account isKindOfClass: [NSDictionary class]];
|
|
|
|
if (valid)
|
|
|
|
{
|
|
|
|
clone = [account mutableCopy];
|
|
|
|
[clone removeObjectsForKeys: knownKeys];
|
|
|
|
valid = ([clone count] == 0);
|
|
|
|
[clone autorelease];
|
|
|
|
|
|
|
|
key = accountKeys;
|
|
|
|
while (valid && *key)
|
|
|
|
{
|
|
|
|
value = [account objectForKey: *key];
|
|
|
|
if ([value isKindOfClass: [NSString class]]
|
|
|
|
&& [value length] > 0)
|
|
|
|
key++;
|
|
|
|
else
|
|
|
|
valid = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid)
|
|
|
|
{
|
2018-01-12 20:47:31 +01:00
|
|
|
value = [account objectForKey: @"encryption"];
|
2010-08-06 17:34:05 +02:00
|
|
|
if (value)
|
|
|
|
valid = ([value isKindOfClass: [NSString class]]
|
|
|
|
&& ([value isEqualToString: @"none"]
|
|
|
|
|| [value isEqualToString: @"ssl"]
|
|
|
|
|| [value isEqualToString: @"tls"]));
|
|
|
|
|
|
|
|
valid &= [self _validateAccountIdentities: [account objectForKey: @"identities"]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
2012-04-20 15:27:21 +02:00
|
|
|
- (void) _extractMainAccountSettings: (NSDictionary *) account
|
2015-03-26 18:37:44 +01:00
|
|
|
inDictionary: (NSMutableDictionary *) target
|
2012-04-20 15:27:21 +02:00
|
|
|
{
|
|
|
|
NSArray *identities;
|
|
|
|
|
|
|
|
if ([account isKindOfClass: [NSDictionary class]])
|
|
|
|
{
|
|
|
|
identities = [account objectForKey: @"identities"];
|
|
|
|
if ([identities isKindOfClass: [NSArray class]]
|
|
|
|
&& [identities count] > 0)
|
2015-03-26 18:37:44 +01:00
|
|
|
[self _extractMainIdentity: [identities objectAtIndex: 0] inDictionary: target];
|
|
|
|
[self _extractMainReceiptsPreferences: [account objectForKey: @"receipts"] inDictionary: target];
|
2018-01-12 20:47:31 +01:00
|
|
|
[self _extractMainSecurityPreferences: [account objectForKey: @"security"] inDictionary: target];
|
2012-04-20 15:27:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
//
|
|
|
|
// Used internally
|
|
|
|
//
|
|
|
|
- (NSArray *) _extractAuxiliaryAccounts: (NSArray *) accounts
|
2010-08-06 17:34:05 +02:00
|
|
|
{
|
2018-01-12 20:47:31 +01:00
|
|
|
int count, max;
|
2010-08-06 17:34:05 +02:00
|
|
|
NSMutableArray *auxAccounts;
|
2010-08-06 22:26:47 +02:00
|
|
|
NSMutableDictionary *account;
|
2010-08-06 17:34:05 +02:00
|
|
|
|
|
|
|
max = [accounts count];
|
|
|
|
auxAccounts = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
|
|
|
|
for (count = 1; count < max; count++)
|
|
|
|
{
|
|
|
|
account = [accounts objectAtIndex: count];
|
|
|
|
if ([self _validateAccount: account])
|
2010-08-06 22:26:47 +02:00
|
|
|
{
|
2018-01-12 20:47:31 +01:00
|
|
|
[self _updateAuxiliaryAccount: account];
|
|
|
|
[auxAccounts addObject: account];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return auxAccounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _updateAuxiliaryAccount: (NSMutableDictionary *) newAccount
|
|
|
|
{
|
|
|
|
int count, oldMax;
|
|
|
|
NSArray *oldAccounts, *comparisonAttributes;
|
|
|
|
NSDictionary *oldAccount, *oldSecurity;
|
|
|
|
NSEnumerator *comparisonAttributesList;
|
|
|
|
NSMutableDictionary *newSecurity;
|
|
|
|
NSString *comparisonAttribute, *password, *certificate;
|
|
|
|
|
|
|
|
comparisonAttributes = [NSArray arrayWithObjects: @"serverName", @"userName", nil];
|
|
|
|
oldAccounts = [user mailAccounts];
|
|
|
|
oldAccount = nil;
|
|
|
|
oldMax = [oldAccounts count];
|
|
|
|
|
|
|
|
for (count = 1 /* skip system account */; !oldAccount && count < oldMax; count++)
|
|
|
|
{
|
|
|
|
oldAccount = [oldAccounts objectAtIndex: count];
|
|
|
|
comparisonAttributesList = [comparisonAttributes objectEnumerator];
|
|
|
|
while (oldAccount && (comparisonAttribute = [comparisonAttributesList nextObject]))
|
|
|
|
{
|
|
|
|
if (![[oldAccount objectForKey: comparisonAttribute]
|
|
|
|
isEqualToString: [newAccount objectForKey: comparisonAttribute]])
|
|
|
|
oldAccount = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldAccount)
|
|
|
|
{
|
|
|
|
// Use previous password if none is provided
|
|
|
|
password = [newAccount objectForKey: @"password"];
|
|
|
|
if (!password)
|
|
|
|
password = [oldAccount objectForKey: @"password"];
|
|
|
|
if (!password)
|
|
|
|
password = @"";
|
|
|
|
[newAccount setObject: password forKey: @"password"];
|
|
|
|
|
|
|
|
// Keep previous certificate
|
|
|
|
oldSecurity = [oldAccount objectForKey: @"security"];
|
|
|
|
if (oldSecurity)
|
|
|
|
{
|
|
|
|
certificate = [oldSecurity objectForKey: @"certificate"];
|
|
|
|
if (certificate)
|
2010-08-06 22:26:47 +02:00
|
|
|
{
|
2018-01-12 20:47:31 +01:00
|
|
|
newSecurity = [newAccount objectForKey: @"security"];
|
|
|
|
if (!newSecurity)
|
2010-08-06 22:26:47 +02:00
|
|
|
{
|
2018-01-12 20:47:31 +01:00
|
|
|
newSecurity = [NSMutableDictionary dictionary];
|
|
|
|
[newAccount setObject: newSecurity forKey: @"security"];
|
2010-08-06 22:26:47 +02:00
|
|
|
}
|
2018-01-12 20:47:31 +01:00
|
|
|
[newSecurity setObject: certificate forKey: @"certificate"];
|
2010-08-06 22:26:47 +02:00
|
|
|
}
|
|
|
|
}
|
2010-08-06 17:34:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-20 15:37:46 +02:00
|
|
|
- (NSString *) mailCustomFromEnabled
|
|
|
|
{
|
|
|
|
return (mailCustomFromEnabled ? @"true" : @"false");
|
|
|
|
}
|
|
|
|
|
2016-02-09 20:15:23 +01:00
|
|
|
- (NSString *) forwardEnabled
|
|
|
|
{
|
|
|
|
return (forwardEnabled ? @"true" : @"false");
|
|
|
|
}
|
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
/**
|
|
|
|
* @api {post} /so/:username/Preferences/save Save user's defaults and settings
|
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName PostPreferencesSave
|
|
|
|
* @apiGroup Preferences
|
|
|
|
* @apiDescription Save user's defaults and settings.
|
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Preferences/save \
|
|
|
|
* -H 'Content-Type: application/json' \
|
|
|
|
* -d '{ "defaults": { SOGoDayStartTime: "09:00", "SOGoDayEndTime": "18:00" }, \
|
|
|
|
* "settings": { Calendar: { ListState: "rise", EventsFilterState: "view_next7" } } }'
|
|
|
|
*
|
|
|
|
* @apiParam {Object} [defaults] All attributes for user's defaults
|
|
|
|
* @apiParam {Object} [settings] All attributes for user's settings
|
|
|
|
*
|
|
|
|
* @apiError (Error 500) {Object} error The error message
|
|
|
|
*/
|
2015-02-25 23:21:07 +01:00
|
|
|
- (id <WOActionResults>) saveAction
|
|
|
|
{
|
2015-04-28 17:19:37 +02:00
|
|
|
id <WOActionResults> results;
|
2015-03-21 20:34:18 +01:00
|
|
|
id o, v;
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-03-21 20:34:18 +01:00
|
|
|
o = [[[context request] contentAsString] objectFromJSONString];
|
2015-04-28 17:19:37 +02:00
|
|
|
results = nil;
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
// Proceed with data sanitization of the "defaults"
|
2015-03-21 20:34:18 +01:00
|
|
|
if ((v = [o objectForKey: @"defaults"]))
|
|
|
|
{
|
2015-03-24 15:44:50 +01:00
|
|
|
NSMutableDictionary *sanitizedLabels;
|
2015-04-28 17:19:37 +02:00
|
|
|
NSArray *allKeys, *accounts;
|
2015-03-24 15:44:50 +01:00
|
|
|
NSDictionary *newLabels;
|
2015-04-28 17:19:37 +02:00
|
|
|
NSString *name;
|
2016-10-31 20:12:47 +01:00
|
|
|
id loginModule;
|
2015-04-10 15:44:30 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
// We convert our object into a mutable one
|
|
|
|
v = [[v mutableCopy] autorelease];
|
2015-04-10 15:44:30 +02:00
|
|
|
|
2015-09-01 22:43:56 +02:00
|
|
|
if ([[v objectForKey: @"SOGoLoginModule"] isEqualToString: @"Last"])
|
2016-10-31 20:12:47 +01:00
|
|
|
{
|
|
|
|
[v setObject: [NSNumber numberWithBool: YES] forKey: @"SOGoRememberLastModule"];
|
|
|
|
loginModule = [[[user userDefaults] source] objectForKey: @"SOGoLoginModule"];
|
|
|
|
if (loginModule)
|
|
|
|
[v setObject: loginModule forKey: @"SOGoLoginModule"];
|
|
|
|
else
|
|
|
|
[v removeObjectForKey: @"SOGoLoginModule"];
|
|
|
|
}
|
2015-09-01 22:43:56 +02:00
|
|
|
else
|
|
|
|
[v setObject: [NSNumber numberWithBool: NO] forKey: @"SOGoRememberLastModule"];
|
2015-07-30 01:10:03 +02:00
|
|
|
|
2016-06-10 20:26:34 +02:00
|
|
|
// We remove short/long date/time formats if they are default ones
|
2015-07-30 01:10:03 +02:00
|
|
|
if ([[v objectForKey: @"SOGoShortDateFormat"] isEqualToString: @"default"])
|
|
|
|
[v removeObjectForKey: @"SOGoShortDateFormat"];
|
|
|
|
|
|
|
|
if ([[v objectForKey: @"SOGoLongDateFormat"] isEqualToString: @"default"])
|
|
|
|
[v removeObjectForKey: @"SOGoLongDateFormat"];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2016-06-10 20:26:34 +02:00
|
|
|
if ([[v objectForKey: @"SOGoTimeFormat"] isEqualToString: @"default"])
|
|
|
|
[v removeObjectForKey: @"SOGoTimeFormat"];
|
|
|
|
|
2016-05-25 22:04:58 +02:00
|
|
|
if (![self externalAvatarsEnabled])
|
|
|
|
{
|
|
|
|
[v removeObjectForKey: @"SOGoGravatarEnabled"];
|
|
|
|
[[[user userDefaults] source] removeObjectForKey: @"SOGoGravatarEnabled"];
|
|
|
|
[v removeObjectForKey: @"SOGoAlternateAvatar"];
|
|
|
|
[[[user userDefaults] source] removeObjectForKey: @"SOGoAlternateAvatar"];
|
|
|
|
}
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
|
|
|
// We sanitize mail labels
|
|
|
|
//
|
2015-03-24 15:44:50 +01:00
|
|
|
newLabels = [v objectForKey: @"SOGoMailLabelsColors"];
|
|
|
|
if (newLabels && [newLabels isKindOfClass: [NSDictionary class]])
|
|
|
|
{
|
|
|
|
// We encode correctly our keys
|
|
|
|
sanitizedLabels = [NSMutableDictionary dictionary];
|
|
|
|
allKeys = [newLabels allKeys];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
for (i = 0; i < [allKeys count]; i++)
|
|
|
|
{
|
|
|
|
name = [allKeys objectAtIndex: i];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
if (![name is7bitSafe])
|
|
|
|
name = [name stringByEncodingImap4FolderName];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
name = [name lowercaseString];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
[sanitizedLabels setObject: [newLabels objectForKey: [allKeys objectAtIndex: i]]
|
|
|
|
forKey: name];
|
|
|
|
}
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
[v setObject: sanitizedLabels forKey: @"SOGoMailLabelsColors"];
|
|
|
|
}
|
2015-04-08 19:33:54 +02:00
|
|
|
|
2018-01-19 15:29:28 +01:00
|
|
|
//
|
|
|
|
// Keep the primary mail certificate
|
|
|
|
//
|
|
|
|
if ([[[user userDefaults] mailCertificate] length])
|
|
|
|
[v setObject: [[user userDefaults] mailCertificate] forKey: @"SOGoMailCertificate"];
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
2015-03-26 18:37:44 +01:00
|
|
|
// We sanitize our auxilary mail accounts
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
2015-03-26 18:37:44 +01:00
|
|
|
accounts = [v objectForKey: @"AuxiliaryMailAccounts"];
|
|
|
|
if (accounts && [accounts isKindOfClass: [NSArray class]])
|
|
|
|
{
|
|
|
|
if ([accounts count] > 0)
|
|
|
|
{
|
2018-01-12 20:47:31 +01:00
|
|
|
// The first account is the main system account. The following mapping is required:
|
|
|
|
// - identities[0].signature => SOGoMailSignature
|
|
|
|
// - identities[0].email => SOGoMailCustomEmail
|
|
|
|
// - identities[0].fullName => SOGoMailCustomFullName
|
|
|
|
// - identities[0].replyTo => SOGoMailReplyTo
|
|
|
|
// - receipts.receiptAction => SOGoMailReceiptAllow
|
|
|
|
// - receipts.receiptNonRecipientAction => SOGoMailReceiptNonRecipientAction
|
|
|
|
// - receipts.receiptOutsideDomainAction => SOGoMailReceiptOutsideDomainAction
|
|
|
|
// - receipts.receiptAnyAction => SOGoMailReceiptAnyAction
|
|
|
|
// - security.alwaysSign => SOGoMailCertificateAlwaysSign
|
|
|
|
// - security.alwaysEncrypt => SOGoMailCertificateAlwaysEncrypt
|
2015-03-26 18:37:44 +01:00
|
|
|
[self _extractMainAccountSettings: [accounts objectAtIndex: 0] inDictionary: v];
|
|
|
|
if ([self mailAuxiliaryUserAccountsEnabled])
|
|
|
|
accounts = [self _extractAuxiliaryAccounts: accounts];
|
|
|
|
else
|
|
|
|
accounts = [NSArray array];
|
|
|
|
|
|
|
|
[v setObject: accounts forKey: @"AuxiliaryMailAccounts"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 20:34:18 +01:00
|
|
|
[[[user userDefaults] source] setValues: v];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-04-28 17:19:37 +02:00
|
|
|
if ([[user userDefaults] synchronize])
|
|
|
|
{
|
|
|
|
SOGoMailAccount *account;
|
|
|
|
SOGoMailAccounts *folder;
|
|
|
|
SOGoDomainDefaults *dd;
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-04-28 17:19:37 +02:00
|
|
|
dd = [[context activeUser] domainDefaults];
|
|
|
|
|
|
|
|
// We check if the Sieve server is available *ONLY* if at least one of the option is enabled
|
|
|
|
if (!([dd sieveScriptsEnabled] || [dd vacationEnabled] || [dd forwardEnabled]) || [self _isSieveServerAvailable])
|
|
|
|
{
|
2019-11-15 20:37:35 +01:00
|
|
|
BOOL forceActivation = ![[v objectForKey: @"hasActiveExternalSieveScripts"] boolValue];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-04-28 17:51:39 +02:00
|
|
|
folder = [[[context activeUser] homeFolderInContext: context] mailAccountsFolder: @"Mail"
|
|
|
|
inContext: context];
|
2015-04-28 17:19:37 +02:00
|
|
|
account = [folder lookupName: @"0" inContext: context acquire: NO];
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2019-11-15 20:37:35 +01:00
|
|
|
if (![account updateFiltersAndForceActivation: forceActivation])
|
2015-04-28 17:19:37 +02:00
|
|
|
{
|
2015-10-31 07:10:03 +01:00
|
|
|
results = (id <WOActionResults>) [self responseWithStatus: 502
|
2015-12-09 15:44:33 +01:00
|
|
|
andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Connection error", @"message", nil]];
|
2015-04-28 17:19:37 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-04 19:48:55 +02:00
|
|
|
else
|
2015-10-31 07:10:03 +01:00
|
|
|
results = (id <WOActionResults>) [self responseWithStatus: 503
|
2015-12-09 15:44:33 +01:00
|
|
|
andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Service temporarily unavailable", @"message", nil]];
|
2015-04-28 17:19:37 +02:00
|
|
|
}
|
2015-03-21 20:34:18 +01:00
|
|
|
}
|
2016-05-25 22:04:58 +02:00
|
|
|
|
2015-03-21 20:34:18 +01:00
|
|
|
if ((v = [o objectForKey: @"settings"]))
|
|
|
|
{
|
|
|
|
[[[user userSettings] source] setValues: v];
|
|
|
|
[[user userSettings] synchronize];
|
|
|
|
}
|
2015-04-28 17:19:37 +02:00
|
|
|
|
|
|
|
if (!results)
|
2015-10-31 07:10:03 +01:00
|
|
|
results = (id <WOActionResults>) [self responseWithStatus: 200];
|
2015-04-28 17:19:37 +02:00
|
|
|
|
|
|
|
return results;
|
2015-02-25 23:21:07 +01:00
|
|
|
}
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
@end
|