2007-05-30 22:05:21 +02:00
|
|
|
/* SOGoACLAdvisory.m - this file is part of SOGo
|
|
|
|
*
|
2009-04-01 15:49:24 +02:00
|
|
|
* Copyright (C) 2007-2009 Inverse inc.
|
2007-05-30 22:05:21 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-12-17 16:29:06 +01:00
|
|
|
#import <Foundation/NSURL.h>
|
|
|
|
|
2007-05-30 22:05:21 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NGHashMap.h>
|
|
|
|
#import <NGMail/NGMimeMessage.h>
|
|
|
|
#import <NGMime/NGMimeBodyPart.h>
|
|
|
|
#import <NGMime/NGMimeMultipartBody.h>
|
|
|
|
|
2007-08-09 22:58:01 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoMailer.h>
|
2007-05-30 22:05:21 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoObject.h>
|
2009-09-25 16:42:33 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUserManager.h>
|
2007-05-30 22:05:21 +02:00
|
|
|
#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
|
2007-10-17 17:46:59 +02:00
|
|
|
#import <SoObjects/SOGo/NSString+Utilities.h>
|
2007-05-30 22:05:21 +02:00
|
|
|
|
|
|
|
#import "SOGoACLAdvisory.h"
|
|
|
|
|
2010-01-22 17:33:35 +01:00
|
|
|
/* those methods appear here because SOGoMailFolder is not a descendant of
|
|
|
|
SOGoFolder... */
|
|
|
|
@interface SOGoObject (SOGoFolderACLMethods)
|
|
|
|
|
|
|
|
- (NSString *) displayName;
|
|
|
|
- (NSString *) folderType;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2007-05-30 22:05:21 +02:00
|
|
|
@implementation SOGoACLAdvisory
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
aclObject = nil;
|
|
|
|
recipientUID = nil;
|
|
|
|
|
|
|
|
isSubject = NO;
|
|
|
|
isBody = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[recipientUID release];
|
|
|
|
[aclObject release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setACLObject: (SOGoObject *) newACLObject
|
|
|
|
{
|
|
|
|
ASSIGN (aclObject, newACLObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRecipientUID: (NSString *) newRecipientUID
|
|
|
|
{
|
|
|
|
ASSIGN (recipientUID, newRecipientUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSubject
|
|
|
|
{
|
|
|
|
return isSubject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isBody
|
|
|
|
{
|
|
|
|
return isBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentUserName
|
|
|
|
{
|
|
|
|
return [[context activeUser] cn];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) httpAdvisoryURL
|
|
|
|
{
|
|
|
|
NSMutableString *url;
|
|
|
|
|
2007-06-05 16:56:36 +02:00
|
|
|
#warning the url returned by SOGoMail may be empty, we need to handle that
|
2007-05-30 22:05:21 +02:00
|
|
|
url
|
|
|
|
= [NSMutableString stringWithString:
|
|
|
|
[aclObject httpURLForAdvisoryToUser: recipientUID]];
|
|
|
|
if (![url hasSuffix: @"/"])
|
|
|
|
[url appendString: @"/"];
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2007-12-03 15:13:10 +01:00
|
|
|
- (NSString *) httpFolderURL
|
|
|
|
{
|
|
|
|
NSString *absoluteString;
|
|
|
|
NSMutableString *url;
|
|
|
|
|
|
|
|
#warning the url returned by SOGoMail may be empty, we need to handle that
|
|
|
|
absoluteString = [[aclObject soURL] absoluteString];
|
|
|
|
url = [NSMutableString stringWithString: absoluteString];
|
|
|
|
|
|
|
|
if (![url hasSuffix: @"/"])
|
|
|
|
[url appendString: @"/"];
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2007-05-30 22:05:21 +02:00
|
|
|
- (NSString *) resourceName
|
|
|
|
{
|
2008-03-31 22:30:05 +02:00
|
|
|
return [aclObject displayName];
|
2007-05-30 22:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) subject
|
|
|
|
{
|
|
|
|
NSString *subject;
|
|
|
|
|
|
|
|
isSubject = YES;
|
|
|
|
subject = [[self generateResponse] contentAsString];
|
|
|
|
isSubject = NO;
|
|
|
|
|
2007-10-17 17:46:59 +02:00
|
|
|
return [[subject stringByTrimmingSpaces] asQPSubjectString: @"utf-8"];
|
2007-05-30 22:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) body
|
|
|
|
{
|
|
|
|
NSString *body;
|
|
|
|
|
|
|
|
isBody = YES;
|
|
|
|
body = [[self generateResponse] contentAsString];
|
|
|
|
isBody = NO;
|
|
|
|
|
|
|
|
return [body stringByTrimmingSpaces];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) aclMethod
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
2007-10-14 18:07:22 +02:00
|
|
|
|
2007-05-30 22:05:21 +02:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NGMimeBodyPart *) _textPart
|
|
|
|
{
|
|
|
|
NGMutableHashMap *headerMap;
|
|
|
|
NGMimeBodyPart *part;
|
|
|
|
NSData *body;
|
|
|
|
|
|
|
|
headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
|
|
|
|
[headerMap setObject: @"text/plain; charset=utf-8" forKey: @"content-type"];
|
|
|
|
|
|
|
|
part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
|
|
|
|
body = [[self body] dataUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
[part setBody: [self body]];
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NGMimeBodyPart *) _sogoNotificationPart
|
|
|
|
{
|
|
|
|
NGMutableHashMap *headerMap;
|
|
|
|
NGMimeBodyPart *part;
|
|
|
|
NSData *body;
|
|
|
|
|
|
|
|
/* calendar part */
|
|
|
|
headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
|
|
|
|
[headerMap setObject: [NSString stringWithFormat:
|
|
|
|
@"%@; method=%@; type=%@; charset=%@",
|
|
|
|
@"application/x-sogo-notification",
|
|
|
|
[self aclMethod], [aclObject folderType],
|
|
|
|
@"utf-8"]
|
|
|
|
forKey: @"content-type"];
|
|
|
|
|
|
|
|
part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
|
|
|
|
body = [[aclObject resourceURLForAdvisoryToUser: recipientUID]
|
|
|
|
dataUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
[part setBody: body];
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) send
|
|
|
|
{
|
|
|
|
NSString *recipient, *date;
|
|
|
|
NGMutableHashMap *headerMap;
|
|
|
|
NGMimeMessage *message;
|
|
|
|
NGMimeMultipartBody *body;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoMailer *mailer;
|
2007-05-30 22:05:21 +02:00
|
|
|
SOGoUser *activeUser;
|
2007-08-15 22:13:41 +02:00
|
|
|
NSDictionary *identity;
|
|
|
|
NSString *from, *fullMail;
|
2007-05-30 22:05:21 +02:00
|
|
|
|
|
|
|
activeUser = [context activeUser];
|
2007-08-15 22:13:41 +02:00
|
|
|
identity = [activeUser primaryIdentity];
|
|
|
|
from = [identity objectForKey: @"email"];
|
|
|
|
fullMail = [NSString stringWithFormat: @"%@ <%@>",
|
|
|
|
[identity objectForKey: @"fullName"], from];
|
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
recipient = [[SOGoUserManager sharedUserManager]
|
2007-08-15 22:13:41 +02:00
|
|
|
getFullEmailForUID: recipientUID];
|
2007-05-30 22:05:21 +02:00
|
|
|
|
2009-11-07 23:33:25 +01:00
|
|
|
#warning SOPE is just plain stupid here - if you change the case of keys, it will break the encoding of fields
|
2007-05-30 22:05:21 +02:00
|
|
|
headerMap = [NGMutableHashMap hashMapWithCapacity: 5];
|
|
|
|
[headerMap setObject: @"multipart/alternative" forKey: @"content-type"];
|
2009-11-07 23:33:25 +01:00
|
|
|
[headerMap setObject: fullMail forKey: @"from"];
|
|
|
|
[headerMap setObject: recipient forKey: @"to"];
|
2007-05-30 22:05:21 +02:00
|
|
|
date = [[NSCalendarDate date] rfc822DateString];
|
2009-11-07 23:33:25 +01:00
|
|
|
[headerMap setObject: date forKey: @"date"];
|
|
|
|
[headerMap setObject: [self subject] forKey: @"subject"];
|
2007-05-30 22:05:21 +02:00
|
|
|
message = [NGMimeMessage messageWithHeader: headerMap];
|
|
|
|
|
|
|
|
body = [[NGMimeMultipartBody alloc] initWithPart: message];
|
|
|
|
[body addBodyPart: [self _textPart]];
|
|
|
|
[body addBodyPart: [self _sogoNotificationPart]];
|
|
|
|
[message setBody: body];
|
|
|
|
[body release];
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
mailer = [SOGoMailer mailerWithDomainDefaults: [activeUser domainDefaults]];
|
|
|
|
[mailer sendMimePart: message
|
|
|
|
toRecipients: [NSArray arrayWithObject: recipient]
|
|
|
|
sender: from];
|
2007-05-30 22:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2007-08-23 18:13:24 +02:00
|
|
|
|
2007-10-17 17:46:59 +02:00
|
|
|
@implementation SOGoACLAdditionAdvisory
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
- (NSString *) aclMethod { return @"add"; }
|
2007-10-17 17:46:59 +02:00
|
|
|
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
|
|
|
|
2007-10-17 17:46:59 +02:00
|
|
|
@implementation SOGoACLRemovalAdvisory
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
- (NSString *) aclMethod { return @"remove"; }
|
2007-10-17 17:46:59 +02:00
|
|
|
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
|
|
|
|
2007-12-03 15:13:10 +01:00
|
|
|
@implementation SOGoACLModificationAdvisory
|
|
|
|
|
|
|
|
- (NSString *) aclMethod { return @"modify"; }
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2009-07-09 21:49:04 +02:00
|
|
|
@implementation SOGoACLBrazilianPortugueseAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLBrazilianPortugueseModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLBrazilianPortugueseRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLCzechAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLCzechModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLCzechRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLDutchAdditionAdvisory
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLDutchModificationAdvisory
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLDutchRemovalAdvisory
|
2007-10-17 17:46:59 +02:00
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLEnglishAdditionAdvisory
|
2008-03-20 14:48:17 +01:00
|
|
|
@end
|
|
|
|
|
2007-12-03 15:13:10 +01:00
|
|
|
@implementation SOGoACLEnglishModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLEnglishRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLFrenchAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
2007-12-03 15:13:10 +01:00
|
|
|
@implementation SOGoACLFrenchModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLFrenchRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLGermanAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
2007-12-03 15:13:10 +01:00
|
|
|
@implementation SOGoACLGermanModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLGermanRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2009-07-30 04:12:53 +02:00
|
|
|
@implementation SOGoACLHungarianAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLHungarianModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLHungarianRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2011-05-11 21:12:47 +02:00
|
|
|
@implementation SOGoACLIcelandicModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLIcelandicAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLIcelandicRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2008-03-20 14:48:17 +01:00
|
|
|
@implementation SOGoACLItalianModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLItalianAdditionAdvisory
|
2007-10-17 17:46:59 +02:00
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoACLItalianRemovalAdvisory
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
|
|
|
|
2011-11-17 16:22:09 +01:00
|
|
|
@implementation SOGoACLNorwegianBokmalAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLNorwegianBokmalModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLNorwegianBokmalRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLNorwegianNynorskAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLNorwegianNynorskModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLNorwegianNynorskRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2010-08-03 17:13:58 +02:00
|
|
|
@implementation SOGoACLPolishAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLPolishModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLPolishRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2009-11-18 23:54:12 +01:00
|
|
|
@implementation SOGoACLRussianAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLRussianModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLRussianRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2011-11-17 16:22:09 +01:00
|
|
|
@implementation SOGoACLSpanishSpainAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLSpanishSpainModificationAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLSpanishSpainRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLSpanishArgentinaAdditionAdvisory
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
2008-03-20 14:48:17 +01:00
|
|
|
|
2011-11-17 16:22:09 +01:00
|
|
|
@implementation SOGoACLSpanishArgentinaModificationAdvisory
|
2008-03-20 14:48:17 +01:00
|
|
|
@end
|
|
|
|
|
2011-11-17 16:22:09 +01:00
|
|
|
@implementation SOGoACLSpanishArgentinaRemovalAdvisory
|
2008-05-20 21:16:19 +02:00
|
|
|
@end
|
2009-05-23 13:12:34 +02:00
|
|
|
|
2009-11-18 23:54:12 +01:00
|
|
|
@implementation SOGoACLSwedishAdditionAdvisory
|
2009-05-23 13:12:34 +02:00
|
|
|
@end
|
|
|
|
|
2009-11-18 23:54:12 +01:00
|
|
|
@implementation SOGoACLSwedishModificationAdvisory
|
2009-05-23 13:12:34 +02:00
|
|
|
@end
|
|
|
|
|
2009-11-18 23:54:12 +01:00
|
|
|
@implementation SOGoACLSwedishRemovalAdvisory
|
2009-05-23 13:12:34 +02:00
|
|
|
@end
|
2009-11-18 23:54:12 +01:00
|
|
|
|