]> err.no Git - scalable-opengroupware.org/commitdiff
improved WebDAV support
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 25 Mar 2005 14:25:33 +0000 (14:25 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 25 Mar 2005 14:25:33 +0000 (14:25 +0000)
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
SOGo/SoObjects/Mailer/GNUmakefile
SOGo/SoObjects/Mailer/SOGoMailFolder.h
SOGo/SoObjects/Mailer/SOGoMailFolder.m
SOGo/SoObjects/Mailer/SOGoMailManager.h
SOGo/SoObjects/Mailer/SOGoMailManager.m
SOGo/SoObjects/Mailer/SOGoMailboxInfo.h [new file with mode: 0644]
SOGo/SoObjects/Mailer/SOGoMailboxInfo.m [new file with mode: 0644]
SOGo/SoObjects/Mailer/Version
SOGo/SoObjects/Mailer/common.h

index 90454a5887ea9ca83e4f8cfef2598927f0bd24c4..e4d5f4e35db4543d9d86797056b503f74fbe3d4f 100644 (file)
@@ -1,5 +1,12 @@
 2005-03-25  Helge Hess  <helge.hess@opengroupware.org>
 
+       * 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)
 
index 31da6471bb491ea1ffebcf38474af8aa05dd53bf..a6cf7580882e734fbd4fd917c4f133e4a46a4ccc 100644 (file)
@@ -10,6 +10,7 @@ Mailer_OBJC_FILES += \
        Product.m                       \
        \
        SOGoMailManager.m               \
+       SOGoMailboxInfo.m               \
        SOGoMailConnectionEntry.m       \
        \
        SOGoMailBaseObject.m            \
index cc7d34ab1a3acf24031da991e925a6742b8f34ab..441de7501141188a030b424c76eba7e936f8b0a8 100644 (file)
 */
 
 @class NSData, NSArray, NSException;
+@class SOGoMailboxInfo;
 
 @interface SOGoMailFolder : SOGoMailBaseObject
 {
   NSArray  *filenames;
   NSString *folderType;
+  SOGoMailboxInfo *selectInfo;
 }
 
 /* messages */
index 83b69dcbf1d07add3251cf807c2df217e45702c3..459cf049a4a377818ac5598b1e8a5ae2f6983d38 100644 (file)
 #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];
   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 {
                             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 {
   return self->folderType;
 }
 
-/* operations */
-
-- (NSException *)delete {
-  /* Note: overrides SOGoObject -delete */
-  return [[self mailManager] deleteMailboxAtURL:[self imap4URL]
-                            password:[self imap4Password]];
-}
-
 @end /* SOGoMailFolder */
index 726226c77eb13ed0a6ef581436ddde97a9d7cb07..c46371288ebeef758d38f4c8103ea99e3192332f 100644 (file)
@@ -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;
index 464877870ea89bf8aadaef1867754248cfe6dbc2..21b7e02e5910e14c82862aa8f115186ea07ad013 100644 (file)
@@ -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 (file)
index 0000000..8f4b0f2
--- /dev/null
@@ -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 <Foundation/NSObject.h>
+
+/*
+  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 (file)
index 0000000..54c626a
--- /dev/null
@@ -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 */
index 9bb14ee15c612efc08f73d76bbf8e72d7a066070..2d796d6994045aac9b3a9b3f0f270ecb80e73efb 100644 (file)
@@ -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
index bf5ab285e2de13665ba436e5af36bd3e1545e1bb..c05b976289d29aeeae9396cc83208ba1d0d5e1a3 100644 (file)
@@ -31,4 +31,6 @@
 #include <NGObjWeb/NGObjWeb.h>
 #include <NGObjWeb/SoObjects.h>
 
+#include <NGObjWeb/SoObject+SoDAV.h>
+
 #include <NGImap4/NGImap4Client.h>