;;;
-;;; tm-partial.el
+;;; tm-partial.el --- Grabbing all MIME "message/partial"s.
;;;
-;;; Grabbing all MIME "message/partial"s.
-;;; by Yasuo OKABE @ Kyoto University 1994
-;;; modified by MORIOKA Tomohiko
-
-;; original file is
-;; gif.el written by Art Mellor @ Cayman Systems, Inc. 1991
-
-;;; $Id: tm-partial.el,v 1.5 1994/12/05 05:13:25 morioka Exp $
+;;; Copyright (C) 1995 Free Software Foundation, Inc.
+;;; Copyright (C) 1994 OKABE Yasuo
+;;; Copyright (C) 1995 MORIOKA Tomohiko
+;;;
+;;; Author: OKABE Yasuo @ Kyoto University
+;;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;; Version:
+;;; $Id: tm-partial.el,v 7.11 1995/11/16 15:51:10 morioka Exp $
+;;; Keywords: mail, news, MIME, multimedia, message/partial
+;;;
+;;; This file is a part of tm (Tools for MIME).
+;;;
(require 'tm-view)
+(require 'tm-play)
-;; 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
-
-(defvar mime/gp:subject-start-regexp "[ \t]*\\(v[0-9]+i[0-9]+:[ \t]+\\)?")
-
-(defvar mime/gp:subject-end-regexp "\\([[(]?\\)\\([0-9]+\\)\\(/\\| [oO][fF] \\)\\([0-9]+\\)\\([])]?\\)[ \t]*$")
-
-;; 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")))))
+(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/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)))
+ (mother mime::article/preview-buffer)
+ (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)))
- (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 (rfc822/get-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)
- ))
-
-(set-atype 'mime/content-decoding-condition
- '((type . "message/partial")
- (method . mime/decode-message/grab-partials)
- (major-mode . mh-show-mode)
- ))
-
(provide 'tm-partial)
+
+(run-hooks 'tm-partial-load-hook)