Add code to write strings to the IMAP server.
authorChris Hanson <org/chris-hanson/cph>
Tue, 25 Apr 2000 03:39:44 +0000 (03:39 +0000)
committerChris Hanson <org/chris-hanson/cph>
Tue, 25 Apr 2000 03:39:44 +0000 (03:39 +0000)
v7/src/imail/imail.pkg
v7/src/imail/imap-syntax.scm

index 2e43c4c7e902d7448d733a954b7c1d089bb36be3..bb79e3c35c03da6f02f80fb63150e3809636d412 100644 (file)
@@ -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
 ;;;
          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")
index 6b172ddda9a27bd95995dd1787281f04646e37a1..7eb72c436b89874ef7d846e096f7dd24ef568b6d 100644 (file)
@@ -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
 ;;;
   (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))
       (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)
+\f
+;;;; 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