2007-05-30 22:05:21 +02:00
|
|
|
/* SOGoACLAdvisory.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* 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 <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>
|
|
|
|
#import <SoObjects/SOGo/LDAPUserManager.h>
|
|
|
|
#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"
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) resourceName
|
|
|
|
{
|
|
|
|
return [aclObject nameInContainer];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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;
|
|
|
|
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];
|
|
|
|
|
|
|
|
recipient = [[LDAPUserManager sharedUserManager]
|
|
|
|
getFullEmailForUID: recipientUID];
|
2007-05-30 22:05:21 +02:00
|
|
|
|
|
|
|
headerMap = [NGMutableHashMap hashMapWithCapacity: 5];
|
|
|
|
[headerMap setObject: @"multipart/alternative" forKey: @"content-type"];
|
2007-08-15 22:13:41 +02:00
|
|
|
[headerMap setObject: fullMail forKey: @"From"];
|
2007-05-30 22:05:21 +02:00
|
|
|
[headerMap setObject: recipient forKey: @"To"];
|
|
|
|
date = [[NSCalendarDate date] rfc822DateString];
|
|
|
|
[headerMap setObject: date forKey: @"Date"];
|
|
|
|
[headerMap setObject: [self subject] forKey: @"Subject"];
|
|
|
|
message = [NGMimeMessage messageWithHeader: headerMap];
|
|
|
|
|
|
|
|
body = [[NGMimeMultipartBody alloc] initWithPart: message];
|
|
|
|
[body addBodyPart: [self _textPart]];
|
|
|
|
[body addBodyPart: [self _sogoNotificationPart]];
|
|
|
|
[message setBody: body];
|
|
|
|
[body release];
|
|
|
|
|
2007-08-09 22:58:01 +02:00
|
|
|
[[SOGoMailer sharedMailer] sendMimePart: message
|
|
|
|
toRecipients: [NSArray arrayWithObject: recipient]
|
2007-08-15 22:13:41 +02:00
|
|
|
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-10-17 17:46:59 +02:00
|
|
|
@implementation SOGoACLEnglishAdditionAdvisory
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
|
|
|
|
2007-10-17 17:46:59 +02:00
|
|
|
@implementation SOGoACLFrenchAdditionAdvisory
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLGermanAdditionAdvisory
|
2007-10-17 17:46:59 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLEnglishRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLFrenchRemovalAdvisory
|
2007-08-23 18:13:24 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoACLGermanRemovalAdvisory
|
|
|
|
@end
|