Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

James 4099 Configurable path delimiter #2588

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

j-hellenberg
Copy link
Contributor

James-4099

Add a configuration switch for adjusting the default mailbox folder delimiter.

Currently allowed (because unit-tested) values are: dot (will use '.' as delimiter), slash (will use '/' as delimiter), pipe ('|'), comma (','), colon (':'), semicolon (';').

Currently explicitly left-out values are: '#' (clashes with namespace prefix character), '\' (anticipated some problems with the prefixedRegex matching and because it is the escaping character, it can generally be a bit more annoying to deal with in strings).

This feature is opt in - the default configuration will still retain the current default delimiter (dot).

Notes to reviewer:

  • Unfortunately, git becomes pretty confused when indentation of a large code chunk is changed. For this reasons, it might make sense to look at some commits individually - I specifically separated refactoring and correctly intending the MailPathTests and PrefixedRegexTests into their own commits to improve diff readability.
  • There may be more places in the code where '.' is used as a hard-coded constant. Is this an issue? Obviously, the dot used in Domain.java or MailAddress.java is independent of the mailbox folder delimiter, but the FileIntoAction, for example, also has a hierarchy delimiter.

@chibenwa
Copy link
Contributor

chibenwa commented Jan 8, 2025

FileIntoAction follows sieve convention to use / as a folder delimiter and needs a translation to the actual deleimiter. Email, i know...

Comment on lines -376 to -382
@Test
void assertAcceptableShouldNotThrowOnPercentWhenRelaxMode() {
System.setProperty("james.relaxed.mailbox.name.validation", "true");

assertThatCode(() -> MailboxPath.forUser(USER, "a%b"))
.doesNotThrowAnyException();
}
Copy link
Contributor Author

@j-hellenberg j-hellenberg Jan 8, 2025

Choose a reason for hiding this comment

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

The old version of the relax-mode tests essentially asked "If I do nothing, does it throw an exception?" 😁 Obviously, that sort of mistake is easy to overlook as the resulting test trivially passes, but I still found it a bit funny

Copy link
Contributor

Choose a reason for hiding this comment

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

That's what happens when TDD is overlooked I believe!

Copy link
Contributor

@chibenwa chibenwa left a comment

Choose a reason for hiding this comment

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

It looks overall good to me.

Thanks for the quality contribution.

I did took the time to review what Cyrus does. It offers either . or / as a delimiter. So I am OK with the implemented behavious.

Please clearly state in the documentation AND in the configuration comment that this option is not safe to change once you have data and will result in loss of the folder hierarchy.

@j-hellenberg j-hellenberg marked this pull request as ready for review January 8, 2025 10:25
@j-hellenberg
Copy link
Contributor Author

Please clearly state in the documentation AND in the configuration comment that this option is not safe to change once you have data and will result in loss of the folder hierarchy.

Currently, I'm writing everywhere WARNING: This value should only be changed when setting up a new deployment. Changing the parameter for an existing deployments will likely lead to failure of some system components, as occurrences of old the delimiter will still be present in the database/data store. Would you like that comment to be reworded in some way? Or do you see a place where I am missing the comment?

@j-hellenberg
Copy link
Contributor Author

FileIntoAction follows sieve convention to use / as a folder delimiter and needs a translation to the actual deleimiter. Email, i know...

I saw that the execute method does destinationMailbox.replace(FileIntoAction.HIERARCHY_DELIMITER, '/') (destinationMailbox.replace('.', '/'), in other words).

So, to be clear: If the MailboxConstants.FOLDER_DELIMITER is anything except '/', this line needs to be destinationMailbox.replace(MailboxConstants.FOLDER_DELIMITER, '/') (and it works fine if delimiter is already /, in which case this is a noop)?

@chibenwa
Copy link
Contributor

chibenwa commented Jan 8, 2025

So, to be clear: If the MailboxConstants.FOLDER_DELIMITER is anything except '/', this line needs to be destinationMailbox.replace(MailboxConstants.FOLDER_DELIMITER, '/') (and it works fine if delimiter is already /, in which case this is a noop

Yes!

@j-hellenberg
Copy link
Contributor Author

So, to be clear: If the MailboxConstants.FOLDER_DELIMITER is anything except '/', this line needs to be destinationMailbox.replace(MailboxConstants.FOLDER_DELIMITER, '/') (and it works fine if delimiter is already /, in which case this is a noop

Yes!

Okay, so I added that. Do you know of any more locations where it would be critical to honor the new delimiter? (I did not find any, but I'm not sure that means much)

Copy link
Contributor

@vttranlina vttranlina left a comment

Choose a reason for hiding this comment

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

+1, When I read RFC documents, It tend to use / more frequently as an example.

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