X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Fmm-uu.el;h=3b008982502f3dbd35320452c38eba30135a956e;hb=348561af2b5950d72a20c41e12af9f18fd5fd0d3;hp=03aa0c69a898cf958a7fc3187233f74215ee19dc;hpb=100a99008d8270e311e91878390f765ac33e9fff;p=gnus diff --git a/lisp/mm-uu.el b/lisp/mm-uu.el index 03aa0c69a..3b0089825 100644 --- a/lisp/mm-uu.el +++ b/lisp/mm-uu.el @@ -1,13 +1,11 @@ ;;; mm-uu.el -- Return uu stuffs as mm handles -;; Copyright (c) 1998 by Shenghuo Zhu +;; Copyright (c) 1998, 1999, 2000 Free Software Foundation, Inc. ;; Author: Shenghuo Zhu -;; $Revision: 5.2 $ -;; Keywords: news postscript uudecode binhex shar - -;; This file is not part of GNU Emacs, but the same permissions -;; apply. -;; +;; Keywords: postscript uudecode binhex shar forward news + +;; This file is part of GNU Emacs. + ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) @@ -17,17 +15,23 @@ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. -;; + ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: -;; + ;;; Code: +(require 'mail-parse) +(require 'message) +(require 'nnheader) +(require 'mm-decode) +(require 'mailcap) + (eval-and-compile (autoload 'binhex-decode-region "binhex") (autoload 'binhex-decode-region-external "binhex") @@ -47,107 +51,199 @@ (defconst mm-uu-postscript-begin-line "^%!PS-") (defconst mm-uu-postscript-end-line "^%%EOF$") -(defconst mm-uu-uu-begin-line "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$") +(defconst mm-uu-uu-begin-line "^begin[ \t]+[0-7][0-7][0-7][ \t]+") (defconst mm-uu-uu-end-line "^end[ \t]*$") -(defvar mm-uu-decode-function 'uudecode-decode-region) + +(defcustom mm-uu-decode-function 'uudecode-decode-region + "*Function to uudecode. +Internal function is done in elisp by default, therefore decoding may +appear to be horribly slow . You can make Gnus use the external Unix +decoder, such as uudecode." + :type '(choice (item :tag "internal" uudecode-decode-region) + (item :tag "external" uudecode-decode-region-external)) + :group 'gnus-article-mime) (defconst mm-uu-binhex-begin-line "^:...............................................................$") (defconst mm-uu-binhex-end-line ":$") -(defvar mm-uu-binhex-decode-function 'binhex-decode-region) -(defconst mm-uu-shar-begin-line "^#! */bin/sh") -(defconst mm-uu-shar-end-line "^exit 0") +(defcustom mm-uu-binhex-decode-function 'binhex-decode-region + "*Function to binhex decode. +Internal function is done in elisp by default, therefore decoding may +appear to be horribly slow . You can make Gnus use the external Unix +decoder, such as hexbin." + :type '(choice (item :tag "internal" binhex-decode-region) + (item :tag "external" binhex-decode-region-external)) + :group 'gnus-article-mime) -(defvar mm-uu-begin-line - (concat mm-uu-postscript-begin-line "\\|" - mm-uu-uu-begin-line "\\|" - mm-uu-binhex-begin-line "\\|" - mm-uu-shar-begin-line)) - -(defvar mm-uu-identifier-alist - '((?% . postscript) (?b . uu) (?: . binhex) (?# . shar))) +(defconst mm-uu-shar-begin-line "^#! */bin/sh") +(defconst mm-uu-shar-end-line "^exit 0\\|^$") + +;;; Thanks to Edward J. Sabol and +;;; Peter von der Ah\'e +(defconst mm-uu-forward-begin-line "^-+ \\(Start of \\)?Forwarded message") +(defconst mm-uu-forward-end-line "^-+ End \\(of \\)?forwarded message") + +(defvar mm-uu-begin-line nil) + +(defconst mm-uu-identifier-alist + '((?% . postscript) (?b . uu) (?: . binhex) (?# . shar) + (?- . forward))) + +(defvar mm-dissect-disposition "inline" + "The default disposition of uu parts. +This can be either \"inline\" or \"attachment\".") + +(defun mm-uu-configure-p (key val) + (member (cons key val) mm-uu-configure-list)) + +(defun mm-uu-configure (&optional symbol value) + (if symbol (set-default symbol value)) + (setq mm-uu-begin-line nil) + (mapcar '(lambda (type) + (if (mm-uu-configure-p type 'disabled) + nil + (setq mm-uu-begin-line + (concat mm-uu-begin-line + (if mm-uu-begin-line "\\|") + (symbol-value + (intern (concat "mm-uu-" (symbol-name type) + "-begin-line"))))))) + '(uu postscript binhex shar forward))) + +(defcustom mm-uu-configure-list nil + "A list of mm-uu configuration. +To disable dissecting shar codes, for instance, add +`(shar . disabled)' to this list." + :type '(repeat (cons + (choice (item postscript) + (item uu) + (item binhex) + (item shar) + (item forward)) + (choice (item disabled)))) + :group 'gnus-article-mime + :set 'mm-uu-configure) + +(mm-uu-configure) ;;;### autoload (defun mm-uu-dissect () "Dissect the current buffer and return a list of uu handles." - (save-excursion - (save-restriction - (mail-narrow-to-head) - (goto-char (point-max))) - (forward-line) - (let ((text-start (point)) start-char end-char - type file-name end-line result) + (let (text-start start-char end-char + type file-name end-line result text-plain-type + start-char-1 end-char-1 + (case-fold-search t)) + (save-excursion + (save-restriction + (mail-narrow-to-head) + (goto-char (point-max))) + (forward-line) + ;;; gnus-decoded is a fake charset, which means no further + ;;; decoding. + (setq text-start (point) + text-plain-type '("text/plain" (charset . gnus-decoded))) (while (re-search-forward mm-uu-begin-line nil t) - (beginning-of-line) - (setq start-char (point)) - (forward-line) ;; in case of failure - (setq type (cdr (assq (aref (match-string 0) 0) + (setq start-char (match-beginning 0)) + (setq type (cdr (assq (aref (match-string 0) 0) mm-uu-identifier-alist))) - (setq file-name - (if (eq type 'uu) + (setq file-name + (if (and (eq type 'uu) + (looking-at "\\(.+\\)$")) (and (match-string 1) (let ((nnheader-file-name-translation-alist '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_)))) (nnheader-translate-file-chars (match-string 1)))))) - (setq end-line (symbol-value - (intern (concat "mm-uu-" (symbol-name type) - "-end-line")))) - (when (re-search-forward end-line nil t) + (forward-line);; in case of failure + (setq start-char-1 (point)) + (setq end-line (symbol-value + (intern (concat "mm-uu-" (symbol-name type) + "-end-line")))) + (when (and (re-search-forward end-line nil t) + (not (eq (match-beginning 0) (match-end 0)))) + (setq end-char-1 (match-beginning 0)) (forward-line) (setq end-char (point)) - (when (or (not (eq type 'binhex)) - (setq file-name - (condition-case nil - (binhex-decode-region start-char end-char t) - (error nil)))) + (when (cond + ((eq type 'binhex) + (setq file-name + (ignore-errors + (binhex-decode-region start-char end-char t)))) + ((eq type 'forward) + (save-excursion + (goto-char start-char-1) + (looking-at "[\r\n]*[a-zA-Z][a-zA-Z0-9-]*:"))) + (t t)) (if (> start-char text-start) (push - (list (mm-uu-copy-to-buffer text-start start-char) - '("text/plain") nil nil nil nil) + (mm-make-handle (mm-uu-copy-to-buffer text-start start-char) + text-plain-type) result)) - (push + (push (cond ((eq type 'postscript) - (list (mm-uu-copy-to-buffer start-char end-char) - '("application/postscript") nil nil nil nil)) + (mm-make-handle (mm-uu-copy-to-buffer start-char end-char) + '("application/postscript"))) + ((eq type 'forward) + (mm-make-handle (mm-uu-copy-to-buffer start-char-1 end-char-1) + '("message/rfc822" (charset . gnus-decoded)))) ((eq type 'uu) - (list (mm-uu-copy-to-buffer start-char end-char) - (list (or (and file-name - (string-match "\\.[^\\.]+$" file-name) - (mailcap-extension-to-mime - (match-string 0 file-name))) - "application/octet-stream")) - mm-uu-decode-function nil - (if (and file-name (not (equal file-name ""))) - (list "attachment" (cons 'filename file-name))) - file-name)) + (mm-make-handle (mm-uu-copy-to-buffer start-char end-char) + (list (or (and file-name + (string-match "\\.[^\\.]+$" file-name) + (mailcap-extension-to-mime + (match-string 0 file-name))) + "application/octet-stream")) + 'x-uuencode nil + (if (and file-name (not (equal file-name ""))) + (list mm-dissect-disposition + (cons 'filename file-name))))) ((eq type 'binhex) - (list (mm-uu-copy-to-buffer start-char end-char) - (list (or (and file-name - (string-match "\\.[^\\.]+$" file-name) - (mailcap-extension-to-mime - (match-string 0 file-name))) - "application/octet-stream")) - mm-uu-binhex-decode-function nil - (if (and file-name (not (equal file-name ""))) - (list "attachment" (cons 'filename file-name))) - file-name)) + (mm-make-handle (mm-uu-copy-to-buffer start-char end-char) + (list (or (and file-name + (string-match "\\.[^\\.]+$" file-name) + (mailcap-extension-to-mime + (match-string 0 file-name))) + "application/octet-stream")) + 'x-binhex nil + (if (and file-name (not (equal file-name ""))) + (list mm-dissect-disposition + (cons 'filename file-name))))) ((eq type 'shar) - (list (mm-uu-copy-to-buffer start-char end-char) - '("application/x-shar") nil nil nil nil))) + (mm-make-handle (mm-uu-copy-to-buffer start-char end-char) + '("application/x-shar")))) result) (setq text-start end-char)))) (when result (if (> (point-max) (1+ text-start)) (push - (list (mm-uu-copy-to-buffer text-start (point-max)) - '("text/plain") nil nil nil nil) + (mm-make-handle (mm-uu-copy-to-buffer text-start (point-max)) + text-plain-type) result)) (setq result (cons "multipart/mixed" (nreverse result)))) result))) +;;;### autoload +(defun mm-uu-test () + "Check whether the current buffer contains uu stuffs." + (save-excursion + (goto-char (point-min)) + (let (type end-line result + (case-fold-search t)) + (while (and mm-uu-begin-line + (not result) (re-search-forward mm-uu-begin-line nil t)) + (forward-line) + (setq type (cdr (assq (aref (match-string 0) 0) + mm-uu-identifier-alist))) + (setq end-line (symbol-value + (intern (concat "mm-uu-" (symbol-name type) + "-end-line")))) + (if (and (re-search-forward end-line nil t) + (not (eq (match-beginning 0) (match-end 0)))) + (setq result t))) + result))) + (provide 'mm-uu) ;;; mm-uu.el ends here