From 96331cac905ee7b6dc1adfda083dcefffe0f8795 Mon Sep 17 00:00:00 2001 From: Hivert Quentin Date: Thu, 7 Mar 2024 15:36:40 +0100 Subject: [PATCH] feat(mail): add options to not add X-Foward header in mail --- Documentation/SOGoInstallationGuide.asciidoc | 4 ++++ SoObjects/Mailer/SOGoDraftObject.m | 13 ++++++------- SoObjects/SOGo/SOGoDomainDefaults.h | 1 + SoObjects/SOGo/SOGoDomainDefaults.m | 5 +++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index dd081b7b2..ad4fcbc89 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -530,6 +530,10 @@ This could be `America/New_York`, `Europe/Berlin`, `Asia/Tokyo` or In our example, we set the time zone to `America/Montreal`. +|D |SOGoMailDisableXForward +|Parameter used to prevent sogo from adding the mail header X-Forward that +contains the user ip. Set to 'YES' to disable this header. Default to 'NO'. + |D |SOGoMailDomain |Parameter used to set the default domain name used by SOGo. SOGo uses this parameter to build the list of valid email addresses for users. diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index a84940820..d41eebf4a 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -1838,6 +1838,7 @@ static NSString *userAgent = nil; NSString *s, *dateString; NGMutableHashMap *map; id emails, from, replyTo; + BOOL addXForward = NO; map = [[[NGMutableHashMap alloc] initWithCapacity:16] autorelease]; @@ -1884,16 +1885,14 @@ static NSString *userAgent = nil; [map addObject: userAgent forKey: @"User-Agent"]; /* add custom headers */ - if ([(s = [[context request] headerForKey:@"x-webobjects-remote-host"]) length] > 0 && + addXForward = ![[[context activeUser] domainDefaults] mailDisableXForward]; + if (addXForward && [(s = [[context request] headerForKey:@"x-webobjects-remote-host"]) length] > 0 && [s compare: @"localhost"] != NSOrderedSame) - [map addObject: s - forKey: @"X-Forward"]; + [map addObject: s forKey: @"X-Forward"]; if ([(s = [headers objectForKey: @"X-Priority"]) length] > 0) - [map setObject: s - forKey: @"X-Priority"]; + [map setObject: s forKey: @"X-Priority"]; if ([(s = [headers objectForKey: @"Disposition-Notification-To"]) length] > 0) - [map setObject: s - forKey: @"Disposition-Notification-To"]; + [map setObject: s forKey: @"Disposition-Notification-To"]; [self _addHeaders: _headers toHeaderMap: map]; diff --git a/SoObjects/SOGo/SOGoDomainDefaults.h b/SoObjects/SOGo/SOGoDomainDefaults.h index 0c74e12db..54d7524ec 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.h +++ b/SoObjects/SOGo/SOGoDomainDefaults.h @@ -38,6 +38,7 @@ - (BOOL) mailCustomFromEnabled; - (BOOL) mailAuxiliaryUserAccountsEnabled; +- (BOOL) mailDisableXForward; - (NSString *) mailDomain; - (NSString *) imapServer; - (NSString *) sieveServer; diff --git a/SoObjects/SOGo/SOGoDomainDefaults.m b/SoObjects/SOGo/SOGoDomainDefaults.m index 4eacf1803..2ec86124e 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.m +++ b/SoObjects/SOGo/SOGoDomainDefaults.m @@ -106,6 +106,11 @@ return [self boolForKey: @"SOGoMailAuxiliaryUserAccountsEnabled"]; } +- (BOOL) mailDisableXForward +{ + return [self boolForKey: @"SOGoMailDisableXForward"]; +} + - (NSString *) mailDomain { return [self stringForKey: @"SOGoMailDomain"];