From 1c439c866efc5e639e7b3bc1259fb442942d0e19 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 13 Nov 2013 15:44:57 -0500 Subject: [PATCH] Added DAV support for mails labels. --- SoObjects/Contacts/SOGoContactFolders.m | 12 +- SoObjects/Mailer/SOGoMailAccount.h | 2 +- SoObjects/Mailer/SOGoMailAccount.m | 7 +- SoObjects/Mailer/SOGoMailAccounts.h | 9 +- SoObjects/Mailer/SOGoMailAccounts.m | 165 ++++++++++++++++++++- SoObjects/Mailer/SOGoMailNamespace.m | 4 +- SoObjects/Mailer/product.plist | 6 - SoObjects/SOGo/NSDictionary+DAV.m | 21 ++- SoObjects/SOGo/NSObject+DAV.h | 10 +- SoObjects/SOGo/NSObject+DAV.m | 4 +- SoObjects/SOGo/NSString+DAV.h | 4 +- SoObjects/SOGo/NSString+Utilities.m | 4 +- SoObjects/SOGo/SOGoDefaults.plist | 10 +- SoObjects/SOGo/SOGoObject.m | 4 +- SoObjects/SOGo/SOGoWebDAVValue.m | 4 +- UI/Templates/MailerUI/UIxMailMainFrame.wox | 4 +- 16 files changed, 215 insertions(+), 55 deletions(-) diff --git a/SoObjects/Contacts/SOGoContactFolders.m b/SoObjects/Contacts/SOGoContactFolders.m index c10f88c66..5bf9ba7bd 100644 --- a/SoObjects/Contacts/SOGoContactFolders.m +++ b/SoObjects/Contacts/SOGoContactFolders.m @@ -1,8 +1,6 @@ /* SOGoContactFolders.m - this file is part of SOGo * - * Copyright (C) 2006-2011 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2006-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,13 +18,6 @@ * Boston, MA 02111-1307, USA. */ -/* MailItems IPF.Note - ContactItems IPF.Contact - AppointmentItems IPF.Appointment - NoteItems IPF.StickyNote - TaskItems IPF.Task - JournalItems IPF.Journal */ - #import #import #import @@ -50,6 +41,7 @@ #import "SOGoContactFolders.h" #define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav" + @implementation SOGoContactFolders + (NSString *) gcsFolderType diff --git a/SoObjects/Mailer/SOGoMailAccount.h b/SoObjects/Mailer/SOGoMailAccount.h index bec7a5e9e..011a7620e 100644 --- a/SoObjects/Mailer/SOGoMailAccount.h +++ b/SoObjects/Mailer/SOGoMailAccount.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2009-2011 Inverse inc. + Copyright (C) 2009-2013 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG This file is part of SOGo. diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 37b9e08c5..c396b04d1 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -1,6 +1,6 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG - Copyright (C) 2007-2011 Inverse inc. + Copyright (C) 2007-2013 Inverse inc. This file is part of SOGo. @@ -26,6 +26,9 @@ #import #import +#import +#import + #import #import #import @@ -56,6 +59,8 @@ #import "SOGoMailAccount.h" +#define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav" + @implementation SOGoMailAccount static NSString *inboxFolderName = @"INBOX"; diff --git a/SoObjects/Mailer/SOGoMailAccounts.h b/SoObjects/Mailer/SOGoMailAccounts.h index 2fe066a31..a9b1bdb9d 100644 --- a/SoObjects/Mailer/SOGoMailAccounts.h +++ b/SoObjects/Mailer/SOGoMailAccounts.h @@ -1,20 +1,21 @@ /* + Copyright (C) 2009-2013 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG - This file is part of OpenGroupware.org. + This file is part of SOGo. - OGo is free software; you can redistribute it and/or modify it under + SOGo 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 + SOGo 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 SOGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ diff --git a/SoObjects/Mailer/SOGoMailAccounts.m b/SoObjects/Mailer/SOGoMailAccounts.m index fda419240..3d792d885 100644 --- a/SoObjects/Mailer/SOGoMailAccounts.m +++ b/SoObjects/Mailer/SOGoMailAccounts.m @@ -1,14 +1,15 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG + Copyright (C) 2007-2013 Inverse inc. - This file is part of OpenGroupware.org. + This file is part of SOGo. - OGo is free software; you can redistribute it and/or modify it under + SOGo 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 + SOGo 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. @@ -26,14 +27,20 @@ #import #import #import +#import +#import #import "../SOGo/NSArray+Utilities.h" +#import "../SOGo/NSObject+DAV.h" #import "../SOGo/NSString+Utilities.h" #import "../SOGo/SOGoUser.h" +#import "../SOGo/SOGoUserDefaults.h" #import "SOGoMailAccount.h" #import "SOGoMailAccounts.h" +#define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav" + @implementation SOGoMailAccounts - (NSArray *) mailAccounts @@ -92,4 +99,156 @@ return obj; } +/* + Mail labels/tags synchronization. + + Request: + + + + Result: + + + + + /SOGo/dav/sogo10/Mail/ + + HTTP/1.1 200 OK + + + Important + Work + Personal + To Do + Later + + + + + + +*/ +- (SOGoWebDAVValue *) davMailsLabels +{ + NSDictionary *labelsFromDefaults, *labelValues, *attributes; + NSMutableArray *davMailsLabels; + NSUInteger count, max; + SOGoUser *ownerUser; + NSArray *allKeys, *values; + NSString *key; + + ownerUser = [SOGoUser userWithLogin: owner]; + labelsFromDefaults = [[ownerUser userDefaults] mailLabelsColors]; + allKeys = [labelsFromDefaults allKeys]; + max = [allKeys count]; + + davMailsLabels = [NSMutableArray arrayWithCapacity: max]; + + for (count = 0; count < max; count++) + { + key = [allKeys objectAtIndex: count]; + values = [labelsFromDefaults objectForKey: key]; + + attributes = [NSDictionary dictionaryWithObjectsAndKeys: key, @"id", + [values objectAtIndex: 1], @"color", + nil]; + + labelValues = davElementWithAttributesAndContent(@"label", + attributes, + XMLNS_INVERSEDAV, + [values objectAtIndex: 0]); + + [davMailsLabels addObject: labelValues]; + } + + return [davElementWithContent (@"mails-labels", + XMLNS_INVERSEDAV, + davMailsLabels) + asWebDAVValue]; +} + +/* + + We get something like that: + + Request: + + + + + + + Important + Work + Personal + To Do + Later + + + + + + Response: + + + + /SOGo/dav/sogo10/Mail/ + + + + + HTTP/1.1 200 OK + + + + +*/ +- (NSException *) setDavMailsLabels: (NSString *) newLabels +{ + id documentElement, labelNode; + id labelNodes; + id document; + + NSString *label, *name, *color; + NSMutableDictionary *labels; + NSMutableArray *values; + SOGoUserDefaults *ud; + SOGoUser *ownerUser; + + NSUInteger count, max; + + labels = [NSMutableDictionary dictionary]; + + if ([newLabels length] > 0) + { + document = [[context request] contentAsDOMDocument]; + documentElement = [document documentElement]; + labelNodes = [documentElement getElementsByTagName: @"label"]; + max = [labelNodes length]; + + for (count = 0; count < max; count++) + { + values = [NSMutableArray array]; + + labelNode = [labelNodes objectAtIndex: count]; + + label = [labelNode attribute: @"id"]; + name = [labelNode textValue]; + color = [labelNode attribute: @"color"]; + + [values addObject: name]; + [values addObject: color]; + + [labels setObject: values forKey: label]; + } + } + + ownerUser = [SOGoUser userWithLogin: owner]; + ud = [ownerUser userDefaults]; + [ud setMailLabelsColors: labels]; + [ud synchronize]; + + return nil; +} + @end /* SOGoMailAccounts */ diff --git a/SoObjects/Mailer/SOGoMailNamespace.m b/SoObjects/Mailer/SOGoMailNamespace.m index bc4d1f88b..4bec0420a 100644 --- a/SoObjects/Mailer/SOGoMailNamespace.m +++ b/SoObjects/Mailer/SOGoMailNamespace.m @@ -1,8 +1,6 @@ /* SOGoMailNamespace.m - this file is part of SOGo * - * Copyright (C) 2010 Wolfgang Sourdeau - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2010-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/SoObjects/Mailer/product.plist b/SoObjects/Mailer/product.plist index 523da2688..42249f727 100644 --- a/SoObjects/Mailer/product.plist +++ b/SoObjects/Mailer/product.plist @@ -29,9 +29,6 @@ "WebDAV Access" = ( "Owner", "AuthorizedSubscriber" ); }; }; -/* SOGoSharedMailAccount = { - superclass = "SOGoMailAccount"; - }; */ SOGoMailFolder = { superclass = "SOGoMailBaseObject"; defaultRoles = { @@ -44,9 +41,6 @@ "Change Permissions" = ( "Owner", "MailAdministrator" ); }; }; -/* SOGoSharedInboxFolder = { - superclass = "SOGoMailFolder"; - }; */ SOGoTrashFolder = { superclass = "SOGoMailFolder"; }; diff --git a/SoObjects/SOGo/NSDictionary+DAV.m b/SoObjects/SOGo/NSDictionary+DAV.m index bd3d40161..722e20511 100644 --- a/SoObjects/SOGo/NSDictionary+DAV.m +++ b/SoObjects/SOGo/NSDictionary+DAV.m @@ -1,8 +1,6 @@ /* NSDictionary+DAV.m - this file is part of SOGo * - * Copyright (C) 2008-2009 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2008-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,6 +57,7 @@ - (NSString *) asWebDavStringWithNamespaces: (NSMutableDictionary *) namespaces { + NSDictionary *attributes; NSMutableString *webdavString; NSString *nsTag, *ns, *subString, *element; BOOL firstLevel; @@ -88,6 +87,22 @@ [webdavString appendString: [self _namespaceDecl: namespaces]]; [namespaces release]; } + + attributes = [self objectForKey: @"attributes"]; + + if (attributes) + { + NSArray *keys; + int i; + + keys = [attributes allKeys]; + + for (i = 0; i < [keys count]; i++) + { + [webdavString appendFormat: @" %@=\"%@\"", [keys objectAtIndex: i], [attributes objectForKey: [keys objectAtIndex: i]]]; + } + } + if (subString) [webdavString appendFormat: @">%@", subString, element]; else diff --git a/SoObjects/SOGo/NSObject+DAV.h b/SoObjects/SOGo/NSObject+DAV.h index e1d0e76a2..ef5399e57 100644 --- a/SoObjects/SOGo/NSObject+DAV.h +++ b/SoObjects/SOGo/NSObject+DAV.h @@ -1,8 +1,6 @@ /* NSObject+DAV.h - this file is part of SOGo * - * Copyright (C) 2008 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2008-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,6 +45,12 @@ typedef enum _HTTPStatusCode { n, @"ns", \ c, @"content", nil] +#define davElementWithAttributesAndContent(t,a,n,c) \ + [NSDictionary dictionaryWithObjectsAndKeys: t, @"method", \ + a, @"attributes", \ + n, @"ns", \ + c, @"content", nil] + SEL SOGoSelectorForPropertyGetter (NSString *property); SEL SOGoSelectorForPropertySetter (NSString *property); diff --git a/SoObjects/SOGo/NSObject+DAV.m b/SoObjects/SOGo/NSObject+DAV.m index 30f5ab016..b5e9a40f6 100644 --- a/SoObjects/SOGo/NSObject+DAV.m +++ b/SoObjects/SOGo/NSObject+DAV.m @@ -1,8 +1,6 @@ /* NSObject+DAV.m - this file is part of SOGo * - * Copyright (C) 2008-2010 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2008-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/SoObjects/SOGo/NSString+DAV.h b/SoObjects/SOGo/NSString+DAV.h index 29478150b..83a5ce26d 100644 --- a/SoObjects/SOGo/NSString+DAV.h +++ b/SoObjects/SOGo/NSString+DAV.h @@ -1,8 +1,6 @@ /* NSString+DAV.h - this file is part of SOGo * - * Copyright (C) 2008 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2008-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index 59241ba4b..cb9889eb8 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -314,12 +314,12 @@ static int cssEscapingCount; int count; strings = [NSArray arrayWithObjects: @"_U_", @"_D_", @"_H_", @"_A_", @"_S_", - @"_C_", @"_CO_", @"_SP_", @"_SQ_", @"_AM_", @"_P_", nil]; + @"_C_", @"_CO_", @"_SP_", @"_SQ_", @"_AM_", @"_P_", @"_DS_", nil]; [strings retain]; cssEscapingStrings = [strings asPointersOfObjects]; characters = [NSArray arrayWithObjects: @"_", @".", @"#", @"@", @"*", @":", - @",", @" ", @"'", @"&", @"+", nil]; + @",", @" ", @"'", @"&", @"+", @"$", nil]; cssEscapingCount = [strings count]; cssEscapingCharacters = NSZoneMalloc (NULL, (cssEscapingCount + 1) diff --git a/SoObjects/SOGo/SOGoDefaults.plist b/SoObjects/SOGo/SOGoDefaults.plist index 926b20997..e1277df04 100644 --- a/SoObjects/SOGo/SOGoDefaults.plist +++ b/SoObjects/SOGo/SOGoDefaults.plist @@ -78,10 +78,10 @@ SOGoSearchMinimumWordLength = 2; SOGoMailLabelsColors = { - label1 = ("Important", "#f00"); - label2 = ("Work", "#ff9a00"); - label3 = ("Personal", "#009a00"); - label4 = ("To Do", "#3130ff"); - label5 = ("Later", "#9c309c"); + $label1 = ("Important", "#f00"); + $label2 = ("Work", "#ff9a00"); + $label3 = ("Personal", "#009a00"); + $label4 = ("To Do", "#3130ff"); + $label5 = ("Later", "#9c309c"); }; } diff --git a/SoObjects/SOGo/SOGoObject.m b/SoObjects/SOGo/SOGoObject.m index 90df71afe..716e8f194 100644 --- a/SoObjects/SOGo/SOGoObject.m +++ b/SoObjects/SOGo/SOGoObject.m @@ -1,9 +1,7 @@ /* SOGoObject.m - this file is part of SOGo * * Copyright (C) 2004-2005 SKYRIX Software AG - * Copyright (C) 2006-2009 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2006-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/SoObjects/SOGo/SOGoWebDAVValue.m b/SoObjects/SOGo/SOGoWebDAVValue.m index 31c471f71..3734491e4 100644 --- a/SoObjects/SOGo/SOGoWebDAVValue.m +++ b/SoObjects/SOGo/SOGoWebDAVValue.m @@ -1,8 +1,6 @@ /* SOGoWebDAVValue.m - this file is part of $PROJECT_NAME_HERE$ * - * Copyright (C) 2008 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2008-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/UI/Templates/MailerUI/UIxMailMainFrame.wox b/UI/Templates/MailerUI/UIxMailMainFrame.wox index 809c19303..f79b9755f 100644 --- a/UI/Templates/MailerUI/UIxMailMainFrame.wox +++ b/UI/Templates/MailerUI/UIxMailMainFrame.wox @@ -17,7 +17,7 @@