(mime-combine-message/partials-automatically): Use
[elisp/semi.git] / mime-partial.el
1 ;;; mime-partial.el --- Grabbing all MIME "message/partial"s.
2
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
4
5 ;; Author: OKABE Yasuo @ Kyoto University
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Version: $Id: mime-partial.el,v 0.10 1997-09-05 11:29:06 morioka Exp $ 
8 ;; Keywords: message/partial, MIME, multimedia, mail, news
9
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Code:
28
29 (require 'mime-view)
30 (require 'mime-play)
31
32 (defvar mime-view-partial-message-method-alist nil
33   "Alist major-mode vs. function to view partial message for mime-partial.")
34
35 ;; display Article at the cursor in Subject buffer.
36 (defsubst mime-view-partial-message (target)
37   (save-window-excursion
38     (let ((f (assq target mime-view-partial-message-method-alist)))
39       (if f
40           (funcall (cdr f))
41         (error "Fatal. Unsupported mode")
42         ))))
43
44 (defun mime-combine-message/partials-automatically (beg end cal)
45   "Internal method for mime-view to combine message/partial messages
46 automatically.  This function refers variable
47 `mime-view-partial-message-method-alist' to select function to display
48 partial messages using mime-view."
49   (interactive)
50   (let* ((id (cdr (assoc "id" cal)))
51          (target (cdr (assq 'major-mode cal)))
52          (article-buffer (buffer-name (current-buffer)))
53          (subject-buf (eval (cdr (assq 'summary-buffer-exp cal))))
54          subject-id
55          (root-dir (expand-file-name
56                     (concat "m-prts-" (user-login-name)) mime-temp-directory))
57          full-file)
58     (setq root-dir (concat root-dir "/" (replace-as-filename id)))
59     (setq full-file (concat root-dir "/FULL"))
60     
61     (if (null target)
62         (error "%s is not supported. Sorry." target)
63       )
64     
65     ;; if you can't parse the subject line, try simple decoding method
66     (if (or (file-exists-p full-file)
67             (not (y-or-n-p "Merge partials?"))
68             )
69         (mime-display-message/partial beg end cal)
70       (let (the-id parameters)
71         (setq subject-id (std11-field-body "Subject"))
72         (if (string-match "[0-9\n]+" subject-id)
73             (setq subject-id (substring subject-id 0 (match-beginning 0)))
74           )
75         (save-excursion
76           (set-buffer subject-buf)
77           (while (search-backward subject-id nil t))
78           (catch 'tag
79             (while t
80               (mime-view-partial-message target)
81               (set-buffer article-buffer)
82               (setq parameters
83                     (mime-entity-info-parameters mime::article/content-info))
84               (setq the-id (cdr (assoc "id" parameters)))
85               (if (string= the-id id)
86                   (progn
87                     (mime-display-message/partial
88                      (point-min)(point-max) parameters)
89                     (if (file-exists-p full-file)
90                         (throw 'tag nil)
91                       )
92                     ))
93               (if (not (progn
94                          (set-buffer subject-buf)
95                          (end-of-line)
96                          (search-forward subject-id nil t)
97                          ))
98                   (error "not found")
99                 )
100               )
101             ))))))
102
103
104 ;;; @ end
105 ;;;
106
107 (provide 'mime-partial)
108
109 (run-hooks 'mime-partial-load-hook)
110
111 ;;; mime-partial.el ends here