[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problems decoding base64 text/plain utf-8
Hi,
> I just tried to read a message with the following MIME headers:
> Content-Type: text/plain; charset="utf-8"
> Content-Transfer-Encoding: base64
> but I was told:
> Can't decode current entity.
> (the BASE-64 blob looks Ok, and the message was on the Git list and many
> others seem to have been able to decode it as their replies show the
> original text)
If it is a problem of ML programs breaking base64 encoded entity by
adding plain text to the tail of it, below workaround would fix a
problem.
;; ~/.wl
;; Workaround for base64 with trailing garbage
(require 'mime-def)
(mel-define-method mime-decode-string (string (nil "base64"))
(condition-case error
(base64-decode-string string)
(error
(catch 'done
(when (string-match
"\\([A-Za-z0-9+/ \t\r\n]+\\)=*" string)
(let ((tail (substring string (match-end 0)))
(string (match-string 1 string)))
(dotimes (i 3)
(condition-case nil
(progn
(setq string (base64-decode-string string))
(throw 'done (concat string tail)))
(error))
(setq string (concat string "=")))))
(signal (car error) (cdr error))))))
Cf. (in Japanese)
http://thread.gmane.org/gmane.mail.wanderlust.general.japanese/4893/focus=600
--
Kazuhiro Ito