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 <NGMime/NGMimeBodyPart.h>
27 #import <NGMime/NGMimeMultipartBody.h>
29 #import <SoObjects/SOGo/SOGoMailer.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>
34 #import <SoObjects/SOGo/NSString+Utilities.h>
36 #import "SOGoACLAdvisory.h"
38 @implementation SOGoACLAdvisory
42 if ((self = [super init]))
56 [recipientUID release];
61 - (void) setACLObject: (SOGoObject *) newACLObject
63 ASSIGN (aclObject, newACLObject);
66 - (void) setRecipientUID: (NSString *) newRecipientUID
68 ASSIGN (recipientUID, newRecipientUID);
81 - (NSString *) currentUserName
83 return [[context activeUser] cn];
86 - (NSString *) httpAdvisoryURL
90 #warning the url returned by SOGoMail may be empty, we need to handle that
92 = [NSMutableString stringWithString:
93 [aclObject httpURLForAdvisoryToUser: recipientUID]];
94 if (![url hasSuffix: @"/"])
95 [url appendString: @"/"];
100 - (NSString *) resourceName
102 return [aclObject nameInContainer];
105 - (NSString *) subject
110 subject = [[self generateResponse] contentAsString];
113 return [[subject stringByTrimmingSpaces] asQPSubjectString: @"utf-8"];
121 body = [[self generateResponse] contentAsString];
124 return [body stringByTrimmingSpaces];
127 - (NSString *) aclMethod
129 [self subclassResponsibility: _cmd];
134 - (NGMimeBodyPart *) _textPart
136 NGMutableHashMap *headerMap;
137 NGMimeBodyPart *part;
140 headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
141 [headerMap setObject: @"text/plain; charset=utf-8" forKey: @"content-type"];
143 part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
144 body = [[self body] dataUsingEncoding: NSUTF8StringEncoding];
145 [part setBody: [self body]];
150 - (NGMimeBodyPart *) _sogoNotificationPart
152 NGMutableHashMap *headerMap;
153 NGMimeBodyPart *part;
157 headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
158 [headerMap setObject: [NSString stringWithFormat:
159 @"%@; method=%@; type=%@; charset=%@",
160 @"application/x-sogo-notification",
161 [self aclMethod], [aclObject folderType],
163 forKey: @"content-type"];
165 part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
166 body = [[aclObject resourceURLForAdvisoryToUser: recipientUID]
167 dataUsingEncoding: NSUTF8StringEncoding];
168 [part setBody: body];
175 NSString *recipient, *date;
176 NGMutableHashMap *headerMap;
177 NGMimeMessage *message;
178 NGMimeMultipartBody *body;
179 SOGoUser *activeUser;
180 NSDictionary *identity;
181 NSString *from, *fullMail;
183 activeUser = [context activeUser];
184 identity = [activeUser primaryIdentity];
185 from = [identity objectForKey: @"email"];
186 fullMail = [NSString stringWithFormat: @"%@ <%@>",
187 [identity objectForKey: @"fullName"], from];
189 recipient = [[LDAPUserManager sharedUserManager]
190 getFullEmailForUID: recipientUID];
192 headerMap = [NGMutableHashMap hashMapWithCapacity: 5];
193 [headerMap setObject: @"multipart/alternative" forKey: @"content-type"];
194 [headerMap setObject: fullMail forKey: @"From"];
195 [headerMap setObject: recipient forKey: @"To"];
196 date = [[NSCalendarDate date] rfc822DateString];
197 [headerMap setObject: date forKey: @"Date"];
198 [headerMap setObject: [self subject] forKey: @"Subject"];
199 message = [NGMimeMessage messageWithHeader: headerMap];
201 body = [[NGMimeMultipartBody alloc] initWithPart: message];
202 [body addBodyPart: [self _textPart]];
203 [body addBodyPart: [self _sogoNotificationPart]];
204 [message setBody: body];
207 [[SOGoMailer sharedMailer] sendMimePart: message
208 toRecipients: [NSArray arrayWithObject: recipient]
214 @implementation SOGoACLAdditionAdvisory
216 - (NSString *) aclMethod { return @"add"; }
220 @implementation SOGoACLRemovalAdvisory
222 - (NSString *) aclMethod { return @"remove"; }
226 @implementation SOGoACLEnglishAdditionAdvisory
229 @implementation SOGoACLFrenchAdditionAdvisory
232 @implementation SOGoACLGermanAdditionAdvisory
235 @implementation SOGoACLEnglishRemovalAdvisory
238 @implementation SOGoACLFrenchRemovalAdvisory
241 @implementation SOGoACLGermanRemovalAdvisory