X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=tm-partial.el;h=7ef93a5060d540eb88e31d866f69680d0f577f20;hb=c82260725e75fa17323d555e071923fb29f53992;hp=99542093d51bc2f919747cf21fe4d0ed66828ce4;hpb=fc6b2cc1de3a2ee19d3cd62650673e7bf0d82edb;p=elisp%2Ftm.git diff --git a/tm-partial.el b/tm-partial.el index 9954209..7ef93a5 100644 --- a/tm-partial.el +++ b/tm-partial.el @@ -1,178 +1,114 @@ -;;; -;;; tm-partial.el -;;; -;;; Grabbing all MIME "message/partial"s. -;;; by Yasuo OKABE @ Kyoto University 1994 -;;; modified by MORIOKA Tomohiko +;;; tm-partial.el --- Grabbing all MIME "message/partial"s. -;; original file is -;; gif.el written by Art Mellor @ Cayman Systems, Inc. 1991 +;; Copyright (C) 1995,1996 Free Software Foundation, Inc. -;;; $Id: tm-partial.el,v 2.0 1995/03/12 16:14:44 morioka Exp $ +;; Author: OKABE Yasuo @ Kyoto University +;; MORIOKA Tomohiko +;; Version: +;; $Id: tm-partial.el,v 7.13 1996/08/30 04:27:52 morioka Exp $ +;; Keywords: mail, news, MIME, multimedia, message/partial -(require 'tm-view) +;; This file is a part of tm (Tools for MIME). -;; This regular expression controls what types of subject lines can be -;; parsed. Currently handles lines like: -;; foo [1/3] -;; foo (1/3) -;; foo 1/3 -;; foo [1 of 3] -;; foo (1 of 3) -;; foo 1 of 3 -;; foo1 of 3 +;; 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. -(defvar mime/gp:subject-start-regexp "[ \t]*\\(v[0-9]+i[0-9]+:[ \t]+\\)?") +;; 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. -(defvar mime/gp:subject-end-regexp "\\([[(]?\\)\\([0-9]+\\)\\(/\\| [oO][fF] \\)\\([0-9]+\\)\\([])]?\\)[ \t]*$") +;; You should have received a copy of the GNU General Public License +;; along with this program; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. -;; display Article at the cursor in Subject buffer. -(defun mime/gp:display-article () - (save-excursion - (cond - ((eq target 'gnus4) - (gnus-summary-display-article (gnus-summary-article-number))) - ((eq target 'mh-e) - (mh-show)) - (t - (error "Fatal. Unsupported mode"))))) +;;; Code: + +(require 'tm-view) +(require 'tm-play) + +(defvar tm-partial/preview-article-method-alist nil) -(defun mime/decode-message/grab-partials (beg end cal) +;; display Article at the cursor in Subject buffer. +(defun tm-partial/preview-article (target) + (let ((f (assq target tm-partial/preview-article-method-alist))) + (if f + (funcall (cdr f)) + (error "Fatal. Unsupported mode") + ))) + +(defun mime-article/grab-message/partials (beg end cal) (interactive) (let* ((id (cdr (assoc "id" cal))) - (number (cdr (assoc "number" cal))) - (total (cdr (assoc "total" cal))) (buffer (generate-new-buffer id)) (mother mime::article/preview-buffer) - target - subject-buf - (article-buf (buffer-name (current-buffer))) - (subject-id nil) - (part-num 1) - (part-missing nil)) - (cond ((eq major-mode 'gnus-article-mode) - (progn - (setq subject-buf gnus-summary-buffer) - (setq target 'gnus4))) - ((eq major-mode 'mh-show-mode) - (progn - (string-match "^show-\\(.+\\)$" article-buf) - (setq subject-buf (substring article-buf (match-beginning 1) (match-end 1))) - (setq target 'mh-e))) - (t (error "%s is not supported. Sorry." major-mode))) + (target (cdr (assq 'major-mode cal))) + (article-buffer (buffer-name (current-buffer))) + (subject-buf (eval (cdr (assq 'summary-buffer-exp cal)))) + subject-id + (root-dir (expand-file-name + (concat "m-prts-" (user-login-name)) mime/tmp-dir)) + full-file) + (setq root-dir (concat root-dir "/" (replace-as-filename id))) + (setq full-file (concat root-dir "/FULL")) + + (if (null target) + (error "%s is not supported. Sorry." target) + ) - (if (and (eq beg (point-min)) (eq end (point-max))) - (save-excursion - (goto-char (point-min)) - (re-search-forward "^$") - (let ((delim (match-beginning 0))) - (goto-char (point-min)) - (if (re-search-forward "^[Ss]ubject:.*$" delim t) - (let ((tail (match-end 0))) - (beginning-of-line) - (re-search-forward (concat "^[Ss]ubject:" mime/gp:subject-start-regexp) tail t) - (let ((start (point))) - (if (and (re-search-forward mime/gp:subject-end-regexp tail t) - (eq (string-to-int number) - (string-to-int (buffer-substring (match-beginning 2) (match-end 2)))) - (eq (string-to-int total) - (string-to-int (buffer-substring (match-beginning 4) (match-end 4))))) - (setq subject-id (buffer-substring start (match-end 1))) - (setq part-missing (string-to-int number))))) - (setq part-missing t)))) - (setq part-missing t)) - ;; if you can't parse the subject line, try simple decoding method - (if (or part-missing - (not (y-or-n-p "Merge partials?"))) + (if (or (file-exists-p full-file) + (not (y-or-n-p "Merge partials?")) + ) (progn (kill-buffer buffer) - (mime/decode-message/partial-region beg end cal)) - (progn - (set-buffer subject-buf) - (setq part-missing (mime/gp:part-missing-p subject-id (string-to-int total))) - (if part-missing - (progn - (kill-buffer buffer) - (error "Couldn't find part %d" part-missing))) - (save-excursion - (while (<= part-num (string-to-int total)) - (goto-char (point-min)) - (message "Grabbing part %d of %d" part-num (string-to-int total)) - (re-search-forward - (concat (regexp-quote subject-id) "0*" - (int-to-string part-num)) nil t) - (mime/gp:display-article) - (save-excursion - (set-buffer article-buf) - (goto-char (point-min)) - (re-search-forward "^$") - (let ((delimit (point))) - (goto-char (point-min)) - (if (not - (and - (re-search-forward - "^[Cc]ontent-[Tt]ype:[ \t]*message/partial;" delimit t) - (re-search-forward - (concat "[ \t]+id=[ \t]*\"" - (regexp-quote id) "\";") delimit) - (re-search-forward - (concat "[ \t]+number=[ \t]*" - (int-to-string part-num) ";") delimit))) - (progn - (kill-buffer buffer) - (error "Couldn't find part %d" part-num))) - (append-to-buffer buffer (+ delimit 1) (point-max)))) - (setq part-num (+ part-num 1)))) - (mime/gp:display-article) - (save-excursion - (set-buffer article-buf) - ;; (make-variable-buffer-local 'mime/content-list) - ;; (setq mime/content-list (mime/parse-contents)) - (make-variable-buffer-local 'mime::article/content-info) - (setq mime::article/content-info (mime-viewer/parse)) - ) - (delete-other-windows) - (switch-to-buffer buffer) - (goto-char (point-min)) - (setq major-mode 'mime/show-message-mode) - (mime/viewer-mode mother) - (pop-to-buffer (current-buffer)) - )))) - -;; Check if all the parts are there -(defun mime/gp:part-missing-p (subject-string num-parts) - (save-excursion - (let ((part-num 1) - (cant-find nil)) + (mime-article/decode-message/partial beg end cal) + ) + (let (cinfo the-id parameters) + (setq subject-id (std11-field-body "Subject")) + (if (string-match "[0-9\n]+" subject-id) + (setq subject-id (substring subject-id 0 (match-beginning 0))) + ) + (pop-to-buffer subject-buf) + (while (search-backward subject-id nil t) + ) + (catch 'tag + (while t + (tm-partial/preview-article target) + (pop-to-buffer article-buffer) + (switch-to-buffer mime::article/preview-buffer) + (setq cinfo + (mime::preview-content-info/content-info + (car mime::preview/content-list))) + (setq parameters (mime::content-info/parameters cinfo)) + (setq the-id (assoc-value "id" parameters)) + (if (equal the-id id) + (progn + (switch-to-buffer article-buffer) + (mime-article/decode-message/partial + (point-min)(point-max) parameters) + (if (file-exists-p full-file) + (throw 'tag nil) + ) + )) + (if (not (progn + (pop-to-buffer subject-buf) + (end-of-line) + (search-forward subject-id nil t) + )) + (error "not found") + ) + )))))) - (while (and (<= part-num num-parts) (not cant-find)) - (goto-char (point-min)) - ;; If the parts are numbered 01/10, then chop off the leading 0 - (if (not (re-search-forward - (concat (regexp-quote subject-id) "0*" - (int-to-string part-num)) - nil t)) - (setq cant-find part-num) - (progn - (message "Found part %d of %d." part-num num-parts) - (setq part-num (+ part-num 1))))) - cant-find))) - -;;; @ set up +;;; @ end ;;; -(set-atype 'mime/content-decoding-condition - '((type . "message/partial") - (method . mime/decode-message/grab-partials) - (major-mode . gnus-article-mode) - )) +(provide 'tm-partial) -(set-atype 'mime/content-decoding-condition - '((type . "message/partial") - (method . mime/decode-message/grab-partials) - (major-mode . mh-show-mode) - )) +(run-hooks 'tm-partial-load-hook) -(provide 'tm-partial) +;;; tm-partial.el ends here