Home   Archive   Permalink

decode quoted-printable text

How can I decode a 'quoted-printable' text in rebol ?
Thanks !!

posted by:   LM       7-Jun-2016/5:08:48-7:00

This is an overly simplistic approach that works in Rebol 2 though is broken in Rebol 3 (due to DEHEX being broken):
     dehex replace/all replace/all quoted-printable-string "%" "=25" "=" "%"

posted by:   Chris       7-Jun-2016/13:52:15-7:00

Here's a Rebol 2 function for that.
R E B O L [
     Title: "decode-quoted-printable"
     File: %decode-quoted-printable.r
     Author: "Brett Handley"
     web: http://www.codeconscious.com
     Date: 25-Aug-2002
     Purpose: "Decodes text that has been encode using the quoted printable method."
decode-quoted-printable: function [
     "Decodes quoted-printable encoded data."
     data [string! binary!]
] [decoded-data hex-rep data-char hex-char ws-char ordinary-char] [
     decoded-data: hex-rep: data-char: none
     hex-char: charset "0123456789ABCDEFabcdef"
     ws-char: charset {^- }
     ordinary-char: complement charset [] ; Ignoring illegal characters for the moment.
     if parse/all data [
         (decoded-data: copy #{})
         some [
             "=3D" (insert tail decoded-data #"=")
             | "=20" (insert tail decoded-data #" ")
             | "=^/"
             | "=0A" (insert tail decoded-data #"^/")
             | [copy hex-rep ["=" 2 hex-char] (insert tail decoded-data dehex head change hex-rep #"%")]
             | ; Ignore linespace at the end of the line - it must have been added by an MTA see RFC 2045
                 some ws-char copy data-char [CRLF | newline] (insert tail decoded-data data-char)
             | copy data-char ordinary-char (insert tail decoded-data data-char)
         | end
     ] [to-string decoded-data]

posted by:   Brett       8-Jun-2016/17:44:14-7:00