2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
2007-11-10 01:02:30 +01:00
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
2006-06-15 21:34:10 +02:00
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2007-11-10 01:02:30 +01:00
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
2006-06-15 21:34:10 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
UIxMailPartICalViewer
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
Show plain/calendar mail parts.
|
|
|
|
*/
|
|
|
|
|
2007-11-13 18:39:33 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
|
2007-07-30 16:10:18 +02:00
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
|
|
|
#import <NGImap4/NGImap4EnvelopeAddress.h>
|
|
|
|
|
|
|
|
#import <NGCards/iCalCalendar.h>
|
|
|
|
#import <NGCards/iCalEvent.h>
|
|
|
|
#import <NGCards/iCalPerson.h>
|
|
|
|
#import <NGCards/iCalDateTime.h>
|
|
|
|
|
2007-06-27 19:52:33 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoDateFormatter.h>
|
2007-05-09 21:23:45 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <SoObjects/Appointments/iCalEntityObject+SOGo.h>
|
2006-09-29 20:31:20 +02:00
|
|
|
#import <SoObjects/Appointments/SOGoAppointmentFolder.h>
|
|
|
|
#import <SoObjects/Appointments/SOGoAppointmentObject.h>
|
|
|
|
#import <SoObjects/Mailer/SOGoMailObject.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <SoObjects/Mailer/SOGoMailBodyPart.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-29 20:31:20 +02:00
|
|
|
#import "UIxMailPartICalViewer.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation UIxMailPartICalViewer
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[storedEventObject release];
|
|
|
|
[storedEvent release];
|
|
|
|
[attendee release];
|
|
|
|
[item release];
|
|
|
|
[inCalendar release];
|
|
|
|
[inEvent release];
|
|
|
|
[dateFormatter release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maintain caches */
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (void) resetPathCaches
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
[super resetPathCaches];
|
2007-11-10 01:02:30 +01:00
|
|
|
[inEvent release]; inEvent = nil;
|
|
|
|
[inCalendar release]; inCalendar = nil;
|
|
|
|
[storedEventObject release]; storedEventObject = nil;
|
|
|
|
[storedEvent release]; storedEvent = nil;
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* not strictly path-related, but useless without it anyway: */
|
2007-11-10 01:02:30 +01:00
|
|
|
[attendee release]; attendee = nil;
|
|
|
|
[item release]; item = nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* raw content handling */
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (NSStringEncoding) fallbackStringEncoding
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
iCalendar invitations sent by Outlook 2002 have the annoying bug that the
|
|
|
|
mail states an UTF-8 content encoding but the actual iCalendar content is
|
|
|
|
encoding in Latin-1 (or Windows Western?).
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
As a result the content decoding will fail (TODO: always?). In this case we
|
|
|
|
try to decode with Latin-1.
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
Note: we could check for the Outlook x-mailer, but it was considered better
|
2007-11-10 01:02:30 +01:00
|
|
|
to try Latin-1 as a fallback in any case (be tolerant).
|
2006-06-15 21:34:10 +02:00
|
|
|
*/
|
|
|
|
return NSISOLatin1StringEncoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2006-09-29 20:31:20 +02:00
|
|
|
- (iCalCalendar *) inCalendar
|
|
|
|
{
|
|
|
|
if (!inCalendar)
|
|
|
|
{
|
|
|
|
inCalendar
|
2007-11-10 01:02:30 +01:00
|
|
|
= [iCalCalendar parseSingleFromSource: [self flatContentAsString]];
|
2006-09-29 20:31:20 +02:00
|
|
|
[inCalendar retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return inCalendar;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-09-29 20:31:20 +02:00
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (BOOL) couldParseCalendar
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
return (([self inCalendar]));
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (iCalEvent *) inEvent
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *events;
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
if (!inEvent)
|
|
|
|
{
|
|
|
|
events = [[self inCalendar] events];
|
|
|
|
if ([events count] > 0)
|
|
|
|
inEvent = [[events objectAtIndex:0] retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return inEvent;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* formatters */
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (SOGoDateFormatter *) dateFormatter
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
if (!dateFormatter)
|
|
|
|
{
|
|
|
|
dateFormatter = [[context activeUser] dateFormatterInContext: context];
|
|
|
|
[dateFormatter retain];
|
|
|
|
}
|
2007-06-19 20:06:42 +02:00
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
return dateFormatter;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* below is copied from UIxAppointmentView, can we avoid that? */
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (void) setAttendee: (id) _attendee
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
ASSIGN (attendee, _attendee);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-11-10 01:02:30 +01:00
|
|
|
|
|
|
|
- (id) attendee
|
|
|
|
{
|
|
|
|
return attendee;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-03-30 20:09:55 +02:00
|
|
|
- (NSString *) _personForDisplay: (iCalPerson *) person
|
|
|
|
{
|
2007-11-10 01:02:30 +01:00
|
|
|
NSString *fn, *email, *result;
|
|
|
|
|
|
|
|
fn = [person cnWithoutQuotes];
|
|
|
|
email = [person rfc822Email];
|
|
|
|
if ([fn length])
|
|
|
|
result = [NSString stringWithFormat: @"%@ <%@>",
|
|
|
|
fn, email];
|
|
|
|
else
|
|
|
|
result = email;
|
|
|
|
|
|
|
|
return result;
|
2007-03-30 20:09:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) attendeeForDisplay
|
|
|
|
{
|
|
|
|
return [self _personForDisplay: attendee];
|
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (void) setItem: (id) _item
|
|
|
|
{
|
|
|
|
ASSIGN(item, _item);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-11-10 01:02:30 +01:00
|
|
|
|
|
|
|
- (id) item
|
|
|
|
{
|
|
|
|
return item;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:08:58 +02:00
|
|
|
- (NSCalendarDate *) startTime
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSCalendarDate *date;
|
2007-04-11 21:08:58 +02:00
|
|
|
NSTimeZone *timeZone;
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
date = [[self authorativeEvent] startDate];
|
2007-04-11 21:08:58 +02:00
|
|
|
timeZone = [[context activeUser] timeZone];
|
|
|
|
[date setTimeZone: timeZone];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
2007-04-11 21:08:58 +02:00
|
|
|
- (NSCalendarDate *) endTime
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSCalendarDate *date;
|
2007-04-11 21:08:58 +02:00
|
|
|
NSTimeZone *timeZone;
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
date = [[self authorativeEvent] endDate];
|
2007-04-11 21:08:58 +02:00
|
|
|
timeZone = [[context activeUser] timeZone];
|
|
|
|
[date setTimeZone: timeZone];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (BOOL) isEndDateOnSameDay
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self startTime] isDateOnSameDay:[self endTime]];
|
|
|
|
}
|
2007-11-10 01:02:30 +01:00
|
|
|
|
|
|
|
- (NSTimeInterval) duration
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self endTime] timeIntervalSinceDate:[self startTime]];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calendar folder support */
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (SOGoAppointmentFolder *) calendarFolder
|
2007-09-17 20:01:02 +02:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* return scheduling calendar of currently logged-in user */
|
2007-05-09 21:23:45 +02:00
|
|
|
SOGoUser *user;
|
|
|
|
id folder;
|
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
folder = [[user homeFolderInContext: context] lookupName: @"Calendar"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
|
2007-09-17 20:01:02 +02:00
|
|
|
return [folder lookupName: @"personal" inContext: context acquire: NO];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (SOGoAppointmentObject *) storedEventObject
|
2007-11-10 01:02:30 +01:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* lookup object in the users Calendar */
|
2007-11-18 11:16:25 +01:00
|
|
|
SOGoAppointmentFolder *calendar;
|
|
|
|
NSString *filename;
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
if (!storedEventObject)
|
|
|
|
{
|
|
|
|
calendar = [self calendarFolder];
|
|
|
|
if ([calendar isKindOfClass: [NSException class]])
|
|
|
|
[self errorWithFormat:@"Did not find Calendar folder: %@", calendar];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename = [calendar resourceNameForEventUID:[[self inEvent] uid]];
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
storedEventObject = [calendar lookupName: filename
|
|
|
|
inContext: [self context]
|
|
|
|
acquire: NO];
|
|
|
|
if ([storedEventObject isKindOfClass: [NSException class]])
|
|
|
|
storedEventObject = nil;
|
|
|
|
else
|
|
|
|
[storedEventObject retain];
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-11-10 01:02:30 +01:00
|
|
|
|
|
|
|
return storedEventObject;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (BOOL) isEventStoredInCalendar
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
return (([self storedEventObject]));
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (iCalEvent *) storedEvent
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
if (!storedEvent)
|
|
|
|
{
|
|
|
|
storedEvent = [[self storedEventObject] component: NO secure: NO];
|
|
|
|
[storedEvent retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return storedEvent;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* organizer tracking */
|
|
|
|
|
2007-08-15 22:13:41 +02:00
|
|
|
- (NSString *) loggedInUserEMail
|
|
|
|
{
|
|
|
|
NSDictionary *identity;
|
|
|
|
|
|
|
|
identity = [[context activeUser] primaryIdentity];
|
|
|
|
|
|
|
|
return [identity objectForKey: @"email"];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (iCalEvent *) authorativeEvent
|
|
|
|
{
|
2007-11-13 23:38:05 +01:00
|
|
|
iCalEvent *authorativeEvent;
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
[self storedEvent];
|
|
|
|
if (!storedEvent
|
|
|
|
|| ([storedEvent compare: [self inEvent]] == NSOrderedAscending))
|
2007-11-13 23:38:05 +01:00
|
|
|
authorativeEvent = inEvent;
|
|
|
|
else
|
2007-11-18 11:16:25 +01:00
|
|
|
authorativeEvent = [self storedEvent];
|
2007-11-13 23:38:05 +01:00
|
|
|
|
|
|
|
return authorativeEvent;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (BOOL) isLoggedInUserTheOrganizer
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
return [[self authorativeEvent] userIsOrganizer: [context activeUser]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (BOOL) isLoggedInUserAnAttendee
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
return [[self authorativeEvent] userIsParticipant: [context activeUser]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* derived fields */
|
|
|
|
|
2007-03-30 20:09:55 +02:00
|
|
|
- (NSString *) organizerDisplayName
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
iCalPerson *organizer;
|
2007-03-30 20:09:55 +02:00
|
|
|
NSString *value;
|
|
|
|
|
|
|
|
organizer = [[self authorativeEvent] organizer];
|
|
|
|
if (organizer)
|
|
|
|
value = [self _personForDisplay: organizer];
|
|
|
|
else
|
|
|
|
value = @"[todo: no organizer set, use 'from']";
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-03-30 20:09:55 +02:00
|
|
|
return value;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* replies */
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (NGImap4EnvelopeAddress *) replySenderAddress
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
The iMIP reply is the sender of the mail, the 'attendees' are NOT set to
|
|
|
|
the actual attendees. BUT the attendee field contains the reply-status!
|
|
|
|
*/
|
|
|
|
id tmp;
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
tmp = [[self clientObject] fromEnvelopeAddresses];
|
|
|
|
if ([tmp count] == 0) return nil;
|
|
|
|
return [tmp objectAtIndex:0];
|
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (NSString *) replySenderEMail
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self replySenderAddress] email];
|
|
|
|
}
|
2007-11-10 01:02:30 +01:00
|
|
|
|
|
|
|
- (NSString *) replySenderBaseEMail
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self replySenderAddress] baseEMail];
|
|
|
|
}
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
- (iCalPerson *) inReplyAttendee
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *attendees;
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
attendees = [[self inEvent] attendees];
|
|
|
|
if ([attendees count] == 0)
|
|
|
|
return nil;
|
|
|
|
if ([attendees count] > 1)
|
|
|
|
[self warnWithFormat:@"More than one attendee in REPLY: %@", attendees];
|
2007-11-10 01:02:30 +01:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return [attendees objectAtIndex:0];
|
|
|
|
}
|
2007-11-10 01:02:30 +01:00
|
|
|
|
|
|
|
- (iCalPerson *) storedReplyAttendee
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
TODO: since an attendee can have multiple email addresses, maybe we
|
2007-11-10 01:02:30 +01:00
|
|
|
should translate the email to an internal uid and then retrieve
|
|
|
|
all emails addresses for matching the participant.
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
Note: -findParticipantWithEmail: does not parse the email!
|
|
|
|
*/
|
2007-11-10 01:02:30 +01:00
|
|
|
iCalEvent *e;
|
2006-06-15 21:34:10 +02:00
|
|
|
iCalPerson *p;
|
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
p = nil;
|
|
|
|
|
|
|
|
e = [self storedEvent];
|
|
|
|
if (e)
|
|
|
|
{
|
|
|
|
p = [e findParticipantWithEmail: [self replySenderBaseEMail]];
|
|
|
|
if (!p)
|
|
|
|
p = [e findParticipantWithEmail:[self replySenderEMail]];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-10 01:02:30 +01:00
|
|
|
return p;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-11-10 01:02:30 +01:00
|
|
|
|
|
|
|
- (BOOL) isReplySenderAnAttendee
|
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
return (([self storedReplyAttendee]));
|
|
|
|
}
|
|
|
|
|
|
|
|
- (iCalPerson *) _emailParticipantWithEvent: (iCalEvent *) event
|
|
|
|
{
|
|
|
|
NSString *emailFrom;
|
|
|
|
SOGoMailObject *mailObject;
|
|
|
|
NGImap4EnvelopeAddress *address;
|
|
|
|
|
|
|
|
mailObject = [[self clientObject] mailObject];
|
|
|
|
address = [[mailObject fromEnvelopeAddresses] objectAtIndex: 0];
|
|
|
|
emailFrom = [address baseEMail];
|
|
|
|
|
|
|
|
return [event findParticipantWithEmail: emailFrom];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasSenderStatusChanged
|
|
|
|
{
|
|
|
|
iCalPerson *emailParticipant, *calendarParticipant;
|
|
|
|
|
|
|
|
[self inEvent];
|
|
|
|
[self storedEvent];
|
|
|
|
emailParticipant = [self _emailParticipantWithEvent: inEvent];
|
|
|
|
calendarParticipant = [self _emailParticipantWithEvent: storedEvent];
|
|
|
|
|
|
|
|
return ([[emailParticipant partStat]
|
|
|
|
caseInsensitiveCompare: [calendarParticipant partStat]]
|
|
|
|
!= NSOrderedSame);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end /* UIxMailPartICalViewer */
|