Added DAV support for mails labels.

pull/15/merge
Ludovic Marcotte 2013-11-13 15:44:57 -05:00
parent 616ee7c6e4
commit 1c439c866e
16 changed files with 215 additions and 55 deletions

View File

@ -1,8 +1,6 @@
/* SOGoContactFolders.m - this file is part of SOGo /* SOGoContactFolders.m - this file is part of SOGo
* *
* Copyright (C) 2006-2011 Inverse inc. * Copyright (C) 2006-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -20,13 +18,6 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
/* MailItems IPF.Note
ContactItems IPF.Contact
AppointmentItems IPF.Appointment
NoteItems IPF.StickyNote
TaskItems IPF.Task
JournalItems IPF.Journal */
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h> #import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
@ -50,6 +41,7 @@
#import "SOGoContactFolders.h" #import "SOGoContactFolders.h"
#define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav" #define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav"
@implementation SOGoContactFolders @implementation SOGoContactFolders
+ (NSString *) gcsFolderType + (NSString *) gcsFolderType

View File

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2009-2011 Inverse inc. Copyright (C) 2009-2013 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo. This file is part of SOGo.

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2004-2005 SKYRIX Software AG 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. This file is part of SOGo.
@ -26,6 +26,9 @@
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
#import <Foundation/NSValue.h> #import <Foundation/NSValue.h>
#import <DOM/DOMElement.h>
#import <DOM/DOMProtocols.h>
#import <NGObjWeb/NSException+HTTP.h> #import <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/SoHTTPAuthenticator.h> #import <NGObjWeb/SoHTTPAuthenticator.h>
#import <NGObjWeb/WORequest.h> #import <NGObjWeb/WORequest.h>
@ -56,6 +59,8 @@
#import "SOGoMailAccount.h" #import "SOGoMailAccount.h"
#define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav"
@implementation SOGoMailAccount @implementation SOGoMailAccount
static NSString *inboxFolderName = @"INBOX"; static NSString *inboxFolderName = @"INBOX";

View File

@ -1,20 +1,21 @@
/* /*
Copyright (C) 2009-2013 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG 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 the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any Free Software Foundation; either version 2, or (at your option) any
later version. 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 WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details. License for more details.
You should have received a copy of the GNU Lesser General Public 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 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. 02111-1307, USA.
*/ */

View File

@ -1,14 +1,15 @@
/* /*
Copyright (C) 2004-2005 SKYRIX Software AG 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 the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any Free Software Foundation; either version 2, or (at your option) any
later version. 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 WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details. License for more details.
@ -26,14 +27,20 @@
#import <NGObjWeb/WOContext+SoObjects.h> #import <NGObjWeb/WOContext+SoObjects.h>
#import <NGExtensions/NSNull+misc.h> #import <NGExtensions/NSNull+misc.h>
#import <NGExtensions/NSObject+Logs.h> #import <NGExtensions/NSObject+Logs.h>
#import <DOM/DOMElement.h>
#import <DOM/DOMProtocols.h>
#import "../SOGo/NSArray+Utilities.h" #import "../SOGo/NSArray+Utilities.h"
#import "../SOGo/NSObject+DAV.h"
#import "../SOGo/NSString+Utilities.h" #import "../SOGo/NSString+Utilities.h"
#import "../SOGo/SOGoUser.h" #import "../SOGo/SOGoUser.h"
#import "../SOGo/SOGoUserDefaults.h"
#import "SOGoMailAccount.h" #import "SOGoMailAccount.h"
#import "SOGoMailAccounts.h" #import "SOGoMailAccounts.h"
#define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav"
@implementation SOGoMailAccounts @implementation SOGoMailAccounts
- (NSArray *) mailAccounts - (NSArray *) mailAccounts
@ -92,4 +99,156 @@
return obj; return obj;
} }
/*
Mail labels/tags synchronization.
Request:
<D:propfind xmlns:D="DAV:" xmlns:x0="urn:inverse:params:xml:ns:inverse-dav"><D:prop><x0:mails-labels/></D:prop></D:propfind>
Result:
<?xml version="1.0" encoding="UTF-8"?>
<D:multistatus>
<D:response>
<D:href>/SOGo/dav/sogo10/Mail/</D:href>
<D:propstat>
<D:status>HTTP/1.1 200 OK</D:status>
<D:prop>
<n1:mails-labels>
<n1:label color="#f00" id="$label1">Important</n1:label>
<n1:label color="#ff9a00" id="$label2">Work</n1:label>
<n1:label color="#009a00" id="$label3">Personal</n1:label>
<n1:label color="#3130ff" id="$label4">To Do</n1:label>
<n1:label color="#9c309c" id="$label5">Later</n1:label>
</n1:mails-labels>
</D:prop>
</D:propstat>
</D:response>
</D:multistatus>
*/
- (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:
<?xml version="1.0" encoding="UTF-8"?>
<propertyupdate xmlns="DAV:" xmlns:i="urn:inverse:params:xml:ns:inverse-dav">
<set>
<prop>
<i:mails-labels>
<i:label color="#f00" id="$label1">Important</i:label>
<i:label color="#ff9a00" id="$label2">Work</i:label>
<i:label color="#009a00" id="$label3">Personal</i:label>
<i:label color="#3130ff" id="$label4">To Do</i:label>
<i:label color="#9c309c" id="$label5">Later</i:label>
</i:mails-labels>
</prop>
</set>
</propertyupdate>
Response:
<D:multistatus>
<D:response>
<D:href>/SOGo/dav/sogo10/Mail/</D:href>
<D:propstat>
<D:prop>
<a:mails-labels/>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
*/
- (NSException *) setDavMailsLabels: (NSString *) newLabels
{
id <DOMElement> documentElement, labelNode;
id <DOMNodeList> labelNodes;
id <DOMDocument> 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 */ @end /* SOGoMailAccounts */

View File

@ -1,8 +1,6 @@
/* SOGoMailNamespace.m - this file is part of SOGo /* SOGoMailNamespace.m - this file is part of SOGo
* *
* Copyright (C) 2010 Wolfgang Sourdeau * Copyright (C) 2010-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@ -29,9 +29,6 @@
"WebDAV Access" = ( "Owner", "AuthorizedSubscriber" ); "WebDAV Access" = ( "Owner", "AuthorizedSubscriber" );
}; };
}; };
/* SOGoSharedMailAccount = {
superclass = "SOGoMailAccount";
}; */
SOGoMailFolder = { SOGoMailFolder = {
superclass = "SOGoMailBaseObject"; superclass = "SOGoMailBaseObject";
defaultRoles = { defaultRoles = {
@ -44,9 +41,6 @@
"Change Permissions" = ( "Owner", "MailAdministrator" ); "Change Permissions" = ( "Owner", "MailAdministrator" );
}; };
}; };
/* SOGoSharedInboxFolder = {
superclass = "SOGoMailFolder";
}; */
SOGoTrashFolder = { SOGoTrashFolder = {
superclass = "SOGoMailFolder"; superclass = "SOGoMailFolder";
}; };

View File

@ -1,8 +1,6 @@
/* NSDictionary+DAV.m - this file is part of SOGo /* NSDictionary+DAV.m - this file is part of SOGo
* *
* Copyright (C) 2008-2009 Inverse inc. * Copyright (C) 2008-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -59,6 +57,7 @@
- (NSString *) - (NSString *)
asWebDavStringWithNamespaces: (NSMutableDictionary *) namespaces asWebDavStringWithNamespaces: (NSMutableDictionary *) namespaces
{ {
NSDictionary *attributes;
NSMutableString *webdavString; NSMutableString *webdavString;
NSString *nsTag, *ns, *subString, *element; NSString *nsTag, *ns, *subString, *element;
BOOL firstLevel; BOOL firstLevel;
@ -88,6 +87,22 @@
[webdavString appendString: [self _namespaceDecl: namespaces]]; [webdavString appendString: [self _namespaceDecl: namespaces]];
[namespaces release]; [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) if (subString)
[webdavString appendFormat: @">%@</%@>", subString, element]; [webdavString appendFormat: @">%@</%@>", subString, element];
else else

View File

@ -1,8 +1,6 @@
/* NSObject+DAV.h - this file is part of SOGo /* NSObject+DAV.h - this file is part of SOGo
* *
* Copyright (C) 2008 Inverse inc. * Copyright (C) 2008-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -47,6 +45,12 @@ typedef enum _HTTPStatusCode {
n, @"ns", \ n, @"ns", \
c, @"content", nil] 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 SOGoSelectorForPropertyGetter (NSString *property);
SEL SOGoSelectorForPropertySetter (NSString *property); SEL SOGoSelectorForPropertySetter (NSString *property);

View File

@ -1,8 +1,6 @@
/* NSObject+DAV.m - this file is part of SOGo /* NSObject+DAV.m - this file is part of SOGo
* *
* Copyright (C) 2008-2010 Inverse inc. * Copyright (C) 2008-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@ -1,8 +1,6 @@
/* NSString+DAV.h - this file is part of SOGo /* NSString+DAV.h - this file is part of SOGo
* *
* Copyright (C) 2008 Inverse inc. * Copyright (C) 2008-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@ -314,12 +314,12 @@ static int cssEscapingCount;
int count; int count;
strings = [NSArray arrayWithObjects: @"_U_", @"_D_", @"_H_", @"_A_", @"_S_", 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]; [strings retain];
cssEscapingStrings = [strings asPointersOfObjects]; cssEscapingStrings = [strings asPointersOfObjects];
characters = [NSArray arrayWithObjects: @"_", @".", @"#", @"@", @"*", @":", characters = [NSArray arrayWithObjects: @"_", @".", @"#", @"@", @"*", @":",
@",", @" ", @"'", @"&", @"+", nil]; @",", @" ", @"'", @"&", @"+", @"$", nil];
cssEscapingCount = [strings count]; cssEscapingCount = [strings count];
cssEscapingCharacters = NSZoneMalloc (NULL, cssEscapingCharacters = NSZoneMalloc (NULL,
(cssEscapingCount + 1) (cssEscapingCount + 1)

View File

@ -78,10 +78,10 @@
SOGoSearchMinimumWordLength = 2; SOGoSearchMinimumWordLength = 2;
SOGoMailLabelsColors = { SOGoMailLabelsColors = {
label1 = ("Important", "#f00"); $label1 = ("Important", "#f00");
label2 = ("Work", "#ff9a00"); $label2 = ("Work", "#ff9a00");
label3 = ("Personal", "#009a00"); $label3 = ("Personal", "#009a00");
label4 = ("To Do", "#3130ff"); $label4 = ("To Do", "#3130ff");
label5 = ("Later", "#9c309c"); $label5 = ("Later", "#9c309c");
}; };
} }

View File

@ -1,9 +1,7 @@
/* SOGoObject.m - this file is part of SOGo /* SOGoObject.m - this file is part of SOGo
* *
* Copyright (C) 2004-2005 SKYRIX Software AG * Copyright (C) 2004-2005 SKYRIX Software AG
* Copyright (C) 2006-2009 Inverse inc. * Copyright (C) 2006-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@ -1,8 +1,6 @@
/* SOGoWebDAVValue.m - this file is part of $PROJECT_NAME_HERE$ /* SOGoWebDAVValue.m - this file is part of $PROJECT_NAME_HERE$
* *
* Copyright (C) 2008 Inverse inc. * Copyright (C) 2008-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

View File

@ -17,7 +17,7 @@
</script> </script>
<style type="text/css"> <style type="text/css">
<var:foreach list="availableLabels" item="currentLabel"> <var:foreach list="availableLabels" item="currentLabel">
#label-menu LI.<var:string value="currentLabel.name"/>, #label-menu LI.<var:string value="currentLabel.name.asCSSIdentifier"/>,
TABLE.messageList TR[labels~=<var:string const:value='"' const:escapeHTML="NO" TABLE.messageList TR[labels~=<var:string const:value='"' const:escapeHTML="NO"
/><var:string value="currentLabel.name"/><var:string const:value='"' const:escapeHTML="NO"/>] TD /><var:string value="currentLabel.name"/><var:string const:value='"' const:escapeHTML="NO"/>] TD
{ color: <var:string value="currentLabel.color"/>; } { color: <var:string value="currentLabel.color"/>; }
@ -181,7 +181,7 @@
<li><var:string label:value="None" /></li> <li><var:string label:value="None" /></li>
<li><!-- separator --></li> <li><!-- separator --></li>
<var:foreach list="availableLabels" item="currentLabel"> <var:foreach list="availableLabels" item="currentLabel">
<li var:class="currentLabel.name" var:data-name="currentLabel.name"> <var:string value="currentLabel.label"/></li> <li var:class="currentLabel.name.asCSSIdentifier" var:data-name="currentLabel.name"> <var:string value="currentLabel.label"/></li>
</var:foreach> </var:foreach>
</ul> </ul>
</div> </div>