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

This commit is contained in:
Hivert Quentin
2024-02-08 17:07:25 +01:00
parent f5cd67972b
commit adc2d74e54
9 changed files with 87 additions and 52 deletions
+22 -7
View File
@@ -2280,9 +2280,11 @@ static NSString *userAgent = nil;
SOGoDomainDefaults *dd;
NSURL *sourceIMAP4URL, *smtpUrl;
NSException *error;
NSString *userId;
dd = [[context activeUser] domainDefaults];
messageForSent = nil;
userId = [[self->container mailAccountFolder] nameInContainer];
// If we are encrypting mails, let's generate and
// send them individually
@@ -2311,7 +2313,7 @@ static NSString *userAgent = nil;
if (smtpUrl)
{
error = [[SOGoMailer mailerWithDomainDefaultsAndSmtpUrl: dd smtpUrl: smtpUrl]
error = [[SOGoMailer mailerWithDomainDefaultsAndSmtpUrl: dd smtpUrl: smtpUrl userIdAccount: userId]
sendMailData: message
toRecipients: [NSArray arrayWithObject: recipient]
sender: [self sender]
@@ -2352,13 +2354,26 @@ static NSString *userAgent = nil;
smtpUrl = [self smtp4URL];
error = [[SOGoMailer mailerWithDomainDefaultsAndSmtpUrl: dd smtpUrl: smtpUrl]
sendMailData: message
toRecipients: [self allBareRecipients]
sender: [self sender]
if (smtpUrl)
{
error = [[SOGoMailer mailerWithDomainDefaultsAndSmtpUrl: dd smtpUrl: smtpUrl userIdAccount: userId]
sendMailData: message
toRecipients: [self allBareRecipients]
sender: [self sender]
withAuthenticator: [self authenticatorInContext: context]
inContext: context
systemMessage: NO];
inContext: context
systemMessage: NO];
}
else
{
error = [[SOGoMailer mailerWithDomainDefaults: dd]
sendMailData: message
toRecipients: [self allBareRecipients]
sender: [self sender]
withAuthenticator: [self authenticatorInContext: context]
inContext: context
systemMessage: NO];
}
}
if (!error && copyToSent)
+4 -1
View File
@@ -40,11 +40,14 @@
NSString *smtpMasterUserUsername;
NSString *smtpMasterUserPassword;
NSString *authenticationType;
NSString* userIdAccount;
}
+ (SOGoMailer *) mailerWithDomainDefaults: (SOGoDomainDefaults *) dd;
+ (SOGoMailer *) mailerWithDomainDefaultsAndSmtpUrl: (SOGoDomainDefaults *) dd
smtpUrl: (NSURL *) smtpUrl;
smtpUrl: (NSURL *) smtpUrl
userIdAccount: (NSString *) userIdAccount;
- (id) initWithDomainDefaults: (SOGoDomainDefaults *) dd;
- (BOOL) requiresAuthentication;
+44 -12
View File
@@ -150,9 +150,11 @@
+ (SOGoMailer *) mailerWithDomainDefaultsAndSmtpUrl: (SOGoDomainDefaults *) dd
smtpUrl: (NSURL *) smtpUrl
userIdAccount: (NSString *) _userIdAccount
{
return [[self alloc] initWithDomainDefaultsAndSmtpUrl: dd
smtpUrl: smtpUrl];
smtpUrl: smtpUrl
userIdAccount: _userIdAccount];
}
- (id) initWithDomainDefaults: (SOGoDomainDefaults *) dd
@@ -165,6 +167,7 @@
ASSIGN (smtpMasterUserUsername, [dd smtpMasterUserUsername]);
ASSIGN (smtpMasterUserPassword, [dd smtpMasterUserPassword]);
ASSIGN (authenticationType, [[dd smtpAuthenticationType] lowercaseString]);
ASSIGN (userIdAccount, @"0");
}
return self;
@@ -172,6 +175,7 @@
- (id) initWithDomainDefaultsAndSmtpUrl: (SOGoDomainDefaults *) dd
smtpUrl: (NSURL *) smtpUrl
userIdAccount: (NSString *) _userIdAccount
{
if ((self = [self init]))
{
@@ -181,6 +185,7 @@
ASSIGN (smtpMasterUserUsername, [dd smtpMasterUserUsername]);
ASSIGN (smtpMasterUserPassword, [dd smtpMasterUserPassword]);
ASSIGN (authenticationType, [[dd smtpAuthenticationType] lowercaseString]);
ASSIGN (userIdAccount, _userIdAccount);
}
return self;
@@ -196,6 +201,7 @@
smtpMasterUserUsername = nil;
smtpMasterUserPassword = nil;
authenticationType = nil;
userIdAccount = nil;
}
return self;
@@ -208,6 +214,7 @@
[smtpMasterUserUsername release];
[smtpMasterUserPassword release];
[authenticationType release];
[userIdAccount release];
[super dealloc];
}
@@ -259,35 +266,58 @@
systemMessage: (BOOL) isSystemMessage
{
NSString *currentTo, *login, *password;
NSDictionary *currentAcount;
NSMutableArray *toErrors;
NSEnumerator *addresses;
NGSmtpClient *client;
NSException *result;
NSURL * smtpUrl;
SOGoUser* user;
BOOL doSmtpAuth;
result = nil;
doSmtpAuth = NO;
//find the smtpurl for the account
smtpUrl = [[[NSURL alloc] initWithString: smtpServer] autorelease];
client = [NGSmtpClient clientWithURL: smtpUrl];
//Get the user and the current account
int userId = [userIdAccount intValue];
user = [SOGoUser userWithLogin: [[woContext activeUser] login]];
currentAcount = [[user mailAccounts] objectAtIndex: userId];
//Check if we do an smtp authentication
doSmtpAuth = [authenticationType isEqualToString: @"plain"] && ![authenticator isKindOfClass: [SOGoEmptyAuthenticator class]];
if(!doSmtpAuth && userId > 0)
{
doSmtpAuth = [currentAcount objectForKey: @"smtpAuth"] ? [[currentAcount objectForKey: @"smtpAuth"] boolValue] : NO;
}
NS_DURING
{
[client connect];
if ([authenticationType isEqualToString: @"plain"] && ![authenticator isKindOfClass: [SOGoEmptyAuthenticator class]])
if (doSmtpAuth)
{
/* XXX Allow static credentials by peeking at the classname */
if ([authenticator isKindOfClass: [SOGoStaticAuthenticator class]])
login = [(SOGoStaticAuthenticator *)authenticator username];
//Check if the ccurent mail folder if for an auxiliary account (userId > 0)
if(userId > 0)
{
login = [currentAcount objectForKey: @"userName"];
password = [currentAcount objectForKey: @"password"];
}
else
login = [[SOGoUserManager sharedUserManager]
getExternalLoginForUID: [[authenticator userInContext: woContext] loginInDomain]
inDomain: [[authenticator userInContext: woContext] domain]];
{
/* XXX Allow static credentials by peeking at the classname */
if ([authenticator isKindOfClass: [SOGoStaticAuthenticator class]])
login = [(SOGoStaticAuthenticator *)authenticator username];
else
login = [[SOGoUserManager sharedUserManager]
getExternalLoginForUID: [[authenticator userInContext: woContext] loginInDomain]
inDomain: [[authenticator userInContext: woContext] domain]];
password = [authenticator passwordInContext: woContext];
}
password = [authenticator passwordInContext: woContext];
if (isSystemMessage
&& ![[[SOGoUserManager sharedUserManager] getEmailForUID: [[authenticator userInContext: woContext] loginInDomain]] isEqualToString: sender]
@@ -299,7 +329,9 @@
@" (smtp) authentication failure"];
[self errorWithFormat: @"Could not connect to the SMTP server with master credentials %@", smtpServer];
}
} else {
}
else
{
if ([login length] == 0
|| [login isEqualToString: @"anonymous"]
|| ![client plainAuthenticateUser: login
@@ -232,6 +232,7 @@
"New Mail Account" = "New Mail Account";
"Server Name" = "Server Name";
"Outgoing Server Name (SMTP)" = "Outgoing Server Name (SMTP)";
"Smtp Auth" = "Smtp Auth";
"Port" = "Port";
"Encryption" = "Encryption";
"Outgoing Encryption" = "Outgoing Encryption";
@@ -232,6 +232,7 @@
"New Mail Account" = "Nouveau compte";
"Server Name" = "Serveur";
"Outgoing Server Name (SMTP)" = "Serveur sortant (SMTP)";
"Smtp Auth" = "Smtp Auth";
"Port" = "Port";
"Encryption" = "Chiffrement";
"Outgoing Encryption" = "Chiffrement sortant";
-31
View File
@@ -513,37 +513,6 @@ static SoProduct *preferencesProduct = nil;
}
[auxAccount setObject: limitedSecurity forKey: @"security"];
}
//Decrypt password if needed
sogoSecret = [[SOGoSystemDefaults sharedSystemDefaults] sogoSecretValue];
if (sogoSecret)
{
if(![[auxAccount objectForKey: @"password"] isKindOfClass: [NSDictionary class]])
{
[self errorWithFormat:@"Can't decrypt the password for auxiliary account %@, is not a dictionnary",
[auxAccount objectForKey: @"name"]];
continue;
}
accountPassword = [auxAccount objectForKey: @"password"];
encryptedPassword = [accountPassword objectForKey: @"cypher"];
iv = [accountPassword objectForKey: @"iv"];
tag = [accountPassword objectForKey: @"tag"];
if([encryptedPassword length] > 0)
{
NS_DURING
password = [encryptedPassword decryptAES256GCM: sogoSecret iv: iv tag: tag exception:&exception];
NS_HANDLER
[self errorWithFormat:@"Can't decrypt the password for auxiliary account %@, probably not encrypted.",
[auxAccount objectForKey: @"name"]];
password = [auxAccount objectForKey: @"password"];
NS_ENDHANDLER
if(exception)
[self errorWithFormat:@"Can't decrypt the password for auxiliary account %@: %@",
[auxAccount objectForKey: @"name"], [exception reason]];
else
[auxAccount setObject: password forKey: @"password"];
}
}
}
}
// We inject our default mail account
+1 -1
View File
@@ -1359,7 +1359,7 @@ static NSArray *reminderValues = nil;
if (!knownKeys)
{
knownKeys = [NSArray arrayWithObjects: @"id", @"name", @"serverName", @"port",
@"smtpServerName", @"smtpPort", @"smtpEncryption",
@"smtpServerName", @"smtpPort", @"smtpEncryption", @"smtpAuth",
@"userName", @"password", @"encryption", @"replyTo",
@"identities", @"mailboxes", @"forceDefaultIdentity",
@"receipts", @"security", @"isNew",
@@ -97,6 +97,14 @@
placeholder=""
sg-placeholder="$AccountDialogController.smtpDefaultPort"/>
</md-input-container>
<md-checkbox class="sg-checkbox--input-container"
ng-disabled="$AccountDialogController.accountId == 0"
ng-model="$AccountDialogController.account.smtpAuth"
ng-true-value="1"
ng-false-value="0">
<var:string label:value="Smtp Auth"/>
</md-checkbox>
</div>
<md-input-container class="md-block md-input-has-value">
@@ -19,6 +19,12 @@ md-sidenav .md-dense :not(.md-dense-disabled) md-checkbox:not(.md-dense-disabled
min-height: $checkbox-width;
}
//Checkbox with input container
md-checkbox.sg-checkbox--input-container {
margin: auto;
margin-left: 16px;
}
// Checkbox in an inline form beside a select element
.md-inline-form md-checkbox.sg-checkbox--with-select {
margin: 2.5*$baseline-grid $baseline-grid*0.5 3*$baseline-grid + 2 0;