In FETCH queries, some IMAP servers don't tolerate trailing spaces in HEADER.FIELDS
Here is a live example error produced by imap.ionos.fr (screenshot attached):
ERROR: Bad or malformed request.
Query: FETCH XXX,YYY,ZZZ (FLAGS UID RFC822.SIZE INTERNALDATE BODY.PEEK[HEADER.FIELDS (Date To Cc From Subject X-Priority Importance Priority Content-Type )])
Server responded: expected 1*ASTRING-CHAR / string instead of ")"
This patch resolves this issue by injecting in the header fields an empty string instead of a single-space string when there are no extra header fields.