Skip to content

JAMES-4213 Check whether alias target is valid when receiving email for alias#3073

Draft
felixauringer wants to merge 2 commits into
apache:masterfrom
giz-berlin:fix-invalid-alias-target
Draft

JAMES-4213 Check whether alias target is valid when receiving email for alias#3073
felixauringer wants to merge 2 commits into
apache:masterfrom
giz-berlin:fix-invalid-alias-target

Conversation

@felixauringer

@felixauringer felixauringer commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Currently, it is only checked if the recipient is a user or if there is a mapping with the recipient as source. It is not checked that this mapping actually points to a local mailbox.
We do not want to accept emails that go directly to an error repository, so this should be catched after the SMTP RCPT command.

I opted to accept a recipient if all resolved mailboxes are present. This may break some poorly maintained groups, I guess. Because this check is optional, I think this is acceptable.

Note: This also prepares for linagora/tmail-backend#2446 by separating the check whether a mailbox exists from the step that applies the RRT. See also the MR in that repository: linagora/tmail-backend#2448.

Jira issue: https://issues.apache.org/jira/projects/JAMES/issues/JAMES-4213

@felixauringer

felixauringer commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

I have not adapted the tests yet, so they will probably fail.

@felixauringer felixauringer changed the title fix: check whether alias target is valid when receiving email for alias JAMES-4213 Check whether alias target is valid when receiving email for alias Jun 24, 2026
@chibenwa

Copy link
Copy Markdown
Contributor

My point of view is that if there's an alias or somehting alike we manages this and if we manages this it should come in.

Some people actually have RRT mappings without local mailbox which is valid. And used.

I'd favour an approach that prevent invalid RRT creation in the first place and/or removes/correct RRT as needed,

@felixauringer

Copy link
Copy Markdown
Contributor Author

Some people actually have RRT mappings without local mailbox which is valid. And used.

Just out of curiosity: What does happen after such RRT mappings have been applied? Is the email forwarded? I thought those emails just land in the error repository in all cases.

I'd favour an approach that prevent invalid RRT creation in the first place and/or removes/correct RRT as needed,

As this (what I thought of as a bug) does not really bother us, I sadly have not the capacity to do a refactoring like that.

@chibenwa

Copy link
Copy Markdown
Contributor

Is the email forwarded?

Yes

I thought those emails just land in the error repository in all cases.

It depends on the mailetcontainer structure

As this (what I thought of as a bug) does not really bother us, I sadly have not the capacity to do a refactoring like that.

Then we can close ?

But thanks a lot for the report and feedback: challenging the software that way is definitly very beneficial ;-)

@felixauringer

Copy link
Copy Markdown
Contributor Author

Then we can close ?

Depends. In the Jira Issue you said that this stricter check could be behind a setting. I would be willing to implement that.

Additionally, I think having one method that checks the RRT table and one that checks the existence of the mailbox still makes sense for extensibility. What do you think?

@chibenwa

Copy link
Copy Markdown
Contributor

stricter check could be behind a setting. I would be willing to implement that.

Ok

Additionally, I think having one method that checks the RRT table and one that checks the existence of the mailbox still makes sense for extensibility. What do you think?

Not very opinionated I'd need to see how this looks like TBH

@felixauringer felixauringer force-pushed the fix-invalid-alias-target branch 2 times, most recently from bacec8a to 7819a46 Compare June 29, 2026 07:26
@felixauringer

Copy link
Copy Markdown
Contributor Author

Not very opinionated I'd need to see how this looks like TBH

See the newest commit in this PR (7819a46).

This enhances the extensibility as only one of them can be
overwritten without having to touch the logic of the other.
@felixauringer felixauringer force-pushed the fix-invalid-alias-target branch from b29e8cb to 49e5f60 Compare June 29, 2026 08:17
felixauringer added a commit to giz-berlin/tmail-backend that referenced this pull request Jun 29, 2026
This relies on apache/james-project#3073.
Because the RRT is applied only in the parent class, the functionality
that must be tested is smaller so that I could reduce the complexity
of the test.
Comment on lines +108 to +112
private boolean allResolvedMailboxesExist(Mappings mappings) {
return mappings
.asStream()
.flatMap(mapping -> mapping.asMailAddress().stream())
.allMatch(address -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: shouldn't this be any ?

Eg with the forward feature with a local copy one of the resolved address would not be local.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is now behind a config switch, I thought I could as well make it strict.
In my opinion, it doesn't make sense to enable it when using aliases for forwarding because one would have to create an additional local alias for every forward then.

@quantranhong1999

Copy link
Copy Markdown
Member

FYI:

11:11:52,561 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.6.0:check (check-style) on project james-server-protocols-smtp: You have 1 Checkstyle violation. -> [Help 1]
--
  |   |   | org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.6.0:check (check-style) on project james-server-protocols-smtp: You have 1 Checkstyle violation.

Currently, James only checks whether either the recipient exists
or any alias for it exists. There is no guarantee that the alias
actually points to an existing mailbox.

The optional behavior checks whether all resolved mailboxes of the
intended recipient actually exists locally.
This allows to abort directly after the RCPT command instead of
accepting the email and then error because the mailbox could not be
found.
However, with this additional check enabled, it is not possible
anymore to forward emails to other email servers via the RRT.
@felixauringer felixauringer force-pushed the fix-invalid-alias-target branch from 49e5f60 to c8d080a Compare June 30, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants