tm 7.19.
[elisp/tm.git] / tm-partial.el
1 ;;; 
2 ;;; tm-partial.el
3 ;;; 
4 ;;; Grabbing all MIME "message/partial"s.
5 ;;; by Yasuo OKABE @ Kyoto University 1994
6 ;;; modified by MORIOKA Tomohiko
7 ;;;
8 ;;; original file is 
9 ;;;  gif.el written by Art Mellor @ Cayman Systems, Inc. 1991
10 ;;;
11 ;;; This file is a part of tm (Tools for MIME).
12 ;;;
13 ;;; $Id: tm-partial.el,v 7.9 1995/10/23 09:27:29 morioka Exp $
14 ;;;
15
16 (require 'tm-view)
17
18 (defvar tm-partial/preview-article-method-alist nil)
19    
20 ;; display Article at the cursor in Subject buffer.
21 (defun tm-partial/preview-article (target)
22   (let ((f (assq target tm-partial/preview-article-method-alist)))
23     (if f
24         (funcall (cdr f))
25       (error "Fatal. Unsupported mode")
26       )))
27
28 (defun mime-article/grab-message/partials (beg end cal)
29   (interactive)
30   (let* ((id (cdr (assoc "id" cal)))
31          (buffer (generate-new-buffer id))
32          (mother mime::article/preview-buffer)
33          (target (cdr (assq 'major-mode cal)))
34          (article-buffer (buffer-name (current-buffer)))
35          (subject-buf (eval (cdr (assq 'summary-buffer-exp cal))))
36          subject-id
37          (root-dir (expand-file-name
38                     (concat "m-prts-" (user-login-name)) mime/tmp-dir))
39          full-file)
40     (setq root-dir (concat root-dir "/" (replace-as-filename id)))
41     (setq full-file (concat root-dir "/FULL"))
42     
43     (if (null target)
44         (error "%s is not supported. Sorry." target)
45       )
46     
47     ;; if you can't parse the subject line, try simple decoding method
48     (if (or (file-exists-p full-file)
49             (not (y-or-n-p "Merge partials?"))
50             )
51         (progn
52           (kill-buffer buffer)
53           (mime-article/decode-message/partial beg end cal)
54           )
55       (let (cinfo the-id parameters)
56         (setq subject-id (rfc822/get-field-body "Subject"))
57         (if (string-match "[0-9]+" subject-id)
58             (setq subject-id (substring subject-id 0 (match-beginning 0)))
59           )
60         (pop-to-buffer subject-buf)
61         (while (search-backward subject-id nil t)
62           )
63         (catch 'tag
64           (while t
65             (tm-partial/preview-article target)
66             (pop-to-buffer article-buffer)
67             (switch-to-buffer mime::article/preview-buffer)
68             (setq cinfo
69                   (mime::preview-content-info/content-info
70                    (car mime::preview/content-list)))
71             (setq parameters (mime::content-info/parameters cinfo))
72             (setq the-id (assoc-value "id" parameters))
73             (if (equal the-id id)
74                 (progn
75                   (switch-to-buffer article-buffer)
76                   (mime-article/decode-message/partial
77                    (point-min)(point-max) parameters)
78                   (if (file-exists-p full-file)
79                       (throw 'tag nil)
80                     )
81                   ))
82             (if (not (progn
83                        (pop-to-buffer subject-buf)
84                        (end-of-line)
85                        (search-forward subject-id nil t)
86                        ))
87                 (error "not found")
88               )
89             ))))))
90
91
92 ;;; @ end
93 ;;;
94
95 (provide 'tm-partial)
96
97 (run-hooks 'tm-partial-load-hook)