mjl- / mox

modern full-featured open source secure mail server for low-maintenance self-hosted email
https://www.xmox.nl
MIT License
3.56k stars 99 forks source link

character & not allowed in mailbox name #110

Closed jsfan3 closed 5 months ago

jsfan3 commented 9 months ago

Does mox fully support all imap_utf7 characters?

With imapsync, I have the following errors. In this case, "host2" uses mox:

Err 1/14: Could not create folder [2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO] from [2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO]: 498 NO [CANNOT] CREATE character & not allowed in mailbox name Err 2/14: Host2 folder 2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO: Could not select: 500 NO [CANNOT] SELECT character & not allowed in mailbox name Err 3/14: Could not create folder [2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO] from [2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO/2PAX_20_30_APR'24]: 505 NO [CANNOT] CREATE character & not allowed in mailbox name Err 4/14: Host2 folder 2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO: Could not select: 507 NO [CANNOT] SELECT character & not allowed in mailbox name Err 5/14: Could not create folder [2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO/2PAX_20_30_APR'24] from [2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO/2PAX_20_30_APR'24]: 508 NO [CANNOT] CREATE character & not allowed in mailbox name Err 6/14: Host2 folder 2023_xF8FF_2024/DIRETTI/VALERIA&-MATTEO/2PAX_20_30_APR'24: Could not select: 510 NO [CANNOT] SELECT character & not allowed in mailbox name Err 7/14: Could not create folder [2023_xF8FF_2024/YOU&-MEVIAGGI] from [2023_xF8FF_2024/YOU&-MEVIAGGI]: 878 NO [CANNOT] CREATE character & not allowed in mailbox name Err 8/14: Host2 folder 2023_xF8FF_2024/YOU&-MEVIAGGI: Could not select: 880 NO [CANNOT] SELECT character & not allowed in mailbox name

About this issue, this answer can be interesting: https://serverfault.com/a/598680

mjl- commented 9 months ago

No, UTF7 support is not complete. Mox initially only handled UTF-8 mailbox names. It now also decodes incoming UTF-7, but doesn't encode mailboxes with UTF-7 when it sends out mailbox names. To prevent confusion, mox currently doesn't allow "&" at all. And that is certainly too restricting. The proper solution is to encode mailbox names with UTF-7 when IMAP4rev2 is not enabled (which probably applies to most client connections), and to allow "&" in mailbox names.

It was on a todo-list already after another report, but I'll bump up the priority.

Thanks for reporting!

mjl- commented 9 months ago

I think the commits just now fixed the issue, see the commit message for details. Summary: Out of precaution, the "special" characters &#*% weren't allowed in mailbox names, they are allowed now. And incoming mailbox names were already parsed as IMAP-UTF-7, but outgoing mailbox names weren't. Now incoming names are parsed strictly as IMAP-UTF-7 when they should be, and outgoing names are encoded when needed.

jsfan3 commented 9 months ago

Wow! Thank you so much! What are the instructions for updating mox with your fix? Is it enough to repeat the following command?

GOBIN=$PWD CGO_ENABLED=0 go install github.com/mjl-/mox@latest

mjl- commented 9 months ago

The "@latest" resolves to the latest release. To build for this commit, use: GOBIN=$PWD CGO_ENABLED=0 go install github.com/mjl-/mox@b887539ee4ffb93c979649cf675a2e4d6eedb884. Running "./mox version" afterwards should show v0.0.9-0.20240101131305-b887539ee4ff.

Hope this commit makes it work. Let me know if there are any issues. And thanks for reporting!

jsfan3 commented 9 months ago

I have been testing for a few hours now. So far, your commit seems to have fixed the problem. Thank you very much. If there are more problems later, I will update you.

mjl- commented 5 months ago

Assuming this is no longer an issue. Feel free to reopen if this issue could still use some work/discussion.