;;; tm-play.el --- decoder for tm-view.el;; Copyright (C) 1994,1995,1996,1997 Free Software Foundation, Inc.;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>;; Created: 1995/9/26 (separated from tm-view.el);; Version: $Id$;; Keywords: mail, news, MIME, multimedia;; This file is part of tm (Tools for MIME).;; 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'tm-view);;; @ content decoder;;;(defvarmime-preview/after-decoded-positionnil)(defunmime-preview/decode-content()(interactive)(let((pc(mime-preview/point-pcinfo(point))))(ifpc(let((the-buf(current-buffer)))(setqmime-preview/after-decoded-position(point))(set-buffer(mime::preview-content-info/bufferpc))(mime-article/decode-content(mime::preview-content-info/content-infopc))(if(eq(current-buffer)(mime::preview-content-info/bufferpc))(progn(set-bufferthe-buf)(goto-charmime-preview/after-decoded-position)))))))(defunmime-article/decode-content(cinfo)(let((beg(mime::content-info/point-mincinfo))(end(mime::content-info/point-maxcinfo))(ctype(or(mime::content-info/typecinfo)"text/plain"))(params(mime::content-info/parameterscinfo))(encoding(mime::content-info/encodingcinfo)));; Check for VM(if(<beg(point-min))(setqbeg(point-min)))(if(<(point-max)end)(setqend(point-max)))(let(methodcalret)(setqcal(list*(cons'typectype)(cons'encodingencoding)(cons'major-modemajor-mode)params))(ifmime-viewer/decoding-mode(setqcal(cons(cons'modemime-viewer/decoding-mode)cal)))(setqret(mime/get-content-decoding-alistcal))(setqmethod(cdr(assq'methodret)))(cond((and(symbolpmethod)(fboundpmethod))(funcallmethodbegendret))((and(listpmethod)(stringp(carmethod)))(mime-article/start-external-method-regionbegendret))(t(mime-article/show-output-buffer"No method are specified for %s\n"ctype))))))(defunfield-unifier-for-mode(ab)(let((va(cdra)))(if(if(conspva)(member(cdrb)va)(equalva(cdrb)))(listnilbnil))))(defunmime/get-content-decoding-alist(al)(get-unified-alistmime/content-decoding-conditional));;; @ external decoder;;;(defunmime-article/start-external-method-region(begendcal)(save-excursion(save-restriction(narrow-to-regionbegend)(goto-charbeg)(let((method(cdr(assoc'methodcal)))(name(mime-article/get-filenamecal)))(ifmethod(let((file(make-temp-name(expand-file-name"TM"mime/tmp-dir)))bargs)(if(nth1method)(setqbbeg)(setqb(if(re-search-forward"^$"nilt)(1+(match-end0))(point-min))))(goto-charb)(write-regionbendfile)(message"External method is starting...")(setqcal(put-alist'name(replace-as-filenamename)cal))(setqcal(put-alist'filefilecal))(setqargs(nconc(list(carmethod)mime/output-buffer-name(carmethod))(mime-article/make-method-argscal(cdr(cdrmethod)))))(apply(functionstart-process)args)(mime-article/show-output-buffer)))))))(defunmime-article/make-method-args(calformat)(mapcar(function(lambda(arg)(if(stringparg)arg(let*((item(evalarg))(ret(cdr(associtemcal))))(ifretret(if(eqitem'encoding)"7bit"""))))))format))(defunmime-article/show-output-buffer(&restforms)(get-buffer-createmime/output-buffer-name)(let((the-win(selected-window))(win(get-buffer-windowmime/output-buffer-name)))(orwin(if(andmime/output-buffer-window-is-shared-with-bbdb(boundp'bbdb-buffer-name)(setqwin(get-buffer-windowbbdb-buffer-name)))(set-window-bufferwinmime/output-buffer-name)(select-window(get-buffer-windowmime::article/preview-buffer))(setqwin(split-window-vertically(/(*(window-height)3)4)))(set-window-bufferwinmime/output-buffer-name)))(select-windowwin)(goto-char(point-max))(ifforms(insert(apply(functionformat)forms)))(select-windowthe-win)));;; @ file name;;;(defvarmime-viewer/file-name-char-regexp"[A-Za-z0-9+_-]")(defvarmime-viewer/file-name-regexp-1(concatmime-viewer/file-name-char-regexp"+\\."mime-viewer/file-name-char-regexp"+"))(defvarmime-viewer/file-name-regexp-2(concat(regexp-*mime-viewer/file-name-char-regexp)"\\(\\."mime-viewer/file-name-char-regexp"+\\)*"))(defunmime-article/get-original-filename(param&optionalencoding)(or(mime-article/get-uu-filenameparamencoding)(let(ret)(or(if(or(and(setqret(mime/Content-Disposition))(setqret(assoc"filename"(cdrret))))(setqret(assoc"name"param))(setqret(assoc"x-name"param)))(std11-strip-quoted-string(cdrret)))(if(setqret(std11-find-field-body'("Content-Description""Subject")))(if(or(string-matchmime-viewer/file-name-regexp-1ret)(string-matchmime-viewer/file-name-regexp-2ret))(substringret(match-beginning0)(match-end0))))))))(defunmime-article/get-filename(param)(replace-as-filename(mime-article/get-original-filenameparam)));;; @ mail/news message;;;(defunmime-viewer/quitting-method-for-mime/show-message-mode()(let((mothermime::preview/mother-buffer)(win-confmime::preview/original-window-configuration))(kill-buffer(mime::preview-content-info/buffer(carmime::preview/content-list)))(mime-viewer/kill-buffer)(set-window-configurationwin-conf)(pop-to-buffermother);;(goto-char (point-min));;(mime-viewer/up-content)))(defunmime-article/view-message/rfc822(begendcal)(let*((cnum(mime-article/point-content-numberbeg))(cur-buf(current-buffer))(new-name(format"%s-%s"(buffer-name)cnum))(mothermime::article/preview-buffer)(code-converter(or(cdr(assqmajor-modemime-viewer/code-converter-alist))'mime-viewer/default-code-convert-region))str)(setqstr(buffer-substringbegend))(switch-to-buffernew-name)(erase-buffer)(insertstr)(goto-char(point-min))(if(re-search-forward"^\n"nilt)(delete-region(point-min)(match-end0)))(setqmajor-mode'mime/show-message-mode)(setqmime::article/code-convertercode-converter)(mime/viewer-modemother)));;; @ message/partial;;;(defvarmime-article/coding-system-alist(list(cons'mh-show-mode*noconv*)(const(mime-charset-to-coding-systemdefault-mime-charset))))(cond((boundp'MULE); for MULE 2.3 or older(defunmime-article::write-region(startendfile)(let((file-coding-system(cdr(or(assqmajor-modemime-article/coding-system-alist)(assqtmime-article/coding-system-alist)))))(write-regionstartendfile))))((featurep'mule); for Emacs/mule and XEmacs/mule(defunmime-article::write-region(startendfile)(let((coding-system-for-write(cdr(or(assqmajor-modemime-article/coding-system-alist)(assqtmime-article/coding-system-alist)))))(write-regionstartendfile))))((boundp'NEMACS); for NEmacs(defunmime-article::write-region(startendfile)(let((kanji-fileio-code(cdr(or(assqmajor-modemime-article/kanji-code-alist)(assqtmime-article/kanji-code-alist)))))(write-regionstartendfile))))(t; for Emacs 19 or older and XEmacs without mule(defalias'mime-article::write-region'write-region)))(defunmime-article/decode-message/partial(begendcal)(goto-charbeg)(let*((root-dir(expand-file-name(concat"m-prts-"(user-login-name))mime/tmp-dir))(id(cdr(assoc"id"cal)))(number(cdr(assoc"number"cal)))(total(cdr(assoc"total"cal)))file(mothermime::article/preview-buffer))(or(file-exists-proot-dir)(make-directoryroot-dir))(setqid(replace-as-filenameid))(setqroot-dir(concatroot-dir"/"id))(or(file-exists-proot-dir)(make-directoryroot-dir))(setqfile(concatroot-dir"/FULL"))(if(file-exists-pfile)(let((full-buf(get-buffer-create"FULL"))(pwin(or(get-buffer-windowmother)(get-largest-window))))(save-window-excursion(set-bufferfull-buf)(erase-buffer)(as-binary-input-file(insert-file-contentsfile))(setqmajor-mode'mime/show-message-mode)(mime/viewer-modemother))(set-window-bufferpwin(save-excursion(set-bufferfull-buf)mime::article/preview-buffer))(select-windowpwin))(re-search-forward"^$")(goto-char(1+(match-end0)))(setqfile(concatroot-dir"/"number))(mime-article::write-region(point)(point-max)file)(let((total-file(concatroot-dir"/CT")))(setqtotal(iftotal(progn(or(file-exists-ptotal-file)(save-excursion(set-buffer(get-buffer-createmime/temp-buffer-name))(erase-buffer)(inserttotal)(write-filetotal-file)(kill-buffer(current-buffer))))(string-to-numbertotal))(and(file-exists-ptotal-file)(save-excursion(set-buffer(find-file-noselecttotal-file))(prog1(and(re-search-forward"[0-9]+"nilt)(string-to-number(buffer-substring(match-beginning0)(match-end0))))(kill-buffer(current-buffer))))))))(if(andtotal(>total0))(catch'tag(save-excursion(set-buffer(get-buffer-createmime/temp-buffer-name))(let((full-buf(current-buffer)))(erase-buffer)(let((i1))(while(<=itotal)(setqfile(concatroot-dir"/"(int-to-stringi)))(or(file-exists-pfile)(throw'tagnil))(as-binary-input-file(insert-file-contentsfile))(goto-char(point-max))(setqi(1+i))))(as-binary-output-file(write-file(concatroot-dir"/FULL")))(let((i1))(while(<=itotal)(let((file(format"%s/%d"root-diri)))(and(file-exists-pfile)(delete-filefile)))(setqi(1+i))))(let((file(expand-file-name"CT"root-dir)))(and(file-exists-pfile)(delete-filefile)))(save-window-excursion(setqmajor-mode'mime/show-message-mode)(mime/viewer-modemother))(let((pwin(or(get-buffer-windowmother)(get-largest-window)))(pbuf(save-excursion(set-bufferfull-buf)mime::article/preview-buffer)))(set-window-bufferpwinpbuf)(select-windowpwin)))))))));;; @ rot13-47;;;(or(boundp'view-mode-map)(require'view))(defconstmime-view-text/plain-mode-map(copy-keymapview-mode-map))(define-keymime-view-text/plain-mode-map"q"(functionmime-view-text/plain-exit))(defunmime-view-text/plain-mode()"\\{mime-view-text/plain-mode-map}"(setqbuffer-read-onlyt)(setqmajor-mode'mime-view-text/plain-mode)(setqmode-name"MIME-View text/plain")(use-local-mapmime-view-text/plain-mode-map))(defunmime-view-text/plain-exit()(interactive)(kill-buffer(current-buffer)))(defunmime-article/decode-caesar(begendcal)(let*((cnum(mime-article/point-content-numberbeg))(cur-buf(current-buffer))(new-name(format"%s-%s"(buffer-name)cnum))(mothermime::article/preview-buffer)(charset(cdr(assoc"charset"cal)))(encoding(cdr(assq'encodingcal)))(modemajor-mode)str)(setqstr(buffer-substringbegend))(let((pwin(or(get-buffer-windowmother)(get-largest-window)))(buf(get-buffer-createnew-name)))(set-window-bufferpwinbuf)(set-bufferbuf)(select-windowpwin))(setqbuffer-read-onlynil)(erase-buffer)(insertstr)(goto-char(point-min))(if(re-search-forward"^\n"nilt)(delete-region(point-min)(match-end0)))(let((m(cdr(or(assqmodemime-viewer/code-converter-alist)(assqtmime-viewer/code-converter-alist)))))(and(functionpm)(funcallmcharsetencoding)))(save-excursion(set-mark(point-min))(goto-char(point-max))(tm:caesar-region))(set-buffer-modified-pnil)(mime-view-text/plain-mode)));;; @ end;;;(provide'tm-play);;; tm-play.el ends here