Fix sogo-tool operations on Sieve script

Fixes #2617
pull/20/head
Francis Lachapelle 2014-03-03 22:07:24 -05:00
parent c6b227160c
commit 1aabcf04b5
8 changed files with 118 additions and 32 deletions

7
NEWS
View File

@ -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) 2.2.0 (2014-02-24)
------------------ ------------------

View File

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2009-2013 Inverse inc. Copyright (C) 2009-2014 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo. This file is part of SOGo.
@ -71,6 +71,8 @@ typedef enum {
- (id) getInboxQuota; - (id) getInboxQuota;
- (BOOL) updateFilters; - (BOOL) updateFilters;
- (BOOL) updateFiltersWithUsername: (NSString *) theUsername
andPassword: (NSString *) thePassword;
- (NSArray *) identities; - (NSArray *) identities;
- (NSString *) signature; - (NSString *) signature;

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2004-2005 SKYRIX Software AG 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. This file is part of SOGo.
@ -306,12 +306,18 @@ static NSString *inboxFolderName = @"INBOX";
} }
- (BOOL) updateFilters - (BOOL) updateFilters
{
return [self updateFiltersWithUsername: nil andPassword: nil];
}
- (BOOL) updateFiltersWithUsername: (NSString *) theUsername
andPassword: (NSString *) thePassword
{ {
SOGoSieveManager *manager; SOGoSieveManager *manager;
manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]]; manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]];
return [manager updateFiltersForAccount: self]; return [manager updateFiltersForAccount: self withUsername: theUsername andPassword: thePassword];
} }

View File

@ -1,9 +1,8 @@
/* SOGoSieveManager.h - this file is part of SOGo /* SOGoSieveManager.h - this file is part of SOGo
* *
* Copyright (C) 2010-2011 Inverse inc. * Copyright (C) 2010-2014 Inverse inc.
* *
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca> * Author: Inverse <info@inverse.ca>
* Ludovic Marcotte <lmarcotte@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -47,8 +46,14 @@
- (NSString *) lastScriptError; - (NSString *) lastScriptError;
- (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount; - (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount;
- (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount
withUsername: (NSString *) theUsername
andPassword: (NSString *) thePassword;
- (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount; - (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount;
- (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount
withUsername: (NSString *) theUsername
andPassword: (NSString *) thePassword;
@end @end

View File

@ -1,9 +1,8 @@
/* SOGoSieveManager.m - this file is part of SOGo /* SOGoSieveManager.m - this file is part of SOGo
* *
* Copyright (C) 2010-2011 Inverse inc. * Copyright (C) 2010-2014 Inverse inc.
* *
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca> * Author: Inverse <info@inverse.ca>
* Ludovic Marcotte <lmarcotte@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * 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 - (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount
{
return [self clientForAccount: theAccount withUsername: nil andPassword: nil];
}
//
//
//
- (NGSieveClient *) clientForAccount: (SOGoMailAccount *) theAccount
withUsername: (NSString *) theUsername
andPassword: (NSString *) thePassword
{ {
NSDictionary *result; NSDictionary *result;
NSString *login, *authname, *password; NSString *login, *authname, *password;
@ -640,8 +649,16 @@ static NSString *sieveScriptName = @"sogo";
// Extract credentials from mail account // Extract credentials from mail account
login = [[theAccount imap4URL] user]; login = [[theAccount imap4URL] user];
authname = [[theAccount imap4URL] user]; if (!theUsername && !thePassword)
password = [theAccount imap4PasswordRenewed: NO]; {
authname = [[theAccount imap4URL] user];
password = [theAccount imap4PasswordRenewed: NO];
}
else
{
authname = theUsername;
password = thePassword;
}
// We connect to our Sieve server and check capabilities, in order // We connect to our Sieve server and check capabilities, in order
// to generate the right script, based on capabilities // to generate the right script, based on capabilities
@ -725,7 +742,7 @@ static NSString *sieveScriptName = @"sogo";
return nil; return nil;
} }
if (![[result valueForKey:@"result"] boolValue]) { if (![[result valueForKey:@"result"] boolValue] && !theUsername && !thePassword) {
NSLog(@"failure. Attempting with a renewed password (no authname supported)"); NSLog(@"failure. Attempting with a renewed password (no authname supported)");
password = [theAccount imap4PasswordRenewed: YES]; password = [theAccount imap4PasswordRenewed: YES];
result = [client login: login password: password]; result = [client login: login password: password];
@ -741,10 +758,23 @@ static NSString *sieveScriptName = @"sogo";
return client; return client;
} }
// //
// //
// //
- (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount - (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount
{
return [self updateFiltersForAccount: theAccount
withUsername: nil
andPassword: nil];
}
//
//
//
- (BOOL) updateFiltersForAccount: (SOGoMailAccount *) theAccount
withUsername: (NSString *) theUsername
andPassword: (NSString *) thePassword
{ {
NSMutableArray *req; NSMutableArray *req;
NSMutableString *script, *header; NSMutableString *script, *header;
@ -762,7 +792,7 @@ static NSString *sieveScriptName = @"sogo";
req = [NSMutableArray arrayWithCapacity: 15]; req = [NSMutableArray arrayWithCapacity: 15];
ud = [user userDefaults]; ud = [user userDefaults];
client = [self clientForAccount: theAccount]; client = [self clientForAccount: theAccount withUsername: theUsername andPassword: thePassword];
if (!client) if (!client)
return NO; return NO;
@ -888,7 +918,7 @@ static NSString *sieveScriptName = @"sogo";
// We put and activate the script only if we actually have a script // We put and activate the script only if we actually have a script
// that does something... // that does something...
if (b) if (b && [script length])
{ {
result = [client putScript: sieveScriptName script: script]; result = [client putScript: sieveScriptName script: script];

View File

@ -14,4 +14,4 @@ ADDITIONAL_LIB_DIRS += \
-L../OGoContentStore/$(GNUSTEP_OBJ_DIR)/ -lOGoContentStore \ -L../OGoContentStore/$(GNUSTEP_OBJ_DIR)/ -lOGoContentStore \
-L../SOPE/GDLContentStore/$(GNUSTEP_OBJ_DIR)/ -lGDLContentStore \ -L../SOPE/GDLContentStore/$(GNUSTEP_OBJ_DIR)/ -lGDLContentStore \
-L../SOPE/NGCards/$(GNUSTEP_OBJ_DIR)/ -lNGCards \ -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

View File

@ -36,13 +36,19 @@
#import <NGExtensions/NSNull+misc.h> #import <NGExtensions/NSNull+misc.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import <SOGo/NSString+Utilities.h> #import <SOGo/NSString+Utilities.h>
#import "SOGo/SOGoCredentialsFile.h" #import "SOGo/SOGoCredentialsFile.h"
#import <SOGo/SOGoProductLoader.h>
#import <SOGo/SOGoSieveManager.h> #import <SOGo/SOGoSieveManager.h>
#import <SOGo/SOGoSystemDefaults.h> #import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUser.h> #import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h> #import <SOGo/SOGoUserDefaults.h>
#import <Mailer/SOGoMailAccounts.h>
#import <Mailer/SOGoMailAccount.h>
#import "SOGoTool.h" #import "SOGoTool.h"
@interface SOGoToolExpireAutoReply : SOGoTool @interface SOGoToolExpireAutoReply : SOGoTool
@ -80,12 +86,10 @@
{ {
NSMutableDictionary *vacationOptions; NSMutableDictionary *vacationOptions;
SOGoUserDefaults *userDefaults; SOGoUserDefaults *userDefaults;
SOGoSieveManager *manager;
SOGoUser *user; SOGoUser *user;
BOOL result; BOOL result;
user = [SOGoUser userWithLogin: theLogin]; user = [SOGoUser userWithLogin: theLogin];
manager = [SOGoSieveManager sieveManagerForUser: user];
userDefaults = [user userDefaults]; userDefaults = [user userDefaults];
vacationOptions = [[userDefaults vacationOptions] mutableCopy]; vacationOptions = [[userDefaults vacationOptions] mutableCopy];
[vacationOptions autorelease]; [vacationOptions autorelease];
@ -96,10 +100,24 @@
if (result) if (result)
{ {
result = [manager updateFiltersForLogin: theLogin SOGoUserFolder *home;
authname: theUsername SOGoMailAccounts *folder;
password: thePassword SOGoMailAccount *account;
account: nil]; 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) if (!result)
{ {
// Can't update Sieve script -- Reactivate auto-reply // Can't update Sieve script -- Reactivate auto-reply

View File

@ -27,12 +27,18 @@
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
#import <Foundation/NSUserDefaults.h> #import <Foundation/NSUserDefaults.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import <NGObjWeb/WOApplication.h>
#import <SOGo/NSString+Utilities.h> #import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoProductLoader.h>
#import "SOGo/SOGoCredentialsFile.h" #import "SOGo/SOGoCredentialsFile.h"
#import <SOGo/SOGoUser.h> #import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserFolder.h>
#import <SOGo/SOGoUserDefaults.h> #import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserSettings.h> #import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoSieveManager.h> #import <Mailer/SOGoMailAccounts.h>
#import <Mailer/SOGoMailAccount.h>
#import "SOGoTool.h" #import "SOGoTool.h"
@ -102,7 +108,6 @@ typedef enum
// Vacation // Vacation
// //
- (BOOL) _updateSieveScripsForkey: (NSString *) theKey - (BOOL) _updateSieveScripsForkey: (NSString *) theKey
manager: (SOGoSieveManager *) theManager
login: (NSString *) theLogin login: (NSString *) theLogin
{ {
if ([theKey caseInsensitiveCompare: @"Forward"] == NSOrderedSame || if ([theKey caseInsensitiveCompare: @"Forward"] == NSOrderedSame ||
@ -126,11 +131,28 @@ typedef enum
NSLog(@"To update Sieve scripts, you must provide the \"-p credentialFile\" parameter"); NSLog(@"To update Sieve scripts, you must provide the \"-p credentialFile\" parameter");
return NO; return NO;
} }
return [theManager updateFiltersForLogin: theLogin /* update sieve script */
authname: authname SOGoUser *user;
password: authpwd SOGoUserFolder *home;
account: nil]; 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; return YES;
@ -154,7 +176,6 @@ typedef enum
if (max > 3) if (max > 3)
{ {
SOGoDefaultsSource *source; SOGoDefaultsSource *source;
SOGoSieveManager *manager;
SOGoUser *user; SOGoUser *user;
cmd = [self _cmdFromString: [sanitizedArguments objectAtIndex: 0]]; cmd = [self _cmdFromString: [sanitizedArguments objectAtIndex: 0]];
@ -164,7 +185,6 @@ typedef enum
key = [sanitizedArguments objectAtIndex: 3]; key = [sanitizedArguments objectAtIndex: 3];
user = [SOGoUser userWithLogin: userId]; user = [SOGoUser userWithLogin: userId];
manager = [SOGoSieveManager sieveManagerForUser: user];
if ([type caseInsensitiveCompare: @"defaults"] == NSOrderedSame) if ([type caseInsensitiveCompare: @"defaults"] == NSOrderedSame)
source = [user userDefaults]; source = [user userDefaults];
@ -254,7 +274,6 @@ typedef enum
} }
rc = [self _updateSieveScripsForkey: key rc = [self _updateSieveScripsForkey: key
manager: manager
login: userId]; login: userId];
if (rc) if (rc)
[source synchronize]; [source synchronize];
@ -266,7 +285,6 @@ typedef enum
case UserPreferencesUnset: case UserPreferencesUnset:
[source removeObjectForKey: key]; [source removeObjectForKey: key];
rc = [self _updateSieveScripsForkey: key rc = [self _updateSieveScripsForkey: key
manager: manager
login: userId]; login: userId];
if (rc) if (rc)
[source synchronize]; [source synchronize];