~maxgyver83/emailbook-janet

2d20cf3f51c03746ae1c0541816a2f4faf4a606c — Max Schillinger 6 months ago c16866d
Handle =?utf-8?b? (lowercase b or q)
1 files changed, 3 insertions(+), 2 deletions(-)

M emailbook.janet
M emailbook.janet => emailbook.janet +3 -2
@@ 48,7 48,7 @@ Options:
(def some-spaces (peg/compile ~(some :s)))
(def utf8-pattern (peg/compile
  ~{:main (sequence :charset '(to "?=") "?=")
    :charset (sequence "=?" (+ "UTF" "utf") "-8?" '(set "BQ") "?")}))
    :charset (sequence "=?" (+ "UTF" "utf") "-8?" '(set "bqBQ") "?")}))
(def iso-8859-q-pattern (peg/compile
  ~{:main (sequence :charset '(to "?=") "?=")
    :iso (sequence (+ "ISO" "iso") "-8859-1" (? "5"))


@@ 195,7 195,8 @@ Options:
(defn decode-utf8 [line]
  # TODO: might result in `Doe, John <john@doe.net>` → needs double quotes
  (string (peg/replace-all utf8-pattern
                           (fn [_ type_ bytes] (if (= type_ "B")
                           (fn [_ type_ bytes] (if (or (= type_ "B")
                                                       (= type_ "b"))
                                                 (base64/decode bytes)
                                                 (replace-utf8 bytes))) line)))