2007-10-14 18:07:22 +02:00
|
|
|
/* SOGoFolderAdvisory.m - this file is part of SOGo
|
|
|
|
*
|
2010-11-09 19:34:37 +01:00
|
|
|
* Copyright (C) 2007-2010 Inverse inc.
|
2007-10-14 18:07:22 +02:00
|
|
|
*
|
|
|
|
* Author: Ludovic Marcotte <ludovic@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-10-17 17:45:23 +02:00
|
|
|
#import <Foundation/NSURL.h>
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NGHashMap.h>
|
|
|
|
#import <NGMail/NGMimeMessage.h>
|
|
|
|
#import <NGMime/NGMimeBodyPart.h>
|
|
|
|
#import <NGMime/NGMimeMultipartBody.h>
|
|
|
|
|
|
|
|
#import <SoObjects/SOGo/SOGoMailer.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2009-09-25 16:42:33 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUserManager.h>
|
2007-10-14 18:07:22 +02:00
|
|
|
#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
|
2007-10-17 17:45:23 +02:00
|
|
|
#import <SoObjects/SOGo/NSString+Utilities.h>
|
2007-10-14 18:07:22 +02:00
|
|
|
|
|
|
|
#import "SOGoFolderAdvisory.h"
|
|
|
|
|
|
|
|
@implementation SOGoFolderAdvisory
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
recipientUID = nil;
|
|
|
|
folderObject = nil;
|
|
|
|
isSubject = NO;
|
|
|
|
isBody = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[recipientUID release];
|
|
|
|
[folderObject release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFolderObject: (SOGoFolder *) theFolder
|
|
|
|
{
|
|
|
|
ASSIGN(folderObject, theFolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRecipientUID: (NSString *) newRecipientUID
|
|
|
|
{
|
|
|
|
ASSIGN (recipientUID, newRecipientUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSubject
|
|
|
|
{
|
|
|
|
return isSubject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isBody
|
|
|
|
{
|
|
|
|
return isBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) displayName
|
|
|
|
{
|
|
|
|
return [folderObject displayName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) httpFolderURL
|
|
|
|
{
|
2007-10-17 17:45:23 +02:00
|
|
|
NSString *absoluteString;
|
2007-10-14 18:07:22 +02:00
|
|
|
NSMutableString *url;
|
|
|
|
|
|
|
|
#warning the url returned by SOGoMail may be empty, we need to handle that
|
2007-10-17 17:45:23 +02:00
|
|
|
absoluteString = [[folderObject soURL] absoluteString];
|
|
|
|
url = [NSMutableString stringWithString: absoluteString];
|
2007-10-14 18:07:22 +02:00
|
|
|
|
|
|
|
if (![url hasSuffix: @"/"])
|
|
|
|
[url appendString: @"/"];
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) subject
|
|
|
|
{
|
|
|
|
NSString *subject;
|
|
|
|
|
|
|
|
isSubject = YES;
|
|
|
|
subject = [[self generateResponse] contentAsString];
|
|
|
|
isSubject = NO;
|
|
|
|
|
2007-10-17 17:45:23 +02:00
|
|
|
return [[subject stringByTrimmingSpaces] asQPSubjectString: @"utf-8"];
|
2007-10-14 18:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) body
|
|
|
|
{
|
|
|
|
NSString *body;
|
|
|
|
|
|
|
|
isBody = YES;
|
|
|
|
body = [[self generateResponse] contentAsString];
|
|
|
|
isBody = NO;
|
|
|
|
|
|
|
|
return [body stringByTrimmingSpaces];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) folderMethod
|
|
|
|
{
|
|
|
|
[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];
|
2012-10-22 16:09:13 +02:00
|
|
|
[part setBody: body];
|
2007-10-14 18:07:22 +02:00
|
|
|
|
|
|
|
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 folderMethod], [folderObject folderType],
|
|
|
|
@"utf-8"]
|
|
|
|
forKey: @"content-type"];
|
|
|
|
|
|
|
|
part = [NGMimeBodyPart bodyPartWithHeader: headerMap];
|
|
|
|
body = [[self httpFolderURL] dataUsingEncoding: NSUTF8StringEncoding];
|
|
|
|
[part setBody: body];
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) send
|
|
|
|
{
|
|
|
|
NSString *recipient, *date;
|
|
|
|
NGMutableHashMap *headerMap;
|
|
|
|
NGMimeMessage *message;
|
|
|
|
NGMimeMultipartBody *body;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoDomainDefaults *dd;
|
2007-10-14 18:07:22 +02:00
|
|
|
SOGoUser *activeUser;
|
|
|
|
NSDictionary *identity;
|
|
|
|
NSString *from, *fullMail;
|
|
|
|
|
|
|
|
activeUser = [context activeUser];
|
|
|
|
identity = [activeUser primaryIdentity];
|
|
|
|
from = [identity objectForKey: @"email"];
|
|
|
|
fullMail = [NSString stringWithFormat: @"%@ <%@>",
|
|
|
|
[identity objectForKey: @"fullName"], from];
|
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
recipient = [[SOGoUserManager sharedUserManager]
|
2007-10-14 18:07:22 +02:00
|
|
|
getFullEmailForUID: recipientUID];
|
|
|
|
|
2009-11-07 23:33:25 +01:00
|
|
|
#warning SOPE is just plain stupid here - if you change the case of keys, it will break the encoding of fields
|
2007-10-14 18:07:22 +02:00
|
|
|
headerMap = [NGMutableHashMap hashMapWithCapacity: 5];
|
|
|
|
[headerMap setObject: @"multipart/alternative" forKey: @"content-type"];
|
2009-11-07 23:33:25 +01:00
|
|
|
[headerMap setObject: fullMail forKey: @"from"];
|
|
|
|
[headerMap setObject: recipient forKey: @"to"];
|
2007-10-14 18:07:22 +02:00
|
|
|
date = [[NSCalendarDate date] rfc822DateString];
|
2009-11-07 23:33:25 +01:00
|
|
|
[headerMap setObject: date forKey: @"date"];
|
|
|
|
[headerMap setObject: [self subject] forKey: @"subject"];
|
2007-10-14 18:07:22 +02:00
|
|
|
message = [NGMimeMessage messageWithHeader: headerMap];
|
|
|
|
|
|
|
|
body = [[NGMimeMultipartBody alloc] initWithPart: message];
|
|
|
|
[body addBodyPart: [self _textPart]];
|
|
|
|
[body addBodyPart: [self _sogoNotificationPart]];
|
|
|
|
[message setBody: body];
|
|
|
|
[body release];
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
dd = [activeUser domainDefaults];
|
|
|
|
[[SOGoMailer mailerWithDomainDefaults: dd]
|
2012-10-16 22:56:48 +02:00
|
|
|
sendMimePart: message
|
|
|
|
toRecipients: [NSArray arrayWithObject: recipient]
|
|
|
|
sender: from
|
|
|
|
withAuthenticator: [self authenticatorInContext: context]
|
|
|
|
inContext: context];
|
2007-10-14 18:07:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoFolderAdditionAdvisory
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
- (NSString *) folderMethod { return @"add"; }
|
2008-05-20 21:16:19 +02:00
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoFolderRemovalAdvisory
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
- (NSString *) folderMethod { return @"remove"; }
|
2008-05-20 21:16:19 +02:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2009-07-09 21:49:04 +02:00
|
|
|
@implementation SOGoFolderBrazilianPortugueseAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderBrazilianPortugueseRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderCzechAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderCzechRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2011-12-19 18:16:23 +01:00
|
|
|
@implementation SOGoFolderDanishAdditionAdvisory
|
2011-12-02 04:37:42 +01:00
|
|
|
@end
|
|
|
|
|
2011-12-19 18:16:23 +01:00
|
|
|
@implementation SOGoFolderDanishRemovalAdvisory
|
2011-12-02 04:37:42 +01:00
|
|
|
@end
|
|
|
|
|
2008-05-20 21:16:19 +02:00
|
|
|
@implementation SOGoFolderDutchAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderDutchRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderEnglishAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderEnglishRemovalAdvisory
|
2007-10-14 18:07:22 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderFrenchAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderFrenchRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderGermanAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderGermanRemovalAdvisory
|
|
|
|
@end
|
2008-03-20 14:48:17 +01:00
|
|
|
|
2017-03-09 18:31:54 +01:00
|
|
|
@implementation SOGoFolderHebrewAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderHebrewRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2009-07-30 04:12:53 +02:00
|
|
|
@implementation SOGoFolderHungarianAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderHungarianRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2011-05-11 21:12:47 +02:00
|
|
|
@implementation SOGoFolderIcelandicAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderIcelandicRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2008-03-20 14:48:17 +01:00
|
|
|
@implementation SOGoFolderItalianAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderItalianRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2017-05-30 23:27:49 +02:00
|
|
|
@implementation SOGoFolderLatvianAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderLatvianRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderLithuanianAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderLithuanianRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2011-11-17 16:22:09 +01:00
|
|
|
@implementation SOGoFolderNorwegianBokmalAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderNorwegianBokmalRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderNorwegianNynorskAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderNorwegianNynorskRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2010-08-03 17:13:58 +02:00
|
|
|
@implementation SOGoFolderPolishAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderPolishRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2009-11-18 23:54:12 +01:00
|
|
|
@implementation SOGoFolderRussianAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderRussianRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
2011-11-17 16:22:09 +01:00
|
|
|
@implementation SOGoFolderSpanishSpainAdditionAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderSpanishSpainRemovalAdvisory
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFolderSpanishArgentinaAdditionAdvisory
|
2008-05-20 21:16:19 +02:00
|
|
|
@end
|
|
|
|
|
2011-11-17 16:22:09 +01:00
|
|
|
@implementation SOGoFolderSpanishArgentinaRemovalAdvisory
|
2008-05-20 21:16:19 +02:00
|
|
|
@end
|
2009-05-23 13:12:34 +02:00
|
|
|
|
2009-11-18 23:54:12 +01:00
|
|
|
@implementation SOGoFolderSwedishAdditionAdvisory
|
2009-05-23 13:12:34 +02:00
|
|
|
@end
|
|
|
|
|
2009-11-18 23:54:12 +01:00
|
|
|
@implementation SOGoFolderSwedishRemovalAdvisory
|
2009-05-23 13:12:34 +02:00
|
|
|
@end
|