Import Oort Gnus v0.11.
[elisp/gnus.git-] / lisp / drums.el
index 0344956..6b4a0d8 100644 (file)
@@ -29,6 +29,7 @@
 ;;; Code:
 
 (require 'time-date)
+(require 'mm-util)
 
 (defvar drums-no-ws-ctl-token "\001-\010\013\014\016-\037\177"
   "US-ASCII control characters excluding CR, LF and white space.")
 (defvar drums-qtext-token
   (concat drums-no-ws-ctl-token "\041\043-\133\135-\177")
   "Non-white-space control characaters, plus the rest of ASCII excluding backslash and doublequote.")
-  
+(defvar drums-tspecials "][()<>@,;:\\\"/?="
+  "Tspecials.")
+
 (defvar drums-syntax-table
   (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
     (modify-syntax-entry ?\\ "/" table)
     (modify-syntax-entry ?< "(" table)
     (modify-syntax-entry ?> ")" table)
-    (modify-syntax-entry ?( "(" table)
-    (modify-syntax-entry ?) ")" table)
+    (modify-syntax-entry ?@ "w" table)
+    (modify-syntax-entry ?/ "w" table)
+    (modify-syntax-entry ?= " " table)
+    (modify-syntax-entry ?* " " table)
+    (modify-syntax-entry ?\; " " table)
+    (modify-syntax-entry ?\' " " table)
     table))
 
+(defun drums-token-to-list (token)
+  "Translate TOKEN into a list of characters."
+  (let ((i 0)
+       b e c out range)
+    (while (< i (length token))
+      (setq c (mm-char-int (aref token i)))
+      (incf i)
+      (cond
+       ((eq c (mm-char-int ?-))
+       (if b
+           (setq range t)
+         (push c out)))
+       (range
+       (while (<= b c)
+         (push (mm-make-char 'ascii b) out)
+         (incf b))
+       (setq range nil))
+       ((= i (length token))
+       (push (mm-make-char 'ascii c) out))
+       (t
+       (setq b c))))
+    (nreverse out)))
+
 (defsubst drums-init (string)
   (set-syntax-table drums-syntax-table)
   (insert string)
        (cond
         ((eq c ?\")
          (forward-sexp 1))
-        ((memq c '(? ?\t))
+        ((eq c ?\()
+         (forward-sexp 1))
+        ((memq c '(? ?\t ?\n))
          (delete-char 1))
         (t
          (forward-char 1))))
            (cons
             (mapconcat 'identity (nreverse display-name) "")
             (drums-get-comment string)))
-       (cons mailbox display-name)))))
+       (cons mailbox display-string)))))
 
 (defun drums-parse-addresses (string)
   "Parse STRING and return a list of MAILBOX / DISPLAY-NAME pairs."
         ((memq c '(?\" ?< ?\())
          (forward-sexp 1))
         ((eq c ?,)
-         (push (drums-parse-address (buffer-substring beg (1- (point))))
+         (push (drums-parse-address (buffer-substring beg (point)))
                pairs)
+         (forward-char 1)
          (setq beg (point)))
         (t
          (forward-char 1))))
+      (push (drums-parse-address (buffer-substring beg (point)))
+           pairs)
       (nreverse pairs))))
 
 (defun drums-unfold-fws ()
 (defun drums-parse-date (string)
   "Return an Emacs time spec from STRING."
   (apply 'encode-time (parse-time-string string)))
-    
+
+(defun drums-narrow-to-header ()
+  "Narrow to the header section in the current buffer."
+  (narrow-to-region
+   (goto-char (point-min))
+   (if (search-forward "\n\n" nil 1)
+       (1- (point))
+     (point-max)))
+  (goto-char (point-min)))
+
+(defun drums-quote-string (string)
+  "Quote string if it needs quoting to be displayed in a header."
+  (if (not (string-match (concat "[^" drums-atext-token "]") string))
+      (concat "\"" string "\"")
+    string))
+
 (provide 'drums)
 
 ;;; drums.el ends here