From 454ed446ea19ed77113331ece5c64104459873dd Mon Sep 17 00:00:00 2001 From: wolfgang Date: Wed, 31 Jan 2007 22:36:08 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1014 d1b88da0-ebda-0310-925b-ed51d893ca5b --- ChangeLog | 9 + .../Appointments/SOGoAppointmentObject.h | 16 +- .../Appointments/SOGoAppointmentObject.m | 278 ++---------------- .../Appointments/SOGoCalendarComponent.h | 10 +- .../Appointments/SOGoCalendarComponent.m | 199 ++++++++++++- .../Appointments/SOGoGroupAppointmentFolder.m | 2 + SoObjects/Appointments/SOGoTaskObject.m | 242 ++------------- SoObjects/common.make | 3 +- UI/Common/UIxAclEditor.m | 1 + 9 files changed, 279 insertions(+), 481 deletions(-) diff --git a/ChangeLog b/ChangeLog index e236403f..4c84b8a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-01-31 Wolfgang Sourdeau + + * SoObjects/Appointments/SOGoCalendarComponent.m + ([SOGoCalendarComponent -sendEMailNotifications]): new method that + returns the value of ud "SOGoAppointmentSendEMailNotifications" + (iMIP/iTIP). + ([SOGoCalendarComponent + -sendEMailUsingTemplateNamed:_pageNameforOldObject:_oldObjectandNewObject:_newObjecttoAttendees:_attendees]): method moved from SOGoAppointmentObject/SOGoTaskObject, replacing occurences of "appointment" to "object" in its name. + 2007-01-30 Wolfgang Sourdeau * UI/MailerUI/UIxMailListView.m ([UIxMailListView diff --git a/SoObjects/Appointments/SOGoAppointmentObject.h b/SoObjects/Appointments/SOGoAppointmentObject.h index 3c7e4d78..ab41219b 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.h +++ b/SoObjects/Appointments/SOGoAppointmentObject.h @@ -53,18 +53,20 @@ /* folder management */ -- (id)lookupHomeFolderForUID:(NSString *)_uid inContext:(id)_ctx; -- (NSArray *)lookupCalendarFoldersForUIDs:(NSArray *)_uids inContext:(id)_ctx; +- (id) lookupHomeFolderForUID: (NSString *) _uid inContext: (id)_ctx; +- (NSArray *) lookupCalendarFoldersForUIDs: (NSArray *) _uids + inContext: (id) _ctx; /* "iCal multifolder saves" */ -- (NSException *)saveContentString:(NSString *)_iCal baseSequence:(int)_v; -- (NSException *)deleteWithBaseSequence:(int)_v; +- (NSException *) saveContentString: (NSString *)_iCal + baseSequence: (int) _v; +- (NSException *) deleteWithBaseSequence: (int) _v; -- (NSException *)saveContentString:(NSString *)_iCalString; +- (NSException *) saveContentString: (NSString *) _iCalString; -- (NSException *)changeParticipationStatus:(NSString *)_status - inContext:(id)_ctx; +- (NSException *) changeParticipationStatus: (NSString *) _status + inContext: (id) _ctx; @end diff --git a/SoObjects/Appointments/SOGoAppointmentObject.m b/SoObjects/Appointments/SOGoAppointmentObject.m index 42e4f01e..cd2d9070 100644 --- a/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SoObjects/Appointments/SOGoAppointmentObject.m @@ -25,64 +25,18 @@ #import #import #import -#import -#import -#import #import #import -#import "SOGoAptMailNotification.h" #import "iCalEntityObject+Agenor.h" #import "common.h" #import "NSArray+Appointments.h" -@interface SOGoAppointmentObject (PrivateAPI) -- (NSString *) homePageURLForPerson: (iCalPerson *) _person; - -- (void) sendEMailUsingTemplateNamed: (NSString *) _pageName - forOldAppointment: (iCalEvent *) _newApt - andNewAppointment: (iCalEvent *) _oldApt - toAttendees: (NSArray *) _attendees; - -- (void) sendInvitationEMailForAppointment: (iCalEvent *) _apt - toAttendees: (NSArray *) _attendees; -- (void) sendAppointmentUpdateEMailForOldAppointment: (iCalEvent *) _oldApt - newAppointment: (iCalEvent *) _newApt - toAttendees: (NSArray *) _attendees; -- (void) sendAttendeeRemovalEMailForAppointment: (iCalEvent *) _apt - toAttendees: (NSArray *) _attendees; -- (void) sendAppointmentDeletionEMailForAppointment: (iCalEvent *) _apt - toAttendees: (NSArray *) _attendees; -@end - @implementation SOGoAppointmentObject -static NSString *mailTemplateDefaultLanguage = nil; -static BOOL sendEMailNotifications = NO; - -+ (void) initialize -{ - NSUserDefaults *ud; - static BOOL didInit = NO; - - if (!didInit) - { - didInit = YES; - - ud = [NSUserDefaults standardUserDefaults]; - mailTemplateDefaultLanguage = [[ud stringForKey:@"SOGoDefaultLanguage"] - retain]; - if (!mailTemplateDefaultLanguage) - mailTemplateDefaultLanguage = @"French"; - - sendEMailNotifications - = [ud boolForKey: @"SOGoAppointmentSendEMailNotifications"]; - } -} - /* accessors */ - (iCalEvent *) event @@ -290,7 +244,7 @@ static BOOL sendEMailNotifications = NO; /* handle old content */ - oldContent = [self iCalString]; /* if nil, this is a new appointment */ + oldContent = [self contentAsString]; /* if nil, this is a new appointment */ if ([oldContent length] == 0) { /* new appointment */ @@ -395,20 +349,23 @@ static BOOL sendEMailNotifications = NO; if (delError != nil) return delError; /* email notifications */ - if (sendEMailNotifications) + if ([self sendEMailNotifications]) { - attendees = [NSMutableArray arrayWithArray:[changes insertedAttendees]]; - [attendees removePerson:organizer]; - [self sendInvitationEMailForAppointment:newApt - toAttendees:attendees]; + attendees = [NSMutableArray arrayWithArray: [changes insertedAttendees]]; + [attendees removePerson: organizer]; + [self sendEMailUsingTemplateNamed: @"Invitation" + forOldObject: nil + andNewObject: newApt + toAttendees: attendees]; if (updateForcesReconsider) { attendees = [NSMutableArray arrayWithArray:[newApt attendees]]; [attendees removeObjectsInArray:[changes insertedAttendees]]; [attendees removePerson:organizer]; - [self sendAppointmentUpdateEMailForOldAppointment:oldApt - newAppointment:newApt - toAttendees:attendees]; + [self sendEMailUsingTemplateNamed: @"Update" + forOldObject: oldApt + andNewObject: newApt + toAttendees: attendees]; } attendees = [NSMutableArray arrayWithArray:[changes deletedAttendees]]; @@ -419,7 +376,9 @@ static BOOL sendEMailNotifications = NO; canceledApt = [newApt copy]; [(iCalCalendar *) [canceledApt parent] setMethod: @"cancel"]; - [self sendAttendeeRemovalEMailForAppointment:canceledApt + [self sendEMailUsingTemplateNamed: @"Removal" + forOldObject: nil + andNewObject: canceledApt toAttendees: attendees]; [canceledApt release]; } @@ -459,7 +418,7 @@ static BOOL sendEMailNotifications = NO; removedUIDs = [self attendeeUIDsFromAppointment:apt]; - if (sendEMailNotifications) + if ([self sendEMailNotifications]) { /* send notification email to attendees excluding organizer */ attendees = [NSMutableArray arrayWithArray:[apt attendees]]; @@ -473,8 +432,10 @@ static BOOL sendEMailNotifications = NO; [apt removeAllAttendees]; /* send notification email */ - [self sendAppointmentDeletionEMailForAppointment:apt - toAttendees:attendees]; + [self sendEMailUsingTemplateNamed: @"Deletion" + forOldObject: nil + andNewObject: apt + toAttendees: attendees]; } /* perform */ @@ -545,33 +506,6 @@ static BOOL sendEMailNotifications = NO; return @"IPM.Appointment"; } -/* EMail Notifications */ - -- (NSString *) homePageURLForPerson: (iCalPerson *) _person -{ - NSString *baseURL; - NSString *uid; - WOContext *ctx; - NSArray *traversalObjects; - - /* generate URL from traversal stack */ - ctx = [[WOApplication application] context]; - traversalObjects = [ctx objectTraversalStack]; - if ([traversalObjects count] > 0) - baseURL = [[traversalObjects objectAtIndex:0] baseURLInContext:ctx]; - else - { - baseURL = @"http://localhost/"; - [self warnWithFormat:@"Unable to create baseURL from context!"]; - } - uid = [[AgenorUserManager sharedUserManager] - getUIDForEmail: [_person rfc822Email]]; - - return ((uid) - ? [NSString stringWithFormat:@"%@%@", baseURL, uid] - : nil); -} - - (NSException *) saveContentString: (NSString *) contentString baseVersion: (unsigned int) baseVersion { @@ -580,7 +514,7 @@ static BOOL sendEMailNotifications = NO; iCalEvent *event; NSArray *organizers; - oldContentString = [self iCalString]; + oldContentString = [self contentAsString]; if (oldContentString) newContentString = contentString; else @@ -601,176 +535,6 @@ static BOOL sendEMailNotifications = NO; baseVersion: baseVersion]; } -- (void) sendEMailUsingTemplateNamed: (NSString *) _pageName - forOldAppointment: (iCalEvent *) _oldApt - andNewAppointment: (iCalEvent *) _newApt - toAttendees: (NSArray *) _attendees -{ - NSString *pageName; - iCalPerson *organizer; - NSString *cn, *sender, *iCalString; - NGSendMail *sendmail; - WOApplication *app; - unsigned i, count; - iCalPerson *attendee; - NSString *recipient; - SOGoAptMailNotification *p; - NSString *subject, *text, *header; - NGMutableHashMap *headerMap; - NGMimeMessage *msg; - NGMimeBodyPart *bodyPart; - NGMimeMultipartBody *body; - - if ([_attendees count]) - { - /* sender */ - - organizer = [_newApt organizer]; - cn = [organizer cnWithoutQuotes]; - if (cn) - sender = [NSString stringWithFormat:@"%@ <%@>", - cn, - [organizer rfc822Email]]; - else - sender = [organizer rfc822Email]; - - /* generate iCalString once */ - iCalString = [[_newApt parent] versitString]; - - /* get sendmail object */ - sendmail = [NGSendMail sharedSendMail]; - - /* get WOApplication instance */ - app = [WOApplication application]; - - /* generate dynamic message content */ - - count = [_attendees count]; - for (i = 0; i < count; i++) - { - attendee = [_attendees objectAtIndex:i]; - - /* construct recipient */ - cn = [attendee cn]; - if (cn) - recipient = [NSString stringWithFormat: @"%@ <%@>", - cn, - [attendee rfc822Email]]; - else - recipient = [attendee rfc822Email]; - - /* create page name */ - // TODO: select user's default language? - pageName = [NSString stringWithFormat: @"SOGoAptMail%@%@", - mailTemplateDefaultLanguage, - _pageName]; - /* construct message content */ - p = [app pageWithName: pageName inContext: [WOContext context]]; - [p setNewApt: _newApt]; - [p setOldApt: _oldApt]; - [p setHomePageURL: [self homePageURLForPerson: attendee]]; - [p setViewTZ: [self userTimeZone: cn]]; - subject = [p getSubject]; - text = [p getBody]; - - /* construct message */ - headerMap = [NGMutableHashMap hashMapWithCapacity: 5]; - - /* NOTE: multipart/alternative seems like the correct choice but - * unfortunately Thunderbird doesn't offer the rich content alternative - * at all. Mail.app shows the rich content alternative _only_ - * so we'll stick with multipart/mixed for the time being. - */ - [headerMap setObject: @"multipart/mixed" forKey: @"content-type"]; - [headerMap setObject: sender forKey: @"From"]; - [headerMap setObject: recipient forKey: @"To"]; - [headerMap setObject: [NSCalendarDate date] forKey: @"date"]; - [headerMap setObject: subject forKey: @"Subject"]; - msg = [NGMimeMessage messageWithHeader: headerMap]; - - /* multipart body */ - body = [[NGMimeMultipartBody alloc] initWithPart: msg]; - - /* text part */ - headerMap = [NGMutableHashMap hashMapWithCapacity: 1]; - [headerMap setObject: @"text/plain; charset=utf-8" - forKey: @"content-type"]; - bodyPart = [NGMimeBodyPart bodyPartWithHeader: headerMap]; - [bodyPart setBody: [text dataUsingEncoding: NSUTF8StringEncoding]]; - - /* attach text part to multipart body */ - [body addBodyPart: bodyPart]; - - /* calendar part */ - header = [NSString stringWithFormat: @"text/calendar; method=%@;" - @" charset=utf-8", - [(iCalCalendar *) [_newApt parent] method]]; - headerMap = [NGMutableHashMap hashMapWithCapacity: 1]; - [headerMap setObject:header forKey: @"content-type"]; - bodyPart = [NGMimeBodyPart bodyPartWithHeader: headerMap]; - [bodyPart setBody: [iCalString dataUsingEncoding: NSUTF8StringEncoding]]; - - /* attach calendar part to multipart body */ - [body addBodyPart: bodyPart]; - - /* attach multipart body to message */ - [msg setBody: body]; - [body release]; - - /* send the damn thing */ - [sendmail sendMimePart: msg - toRecipients: [NSArray arrayWithObject: [attendee rfc822Email]] - sender: [organizer rfc822Email]]; - } - } -} - -- (void) sendInvitationEMailForAppointment: (iCalEvent *) _apt - toAttendees: (NSArray *) _attendees -{ - if ([_attendees count]) - [self sendEMailUsingTemplateNamed: @"Invitation" - forOldAppointment: nil - andNewAppointment: _apt - toAttendees: _attendees]; -} - -- (void) sendAppointmentUpdateEMailForOldAppointment: (iCalEvent *) _oldApt - newAppointment: (iCalEvent *) _newApt - toAttendees: (NSArray *) _attendees -{ - if ([_attendees count]) - [self sendEMailUsingTemplateNamed: @"Update" - forOldAppointment: _oldApt - andNewAppointment: _newApt - toAttendees: _attendees]; -} - -- (void) sendAttendeeRemovalEMailForAppointment: (iCalEvent *) _apt - toAttendees: (NSArray *) _attendees -{ - if ([_attendees count]) - [self sendEMailUsingTemplateNamed: @"Removal" - forOldAppointment: nil - andNewAppointment: _apt - toAttendees: _attendees]; -} - -- (void) sendAppointmentDeletionEMailForAppointment: (iCalEvent *) _apt - toAttendees: (NSArray *) _attendees -{ - if ([_attendees count]) - [self sendEMailUsingTemplateNamed: @"Deletion" - forOldAppointment: nil - andNewAppointment: _apt - toAttendees: _attendees]; -} - -- (NSString *) davContentType -{ - return @"text/calendar"; -} - - (NSString *) roleOfUser: (NSString *) login inContext: (WOContext *) context { diff --git a/SoObjects/Appointments/SOGoCalendarComponent.h b/SoObjects/Appointments/SOGoCalendarComponent.h index 637c6f67..101ebbb4 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.h +++ b/SoObjects/Appointments/SOGoCalendarComponent.h @@ -25,9 +25,11 @@ #import +@class NSArray; @class NSString; @class iCalCalendar; +@class iCalRepeatableEntityObject; @interface SOGoCalendarComponent : SOGoContentObject { @@ -36,7 +38,6 @@ /* accessors */ -- (NSString *) iCalString; - (iCalCalendar *) calendar; - (NSException *) primarySaveContentString: (NSString *) _iCalString; @@ -44,6 +45,13 @@ - (NSException *) delete; +/* mail notifications */ +- (BOOL) sendEMailNotifications; +- (void) sendEMailUsingTemplateNamed: (NSString *) _pageName + forOldObject: (iCalRepeatableEntityObject *) _oldObject + andNewObject: (iCalRepeatableEntityObject *) _newObject + toAttendees: (NSArray *) _attendees; + @end #endif /* SOGOCALENDARCOMPONENT_H */ diff --git a/SoObjects/Appointments/SOGoCalendarComponent.m b/SoObjects/Appointments/SOGoCalendarComponent.m index adb0cc80..ffae08c1 100644 --- a/SoObjects/Appointments/SOGoCalendarComponent.m +++ b/SoObjects/Appointments/SOGoCalendarComponent.m @@ -20,12 +20,47 @@ * Boston, MA 02111-1307, USA. */ +#import + #import +#import +#import +#import +#import +#import + +#import + +#import "common.h" +#import "SOGoAptMailNotification.h" #import "SOGoCalendarComponent.h" +static NSString *mailTemplateDefaultLanguage = nil; +static BOOL sendEMailNotifications = NO; + @implementation SOGoCalendarComponent ++ (void) initialize +{ + NSUserDefaults *ud; + static BOOL didInit = NO; + + if (!didInit) + { + didInit = YES; + + ud = [NSUserDefaults standardUserDefaults]; + mailTemplateDefaultLanguage = [[ud stringForKey:@"SOGoDefaultLanguage"] + retain]; + if (!mailTemplateDefaultLanguage) + mailTemplateDefaultLanguage = @"French"; + + sendEMailNotifications + = [ud boolForKey: @"SOGoAppointmentSendEMailNotifications"]; + } +} + - (id) init { if ((self = [super init])) @@ -43,10 +78,9 @@ [super dealloc]; } -- (NSString *) iCalString +- (NSString *) davContentType { - // for UI-X appointment viewer - return [self contentAsString]; + return @"text/calendar"; } - (iCalCalendar *) calendar @@ -55,7 +89,7 @@ if (!calendar) { - iCalString = [self iCalString]; + iCalString = [self contentAsString]; if (iCalString) { calendar = [iCalCalendar parseSingleFromSource: iCalString]; @@ -70,7 +104,7 @@ - (NSException *) primarySaveContentString: (NSString *) _iCalString { - return [super saveContentString:_iCalString]; + return [super saveContentString: _iCalString]; } - (NSException *) primaryDelete @@ -90,4 +124,159 @@ return [self deleteWithBaseSequence:0]; } +/* EMail Notifications */ +- (NSString *) homePageURLForPerson: (iCalPerson *) _person +{ + NSString *baseURL; + NSString *uid; + WOContext *ctx; + NSArray *traversalObjects; + + /* generate URL from traversal stack */ + ctx = [[WOApplication application] context]; + traversalObjects = [ctx objectTraversalStack]; + if ([traversalObjects count] > 0) + baseURL = [[traversalObjects objectAtIndex:0] baseURLInContext:ctx]; + else + { + baseURL = @"http://localhost/"; + [self warnWithFormat:@"Unable to create baseURL from context!"]; + } + uid = [[AgenorUserManager sharedUserManager] + getUIDForEmail: [_person rfc822Email]]; + + return ((uid) + ? [NSString stringWithFormat:@"%@%@", baseURL, uid] + : nil); +} + +- (BOOL) sendEMailNotifications +{ + return sendEMailNotifications; +} + +- (void) sendEMailUsingTemplateNamed: (NSString *) _pageName + forOldObject: (iCalRepeatableEntityObject *) _oldObject + andNewObject: (iCalRepeatableEntityObject *) _newObject + toAttendees: (NSArray *) _attendees +{ + NSString *pageName; + iCalPerson *organizer; + NSString *cn, *sender, *iCalString; + NGSendMail *sendmail; + WOApplication *app; + unsigned i, count; + iCalPerson *attendee; + NSString *recipient; + SOGoAptMailNotification *p; + NSString *subject, *text, *header; + NGMutableHashMap *headerMap; + NGMimeMessage *msg; + NGMimeBodyPart *bodyPart; + NGMimeMultipartBody *body; + + if ([_attendees count]) + { + /* sender */ + + organizer = [_newObject organizer]; + cn = [organizer cnWithoutQuotes]; + if (cn) + sender = [NSString stringWithFormat:@"%@ <%@>", + cn, + [organizer rfc822Email]]; + else + sender = [organizer rfc822Email]; + + /* generate iCalString once */ + iCalString = [[_newObject parent] versitString]; + + /* get sendmail object */ + sendmail = [NGSendMail sharedSendMail]; + + /* get WOApplication instance */ + app = [WOApplication application]; + + /* generate dynamic message content */ + + count = [_attendees count]; + for (i = 0; i < count; i++) + { + attendee = [_attendees objectAtIndex:i]; + + /* construct recipient */ + cn = [attendee cn]; + if (cn) + recipient = [NSString stringWithFormat: @"%@ <%@>", + cn, + [attendee rfc822Email]]; + else + recipient = [attendee rfc822Email]; + + /* create page name */ + // TODO: select user's default language? + pageName = [NSString stringWithFormat: @"SOGoAptMail%@%@", + mailTemplateDefaultLanguage, + _pageName]; + /* construct message content */ + p = [app pageWithName: pageName inContext: [WOContext context]]; + [p setNewApt: _newObject]; + [p setOldApt: _oldObject]; + [p setHomePageURL: [self homePageURLForPerson: attendee]]; + [p setViewTZ: [self userTimeZone: cn]]; + subject = [p getSubject]; + text = [p getBody]; + + /* construct message */ + headerMap = [NGMutableHashMap hashMapWithCapacity: 5]; + + /* NOTE: multipart/alternative seems like the correct choice but + * unfortunately Thunderbird doesn't offer the rich content alternative + * at all. Mail.app shows the rich content alternative _only_ + * so we'll stick with multipart/mixed for the time being. + */ + [headerMap setObject: @"multipart/mixed" forKey: @"content-type"]; + [headerMap setObject: sender forKey: @"From"]; + [headerMap setObject: recipient forKey: @"To"]; + [headerMap setObject: [NSCalendarDate date] forKey: @"date"]; + [headerMap setObject: subject forKey: @"Subject"]; + msg = [NGMimeMessage messageWithHeader: headerMap]; + + /* multipart body */ + body = [[NGMimeMultipartBody alloc] initWithPart: msg]; + + /* text part */ + headerMap = [NGMutableHashMap hashMapWithCapacity: 1]; + [headerMap setObject: @"text/plain; charset=utf-8" + forKey: @"content-type"]; + bodyPart = [NGMimeBodyPart bodyPartWithHeader: headerMap]; + [bodyPart setBody: [text dataUsingEncoding: NSUTF8StringEncoding]]; + + /* attach text part to multipart body */ + [body addBodyPart: bodyPart]; + + /* calendar part */ + header = [NSString stringWithFormat: @"text/calendar; method=%@;" + @" charset=utf-8", + [(iCalCalendar *) [_newObject parent] method]]; + headerMap = [NGMutableHashMap hashMapWithCapacity: 1]; + [headerMap setObject:header forKey: @"content-type"]; + bodyPart = [NGMimeBodyPart bodyPartWithHeader: headerMap]; + [bodyPart setBody: [iCalString dataUsingEncoding: NSUTF8StringEncoding]]; + + /* attach calendar part to multipart body */ + [body addBodyPart: bodyPart]; + + /* attach multipart body to message */ + [msg setBody: body]; + [body release]; + + /* send the damn thing */ + [sendmail sendMimePart: msg + toRecipients: [NSArray arrayWithObject: [attendee rfc822Email]] + sender: [organizer rfc822Email]]; + } + } +} + @end diff --git a/SoObjects/Appointments/SOGoGroupAppointmentFolder.m b/SoObjects/Appointments/SOGoGroupAppointmentFolder.m index 0295de50..c154c5b3 100644 --- a/SoObjects/Appointments/SOGoGroupAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoGroupAppointmentFolder.m @@ -19,6 +19,8 @@ 02111-1307, USA. */ +#import + #include "SOGoGroupAppointmentFolder.h" #include "common.h" diff --git a/SoObjects/Appointments/SOGoTaskObject.m b/SoObjects/Appointments/SOGoTaskObject.m index f3416c3d..775dcecf 100644 --- a/SoObjects/Appointments/SOGoTaskObject.m +++ b/SoObjects/Appointments/SOGoTaskObject.m @@ -35,22 +35,9 @@ #import "NSArray+Appointments.h" @interface SOGoTaskObject (PrivateAPI) -- (NSString *)homePageURLForPerson:(iCalPerson *)_person; - -- (void)sendEMailUsingTemplateNamed:(NSString *)_pageName - forOldTask:(iCalToDo *)_newApt - andNewTask:(iCalToDo *)_oldApt - toAttendees:(NSArray *)_attendees; - -- (void)sendInvitationEMailForTask:(iCalToDo *)_task - toAttendees:(NSArray *)_attendees; -- (void)sendTaskUpdateEMailForOldTask:(iCalToDo *)_oldApt - newTask:(iCalToDo *)_newApt - toAttendees:(NSArray *)_attendees; -- (void)sendAttendeeRemovalEMailForTask:(iCalToDo *)_task - toAttendees:(NSArray *)_attendees; -- (void)sendTaskDeletionEMailForTask:(iCalToDo *)_task - toAttendees:(NSArray *)_attendees; + +- (NSString *) homePageURLForPerson: (iCalPerson *) _person; + @end @implementation SOGoTaskObject @@ -277,7 +264,7 @@ static NSString *mailTemplateDefaultLanguage = nil; // /* handle old content */ -// oldContent = [self iCalString]; /* if nil, this is a new task */ +// oldContent = [self contentAsString]; /* if nil, this is a new task */ // if ([oldContent length] == 0) // { // /* new task */ @@ -387,7 +374,8 @@ static NSString *mailTemplateDefaultLanguage = nil; // if (delError != nil) return delError; /* email notifications */ - +// if ([self sendEMailNotifications]) +// { // attendees = [NSMutableArray arrayWithArray:[changes insertedAttendees]]; // [attendees removePerson:organizer]; // [self sendInvitationEMailForTask:newApt @@ -397,9 +385,10 @@ static NSString *mailTemplateDefaultLanguage = nil; // attendees = [NSMutableArray arrayWithArray:[newApt attendees]]; // [attendees removeObjectsInArray:[changes insertedAttendees]]; // [attendees removePerson:organizer]; -// [self sendTaskUpdateEMailForOldTask:oldApt -// newTask:newApt -// toAttendees:attendees]; +// [self sendEMailUsingTemplateNamed: @"Update" +// forOldObject: oldApt +// andNewObject: newApt +// toAttendees: attendees]; // } // attendees = [NSMutableArray arrayWithArray:[changes deletedAttendees]]; @@ -409,10 +398,14 @@ static NSString *mailTemplateDefaultLanguage = nil; // canceledApt = [newApt copy]; // [(iCalCalendar *) [canceledApt parent] setMethod: @"cancel"]; -// [self sendAttendeeRemovalEMailForTask:canceledApt -// toAttendees:attendees]; +// [self sendEMailUsingTemplateNamed: @"Removal" +// forOldObject: nil +// andNewObject: canceledApt +// toAttendees: attendees]; // [canceledApt release]; // } +// } + return nil; } @@ -447,20 +440,25 @@ static NSString *mailTemplateDefaultLanguage = nil; removedUIDs = [self attendeeUIDsFromTask:task]; - /* send notification email to attendees excluding organizer */ - attendees = [NSMutableArray arrayWithArray:[task attendees]]; - [attendees removePerson:[task organizer]]; + if ([self sendEMailNotifications]) + { + /* send notification email to attendees excluding organizer */ + attendees = [NSMutableArray arrayWithArray:[task attendees]]; + [attendees removePerson:[task organizer]]; - /* flag task as being canceled */ - [(iCalCalendar *) [task parent] setMethod: @"cancel"]; - [task increaseSequence]; + /* flag task as being canceled */ + [(iCalCalendar *) [task parent] setMethod: @"cancel"]; + [task increaseSequence]; - /* remove all attendees to signal complete removal */ - [task removeAllAttendees]; + /* remove all attendees to signal complete removal */ + [task removeAllAttendees]; - /* send notification email */ - [self sendTaskDeletionEMailForTask:task - toAttendees:attendees]; + /* send notification email */ + [self sendEMailUsingTemplateNamed: @"Deletion" + forOldObject: nil + andNewObject: task + toAttendees: attendees]; + } /* perform */ @@ -553,180 +551,4 @@ static NSString *mailTemplateDefaultLanguage = nil; return [NSString stringWithFormat:@"%@%@", baseURL, uid]; } -- (void)sendEMailUsingTemplateNamed:(NSString *)_pageName - forOldTask:(iCalToDo *)_oldApt - andNewTask:(iCalToDo *)_newApt - toAttendees:(NSArray *)_attendees -{ - NSString *pageName; - iCalPerson *organizer; - NSString *cn, *sender, *iCalString; - NGSendMail *sendmail; - WOApplication *app; - unsigned i, count; - - if (![_attendees count]) return; // another job neatly done :-) - - /* sender */ - - organizer = [_newApt organizer]; - cn = [organizer cnWithoutQuotes]; - if (cn) { - sender = [NSString stringWithFormat:@"%@ <%@>", - cn, - [organizer rfc822Email]]; - } - else { - sender = [organizer rfc822Email]; - } - - /* generate iCalString once */ - iCalString = [[_newApt parent] versitString]; - - /* get sendmail object */ - sendmail = [NGSendMail sharedSendMail]; - - /* get WOApplication instance */ - app = [WOApplication application]; - - /* generate dynamic message content */ - - count = [_attendees count]; - for (i = 0; i < count; i++) { - iCalPerson *attendee; - NSString *recipient; - SOGoAptMailNotification *p; - NSString *subject, *text, *header; - NGMutableHashMap *headerMap; - NGMimeMessage *msg; - NGMimeBodyPart *bodyPart; - NGMimeMultipartBody *body; - - attendee = [_attendees objectAtIndex:i]; - - /* construct recipient */ - cn = [attendee cn]; - if (cn) { - recipient = [NSString stringWithFormat:@"%@ <%@>", - cn, - [attendee rfc822Email]]; - } - else { - recipient = [attendee rfc822Email]; - } - - /* create page name */ - // TODO: select user's default language? - pageName = [NSString stringWithFormat:@"SOGoAptMail%@%@", - mailTemplateDefaultLanguage, - _pageName]; - /* construct message content */ - p = [app pageWithName:pageName inContext:[WOContext context]]; - [p setNewApt: _newApt]; - [p setOldApt: _oldApt]; - [p setHomePageURL:[self homePageURLForPerson:attendee]]; - [p setViewTZ: [self userTimeZone: cn]]; - subject = [p getSubject]; - text = [p getBody]; - - /* construct message */ - headerMap = [NGMutableHashMap hashMapWithCapacity:5]; - - /* NOTE: multipart/alternative seems like the correct choice but - * unfortunately Thunderbird doesn't offer the rich content alternative - * at all. Mail.app shows the rich content alternative _only_ - * so we'll stick with multipart/mixed for the time being. - */ - [headerMap setObject:@"multipart/mixed" forKey:@"content-type"]; - [headerMap setObject:sender forKey:@"From"]; - [headerMap setObject:recipient forKey:@"To"]; - [headerMap setObject:[NSCalendarDate date] forKey:@"date"]; - [headerMap setObject:subject forKey:@"Subject"]; - msg = [NGMimeMessage messageWithHeader:headerMap]; - - /* multipart body */ - body = [[NGMimeMultipartBody alloc] initWithPart:msg]; - - /* text part */ - headerMap = [NGMutableHashMap hashMapWithCapacity:1]; - [headerMap setObject:@"text/plain; charset=utf-8" forKey:@"content-type"]; - bodyPart = [NGMimeBodyPart bodyPartWithHeader:headerMap]; - [bodyPart setBody:[text dataUsingEncoding:NSUTF8StringEncoding]]; - - /* attach text part to multipart body */ - [body addBodyPart:bodyPart]; - - /* calendar part */ - header = [NSString stringWithFormat:@"text/calendar; method=%@;" - @" charset=utf-8", - [(iCalCalendar *) [_newApt parent] method]]; - headerMap = [NGMutableHashMap hashMapWithCapacity:1]; - [headerMap setObject:header forKey:@"content-type"]; - bodyPart = [NGMimeBodyPart bodyPartWithHeader:headerMap]; - [bodyPart setBody:[iCalString dataUsingEncoding:NSUTF8StringEncoding]]; - - /* attach calendar part to multipart body */ - [body addBodyPart:bodyPart]; - - /* attach multipart body to message */ - [msg setBody:body]; - [body release]; - - /* send the damn thing */ - [sendmail sendMimePart:msg - toRecipients:[NSArray arrayWithObject:[attendee rfc822Email]] - sender:[organizer rfc822Email]]; - } -} - -- (void)sendInvitationEMailForTask:(iCalToDo *)_task - toAttendees:(NSArray *)_attendees -{ - if (![_attendees count]) return; // another job neatly done :-) - - [self sendEMailUsingTemplateNamed:@"Invitation" - forOldTask:nil - andNewTask:_task - toAttendees:_attendees]; -} - -- (void)sendTaskUpdateEMailForOldTask:(iCalToDo *)_oldApt - newTask:(iCalToDo *)_newApt - toAttendees:(NSArray *)_attendees -{ - if (![_attendees count]) return; - - [self sendEMailUsingTemplateNamed:@"Update" - forOldTask:_oldApt - andNewTask:_newApt - toAttendees:_attendees]; -} - -- (void) sendAttendeeRemovalEMailForTask:(iCalToDo *)_task - toAttendees:(NSArray *)_attendees -{ - if (![_attendees count]) return; - - [self sendEMailUsingTemplateNamed:@"Removal" - forOldTask:nil - andNewTask:_task - toAttendees:_attendees]; -} - -- (void) sendTaskDeletionEMailForTask: (iCalToDo *) _task - toAttendees: (NSArray *) _attendees -{ - if (![_attendees count]) return; - - [self sendEMailUsingTemplateNamed:@"Deletion" - forOldTask:nil - andNewTask:_task - toAttendees:_attendees]; -} - -- (NSString *) davContentType -{ - return @"text/calendar"; -} - @end /* SOGoTaskObject */ diff --git a/SoObjects/common.make b/SoObjects/common.make index 3684a1e4..fbedc517 100644 --- a/SoObjects/common.make +++ b/SoObjects/common.make @@ -19,7 +19,8 @@ ADDITIONAL_INCLUDE_DIRS += \ ADDITIONAL_LIB_DIRS += \ -L../SOGo/$(GNUSTEP_OBJ_DIR)/ \ -L../../SOGo/$(GNUSTEP_OBJ_DIR)/ \ - -L../../OGoContentStore/$(GNUSTEP_OBJ_DIR)/ + -L../../OGoContentStore/$(GNUSTEP_OBJ_DIR)/ \ + -L/usr/local/lib BUNDLE_LIBS += \ -lSOGo \ diff --git a/UI/Common/UIxAclEditor.m b/UI/Common/UIxAclEditor.m index 7b00e62d..b6917d56 100644 --- a/UI/Common/UIxAclEditor.m +++ b/UI/Common/UIxAclEditor.m @@ -21,6 +21,7 @@ */ #import +#import #import #import #import -- 2.39.5