1 ;;; mm-partial.el --- showing message/partial
3 ;; Copyright (C) 2000-2015 Free Software Foundation, Inc.
5 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
6 ;; Keywords: message partial
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 (eval-when-compile (require 'cl
))
33 (defun mm-partial-find-parts (id &optional art
)
34 (let ((headers (with-current-buffer gnus-summary-buffer
35 gnus-newsgroup-headers
))
37 (while (setq header
(pop headers
))
38 (unless (eq (aref header
0) art
)
39 (mm-with-unibyte-buffer
40 (gnus-request-article-this-buffer (aref header
0)
42 (when (search-forward id nil t
)
43 (let ((nhandles (mm-dissect-buffer
44 nil gnus-article-loose-mime
)) nid
)
45 (if (consp (car nhandles
))
46 (mm-destroy-parts nhandles
)
47 (setq nid
(cdr (assq 'id
48 (cdr (mm-handle-type nhandles
)))))
49 (if (not (equal id nid
))
50 (mm-destroy-parts nhandles
)
51 (push nhandles phandles
))))))))
55 (defun mm-inline-partial (handle &optional no-display
)
56 "Show the partial part of HANDLE.
57 This function replaces the buffer of HANDLE with a buffer contains
59 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing."
60 (let ((id (cdr (assq 'id
(cdr (mm-handle-type handle
)))))
62 (b (point)) (n 1) total
64 gnus-displaying-mime handles buffer
)
65 (unless (mm-handle-cache handle
)
67 (error "Can not find message/partial id"))
70 (mm-partial-find-parts
72 (with-current-buffer gnus-summary-buffer
73 (gnus-summary-article-number))))
75 (let ((anumber (string-to-number
77 (cdr (mm-handle-type a
))))))
78 (bnumber (string-to-number
80 (cdr (mm-handle-type b
)))))))
81 (< anumber bnumber
)))))
82 (setq gnus-article-mime-handles
83 (mm-merge-handles gnus-article-mime-handles phandles
))
84 (with-current-buffer (generate-new-buffer " *mm*")
85 (while (setq phandle
(pop phandles
))
86 (setq nn
(string-to-number
88 (cdr (mm-handle-type phandle
))))))
89 (setq ntotal
(string-to-number
91 (cdr (mm-handle-type phandle
))))))
94 (unless (eq total ntotal
)
95 (error "The numbers of total are different"))
99 (error "Missing part %d" n
))
100 (mm-insert-part phandle
)
101 (goto-char (point-max))
102 (when (not (eq 0 (skip-chars-backward "\r\n")))
103 ;; remove tail blank spaces except one
104 (if (looking-at "\r?\n")
105 (goto-char (match-end 0)))
106 (delete-region (point) (point-max)))
109 (error "Don't known the total number of"))
111 (error "Missing part %d" n
))
112 (kill-buffer (mm-handle-buffer handle
))
113 (goto-char (point-min))
114 (let ((point (if (search-forward "\n\n" nil t
)
117 (goto-char (point-min))
118 (unless (re-search-forward "^mime-version:" point t
)
119 (insert "MIME-Version: 1.0\n")))
120 (setcar handle
(current-buffer))
121 (mm-handle-set-cache handle t
)))
125 (narrow-to-region b b
)
126 (mm-insert-part handle
)
127 (let (gnus-article-mime-handles)
128 (run-hooks 'gnus-article-decode-hook
)
129 (gnus-article-prepare-display)
130 (setq handles gnus-article-mime-handles
))
132 ;; It is in article buffer.
133 (setq gnus-article-mime-handles
134 (mm-merge-handles gnus-article-mime-handles handles
)))
135 (mm-handle-set-undisplayer
138 (let (buffer-read-only)
140 ;; This is only valid on XEmacs.
141 (mapcar (lambda (prop)
143 (face-property 'default prop
) (current-buffer)))
144 '(background background-pixmap foreground
))
146 (delete-region ,(point-min-marker) ,(point-max-marker))))))))))
148 (provide 'mm-partial
)
150 ;;; mm-partial.el ends here