Fix IMAP sync authentication with legacy-encoded passwords#6969
Draft
Fix IMAP sync authentication with legacy-encoded passwords#6969
Conversation
…in-1 retry logic Co-authored-by: DerLinkman <62480600+DerLinkman@users.noreply.github.com>
Co-authored-by: DerLinkman <62480600+DerLinkman@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Sync jobs with legacy-encoded passwords
Fix IMAP sync authentication with legacy-encoded passwords
Dec 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution Guidelines
What does this PR include?
Short Description
IMAP sync jobs fail when passwords contain single-byte characters (e.g., § =
0xA7) because UTF-8 encoding transforms0xA7→0xC2 0xA7, breaking authentication with Exchange 2016 and similar servers.Solution: Retry with Latin-1 encoding on authentication failure, preserving original byte sequences while maintaining UTF-8 compatibility.
Changes:
Example flow:
Affected Containers
Did you run tests?
What did you tested?
What were the final results? (Awaited, got)
0xA7→0xC2 0xA7(expected, got)0xA7→0xA7(expected, got)Original prompt
This section details on the original issue you should resolve
<issue_title>Sync-Jobs with legacy-encoded passwords</issue_title>
<issue_description>### Contribution guidelines
Checklist prior issue creation
Description
IMAP sync jobs generated via the mailcow API fail when the remote password contains single-byte (non-UTF-8) characters, such as § (0xA7), which are accepted by Exchange 2016 IMAP.
As example, the user has a password ending with "§" (the character 0xA7) , imapsync_runner.pl will encode that as 0xC2 0xA7 in the password file and pass that to imapsync, failing the Authentication.
The failure is caused by forcing :utf8 binmode on the temporary passfile in the imapsync wrapper, which re-encodes the password to UTF-8, changing the byte sequence and breaking authentication. I understand that this is required for paswords that actually contains UTF-8, so while removing the binmode works for me, it will regress on #5528.
I think there is no easy way to correctly fix this, a workaround could be, if the password is UTF-8 and authentication fails to retry with re-encoding the password to latin1. (This seems also a strategy thunderbird employed, at least some years ago -
https://superuser.com/questions/1696433/outlook-password-encoding-for-email-services-imap-smtp )
Steps to reproduce:
Setup Sync-Job with Exchange 2016, password contains 8-bit character (like §); options like "--showpasswords" and "--debugimap1" are helpful, as they show how the password is sent over the wire.
Sync-Job fails with password error, --showpaswords show that the password is UTF-8 encoded -- see below for extract.
manually calling imapsync with password's "§" sent as 0xA7 only.
imapsync --showpasswords --debugimap1 --dry --justfolders --host1 <redacted> --user1 <redacted> --password1 $(printf"xxxxxxxxxxxx\xa7") --host2 <redacted> --user2 <redacted> --password2 "<redacted>"removing the "binmode( $passfile1, ":utf8" );" line from data/Dockerfiles/dovecot/imapsync_runner.pl -- auth now works.
Logs:
Which branch are you using?
master (stable)
Which architecture are you using?
x86_64
Operating System:
Debian GNU/Linux 13 (trixie)
Server/VM specifications:
16 GiB, 8 cores
Is Apparmor, SELinux or similar active?
no
Virtualization technology:
Proxmox
Docker version:
26.1.5+dfsg1
docker-compose version or docker compose version:
Docker Compose version 2.26.1-4
mailcow version:
2025-12a
Reverse proxy:
n/a
Logs of git diff:
Logs of iptables -L -vn:
Logs of ip6tables -L -vn:
Logs of iptables -L -vn -t nat:
Logs of ip6tables...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.