From 1aabcf04b5d26471a62f97566bb3fd6911848f48 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 3 Mar 2014 22:07:24 -0500 Subject: [PATCH] Fix sogo-tool operations on Sieve script Fixes #2617 --- NEWS | 7 +++++ SoObjects/Mailer/SOGoMailAccount.h | 4 ++- SoObjects/Mailer/SOGoMailAccount.m | 10 +++++-- SoObjects/SOGo/SOGoSieveManager.h | 11 +++++-- SoObjects/SOGo/SOGoSieveManager.m | 46 ++++++++++++++++++++++++------ Tools/GNUmakefile.preamble | 2 +- Tools/SOGoToolExpireAutoReply.m | 30 +++++++++++++++---- Tools/SOGoToolUserPreferences.m | 40 +++++++++++++++++++------- 8 files changed, 118 insertions(+), 32 deletions(-) diff --git a/NEWS b/NEWS index 88fceeb4f..b979e6ed5 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +2.2.0a (2014-03-XX) +------------------- + +Bug fixes +- fixed an issue with ActiveSync when the number of messages in the mailbox was greater than the window-size specified by the client +- fixed sogo-tool operations on Sieve script (#2617) + 2.2.0 (2014-02-24) ------------------ diff --git a/SoObjects/Mailer/SOGoMailAccount.h b/SoObjects/Mailer/SOGoMailAccount.h index cec85d61e..2efc05fc1 100644 --- a/SoObjects/Mailer/SOGoMailAccount.h +++ b/SoObjects/Mailer/SOGoMailAccount.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2009-2013 Inverse inc. + Copyright (C) 2009-2014 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG This file is part of SOGo. @@ -71,6 +71,8 @@ typedef enum { - (id) getInboxQuota; - (BOOL) updateFilters; +- (BOOL) updateFiltersWithUsername: (NSString *) theUsername + andPassword: (NSString *) thePassword; - (NSArray *) identities; - (NSString *) signature; diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 2beb53acb..5f9a67c49 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -1,6 +1,6 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG - Copyright (C) 2007-2013 Inverse inc. + Copyright (C) 2007-2014 Inverse inc. This file is part of SOGo. @@ -306,12 +306,18 @@ static NSString *inboxFolderName = @"INBOX"; } - (BOOL) updateFilters +{ + return [self updateFiltersWithUsername: nil andPassword: nil]; +} + +- (BOOL) updateFiltersWithUsername: (NSString *) theUsername + andPassword: (NSString *) thePassword { SOGoSieveManager *manager; manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]]; - return [manager updateFiltersForAccount: self]; + return [manager updateFiltersForAccount: self withUsername: theUsername andPassword: thePassword]; } diff --git a/SoObjects/SOGo/SOGoSieveManager.h b/SoObjects/SOGo/SOGoSieveManager.h index 783a948d8..a1c28fd56 100644 --- a/SoObjects/SOGo/SOGoSieveManager.h +++ b/SoObjects/SOGo/SOGoSieveManager.h @@ -1,9 +1,8 @@ /* SOGoSieveManager.h - this file is part of SOGo * - * Copyright (C) 2010-2011 Inverse inc. + * Copyright (C) 2010-2014 Inverse inc. * - * Author: Wolfgang Sourdeau - * Ludovic Marcotte + * Author: Inverse * * 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 @@ -47,8 +46,14 @@ - (NSString *) lastScriptError; - (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount; +- (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount + withUsername: (NSString *) theUsername + andPassword: (NSString *) thePassword; - (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount; +- (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount + withUsername: (NSString *) theUsername + andPassword: (NSString *) thePassword; @end diff --git a/SoObjects/SOGo/SOGoSieveManager.m b/SoObjects/SOGo/SOGoSieveManager.m index 72a4cfc25..765ad32d6 100644 --- a/SoObjects/SOGo/SOGoSieveManager.m +++ b/SoObjects/SOGo/SOGoSieveManager.m @@ -1,9 +1,8 @@ /* SOGoSieveManager.m - this file is part of SOGo * - * Copyright (C) 2010-2011 Inverse inc. + * Copyright (C) 2010-2014 Inverse inc. * - * Author: Wolfgang Sourdeau - * Ludovic Marcotte + * Author: Inverse * * 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 @@ -625,6 +624,16 @@ static NSString *sieveScriptName = @"sogo"; // // - (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount +{ + return [self clientForAccount: theAccount withUsername: nil andPassword: nil]; +} + +// +// +// +- (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount + withUsername: (NSString *) theUsername + andPassword: (NSString *) thePassword { NSDictionary *result; NSString *login, *authname, *password; @@ -640,8 +649,16 @@ static NSString *sieveScriptName = @"sogo"; // Extract credentials from mail account login = [[theAccount imap4URL] user]; - authname = [[theAccount imap4URL] user]; - password = [theAccount imap4PasswordRenewed: NO]; + if (!theUsername && !thePassword) + { + authname = [[theAccount imap4URL] user]; + password = [theAccount imap4PasswordRenewed: NO]; + } + else + { + authname = theUsername; + password = thePassword; + } // We connect to our Sieve server and check capabilities, in order // to generate the right script, based on capabilities @@ -725,7 +742,7 @@ static NSString *sieveScriptName = @"sogo"; return nil; } - if (![[result valueForKey:@"result"] boolValue]) { + if (![[result valueForKey:@"result"] boolValue] && !theUsername && !thePassword) { NSLog(@"failure. Attempting with a renewed password (no authname supported)"); password = [theAccount imap4PasswordRenewed: YES]; result = [client login: login password: password]; @@ -741,10 +758,23 @@ static NSString *sieveScriptName = @"sogo"; return client; } + // // // - (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount +{ + return [self updateFiltersForAccount: theAccount + withUsername: nil + andPassword: nil]; +} + +// +// +// +- (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount + withUsername: (NSString *) theUsername + andPassword: (NSString *) thePassword { NSMutableArray *req; NSMutableString *script, *header; @@ -762,7 +792,7 @@ static NSString *sieveScriptName = @"sogo"; req = [NSMutableArray arrayWithCapacity: 15]; ud = [user userDefaults]; - client = [self clientForAccount: theAccount]; + client = [self clientForAccount: theAccount withUsername: theUsername andPassword: thePassword]; if (!client) return NO; @@ -888,7 +918,7 @@ static NSString *sieveScriptName = @"sogo"; // We put and activate the script only if we actually have a script // that does something... - if (b) + if (b && [script length]) { result = [client putScript: sieveScriptName script: script]; diff --git a/Tools/GNUmakefile.preamble b/Tools/GNUmakefile.preamble index 8f087f01c..3c0700276 100644 --- a/Tools/GNUmakefile.preamble +++ b/Tools/GNUmakefile.preamble @@ -14,4 +14,4 @@ ADDITIONAL_LIB_DIRS += \ -L../OGoContentStore/$(GNUSTEP_OBJ_DIR)/ -lOGoContentStore \ -L../SOPE/GDLContentStore/$(GNUSTEP_OBJ_DIR)/ -lGDLContentStore \ -L../SOPE/NGCards/$(GNUSTEP_OBJ_DIR)/ -lNGCards \ - -L/usr/local/lib -L/usr/lib -lEOControl -lNGStreams -lNGMime -lNGExtensions + -L/usr/local/lib -L/usr/lib -lEOControl -lNGStreams -lNGMime -lNGExtensions -lNGObjWeb diff --git a/Tools/SOGoToolExpireAutoReply.m b/Tools/SOGoToolExpireAutoReply.m index ddfa3890d..d3f600054 100644 --- a/Tools/SOGoToolExpireAutoReply.m +++ b/Tools/SOGoToolExpireAutoReply.m @@ -36,13 +36,19 @@ #import +#import + #import #import "SOGo/SOGoCredentialsFile.h" +#import #import #import #import #import +#import +#import + #import "SOGoTool.h" @interface SOGoToolExpireAutoReply : SOGoTool @@ -80,12 +86,10 @@ { NSMutableDictionary *vacationOptions; SOGoUserDefaults *userDefaults; - SOGoSieveManager *manager; SOGoUser *user; BOOL result; user = [SOGoUser userWithLogin: theLogin]; - manager = [SOGoSieveManager sieveManagerForUser: user]; userDefaults = [user userDefaults]; vacationOptions = [[userDefaults vacationOptions] mutableCopy]; [vacationOptions autorelease]; @@ -96,10 +100,24 @@ if (result) { - result = [manager updateFiltersForLogin: theLogin - authname: theUsername - password: thePassword - account: nil]; + SOGoUserFolder *home; + SOGoMailAccounts *folder; + SOGoMailAccount *account; + WOContext *localContext; + Class SOGoMailAccounts_class; + + [[SOGoProductLoader productLoader] loadProducts: [NSArray arrayWithObject: @"Mailer.SOGo"]]; + SOGoMailAccounts_class = NSClassFromString(@"SOGoMailAccounts"); + + localContext = [WOContext context]; + [localContext setActiveUser: user]; + + home = [user homeFolderInContext: localContext]; + folder = [SOGoMailAccounts_class objectWithName: @"Mail" inContainer: home]; + account = [folder lookupName: @"0" inContext: localContext acquire: NO]; + [account setContext: localContext]; + + result = [account updateFiltersWithUsername: theUsername andPassword: thePassword]; if (!result) { // Can't update Sieve script -- Reactivate auto-reply diff --git a/Tools/SOGoToolUserPreferences.m b/Tools/SOGoToolUserPreferences.m index 3d1f982a2..a6255d6f0 100644 --- a/Tools/SOGoToolUserPreferences.m +++ b/Tools/SOGoToolUserPreferences.m @@ -27,12 +27,18 @@ #import #import +#import +#import + #import +#import #import "SOGo/SOGoCredentialsFile.h" #import +#import #import #import -#import +#import +#import #import "SOGoTool.h" @@ -102,7 +108,6 @@ typedef enum // Vacation // - (BOOL) _updateSieveScripsForkey: (NSString *) theKey - manager: (SOGoSieveManager *) theManager login: (NSString *) theLogin { if ([theKey caseInsensitiveCompare: @"Forward"] == NSOrderedSame || @@ -126,11 +131,28 @@ typedef enum NSLog(@"To update Sieve scripts, you must provide the \"-p credentialFile\" parameter"); return NO; } - - return [theManager updateFiltersForLogin: theLogin - authname: authname - password: authpwd - account: nil]; + + /* update sieve script */ + SOGoUser *user; + SOGoUserFolder *home; + SOGoMailAccounts *folder; + SOGoMailAccount *account; + WOContext *localContext; + Class SOGoMailAccounts_class; + + [[SOGoProductLoader productLoader] loadProducts: [NSArray arrayWithObject: @"Mailer.SOGo"]]; + SOGoMailAccounts_class = NSClassFromString(@"SOGoMailAccounts"); + + user = [SOGoUser userWithLogin: theLogin]; + localContext = [WOContext context]; + [localContext setActiveUser: user]; + + home = [user homeFolderInContext: localContext]; + folder = [SOGoMailAccounts_class objectWithName: @"Mail" inContainer: home]; + account = [folder lookupName: @"0" inContext: localContext acquire: NO]; + [account setContext: localContext]; + + return [account updateFiltersWithUsername: authname andPassword: authpwd]; } return YES; @@ -154,7 +176,6 @@ typedef enum if (max > 3) { SOGoDefaultsSource *source; - SOGoSieveManager *manager; SOGoUser *user; cmd = [self _cmdFromString: [sanitizedArguments objectAtIndex: 0]]; @@ -164,7 +185,6 @@ typedef enum key = [sanitizedArguments objectAtIndex: 3]; user = [SOGoUser userWithLogin: userId]; - manager = [SOGoSieveManager sieveManagerForUser: user]; if ([type caseInsensitiveCompare: @"defaults"] == NSOrderedSame) source = [user userDefaults]; @@ -254,7 +274,6 @@ typedef enum } rc = [self _updateSieveScripsForkey: key - manager: manager login: userId]; if (rc) [source synchronize]; @@ -266,7 +285,6 @@ typedef enum case UserPreferencesUnset: [source removeObjectForKey: key]; rc = [self _updateSieveScripsForkey: key - manager: manager login: userId]; if (rc) [source synchronize];