From: akr Date: Mon, 26 Oct 1998 14:03:12 +0000 (+0000) Subject: * Sync up to flim-1_11_2 from flim-1_11_0. X-Git-Tag: doodle-1_11_1~2 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8352b732ac2a1f27294120ac06c34944095a2ea6;p=elisp%2Fflim.git * Sync up to flim-1_11_2 from flim-1_11_0. * mime-def.el (mime-library-product): Bump up to FLAM-DOODLE 1.11.1. --- diff --git a/ChangeLog b/ChangeLog index a94317b..08d3d31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +1998-10-26 Tanaka Akira + + * Sync up to flim-1_11_2 from flim-1_11_0. + + * mime-def.el (mime-library-product): Bump up to FLAM-DOODLE + 1.11.1. + 1998-10-25 Tanaka Akira * eword-decode.el (eword-decode-field-body): Change interface. @@ -1245,6 +1252,157 @@ * eword-decode.el: Copied from AKEMI branch of SEMI. +1998-10-26 MORIOKA Tomohiko + + * FLIM: Version 1.11.2 (Heij-Dò)-A was released. + + * NEWS (Abolish variable `mime-temp-directory'): New subsection. + + * README.en (Installation): Modify for APEL 9.6. + +1998-10-26 MORIOKA Tomohiko + + * eword-encode.el (eword-encode-field-body): Don't eliminate + top-spaces. + +1998-10-25 MORIOKA Tomohiko + + * FLIM-ELS (flim-modules): Don't install mel-b-el for Emacs 20.4. + +1998-10-25 Tanaka Akira + + * eword-decode.el (eword-decode-field-body): Refine implementation. + +1998-10-24 Tanaka Akira + + * mel-b-ccl.el, mel-q-ccl.el, mel.el, FLIM-ELS: Divide mel-ccl.el + into mel-b-ccl.el and mel-q-ccl.el. + +1998-09-11 Tanaka Akira + + * mel.el (base64-encoded-length): New implementation. + +1998-10-25 Tanaka Akira + + * eword-decode.el (eword-decode-field-body): New function. + +1998-10-25 MORIOKA Tomohiko + + * eword-encode.el (eword-encode-field-body): Change interface. + (eword-encode-header): Use `eword-encode-field-body'; abolish + function `eword-encode-field'. + +1998-10-25 Tanaka Akira + + * eword-encode.el (eword-encode-field-body): New function. + (eword-encode-field): Use `eword-encode-field-body'. + +1998-10-24 MORIOKA Tomohiko + + * mel.el, mel-b-el.el, FLIM-ELS: Rename mel-b.el -> mel-b-el.el. + +1998-10-24 MORIOKA Tomohiko + + * mel-u.el (uuencode-external-decode-region): Use + `temporary-file-directory' instead of `mime-temp-directory'. + (mime-write-decoded-region): Likewise. + + * mime-def.el: Abolish variable `mime-temp-directory'. + +1998-10-24 MORIOKA Tomohiko + + * mmgeneric.el (mime-insert-header-from-buffer): New function. + (insert-header): Use `mime-insert-header-from-buffer'. + +1998-10-24 MORIOKA Tomohiko + + * FLIM-ELS: Don't install mel-b-dl.el if the running emacs has + builtin base64 encoder/decoder. + + * mel.el: Set up builtin base64 encoder/decoder if they are + available. + + * mime-def.el (base64-dl-module): Set nil as initial value if the + running emacs has builtin base64 encoder/decoder. + + * mel-b.el: Require `poe' instead of `emu'. + (base64-encode-string): Use `defun-maybe'. + (base64-encode-region): Likewise. + (base64-decode-region): Likewise. + (base64-decode-string): Likewise. + + * mel-b-dl.el: Require `poe' instead of `emu'. + + +1998-10-23 MORIOKA Tomohiko + + * FLIM: Version 1.11.1 (Takanohara) was released. + +1998-10-22 Yoshiki Hayashi + + * README.ja: New file. + +1998-10-20 MORIOKA Tomohiko + + * mime-def.el: Require mcharset. + +1998-10-20 Katsumi Yamaoka + + * mel-u.el (mime-write-decoded-region): Fix typo. + + * mime-def.el: Enclose defining procedure for the constants + `std11-quoted-pair-regexp', `std11-non-qtext-char-list' and + `std11-qtext-regexp' with `eval-and-compile'. + +1998-10-19 MORIOKA Tomohiko + + * NEWS (Behavior change of `mime-insert-header'): New subsection. + + * mmgeneric.el (insert-header): Include `:' in field-name. + +1998-10-19 MORIOKA Tomohiko + + * mime-def.el (std11-qtext-regexp): Use `eval-when-compile'; don't + use `char-list-to-string'. + (std11-quoted-string-regexp): Use `eval-when-compile'. + - Use `def-edebug-spec' to define edebug-form-spec of + mm-define-method; fix definition of edebug-form-spec of + mm-define-method. + +1998-10-18 MORIOKA Tomohiko + + * mime-en.sgml, mime-ja.sgml (Header encoder/decoder): Add + description about `eword-field-encoding-method-alist'. + + * mime-en.sgml (Header encoder/decoder): Modify description about + `eword-encode-header'. + + * mime-ja.sgml (Header encoder/decoder): Translate. + +1998-10-18 MORIOKA Tomohiko + + * mime-en.sgml (entity formatting): Fix typo in description of + `default-mime-charset'. + + * mime-en.sgml (Header encoder/decoder): Modify description of + `eword-decode-header'. + + * mime-ja.sgml, mime-en.sgml (Header encoder/decoder): fix typo. + + * mime-en.sgml (encoder/decoder): Translate description of + `mime-decode-string'. + +1998-10-18 MORIOKA Tomohiko + + * mime-en.sgml (Content-Disposition parser): Modify description. + + * mime-en.sgml (Content-Type parser): Modify description. + +1998-10-18 MORIOKA Tomohiko + + * mime-en.sgml (Content-Transfer-Encoding parser): Translate. + + 1998-10-18 MORIOKA Tomohiko * FLIM: Version 1.11.0 (Yamadagawa) was released. diff --git a/DOODLE-VERSION b/DOODLE-VERSION index c23bbc2..2a37cab 100644 --- a/DOODLE-VERSION +++ b/DOODLE-VERSION @@ -23,7 +23,7 @@ Order is not significant. 17 $B5`MU(B $B$/$A$P(B 10YR7.5/10.0 FLAM-DOODLE 1.10.1 18 $B@VGrFK(B $B$"$+$7$m$D$k$P$_(B 5.0YR8.0/6.0 FLAM-DOODLE 1.10.2 19 $B>.F&(B $B$"$:$-(B 2.5R3.5/5.0 FLAM-DOODLE 1.11.0 - 20 $BIrF:Cc(B $B$($S$A$c(B 5.0R4.0/11.0 + 20 $BIrF:Cc(B $B$($S$A$c(B 5.0R4.0/11.0 FLAM-DOODLE 1.11.1 21 $B?? JR $(BJRD.@~(B $(B=K1`(B 1.10.5 Kizugawadai $(BLZDE@nBf(B 1.11.0 Yamadagawa $(B;3ED@n(B ------ Takanohara $(B9b$N86(B ------ Heij-Dò-A $(BJ?>k(B +1.11.1 Takanohara $(B9b$N86(B +1.11.2 Heij-Dò-A $(BJ?>k(B ----- Saidaiji $(B@>Bg;{(B ;;------------------------------------------------------------------------- ;; Kinki Nippon Railway $(B6a5&F|K\E4F;(B http://www.kintetsu.co.jp/ diff --git a/Makefile b/Makefile index c1fd0e4..c0fdb09 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # PACKAGE = flim -VERSION = 1.11.0 +VERSION = 1.11.2 TAR = tar RM = /bin/rm -f diff --git a/NEWS b/NEWS index af32579..7662287 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,19 @@ Similarly generic function `mime-insert-decoded-header' was renamed to as an obsolete alias. +** Behavior change of `mime-insert-header' + +Each field-name of second and third argument of function +`mime-insert-header' can include `:'. + + +** Abolish variable `mime-temp-directory' + +Now FLIM uses `temporary-file-directory' instead of +`mime-temp-directory'. So environment variable "MIME_TMP_DIR" and +"TM_TMP_DIR" are not effective to specify temporary directory of FLIM. + + ** Add new function `eword-decode-and-unfold-unstructured-field' diff --git a/README.en b/README.en index 004fbe3..4213653 100644 --- a/README.en +++ b/README.en @@ -36,7 +36,7 @@ What's FLIM Installation ============ -(0) before installing it, please install APEL (9.4 or later) package. +(0) before installing it, please install APEL (9.6 or later) package. APEL package is available at: ftp://ftp.jaist.ac.jp/pub/GNU/elisp/apel/ diff --git a/README.ja b/README.ja new file mode 100644 index 0000000..cecec7f --- /dev/null +++ b/README.ja @@ -0,0 +1,158 @@ +[FLIM $B$N(B README ($BF|K\8lHG(B)] + +FLIM $B$H$O!)(B +=========== + + FLIM $B$O%a%C%;!<%8I=8=$HId9f2=$K4X$9$k4pACE*$J5!G=$rDs6!$9$k%i%$%V%i(B + $B%j!<$G$9!#0J2<$N%b%8%e!<%k$+$i9=@.$5$l$F$$$^$9(B: + + std11.el --- STD 11 (RFC 822) $B$N2r@O4o$H%f!<%F%#%j%F%#!<(B + + mime.el --- MIME $B%i%$%V%i%j!<(B + + mime-def.el --- MIME $B$NMM<0$K4X$9$kDj5A(B + + mime-parse.el --- MIME $B2r@O4o(B + + mel.el --- MIME $BId9f4o(B/$BI|9f4o(B + mel-b-dl.el --- base64 (B-encoding) $BId9f4o(B/$BI|9f4o(B + (Emacs 20 $B$NF0E*FI$_9~$_5!G=IU$-MQ(B) + mel-b.el --- base64 (B-encoding) $BId9f4o(B/$BI|9f4o(B + ($BB>$N(B emacs $B4D6-MQ(B) + mel-q.el --- quoted-printable $B$H(B Q-encoding + $BId9f4o(B/$BI|9f4o(B + mel-ccl.el --- CCL $B$r;H$C$?(B base64 (B-encoding), + quoted-printable $B$H(B Q-encoding $B$NId9f4o(B/$BI|9f4o(B + mel-u.el --- uuencode $B$N$?$a$NHs8x<0%b%8%e!<%k(B + mel-g.el --- gzip64 $B$N$?$a$NHs8x<0%b%8%e!<%k(B + + eword-decode.el --- encoded-word $BI|9f4o(B + eword-encode.el --- encoded-word $BId9f4o(B + + mailcap.el --- mailcap $B2r@O4o$H%f!<%F%#%j%F%#!<(B + + +$B%$%s%9%H!<%k(B +============ + +(0) $B%$%s%9%H!<%k$9$kA0$K!"(BAPEL $B%Q%C%1!<%8$r%$%s%9%H!<%k$7$F$/$@$5$$!#(B + APEL $B%Q%C%1!<%8$O0J2<$N$H$3$m$Gl=j$G$N%G%#%l%/%H%j!<$K%$%s%9%H!<%k$7$?$/$J$$$J$i!"0J2<$N$3$H$@$1$r$d$C(B + $B$F$/$@$5$$(B: + + % make + + emacs $B$N%3%^%s%IL>$r;XDj$9$k$3$H$,$G$-$^$9!#Nc$($P!"(B + + % make EMACS=xemacs + + `EMACS=...' $B$,>JN,$5$l$k$H!"(BEmacs=emacs $B$,;H$o$l$^$9!#(B + +(b) make install + + $BB>$N%G%#%l%/%H%j!<$K%$%s%9%H!<%k$7$?$$$J$i!"0J2<$N$3$H$r$7$F$/$@$5$$(B: + + % make install + + emacs $B$N%3%^%s%IL>$r;XDj$9$k$3$H$,$G$-$^$9!#Nc$($P!"(B + + % make install EMACS=xemacs + + `EMACS=...' $B$,>JN,$5$l$k$H!"(BEmacs=emacs $B$,;H$o$l$^$9!#(B + + Emacs Lisp $B%W%m%0%i%`$H%7%'%k%9%/%j%W%H$N$?$a$N%G%#%l%/%H%j!JN,$5$l$k$H!";XDj$5$l$?(B emacs $B%3%^%s%I$N%G%#%l%/%H%j!<(B + $BLZ$N@\F,<-$,;HMQ$5$l$^$9(B ($B$*$=$i$/(B /usr/local $B$G$9(B)$B!#(B + + $BNc$($P!"(BPREFIX=/usr/local $B$H(B Emacs 19.34 $B$,;XDj$5$l$l$P!"0J2<$N%G%#%l(B + $B%/%H%j!JN,$5$l$k$H!";XDj$5$l$?(B emacs $B$N%3%^%s%I$N(B + site-lisp $B%G%#%l%/%H%j!<$,;H$o$l$^$9(B ($B$*$=$i$/(B + /usr/local/share/emacs/site-lisp $B$+(B /usr/local/lib/xemacs/site-lisp) + $B$G$9!#(B + + emu $B%b%8%e!<%k(B (APEL $B%Q%C%1!<%8$KF~$C$F$$$^$9(B) $B$,I8=`$G$J$$%G%#%l%/(B + $B%H%j!<$K%$%s%9%H!<%k$5$l$F$$$k>l9g$O!"$=$l$i$N$"$k>l=j$r;XDj$9$kI,MW(B + $B$,$"$j$^$9!#Nc$($P!"(B: + + % make install VERSION_SPECIFIC_LISPDIR=~/elisp + + $B$I$N%U%!%$%k$,(B emu $B%b%8%e!<%k$+(B apel $B%b%8%e!<%k$N0lIt$J$N$+!"$=$l$i(B + $B$,$I$3$K%$%s%9%H!<%k$5$l$k$+$rCN$j$?$$$H$-$O!"$NA*Br<+M3$J@_Dj$r;XDj$9$k$3$H$,(B + $B$G$-$^$9!#$=$NCf$N%3%a%s%H$rFI$s$G$/$@$5$$!#(B + +(1-c) XEmacs $B$N%Q%C%1!<%8$H$7$F%$%s%9%H!<%k$9$k(B + + XEmacs $B$N%Q%C%1!<%8%G%#%l%/%H%j!<$K%$%s%9%H!<%k$9$k>l9g$O!"0J2<$N$3(B + $B$H$r$7$F$/$@$5$$(B: + + % make install-package + + emacs $B$N%3%^%s%IL>$r;XDj$9$k$3$H$,$G$-$^$9!#Nc$($P!"(B + + % make install-package XEMACS=xemacs-21 + + `XEMACS=...' $B$,>JN,$5$l$k$H!"(BXEMACS=xemacs $B$,;HMQ$5$l$^$9!#(B + + $B%Q%C%1!<%8$N%G%#%l%/%H%j!<$r;XDj$9$k$3$H$,$G$-$^$9!#Nc$($P(B: + + % make install PACKAGEDIR=~/.xemacs + + `PACKAGEDIR=...' $B$,>JN,$5$l$k$H!"B8:_$9$k%Q%C%1!<%8%G%#%l%/%H%j!<$N(B + $B:G=i$N$b$N$,;H$o$l$^$9!#(B + + XEmacs $B$N%Q%C%1!<%8%7%9%F%`$O(B XEmacs 21.0 $B$+$=$l0J9_$rMW5a$9$k$3$H$K(B + $BCm0U$7$F$/$@$5$$!#(B + +load-path (Emacs $B$H(B MULE $BMQ(B) +============================= + + Emacs $B$+(B Mule $B$r;H$C$F$$$k$J$i!"(BFLIM $B$N%G%#%l%/%H%j!<$r(B + load-path $B$KDI2C$7$F$/$@$5$$!#=i4|@_Dj$G%$%s%9%H!<%k$7$?$J$i!"-Mh$N3HD%$N5DO@$r$7$?$j$9$k$3$H$,$G$-$^$9!#(Btm ML $B$K(B + $B;22C$9$k$K$O!"6u$NEE;R%a!<%k$r(B + + tm-en-help@chamonix.jaist.ac.jp ($B1Q8l(B) + tm-ja-help@chamonix.jaist.ac.jp ($BF|K\8l(B) + + $B$KAw$C$F$/$@$5$$!#(B diff --git a/eword-decode.el b/eword-decode.el index b0607cb..67c02e6 100644 --- a/eword-decode.el +++ b/eword-decode.el @@ -493,18 +493,19 @@ MIME encoded-word in FIELD-BODY is recognized according to Non MIME encoded-word part in FILED-BODY is decoded with `default-mime-charset'." + (if (symbolp field-name) (setq field-name (symbol-name field-name))) (let ((decoded (if unfolded (let ((ew-ignore-76bytes-limit t)) - (ew-decode-field (symbol-name field-name) - (ew-lf-crlf-to-crlf field-body))) - (ew-decode-field (symbol-name field-name) - (ew-lf-crlf-to-crlf field-body))))) + (ew-decode-field + field-name (ew-lf-crlf-to-crlf field-body))) + (ew-decode-field + field-name (ew-lf-crlf-to-crlf field-body))))) (if max-column (setq decoded (ew-crlf-refold decoded (1+ (string-width field-name)) - (if (integerp max-column) max-column fill-column))) + (if (eq max-column t) fill-column max-column))) (setq decoded (ew-crlf-unfold decoded))) (ew-crlf-to-lf decoded))) diff --git a/eword-encode.el b/eword-encode.el index c1603cd..52390c7 100644 --- a/eword-encode.el +++ b/eword-encode.el @@ -592,48 +592,36 @@ Optional argument COLUMN is start-position of the field." (or column eword-encode-default-start-column) (eword-encode-split-string string 'text)))) -(defun eword-encode-field (string) - "Encode header field STRING, and return the result. +(defun eword-encode-field-body (field-body field-name) + "Encode FIELD-BODY as FIELD-NAME, and return the result. A lexical token includes non-ASCII character is encoded as MIME encoded-word. ASCII token is not encoded." - (setq string (std11-unfold-string string)) - (let ((ret (string-match std11-field-head-regexp string))) - (or (if ret - (let ((field-name (substring string 0 (1- (match-end 0)))) - (field-body (eliminate-top-spaces - (substring string (match-end 0)))) - field-name-symbol) - (if (setq ret - (cond ((string= field-body "") "") - ((memq (setq field-name-symbol - (intern (capitalize field-name))) - '(Reply-To - From Sender - Resent-Reply-To Resent-From - Resent-Sender To Resent-To - Cc Resent-Cc Bcc Resent-Bcc - Dcc)) - (eword-encode-address-list - field-body (+ (length field-name) 2)) - ) - ((eq field-name-symbol 'In-Reply-To) - (eword-encode-in-reply-to - field-body (+ (length field-name) 2)) - ) - ((memq field-name-symbol - '(Mime-Version User-Agent)) - (eword-encode-structured-field-body - field-body (+ (length field-name) 2)) - ) - (t - (eword-encode-unstructured-field-body - field-body (1+ (length field-name))) - )) - ) - (concat field-name ": " ret) - ))) - (eword-encode-string string 0) - ))) + (if (string= field-body "") + "" + (let (start) + (if (symbolp field-name) + (setq start (1+ (length (symbol-name field-name)))) + (setq start (1+ (length field-name)) + field-name (intern (capitalize field-name)))) + (cond ((memq field-name + '(Reply-To + From Sender + Resent-Reply-To Resent-From + Resent-Sender To Resent-To + Cc Resent-Cc Bcc Resent-Bcc + Dcc)) + (eword-encode-address-list field-body start) + ) + ((eq field-name 'In-Reply-To) + (eword-encode-in-reply-to field-body start) + ) + ((memq field-name '(Mime-Version User-Agent)) + (eword-encode-structured-field-body field-body start) + ) + (t + (eword-encode-unstructured-field-body field-body start) + )) + ))) (defun eword-in-subject-p () (let ((str (std11-field-body "Subject"))) @@ -665,27 +653,28 @@ It refer variable `eword-field-encoding-method-alist'." (std11-narrow-to-header mail-header-separator) (goto-char (point-min)) (let ((default-cs (mime-charset-to-coding-system default-mime-charset)) - beg end field-name) + bbeg end field-name) (while (re-search-forward std11-field-head-regexp nil t) - (setq beg (match-beginning 0)) - (setq field-name (buffer-substring beg (1- (match-end 0)))) - (setq end (std11-field-end)) - (and (find-non-ascii-charset-region beg end) + (setq bbeg (match-end 0) + field-name (buffer-substring (match-beginning 0) (1- bbeg)) + end (std11-field-end)) + (and (find-non-ascii-charset-region bbeg end) (let ((method (eword-find-field-encoding-method (downcase field-name)))) (cond ((eq method 'mime) - (let ((field - (buffer-substring-no-properties beg end) + (let ((field-body + (buffer-substring-no-properties bbeg end) )) - (delete-region beg end) - (insert (eword-encode-field field)) + (delete-region bbeg end) + (insert (eword-encode-field-body field-body + field-name)) )) (code-conversion (let ((cs (or (mime-charset-to-coding-system method) default-cs))) - (encode-coding-region beg end cs) + (encode-coding-region bbeg end cs) ))) )) )) diff --git a/mel-b-dl.el b/mel-b-dl.el index 3adea3d..411fa74 100644 --- a/mel-b-dl.el +++ b/mel-b-dl.el @@ -24,7 +24,7 @@ ;;; Code: -(require 'emu) +(require 'poe) (require 'mime-def) (eval-and-compile diff --git a/mel-b-el.el b/mel-b-el.el new file mode 100644 index 0000000..7426cc5 --- /dev/null +++ b/mel-b-el.el @@ -0,0 +1,409 @@ +;;; mel-b-el.el: Base64 encoder/decoder for GNU Emacs + +;; Copyright (C) 1992,1995,1996,1997,1998 Free Software Foundation, Inc. + +;; Author: ENAMI Tsugutomo +;; MORIOKA Tomohiko +;; Created: 1995/6/24 +;; Keywords: MIME, Base64 + +;; This file is part of MEL (MIME Encoding Library). + +;; This program 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) any later version. + +;; This program is distributed in the hope that it will be useful, 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. + +;;; Code: + +(require 'poe) +(require 'mime-def) + + +;;; @ variables +;;; + +(defgroup base64 nil + "Base64 encoder/decoder" + :group 'mime) + +(defcustom base64-external-encoder '("mmencode") + "*list of base64 encoder program name and its arguments." + :group 'base64 + :type '(cons (file :tag "Command")(repeat :tag "Arguments" string))) + +(defcustom base64-external-decoder '("mmencode" "-u") + "*list of base64 decoder program name and its arguments." + :group 'base64 + :type '(cons (file :tag "Command")(repeat :tag "Arguments" string))) + +(defcustom base64-external-decoder-option-to-specify-file '("-o") + "*list of options of base64 decoder program to specify file." + :group 'base64 + :type '(repeat :tag "Arguments" string)) + +(defcustom base64-internal-encoding-limit 1000 + "*limit size to use internal base64 encoder. +If size of input to encode is larger than this limit, +external encoder is called." + :group 'base64 + :type '(choice (const :tag "Always use internal encoder" nil) + (integer :tag "Size"))) + +(defcustom base64-internal-decoding-limit (if (and (featurep 'xemacs) + (featurep 'mule)) + 1000 + 7600) + "*limit size to use internal base64 decoder. +If size of input to decode is larger than this limit, +external decoder is called." + :group 'base64 + :type '(choice (const :tag "Always use internal decoder" nil) + (integer :tag "Size"))) + + +;;; @ internal base64 encoder +;;; based on base64 decoder by Enami Tsugutomo + +(eval-and-compile + (defconst base64-characters + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") + ) + +(defmacro base64-num-to-char (n) + `(aref base64-characters ,n)) + +(defun base64-encode-1 (pack) + (let ((a (car pack)) + (b (nth 1 pack)) + (c (nth 2 pack))) + (concat + (char-to-string (base64-num-to-char (ash a -2))) + (if b + (concat + (char-to-string + (base64-num-to-char (logior (ash (logand a 3) 4) (ash b -4)))) + (if c + (concat + (char-to-string + (base64-num-to-char (logior (ash (logand b 15) 2) (ash c -6)))) + (char-to-string (base64-num-to-char (logand c 63))) + ) + (concat (char-to-string + (base64-num-to-char (ash (logand b 15) 2))) "=") + )) + (concat (char-to-string + (base64-num-to-char (ash (logand a 3) 4))) "==") + )))) + +(defun-maybe base64-encode-string (string) + "Encode STRING to base64, and return the result." + (let ((len (length string)) + (b 0)(e 57) + dest) + (while (< e len) + (setq dest + (concat dest + (mapconcat + (function base64-encode-1) + (pack-sequence (substring string b e) 3) + "") + "\n")) + (setq b e + e (+ e 57) + ) + ) + (let* ((es (mapconcat + (function base64-encode-1) + (pack-sequence (substring string b) 3) + "")) + (m (mod (length es) 4)) + ) + (concat dest es (cond ((= m 3) "=") + ((= m 2) "==") + )) + ))) + +(defun base64-internal-encode-region (beg end) + (save-excursion + (save-restriction + (narrow-to-region beg end) + (let ((str (buffer-substring beg end))) + (delete-region beg end) + (insert (base64-encode-string str)) + ) + (or (bolp) + (insert "\n") + ) + ))) + + +;;; @ internal base64 decoder +;;; + +(defconst base64-numbers + (eval-when-compile + (let ((len (length base64-characters)) + (vec (make-vector 123 nil)) + (i 0)) + (while (< i len) + (aset vec (aref base64-characters i) i) + (setq i (1+ i))) + vec))) + +(defmacro base64-char-to-num (c) + `(aref base64-numbers ,c)) + +(defsubst base64-internal-decode (string buffer) + (let* ((len (length string)) + (i 0) + (j 0) + v1 v2 v3) + (catch 'tag + (while (< i len) + (when (prog1 (setq v1 (base64-char-to-num (aref string i))) + (setq i (1+ i))) + (setq v2 (base64-char-to-num (aref string i)) + i (1+ i) + v3 (base64-char-to-num (aref string i)) + i (1+ i)) + (aset buffer j (logior (lsh v1 2)(lsh v2 -4))) + (setq j (1+ j)) + (if v3 + (let ((v4 (base64-char-to-num (aref string i)))) + (setq i (1+ i)) + (aset buffer j (logior (lsh (logand v2 15) 4)(lsh v3 -2))) + (setq j (1+ j)) + (if v4 + (aset buffer (prog1 j (setq j (1+ j))) + (logior (lsh (logand v3 3) 6) v4)) + (throw 'tag nil) + )) + (throw 'tag nil) + )))) + (substring buffer 0 j) + )) + +(defun base64-internal-decode-string (string) + (base64-internal-decode string (make-string (length string) 0))) + +;; (defsubst base64-decode-string! (string) +;; (setq string (string-as-unibyte string)) +;; (base64-internal-decode string string)) + +(defun base64-internal-decode-region (beg end) + (save-excursion + (let ((str (string-as-unibyte (buffer-substring beg end)))) + (delete-region beg end) + (goto-char beg) + (insert (base64-internal-decode str str))))) + +;; (defun base64-internal-decode-region2 (beg end) +;; (save-excursion +;; (let ((str (buffer-substring beg end))) +;; (delete-region beg end) +;; (goto-char beg) +;; (insert (base64-decode-string! str))))) + +;; (defun base64-internal-decode-region3 (beg end) +;; (save-excursion +;; (let ((str (buffer-substring beg end))) +;; (delete-region beg end) +;; (goto-char beg) +;; (insert (base64-internal-decode-string str))))) + + +;;; @ external encoder/decoder +;;; + +(defun base64-external-encode-region (beg end) + (save-excursion + (save-restriction + (narrow-to-region beg end) + (as-binary-process + (apply (function call-process-region) + beg end (car base64-external-encoder) + t t nil (cdr base64-external-encoder))) + ;; for OS/2 + ;; regularize line break code + (goto-char (point-min)) + (while (re-search-forward "\r$" nil t) + (replace-match "")) + ))) + +(defun base64-external-decode-region (beg end) + (save-excursion + (as-binary-process + (apply (function call-process-region) + beg end (car base64-external-decoder) + t t nil (cdr base64-external-decoder))) + )) + +(defun base64-external-decode-string (string) + (with-temp-buffer + (insert string) + (as-binary-process + (apply (function call-process-region) + (point-min) (point-max) + (car base64-external-decoder) + t t nil (cdr base64-external-decoder))) + (buffer-string))) + + +;;; @ application interfaces +;;; + +(defun-maybe base64-encode-region (start end) + "Encode current region by base64. +START and END are buffer positions. +This function calls internal base64 encoder if size of region is +smaller than `base64-internal-encoding-limit', otherwise it calls +external base64 encoder specified by `base64-external-encoder'. In +this case, you must install the program (maybe mmencode included in +metamail or XEmacs package)." + (interactive "r") + (if (and base64-internal-encoding-limit + (> (- end start) base64-internal-encoding-limit)) + (base64-external-encode-region start end) + (base64-internal-encode-region start end))) + +(defun-maybe base64-decode-region (start end) + "Decode current region by base64. +START and END are buffer positions. +This function calls internal base64 decoder if size of region is +smaller than `base64-internal-decoding-limit', otherwise it calls +external base64 decoder specified by `base64-external-decoder'. In +this case, you must install the program (maybe mmencode included in +metamail or XEmacs package)." + (interactive "r") + (if (and base64-internal-decoding-limit + (> (- end start) base64-internal-decoding-limit)) + (base64-external-decode-region start end) + (base64-internal-decode-region start end))) + +(defun-maybe base64-decode-string (string) + "Decode STRING which is encoded in base64, and return the result. +This function calls internal base64 decoder if size of STRING is +smaller than `base64-internal-decoding-limit', otherwise it calls +external base64 decoder specified by `base64-external-decoder'. In +this case, you must install the program (maybe mmencode included in +metamail or XEmacs package)." + (interactive "r") + (if (and base64-internal-decoding-limit + (> (length string) base64-internal-decoding-limit)) + (base64-external-decode-string string) + (base64-internal-decode-string string))) + + +(mel-define-method-function (mime-encode-string string (nil "base64")) + 'base64-encode-string) +(mel-define-method-function (mime-decode-string string (nil "base64")) + 'base64-decode-string) +(mel-define-method-function (mime-encode-region start end (nil "base64")) + 'base64-encode-region) +(mel-define-method-function (mime-decode-region start end (nil "base64")) + 'base64-decode-region) + +(mel-define-method-function (encoded-text-encode-string string (nil "B")) + 'base64-encode-string) + +(mel-define-method encoded-text-decode-string (string (nil "B")) + (if (and (string-match B-encoded-text-regexp string) + (string= string (match-string 0 string))) + (base64-decode-string string) + (error "Invalid encoded-text %s" string))) + +(defun base64-insert-encoded-file (filename) + "Encode contents of file FILENAME to base64, and insert the result. +It calls external base64 encoder specified by +`base64-external-encoder'. So you must install the program (maybe +mmencode included in metamail or XEmacs package)." + (interactive (list (read-file-name "Insert encoded file: "))) + (if (and base64-internal-encoding-limit + (> (nth 7 (file-attributes filename)) + base64-internal-encoding-limit)) + (apply (function call-process) (car base64-external-encoder) + filename t nil (cdr base64-external-encoder)) + (insert + (base64-encode-string + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-as-binary filename) + (buffer-string)))) + (or (bolp) + (insert "\n")) + )) + +(mel-define-method-function (mime-insert-encoded-file filename (nil "base64")) + 'base64-insert-encoded-file) + +(defun base64-write-decoded-region (start end filename) + "Decode and write current region encoded by base64 into FILENAME. +START and END are buffer positions." + (interactive + (list (region-beginning) (region-end) + (read-file-name "Write decoded region to file: "))) + (if (and base64-internal-decoding-limit + (> (- end start) base64-internal-decoding-limit)) + (as-binary-process + (apply (function call-process-region) + start end (car base64-external-decoder) + nil nil nil + (append (cdr base64-external-decoder) + base64-external-decoder-option-to-specify-file + (list filename)))) + (let ((str (buffer-substring start end))) + (with-temp-buffer + (insert (base64-internal-decode-string str)) + (write-region-as-binary (point-min) (point-max) filename) + )))) + +(mel-define-method-function + (mime-write-decoded-region start end filename (nil "base64")) + 'base64-write-decoded-region) + + +;;; @ etc +;;; + +(defun pack-sequence (seq size) + "Split sequence SEQ into SIZE elements packs, +and return list of packs. [mel-b-el; tl-seq function]" + (let ((len (length seq)) (p 0) obj + unit (i 0) + dest) + (while (< p len) + (setq obj (elt seq p)) + (setq unit (cons obj unit)) + (setq i (1+ i)) + (if (= i size) + (progn + (setq dest (cons (reverse unit) dest)) + (setq unit nil) + (setq i 0) + )) + (setq p (1+ p)) + ) + (if unit + (setq dest (cons (reverse unit) dest)) + ) + (reverse dest) + )) + + +;;; @ end +;;; + +(provide 'mel-b-el) + +;;; mel-b-el.el ends here. diff --git a/mel-b.el b/mel-b.el deleted file mode 100644 index ad34a37..0000000 --- a/mel-b.el +++ /dev/null @@ -1,409 +0,0 @@ -;;; mel-b.el: Base64 encoder/decoder for GNU Emacs - -;; Copyright (C) 1992,1995,1996,1997,1998 Free Software Foundation, Inc. - -;; Author: ENAMI Tsugutomo -;; MORIOKA Tomohiko -;; Created: 1995/6/24 -;; Keywords: MIME, Base64 - -;; This file is part of MEL (MIME Encoding Library). - -;; This program 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) any later version. - -;; This program is distributed in the hope that it will be useful, 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. - -;;; Code: - -(require 'emu) -(require 'mime-def) - - -;;; @ variables -;;; - -(defgroup base64 nil - "Base64 encoder/decoder" - :group 'mime) - -(defcustom base64-external-encoder '("mmencode") - "*list of base64 encoder program name and its arguments." - :group 'base64 - :type '(cons (file :tag "Command")(repeat :tag "Arguments" string))) - -(defcustom base64-external-decoder '("mmencode" "-u") - "*list of base64 decoder program name and its arguments." - :group 'base64 - :type '(cons (file :tag "Command")(repeat :tag "Arguments" string))) - -(defcustom base64-external-decoder-option-to-specify-file '("-o") - "*list of options of base64 decoder program to specify file." - :group 'base64 - :type '(repeat :tag "Arguments" string)) - -(defcustom base64-internal-encoding-limit 1000 - "*limit size to use internal base64 encoder. -If size of input to encode is larger than this limit, -external encoder is called." - :group 'base64 - :type '(choice (const :tag "Always use internal encoder" nil) - (integer :tag "Size"))) - -(defcustom base64-internal-decoding-limit (if (and (featurep 'xemacs) - (featurep 'mule)) - 1000 - 7600) - "*limit size to use internal base64 decoder. -If size of input to decode is larger than this limit, -external decoder is called." - :group 'base64 - :type '(choice (const :tag "Always use internal decoder" nil) - (integer :tag "Size"))) - - -;;; @ internal base64 encoder -;;; based on base64 decoder by Enami Tsugutomo - -(eval-and-compile - (defconst base64-characters - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") - ) - -(defmacro base64-num-to-char (n) - `(aref base64-characters ,n)) - -(defun base64-encode-1 (pack) - (let ((a (car pack)) - (b (nth 1 pack)) - (c (nth 2 pack))) - (concat - (char-to-string (base64-num-to-char (ash a -2))) - (if b - (concat - (char-to-string - (base64-num-to-char (logior (ash (logand a 3) 4) (ash b -4)))) - (if c - (concat - (char-to-string - (base64-num-to-char (logior (ash (logand b 15) 2) (ash c -6)))) - (char-to-string (base64-num-to-char (logand c 63))) - ) - (concat (char-to-string - (base64-num-to-char (ash (logand b 15) 2))) "=") - )) - (concat (char-to-string - (base64-num-to-char (ash (logand a 3) 4))) "==") - )))) - -(defun base64-encode-string (string) - "Encode STRING to base64, and return the result." - (let ((len (length string)) - (b 0)(e 57) - dest) - (while (< e len) - (setq dest - (concat dest - (mapconcat - (function base64-encode-1) - (pack-sequence (substring string b e) 3) - "") - "\n")) - (setq b e - e (+ e 57) - ) - ) - (let* ((es (mapconcat - (function base64-encode-1) - (pack-sequence (substring string b) 3) - "")) - (m (mod (length es) 4)) - ) - (concat dest es (cond ((= m 3) "=") - ((= m 2) "==") - )) - ))) - -(defun base64-internal-encode-region (beg end) - (save-excursion - (save-restriction - (narrow-to-region beg end) - (let ((str (buffer-substring beg end))) - (delete-region beg end) - (insert (base64-encode-string str)) - ) - (or (bolp) - (insert "\n") - ) - ))) - - -;;; @ internal base64 decoder -;;; - -(defconst base64-numbers - (eval-when-compile - (let ((len (length base64-characters)) - (vec (make-vector 123 nil)) - (i 0)) - (while (< i len) - (aset vec (aref base64-characters i) i) - (setq i (1+ i))) - vec))) - -(defmacro base64-char-to-num (c) - `(aref base64-numbers ,c)) - -(defsubst base64-internal-decode (string buffer) - (let* ((len (length string)) - (i 0) - (j 0) - v1 v2 v3) - (catch 'tag - (while (< i len) - (when (prog1 (setq v1 (base64-char-to-num (aref string i))) - (setq i (1+ i))) - (setq v2 (base64-char-to-num (aref string i)) - i (1+ i) - v3 (base64-char-to-num (aref string i)) - i (1+ i)) - (aset buffer j (logior (lsh v1 2)(lsh v2 -4))) - (setq j (1+ j)) - (if v3 - (let ((v4 (base64-char-to-num (aref string i)))) - (setq i (1+ i)) - (aset buffer j (logior (lsh (logand v2 15) 4)(lsh v3 -2))) - (setq j (1+ j)) - (if v4 - (aset buffer (prog1 j (setq j (1+ j))) - (logior (lsh (logand v3 3) 6) v4)) - (throw 'tag nil) - )) - (throw 'tag nil) - )))) - (substring buffer 0 j) - )) - -(defun base64-internal-decode-string (string) - (base64-internal-decode string (make-string (length string) 0))) - -;; (defsubst base64-decode-string! (string) -;; (setq string (string-as-unibyte string)) -;; (base64-internal-decode string string)) - -(defun base64-internal-decode-region (beg end) - (save-excursion - (let ((str (string-as-unibyte (buffer-substring beg end)))) - (delete-region beg end) - (goto-char beg) - (insert (base64-internal-decode str str))))) - -;; (defun base64-internal-decode-region2 (beg end) -;; (save-excursion -;; (let ((str (buffer-substring beg end))) -;; (delete-region beg end) -;; (goto-char beg) -;; (insert (base64-decode-string! str))))) - -;; (defun base64-internal-decode-region3 (beg end) -;; (save-excursion -;; (let ((str (buffer-substring beg end))) -;; (delete-region beg end) -;; (goto-char beg) -;; (insert (base64-internal-decode-string str))))) - - -;;; @ external encoder/decoder -;;; - -(defun base64-external-encode-region (beg end) - (save-excursion - (save-restriction - (narrow-to-region beg end) - (as-binary-process - (apply (function call-process-region) - beg end (car base64-external-encoder) - t t nil (cdr base64-external-encoder))) - ;; for OS/2 - ;; regularize line break code - (goto-char (point-min)) - (while (re-search-forward "\r$" nil t) - (replace-match "")) - ))) - -(defun base64-external-decode-region (beg end) - (save-excursion - (as-binary-process - (apply (function call-process-region) - beg end (car base64-external-decoder) - t t nil (cdr base64-external-decoder))) - )) - -(defun base64-external-decode-string (string) - (with-temp-buffer - (insert string) - (as-binary-process - (apply (function call-process-region) - (point-min) (point-max) - (car base64-external-decoder) - t t nil (cdr base64-external-decoder))) - (buffer-string))) - - -;;; @ application interfaces -;;; - -(defun base64-encode-region (start end) - "Encode current region by base64. -START and END are buffer positions. -This function calls internal base64 encoder if size of region is -smaller than `base64-internal-encoding-limit', otherwise it calls -external base64 encoder specified by `base64-external-encoder'. In -this case, you must install the program (maybe mmencode included in -metamail or XEmacs package)." - (interactive "r") - (if (and base64-internal-encoding-limit - (> (- end start) base64-internal-encoding-limit)) - (base64-external-encode-region start end) - (base64-internal-encode-region start end))) - -(defun base64-decode-region (start end) - "Decode current region by base64. -START and END are buffer positions. -This function calls internal base64 decoder if size of region is -smaller than `base64-internal-decoding-limit', otherwise it calls -external base64 decoder specified by `base64-external-decoder'. In -this case, you must install the program (maybe mmencode included in -metamail or XEmacs package)." - (interactive "r") - (if (and base64-internal-decoding-limit - (> (- end start) base64-internal-decoding-limit)) - (base64-external-decode-region start end) - (base64-internal-decode-region start end))) - -(defun base64-decode-string (string) - "Decode STRING which is encoded in base64, and return the result. -This function calls internal base64 decoder if size of STRING is -smaller than `base64-internal-decoding-limit', otherwise it calls -external base64 decoder specified by `base64-external-decoder'. In -this case, you must install the program (maybe mmencode included in -metamail or XEmacs package)." - (interactive "r") - (if (and base64-internal-decoding-limit - (> (length string) base64-internal-decoding-limit)) - (base64-external-decode-string string) - (base64-internal-decode-string string))) - - -(mel-define-method-function (mime-encode-string string (nil "base64")) - 'base64-encode-string) -(mel-define-method-function (mime-decode-string string (nil "base64")) - 'base64-decode-string) -(mel-define-method-function (mime-encode-region start end (nil "base64")) - 'base64-encode-region) -(mel-define-method-function (mime-decode-region start end (nil "base64")) - 'base64-decode-region) - -(mel-define-method-function (encoded-text-encode-string string (nil "B")) - 'base64-encode-string) - -(mel-define-method encoded-text-decode-string (string (nil "B")) - (if (and (string-match B-encoded-text-regexp string) - (string= string (match-string 0 string))) - (base64-decode-string string) - (error "Invalid encoded-text %s" string))) - -(defun base64-insert-encoded-file (filename) - "Encode contents of file FILENAME to base64, and insert the result. -It calls external base64 encoder specified by -`base64-external-encoder'. So you must install the program (maybe -mmencode included in metamail or XEmacs package)." - (interactive (list (read-file-name "Insert encoded file: "))) - (if (and base64-internal-encoding-limit - (> (nth 7 (file-attributes filename)) - base64-internal-encoding-limit)) - (apply (function call-process) (car base64-external-encoder) - filename t nil (cdr base64-external-encoder)) - (insert - (base64-encode-string - (with-temp-buffer - (set-buffer-multibyte nil) - (insert-file-contents-as-binary filename) - (buffer-string)))) - (or (bolp) - (insert "\n")) - )) - -(mel-define-method-function (mime-insert-encoded-file filename (nil "base64")) - 'base64-insert-encoded-file) - -(defun base64-write-decoded-region (start end filename) - "Decode and write current region encoded by base64 into FILENAME. -START and END are buffer positions." - (interactive - (list (region-beginning) (region-end) - (read-file-name "Write decoded region to file: "))) - (if (and base64-internal-decoding-limit - (> (- end start) base64-internal-decoding-limit)) - (as-binary-process - (apply (function call-process-region) - start end (car base64-external-decoder) - nil nil nil - (append (cdr base64-external-decoder) - base64-external-decoder-option-to-specify-file - (list filename)))) - (let ((str (buffer-substring start end))) - (with-temp-buffer - (insert (base64-internal-decode-string str)) - (write-region-as-binary (point-min) (point-max) filename) - )))) - -(mel-define-method-function - (mime-write-decoded-region start end filename (nil "base64")) - 'base64-write-decoded-region) - - -;;; @ etc -;;; - -(defun pack-sequence (seq size) - "Split sequence SEQ into SIZE elements packs, -and return list of packs. [mel-b; tl-seq function]" - (let ((len (length seq)) (p 0) obj - unit (i 0) - dest) - (while (< p len) - (setq obj (elt seq p)) - (setq unit (cons obj unit)) - (setq i (1+ i)) - (if (= i size) - (progn - (setq dest (cons (reverse unit) dest)) - (setq unit nil) - (setq i 0) - )) - (setq p (1+ p)) - ) - (if unit - (setq dest (cons (reverse unit) dest)) - ) - (reverse dest) - )) - - -;;; @ end -;;; - -(provide 'mel-b) - -;;; mel-b.el ends here. diff --git a/mel-u.el b/mel-u.el index 5a756aa..3328e56 100644 --- a/mel-u.el +++ b/mel-u.el @@ -78,7 +78,7 @@ variable `uuencode-external-decoder'." (buffer-substring (match-beginning 0) (match-end 0)) ))))) - (default-directory mime-temp-directory)) + (default-directory temporary-file-directory)) (if filename (as-binary-process (apply (function call-process-region) @@ -131,7 +131,7 @@ variable `uuencode-external-encoder'." ) (mel-define-method mime-write-decoded-region (start end filename - (nil "x-gzip64")) + (nil "x-uue")) "Decode and write current region encoded by uuencode into FILENAME. START and END are buffer positions." (interactive @@ -147,7 +147,7 @@ START and END are buffer positions." (buffer-substring (match-beginning 0) (match-end 0)) ))))) - (default-directory mime-temp-directory)) + (default-directory temporary-file-directory)) (if file (as-binary-process (apply (function call-process-region) diff --git a/mel.el b/mel.el index cecef20..ccfc072 100644 --- a/mel.el +++ b/mel.el @@ -79,27 +79,77 @@ Content-Transfer-Encoding for it." ;;; @ setting for modules ;;; -(defvar mel-ccl-module (featurep 'mule)) +(mel-define-backend "7bit") +(mel-define-method-function (mime-encode-string string (nil "7bit")) + 'identity) +(mel-define-method-function (mime-decode-string string (nil "7bit")) + 'identity) +(mel-define-method mime-encode-region (start end (nil "7bit"))) +(mel-define-method mime-decode-region (start end (nil "7bit"))) +(mel-define-method-function (mime-insert-encoded-file filename (nil "7bit")) + 'insert-file-contents-as-binary) +(mel-define-method-function (mime-write-decoded-region + start end filename (nil "7bit")) + 'write-region-as-binary) + +(mel-define-backend "8bit" ("7bit")) + +(mel-define-backend "binary" ("8bit")) + +(when (and (fboundp 'base64-encode-string) + (subrp (symbol-function 'base64-encode-string))) + (mel-define-backend "base64") + (mel-define-method-function (mime-encode-string string (nil "base64")) + 'base64-encode-string) + (mel-define-method-function (mime-decode-string string (nil "base64")) + 'base64-decode-string) + (mel-define-method-function (mime-encode-region start end (nil "base64")) + 'base64-encode-region) + (mel-define-method-function (mime-decode-region start end (nil "base64")) + 'base64-decode-region) + (mel-define-method mime-insert-encoded-file (filename (nil "base64")) + "Encode contents of file FILENAME to base64, and insert the result. +It calls external base64 encoder specified by +`base64-external-encoder'. So you must install the program (maybe +mmencode included in metamail or XEmacs package)." + (interactive (list (read-file-name "Insert encoded file: "))) + (insert (base64-encode-string + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-as-binary filename) + (buffer-string)))) + (or (bolp) + (insert "\n")) + ) + + (mel-define-method-function (encoded-text-encode-string string (nil "B")) + 'base64-encode-string) + (mel-define-method encoded-text-decode-string (string (nil "B")) + (if (and (string-match B-encoded-text-regexp string) + (string= string (match-string 0 string))) + (base64-decode-string string) + (error "Invalid encoded-text %s" string))) + ) + +(mel-use-module 'mel-b-el '("base64" "B")) +(mel-use-module 'mel-q '("quoted-printable" "Q")) +(mel-use-module 'mel-g '("x-gzip64")) +(mel-use-module 'mel-u '("x-uue" "x-uuencode")) (defvar mel-b-ccl-module - (and mel-ccl-module + (and (featurep 'mule) (progn (require 'path-util) (module-installed-p 'mel-b-ccl) ))) (defvar mel-q-ccl-module - (and mel-ccl-module + (and (featurep 'mule) (progn (require 'path-util) (module-installed-p 'mel-q-ccl) ))) -(mel-use-module 'mel-b '("base64" "B")) -(mel-use-module 'mel-q '("quoted-printable" "Q")) -(mel-use-module 'mel-g '("x-gzip64")) -(mel-use-module 'mel-u '("x-uue" "x-uuencode")) - (if mel-b-ccl-module (mel-use-module 'mel-b-ccl '("base64" "B")) ) @@ -112,23 +162,6 @@ Content-Transfer-Encoding for it." (mel-use-module 'mel-b-dl '("base64" "B")) ) -(mel-define-backend "7bit") -(mel-define-method-function (mime-encode-string string (nil "7bit")) - 'identity) -(mel-define-method-function (mime-decode-string string (nil "7bit")) - 'identity) -(mel-define-method mime-encode-region (start end (nil "7bit"))) -(mel-define-method mime-decode-region (start end (nil "7bit"))) -(mel-define-method-function (mime-insert-encoded-file filename (nil "7bit")) - 'insert-file-contents-as-binary) -(mel-define-method-function (mime-write-decoded-region - start end filename (nil "7bit")) - 'write-region-as-binary) - -(mel-define-backend "8bit" ("7bit")) - -(mel-define-backend "binary" ("8bit")) - ;;; @ region ;;; diff --git a/mime-def.el b/mime-def.el index a952121..b6dfe20 100644 --- a/mime-def.el +++ b/mime-def.el @@ -24,8 +24,10 @@ ;;; Code: +(require 'mcharset) + (eval-and-compile - (defconst mime-library-product ["FLAM-DOODLE" (1 11 0) "$B>.F&(B 2.5R3.5/5.0"] + (defconst mime-library-product ["FLAM-DOODLE" (1 11 1) "$BIrF:Cc(B 5.0R4.0/11.0"] "Product name, version number and code name of MIME-library package.") ) @@ -61,16 +63,6 @@ (custom-handle-keyword 'default-mime-charset :group 'mime 'custom-variable) -(defcustom mime-temp-directory (or (getenv "MIME_TMP_DIR") - (getenv "TM_TMP_DIR") - (getenv "TMPDIR") - (getenv "TMP") - (getenv "TEMP") - "/tmp/") - "*Directory for temporary files." - :group 'mime - :type 'directory) - (defcustom mime-uuencode-encoding-name-list '("x-uue" "x-uuencode") "*List of encoding names for uuencode format." :group 'mime @@ -96,15 +88,18 @@ ;;; @ about STD 11 ;;; -(defconst std11-quoted-pair-regexp "\\\\.") -(defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n)) -(defconst std11-qtext-regexp - (concat "[^" (char-list-to-string std11-non-qtext-char-list) "]")) +(eval-and-compile + (defconst std11-quoted-pair-regexp "\\\\.") + (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n)) + (defconst std11-qtext-regexp + (eval-when-compile + (concat "[^" (apply #'string std11-non-qtext-char-list) "]")))) (defconst std11-quoted-string-regexp - (concat "\"" - (regexp-* - (regexp-or std11-qtext-regexp std11-quoted-pair-regexp)) - "\"")) + (eval-when-compile + (concat "\"" + (regexp-* + (regexp-or std11-qtext-regexp std11-quoted-pair-regexp)) + "\""))) ;;; @ about MIME @@ -407,8 +402,13 @@ specialized parameter. (car (car ARGS)) is name of variable and (nth )))) (put 'mm-define-method 'lisp-indent-function 'defun) -(put 'mm-define-method 'edebug-form-spec - '(&define name ((arg symbolp) &rest arg) def-body)) +(def-edebug-spec mm-define-method + (&define name ((arg symbolp) + [&rest arg] + [&optional ["&optional" arg &rest arg]] + &optional ["&rest" arg] + ) + def-body)) (defsubst mm-arglist-to-arguments (arglist) (let (dest) @@ -527,10 +527,14 @@ variable and (nth 1 (car (last ARGS))) is name of backend (encoding)." ))) (defvar base64-dl-module - (and (fboundp 'dynamic-link) - (let ((path (expand-file-name "base64.so" exec-directory))) - (and (file-exists-p path) - path)))) + (if (and (fboundp 'base64-encode-string) + (subrp (symbol-function 'base64-encode-string))) + nil + (if (fboundp 'dynamic-link) + (let ((path (expand-file-name "base64.so" exec-directory))) + (and (file-exists-p path) + path) + )))) ;;; @ end diff --git a/mime-en.sgml b/mime-en.sgml index 2523585..de14cb9 100644 --- a/mime-en.sgml +++ b/mime-en.sgml @@ -299,9 +299,9 @@ used as default value.

-Symbol to indicate default value of MIME-charset. +Symbol to indicate default value of MIME charset.

-It is used when MIME-charset is not specified. +It is used when MIME charset is not specified.

It is originally variable of APEL. @@ -563,15 +563,16 @@ Return value of parameter of content-type. Content-Type parser

- string + string

-Parse string as field-body of Content-Type field. +Parse string as a field-body of Content-Type field, and +return the result as mime-content-type structure.

-Read field-body of Content-Type field from current-buffer, -and return parsed it. +Parse Content-Type field of the current buffer, and return the result +as mime-content-type structure.

Return nil if Content-Type field is not found. @@ -581,7 +582,7 @@ Return nil if Content-Type field is not found. Content-Type utility

- type subtype + type subtype

Return type/subtype string from type and subtype. @@ -596,10 +597,10 @@ specify presentation of an entity or attributes of an entity, such as file name. + author="S. Dorner, K. Moore and R. Troost" + title="Communicating Presentation Information in Internet + Messages: The Content-Disposition Header" date="August + 1997">

FLIM provides parser for Content-Disposition field and structure mime-content-disposition to store information of @@ -649,14 +650,16 @@ Return filename of content-disposition. string

Parse string as field-body of Content-Disposition field, -and return the result. +and return the result as mime-content-disposition +structure.

-Read field-body of Content-Disposition field from current-buffer, +Parse Content-Disposition field of the current buffer, and return the +result as mime-content-disposition structure.

-Return nil if Content-Disposition field is not found. +Return nil if Content-Disposition field is not found. @@ -678,19 +681,21 @@ Content-Transfer-Encoding. Content-Transfer-Encoding parser

- string + string

-string $B$r(B content-transfer-encoding $B$H$7$F2r@O$7$?7k2L$rJV$9!#(B +Parse string as a field-body of Content-Transfer-Encoding +field, and return the result. - default-encoding + default-encoding

-$B8=:_$N(B buffer $B$N(B Content-Transfer-Encoding $BMs$rFI$_ -Content-Transfer-Encoding $BMs$,B8:_$7$J$$>l9g$O(B -default-encoding $B$rJV$9!#(B +Return default-encoding if Content-Transfer-Encoding field +is not found. If it is not specified, nil is used as the +default value. @@ -713,9 +718,10 @@ using encoding. - string encoding + string encoding

-string $B$r(B encoding $B$H$7$FI|9f$7$?7k2L$rJV$7$^$9!#(B +Decode string which is encoded in encoding, and +return the result. @@ -852,28 +858,49 @@ FLIM $B$O$3$l$i$rId9f2=!&I|9f2=$9$k5!G=$rDs6!$7$^$9!#(B

Header encoding/decoding Header encoder/decoder

- - code-conversion separator + + code-conversion separator

Decode MIME encoded-words in header fields.

-If code-conversion is nil, it decodes only -encoded-words. If it is mime-charset, it decodes non-ASCII bit -patterns as the mime-charset. Otherwise it decodes non-ASCII bit -patterns as the default-mime-charset. +If code-conversion is nil, only encoded-words +are decoded. If code-conversion is a MIME +charset, non-ASCII bit patterns are decoded as the MIME +charset. Otherwise non-ASCII bit patterns are decoded as the +default-mime-charset.

-If separator is not nil, it is used as header separator. +If separator is not nil, it is used as header +separator. - code-conversion + code-conversion

Encode header fields to network representation, such as MIME encoded-word.

-It refer variable eword-field-encoding-method-alist. +Each field is encoded as corresponding method specified by variable +eword-field-encoding-method-alist. + +

+Association list to specify field encoding method. Each element looks +like (FIELD . METHOD). +

+If METHOD is mime, the FIELD will be encoded into MIME +format (encoded-word). +

+If METHOD is nil, the FIELD will not be encoded. +

+If METHOD is a MIME charset, the FIELD will be encoded as the charset +when it must be convert into network-code. +

+Otherwise the FIELD will be encoded as variable +default-mime-charset when it must be convert into +network-code. + +

Various Customization custom diff --git a/mime-en.texi b/mime-en.texi index e53af52..6da91cd 100644 --- a/mime-en.texi +++ b/mime-en.texi @@ -103,7 +103,8 @@ mime-entity.@refill If @var{buffer} is omitted, current buffer is used.@refill @var{type} is representation-type of created -mime-entity. (cf. @ref{mm-backend}) Default value is @var{buffer}. +mime-entity. (cf. @ref{mm-backend}) + Default value is @var{buffer}. @end defun @@ -329,10 +330,9 @@ value. @defvar default-mime-charset -Symbol to indicate default value of MIME-charset -(@ref{MIME-charset}).@refill +Symbol to indicate default value of MIME charset (@ref{MIME charset}).@refill -It is used when MIME-charset is not specified.@refill +It is used when MIME charset is not specified.@refill It is originally variable of APEL. @end defvar @@ -626,14 +626,15 @@ Return value of @var{parameter} of @var{content-type}. @defun mime-parse-Content-Type string -Parse @var{string} as field-body of Content-Type field. +Parse @var{string} as a field-body of Content-Type field, and return the +result as mime-content-type (@ref{mime-content-type}) structure. @end defun @defun mime-read-Content-Type -Read field-body of Content-Type field from current-buffer, and return -parsed it.@refill +Parse Content-Type field of the current buffer, and return the result as +mime-content-type (@ref{mime-content-type}) structure.@refill Return @code{nil} if Content-Type field is not found. @end defun @@ -724,15 +725,18 @@ Return filename of @var{content-disposition}. @defun mime-parse-Content-Disposition string Parse @var{string} as field-body of Content-Disposition field, and -return the result. +return the result as mime-content-disposition +(@ref{mime-content-disposition}) structure. @end defun @defun mime-read-Content-Disposition -Read field-body of Content-Disposition field from current-buffer,@refill +Parse Content-Disposition field of the current buffer, and return the +result as mime-content-disposition (@ref{mime-content-disposition}) +structure.@refill -Return nil if Content-Disposition field is not found. +Return @code{nil} if Content-Disposition field is not found. @end defun @@ -765,17 +769,18 @@ Content-Transfer-Encoding. @defun mime-parse-Content-Transfer-Encoding string -@var{string} $B$r(B content-transfer-encoding $B$H$7$F2r@O$7$?7k2L$rJV$9!#(B +Parse @var{string} as a field-body of Content-Transfer-Encoding field, +and return the result. @end defun @defun mime-read-Content-Transfer-Encoding &optional default-encoding -$B8=:_$N(B buffer $B$N(B Content-Transfer-Encoding $BMs$rFI$_l9g$O(B@var{default-encoding} $B$r(B -$BJV$9!#(B +Return @var{default-encoding} if Content-Transfer-Encoding field is not +found. If it is not specified, @code{nil} is used as the default value. @end defun @@ -800,7 +805,8 @@ Decode region @var{start} to @var{end} of current buffer using @defun mime-decode-string string encoding -@var{string} $B$r(B @var{encoding} $B$H$7$FI|9f$7$?7k2L$rJV$7$^$9!#(B +Decode @var{string} which is encoded in @var{encoding}, and return the +result. @end defun @@ -948,16 +954,17 @@ FLIM $B$O$3$l$i$rId9f2=!&I|9f2=$9$k5!G=$rDs6!$7$^$9!#(B @node Header encoder/decoder, , encoded-word, encoded-word @section Header encoding/decoding -@defun eword-encode-header &optional code-conversion separator +@defun eword-decode-header &optional code-conversion separator Decode MIME encoded-words in header fields.@refill -If @var{code-conversion} is @code{nil}, it decodes only encoded-words. -If it is mime-charset, it decodes non-ASCII bit patterns as the -mime-charset. Otherwise it decodes non-ASCII bit patterns as the -default-mime-charset.@refill +If @var{code-conversion} is @code{nil}, only encoded-words are decoded. +If @var{code-conversion} is a MIME charset (@ref{MIME charset}), +non-ASCII bit patterns are decoded as the MIME charset. Otherwise +non-ASCII bit patterns are decoded as the +@code{default-mime-charset}. (cf. @ref{entity formatting}) @refill -If @var{separator} is not nil, it is used as header separator. +If @var{separator} is not @code{nil}, it is used as header separator. @end defun @@ -966,10 +973,29 @@ If @var{separator} is not nil, it is used as header separator. Encode header fields to network representation, such as MIME encoded-word.@refill -It refer variable @code{eword-field-encoding-method-alist}. +Each field is encoded as corresponding method specified by variable +@code{eword-field-encoding-method-alist}. @end defun +@defvar eword-field-encoding-method-alist + +Association list to specify field encoding method. Each element looks +like (FIELD . METHOD).@refill + +If METHOD is @code{mime}, the FIELD will be encoded into MIME format +(encoded-word).@refill + +If METHOD is @code{nil}, the FIELD will not be encoded.@refill + +If METHOD is a MIME charset, the FIELD will be encoded as the charset +when it must be convert into network-code.@refill + +Otherwise the FIELD will be encoded as variable +@code{default-mime-charset} when it must be convert into network-code. +@end defvar + + @node custom, Appendix, encoded-word, Top @chapter Various Customization diff --git a/mime-ja.sgml b/mime-ja.sgml index 7afcd96..fe6794b 100644 --- a/mime-ja.sgml +++ b/mime-ja.sgml @@ -708,9 +708,9 @@ using encoding. - string encoding + string encoding

-string $B$r(B encoding $B$H$7$FI|9f$7$?7k2L$rJV$7$^$9!#(B +string $B$r(B encoding $B$H$7$FI|9f$7$?7k2L$rJV$9!#(B @@ -847,28 +847,49 @@ FLIM $B$O$3$l$i$rId9f2=!&I|9f2=$9$k5!G=$rDs6!$7$^$9!#(B

Header $B$NId9f2=!&I|9f2=(B Header encoder/decoder

- - code-conversion separator + + code-conversion separator

-Decode MIME encoded-words in header fields. +Header $BCf$N(B encoded-word $B$rI|9f$9$k!#(B

-If code-conversion is nil, it decodes only -encoded-words. If it is mime-charset, it decodes non-ASCII bit -patterns as the mime-charset. Otherwise it decodes non-ASCII bit -patterns as the default-mime-charset. +$B$b$7(B code-conversion $B$,(B nil $B$J$i!"(Bencoded-word +$B$@$1$,I|9f$5$l$k!#$b$7!"(Bcode-conversion $B$,(B MIME +charset $B$J$i!"Hs(B ASCII bit patterns $B$O$=$N(B MIME charset $B$H$7$F(B +$BI|9f$5$l$k!#$3$l0J30$N>l9g!"Hs(B ASCII bit patterns $B$O(B +default-mime-charset. $B$H$7$FI|9f$5$l$k!#(B

-If separator is not nil, it is used as header separator. +$B$b$7(B separator $B$,(B nil $B$G$J$1$l$P!"$=$NCM$,(B +header separator $B$H$7$FMQ$$$i$l$k!#(B - code-conversion + code-conversion

-Encode header fields to network representation, such as MIME -encoded-word. +Header $B$r(B network $BI=8=$KId9f2=$9$k!#(B

-It refer variable eword-field-encoding-method-alist. +$B3F(B field $B$O(B eword-field-encoding-method-alist $B$G;XDj$5$l(B +$B$?J}<0$GId9f2=$5$l$k!#(B + +

+Association list to specify field encoding method. Each element looks +like (FIELD . METHOD). +

+If METHOD is mime, the FIELD will be encoded into MIME +format (encoded-word). +

+If METHOD is nil, the FIELD will not be encoded. +

+If METHOD is a MIME charset, the FIELD will be encoded as the charset +when it must be convert into network-code. +

+Otherwise the FIELD will be encoded as variable +default-mime-charset when it must be convert into +network-code. + +

$B0lHL@_Dj(B custom diff --git a/mime-ja.texi b/mime-ja.texi index f5cf4fc..171e5ad 100644 --- a/mime-ja.texi +++ b/mime-ja.texi @@ -796,7 +796,7 @@ Decode region @var{start} to @var{end} of current buffer using @defun mime-decode-string string encoding -@var{string} $B$r(B @var{encoding} $B$H$7$FI|9f$7$?7k2L$rJV$7$^$9!#(B +@var{string} $B$r(B @var{encoding} $B$H$7$FI|9f$7$?7k2L$rJV$9!#(B @end defun @@ -944,28 +944,48 @@ FLIM $B$O$3$l$i$rId9f2=!&I|9f2=$9$k5!G=$rDs6!$7$^$9!#(B @node Header encoder/decoder, , encoded-word, encoded-word @section Header $B$NId9f2=!&I|9f2=(B -@defun eword-encode-header &optional code-conversion separator +@defun eword-decode-header &optional code-conversion separator -Decode MIME encoded-words in header fields.@refill +Header $BCf$N(B encoded-word $B$rI|9f$9$k!#(B@refill -If @var{code-conversion} is @code{nil}, it decodes only encoded-words. -If it is mime-charset, it decodes non-ASCII bit patterns as the -mime-charset. Otherwise it decodes non-ASCII bit patterns as the -default-mime-charset.@refill +$B$b$7(B @var{code-conversion} $B$,(B @code{nil} $B$J$i!"(Bencoded-word $B$@$1$,I|9f$5(B +$B$l$k!#$b$7!"(B@var{code-conversion} $B$,(B MIME charset (@ref{MIME charset}) +$B$J$i!"Hs(B ASCII bit patterns $B$O$=$N(B MIME charset $B$H$7$FI|9f$5$l$k!#$3$l0J(B +$B30$N>l9g!"Hs(B ASCII bit patterns $B$O(B@code{default-mime-charset}. $B$H$7$FI|(B +$B9f$5$l$k!#(B(cf. @ref{entity formatting}) @refill -If @var{separator} is not nil, it is used as header separator. +$B$b$7(B @var{separator} $B$,(B @code{nil} $B$G$J$1$l$P!"$=$NCM$,(Bheader separator +$B$H$7$FMQ$$$i$l$k!#(B @end defun @defun eword-encode-header &optional code-conversion -Encode header fields to network representation, such as MIME -encoded-word.@refill +Header $B$r(B network $BI=8=$KId9f2=$9$k!#(B@refill -It refer variable @code{eword-field-encoding-method-alist}. +$B3F(B field $B$O(B @code{eword-field-encoding-method-alist} $B$G;XDj$5$l$?J}<0$G(B +$BId9f2=$5$l$k!#(B @end defun +@defvar eword-field-encoding-method-alist + +Association list to specify field encoding method. Each element looks +like (FIELD . METHOD).@refill + +If METHOD is @code{mime}, the FIELD will be encoded into MIME format +(encoded-word).@refill + +If METHOD is @code{nil}, the FIELD will not be encoded.@refill + +If METHOD is a MIME charset, the FIELD will be encoded as the charset +when it must be convert into network-code.@refill + +Otherwise the FIELD will be encoded as variable +@code{default-mime-charset} when it must be convert into network-code. +@end defvar + + @node custom, Appendix, encoded-word, Top @chapter $B0lHL@_Dj(B diff --git a/mmgeneric.el b/mmgeneric.el index 447b3af..6dbfe4a 100644 --- a/mmgeneric.el +++ b/mmgeneric.el @@ -144,48 +144,41 @@ ) t))) +(defun mime-insert-header-from-buffer (buffer start end + &optional invisible-fields + visible-fields) + (let ((the-buf (current-buffer)) + f-b p f-e field-name len field field-body) + (save-excursion + (set-buffer buffer) + (save-restriction + (narrow-to-region start end) + (goto-char start) + (while (re-search-forward std11-field-head-regexp nil t) + (setq f-b (match-beginning 0) + p (match-end 0) + field-name (buffer-substring f-b p) + len (string-width field-name) + f-e (std11-field-end)) + (when (mime-visible-field-p field-name + visible-fields invisible-fields) + (setq field (buffer-substring f-b (1- p)) + field-body (buffer-substring p f-e)) + (with-current-buffer the-buf + (insert + field-name + (eword-decode-field-body field-body field nil t) + "\n") + ))))))) + (mm-define-method insert-header ((entity generic) &optional invisible-fields visible-fields) - (save-restriction - (narrow-to-region (point)(point)) - (let ((the-buf (current-buffer)) - (src-buf (mime-entity-buffer entity)) - (h-end (mime-entity-header-end-internal entity)) - beg p end field-name len field-body decoded) - (save-excursion - (set-buffer src-buf) - (goto-char (mime-entity-header-start-internal entity)) - (save-restriction - (narrow-to-region (point) h-end) - (while (re-search-forward std11-field-head-regexp nil t) - (setq beg (match-beginning 0) - p (match-end 0) - field-name (buffer-substring beg (1- p)) - len (string-width field-name) - end (std11-field-end)) - (when (mime-visible-field-p field-name - visible-fields invisible-fields) - (save-excursion - (set-buffer the-buf) - (setq field-body (ew-lf-crlf-to-crlf - (save-excursion - (set-buffer src-buf) - (buffer-substring p end)))) - (setq decoded (ew-decode-field field-name field-body)) - (unless (equal field-body decoded) - (setq decoded (ew-crlf-refold - decoded - (1+ (string-width field-name)) - fill-column))) - (setq beg (point)) - (insert field-name) - (insert ":") - (insert (ew-crlf-to-lf decoded)) - (insert "\n") - (add-text-properties beg (point) - (list 'original-field-name field-name - 'original-field-body field-body)) - )))))))) + (mime-insert-header-from-buffer + (mime-entity-buffer entity) + (mime-entity-header-start-internal entity) + (mime-entity-header-end-internal entity) + invisible-fields visible-fields) + ) (mm-define-method insert-text-content ((entity generic)) (insert