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