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

pull/215/head
Ludovic Marcotte 2016-06-13 13:14:55 -04:00
parent dab18608c7
commit eab6502d5a
2 changed files with 33 additions and 0 deletions

View File

@ -1892,6 +1892,11 @@ host.
Defaults to `NO` when unset. 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 |D |SOGoMailPollingIntervals
|Parameter used to define the mail polling intervals (in minutes) |Parameter used to define the mail polling intervals (in minutes)
available to the user. The parameter is an array that can contain the available to the user. The parameter is an array that can contain the

View File

@ -34,11 +34,15 @@
#import <Appointments/SOGoFreeBusyObject.h> #import <Appointments/SOGoFreeBusyObject.h>
#import <Mailer/SOGoMailAccount.h>
#import <Mailer/SOGoMailAccounts.h>
#import <SOGo/SOGoCache.h> #import <SOGo/SOGoCache.h>
#import <SOGo/SOGoCASSession.h> #import <SOGo/SOGoCASSession.h>
#if defined(SAML2_CONFIG) #if defined(SAML2_CONFIG)
#import <SOGo/SOGoSAML2Session.h> #import <SOGo/SOGoSAML2Session.h>
#endif #endif
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoUserManager.h> #import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoWebAuthenticator.h> #import <SOGo/SOGoWebAuthenticator.h>
#import <SOGo/SOGoUser.h> #import <SOGo/SOGoUser.h>
@ -66,10 +70,16 @@
{ {
SOGoUserFolder *co; SOGoUserFolder *co;
NSString *loginModule; NSString *loginModule;
SOGoSystemDefaults *sd;
SOGoDomainDefaults *dd;
SOGoUserDefaults *ud; SOGoUserDefaults *ud;
NSArray *filters;
NSURL *moduleURL; NSURL *moduleURL;
sd = [SOGoSystemDefaults sharedSystemDefaults];
dd = [[context activeUser] domainDefaults];
ud = [[context activeUser] userDefaults]; ud = [[context activeUser] userDefaults];
loginModule = [ud loginModule]; loginModule = [ud loginModule];
if (!([loginModule isEqualToString: @"Calendar"] if (!([loginModule isEqualToString: @"Calendar"]
|| [loginModule isEqualToString: @"Contacts"] || [loginModule isEqualToString: @"Contacts"]
@ -80,6 +90,24 @@
loginModule = @"Calendar"; 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]; co = [self clientObject];
moduleURL = [NSURL URLWithString: loginModule moduleURL = [NSURL URLWithString: loginModule
relativeToURL: [co soURL]]; relativeToURL: [co soURL]];