Merge pull request #241 from zentyal/fail-on-broken-imap
Allow exception raising when connecting to IMAP
This commit is contained in:
commit
46bffaa449
|
@ -172,6 +172,11 @@ sogo_backend_init (void)
|
||||||
|
|
||||||
/* We force the plugin to base its configuration on the SOGo tree. */
|
/* We force the plugin to base its configuration on the SOGo tree. */
|
||||||
ud = [NSUserDefaults standardUserDefaults];
|
ud = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
||||||
|
/* Ensure imap4Connection calls raise Exception if
|
||||||
|
IMAP connection is not established. See NGImap4Connection.m */
|
||||||
|
[ud setBool: YES forKey: @"SoIMAP4ExceptionsEnabled"];
|
||||||
|
|
||||||
if (!leakDebugging && [ud boolForKey: @"SOGoDebugLeaks"])
|
if (!leakDebugging && [ud boolForKey: @"SOGoDebugLeaks"])
|
||||||
{
|
{
|
||||||
NSLog (@" leak debugging on");
|
NSLog (@" leak debugging on");
|
||||||
|
|
|
@ -46,10 +46,13 @@
|
||||||
{
|
{
|
||||||
NSURL *imap4URL;
|
NSURL *imap4URL;
|
||||||
NGImap4Connection *imap4;
|
NGImap4Connection *imap4;
|
||||||
|
BOOL imap4ExceptionsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isFolderish;
|
- (BOOL) isFolderish;
|
||||||
|
|
||||||
|
- (id) init;
|
||||||
|
|
||||||
- (id) initWithImap4URL: (NSURL *) _url
|
- (id) initWithImap4URL: (NSURL *) _url
|
||||||
inContainer: (id) _container;
|
inContainer: (id) _container;
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,20 @@
|
||||||
|
|
||||||
@implementation SOGoMailBaseObject
|
@implementation SOGoMailBaseObject
|
||||||
|
|
||||||
|
|
||||||
|
- (id)init
|
||||||
|
{
|
||||||
|
if ((self = [super init]))
|
||||||
|
{
|
||||||
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
||||||
|
// With this to YES, imap4Connection will raise exception if a working
|
||||||
|
// connection cannot be provided
|
||||||
|
imap4ExceptionsEnabled = [ud boolForKey:@"SoIMAP4ExceptionsEnabled"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (id) initWithImap4URL: (NSURL *) _url
|
- (id) initWithImap4URL: (NSURL *) _url
|
||||||
inContainer: (id) _container
|
inContainer: (id) _container
|
||||||
{
|
{
|
||||||
|
@ -148,7 +162,10 @@
|
||||||
if (!newConnection)
|
if (!newConnection)
|
||||||
{
|
{
|
||||||
newConnection = (NGImap4Connection *) [NSNull null];
|
newConnection = (NGImap4Connection *) [NSNull null];
|
||||||
[self errorWithFormat:@"Could not connect IMAP4"];
|
if (imap4ExceptionsEnabled)
|
||||||
|
[NSException raise: @"IOException" format: @"IMAP connection failed"];
|
||||||
|
else
|
||||||
|
[self errorWithFormat:@"Could not connect IMAP4"];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -206,6 +223,22 @@
|
||||||
[imap4 retain];
|
[imap4 retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Connection broken, try to reconnect
|
||||||
|
if (![imap4 isKindOfClass: [NSNull class]] && ![[[imap4 client] isConnected] boolValue])
|
||||||
|
{
|
||||||
|
[self warnWithFormat: @"IMAP connection is broken, trying to reconnect..."];
|
||||||
|
[[imap4 client] reconnect];
|
||||||
|
|
||||||
|
// Still broken, give up
|
||||||
|
if (![[[imap4 client] isConnected] boolValue])
|
||||||
|
{
|
||||||
|
if (imap4ExceptionsEnabled)
|
||||||
|
[NSException raise: @"IOException" format: @"IMAP connection failed"];
|
||||||
|
else
|
||||||
|
[self errorWithFormat: @"Could not get a valid IMAP connection"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [imap4 isKindOfClass: [NSNull class]] ? nil : imap4;
|
return [imap4 isKindOfClass: [NSNull class]] ? nil : imap4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue