]> err.no Git - scalable-opengroupware.org/commitdiff
further improved etag support
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Wed, 20 Jul 2005 15:30:41 +0000 (15:30 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Wed, 20 Jul 2005 15:30:41 +0000 (15:30 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@853 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGo/SoObjects/Mailer/ChangeLog
SOGo/SoObjects/Mailer/GNUmakefile.preamble
SOGo/SoObjects/Mailer/SOGoMailBodyPart.m
SOGo/SoObjects/Mailer/SOGoMailObject.h
SOGo/SoObjects/Mailer/SOGoMailObject.m
SOGo/SoObjects/SOGo/SOGoObject.m

index 7116760f531e02acaa809af42662905678ab4d9a..e2ef8d5a7adfd430888bf712f4a916b6de0a4e1e 100644 (file)
@@ -1,5 +1,15 @@
 2005-07-20  Helge Hess  <helge.hess@opengroupware.org>
 
+       * v0.9.115
+
+       * SOGoMailObject.m: do not use clientObject when fetching the
+         coreinfos, added a -doesMailExist method to cheaply check for
+         mail existance
+
+       * SOGoMailBodyPart.m, SOGoMailObject.m: added a constant etag for
+         content (possible for IMAP4 content), check etag prior delivering 
+         content (return a 304 in case the constant etag is supplied)
+
        * SOGoMailObject.m: added handling for some specific headers (v0.9.114)
 
 2005-07-19  Helge Hess  <helge.hess@opengroupware.org>
index c302ad8bea3cc22d88b4c7570cea4da76b30622b..848ebbb2c6d80f5831e842b87de3b2c8be2d32e7 100644 (file)
@@ -1 +1,7 @@
 # compilation settings
+
+ADDITIONAL_CPPFLAGS += \
+        -Wall -DCOMPILE_FOR_GSTEP_MAKE=1        \
+        -DUIX_MAILER_MAJOR_VERSION=$(MAJOR_VERSION)   \
+        -DUIX_MAILER_MINOR_VERSION=$(MINOR_VERSION)   \
+        -DUIX_MAILER_SUBMINOR_VERSION=$(SUBMINOR_VERSION)
index f13feabd55b9c2253310470ce35b688f1e774f19..28b6ea328968c4f7848ff0a7009a02e206bd06c5 100644 (file)
@@ -26,6 +26,7 @@
 
 @implementation SOGoMailBodyPart
 
+static NSString *mailETag = nil;
 static BOOL debugOn = NO;
 
 + (int)version {
@@ -36,6 +37,12 @@ static BOOL debugOn = NO;
   NSAssert2([super version] == 1,
             @"invalid superclass (%@) version %i !",
             NSStringFromClass([self superclass]), [super version]);
+  
+  mailETag = [[NSString alloc] initWithFormat:@"\"imap4url_%d_%d_%03d\"",
+                                UIX_MAILER_MAJOR_VERSION,
+                                UIX_MAILER_MINOR_VERSION,
+                                UIX_MAILER_SUBMINOR_VERSION];
+  NSLog(@"Note: using constant etag for mail parts: '%@'", mailETag);
 }
 
 - (void)dealloc {
@@ -236,9 +243,21 @@ static BOOL debugOn = NO;
 /* actions */
 
 - (id)GETAction:(id)_ctx {
+  NSException *error;
   WOResponse *r;
   NSData     *data;
+  NSString   *etag;
   
+  if ((error = [self matchesRequestConditionInContext:_ctx]) != nil) {
+    // TODO: currently we fetch the body structure to get here - check this!
+    /* check whether the mail still exists */
+    if (![[self mailObject] doesMailExist]) {
+      return [NSException exceptionWithHTTPStatus:404 /* Not Found */
+                         reason:@"mail was deleted"];
+    }
+    return error; /* return 304 or 416 */
+  }
+
   [self debugWithFormat:@"should fetch body part: %@", 
          [self bodyPartIdentifier]];
   
@@ -255,6 +274,10 @@ static BOOL debugOn = NO;
   [r setHeader:[self davContentType] forKey:@"content-type"];
   [r setHeader:[NSString stringWithFormat:@"%d", [data length]]
      forKey:@"content-length"];
+  
+  if ((etag = [self davEntityTag]) != nil)
+    [r setHeader:etag forKey:@"etag"];
+
   [r setContent:data];
   return r;
 }
@@ -291,6 +314,12 @@ static BOOL debugOn = NO;
   return self;
 }
 
+/* etag support */
+
+- (id)davEntityTag {
+  return mailETag;
+}
+
 /* debugging */
 
 - (BOOL)isDebuggingEnabled {
index d82a14cf1dea94420111a69fbc57bbf607f33620..1b5b7591f915debd989b1235f38a25de6f73ad2e 100644 (file)
@@ -53,6 +53,7 @@
 
 /* core infos */
 
+- (BOOL)doesMailExist;
 - (id)fetchCoreInfos; // TODO: what does it do?
 
 - (NGImap4Envelope *)envelope;
index cd50bbed6549a9751150819ee05987919b743449..80477ac7c9873f1dd9b072306fef0e92f59eec95 100644 (file)
@@ -166,13 +166,29 @@ static BOOL debugSoParts       = NO;
 
 /* core infos */
 
+- (BOOL)doesMailExist {
+  static NSArray *existsKey = nil;
+  id msgs;
+  
+  if (existsKey == nil) /* we use size, other suggestions? */
+    existsKey = [[NSArray alloc] initWithObjects:@"RFC822.SIZE", nil];
+  
+  msgs = [self fetchParts:existsKey]; // returns dict
+  msgs = [msgs valueForKey:@"fetch"];
+  return [msgs count] > 0 ? YES : NO;
+}
+
 - (id)fetchCoreInfos {
   id msgs;
   
   if (self->coreInfos != nil)
     return [self->coreInfos isNotNull] ? self->coreInfos : nil;
-
+  
+#if 0 // TODO: old code, why was it using clientObject??
   msgs = [[self clientObject] fetchParts:coreInfoKeys]; // returns dict
+#else
+  msgs = [self fetchParts:coreInfoKeys]; // returns dict
+#endif
   if (heavyDebug) [self logWithFormat:@"M: %@", msgs];
   msgs = [msgs valueForKey:@"fetch"];
   if ([msgs count] == 0)
@@ -670,8 +686,18 @@ static BOOL debugSoParts       = NO;
 /* actions */
 
 - (id)GETAction:(id)_ctx {
-  WOResponse *r;
-  NSData     *content;
+  NSException *error;
+  WOResponse  *r;
+  NSData      *content;
+  
+  if ((error = [self matchesRequestConditionInContext:_ctx]) != nil) {
+    /* check whether the mail still exists */
+    if (![self doesMailExist]) {
+      return [NSException exceptionWithHTTPStatus:404 /* Not Found */
+                         reason:@"mail was deleted"];
+    }
+    return error; /* return 304 or 416 */
+  }
   
   content = [self content];
   if ([content isKindOfClass:[NSException class]])
index f63fc6e183d1a3374a2e8573822a3f5d69e31572..ac1e4fe1023c59c8a454fc45ed7b4e2c7b4f2a58 100644 (file)
@@ -297,12 +297,10 @@ static BOOL kontactGroupDAV = YES;
     etag = [self davEntityTag];
     if ([etag length] == 0) /* has no etag, ignore */
       return nil;
-
-    [self logWithFormat:@"CHECK %@ vs %@", etag, etags];
     
     if ([etags containsObject:etag]) {
-      [self logWithFormat:@"etag '%@' matches: %@", etag, 
-           [etags componentsJoinedByString:@","]];
+      [self debugWithFormat:@"etag '%@' matches: %@", etag, 
+             [etags componentsJoinedByString:@","]];
       /* one etag matches, so stop the request */
       return [NSException exceptionWithHTTPStatus:304 /* Not Modified */
                          reason:@"object was not modified"];