/*
- 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.
*/
- (NSString *)imap4SearchString;
@end
+@interface EOSortOrdering(IMAPAdditions)
+- (NSString *)imap4SortString;
+@end
+
+@interface NSArray(IMAPAdditions)
+- (NSString *)imap4SortStringForSortOrderings;
+@end
+
@interface NGImap4Client(ConnectionRegistration)
- (void)removeFromConnectionRegister;
static int ProfileImapEnabled = -1;
static int LogImapEnabled = -1;
static int PreventExceptions = -1;
-static NSArray *AllowedSortKeys = nil;
static BOOL fetchDebug = NO;
static BOOL ImapDebugEnabled = NO;
}
if (ImapClients == NULL)
ImapClients = calloc(MaxImapClients + 2, sizeof(id));
-
- AllowedSortKeys = [[NSArray alloc] initWithObjects:
- @"ARRIVAL", @"CC", @"DATE", @"FROM",
- @"SIZE", @"SUBJECT", @"TO", nil];
}
/* constructors */
return self->serverGID;
}
+- (NSString *)selectedFolderName {
+ return self->selectedFolder;
+}
+
/* connection */
- (id)_openSocket {
*/
NSString *s;
id tmp;
-
- tmp = self->selectedFolder;
-
+
+ tmp = self->selectedFolder; // remember ptr to old folder name
+
if ([_folder length] == 0)
return nil;
if ((_folder = [self _folder2ImapFolder:_folder]) == nil)
self->selectedFolder = [_folder copy];
- [tmp release]; tmp = nil;
+ [tmp release]; tmp = nil; // release old folder name
s = [NSString stringWithFormat:@"select \"%@\"", self->selectedFolder];
return [self->normer normalizeSelectResponse:[self processCommand:s]];
}
- (NSDictionary *)fetchUids:(NSArray *)_uids parts:(NSArray *)_parts {
+ /*
+ eg: 'UID FETCH 1189,1325,1326 ([TODO])'
+ */
NSAutoreleasePool *pool;
NSString *cmd;
NSDictionary *result;
+ NSString *uidsStr, *partsStr;
id fetchres;
pool = [[NSAutoreleasePool alloc] init];
- cmd = [NSString stringWithFormat:@"uid fetch %@ (%@)",
- [self _uidsJoinedForFetchCmd:_uids],
- [self _partsJoinedForFetchCmd:_parts]];
+
+ uidsStr = [self _uidsJoinedForFetchCmd:_uids];
+ partsStr = [self _partsJoinedForFetchCmd:_parts];
+ cmd = [NSString stringWithFormat:@"uid fetch %@ (%@)", uidsStr, partsStr];
fetchres = [self processCommand:cmd];
result = [[self->normer normalizeFetchResponse:fetchres] retain];
return [self->normer normalizeResponse:[self processCommand:cmd]];
}
+- (NSDictionary *)copyUids:(NSArray *)_uids toFolder:(NSString *)_folder {
+ NSString *cmd;
+
+ if ((_folder = [self _folder2ImapFolder:_folder]) == nil)
+ return nil;
+
+ cmd = [NSString stringWithFormat:@"uid copy %@ \"%@\"",
+ [_uids componentsJoinedByString:@","], _folder];
+
+ return [self->normer normalizeResponse:[self processCommand:cmd]];
+}
- (NSDictionary *)getQuotaRoot:(NSString *)_folder {
NSString *cmd;
while (cntOld < (len - 1)) {
if (old[cntOld] == '\n') {
- new[cntNew++] = '\r';
- new[cntNew++] = '\n';
+ new[cntNew] = '\r'; cntNew++;
+ new[cntNew] = '\n'; cntNew++;
}
else if (old[cntOld] != '\r') {
- new[cntNew++] = old[cntOld];
+ new[cntNew] = old[cntOld]; cntNew++;
}
cntOld++;
}
if (old[cntOld] == '\n') {
- new[cntNew++] = '\r';
- new[cntNew++] = '\n';
+ new[cntNew] = '\r'; cntNew++;
+ new[cntNew] = '\n'; cntNew++;
}
else if (old[cntOld] != '\r') {
- new[cntNew++] = old[cntOld];
- }
- message = [(NSString *)[NSString alloc]
- initWithCString:new length:cntNew];
- if (new) free(new); new = NULL;
+ new[cntNew] = old[cntOld]; cntNew++;
+ }
+
+ // TODO: fix this junk, do not treat the message as a string, its NSData
+ message = [(NSString *)[NSString alloc] initWithCString:new length:cntNew];
+ if (new != NULL) free(new); new = NULL;
}
icmd = [NSString stringWithFormat:@"append \"%@\" (%@) {%d}",
result = [self processCommand:icmd
withTag:YES withNotification:NO];
+ // TODO: explain that
if ([[result objectForKey:@"ContinuationResponse"] boolValue])
result = [self processCommand:message withTag:NO];
qualifier:_qualifier];
return nil;
}
- return result;
+ return [@" " stringByAppendingString:result];
}
- (NSDictionary *)threadBySubject:(BOOL)_bySubject
}
- (NSString *)_generateIMAP4SortOrdering:(EOSortOrdering *)_sortOrdering {
- SEL sel;
- NSString *key;
-
- key = [_sortOrdering key];
- if ([key length] == 0)
- return nil;
-
- if (![AllowedSortKeys containsObject:[key uppercaseString]]) {
- [self logWithFormat:@"ERROR[%s] key %@ is not allowed here!",
- __PRETTY_FUNCTION__, key];
- return nil;
- }
-
- sel = [_sortOrdering selector];
- if (sel_eq(sel, EOCompareDescending) ||
- sel_eq(sel, EOCompareCaseInsensitiveDescending)) {
- return [@"REVERSE " stringByAppendingString:key];
- }
- // TODO: check other selectors whether they make sense instead of silent acc.
-
- return key;
+ // TODO: still called by anything?
+ return [_sortOrdering imap4SortString];
}
-
- (NSString *)_generateIMAP4SortOrderings:(NSArray *)_sortOrderings {
- /*
- turn EOSortOrdering into an IMAP4 value for "SORT()"
-
- eg: "DATE REVERSE SUBJECT"
-
- It also checks a set of allowed sort-keys (don't know why)
- */
- NSMutableString *sortStr;
- NSEnumerator *soe;
- EOSortOrdering *so;
- BOOL isFirst = YES;
-
- if ([_sortOrderings count] == 0)
- return nil;
-
- sortStr = [NSMutableString stringWithCapacity:128];
- soe = [_sortOrderings objectEnumerator];
- while ((so = [soe nextObject])) {
- NSString *s;
-
- s = [self _generateIMAP4SortOrdering:so];
- if (s == nil)
- continue;
-
- if (isFirst)
- isFirst = NO;
- else
- [sortStr appendString:@" "];
-
- [sortStr appendString:s];
- }
- return isFirst ? nil : sortStr;
+ return [_sortOrderings imap4SortStringForSortOrderings];
}
- (NSDictionary *)primarySort:(NSString *)_sort
[self sendCommand:_command withTag:YES logText:_command];
}
-static inline NSArray *_flags2ImapFlags(NGImap4Client *self, NSArray *_flags) {
+- (NSArray *)_flags2ImapFlags:(NSArray *)_flags {
+ /* adds backslashes in front of the flags */
NSEnumerator *enumerator;
NSArray *result;
id obj;
id *objs;
unsigned cnt;
-
+
objs = calloc([_flags count] + 2, sizeof(id));
cnt = 0;
enumerator = [_flags objectEnumerator];
cnt++;
}
result = [NSArray arrayWithObjects:objs count:cnt];
- if (objs) free(objs);
+ if (objs != NULL) free(objs);
return result;
}
+static inline NSArray *_flags2ImapFlags(NGImap4Client *self, NSArray *_flags) {
+ return [self _flags2ImapFlags:_flags];
+}
- (NSString *)_folder2ImapFolder:(NSString *)_folder {
NSArray *array;