QP-encoded headers encoding/decoding regression

E-mails with QP-encoded headers are both incorrectly encoded and decoded when the last character needs encoding. FWIW, reverting the two functions vm-mime-qp-encode-region and vm-mime-qp-decode-region to what they were before your changes to use the builtin emacs functions fixes the issue, indicating that there is a regression here.

To reproduce, make sure you have vm-mime-encode-headers-type set to 'Q and send an e-mail with e.g. the Subject: Testé

By inspecting the received e-mail, one can notice that the header is not correctly encoded and contains Subject: =?utf-8?Q?test=C3?==A9, that is: the ?= is inserted before the last =A9. I think this is related to the way vm-markers are defined, and maybe this is what really needs fixing. However, I could not fix the issue by just fiddling with vm-marker definition, and I instead came up with the patch below.

A similar issue happens when decoding a correctly encoded QP header, where the end marker is not moved to the right place after quoted-printable-decode-region, then messing up the charset coding in vm-mime-charset-decode-region (applied only to the beginning of the region).

Note again that this only happens for the last character of the header needs coding/decoding. (Previous characters are correctly handled).

Here is my tentative fix, but I'm not fully satisfied with it as I don't really understand why exactly this works ... Maybe you or someone will have a better insight.

fix-qp-headers.patch

Edited by Anthony Mallet