1 /* SOGoACLAdvisory.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <NGObjWeb/WOResponse.h>
24 #import <NGExtensions/NGHashMap.h>
25 #import <NGMail/NGMimeMessage.h>
26 #import <NGMail/NGSendMail.h>
27 #import <NGMime/NGMimeBodyPart.h>
28 #import <NGMime/NGMimeMultipartBody.h>
30 #import <SoObjects/SOGo/SOGoUser.h>
31 #import <SoObjects/SOGo/SOGoObject.h>
32 #import <SoObjects/SOGo/LDAPUserManager.h>
33 #import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
35 #import "SOGoACLAdvisory.h"
37 @implementation SOGoACLAdvisory
41 if ((self = [super init]))
55 [recipientUID release];
60 - (void) setACLObject: (SOGoObject *) newACLObject
62 ASSIGN (aclObject, newACLObject);
65 - (void) setRecipientUID: (NSString *) newRecipientUID
67 ASSIGN (recipientUID, newRecipientUID);
80 - (NSString *) currentUserName
82 return [[context activeUser] cn];
85 - (NSString *) httpAdvisoryURL
89 #warning the url returned by SOGoMail may be empty, we need to handle that
91 = [NSMutableString stringWithString:
92 [aclObject httpURLForAdvisoryToUser: recipientUID]];
93 if (![url hasSuffix: @"/"])
94 [url appendString: @"/"];
99 - (NSString *) resourceName
101 return [aclObject nameInContainer];
104 - (NSString *) subject
109 subject = [[self generateResponse] contentAsString];
112 return [subject stringByTrimmingSpaces];
120 body = [[self generateResponse] contentAsString];
123 return [body stringByTrimmingSpaces];
126 - (NSString *) aclMethod
128 [self subclassResponsibility: _cmd];
133 - (NGMimeBodyPart *) _textPart
135 NGMutableHashMap *headerMap;
136 NGMimeBodyPart *part;
139 headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
140 [headerMap setObject: @"text/plain; charset=utf-8" forKey: @"content-type"];
142 part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
143 body = [[self body] dataUsingEncoding: NSUTF8StringEncoding];
144 [part setBody: [self body]];
149 - (NGMimeBodyPart *) _sogoNotificationPart
151 NGMutableHashMap *headerMap;
152 NGMimeBodyPart *part;
156 headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
157 [headerMap setObject: [NSString stringWithFormat:
158 @"%@; method=%@; type=%@; charset=%@",
159 @"application/x-sogo-notification",
160 [self aclMethod], [aclObject folderType],
162 forKey: @"content-type"];
164 part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
165 body = [[aclObject resourceURLForAdvisoryToUser: recipientUID]
166 dataUsingEncoding: NSUTF8StringEncoding];
167 [part setBody: body];
174 NSString *recipient, *date;
175 NGMutableHashMap *headerMap;
176 NGMimeMessage *message;
177 NGMimeMultipartBody *body;
178 SOGoUser *activeUser;
180 activeUser = [context activeUser];
181 recipient = [[LDAPUserManager sharedUserManager] getFullEmailForUID: recipientUID];
183 headerMap = [NGMutableHashMap hashMapWithCapacity: 5];
184 [headerMap setObject: @"multipart/alternative" forKey: @"content-type"];
185 [headerMap setObject: [activeUser fullEmail] forKey: @"From"];
186 [headerMap setObject: recipient forKey: @"To"];
187 date = [[NSCalendarDate date] rfc822DateString];
188 [headerMap setObject: date forKey: @"Date"];
189 [headerMap setObject: [self subject] forKey: @"Subject"];
190 message = [NGMimeMessage messageWithHeader: headerMap];
192 body = [[NGMimeMultipartBody alloc] initWithPart: message];
193 [body addBodyPart: [self _textPart]];
194 [body addBodyPart: [self _sogoNotificationPart]];
195 [message setBody: body];
198 [[NGSendMail sharedSendMail] sendMimePart: message
199 toRecipients: [NSArray arrayWithObject: recipient]
200 sender: [activeUser primaryEmail]];