From c6d17a3397517cef464e080ee6dbfd3afeea0193 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 25 Apr 2000 03:39:44 +0000 Subject: [PATCH] Add code to write strings to the IMAP server. --- v7/src/imail/imail.pkg | 7 ++++-- v7/src/imail/imap-syntax.scm | 42 ++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/v7/src/imail/imail.pkg b/v7/src/imail/imail.pkg index 2e43c4c7e..bb79e3c35 100644 --- a/v7/src/imail/imail.pkg +++ b/v7/src/imail/imail.pkg @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: imail.pkg,v 1.18 2000/04/23 00:40:29 cph Exp $ +;;; $Id: imail.pkg,v 1.19 2000/04/25 03:39:44 cph Exp $ ;;; ;;; Copyright (c) 2000 Massachusetts Institute of Technology ;;; @@ -128,7 +128,10 @@ imap:match:tag imap:parse:section imap:quoted-char? - imap:quoted-special?)) + imap:quoted-special? + imap:string-may-be-quoted? + imap:write-literal-string + imap:write-quoted-string)) (define-package (edwin imail imap-response) (files "imap-response") diff --git a/v7/src/imail/imap-syntax.scm b/v7/src/imail/imap-syntax.scm index 6b172ddda..7eb72c436 100644 --- a/v7/src/imail/imap-syntax.scm +++ b/v7/src/imail/imap-syntax.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: imap-syntax.scm,v 1.4 2000/04/23 00:40:34 cph Exp $ +;;; $Id: imap-syntax.scm,v 1.5 2000/04/25 03:38:51 cph Exp $ ;;; ;;; Copyright (c) 2000 Massachusetts Institute of Technology ;;; @@ -65,6 +65,12 @@ (char-set-difference imap:char-set:char (char-set #\return #\linefeed))) +(define imap:char-set:not-text-char + (char-set-invert imap:char-set:text-char)) + +(define (imap:string-may-be-quoted? string) + (not (string-find-next-char-in-set string imap:char-set:not-text-char))) + (define imap:char-set:quoted-char (char-set-difference imap:char-set:text-char imap:char-set:quoted-specials)) @@ -560,4 +566,36 @@ (do-single (char->integer #\,) 63))) (set! base64-char-table char-table) (set! base64-digit-table digit-table) - unspecific) \ No newline at end of file + unspecific) + +;;;; Formatted output + +(define (imap:write-quoted-string string port) + (imap:write-quoted-substring string 0 (string-length string) port)) + +(define (imap:write-quoted-substring string start end port) + (write-char #\" port) + (let loop ((start start)) + (if (fix:< start end) + (let ((char (string-ref string start))) + (if (or (char=? char #\\) (char=? char #\")) + (write-char #\\ port)) + (write-char char port) + (loop (fix:+ start 1))))) + (write-char #\" port)) + +(define (imap:write-literal-string-header string port) + (imap:write-literal-substring-header string 0 (string-length string) port)) + +(define (imap:write-literal-substring-header string start end port) + (write-char #\{ port) + (write (fix:- end start) port) + (write-char #\} port) + (write-char #\return port) + (write-char #\linefeed port)) + +(define (imap:write-literal-string-body string port) + (imap:write-literal-substring-body string 0 (string-length string) port)) + +(define (imap:write-literal-substring-body string start end port) + (write-substring string start end port)) \ No newline at end of file -- 2.25.1