From 2a526120f789ea73ca698c9b97624908504bb180 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 30 May 2007 20:05:21 +0000 Subject: [PATCH] Monotone-Parent: 13b85b286011f096c4141829b528972047581e57 Monotone-Revision: 7757c54327c7b25ce729a04203f7d92573db98fc Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-05-30T20:05:21 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 ++ UI/SOGoUI/SOGoACLAdvisory.h | 50 +++++++++ UI/SOGoUI/SOGoACLAdvisory.m | 202 ++++++++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 UI/SOGoUI/SOGoACLAdvisory.h create mode 100644 UI/SOGoUI/SOGoACLAdvisory.m diff --git a/ChangeLog b/ChangeLog index 8d6d2b357..7ff8d004e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-05-30 Wolfgang Sourdeau + * UI/SOGoUI/SOGoACLAdvisory.[hm]: new class module implemented the + supercall of all the acl advistory templates. The model is based + on SOGoAptMailNotification except that the template encapsulates + the message to be sent. Later, we might create a superclass common + to all template-based emails. + * SoObjects/SOGo/NSArray+Utilities.m ([NSMutableArray -addRange:newRange]): new method that store a string representation of the NSRange passed as parameter. diff --git a/UI/SOGoUI/SOGoACLAdvisory.h b/UI/SOGoUI/SOGoACLAdvisory.h new file mode 100644 index 000000000..788a49a02 --- /dev/null +++ b/UI/SOGoUI/SOGoACLAdvisory.h @@ -0,0 +1,50 @@ +/* SOGoACLAdvisory.h - this file is part of SOGo + * + * Copyright (C) 2007 Inverse groupe conseil + * + * 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 SOGOACLADVISORY_H +#define SOGOACLADVISORY_H + +#import "UIxComponent.h" + +@interface SOGoACLAdvisory : UIxComponent +{ + SOGoObject *aclObject; + NSString *recipientUID; + + BOOL isSubject; + BOOL isBody; +} + +- (void) setACLObject: (SOGoObject *) newACLObject; +- (void) setRecipientUID: (NSString *) newRecipientUID; +- (void) send; + +- (BOOL) isSubject; +- (BOOL) isBody; + +- (NSString *) subject; +- (NSString *) body; +- (NSString *) aclMethod; + +@end + +#endif /* SOGOACLADVISORY_H */ diff --git a/UI/SOGoUI/SOGoACLAdvisory.m b/UI/SOGoUI/SOGoACLAdvisory.m new file mode 100644 index 000000000..78a146e5c --- /dev/null +++ b/UI/SOGoUI/SOGoACLAdvisory.m @@ -0,0 +1,202 @@ +/* SOGoACLAdvisory.m - this file is part of SOGo + * + * Copyright (C) 2007 Inverse groupe conseil + * + * 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 +#import +#import + +#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; + + 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; + + return [subject stringByTrimmingSpaces]; +} + +- (NSString *) body +{ + NSString *body; + + isBody = YES; + body = [[self generateResponse] contentAsString]; + isBody = NO; + + return [body stringByTrimmingSpaces]; +} + +- (NSString *) aclMethod +{ + [self subclassResponsibility: _cmd]; + + 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; + + activeUser = [context activeUser]; + recipient = [[LDAPUserManager sharedUserManager] getFullEmailForUID: recipientUID]; + + headerMap = [NGMutableHashMap hashMapWithCapacity: 5]; + [headerMap setObject: @"multipart/alternative" forKey: @"content-type"]; + [headerMap setObject: [activeUser fullEmail] forKey: @"From"]; + [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]; + + [[NGSendMail sharedSendMail] sendMimePart: message + toRecipients: [NSArray arrayWithObject: recipient] + sender: [activeUser primaryEmail]]; +} + +@end