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
This commit is contained in:
Jean Raby
2013-08-27 13:12:03 -04:00
parent be531100c6
commit e6ab0a590a
2 changed files with 54 additions and 3 deletions
+3
View File
@@ -25,8 +25,11 @@
#import <Foundation/NSObject.h>
#import <SOGo/SOGoStaticAuthenticator.h>
@interface SOGoEAlarmsNotifier : NSObject
{
SOGoStaticAuthenticator *staticAuthenticator;
}
- (BOOL) run;
+51 -3
View File
@@ -27,6 +27,7 @@
#import <Foundation/NSDictionary.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSString.h>
#import <Foundation/NSUserDefaults.h>
#import <NGExtensions/NGHashMap.h>
#import <NGExtensions/NGQuotedPrintableCoding.h>
@@ -38,12 +39,14 @@
#import <NGCards/iCalEntityObject.h>
#import <NGCards/iCalPerson.h>
#import "SOGo/SOGoCredentialsFile.h"
#import <SOGo/NSCalendarDate+SOGo.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoMailer.h>
#import <SOGo/SOGoProductLoader.h>
#import <SOGo/SOGoStaticAuthenticator.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUser.h>
#import <Appointments/iCalPerson+SOGo.h>
#import <Appointments/SOGoEMailAlarmsManager.h>
@@ -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"]];