1 ;;; mm-partial.el --- showing message/partial
3 ;; Copyright (C) 2000-2018 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 <https://www.gnu.org/licenses/>.
31 (defun mm-partial-find-parts (id &optional art
)
32 (let ((headers (with-current-buffer gnus-summary-buffer
33 gnus-newsgroup-headers
))
35 (while (setq header
(pop headers
))
36 (unless (eq (aref header
0) art
)
37 (mm-with-unibyte-buffer
38 (gnus-request-article-this-buffer (aref header
0)
40 (when (search-forward id nil t
)
41 (let ((nhandles (mm-dissect-buffer
42 nil gnus-article-loose-mime
)) nid
)
43 (if (consp (car nhandles
))
44 (mm-destroy-parts nhandles
)
45 (setq nid
(cdr (assq 'id
46 (cdr (mm-handle-type nhandles
)))))
47 (if (not (equal id nid
))
48 (mm-destroy-parts nhandles
)
49 (push nhandles phandles
))))))))
53 (defun mm-inline-partial (handle &optional no-display
)
54 "Show the partial part of HANDLE.
55 This function replaces the buffer of HANDLE with a buffer contains
57 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing."
58 (let ((id (cdr (assq 'id
(cdr (mm-handle-type handle
)))))
60 (b (point)) (n 1) total
62 gnus-displaying-mime handles buffer
)
63 (unless (mm-handle-cache handle
)
65 (error "Can not find message/partial id"))
68 (mm-partial-find-parts
70 (with-current-buffer gnus-summary-buffer
71 (gnus-summary-article-number))))
73 (let ((anumber (string-to-number
75 (cdr (mm-handle-type a
))))))
76 (bnumber (string-to-number
78 (cdr (mm-handle-type b
)))))))
79 (< anumber bnumber
)))))
80 (setq gnus-article-mime-handles
81 (mm-merge-handles gnus-article-mime-handles phandles
))
82 (with-current-buffer (generate-new-buffer " *mm*")
83 (while (setq phandle
(pop phandles
))
84 (setq nn
(string-to-number
86 (cdr (mm-handle-type phandle
))))))
87 (setq ntotal
(string-to-number
89 (cdr (mm-handle-type phandle
))))))
92 (unless (eq total ntotal
)
93 (error "The numbers of total are different"))
97 (error "Missing part %d" n
))
98 (mm-insert-part phandle
)
99 (goto-char (point-max))
100 (when (not (eq 0 (skip-chars-backward "\r\n")))
101 ;; remove tail blank spaces except one
102 (if (looking-at "\r?\n")
103 (goto-char (match-end 0)))
104 (delete-region (point) (point-max)))
107 (error "Don't known the total number of"))
109 (error "Missing part %d" n
))
110 (kill-buffer (mm-handle-buffer handle
))
111 (goto-char (point-min))
112 (let ((point (if (search-forward "\n\n" nil t
)
115 (goto-char (point-min))
116 (unless (re-search-forward "^mime-version:" point t
)
117 (insert "MIME-Version: 1.0\n")))
118 (setcar handle
(current-buffer))
119 (mm-handle-set-cache handle t
)))
123 (narrow-to-region b b
)
124 (mm-insert-part handle
)
125 (let (gnus-article-mime-handles)
126 (run-hooks 'gnus-article-decode-hook
)
127 (gnus-article-prepare-display)
128 (setq handles gnus-article-mime-handles
))
130 ;; It is in article buffer.
131 (setq gnus-article-mime-handles
132 (mm-merge-handles gnus-article-mime-handles handles
)))
133 (mm-handle-set-undisplayer
136 (let (buffer-read-only)
137 (delete-region ,(point-min-marker) ,(point-max-marker))))))))))
139 (provide 'mm-partial
)
141 ;;; mm-partial.el ends here