I've now changed imap.el to use open-network-stream and removed all the variables specifying gnutls-cli etc.