2007-11-18 11:16:25 +01:00
|
|
|
/* SOGoAptMailICalReply - this file is part of SOGo
|
|
|
|
*
|
2012-08-27 22:35:10 +02:00
|
|
|
* Copyright (C) 2010-2012 Inverse inc.
|
2007-11-18 11:16:25 +01:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@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.
|
|
|
|
*/
|
2012-08-27 22:35:10 +02:00
|
|
|
#import <Foundation/NSCharacterSet.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
#import "iCalPerson+SOGo.h"
|
2007-11-18 11:16:25 +01:00
|
|
|
#import "SOGoAptMailICalReply.h"
|
|
|
|
|
|
|
|
@implementation SOGoAptMailICalReply
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
attendee = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[attendee release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAttendee: (iCalPerson *) newAttendee
|
|
|
|
{
|
|
|
|
ASSIGN (attendee, newAttendee);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (iCalPerson *) attendee
|
|
|
|
{
|
|
|
|
return attendee;
|
|
|
|
}
|
|
|
|
|
2008-10-01 21:32:14 +02:00
|
|
|
- (NSString *) attendeeName
|
|
|
|
{
|
2008-11-05 22:04:16 +01:00
|
|
|
NSString *name;
|
|
|
|
|
|
|
|
name = [attendee cn];
|
|
|
|
|
|
|
|
if (name && [name length])
|
|
|
|
return name;
|
|
|
|
|
|
|
|
return [attendee rfc822Email];
|
|
|
|
}
|
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
- (void) setupValues
|
2008-11-05 22:04:16 +01:00
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
NSDictionary *sentByValues;
|
|
|
|
NSString *sentBy, *sentByText;
|
2008-11-05 22:04:16 +01:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
[super setupValues];
|
2008-10-01 21:32:14 +02:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
[values setObject: [self attendeeName] forKey: @"Attendee"];
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
sentBy = [attendee sentBy];
|
|
|
|
if ([sentBy length])
|
|
|
|
{
|
|
|
|
sentByValues = [NSDictionary dictionaryWithObject: sentBy
|
|
|
|
forKey: @"SentBy"];
|
|
|
|
sentByText
|
|
|
|
= [sentByValues keysWithFormat: [self
|
2010-07-08 06:47:28 +02:00
|
|
|
labelForKey: @"(sent by %{SentBy}) "
|
2010-04-09 20:45:14 +02:00
|
|
|
inContext: context]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sentByText = @"";
|
|
|
|
[values setObject: sentByText forKey: @"SentByText"];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate Response */
|
|
|
|
|
|
|
|
- (NSString *) getSubject
|
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
NSString *subjectFormat;
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
if (!values)
|
|
|
|
[self setupValues];
|
|
|
|
|
|
|
|
subjectFormat = [self labelForKey: @"Reply to invitation: \"%{Summary}\""
|
|
|
|
inContext: context];
|
2007-11-18 11:16:25 +01:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
return [values keysWithFormat: subjectFormat];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
- (NSString *) bodyStartText
|
2007-11-18 11:16:25 +01:00
|
|
|
{
|
2010-04-09 20:45:14 +02:00
|
|
|
NSString *bodyFormat;
|
|
|
|
NSString *partStat, *delegate;
|
2009-09-10 20:31:20 +02:00
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
partStat = [[attendee partStat] lowercaseString];
|
|
|
|
if ([partStat isEqualToString: @"accepted"])
|
|
|
|
bodyFormat = @"%{Attendee} %{SentByText}has accepted your event invitation.";
|
|
|
|
else if ([partStat isEqualToString: @"declined"])
|
|
|
|
bodyFormat = @"%{Attendee} %{SentByText}has declined your event invitation.";
|
|
|
|
else if ([partStat isEqualToString: @"delegated"])
|
|
|
|
{
|
|
|
|
bodyFormat = @"%{Attendee} %{SentByText}has delegated the invitation"
|
|
|
|
@" to %{Delegate}.";
|
|
|
|
delegate = [attendee delegatedTo];
|
|
|
|
if ([delegate length] > 7)
|
|
|
|
{
|
|
|
|
delegate = [delegate substringFromIndex: 7];
|
|
|
|
if ([delegate characterAtIndex: 0] == '"' && [delegate hasSuffix: @"\""])
|
|
|
|
delegate = [delegate substringWithRange: NSMakeRange(1, [delegate length]-2)];
|
|
|
|
|
|
|
|
[values setObject: delegate forKey: @"Delegate"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bodyFormat = @"%{Attendee} %{SentByText}has not yet decided upon your event invitation.";
|
2009-09-10 20:31:20 +02:00
|
|
|
|
2012-08-27 22:35:10 +02:00
|
|
|
return [values keysWithFormat: bodyFormat];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) getBody
|
|
|
|
{
|
|
|
|
NSString *body;
|
|
|
|
|
|
|
|
if (!values)
|
|
|
|
[self setupValues];
|
|
|
|
|
|
|
|
body = [[self generateResponse] contentAsString];
|
|
|
|
|
|
|
|
return [body stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
2007-11-18 11:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|