Merge from gnus--devo--0
[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."
721 :version "23.0" ;; No Gnus
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."
888 :version "23.0" ;; No Gnus
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."
1060 :version "23.0" ;; No Gnus
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."
1365 :version "23.0" ;; No Gnus
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)
1717 `(save-excursion
1718 (set-buffer gnus-article-buffer)
1719 (save-restriction
1720 (let ((inhibit-read-only t)
1721 (inhibit-point-motion-hooks t)
1722 (case-fold-search t))
1723 (article-narrow-to-head)
1724 ,@forms))))
1725
1726(put 'gnus-with-article-headers 'lisp-indent-function 0)
1727(put 'gnus-with-article-headers 'edebug-form-spec '(body))
1728
1729(defmacro gnus-with-article-buffer (&rest forms)
1730 `(save-excursion
1731 (set-buffer gnus-article-buffer)
1732 (let ((inhibit-read-only t))
1733 ,@forms)))
1734
1735(put 'gnus-with-article-buffer 'lisp-indent-function 0)
1736(put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1737
1738(defun gnus-article-goto-header (header)
1739 "Go to HEADER, which is a regular expression."
1740 (re-search-forward (concat "^\\(" header "\\):") nil t))
1741
eec82323
LMI
1742(defsubst gnus-article-hide-text (b e props)
1743 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
520aa572 1744 (gnus-add-text-properties-when 'article-type nil b e props)
eec82323
LMI
1745 (when (memq 'intangible props)
1746 (put-text-property
1747 (max (1- b) (point-min))
1748 b 'intangible (cddr (memq 'intangible props)))))
520aa572 1749
eec82323
LMI
1750(defsubst gnus-article-unhide-text (b e)
1751 "Remove hidden text properties from region between B and E."
1752 (remove-text-properties b e gnus-hidden-properties)
1753 (when (memq 'intangible gnus-hidden-properties)
1754 (put-text-property (max (1- b) (point-min))
1755 b 'intangible nil)))
1756
1757(defun gnus-article-hide-text-type (b e type)
1758 "Hide text of TYPE between B and E."
23f87bed 1759 (gnus-add-wash-type type)
eec82323
LMI
1760 (gnus-article-hide-text
1761 b e (cons 'article-type (cons type gnus-hidden-properties))))
1762
1763(defun gnus-article-unhide-text-type (b e type)
6748645f 1764 "Unhide text of TYPE between B and E."
23f87bed 1765 (gnus-delete-wash-type type)
eec82323
LMI
1766 (remove-text-properties
1767 b e (cons 'article-type (cons type gnus-hidden-properties)))
1768 (when (memq 'intangible gnus-hidden-properties)
1769 (put-text-property (max (1- b) (point-min))
1770 b 'intangible nil)))
1771
1772(defun gnus-article-hide-text-of-type (type)
1773 "Hide text of TYPE in the current buffer."
1774 (save-excursion
1775 (let ((b (point-min))
1776 (e (point-max)))
1777 (while (setq b (text-property-any b e 'article-type type))
1778 (add-text-properties b (incf b) gnus-hidden-properties)))))
1779
1780(defun gnus-article-delete-text-of-type (type)
1781 "Delete text of TYPE in the current buffer."
1782 (save-excursion
a8151ef7 1783 (let ((b (point-min)))
7dafe00b
MB
1784 (if (eq type 'multipart)
1785 ;; Remove MIME buttons associated with multipart/alternative parts.
1786 (progn
1787 (goto-char b)
1788 (while (if (get-text-property (point) 'gnus-part)
1789 (setq b (point))
1790 (when (setq b (next-single-property-change (point)
1791 'gnus-part))
1792 (goto-char b)
1793 t))
1794 (end-of-line)
1795 (skip-chars-forward "\n")
1796 (when (eq (get-text-property b 'article-type) 'multipart)
1797 (delete-region b (point)))))
1798 (while (setq b (text-property-any b (point-max) 'article-type type))
1799 (delete-region
1800 b (or (text-property-not-all b (point-max) 'article-type type)
1801 (point-max))))))))
eec82323
LMI
1802
1803(defun gnus-article-delete-invisible-text ()
1804 "Delete all invisible text in the current buffer."
1805 (save-excursion
a8151ef7
LMI
1806 (let ((b (point-min)))
1807 (while (setq b (text-property-any b (point-max) 'invisible t))
1808 (delete-region
1809 b (or (text-property-not-all b (point-max) 'invisible t)
1810 (point-max)))))))
eec82323
LMI
1811
1812(defun gnus-article-text-type-exists-p (type)
1813 "Say whether any text of type TYPE exists in the buffer."
1814 (text-property-any (point-min) (point-max) 'article-type type))
1815
1816(defsubst gnus-article-header-rank ()
1817 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1818 (let ((list gnus-sorted-header-list)
23f87bed 1819 (i 1))
eec82323 1820 (while list
23f87bed
MB
1821 (if (looking-at (car list))
1822 (setq list nil)
1823 (setq list (cdr list))
1824 (incf i)))
1825 i))
eec82323
LMI
1826
1827(defun article-hide-headers (&optional arg delete)
16409b0b
GM
1828 "Hide unwanted headers and possibly sort them as well."
1829 (interactive)
1830 ;; This function might be inhibited.
1831 (unless gnus-inhibit-hiding
37cc095b 1832 (let ((inhibit-read-only t)
23f87bed
MB
1833 (case-fold-search t)
1834 (max (1+ (length gnus-sorted-header-list)))
1835 (inhibit-point-motion-hooks t)
1836 (cur (current-buffer))
1837 ignored visible beg)
1838 (save-excursion
1839 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1840 ;; group parameters, so we should go to the summary buffer.
1841 (when (prog1
1842 (condition-case nil
1843 (progn (set-buffer gnus-summary-buffer) t)
1844 (error nil))
1845 (setq ignored (when (not gnus-visible-headers)
1846 (cond ((stringp gnus-ignored-headers)
1847 gnus-ignored-headers)
1848 ((listp gnus-ignored-headers)
1849 (mapconcat 'identity
1850 gnus-ignored-headers
1851 "\\|"))))
1852 visible (cond ((stringp gnus-visible-headers)
1853 gnus-visible-headers)
1854 ((and gnus-visible-headers
1855 (listp gnus-visible-headers))
1856 (mapconcat 'identity
1857 gnus-visible-headers
1858 "\\|")))))
1859 (set-buffer cur))
1860 (save-restriction
16409b0b
GM
1861 ;; First we narrow to just the headers.
1862 (article-narrow-to-head)
1863 ;; Hide any "From " lines at the beginning of (mail) articles.
1864 (while (looking-at "From ")
1865 (forward-line 1))
1866 (unless (bobp)
1867 (delete-region (point-min) (point)))
1868 ;; Then treat the rest of the header lines.
1869 ;; Then we use the two regular expressions
1870 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1871 ;; select which header lines is to remain visible in the
1872 ;; article buffer.
23f87bed 1873 (while (re-search-forward "^[^ \t:]*:" nil t)
16409b0b
GM
1874 (beginning-of-line)
1875 ;; Mark the rank of the header.
1876 (put-text-property
1877 (point) (1+ (point)) 'message-rank
1878 (if (or (and visible (looking-at visible))
1879 (and ignored
1880 (not (looking-at ignored))))
1881 (gnus-article-header-rank)
1882 (+ 2 max)))
1883 (forward-line 1))
1884 (message-sort-headers-1)
1885 (when (setq beg (text-property-any
1886 (point-min) (point-max) 'message-rank (+ 2 max)))
1887 ;; We delete the unwanted headers.
23f87bed 1888 (gnus-add-wash-type 'headers)
16409b0b
GM
1889 (add-text-properties (point-min) (+ 5 (point-min))
1890 '(article-type headers dummy-invisible t))
1891 (delete-region beg (point-max))))))))
eec82323
LMI
1892
1893(defun article-hide-boring-headers (&optional arg)
1894 "Toggle hiding of headers that aren't very interesting.
1895If given a negative prefix, always show; if given a positive prefix,
1896always hide."
1897 (interactive (gnus-article-hidden-arg))
1898 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1899 (not gnus-show-all-headers))
1900 (save-excursion
1901 (save-restriction
4e7d0221 1902 (let ((inhibit-read-only t)
01c52d31 1903 (inhibit-point-motion-hooks t))
16409b0b 1904 (article-narrow-to-head)
01c52d31 1905 (dolist (elem gnus-boring-article-headers)
eec82323
LMI
1906 (goto-char (point-min))
1907 (cond
1908 ;; Hide empty headers.
1909 ((eq elem 'empty)
16409b0b 1910 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
eec82323
LMI
1911 (forward-line -1)
1912 (gnus-article-hide-text-type
01c52d31 1913 (point-at-bol)
eec82323
LMI
1914 (progn
1915 (end-of-line)
1916 (if (re-search-forward "^[^ \t]" nil t)
1917 (match-beginning 0)
1918 (point-max)))
1919 'boring-headers)))
1920 ;; Hide boring Newsgroups header.
1921 ((eq elem 'newsgroups)
23f87bed
MB
1922 (when (gnus-string-equal
1923 (gnus-fetch-field "newsgroups")
1924 (gnus-group-real-name
1925 (if (boundp 'gnus-newsgroup-name)
1926 gnus-newsgroup-name
1927 "")))
eec82323 1928 (gnus-article-hide-header "newsgroups")))
23f87bed
MB
1929 ((eq elem 'to-address)
1930 (let ((to (message-fetch-field "to"))
1931 (to-address
1932 (gnus-parameter-to-address
1933 (if (boundp 'gnus-newsgroup-name)
1934 gnus-newsgroup-name ""))))
1935 (when (and to to-address
1936 (ignore-errors
1937 (gnus-string-equal
1938 ;; only one address in To
1939 (nth 1 (mail-extract-address-components to))
1940 to-address)))
1941 (gnus-article-hide-header "to"))))
1942 ((eq elem 'to-list)
1943 (let ((to (message-fetch-field "to"))
1944 (to-list
1945 (gnus-parameter-to-list
1946 (if (boundp 'gnus-newsgroup-name)
1947 gnus-newsgroup-name ""))))
1948 (when (and to to-list
1949 (ignore-errors
1950 (gnus-string-equal
1951 ;; only one address in To
1952 (nth 1 (mail-extract-address-components to))
1953 to-list)))
1954 (gnus-article-hide-header "to"))))
1955 ((eq elem 'cc-list)
1956 (let ((cc (message-fetch-field "cc"))
1957 (to-list
1958 (gnus-parameter-to-list
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and cc to-list
1962 (ignore-errors
1963 (gnus-string-equal
1964 ;; only one address in CC
1965 (nth 1 (mail-extract-address-components cc))
1966 to-list)))
1967 (gnus-article-hide-header "cc"))))
eec82323 1968 ((eq elem 'followup-to)
23f87bed
MB
1969 (when (gnus-string-equal
1970 (message-fetch-field "followup-to")
1971 (message-fetch-field "newsgroups"))
eec82323
LMI
1972 (gnus-article-hide-header "followup-to")))
1973 ((eq elem 'reply-to)
23f87bed
MB
1974 (if (gnus-group-find-parameter
1975 gnus-newsgroup-name 'broken-reply-to)
1976 (gnus-article-hide-header "reply-to")
1977 (let ((from (message-fetch-field "from"))
1978 (reply-to (message-fetch-field "reply-to")))
1979 (when
1980 (and
eec82323
LMI
1981 from reply-to
1982 (ignore-errors
1983 (equal
23f87bed
MB
1984 (sort (mapcar
1985 (lambda (x) (downcase (cadr x)))
1986 (mail-extract-address-components from t))
1987 'string<)
1988 (sort (mapcar
1989 (lambda (x) (downcase (cadr x)))
1990 (mail-extract-address-components reply-to t))
1991 'string<))))
1992 (gnus-article-hide-header "reply-to")))))
eec82323 1993 ((eq elem 'date)
b193caa3
MB
1994 (let ((date (with-current-buffer gnus-original-article-buffer
1995 ;; If date in `gnus-article-buffer' is localized
1996 ;; (`gnus-treat-date-user-defined'),
1997 ;; `days-between' might fail.
1998 (message-fetch-field "date"))))
eec82323 1999 (when (and date
16409b0b 2000 (< (days-between (current-time-string) date)
eec82323 2001 4))
6748645f
LMI
2002 (gnus-article-hide-header "date"))))
2003 ((eq elem 'long-to)
16409b0b
GM
2004 (let ((to (message-fetch-field "to"))
2005 (cc (message-fetch-field "cc")))
6748645f 2006 (when (> (length to) 1024)
16409b0b
GM
2007 (gnus-article-hide-header "to"))
2008 (when (> (length cc) 1024)
2009 (gnus-article-hide-header "cc"))))
6748645f 2010 ((eq elem 'many-to)
16409b0b
GM
2011 (let ((to-count 0)
2012 (cc-count 0))
6748645f
LMI
2013 (goto-char (point-min))
2014 (while (re-search-forward "^to:" nil t)
2015 (setq to-count (1+ to-count)))
2016 (when (> to-count 1)
2017 (while (> to-count 0)
2018 (goto-char (point-min))
2019 (save-restriction
2020 (re-search-forward "^to:" nil nil to-count)
2021 (forward-line -1)
2022 (narrow-to-region (point) (point-max))
2023 (gnus-article-hide-header "to"))
16409b0b
GM
2024 (setq to-count (1- to-count))))
2025 (goto-char (point-min))
2026 (while (re-search-forward "^cc:" nil t)
2027 (setq cc-count (1+ cc-count)))
2028 (when (> cc-count 1)
2029 (while (> cc-count 0)
2030 (goto-char (point-min))
2031 (save-restriction
2032 (re-search-forward "^cc:" nil nil cc-count)
2033 (forward-line -1)
2034 (narrow-to-region (point) (point-max))
2035 (gnus-article-hide-header "cc"))
2036 (setq cc-count (1- cc-count)))))))))))))
eec82323
LMI
2037
2038(defun gnus-article-hide-header (header)
2039 (save-excursion
2040 (goto-char (point-min))
2041 (when (re-search-forward (concat "^" header ":") nil t)
2042 (gnus-article-hide-text-type
01c52d31 2043 (point-at-bol)
eec82323
LMI
2044 (progn
2045 (end-of-line)
2046 (if (re-search-forward "^[^ \t]" nil t)
2047 (match-beginning 0)
2048 (point-max)))
2049 'boring-headers))))
2050
16409b0b
GM
2051(defvar gnus-article-normalized-header-length 40
2052 "Length of normalized headers.")
2053
2054(defun article-normalize-headers ()
2055 "Make all header lines 40 characters long."
2056 (interactive)
4e7d0221 2057 (let ((inhibit-read-only t)
16409b0b
GM
2058 column)
2059 (save-excursion
2060 (save-restriction
2061 (article-narrow-to-head)
2062 (while (not (eobp))
2063 (cond
01c52d31 2064 ((< (setq column (- (point-at-eol) (point)))
16409b0b
GM
2065 gnus-article-normalized-header-length)
2066 (end-of-line)
2067 (insert (make-string
2068 (- gnus-article-normalized-header-length column)
2069 ? )))
2070 ((> column gnus-article-normalized-header-length)
2071 (gnus-put-text-property
2072 (progn
2073 (forward-char gnus-article-normalized-header-length)
2074 (point))
01c52d31 2075 (point-at-eol)
16409b0b
GM
2076 'invisible t))
2077 (t
2078 ;; Do nothing.
2079 ))
2080 (forward-line 1))))))
2081
6748645f 2082(defun article-treat-dumbquotes ()
23f87bed 2083 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
16409b0b 2084Note that this function guesses whether a character is a sm*rtq**t* or
74dd1b0d
SZ
2085not, so it should only be used interactively.
2086
23f87bed
MB
2087Sm*rtq**t*s are M****s***'s unilateral extension to the
2088iso-8859-1 character map in an attempt to provide more quoting
2089characters. If you see something like \\222 or \\264 where
2090you're expecting some kind of apostrophe or quotation mark, then
2091try this wash."
6748645f 2092 (interactive)
16409b0b 2093 (article-translate-strings gnus-article-dumbquotes-map))
6748645f
LMI
2094
2095(defun article-translate-characters (from to)
2096 "Translate all characters in the body of the article according to FROM and TO.
2097FROM is a string of characters to translate from; to is a string of
2098characters to translate to."
2099 (save-excursion
16409b0b 2100 (when (article-goto-body)
4e7d0221 2101 (let ((inhibit-read-only t)
6748645f
LMI
2102 (x (make-string 225 ?x))
2103 (i -1))
2104 (while (< (incf i) (length x))
2105 (aset x i i))
2106 (setq i 0)
2107 (while (< i (length from))
2108 (aset x (aref from i) (aref to i))
2109 (incf i))
2110 (translate-region (point) (point-max) x)))))
2111
16409b0b
GM
2112(defun article-translate-strings (map)
2113 "Translate all string in the body of the article according to MAP.
2114MAP is an alist where the elements are on the form (\"from\" \"to\")."
2115 (save-excursion
2116 (when (article-goto-body)
01c52d31
MB
2117 (let ((inhibit-read-only t))
2118 (dolist (elem map)
16409b0b
GM
2119 (save-excursion
2120 (while (search-forward (car elem) nil t)
2121 (replace-match (cadr elem)))))))))
2122
eec82323
LMI
2123(defun article-treat-overstrike ()
2124 "Translate overstrikes into bold text."
2125 (interactive)
2126 (save-excursion
16409b0b 2127 (when (article-goto-body)
4e7d0221 2128 (let ((inhibit-read-only t))
eec82323 2129 (while (search-forward "\b" nil t)
16409b0b 2130 (let ((next (char-after))
eec82323
LMI
2131 (previous (char-after (- (point) 2))))
2132 ;; We do the boldification/underlining by hiding the
2133 ;; overstrikes and putting the proper text property
2134 ;; on the letters.
2135 (cond
2136 ((eq next previous)
2137 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2138 (put-text-property (point) (1+ (point)) 'face 'bold))
2139 ((eq next ?_)
2140 (gnus-article-hide-text-type
2141 (1- (point)) (1+ (point)) 'overstrike)
2142 (put-text-property
2143 (- (point) 2) (1- (point)) 'face 'underline))
2144 ((eq previous ?_)
2145 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2146 (put-text-property
2147 (point) (1+ (point)) 'face 'underline)))))))))
2148
01c52d31
MB
2149(defun article-treat-ansi-sequences ()
2150 "Translate ANSI SGR control sequences into overlays or extents."
2151 (interactive)
2152 (save-excursion
2153 (when (article-goto-body)
2154 (let ((inhibit-read-only t))
2155 (ansi-color-apply-on-region (point) (point-max))))))
2156
23f87bed
MB
2157(defun gnus-article-treat-unfold-headers ()
2158 "Unfold folded message headers.
2159Only the headers that fit into the current window width will be
2160unfolded."
2161 (interactive)
2162 (gnus-with-article-headers
2163 (let (length)
2164 (while (not (eobp))
2165 (save-restriction
2166 (mail-header-narrow-to-field)
01c52d31
MB
2167 (let* ((header (buffer-string))
2168 (unfoldable
2169 (or (equal gnus-article-unfold-long-headers t)
2170 (and (stringp gnus-article-unfold-long-headers)
2171 (string-match gnus-article-unfold-long-headers header)))))
23f87bed
MB
2172 (with-temp-buffer
2173 (insert header)
2174 (goto-char (point-min))
2175 (while (re-search-forward "\n[\t ]" nil t)
2176 (replace-match " " t t)))
01c52d31
MB
2177 (setq length (- (point-max) (point-min) 1))
2178 (when (or unfoldable
2179 (< length (window-width)))
2180 (while (re-search-forward "\n[\t ]" nil t)
2181 (replace-match " " t t))))
23f87bed
MB
2182 (goto-char (point-max)))))))
2183
2184(defun gnus-article-treat-fold-headers ()
2185 "Fold message headers."
2186 (interactive)
2187 (gnus-with-article-headers
2188 (while (not (eobp))
2189 (save-restriction
2190 (mail-header-narrow-to-field)
2191 (mail-header-fold-field)
2192 (goto-char (point-max))))))
2193
2194(defun gnus-treat-smiley ()
2195 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2196 (interactive)
2197 (gnus-with-article-buffer
2198 (if (memq 'smiley gnus-article-wash-types)
2199 (gnus-delete-images 'smiley)
2200 (article-goto-body)
2201 (let ((images (smiley-region (point) (point-max))))
2202 (when images
2203 (gnus-add-wash-type 'smiley)
2204 (dolist (image images)
2205 (gnus-add-image 'smiley image)))))))
2206
2207(defun gnus-article-remove-images ()
2208 "Remove all images from the article buffer."
2209 (interactive)
2210 (gnus-with-article-buffer
2211 (dolist (elem gnus-article-image-alist)
2212 (gnus-delete-images (car elem)))))
2213
2214(defun gnus-article-treat-fold-newsgroups ()
2215 "Unfold folded message headers.
2216Only the headers that fit into the current window width will be
2217unfolded."
2218 (interactive)
2219 (gnus-with-article-headers
2220 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2221 (save-restriction
2222 (mail-header-narrow-to-field)
2223 (while (re-search-forward ", *" nil t)
2224 (replace-match ", " t t))
2225 (mail-header-fold-field)
2226 (goto-char (point-max))))))
2227
b7b80032 2228(defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
01c52d31
MB
2229 "Value of `truncate-lines' in Gnus Article buffer.
2230Valid values are nil, t, `head', `first', `last', an integer or a
2231predicate. See Info node `(gnus)Customizing Articles'."
2232 :version "23.0" ;; No Gnus
2233 :group 'gnus-article
2234 ;; :link '(custom-manual "(gnus)Customizing Articles")
2235 :type 'boolean)
2236
2237(defun gnus-article-toggle-truncate-lines (&optional arg)
2238 "Toggle whether to fold or truncate long lines in article the buffer.
2239If ARG is non-nil and not a number, toggle
2240`gnus-article-truncate-lines' too. If ARG is a number, truncate
2241long lines iff arg is positive."
2242 (interactive "P")
2243 (cond
2244 ((and (numberp arg) (> arg 0))
2245 (setq gnus-article-truncate-lines t))
2246 ((numberp arg)
2247 (setq gnus-article-truncate-lines nil))
2248 (arg
2249 (setq gnus-article-truncate-lines
2250 (not gnus-article-truncate-lines))))
2251 (gnus-with-article-buffer
2252 (cond
2253 ((and (numberp arg) (> arg 0))
2254 (setq truncate-lines nil))
2255 ((numberp arg)
2256 (setq truncate-lines t)))
2257 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2258 ;; `toggle-truncate-lines' needs an argument.
2259 (toggle-truncate-lines)))
2260
23f87bed
MB
2261(defun gnus-article-treat-body-boundary ()
2262 "Place a boundary line at the end of the headers."
2263 (interactive)
2264 (when (and gnus-body-boundary-delimiter
2265 (> (length gnus-body-boundary-delimiter) 0))
2266 (gnus-with-article-headers
2267 (goto-char (point-max))
2268 (let ((start (point)))
2269 (insert "X-Boundary: ")
2270 (gnus-add-text-properties start (point) '(invisible t intangible t))
2271 (insert (let (str)
2272 (while (>= (1- (window-width)) (length str))
2273 (setq str (concat str gnus-body-boundary-delimiter)))
2274 (substring str 0 (1- (window-width))))
2275 "\n")
2276 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2277
16409b0b
GM
2278(defun article-fill-long-lines ()
2279 "Fill lines that are wider than the window width."
eec82323
LMI
2280 (interactive)
2281 (save-excursion
4e7d0221 2282 (let ((inhibit-read-only t)
16409b0b
GM
2283 (width (window-width (get-buffer-window (current-buffer)))))
2284 (save-restriction
2285 (article-goto-body)
80b47379 2286 (let ((adaptive-fill-mode nil)) ;Why? -sm
16409b0b
GM
2287 (while (not (eobp))
2288 (end-of-line)
2289 (when (>= (current-column) (min fill-column width))
23f87bed 2290 (narrow-to-region (min (1+ (point)) (point-max))
01c52d31 2291 (point-at-bol))
23f87bed
MB
2292 (let ((goback (point-marker)))
2293 (fill-paragraph nil)
2294 (goto-char (marker-position goback)))
16409b0b
GM
2295 (widen))
2296 (forward-line 1)))))))
2297
2298(defun article-capitalize-sentences ()
2299 "Capitalize the first word in each sentence."
2300 (interactive)
2301 (save-excursion
4e7d0221 2302 (let ((inhibit-read-only t)
16409b0b
GM
2303 (paragraph-start "^[\n\^L]"))
2304 (article-goto-body)
2305 (while (not (eobp))
2306 (capitalize-word 1)
2307 (forward-sentence)))))
eec82323
LMI
2308
2309(defun article-remove-cr ()
16409b0b 2310 "Remove trailing CRs and then translate remaining CRs into LFs."
eec82323
LMI
2311 (interactive)
2312 (save-excursion
4e7d0221 2313 (let ((inhibit-read-only t))
eec82323 2314 (goto-char (point-min))
16409b0b
GM
2315 (while (re-search-forward "\r+$" nil t)
2316 (replace-match "" t t))
2317 (goto-char (point-min))
eec82323 2318 (while (search-forward "\r" nil t)
16409b0b 2319 (replace-match "\n" t t)))))
eec82323
LMI
2320
2321(defun article-remove-trailing-blank-lines ()
2322 "Remove all trailing blank lines from the article."
2323 (interactive)
2324 (save-excursion
4e7d0221 2325 (let ((inhibit-read-only t))
eec82323
LMI
2326 (goto-char (point-max))
2327 (delete-region
2328 (point)
2329 (progn
2330 (while (and (not (bobp))
16409b0b
GM
2331 (looking-at "^[ \t]*$")
2332 (not (gnus-annotation-in-region-p
01c52d31 2333 (point) (point-at-eol))))
eec82323
LMI
2334 (forward-line -1))
2335 (forward-line 1)
2336 (point))))))
2337
9efa445f 2338(defvar gnus-face-properties-alist)
01c52d31 2339
b890d447 2340(defun article-display-face (&optional force)
23f87bed 2341 "Display any Face headers in the header."
b890d447 2342 (interactive (list 'force))
23f87bed
MB
2343 (let ((wash-face-p buffer-read-only))
2344 (gnus-with-article-headers
2345 ;; When displaying parts, this function can be called several times on
2346 ;; the same article, without any intended toggle semantic (as typing `W
2347 ;; D d' would have). So face deletion must occur only when we come from
2348 ;; an interactive command, that is when the *Article* buffer is
2349 ;; read-only.
2350 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2351 (gnus-delete-images 'face)
b890d447
MB
2352 (let ((from (message-fetch-field "from"))
2353 face faces)
7d0c69be 2354 (save-current-buffer
23f87bed 2355 (when (and wash-face-p
7d0c69be
MB
2356 (gnus-buffer-live-p gnus-original-article-buffer)
2357 (not (re-search-forward "^Face:[\t ]*" nil t)))
23f87bed
MB
2358 (set-buffer gnus-original-article-buffer))
2359 (save-restriction
2360 (mail-narrow-to-head)
b890d447
MB
2361 (when (or force
2362 ;; Check whether this face is censored.
2363 (not (and gnus-article-x-face-too-ugly
2364 (or from
2365 (setq from (message-fetch-field "from")))
2366 (string-match gnus-article-x-face-too-ugly
2367 from))))
2368 (while (gnus-article-goto-header "Face")
2369 (push (mail-header-field-value) faces)))))
d6697c02 2370 (when faces
7d0c69be 2371 (goto-char (point-min))
b890d447
MB
2372 (let (png image)
2373 (unless (setq from (gnus-article-goto-header "from"))
7d0c69be
MB
2374 (insert "From:")
2375 (setq from (point))
b890d447 2376 (insert " [no `from' set]\n"))
7d0c69be
MB
2377 (while faces
2378 (when (setq png (gnus-convert-face-to-png (pop faces)))
01c52d31
MB
2379 (setq image
2380 (apply 'gnus-create-image png 'png t
2381 (cdr (assq 'png gnus-face-properties-alist))))
d6697c02
MB
2382 (goto-char from)
2383 (gnus-add-wash-type 'face)
2384 (gnus-add-image 'face image)
2385 (gnus-put-image image nil 'face))))))))))
23f87bed 2386
eec82323
LMI
2387(defun article-display-x-face (&optional force)
2388 "Look for an X-Face header and display it if present."
2389 (interactive (list 'force))
23f87bed
MB
2390 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2391 (gnus-with-article-headers
2392 ;; Delete the old process, if any.
2393 (when (process-status "article-x-face")
2394 (delete-process "article-x-face"))
2395 ;; See the comment in `article-display-face'.
2396 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2397 ;; We have already displayed X-Faces, so we remove them
2398 ;; instead.
2399 (gnus-delete-images 'xface)
2400 ;; Display X-Faces.
b890d447
MB
2401 (let ((from (message-fetch-field "from"))
2402 x-faces face)
7d0c69be 2403 (save-current-buffer
23f87bed 2404 (when (and wash-face-p
7d0c69be
MB
2405 (gnus-buffer-live-p gnus-original-article-buffer)
2406 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
23f87bed
MB
2407 ;; If type `W f', use gnus-original-article-buffer,
2408 ;; otherwise use the current buffer because displaying
2409 ;; RFC822 parts calls this function too.
2410 (set-buffer gnus-original-article-buffer))
2411 (save-restriction
2412 (mail-narrow-to-head)
b890d447
MB
2413 (and gnus-article-x-face-command
2414 (or force
2415 ;; Check whether this face is censored.
2416 (not (and gnus-article-x-face-too-ugly
2417 (or from
2418 (setq from (message-fetch-field "from")))
2419 (string-match gnus-article-x-face-too-ugly
2420 from))))
2421 (while (gnus-article-goto-header "X-Face")
2422 (push (mail-header-field-value) x-faces)))))
2423 (when x-faces
2424 ;; We display the face.
2425 (cond ((functionp gnus-article-x-face-command)
2426 ;; The command is a lisp function, so we call it.
2427 (mapc gnus-article-x-face-command x-faces))
2428 ((stringp gnus-article-x-face-command)
2429 ;; The command is a string, so we interpret the command
2430 ;; as a, well, command, and fork it off.
2431 (let ((process-connection-type nil))
2432 (gnus-set-process-query-on-exit-flag
2433 (start-process
2434 "article-x-face" nil shell-file-name
2435 shell-command-switch gnus-article-x-face-command)
2436 nil)
2437 ;; Sending multiple EOFs to xv doesn't work,
2438 ;; so we only do a single external face.
2439 (with-temp-buffer
2440 (insert (car x-faces))
2441 (process-send-region "article-x-face"
2442 (point-min) (point-max)))
2443 (process-send-eof "article-x-face")))
2444 (t
2445 (error "`%s' set to `%s' is not a function"
2446 gnus-article-x-face-command
2447 'gnus-article-x-face-command)))))))))
a8151ef7 2448
16409b0b
GM
2449(defun article-decode-mime-words ()
2450 "Decode all MIME-encoded words in the article."
2451 (interactive)
01c52d31 2452 (gnus-with-article-buffer
16409b0b 2453 (let ((inhibit-point-motion-hooks t)
16409b0b 2454 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2455 (mail-parse-ignored-charsets
01c52d31
MB
2456 (with-current-buffer gnus-summary-buffer
2457 gnus-newsgroup-ignored-charsets)))
16409b0b
GM
2458 (mail-decode-encoded-word-region (point-min) (point-max)))))
2459
2460(defun article-decode-charset (&optional prompt)
2461 "Decode charset-encoded text in the article.
2462If PROMPT (the prefix), prompt for a coding system to use."
2463 (interactive "P")
2464 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
23f87bed 2465 (inhibit-read-only t)
16409b0b 2466 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2467 (mail-parse-ignored-charsets
16409b0b
GM
2468 (save-excursion (condition-case nil
2469 (set-buffer gnus-summary-buffer)
2470 (error))
2471 gnus-newsgroup-ignored-charsets))
2472 ct cte ctl charset format)
c96ec15a
MB
2473 (save-excursion
2474 (save-restriction
2475 (article-narrow-to-head)
2476 (setq ct (message-fetch-field "Content-Type" t)
2477 cte (message-fetch-field "Content-Transfer-Encoding" t)
2478 ctl (and ct (mail-header-parse-content-type ct))
2479 charset (cond
2480 (prompt
2481 (mm-read-coding-system "Charset to decode: "))
2482 (ctl
2483 (mail-content-type-get ctl 'charset)))
2484 format (and ctl (mail-content-type-get ctl 'format)))
2485 (when cte
2486 (setq cte (mail-header-strip cte)))
2487 (if (and ctl (not (string-match "/" (car ctl))))
2488 (setq ctl nil))
2489 (goto-char (point-max)))
2490 (forward-line 1)
2491 (save-restriction
2492 (narrow-to-region (point) (point-max))
2493 (when (and (eq mail-parse-charset 'gnus-decoded)
2494 (eq (mm-body-7-or-8) '8bit))
2495 ;; The text code could have been decoded.
2496 (setq charset mail-parse-charset))
2497 (when (and (or (not ctl)
2498 (equal (car ctl) "text/plain"))
2499 (not format)) ;; article with format will decode later.
2500 (mm-decode-body
2501 charset (and cte (intern (downcase
2502 (gnus-strip-whitespace cte))))
2503 (car ctl)))))))
16409b0b
GM
2504
2505(defun article-decode-encoded-words ()
2506 "Remove encoded-word encoding from headers."
2507 (let ((inhibit-point-motion-hooks t)
2508 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2509 (mail-parse-ignored-charsets
16409b0b
GM
2510 (save-excursion (condition-case nil
2511 (set-buffer gnus-summary-buffer)
2512 (error))
2513 gnus-newsgroup-ignored-charsets))
343d6628 2514 (inhibit-read-only t)
8fbdffe5
MB
2515 end start)
2516 (goto-char (point-min))
2517 (when (search-forward "\n\n" nil 'move)
2518 (forward-line -1))
2519 (setq end (point))
2520 (while (not (bobp))
2521 (while (progn
2522 (forward-line -1)
2523 (and (not (bobp))
2524 (memq (char-after) '(?\t ? )))))
2525 (setq start (point))
2526 (if (looking-at "\
343d6628
MB
2527\\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2528\\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
8fbdffe5
MB
2529 (funcall gnus-decode-address-function start end)
2530 (funcall gnus-decode-header-function start end))
2531 (goto-char (setq end start)))))
eec82323 2532
23f87bed 2533(defun article-decode-group-name ()
01c52d31 2534 "Decode group names in Newsgroups, Followup-To and Xref headers."
23f87bed
MB
2535 (let ((inhibit-point-motion-hooks t)
2536 (inhibit-read-only t)
01c52d31
MB
2537 (method (gnus-find-method-for-group gnus-newsgroup-name))
2538 regexp)
23f87bed
MB
2539 (when (and (or gnus-group-name-charset-method-alist
2540 gnus-group-name-charset-group-alist)
2541 (gnus-buffer-live-p gnus-original-article-buffer))
2542 (save-restriction
2543 (article-narrow-to-head)
01c52d31
MB
2544 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2545 (with-current-buffer gnus-original-article-buffer
2546 (goto-char (point-min)))
2547 (setq regexp (concat "^" header
2548 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2549 (while (re-search-forward regexp nil t)
2550 (replace-match (save-match-data
2551 (gnus-decode-newsgroups
2552 ;; XXX how to use data in article buffer?
2553 (with-current-buffer gnus-original-article-buffer
2554 (re-search-forward regexp nil t)
2555 (match-string 1))
2556 gnus-newsgroup-name method))
2557 t t nil 1))
2558 (goto-char (point-min)))))))
23f87bed
MB
2559
2560(autoload 'idna-to-unicode "idna")
2561
2562(defun article-decode-idna-rhs ()
53cfefc8
MB
2563 "Decode IDNA strings in RHS in various headers in current buffer.
2564The following headers are decoded: From:, To:, Cc:, Reply-To:,
2565Mail-Reply-To: and Mail-Followup-To:."
23f87bed
MB
2566 (when gnus-use-idna
2567 (save-restriction
2568 (let ((inhibit-point-motion-hooks t)
2569 (inhibit-read-only t))
2570 (article-narrow-to-head)
2571 (goto-char (point-min))
53cfefc8 2572 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
23f87bed
MB
2573 (let (ace unicode)
2574 (when (save-match-data
2575 (and (setq ace (match-string 1))
2576 (save-excursion
2577 (and (re-search-backward "^[^ \t]" nil t)
53cfefc8 2578 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
23f87bed
MB
2579 (setq unicode (idna-to-unicode ace))))
2580 (unless (string= ace unicode)
2581 (replace-match unicode nil nil nil 1)))))))))
2582
2583(defun article-de-quoted-unreadable (&optional force read-charset)
16409b0b 2584 "Translate a quoted-printable-encoded article.
eec82323 2585If FORCE, decode the article whether it is marked as quoted-printable
23f87bed
MB
2586or not.
2587If READ-CHARSET, ask for a coding system."
2588 (interactive (list 'force current-prefix-arg))
eec82323 2589 (save-excursion
4e7d0221 2590 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2591 (if (gnus-buffer-live-p gnus-original-article-buffer)
2592 (with-current-buffer gnus-original-article-buffer
2593 (setq type
2594 (gnus-fetch-field "content-transfer-encoding"))
2595 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2596 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2597 (setq charset (and ctl
2598 (mail-content-type-get ctl 'charset)))
2599 (if (stringp charset)
2600 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2601 (if read-charset
2602 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2603 (unless charset
8b93df01 2604 (setq charset gnus-newsgroup-charset))
eec82323 2605 (when (or force
eb806ef3
DL
2606 (and type (let ((case-fold-search t))
2607 (string-match "quoted-printable" type))))
16409b0b 2608 (article-goto-body)
eb806ef3
DL
2609 (quoted-printable-decode-region
2610 (point) (point-max) (mm-charset-to-coding-system charset))))))
16409b0b 2611
23f87bed 2612(defun article-de-base64-unreadable (&optional force read-charset)
16409b0b 2613 "Translate a base64 article.
23f87bed
MB
2614If FORCE, decode the article whether it is marked as base64 not.
2615If READ-CHARSET, ask for a coding system."
2616 (interactive (list 'force current-prefix-arg))
16409b0b 2617 (save-excursion
4e7d0221 2618 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2619 (if (gnus-buffer-live-p gnus-original-article-buffer)
2620 (with-current-buffer gnus-original-article-buffer
2621 (setq type
2622 (gnus-fetch-field "content-transfer-encoding"))
2623 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2624 (ctl (and ct (mail-header-parse-content-type ct))))
8b93df01
DL
2625 (setq charset (and ctl
2626 (mail-content-type-get ctl 'charset)))
2627 (if (stringp charset)
2628 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2629 (if read-charset
2630 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2631 (unless charset
8b93df01 2632 (setq charset gnus-newsgroup-charset))
16409b0b 2633 (when (or force
eb806ef3
DL
2634 (and type (let ((case-fold-search t))
2635 (string-match "base64" type))))
16409b0b
GM
2636 (article-goto-body)
2637 (save-restriction
2638 (narrow-to-region (point) (point-max))
2639 (base64-decode-region (point-min) (point-max))
eb806ef3
DL
2640 (mm-decode-coding-region
2641 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
16409b0b
GM
2642
2643(eval-when-compile
2644 (require 'rfc1843))
2645
2646(defun article-decode-HZ ()
2647 "Translate a HZ-encoded article."
2648 (interactive)
2649 (require 'rfc1843)
2650 (save-excursion
4e7d0221 2651 (let ((inhibit-read-only t))
16409b0b
GM
2652 (rfc1843-decode-region (point-min) (point-max)))))
2653
23f87bed
MB
2654(defun article-unsplit-urls ()
2655 "Remove the newlines that some other mailers insert into URLs."
16409b0b 2656 (interactive)
23f87bed
MB
2657 (save-excursion
2658 (let ((inhibit-read-only t))
2659 (goto-char (point-min))
2660 (while (re-search-forward
97f78c9b 2661 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
23f87bed
MB
2662 (replace-match "\\1\\3" t)))
2663 (when (interactive-p)
2664 (gnus-treat-article nil))))
2665
2666
2667(defun article-wash-html (&optional read-charset)
2668 "Format an HTML article.
73043f7d
MB
2669If READ-CHARSET, ask for a coding system. If it is a number, the
2670charset defined in `gnus-summary-show-article-charset-alist' is used."
23f87bed 2671 (interactive "P")
16409b0b 2672 (save-excursion
4e7d0221 2673 (let ((inhibit-read-only t)
8b93df01 2674 charset)
73043f7d
MB
2675 (if read-charset
2676 (if (or (and (numberp read-charset)
2677 (setq charset
2678 (cdr
2679 (assq read-charset
2680 gnus-summary-show-article-charset-alist))))
2681 (setq charset (mm-read-coding-system "Charset: ")))
2682 (let ((gnus-summary-show-article-charset-alist
2683 (list (cons 1 charset))))
2684 (with-current-buffer gnus-summary-buffer
2685 (gnus-summary-show-article 1)))
2686 (error "No charset is given"))
2687 (when (gnus-buffer-live-p gnus-original-article-buffer)
2688 (with-current-buffer gnus-original-article-buffer
2689 (let* ((ct (gnus-fetch-field "content-type"))
c96ec15a 2690 (ctl (and ct (mail-header-parse-content-type ct))))
73043f7d
MB
2691 (setq charset (and ctl
2692 (mail-content-type-get ctl 'charset)))
2693 (when (stringp charset)
2694 (setq charset (intern (downcase charset)))))))
2695 (unless charset
2696 (setq charset gnus-newsgroup-charset)))
16409b0b
GM
2697 (article-goto-body)
2698 (save-window-excursion
2699 (save-restriction
2700 (narrow-to-region (point) (point-max))
23f87bed
MB
2701 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2702 (entry (assq func mm-text-html-washer-alist)))
2703 (when entry
2704 (setq func (cdr entry)))
2705 (cond
2706 ((functionp func)
2707 (funcall func))
2708 (t
2709 (apply (car func) (cdr func))))))))))
2710
9640c3bc
GM
2711;; External.
2712(declare-function w3-region "ext:w3-display" (st nd))
2713
23f87bed
MB
2714(defun gnus-article-wash-html-with-w3 ()
2715 "Wash the current buffer with w3."
2716 (mm-setup-w3)
2717 (let ((w3-strict-width (window-width))
2718 (url-standalone-mode t)
2719 (url-gateway-unplugged t)
2720 (w3-honor-stylesheets nil))
2721 (condition-case ()
2722 (w3-region (point-min) (point-max))
2723 (error))))
2724
9640c3bc
GM
2725;; External.
2726(declare-function w3m-region "ext:w3m" (start end &optional url charset))
2727
23f87bed
MB
2728(defun gnus-article-wash-html-with-w3m ()
2729 "Wash the current buffer with emacs-w3m."
2730 (mm-setup-w3m)
7dafe00b
MB
2731 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2732 w3m-force-redisplay)
2733 (w3m-region (point-min) (point-max)))
2734 (when (and mm-inline-text-html-with-w3m-keymap
2735 (boundp 'w3m-minor-mode-map)
2736 w3m-minor-mode-map)
2737 (add-text-properties
2738 (point-min) (point-max)
2739 (list 'keymap w3m-minor-mode-map
2740 ;; Put the mark meaning this part was rendered by emacs-w3m.
2741 'mm-inline-text-html-with-w3m t))))
16409b0b 2742
9efa445f 2743(defvar charset) ;; Bound by `article-wash-html'.
73043f7d
MB
2744
2745(defun gnus-article-wash-html-with-w3m-standalone ()
2746 "Wash the current buffer with w3m."
7347faa8
MB
2747 (if (mm-w3m-standalone-supports-m17n-p)
2748 (progn
2749 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2750 ;; The default.
2751 (setq charset 'iso-8859-1))
2752 (let ((coding-system-for-write charset)
2753 (coding-system-for-read charset))
2754 (call-process-region
2755 (point-min) (point-max)
2756 "w3m" t t nil "-dump" "-T" "text/html"
2757 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2758 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
73043f7d 2759
01c52d31
MB
2760(defvar gnus-article-browse-html-temp-list nil
2761 "List of temporary files created by `gnus-article-browse-html-parts'.
2762Internal variable.")
2763
2764(defcustom gnus-article-browse-delete-temp 'ask
2765 "What to do with temporary files from `gnus-article-browse-html-parts'.
2766If nil, don't delete temporary files. If it is t, delete them on
2767exit from the summary buffer. If it is the symbol `file', query
2768on each file, if it is `ask' ask once when exiting from the
2769summary buffer."
2770 :group 'gnus-article
2771 :version "23.0" ;; No Gnus
2772 :type '(choice (const :tag "Don't delete" nil)
2773 (const :tag "Don't ask" t)
2774 (const :tag "Ask" ask)
2775 (const :tag "Ask for each file" file)))
2776
2777;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2778
2779(defun gnus-article-browse-delete-temp-files (&optional how)
2780 "Delete temp-files created by `gnus-article-browse-html-parts'."
2781 (when (and gnus-article-browse-html-temp-list
2782 (or how
2783 (setq how gnus-article-browse-delete-temp)))
2784 (when (and (eq how 'ask)
bbbe940b
MB
2785 (gnus-y-or-n-p (format
2786 "Delete all %s temporary HTML file(s)? "
2787 (length gnus-article-browse-html-temp-list)))
01c52d31
MB
2788 (setq how t)))
2789 (dolist (file gnus-article-browse-html-temp-list)
2790 (when (and (file-exists-p file)
2791 (or (eq how t)
2792 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2793 (gnus-y-or-n-p
2794 (format "Delete temporary HTML file `%s'? " file))))
2795 (delete-file file)))
2796 ;; Also remove file from the list when not deleted or if file doesn't
2797 ;; exist anymore.
2798 (setq gnus-article-browse-html-temp-list nil))
2799 gnus-article-browse-html-temp-list)
2800
87035689 2801(defun gnus-article-browse-html-parts (list &optional header)
01c52d31 2802 "View all \"text/html\" parts from LIST.
87035689
MB
2803Recurse into multiparts. The optional HEADER that should be a decoded
2804message header will be added to the bodies of the \"text/html\" parts."
01c52d31 2805 ;; Internal function used by `gnus-article-browse-html-article'.
bbbe940b 2806 (let (type file charset tmp-file showed)
01c52d31
MB
2807 ;; Find and show the html-parts.
2808 (dolist (handle list)
2809 ;; If HTML, show it:
bbbe940b
MB
2810 (cond ((not (listp handle)))
2811 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2812 (and (equal (car type) "message/external-body")
87035689
MB
2813 (or header
2814 (setq file (or (mail-content-type-get type 'name)
2815 (mail-content-type-get
2816 (mm-handle-disposition handle)
2817 'filename))))
bbbe940b
MB
2818 (or (mm-handle-cache handle)
2819 (condition-case code
2820 (progn (mm-extern-cache-contents handle) t)
2821 (error
2822 (gnus-message 3 "%s" (error-message-string code))
2823 (when (>= gnus-verbose 3) (sit-for 2))
2824 nil)))
2825 (progn
2826 (setq handle (mm-handle-cache handle)
2827 type (mm-handle-type handle))
2828 (equal (car type) "text/html"))))
2829 (when (or (setq charset (mail-content-type-get type 'charset))
87035689 2830 header
bbbe940b
MB
2831 (not file))
2832 (setq tmp-file (mm-make-temp-file
2833 ;; Do we need to care for 8.3 filenames?
2834 "mm-" nil ".html")))
87035689
MB
2835 ;; Add a meta html tag to specify charset and a header.
2836 (cond
2837 (header
2838 (let (title eheader body hcharset coding)
2839 (with-temp-buffer
2840 (mm-enable-multibyte)
2841 (setq case-fold-search t)
2842 (insert header "\n")
2843 (setq title (message-fetch-field "subject"))
2844 (goto-char (point-min))
2845 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2846 (replace-match (cond ((match-beginning 1) "&lt;")
2847 ((match-beginning 2) "&gt;")
2848 (t "&amp;"))))
2849 (goto-char (point-min))
2850 (insert "<pre>\n")
2851 (goto-char (point-max))
2852 (insert "</pre>\n<hr>\n")
2853 ;; We have to examine charset one by one since
2854 ;; charset specified in parts might be different.
2855 (if (eq charset 'gnus-decoded)
2856 (setq charset 'utf-8
2857 eheader (mm-encode-coding-string (buffer-string)
2858 charset)
2859 title (when title
2860 (mm-encode-coding-string title charset))
2861 body (mm-encode-coding-string (mm-get-part handle)
2862 charset))
2863 (setq hcharset (mm-find-mime-charset-region (point-min)
2864 (point-max)))
2865 (cond ((= (length hcharset) 1)
2866 (setq hcharset (car hcharset)
2867 coding (mm-charset-to-coding-system
2868 hcharset)))
2869 ((> (length hcharset) 1)
2870 (setq hcharset 'utf-8
2871 coding hcharset)))
2872 (if coding
2873 (if charset
2874 (progn
2875 (setq body
2876 (mm-charset-to-coding-system charset))
2877 (if (eq coding body)
2878 (setq eheader (mm-encode-coding-string
2879 (buffer-string) coding)
2880 title (when title
2881 (mm-encode-coding-string
2882 title coding))
2883 body (mm-get-part handle))
2884 (setq charset 'utf-8
2885 eheader (mm-encode-coding-string
2886 (buffer-string) charset)
2887 title (when title
2888 (mm-encode-coding-string
2889 title charset))
2890 body (mm-encode-coding-string
2891 (mm-decode-coding-string
2892 (mm-get-part handle) body)
2893 charset))))
2894 (setq charset hcharset
2895 eheader (mm-encode-coding-string
2896 (buffer-string) coding)
2897 title (when title
2898 (mm-encode-coding-string
2899 title coding))
2900 body (mm-get-part handle)))
2901 (setq eheader (mm-string-as-unibyte (buffer-string))
2902 body (mm-get-part handle))))
2903 (erase-buffer)
2904 (mm-disable-multibyte)
2905 (insert body)
2906 (when charset
2907 (mm-add-meta-html-tag handle charset))
2908 (when title
2909 (goto-char (point-min))
2910 (unless (search-forward "<title>" nil t)
2911 (re-search-forward "<head>\\s-*" nil t)
2912 (insert "<title>" title "</title>\n")))
2913 (goto-char (point-min))
2914 (or (re-search-forward
2915 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2916 (re-search-forward
2917 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2918 (insert eheader)
2919 (mm-write-region (point-min) (point-max)
2920 tmp-file nil nil nil 'binary t))))
2921 (charset
2922 (mm-with-unibyte-buffer
2923 (insert (if (eq charset 'gnus-decoded)
2924 (mm-encode-coding-string
2925 (mm-get-part handle)
2926 (setq charset 'utf-8))
2927 (mm-get-part handle)))
2928 (if (or (mm-add-meta-html-tag handle charset)
2929 (not file))
2930 (mm-write-region (point-min) (point-max)
2931 tmp-file nil nil nil 'binary t)
2932 (setq tmp-file nil))))
2933 (tmp-file
2934 (mm-save-part-to-file handle tmp-file)))
bbbe940b
MB
2935 (when tmp-file
2936 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2937 (add-hook 'gnus-summary-prepare-exit-hook
2938 'gnus-article-browse-delete-temp-files)
2939 (add-hook 'gnus-exit-gnus-hook
2940 (lambda ()
2941 (gnus-article-browse-delete-temp-files t)))
2942 ;; FIXME: Warn if there's an <img> tag?
2943 (browse-url-of-file (or tmp-file (expand-file-name file)))
2944 (setq showed t))
2945 ;; If multipart, recurse
87035689
MB
2946 ((equal (mm-handle-media-supertype handle) "multipart")
2947 (when (gnus-article-browse-html-parts handle header)
2948 (setq showed t)))
2949 ((equal (mm-handle-media-type handle) "message/rfc822")
2950 (mm-with-multibyte-buffer
2951 (mm-insert-part handle)
2952 (setq handle (mm-dissect-buffer t t))
2953 (when (and (bufferp (car handle))
2954 (stringp (car (mm-handle-type handle))))
2955 (setq handle (list handle)))
2956 (when header
2957 (article-decode-encoded-words)
2958 (let ((gnus-visible-headers
2959 (or (get 'gnus-visible-headers 'standard-value)
2960 gnus-visible-headers)))
2961 (article-hide-headers))
2962 (goto-char (point-min))
2963 (search-forward "\n\n" nil 'move)
2964 (skip-chars-backward "\t\n ")
2965 (setq header (buffer-substring (point-min) (point)))))
2966 (when (prog1
2967 (gnus-article-browse-html-parts handle header)
2968 (mm-destroy-parts handle))
2969 (setq showed t)))))
01c52d31
MB
2970 showed))
2971
2972;; FIXME: Documentation in texi/gnus.texi missing.
87035689 2973(defun gnus-article-browse-html-article (&optional arg)
01c52d31 2974 "View \"text/html\" parts of the current article with a WWW browser.
87035689
MB
2975The message header is added to the beginning of every html part unless
2976the prefix argument ARG is given.
01c52d31
MB
2977
2978Warning: Spammers use links to images in HTML articles to verify
2979whether you have read the message. As
2980`gnus-article-browse-html-article' passes the unmodified HTML
2981content to the browser without eliminating these \"web bugs\" you
b890d447
MB
2982should only use it for mails from trusted senders.
2983
2984If you alwasy want to display HTML part in the browser, set
2985`mm-text-html-renderer' to nil."
01c52d31 2986 ;; Cf. `mm-w3m-safe-url-regexp'
87035689
MB
2987 (interactive "P")
2988 (if arg
2989 (gnus-summary-show-article)
2990 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
2991 gnus-visible-headers)))
2992 (gnus-summary-show-article)))
2993 (with-current-buffer gnus-article-buffer
2994 (let ((header (unless arg
2995 (save-restriction
2996 (widen)
2997 (buffer-substring-no-properties
2998 (goto-char (point-min))
2999 (if (search-forward "\n\n" nil t)
3000 (match-beginning 0)
3001 (goto-char (point-max))
3002 (skip-chars-backward "\t\n ")
3003 (point))))))
3004 parts)
3005 (set-buffer gnus-original-article-buffer)
3006 (setq parts (mm-dissect-buffer t t))
01c52d31
MB
3007 ;; If singlepart, enforce a list.
3008 (when (and (bufferp (car parts))
3009 (stringp (car (mm-handle-type parts))))
3010 (setq parts (list parts)))
3011 ;; Process the list
87035689 3012 (unless (gnus-article-browse-html-parts parts header)
01c52d31 3013 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
87035689
MB
3014 (mm-destroy-parts parts)
3015 (unless arg
3016 (gnus-summary-show-article)))))
01c52d31 3017
16409b0b
GM
3018(defun article-hide-list-identifiers ()
3019 "Remove list identifies from the Subject header.
3020The `gnus-list-identifiers' variable specifies what to do."
3021 (interactive)
23f87bed
MB
3022 (let ((inhibit-point-motion-hooks t)
3023 (regexp (if (consp gnus-list-identifiers)
3024 (mapconcat 'identity gnus-list-identifiers " *\\|")
3025 gnus-list-identifiers))
3026 (inhibit-read-only t))
3027 (when regexp
3028 (save-excursion
3029 (save-restriction
3030 (article-narrow-to-head)
3031 (goto-char (point-min))
3032 (while (re-search-forward
3033 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3034 nil t)
3035 (delete-region (match-beginning 2) (match-end 0))
3036 (beginning-of-line))
3037 (when (re-search-forward
3038 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3039 (delete-region (match-beginning 1) (match-end 1))))))))
eec82323
LMI
3040
3041(defun article-hide-pem (&optional arg)
3042 "Toggle hiding of any PEM headers and signatures in the current article.
3043If given a negative prefix, always show; if given a positive prefix,
3044always hide."
3045 (interactive (gnus-article-hidden-arg))
3046 (unless (gnus-article-check-hidden-text 'pem arg)
3047 (save-excursion
23f87bed 3048 (let ((inhibit-read-only t) end)
eec82323 3049 (goto-char (point-min))
16409b0b
GM
3050 ;; Hide the horrendously ugly "header".
3051 (when (and (search-forward
3052 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3053 nil t)
3054 (setq end (1+ (match-beginning 0))))
23f87bed 3055 (gnus-add-wash-type 'pem)
16409b0b
GM
3056 (gnus-article-hide-text-type
3057 end
3058 (if (search-forward "\n\n" nil t)
3059 (match-end 0)
3060 (point-max))
3061 'pem)
3062 ;; Hide the trailer as well
3063 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3064 nil t)
3065 (gnus-article-hide-text-type
3066 (match-beginning 0) (match-end 0) 'pem)))))))
3067
3068(defun article-strip-banner ()
23f87bed
MB
3069 "Strip the banners specified by the `banner' group parameter and by
3070`gnus-article-address-banner-alist'."
16409b0b 3071 (interactive)
23f87bed
MB
3072 (save-excursion
3073 (save-restriction
3074 (let ((inhibit-point-motion-hooks t))
3075 (when (gnus-parameter-banner gnus-newsgroup-name)
3076 (article-really-strip-banner
3077 (gnus-parameter-banner gnus-newsgroup-name)))
3078 (when gnus-article-address-banner-alist
cf5a5c38
MB
3079 ;; Note that the From header is decoded here, so it is
3080 ;; required that the *-extract-address-components function
3081 ;; supports non-ASCII text.
d71c0855
MB
3082 (let ((from (save-restriction
3083 (widen)
3084 (article-narrow-to-head)
3085 (mail-fetch-field "from"))))
3086 (when (and from
3087 (setq from
3088 (cadr (funcall gnus-extract-address-components
3089 from))))
3090 (catch 'found
3091 (dolist (pair gnus-article-address-banner-alist)
3092 (when (string-match (car pair) from)
3093 (throw 'found
3094 (article-really-strip-banner (cdr pair)))))))))))))
23f87bed
MB
3095
3096(defun article-really-strip-banner (banner)
3097 "Strip the banner specified by the argument."
16409b0b
GM
3098 (save-excursion
3099 (save-restriction
3100 (let ((inhibit-point-motion-hooks t)
16409b0b 3101 (gnus-signature-limit nil)
23f87bed
MB
3102 (inhibit-read-only t))
3103 (article-goto-body)
3104 (cond
3105 ((eq banner 'signature)
3106 (when (gnus-article-narrow-to-signature)
3107 (widen)
3108 (forward-line -1)
3109 (delete-region (point) (point-max))))
3110 ((symbolp banner)
3111 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3112 (while (re-search-forward banner nil t)
3113 (delete-region (match-beginning 0) (match-end 0)))))
3114 ((stringp banner)
3115 (while (re-search-forward banner nil t)
3116 (delete-region (match-beginning 0) (match-end 0)))))))))
16409b0b
GM
3117
3118(defun article-babel ()
3119 "Translate article using an online translation service."
3120 (interactive)
3121 (require 'babel)
01c52d31 3122 (gnus-with-article-buffer
16409b0b 3123 (when (article-goto-body)
01c52d31 3124 (let* ((start (point))
16409b0b
GM
3125 (end (point-max))
3126 (orig (buffer-substring start end))
23f87bed 3127 (trans (babel-as-string orig)))
16409b0b
GM
3128 (save-restriction
3129 (narrow-to-region start end)
3130 (delete-region start end)
23f87bed 3131 (insert trans))))))
eec82323
LMI
3132
3133(defun article-hide-signature (&optional arg)
3134 "Hide the signature in the current article.
3135If given a negative prefix, always show; if given a positive prefix,
3136always hide."
3137 (interactive (gnus-article-hidden-arg))
3138 (unless (gnus-article-check-hidden-text 'signature arg)
3139 (save-excursion
3140 (save-restriction
4e7d0221 3141 (let ((inhibit-read-only t))
eec82323
LMI
3142 (when (gnus-article-narrow-to-signature)
3143 (gnus-article-hide-text-type
23f87bed
MB
3144 (point-min) (point-max) 'signature))))))
3145 (gnus-set-mode-line 'article))
eec82323 3146
16409b0b
GM
3147(defun article-strip-headers-in-body ()
3148 "Strip offensive headers from bodies."
3149 (interactive)
3150 (save-excursion
3151 (article-goto-body)
3152 (let ((case-fold-search t))
3153 (when (looking-at "x-no-archive:")
3154 (gnus-delete-line)))))
3155
eec82323
LMI
3156(defun article-strip-leading-blank-lines ()
3157 "Remove all blank lines from the beginning of the article."
3158 (interactive)
3159 (save-excursion
3160 (let ((inhibit-point-motion-hooks t)
23f87bed 3161 (inhibit-read-only t))
16409b0b 3162 (when (article-goto-body)
eec82323
LMI
3163 (while (and (not (eobp))
3164 (looking-at "[ \t]*$"))
3165 (gnus-delete-line))))))
3166
16409b0b
GM
3167(defun article-narrow-to-head ()
3168 "Narrow the buffer to the head of the message.
3169Point is left at the beginning of the narrowed-to region."
3170 (narrow-to-region
3171 (goto-char (point-min))
3172 (if (search-forward "\n\n" nil 1)
3173 (1- (point))
3174 (point-max)))
3175 (goto-char (point-min)))
3176
3177(defun article-goto-body ()
3178 "Place point at the start of the body."
3179 (goto-char (point-min))
3180 (cond
3181 ;; This variable is only bound when dealing with separate
3182 ;; MIME body parts.
3183 (article-goto-body-goes-to-point-min-p
3184 t)
3185 ((search-forward "\n\n" nil t)
3186 t)
3187 (t
3188 (goto-char (point-max))
3189 nil)))
3190
eec82323
LMI
3191(defun article-strip-multiple-blank-lines ()
3192 "Replace consecutive blank lines with one empty line."
3193 (interactive)
3194 (save-excursion
3195 (let ((inhibit-point-motion-hooks t)
23f87bed 3196 (inhibit-read-only t))
eec82323 3197 ;; First make all blank lines empty.
16409b0b 3198 (article-goto-body)
eec82323 3199 (while (re-search-forward "^[ \t]+$" nil t)
16409b0b
GM
3200 (unless (gnus-annotation-in-region-p
3201 (match-beginning 0) (match-end 0))
3202 (replace-match "" nil t)))
eec82323 3203 ;; Then replace multiple empty lines with a single empty line.
16409b0b 3204 (article-goto-body)
23f87bed 3205 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
16409b0b
GM
3206 (unless (gnus-annotation-in-region-p
3207 (match-beginning 0) (match-end 0))
23f87bed 3208 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3209
3210(defun article-strip-leading-space ()
3211 "Remove all white space from the beginning of the lines in the article."
3212 (interactive)
3213 (save-excursion
3214 (let ((inhibit-point-motion-hooks t)
23f87bed 3215 (inhibit-read-only t))
16409b0b 3216 (article-goto-body)
eec82323
LMI
3217 (while (re-search-forward "^[ \t]+" nil t)
3218 (replace-match "" t t)))))
3219
16409b0b
GM
3220(defun article-strip-trailing-space ()
3221 "Remove all white space from the end of the lines in the article."
3222 (interactive)
3223 (save-excursion
3224 (let ((inhibit-point-motion-hooks t)
23f87bed 3225 (inhibit-read-only t))
16409b0b
GM
3226 (article-goto-body)
3227 (while (re-search-forward "[ \t]+$" nil t)
3228 (replace-match "" t t)))))
3229
eec82323
LMI
3230(defun article-strip-blank-lines ()
3231 "Strip leading, trailing and multiple blank lines."
3232 (interactive)
3233 (article-strip-leading-blank-lines)
3234 (article-remove-trailing-blank-lines)
3235 (article-strip-multiple-blank-lines))
3236
6748645f
LMI
3237(defun article-strip-all-blank-lines ()
3238 "Strip all blank lines."
3239 (interactive)
3240 (save-excursion
3241 (let ((inhibit-point-motion-hooks t)
23f87bed 3242 (inhibit-read-only t))
16409b0b 3243 (article-goto-body)
6748645f
LMI
3244 (while (re-search-forward "^[ \t]*\n" nil t)
3245 (replace-match "" t t)))))
3246
eec82323
LMI
3247(defun gnus-article-narrow-to-signature ()
3248 "Narrow to the signature; return t if a signature is found, else nil."
6748645f 3249 (let ((inhibit-point-motion-hooks t))
6748645f
LMI
3250 (when (gnus-article-search-signature)
3251 (forward-line 1)
3252 ;; Check whether we have some limits to what we consider
3253 ;; to be a signature.
3254 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3255 (list gnus-signature-limit)))
3256 limit limited)
3257 (while (setq limit (pop limits))
3258 (if (or (and (integerp limit)
3259 (< (- (point-max) (point)) limit))
3260 (and (floatp limit)
3261 (< (count-lines (point) (point-max)) limit))
23f87bed 3262 (and (functionp limit)
6748645f
LMI
3263 (funcall limit))
3264 (and (stringp limit)
3265 (not (re-search-forward limit nil t))))
3266 () ; This limit did not succeed.
3267 (setq limited t
3268 limits nil)))
3269 (unless limited
3270 (narrow-to-region (point) (point-max))
3271 t)))))
eec82323
LMI
3272
3273(defun gnus-article-search-signature ()
3274 "Search the current buffer for the signature separator.
3275Put point at the beginning of the signature separator."
3276 (let ((cur (point)))
3277 (goto-char (point-max))
3278 (if (if (stringp gnus-signature-separator)
3279 (re-search-backward gnus-signature-separator nil t)
3280 (let ((seps gnus-signature-separator))
3281 (while (and seps
3282 (not (re-search-backward (car seps) nil t)))
3283 (pop seps))
3284 seps))
3285 t
3286 (goto-char cur)
3287 nil)))
3288
eec82323
LMI
3289(defun gnus-article-hidden-arg ()
3290 "Return the current prefix arg as a number, or 0 if no prefix."
3291 (list (if current-prefix-arg
3292 (prefix-numeric-value current-prefix-arg)
3293 0)))
3294
3295(defun gnus-article-check-hidden-text (type arg)
3296 "Return nil if hiding is necessary.
f0529b5b 3297Arg can be nil or a number. nil and positive means hide, negative
eec82323
LMI
3298means show, 0 means toggle."
3299 (save-excursion
3300 (save-restriction
eec82323
LMI
3301 (let ((hide (gnus-article-hidden-text-p type)))
3302 (cond
3303 ((or (null arg)
3304 (> arg 0))
3305 nil)
3306 ((< arg 0)
4481aa98
SZ
3307 (gnus-article-show-hidden-text type)
3308 t)
eec82323
LMI
3309 (t
3310 (if (eq hide 'hidden)
4481aa98
SZ
3311 (progn
3312 (gnus-article-show-hidden-text type)
3313 t)
eec82323
LMI
3314 nil)))))))
3315
3316(defun gnus-article-hidden-text-p (type)
3317 "Say whether the current buffer contains hidden text of type TYPE."
6748645f 3318 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
eec82323 3319 (while (and pos
16409b0b
GM
3320 (not (get-text-property pos 'invisible))
3321 (not (get-text-property pos 'dummy-invisible)))
eec82323
LMI
3322 (setq pos
3323 (text-property-any (1+ pos) (point-max) 'article-type type)))
3324 (if pos
3325 'hidden
16409b0b 3326 nil)))
eec82323 3327
520aa572 3328(defun gnus-article-show-hidden-text (type &optional dummy)
eec82323 3329 "Show all hidden text of type TYPE.
520aa572 3330Originally it is hide instead of DUMMY."
4e7d0221 3331 (let ((inhibit-read-only t)
520aa572 3332 (inhibit-point-motion-hooks t))
a1506d29 3333 (gnus-remove-text-properties-when
520aa572 3334 'article-type type
a1506d29 3335 (point-min) (point-max)
520aa572 3336 (cons 'article-type (cons type
23f87bed
MB
3337 gnus-hidden-properties)))
3338 (gnus-delete-wash-type type)))
eec82323
LMI
3339
3340(defconst article-time-units
3341 `((year . ,(* 365.25 24 60 60))
3342 (week . ,(* 7 24 60 60))
3343 (day . ,(* 24 60 60))
3344 (hour . ,(* 60 60))
3345 (minute . 60)
3346 (second . 1))
3347 "Mapping from time units to seconds.")
3348
23f87bed
MB
3349(defun gnus-article-forward-header ()
3350 "Move point to the start of the next header.
3351If the current header is a continuation header, this can be several
3352lines forward."
3353 (let ((ended nil))
3354 (while (not ended)
3355 (forward-line 1)
3356 (if (looking-at "[ \t]+[^ \t]")
3357 (forward-line 1)
3358 (setq ended t)))))
3359
31640842 3360(defun article-date-ut (&optional type highlight)
eec82323
LMI
3361 "Convert DATE date to universal time in the current article.
3362If TYPE is `local', convert to local time; if it is `lapsed', output
16409b0b
GM
3363how much time has lapsed since DATE. For `lapsed', the value of
3364`gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3365should replace the \"Date:\" one, or should be added below it."
eec82323 3366 (interactive (list 'ut t))
31640842
MB
3367 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3368 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3369 tdate-regexp)
3370 ((eq type 'lapsed)
3371 "^X-Sent:[ \t]")
3372 (article-lapsed-timer
3373 "^Date:[ \t]")
3374 (t
3375 tdate-regexp)))
3376 (case-fold-search t)
3377 (inhibit-read-only t)
eec82323 3378 (inhibit-point-motion-hooks t)
31640842 3379 pos date bface eface)
16409b0b
GM
3380 (save-excursion
3381 (save-restriction
31640842
MB
3382 (widen)
3383 (goto-char (point-min))
3384 (while (or (setq date (get-text-property (setq pos (point))
3385 'original-date))
3386 (when (setq pos (next-single-property-change
3387 (point) 'original-date))
3388 (setq date (get-text-property pos 'original-date))
3389 t))
3390 (narrow-to-region pos (or (text-property-any pos (point-max)
3391 'original-date nil)
3392 (point-max)))
16409b0b 3393 (goto-char (point-min))
31640842 3394 (when (re-search-forward tdate-regexp nil t)
01c52d31
MB
3395 (setq bface (get-text-property (point-at-bol) 'face)
3396 eface (get-text-property (1- (point-at-eol)) 'face)))
31640842
MB
3397 (goto-char (point-min))
3398 (setq pos nil)
3399 ;; Delete any old Date headers.
3400 (while (re-search-forward date-regexp nil t)
3401 (if pos
01c52d31
MB
3402 (delete-region (point-at-bol) (progn
3403 (gnus-article-forward-header)
3404 (point)))
3405 (delete-region (point-at-bol) (progn
3406 (gnus-article-forward-header)
3407 (forward-char -1)
3408 (point)))
31640842
MB
3409 (setq pos (point))))
3410 (when (and (not pos)
3411 (re-search-forward tdate-regexp nil t))
3412 (forward-line 1))
3413 (gnus-goto-char pos)
3414 (insert (article-make-date-line date (or type 'ut)))
3415 (unless pos
3416 (insert "\n")
3417 (forward-line -1))
3418 ;; Do highlighting.
3419 (beginning-of-line)
3420 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3421 (put-text-property (match-beginning 1) (1+ (match-end 1))
3422 'face bface)
3423 (put-text-property (match-beginning 2) (match-end 2)
3424 'face eface))
3425 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3426 (goto-char (point-max))
3427 (widen))))))
eec82323
LMI
3428
3429(defun article-make-date-line (date type)
3430 "Return a DATE line of TYPE."
23f87bed
MB
3431 (unless (memq type '(local ut original user iso8601 lapsed english))
3432 (error "Unknown conversion type: %s" type))
3433 (condition-case ()
3434 (let ((time (date-to-time date)))
16409b0b 3435 (cond
23f87bed
MB
3436 ;; Convert to the local timezone.
3437 ((eq type 'local)
01c52d31 3438 (concat "Date: " (message-make-date time)))
23f87bed
MB
3439 ;; Convert to Universal Time.
3440 ((eq type 'ut)
3441 (concat "Date: "
01c52d31
MB
3442 (substring
3443 (message-make-date
3444 (let* ((e (parse-time-string date))
3445 (tm (apply 'encode-time e))
3446 (ms (car tm))
3447 (ls (- (cadr tm) (car (current-time-zone time)))))
3448 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3449 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3450 (t (list ms ls)))))
3451 0 -5)
3452 "UT"))
23f87bed
MB
3453 ;; Get the original date from the article.
3454 ((eq type 'original)
3455 (concat "Date: " (if (string-match "\n+$" date)
3456 (substring date 0 (match-beginning 0))
3457 date)))
3458 ;; Let the user define the format.
3459 ((eq type 'user)
3460 (let ((format (or (condition-case nil
3461 (with-current-buffer gnus-summary-buffer
3462 gnus-article-time-format)
3463 (error nil))
3464 gnus-article-time-format)))
3465 (if (functionp format)
3466 (funcall format time)
3467 (concat "Date: " (format-time-string format time)))))
3468 ;; ISO 8601.
3469 ((eq type 'iso8601)
3470 (let ((tz (car (current-time-zone time))))
3471 (concat
3472 "Date: "
3473 (format-time-string "%Y%m%dT%H%M%S" time)
3474 (format "%s%02d%02d"
3475 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3476 (/ (% (abs tz) 3600) 60)))))
3477 ;; Do an X-Sent lapsed format.
3478 ((eq type 'lapsed)
3479 ;; If the date is seriously mangled, the timezone functions are
3480 ;; liable to bug out, so we ignore all errors.
3481 (let* ((now (current-time))
3482 (real-time (subtract-time now time))
3483 (real-sec (and real-time
3484 (+ (* (float (car real-time)) 65536)
3485 (cadr real-time))))
3486 (sec (and real-time (abs real-sec)))
3487 num prev)
3488 (cond
3489 ((null real-time)
3490 "X-Sent: Unknown")
3491 ((zerop sec)
3492 "X-Sent: Now")
3493 (t
3494 (concat
3495 "X-Sent: "
3496 ;; This is a bit convoluted, but basically we go
3497 ;; through the time units for years, weeks, etc,
3498 ;; and divide things to see whether that results
3499 ;; in positive answers.
3500 (mapconcat
3501 (lambda (unit)
3502 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3503 ;; The (remaining) seconds are too few to
3504 ;; be divided into this time unit.
3505 ""
3506 ;; It's big enough, so we output it.
3507 (setq sec (- sec (* num (cdr unit))))
3508 (prog1
3509 (concat (if prev ", " "") (int-to-string
3510 (floor num))
3511 " " (symbol-name (car unit))
3512 (if (> num 1) "s" ""))
3513 (setq prev t))))
3514 article-time-units "")
3515 ;; If dates are odd, then it might appear like the
3516 ;; article was sent in the future.
3517 (if (> real-sec 0)
3518 " ago"
3519 " in the future"))))))
3520 ;; Display the date in proper English
3521 ((eq type 'english)
3522 (let ((dtime (decode-time time)))
3523 (concat
3524 "Date: the "
3525 (number-to-string (nth 3 dtime))
3526 (let ((digit (% (nth 3 dtime) 10)))
3527 (cond
3528 ((memq (nth 3 dtime) '(11 12 13)) "th")
3529 ((= digit 1) "st")
3530 ((= digit 2) "nd")
3531 ((= digit 3) "rd")
3532 (t "th")))
3533 " of "
3534 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3535 " "
3536 (number-to-string (nth 5 dtime))
3537 " at "
3538 (format "%02d" (nth 2 dtime))
3539 ":"
3540 (format "%02d" (nth 1 dtime)))))))
3541 (error
a601fb74 3542 (format "Date: %s (from Gnus)" date))))
eec82323
LMI
3543
3544(defun article-date-local (&optional highlight)
3545 "Convert the current article date to the local timezone."
3546 (interactive (list t))
3547 (article-date-ut 'local highlight))
3548
23f87bed
MB
3549(defun article-date-english (&optional highlight)
3550 "Convert the current article date to something that is proper English."
3551 (interactive (list t))
3552 (article-date-ut 'english highlight))
3553
eec82323
LMI
3554(defun article-date-original (&optional highlight)
3555 "Convert the current article date to what it was originally.
3556This is only useful if you have used some other date conversion
3557function and want to see what the date was before converting."
3558 (interactive (list t))
3559 (article-date-ut 'original highlight))
3560
3561(defun article-date-lapsed (&optional highlight)
3562 "Convert the current article date to time lapsed since it was sent."
3563 (interactive (list t))
3564 (article-date-ut 'lapsed highlight))
3565
6748645f
LMI
3566(defun article-update-date-lapsed ()
3567 "Function to be run from a timer to update the lapsed time line."
e0a8aa09
LT
3568 (save-match-data
3569 (let (deactivate-mark)
3570 (save-excursion
3571 (ignore-errors
3572 (walk-windows
3573 (lambda (w)
3574 (set-buffer (window-buffer w))
3575 (when (eq major-mode 'gnus-article-mode)
3576 (let ((mark (point-marker)))
3577 (goto-char (point-min))
3578 (when (re-search-forward "^X-Sent:" nil t)
3579 (article-date-lapsed t))
3580 (goto-char (marker-position mark))
3581 (move-marker mark nil))))
3582 nil 'visible))))))
6748645f
LMI
3583
3584(defun gnus-start-date-timer (&optional n)
3585 "Start a timer to update the X-Sent header in the article buffers.
3586The numerical prefix says how frequently (in seconds) the function
3587is to run."
3588 (interactive "p")
3589 (unless n
3590 (setq n 1))
3591 (gnus-stop-date-timer)
3592 (setq article-lapsed-timer
01c52d31 3593 (run-at-time 1 n 'article-update-date-lapsed)))
6748645f
LMI
3594
3595(defun gnus-stop-date-timer ()
3596 "Stop the X-Sent timer."
3597 (interactive)
3598 (when article-lapsed-timer
3599 (nnheader-cancel-timer article-lapsed-timer)
3600 (setq article-lapsed-timer nil)))
3601
eec82323
LMI
3602(defun article-date-user (&optional highlight)
3603 "Convert the current article date to the user-defined format.
3604This format is defined by the `gnus-article-time-format' variable."
3605 (interactive (list t))
3606 (article-date-ut 'user highlight))
3607
6748645f
LMI
3608(defun article-date-iso8601 (&optional highlight)
3609 "Convert the current article date to ISO8601."
3610 (interactive (list t))
3611 (article-date-ut 'iso8601 highlight))
3612
31640842
MB
3613(defmacro gnus-article-save-original-date (&rest forms)
3614 "Save the original date as a text property and evaluate FORMS."
3615 `(let* ((case-fold-search t)
3616 (start (progn
3617 (goto-char (point-min))
3618 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3619 (not (bolp)))
3620 (match-end 0))))
3621 (date (when (and start
01c52d31 3622 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
31640842
MB
3623 nil t))
3624 (buffer-substring-no-properties start
3625 (match-beginning 0)))))
3626 (goto-char (point-max))
3627 (skip-chars-backward "\n")
3628 (put-text-property (point-min) (point) 'original-date date)
3629 ,@forms
3630 (goto-char (point-max))
3631 (skip-chars-backward "\n")
3632 (put-text-property (point-min) (point) 'original-date date)))
3633
23f87bed
MB
3634;; (defun article-show-all ()
3635;; "Show all hidden text in the article buffer."
3636;; (interactive)
3637;; (save-excursion
3638;; (let ((inhibit-read-only t))
3639;; (gnus-article-unhide-text (point-min) (point-max)))))
3640
3641(defun article-remove-leading-whitespace ()
3642 "Remove excessive whitespace from all headers."
eec82323
LMI
3643 (interactive)
3644 (save-excursion
23f87bed
MB
3645 (save-restriction
3646 (let ((inhibit-read-only t))
3647 (article-narrow-to-head)
3648 (goto-char (point-min))
3649 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3650 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3651
3652(defun article-emphasize (&optional arg)
3653 "Emphasize text according to `gnus-emphasis-alist'."
3654 (interactive (gnus-article-hidden-arg))
3655 (unless (gnus-article-check-hidden-text 'emphasis arg)
3656 (save-excursion
a1506d29 3657 (let ((alist (or
16409b0b 3658 (condition-case nil
a1506d29
JB
3659 (with-current-buffer gnus-summary-buffer
3660 gnus-article-emphasis-alist)
16409b0b
GM
3661 (error))
3662 gnus-emphasis-alist))
4e7d0221 3663 (inhibit-read-only t)
eec82323
LMI
3664 (props (append '(article-type emphasis)
3665 gnus-hidden-properties))
3666 regexp elem beg invisible visible face)
16409b0b 3667 (article-goto-body)
eec82323
LMI
3668 (setq beg (point))
3669 (while (setq elem (pop alist))
3670 (goto-char beg)
3671 (setq regexp (car elem)
3672 invisible (nth 1 elem)
3673 visible (nth 2 elem)
3674 face (nth 3 elem))
3675 (while (re-search-forward regexp nil t)
23f87bed
MB
3676 (when (and (match-beginning visible) (match-beginning invisible))
3677 (gnus-article-hide-text
3678 (match-beginning invisible) (match-end invisible) props)
3679 (gnus-article-unhide-text-type
3680 (match-beginning visible) (match-end visible) 'emphasis)
3681 (gnus-put-overlay-excluding-newlines
3682 (match-beginning visible) (match-end visible) 'face face)
3683 (gnus-add-wash-type 'emphasis)
3684 (goto-char (match-end invisible)))))))))
eec82323 3685
16409b0b
GM
3686(defun gnus-article-setup-highlight-words (&optional highlight-words)
3687 "Setup newsgroup emphasis alist."
3688 (unless gnus-article-emphasis-alist
3689 (let ((name (and gnus-newsgroup-name
3690 (gnus-group-real-name gnus-newsgroup-name))))
3691 (make-local-variable 'gnus-article-emphasis-alist)
a1506d29
JB
3692 (setq gnus-article-emphasis-alist
3693 (nconc
16409b0b
GM
3694 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3695 (while (setq elem (pop alist))
3696 (when (and name (string-match (car elem) name))
3697 (setq alist nil
3698 highlight (copy-sequence (cdr elem)))))
3699 highlight)
3700 (copy-sequence highlight-words)
3701 (if gnus-newsgroup-name
a1506d29 3702 (copy-sequence (gnus-group-find-parameter
16409b0b
GM
3703 gnus-newsgroup-name 'highlight-words t)))
3704 gnus-emphasis-alist)))))
3705
9efa445f
DN
3706(defvar gnus-summary-article-menu)
3707(defvar gnus-summary-post-menu)
eec82323
LMI
3708
3709;;; Saving functions.
3710
3711(defun gnus-article-save (save-buffer file &optional num)
3712 "Save the currently selected article."
26c9afc3
MB
3713 (when (or (get gnus-default-article-saver :headers)
3714 (not gnus-save-all-headers))
3715 ;; Remove headers according to `gnus-saved-headers' or the value
3716 ;; of the `:headers' property that the saver function might have.
eec82323 3717 (let ((gnus-visible-headers
26c9afc3
MB
3718 (or (symbol-value (get gnus-default-article-saver :headers))
3719 gnus-saved-headers gnus-visible-headers))
eec82323 3720 (gnus-article-buffer save-buffer))
6748645f
LMI
3721 (save-excursion
3722 (set-buffer save-buffer)
3723 (article-hide-headers 1 t))))
eec82323
LMI
3724 (save-window-excursion
3725 (if (not gnus-default-article-saver)
a8151ef7 3726 (error "No default saver is defined")
eec82323 3727 ;; !!! Magic! The saving functions all save
16409b0b 3728 ;; `gnus-save-article-buffer' (or so they think), but we
eec82323
LMI
3729 ;; bind that variable to our save-buffer.
3730 (set-buffer gnus-article-buffer)
3731 (let* ((gnus-save-article-buffer save-buffer)
3732 (filename
3733 (cond
3734 ((not gnus-prompt-before-saving) 'default)
3735 ((eq gnus-prompt-before-saving 'always) nil)
3736 (t file)))
3737 (gnus-number-of-articles-to-be-saved
3738 (when (eq gnus-prompt-before-saving t)
3739 num))) ; Magic
6748645f 3740 (set-buffer gnus-article-current-summary)
eec82323
LMI
3741 (funcall gnus-default-article-saver filename)))))
3742
3743(defun gnus-read-save-file-name (prompt &optional filename
26c9afc3
MB
3744 function group headers variable
3745 dir-var)
eec82323
LMI
3746 (let ((default-name
3747 (funcall function group headers (symbol-value variable)))
3748 result)
4325195c 3749 (setq result
a1506d29 3750 (expand-file-name
4325195c
DL
3751 (cond
3752 ((eq filename 'default)
3753 default-name)
3754 ((eq filename t)
3755 default-name)
3756 (filename filename)
3757 (t
26c9afc3
MB
3758 (when (symbol-value dir-var)
3759 (setq default-name (expand-file-name
3760 (file-name-nondirectory default-name)
3761 (symbol-value dir-var))))
4325195c
DL
3762 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3763 (prompt
3764 (format prompt
3765 (if (and gnus-number-of-articles-to-be-saved
3766 (> gnus-number-of-articles-to-be-saved 1))
3767 (format "these %d articles"
3768 gnus-number-of-articles-to-be-saved)
3769 "this article")))
3770 (file
3771 ;; Let the split methods have their say.
3772 (cond
3773 ;; No split name was found.
3774 ((null split-name)
3775 (read-file-name
3776 (concat prompt " (default "
81df110a 3777 (file-name-nondirectory default-name) "): ")
4325195c
DL
3778 (file-name-directory default-name)
3779 default-name))
3780 ;; A single group name is returned.
3781 ((stringp split-name)
3782 (setq default-name
3783 (funcall function split-name headers
3784 (symbol-value variable)))
3785 (read-file-name
3786 (concat prompt " (default "
81df110a 3787 (file-name-nondirectory default-name) "): ")
4325195c
DL
3788 (file-name-directory default-name)
3789 default-name))
3790 ;; A single split name was found
3791 ((= 1 (length split-name))
3792 (let* ((name (expand-file-name
23f87bed
MB
3793 (car split-name)
3794 gnus-article-save-directory))
4325195c
DL
3795 (dir (cond ((file-directory-p name)
3796 (file-name-as-directory name))
3797 ((file-exists-p name) name)
3798 (t gnus-article-save-directory))))
3799 (read-file-name
81df110a 3800 (concat prompt " (default " name "): ")
4325195c
DL
3801 dir name)))
3802 ;; A list of splits was found.
3803 (t
3804 (setq split-name (nreverse split-name))
3805 (let (result)
3806 (let ((file-name-history
3807 (nconc split-name file-name-history)))
3808 (setq result
3809 (expand-file-name
3810 (read-file-name
81df110a 3811 (concat prompt " (`M-p' for defaults): ")
4325195c
DL
3812 gnus-article-save-directory
3813 (car split-name))
3814 gnus-article-save-directory)))
3815 (car (push result file-name-history)))))))
3816 ;; Create the directory.
3817 (gnus-make-directory (file-name-directory file))
23f87bed 3818 ;; If we have read a directory, we append the default file name.
4325195c 3819 (when (file-directory-p file)
23f87bed
MB
3820 (setq file (expand-file-name (file-name-nondirectory
3821 default-name)
4325195c
DL
3822 (file-name-as-directory file))))
3823 ;; Possibly translate some characters.
3824 (nnheader-translate-file-chars file))))))
eec82323 3825 (gnus-make-directory (file-name-directory result))
26c9afc3
MB
3826 (when variable
3827 (set variable result))
3828 (when dir-var
3829 (set dir-var (file-name-directory result)))
3830 result))
eec82323
LMI
3831
3832(defun gnus-article-archive-name (group)
3833 "Return the first instance of an \"Archive-name\" in the current buffer."
3834 (let ((case-fold-search t))
3835 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3836 (nnheader-concat gnus-article-save-directory
3837 (match-string 1)))))
3838
3839(defun gnus-article-nndoc-name (group)
3840 "If GROUP is an nndoc group, return the name of the parent group."
3841 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3842 (gnus-group-get-parameter group 'save-article-group)))
3843
3844(defun gnus-summary-save-in-rmail (&optional filename)
3845 "Append this article to Rmail file.
3846Optional argument FILENAME specifies file name.
3847Directory to save to is default to `gnus-article-save-directory'."
eec82323 3848 (setq filename (gnus-read-save-file-name
81df110a 3849 "Save %s in rmail file" filename
eec82323
LMI
3850 gnus-rmail-save-name gnus-newsgroup-name
3851 gnus-current-headers 'gnus-newsgroup-last-rmail))
3852 (gnus-eval-in-buffer-window gnus-save-article-buffer
3853 (save-excursion
3854 (save-restriction
3855 (widen)
6748645f
LMI
3856 (gnus-output-to-rmail filename))))
3857 filename)
eec82323
LMI
3858
3859(defun gnus-summary-save-in-mail (&optional filename)
3860 "Append this article to Unix mail file.
3861Optional argument FILENAME specifies file name.
3862Directory to save to is default to `gnus-article-save-directory'."
eec82323 3863 (setq filename (gnus-read-save-file-name
81df110a 3864 "Save %s in Unix mail file" filename
eec82323
LMI
3865 gnus-mail-save-name gnus-newsgroup-name
3866 gnus-current-headers 'gnus-newsgroup-last-mail))
3867 (gnus-eval-in-buffer-window gnus-save-article-buffer
3868 (save-excursion
3869 (save-restriction
3870 (widen)
3871 (if (and (file-readable-p filename)
23f87bed 3872 (file-regular-p filename)
eec82323 3873 (mail-file-babyl-p filename))
16409b0b 3874 (rmail-output-to-rmail-file filename t)
6748645f
LMI
3875 (gnus-output-to-mail filename)))))
3876 filename)
eec82323 3877
26c9afc3
MB
3878(put 'gnus-summary-save-in-file :decode t)
3879(put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
eec82323
LMI
3880(defun gnus-summary-save-in-file (&optional filename overwrite)
3881 "Append this article to file.
3882Optional argument FILENAME specifies file name.
3883Directory to save to is default to `gnus-article-save-directory'."
eec82323 3884 (setq filename (gnus-read-save-file-name
81df110a 3885 "Save %s in file" filename
eec82323
LMI
3886 gnus-file-save-name gnus-newsgroup-name
3887 gnus-current-headers 'gnus-newsgroup-last-file))
3888 (gnus-eval-in-buffer-window gnus-save-article-buffer
3889 (save-excursion
3890 (save-restriction
3891 (widen)
3892 (when (and overwrite
3893 (file-exists-p filename))
3894 (delete-file filename))
6748645f
LMI
3895 (gnus-output-to-file filename))))
3896 filename)
eec82323 3897
26c9afc3
MB
3898(put 'gnus-summary-write-to-file :decode t)
3899(put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3900(put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
eec82323 3901(defun gnus-summary-write-to-file (&optional filename)
23f87bed 3902 "Write this article to a file, overwriting it if the file exists.
eec82323
LMI
3903Optional argument FILENAME specifies file name.
3904The directory to save in defaults to `gnus-article-save-directory'."
26c9afc3
MB
3905 (setq filename (gnus-read-save-file-name
3906 "Save %s in file" filename
3907 gnus-file-save-name gnus-newsgroup-name
3908 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3909 (gnus-summary-save-in-file filename t))
eec82323 3910
26c9afc3
MB
3911(put 'gnus-summary-save-body-in-file :decode t)
3912(defun gnus-summary-save-body-in-file (&optional filename overwrite)
eec82323
LMI
3913 "Append this article body to a file.
3914Optional argument FILENAME specifies file name.
3915The directory to save in defaults to `gnus-article-save-directory'."
eec82323 3916 (setq filename (gnus-read-save-file-name
81df110a 3917 "Save %s body in file" filename
eec82323
LMI
3918 gnus-file-save-name gnus-newsgroup-name
3919 gnus-current-headers 'gnus-newsgroup-last-file))
3920 (gnus-eval-in-buffer-window gnus-save-article-buffer
3921 (save-excursion
3922 (save-restriction
3923 (widen)
16409b0b 3924 (when (article-goto-body)
eec82323 3925 (narrow-to-region (point) (point-max)))
26c9afc3
MB
3926 (when (and overwrite
3927 (file-exists-p filename))
3928 (delete-file filename))
6748645f
LMI
3929 (gnus-output-to-file filename))))
3930 filename)
eec82323 3931
26c9afc3
MB
3932(put 'gnus-summary-write-body-to-file :decode t)
3933(put 'gnus-summary-write-body-to-file
3934 :function 'gnus-summary-save-body-in-file)
3935(defun gnus-summary-write-body-to-file (&optional filename)
3936 "Write this article body to a file, overwriting it if the file exists.
3937Optional argument FILENAME specifies file name.
3938The directory to save in defaults to `gnus-article-save-directory'."
3939 (setq filename (gnus-read-save-file-name
3940 "Save %s body in file" filename
3941 gnus-file-save-name gnus-newsgroup-name
3942 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3943 (gnus-summary-save-body-in-file filename t))
3944
eec82323
LMI
3945(defun gnus-summary-save-in-pipe (&optional command)
3946 "Pipe this article to subprocess."
eec82323 3947 (setq command
16409b0b
GM
3948 (cond ((and (eq command 'default)
3949 gnus-last-shell-command)
eec82323 3950 gnus-last-shell-command)
676a7cc9
SZ
3951 ((stringp command)
3952 command)
eec82323
LMI
3953 (t (read-string
3954 (format
3955 "Shell command on %s: "
3956 (if (and gnus-number-of-articles-to-be-saved
3957 (> gnus-number-of-articles-to-be-saved 1))
3958 (format "these %d articles"
3959 gnus-number-of-articles-to-be-saved)
3960 "this article"))
3961 gnus-last-shell-command))))
3962 (when (string-equal command "")
676a7cc9
SZ
3963 (if gnus-last-shell-command
3964 (setq command gnus-last-shell-command)
715a2ca2 3965 (error "A command is required")))
eec82323
LMI
3966 (gnus-eval-in-buffer-window gnus-article-buffer
3967 (save-restriction
3968 (widen)
3969 (shell-command-on-region (point-min) (point-max) command nil)))
3970 (setq gnus-last-shell-command command))
3971
23f87bed
MB
3972(defun gnus-summary-pipe-to-muttprint (&optional command)
3973 "Pipe this article to muttprint."
01c52d31 3974 (setq command (read-string
23f87bed
MB
3975 "Print using command: " gnus-summary-muttprint-program
3976 nil gnus-summary-muttprint-program))
3977 (gnus-summary-save-in-pipe command))
3978
eec82323
LMI
3979;;; Article file names when saving.
3980
3981(defun gnus-capitalize-newsgroup (newsgroup)
3982 "Capitalize NEWSGROUP name."
3983 (when (not (zerop (length newsgroup)))
3984 (concat (char-to-string (upcase (aref newsgroup 0)))
3985 (substring newsgroup 1))))
3986
3987(defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3988 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3989If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3990Otherwise, it is like ~/News/news/group/num."
3991 (let ((default
3992 (expand-file-name
3993 (concat (if (gnus-use-long-file-name 'not-save)
3994 (gnus-capitalize-newsgroup newsgroup)
3995 (gnus-newsgroup-directory-form newsgroup))
3996 "/" (int-to-string (mail-header-number headers)))
3997 gnus-article-save-directory)))
3998 (if (and last-file
3999 (string-equal (file-name-directory default)
4000 (file-name-directory last-file))
4001 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4002 default
4003 (or last-file default))))
4004
4005(defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4006 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4007If variable `gnus-use-long-file-name' is non-nil, it is
2ff9f5b4 4008~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
eec82323
LMI
4009 (let ((default
4010 (expand-file-name
4011 (concat (if (gnus-use-long-file-name 'not-save)
4012 newsgroup
4013 (gnus-newsgroup-directory-form newsgroup))
4014 "/" (int-to-string (mail-header-number headers)))
4015 gnus-article-save-directory)))
4016 (if (and last-file
4017 (string-equal (file-name-directory default)
4018 (file-name-directory last-file))
4019 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4020 default
4021 (or last-file default))))
4022
eec82323
LMI
4023(defun gnus-plain-save-name (newsgroup headers &optional last-file)
4024 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4025If variable `gnus-use-long-file-name' is non-nil, it is
4026~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4027 (or last-file
4028 (expand-file-name
4029 (if (gnus-use-long-file-name 'not-save)
4030 newsgroup
23f87bed
MB
4031 (file-relative-name
4032 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4033 default-directory))
eec82323
LMI
4034 gnus-article-save-directory)))
4035
23f87bed
MB
4036(defun gnus-sender-save-name (newsgroup headers &optional last-file)
4037 "Generate file name from sender."
4038 (let ((from (mail-header-from headers)))
4039 (expand-file-name
4040 (if (and from (string-match "\\([^ <]+\\)@" from))
4041 (match-string 1 from)
4042 "nobody")
4043 gnus-article-save-directory)))
4044
4045(defun article-verify-x-pgp-sig ()
4046 "Verify X-PGP-Sig."
bbbe940b 4047 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
23f87bed
MB
4048 (interactive)
4049 (if (gnus-buffer-live-p gnus-original-article-buffer)
4050 (let ((sig (with-current-buffer gnus-original-article-buffer
4051 (gnus-fetch-field "X-PGP-Sig")))
4052 items info headers)
4053 (when (and sig
4054 mml2015-use
4055 (mml2015-clear-verify-function))
4056 (with-temp-buffer
4057 (insert-buffer-substring gnus-original-article-buffer)
4058 (setq items (split-string sig))
4059 (message-narrow-to-head)
4060 (let ((inhibit-point-motion-hooks t)
4061 (case-fold-search t))
4062 ;; Don't verify multiple headers.
4063 (setq headers (mapconcat (lambda (header)
4064 (concat header ": "
4065 (mail-fetch-field header)
4066 "\n"))
4067 (split-string (nth 1 items) ",") "")))
4068 (delete-region (point-min) (point-max))
4069 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4070 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4071 (insert headers)
4072 (widen)
4073 (forward-line)
4074 (while (not (eobp))
4075 (if (looking-at "^-")
4076 (insert "- "))
4077 (forward-line))
4078 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4079 (insert "Version: " (car items) "\n\n")
4080 (insert (mapconcat 'identity (cddr items) "\n"))
4081 (insert "\n-----END PGP SIGNATURE-----\n")
4082 (let ((mm-security-handle (list (format "multipart/signed"))))
4083 (mml2015-clean-buffer)
4084 (let ((coding-system-for-write (or gnus-newsgroup-charset
4085 'iso-8859-1)))
4086 (funcall (mml2015-clear-verify-function)))
4087 (setq info
4088 (or (mm-handle-multipart-ctl-parameter
4089 mm-security-handle 'gnus-details)
4090 (mm-handle-multipart-ctl-parameter
4091 mm-security-handle 'gnus-info)))))
4092 (when info
4093 (let ((inhibit-read-only t) bface eface)
4094 (save-restriction
4095 (message-narrow-to-head)
4096 (goto-char (point-max))
4097 (forward-line -1)
01c52d31
MB
4098 (setq bface (get-text-property (point-at-bol) 'face)
4099 eface (get-text-property (1- (point-at-eol)) 'face))
23f87bed
MB
4100 (message-remove-header "X-Gnus-PGP-Verify")
4101 (if (re-search-forward "^X-PGP-Sig:" nil t)
4102 (forward-line)
4103 (goto-char (point-max)))
4104 (narrow-to-region (point) (point))
4105 (insert "X-Gnus-PGP-Verify: " info "\n")
4106 (goto-char (point-min))
4107 (forward-line)
4108 (while (not (eobp))
4109 (if (not (looking-at "^[ \t]"))
4110 (insert " "))
4111 (forward-line))
4112 ;; Do highlighting.
4113 (goto-char (point-min))
4114 (when (looking-at "\\([^:]+\\): *")
4115 (put-text-property (match-beginning 1) (1+ (match-end 1))
4116 'face bface)
4117 (put-text-property (match-end 0) (point-max)
4118 'face eface)))))))))
4119
4120(defun article-verify-cancel-lock ()
4121 "Verify Cancel-Lock header."
4122 (interactive)
4123 (if (gnus-buffer-live-p gnus-original-article-buffer)
4124 (canlock-verify gnus-original-article-buffer)))
4125
eec82323 4126(eval-and-compile
01c52d31 4127 (mapc
eec82323
LMI
4128 (lambda (func)
4129 (let (afunc gfunc)
4130 (if (consp func)
4131 (setq afunc (car func)
4132 gfunc (cdr func))
4133 (setq afunc func
4134 gfunc (intern (format "gnus-%s" func))))
16409b0b 4135 (defalias gfunc
23f87bed 4136 (when (fboundp afunc)
16409b0b
GM
4137 `(lambda (&optional interactive &rest args)
4138 ,(documentation afunc t)
4139 (interactive (list t))
4140 (save-excursion
4141 (set-buffer gnus-article-buffer)
4142 (if interactive
4143 (call-interactively ',afunc)
4144 (apply ',afunc args))))))))
eec82323 4145 '(article-hide-headers
23f87bed
MB
4146 article-verify-x-pgp-sig
4147 article-verify-cancel-lock
eec82323
LMI
4148 article-hide-boring-headers
4149 article-treat-overstrike
01c52d31 4150 article-treat-ansi-sequences
16409b0b
GM
4151 article-fill-long-lines
4152 article-capitalize-sentences
eec82323 4153 article-remove-cr
23f87bed 4154 article-remove-leading-whitespace
eec82323 4155 article-display-x-face
23f87bed 4156 article-display-face
eec82323 4157 article-de-quoted-unreadable
16409b0b
GM
4158 article-de-base64-unreadable
4159 article-decode-HZ
4160 article-wash-html
23f87bed 4161 article-unsplit-urls
16409b0b 4162 article-hide-list-identifiers
16409b0b
GM
4163 article-strip-banner
4164 article-babel
eec82323
LMI
4165 article-hide-pem
4166 article-hide-signature
16409b0b 4167 article-strip-headers-in-body
eec82323
LMI
4168 article-remove-trailing-blank-lines
4169 article-strip-leading-blank-lines
4170 article-strip-multiple-blank-lines
4171 article-strip-leading-space
16409b0b 4172 article-strip-trailing-space
eec82323 4173 article-strip-blank-lines
6748645f 4174 article-strip-all-blank-lines
eec82323 4175 article-date-local
23f87bed 4176 article-date-english
6748645f 4177 article-date-iso8601
eec82323
LMI
4178 article-date-original
4179 article-date-ut
16409b0b
GM
4180 article-decode-mime-words
4181 article-decode-charset
4182 article-decode-encoded-words
eec82323
LMI
4183 article-date-user
4184 article-date-lapsed
4185 article-emphasize
6748645f 4186 article-treat-dumbquotes
16409b0b 4187 article-normalize-headers
01c52d31 4188 ;;(article-show-all . gnus-article-show-all-headers)
23f87bed 4189 )))
eec82323
LMI
4190\f
4191;;;
4192;;; Gnus article mode
4193;;;
4194
4195(put 'gnus-article-mode 'mode-class 'special)
4196
16409b0b
GM
4197(set-keymap-parent gnus-article-mode-map widget-keymap)
4198
a8151ef7
LMI
4199(gnus-define-keys gnus-article-mode-map
4200 " " gnus-article-goto-next-page
4201 "\177" gnus-article-goto-prev-page
4202 [delete] gnus-article-goto-prev-page
16409b0b 4203 [backspace] gnus-article-goto-prev-page
a8151ef7
LMI
4204 "\C-c^" gnus-article-refer-article
4205 "h" gnus-article-show-summary
4206 "s" gnus-article-show-summary
4207 "\C-c\C-m" gnus-article-mail
4208 "?" gnus-article-describe-briefly
16409b0b 4209 "e" gnus-summary-edit-article
a8151ef7
LMI
4210 "<" beginning-of-buffer
4211 ">" end-of-buffer
4212 "\C-c\C-i" gnus-info-find-node
4213 "\C-c\C-b" gnus-bug
23f87bed
MB
4214 "R" gnus-article-reply-with-original
4215 "F" gnus-article-followup-with-original
520aa572
SZ
4216 "\C-hk" gnus-article-describe-key
4217 "\C-hc" gnus-article-describe-key-briefly
a8151ef7
LMI
4218
4219 "\C-d" gnus-article-read-summary-keys
4220 "\M-*" gnus-article-read-summary-keys
4221 "\M-#" gnus-article-read-summary-keys
4222 "\M-^" gnus-article-read-summary-keys
4223 "\M-g" gnus-article-read-summary-keys)
4224
4225(substitute-key-definition
4226 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
eec82323 4227
95838435
MB
4228(gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4229 "W" gnus-article-wide-reply-with-original)
4230(if (featurep 'xemacs)
4231 (set-keymap-default-binding gnus-article-send-map
4232 'gnus-article-read-summary-send-keys)
4233 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4234
eec82323 4235(defun gnus-article-make-menu-bar ()
23f87bed
MB
4236 (unless (boundp 'gnus-article-commands-menu)
4237 (gnus-summary-make-menu-bar))
eec82323
LMI
4238 (gnus-turn-off-edit-menu 'article)
4239 (unless (boundp 'gnus-article-article-menu)
4240 (easy-menu-define
4241 gnus-article-article-menu gnus-article-mode-map ""
4242 '("Article"
4243 ["Scroll forwards" gnus-article-goto-next-page t]
4244 ["Scroll backwards" gnus-article-goto-prev-page t]
4245 ["Show summary" gnus-article-show-summary t]
4246 ["Fetch Message-ID at point" gnus-article-refer-article t]
6748645f
LMI
4247 ["Mail to address at point" gnus-article-mail t]
4248 ["Send a bug report" gnus-bug t]))
eec82323
LMI
4249
4250 (easy-menu-define
4251 gnus-article-treatment-menu gnus-article-mode-map ""
bb367cba 4252 ;; Fixme: this should use :active (and maybe :visible).
eec82323
LMI
4253 '("Treatment"
4254 ["Hide headers" gnus-article-hide-headers t]
4255 ["Hide signature" gnus-article-hide-signature t]
4256 ["Hide citation" gnus-article-hide-citation t]
4257 ["Treat overstrike" gnus-article-treat-overstrike t]
01c52d31 4258 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
eec82323 4259 ["Remove carriage return" gnus-article-remove-cr t]
23f87bed 4260 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
16409b0b
GM
4261 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4262 ["Remove base64" gnus-article-de-base64-unreadable t]
4263 ["Treat html" gnus-article-wash-html t]
23f87bed 4264 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
16409b0b 4265 ["Decode HZ" gnus-article-decode-HZ t]))
eec82323 4266
6748645f 4267 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
eec82323 4268
23f87bed 4269 ;; Note "Post" menu is defined in gnus-sum.el for consistency
eec82323 4270
6748645f 4271 (gnus-run-hooks 'gnus-article-menu-hook)))
eec82323
LMI
4272
4273(defun gnus-article-mode ()
4274 "Major mode for displaying an article.
4275
4276All normal editing commands are switched off.
4277
4278The following commands are available in addition to all summary mode
4279commands:
4280\\<gnus-article-mode-map>
4281\\[gnus-article-next-page]\t Scroll the article one page forwards
4282\\[gnus-article-prev-page]\t Scroll the article one page backwards
4283\\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4284\\[gnus-article-show-summary]\t Display the summary buffer
4285\\[gnus-article-mail]\t Send a reply to the address near point
4286\\[gnus-article-describe-briefly]\t Describe the current mode briefly
4287\\[gnus-info-find-node]\t Go to the Gnus info node"
4288 (interactive)
0eb586fc 4289 (kill-all-local-variables)
eec82323
LMI
4290 (gnus-simplify-mode-line)
4291 (setq mode-name "Article")
4292 (setq major-mode 'gnus-article-mode)
4293 (make-local-variable 'minor-mode-alist)
eec82323 4294 (use-local-map gnus-article-mode-map)
1653df0f 4295 (when (gnus-visual-p 'article-menu 'menu)
23f87bed
MB
4296 (gnus-article-make-menu-bar)
4297 (when gnus-summary-tool-bar-map
4298 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
eec82323
LMI
4299 (gnus-update-format-specifications nil 'article-mode)
4300 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
23f87bed 4301 (set (make-local-variable 'gnus-page-broken) nil)
6748645f
LMI
4302 (make-local-variable 'gnus-button-marker-list)
4303 (make-local-variable 'gnus-article-current-summary)
16409b0b
GM
4304 (make-local-variable 'gnus-article-mime-handles)
4305 (make-local-variable 'gnus-article-decoded-p)
4306 (make-local-variable 'gnus-article-mime-handle-alist)
4307 (make-local-variable 'gnus-article-wash-types)
23f87bed
MB
4308 (make-local-variable 'gnus-article-image-alist)
4309 (make-local-variable 'gnus-article-charset)
4310 (make-local-variable 'gnus-article-ignored-charsets)
524705ae
MB
4311 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4312 ;; face.
fc1c32c1 4313 (set (make-local-variable 'nobreak-char-display) nil)
e4a89ccf 4314 (setq cursor-in-non-selected-windows nil)
01c52d31 4315 (setq truncate-lines gnus-article-truncate-lines)
eec82323 4316 (gnus-set-default-directory)
16409b0b 4317 (buffer-disable-undo)
01c52d31
MB
4318 (setq buffer-read-only t
4319 show-trailing-whitespace nil)
eec82323 4320 (set-syntax-table gnus-article-mode-syntax-table)
16409b0b 4321 (mm-enable-multibyte)
cfcd5c91 4322 (gnus-run-mode-hooks 'gnus-article-mode-hook))
eec82323 4323
676c1893 4324(defvar gnus-button-marker-list nil
01c52d31
MB
4325 "Regexp matching any of the regexps from `gnus-button-alist'.
4326Internal variable.")
676c1893 4327
eec82323
LMI
4328(defun gnus-article-setup-buffer ()
4329 "Initialize the article buffer."
4330 (let* ((name (if gnus-single-article-buffer "*Article*"
4331 (concat "*Article " gnus-newsgroup-name "*")))
4332 (original
4333 (progn (string-match "\\*Article" name)
4334 (concat " *Original Article"
4335 (substring name (match-end 0))))))
4336 (setq gnus-article-buffer name)
4337 (setq gnus-original-article-buffer original)
16409b0b 4338 (setq gnus-article-mime-handle-alist nil)
01c52d31
MB
4339 (with-current-buffer gnus-summary-buffer
4340 ;; This might be a variable local to the summary buffer.
4341 (unless gnus-single-article-buffer
eec82323
LMI
4342 (setq gnus-article-buffer name)
4343 (setq gnus-original-article-buffer original)
4344 (gnus-set-global-variables)))
16409b0b 4345 (gnus-article-setup-highlight-words)
eec82323
LMI
4346 ;; Init original article buffer.
4347 (save-excursion
6748645f 4348 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 4349 (mm-enable-multibyte)
eec82323 4350 (setq major-mode 'gnus-original-article-mode)
eec82323 4351 (make-local-variable 'gnus-original-article))
aba1948a
MB
4352 (if (and (get-buffer name)
4353 (with-current-buffer name
4354 (if gnus-article-edit-mode
4355 (if (y-or-n-p "Article mode edit in progress; discard? ")
4356 (progn
4357 (set-buffer-modified-p nil)
4358 (gnus-kill-buffer name)
4359 (message "")
4360 nil)
4361 (error "Action aborted"))
4362 t)))
eec82323
LMI
4363 (save-excursion
4364 (set-buffer name)
23f87bed 4365 (set (make-local-variable 'gnus-article-edit-mode) nil)
16409b0b
GM
4366 (when gnus-article-mime-handles
4367 (mm-destroy-parts gnus-article-mime-handles)
4368 (setq gnus-article-mime-handles nil))
4369 ;; Set it to nil in article-buffer!
a1506d29 4370 (setq gnus-article-mime-handle-alist nil)
16409b0b 4371 (buffer-disable-undo)
eec82323 4372 (setq buffer-read-only t)
23f87bed
MB
4373 ;; This list just keeps growing if we don't reset it.
4374 (setq gnus-button-marker-list nil)
eec82323
LMI
4375 (unless (eq major-mode 'gnus-article-mode)
4376 (gnus-article-mode))
4377 (current-buffer))
4378 (save-excursion
6748645f 4379 (set-buffer (gnus-get-buffer-create name))
eec82323
LMI
4380 (gnus-article-mode)
4381 (make-local-variable 'gnus-summary-buffer)
01c52d31
MB
4382 (setq gnus-summary-buffer
4383 (gnus-summary-buffer-name gnus-newsgroup-name))
16409b0b 4384 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
4385 (current-buffer)))))
4386
4387;; Set article window start at LINE, where LINE is the number of lines
4388;; from the head of the article.
4389(defun gnus-article-set-window-start (&optional line)
01c52d31
MB
4390 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4391 (when article-window
4392 (set-window-start
4393 article-window
4394 (save-excursion
4395 (set-buffer gnus-article-buffer)
4396 (goto-char (point-min))
4397 (if (not line)
4398 (point-min)
4399 (gnus-message 6 "Moved to bookmark")
4400 (search-forward "\n\n" nil t)
4401 (forward-line line)
4402 (point)))))))
eec82323
LMI
4403
4404(defun gnus-article-prepare (article &optional all-headers header)
4405 "Prepare ARTICLE in article mode buffer.
4406ARTICLE should either be an article number or a Message-ID.
4407If ARTICLE is an id, HEADER should be the article headers.
4408If ALL-HEADERS is non-nil, no headers are hidden."
4409 (save-excursion
4410 ;; Make sure we start in a summary buffer.
4411 (unless (eq major-mode 'gnus-summary-mode)
4412 (set-buffer gnus-summary-buffer))
4413 (setq gnus-summary-buffer (current-buffer))
eec82323
LMI
4414 (let* ((gnus-article (if header (mail-header-number header) article))
4415 (summary-buffer (current-buffer))
6748645f 4416 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
eec82323
LMI
4417 (group gnus-newsgroup-name)
4418 result)
4419 (save-excursion
4420 (gnus-article-setup-buffer)
4421 (set-buffer gnus-article-buffer)
4422 ;; Deactivate active regions.
4423 (when (and (boundp 'transient-mark-mode)
4424 transient-mark-mode)
4425 (setq mark-active nil))
4e7d0221 4426 (if (not (setq result (let ((inhibit-read-only t))
eec82323
LMI
4427 (gnus-request-article-this-buffer
4428 article group))))
4429 ;; There is no such article.
4430 (save-excursion
4431 (when (and (numberp article)
4432 (not (memq article gnus-newsgroup-sparse)))
4433 (setq gnus-article-current
4434 (cons gnus-newsgroup-name article))
4435 (set-buffer gnus-summary-buffer)
4436 (setq gnus-current-article article)
23f87bed
MB
4437 (if (and (memq article gnus-newsgroup-undownloaded)
4438 (not (gnus-online (gnus-find-method-for-group
4439 gnus-newsgroup-name))))
6748645f
LMI
4440 (progn
4441 (gnus-summary-set-agent-mark article)
4442 (message "Message marked for downloading"))
4443 (gnus-summary-mark-article article gnus-canceled-mark)
4444 (unless (memq article gnus-newsgroup-sparse)
16409b0b 4445 (gnus-error 1 "No such article (may have expired or been canceled)")))))
6748645f
LMI
4446 (if (or (eq result 'pseudo)
4447 (eq result 'nneething))
eec82323
LMI
4448 (progn
4449 (save-excursion
4450 (set-buffer summary-buffer)
6748645f 4451 (push article gnus-newsgroup-history)
eec82323 4452 (setq gnus-last-article gnus-current-article
eec82323
LMI
4453 gnus-current-article 0
4454 gnus-current-headers nil
4455 gnus-article-current nil)
4456 (if (eq result 'nneething)
4457 (gnus-configure-windows 'summary)
4458 (gnus-configure-windows 'article))
4459 (gnus-set-global-variables))
16409b0b
GM
4460 (let ((gnus-article-mime-handle-alist-1
4461 gnus-article-mime-handle-alist))
4462 (gnus-set-mode-line 'article)))
eec82323
LMI
4463 ;; The result from the `request' was an actual article -
4464 ;; or at least some text that is now displayed in the
4465 ;; article buffer.
4466 (when (and (numberp article)
4467 (not (eq article gnus-current-article)))
4468 ;; Seems like a new article has been selected.
4469 ;; `gnus-current-article' must be an article number.
4470 (save-excursion
4471 (set-buffer summary-buffer)
6748645f 4472 (push article gnus-newsgroup-history)
eec82323 4473 (setq gnus-last-article gnus-current-article
eec82323
LMI
4474 gnus-current-article article
4475 gnus-current-headers
4476 (gnus-summary-article-header gnus-current-article)
4477 gnus-article-current
4478 (cons gnus-newsgroup-name gnus-current-article))
4479 (unless (vectorp gnus-current-headers)
4480 (setq gnus-current-headers nil))
6748645f
LMI
4481 (gnus-summary-goto-subject gnus-current-article)
4482 (when (gnus-summary-show-thread)
4483 ;; If the summary buffer really was folded, the
4484 ;; previous goto may not actually have gone to
4485 ;; the right article, but the thread root instead.
4486 ;; So we go again.
4487 (gnus-summary-goto-subject gnus-current-article))
4488 (gnus-run-hooks 'gnus-mark-article-hook)
eec82323
LMI
4489 (gnus-set-mode-line 'summary)
4490 (when (gnus-visual-p 'article-highlight 'highlight)
6748645f 4491 (gnus-run-hooks 'gnus-visual-mark-article-hook))
eec82323 4492 ;; Set the global newsgroup variables here.
eec82323
LMI
4493 (gnus-set-global-variables)
4494 (setq gnus-have-all-headers
6748645f 4495 (or all-headers gnus-show-all-headers))))
e0bad764
DL
4496 (save-excursion
4497 (gnus-configure-windows 'article))
eec82323
LMI
4498 (when (or (numberp article)
4499 (stringp article))
16409b0b 4500 (gnus-article-prepare-display)
eec82323
LMI
4501 ;; Do page break.
4502 (goto-char (point-min))
23f87bed
MB
4503 (when gnus-break-pages
4504 (gnus-narrow-to-page)))
16409b0b
GM
4505 (let ((gnus-article-mime-handle-alist-1
4506 gnus-article-mime-handle-alist))
4507 (gnus-set-mode-line 'article))
4508 (article-goto-body)
23f87bed
MB
4509 (unless (bobp)
4510 (forward-line -1))
6748645f 4511 (set-window-point (get-buffer-window (current-buffer)) (point))
16409b0b 4512 (gnus-configure-windows 'article)
eec82323
LMI
4513 t))))))
4514
16409b0b
GM
4515;;;###autoload
4516(defun gnus-article-prepare-display ()
4517 "Make the current buffer look like a nice article."
4518 ;; Hooks for getting information from the article.
4519 ;; This hook must be called before being narrowed.
4520 (let ((gnus-article-buffer (current-buffer))
23f87bed
MB
4521 buffer-read-only
4522 (inhibit-read-only t))
16409b0b
GM
4523 (unless (eq major-mode 'gnus-article-mode)
4524 (gnus-article-mode))
4525 (setq buffer-read-only nil
23f87bed
MB
4526 gnus-article-wash-types nil
4527 gnus-article-image-alist nil)
16409b0b
GM
4528 (gnus-run-hooks 'gnus-tmp-internal-hook)
4529 (when gnus-display-mime-function
4530 (funcall gnus-display-mime-function))
4531 (gnus-run-hooks 'gnus-article-prepare-hook)))
4532
01c52d31
MB
4533;;;
4534;;; Gnus Sticky Article Mode
4535;;;
4536
4537(define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4538 "Mode for sticky articles."
4539 ;; Release bindings that won't work.
4540 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4541 gnus-sticky-article-mode-map)
4542 (substitute-key-definition 'gnus-article-refer-article 'undefined
4543 gnus-sticky-article-mode-map)
4544 (dolist (k '("e" "h" "s" "F" "R"))
4545 (define-key gnus-sticky-article-mode-map k nil))
4546 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4547 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4548 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4549 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4550
4551(defun gnus-sticky-article (arg)
4552 "Make the current article sticky.
4553If a prefix ARG is given, ask for a name for this sticky article buffer."
4554 (interactive "P")
4555 (gnus-summary-show-thread)
4556 (gnus-summary-select-article nil nil 'pseudo)
4557 (let (new-art-buf-name)
4558 (gnus-eval-in-buffer-window gnus-article-buffer
4559 (setq new-art-buf-name
4560 (concat
4561 "*Sticky Article: "
4562 (if arg
4563 (read-from-minibuffer "Sticky article buffer name: ")
4564 (gnus-with-article-headers
4565 (gnus-article-goto-header "subject")
4566 (setq new-art-buf-name
4567 (buffer-substring-no-properties
4568 (line-beginning-position) (line-end-position)))
4569 (goto-char (point-min))
4570 (gnus-article-goto-header "from")
4571 (setq new-art-buf-name
4572 (concat
4573 new-art-buf-name ", "
4574 (buffer-substring-no-properties
4575 (line-beginning-position) (line-end-position))))
4576 (goto-char (point-min))
4577 (gnus-article-goto-header "date")
4578 (setq new-art-buf-name
4579 (concat
4580 new-art-buf-name ", "
4581 (buffer-substring-no-properties
4582 (line-beginning-position) (line-end-position))))))
4583 "*"))
4584 (if (and (gnus-buffer-live-p new-art-buf-name)
4585 (with-current-buffer new-art-buf-name
4586 (eq major-mode 'gnus-sticky-article-mode)))
4587 (switch-to-buffer new-art-buf-name)
4588 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4589 (gnus-sticky-article-mode))
4590 (setq gnus-article-buffer new-art-buf-name))
4591 (gnus-summary-recenter)
4592 (gnus-summary-position-point))
4593
4594(defun gnus-kill-sticky-article-buffer (&optional buffer)
4595 "Kill the given sticky article BUFFER.
4596If none is given, assume the current buffer and kill it if it has
4597`gnus-sticky-article-mode'."
4598 (interactive)
4599 (unless buffer
4600 (setq buffer (current-buffer)))
4601 (with-current-buffer buffer
4602 (when (eq major-mode 'gnus-sticky-article-mode)
4603 (gnus-kill-buffer buffer))))
4604
4605(defun gnus-kill-sticky-article-buffers (arg)
4606 "Kill all sticky article buffers.
4607If a prefix ARG is given, ask for confirmation."
4608 (interactive "P")
4609 (dolist (buf (gnus-buffers))
4610 (with-current-buffer buf
4611 (when (eq major-mode 'gnus-sticky-article-mode)
4612 (if (not arg)
4613 (gnus-kill-buffer buf)
4614 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4615 (gnus-kill-buffer buf)))))))
4616
16409b0b
GM
4617;;;
4618;;; Gnus MIME viewing functions
4619;;;
4620
4621(defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
23f87bed
MB
4622 "Format of the MIME buttons.
4623
4624Valid specifiers include:
16409b0b
GM
4625%t The MIME type
4626%T MIME type, along with additional info
4627%n The `name' parameter
4628%d The description, if any
4629%l The length of the encoded part
4630%p The part identifier number
23f87bed
MB
4631%e Dots if the part isn't displayed
4632
4633General format specifiers can also be used. See Info node
4634`(gnus)Formatting Variables'.")
16409b0b
GM
4635
4636(defvar gnus-mime-button-line-format-alist
4637 '((?t gnus-tmp-type ?s)
4638 (?T gnus-tmp-type-long ?s)
4639 (?n gnus-tmp-name ?s)
4640 (?d gnus-tmp-description ?s)
4641 (?p gnus-tmp-id ?s)
4642 (?l gnus-tmp-length ?d)
4643 (?e gnus-tmp-dots ?s)))
4644
4645(defvar gnus-mime-button-commands
4646 '((gnus-article-press-button "\r" "Toggle Display")
4647 (gnus-mime-view-part "v" "View Interactively...")
4648 (gnus-mime-view-part-as-type "t" "View As Type...")
23f87bed 4649 (gnus-mime-view-part-as-charset "C" "View As charset...")
16409b0b 4650 (gnus-mime-save-part "o" "Save...")
23f87bed 4651 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
01c52d31 4652 (gnus-mime-replace-part "r" "Replace part")
23f87bed 4653 (gnus-mime-delete-part "d" "Delete part")
16409b0b
GM
4654 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4655 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
01c52d31 4656 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
23f87bed
MB
4657 (gnus-mime-view-part-externally "e" "View Externally")
4658 (gnus-mime-print-part "p" "Print")
e0bad764 4659 (gnus-mime-pipe-part "|" "Pipe To Command...")
23f87bed 4660 (gnus-mime-action-on-part "." "Take action on the part...")))
16409b0b
GM
4661
4662(defun gnus-article-mime-part-status ()
4663 (if gnus-article-mime-handle-alist-1
23f87bed
MB
4664 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4665 " (1 part)"
4666 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
16409b0b
GM
4667 ""))
4668
4669(defvar gnus-mime-button-map
4670 (let ((map (make-sparse-keymap)))
16409b0b
GM
4671 (define-key map gnus-mouse-2 'gnus-article-push-button)
4672 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4673 (dolist (c gnus-mime-button-commands)
4674 (define-key map (cadr c) (car c)))
4675 map))
4676
23f87bed
MB
4677(easy-menu-define
4678 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4679 `("MIME Part"
4680 ,@(mapcar (lambda (c)
01c52d31 4681 (vector (caddr c) (car c) :active t))
23f87bed
MB
4682 gnus-mime-button-commands)))
4683
23f87bed
MB
4684(defun gnus-mime-button-menu (event prefix)
4685 "Construct a context-sensitive menu of MIME commands."
4686 (interactive "e\nP")
4687 (save-window-excursion
4688 (let ((pos (event-start event)))
4689 (select-window (posn-window pos))
4690 (goto-char (posn-point pos))
4691 (gnus-article-check-buffer)
4692 (popup-menu gnus-mime-button-menu nil prefix))))
16409b0b
GM
4693
4694(defun gnus-mime-view-all-parts (&optional handles)
4695 "View all the MIME parts."
4696 (interactive)
01c52d31 4697 (with-current-buffer gnus-article-buffer
16409b0b
GM
4698 (let ((handles (or handles gnus-article-mime-handles))
4699 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4700 (mail-parse-ignored-charsets
23f87bed
MB
4701 (with-current-buffer gnus-summary-buffer
4702 gnus-newsgroup-ignored-charsets)))
4703 (when handles
4704 (mm-remove-parts handles)
4705 (goto-char (point-min))
4706 (or (search-forward "\n\n") (goto-char (point-max)))
4707 (let ((inhibit-read-only t))
4708 (delete-region (point) (point-max))
4709 (mm-display-parts handles))))))
4710
01c52d31
MB
4711(defun gnus-article-jump-to-part (n)
4712 "Jump to MIME part N."
4713 (interactive "P")
4714 (pop-to-buffer gnus-article-buffer)
4715 ;; FIXME: why is it necessary?
4716 (sit-for 0)
4717 (let ((parts (length gnus-article-mime-handle-alist)))
4718 (or n (setq n
4719 (string-to-number
4720 (read-string ;; Emacs 21 doesn't have `read-number'.
4721 (format "Jump to part (2..%s): " parts)))))
4722 (unless (and (integerp n) (<= n parts) (>= n 1))
4723 (setq n
4724 (progn
4725 (gnus-message 7 "Invalid part `%s', using %s instead."
4726 n parts)
4727 parts)))
4728 (gnus-message 9 "Jumping to part %s." n)
4729 (cond ((>= gnus-auto-select-part 1)
4730 (while (and (<= n parts)
4731 (not (gnus-article-goto-part n)))
4732 (setq n (1+ n))))
4733 ((< gnus-auto-select-part 0)
4734 (while (and (>= n 1)
4735 (not (gnus-article-goto-part n)))
4736 (setq n (1- n))))
4737 (t
4738 (gnus-article-goto-part n)))))
4739
4740(eval-when-compile
4741 (defsubst gnus-article-edit-part (handles &optional current-id)
4742 "Edit an article in order to delete a mime part.
4743This function is exclusively used by `gnus-mime-save-part-and-strip'
4744and `gnus-mime-delete-part', and not provided at run-time normally."
4745 (gnus-article-edit-article
4746 `(lambda ()
4747 (buffer-disable-undo)
4748 (erase-buffer)
4749 (let ((mail-parse-charset (or gnus-article-charset
4750 ',gnus-newsgroup-charset))
4751 (mail-parse-ignored-charsets
4752 (or gnus-article-ignored-charsets
4753 ',gnus-newsgroup-ignored-charsets))
4754 (mbl mml-buffer-list))
4755 (setq mml-buffer-list nil)
4756 (insert-buffer-substring gnus-original-article-buffer)
4757 (mime-to-mml ',handles)
4758 (setq gnus-article-mime-handles nil)
4759 (let ((mbl1 mml-buffer-list))
4760 (setq mml-buffer-list mbl)
4761 (set (make-local-variable 'mml-buffer-list) mbl1))
4762 (gnus-make-local-hook 'kill-buffer-hook)
4763 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4764 `(lambda (no-highlight)
4765 (let ((mail-parse-charset (or gnus-article-charset
4766 ',gnus-newsgroup-charset))
4767 (message-options message-options)
4768 (message-options-set-recipient)
4769 (mail-parse-ignored-charsets
4770 (or gnus-article-ignored-charsets
4771 ',gnus-newsgroup-ignored-charsets)))
4772 (mml-to-mime)
4773 (mml-destroy-buffers)
4774 (remove-hook 'kill-buffer-hook
4775 'mml-destroy-buffers t)
4776 (kill-local-variable 'mml-buffer-list))
4777 (gnus-summary-edit-article-done
4778 ,(or (mail-header-references gnus-current-headers) "")
4779 ,(gnus-group-read-only-p)
4780 ,gnus-summary-buffer no-highlight))
4781 t)
4782 (gnus-article-edit-done)
4783 (gnus-summary-expand-window)
4784 (gnus-summary-show-article)
4785 (when (and current-id (integerp gnus-auto-select-part))
4786 (gnus-article-jump-to-part
4787 (if (text-property-any (point-min) (point-max)
4788 'gnus-part (+ current-id gnus-auto-select-part))
4789 (+ current-id gnus-auto-select-part)
4790 (with-current-buffer gnus-article-buffer
4791 (length gnus-article-mime-handle-alist)))))))
4792
4793(defun gnus-mime-replace-part (file)
4794 "Replace MIME part under point with an external body."
4795 ;; Useful if file has already been saved to disk
4796 (interactive
4797 (list
4798 (mm-with-multibyte
4799 (read-file-name "Replace MIME part with file: "
4800 (or mm-default-directory default-directory)
4801 nil nil))))
4802 (gnus-mime-save-part-and-strip file))
4803
4804(defun gnus-mime-save-part-and-strip (&optional file)
4805 "Save the MIME part under point then replace it with an external body.
4806If FILE is given, use it for the external part."
23f87bed
MB
4807 (interactive)
4808 (gnus-article-check-buffer)
4809 (when (gnus-group-read-only-p)
4810 (error "The current group does not support deleting of parts"))
4811 (when (mm-complicated-handles gnus-article-mime-handles)
4812 (error "\
4813The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4814 (let* ((data (get-text-property (point) 'gnus-data))
4815 (id (get-text-property (point) 'gnus-part))
4816 param
4817 (handles gnus-article-mime-handles))
4818 (unless file
4819 (setq file
4820 (and data (mm-save-part data "Delete MIME part and save to: "))))
4821 (when file
4822 (with-current-buffer (mm-handle-buffer data)
4823 (erase-buffer)
4824 (insert "Content-Type: " (mm-handle-media-type data))
4825 (mml-insert-parameter-string (cdr (mm-handle-type data))
4826 '(charset))
4827 ;; Add a filename for the sake of saving the part again.
4828 (mml-insert-parameter
4829 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4830 (insert "\n")
4831 (insert "Content-ID: " (message-make-message-id) "\n")
4832 (insert "Content-Transfer-Encoding: binary\n")
4833 (insert "\n"))
4834 (setcdr data
4835 (cdr (mm-make-handle nil
4836 `("message/external-body"
4837 (access-type . "LOCAL-FILE")
4838 (name . ,file)))))
4839 ;; (set-buffer gnus-summary-buffer)
4840 (gnus-article-edit-part handles id))))
4841
4842;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4843;; parts...>') but with stripping would be nice.
23f87bed
MB
4844
4845(defun gnus-mime-delete-part ()
4846 "Delete the MIME part under point.
4847Replace it with some information about the removed part."
4848 (interactive)
4849 (gnus-article-check-buffer)
4850 (when (gnus-group-read-only-p)
4851 (error "The current group does not support deleting of parts"))
4852 (when (mm-complicated-handles gnus-article-mime-handles)
4853 (error "\
4854The current article has a complicated MIME structure, giving up..."))
01c52d31
MB
4855 (when (or gnus-expert-user
4856 (gnus-yes-or-no-p "\
4857Deleting parts may malfunction or destroy the article; continue? "))
23f87bed 4858 (let* ((data (get-text-property (point) 'gnus-data))
01c52d31 4859 (id (get-text-property (point) 'gnus-part))
23f87bed
MB
4860 (handles gnus-article-mime-handles)
4861 (none "(none)")
4862 (description
bbbe940b
MB
4863 (let ((desc (mm-handle-description data)))
4864 (when desc
4865 (mail-decode-encoded-word-string desc))))
23f87bed
MB
4866 (filename
4867 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4868 none))
4869 (type (mm-handle-media-type data)))
4870 (unless data
4871 (error "No MIME part under point"))
4872 (with-current-buffer (mm-handle-buffer data)
4873 (let ((bsize (format "%s" (buffer-size))))
4874 (erase-buffer)
4875 (insert
4876 (concat
4877 ",----\n"
4878 "| The following attachment has been deleted:\n"
4879 "|\n"
4880 "| Type: " type "\n"
4881 "| Filename: " filename "\n"
4882 "| Size (encoded): " bsize " Byte\n"
bbbe940b
MB
4883 (when description
4884 (concat "| Description: " description "\n"))
23f87bed
MB
4885 "`----\n"))
4886 (setcdr data
4887 (cdr (mm-make-handle
4888 nil `("text/plain") nil nil
4889 (list "attachment")
4890 (format "Deleted attachment (%s bytes)" bsize))))))
01c52d31
MB
4891 ;; (set-buffer gnus-summary-buffer)
4892 (gnus-article-edit-part handles id))))
16409b0b
GM
4893
4894(defun gnus-mime-save-part ()
4895 "Save the MIME part under point."
4896 (interactive)
4897 (gnus-article-check-buffer)
4898 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4899 (when data
4900 (mm-save-part data))))
16409b0b
GM
4901
4902(defun gnus-mime-pipe-part ()
4903 "Pipe the MIME part under point to a process."
4904 (interactive)
4905 (gnus-article-check-buffer)
4906 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4907 (when data
4908 (mm-pipe-part data))))
16409b0b
GM
4909
4910(defun gnus-mime-view-part ()
4911 "Interactively choose a viewing method for the MIME part under point."
4912 (interactive)
4913 (gnus-article-check-buffer)
4914 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4915 (when data
4916 (setq gnus-article-mime-handles
4917 (mm-merge-handles
4918 gnus-article-mime-handles (setq data (copy-sequence data))))
4919 (mm-interactively-view-part data))))
16409b0b
GM
4920
4921(defun gnus-mime-view-part-as-type-internal ()
4922 (gnus-article-check-buffer)
54e573e6
MB
4923 (let* ((handle (get-text-property (point) 'gnus-data))
4924 (name (or
4925 ;; Content-Type: foo/bar; name=...
4926 (mail-content-type-get (mm-handle-type handle) 'name)
4927 ;; Content-Disposition: attachment; filename=...
4928 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
16409b0b 4929 (def-type (and name (mm-default-file-encoding name))))
01c52d31
MB
4930 (or (and def-type (cons def-type 0))
4931 (and handle
4932 (equal (mm-handle-media-supertype handle) "text")
4933 '("text/plain" . 0))
4934 '("application/octet-stream" . 0))))
16409b0b 4935
54e573e6
MB
4936(defun gnus-mime-view-part-as-type (&optional mime-type pred)
4937 "Choose a MIME media type, and view the part as such.
4938If non-nil, PRED is a predicate to use during completion to limit the
4939available media-types."
23f87bed
MB
4940 (interactive)
4941 (unless mime-type
54e573e6
MB
4942 (setq mime-type
4943 (let ((default (gnus-mime-view-part-as-type-internal)))
4944 (completing-read
4945 (format "View as MIME type (default %s): "
4946 (car default))
4947 (mapcar #'list (mailcap-mime-types))
4948 pred nil nil nil
4949 (car default)))))
16409b0b
GM
4950 (gnus-article-check-buffer)
4951 (let ((handle (get-text-property (point) 'gnus-data)))
23f87bed 4952 (when handle
531bedc3
MB
4953 (when (equal (mm-handle-media-type handle) "message/external-body")
4954 (unless (mm-handle-cache handle)
4955 (mm-extern-cache-contents handle))
4956 (setq handle (mm-handle-cache handle)))
23f87bed
MB
4957 (setq handle
4958 (mm-make-handle (mm-handle-buffer handle)
4959 (cons mime-type (cdr (mm-handle-type handle)))
4960 (mm-handle-encoding handle)
4961 (mm-handle-undisplayer handle)
4962 (mm-handle-disposition handle)
4963 (mm-handle-description handle)
4964 nil
4965 (mm-handle-id handle)))
4966 (setq gnus-article-mime-handles
4967 (mm-merge-handles gnus-article-mime-handles handle))
01c52d31
MB
4968 (when (mm-handle-displayed-p handle)
4969 (mm-remove-part handle))
23f87bed
MB
4970 (gnus-mm-display-part handle))))
4971
01c52d31 4972(defun gnus-mime-copy-part (&optional handle arg)
23f87bed
MB
4973 "Put the MIME part under point into a new buffer.
4974If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4975are decompressed."
01c52d31 4976 (interactive (list nil current-prefix-arg))
16409b0b 4977 (gnus-article-check-buffer)
01c52d31
MB
4978 (unless handle
4979 (setq handle (get-text-property (point) 'gnus-data)))
4980 (when handle
4981 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4982 'name)
4983 (mail-content-type-get (mm-handle-disposition handle)
4984 'filename)))
4985 contents dont-decode charset coding-system)
4986 (mm-with-unibyte-buffer
4987 (mm-insert-part handle)
4988 (setq contents (or (condition-case nil
4989 (mm-decompress-buffer filename nil 'sig)
4990 (error
4991 (setq dont-decode t)
4992 nil))
4993 (buffer-string))))
4994 (setq filename (cond (filename (file-name-nondirectory filename))
4995 (dont-decode "*raw data*")
4996 (t "*decoded*")))
4997 (cond
4998 (dont-decode)
4999 ((not arg)
5000 (unless (setq charset (mail-content-type-get
5001 (mm-handle-type handle) 'charset))
5002 (unless (setq coding-system (mm-with-unibyte-buffer
5003 (insert contents)
5004 (mm-find-buffer-file-coding-system)))
5005 (setq charset gnus-newsgroup-charset))))
5006 ((numberp arg)
5007 (setq charset (or (cdr (assq arg
5008 gnus-summary-show-article-charset-alist))
5009 (mm-read-coding-system "Charset: ")))))
5010 (switch-to-buffer (generate-new-buffer filename))
5011 (if (or coding-system
5012 (and charset
5013 (setq coding-system (mm-charset-to-coding-system charset))
5014 (not (eq charset 'ascii))))
5015 (progn
5016 (mm-enable-multibyte)
5017 (insert (mm-decode-coding-string contents coding-system))
5018 (setq buffer-file-coding-system
5019 (if (boundp 'last-coding-system-used)
5020 (symbol-value 'last-coding-system-used)
5021 coding-system)))
5022 (mm-disable-multibyte)
5023 (insert contents)
5024 (setq buffer-file-coding-system mm-binary-coding-system))
23f87bed
MB
5025 ;; We do it this way to make `normal-mode' set the appropriate mode.
5026 (unwind-protect
5027 (progn
01c52d31 5028 (setq buffer-file-name (expand-file-name filename))
23f87bed
MB
5029 (normal-mode))
5030 (setq buffer-file-name nil))
5031 (goto-char (point-min)))))
5032
5033(defun gnus-mime-print-part (&optional handle filename)
5034 "Print the MIME part under point."
5035 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5036 (gnus-article-check-buffer)
5037 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5038 (contents (and handle (mm-get-part handle)))
5039 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5040 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5041 (when contents
5042 (if printer
5043 (unwind-protect
5044 (progn
5045 (mm-save-part-to-file handle file)
5046 (call-process shell-file-name nil
5047 (generate-new-buffer " *mm*")
5048 nil
5049 shell-command-switch
5050 (mm-mailcap-command
5051 printer file (mm-handle-type handle))))
5052 (delete-file file))
5053 (with-temp-buffer
5054 (insert contents)
5055 (gnus-print-buffer))
5056 (ps-despool filename)))))
16409b0b 5057
e0bad764 5058(defun gnus-mime-inline-part (&optional handle arg)
01c52d31
MB
5059 "Insert the MIME part under point into the current buffer.
5060Compressed files like .gz and .bz2 are decompressed."
e0bad764 5061 (interactive (list nil current-prefix-arg))
16409b0b 5062 (gnus-article-check-buffer)
01c52d31
MB
5063 (unless handle
5064 (setq handle (get-text-property (point) 'gnus-data)))
5065 (when handle
5066 (let ((b (point))
5067 (inhibit-read-only t)
5068 contents charset coding-system)
23f87bed
MB
5069 (if (and (not arg) (mm-handle-undisplayer handle))
5070 (mm-remove-part handle)
01c52d31
MB
5071 (mm-with-unibyte-buffer
5072 (mm-insert-part handle)
5073 (setq contents
5074 (or (mm-decompress-buffer
5075 (or (mail-content-type-get (mm-handle-type handle)
5076 'name)
5077 (mail-content-type-get (mm-handle-disposition handle)
5078 'filename))
5079 nil t)
5080 (buffer-string))))
23f87bed
MB
5081 (cond
5082 ((not arg)
01c52d31
MB
5083 (unless (setq charset (mail-content-type-get
5084 (mm-handle-type handle) 'charset))
5085 (unless (setq coding-system
5086 (mm-with-unibyte-buffer
5087 (insert contents)
5088 (mm-find-buffer-file-coding-system)))
5089 (setq charset gnus-newsgroup-charset))))
23f87bed
MB
5090 ((numberp arg)
5091 (if (mm-handle-undisplayer handle)
5092 (mm-remove-part handle))
5093 (setq charset
5094 (or (cdr (assq arg
5095 gnus-summary-show-article-charset-alist))
56c30d72
MB
5096 (mm-read-coding-system "Charset: "))))
5097 (t
5098 (if (mm-handle-undisplayer handle)
850c333d 5099 (mm-remove-part handle))))
23f87bed 5100 (forward-line 2)
850c333d
MB
5101 (mm-insert-inline
5102 handle
01c52d31
MB
5103 (if (or coding-system
5104 (and charset
5105 (setq coding-system
5106 (mm-charset-to-coding-system charset))
5107 (not (eq coding-system 'ascii))))
5108 (mm-decode-coding-string contents coding-system)
850c333d 5109 (mm-string-to-multibyte contents)))
23f87bed
MB
5110 (goto-char b)))))
5111
6b554e88
MB
5112(defun gnus-mime-strip-charset-parameters (handle)
5113 "Strip charset parameters from HANDLE."
5114 (if (stringp (car handle))
5115 (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
5116 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5117 "message/external-body")
5118 (progn
5119 (unless (mm-handle-cache handle)
5120 (mm-extern-cache-contents handle))
5121 (mm-handle-cache handle))
5122 handle)))
5123 (charset (assq 'charset (cdr type))))
5124 (when charset
5125 (delq charset type)))))
5126
23f87bed
MB
5127(defun gnus-mime-view-part-as-charset (&optional handle arg)
5128 "Insert the MIME part under point into the current buffer using the
5129specified charset."
5130 (interactive (list nil current-prefix-arg))
5131 (gnus-article-check-buffer)
163cb72d
MB
5132 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5133 (fun (get-text-property (point) 'gnus-callback))
5134 (gnus-newsgroup-ignored-charsets 'gnus-all)
6b554e88 5135 gnus-newsgroup-charset form preferred parts)
23f87bed 5136 (when handle
01c52d31
MB
5137 (when (prog1
5138 (and fun
5139 (setq gnus-newsgroup-charset
5140 (or (cdr (assq
5141 arg
5142 gnus-summary-show-article-charset-alist))
5143 (mm-read-coding-system "Charset: "))))
5144 (if (mm-handle-undisplayer handle)
5145 (mm-remove-part handle)))
6b554e88
MB
5146 (gnus-mime-strip-charset-parameters handle)
5147 (when (and (consp (setq form (cdr-safe fun)))
5148 (setq form (ignore-errors
5149 (assq 'gnus-mime-display-alternative form)))
5150 (setq preferred (caddr form))
5151 (progn
5152 (when (eq (car preferred) 'quote)
5153 (setq preferred (cadr preferred)))
5154 (not (equal preferred
5155 (get-text-property (point) 'gnus-data))))
5156 (setq parts (get-text-property (point) 'gnus-part))
5157 (setq parts (cdr (assq parts
5158 gnus-article-mime-handle-alist)))
5159 (equal (mm-handle-media-type parts) "multipart/alternative")
5160 (setq parts (reverse (cdr parts))))
5161 (setcar (cddr form)
5162 (list 'quote (or (cadr (member preferred parts))
5163 (car parts)))))
163cb72d 5164 (funcall fun handle)))))
23f87bed
MB
5165
5166(defun gnus-mime-view-part-externally (&optional handle)
16409b0b
GM
5167 "View the MIME part under point with an external viewer."
5168 (interactive)
5169 (gnus-article-check-buffer)
5170 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5171 (mm-user-display-methods nil)
5172 (mm-inlined-types nil)
5173 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5174 (mail-parse-ignored-charsets
54e573e6
MB
5175 (with-current-buffer gnus-summary-buffer
5176 gnus-newsgroup-ignored-charsets))
5177 (type (mm-handle-media-type handle))
5178 (method (mailcap-mime-info type))
5179 (mm-enable-external t))
5180 (if (not (stringp method))
5181 (gnus-mime-view-part-as-type
524705ae 5182 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
54e573e6
MB
5183 (when handle
5184 (if (mm-handle-undisplayer handle)
5185 (mm-remove-part handle)
5186 (mm-display-part handle))))))
16409b0b 5187
23f87bed 5188(defun gnus-mime-view-part-internally (&optional handle)
16409b0b 5189 "View the MIME part under point with an internal viewer.
23f87bed 5190If no internal viewer is available, use an external viewer."
16409b0b
GM
5191 (interactive)
5192 (gnus-article-check-buffer)
5193 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5194 (mm-inlined-types '(".*"))
5195 (mm-inline-large-images t)
5196 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5197 (mail-parse-ignored-charsets
54e573e6
MB
5198 (with-current-buffer gnus-summary-buffer
5199 gnus-newsgroup-ignored-charsets))
23f87bed 5200 (inhibit-read-only t))
54e573e6
MB
5201 (if (not (mm-inlinable-p handle))
5202 (gnus-mime-view-part-as-type
524705ae 5203 nil (lambda (types) (mm-inlinable-p handle (car types))))
54e573e6
MB
5204 (when handle
5205 (if (mm-handle-undisplayer handle)
5206 (mm-remove-part handle)
5207 (mm-display-part handle))))))
16409b0b 5208
e0bad764
DL
5209(defun gnus-mime-action-on-part (&optional action)
5210 "Do something with the MIME attachment at \(point\)."
5211 (interactive
23f87bed 5212 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
e0bad764
DL
5213 (gnus-article-check-buffer)
5214 (let ((action-pair (assoc action gnus-mime-action-alist)))
5215 (if action-pair
5216 (funcall (cdr action-pair)))))
5217
01c52d31
MB
5218(defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5219 "Call FUNCTION on MIME part N.
5220Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5221If INTERACTIVE, call FUNCTION interactivly."
5222 (let (window frame)
5223 ;; Check whether the article is displayed.
5224 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5225 (setq window (get-buffer-window gnus-article-buffer t))
5226 (frame-visible-p (setq frame (window-frame window))))
5227 (error "No article is displayed"))
5228 (with-current-buffer gnus-article-buffer
5229 ;; Check whether the article displays the right contents.
5230 (unless (with-current-buffer gnus-summary-buffer
5231 (eq gnus-current-article (gnus-summary-article-number)))
5232 (error "You should select the right article first"))
5233 (if n
5234 (setq n (prefix-numeric-value n))
5235 (let ((pt (point)))
5236 (setq n (or (get-text-property pt 'gnus-part)
5237 (and (not (bobp))
5238 (get-text-property (1- pt) 'gnus-part))
5239 (get-text-property (prog2
5240 (forward-line 1)
5241 (point)
5242 (goto-char pt))
5243 'gnus-part)
5244 (get-text-property
5245 (or (and (setq pt (previous-single-property-change
5246 pt 'gnus-part))
5247 (1- pt))
5248 (next-single-property-change (point) 'gnus-part)
5249 (point))
5250 'gnus-part)
5251 1))))
5252 ;; Check whether the specified part exists.
5253 (when (> n (length gnus-article-mime-handle-alist))
5254 (error "No such part")))
5255 (unless
5256 (progn
5257 ;; To select the window is needed so that the cursor
5258 ;; might be visible on the MIME button.
5259 (select-window (prog1
5260 window
5261 (setq window (selected-window))
5262 ;; Article may be displayed in the other frame.
5263 (gnus-select-frame-set-input-focus
5264 (prog1
5265 frame
5266 (setq frame (selected-frame))))))
5267 (when (gnus-article-goto-part n)
5268 ;; We point the cursor and the arrow at the MIME button
5269 ;; when the `function' prompt the user for something.
5270 (let ((cursor-in-non-selected-windows t)
5271 (overlay-arrow-string "=>")
5272 (overlay-arrow-position (point-marker)))
5273 (unwind-protect
5274 (cond
5275 ((and no-handle interactive)
5276 (call-interactively function))
5277 (no-handle
5278 (funcall function))
5279 (interactive
5280 (call-interactively
5281 function
5282 (cdr (assq n gnus-article-mime-handle-alist))))
5283 (t
5284 (funcall function
5285 (cdr (assq n gnus-article-mime-handle-alist)))))
5286 (set-marker overlay-arrow-position nil)
5287 (unless gnus-auto-select-part
5288 (gnus-select-frame-set-input-focus frame)
5289 (select-window window))))
5290 t))
5291 (if gnus-inhibit-mime-unbuttonizing
5292 ;; This is the default though the program shouldn't reach here.
5293 (error "No such part")
5294 ;; The part which doesn't have the MIME button is selected.
5295 ;; So, we display all the buttons and redo it.
5296 (let ((gnus-inhibit-mime-unbuttonizing t))
5297 (gnus-summary-show-article)
5298 (gnus-article-part-wrapper n function no-handle))))))
16409b0b
GM
5299
5300(defun gnus-article-pipe-part (n)
5301 "Pipe MIME part N, which is the numerical prefix."
01c52d31 5302 (interactive "P")
16409b0b
GM
5303 (gnus-article-part-wrapper n 'mm-pipe-part))
5304
5305(defun gnus-article-save-part (n)
5306 "Save MIME part N, which is the numerical prefix."
01c52d31 5307 (interactive "P")
16409b0b
GM
5308 (gnus-article-part-wrapper n 'mm-save-part))
5309
5310(defun gnus-article-interactively-view-part (n)
5311 "View MIME part N interactively, which is the numerical prefix."
01c52d31 5312 (interactive "P")
16409b0b
GM
5313 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5314
5315(defun gnus-article-copy-part (n)
5316 "Copy MIME part N, which is the numerical prefix."
01c52d31 5317 (interactive "P")
16409b0b
GM
5318 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5319
23f87bed
MB
5320(defun gnus-article-view-part-as-charset (n)
5321 "View MIME part N using a specified charset.
5322N is the numerical prefix."
01c52d31 5323 (interactive "P")
23f87bed
MB
5324 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5325
5326(defun gnus-article-view-part-externally (n)
16409b0b 5327 "View MIME part N externally, which is the numerical prefix."
01c52d31 5328 (interactive "P")
23f87bed 5329 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
16409b0b
GM
5330
5331(defun gnus-article-inline-part (n)
5332 "Inline MIME part N, which is the numerical prefix."
01c52d31 5333 (interactive "P")
16409b0b
GM
5334 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5335
01c52d31
MB
5336(defun gnus-article-save-part-and-strip (n)
5337 "Save MIME part N and replace it with an external body.
5338N is the numerical prefix."
5339 (interactive "P")
5340 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5341
5342(defun gnus-article-replace-part (n)
5343 "Replace MIME part N with an external body.
5344N is the numerical prefix."
5345 (interactive "P")
5346 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5347
5348(defun gnus-article-delete-part (n)
5349 "Delete MIME part N and add some information about the removed part.
5350N is the numerical prefix."
5351 (interactive "P")
5352 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5353
5354(defun gnus-article-view-part-as-type (n)
5355 "Choose a MIME media type, and view part N as such.
5356N is the numerical prefix."
5357 (interactive "P")
5358 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5359
16409b0b
GM
5360(defun gnus-article-mime-match-handle-first (condition)
5361 (if condition
01c52d31
MB
5362 (let (n)
5363 (dolist (ihandle gnus-article-mime-handle-alist)
a1506d29 5364 (if (and (cond
16409b0b
GM
5365 ((functionp condition)
5366 (funcall condition (cdr ihandle)))
a1506d29 5367 ((eq condition 'undisplayed)
16409b0b
GM
5368 (not (or (mm-handle-undisplayer (cdr ihandle))
5369 (equal (mm-handle-media-type (cdr ihandle))
5370 "multipart/alternative"))))
5371 ((eq condition 'undisplayed-alternative)
5372 (not (mm-handle-undisplayer (cdr ihandle))))
5373 (t t))
5374 (gnus-article-goto-part (car ihandle))
5375 (or (not n) (< (car ihandle) n)))
5376 (setq n (car ihandle))))
5377 (or n 1))
5378 1))
5379
5380(defun gnus-article-view-part (&optional n)
5381 "View MIME part N, which is the numerical prefix."
5382 (interactive "P")
01c52d31 5383 (with-current-buffer gnus-article-buffer
a1506d29 5384 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
16409b0b
GM
5385 gnus-article-mime-match-handle-function)))
5386 (when (> n (length gnus-article-mime-handle-alist))
5387 (error "No such part"))
5388 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5389 (when (gnus-article-goto-part n)
5390 (if (equal (car handle) "multipart/alternative")
5391 (gnus-article-press-button)
5392 (when (eq (gnus-mm-display-part handle) 'internal)
5393 (gnus-set-window-start)))))))
5394
e0bad764
DL
5395(defsubst gnus-article-mime-total-parts ()
5396 (if (bufferp (car gnus-article-mime-handles))
5397 1 ;; single part
5398 (1- (length gnus-article-mime-handles))))
5399
16409b0b
GM
5400(defun gnus-mm-display-part (handle)
5401 "Display HANDLE and fix MIME button."
5402 (let ((id (get-text-property (point) 'gnus-part))
5403 (point (point))
23f87bed 5404 (inhibit-read-only t))
16409b0b
GM
5405 (forward-line 1)
5406 (prog1
5407 (let ((window (selected-window))
5408 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 5409 (mail-parse-ignored-charsets
23f87bed 5410 (if (gnus-buffer-live-p gnus-summary-buffer)
01c52d31 5411 (with-current-buffer gnus-summary-buffer
23f87bed
MB
5412 gnus-newsgroup-ignored-charsets)
5413 nil)))
16409b0b
GM
5414 (save-excursion
5415 (unwind-protect
23f87bed 5416 (let ((win (gnus-get-buffer-window (current-buffer) t))
16409b0b
GM
5417 (beg (point)))
5418 (when win
5419 (select-window win))
5420 (goto-char point)
5421 (forward-line)
5422 (if (mm-handle-displayed-p handle)
5423 ;; This will remove the part.
5424 (mm-display-part handle)
5425 (save-restriction
23f87bed
MB
5426 (narrow-to-region (point)
5427 (if (eobp) (point) (1+ (point))))
16409b0b
GM
5428 (mm-display-part handle)
5429 ;; We narrow to the part itself and
5430 ;; then call the treatment functions.
5431 (goto-char (point-min))
5432 (forward-line 1)
5433 (narrow-to-region (point) (point-max))
5434 (gnus-treat-article
5435 nil id
e0bad764 5436 (gnus-article-mime-total-parts)
16409b0b 5437 (mm-handle-media-type handle)))))
23f87bed
MB
5438 (if (window-live-p window)
5439 (select-window window)))))
16409b0b 5440 (goto-char point)
23f87bed 5441 (gnus-delete-line)
16409b0b
GM
5442 (gnus-insert-mime-button
5443 handle id (list (mm-handle-displayed-p handle)))
5444 (goto-char point))))
5445
5446(defun gnus-article-goto-part (n)
5447 "Go to MIME part N."
23f87bed 5448 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
16409b0b
GM
5449
5450(defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5451 (let ((gnus-tmp-name
23f87bed
MB
5452 (or (mail-content-type-get (mm-handle-type handle) 'name)
5453 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5454 (mail-content-type-get (mm-handle-type handle) 'url)
16409b0b
GM
5455 ""))
5456 (gnus-tmp-type (mm-handle-media-type handle))
5457 (gnus-tmp-description
5458 (mail-decode-encoded-word-string (or (mm-handle-description handle)
5459 "")))
5460 (gnus-tmp-dots
5461 (if (if displayed (car displayed)
5462 (mm-handle-displayed-p handle))
5463 "" "..."))
5464 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5465 (buffer-size)))
5466 gnus-tmp-type-long b e)
5467 (when (string-match ".*/" gnus-tmp-name)
5468 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5469 (setq gnus-tmp-type-long (concat gnus-tmp-type
5470 (and (not (equal gnus-tmp-name ""))
5471 (concat "; " gnus-tmp-name))))
23f87bed
MB
5472 (unless (equal gnus-tmp-description "")
5473 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
16409b0b
GM
5474 (unless (bolp)
5475 (insert "\n"))
5476 (setq b (point))
5477 (gnus-eval-format
5478 gnus-mime-button-line-format gnus-mime-button-line-format-alist
01c52d31
MB
5479 `(keymap ,gnus-mime-button-map
5480 gnus-callback gnus-mm-display-part
5481 gnus-part ,gnus-tmp-id
5482 article-type annotation
5483 gnus-data ,handle))
23f87bed
MB
5484 (setq e (if (bolp)
5485 ;; Exclude a newline.
5486 (1- (point))
5487 (point)))
01c52d31
MB
5488 (when gnus-article-button-face
5489 (gnus-overlay-put (gnus-make-overlay b e nil t)
5490 'face gnus-article-button-face))
16409b0b
GM
5491 (widget-convert-button
5492 'link b e
5493 :mime-handle handle
5494 :action 'gnus-widget-press-button
5495 :button-keymap gnus-mime-button-map
5496 :help-echo
5497 (lambda (widget/window &optional overlay pos)
5498 ;; Needed to properly clear the message due to a bug in
5499 ;; wid-edit (XEmacs only).
5500 (if (boundp 'help-echo-owns-message)
5501 (setq help-echo-owns-message t))
5502 (format
5503 "%S: %s the MIME part; %S: more options"
5504 (aref gnus-mouse-2 0)
5505 ;; XEmacs will get a single widget arg; Emacs 21 will get
5506 ;; window, overlay, position.
5507 (if (mm-handle-displayed-p
5508 (if overlay
e0bad764
DL
5509 (with-current-buffer (gnus-overlay-buffer overlay)
5510 (widget-get (widget-at (gnus-overlay-start overlay))
16409b0b
GM
5511 :mime-handle))
5512 (widget-get widget/window :mime-handle)))
5513 "hide" "show")
5514 (aref gnus-down-mouse-3 0))))))
5515
5516(defun gnus-widget-press-button (elems el)
5517 (goto-char (widget-get elems :from))
5518 (gnus-article-press-button))
5519
5520(defvar gnus-displaying-mime nil)
5521
5522(defun gnus-display-mime (&optional ihandles)
5523 "Display the MIME parts."
5524 (save-excursion
5525 (save-selected-window
5526 (let ((window (get-buffer-window gnus-article-buffer))
5527 (point (point)))
5528 (when window
5529 (select-window window)
5530 ;; We have to do this since selecting the window
5531 ;; may change the point. So we set the window point.
5532 (set-window-point window point)))
73043f7d
MB
5533 (let ((handles ihandles)
5534 (inhibit-read-only t)
5535 handle)
5536 (cond (handles)
5537 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5538 (when gnus-article-emulate-mime
5539 (mm-uu-dissect-text-parts handles)))
5540 (gnus-article-emulate-mime
5541 (setq handles (mm-uu-dissect))))
16409b0b
GM
5542 (when (and (not ihandles)
5543 (not gnus-displaying-mime))
5544 ;; Top-level call; we clean up.
5545 (when gnus-article-mime-handles
5546 (mm-destroy-parts gnus-article-mime-handles)
5547 (setq gnus-article-mime-handle-alist nil));; A trick.
5548 (setq gnus-article-mime-handles handles)
5549 ;; We allow users to glean info from the handles.
5550 (when gnus-article-mime-part-function
5551 (gnus-mime-part-function handles)))
5552 (if (and handles
5553 (or (not (stringp (car handles)))
5554 (cdr handles)))
5555 (progn
5556 (when (and (not ihandles)
5557 (not gnus-displaying-mime))
5558 ;; Clean up for mime parts.
5559 (article-goto-body)
5560 (delete-region (point) (point-max)))
5561 (let ((gnus-displaying-mime t))
5562 (gnus-mime-display-part handles)))
5563 (save-restriction
5564 (article-goto-body)
5565 (narrow-to-region (point) (point-max))
5566 (gnus-treat-article nil 1 1)
5567 (widen)))
5568 (unless ihandles
5569 ;; Highlight the headers.
5570 (save-excursion
5571 (save-restriction
5572 (article-goto-body)
5573 (narrow-to-region (point-min) (point))
31640842 5574 (gnus-article-save-original-date
f362b760
MB
5575 (gnus-treat-article 'head)))))))
5576 ;; Cope with broken MIME messages.
5577 (goto-char (point-max))
5578 (unless (bolp)
5579 (insert "\n"))))
16409b0b 5580
23f87bed
MB
5581(defcustom gnus-mime-display-multipart-as-mixed nil
5582 "Display \"multipart\" parts as \"multipart/mixed\".
5583
5584If t, it overrides nil values of
5585`gnus-mime-display-multipart-alternative-as-mixed' and
5586`gnus-mime-display-multipart-related-as-mixed'."
5587 :group 'gnus-article-mime
5588 :type 'boolean)
5589
5590(defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5591 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
bf247b6e 5592 :version "22.1"
23f87bed
MB
5593 :group 'gnus-article-mime
5594 :type 'boolean)
5595
5596(defcustom gnus-mime-display-multipart-related-as-mixed nil
5597 "Display \"multipart/related\" parts as \"multipart/mixed\".
5598
5599If displaying \"text/html\" is discouraged \(see
5600`mm-discouraged-alternatives'\) images or other material inside a
5601\"multipart/related\" part might be overlooked when this variable is nil."
bf247b6e 5602 :version "22.1"
23f87bed
MB
5603 :group 'gnus-article-mime
5604 :type 'boolean)
16409b0b
GM
5605
5606(defun gnus-mime-display-part (handle)
5607 (cond
430d3ed7
MB
5608 ;; Maybe a broken MIME message.
5609 ((null handle))
16409b0b
GM
5610 ;; Single part.
5611 ((not (stringp (car handle)))
5612 (gnus-mime-display-single handle))
5613 ;; User-defined multipart
5614 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5615 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5616 handle))
5617 ;; multipart/alternative
5618 ((and (equal (car handle) "multipart/alternative")
23f87bed
MB
5619 (not (or gnus-mime-display-multipart-as-mixed
5620 gnus-mime-display-multipart-alternative-as-mixed)))
16409b0b
GM
5621 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5622 (push (cons id handle) gnus-article-mime-handle-alist)
5623 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5624 ;; multipart/related
5625 ((and (equal (car handle) "multipart/related")
23f87bed
MB
5626 (not (or gnus-mime-display-multipart-as-mixed
5627 gnus-mime-display-multipart-related-as-mixed)))
16409b0b
GM
5628 ;;;!!!We should find the start part, but we just default
5629 ;;;!!!to the first part.
23f87bed
MB
5630 ;;(gnus-mime-display-part (cadr handle))
5631 ;;;!!! Most multipart/related is an HTML message plus images.
5632 ;;;!!! Unfortunately we are unable to let W3 display those
5633 ;;;!!! included images, so we just display it as a mixed multipart.
5634 ;;(gnus-mime-display-mixed (cdr handle))
5635 ;;;!!! No, w3 can display everything just fine.
16409b0b 5636 (gnus-mime-display-part (cadr handle)))
23f87bed
MB
5637 ((equal (car handle) "multipart/signed")
5638 (gnus-add-wash-type 'signed)
5639 (gnus-mime-display-security handle))
5640 ((equal (car handle) "multipart/encrypted")
5641 (gnus-add-wash-type 'encrypted)
5642 (gnus-mime-display-security handle))
16409b0b
GM
5643 ;; Other multiparts are handled like multipart/mixed.
5644 (t
5645 (gnus-mime-display-mixed (cdr handle)))))
5646
5647(defun gnus-mime-part-function (handles)
5648 (if (stringp (car handles))
5649 (mapcar 'gnus-mime-part-function (cdr handles))
5650 (funcall gnus-article-mime-part-function handles)))
5651
5652(defun gnus-mime-display-mixed (handles)
5653 (mapcar 'gnus-mime-display-part handles))
5654
5655(defun gnus-mime-display-single (handle)
5656 (let ((type (mm-handle-media-type handle))
5657 (ignored gnus-ignored-mime-types)
5658 (not-attachment t)
5659 (move nil)
5660 display text)
5661 (catch 'ignored
5662 (progn
5663 (while ignored
5664 (when (string-match (pop ignored) type)
5665 (throw 'ignored nil)))
5666 (if (and (setq not-attachment
5667 (and (not (mm-inline-override-p handle))
5668 (or (not (mm-handle-disposition handle))
5669 (equal (car (mm-handle-disposition handle))
5670 "inline")
5671 (mm-attachment-override-p handle))))
5672 (mm-automatic-display-p handle)
23f87bed
MB
5673 (or (and
5674 (mm-inlinable-p handle)
5675 (mm-inlined-p handle))
16409b0b
GM
5676 (mm-automatic-external-display-p type)))
5677 (setq display t)
5678 (when (equal (mm-handle-media-supertype handle) "text")
5679 (setq text t)))
e0bad764
DL
5680 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5681 beg)
16409b0b 5682 (push (cons id handle) gnus-article-mime-handle-alist)
531bedc3
MB
5683 (when (and display
5684 (equal (mm-handle-media-supertype handle) "message"))
5685 (insert-char
5686 ?\n
5687 (cond ((not (bolp)) 2)
5688 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5689 (t 1))))
16409b0b
GM
5690 (when (or (not display)
5691 (not (gnus-unbuttonized-mime-type-p type)))
16409b0b
GM
5692 (gnus-insert-mime-button
5693 handle id (list (or display (and not-attachment text))))
5694 (gnus-article-insert-newline)
23f87bed 5695 ;; Remember modify the number of forward lines.
e0bad764
DL
5696 (setq move t))
5697 (setq beg (point))
16409b0b
GM
5698 (cond
5699 (display
5700 (when move
23f87bed 5701 (forward-line -1)
16409b0b
GM
5702 (setq beg (point)))
5703 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5704 (mail-parse-ignored-charsets
16409b0b
GM
5705 (save-excursion (condition-case ()
5706 (set-buffer gnus-summary-buffer)
5707 (error))
5708 gnus-newsgroup-ignored-charsets)))
5709 (mm-display-part handle t))
5710 (goto-char (point-max)))
5711 ((and text not-attachment)
5712 (when move
23f87bed 5713 (forward-line -1)
16409b0b
GM
5714 (setq beg (point)))
5715 (gnus-article-insert-newline)
53cfefc8
MB
5716 (mm-insert-inline
5717 handle
01c52d31
MB
5718 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5719 'charset)
5720 (and (equal type "text/calendar") 'utf-8))))
53cfefc8
MB
5721 (cond ((not charset)
5722 (mm-string-as-multibyte (mm-get-part handle)))
5723 ((eq charset 'gnus-decoded)
5724 (with-current-buffer (mm-handle-buffer handle)
5725 (buffer-string)))
5726 (t
5727 (mm-decode-string (mm-get-part handle) charset)))))
16409b0b
GM
5728 (goto-char (point-max))))
5729 ;; Do highlighting.
5730 (save-excursion
5731 (save-restriction
5732 (narrow-to-region beg (point))
01c52d31
MB
5733 (if (eq handle gnus-article-mime-handles)
5734 ;; The format=flowed case.
5735 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5736 ;; Don't count signature parts that are never displayed.
5737 ;; The part number should be re-calculated supposing this
5738 ;; might be a message/rfc822 part.
5739 (let (handles)
5740 (dolist (part gnus-article-mime-handles)
5741 (unless (or (stringp part)
5742 (equal (car (mm-handle-type part))
5743 "application/pgp-signature"))
5744 (push part handles)))
5745 (gnus-treat-article
5746 nil (length (memq handle handles)) (length handles)
5747 (mm-handle-media-type handle)))))))))))
16409b0b
GM
5748
5749(defun gnus-unbuttonized-mime-type-p (type)
5750 "Say whether TYPE is to be unbuttonized."
5751 (unless gnus-inhibit-mime-unbuttonizing
23f87bed
MB
5752 (when (catch 'found
5753 (let ((types gnus-unbuttonized-mime-types))
5754 (while types
5755 (when (string-match (pop types) type)
5756 (throw 'found t)))))
5757 (not (catch 'found
5758 (let ((types gnus-buttonized-mime-types))
5759 (while types
5760 (when (string-match (pop types) type)
5761 (throw 'found t)))))))))
16409b0b
GM
5762
5763(defun gnus-article-insert-newline ()
5764 "Insert a newline, but mark it as undeletable."
5765 (gnus-put-text-property
5766 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5767
5768(defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5769 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5770 (ihandles handles)
5771 (point (point))
23f87bed 5772 handle (inhibit-read-only t) from props begend not-pref)
16409b0b
GM
5773 (save-window-excursion
5774 (save-restriction
5775 (when ibegend
5776 (narrow-to-region (car ibegend)
5777 (or (cdr ibegend)
5778 (progn
5779 (goto-char (car ibegend))
5780 (forward-line 2)
5781 (point))))
5782 (delete-region (point-min) (point-max))
5783 (mm-remove-parts handles))
5784 (setq begend (list (point-marker)))
5785 ;; Do the toggle.
5786 (unless (setq not-pref (cadr (member preferred ihandles)))
5787 (setq not-pref (car ihandles)))
5788 (when (or ibegend
23f87bed 5789 (not preferred)
16409b0b
GM
5790 (not (gnus-unbuttonized-mime-type-p
5791 "multipart/alternative")))
5792 (gnus-add-text-properties
5793 (setq from (point))
5794 (progn
5795 (insert (format "%d. " id))
5796 (point))
5797 `(gnus-callback
5798 (lambda (handles)
5799 (unless ,(not ibegend)
5800 (setq gnus-article-mime-handle-alist
5801 ',gnus-article-mime-handle-alist))
5802 (gnus-mime-display-alternative
5803 ',ihandles ',not-pref ',begend ,id))
01c52d31 5804 keymap ,gnus-mime-button-map
16409b0b
GM
5805 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5806 face ,gnus-article-button-face
16409b0b 5807 gnus-part ,id
7dafe00b 5808 article-type multipart))
16409b0b
GM
5809 (widget-convert-button 'link from (point)
5810 :action 'gnus-widget-press-button
5811 :button-keymap gnus-widget-button-keymap)
5812 ;; Do the handles
5813 (while (setq handle (pop handles))
5814 (gnus-add-text-properties
5815 (setq from (point))
5816 (progn
5817 (insert (format "(%c) %-18s"
5818 (if (equal handle preferred) ?* ? )
5819 (mm-handle-media-type handle)))
5820 (point))
5821 `(gnus-callback
5822 (lambda (handles)
5823 (unless ,(not ibegend)
5824 (setq gnus-article-mime-handle-alist
5825 ',gnus-article-mime-handle-alist))
5826 (gnus-mime-display-alternative
5827 ',ihandles ',handle ',begend ,id))
01c52d31 5828 keymap ,gnus-mime-button-map
16409b0b
GM
5829 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5830 face ,gnus-article-button-face
16409b0b
GM
5831 gnus-part ,id
5832 gnus-data ,handle))
5833 (widget-convert-button 'link from (point)
5834 :action 'gnus-widget-press-button
5835 :button-keymap gnus-widget-button-keymap)
5836 (insert " "))
5837 (insert "\n\n"))
5838 (when preferred
5839 (if (stringp (car preferred))
5840 (gnus-display-mime preferred)
5841 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 5842 (mail-parse-ignored-charsets
01c52d31
MB
5843 (with-current-buffer gnus-summary-buffer
5844 gnus-newsgroup-ignored-charsets)))
16409b0b
GM
5845 (mm-display-part preferred)
5846 ;; Do highlighting.
5847 (save-excursion
5848 (save-restriction
5849 (narrow-to-region (car begend) (point-max))
5850 (gnus-treat-article
5851 nil (length gnus-article-mime-handle-alist)
e0bad764 5852 (gnus-article-mime-total-parts)
16409b0b
GM
5853 (mm-handle-media-type handle))))))
5854 (goto-char (point-max))
5855 (setcdr begend (point-marker)))))
5856 (when ibegend
5857 (goto-char point))))
5858
23f87bed
MB
5859(defconst gnus-article-wash-status-strings
5860 (let ((alist '((cite "c" "Possible hidden citation text"
5861 " " "All citation text visible")
5862 (headers "h" "Hidden headers"
5863 " " "All headers visible.")
5864 (pgp "p" "Encrypted or signed message status hidden"
5865 " " "No hidden encryption nor digital signature status")
5866 (signature "s" "Signature has been hidden"
5867 " " "Signature is visible")
5868 (overstrike "o" "Overstrike (^H) characters applied"
5869 " " "No overstrike characters applied")
5870 (emphasis "e" "/*_Emphasis_*/ characters applied"
5871 " " "No /*_emphasis_*/ characters applied")))
5872 result)
5873 (dolist (entry alist result)
5874 (let ((key (nth 0 entry))
5875 (on (copy-sequence (nth 1 entry)))
5876 (on-help (nth 2 entry))
5877 (off (copy-sequence (nth 3 entry)))
5878 (off-help (nth 4 entry)))
5879 (put-text-property 0 1 'help-echo on-help on)
5880 (put-text-property 0 1 'help-echo off-help off)
5881 (push (list key on off) result))))
5882 "Alist of strings describing wash status in the mode line.
5883Each entry has the form (KEY ON OF), where the KEY is a symbol
5884representing the particular washing function, ON is the string to use
5885in the article mode line when the washing function is active, and OFF
5886is the string to use when it is inactive.")
5887
5888(defun gnus-article-wash-status-entry (key value)
5889 (let ((entry (assoc key gnus-article-wash-status-strings)))
5890 (if value (nth 1 entry) (nth 2 entry))))
5891
eec82323
LMI
5892(defun gnus-article-wash-status ()
5893 "Return a string which display status of article washing."
01c52d31 5894 (with-current-buffer gnus-article-buffer
16409b0b
GM
5895 (let ((cite (memq 'cite gnus-article-wash-types))
5896 (headers (memq 'headers gnus-article-wash-types))
5897 (boring (memq 'boring-headers gnus-article-wash-types))
5898 (pgp (memq 'pgp gnus-article-wash-types))
5899 (pem (memq 'pem gnus-article-wash-types))
23f87bed
MB
5900 (signed (memq 'signed gnus-article-wash-types))
5901 (encrypted (memq 'encrypted gnus-article-wash-types))
16409b0b
GM
5902 (signature (memq 'signature gnus-article-wash-types))
5903 (overstrike (memq 'overstrike gnus-article-wash-types))
5904 (emphasis (memq 'emphasis gnus-article-wash-types)))
23f87bed
MB
5905 (concat
5906 (gnus-article-wash-status-entry 'cite cite)
5907 (gnus-article-wash-status-entry 'headers (or headers boring))
5908 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5909 (gnus-article-wash-status-entry 'signature signature)
5910 (gnus-article-wash-status-entry 'overstrike overstrike)
5911 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5912
5913(defun gnus-add-wash-type (type)
5914 "Add a washing of TYPE to the current status."
5915 (add-to-list 'gnus-article-wash-types type))
5916
5917(defun gnus-delete-wash-type (type)
5918 "Add a washing of TYPE to the current status."
5919 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5920
5921(defun gnus-add-image (category image)
5922 "Add IMAGE of CATEGORY to the list of displayed images."
5923 (let ((entry (assq category gnus-article-image-alist)))
5924 (unless entry
5925 (setq entry (list category))
5926 (push entry gnus-article-image-alist))
5927 (nconc entry (list image))))
5928
5929(defun gnus-delete-images (category)
5930 "Delete all images in CATEGORY."
5931 (let ((entry (assq category gnus-article-image-alist)))
5932 (dolist (image (cdr entry))
5933 (gnus-remove-image image category))
5934 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5935 (gnus-delete-wash-type category)))
eec82323 5936
16409b0b 5937(defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6748645f
LMI
5938
5939(defun gnus-article-maybe-hide-headers ()
eec82323
LMI
5940 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5941Provided for backwards compatibility."
16409b0b 5942 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
01c52d31
MB
5943 (not (with-current-buffer gnus-summary-buffer
5944 gnus-have-all-headers)))
16409b0b
GM
5945 (not gnus-inhibit-hiding))
5946 (gnus-article-hide-headers)))
eec82323
LMI
5947
5948;;; Article savers.
5949
5950(defun gnus-output-to-file (file-name)
26c9afc3
MB
5951 "Append the current article to a file named FILE-NAME.
5952If `gnus-article-save-coding-system' is non-nil, it is used to encode
5953text and used as the value of the coding cookie which is added to the
5954top of a file. Otherwise, this function saves a raw article without
5955the coding cookie."
5956 (let* ((artbuf (current-buffer))
5957 (file-name-coding-system nnmail-pathname-coding-system)
5958 (coding gnus-article-save-coding-system)
5959 (coding-system-for-read (if coding
5960 nil ;; Rely on the coding cookie.
5961 mm-text-coding-system))
5962 (coding-system-for-write (or coding
5963 mm-text-coding-system-for-write
5964 mm-text-coding-system))
5965 (exists (file-exists-p file-name)))
16409b0b 5966 (with-temp-buffer
26c9afc3
MB
5967 (when exists
5968 (insert-file-contents file-name)
5969 (goto-char (point-min))
5970 ;; Remove the existing coding cookie.
5971 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5972 (delete-region (match-beginning 0) (match-end 0))))
5973 (goto-char (point-max))
eec82323
LMI
5974 (insert-buffer-substring artbuf)
5975 ;; Append newline at end of the buffer as separator, and then
5976 ;; save it to file.
5977 (goto-char (point-max))
5978 (insert "\n")
26c9afc3
MB
5979 (when coding
5980 ;; If the coding system is not suitable to encode the text,
5981 ;; ask a user for a proper one.
5982 (when (fboundp 'select-safe-coding-system)
5983 (setq coding (coding-system-base
5984 (save-window-excursion
5985 (select-safe-coding-system (point-min) (point-max)
5986 coding))))
5987 (setq coding-system-for-write
5988 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5989 coding)))
5990 (goto-char (point-min))
5991 ;; Add the coding cookie.
5992 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5993 coding-system-for-write)))
5994 (if exists
5995 (progn
5996 (write-region (point-min) (point-max) file-name nil 'no-message)
5997 (message "Appended to %s" file-name))
5998 (write-region (point-min) (point-max) file-name))))
5999 t)
eec82323
LMI
6000
6001(defun gnus-narrow-to-page (&optional arg)
6002 "Narrow the article buffer to a page.
6003If given a numerical ARG, move forward ARG pages."
6004 (interactive "P")
6005 (setq arg (if arg (prefix-numeric-value arg) 0))
6006 (save-excursion
6007 (set-buffer gnus-article-buffer)
6008 (goto-char (point-min))
6009 (widen)
6010 ;; Remove any old next/prev buttons.
6011 (when (gnus-visual-p 'page-marker)
4e7d0221 6012 (let ((inhibit-read-only t))
eec82323
LMI
6013 (gnus-remove-text-with-property 'gnus-prev)
6014 (gnus-remove-text-with-property 'gnus-next)))
23f87bed 6015 (if
eec82323
LMI
6016 (cond ((< arg 0)
6017 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
6018 ((> arg 0)
6019 (re-search-forward page-delimiter nil 'move arg)))
23f87bed 6020 (goto-char (match-end 0))
eec82323
LMI
6021 (save-excursion
6022 (goto-char (point-min))
23f87bed
MB
6023 (setq gnus-page-broken
6024 (and (re-search-forward page-delimiter nil t) t))))
6025 (when gnus-page-broken
6026 (narrow-to-region
6027 (point)
6028 (if (re-search-forward page-delimiter nil 'move)
6029 (match-beginning 0)
6030 (point)))
6031 (when (and (gnus-visual-p 'page-marker)
6032 (> (point-min) (save-restriction (widen) (point-min))))
6033 (save-excursion
6034 (goto-char (point-min))
6035 (gnus-insert-prev-page-button)))
6036 (when (and (gnus-visual-p 'page-marker)
45893b95 6037 (< (point-max) (save-restriction (widen) (point-max))))
23f87bed
MB
6038 (save-excursion
6039 (goto-char (point-max))
6040 (gnus-insert-next-page-button))))))
eec82323
LMI
6041
6042;; Article mode commands
6043
6044(defun gnus-article-goto-next-page ()
6045 "Show the next page of the article."
6046 (interactive)
6047 (when (gnus-article-next-page)
6048 (goto-char (point-min))
6049 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6050
23f87bed 6051
eec82323 6052(defun gnus-article-goto-prev-page ()
23f87bed 6053 "Show the previous page of the article."
eec82323 6054 (interactive)
23f87bed
MB
6055 (if (bobp)
6056 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
eec82323
LMI
6057 (gnus-article-prev-page nil)))
6058
23f87bed
MB
6059;; This is cleaner but currently breaks `gnus-pick-mode':
6060;;
6061;; (defun gnus-article-goto-next-page ()
6062;; "Show the next page of the article."
6063;; (interactive)
6064;; (gnus-eval-in-buffer-window gnus-summary-buffer
6065;; (gnus-summary-next-page)))
6066;;
6067;; (defun gnus-article-goto-prev-page ()
6068;; "Show the next page of the article."
6069;; (interactive)
6070;; (gnus-eval-in-buffer-window gnus-summary-buffer
6071;; (gnus-summary-prev-page)))
6072
eec82323
LMI
6073(defun gnus-article-next-page (&optional lines)
6074 "Show the next page of the current article.
6075If end of article, return non-nil. Otherwise return nil.
6076Argument LINES specifies lines to be scrolled up."
6077 (interactive "p")
d8a88581 6078 (move-to-window-line -1)
60ece9b0
MB
6079 (if (and (not (and gnus-article-over-scroll
6080 (> (count-lines (window-start) (point-max))
6081 (+ (or lines (1- (window-height)))
6082 (or (and (boundp 'scroll-margin)
6083 (symbol-value 'scroll-margin))
6084 0)))))
6085 (save-excursion
6086 (end-of-line)
6087 (and (pos-visible-in-window-p) ;Not continuation line.
6088 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
eec82323
LMI
6089 ;; Nothing in this page.
6090 (if (or (not gnus-page-broken)
6091 (save-excursion
6092 (save-restriction
23f87bed
MB
6093 (widen)
6094 (forward-line)
6095 (eobp)))) ;Real end-of-buffer?
6096 (progn
6097 (when gnus-article-over-scroll
6098 (gnus-article-next-page-1 lines))
6099 t) ;Nothing more.
eec82323
LMI
6100 (gnus-narrow-to-page 1) ;Go to next page.
6101 nil)
6102 ;; More in this page.
23f87bed 6103 (gnus-article-next-page-1 lines)
eec82323
LMI
6104 nil))
6105
d8a88581
MB
6106(defmacro gnus-article-beginning-of-window ()
6107 "Move point to the beginning of the window.
6108In Emacs, the point is placed at the line number which `scroll-margin'
6109specifies."
6110 (if (featurep 'xemacs)
6111 '(move-to-window-line 0)
6112 '(move-to-window-line
6113 (min (max 0 scroll-margin)
6114 (max 1 (- (window-height)
6115 (if mode-line-format 1 0)
01c52d31 6116 (if header-line-format 1 0)))))))
d8a88581 6117
23f87bed 6118(defun gnus-article-next-page-1 (lines)
4b91459a
MB
6119 (when (and (not (featurep 'xemacs))
6120 (numberp lines)
6121 (> lines 0)
6122 (numberp (symbol-value 'scroll-margin))
6123 (> (symbol-value 'scroll-margin) 0))
6124 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
6125 ;; too many number of lines if `scroll-margin' is set as two or greater.
6126 (setq lines (min lines
6127 (max 0 (- (count-lines (window-start) (point-max))
6128 (symbol-value 'scroll-margin))))))
6129 (condition-case ()
6130 (let ((scroll-in-place nil))
6131 (scroll-up lines))
6132 (end-of-buffer
6133 ;; Long lines may cause an end-of-buffer error.
6134 (goto-char (point-max))))
6135 (gnus-article-beginning-of-window))
23f87bed 6136
eec82323
LMI
6137(defun gnus-article-prev-page (&optional lines)
6138 "Show previous page of current article.
6139Argument LINES specifies lines to be scrolled down."
6140 (interactive "p")
d8a88581 6141 (move-to-window-line 0)
eec82323
LMI
6142 (if (and gnus-page-broken
6143 (bobp)
6144 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6145 (progn
6146 (gnus-narrow-to-page -1) ;Go to previous page.
6147 (goto-char (point-max))
60ece9b0
MB
6148 (recenter (if gnus-article-over-scroll
6149 (if lines
6150 (max (+ lines (or (and (boundp 'scroll-margin)
6151 (symbol-value 'scroll-margin))
6152 0))
6153 3)
6154 (- (window-height) 2))
6155 -1)))
c03ac728
MB
6156 (prog1
6157 (condition-case ()
6158 (let ((scroll-in-place nil))
6159 (scroll-down lines))
6160 (beginning-of-buffer
6161 (goto-char (point-min))))
6162 (gnus-article-beginning-of-window))))
eec82323 6163
23f87bed
MB
6164(defun gnus-article-only-boring-p ()
6165 "Decide whether there is only boring text remaining in the article.
6166Something \"interesting\" is a word of at least two letters that does
6167not have a face in `gnus-article-boring-faces'."
6168 (when (and gnus-article-skip-boring
6169 (boundp 'gnus-article-boring-faces)
6170 (symbol-value 'gnus-article-boring-faces))
6171 (save-excursion
531bedc3
MB
6172 (let ((inhibit-point-motion-hooks t))
6173 (catch 'only-boring
6174 (while (re-search-forward "\\b\\w\\w" nil t)
6175 (forward-char -1)
6176 (when (not (gnus-intersection
6177 (gnus-faces-at (point))
6178 (symbol-value 'gnus-article-boring-faces)))
6179 (throw 'only-boring nil)))
6180 (throw 'only-boring t))))))
23f87bed 6181
eec82323
LMI
6182(defun gnus-article-refer-article ()
6183 "Read article specified by message-id around point."
6184 (interactive)
23f87bed 6185 (save-excursion
01c52d31
MB
6186 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6187 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6188 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
23f87bed 6189 (let ((msg-id (concat "<" (match-string 0) ">")))
eec82323 6190 (set-buffer gnus-summary-buffer)
23f87bed 6191 (gnus-summary-refer-article msg-id))
eec82323
LMI
6192 (error "No references around point"))))
6193
6194(defun gnus-article-show-summary ()
6195 "Reconfigure windows to show summary buffer."
6196 (interactive)
6197 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6198 (error "There is no summary buffer for this article buffer")
a8151ef7 6199 (gnus-article-set-globals)
eec82323 6200 (gnus-configure-windows 'article)
6748645f
LMI
6201 (gnus-summary-goto-subject gnus-current-article)
6202 (gnus-summary-position-point)))
eec82323
LMI
6203
6204(defun gnus-article-describe-briefly ()
6205 "Describe article mode commands briefly."
6206 (interactive)
16409b0b 6207 (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
6208
6209(defun gnus-article-summary-command ()
6210 "Execute the last keystroke in the summary buffer."
6211 (interactive)
6212 (let ((obuf (current-buffer))
6213 (owin (current-window-configuration))
6214 func)
6748645f 6215 (switch-to-buffer gnus-article-current-summary 'norecord)
eec82323
LMI
6216 (setq func (lookup-key (current-local-map) (this-command-keys)))
6217 (call-interactively func)
6218 (set-buffer obuf)
6219 (set-window-configuration owin)
6220 (set-window-point (get-buffer-window (current-buffer)) (point))))
6221
6222(defun gnus-article-summary-command-nosave ()
6223 "Execute the last keystroke in the summary buffer."
6224 (interactive)
6225 (let (func)
bdaf8a62 6226 (pop-to-buffer gnus-article-current-summary)
eec82323
LMI
6227 (setq func (lookup-key (current-local-map) (this-command-keys)))
6228 (call-interactively func)))
6229
16409b0b
GM
6230(defun gnus-article-check-buffer ()
6231 "Beep if not in an article buffer."
6232 (unless (equal major-mode 'gnus-article-mode)
6233 (error "Command invoked outside of a Gnus article buffer")))
6234
eec82323
LMI
6235(defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6236 "Read a summary buffer key sequence and execute it from the article buffer."
6237 (interactive "P")
16409b0b 6238 (gnus-article-check-buffer)
eec82323 6239 (let ((nosaves
23f87bed
MB
6240 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6241 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6242 "=" "^" "\M-^" "|"))
6243 (nosave-but-article
6244 '("A\r"))
6245 (nosave-in-article
6246 '("\C-d"))
6247 (up-to-top
6248 '("n" "Gn" "p" "Gp"))
6249 keys new-sum-point)
eec82323 6250 (save-excursion
6748645f 6251 (set-buffer gnus-article-current-summary)
eec82323 6252 (let (gnus-pick-mode)
95838435
MB
6253 (setq unread-command-events (nconc unread-command-events
6254 (list (or key last-command-event)))
6255 keys (if (featurep 'xemacs)
6256 (events-to-keys (read-key-sequence nil t))
6257 (read-key-sequence nil t)))))
a1506d29 6258
eec82323
LMI
6259 (message "")
6260
01c52d31
MB
6261 (cond
6262 ((eq (aref keys (1- (length keys))) ?\C-h)
95838435
MB
6263 (if (featurep 'xemacs)
6264 (let ((keymap (with-current-buffer gnus-article-current-summary
6265 (copy-keymap (current-local-map)))))
6266 (map-keymap
6267 (lambda (key def)
6268 (define-key keymap (vector ?S key) def))
6269 gnus-article-send-map)
6270 (with-temp-buffer
6271 (setq major-mode 'gnus-article-mode)
6272 (use-local-map keymap)
6273 (describe-bindings (substring keys 0 -1))))
6274 (let ((keymap (make-sparse-keymap))
6275 (map (copy-keymap gnus-article-send-map)))
6276 (define-key keymap "S" map)
6277 (define-key map [t] nil)
6278 (set-keymap-parent keymap
6279 (with-current-buffer gnus-article-current-summary
6280 (current-local-map)))
6281 (with-temp-buffer
6282 (use-local-map keymap)
6283 (describe-bindings (substring keys 0 -1))))))
01c52d31
MB
6284 ((or (member keys nosaves)
6285 (member keys nosave-but-article)
6286 (member keys nosave-in-article))
6287 (let (func)
6288 (save-window-excursion
6289 (pop-to-buffer gnus-article-current-summary)
6290 ;; We disable the pick minor mode commands.
6291 (let (gnus-pick-mode)
6292 (setq func (lookup-key (current-local-map) keys))))
6293 (if (or (not func)
6294 (numberp func))
6295 (ding)
6296 (unless (member keys nosave-in-article)
6297 (set-buffer gnus-article-current-summary))
6298 (call-interactively func)
6299 (setq new-sum-point (point)))
6300 (when (member keys nosave-but-article)
6301 (pop-to-buffer gnus-article-buffer))))
6302 (t
eec82323
LMI
6303 ;; These commands should restore window configuration.
6304 (let ((obuf (current-buffer))
23f87bed 6305 (owin (current-window-configuration))
01c52d31 6306 win func in-buffer selected new-sum-start new-sum-hscroll err)
23f87bed 6307 (cond (not-restore-window
01c52d31
MB
6308 (pop-to-buffer gnus-article-current-summary)
6309 (setq win (selected-window)))
23f87bed
MB
6310 ((setq win (get-buffer-window gnus-article-current-summary))
6311 (select-window win))
6312 (t
01c52d31
MB
6313 (let ((summary-buffer gnus-article-current-summary))
6314 (gnus-configure-windows 'article)
6315 (unless (setq win (get-buffer-window summary-buffer 'visible))
6316 (let ((gnus-buffer-configuration
6317 '(article ((vertical 1.0
6318 (summary 0.25 point)
6319 (article 1.0))))))
6320 (gnus-configure-windows 'article))
6321 (setq win (get-buffer-window summary-buffer 'visible)))
6322 (gnus-select-frame-set-input-focus (window-frame win))
6323 (select-window win))))
23f87bed
MB
6324 (setq in-buffer (current-buffer))
6325 ;; We disable the pick minor mode commands.
6326 (if (and (setq func (let (gnus-pick-mode)
520aa572 6327 (lookup-key (current-local-map) keys)))
01c52d31
MB
6328 (functionp func)
6329 (condition-case code
6330 (progn
6331 (call-interactively func)
6332 t)
6333 (error
6334 (setq err code)
6335 nil)))
23f87bed 6336 (progn
23f87bed
MB
6337 (when (eq win (selected-window))
6338 (setq new-sum-point (point)
6339 new-sum-start (window-start win)
9a89f5b0 6340 new-sum-hscroll (window-hscroll win)))
01c52d31
MB
6341 (when (or (eq in-buffer (current-buffer))
6342 (when (eq obuf (current-buffer))
6343 (set-buffer in-buffer)
6344 t))
520aa572
SZ
6345 (setq selected (gnus-summary-select-article))
6346 (set-buffer obuf)
6347 (unless not-restore-window
6348 (set-window-configuration owin))
01c52d31
MB
6349 (when (and (eq selected 'old)
6350 new-sum-point)
520aa572
SZ
6351 (set-window-start (get-buffer-window (current-buffer))
6352 1)
6353 (set-window-point (get-buffer-window (current-buffer))
01c52d31
MB
6354 (if (article-goto-body)
6355 (1- (point))
6356 (point))))
23f87bed 6357 (when (and (not not-restore-window)
01c52d31
MB
6358 new-sum-point
6359 (with-current-buffer (window-buffer win)
6360 (eq major-mode 'gnus-summary-mode)))
23f87bed
MB
6361 (set-window-point win new-sum-point)
6362 (set-window-start win new-sum-start)
9a89f5b0 6363 (set-window-hscroll win new-sum-hscroll))))
23f87bed 6364 (set-window-configuration owin)
01c52d31
MB
6365 (if err
6366 (signal (car err) (cdr err))
6367 (ding))))))))
520aa572 6368
95838435
MB
6369(defun gnus-article-read-summary-send-keys ()
6370 (interactive)
6371 (let ((unread-command-events (list (if (featurep 'xemacs)
6372 (character-to-event ?S)
6373 ?S))))
6374 (gnus-article-read-summary-keys)))
6375
520aa572 6376(defun gnus-article-describe-key (key)
95838435
MB
6377 "Display documentation of the function invoked by KEY.
6378KEY is a string or a vector."
6379 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6380 (read-key-sequence "Describe key: "))))
520aa572 6381 (gnus-article-check-buffer)
95838435
MB
6382 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6383 gnus-article-read-summary-send-keys))
520aa572
SZ
6384 (save-excursion
6385 (set-buffer gnus-article-current-summary)
95838435
MB
6386 (setq unread-command-events
6387 (if (featurep 'xemacs)
6388 (append key nil)
6389 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6390 (list 'meta (- x 128))
6391 x))
6392 key)))
6393 (let ((cursor-in-echo-area t)
6394 gnus-pick-mode)
6395 (describe-key (read-key-sequence nil t))))
520aa572
SZ
6396 (describe-key key)))
6397
6398(defun gnus-article-describe-key-briefly (key &optional insert)
95838435
MB
6399 "Display documentation of the function invoked by KEY.
6400KEY is a string or a vector."
6401 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6402 (read-key-sequence "Describe key: "))
6403 current-prefix-arg))
520aa572 6404 (gnus-article-check-buffer)
95838435
MB
6405 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6406 gnus-article-read-summary-send-keys))
520aa572
SZ
6407 (save-excursion
6408 (set-buffer gnus-article-current-summary)
95838435
MB
6409 (setq unread-command-events
6410 (if (featurep 'xemacs)
6411 (append key nil)
6412 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6413 (list 'meta (- x 128))
6414 x))
6415 key)))
6416 (let ((cursor-in-echo-area t)
6417 gnus-pick-mode)
6418 (describe-key-briefly (read-key-sequence nil t) insert)))
520aa572 6419 (describe-key-briefly key insert)))
eec82323 6420
23f87bed
MB
6421(defun gnus-article-reply-with-original (&optional wide)
6422 "Start composing a reply mail to the current message.
6423The text in the region will be yanked. If the region isn't active,
6424the entire article will be yanked."
95838435 6425 (interactive)
23f87bed
MB
6426 (let ((article (cdr gnus-article-current))
6427 contents)
1d0df8af 6428 (if (not (gnus-region-active-p))
23f87bed
MB
6429 (with-current-buffer gnus-summary-buffer
6430 (gnus-summary-reply (list (list article)) wide))
6431 (setq contents (buffer-substring (point) (mark t)))
6432 ;; Deactivate active regions.
6433 (when (and (boundp 'transient-mark-mode)
6434 transient-mark-mode)
6435 (setq mark-active nil))
6436 (with-current-buffer gnus-summary-buffer
6437 (gnus-summary-reply
6438 (list (list article contents)) wide)))))
6439
95838435
MB
6440(defun gnus-article-wide-reply-with-original ()
6441 "Start composing a wide reply mail to the current message.
6442The text in the region will be yanked. If the region isn't active,
6443the entire article will be yanked."
6444 (interactive)
6445 (gnus-article-reply-with-original t))
6446
23f87bed
MB
6447(defun gnus-article-followup-with-original ()
6448 "Compose a followup to the current article.
6449The text in the region will be yanked. If the region isn't active,
6450the entire article will be yanked."
6451 (interactive)
6452 (let ((article (cdr gnus-article-current))
6453 contents)
1d0df8af 6454 (if (not (gnus-region-active-p))
23f87bed
MB
6455 (with-current-buffer gnus-summary-buffer
6456 (gnus-summary-followup (list (list article))))
6457 (setq contents (buffer-substring (point) (mark t)))
6458 ;; Deactivate active regions.
6459 (when (and (boundp 'transient-mark-mode)
6460 transient-mark-mode)
6461 (setq mark-active nil))
6462 (with-current-buffer gnus-summary-buffer
6463 (gnus-summary-followup
6464 (list (list article contents)))))))
6465
eec82323
LMI
6466(defun gnus-article-hide (&optional arg force)
6467 "Hide all the gruft in the current article.
23f87bed
MB
6468This means that signatures, cited text and (some) headers will be
6469hidden.
eec82323 6470If given a prefix, show the hidden text instead."
6748645f 6471 (interactive (append (gnus-article-hidden-arg) (list 'force)))
eec82323 6472 (gnus-article-hide-headers arg)
16409b0b 6473 (gnus-article-hide-list-identifiers arg)
eec82323
LMI
6474 (gnus-article-hide-citation-maybe arg force)
6475 (gnus-article-hide-signature arg))
6476
6477(defun gnus-article-maybe-highlight ()
6748645f 6478 "Do some article highlighting if article highlighting is requested."
eec82323
LMI
6479 (when (gnus-visual-p 'article-highlight 'highlight)
6480 (gnus-article-highlight-some)))
6481
6748645f
LMI
6482(defun gnus-check-group-server ()
6483 ;; Make sure the connection to the server is alive.
6484 (unless (gnus-server-opened
6485 (gnus-find-method-for-group gnus-newsgroup-name))
6486 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6487 (gnus-request-group gnus-newsgroup-name t)))
6488
23f87bed
MB
6489(eval-when-compile
6490 (autoload 'nneething-get-file-name "nneething"))
6491
eec82323
LMI
6492(defun gnus-request-article-this-buffer (article group)
6493 "Get an article and insert it into this buffer."
6748645f 6494 (let (do-update-line sparse-header)
eec82323
LMI
6495 (prog1
6496 (save-excursion
6497 (erase-buffer)
6498 (gnus-kill-all-overlays)
6499 (setq group (or group gnus-newsgroup-name))
6500
eec82323
LMI
6501 ;; Using `gnus-request-article' directly will insert the article into
6502 ;; `nntp-server-buffer' - so we'll save some time by not having to
6503 ;; copy it from the server buffer into the article buffer.
6504
6505 ;; We only request an article by message-id when we do not have the
6506 ;; headers for it, so we'll have to get those.
6507 (when (stringp article)
16409b0b 6508 (gnus-read-header article))
eec82323
LMI
6509
6510 ;; If the article number is negative, that means that this article
6511 ;; doesn't belong in this newsgroup (possibly), so we find its
6512 ;; message-id and request it by id instead of number.
6513 (when (and (numberp article)
6514 gnus-summary-buffer
6515 (get-buffer gnus-summary-buffer)
6748645f 6516 (gnus-buffer-exists-p gnus-summary-buffer))
eec82323
LMI
6517 (save-excursion
6518 (set-buffer gnus-summary-buffer)
6519 (let ((header (gnus-summary-article-header article)))
6520 (when (< article 0)
6521 (cond
6522 ((memq article gnus-newsgroup-sparse)
6523 ;; This is a sparse gap article.
6524 (setq do-update-line article)
6525 (setq article (mail-header-id header))
16409b0b 6526 (setq sparse-header (gnus-read-header article))
eec82323
LMI
6527 (setq gnus-newsgroup-sparse
6528 (delq article gnus-newsgroup-sparse)))
6529 ((vectorp header)
6530 ;; It's a real article.
6531 (setq article (mail-header-id header)))
6532 (t
6533 ;; It is an extracted pseudo-article.
6534 (setq article 'pseudo)
6535 (gnus-request-pseudo-article header))))
6536
6537 (let ((method (gnus-find-method-for-group
6538 gnus-newsgroup-name)))
6748645f
LMI
6539 (when (and (eq (car method) 'nneething)
6540 (vectorp header))
23f87bed
MB
6541 (let ((dir (nneething-get-file-name
6542 (mail-header-id header))))
6543 (when (and (stringp dir)
6544 (file-directory-p dir))
eec82323
LMI
6545 (setq article 'nneething)
6546 (gnus-group-enter-directory dir))))))))
6547
6548 (cond
6549 ;; Refuse to select canceled articles.
6550 ((and (numberp article)
6551 gnus-summary-buffer
6552 (get-buffer gnus-summary-buffer)
6748645f 6553 (gnus-buffer-exists-p gnus-summary-buffer)
01c52d31 6554 (eq (cdr (with-current-buffer gnus-summary-buffer
eec82323
LMI
6555 (assq article gnus-newsgroup-reads)))
6556 gnus-canceled-mark))
6557 nil)
6558 ;; We first check `gnus-original-article-buffer'.
6559 ((and (get-buffer gnus-original-article-buffer)
6560 (numberp article)
01c52d31 6561 (with-current-buffer gnus-original-article-buffer
eec82323
LMI
6562 (and (equal (car gnus-original-article) group)
6563 (eq (cdr gnus-original-article) article))))
6564 (insert-buffer-substring gnus-original-article-buffer)
6565 'article)
6566 ;; Check the backlog.
6567 ((and gnus-keep-backlog
6568 (gnus-backlog-request-article group article (current-buffer)))
6569 'article)
6570 ;; Check asynchronous pre-fetch.
6571 ((gnus-async-request-fetched-article group article (current-buffer))
6572 (gnus-async-prefetch-next group article gnus-summary-buffer)
6748645f
LMI
6573 (when (and (numberp article) gnus-keep-backlog)
6574 (gnus-backlog-enter-article group article (current-buffer)))
eec82323
LMI
6575 'article)
6576 ;; Check the cache.
6577 ((and gnus-use-cache
6578 (numberp article)
6579 (gnus-cache-request-article article group))
6580 'article)
23f87bed
MB
6581 ;; Check the agent cache.
6582 ((gnus-agent-request-article article group)
6583 'article)
eec82323 6584 ;; Get the article and put into the article buffer.
16409b0b
GM
6585 ((or (stringp article)
6586 (numberp article))
6587 (let ((gnus-override-method gnus-override-method)
a1506d29 6588 (methods (and (stringp article)
16409b0b 6589 gnus-refer-article-method))
23f87bed
MB
6590 (backend (car (gnus-find-method-for-group
6591 gnus-newsgroup-name)))
16409b0b 6592 result
4e7d0221 6593 (inhibit-read-only t))
e0bad764
DL
6594 (if (or (not (listp methods))
6595 (and (symbolp (car methods))
6596 (assq (car methods) nnoo-definition-alist)))
6597 (setq methods (list methods)))
16409b0b
GM
6598 (when (and (null gnus-override-method)
6599 methods)
6600 (setq gnus-override-method (pop methods)))
6601 (while (not result)
6602 (when (eq gnus-override-method 'current)
c55f89a5
GM
6603 (setq gnus-override-method
6604 (with-current-buffer gnus-summary-buffer
6605 gnus-current-select-method)))
16409b0b
GM
6606 (erase-buffer)
6607 (gnus-kill-all-overlays)
6608 (let ((gnus-newsgroup-name group))
6609 (gnus-check-group-server))
23f87bed
MB
6610 (cond
6611 ((gnus-request-article article group (current-buffer))
16409b0b 6612 (when (numberp article)
a1506d29 6613 (gnus-async-prefetch-next group article
16409b0b
GM
6614 gnus-summary-buffer)
6615 (when gnus-keep-backlog
6616 (gnus-backlog-enter-article
6617 group article (current-buffer))))
6618 (setq result 'article))
23f87bed
MB
6619 (methods
6620 (setq gnus-override-method (pop methods)))
6621 ((not (string-match "^400 "
6622 (nnheader-get-report backend)))
6623 ;; If we get 400 server disconnect, reconnect and
6624 ;; retry; otherwise, assume the article has expired.
6625 (setq result 'done))))
16409b0b 6626 (and (eq result 'article) 'article)))
eec82323
LMI
6627 ;; It was a pseudo.
6628 (t article)))
6629
6748645f
LMI
6630 ;; Associate this article with the current summary buffer.
6631 (setq gnus-article-current-summary gnus-summary-buffer)
6632
eec82323
LMI
6633 ;; Take the article from the original article buffer
6634 ;; and place it in the buffer it's supposed to be in.
6635 (when (and (get-buffer gnus-article-buffer)
eec82323
LMI
6636 (equal (buffer-name (current-buffer))
6637 (buffer-name (get-buffer gnus-article-buffer))))
6638 (save-excursion
6639 (if (get-buffer gnus-original-article-buffer)
6748645f
LMI
6640 (set-buffer gnus-original-article-buffer)
6641 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 6642 (buffer-disable-undo)
eec82323 6643 (setq major-mode 'gnus-original-article-mode)
6748645f 6644 (setq buffer-read-only t))
23f87bed 6645 (let ((inhibit-read-only t))
eec82323
LMI
6646 (erase-buffer)
6647 (insert-buffer-substring gnus-article-buffer))
16409b0b
GM
6648 (setq gnus-original-article (cons group article)))
6649
6650 ;; Decode charsets.
6651 (run-hooks 'gnus-article-decode-hook)
6652 ;; Mark article as decoded or not.
6653 (setq gnus-article-decoded-p gnus-article-decode-hook))
eec82323
LMI
6654
6655 ;; Update sparse articles.
6656 (when (and do-update-line
6657 (or (numberp article)
6658 (stringp article)))
6659 (let ((buf (current-buffer)))
6660 (set-buffer gnus-summary-buffer)
6748645f 6661 (gnus-summary-update-article do-update-line sparse-header)
eec82323 6662 (gnus-summary-goto-subject do-update-line nil t)
23f87bed 6663 (set-window-point (gnus-get-buffer-window (current-buffer) t)
eec82323
LMI
6664 (point))
6665 (set-buffer buf))))))
6666
6667;;;
6668;;; Article editing
6669;;;
6670
6671(defcustom gnus-article-edit-mode-hook nil
6672 "Hook run in article edit mode buffers."
6673 :group 'gnus-article-various
6674 :type 'hook)
6675
6676(defvar gnus-article-edit-done-function nil)
6677
6678(defvar gnus-article-edit-mode-map nil)
6679
16409b0b 6680;; Should we be using derived.el for this?
eec82323 6681(unless gnus-article-edit-mode-map
23f87bed 6682 (setq gnus-article-edit-mode-map (make-keymap))
16409b0b 6683 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
eec82323
LMI
6684
6685 (gnus-define-keys gnus-article-edit-mode-map
23f87bed 6686 "\C-c?" describe-mode
eec82323 6687 "\C-c\C-c" gnus-article-edit-done
23f87bed
MB
6688 "\C-c\C-k" gnus-article-edit-exit
6689 "\C-c\C-f\C-t" message-goto-to
6690 "\C-c\C-f\C-o" message-goto-from
6691 "\C-c\C-f\C-b" message-goto-bcc
6692 ;;"\C-c\C-f\C-w" message-goto-fcc
6693 "\C-c\C-f\C-c" message-goto-cc
6694 "\C-c\C-f\C-s" message-goto-subject
6695 "\C-c\C-f\C-r" message-goto-reply-to
6696 "\C-c\C-f\C-n" message-goto-newsgroups
6697 "\C-c\C-f\C-d" message-goto-distribution
6698 "\C-c\C-f\C-f" message-goto-followup-to
6699 "\C-c\C-f\C-m" message-goto-mail-followup-to
6700 "\C-c\C-f\C-k" message-goto-keywords
6701 "\C-c\C-f\C-u" message-goto-summary
6702 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6703 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6704 "\C-c\C-b" message-goto-body
6705 "\C-c\C-i" message-goto-signature
6706
6707 "\C-c\C-t" message-insert-to
6708 "\C-c\C-n" message-insert-newsgroups
6709 "\C-c\C-o" message-sort-headers
6710 "\C-c\C-e" message-elide-region
6711 "\C-c\C-v" message-delete-not-region
6712 "\C-c\C-z" message-kill-to-signature
6713 "\M-\r" message-newline-and-reformat
6714 "\C-c\C-a" mml-attach-file
6715 "\C-a" message-beginning-of-line
6716 "\t" message-tab
6717 "\M-;" comment-region)
eec82323
LMI
6718
6719 (gnus-define-keys (gnus-article-edit-wash-map
6720 "\C-c\C-w" gnus-article-edit-mode-map)
6721 "f" gnus-article-edit-full-stops))
6722
23f87bed
MB
6723(easy-menu-define
6724 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6725 '("Field"
6726 ["Fetch To" message-insert-to t]
6727 ["Fetch Newsgroups" message-insert-newsgroups t]
6728 "----"
6729 ["To" message-goto-to t]
6730 ["From" message-goto-from t]
6731 ["Subject" message-goto-subject t]
6732 ["Cc" message-goto-cc t]
6733 ["Reply-To" message-goto-reply-to t]
6734 ["Summary" message-goto-summary t]
6735 ["Keywords" message-goto-keywords t]
6736 ["Newsgroups" message-goto-newsgroups t]
6737 ["Followup-To" message-goto-followup-to t]
6738 ["Mail-Followup-To" message-goto-mail-followup-to t]
6739 ["Distribution" message-goto-distribution t]
6740 ["Body" message-goto-body t]
6741 ["Signature" message-goto-signature t]))
6742
4e7d0221 6743(define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
eec82323
LMI
6744 "Major mode for editing articles.
6745This is an extended text-mode.
6746
6747\\{gnus-article-edit-mode-map}"
eec82323
LMI
6748 (make-local-variable 'gnus-article-edit-done-function)
6749 (make-local-variable 'gnus-prev-winconf)
80b47379
SZ
6750 (set (make-local-variable 'font-lock-defaults)
6751 '(message-font-lock-keywords t))
23f87bed
MB
6752 (set (make-local-variable 'mail-header-separator) "")
6753 (set (make-local-variable 'gnus-article-edit-mode) t)
6754 (easy-menu-add message-mode-field-menu message-mode-map)
6755 (mml-mode)
eec82323
LMI
6756 (setq buffer-read-only nil)
6757 (buffer-enable-undo)
80b47379 6758 (widen))
eec82323
LMI
6759
6760(defun gnus-article-edit (&optional force)
6761 "Edit the current article.
6762This will have permanent effect only in mail groups.
6763If FORCE is non-nil, allow editing of articles even in read-only
6764groups."
6765 (interactive "P")
6766 (when (and (not force)
6767 (gnus-group-read-only-p))
a8151ef7 6768 (error "The current newsgroup does not support article editing"))
6748645f 6769 (gnus-article-date-original)
eec82323 6770 (gnus-article-edit-article
16409b0b 6771 'ignore
6748645f 6772 `(lambda (no-highlight)
16409b0b 6773 'ignore
eec82323
LMI
6774 (gnus-summary-edit-article-done
6775 ,(or (mail-header-references gnus-current-headers) "")
6748645f 6776 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
eec82323 6777
01c52d31 6778(defun gnus-article-edit-article (start-func exit-func &optional quiet)
eec82323
LMI
6779 "Start editing the contents of the current article buffer."
6780 (let ((winconf (current-window-configuration)))
6781 (set-buffer gnus-article-buffer)
0683d241
MB
6782 (let ((message-auto-save-directory
6783 ;; Don't associate the article buffer with a draft file.
6784 nil))
6785 (gnus-article-edit-mode))
16409b0b 6786 (funcall start-func)
23f87bed 6787 (set-buffer-modified-p nil)
eec82323
LMI
6788 (gnus-configure-windows 'edit-article)
6789 (setq gnus-article-edit-done-function exit-func)
6790 (setq gnus-prev-winconf winconf)
01c52d31
MB
6791 (unless quiet
6792 (gnus-message 6 "C-c C-c to end edits"))))
eec82323 6793
6748645f 6794(defun gnus-article-edit-done (&optional arg)
eec82323 6795 "Update the article edits and exit."
6748645f 6796 (interactive "P")
eec82323
LMI
6797 (let ((func gnus-article-edit-done-function)
6798 (buf (current-buffer))
23f87bed
MB
6799 (start (window-start))
6800 (p (point))
6801 (winconf gnus-prev-winconf))
6802 (widen) ;; Widen it in case that users narrowed the buffer.
6803 (funcall func arg)
6804 (set-buffer buf)
6805 ;; The cache and backlog have to be flushed somewhat.
6806 (when gnus-keep-backlog
6807 (gnus-backlog-remove-article
6808 (car gnus-article-current) (cdr gnus-article-current)))
6809 ;; Flush original article as well.
eec82323 6810 (save-excursion
23f87bed
MB
6811 (when (get-buffer gnus-original-article-buffer)
6812 (set-buffer gnus-original-article-buffer)
6813 (setq gnus-original-article nil)))
6814 (when gnus-use-cache
6815 (gnus-cache-update-article
6816 (car gnus-article-current) (cdr gnus-article-current)))
6817 ;; We remove all text props from the article buffer.
6818 (kill-all-local-variables)
01c52d31 6819 (set-text-properties (point-min) (point-max) nil)
23f87bed
MB
6820 (gnus-article-mode)
6821 (set-window-configuration winconf)
eec82323
LMI
6822 (set-buffer buf)
6823 (set-window-start (get-buffer-window buf) start)
23f87bed
MB
6824 (set-window-point (get-buffer-window buf) (point)))
6825 (gnus-summary-show-article))
eec82323
LMI
6826
6827(defun gnus-article-edit-exit ()
6828 "Exit the article editing without updating."
6829 (interactive)
23f87bed
MB
6830 (when (or (not (buffer-modified-p))
6831 (yes-or-no-p "Article modified; kill anyway? "))
6832 (let ((curbuf (current-buffer))
6833 (p (point))
6834 (window-start (window-start)))
6835 (erase-buffer)
6836 (if (gnus-buffer-live-p gnus-original-article-buffer)
d8a88581 6837 (insert-buffer-substring gnus-original-article-buffer))
23f87bed
MB
6838 (let ((winconf gnus-prev-winconf))
6839 (kill-all-local-variables)
6840 (gnus-article-mode)
6841 (set-window-configuration winconf)
6842 ;; Tippy-toe some to make sure that point remains where it was.
6843 (save-current-buffer
6844 (set-buffer curbuf)
6845 (set-window-start (get-buffer-window (current-buffer)) window-start)
6846 (goto-char p))))
6847 (gnus-summary-show-article)))
eec82323
LMI
6848
6849(defun gnus-article-edit-full-stops ()
6850 "Interactively repair spacing at end of sentences."
6851 (interactive)
6852 (save-excursion
6853 (goto-char (point-min))
6854 (search-forward-regexp "^$" nil t)
6855 (let ((case-fold-search nil))
6856 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6857
6858;;;
6859;;; Article highlights
6860;;;
6861
6862;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6863
6864;;; Internal Variables:
6865
a1506d29 6866(defcustom gnus-button-url-regexp
01c52d31
MB
6867 (concat
6868 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6869 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6870 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6871 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6872 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6873 (punct "!?:;.,"))
6874 (concat
6875 "\\(?:"
6876 ;; Match paired parentheses, e.g. in Wikipedia URLs:
6877 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6878 "\\|"
6879 "[" chars punct "]+" "[" chars "]"
6880 "\\)"))
6881 (concat ;; XEmacs 21.4 doesn't support POSIX.
6882 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6883 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6884 "\\)")
eec82323
LMI
6885 "Regular expression that matches URLs."
6886 :group 'gnus-article-buttons
6887 :type 'regexp)
6888
23f87bed
MB
6889(defcustom gnus-button-valid-fqdn-regexp
6890 message-valid-fqdn-regexp
6891 "Regular expression that matches a valid FQDN."
bf247b6e 6892 :version "22.1"
23f87bed
MB
6893 :group 'gnus-article-buttons
6894 :type 'regexp)
6895
97f78c9b
MB
6896;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6897(defcustom gnus-button-valid-localpart-regexp
14e6dc54 6898 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
97f78c9b
MB
6899 "Regular expression that matches a localpart of mail addresses or MIDs."
6900 :version "22.1"
6901 :group 'gnus-article-buttons
6902 :type 'regexp)
6903
23f87bed
MB
6904(defcustom gnus-button-man-handler 'manual-entry
6905 "Function to use for displaying man pages.
6906The function must take at least one argument with a string naming the
6907man page."
bf247b6e 6908 :version "22.1"
23f87bed
MB
6909 :type '(choice (function-item :tag "Man" manual-entry)
6910 (function-item :tag "Woman" woman)
6911 (function :tag "Other"))
6912 :group 'gnus-article-buttons)
6913
6914(defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6915 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6916If the default site is too slow, try to find a CTAN mirror, see
6917<URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6918the variable `gnus-button-handle-ctan'."
bf247b6e 6919 :version "22.1"
23f87bed
MB
6920 :group 'gnus-article-buttons
6921 :link '(custom-manual "(gnus)Group Parameters")
6922 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6923 (const "http://tug.ctan.org/tex-archive/")
6924 (const "http://www.dante.de/CTAN/")
6925 (string :tag "Other")))
6926
6927(defcustom gnus-button-ctan-handler 'browse-url
6928 "Function to use for displaying CTAN links.
6929The function must take one argument, the string naming the URL."
bf247b6e 6930 :version "22.1"
23f87bed
MB
6931 :type '(choice (function-item :tag "Browse Url" browse-url)
6932 (function :tag "Other"))
6933 :group 'gnus-article-buttons)
6934
6935(defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6936 "Bogus strings removed from CTAN URLs."
bf247b6e 6937 :version "22.1"
23f87bed
MB
6938 :group 'gnus-article-buttons
6939 :type '(choice (const "^/?tex-archive/\\|/")
6940 (regexp :tag "Other")))
6941
6942(defcustom gnus-button-ctan-directory-regexp
97f78c9b
MB
6943 (regexp-opt
6944 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6945 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6946 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6947 "tds" "tools" "usergrps" "web") t)
23f87bed
MB
6948 "Regular expression for ctan directories.
6949It should match all directories in the top level of `gnus-ctan-url'."
bf247b6e 6950 :version "22.1"
23f87bed
MB
6951 :group 'gnus-article-buttons
6952 :type 'regexp)
6953
6954(defcustom gnus-button-mid-or-mail-regexp
97f78c9b 6955 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
23f87bed
MB
6956 gnus-button-valid-fqdn-regexp
6957 ">?\\)\\b")
6958 "Regular expression that matches a message ID or a mail address."
bf247b6e 6959 :version "22.1"
23f87bed
MB
6960 :group 'gnus-article-buttons
6961 :type 'regexp)
6962
6963(defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6964 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6965Strings like this can be either a message ID or a mail address. If it is one
6966of the symbols `mid' or `mail', Gnus will always assume that the string is a
6967message ID or a mail address, respectively. If this variable is set to the
6968symbol `ask', always query the user what do do. If it is a function, this
aa819354 6969function will be called with the string as its only argument. The function
23f87bed 6970must return `mid', `mail', `invalid' or `ask'."
bf247b6e 6971 :version "22.1"
23f87bed
MB
6972 :group 'gnus-article-buttons
6973 :type '(choice (function-item :tag "Heuristic function"
6974 gnus-button-mid-or-mail-heuristic)
6975 (const ask)
6976 (const mid)
6977 (const mail)))
6978
6979(defcustom gnus-button-mid-or-mail-heuristic-alist
6980 '((-10.0 . ".+\\$.+@")
6981 (-10.0 . "#")
6982 (-10.0 . "\\*")
6983 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6984 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6985 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6986 (-1.0 . "^[^a-z]+@")
6987 ;;
6988 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6989 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6990 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6991 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6992 ;;
6993 (-2.0 . "^[0-9]")
6994 (-1.0 . "^[0-9][0-9]")
6995 ;;
6996 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6997 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6998 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6999 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7000 ;;
7001 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7002 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7003 ;; "[0-9]{8,}.*\@"
7004 (-3.0
7005 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7006 ;; "[0-9]{12,}.*\@"
7007 ;; compensation for TDMA dated mail addresses:
7008 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7009 ;;
7010 (-20.0 . "\\.fsf@") ;; Gnus
7011 (-20.0 . "^slrn")
7012 (-20.0 . "^Pine")
437ce4be 7013 (-20.0 . "^alpine\\.")
23f87bed
MB
7014 (-20.0 . "_-_") ;; Subject change in thread
7015 ;;
7016 (-20.0 . "\\.ln@") ;; leafnode
7017 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7018 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7019 ;;
7020 ;; (5.0 . "") ;; $local_part_len <= 7
7021 (10.0 . "^[^0-9]+@")
7022 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7023 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7024 (3.0 . "\@stud")
7025 ;;
7026 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7027 ;;
7028 (0.5 . "^[A-Z][a-z]")
7029 (0.5 . "^[A-Z][a-z][a-z]")
7030 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7031 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7032 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7033
7034A negative RATE indicates a message IDs, whereas a positive indicates a mail
7035address. The REGEXP is processed with `case-fold-search' set to nil."
bf247b6e 7036 :version "22.1"
23f87bed
MB
7037 :group 'gnus-article-buttons
7038 :type '(repeat (cons (number :tag "Rate")
7039 (regexp :tag "Regexp"))))
7040
7041(defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7042 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7043Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7044address, `ask' if unsure and `invalid' if the string is invalid."
7045 (let ((case-fold-search nil)
7046 (list gnus-button-mid-or-mail-heuristic-alist)
7047 (result 0) rate regexp lpartlen elem)
7048 (setq lpartlen
7049 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7050 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7051 ;; Certain special cases...
7052 (when (string-match
7053 (concat
7054 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7055 "^[0-9]+\\.[0-9]+@compuserve\\|"
7056 "@public\\.gmane\\.org")
7057 mid-or-mail)
7058 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7059 (setq result 'mail))
7060 (when (string-match "@.*@\\| " mid-or-mail)
7061 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7062 (setq result 'invalid))
7063 ;; Nothing more to do, if result is not a number here...
7064 (when (numberp result)
7065 (while list
7066 (setq elem (car list)
7067 rate (car elem)
7068 regexp (cdr elem)
7069 list (cdr list))
7070 (when (string-match regexp mid-or-mail)
7071 (setq result (+ result rate))
7072 (gnus-message
7073 9 "`%s' matched `%s', rate `%s', result `%s'."
7074 mid-or-mail regexp rate result)))
7075 (when (<= lpartlen 7)
7076 (setq result (+ result 5.0))
7077 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7078 mid-or-mail result))
7079 (when (>= lpartlen 12)
7080 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7081 (cond
7082 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7083 ;; Long local part should contain realname if e-mail address,
7084 ;; too many digits: message-id.
7085 ;; $score -= 5.0 + 0.1 * $local_part_len;
7086 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7087 (setq result (+ result rate))
7088 (gnus-message
7089 9 "Many digits in `%s', rate `%s', result `%s'."
7090 mid-or-mail rate result))
7091 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7092 mid-or-mail)
7093 ;; Too few vowels [^aeiouy]{4,}.*\@
7094 (setq result (+ result -5.0))
7095 (gnus-message
7096 9 "Few vowels in `%s', rate `%s', result `%s'."
7097 mid-or-mail -5.0 result))
7098 (t
7099 (setq result (+ result 5.0))
7100 (gnus-message
7101 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7102 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7103 ;; Maybe we should make this a customizable alist: (condition . 'result)
7104 (cond
7105 ((symbolp result) result)
7106 ;; Now convert number into proper results:
7107 ((< result -10.0) 'mid)
7108 ((> result 10.0) 'mail)
7109 (t 'ask))))
7110
7111(defun gnus-button-handle-mid-or-mail (mid-or-mail)
7112 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7113 (url-mid (concat "news" ":" mid-or-mail))
7114 (url-mailto (concat "mailto" ":" mid-or-mail)))
7115 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7116 (when (fboundp pref)
7117 (setq guessed
7118 ;; get rid of surrounding angles...
7119 (funcall pref
7120 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7121 (if (or (eq 'mid guessed) (eq 'mail guessed))
7122 (setq pref guessed)
7123 (setq pref 'ask)))
7124 (if (eq pref 'ask)
7125 (save-window-excursion
7126 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7127 (setq pref 'mail)
7128 (setq pref 'mid))))
7129 (cond ((eq pref 'mid)
7130 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7131 (gnus-button-handle-news url-mid))
7132 ((eq pref 'mail)
7133 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7134 (gnus-url-mailto url-mailto))
7135 (t (gnus-message 3 "Invalid string.")))))
7136
01c52d31
MB
7137(defun gnus-button-handle-custom (fun arg)
7138 "Call function FUN on argument ARG.
7139Both FUN and ARG are supposed to be strings. ARG will be passed
7140as a symbol to FUN."
7141 (funcall (intern fun)
7142 (if (string-match "^customize-apropos" fun)
7143 arg
7144 (intern arg))))
23f87bed
MB
7145
7146(defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7147
7148;; FIXME: Maybe we should merge some of the functions that do quite similar
7149;; stuff?
7150
7151(defun gnus-button-handle-describe-function (url)
7152 "Call `describe-function' when pushing the corresponding URL button."
7153 (describe-function
7154 (intern
7155 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7156
7157(defun gnus-button-handle-describe-variable (url)
7158 "Call `describe-variable' when pushing the corresponding URL button."
7159 (describe-variable
7160 (intern
7161 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7162
7163(defun gnus-button-handle-symbol (url)
7164"Display help on variable or function.
7165Calls `describe-variable' or `describe-function'."
7166 (let ((sym (intern url)))
7167 (cond
7168 ((fboundp sym) (describe-function sym))
7169 ((boundp sym) (describe-variable sym))
7170 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7171
7172(defun gnus-button-handle-describe-key (url)
7173 "Call `describe-key' when pushing the corresponding URL button."
7174 (let* ((key-string
7175 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7176 (keys (ignore-errors (eval `(kbd ,key-string)))))
7177 (if keys
7178 (describe-key keys)
7179 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7180
7181(defun gnus-button-handle-apropos (url)
7182 "Call `apropos' when pushing the corresponding URL button."
7183 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7184
7185(defun gnus-button-handle-apropos-command (url)
7186 "Call `apropos' when pushing the corresponding URL button."
7187 (apropos-command
7188 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7189
7190(defun gnus-button-handle-apropos-variable (url)
7191 "Call `apropos' when pushing the corresponding URL button."
7192 (funcall
7193 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7194 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7195
7196(defun gnus-button-handle-apropos-documentation (url)
7197 "Call `apropos' when pushing the corresponding URL button."
7198 (funcall
7199 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7200 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7201
7202(defun gnus-button-handle-library (url)
7203 "Call `locate-library' when pushing the corresponding URL button."
7204 (gnus-message 9 "url=`%s'" url)
7205 (let* ((lib (locate-library url))
7206 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7207 (if (not lib)
7208 (gnus-message 1 "Cannot locale library `%s'." url)
7209 (find-file-read-only file))))
7210
7211(defun gnus-button-handle-ctan (url)
7212 "Call `browse-url' when pushing a CTAN URL button."
7213 (funcall
7214 gnus-button-ctan-handler
7215 (concat
7216 gnus-ctan-url
7217 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7218
7219(defcustom gnus-button-tex-level 5
7220 "*Integer that says how many TeX-related buttons Gnus will show.
7221The higher the number, the more buttons will appear and the more false
7222positives are possible. Note that you can set this variable local to
7223specific groups. Setting it higher in TeX groups is probably a good idea.
7224See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7225how to set variables in specific groups."
bf247b6e 7226 :version "22.1"
23f87bed
MB
7227 :group 'gnus-article-buttons
7228 :link '(custom-manual "(gnus)Group Parameters")
7229 :type 'integer)
7230
7231(defcustom gnus-button-man-level 5
7232 "*Integer that says how many man-related buttons Gnus will show.
7233The higher the number, the more buttons will appear and the more false
7234positives are possible. Note that you can set this variable local to
7235specific groups. Setting it higher in Unix groups is probably a good idea.
7236See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7237how to set variables in specific groups."
bf247b6e 7238 :version "22.1"
23f87bed
MB
7239 :group 'gnus-article-buttons
7240 :link '(custom-manual "(gnus)Group Parameters")
7241 :type 'integer)
7242
7243(defcustom gnus-button-emacs-level 5
7244 "*Integer that says how many emacs-related buttons Gnus will show.
7245The higher the number, the more buttons will appear and the more false
7246positives are possible. Note that you can set this variable local to
7247specific groups. Setting it higher in Emacs or Gnus related groups is
7248probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7249`gnus-parameters' on how to set variables in specific groups."
bf247b6e 7250 :version "22.1"
23f87bed
MB
7251 :group 'gnus-article-buttons
7252 :link '(custom-manual "(gnus)Group Parameters")
7253 :type 'integer)
7254
7255(defcustom gnus-button-message-level 5
7256 "*Integer that says how many buttons for news or mail messages will appear.
7257The higher the number, the more buttons will appear and the more false
7258positives are possible."
7259 ;; mail addresses, MIDs, URLs for news, ...
bf247b6e 7260 :version "22.1"
23f87bed
MB
7261 :group 'gnus-article-buttons
7262 :type 'integer)
7263
7264(defcustom gnus-button-browse-level 5
7265 "*Integer that says how many buttons for browsing will appear.
7266The higher the number, the more buttons will appear and the more false
7267positives are possible."
7268 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
bf247b6e 7269 :version "22.1"
23f87bed
MB
7270 :group 'gnus-article-buttons
7271 :type 'integer)
7272
eec82323 7273(defcustom gnus-button-alist
23f87bed
MB
7274 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7275 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
97f78c9b
MB
7276 ((concat "\\b\\(nntp\\|news\\):\\("
7277 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7278 0 t gnus-button-handle-news 2)
23f87bed
MB
7279 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7280 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7281 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7282 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7283 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7284 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7285 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7286 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7287 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
01c52d31
MB
7288 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7289 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
23f87bed
MB
7290 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7291 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7292 ;; RFC 2368 (The mailto URL scheme)
531e5812 7293 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7294 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7295 ("\\bmailto:\\([^ \n\t]+\\)"
7296 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7297 ;; CTAN
7298 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7299 gnus-button-ctan-directory-regexp
7300 "[^][>)!;:,'\n\t ]+\\)")
7301 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7302 ((concat "\\btex-archive/\\("
7303 gnus-button-ctan-directory-regexp
7304 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7305 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7306 ((concat
7307 "\\b\\("
7308 gnus-button-ctan-directory-regexp
7309 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7310 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7311 ;; This is info (home-grown style) <info://foo/bar+baz>
7312 ("\\binfo://\\([^'\">\n\t ]+\\)"
7313 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7314 ;; Info GNOME style <info:foo#bar_baz>
7315 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7316 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7317 ;; Info KDE style <info:(foo)bar baz>
7318 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7319 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7320 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7321 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7322 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7323 ;; Info links like `C-h i d m CC Mode RET'
7324 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
7325 ;; This is custom
01c52d31
MB
7326 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7327 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
23f87bed
MB
7328 ;; Emacs help commands
7329 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7330 ;; regexp doesn't match arguments containing ` '.
7331 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7332 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7333 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7334 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7335 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7336 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7337 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7338 ;; The following entries may lead to many false positives so don't enable
531e5812
MB
7339 ;; them by default (use a high button level).
7340 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7341 ;; Exclude [.?] for URLs in gmane.emacs.cvs
23f87bed
MB
7342 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7343 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7344 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
01c52d31 7345 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
23f87bed
MB
7346 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7347 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7348 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7349 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7350 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7351 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7352 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7353 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7354 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7355 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7356 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
87ba2830 7357 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
23f87bed
MB
7358 ;; Unlike the other regexps we really have to require quoting
7359 ;; here to determine where it ends.
7360 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7361 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
01c52d31 7362 ("<URL: *\\([^\n<>]*\\)>"
23f87bed
MB
7363 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7364 ;; RFC 2396 (2.4.3., delims) ...
01c52d31 7365 ("\"URL: *\\([^\n\"]*\\)\""
23f87bed 7366 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
eec82323 7367 ;; Raw URLs.
23f87bed
MB
7368 (gnus-button-url-regexp
7369 0 (>= gnus-button-browse-level 0) browse-url 0)
7370 ;; man pages
531e5812 7371 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
23f87bed
MB
7372 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7373 gnus-button-handle-man 1)
7374 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
531e5812 7375 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
23f87bed
MB
7376 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7377 gnus-button-handle-man 1)
7378 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7379 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
531e5812 7380 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
23f87bed 7381 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
01c52d31
MB
7382 ;; Recognizing patches to .el files. This is somewhat obscure,
7383 ;; but considering the percentage of Gnus users who hack Emacs
7384 ;; Lisp files...
7385 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7386 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7387 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7388 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
23f87bed
MB
7389 ;; MID or mail: To avoid too many false positives we don't try to catch
7390 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7391 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7392 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7393 ;; so that non-ambiguous entries (see above) match first.
7394 (gnus-button-mid-or-mail-regexp
7395 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6748645f 7396 "*Alist of regexps matching buttons in article bodies.
eec82323
LMI
7397
7398Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
23f87bed
MB
7399REGEXP: is the string (case insensitive) matching text around the button (can
7400also be Lisp expression evaluating to a string),
eec82323 7401BUTTON: is the number of the regexp grouping actually matching the button,
4e7d0221 7402FORM: is a Lisp expression which must eval to true for the button to
eec82323
LMI
7403be added,
7404CALLBACK: is the function to call when the user push this button, and each
7405PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7406
7407CALLBACK can also be a variable, in that case the value of that
7408variable it the real callback function."
7409 :group 'gnus-article-buttons
23f87bed 7410 :type '(repeat (list (choice regexp variable sexp)
eec82323
LMI
7411 (integer :tag "Button")
7412 (sexp :tag "Form")
7413 (function :tag "Callback")
7414 (repeat :tag "Par"
7415 :inline t
7416 (integer :tag "Regexp group")))))
60ece9b0 7417(put 'gnus-button-alist 'risky-local-variable t)
eec82323
LMI
7418
7419(defcustom gnus-header-button-alist
23f87bed
MB
7420 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7421 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7422 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7423 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
eec82323 7424 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
fa9a04e1 7425 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
23f87bed
MB
7426 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7427 0 (>= gnus-button-browse-level 0) browse-url 0)
7428 ("^Subject:" gnus-button-url-regexp
7429 0 (>= gnus-button-browse-level 0) browse-url 0)
7430 ("^[^:]+:" gnus-button-url-regexp
7431 0 (>= gnus-button-browse-level 0) browse-url 0)
01c52d31
MB
7432 ("^OpenPGP:.*url=" gnus-button-url-regexp
7433 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
531e5812 7434 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
7435 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7436 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7437 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6748645f 7438 "*Alist of headers and regexps to match buttons in article heads.
eec82323
LMI
7439
7440This alist is very similar to `gnus-button-alist', except that each
7441alist has an additional HEADER element first in each entry:
7442
7443\(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7444
7445HEADER is a regexp to match a header. For a fuller explanation, see
7446`gnus-button-alist'."
7447 :group 'gnus-article-buttons
7448 :group 'gnus-article-headers
7449 :type '(repeat (list (regexp :tag "Header")
23f87bed 7450 (choice regexp variable)
eec82323
LMI
7451 (integer :tag "Button")
7452 (sexp :tag "Form")
7453 (function :tag "Callback")
7454 (repeat :tag "Par"
7455 :inline t
7456 (integer :tag "Regexp group")))))
60ece9b0 7457(put 'gnus-header-button-alist 'risky-local-variable t)
eec82323 7458
eec82323
LMI
7459;;; Commands:
7460
7461(defun gnus-article-push-button (event)
7462 "Check text under the mouse pointer for a callback function.
7463If the text under the mouse pointer has a `gnus-callback' property,
7464call it with the value of the `gnus-data' text property."
7465 (interactive "e")
7466 (set-buffer (window-buffer (posn-window (event-start event))))
7467 (let* ((pos (posn-point (event-start event)))
23f87bed 7468 (data (get-text-property pos 'gnus-data))
eec82323 7469 (fun (get-text-property pos 'gnus-callback)))
6748645f 7470 (goto-char pos)
eec82323
LMI
7471 (when fun
7472 (funcall fun data))))
7473
7474(defun gnus-article-press-button ()
7475 "Check text at point for a callback function.
7476If the text at point has a `gnus-callback' property,
7477call it with the value of the `gnus-data' text property."
7478 (interactive)
23f87bed
MB
7479 (let ((data (get-text-property (point) 'gnus-data))
7480 (fun (get-text-property (point) 'gnus-callback)))
eec82323
LMI
7481 (when fun
7482 (funcall fun data))))
7483
eec82323
LMI
7484(defun gnus-article-highlight (&optional force)
7485 "Highlight current article.
7486This function calls `gnus-article-highlight-headers',
7487`gnus-article-highlight-citation',
7488`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7489do the highlighting. See the documentation for those functions."
7490 (interactive (list 'force))
7491 (gnus-article-highlight-headers)
7492 (gnus-article-highlight-citation force)
7493 (gnus-article-highlight-signature)
7494 (gnus-article-add-buttons force)
7495 (gnus-article-add-buttons-to-head))
7496
7497(defun gnus-article-highlight-some (&optional force)
7498 "Highlight current article.
7499This function calls `gnus-article-highlight-headers',
7500`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7501do the highlighting. See the documentation for those functions."
7502 (interactive (list 'force))
7503 (gnus-article-highlight-headers)
7504 (gnus-article-highlight-signature)
7505 (gnus-article-add-buttons))
7506
7507(defun gnus-article-highlight-headers ()
7508 "Highlight article headers as specified by `gnus-header-face-alist'."
7509 (interactive)
01c52d31
MB
7510 (gnus-with-article-headers
7511 (let (regexp header-face field-face from hpoints fpoints)
7512 (dolist (entry gnus-header-face-alist)
7513 (goto-char (point-min))
7514 (setq regexp (concat "^\\("
7515 (if (string-equal "" (nth 0 entry))
7516 "[^\t ]"
7517 (nth 0 entry))
7518 "\\)")
7519 header-face (nth 1 entry)
7520 field-face (nth 2 entry))
7521 (while (and (re-search-forward regexp nil t)
7522 (not (eobp)))
7523 (beginning-of-line)
7524 (setq from (point))
7525 (unless (search-forward ":" nil t)
7526 (forward-char 1))
7527 (when (and header-face
7528 (not (memq (point) hpoints)))
7529 (push (point) hpoints)
7530 (gnus-put-text-property from (point) 'face header-face))
7531 (when (and field-face
7532 (not (memq (setq from (point)) fpoints)))
7533 (push from fpoints)
7534 (if (re-search-forward "^[^ \t]" nil t)
7535 (forward-char -2)
7536 (goto-char (point-max)))
7537 (gnus-put-text-property from (point) 'face field-face)))))))
eec82323
LMI
7538
7539(defun gnus-article-highlight-signature ()
7540 "Highlight the signature in an article.
7541It does this by highlighting everything after
0f49874b 7542`gnus-signature-separator' using the face `gnus-signature'."
eec82323 7543 (interactive)
01c52d31
MB
7544 (gnus-with-article-buffer
7545 (let ((inhibit-point-motion-hooks t))
eec82323
LMI
7546 (save-restriction
7547 (when (and gnus-signature-face
7548 (gnus-article-narrow-to-signature))
01c52d31 7549 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
eec82323
LMI
7550 'face gnus-signature-face)
7551 (widen)
7552 (gnus-article-search-signature)
7553 (let ((start (match-beginning 0))
7554 (end (set-marker (make-marker) (1+ (match-end 0)))))
7555 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7556 end)))))))
7557
7558(defun gnus-button-in-region-p (b e prop)
7559 "Say whether PROP exists in the region."
7560 (text-property-not-all b e prop nil))
7561
7562(defun gnus-article-add-buttons (&optional force)
7563 "Find external references in the article and make buttons of them.
7564\"External references\" are things like Message-IDs and URLs, as
7565specified by `gnus-button-alist'."
7566 (interactive (list 'force))
01c52d31
MB
7567 (gnus-with-article-buffer
7568 (let ((inhibit-point-motion-hooks t)
eec82323
LMI
7569 (case-fold-search t)
7570 (alist gnus-button-alist)
7571 beg entry regexp)
7572 ;; Remove all old markers.
16409b0b 7573 (let (marker entry new-list)
eec82323 7574 (while (setq marker (pop gnus-button-marker-list))
16409b0b
GM
7575 (if (or (< marker (point-min)) (>= marker (point-max)))
7576 (push marker new-list)
7577 (goto-char marker)
7578 (when (setq entry (gnus-button-entry))
7579 (put-text-property (match-beginning (nth 1 entry))
7580 (match-end (nth 1 entry))
7581 'gnus-callback nil))
7582 (set-marker marker nil)))
7583 (setq gnus-button-marker-list new-list))
eec82323 7584 ;; We skip the headers.
16409b0b 7585 (article-goto-body)
eec82323
LMI
7586 (setq beg (point))
7587 (while (setq entry (pop alist))
23f87bed 7588 (setq regexp (eval (car entry)))
eec82323
LMI
7589 (goto-char beg)
7590 (while (re-search-forward regexp nil t)
01c52d31
MB
7591 (let ((start (match-beginning (nth 1 entry)))
7592 (end (match-end (nth 1 entry)))
7593 (from (match-beginning 0)))
eec82323
LMI
7594 (when (and (or (eq t (nth 2 entry))
7595 (eval (nth 2 entry)))
7596 (not (gnus-button-in-region-p
7597 start end 'gnus-callback)))
7598 ;; That optional form returned non-nil, so we add the
7599 ;; button.
01c52d31
MB
7600 (setq from (set-marker (make-marker) from))
7601 (push from gnus-button-marker-list)
7602 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7603 (gnus-article-extend-url-button from start end))
7604 (gnus-article-add-button start end
7605 'gnus-button-push from)))))))))
7606
7607(defun gnus-article-extend-url-button (beg start end)
7608 "Extend url button if url is folded into two or more lines.
7609Return non-nil if button is extended. BEG is a marker that points to
7610the beginning position of a text containing url. START and END are
7611the endpoints of a url button before it is extended. The concatenated
7612url is put as the `gnus-button-url' overlay property on the button."
7613 (let ((opoint (point))
7614 (points (list start end))
7615 url delim regexp)
7616 (prog1
7617 (when (and (progn
7618 (goto-char end)
7619 (not (looking-at "[\t ]*[\">]")))
7620 (progn
7621 (goto-char start)
7622 (string-match
7623 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7624 (buffer-substring (point-at-bol) start)))
7625 (progn
7626 (setq url (list (buffer-substring start end))
7627 delim (if (match-beginning 1) ">" "\""))
7628 (beginning-of-line)
7629 (setq regexp (concat
7630 (when (and (looking-at
7631 message-cite-prefix-regexp)
7632 (< (match-end 0) start))
7633 (regexp-quote (match-string 0)))
7634 "\
7635\[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7636 delim "\\)"))
7637 (while (progn
7638 (forward-line 1)
7639 (and (looking-at regexp)
7640 (prog1
7641 (match-beginning 1)
7642 (push (or (match-string 2)
7643 (match-string 1))
7644 url)
7645 (push (setq end (or (match-end 2)
7646 (match-end 1)))
7647 points)
7648 (push (or (match-beginning 2)
7649 (match-beginning 1))
7650 points)))))
7651 (match-beginning 2)))
7652 (let (gnus-article-mouse-face widget-mouse-face)
7653 (while points
7654 (gnus-article-add-button (pop points) (pop points)
7655 'gnus-button-push beg)))
7656 (let ((overlay (gnus-make-overlay start end)))
7657 (gnus-overlay-put overlay 'evaporate t)
7658 (gnus-overlay-put overlay 'gnus-button-url
7659 (list (mapconcat 'identity (nreverse url) "")))
7660 (when gnus-article-mouse-face
7661 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7662 t)
7663 (goto-char opoint))))
eec82323
LMI
7664
7665;; Add buttons to the head of an article.
7666(defun gnus-article-add-buttons-to-head ()
7667 "Add buttons to the head of the article."
7668 (interactive)
01c52d31
MB
7669 (gnus-with-article-headers
7670 (let (beg end)
7671 (dolist (entry gnus-header-button-alist)
7672 ;; Each alist entry.
7673 (goto-char (point-min))
7674 (while (re-search-forward (car entry) nil t)
7675 ;; Each header matching the entry.
7676 (setq beg (match-beginning 0))
7677 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7678 (match-beginning 0))
7679 (point-max)))
7680 (goto-char beg)
7681 (while (re-search-forward (eval (nth 1 entry)) end t)
7682 ;; Each match within a header.
7683 (let* ((entry (cdr entry))
7684 (start (match-beginning (nth 1 entry)))
7685 (end (match-end (nth 1 entry)))
7686 (form (nth 2 entry)))
7687 (goto-char (match-end 0))
7688 (when (eval form)
7689 (gnus-article-add-button
7690 start end (nth 3 entry)
7691 (buffer-substring (match-beginning (nth 4 entry))
7692 (match-end (nth 4 entry)))))))
7693 (goto-char end))))))
eec82323
LMI
7694
7695;;; External functions:
7696
7697(defun gnus-article-add-button (from to fun &optional data)
7698 "Create a button between FROM and TO with callback FUN and data DATA."
7699 (when gnus-article-button-face
01c52d31 7700 (gnus-overlay-put (gnus-make-overlay from to nil t)
eec82323
LMI
7701 'face gnus-article-button-face))
7702 (gnus-add-text-properties
7703 from to
7704 (nconc (and gnus-article-mouse-face
7705 (list gnus-mouse-face-prop gnus-article-mouse-face))
7706 (list 'gnus-callback fun)
16409b0b
GM
7707 (and data (list 'gnus-data data))))
7708 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7709 :button-keymap gnus-widget-button-keymap))
eec82323
LMI
7710
7711;;; Internal functions:
7712
a8151ef7 7713(defun gnus-article-set-globals ()
01c52d31 7714 (with-current-buffer gnus-summary-buffer
a8151ef7
LMI
7715 (gnus-set-global-variables)))
7716
eec82323 7717(defun gnus-signature-toggle (end)
01c52d31
MB
7718 (gnus-with-article-buffer
7719 (let ((inhibit-point-motion-hooks t))
520aa572 7720 (if (text-property-any end (point-max) 'article-type 'signature)
23f87bed
MB
7721 (progn
7722 (gnus-delete-wash-type 'signature)
7723 (gnus-remove-text-properties-when
7724 'article-type 'signature end (point-max)
7725 (cons 'article-type (cons 'signature
7726 gnus-hidden-properties))))
7727 (gnus-add-wash-type 'signature)
520aa572
SZ
7728 (gnus-add-text-properties-when
7729 'article-type nil end (point-max)
7730 (cons 'article-type (cons 'signature
23f87bed
MB
7731 gnus-hidden-properties)))))
7732 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7733 (gnus-set-mode-line 'article))))
eec82323
LMI
7734
7735(defun gnus-button-entry ()
7736 ;; Return the first entry in `gnus-button-alist' matching this place.
7737 (let ((alist gnus-button-alist)
7738 (entry nil))
7739 (while alist
7740 (setq entry (pop alist))
23f87bed 7741 (if (looking-at (eval (car entry)))
eec82323
LMI
7742 (setq alist nil)
7743 (setq entry nil)))
7744 entry))
7745
7746(defun gnus-button-push (marker)
7747 ;; Push button starting at MARKER.
7748 (save-excursion
eec82323
LMI
7749 (goto-char marker)
7750 (let* ((entry (gnus-button-entry))
7751 (inhibit-point-motion-hooks t)
7752 (fun (nth 3 entry))
01c52d31
MB
7753 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7754 (get-char-property marker 'gnus-button-url))
7755 (mapcar (lambda (group)
7756 (let ((string (match-string group)))
7757 (set-text-properties
7758 0 (length string) nil string)
7759 string))
7760 (nthcdr 4 entry)))))
eec82323
LMI
7761 (cond
7762 ((fboundp fun)
7763 (apply fun args))
7764 ((and (boundp fun)
7765 (fboundp (symbol-value fun)))
7766 (apply (symbol-value fun) args))
7767 (t
7768 (gnus-message 1 "You must define `%S' to use this button"
7769 (cons fun args)))))))
7770
23f87bed 7771(defun gnus-parse-news-url (url)
82a8ad04 7772 (let (scheme server port group message-id articles)
23f87bed
MB
7773 (with-temp-buffer
7774 (insert url)
7775 (goto-char (point-min))
7776 (when (looking-at "\\([A-Za-z]+\\):")
7777 (setq scheme (match-string 1))
7778 (goto-char (match-end 0)))
82a8ad04 7779 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
23f87bed 7780 (setq server (match-string 1))
82a8ad04
MB
7781 (setq port (if (stringp (match-string 3))
7782 (string-to-number (match-string 3))
7783 (match-string 3)))
23f87bed
MB
7784 (goto-char (match-end 0)))
7785
7786 (cond
7787 ((looking-at "\\(.*@.*\\)")
7788 (setq message-id (match-string 1)))
7789 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7790 (setq group (match-string 1)
7791 articles (split-string (match-string 2) "-")))
7792 ((looking-at "\\([^/]+\\)/?")
7793 (setq group (match-string 1)))
7794 (t
7795 (error "Unknown news URL syntax"))))
82a8ad04 7796 (list scheme server port group message-id articles)))
23f87bed
MB
7797
7798(defun gnus-button-handle-news (url)
7799 "Fetch a news URL."
82a8ad04 7800 (destructuring-bind (scheme server port group message-id articles)
23f87bed
MB
7801 (gnus-parse-news-url url)
7802 (cond
7803 (message-id
7804 (save-excursion
7805 (set-buffer gnus-summary-buffer)
7806 (if server
ff4d3926
MB
7807 (let ((gnus-refer-article-method
7808 (nconc (list (list 'nntp server))
7809 gnus-refer-article-method))
82a8ad04 7810 (nntp-port-number (or port "nntp")))
ff4d3926
MB
7811 (gnus-message 7 "Fetching %s with %s"
7812 message-id gnus-refer-article-method)
23f87bed
MB
7813 (gnus-summary-refer-article message-id))
7814 (gnus-summary-refer-article message-id))))
7815 (group
7816 (gnus-button-fetch-group url)))))
7817
01c52d31
MB
7818(defun gnus-button-patch (library line)
7819 "Visit an Emacs Lisp library LIBRARY on line LINE."
7820 (interactive)
7821 (let ((file (locate-library (file-name-nondirectory library))))
7822 (unless file
7823 (error "Couldn't find library %s" library))
7824 (find-file file)
7825 (goto-line (string-to-number line))))
7826
23f87bed
MB
7827(defun gnus-button-handle-man (url)
7828 "Fetch a man page."
531e5812
MB
7829 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7830 (when (eq gnus-button-man-handler 'woman)
7831 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7832 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
23f87bed
MB
7833 (funcall gnus-button-man-handler url))
7834
7835(defun gnus-button-handle-info-url (url)
7836 "Fetch an info URL."
7837 (setq url (mm-subst-char-in-string ?+ ?\ url))
7838 (cond
7839 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7840 (gnus-info-find-node
7841 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7842 "Gnus")
7843 ")" (gnus-url-unhex-string (match-string 2 url)))))
7844 ((string-match "([^)\"]+)[^\"]+" url)
7845 (setq url
7846 (gnus-replace-in-string
7847 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7848 (gnus-info-find-node url))
7849 (t (error "Can't parse %s" url))))
7850
7851(defun gnus-button-handle-info-url-gnome (url)
7852 "Fetch GNOME style info URL."
7853 (setq url (mm-subst-char-in-string ?_ ?\ url))
7854 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7855 (gnus-info-find-node
7856 (concat "("
bf247b6e 7857 (gnus-url-unhex-string
23f87bed
MB
7858 (match-string 1 url))
7859 ")"
bf247b6e 7860 (or (gnus-url-unhex-string
23f87bed
MB
7861 (match-string 2 url))
7862 "Top")))
7863 (error "Can't parse %s" url)))
7864
7865(defun gnus-button-handle-info-url-kde (url)
7866 "Fetch KDE style info URL."
7867 (gnus-info-find-node (gnus-url-unhex-string url)))
7868
9640c3bc
GM
7869;; (info) will autoload info.el
7870(declare-function Info-menu "info" (menu-item &optional fork))
7871
23f87bed
MB
7872(defun gnus-button-handle-info-keystrokes (url)
7873 "Call `info' when pushing the corresponding URL button."
7874 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7875 (info)
7876 (Info-directory)
7877 (Info-menu url))
7878
01c52d31
MB
7879(defun gnus-button-openpgp (url)
7880 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7881 (with-temp-buffer
7882 (mm-url-insert-file-contents-external url)
7883 (pgg-snarf-keys-region (point-min) (point-max))
7884 (pgg-display-output-buffer nil nil nil)))
7885
eec82323
LMI
7886(defun gnus-button-message-id (message-id)
7887 "Fetch MESSAGE-ID."
01c52d31 7888 (with-current-buffer gnus-summary-buffer
eec82323
LMI
7889 (gnus-summary-refer-article message-id)))
7890
01c52d31 7891(defun gnus-button-fetch-group (address &rest ignore)
eec82323 7892 "Fetch GROUP specified by ADDRESS."
01c52d31
MB
7893 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7894 address)
7895 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7896 ;; for nntp:// and news://
7897 (setq address (match-string 3 address)))
eec82323
LMI
7898 (if (not (string-match "[:/]" address))
7899 ;; This is just a simple group url.
7900 (gnus-group-read-ephemeral-group address gnus-select-method)
23f87bed
MB
7901 (if (not
7902 (string-match
7903 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7904 address))
eec82323
LMI
7905 (error "Can't parse %s" address)
7906 (gnus-group-read-ephemeral-group
7907 (match-string 4 address)
7908 `(nntp ,(match-string 1 address)
7909 (nntp-address ,(match-string 1 address))
7910 (nntp-port-number ,(if (match-end 3)
7911 (match-string 3 address)
23f87bed
MB
7912 "nntp")))
7913 nil nil nil
e9bd5782 7914 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
eec82323 7915
eec82323
LMI
7916(defun gnus-url-parse-query-string (query &optional downcase)
7917 (let (retval pairs cur key val)
16409b0b 7918 (setq pairs (split-string query "&"))
eec82323
LMI
7919 (while pairs
7920 (setq cur (car pairs)
23f87bed 7921 pairs (cdr pairs))
eec82323 7922 (if (not (string-match "=" cur))
23f87bed
MB
7923 nil ; Grace
7924 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7925 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7926 (if downcase
7927 (setq key (downcase key)))
7928 (setq cur (assoc key retval))
7929 (if cur
7930 (setcdr cur (cons val (cdr cur)))
7931 (setq retval (cons (list key val) retval)))))
eec82323
LMI
7932 retval))
7933
eec82323
LMI
7934(defun gnus-url-mailto (url)
7935 ;; Send mail to someone
7936 (when (string-match "mailto:/*\\(.*\\)" url)
7937 (setq url (substring url (match-beginning 1) nil)))
6748645f 7938 (let (to args subject func)
23f87bed
MB
7939 (setq args (gnus-url-parse-query-string
7940 (if (string-match "^\\?" url)
7941 (substring url 1)
7942 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7943 (concat "to=" (match-string 1 url) "&"
7944 (match-string 2 url))
7945 (concat "to=" url)))
7946 t)
7947 subject (cdr-safe (assoc "subject" args)))
7948 (gnus-msg-mail)
eec82323
LMI
7949 (while args
7950 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7951 (if (fboundp func)
23f87bed
MB
7952 (funcall func)
7953 (message-position-on-field (caar args)))
7954 (insert (gnus-replace-in-string
7955 (mapconcat 'identity (reverse (cdar args)) ", ")
7956 "\r\n" "\n" t))
eec82323
LMI
7957 (setq args (cdr args)))
7958 (if subject
23f87bed 7959 (message-goto-body)
eec82323
LMI
7960 (message-goto-subject))))
7961
eec82323 7962(defun gnus-button-embedded-url (address)
e0bad764 7963 "Activate ADDRESS with `browse-url'."
1b978bfc 7964 (browse-url (gnus-strip-whitespace address)))
eec82323
LMI
7965
7966;;; Next/prev buttons in the article buffer.
7967
7968(defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7969(defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7970
23f87bed
MB
7971(defvar gnus-prev-page-map
7972 (let ((map (make-sparse-keymap)))
23f87bed
MB
7973 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7974 (define-key map "\r" 'gnus-button-prev-page)
7975 map))
7976
7977(defvar gnus-next-page-map
7978 (let ((map (make-sparse-keymap)))
7979 (unless (>= emacs-major-version 21)
7980 ;; XEmacs doesn't care.
7981 (set-keymap-parent map gnus-article-mode-map))
7982 (define-key map gnus-mouse-2 'gnus-button-next-page)
7983 (define-key map "\r" 'gnus-button-next-page)
7984 map))
eec82323
LMI
7985
7986(defun gnus-insert-prev-page-button ()
01c52d31 7987 (let ((b (point)) e
23f87bed 7988 (inhibit-read-only t))
eec82323
LMI
7989 (gnus-eval-format
7990 gnus-prev-page-line-format nil
01c52d31
MB
7991 `(keymap ,gnus-prev-page-map
7992 gnus-prev t
7993 gnus-callback gnus-article-button-prev-page
7994 article-type annotation))
7995 (setq e (if (bolp)
7996 ;; Exclude a newline.
7997 (1- (point))
7998 (point)))
7999 (when gnus-article-button-face
8000 (gnus-overlay-put (gnus-make-overlay b e nil t)
8001 'face gnus-article-button-face))
23f87bed 8002 (widget-convert-button
01c52d31 8003 'link b e
23f87bed
MB
8004 :action 'gnus-button-prev-page
8005 :button-keymap gnus-prev-page-map)))
8006
8007(defun gnus-button-next-page (&optional args more-args)
eec82323
LMI
8008 "Go to the next page."
8009 (interactive)
8010 (let ((win (selected-window)))
23f87bed 8011 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8012 (gnus-article-next-page)
8013 (select-window win)))
8014
23f87bed 8015(defun gnus-button-prev-page (&optional args more-args)
eec82323
LMI
8016 "Go to the prev page."
8017 (interactive)
8018 (let ((win (selected-window)))
23f87bed 8019 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8020 (gnus-article-prev-page)
8021 (select-window win)))
8022
8023(defun gnus-insert-next-page-button ()
01c52d31 8024 (let ((b (point)) e
23f87bed 8025 (inhibit-read-only t))
eec82323 8026 (gnus-eval-format gnus-next-page-line-format nil
01c52d31
MB
8027 `(keymap ,gnus-next-page-map
8028 gnus-next t
8029 gnus-callback gnus-article-button-next-page
8030 article-type annotation))
8031 (setq e (if (bolp)
8032 ;; Exclude a newline.
8033 (1- (point))
8034 (point)))
8035 (when gnus-article-button-face
8036 (gnus-overlay-put (gnus-make-overlay b e nil t)
8037 'face gnus-article-button-face))
23f87bed 8038 (widget-convert-button
01c52d31 8039 'link b e
23f87bed
MB
8040 :action 'gnus-button-next-page
8041 :button-keymap gnus-next-page-map)))
eec82323
LMI
8042
8043(defun gnus-article-button-next-page (arg)
8044 "Go to the next page."
8045 (interactive "P")
8046 (let ((win (selected-window)))
23f87bed 8047 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8048 (gnus-article-next-page)
8049 (select-window win)))
8050
8051(defun gnus-article-button-prev-page (arg)
8052 "Go to the prev page."
8053 (interactive "P")
8054 (let ((win (selected-window)))
23f87bed 8055 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
8056 (gnus-article-prev-page)
8057 (select-window win)))
8058
16409b0b
GM
8059(defvar gnus-decode-header-methods
8060 '(mail-decode-encoded-word-region)
8061 "List of methods used to decode headers.
8062
8063This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4e7d0221 8064is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
23f87bed 8065\(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
16409b0b
GM
8066whose names match REGEXP.
8067
8068For example:
8f688cb0 8069\((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
16409b0b
GM
8070 mail-decode-encoded-word-region
8071 (\"chinese\" . rfc1843-decode-region))
8072")
8073
8074(defvar gnus-decode-header-methods-cache nil)
8075
8076(defun gnus-multi-decode-header (start end)
8077 "Apply the functions from `gnus-encoded-word-methods' that match."
8078 (unless (and gnus-decode-header-methods-cache
8079 (eq gnus-newsgroup-name
8080 (car gnus-decode-header-methods-cache)))
8081 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
01c52d31
MB
8082 (dolist (x gnus-decode-header-methods)
8083 (if (symbolp x)
8084 (nconc gnus-decode-header-methods-cache (list x))
8085 (if (and gnus-newsgroup-name
8086 (string-match (car x) gnus-newsgroup-name))
8087 (nconc gnus-decode-header-methods-cache
8088 (list (cdr x)))))))
16409b0b
GM
8089 (let ((xlist gnus-decode-header-methods-cache))
8090 (pop xlist)
8091 (save-restriction
8092 (narrow-to-region start end)
8093 (while xlist
8094 (funcall (pop xlist) (point-min) (point-max))))))
8095
8096;;;
8097;;; Treatment top-level handling.
8098;;;
8099
8100(defun gnus-treat-article (condition &optional part-number total-parts type)
8101 (let ((length (- (point-max) (point-min)))
8102 (alist gnus-treatment-function-alist)
8103 (article-goto-body-goes-to-point-min-p t)
8104 (treated-type
8105 (or (not type)
8106 (catch 'found
8107 (let ((list gnus-article-treat-types))
8108 (while list
8109 (when (string-match (pop list) type)
8110 (throw 'found t)))))))
8111 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8112 val elem)
8113 (gnus-run-hooks 'gnus-part-display-hook)
23f87bed 8114 (dolist (elem alist)
16409b0b
GM
8115 (setq val
8116 (save-excursion
23f87bed
MB
8117 (when (gnus-buffer-live-p gnus-summary-buffer)
8118 (set-buffer gnus-summary-buffer))
16409b0b
GM
8119 (symbol-value (car elem))))
8120 (when (and (or (consp val)
8121 treated-type)
8122 (gnus-treat-predicate val)
8123 (or (not (get (car elem) 'highlight))
8124 highlightp))
8125 (save-restriction
8126 (funcall (cadr elem)))))))
8127
8128;; Dynamic variables.
9efa445f
DN
8129(defvar part-number)
8130(defvar total-parts)
8131(defvar type)
8132(defvar condition)
8133(defvar length)
e0bad764 8134
16409b0b
GM
8135(defun gnus-treat-predicate (val)
8136 (cond
8137 ((null val)
8138 nil)
23f87bed
MB
8139 (condition
8140 (eq condition val))
16409b0b
GM
8141 ((and (listp val)
8142 (stringp (car val)))
8143 (apply 'gnus-or (mapcar `(lambda (s)
8144 (string-match s ,(or gnus-newsgroup-name "")))
8145 val)))
8146 ((listp val)
8147 (let ((pred (pop val)))
8148 (cond
8149 ((eq pred 'or)
8150 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8151 ((eq pred 'and)
8152 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8153 ((eq pred 'not)
8154 (not (gnus-treat-predicate (car val))))
8155 ((eq pred 'typep)
8156 (equal (car val) type))
8157 (t
8158 (error "%S is not a valid predicate" pred)))))
16409b0b
GM
8159 ((eq val t)
8160 t)
8161 ((eq val 'head)
8162 nil)
01c52d31
MB
8163 ((eq val 'first)
8164 (eq part-number 1))
16409b0b
GM
8165 ((eq val 'last)
8166 (eq part-number total-parts))
8167 ((numberp val)
8168 (< length val))
8169 (t
8170 (error "%S is not a valid value" val))))
8171
23f87bed
MB
8172(defun gnus-article-encrypt-body (protocol &optional n)
8173 "Encrypt the article body."
8174 (interactive
8175 (list
8176 (or gnus-article-encrypt-protocol
8177 (completing-read "Encrypt protocol: "
8178 gnus-article-encrypt-protocol-alist
8179 nil t))
8180 current-prefix-arg))
bbbe940b
MB
8181 ;; User might hit `K E' instead of `K e', so prompt once.
8182 (when (and gnus-article-encrypt-protocol
8183 gnus-novice-user)
8184 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8185 (error "Encrypt aborted.")))
23f87bed
MB
8186 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8187 (unless func
998a5a95 8188 (error "Can't find the encrypt protocol %s" protocol))
23f87bed
MB
8189 (if (member gnus-newsgroup-name '("nndraft:delayed"
8190 "nndraft:drafts"
8191 "nndraft:queue"))
8192 (error "Can't encrypt the article in group %s"
8193 gnus-newsgroup-name))
8194 (gnus-summary-iterate n
8195 (save-excursion
8196 (set-buffer gnus-summary-buffer)
8197 (let ((mail-parse-charset gnus-newsgroup-charset)
8198 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8199 (summary-buffer gnus-summary-buffer)
8200 references point)
8201 (gnus-set-global-variables)
8202 (when (gnus-group-read-only-p)
8203 (error "The current newsgroup does not support article encrypt"))
8204 (gnus-summary-show-article t)
8205 (setq references
8206 (or (mail-header-references gnus-current-headers) ""))
8207 (set-buffer gnus-article-buffer)
8208 (let* ((inhibit-read-only t)
8209 (headers
8210 (mapcar (lambda (field)
8211 (and (save-restriction
8212 (message-narrow-to-head)
8213 (goto-char (point-min))
8214 (search-forward field nil t))
8215 (prog2
8216 (message-narrow-to-field)
8217 (buffer-string)
8218 (delete-region (point-min) (point-max))
8219 (widen))))
8220 '("Content-Type:" "Content-Transfer-Encoding:"
8221 "Content-Disposition:"))))
8222 (message-narrow-to-head)
8223 (message-remove-header "MIME-Version")
8224 (goto-char (point-max))
8225 (setq point (point))
8226 (insert (apply 'concat headers))
8227 (widen)
8228 (narrow-to-region point (point-max))
8229 (let ((message-options message-options))
8230 (message-options-set 'message-sender user-mail-address)
8231 (message-options-set 'message-recipients user-mail-address)
8232 (message-options-set 'message-sign-encrypt 'not)
8233 (funcall func))
8234 (goto-char (point-min))
8235 (insert "MIME-Version: 1.0\n")
8236 (widen)
8237 (gnus-summary-edit-article-done
8238 references nil summary-buffer t))
8239 (when gnus-keep-backlog
8240 (gnus-backlog-remove-article
8241 (car gnus-article-current) (cdr gnus-article-current)))
8242 (save-excursion
8243 (when (get-buffer gnus-original-article-buffer)
8244 (set-buffer gnus-original-article-buffer)
8245 (setq gnus-original-article nil)))
8246 (when gnus-use-cache
8247 (gnus-cache-update-article
8248 (car gnus-article-current) (cdr gnus-article-current))))))))
8249
8250(defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8251 "The following specs can be used:
8252%t The security MIME type
8253%i Additional info
8254%d Details
8255%D Details if button is pressed")
8256
8257(defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8258 "The following specs can be used:
8259%t The security MIME type
8260%i Additional info
8261%d Details
8262%D Details if button is pressed")
8263
8264(defvar gnus-mime-security-button-line-format-alist
8265 '((?t gnus-tmp-type ?s)
8266 (?i gnus-tmp-info ?s)
8267 (?d gnus-tmp-details ?s)
8268 (?D gnus-tmp-pressed-details ?s)))
8269
01c52d31
MB
8270(defvar gnus-mime-security-button-commands
8271 '((gnus-article-press-button "\r" "Show Detail")
8272 (undefined "v")
8273 (undefined "t")
8274 (undefined "C")
8275 (gnus-mime-security-save-part "o" "Save...")
8276 (undefined "\C-o")
8277 (undefined "r")
8278 (undefined "d")
8279 (undefined "c")
8280 (undefined "i")
8281 (undefined "E")
8282 (undefined "e")
8283 (undefined "p")
8284 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8285 (undefined ".")))
8286
23f87bed
MB
8287(defvar gnus-mime-security-button-map
8288 (let ((map (make-sparse-keymap)))
23f87bed 8289 (define-key map gnus-mouse-2 'gnus-article-push-button)
01c52d31
MB
8290 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8291 (dolist (c gnus-mime-security-button-commands)
8292 (define-key map (cadr c) (car c)))
23f87bed
MB
8293 map))
8294
01c52d31
MB
8295(easy-menu-define
8296 gnus-mime-security-button-menu gnus-mime-security-button-map
8297 "Security button menu."
8298 `("Security Part"
8299 ,@(delq nil
8300 (mapcar (lambda (c)
8301 (unless (eq (car c) 'undefined)
8302 (vector (caddr c) (car c) :active t)))
8303 gnus-mime-security-button-commands))))
8304
8305(defun gnus-mime-security-button-menu (event prefix)
8306 "Construct a context-sensitive menu of security commands."
8307 (interactive "e\nP")
8308 (save-window-excursion
8309 (let ((pos (event-start event)))
8310 (select-window (posn-window pos))
8311 (goto-char (posn-point pos))
8312 (gnus-article-check-buffer)
8313 (popup-menu gnus-mime-security-button-menu nil prefix))))
8314
23f87bed
MB
8315(defvar gnus-mime-security-details-buffer nil)
8316
8317(defvar gnus-mime-security-button-pressed nil)
8318
8319(defvar gnus-mime-security-show-details-inline t
8320 "If non-nil, show details in the article buffer.")
8321
8322(defun gnus-mime-security-verify-or-decrypt (handle)
8323 (mm-remove-parts (cdr handle))
8324 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8325 point (inhibit-read-only t))
8326 (if region
8327 (goto-char (car region)))
01c52d31
MB
8328 (setq point (point))
8329 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8330 (let* ((mm-verify-option 'known)
8331 (mm-decrypt-option 'known)
8332 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8333 (unless (eq nparts (cdr handle))
8334 (mm-destroy-parts (cdr handle))
8335 (setcdr handle nparts))))
8336 (gnus-mime-display-security handle)
23f87bed
MB
8337 (when region
8338 (delete-region (point) (cdr region))
8339 (set-marker (car region) nil)
8340 (set-marker (cdr region) nil))
8341 (goto-char point)))
8342
8343(defun gnus-mime-security-show-details (handle)
8344 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8345 (if (not details)
8346 (gnus-message 5 "No details.")
8347 (if gnus-mime-security-show-details-inline
8348 (let ((gnus-mime-security-button-pressed
8349 (not (get-text-property (point) 'gnus-mime-details)))
8350 (gnus-mime-security-button-line-format
8351 (get-text-property (point) 'gnus-line-format))
8352 (inhibit-read-only t))
8353 (forward-char -1)
8354 (while (eq (get-text-property (point) 'gnus-line-format)
8355 gnus-mime-security-button-line-format)
8356 (forward-char -1))
8357 (forward-char)
8358 (save-restriction
8359 (narrow-to-region (point) (point))
8360 (gnus-insert-mime-security-button handle))
8361 (delete-region (point)
8362 (or (text-property-not-all
8363 (point) (point-max)
8364 'gnus-line-format
8365 gnus-mime-security-button-line-format)
8366 (point-max))))
8367 ;; Not inlined.
8368 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8369 (with-current-buffer gnus-mime-security-details-buffer
8370 (erase-buffer)
8371 t)
8372 (setq gnus-mime-security-details-buffer
8373 (gnus-get-buffer-create "*MIME Security Details*")))
8374 (with-current-buffer gnus-mime-security-details-buffer
8375 (insert details)
8376 (goto-char (point-min)))
8377 (pop-to-buffer gnus-mime-security-details-buffer)))))
8378
8379(defun gnus-mime-security-press-button (handle)
8380 (save-excursion
8381 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8382 (gnus-mime-security-show-details handle)
8383 (gnus-mime-security-verify-or-decrypt handle))))
8384
8385(defun gnus-insert-mime-security-button (handle &optional displayed)
8386 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8387 (gnus-tmp-type
8388 (concat
8389 (or (nth 2 (assoc protocol mm-verify-function-alist))
8390 (nth 2 (assoc protocol mm-decrypt-function-alist))
8391 "Unknown")
8392 (if (equal (car handle) "multipart/signed")
8393 " Signed" " Encrypted")
8394 " Part"))
8395 (gnus-tmp-info
8396 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8397 "Undecided"))
8398 (gnus-tmp-details
8399 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8400 gnus-tmp-pressed-details
8401 b e)
8402 (setq gnus-tmp-details
8403 (if gnus-tmp-details
8404 (concat "\n" gnus-tmp-details)
8405 ""))
8406 (setq gnus-tmp-pressed-details
8407 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8408 (unless (bolp)
8409 (insert "\n"))
8410 (setq b (point))
8411 (gnus-eval-format
8412 gnus-mime-security-button-line-format
8413 gnus-mime-security-button-line-format-alist
01c52d31 8414 `(keymap ,gnus-mime-security-button-map
23f87bed
MB
8415 gnus-callback gnus-mime-security-press-button
8416 gnus-line-format ,gnus-mime-security-button-line-format
8417 gnus-mime-details ,gnus-mime-security-button-pressed
8418 article-type annotation
8419 gnus-data ,handle))
8420 (setq e (if (bolp)
8421 ;; Exclude a newline.
8422 (1- (point))
8423 (point)))
01c52d31
MB
8424 (when gnus-article-button-face
8425 (gnus-overlay-put (gnus-make-overlay b e nil t)
8426 'face gnus-article-button-face))
23f87bed
MB
8427 (widget-convert-button
8428 'link b e
8429 :mime-handle handle
8430 :action 'gnus-widget-press-button
8431 :button-keymap gnus-mime-security-button-map
8432 :help-echo
8433 (lambda (widget/window &optional overlay pos)
8434 ;; Needed to properly clear the message due to a bug in
8435 ;; wid-edit (XEmacs only).
8436 (when (boundp 'help-echo-owns-message)
8437 (setq help-echo-owns-message t))
8438 (format
01c52d31
MB
8439 "%S: show detail; %S: more options"
8440 (aref gnus-mouse-2 0)
8441 (aref gnus-down-mouse-3 0))))))
23f87bed
MB
8442
8443(defun gnus-mime-display-security (handle)
8444 (save-restriction
8445 (narrow-to-region (point) (point))
8446 (unless (gnus-unbuttonized-mime-type-p (car handle))
8447 (gnus-insert-mime-security-button handle))
01c52d31 8448 (gnus-mime-display-part (cadr handle))
23f87bed
MB
8449 (unless (bolp)
8450 (insert "\n"))
8451 (unless (gnus-unbuttonized-mime-type-p (car handle))
8452 (let ((gnus-mime-security-button-line-format
8453 gnus-mime-security-button-end-line-format))
8454 (gnus-insert-mime-security-button handle)))
8455 (mm-set-handle-multipart-parameter
8456 handle 'gnus-region
8457 (cons (set-marker (make-marker) (point-min))
01c52d31
MB
8458 (set-marker (make-marker) (point-max))))
8459 (goto-char (point-max))))
8460
8461(defun gnus-mime-security-run-function (function)
8462 "Run FUNCTION with the security part under point."
8463 (gnus-article-check-buffer)
8464 (let ((data (get-text-property (point) 'gnus-data))
8465 buffer handle)
8466 (when (and (stringp (car-safe data))
8467 (setq buffer (mm-handle-multipart-original-buffer data))
8468 (setq handle (cadr data)))
8469 (if (bufferp (mm-handle-buffer handle))
8470 (progn
8471 (setq handle (cons buffer (copy-sequence (cdr handle))))
8472 (mm-handle-set-undisplayer handle nil))
8473 (setq handle (mm-make-handle
8474 buffer
8475 (mm-handle-multipart-ctl-parameter handle 'protocol)
8476 nil nil nil nil nil nil)))
8477 (funcall function handle))))
8478
8479(defun gnus-mime-security-save-part ()
8480 "Save the security part under point."
8481 (interactive)
8482 (gnus-mime-security-run-function 'mm-save-part))
8483
8484(defun gnus-mime-security-pipe-part ()
8485 "Pipe the security part under point to a process."
8486 (interactive)
8487 (gnus-mime-security-run-function 'mm-pipe-part))
23f87bed 8488
eec82323
LMI
8489(gnus-ems-redefine)
8490
8491(provide 'gnus-art)
8492
8493(run-hooks 'gnus-art-load-hook)
8494
ab5796a9 8495;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
eec82323 8496;;; gnus-art.el ends here