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