From 5e342d5e9942529c441cf52a2ecb01e5893aac99 Mon Sep 17 00:00:00 2001 From: C Robert Date: Mon, 5 Oct 2009 19:15:14 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: 8260a03656dcb7042c36f5ed015c0e1691560468 Monotone-Revision: 11c5eefb2d127036af170d47dc0f555860e8c38a Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-10-05T19:15:14 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 7 ++ SoObjects/Mailer/EOQualifier+MailDAV.h | 37 +++++++ SoObjects/Mailer/EOQualifier+MailDAV.m | 141 +++++++++++++++++++++++++ SoObjects/Mailer/GNUmakefile | 1 + Tests/test-webdavlib.py | 18 ++++ Tests/webdavlib.py | 2 +- 6 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 SoObjects/Mailer/EOQualifier+MailDAV.h create mode 100644 SoObjects/Mailer/EOQualifier+MailDAV.m diff --git a/ChangeLog b/ChangeLog index 32c7aa978..dcc4dbf70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-10-05 Cyril Robert + + * Tests/test-webdavlib.py: Added new tests for the URL parser / regexp. + * Tests/webdavlib.py: Fixed errors in the URL regexp. + * SoObjects/Mailer/EOQualifier+MailDAV.m: New category to generate IMAP + qualifiers from DAV filters. (REPORT) + 2009-10-04 Ludovic Marcotte * Adjusted the Welsh and Dutch templates for diff --git a/SoObjects/Mailer/EOQualifier+MailDAV.h b/SoObjects/Mailer/EOQualifier+MailDAV.h new file mode 100644 index 000000000..f779ca865 --- /dev/null +++ b/SoObjects/Mailer/EOQualifier+MailDAV.h @@ -0,0 +1,37 @@ +/* EOQualifier+MailDAV.h - this file is part of SOGo + * + * Copyright (C) 2009 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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. + */ + +#ifndef EOQUALIFIER_MAILDAV_H +#define EOQUALIFIER_MAILDAV_H + +#import +#define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav" + +@class DOMElement; + +@interface EOQualifier (SOGoMailDAVExtension) + ++ (id) qualifierFromMailDAVMailFilters: (DOMElement *) mailFilters; + +@end + +#endif /* EOQUALIFIER_MAILDAV_H */ diff --git a/SoObjects/Mailer/EOQualifier+MailDAV.m b/SoObjects/Mailer/EOQualifier+MailDAV.m new file mode 100644 index 000000000..8b404bbbf --- /dev/null +++ b/SoObjects/Mailer/EOQualifier+MailDAV.m @@ -0,0 +1,141 @@ +/* EOQualifier+MailDAV.m - this file is part of SOGo + * + * Copyright (C) 2009 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 +#import + +#import +#import +#import +#import + +#import + +#import "EOQualifier+MailDAV.h" + +@implementation EOQualifier (SOGoMailDAVExtension) + ++ (NSString *) buildQualifierFromFilters: (DOMElement *) mailFilters +{ + NSMutableArray *qualifiers; + NSString *qual, *buffer; + id list; + DOMElement *current; + NSCalendarDate *startDate, *endDate; + int count, max; + + qualifiers = [NSMutableArray array]; + qual = nil; + + list = [mailFilters childNodes]; + if (list) + { + max = [list length]; + for (count = 0; count < max; count++) + { + current = [list objectAtIndex: count]; + if ([current nodeType] == DOM_ELEMENT_NODE) + { + // 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: + [NSString stringWithFormat: @"(on = '%@')", startDate]]; + else if (startDate) + [qualifiers addObject: + [NSString stringWithFormat: @"(since > '%@')", startDate]]; + if (endDate) + [qualifiers addObject: + [NSString stringWithFormat: @"(before < '%@')", endDate]]; + } + // 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: + [NSString stringWithFormat: @"(senton = '%@')", startDate]]; + else if (startDate) + [qualifiers addObject: + [NSString stringWithFormat: @"(sentsince > '%@')", startDate]]; + if (endDate) + [qualifiers addObject: + [NSString stringWithFormat: @"(sentbefore < '%@')", endDate]]; + } + // Sequence + else if ([[current tagName] isEqualToString: @"sequence"]) + { + //TODO + } + // UID + else if ([[current tagName] isEqualToString: @"uid"]) + { + buffer = [current attribute: @"uid"]; + if (buffer) + [qualifiers addObject: + [NSString stringWithFormat: @"(uid = '%@')", buffer]]; + } + // From + else if ([[current tagName] isEqualToString: @"from"]) + { + buffer = [current attribute: @"from"]; + if (buffer) + [qualifiers addObject: + [NSString stringWithFormat: @"(from = '%@')", buffer]]; + } + // To + else if ([[current tagName] isEqualToString: @"to"]) + { + buffer = [current attribute: @"to"]; + if (buffer) + [qualifiers addObject: + [NSString stringWithFormat: @"(to = '%@')", buffer]]; + } + + } + } + } + + 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 diff --git a/SoObjects/Mailer/GNUmakefile b/SoObjects/Mailer/GNUmakefile index 784695c14..c737fbed5 100644 --- a/SoObjects/Mailer/GNUmakefile +++ b/SoObjects/Mailer/GNUmakefile @@ -32,6 +32,7 @@ Mailer_OBJC_FILES += \ SOGoMailForward.m \ SOGoMailReply.m \ \ + EOQualifier+MailDAV.m \ NSData+Mail.m \ NSString+Mail.m diff --git a/Tests/test-webdavlib.py b/Tests/test-webdavlib.py index b12b42bf2..20a4f6f10 100755 --- a/Tests/test-webdavlib.py +++ b/Tests/test-webdavlib.py @@ -28,5 +28,23 @@ class HTTPUnparsedURLTest(unittest.TestCase): self.assertEquals(testURL.port, None) self.assertEquals(testURL.path, "/folder/folder/simplereference") + pathURL = "http://user:secret@bla.com/hooray" + testURL = HTTPUnparsedURL(pathURL) + self.assertEquals(testURL.protocol, "http") + self.assertEquals(testURL.username, "user") + self.assertEquals(testURL.password, "secret") + self.assertEquals(testURL.hostname, "bla.com") + self.assertEquals(testURL.port, None) + self.assertEquals(testURL.path, "/hooray") + + pathURL = "http://user@bla.com:80/hooray" + testURL = HTTPUnparsedURL(pathURL) + self.assertEquals(testURL.protocol, "http") + self.assertEquals(testURL.username, "user") + self.assertEquals(testURL.password, None) + self.assertEquals(testURL.hostname, "bla.com") + self.assertEquals(testURL.port, "80") + self.assertEquals(testURL.path, "/hooray") + if __name__ == "__main__": unittest.main() diff --git a/Tests/webdavlib.py b/Tests/webdavlib.py index 10111b565..5f5c7c834 100644 --- a/Tests/webdavlib.py +++ b/Tests/webdavlib.py @@ -24,7 +24,7 @@ class HTTPUnparsedURL: url_parts = url.split("?") alpha_match = "[a-zA-Z0-9%\._-]+" num_match = "[0-9]+" - pattern = ("((%s)://(((%s)(:(%s)?)@)?(%s)(:(%s))))?(/.*)" + pattern = ("((%s)://(((%s)(:(%s))?@)?(%s)(:(%s))?))?(/.*)" % (alpha_match, alpha_match, alpha_match, alpha_match, num_match)) url_re = re.compile(pattern)