]> err.no Git - sope/blobdiff - sope-mime/NGImap4/NGImap4ResponseNormalizer.m
synced with latest additions and bumped framework versions
[sope] / sope-mime / NGImap4 / NGImap4ResponseNormalizer.m
index 6605ee6a16b782fc327b6f8ee72256d46e7eab81..ffff8b1b73f2d1aede1508ecefe305e100a5a408 100644 (file)
@@ -1,20 +1,20 @@
 /*
-  Copyright (C) 2000-2004 SKYRIX Software AG
+  Copyright (C) 2000-2005 SKYRIX Software AG
 
-  This file is part of OpenGroupware.org.
+  This file is part of SOPE.
 
-  OGo is free software; you can redistribute it and/or modify it under
+  SOPE 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
+  SOPE 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
+  License along with SOPE; see the file COPYING.  If not, write to the
   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.
 */
@@ -150,7 +150,7 @@ static int      LogImapEnabled = -1;
 
   result = [self normalizeResponse:_map];
   
-  if ((obj = [[_map objectEnumeratorForKey:@"sort"] nextObject]))
+  if ((obj = [[_map objectEnumeratorForKey:@"sort"] nextObject]) != nil)
     [result setObject:obj forKey:@"sort"];
   
   return result;
@@ -285,63 +285,7 @@ static int      LogImapEnabled = -1;
   dictionary for each response to the 'fetch' key of the normalized response
   dictionary (as retrieved by 'normalizeResponse')
 */
-- (NSDictionary *)normalizeFetchResponse:(NGHashMap *)_map {
-  /*
-    Raw Sample (Courier):
-      C[0x8b4e754]: 27 uid fetch 635 (body)
-      S[0x8c8b4e4]: * 627 FETCH (UID 635 BODY 
-        ("text" "plain" ("charset" "iso-8859-1" "format" "flowed") 
-        NIL NIL "8bit" 2474 51))
-      S[0x8c8b4e4]: * 627 FETCH (FLAGS (\Seen))
-      S[0x8c8b4e4]: 27 OK FETCH completed.
-    - this results in two result records (one for UID and one for FLAGS)
-      TODO: should we coalesce?
-
-    Raw Sample (Cyrus):
-      C[0x8c8ec64]: 14 uid fetch 20199 (body)
-      S[0x8da46a4]: * 93 FETCH (UID 20199 BODY 
-        ((("TEXT" "PLAIN" ("CHARSET" "utf-8") NIL "signed data" "7BIT" 691 17)
-          ("APPLICATION" "PKCS7-SIGNATURE" ("NAME" "smime.p7s") NIL 
-           "signature" "BASE64" 2936) "SIGNED")
-          ("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 146 4) 
-          "MIXED"))
-      S[0x8da46a4]: 14 OK Completed
-    - UID key is mapped to 'uid'
-    - BODY key is mapped to a nested body structure
-    - MSN is added for the '93'? (TODO: make sure this is the case)
-
-    Sample returns (not for the above code!):
-      {
-        // other message stuff
-        fetch = (
-          {
-            header = < NSData containing the header >;
-            size   = 3314;
-            uid    = 20187;
-            msn    = 72;
-            flags  = ( answered, deleted, seen );
-          },
-          ... for each fetch message ...
-        )
-      }
-  */
-  NSMutableDictionary *result;
-  id                  obj;
-  NSEnumerator        *enumerator;
-  NSMutableArray      *fetchResponseRecords;
-
-  // TODO: describe what the generic normalize does.
-  //       Q: do we need to run this before the following section or can we
-  //          call this method just before [result setObject:...] ? (I guess
-  //          the latter, because 'result' is not accessed, but who knows
-  //          about side effects in this JR cruft :-( )
-  result = [self normalizeResponse:_map];
-  
-  fetchResponseRecords = [[NSMutableArray alloc] initWithCapacity:512];
-  
-  /* walk over each response tag which is keyed by 'fetch' in the hashmap */
-  enumerator = [_map objectEnumeratorForKey:@"fetch"];
-  while ((obj = [enumerator nextObject])) {
+- (NSDictionary *)normalizeFetchResponsePart:(id)obj {
     // TODO: shouldn't we use a specific object instead of NSDict for that?
     NSDictionary *entry;
     NSEnumerator *keyEnum;
@@ -361,7 +305,7 @@ static int      LogImapEnabled = -1;
     
     // TODO: this should add some error handling wrt the count?
     // TODO: this could return multiple values for the same key?! => fix that
-    while ((key = [keyEnum nextObject]) && (count < 9)) {
+    while (((key = [keyEnum nextObject]) != nil) && (count < 9)) {
       unsigned klen;
       unichar  c;
       
@@ -440,7 +384,68 @@ static int      LogImapEnabled = -1;
       ? [[DictClass alloc] initWithObjects:values forKeys:keys count:count]
       : nil;
     
-    if (entry == nil)
+    return entry; /* returns retained object! */
+}
+- (NSDictionary *)normalizeFetchResponse:(NGHashMap *)_map {
+  /*
+    Raw Sample (Courier):
+      C[0x8b4e754]: 27 uid fetch 635 (body)
+      S[0x8c8b4e4]: * 627 FETCH (UID 635 BODY 
+        ("text" "plain" ("charset" "iso-8859-1" "format" "flowed") 
+        NIL NIL "8bit" 2474 51))
+      S[0x8c8b4e4]: * 627 FETCH (FLAGS (\Seen))
+      S[0x8c8b4e4]: 27 OK FETCH completed.
+    - this results in two result records (one for UID and one for FLAGS)
+      TODO: should we coalesce?
+
+    Raw Sample (Cyrus):
+      C[0x8c8ec64]: 14 uid fetch 20199 (body)
+      S[0x8da46a4]: * 93 FETCH (UID 20199 BODY 
+        ((("TEXT" "PLAIN" ("CHARSET" "utf-8") NIL "signed data" "7BIT" 691 17)
+          ("APPLICATION" "PKCS7-SIGNATURE" ("NAME" "smime.p7s") NIL 
+           "signature" "BASE64" 2936) "SIGNED")
+          ("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 146 4) 
+          "MIXED"))
+      S[0x8da46a4]: 14 OK Completed
+    - UID key is mapped to 'uid'
+    - BODY key is mapped to a nested body structure
+    - MSN is added for the '93'? (TODO: make sure this is the case)
+
+    Sample returns (not for the above code!):
+      {
+        // other message stuff
+        fetch = (
+          {
+            header = < NSData containing the header >;
+            size   = 3314;
+            uid    = 20187;
+            msn    = 72;
+            flags  = ( answered, deleted, seen );
+          },
+          ... for each fetch message ...
+        )
+      }
+  */
+  NSMutableDictionary *result;
+  id                  obj;
+  NSEnumerator        *enumerator;
+  NSMutableArray      *fetchResponseRecords;
+
+  // TODO: describe what the generic normalize does.
+  //       Q: do we need to run this before the following section or can we
+  //          call this method just before [result setObject:...] ? (I guess
+  //          the latter, because 'result' is not accessed, but who knows
+  //          about side effects in this JR cruft :-( )
+  result = [self normalizeResponse:_map];
+  
+  fetchResponseRecords = [[NSMutableArray alloc] initWithCapacity:512];
+  
+  /* walk over each response tag which is keyed by 'fetch' in the hashmap */
+  enumerator = [_map objectEnumeratorForKey:@"fetch"];
+  while ((obj = [enumerator nextObject]) != nil) {
+    NSDictionary *entry;
+    
+    if ((entry = [self normalizeFetchResponsePart:obj]) == nil)
       continue;
     
     [fetchResponseRecords addObject:entry];
@@ -637,4 +642,66 @@ _imapFlags2Flags(NGImap4ResponseNormalizer *self, NSArray *_flags)
   return result;
 }
 
+/* ACL */
+
+- (NSDictionary *)normalizeGetACLResponse:(NGHashMap *)_map {
+  /*
+    Raw Sample (Cyrus):
+      21 GETACL INBOX
+      * ACL INBOX test.et.di.cete-lyon lrswipcda helge lrwip
+      21 OK Completed
+  */
+  NSMutableDictionary *result;
+  id obj;
+  
+  result = [self normalizeResponse:_map];
+  if ((obj = [[_map objectEnumeratorForKey:@"acl"] nextObject]) != nil)
+    [result setObject:obj forKey:@"acl"];
+  if ((obj = [[_map objectEnumeratorForKey:@"mailbox"] nextObject]) != nil)
+    [result setObject:obj forKey:@"mailbox"];
+  return result;
+}
+
+- (NSDictionary *)normalizeListRightsResponse:(NGHashMap *)_map {
+  /*
+    Raw Sample (Cyrus):
+      16 listrights INBOX anyone
+      * LISTRIGHTS INBOX anyone "" l r s w i p c d a 0 1 2 3 4 5 6 7 8 9
+      16 OK Completed
+  */
+  NSMutableDictionary *result;
+  id obj;
+
+  result = [self normalizeResponse:_map];
+
+  if ((obj = [[_map objectEnumeratorForKey:@"listrights"] nextObject]))
+    [result setObject:obj forKey:@"listrights"];
+  if ((obj = [[_map objectEnumeratorForKey:@"requiredRights"] nextObject]))
+    [result setObject:obj forKey:@"requiredRights"];
+
+  if ((obj = [[_map objectEnumeratorForKey:@"mailbox"] nextObject]) != nil)
+    [result setObject:obj forKey:@"mailbox"];
+  if ((obj = [[_map objectEnumeratorForKey:@"uid"] nextObject]) != nil)
+    [result setObject:obj forKey:@"uid"];
+  return result;
+}
+
+- (NSDictionary *)normalizeMyRightsResponse:(NGHashMap *)_map {
+  /*
+    Raw Sample (Cyrus):
+      18 myrights INBOX
+      * MYRIGHTS INBOX lrswipcda
+      18 OK Completed
+  */
+  NSMutableDictionary *result;
+  id obj;
+
+  result = [self normalizeResponse:_map];
+  if ((obj = [[_map objectEnumeratorForKey:@"myrights"] nextObject]) != nil)
+    [result setObject:obj forKey:@"myrights"];
+  if ((obj = [[_map objectEnumeratorForKey:@"mailbox"] nextObject]) != nil)
+    [result setObject:obj forKey:@"mailbox"];
+  return result;
+}
+
 @end /* NGImap4ResponseNormalizer */