(fix) email alarms are sent too many times (fixes #4100)
parent
5fd8c9d2d0
commit
a86f8a8a0a
1
NEWS
1
NEWS
|
@ -21,6 +21,7 @@ Bug fixes
|
||||||
- [web] fixed responsive condition of login page (960px to 1023px)
|
- [web] fixed responsive condition of login page (960px to 1023px)
|
||||||
- [core] newly subscribed calendars are excluded from freebusy (#3354)
|
- [core] newly subscribed calendars are excluded from freebusy (#3354)
|
||||||
- [core] strip cr during LDIF import process (#4172)
|
- [core] strip cr during LDIF import process (#4172)
|
||||||
|
- [core] email alarms are sent too many times (#4100)
|
||||||
|
|
||||||
3.2.9 (2017-05-09)
|
3.2.9 (2017-05-09)
|
||||||
------------------
|
------------------
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* iCalAlarm+SOGo.h - this file is part of SOGo
|
/* iCalAlarm+SOGo.h - this file is part of SOGo
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Inverse inc.
|
* Copyright (C) 2015-2017 Inverse inc.
|
||||||
*
|
*
|
||||||
* This file is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
#import <NGCards/iCalAlarm.h>
|
#import <NGCards/iCalAlarm.h>
|
||||||
|
|
||||||
@class iCalEntityObject;
|
@class iCalEntityObject;
|
||||||
|
@class SOGoUser;
|
||||||
|
|
||||||
@interface iCalAlarm (SOGoExtensions)
|
@interface iCalAlarm (SOGoExtensions)
|
||||||
|
|
||||||
|
@ -34,4 +35,6 @@
|
||||||
emailAttendees: (BOOL) reminderEmailAttendees
|
emailAttendees: (BOOL) reminderEmailAttendees
|
||||||
emailOrganizer: (BOOL) reminderEmailOrganizer;
|
emailOrganizer: (BOOL) reminderEmailOrganizer;
|
||||||
|
|
||||||
|
- (BOOL) userIsAttendee: (SOGoUser *) user;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* iCalAlarm+SOGo.m - this file is part of SOGo
|
/* iCalAlarm+SOGo.m - this file is part of SOGo
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Inverse inc.
|
* Copyright (C) 2015-2017 Inverse inc.
|
||||||
*
|
*
|
||||||
* This file is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -125,4 +125,24 @@
|
||||||
return AUTORELEASE(anAlarm);
|
return AUTORELEASE(anAlarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) userIsAttendee: (SOGoUser *) user
|
||||||
|
{
|
||||||
|
NSEnumerator *attendees;
|
||||||
|
iCalPerson *currentAttendee;
|
||||||
|
BOOL isAttendee;
|
||||||
|
|
||||||
|
isAttendee = NO;
|
||||||
|
|
||||||
|
attendees = [[self attendees] objectEnumerator];
|
||||||
|
currentAttendee = [attendees nextObject];
|
||||||
|
while (!isAttendee
|
||||||
|
&& currentAttendee)
|
||||||
|
if ([user hasEmail: [currentAttendee rfc822Email]])
|
||||||
|
isAttendee = YES;
|
||||||
|
else
|
||||||
|
currentAttendee = [attendees nextObject];
|
||||||
|
|
||||||
|
return isAttendee;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -690,6 +690,7 @@ NSNumber *iCalDistantFutureNumber = nil;
|
||||||
{
|
{
|
||||||
NSCalendarDate *nextAlarmDate;
|
NSCalendarDate *nextAlarmDate;
|
||||||
GCSAlarmsFolder *af;
|
GCSAlarmsFolder *af;
|
||||||
|
SOGoUser *alarmOwner;
|
||||||
NSString *path;
|
NSString *path;
|
||||||
|
|
||||||
int email_alarm_number;
|
int email_alarm_number;
|
||||||
|
@ -698,11 +699,13 @@ NSNumber *iCalDistantFutureNumber = nil;
|
||||||
{
|
{
|
||||||
af = [[GCSFolderManager defaultFolderManager] alarmsFolder];
|
af = [[GCSFolderManager defaultFolderManager] alarmsFolder];
|
||||||
path = [theContainer ocsPath];
|
path = [theContainer ocsPath];
|
||||||
|
alarmOwner = [SOGoUser userWithLogin: [[path componentsSeparatedByString: @"/"] objectAtIndex: 2]];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
af = nil;
|
af = nil;
|
||||||
path = nil;
|
path = nil;
|
||||||
|
alarmOwner = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
nextAlarmDate = nil;
|
nextAlarmDate = nil;
|
||||||
|
@ -736,7 +739,8 @@ NSNumber *iCalDistantFutureNumber = nil;
|
||||||
email_alarm_number = [[self alarms] indexOfObject: anAlarm];
|
email_alarm_number = [[self alarms] indexOfObject: anAlarm];
|
||||||
|
|
||||||
// The email alarm is too old, let's just remove it
|
// The email alarm is too old, let's just remove it
|
||||||
if ([nextAlarmDate earlierDate: [NSDate date]] == nextAlarmDate)
|
if ([nextAlarmDate earlierDate: [NSDate date]] == nextAlarmDate ||
|
||||||
|
![anAlarm userIsAttendee: alarmOwner])
|
||||||
nextAlarmDate = nil;
|
nextAlarmDate = nil;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -831,16 +835,20 @@ NSNumber *iCalDistantFutureNumber = nil;
|
||||||
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue]];
|
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue]];
|
||||||
}
|
}
|
||||||
else if ((anAlarm = [self firstEmailAlarm]) && af)
|
else if ((anAlarm = [self firstEmailAlarm]) && af)
|
||||||
|
|
||||||
{
|
{
|
||||||
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue]];
|
nextAlarmDate = [NSDate dateWithTimeIntervalSince1970: [[[alarms objectAtIndex: i] objectForKey: @"c_nextalarm"] intValue]];
|
||||||
email_alarm_number = [[self alarms] indexOfObject: anAlarm];
|
email_alarm_number = [[self alarms] indexOfObject: anAlarm];
|
||||||
|
|
||||||
|
if ([anAlarm userIsAttendee: alarmOwner])
|
||||||
[af writeRecordForEntryWithCName: nameInContainer
|
[af writeRecordForEntryWithCName: nameInContainer
|
||||||
inCalendarAtPath: path
|
inCalendarAtPath: path
|
||||||
forUID: [self uid]
|
forUID: [self uid]
|
||||||
recurrenceId: [self recurrenceId]
|
recurrenceId: [self recurrenceId]
|
||||||
alarmNumber: [NSNumber numberWithInt: email_alarm_number]
|
alarmNumber: [NSNumber numberWithInt: email_alarm_number]
|
||||||
andAlarmDate: nextAlarmDate];
|
andAlarmDate: nextAlarmDate];
|
||||||
|
else
|
||||||
|
nextAlarmDate = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,28 +124,22 @@
|
||||||
|
|
||||||
- (void) _sendMessageWithHeaders: (NGMutableHashMap *) headers
|
- (void) _sendMessageWithHeaders: (NGMutableHashMap *) headers
|
||||||
content: (NSData *) content
|
content: (NSData *) content
|
||||||
toAttendee: (iCalPerson *) attendee
|
to: (NSDictionary *) to
|
||||||
from: (NSString *) from
|
|
||||||
withMailer: (SOGoMailer *) mailer
|
withMailer: (SOGoMailer *) mailer
|
||||||
{
|
{
|
||||||
NGMimeMessage *message;
|
NGMimeMessage *message;
|
||||||
NSString *to, *headerTo, *attendeeName;
|
NSString *headerTo;
|
||||||
|
|
||||||
attendeeName = [attendee cnWithoutQuotes];
|
headerTo = [NSString stringWithFormat: @"%@ <%@>", [to objectForKey: @"fullName"],
|
||||||
if ([attendeeName length])
|
[to objectForKey: @"email"]];
|
||||||
headerTo = [NSString stringWithFormat: @"%@ <%@>", attendeeName,
|
|
||||||
[attendee rfc822Email]];
|
|
||||||
else
|
|
||||||
headerTo = [attendee rfc822Email];
|
|
||||||
[headers setObject: headerTo forKey: @"To"];
|
[headers setObject: headerTo forKey: @"To"];
|
||||||
[headers setObject: [self _messageID] forKey: @"Message-Id"];
|
[headers setObject: [self _messageID] forKey: @"Message-Id"];
|
||||||
message = [NGMimeMessage messageWithHeader: headers];
|
message = [NGMimeMessage messageWithHeader: headers];
|
||||||
[message setBody: content];
|
[message setBody: content];
|
||||||
to = [attendee rfc822Email];
|
|
||||||
|
|
||||||
[mailer sendMimePart: message
|
[mailer sendMimePart: message
|
||||||
toRecipients: [NSArray arrayWithObject: to]
|
toRecipients: [NSArray arrayWithObject: [to objectForKey: @"email"]]
|
||||||
sender: from
|
sender: [to objectForKey: @"email"]
|
||||||
withAuthenticator: staticAuthenticator inContext: nil];
|
withAuthenticator: staticAuthenticator inContext: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,11 +148,10 @@
|
||||||
andContainerPath: (NSString *) containerPath
|
andContainerPath: (NSString *) containerPath
|
||||||
{
|
{
|
||||||
NGMutableHashMap *headers;
|
NGMutableHashMap *headers;
|
||||||
NSArray *attendees, *parts;
|
NSArray *parts;
|
||||||
NSData *content, *qpContent;
|
NSData *content, *qpContent;
|
||||||
int count, max;
|
|
||||||
SOGoMailer *mailer;
|
SOGoMailer *mailer;
|
||||||
NSString *from, *subject;
|
NSString *subject;
|
||||||
SOGoUser *owner;
|
SOGoUser *owner;
|
||||||
|
|
||||||
WOContext *localContext;
|
WOContext *localContext;
|
||||||
|
@ -171,7 +164,6 @@
|
||||||
SOGoAppointmentFolder *folder;
|
SOGoAppointmentFolder *folder;
|
||||||
SOGoUserFolder *userFolder;
|
SOGoUserFolder *userFolder;
|
||||||
|
|
||||||
|
|
||||||
owner = [SOGoUser userWithLogin: ownerId];
|
owner = [SOGoUser userWithLogin: ownerId];
|
||||||
mailer = [SOGoMailer mailerWithDomainDefaults: [owner domainDefaults]];
|
mailer = [SOGoMailer mailerWithDomainDefaults: [owner domainDefaults]];
|
||||||
|
|
||||||
|
@ -209,15 +201,9 @@
|
||||||
|
|
||||||
headers = [self _headersForAlarm: alarm withOwner: owner withSubject: subject];
|
headers = [self _headersForAlarm: alarm withOwner: owner withSubject: subject];
|
||||||
qpContent = [content dataByEncodingQuotedPrintable];
|
qpContent = [content dataByEncodingQuotedPrintable];
|
||||||
from = [[owner primaryIdentity] objectForKey: @"email"];
|
|
||||||
|
|
||||||
attendees = [alarm attendees];
|
|
||||||
max = [attendees count];
|
|
||||||
for (count = 0; count < max; count++)
|
|
||||||
[self _sendMessageWithHeaders: headers
|
[self _sendMessageWithHeaders: headers
|
||||||
content: qpContent
|
content: qpContent
|
||||||
toAttendee: [attendees objectAtIndex: count]
|
to: [owner primaryIdentity]
|
||||||
from: from
|
|
||||||
withMailer: mailer];
|
withMailer: mailer];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue