]> err.no Git - scalable-opengroupware.org/blobdiff - SOGo/SoObjects/Mailer/SOGoMailAccount.m
do not show Drafts folder in shared mailboxes
[scalable-opengroupware.org] / SOGo / SoObjects / Mailer / SOGoMailAccount.m
index 05fdcb478e37a9ac9c8ba359cf53bb19a034a0b2..bcb0ea6b74958530a92f0b7777a28b380031cdc2 100644 (file)
 
 @implementation SOGoMailAccount
 
-static NSArray  *rootFolderNames  = nil;
-static NSString *inboxFolderName  = @"INBOX";
-static NSString *draftsFolderName = @"Drafts";
-static NSString *sieveFolderName  = @"Filters";
-static BOOL     useAltNamespace   = NO;
+static NSArray  *rootFolderNames      = nil;
+static NSString *inboxFolderName      = @"INBOX";
+static NSString *draftsFolderName     = @"Drafts";
+static NSString *sieveFolderName      = @"Filters";
+static NSString *sharedFolderName     = @""; // TODO: add English default
+static NSString *otherUsersFolderName = @""; // TODO: add English default
+static BOOL     useAltNamespace       = NO;
+
++ (int)version {
+  return [super version] + 0 /* v1 */;
+}
 
 + (void)initialize {
   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
+
+  NSAssert2([super version] == 1,
+            @"invalid superclass (%@) version %i !",
+            NSStringFromClass([self superclass]), [super version]);
   
   useAltNamespace = [ud boolForKey:@"SOGoSpecialFoldersInRoot"];
   
+  sharedFolderName     = [ud stringForKey:@"SOGoSharedFolderName"];
+  otherUsersFolderName = [ud stringForKey:@"SOGoOtherUsersFolderName"];
+  
+  NSLog(@"Note: using shared-folders name:      '%@'", sharedFolderName);
+  NSLog(@"Note: using other-users-folders name: '%@'", otherUsersFolderName);
+  
   if ([ud boolForKey:@"SOGoEnableSieveFolder"]) {
     rootFolderNames = [[NSArray alloc] initWithObjects:
                                        draftsFolderName, 
@@ -52,15 +68,36 @@ static BOOL     useAltNamespace   = NO;
   }
 }
 
+/* shared accounts */
+
+- (BOOL)isSharedAccount {
+  NSString *s;
+  NSRange  r;
+  
+  s = [self nameInContainer];
+  r = [s rangeOfString:@"@"];
+  if (r.length == 0) /* regular HTTP logins are never a shared mailbox */
+    return NO;
+  
+  s = [s substringToIndex:r.location];
+  return [s rangeOfString:@".-."].length > 0 ? YES : NO;
+}
+
+- (NSString *)sharedAccountName {
+  return nil;
+}
+
 /* listing the available folders */
 
+- (NSArray *)additionalRootFolderNames {
+  return rootFolderNames;
+}
+
 - (NSArray *)toManyRelationshipKeys {
   NSArray *a, *b;
-
-  a = rootFolderNames;
   
-  b = [[self mailManager] subfoldersForURL:[self imap4URL] 
-                         password:[self imap4Password]];
+  a = [self additionalRootFolderNames];
+  b = [[self imap4Connection] subfoldersForURL:[self imap4URL]];
   return [b count] > 0 ? [b arrayByAddingObjectsFromArray:a] : a;
 }
 
@@ -73,8 +110,7 @@ static BOOL     useAltNamespace   = NO;
 - (NSArray *)allFolderPathes {
   NSArray *pathes;
   
-  pathes = [[self mailManager] allFoldersForURL:[self imap4URL] 
-                              password:[self imap4Password]];
+  pathes = [[self imap4Connection] allFoldersForURL:[self imap4URL] ];
   pathes = [pathes sortedArrayUsingSelector:@selector(compare:)];
   return pathes;
 }
@@ -109,14 +145,11 @@ static BOOL     useAltNamespace   = NO;
   return [creds objectAtIndex:0]; /* the user */
 }
 
-- (NSURL *)imap4URL {
-  /* imap://agenortest@mail.opengroupware.org/INBOX/withsubdirs/subdir1 */
+- (NSString *)imap4URLString {
+  /* private, overridden by SOGoSharedMailAccount */
   NSString *s;
   NSRange  r;
   
-  if (self->imap4URL != nil)
-    return self->imap4URL;
-  
   s = [self nameInContainer];
   r = [s rangeOfString:@"@"];
   if (r.length == 0) {
@@ -136,6 +169,18 @@ static BOOL     useAltNamespace   = NO;
   
   s = [([self useSSL] ? @"imaps://" : @"imap://") stringByAppendingString:s];
   s = [s stringByAppendingString:@"/"];
+  return s;
+}
+
+- (NSURL *)imap4URL {
+  /* imap://agenortest@mail.opengroupware.org/ */
+  NSString *s;
+  
+  if (self->imap4URL != nil)
+    return self->imap4URL;
+
+  if ((s = [self imap4URLString]) == nil)
+    return nil;
   
   self->imap4URL = [[NSURL alloc] initWithString:s];
   return self->imap4URL;
@@ -225,7 +270,7 @@ static BOOL     useAltNamespace   = NO;
     ud = [NSUserDefaults standardUserDefaults];
     s = [[ud stringForKey:@"SOGoSentFolderName"] copy];
     if ([s length] == 0) s = @"Sent";
-    NSLog(@"Note: using SOGoSentFolderName: '%@'", s);
+    [self logWithFormat:@"Note: using SOGoSentFolderName: '%@'", s];
   }
   return s;
 }
@@ -309,8 +354,7 @@ static BOOL     useAltNamespace   = NO;
 }
 
 - (NSException *)davCreateCollection:(NSString *)_name inContext:(id)_ctx {
-  return [[self mailManager] createMailbox:_name atURL:[self imap4URL]
-                            password:[self imap4Password]];
+  return [[self imap4Connection] createMailbox:_name atURL:[self imap4URL]];
 }
 
 - (NSString *)shortTitle {