diff --git a/lisp/gnus/gnus-fun.el b/lisp/gnus/gnus-fun.el index c95449762e..f1773db29a 100644 --- a/lisp/gnus/gnus-fun.el +++ b/lisp/gnus/gnus-fun.el @@ -205,11 +205,27 @@ gnus-face-encode (defun gnus-convert-face-to-png (face) "Convert FACE (which is base64-encoded) to a PNG. The PNG is returned as a string." - (mm-with-unibyte-buffer - (insert face) - (ignore-errors - (base64-decode-region (point-min) (point-max))) - (buffer-string))) + (let ((face (replace-regexp-in-string "[^[:graph:]]" "" face))) + ;; Calculate correct base64 padding + (if (string-match "=" face) + (let ((length (match-beginning 0)) + (padding nil)) + (progn (setq padding + (/ + (- 24 + (pcase (mod (* length 6) 24) + (`0 24) + (n n))) + 6)) + (setq face (concat + (substring face 0 + (match-beginning 0)) + (make-string padding ?=)))))) + (mm-with-unibyte-buffer + (insert face) + (ignore-errors + (base64-decode-region (point-min) (point-max))) + (buffer-string)))) ;;;###autoload (defun gnus-convert-png-to-face (file)