feat(accounts): Can now add smtp server to auxilliary accounts

This commit is contained in:
Hivert Quentin
2024-02-01 16:55:41 +01:00
parent 59bd290d62
commit f0010afef4
13 changed files with 293 additions and 48 deletions
+26 -9
View File
@@ -2278,7 +2278,7 @@ static NSString *userAgent = nil;
NSData *message, *messageForSent;
SOGoMailFolder *sentFolder;
SOGoDomainDefaults *dd;
NSURL *sourceIMAP4URL;
NSURL *sourceIMAP4URL, *smtpUrl;
NSException *error;
dd = [[context activeUser] domainDefaults];
@@ -2307,13 +2307,28 @@ static NSString *userAgent = nil;
return [NSException exceptionWithHTTPStatus: 500
reason: @"could not generate message content"];
error = [[SOGoMailer mailerWithDomainDefaults: dd]
sendMailData: message
toRecipients: [NSArray arrayWithObject: recipient]
sender: [self sender]
withAuthenticator: [self authenticatorInContext: context]
inContext: context
systemMessage: NO];
smtpUrl = [self smtp4URL];
if (smtpUrl)
{
error = [[SOGoMailer mailerWithDomainDefaultsAndSmtpUrl: dd smtpUrl: smtpUrl]
sendMailData: message
toRecipients: [NSArray arrayWithObject: recipient]
sender: [self sender]
withAuthenticator: [self authenticatorInContext: context]
inContext: context
systemMessage: NO];
}
else
{
error = [[SOGoMailer mailerWithDomainDefaults: dd]
sendMailData: message
toRecipients: [NSArray arrayWithObject: recipient]
sender: [self sender]
withAuthenticator: [self authenticatorInContext: context]
inContext: context
systemMessage: NO];
}
if (error) {
[self cleanTmpFiles];
@@ -2335,7 +2350,9 @@ static NSString *userAgent = nil;
return [NSException exceptionWithHTTPStatus: 500
reason: @"could not generate message content"];
error = [[SOGoMailer mailerWithDomainDefaults: dd]
smtpUrl = [self smtp4URL];
error = [[SOGoMailer mailerWithDomainDefaultsAndSmtpUrl: dd smtpUrl: smtpUrl]
sendMailData: message
toRecipients: [self allBareRecipients]
sender: [self sender]
+3
View File
@@ -95,7 +95,10 @@ typedef enum {
- (NSDictionary *) identityForEmail: (NSString *) email;
- (NSString *) signature;
- (NSString *) encryption;
- (NSString *) smtpEncryption;
- (NSString *) tlsVerifyMode;
- (NSString *) smtpTlsVerifyMode;
- (NSMutableString *) smtp4URLString;
/* folder pathes */
- (NSArray *) toManyRelationshipKeysWithNamespaces: (BOOL) withNSs;
+58
View File
@@ -800,6 +800,17 @@ static NSString *inboxFolderName = @"INBOX";
return encryption;
}
- (NSString *) smtpEncryption
{
NSString *encryption;
encryption = [[self _mailAccount] objectForKey: @"smtpEncryption"];
if (![encryption length])
encryption = @"none";
return encryption;
}
- (NSString *) tlsVerifyMode
{
NSString *verifyMode;
@@ -811,6 +822,17 @@ static NSString *inboxFolderName = @"INBOX";
return verifyMode;
}
- (NSString *) smtpTlsVerifyMode
{
NSString *verifyMode;
verifyMode = [[self _mailAccount] objectForKey: @"smtpTlsVerifyMode"];
if (!verifyMode || ![verifyMode length])
verifyMode = @"default";
return verifyMode;
}
- (NSMutableString *) imap4URLString
{
NSMutableString *imap4URLString;
@@ -849,6 +871,42 @@ static NSString *inboxFolderName = @"INBOX";
return imap4URLString;
}
- (NSMutableString *) smtp4URLString
{
NSMutableString *smtp4URLString;
NSDictionary *mailAccount;
NSString *encryption, *protocol, *smtpServerName;
int defaultPort, port;
mailAccount = [self _mailAccount];
smtpServerName = [mailAccount objectForKey: @"smtpServerName"];
if(!smtpServerName)
return nil; //Auxiliary account can be only configured for imap and not smtp
encryption = [mailAccount objectForKey: @"smtpEncryption"];
defaultPort = 25;
protocol = @"smtp";
if ([encryption isEqualToString: @"ssl"])
{
protocol = @"smtps";
defaultPort = 465;
}
else if ([encryption isEqualToString: @"tls"])
{
protocol = @"smtps";
defaultPort = 465;
}
smtp4URLString = [NSMutableString stringWithFormat: @"%@://%@", protocol, smtpServerName];
port = [[mailAccount objectForKey: @"smtpPort"] intValue];
if (port && port != defaultPort)
[smtp4URLString appendFormat: @":%d", port];
[smtp4URLString appendString: @"/"];
return smtp4URLString;
}
- (NSMutableString *) traversalFromMailAccount
{
return [NSMutableString string];
+2
View File
@@ -46,6 +46,7 @@
@interface SOGoMailBaseObject : SOGoObject
{
NSURL *imap4URL;
NSURL *smtp4URL;
NGImap4Connection *imap4;
BOOL imap4ExceptionsEnabled;
}
@@ -74,6 +75,7 @@
- (NSMutableString *) traversalFromMailAccount;
- (NSURL *) imap4URL;
- (NSURL *) smtp4URL;
- (NSString *) imap4PasswordRenewed: (BOOL) renew;
- (void) flushMailCaches;
+30
View File
@@ -71,6 +71,7 @@
- (void) dealloc
{
[imap4URL release];
[smtp4URL release];
[imap4 release];
[super dealloc];
}
@@ -317,6 +318,35 @@
return imap4URL;
}
- (NSURL *) smtp4URL
{
SOGoMailAccount *account;
NSString *urlString, *smtpUrl;
NSString *useTls = @"NO";
/* this could probably be handled better from NSURL but it's buggy in
GNUstep */
if (!smtp4URL)
{
account = [self mailAccountFolder];
smtpUrl = [account smtp4URLString];
if(smtpUrl)
{
if ([[account smtpEncryption] isEqualToString: @"tls"])
{
useTls = @"YES";
}
urlString = [NSString stringWithFormat: @"%@?tls=%@&tlsVerifyMode=%@",
smtpUrl, useTls, [account smtpTlsVerifyMode]];
smtp4URL = [[NSURL alloc] initWithString: urlString];
}
else
smtp4URL = nil;
}
return smtp4URL;
}
- (NSString *) imap4PasswordRenewed: (BOOL) renewed
{
return [[self mailAccountFolder] imap4PasswordRenewed: renewed];