@chebra
I admit I never really researched this, as I have a domain at hetzner, which out of the box fulfills all my email needs (including IMAP).
I'm surprised Tutanota does not have this. Librem One does, but I assume there are others, too!?
https://docs.puri.sm/Librem_One/PureOS/Email.html
@danielst
In the end I traced the problem to openssl. Gmail apparently started requiring SNI with TLS1.3. Instead of failing with an error, they just return a self-signed certificate. Php imap extension uses abandoned library which cannot support SNI. Downgrading openssl to 1.1.0 uses TLS 1.2 which then works with gmail. This is facepalm upon facepalm...
@danielst
I thought about that. But tutanota doesn't have an API yet, nor will ever support imap, so it would mean a complete rewrite, special adapter for each email provider. Why did email become so complicated?