2009-10-05 21:15:14 +02:00
|
|
|
/* EOQualifier+MailDAV.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Inverse inc.
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <Foundation/NSSet.h>
|
|
|
|
|
|
|
|
#import <DOM/DOMElement.h>
|
|
|
|
#import <DOM/DOMProtocols.h>
|
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
|
|
|
#import <SOGo/DOMNode+SOGo.h>
|
|
|
|
|
|
|
|
#import <NGCards/NSString+NGCards.h>
|
2009-10-05 21:38:40 +02:00
|
|
|
#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
|
2009-10-05 21:15:14 +02:00
|
|
|
|
|
|
|
#import "EOQualifier+MailDAV.h"
|
|
|
|
|
|
|
|
@implementation EOQualifier (SOGoMailDAVExtension)
|
|
|
|
|
|
|
|
+ (NSString *) buildQualifierFromFilters: (DOMElement *) mailFilters
|
|
|
|
{
|
|
|
|
NSMutableArray *qualifiers;
|
|
|
|
NSString *qual, *buffer;
|
|
|
|
id <DOMNodeList> list;
|
|
|
|
DOMElement *current;
|
|
|
|
NSCalendarDate *startDate, *endDate;
|
2009-10-05 23:14:44 +02:00
|
|
|
int count, max, intValue;
|
|
|
|
NSString *negate;
|
2009-10-05 21:15:14 +02:00
|
|
|
|
|
|
|
qualifiers = [NSMutableArray array];
|
|
|
|
qual = nil;
|
|
|
|
|
2009-10-05 23:14:44 +02:00
|
|
|
#warning Qualifiers may be invalid, need to be tested
|
|
|
|
|
2009-10-05 21:15:14 +02:00
|
|
|
list = [mailFilters childNodes];
|
|
|
|
if (list)
|
|
|
|
{
|
|
|
|
max = [list length];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
current = [list objectAtIndex: count];
|
|
|
|
if ([current nodeType] == DOM_ELEMENT_NODE)
|
|
|
|
{
|
2009-10-05 23:14:44 +02:00
|
|
|
// Negate condition
|
|
|
|
if ([current attribute: @"not"])
|
|
|
|
negate = @"NOT ";
|
|
|
|
else
|
|
|
|
negate = @"";
|
|
|
|
|
2009-10-05 21:15:14 +02:00
|
|
|
// Received date
|
|
|
|
if ([[current tagName] isEqualToString: @"receive-date"])
|
|
|
|
{
|
|
|
|
startDate = [[current attribute: @"from"] asCalendarDate];
|
|
|
|
endDate = [[current attribute: @"to"] asCalendarDate];
|
|
|
|
if (startDate && [startDate isEqual: endDate])
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(on = '%@')",
|
|
|
|
negate, [startDate rfc822DateString]]];
|
2009-10-05 21:15:14 +02:00
|
|
|
else if (startDate)
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(since > '%@')",
|
|
|
|
negate, [startDate rfc822DateString]]];
|
2009-10-05 21:15:14 +02:00
|
|
|
if (endDate)
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(before < '%@')",
|
|
|
|
negate, [endDate rfc822DateString]]];
|
2009-10-05 21:15:14 +02:00
|
|
|
}
|
|
|
|
// Sent date
|
|
|
|
else if ([[current tagName] isEqualToString: @"date"])
|
|
|
|
{
|
|
|
|
startDate = [[current attribute: @"from"] asCalendarDate];
|
|
|
|
endDate = [[current attribute: @"to"] asCalendarDate];
|
|
|
|
if (startDate && [startDate isEqual: endDate])
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(senton = '%@')",
|
|
|
|
negate, [startDate rfc822DateString]]];
|
2009-10-05 21:15:14 +02:00
|
|
|
else if (startDate)
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(sentsince > '%@')",
|
|
|
|
negate, [startDate rfc822DateString]]];
|
2009-10-05 21:15:14 +02:00
|
|
|
if (endDate)
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(sentbefore < '%@')",
|
|
|
|
negate, [endDate rfc822DateString]]];
|
2009-10-05 21:15:14 +02:00
|
|
|
}
|
|
|
|
// Sequence
|
|
|
|
else if ([[current tagName] isEqualToString: @"sequence"])
|
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
// UID
|
|
|
|
else if ([[current tagName] isEqualToString: @"uid"])
|
|
|
|
{
|
|
|
|
buffer = [current attribute: @"uid"];
|
|
|
|
if (buffer)
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(uid = '%@')",
|
|
|
|
negate, buffer]];
|
2009-10-05 21:15:14 +02:00
|
|
|
}
|
|
|
|
// From
|
|
|
|
else if ([[current tagName] isEqualToString: @"from"])
|
|
|
|
{
|
|
|
|
buffer = [current attribute: @"from"];
|
|
|
|
if (buffer)
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(from doesContain: '%@')",
|
|
|
|
negate, buffer]];
|
2009-10-05 21:15:14 +02:00
|
|
|
}
|
|
|
|
// To
|
|
|
|
else if ([[current tagName] isEqualToString: @"to"])
|
|
|
|
{
|
|
|
|
buffer = [current attribute: @"to"];
|
|
|
|
if (buffer)
|
|
|
|
[qualifiers addObject:
|
2009-10-05 23:14:44 +02:00
|
|
|
[NSString stringWithFormat: @"%@(to doesContain: '%@')",
|
|
|
|
negate, buffer]];
|
|
|
|
}
|
|
|
|
// Size
|
|
|
|
else if ([[current tagName] isEqualToString: @"size"])
|
|
|
|
{
|
|
|
|
intValue = [[current attribute: @"min"] intValue];
|
|
|
|
[qualifiers addObject:
|
|
|
|
[NSString stringWithFormat: @"%@(larger > '%d')",
|
|
|
|
negate, intValue]];
|
|
|
|
intValue = [[current attribute: @"max"] intValue];
|
|
|
|
if (intValue)
|
|
|
|
[qualifiers addObject:
|
|
|
|
[NSString stringWithFormat: @"%@(smaller < '%d')",
|
|
|
|
negate, intValue]];
|
|
|
|
}
|
|
|
|
// Answered
|
|
|
|
else if ([[current tagName] isEqualToString: @"answered"])
|
|
|
|
{
|
|
|
|
intValue = [[current attribute: @"answered"] intValue];
|
|
|
|
if (intValue)
|
|
|
|
[qualifiers addObject: [NSString stringWithFormat:
|
|
|
|
@"%@(answered)", negate]];
|
|
|
|
intValue = [[current attribute: @"unanswered"] intValue];
|
|
|
|
if (intValue)
|
|
|
|
[qualifiers addObject: [NSString stringWithFormat:
|
|
|
|
@"%@(unanswered)", negate]];
|
|
|
|
}
|
|
|
|
// Draft
|
|
|
|
else if ([[current tagName] isEqualToString: @"draft"])
|
|
|
|
{
|
|
|
|
intValue = [[current attribute: @"draft"] intValue];
|
|
|
|
if (intValue)
|
|
|
|
[qualifiers addObject: [NSString stringWithFormat:
|
|
|
|
@"%@(draft)", negate]];
|
|
|
|
}
|
|
|
|
// Flagged
|
|
|
|
else if ([[current tagName] isEqualToString: @"flagged"])
|
|
|
|
{
|
|
|
|
intValue = [[current attribute: @"flagged"] intValue];
|
|
|
|
if (intValue)
|
|
|
|
[qualifiers addObject: [NSString stringWithFormat:
|
|
|
|
@"%@(flagged)", negate]];
|
|
|
|
}
|
|
|
|
// Recent
|
|
|
|
else if ([[current tagName] isEqualToString: @"recent"])
|
|
|
|
{
|
|
|
|
intValue = [[current attribute: @"recent"] intValue];
|
|
|
|
if (intValue)
|
|
|
|
[qualifiers addObject: [NSString stringWithFormat:
|
|
|
|
@"%@(recent)", negate]];
|
|
|
|
}
|
|
|
|
// Seen
|
|
|
|
else if ([[current tagName] isEqualToString: @"seen"])
|
|
|
|
{
|
|
|
|
intValue = [[current attribute: @"seen"] intValue];
|
|
|
|
if (intValue)
|
|
|
|
[qualifiers addObject: [NSString stringWithFormat:
|
|
|
|
@"%@(seen)", negate]];
|
|
|
|
}
|
|
|
|
// Deleted
|
|
|
|
else if ([[current tagName] isEqualToString: @"deleted"])
|
|
|
|
{
|
|
|
|
intValue = [[current attribute: @"deleted"] intValue];
|
|
|
|
if (intValue)
|
|
|
|
[qualifiers addObject: [NSString stringWithFormat:
|
|
|
|
@"%@(deleted)", negate]];
|
|
|
|
}
|
|
|
|
// Keywords
|
|
|
|
else if ([[current tagName] isEqualToString: @"keywords"])
|
|
|
|
{
|
|
|
|
buffer = [current attribute: @"keywords"];
|
|
|
|
if (buffer)
|
|
|
|
[qualifiers addObject:
|
|
|
|
[NSString stringWithFormat: @"%@(keywords doesContain: '%@')",
|
|
|
|
negate, buffer]];
|
2009-10-05 21:15:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([qualifiers count])
|
|
|
|
qual = [qualifiers componentsJoinedByString: @" AND "];
|
|
|
|
|
|
|
|
return qual;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ (id) qualifierFromMailDAVMailFilters: (DOMElement *) mailFilters
|
|
|
|
{
|
|
|
|
EOQualifier *newQualifier;
|
|
|
|
NSString *qual;
|
|
|
|
|
|
|
|
qual = [EOQualifier buildQualifierFromFilters: mailFilters];
|
|
|
|
|
|
|
|
newQualifier = [EOQualifier qualifierWithQualifierFormat: qual];
|
|
|
|
|
|
|
|
return newQualifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|