]> err.no Git - scalable-opengroupware.org/blob - SoObjects/Appointments/SOGoAptMailNotification.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1217 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / Appointments / SOGoAptMailNotification.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3  
4   This file is part of OpenGroupware.org.
5  
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #import <Foundation/NSCharacterSet.h>
23 #import <Foundation/NSCalendarDate.h>
24 #import <Foundation/NSTimeZone.h>
25
26 #import <NGObjWeb/WOActionResults.h>
27 #import <NGObjWeb/WOMessage.h>
28 #import <NGExtensions/NSObject+Logs.h>
29 #import <NGCards/iCalEntityObject.h>
30
31 #import <SoObjects/SOGo/NSString+Utilities.h>
32
33 #import "SOGoAptMailNotification.h"
34
35 @interface SOGoAptMailNotification (PrivateAPI)
36 - (BOOL)isSubject;
37 - (void)setIsSubject:(BOOL)_isSubject;
38 @end
39
40 @implementation SOGoAptMailNotification
41
42 static NSCharacterSet *wsSet  = nil;
43 static NSTimeZone     *EST = nil;
44
45 + (void)initialize {
46   static BOOL didInit = NO;
47
48   if (didInit) return;
49   didInit = YES;
50
51   wsSet = [[NSCharacterSet whitespaceAndNewlineCharacterSet] retain];
52   EST   = [[NSTimeZone timeZoneWithAbbreviation:@"EST"] retain];
53 }
54
55 - (void)dealloc {
56   [self->oldApt       release];
57   [self->newApt       release];
58   [self->homePageURL  release];
59   [self->viewTZ       release];
60
61   [self->oldStartDate release];
62   [self->newStartDate release];
63   [super dealloc];
64 }
65
66 - (id)oldApt {
67   return self->oldApt;
68 }
69 - (void)setOldApt:(iCalEntityObject *)_oldApt {
70   ASSIGN(self->oldApt, _oldApt);
71 }
72
73 - (id)newApt {
74   return self->newApt;
75 }
76
77 - (void)setNewApt:(iCalEntityObject *) _newApt
78 {
79   ASSIGN(self->newApt, _newApt);
80 }
81
82 - (NSString *)homePageURL {
83   return self->homePageURL;
84 }
85 - (void)setHomePageURL:(NSString *)_homePageURL {
86   ASSIGN(self->homePageURL, _homePageURL);
87 }
88
89 - (NSString *)appointmentURL {
90   NSString *aptUID;
91   
92   aptUID = [[self newApt] uid];
93   return [NSString stringWithFormat:@"%@/Calendar/personal/%@/edit?mail-invitation=yes",
94                                     [self homePageURL],
95                                     aptUID];
96 }
97
98 - (NSTimeZone *)viewTZ {
99   if (self->viewTZ) return self->viewTZ;
100   return EST;
101 }
102 - (void)setViewTZ:(NSTimeZone *)_viewTZ {
103   ASSIGN(self->viewTZ, _viewTZ);
104 }
105
106 - (BOOL)isSubject {
107   return self->isSubject;
108 }
109 - (void)setIsSubject:(BOOL)_isSubject {
110   self->isSubject = _isSubject;
111 }
112
113
114 /* Helpers */
115
116 - (NSCalendarDate *)oldStartDate {
117   if (!self->oldStartDate) {
118     ASSIGN(self->oldStartDate, [[self oldApt] startDate]);
119     [self->oldStartDate setTimeZone:[self viewTZ]];
120   }
121   return self->oldStartDate;
122 }
123
124 - (NSCalendarDate *)newStartDate {
125   if (!self->newStartDate) {
126     ASSIGN(self->newStartDate, [[self newApt] startDate]);
127     [self->newStartDate setTimeZone:[self viewTZ]];
128   }
129   return self->newStartDate;
130 }
131
132 /* Generate Response */
133
134 - (NSString *)getSubject {
135   NSString *subject;
136
137   [self setIsSubject:YES];
138   subject = [[[self generateResponse] contentAsString]
139                                       stringByTrimmingCharactersInSet:wsSet];
140   if (!subject) {
141     [self errorWithFormat:@"Failed to properly generate subject! Please check "
142                           @"template for component '%@'!",
143                           [self name]];
144     subject = @"ERROR: missing subject!";
145   }
146
147   return [subject asQPSubjectString: @"utf-8"];
148 }
149
150 - (NSString *)getBody {
151   [self setIsSubject:NO];
152   return [[self generateResponse] contentAsString];
153 }
154
155 @end