2007-06-19 19:58:21 +02:00
|
|
|
/* UIxJSONPreferences.m - this file is part of SOGo
|
|
|
|
*
|
2021-01-14 21:13:27 +01:00
|
|
|
* Copyright (C) 2007-2021 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.
|
|
|
|
*/
|
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2015-05-01 19:56:43 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2015-04-03 23:37:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
#import <NGObjWeb/SoObjects.h>
|
2007-06-19 19:58:21 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
|
2016-03-25 02:44:29 +01:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2019-11-15 20:37:35 +01:00
|
|
|
#import <NGImap4/NGSieveClient.h>
|
2016-03-25 02:44:29 +01:00
|
|
|
|
2016-05-06 20:14:45 +02:00
|
|
|
#import <SOPE/NGCards/iCalRecurrenceRule.h>
|
|
|
|
|
2020-07-03 16:43:20 +02:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
2015-04-08 20:19:31 +02:00
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2016-05-25 22:04:58 +02:00
|
|
|
#import <SOGo/SOGoDomainDefaults.h>
|
2019-11-15 20:37:35 +01:00
|
|
|
#import <SOGo/SOGoSieveManager.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2019-11-15 20:37:35 +01:00
|
|
|
#import <SOGo/SOGoUserFolder.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
|
|
|
#import <SOGo/SOGoUserProfile.h>
|
2015-11-03 20:59:40 +01:00
|
|
|
#import <SOGo/WOResourceManager+SOGo.h>
|
2017-06-01 19:50:46 +02:00
|
|
|
#import <SOGoUI/UIxComponent.h>
|
2019-11-15 20:37:35 +01:00
|
|
|
#import <Mailer/SOGoMailAccount.h>
|
|
|
|
#import <Mailer/SOGoMailAccounts.h>
|
2015-03-24 15:44:50 +01:00
|
|
|
#import <Mailer/SOGoMailLabel.h>
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
#import "UIxJSONPreferences.h"
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
static SoProduct *preferencesProduct = nil;
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
@implementation UIxJSONPreferences
|
|
|
|
|
2016-03-25 02:44:29 +01:00
|
|
|
- (NSDictionary *) _localizedCategoryLabels
|
|
|
|
{
|
|
|
|
NSArray *categoryLabels, *localizedCategoryLabels;
|
|
|
|
NSDictionary *labelsDictionary;
|
|
|
|
|
|
|
|
labelsDictionary = nil;
|
|
|
|
localizedCategoryLabels = [[self labelForKey: @"calendar_category_labels"
|
|
|
|
withResourceManager: [preferencesProduct resourceManager]]
|
|
|
|
componentsSeparatedByString: @","];
|
|
|
|
categoryLabels = [[[preferencesProduct 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;
|
|
|
|
}
|
|
|
|
|
2020-01-31 22:51:33 +01:00
|
|
|
- (WOResponse *) activeExternalSieveScriptsAction
|
2019-11-15 20:37:35 +01:00
|
|
|
{
|
|
|
|
NGSieveClient *client;
|
2020-01-31 22:51:33 +01:00
|
|
|
NSDictionary *data;
|
2019-11-15 20:37:35 +01:00
|
|
|
SOGoMailAccount *account;
|
|
|
|
SOGoMailAccounts *folder;
|
|
|
|
SOGoSieveManager *manager;
|
2020-01-31 22:51:33 +01:00
|
|
|
WOResponse *response;
|
2019-11-15 20:37:35 +01:00
|
|
|
|
|
|
|
folder = [[[context activeUser] homeFolderInContext: context] mailAccountsFolder: @"Mail" inContext: context];
|
|
|
|
account = [folder lookupName: @"0" inContext: context acquire: NO];
|
|
|
|
manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]];
|
|
|
|
client = [manager clientForAccount: account];
|
|
|
|
|
|
|
|
if (client)
|
2020-01-31 22:51:33 +01:00
|
|
|
{
|
|
|
|
if ([manager hasActiveExternalSieveScripts: client])
|
|
|
|
response = [self responseWith204];
|
|
|
|
else
|
|
|
|
response = [self responseWithStatus: 404];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"An error occured while communicating with the Sieve server", @"message", nil];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: data];
|
|
|
|
}
|
2019-11-15 20:37:35 +01:00
|
|
|
|
2020-01-31 22:51:33 +01:00
|
|
|
return response;
|
2019-11-15 20:37:35 +01:00
|
|
|
}
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
- (WOResponse *) jsonDefaultsAction
|
2017-06-01 19:50:46 +02:00
|
|
|
{
|
|
|
|
return [self responseWithStatus: 200
|
|
|
|
andString: [self jsonDefaults]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) jsonDefaults
|
2007-06-19 19:58:21 +02:00
|
|
|
{
|
2016-06-15 22:02:12 +02:00
|
|
|
NSMutableDictionary *values, *account, *vacation;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *defaults;
|
2016-05-25 22:04:58 +02:00
|
|
|
SOGoDomainDefaults *domainDefaults;
|
2015-04-10 15:44:30 +02:00
|
|
|
NSMutableArray *accounts;
|
2016-06-15 22:02:12 +02:00
|
|
|
NSDictionary *categoryLabels, *vacationOptions;
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (!preferencesProduct)
|
|
|
|
{
|
|
|
|
preferencesProduct = [[SoProduct alloc] initWithBundle:
|
|
|
|
[NSBundle bundleForClass: NSClassFromString(@"PreferencesUIProduct")]];
|
|
|
|
}
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
defaults = [[context activeUser] userDefaults];
|
2016-05-25 22:04:58 +02:00
|
|
|
domainDefaults = [[context activeUser] domainDefaults];
|
2016-03-25 02:44:29 +01:00
|
|
|
categoryLabels = nil;
|
2015-04-06 16:55:42 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
|
|
|
// Default General preferences
|
|
|
|
//
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoLanguage"])
|
|
|
|
[[defaults source] setObject: [defaults language] forKey: @"SOGoLanguage"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoTimeZone"])
|
|
|
|
[[defaults source] setObject: [defaults timeZoneName] forKey: @"SOGoTimeZone"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-06 16:55:42 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoShortDateFormat"])
|
2015-04-10 15:44:30 +02:00
|
|
|
[[defaults source] setObject: [defaults shortDateFormat] forKey: @"SOGoShortDateFormat"];
|
2015-04-06 16:55:42 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoLongDateFormat"])
|
2015-04-10 15:44:30 +02:00
|
|
|
[[defaults source] setObject: [defaults longDateFormat] forKey: @"SOGoLongDateFormat"];
|
2015-03-24 15:44:50 +01:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoTimeFormat"])
|
|
|
|
[[defaults source] setObject: [defaults timeFormat] forKey: @"SOGoTimeFormat"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoLoginModule"])
|
|
|
|
[[defaults source] setObject: [defaults loginModule] forKey: @"SOGoLoginModule"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoRefreshViewCheck"])
|
|
|
|
[[defaults source] setObject: [defaults refreshViewCheck] forKey: @"SOGoRefreshViewCheck"];
|
|
|
|
|
2016-05-25 22:04:58 +02:00
|
|
|
if ([domainDefaults externalAvatarsEnabled])
|
|
|
|
{
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoGravatarEnabled"])
|
|
|
|
[[defaults source] setObject: [NSNumber numberWithBool: [defaults gravatarEnabled]] forKey: @"SOGoGravatarEnabled"];
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoAlternateAvatar"])
|
|
|
|
[[defaults source] setObject: [defaults alternateAvatar] forKey: @"SOGoAlternateAvatar"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[defaults source] setObject: [NSNumber numberWithInt: 0] forKey: @"SOGoGravatarEnabled"];
|
|
|
|
[[defaults source] removeObjectForKey: @"SOGoAlternateAvatar"];
|
|
|
|
}
|
2015-11-27 22:04:12 +01:00
|
|
|
|
2017-04-25 22:35:39 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoAnimationMode"])
|
|
|
|
[[defaults source] setObject: [defaults animationMode] forKey: @"SOGoAnimationMode"];
|
|
|
|
|
2020-05-07 13:22:24 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoGoogleAuthenticatorEnabled"])
|
|
|
|
[[defaults source] setObject: [NSNumber numberWithBool: NO] forKey: @"SOGoGoogleAuthenticatorEnabled"];
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
|
|
|
// Default Calendar preferences
|
|
|
|
//
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoFirstDayOfWeek"])
|
|
|
|
[[defaults source] setObject: [NSNumber numberWithInt: [defaults firstDayOfWeek]] forKey: @"SOGoFirstDayOfWeek"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoDayStartTime"])
|
|
|
|
[[defaults source] setObject: [NSString stringWithFormat: @"%02d:00", [defaults dayStartHour]] forKey: @"SOGoDayStartTime"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoDayEndTime"])
|
|
|
|
[[defaults source] setObject: [NSString stringWithFormat: @"%02d:00", [defaults dayEndHour]] forKey: @"SOGoDayEndTime"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2016-05-06 20:14:45 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarWeekdays"])
|
|
|
|
[[defaults source] setObject: [NSArray arrayWithObjects: iCalWeekDayString count: 7] forKey: @"SOGoCalendarWeekdays"];
|
|
|
|
|
2015-04-07 22:32:51 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoFirstWeekOfYear"])
|
|
|
|
[[defaults source] setObject: [defaults firstWeekOfYear] forKey: @"SOGoFirstWeekOfYear"];
|
2015-04-10 15:44:30 +02:00
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoDefaultCalendar"])
|
|
|
|
[[defaults source] setObject: [defaults defaultCalendar] forKey: @"SOGoDefaultCalendar"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarEventsDefaultClassification"])
|
|
|
|
[[defaults source] setObject: [defaults calendarEventsDefaultClassification] forKey: @"SOGoCalendarEventsDefaultClassification"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarTasksDefaultClassification"])
|
|
|
|
[[defaults source] setObject: [defaults calendarTasksDefaultClassification] forKey: @"SOGoCalendarTasksDefaultClassification"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarDefaultReminder"])
|
|
|
|
[[defaults source] setObject: [defaults calendarDefaultReminder] forKey: @"SOGoCalendarDefaultReminder"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
// Populate default calendar categories, based on the user's preferred language
|
2016-03-25 02:44:29 +01:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarCategories"])
|
2015-03-24 15:44:50 +01:00
|
|
|
{
|
2016-03-25 02:44:29 +01:00
|
|
|
NSArray *defaultCalendarCategories;
|
|
|
|
|
|
|
|
categoryLabels = [self _localizedCategoryLabels];
|
|
|
|
|
|
|
|
if ((defaultCalendarCategories = [defaults calendarCategories]))
|
|
|
|
{
|
|
|
|
// Calendar categories are taken from SOGo's configuration or SOGoDefaults.plist
|
|
|
|
|
|
|
|
NSMutableArray *filteredCalendarCategories;
|
|
|
|
NSString *label, *localizedLabel;
|
|
|
|
int count, max;
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2016-03-25 02:44:29 +01:00
|
|
|
max = [defaultCalendarCategories count];
|
|
|
|
filteredCalendarCategories = [NSMutableArray arrayWithCapacity: max];
|
2016-01-11 22:32:12 +01:00
|
|
|
|
2016-03-25 02:44:29 +01:00
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
label = [defaultCalendarCategories objectAtIndex: count];
|
2019-03-07 16:52:04 +01:00
|
|
|
if (!(localizedLabel = [categoryLabels objectForKey: label]))
|
2016-03-25 02:44:29 +01:00
|
|
|
{
|
2019-03-07 16:52:04 +01:00
|
|
|
localizedLabel = label;
|
2016-03-25 02:44:29 +01:00
|
|
|
}
|
2019-03-07 16:52:04 +01:00
|
|
|
[filteredCalendarCategories addObject: localizedLabel];
|
2016-03-25 02:44:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[defaults setCalendarCategories: filteredCalendarCategories];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Calendar categories are taken from localizable strings
|
|
|
|
|
|
|
|
[defaults setCalendarCategories: [categoryLabels allValues]];
|
|
|
|
}
|
2015-03-24 15:44:50 +01:00
|
|
|
}
|
2016-03-25 02:44:29 +01:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarCategoriesColors"])
|
2015-04-28 21:15:42 +02:00
|
|
|
{
|
2016-03-25 02:44:29 +01:00
|
|
|
NSDictionary *defaultCalendarCategoriesColors;
|
|
|
|
|
|
|
|
if (!categoryLabels)
|
|
|
|
categoryLabels = [self _localizedCategoryLabels];
|
|
|
|
|
|
|
|
if ((defaultCalendarCategoriesColors = [defaults calendarCategoriesColors]))
|
|
|
|
{
|
|
|
|
// Calendar categories colors are taken from SOGo's configuration or SOGoDefaults.plist
|
|
|
|
|
|
|
|
NSArray *defaultCalendarCategories;
|
|
|
|
NSMutableDictionary *filteredCalendarCategoriesColors;
|
|
|
|
NSString *label, *localizedLabel;
|
|
|
|
int count, max;
|
|
|
|
|
|
|
|
defaultCalendarCategories = [defaultCalendarCategoriesColors allKeys];
|
|
|
|
max = [defaultCalendarCategories count];
|
|
|
|
filteredCalendarCategoriesColors = [NSMutableDictionary dictionaryWithCapacity: max];
|
|
|
|
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
label = [defaultCalendarCategories objectAtIndex: count];
|
2019-03-07 16:52:04 +01:00
|
|
|
if (!(localizedLabel = [categoryLabels objectForKey: label]))
|
2016-03-25 02:44:29 +01:00
|
|
|
{
|
2019-03-07 16:52:04 +01:00
|
|
|
localizedLabel = label;
|
2016-03-25 02:44:29 +01:00
|
|
|
}
|
2019-03-07 16:52:04 +01:00
|
|
|
[filteredCalendarCategoriesColors setObject: [defaultCalendarCategoriesColors objectForKey: label]
|
|
|
|
forKey: localizedLabel];
|
2016-03-25 02:44:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[defaults setCalendarCategoriesColors: filteredCalendarCategoriesColors];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Calendar categories colors are set to #CCC
|
|
|
|
|
|
|
|
NSArray *calendarCategories;
|
|
|
|
NSMutableDictionary *colors;
|
|
|
|
int i;
|
2015-04-28 21:15:42 +02:00
|
|
|
|
2016-03-25 02:44:29 +01:00
|
|
|
calendarCategories = [categoryLabels allValues];
|
|
|
|
colors = [NSMutableDictionary dictionaryWithCapacity: [calendarCategories count]];
|
2015-04-28 21:15:42 +02:00
|
|
|
|
2016-03-25 02:44:29 +01:00
|
|
|
for (i = 0; i < [calendarCategories count]; i++)
|
|
|
|
[colors setObject: @"#CCCCCCC" forKey: [calendarCategories objectAtIndex: i]];
|
2015-04-28 21:15:42 +02:00
|
|
|
|
2016-03-25 02:44:29 +01:00
|
|
|
[defaults setCalendarCategoriesColors: colors];
|
|
|
|
}
|
2015-04-28 21:15:42 +02:00
|
|
|
}
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
|
|
|
// Default Contacts preferences
|
|
|
|
//
|
2015-03-24 15:44:50 +01:00
|
|
|
// Populate default contact categories, based on the user's preferred language
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
2015-03-24 15:44:50 +01:00
|
|
|
if (![defaults contactsCategories])
|
|
|
|
{
|
2020-07-03 16:43:20 +02:00
|
|
|
NSArray *contactsCategories;
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2020-07-03 16:43:20 +02:00
|
|
|
contactsCategories = [[[[self labelForKey: @"contacts_category_labels" withResourceManager: [preferencesProduct resourceManager]]
|
|
|
|
componentsSeparatedByString: @","] trimmedComponents]
|
|
|
|
sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)];
|
|
|
|
|
|
|
|
if (!contactsCategories)
|
|
|
|
contactsCategories = [NSArray array];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2020-07-03 16:43:20 +02:00
|
|
|
[defaults setContactsCategories: contactsCategories];
|
2015-03-24 15:44:50 +01:00
|
|
|
}
|
2015-04-10 15:44:30 +02:00
|
|
|
|
2017-03-23 20:42:05 +01:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailAddOutgoingAddresses"])
|
|
|
|
[[defaults source] setObject: [NSNumber numberWithBool: [defaults mailAddOutgoingAddresses]] forKey: @"SOGoMailAddOutgoingAddresses"];
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
|
|
|
// Default Mail preferences
|
|
|
|
//
|
2017-09-20 22:50:41 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailComposeWindow"])
|
|
|
|
[[defaults source] setObject: [defaults mailComposeWindow] forKey: @"SOGoMailComposeWindow"];
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoSelectedAddressBook"])
|
|
|
|
[[defaults source] setObject: [defaults selectedAddressBook] forKey: @"SOGoSelectedAddressBook"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailMessageForwarding"])
|
|
|
|
[[defaults source] setObject: [defaults mailMessageForwarding] forKey: @"SOGoMailMessageForwarding"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailReplyPlacement"])
|
|
|
|
[[defaults source] setObject: [defaults mailReplyPlacement] forKey: @"SOGoMailReplyPlacement"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailSignaturePlacement"])
|
|
|
|
[[defaults source] setObject: [defaults mailSignaturePlacement] forKey: @"SOGoMailSignaturePlacement"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailComposeMessageType"])
|
|
|
|
[[defaults source] setObject: [defaults mailComposeMessageType] forKey: @"SOGoMailComposeMessageType"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2016-02-11 22:45:58 +01:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailComposeFontSize"])
|
|
|
|
[[defaults source] setObject: [defaults mailComposeFontSize] forKey: @"SOGoMailComposeFontSize"];
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailDisplayRemoteInlineImages"])
|
|
|
|
[[defaults source] setObject: [defaults mailDisplayRemoteInlineImages] forKey: @"SOGoMailDisplayRemoteInlineImages"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2017-03-01 21:14:09 +01:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailAutoSave"])
|
|
|
|
[[defaults source] setObject: [defaults mailAutoSave] forKey: @"SOGoMailAutoSave"];
|
|
|
|
|
2016-06-16 21:37:41 +02:00
|
|
|
// Populate default mail labels, based on the user's preferred language
|
2015-03-24 15:44:50 +01:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailLabelsColors"])
|
|
|
|
{
|
2015-04-03 23:37:46 +02:00
|
|
|
SOGoMailLabel *label;
|
|
|
|
NSArray *labels;
|
|
|
|
id v;
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
int i;
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
v = [defaults mailLabelsColors];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
labels = [SOGoMailLabel labelsFromDefaults: v component: self];
|
|
|
|
v = [NSMutableDictionary dictionary];
|
|
|
|
for (i = 0; i < [labels count]; i++)
|
|
|
|
{
|
|
|
|
label = [labels objectAtIndex: i];
|
|
|
|
[v setObject: [NSArray arrayWithObjects: [label label], [label color], nil]
|
|
|
|
forKey: [label name]];
|
|
|
|
}
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
[defaults setMailLabelsColors: v];
|
2015-03-24 15:44:50 +01:00
|
|
|
}
|
|
|
|
|
2020-06-27 17:31:08 +02:00
|
|
|
if ([domainDefaults forwardEnabled] && ![defaults forwardOptions])
|
|
|
|
{
|
|
|
|
[defaults setForwardOptions: [NSDictionary new]];
|
|
|
|
}
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if ([[defaults source] dirty])
|
2015-03-26 18:37:44 +01:00
|
|
|
[defaults synchronize];
|
|
|
|
|
|
|
|
values = [[[[defaults source] values] mutableCopy] autorelease];
|
2015-04-10 15:44:30 +02:00
|
|
|
|
2016-06-14 16:31:45 +02:00
|
|
|
//
|
2016-06-15 22:02:12 +02:00
|
|
|
// Expose additional information that must *not* be synchronized in the defaults
|
2016-06-14 16:31:45 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
// Expose the SOGoAppointmentSendEMailNotifications configuration parameter from the domain defaults
|
|
|
|
[values setObject: [NSNumber numberWithBool: [domainDefaults appointmentSendEMailNotifications]]
|
|
|
|
forKey: @"SOGoAppointmentSendEMailNotifications"];
|
|
|
|
|
2019-11-18 17:06:15 +01:00
|
|
|
// Expose the SOGoLDAPGroupExpansionEnabled configuration parameter from the domain defaults
|
|
|
|
[values setObject: [NSNumber numberWithBool: [domainDefaults ldapGroupExpansionEnabled]]
|
|
|
|
forKey: @"SOGoLDAPGroupExpansionEnabled"];
|
|
|
|
|
2015-08-06 22:07:46 +02:00
|
|
|
// Add locale code (used by CK Editor)
|
|
|
|
[values setObject: [locale objectForKey: @"NSLocaleCode"] forKey: @"LocaleCode"];
|
2016-01-11 22:32:12 +01:00
|
|
|
[values setObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[locale objectForKey: @"NSMonthNameArray"], @"months",
|
|
|
|
[locale objectForKey: @"NSShortMonthNameArray"], @"shortMonths",
|
|
|
|
[locale objectForKey: @"NSWeekDayNameArray"], @"days",
|
|
|
|
[locale objectForKey: @"NSShortWeekDayNameArray"], @"shortDays",
|
|
|
|
nil] forKey: @"locale"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
accounts = [NSMutableArray arrayWithArray: [values objectForKey: @"AuxiliaryMailAccounts"]];
|
2018-01-12 20:47:31 +01:00
|
|
|
if ([accounts count])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
NSDictionary *security;
|
|
|
|
NSMutableDictionary *auxAccount, *limitedSecurity;
|
|
|
|
|
|
|
|
for (i = 0; i < [accounts count]; i++)
|
|
|
|
{
|
|
|
|
auxAccount = [accounts objectAtIndex: i];
|
|
|
|
security = [auxAccount objectForKey: @"security"];
|
|
|
|
if (security)
|
|
|
|
{
|
|
|
|
limitedSecurity = [NSMutableDictionary dictionaryWithDictionary: security];
|
|
|
|
if ([limitedSecurity objectForKey: @"certificate"])
|
|
|
|
{
|
|
|
|
[limitedSecurity setObject: [NSNumber numberWithBool: YES] forKey: @"hasCertificate"];
|
|
|
|
[limitedSecurity removeObjectForKey: @"certificate"];
|
|
|
|
}
|
|
|
|
[auxAccount setObject: limitedSecurity forKey: @"security"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We inject our default mail account
|
2015-04-30 17:19:30 +02:00
|
|
|
account = [[[context activeUser] mailAccounts] objectAtIndex: 0];
|
|
|
|
if (![account objectForKey: @"receipts"])
|
|
|
|
{
|
|
|
|
[account setObject: [NSDictionary dictionaryWithObjectsAndKeys: @"ignore", @"receiptAction",
|
|
|
|
@"ignore", @"receiptNonRecipientAction",
|
|
|
|
@"ignore", @"receiptOutsideDomainAction",
|
|
|
|
@"ignore", @"receiptAnyAction", nil]
|
|
|
|
forKey: @"receipts"];
|
|
|
|
}
|
2017-06-05 16:23:59 +02:00
|
|
|
if (account)
|
|
|
|
[accounts insertObject: account atIndex: 0];
|
2020-06-18 22:53:42 +02:00
|
|
|
[values setObject: accounts forKey: @"AuxiliaryMailAccounts"];
|
|
|
|
|
|
|
|
// Ignore parameters as they are injected in the system mail account ([SOGoUser mailAccounts])
|
|
|
|
[values removeObjectForKey: @"SOGoMailIdentities"];
|
2018-01-12 20:47:31 +01:00
|
|
|
[values removeObjectForKey: @"SOGoMailCertificate"];
|
|
|
|
[values removeObjectForKey: @"SOGoMailCertificateAlwaysSign"];
|
|
|
|
[values removeObjectForKey: @"SOGoMailCertificateAlwaysEncrypt"];
|
2021-01-14 21:13:27 +01:00
|
|
|
[values removeObjectForKey: @"SOGoMailForceDefaultIdentity"];
|
2015-04-30 17:19:30 +02:00
|
|
|
|
2016-06-15 22:02:12 +02:00
|
|
|
// Add the domain's default vacation subject if user has not specified a custom subject
|
|
|
|
vacationOptions = [defaults vacationOptions];
|
2016-12-01 17:21:59 +01:00
|
|
|
if (![[vacationOptions objectForKey: @"customSubject"] length] && [domainDefaults vacationDefaultSubject])
|
2016-06-15 22:02:12 +02:00
|
|
|
{
|
|
|
|
if (vacationOptions)
|
|
|
|
vacation = [NSMutableDictionary dictionaryWithDictionary: vacationOptions];
|
|
|
|
else
|
|
|
|
vacation = [NSMutableDictionary dictionary];
|
|
|
|
|
|
|
|
[vacation setObject: [domainDefaults vacationDefaultSubject] forKey: @"customSubject"];
|
|
|
|
[values setObject: vacation forKey: @"Vacation"];
|
|
|
|
}
|
2015-04-30 17:19:30 +02:00
|
|
|
|
2020-01-31 22:51:33 +01:00
|
|
|
// Ignore hasActiveExternalSieveScripts as it will be requested on demand
|
|
|
|
[values removeObjectForKey: @"hasActiveExternalSieveScripts"];
|
2019-11-15 20:37:35 +01:00
|
|
|
|
2017-06-01 19:50:46 +02:00
|
|
|
return [values jsonRepresentation];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) jsonSettingsAction
|
2017-06-01 19:50:46 +02:00
|
|
|
{
|
|
|
|
return [self responseWithStatus: 200
|
|
|
|
andString: [self jsonSettings]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) jsonSettings
|
2007-06-19 19:58:21 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserSettings *settings;
|
2015-04-08 20:19:31 +02:00
|
|
|
id v;
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
settings = [[context activeUser] userSettings];
|
|
|
|
|
2015-04-08 20:19:31 +02:00
|
|
|
// We sanitize PreventInvitationsWhitelist if we need to, this is due to the fact
|
|
|
|
// that SOGo <= 2.2.17 used to store it as a JSON *string* within the JSON-blob -
|
|
|
|
// sorry about this engineering brain fart!
|
|
|
|
v = [[settings objectForKey: @"Calendar"] objectForKey: @"PreventInvitationsWhitelist"];
|
|
|
|
|
2020-04-17 18:11:01 +02:00
|
|
|
if (v && [v isKindOfClass: [NSString class]] && [v length] > 0)
|
2015-04-08 20:19:31 +02:00
|
|
|
{
|
|
|
|
[[settings objectForKey: @"Calendar"] setObject: [v objectFromJSONString]
|
|
|
|
forKey: @"PreventInvitationsWhitelist"];
|
|
|
|
}
|
|
|
|
|
2015-08-17 15:55:14 +02:00
|
|
|
// Initialize some default values
|
|
|
|
if (![settings objectForKey: @"Calendar"])
|
|
|
|
[settings setObject: [NSMutableDictionary dictionary] forKey: @"Calendar"];
|
|
|
|
|
|
|
|
if (![settings objectForKey: @"Contact"])
|
|
|
|
[settings setObject: [NSMutableDictionary dictionary] forKey: @"Contact"];
|
|
|
|
|
|
|
|
if (![settings objectForKey: @"Mail"])
|
|
|
|
[settings setObject: [NSMutableDictionary dictionary] forKey: @"Mail"];
|
|
|
|
|
2017-06-01 19:50:46 +02:00
|
|
|
return [[[settings source] values] jsonRepresentation];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|