From e6ab0a590a7776331270f02a83cd123d41f14c1f Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Tue, 27 Aug 2013 13:12:03 -0400 Subject: [PATCH] Support using SMTP AUTH creds for email alarms Credentials must be supplied using '-p /path/to/credsFile'. The credentials file should contain a single line with the format 'user:pass' While there, add a usage message --- Tools/SOGoEAlarmsNotifier.h | 3 +++ Tools/SOGoEAlarmsNotifier.m | 54 ++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Tools/SOGoEAlarmsNotifier.h b/Tools/SOGoEAlarmsNotifier.h index 8cd964d9f..692b5260d 100644 --- a/Tools/SOGoEAlarmsNotifier.h +++ b/Tools/SOGoEAlarmsNotifier.h @@ -25,8 +25,11 @@ #import +#import + @interface SOGoEAlarmsNotifier : NSObject { + SOGoStaticAuthenticator *staticAuthenticator; } - (BOOL) run; diff --git a/Tools/SOGoEAlarmsNotifier.m b/Tools/SOGoEAlarmsNotifier.m index 29cfff8fd..81de6528d 100644 --- a/Tools/SOGoEAlarmsNotifier.m +++ b/Tools/SOGoEAlarmsNotifier.m @@ -27,6 +27,7 @@ #import #import #import +#import #import #import @@ -38,12 +39,14 @@ #import #import +#import "SOGo/SOGoCredentialsFile.h" #import #import #import -#import #import #import +#import +#import #import #import #import @@ -52,6 +55,21 @@ @implementation SOGoEAlarmsNotifier +- (id) init +{ + if ((self = [super init])) + { + staticAuthenticator = nil; + } + return self; +} + +- (void) dealloc +{ + [staticAuthenticator release]; + [super dealloc]; +} + - (NSString *) _messageID { static int pid = 0; @@ -124,11 +142,10 @@ [message setBody: content]; to = [attendee rfc822Email]; - /* TODO: SMTP authentication for services */ [mailer sendMimePart: message toRecipients: [NSArray arrayWithObject: to] sender: from - withAuthenticator: nil inContext: nil]; + withAuthenticator: staticAuthenticator inContext: nil]; } - (void) _processAlarm: (iCalAlarm *) alarm @@ -160,14 +177,45 @@ withMailer: mailer]; } +- (void) usage +{ + fprintf (stderr, "sogo-ealarms-notify [-p credentialFile] [-h]\n\n" + " -p credentialFile Specify the file containing credentials to use for SMTP AUTH\n" + " The file should contain a single line:\n" + " username:password\n" + " -h This message\n" + "\n" + "This program should be configured to run every minute from a crontab.\n"); +} + - (BOOL) run { SOGoEMailAlarmsManager *eaMgr; + SOGoCredentialsFile *cf; NSCalendarDate *startDate, *toDate; NSArray *alarms; NSMutableArray *owners; + NSString *credsFilename; int count, max; + if ([[NSUserDefaults standardUserDefaults] stringForKey: @"h"]) + { + [self usage]; + return YES; + } + + credsFilename = [[NSUserDefaults standardUserDefaults] stringForKey: @"p"]; + if (credsFilename) + { + cf = [SOGoCredentialsFile credentialsFromFile: credsFilename]; + if (!cf) + return NO; + staticAuthenticator = + [SOGoStaticAuthenticator authenticatorWithUser: [cf username] + andPassword: [cf password]]; + [staticAuthenticator retain]; + } + [[SOGoProductLoader productLoader] loadProducts: [NSArray arrayWithObject: @"Appointments.SOGo"]];