*/
@class NSString, NSArray, NSURL;
-@class NGImap4Client;
+@class NGImap4Client, NGSieveClient;
@class SOGoMailManager;
@class SOGoMailAccount;
@interface SOGoSieveBaseObject : SOGoObject
{
+ NGSieveClient *sieveClient;
}
/* hierarchy */
- (NGImap4Client *)imap4Client;
- (void)flushMailCaches;
+/* Sieve */
+
+- (NGSieveClient *)sieveClient;
+
@end
#endif /* __Sieve_SOGoSieveBaseObject_H__ */
#include <Mailer/SOGoMailManager.h>
#include <Mailer/SOGoMailAccount.h>
#include "common.h"
+#include <NGImap4/NGSieveClient.h>
#include <NGObjWeb/SoObject+SoDAV.h>
#include <NGObjWeb/SoHTTPAuthenticator.h>
#include <NGExtensions/NSURL+misc.h>
@implementation SOGoSieveBaseObject
+- (void)dealloc {
+ [self->sieveClient release];
+ [super dealloc];
+}
+
/* hierarchy */
- (SOGoMailAccount *)mailAccountFolder {
- (void)flushMailCaches {
}
+/* Sieve */
+
+- (NGSieveClient *)sieveClient {
+ id res;
+
+ if (self->sieveClient != nil)
+ return self->sieveClient;
+
+ /* check container */
+
+ res = [self container];
+ if ([res respondsToSelector:_cmd]) {
+ if ((res = [res sieveClient]) != nil) {
+ self->sieveClient = [res retain];
+ return self->sieveClient;
+ }
+ }
+
+ /* create client */
+
+ self->sieveClient =
+ [[NGSieveClient alloc] initWithHost:[[self imap4URL] host]];
+ if (self->sieveClient == nil)
+ return nil;
+
+ /* login */
+
+ res = [self->sieveClient
+ login:[[self imap4URL] user]
+ password:[self imap4Password]];
+
+ if (![[res valueForKey:@"result"] boolValue]) {
+ [self logWithFormat:
+ @"ERROR: could not login '%@'(%@) into Sieve server: %@: %@",
+ [[self imap4URL] user], [self imap4Password],
+ self->sieveClient, res];
+ [self->sieveClient release]; self->sieveClient = nil;
+ return nil;
+ }
+
+ return self->sieveClient;
+}
+
/* debugging */
- (NSString *)loggingPrefix {
*/
#include "SOGoSieveScriptsFolder.h"
+#include <NGImap4/NGSieveClient.h>
#include "common.h"
@implementation SOGoSieveScriptsFolder
+- (void)dealloc {
+ [self->listedScripts release];
+ [super dealloc];
+}
+
+/* listing */
+
+- (NSDictionary *)fetchScripts {
+ if (self->listedScripts != nil)
+ return self->listedScripts;
+
+ self->listedScripts = [[[self sieveClient] listScripts] copy];
+ return self->listedScripts;
+}
+
+/* standard methods */
+
+- (NSArray *)toOneRelationshipKeys {
+ return [[self fetchScripts] allKeys];
+}
+
@end /* SOGoSieveScriptsFolder */