From 8a9c14473f0ae449bfbfe77ba680734e4a14562f Mon Sep 17 00:00:00 2001 From: Andrew Whatson Date: Tue, 3 Jan 2023 22:19:42 +1000 Subject: email: Support quoted-printable CR LF sequences. * email/quoted-printable.scm (quoted-printable-decode): Ignore "=\r\n" sequences in the input. * tests/quoted-printable.scm ("quoted-printable decoding of soft line breaks (=\\n)", "quoted-printable decoding of soft line breaks (=\\r\\n)"): New tests. Signed-off-by: Arun Isaac --- email/quoted-printable.scm | 8 ++++++-- tests/quoted-printable.scm | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/email/quoted-printable.scm b/email/quoted-printable.scm index 2c5d7a7..d986346 100644 --- a/email/quoted-printable.scm +++ b/email/quoted-printable.scm @@ -1,5 +1,6 @@ ;;; guile-email --- Guile email parser ;;; Copyright © 2018, 2020 Arun Isaac +;;; Copyright © 2023 Andrew Whatson ;;; ;;; This file is part of guile-email. ;;; @@ -41,11 +42,14 @@ (cond ((eof-object? c) out) ((char=? c #\=) - ;; TODO: Support "\r\n" line ending (let ((c1 (read-char in))) + ;; Skip if \n was read. (unless (char=? c1 #\Newline) (let ((c2 (read-char in))) - (put-u8 out (string->number (string c1 c2) 16))))) + ;; Skip if \r\n was read. + (unless (and (char=? c1 #\Return) + (char=? c2 #\Newline)) + (put-u8 out (string->number (string c1 c2) 16)))))) (quoted-printable-decode in out)) (else (put-u8 out (char->integer c)) (quoted-printable-decode in out))))))) diff --git a/tests/quoted-printable.scm b/tests/quoted-printable.scm index bfbd985..415feb0 100644 --- a/tests/quoted-printable.scm +++ b/tests/quoted-printable.scm @@ -1,5 +1,6 @@ ;;; guile-email --- Guile email parser ;;; Copyright © 2018, 2020 Arun Isaac +;;; Copyright © 2023 Andrew Whatson ;;; ;;; This file is part of guile-email. ;;; @@ -67,6 +68,12 @@ abriquent pour te la vendre une =C3=A2me vulgaire.") (quoted-printable-escape-encode-char #\return) (quoted-printable-escape-encode-char #\newline))) +(test-equal "quoted-printable decoding of soft line breaks (=\\n)" + (quoted-printable-decode "=\n") #vu8()) + +(test-equal "quoted-printable decoding of soft line breaks (=\\r\\n)" + (quoted-printable-decode "=\r\n") #vu8()) + (test-assert "quoted-printable random bytevector: quoted-printable-encode and quoted-printable-decode are inverses of each other" (every (lambda (len) (let ((x (random-bytevector len))) -- cgit v1.2.3