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