Mercurial > emacs
annotate lisp/gnus/mm-partial.el @ 93866:1f769203aa6c
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 08 Apr 2008 14:57:02 +0000 |
parents | 107ccd98fa12 |
children | 606f2d163a64 1e3a407766b9 |
rev | line source |
---|---|
31717 | 1 ;;; mm-partial.el --- showing message/partial |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
2 |
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, |
79708 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
31717 | 5 |
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu> | |
7 ;; Keywords: message partial | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
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 | |
78224
24202b793a08
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
13 ;; by the Free Software Foundation; either version 3, or (at your |
31717 | 14 ;; option) any later version. |
15 | |
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. | |
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 | |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
31717 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;;; Code: | |
29 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
30 (eval-when-compile (require 'cl)) |
31717 | 31 |
32 (require 'gnus-sum) | |
33 (require 'mm-util) | |
34 (require 'mm-decode) | |
35 | |
36 (defun mm-partial-find-parts (id &optional art) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
37 (let ((headers (with-current-buffer gnus-summary-buffer |
31717 | 38 gnus-newsgroup-headers)) |
39 phandles header) | |
40 (while (setq header (pop headers)) | |
41 (unless (eq (aref header 0) art) | |
42 (mm-with-unibyte-buffer | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
43 (gnus-request-article-this-buffer (aref header 0) |
31717 | 44 gnus-newsgroup-name) |
45 (when (search-forward id nil t) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
46 (let ((nhandles (mm-dissect-buffer |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
47 nil gnus-article-loose-mime)) nid) |
31717 | 48 (if (consp (car nhandles)) |
49 (mm-destroy-parts nhandles) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
50 (setq nid (cdr (assq 'id |
31717 | 51 (cdr (mm-handle-type nhandles))))) |
52 (if (not (equal id nid)) | |
53 (mm-destroy-parts nhandles) | |
54 (push nhandles phandles)))))))) | |
55 phandles)) | |
56 | |
57 ;;;###autoload | |
58 (defun mm-inline-partial (handle &optional no-display) | |
59 "Show the partial part of HANDLE. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
60 This function replaces the buffer of HANDLE with a buffer contains |
31717 | 61 the entire message. |
62 If NO-DISPLAY is nil, display it. Otherwise, do nothing after replacing." | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
63 (let ((id (cdr (assq 'id (cdr (mm-handle-type handle))))) |
31717 | 64 phandles |
65 (b (point)) (n 1) total | |
66 phandle nn ntotal | |
67 gnus-displaying-mime handles buffer) | |
68 (unless (mm-handle-cache handle) | |
69 (unless id | |
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
33176
diff
changeset
|
70 (error "Can not find message/partial id")) |
31717 | 71 (setq phandles |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
72 (sort (cons handle |
31717 | 73 (mm-partial-find-parts |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
74 id |
31717 | 75 (save-excursion |
76 (set-buffer gnus-summary-buffer) | |
77 (gnus-summary-article-number)))) | |
78 #'(lambda (a b) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
79 (let ((anumber (string-to-number |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
80 (cdr (assq 'number |
31717 | 81 (cdr (mm-handle-type a)))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
82 (bnumber (string-to-number |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
83 (cdr (assq 'number |
31717 | 84 (cdr (mm-handle-type b))))))) |
85 (< anumber bnumber))))) | |
86 (setq gnus-article-mime-handles | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
87 (mm-merge-handles gnus-article-mime-handles phandles)) |
31717 | 88 (save-excursion |
33176
aa40591dba57
(mm-inline-partial): Space-prefix temp buffer
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
89 (set-buffer (generate-new-buffer " *mm*")) |
31717 | 90 (while (setq phandle (pop phandles)) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
91 (setq nn (string-to-number |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
92 (cdr (assq 'number |
31717 | 93 (cdr (mm-handle-type phandle)))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
94 (setq ntotal (string-to-number |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
95 (cdr (assq 'total |
31717 | 96 (cdr (mm-handle-type phandle)))))) |
97 (if ntotal | |
98 (if total | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38413
diff
changeset
|
99 (unless (eq total ntotal) |
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
33176
diff
changeset
|
100 (error "The numbers of total are different")) |
31717 | 101 (setq total ntotal))) |
102 (unless (< nn n) | |
103 (unless (eq nn n) | |
104 (error "Missing part %d" n)) | |
105 (mm-insert-part phandle) | |
106 (goto-char (point-max)) | |
107 (when (not (eq 0 (skip-chars-backward "\r\n"))) | |
108 ;; remove tail blank spaces except one | |
109 (if (looking-at "\r?\n") | |
110 (goto-char (match-end 0))) | |
111 (delete-region (point) (point-max))) | |
112 (setq n (+ n 1)))) | |
113 (unless total | |
114 (error "Don't known the total number of")) | |
115 (if (<= n total) | |
116 (error "Missing part %d" n)) | |
117 (kill-buffer (mm-handle-buffer handle)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
118 (goto-char (point-min)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
119 (let ((point (if (search-forward "\n\n" nil t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
120 (1- (point)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
121 (point-max)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
122 (goto-char (point-min)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
123 (unless (re-search-forward "^mime-version:" point t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
124 (insert "MIME-Version: 1.0\n"))) |
31717 | 125 (setcar handle (current-buffer)) |
126 (mm-handle-set-cache handle t))) | |
127 (unless no-display | |
128 (save-excursion | |
129 (save-restriction | |
130 (narrow-to-region b b) | |
131 (mm-insert-part handle) | |
132 (let (gnus-article-mime-handles) | |
133 (run-hooks 'gnus-article-decode-hook) | |
134 (gnus-article-prepare-display) | |
135 (setq handles gnus-article-mime-handles)) | |
136 (when handles | |
137 ;; It is in article buffer. | |
138 (setq gnus-article-mime-handles | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
139 (mm-merge-handles gnus-article-mime-handles handles))) |
31717 | 140 (mm-handle-set-undisplayer |
141 handle | |
142 `(lambda () | |
143 (let (buffer-read-only) | |
144 (condition-case nil | |
145 ;; This is only valid on XEmacs. | |
146 (mapcar (lambda (prop) | |
147 (remove-specifier | |
148 (face-property 'default prop) (current-buffer))) | |
149 '(background background-pixmap foreground)) | |
150 (error nil)) | |
151 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))) | |
152 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
153 (provide 'mm-partial) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
154 |
52401 | 155 ;;; arch-tag: 460e7424-05f2-4a1d-a0f2-70ec081eff7d |
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
33176
diff
changeset
|
156 ;;; mm-partial.el ends here |