1 ;;; mm-partial.el --- showing message/partial
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
7 ;; Keywords: message partial
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published
13 ;; by the Free Software Foundation; either version 3, or (at your
14 ;; option) any later version.
16 ;; GNU Emacs 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.
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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 (eval-when-compile (require 'cl
))
36 (defun mm-partial-find-parts (id &optional art
)
37 (let ((headers (save-excursion
38 (set-buffer gnus-summary-buffer
)
39 gnus-newsgroup-headers
))
41 (while (setq header
(pop headers
))
42 (unless (eq (aref header
0) art
)
43 (mm-with-unibyte-buffer
44 (gnus-request-article-this-buffer (aref header
0)
46 (when (search-forward id nil t
)
47 (let ((nhandles (mm-dissect-buffer
48 nil gnus-article-loose-mime
)) nid
)
49 (if (consp (car nhandles
))
50 (mm-destroy-parts nhandles
)
51 (setq nid
(cdr (assq 'id
52 (cdr (mm-handle-type nhandles
)))))
53 (if (not (equal id nid
))
54 (mm-destroy-parts nhandles
)
55 (push nhandles phandles
))))))))
59 (defun mm-inline-partial (handle &optional no-display
)
60 "Show the partial part of HANDLE.
61 This function replaces the buffer of HANDLE with a buffer contains
63 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing."
64 (let ((id (cdr (assq 'id
(cdr (mm-handle-type handle
)))))
66 (b (point)) (n 1) total
68 gnus-displaying-mime handles buffer
)
69 (unless (mm-handle-cache handle
)
71 (error "Can not find message/partial id"))
74 (mm-partial-find-parts
77 (set-buffer gnus-summary-buffer
)
78 (gnus-summary-article-number))))
80 (let ((anumber (string-to-number
82 (cdr (mm-handle-type a
))))))
83 (bnumber (string-to-number
85 (cdr (mm-handle-type b
)))))))
86 (< anumber bnumber
)))))
87 (setq gnus-article-mime-handles
88 (mm-merge-handles gnus-article-mime-handles phandles
))
90 (set-buffer (generate-new-buffer " *mm*"))
91 (while (setq phandle
(pop phandles
))
92 (setq nn
(string-to-number
94 (cdr (mm-handle-type phandle
))))))
95 (setq ntotal
(string-to-number
97 (cdr (mm-handle-type phandle
))))))
100 (unless (eq total ntotal
)
101 (error "The numbers of total are different"))
102 (setq total ntotal
)))
105 (error "Missing part %d" n
))
106 (mm-insert-part phandle
)
107 (goto-char (point-max))
108 (when (not (eq 0 (skip-chars-backward "\r\n")))
109 ;; remove tail blank spaces except one
110 (if (looking-at "\r?\n")
111 (goto-char (match-end 0)))
112 (delete-region (point) (point-max)))
115 (error "Don't known the total number of"))
117 (error "Missing part %d" n
))
118 (kill-buffer (mm-handle-buffer handle
))
119 (goto-char (point-min))
120 (let ((point (if (search-forward "\n\n" nil t
)
123 (goto-char (point-min))
124 (unless (re-search-forward "^mime-version:" point t
)
125 (insert "MIME-Version: 1.0\n")))
126 (setcar handle
(current-buffer))
127 (mm-handle-set-cache handle t
)))
131 (narrow-to-region b b
)
132 (mm-insert-part handle
)
133 (let (gnus-article-mime-handles)
134 (run-hooks 'gnus-article-decode-hook
)
135 (gnus-article-prepare-display)
136 (setq handles gnus-article-mime-handles
))
138 ;; It is in article buffer.
139 (setq gnus-article-mime-handles
140 (mm-merge-handles gnus-article-mime-handles handles
)))
141 (mm-handle-set-undisplayer
144 (let (buffer-read-only)
146 ;; This is only valid on XEmacs.
147 (mapcar (lambda (prop)
149 (face-property 'default prop
) (current-buffer)))
150 '(background background-pixmap foreground
))
152 (delete-region ,(point-min-marker) ,(point-max-marker))))))))))
154 (provide 'mm-partial
)
156 ;;; arch-tag: 460e7424-05f2-4a1d-a0f2-70ec081eff7d
157 ;;; mm-partial.el ends here