]> err.no Git - scalable-opengroupware.org/blob - SoObjects/Mailer/SOGoSharedMailAccount.m
moved SOGo files up
[scalable-opengroupware.org] / SoObjects / Mailer / SOGoSharedMailAccount.m
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include "SOGoSharedMailAccount.h"
23 #include "common.h"
24
25 @interface SOGoMailAccount(UsedPrivates)
26
27 - (NSString *)imap4URLString;
28
29 - (id)lookupFolder:(NSString *)_key ofClassNamed:(NSString *)_cn
30   inContext:(id)_cx;
31
32 @end
33
34 @implementation SOGoSharedMailAccount
35
36 static NSString *otherUsersFolderName = @""; // TODO: add English default
37
38 + (int)version {
39   return [super version] + 0 /* v1 */;
40 }
41
42 + (void)initialize {
43   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
44
45   NSAssert2([super version] == 1,
46             @"invalid superclass (%@) version %i !",
47             NSStringFromClass([self superclass]), [super version]);
48   
49   otherUsersFolderName = [ud stringForKey:@"SOGoOtherUsersFolderName"];
50   NSLog(@"Note: using other-users-folders name: '%@'", otherUsersFolderName);
51 }
52
53 /* shared accounts */
54
55 - (BOOL)isSharedAccount {
56   return YES;
57 }
58
59 - (NSString *)sharedAccountName {
60   NSString *s;
61   NSRange  r;
62   
63   s = [self nameInContainer];
64   r = [s rangeOfString:@"@"];
65   if (r.length == 0) /* regular HTTP logins are never a shared mailbox */
66     return nil;
67   
68   s = [s substringToIndex:r.location];
69   r = [s rangeOfString:@".-."];
70   if (r.length == 0) /* no shared mailbox marker */
71     return nil;
72
73   return [s substringFromIndex:(r.location + r.length)];
74 }
75
76 /* listing the available folders */
77
78 - (NSArray *)additionalRootFolderNames {
79   /* do not show Drafts folder in shared mailboxes (#1452) */
80   /* Note: this also disables the Sieve folder */
81   return nil;
82 }
83
84 - (NSArray *)toManyRelationshipKeys {
85   NSMutableArray *m;
86   NSArray *b;
87   
88   m = [NSMutableArray arrayWithCapacity:16];
89   
90   [m addObject:@"INBOX"]; /* special for shared, see -lookupInboxFolder:.. */
91   
92   if ((b = [[self imap4Connection] subfoldersForURL:[self imap4URL]]) != nil)
93     [m addObjectsFromArray:b];
94   
95   if ((b = [self additionalRootFolderNames]) != nil)
96     [m addObjectsFromArray:b];
97   return m;
98 }
99
100 /* IMAP4 locator */
101
102 - (NSString *)imap4URLString {
103   /* we jump in the hierarchy directly to the shared user folder */
104   NSString *s;
105   
106   s = [super imap4URLString];
107   s = [s stringByAppendingString:otherUsersFolderName];
108   s = [s stringByAppendingString:@"/"];
109   s = [s stringByAppendingString:[self sharedAccountName]];
110   return s;
111 }
112
113 /* lookup */
114
115 - (id)lookupInboxFolder:(NSString *)_key inContext:(id)_ctx {
116   /*
117     Note: We have a choice: Cyrus does both, it gives the user an own
118           INBOX folder, but it also provides access to the mailbox INBOX
119           folder.
120           However the mailbox INBOX folder is NOT returned as an "INBOX"
121           subcollection as usual, but is the primary mailbox name.
122     Eg:
123       2 list "*" "*"
124       * LIST (\Noinferiors) "/" "INBOX"
125       * LIST (\HasChildren) "/" "Boite partag&AOk-e/alienor.a"
126     
127     The first INBOX is auto-assigned for the user by Cyrus, the second entry
128     is actually the INBOX of the mailbox itself (alienor.a).
129   */
130   return [self lookupFolder:_key ofClassNamed:@"SOGoSharedInboxFolder"
131                inContext:_ctx];
132 }
133
134 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
135   if ([_key isEqualToString:@"INBOX"])
136     return [self lookupInboxFolder:_key inContext:_ctx];
137   
138   return [super lookupName:_key inContext:_ctx acquire:_flag];
139 }
140
141 @end /* SOGoSharedMailAccount */