(feat) now possible to set a default Sieve filter (fixes #2949)

pull/214/head
Ludovic Marcotte 2016-06-13 13:14:55 -04:00
parent 4f64994f7b
commit ae7fefb487
2 changed files with 33 additions and 0 deletions

View File

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

View File

@ -27,11 +27,15 @@
#import <Appointments/SOGoFreeBusyObject.h>
#import <Mailer/SOGoMailAccount.h>
#import <Mailer/SOGoMailAccounts.h>
#import <SOGo/SOGoCache.h>
#import <SOGo/SOGoCASSession.h>
#if defined(SAML2_CONFIG)
#import <SOGo/SOGoSAML2Session.h>
#endif
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoWebAuthenticator.h>
#import <SOGo/SOGoUser.h>
@ -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]];