From 88898561379d5ec21f1f0742135088ca7697f3d1 Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 25 Mar 2005 14:25:33 +0000 Subject: [PATCH] improved WebDAV support added methods to return select info git-svn-id: http://svn.opengroupware.org/SOGo/trunk@638 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 7 ++ SOGo/SoObjects/Mailer/GNUmakefile | 1 + SOGo/SoObjects/Mailer/SOGoMailFolder.h | 2 + SOGo/SoObjects/Mailer/SOGoMailFolder.m | 44 +++++++++-- SOGo/SoObjects/Mailer/SOGoMailManager.h | 2 + SOGo/SoObjects/Mailer/SOGoMailManager.m | 31 +++++++- SOGo/SoObjects/Mailer/SOGoMailboxInfo.h | 60 ++++++++++++++ SOGo/SoObjects/Mailer/SOGoMailboxInfo.m | 101 ++++++++++++++++++++++++ SOGo/SoObjects/Mailer/Version | 2 +- SOGo/SoObjects/Mailer/common.h | 2 + 10 files changed, 241 insertions(+), 11 deletions(-) create mode 100644 SOGo/SoObjects/Mailer/SOGoMailboxInfo.h create mode 100644 SOGo/SoObjects/Mailer/SOGoMailboxInfo.m diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 90454a58..e4d5f4e3 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,12 @@ 2005-03-25 Helge Hess + * v0.9.79 + + * SOGoMailFolder.m: ensure that mailbox exists if a DAV depth:0 query + is run on the folder (by selecting the mailbox) + + * SOGoMailManager.m: added method to retrieve mailbox select info + * SOGoMailAccount.m: added ability to create mailboxes at the root (account) level (v0.9.78) diff --git a/SOGo/SoObjects/Mailer/GNUmakefile b/SOGo/SoObjects/Mailer/GNUmakefile index 31da6471..a6cf7580 100644 --- a/SOGo/SoObjects/Mailer/GNUmakefile +++ b/SOGo/SoObjects/Mailer/GNUmakefile @@ -10,6 +10,7 @@ Mailer_OBJC_FILES += \ Product.m \ \ SOGoMailManager.m \ + SOGoMailboxInfo.m \ SOGoMailConnectionEntry.m \ \ SOGoMailBaseObject.m \ diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.h b/SOGo/SoObjects/Mailer/SOGoMailFolder.h index cc7d34ab..441de750 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.h +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.h @@ -34,11 +34,13 @@ */ @class NSData, NSArray, NSException; +@class SOGoMailboxInfo; @interface SOGoMailFolder : SOGoMailBaseObject { NSArray *filenames; NSString *folderType; + SOGoMailboxInfo *selectInfo; } /* messages */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.m b/SOGo/SoObjects/Mailer/SOGoMailFolder.m index 83b69dcb..459cf049 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.m @@ -23,11 +23,13 @@ #include "SOGoMailObject.h" #include "SOGoMailAccount.h" #include "SOGoMailManager.h" +#include "SOGoMailboxInfo.h" #include "common.h" @implementation SOGoMailFolder - (void)dealloc { + [self->selectInfo release]; [self->filenames release]; [self->folderType release]; [super dealloc]; @@ -77,6 +79,24 @@ return self->filenames; } +/* mailbox raw ops */ + +- (NSException *)primaryFetchMailboxInfo { + /* returns nil if fetch was successful */ + id info; + + if (self->selectInfo != nil) + return nil; /* select info exists, => no error */ + + info = [[self mailManager] infoForMailboxAtURL:[self imap4URL] + password:[self imap4Password]]; + if ([info isKindOfClass:[NSException class]]) + return info; + + self->selectInfo = [info retain]; + return nil; /* no error */ +} + /* messages */ - (NSArray *)fetchUIDsMatchingQualifier:(id)_q sortOrdering:(id)_so { @@ -169,6 +189,22 @@ password:[self imap4Password]]; } +- (id)davQueryOnSelf:(EOFetchSpecification *)_fs inContext:(id)_ctx { + NSException *error; + + /* ensure that the mailbox exists */ + if ((error = [self primaryFetchMailboxInfo]) != nil) + return error; + + return [super davQueryOnSelf:_fs inContext:_ctx]; +} + +- (NSException *)delete { + /* Note: overrides SOGoObject -delete */ + return [[self mailManager] deleteMailboxAtURL:[self imap4URL] + password:[self imap4Password]]; +} + /* folder type */ - (NSString *)outlookFolderClass { @@ -194,12 +230,4 @@ return self->folderType; } -/* operations */ - -- (NSException *)delete { - /* Note: overrides SOGoObject -delete */ - return [[self mailManager] deleteMailboxAtURL:[self imap4URL] - password:[self imap4Password]]; -} - @end /* SOGoMailFolder */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.h b/SOGo/SoObjects/Mailer/SOGoMailManager.h index 726226c7..c4637128 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.h +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.h @@ -80,6 +80,8 @@ /* managing folders */ +- (id)infoForMailboxAtURL:(NSURL *)_url password:(NSString *)_pwd; + - (NSException *)createMailbox:(NSString *)_mailbox atURL:(NSURL *)_url password:(NSString *)_pwd; - (NSException *)deleteMailboxAtURL:(NSURL *)_url password:(NSString *)_pwd; diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m index 46487787..21b7e02e 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.m +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -21,6 +21,7 @@ #include "SOGoMailManager.h" #include "SOGoMailConnectionEntry.h" +#include "SOGoMailboxInfo.h" #include "common.h" /* @@ -723,6 +724,30 @@ static NSString *imap4Separator = nil; isEqualToString:@"Permission denied"]; } +- (id)infoForMailboxAtURL:(NSURL *)_url password:(NSString *)_pwd { + SOGoMailConnectionEntry *entry; + SOGoMailboxInfo *info; + NSString *folderName; + id result; + + if ((entry = [self entryForURL:_url password:_pwd]) == nil) { + // TODO: better to use an auth exception? + return [NSException exceptionWithHTTPStatus:404 /* Not Found */ + reason:@"did not find IMAP4 folder (no entry)"]; + } + + folderName = [self imap4FolderNameForURL:_url]; + result = [[entry client] select:folderName]; + if (![[result valueForKey:@"result"] boolValue]) { + return [NSException exceptionWithHTTPStatus:404 /* Not Found */ + reason:@"did not find IMAP4 folder (select failed)"]; + } + + info = [[SOGoMailboxInfo alloc] initWithURL:_url folderName:folderName + selectDictionary:result]; + return [info autorelease]; +} + - (NSException *)createMailbox:(NSString *)_mailbox atURL:(NSURL *)_url password:(NSString *)_pwd { @@ -733,8 +758,9 @@ static NSString *imap4Separator = nil; /* check connection cache */ if ((entry = [self entryForURL:_url password:_pwd]) == nil) { + // TODO: better to use an auth exception? return [NSException exceptionWithHTTPStatus:404 /* Not Found */ - reason:@"did not find IMAP4 folder"]; + reason:@"did not find IMAP4 folder (no entry)"]; } /* construct path */ @@ -768,8 +794,9 @@ static NSString *imap4Separator = nil; /* check connection cache */ if ((entry = [self entryForURL:_url password:_pwd]) == nil) { + // TODO: better to use an auth exception? return [NSException exceptionWithHTTPStatus:404 /* Not Found */ - reason:@"did not find IMAP4 folder"]; + reason:@"did not find IMAP4 folder (no entry)"]; } /* delete */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailboxInfo.h b/SOGo/SoObjects/Mailer/SOGoMailboxInfo.h new file mode 100644 index 00000000..8f4b0f2b --- /dev/null +++ b/SOGo/SoObjects/Mailer/SOGoMailboxInfo.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#ifndef __Mailer_SOGoMailboxInfo_H__ +#define __Mailer_SOGoMailboxInfo_H__ + +#import + +/* + SOGoMailboxInfo + + Represents the info returned by an IMAP4 select. Use SOGoMailManager to + retrieve the data. +*/ + +@class NSString, NSDate, NSArray, NSURL, NSDictionary; + +@interface SOGoMailboxInfo : NSObject +{ + NSDate *timestamp; + NSURL *url; + NSString *name; + NSArray *allowedFlags; + NSString *access; + unsigned int recent; +} + +- (id)initWithURL:(NSURL *)_url folderName:(NSString *)_name + selectDictionary:(NSDictionary *)_dict; + +/* accessors */ + +- (NSDate *)timestamp; +- (NSURL *)url; +- (NSString *)name; +- (NSArray *)allowedFlags; +- (NSString *)access; +- (unsigned int)recent; + +@end + +#endif /* __Mailer_SOGoMailboxInfo_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailboxInfo.m b/SOGo/SoObjects/Mailer/SOGoMailboxInfo.m new file mode 100644 index 00000000..54c626a6 --- /dev/null +++ b/SOGo/SoObjects/Mailer/SOGoMailboxInfo.m @@ -0,0 +1,101 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "SOGoMailboxInfo.h" +#include "common.h" + +@implementation SOGoMailboxInfo + +- (id)initWithURL:(NSURL *)_url folderName:(NSString *)_name + selectDictionary:(NSDictionary *)_dict +{ + if (_dict == nil || (_url == nil && _name == nil)) { + [self release]; + return nil; + } + + if ((self = [super init])) { + self->timestamp = [[NSDate alloc] init]; + self->url = [_url copy]; + self->name = [_name copy]; + self->allowedFlags = [[_dict objectForKey:@"flags"] copy]; + self->access = [[_dict objectForKey:@"access"] copy]; + self->recent = [[_dict objectForKey:@"recent"] unsignedIntValue]; + } + return self; +} +- (id)init { + return [self initWithURL:nil folderName: nil selectDictionary:nil]; +} + +- (void)dealloc { + [self->timestamp release]; + [self->url release]; + [self->name release]; + [self->allowedFlags release]; + [self->access release]; + [super dealloc]; +} + +/* accessors */ + +- (NSDate *)timestamp { + return self->timestamp; +} +- (NSURL *)url { + return self->url; +} +- (NSString *)name { + return self->name; +} +- (NSArray *)allowedFlags { + return self->allowedFlags; +} +- (NSString *)access { + return self->access; +} +- (unsigned int)recent { + return self->recent; +} + +/* description */ + +- (void)appendAttributesToDescription:(NSMutableString *)_ms { + if (self->name) [_ms appendFormat:@" name=%@", self->name]; + if (self->access) [_ms appendFormat:@" access=%@", self->access]; + + if (self->recent != 0) [_ms appendFormat:@" recent=%d", self->recent]; + + [_ms appendFormat:@" flags=%@", + [[self allowedFlags] componentsJoinedByString:@","]]; +} + +- (NSString *)description { + NSMutableString *ms; + + ms = [NSMutableString stringWithCapacity:64]; + [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; + [self appendAttributesToDescription:ms]; + [ms appendString:@">"]; + return ms; +} + +@end /* SOGoMailboxInfo */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 9bb14ee1..2d796d69 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=78 +SUBMINOR_VERSION:=79 # v0.9.69 requires libNGMime v4.5.210 # v0.9.55 requires libNGExtensions v4.5.136 diff --git a/SOGo/SoObjects/Mailer/common.h b/SOGo/SoObjects/Mailer/common.h index bf5ab285..c05b9762 100644 --- a/SOGo/SoObjects/Mailer/common.h +++ b/SOGo/SoObjects/Mailer/common.h @@ -31,4 +31,6 @@ #include #include +#include + #include -- 2.39.5