From 2b9df195500b114afe093c83ee03c9dfba100948 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 6 Aug 2010 15:34:05 +0000 Subject: [PATCH] Monotone-Parent: 533cfe8838587987ff2e1ab8c7ed56d0e4b66bb4 Monotone-Revision: fe2bfcd815039f3fc87b6307a5eb4a89ca9d9022 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-08-06T15:34:05 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 24 ++ UI/PreferencesUI/UIxPreferences.m | 231 +++++++++-- UI/Templates/PreferencesUI/UIxPreferences.wox | 69 +++- UI/WebServerResources/UIxPreferences.css | 113 +++++- UI/WebServerResources/UIxPreferences.js | 360 ++++++++++++++++-- 5 files changed, 703 insertions(+), 94 deletions(-) diff --git a/ChangeLog b/ChangeLog index a46e22173..00f6aed10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,29 @@ 2010-08-06 Wolfgang Sourdeau + * UI/WebServerResources/UIxPreferences.js: (_setupEvents): no + longer take any parameter, which simplifies the method, as + removing the "change" observers on input field is not useful. + (initMailAccounts): new method that parses the mail accounts JSON + dictionary, populates the mail account UL and setup related + events. + (onMailAccountInfoChange, onMailIdentityInfoChange) + (onMailIdentitySignatureClick, onMailIdentitySignatureOK) + (createMailAccountLI, onMailAccountEntryClick, displayMailAccount) + (displayAccountSignature, createMailAccount) + (onMailAccountAdd, onMailAccountDelete, saveMailAccounts) + (compactMailAccounts): new methods completing the above. + + * UI/PreferencesUI/UIxPreferences.m (-identitiesList) + (-itemIdentityText, -signature, -setSignature): removed obsolete + methods. + (-defaultAction): when updating filters, we now only need to query + the "0" account since accounts are no longer identified by "name". + (-mailAuxiliaryUserAccountsEnabled): new bool method. + (-setMailAccounts): new accessor that decodes the new mail + accounts dictionary in JSON format and validates it prior to save + it in the user defaults. + (-mailAccounts): new accessor. + * UI/MailerUI/UIxMailFolderActions.m (_setFolderPurpose:): we now use the corresponding methods on the SOGoUserDefaults instance rather than in the user settings (old bug) when setting folders diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index e63ac7514..8205a3d52 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -67,6 +67,7 @@ if ((self = [super init])) { item = nil; +#warning user should be the owner rather than the activeUser ASSIGN (user, [context activeUser]); ASSIGN (userDefaults, [user userDefaults]); ASSIGN (today, [NSCalendarDate date]); @@ -575,35 +576,6 @@ [userDefaults setMailMessageForwarding: newMessageForwarding]; } -/* -// -- (NSArray *) identitiesList -{ - NSDictionary *primaryAccount; - -#warning we manage only one account per user at this time... - primaryAccount = [[user mailAccounts] objectAtIndex: 0]; - - return [primaryAccount objectForKey: @"identities"]; -} - -- (NSString *) itemIdentityText -{ - return [(NSDictionary *) item keysWithFormat: @"%{fullName} <%{email}>"]; - } */ - -- (NSString *) signature -{ - return [userDefaults mailSignature]; -} - -- (void) setSignature: (NSString *) newSignature -{ - [userDefaults setMailSignature: newSignature]; -} - - (NSArray *) replyPlacementList { return [NSArray arrayWithObjects: @"above", @"below", nil]; @@ -676,7 +648,7 @@ - (NSString *) sieveCapabilities { -#warning this should be deduced from the server +#warning sieve caps should be deduced from the server static NSArray *capabilities = nil; if (!capabilities) @@ -931,8 +903,7 @@ if ([[request method] isEqualToString: @"POST"]) { SOGoMailAccount *account; - id mailAccounts; - id folder; + SOGoMailAccounts *folder; dd = [[context activeUser] domainDefaults]; if ([dd sieveScriptsEnabled]) @@ -943,13 +914,10 @@ [userDefaults setForwardOptions: forwardOptions]; [userDefaults synchronize]; - - mailAccounts = [[[context activeUser] mailAccounts] objectAtIndex: 0]; + folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; - account = [folder lookupName: [[mailAccounts objectForKey: @"name"] asCSSIdentifier] - inContext: context - acquire: NO]; + account = [folder lookupName: @"0" inContext: context acquire: NO]; [account updateFilters]; if (hasChanged) @@ -1093,4 +1061,193 @@ return [self labelForKey: item]; } +- (BOOL) mailAuxiliaryUserAccountsEnabled +{ + return [[user domainDefaults] mailAuxiliaryUserAccountsEnabled]; +} + +- (void) _extractMainSignature: (NSDictionary *) account +{ + /* We perform some validation here as we have no guaranty on the input + validity. */ + NSString *signature; + NSArray *identities; + NSDictionary *identity; + + if ([account isKindOfClass: [NSDictionary class]]) + { + identities = [account objectForKey: @"identities"]; + if ([identities isKindOfClass: [NSArray class]]) + { + signature = nil; + + if ([identities count] > 0) + { + identity = [identities objectAtIndex: 0]; + if ([identity isKindOfClass: [NSDictionary class]]) + { + signature = [identity objectForKey: @"signature"]; + if (!signature) + signature = @""; + [userDefaults setMailSignature: signature]; + } + } + } + } +} + +- (BOOL) _validateAccountIdentities: (NSArray *) identities +{ + static NSString *identityKeys[] = { @"fullName", @"email", nil }; + static NSArray *knownKeys = nil; + NSString **key, *value; + NSDictionary *identity; + NSMutableDictionary *clone; + BOOL valid; + int count, max; + + if (!knownKeys) + { + knownKeys = [NSArray arrayWithObjects: @"fullName", @"email", + @"signature", nil]; + [knownKeys retain]; + } + + valid = [identities isKindOfClass: [NSArray class]]; + if (valid) + { + max = [identities count]; + valid = (max > 0); + for (count = 0; valid && count < max; count++) + { + identity = [identities objectAtIndex: count]; + clone = [identity mutableCopy]; + [clone removeObjectsForKeys: knownKeys]; + valid = ([clone count] == 0); + [clone autorelease]; + if (valid) + { + key = identityKeys; + while (valid && *key) + { + value = [identity objectForKey: *key]; + if ([value isKindOfClass: [NSString class]] + && [value length] > 0) + key++; + else + valid = NO; + } + if (valid) + { + value = [identity objectForKey: @"signature"]; + valid = (!value || [value isKindOfClass: [NSString class]]); + } + } + } + } + + return valid; +} + +- (BOOL) _validateAccount: (NSDictionary *) account +{ + static NSString *accountKeys[] = { @"name", @"serverName", @"userName", + @"password", nil }; + static NSArray *knownKeys = nil; + NSMutableDictionary *clone; + NSString **key, *value; + BOOL valid; + + if (!knownKeys) + { + knownKeys = [NSArray arrayWithObjects: @"name", @"serverName", + @"userName", @"password", @"encryption", + @"identities", @"mailboxes", nil]; + [knownKeys retain]; + } + + valid = [account isKindOfClass: [NSDictionary class]]; + if (valid) + { + clone = [account mutableCopy]; + [clone removeObjectsForKeys: knownKeys]; + valid = ([clone count] == 0); + [clone autorelease]; + + key = accountKeys; + while (valid && *key) + { + value = [account objectForKey: *key]; + if ([value isKindOfClass: [NSString class]] + && [value length] > 0) + key++; + else + valid = NO; + } + + if (valid) + { + value = [account objectForKey: @"security"]; + if (value) + valid = ([value isKindOfClass: [NSString class]] + && ([value isEqualToString: @"none"] + || [value isEqualToString: @"ssl"] + || [value isEqualToString: @"tls"])); + + valid &= [self _validateAccountIdentities: [account objectForKey: @"identities"]]; + } + } + + return valid; +} + +- (void) _extractAuxiliaryAccounts: (NSArray *) accounts +{ + int count, max; + NSMutableArray *auxAccounts; + NSDictionary *account; + + max = [accounts count]; + auxAccounts = [NSMutableArray arrayWithCapacity: max]; + + for (count = 1; count < max; count++) + { + account = [accounts objectAtIndex: count]; + if ([self _validateAccount: account]) + [auxAccounts addObject: account]; + } + + [userDefaults setAuxiliaryMailAccounts: auxAccounts]; +} + +- (void) setMailAccounts: (NSString *) newMailAccounts +{ + NSArray *accounts; + NSScanner *scanner; + int max; + + scanner = [NSScanner scannerWithString: newMailAccounts]; + [scanner scanJSONArray: &accounts]; + if (accounts && [accounts isKindOfClass: [NSArray class]]) + { + max = [accounts count]; + if (max > 0) + { + [self _extractMainSignature: [accounts objectAtIndex: 0]]; + + if (max > 1 && [self mailAuxiliaryUserAccountsEnabled]) + [self _extractAuxiliaryAccounts: accounts]; + } + } +} + +- (NSString *) mailAccounts +{ + NSArray *accounts; + + accounts = [user mailAccounts]; + + return [accounts jsonRepresentation]; +} + @end diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index d337a5900..22795b75e 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -27,8 +27,8 @@ >
  • -
  • +
  • - -
    + +
    +
    @@ -195,8 +196,9 @@
    -
    + var:value="sieveFiltersValue"/> +
    +
    @@ -212,10 +214,57 @@
    -