]> err.no Git - scalable-opengroupware.org/blob - UI/SOGoUI/SOGoACLAdvisory.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1259 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / SOGoUI / SOGoACLAdvisory.m
1 /* SOGoACLAdvisory.m - this file is part of SOGo
2  *
3  * Copyright (C) 2007 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22
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>
28
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>
35
36 #import "SOGoACLAdvisory.h"
37
38 @implementation SOGoACLAdvisory
39
40 - (id) init
41 {
42   if ((self = [super init]))
43     {
44       aclObject = nil;
45       recipientUID = nil;
46
47       isSubject = NO;
48       isBody = NO;
49     }
50
51   return self;
52 }
53
54 - (void) dealloc
55 {
56   [recipientUID release];
57   [aclObject release];
58   [super dealloc];
59 }
60
61 - (void) setACLObject: (SOGoObject *) newACLObject
62 {
63   ASSIGN (aclObject, newACLObject);
64 }
65
66 - (void) setRecipientUID: (NSString *) newRecipientUID
67 {
68   ASSIGN (recipientUID, newRecipientUID);
69 }
70
71 - (BOOL) isSubject
72 {
73   return isSubject;
74 }
75
76 - (BOOL) isBody
77 {
78   return isBody;
79 }
80
81 - (NSString *) currentUserName
82 {
83   return [[context activeUser] cn];
84 }
85
86 - (NSString *) httpAdvisoryURL
87 {
88   NSMutableString *url;
89
90 #warning the url returned by SOGoMail may be empty, we need to handle that
91   url
92     = [NSMutableString stringWithString:
93                          [aclObject httpURLForAdvisoryToUser: recipientUID]];
94   if (![url hasSuffix: @"/"])
95     [url appendString: @"/"];
96
97   return url;
98 }
99
100 - (NSString *) resourceName
101 {
102   return [aclObject nameInContainer];
103 }
104
105 - (NSString *) subject
106 {
107   NSString *subject;
108
109   isSubject = YES;
110   subject = [[self generateResponse] contentAsString];
111   isSubject = NO;
112
113   return [[subject stringByTrimmingSpaces] asQPSubjectString: @"utf-8"];
114 }
115
116 - (NSString *) body
117 {
118   NSString *body;
119
120   isBody = YES;
121   body = [[self generateResponse] contentAsString];
122   isBody = NO;
123
124   return [body stringByTrimmingSpaces];
125 }
126
127 - (NSString *) aclMethod
128 {
129   [self subclassResponsibility: _cmd];
130   
131   return nil;
132 }
133
134 - (NGMimeBodyPart *) _textPart
135 {
136   NGMutableHashMap *headerMap;
137   NGMimeBodyPart *part;
138   NSData *body;
139
140   headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
141   [headerMap setObject: @"text/plain; charset=utf-8" forKey: @"content-type"];
142
143   part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
144   body = [[self body] dataUsingEncoding: NSUTF8StringEncoding];
145   [part setBody: [self body]];
146
147   return part;
148 }
149
150 - (NGMimeBodyPart *) _sogoNotificationPart
151 {
152   NGMutableHashMap *headerMap;
153   NGMimeBodyPart *part;
154   NSData *body;
155
156   /* calendar 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],
162                                   @"utf-8"]
163              forKey: @"content-type"];
164
165   part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
166   body = [[aclObject resourceURLForAdvisoryToUser: recipientUID]
167            dataUsingEncoding: NSUTF8StringEncoding];
168   [part setBody: body];
169
170   return part;
171 }
172
173 - (void) send
174 {
175   NSString *recipient, *date;
176   NGMutableHashMap *headerMap;
177   NGMimeMessage *message;
178   NGMimeMultipartBody *body;
179   SOGoUser *activeUser;
180   NSDictionary *identity;
181   NSString *from, *fullMail;
182
183   activeUser = [context activeUser];
184   identity = [activeUser primaryIdentity];
185   from = [identity objectForKey: @"email"];
186   fullMail = [NSString stringWithFormat: @"%@ <%@>",
187                        [identity objectForKey: @"fullName"], from];
188
189   recipient = [[LDAPUserManager sharedUserManager]
190                 getFullEmailForUID: recipientUID];
191
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];
200
201   body = [[NGMimeMultipartBody alloc] initWithPart: message];
202   [body addBodyPart: [self _textPart]];
203   [body addBodyPart: [self _sogoNotificationPart]];
204   [message setBody: body];
205   [body release];
206
207   [[SOGoMailer sharedMailer] sendMimePart: message
208                              toRecipients: [NSArray arrayWithObject: recipient]
209                              sender: from];
210 }
211
212 @end
213
214 @implementation SOGoACLAdditionAdvisory
215
216 - (NSString *) aclMethod { return @"add"; }
217
218 @end
219
220 @implementation SOGoACLRemovalAdvisory
221
222 - (NSString *) aclMethod { return @"remove"; }
223
224 @end
225
226 @implementation SOGoACLEnglishAdditionAdvisory
227 @end
228
229 @implementation SOGoACLFrenchAdditionAdvisory
230 @end
231
232 @implementation SOGoACLGermanAdditionAdvisory
233 @end
234
235 @implementation SOGoACLEnglishRemovalAdvisory
236 @end
237
238 @implementation SOGoACLFrenchRemovalAdvisory
239 @end
240
241 @implementation SOGoACLGermanRemovalAdvisory
242 @end