1 /* SOGoFolderAdvisory.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Ludovic Marcotte <ludovic@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 <Foundation/NSURL.h>
25 #import <NGObjWeb/WOResponse.h>
26 #import <NGExtensions/NGHashMap.h>
27 #import <NGMail/NGMimeMessage.h>
28 #import <NGMime/NGMimeBodyPart.h>
29 #import <NGMime/NGMimeMultipartBody.h>
31 #import <SoObjects/SOGo/SOGoMailer.h>
32 #import <SoObjects/SOGo/SOGoUser.h>
33 #import <SoObjects/SOGo/SOGoObject.h>
34 #import <SoObjects/SOGo/LDAPUserManager.h>
35 #import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
36 #import <SoObjects/SOGo/NSString+Utilities.h>
38 #import "SOGoFolderAdvisory.h"
40 @implementation SOGoFolderAdvisory
44 if ((self = [super init]))
57 [recipientUID release];
58 [folderObject release];
62 - (void) setFolderObject: (SOGoFolder *) theFolder
64 ASSIGN(folderObject, theFolder);
67 - (void) setRecipientUID: (NSString *) newRecipientUID
69 ASSIGN (recipientUID, newRecipientUID);
82 - (NSString *) displayName
84 return [folderObject displayName];
87 - (NSString *) httpFolderURL
89 NSString *absoluteString;
92 #warning the url returned by SOGoMail may be empty, we need to handle that
93 absoluteString = [[folderObject soURL] absoluteString];
94 url = [NSMutableString stringWithString: absoluteString];
96 if (![url hasSuffix: @"/"])
97 [url appendString: @"/"];
102 - (NSString *) subject
107 subject = [[self generateResponse] contentAsString];
110 return [[subject stringByTrimmingSpaces] asQPSubjectString: @"utf-8"];
118 body = [[self generateResponse] contentAsString];
121 return [body stringByTrimmingSpaces];
124 - (NSString *) folderMethod
126 [self subclassResponsibility: _cmd];
131 - (NGMimeBodyPart *) _textPart
133 NGMutableHashMap *headerMap;
134 NGMimeBodyPart *part;
137 headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
138 [headerMap setObject: @"text/plain; charset=utf-8" forKey: @"content-type"];
140 part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
141 body = [[self body] dataUsingEncoding: NSUTF8StringEncoding];
142 [part setBody: [self body]];
147 - (NGMimeBodyPart *) _sogoNotificationPart
149 NGMutableHashMap *headerMap;
150 NGMimeBodyPart *part;
154 headerMap = [NGMutableHashMap hashMapWithCapacity: 1];
155 [headerMap setObject: [NSString stringWithFormat:
156 @"%@; method=%@; type=%@; charset=%@",
157 @"application/x-sogo-notification",
158 [self folderMethod], [folderObject folderType],
160 forKey: @"content-type"];
162 part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
163 body = [[self httpFolderURL] dataUsingEncoding: NSUTF8StringEncoding];
164 [part setBody: body];
171 NSString *recipient, *date;
172 NGMutableHashMap *headerMap;
173 NGMimeMessage *message;
174 NGMimeMultipartBody *body;
175 SOGoUser *activeUser;
176 NSDictionary *identity;
177 NSString *from, *fullMail;
179 activeUser = [context activeUser];
180 identity = [activeUser primaryIdentity];
181 from = [identity objectForKey: @"email"];
182 fullMail = [NSString stringWithFormat: @"%@ <%@>",
183 [identity objectForKey: @"fullName"], from];
185 recipient = [[LDAPUserManager sharedUserManager]
186 getFullEmailForUID: recipientUID];
188 headerMap = [NGMutableHashMap hashMapWithCapacity: 5];
189 [headerMap setObject: @"multipart/alternative" forKey: @"content-type"];
190 [headerMap setObject: fullMail forKey: @"From"];
191 [headerMap setObject: recipient forKey: @"To"];
192 date = [[NSCalendarDate date] rfc822DateString];
193 [headerMap setObject: date forKey: @"Date"];
194 [headerMap setObject: [self subject] forKey: @"Subject"];
195 message = [NGMimeMessage messageWithHeader: headerMap];
197 body = [[NGMimeMultipartBody alloc] initWithPart: message];
198 [body addBodyPart: [self _textPart]];
199 [body addBodyPart: [self _sogoNotificationPart]];
200 [message setBody: body];
203 [[SOGoMailer sharedMailer] sendMimePart: message
204 toRecipients: [NSArray arrayWithObject: recipient]
210 @implementation SOGoFolderEnglishAdditionAdvisory
211 - (NSString *) folderMethod { return @"add"; }
214 @implementation SOGoFolderEnglishRemovalAdvisory
215 - (NSString *) folderMethod { return @"remove"; }
218 @implementation SOGoFolderFrenchAdditionAdvisory
219 - (NSString *) folderMethod { return @"add"; }
222 @implementation SOGoFolderFrenchRemovalAdvisory
223 - (NSString *) folderMethod { return @"remove"; }
226 @implementation SOGoFolderGermanAdditionAdvisory
227 - (NSString *) folderMethod { return @"add"; }
230 @implementation SOGoFolderGermanRemovalAdvisory
231 - (NSString *) folderMethod { return @"remove"; }