(article-hide-headers): Don't change the buffer mistakenly when performing
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile
30   (require 'cl)
31   (defvar tool-bar-map))
32
33 (require 'gnus)
34 (require 'gnus-sum)
35 (require 'gnus-spec)
36 (require 'gnus-int)
37 (require 'gnus-win)
38 (require 'mm-bodies)
39 (require 'mail-parse)
40 (require 'mm-decode)
41 (require 'mm-view)
42 (require 'wid-edit)
43 (require 'mm-uu)
44 (require 'message)
45
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'ansi-color-apply-on-region "ansi-color")
50
51 (defgroup gnus-article nil
52   "Article display."
53   :link '(custom-manual "(gnus)Article Buffer")
54   :group 'gnus)
55
56 (defgroup gnus-article-treat nil
57   "Treating article parts."
58   :link '(custom-manual "(gnus)Article Hiding")
59   :group 'gnus-article)
60
61 (defgroup gnus-article-hiding nil
62   "Hiding article parts."
63   :link '(custom-manual "(gnus)Article Hiding")
64   :group 'gnus-article)
65
66 (defgroup gnus-article-highlight nil
67   "Article highlighting."
68   :link '(custom-manual "(gnus)Article Highlighting")
69   :group 'gnus-article
70   :group 'gnus-visual)
71
72 (defgroup gnus-article-signature nil
73   "Article signatures."
74   :link '(custom-manual "(gnus)Article Signature")
75   :group 'gnus-article)
76
77 (defgroup gnus-article-headers nil
78   "Article headers."
79   :link '(custom-manual "(gnus)Hiding Headers")
80   :group 'gnus-article)
81
82 (defgroup gnus-article-washing nil
83   "Special commands on articles."
84   :link '(custom-manual "(gnus)Article Washing")
85   :group 'gnus-article)
86
87 (defgroup gnus-article-emphasis nil
88   "Fontisizing articles."
89   :link '(custom-manual "(gnus)Article Fontisizing")
90   :group 'gnus-article)
91
92 (defgroup gnus-article-saving nil
93   "Saving articles."
94   :link '(custom-manual "(gnus)Saving Articles")
95   :group 'gnus-article)
96
97 (defgroup gnus-article-mime nil
98   "Worshiping the MIME wonder."
99   :link '(custom-manual "(gnus)Using MIME")
100   :group 'gnus-article)
101
102 (defgroup gnus-article-buttons nil
103   "Pushable buttons in the article buffer."
104   :link '(custom-manual "(gnus)Article Buttons")
105   :group 'gnus-article)
106
107 (defgroup gnus-article-various nil
108   "Other article options."
109   :link '(custom-manual "(gnus)Misc Article")
110   :group 'gnus-article)
111
112 (defcustom gnus-ignored-headers
113   (mapcar
114    (lambda (header)
115      (concat "^" header ":"))
116    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
117      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
118      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
119      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
120      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
121      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
122      "X-Attribution" "X-Originating-IP" "Delivered-To"
123      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
124      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
125      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
126      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
127      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
128      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
129      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
130      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
131      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
132      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
133      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
134      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
135      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
136      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
137      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
138      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
139      "List-[A-Za-z]+" "X-Listprocessor-Version"
140      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
141      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
142      "X-Received" "Content-length" "X-precedence"
143      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
144      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
145      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
146      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
147      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
148      "X-Content-length" "X-Posting-Agent" "Original-Received"
149      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
150      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
151      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
152      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
153      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
154   "*All headers that start with this regexp will be hidden.
155 This variable can also be a list of regexps of headers to be ignored.
156 If `gnus-visible-headers' is non-nil, this variable will be ignored."
157   :type '(choice :custom-show nil
158                  regexp
159                  (repeat regexp))
160   :group 'gnus-article-hiding)
161
162 (defcustom gnus-visible-headers
163   "^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:"
164   "*All headers that do not match this regexp will be hidden.
165 This variable can also be a list of regexp of headers to remain visible.
166 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
167   :type '(repeat :value-to-internal (lambda (widget value)
168                                       (custom-split-regexp-maybe value))
169                  :match (lambda (widget value)
170                           (or (stringp value)
171                               (widget-editable-list-match widget value)))
172                  regexp)
173   :group 'gnus-article-hiding)
174
175 (defcustom gnus-sorted-header-list
176   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
177     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
178   "*This variable is a list of regular expressions.
179 If it is non-nil, headers that match the regular expressions will
180 be placed first in the article buffer in the sequence specified by
181 this list."
182   :type '(repeat regexp)
183   :group 'gnus-article-hiding)
184
185 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
186   "Headers that are only to be displayed if they have interesting data.
187 Possible values in this list are:
188
189   'empty       Headers with no content.
190   'newsgroups  Newsgroup identical to Gnus group.
191   'to-address  To identical to To-address.
192   'to-list     To identical to To-list.
193   'cc-list     CC identical to To-list.
194   'followup-to Followup-to identical to Newsgroups.
195   'reply-to    Reply-to identical to From.
196   'date        Date less than four days old.
197   'long-to     To and/or Cc longer than 1024 characters.
198   'many-to     Multiple To and/or Cc."
199   :type '(set (const :tag "Headers with no content." empty)
200               (const :tag "Newsgroups identical to Gnus group." newsgroups)
201               (const :tag "To identical to To-address." to-address)
202               (const :tag "To identical to To-list." to-list)
203               (const :tag "CC identical to To-list." cc-list)
204               (const :tag "Followup-to identical to Newsgroups." followup-to)
205               (const :tag "Reply-to identical to From." reply-to)
206               (const :tag "Date less than four days old." date)
207               (const :tag "To and/or Cc longer than 1024 characters." long-to)
208               (const :tag "Multiple To and/or Cc headers." many-to))
209   :group 'gnus-article-hiding)
210
211 (defcustom gnus-article-skip-boring nil
212   "Skip over text that is not worth reading.
213 By default, if you set this t, then Gnus will display citations and
214 signatures, but will never scroll down to show you a page consisting
215 only of boring text.  Boring text is controlled by
216 `gnus-article-boring-faces'."
217   :type 'boolean
218   :group 'gnus-article-hiding)
219
220 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
221   "Regexp matching signature separator.
222 This can also be a list of regexps.  In that case, it will be checked
223 from head to tail looking for a separator.  Searches will be done from
224 the end of the buffer."
225   :type '(repeat string)
226   :group 'gnus-article-signature)
227
228 (defcustom gnus-signature-limit nil
229   "Provide a limit to what is considered a signature.
230 If it is a number, no signature may not be longer (in characters) than
231 that number.  If it is a floating point number, no signature may be
232 longer (in lines) than that number.  If it is a function, the function
233 will be called without any parameters, and if it returns nil, there is
234 no signature in the buffer.  If it is a string, it will be used as a
235 regexp.  If it matches, the text in question is not a signature.
236
237 This can also be a list of the above values."
238   :type '(choice (integer :value 200)
239                  (number :value 4.0)
240                  (function :value fun)
241                  (regexp :value ".*"))
242   :group 'gnus-article-signature)
243
244 (defcustom gnus-hidden-properties '(invisible t intangible t)
245   "Property list to use for hiding text."
246   :type 'sexp
247   :group 'gnus-article-hiding)
248
249 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
250 ;; frames in a session.
251 (defcustom gnus-article-x-face-command
252   (if (featurep 'xemacs)
253       (if (or (gnus-image-type-available-p 'xface)
254               (gnus-image-type-available-p 'pbm))
255           'gnus-display-x-face-in-from
256         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
257     (if (gnus-image-type-available-p 'pbm)
258         'gnus-display-x-face-in-from
259       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
260 display -"))
261   "*String or function to be executed to display an X-Face header.
262 If it is a string, the command will be executed in a sub-shell
263 asynchronously.  The compressed face will be piped to this command."
264   :type `(choice string
265                  (function-item gnus-display-x-face-in-from)
266                  function)
267   :version "21.1"
268   :group 'gnus-picon
269   :group 'gnus-article-washing)
270
271 (defcustom gnus-article-x-face-too-ugly nil
272   "Regexp matching posters whose face shouldn't be shown automatically."
273   :type '(choice regexp (const nil))
274   :group 'gnus-article-washing)
275
276 (defcustom gnus-article-banner-alist nil
277   "Banner alist for stripping.
278 For example,
279      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
280   :version "21.1"
281   :type '(repeat (cons symbol regexp))
282   :group 'gnus-article-washing)
283
284 (gnus-define-group-parameter
285  banner
286  :variable-document
287  "Alist of regexps (to match group names) and banner."
288  :variable-group gnus-article-washing
289  :parameter-type
290  '(choice :tag "Banner"
291           :value nil
292           (const :tag "Remove signature" signature)
293           (symbol :tag "Item in `gnus-article-banner-alist'" none)
294           regexp
295           (const :tag "None" nil))
296  :parameter-document
297  "If non-nil, specify how to remove `banners' from articles.
298
299 Symbol `signature' means to remove signatures delimited by
300 `gnus-signature-separator'.  Any other symbol is used to look up a
301 regular expression to match the banner in `gnus-article-banner-alist'.
302 A string is used as a regular expression to match the banner
303 directly.")
304
305 (defcustom gnus-article-address-banner-alist nil
306   "Alist of mail addresses and banners.
307 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
308 to match a mail address in the From: header, BANNER is one of a symbol
309 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
310 If ADDRESS matches author's mail address, it will remove things like
311 advertisements.  For example:
312
313 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
314 "
315   :type '(repeat
316           (cons
317            (regexp :tag "Address")
318            (choice :tag "Banner" :value nil
319                    (const :tag "Remove signature" signature)
320                    (symbol :tag "Item in `gnus-article-banner-alist'" none)
321                    regexp
322                    (const :tag "None" nil))))
323   :group 'gnus-article-washing)
324
325 (defcustom gnus-emphasis-alist
326   (let ((format
327          "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
328         (types
329          '(("\\*" "\\*" bold)
330            ("_" "_" underline)
331            ("/" "/" italic)
332            ("_/" "/_" underline-italic)
333            ("_\\*" "\\*_" underline-bold)
334            ("\\*/" "/\\*" bold-italic)
335            ("_\\*/" "/\\*_" underline-bold-italic))))
336     `(,@(mapcar
337          (lambda (spec)
338            (list
339             (format format (car spec) (cadr spec))
340             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
341          types)
342         ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
343          2 3 gnus-emphasis-underline)))
344   "*Alist that says how to fontify certain phrases.
345 Each item looks like this:
346
347   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
348
349 The first element is a regular expression to be matched.  The second
350 is a number that says what regular expression grouping used to find
351 the entire emphasized word.  The third is a number that says what
352 regexp grouping should be displayed and highlighted.  The fourth
353 is the face used for highlighting."
354   :type '(repeat (list :value ("" 0 0 default)
355                        regexp
356                        (integer :tag "Match group")
357                        (integer :tag "Emphasize group")
358                        face))
359   :group 'gnus-article-emphasis)
360
361 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
362   "A regexp to describe whitespace which should not be emphasized.
363 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
364 The former avoids underlining of leading and trailing whitespace,
365 and the latter avoids underlining any whitespace at all."
366   :version "21.1"
367   :group 'gnus-article-emphasis
368   :type 'regexp)
369
370 (defface gnus-emphasis-bold '((t (:bold t)))
371   "Face used for displaying strong emphasized text (*word*)."
372   :group 'gnus-article-emphasis)
373
374 (defface gnus-emphasis-italic '((t (:italic t)))
375   "Face used for displaying italic emphasized text (/word/)."
376   :group 'gnus-article-emphasis)
377
378 (defface gnus-emphasis-underline '((t (:underline t)))
379   "Face used for displaying underlined emphasized text (_word_)."
380   :group 'gnus-article-emphasis)
381
382 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
383   "Face used for displaying underlined bold emphasized text (_*word*_)."
384   :group 'gnus-article-emphasis)
385
386 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
387   "Face used for displaying underlined italic emphasized text (_/word/_)."
388   :group 'gnus-article-emphasis)
389
390 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
391   "Face used for displaying bold italic emphasized text (/*word*/)."
392   :group 'gnus-article-emphasis)
393
394 (defface gnus-emphasis-underline-bold-italic
395   '((t (:bold t :italic t :underline t)))
396   "Face used for displaying underlined bold italic emphasized text.
397 Example: (_/*word*/_)."
398   :group 'gnus-article-emphasis)
399
400 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
401                                       '((t (:strikethru t)))
402                                     '((t (:strike-through t))))
403   "Face used for displaying strike-through text (-word-)."
404   :group 'gnus-article-emphasis)
405
406 (defface gnus-emphasis-highlight-words
407   '((t (:background "black" :foreground "yellow")))
408   "Face used for displaying highlighted words."
409   :group 'gnus-article-emphasis)
410
411 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
412   "Format for display of Date headers in article bodies.
413 See `format-time-string' for the possible values.
414
415 The variable can also be function, which should return a complete Date
416 header.  The function is called with one argument, the time, which can
417 be fed to `format-time-string'."
418   :type '(choice string symbol)
419   :link '(custom-manual "(gnus)Article Date")
420   :group 'gnus-article-washing)
421
422 (eval-and-compile
423   (autoload 'mail-extract-address-components "mail-extr"))
424
425 (defcustom gnus-save-all-headers t
426   "*If non-nil, don't remove any headers before saving."
427   :group 'gnus-article-saving
428   :type 'boolean)
429
430 (defcustom gnus-prompt-before-saving 'always
431   "*This variable says how much prompting is to be done when saving articles.
432 If it is nil, no prompting will be done, and the articles will be
433 saved to the default files.  If this variable is `always', each and
434 every article that is saved will be preceded by a prompt, even when
435 saving large batches of articles.  If this variable is neither nil not
436 `always', there the user will be prompted once for a file name for
437 each invocation of the saving commands."
438   :group 'gnus-article-saving
439   :type '(choice (item always)
440                  (item :tag "never" nil)
441                  (sexp :tag "once" :format "%t\n" :value t)))
442
443 (defcustom gnus-saved-headers gnus-visible-headers
444   "Headers to keep if `gnus-save-all-headers' is nil.
445 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
446 If that variable is nil, however, all headers that match this regexp
447 will be kept while the rest will be deleted before saving."
448   :group 'gnus-article-saving
449   :type 'regexp)
450
451 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
452   "A function to save articles in your favourite format.
453 The function must be interactively callable (in other words, it must
454 be an Emacs command).
455
456 Gnus provides the following functions:
457
458 * gnus-summary-save-in-rmail (Rmail format)
459 * gnus-summary-save-in-mail (Unix mail format)
460 * gnus-summary-save-in-folder (MH folder)
461 * gnus-summary-save-in-file (article format)
462 * gnus-summary-save-body-in-file (article body)
463 * gnus-summary-save-in-vm (use VM's folder format)
464 * gnus-summary-write-to-file (article format -- overwrite)."
465   :group 'gnus-article-saving
466   :type '(radio (function-item gnus-summary-save-in-rmail)
467                 (function-item gnus-summary-save-in-mail)
468                 (function-item gnus-summary-save-in-folder)
469                 (function-item gnus-summary-save-in-file)
470                 (function-item gnus-summary-save-body-in-file)
471                 (function-item gnus-summary-save-in-vm)
472                 (function-item gnus-summary-write-to-file)))
473
474 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
475   "A function generating a file name to save articles in Rmail format.
476 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
477   :group 'gnus-article-saving
478   :type 'function)
479
480 (defcustom gnus-mail-save-name 'gnus-plain-save-name
481   "A function generating a file name to save articles in Unix mail format.
482 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
483   :group 'gnus-article-saving
484   :type 'function)
485
486 (defcustom gnus-folder-save-name 'gnus-folder-save-name
487   "A function generating a file name to save articles in MH folder.
488 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
489   :group 'gnus-article-saving
490   :type 'function)
491
492 (defcustom gnus-file-save-name 'gnus-numeric-save-name
493   "A function generating a file name to save articles in article format.
494 The function is called with NEWSGROUP, HEADERS, and optional
495 LAST-FILE."
496   :group 'gnus-article-saving
497   :type 'function)
498
499 (defcustom gnus-split-methods
500   '((gnus-article-archive-name)
501     (gnus-article-nndoc-name))
502   "*Variable used to suggest where articles are to be saved.
503 For instance, if you would like to save articles related to Gnus in
504 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
505 you could set this variable to something like:
506
507  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
508    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
509
510 This variable is an alist where the where the key is the match and the
511 value is a list of possible files to save in if the match is non-nil.
512
513 If the match is a string, it is used as a regexp match on the
514 article.  If the match is a symbol, that symbol will be funcalled
515 from the buffer of the article to be saved with the newsgroup as the
516 parameter.  If it is a list, it will be evaled in the same buffer.
517
518 If this form or function returns a string, this string will be used as
519 a possible file name; and if it returns a non-nil list, that list will
520 be used as possible file names."
521   :group 'gnus-article-saving
522   :type '(repeat (choice (list :value (fun) function)
523                          (cons :value ("" "") regexp (repeat string))
524                          (sexp :value nil))))
525
526 (defcustom gnus-page-delimiter "^\^L"
527   "*Regexp describing what to use as article page delimiters.
528 The default value is \"^\^L\", which is a form linefeed at the
529 beginning of a line."
530   :type 'regexp
531   :group 'gnus-article-various)
532
533 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
534   "*The format specification for the article mode line.
535 See `gnus-summary-mode-line-format' for a closer description.
536
537 The following additional specs are available:
538
539 %w  The article washing status.
540 %m  The number of MIME parts in the article."
541   :type 'string
542   :group 'gnus-article-various)
543
544 (defcustom gnus-article-mode-hook nil
545   "*A hook for Gnus article mode."
546   :type 'hook
547   :group 'gnus-article-various)
548
549 (when (featurep 'xemacs)
550   ;; Extracted from gnus-xmas-define in order to preserve user settings
551   (when (fboundp 'turn-off-scroll-in-place)
552     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
553   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
554   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
555
556 (defcustom gnus-article-menu-hook nil
557   "*Hook run after the creation of the article mode menu."
558   :type 'hook
559   :group 'gnus-article-various)
560
561 (defcustom gnus-article-prepare-hook nil
562   "*A hook called after an article has been prepared in the article buffer."
563   :type 'hook
564   :group 'gnus-article-various)
565
566 (make-obsolete-variable 'gnus-article-hide-pgp-hook
567                         "This variable is obsolete in Gnus 5.10.")
568
569 (defcustom gnus-article-button-face 'bold
570   "Face used for highlighting buttons in the article buffer.
571
572 An article button is a piece of text that you can activate by pressing
573 `RET' or `mouse-2' above it."
574   :type 'face
575   :group 'gnus-article-buttons)
576
577 (defcustom gnus-article-mouse-face 'highlight
578   "Face used for mouse highlighting in the article buffer.
579
580 Article buttons will be displayed in this face when the cursor is
581 above them."
582   :type 'face
583   :group 'gnus-article-buttons)
584
585 (defcustom gnus-signature-face 'gnus-signature-face
586   "Face used for highlighting a signature in the article buffer.
587 Obsolete; use the face `gnus-signature-face' for customizations instead."
588   :type 'face
589   :group 'gnus-article-highlight
590   :group 'gnus-article-signature)
591
592 (defface gnus-signature-face
593   '((t
594      (:italic t)))
595   "Face used for highlighting a signature in the article buffer."
596   :group 'gnus-article-highlight
597   :group 'gnus-article-signature)
598
599 (defface gnus-header-from-face
600   '((((class color)
601       (background dark))
602      (:foreground "spring green"))
603     (((class color)
604       (background light))
605      (:foreground "red3"))
606     (t
607      (:italic t)))
608   "Face used for displaying from headers."
609   :group 'gnus-article-headers
610   :group 'gnus-article-highlight)
611
612 (defface gnus-header-subject-face
613   '((((class color)
614       (background dark))
615      (:foreground "SeaGreen3"))
616     (((class color)
617       (background light))
618      (:foreground "red4"))
619     (t
620      (:bold t :italic t)))
621   "Face used for displaying subject headers."
622   :group 'gnus-article-headers
623   :group 'gnus-article-highlight)
624
625 (defface gnus-header-newsgroups-face
626   '((((class color)
627       (background dark))
628      (:foreground "yellow" :italic t))
629     (((class color)
630       (background light))
631      (:foreground "MidnightBlue" :italic t))
632     (t
633      (:italic t)))
634   "Face used for displaying newsgroups headers.
635 In the default setup this face is only used for crossposted
636 articles."
637   :group 'gnus-article-headers
638   :group 'gnus-article-highlight)
639
640 (defface gnus-header-name-face
641   '((((class color)
642       (background dark))
643      (:foreground "SeaGreen"))
644     (((class color)
645       (background light))
646      (:foreground "maroon"))
647     (t
648      (:bold t)))
649   "Face used for displaying header names."
650   :group 'gnus-article-headers
651   :group 'gnus-article-highlight)
652
653 (defface gnus-header-content-face
654   '((((class color)
655       (background dark))
656      (:foreground "forest green" :italic t))
657     (((class color)
658       (background light))
659      (:foreground "indianred4" :italic t))
660     (t
661      (:italic t)))  "Face used for displaying header content."
662   :group 'gnus-article-headers
663   :group 'gnus-article-highlight)
664
665 (defcustom gnus-header-face-alist
666   '(("From" nil gnus-header-from-face)
667     ("Subject" nil gnus-header-subject-face)
668     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
669     ("" gnus-header-name-face gnus-header-content-face))
670   "*Controls highlighting of article headers.
671
672 An alist of the form (HEADER NAME CONTENT).
673
674 HEADER is a regular expression which should match the name of a
675 header and NAME and CONTENT are either face names or nil.
676
677 The name of each header field will be displayed using the face
678 specified by the first element in the list where HEADER matches
679 the header name and NAME is non-nil.  Similarly, the content will
680 be displayed by the first non-nil matching CONTENT face."
681   :group 'gnus-article-headers
682   :group 'gnus-article-highlight
683   :type '(repeat (list (regexp :tag "Header")
684                        (choice :tag "Name"
685                                (item :tag "skip" nil)
686                                (face :value default))
687                        (choice :tag "Content"
688                                (item :tag "skip" nil)
689                                (face :value default)))))
690
691 (defcustom gnus-article-decode-hook
692   '(article-decode-charset article-decode-encoded-words
693                            article-decode-group-name article-decode-idna-rhs)
694   "*Hook run to decode charsets in articles."
695   :group 'gnus-article-headers
696   :type 'hook)
697
698 (defcustom gnus-display-mime-function 'gnus-display-mime
699   "Function to display MIME articles."
700   :group 'gnus-article-mime
701   :type 'function)
702
703 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
704   "Function used to decode headers.")
705
706 (defvar gnus-article-dumbquotes-map
707   '(("\200" "EUR")
708     ("\202" ",")
709     ("\203" "f")
710     ("\204" ",,")
711     ("\205" "...")
712     ("\213" "<")
713     ("\214" "OE")
714     ("\221" "`")
715     ("\222" "'")
716     ("\223" "``")
717     ("\224" "\"")
718     ("\225" "*")
719     ("\226" "-")
720     ("\227" "--")
721     ("\230" "~")
722     ("\231" "(TM)")
723     ("\233" ">")
724     ("\234" "oe")
725     ("\264" "'"))
726   "Table for MS-to-Latin1 translation.")
727
728 (defcustom gnus-ignored-mime-types nil
729   "List of MIME types that should be ignored by Gnus."
730   :version "21.1"
731   :group 'gnus-article-mime
732   :type '(repeat regexp))
733
734 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
735   "List of MIME types that should not be given buttons when rendered inline.
736 See also `gnus-buttonized-mime-types' which may override this variable.
737 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
738   :version "21.1"
739   :group 'gnus-article-mime
740   :type '(repeat regexp))
741
742 (defcustom gnus-buttonized-mime-types nil
743   "List of MIME types that should be given buttons when rendered inline.
744 If set, this variable overrides `gnus-unbuttonized-mime-types'.
745 To see e.g. security buttons you could set this to
746 `(\"multipart/signed\")'.
747 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
748   :version "21.1"
749   :group 'gnus-article-mime
750   :type '(repeat regexp))
751
752 (defcustom gnus-inhibit-mime-unbuttonizing nil
753   "If non-nil, all MIME parts get buttons.
754 When nil (the default value), then some MIME parts do not get buttons,
755 as described by the variables `gnus-buttonized-mime-types' and
756 `gnus-unbuttonized-mime-types'."
757   :version "21.3"
758   :group 'gnus-article-mime
759   :type 'boolean)
760
761 (defcustom gnus-body-boundary-delimiter "_"
762   "String used to delimit header and body.
763 This variable is used by `gnus-article-treat-body-boundary' which can
764 be controlled by `gnus-treat-body-boundary'."
765   :group 'gnus-article-various
766   :type '(choice (item :tag "None" :value nil)
767                  string))
768
769 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
770                                   "/usr/share/picons")
771   "Defines the location of the faces database.
772 For information on obtaining this database of pretty pictures, please
773 see http://www.cs.indiana.edu/picons/ftp/index.html"
774   :type '(repeat directory)
775   :link '(url-link :tag "download"
776                    "http://www.cs.indiana.edu/picons/ftp/index.html")
777   :link '(custom-manual "(gnus)Picons")
778   :group 'gnus-picon)
779
780 (defun gnus-picons-installed-p ()
781   "Say whether picons are installed on your machine."
782   (let ((installed nil))
783     (dolist (database gnus-picon-databases)
784       (when (file-exists-p database)
785         (setq installed t)))
786     installed))
787
788 (defcustom gnus-article-mime-part-function nil
789   "Function called with a MIME handle as the argument.
790 This is meant for people who want to do something automatic based
791 on parts -- for instance, adding Vcard info to a database."
792   :group 'gnus-article-mime
793   :type 'function)
794
795 (defcustom gnus-mime-multipart-functions nil
796   "An alist of MIME types to functions to display them."
797   :version "21.1"
798   :group 'gnus-article-mime
799   :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
800
801 (defcustom gnus-article-date-lapsed-new-header nil
802   "Whether the X-Sent and Date headers can coexist.
803 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
804 either replace the old \"Date:\" header (if this variable is nil), or
805 be added below it (otherwise)."
806   :version "21.1"
807   :group 'gnus-article-headers
808   :type 'boolean)
809
810 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
811   "Function called with a MIME handle as the argument.
812 This is meant for people who want to view first matched part.
813 For `undisplayed-alternative' (default), the first undisplayed
814 part or alternative part is used.  For `undisplayed', the first
815 undisplayed part is used.  For a function, the first part which
816 the function return t is used.  For nil, the first part is
817 used."
818   :version "21.1"
819   :group 'gnus-article-mime
820   :type '(choice
821           (item :tag "first" :value nil)
822           (item :tag "undisplayed" :value undisplayed)
823           (item :tag "undisplayed or alternative"
824                 :value undisplayed-alternative)
825           (function)))
826
827 (defcustom gnus-mime-action-alist
828   '(("save to file" . gnus-mime-save-part)
829     ("save and strip" . gnus-mime-save-part-and-strip)
830     ("delete part" . gnus-mime-delete-part)
831     ("display as text" . gnus-mime-inline-part)
832     ("view the part" . gnus-mime-view-part)
833     ("pipe to command" . gnus-mime-pipe-part)
834     ("toggle display" . gnus-article-press-button)
835     ("toggle display" . gnus-article-view-part-as-charset)
836     ("view as type" . gnus-mime-view-part-as-type)
837     ("view internally" . gnus-mime-view-part-internally)
838     ("view externally" . gnus-mime-view-part-externally))
839   "An alist of actions that run on the MIME attachment."
840   :group 'gnus-article-mime
841   :type '(repeat (cons (string :tag "name")
842                        (function))))
843
844 ;;;
845 ;;; The treatment variables
846 ;;;
847
848 (defvar gnus-part-display-hook nil
849   "Hook called on parts that are to receive treatment.")
850
851 (defvar gnus-article-treat-custom
852   '(choice (const :tag "Off" nil)
853            (const :tag "On" t)
854            (const :tag "Header" head)
855            (const :tag "Last" last)
856            (integer :tag "Less")
857            (repeat :tag "Groups" regexp)
858            (sexp :tag "Predicate")))
859
860 (defvar gnus-article-treat-head-custom
861   '(choice (const :tag "Off" nil)
862            (const :tag "Header" head)))
863
864 (defvar gnus-article-treat-types '("text/plain")
865   "Parts to treat.")
866
867 (defvar gnus-inhibit-treatment nil
868   "Whether to inhibit treatment.")
869
870 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
871   "Highlight the signature.
872 Valid values are nil, t, `head', `last', an integer or a predicate.
873 See Info node `(gnus)Customizing Articles'."
874   :group 'gnus-article-treat
875   :link '(custom-manual "(gnus)Customizing Articles")
876   :type gnus-article-treat-custom)
877 (put 'gnus-treat-highlight-signature 'highlight t)
878
879 (defcustom gnus-treat-buttonize 100000
880   "Add buttons.
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See Info node `(gnus)Customizing Articles'."
883   :group 'gnus-article-treat
884   :link '(custom-manual "(gnus)Customizing Articles")
885   :type gnus-article-treat-custom)
886 (put 'gnus-treat-buttonize 'highlight t)
887
888 (defcustom gnus-treat-buttonize-head 'head
889   "Add buttons to the head.
890 Valid values are nil, t, `head', `last', an integer or a predicate.
891 See Info node `(gnus)Customizing Articles' for details."
892   :group 'gnus-article-treat
893   :link '(custom-manual "(gnus)Customizing Articles")
894   :type gnus-article-treat-head-custom)
895 (put 'gnus-treat-buttonize-head 'highlight t)
896
897 (defcustom gnus-treat-emphasize
898   (and (or window-system
899            (featurep 'xemacs))
900        50000)
901   "Emphasize text.
902 Valid values are nil, t, `head', `last', an integer or a predicate.
903 See Info node `(gnus)Customizing Articles' for details."
904   :group 'gnus-article-treat
905   :link '(custom-manual "(gnus)Customizing Articles")
906   :type gnus-article-treat-custom)
907 (put 'gnus-treat-emphasize 'highlight t)
908
909 (defcustom gnus-treat-strip-cr nil
910   "Remove carriage returns.
911 Valid values are nil, t, `head', `last', an integer or a predicate.
912 See Info node `(gnus)Customizing Articles' for details."
913   :group 'gnus-article-treat
914   :link '(custom-manual "(gnus)Customizing Articles")
915   :type gnus-article-treat-custom)
916
917 (defcustom gnus-treat-unsplit-urls nil
918   "Remove newlines from within URLs.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See Info node `(gnus)Customizing Articles' for details."
921   :group 'gnus-article-treat
922   :link '(custom-manual "(gnus)Customizing Articles")
923   :type gnus-article-treat-custom)
924
925 (defcustom gnus-treat-leading-whitespace nil
926   "Remove leading whitespace in headers.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See Info node `(gnus)Customizing Articles' for details."
929   :group 'gnus-article-treat
930   :link '(custom-manual "(gnus)Customizing Articles")
931   :type gnus-article-treat-custom)
932
933 (defcustom gnus-treat-hide-headers 'head
934   "Hide headers.
935 Valid values are nil, t, `head', `last', an integer or a predicate.
936 See Info node `(gnus)Customizing Articles' for details."
937   :group 'gnus-article-treat
938   :link '(custom-manual "(gnus)Customizing Articles")
939   :type gnus-article-treat-head-custom)
940
941 (defcustom gnus-treat-hide-boring-headers nil
942   "Hide boring headers.
943 Valid values are nil, t, `head', `last', an integer or a predicate.
944 See Info node `(gnus)Customizing Articles' for details."
945   :group 'gnus-article-treat
946   :link '(custom-manual "(gnus)Customizing Articles")
947   :type gnus-article-treat-head-custom)
948
949 (defcustom gnus-treat-hide-signature nil
950   "Hide the signature.
951 Valid values are nil, t, `head', `last', an integer or a predicate.
952 See Info node `(gnus)Customizing Articles' for details."
953   :group 'gnus-article-treat
954   :link '(custom-manual "(gnus)Customizing Articles")
955   :type gnus-article-treat-custom)
956
957 (defcustom gnus-treat-fill-article nil
958   "Fill the article.
959 Valid values are nil, t, `head', `last', an integer or a predicate.
960 See Info node `(gnus)Customizing Articles' for details."
961   :group 'gnus-article-treat
962   :link '(custom-manual "(gnus)Customizing Articles")
963   :type gnus-article-treat-custom)
964
965 (defcustom gnus-treat-hide-citation nil
966   "Hide cited text.
967 Valid values are nil, t, `head', `last', an integer or a predicate.
968 See Info node `(gnus)Customizing Articles' for details."
969   :group 'gnus-article-treat
970   :link '(custom-manual "(gnus)Customizing Articles")
971   :type gnus-article-treat-custom)
972
973 (defcustom gnus-treat-hide-citation-maybe nil
974   "Hide cited text.
975 Valid values are nil, t, `head', `last', an integer or a predicate.
976 See Info node `(gnus)Customizing Articles' for details."
977   :group 'gnus-article-treat
978   :link '(custom-manual "(gnus)Customizing Articles")
979   :type gnus-article-treat-custom)
980
981 (defcustom gnus-treat-strip-list-identifiers 'head
982   "Strip list identifiers from `gnus-list-identifiers`.
983 Valid values are nil, t, `head', `last', an integer or a predicate.
984 See Info node `(gnus)Customizing Articles' for details."
985   :version "21.1"
986   :group 'gnus-article-treat
987   :link '(custom-manual "(gnus)Customizing Articles")
988   :type gnus-article-treat-custom)
989
990 (make-obsolete-variable 'gnus-treat-strip-pgp
991                         "This option is obsolete in Gnus 5.10.")
992
993 (defcustom gnus-treat-strip-pem nil
994   "Strip PEM signatures.
995 Valid values are nil, t, `head', `last', an integer or a predicate.
996 See Info node `(gnus)Customizing Articles' for details."
997   :group 'gnus-article-treat
998   :link '(custom-manual "(gnus)Customizing Articles")
999   :type gnus-article-treat-custom)
1000
1001 (defcustom gnus-treat-strip-banner t
1002   "Strip banners from articles.
1003 The banner to be stripped is specified in the `banner' group parameter.
1004 Valid values are nil, t, `head', `last', an integer or a predicate.
1005 See Info node `(gnus)Customizing Articles' for details."
1006   :group 'gnus-article-treat
1007   :link '(custom-manual "(gnus)Customizing Articles")
1008   :type gnus-article-treat-custom)
1009
1010 (defcustom gnus-treat-highlight-headers 'head
1011   "Highlight the headers.
1012 Valid values are nil, t, `head', `last', an integer or a predicate.
1013 See Info node `(gnus)Customizing Articles' for details."
1014   :group 'gnus-article-treat
1015   :link '(custom-manual "(gnus)Customizing Articles")
1016   :type gnus-article-treat-head-custom)
1017 (put 'gnus-treat-highlight-headers 'highlight t)
1018
1019 (defcustom gnus-treat-highlight-citation t
1020   "Highlight cited text.
1021 Valid values are nil, t, `head', `last', an integer or a predicate.
1022 See Info node `(gnus)Customizing Articles' for details."
1023   :group 'gnus-article-treat
1024   :link '(custom-manual "(gnus)Customizing Articles")
1025   :type gnus-article-treat-custom)
1026 (put 'gnus-treat-highlight-citation 'highlight t)
1027
1028 (defcustom gnus-treat-date-ut nil
1029   "Display the Date in UT (GMT).
1030 Valid values are nil, t, `head', `last', an integer or a predicate.
1031 See Info node `(gnus)Customizing Articles' for details."
1032   :group 'gnus-article-treat
1033   :link '(custom-manual "(gnus)Customizing Articles")
1034   :type gnus-article-treat-head-custom)
1035
1036 (defcustom gnus-treat-date-local nil
1037   "Display the Date in the local timezone.
1038 Valid values are nil, t, `head', `last', an integer or a predicate.
1039 See Info node `(gnus)Customizing Articles' for details."
1040   :group 'gnus-article-treat
1041   :link '(custom-manual "(gnus)Customizing Articles")
1042   :type gnus-article-treat-head-custom)
1043
1044 (defcustom gnus-treat-date-english nil
1045   "Display the Date in a format that can be read aloud in English.
1046 Valid values are nil, t, `head', `last', an integer or a predicate.
1047 See Info node `(gnus)Customizing Articles' for details."
1048   :group 'gnus-article-treat
1049   :link '(custom-manual "(gnus)Customizing Articles")
1050   :type gnus-article-treat-head-custom)
1051
1052 (defcustom gnus-treat-date-lapsed nil
1053   "Display the Date header in a way that says how much time has elapsed.
1054 Valid values are nil, t, `head', `last', an integer or a predicate.
1055 See Info node `(gnus)Customizing Articles' for details."
1056   :group 'gnus-article-treat
1057   :link '(custom-manual "(gnus)Customizing Articles")
1058   :type gnus-article-treat-head-custom)
1059
1060 (defcustom gnus-treat-date-original nil
1061   "Display the date in the original timezone.
1062 Valid values are nil, t, `head', `last', an integer or a predicate.
1063 See Info node `(gnus)Customizing Articles' for details."
1064   :group 'gnus-article-treat
1065   :link '(custom-manual "(gnus)Customizing Articles")
1066   :type gnus-article-treat-head-custom)
1067
1068 (defcustom gnus-treat-date-iso8601 nil
1069   "Display the date in the ISO8601 format.
1070 Valid values are nil, t, `head', `last', an integer or a predicate.
1071 See Info node `(gnus)Customizing Articles' for details."
1072   :version "21.1"
1073   :group 'gnus-article-treat
1074   :link '(custom-manual "(gnus)Customizing Articles")
1075   :type gnus-article-treat-head-custom)
1076
1077 (defcustom gnus-treat-date-user-defined nil
1078   "Display the date in a user-defined format.
1079 The format is defined by the `gnus-article-time-format' variable.
1080 Valid values are nil, t, `head', `last', an integer or a predicate.
1081 See Info node `(gnus)Customizing Articles' for details."
1082   :group 'gnus-article-treat
1083   :link '(custom-manual "(gnus)Customizing Articles")
1084   :type gnus-article-treat-head-custom)
1085
1086 (defcustom gnus-treat-strip-headers-in-body t
1087   "Strip the X-No-Archive header line from the beginning of the body.
1088 Valid values are nil, t, `head', `last', an integer or a predicate.
1089 See Info node `(gnus)Customizing Articles' for details."
1090   :version "21.1"
1091   :group 'gnus-article-treat
1092   :link '(custom-manual "(gnus)Customizing Articles")
1093   :type gnus-article-treat-custom)
1094
1095 (defcustom gnus-treat-strip-trailing-blank-lines nil
1096   "Strip trailing blank lines.
1097 Valid values are nil, t, `head', `last', an integer or a predicate.
1098 See Info node `(gnus)Customizing Articles' for details."
1099   :group 'gnus-article-treat
1100   :link '(custom-manual "(gnus)Customizing Articles")
1101   :type gnus-article-treat-custom)
1102
1103 (defcustom gnus-treat-strip-leading-blank-lines nil
1104   "Strip leading blank lines.
1105 Valid values are nil, t, `head', `last', an integer or a predicate.
1106 See Info node `(gnus)Customizing Articles' for details."
1107   :group 'gnus-article-treat
1108   :link '(custom-manual "(gnus)Customizing Articles")
1109   :type gnus-article-treat-custom)
1110
1111 (defcustom gnus-treat-strip-multiple-blank-lines nil
1112   "Strip multiple blank lines.
1113 Valid values are nil, t, `head', `last', an integer or a predicate.
1114 See Info node `(gnus)Customizing Articles' for details."
1115   :group 'gnus-article-treat
1116   :link '(custom-manual "(gnus)Customizing Articles")
1117   :type gnus-article-treat-custom)
1118
1119 (defcustom gnus-treat-unfold-headers 'head
1120   "Unfold folded header lines.
1121 Valid values are nil, t, `head', `last', an integer or a predicate.
1122 See Info node `(gnus)Customizing Articles' for details."
1123   :group 'gnus-article-treat
1124   :link '(custom-manual "(gnus)Customizing Articles")
1125   :type gnus-article-treat-custom)
1126
1127 (defcustom gnus-treat-fold-headers nil
1128   "Fold headers.
1129 Valid values are nil, t, `head', `last', an integer or a predicate.
1130 See Info node `(gnus)Customizing Articles' for details."
1131   :group 'gnus-article-treat
1132   :link '(custom-manual "(gnus)Customizing Articles")
1133   :type gnus-article-treat-custom)
1134
1135 (defcustom gnus-treat-fold-newsgroups 'head
1136   "Fold the Newsgroups and Followup-To headers.
1137 Valid values are nil, t, `head', `last', an integer or a predicate.
1138 See Info node `(gnus)Customizing Articles' for details."
1139   :group 'gnus-article-treat
1140   :link '(custom-manual "(gnus)Customizing Articles")
1141   :type gnus-article-treat-custom)
1142
1143 (defcustom gnus-treat-overstrike t
1144   "Treat overstrike highlighting.
1145 Valid values are nil, t, `head', `last', an integer or a predicate.
1146 See Info node `(gnus)Customizing Articles' for details."
1147   :group 'gnus-article-treat
1148   :link '(custom-manual "(gnus)Customizing Articles")
1149   :type gnus-article-treat-custom)
1150 (put 'gnus-treat-overstrike 'highlight t)
1151
1152 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1153   "Treat ANSI SGR control sequences.
1154 Valid values are nil, t, `head', `last', an integer or a predicate.
1155 See Info node `(gnus)Customizing Articles' for details."
1156   :group 'gnus-article-treat
1157   :link '(custom-manual "(gnus)Customizing Articles")
1158   :type gnus-article-treat-custom)
1159
1160 (make-obsolete-variable 'gnus-treat-display-xface
1161                         'gnus-treat-display-x-face)
1162
1163 (defcustom gnus-treat-display-x-face
1164   (and (not noninteractive)
1165        (or (and (fboundp 'image-type-available-p)
1166                 (image-type-available-p 'xbm)
1167                 (string-match "^0x" (shell-command-to-string "uncompface"))
1168                 (executable-find "icontopbm"))
1169            (and (featurep 'xemacs)
1170                 (featurep 'xface)))
1171        'head)
1172   "Display X-Face headers.
1173 Valid values are nil, t, `head', `last', an integer or a predicate.
1174 See Info node `(gnus)Customizing Articles' and Info node
1175 `(gnus)X-Face' for details."
1176   :group 'gnus-article-treat
1177   :version "21.1"
1178   :link '(custom-manual "(gnus)Customizing Articles")
1179   :link '(custom-manual "(gnus)X-Face")
1180   :type gnus-article-treat-head-custom
1181   :set (lambda (symbol value)
1182          (set-default
1183           symbol
1184           (cond ((or (boundp symbol) (get symbol 'saved-value))
1185                  value)
1186                 ((boundp 'gnus-treat-display-xface)
1187                  (message "\
1188 ** gnus-treat-display-xface is an obsolete variable;\
1189  use gnus-treat-display-x-face instead")
1190                  (default-value 'gnus-treat-display-xface))
1191                 ((get 'gnus-treat-display-xface 'saved-value)
1192                  (message "\
1193 ** gnus-treat-display-xface is an obsolete variable;\
1194  use gnus-treat-display-x-face instead")
1195                  (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1196                 (t
1197                  value)))))
1198 (put 'gnus-treat-display-x-face 'highlight t)
1199
1200 (defcustom gnus-treat-display-face
1201   (and (not noninteractive)
1202        (or (and (fboundp 'image-type-available-p)
1203                 (image-type-available-p 'png))
1204            (and (featurep 'xemacs)
1205                 (featurep 'png)))
1206        'head)
1207   "Display Face headers.
1208 Valid values are nil, t, `head', `last', an integer or a predicate.
1209 See Info node `(gnus)Customizing Articles' and Info node
1210 `(gnus)X-Face' for details."
1211   :group 'gnus-article-treat
1212   :version "21.1"
1213   :link '(custom-manual "(gnus)Customizing Articles")
1214   :link '(custom-manual "(gnus)X-Face")
1215   :type gnus-article-treat-head-custom)
1216 (put 'gnus-treat-display-face 'highlight t)
1217
1218 (defcustom gnus-treat-display-smileys
1219   (if (or (and (featurep 'xemacs)
1220                (featurep 'xpm))
1221           (and (fboundp 'image-type-available-p)
1222                (image-type-available-p 'pbm)))
1223       t nil)
1224   "Display smileys.
1225 Valid values are nil, t, `head', `last', an integer or a predicate.
1226 See Info node `(gnus)Customizing Articles' and Info node
1227 `(gnus)Smileys' for details."
1228   :group 'gnus-article-treat
1229   :version "21.1"
1230   :link '(custom-manual "(gnus)Customizing Articles")
1231   :link '(custom-manual "(gnus)Smileys")
1232   :type gnus-article-treat-custom)
1233 (put 'gnus-treat-display-smileys 'highlight t)
1234
1235 (defcustom gnus-treat-from-picon
1236   (if (and (gnus-image-type-available-p 'xpm)
1237            (gnus-picons-installed-p))
1238       'head nil)
1239   "Display picons in the From header.
1240 Valid values are nil, t, `head', `last', an integer or a predicate.
1241 See Info node `(gnus)Customizing Articles' and Info node
1242 `(gnus)Picons' for details."
1243   :group 'gnus-article-treat
1244   :group 'gnus-picon
1245   :link '(custom-manual "(gnus)Customizing Articles")
1246   :link '(custom-manual "(gnus)Picons")
1247   :type gnus-article-treat-head-custom)
1248 (put 'gnus-treat-from-picon 'highlight t)
1249
1250 (defcustom gnus-treat-mail-picon
1251   (if (and (gnus-image-type-available-p 'xpm)
1252            (gnus-picons-installed-p))
1253       'head nil)
1254   "Display picons in To and Cc headers.
1255 Valid values are nil, t, `head', `last', an integer or a predicate.
1256 See Info node `(gnus)Customizing Articles' and Info node
1257 `(gnus)Picons' for details."
1258   :group 'gnus-article-treat
1259   :group 'gnus-picon
1260   :link '(custom-manual "(gnus)Customizing Articles")
1261   :link '(custom-manual "(gnus)Picons")
1262   :type gnus-article-treat-head-custom)
1263 (put 'gnus-treat-mail-picon 'highlight t)
1264
1265 (defcustom gnus-treat-newsgroups-picon
1266   (if (and (gnus-image-type-available-p 'xpm)
1267            (gnus-picons-installed-p))
1268       'head nil)
1269   "Display picons in the Newsgroups and Followup-To headers.
1270 Valid values are nil, t, `head', `last', an integer or a predicate.
1271 See Info node `(gnus)Customizing Articles' and Info node
1272 `(gnus)Picons' for details."
1273   :group 'gnus-article-treat
1274   :group 'gnus-picon
1275   :link '(custom-manual "(gnus)Customizing Articles")
1276   :link '(custom-manual "(gnus)Picons")
1277   :type gnus-article-treat-head-custom)
1278 (put 'gnus-treat-newsgroups-picon 'highlight t)
1279
1280 (defcustom gnus-treat-body-boundary
1281   (if (or gnus-treat-newsgroups-picon
1282           gnus-treat-mail-picon
1283           gnus-treat-from-picon)
1284       'head nil)
1285   "Draw a boundary at the end of the headers.
1286 Valid values are nil and `head'.
1287 See Info node `(gnus)Customizing Articles' for details."
1288   :version "21.1"
1289   :group 'gnus-article-treat
1290   :link '(custom-manual "(gnus)Customizing Articles")
1291   :type gnus-article-treat-head-custom)
1292
1293 (defcustom gnus-treat-capitalize-sentences nil
1294   "Capitalize sentence-starting words.
1295 Valid values are nil, t, `head', `last', an integer or a predicate.
1296 See Info node `(gnus)Customizing Articles' for details."
1297   :version "21.1"
1298   :group 'gnus-article-treat
1299   :link '(custom-manual "(gnus)Customizing Articles")
1300   :type gnus-article-treat-custom)
1301
1302 (defcustom gnus-treat-wash-html nil
1303   "Format as HTML.
1304 Valid values are nil, t, `head', `last', an integer or a predicate.
1305 See Info node `(gnus)Customizing Articles' for details."
1306   :group 'gnus-article-treat
1307   :link '(custom-manual "(gnus)Customizing Articles")
1308   :type gnus-article-treat-custom)
1309
1310 (defcustom gnus-treat-fill-long-lines nil
1311   "Fill long lines.
1312 Valid values are nil, t, `head', `last', an integer or a predicate.
1313 See Info node `(gnus)Customizing Articles' for details."
1314   :group 'gnus-article-treat
1315   :link '(custom-manual "(gnus)Customizing Articles")
1316   :type gnus-article-treat-custom)
1317
1318 (defcustom gnus-treat-play-sounds nil
1319   "Play sounds.
1320 Valid values are nil, t, `head', `last', an integer or a predicate.
1321 See Info node `(gnus)Customizing Articles' for details."
1322   :version "21.1"
1323   :group 'gnus-article-treat
1324   :link '(custom-manual "(gnus)Customizing Articles")
1325   :type gnus-article-treat-custom)
1326
1327 (defcustom gnus-treat-translate nil
1328   "Translate articles from one language to another.
1329 Valid values are nil, t, `head', `last', an integer or a predicate.
1330 See Info node `(gnus)Customizing Articles' for details."
1331   :version "21.1"
1332   :group 'gnus-article-treat
1333   :link '(custom-manual "(gnus)Customizing Articles")
1334   :type gnus-article-treat-custom)
1335
1336 (defcustom gnus-treat-x-pgp-sig nil
1337   "Verify X-PGP-Sig.
1338 To automatically treat X-PGP-Sig, set it to head.
1339 Valid values are nil, t, `head', `last', an integer or a predicate.
1340 See Info node `(gnus)Customizing Articles' for details."
1341   :group 'gnus-article-treat
1342   :group 'mime-security
1343   :link '(custom-manual "(gnus)Customizing Articles")
1344   :type gnus-article-treat-custom)
1345
1346 (defvar gnus-article-encrypt-protocol-alist
1347   '(("PGP" . mml2015-self-encrypt)))
1348
1349 ;; Set to nil if more than one protocol added to
1350 ;; gnus-article-encrypt-protocol-alist.
1351 (defcustom gnus-article-encrypt-protocol "PGP"
1352   "The protocol used for encrypt articles.
1353 It is a string, such as \"PGP\". If nil, ask user."
1354   :type 'string
1355   :group 'mime-security)
1356
1357 (defvar gnus-article-wash-function nil
1358   "Function used for converting HTML into text.")
1359
1360 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1361                               (mm-coding-system-p 'utf-8)
1362                               (executable-find idna-program))
1363   "Whether IDNA decoding of headers is used when viewing messages.
1364 This requires GNU Libidn, and by default only enabled if it is found."
1365   :group 'gnus-article-headers
1366   :type 'boolean)
1367
1368 (defcustom gnus-article-over-scroll nil
1369   "If non-nil, allow scrolling the article buffer even when there no more text."
1370   :group 'gnus-article
1371   :type 'boolean)
1372
1373 ;;; Internal variables
1374
1375 (defvar gnus-english-month-names
1376   '("January" "February" "March" "April" "May" "June" "July" "August"
1377     "September" "October" "November" "December"))
1378
1379 (defvar gnus-button-regexp nil)
1380 (defvar gnus-button-marker-list nil)
1381 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1382
1383 (defvar gnus-button-last nil)
1384 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1385
1386 (defvar article-goto-body-goes-to-point-min-p nil)
1387 (defvar gnus-article-wash-types nil)
1388 (defvar gnus-article-emphasis-alist nil)
1389 (defvar gnus-article-image-alist nil)
1390
1391 (defvar gnus-article-mime-handle-alist-1 nil)
1392 (defvar gnus-treatment-function-alist
1393   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1394     (gnus-treat-strip-banner gnus-article-strip-banner)
1395     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1396     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1397     (gnus-treat-buttonize gnus-article-add-buttons)
1398     (gnus-treat-fill-article gnus-article-fill-cited-article)
1399     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1400     (gnus-treat-strip-cr gnus-article-remove-cr)
1401     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1402     (gnus-treat-date-ut gnus-article-date-ut)
1403     (gnus-treat-date-local gnus-article-date-local)
1404     (gnus-treat-date-english gnus-article-date-english)
1405     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1406     (gnus-treat-date-original gnus-article-date-original)
1407     (gnus-treat-date-user-defined gnus-article-date-user)
1408     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1409     (gnus-treat-display-x-face gnus-article-display-x-face)
1410     (gnus-treat-display-face gnus-article-display-face)
1411     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1412     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1413     (gnus-treat-hide-signature gnus-article-hide-signature)
1414     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1415     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1416     (gnus-treat-strip-pem gnus-article-hide-pem)
1417     (gnus-treat-from-picon gnus-treat-from-picon)
1418     (gnus-treat-mail-picon gnus-treat-mail-picon)
1419     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1420     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1421     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1422     (gnus-treat-strip-trailing-blank-lines
1423      gnus-article-remove-trailing-blank-lines)
1424     (gnus-treat-strip-leading-blank-lines
1425      gnus-article-strip-leading-blank-lines)
1426     (gnus-treat-strip-multiple-blank-lines
1427      gnus-article-strip-multiple-blank-lines)
1428     (gnus-treat-overstrike gnus-article-treat-overstrike)
1429     (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1430     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1431     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1432     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1433     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1434     (gnus-treat-display-smileys gnus-treat-smiley)
1435     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1436     (gnus-treat-wash-html gnus-article-wash-html)
1437     (gnus-treat-emphasize gnus-article-emphasize)
1438     (gnus-treat-hide-citation gnus-article-hide-citation)
1439     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1440     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1441     (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1442     (gnus-treat-play-sounds gnus-earcon-display)))
1443
1444 (defvar gnus-article-mime-handle-alist nil)
1445 (defvar article-lapsed-timer nil)
1446 (defvar gnus-article-current-summary nil)
1447
1448 (defvar gnus-article-mode-syntax-table
1449   (let ((table (copy-syntax-table text-mode-syntax-table)))
1450     ;; This causes the citation match run O(2^n).
1451     ;; (modify-syntax-entry ?- "w" table)
1452     (modify-syntax-entry ?> ")<" table)
1453     (modify-syntax-entry ?< "(>" table)
1454     ;; make M-. in article buffers work for `foo' strings
1455     (modify-syntax-entry ?' " " table)
1456     (modify-syntax-entry ?` " " table)
1457     table)
1458   "Syntax table used in article mode buffers.
1459 Initialized from `text-mode-syntax-table.")
1460
1461 (defvar gnus-save-article-buffer nil)
1462
1463 (defvar gnus-article-mode-line-format-alist
1464   (nconc '((?w (gnus-article-wash-status) ?s)
1465            (?m (gnus-article-mime-part-status) ?s))
1466          gnus-summary-mode-line-format-alist))
1467
1468 (defvar gnus-number-of-articles-to-be-saved nil)
1469
1470 (defvar gnus-inhibit-hiding nil)
1471
1472 (defvar gnus-article-edit-mode nil)
1473
1474 ;;; Macros for dealing with the article buffer.
1475
1476 (defmacro gnus-with-article-headers (&rest forms)
1477   `(save-excursion
1478      (set-buffer gnus-article-buffer)
1479      (save-restriction
1480        (let ((buffer-read-only nil)
1481              (inhibit-point-motion-hooks t)
1482              (case-fold-search t))
1483          (article-narrow-to-head)
1484          ,@forms))))
1485
1486 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1487 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1488
1489 (defmacro gnus-with-article-buffer (&rest forms)
1490   `(save-excursion
1491      (set-buffer gnus-article-buffer)
1492      (let ((buffer-read-only nil))
1493        ,@forms)))
1494
1495 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1496 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1497
1498 (defun gnus-article-goto-header (header)
1499   "Go to HEADER, which is a regular expression."
1500   (re-search-forward (concat "^\\(" header "\\):") nil t))
1501
1502 (defsubst gnus-article-hide-text (b e props)
1503   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1504   (gnus-add-text-properties-when 'article-type nil b e props)
1505   (when (memq 'intangible props)
1506     (put-text-property
1507      (max (1- b) (point-min))
1508      b 'intangible (cddr (memq 'intangible props)))))
1509
1510 (defsubst gnus-article-unhide-text (b e)
1511   "Remove hidden text properties from region between B and E."
1512   (remove-text-properties b e gnus-hidden-properties)
1513   (when (memq 'intangible gnus-hidden-properties)
1514     (put-text-property (max (1- b) (point-min))
1515                        b 'intangible nil)))
1516
1517 (defun gnus-article-hide-text-type (b e type)
1518   "Hide text of TYPE between B and E."
1519   (gnus-add-wash-type type)
1520   (gnus-article-hide-text
1521    b e (cons 'article-type (cons type gnus-hidden-properties))))
1522
1523 (defun gnus-article-unhide-text-type (b e type)
1524   "Unhide text of TYPE between B and E."
1525   (gnus-delete-wash-type type)
1526   (remove-text-properties
1527    b e (cons 'article-type (cons type gnus-hidden-properties)))
1528   (when (memq 'intangible gnus-hidden-properties)
1529     (put-text-property (max (1- b) (point-min))
1530                        b 'intangible nil)))
1531
1532 (defun gnus-article-hide-text-of-type (type)
1533   "Hide text of TYPE in the current buffer."
1534   (save-excursion
1535     (let ((b (point-min))
1536           (e (point-max)))
1537       (while (setq b (text-property-any b e 'article-type type))
1538         (add-text-properties b (incf b) gnus-hidden-properties)))))
1539
1540 (defun gnus-article-delete-text-of-type (type)
1541   "Delete text of TYPE in the current buffer."
1542   (save-excursion
1543     (let ((b (point-min)))
1544       (while (setq b (text-property-any b (point-max) 'article-type type))
1545         (delete-region
1546          b (or (text-property-not-all b (point-max) 'article-type type)
1547                (point-max)))))))
1548
1549 (defun gnus-article-delete-invisible-text ()
1550   "Delete all invisible text in the current buffer."
1551   (save-excursion
1552     (let ((b (point-min)))
1553       (while (setq b (text-property-any b (point-max) 'invisible t))
1554         (delete-region
1555          b (or (text-property-not-all b (point-max) 'invisible t)
1556                (point-max)))))))
1557
1558 (defun gnus-article-text-type-exists-p (type)
1559   "Say whether any text of type TYPE exists in the buffer."
1560   (text-property-any (point-min) (point-max) 'article-type type))
1561
1562 (defsubst gnus-article-header-rank ()
1563   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1564   (let ((list gnus-sorted-header-list)
1565         (i 1))
1566     (while list
1567       (if (looking-at (car list))
1568           (setq list nil)
1569         (setq list (cdr list))
1570         (incf i)))
1571       i))
1572
1573 (defun article-hide-headers (&optional arg delete)
1574   "Hide unwanted headers and possibly sort them as well."
1575   (interactive)
1576   ;; This function might be inhibited.
1577   (unless gnus-inhibit-hiding
1578     (let ((buffer-read-only nil)
1579           (case-fold-search t)
1580           (max (1+ (length gnus-sorted-header-list)))
1581           (inhibit-point-motion-hooks t)
1582           (cur (current-buffer))
1583           ignored visible beg)
1584       (save-excursion
1585         ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1586         ;; group parameters, so we should go to the summary buffer.
1587         (when (prog1
1588                   (condition-case nil
1589                       (progn (set-buffer gnus-summary-buffer) t)
1590                     (error nil))
1591                 (setq ignored (when (not gnus-visible-headers)
1592                                 (cond ((stringp gnus-ignored-headers)
1593                                        gnus-ignored-headers)
1594                                       ((listp gnus-ignored-headers)
1595                                        (mapconcat 'identity
1596                                                   gnus-ignored-headers
1597                                                   "\\|"))))
1598                       visible (cond ((stringp gnus-visible-headers)
1599                                      gnus-visible-headers)
1600                                     ((and gnus-visible-headers
1601                                           (listp gnus-visible-headers))
1602                                      (mapconcat 'identity
1603                                                 gnus-visible-headers
1604                                                 "\\|")))))
1605           (set-buffer cur))
1606         (save-restriction
1607           ;; First we narrow to just the headers.
1608           (article-narrow-to-head)
1609           ;; Hide any "From " lines at the beginning of (mail) articles.
1610           (while (looking-at "From ")
1611             (forward-line 1))
1612           (unless (bobp)
1613             (delete-region (point-min) (point)))
1614           ;; Then treat the rest of the header lines.
1615           ;; Then we use the two regular expressions
1616           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1617           ;; select which header lines is to remain visible in the
1618           ;; article buffer.
1619           (while (re-search-forward "^[^ \t:]*:" nil t)
1620             (beginning-of-line)
1621             ;; Mark the rank of the header.
1622             (put-text-property
1623              (point) (1+ (point)) 'message-rank
1624              (if (or (and visible (looking-at visible))
1625                      (and ignored
1626                           (not (looking-at ignored))))
1627                  (gnus-article-header-rank)
1628                (+ 2 max)))
1629             (forward-line 1))
1630           (message-sort-headers-1)
1631           (when (setq beg (text-property-any
1632                            (point-min) (point-max) 'message-rank (+ 2 max)))
1633             ;; We delete the unwanted headers.
1634             (gnus-add-wash-type 'headers)
1635             (add-text-properties (point-min) (+ 5 (point-min))
1636                                  '(article-type headers dummy-invisible t))
1637             (delete-region beg (point-max))))))))
1638
1639 (defun article-hide-boring-headers (&optional arg)
1640   "Toggle hiding of headers that aren't very interesting.
1641 If given a negative prefix, always show; if given a positive prefix,
1642 always hide."
1643   (interactive (gnus-article-hidden-arg))
1644   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1645              (not gnus-show-all-headers))
1646     (save-excursion
1647       (save-restriction
1648         (let ((buffer-read-only nil)
1649               (list gnus-boring-article-headers)
1650               (inhibit-point-motion-hooks t)
1651               elem)
1652           (article-narrow-to-head)
1653           (while list
1654             (setq elem (pop list))
1655             (goto-char (point-min))
1656             (cond
1657              ;; Hide empty headers.
1658              ((eq elem 'empty)
1659               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1660                 (forward-line -1)
1661                 (gnus-article-hide-text-type
1662                  (point-at-bol)
1663                  (progn
1664                    (end-of-line)
1665                    (if (re-search-forward "^[^ \t]" nil t)
1666                        (match-beginning 0)
1667                      (point-max)))
1668                  'boring-headers)))
1669              ;; Hide boring Newsgroups header.
1670              ((eq elem 'newsgroups)
1671               (when (gnus-string-equal
1672                      (gnus-fetch-field "newsgroups")
1673                      (gnus-group-real-name
1674                       (if (boundp 'gnus-newsgroup-name)
1675                           gnus-newsgroup-name
1676                         "")))
1677                 (gnus-article-hide-header "newsgroups")))
1678              ((eq elem 'to-address)
1679               (let ((to (message-fetch-field "to"))
1680                     (to-address
1681                      (gnus-parameter-to-address
1682                       (if (boundp 'gnus-newsgroup-name)
1683                           gnus-newsgroup-name ""))))
1684                 (when (and to to-address
1685                            (ignore-errors
1686                              (gnus-string-equal
1687                               ;; only one address in To
1688                               (nth 1 (mail-extract-address-components to))
1689                               to-address)))
1690                   (gnus-article-hide-header "to"))))
1691              ((eq elem 'to-list)
1692               (let ((to (message-fetch-field "to"))
1693                     (to-list
1694                      (gnus-parameter-to-list
1695                       (if (boundp 'gnus-newsgroup-name)
1696                           gnus-newsgroup-name ""))))
1697                 (when (and to to-list
1698                            (ignore-errors
1699                              (gnus-string-equal
1700                               ;; only one address in To
1701                               (nth 1 (mail-extract-address-components to))
1702                               to-list)))
1703                   (gnus-article-hide-header "to"))))
1704              ((eq elem 'cc-list)
1705               (let ((cc (message-fetch-field "cc"))
1706                     (to-list
1707                      (gnus-parameter-to-list
1708                       (if (boundp 'gnus-newsgroup-name)
1709                           gnus-newsgroup-name ""))))
1710                 (when (and cc to-list
1711                            (ignore-errors
1712                              (gnus-string-equal
1713                               ;; only one address in CC
1714                               (nth 1 (mail-extract-address-components cc))
1715                               to-list)))
1716                   (gnus-article-hide-header "cc"))))
1717              ((eq elem 'followup-to)
1718               (when (gnus-string-equal
1719                      (message-fetch-field "followup-to")
1720                      (message-fetch-field "newsgroups"))
1721                 (gnus-article-hide-header "followup-to")))
1722              ((eq elem 'reply-to)
1723               (if (gnus-group-find-parameter
1724                    gnus-newsgroup-name 'broken-reply-to)
1725                   (gnus-article-hide-header "reply-to")
1726                 (let ((from (message-fetch-field "from"))
1727                       (reply-to (message-fetch-field "reply-to")))
1728                   (when
1729                       (and
1730                        from reply-to
1731                        (ignore-errors
1732                          (equal
1733                           (sort (mapcar
1734                                  (lambda (x) (downcase (cadr x)))
1735                                  (mail-extract-address-components from t))
1736                                 'string<)
1737                           (sort (mapcar
1738                                  (lambda (x) (downcase (cadr x)))
1739                                  (mail-extract-address-components reply-to t))
1740                                 'string<))))
1741                     (gnus-article-hide-header "reply-to")))))
1742              ((eq elem 'date)
1743               (let ((date (message-fetch-field "date")))
1744                 (when (and date
1745                            (< (days-between (current-time-string) date)
1746                               4))
1747                   (gnus-article-hide-header "date"))))
1748              ((eq elem 'long-to)
1749               (let ((to (message-fetch-field "to"))
1750                     (cc (message-fetch-field "cc")))
1751                 (when (> (length to) 1024)
1752                   (gnus-article-hide-header "to"))
1753                 (when (> (length cc) 1024)
1754                   (gnus-article-hide-header "cc"))))
1755              ((eq elem 'many-to)
1756               (let ((to-count 0)
1757                     (cc-count 0))
1758                 (goto-char (point-min))
1759                 (while (re-search-forward "^to:" nil t)
1760                   (setq to-count (1+ to-count)))
1761                 (when (> to-count 1)
1762                   (while (> to-count 0)
1763                     (goto-char (point-min))
1764                     (save-restriction
1765                       (re-search-forward "^to:" nil nil to-count)
1766                       (forward-line -1)
1767                       (narrow-to-region (point) (point-max))
1768                       (gnus-article-hide-header "to"))
1769                     (setq to-count (1- to-count))))
1770                 (goto-char (point-min))
1771                 (while (re-search-forward "^cc:" nil t)
1772                   (setq cc-count (1+ cc-count)))
1773                 (when (> cc-count 1)
1774                   (while (> cc-count 0)
1775                     (goto-char (point-min))
1776                     (save-restriction
1777                       (re-search-forward "^cc:" nil nil cc-count)
1778                       (forward-line -1)
1779                       (narrow-to-region (point) (point-max))
1780                       (gnus-article-hide-header "cc"))
1781                     (setq cc-count (1- cc-count)))))))))))))
1782
1783 (defun gnus-article-hide-header (header)
1784   (save-excursion
1785     (goto-char (point-min))
1786     (when (re-search-forward (concat "^" header ":") nil t)
1787       (gnus-article-hide-text-type
1788        (point-at-bol)
1789        (progn
1790          (end-of-line)
1791          (if (re-search-forward "^[^ \t]" nil t)
1792              (match-beginning 0)
1793            (point-max)))
1794        'boring-headers))))
1795
1796 (defvar gnus-article-normalized-header-length 40
1797   "Length of normalized headers.")
1798
1799 (defun article-normalize-headers ()
1800   "Make all header lines 40 characters long."
1801   (interactive)
1802   (let ((buffer-read-only nil)
1803         column)
1804     (save-excursion
1805       (save-restriction
1806         (article-narrow-to-head)
1807         (while (not (eobp))
1808           (cond
1809            ((< (setq column (- (point-at-eol) (point)))
1810                gnus-article-normalized-header-length)
1811             (end-of-line)
1812             (insert (make-string
1813                      (- gnus-article-normalized-header-length column)
1814                      ? )))
1815            ((> column gnus-article-normalized-header-length)
1816             (gnus-put-text-property
1817              (progn
1818                (forward-char gnus-article-normalized-header-length)
1819                (point))
1820              (point-at-eol)
1821              'invisible t))
1822            (t
1823             ;; Do nothing.
1824             ))
1825           (forward-line 1))))))
1826
1827 (defun article-treat-dumbquotes ()
1828   "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1829 Note that this function guesses whether a character is a sm*rtq**t* or
1830 not, so it should only be used interactively.
1831
1832 Sm*rtq**t*s are M****s***'s unilateral extension to the
1833 iso-8859-1 character map in an attempt to provide more quoting
1834 characters.  If you see something like \\222 or \\264 where
1835 you're expecting some kind of apostrophe or quotation mark, then
1836 try this wash."
1837   (interactive)
1838   (article-translate-strings gnus-article-dumbquotes-map))
1839
1840 (defun article-translate-characters (from to)
1841   "Translate all characters in the body of the article according to FROM and TO.
1842 FROM is a string of characters to translate from; to is a string of
1843 characters to translate to."
1844   (save-excursion
1845     (when (article-goto-body)
1846       (let ((buffer-read-only nil)
1847             (x (make-string 225 ?x))
1848             (i -1))
1849         (while (< (incf i) (length x))
1850           (aset x i i))
1851         (setq i 0)
1852         (while (< i (length from))
1853           (aset x (aref from i) (aref to i))
1854           (incf i))
1855         (translate-region (point) (point-max) x)))))
1856
1857 (defun article-translate-strings (map)
1858   "Translate all string in the body of the article according to MAP.
1859 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1860   (save-excursion
1861     (when (article-goto-body)
1862       (let ((buffer-read-only nil)
1863             elem)
1864         (while (setq elem (pop map))
1865           (save-excursion
1866             (while (search-forward (car elem) nil t)
1867               (replace-match (cadr elem)))))))))
1868
1869 (defun article-treat-overstrike ()
1870   "Translate overstrikes into bold text."
1871   (interactive)
1872   (save-excursion
1873     (when (article-goto-body)
1874       (let ((buffer-read-only nil))
1875         (while (search-forward "\b" nil t)
1876           (let ((next (char-after))
1877                 (previous (char-after (- (point) 2))))
1878             ;; We do the boldification/underlining by hiding the
1879             ;; overstrikes and putting the proper text property
1880             ;; on the letters.
1881             (cond
1882              ((eq next previous)
1883               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1884               (put-text-property (point) (1+ (point)) 'face 'bold))
1885              ((eq next ?_)
1886               (gnus-article-hide-text-type
1887                (1- (point)) (1+ (point)) 'overstrike)
1888               (put-text-property
1889                (- (point) 2) (1- (point)) 'face 'underline))
1890              ((eq previous ?_)
1891               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1892               (put-text-property
1893                (point) (1+ (point)) 'face 'underline)))))))))
1894
1895 (defun article-treat-ansi-sequences ()
1896   "Translate ANSI SGR control sequences into overlays or extents."
1897   (interactive)
1898   (save-excursion
1899     (when (article-goto-body)
1900       (let ((buffer-read-only nil))
1901         (ansi-color-apply-on-region (point) (point-max))))))
1902
1903 (defun gnus-article-treat-unfold-headers ()
1904   "Unfold folded message headers.
1905 Only the headers that fit into the current window width will be
1906 unfolded."
1907   (interactive)
1908   (gnus-with-article-headers
1909     (let (length)
1910       (while (not (eobp))
1911         (save-restriction
1912           (mail-header-narrow-to-field)
1913           (let ((header (buffer-string)))
1914             (with-temp-buffer
1915               (insert header)
1916               (goto-char (point-min))
1917               (while (re-search-forward "\n[\t ]" nil t)
1918                 (replace-match " " t t)))
1919             (setq length (- (point-max) (point-min) 1)))
1920           (when (< length (window-width))
1921             (while (re-search-forward "\n[\t ]" nil t)
1922               (replace-match " " t t)))
1923           (goto-char (point-max)))))))
1924
1925 (defun gnus-article-treat-fold-headers ()
1926   "Fold message headers."
1927   (interactive)
1928   (gnus-with-article-headers
1929     (while (not (eobp))
1930       (save-restriction
1931         (mail-header-narrow-to-field)
1932         (mail-header-fold-field)
1933         (goto-char (point-max))))))
1934
1935 (defun gnus-treat-smiley ()
1936   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
1937   (interactive)
1938   (gnus-with-article-buffer
1939     (if (memq 'smiley gnus-article-wash-types)
1940         (gnus-delete-images 'smiley)
1941       (article-goto-body)
1942       (let ((images (smiley-region (point) (point-max))))
1943         (when images
1944           (gnus-add-wash-type 'smiley)
1945           (dolist (image images)
1946             (gnus-add-image 'smiley image)))))))
1947
1948 (defun gnus-article-remove-images ()
1949   "Remove all images from the article buffer."
1950   (interactive)
1951   (gnus-with-article-buffer
1952     (dolist (elem gnus-article-image-alist)
1953       (gnus-delete-images (car elem)))))
1954
1955 (defun gnus-article-treat-fold-newsgroups ()
1956   "Unfold folded message headers.
1957 Only the headers that fit into the current window width will be
1958 unfolded."
1959   (interactive)
1960   (gnus-with-article-headers
1961     (while (gnus-article-goto-header "newsgroups\\|followup-to")
1962       (save-restriction
1963         (mail-header-narrow-to-field)
1964         (while (re-search-forward ", *" nil t)
1965           (replace-match ", " t t))
1966         (mail-header-fold-field)
1967         (goto-char (point-max))))))
1968
1969 (defun gnus-article-treat-body-boundary ()
1970   "Place a boundary line at the end of the headers."
1971   (interactive)
1972   (when (and gnus-body-boundary-delimiter
1973              (> (length gnus-body-boundary-delimiter) 0))
1974     (gnus-with-article-headers
1975       (goto-char (point-max))
1976       (let ((start (point)))
1977         (insert "X-Boundary: ")
1978         (gnus-add-text-properties start (point) '(invisible t intangible t))
1979         (insert (let (str)
1980                   (while (>= (1- (window-width)) (length str))
1981                     (setq str (concat str gnus-body-boundary-delimiter)))
1982                   (substring str 0 (1- (window-width))))
1983                 "\n")
1984         (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
1985
1986 (defun article-fill-long-lines ()
1987   "Fill lines that are wider than the window width."
1988   (interactive)
1989   (save-excursion
1990     (let ((buffer-read-only nil)
1991           (width (window-width (get-buffer-window (current-buffer)))))
1992       (save-restriction
1993         (article-goto-body)
1994         (let ((adaptive-fill-mode nil)) ;Why?  -sm
1995           (while (not (eobp))
1996             (end-of-line)
1997             (when (>= (current-column) (min fill-column width))
1998               (narrow-to-region (min (1+ (point)) (point-max))
1999                                 (point-at-bol))
2000               (let ((goback (point-marker)))
2001                 (fill-paragraph nil)
2002                 (goto-char (marker-position goback)))
2003               (widen))
2004             (forward-line 1)))))))
2005
2006 (defun article-capitalize-sentences ()
2007   "Capitalize the first word in each sentence."
2008   (interactive)
2009   (save-excursion
2010     (let ((buffer-read-only nil)
2011           (paragraph-start "^[\n\^L]"))
2012       (article-goto-body)
2013       (while (not (eobp))
2014         (capitalize-word 1)
2015         (forward-sentence)))))
2016
2017 (defun article-remove-cr ()
2018   "Remove trailing CRs and then translate remaining CRs into LFs."
2019   (interactive)
2020   (save-excursion
2021     (let ((buffer-read-only nil))
2022       (goto-char (point-min))
2023       (while (re-search-forward "\r+$" nil t)
2024         (replace-match "" t t))
2025       (goto-char (point-min))
2026       (while (search-forward "\r" nil t)
2027         (replace-match "\n" t t)))))
2028
2029 (defun article-remove-trailing-blank-lines ()
2030   "Remove all trailing blank lines from the article."
2031   (interactive)
2032   (save-excursion
2033     (let ((buffer-read-only nil))
2034       (goto-char (point-max))
2035       (delete-region
2036        (point)
2037        (progn
2038          (while (and (not (bobp))
2039                      (looking-at "^[ \t]*$")
2040                      (not (gnus-annotation-in-region-p
2041                            (point) (point-at-eol))))
2042            (forward-line -1))
2043          (forward-line 1)
2044          (point))))))
2045
2046 (eval-when-compile
2047   (defvar gnus-face-properties-alist))
2048
2049 (defun article-display-face ()
2050   "Display any Face headers in the header."
2051   (interactive)
2052   (let ((wash-face-p buffer-read-only))
2053     (gnus-with-article-headers
2054       ;; When displaying parts, this function can be called several times on
2055       ;; the same article, without any intended toggle semantic (as typing `W
2056       ;; D d' would have). So face deletion must occur only when we come from
2057       ;; an interactive command, that is when the *Article* buffer is
2058       ;; read-only.
2059       (if (and wash-face-p (memq 'face gnus-article-wash-types))
2060           (gnus-delete-images 'face)
2061         (let (face faces)
2062           (save-excursion
2063             (when (and wash-face-p
2064                        (progn
2065                          (goto-char (point-min))
2066                          (not (re-search-forward "^Face:[\t ]*" nil t)))
2067                        (gnus-buffer-live-p gnus-original-article-buffer))
2068               (set-buffer gnus-original-article-buffer))
2069             (save-restriction
2070               (mail-narrow-to-head)
2071               (while (gnus-article-goto-header "Face")
2072                 (setq faces (nconc faces (list (mail-header-field-value)))))))
2073           (while (setq face (pop faces))
2074             (let ((png (gnus-convert-face-to-png face))
2075                   image)
2076               (when png
2077                 (setq image
2078                       (apply 'gnus-create-image png 'png t
2079                              (cdr (assq 'png gnus-face-properties-alist))))
2080                 (gnus-article-goto-header "from")
2081                 (when (bobp)
2082                   (insert "From: [no `from' set]\n")
2083                   (forward-char -17))
2084                 (gnus-add-wash-type 'face)
2085                 (gnus-add-image 'face image)
2086                 (gnus-put-image image nil 'face))))))
2087       )))
2088
2089 (defun article-display-x-face (&optional force)
2090   "Look for an X-Face header and display it if present."
2091   (interactive (list 'force))
2092   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2093     (gnus-with-article-headers
2094       ;; Delete the old process, if any.
2095       (when (process-status "article-x-face")
2096         (delete-process "article-x-face"))
2097       ;; See the comment in `article-display-face'.
2098       (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2099           ;; We have already displayed X-Faces, so we remove them
2100           ;; instead.
2101           (gnus-delete-images 'xface)
2102         ;; Display X-Faces.
2103         (let (x-faces from face)
2104           (save-excursion
2105             (when (and wash-face-p
2106                        (progn
2107                          (goto-char (point-min))
2108                          (not (re-search-forward
2109                                "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2110                        (gnus-buffer-live-p gnus-original-article-buffer))
2111               ;; If type `W f', use gnus-original-article-buffer,
2112               ;; otherwise use the current buffer because displaying
2113               ;; RFC822 parts calls this function too.
2114               (set-buffer gnus-original-article-buffer))
2115             (save-restriction
2116               (mail-narrow-to-head)
2117               (while (gnus-article-goto-header "X-Face")
2118                 (push (mail-header-field-value) x-faces))
2119               (setq from (message-fetch-field "from"))))
2120           ;; Sending multiple EOFs to xv doesn't work, so we only do a
2121           ;; single external face.
2122           (when (stringp gnus-article-x-face-command)
2123             (setq x-faces (list (car x-faces))))
2124           (while (and (setq face (pop x-faces))
2125                       gnus-article-x-face-command
2126                       (or force
2127                           ;; Check whether this face is censored.
2128                           (not gnus-article-x-face-too-ugly)
2129                           (and gnus-article-x-face-too-ugly from
2130                                (not (string-match gnus-article-x-face-too-ugly
2131                                                   from)))))
2132             ;; We display the face.
2133             (cond ((stringp gnus-article-x-face-command)
2134                    ;; The command is a string, so we interpret the command
2135                    ;; as a, well, command, and fork it off.
2136                    (let ((process-connection-type nil))
2137                      (process-kill-without-query
2138                       (start-process
2139                        "article-x-face" nil shell-file-name
2140                        shell-command-switch gnus-article-x-face-command))
2141                      (with-temp-buffer
2142                        (insert face)
2143                        (process-send-region "article-x-face"
2144                                             (point-min) (point-max)))
2145                      (process-send-eof "article-x-face")))
2146                   ((functionp gnus-article-x-face-command)
2147                    ;; The command is a lisp function, so we call it.
2148                    (funcall gnus-article-x-face-command face))
2149                   (t
2150                    (error "%s is not a function"
2151                           gnus-article-x-face-command)))))))))
2152
2153 (defun article-decode-mime-words ()
2154   "Decode all MIME-encoded words in the article."
2155   (interactive)
2156   (gnus-with-article-buffer
2157     (let ((inhibit-point-motion-hooks t)
2158           (mail-parse-charset gnus-newsgroup-charset)
2159           (mail-parse-ignored-charsets
2160            (with-current-buffer gnus-summary-buffer
2161              gnus-newsgroup-ignored-charsets)))
2162       (mail-decode-encoded-word-region (point-min) (point-max)))))
2163
2164 (defun article-decode-charset (&optional prompt)
2165   "Decode charset-encoded text in the article.
2166 If PROMPT (the prefix), prompt for a coding system to use."
2167   (interactive "P")
2168   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2169         buffer-read-only
2170         (mail-parse-charset gnus-newsgroup-charset)
2171         (mail-parse-ignored-charsets
2172          (save-excursion (condition-case nil
2173                              (set-buffer gnus-summary-buffer)
2174                            (error))
2175                          gnus-newsgroup-ignored-charsets))
2176         ct cte ctl charset format)
2177   (save-excursion
2178     (save-restriction
2179       (article-narrow-to-head)
2180       (setq ct (message-fetch-field "Content-Type" t)
2181             cte (message-fetch-field "Content-Transfer-Encoding" t)
2182             ctl (and ct (ignore-errors
2183                           (mail-header-parse-content-type ct)))
2184             charset (cond
2185                      (prompt
2186                       (mm-read-coding-system "Charset to decode: "))
2187                      (ctl
2188                       (mail-content-type-get ctl 'charset)))
2189             format (and ctl (mail-content-type-get ctl 'format)))
2190       (when cte
2191         (setq cte (mail-header-strip cte)))
2192       (if (and ctl (not (string-match "/" (car ctl))))
2193           (setq ctl nil))
2194       (goto-char (point-max)))
2195     (forward-line 1)
2196     (save-restriction
2197       (narrow-to-region (point) (point-max))
2198       (when (and (eq mail-parse-charset 'gnus-decoded)
2199                  (eq (mm-body-7-or-8) '8bit))
2200         ;; The text code could have been decoded.
2201         (setq charset mail-parse-charset))
2202       (when (and (or (not ctl)
2203                      (equal (car ctl) "text/plain"))
2204                  (not format)) ;; article with format will decode later.
2205         (mm-decode-body
2206          charset (and cte (intern (downcase
2207                                    (gnus-strip-whitespace cte))))
2208          (car ctl)))))))
2209
2210 (defun article-decode-encoded-words ()
2211   "Remove encoded-word encoding from headers."
2212   (let ((inhibit-point-motion-hooks t)
2213         (mail-parse-charset gnus-newsgroup-charset)
2214         (mail-parse-ignored-charsets
2215          (save-excursion (condition-case nil
2216                              (set-buffer gnus-summary-buffer)
2217                            (error))
2218                          gnus-newsgroup-ignored-charsets))
2219         buffer-read-only)
2220     (save-restriction
2221       (article-narrow-to-head)
2222       (funcall gnus-decode-header-function (point-min) (point-max)))))
2223
2224 (defun article-decode-group-name ()
2225   "Decode group names in `Newsgroups:'."
2226   (let ((inhibit-point-motion-hooks t)
2227         buffer-read-only
2228         (method (gnus-find-method-for-group gnus-newsgroup-name)))
2229     (when (and (or gnus-group-name-charset-method-alist
2230                    gnus-group-name-charset-group-alist)
2231                (gnus-buffer-live-p gnus-original-article-buffer))
2232       (save-restriction
2233         (article-narrow-to-head)
2234         (with-current-buffer gnus-original-article-buffer
2235           (goto-char (point-min)))
2236         (while (re-search-forward
2237                 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2238           (replace-match (save-match-data
2239                            (gnus-decode-newsgroups
2240                             ;; XXX how to use data in article buffer?
2241                             (with-current-buffer gnus-original-article-buffer
2242                               (re-search-forward
2243                                "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2244                                nil t)
2245                               (match-string 1))
2246                             gnus-newsgroup-name method))
2247                          t t nil 1))
2248         (goto-char (point-min))
2249         (with-current-buffer gnus-original-article-buffer
2250           (goto-char (point-min)))
2251         (while (re-search-forward
2252                 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2253           (replace-match (save-match-data
2254                            (gnus-decode-newsgroups
2255                             ;; XXX how to use data in article buffer?
2256                             (with-current-buffer gnus-original-article-buffer
2257                               (re-search-forward
2258                                "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2259                                nil t)
2260                               (match-string 1))
2261                             gnus-newsgroup-name method))
2262                          t t nil 1))))))
2263
2264 (autoload 'idna-to-unicode "idna")
2265
2266 (defun article-decode-idna-rhs ()
2267   "Decode IDNA strings in RHS in From:, To: and Cc: headers in current buffer."
2268   (when gnus-use-idna
2269     (save-restriction
2270       (let ((inhibit-point-motion-hooks t)
2271             buffer-read-only)
2272         (article-narrow-to-head)
2273         (goto-char (point-min))
2274         (while (re-search-forward "@.*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2275           (let (ace unicode)
2276             (when (save-match-data
2277                     (and (setq ace (match-string 1))
2278                          (save-excursion
2279                            (and (re-search-backward "^[^ \t]" nil t)
2280                                 (looking-at "From\\|To\\|Cc")))
2281                          (setq unicode (idna-to-unicode ace))))
2282               (unless (string= ace unicode)
2283                 (replace-match unicode nil nil nil 1)))))))))
2284
2285 (defun article-de-quoted-unreadable (&optional force read-charset)
2286   "Translate a quoted-printable-encoded article.
2287 If FORCE, decode the article whether it is marked as quoted-printable
2288 or not.
2289 If READ-CHARSET, ask for a coding system."
2290   (interactive (list 'force current-prefix-arg))
2291   (save-excursion
2292     (let ((buffer-read-only nil) type charset)
2293       (if (gnus-buffer-live-p gnus-original-article-buffer)
2294           (with-current-buffer gnus-original-article-buffer
2295             (setq type
2296                   (gnus-fetch-field "content-transfer-encoding"))
2297             (let* ((ct (gnus-fetch-field "content-type"))
2298                    (ctl (and ct
2299                              (ignore-errors
2300                                (mail-header-parse-content-type ct)))))
2301               (setq charset (and ctl
2302                                  (mail-content-type-get ctl 'charset)))
2303               (if (stringp charset)
2304                   (setq charset (intern (downcase charset)))))))
2305       (if read-charset
2306           (setq charset (mm-read-coding-system "Charset: " charset)))
2307       (unless charset
2308         (setq charset gnus-newsgroup-charset))
2309       (when (or force
2310                 (and type (let ((case-fold-search t))
2311                             (string-match "quoted-printable" type))))
2312         (article-goto-body)
2313         (quoted-printable-decode-region
2314          (point) (point-max) (mm-charset-to-coding-system charset))))))
2315
2316 (defun article-de-base64-unreadable (&optional force read-charset)
2317   "Translate a base64 article.
2318 If FORCE, decode the article whether it is marked as base64 not.
2319 If READ-CHARSET, ask for a coding system."
2320   (interactive (list 'force current-prefix-arg))
2321   (save-excursion
2322     (let ((buffer-read-only nil) type charset)
2323       (if (gnus-buffer-live-p gnus-original-article-buffer)
2324           (with-current-buffer gnus-original-article-buffer
2325             (setq type
2326                   (gnus-fetch-field "content-transfer-encoding"))
2327             (let* ((ct (gnus-fetch-field "content-type"))
2328                    (ctl (and ct
2329                              (ignore-errors
2330                                (mail-header-parse-content-type ct)))))
2331               (setq charset (and ctl
2332                                  (mail-content-type-get ctl 'charset)))
2333               (if (stringp charset)
2334                   (setq charset (intern (downcase charset)))))))
2335       (if read-charset
2336           (setq charset (mm-read-coding-system "Charset: " charset)))
2337       (unless charset
2338         (setq charset gnus-newsgroup-charset))
2339       (when (or force
2340                 (and type (let ((case-fold-search t))
2341                             (string-match "base64" type))))
2342         (article-goto-body)
2343         (save-restriction
2344           (narrow-to-region (point) (point-max))
2345           (base64-decode-region (point-min) (point-max))
2346           (mm-decode-coding-region
2347            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2348
2349 (eval-when-compile
2350   (require 'rfc1843))
2351
2352 (defun article-decode-HZ ()
2353   "Translate a HZ-encoded article."
2354   (interactive)
2355   (require 'rfc1843)
2356   (save-excursion
2357     (let ((buffer-read-only nil))
2358       (rfc1843-decode-region (point-min) (point-max)))))
2359
2360 (defun article-unsplit-urls ()
2361   "Remove the newlines that some other mailers insert into URLs."
2362   (interactive)
2363   (save-excursion
2364     (let ((buffer-read-only nil))
2365       (goto-char (point-min))
2366       (while (re-search-forward
2367               "^\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2368         (replace-match "\\1\\3" t)))
2369     (when (interactive-p)
2370       (gnus-treat-article nil))))
2371
2372
2373 (defun article-wash-html (&optional read-charset)
2374   "Format an HTML article.
2375 If READ-CHARSET, ask for a coding system."
2376   (interactive "P")
2377   (save-excursion
2378     (let ((buffer-read-only nil)
2379           charset)
2380       (when (gnus-buffer-live-p gnus-original-article-buffer)
2381         (with-current-buffer gnus-original-article-buffer
2382           (let* ((ct (gnus-fetch-field "content-type"))
2383                  (ctl (and ct
2384                            (ignore-errors
2385                              (mail-header-parse-content-type ct)))))
2386             (setq charset (and ctl
2387                                (mail-content-type-get ctl 'charset)))
2388             (when (stringp charset)
2389               (setq charset (intern (downcase charset)))))))
2390       (when read-charset
2391         (setq charset (mm-read-coding-system "Charset: " charset)))
2392       (unless charset
2393         (setq charset gnus-newsgroup-charset))
2394       (article-goto-body)
2395       (save-window-excursion
2396         (save-restriction
2397           (narrow-to-region (point) (point-max))
2398           (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2399                  (entry (assq func mm-text-html-washer-alist)))
2400             (when entry
2401               (setq func (cdr entry)))
2402             (cond
2403              ((functionp func)
2404               (funcall func))
2405              (t
2406               (apply (car func) (cdr func))))))))))
2407
2408 (defun gnus-article-wash-html-with-w3 ()
2409   "Wash the current buffer with w3."
2410   (mm-setup-w3)
2411   (let ((w3-strict-width (window-width))
2412         (url-standalone-mode t)
2413         (url-gateway-unplugged t)
2414         (w3-honor-stylesheets nil))
2415     (condition-case ()
2416         (w3-region (point-min) (point-max))
2417       (error))))
2418
2419 (defun gnus-article-wash-html-with-w3m ()
2420   "Wash the current buffer with emacs-w3m."
2421   (mm-setup-w3m)
2422   (save-restriction
2423     (narrow-to-region (point) (point-max))
2424     (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2425           w3m-force-redisplay)
2426       (w3m-region (point-min) (point-max)))
2427     (when (and mm-inline-text-html-with-w3m-keymap
2428                (boundp 'w3m-minor-mode-map)
2429                w3m-minor-mode-map)
2430       (add-text-properties
2431        (point-min) (point-max)
2432        (list 'keymap w3m-minor-mode-map
2433              ;; Put the mark meaning this part was rendered by emacs-w3m.
2434              'mm-inline-text-html-with-w3m t)))))
2435
2436 (defun article-hide-list-identifiers ()
2437   "Remove list identifies from the Subject header.
2438 The `gnus-list-identifiers' variable specifies what to do."
2439   (interactive)
2440   (let ((inhibit-point-motion-hooks t)
2441         (regexp (if (consp gnus-list-identifiers)
2442                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2443                   gnus-list-identifiers))
2444         buffer-read-only)
2445     (when regexp
2446       (save-excursion
2447         (save-restriction
2448           (article-narrow-to-head)
2449           (goto-char (point-min))
2450           (while (re-search-forward
2451                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2452                   nil t)
2453             (delete-region (match-beginning 2) (match-end 0))
2454             (beginning-of-line))
2455           (when (re-search-forward
2456                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2457             (delete-region (match-beginning 1) (match-end 1))))))))
2458
2459 (defun article-hide-pem (&optional arg)
2460   "Toggle hiding of any PEM headers and signatures in the current article.
2461 If given a negative prefix, always show; if given a positive prefix,
2462 always hide."
2463   (interactive (gnus-article-hidden-arg))
2464   (unless (gnus-article-check-hidden-text 'pem arg)
2465     (save-excursion
2466       (let (buffer-read-only end)
2467         (goto-char (point-min))
2468         ;; Hide the horrendously ugly "header".
2469         (when (and (search-forward
2470                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2471                     nil t)
2472                    (setq end (1+ (match-beginning 0))))
2473           (gnus-add-wash-type 'pem)
2474           (gnus-article-hide-text-type
2475            end
2476            (if (search-forward "\n\n" nil t)
2477                (match-end 0)
2478              (point-max))
2479            'pem)
2480           ;; Hide the trailer as well
2481           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2482                                 nil t)
2483             (gnus-article-hide-text-type
2484              (match-beginning 0) (match-end 0) 'pem)))))))
2485
2486 (defun article-strip-banner ()
2487   "Strip the banners specified by the `banner' group parameter and by
2488 `gnus-article-address-banner-alist'."
2489   (interactive)
2490   (save-excursion
2491     (save-restriction
2492       (let ((inhibit-point-motion-hooks t))
2493         (when (gnus-parameter-banner gnus-newsgroup-name)
2494           (article-really-strip-banner
2495            (gnus-parameter-banner gnus-newsgroup-name)))
2496         (when gnus-article-address-banner-alist
2497           ;; It is necessary to encode from fields before checking,
2498           ;; because `mail-header-parse-addresses' does not work
2499           ;; (reliably) on decoded headers.  And more, it is
2500           ;; impossible to use `gnus-fetch-original-field' here,
2501           ;; because `article-strip-banner' may be called in draft
2502           ;; buffers to preview them.
2503           (let ((from (save-restriction
2504                         (widen)
2505                         (article-narrow-to-head)
2506                         (mail-fetch-field "from"))))
2507             (when (and from
2508                        (setq from
2509                              (caar (mail-header-parse-addresses
2510                                     (mail-encode-encoded-word-string from)))))
2511               (catch 'found
2512                 (dolist (pair gnus-article-address-banner-alist)
2513                   (when (string-match (car pair) from)
2514                     (throw 'found
2515                            (article-really-strip-banner (cdr pair)))))))))))))
2516
2517 (defun article-really-strip-banner (banner)
2518   "Strip the banner specified by the argument."
2519   (save-excursion
2520     (save-restriction
2521       (let ((inhibit-point-motion-hooks t)
2522             (gnus-signature-limit nil)
2523             buffer-read-only)
2524         (article-goto-body)
2525         (cond
2526          ((eq banner 'signature)
2527           (when (gnus-article-narrow-to-signature)
2528             (widen)
2529             (forward-line -1)
2530             (delete-region (point) (point-max))))
2531          ((symbolp banner)
2532           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2533               (while (re-search-forward banner nil t)
2534                 (delete-region (match-beginning 0) (match-end 0)))))
2535          ((stringp banner)
2536           (while (re-search-forward banner nil t)
2537             (delete-region (match-beginning 0) (match-end 0)))))))))
2538
2539 (defun article-babel ()
2540   "Translate article using an online translation service."
2541   (interactive)
2542   (require 'babel)
2543   (gnus-with-article-buffer
2544     (when (article-goto-body)
2545       (let* ((start (point))
2546              (end (point-max))
2547              (orig (buffer-substring start end))
2548              (trans (babel-as-string orig)))
2549         (save-restriction
2550           (narrow-to-region start end)
2551           (delete-region start end)
2552           (insert trans))))))
2553
2554 (defun article-hide-signature (&optional arg)
2555   "Hide the signature in the current article.
2556 If given a negative prefix, always show; if given a positive prefix,
2557 always hide."
2558   (interactive (gnus-article-hidden-arg))
2559   (unless (gnus-article-check-hidden-text 'signature arg)
2560     (save-excursion
2561       (save-restriction
2562         (let ((buffer-read-only nil))
2563           (when (gnus-article-narrow-to-signature)
2564             (gnus-article-hide-text-type
2565              (point-min) (point-max) 'signature))))))
2566   (gnus-set-mode-line 'article))
2567
2568 (defun article-strip-headers-in-body ()
2569   "Strip offensive headers from bodies."
2570   (interactive)
2571   (save-excursion
2572     (article-goto-body)
2573     (let ((case-fold-search t))
2574       (when (looking-at "x-no-archive:")
2575         (gnus-delete-line)))))
2576
2577 (defun article-strip-leading-blank-lines ()
2578   "Remove all blank lines from the beginning of the article."
2579   (interactive)
2580   (save-excursion
2581     (let ((inhibit-point-motion-hooks t)
2582           buffer-read-only)
2583       (when (article-goto-body)
2584         (while (and (not (eobp))
2585                     (looking-at "[ \t]*$"))
2586           (gnus-delete-line))))))
2587
2588 (defun article-narrow-to-head ()
2589   "Narrow the buffer to the head of the message.
2590 Point is left at the beginning of the narrowed-to region."
2591   (narrow-to-region
2592    (goto-char (point-min))
2593    (if (search-forward "\n\n" nil 1)
2594        (1- (point))
2595      (point-max)))
2596   (goto-char (point-min)))
2597
2598 (defun article-goto-body ()
2599   "Place point at the start of the body."
2600   (goto-char (point-min))
2601   (cond
2602    ;; This variable is only bound when dealing with separate
2603    ;; MIME body parts.
2604    (article-goto-body-goes-to-point-min-p
2605     t)
2606    ((search-forward "\n\n" nil t)
2607     t)
2608    (t
2609     (goto-char (point-max))
2610     nil)))
2611
2612 (defun article-strip-multiple-blank-lines ()
2613   "Replace consecutive blank lines with one empty line."
2614   (interactive)
2615   (save-excursion
2616     (let ((inhibit-point-motion-hooks t)
2617           buffer-read-only)
2618       ;; First make all blank lines empty.
2619       (article-goto-body)
2620       (while (re-search-forward "^[ \t]+$" nil t)
2621         (unless (gnus-annotation-in-region-p
2622                  (match-beginning 0) (match-end 0))
2623           (replace-match "" nil t)))
2624       ;; Then replace multiple empty lines with a single empty line.
2625       (article-goto-body)
2626       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2627         (unless (gnus-annotation-in-region-p
2628                  (match-beginning 0) (match-end 0))
2629           (delete-region (match-beginning 1) (match-end 1)))))))
2630
2631 (defun article-strip-leading-space ()
2632   "Remove all white space from the beginning of the lines in the article."
2633   (interactive)
2634   (save-excursion
2635     (let ((inhibit-point-motion-hooks t)
2636           buffer-read-only)
2637       (article-goto-body)
2638       (while (re-search-forward "^[ \t]+" nil t)
2639         (replace-match "" t t)))))
2640
2641 (defun article-strip-trailing-space ()
2642   "Remove all white space from the end of the lines in the article."
2643   (interactive)
2644   (save-excursion
2645     (let ((inhibit-point-motion-hooks t)
2646           buffer-read-only)
2647       (article-goto-body)
2648       (while (re-search-forward "[ \t]+$" nil t)
2649         (replace-match "" t t)))))
2650
2651 (defun article-strip-blank-lines ()
2652   "Strip leading, trailing and multiple blank lines."
2653   (interactive)
2654   (article-strip-leading-blank-lines)
2655   (article-remove-trailing-blank-lines)
2656   (article-strip-multiple-blank-lines))
2657
2658 (defun article-strip-all-blank-lines ()
2659   "Strip all blank lines."
2660   (interactive)
2661   (save-excursion
2662     (let ((inhibit-point-motion-hooks t)
2663           buffer-read-only)
2664       (article-goto-body)
2665       (while (re-search-forward "^[ \t]*\n" nil t)
2666         (replace-match "" t t)))))
2667
2668 (defun gnus-article-narrow-to-signature ()
2669   "Narrow to the signature; return t if a signature is found, else nil."
2670   (let ((inhibit-point-motion-hooks t))
2671     (when (gnus-article-search-signature)
2672       (forward-line 1)
2673       ;; Check whether we have some limits to what we consider
2674       ;; to be a signature.
2675       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2676                       (list gnus-signature-limit)))
2677             limit limited)
2678         (while (setq limit (pop limits))
2679           (if (or (and (integerp limit)
2680                        (< (- (point-max) (point)) limit))
2681                   (and (floatp limit)
2682                        (< (count-lines (point) (point-max)) limit))
2683                   (and (functionp limit)
2684                        (funcall limit))
2685                   (and (stringp limit)
2686                        (not (re-search-forward limit nil t))))
2687               ()                        ; This limit did not succeed.
2688             (setq limited t
2689                   limits nil)))
2690         (unless limited
2691           (narrow-to-region (point) (point-max))
2692           t)))))
2693
2694 (defun gnus-article-search-signature ()
2695   "Search the current buffer for the signature separator.
2696 Put point at the beginning of the signature separator."
2697   (let ((cur (point)))
2698     (goto-char (point-max))
2699     (if (if (stringp gnus-signature-separator)
2700             (re-search-backward gnus-signature-separator nil t)
2701           (let ((seps gnus-signature-separator))
2702             (while (and seps
2703                         (not (re-search-backward (car seps) nil t)))
2704               (pop seps))
2705             seps))
2706         t
2707       (goto-char cur)
2708       nil)))
2709
2710 (defun gnus-article-hidden-arg ()
2711   "Return the current prefix arg as a number, or 0 if no prefix."
2712   (list (if current-prefix-arg
2713             (prefix-numeric-value current-prefix-arg)
2714           0)))
2715
2716 (defun gnus-article-check-hidden-text (type arg)
2717   "Return nil if hiding is necessary.
2718 Arg can be nil or a number.  nil and positive means hide, negative
2719 means show, 0 means toggle."
2720   (save-excursion
2721     (save-restriction
2722       (let ((hide (gnus-article-hidden-text-p type)))
2723         (cond
2724          ((or (null arg)
2725               (> arg 0))
2726           nil)
2727          ((< arg 0)
2728           (gnus-article-show-hidden-text type)
2729           t)
2730          (t
2731           (if (eq hide 'hidden)
2732               (progn
2733                 (gnus-article-show-hidden-text type)
2734                 t)
2735             nil)))))))
2736
2737 (defun gnus-article-hidden-text-p (type)
2738   "Say whether the current buffer contains hidden text of type TYPE."
2739   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2740     (while (and pos
2741                 (not (get-text-property pos 'invisible))
2742                 (not (get-text-property pos 'dummy-invisible)))
2743       (setq pos
2744             (text-property-any (1+ pos) (point-max) 'article-type type)))
2745     (if pos
2746         'hidden
2747       nil)))
2748
2749 (defun gnus-article-show-hidden-text (type &optional dummy)
2750   "Show all hidden text of type TYPE.
2751 Originally it is hide instead of DUMMY."
2752   (let ((buffer-read-only nil)
2753         (inhibit-point-motion-hooks t))
2754     (gnus-remove-text-properties-when
2755      'article-type type
2756      (point-min) (point-max)
2757      (cons 'article-type (cons type
2758                                gnus-hidden-properties)))
2759     (gnus-delete-wash-type type)))
2760
2761 (defconst article-time-units
2762   `((year . ,(* 365.25 24 60 60))
2763     (week . ,(* 7 24 60 60))
2764     (day . ,(* 24 60 60))
2765     (hour . ,(* 60 60))
2766     (minute . 60)
2767     (second . 1))
2768   "Mapping from time units to seconds.")
2769
2770 (defun gnus-article-forward-header ()
2771   "Move point to the start of the next header.
2772 If the current header is a continuation header, this can be several
2773 lines forward."
2774   (let ((ended nil))
2775     (while (not ended)
2776       (forward-line 1)
2777       (if (looking-at "[ \t]+[^ \t]")
2778           (forward-line 1)
2779         (setq ended t)))))
2780
2781 (defun article-date-ut (&optional type highlight header)
2782   "Convert DATE date to universal time in the current article.
2783 If TYPE is `local', convert to local time; if it is `lapsed', output
2784 how much time has lapsed since DATE.  For `lapsed', the value of
2785 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2786 should replace the \"Date:\" one, or should be added below it."
2787   (interactive (list 'ut t))
2788   (let* ((header (or header
2789                      (message-fetch-field "date")
2790                      ""))
2791          (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2792          (date-regexp
2793           (cond
2794            ((not gnus-article-date-lapsed-new-header)
2795             tdate-regexp)
2796            ((eq type 'lapsed)
2797             "^X-Sent:[ \t]")
2798            (t
2799             "^Date:[ \t]")))
2800          (date (if (vectorp header) (mail-header-date header)
2801                  header))
2802          (inhibit-point-motion-hooks t)
2803          pos
2804          bface eface)
2805     (save-excursion
2806       (save-restriction
2807         (article-narrow-to-head)
2808         (when (re-search-forward tdate-regexp nil t)
2809           (setq bface (get-text-property (point-at-bol) 'face)
2810                 date (or (get-text-property (point-at-bol)
2811                                             'original-date)
2812                          date)
2813                 eface (get-text-property (1- (point-at-eol)) 'face))
2814           (forward-line 1))
2815         (when (and date (not (string= date "")))
2816           (goto-char (point-min))
2817           (let ((buffer-read-only nil))
2818             ;; Delete any old Date headers.
2819             (while (re-search-forward date-regexp nil t)
2820               (if pos
2821                   (delete-region (point-at-bol)
2822                                  (progn (gnus-article-forward-header)
2823                                         (point)))
2824                 (delete-region (point-at-bol)
2825                                (progn (gnus-article-forward-header)
2826                                       (forward-char -1)
2827                                       (point)))
2828                 (setq pos (point))))
2829             (when (and (not pos)
2830                        (re-search-forward tdate-regexp nil t))
2831               (forward-line 1))
2832             (gnus-goto-char pos)
2833             (insert (article-make-date-line date (or type 'ut)))
2834             (unless pos
2835               (insert "\n")
2836               (forward-line -1))
2837             ;; Do highlighting.
2838             (beginning-of-line)
2839             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2840               (put-text-property (match-beginning 1) (1+ (match-end 1))
2841                                  'original-date date)
2842               (put-text-property (match-beginning 1) (1+ (match-end 1))
2843                                  'face bface)
2844               (put-text-property (match-beginning 2) (match-end 2)
2845                                  'face eface))))))))
2846
2847 (defun article-make-date-line (date type)
2848   "Return a DATE line of TYPE."
2849   (unless (memq type '(local ut original user iso8601 lapsed english))
2850     (error "Unknown conversion type: %s" type))
2851   (condition-case ()
2852       (let ((time (date-to-time date)))
2853         (cond
2854          ;; Convert to the local timezone.
2855          ((eq type 'local)
2856           (let ((tz (car (current-time-zone time))))
2857             (format "Date: %s %s%02d%02d" (current-time-string time)
2858                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2859                     (/ (% (abs tz) 3600) 60))))
2860          ;; Convert to Universal Time.
2861          ((eq type 'ut)
2862           (concat "Date: "
2863                   (current-time-string
2864                    (let* ((e (parse-time-string date))
2865                           (tm (apply 'encode-time e))
2866                           (ms (car tm))
2867                           (ls (- (cadr tm) (car (current-time-zone time)))))
2868                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2869                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2870                            (t (list ms ls)))))
2871                   " UT"))
2872          ;; Get the original date from the article.
2873          ((eq type 'original)
2874           (concat "Date: " (if (string-match "\n+$" date)
2875                                (substring date 0 (match-beginning 0))
2876                              date)))
2877          ;; Let the user define the format.
2878          ((eq type 'user)
2879           (let ((format (or (condition-case nil
2880                                 (with-current-buffer gnus-summary-buffer
2881                                   gnus-article-time-format)
2882                               (error nil))
2883                             gnus-article-time-format)))
2884             (if (functionp format)
2885                 (funcall format time)
2886               (concat "Date: " (format-time-string format time)))))
2887          ;; ISO 8601.
2888          ((eq type 'iso8601)
2889           (let ((tz (car (current-time-zone time))))
2890             (concat
2891              "Date: "
2892              (format-time-string "%Y%m%dT%H%M%S" time)
2893              (format "%s%02d%02d"
2894                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2895                      (/ (% (abs tz) 3600) 60)))))
2896          ;; Do an X-Sent lapsed format.
2897          ((eq type 'lapsed)
2898           ;; If the date is seriously mangled, the timezone functions are
2899           ;; liable to bug out, so we ignore all errors.
2900           (let* ((now (current-time))
2901                  (real-time (subtract-time now time))
2902                  (real-sec (and real-time
2903                                 (+ (* (float (car real-time)) 65536)
2904                                    (cadr real-time))))
2905                  (sec (and real-time (abs real-sec)))
2906                  num prev)
2907             (cond
2908              ((null real-time)
2909               "X-Sent: Unknown")
2910              ((zerop sec)
2911               "X-Sent: Now")
2912              (t
2913               (concat
2914                "X-Sent: "
2915                ;; This is a bit convoluted, but basically we go
2916                ;; through the time units for years, weeks, etc,
2917                ;; and divide things to see whether that results
2918                ;; in positive answers.
2919                (mapconcat
2920                 (lambda (unit)
2921                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2922                       ;; The (remaining) seconds are too few to
2923                       ;; be divided into this time unit.
2924                       ""
2925                     ;; It's big enough, so we output it.
2926                     (setq sec (- sec (* num (cdr unit))))
2927                     (prog1
2928                         (concat (if prev ", " "") (int-to-string
2929                                                    (floor num))
2930                                 " " (symbol-name (car unit))
2931                                 (if (> num 1) "s" ""))
2932                       (setq prev t))))
2933                 article-time-units "")
2934                ;; If dates are odd, then it might appear like the
2935                ;; article was sent in the future.
2936                (if (> real-sec 0)
2937                    " ago"
2938                  " in the future"))))))
2939          ;; Display the date in proper English
2940          ((eq type 'english)
2941           (let ((dtime (decode-time time)))
2942             (concat
2943              "Date: the "
2944              (number-to-string (nth 3 dtime))
2945              (let ((digit (% (nth 3 dtime) 10)))
2946                (cond
2947                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2948                 ((= digit 1) "st")
2949                 ((= digit 2) "nd")
2950                 ((= digit 3) "rd")
2951                 (t "th")))
2952              " of "
2953              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2954              " "
2955              (number-to-string (nth 5 dtime))
2956              " at "
2957              (format "%02d" (nth 2 dtime))
2958              ":"
2959              (format "%02d" (nth 1 dtime)))))))
2960     (error
2961      (format "Date: %s (from Gnus)" date))))
2962
2963 (defun article-date-local (&optional highlight)
2964   "Convert the current article date to the local timezone."
2965   (interactive (list t))
2966   (article-date-ut 'local highlight))
2967
2968 (defun article-date-english (&optional highlight)
2969   "Convert the current article date to something that is proper English."
2970   (interactive (list t))
2971   (article-date-ut 'english highlight))
2972
2973 (defun article-date-original (&optional highlight)
2974   "Convert the current article date to what it was originally.
2975 This is only useful if you have used some other date conversion
2976 function and want to see what the date was before converting."
2977   (interactive (list t))
2978   (article-date-ut 'original highlight))
2979
2980 (defun article-date-lapsed (&optional highlight)
2981   "Convert the current article date to time lapsed since it was sent."
2982   (interactive (list t))
2983   (article-date-ut 'lapsed highlight))
2984
2985 (defun article-update-date-lapsed ()
2986   "Function to be run from a timer to update the lapsed time line."
2987   (let (deactivate-mark)
2988     (save-excursion
2989       (ignore-errors
2990         (walk-windows
2991          (lambda (w)
2992            (set-buffer (window-buffer w))
2993            (when (eq major-mode 'gnus-article-mode)
2994              (let ((mark (point-marker)))
2995                (goto-char (point-min))
2996                (when (re-search-forward "^X-Sent:" nil t)
2997                  (article-date-lapsed t))
2998                (goto-char (marker-position mark))
2999                (move-marker mark nil))))
3000          nil 'visible)))))
3001
3002 (defun gnus-start-date-timer (&optional n)
3003   "Start a timer to update the X-Sent header in the article buffers.
3004 The numerical prefix says how frequently (in seconds) the function
3005 is to run."
3006   (interactive "p")
3007   (unless n
3008     (setq n 1))
3009   (gnus-stop-date-timer)
3010   (setq article-lapsed-timer
3011         (run-at-time 1 n 'article-update-date-lapsed)))
3012
3013 (defun gnus-stop-date-timer ()
3014   "Stop the X-Sent timer."
3015   (interactive)
3016   (when article-lapsed-timer
3017     (nnheader-cancel-timer article-lapsed-timer)
3018     (setq article-lapsed-timer nil)))
3019
3020 (defun article-date-user (&optional highlight)
3021   "Convert the current article date to the user-defined format.
3022 This format is defined by the `gnus-article-time-format' variable."
3023   (interactive (list t))
3024   (article-date-ut 'user highlight))
3025
3026 (defun article-date-iso8601 (&optional highlight)
3027   "Convert the current article date to ISO8601."
3028   (interactive (list t))
3029   (article-date-ut 'iso8601 highlight))
3030
3031 ;; (defun article-show-all ()
3032 ;;   "Show all hidden text in the article buffer."
3033 ;;   (interactive)
3034 ;;   (save-excursion
3035 ;;     (let ((buffer-read-only nil))
3036 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
3037
3038 (defun article-remove-leading-whitespace ()
3039   "Remove excessive whitespace from all headers."
3040   (interactive)
3041   (save-excursion
3042     (save-restriction
3043       (let ((buffer-read-only nil))
3044         (article-narrow-to-head)
3045         (goto-char (point-min))
3046         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3047           (delete-region (match-beginning 1) (match-end 1)))))))
3048
3049 (defun article-emphasize (&optional arg)
3050   "Emphasize text according to `gnus-emphasis-alist'."
3051   (interactive (gnus-article-hidden-arg))
3052   (unless (gnus-article-check-hidden-text 'emphasis arg)
3053     (save-excursion
3054       (let ((alist (or
3055                     (condition-case nil
3056                         (with-current-buffer gnus-summary-buffer
3057                           gnus-article-emphasis-alist)
3058                       (error))
3059                     gnus-emphasis-alist))
3060             (buffer-read-only nil)
3061             (props (append '(article-type emphasis)
3062                            gnus-hidden-properties))
3063             regexp elem beg invisible visible face)
3064         (article-goto-body)
3065         (setq beg (point))
3066         (while (setq elem (pop alist))
3067           (goto-char beg)
3068           (setq regexp (car elem)
3069                 invisible (nth 1 elem)
3070                 visible (nth 2 elem)
3071                 face (nth 3 elem))
3072           (while (re-search-forward regexp nil t)
3073             (when (and (match-beginning visible) (match-beginning invisible))
3074               (gnus-article-hide-text
3075                (match-beginning invisible) (match-end invisible) props)
3076               (gnus-article-unhide-text-type
3077                (match-beginning visible) (match-end visible) 'emphasis)
3078               (gnus-put-overlay-excluding-newlines
3079                (match-beginning visible) (match-end visible) 'face face)
3080               (gnus-add-wash-type 'emphasis)
3081               (goto-char (match-end invisible)))))))))
3082
3083 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3084   "Setup newsgroup emphasis alist."
3085   (unless gnus-article-emphasis-alist
3086     (let ((name (and gnus-newsgroup-name
3087                      (gnus-group-real-name gnus-newsgroup-name))))
3088       (make-local-variable 'gnus-article-emphasis-alist)
3089       (setq gnus-article-emphasis-alist
3090             (nconc
3091              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3092                (while (setq elem (pop alist))
3093                  (when (and name (string-match (car elem) name))
3094                    (setq alist nil
3095                          highlight (copy-sequence (cdr elem)))))
3096                highlight)
3097              (copy-sequence highlight-words)
3098              (if gnus-newsgroup-name
3099                  (copy-sequence (gnus-group-find-parameter
3100                                  gnus-newsgroup-name 'highlight-words t)))
3101              gnus-emphasis-alist)))))
3102
3103 (eval-when-compile
3104   (defvar gnus-summary-article-menu)
3105   (defvar gnus-summary-post-menu))
3106
3107 ;;; Saving functions.
3108
3109 (defun gnus-article-save (save-buffer file &optional num)
3110   "Save the currently selected article."
3111   (unless gnus-save-all-headers
3112     ;; Remove headers according to `gnus-saved-headers'.
3113     (let ((gnus-visible-headers
3114            (or gnus-saved-headers gnus-visible-headers))
3115           (gnus-article-buffer save-buffer))
3116       (save-excursion
3117         (set-buffer save-buffer)
3118         (article-hide-headers 1 t))))
3119   (save-window-excursion
3120     (if (not gnus-default-article-saver)
3121         (error "No default saver is defined")
3122       ;; !!! Magic!  The saving functions all save
3123       ;; `gnus-save-article-buffer' (or so they think), but we
3124       ;; bind that variable to our save-buffer.
3125       (set-buffer gnus-article-buffer)
3126       (let* ((gnus-save-article-buffer save-buffer)
3127              (filename
3128               (cond
3129                ((not gnus-prompt-before-saving) 'default)
3130                ((eq gnus-prompt-before-saving 'always) nil)
3131                (t file)))
3132              (gnus-number-of-articles-to-be-saved
3133               (when (eq gnus-prompt-before-saving t)
3134                 num)))                  ; Magic
3135         (set-buffer gnus-article-current-summary)
3136         (funcall gnus-default-article-saver filename)))))
3137
3138 (defun gnus-read-save-file-name (prompt &optional filename
3139                                         function group headers variable)
3140   (let ((default-name
3141           (funcall function group headers (symbol-value variable)))
3142         result)
3143     (setq result
3144           (expand-file-name
3145            (cond
3146             ((eq filename 'default)
3147              default-name)
3148             ((eq filename t)
3149              default-name)
3150             (filename filename)
3151             (t
3152              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3153                     (prompt
3154                      (format prompt
3155                              (if (and gnus-number-of-articles-to-be-saved
3156                                       (> gnus-number-of-articles-to-be-saved 1))
3157                                  (format "these %d articles"
3158                                          gnus-number-of-articles-to-be-saved)
3159                                "this article")))
3160                     (file
3161                      ;; Let the split methods have their say.
3162                      (cond
3163                       ;; No split name was found.
3164                       ((null split-name)
3165                        (read-file-name
3166                         (concat prompt " (default "
3167                                 (file-name-nondirectory default-name) ") ")
3168                         (file-name-directory default-name)
3169                         default-name))
3170                       ;; A single group name is returned.
3171                       ((stringp split-name)
3172                        (setq default-name
3173                              (funcall function split-name headers
3174                                       (symbol-value variable)))
3175                        (read-file-name
3176                         (concat prompt " (default "
3177                                 (file-name-nondirectory default-name) ") ")
3178                         (file-name-directory default-name)
3179                         default-name))
3180                       ;; A single split name was found
3181                       ((= 1 (length split-name))
3182                        (let* ((name (expand-file-name
3183                                      (car split-name)
3184                                      gnus-article-save-directory))
3185                               (dir (cond ((file-directory-p name)
3186                                           (file-name-as-directory name))
3187                                          ((file-exists-p name) name)
3188                                          (t gnus-article-save-directory))))
3189                          (read-file-name
3190                           (concat prompt " (default " name ") ")
3191                           dir name)))
3192                       ;; A list of splits was found.
3193                       (t
3194                        (setq split-name (nreverse split-name))
3195                        (let (result)
3196                          (let ((file-name-history
3197                                 (nconc split-name file-name-history)))
3198                            (setq result
3199                                  (expand-file-name
3200                                   (read-file-name
3201                                    (concat prompt " (`M-p' for defaults) ")
3202                                    gnus-article-save-directory
3203                                    (car split-name))
3204                                   gnus-article-save-directory)))
3205                          (car (push result file-name-history)))))))
3206                ;; Create the directory.
3207                (gnus-make-directory (file-name-directory file))
3208                ;; If we have read a directory, we append the default file name.
3209                (when (file-directory-p file)
3210                  (setq file (expand-file-name (file-name-nondirectory
3211                                                default-name)
3212                                               (file-name-as-directory file))))
3213                ;; Possibly translate some characters.
3214                (nnheader-translate-file-chars file))))))
3215     (gnus-make-directory (file-name-directory result))
3216     (set variable result)))
3217
3218 (defun gnus-article-archive-name (group)
3219   "Return the first instance of an \"Archive-name\" in the current buffer."
3220   (let ((case-fold-search t))
3221     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3222       (nnheader-concat gnus-article-save-directory
3223                        (match-string 1)))))
3224
3225 (defun gnus-article-nndoc-name (group)
3226   "If GROUP is an nndoc group, return the name of the parent group."
3227   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3228     (gnus-group-get-parameter group 'save-article-group)))
3229
3230 (defun gnus-summary-save-in-rmail (&optional filename)
3231   "Append this article to Rmail file.
3232 Optional argument FILENAME specifies file name.
3233 Directory to save to is default to `gnus-article-save-directory'."
3234   (setq filename (gnus-read-save-file-name
3235                   "Save %s in rmail file:" filename
3236                   gnus-rmail-save-name gnus-newsgroup-name
3237                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3238   (gnus-eval-in-buffer-window gnus-save-article-buffer
3239     (save-excursion
3240       (save-restriction
3241         (widen)
3242         (gnus-output-to-rmail filename))))
3243   filename)
3244
3245 (defun gnus-summary-save-in-mail (&optional filename)
3246   "Append this article to Unix mail file.
3247 Optional argument FILENAME specifies file name.
3248 Directory to save to is default to `gnus-article-save-directory'."
3249   (setq filename (gnus-read-save-file-name
3250                   "Save %s in Unix mail file:" filename
3251                   gnus-mail-save-name gnus-newsgroup-name
3252                   gnus-current-headers 'gnus-newsgroup-last-mail))
3253   (gnus-eval-in-buffer-window gnus-save-article-buffer
3254     (save-excursion
3255       (save-restriction
3256         (widen)
3257         (if (and (file-readable-p filename)
3258                  (file-regular-p filename)
3259                  (mail-file-babyl-p filename))
3260             (rmail-output-to-rmail-file filename t)
3261           (gnus-output-to-mail filename)))))
3262   filename)
3263
3264 (defun gnus-summary-save-in-file (&optional filename overwrite)
3265   "Append this article to file.
3266 Optional argument FILENAME specifies file name.
3267 Directory to save to is default to `gnus-article-save-directory'."
3268   (setq filename (gnus-read-save-file-name
3269                   "Save %s in file:" filename
3270                   gnus-file-save-name gnus-newsgroup-name
3271                   gnus-current-headers 'gnus-newsgroup-last-file))
3272   (gnus-eval-in-buffer-window gnus-save-article-buffer
3273     (save-excursion
3274       (save-restriction
3275         (widen)
3276         (when (and overwrite
3277                    (file-exists-p filename))
3278           (delete-file filename))
3279         (gnus-output-to-file filename))))
3280   filename)
3281
3282 (defun gnus-summary-write-to-file (&optional filename)
3283   "Write this article to a file, overwriting it if the file exists.
3284 Optional argument FILENAME specifies file name.
3285 The directory to save in defaults to `gnus-article-save-directory'."
3286   (gnus-summary-save-in-file nil t))
3287
3288 (defun gnus-summary-save-body-in-file (&optional filename)
3289   "Append this article body to a file.
3290 Optional argument FILENAME specifies file name.
3291 The directory to save in defaults to `gnus-article-save-directory'."
3292   (setq filename (gnus-read-save-file-name
3293                   "Save %s body in file:" filename
3294                   gnus-file-save-name gnus-newsgroup-name
3295                   gnus-current-headers 'gnus-newsgroup-last-file))
3296   (gnus-eval-in-buffer-window gnus-save-article-buffer
3297     (save-excursion
3298       (save-restriction
3299         (widen)
3300         (when (article-goto-body)
3301           (narrow-to-region (point) (point-max)))
3302         (gnus-output-to-file filename))))
3303   filename)
3304
3305 (defun gnus-summary-save-in-pipe (&optional command)
3306   "Pipe this article to subprocess."
3307   (setq command
3308         (cond ((and (eq command 'default)
3309                     gnus-last-shell-command)
3310                gnus-last-shell-command)
3311               ((stringp command)
3312                command)
3313               (t (read-string
3314                   (format
3315                    "Shell command on %s: "
3316                    (if (and gnus-number-of-articles-to-be-saved
3317                             (> gnus-number-of-articles-to-be-saved 1))
3318                        (format "these %d articles"
3319                                gnus-number-of-articles-to-be-saved)
3320                      "this article"))
3321                   gnus-last-shell-command))))
3322   (when (string-equal command "")
3323     (if gnus-last-shell-command
3324         (setq command gnus-last-shell-command)
3325       (error "A command is required")))
3326   (gnus-eval-in-buffer-window gnus-article-buffer
3327     (save-restriction
3328       (widen)
3329       (shell-command-on-region (point-min) (point-max) command nil)))
3330   (setq gnus-last-shell-command command))
3331
3332 (defun gnus-summary-pipe-to-muttprint (&optional command)
3333   "Pipe this article to muttprint."
3334   (setq command (read-string
3335                  "Print using command: " gnus-summary-muttprint-program
3336                  nil gnus-summary-muttprint-program))
3337   (gnus-summary-save-in-pipe command))
3338
3339 ;;; Article file names when saving.
3340
3341 (defun gnus-capitalize-newsgroup (newsgroup)
3342   "Capitalize NEWSGROUP name."
3343   (when (not (zerop (length newsgroup)))
3344     (concat (char-to-string (upcase (aref newsgroup 0)))
3345             (substring newsgroup 1))))
3346
3347 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3348   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3349 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3350 Otherwise, it is like ~/News/news/group/num."
3351   (let ((default
3352           (expand-file-name
3353            (concat (if (gnus-use-long-file-name 'not-save)
3354                        (gnus-capitalize-newsgroup newsgroup)
3355                      (gnus-newsgroup-directory-form newsgroup))
3356                    "/" (int-to-string (mail-header-number headers)))
3357            gnus-article-save-directory)))
3358     (if (and last-file
3359              (string-equal (file-name-directory default)
3360                            (file-name-directory last-file))
3361              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3362         default
3363       (or last-file default))))
3364
3365 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3366   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3367 If variable `gnus-use-long-file-name' is non-nil, it is
3368 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3369   (let ((default
3370           (expand-file-name
3371            (concat (if (gnus-use-long-file-name 'not-save)
3372                        newsgroup
3373                      (gnus-newsgroup-directory-form newsgroup))
3374                    "/" (int-to-string (mail-header-number headers)))
3375            gnus-article-save-directory)))
3376     (if (and last-file
3377              (string-equal (file-name-directory default)
3378                            (file-name-directory last-file))
3379              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3380         default
3381       (or last-file default))))
3382
3383 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3384   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3385 If variable `gnus-use-long-file-name' is non-nil, it is
3386 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3387   (or last-file
3388       (expand-file-name
3389        (if (gnus-use-long-file-name 'not-save)
3390            newsgroup
3391          (file-relative-name
3392           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3393           default-directory))
3394        gnus-article-save-directory)))
3395
3396 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3397   "Generate file name from sender."
3398   (let ((from (mail-header-from headers)))
3399     (expand-file-name
3400      (if (and from (string-match "\\([^ <]+\\)@" from))
3401          (match-string 1 from)
3402        "nobody")
3403      gnus-article-save-directory)))
3404
3405 (defun article-verify-x-pgp-sig ()
3406   "Verify X-PGP-Sig."
3407   (interactive)
3408   (if (gnus-buffer-live-p gnus-original-article-buffer)
3409       (let ((sig (with-current-buffer gnus-original-article-buffer
3410                    (gnus-fetch-field "X-PGP-Sig")))
3411             items info headers)
3412         (when (and sig
3413                    mml2015-use
3414                    (mml2015-clear-verify-function))
3415           (with-temp-buffer
3416             (insert-buffer-substring gnus-original-article-buffer)
3417             (setq items (split-string sig))
3418             (message-narrow-to-head)
3419             (let ((inhibit-point-motion-hooks t)
3420                   (case-fold-search t))
3421               ;; Don't verify multiple headers.
3422               (setq headers (mapconcat (lambda (header)
3423                                          (concat header ": "
3424                                                  (mail-fetch-field header)
3425                                                  "\n"))
3426                                        (split-string (nth 1 items) ",") "")))
3427             (delete-region (point-min) (point-max))
3428             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3429             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3430             (insert headers)
3431             (widen)
3432             (forward-line)
3433             (while (not (eobp))
3434               (if (looking-at "^-")
3435                   (insert "- "))
3436               (forward-line))
3437             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3438             (insert "Version: " (car items) "\n\n")
3439             (insert (mapconcat 'identity (cddr items) "\n"))
3440             (insert "\n-----END PGP SIGNATURE-----\n")
3441             (let ((mm-security-handle (list (format "multipart/signed"))))
3442               (mml2015-clean-buffer)
3443               (let ((coding-system-for-write (or gnus-newsgroup-charset
3444                                                  'iso-8859-1)))
3445                 (funcall (mml2015-clear-verify-function)))
3446               (setq info
3447                     (or (mm-handle-multipart-ctl-parameter
3448                          mm-security-handle 'gnus-details)
3449                         (mm-handle-multipart-ctl-parameter
3450                          mm-security-handle 'gnus-info)))))
3451           (when info
3452             (let (buffer-read-only bface eface)
3453               (save-restriction
3454                 (message-narrow-to-head)
3455                 (goto-char (point-max))
3456                 (forward-line -1)
3457                 (setq bface (get-text-property (point-at-bol) 'face)
3458                       eface (get-text-property (1- (point-at-eol)) 'face))
3459                 (message-remove-header "X-Gnus-PGP-Verify")
3460                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3461                     (forward-line)
3462                   (goto-char (point-max)))
3463                 (narrow-to-region (point) (point))
3464                 (insert "X-Gnus-PGP-Verify: " info "\n")
3465                 (goto-char (point-min))
3466                 (forward-line)
3467                 (while (not (eobp))
3468                   (if (not (looking-at "^[ \t]"))
3469                       (insert " "))
3470                   (forward-line))
3471                 ;; Do highlighting.
3472                 (goto-char (point-min))
3473                 (when (looking-at "\\([^:]+\\): *")
3474                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3475                                      'face bface)
3476                   (put-text-property (match-end 0) (point-max)
3477                                      'face eface)))))))))
3478
3479 (defun article-verify-cancel-lock ()
3480   "Verify Cancel-Lock header."
3481   (interactive)
3482   (if (gnus-buffer-live-p gnus-original-article-buffer)
3483       (canlock-verify gnus-original-article-buffer)))
3484
3485 (eval-and-compile
3486   (mapcar
3487    (lambda (func)
3488      (let (afunc gfunc)
3489        (if (consp func)
3490            (setq afunc (car func)
3491                  gfunc (cdr func))
3492          (setq afunc func
3493                gfunc (intern (format "gnus-%s" func))))
3494        (defalias gfunc
3495          (when (fboundp afunc)
3496            `(lambda (&optional interactive &rest args)
3497               ,(documentation afunc t)
3498               (interactive (list t))
3499               (save-excursion
3500                 (set-buffer gnus-article-buffer)
3501                 (if interactive
3502                     (call-interactively ',afunc)
3503                   (apply ',afunc args))))))))
3504    '(article-hide-headers
3505      article-verify-x-pgp-sig
3506      article-verify-cancel-lock
3507      article-hide-boring-headers
3508      article-treat-overstrike
3509      article-treat-ansi-sequences
3510      article-fill-long-lines
3511      article-capitalize-sentences
3512      article-remove-cr
3513      article-remove-leading-whitespace
3514      article-display-x-face
3515      article-display-face
3516      article-de-quoted-unreadable
3517      article-de-base64-unreadable
3518      article-decode-HZ
3519      article-wash-html
3520      article-unsplit-urls
3521      article-hide-list-identifiers
3522      article-strip-banner
3523      article-babel
3524      article-hide-pem
3525      article-hide-signature
3526      article-strip-headers-in-body
3527      article-remove-trailing-blank-lines
3528      article-strip-leading-blank-lines
3529      article-strip-multiple-blank-lines
3530      article-strip-leading-space
3531      article-strip-trailing-space
3532      article-strip-blank-lines
3533      article-strip-all-blank-lines
3534      article-date-local
3535      article-date-english
3536      article-date-iso8601
3537      article-date-original
3538      article-date-ut
3539      article-decode-mime-words
3540      article-decode-charset
3541      article-decode-encoded-words
3542      article-date-user
3543      article-date-lapsed
3544      article-emphasize
3545      article-treat-dumbquotes
3546      article-normalize-headers
3547 ;;     (article-show-all . gnus-article-show-all-headers)
3548      )))
3549 \f
3550 ;;;
3551 ;;; Gnus article mode
3552 ;;;
3553
3554 (put 'gnus-article-mode 'mode-class 'special)
3555
3556 (set-keymap-parent gnus-article-mode-map widget-keymap)
3557
3558 (gnus-define-keys gnus-article-mode-map
3559   " " gnus-article-goto-next-page
3560   "\177" gnus-article-goto-prev-page
3561   [delete] gnus-article-goto-prev-page
3562   [backspace] gnus-article-goto-prev-page
3563   "\C-c^" gnus-article-refer-article
3564   "h" gnus-article-show-summary
3565   "s" gnus-article-show-summary
3566   "\C-c\C-m" gnus-article-mail
3567   "?" gnus-article-describe-briefly
3568   "e" gnus-summary-edit-article
3569   "<" beginning-of-buffer
3570   ">" end-of-buffer
3571   "\C-c\C-i" gnus-info-find-node
3572   "\C-c\C-b" gnus-bug
3573   "R" gnus-article-reply-with-original
3574   "F" gnus-article-followup-with-original
3575   "\C-hk" gnus-article-describe-key
3576   "\C-hc" gnus-article-describe-key-briefly
3577
3578   "\C-d" gnus-article-read-summary-keys
3579   "\M-*" gnus-article-read-summary-keys
3580   "\M-#" gnus-article-read-summary-keys
3581   "\M-^" gnus-article-read-summary-keys
3582   "\M-g" gnus-article-read-summary-keys)
3583
3584 (substitute-key-definition
3585  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3586
3587 (defun gnus-article-make-menu-bar ()
3588   (unless (boundp 'gnus-article-commands-menu)
3589     (gnus-summary-make-menu-bar))
3590   (gnus-turn-off-edit-menu 'article)
3591   (unless (boundp 'gnus-article-article-menu)
3592     (easy-menu-define
3593      gnus-article-article-menu gnus-article-mode-map ""
3594      '("Article"
3595        ["Scroll forwards" gnus-article-goto-next-page t]
3596        ["Scroll backwards" gnus-article-goto-prev-page t]
3597        ["Show summary" gnus-article-show-summary t]
3598        ["Fetch Message-ID at point" gnus-article-refer-article t]
3599        ["Mail to address at point" gnus-article-mail t]
3600        ["Send a bug report" gnus-bug t]))
3601
3602     (easy-menu-define
3603      gnus-article-treatment-menu gnus-article-mode-map ""
3604      ;; Fixme: this should use :active (and maybe :visible).
3605      '("Treatment"
3606        ["Hide headers" gnus-article-hide-headers t]
3607        ["Hide signature" gnus-article-hide-signature t]
3608        ["Hide citation" gnus-article-hide-citation t]
3609        ["Treat overstrike" gnus-article-treat-overstrike t]
3610        ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3611        ["Remove carriage return" gnus-article-remove-cr t]
3612        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3613        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3614        ["Remove base64" gnus-article-de-base64-unreadable t]
3615        ["Treat html" gnus-article-wash-html t]
3616        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3617        ["Decode HZ" gnus-article-decode-HZ t]))
3618
3619     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3620
3621     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3622
3623     (gnus-run-hooks 'gnus-article-menu-hook)))
3624
3625 (defun gnus-article-mode ()
3626   "Major mode for displaying an article.
3627
3628 All normal editing commands are switched off.
3629
3630 The following commands are available in addition to all summary mode
3631 commands:
3632 \\<gnus-article-mode-map>
3633 \\[gnus-article-next-page]\t Scroll the article one page forwards
3634 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3635 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3636 \\[gnus-article-show-summary]\t Display the summary buffer
3637 \\[gnus-article-mail]\t Send a reply to the address near point
3638 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3639 \\[gnus-info-find-node]\t Go to the Gnus info node"
3640   (interactive)
3641   (gnus-simplify-mode-line)
3642   (setq mode-name "Article")
3643   (setq major-mode 'gnus-article-mode)
3644   (make-local-variable 'minor-mode-alist)
3645   (use-local-map gnus-article-mode-map)
3646   (when (gnus-visual-p 'article-menu 'menu)
3647     (gnus-article-make-menu-bar)
3648     (when gnus-summary-tool-bar-map
3649       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3650   (gnus-update-format-specifications nil 'article-mode)
3651   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3652   (set (make-local-variable 'gnus-page-broken) nil)
3653   (make-local-variable 'gnus-button-marker-list)
3654   (make-local-variable 'gnus-article-current-summary)
3655   (make-local-variable 'gnus-article-mime-handles)
3656   (make-local-variable 'gnus-article-decoded-p)
3657   (make-local-variable 'gnus-article-mime-handle-alist)
3658   (make-local-variable 'gnus-article-wash-types)
3659   (make-local-variable 'gnus-article-image-alist)
3660   (make-local-variable 'gnus-article-charset)
3661   (make-local-variable 'gnus-article-ignored-charsets)
3662   (gnus-set-default-directory)
3663   (buffer-disable-undo)
3664   (setq buffer-read-only t
3665         show-trailing-whitespace nil)
3666   (set-syntax-table gnus-article-mode-syntax-table)
3667   (mm-enable-multibyte)
3668   (gnus-run-hooks 'gnus-article-mode-hook))
3669
3670 (defun gnus-article-setup-buffer ()
3671   "Initialize the article buffer."
3672   (let* ((name (if gnus-single-article-buffer "*Article*"
3673                  (concat "*Article " gnus-newsgroup-name "*")))
3674          (original
3675           (progn (string-match "\\*Article" name)
3676                  (concat " *Original Article"
3677                          (substring name (match-end 0))))))
3678     (setq gnus-article-buffer name)
3679     (setq gnus-original-article-buffer original)
3680     (setq gnus-article-mime-handle-alist nil)
3681     ;; This might be a variable local to the summary buffer.
3682     (unless gnus-single-article-buffer
3683       (save-excursion
3684         (set-buffer gnus-summary-buffer)
3685         (setq gnus-article-buffer name)
3686         (setq gnus-original-article-buffer original)
3687         (gnus-set-global-variables)))
3688     (gnus-article-setup-highlight-words)
3689     ;; Init original article buffer.
3690     (save-excursion
3691       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3692       (mm-enable-multibyte)
3693       (setq major-mode 'gnus-original-article-mode)
3694       (make-local-variable 'gnus-original-article))
3695     (if (get-buffer name)
3696         (save-excursion
3697           (set-buffer name)
3698           (when (and gnus-article-edit-mode
3699                      (buffer-modified-p)
3700                      (not
3701                       (y-or-n-p "Article mode edit in progress; discard? ")))
3702             (error "Action aborted"))
3703           (set (make-local-variable 'gnus-article-edit-mode) nil)
3704           (when gnus-article-mime-handles
3705             (mm-destroy-parts gnus-article-mime-handles)
3706             (setq gnus-article-mime-handles nil))
3707           ;; Set it to nil in article-buffer!
3708           (setq gnus-article-mime-handle-alist nil)
3709           (buffer-disable-undo)
3710           (setq buffer-read-only t)
3711           ;; This list just keeps growing if we don't reset it.
3712           (setq gnus-button-marker-list nil)
3713           (unless (eq major-mode 'gnus-article-mode)
3714             (gnus-article-mode))
3715           (current-buffer))
3716       (save-excursion
3717         (set-buffer (gnus-get-buffer-create name))
3718         (gnus-article-mode)
3719         (make-local-variable 'gnus-summary-buffer)
3720         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3721         (current-buffer)))))
3722
3723 ;; Set article window start at LINE, where LINE is the number of lines
3724 ;; from the head of the article.
3725 (defun gnus-article-set-window-start (&optional line)
3726   (set-window-start
3727    (gnus-get-buffer-window gnus-article-buffer t)
3728    (save-excursion
3729      (set-buffer gnus-article-buffer)
3730      (goto-char (point-min))
3731      (if (not line)
3732          (point-min)
3733        (gnus-message 6 "Moved to bookmark")
3734        (search-forward "\n\n" nil t)
3735        (forward-line line)
3736        (point)))))
3737
3738 (defun gnus-article-prepare (article &optional all-headers header)
3739   "Prepare ARTICLE in article mode buffer.
3740 ARTICLE should either be an article number or a Message-ID.
3741 If ARTICLE is an id, HEADER should be the article headers.
3742 If ALL-HEADERS is non-nil, no headers are hidden."
3743   (save-excursion
3744     ;; Make sure we start in a summary buffer.
3745     (unless (eq major-mode 'gnus-summary-mode)
3746       (set-buffer gnus-summary-buffer))
3747     (setq gnus-summary-buffer (current-buffer))
3748     (let* ((gnus-article (if header (mail-header-number header) article))
3749            (summary-buffer (current-buffer))
3750            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3751            (group gnus-newsgroup-name)
3752            result)
3753       (save-excursion
3754         (gnus-article-setup-buffer)
3755         (set-buffer gnus-article-buffer)
3756         ;; Deactivate active regions.
3757         (when (and (boundp 'transient-mark-mode)
3758                    transient-mark-mode)
3759           (setq mark-active nil))
3760         (if (not (setq result (let ((buffer-read-only nil))
3761                                 (gnus-request-article-this-buffer
3762                                  article group))))
3763             ;; There is no such article.
3764             (save-excursion
3765               (when (and (numberp article)
3766                          (not (memq article gnus-newsgroup-sparse)))
3767                 (setq gnus-article-current
3768                       (cons gnus-newsgroup-name article))
3769                 (set-buffer gnus-summary-buffer)
3770                 (setq gnus-current-article article)
3771                 (if (and (memq article gnus-newsgroup-undownloaded)
3772                          (not (gnus-online (gnus-find-method-for-group
3773                                             gnus-newsgroup-name))))
3774                     (progn
3775                       (gnus-summary-set-agent-mark article)
3776                       (message "Message marked for downloading"))
3777                   (gnus-summary-mark-article article gnus-canceled-mark)
3778                   (unless (memq article gnus-newsgroup-sparse)
3779                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3780           (if (or (eq result 'pseudo)
3781                   (eq result 'nneething))
3782               (progn
3783                 (save-excursion
3784                   (set-buffer summary-buffer)
3785                   (push article gnus-newsgroup-history)
3786                   (setq gnus-last-article gnus-current-article
3787                         gnus-current-article 0
3788                         gnus-current-headers nil
3789                         gnus-article-current nil)
3790                   (if (eq result 'nneething)
3791                       (gnus-configure-windows 'summary)
3792                     (gnus-configure-windows 'article))
3793                   (gnus-set-global-variables))
3794                 (let ((gnus-article-mime-handle-alist-1
3795                        gnus-article-mime-handle-alist))
3796                   (gnus-set-mode-line 'article)))
3797             ;; The result from the `request' was an actual article -
3798             ;; or at least some text that is now displayed in the
3799             ;; article buffer.
3800             (when (and (numberp article)
3801                        (not (eq article gnus-current-article)))
3802               ;; Seems like a new article has been selected.
3803               ;; `gnus-current-article' must be an article number.
3804               (save-excursion
3805                 (set-buffer summary-buffer)
3806                 (push article gnus-newsgroup-history)
3807                 (setq gnus-last-article gnus-current-article
3808                       gnus-current-article article
3809                       gnus-current-headers
3810                       (gnus-summary-article-header gnus-current-article)
3811                       gnus-article-current
3812                       (cons gnus-newsgroup-name gnus-current-article))
3813                 (unless (vectorp gnus-current-headers)
3814                   (setq gnus-current-headers nil))
3815                 (gnus-summary-goto-subject gnus-current-article)
3816                 (when (gnus-summary-show-thread)
3817                   ;; If the summary buffer really was folded, the
3818                   ;; previous goto may not actually have gone to
3819                   ;; the right article, but the thread root instead.
3820                   ;; So we go again.
3821                   (gnus-summary-goto-subject gnus-current-article))
3822                 (gnus-run-hooks 'gnus-mark-article-hook)
3823                 (gnus-set-mode-line 'summary)
3824                 (when (gnus-visual-p 'article-highlight 'highlight)
3825                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3826                 ;; Set the global newsgroup variables here.
3827                 (gnus-set-global-variables)
3828                 (setq gnus-have-all-headers
3829                       (or all-headers gnus-show-all-headers))))
3830             (save-excursion
3831               (gnus-configure-windows 'article))
3832             (when (or (numberp article)
3833                       (stringp article))
3834               (gnus-article-prepare-display)
3835               ;; Do page break.
3836               (goto-char (point-min))
3837               (when gnus-break-pages
3838                 (gnus-narrow-to-page)))
3839             (let ((gnus-article-mime-handle-alist-1
3840                    gnus-article-mime-handle-alist))
3841               (gnus-set-mode-line 'article))
3842             (article-goto-body)
3843             (unless (bobp)
3844               (forward-line -1))
3845             (set-window-point (get-buffer-window (current-buffer)) (point))
3846             (gnus-configure-windows 'article)
3847             t))))))
3848
3849 ;;;###autoload
3850 (defun gnus-article-prepare-display ()
3851   "Make the current buffer look like a nice article."
3852   ;; Hooks for getting information from the article.
3853   ;; This hook must be called before being narrowed.
3854   (let ((gnus-article-buffer (current-buffer))
3855         buffer-read-only)
3856     (unless (eq major-mode 'gnus-article-mode)
3857       (gnus-article-mode))
3858     (setq buffer-read-only nil
3859           gnus-article-wash-types nil
3860           gnus-article-image-alist nil)
3861     (gnus-run-hooks 'gnus-tmp-internal-hook)
3862     (when gnus-display-mime-function
3863       (funcall gnus-display-mime-function))
3864     (gnus-run-hooks 'gnus-article-prepare-hook)))
3865
3866 ;;;
3867 ;;; Gnus MIME viewing functions
3868 ;;;
3869
3870 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3871   "Format of the MIME buttons.
3872
3873 Valid specifiers include:
3874 %t  The MIME type
3875 %T  MIME type, along with additional info
3876 %n  The `name' parameter
3877 %d  The description, if any
3878 %l  The length of the encoded part
3879 %p  The part identifier number
3880 %e  Dots if the part isn't displayed
3881
3882 General format specifiers can also be used.  See Info node
3883 `(gnus)Formatting Variables'.")
3884
3885 (defvar gnus-mime-button-line-format-alist
3886   '((?t gnus-tmp-type ?s)
3887     (?T gnus-tmp-type-long ?s)
3888     (?n gnus-tmp-name ?s)
3889     (?d gnus-tmp-description ?s)
3890     (?p gnus-tmp-id ?s)
3891     (?l gnus-tmp-length ?d)
3892     (?e gnus-tmp-dots ?s)))
3893
3894 (defvar gnus-mime-button-commands
3895   '((gnus-article-press-button "\r" "Toggle Display")
3896     (gnus-mime-view-part "v" "View Interactively...")
3897     (gnus-mime-view-part-as-type "t" "View As Type...")
3898     (gnus-mime-view-part-as-charset "C" "View As charset...")
3899     (gnus-mime-save-part "o" "Save...")
3900     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3901     (gnus-mime-delete-part "d" "Delete part")
3902     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3903     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3904     (gnus-mime-view-part-internally "E" "View Internally")
3905     (gnus-mime-view-part-externally "e" "View Externally")
3906     (gnus-mime-print-part "p" "Print")
3907     (gnus-mime-pipe-part "|" "Pipe To Command...")
3908     (gnus-mime-action-on-part "." "Take action on the part...")))
3909
3910 (defun gnus-article-mime-part-status ()
3911   (if gnus-article-mime-handle-alist-1
3912       (if (eq 1 (length gnus-article-mime-handle-alist-1))
3913           " (1 part)"
3914         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3915     ""))
3916
3917 (defvar gnus-mime-button-map
3918   (let ((map (make-sparse-keymap)))
3919     (define-key map gnus-mouse-2 'gnus-article-push-button)
3920     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3921     (dolist (c gnus-mime-button-commands)
3922       (define-key map (cadr c) (car c)))
3923     map))
3924
3925 (easy-menu-define
3926   gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
3927   `("MIME Part"
3928     ,@(mapcar (lambda (c)
3929                 (vector (caddr c) (car c) :enable t))
3930               gnus-mime-button-commands)))
3931
3932 (defun gnus-mime-button-menu (event prefix)
3933  "Construct a context-sensitive menu of MIME commands."
3934  (interactive "e\nP")
3935  (save-window-excursion
3936    (let ((pos (event-start event)))
3937      (select-window (posn-window pos))
3938      (goto-char (posn-point pos))
3939      (gnus-article-check-buffer)
3940      (popup-menu gnus-mime-button-menu nil prefix))))
3941
3942 (defun gnus-mime-view-all-parts (&optional handles)
3943   "View all the MIME parts."
3944   (interactive)
3945   (with-current-buffer gnus-article-buffer
3946     (let ((handles (or handles gnus-article-mime-handles))
3947           (mail-parse-charset gnus-newsgroup-charset)
3948           (mail-parse-ignored-charsets
3949            (with-current-buffer gnus-summary-buffer
3950              gnus-newsgroup-ignored-charsets)))
3951       (when handles
3952         (mm-remove-parts handles)
3953         (goto-char (point-min))
3954         (or (search-forward "\n\n") (goto-char (point-max)))
3955         (let (buffer-read-only)
3956           (delete-region (point) (point-max))
3957           (mm-display-parts handles))))))
3958
3959 (eval-when-compile
3960   (defsubst gnus-article-edit-part (handles)
3961     "Edit an article in order to delete a mime part.
3962 This function is exclusively used by `gnus-mime-save-part-and-strip'
3963 and `gnus-mime-delete-part', and not provided at run-time normally."
3964     (gnus-article-edit-article
3965      `(lambda ()
3966         (erase-buffer)
3967         (let ((mail-parse-charset (or gnus-article-charset
3968                                       ',gnus-newsgroup-charset))
3969               (mail-parse-ignored-charsets
3970                (or gnus-article-ignored-charsets
3971                    ',gnus-newsgroup-ignored-charsets))
3972               (mbl mml-buffer-list))
3973           (setq mml-buffer-list nil)
3974           (insert-buffer gnus-original-article-buffer)
3975           (mime-to-mml ',handles)
3976           (setq gnus-article-mime-handles nil)
3977           (let ((mbl1 mml-buffer-list))
3978             (setq mml-buffer-list mbl)
3979             (set (make-local-variable 'mml-buffer-list) mbl1))
3980           (gnus-make-local-hook 'kill-buffer-hook)
3981           (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3982      `(lambda (no-highlight)
3983         (let ((mail-parse-charset (or gnus-article-charset
3984                                       ',gnus-newsgroup-charset))
3985               (message-options message-options)
3986               (message-options-set-recipient)
3987               (mail-parse-ignored-charsets
3988                (or gnus-article-ignored-charsets
3989                    ',gnus-newsgroup-ignored-charsets)))
3990           (mml-to-mime)
3991           (mml-destroy-buffers)
3992           (remove-hook 'kill-buffer-hook
3993                        'mml-destroy-buffers t)
3994           (kill-local-variable 'mml-buffer-list))
3995         (gnus-summary-edit-article-done
3996          ,(or (mail-header-references gnus-current-headers) "")
3997          ,(gnus-group-read-only-p)
3998          ,gnus-summary-buffer no-highlight)))
3999     (gnus-article-edit-done)
4000     (gnus-summary-expand-window)
4001     (gnus-summary-show-article)))
4002
4003 (defun gnus-mime-save-part-and-strip ()
4004   "Save the MIME part under point then replace it with an external body."
4005   (interactive)
4006   (gnus-article-check-buffer)
4007   (when (gnus-group-read-only-p)
4008     (error "The current group does not support deleting of parts"))
4009   (when (mm-complicated-handles gnus-article-mime-handles)
4010     (error "\
4011 The current article has a complicated MIME structure, giving up..."))
4012   (when (gnus-yes-or-no-p "\
4013 Deleting parts may malfunction or destroy the article; continue? ")
4014     (let* ((data (get-text-property (point) 'gnus-data))
4015            file param
4016            (handles gnus-article-mime-handles))
4017       (setq file (and data (mm-save-part data)))
4018       (when file
4019         (with-current-buffer (mm-handle-buffer data)
4020           (erase-buffer)
4021           (insert "Content-Type: " (mm-handle-media-type data))
4022           (mml-insert-parameter-string (cdr (mm-handle-type data))
4023                                        '(charset))
4024           (insert "\n")
4025           (insert "Content-ID: " (message-make-message-id) "\n")
4026           (insert "Content-Transfer-Encoding: binary\n")
4027           (insert "\n"))
4028         (setcdr data
4029                 (cdr (mm-make-handle nil
4030                                      `("message/external-body"
4031                                        (access-type . "LOCAL-FILE")
4032                                        (name . ,file)))))
4033         (set-buffer gnus-summary-buffer)
4034         (gnus-article-edit-part handles)))))
4035
4036 (defun gnus-mime-delete-part ()
4037   "Delete the MIME part under point.
4038 Replace it with some information about the removed part."
4039   (interactive)
4040   (gnus-article-check-buffer)
4041   (when (gnus-group-read-only-p)
4042     (error "The current group does not support deleting of parts"))
4043   (when (mm-complicated-handles gnus-article-mime-handles)
4044     (error "\
4045 The current article has a complicated MIME structure, giving up..."))
4046   (when (gnus-yes-or-no-p "\
4047 Deleting parts may malfunction or destroy the article; continue? ")
4048     (let* ((data (get-text-property (point) 'gnus-data))
4049            (handles gnus-article-mime-handles)
4050            (none "(none)")
4051            (description
4052             (or
4053              (mail-decode-encoded-word-string (or (mm-handle-description data)
4054                                                   none))))
4055            (filename
4056             (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4057                 none))
4058            (type (mm-handle-media-type data)))
4059       (unless data
4060         (error "No MIME part under point"))
4061       (with-current-buffer (mm-handle-buffer data)
4062         (let ((bsize (format "%s" (buffer-size))))
4063           (erase-buffer)
4064           (insert
4065            (concat
4066             ",----\n"
4067             "| The following attachment has been deleted:\n"
4068             "|\n"
4069             "| Type:           " type "\n"
4070             "| Filename:       " filename "\n"
4071             "| Size (encoded): " bsize " Byte\n"
4072             "| Description:    " description "\n"
4073             "`----\n"))
4074           (setcdr data
4075                   (cdr (mm-make-handle
4076                         nil `("text/plain") nil nil
4077                         (list "attachment")
4078                         (format "Deleted attachment (%s bytes)" bsize))))))
4079       (set-buffer gnus-summary-buffer)
4080       (gnus-article-edit-part handles))))
4081
4082 (defun gnus-mime-save-part ()
4083   "Save the MIME part under point."
4084   (interactive)
4085   (gnus-article-check-buffer)
4086   (let ((data (get-text-property (point) 'gnus-data)))
4087     (when data
4088       (mm-save-part data))))
4089
4090 (defun gnus-mime-pipe-part ()
4091   "Pipe the MIME part under point to a process."
4092   (interactive)
4093   (gnus-article-check-buffer)
4094   (let ((data (get-text-property (point) 'gnus-data)))
4095     (when data
4096       (mm-pipe-part data))))
4097
4098 (defun gnus-mime-view-part ()
4099   "Interactively choose a viewing method for the MIME part under point."
4100   (interactive)
4101   (gnus-article-check-buffer)
4102   (let ((data (get-text-property (point) 'gnus-data)))
4103     (when data
4104       (setq gnus-article-mime-handles
4105             (mm-merge-handles
4106              gnus-article-mime-handles (setq data (copy-sequence data))))
4107       (mm-interactively-view-part data))))
4108
4109 (defun gnus-mime-view-part-as-type-internal ()
4110   (gnus-article-check-buffer)
4111   (let* ((name (mail-content-type-get
4112                 (mm-handle-type (get-text-property (point) 'gnus-data))
4113                 'name))
4114          (def-type (and name (mm-default-file-encoding name))))
4115     (and def-type (cons def-type 0))))
4116
4117 (defun gnus-mime-view-part-as-type (&optional mime-type)
4118   "Choose a MIME media type, and view the part as such."
4119   (interactive)
4120   (unless mime-type
4121     (setq mime-type (completing-read
4122                      "View as MIME type: "
4123                      (mapcar #'list (mailcap-mime-types))
4124                      nil nil
4125                      (gnus-mime-view-part-as-type-internal))))
4126   (gnus-article-check-buffer)
4127   (let ((handle (get-text-property (point) 'gnus-data)))
4128     (when handle
4129       (setq handle
4130             (mm-make-handle (mm-handle-buffer handle)
4131                             (cons mime-type (cdr (mm-handle-type handle)))
4132                             (mm-handle-encoding handle)
4133                             (mm-handle-undisplayer handle)
4134                             (mm-handle-disposition handle)
4135                             (mm-handle-description handle)
4136                             nil
4137                             (mm-handle-id handle)))
4138       (setq gnus-article-mime-handles
4139             (mm-merge-handles gnus-article-mime-handles handle))
4140       (gnus-mm-display-part handle))))
4141
4142 (eval-when-compile
4143   (require 'jka-compr))
4144
4145 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4146 ;; emacs can do that itself.
4147 ;;
4148 (defun gnus-mime-jka-compr-maybe-uncompress ()
4149   "Uncompress the current buffer if `auto-compression-mode' is enabled.
4150 The uncompress method used is derived from `buffer-file-name'."
4151   (when (and (fboundp 'jka-compr-installed-p)
4152              (jka-compr-installed-p))
4153     (let ((info (jka-compr-get-compression-info buffer-file-name)))
4154       (when info
4155         (let ((basename (file-name-nondirectory buffer-file-name))
4156               (args     (jka-compr-info-uncompress-args    info))
4157               (prog     (jka-compr-info-uncompress-program info))
4158               (message  (jka-compr-info-uncompress-message info))
4159               (err-file (jka-compr-make-temp-name)))
4160           (if message
4161               (message "%s %s..." message basename))
4162           (unwind-protect
4163               (unless (memq (apply 'call-process-region
4164                                    (point-min) (point-max)
4165                                    prog
4166                                    t (list t err-file) nil
4167                                    args)
4168                             jka-compr-acceptable-retval-list)
4169                 (jka-compr-error prog args basename message err-file))
4170             (jka-compr-delete-temp-file err-file)))))))
4171
4172 (defun gnus-mime-copy-part (&optional handle)
4173   "Put the MIME part under point into a new buffer.
4174 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4175 are decompressed."
4176   (interactive)
4177   (gnus-article-check-buffer)
4178   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4179          (contents (and handle (mm-get-part handle)))
4180          (base (and handle
4181                     (file-name-nondirectory
4182                      (or
4183                       (mail-content-type-get (mm-handle-type handle) 'name)
4184                       (mail-content-type-get (mm-handle-disposition handle)
4185                                              'filename)
4186                       "*decoded*"))))
4187          (buffer (and base (generate-new-buffer base))))
4188     (when contents
4189       (switch-to-buffer buffer)
4190       (insert contents)
4191       ;; We do it this way to make `normal-mode' set the appropriate mode.
4192       (unwind-protect
4193           (progn
4194             (setq buffer-file-name (expand-file-name base))
4195             (gnus-mime-jka-compr-maybe-uncompress)
4196             (normal-mode))
4197         (setq buffer-file-name nil))
4198       (goto-char (point-min)))))
4199
4200 (defun gnus-mime-print-part (&optional handle filename)
4201   "Print the MIME part under point."
4202   (interactive (list nil (ps-print-preprint current-prefix-arg)))
4203   (gnus-article-check-buffer)
4204   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4205          (contents (and handle (mm-get-part handle)))
4206          (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4207          (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4208     (when contents
4209         (if printer
4210             (unwind-protect
4211                 (progn
4212                   (mm-save-part-to-file handle file)
4213                   (call-process shell-file-name nil
4214                                 (generate-new-buffer " *mm*")
4215                                 nil
4216                                 shell-command-switch
4217                                 (mm-mailcap-command
4218                                  printer file (mm-handle-type handle))))
4219               (delete-file file))
4220           (with-temp-buffer
4221             (insert contents)
4222             (gnus-print-buffer))
4223           (ps-despool filename)))))
4224
4225 (defun gnus-mime-inline-part (&optional handle arg)
4226   "Insert the MIME part under point into the current buffer."
4227   (interactive (list nil current-prefix-arg))
4228   (gnus-article-check-buffer)
4229   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4230          contents charset
4231          (b (point))
4232          buffer-read-only)
4233     (when handle
4234       (if (and (not arg) (mm-handle-undisplayer handle))
4235           (mm-remove-part handle)
4236         (setq contents (mm-get-part handle))
4237         (cond
4238          ((not arg)
4239           (setq charset (or (mail-content-type-get
4240                              (mm-handle-type handle) 'charset)
4241                             gnus-newsgroup-charset)))
4242          ((numberp arg)
4243           (if (mm-handle-undisplayer handle)
4244               (mm-remove-part handle))
4245           (setq charset
4246                 (or (cdr (assq arg
4247                                gnus-summary-show-article-charset-alist))
4248                     (mm-read-coding-system "Charset: ")))))
4249         (forward-line 2)
4250         (mm-insert-inline handle
4251                           (if (and charset
4252                                    (setq charset (mm-charset-to-coding-system
4253                                                   charset))
4254                                    (not (eq charset 'ascii)))
4255                               (mm-decode-coding-string contents charset)
4256                             contents))
4257         (goto-char b)))))
4258
4259 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4260   "Insert the MIME part under point into the current buffer using the
4261 specified charset."
4262   (interactive (list nil current-prefix-arg))
4263   (gnus-article-check-buffer)
4264   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4265          contents charset
4266          (b (point))
4267          buffer-read-only)
4268     (when handle
4269       (if (mm-handle-undisplayer handle)
4270           (mm-remove-part handle))
4271       (let ((gnus-newsgroup-charset
4272              (or (cdr (assq arg
4273                             gnus-summary-show-article-charset-alist))
4274                  (mm-read-coding-system "Charset: ")))
4275           (gnus-newsgroup-ignored-charsets 'gnus-all))
4276         (gnus-article-press-button)))))
4277
4278 (defun gnus-mime-view-part-externally (&optional handle)
4279   "View the MIME part under point with an external viewer."
4280   (interactive)
4281   (gnus-article-check-buffer)
4282   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4283          (mm-user-display-methods nil)
4284          (mm-inlined-types nil)
4285          (mail-parse-charset gnus-newsgroup-charset)
4286          (mail-parse-ignored-charsets
4287           (with-current-buffer gnus-summary-buffer
4288             gnus-newsgroup-ignored-charsets)))
4289     (when handle
4290       (if (mm-handle-undisplayer handle)
4291           (mm-remove-part handle)
4292         (mm-display-part handle)))))
4293
4294 (defun gnus-mime-view-part-internally (&optional handle)
4295   "View the MIME part under point with an internal viewer.
4296 If no internal viewer is available, use an external viewer."
4297   (interactive)
4298   (gnus-article-check-buffer)
4299   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4300          (mm-inlined-types '(".*"))
4301          (mm-inline-large-images t)
4302          (mail-parse-charset gnus-newsgroup-charset)
4303          (mail-parse-ignored-charsets
4304           (with-current-buffer gnus-summary-buffer
4305             gnus-newsgroup-ignored-charsets))
4306          buffer-read-only)
4307     (when handle
4308       (if (mm-handle-undisplayer handle)
4309           (mm-remove-part handle)
4310         (mm-display-part handle)))))
4311
4312 (defun gnus-mime-action-on-part (&optional action)
4313   "Do something with the MIME attachment at \(point\)."
4314   (interactive
4315    (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4316   (gnus-article-check-buffer)
4317   (let ((action-pair (assoc action gnus-mime-action-alist)))
4318     (if action-pair
4319         (funcall (cdr action-pair)))))
4320
4321 (defun gnus-article-part-wrapper (n function)
4322   (with-current-buffer gnus-article-buffer
4323     (when (> n (length gnus-article-mime-handle-alist))
4324       (error "No such part"))
4325     (gnus-article-goto-part n)
4326     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4327       (funcall function handle))))
4328
4329 (defun gnus-article-pipe-part (n)
4330   "Pipe MIME part N, which is the numerical prefix."
4331   (interactive "p")
4332   (gnus-article-part-wrapper n 'mm-pipe-part))
4333
4334 (defun gnus-article-save-part (n)
4335   "Save MIME part N, which is the numerical prefix."
4336   (interactive "p")
4337   (gnus-article-part-wrapper n 'mm-save-part))
4338
4339 (defun gnus-article-interactively-view-part (n)
4340   "View MIME part N interactively, which is the numerical prefix."
4341   (interactive "p")
4342   (gnus-article-part-wrapper n 'mm-interactively-view-part))
4343
4344 (defun gnus-article-copy-part (n)
4345   "Copy MIME part N, which is the numerical prefix."
4346   (interactive "p")
4347   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4348
4349 (defun gnus-article-view-part-as-charset (n)
4350   "View MIME part N using a specified charset.
4351 N is the numerical prefix."
4352   (interactive "p")
4353   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4354
4355 (defun gnus-article-view-part-externally (n)
4356   "View MIME part N externally, which is the numerical prefix."
4357   (interactive "p")
4358   (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4359
4360 (defun gnus-article-inline-part (n)
4361   "Inline MIME part N, which is the numerical prefix."
4362   (interactive "p")
4363   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4364
4365 (defun gnus-article-mime-match-handle-first (condition)
4366   (if condition
4367       (let ((alist gnus-article-mime-handle-alist) ihandle n)
4368         (while (setq ihandle (pop alist))
4369           (if (and (cond
4370                     ((functionp condition)
4371                      (funcall condition (cdr ihandle)))
4372                     ((eq condition 'undisplayed)
4373                      (not (or (mm-handle-undisplayer (cdr ihandle))
4374                               (equal (mm-handle-media-type (cdr ihandle))
4375                                      "multipart/alternative"))))
4376                     ((eq condition 'undisplayed-alternative)
4377                      (not (mm-handle-undisplayer (cdr ihandle))))
4378                     (t t))
4379                    (gnus-article-goto-part (car ihandle))
4380                    (or (not n) (< (car ihandle) n)))
4381               (setq n (car ihandle))))
4382         (or n 1))
4383     1))
4384
4385 (defun gnus-article-view-part (&optional n)
4386   "View MIME part N, which is the numerical prefix."
4387   (interactive "P")
4388   (with-current-buffer gnus-article-buffer
4389     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4390                              gnus-article-mime-match-handle-function)))
4391     (when (> n (length gnus-article-mime-handle-alist))
4392       (error "No such part"))
4393     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4394       (when (gnus-article-goto-part n)
4395         (if (equal (car handle) "multipart/alternative")
4396             (gnus-article-press-button)
4397           (when (eq (gnus-mm-display-part handle) 'internal)
4398             (gnus-set-window-start)))))))
4399
4400 (defsubst gnus-article-mime-total-parts ()
4401   (if (bufferp (car gnus-article-mime-handles))
4402       1 ;; single part
4403     (1- (length gnus-article-mime-handles))))
4404
4405 (defun gnus-mm-display-part (handle)
4406   "Display HANDLE and fix MIME button."
4407   (let ((id (get-text-property (point) 'gnus-part))
4408         (point (point))
4409         buffer-read-only)
4410     (forward-line 1)
4411     (prog1
4412         (let ((window (selected-window))
4413               (mail-parse-charset gnus-newsgroup-charset)
4414               (mail-parse-ignored-charsets
4415                (if (gnus-buffer-live-p gnus-summary-buffer)
4416                    (with-current-buffer gnus-summary-buffer
4417                      gnus-newsgroup-ignored-charsets)
4418                  nil)))
4419           (save-excursion
4420             (unwind-protect
4421                 (let ((win (gnus-get-buffer-window (current-buffer) t))
4422                       (beg (point)))
4423                   (when win
4424                     (select-window win))
4425                   (goto-char point)
4426                   (forward-line)
4427                   (if (mm-handle-displayed-p handle)
4428                       ;; This will remove the part.
4429                       (mm-display-part handle)
4430                     (save-restriction
4431                       (narrow-to-region (point)
4432                                         (if (eobp) (point) (1+ (point))))
4433                       (mm-display-part handle)
4434                       ;; We narrow to the part itself and
4435                       ;; then call the treatment functions.
4436                       (goto-char (point-min))
4437                       (forward-line 1)
4438                       (narrow-to-region (point) (point-max))
4439                       (gnus-treat-article
4440                        nil id
4441                        (gnus-article-mime-total-parts)
4442                        (mm-handle-media-type handle)))))
4443               (if (window-live-p window)
4444                   (select-window window)))))
4445       (goto-char point)
4446       (gnus-delete-line)
4447       (gnus-insert-mime-button
4448        handle id (list (mm-handle-displayed-p handle)))
4449       (goto-char point))))
4450
4451 (defun gnus-article-goto-part (n)
4452   "Go to MIME part N."
4453   (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4454
4455 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4456   (let ((gnus-tmp-name
4457          (or (mail-content-type-get (mm-handle-type handle) 'name)
4458              (mail-content-type-get (mm-handle-disposition handle) 'filename)
4459              (mail-content-type-get (mm-handle-type handle) 'url)
4460              ""))
4461         (gnus-tmp-type (mm-handle-media-type handle))
4462         (gnus-tmp-description
4463          (mail-decode-encoded-word-string (or (mm-handle-description handle)
4464                                               "")))
4465         (gnus-tmp-dots
4466          (if (if displayed (car displayed)
4467                (mm-handle-displayed-p handle))
4468              "" "..."))
4469         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4470                            (buffer-size)))
4471         gnus-tmp-type-long b e)
4472     (when (string-match ".*/" gnus-tmp-name)
4473       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4474     (setq gnus-tmp-type-long (concat gnus-tmp-type
4475                                      (and (not (equal gnus-tmp-name ""))
4476                                           (concat "; " gnus-tmp-name))))
4477     (unless (equal gnus-tmp-description "")
4478       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4479     (unless (bolp)
4480       (insert "\n"))
4481     (setq b (point))
4482     (gnus-eval-format
4483      gnus-mime-button-line-format gnus-mime-button-line-format-alist
4484      `(keymap ,gnus-mime-button-map
4485               gnus-callback gnus-mm-display-part
4486               gnus-part ,gnus-tmp-id
4487               article-type annotation
4488               gnus-data ,handle))
4489     (setq e (if (bolp)
4490                 ;; Exclude a newline.
4491                 (1- (point))
4492               (point)))
4493     (widget-convert-button
4494      'link b e
4495      :mime-handle handle
4496      :action 'gnus-widget-press-button
4497      :button-keymap gnus-mime-button-map
4498      :help-echo
4499      (lambda (widget/window &optional overlay pos)
4500        ;; Needed to properly clear the message due to a bug in
4501        ;; wid-edit (XEmacs only).
4502        (if (boundp 'help-echo-owns-message)
4503            (setq help-echo-owns-message t))
4504        (format
4505         "%S: %s the MIME part; %S: more options"
4506         (aref gnus-mouse-2 0)
4507         ;; XEmacs will get a single widget arg; Emacs 21 will get
4508         ;; window, overlay, position.
4509         (if (mm-handle-displayed-p
4510              (if overlay
4511                  (with-current-buffer (gnus-overlay-buffer overlay)
4512                    (widget-get (widget-at (gnus-overlay-start overlay))
4513                                :mime-handle))
4514                (widget-get widget/window :mime-handle)))
4515             "hide" "show")
4516         (aref gnus-down-mouse-3 0))))))
4517
4518 (defun gnus-widget-press-button (elems el)
4519   (goto-char (widget-get elems :from))
4520   (gnus-article-press-button))
4521
4522 (defvar gnus-displaying-mime nil)
4523
4524 (defun gnus-display-mime (&optional ihandles)
4525   "Display the MIME parts."
4526   (save-excursion
4527     (save-selected-window
4528       (let ((window (get-buffer-window gnus-article-buffer))
4529             (point (point)))
4530         (when window
4531           (select-window window)
4532           ;; We have to do this since selecting the window
4533           ;; may change the point.  So we set the window point.
4534           (set-window-point window point)))
4535       (let* ((handles (or ihandles
4536                           (mm-dissect-buffer nil gnus-article-loose-mime)
4537                           (and gnus-article-emulate-mime
4538                                (mm-uu-dissect))))
4539              buffer-read-only handle name type b e display)
4540         (when (and (not ihandles)
4541                    (not gnus-displaying-mime))
4542           ;; Top-level call; we clean up.
4543           (when gnus-article-mime-handles
4544             (mm-destroy-parts gnus-article-mime-handles)
4545             (setq gnus-article-mime-handle-alist nil));; A trick.
4546           (setq gnus-article-mime-handles handles)
4547           ;; We allow users to glean info from the handles.
4548           (when gnus-article-mime-part-function
4549             (gnus-mime-part-function handles)))
4550         (if (and handles
4551                  (or (not (stringp (car handles)))
4552                      (cdr handles)))
4553             (progn
4554               (when (and (not ihandles)
4555                          (not gnus-displaying-mime))
4556                 ;; Clean up for mime parts.
4557                 (article-goto-body)
4558                 (delete-region (point) (point-max)))
4559               (let ((gnus-displaying-mime t))
4560                 (gnus-mime-display-part handles)))
4561           (save-restriction
4562             (article-goto-body)
4563             (narrow-to-region (point) (point-max))
4564             (gnus-treat-article nil 1 1)
4565             (widen)))
4566         (unless ihandles
4567           ;; Highlight the headers.
4568           (save-excursion
4569             (save-restriction
4570               (article-goto-body)
4571               (narrow-to-region (point-min) (point))
4572               (gnus-treat-article 'head))))))))
4573
4574 (defcustom gnus-mime-display-multipart-as-mixed nil
4575   "Display \"multipart\" parts as  \"multipart/mixed\".
4576
4577 If t, it overrides nil values of
4578 `gnus-mime-display-multipart-alternative-as-mixed' and
4579 `gnus-mime-display-multipart-related-as-mixed'."
4580   :group 'gnus-article-mime
4581   :type 'boolean)
4582
4583 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4584   "Display \"multipart/alternative\" parts as  \"multipart/mixed\"."
4585   :group 'gnus-article-mime
4586   :type 'boolean)
4587
4588 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4589   "Display \"multipart/related\" parts as  \"multipart/mixed\".
4590
4591 If displaying \"text/html\" is discouraged \(see
4592 `mm-discouraged-alternatives'\) images or other material inside a
4593 \"multipart/related\" part might be overlooked when this variable is nil."
4594   :group 'gnus-article-mime
4595   :type 'boolean)
4596
4597 (defun gnus-mime-display-part (handle)
4598   (cond
4599    ;; Single part.
4600    ((not (stringp (car handle)))
4601     (gnus-mime-display-single handle))
4602    ;; User-defined multipart
4603    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4604     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4605              handle))
4606    ;; multipart/alternative
4607    ((and (equal (car handle) "multipart/alternative")
4608          (not (or gnus-mime-display-multipart-as-mixed
4609                   gnus-mime-display-multipart-alternative-as-mixed)))
4610     (let ((id (1+ (length gnus-article-mime-handle-alist))))
4611       (push (cons id handle) gnus-article-mime-handle-alist)
4612       (gnus-mime-display-alternative (cdr handle) nil nil id)))
4613    ;; multipart/related
4614    ((and (equal (car handle) "multipart/related")
4615          (not (or gnus-mime-display-multipart-as-mixed
4616                   gnus-mime-display-multipart-related-as-mixed)))
4617     ;;;!!!We should find the start part, but we just default
4618     ;;;!!!to the first part.
4619     ;;(gnus-mime-display-part (cadr handle))
4620     ;;;!!! Most multipart/related is an HTML message plus images.
4621     ;;;!!! Unfortunately we are unable to let W3 display those
4622     ;;;!!! included images, so we just display it as a mixed multipart.
4623     ;;(gnus-mime-display-mixed (cdr handle))
4624     ;;;!!! No, w3 can display everything just fine.
4625     (gnus-mime-display-part (cadr handle)))
4626    ((equal (car handle) "multipart/signed")
4627     (gnus-add-wash-type 'signed)
4628     (gnus-mime-display-security handle))
4629    ((equal (car handle) "multipart/encrypted")
4630     (gnus-add-wash-type 'encrypted)
4631     (gnus-mime-display-security handle))
4632    ;; Other multiparts are handled like multipart/mixed.
4633    (t
4634     (gnus-mime-display-mixed (cdr handle)))))
4635
4636 (defun gnus-mime-part-function (handles)
4637   (if (stringp (car handles))
4638       (mapcar 'gnus-mime-part-function (cdr handles))
4639     (funcall gnus-article-mime-part-function handles)))
4640
4641 (defun gnus-mime-display-mixed (handles)
4642   (mapcar 'gnus-mime-display-part handles))
4643
4644 (defun gnus-mime-display-single (handle)
4645   (let ((type (mm-handle-media-type handle))
4646         (ignored gnus-ignored-mime-types)
4647         (not-attachment t)
4648         (move nil)
4649         display text)
4650     (catch 'ignored
4651       (progn
4652         (while ignored
4653           (when (string-match (pop ignored) type)
4654             (throw 'ignored nil)))
4655         (if (and (setq not-attachment
4656                        (and (not (mm-inline-override-p handle))
4657                             (or (not (mm-handle-disposition handle))
4658                                 (equal (car (mm-handle-disposition handle))
4659                                        "inline")
4660                                 (mm-attachment-override-p handle))))
4661                  (mm-automatic-display-p handle)
4662                  (or (and
4663                       (mm-inlinable-p handle)
4664                       (mm-inlined-p handle))
4665                      (mm-automatic-external-display-p type)))
4666             (setq display t)
4667           (when (equal (mm-handle-media-supertype handle) "text")
4668             (setq text t)))
4669         (let ((id (1+ (length gnus-article-mime-handle-alist)))
4670               beg)
4671           (push (cons id handle) gnus-article-mime-handle-alist)
4672           (when (or (not display)
4673                     (not (gnus-unbuttonized-mime-type-p type)))
4674             (gnus-insert-mime-button
4675              handle id (list (or display (and not-attachment text))))
4676             (gnus-article-insert-newline)
4677             ;; Remember modify the number of forward lines.
4678             (setq move t))
4679           (setq beg (point))
4680           (cond
4681            (display
4682             (when move
4683               (forward-line -1)
4684               (setq beg (point)))
4685             (let ((mail-parse-charset gnus-newsgroup-charset)
4686                   (mail-parse-ignored-charsets
4687                    (save-excursion (condition-case ()
4688                                        (set-buffer gnus-summary-buffer)
4689                                      (error))
4690                                    gnus-newsgroup-ignored-charsets)))
4691               (mm-display-part handle t))
4692             (goto-char (point-max)))
4693            ((and text not-attachment)
4694             (when move
4695               (forward-line -1)
4696               (setq beg (point)))
4697             (gnus-article-insert-newline)
4698             (mm-insert-inline handle (mm-get-part handle))
4699             (goto-char (point-max))))
4700           ;; Do highlighting.
4701           (save-excursion
4702             (save-restriction
4703               (narrow-to-region beg (point))
4704               (gnus-treat-article
4705                nil id
4706                (gnus-article-mime-total-parts)
4707                (mm-handle-media-type handle)))))))))
4708
4709 (defun gnus-unbuttonized-mime-type-p (type)
4710   "Say whether TYPE is to be unbuttonized."
4711   (unless gnus-inhibit-mime-unbuttonizing
4712     (when (catch 'found
4713             (let ((types gnus-unbuttonized-mime-types))
4714               (while types
4715                 (when (string-match (pop types) type)
4716                   (throw 'found t)))))
4717       (not (catch 'found
4718              (let ((types gnus-buttonized-mime-types))
4719                (while types
4720                  (when (string-match (pop types) type)
4721                    (throw 'found t)))))))))
4722
4723 (defun gnus-article-insert-newline ()
4724   "Insert a newline, but mark it as undeletable."
4725   (gnus-put-text-property
4726    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4727
4728 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4729   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4730          (ihandles handles)
4731          (point (point))
4732          handle buffer-read-only from props begend not-pref)
4733     (save-window-excursion
4734       (save-restriction
4735         (when ibegend
4736           (narrow-to-region (car ibegend)
4737                             (or (cdr ibegend)
4738                                 (progn
4739                                   (goto-char (car ibegend))
4740                                   (forward-line 2)
4741                                   (point))))
4742           (delete-region (point-min) (point-max))
4743           (mm-remove-parts handles))
4744         (setq begend (list (point-marker)))
4745         ;; Do the toggle.
4746         (unless (setq not-pref (cadr (member preferred ihandles)))
4747           (setq not-pref (car ihandles)))
4748         (when (or ibegend
4749                   (not preferred)
4750                   (not (gnus-unbuttonized-mime-type-p
4751                         "multipart/alternative")))
4752           (gnus-add-text-properties
4753            (setq from (point))
4754            (progn
4755              (insert (format "%d.  " id))
4756              (point))
4757            `(gnus-callback
4758              (lambda (handles)
4759                (unless ,(not ibegend)
4760                  (setq gnus-article-mime-handle-alist
4761                        ',gnus-article-mime-handle-alist))
4762                (gnus-mime-display-alternative
4763                 ',ihandles ',not-pref ',begend ,id))
4764              keymap ,gnus-mime-button-map
4765              ,gnus-mouse-face-prop ,gnus-article-mouse-face
4766              face ,gnus-article-button-face
4767              gnus-part ,id
4768              gnus-data ,handle))
4769           (widget-convert-button 'link from (point)
4770                                  :action 'gnus-widget-press-button
4771                                  :button-keymap gnus-widget-button-keymap)
4772           ;; Do the handles
4773           (while (setq handle (pop handles))
4774             (gnus-add-text-properties
4775              (setq from (point))
4776              (progn
4777                (insert (format "(%c) %-18s"
4778                                (if (equal handle preferred) ?* ? )
4779                                (mm-handle-media-type handle)))
4780                (point))
4781              `(gnus-callback
4782                (lambda (handles)
4783                  (unless ,(not ibegend)
4784                    (setq gnus-article-mime-handle-alist
4785                          ',gnus-article-mime-handle-alist))
4786                  (gnus-mime-display-alternative
4787                   ',ihandles ',handle ',begend ,id))
4788                keymap ,gnus-mime-button-map
4789                ,gnus-mouse-face-prop ,gnus-article-mouse-face
4790                face ,gnus-article-button-face
4791                gnus-part ,id
4792                gnus-data ,handle))
4793             (widget-convert-button 'link from (point)
4794                                    :action 'gnus-widget-press-button
4795                                    :button-keymap gnus-widget-button-keymap)
4796             (insert "  "))
4797           (insert "\n\n"))
4798         (when preferred
4799           (if (stringp (car preferred))
4800               (gnus-display-mime preferred)
4801             (let ((mail-parse-charset gnus-newsgroup-charset)
4802                   (mail-parse-ignored-charsets
4803                    (with-current-buffer gnus-summary-buffer
4804                      gnus-newsgroup-ignored-charsets)))
4805               (mm-display-part preferred)
4806               ;; Do highlighting.
4807               (save-excursion
4808                 (save-restriction
4809                   (narrow-to-region (car begend) (point-max))
4810                   (gnus-treat-article
4811                    nil (length gnus-article-mime-handle-alist)
4812                    (gnus-article-mime-total-parts)
4813                    (mm-handle-media-type handle))))))
4814           (goto-char (point-max))
4815           (setcdr begend (point-marker)))))
4816     (when ibegend
4817       (goto-char point))))
4818
4819 (defconst gnus-article-wash-status-strings
4820   (let ((alist '((cite "c" "Possible hidden citation text"
4821                        " " "All citation text visible")
4822                  (headers "h" "Hidden headers"
4823                           " " "All headers visible.")
4824                  (pgp "p" "Encrypted or signed message status hidden"
4825                       " " "No hidden encryption nor digital signature status")
4826                  (signature "s" "Signature has been hidden"
4827                             " " "Signature is visible")
4828                  (overstrike "o" "Overstrike (^H) characters applied"
4829                              " " "No overstrike characters applied")
4830                  (emphasis "e" "/*_Emphasis_*/ characters applied"
4831                            " " "No /*_emphasis_*/ characters applied")))
4832         result)
4833     (dolist (entry alist result)
4834       (let ((key (nth 0 entry))
4835             (on (copy-sequence (nth 1 entry)))
4836             (on-help (nth 2 entry))
4837             (off (copy-sequence (nth 3 entry)))
4838             (off-help (nth 4 entry)))
4839         (put-text-property 0 1 'help-echo on-help on)
4840         (put-text-property 0 1 'help-echo off-help off)
4841         (push (list key on off) result))))
4842   "Alist of strings describing wash status in the mode line.
4843 Each entry has the form (KEY ON OF), where the KEY is a symbol
4844 representing the particular washing function, ON is the string to use
4845 in the article mode line when the washing function is active, and OFF
4846 is the string to use when it is inactive.")
4847
4848 (defun gnus-article-wash-status-entry (key value)
4849   (let ((entry (assoc key gnus-article-wash-status-strings)))
4850     (if value (nth 1 entry) (nth 2 entry))))
4851
4852 (defun gnus-article-wash-status ()
4853   "Return a string which display status of article washing."
4854   (with-current-buffer gnus-article-buffer
4855     (let ((cite (memq 'cite gnus-article-wash-types))
4856           (headers (memq 'headers gnus-article-wash-types))
4857           (boring (memq 'boring-headers gnus-article-wash-types))
4858           (pgp (memq 'pgp gnus-article-wash-types))
4859           (pem (memq 'pem gnus-article-wash-types))
4860           (signed (memq 'signed gnus-article-wash-types))
4861           (encrypted (memq 'encrypted gnus-article-wash-types))
4862           (signature (memq 'signature gnus-article-wash-types))
4863           (overstrike (memq 'overstrike gnus-article-wash-types))
4864           (emphasis (memq 'emphasis gnus-article-wash-types)))
4865       (concat
4866        (gnus-article-wash-status-entry 'cite cite)
4867        (gnus-article-wash-status-entry 'headers (or headers boring))
4868        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4869        (gnus-article-wash-status-entry 'signature signature)
4870        (gnus-article-wash-status-entry 'overstrike overstrike)
4871        (gnus-article-wash-status-entry 'emphasis emphasis)))))
4872
4873 (defun gnus-add-wash-type (type)
4874   "Add a washing of TYPE to the current status."
4875   (add-to-list 'gnus-article-wash-types type))
4876
4877 (defun gnus-delete-wash-type (type)
4878   "Add a washing of TYPE to the current status."
4879   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4880
4881 (defun gnus-add-image (category image)
4882   "Add IMAGE of CATEGORY to the list of displayed images."
4883   (let ((entry (assq category gnus-article-image-alist)))
4884     (unless entry
4885       (setq entry (list category))
4886       (push entry gnus-article-image-alist))
4887     (nconc entry (list image))))
4888
4889 (defun gnus-delete-images (category)
4890   "Delete all images in CATEGORY."
4891   (let ((entry (assq category gnus-article-image-alist)))
4892     (dolist (image (cdr entry))
4893       (gnus-remove-image image category))
4894     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4895     (gnus-delete-wash-type category)))
4896
4897 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4898
4899 (defun gnus-article-maybe-hide-headers ()
4900   "Hide unwanted headers if `gnus-have-all-headers' is nil.
4901 Provided for backwards compatibility."
4902   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4903                  (not (with-current-buffer gnus-summary-buffer
4904                         gnus-have-all-headers)))
4905              (not gnus-inhibit-hiding))
4906     (gnus-article-hide-headers)))
4907
4908 ;;; Article savers.
4909
4910 (defun gnus-output-to-file (file-name)
4911   "Append the current article to a file named FILE-NAME."
4912   (let ((artbuf (current-buffer)))
4913     (with-temp-buffer
4914       (insert-buffer-substring artbuf)
4915       ;; Append newline at end of the buffer as separator, and then
4916       ;; save it to file.
4917       (goto-char (point-max))
4918       (insert "\n")
4919       (let ((file-name-coding-system nnmail-pathname-coding-system))
4920         (mm-append-to-file (point-min) (point-max) file-name))
4921       t)))
4922
4923 (defun gnus-narrow-to-page (&optional arg)
4924   "Narrow the article buffer to a page.
4925 If given a numerical ARG, move forward ARG pages."
4926   (interactive "P")
4927   (setq arg (if arg (prefix-numeric-value arg) 0))
4928   (save-excursion
4929     (set-buffer gnus-article-buffer)
4930     (goto-char (point-min))
4931     (widen)
4932     ;; Remove any old next/prev buttons.
4933     (when (gnus-visual-p 'page-marker)
4934       (let ((buffer-read-only nil))
4935         (gnus-remove-text-with-property 'gnus-prev)
4936         (gnus-remove-text-with-property 'gnus-next)))
4937     (if
4938         (cond ((< arg 0)
4939                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4940               ((> arg 0)
4941                (re-search-forward page-delimiter nil 'move arg)))
4942         (goto-char (match-end 0))
4943       (save-excursion
4944         (goto-char (point-min))
4945         (setq gnus-page-broken
4946               (and (re-search-forward page-delimiter nil t) t))))
4947     (when gnus-page-broken
4948       (narrow-to-region
4949        (point)
4950        (if (re-search-forward page-delimiter nil 'move)
4951            (match-beginning 0)
4952          (point)))
4953       (when (and (gnus-visual-p 'page-marker)
4954                  (not (= (point-min) 1)))
4955         (save-excursion
4956           (goto-char (point-min))
4957           (gnus-insert-prev-page-button)))
4958       (when (and (gnus-visual-p 'page-marker)
4959                  (< (+ (point-max) 2) (buffer-size)))
4960         (save-excursion
4961           (goto-char (point-max))
4962           (gnus-insert-next-page-button))))))
4963
4964 ;; Article mode commands
4965
4966 (defun gnus-article-goto-next-page ()
4967   "Show the next page of the article."
4968   (interactive)
4969   (when (gnus-article-next-page)
4970     (goto-char (point-min))
4971     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4972
4973
4974 (defun gnus-article-goto-prev-page ()
4975   "Show the previous page of the article."
4976   (interactive)
4977   (if (bobp)
4978       (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4979     (gnus-article-prev-page nil)))
4980
4981 ;; This is cleaner but currently breaks `gnus-pick-mode':
4982 ;;
4983 ;; (defun gnus-article-goto-next-page ()
4984 ;;   "Show the next page of the article."
4985 ;;   (interactive)
4986 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
4987 ;;     (gnus-summary-next-page)))
4988 ;;
4989 ;; (defun gnus-article-goto-prev-page ()
4990 ;;   "Show the next page of the article."
4991 ;;   (interactive)
4992 ;;   (gnus-eval-in-buffer-window gnus-summary-buffer
4993 ;;     (gnus-summary-prev-page)))
4994
4995 (defun gnus-article-next-page (&optional lines)
4996   "Show the next page of the current article.
4997 If end of article, return non-nil.  Otherwise return nil.
4998 Argument LINES specifies lines to be scrolled up."
4999   (interactive "p")
5000   (move-to-window-line -1)
5001   (if (save-excursion
5002         (end-of-line)
5003         (and (pos-visible-in-window-p)  ;Not continuation line.
5004              (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5005       ;; Nothing in this page.
5006       (if (or (not gnus-page-broken)
5007               (save-excursion
5008                 (save-restriction
5009                   (widen)
5010                   (eobp)))) ;Real end-of-buffer?
5011           (progn
5012             (when gnus-article-over-scroll
5013               (gnus-article-next-page-1 lines))
5014             t)                  ;Nothing more.
5015         (gnus-narrow-to-page 1)         ;Go to next page.
5016         nil)
5017     ;; More in this page.
5018     (gnus-article-next-page-1 lines)
5019     nil))
5020
5021 (defun gnus-article-next-page-1 (lines)
5022   (let ((scroll-in-place nil))
5023     (condition-case ()
5024         (scroll-up lines)
5025       (end-of-buffer
5026        ;; Long lines may cause an end-of-buffer error.
5027        (goto-char (point-max)))))
5028   (move-to-window-line 0))
5029
5030 (defun gnus-article-prev-page (&optional lines)
5031   "Show previous page of current article.
5032 Argument LINES specifies lines to be scrolled down."
5033   (interactive "p")
5034   (move-to-window-line 0)
5035   (if (and gnus-page-broken
5036            (bobp)
5037            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5038       (progn
5039         (gnus-narrow-to-page -1)        ;Go to previous page.
5040         (goto-char (point-max))
5041         (recenter -1))
5042     (let ((scroll-in-place nil))
5043       (prog1
5044           (condition-case ()
5045               (scroll-down lines)
5046             (beginning-of-buffer
5047              (goto-char (point-min))))
5048         (move-to-window-line 0)))))
5049
5050 (defun gnus-article-only-boring-p ()
5051   "Decide whether there is only boring text remaining in the article.
5052 Something \"interesting\" is a word of at least two letters that does
5053 not have a face in `gnus-article-boring-faces'."
5054   (when (and gnus-article-skip-boring
5055              (boundp 'gnus-article-boring-faces)
5056              (symbol-value 'gnus-article-boring-faces))
5057     (save-excursion
5058       (catch 'only-boring
5059         (while (re-search-forward "\\b\\w\\w" nil t)
5060           (forward-char -1)
5061           (when (not (gnus-intersection
5062                       (gnus-faces-at (point))
5063                       (symbol-value 'gnus-article-boring-faces)))
5064             (throw 'only-boring nil)))
5065         (throw 'only-boring t)))))
5066
5067 (defun gnus-article-refer-article ()
5068   "Read article specified by message-id around point."
5069   (interactive)
5070   (save-excursion
5071     (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5072     (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5073     (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5074         (let ((msg-id (concat "<" (match-string 0) ">")))
5075           (set-buffer gnus-summary-buffer)
5076           (gnus-summary-refer-article msg-id))
5077       (error "No references around point"))))
5078
5079 (defun gnus-article-show-summary ()
5080   "Reconfigure windows to show summary buffer."
5081   (interactive)
5082   (if (not (gnus-buffer-live-p gnus-summary-buffer))
5083       (error "There is no summary buffer for this article buffer")
5084     (gnus-article-set-globals)
5085     (gnus-configure-windows 'article)
5086     (gnus-summary-goto-subject gnus-current-article)
5087     (gnus-summary-position-point)))
5088
5089 (defun gnus-article-describe-briefly ()
5090   "Describe article mode commands briefly."
5091   (interactive)
5092   (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")))
5093
5094 (defun gnus-article-summary-command ()
5095   "Execute the last keystroke in the summary buffer."
5096   (interactive)
5097   (let ((obuf (current-buffer))
5098         (owin (current-window-configuration))
5099         func)
5100     (switch-to-buffer gnus-article-current-summary 'norecord)
5101     (setq func (lookup-key (current-local-map) (this-command-keys)))
5102     (call-interactively func)
5103     (set-buffer obuf)
5104     (set-window-configuration owin)
5105     (set-window-point (get-buffer-window (current-buffer)) (point))))
5106
5107 (defun gnus-article-summary-command-nosave ()
5108   "Execute the last keystroke in the summary buffer."
5109   (interactive)
5110   (let (func)
5111     (pop-to-buffer gnus-article-current-summary 'norecord)
5112     (setq func (lookup-key (current-local-map) (this-command-keys)))
5113     (call-interactively func)))
5114
5115 (defun gnus-article-check-buffer ()
5116   "Beep if not in an article buffer."
5117   (unless (equal major-mode 'gnus-article-mode)
5118     (error "Command invoked outside of a Gnus article buffer")))
5119
5120 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5121   "Read a summary buffer key sequence and execute it from the article buffer."
5122   (interactive "P")
5123   (gnus-article-check-buffer)
5124   (let ((nosaves
5125          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
5126            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5127            "=" "^" "\M-^" "|"))
5128         (nosave-but-article
5129          '("A\r"))
5130         (nosave-in-article
5131          '("\C-d"))
5132         (up-to-top
5133          '("n" "Gn" "p" "Gp"))
5134         keys new-sum-point)
5135     (save-excursion
5136       (set-buffer gnus-article-current-summary)
5137       (let (gnus-pick-mode)
5138         (push (or key last-command-event) unread-command-events)
5139         (setq keys (if (featurep 'xemacs)
5140                        (events-to-keys (read-key-sequence nil))
5141                      (read-key-sequence nil)))))
5142
5143     (message "")
5144
5145     (if (or (member keys nosaves)
5146             (member keys nosave-but-article)
5147             (member keys nosave-in-article))
5148         (let (func)
5149           (save-window-excursion
5150             (pop-to-buffer gnus-article-current-summary 'norecord)
5151             ;; We disable the pick minor mode commands.
5152             (let (gnus-pick-mode)
5153               (setq func (lookup-key (current-local-map) keys))))
5154           (if (or (not func)
5155                   (numberp func))
5156               (ding)
5157             (unless (member keys nosave-in-article)
5158               (set-buffer gnus-article-current-summary))
5159             (call-interactively func)
5160             (setq new-sum-point (point)))
5161           (when (member keys nosave-but-article)
5162             (pop-to-buffer gnus-article-buffer 'norecord)))
5163       ;; These commands should restore window configuration.
5164       (let ((obuf (current-buffer))
5165             (owin (current-window-configuration))
5166             (opoint (point))
5167             win func in-buffer selected new-sum-start new-sum-hscroll)
5168         (cond (not-restore-window
5169                (pop-to-buffer gnus-article-current-summary 'norecord))
5170               ((setq win (get-buffer-window gnus-article-current-summary))
5171                (select-window win))
5172               (t
5173                (switch-to-buffer gnus-article-current-summary 'norecord)))
5174         (setq in-buffer (current-buffer))
5175         ;; We disable the pick minor mode commands.
5176         (if (and (setq func (let (gnus-pick-mode)
5177                               (lookup-key (current-local-map) keys)))
5178                  (functionp func))
5179             (progn
5180               (call-interactively func)
5181               (when (eq win (selected-window))
5182                 (setq new-sum-point (point)
5183                       new-sum-start (window-start win)
5184                       new-sum-hscroll (window-hscroll win))
5185               (when (eq in-buffer (current-buffer))
5186                 (setq selected (gnus-summary-select-article))
5187                 (set-buffer obuf)
5188                 (unless not-restore-window
5189                   (set-window-configuration owin))
5190                 (when (eq selected 'old)
5191                   (article-goto-body)
5192                   (set-window-start (get-buffer-window (current-buffer))
5193                                     1)
5194                   (set-window-point (get-buffer-window (current-buffer))
5195                                     (point)))
5196                 (when (and (not not-restore-window)
5197                            new-sum-point)
5198                   (set-window-point win new-sum-point)
5199                   (set-window-start win new-sum-start)
5200                   (set-window-hscroll win new-sum-hscroll)))))
5201           (set-window-configuration owin)
5202           (ding))))))
5203
5204 (defun gnus-article-describe-key (key)
5205   "Display documentation of the function invoked by KEY.  KEY is a string."
5206   (interactive "kDescribe key: ")
5207   (gnus-article-check-buffer)
5208   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5209       (save-excursion
5210         (set-buffer gnus-article-current-summary)
5211         (let (gnus-pick-mode)
5212           (if (featurep 'xemacs)
5213               (progn
5214                 (push (elt key 0) unread-command-events)
5215                 (setq key (events-to-keys
5216                            (read-key-sequence "Describe key: "))))
5217             (setq unread-command-events
5218                   (mapcar
5219                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5220                    (string-to-list key)))
5221             (setq key (read-key-sequence "Describe key: "))))
5222         (describe-key key))
5223     (describe-key key)))
5224
5225 (defun gnus-article-describe-key-briefly (key &optional insert)
5226   "Display documentation of the function invoked by KEY.  KEY is a string."
5227   (interactive "kDescribe key: \nP")
5228   (gnus-article-check-buffer)
5229   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5230       (save-excursion
5231         (set-buffer gnus-article-current-summary)
5232         (let (gnus-pick-mode)
5233           (if (featurep 'xemacs)
5234               (progn
5235                 (push (elt key 0) unread-command-events)
5236                 (setq key (events-to-keys
5237                            (read-key-sequence "Describe key: "))))
5238             (setq unread-command-events
5239                   (mapcar
5240                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5241                    (string-to-list key)))
5242             (setq key (read-key-sequence "Describe key: "))))
5243         (describe-key-briefly key insert))
5244     (describe-key-briefly key insert)))
5245
5246 (defun gnus-article-reply-with-original (&optional wide)
5247   "Start composing a reply mail to the current message.
5248 The text in the region will be yanked.  If the region isn't active,
5249 the entire article will be yanked."
5250   (interactive "P")
5251   (let ((article (cdr gnus-article-current))
5252         contents)
5253     (if (not (gnus-region-active-p))
5254         (with-current-buffer gnus-summary-buffer
5255           (gnus-summary-reply (list (list article)) wide))
5256       (setq contents (buffer-substring (point) (mark t)))
5257       ;; Deactivate active regions.
5258       (when (and (boundp 'transient-mark-mode)
5259                  transient-mark-mode)
5260         (setq mark-active nil))
5261       (with-current-buffer gnus-summary-buffer
5262         (gnus-summary-reply
5263          (list (list article contents)) wide)))))
5264
5265 (defun gnus-article-followup-with-original ()
5266   "Compose a followup to the current article.
5267 The text in the region will be yanked.  If the region isn't active,
5268 the entire article will be yanked."
5269   (interactive)
5270   (let ((article (cdr gnus-article-current))
5271         contents)
5272       (if (not (gnus-region-active-p))
5273           (with-current-buffer gnus-summary-buffer
5274             (gnus-summary-followup (list (list article))))
5275         (setq contents (buffer-substring (point) (mark t)))
5276         ;; Deactivate active regions.
5277         (when (and (boundp 'transient-mark-mode)
5278                    transient-mark-mode)
5279           (setq mark-active nil))
5280         (with-current-buffer gnus-summary-buffer
5281           (gnus-summary-followup
5282            (list (list article contents)))))))
5283
5284 (defun gnus-article-hide (&optional arg force)
5285   "Hide all the gruft in the current article.
5286 This means that signatures, cited text and (some) headers will be
5287 hidden.
5288 If given a prefix, show the hidden text instead."
5289   (interactive (append (gnus-article-hidden-arg) (list 'force)))
5290   (gnus-article-hide-headers arg)
5291   (gnus-article-hide-list-identifiers arg)
5292   (gnus-article-hide-citation-maybe arg force)
5293   (gnus-article-hide-signature arg))
5294
5295 (defun gnus-article-maybe-highlight ()
5296   "Do some article highlighting if article highlighting is requested."
5297   (when (gnus-visual-p 'article-highlight 'highlight)
5298     (gnus-article-highlight-some)))
5299
5300 (defun gnus-check-group-server ()
5301   ;; Make sure the connection to the server is alive.
5302   (unless (gnus-server-opened
5303            (gnus-find-method-for-group gnus-newsgroup-name))
5304     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5305     (gnus-request-group gnus-newsgroup-name t)))
5306
5307 (eval-when-compile
5308   (autoload 'nneething-get-file-name "nneething"))
5309
5310 (defun gnus-request-article-this-buffer (article group)
5311   "Get an article and insert it into this buffer."
5312   (let (do-update-line sparse-header)
5313     (prog1
5314         (save-excursion
5315           (erase-buffer)
5316           (gnus-kill-all-overlays)
5317           (setq group (or group gnus-newsgroup-name))
5318
5319           ;; Using `gnus-request-article' directly will insert the article into
5320           ;; `nntp-server-buffer' - so we'll save some time by not having to
5321           ;; copy it from the server buffer into the article buffer.
5322
5323           ;; We only request an article by message-id when we do not have the
5324           ;; headers for it, so we'll have to get those.
5325           (when (stringp article)
5326             (gnus-read-header article))
5327
5328           ;; If the article number is negative, that means that this article
5329           ;; doesn't belong in this newsgroup (possibly), so we find its
5330           ;; message-id and request it by id instead of number.
5331           (when (and (numberp article)
5332                      gnus-summary-buffer
5333                      (get-buffer gnus-summary-buffer)
5334                      (gnus-buffer-exists-p gnus-summary-buffer))
5335             (save-excursion
5336               (set-buffer gnus-summary-buffer)
5337               (let ((header (gnus-summary-article-header article)))
5338                 (when (< article 0)
5339                   (cond
5340                    ((memq article gnus-newsgroup-sparse)
5341                     ;; This is a sparse gap article.
5342                     (setq do-update-line article)
5343                     (setq article (mail-header-id header))
5344                     (setq sparse-header (gnus-read-header article))
5345                     (setq gnus-newsgroup-sparse
5346                           (delq article gnus-newsgroup-sparse)))
5347                    ((vectorp header)
5348                     ;; It's a real article.
5349                     (setq article (mail-header-id header)))
5350                    (t
5351                     ;; It is an extracted pseudo-article.
5352                     (setq article 'pseudo)
5353                     (gnus-request-pseudo-article header))))
5354
5355                 (let ((method (gnus-find-method-for-group
5356                                gnus-newsgroup-name)))
5357                   (when (and (eq (car method) 'nneething)
5358                              (vectorp header))
5359                     (let ((dir (nneething-get-file-name
5360                                 (mail-header-id header))))
5361                       (when (and (stringp dir)
5362                                  (file-directory-p dir))
5363                         (setq article 'nneething)
5364                         (gnus-group-enter-directory dir))))))))
5365
5366           (cond
5367            ;; Refuse to select canceled articles.
5368            ((and (numberp article)
5369                  gnus-summary-buffer
5370                  (get-buffer gnus-summary-buffer)
5371                  (gnus-buffer-exists-p gnus-summary-buffer)
5372                  (eq (cdr (with-current-buffer gnus-summary-buffer
5373                             (assq article gnus-newsgroup-reads)))
5374                      gnus-canceled-mark))
5375             nil)
5376            ;; We first check `gnus-original-article-buffer'.
5377            ((and (get-buffer gnus-original-article-buffer)
5378                  (numberp article)
5379                  (with-current-buffer gnus-original-article-buffer
5380                    (and (equal (car gnus-original-article) group)
5381                         (eq (cdr gnus-original-article) article))))
5382             (insert-buffer-substring gnus-original-article-buffer)
5383             'article)
5384            ;; Check the backlog.
5385            ((and gnus-keep-backlog
5386                  (gnus-backlog-request-article group article (current-buffer)))
5387             'article)
5388            ;; Check asynchronous pre-fetch.
5389            ((gnus-async-request-fetched-article group article (current-buffer))
5390             (gnus-async-prefetch-next group article gnus-summary-buffer)
5391             (when (and (numberp article) gnus-keep-backlog)
5392               (gnus-backlog-enter-article group article (current-buffer)))
5393             'article)
5394            ;; Check the cache.
5395            ((and gnus-use-cache
5396                  (numberp article)
5397                  (gnus-cache-request-article article group))
5398             'article)
5399            ;; Check the agent cache.
5400            ((gnus-agent-request-article article group)
5401             'article)
5402            ;; Get the article and put into the article buffer.
5403            ((or (stringp article)
5404                 (numberp article))
5405             (let ((gnus-override-method gnus-override-method)
5406                   (methods (and (stringp article)
5407                                 gnus-refer-article-method))
5408                   (backend (car (gnus-find-method-for-group
5409                                  gnus-newsgroup-name)))
5410                   result
5411                   (buffer-read-only nil))
5412               (if (or (not (listp methods))
5413                       (and (symbolp (car methods))
5414                            (assq (car methods) nnoo-definition-alist)))
5415                   (setq methods (list methods)))
5416               (when (and (null gnus-override-method)
5417                          methods)
5418                 (setq gnus-override-method (pop methods)))
5419               (while (not result)
5420                 (when (eq gnus-override-method 'current)
5421                   (setq gnus-override-method
5422                         (with-current-buffer gnus-summary-buffer
5423                           gnus-current-select-method)))
5424                 (erase-buffer)
5425                 (gnus-kill-all-overlays)
5426                 (let ((gnus-newsgroup-name group))
5427                   (gnus-check-group-server))
5428                 (cond
5429                  ((gnus-request-article article group (current-buffer))
5430                   (when (numberp article)
5431                     (gnus-async-prefetch-next group article
5432                                               gnus-summary-buffer)
5433                     (when gnus-keep-backlog
5434                       (gnus-backlog-enter-article
5435                        group article (current-buffer))))
5436                   (setq result 'article))
5437                  (methods
5438                   (setq gnus-override-method (pop methods)))
5439                  ((not (string-match "^400 "
5440                                      (nnheader-get-report backend)))
5441                   ;; If we get 400 server disconnect, reconnect and
5442                   ;; retry; otherwise, assume the article has expired.
5443                   (setq result 'done))))
5444               (and (eq result 'article) 'article)))
5445            ;; It was a pseudo.
5446            (t article)))
5447
5448       ;; Associate this article with the current summary buffer.
5449       (setq gnus-article-current-summary gnus-summary-buffer)
5450
5451       ;; Take the article from the original article buffer
5452       ;; and place it in the buffer it's supposed to be in.
5453       (when (and (get-buffer gnus-article-buffer)
5454                  (equal (buffer-name (current-buffer))
5455                         (buffer-name (get-buffer gnus-article-buffer))))
5456         (save-excursion
5457           (if (get-buffer gnus-original-article-buffer)
5458               (set-buffer gnus-original-article-buffer)
5459             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5460             (buffer-disable-undo)
5461             (setq major-mode 'gnus-original-article-mode)
5462             (setq buffer-read-only t))
5463           (let (buffer-read-only)
5464             (erase-buffer)
5465             (insert-buffer-substring gnus-article-buffer))
5466           (setq gnus-original-article (cons group article)))
5467
5468         ;; Decode charsets.
5469         (run-hooks 'gnus-article-decode-hook)
5470         ;; Mark article as decoded or not.
5471         (setq gnus-article-decoded-p gnus-article-decode-hook))
5472
5473       ;; Update sparse articles.
5474       (when (and do-update-line
5475                  (or (numberp article)
5476                      (stringp article)))
5477         (let ((buf (current-buffer)))
5478           (set-buffer gnus-summary-buffer)
5479           (gnus-summary-update-article do-update-line sparse-header)
5480           (gnus-summary-goto-subject do-update-line nil t)
5481           (set-window-point (gnus-get-buffer-window (current-buffer) t)
5482                             (point))
5483           (set-buffer buf))))))
5484
5485 ;;;
5486 ;;; Article editing
5487 ;;;
5488
5489 (defcustom gnus-article-edit-mode-hook nil
5490   "Hook run in article edit mode buffers."
5491   :group 'gnus-article-various
5492   :type 'hook)
5493
5494 (defvar gnus-article-edit-done-function nil)
5495
5496 (defvar gnus-article-edit-mode-map nil)
5497
5498 ;; Should we be using derived.el for this?
5499 (unless gnus-article-edit-mode-map
5500   (setq gnus-article-edit-mode-map (make-keymap))
5501   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5502
5503   (gnus-define-keys gnus-article-edit-mode-map
5504     "\C-c?"    describe-mode
5505     "\C-c\C-c" gnus-article-edit-done
5506     "\C-c\C-k" gnus-article-edit-exit
5507     "\C-c\C-f\C-t" message-goto-to
5508     "\C-c\C-f\C-o" message-goto-from
5509     "\C-c\C-f\C-b" message-goto-bcc
5510     ;;"\C-c\C-f\C-w" message-goto-fcc
5511     "\C-c\C-f\C-c" message-goto-cc
5512     "\C-c\C-f\C-s" message-goto-subject
5513     "\C-c\C-f\C-r" message-goto-reply-to
5514     "\C-c\C-f\C-n" message-goto-newsgroups
5515     "\C-c\C-f\C-d" message-goto-distribution
5516     "\C-c\C-f\C-f" message-goto-followup-to
5517     "\C-c\C-f\C-m" message-goto-mail-followup-to
5518     "\C-c\C-f\C-k" message-goto-keywords
5519     "\C-c\C-f\C-u" message-goto-summary
5520     "\C-c\C-f\C-i" message-insert-or-toggle-importance
5521     "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5522     "\C-c\C-b" message-goto-body
5523     "\C-c\C-i" message-goto-signature
5524
5525     "\C-c\C-t" message-insert-to
5526     "\C-c\C-n" message-insert-newsgroups
5527     "\C-c\C-o" message-sort-headers
5528     "\C-c\C-e" message-elide-region
5529     "\C-c\C-v" message-delete-not-region
5530     "\C-c\C-z" message-kill-to-signature
5531     "\M-\r" message-newline-and-reformat
5532     "\C-c\C-a" mml-attach-file
5533     "\C-a" message-beginning-of-line
5534     "\t" message-tab
5535     "\M-;" comment-region)
5536
5537   (gnus-define-keys (gnus-article-edit-wash-map
5538                      "\C-c\C-w" gnus-article-edit-mode-map)
5539     "f" gnus-article-edit-full-stops))
5540
5541 (easy-menu-define
5542   gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5543   '("Field"
5544     ["Fetch To" message-insert-to t]
5545     ["Fetch Newsgroups" message-insert-newsgroups t]
5546     "----"
5547     ["To" message-goto-to t]
5548     ["From" message-goto-from t]
5549     ["Subject" message-goto-subject t]
5550     ["Cc" message-goto-cc t]
5551     ["Reply-To" message-goto-reply-to t]
5552     ["Summary" message-goto-summary t]
5553     ["Keywords" message-goto-keywords t]
5554     ["Newsgroups" message-goto-newsgroups t]
5555     ["Followup-To" message-goto-followup-to t]
5556     ["Mail-Followup-To" message-goto-mail-followup-to t]
5557     ["Distribution" message-goto-distribution t]
5558     ["Body" message-goto-body t]
5559     ["Signature" message-goto-signature t]))
5560
5561 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5562   "Major mode for editing articles.
5563 This is an extended text-mode.
5564
5565 \\{gnus-article-edit-mode-map}"
5566   (make-local-variable 'gnus-article-edit-done-function)
5567   (make-local-variable 'gnus-prev-winconf)
5568   (set (make-local-variable 'font-lock-defaults)
5569        '(message-font-lock-keywords t))
5570   (set (make-local-variable 'mail-header-separator) "")
5571   (set (make-local-variable 'gnus-article-edit-mode) t)
5572   (easy-menu-add message-mode-field-menu message-mode-map)
5573   (mml-mode)
5574   (setq buffer-read-only nil)
5575   (buffer-enable-undo)
5576   (widen))
5577
5578 (defun gnus-article-edit (&optional force)
5579   "Edit the current article.
5580 This will have permanent effect only in mail groups.
5581 If FORCE is non-nil, allow editing of articles even in read-only
5582 groups."
5583   (interactive "P")
5584   (when (and (not force)
5585              (gnus-group-read-only-p))
5586     (error "The current newsgroup does not support article editing"))
5587   (gnus-article-date-original)
5588   (gnus-article-edit-article
5589    'ignore
5590    `(lambda (no-highlight)
5591       'ignore
5592       (gnus-summary-edit-article-done
5593        ,(or (mail-header-references gnus-current-headers) "")
5594        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5595
5596 (defun gnus-article-edit-article (start-func exit-func)
5597   "Start editing the contents of the current article buffer."
5598   (let ((winconf (current-window-configuration)))
5599     (set-buffer gnus-article-buffer)
5600     (gnus-article-edit-mode)
5601     (funcall start-func)
5602     (set-buffer-modified-p nil)
5603     (gnus-configure-windows 'edit-article)
5604     (setq gnus-article-edit-done-function exit-func)
5605     (setq gnus-prev-winconf winconf)
5606     (gnus-message 6 "C-c C-c to end edits")))
5607
5608 (defun gnus-article-edit-done (&optional arg)
5609   "Update the article edits and exit."
5610   (interactive "P")
5611   (let ((func gnus-article-edit-done-function)
5612         (buf (current-buffer))
5613         (start (window-start))
5614         (p (point))
5615         (winconf gnus-prev-winconf))
5616     (widen) ;; Widen it in case that users narrowed the buffer.
5617     (funcall func arg)
5618     (set-buffer buf)
5619     ;; The cache and backlog have to be flushed somewhat.
5620     (when gnus-keep-backlog
5621       (gnus-backlog-remove-article
5622        (car gnus-article-current) (cdr gnus-article-current)))
5623     ;; Flush original article as well.
5624     (save-excursion
5625       (when (get-buffer gnus-original-article-buffer)
5626         (set-buffer gnus-original-article-buffer)
5627         (setq gnus-original-article nil)))
5628     (when gnus-use-cache
5629       (gnus-cache-update-article
5630        (car gnus-article-current) (cdr gnus-article-current)))
5631     ;; We remove all text props from the article buffer.
5632     (kill-all-local-variables)
5633     (set-text-properties (point-min) (point-max) nil)
5634     (gnus-article-mode)
5635     (set-window-configuration winconf)
5636     (set-buffer buf)
5637     (set-window-start (get-buffer-window buf) start)
5638     (set-window-point (get-buffer-window buf) (point)))
5639   (gnus-summary-show-article))
5640
5641 (defun gnus-article-edit-exit ()
5642   "Exit the article editing without updating."
5643   (interactive)
5644   (when (or (not (buffer-modified-p))
5645             (yes-or-no-p "Article modified; kill anyway? "))
5646     (let ((curbuf (current-buffer))
5647           (p (point))
5648           (window-start (window-start)))
5649       (erase-buffer)
5650       (if (gnus-buffer-live-p gnus-original-article-buffer)
5651           (insert-buffer gnus-original-article-buffer))
5652       (let ((winconf gnus-prev-winconf))
5653         (kill-all-local-variables)
5654         (gnus-article-mode)
5655         (set-window-configuration winconf)
5656         ;; Tippy-toe some to make sure that point remains where it was.
5657         (save-current-buffer
5658           (set-buffer curbuf)
5659           (set-window-start (get-buffer-window (current-buffer)) window-start)
5660           (goto-char p))))
5661     (gnus-summary-show-article)))
5662
5663 (defun gnus-article-edit-full-stops ()
5664   "Interactively repair spacing at end of sentences."
5665   (interactive)
5666   (save-excursion
5667     (goto-char (point-min))
5668     (search-forward-regexp "^$" nil t)
5669     (let ((case-fold-search nil))
5670       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5671
5672 ;;;
5673 ;;; Article highlights
5674 ;;;
5675
5676 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5677
5678 ;;; Internal Variables:
5679
5680 (defcustom gnus-button-url-regexp
5681   (if (string-match "[[:digit:]]" "1") ;; support POSIX?
5682       "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]\\)"
5683     "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)\\)")
5684   "Regular expression that matches URLs."
5685   :group 'gnus-article-buttons
5686   :type 'regexp)
5687
5688 (defcustom gnus-button-valid-fqdn-regexp
5689   message-valid-fqdn-regexp
5690   "Regular expression that matches a valid FQDN."
5691   :group 'gnus-article-buttons
5692   :type 'regexp)
5693
5694 (defcustom gnus-button-man-handler 'manual-entry
5695   "Function to use for displaying man pages.
5696 The function must take at least one argument with a string naming the
5697 man page."
5698   :type '(choice (function-item :tag "Man" manual-entry)
5699                  (function-item :tag "Woman" woman)
5700                  (function :tag "Other"))
5701   :group 'gnus-article-buttons)
5702
5703 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
5704   "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
5705 If the default site is too slow, try to find a CTAN mirror, see
5706 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>.  See also
5707 the variable `gnus-button-handle-ctan'."
5708   :group 'gnus-article-buttons
5709   :link '(custom-manual "(gnus)Group Parameters")
5710   :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
5711                  (const "http://tug.ctan.org/tex-archive/")
5712                  (const "http://www.dante.de/CTAN/")
5713                  (string :tag "Other")))
5714
5715 (defcustom gnus-button-ctan-handler 'browse-url
5716   "Function to use for displaying CTAN links.
5717 The function must take one argument, the string naming the URL."
5718   :type '(choice (function-item :tag "Browse Url" browse-url)
5719                  (function :tag "Other"))
5720   :group 'gnus-article-buttons)
5721
5722 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
5723   "Bogus strings removed from CTAN URLs."
5724   :group 'gnus-article-buttons
5725   :type '(choice (const "^/?tex-archive/\\|/")
5726                  (regexp :tag "Other")))
5727
5728 (defcustom gnus-button-ctan-directory-regexp
5729   (concat
5730    "\\(?:"
5731    "biblio\\|digests\\|dviware\\|fonts\\|graphics\\|help\\|"
5732    "indexing\\|info\\|language\\|macros\\|support\\|systems\\|"
5733    "tds\\|tools\\|usergrps\\|web\\|nonfree\\|obsolete"
5734    "\\)")
5735   "Regular expression for ctan directories.
5736 It should match all directories in the top level of `gnus-ctan-url'."
5737   :group 'gnus-article-buttons
5738   :type 'regexp)
5739
5740 (defcustom gnus-button-mid-or-mail-regexp
5741   (concat "\\b\\(<?[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*@"
5742           ;; Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
5743           gnus-button-valid-fqdn-regexp
5744           ">?\\)\\b")
5745   "Regular expression that matches a message ID or a mail address."
5746   :group 'gnus-article-buttons
5747   :type 'regexp)
5748
5749 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
5750   "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
5751 Strings like this can be either a message ID or a mail address.  If it is one
5752 of the symbols `mid' or `mail', Gnus will always assume that the string is a
5753 message ID or a mail address, respectively.  If this variable is set to the
5754 symbol `ask', always query the user what do do.  If it is a function, this
5755 function will be called with the string as it's only argument.  The function
5756 must return `mid', `mail', `invalid' or `ask'."
5757   :group 'gnus-article-buttons
5758   :type '(choice (function-item :tag "Heuristic function"
5759                                 gnus-button-mid-or-mail-heuristic)
5760                  (const ask)
5761                  (const mid)
5762                  (const mail)))
5763
5764 (defcustom gnus-button-mid-or-mail-heuristic-alist
5765   '((-10.0 . ".+\\$.+@")
5766     (-10.0 . "#")
5767     (-10.0 . "\\*")
5768     (-5.0  . "\\+[^+]*\\+.*@") ;; # two plus signs
5769     (-5.0  . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
5770     (-5.0  . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
5771     (-1.0  . "^[^a-z]+@")
5772     ;;
5773     (-5.0  . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
5774     (-5.0  . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
5775     (-3.0  . "[A-Z][A-Z][a-z][a-z].*@")
5776     (-5.0  . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
5777     ;;
5778     (-2.0  . "^[0-9]")
5779     (-1.0  . "^[0-9][0-9]")
5780     ;;
5781     ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
5782     (-3.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5783     ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
5784     (-5.0  . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5785     ;;
5786     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
5787     (-3.0  .  "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
5788     ;;       "[0-9]{8,}.*\@"
5789     (-3.0
5790      . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
5791     ;; "[0-9]{12,}.*\@"
5792     ;; compensation for TDMA dated mail addresses:
5793     (25.0  . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
5794     ;;
5795     (-20.0 . "\\.fsf@") ;; Gnus
5796     (-20.0 . "^slrn")
5797     (-20.0 . "^Pine")
5798     (-20.0 . "_-_") ;; Subject change in thread
5799     ;;
5800     (-20.0 . "\\.ln@") ;; leafnode
5801     (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
5802     (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
5803     ;;
5804     ;; (5.0 . "") ;; $local_part_len <= 7
5805     (10.0  . "^[^0-9]+@")
5806     (3.0   . "^[^0-9]+[0-9][0-9]?[0-9]?@")
5807     ;;      ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
5808     (3.0   . "\@stud")
5809     ;;
5810     (2.0   . "[a-z][a-z][._-][A-Z][a-z].*@")
5811     ;;
5812     (0.5   . "^[A-Z][a-z]")
5813     (0.5   . "^[A-Z][a-z][a-z]")
5814     (1.5   . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
5815     (2.0   . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
5816   "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
5817
5818 A negative RATE indicates a message IDs, whereas a positive indicates a mail
5819 address.  The REGEXP is processed with `case-fold-search' set to nil."
5820   :group 'gnus-article-buttons
5821   :type '(repeat (cons (number :tag "Rate")
5822                        (regexp :tag "Regexp"))))
5823
5824 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
5825   "Guess whether MID-OR-MAIL is a message ID or a mail address.
5826 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
5827 address, `ask' if unsure and `invalid' if the string is invalid."
5828   (let ((case-fold-search nil)
5829         (list gnus-button-mid-or-mail-heuristic-alist)
5830         (result 0) rate regexp lpartlen elem)
5831     (setq lpartlen
5832           (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
5833     (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
5834     ;; Certain special cases...
5835     (when (string-match
5836            (concat
5837             "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
5838             "^[0-9]+\\.[0-9]+@compuserve\\|"
5839             "@public\\.gmane\\.org")
5840            mid-or-mail)
5841       (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
5842       (setq result 'mail))
5843     (when (string-match "@.*@\\| " mid-or-mail)
5844       (gnus-message 8 "`%s' is invalid." mid-or-mail)
5845       (setq result 'invalid))
5846     ;; Nothing more to do, if result is not a number here...
5847     (when (numberp result)
5848       (while list
5849         (setq elem (car list)
5850               rate (car elem)
5851               regexp (cdr elem)
5852               list (cdr list))
5853         (when (string-match regexp mid-or-mail)
5854           (setq result (+ result rate))
5855           (gnus-message
5856            9 "`%s' matched `%s', rate `%s', result `%s'."
5857            mid-or-mail regexp rate result)))
5858       (when (<= lpartlen 7)
5859         (setq result (+ result 5.0))
5860         (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
5861                       mid-or-mail result))
5862       (when (>= lpartlen 12)
5863         (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
5864         (cond
5865          ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
5866           ;; Long local part should contain realname if e-mail address,
5867           ;; too many digits: message-id.
5868           ;; $score -= 5.0 + 0.1 * $local_part_len;
5869           (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
5870           (setq result (+ result rate))
5871           (gnus-message
5872            9 "Many digits in `%s', rate `%s', result `%s'."
5873            mid-or-mail rate result))
5874          ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
5875                         mid-or-mail)
5876           ;; Too few vowels [^aeiouy]{4,}.*\@
5877           (setq result (+ result -5.0))
5878           (gnus-message
5879            9 "Few vowels in `%s', rate `%s', result `%s'."
5880            mid-or-mail -5.0 result))
5881          (t
5882           (setq result (+ result 5.0))
5883           (gnus-message
5884            9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
5885     (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
5886     ;; Maybe we should make this a customizable alist: (condition . 'result)
5887     (cond
5888      ((symbolp result) result)
5889      ;; Now convert number into proper results:
5890      ((< result -10.0) 'mid)
5891      ((> result  10.0) 'mail)
5892      (t 'ask))))
5893
5894 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
5895   (let* ((pref gnus-button-prefer-mid-or-mail) guessed
5896          (url-mid (concat "news" ":" mid-or-mail))
5897          (url-mailto (concat "mailto" ":" mid-or-mail)))
5898     (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
5899     (when (fboundp pref)
5900       (setq guessed
5901             ;; get rid of surrounding angles...
5902             (funcall pref
5903                      (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
5904       (if (or (eq 'mid guessed) (eq 'mail guessed))
5905           (setq pref guessed)
5906         (setq pref 'ask)))
5907     (if (eq pref 'ask)
5908         (save-window-excursion
5909           (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
5910               (setq pref 'mail)
5911             (setq pref 'mid))))
5912     (cond ((eq pref 'mid)
5913            (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
5914            (gnus-button-handle-news url-mid))
5915           ((eq pref 'mail)
5916            (gnus-message 8 "calling `gnus-url-mailto'  %s" url-mailto)
5917            (gnus-url-mailto url-mailto))
5918           (t (gnus-message 3 "Invalid string.")))))
5919
5920 (defun gnus-button-handle-custom (url)
5921   "Follow a Custom URL."
5922   (customize-apropos (gnus-url-unhex-string url)))
5923
5924 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
5925
5926 ;; FIXME: Maybe we should merge some of the functions that do quite similar
5927 ;; stuff?
5928
5929 (defun gnus-button-handle-describe-function (url)
5930   "Call `describe-function' when pushing the corresponding URL button."
5931   (describe-function
5932    (intern
5933     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5934
5935 (defun gnus-button-handle-describe-variable (url)
5936   "Call `describe-variable' when pushing the corresponding URL button."
5937   (describe-variable
5938    (intern
5939     (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
5940
5941 (defun gnus-button-handle-symbol (url)
5942 "Display help on variable or function.
5943 Calls `describe-variable' or `describe-function'."
5944   (let ((sym (intern url)))
5945     (cond
5946      ((fboundp sym) (describe-function sym))
5947      ((boundp sym) (describe-variable sym))
5948      (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
5949
5950 (defun gnus-button-handle-describe-key (url)
5951   "Call `describe-key' when pushing the corresponding URL button."
5952   (let* ((key-string
5953           (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
5954          (keys (ignore-errors (eval `(kbd ,key-string)))))
5955     (if keys
5956         (describe-key keys)
5957       (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
5958
5959 (defun gnus-button-handle-apropos (url)
5960   "Call `apropos' when pushing the corresponding URL button."
5961   (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5962
5963 (defun gnus-button-handle-apropos-command (url)
5964   "Call `apropos' when pushing the corresponding URL button."
5965   (apropos-command
5966    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5967
5968 (defun gnus-button-handle-apropos-variable (url)
5969   "Call `apropos' when pushing the corresponding URL button."
5970   (funcall
5971    (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
5972    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5973
5974 (defun gnus-button-handle-apropos-documentation (url)
5975   "Call `apropos' when pushing the corresponding URL button."
5976   (funcall
5977    (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
5978    (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
5979
5980 (defun gnus-button-handle-library (url)
5981   "Call `locate-library' when pushing the corresponding URL button."
5982   (gnus-message 9 "url=`%s'" url)
5983   (let* ((lib (locate-library url))
5984          (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
5985     (if (not lib)
5986         (gnus-message 1 "Cannot locale library `%s'." url)
5987       (find-file-read-only file))))
5988
5989 (defun gnus-button-handle-ctan (url)
5990   "Call `browse-url' when pushing a CTAN URL button."
5991   (funcall
5992    gnus-button-ctan-handler
5993    (concat
5994     gnus-ctan-url
5995     (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
5996
5997 (defcustom gnus-button-tex-level 5
5998   "*Integer that says how many TeX-related buttons Gnus will show.
5999 The higher the number, the more buttons will appear and the more false
6000 positives are possible.  Note that you can set this variable local to
6001 specific groups.  Setting it higher in TeX groups is probably a good idea.
6002 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6003 how to set variables in specific groups."
6004   :group 'gnus-article-buttons
6005   :link '(custom-manual "(gnus)Group Parameters")
6006   :type 'integer)
6007
6008 (defcustom gnus-button-man-level 5
6009   "*Integer that says how many man-related buttons Gnus will show.
6010 The higher the number, the more buttons will appear and the more false
6011 positives are possible.  Note that you can set this variable local to
6012 specific groups.  Setting it higher in Unix groups is probably a good idea.
6013 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6014 how to set variables in specific groups."
6015   :group 'gnus-article-buttons
6016   :link '(custom-manual "(gnus)Group Parameters")
6017   :type 'integer)
6018
6019 (defcustom gnus-button-emacs-level 5
6020   "*Integer that says how many emacs-related buttons Gnus will show.
6021 The higher the number, the more buttons will appear and the more false
6022 positives are possible.  Note that you can set this variable local to
6023 specific groups.  Setting it higher in Emacs or Gnus related groups is
6024 probably a good idea.  See Info node `(gnus)Group Parameters' and the variable
6025 `gnus-parameters' on how to set variables in specific groups."
6026   :group 'gnus-article-buttons
6027   :link '(custom-manual "(gnus)Group Parameters")
6028   :type 'integer)
6029
6030 (defcustom gnus-button-message-level 5
6031   "*Integer that says how many buttons for news or mail messages will appear.
6032 The higher the number, the more buttons will appear and the more false
6033 positives are possible."
6034   ;; mail addresses, MIDs, URLs for news, ...
6035   :group 'gnus-article-buttons
6036   :type 'integer)
6037
6038 (defcustom gnus-button-browse-level 5
6039   "*Integer that says how many buttons for browsing will appear.
6040 The higher the number, the more buttons will appear and the more false
6041 positives are possible."
6042   ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6043   :group 'gnus-article-buttons
6044   :type 'integer)
6045
6046 (defcustom gnus-button-alist
6047   '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6048      0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6049     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
6050      gnus-button-handle-news 2)
6051     ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6052      1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6053     ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6054      0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6055     ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6056     ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6057      0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6058     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6059      2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6060     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6061      0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6062     ;; RFC 2368 (The mailto URL scheme)
6063     ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6064      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6065     ("\\bmailto:\\([^ \n\t]+\\)"
6066      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6067     ;; CTAN
6068     ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6069              gnus-button-ctan-directory-regexp
6070              "[^][>)!;:,'\n\t ]+\\)")
6071      0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6072     ((concat "\\btex-archive/\\("
6073              gnus-button-ctan-directory-regexp
6074              "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6075      1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6076     ((concat
6077       "\\b\\("
6078       gnus-button-ctan-directory-regexp
6079       "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6080      1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6081     ;; This is info (home-grown style) <info://foo/bar+baz>
6082     ("\\binfo://\\([^'\">\n\t ]+\\)"
6083      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6084     ;; Info GNOME style <info:foo#bar_baz>
6085     ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6086      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6087     ;; Info KDE style <info:(foo)bar baz>
6088     ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6089      1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6090     ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6091      (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6092     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6093      ;; Info links like `C-h i d m CC Mode RET'
6094      0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6095     ;; This is custom
6096     ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6097      0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6098     ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6099      (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6100     ;; Emacs help commands
6101     ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6102      ;; regexp doesn't match arguments containing ` '.
6103      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6104     ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6105      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6106     ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6107      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6108     ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6109      0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6110     ;; The following entries may lead to many false positives so don't enable
6111     ;; them by default (use a high button level):
6112     ("/\\([a-z][-a-z0-9]+\\.el\\)\\>"
6113      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6114     ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6115      1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6116     ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6117      0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6118     ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6119      0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6120     ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6121      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6122     ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6123      1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6124     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6125      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6126     ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6127      0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6128     ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6129      ;; Unlike the other regexps we really have to require quoting
6130      ;; here to determine where it ends.
6131      1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6132     ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6133     ("<URL: *\\([^<>]*\\)>"
6134      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6135     ;; RFC 2396 (2.4.3., delims) ...
6136     ("\"URL: *\\([^\"]*\\)\""
6137      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6138     ;; RFC 2396 (2.4.3., delims) ...
6139     ("\"URL: *\\([^\"]*\\)\""
6140      1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6141     ;; Raw URLs.
6142     (gnus-button-url-regexp
6143      0 (>= gnus-button-browse-level 0) browse-url 0)
6144     ;; man pages
6145     ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6146      0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6147      gnus-button-handle-man 1)
6148     ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6149     ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6150      0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6151      gnus-button-handle-man 1)
6152     ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6153     ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6154     ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6155      0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6156     ;; MID or mail: To avoid too many false positives we don't try to catch
6157     ;; all kind of allowed MIDs or mail addresses.  Domain part must contain
6158     ;; at least one dot.  TLD must contain two or three chars or be a know TLD
6159     ;; (info|name|...).  Put this entry near the _end_ of `gnus-button-alist'
6160     ;; so that non-ambiguous entries (see above) match first.
6161     (gnus-button-mid-or-mail-regexp
6162      0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6163   "*Alist of regexps matching buttons in article bodies.
6164
6165 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6166 REGEXP: is the string (case insensitive) matching text around the button (can
6167 also be Lisp expression evaluating to a string),
6168 BUTTON: is the number of the regexp grouping actually matching the button,
6169 FORM: is a Lisp expression which must eval to true for the button to
6170 be added,
6171 CALLBACK: is the function to call when the user push this button, and each
6172 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6173
6174 CALLBACK can also be a variable, in that case the value of that
6175 variable it the real callback function."
6176   :group 'gnus-article-buttons
6177   :type '(repeat (list (choice regexp variable sexp)
6178                        (integer :tag "Button")
6179                        (sexp :tag "Form")
6180                        (function :tag "Callback")
6181                        (repeat :tag "Par"
6182                                :inline t
6183                                (integer :tag "Regexp group")))))
6184
6185 (defcustom gnus-header-button-alist
6186   '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6187      0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6188     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6189      1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6190     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6191      0 (>= gnus-button-message-level 0) gnus-button-mailto 0)
6192     ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6193      0 (>= gnus-button-browse-level 0) browse-url 0)
6194     ("^Subject:" gnus-button-url-regexp
6195      0 (>= gnus-button-browse-level 0) browse-url 0)
6196     ("^[^:]+:" gnus-button-url-regexp
6197      0 (>= gnus-button-browse-level 0) browse-url 0)
6198     ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6199      0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6200     ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6201      1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6202   "*Alist of headers and regexps to match buttons in article heads.
6203
6204 This alist is very similar to `gnus-button-alist', except that each
6205 alist has an additional HEADER element first in each entry:
6206
6207 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6208
6209 HEADER is a regexp to match a header.  For a fuller explanation, see
6210 `gnus-button-alist'."
6211   :group 'gnus-article-buttons
6212   :group 'gnus-article-headers
6213   :type '(repeat (list (regexp :tag "Header")
6214                        (choice regexp variable)
6215                        (integer :tag "Button")
6216                        (sexp :tag "Form")
6217                        (function :tag "Callback")
6218                        (repeat :tag "Par"
6219                                :inline t
6220                                (integer :tag "Regexp group")))))
6221
6222 ;;; Commands:
6223
6224 (defun gnus-article-push-button (event)
6225   "Check text under the mouse pointer for a callback function.
6226 If the text under the mouse pointer has a `gnus-callback' property,
6227 call it with the value of the `gnus-data' text property."
6228   (interactive "e")
6229   (set-buffer (window-buffer (posn-window (event-start event))))
6230   (let* ((pos (posn-point (event-start event)))
6231          (data (get-text-property pos 'gnus-data))
6232          (fun (get-text-property pos 'gnus-callback)))
6233     (goto-char pos)
6234     (when fun
6235       (funcall fun data))))
6236
6237 (defun gnus-article-press-button ()
6238   "Check text at point for a callback function.
6239 If the text at point has a `gnus-callback' property,
6240 call it with the value of the `gnus-data' text property."
6241   (interactive)
6242   (let ((data (get-text-property (point) 'gnus-data))
6243         (fun (get-text-property (point) 'gnus-callback)))
6244     (when fun
6245       (funcall fun data))))
6246
6247 (defun gnus-article-highlight (&optional force)
6248   "Highlight current article.
6249 This function calls `gnus-article-highlight-headers',
6250 `gnus-article-highlight-citation',
6251 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6252 do the highlighting.  See the documentation for those functions."
6253   (interactive (list 'force))
6254   (gnus-article-highlight-headers)
6255   (gnus-article-highlight-citation force)
6256   (gnus-article-highlight-signature)
6257   (gnus-article-add-buttons force)
6258   (gnus-article-add-buttons-to-head))
6259
6260 (defun gnus-article-highlight-some (&optional force)
6261   "Highlight current article.
6262 This function calls `gnus-article-highlight-headers',
6263 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6264 do the highlighting.  See the documentation for those functions."
6265   (interactive (list 'force))
6266   (gnus-article-highlight-headers)
6267   (gnus-article-highlight-signature)
6268   (gnus-article-add-buttons))
6269
6270 (defun gnus-article-highlight-headers ()
6271   "Highlight article headers as specified by `gnus-header-face-alist'."
6272   (interactive)
6273   (gnus-with-article-headers
6274     (let ((alist gnus-header-face-alist)
6275           entry regexp header-face field-face from hpoints fpoints)
6276       (while (setq entry (pop alist))
6277         (goto-char (point-min))
6278         (setq regexp (concat "^\\("
6279                              (if (string-equal "" (nth 0 entry))
6280                                  "[^\t ]"
6281                                (nth 0 entry))
6282                              "\\)")
6283               header-face (nth 1 entry)
6284               field-face (nth 2 entry))
6285         (while (and (re-search-forward regexp nil t)
6286                     (not (eobp)))
6287           (beginning-of-line)
6288           (setq from (point))
6289           (unless (search-forward ":" nil t)
6290             (forward-char 1))
6291           (when (and header-face
6292                      (not (memq (point) hpoints)))
6293             (push (point) hpoints)
6294             (gnus-put-text-property from (point) 'face header-face))
6295           (when (and field-face
6296                      (not (memq (setq from (point)) fpoints)))
6297             (push from fpoints)
6298             (if (re-search-forward "^[^ \t]" nil t)
6299                 (forward-char -2)
6300               (goto-char (point-max)))
6301             (gnus-put-text-property from (point) 'face field-face)))))))
6302
6303 (defun gnus-article-highlight-signature ()
6304   "Highlight the signature in an article.
6305 It does this by highlighting everything after
6306 `gnus-signature-separator' using `gnus-signature-face'."
6307   (interactive)
6308   (gnus-with-article-buffer
6309     (let ((inhibit-point-motion-hooks t))
6310       (save-restriction
6311         (when (and gnus-signature-face
6312                    (gnus-article-narrow-to-signature))
6313           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6314                             'face gnus-signature-face)
6315           (widen)
6316           (gnus-article-search-signature)
6317           (let ((start (match-beginning 0))
6318                 (end (set-marker (make-marker) (1+ (match-end 0)))))
6319             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6320                                      end)))))))
6321
6322 (defun gnus-button-in-region-p (b e prop)
6323   "Say whether PROP exists in the region."
6324   (text-property-not-all b e prop nil))
6325
6326 (defun gnus-article-add-buttons (&optional force)
6327   "Find external references in the article and make buttons of them.
6328 \"External references\" are things like Message-IDs and URLs, as
6329 specified by `gnus-button-alist'."
6330   (interactive (list 'force))
6331   (gnus-with-article-buffer
6332     (let ((inhibit-point-motion-hooks t)
6333           (case-fold-search t)
6334           (alist gnus-button-alist)
6335           beg entry regexp)
6336       ;; Remove all old markers.
6337       (let (marker entry new-list)
6338         (while (setq marker (pop gnus-button-marker-list))
6339           (if (or (< marker (point-min)) (>= marker (point-max)))
6340               (push marker new-list)
6341             (goto-char marker)
6342             (when (setq entry (gnus-button-entry))
6343               (put-text-property (match-beginning (nth 1 entry))
6344                                  (match-end (nth 1 entry))
6345                                  'gnus-callback nil))
6346             (set-marker marker nil)))
6347         (setq gnus-button-marker-list new-list))
6348       ;; We skip the headers.
6349       (article-goto-body)
6350       (setq beg (point))
6351       (while (setq entry (pop alist))
6352         (setq regexp (eval (car entry)))
6353         (goto-char beg)
6354         (while (re-search-forward regexp nil t)
6355           (let* ((start (and entry (match-beginning (nth 1 entry))))
6356                  (end (and entry (match-end (nth 1 entry))))
6357                  (from (match-beginning 0)))
6358             (when (and (or (eq t (nth 2 entry))
6359                            (eval (nth 2 entry)))
6360                        (not (gnus-button-in-region-p
6361                              start end 'gnus-callback)))
6362               ;; That optional form returned non-nil, so we add the
6363               ;; button.
6364               (gnus-article-add-button
6365                start end 'gnus-button-push
6366                (car (push (set-marker (make-marker) from)
6367                           gnus-button-marker-list))))))))))
6368
6369 ;; Add buttons to the head of an article.
6370 (defun gnus-article-add-buttons-to-head ()
6371   "Add buttons to the head of the article."
6372   (interactive)
6373   (gnus-with-article-headers
6374     (let ((alist gnus-header-button-alist)
6375           entry beg end)
6376       (while alist
6377         ;; Each alist entry.
6378         (setq entry (pop alist))
6379         (goto-char (point-min))
6380         (while (re-search-forward (car entry) nil t)
6381           ;; Each header matching the entry.
6382           (setq beg (match-beginning 0))
6383           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6384                              (match-beginning 0))
6385                         (point-max)))
6386           (goto-char beg)
6387           (while (re-search-forward (eval (nth 1 entry)) end t)
6388             ;; Each match within a header.
6389             (let* ((entry (cdr entry))
6390                    (start (match-beginning (nth 1 entry)))
6391                    (end (match-end (nth 1 entry)))
6392                    (form (nth 2 entry)))
6393               (goto-char (match-end 0))
6394               (when (eval form)
6395                 (gnus-article-add-button
6396                  start end (nth 3 entry)
6397                  (buffer-substring (match-beginning (nth 4 entry))
6398                                    (match-end (nth 4 entry)))))))
6399           (goto-char end))))))
6400
6401 ;;; External functions:
6402
6403 (defun gnus-article-add-button (from to fun &optional data)
6404   "Create a button between FROM and TO with callback FUN and data DATA."
6405   (when gnus-article-button-face
6406     (gnus-overlay-put (gnus-make-overlay from to)
6407                       'face gnus-article-button-face))
6408   (gnus-add-text-properties
6409    from to
6410    (nconc (and gnus-article-mouse-face
6411                (list gnus-mouse-face-prop gnus-article-mouse-face))
6412           (list 'gnus-callback fun)
6413           (and data (list 'gnus-data data))))
6414   (widget-convert-button 'link from to :action 'gnus-widget-press-button
6415                          :button-keymap gnus-widget-button-keymap))
6416
6417 ;;; Internal functions:
6418
6419 (defun gnus-article-set-globals ()
6420   (with-current-buffer gnus-summary-buffer
6421     (gnus-set-global-variables)))
6422
6423 (defun gnus-signature-toggle (end)
6424   (gnus-with-article-buffer
6425     (let ((inhibit-point-motion-hooks t))
6426       (if (text-property-any end (point-max) 'article-type 'signature)
6427           (progn
6428             (gnus-delete-wash-type 'signature)
6429             (gnus-remove-text-properties-when
6430              'article-type 'signature end (point-max)
6431              (cons 'article-type (cons 'signature
6432                                        gnus-hidden-properties))))
6433         (gnus-add-wash-type 'signature)
6434         (gnus-add-text-properties-when
6435          'article-type nil end (point-max)
6436          (cons 'article-type (cons 'signature
6437                                    gnus-hidden-properties)))))
6438     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6439       (gnus-set-mode-line 'article))))
6440
6441 (defun gnus-button-entry ()
6442   ;; Return the first entry in `gnus-button-alist' matching this place.
6443   (let ((alist gnus-button-alist)
6444         (entry nil))
6445     (while alist
6446       (setq entry (pop alist))
6447       (if (looking-at (eval (car entry)))
6448           (setq alist nil)
6449         (setq entry nil)))
6450     entry))
6451
6452 (defun gnus-button-push (marker)
6453   ;; Push button starting at MARKER.
6454   (save-excursion
6455     (goto-char marker)
6456     (let* ((entry (gnus-button-entry))
6457            (inhibit-point-motion-hooks t)
6458            (fun (nth 3 entry))
6459            (args (mapcar (lambda (group)
6460                            (let ((string (match-string group)))
6461                              (set-text-properties
6462                               0 (length string) nil string)
6463                              string))
6464                          (nthcdr 4 entry))))
6465       (cond
6466        ((fboundp fun)
6467         (apply fun args))
6468        ((and (boundp fun)
6469              (fboundp (symbol-value fun)))
6470         (apply (symbol-value fun) args))
6471        (t
6472         (gnus-message 1 "You must define `%S' to use this button"
6473                       (cons fun args)))))))
6474
6475 (defun gnus-parse-news-url (url)
6476   (let (scheme server group message-id articles)
6477     (with-temp-buffer
6478       (insert url)
6479       (goto-char (point-min))
6480       (when (looking-at "\\([A-Za-z]+\\):")
6481         (setq scheme (match-string 1))
6482         (goto-char (match-end 0)))
6483       (when (looking-at "//\\([^/]+\\)/")
6484         (setq server (match-string 1))
6485         (goto-char (match-end 0)))
6486
6487       (cond
6488        ((looking-at "\\(.*@.*\\)")
6489         (setq message-id (match-string 1)))
6490        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6491         (setq group (match-string 1)
6492               articles (split-string (match-string 2) "-")))
6493        ((looking-at "\\([^/]+\\)/?")
6494         (setq group (match-string 1)))
6495        (t
6496         (error "Unknown news URL syntax"))))
6497     (list scheme server group message-id articles)))
6498
6499 (defun gnus-button-handle-news (url)
6500   "Fetch a news URL."
6501   (destructuring-bind (scheme server group message-id articles)
6502       (gnus-parse-news-url url)
6503     (cond
6504      (message-id
6505       (save-excursion
6506         (set-buffer gnus-summary-buffer)
6507         (if server
6508             (let ((gnus-refer-article-method (list (list 'nntp server))))
6509               (gnus-summary-refer-article message-id))
6510           (gnus-summary-refer-article message-id))))
6511      (group
6512       (gnus-button-fetch-group url)))))
6513
6514 (defun gnus-button-handle-man (url)
6515   "Fetch a man page."
6516   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6517   (when (eq gnus-button-man-handler 'woman)
6518     (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
6519   (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6520   (funcall gnus-button-man-handler url))
6521
6522 (defun gnus-button-handle-info-url (url)
6523   "Fetch an info URL."
6524   (setq url (mm-subst-char-in-string ?+ ?\  url))
6525   (cond
6526    ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6527     (gnus-info-find-node
6528      (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6529                      "Gnus")
6530              ")" (gnus-url-unhex-string (match-string 2 url)))))
6531    ((string-match "([^)\"]+)[^\"]+" url)
6532     (setq url
6533           (gnus-replace-in-string
6534            (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
6535     (gnus-info-find-node url))
6536    (t (error "Can't parse %s" url))))
6537
6538 (defun gnus-button-handle-info-url-gnome (url)
6539   "Fetch GNOME style info URL."
6540   (setq url (mm-subst-char-in-string ?_ ?\  url))
6541   (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
6542       (gnus-info-find-node
6543        (concat "("
6544                (gnus-url-unhex-string 
6545                  (match-string 1 url))
6546                ")"
6547                (or (gnus-url-unhex-string 
6548                     (match-string 2 url))
6549                    "Top")))
6550     (error "Can't parse %s" url)))
6551
6552 (defun gnus-button-handle-info-url-kde (url)
6553   "Fetch KDE style info URL."
6554   (gnus-info-find-node (gnus-url-unhex-string url)))
6555
6556 (defun gnus-button-handle-info-keystrokes (url)
6557   "Call `info' when pushing the corresponding URL button."
6558   ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
6559   (info)
6560   (Info-directory)
6561   (Info-menu url))
6562
6563 (defun gnus-button-message-id (message-id)
6564   "Fetch MESSAGE-ID."
6565   (with-current-buffer gnus-summary-buffer
6566     (gnus-summary-refer-article message-id)))
6567
6568 (defun gnus-button-fetch-group (address)
6569   "Fetch GROUP specified by ADDRESS."
6570   (if (not (string-match "[:/]" address))
6571       ;; This is just a simple group url.
6572       (gnus-group-read-ephemeral-group address gnus-select-method)
6573     (if (not
6574          (string-match
6575           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6576           address))
6577         (error "Can't parse %s" address)
6578       (gnus-group-read-ephemeral-group
6579        (match-string 4 address)
6580        `(nntp ,(match-string 1 address)
6581               (nntp-address ,(match-string 1 address))
6582               (nntp-port-number ,(if (match-end 3)
6583                                      (match-string 3 address)
6584                                    "nntp")))
6585        nil nil nil
6586        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6587
6588 (defun gnus-url-parse-query-string (query &optional downcase)
6589   (let (retval pairs cur key val)
6590     (setq pairs (split-string query "&"))
6591     (while pairs
6592       (setq cur (car pairs)
6593             pairs (cdr pairs))
6594       (if (not (string-match "=" cur))
6595           nil                           ; Grace
6596         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6597               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6598         (if downcase
6599             (setq key (downcase key)))
6600         (setq cur (assoc key retval))
6601         (if cur
6602             (setcdr cur (cons val (cdr cur)))
6603           (setq retval (cons (list key val) retval)))))
6604     retval))
6605
6606 (defun gnus-url-mailto (url)
6607   ;; Send mail to someone
6608   (when (string-match "mailto:/*\\(.*\\)" url)
6609     (setq url (substring url (match-beginning 1) nil)))
6610   (let (to args subject func)
6611     (setq args (gnus-url-parse-query-string
6612                 (if (string-match "^\\?" url)
6613                     (substring url 1)
6614                   (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
6615                       (concat "to=" (match-string 1 url) "&"
6616                               (match-string 2 url))
6617                     (concat "to=" url)))
6618                 t)
6619           subject (cdr-safe (assoc "subject" args)))
6620     (gnus-msg-mail)
6621     (while args
6622       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6623       (if (fboundp func)
6624           (funcall func)
6625         (message-position-on-field (caar args)))
6626       (insert (gnus-replace-in-string
6627                (mapconcat 'identity (reverse (cdar args)) ", ")
6628                "\r\n" "\n" t))
6629       (setq args (cdr args)))
6630     (if subject
6631         (message-goto-body)
6632       (message-goto-subject))))
6633
6634 (defun gnus-button-embedded-url (address)
6635   "Activate ADDRESS with `browse-url'."
6636   (browse-url (gnus-strip-whitespace address)))
6637
6638 ;;; Next/prev buttons in the article buffer.
6639
6640 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6641 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6642
6643 (defvar gnus-prev-page-map
6644   (let ((map (make-sparse-keymap)))
6645     (define-key map gnus-mouse-2 'gnus-button-prev-page)
6646     (define-key map "\r" 'gnus-button-prev-page)
6647     map))
6648
6649 (defvar gnus-next-page-map
6650   (let ((map (make-sparse-keymap)))
6651     (define-key map gnus-mouse-2 'gnus-button-next-page)
6652     (define-key map "\r" 'gnus-button-next-page)
6653     map))
6654
6655 (defun gnus-insert-prev-page-button ()
6656   (let ((b (point))
6657         (buffer-read-only nil))
6658     (gnus-eval-format
6659      gnus-prev-page-line-format nil
6660      `(keymap ,gnus-prev-page-map
6661          gnus-prev t
6662          gnus-callback gnus-article-button-prev-page
6663          article-type annotation))
6664     (widget-convert-button
6665      'link b (if (bolp)
6666                  ;; Exclude a newline.
6667                  (1- (point))
6668                (point))
6669      :action 'gnus-button-prev-page
6670      :button-keymap gnus-prev-page-map)))
6671
6672 (defun gnus-button-next-page (&optional args more-args)
6673   "Go to the next page."
6674   (interactive)
6675   (let ((win (selected-window)))
6676     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6677     (gnus-article-next-page)
6678     (select-window win)))
6679
6680 (defun gnus-button-prev-page (&optional args more-args)
6681   "Go to the prev page."
6682   (interactive)
6683   (let ((win (selected-window)))
6684     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6685     (gnus-article-prev-page)
6686     (select-window win)))
6687
6688 (defun gnus-insert-next-page-button ()
6689   (let ((b (point))
6690         (buffer-read-only nil))
6691     (gnus-eval-format gnus-next-page-line-format nil
6692                       `(keymap ,gnus-next-page-map
6693                           gnus-next t
6694                           gnus-callback gnus-article-button-next-page
6695                           article-type annotation))
6696     (widget-convert-button
6697      'link b (if (bolp)
6698                  ;; Exclude a newline.
6699                  (1- (point))
6700                (point))
6701      :action 'gnus-button-next-page
6702      :button-keymap gnus-next-page-map)))
6703
6704 (defun gnus-article-button-next-page (arg)
6705   "Go to the next page."
6706   (interactive "P")
6707   (let ((win (selected-window)))
6708     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6709     (gnus-article-next-page)
6710     (select-window win)))
6711
6712 (defun gnus-article-button-prev-page (arg)
6713   "Go to the prev page."
6714   (interactive "P")
6715   (let ((win (selected-window)))
6716     (select-window (gnus-get-buffer-window gnus-article-buffer t))
6717     (gnus-article-prev-page)
6718     (select-window win)))
6719
6720 (defvar gnus-decode-header-methods
6721   '(mail-decode-encoded-word-region)
6722   "List of methods used to decode headers.
6723
6724 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
6725 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
6726 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
6727 whose names match REGEXP.
6728
6729 For example:
6730 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6731  mail-decode-encoded-word-region
6732  (\"chinese\" . rfc1843-decode-region))
6733 ")
6734
6735 (defvar gnus-decode-header-methods-cache nil)
6736
6737 (defun gnus-multi-decode-header (start end)
6738   "Apply the functions from `gnus-encoded-word-methods' that match."
6739   (unless (and gnus-decode-header-methods-cache
6740                (eq gnus-newsgroup-name
6741                    (car gnus-decode-header-methods-cache)))
6742     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6743     (mapcar (lambda (x)
6744               (if (symbolp x)
6745                   (nconc gnus-decode-header-methods-cache (list x))
6746                 (if (and gnus-newsgroup-name
6747                          (string-match (car x) gnus-newsgroup-name))
6748                     (nconc gnus-decode-header-methods-cache
6749                            (list (cdr x))))))
6750           gnus-decode-header-methods))
6751   (let ((xlist gnus-decode-header-methods-cache))
6752     (pop xlist)
6753     (save-restriction
6754       (narrow-to-region start end)
6755       (while xlist
6756         (funcall (pop xlist) (point-min) (point-max))))))
6757
6758 ;;;
6759 ;;; Treatment top-level handling.
6760 ;;;
6761
6762 (defun gnus-treat-article (condition &optional part-number total-parts type)
6763   (let ((length (- (point-max) (point-min)))
6764         (alist gnus-treatment-function-alist)
6765         (article-goto-body-goes-to-point-min-p t)
6766         (treated-type
6767          (or (not type)
6768              (catch 'found
6769                (let ((list gnus-article-treat-types))
6770                  (while list
6771                    (when (string-match (pop list) type)
6772                      (throw 'found t)))))))
6773         (highlightp (gnus-visual-p 'article-highlight 'highlight))
6774         val elem)
6775     (gnus-run-hooks 'gnus-part-display-hook)
6776     (dolist (elem alist)
6777       (setq val
6778             (save-excursion
6779               (when (gnus-buffer-live-p gnus-summary-buffer)
6780                 (set-buffer gnus-summary-buffer))
6781               (symbol-value (car elem))))
6782       (when (and (or (consp val)
6783                      treated-type)
6784                  (gnus-treat-predicate val)
6785                  (or (not (get (car elem) 'highlight))
6786                      highlightp))
6787         (save-restriction
6788           (funcall (cadr elem)))))))
6789
6790 ;; Dynamic variables.
6791 (eval-when-compile
6792   (defvar part-number)
6793   (defvar total-parts)
6794   (defvar type)
6795   (defvar condition)
6796   (defvar length))
6797
6798 (defun gnus-treat-predicate (val)
6799   (cond
6800    ((null val)
6801     nil)
6802    (condition
6803     (eq condition val))
6804    ((and (listp val)
6805          (stringp (car val)))
6806     (apply 'gnus-or (mapcar `(lambda (s)
6807                                (string-match s ,(or gnus-newsgroup-name "")))
6808                             val)))
6809    ((listp val)
6810     (let ((pred (pop val)))
6811       (cond
6812        ((eq pred 'or)
6813         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6814        ((eq pred 'and)
6815         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6816        ((eq pred 'not)
6817         (not (gnus-treat-predicate (car val))))
6818        ((eq pred 'typep)
6819         (equal (car val) type))
6820        (t
6821         (error "%S is not a valid predicate" pred)))))
6822    ((eq val t)
6823     t)
6824    ((eq val 'head)
6825     nil)
6826    ((eq val 'last)
6827     (eq part-number total-parts))
6828    ((numberp val)
6829     (< length val))
6830    (t
6831     (error "%S is not a valid value" val))))
6832
6833 (defun gnus-article-encrypt-body (protocol &optional n)
6834   "Encrypt the article body."
6835   (interactive
6836    (list
6837     (or gnus-article-encrypt-protocol
6838         (completing-read "Encrypt protocol: "
6839                          gnus-article-encrypt-protocol-alist
6840                          nil t))
6841     current-prefix-arg))
6842   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6843     (unless func
6844       (error (format "Can't find the encrypt protocol %s" protocol)))
6845     (if (member gnus-newsgroup-name '("nndraft:delayed"
6846                                       "nndraft:drafts"
6847                                       "nndraft:queue"))
6848         (error "Can't encrypt the article in group %s"
6849                gnus-newsgroup-name))
6850     (gnus-summary-iterate n
6851       (save-excursion
6852         (set-buffer gnus-summary-buffer)
6853         (let ((mail-parse-charset gnus-newsgroup-charset)
6854               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6855               (summary-buffer gnus-summary-buffer)
6856               references point)
6857           (gnus-set-global-variables)
6858           (when (gnus-group-read-only-p)
6859             (error "The current newsgroup does not support article encrypt"))
6860           (gnus-summary-show-article t)
6861           (setq references
6862               (or (mail-header-references gnus-current-headers) ""))
6863           (set-buffer gnus-article-buffer)
6864           (let* ((buffer-read-only nil)
6865                  (headers
6866                   (mapcar (lambda (field)
6867                             (and (save-restriction
6868                                    (message-narrow-to-head)
6869                                    (goto-char (point-min))
6870                                    (search-forward field nil t))
6871                                  (prog2
6872                                      (message-narrow-to-field)
6873                                      (buffer-string)
6874                                    (delete-region (point-min) (point-max))
6875                                    (widen))))
6876                           '("Content-Type:" "Content-Transfer-Encoding:"
6877                             "Content-Disposition:"))))
6878             (message-narrow-to-head)
6879             (message-remove-header "MIME-Version")
6880             (goto-char (point-max))
6881             (setq point (point))
6882             (insert (apply 'concat headers))
6883             (widen)
6884             (narrow-to-region point (point-max))
6885             (let ((message-options message-options))
6886               (message-options-set 'message-sender user-mail-address)
6887               (message-options-set 'message-recipients user-mail-address)
6888               (message-options-set 'message-sign-encrypt 'not)
6889               (funcall func))
6890             (goto-char (point-min))
6891             (insert "MIME-Version: 1.0\n")
6892             (widen)
6893             (gnus-summary-edit-article-done
6894              references nil summary-buffer t))
6895           (when gnus-keep-backlog
6896             (gnus-backlog-remove-article
6897              (car gnus-article-current) (cdr gnus-article-current)))
6898           (save-excursion
6899             (when (get-buffer gnus-original-article-buffer)
6900               (set-buffer gnus-original-article-buffer)
6901               (setq gnus-original-article nil)))
6902           (when gnus-use-cache
6903             (gnus-cache-update-article
6904              (car gnus-article-current) (cdr gnus-article-current))))))))
6905
6906 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6907   "The following specs can be used:
6908 %t  The security MIME type
6909 %i  Additional info
6910 %d  Details
6911 %D  Details if button is pressed")
6912
6913 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6914   "The following specs can be used:
6915 %t  The security MIME type
6916 %i  Additional info
6917 %d  Details
6918 %D  Details if button is pressed")
6919
6920 (defvar gnus-mime-security-button-line-format-alist
6921   '((?t gnus-tmp-type ?s)
6922     (?i gnus-tmp-info ?s)
6923     (?d gnus-tmp-details ?s)
6924     (?D gnus-tmp-pressed-details ?s)))
6925
6926 (defvar gnus-mime-security-button-map
6927   (let ((map (make-sparse-keymap)))
6928     (define-key map gnus-mouse-2 'gnus-article-push-button)
6929     (define-key map "\r" 'gnus-article-press-button)
6930     map))
6931
6932 (defvar gnus-mime-security-details-buffer nil)
6933
6934 (defvar gnus-mime-security-button-pressed nil)
6935
6936 (defvar gnus-mime-security-show-details-inline t
6937   "If non-nil, show details in the article buffer.")
6938
6939 (defun gnus-mime-security-verify-or-decrypt (handle)
6940   (mm-remove-parts (cdr handle))
6941   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6942         point buffer-read-only)
6943     (if region
6944         (goto-char (car region)))
6945     (save-restriction
6946       (narrow-to-region (point) (point))
6947       (with-current-buffer (mm-handle-multipart-original-buffer handle)
6948         (let* ((mm-verify-option 'known)
6949                (mm-decrypt-option 'known)
6950                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6951           (unless (eq nparts (cdr handle))
6952             (mm-destroy-parts (cdr handle))
6953             (setcdr handle nparts))))
6954       (setq point (point))
6955       (gnus-mime-display-security handle)
6956       (goto-char (point-max)))
6957     (when region
6958       (delete-region (point) (cdr region))
6959       (set-marker (car region) nil)
6960       (set-marker (cdr region) nil))
6961     (goto-char point)))
6962
6963 (defun gnus-mime-security-show-details (handle)
6964   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6965     (if (not details)
6966         (gnus-message 5 "No details.")
6967       (if gnus-mime-security-show-details-inline
6968           (let ((gnus-mime-security-button-pressed
6969                  (not (get-text-property (point) 'gnus-mime-details)))
6970                 (gnus-mime-security-button-line-format
6971                  (get-text-property (point) 'gnus-line-format))
6972                 buffer-read-only)
6973             (forward-char -1)
6974             (while (eq (get-text-property (point) 'gnus-line-format)
6975                        gnus-mime-security-button-line-format)
6976               (forward-char -1))
6977             (forward-char)
6978             (save-restriction
6979               (narrow-to-region (point) (point))
6980               (gnus-insert-mime-security-button handle))
6981             (delete-region (point)
6982                            (or (text-property-not-all
6983                                 (point) (point-max)
6984                                 'gnus-line-format
6985                                 gnus-mime-security-button-line-format)
6986                                (point-max))))
6987         ;; Not inlined.
6988         (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6989             (with-current-buffer gnus-mime-security-details-buffer
6990               (erase-buffer)
6991               t)
6992           (setq gnus-mime-security-details-buffer
6993                 (gnus-get-buffer-create "*MIME Security Details*")))
6994         (with-current-buffer gnus-mime-security-details-buffer
6995           (insert details)
6996           (goto-char (point-min)))
6997         (pop-to-buffer gnus-mime-security-details-buffer)))))
6998
6999 (defun gnus-mime-security-press-button (handle)
7000   (save-excursion
7001     (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7002         (gnus-mime-security-show-details handle)
7003       (gnus-mime-security-verify-or-decrypt handle))))
7004
7005 (defun gnus-insert-mime-security-button (handle &optional displayed)
7006   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7007          (gnus-tmp-type
7008           (concat
7009            (or (nth 2 (assoc protocol mm-verify-function-alist))
7010                (nth 2 (assoc protocol mm-decrypt-function-alist))
7011                "Unknown")
7012            (if (equal (car handle) "multipart/signed")
7013                " Signed" " Encrypted")
7014            " Part"))
7015          (gnus-tmp-info
7016           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7017               "Undecided"))
7018          (gnus-tmp-details
7019           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7020          gnus-tmp-pressed-details
7021          b e)
7022     (setq gnus-tmp-details
7023           (if gnus-tmp-details
7024               (concat "\n" gnus-tmp-details)
7025             ""))
7026     (setq gnus-tmp-pressed-details
7027           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7028     (unless (bolp)
7029       (insert "\n"))
7030     (setq b (point))
7031     (gnus-eval-format
7032      gnus-mime-security-button-line-format
7033      gnus-mime-security-button-line-format-alist
7034      `(keymap ,gnus-mime-security-button-map
7035          gnus-callback gnus-mime-security-press-button
7036          gnus-line-format ,gnus-mime-security-button-line-format
7037          gnus-mime-details ,gnus-mime-security-button-pressed
7038          article-type annotation
7039          gnus-data ,handle))
7040     (setq e (if (bolp)
7041                 ;; Exclude a newline.
7042                 (1- (point))
7043               (point)))
7044     (widget-convert-button
7045      'link b e
7046      :mime-handle handle
7047      :action 'gnus-widget-press-button
7048      :button-keymap gnus-mime-security-button-map
7049      :help-echo
7050      (lambda (widget/window &optional overlay pos)
7051        ;; Needed to properly clear the message due to a bug in
7052        ;; wid-edit (XEmacs only).
7053        (when (boundp 'help-echo-owns-message)
7054          (setq help-echo-owns-message t))
7055        (format
7056         "%S: show detail"
7057         (aref gnus-mouse-2 0))))))
7058
7059 (defun gnus-mime-display-security (handle)
7060   (save-restriction
7061     (narrow-to-region (point) (point))
7062     (unless (gnus-unbuttonized-mime-type-p (car handle))
7063       (gnus-insert-mime-security-button handle))
7064     (gnus-mime-display-mixed (cdr handle))
7065     (unless (bolp)
7066       (insert "\n"))
7067     (unless (gnus-unbuttonized-mime-type-p (car handle))
7068       (let ((gnus-mime-security-button-line-format
7069              gnus-mime-security-button-end-line-format))
7070         (gnus-insert-mime-security-button handle)))
7071     (mm-set-handle-multipart-parameter
7072      handle 'gnus-region
7073      (cons (set-marker (make-marker) (point-min))
7074            (set-marker (make-marker) (point-max))))))
7075
7076 (gnus-ems-redefine)
7077
7078 (provide 'gnus-art)
7079
7080 (run-hooks 'gnus-art-load-hook)
7081
7082 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7083 ;;; gnus-art.el ends here