1 ;;; mm-partial.el --- showing message/partial
2 ;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: message partial
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
28 (eval-when-compile (require 'cl))
34 (defun mm-partial-find-parts (id &optional art)
35 (let ((headers (with-current-buffer gnus-summary-buffer
36 gnus-newsgroup-headers))
38 (while (setq header (pop headers))
39 (unless (eq (aref header 0) art)
40 (mm-with-unibyte-buffer
41 (gnus-request-article-this-buffer (aref header 0)
43 (when (search-forward id nil t)
44 (let ((nhandles (mm-dissect-buffer
45 nil gnus-article-loose-mime)) nid)
46 (if (consp (car nhandles))
47 (mm-destroy-parts nhandles)
48 (setq nid (cdr (assq 'id
49 (cdr (mm-handle-type nhandles)))))
50 (if (not (equal id nid))
51 (mm-destroy-parts nhandles)
52 (push nhandles phandles))))))))
56 (defun mm-inline-partial (handle &optional no-display)
57 "Show the partial part of HANDLE.
58 This function replaces the buffer of HANDLE with a buffer contains
60 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing."
61 (let ((id (cdr (assq 'id (cdr (mm-handle-type handle)))))
63 (b (point)) (n 1) total
65 gnus-displaying-mime handles buffer)
66 (unless (mm-handle-cache handle)
68 (error "Can not find message/partial id"))
71 (mm-partial-find-parts
74 (set-buffer gnus-summary-buffer)
75 (gnus-summary-article-number))))
77 (let ((anumber (string-to-number
79 (cdr (mm-handle-type a))))))
80 (bnumber (string-to-number
82 (cdr (mm-handle-type b)))))))
83 (< anumber bnumber)))))
84 (setq gnus-article-mime-handles
85 (mm-merge-handles gnus-article-mime-handles phandles))
87 (set-buffer (generate-new-buffer " *mm*"))
88 (while (setq phandle (pop phandles))
89 (setq nn (string-to-number
91 (cdr (mm-handle-type phandle))))))
92 (setq ntotal (string-to-number
94 (cdr (mm-handle-type phandle))))))
97 (unless (eq total ntotal)
98 (error "The numbers of total are different"))
102 (error "Missing part %d" n))
103 (mm-insert-part phandle)
104 (goto-char (point-max))
105 (when (not (eq 0 (skip-chars-backward "\r\n")))
106 ;; remove tail blank spaces except one
107 (if (looking-at "\r?\n")
108 (goto-char (match-end 0)))
109 (delete-region (point) (point-max)))
112 (error "Don't known the total number of"))
114 (error "Missing part %d" n))
115 (kill-buffer (mm-handle-buffer handle))
116 (goto-char (point-min))
117 (let ((point (if (search-forward "\n\n" nil t)
120 (goto-char (point-min))
121 (unless (re-search-forward "^mime-version:" point t)
122 (insert "MIME-Version: 1.0\n")))
123 (setcar handle (current-buffer))
124 (mm-handle-set-cache handle t)))
128 (narrow-to-region b b)
129 (mm-insert-part handle)
130 (let (gnus-article-mime-handles)
131 (run-hooks 'gnus-article-decode-hook)
132 (gnus-article-prepare-display)
133 (setq handles gnus-article-mime-handles))
135 ;; It is in article buffer.
136 (setq gnus-article-mime-handles
137 (mm-merge-handles gnus-article-mime-handles handles)))
138 (mm-handle-set-undisplayer
141 (let (buffer-read-only)
143 ;; This is only valid on XEmacs.
144 (mapcar (lambda (prop)
146 (face-property 'default prop) (current-buffer)))
147 '(background background-pixmap foreground))
149 (delete-region ,(point-min-marker) ,(point-max-marker))))))))))
151 (provide 'mm-partial)
153 ;;; mm-partial.el ends here