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