From: helge Date: Sat, 12 Feb 2005 17:35:11 +0000 (+0000) Subject: qualifier/sortordering cleanups X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adb9739d88f1ede19eb609e7efc0cc5ebea9a0ad;p=sope qualifier/sortordering cleanups added new IMAP4 copying method git-svn-id: http://svn.opengroupware.org/SOPE/trunk@550 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index 55707e4a..a7453572 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,7 @@ +2005-02-12 Helge Hess + + * NGImap4: improved copying, cleaned up sort ordering (v4.5.212) + 2005-02-08 Helge Hess * NGImap4: added method to retrieve selected folder (v4.5.211) diff --git a/sope-mime/NGImap4/ChangeLog b/sope-mime/NGImap4/ChangeLog index 5d41d188..bcbc6932 100644 --- a/sope-mime/NGImap4/ChangeLog +++ b/sope-mime/NGImap4/ChangeLog @@ -1,3 +1,14 @@ +2005-02-12 Helge Hess + + * EOQualifier+IMAPAdditions.m: allow contains: qualifier operator for + key searches + + * NGImap4Client.m: moved EOSortOrdering => IMAP4 code to an own + category/file + + * NGImap4Client.m: added -copyUids:toFolder: method to perform set copy + operations without sequence numbers (uses UID COPY IMAP4 command) + 2005-02-08 Helge Hess * NGImap4Client.m: added -selectedFolderName method to retrieve the diff --git a/sope-mime/NGImap4/EOQualifier+IMAPAdditions.m b/sope-mime/NGImap4/EOQualifier+IMAPAdditions.m index 3cfd0a8a..401d4c02 100644 --- a/sope-mime/NGImap4/EOQualifier+IMAPAdditions.m +++ b/sope-mime/NGImap4/EOQualifier+IMAPAdditions.m @@ -118,7 +118,7 @@ static BOOL debugOn = NO; if (disjunction) [search appendString:@" or"]; - while ((qualifier = [quals nextObject])) { + while ((qualifier = [quals nextObject]) != nil) { NSException *error; if (debugOn) @@ -274,8 +274,11 @@ static BOOL debugOn = NO; [search appendString:[lvalue stringValue]]; } else if ([OtherKeyWords containsObject:lkey]) { - if (!sel_eq(lselector, EOQualifierOperatorEqual)) { - [self logWithFormat:@"SELECTOR: got: %@, allowed: %@", + // TODO: actually most keywords only allow for contains! Eg "subject abc" + // is a contains query, not an equal query! + if (!sel_eq(lselector, EOQualifierOperatorEqual) && + !sel_eq(lselector, EOQualifierOperatorContains)) { + [self logWithFormat:@"IMAP4 generation: got: %@, allowed: %@", NSStringFromSelector(lselector), NSStringFromSelector(EOQualifierOperatorEqual)]; return [self invalidImap4SearchQualifier: diff --git a/sope-mime/NGImap4/EOSortOrdering+IMAPAdditions.m b/sope-mime/NGImap4/EOSortOrdering+IMAPAdditions.m new file mode 100644 index 00000000..59d1e501 --- /dev/null +++ b/sope-mime/NGImap4/EOSortOrdering+IMAPAdditions.m @@ -0,0 +1,115 @@ +/* + Copyright (C) 2000-2005 SKYRIX Software AG + + This file is part of SOPE. + + 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. + + 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 SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "imCommon.h" + +@interface NSObject(IMAPAdditions) +- (NSString *)imap4SortString; +@end + +@implementation NSString(IMAPAdditions) + +- (NSString *)imap4SortString { + /* support preformatted sort strings */ + return self; +} + +@end /* NSString(IMAPAdditions) */ + +@implementation EOSortOrdering(IMAPAdditions) + +static NSArray *AllowedSortKeys = nil; + +- (void)_setupAllowedIMAP4SortKeys { + if (AllowedSortKeys != nil) + return; + + AllowedSortKeys = [[NSArray alloc] initWithObjects: + @"ARRIVAL", @"CC", @"DATE", @"FROM", + @"SIZE", @"SUBJECT", @"TO", nil]; +} + +- (NSString *)imap4SortString { + SEL sel; + NSString *lkey; + + lkey = [self key]; + if ([lkey length] == 0) + return nil; + + /* check whether key is a valid sort string */ + + if (AllowedSortKeys == nil) [self _setupAllowedIMAP4SortKeys]; + if (![AllowedSortKeys containsObject:[lkey uppercaseString]]) { + NSLog(@"ERROR[%s] key %@ is not allowed here!", + __PRETTY_FUNCTION__, lkey); + return nil; + } + + /* check selector */ + + sel = [self selector]; + if (sel_eq(sel, EOCompareDescending) || + sel_eq(sel, EOCompareCaseInsensitiveDescending)) { + return [@"REVERSE " stringByAppendingString:lkey]; + } + // TODO: check other selectors whether they make sense instead of silent acc. + + return lkey; +} + +@end /* EOSortOrdering(IMAPAdditions) */ + +@implementation NSArray(IMAPAdditions) + +- (NSString *)imap4SortStringForSortOrderings { + /* + 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; + unsigned i, count; + + if ((count = [self count]) == 0) + return nil; + + sortStr = [NSMutableString stringWithCapacity:(count * 24)]; + + for (i = 0; i < count; i++) { + EOSortOrdering *so; + NSString *s; + + so = [self objectAtIndex:i]; + if (![so isNotNull]) + continue; + if ((s = [so imap4SortString]) == nil) + continue; + + if (i > 0) [sortStr appendString:@" "]; + [sortStr appendString:s]; + } + return [sortStr length] > 0 ? sortStr : nil; +} + +@end /* NSArray(IMAPAdditions) */ diff --git a/sope-mime/NGImap4/GNUmakefile b/sope-mime/NGImap4/GNUmakefile index 83f6759c..f2d59089 100644 --- a/sope-mime/NGImap4/GNUmakefile +++ b/sope-mime/NGImap4/GNUmakefile @@ -39,6 +39,7 @@ NGImap4_OBJC_FILES = \ NSString+Imap4.m \ NGSieveClient.m \ EOQualifier+IMAPAdditions.m \ + EOSortOrdering+IMAPAdditions.m \ \ NGImap4MessageGlobalID.m \ NGImap4FolderGlobalID.m \ diff --git a/sope-mime/NGImap4/NGImap4Client.h b/sope-mime/NGImap4/NGImap4Client.h index cf337637..aa679718 100644 --- a/sope-mime/NGImap4/NGImap4Client.h +++ b/sope-mime/NGImap4/NGImap4Client.h @@ -139,9 +139,12 @@ typedef enum { flags:(NSArray *)_flags; - (NSDictionary *)storeFrom:(unsigned)_from to:(unsigned)_to add:(NSNumber *)_add flags:(NSArray *)_flags; -- (NSDictionary *)copyUid:(unsigned)_uid toFolder:(NSString *)_folder; + +- (NSDictionary *)copyUid:(unsigned)_uid toFolder:(NSString *)_folder; +- (NSDictionary *)copyUids:(NSArray *)_uids toFolder:(NSString *)_folder; - (NSDictionary *)copyFrom:(unsigned)_from to:(unsigned)_to toFolder:(NSString *)_folder; + - (NSDictionary *)append:(NSData *)_message toFolder:(NSString *)_folder withFlags:(NSArray *)_flags; - (NSDictionary *)threadBySubject:(BOOL)_bySubject diff --git a/sope-mime/NGImap4/NGImap4Client.m b/sope-mime/NGImap4/NGImap4Client.m index fbc53a36..b5668913 100644 --- a/sope-mime/NGImap4/NGImap4Client.m +++ b/sope-mime/NGImap4/NGImap4Client.m @@ -37,6 +37,14 @@ - (NSString *)imap4SearchString; @end +@interface EOSortOrdering(IMAPAdditions) +- (NSString *)imap4SortString; +@end + +@interface NSArray(IMAPAdditions) +- (NSString *)imap4SortStringForSortOrderings; +@end + @interface NGImap4Client(ConnectionRegistration) - (void)removeFromConnectionRegister; @@ -98,7 +106,6 @@ static unsigned int MaxImapClients = 0; static int ProfileImapEnabled = -1; static int LogImapEnabled = -1; static int PreventExceptions = -1; -static NSArray *AllowedSortKeys = nil; static BOOL fetchDebug = NO; static BOOL ImapDebugEnabled = NO; @@ -129,10 +136,6 @@ 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 */ @@ -839,6 +842,17 @@ static BOOL ImapDebugEnabled = NO; 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; @@ -988,62 +1002,11 @@ static BOOL ImapDebugEnabled = NO; } - (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 diff --git a/sope-mime/Version b/sope-mime/Version index 91a8de37..892cc325 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,6 +2,6 @@ MAJOR_VERSION:=4 MINOR_VERSION:=5 -SUBMINOR_VERSION:=211 +SUBMINOR_VERSION:=212 # v4.2.149 requires libNGStreams v4.2.34