Change defcustom :version from 23.0 to 23.1.
[bpt/emacs.git] / lisp / gnus / gnus-art.el
CommitLineData
eec82323 1;;; gnus-art.el --- article mode commands for Gnus
e84b4b86
TTN
2
3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
e3fe4da0 4;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
eec82323 5
6748645f 6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news
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 by
5a9dffec 13;; the Free Software Foundation; either version 3, or (at your option)
eec82323
LMI
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2ff9f5b4 18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eec82323
LMI
19;; GNU 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
3a35cf56
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
eec82323
LMI
25
26;;; Commentary:
27
28;;; Code:
29
9640c3bc
GM
30;; For Emacs < 22.2.
31(eval-and-compile
32 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
23f87bed 33(eval-when-compile
9efa445f
DN
34 (require 'cl))
35(defvar tool-bar-map)
36(defvar w3m-minor-mode-map)
5ab7173c 37
eec82323 38(require 'gnus)
01c52d31
MB
39;; Avoid the "Recursive load suspected" error in Emacs 21.1.
40(eval-and-compile
41 (let ((recursive-load-depth-limit 100))
42 (require 'gnus-sum)))
eec82323
LMI
43(require 'gnus-spec)
44(require 'gnus-int)
23f87bed 45(require 'gnus-win)
16409b0b
GM
46(require 'mm-bodies)
47(require 'mail-parse)
48(require 'mm-decode)
49(require 'mm-view)
50(require 'wid-edit)
51(require 'mm-uu)
23f87bed
MB
52(require 'message)
53
54(autoload 'gnus-msg-mail "gnus-msg" nil t)
55(autoload 'gnus-button-mailto "gnus-msg")
56(autoload 'gnus-button-reply "gnus-msg" nil t)
498063ec 57(autoload 'parse-time-string "parse-time" nil nil)
01c52d31
MB
58(autoload 'ansi-color-apply-on-region "ansi-color")
59(autoload 'mm-url-insert-file-contents-external "mm-url")
531bedc3 60(autoload 'mm-extern-cache-contents "mm-extern")
eec82323
LMI
61
62(defgroup gnus-article nil
63 "Article display."
23f87bed 64 :link '(custom-manual "(gnus)Article Buffer")
eec82323
LMI
65 :group 'gnus)
66
16409b0b
GM
67(defgroup gnus-article-treat nil
68 "Treating article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
70 :group 'gnus-article)
71
eec82323
LMI
72(defgroup gnus-article-hiding nil
73 "Hiding article parts."
74 :link '(custom-manual "(gnus)Article Hiding")
75 :group 'gnus-article)
76
77(defgroup gnus-article-highlight nil
78 "Article highlighting."
79 :link '(custom-manual "(gnus)Article Highlighting")
80 :group 'gnus-article
81 :group 'gnus-visual)
82
83(defgroup gnus-article-signature nil
84 "Article signatures."
85 :link '(custom-manual "(gnus)Article Signature")
86 :group 'gnus-article)
87
88(defgroup gnus-article-headers nil
89 "Article headers."
90 :link '(custom-manual "(gnus)Hiding Headers")
91 :group 'gnus-article)
92
93(defgroup gnus-article-washing nil
94 "Special commands on articles."
95 :link '(custom-manual "(gnus)Article Washing")
96 :group 'gnus-article)
97
98(defgroup gnus-article-emphasis nil
99 "Fontisizing articles."
100 :link '(custom-manual "(gnus)Article Fontisizing")
101 :group 'gnus-article)
102
103(defgroup gnus-article-saving nil
104 "Saving articles."
105 :link '(custom-manual "(gnus)Saving Articles")
106 :group 'gnus-article)
107
108(defgroup gnus-article-mime nil
109 "Worshiping the MIME wonder."
110 :link '(custom-manual "(gnus)Using MIME")
111 :group 'gnus-article)
112
113(defgroup gnus-article-buttons nil
114 "Pushable buttons in the article buffer."
115 :link '(custom-manual "(gnus)Article Buttons")
116 :group 'gnus-article)
117
118(defgroup gnus-article-various nil
119 "Other article options."
120 :link '(custom-manual "(gnus)Misc Article")
121 :group 'gnus-article)
122
123(defcustom gnus-ignored-headers
23f87bed
MB
124 (mapcar
125 (lambda (header)
126 (concat "^" header ":"))
127 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
128 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
129 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
130 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
131 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
132 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
133 "X-Attribution" "X-Originating-IP" "Delivered-To"
134 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
135 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
136 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
137 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
138 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
139 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
140 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
141 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
142 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
143 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
144 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
145 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
146 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
147 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
148 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
149 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
150 "List-[A-Za-z]+" "X-Listprocessor-Version"
151 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
152 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
153 "X-Received" "Content-length" "X-precedence"
154 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
155 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
156 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
157 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
158 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
159 "X-Content-length" "X-Posting-Agent" "Original-Received"
160 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
161 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
162 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
163 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
01c52d31
MB
164 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
165 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
166 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
167 "Envelope-Sender" "Envelope-Recipients"))
6748645f 168 "*All headers that start with this regexp will be hidden.
eec82323
LMI
169This variable can also be a list of regexps of headers to be ignored.
170If `gnus-visible-headers' is non-nil, this variable will be ignored."
171 :type '(choice :custom-show nil
172 regexp
173 (repeat regexp))
174 :group 'gnus-article-hiding)
175
176(defcustom gnus-visible-headers
23f87bed 177 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
6748645f 178 "*All headers that do not match this regexp will be hidden.
eec82323
LMI
179This variable can also be a list of regexp of headers to remain visible.
180If this variable is non-nil, `gnus-ignored-headers' will be ignored."
181 :type '(repeat :value-to-internal (lambda (widget value)
182 (custom-split-regexp-maybe value))
183 :match (lambda (widget value)
184 (or (stringp value)
185 (widget-editable-list-match widget value)))
186 regexp)
187 :group 'gnus-article-hiding)
188
189(defcustom gnus-sorted-header-list
190 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
191 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
6748645f 192 "*This variable is a list of regular expressions.
eec82323
LMI
193If it is non-nil, headers that match the regular expressions will
194be placed first in the article buffer in the sequence specified by
195this list."
196 :type '(repeat regexp)
197 :group 'gnus-article-hiding)
198
199(defcustom gnus-boring-article-headers '(empty followup-to reply-to)
200 "Headers that are only to be displayed if they have interesting data.
23f87bed
MB
201Possible values in this list are:
202
203 'empty Headers with no content.
204 'newsgroups Newsgroup identical to Gnus group.
205 'to-address To identical to To-address.
206 'to-list To identical to To-list.
207 'cc-list CC identical to To-list.
208 'followup-to Followup-to identical to Newsgroups.
209 'reply-to Reply-to identical to From.
210 'date Date less than four days old.
211 'long-to To and/or Cc longer than 1024 characters.
212 'many-to Multiple To and/or Cc."
eec82323 213 :type '(set (const :tag "Headers with no content." empty)
23f87bed
MB
214 (const :tag "Newsgroups identical to Gnus group." newsgroups)
215 (const :tag "To identical to To-address." to-address)
216 (const :tag "To identical to To-list." to-list)
217 (const :tag "CC identical to To-list." cc-list)
218 (const :tag "Followup-to identical to Newsgroups." followup-to)
219 (const :tag "Reply-to identical to From." reply-to)
6748645f 220 (const :tag "Date less than four days old." date)
23f87bed 221 (const :tag "To and/or Cc longer than 1024 characters." long-to)
16409b0b 222 (const :tag "Multiple To and/or Cc headers." many-to))
eec82323
LMI
223 :group 'gnus-article-hiding)
224
23f87bed
MB
225(defcustom gnus-article-skip-boring nil
226 "Skip over text that is not worth reading.
227By default, if you set this t, then Gnus will display citations and
228signatures, but will never scroll down to show you a page consisting
229only of boring text. Boring text is controlled by
230`gnus-article-boring-faces'."
bf247b6e 231 :version "22.1"
23f87bed
MB
232 :type 'boolean
233 :group 'gnus-article-hiding)
234
eec82323
LMI
235(defcustom gnus-signature-separator '("^-- $" "^-- *$")
236 "Regexp matching signature separator.
237This can also be a list of regexps. In that case, it will be checked
238from head to tail looking for a separator. Searches will be done from
239the end of the buffer."
3031d8b0
MB
240 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
241 (regexp)
242 (repeat :tag "List of regexp" regexp))
eec82323
LMI
243 :group 'gnus-article-signature)
244
245(defcustom gnus-signature-limit nil
16409b0b 246 "Provide a limit to what is considered a signature.
eec82323
LMI
247If it is a number, no signature may not be longer (in characters) than
248that number. If it is a floating point number, no signature may be
249longer (in lines) than that number. If it is a function, the function
250will be called without any parameters, and if it returns nil, there is
251no signature in the buffer. If it is a string, it will be used as a
01c52d31
MB
252regexp. If it matches, the text in question is not a signature.
253
254This can also be a list of the above values."
4a2358e9
MB
255 :type '(choice (const nil)
256 (integer :value 200)
6748645f 257 (number :value 4.0)
b28080e3 258 function
6748645f 259 (regexp :value ".*"))
eec82323
LMI
260 :group 'gnus-article-signature)
261
262(defcustom gnus-hidden-properties '(invisible t intangible t)
263 "Property list to use for hiding text."
264 :type 'sexp
265 :group 'gnus-article-hiding)
266
23f87bed
MB
267;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268;; frames in a session.
eec82323 269(defcustom gnus-article-x-face-command
23f87bed
MB
270 (if (featurep 'xemacs)
271 (if (or (gnus-image-type-available-p 'xface)
272 (gnus-image-type-available-p 'pbm))
273 'gnus-display-x-face-in-from
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
275 (if (gnus-image-type-available-p 'pbm)
276 'gnus-display-x-face-in-from
e0bad764
DL
277 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
278display -"))
6748645f 279 "*String or function to be executed to display an X-Face header.
eec82323 280If it is a string, the command will be executed in a sub-shell
2ff9f5b4 281asynchronously. The compressed face will be piped to this command."
23f87bed
MB
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
16409b0b 284 function)
b5a206e7 285 :version "21.1"
23f87bed 286 :group 'gnus-picon
eec82323
LMI
287 :group 'gnus-article-washing)
288
289(defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
4bb6a3a6 291 :type '(choice regexp (const nil))
eec82323
LMI
292 :group 'gnus-article-washing)
293
e0bad764
DL
294(defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
a1506d29 296For example,
23f87bed 297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
fc2c2db8 298 :version "21.1"
e0bad764
DL
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
301
23f87bed
MB
302(gnus-define-group-parameter
303 banner
304 :variable-document
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
307 :parameter-type
308 '(choice :tag "Banner"
309 :value nil
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
312 regexp
313 (const :tag "None" nil))
314 :parameter-document
315 "If non-nil, specify how to remove `banners' from articles.
316
317Symbol `signature' means to remove signatures delimited by
318`gnus-signature-separator'. Any other symbol is used to look up a
319regular expression to match the banner in `gnus-article-banner-alist'.
320A string is used as a regular expression to match the banner
321directly.")
322
323(defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326to match a mail address in the From: header, BANNER is one of a symbol
327`signature', an item in `gnus-article-banner-alist', a regexp and nil.
328If ADDRESS matches author's mail address, it will remove things like
329advertisements. For example:
330
331\((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
332"
333 :type '(repeat
334 (cons
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
339 regexp
340 (const :tag "None" nil))))
bf247b6e 341 :version "22.1"
23f87bed
MB
342 :group 'gnus-article-washing)
343
ae465fa7
MB
344(defmacro gnus-emphasis-custom-with-format (&rest body)
345 `(let ((format "\
346\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
348 ,@body))
349
350(defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
354 2
355 (if (nth 1 value) 2 3)
356 (nth 2 value))
357 value)))
358
359(defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
364 "\\'"))
365 pattern)
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
368 (= (nth 2 value) 2)
369 (nth 3 value))
370 value))))
371
eec82323 372(defcustom gnus-emphasis-alist
ae465fa7
MB
373 (let ((types
374 '(("\\*" "\\*" bold nil 2)
23f87bed 375 ("_" "_" underline)
eec82323 376 ("/" "/" italic)
eec82323
LMI
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
ae465fa7
MB
381 (nconc
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
385 (or (nth 3 spec) 2)
386 (or (nth 4 spec) 3)
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
388 types))
95f75c75
SM
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
ae465fa7
MB
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
6748645f 397 "*Alist that says how to fontify certain phrases.
eec82323
LMI
398Each item looks like this:
399
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
401
402The first element is a regular expression to be matched. The second
403is a number that says what regular expression grouping used to find
404the entire emphasized word. The third is a number that says what
405regexp grouping should be displayed and highlighted. The fourth
406is the face used for highlighting."
ae465fa7
MB
407 :type
408 '(repeat
409 (menu-choice
410 :format "%[Customizing Style%]\n%v"
411 :indent 2
412 (group :tag "Default"
413 :value ("" 0 0 default)
414 :value-create
415 (lambda (widget)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
418 :args))
419 :value)))
420 (if (not (eq (nth 2 value) 'default))
421 (widget-put
422 widget
423 :value
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
ad136a7c
MB
426 regexp
427 (integer :format "Match group: %v")
01c52d31 428 (integer :format "Emphasize group: %v")
ae465fa7
MB
429 face)
430 (group :tag "Simple"
431 :value (("_" . "_") nil default)
432 (cons :format "%v"
ad136a7c
MB
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
ae465fa7
MB
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
437 face)))
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
443 value)))
eec82323
LMI
444 :group 'gnus-article-emphasis)
445
16409b0b
GM
446(defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449The former avoids underlining of leading and trailing whitespace,
450and the latter avoids underlining any whitespace at all."
fc2c2db8 451 :version "21.1"
16409b0b
GM
452 :group 'gnus-article-emphasis
453 :type 'regexp)
454
23f87bed 455(defface gnus-emphasis-bold '((t (:bold t)))
eec82323
LMI
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
458
23f87bed 459(defface gnus-emphasis-italic '((t (:italic t)))
eec82323
LMI
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
462
463(defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
466
23f87bed 467(defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
eec82323
LMI
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
470
23f87bed 471(defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
8de38c21 472 "Face used for displaying underlined italic emphasized text (_/word/_)."
eec82323
LMI
473 :group 'gnus-article-emphasis)
474
23f87bed 475(defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
eec82323
LMI
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
478
479(defface gnus-emphasis-underline-bold-italic
23f87bed 480 '((t (:bold t :italic t :underline t)))
eec82323 481 "Face used for displaying underlined bold italic emphasized text.
8f688cb0 482Example: (_/*word*/_)."
eec82323
LMI
483 :group 'gnus-article-emphasis)
484
23f87bed
MB
485(defface gnus-emphasis-strikethru (if (featurep 'xemacs)
486 '((t (:strikethru t)))
487 '((t (:strike-through t))))
488 "Face used for displaying strike-through text (-word-)."
489 :group 'gnus-article-emphasis)
490
16409b0b
GM
491(defface gnus-emphasis-highlight-words
492 '((t (:background "black" :foreground "yellow")))
493 "Face used for displaying highlighted words."
494 :group 'gnus-article-emphasis)
495
01c52d31 496(defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
eec82323 497 "Format for display of Date headers in article bodies.
6748645f
LMI
498See `format-time-string' for the possible values.
499
500The variable can also be function, which should return a complete Date
501header. The function is called with one argument, the time, which can
502be fed to `format-time-string'."
01c52d31 503 :type '(choice string function)
eec82323
LMI
504 :link '(custom-manual "(gnus)Article Date")
505 :group 'gnus-article-washing)
506
eec82323 507(defcustom gnus-save-all-headers t
26c9afc3
MB
508 "*If non-nil, don't remove any headers before saving.
509This will be overridden by the `:headers' property that the symbol of
510the saver function, which is specified by `gnus-default-article-saver',
511might have."
eec82323
LMI
512 :group 'gnus-article-saving
513 :type 'boolean)
514
515(defcustom gnus-prompt-before-saving 'always
516 "*This variable says how much prompting is to be done when saving articles.
517If it is nil, no prompting will be done, and the articles will be
518saved to the default files. If this variable is `always', each and
519every article that is saved will be preceded by a prompt, even when
520saving large batches of articles. If this variable is neither nil not
521`always', there the user will be prompted once for a file name for
522each invocation of the saving commands."
523 :group 'gnus-article-saving
524 :type '(choice (item always)
525 (item :tag "never" nil)
6748645f 526 (sexp :tag "once" :format "%t\n" :value t)))
eec82323
LMI
527
528(defcustom gnus-saved-headers gnus-visible-headers
529 "Headers to keep if `gnus-save-all-headers' is nil.
530If `gnus-save-all-headers' is non-nil, this variable will be ignored.
531If that variable is nil, however, all headers that match this regexp
26c9afc3
MB
532will be kept while the rest will be deleted before saving. This and
533`gnus-save-all-headers' will be overridden by the `:headers' property
534that the symbol of the saver function, which is specified by
535`gnus-default-article-saver', might have."
eec82323 536 :group 'gnus-article-saving
4bb6a3a6 537 :type 'regexp)
eec82323
LMI
538
539(defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
540 "A function to save articles in your favourite format.
26c9afc3
MB
541The function will be called by way of the `gnus-summary-save-article'
542command, and friends such as `gnus-summary-save-article-rmail'.
eec82323
LMI
543
544Gnus provides the following functions:
545
546* gnus-summary-save-in-rmail (Rmail format)
547* gnus-summary-save-in-mail (Unix mail format)
548* gnus-summary-save-in-folder (MH folder)
549* gnus-summary-save-in-file (article format)
23f87bed 550* gnus-summary-save-body-in-file (article body)
eec82323 551* gnus-summary-save-in-vm (use VM's folder format)
26c9afc3
MB
552* gnus-summary-write-to-file (article format -- overwrite)
553* gnus-summary-write-body-to-file (article body -- overwrite)
554
555The symbol of each function may have the following properties:
556
557* :decode
558The value non-nil means save decoded articles. This is meaningful
559only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560`gnus-summary-write-to-file', and `gnus-summary-write-body-to-file'.
561
562* :function
563The value specifies an alternative function which appends, not
564overwrites, articles to a file. This implies that when saving many
565articles at a time, `gnus-prompt-before-saving' is bound to t and all
566articles are saved in a single file. This is meaningful only with
567`gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
568
569* :headers
570The value specifies the symbol of a variable of which the value
571specifies headers to be saved. If it is omitted,
572`gnus-save-all-headers' and `gnus-saved-headers' control what
573headers should be saved."
eec82323
LMI
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
23f87bed 579 (function-item gnus-summary-save-body-in-file)
eec82323 580 (function-item gnus-summary-save-in-vm)
58090a8d 581 (function-item gnus-summary-write-to-file)
26c9afc3 582 (function-item gnus-summary-write-body-to-file)
58090a8d 583 (function)))
eec82323 584
26c9afc3
MB
585(defcustom gnus-article-save-coding-system
586 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
587 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
588 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
589 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
590 "Coding system used to save decoded articles to a file.
591
592The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
593which can safely encode any characters in text. This is used by the
594commands including:
595
596* gnus-summary-save-article-file
597* gnus-summary-save-article-body-file
598* gnus-summary-write-article-file
599* gnus-summary-write-article-body-file
600
601and the functions to which you may set `gnus-default-article-saver':
602
603* gnus-summary-save-in-file
604* gnus-summary-save-body-in-file
605* gnus-summary-write-to-file
606* gnus-summary-write-body-to-file
607
608Those commands and functions save just text displayed in the article
609buffer to a file if the value of this variable is non-nil. Note that
610buttonized MIME parts will be lost in a saved file in that case.
611Otherwise, raw articles will be saved."
612 :group 'gnus-article-saving
613 :type `(choice
614 :format "%{%t%}:\n %[Value Menu%] %v"
615 (const :tag "Save raw articles" nil)
616 ,@(delq nil
617 (mapcar
618 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
619 '((const :tag "UTF-8" utf-8)
620 (const :tag "iso-2022-7bit" iso-2022-7bit)
621 (const :tag "Emacs internal" emacs-mule)
622 (const :tag "escape-quoted" escape-quoted))))
623 (symbol :tag "Coding system")))
624
eec82323
LMI
625(defcustom gnus-rmail-save-name 'gnus-plain-save-name
626 "A function generating a file name to save articles in Rmail format.
627The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
628 :group 'gnus-article-saving
629 :type 'function)
630
631(defcustom gnus-mail-save-name 'gnus-plain-save-name
632 "A function generating a file name to save articles in Unix mail format.
633The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
634 :group 'gnus-article-saving
635 :type 'function)
636
637(defcustom gnus-folder-save-name 'gnus-folder-save-name
638 "A function generating a file name to save articles in MH folder.
639The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
640 :group 'gnus-article-saving
641 :type 'function)
642
643(defcustom gnus-file-save-name 'gnus-numeric-save-name
644 "A function generating a file name to save articles in article format.
645The function is called with NEWSGROUP, HEADERS, and optional
646LAST-FILE."
647 :group 'gnus-article-saving
648 :type 'function)
649
650(defcustom gnus-split-methods
651 '((gnus-article-archive-name)
652 (gnus-article-nndoc-name))
6748645f 653 "*Variable used to suggest where articles are to be saved.
eec82323
LMI
654For instance, if you would like to save articles related to Gnus in
655the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
656you could set this variable to something like:
657
658 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
659 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
660
01c52d31
MB
661This variable is an alist where the key is the match and the
662value is a list of possible files to save in if the match is
663non-nil.
eec82323
LMI
664
665If the match is a string, it is used as a regexp match on the
666article. If the match is a symbol, that symbol will be funcalled
667from the buffer of the article to be saved with the newsgroup as the
01c52d31 668parameter. If it is a list, it will be evaled in the same buffer.
eec82323 669
01c52d31
MB
670If this form or function returns a string, this string will be used as a
671possible file name; and if it returns a non-nil list, that list will be
672used as possible file names."
eec82323 673 :group 'gnus-article-saving
6748645f
LMI
674 :type '(repeat (choice (list :value (fun) function)
675 (cons :value ("" "") regexp (repeat string))
676 (sexp :value nil))))
eec82323 677
eec82323
LMI
678(defcustom gnus-page-delimiter "^\^L"
679 "*Regexp describing what to use as article page delimiters.
680The default value is \"^\^L\", which is a form linefeed at the
681beginning of a line."
682 :type 'regexp
683 :group 'gnus-article-various)
684
16409b0b 685(defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
eec82323 686 "*The format specification for the article mode line.
16409b0b
GM
687See `gnus-summary-mode-line-format' for a closer description.
688
689The following additional specs are available:
690
691%w The article washing status.
692%m The number of MIME parts in the article."
eec82323
LMI
693 :type 'string
694 :group 'gnus-article-various)
695
696(defcustom gnus-article-mode-hook nil
697 "*A hook for Gnus article mode."
698 :type 'hook
699 :group 'gnus-article-various)
700
23f87bed
MB
701(when (featurep 'xemacs)
702 ;; Extracted from gnus-xmas-define in order to preserve user settings
703 (when (fboundp 'turn-off-scroll-in-place)
704 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
705 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
706 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
707
eec82323
LMI
708(defcustom gnus-article-menu-hook nil
709 "*Hook run after the creation of the article mode menu."
710 :type 'hook
711 :group 'gnus-article-various)
712
713(defcustom gnus-article-prepare-hook nil
16409b0b 714 "*A hook called after an article has been prepared in the article buffer."
eec82323
LMI
715 :type 'hook
716 :group 'gnus-article-various)
717
01c52d31
MB
718(defcustom gnus-copy-article-ignored-headers nil
719 "List of headers to be removed when copying an article.
720Each element is a regular expression."
330f707b 721 :version "23.1" ;; No Gnus
01c52d31
MB
722 :type '(repeat regexp)
723 :group 'gnus-article-various)
724
23f87bed
MB
725(make-obsolete-variable 'gnus-article-hide-pgp-hook
726 "This variable is obsolete in Gnus 5.10.")
a8151ef7 727
01c52d31
MB
728(defface gnus-button
729 '((t (:weight bold)))
730 "Face used for highlighting a button in the article buffer."
731 :group 'gnus-article-buttons)
732
733(defcustom gnus-article-button-face 'gnus-button
eec82323
LMI
734 "Face used for highlighting buttons in the article buffer.
735
736An article button is a piece of text that you can activate by pressing
737`RET' or `mouse-2' above it."
738 :type 'face
739 :group 'gnus-article-buttons)
740
741(defcustom gnus-article-mouse-face 'highlight
742 "Face used for mouse highlighting in the article buffer.
743
744Article buttons will be displayed in this face when the cursor is
745above them."
746 :type 'face
747 :group 'gnus-article-buttons)
748
0f49874b 749(defcustom gnus-signature-face 'gnus-signature
a8151ef7 750 "Face used for highlighting a signature in the article buffer.
0f49874b 751Obsolete; use the face `gnus-signature' for customizations instead."
eec82323
LMI
752 :type 'face
753 :group 'gnus-article-highlight
754 :group 'gnus-article-signature)
755
0f49874b 756(defface gnus-signature
f59a3415 757 '((t
23f87bed 758 (:italic t)))
a8151ef7
LMI
759 "Face used for highlighting a signature in the article buffer."
760 :group 'gnus-article-highlight
761 :group 'gnus-article-signature)
0f49874b
MB
762;; backward-compatibility alias
763(put 'gnus-signature-face 'face-alias 'gnus-signature)
a8151ef7 764
0f49874b 765(defface gnus-header-from
eec82323
LMI
766 '((((class color)
767 (background dark))
01c52d31 768 (:foreground "PaleGreen1"))
eec82323
LMI
769 (((class color)
770 (background light))
6748645f 771 (:foreground "red3"))
eec82323 772 (t
23f87bed 773 (:italic t)))
eec82323
LMI
774 "Face used for displaying from headers."
775 :group 'gnus-article-headers
776 :group 'gnus-article-highlight)
0f49874b
MB
777;; backward-compatibility alias
778(put 'gnus-header-from-face 'face-alias 'gnus-header-from)
eec82323 779
0f49874b 780(defface gnus-header-subject
eec82323
LMI
781 '((((class color)
782 (background dark))
01c52d31 783 (:foreground "SeaGreen1"))
eec82323
LMI
784 (((class color)
785 (background light))
6748645f 786 (:foreground "red4"))
eec82323 787 (t
23f87bed 788 (:bold t :italic t)))
eec82323
LMI
789 "Face used for displaying subject headers."
790 :group 'gnus-article-headers
791 :group 'gnus-article-highlight)
0f49874b
MB
792;; backward-compatibility alias
793(put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
eec82323 794
0f49874b 795(defface gnus-header-newsgroups
eec82323
LMI
796 '((((class color)
797 (background dark))
23f87bed 798 (:foreground "yellow" :italic t))
eec82323
LMI
799 (((class color)
800 (background light))
23f87bed 801 (:foreground "MidnightBlue" :italic t))
eec82323 802 (t
23f87bed
MB
803 (:italic t)))
804 "Face used for displaying newsgroups headers.
805In the default setup this face is only used for crossposted
806articles."
eec82323
LMI
807 :group 'gnus-article-headers
808 :group 'gnus-article-highlight)
0f49874b
MB
809;; backward-compatibility alias
810(put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
eec82323 811
0f49874b 812(defface gnus-header-name
eec82323
LMI
813 '((((class color)
814 (background dark))
01c52d31 815 (:foreground "SpringGreen2"))
eec82323
LMI
816 (((class color)
817 (background light))
818 (:foreground "maroon"))
819 (t
23f87bed 820 (:bold t)))
eec82323
LMI
821 "Face used for displaying header names."
822 :group 'gnus-article-headers
823 :group 'gnus-article-highlight)
0f49874b
MB
824;; backward-compatibility alias
825(put 'gnus-header-name-face 'face-alias 'gnus-header-name)
eec82323 826
0f49874b 827(defface gnus-header-content
eec82323
LMI
828 '((((class color)
829 (background dark))
01c52d31 830 (:foreground "SpringGreen1" :italic t))
eec82323
LMI
831 (((class color)
832 (background light))
23f87bed 833 (:foreground "indianred4" :italic t))
eec82323 834 (t
23f87bed 835 (:italic t))) "Face used for displaying header content."
eec82323
LMI
836 :group 'gnus-article-headers
837 :group 'gnus-article-highlight)
0f49874b
MB
838;; backward-compatibility alias
839(put 'gnus-header-content-face 'face-alias 'gnus-header-content)
eec82323
LMI
840
841(defcustom gnus-header-face-alist
0f49874b
MB
842 '(("From" nil gnus-header-from)
843 ("Subject" nil gnus-header-subject)
844 ("Newsgroups:.*," nil gnus-header-newsgroups)
845 ("" gnus-header-name gnus-header-content))
23f87bed 846 "*Controls highlighting of article headers.
eec82323
LMI
847
848An alist of the form (HEADER NAME CONTENT).
849
23f87bed
MB
850HEADER is a regular expression which should match the name of a
851header and NAME and CONTENT are either face names or nil.
eec82323
LMI
852
853The name of each header field will be displayed using the face
23f87bed
MB
854specified by the first element in the list where HEADER matches
855the header name and NAME is non-nil. Similarly, the content will
856be displayed by the first non-nil matching CONTENT face."
eec82323
LMI
857 :group 'gnus-article-headers
858 :group 'gnus-article-highlight
859 :type '(repeat (list (regexp :tag "Header")
860 (choice :tag "Name"
861 (item :tag "skip" nil)
862 (face :value default))
863 (choice :tag "Content"
864 (item :tag "skip" nil)
865 (face :value default)))))
866
01c52d31
MB
867(defcustom gnus-face-properties-alist (if (featurep 'xemacs)
868 '((xface . (:face gnus-x-face)))
869 '((pbm . (:face gnus-x-face))
870 (png . nil)))
871 "Alist of image types and properties applied to Face and X-Face images.
872Here are examples:
873
874;; Specify the altitude of Face images in the From header.
875\(setq gnus-face-properties-alist
876 '((pbm . (:face gnus-x-face :ascent 80))
877 (png . (:ascent 80))))
878
879;; Show Face images as pressed buttons.
880\(setq gnus-face-properties-alist
881 '((pbm . (:face gnus-x-face :relief -2))
882 (png . (:relief -2))))
883
884See the manual for the valid properties for various image types.
885Currently, `pbm' is used for X-Face images and `png' is used for Face
886images in Emacs. Only the `:face' property is effective on the `xface'
887image type in XEmacs if it is built with the libcompface library."
330f707b 888 :version "23.1" ;; No Gnus
01c52d31
MB
889 :group 'gnus-article-headers
890 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
891
16409b0b 892(defcustom gnus-article-decode-hook
23f87bed
MB
893 '(article-decode-charset article-decode-encoded-words
894 article-decode-group-name article-decode-idna-rhs)
16409b0b
GM
895 "*Hook run to decode charsets in articles."
896 :group 'gnus-article-headers
897 :type 'hook)
898
899(defcustom gnus-display-mime-function 'gnus-display-mime
900 "Function to display MIME articles."
901 :group 'gnus-article-mime
902 :type 'function)
903
904(defvar gnus-decode-header-function 'mail-decode-encoded-word-region
905 "Function used to decode headers.")
906
343d6628
MB
907(defvar gnus-decode-address-function 'mail-decode-encoded-address-region
908 "Function used to decode addresses.")
909
16409b0b 910(defvar gnus-article-dumbquotes-map
23f87bed
MB
911 '(("\200" "EUR")
912 ("\202" ",")
16409b0b
GM
913 ("\203" "f")
914 ("\204" ",,")
915 ("\205" "...")
916 ("\213" "<")
917 ("\214" "OE")
918 ("\221" "`")
919 ("\222" "'")
920 ("\223" "``")
921 ("\224" "\"")
922 ("\225" "*")
e0bad764
DL
923 ("\226" "-")
924 ("\227" "--")
23f87bed 925 ("\230" "~")
16409b0b
GM
926 ("\231" "(TM)")
927 ("\233" ">")
928 ("\234" "oe")
929 ("\264" "'"))
930 "Table for MS-to-Latin1 translation.")
931
932(defcustom gnus-ignored-mime-types nil
933 "List of MIME types that should be ignored by Gnus."
fc2c2db8 934 :version "21.1"
16409b0b
GM
935 :group 'gnus-article-mime
936 :type '(repeat regexp))
937
938(defcustom gnus-unbuttonized-mime-types '(".*/.*")
23f87bed
MB
939 "List of MIME types that should not be given buttons when rendered inline.
940See also `gnus-buttonized-mime-types' which may override this variable.
941This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
942 :version "21.1"
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
945
946(defcustom gnus-buttonized-mime-types nil
947 "List of MIME types that should be given buttons when rendered inline.
948If set, this variable overrides `gnus-unbuttonized-mime-types'.
949To see e.g. security buttons you could set this to
3031d8b0
MB
950`(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
951this list to display radio buttons that allow you to choose one of two
952media types those mails include. See also `mm-discouraged-alternatives'.
23f87bed 953This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
bf247b6e 954 :version "22.1"
16409b0b
GM
955 :group 'gnus-article-mime
956 :type '(repeat regexp))
957
23f87bed
MB
958(defcustom gnus-inhibit-mime-unbuttonizing nil
959 "If non-nil, all MIME parts get buttons.
960When nil (the default value), then some MIME parts do not get buttons,
961as described by the variables `gnus-buttonized-mime-types' and
962`gnus-unbuttonized-mime-types'."
bf247b6e 963 :version "22.1"
d0859c9a 964 :group 'gnus-article-mime
23f87bed
MB
965 :type 'boolean)
966
967(defcustom gnus-body-boundary-delimiter "_"
968 "String used to delimit header and body.
969This variable is used by `gnus-article-treat-body-boundary' which can
970be controlled by `gnus-treat-body-boundary'."
bf247b6e 971 :version "22.1"
23f87bed
MB
972 :group 'gnus-article-various
973 :type '(choice (item :tag "None" :value nil)
974 string))
975
97f78c9b
MB
976(defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
977 "/usr/share/picons")
23f87bed
MB
978 "Defines the location of the faces database.
979For information on obtaining this database of pretty pictures, please
980see http://www.cs.indiana.edu/picons/ftp/index.html"
bf247b6e 981 :version "22.1"
23f87bed
MB
982 :type '(repeat directory)
983 :link '(url-link :tag "download"
984 "http://www.cs.indiana.edu/picons/ftp/index.html")
985 :link '(custom-manual "(gnus)Picons")
986 :group 'gnus-picon)
987
988(defun gnus-picons-installed-p ()
989 "Say whether picons are installed on your machine."
990 (let ((installed nil))
991 (dolist (database gnus-picon-databases)
992 (when (file-exists-p database)
993 (setq installed t)))
994 installed))
995
16409b0b
GM
996(defcustom gnus-article-mime-part-function nil
997 "Function called with a MIME handle as the argument.
998This is meant for people who want to do something automatic based
999on parts -- for instance, adding Vcard info to a database."
1000 :group 'gnus-article-mime
4a2358e9
MB
1001 :type '(choice (const nil)
1002 function))
16409b0b
GM
1003
1004(defcustom gnus-mime-multipart-functions nil
fc2c2db8
DL
1005 "An alist of MIME types to functions to display them."
1006 :version "21.1"
1007 :group 'gnus-article-mime
01c52d31 1008 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
16409b0b
GM
1009
1010(defcustom gnus-article-date-lapsed-new-header nil
1011 "Whether the X-Sent and Date headers can coexist.
1012When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1013either replace the old \"Date:\" header (if this variable is nil), or
1014be added below it (otherwise)."
fc2c2db8 1015 :version "21.1"
16409b0b
GM
1016 :group 'gnus-article-headers
1017 :type 'boolean)
1018
1019(defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1020 "Function called with a MIME handle as the argument.
1021This is meant for people who want to view first matched part.
a1506d29
JB
1022For `undisplayed-alternative' (default), the first undisplayed
1023part or alternative part is used. For `undisplayed', the first
1024undisplayed part is used. For a function, the first part which
f20b2f5c 1025the function return t is used. For nil, the first part is
16409b0b 1026used."
fc2c2db8 1027 :version "21.1"
16409b0b 1028 :group 'gnus-article-mime
a1506d29 1029 :type '(choice
16409b0b
GM
1030 (item :tag "first" :value nil)
1031 (item :tag "undisplayed" :value undisplayed)
a1506d29 1032 (item :tag "undisplayed or alternative"
16409b0b
GM
1033 :value undisplayed-alternative)
1034 (function)))
1035
e0bad764
DL
1036(defcustom gnus-mime-action-alist
1037 '(("save to file" . gnus-mime-save-part)
23f87bed 1038 ("save and strip" . gnus-mime-save-part-and-strip)
01c52d31 1039 ("replace with file" . gnus-mime-replace-part)
23f87bed 1040 ("delete part" . gnus-mime-delete-part)
e0bad764
DL
1041 ("display as text" . gnus-mime-inline-part)
1042 ("view the part" . gnus-mime-view-part)
1043 ("pipe to command" . gnus-mime-pipe-part)
1044 ("toggle display" . gnus-article-press-button)
23f87bed 1045 ("toggle display" . gnus-article-view-part-as-charset)
e0bad764 1046 ("view as type" . gnus-mime-view-part-as-type)
23f87bed
MB
1047 ("view internally" . gnus-mime-view-part-internally)
1048 ("view externally" . gnus-mime-view-part-externally))
e0bad764
DL
1049 "An alist of actions that run on the MIME attachment."
1050 :group 'gnus-article-mime
1051 :type '(repeat (cons (string :tag "name")
1052 (function))))
1053
01c52d31
MB
1054(defcustom gnus-auto-select-part 1
1055 "Advance to next MIME part when deleting or stripping parts.
1056
1057When 0, point will be placed on the same part as before. When
1058positive (negative), move point forward (backwards) this many
1059parts. When nil, redisplay article."
330f707b 1060 :version "23.1" ;; No Gnus
01c52d31
MB
1061 :group 'gnus-article-mime
1062 :type '(choice (const nil :tag "Redisplay article.")
1063 (const 1 :tag "Next part.")
1064 (const 0 :tag "Current part.")
1065 integer))
1066
16409b0b
GM
1067;;;
1068;;; The treatment variables
1069;;;
1070
1071(defvar gnus-part-display-hook nil
1072 "Hook called on parts that are to receive treatment.")
1073
1074(defvar gnus-article-treat-custom
1075 '(choice (const :tag "Off" nil)
1076 (const :tag "On" t)
1077 (const :tag "Header" head)
01c52d31 1078 (const :tag "First" first)
16409b0b
GM
1079 (const :tag "Last" last)
1080 (integer :tag "Less")
1081 (repeat :tag "Groups" regexp)
1082 (sexp :tag "Predicate")))
1083
1084(defvar gnus-article-treat-head-custom
1085 '(choice (const :tag "Off" nil)
1086 (const :tag "Header" head)))
1087
01c52d31
MB
1088(defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1089 "text/x-patch")
16409b0b
GM
1090 "Parts to treat.")
1091
1092(defvar gnus-inhibit-treatment nil
1093 "Whether to inhibit treatment.")
1094
23f87bed 1095(defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
16409b0b 1096 "Highlight the signature.
01c52d31
MB
1097Valid values are nil, t, `head', `first', `last', an integer or a
1098predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1099 :group 'gnus-article-treat
23f87bed 1100 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1101 :type gnus-article-treat-custom)
1102(put 'gnus-treat-highlight-signature 'highlight t)
1103
1104(defcustom gnus-treat-buttonize 100000
1105 "Add buttons.
01c52d31
MB
1106Valid values are nil, t, `head', `first', `last', an integer or a
1107predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1108 :group 'gnus-article-treat
23f87bed 1109 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1110 :type gnus-article-treat-custom)
1111(put 'gnus-treat-buttonize 'highlight t)
1112
1113(defcustom gnus-treat-buttonize-head 'head
1114 "Add buttons to the head.
01c52d31
MB
1115Valid values are nil, t, `head', `first', `last', an integer or a
1116predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1117 :group 'gnus-article-treat
23f87bed 1118 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1119 :type gnus-article-treat-head-custom)
1120(put 'gnus-treat-buttonize-head 'highlight t)
1121
437ce4be 1122(defcustom gnus-treat-emphasize 50000
16409b0b 1123 "Emphasize text.
01c52d31
MB
1124Valid values are nil, t, `head', `first', `last', an integer or a
1125predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1126 :group 'gnus-article-treat
23f87bed 1127 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1128 :type gnus-article-treat-custom)
1129(put 'gnus-treat-emphasize 'highlight t)
1130
1131(defcustom gnus-treat-strip-cr nil
1132 "Remove carriage returns.
01c52d31
MB
1133Valid values are nil, t, `head', `first', `last', an integer or a
1134predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1135 :version "22.1"
16409b0b 1136 :group 'gnus-article-treat
23f87bed
MB
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-custom)
1139
1140(defcustom gnus-treat-unsplit-urls nil
1141 "Remove newlines from within URLs.
01c52d31
MB
1142Valid values are nil, t, `head', `first', `last', an integer or a
1143predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1144 :version "22.1"
23f87bed
MB
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-custom)
1148
1149(defcustom gnus-treat-leading-whitespace nil
1150 "Remove leading whitespace in headers.
01c52d31
MB
1151Valid values are nil, t, `head', `first', `last', an integer or a
1152predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1153 :version "22.1"
23f87bed
MB
1154 :group 'gnus-article-treat
1155 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1156 :type gnus-article-treat-custom)
1157
1158(defcustom gnus-treat-hide-headers 'head
1159 "Hide headers.
01c52d31
MB
1160Valid values are nil, t, `head', `first', `last', an integer or a
1161predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1162 :group 'gnus-article-treat
23f87bed 1163 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1164 :type gnus-article-treat-head-custom)
1165
1166(defcustom gnus-treat-hide-boring-headers nil
1167 "Hide boring headers.
01c52d31
MB
1168Valid values are nil, t, `head', `first', `last', an integer or a
1169predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1170 :group 'gnus-article-treat
23f87bed 1171 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1172 :type gnus-article-treat-head-custom)
1173
1174(defcustom gnus-treat-hide-signature nil
1175 "Hide the signature.
01c52d31
MB
1176Valid values are nil, t, `head', `first', `last', an integer or a
1177predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1178 :group 'gnus-article-treat
23f87bed 1179 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1180 :type gnus-article-treat-custom)
1181
1182(defcustom gnus-treat-fill-article nil
1183 "Fill the article.
01c52d31
MB
1184Valid values are nil, t, `head', `first', `last', an integer or a
1185predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1186 :group 'gnus-article-treat
23f87bed 1187 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1188 :type gnus-article-treat-custom)
1189
1190(defcustom gnus-treat-hide-citation nil
1191 "Hide cited text.
01c52d31
MB
1192Valid values are nil, t, `head', `first', `last', an integer or a
1193predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1194 :group 'gnus-article-treat
23f87bed 1195 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1196 :type gnus-article-treat-custom)
1197
e0bad764
DL
1198(defcustom gnus-treat-hide-citation-maybe nil
1199 "Hide cited text.
01c52d31
MB
1200Valid values are nil, t, `head', `first', `last', an integer or a
1201predicate. See Info node `(gnus)Customizing Articles'."
e0bad764 1202 :group 'gnus-article-treat
23f87bed 1203 :link '(custom-manual "(gnus)Customizing Articles")
e0bad764
DL
1204 :type gnus-article-treat-custom)
1205
16409b0b
GM
1206(defcustom gnus-treat-strip-list-identifiers 'head
1207 "Strip list identifiers from `gnus-list-identifiers`.
01c52d31
MB
1208Valid values are nil, t, `head', `first', `last', an integer or a
1209predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1210 :version "21.1"
16409b0b 1211 :group 'gnus-article-treat
23f87bed 1212 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1213 :type gnus-article-treat-custom)
1214
23f87bed
MB
1215(make-obsolete-variable 'gnus-treat-strip-pgp
1216 "This option is obsolete in Gnus 5.10.")
16409b0b
GM
1217
1218(defcustom gnus-treat-strip-pem nil
1219 "Strip PEM signatures.
01c52d31
MB
1220Valid values are nil, t, `head', `first', `last', an integer or a
1221predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1222 :group 'gnus-article-treat
23f87bed 1223 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1224 :type gnus-article-treat-custom)
1225
1226(defcustom gnus-treat-strip-banner t
1227 "Strip banners from articles.
1228The banner to be stripped is specified in the `banner' group parameter.
01c52d31
MB
1229Valid values are nil, t, `head', `first', `last', an integer or a
1230predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1231 :group 'gnus-article-treat
23f87bed 1232 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1233 :type gnus-article-treat-custom)
1234
1235(defcustom gnus-treat-highlight-headers 'head
1236 "Highlight the headers.
01c52d31
MB
1237Valid values are nil, t, `head', `first', `last', an integer or a
1238predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1239 :group 'gnus-article-treat
23f87bed 1240 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1241 :type gnus-article-treat-head-custom)
1242(put 'gnus-treat-highlight-headers 'highlight t)
1243
1244(defcustom gnus-treat-highlight-citation t
1245 "Highlight cited text.
01c52d31
MB
1246Valid values are nil, t, `head', `first', `last', an integer or a
1247predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1248 :group 'gnus-article-treat
23f87bed 1249 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1250 :type gnus-article-treat-custom)
1251(put 'gnus-treat-highlight-citation 'highlight t)
1252
1253(defcustom gnus-treat-date-ut nil
1254 "Display the Date in UT (GMT).
01c52d31
MB
1255Valid values are nil, t, `head', `first', `last', an integer or a
1256predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1257 :group 'gnus-article-treat
23f87bed 1258 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1259 :type gnus-article-treat-head-custom)
1260
1261(defcustom gnus-treat-date-local nil
1262 "Display the Date in the local timezone.
01c52d31
MB
1263Valid values are nil, t, `head', `first', `last', an integer or a
1264predicate. See Info node `(gnus)Customizing Articles'."
23f87bed
MB
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-head-custom)
1268
1269(defcustom gnus-treat-date-english nil
1270 "Display the Date in a format that can be read aloud in English.
01c52d31
MB
1271Valid values are nil, t, `head', `first', `last', an integer or a
1272predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1273 :version "22.1"
16409b0b 1274 :group 'gnus-article-treat
23f87bed 1275 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1276 :type gnus-article-treat-head-custom)
1277
1278(defcustom gnus-treat-date-lapsed nil
1279 "Display the Date header in a way that says how much time has elapsed.
01c52d31
MB
1280Valid values are nil, t, `head', `first', `last', an integer or a
1281predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1282 :group 'gnus-article-treat
23f87bed 1283 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1284 :type gnus-article-treat-head-custom)
1285
1286(defcustom gnus-treat-date-original nil
1287 "Display the date in the original timezone.
01c52d31
MB
1288Valid values are nil, t, `head', `first', `last', an integer or a
1289predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1290 :group 'gnus-article-treat
23f87bed 1291 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1292 :type gnus-article-treat-head-custom)
1293
1294(defcustom gnus-treat-date-iso8601 nil
1295 "Display the date in the ISO8601 format.
01c52d31
MB
1296Valid values are nil, t, `head', `first', `last', an integer or a
1297predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1298 :version "21.1"
16409b0b 1299 :group 'gnus-article-treat
23f87bed 1300 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1301 :type gnus-article-treat-head-custom)
1302
1303(defcustom gnus-treat-date-user-defined nil
1304 "Display the date in a user-defined format.
1305The format is defined by the `gnus-article-time-format' variable.
01c52d31
MB
1306Valid values are nil, t, `head', `first', `last', an integer or a
1307predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1308 :group 'gnus-article-treat
23f87bed 1309 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1310 :type gnus-article-treat-head-custom)
1311
1312(defcustom gnus-treat-strip-headers-in-body t
1313 "Strip the X-No-Archive header line from the beginning of the body.
01c52d31
MB
1314Valid values are nil, t, `head', `first', `last', an integer or a
1315predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1316 :version "21.1"
16409b0b 1317 :group 'gnus-article-treat
23f87bed 1318 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1319 :type gnus-article-treat-custom)
1320
1321(defcustom gnus-treat-strip-trailing-blank-lines nil
1322 "Strip trailing blank lines.
01c52d31
MB
1323Valid values are nil, t, `head', `first', `last', an integer or a
1324predicate. See Info node `(gnus)Customizing Articles'.
292f71fe
MB
1325
1326When set to t, it also strips trailing blanks in all MIME parts.
1327Consider to use `last' instead."
16409b0b 1328 :group 'gnus-article-treat
23f87bed 1329 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1330 :type gnus-article-treat-custom)
1331
1332(defcustom gnus-treat-strip-leading-blank-lines nil
1333 "Strip leading blank lines.
01c52d31
MB
1334Valid values are nil, t, `head', `first', `last', an integer or a
1335predicate. See Info node `(gnus)Customizing Articles'.
292f71fe
MB
1336
1337When set to t, it also strips trailing blanks in all MIME parts."
16409b0b 1338 :group 'gnus-article-treat
23f87bed 1339 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1340 :type gnus-article-treat-custom)
1341
1342(defcustom gnus-treat-strip-multiple-blank-lines nil
1343 "Strip multiple blank lines.
01c52d31
MB
1344Valid values are nil, t, `head', `first', `last', an integer or a
1345predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1346 :group 'gnus-article-treat
23f87bed
MB
1347 :link '(custom-manual "(gnus)Customizing Articles")
1348 :type gnus-article-treat-custom)
1349
1350(defcustom gnus-treat-unfold-headers 'head
1351 "Unfold folded header lines.
01c52d31
MB
1352Valid values are nil, t, `head', `first', `last', an integer or a
1353predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1354 :version "22.1"
23f87bed
MB
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1358
01c52d31
MB
1359(defcustom gnus-article-unfold-long-headers nil
1360 "If non-nil, allow unfolding headers even if the header is long.
1361If it is a regexp, only long headers matching this regexp are unfolded.
1362If it is t, all long headers are unfolded.
1363
1364This variable has no effect if `gnus-treat-unfold-headers' is nil."
330f707b 1365 :version "23.1" ;; No Gnus
01c52d31
MB
1366 :group 'gnus-article-treat
1367 :type '(choice (const nil)
1368 (const :tag "all" t)
1369 (regexp)))
1370
23f87bed
MB
1371(defcustom gnus-treat-fold-headers nil
1372 "Fold headers.
01c52d31
MB
1373Valid values are nil, t, `head', `first', `last', an integer or a
1374predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1375 :version "22.1"
23f87bed
MB
1376 :group 'gnus-article-treat
1377 :link '(custom-manual "(gnus)Customizing Articles")
1378 :type gnus-article-treat-custom)
1379
1380(defcustom gnus-treat-fold-newsgroups 'head
1381 "Fold the Newsgroups and Followup-To headers.
01c52d31
MB
1382Valid values are nil, t, `head', `first', `last', an integer or a
1383predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1384 :version "22.1"
23f87bed
MB
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1387 :type gnus-article-treat-custom)
1388
1389(defcustom gnus-treat-overstrike t
1390 "Treat overstrike highlighting.
01c52d31
MB
1391Valid values are nil, t, `head', `first', `last', an integer or a
1392predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1393 :group 'gnus-article-treat
23f87bed 1394 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1395 :type gnus-article-treat-custom)
1396(put 'gnus-treat-overstrike 'highlight t)
1397
01c52d31
MB
1398(defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1399 "Treat ANSI SGR control sequences.
1400Valid values are nil, t, `head', `first', `last', an integer or a
1401predicate. See Info node `(gnus)Customizing Articles'."
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1405
23f87bed
MB
1406(make-obsolete-variable 'gnus-treat-display-xface
1407 'gnus-treat-display-x-face)
1408
1409(defcustom gnus-treat-display-x-face
1410 (and (not noninteractive)
11e95b02
MB
1411 (gnus-image-type-available-p 'xbm)
1412 (if (featurep 'xemacs)
1413 (featurep 'xface)
1414 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1415 (executable-find "icontopbm")))
8b93df01 1416 'head)
16409b0b 1417 "Display X-Face headers.
87ba2830 1418Valid values are nil and `head'.
23f87bed
MB
1419See Info node `(gnus)Customizing Articles' and Info node
1420`(gnus)X-Face' for details."
1421 :group 'gnus-article-treat
1422 :version "21.1"
1423 :link '(custom-manual "(gnus)Customizing Articles")
1424 :link '(custom-manual "(gnus)X-Face")
1425 :type gnus-article-treat-head-custom
1426 :set (lambda (symbol value)
1427 (set-default
1428 symbol
1429 (cond ((or (boundp symbol) (get symbol 'saved-value))
1430 value)
1431 ((boundp 'gnus-treat-display-xface)
1432 (message "\
1433** gnus-treat-display-xface is an obsolete variable;\
1434 use gnus-treat-display-x-face instead")
1435 (default-value 'gnus-treat-display-xface))
1436 ((get 'gnus-treat-display-xface 'saved-value)
1437 (message "\
1438** gnus-treat-display-xface is an obsolete variable;\
1439 use gnus-treat-display-x-face instead")
1440 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1441 (t
1442 value)))))
1443(put 'gnus-treat-display-x-face 'highlight t)
1444
1445(defcustom gnus-treat-display-face
1446 (and (not noninteractive)
11e95b02 1447 (gnus-image-type-available-p 'png)
23f87bed
MB
1448 'head)
1449 "Display Face headers.
01c52d31
MB
1450Valid values are nil, t, `head', `first', `last', an integer or a
1451predicate. See Info node `(gnus)Customizing Articles' and Info
1452node `(gnus)X-Face' for details."
16409b0b 1453 :group 'gnus-article-treat
bf247b6e 1454 :version "22.1"
23f87bed
MB
1455 :link '(custom-manual "(gnus)Customizing Articles")
1456 :link '(custom-manual "(gnus)X-Face")
16409b0b 1457 :type gnus-article-treat-head-custom)
23f87bed 1458(put 'gnus-treat-display-face 'highlight t)
16409b0b 1459
11e95b02 1460(defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
16409b0b 1461 "Display smileys.
01c52d31
MB
1462Valid values are nil, t, `head', `first', `last', an integer or a
1463predicate. See Info node `(gnus)Customizing Articles' and Info
1464node `(gnus)Smileys' for details."
16409b0b 1465 :group 'gnus-article-treat
b5a206e7 1466 :version "21.1"
23f87bed
MB
1467 :link '(custom-manual "(gnus)Customizing Articles")
1468 :link '(custom-manual "(gnus)Smileys")
16409b0b
GM
1469 :type gnus-article-treat-custom)
1470(put 'gnus-treat-display-smileys 'highlight t)
1471
23f87bed
MB
1472(defcustom gnus-treat-from-picon
1473 (if (and (gnus-image-type-available-p 'xpm)
1474 (gnus-picons-installed-p))
1475 'head nil)
1476 "Display picons in the From header.
01c52d31
MB
1477Valid values are nil, t, `head', `first', `last', an integer or a
1478predicate. See Info node `(gnus)Customizing Articles' and Info
1479node `(gnus)Picons' for details."
bf247b6e 1480 :version "22.1"
16409b0b 1481 :group 'gnus-article-treat
23f87bed
MB
1482 :group 'gnus-picon
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Picons")
1485 :type gnus-article-treat-head-custom)
1486(put 'gnus-treat-from-picon 'highlight t)
1487
1488(defcustom gnus-treat-mail-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1491 'head nil)
1492 "Display picons in To and Cc headers.
01c52d31
MB
1493Valid values are nil, t, `head', `first', `last', an integer or a
1494predicate. See Info node `(gnus)Customizing Articles' and Info
1495node `(gnus)Picons' for details."
bf247b6e 1496 :version "22.1"
23f87bed
MB
1497 :group 'gnus-article-treat
1498 :group 'gnus-picon
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502(put 'gnus-treat-mail-picon 'highlight t)
1503
1504(defcustom gnus-treat-newsgroups-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1507 'head nil)
1508 "Display picons in the Newsgroups and Followup-To headers.
01c52d31
MB
1509Valid values are nil, t, `head', `first', `last', an integer or a
1510predicate. See Info node `(gnus)Customizing Articles' and Info
1511node `(gnus)Picons' for details."
bf247b6e 1512 :version "22.1"
23f87bed
MB
1513 :group 'gnus-article-treat
1514 :group 'gnus-picon
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518(put 'gnus-treat-newsgroups-picon 'highlight t)
1519
1520(defcustom gnus-treat-body-boundary
437ce4be
MB
1521 (if (or gnus-treat-newsgroups-picon
1522 gnus-treat-mail-picon
1523 gnus-treat-from-picon)
1524 ;; If there's much decoration, the user might prefer a boundery.
1525 'head
1526 nil)
23f87bed
MB
1527 "Draw a boundary at the end of the headers.
1528Valid values are nil and `head'.
1529See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1530 :version "22.1"
23f87bed
MB
1531 :group 'gnus-article-treat
1532 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b 1533 :type gnus-article-treat-head-custom)
16409b0b
GM
1534
1535(defcustom gnus-treat-capitalize-sentences nil
1536 "Capitalize sentence-starting words.
01c52d31
MB
1537Valid values are nil, t, `head', `first', `last', an integer or a
1538predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1539 :version "21.1"
16409b0b 1540 :group 'gnus-article-treat
23f87bed
MB
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :type gnus-article-treat-custom)
1543
1544(defcustom gnus-treat-wash-html nil
1545 "Format as HTML.
01c52d31
MB
1546Valid values are nil, t, `head', `first', `last', an integer or a
1547predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1548 :version "22.1"
23f87bed
MB
1549 :group 'gnus-article-treat
1550 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1551 :type gnus-article-treat-custom)
1552
1553(defcustom gnus-treat-fill-long-lines nil
1554 "Fill long lines.
01c52d31
MB
1555Valid values are nil, t, `head', `first', `last', an integer or a
1556predicate. See Info node `(gnus)Customizing Articles'."
16409b0b 1557 :group 'gnus-article-treat
23f87bed 1558 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1559 :type gnus-article-treat-custom)
1560
1561(defcustom gnus-treat-play-sounds nil
1562 "Play sounds.
01c52d31
MB
1563Valid values are nil, t, `head', `first', `last', an integer or a
1564predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1565 :version "21.1"
16409b0b 1566 :group 'gnus-article-treat
23f87bed 1567 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1568 :type gnus-article-treat-custom)
1569
1570(defcustom gnus-treat-translate nil
1571 "Translate articles from one language to another.
01c52d31
MB
1572Valid values are nil, t, `head', `first', `last', an integer or a
1573predicate. See Info node `(gnus)Customizing Articles'."
fc2c2db8 1574 :version "21.1"
16409b0b 1575 :group 'gnus-article-treat
23f87bed 1576 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1577 :type gnus-article-treat-custom)
1578
23f87bed
MB
1579(defcustom gnus-treat-x-pgp-sig nil
1580 "Verify X-PGP-Sig.
1581To automatically treat X-PGP-Sig, set it to head.
01c52d31
MB
1582Valid values are nil, t, `head', `first', `last', an integer or a
1583predicate. See Info node `(gnus)Customizing Articles'."
bf247b6e 1584 :version "22.1"
23f87bed
MB
1585 :group 'gnus-article-treat
1586 :group 'mime-security
1587 :link '(custom-manual "(gnus)Customizing Articles")
1588 :type gnus-article-treat-custom)
1589
1590(defvar gnus-article-encrypt-protocol-alist
1591 '(("PGP" . mml2015-self-encrypt)))
1592
1593;; Set to nil if more than one protocol added to
1594;; gnus-article-encrypt-protocol-alist.
1595(defcustom gnus-article-encrypt-protocol "PGP"
1596 "The protocol used for encrypt articles.
1597It is a string, such as \"PGP\". If nil, ask user."
bf247b6e 1598 :version "22.1"
23f87bed
MB
1599 :type 'string
1600 :group 'mime-security)
1601
1602(defvar gnus-article-wash-function nil
1603 "Function used for converting HTML into text.")
1604
1605(defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1606 (mm-coding-system-p 'utf-8)
1607 (executable-find idna-program))
1608 "Whether IDNA decoding of headers is used when viewing messages.
1609This requires GNU Libidn, and by default only enabled if it is found."
bf247b6e 1610 :version "22.1"
23f87bed
MB
1611 :group 'gnus-article-headers
1612 :type 'boolean)
1613
1614(defcustom gnus-article-over-scroll nil
1615 "If non-nil, allow scrolling the article buffer even when there no more text."
bf247b6e 1616 :version "22.1"
23f87bed
MB
1617 :group 'gnus-article
1618 :type 'boolean)
1619
eec82323
LMI
1620;;; Internal variables
1621
23f87bed
MB
1622(defvar gnus-english-month-names
1623 '("January" "February" "March" "April" "May" "June" "July" "August"
1624 "September" "October" "November" "December"))
1625
16409b0b
GM
1626(defvar article-goto-body-goes-to-point-min-p nil)
1627(defvar gnus-article-wash-types nil)
1628(defvar gnus-article-emphasis-alist nil)
23f87bed 1629(defvar gnus-article-image-alist nil)
16409b0b
GM
1630
1631(defvar gnus-article-mime-handle-alist-1 nil)
1632(defvar gnus-treatment-function-alist
23f87bed
MB
1633 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1634 (gnus-treat-strip-banner gnus-article-strip-banner)
16409b0b
GM
1635 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1636 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1637 (gnus-treat-buttonize gnus-article-add-buttons)
1638 (gnus-treat-fill-article gnus-article-fill-cited-article)
1639 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1640 (gnus-treat-strip-cr gnus-article-remove-cr)
23f87bed
MB
1641 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1642 (gnus-treat-date-ut gnus-article-date-ut)
1643 (gnus-treat-date-local gnus-article-date-local)
1644 (gnus-treat-date-english gnus-article-date-english)
23f87bed
MB
1645 (gnus-treat-date-original gnus-article-date-original)
1646 (gnus-treat-date-user-defined gnus-article-date-user)
1647 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
f3f01d5d 1648 (gnus-treat-date-lapsed gnus-article-date-lapsed)
23f87bed
MB
1649 (gnus-treat-display-x-face gnus-article-display-x-face)
1650 (gnus-treat-display-face gnus-article-display-face)
16409b0b
GM
1651 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1652 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1653 (gnus-treat-hide-signature gnus-article-hide-signature)
16409b0b 1654 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
23f87bed 1655 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
16409b0b 1656 (gnus-treat-strip-pem gnus-article-hide-pem)
23f87bed
MB
1657 (gnus-treat-from-picon gnus-treat-from-picon)
1658 (gnus-treat-mail-picon gnus-treat-mail-picon)
1659 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
16409b0b 1660 (gnus-treat-highlight-headers gnus-article-highlight-headers)
16409b0b 1661 (gnus-treat-highlight-signature gnus-article-highlight-signature)
16409b0b
GM
1662 (gnus-treat-strip-trailing-blank-lines
1663 gnus-article-remove-trailing-blank-lines)
1664 (gnus-treat-strip-leading-blank-lines
1665 gnus-article-strip-leading-blank-lines)
1666 (gnus-treat-strip-multiple-blank-lines
1667 gnus-article-strip-multiple-blank-lines)
1668 (gnus-treat-overstrike gnus-article-treat-overstrike)
01c52d31 1669 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
23f87bed 1670 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
23f87bed 1671 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
01c52d31 1672 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
16409b0b 1673 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
23f87bed 1674 (gnus-treat-display-smileys gnus-treat-smiley)
16409b0b 1675 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
23f87bed
MB
1676 (gnus-treat-wash-html gnus-article-wash-html)
1677 (gnus-treat-emphasize gnus-article-emphasize)
1678 (gnus-treat-hide-citation gnus-article-hide-citation)
1679 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1680 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1681 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
16409b0b
GM
1682 (gnus-treat-play-sounds gnus-earcon-display)))
1683
1684(defvar gnus-article-mime-handle-alist nil)
6748645f
LMI
1685(defvar article-lapsed-timer nil)
1686(defvar gnus-article-current-summary nil)
1687
eec82323
LMI
1688(defvar gnus-article-mode-syntax-table
1689 (let ((table (copy-syntax-table text-mode-syntax-table)))
23f87bed
MB
1690 ;; This causes the citation match run O(2^n).
1691 ;; (modify-syntax-entry ?- "w" table)
1692 (modify-syntax-entry ?> ")<" table)
1693 (modify-syntax-entry ?< "(>" table)
1694 ;; make M-. in article buffers work for `foo' strings
1695 (modify-syntax-entry ?' " " table)
1696 (modify-syntax-entry ?` " " table)
eec82323
LMI
1697 table)
1698 "Syntax table used in article mode buffers.
1699Initialized from `text-mode-syntax-table.")
1700
1701(defvar gnus-save-article-buffer nil)
1702
1703(defvar gnus-article-mode-line-format-alist
16409b0b
GM
1704 (nconc '((?w (gnus-article-wash-status) ?s)
1705 (?m (gnus-article-mime-part-status) ?s))
6748645f 1706 gnus-summary-mode-line-format-alist))
eec82323
LMI
1707
1708(defvar gnus-number-of-articles-to-be-saved nil)
1709
1710(defvar gnus-inhibit-hiding nil)
1711
c1d7d285
MB
1712(defvar gnus-article-edit-mode nil)
1713
23f87bed
MB
1714;;; Macros for dealing with the article buffer.
1715
1716(defmacro gnus-with-article-headers (&rest forms)
80de1778 1717 `(with-current-buffer gnus-article-buffer
23f87bed
MB
1718 (save-restriction
1719 (let ((inhibit-read-only t)
1720 (inhibit-point-motion-hooks t)
1721 (case-fold-search t))
1722 (article-narrow-to-head)
1723 ,@forms))))
1724
1725(put 'gnus-with-article-headers 'lisp-indent-function 0)
1726(put 'gnus-with-article-headers 'edebug-form-spec '(body))
1727
1728(defmacro gnus-with-article-buffer (&rest forms)
80de1778 1729 `(with-current-buffer gnus-article-buffer
23f87bed
MB
1730 (let ((inhibit-read-only t))
1731 ,@forms)))
1732
1733(put 'gnus-with-article-buffer 'lisp-indent-function 0)
1734(put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1735
1736(defun gnus-article-goto-header (header)
1737 "Go to HEADER, which is a regular expression."
1738 (re-search-forward (concat "^\\(" header "\\):") nil t))
1739
eec82323
LMI
1740(defsubst gnus-article-hide-text (b e props)
1741 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
520aa572 1742 (gnus-add-text-properties-when 'article-type nil b e props)
eec82323
LMI
1743 (when (memq 'intangible props)
1744 (put-text-property
1745 (max (1- b) (point-min))
1746 b 'intangible (cddr (memq 'intangible props)))))
520aa572 1747
eec82323
LMI
1748(defsubst gnus-article-unhide-text (b e)
1749 "Remove hidden text properties from region between B and E."
1750 (remove-text-properties b e gnus-hidden-properties)
1751 (when (memq 'intangible gnus-hidden-properties)
1752 (put-text-property (max (1- b) (point-min))
1753 b 'intangible nil)))
1754
1755(defun gnus-article-hide-text-type (b e type)
1756 "Hide text of TYPE between B and E."
23f87bed 1757 (gnus-add-wash-type type)
eec82323
LMI
1758 (gnus-article-hide-text
1759 b e (cons 'article-type (cons type gnus-hidden-properties))))
1760
1761(defun gnus-article-unhide-text-type (b e type)
6748645f 1762 "Unhide text of TYPE between B and E."
23f87bed 1763 (gnus-delete-wash-type type)
eec82323
LMI
1764 (remove-text-properties
1765 b e (cons 'article-type (cons type gnus-hidden-properties)))
1766 (when (memq 'intangible gnus-hidden-properties)
1767 (put-text-property (max (1- b) (point-min))
1768 b 'intangible nil)))
1769
1770(defun gnus-article-hide-text-of-type (type)
1771 "Hide text of TYPE in the current buffer."
1772 (save-excursion
1773 (let ((b (point-min))
1774 (e (point-max)))
1775 (while (setq b (text-property-any b e 'article-type type))
1776 (add-text-properties b (incf b) gnus-hidden-properties)))))
1777
1778(defun gnus-article-delete-text-of-type (type)
1779 "Delete text of TYPE in the current buffer."
1780 (save-excursion
a8151ef7 1781 (let ((b (point-min)))
7dafe00b
MB
1782 (if (eq type 'multipart)
1783 ;; Remove MIME buttons associated with multipart/alternative parts.
1784 (progn
1785 (goto-char b)
1786 (while (if (get-text-property (point) 'gnus-part)
1787 (setq b (point))
1788 (when (setq b (next-single-property-change (point)
1789 'gnus-part))
1790 (goto-char b)
1791 t))
1792 (end-of-line)
1793 (skip-chars-forward "\n")
1794 (when (eq (get-text-property b 'article-type) 'multipart)
1795 (delete-region b (point)))))
1796 (while (setq b (text-property-any b (point-max) 'article-type type))
1797 (delete-region
1798 b (or (text-property-not-all b (point-max) 'article-type type)
1799 (point-max))))))))
eec82323
LMI
1800
1801(defun gnus-article-delete-invisible-text ()
1802 "Delete all invisible text in the current buffer."
1803 (save-excursion
a8151ef7
LMI
1804 (let ((b (point-min)))
1805 (while (setq b (text-property-any b (point-max) 'invisible t))
1806 (delete-region
1807 b (or (text-property-not-all b (point-max) 'invisible t)
1808 (point-max)))))))
eec82323
LMI
1809
1810(defun gnus-article-text-type-exists-p (type)
1811 "Say whether any text of type TYPE exists in the buffer."
1812 (text-property-any (point-min) (point-max) 'article-type type))
1813
1814(defsubst gnus-article-header-rank ()
1815 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1816 (let ((list gnus-sorted-header-list)
23f87bed 1817 (i 1))
eec82323 1818 (while list
23f87bed
MB
1819 (if (looking-at (car list))
1820 (setq list nil)
1821 (setq list (cdr list))
1822 (incf i)))
1823 i))
eec82323
LMI
1824
1825(defun article-hide-headers (&optional arg delete)
16409b0b
GM
1826 "Hide unwanted headers and possibly sort them as well."
1827 (interactive)
1828 ;; This function might be inhibited.
1829 (unless gnus-inhibit-hiding
37cc095b 1830 (let ((inhibit-read-only t)
23f87bed
MB
1831 (case-fold-search t)
1832 (max (1+ (length gnus-sorted-header-list)))
1833 (inhibit-point-motion-hooks t)
1834 (cur (current-buffer))
1835 ignored visible beg)
1836 (save-excursion
1837 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1838 ;; group parameters, so we should go to the summary buffer.
1839 (when (prog1
1840 (condition-case nil
1841 (progn (set-buffer gnus-summary-buffer) t)
1842 (error nil))
1843 (setq ignored (when (not gnus-visible-headers)
1844 (cond ((stringp gnus-ignored-headers)
1845 gnus-ignored-headers)
1846 ((listp gnus-ignored-headers)
1847 (mapconcat 'identity
1848 gnus-ignored-headers
1849 "\\|"))))
1850 visible (cond ((stringp gnus-visible-headers)
1851 gnus-visible-headers)
1852 ((and gnus-visible-headers
1853 (listp gnus-visible-headers))
1854 (mapconcat 'identity
1855 gnus-visible-headers
1856 "\\|")))))
1857 (set-buffer cur))
1858 (save-restriction
16409b0b
GM
1859 ;; First we narrow to just the headers.
1860 (article-narrow-to-head)
1861 ;; Hide any "From " lines at the beginning of (mail) articles.
1862 (while (looking-at "From ")
1863 (forward-line 1))
1864 (unless (bobp)
1865 (delete-region (point-min) (point)))
1866 ;; Then treat the rest of the header lines.
1867 ;; Then we use the two regular expressions
1868 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1869 ;; select which header lines is to remain visible in the
1870 ;; article buffer.
23f87bed 1871 (while (re-search-forward "^[^ \t:]*:" nil t)
16409b0b
GM
1872 (beginning-of-line)
1873 ;; Mark the rank of the header.
1874 (put-text-property
1875 (point) (1+ (point)) 'message-rank
1876 (if (or (and visible (looking-at visible))
1877 (and ignored
1878 (not (looking-at ignored))))
1879 (gnus-article-header-rank)
1880 (+ 2 max)))
1881 (forward-line 1))
1882 (message-sort-headers-1)
1883 (when (setq beg (text-property-any
1884 (point-min) (point-max) 'message-rank (+ 2 max)))
1885 ;; We delete the unwanted headers.
23f87bed 1886 (gnus-add-wash-type 'headers)
16409b0b
GM
1887 (add-text-properties (point-min) (+ 5 (point-min))
1888 '(article-type headers dummy-invisible t))
1889 (delete-region beg (point-max))))))))
eec82323
LMI
1890
1891(defun article-hide-boring-headers (&optional arg)
1892 "Toggle hiding of headers that aren't very interesting.
1893If given a negative prefix, always show; if given a positive prefix,
1894always hide."
1895 (interactive (gnus-article-hidden-arg))
1896 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1897 (not gnus-show-all-headers))
1898 (save-excursion
1899 (save-restriction
4e7d0221 1900 (let ((inhibit-read-only t)
01c52d31 1901 (inhibit-point-motion-hooks t))
16409b0b 1902 (article-narrow-to-head)
01c52d31 1903 (dolist (elem gnus-boring-article-headers)
eec82323
LMI
1904 (goto-char (point-min))
1905 (cond
1906 ;; Hide empty headers.
1907 ((eq elem 'empty)
16409b0b 1908 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
eec82323
LMI
1909 (forward-line -1)
1910 (gnus-article-hide-text-type
01c52d31 1911 (point-at-bol)
eec82323
LMI
1912 (progn
1913 (end-of-line)
1914 (if (re-search-forward "^[^ \t]" nil t)
1915 (match-beginning 0)
1916 (point-max)))
1917 'boring-headers)))
1918 ;; Hide boring Newsgroups header.
1919 ((eq elem 'newsgroups)
23f87bed
MB
1920 (when (gnus-string-equal
1921 (gnus-fetch-field "newsgroups")
1922 (gnus-group-real-name
1923 (if (boundp 'gnus-newsgroup-name)
1924 gnus-newsgroup-name
1925 "")))
eec82323 1926 (gnus-article-hide-header "newsgroups")))
23f87bed
MB
1927 ((eq elem 'to-address)
1928 (let ((to (message-fetch-field "to"))
1929 (to-address
1930 (gnus-parameter-to-address
1931 (if (boundp 'gnus-newsgroup-name)
1932 gnus-newsgroup-name ""))))
1933 (when (and to to-address
1934 (ignore-errors
1935 (gnus-string-equal
1936 ;; only one address in To
1937 (nth 1 (mail-extract-address-components to))
1938 to-address)))
1939 (gnus-article-hide-header "to"))))
1940 ((eq elem 'to-list)
1941 (let ((to (message-fetch-field "to"))
1942 (to-list
1943 (gnus-parameter-to-list
1944 (if (boundp 'gnus-newsgroup-name)
1945 gnus-newsgroup-name ""))))
1946 (when (and to to-list
1947 (ignore-errors
1948 (gnus-string-equal
1949 ;; only one address in To
1950 (nth 1 (mail-extract-address-components to))
1951 to-list)))
1952 (gnus-article-hide-header "to"))))
1953 ((eq elem 'cc-list)
1954 (let ((cc (message-fetch-field "cc"))
1955 (to-list
1956 (gnus-parameter-to-list
1957 (if (boundp 'gnus-newsgroup-name)
1958 gnus-newsgroup-name ""))))
1959 (when (and cc to-list
1960 (ignore-errors
1961 (gnus-string-equal
1962 ;; only one address in CC
1963 (nth 1 (mail-extract-address-components cc))
1964 to-list)))
1965 (gnus-article-hide-header "cc"))))
eec82323 1966 ((eq elem 'followup-to)
23f87bed
MB
1967 (when (gnus-string-equal
1968 (message-fetch-field "followup-to")
1969 (message-fetch-field "newsgroups"))
eec82323
LMI
1970 (gnus-article-hide-header "followup-to")))
1971 ((eq elem 'reply-to)
23f87bed
MB
1972 (if (gnus-group-find-parameter
1973 gnus-newsgroup-name 'broken-reply-to)
1974 (gnus-article-hide-header "reply-to")
1975 (let ((from (message-fetch-field "from"))
1976 (reply-to (message-fetch-field "reply-to")))
1977 (when
1978 (and
eec82323
LMI
1979 from reply-to
1980 (ignore-errors
1981 (equal
23f87bed
MB
1982 (sort (mapcar
1983 (lambda (x) (downcase (cadr x)))
1984 (mail-extract-address-components from t))
1985 'string<)
1986 (sort (mapcar
1987 (lambda (x) (downcase (cadr x)))
1988 (mail-extract-address-components reply-to t))
1989 'string<))))
1990 (gnus-article-hide-header "reply-to")))))
eec82323 1991 ((eq elem 'date)
b193caa3
MB
1992 (let ((date (with-current-buffer gnus-original-article-buffer
1993 ;; If date in `gnus-article-buffer' is localized
1994 ;; (`gnus-treat-date-user-defined'),
1995 ;; `days-between' might fail.
1996 (message-fetch-field "date"))))
eec82323 1997 (when (and date
16409b0b 1998 (< (days-between (current-time-string) date)
eec82323 1999 4))
6748645f
LMI
2000 (gnus-article-hide-header "date"))))
2001 ((eq elem 'long-to)
16409b0b
GM
2002 (let ((to (message-fetch-field "to"))
2003 (cc (message-fetch-field "cc")))
6748645f 2004 (when (> (length to) 1024)
16409b0b
GM
2005 (gnus-article-hide-header "to"))
2006 (when (> (length cc) 1024)
2007 (gnus-article-hide-header "cc"))))
6748645f 2008 ((eq elem 'many-to)
16409b0b
GM
2009 (let ((to-count 0)
2010 (cc-count 0))
6748645f
LMI
2011 (goto-char (point-min))
2012 (while (re-search-forward "^to:" nil t)
2013 (setq to-count (1+ to-count)))
2014 (when (> to-count 1)
2015 (while (> to-count 0)
2016 (goto-char (point-min))
2017 (save-restriction
2018 (re-search-forward "^to:" nil nil to-count)
2019 (forward-line -1)
2020 (narrow-to-region (point) (point-max))
2021 (gnus-article-hide-header "to"))
16409b0b
GM
2022 (setq to-count (1- to-count))))
2023 (goto-char (point-min))
2024 (while (re-search-forward "^cc:" nil t)
2025 (setq cc-count (1+ cc-count)))
2026 (when (> cc-count 1)
2027 (while (> cc-count 0)
2028 (goto-char (point-min))
2029 (save-restriction
2030 (re-search-forward "^cc:" nil nil cc-count)
2031 (forward-line -1)
2032 (narrow-to-region (point) (point-max))
2033 (gnus-article-hide-header "cc"))
2034 (setq cc-count (1- cc-count)))))))))))))
eec82323
LMI
2035
2036(defun gnus-article-hide-header (header)
2037 (save-excursion
2038 (goto-char (point-min))
2039 (when (re-search-forward (concat "^" header ":") nil t)
2040 (gnus-article-hide-text-type
01c52d31 2041 (point-at-bol)
eec82323
LMI
2042 (progn
2043 (end-of-line)
2044 (if (re-search-forward "^[^ \t]" nil t)
2045 (match-beginning 0)
2046 (point-max)))
2047 'boring-headers))))
2048
16409b0b
GM
2049(defvar gnus-article-normalized-header-length 40
2050 "Length of normalized headers.")
2051
2052(defun article-normalize-headers ()
2053 "Make all header lines 40 characters long."
2054 (interactive)
4e7d0221 2055 (let ((inhibit-read-only t)
16409b0b
GM
2056 column)
2057 (save-excursion
2058 (save-restriction
2059 (article-narrow-to-head)
2060 (while (not (eobp))
2061 (cond
01c52d31 2062 ((< (setq column (- (point-at-eol) (point)))
16409b0b
GM
2063 gnus-article-normalized-header-length)
2064 (end-of-line)
2065 (insert (make-string
2066 (- gnus-article-normalized-header-length column)
2067 ? )))
2068 ((> column gnus-article-normalized-header-length)
2069 (gnus-put-text-property
2070 (progn
2071 (forward-char gnus-article-normalized-header-length)
2072 (point))
01c52d31 2073 (point-at-eol)
16409b0b
GM
2074 'invisible t))
2075 (t
2076 ;; Do nothing.
2077 ))
2078 (forward-line 1))))))
2079
6748645f 2080(defun article-treat-dumbquotes ()
23f87bed 2081 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
16409b0b 2082Note that this function guesses whether a character is a sm*rtq**t* or
74dd1b0d
SZ
2083not, so it should only be used interactively.
2084
23f87bed
MB
2085Sm*rtq**t*s are M****s***'s unilateral extension to the
2086iso-8859-1 character map in an attempt to provide more quoting
2087characters. If you see something like \\222 or \\264 where
2088you're expecting some kind of apostrophe or quotation mark, then
2089try this wash."
6748645f 2090 (interactive)
16409b0b 2091 (article-translate-strings gnus-article-dumbquotes-map))
6748645f
LMI
2092
2093(defun article-translate-characters (from to)
2094 "Translate all characters in the body of the article according to FROM and TO.
2095FROM is a string of characters to translate from; to is a string of
2096characters to translate to."
2097 (save-excursion
16409b0b 2098 (when (article-goto-body)
4e7d0221 2099 (let ((inhibit-read-only t)
6748645f
LMI
2100 (x (make-string 225 ?x))
2101 (i -1))
2102 (while (< (incf i) (length x))
2103 (aset x i i))
2104 (setq i 0)
2105 (while (< i (length from))
2106 (aset x (aref from i) (aref to i))
2107 (incf i))
2108 (translate-region (point) (point-max) x)))))
2109
16409b0b
GM
2110(defun article-translate-strings (map)
2111 "Translate all string in the body of the article according to MAP.
2112MAP is an alist where the elements are on the form (\"from\" \"to\")."
2113 (save-excursion
2114 (when (article-goto-body)
01c52d31
MB
2115 (let ((inhibit-read-only t))
2116 (dolist (elem map)
16409b0b
GM
2117 (save-excursion
2118 (while (search-forward (car elem) nil t)
2119 (replace-match (cadr elem)))))))))
2120
eec82323
LMI
2121(defun article-treat-overstrike ()
2122 "Translate overstrikes into bold text."
2123 (interactive)
2124 (save-excursion
16409b0b 2125 (when (article-goto-body)
4e7d0221 2126 (let ((inhibit-read-only t))
eec82323 2127 (while (search-forward "\b" nil t)
16409b0b 2128 (let ((next (char-after))
eec82323
LMI
2129 (previous (char-after (- (point) 2))))
2130 ;; We do the boldification/underlining by hiding the
2131 ;; overstrikes and putting the proper text property
2132 ;; on the letters.
2133 (cond
2134 ((eq next previous)
2135 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2136 (put-text-property (point) (1+ (point)) 'face 'bold))
2137 ((eq next ?_)
2138 (gnus-article-hide-text-type
2139 (1- (point)) (1+ (point)) 'overstrike)
2140 (put-text-property
2141 (- (point) 2) (1- (point)) 'face 'underline))
2142 ((eq previous ?_)
2143 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2144 (put-text-property
2145 (point) (1+ (point)) 'face 'underline)))))))))
2146
01c52d31
MB
2147(defun article-treat-ansi-sequences ()
2148 "Translate ANSI SGR control sequences into overlays or extents."
2149 (interactive)
2150 (save-excursion
2151 (when (article-goto-body)
2152 (let ((inhibit-read-only t))
2153 (ansi-color-apply-on-region (point) (point-max))))))
2154
23f87bed
MB
2155(defun gnus-article-treat-unfold-headers ()
2156 "Unfold folded message headers.
2157Only the headers that fit into the current window width will be
2158unfolded."
2159 (interactive)
2160 (gnus-with-article-headers
2161 (let (length)
2162 (while (not (eobp))
2163 (save-restriction
2164 (mail-header-narrow-to-field)
01c52d31
MB
2165 (let* ((header (buffer-string))
2166 (unfoldable
2167 (or (equal gnus-article-unfold-long-headers t)
2168 (and (stringp gnus-article-unfold-long-headers)
2169 (string-match gnus-article-unfold-long-headers header)))))
23f87bed
MB
2170 (with-temp-buffer
2171 (insert header)
2172 (goto-char (point-min))
2173 (while (re-search-forward "\n[\t ]" nil t)
2174 (replace-match " " t t)))
01c52d31
MB
2175 (setq length (- (point-max) (point-min) 1))
2176 (when (or unfoldable
2177 (< length (window-width)))
2178 (while (re-search-forward "\n[\t ]" nil t)
2179 (replace-match " " t t))))
23f87bed
MB
2180 (goto-char (point-max)))))))
2181
2182(defun gnus-article-treat-fold-headers ()
2183 "Fold message headers."
2184 (interactive)
2185 (gnus-with-article-headers
2186 (while (not (eobp))
2187 (save-restriction
2188 (mail-header-narrow-to-field)
2189 (mail-header-fold-field)
2190 (goto-char (point-max))))))
2191
2192(defun gnus-treat-smiley ()
2193 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2194 (interactive)
2195 (gnus-with-article-buffer
2196 (if (memq 'smiley gnus-article-wash-types)
2197 (gnus-delete-images 'smiley)
2198 (article-goto-body)
2199 (let ((images (smiley-region (point) (point-max))))
2200 (when images
2201 (gnus-add-wash-type 'smiley)
2202 (dolist (image images)
2203 (gnus-add-image 'smiley image)))))))
2204
2205(defun gnus-article-remove-images ()
2206 "Remove all images from the article buffer."
2207 (interactive)
2208 (gnus-with-article-buffer
2209 (dolist (elem gnus-article-image-alist)
2210 (gnus-delete-images (car elem)))))
2211
2212(defun gnus-article-treat-fold-newsgroups ()
2213 "Unfold folded message headers.
2214Only the headers that fit into the current window width will be
2215unfolded."
2216 (interactive)
2217 (gnus-with-article-headers
2218 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2219 (save-restriction
2220 (mail-header-narrow-to-field)
2221 (while (re-search-forward ", *" nil t)
2222 (replace-match ", " t t))
2223 (mail-header-fold-field)
2224 (goto-char (point-max))))))
2225
b7b80032 2226(defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
01c52d31
MB
2227 "Value of `truncate-lines' in Gnus Article buffer.
2228Valid values are nil, t, `head', `first', `last', an integer or a
2229predicate. See Info node `(gnus)Customizing Articles'."
330f707b 2230 :version "23.1" ;; No Gnus
01c52d31
MB
2231 :group 'gnus-article
2232 ;; :link '(custom-manual "(gnus)Customizing Articles")
2233 :type 'boolean)
2234
2235(defun gnus-article-toggle-truncate-lines (&optional arg)
2236 "Toggle whether to fold or truncate long lines in article the buffer.
2237If ARG is non-nil and not a number, toggle
2238`gnus-article-truncate-lines' too. If ARG is a number, truncate
2239long lines iff arg is positive."
2240 (interactive "P")
2241 (cond
2242 ((and (numberp arg) (> arg 0))
2243 (setq gnus-article-truncate-lines t))
2244 ((numberp arg)
2245 (setq gnus-article-truncate-lines nil))
2246 (arg
2247 (setq gnus-article-truncate-lines
2248 (not gnus-article-truncate-lines))))
2249 (gnus-with-article-buffer
2250 (cond
2251 ((and (numberp arg) (> arg 0))
2252 (setq truncate-lines nil))
2253 ((numberp arg)
2254 (setq truncate-lines t)))
2255 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2256 ;; `toggle-truncate-lines' needs an argument.
2257 (toggle-truncate-lines)))
2258
23f87bed
MB
2259(defun gnus-article-treat-body-boundary ()
2260 "Place a boundary line at the end of the headers."
2261 (interactive)
2262 (when (and gnus-body-boundary-delimiter
2263 (> (length gnus-body-boundary-delimiter) 0))
2264 (gnus-with-article-headers
2265 (goto-char (point-max))
2266 (let ((start (point)))
2267 (insert "X-Boundary: ")
2268 (gnus-add-text-properties start (point) '(invisible t intangible t))
2269 (insert (let (str)
2270 (while (>= (1- (window-width)) (length str))
2271 (setq str (concat str gnus-body-boundary-delimiter)))
2272 (substring str 0 (1- (window-width))))
2273 "\n")
2274 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2275
16409b0b
GM
2276(defun article-fill-long-lines ()
2277 "Fill lines that are wider than the window width."
eec82323
LMI
2278 (interactive)
2279 (save-excursion
4e7d0221 2280 (let ((inhibit-read-only t)
16409b0b
GM
2281 (width (window-width (get-buffer-window (current-buffer)))))
2282 (save-restriction
2283 (article-goto-body)
80b47379 2284 (let ((adaptive-fill-mode nil)) ;Why? -sm
16409b0b
GM
2285 (while (not (eobp))
2286 (end-of-line)
2287 (when (>= (current-column) (min fill-column width))
23f87bed 2288 (narrow-to-region (min (1+ (point)) (point-max))
01c52d31 2289 (point-at-bol))
23f87bed
MB
2290 (let ((goback (point-marker)))
2291 (fill-paragraph nil)
2292 (goto-char (marker-position goback)))
16409b0b
GM
2293 (widen))
2294 (forward-line 1)))))))
2295
2296(defun article-capitalize-sentences ()
2297 "Capitalize the first word in each sentence."
2298 (interactive)
2299 (save-excursion
4e7d0221 2300 (let ((inhibit-read-only t)
16409b0b
GM
2301 (paragraph-start "^[\n\^L]"))
2302 (article-goto-body)
2303 (while (not (eobp))
2304 (capitalize-word 1)
2305 (forward-sentence)))))
eec82323
LMI
2306
2307(defun article-remove-cr ()
16409b0b 2308 "Remove trailing CRs and then translate remaining CRs into LFs."
eec82323
LMI
2309 (interactive)
2310 (save-excursion
4e7d0221 2311 (let ((inhibit-read-only t))
eec82323 2312 (goto-char (point-min))
16409b0b
GM
2313 (while (re-search-forward "\r+$" nil t)
2314 (replace-match "" t t))
2315 (goto-char (point-min))
eec82323 2316 (while (search-forward "\r" nil t)
16409b0b 2317 (replace-match "\n" t t)))))
eec82323
LMI
2318
2319(defun article-remove-trailing-blank-lines ()
2320 "Remove all trailing blank lines from the article."
2321 (interactive)
2322 (save-excursion
4e7d0221 2323 (let ((inhibit-read-only t))
eec82323
LMI
2324 (goto-char (point-max))
2325 (delete-region
2326 (point)
2327 (progn
2328 (while (and (not (bobp))
16409b0b
GM
2329 (looking-at "^[ \t]*$")
2330 (not (gnus-annotation-in-region-p
01c52d31 2331 (point) (point-at-eol))))
eec82323
LMI
2332 (forward-line -1))
2333 (forward-line 1)
2334 (point))))))
2335
9efa445f 2336(defvar gnus-face-properties-alist)
01c52d31 2337
b890d447 2338(defun article-display-face (&optional force)
23f87bed 2339 "Display any Face headers in the header."
b890d447 2340 (interactive (list 'force))
23f87bed
MB
2341 (let ((wash-face-p buffer-read-only))
2342 (gnus-with-article-headers
2343 ;; When displaying parts, this function can be called several times on
2344 ;; the same article, without any intended toggle semantic (as typing `W
2345 ;; D d' would have). So face deletion must occur only when we come from
2346 ;; an interactive command, that is when the *Article* buffer is
2347 ;; read-only.
2348 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2349 (gnus-delete-images 'face)
b890d447
MB
2350 (let ((from (message-fetch-field "from"))
2351 face faces)
7d0c69be 2352 (save-current-buffer
23f87bed 2353 (when (and wash-face-p
7d0c69be
MB
2354 (gnus-buffer-live-p gnus-original-article-buffer)
2355 (not (re-search-forward "^Face:[\t ]*" nil t)))
23f87bed
MB
2356 (set-buffer gnus-original-article-buffer))
2357 (save-restriction
2358 (mail-narrow-to-head)
b890d447
MB
2359 (when (or force
2360 ;; Check whether this face is censored.
2361 (not (and gnus-article-x-face-too-ugly
2362 (or from
2363 (setq from (message-fetch-field "from")))
2364 (string-match gnus-article-x-face-too-ugly
2365 from))))
2366 (while (gnus-article-goto-header "Face")
2367 (push (mail-header-field-value) faces)))))
d6697c02 2368 (when faces
7d0c69be 2369 (goto-char (point-min))
b890d447
MB
2370 (let (png image)
2371 (unless (setq from (gnus-article-goto-header "from"))
7d0c69be
MB
2372 (insert "From:")
2373 (setq from (point))
b890d447 2374 (insert " [no `from' set]\n"))
7d0c69be
MB
2375 (while faces
2376 (when (setq png (gnus-convert-face-to-png (pop faces)))
01c52d31
MB
2377 (setq image
2378 (apply 'gnus-create-image png 'png t
2379 (cdr (assq 'png gnus-face-properties-alist))))
d6697c02
MB
2380 (goto-char from)
2381 (gnus-add-wash-type 'face)
2382 (gnus-add-image 'face image)
2383 (gnus-put-image image nil 'face))))))))))
23f87bed 2384
eec82323
LMI
2385(defun article-display-x-face (&optional force)
2386 "Look for an X-Face header and display it if present."
2387 (interactive (list 'force))
23f87bed
MB
2388 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2389 (gnus-with-article-headers
2390 ;; Delete the old process, if any.
2391 (when (process-status "article-x-face")
2392 (delete-process "article-x-face"))
2393 ;; See the comment in `article-display-face'.
2394 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2395 ;; We have already displayed X-Faces, so we remove them
2396 ;; instead.
2397 (gnus-delete-images 'xface)
2398 ;; Display X-Faces.
b890d447
MB
2399 (let ((from (message-fetch-field "from"))
2400 x-faces face)
7d0c69be 2401 (save-current-buffer
23f87bed 2402 (when (and wash-face-p
7d0c69be
MB
2403 (gnus-buffer-live-p gnus-original-article-buffer)
2404 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
23f87bed
MB
2405 ;; If type `W f', use gnus-original-article-buffer,
2406 ;; otherwise use the current buffer because displaying
2407 ;; RFC822 parts calls this function too.
2408 (set-buffer gnus-original-article-buffer))
2409 (save-restriction
2410 (mail-narrow-to-head)
b890d447
MB
2411 (and gnus-article-x-face-command
2412 (or force
2413 ;; Check whether this face is censored.
2414 (not (and gnus-article-x-face-too-ugly
2415 (or from
2416 (setq from (message-fetch-field "from")))
2417 (string-match gnus-article-x-face-too-ugly
2418 from))))
2419 (while (gnus-article-goto-header "X-Face")
2420 (push (mail-header-field-value) x-faces)))))
2421 (when x-faces
2422 ;; We display the face.
2423 (cond ((functionp gnus-article-x-face-command)
2424 ;; The command is a lisp function, so we call it.
2425 (mapc gnus-article-x-face-command x-faces))
2426 ((stringp gnus-article-x-face-command)
2427 ;; The command is a string, so we interpret the command
2428 ;; as a, well, command, and fork it off.
2429 (let ((process-connection-type nil))
2430 (gnus-set-process-query-on-exit-flag
2431 (start-process
2432 "article-x-face" nil shell-file-name
2433 shell-command-switch gnus-article-x-face-command)
2434 nil)
2435 ;; Sending multiple EOFs to xv doesn't work,
2436 ;; so we only do a single external face.
2437 (with-temp-buffer
2438 (insert (car x-faces))
2439 (process-send-region "article-x-face"
2440 (point-min) (point-max)))
2441 (process-send-eof "article-x-face")))
2442 (t
2443 (error "`%s' set to `%s' is not a function"
2444 gnus-article-x-face-command
2445 'gnus-article-x-face-command)))))))))
a8151ef7 2446
16409b0b
GM
2447(defun article-decode-mime-words ()
2448 "Decode all MIME-encoded words in the article."
2449 (interactive)
01c52d31 2450 (gnus-with-article-buffer
16409b0b 2451 (let ((inhibit-point-motion-hooks t)
16409b0b 2452 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2453 (mail-parse-ignored-charsets
01c52d31
MB
2454 (with-current-buffer gnus-summary-buffer
2455 gnus-newsgroup-ignored-charsets)))
16409b0b
GM
2456 (mail-decode-encoded-word-region (point-min) (point-max)))))
2457
2458(defun article-decode-charset (&optional prompt)
2459 "Decode charset-encoded text in the article.
2460If PROMPT (the prefix), prompt for a coding system to use."
2461 (interactive "P")
2462 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
23f87bed 2463 (inhibit-read-only t)
16409b0b 2464 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2465 (mail-parse-ignored-charsets
16409b0b
GM
2466 (save-excursion (condition-case nil
2467 (set-buffer gnus-summary-buffer)
2468 (error))
2469 gnus-newsgroup-ignored-charsets))
2470 ct cte ctl charset format)
c96ec15a
MB
2471 (save-excursion
2472 (save-restriction
2473 (article-narrow-to-head)
2474 (setq ct (message-fetch-field "Content-Type" t)
2475 cte (message-fetch-field "Content-Transfer-Encoding" t)
2476 ctl (and ct (mail-header-parse-content-type ct))
2477 charset (cond
2478 (prompt
2479 (mm-read-coding-system "Charset to decode: "))
2480 (ctl
2481 (mail-content-type-get ctl 'charset)))
2482 format (and ctl (mail-content-type-get ctl 'format)))
2483 (when cte
2484 (setq cte (mail-header-strip cte)))
2485 (if (and ctl (not (string-match "/" (car ctl))))
2486 (setq ctl nil))
2487 (goto-char (point-max)))
2488 (forward-line 1)
2489 (save-restriction
2490 (narrow-to-region (point) (point-max))
2491 (when (and (eq mail-parse-charset 'gnus-decoded)
2492 (eq (mm-body-7-or-8) '8bit))
2493 ;; The text code could have been decoded.
2494 (setq charset mail-parse-charset))
2495 (when (and (or (not ctl)
2496 (equal (car ctl) "text/plain"))
2497 (not format)) ;; article with format will decode later.
2498 (mm-decode-body
2499 charset (and cte (intern (downcase
2500 (gnus-strip-whitespace cte))))
2501 (car ctl)))))))
16409b0b
GM
2502
2503(defun article-decode-encoded-words ()
2504 "Remove encoded-word encoding from headers."
2505 (let ((inhibit-point-motion-hooks t)
2506 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2507 (mail-parse-ignored-charsets
16409b0b
GM
2508 (save-excursion (condition-case nil
2509 (set-buffer gnus-summary-buffer)
2510 (error))
2511 gnus-newsgroup-ignored-charsets))
343d6628 2512 (inhibit-read-only t)
8fbdffe5
MB
2513 end start)
2514 (goto-char (point-min))
2515 (when (search-forward "\n\n" nil 'move)
2516 (forward-line -1))
2517 (setq end (point))
2518 (while (not (bobp))
2519 (while (progn
2520 (forward-line -1)
2521 (and (not (bobp))
2522 (memq (char-after) '(?\t ? )))))
2523 (setq start (point))
2524 (if (looking-at "\
343d6628
MB
2525\\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2526\\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
8fbdffe5
MB
2527 (funcall gnus-decode-address-function start end)
2528 (funcall gnus-decode-header-function start end))
2529 (goto-char (setq end start)))))
eec82323 2530
23f87bed 2531(defun article-decode-group-name ()
01c52d31 2532 "Decode group names in Newsgroups, Followup-To and Xref headers."
23f87bed
MB
2533 (let ((inhibit-point-motion-hooks t)
2534 (inhibit-read-only t)
01c52d31
MB
2535 (method (gnus-find-method-for-group gnus-newsgroup-name))
2536 regexp)
23f87bed
MB
2537 (when (and (or gnus-group-name-charset-method-alist
2538 gnus-group-name-charset-group-alist)
2539 (gnus-buffer-live-p gnus-original-article-buffer))
2540 (save-restriction
2541 (article-narrow-to-head)
01c52d31
MB
2542 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2543 (with-current-buffer gnus-original-article-buffer
2544 (goto-char (point-min)))
2545 (setq regexp (concat "^" header
2546 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2547 (while (re-search-forward regexp nil t)
2548 (replace-match (save-match-data
2549 (gnus-decode-newsgroups
2550 ;; XXX how to use data in article buffer?
2551 (with-current-buffer gnus-original-article-buffer
2552 (re-search-forward regexp nil t)
2553 (match-string 1))
2554 gnus-newsgroup-name method))
2555 t t nil 1))
2556 (goto-char (point-min)))))))
23f87bed
MB
2557
2558(autoload 'idna-to-unicode "idna")
2559
2560(defun article-decode-idna-rhs ()
53cfefc8
MB
2561 "Decode IDNA strings in RHS in various headers in current buffer.
2562The following headers are decoded: From:, To:, Cc:, Reply-To:,
2563Mail-Reply-To: and Mail-Followup-To:."
23f87bed
MB
2564 (when gnus-use-idna
2565 (save-restriction
2566 (let ((inhibit-point-motion-hooks t)
2567 (inhibit-read-only t))
2568 (article-narrow-to-head)
2569 (goto-char (point-min))
53cfefc8 2570 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
23f87bed
MB
2571 (let (ace unicode)
2572 (when (save-match-data
2573 (and (setq ace (match-string 1))
2574 (save-excursion
2575 (and (re-search-backward "^[^ \t]" nil t)
53cfefc8 2576 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
23f87bed
MB
2577 (setq unicode (idna-to-unicode ace))))
2578 (unless (string= ace unicode)
2579 (replace-match unicode nil nil nil 1)))))))))
2580
2581(defun article-de-quoted-unreadable (&optional force read-charset)
16409b0b 2582 "Translate a quoted-printable-encoded article.
eec82323 2583If FORCE, decode the article whether it is marked as quoted-printable
23f87bed
MB
2584or not.
2585If READ-CHARSET, ask for a coding system."
2586 (interactive (list 'force current-prefix-arg))
eec82323 2587 (save-excursion
4e7d0221 2588 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2589 (if (gnus-buffer-live-p gnus-original-article-buffer)
2590 (with-current-buffer gnus-original-article-buffer
2591 (setq type
2592 (gnus-fetch-field "content-transfer-encoding"))
2593 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2594 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2595 (setq charset (and ctl
2596 (mail-content-type-get ctl 'charset)))
2597 (if (stringp charset)
2598 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2599 (if read-charset
2600 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2601 (unless charset
8b93df01 2602 (setq charset gnus-newsgroup-charset))
eec82323 2603 (when (or force
eb806ef3
DL
2604 (and type (let ((case-fold-search t))
2605 (string-match "quoted-printable" type))))
16409b0b 2606 (article-goto-body)
eb806ef3
DL
2607 (quoted-printable-decode-region
2608 (point) (point-max) (mm-charset-to-coding-system charset))))))
16409b0b 2609
23f87bed 2610(defun article-de-base64-unreadable (&optional force read-charset)
16409b0b 2611 "Translate a base64 article.
23f87bed
MB
2612If FORCE, decode the article whether it is marked as base64 not.
2613If READ-CHARSET, ask for a coding system."
2614 (interactive (list 'force current-prefix-arg))
16409b0b 2615 (save-excursion
4e7d0221 2616 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2617 (if (gnus-buffer-live-p gnus-original-article-buffer)
2618 (with-current-buffer gnus-original-article-buffer
2619 (setq type
2620 (gnus-fetch-field "content-transfer-encoding"))
2621 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2622 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2623 (setq charset (and ctl
2624 (mail-content-type-get ctl 'charset)))
2625 (if (stringp charset)
2626 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2627 (if read-charset
2628 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2629 (unless charset
8b93df01 2630 (setq charset gnus-newsgroup-charset))
16409b0b 2631 (when (or force
eb806ef3
DL
2632 (and type (let ((case-fold-search t))
2633 (string-match "base64" type))))
16409b0b
GM
2634 (article-goto-body)
2635 (save-restriction
2636 (narrow-to-region (point) (point-max))
2637 (base64-decode-region (point-min) (point-max))
eb806ef3
DL
2638 (mm-decode-coding-region
2639 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
16409b0b
GM
2640
2641(eval-when-compile
2642 (require 'rfc1843))
2643
2644(defun article-decode-HZ ()
2645 "Translate a HZ-encoded article."
2646 (interactive)
2647 (require 'rfc1843)
2648 (save-excursion
4e7d0221 2649 (let ((inhibit-read-only t))
16409b0b
GM
2650 (rfc1843-decode-region (point-min) (point-max)))))
2651
23f87bed
MB
2652(defun article-unsplit-urls ()
2653 "Remove the newlines that some other mailers insert into URLs."
16409b0b 2654 (interactive)
23f87bed
MB
2655 (save-excursion
2656 (let ((inhibit-read-only t))
2657 (goto-char (point-min))
2658 (while (re-search-forward
97f78c9b 2659 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
23f87bed
MB
2660 (replace-match "\\1\\3" t)))
2661 (when (interactive-p)
2662 (gnus-treat-article nil))))
2663
2664
2665(defun article-wash-html (&optional read-charset)
2666 "Format an HTML article.
73043f7d
MB
2667If READ-CHARSET, ask for a coding system. If it is a number, the
2668charset defined in `gnus-summary-show-article-charset-alist' is used."
23f87bed 2669 (interactive "P")
16409b0b 2670 (save-excursion
4e7d0221 2671 (let ((inhibit-read-only t)
8b93df01 2672 charset)
73043f7d
MB
2673 (if read-charset
2674 (if (or (and (numberp read-charset)
2675 (setq charset
2676 (cdr
2677 (assq read-charset
2678 gnus-summary-show-article-charset-alist))))
2679 (setq charset (mm-read-coding-system "Charset: ")))
2680 (let ((gnus-summary-show-article-charset-alist
2681 (list (cons 1 charset))))
2682 (with-current-buffer gnus-summary-buffer
2683 (gnus-summary-show-article 1)))
2684 (error "No charset is given"))
2685 (when (gnus-buffer-live-p gnus-original-article-buffer)
2686 (with-current-buffer gnus-original-article-buffer
2687 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2688 (ctl (and ct (mail-header-parse-content-type ct))))
73043f7d
MB
2689 (setq charset (and ctl
2690 (mail-content-type-get ctl 'charset)))
2691 (when (stringp charset)
2692 (setq charset (intern (downcase charset)))))))
2693 (unless charset
2694 (setq charset gnus-newsgroup-charset)))
16409b0b
GM
2695 (article-goto-body)
2696 (save-window-excursion
2697 (save-restriction
2698 (narrow-to-region (point) (point-max))
23f87bed
MB
2699 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2700 (entry (assq func mm-text-html-washer-alist)))
2701 (when entry
2702 (setq func (cdr entry)))
2703 (cond
2704 ((functionp func)
2705 (funcall func))
2706 (t
2707 (apply (car func) (cdr func))))))))))
2708
9640c3bc
GM
2709;; External.
2710(declare-function w3-region "ext:w3-display" (st nd))
2711
23f87bed
MB
2712(defun gnus-article-wash-html-with-w3 ()
2713 "Wash the current buffer with w3."
2714 (mm-setup-w3)
2715 (let ((w3-strict-width (window-width))
2716 (url-standalone-mode t)
2717 (url-gateway-unplugged t)
2718 (w3-honor-stylesheets nil))
2719 (condition-case ()
2720 (w3-region (point-min) (point-max))
2721 (error))))
2722
9640c3bc
GM
2723;; External.
2724(declare-function w3m-region "ext:w3m" (start end &optional url charset))
2725
23f87bed
MB
2726(defun gnus-article-wash-html-with-w3m ()
2727 "Wash the current buffer with emacs-w3m."
2728 (mm-setup-w3m)
7dafe00b
MB
2729 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2730 w3m-force-redisplay)
2731 (w3m-region (point-min) (point-max)))
2732 (when (and mm-inline-text-html-with-w3m-keymap
2733 (boundp 'w3m-minor-mode-map)
2734 w3m-minor-mode-map)
2735 (add-text-properties
2736 (point-min) (point-max)
2737 (list 'keymap w3m-minor-mode-map
2738 ;; Put the mark meaning this part was rendered by emacs-w3m.
2739 'mm-inline-text-html-with-w3m t))))
16409b0b 2740
9efa445f 2741(defvar charset) ;; Bound by `article-wash-html'.
73043f7d
MB
2742
2743(defun gnus-article-wash-html-with-w3m-standalone ()
2744 "Wash the current buffer with w3m."
7347faa8
MB
2745 (if (mm-w3m-standalone-supports-m17n-p)
2746 (progn
2747 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2748 ;; The default.
2749 (setq charset 'iso-8859-1))
2750 (let ((coding-system-for-write charset)
2751 (coding-system-for-read charset))
2752 (call-process-region
2753 (point-min) (point-max)
2754 "w3m" t t nil "-dump" "-T" "text/html"
2755 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2756 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
73043f7d 2757
01c52d31
MB
2758(defvar gnus-article-browse-html-temp-list nil
2759 "List of temporary files created by `gnus-article-browse-html-parts'.
2760Internal variable.")
2761
2762(defcustom gnus-article-browse-delete-temp 'ask
2763 "What to do with temporary files from `gnus-article-browse-html-parts'.
2764If nil, don't delete temporary files. If it is t, delete them on
2765exit from the summary buffer. If it is the symbol `file', query
2766on each file, if it is `ask' ask once when exiting from the
2767summary buffer."
2768 :group 'gnus-article
330f707b 2769 :version "23.1" ;; No Gnus
01c52d31
MB
2770 :type '(choice (const :tag "Don't delete" nil)
2771 (const :tag "Don't ask" t)
2772 (const :tag "Ask" ask)
2773 (const :tag "Ask for each file" file)))
2774
2775;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2776
2777(defun gnus-article-browse-delete-temp-files (&optional how)
2778 "Delete temp-files created by `gnus-article-browse-html-parts'."
2779 (when (and gnus-article-browse-html-temp-list
2780 (or how
2781 (setq how gnus-article-browse-delete-temp)))
2782 (when (and (eq how 'ask)
bbbe940b
MB
2783 (gnus-y-or-n-p (format
2784 "Delete all %s temporary HTML file(s)? "
2785 (length gnus-article-browse-html-temp-list)))
01c52d31
MB
2786 (setq how t)))
2787 (dolist (file gnus-article-browse-html-temp-list)
2788 (when (and (file-exists-p file)
2789 (or (eq how t)
2790 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2791 (gnus-y-or-n-p
2792 (format "Delete temporary HTML file `%s'? " file))))
2793 (delete-file file)))
2794 ;; Also remove file from the list when not deleted or if file doesn't
2795 ;; exist anymore.
2796 (setq gnus-article-browse-html-temp-list nil))
2797 gnus-article-browse-html-temp-list)
2798
87035689 2799(defun gnus-article-browse-html-parts (list &optional header)
01c52d31 2800 "View all \"text/html\" parts from LIST.
87035689
MB
2801Recurse into multiparts. The optional HEADER that should be a decoded
2802message header will be added to the bodies of the \"text/html\" parts."
01c52d31 2803 ;; Internal function used by `gnus-article-browse-html-article'.
bbbe940b 2804 (let (type file charset tmp-file showed)
01c52d31
MB
2805 ;; Find and show the html-parts.
2806 (dolist (handle list)
2807 ;; If HTML, show it:
bbbe940b
MB
2808 (cond ((not (listp handle)))
2809 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2810 (and (equal (car type) "message/external-body")
87035689
MB
2811 (or header
2812 (setq file (or (mail-content-type-get type 'name)
2813 (mail-content-type-get
2814 (mm-handle-disposition handle)
2815 'filename))))
bbbe940b
MB
2816 (or (mm-handle-cache handle)
2817 (condition-case code
2818 (progn (mm-extern-cache-contents handle) t)
2819 (error
2820 (gnus-message 3 "%s" (error-message-string code))
2821 (when (>= gnus-verbose 3) (sit-for 2))
2822 nil)))
2823 (progn
2824 (setq handle (mm-handle-cache handle)
2825 type (mm-handle-type handle))
2826 (equal (car type) "text/html"))))
2827 (when (or (setq charset (mail-content-type-get type 'charset))
87035689 2828 header
bbbe940b
MB
2829 (not file))
2830 (setq tmp-file (mm-make-temp-file
2831 ;; Do we need to care for 8.3 filenames?
2832 "mm-" nil ".html")))
87035689
MB
2833 ;; Add a meta html tag to specify charset and a header.
2834 (cond
2835 (header
2836 (let (title eheader body hcharset coding)
2837 (with-temp-buffer
2838 (mm-enable-multibyte)
2839 (setq case-fold-search t)
2840 (insert header "\n")
2841 (setq title (message-fetch-field "subject"))
2842 (goto-char (point-min))
2843 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2844 (replace-match (cond ((match-beginning 1) "&lt;")
2845 ((match-beginning 2) "&gt;")
2846 (t "&amp;"))))
2847 (goto-char (point-min))
2848 (insert "<pre>\n")
2849 (goto-char (point-max))
2850 (insert "</pre>\n<hr>\n")
2851 ;; We have to examine charset one by one since
2852 ;; charset specified in parts might be different.
2853 (if (eq charset 'gnus-decoded)
2854 (setq charset 'utf-8
2855 eheader (mm-encode-coding-string (buffer-string)
2856 charset)
2857 title (when title
2858 (mm-encode-coding-string title charset))
2859 body (mm-encode-coding-string (mm-get-part handle)
2860 charset))
2861 (setq hcharset (mm-find-mime-charset-region (point-min)
2862 (point-max)))
2863 (cond ((= (length hcharset) 1)
2864 (setq hcharset (car hcharset)
2865 coding (mm-charset-to-coding-system
2866 hcharset)))
2867 ((> (length hcharset) 1)
2868 (setq hcharset 'utf-8
2869 coding hcharset)))
2870 (if coding
2871 (if charset
2872 (progn
2873 (setq body
2874 (mm-charset-to-coding-system charset))
2875 (if (eq coding body)
2876 (setq eheader (mm-encode-coding-string
2877 (buffer-string) coding)
2878 title (when title
2879 (mm-encode-coding-string
2880 title coding))
2881 body (mm-get-part handle))
2882 (setq charset 'utf-8
2883 eheader (mm-encode-coding-string
2884 (buffer-string) charset)
2885 title (when title
2886 (mm-encode-coding-string
2887 title charset))
2888 body (mm-encode-coding-string
2889 (mm-decode-coding-string
2890 (mm-get-part handle) body)
2891 charset))))
2892 (setq charset hcharset
2893 eheader (mm-encode-coding-string
2894 (buffer-string) coding)
2895 title (when title
2896 (mm-encode-coding-string
2897 title coding))
2898 body (mm-get-part handle)))
2899 (setq eheader (mm-string-as-unibyte (buffer-string))
2900 body (mm-get-part handle))))
2901 (erase-buffer)
2902 (mm-disable-multibyte)
2903 (insert body)
2904 (when charset
2905 (mm-add-meta-html-tag handle charset))
2906 (when title
2907 (goto-char (point-min))
2908 (unless (search-forward "<title>" nil t)
2909 (re-search-forward "<head>\\s-*" nil t)
2910 (insert "<title>" title "</title>\n")))
2911 (goto-char (point-min))
2912 (or (re-search-forward
2913 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2914 (re-search-forward
2915 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2916 (insert eheader)
2917 (mm-write-region (point-min) (point-max)
2918 tmp-file nil nil nil 'binary t))))
2919 (charset
2920 (mm-with-unibyte-buffer
2921 (insert (if (eq charset 'gnus-decoded)
2922 (mm-encode-coding-string
2923 (mm-get-part handle)
2924 (setq charset 'utf-8))
2925 (mm-get-part handle)))
2926 (if (or (mm-add-meta-html-tag handle charset)
2927 (not file))
2928 (mm-write-region (point-min) (point-max)
2929 tmp-file nil nil nil 'binary t)
2930 (setq tmp-file nil))))
2931 (tmp-file
2932 (mm-save-part-to-file handle tmp-file)))
bbbe940b
MB
2933 (when tmp-file
2934 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2935 (add-hook 'gnus-summary-prepare-exit-hook
2936 'gnus-article-browse-delete-temp-files)
2937 (add-hook 'gnus-exit-gnus-hook
2938 (lambda ()
2939 (gnus-article-browse-delete-temp-files t)))
2940 ;; FIXME: Warn if there's an <img> tag?
2941 (browse-url-of-file (or tmp-file (expand-file-name file)))
2942 (setq showed t))
2943 ;; If multipart, recurse
87035689
MB
2944 ((equal (mm-handle-media-supertype handle) "multipart")
2945 (when (gnus-article-browse-html-parts handle header)
2946 (setq showed t)))
2947 ((equal (mm-handle-media-type handle) "message/rfc822")
2948 (mm-with-multibyte-buffer
2949 (mm-insert-part handle)
2950 (setq handle (mm-dissect-buffer t t))
2951 (when (and (bufferp (car handle))
2952 (stringp (car (mm-handle-type handle))))
2953 (setq handle (list handle)))
2954 (when header
2955 (article-decode-encoded-words)
2956 (let ((gnus-visible-headers
2957 (or (get 'gnus-visible-headers 'standard-value)
2958 gnus-visible-headers)))
2959 (article-hide-headers))
2960 (goto-char (point-min))
2961 (search-forward "\n\n" nil 'move)
2962 (skip-chars-backward "\t\n ")
2963 (setq header (buffer-substring (point-min) (point)))))
2964 (when (prog1
2965 (gnus-article-browse-html-parts handle header)
2966 (mm-destroy-parts handle))
2967 (setq showed t)))))
01c52d31
MB
2968 showed))
2969
2970;; FIXME: Documentation in texi/gnus.texi missing.
87035689 2971(defun gnus-article-browse-html-article (&optional arg)
01c52d31 2972 "View \"text/html\" parts of the current article with a WWW browser.
87035689
MB
2973The message header is added to the beginning of every html part unless
2974the prefix argument ARG is given.
01c52d31
MB
2975
2976Warning: Spammers use links to images in HTML articles to verify
2977whether you have read the message. As
2978`gnus-article-browse-html-article' passes the unmodified HTML
2979content to the browser without eliminating these \"web bugs\" you
b890d447
MB
2980should only use it for mails from trusted senders.
2981
2982If you alwasy want to display HTML part in the browser, set
2983`mm-text-html-renderer' to nil."
01c52d31 2984 ;; Cf. `mm-w3m-safe-url-regexp'
87035689
MB
2985 (interactive "P")
2986 (if arg
2987 (gnus-summary-show-article)
2988 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
2989 gnus-visible-headers)))
2990 (gnus-summary-show-article)))
2991 (with-current-buffer gnus-article-buffer
2992 (let ((header (unless arg
2993 (save-restriction
2994 (widen)
2995 (buffer-substring-no-properties
2996 (goto-char (point-min))
2997 (if (search-forward "\n\n" nil t)
2998 (match-beginning 0)
2999 (goto-char (point-max))
3000 (skip-chars-backward "\t\n ")
3001 (point))))))
3002 parts)
3003 (set-buffer gnus-original-article-buffer)
3004 (setq parts (mm-dissect-buffer t t))
01c52d31
MB
3005 ;; If singlepart, enforce a list.
3006 (when (and (bufferp (car parts))
3007 (stringp (car (mm-handle-type parts))))
3008 (setq parts (list parts)))
3009 ;; Process the list
87035689 3010 (unless (gnus-article-browse-html-parts parts header)
01c52d31 3011 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
87035689
MB
3012 (mm-destroy-parts parts)
3013 (unless arg
3014 (gnus-summary-show-article)))))
01c52d31 3015
16409b0b
GM
3016(defun article-hide-list-identifiers ()
3017 "Remove list identifies from the Subject header.
3018The `gnus-list-identifiers' variable specifies what to do."
3019 (interactive)
23f87bed
MB
3020 (let ((inhibit-point-motion-hooks t)
3021 (regexp (if (consp gnus-list-identifiers)
3022 (mapconcat 'identity gnus-list-identifiers " *\\|")
3023 gnus-list-identifiers))
3024 (inhibit-read-only t))
3025 (when regexp
3026 (save-excursion
3027 (save-restriction
3028 (article-narrow-to-head)
3029 (goto-char (point-min))
3030 (while (re-search-forward
3031 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3032 nil t)
3033 (delete-region (match-beginning 2) (match-end 0))
3034 (beginning-of-line))
3035 (when (re-search-forward
3036 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3037 (delete-region (match-beginning 1) (match-end 1))))))))
eec82323
LMI
3038
3039(defun article-hide-pem (&optional arg)
3040 "Toggle hiding of any PEM headers and signatures in the current article.
3041If given a negative prefix, always show; if given a positive prefix,
3042always hide."
3043 (interactive (gnus-article-hidden-arg))
3044 (unless (gnus-article-check-hidden-text 'pem arg)
3045 (save-excursion
23f87bed 3046 (let ((inhibit-read-only t) end)
eec82323 3047 (goto-char (point-min))
16409b0b
GM
3048 ;; Hide the horrendously ugly "header".
3049 (when (and (search-forward
3050 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3051 nil t)
3052 (setq end (1+ (match-beginning 0))))
23f87bed 3053 (gnus-add-wash-type 'pem)
16409b0b
GM
3054 (gnus-article-hide-text-type
3055 end
3056 (if (search-forward "\n\n" nil t)
3057 (match-end 0)
3058 (point-max))
3059 'pem)
3060 ;; Hide the trailer as well
3061 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3062 nil t)
3063 (gnus-article-hide-text-type
3064 (match-beginning 0) (match-end 0) 'pem)))))))
3065
3066(defun article-strip-banner ()
23f87bed
MB
3067 "Strip the banners specified by the `banner' group parameter and by
3068`gnus-article-address-banner-alist'."
16409b0b 3069 (interactive)
23f87bed
MB
3070 (save-excursion
3071 (save-restriction
3072 (let ((inhibit-point-motion-hooks t))
3073 (when (gnus-parameter-banner gnus-newsgroup-name)
3074 (article-really-strip-banner
3075 (gnus-parameter-banner gnus-newsgroup-name)))
3076 (when gnus-article-address-banner-alist
cf5a5c38
MB
3077 ;; Note that the From header is decoded here, so it is
3078 ;; required that the *-extract-address-components function
3079 ;; supports non-ASCII text.
d71c0855
MB
3080 (let ((from (save-restriction
3081 (widen)
3082 (article-narrow-to-head)
3083 (mail-fetch-field "from"))))
3084 (when (and from
3085 (setq from
3086 (cadr (funcall gnus-extract-address-components
3087 from))))
3088 (catch 'found
3089 (dolist (pair gnus-article-address-banner-alist)
3090 (when (string-match (car pair) from)
3091 (throw 'found
3092 (article-really-strip-banner (cdr pair)))))))))))))
23f87bed
MB
3093
3094(defun article-really-strip-banner (banner)
3095 "Strip the banner specified by the argument."
16409b0b
GM
3096 (save-excursion
3097 (save-restriction
3098 (let ((inhibit-point-motion-hooks t)
16409b0b 3099 (gnus-signature-limit nil)
23f87bed
MB
3100 (inhibit-read-only t))
3101 (article-goto-body)
3102 (cond
3103 ((eq banner 'signature)
3104 (when (gnus-article-narrow-to-signature)
3105 (widen)
3106 (forward-line -1)
3107 (delete-region (point) (point-max))))
3108 ((symbolp banner)
3109 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3110 (while (re-search-forward banner nil t)
3111 (delete-region (match-beginning 0) (match-end 0)))))
3112 ((stringp banner)
3113 (while (re-search-forward banner nil t)
3114 (delete-region (match-beginning 0) (match-end 0)))))))))
16409b0b
GM
3115
3116(defun article-babel ()
3117 "Translate article using an online translation service."
3118 (interactive)
3119 (require 'babel)
01c52d31 3120 (gnus-with-article-buffer
16409b0b 3121 (when (article-goto-body)
01c52d31 3122 (let* ((start (point))
16409b0b
GM
3123 (end (point-max))
3124 (orig (buffer-substring start end))
23f87bed 3125 (trans (babel-as-string orig)))
16409b0b
GM
3126 (save-restriction
3127 (narrow-to-region start end)
3128 (delete-region start end)
23f87bed 3129 (insert trans))))))
eec82323
LMI
3130
3131(defun article-hide-signature (&optional arg)
3132 "Hide the signature in the current article.
3133If given a negative prefix, always show; if given a positive prefix,
3134always hide."
3135 (interactive (gnus-article-hidden-arg))
3136 (unless (gnus-article-check-hidden-text 'signature arg)
3137 (save-excursion
3138 (save-restriction
4e7d0221 3139 (let ((inhibit-read-only t))
eec82323
LMI
3140 (when (gnus-article-narrow-to-signature)
3141 (gnus-article-hide-text-type
23f87bed
MB
3142 (point-min) (point-max) 'signature))))))
3143 (gnus-set-mode-line 'article))
eec82323 3144
16409b0b
GM
3145(defun article-strip-headers-in-body ()
3146 "Strip offensive headers from bodies."
3147 (interactive)
3148 (save-excursion
3149 (article-goto-body)
3150 (let ((case-fold-search t))
3151 (when (looking-at "x-no-archive:")
3152 (gnus-delete-line)))))
3153
eec82323
LMI
3154(defun article-strip-leading-blank-lines ()
3155 "Remove all blank lines from the beginning of the article."
3156 (interactive)
3157 (save-excursion
3158 (let ((inhibit-point-motion-hooks t)
23f87bed 3159 (inhibit-read-only t))
16409b0b 3160 (when (article-goto-body)
eec82323
LMI
3161 (while (and (not (eobp))
3162 (looking-at "[ \t]*$"))
3163 (gnus-delete-line))))))
3164
16409b0b
GM
3165(defun article-narrow-to-head ()
3166 "Narrow the buffer to the head of the message.
3167Point is left at the beginning of the narrowed-to region."
3168 (narrow-to-region
3169 (goto-char (point-min))
3170 (if (search-forward "\n\n" nil 1)
3171 (1- (point))
3172 (point-max)))
3173 (goto-char (point-min)))
3174
3175(defun article-goto-body ()
3176 "Place point at the start of the body."
3177 (goto-char (point-min))
3178 (cond
3179 ;; This variable is only bound when dealing with separate
3180 ;; MIME body parts.
3181 (article-goto-body-goes-to-point-min-p
3182 t)
3183 ((search-forward "\n\n" nil t)
3184 t)
3185 (t
3186 (goto-char (point-max))
3187 nil)))
3188
eec82323
LMI
3189(defun article-strip-multiple-blank-lines ()
3190 "Replace consecutive blank lines with one empty line."
3191 (interactive)
3192 (save-excursion
3193 (let ((inhibit-point-motion-hooks t)
23f87bed 3194 (inhibit-read-only t))
eec82323 3195 ;; First make all blank lines empty.
16409b0b 3196 (article-goto-body)
eec82323 3197 (while (re-search-forward "^[ \t]+$" nil t)
16409b0b
GM
3198 (unless (gnus-annotation-in-region-p
3199 (match-beginning 0) (match-end 0))
3200 (replace-match "" nil t)))
eec82323 3201 ;; Then replace multiple empty lines with a single empty line.
16409b0b 3202 (article-goto-body)
23f87bed 3203 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
16409b0b
GM
3204 (unless (gnus-annotation-in-region-p
3205 (match-beginning 0) (match-end 0))
23f87bed 3206 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3207
3208(defun article-strip-leading-space ()
3209 "Remove all white space from the beginning of the lines in the article."
3210 (interactive)
3211 (save-excursion
3212 (let ((inhibit-point-motion-hooks t)
23f87bed 3213 (inhibit-read-only t))
16409b0b 3214 (article-goto-body)
eec82323
LMI
3215 (while (re-search-forward "^[ \t]+" nil t)
3216 (replace-match "" t t)))))
3217
16409b0b
GM
3218(defun article-strip-trailing-space ()
3219 "Remove all white space from the end of the lines in the article."
3220 (interactive)
3221 (save-excursion
3222 (let ((inhibit-point-motion-hooks t)
23f87bed 3223 (inhibit-read-only t))
16409b0b
GM
3224 (article-goto-body)
3225 (while (re-search-forward "[ \t]+$" nil t)
3226 (replace-match "" t t)))))
3227
eec82323
LMI
3228(defun article-strip-blank-lines ()
3229 "Strip leading, trailing and multiple blank lines."
3230 (interactive)
3231 (article-strip-leading-blank-lines)
3232 (article-remove-trailing-blank-lines)
3233 (article-strip-multiple-blank-lines))
3234
6748645f
LMI
3235(defun article-strip-all-blank-lines ()
3236 "Strip all blank lines."
3237 (interactive)
3238 (save-excursion
3239 (let ((inhibit-point-motion-hooks t)
23f87bed 3240 (inhibit-read-only t))
16409b0b 3241 (article-goto-body)
6748645f
LMI
3242 (while (re-search-forward "^[ \t]*\n" nil t)
3243 (replace-match "" t t)))))
3244
eec82323
LMI
3245(defun gnus-article-narrow-to-signature ()
3246 "Narrow to the signature; return t if a signature is found, else nil."
6748645f 3247 (let ((inhibit-point-motion-hooks t))
6748645f
LMI
3248 (when (gnus-article-search-signature)
3249 (forward-line 1)
3250 ;; Check whether we have some limits to what we consider
3251 ;; to be a signature.
3252 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3253 (list gnus-signature-limit)))
3254 limit limited)
3255 (while (setq limit (pop limits))
3256 (if (or (and (integerp limit)
3257 (< (- (point-max) (point)) limit))
3258 (and (floatp limit)
3259 (< (count-lines (point) (point-max)) limit))
23f87bed 3260 (and (functionp limit)
6748645f
LMI
3261 (funcall limit))
3262 (and (stringp limit)
3263 (not (re-search-forward limit nil t))))
3264 () ; This limit did not succeed.
3265 (setq limited t
3266 limits nil)))
3267 (unless limited
3268 (narrow-to-region (point) (point-max))
3269 t)))))
eec82323
LMI
3270
3271(defun gnus-article-search-signature ()
3272 "Search the current buffer for the signature separator.
3273Put point at the beginning of the signature separator."
3274 (let ((cur (point)))
3275 (goto-char (point-max))
3276 (if (if (stringp gnus-signature-separator)
3277 (re-search-backward gnus-signature-separator nil t)
3278 (let ((seps gnus-signature-separator))
3279 (while (and seps
3280 (not (re-search-backward (car seps) nil t)))
3281 (pop seps))
3282 seps))
3283 t
3284 (goto-char cur)
3285 nil)))
3286
eec82323
LMI
3287(defun gnus-article-hidden-arg ()
3288 "Return the current prefix arg as a number, or 0 if no prefix."
3289 (list (if current-prefix-arg
3290 (prefix-numeric-value current-prefix-arg)
3291 0)))
3292
3293(defun gnus-article-check-hidden-text (type arg)
3294 "Return nil if hiding is necessary.
f0529b5b 3295Arg can be nil or a number. nil and positive means hide, negative
eec82323
LMI
3296means show, 0 means toggle."
3297 (save-excursion
3298 (save-restriction
eec82323
LMI
3299 (let ((hide (gnus-article-hidden-text-p type)))
3300 (cond
3301 ((or (null arg)
3302 (> arg 0))
3303 nil)
3304 ((< arg 0)
4481aa98
SZ
3305 (gnus-article-show-hidden-text type)
3306 t)
eec82323
LMI
3307 (t
3308 (if (eq hide 'hidden)
4481aa98
SZ
3309 (progn
3310 (gnus-article-show-hidden-text type)
3311 t)
eec82323
LMI
3312 nil)))))))
3313
3314(defun gnus-article-hidden-text-p (type)
3315 "Say whether the current buffer contains hidden text of type TYPE."
6748645f 3316 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
eec82323 3317 (while (and pos
16409b0b
GM
3318 (not (get-text-property pos 'invisible))
3319 (not (get-text-property pos 'dummy-invisible)))
eec82323
LMI
3320 (setq pos
3321 (text-property-any (1+ pos) (point-max) 'article-type type)))
3322 (if pos
3323 'hidden
16409b0b 3324 nil)))
eec82323 3325
520aa572 3326(defun gnus-article-show-hidden-text (type &optional dummy)
eec82323 3327 "Show all hidden text of type TYPE.
520aa572 3328Originally it is hide instead of DUMMY."
4e7d0221 3329 (let ((inhibit-read-only t)
520aa572 3330 (inhibit-point-motion-hooks t))
a1506d29 3331 (gnus-remove-text-properties-when
520aa572 3332 'article-type type
a1506d29 3333 (point-min) (point-max)
520aa572 3334 (cons 'article-type (cons type
23f87bed
MB
3335 gnus-hidden-properties)))
3336 (gnus-delete-wash-type type)))
eec82323
LMI
3337
3338(defconst article-time-units
3339 `((year . ,(* 365.25 24 60 60))
3340 (week . ,(* 7 24 60 60))
3341 (day . ,(* 24 60 60))
3342 (hour . ,(* 60 60))
3343 (minute . 60)
3344 (second . 1))
3345 "Mapping from time units to seconds.")
3346
23f87bed
MB
3347(defun gnus-article-forward-header ()
3348 "Move point to the start of the next header.
3349If the current header is a continuation header, this can be several
3350lines forward."
3351 (let ((ended nil))
3352 (while (not ended)
3353 (forward-line 1)
3354 (if (looking-at "[ \t]+[^ \t]")
3355 (forward-line 1)
3356 (setq ended t)))))
3357
31640842 3358(defun article-date-ut (&optional type highlight)
eec82323
LMI
3359 "Convert DATE date to universal time in the current article.
3360If TYPE is `local', convert to local time; if it is `lapsed', output
16409b0b
GM
3361how much time has lapsed since DATE. For `lapsed', the value of
3362`gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3363should replace the \"Date:\" one, or should be added below it."
eec82323 3364 (interactive (list 'ut t))
31640842
MB
3365 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3366 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3367 tdate-regexp)
3368 ((eq type 'lapsed)
3369 "^X-Sent:[ \t]")
3370 (article-lapsed-timer
3371 "^Date:[ \t]")
3372 (t
3373 tdate-regexp)))
3374 (case-fold-search t)
3375 (inhibit-read-only t)
eec82323 3376 (inhibit-point-motion-hooks t)
31640842 3377 pos date bface eface)
16409b0b
GM
3378 (save-excursion
3379 (save-restriction
31640842
MB
3380 (widen)
3381 (goto-char (point-min))
3382 (while (or (setq date (get-text-property (setq pos (point))
3383 'original-date))
3384 (when (setq pos (next-single-property-change
3385 (point) 'original-date))
3386 (setq date (get-text-property pos 'original-date))
3387 t))
3388 (narrow-to-region pos (or (text-property-any pos (point-max)
3389 'original-date nil)
3390 (point-max)))
16409b0b 3391 (goto-char (point-min))
31640842 3392 (when (re-search-forward tdate-regexp nil t)
01c52d31
MB
3393 (setq bface (get-text-property (point-at-bol) 'face)
3394 eface (get-text-property (1- (point-at-eol)) 'face)))
31640842
MB
3395 (goto-char (point-min))
3396 (setq pos nil)
3397 ;; Delete any old Date headers.
3398 (while (re-search-forward date-regexp nil t)
3399 (if pos
01c52d31
MB
3400 (delete-region (point-at-bol) (progn
3401 (gnus-article-forward-header)
3402 (point)))
3403 (delete-region (point-at-bol) (progn
3404 (gnus-article-forward-header)
3405 (forward-char -1)
3406 (point)))
31640842
MB
3407 (setq pos (point))))
3408 (when (and (not pos)
3409 (re-search-forward tdate-regexp nil t))
3410 (forward-line 1))
3411 (gnus-goto-char pos)
3412 (insert (article-make-date-line date (or type 'ut)))
3413 (unless pos
3414 (insert "\n")
3415 (forward-line -1))
3416 ;; Do highlighting.
3417 (beginning-of-line)
3418 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3419 (put-text-property (match-beginning 1) (1+ (match-end 1))
3420 'face bface)
3421 (put-text-property (match-beginning 2) (match-end 2)
3422 'face eface))
3423 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3424 (goto-char (point-max))
3425 (widen))))))
eec82323
LMI
3426
3427(defun article-make-date-line (date type)
3428 "Return a DATE line of TYPE."
23f87bed
MB
3429 (unless (memq type '(local ut original user iso8601 lapsed english))
3430 (error "Unknown conversion type: %s" type))
3431 (condition-case ()
3432 (let ((time (date-to-time date)))
16409b0b 3433 (cond
23f87bed
MB
3434 ;; Convert to the local timezone.
3435 ((eq type 'local)
01c52d31 3436 (concat "Date: " (message-make-date time)))
23f87bed
MB
3437 ;; Convert to Universal Time.
3438 ((eq type 'ut)
3439 (concat "Date: "
01c52d31
MB
3440 (substring
3441 (message-make-date
3442 (let* ((e (parse-time-string date))
3443 (tm (apply 'encode-time e))
3444 (ms (car tm))
3445 (ls (- (cadr tm) (car (current-time-zone time)))))
3446 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3447 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3448 (t (list ms ls)))))
3449 0 -5)
3450 "UT"))
23f87bed
MB
3451 ;; Get the original date from the article.
3452 ((eq type 'original)
3453 (concat "Date: " (if (string-match "\n+$" date)
3454 (substring date 0 (match-beginning 0))
3455 date)))
3456 ;; Let the user define the format.
3457 ((eq type 'user)
3458 (let ((format (or (condition-case nil
3459 (with-current-buffer gnus-summary-buffer
3460 gnus-article-time-format)
3461 (error nil))
3462 gnus-article-time-format)))
3463 (if (functionp format)
3464 (funcall format time)
3465 (concat "Date: " (format-time-string format time)))))
3466 ;; ISO 8601.
3467 ((eq type 'iso8601)
3468 (let ((tz (car (current-time-zone time))))
3469 (concat
3470 "Date: "
3471 (format-time-string "%Y%m%dT%H%M%S" time)
3472 (format "%s%02d%02d"
3473 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3474 (/ (% (abs tz) 3600) 60)))))
3475 ;; Do an X-Sent lapsed format.
3476 ((eq type 'lapsed)
3477 ;; If the date is seriously mangled, the timezone functions are
3478 ;; liable to bug out, so we ignore all errors.
3479 (let* ((now (current-time))
3480 (real-time (subtract-time now time))
3481 (real-sec (and real-time
3482 (+ (* (float (car real-time)) 65536)
3483 (cadr real-time))))
3484 (sec (and real-time (abs real-sec)))
3485 num prev)
3486 (cond
3487 ((null real-time)
3488 "X-Sent: Unknown")
3489 ((zerop sec)
3490 "X-Sent: Now")
3491 (t
3492 (concat
3493 "X-Sent: "
3494 ;; This is a bit convoluted, but basically we go
3495 ;; through the time units for years, weeks, etc,
3496 ;; and divide things to see whether that results
3497 ;; in positive answers.
3498 (mapconcat
3499 (lambda (unit)
3500 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3501 ;; The (remaining) seconds are too few to
3502 ;; be divided into this time unit.
3503 ""
3504 ;; It's big enough, so we output it.
3505 (setq sec (- sec (* num (cdr unit))))
3506 (prog1
3507 (concat (if prev ", " "") (int-to-string
3508 (floor num))
3509 " " (symbol-name (car unit))
3510 (if (> num 1) "s" ""))
3511 (setq prev t))))
3512 article-time-units "")
3513 ;; If dates are odd, then it might appear like the
3514 ;; article was sent in the future.
3515 (if (> real-sec 0)
3516 " ago"
3517 " in the future"))))))
3518 ;; Display the date in proper English
3519 ((eq type 'english)
3520 (let ((dtime (decode-time time)))
3521 (concat
3522 "Date: the "
3523 (number-to-string (nth 3 dtime))
3524 (let ((digit (% (nth 3 dtime) 10)))
3525 (cond
3526 ((memq (nth 3 dtime) '(11 12 13)) "th")
3527 ((= digit 1) "st")
3528 ((= digit 2) "nd")
3529 ((= digit 3) "rd")
3530 (t "th")))
3531 " of "
3532 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3533 " "
3534 (number-to-string (nth 5 dtime))
3535 " at "
3536 (format "%02d" (nth 2 dtime))
3537 ":"
3538 (format "%02d" (nth 1 dtime)))))))
3539 (error
a601fb74 3540 (format "Date: %s (from Gnus)" date))))
eec82323
LMI
3541
3542(defun article-date-local (&optional highlight)
3543 "Convert the current article date to the local timezone."
3544 (interactive (list t))
3545 (article-date-ut 'local highlight))
3546
23f87bed
MB
3547(defun article-date-english (&optional highlight)
3548 "Convert the current article date to something that is proper English."
3549 (interactive (list t))
3550 (article-date-ut 'english highlight))
3551
eec82323
LMI
3552(defun article-date-original (&optional highlight)
3553 "Convert the current article date to what it was originally.
3554This is only useful if you have used some other date conversion
3555function and want to see what the date was before converting."
3556 (interactive (list t))
3557 (article-date-ut 'original highlight))
3558
3559(defun article-date-lapsed (&optional highlight)
3560 "Convert the current article date to time lapsed since it was sent."
3561 (interactive (list t))
3562 (article-date-ut 'lapsed highlight))
3563
6748645f
LMI
3564(defun article-update-date-lapsed ()
3565 "Function to be run from a timer to update the lapsed time line."
e0a8aa09
LT
3566 (save-match-data
3567 (let (deactivate-mark)
3568 (save-excursion
3569 (ignore-errors
3570 (walk-windows
3571 (lambda (w)
3572 (set-buffer (window-buffer w))
3573 (when (eq major-mode 'gnus-article-mode)
3574 (let ((mark (point-marker)))
3575 (goto-char (point-min))
3576 (when (re-search-forward "^X-Sent:" nil t)
3577 (article-date-lapsed t))
3578 (goto-char (marker-position mark))
3579 (move-marker mark nil))))
3580 nil 'visible))))))
6748645f
LMI
3581
3582(defun gnus-start-date-timer (&optional n)
3583 "Start a timer to update the X-Sent header in the article buffers.
3584The numerical prefix says how frequently (in seconds) the function
3585is to run."
3586 (interactive "p")
3587 (unless n
3588 (setq n 1))
3589 (gnus-stop-date-timer)
3590 (setq article-lapsed-timer
01c52d31 3591 (run-at-time 1 n 'article-update-date-lapsed)))
6748645f
LMI
3592
3593(defun gnus-stop-date-timer ()
3594 "Stop the X-Sent timer."
3595 (interactive)
3596 (when article-lapsed-timer
3597 (nnheader-cancel-timer article-lapsed-timer)
3598 (setq article-lapsed-timer nil)))
3599
eec82323
LMI
3600(defun article-date-user (&optional highlight)
3601 "Convert the current article date to the user-defined format.
3602This format is defined by the `gnus-article-time-format' variable."
3603 (interactive (list t))
3604 (article-date-ut 'user highlight))
3605
6748645f
LMI
3606(defun article-date-iso8601 (&optional highlight)
3607 "Convert the current article date to ISO8601."
3608 (interactive (list t))
3609 (article-date-ut 'iso8601 highlight))
3610
31640842
MB
3611(defmacro gnus-article-save-original-date (&rest forms)
3612 "Save the original date as a text property and evaluate FORMS."
3613 `(let* ((case-fold-search t)
3614 (start (progn
3615 (goto-char (point-min))
3616 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3617 (not (bolp)))
3618 (match-end 0))))
3619 (date (when (and start
01c52d31 3620 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
31640842
MB
3621 nil t))
3622 (buffer-substring-no-properties start
3623 (match-beginning 0)))))
3624 (goto-char (point-max))
3625 (skip-chars-backward "\n")
3626 (put-text-property (point-min) (point) 'original-date date)
3627 ,@forms
3628 (goto-char (point-max))
3629 (skip-chars-backward "\n")
3630 (put-text-property (point-min) (point) 'original-date date)))
3631
23f87bed
MB
3632;; (defun article-show-all ()
3633;; "Show all hidden text in the article buffer."
3634;; (interactive)
3635;; (save-excursion
3636;; (let ((inhibit-read-only t))
3637;; (gnus-article-unhide-text (point-min) (point-max)))))
3638
3639(defun article-remove-leading-whitespace ()
3640 "Remove excessive whitespace from all headers."
eec82323
LMI
3641 (interactive)
3642 (save-excursion
23f87bed
MB
3643 (save-restriction
3644 (let ((inhibit-read-only t))
3645 (article-narrow-to-head)
3646 (goto-char (point-min))
3647 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3648 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3649
3650(defun article-emphasize (&optional arg)
3651 "Emphasize text according to `gnus-emphasis-alist'."
3652 (interactive (gnus-article-hidden-arg))
3653 (unless (gnus-article-check-hidden-text 'emphasis arg)
3654 (save-excursion
a1506d29 3655 (let ((alist (or
16409b0b 3656 (condition-case nil
a1506d29
JB
3657 (with-current-buffer gnus-summary-buffer
3658 gnus-article-emphasis-alist)
16409b0b
GM
3659 (error))
3660 gnus-emphasis-alist))
4e7d0221 3661 (inhibit-read-only t)
eec82323
LMI
3662 (props (append '(article-type emphasis)
3663 gnus-hidden-properties))
3664 regexp elem beg invisible visible face)
16409b0b 3665 (article-goto-body)
eec82323
LMI
3666 (setq beg (point))
3667 (while (setq elem (pop alist))
3668 (goto-char beg)
3669 (setq regexp (car elem)
3670 invisible (nth 1 elem)
3671 visible (nth 2 elem)
3672 face (nth 3 elem))
3673 (while (re-search-forward regexp nil t)
23f87bed
MB
3674 (when (and (match-beginning visible) (match-beginning invisible))
3675 (gnus-article-hide-text
3676 (match-beginning invisible) (match-end invisible) props)
3677 (gnus-article-unhide-text-type
3678 (match-beginning visible) (match-end visible) 'emphasis)
3679 (gnus-put-overlay-excluding-newlines
3680 (match-beginning visible) (match-end visible) 'face face)
3681 (gnus-add-wash-type 'emphasis)
3682 (goto-char (match-end invisible)))))))))
eec82323 3683
16409b0b
GM
3684(defun gnus-article-setup-highlight-words (&optional highlight-words)
3685 "Setup newsgroup emphasis alist."
3686 (unless gnus-article-emphasis-alist
3687 (let ((name (and gnus-newsgroup-name
3688 (gnus-group-real-name gnus-newsgroup-name))))
3689 (make-local-variable 'gnus-article-emphasis-alist)
a1506d29
JB
3690 (setq gnus-article-emphasis-alist
3691 (nconc
16409b0b
GM
3692 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3693 (while (setq elem (pop alist))
3694 (when (and name (string-match (car elem) name))
3695 (setq alist nil
3696 highlight (copy-sequence (cdr elem)))))
3697 highlight)
3698 (copy-sequence highlight-words)
3699 (if gnus-newsgroup-name
a1506d29 3700 (copy-sequence (gnus-group-find-parameter
16409b0b
GM
3701 gnus-newsgroup-name 'highlight-words t)))
3702 gnus-emphasis-alist)))))
3703
9efa445f
DN
3704(defvar gnus-summary-article-menu)
3705(defvar gnus-summary-post-menu)
eec82323
LMI
3706
3707;;; Saving functions.
3708
3709(defun gnus-article-save (save-buffer file &optional num)
3710 "Save the currently selected article."
26c9afc3
MB
3711 (when (or (get gnus-default-article-saver :headers)
3712 (not gnus-save-all-headers))
3713 ;; Remove headers according to `gnus-saved-headers' or the value
3714 ;; of the `:headers' property that the saver function might have.
eec82323 3715 (let ((gnus-visible-headers
26c9afc3
MB
3716 (or (symbol-value (get gnus-default-article-saver :headers))
3717 gnus-saved-headers gnus-visible-headers))
eec82323 3718 (gnus-article-buffer save-buffer))
80de1778 3719 (with-current-buffer save-buffer
6748645f 3720 (article-hide-headers 1 t))))
eec82323
LMI
3721 (save-window-excursion
3722 (if (not gnus-default-article-saver)
a8151ef7 3723 (error "No default saver is defined")
eec82323 3724 ;; !!! Magic! The saving functions all save
16409b0b 3725 ;; `gnus-save-article-buffer' (or so they think), but we
eec82323
LMI
3726 ;; bind that variable to our save-buffer.
3727 (set-buffer gnus-article-buffer)
3728 (let* ((gnus-save-article-buffer save-buffer)
3729 (filename
3730 (cond
3731 ((not gnus-prompt-before-saving) 'default)
3732 ((eq gnus-prompt-before-saving 'always) nil)
3733 (t file)))
3734 (gnus-number-of-articles-to-be-saved
3735 (when (eq gnus-prompt-before-saving t)
3736 num))) ; Magic
6748645f 3737 (set-buffer gnus-article-current-summary)
eec82323
LMI
3738 (funcall gnus-default-article-saver filename)))))
3739
3740(defun gnus-read-save-file-name (prompt &optional filename
26c9afc3
MB
3741 function group headers variable
3742 dir-var)
eec82323
LMI
3743 (let ((default-name
3744 (funcall function group headers (symbol-value variable)))
3745 result)
4325195c 3746 (setq result
a1506d29 3747 (expand-file-name
4325195c
DL
3748 (cond
3749 ((eq filename 'default)
3750 default-name)
3751 ((eq filename t)
3752 default-name)
3753 (filename filename)
3754 (t
26c9afc3
MB
3755 (when (symbol-value dir-var)
3756 (setq default-name (expand-file-name
3757 (file-name-nondirectory default-name)
3758 (symbol-value dir-var))))
4325195c
DL
3759 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3760 (prompt
3761 (format prompt
3762 (if (and gnus-number-of-articles-to-be-saved
3763 (> gnus-number-of-articles-to-be-saved 1))
3764 (format "these %d articles"
3765 gnus-number-of-articles-to-be-saved)
3766 "this article")))
3767 (file
3768 ;; Let the split methods have their say.
3769 (cond
3770 ;; No split name was found.
3771 ((null split-name)
3772 (read-file-name
3773 (concat prompt " (default "
81df110a 3774 (file-name-nondirectory default-name) "): ")
4325195c
DL
3775 (file-name-directory default-name)
3776 default-name))
3777 ;; A single group name is returned.
3778 ((stringp split-name)
3779 (setq default-name
3780 (funcall function split-name headers
3781 (symbol-value variable)))
3782 (read-file-name
3783 (concat prompt " (default "
81df110a 3784 (file-name-nondirectory default-name) "): ")
4325195c
DL
3785 (file-name-directory default-name)
3786 default-name))
3787 ;; A single split name was found
3788 ((= 1 (length split-name))
3789 (let* ((name (expand-file-name
23f87bed
MB
3790 (car split-name)
3791 gnus-article-save-directory))
4325195c
DL
3792 (dir (cond ((file-directory-p name)
3793 (file-name-as-directory name))
3794 ((file-exists-p name) name)
3795 (t gnus-article-save-directory))))
3796 (read-file-name
81df110a 3797 (concat prompt " (default " name "): ")
4325195c
DL
3798 dir name)))
3799 ;; A list of splits was found.
3800 (t
3801 (setq split-name (nreverse split-name))
3802 (let (result)
3803 (let ((file-name-history
3804 (nconc split-name file-name-history)))
3805 (setq result
3806 (expand-file-name
3807 (read-file-name
81df110a 3808 (concat prompt " (`M-p' for defaults): ")
4325195c
DL
3809 gnus-article-save-directory
3810 (car split-name))
3811 gnus-article-save-directory)))
3812 (car (push result file-name-history)))))))
3813 ;; Create the directory.
3814 (gnus-make-directory (file-name-directory file))
23f87bed 3815 ;; If we have read a directory, we append the default file name.
4325195c 3816 (when (file-directory-p file)
23f87bed
MB
3817 (setq file (expand-file-name (file-name-nondirectory
3818 default-name)
4325195c
DL
3819 (file-name-as-directory file))))
3820 ;; Possibly translate some characters.
3821 (nnheader-translate-file-chars file))))))
eec82323 3822 (gnus-make-directory (file-name-directory result))
26c9afc3
MB
3823 (when variable
3824 (set variable result))
3825 (when dir-var
3826 (set dir-var (file-name-directory result)))
3827 result))
eec82323
LMI
3828
3829(defun gnus-article-archive-name (group)
3830 "Return the first instance of an \"Archive-name\" in the current buffer."
3831 (let ((case-fold-search t))
3832 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3833 (nnheader-concat gnus-article-save-directory
3834 (match-string 1)))))
3835
3836(defun gnus-article-nndoc-name (group)
3837 "If GROUP is an nndoc group, return the name of the parent group."
3838 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3839 (gnus-group-get-parameter group 'save-article-group)))
3840
3841(defun gnus-summary-save-in-rmail (&optional filename)
3842 "Append this article to Rmail file.
3843Optional argument FILENAME specifies file name.
3844Directory to save to is default to `gnus-article-save-directory'."
eec82323 3845 (setq filename (gnus-read-save-file-name
81df110a 3846 "Save %s in rmail file" filename
eec82323
LMI
3847 gnus-rmail-save-name gnus-newsgroup-name
3848 gnus-current-headers 'gnus-newsgroup-last-rmail))
3849 (gnus-eval-in-buffer-window gnus-save-article-buffer
3850 (save-excursion
3851 (save-restriction
3852 (widen)
6748645f
LMI
3853 (gnus-output-to-rmail filename))))
3854 filename)
eec82323
LMI
3855
3856(defun gnus-summary-save-in-mail (&optional filename)
3857 "Append this article to Unix mail file.
3858Optional argument FILENAME specifies file name.
3859Directory to save to is default to `gnus-article-save-directory'."
eec82323 3860 (setq filename (gnus-read-save-file-name
81df110a 3861 "Save %s in Unix mail file" filename
eec82323
LMI
3862 gnus-mail-save-name gnus-newsgroup-name
3863 gnus-current-headers 'gnus-newsgroup-last-mail))
3864 (gnus-eval-in-buffer-window gnus-save-article-buffer
3865 (save-excursion
3866 (save-restriction
3867 (widen)
3868 (if (and (file-readable-p filename)
23f87bed 3869 (file-regular-p filename)
eec82323 3870 (mail-file-babyl-p filename))
16409b0b 3871 (rmail-output-to-rmail-file filename t)
6748645f
LMI
3872 (gnus-output-to-mail filename)))))
3873 filename)
eec82323 3874
26c9afc3
MB
3875(put 'gnus-summary-save-in-file :decode t)
3876(put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
eec82323
LMI
3877(defun gnus-summary-save-in-file (&optional filename overwrite)
3878 "Append this article to file.
3879Optional argument FILENAME specifies file name.
3880Directory to save to is default to `gnus-article-save-directory'."
eec82323 3881 (setq filename (gnus-read-save-file-name
81df110a 3882 "Save %s in file" filename
eec82323
LMI
3883 gnus-file-save-name gnus-newsgroup-name
3884 gnus-current-headers 'gnus-newsgroup-last-file))
3885 (gnus-eval-in-buffer-window gnus-save-article-buffer
3886 (save-excursion
3887 (save-restriction
3888 (widen)
3889 (when (and overwrite
3890 (file-exists-p filename))
3891 (delete-file filename))
6748645f
LMI
3892 (gnus-output-to-file filename))))
3893 filename)
eec82323 3894
26c9afc3
MB
3895(put 'gnus-summary-write-to-file :decode t)
3896(put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3897(put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
eec82323 3898(defun gnus-summary-write-to-file (&optional filename)
23f87bed 3899 "Write this article to a file, overwriting it if the file exists.
eec82323
LMI
3900Optional argument FILENAME specifies file name.
3901The directory to save in defaults to `gnus-article-save-directory'."
26c9afc3
MB
3902 (setq filename (gnus-read-save-file-name
3903 "Save %s in file" filename
3904 gnus-file-save-name gnus-newsgroup-name
3905 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3906 (gnus-summary-save-in-file filename t))
eec82323 3907
26c9afc3
MB
3908(put 'gnus-summary-save-body-in-file :decode t)
3909(defun gnus-summary-save-body-in-file (&optional filename overwrite)
eec82323
LMI
3910 "Append this article body to a file.
3911Optional argument FILENAME specifies file name.
3912The directory to save in defaults to `gnus-article-save-directory'."
eec82323 3913 (setq filename (gnus-read-save-file-name
81df110a 3914 "Save %s body in file" filename
eec82323
LMI
3915 gnus-file-save-name gnus-newsgroup-name
3916 gnus-current-headers 'gnus-newsgroup-last-file))
3917 (gnus-eval-in-buffer-window gnus-save-article-buffer
3918 (save-excursion
3919 (save-restriction
3920 (widen)
16409b0b 3921 (when (article-goto-body)
eec82323 3922 (narrow-to-region (point) (point-max)))
26c9afc3
MB
3923 (when (and overwrite
3924 (file-exists-p filename))
3925 (delete-file filename))
6748645f
LMI
3926 (gnus-output-to-file filename))))
3927 filename)
eec82323 3928
26c9afc3
MB
3929(put 'gnus-summary-write-body-to-file :decode t)
3930(put 'gnus-summary-write-body-to-file
3931 :function 'gnus-summary-save-body-in-file)
3932(defun gnus-summary-write-body-to-file (&optional filename)
3933 "Write this article body to a file, overwriting it if the file exists.
3934Optional argument FILENAME specifies file name.
3935The directory to save in defaults to `gnus-article-save-directory'."
3936 (setq filename (gnus-read-save-file-name
3937 "Save %s body in file" filename
3938 gnus-file-save-name gnus-newsgroup-name
3939 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3940 (gnus-summary-save-body-in-file filename t))
3941
eec82323
LMI
3942(defun gnus-summary-save-in-pipe (&optional command)
3943 "Pipe this article to subprocess."
eec82323 3944 (setq command
16409b0b
GM
3945 (cond ((and (eq command 'default)
3946 gnus-last-shell-command)
eec82323 3947 gnus-last-shell-command)
676a7cc9
SZ
3948 ((stringp command)
3949 command)
eec82323
LMI
3950 (t (read-string
3951 (format
3952 "Shell command on %s: "
3953 (if (and gnus-number-of-articles-to-be-saved
3954 (> gnus-number-of-articles-to-be-saved 1))
3955 (format "these %d articles"
3956 gnus-number-of-articles-to-be-saved)
3957 "this article"))
3958 gnus-last-shell-command))))
3959 (when (string-equal command "")
676a7cc9
SZ
3960 (if gnus-last-shell-command
3961 (setq command gnus-last-shell-command)
715a2ca2 3962 (error "A command is required")))
eec82323
LMI
3963 (gnus-eval-in-buffer-window gnus-article-buffer
3964 (save-restriction
3965 (widen)
3966 (shell-command-on-region (point-min) (point-max) command nil)))
3967 (setq gnus-last-shell-command command))
3968
23f87bed
MB
3969(defun gnus-summary-pipe-to-muttprint (&optional command)
3970 "Pipe this article to muttprint."
01c52d31 3971 (setq command (read-string
23f87bed
MB
3972 "Print using command: " gnus-summary-muttprint-program
3973 nil gnus-summary-muttprint-program))
3974 (gnus-summary-save-in-pipe command))
3975
eec82323
LMI
3976;;; Article file names when saving.
3977
3978(defun gnus-capitalize-newsgroup (newsgroup)
3979 "Capitalize NEWSGROUP name."
3980 (when (not (zerop (length newsgroup)))
3981 (concat (char-to-string (upcase (aref newsgroup 0)))
3982 (substring newsgroup 1))))
3983
3984(defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3985 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3986If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3987Otherwise, it is like ~/News/news/group/num."
3988 (let ((default
3989 (expand-file-name
3990 (concat (if (gnus-use-long-file-name 'not-save)
3991 (gnus-capitalize-newsgroup newsgroup)
3992 (gnus-newsgroup-directory-form newsgroup))
3993 "/" (int-to-string (mail-header-number headers)))
3994 gnus-article-save-directory)))
3995 (if (and last-file
3996 (string-equal (file-name-directory default)
3997 (file-name-directory last-file))
3998 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3999 default
4000 (or last-file default))))
4001
4002(defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4003 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4004If variable `gnus-use-long-file-name' is non-nil, it is
2ff9f5b4 4005~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
eec82323
LMI
4006 (let ((default
4007 (expand-file-name
4008 (concat (if (gnus-use-long-file-name 'not-save)
4009 newsgroup
4010 (gnus-newsgroup-directory-form newsgroup))
4011 "/" (int-to-string (mail-header-number headers)))
4012 gnus-article-save-directory)))
4013 (if (and last-file
4014 (string-equal (file-name-directory default)
4015 (file-name-directory last-file))
4016 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4017 default
4018 (or last-file default))))
4019
eec82323
LMI
4020(defun gnus-plain-save-name (newsgroup headers &optional last-file)
4021 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4022If variable `gnus-use-long-file-name' is non-nil, it is
4023~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4024 (or last-file
4025 (expand-file-name
4026 (if (gnus-use-long-file-name 'not-save)
4027 newsgroup
23f87bed
MB
4028 (file-relative-name
4029 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4030 default-directory))
eec82323
LMI
4031 gnus-article-save-directory)))
4032
23f87bed
MB
4033(defun gnus-sender-save-name (newsgroup headers &optional last-file)
4034 "Generate file name from sender."
4035 (let ((from (mail-header-from headers)))
4036 (expand-file-name
4037 (if (and from (string-match "\\([^ <]+\\)@" from))
4038 (match-string 1 from)
4039 "nobody")
4040 gnus-article-save-directory)))
4041
4042(defun article-verify-x-pgp-sig ()
4043 "Verify X-PGP-Sig."
bbbe940b 4044 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
23f87bed
MB
4045 (interactive)
4046 (if (gnus-buffer-live-p gnus-original-article-buffer)
4047 (let ((sig (with-current-buffer gnus-original-article-buffer
4048 (gnus-fetch-field "X-PGP-Sig")))
4049 items info headers)
4050 (when (and sig
4051 mml2015-use
4052 (mml2015-clear-verify-function))
4053 (with-temp-buffer
4054 (insert-buffer-substring gnus-original-article-buffer)
4055 (setq items (split-string sig))
4056 (message-narrow-to-head)
4057 (let ((inhibit-point-motion-hooks t)
4058 (case-fold-search t))
4059 ;; Don't verify multiple headers.
4060 (setq headers (mapconcat (lambda (header)
4061 (concat header ": "
4062 (mail-fetch-field header)
4063 "\n"))
4064 (split-string (nth 1 items) ",") "")))
4065 (delete-region (point-min) (point-max))
4066 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4067 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4068 (insert headers)
4069 (widen)
4070 (forward-line)
4071 (while (not (eobp))
4072 (if (looking-at "^-")
4073 (insert "- "))
4074 (forward-line))
4075 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4076 (insert "Version: " (car items) "\n\n")
4077 (insert (mapconcat 'identity (cddr items) "\n"))
4078 (insert "\n-----END PGP SIGNATURE-----\n")
4079 (let ((mm-security-handle (list (format "multipart/signed"))))
4080 (mml2015-clean-buffer)
4081 (let ((coding-system-for-write (or gnus-newsgroup-charset
4082 'iso-8859-1)))
4083 (funcall (mml2015-clear-verify-function)))
4084 (setq info
4085 (or (mm-handle-multipart-ctl-parameter
4086 mm-security-handle 'gnus-details)
4087 (mm-handle-multipart-ctl-parameter
4088 mm-security-handle 'gnus-info)))))
4089 (when info
4090 (let ((inhibit-read-only t) bface eface)
4091 (save-restriction
4092 (message-narrow-to-head)
4093 (goto-char (point-max))
4094 (forward-line -1)
01c52d31
MB
4095 (setq bface (get-text-property (point-at-bol) 'face)
4096 eface (get-text-property (1- (point-at-eol)) 'face))
23f87bed
MB
4097 (message-remove-header "X-Gnus-PGP-Verify")
4098 (if (re-search-forward "^X-PGP-Sig:" nil t)
4099 (forward-line)
4100 (goto-char (point-max)))
4101 (narrow-to-region (point) (point))
4102 (insert "X-Gnus-PGP-Verify: " info "\n")
4103 (goto-char (point-min))
4104 (forward-line)
4105 (while (not (eobp))
4106 (if (not (looking-at "^[ \t]"))
4107 (insert " "))
4108 (forward-line))
4109 ;; Do highlighting.
4110 (goto-char (point-min))
4111 (when (looking-at "\\([^:]+\\): *")
4112 (put-text-property (match-beginning 1) (1+ (match-end 1))
4113 'face bface)
4114 (put-text-property (match-end 0) (point-max)
4115 'face eface)))))))))
4116
4117(defun article-verify-cancel-lock ()
4118 "Verify Cancel-Lock header."
4119 (interactive)
4120 (if (gnus-buffer-live-p gnus-original-article-buffer)
4121 (canlock-verify gnus-original-article-buffer)))
4122
eec82323 4123(eval-and-compile
01c52d31 4124 (mapc
eec82323
LMI
4125 (lambda (func)
4126 (let (afunc gfunc)
4127 (if (consp func)
4128 (setq afunc (car func)
4129 gfunc (cdr func))
4130 (setq afunc func
4131 gfunc (intern (format "gnus-%s" func))))
16409b0b 4132 (defalias gfunc
23f87bed 4133 (when (fboundp afunc)
16409b0b
GM
4134 `(lambda (&optional interactive &rest args)
4135 ,(documentation afunc t)
4136 (interactive (list t))
80de1778 4137 (with-current-buffer gnus-article-buffer
16409b0b
GM
4138 (if interactive
4139 (call-interactively ',afunc)
4140 (apply ',afunc args))))))))
eec82323 4141 '(article-hide-headers
23f87bed
MB
4142 article-verify-x-pgp-sig
4143 article-verify-cancel-lock
eec82323
LMI
4144 article-hide-boring-headers
4145 article-treat-overstrike
01c52d31 4146 article-treat-ansi-sequences
16409b0b
GM
4147 article-fill-long-lines
4148 article-capitalize-sentences
eec82323 4149 article-remove-cr
23f87bed 4150 article-remove-leading-whitespace
eec82323 4151 article-display-x-face
23f87bed 4152 article-display-face
eec82323 4153 article-de-quoted-unreadable
16409b0b
GM
4154 article-de-base64-unreadable
4155 article-decode-HZ
4156 article-wash-html
23f87bed 4157 article-unsplit-urls
16409b0b 4158 article-hide-list-identifiers
16409b0b
GM
4159 article-strip-banner
4160 article-babel
eec82323
LMI
4161 article-hide-pem
4162 article-hide-signature
16409b0b 4163 article-strip-headers-in-body
eec82323
LMI
4164 article-remove-trailing-blank-lines
4165 article-strip-leading-blank-lines
4166 article-strip-multiple-blank-lines
4167 article-strip-leading-space
16409b0b 4168 article-strip-trailing-space
eec82323 4169 article-strip-blank-lines
6748645f 4170 article-strip-all-blank-lines
eec82323 4171 article-date-local
23f87bed 4172 article-date-english
6748645f 4173 article-date-iso8601
eec82323
LMI
4174 article-date-original
4175 article-date-ut
16409b0b
GM
4176 article-decode-mime-words
4177 article-decode-charset
4178 article-decode-encoded-words
eec82323
LMI
4179 article-date-user
4180 article-date-lapsed
4181 article-emphasize
6748645f 4182 article-treat-dumbquotes
16409b0b 4183 article-normalize-headers
01c52d31 4184 ;;(article-show-all . gnus-article-show-all-headers)
23f87bed 4185 )))
eec82323
LMI
4186\f
4187;;;
4188;;; Gnus article mode
4189;;;
4190
4191(put 'gnus-article-mode 'mode-class 'special)
4192
16409b0b
GM
4193(set-keymap-parent gnus-article-mode-map widget-keymap)
4194
a8151ef7
LMI
4195(gnus-define-keys gnus-article-mode-map
4196 " " gnus-article-goto-next-page
4197 "\177" gnus-article-goto-prev-page
4198 [delete] gnus-article-goto-prev-page
16409b0b 4199 [backspace] gnus-article-goto-prev-page
a8151ef7
LMI
4200 "\C-c^" gnus-article-refer-article
4201 "h" gnus-article-show-summary
4202 "s" gnus-article-show-summary
4203 "\C-c\C-m" gnus-article-mail
4204 "?" gnus-article-describe-briefly
16409b0b 4205 "e" gnus-summary-edit-article
a8151ef7
LMI
4206 "<" beginning-of-buffer
4207 ">" end-of-buffer
4208 "\C-c\C-i" gnus-info-find-node
4209 "\C-c\C-b" gnus-bug
23f87bed
MB
4210 "R" gnus-article-reply-with-original
4211 "F" gnus-article-followup-with-original
520aa572
SZ
4212 "\C-hk" gnus-article-describe-key
4213 "\C-hc" gnus-article-describe-key-briefly
0b6799c3 4214 "\C-hb" gnus-article-describe-bindings
a8151ef7
LMI
4215
4216 "\C-d" gnus-article-read-summary-keys
4217 "\M-*" gnus-article-read-summary-keys
4218 "\M-#" gnus-article-read-summary-keys
4219 "\M-^" gnus-article-read-summary-keys
4220 "\M-g" gnus-article-read-summary-keys)
4221
4222(substitute-key-definition
4223 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
eec82323 4224
95838435
MB
4225(gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4226 "W" gnus-article-wide-reply-with-original)
4227(if (featurep 'xemacs)
4228 (set-keymap-default-binding gnus-article-send-map
4229 'gnus-article-read-summary-send-keys)
4230 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4231
eec82323 4232(defun gnus-article-make-menu-bar ()
23f87bed
MB
4233 (unless (boundp 'gnus-article-commands-menu)
4234 (gnus-summary-make-menu-bar))
eec82323
LMI
4235 (gnus-turn-off-edit-menu 'article)
4236 (unless (boundp 'gnus-article-article-menu)
4237 (easy-menu-define
4238 gnus-article-article-menu gnus-article-mode-map ""
4239 '("Article"
4240 ["Scroll forwards" gnus-article-goto-next-page t]
4241 ["Scroll backwards" gnus-article-goto-prev-page t]
4242 ["Show summary" gnus-article-show-summary t]
4243 ["Fetch Message-ID at point" gnus-article-refer-article t]
6748645f
LMI
4244 ["Mail to address at point" gnus-article-mail t]
4245 ["Send a bug report" gnus-bug t]))
eec82323
LMI
4246
4247 (easy-menu-define
4248 gnus-article-treatment-menu gnus-article-mode-map ""
bb367cba 4249 ;; Fixme: this should use :active (and maybe :visible).
eec82323
LMI
4250 '("Treatment"
4251 ["Hide headers" gnus-article-hide-headers t]
4252 ["Hide signature" gnus-article-hide-signature t]
4253 ["Hide citation" gnus-article-hide-citation t]
4254 ["Treat overstrike" gnus-article-treat-overstrike t]
01c52d31 4255 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
eec82323 4256 ["Remove carriage return" gnus-article-remove-cr t]
23f87bed 4257 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
16409b0b
GM
4258 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4259 ["Remove base64" gnus-article-de-base64-unreadable t]
4260 ["Treat html" gnus-article-wash-html t]
23f87bed 4261 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
16409b0b 4262 ["Decode HZ" gnus-article-decode-HZ t]))
eec82323 4263
6748645f 4264 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
eec82323 4265
23f87bed 4266 ;; Note "Post" menu is defined in gnus-sum.el for consistency
eec82323 4267
6748645f 4268 (gnus-run-hooks 'gnus-article-menu-hook)))
eec82323
LMI
4269
4270(defun gnus-article-mode ()
4271 "Major mode for displaying an article.
4272
4273All normal editing commands are switched off.
4274
4275The following commands are available in addition to all summary mode
4276commands:
4277\\<gnus-article-mode-map>
4278\\[gnus-article-next-page]\t Scroll the article one page forwards
4279\\[gnus-article-prev-page]\t Scroll the article one page backwards
4280\\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4281\\[gnus-article-show-summary]\t Display the summary buffer
4282\\[gnus-article-mail]\t Send a reply to the address near point
4283\\[gnus-article-describe-briefly]\t Describe the current mode briefly
4284\\[gnus-info-find-node]\t Go to the Gnus info node"
4285 (interactive)
0eb586fc 4286 (kill-all-local-variables)
eec82323
LMI
4287 (gnus-simplify-mode-line)
4288 (setq mode-name "Article")
4289 (setq major-mode 'gnus-article-mode)
4290 (make-local-variable 'minor-mode-alist)
eec82323 4291 (use-local-map gnus-article-mode-map)
1653df0f 4292 (when (gnus-visual-p 'article-menu 'menu)
23f87bed
MB
4293 (gnus-article-make-menu-bar)
4294 (when gnus-summary-tool-bar-map
4295 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
eec82323
LMI
4296 (gnus-update-format-specifications nil 'article-mode)
4297 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
23f87bed 4298 (set (make-local-variable 'gnus-page-broken) nil)
6748645f
LMI
4299 (make-local-variable 'gnus-button-marker-list)
4300 (make-local-variable 'gnus-article-current-summary)
16409b0b
GM
4301 (make-local-variable 'gnus-article-mime-handles)
4302 (make-local-variable 'gnus-article-decoded-p)
4303 (make-local-variable 'gnus-article-mime-handle-alist)
4304 (make-local-variable 'gnus-article-wash-types)
23f87bed
MB
4305 (make-local-variable 'gnus-article-image-alist)
4306 (make-local-variable 'gnus-article-charset)
4307 (make-local-variable 'gnus-article-ignored-charsets)
524705ae
MB
4308 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4309 ;; face.
fc1c32c1 4310 (set (make-local-variable 'nobreak-char-display) nil)
e4a89ccf 4311 (setq cursor-in-non-selected-windows nil)
01c52d31 4312 (setq truncate-lines gnus-article-truncate-lines)
eec82323 4313 (gnus-set-default-directory)
16409b0b 4314 (buffer-disable-undo)
01c52d31
MB
4315 (setq buffer-read-only t
4316 show-trailing-whitespace nil)
eec82323 4317 (set-syntax-table gnus-article-mode-syntax-table)
16409b0b 4318 (mm-enable-multibyte)
cfcd5c91 4319 (gnus-run-mode-hooks 'gnus-article-mode-hook))
eec82323 4320
676c1893 4321(defvar gnus-button-marker-list nil
01c52d31
MB
4322 "Regexp matching any of the regexps from `gnus-button-alist'.
4323Internal variable.")
676c1893 4324
eec82323
LMI
4325(defun gnus-article-setup-buffer ()
4326 "Initialize the article buffer."
4327 (let* ((name (if gnus-single-article-buffer "*Article*"
4328 (concat "*Article " gnus-newsgroup-name "*")))
4329 (original
4330 (progn (string-match "\\*Article" name)
4331 (concat " *Original Article"
4332 (substring name (match-end 0))))))
4333 (setq gnus-article-buffer name)
4334 (setq gnus-original-article-buffer original)
16409b0b 4335 (setq gnus-article-mime-handle-alist nil)
01c52d31
MB
4336 (with-current-buffer gnus-summary-buffer
4337 ;; This might be a variable local to the summary buffer.
4338 (unless gnus-single-article-buffer
eec82323
LMI
4339 (setq gnus-article-buffer name)
4340 (setq gnus-original-article-buffer original)
4341 (gnus-set-global-variables)))
16409b0b 4342 (gnus-article-setup-highlight-words)
eec82323 4343 ;; Init original article buffer.
80de1778 4344 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
16409b0b 4345 (mm-enable-multibyte)
eec82323 4346 (setq major-mode 'gnus-original-article-mode)
eec82323 4347 (make-local-variable 'gnus-original-article))
aba1948a
MB
4348 (if (and (get-buffer name)
4349 (with-current-buffer name
4350 (if gnus-article-edit-mode
4351 (if (y-or-n-p "Article mode edit in progress; discard? ")
4352 (progn
4353 (set-buffer-modified-p nil)
4354 (gnus-kill-buffer name)
4355 (message "")
4356 nil)
4357 (error "Action aborted"))
4358 t)))
80de1778 4359 (with-current-buffer name
23f87bed 4360 (set (make-local-variable 'gnus-article-edit-mode) nil)
16409b0b
GM
4361 (when gnus-article-mime-handles
4362 (mm-destroy-parts gnus-article-mime-handles)
4363 (setq gnus-article-mime-handles nil))
4364 ;; Set it to nil in article-buffer!
a1506d29 4365 (setq gnus-article-mime-handle-alist nil)
16409b0b 4366 (buffer-disable-undo)
eec82323 4367 (setq buffer-read-only t)
23f87bed
MB
4368 ;; This list just keeps growing if we don't reset it.
4369 (setq gnus-button-marker-list nil)
eec82323
LMI
4370 (unless (eq major-mode 'gnus-article-mode)
4371 (gnus-article-mode))
4372 (current-buffer))
80de1778 4373 (with-current-buffer (gnus-get-buffer-create name)
eec82323
LMI
4374 (gnus-article-mode)
4375 (make-local-variable 'gnus-summary-buffer)
01c52d31
MB
4376 (setq gnus-summary-buffer
4377 (gnus-summary-buffer-name gnus-newsgroup-name))
16409b0b 4378 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
4379 (current-buffer)))))
4380
4381;; Set article window start at LINE, where LINE is the number of lines
4382;; from the head of the article.
4383(defun gnus-article-set-window-start (&optional line)
01c52d31
MB
4384 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4385 (when article-window
4386 (set-window-start
4387 article-window
80de1778 4388 (with-current-buffer gnus-article-buffer
01c52d31
MB
4389 (goto-char (point-min))
4390 (if (not line)
4391 (point-min)
4392 (gnus-message 6 "Moved to bookmark")
4393 (search-forward "\n\n" nil t)
4394 (forward-line line)
4395 (point)))))))
eec82323
LMI
4396
4397(defun gnus-article-prepare (article &optional all-headers header)
4398 "Prepare ARTICLE in article mode buffer.
4399ARTICLE should either be an article number or a Message-ID.
4400If ARTICLE is an id, HEADER should be the article headers.
4401If ALL-HEADERS is non-nil, no headers are hidden."
4402 (save-excursion
4403 ;; Make sure we start in a summary buffer.
4404 (unless (eq major-mode 'gnus-summary-mode)
4405 (set-buffer gnus-summary-buffer))
4406 (setq gnus-summary-buffer (current-buffer))
eec82323
LMI
4407 (let* ((gnus-article (if header (mail-header-number header) article))
4408 (summary-buffer (current-buffer))
6748645f 4409 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
eec82323
LMI
4410 (group gnus-newsgroup-name)
4411 result)
4412 (save-excursion
4413 (gnus-article-setup-buffer)
4414 (set-buffer gnus-article-buffer)
4415 ;; Deactivate active regions.
4416 (when (and (boundp 'transient-mark-mode)
4417 transient-mark-mode)
4418 (setq mark-active nil))
4e7d0221 4419 (if (not (setq result (let ((inhibit-read-only t))
eec82323
LMI
4420 (gnus-request-article-this-buffer
4421 article group))))
4422 ;; There is no such article.
4423 (save-excursion
4424 (when (and (numberp article)
4425 (not (memq article gnus-newsgroup-sparse)))
4426 (setq gnus-article-current
4427 (cons gnus-newsgroup-name article))
4428 (set-buffer gnus-summary-buffer)
4429 (setq gnus-current-article article)
23f87bed
MB
4430 (if (and (memq article gnus-newsgroup-undownloaded)
4431 (not (gnus-online (gnus-find-method-for-group
4432 gnus-newsgroup-name))))
6748645f
LMI
4433 (progn
4434 (gnus-summary-set-agent-mark article)
4435 (message "Message marked for downloading"))
4436 (gnus-summary-mark-article article gnus-canceled-mark)
4437 (unless (memq article gnus-newsgroup-sparse)
16409b0b 4438 (gnus-error 1 "No such article (may have expired or been canceled)")))))
6748645f
LMI
4439 (if (or (eq result 'pseudo)
4440 (eq result 'nneething))
eec82323 4441 (progn
80de1778 4442 (with-current-buffer summary-buffer
6748645f 4443 (push article gnus-newsgroup-history)
eec82323 4444 (setq gnus-last-article gnus-current-article
eec82323
LMI
4445 gnus-current-article 0
4446 gnus-current-headers nil
4447 gnus-article-current nil)
4448 (if (eq result 'nneething)
4449 (gnus-configure-windows 'summary)
4450 (gnus-configure-windows 'article))
4451 (gnus-set-global-variables))
16409b0b
GM
4452 (let ((gnus-article-mime-handle-alist-1
4453 gnus-article-mime-handle-alist))
4454 (gnus-set-mode-line 'article)))
eec82323
LMI
4455 ;; The result from the `request' was an actual article -
4456 ;; or at least some text that is now displayed in the
4457 ;; article buffer.
4458 (when (and (numberp article)
4459 (not (eq article gnus-current-article)))
4460 ;; Seems like a new article has been selected.
4461 ;; `gnus-current-article' must be an article number.
80de1778 4462 (with-current-buffer summary-buffer
6748645f 4463 (push article gnus-newsgroup-history)
eec82323 4464 (setq gnus-last-article gnus-current-article
eec82323
LMI
4465 gnus-current-article article
4466 gnus-current-headers
4467 (gnus-summary-article-header gnus-current-article)
4468 gnus-article-current
4469 (cons gnus-newsgroup-name gnus-current-article))
4470 (unless (vectorp gnus-current-headers)
4471 (setq gnus-current-headers nil))
6748645f
LMI
4472 (gnus-summary-goto-subject gnus-current-article)
4473 (when (gnus-summary-show-thread)
4474 ;; If the summary buffer really was folded, the
4475 ;; previous goto may not actually have gone to
4476 ;; the right article, but the thread root instead.
4477 ;; So we go again.
4478 (gnus-summary-goto-subject gnus-current-article))
4479 (gnus-run-hooks 'gnus-mark-article-hook)
eec82323
LMI
4480 (gnus-set-mode-line 'summary)
4481 (when (gnus-visual-p 'article-highlight 'highlight)
6748645f 4482 (gnus-run-hooks 'gnus-visual-mark-article-hook))
eec82323 4483 ;; Set the global newsgroup variables here.
eec82323
LMI
4484 (gnus-set-global-variables)
4485 (setq gnus-have-all-headers
6748645f 4486 (or all-headers gnus-show-all-headers))))
e0bad764
DL
4487 (save-excursion
4488 (gnus-configure-windows 'article))
eec82323
LMI
4489 (when (or (numberp article)
4490 (stringp article))
16409b0b 4491 (gnus-article-prepare-display)
eec82323
LMI
4492 ;; Do page break.
4493 (goto-char (point-min))
23f87bed
MB
4494 (when gnus-break-pages
4495 (gnus-narrow-to-page)))
16409b0b
GM
4496 (let ((gnus-article-mime-handle-alist-1
4497 gnus-article-mime-handle-alist))
4498 (gnus-set-mode-line 'article))
4499 (article-goto-body)
23f87bed
MB
4500 (unless (bobp)
4501 (forward-line -1))
6748645f 4502 (set-window-point (get-buffer-window (current-buffer)) (point))
16409b0b 4503 (gnus-configure-windows 'article)
eec82323
LMI
4504 t))))))
4505
16409b0b
GM
4506;;;###autoload
4507(defun gnus-article-prepare-display ()
4508 "Make the current buffer look like a nice article."
4509 ;; Hooks for getting information from the article.
4510 ;; This hook must be called before being narrowed.
4511 (let ((gnus-article-buffer (current-buffer))
23f87bed
MB
4512 buffer-read-only
4513 (inhibit-read-only t))
16409b0b
GM
4514 (unless (eq major-mode 'gnus-article-mode)
4515 (gnus-article-mode))
4516 (setq buffer-read-only nil
23f87bed
MB
4517 gnus-article-wash-types nil
4518 gnus-article-image-alist nil)
16409b0b
GM
4519 (gnus-run-hooks 'gnus-tmp-internal-hook)
4520 (when gnus-display-mime-function
4521 (funcall gnus-display-mime-function))
4522 (gnus-run-hooks 'gnus-article-prepare-hook)))
4523
01c52d31
MB
4524;;;
4525;;; Gnus Sticky Article Mode
4526;;;
4527
4528(define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4529 "Mode for sticky articles."
4530 ;; Release bindings that won't work.
4531 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4532 gnus-sticky-article-mode-map)
4533 (substitute-key-definition 'gnus-article-refer-article 'undefined
4534 gnus-sticky-article-mode-map)
4535 (dolist (k '("e" "h" "s" "F" "R"))
4536 (define-key gnus-sticky-article-mode-map k nil))
4537 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4538 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4539 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4540 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4541
4542(defun gnus-sticky-article (arg)
4543 "Make the current article sticky.
4544If a prefix ARG is given, ask for a name for this sticky article buffer."
4545 (interactive "P")
4546 (gnus-summary-show-thread)
4547 (gnus-summary-select-article nil nil 'pseudo)
4548 (let (new-art-buf-name)
4549 (gnus-eval-in-buffer-window gnus-article-buffer
4550 (setq new-art-buf-name
4551 (concat
4552 "*Sticky Article: "
4553 (if arg
4554 (read-from-minibuffer "Sticky article buffer name: ")
4555 (gnus-with-article-headers
4556 (gnus-article-goto-header "subject")
4557 (setq new-art-buf-name
4558 (buffer-substring-no-properties
4559 (line-beginning-position) (line-end-position)))
4560 (goto-char (point-min))
4561 (gnus-article-goto-header "from")
4562 (setq new-art-buf-name
4563 (concat
4564 new-art-buf-name ", "
4565 (buffer-substring-no-properties
4566 (line-beginning-position) (line-end-position))))
4567 (goto-char (point-min))
4568 (gnus-article-goto-header "date")
4569 (setq new-art-buf-name
4570 (concat
4571 new-art-buf-name ", "
4572 (buffer-substring-no-properties
4573 (line-beginning-position) (line-end-position))))))
4574 "*"))
4575 (if (and (gnus-buffer-live-p new-art-buf-name)
4576 (with-current-buffer new-art-buf-name
4577 (eq major-mode 'gnus-sticky-article-mode)))
4578 (switch-to-buffer new-art-buf-name)
4579 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4580 (gnus-sticky-article-mode))
4581 (setq gnus-article-buffer new-art-buf-name))
4582 (gnus-summary-recenter)
4583 (gnus-summary-position-point))
4584
4585(defun gnus-kill-sticky-article-buffer (&optional buffer)
4586 "Kill the given sticky article BUFFER.
4587If none is given, assume the current buffer and kill it if it has
4588`gnus-sticky-article-mode'."
4589 (interactive)
4590 (unless buffer
4591 (setq buffer (current-buffer)))
4592 (with-current-buffer buffer
4593 (when (eq major-mode 'gnus-sticky-article-mode)
4594 (gnus-kill-buffer buffer))))
4595
4596(defun gnus-kill-sticky-article-buffers (arg)
4597 "Kill all sticky article buffers.
4598If a prefix ARG is given, ask for confirmation."
4599 (interactive "P")
4600 (dolist (buf (gnus-buffers))
4601 (with-current-buffer buf
4602 (when (eq major-mode 'gnus-sticky-article-mode)
4603 (if (not arg)
4604 (gnus-kill-buffer buf)
4605 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4606 (gnus-kill-buffer buf)))))))
4607
16409b0b
GM
4608;;;
4609;;; Gnus MIME viewing functions
4610;;;
4611
4612(defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
23f87bed
MB
4613 "Format of the MIME buttons.
4614
4615Valid specifiers include:
16409b0b
GM
4616%t The MIME type
4617%T MIME type, along with additional info
4618%n The `name' parameter
4619%d The description, if any
4620%l The length of the encoded part
4621%p The part identifier number
23f87bed
MB
4622%e Dots if the part isn't displayed
4623
4624General format specifiers can also be used. See Info node
4625`(gnus)Formatting Variables'.")
16409b0b
GM
4626
4627(defvar gnus-mime-button-line-format-alist
4628 '((?t gnus-tmp-type ?s)
4629 (?T gnus-tmp-type-long ?s)
4630 (?n gnus-tmp-name ?s)
4631 (?d gnus-tmp-description ?s)
4632 (?p gnus-tmp-id ?s)
4633 (?l gnus-tmp-length ?d)
4634 (?e gnus-tmp-dots ?s)))
4635
4636(defvar gnus-mime-button-commands
4637 '((gnus-article-press-button "\r" "Toggle Display")
4638 (gnus-mime-view-part "v" "View Interactively...")
4639 (gnus-mime-view-part-as-type "t" "View As Type...")
23f87bed 4640 (gnus-mime-view-part-as-charset "C" "View As charset...")
16409b0b 4641 (gnus-mime-save-part "o" "Save...")
23f87bed 4642 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
01c52d31 4643 (gnus-mime-replace-part "r" "Replace part")
23f87bed 4644 (gnus-mime-delete-part "d" "Delete part")
16409b0b
GM
4645 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4646 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
01c52d31 4647 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
23f87bed
MB
4648 (gnus-mime-view-part-externally "e" "View Externally")
4649 (gnus-mime-print-part "p" "Print")
e0bad764 4650 (gnus-mime-pipe-part "|" "Pipe To Command...")
23f87bed 4651 (gnus-mime-action-on-part "." "Take action on the part...")))
16409b0b
GM
4652
4653(defun gnus-article-mime-part-status ()
4654 (if gnus-article-mime-handle-alist-1
23f87bed
MB
4655 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4656 " (1 part)"
4657 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
16409b0b
GM
4658 ""))
4659
4660(defvar gnus-mime-button-map
4661 (let ((map (make-sparse-keymap)))
16409b0b
GM
4662 (define-key map gnus-mouse-2 'gnus-article-push-button)
4663 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4664 (dolist (c gnus-mime-button-commands)
4665 (define-key map (cadr c) (car c)))
4666 map))
4667
23f87bed
MB
4668(easy-menu-define
4669 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4670 `("MIME Part"
4671 ,@(mapcar (lambda (c)
01c52d31 4672 (vector (caddr c) (car c) :active t))
23f87bed
MB
4673 gnus-mime-button-commands)))
4674
23f87bed
MB
4675(defun gnus-mime-button-menu (event prefix)
4676 "Construct a context-sensitive menu of MIME commands."
4677 (interactive "e\nP")
4678 (save-window-excursion
4679 (let ((pos (event-start event)))
4680 (select-window (posn-window pos))
4681 (goto-char (posn-point pos))
4682 (gnus-article-check-buffer)
4683 (popup-menu gnus-mime-button-menu nil prefix))))
16409b0b
GM
4684
4685(defun gnus-mime-view-all-parts (&optional handles)
4686 "View all the MIME parts."
4687 (interactive)
01c52d31 4688 (with-current-buffer gnus-article-buffer
16409b0b
GM
4689 (let ((handles (or handles gnus-article-mime-handles))
4690 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4691 (mail-parse-ignored-charsets
23f87bed
MB
4692 (with-current-buffer gnus-summary-buffer
4693 gnus-newsgroup-ignored-charsets)))
4694 (when handles
4695 (mm-remove-parts handles)
4696 (goto-char (point-min))
4697 (or (search-forward "\n\n") (goto-char (point-max)))
4698 (let ((inhibit-read-only t))
4699 (delete-region (point) (point-max))
4700 (mm-display-parts handles))))))
4701
01c52d31
MB
4702(defun gnus-article-jump-to-part (n)
4703 "Jump to MIME part N."
4704 (interactive "P")
4705 (pop-to-buffer gnus-article-buffer)
4706 ;; FIXME: why is it necessary?
4707 (sit-for 0)
4708 (let ((parts (length gnus-article-mime-handle-alist)))
4709 (or n (setq n
4710 (string-to-number
4711 (read-string ;; Emacs 21 doesn't have `read-number'.
4712 (format "Jump to part (2..%s): " parts)))))
4713 (unless (and (integerp n) (<= n parts) (>= n 1))
4714 (setq n
4715 (progn
4716 (gnus-message 7 "Invalid part `%s', using %s instead."
4717 n parts)
4718 parts)))
4719 (gnus-message 9 "Jumping to part %s." n)
4720 (cond ((>= gnus-auto-select-part 1)
4721 (while (and (<= n parts)
4722 (not (gnus-article-goto-part n)))
4723 (setq n (1+ n))))
4724 ((< gnus-auto-select-part 0)
4725 (while (and (>= n 1)
4726 (not (gnus-article-goto-part n)))
4727 (setq n (1- n))))
4728 (t
4729 (gnus-article-goto-part n)))))
4730
4731(eval-when-compile
4732 (defsubst gnus-article-edit-part (handles &optional current-id)
4733 "Edit an article in order to delete a mime part.
4734This function is exclusively used by `gnus-mime-save-part-and-strip'
4735and `gnus-mime-delete-part', and not provided at run-time normally."
4736 (gnus-article-edit-article
4737 `(lambda ()
4738 (buffer-disable-undo)
4739 (erase-buffer)
4740 (let ((mail-parse-charset (or gnus-article-charset
4741 ',gnus-newsgroup-charset))
4742 (mail-parse-ignored-charsets
4743 (or gnus-article-ignored-charsets
4744 ',gnus-newsgroup-ignored-charsets))
4745 (mbl mml-buffer-list))
4746 (setq mml-buffer-list nil)
4747 (insert-buffer-substring gnus-original-article-buffer)
4748 (mime-to-mml ',handles)
4749 (setq gnus-article-mime-handles nil)
4750 (let ((mbl1 mml-buffer-list))
4751 (setq mml-buffer-list mbl)
4752 (set (make-local-variable 'mml-buffer-list) mbl1))
4753 (gnus-make-local-hook 'kill-buffer-hook)
4754 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4755 `(lambda (no-highlight)
4756 (let ((mail-parse-charset (or gnus-article-charset
4757 ',gnus-newsgroup-charset))
4758 (message-options message-options)
4759 (message-options-set-recipient)
4760 (mail-parse-ignored-charsets
4761 (or gnus-article-ignored-charsets
4762 ',gnus-newsgroup-ignored-charsets)))
4763 (mml-to-mime)
4764 (mml-destroy-buffers)
4765 (remove-hook 'kill-buffer-hook
4766 'mml-destroy-buffers t)
4767 (kill-local-variable 'mml-buffer-list))
4768 (gnus-summary-edit-article-done
4769 ,(or (mail-header-references gnus-current-headers) "")
4770 ,(gnus-group-read-only-p)
4771 ,gnus-summary-buffer no-highlight))
4772 t)
4773 (gnus-article-edit-done)
4774 (gnus-summary-expand-window)
4775 (gnus-summary-show-article)
4776 (when (and current-id (integerp gnus-auto-select-part))
4777 (gnus-article-jump-to-part
4778 (if (text-property-any (point-min) (point-max)
4779 'gnus-part (+ current-id gnus-auto-select-part))
4780 (+ current-id gnus-auto-select-part)
4781 (with-current-buffer gnus-article-buffer
4782 (length gnus-article-mime-handle-alist)))))))
4783
4784(defun gnus-mime-replace-part (file)
4785 "Replace MIME part under point with an external body."
4786 ;; Useful if file has already been saved to disk
4787 (interactive
4788 (list
4789 (mm-with-multibyte
4790 (read-file-name "Replace MIME part with file: "
4791 (or mm-default-directory default-directory)
4792 nil nil))))
4793 (gnus-mime-save-part-and-strip file))
4794
4795(defun gnus-mime-save-part-and-strip (&optional file)
4796 "Save the MIME part under point then replace it with an external body.
4797If FILE is given, use it for the external part."
23f87bed
MB
4798 (interactive)
4799 (gnus-article-check-buffer)
4800 (when (gnus-group-read-only-p)
4801 (error "The current group does not support deleting of parts"))
4802 (when (mm-complicated-handles gnus-article-mime-handles)
4803 (error "\
4804The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4805 (let* ((data (get-text-property (point) 'gnus-data))
4806 (id (get-text-property (point) 'gnus-part))
4807 param
4808 (handles gnus-article-mime-handles))
4809 (unless file
4810 (setq file
4811 (and data (mm-save-part data "Delete MIME part and save to: "))))
4812 (when file
4813 (with-current-buffer (mm-handle-buffer data)
4814 (erase-buffer)
4815 (insert "Content-Type: " (mm-handle-media-type data))
4816 (mml-insert-parameter-string (cdr (mm-handle-type data))
4817 '(charset))
4818 ;; Add a filename for the sake of saving the part again.
4819 (mml-insert-parameter
4820 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4821 (insert "\n")
4822 (insert "Content-ID: " (message-make-message-id) "\n")
4823 (insert "Content-Transfer-Encoding: binary\n")
4824 (insert "\n"))
4825 (setcdr data
4826 (cdr (mm-make-handle nil
4827 `("message/external-body"
4828 (access-type . "LOCAL-FILE")
4829 (name . ,file)))))
4830 ;; (set-buffer gnus-summary-buffer)
4831 (gnus-article-edit-part handles id))))
4832
4833;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4834;; parts...>') but with stripping would be nice.
23f87bed
MB
4835
4836(defun gnus-mime-delete-part ()
4837 "Delete the MIME part under point.
4838Replace it with some information about the removed part."
4839 (interactive)
4840 (gnus-article-check-buffer)
4841 (when (gnus-group-read-only-p)
4842 (error "The current group does not support deleting of parts"))
4843 (when (mm-complicated-handles gnus-article-mime-handles)
4844 (error "\
4845The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4846 (when (or gnus-expert-user
4847 (gnus-yes-or-no-p "\
4848Deleting parts may malfunction or destroy the article; continue? "))
23f87bed 4849 (let* ((data (get-text-property (point) 'gnus-data))
01c52d31 4850 (id (get-text-property (point) 'gnus-part))
23f87bed
MB
4851 (handles gnus-article-mime-handles)
4852 (none "(none)")
4853 (description
bbbe940b
MB
4854 (let ((desc (mm-handle-description data)))
4855 (when desc
4856 (mail-decode-encoded-word-string desc))))
23f87bed
MB
4857 (filename
4858 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4859 none))
4860 (type (mm-handle-media-type data)))
4861 (unless data
4862 (error "No MIME part under point"))
4863 (with-current-buffer (mm-handle-buffer data)
4864 (let ((bsize (format "%s" (buffer-size))))
4865 (erase-buffer)
4866 (insert
4867 (concat
4868 ",----\n"
4869 "| The following attachment has been deleted:\n"
4870 "|\n"
4871 "| Type: " type "\n"
4872 "| Filename: " filename "\n"
4873 "| Size (encoded): " bsize " Byte\n"
bbbe940b
MB
4874 (when description
4875 (concat "| Description: " description "\n"))
23f87bed
MB
4876 "`----\n"))
4877 (setcdr data
4878 (cdr (mm-make-handle
4879 nil `("text/plain") nil nil
4880 (list "attachment")
4881 (format "Deleted attachment (%s bytes)" bsize))))))
01c52d31
MB
4882 ;; (set-buffer gnus-summary-buffer)
4883 (gnus-article-edit-part handles id))))
16409b0b
GM
4884
4885(defun gnus-mime-save-part ()
4886 "Save the MIME part under point."
4887 (interactive)
4888 (gnus-article-check-buffer)
4889 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4890 (when data
4891 (mm-save-part data))))
16409b0b
GM
4892
4893(defun gnus-mime-pipe-part ()
4894 "Pipe the MIME part under point to a process."
4895 (interactive)
4896 (gnus-article-check-buffer)
4897 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4898 (when data
4899 (mm-pipe-part data))))
16409b0b
GM
4900
4901(defun gnus-mime-view-part ()
4902 "Interactively choose a viewing method for the MIME part under point."
4903 (interactive)
4904 (gnus-article-check-buffer)
4905 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4906 (when data
4907 (setq gnus-article-mime-handles
4908 (mm-merge-handles
4909 gnus-article-mime-handles (setq data (copy-sequence data))))
4910 (mm-interactively-view-part data))))
16409b0b
GM
4911
4912(defun gnus-mime-view-part-as-type-internal ()
4913 (gnus-article-check-buffer)
54e573e6
MB
4914 (let* ((handle (get-text-property (point) 'gnus-data))
4915 (name (or
4916 ;; Content-Type: foo/bar; name=...
4917 (mail-content-type-get (mm-handle-type handle) 'name)
4918 ;; Content-Disposition: attachment; filename=...
4919 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
16409b0b 4920 (def-type (and name (mm-default-file-encoding name))))
01c52d31
MB
4921 (or (and def-type (cons def-type 0))
4922 (and handle
4923 (equal (mm-handle-media-supertype handle) "text")
4924 '("text/plain" . 0))
4925 '("application/octet-stream" . 0))))
16409b0b 4926
54e573e6
MB
4927(defun gnus-mime-view-part-as-type (&optional mime-type pred)
4928 "Choose a MIME media type, and view the part as such.
4929If non-nil, PRED is a predicate to use during completion to limit the
4930available media-types."
23f87bed
MB
4931 (interactive)
4932 (unless mime-type
54e573e6
MB
4933 (setq mime-type
4934 (let ((default (gnus-mime-view-part-as-type-internal)))
4935 (completing-read
4936 (format "View as MIME type (default %s): "
4937 (car default))
4938 (mapcar #'list (mailcap-mime-types))
4939 pred nil nil nil
4940 (car default)))))
16409b0b
GM
4941 (gnus-article-check-buffer)
4942 (let ((handle (get-text-property (point) 'gnus-data)))
23f87bed 4943 (when handle
531bedc3
MB
4944 (when (equal (mm-handle-media-type handle) "message/external-body")
4945 (unless (mm-handle-cache handle)
4946 (mm-extern-cache-contents handle))
4947 (setq handle (mm-handle-cache handle)))
23f87bed
MB
4948 (setq handle
4949 (mm-make-handle (mm-handle-buffer handle)
4950 (cons mime-type (cdr (mm-handle-type handle)))
4951 (mm-handle-encoding handle)
4952 (mm-handle-undisplayer handle)
4953 (mm-handle-disposition handle)
4954 (mm-handle-description handle)
4955 nil
4956 (mm-handle-id handle)))
4957 (setq gnus-article-mime-handles
4958 (mm-merge-handles gnus-article-mime-handles handle))
01c52d31
MB
4959 (when (mm-handle-displayed-p handle)
4960 (mm-remove-part handle))
23f87bed
MB
4961 (gnus-mm-display-part handle))))
4962
01c52d31 4963(defun gnus-mime-copy-part (&optional handle arg)
23f87bed
MB
4964 "Put the MIME part under point into a new buffer.
4965If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4966are decompressed."
01c52d31 4967 (interactive (list nil current-prefix-arg))
16409b0b 4968 (gnus-article-check-buffer)
01c52d31
MB
4969 (unless handle
4970 (setq handle (get-text-property (point) 'gnus-data)))
4971 (when handle
4972 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4973 'name)
4974 (mail-content-type-get (mm-handle-disposition handle)
4975 'filename)))
4976 contents dont-decode charset coding-system)
4977 (mm-with-unibyte-buffer
4978 (mm-insert-part handle)
4979 (setq contents (or (condition-case nil
4980 (mm-decompress-buffer filename nil 'sig)
4981 (error
4982 (setq dont-decode t)
4983 nil))
4984 (buffer-string))))
4985 (setq filename (cond (filename (file-name-nondirectory filename))
4986 (dont-decode "*raw data*")
4987 (t "*decoded*")))
4988 (cond
4989 (dont-decode)
4990 ((not arg)
4991 (unless (setq charset (mail-content-type-get
4992 (mm-handle-type handle) 'charset))
4993 (unless (setq coding-system (mm-with-unibyte-buffer
4994 (insert contents)
4995 (mm-find-buffer-file-coding-system)))
4996 (setq charset gnus-newsgroup-charset))))
4997 ((numberp arg)
4998 (setq charset (or (cdr (assq arg
4999 gnus-summary-show-article-charset-alist))
5000 (mm-read-coding-system "Charset: ")))))
5001 (switch-to-buffer (generate-new-buffer filename))
5002 (if (or coding-system
5003 (and charset
5004 (setq coding-system (mm-charset-to-coding-system charset))
5005 (not (eq charset 'ascii))))
5006 (progn
5007 (mm-enable-multibyte)
5008 (insert (mm-decode-coding-string contents coding-system))
5009 (setq buffer-file-coding-system
5010 (if (boundp 'last-coding-system-used)
5011 (symbol-value 'last-coding-system-used)
5012 coding-system)))
5013 (mm-disable-multibyte)
5014 (insert contents)
5015 (setq buffer-file-coding-system mm-binary-coding-system))
23f87bed
MB
5016 ;; We do it this way to make `normal-mode' set the appropriate mode.
5017 (unwind-protect
5018 (progn
01c52d31 5019 (setq buffer-file-name (expand-file-name filename))
23f87bed
MB
5020 (normal-mode))
5021 (setq buffer-file-name nil))
5022 (goto-char (point-min)))))
5023
5024(defun gnus-mime-print-part (&optional handle filename)
5025 "Print the MIME part under point."
5026 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5027 (gnus-article-check-buffer)
5028 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5029 (contents (and handle (mm-get-part handle)))
5030 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5031 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5032 (when contents
5033 (if printer
5034 (unwind-protect
5035 (progn
5036 (mm-save-part-to-file handle file)
5037 (call-process shell-file-name nil
5038 (generate-new-buffer " *mm*")
5039 nil
5040 shell-command-switch
5041 (mm-mailcap-command
5042 printer file (mm-handle-type handle))))
5043 (delete-file file))
5044 (with-temp-buffer
5045 (insert contents)
5046 (gnus-print-buffer))
5047 (ps-despool filename)))))
16409b0b 5048
e0bad764 5049(defun gnus-mime-inline-part (&optional handle arg)
01c52d31
MB
5050 "Insert the MIME part under point into the current buffer.
5051Compressed files like .gz and .bz2 are decompressed."
e0bad764 5052 (interactive (list nil current-prefix-arg))
16409b0b 5053 (gnus-article-check-buffer)
01c52d31
MB
5054 (unless handle
5055 (setq handle (get-text-property (point) 'gnus-data)))
5056 (when handle
5057 (let ((b (point))
5058 (inhibit-read-only t)
5059 contents charset coding-system)
23f87bed
MB
5060 (if (and (not arg) (mm-handle-undisplayer handle))
5061 (mm-remove-part handle)
01c52d31
MB
5062 (mm-with-unibyte-buffer
5063 (mm-insert-part handle)
5064 (setq contents
5065 (or (mm-decompress-buffer
5066 (or (mail-content-type-get (mm-handle-type handle)
5067 'name)
5068 (mail-content-type-get (mm-handle-disposition handle)
5069 'filename))
5070 nil t)
5071 (buffer-string))))
23f87bed
MB
5072 (cond
5073 ((not arg)
01c52d31
MB
5074 (unless (setq charset (mail-content-type-get
5075 (mm-handle-type handle) 'charset))
5076 (unless (setq coding-system
5077 (mm-with-unibyte-buffer
5078 (insert contents)
5079 (mm-find-buffer-file-coding-system)))
5080 (setq charset gnus-newsgroup-charset))))
23f87bed
MB
5081 ((numberp arg)
5082 (if (mm-handle-undisplayer handle)
5083 (mm-remove-part handle))
5084 (setq charset
5085 (or (cdr (assq arg
5086 gnus-summary-show-article-charset-alist))
56c30d72
MB
5087 (mm-read-coding-system "Charset: "))))
5088 (t
5089 (if (mm-handle-undisplayer handle)
850c333d 5090 (mm-remove-part handle))))
23f87bed 5091 (forward-line 2)
850c333d
MB
5092 (mm-insert-inline
5093 handle
01c52d31
MB
5094 (if (or coding-system
5095 (and charset
5096 (setq coding-system
5097 (mm-charset-to-coding-system charset))
5098 (not (eq coding-system 'ascii))))
5099 (mm-decode-coding-string contents coding-system)
850c333d 5100 (mm-string-to-multibyte contents)))
23f87bed
MB
5101 (goto-char b)))))
5102
6b554e88
MB
5103(defun gnus-mime-strip-charset-parameters (handle)
5104 "Strip charset parameters from HANDLE."
5105 (if (stringp (car handle))
5106 (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
5107 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5108 "message/external-body")
5109 (progn
5110 (unless (mm-handle-cache handle)
5111 (mm-extern-cache-contents handle))
5112 (mm-handle-cache handle))
5113 handle)))
5114 (charset (assq 'charset (cdr type))))
5115 (when charset
5116 (delq charset type)))))
5117
23f87bed
MB
5118(defun gnus-mime-view-part-as-charset (&optional handle arg)
5119 "Insert the MIME part under point into the current buffer using the
5120specified charset."
5121 (interactive (list nil current-prefix-arg))
5122 (gnus-article-check-buffer)
163cb72d
MB
5123 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5124 (fun (get-text-property (point) 'gnus-callback))
5125 (gnus-newsgroup-ignored-charsets 'gnus-all)
6b554e88 5126 gnus-newsgroup-charset form preferred parts)
23f87bed 5127 (when handle
01c52d31
MB
5128 (when (prog1
5129 (and fun
5130 (setq gnus-newsgroup-charset
5131 (or (cdr (assq
5132 arg
5133 gnus-summary-show-article-charset-alist))
5134 (mm-read-coding-system "Charset: "))))
5135 (if (mm-handle-undisplayer handle)
5136 (mm-remove-part handle)))
6b554e88
MB
5137 (gnus-mime-strip-charset-parameters handle)
5138 (when (and (consp (setq form (cdr-safe fun)))
5139 (setq form (ignore-errors
5140 (assq 'gnus-mime-display-alternative form)))
5141 (setq preferred (caddr form))
5142 (progn
5143 (when (eq (car preferred) 'quote)
5144 (setq preferred (cadr preferred)))
5145 (not (equal preferred
5146 (get-text-property (point) 'gnus-data))))
5147 (setq parts (get-text-property (point) 'gnus-part))
5148 (setq parts (cdr (assq parts
5149 gnus-article-mime-handle-alist)))
5150 (equal (mm-handle-media-type parts) "multipart/alternative")
5151 (setq parts (reverse (cdr parts))))
5152 (setcar (cddr form)
5153 (list 'quote (or (cadr (member preferred parts))
5154 (car parts)))))
163cb72d 5155 (funcall fun handle)))))
23f87bed
MB
5156
5157(defun gnus-mime-view-part-externally (&optional handle)
16409b0b
GM
5158 "View the MIME part under point with an external viewer."
5159 (interactive)
5160 (gnus-article-check-buffer)
5161 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5162 (mm-user-display-methods nil)
5163 (mm-inlined-types nil)
5164 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5165 (mail-parse-ignored-charsets
54e573e6
MB
5166 (with-current-buffer gnus-summary-buffer
5167 gnus-newsgroup-ignored-charsets))
5168 (type (mm-handle-media-type handle))
5169 (method (mailcap-mime-info type))
5170 (mm-enable-external t))
5171 (if (not (stringp method))
5172 (gnus-mime-view-part-as-type
524705ae 5173 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
54e573e6
MB
5174 (when handle
5175 (if (mm-handle-undisplayer handle)
5176 (mm-remove-part handle)
5177 (mm-display-part handle))))))
16409b0b 5178
23f87bed 5179(defun gnus-mime-view-part-internally (&optional handle)
16409b0b 5180 "View the MIME part under point with an internal viewer.
23f87bed 5181If no internal viewer is available, use an external viewer."
16409b0b
GM
5182 (interactive)
5183 (gnus-article-check-buffer)
5184 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5185 (mm-inlined-types '(".*"))
5186 (mm-inline-large-images t)
5187 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5188 (mail-parse-ignored-charsets
54e573e6
MB
5189 (with-current-buffer gnus-summary-buffer
5190 gnus-newsgroup-ignored-charsets))
23f87bed 5191 (inhibit-read-only t))
54e573e6
MB
5192 (if (not (mm-inlinable-p handle))
5193 (gnus-mime-view-part-as-type
524705ae 5194 nil (lambda (types) (mm-inlinable-p handle (car types))))
54e573e6
MB
5195 (when handle
5196 (if (mm-handle-undisplayer handle)
5197 (mm-remove-part handle)
5198 (mm-display-part handle))))))
16409b0b 5199
e0bad764
DL
5200(defun gnus-mime-action-on-part (&optional action)
5201 "Do something with the MIME attachment at \(point\)."
5202 (interactive
23f87bed 5203 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
e0bad764
DL
5204 (gnus-article-check-buffer)
5205 (let ((action-pair (assoc action gnus-mime-action-alist)))
5206 (if action-pair
5207 (funcall (cdr action-pair)))))
5208
01c52d31
MB
5209(defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5210 "Call FUNCTION on MIME part N.
5211Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5212If INTERACTIVE, call FUNCTION interactivly."
5213 (let (window frame)
5214 ;; Check whether the article is displayed.
5215 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5216 (setq window (get-buffer-window gnus-article-buffer t))
5217 (frame-visible-p (setq frame (window-frame window))))
5218 (error "No article is displayed"))
5219 (with-current-buffer gnus-article-buffer
5220 ;; Check whether the article displays the right contents.
5221 (unless (with-current-buffer gnus-summary-buffer
5222 (eq gnus-current-article (gnus-summary-article-number)))
5223 (error "You should select the right article first"))
5224 (if n
5225 (setq n (prefix-numeric-value n))
5226 (let ((pt (point)))
5227 (setq n (or (get-text-property pt 'gnus-part)
5228 (and (not (bobp))
5229 (get-text-property (1- pt) 'gnus-part))
5230 (get-text-property (prog2
5231 (forward-line 1)
5232 (point)
5233 (goto-char pt))
5234 'gnus-part)
5235 (get-text-property
5236 (or (and (setq pt (previous-single-property-change
5237 pt 'gnus-part))
5238 (1- pt))
5239 (next-single-property-change (point) 'gnus-part)
5240 (point))
5241 'gnus-part)
5242 1))))
5243 ;; Check whether the specified part exists.
5244 (when (> n (length gnus-article-mime-handle-alist))
5245 (error "No such part")))
5246 (unless
5247 (progn
5248 ;; To select the window is needed so that the cursor
5249 ;; might be visible on the MIME button.
5250 (select-window (prog1
5251 window
5252 (setq window (selected-window))
5253 ;; Article may be displayed in the other frame.
5254 (gnus-select-frame-set-input-focus
5255 (prog1
5256 frame
5257 (setq frame (selected-frame))))))
5258 (when (gnus-article-goto-part n)
5259 ;; We point the cursor and the arrow at the MIME button
5260 ;; when the `function' prompt the user for something.
5261 (let ((cursor-in-non-selected-windows t)
5262 (overlay-arrow-string "=>")
5263 (overlay-arrow-position (point-marker)))
5264 (unwind-protect
5265 (cond
5266 ((and no-handle interactive)
5267 (call-interactively function))
5268 (no-handle
5269 (funcall function))
5270 (interactive
5271 (call-interactively
5272 function
5273 (cdr (assq n gnus-article-mime-handle-alist))))
5274 (t
5275 (funcall function
5276 (cdr (assq n gnus-article-mime-handle-alist)))))
5277 (set-marker overlay-arrow-position nil)
5278 (unless gnus-auto-select-part
5279 (gnus-select-frame-set-input-focus frame)
5280 (select-window window))))
5281 t))
5282 (if gnus-inhibit-mime-unbuttonizing
5283 ;; This is the default though the program shouldn't reach here.
5284 (error "No such part")
5285 ;; The part which doesn't have the MIME button is selected.
5286 ;; So, we display all the buttons and redo it.
5287 (let ((gnus-inhibit-mime-unbuttonizing t))
5288 (gnus-summary-show-article)
5289 (gnus-article-part-wrapper n function no-handle))))))
16409b0b
GM
5290
5291(defun gnus-article-pipe-part (n)
5292 "Pipe MIME part N, which is the numerical prefix."
01c52d31 5293 (interactive "P")
16409b0b
GM
5294 (gnus-article-part-wrapper n 'mm-pipe-part))
5295
5296(defun gnus-article-save-part (n)
5297 "Save MIME part N, which is the numerical prefix."
01c52d31 5298 (interactive "P")
16409b0b
GM
5299 (gnus-article-part-wrapper n 'mm-save-part))
5300
5301(defun gnus-article-interactively-view-part (n)
5302 "View MIME part N interactively, which is the numerical prefix."
01c52d31 5303 (interactive "P")
16409b0b
GM
5304 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5305
5306(defun gnus-article-copy-part (n)
5307 "Copy MIME part N, which is the numerical prefix."
01c52d31 5308 (interactive "P")
16409b0b
GM
5309 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5310
23f87bed
MB
5311(defun gnus-article-view-part-as-charset (n)
5312 "View MIME part N using a specified charset.
5313N is the numerical prefix."
01c52d31 5314 (interactive "P")
23f87bed
MB
5315 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5316
5317(defun gnus-article-view-part-externally (n)
16409b0b 5318 "View MIME part N externally, which is the numerical prefix."
01c52d31 5319 (interactive "P")
23f87bed 5320 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
16409b0b
GM
5321
5322(defun gnus-article-inline-part (n)
5323 "Inline MIME part N, which is the numerical prefix."
01c52d31 5324 (interactive "P")
16409b0b
GM
5325 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5326
01c52d31
MB
5327(defun gnus-article-save-part-and-strip (n)
5328 "Save MIME part N and replace it with an external body.
5329N is the numerical prefix."
5330 (interactive "P")
5331 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5332
5333(defun gnus-article-replace-part (n)
5334 "Replace MIME part N with an external body.
5335N is the numerical prefix."
5336 (interactive "P")
5337 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5338
5339(defun gnus-article-delete-part (n)
5340 "Delete MIME part N and add some information about the removed part.
5341N is the numerical prefix."
5342 (interactive "P")
5343 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5344
5345(defun gnus-article-view-part-as-type (n)
5346 "Choose a MIME media type, and view part N as such.
5347N is the numerical prefix."
5348 (interactive "P")
5349 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5350
16409b0b
GM
5351(defun gnus-article-mime-match-handle-first (condition)
5352 (if condition
01c52d31
MB
5353 (let (n)
5354 (dolist (ihandle gnus-article-mime-handle-alist)
a1506d29 5355 (if (and (cond
16409b0b
GM
5356 ((functionp condition)
5357 (funcall condition (cdr ihandle)))
a1506d29 5358 ((eq condition 'undisplayed)
16409b0b
GM
5359 (not (or (mm-handle-undisplayer (cdr ihandle))
5360 (equal (mm-handle-media-type (cdr ihandle))
5361 "multipart/alternative"))))
5362 ((eq condition 'undisplayed-alternative)
5363 (not (mm-handle-undisplayer (cdr ihandle))))
5364 (t t))
5365 (gnus-article-goto-part (car ihandle))
5366 (or (not n) (< (car ihandle) n)))
5367 (setq n (car ihandle))))
5368 (or n 1))
5369 1))
5370
5371(defun gnus-article-view-part (&optional n)
5372 "View MIME part N, which is the numerical prefix."
5373 (interactive "P")
01c52d31 5374 (with-current-buffer gnus-article-buffer
a1506d29 5375 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
16409b0b
GM
5376 gnus-article-mime-match-handle-function)))
5377 (when (> n (length gnus-article-mime-handle-alist))
5378 (error "No such part"))
5379 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5380 (when (gnus-article-goto-part n)
5381 (if (equal (car handle) "multipart/alternative")
5382 (gnus-article-press-button)
5383 (when (eq (gnus-mm-display-part handle) 'internal)
5384 (gnus-set-window-start)))))))
5385
e0bad764
DL
5386(defsubst gnus-article-mime-total-parts ()
5387 (if (bufferp (car gnus-article-mime-handles))
5388 1 ;; single part
5389 (1- (length gnus-article-mime-handles))))
5390
16409b0b
GM
5391(defun gnus-mm-display-part (handle)
5392 "Display HANDLE and fix MIME button."
5393 (let ((id (get-text-property (point) 'gnus-part))
5394 (point (point))
23f87bed 5395 (inhibit-read-only t))
16409b0b
GM
5396 (forward-line 1)
5397 (prog1
5398 (let ((window (selected-window))
5399 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5400 (mail-parse-ignored-charsets
23f87bed 5401 (if (gnus-buffer-live-p gnus-summary-buffer)
01c52d31 5402 (with-current-buffer gnus-summary-buffer
23f87bed
MB
5403 gnus-newsgroup-ignored-charsets)
5404 nil)))
16409b0b
GM
5405 (save-excursion
5406 (unwind-protect
23f87bed 5407 (let ((win (gnus-get-buffer-window (current-buffer) t))
16409b0b
GM
5408 (beg (point)))
5409 (when win
5410 (select-window win))
5411 (goto-char point)
5412 (forward-line)
5413 (if (mm-handle-displayed-p handle)
5414 ;; This will remove the part.
5415 (mm-display-part handle)
5416 (save-restriction
23f87bed
MB
5417 (narrow-to-region (point)
5418 (if (eobp) (point) (1+ (point))))
16409b0b
GM
5419 (mm-display-part handle)
5420 ;; We narrow to the part itself and
5421 ;; then call the treatment functions.
5422 (goto-char (point-min))
5423 (forward-line 1)
5424 (narrow-to-region (point) (point-max))
5425 (gnus-treat-article
5426 nil id
e0bad764 5427 (gnus-article-mime-total-parts)
16409b0b 5428 (mm-handle-media-type handle)))))
23f87bed
MB
5429 (if (window-live-p window)
5430 (select-window window)))))
16409b0b 5431 (goto-char point)
23f87bed 5432 (gnus-delete-line)
16409b0b
GM
5433 (gnus-insert-mime-button
5434 handle id (list (mm-handle-displayed-p handle)))
5435 (goto-char point))))
5436
5437(defun gnus-article-goto-part (n)
5438 "Go to MIME part N."
23f87bed 5439 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
16409b0b
GM
5440
5441(defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5442 (let ((gnus-tmp-name
23f87bed
MB
5443 (or (mail-content-type-get (mm-handle-type handle) 'name)
5444 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5445 (mail-content-type-get (mm-handle-type handle) 'url)
16409b0b
GM
5446 ""))
5447 (gnus-tmp-type (mm-handle-media-type handle))
4599d0ec 5448 (gnus-tmp-description (or (mm-handle-description handle) ""))
16409b0b
GM
5449 (gnus-tmp-dots
5450 (if (if displayed (car displayed)
5451 (mm-handle-displayed-p handle))
5452 "" "..."))
5453 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5454 (buffer-size)))
5455 gnus-tmp-type-long b e)
5456 (when (string-match ".*/" gnus-tmp-name)
5457 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5458 (setq gnus-tmp-type-long (concat gnus-tmp-type
5459 (and (not (equal gnus-tmp-name ""))
5460 (concat "; " gnus-tmp-name))))
23f87bed
MB
5461 (unless (equal gnus-tmp-description "")
5462 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
16409b0b
GM
5463 (unless (bolp)
5464 (insert "\n"))
5465 (setq b (point))
5466 (gnus-eval-format
5467 gnus-mime-button-line-format gnus-mime-button-line-format-alist
01c52d31
MB
5468 `(keymap ,gnus-mime-button-map
5469 gnus-callback gnus-mm-display-part
5470 gnus-part ,gnus-tmp-id
5471 article-type annotation
5472 gnus-data ,handle))
23f87bed
MB
5473 (setq e (if (bolp)
5474 ;; Exclude a newline.
5475 (1- (point))
5476 (point)))
01c52d31
MB
5477 (when gnus-article-button-face
5478 (gnus-overlay-put (gnus-make-overlay b e nil t)
5479 'face gnus-article-button-face))
16409b0b
GM
5480 (widget-convert-button
5481 'link b e
5482 :mime-handle handle
5483 :action 'gnus-widget-press-button
5484 :button-keymap gnus-mime-button-map
5485 :help-echo
5486 (lambda (widget/window &optional overlay pos)
5487 ;; Needed to properly clear the message due to a bug in
5488 ;; wid-edit (XEmacs only).
5489 (if (boundp 'help-echo-owns-message)
5490 (setq help-echo-owns-message t))
5491 (format
5492 "%S: %s the MIME part; %S: more options"
5493 (aref gnus-mouse-2 0)
5494 ;; XEmacs will get a single widget arg; Emacs 21 will get
5495 ;; window, overlay, position.
5496 (if (mm-handle-displayed-p
5497 (if overlay
e0bad764
DL
5498 (with-current-buffer (gnus-overlay-buffer overlay)
5499 (widget-get (widget-at (gnus-overlay-start overlay))
16409b0b
GM
5500 :mime-handle))
5501 (widget-get widget/window :mime-handle)))
5502 "hide" "show")
5503 (aref gnus-down-mouse-3 0))))))
5504
5505(defun gnus-widget-press-button (elems el)
5506 (goto-char (widget-get elems :from))
5507 (gnus-article-press-button))
5508
5509(defvar gnus-displaying-mime nil)
5510
5511(defun gnus-display-mime (&optional ihandles)
5512 "Display the MIME parts."
5513 (save-excursion
5514 (save-selected-window
5515 (let ((window (get-buffer-window gnus-article-buffer))
5516 (point (point)))
5517 (when window
5518 (select-window window)
5519 ;; We have to do this since selecting the window
5520 ;; may change the point. So we set the window point.
5521 (set-window-point window point)))
73043f7d
MB
5522 (let ((handles ihandles)
5523 (inhibit-read-only t)
5524 handle)
5525 (cond (handles)
5526 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5527 (when gnus-article-emulate-mime
5528 (mm-uu-dissect-text-parts handles)))
5529 (gnus-article-emulate-mime
5530 (setq handles (mm-uu-dissect))))
16409b0b
GM
5531 (when (and (not ihandles)
5532 (not gnus-displaying-mime))
5533 ;; Top-level call; we clean up.
5534 (when gnus-article-mime-handles
5535 (mm-destroy-parts gnus-article-mime-handles)
5536 (setq gnus-article-mime-handle-alist nil));; A trick.
5537 (setq gnus-article-mime-handles handles)
5538 ;; We allow users to glean info from the handles.
5539 (when gnus-article-mime-part-function
5540 (gnus-mime-part-function handles)))
5541 (if (and handles
5542 (or (not (stringp (car handles)))
5543 (cdr handles)))
5544 (progn
5545 (when (and (not ihandles)
5546 (not gnus-displaying-mime))
5547 ;; Clean up for mime parts.
5548 (article-goto-body)
5549 (delete-region (point) (point-max)))
5550 (let ((gnus-displaying-mime t))
5551 (gnus-mime-display-part handles)))
5552 (save-restriction
5553 (article-goto-body)
5554 (narrow-to-region (point) (point-max))
5555 (gnus-treat-article nil 1 1)
5556 (widen)))
5557 (unless ihandles
5558 ;; Highlight the headers.
5559 (save-excursion
5560 (save-restriction
5561 (article-goto-body)
5562 (narrow-to-region (point-min) (point))
31640842 5563 (gnus-article-save-original-date
f362b760
MB
5564 (gnus-treat-article 'head)))))))
5565 ;; Cope with broken MIME messages.
5566 (goto-char (point-max))
5567 (unless (bolp)
5568 (insert "\n"))))
16409b0b 5569
23f87bed
MB
5570(defcustom gnus-mime-display-multipart-as-mixed nil
5571 "Display \"multipart\" parts as \"multipart/mixed\".
5572
5573If t, it overrides nil values of
5574`gnus-mime-display-multipart-alternative-as-mixed' and
5575`gnus-mime-display-multipart-related-as-mixed'."
5576 :group 'gnus-article-mime
5577 :type 'boolean)
5578
5579(defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5580 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
bf247b6e 5581 :version "22.1"
23f87bed
MB
5582 :group 'gnus-article-mime
5583 :type 'boolean)
5584
5585(defcustom gnus-mime-display-multipart-related-as-mixed nil
5586 "Display \"multipart/related\" parts as \"multipart/mixed\".
5587
5588If displaying \"text/html\" is discouraged \(see
5589`mm-discouraged-alternatives'\) images or other material inside a
5590\"multipart/related\" part might be overlooked when this variable is nil."
bf247b6e 5591 :version "22.1"
23f87bed
MB
5592 :group 'gnus-article-mime
5593 :type 'boolean)
16409b0b
GM
5594
5595(defun gnus-mime-display-part (handle)
5596 (cond
430d3ed7
MB
5597 ;; Maybe a broken MIME message.
5598 ((null handle))
16409b0b
GM
5599 ;; Single part.
5600 ((not (stringp (car handle)))
5601 (gnus-mime-display-single handle))
5602 ;; User-defined multipart
5603 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5604 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5605 handle))
5606 ;; multipart/alternative
5607 ((and (equal (car handle) "multipart/alternative")
23f87bed
MB
5608 (not (or gnus-mime-display-multipart-as-mixed
5609 gnus-mime-display-multipart-alternative-as-mixed)))
16409b0b
GM
5610 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5611 (push (cons id handle) gnus-article-mime-handle-alist)
5612 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5613 ;; multipart/related
5614 ((and (equal (car handle) "multipart/related")
23f87bed
MB
5615 (not (or gnus-mime-display-multipart-as-mixed
5616 gnus-mime-display-multipart-related-as-mixed)))
16409b0b
GM
5617 ;;;!!!We should find the start part, but we just default
5618 ;;;!!!to the first part.
23f87bed
MB
5619 ;;(gnus-mime-display-part (cadr handle))
5620 ;;;!!! Most multipart/related is an HTML message plus images.
5621 ;;;!!! Unfortunately we are unable to let W3 display those
5622 ;;;!!! included images, so we just display it as a mixed multipart.
5623 ;;(gnus-mime-display-mixed (cdr handle))
5624 ;;;!!! No, w3 can display everything just fine.
16409b0b 5625 (gnus-mime-display-part (cadr handle)))
23f87bed
MB
5626 ((equal (car handle) "multipart/signed")
5627 (gnus-add-wash-type 'signed)
5628 (gnus-mime-display-security handle))
5629 ((equal (car handle) "multipart/encrypted")
5630 (gnus-add-wash-type 'encrypted)
5631 (gnus-mime-display-security handle))
16409b0b
GM
5632 ;; Other multiparts are handled like multipart/mixed.
5633 (t
5634 (gnus-mime-display-mixed (cdr handle)))))
5635
5636(defun gnus-mime-part-function (handles)
5637 (if (stringp (car handles))
5638 (mapcar 'gnus-mime-part-function (cdr handles))
5639 (funcall gnus-article-mime-part-function handles)))
5640
5641(defun gnus-mime-display-mixed (handles)
5642 (mapcar 'gnus-mime-display-part handles))
5643
5644(defun gnus-mime-display-single (handle)
5645 (let ((type (mm-handle-media-type handle))
5646 (ignored gnus-ignored-mime-types)
5647 (not-attachment t)
5648 (move nil)
5649 display text)
5650 (catch 'ignored
5651 (progn
5652 (while ignored
5653 (when (string-match (pop ignored) type)
5654 (throw 'ignored nil)))
5655 (if (and (setq not-attachment
5656 (and (not (mm-inline-override-p handle))
5657 (or (not (mm-handle-disposition handle))
5658 (equal (car (mm-handle-disposition handle))
5659 "inline")
5660 (mm-attachment-override-p handle))))
5661 (mm-automatic-display-p handle)
23f87bed
MB
5662 (or (and
5663 (mm-inlinable-p handle)
5664 (mm-inlined-p handle))
16409b0b
GM
5665 (mm-automatic-external-display-p type)))
5666 (setq display t)
5667 (when (equal (mm-handle-media-supertype handle) "text")
5668 (setq text t)))
e0bad764
DL
5669 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5670 beg)
16409b0b 5671 (push (cons id handle) gnus-article-mime-handle-alist)
531bedc3
MB
5672 (when (and display
5673 (equal (mm-handle-media-supertype handle) "message"))
5674 (insert-char
5675 ?\n
5676 (cond ((not (bolp)) 2)
5677 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5678 (t 1))))
16409b0b
GM
5679 (when (or (not display)
5680 (not (gnus-unbuttonized-mime-type-p type)))
16409b0b
GM
5681 (gnus-insert-mime-button
5682 handle id (list (or display (and not-attachment text))))
5683 (gnus-article-insert-newline)
23f87bed 5684 ;; Remember modify the number of forward lines.
e0bad764
DL
5685 (setq move t))
5686 (setq beg (point))
16409b0b
GM
5687 (cond
5688 (display
5689 (when move
23f87bed 5690 (forward-line -1)
16409b0b
GM
5691 (setq beg (point)))
5692 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5693 (mail-parse-ignored-charsets
16409b0b
GM
5694 (save-excursion (condition-case ()
5695 (set-buffer gnus-summary-buffer)
5696 (error))
5697 gnus-newsgroup-ignored-charsets)))
5698 (mm-display-part handle t))
5699 (goto-char (point-max)))
5700 ((and text not-attachment)
5701 (when move
23f87bed 5702 (forward-line -1)
16409b0b
GM
5703 (setq beg (point)))
5704 (gnus-article-insert-newline)
53cfefc8
MB
5705 (mm-insert-inline
5706 handle
01c52d31
MB
5707 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5708 'charset)
5709 (and (equal type "text/calendar") 'utf-8))))
53cfefc8
MB
5710 (cond ((not charset)
5711 (mm-string-as-multibyte (mm-get-part handle)))
5712 ((eq charset 'gnus-decoded)
5713 (with-current-buffer (mm-handle-buffer handle)
5714 (buffer-string)))
5715 (t
5716 (mm-decode-string (mm-get-part handle) charset)))))
16409b0b
GM
5717 (goto-char (point-max))))
5718 ;; Do highlighting.
5719 (save-excursion
5720 (save-restriction
5721 (narrow-to-region beg (point))
01c52d31
MB
5722 (if (eq handle gnus-article-mime-handles)
5723 ;; The format=flowed case.
5724 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5725 ;; Don't count signature parts that are never displayed.
5726 ;; The part number should be re-calculated supposing this
5727 ;; might be a message/rfc822 part.
5728 (let (handles)
5729 (dolist (part gnus-article-mime-handles)
5730 (unless (or (stringp part)
5731 (equal (car (mm-handle-type part))
5732 "application/pgp-signature"))
5733 (push part handles)))
5734 (gnus-treat-article
5735 nil (length (memq handle handles)) (length handles)
5736 (mm-handle-media-type handle)))))))))))
16409b0b
GM
5737
5738(defun gnus-unbuttonized-mime-type-p (type)
5739 "Say whether TYPE is to be unbuttonized."
5740 (unless gnus-inhibit-mime-unbuttonizing
23f87bed
MB
5741 (when (catch 'found
5742 (let ((types gnus-unbuttonized-mime-types))
5743 (while types
5744 (when (string-match (pop types) type)
5745 (throw 'found t)))))
5746 (not (catch 'found
5747 (let ((types gnus-buttonized-mime-types))
5748 (while types
5749 (when (string-match (pop types) type)
5750 (throw 'found t)))))))))
16409b0b
GM
5751
5752(defun gnus-article-insert-newline ()
5753 "Insert a newline, but mark it as undeletable."
5754 (gnus-put-text-property
5755 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5756
5757(defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5758 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5759 (ihandles handles)
5760 (point (point))
23f87bed 5761 handle (inhibit-read-only t) from props begend not-pref)
16409b0b
GM
5762 (save-window-excursion
5763 (save-restriction
5764 (when ibegend
5765 (narrow-to-region (car ibegend)
5766 (or (cdr ibegend)
5767 (progn
5768 (goto-char (car ibegend))
5769 (forward-line 2)
5770 (point))))
5771 (delete-region (point-min) (point-max))
5772 (mm-remove-parts handles))
5773 (setq begend (list (point-marker)))
5774 ;; Do the toggle.
5775 (unless (setq not-pref (cadr (member preferred ihandles)))
5776 (setq not-pref (car ihandles)))
5777 (when (or ibegend
23f87bed 5778 (not preferred)
16409b0b
GM
5779 (not (gnus-unbuttonized-mime-type-p
5780 "multipart/alternative")))
5781 (gnus-add-text-properties
5782 (setq from (point))
5783 (progn
5784 (insert (format "%d. " id))
5785 (point))
5786 `(gnus-callback
5787 (lambda (handles)
5788 (unless ,(not ibegend)
5789 (setq gnus-article-mime-handle-alist
5790 ',gnus-article-mime-handle-alist))
5791 (gnus-mime-display-alternative
5792 ',ihandles ',not-pref ',begend ,id))
01c52d31 5793 keymap ,gnus-mime-button-map
16409b0b
GM
5794 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5795 face ,gnus-article-button-face
16409b0b 5796 gnus-part ,id
7dafe00b 5797 article-type multipart))
16409b0b
GM
5798 (widget-convert-button 'link from (point)
5799 :action 'gnus-widget-press-button
5800 :button-keymap gnus-widget-button-keymap)
5801 ;; Do the handles
5802 (while (setq handle (pop handles))
5803 (gnus-add-text-properties
5804 (setq from (point))
5805 (progn
5806 (insert (format "(%c) %-18s"
5807 (if (equal handle preferred) ?* ? )
5808 (mm-handle-media-type handle)))
5809 (point))
5810 `(gnus-callback
5811 (lambda (handles)
5812 (unless ,(not ibegend)
5813 (setq gnus-article-mime-handle-alist
5814 ',gnus-article-mime-handle-alist))
5815 (gnus-mime-display-alternative
5816 ',ihandles ',handle ',begend ,id))
01c52d31 5817 keymap ,gnus-mime-button-map
16409b0b
GM
5818 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5819 face ,gnus-article-button-face
16409b0b
GM
5820 gnus-part ,id
5821 gnus-data ,handle))
5822 (widget-convert-button 'link from (point)
5823 :action 'gnus-widget-press-button
5824 :button-keymap gnus-widget-button-keymap)
5825 (insert " "))
5826 (insert "\n\n"))
5827 (when preferred
5828 (if (stringp (car preferred))
5829 (gnus-display-mime preferred)
5830 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5831 (mail-parse-ignored-charsets
01c52d31
MB
5832 (with-current-buffer gnus-summary-buffer
5833 gnus-newsgroup-ignored-charsets)))
16409b0b
GM
5834 (mm-display-part preferred)
5835 ;; Do highlighting.
5836 (save-excursion
5837 (save-restriction
5838 (narrow-to-region (car begend) (point-max))
5839 (gnus-treat-article
5840 nil (length gnus-article-mime-handle-alist)
e0bad764 5841 (gnus-article-mime-total-parts)
16409b0b
GM
5842 (mm-handle-media-type handle))))))
5843 (goto-char (point-max))
5844 (setcdr begend (point-marker)))))
5845 (when ibegend
5846 (goto-char point))))
5847
23f87bed
MB
5848(defconst gnus-article-wash-status-strings
5849 (let ((alist '((cite "c" "Possible hidden citation text"
5850 " " "All citation text visible")
5851 (headers "h" "Hidden headers"
5852 " " "All headers visible.")
5853 (pgp "p" "Encrypted or signed message status hidden"
5854 " " "No hidden encryption nor digital signature status")
5855 (signature "s" "Signature has been hidden"
5856 " " "Signature is visible")
5857 (overstrike "o" "Overstrike (^H) characters applied"
5858 " " "No overstrike characters applied")
5859 (emphasis "e" "/*_Emphasis_*/ characters applied"
5860 " " "No /*_emphasis_*/ characters applied")))
5861 result)
5862 (dolist (entry alist result)
5863 (let ((key (nth 0 entry))
5864 (on (copy-sequence (nth 1 entry)))
5865 (on-help (nth 2 entry))
5866 (off (copy-sequence (nth 3 entry)))
5867 (off-help (nth 4 entry)))
5868 (put-text-property 0 1 'help-echo on-help on)
5869 (put-text-property 0 1 'help-echo off-help off)
5870 (push (list key on off) result))))
5871 "Alist of strings describing wash status in the mode line.
5872Each entry has the form (KEY ON OF), where the KEY is a symbol
5873representing the particular washing function, ON is the string to use
5874in the article mode line when the washing function is active, and OFF
5875is the string to use when it is inactive.")
5876
5877(defun gnus-article-wash-status-entry (key value)
5878 (let ((entry (assoc key gnus-article-wash-status-strings)))
5879 (if value (nth 1 entry) (nth 2 entry))))
5880
eec82323
LMI
5881(defun gnus-article-wash-status ()
5882 "Return a string which display status of article washing."
01c52d31 5883 (with-current-buffer gnus-article-buffer
16409b0b
GM
5884 (let ((cite (memq 'cite gnus-article-wash-types))
5885 (headers (memq 'headers gnus-article-wash-types))
5886 (boring (memq 'boring-headers gnus-article-wash-types))
5887 (pgp (memq 'pgp gnus-article-wash-types))
5888 (pem (memq 'pem gnus-article-wash-types))
23f87bed
MB
5889 (signed (memq 'signed gnus-article-wash-types))
5890 (encrypted (memq 'encrypted gnus-article-wash-types))
16409b0b
GM
5891 (signature (memq 'signature gnus-article-wash-types))
5892 (overstrike (memq 'overstrike gnus-article-wash-types))
5893 (emphasis (memq 'emphasis gnus-article-wash-types)))
23f87bed
MB
5894 (concat
5895 (gnus-article-wash-status-entry 'cite cite)
5896 (gnus-article-wash-status-entry 'headers (or headers boring))
5897 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5898 (gnus-article-wash-status-entry 'signature signature)
5899 (gnus-article-wash-status-entry 'overstrike overstrike)
5900 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5901
5902(defun gnus-add-wash-type (type)
5903 "Add a washing of TYPE to the current status."
5904 (add-to-list 'gnus-article-wash-types type))
5905
5906(defun gnus-delete-wash-type (type)
5907 "Add a washing of TYPE to the current status."
5908 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5909
5910(defun gnus-add-image (category image)
5911 "Add IMAGE of CATEGORY to the list of displayed images."
5912 (let ((entry (assq category gnus-article-image-alist)))
5913 (unless entry
5914 (setq entry (list category))
5915 (push entry gnus-article-image-alist))
5916 (nconc entry (list image))))
5917
5918(defun gnus-delete-images (category)
5919 "Delete all images in CATEGORY."
5920 (let ((entry (assq category gnus-article-image-alist)))
5921 (dolist (image (cdr entry))
5922 (gnus-remove-image image category))
5923 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5924 (gnus-delete-wash-type category)))
eec82323 5925
16409b0b 5926(defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6748645f
LMI
5927
5928(defun gnus-article-maybe-hide-headers ()
eec82323
LMI
5929 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5930Provided for backwards compatibility."
16409b0b 5931 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
01c52d31
MB
5932 (not (with-current-buffer gnus-summary-buffer
5933 gnus-have-all-headers)))
16409b0b
GM
5934 (not gnus-inhibit-hiding))
5935 (gnus-article-hide-headers)))
eec82323
LMI
5936
5937;;; Article savers.
5938
5939(defun gnus-output-to-file (file-name)
26c9afc3
MB
5940 "Append the current article to a file named FILE-NAME.
5941If `gnus-article-save-coding-system' is non-nil, it is used to encode
5942text and used as the value of the coding cookie which is added to the
5943top of a file. Otherwise, this function saves a raw article without
5944the coding cookie."
5945 (let* ((artbuf (current-buffer))
5946 (file-name-coding-system nnmail-pathname-coding-system)
5947 (coding gnus-article-save-coding-system)
5948 (coding-system-for-read (if coding
5949 nil ;; Rely on the coding cookie.
5950 mm-text-coding-system))
5951 (coding-system-for-write (or coding
5952 mm-text-coding-system-for-write
5953 mm-text-coding-system))
5954 (exists (file-exists-p file-name)))
16409b0b 5955 (with-temp-buffer
26c9afc3
MB
5956 (when exists
5957 (insert-file-contents file-name)
5958 (goto-char (point-min))
5959 ;; Remove the existing coding cookie.
5960 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5961 (delete-region (match-beginning 0) (match-end 0))))
5962 (goto-char (point-max))
eec82323
LMI
5963 (insert-buffer-substring artbuf)
5964 ;; Append newline at end of the buffer as separator, and then
5965 ;; save it to file.
5966 (goto-char (point-max))
5967 (insert "\n")
26c9afc3
MB
5968 (when coding
5969 ;; If the coding system is not suitable to encode the text,
5970 ;; ask a user for a proper one.
5971 (when (fboundp 'select-safe-coding-system)
5972 (setq coding (coding-system-base
5973 (save-window-excursion
5974 (select-safe-coding-system (point-min) (point-max)
5975 coding))))
5976 (setq coding-system-for-write
5977 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5978 coding)))
5979 (goto-char (point-min))
5980 ;; Add the coding cookie.
5981 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5982 coding-system-for-write)))
5983 (if exists
5984 (progn
5985 (write-region (point-min) (point-max) file-name nil 'no-message)
5986 (message "Appended to %s" file-name))
5987 (write-region (point-min) (point-max) file-name))))
5988 t)
eec82323
LMI
5989
5990(defun gnus-narrow-to-page (&optional arg)
5991 "Narrow the article buffer to a page.
5992If given a numerical ARG, move forward ARG pages."
5993 (interactive "P")
5994 (setq arg (if arg (prefix-numeric-value arg) 0))
80de1778 5995 (with-current-buffer gnus-article-buffer
eec82323
LMI
5996 (goto-char (point-min))
5997 (widen)
5998 ;; Remove any old next/prev buttons.
5999 (when (gnus-visual-p 'page-marker)
4e7d0221 6000 (let ((inhibit-read-only t))
eec82323
LMI
6001 (gnus-remove-text-with-property 'gnus-prev)
6002 (gnus-remove-text-with-property 'gnus-next)))
23f87bed 6003 (if
eec82323
LMI
6004 (cond ((< arg 0)
6005 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
6006 ((> arg 0)
6007 (re-search-forward page-delimiter nil 'move arg)))
23f87bed 6008 (goto-char (match-end 0))
eec82323
LMI
6009 (save-excursion
6010 (goto-char (point-min))
23f87bed
MB
6011 (setq gnus-page-broken
6012 (and (re-search-forward page-delimiter nil t) t))))
6013 (when gnus-page-broken
6014 (narrow-to-region
6015 (point)
6016 (if (re-search-forward page-delimiter nil 'move)
6017 (match-beginning 0)
6018 (point)))
6019 (when (and (gnus-visual-p 'page-marker)
6020 (> (point-min) (save-restriction (widen) (point-min))))
6021 (save-excursion
6022 (goto-char (point-min))
6023 (gnus-insert-prev-page-button)))
6024 (when (and (gnus-visual-p 'page-marker)
45893b95 6025 (< (point-max) (save-restriction (widen) (point-max))))
23f87bed
MB
6026 (save-excursion
6027 (goto-char (point-max))
6028 (gnus-insert-next-page-button))))))
eec82323
LMI
6029
6030;; Article mode commands
6031
6032(defun gnus-article-goto-next-page ()
6033 "Show the next page of the article."
6034 (interactive)
6035 (when (gnus-article-next-page)
6036 (goto-char (point-min))
6037 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6038
23f87bed 6039
eec82323 6040(defun gnus-article-goto-prev-page ()
23f87bed 6041 "Show the previous page of the article."
eec82323 6042 (interactive)
23f87bed
MB
6043 (if (bobp)
6044 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
eec82323
LMI
6045 (gnus-article-prev-page nil)))
6046
23f87bed
MB
6047;; This is cleaner but currently breaks `gnus-pick-mode':
6048;;
6049;; (defun gnus-article-goto-next-page ()
6050;; "Show the next page of the article."
6051;; (interactive)
6052;; (gnus-eval-in-buffer-window gnus-summary-buffer
6053;; (gnus-summary-next-page)))
6054;;
6055;; (defun gnus-article-goto-prev-page ()
6056;; "Show the next page of the article."
6057;; (interactive)
6058;; (gnus-eval-in-buffer-window gnus-summary-buffer
6059;; (gnus-summary-prev-page)))
6060
eec82323
LMI
6061(defun gnus-article-next-page (&optional lines)
6062 "Show the next page of the current article.
6063If end of article, return non-nil. Otherwise return nil.
6064Argument LINES specifies lines to be scrolled up."
6065 (interactive "p")
d8a88581 6066 (move-to-window-line -1)
60ece9b0
MB
6067 (if (and (not (and gnus-article-over-scroll
6068 (> (count-lines (window-start) (point-max))
6069 (+ (or lines (1- (window-height)))
6070 (or (and (boundp 'scroll-margin)
6071 (symbol-value 'scroll-margin))
6072 0)))))
6073 (save-excursion
6074 (end-of-line)
6075 (and (pos-visible-in-window-p) ;Not continuation line.
6076 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
eec82323
LMI
6077 ;; Nothing in this page.
6078 (if (or (not gnus-page-broken)
6079 (save-excursion
6080 (save-restriction
23f87bed
MB
6081 (widen)
6082 (forward-line)
6083 (eobp)))) ;Real end-of-buffer?
6084 (progn
6085 (when gnus-article-over-scroll
6086 (gnus-article-next-page-1 lines))
6087 t) ;Nothing more.
eec82323
LMI
6088 (gnus-narrow-to-page 1) ;Go to next page.
6089 nil)
6090 ;; More in this page.
23f87bed 6091 (gnus-article-next-page-1 lines)
eec82323
LMI
6092 nil))
6093
d8a88581
MB
6094(defmacro gnus-article-beginning-of-window ()
6095 "Move point to the beginning of the window.
6096In Emacs, the point is placed at the line number which `scroll-margin'
6097specifies."
6098 (if (featurep 'xemacs)
6099 '(move-to-window-line 0)
6100 '(move-to-window-line
6101 (min (max 0 scroll-margin)
6102 (max 1 (- (window-height)
6103 (if mode-line-format 1 0)
01c52d31 6104 (if header-line-format 1 0)))))))
d8a88581 6105
23f87bed 6106(defun gnus-article-next-page-1 (lines)
4b91459a
MB
6107 (when (and (not (featurep 'xemacs))
6108 (numberp lines)
6109 (> lines 0)
6110 (numberp (symbol-value 'scroll-margin))
6111 (> (symbol-value 'scroll-margin) 0))
6112 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
6113 ;; too many number of lines if `scroll-margin' is set as two or greater.
6114 (setq lines (min lines
6115 (max 0 (- (count-lines (window-start) (point-max))
6116 (symbol-value 'scroll-margin))))))
6117 (condition-case ()
6118 (let ((scroll-in-place nil))
6119 (scroll-up lines))
6120 (end-of-buffer
6121 ;; Long lines may cause an end-of-buffer error.
6122 (goto-char (point-max))))
6123 (gnus-article-beginning-of-window))
23f87bed 6124
eec82323
LMI
6125(defun gnus-article-prev-page (&optional lines)
6126 "Show previous page of current article.
6127Argument LINES specifies lines to be scrolled down."
6128 (interactive "p")
d8a88581 6129 (move-to-window-line 0)
eec82323
LMI
6130 (if (and gnus-page-broken
6131 (bobp)
6132 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6133 (progn
6134 (gnus-narrow-to-page -1) ;Go to previous page.
6135 (goto-char (point-max))
60ece9b0
MB
6136 (recenter (if gnus-article-over-scroll
6137 (if lines
6138 (max (+ lines (or (and (boundp 'scroll-margin)
6139 (symbol-value 'scroll-margin))
6140 0))
6141 3)
6142 (- (window-height) 2))
6143 -1)))
c03ac728
MB
6144 (prog1
6145 (condition-case ()
6146 (let ((scroll-in-place nil))
6147 (scroll-down lines))
6148 (beginning-of-buffer
6149 (goto-char (point-min))))
6150 (gnus-article-beginning-of-window))))
eec82323 6151
23f87bed
MB
6152(defun gnus-article-only-boring-p ()
6153 "Decide whether there is only boring text remaining in the article.
6154Something \"interesting\" is a word of at least two letters that does
6155not have a face in `gnus-article-boring-faces'."
6156 (when (and gnus-article-skip-boring
6157 (boundp 'gnus-article-boring-faces)
6158 (symbol-value 'gnus-article-boring-faces))
6159 (save-excursion
531bedc3
MB
6160 (let ((inhibit-point-motion-hooks t))
6161 (catch 'only-boring
6162 (while (re-search-forward "\\b\\w\\w" nil t)
6163 (forward-char -1)
6164 (when (not (gnus-intersection
6165 (gnus-faces-at (point))
6166 (symbol-value 'gnus-article-boring-faces)))
6167 (throw 'only-boring nil)))
6168 (throw 'only-boring t))))))
23f87bed 6169
eec82323
LMI
6170(defun gnus-article-refer-article ()
6171 "Read article specified by message-id around point."
6172 (interactive)
23f87bed 6173 (save-excursion
01c52d31
MB
6174 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6175 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6176 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
23f87bed 6177 (let ((msg-id (concat "<" (match-string 0) ">")))
eec82323 6178 (set-buffer gnus-summary-buffer)
23f87bed 6179 (gnus-summary-refer-article msg-id))
eec82323
LMI
6180 (error "No references around point"))))
6181
6182(defun gnus-article-show-summary ()
6183 "Reconfigure windows to show summary buffer."
6184 (interactive)
6185 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6186 (error "There is no summary buffer for this article buffer")
a8151ef7 6187 (gnus-article-set-globals)
eec82323 6188 (gnus-configure-windows 'article)
6748645f
LMI
6189 (gnus-summary-goto-subject gnus-current-article)
6190 (gnus-summary-position-point)))
eec82323
LMI
6191
6192(defun gnus-article-describe-briefly ()
6193 "Describe article mode commands briefly."
6194 (interactive)
16409b0b 6195 (gnus-message 6 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
eec82323
LMI
6196
6197(defun gnus-article-summary-command ()
6198 "Execute the last keystroke in the summary buffer."
6199 (interactive)
6200 (let ((obuf (current-buffer))
6201 (owin (current-window-configuration))
6202 func)
6748645f 6203 (switch-to-buffer gnus-article-current-summary 'norecord)
eec82323
LMI
6204 (setq func (lookup-key (current-local-map) (this-command-keys)))
6205 (call-interactively func)
6206 (set-buffer obuf)
6207 (set-window-configuration owin)
6208 (set-window-point (get-buffer-window (current-buffer)) (point))))
6209
6210(defun gnus-article-summary-command-nosave ()
6211 "Execute the last keystroke in the summary buffer."
6212 (interactive)
6213 (let (func)
bdaf8a62 6214 (pop-to-buffer gnus-article-current-summary)
eec82323
LMI
6215 (setq func (lookup-key (current-local-map) (this-command-keys)))
6216 (call-interactively func)))
6217
16409b0b
GM
6218(defun gnus-article-check-buffer ()
6219 "Beep if not in an article buffer."
6220 (unless (equal major-mode 'gnus-article-mode)
6221 (error "Command invoked outside of a Gnus article buffer")))
6222
eec82323
LMI
6223(defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6224 "Read a summary buffer key sequence and execute it from the article buffer."
6225 (interactive "P")
16409b0b 6226 (gnus-article-check-buffer)
eec82323 6227 (let ((nosaves
23f87bed
MB
6228 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6229 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6230 "=" "^" "\M-^" "|"))
6231 (nosave-but-article
0b6799c3
MB
6232 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6233 "An" "Ap" [?A (meta return)] [?A delete]))
23f87bed 6234 (nosave-in-article
0b6799c3 6235 '("AS" "\C-d"))
23f87bed
MB
6236 (up-to-top
6237 '("n" "Gn" "p" "Gp"))
6238 keys new-sum-point)
80de1778 6239 (with-current-buffer gnus-article-current-summary
eec82323 6240 (let (gnus-pick-mode)
95838435
MB
6241 (setq unread-command-events (nconc unread-command-events
6242 (list (or key last-command-event)))
6243 keys (if (featurep 'xemacs)
6244 (events-to-keys (read-key-sequence nil t))
6245 (read-key-sequence nil t)))))
a1506d29 6246
eec82323
LMI
6247 (message "")
6248
01c52d31
MB
6249 (cond
6250 ((eq (aref keys (1- (length keys))) ?\C-h)
0b6799c3 6251 (gnus-article-describe-bindings (substring keys 0 -1)))
01c52d31
MB
6252 ((or (member keys nosaves)
6253 (member keys nosave-but-article)
6254 (member keys nosave-in-article))
6255 (let (func)
6256 (save-window-excursion
6257 (pop-to-buffer gnus-article-current-summary)
6258 ;; We disable the pick minor mode commands.
6259 (let (gnus-pick-mode)
6260 (setq func (lookup-key (current-local-map) keys))))
6261 (if (or (not func)
6262 (numberp func))
6263 (ding)
6264 (unless (member keys nosave-in-article)
6265 (set-buffer gnus-article-current-summary))
6266 (call-interactively func)
6267 (setq new-sum-point (point)))
6268 (when (member keys nosave-but-article)
6269 (pop-to-buffer gnus-article-buffer))))
6270 (t
eec82323
LMI
6271 ;; These commands should restore window configuration.
6272 (let ((obuf (current-buffer))
23f87bed 6273 (owin (current-window-configuration))
01c52d31 6274 win func in-buffer selected new-sum-start new-sum-hscroll err)
23f87bed 6275 (cond (not-restore-window
01c52d31
MB
6276 (pop-to-buffer gnus-article-current-summary)
6277 (setq win (selected-window)))
23f87bed
MB
6278 ((setq win (get-buffer-window gnus-article-current-summary))
6279 (select-window win))
6280 (t
01c52d31
MB
6281 (let ((summary-buffer gnus-article-current-summary))
6282 (gnus-configure-windows 'article)
6283 (unless (setq win (get-buffer-window summary-buffer 'visible))
6284 (let ((gnus-buffer-configuration
6285 '(article ((vertical 1.0
6286 (summary 0.25 point)
6287 (article 1.0))))))
6288 (gnus-configure-windows 'article))
6289 (setq win (get-buffer-window summary-buffer 'visible)))
6290 (gnus-select-frame-set-input-focus (window-frame win))
6291 (select-window win))))
23f87bed
MB
6292 (setq in-buffer (current-buffer))
6293 ;; We disable the pick minor mode commands.
6294 (if (and (setq func (let (gnus-pick-mode)
520aa572 6295 (lookup-key (current-local-map) keys)))
01c52d31
MB
6296 (functionp func)
6297 (condition-case code
6298 (progn
6299 (call-interactively func)
6300 t)
6301 (error
6302 (setq err code)
6303 nil)))
23f87bed 6304 (progn
23f87bed
MB
6305 (when (eq win (selected-window))
6306 (setq new-sum-point (point)
6307 new-sum-start (window-start win)
9a89f5b0 6308 new-sum-hscroll (window-hscroll win)))
01c52d31
MB
6309 (when (or (eq in-buffer (current-buffer))
6310 (when (eq obuf (current-buffer))
6311 (set-buffer in-buffer)
6312 t))
520aa572
SZ
6313 (setq selected (gnus-summary-select-article))
6314 (set-buffer obuf)
6315 (unless not-restore-window
6316 (set-window-configuration owin))
01c52d31
MB
6317 (when (and (eq selected 'old)
6318 new-sum-point)
520aa572
SZ
6319 (set-window-start (get-buffer-window (current-buffer))
6320 1)
6321 (set-window-point (get-buffer-window (current-buffer))
01c52d31
MB
6322 (if (article-goto-body)
6323 (1- (point))
6324 (point))))
23f87bed 6325 (when (and (not not-restore-window)
01c52d31
MB
6326 new-sum-point
6327 (with-current-buffer (window-buffer win)
6328 (eq major-mode 'gnus-summary-mode)))
23f87bed
MB
6329 (set-window-point win new-sum-point)
6330 (set-window-start win new-sum-start)
9a89f5b0 6331 (set-window-hscroll win new-sum-hscroll))))
23f87bed 6332 (set-window-configuration owin)
01c52d31
MB
6333 (if err
6334 (signal (car err) (cdr err))
6335 (ding))))))))
520aa572 6336
95838435
MB
6337(defun gnus-article-read-summary-send-keys ()
6338 (interactive)
0b6799c3 6339 (let ((unread-command-events (list (gnus-character-to-event ?S))))
95838435
MB
6340 (gnus-article-read-summary-keys)))
6341
520aa572 6342(defun gnus-article-describe-key (key)
95838435
MB
6343 "Display documentation of the function invoked by KEY.
6344KEY is a string or a vector."
6345 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6346 (read-key-sequence "Describe key: "))))
520aa572 6347 (gnus-article-check-buffer)
95838435
MB
6348 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6349 gnus-article-read-summary-send-keys))
80de1778 6350 (with-current-buffer gnus-article-current-summary
95838435
MB
6351 (setq unread-command-events
6352 (if (featurep 'xemacs)
6353 (append key nil)
6354 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6355 (list 'meta (- x 128))
6356 x))
6357 key)))
6358 (let ((cursor-in-echo-area t)
6359 gnus-pick-mode)
6360 (describe-key (read-key-sequence nil t))))
520aa572
SZ
6361 (describe-key key)))
6362
6363(defun gnus-article-describe-key-briefly (key &optional insert)
95838435
MB
6364 "Display documentation of the function invoked by KEY.
6365KEY is a string or a vector."
6366 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6367 (read-key-sequence "Describe key: "))
6368 current-prefix-arg))
520aa572 6369 (gnus-article-check-buffer)
95838435
MB
6370 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6371 gnus-article-read-summary-send-keys))
80de1778 6372 (with-current-buffer gnus-article-current-summary
95838435
MB
6373 (setq unread-command-events
6374 (if (featurep 'xemacs)
6375 (append key nil)
6376 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6377 (list 'meta (- x 128))
6378 x))
6379 key)))
6380 (let ((cursor-in-echo-area t)
6381 gnus-pick-mode)
6382 (describe-key-briefly (read-key-sequence nil t) insert)))
520aa572 6383 (describe-key-briefly key insert)))
eec82323 6384
0b6799c3
MB
6385;;`gnus-agent-mode' in gnus-agent.el will define it.
6386(defvar gnus-agent-summary-mode)
e9198520 6387(defvar gnus-draft-mode)
0b6799c3
MB
6388
6389(defun gnus-article-describe-bindings (&optional prefix)
6390 "Show a list of all defined keys, and their definitions.
6391The optional argument PREFIX, if non-nil, should be a key sequence;
6392then we display only bindings that start with that prefix."
6393 (interactive)
6394 (gnus-article-check-buffer)
6395 (let ((keymap (copy-keymap gnus-article-mode-map))
6396 (map (copy-keymap gnus-article-send-map))
6397 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
e9198520 6398 agent draft)
0b6799c3
MB
6399 (define-key keymap "S" map)
6400 (define-key map [t] nil)
6401 (with-current-buffer gnus-article-current-summary
6402 (set-keymap-parent map (key-binding "S"))
6403 (let (def gnus-pick-mode)
6404 (dolist (key sumkeys)
6405 (when (setq def (key-binding key))
6406 (define-key keymap key def))))
6407 (when (boundp 'gnus-agent-summary-mode)
e9198520
MB
6408 (setq agent gnus-agent-summary-mode))
6409 (when (boundp 'gnus-draft-mode)
6410 (setq draft gnus-draft-mode)))
0b6799c3
MB
6411 (with-temp-buffer
6412 (use-local-map keymap)
6413 (set (make-local-variable 'gnus-agent-summary-mode) agent)
e9198520 6414 (set (make-local-variable 'gnus-draft-mode) draft)
0b6799c3
MB
6415 (describe-bindings prefix))
6416 (let ((item `((lambda (prefix)
80de1778 6417 (with-current-buffer ,(current-buffer)
0b6799c3
MB
6418 (gnus-article-describe-bindings prefix)))
6419 ,prefix)))
6420 (with-current-buffer (if (fboundp 'help-buffer)
6421 (let (help-xref-following) (help-buffer))
6422 "*Help*") ;; Emacs 21
6423 (setq help-xref-stack-item item)))))
6424
23f87bed
MB
6425(defun gnus-article-reply-with-original (&optional wide)
6426 "Start composing a reply mail to the current message.
6427The text in the region will be yanked. If the region isn't active,
6428the entire article will be yanked."
95838435 6429 (interactive)
23f87bed
MB
6430 (let ((article (cdr gnus-article-current))
6431 contents)
1d0df8af 6432 (if (not (gnus-region-active-p))
23f87bed
MB
6433 (with-current-buffer gnus-summary-buffer
6434 (gnus-summary-reply (list (list article)) wide))
6435 (setq contents (buffer-substring (point) (mark t)))
6436 ;; Deactivate active regions.
6437 (when (and (boundp 'transient-mark-mode)
6438 transient-mark-mode)
6439 (setq mark-active nil))
6440 (with-current-buffer gnus-summary-buffer
6441 (gnus-summary-reply
6442 (list (list article contents)) wide)))))
6443
95838435
MB
6444(defun gnus-article-wide-reply-with-original ()
6445 "Start composing a wide reply mail to the current message.
6446The text in the region will be yanked. If the region isn't active,
6447the entire article will be yanked."
6448 (interactive)
6449 (gnus-article-reply-with-original t))
6450
23f87bed
MB
6451(defun gnus-article-followup-with-original ()
6452 "Compose a followup to the current article.
6453The text in the region will be yanked. If the region isn't active,
6454the entire article will be yanked."
6455 (interactive)
6456 (let ((article (cdr gnus-article-current))
6457 contents)
1d0df8af 6458 (if (not (gnus-region-active-p))
23f87bed
MB
6459 (with-current-buffer gnus-summary-buffer
6460 (gnus-summary-followup (list (list article))))
6461 (setq contents (buffer-substring (point) (mark t)))
6462 ;; Deactivate active regions.
6463 (when (and (boundp 'transient-mark-mode)
6464 transient-mark-mode)
6465 (setq mark-active nil))
6466 (with-current-buffer gnus-summary-buffer
6467 (gnus-summary-followup
6468 (list (list article contents)))))))
6469
eec82323
LMI
6470(defun gnus-article-hide (&optional arg force)
6471 "Hide all the gruft in the current article.
23f87bed
MB
6472This means that signatures, cited text and (some) headers will be
6473hidden.
eec82323 6474If given a prefix, show the hidden text instead."
6748645f 6475 (interactive (append (gnus-article-hidden-arg) (list 'force)))
eec82323 6476 (gnus-article-hide-headers arg)
16409b0b 6477 (gnus-article-hide-list-identifiers arg)
eec82323
LMI
6478 (gnus-article-hide-citation-maybe arg force)
6479 (gnus-article-hide-signature arg))
6480
6481(defun gnus-article-maybe-highlight ()
6748645f 6482 "Do some article highlighting if article highlighting is requested."
eec82323
LMI
6483 (when (gnus-visual-p 'article-highlight 'highlight)
6484 (gnus-article-highlight-some)))
6485
6748645f
LMI
6486(defun gnus-check-group-server ()
6487 ;; Make sure the connection to the server is alive.
6488 (unless (gnus-server-opened
6489 (gnus-find-method-for-group gnus-newsgroup-name))
6490 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6491 (gnus-request-group gnus-newsgroup-name t)))
6492
23f87bed
MB
6493(eval-when-compile
6494 (autoload 'nneething-get-file-name "nneething"))
6495
eec82323
LMI
6496(defun gnus-request-article-this-buffer (article group)
6497 "Get an article and insert it into this buffer."
6748645f 6498 (let (do-update-line sparse-header)
eec82323
LMI
6499 (prog1
6500 (save-excursion
6501 (erase-buffer)
6502 (gnus-kill-all-overlays)
6503 (setq group (or group gnus-newsgroup-name))
6504
eec82323
LMI
6505 ;; Using `gnus-request-article' directly will insert the article into
6506 ;; `nntp-server-buffer' - so we'll save some time by not having to
6507 ;; copy it from the server buffer into the article buffer.
6508
6509 ;; We only request an article by message-id when we do not have the
6510 ;; headers for it, so we'll have to get those.
6511 (when (stringp article)
16409b0b 6512 (gnus-read-header article))
eec82323
LMI
6513
6514 ;; If the article number is negative, that means that this article
6515 ;; doesn't belong in this newsgroup (possibly), so we find its
6516 ;; message-id and request it by id instead of number.
6517 (when (and (numberp article)
6518 gnus-summary-buffer
6519 (get-buffer gnus-summary-buffer)
6748645f 6520 (gnus-buffer-exists-p gnus-summary-buffer))
80de1778 6521 (with-current-buffer gnus-summary-buffer
eec82323
LMI
6522 (let ((header (gnus-summary-article-header article)))
6523 (when (< article 0)
6524 (cond
6525 ((memq article gnus-newsgroup-sparse)
6526 ;; This is a sparse gap article.
6527 (setq do-update-line article)
6528 (setq article (mail-header-id header))
16409b0b 6529 (setq sparse-header (gnus-read-header article))
eec82323
LMI
6530 (setq gnus-newsgroup-sparse
6531 (delq article gnus-newsgroup-sparse)))
6532 ((vectorp header)
6533 ;; It's a real article.
6534 (setq article (mail-header-id header)))
6535 (t
6536 ;; It is an extracted pseudo-article.
6537 (setq article 'pseudo)
6538 (gnus-request-pseudo-article header))))
6539
6540 (let ((method (gnus-find-method-for-group
6541 gnus-newsgroup-name)))
6748645f
LMI
6542 (when (and (eq (car method) 'nneething)
6543 (vectorp header))
23f87bed
MB
6544 (let ((dir (nneething-get-file-name
6545 (mail-header-id header))))
6546 (when (and (stringp dir)
6547 (file-directory-p dir))
eec82323
LMI
6548 (setq article 'nneething)
6549 (gnus-group-enter-directory dir))))))))
6550
6551 (cond
6552 ;; Refuse to select canceled articles.
6553 ((and (numberp article)
6554 gnus-summary-buffer
6555 (get-buffer gnus-summary-buffer)
6748645f 6556 (gnus-buffer-exists-p gnus-summary-buffer)
01c52d31 6557 (eq (cdr (with-current-buffer gnus-summary-buffer
eec82323
LMI
6558 (assq article gnus-newsgroup-reads)))
6559 gnus-canceled-mark))
6560 nil)
6561 ;; We first check `gnus-original-article-buffer'.
6562 ((and (get-buffer gnus-original-article-buffer)
6563 (numberp article)
01c52d31 6564 (with-current-buffer gnus-original-article-buffer
eec82323
LMI
6565 (and (equal (car gnus-original-article) group)
6566 (eq (cdr gnus-original-article) article))))
6567 (insert-buffer-substring gnus-original-article-buffer)
6568 'article)
6569 ;; Check the backlog.
6570 ((and gnus-keep-backlog
6571 (gnus-backlog-request-article group article (current-buffer)))
6572 'article)
6573 ;; Check asynchronous pre-fetch.
6574 ((gnus-async-request-fetched-article group article (current-buffer))
6575 (gnus-async-prefetch-next group article gnus-summary-buffer)
6748645f
LMI
6576 (when (and (numberp article) gnus-keep-backlog)
6577 (gnus-backlog-enter-article group article (current-buffer)))
eec82323
LMI
6578 'article)
6579 ;; Check the cache.
6580 ((and gnus-use-cache
6581 (numberp article)
6582 (gnus-cache-request-article article group))
6583 'article)
23f87bed
MB
6584 ;; Check the agent cache.
6585 ((gnus-agent-request-article article group)
6586 'article)
eec82323 6587 ;; Get the article and put into the article buffer.
16409b0b
GM
6588 ((or (stringp article)
6589 (numberp article))
6590 (let ((gnus-override-method gnus-override-method)
a1506d29 6591 (methods (and (stringp article)
16409b0b 6592 gnus-refer-article-method))
23f87bed
MB
6593 (backend (car (gnus-find-method-for-group
6594 gnus-newsgroup-name)))
16409b0b 6595 result
4e7d0221 6596 (inhibit-read-only t))
e0bad764
DL
6597 (if (or (not (listp methods))
6598 (and (symbolp (car methods))
6599 (assq (car methods) nnoo-definition-alist)))
6600 (setq methods (list methods)))
16409b0b
GM
6601 (when (and (null gnus-override-method)
6602 methods)
6603 (setq gnus-override-method (pop methods)))
6604 (while (not result)
6605 (when (eq gnus-override-method 'current)
c55f89a5
GM
6606 (setq gnus-override-method
6607 (with-current-buffer gnus-summary-buffer
6608 gnus-current-select-method)))
16409b0b
GM
6609 (erase-buffer)
6610 (gnus-kill-all-overlays)
6611 (let ((gnus-newsgroup-name group))
6612 (gnus-check-group-server))
23f87bed
MB
6613 (cond
6614 ((gnus-request-article article group (current-buffer))
16409b0b 6615 (when (numberp article)
a1506d29 6616 (gnus-async-prefetch-next group article
16409b0b
GM
6617 gnus-summary-buffer)
6618 (when gnus-keep-backlog
6619 (gnus-backlog-enter-article
6620 group article (current-buffer))))
6621 (setq result 'article))
23f87bed
MB
6622 (methods
6623 (setq gnus-override-method (pop methods)))
6624 ((not (string-match "^400 "
6625 (nnheader-get-report backend)))
6626 ;; If we get 400 server disconnect, reconnect and
6627 ;; retry; otherwise, assume the article has expired.
6628 (setq result 'done))))
16409b0b 6629 (and (eq result 'article) 'article)))
eec82323
LMI
6630 ;; It was a pseudo.
6631 (t article)))
6632
6748645f
LMI
6633 ;; Associate this article with the current summary buffer.
6634 (setq gnus-article-current-summary gnus-summary-buffer)
6635
eec82323
LMI
6636 ;; Take the article from the original article buffer
6637 ;; and place it in the buffer it's supposed to be in.
6638 (when (and (get-buffer gnus-article-buffer)
eec82323
LMI
6639 (equal (buffer-name (current-buffer))
6640 (buffer-name (get-buffer gnus-article-buffer))))
6641 (save-excursion
6642 (if (get-buffer gnus-original-article-buffer)
6748645f
LMI
6643 (set-buffer gnus-original-article-buffer)
6644 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 6645 (buffer-disable-undo)
eec82323 6646 (setq major-mode 'gnus-original-article-mode)
6748645f 6647 (setq buffer-read-only t))
23f87bed 6648 (let ((inhibit-read-only t))
eec82323
LMI
6649 (erase-buffer)
6650 (insert-buffer-substring gnus-article-buffer))
16409b0b
GM
6651 (setq gnus-original-article (cons group article)))
6652
6653 ;; Decode charsets.
6654 (run-hooks 'gnus-article-decode-hook)
6655 ;; Mark article as decoded or not.
6656 (setq gnus-article-decoded-p gnus-article-decode-hook))
eec82323
LMI
6657
6658 ;; Update sparse articles.
6659 (when (and do-update-line
6660 (or (numberp article)
6661 (stringp article)))
6662 (let ((buf (current-buffer)))
6663 (set-buffer gnus-summary-buffer)
6748645f 6664 (gnus-summary-update-article do-update-line sparse-header)
eec82323 6665 (gnus-summary-goto-subject do-update-line nil t)
23f87bed 6666 (set-window-point (gnus-get-buffer-window (current-buffer) t)
eec82323
LMI
6667 (point))
6668 (set-buffer buf))))))
6669
6670;;;
6671;;; Article editing
6672;;;
6673
6674(defcustom gnus-article-edit-mode-hook nil
6675 "Hook run in article edit mode buffers."
6676 :group 'gnus-article-various
6677 :type 'hook)
6678
6679(defvar gnus-article-edit-done-function nil)
6680
6681(defvar gnus-article-edit-mode-map nil)
6682
16409b0b 6683;; Should we be using derived.el for this?
eec82323 6684(unless gnus-article-edit-mode-map
23f87bed 6685 (setq gnus-article-edit-mode-map (make-keymap))
16409b0b 6686 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
eec82323
LMI
6687
6688 (gnus-define-keys gnus-article-edit-mode-map
23f87bed 6689 "\C-c?" describe-mode
eec82323 6690 "\C-c\C-c" gnus-article-edit-done
23f87bed
MB
6691 "\C-c\C-k" gnus-article-edit-exit
6692 "\C-c\C-f\C-t" message-goto-to
6693 "\C-c\C-f\C-o" message-goto-from
6694 "\C-c\C-f\C-b" message-goto-bcc
6695 ;;"\C-c\C-f\C-w" message-goto-fcc
6696 "\C-c\C-f\C-c" message-goto-cc
6697 "\C-c\C-f\C-s" message-goto-subject
6698 "\C-c\C-f\C-r" message-goto-reply-to
6699 "\C-c\C-f\C-n" message-goto-newsgroups
6700 "\C-c\C-f\C-d" message-goto-distribution
6701 "\C-c\C-f\C-f" message-goto-followup-to
6702 "\C-c\C-f\C-m" message-goto-mail-followup-to
6703 "\C-c\C-f\C-k" message-goto-keywords
6704 "\C-c\C-f\C-u" message-goto-summary
6705 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6706 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6707 "\C-c\C-b" message-goto-body
6708 "\C-c\C-i" message-goto-signature
6709
6710 "\C-c\C-t" message-insert-to
6711 "\C-c\C-n" message-insert-newsgroups
6712 "\C-c\C-o" message-sort-headers
6713 "\C-c\C-e" message-elide-region
6714 "\C-c\C-v" message-delete-not-region
6715 "\C-c\C-z" message-kill-to-signature
6716 "\M-\r" message-newline-and-reformat
6717 "\C-c\C-a" mml-attach-file
6718 "\C-a" message-beginning-of-line
6719 "\t" message-tab
6720 "\M-;" comment-region)
eec82323
LMI
6721
6722 (gnus-define-keys (gnus-article-edit-wash-map
6723 "\C-c\C-w" gnus-article-edit-mode-map)
6724 "f" gnus-article-edit-full-stops))
6725
23f87bed
MB
6726(easy-menu-define
6727 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6728 '("Field"
6729 ["Fetch To" message-insert-to t]
6730 ["Fetch Newsgroups" message-insert-newsgroups t]
6731 "----"
6732 ["To" message-goto-to t]
6733 ["From" message-goto-from t]
6734 ["Subject" message-goto-subject t]
6735 ["Cc" message-goto-cc t]
6736 ["Reply-To" message-goto-reply-to t]
6737 ["Summary" message-goto-summary t]
6738 ["Keywords" message-goto-keywords t]
6739 ["Newsgroups" message-goto-newsgroups t]
6740 ["Followup-To" message-goto-followup-to t]
6741 ["Mail-Followup-To" message-goto-mail-followup-to t]
6742 ["Distribution" message-goto-distribution t]
6743 ["Body" message-goto-body t]
6744 ["Signature" message-goto-signature t]))
6745
4e7d0221 6746(define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
eec82323
LMI
6747 "Major mode for editing articles.
6748This is an extended text-mode.
6749
6750\\{gnus-article-edit-mode-map}"
eec82323
LMI
6751 (make-local-variable 'gnus-article-edit-done-function)
6752 (make-local-variable 'gnus-prev-winconf)
80b47379
SZ
6753 (set (make-local-variable 'font-lock-defaults)
6754 '(message-font-lock-keywords t))
23f87bed
MB
6755 (set (make-local-variable 'mail-header-separator) "")
6756 (set (make-local-variable 'gnus-article-edit-mode) t)
6757 (easy-menu-add message-mode-field-menu message-mode-map)
6758 (mml-mode)
eec82323
LMI
6759 (setq buffer-read-only nil)
6760 (buffer-enable-undo)
80b47379 6761 (widen))
eec82323
LMI
6762
6763(defun gnus-article-edit (&optional force)
6764 "Edit the current article.
6765This will have permanent effect only in mail groups.
6766If FORCE is non-nil, allow editing of articles even in read-only
6767groups."
6768 (interactive "P")
6769 (when (and (not force)
6770 (gnus-group-read-only-p))
a8151ef7 6771 (error "The current newsgroup does not support article editing"))
6748645f 6772 (gnus-article-date-original)
eec82323 6773 (gnus-article-edit-article
16409b0b 6774 'ignore
6748645f 6775 `(lambda (no-highlight)
16409b0b 6776 'ignore
eec82323
LMI
6777 (gnus-summary-edit-article-done
6778 ,(or (mail-header-references gnus-current-headers) "")
6748645f 6779 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
eec82323 6780
01c52d31 6781(defun gnus-article-edit-article (start-func exit-func &optional quiet)
eec82323
LMI
6782 "Start editing the contents of the current article buffer."
6783 (let ((winconf (current-window-configuration)))
6784 (set-buffer gnus-article-buffer)
0683d241
MB
6785 (let ((message-auto-save-directory
6786 ;; Don't associate the article buffer with a draft file.
6787 nil))
6788 (gnus-article-edit-mode))
16409b0b 6789 (funcall start-func)
23f87bed 6790 (set-buffer-modified-p nil)
eec82323
LMI
6791 (gnus-configure-windows 'edit-article)
6792 (setq gnus-article-edit-done-function exit-func)
6793 (setq gnus-prev-winconf winconf)
01c52d31
MB
6794 (unless quiet
6795 (gnus-message 6 "C-c C-c to end edits"))))
eec82323 6796
6748645f 6797(defun gnus-article-edit-done (&optional arg)
eec82323 6798 "Update the article edits and exit."
6748645f 6799 (interactive "P")
eec82323
LMI
6800 (let ((func gnus-article-edit-done-function)
6801 (buf (current-buffer))
23f87bed
MB
6802 (start (window-start))
6803 (p (point))
6804 (winconf gnus-prev-winconf))
6805 (widen) ;; Widen it in case that users narrowed the buffer.
6806 (funcall func arg)
6807 (set-buffer buf)
6808 ;; The cache and backlog have to be flushed somewhat.
6809 (when gnus-keep-backlog
6810 (gnus-backlog-remove-article
6811 (car gnus-article-current) (cdr gnus-article-current)))
6812 ;; Flush original article as well.
80de1778
SM
6813 (when (get-buffer gnus-original-article-buffer)
6814 (with-current-buffer gnus-original-article-buffer
23f87bed
MB
6815 (setq gnus-original-article nil)))
6816 (when gnus-use-cache
6817 (gnus-cache-update-article
6818 (car gnus-article-current) (cdr gnus-article-current)))
6819 ;; We remove all text props from the article buffer.
6820 (kill-all-local-variables)
01c52d31 6821 (set-text-properties (point-min) (point-max) nil)
23f87bed
MB
6822 (gnus-article-mode)
6823 (set-window-configuration winconf)
eec82323
LMI
6824 (set-buffer buf)
6825 (set-window-start (get-buffer-window buf) start)
23f87bed
MB
6826 (set-window-point (get-buffer-window buf) (point)))
6827 (gnus-summary-show-article))
eec82323
LMI
6828
6829(defun gnus-article-edit-exit ()
6830 "Exit the article editing without updating."
6831 (interactive)
23f87bed
MB
6832 (when (or (not (buffer-modified-p))
6833 (yes-or-no-p "Article modified; kill anyway? "))
6834 (let ((curbuf (current-buffer))
6835 (p (point))
6836 (window-start (window-start)))
6837 (erase-buffer)
6838 (if (gnus-buffer-live-p gnus-original-article-buffer)
d8a88581 6839 (insert-buffer-substring gnus-original-article-buffer))
23f87bed
MB
6840 (let ((winconf gnus-prev-winconf))
6841 (kill-all-local-variables)
6842 (gnus-article-mode)
6843 (set-window-configuration winconf)
6844 ;; Tippy-toe some to make sure that point remains where it was.
6845 (save-current-buffer
6846 (set-buffer curbuf)
6847 (set-window-start (get-buffer-window (current-buffer)) window-start)
6848 (goto-char p))))
6849 (gnus-summary-show-article)))
eec82323
LMI
6850
6851(defun gnus-article-edit-full-stops ()
6852 "Interactively repair spacing at end of sentences."
6853 (interactive)
6854 (save-excursion
6855 (goto-char (point-min))
6856 (search-forward-regexp "^$" nil t)
6857 (let ((case-fold-search nil))
6858 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6859
6860;;;
6861;;; Article highlights
6862;;;
6863
6864;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6865
6866;;; Internal Variables:
6867
a1506d29 6868(defcustom gnus-button-url-regexp
01c52d31
MB
6869 (concat
6870 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6871 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6872 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6873 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6874 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6875 (punct "!?:;.,"))
6876 (concat
6877 "\\(?:"
6878 ;; Match paired parentheses, e.g. in Wikipedia URLs:
6879 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6880 "\\|"
6881 "[" chars punct "]+" "[" chars "]"
6882 "\\)"))
6883 (concat ;; XEmacs 21.4 doesn't support POSIX.
6884 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6885 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6886 "\\)")
eec82323
LMI
6887 "Regular expression that matches URLs."
6888 :group 'gnus-article-buttons
6889 :type 'regexp)
6890
23f87bed
MB
6891(defcustom gnus-button-valid-fqdn-regexp
6892 message-valid-fqdn-regexp
6893 "Regular expression that matches a valid FQDN."
bf247b6e 6894 :version "22.1"
23f87bed
MB
6895 :group 'gnus-article-buttons
6896 :type 'regexp)
6897
97f78c9b
MB
6898;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6899(defcustom gnus-button-valid-localpart-regexp
14e6dc54 6900 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
97f78c9b
MB
6901 "Regular expression that matches a localpart of mail addresses or MIDs."
6902 :version "22.1"
6903 :group 'gnus-article-buttons
6904 :type 'regexp)
6905
23f87bed
MB
6906(defcustom gnus-button-man-handler 'manual-entry
6907 "Function to use for displaying man pages.
6908The function must take at least one argument with a string naming the
6909man page."
bf247b6e 6910 :version "22.1"
23f87bed
MB
6911 :type '(choice (function-item :tag "Man" manual-entry)
6912 (function-item :tag "Woman" woman)
6913 (function :tag "Other"))
6914 :group 'gnus-article-buttons)
6915
6916(defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6917 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6918If the default site is too slow, try to find a CTAN mirror, see
6919<URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6920the variable `gnus-button-handle-ctan'."
bf247b6e 6921 :version "22.1"
23f87bed
MB
6922 :group 'gnus-article-buttons
6923 :link '(custom-manual "(gnus)Group Parameters")
6924 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6925 (const "http://tug.ctan.org/tex-archive/")
6926 (const "http://www.dante.de/CTAN/")
6927 (string :tag "Other")))
6928
6929(defcustom gnus-button-ctan-handler 'browse-url
6930 "Function to use for displaying CTAN links.
6931The function must take one argument, the string naming the URL."
bf247b6e 6932 :version "22.1"
23f87bed
MB
6933 :type '(choice (function-item :tag "Browse Url" browse-url)
6934 (function :tag "Other"))
6935 :group 'gnus-article-buttons)
6936
6937(defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6938 "Bogus strings removed from CTAN URLs."
bf247b6e 6939 :version "22.1"
23f87bed
MB
6940 :group 'gnus-article-buttons
6941 :type '(choice (const "^/?tex-archive/\\|/")
6942 (regexp :tag "Other")))
6943
6944(defcustom gnus-button-ctan-directory-regexp
97f78c9b
MB
6945 (regexp-opt
6946 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6947 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6948 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6949 "tds" "tools" "usergrps" "web") t)
23f87bed
MB
6950 "Regular expression for ctan directories.
6951It should match all directories in the top level of `gnus-ctan-url'."
bf247b6e 6952 :version "22.1"
23f87bed
MB
6953 :group 'gnus-article-buttons
6954 :type 'regexp)
6955
6956(defcustom gnus-button-mid-or-mail-regexp
97f78c9b 6957 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
23f87bed
MB
6958 gnus-button-valid-fqdn-regexp
6959 ">?\\)\\b")
6960 "Regular expression that matches a message ID or a mail address."
bf247b6e 6961 :version "22.1"
23f87bed
MB
6962 :group 'gnus-article-buttons
6963 :type 'regexp)
6964
6965(defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6966 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6967Strings like this can be either a message ID or a mail address. If it is one
6968of the symbols `mid' or `mail', Gnus will always assume that the string is a
6969message ID or a mail address, respectively. If this variable is set to the
6970symbol `ask', always query the user what do do. If it is a function, this
aa819354 6971function will be called with the string as its only argument. The function
23f87bed 6972must return `mid', `mail', `invalid' or `ask'."
bf247b6e 6973 :version "22.1"
23f87bed
MB
6974 :group 'gnus-article-buttons
6975 :type '(choice (function-item :tag "Heuristic function"
6976 gnus-button-mid-or-mail-heuristic)
6977 (const ask)
6978 (const mid)
6979 (const mail)))
6980
6981(defcustom gnus-button-mid-or-mail-heuristic-alist
6982 '((-10.0 . ".+\\$.+@")
6983 (-10.0 . "#")
6984 (-10.0 . "\\*")
6985 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6986 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6987 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6988 (-1.0 . "^[^a-z]+@")
6989 ;;
6990 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6991 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6992 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6993 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6994 ;;
6995 (-2.0 . "^[0-9]")
6996 (-1.0 . "^[0-9][0-9]")
6997 ;;
6998 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6999 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7000 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7001 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7002 ;;
7003 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7004 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7005 ;; "[0-9]{8,}.*\@"
7006 (-3.0
7007 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7008 ;; "[0-9]{12,}.*\@"
7009 ;; compensation for TDMA dated mail addresses:
7010 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7011 ;;
7012 (-20.0 . "\\.fsf@") ;; Gnus
7013 (-20.0 . "^slrn")
7014 (-20.0 . "^Pine")
437ce4be 7015 (-20.0 . "^alpine\\.")
23f87bed
MB
7016 (-20.0 . "_-_") ;; Subject change in thread
7017 ;;
7018 (-20.0 . "\\.ln@") ;; leafnode
7019 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7020 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7021 ;;
7022 ;; (5.0 . "") ;; $local_part_len <= 7
7023 (10.0 . "^[^0-9]+@")
7024 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7025 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7026 (3.0 . "\@stud")
7027 ;;
7028 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7029 ;;
7030 (0.5 . "^[A-Z][a-z]")
7031 (0.5 . "^[A-Z][a-z][a-z]")
7032 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7033 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7034 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7035
7036A negative RATE indicates a message IDs, whereas a positive indicates a mail
7037address. The REGEXP is processed with `case-fold-search' set to nil."
bf247b6e 7038 :version "22.1"
23f87bed
MB
7039 :group 'gnus-article-buttons
7040 :type '(repeat (cons (number :tag "Rate")
7041 (regexp :tag "Regexp"))))
7042
7043(defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7044 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7045Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7046address, `ask' if unsure and `invalid' if the string is invalid."
7047 (let ((case-fold-search nil)
7048 (list gnus-button-mid-or-mail-heuristic-alist)
7049 (result 0) rate regexp lpartlen elem)
7050 (setq lpartlen
7051 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7052 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7053 ;; Certain special cases...
7054 (when (string-match
7055 (concat
7056 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7057 "^[0-9]+\\.[0-9]+@compuserve\\|"
7058 "@public\\.gmane\\.org")
7059 mid-or-mail)
7060 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7061 (setq result 'mail))
7062 (when (string-match "@.*@\\| " mid-or-mail)
7063 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7064 (setq result 'invalid))
7065 ;; Nothing more to do, if result is not a number here...
7066 (when (numberp result)
7067 (while list
7068 (setq elem (car list)
7069 rate (car elem)
7070 regexp (cdr elem)
7071 list (cdr list))
7072 (when (string-match regexp mid-or-mail)
7073 (setq result (+ result rate))
7074 (gnus-message
7075 9 "`%s' matched `%s', rate `%s', result `%s'."
7076 mid-or-mail regexp rate result)))
7077 (when (<= lpartlen 7)
7078 (setq result (+ result 5.0))
7079 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7080 mid-or-mail result))
7081 (when (>= lpartlen 12)
7082 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7083 (cond
7084 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7085 ;; Long local part should contain realname if e-mail address,
7086 ;; too many digits: message-id.
7087 ;; $score -= 5.0 + 0.1 * $local_part_len;
7088 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7089 (setq result (+ result rate))
7090 (gnus-message
7091 9 "Many digits in `%s', rate `%s', result `%s'."
7092 mid-or-mail rate result))
7093 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7094 mid-or-mail)
7095 ;; Too few vowels [^aeiouy]{4,}.*\@
7096 (setq result (+ result -5.0))
7097 (gnus-message
7098 9 "Few vowels in `%s', rate `%s', result `%s'."
7099 mid-or-mail -5.0 result))
7100 (t
7101 (setq result (+ result 5.0))
7102 (gnus-message
7103 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7104 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7105 ;; Maybe we should make this a customizable alist: (condition . 'result)
7106 (cond
7107 ((symbolp result) result)
7108 ;; Now convert number into proper results:
7109 ((< result -10.0) 'mid)
7110 ((> result 10.0) 'mail)
7111 (t 'ask))))
7112
7113(defun gnus-button-handle-mid-or-mail (mid-or-mail)
7114 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7115 (url-mid (concat "news" ":" mid-or-mail))
7116 (url-mailto (concat "mailto" ":" mid-or-mail)))
7117 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7118 (when (fboundp pref)
7119 (setq guessed
7120 ;; get rid of surrounding angles...
7121 (funcall pref
7122 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7123 (if (or (eq 'mid guessed) (eq 'mail guessed))
7124 (setq pref guessed)
7125 (setq pref 'ask)))
7126 (if (eq pref 'ask)
7127 (save-window-excursion
7128 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7129 (setq pref 'mail)
7130 (setq pref 'mid))))
7131 (cond ((eq pref 'mid)
7132 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7133 (gnus-button-handle-news url-mid))
7134 ((eq pref 'mail)
7135 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7136 (gnus-url-mailto url-mailto))
7137 (t (gnus-message 3 "Invalid string.")))))
7138
01c52d31
MB
7139(defun gnus-button-handle-custom (fun arg)
7140 "Call function FUN on argument ARG.
7141Both FUN and ARG are supposed to be strings. ARG will be passed
7142as a symbol to FUN."
7143 (funcall (intern fun)
7144 (if (string-match "^customize-apropos" fun)
7145 arg
7146 (intern arg))))
23f87bed
MB
7147
7148(defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7149
7150;; FIXME: Maybe we should merge some of the functions that do quite similar
7151;; stuff?
7152
7153(defun gnus-button-handle-describe-function (url)
7154 "Call `describe-function' when pushing the corresponding URL button."
7155 (describe-function
7156 (intern
7157 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7158
7159(defun gnus-button-handle-describe-variable (url)
7160 "Call `describe-variable' when pushing the corresponding URL button."
7161 (describe-variable
7162 (intern
7163 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7164
7165(defun gnus-button-handle-symbol (url)
7166"Display help on variable or function.
7167Calls `describe-variable' or `describe-function'."
7168 (let ((sym (intern url)))
7169 (cond
7170 ((fboundp sym) (describe-function sym))
7171 ((boundp sym) (describe-variable sym))
7172 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7173
7174(defun gnus-button-handle-describe-key (url)
7175 "Call `describe-key' when pushing the corresponding URL button."
7176 (let* ((key-string
7177 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7178 (keys (ignore-errors (eval `(kbd ,key-string)))))
7179 (if keys
7180 (describe-key keys)
7181 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7182
7183(defun gnus-button-handle-apropos (url)
7184 "Call `apropos' when pushing the corresponding URL button."
7185 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7186
7187(defun gnus-button-handle-apropos-command (url)
7188 "Call `apropos' when pushing the corresponding URL button."
7189 (apropos-command
7190 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7191
7192(defun gnus-button-handle-apropos-variable (url)
7193 "Call `apropos' when pushing the corresponding URL button."
7194 (funcall
7195 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7196 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7197
7198(defun gnus-button-handle-apropos-documentation (url)
7199 "Call `apropos' when pushing the corresponding URL button."
7200 (funcall
7201 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7202 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7203
7204(defun gnus-button-handle-library (url)
7205 "Call `locate-library' when pushing the corresponding URL button."
7206 (gnus-message 9 "url=`%s'" url)
7207 (let* ((lib (locate-library url))
7208 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7209 (if (not lib)
7210 (gnus-message 1 "Cannot locale library `%s'." url)
7211 (find-file-read-only file))))
7212
7213(defun gnus-button-handle-ctan (url)
7214 "Call `browse-url' when pushing a CTAN URL button."
7215 (funcall
7216 gnus-button-ctan-handler
7217 (concat
7218 gnus-ctan-url
7219 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7220
7221(defcustom gnus-button-tex-level 5
7222 "*Integer that says how many TeX-related buttons Gnus will show.
7223The higher the number, the more buttons will appear and the more false
7224positives are possible. Note that you can set this variable local to
7225specific groups. Setting it higher in TeX groups is probably a good idea.
7226See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7227how to set variables in specific groups."
bf247b6e 7228 :version "22.1"
23f87bed
MB
7229 :group 'gnus-article-buttons
7230 :link '(custom-manual "(gnus)Group Parameters")
7231 :type 'integer)
7232
7233(defcustom gnus-button-man-level 5
7234 "*Integer that says how many man-related buttons Gnus will show.
7235The higher the number, the more buttons will appear and the more false
7236positives are possible. Note that you can set this variable local to
7237specific groups. Setting it higher in Unix groups is probably a good idea.
7238See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7239how to set variables in specific groups."
bf247b6e 7240 :version "22.1"
23f87bed
MB
7241 :group 'gnus-article-buttons
7242 :link '(custom-manual "(gnus)Group Parameters")
7243 :type 'integer)
7244
7245(defcustom gnus-button-emacs-level 5
7246 "*Integer that says how many emacs-related buttons Gnus will show.
7247The higher the number, the more buttons will appear and the more false
7248positives are possible. Note that you can set this variable local to
7249specific groups. Setting it higher in Emacs or Gnus related groups is
7250probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7251`gnus-parameters' on how to set variables in specific groups."
bf247b6e 7252 :version "22.1"
23f87bed
MB
7253 :group 'gnus-article-buttons
7254 :link '(custom-manual "(gnus)Group Parameters")
7255 :type 'integer)
7256
7257(defcustom gnus-button-message-level 5
7258 "*Integer that says how many buttons for news or mail messages will appear.
7259The higher the number, the more buttons will appear and the more false
7260positives are possible."
7261 ;; mail addresses, MIDs, URLs for news, ...
bf247b6e 7262 :version "22.1"
23f87bed
MB
7263 :group 'gnus-article-buttons
7264 :type 'integer)
7265
7266(defcustom gnus-button-browse-level 5
7267 "*Integer that says how many buttons for browsing will appear.
7268The higher the number, the more buttons will appear and the more false
7269positives are possible."
7270 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
bf247b6e 7271 :version "22.1"
23f87bed
MB
7272 :group 'gnus-article-buttons
7273 :type 'integer)
7274
eec82323 7275(defcustom gnus-button-alist
23f87bed
MB
7276 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7277 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
97f78c9b
MB
7278 ((concat "\\b\\(nntp\\|news\\):\\("
7279 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7280 0 t gnus-button-handle-news 2)
23f87bed
MB
7281 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7282 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7283 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7284 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7285 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7286 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7287 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7288 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7289 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
01c52d31
MB
7290 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7291 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
23f87bed
MB
7292 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7293 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7294 ;; RFC 2368 (The mailto URL scheme)
531e5812 7295 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7296 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7297 ("\\bmailto:\\([^ \n\t]+\\)"
7298 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7299 ;; CTAN
7300 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7301 gnus-button-ctan-directory-regexp
7302 "[^][>)!;:,'\n\t ]+\\)")
7303 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7304 ((concat "\\btex-archive/\\("
7305 gnus-button-ctan-directory-regexp
7306 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7307 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7308 ((concat
7309 "\\b\\("
7310 gnus-button-ctan-directory-regexp
7311 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7312 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7313 ;; This is info (home-grown style) <info://foo/bar+baz>
7314 ("\\binfo://\\([^'\">\n\t ]+\\)"
7315 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7316 ;; Info GNOME style <info:foo#bar_baz>
7317 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7318 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7319 ;; Info KDE style <info:(foo)bar baz>
7320 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7321 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7322 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7323 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7324 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7325 ;; Info links like `C-h i d m CC Mode RET'
7326 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
7327 ;; This is custom
01c52d31
MB
7328 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7329 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
23f87bed
MB
7330 ;; Emacs help commands
7331 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7332 ;; regexp doesn't match arguments containing ` '.
7333 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7334 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7335 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7336 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7337 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7338 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7339 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7340 ;; The following entries may lead to many false positives so don't enable
531e5812
MB
7341 ;; them by default (use a high button level).
7342 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7343 ;; Exclude [.?] for URLs in gmane.emacs.cvs
23f87bed
MB
7344 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7345 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7346 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
01c52d31 7347 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
23f87bed
MB
7348 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7349 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7350 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7351 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7352 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7353 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7354 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7355 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7356 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7357 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7358 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
87ba2830 7359 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
23f87bed
MB
7360 ;; Unlike the other regexps we really have to require quoting
7361 ;; here to determine where it ends.
7362 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7363 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
01c52d31 7364 ("<URL: *\\([^\n<>]*\\)>"
23f87bed
MB
7365 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7366 ;; RFC 2396 (2.4.3., delims) ...
01c52d31 7367 ("\"URL: *\\([^\n\"]*\\)\""
23f87bed 7368 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
eec82323 7369 ;; Raw URLs.
23f87bed
MB
7370 (gnus-button-url-regexp
7371 0 (>= gnus-button-browse-level 0) browse-url 0)
7372 ;; man pages
531e5812 7373 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
23f87bed
MB
7374 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7375 gnus-button-handle-man 1)
7376 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
531e5812 7377 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
23f87bed
MB
7378 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7379 gnus-button-handle-man 1)
7380 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7381 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
531e5812 7382 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
23f87bed 7383 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
01c52d31
MB
7384 ;; Recognizing patches to .el files. This is somewhat obscure,
7385 ;; but considering the percentage of Gnus users who hack Emacs
7386 ;; Lisp files...
7387 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7388 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7389 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7390 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
23f87bed
MB
7391 ;; MID or mail: To avoid too many false positives we don't try to catch
7392 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7393 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7394 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7395 ;; so that non-ambiguous entries (see above) match first.
7396 (gnus-button-mid-or-mail-regexp
7397 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6748645f 7398 "*Alist of regexps matching buttons in article bodies.
eec82323
LMI
7399
7400Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
23f87bed
MB
7401REGEXP: is the string (case insensitive) matching text around the button (can
7402also be Lisp expression evaluating to a string),
eec82323 7403BUTTON: is the number of the regexp grouping actually matching the button,
4e7d0221 7404FORM: is a Lisp expression which must eval to true for the button to
eec82323
LMI
7405be added,
7406CALLBACK: is the function to call when the user push this button, and each
7407PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7408
7409CALLBACK can also be a variable, in that case the value of that
7410variable it the real callback function."
7411 :group 'gnus-article-buttons
23f87bed 7412 :type '(repeat (list (choice regexp variable sexp)
eec82323
LMI
7413 (integer :tag "Button")
7414 (sexp :tag "Form")
7415 (function :tag "Callback")
7416 (repeat :tag "Par"
7417 :inline t
7418 (integer :tag "Regexp group")))))
60ece9b0 7419(put 'gnus-button-alist 'risky-local-variable t)
eec82323
LMI
7420
7421(defcustom gnus-header-button-alist
23f87bed
MB
7422 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7423 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7424 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7425 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
eec82323 7426 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
fa9a04e1 7427 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
23f87bed
MB
7428 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7429 0 (>= gnus-button-browse-level 0) browse-url 0)
7430 ("^Subject:" gnus-button-url-regexp
7431 0 (>= gnus-button-browse-level 0) browse-url 0)
7432 ("^[^:]+:" gnus-button-url-regexp
7433 0 (>= gnus-button-browse-level 0) browse-url 0)
01c52d31
MB
7434 ("^OpenPGP:.*url=" gnus-button-url-regexp
7435 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
531e5812 7436 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7437 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7438 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7439 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6748645f 7440 "*Alist of headers and regexps to match buttons in article heads.
eec82323
LMI
7441
7442This alist is very similar to `gnus-button-alist', except that each
7443alist has an additional HEADER element first in each entry:
7444
7445\(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7446
7447HEADER is a regexp to match a header. For a fuller explanation, see
7448`gnus-button-alist'."
7449 :group 'gnus-article-buttons
7450 :group 'gnus-article-headers
7451 :type '(repeat (list (regexp :tag "Header")
23f87bed 7452 (choice regexp variable)
eec82323
LMI
7453 (integer :tag "Button")
7454 (sexp :tag "Form")
7455 (function :tag "Callback")
7456 (repeat :tag "Par"
7457 :inline t
7458 (integer :tag "Regexp group")))))
60ece9b0 7459(put 'gnus-header-button-alist 'risky-local-variable t)
eec82323 7460
eec82323
LMI
7461;;; Commands:
7462
7463(defun gnus-article-push-button (event)
7464 "Check text under the mouse pointer for a callback function.
7465If the text under the mouse pointer has a `gnus-callback' property,
7466call it with the value of the `gnus-data' text property."
7467 (interactive "e")
7468 (set-buffer (window-buffer (posn-window (event-start event))))
7469 (let* ((pos (posn-point (event-start event)))
23f87bed 7470 (data (get-text-property pos 'gnus-data))
eec82323 7471 (fun (get-text-property pos 'gnus-callback)))
6748645f 7472 (goto-char pos)
eec82323
LMI
7473 (when fun
7474 (funcall fun data))))
7475
7476(defun gnus-article-press-button ()
7477 "Check text at point for a callback function.
7478If the text at point has a `gnus-callback' property,
7479call it with the value of the `gnus-data' text property."
7480 (interactive)
23f87bed
MB
7481 (let ((data (get-text-property (point) 'gnus-data))
7482 (fun (get-text-property (point) 'gnus-callback)))
eec82323
LMI
7483 (when fun
7484 (funcall fun data))))
7485
eec82323
LMI
7486(defun gnus-article-highlight (&optional force)
7487 "Highlight current article.
7488This function calls `gnus-article-highlight-headers',
7489`gnus-article-highlight-citation',
7490`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7491do the highlighting. See the documentation for those functions."
7492 (interactive (list 'force))
7493 (gnus-article-highlight-headers)
7494 (gnus-article-highlight-citation force)
7495 (gnus-article-highlight-signature)
7496 (gnus-article-add-buttons force)
7497 (gnus-article-add-buttons-to-head))
7498
7499(defun gnus-article-highlight-some (&optional force)
7500 "Highlight current article.
7501This function calls `gnus-article-highlight-headers',
7502`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7503do the highlighting. See the documentation for those functions."
7504 (interactive (list 'force))
7505 (gnus-article-highlight-headers)
7506 (gnus-article-highlight-signature)
7507 (gnus-article-add-buttons))
7508
7509(defun gnus-article-highlight-headers ()
7510 "Highlight article headers as specified by `gnus-header-face-alist'."
7511 (interactive)
01c52d31
MB
7512 (gnus-with-article-headers
7513 (let (regexp header-face field-face from hpoints fpoints)
7514 (dolist (entry gnus-header-face-alist)
7515 (goto-char (point-min))
7516 (setq regexp (concat "^\\("
7517 (if (string-equal "" (nth 0 entry))
7518 "[^\t ]"
7519 (nth 0 entry))
7520 "\\)")
7521 header-face (nth 1 entry)
7522 field-face (nth 2 entry))
7523 (while (and (re-search-forward regexp nil t)
7524 (not (eobp)))
7525 (beginning-of-line)
7526 (setq from (point))
7527 (unless (search-forward ":" nil t)
7528 (forward-char 1))
7529 (when (and header-face
7530 (not (memq (point) hpoints)))
7531 (push (point) hpoints)
7532 (gnus-put-text-property from (point) 'face header-face))
7533 (when (and field-face
7534 (not (memq (setq from (point)) fpoints)))
7535 (push from fpoints)
7536 (if (re-search-forward "^[^ \t]" nil t)
7537 (forward-char -2)
7538 (goto-char (point-max)))
7539 (gnus-put-text-property from (point) 'face field-face)))))))
eec82323
LMI
7540
7541(defun gnus-article-highlight-signature ()
7542 "Highlight the signature in an article.
7543It does this by highlighting everything after
0f49874b 7544`gnus-signature-separator' using the face `gnus-signature'."
eec82323 7545 (interactive)
01c52d31
MB
7546 (gnus-with-article-buffer
7547 (let ((inhibit-point-motion-hooks t))
eec82323
LMI
7548 (save-restriction
7549 (when (and gnus-signature-face
7550 (gnus-article-narrow-to-signature))
01c52d31 7551 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
eec82323
LMI
7552 'face gnus-signature-face)
7553 (widen)
7554 (gnus-article-search-signature)
7555 (let ((start (match-beginning 0))
7556 (end (set-marker (make-marker) (1+ (match-end 0)))))
7557 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7558 end)))))))
7559
7560(defun gnus-button-in-region-p (b e prop)
7561 "Say whether PROP exists in the region."
7562 (text-property-not-all b e prop nil))
7563
7564(defun gnus-article-add-buttons (&optional force)
7565 "Find external references in the article and make buttons of them.
7566\"External references\" are things like Message-IDs and URLs, as
7567specified by `gnus-button-alist'."
7568 (interactive (list 'force))
01c52d31
MB
7569 (gnus-with-article-buffer
7570 (let ((inhibit-point-motion-hooks t)
eec82323
LMI
7571 (case-fold-search t)
7572 (alist gnus-button-alist)
7573 beg entry regexp)
7574 ;; Remove all old markers.
16409b0b 7575 (let (marker entry new-list)
eec82323 7576 (while (setq marker (pop gnus-button-marker-list))
16409b0b
GM
7577 (if (or (< marker (point-min)) (>= marker (point-max)))
7578 (push marker new-list)
7579 (goto-char marker)
7580 (when (setq entry (gnus-button-entry))
7581 (put-text-property (match-beginning (nth 1 entry))
7582 (match-end (nth 1 entry))
7583 'gnus-callback nil))
7584 (set-marker marker nil)))
7585 (setq gnus-button-marker-list new-list))
eec82323 7586 ;; We skip the headers.
16409b0b 7587 (article-goto-body)
eec82323
LMI
7588 (setq beg (point))
7589 (while (setq entry (pop alist))
23f87bed 7590 (setq regexp (eval (car entry)))
eec82323
LMI
7591 (goto-char beg)
7592 (while (re-search-forward regexp nil t)
01c52d31
MB
7593 (let ((start (match-beginning (nth 1 entry)))
7594 (end (match-end (nth 1 entry)))
7595 (from (match-beginning 0)))
eec82323
LMI
7596 (when (and (or (eq t (nth 2 entry))
7597 (eval (nth 2 entry)))
7598 (not (gnus-button-in-region-p
7599 start end 'gnus-callback)))
7600 ;; That optional form returned non-nil, so we add the
7601 ;; button.
01c52d31
MB
7602 (setq from (set-marker (make-marker) from))
7603 (push from gnus-button-marker-list)
7604 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7605 (gnus-article-extend-url-button from start end))
7606 (gnus-article-add-button start end
7607 'gnus-button-push from)))))))))
7608
7609(defun gnus-article-extend-url-button (beg start end)
7610 "Extend url button if url is folded into two or more lines.
7611Return non-nil if button is extended. BEG is a marker that points to
7612the beginning position of a text containing url. START and END are
7613the endpoints of a url button before it is extended. The concatenated
7614url is put as the `gnus-button-url' overlay property on the button."
7615 (let ((opoint (point))
7616 (points (list start end))
7617 url delim regexp)
7618 (prog1
7619 (when (and (progn
7620 (goto-char end)
7621 (not (looking-at "[\t ]*[\">]")))
7622 (progn
7623 (goto-char start)
7624 (string-match
7625 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7626 (buffer-substring (point-at-bol) start)))
7627 (progn
7628 (setq url (list (buffer-substring start end))
7629 delim (if (match-beginning 1) ">" "\""))
7630 (beginning-of-line)
7631 (setq regexp (concat
7632 (when (and (looking-at
7633 message-cite-prefix-regexp)
7634 (< (match-end 0) start))
7635 (regexp-quote (match-string 0)))
7636 "\
7637\[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7638 delim "\\)"))
7639 (while (progn
7640 (forward-line 1)
7641 (and (looking-at regexp)
7642 (prog1
7643 (match-beginning 1)
7644 (push (or (match-string 2)
7645 (match-string 1))
7646 url)
7647 (push (setq end (or (match-end 2)
7648 (match-end 1)))
7649 points)
7650 (push (or (match-beginning 2)
7651 (match-beginning 1))
7652 points)))))
7653 (match-beginning 2)))
7654 (let (gnus-article-mouse-face widget-mouse-face)
7655 (while points
7656 (gnus-article-add-button (pop points) (pop points)
7657 'gnus-button-push beg)))
7658 (let ((overlay (gnus-make-overlay start end)))
7659 (gnus-overlay-put overlay 'evaporate t)
7660 (gnus-overlay-put overlay 'gnus-button-url
7661 (list (mapconcat 'identity (nreverse url) "")))
7662 (when gnus-article-mouse-face
7663 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7664 t)
7665 (goto-char opoint))))
eec82323
LMI
7666
7667;; Add buttons to the head of an article.
7668(defun gnus-article-add-buttons-to-head ()
7669 "Add buttons to the head of the article."
7670 (interactive)
01c52d31
MB
7671 (gnus-with-article-headers
7672 (let (beg end)
7673 (dolist (entry gnus-header-button-alist)
7674 ;; Each alist entry.
7675 (goto-char (point-min))
7676 (while (re-search-forward (car entry) nil t)
7677 ;; Each header matching the entry.
7678 (setq beg (match-beginning 0))
7679 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7680 (match-beginning 0))
7681 (point-max)))
7682 (goto-char beg)
7683 (while (re-search-forward (eval (nth 1 entry)) end t)
7684 ;; Each match within a header.
7685 (let* ((entry (cdr entry))
7686 (start (match-beginning (nth 1 entry)))
7687 (end (match-end (nth 1 entry)))
7688 (form (nth 2 entry)))
7689 (goto-char (match-end 0))
7690 (when (eval form)
7691 (gnus-article-add-button
7692 start end (nth 3 entry)
7693 (buffer-substring (match-beginning (nth 4 entry))
7694 (match-end (nth 4 entry)))))))
7695 (goto-char end))))))
eec82323
LMI
7696
7697;;; External functions:
7698
7699(defun gnus-article-add-button (from to fun &optional data)
7700 "Create a button between FROM and TO with callback FUN and data DATA."
7701 (when gnus-article-button-face
01c52d31 7702 (gnus-overlay-put (gnus-make-overlay from to nil t)
eec82323
LMI
7703 'face gnus-article-button-face))
7704 (gnus-add-text-properties
7705 from to
7706 (nconc (and gnus-article-mouse-face
7707 (list gnus-mouse-face-prop gnus-article-mouse-face))
7708 (list 'gnus-callback fun)
16409b0b
GM
7709 (and data (list 'gnus-data data))))
7710 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7711 :button-keymap gnus-widget-button-keymap))
eec82323
LMI
7712
7713;;; Internal functions:
7714
a8151ef7 7715(defun gnus-article-set-globals ()
01c52d31 7716 (with-current-buffer gnus-summary-buffer
a8151ef7
LMI
7717 (gnus-set-global-variables)))
7718
eec82323 7719(defun gnus-signature-toggle (end)
01c52d31
MB
7720 (gnus-with-article-buffer
7721 (let ((inhibit-point-motion-hooks t))
520aa572 7722 (if (text-property-any end (point-max) 'article-type 'signature)
23f87bed
MB
7723 (progn
7724 (gnus-delete-wash-type 'signature)
7725 (gnus-remove-text-properties-when
7726 'article-type 'signature end (point-max)
7727 (cons 'article-type (cons 'signature
7728 gnus-hidden-properties))))
7729 (gnus-add-wash-type 'signature)
520aa572
SZ
7730 (gnus-add-text-properties-when
7731 'article-type nil end (point-max)
7732 (cons 'article-type (cons 'signature
23f87bed
MB
7733 gnus-hidden-properties)))))
7734 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7735 (gnus-set-mode-line 'article))))
eec82323
LMI
7736
7737(defun gnus-button-entry ()
7738 ;; Return the first entry in `gnus-button-alist' matching this place.
7739 (let ((alist gnus-button-alist)
7740 (entry nil))
7741 (while alist
7742 (setq entry (pop alist))
23f87bed 7743 (if (looking-at (eval (car entry)))
eec82323
LMI
7744 (setq alist nil)
7745 (setq entry nil)))
7746 entry))
7747
7748(defun gnus-button-push (marker)
7749 ;; Push button starting at MARKER.
7750 (save-excursion
eec82323
LMI
7751 (goto-char marker)
7752 (let* ((entry (gnus-button-entry))
7753 (inhibit-point-motion-hooks t)
7754 (fun (nth 3 entry))
01c52d31
MB
7755 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7756 (get-char-property marker 'gnus-button-url))
7757 (mapcar (lambda (group)
7758 (let ((string (match-string group)))
7759 (set-text-properties
7760 0 (length string) nil string)
7761 string))
7762 (nthcdr 4 entry)))))
eec82323
LMI
7763 (cond
7764 ((fboundp fun)
7765 (apply fun args))
7766 ((and (boundp fun)
7767 (fboundp (symbol-value fun)))
7768 (apply (symbol-value fun) args))
7769 (t
7770 (gnus-message 1 "You must define `%S' to use this button"
7771 (cons fun args)))))))
7772
23f87bed 7773(defun gnus-parse-news-url (url)
82a8ad04 7774 (let (scheme server port group message-id articles)
23f87bed
MB
7775 (with-temp-buffer
7776 (insert url)
7777 (goto-char (point-min))
7778 (when (looking-at "\\([A-Za-z]+\\):")
7779 (setq scheme (match-string 1))
7780 (goto-char (match-end 0)))
82a8ad04 7781 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
23f87bed 7782 (setq server (match-string 1))
82a8ad04
MB
7783 (setq port (if (stringp (match-string 3))
7784 (string-to-number (match-string 3))
7785 (match-string 3)))
23f87bed
MB
7786 (goto-char (match-end 0)))
7787
7788 (cond
7789 ((looking-at "\\(.*@.*\\)")
7790 (setq message-id (match-string 1)))
7791 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7792 (setq group (match-string 1)
7793 articles (split-string (match-string 2) "-")))
7794 ((looking-at "\\([^/]+\\)/?")
7795 (setq group (match-string 1)))
7796 (t
7797 (error "Unknown news URL syntax"))))
82a8ad04 7798 (list scheme server port group message-id articles)))
23f87bed
MB
7799
7800(defun gnus-button-handle-news (url)
7801 "Fetch a news URL."
82a8ad04 7802 (destructuring-bind (scheme server port group message-id articles)
23f87bed
MB
7803 (gnus-parse-news-url url)
7804 (cond
7805 (message-id
80de1778 7806 (with-current-buffer gnus-summary-buffer
23f87bed 7807 (if server
ff4d3926
MB
7808 (let ((gnus-refer-article-method
7809 (nconc (list (list 'nntp server))
7810 gnus-refer-article-method))
82a8ad04 7811 (nntp-port-number (or port "nntp")))
ff4d3926
MB
7812 (gnus-message 7 "Fetching %s with %s"
7813 message-id gnus-refer-article-method)
23f87bed
MB
7814 (gnus-summary-refer-article message-id))
7815 (gnus-summary-refer-article message-id))))
7816 (group
7817 (gnus-button-fetch-group url)))))
7818
01c52d31
MB
7819(defun gnus-button-patch (library line)
7820 "Visit an Emacs Lisp library LIBRARY on line LINE."
7821 (interactive)
7822 (let ((file (locate-library (file-name-nondirectory library))))
7823 (unless file
7824 (error "Couldn't find library %s" library))
7825 (find-file file)
7826 (goto-line (string-to-number line))))
7827
23f87bed
MB
7828(defun gnus-button-handle-man (url)
7829 "Fetch a man page."
531e5812
MB
7830 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7831 (when (eq gnus-button-man-handler 'woman)
7832 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7833 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
23f87bed
MB
7834 (funcall gnus-button-man-handler url))
7835
7836(defun gnus-button-handle-info-url (url)
7837 "Fetch an info URL."
7838 (setq url (mm-subst-char-in-string ?+ ?\ url))
7839 (cond
7840 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7841 (gnus-info-find-node
7842 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7843 "Gnus")
7844 ")" (gnus-url-unhex-string (match-string 2 url)))))
7845 ((string-match "([^)\"]+)[^\"]+" url)
7846 (setq url
7847 (gnus-replace-in-string
7848 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7849 (gnus-info-find-node url))
7850 (t (error "Can't parse %s" url))))
7851
7852(defun gnus-button-handle-info-url-gnome (url)
7853 "Fetch GNOME style info URL."
7854 (setq url (mm-subst-char-in-string ?_ ?\ url))
7855 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7856 (gnus-info-find-node
7857 (concat "("
bf247b6e 7858 (gnus-url-unhex-string
23f87bed
MB
7859 (match-string 1 url))
7860 ")"
bf247b6e 7861 (or (gnus-url-unhex-string
23f87bed
MB
7862 (match-string 2 url))
7863 "Top")))
7864 (error "Can't parse %s" url)))
7865
7866(defun gnus-button-handle-info-url-kde (url)
7867 "Fetch KDE style info URL."
7868 (gnus-info-find-node (gnus-url-unhex-string url)))
7869
9640c3bc
GM
7870;; (info) will autoload info.el
7871(declare-function Info-menu "info" (menu-item &optional fork))
7872
23f87bed
MB
7873(defun gnus-button-handle-info-keystrokes (url)
7874 "Call `info' when pushing the corresponding URL button."
7875 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7876 (info)
7877 (Info-directory)
7878 (Info-menu url))
1888e568
GM
7879
7880;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
7881(declare-function pgg-display-output-buffer "pgg" (start end status))
23f87bed 7882
01c52d31
MB
7883(defun gnus-button-openpgp (url)
7884 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7885 (with-temp-buffer
7886 (mm-url-insert-file-contents-external url)
7887 (pgg-snarf-keys-region (point-min) (point-max))
7888 (pgg-display-output-buffer nil nil nil)))
7889
eec82323
LMI
7890(defun gnus-button-message-id (message-id)
7891 "Fetch MESSAGE-ID."
01c52d31 7892 (with-current-buffer gnus-summary-buffer
eec82323
LMI
7893 (gnus-summary-refer-article message-id)))
7894
01c52d31 7895(defun gnus-button-fetch-group (address &rest ignore)
eec82323 7896 "Fetch GROUP specified by ADDRESS."
01c52d31
MB
7897 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7898 address)
7899 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7900 ;; for nntp:// and news://
7901 (setq address (match-string 3 address)))
eec82323
LMI
7902 (if (not (string-match "[:/]" address))
7903 ;; This is just a simple group url.
7904 (gnus-group-read-ephemeral-group address gnus-select-method)
23f87bed
MB
7905 (if (not
7906 (string-match
7907 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7908 address))
eec82323
LMI
7909 (error "Can't parse %s" address)
7910 (gnus-group-read-ephemeral-group
7911 (match-string 4 address)
7912 `(nntp ,(match-string 1 address)
7913 (nntp-address ,(match-string 1 address))
7914 (nntp-port-number ,(if (match-end 3)
7915 (match-string 3 address)
23f87bed
MB
7916 "nntp")))
7917 nil nil nil
e9bd5782 7918 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
eec82323 7919
eec82323
LMI
7920(defun gnus-url-parse-query-string (query &optional downcase)
7921 (let (retval pairs cur key val)
16409b0b 7922 (setq pairs (split-string query "&"))
eec82323
LMI
7923 (while pairs
7924 (setq cur (car pairs)
23f87bed 7925 pairs (cdr pairs))
eec82323 7926 (if (not (string-match "=" cur))
23f87bed
MB
7927 nil ; Grace
7928 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7929 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7930 (if downcase
7931 (setq key (downcase key)))
7932 (setq cur (assoc key retval))
7933 (if cur
7934 (setcdr cur (cons val (cdr cur)))
7935 (setq retval (cons (list key val) retval)))))
eec82323
LMI
7936 retval))
7937
eec82323
LMI
7938(defun gnus-url-mailto (url)
7939 ;; Send mail to someone
7940 (when (string-match "mailto:/*\\(.*\\)" url)
7941 (setq url (substring url (match-beginning 1) nil)))
6748645f 7942 (let (to args subject func)
23f87bed
MB
7943 (setq args (gnus-url-parse-query-string
7944 (if (string-match "^\\?" url)
7945 (substring url 1)
7946 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7947 (concat "to=" (match-string 1 url) "&"
7948 (match-string 2 url))
7949 (concat "to=" url)))
7950 t)
7951 subject (cdr-safe (assoc "subject" args)))
7952 (gnus-msg-mail)
eec82323
LMI
7953 (while args
7954 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7955 (if (fboundp func)
23f87bed
MB
7956 (funcall func)
7957 (message-position-on-field (caar args)))
7958 (insert (gnus-replace-in-string
7959 (mapconcat 'identity (reverse (cdar args)) ", ")
7960 "\r\n" "\n" t))
eec82323
LMI
7961 (setq args (cdr args)))
7962 (if subject
23f87bed 7963 (message-goto-body)
eec82323
LMI
7964 (message-goto-subject))))
7965
eec82323 7966(defun gnus-button-embedded-url (address)
e0bad764 7967 "Activate ADDRESS with `browse-url'."
1b978bfc 7968 (browse-url (gnus-strip-whitespace address)))
eec82323
LMI
7969
7970;;; Next/prev buttons in the article buffer.
7971
7972(defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7973(defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7974
23f87bed
MB
7975(defvar gnus-prev-page-map
7976 (let ((map (make-sparse-keymap)))
23f87bed
MB
7977 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7978 (define-key map "\r" 'gnus-button-prev-page)
7979 map))
7980
7981(defvar gnus-next-page-map
7982 (let ((map (make-sparse-keymap)))
7983 (unless (>= emacs-major-version 21)
7984 ;; XEmacs doesn't care.
7985 (set-keymap-parent map gnus-article-mode-map))
7986 (define-key map gnus-mouse-2 'gnus-button-next-page)
7987 (define-key map "\r" 'gnus-button-next-page)
7988 map))
eec82323
LMI
7989
7990(defun gnus-insert-prev-page-button ()
01c52d31 7991 (let ((b (point)) e
23f87bed 7992 (inhibit-read-only t))
eec82323
LMI
7993 (gnus-eval-format
7994 gnus-prev-page-line-format nil
01c52d31
MB
7995 `(keymap ,gnus-prev-page-map
7996 gnus-prev t
7997 gnus-callback gnus-article-button-prev-page
7998 article-type annotation))
7999 (setq e (if (bolp)
8000 ;; Exclude a newline.
8001 (1- (point))
8002 (point)))
8003 (when gnus-article-button-face
8004 (gnus-overlay-put (gnus-make-overlay b e nil t)
8005 'face gnus-article-button-face))
23f87bed 8006 (widget-convert-button
01c52d31 8007 'link b e
23f87bed
MB
8008 :action 'gnus-button-prev-page
8009 :button-keymap gnus-prev-page-map)))
8010
8011(defun gnus-button-next-page (&optional args more-args)
eec82323
LMI
8012 "Go to the next page."
8013 (interactive)
8014 (let ((win (selected-window)))
23f87bed 8015 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8016 (gnus-article-next-page)
8017 (select-window win)))
8018
23f87bed 8019(defun gnus-button-prev-page (&optional args more-args)
eec82323
LMI
8020 "Go to the prev page."
8021 (interactive)
8022 (let ((win (selected-window)))
23f87bed 8023 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8024 (gnus-article-prev-page)
8025 (select-window win)))
8026
8027(defun gnus-insert-next-page-button ()
01c52d31 8028 (let ((b (point)) e
23f87bed 8029 (inhibit-read-only t))
eec82323 8030 (gnus-eval-format gnus-next-page-line-format nil
01c52d31
MB
8031 `(keymap ,gnus-next-page-map
8032 gnus-next t
8033 gnus-callback gnus-article-button-next-page
8034 article-type annotation))
8035 (setq e (if (bolp)
8036 ;; Exclude a newline.
8037 (1- (point))
8038 (point)))
8039 (when gnus-article-button-face
8040 (gnus-overlay-put (gnus-make-overlay b e nil t)
8041 'face gnus-article-button-face))
23f87bed 8042 (widget-convert-button
01c52d31 8043 'link b e
23f87bed
MB
8044 :action 'gnus-button-next-page
8045 :button-keymap gnus-next-page-map)))
eec82323
LMI
8046
8047(defun gnus-article-button-next-page (arg)
8048 "Go to the next page."
8049 (interactive "P")
8050 (let ((win (selected-window)))
23f87bed 8051 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8052 (gnus-article-next-page)
8053 (select-window win)))
8054
8055(defun gnus-article-button-prev-page (arg)
8056 "Go to the prev page."
8057 (interactive "P")
8058 (let ((win (selected-window)))
23f87bed 8059 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8060 (gnus-article-prev-page)
8061 (select-window win)))
8062
16409b0b
GM
8063(defvar gnus-decode-header-methods
8064 '(mail-decode-encoded-word-region)
8065 "List of methods used to decode headers.
8066
8067This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4e7d0221 8068is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
23f87bed 8069\(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
16409b0b
GM
8070whose names match REGEXP.
8071
8072For example:
8f688cb0 8073\((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
16409b0b
GM
8074 mail-decode-encoded-word-region
8075 (\"chinese\" . rfc1843-decode-region))
8076")
8077
8078(defvar gnus-decode-header-methods-cache nil)
8079
8080(defun gnus-multi-decode-header (start end)
8081 "Apply the functions from `gnus-encoded-word-methods' that match."
8082 (unless (and gnus-decode-header-methods-cache
8083 (eq gnus-newsgroup-name
8084 (car gnus-decode-header-methods-cache)))
8085 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
01c52d31
MB
8086 (dolist (x gnus-decode-header-methods)
8087 (if (symbolp x)
8088 (nconc gnus-decode-header-methods-cache (list x))
8089 (if (and gnus-newsgroup-name
8090 (string-match (car x) gnus-newsgroup-name))
8091 (nconc gnus-decode-header-methods-cache
8092 (list (cdr x)))))))
16409b0b
GM
8093 (let ((xlist gnus-decode-header-methods-cache))
8094 (pop xlist)
8095 (save-restriction
8096 (narrow-to-region start end)
8097 (while xlist
8098 (funcall (pop xlist) (point-min) (point-max))))))
8099
8100;;;
8101;;; Treatment top-level handling.
8102;;;
8103
8104(defun gnus-treat-article (condition &optional part-number total-parts type)
8105 (let ((length (- (point-max) (point-min)))
8106 (alist gnus-treatment-function-alist)
8107 (article-goto-body-goes-to-point-min-p t)
8108 (treated-type
8109 (or (not type)
8110 (catch 'found
8111 (let ((list gnus-article-treat-types))
8112 (while list
8113 (when (string-match (pop list) type)
8114 (throw 'found t)))))))
8115 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8116 val elem)
8117 (gnus-run-hooks 'gnus-part-display-hook)
23f87bed 8118 (dolist (elem alist)
16409b0b
GM
8119 (setq val
8120 (save-excursion
23f87bed
MB
8121 (when (gnus-buffer-live-p gnus-summary-buffer)
8122 (set-buffer gnus-summary-buffer))
16409b0b
GM
8123 (symbol-value (car elem))))
8124 (when (and (or (consp val)
8125 treated-type)
8126 (gnus-treat-predicate val)
8127 (or (not (get (car elem) 'highlight))
8128 highlightp))
8129 (save-restriction
8130 (funcall (cadr elem)))))))
8131
8132;; Dynamic variables.
9efa445f
DN
8133(defvar part-number)
8134(defvar total-parts)
8135(defvar type)
8136(defvar condition)
8137(defvar length)
e0bad764 8138
16409b0b
GM
8139(defun gnus-treat-predicate (val)
8140 (cond
8141 ((null val)
8142 nil)
23f87bed
MB
8143 (condition
8144 (eq condition val))
16409b0b
GM
8145 ((and (listp val)
8146 (stringp (car val)))
8147 (apply 'gnus-or (mapcar `(lambda (s)
8148 (string-match s ,(or gnus-newsgroup-name "")))
8149 val)))
8150 ((listp val)
8151 (let ((pred (pop val)))
8152 (cond
8153 ((eq pred 'or)
8154 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8155 ((eq pred 'and)
8156 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8157 ((eq pred 'not)
8158 (not (gnus-treat-predicate (car val))))
8159 ((eq pred 'typep)
8160 (equal (car val) type))
8161 (t
8162 (error "%S is not a valid predicate" pred)))))
16409b0b
GM
8163 ((eq val t)
8164 t)
8165 ((eq val 'head)
8166 nil)
01c52d31
MB
8167 ((eq val 'first)
8168 (eq part-number 1))
16409b0b
GM
8169 ((eq val 'last)
8170 (eq part-number total-parts))
8171 ((numberp val)
8172 (< length val))
8173 (t
8174 (error "%S is not a valid value" val))))
8175
23f87bed
MB
8176(defun gnus-article-encrypt-body (protocol &optional n)
8177 "Encrypt the article body."
8178 (interactive
8179 (list
8180 (or gnus-article-encrypt-protocol
8181 (completing-read "Encrypt protocol: "
8182 gnus-article-encrypt-protocol-alist
8183 nil t))
8184 current-prefix-arg))
bbbe940b
MB
8185 ;; User might hit `K E' instead of `K e', so prompt once.
8186 (when (and gnus-article-encrypt-protocol
8187 gnus-novice-user)
8188 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8189 (error "Encrypt aborted.")))
23f87bed
MB
8190 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8191 (unless func
998a5a95 8192 (error "Can't find the encrypt protocol %s" protocol))
23f87bed
MB
8193 (if (member gnus-newsgroup-name '("nndraft:delayed"
8194 "nndraft:drafts"
8195 "nndraft:queue"))
8196 (error "Can't encrypt the article in group %s"
8197 gnus-newsgroup-name))
8198 (gnus-summary-iterate n
80de1778 8199 (with-current-buffer gnus-summary-buffer
23f87bed
MB
8200 (let ((mail-parse-charset gnus-newsgroup-charset)
8201 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8202 (summary-buffer gnus-summary-buffer)
8203 references point)
8204 (gnus-set-global-variables)
8205 (when (gnus-group-read-only-p)
8206 (error "The current newsgroup does not support article encrypt"))
8207 (gnus-summary-show-article t)
8208 (setq references
8209 (or (mail-header-references gnus-current-headers) ""))
8210 (set-buffer gnus-article-buffer)
8211 (let* ((inhibit-read-only t)
8212 (headers
8213 (mapcar (lambda (field)
8214 (and (save-restriction
8215 (message-narrow-to-head)
8216 (goto-char (point-min))
8217 (search-forward field nil t))
8218 (prog2
8219 (message-narrow-to-field)
8220 (buffer-string)
8221 (delete-region (point-min) (point-max))
8222 (widen))))
8223 '("Content-Type:" "Content-Transfer-Encoding:"
8224 "Content-Disposition:"))))
8225 (message-narrow-to-head)
8226 (message-remove-header "MIME-Version")
8227 (goto-char (point-max))
8228 (setq point (point))
8229 (insert (apply 'concat headers))
8230 (widen)
8231 (narrow-to-region point (point-max))
8232 (let ((message-options message-options))
8233 (message-options-set 'message-sender user-mail-address)
8234 (message-options-set 'message-recipients user-mail-address)
8235 (message-options-set 'message-sign-encrypt 'not)
8236 (funcall func))
8237 (goto-char (point-min))
8238 (insert "MIME-Version: 1.0\n")
8239 (widen)
8240 (gnus-summary-edit-article-done
8241 references nil summary-buffer t))
8242 (when gnus-keep-backlog
8243 (gnus-backlog-remove-article
8244 (car gnus-article-current) (cdr gnus-article-current)))
80de1778
SM
8245 (when (get-buffer gnus-original-article-buffer)
8246 (with-current-buffer gnus-original-article-buffer
23f87bed
MB
8247 (setq gnus-original-article nil)))
8248 (when gnus-use-cache
8249 (gnus-cache-update-article
8250 (car gnus-article-current) (cdr gnus-article-current))))))))
8251
8252(defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8253 "The following specs can be used:
8254%t The security MIME type
8255%i Additional info
8256%d Details
8257%D Details if button is pressed")
8258
8259(defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8260 "The following specs can be used:
8261%t The security MIME type
8262%i Additional info
8263%d Details
8264%D Details if button is pressed")
8265
8266(defvar gnus-mime-security-button-line-format-alist
8267 '((?t gnus-tmp-type ?s)
8268 (?i gnus-tmp-info ?s)
8269 (?d gnus-tmp-details ?s)
8270 (?D gnus-tmp-pressed-details ?s)))
8271
01c52d31
MB
8272(defvar gnus-mime-security-button-commands
8273 '((gnus-article-press-button "\r" "Show Detail")
8274 (undefined "v")
8275 (undefined "t")
8276 (undefined "C")
8277 (gnus-mime-security-save-part "o" "Save...")
8278 (undefined "\C-o")
8279 (undefined "r")
8280 (undefined "d")
8281 (undefined "c")
8282 (undefined "i")
8283 (undefined "E")
8284 (undefined "e")
8285 (undefined "p")
8286 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8287 (undefined ".")))
8288
23f87bed
MB
8289(defvar gnus-mime-security-button-map
8290 (let ((map (make-sparse-keymap)))
23f87bed 8291 (define-key map gnus-mouse-2 'gnus-article-push-button)
01c52d31
MB
8292 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8293 (dolist (c gnus-mime-security-button-commands)
8294 (define-key map (cadr c) (car c)))
23f87bed
MB
8295 map))
8296
01c52d31
MB
8297(easy-menu-define
8298 gnus-mime-security-button-menu gnus-mime-security-button-map
8299 "Security button menu."
8300 `("Security Part"
8301 ,@(delq nil
8302 (mapcar (lambda (c)
8303 (unless (eq (car c) 'undefined)
8304 (vector (caddr c) (car c) :active t)))
8305 gnus-mime-security-button-commands))))
8306
8307(defun gnus-mime-security-button-menu (event prefix)
8308 "Construct a context-sensitive menu of security commands."
8309 (interactive "e\nP")
8310 (save-window-excursion
8311 (let ((pos (event-start event)))
8312 (select-window (posn-window pos))
8313 (goto-char (posn-point pos))
8314 (gnus-article-check-buffer)
8315 (popup-menu gnus-mime-security-button-menu nil prefix))))
8316
23f87bed
MB
8317(defvar gnus-mime-security-details-buffer nil)
8318
8319(defvar gnus-mime-security-button-pressed nil)
8320
8321(defvar gnus-mime-security-show-details-inline t
8322 "If non-nil, show details in the article buffer.")
8323
8324(defun gnus-mime-security-verify-or-decrypt (handle)
8325 (mm-remove-parts (cdr handle))
8326 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8327 point (inhibit-read-only t))
8328 (if region
8329 (goto-char (car region)))
01c52d31
MB
8330 (setq point (point))
8331 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8332 (let* ((mm-verify-option 'known)
8333 (mm-decrypt-option 'known)
8334 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8335 (unless (eq nparts (cdr handle))
8336 (mm-destroy-parts (cdr handle))
8337 (setcdr handle nparts))))
8338 (gnus-mime-display-security handle)
23f87bed
MB
8339 (when region
8340 (delete-region (point) (cdr region))
8341 (set-marker (car region) nil)
8342 (set-marker (cdr region) nil))
8343 (goto-char point)))
8344
8345(defun gnus-mime-security-show-details (handle)
8346 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8347 (if (not details)
8348 (gnus-message 5 "No details.")
8349 (if gnus-mime-security-show-details-inline
8350 (let ((gnus-mime-security-button-pressed
8351 (not (get-text-property (point) 'gnus-mime-details)))
8352 (gnus-mime-security-button-line-format
8353 (get-text-property (point) 'gnus-line-format))
8354 (inhibit-read-only t))
8355 (forward-char -1)
8356 (while (eq (get-text-property (point) 'gnus-line-format)
8357 gnus-mime-security-button-line-format)
8358 (forward-char -1))
8359 (forward-char)
8360 (save-restriction
8361 (narrow-to-region (point) (point))
8362 (gnus-insert-mime-security-button handle))
8363 (delete-region (point)
8364 (or (text-property-not-all
8365 (point) (point-max)
8366 'gnus-line-format
8367 gnus-mime-security-button-line-format)
8368 (point-max))))
8369 ;; Not inlined.
8370 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8371 (with-current-buffer gnus-mime-security-details-buffer
8372 (erase-buffer)
8373 t)
8374 (setq gnus-mime-security-details-buffer
8375 (gnus-get-buffer-create "*MIME Security Details*")))
8376 (with-current-buffer gnus-mime-security-details-buffer
8377 (insert details)
8378 (goto-char (point-min)))
8379 (pop-to-buffer gnus-mime-security-details-buffer)))))
8380
8381(defun gnus-mime-security-press-button (handle)
8382 (save-excursion
8383 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8384 (gnus-mime-security-show-details handle)
8385 (gnus-mime-security-verify-or-decrypt handle))))
8386
8387(defun gnus-insert-mime-security-button (handle &optional displayed)
8388 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8389 (gnus-tmp-type
8390 (concat
8391 (or (nth 2 (assoc protocol mm-verify-function-alist))
8392 (nth 2 (assoc protocol mm-decrypt-function-alist))
8393 "Unknown")
8394 (if (equal (car handle) "multipart/signed")
8395 " Signed" " Encrypted")
8396 " Part"))
8397 (gnus-tmp-info
8398 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8399 "Undecided"))
8400 (gnus-tmp-details
8401 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8402 gnus-tmp-pressed-details
8403 b e)
8404 (setq gnus-tmp-details
8405 (if gnus-tmp-details
8406 (concat "\n" gnus-tmp-details)
8407 ""))
8408 (setq gnus-tmp-pressed-details
8409 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8410 (unless (bolp)
8411 (insert "\n"))
8412 (setq b (point))
8413 (gnus-eval-format
8414 gnus-mime-security-button-line-format
8415 gnus-mime-security-button-line-format-alist
01c52d31 8416 `(keymap ,gnus-mime-security-button-map
23f87bed
MB
8417 gnus-callback gnus-mime-security-press-button
8418 gnus-line-format ,gnus-mime-security-button-line-format
8419 gnus-mime-details ,gnus-mime-security-button-pressed
8420 article-type annotation
8421 gnus-data ,handle))
8422 (setq e (if (bolp)
8423 ;; Exclude a newline.
8424 (1- (point))
8425 (point)))
01c52d31
MB
8426 (when gnus-article-button-face
8427 (gnus-overlay-put (gnus-make-overlay b e nil t)
8428 'face gnus-article-button-face))
23f87bed
MB
8429 (widget-convert-button
8430 'link b e
8431 :mime-handle handle
8432 :action 'gnus-widget-press-button
8433 :button-keymap gnus-mime-security-button-map
8434 :help-echo
8435 (lambda (widget/window &optional overlay pos)
8436 ;; Needed to properly clear the message due to a bug in
8437 ;; wid-edit (XEmacs only).
8438 (when (boundp 'help-echo-owns-message)
8439 (setq help-echo-owns-message t))
8440 (format
01c52d31
MB
8441 "%S: show detail; %S: more options"
8442 (aref gnus-mouse-2 0)
8443 (aref gnus-down-mouse-3 0))))))
23f87bed
MB
8444
8445(defun gnus-mime-display-security (handle)
8446 (save-restriction
8447 (narrow-to-region (point) (point))
8448 (unless (gnus-unbuttonized-mime-type-p (car handle))
8449 (gnus-insert-mime-security-button handle))
01c52d31 8450 (gnus-mime-display-part (cadr handle))
23f87bed
MB
8451 (unless (bolp)
8452 (insert "\n"))
8453 (unless (gnus-unbuttonized-mime-type-p (car handle))
8454 (let ((gnus-mime-security-button-line-format
8455 gnus-mime-security-button-end-line-format))
8456 (gnus-insert-mime-security-button handle)))
8457 (mm-set-handle-multipart-parameter
8458 handle 'gnus-region
8459 (cons (set-marker (make-marker) (point-min))
01c52d31
MB
8460 (set-marker (make-marker) (point-max))))
8461 (goto-char (point-max))))
8462
8463(defun gnus-mime-security-run-function (function)
8464 "Run FUNCTION with the security part under point."
8465 (gnus-article-check-buffer)
8466 (let ((data (get-text-property (point) 'gnus-data))
8467 buffer handle)
8468 (when (and (stringp (car-safe data))
8469 (setq buffer (mm-handle-multipart-original-buffer data))
8470 (setq handle (cadr data)))
8471 (if (bufferp (mm-handle-buffer handle))
8472 (progn
8473 (setq handle (cons buffer (copy-sequence (cdr handle))))
8474 (mm-handle-set-undisplayer handle nil))
8475 (setq handle (mm-make-handle
8476 buffer
8477 (mm-handle-multipart-ctl-parameter handle 'protocol)
8478 nil nil nil nil nil nil)))
8479 (funcall function handle))))
8480
8481(defun gnus-mime-security-save-part ()
8482 "Save the security part under point."
8483 (interactive)
8484 (gnus-mime-security-run-function 'mm-save-part))
8485
8486(defun gnus-mime-security-pipe-part ()
8487 "Pipe the security part under point to a process."
8488 (interactive)
8489 (gnus-mime-security-run-function 'mm-pipe-part))
23f87bed 8490
eec82323
LMI
8491(gnus-ems-redefine)
8492
8493(provide 'gnus-art)
8494
8495(run-hooks 'gnus-art-load-hook)
8496
80de1778 8497;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
eec82323 8498;;; gnus-art.el ends here