From ae7fefb487c206947c78c978b5e0331a58f56c48 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 13 Jun 2016 13:14:55 -0400 Subject: [PATCH] (feat) now possible to set a default Sieve filter (fixes #2949) --- Documentation/SOGoInstallationGuide.asciidoc | 5 ++++ UI/MainUI/SOGoUserHomePage.m | 28 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index 2a6ec3db1..6ace3ee05 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -2018,6 +2018,11 @@ host. Defaults to `NO` when unset. +|U |SOGoSieveFilters +|Parameter used to define initial Sieve scripts for users. The user +can still modify the scripts and the initial values will be written +to the Sieve server upon first login. + |D |SOGoMailPollingIntervals |Parameter used to define the mail polling intervals (in minutes) available to the user. The parameter is an array that can contain the diff --git a/UI/MainUI/SOGoUserHomePage.m b/UI/MainUI/SOGoUserHomePage.m index e6cf4bfb7..527bab135 100644 --- a/UI/MainUI/SOGoUserHomePage.m +++ b/UI/MainUI/SOGoUserHomePage.m @@ -27,11 +27,15 @@ #import +#import +#import + #import #import #if defined(SAML2_CONFIG) #import #endif +#import #import #import #import @@ -58,10 +62,16 @@ { SOGoUserFolder *co; NSString *loginModule; + SOGoSystemDefaults *sd; + SOGoDomainDefaults *dd; SOGoUserDefaults *ud; + NSArray *filters; NSURL *moduleURL; + sd = [SOGoSystemDefaults sharedSystemDefaults]; + dd = [[context activeUser] domainDefaults]; ud = [[context activeUser] userDefaults]; + loginModule = [ud loginModule]; if (!([loginModule isEqualToString: @"Calendar"] || [loginModule isEqualToString: @"Contacts"] @@ -72,6 +82,24 @@ loginModule = @"Calendar"; } + // We check if we must write the Sieve scripts to the server + // upon first login if no user preferences are found, and the SOGo + // admin has defined SOGoSieveFilters in the domain or system settings + if ([dd sieveScriptsEnabled] && [[[ud source] values] count] == 0 && + ((filters = [[dd source] objectForKey: @"SOGoSieveFilters"]) || (filters = [[sd source] objectForKey: @"SOGoSieveFilters"]))) + { + SOGoMailAccount *account; + SOGoMailAccounts *folder; + + [ud setSieveFilters: filters]; + [ud synchronize]; + + folder = [[self clientObject] mailAccountsFolder: @"Mail" + inContext: context]; + account = [folder lookupName: @"0" inContext: context acquire: NO]; + [account updateFilters]; + } + co = [self clientObject]; moduleURL = [NSURL URLWithString: loginModule relativeToURL: [co soURL]];