aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--email/quoted-printable.scm9
-rwxr-xr-xtests/quoted-printable.scm18
2 files changed, 21 insertions, 6 deletions
diff --git a/email/quoted-printable.scm b/email/quoted-printable.scm
index b6f4c54..11abaff 100644
--- a/email/quoted-printable.scm
+++ b/email/quoted-printable.scm
@@ -24,7 +24,8 @@
#:use-module (srfi srfi-26)
#:export (quoted-printable-decode
quoted-printable-encode
- q-encoding-decode))
+ q-encoding-decode
+ q-encoding-encode))
;; TODO: Error out on invalid quoted-printable input
(define quoted-printable-decode
@@ -89,3 +90,9 @@
(lambda (c)
(if (char=? c #\_) #\Space c))
str)))
+
+(define (q-encoding-encode bv)
+ (string-map
+ (lambda (c)
+ (if (char=? c #\Space) #\_ c))
+ (quoted-printable-encode bv)))
diff --git a/tests/quoted-printable.scm b/tests/quoted-printable.scm
index a0f0369..608a937 100755
--- a/tests/quoted-printable.scm
+++ b/tests/quoted-printable.scm
@@ -49,10 +49,18 @@ abriquent pour te la vendre une =C3=A2me vulgaire.")
(string->bytevector decoded-text charset))
#\newline))))
-(test-equal "q-encoding wikipedia example"
- (bytevector->string
- (q-encoding-decode "=A1Hola,_se=F1or!")
- "ISO-8859-1")
- "¡Hola, señor!")
+(let ((encoded-text "=A1Hola,_se=F1or!")
+ (decoded-text "¡Hola, señor!")
+ (charset "ISO-8859-1"))
+ (test-equal "q-encoding wikipedia example: decoding"
+ (q-encoding-encode
+ (string->bytevector decoded-text charset))
+ encoded-text)
+
+ (test-equal "q-encoding wikipedia example: encoding"
+ (bytevector->string
+ (q-encoding-decode encoded-text)
+ charset)
+ decoded-text))
(test-end "quoted-printable")