emacs -batch -eval '(progn (add-to-list '\''load-path
   "~/lisp/gnus/lisp/") (require '\''uudecode) (find-file "foo.uue")
   (uudecode-decode-region (point-min) (point-max) "/dev/stdout"))'
   2>/dev/null

I have elisp functions for  doing coding and decoding that (according to
my tests) were  faster than any other elisp  before mime64 de/coding was
written in C  inside Emacs.  I suppose my code  can trivially be changed
to doing uuencode/decode.  I append it.  If people are interested, I can
change  it myself  and repost  it  after having  benchmarked it  against
gnus'.

===File ~/elisp/mime64.el===================================
(setq mime64-code-string
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")

(setq mime64-decode-vector (make-vector 256 nil))
(let ((i 0) (case-fold-search nil))
  (while (< i 256)
    (aset mime64-decode-vector i
          (string-match (regexp-quote (char-to-string i)) mime64-code-string))
    (setq i (1+ i))))

(defun mime-code (c)
  (cond
   ((aref mime64-decode-vector c))
   ((char-equal c ?=)
    (setq endchars (1+ endchars))
    0)
   (nil
    (error
     "Character %c does not match Mime base64 coding" c))))

(defun mime64-decode-region (beg end)
  (interactive "r")
  (barf-if-buffer-read-only)
  (let
      ((exchange (= (point) beg))
       (endchars 0)
       (list) (code))
    (goto-char beg)
    (while (< (point) end)
      (setq list (mapcar 'mime-code (buffer-substring-no-properties (point) (+ (point) 
4))))
      (setq code (+ (nth 3 list) (lsh (nth 2 list) 6)
                    (lsh (nth 1 list) 12) (lsh (car list) 18)))
      (delete-char 4)
      (cond
       ((zerop endchars)
        (insert (lsh code -16) (logand 255 (lsh code -8)) (logand 255 code)))
       ((= endchars 1)
        (insert (lsh code -16) (logand 255 (lsh code -8)))
        (setq end (point)))
       ((= endchars 2)
        (insert (lsh code -16))
        (setq end (point))))
      (if (char-equal (following-char) ?\n)
          (progn (delete-char 1)
                 (setq end (- end 2)))
        (setq end (1- end))))
    (if exchange
        (exchange-point-and-mark))))
============================================================

Reply via email to