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

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

View File

@ -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];
}

View File

@ -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 <wsourdeau@inverse.ca>
* Ludovic Marcotte <lmarcotte@inverse.ca>
* Author: Inverse <info@inverse.ca>
*
* 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

View File

@ -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 <wsourdeau@inverse.ca>
* Ludovic Marcotte <lmarcotte@inverse.ca>
* Author: Inverse <info@inverse.ca>
*
* 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];

View File

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

View File

@ -36,13 +36,19 @@
#import <NGExtensions/NSNull+misc.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import <SOGo/NSString+Utilities.h>
#import "SOGo/SOGoCredentialsFile.h"
#import <SOGo/SOGoProductLoader.h>
#import <SOGo/SOGoSieveManager.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <Mailer/SOGoMailAccounts.h>
#import <Mailer/SOGoMailAccount.h>
#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

View File

@ -27,12 +27,18 @@
#import <Foundation/NSString.h>
#import <Foundation/NSUserDefaults.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import <NGObjWeb/WOApplication.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoProductLoader.h>
#import "SOGo/SOGoCredentialsFile.h"
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserFolder.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoSieveManager.h>
#import <Mailer/SOGoMailAccounts.h>
#import <Mailer/SOGoMailAccount.h>
#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];