Sync up with Pterodactyl Gnus 0.36.
[elisp/gnus.git-] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME
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 (require 'cl))
30
31 (require 'custom)
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'browse-url)
37 (require 'alist)
38 (require 'mime-view)
39
40 (defgroup gnus-article nil
41   "Article display."
42   :link '(custom-manual "(gnus)The Article Buffer")
43   :group 'gnus)
44
45 (defgroup gnus-article-hiding nil
46   "Hiding article parts."
47   :link '(custom-manual "(gnus)Article Hiding")
48   :group 'gnus-article)
49
50 (defgroup gnus-article-highlight nil
51   "Article highlighting."
52   :link '(custom-manual "(gnus)Article Highlighting")
53   :group 'gnus-article
54   :group 'gnus-visual)
55
56 (defgroup gnus-article-signature nil
57   "Article signatures."
58   :link '(custom-manual "(gnus)Article Signature")
59   :group 'gnus-article)
60
61 (defgroup gnus-article-headers nil
62   "Article headers."
63   :link '(custom-manual "(gnus)Hiding Headers")
64   :group 'gnus-article)
65
66 (defgroup gnus-article-washing nil
67   "Special commands on articles."
68   :link '(custom-manual "(gnus)Article Washing")
69   :group 'gnus-article)
70
71 (defgroup gnus-article-emphasis nil
72   "Fontisizing articles."
73   :link '(custom-manual "(gnus)Article Fontisizing")
74   :group 'gnus-article)
75
76 (defgroup gnus-article-saving nil
77   "Saving articles."
78   :link '(custom-manual "(gnus)Saving Articles")
79   :group 'gnus-article)
80
81 (defgroup gnus-article-mime nil
82   "Worshiping the MIME wonder."
83   :link '(custom-manual "(gnus)Using MIME")
84   :group 'gnus-article)
85
86 (defgroup gnus-article-buttons nil
87   "Pushable buttons in the article buffer."
88   :link '(custom-manual "(gnus)Article Buttons")
89   :group 'gnus-article)
90
91 (defgroup gnus-article-various nil
92   "Other article options."
93   :link '(custom-manual "(gnus)Misc Article")
94   :group 'gnus-article)
95
96 (defcustom gnus-ignored-headers
97   '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
98     "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
99     "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
100     "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
101     "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
102     "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
103     "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
104     "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
105     "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
106     "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
107     "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
108     "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
109     "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
110     "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
111     "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
112     "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
113     "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
114     "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
115     "^Status:")
116   "*All headers that start with this regexp will be hidden.
117 This variable can also be a list of regexps of headers to be ignored.
118 If `gnus-visible-headers' is non-nil, this variable will be ignored."
119   :type '(choice :custom-show nil
120                  regexp
121                  (repeat regexp))
122   :group 'gnus-article-hiding)
123
124 (defcustom gnus-visible-headers
125   "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
126   "*All headers that do not match this regexp will be hidden.
127 This variable can also be a list of regexp of headers to remain visible.
128 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
129   :type '(repeat :value-to-internal (lambda (widget value)
130                                       (custom-split-regexp-maybe value))
131                  :match (lambda (widget value)
132                           (or (stringp value)
133                               (widget-editable-list-match widget value)))
134                  regexp)
135   :group 'gnus-article-hiding)
136
137 (defcustom gnus-sorted-header-list
138   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
139     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
140   "*This variable is a list of regular expressions.
141 If it is non-nil, headers that match the regular expressions will
142 be placed first in the article buffer in the sequence specified by
143 this list."
144   :type '(repeat regexp)
145   :group 'gnus-article-hiding)
146
147 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
148   "Headers that are only to be displayed if they have interesting data.
149 Possible values in this list are `empty', `newsgroups', `followup-to',
150 `reply-to', `date', `long-to', and `many-to'."
151   :type '(set (const :tag "Headers with no content." empty)
152               (const :tag "Newsgroups with only one group." newsgroups)
153               (const :tag "Followup-to identical to newsgroups." followup-to)
154               (const :tag "Reply-to identical to from." reply-to)
155               (const :tag "Date less than four days old." date)
156               (const :tag "Very long To header." long-to)
157               (const :tag "Multiple To headers." many-to))
158   :group 'gnus-article-hiding)
159
160 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
161   "Regexp matching signature separator.
162 This can also be a list of regexps.  In that case, it will be checked
163 from head to tail looking for a separator.  Searches will be done from
164 the end of the buffer."
165   :type '(repeat string)
166   :group 'gnus-article-signature)
167
168 (defcustom gnus-signature-limit nil
169    "Provide a limit to what is considered a signature.
170 If it is a number, no signature may not be longer (in characters) than
171 that number.  If it is a floating point number, no signature may be
172 longer (in lines) than that number.  If it is a function, the function
173 will be called without any parameters, and if it returns nil, there is
174 no signature in the buffer.  If it is a string, it will be used as a
175 regexp.  If it matches, the text in question is not a signature."
176   :type '(choice (integer :value 200)
177                  (number :value 4.0)
178                  (function :value fun)
179                  (regexp :value ".*"))
180   :group 'gnus-article-signature)
181
182 (defcustom gnus-hidden-properties '(invisible t intangible t)
183   "Property list to use for hiding text."
184   :type 'sexp
185   :group 'gnus-article-hiding)
186
187 (defcustom gnus-article-x-face-command
188   "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
189   "*String or function to be executed to display an X-Face header.
190 If it is a string, the command will be executed in a sub-shell
191 asynchronously.  The compressed face will be piped to this command."
192   :type 'string                         ;Leave function case to Lisp.
193   :group 'gnus-article-washing)
194
195 (defcustom gnus-article-x-face-too-ugly nil
196   "Regexp matching posters whose face shouldn't be shown automatically."
197   :type '(choice regexp (const nil))
198   :group 'gnus-article-washing)
199
200 (defcustom gnus-emphasis-alist
201   (let ((format
202          "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
203         (types
204          '(("_" "_" underline)
205            ("/" "/" italic)
206            ("\\*" "\\*" bold)
207            ("_/" "/_" underline-italic)
208            ("_\\*" "\\*_" underline-bold)
209            ("\\*/" "/\\*" bold-italic)
210            ("_\\*/" "/\\*_" underline-bold-italic))))
211     `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
212        2 3 gnus-emphasis-underline)
213       ,@(mapcar
214          (lambda (spec)
215            (list
216             (format format (car spec) (cadr spec))
217             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
218          types)))
219   "*Alist that says how to fontify certain phrases.
220 Each item looks like this:
221
222   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
223
224 The first element is a regular expression to be matched.  The second
225 is a number that says what regular expression grouping used to find
226 the entire emphasized word.  The third is a number that says what
227 regexp grouping should be displayed and highlighted.  The fourth
228 is the face used for highlighting."
229   :type '(repeat (list :value ("" 0 0 default)
230                        regexp
231                        (integer :tag "Match group")
232                        (integer :tag "Emphasize group")
233                        face))
234   :group 'gnus-article-emphasis)
235
236 (defface gnus-emphasis-bold '((t (:bold t)))
237   "Face used for displaying strong emphasized text (*word*)."
238   :group 'gnus-article-emphasis)
239
240 (defface gnus-emphasis-italic '((t (:italic t)))
241   "Face used for displaying italic emphasized text (/word/)."
242   :group 'gnus-article-emphasis)
243
244 (defface gnus-emphasis-underline '((t (:underline t)))
245   "Face used for displaying underlined emphasized text (_word_)."
246   :group 'gnus-article-emphasis)
247
248 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
249   "Face used for displaying underlined bold emphasized text (_*word*_)."
250   :group 'gnus-article-emphasis)
251
252 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
253   "Face used for displaying underlined italic emphasized text (_*word*_)."
254   :group 'gnus-article-emphasis)
255
256 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
257   "Face used for displaying bold italic emphasized text (/*word*/)."
258   :group 'gnus-article-emphasis)
259
260 (defface gnus-emphasis-underline-bold-italic
261   '((t (:bold t :italic t :underline t)))
262   "Face used for displaying underlined bold italic emphasized text.
263 Esample: (_/*word*/_)."
264   :group 'gnus-article-emphasis)
265
266 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
267   "Format for display of Date headers in article bodies.
268 See `format-time-string' for the possible values.
269
270 The variable can also be function, which should return a complete Date
271 header.  The function is called with one argument, the time, which can
272 be fed to `format-time-string'."
273   :type '(choice string symbol)
274   :link '(custom-manual "(gnus)Article Date")
275   :group 'gnus-article-washing)
276
277 (eval-and-compile
278   (autoload 'mail-extract-address-components "mail-extr"))
279
280 (defcustom gnus-save-all-headers t
281   "*If non-nil, don't remove any headers before saving."
282   :group 'gnus-article-saving
283   :type 'boolean)
284
285 (defcustom gnus-prompt-before-saving 'always
286   "*This variable says how much prompting is to be done when saving articles.
287 If it is nil, no prompting will be done, and the articles will be
288 saved to the default files.  If this variable is `always', each and
289 every article that is saved will be preceded by a prompt, even when
290 saving large batches of articles.  If this variable is neither nil not
291 `always', there the user will be prompted once for a file name for
292 each invocation of the saving commands."
293   :group 'gnus-article-saving
294   :type '(choice (item always)
295                  (item :tag "never" nil)
296                  (sexp :tag "once" :format "%t\n" :value t)))
297
298 (defcustom gnus-saved-headers gnus-visible-headers
299   "Headers to keep if `gnus-save-all-headers' is nil.
300 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
301 If that variable is nil, however, all headers that match this regexp
302 will be kept while the rest will be deleted before saving."
303   :group 'gnus-article-saving
304   :type 'regexp)
305
306 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
307   "A function to save articles in your favourite format.
308 The function must be interactively callable (in other words, it must
309 be an Emacs command).
310
311 Gnus provides the following functions:
312
313 * gnus-summary-save-in-rmail (Rmail format)
314 * gnus-summary-save-in-mail (Unix mail format)
315 * gnus-summary-save-in-folder (MH folder)
316 * gnus-summary-save-in-file (article format)
317 * gnus-summary-save-in-vm (use VM's folder format)
318 * gnus-summary-write-to-file (article format -- overwrite)."
319   :group 'gnus-article-saving
320   :type '(radio (function-item gnus-summary-save-in-rmail)
321                 (function-item gnus-summary-save-in-mail)
322                 (function-item gnus-summary-save-in-folder)
323                 (function-item gnus-summary-save-in-file)
324                 (function-item gnus-summary-save-in-vm)
325                 (function-item gnus-summary-write-to-file)))
326
327 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
328   "A function generating a file name to save articles in Rmail format.
329 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
330   :group 'gnus-article-saving
331   :type 'function)
332
333 (defcustom gnus-mail-save-name 'gnus-plain-save-name
334   "A function generating a file name to save articles in Unix mail format.
335 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
336   :group 'gnus-article-saving
337   :type 'function)
338
339 (defcustom gnus-folder-save-name 'gnus-folder-save-name
340   "A function generating a file name to save articles in MH folder.
341 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
342   :group 'gnus-article-saving
343   :type 'function)
344
345 (defcustom gnus-file-save-name 'gnus-numeric-save-name
346   "A function generating a file name to save articles in article format.
347 The function is called with NEWSGROUP, HEADERS, and optional
348 LAST-FILE."
349   :group 'gnus-article-saving
350   :type 'function)
351
352 (defcustom gnus-split-methods
353   '((gnus-article-archive-name)
354     (gnus-article-nndoc-name))
355   "*Variable used to suggest where articles are to be saved.
356 For instance, if you would like to save articles related to Gnus in
357 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
358 you could set this variable to something like:
359
360  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
361    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
362
363 This variable is an alist where the where the key is the match and the
364 value is a list of possible files to save in if the match is non-nil.
365
366 If the match is a string, it is used as a regexp match on the
367 article.  If the match is a symbol, that symbol will be funcalled
368 from the buffer of the article to be saved with the newsgroup as the
369 parameter.  If it is a list, it will be evaled in the same buffer.
370
371 If this form or function returns a string, this string will be used as
372 a possible file name; and if it returns a non-nil list, that list will
373 be used as possible file names."
374   :group 'gnus-article-saving
375   :type '(repeat (choice (list :value (fun) function)
376                          (cons :value ("" "") regexp (repeat string))
377                          (sexp :value nil))))
378
379 (defcustom gnus-article-display-method-for-mime
380   'gnus-article-display-mime-message
381   "Function to display a MIME message.
382 The function is called from the article buffer."
383   :group 'gnus-article-mime
384   :type 'function)
385
386 (defcustom gnus-article-display-method-for-encoded-word
387   'gnus-article-display-message-with-encoded-word
388   "*Function to display a message with MIME encoded-words.
389 The function is called from the article buffer."
390   :group 'gnus-article-mime
391   :type 'function)
392
393 (defcustom gnus-article-display-method-for-traditional
394   'gnus-article-display-traditional-message
395   "*Function to display a traditional message.
396 The function is called from the article buffer."
397   :group 'gnus-article-mime
398   :type 'function)
399
400 (defcustom gnus-page-delimiter "^\^L"
401   "*Regexp describing what to use as article page delimiters.
402 The default value is \"^\^L\", which is a form linefeed at the
403 beginning of a line."
404   :type 'regexp
405   :group 'gnus-article-various)
406
407 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
408   "*The format specification for the article mode line.
409 See `gnus-summary-mode-line-format' for a closer description."
410   :type 'string
411   :group 'gnus-article-various)
412
413 (defcustom gnus-article-mode-hook nil
414   "*A hook for Gnus article mode."
415   :type 'hook
416   :group 'gnus-article-various)
417
418 (defcustom gnus-article-menu-hook nil
419   "*Hook run after the creation of the article mode menu."
420   :type 'hook
421   :group 'gnus-article-various)
422
423 (defcustom gnus-article-prepare-hook nil
424   "*A hook called after an article has been prepared in the article buffer.
425 If you want to run a special decoding program like nkf, use this hook."
426   :type 'hook
427   :group 'gnus-article-various)
428
429 (defcustom gnus-article-hide-pgp-hook nil
430   "*A hook called after successfully hiding a PGP signature."
431   :type 'hook
432   :group 'gnus-article-various)
433
434 (defcustom gnus-article-button-face 'bold
435   "Face used for highlighting buttons in the article buffer.
436
437 An article button is a piece of text that you can activate by pressing
438 `RET' or `mouse-2' above it."
439   :type 'face
440   :group 'gnus-article-buttons)
441
442 (defcustom gnus-article-mouse-face 'highlight
443   "Face used for mouse highlighting in the article buffer.
444
445 Article buttons will be displayed in this face when the cursor is
446 above them."
447   :type 'face
448   :group 'gnus-article-buttons)
449
450 (defcustom gnus-signature-face 'gnus-signature-face
451   "Face used for highlighting a signature in the article buffer.
452 Obsolete; use the face `gnus-signature-face' for customizations instead."
453   :type 'face
454   :group 'gnus-article-highlight
455   :group 'gnus-article-signature)
456
457 (defface gnus-signature-face
458   '((((type x))
459      (:italic t)))
460   "Face used for highlighting a signature in the article buffer."
461   :group 'gnus-article-highlight
462   :group 'gnus-article-signature)
463
464 (defface gnus-header-from-face
465   '((((class color)
466       (background dark))
467      (:foreground "spring green"))
468     (((class color)
469       (background light))
470      (:foreground "red3"))
471     (t
472      (:italic t)))
473   "Face used for displaying from headers."
474   :group 'gnus-article-headers
475   :group 'gnus-article-highlight)
476
477 (defface gnus-header-subject-face
478   '((((class color)
479       (background dark))
480      (:foreground "SeaGreen3"))
481     (((class color)
482       (background light))
483      (:foreground "red4"))
484     (t
485      (:bold t :italic t)))
486   "Face used for displaying subject headers."
487   :group 'gnus-article-headers
488   :group 'gnus-article-highlight)
489
490 (defface gnus-header-newsgroups-face
491   '((((class color)
492       (background dark))
493      (:foreground "yellow" :italic t))
494     (((class color)
495       (background light))
496      (:foreground "MidnightBlue" :italic t))
497     (t
498      (:italic t)))
499   "Face used for displaying newsgroups headers."
500   :group 'gnus-article-headers
501   :group 'gnus-article-highlight)
502
503 (defface gnus-header-name-face
504   '((((class color)
505       (background dark))
506      (:foreground "SeaGreen"))
507     (((class color)
508       (background light))
509      (:foreground "maroon"))
510     (t
511      (:bold t)))
512   "Face used for displaying header names."
513   :group 'gnus-article-headers
514   :group 'gnus-article-highlight)
515
516 (defface gnus-header-content-face
517   '((((class color)
518       (background dark))
519      (:foreground "forest green" :italic t))
520     (((class color)
521       (background light))
522      (:foreground "indianred4" :italic t))
523     (t
524      (:italic t)))  "Face used for displaying header content."
525   :group 'gnus-article-headers
526   :group 'gnus-article-highlight)
527
528 (defcustom gnus-header-face-alist
529   '(("From" nil gnus-header-from-face)
530     ("Subject" nil gnus-header-subject-face)
531     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
532     ("" gnus-header-name-face gnus-header-content-face))
533   "*Controls highlighting of article header.
534
535 An alist of the form (HEADER NAME CONTENT).
536
537 HEADER is a regular expression which should match the name of an
538 header header and NAME and CONTENT are either face names or nil.
539
540 The name of each header field will be displayed using the face
541 specified by the first element in the list where HEADER match the
542 header name and NAME is non-nil.  Similarly, the content will be
543 displayed by the first non-nil matching CONTENT face."
544   :group 'gnus-article-headers
545   :group 'gnus-article-highlight
546   :type '(repeat (list (regexp :tag "Header")
547                        (choice :tag "Name"
548                                (item :tag "skip" nil)
549                                (face :value default))
550                        (choice :tag "Content"
551                                (item :tag "skip" nil)
552                                (face :value default)))))
553
554 (defcustom gnus-article-decode-hook nil
555   "*Hook run to decode charsets in articles."
556   :group 'gnus-article-headers
557   :type 'hook)
558
559 (defcustom gnus-display-mime-function 'gnus-display-mime
560   "Function to display MIME articles."
561   :group 'gnus-article-headers
562   :type 'function)
563
564 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
565   "Function used to decode headers.")
566
567 (defvar gnus-article-dumbquotes-map
568   '(("\202" ",")
569     ("\203" "f")
570     ("\204" ",,")
571     ("\213" "<")
572     ("\214" "OE")
573     ("\205" "...")
574     ("\221" "`")
575     ("\222" "'")
576     ("\223" "``")
577     ("\224" "''")
578     ("\225" "*")
579     ("\226" "-")
580     ("\227" "-")
581     ("\231" "(TM)")
582     ("\233" ">")
583     ("\234" "oe")
584     ("\264" "'"))
585   "Table for MS-to-Latin1 translation.")
586
587 ;;; Internal variables
588
589 (defvar gnus-article-mime-handle-alist nil)
590 (defvar article-lapsed-timer nil)
591 (defvar gnus-article-current-summary nil)
592
593 (defvar gnus-article-mode-syntax-table
594   (let ((table (copy-syntax-table text-mode-syntax-table)))
595     (modify-syntax-entry ?- "w" table)
596     (modify-syntax-entry ?> ")" table)
597     (modify-syntax-entry ?< "(" table)
598     table)
599   "Syntax table used in article mode buffers.
600 Initialized from `text-mode-syntax-table.")
601
602 (defvar gnus-save-article-buffer nil)
603
604 (defvar gnus-article-mode-line-format-alist
605   (nconc '((?w (gnus-article-wash-status) ?s))
606          gnus-summary-mode-line-format-alist))
607
608 (defvar gnus-number-of-articles-to-be-saved nil)
609
610 (defvar gnus-inhibit-hiding nil)
611
612 (defsubst gnus-article-hide-text (b e props)
613   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
614   (add-text-properties b e props)
615   (when (memq 'intangible props)
616     (put-text-property
617      (max (1- b) (point-min))
618      b 'intangible (cddr (memq 'intangible props)))))
619
620 (defsubst gnus-article-unhide-text (b e)
621   "Remove hidden text properties from region between B and E."
622   (remove-text-properties b e gnus-hidden-properties)
623   (when (memq 'intangible gnus-hidden-properties)
624     (put-text-property (max (1- b) (point-min))
625                        b 'intangible nil)))
626
627 (defun gnus-article-hide-text-type (b e type)
628   "Hide text of TYPE between B and E."
629   (gnus-article-hide-text
630    b e (cons 'article-type (cons type gnus-hidden-properties))))
631
632 (defun gnus-article-unhide-text-type (b e type)
633   "Unhide text of TYPE between B and E."
634   (remove-text-properties
635    b e (cons 'article-type (cons type gnus-hidden-properties)))
636   (when (memq 'intangible gnus-hidden-properties)
637     (put-text-property (max (1- b) (point-min))
638                        b 'intangible nil)))
639
640 (defun gnus-article-hide-text-of-type (type)
641   "Hide text of TYPE in the current buffer."
642   (save-excursion
643     (let ((b (point-min))
644           (e (point-max)))
645       (while (setq b (text-property-any b e 'article-type type))
646         (add-text-properties b (incf b) gnus-hidden-properties)))))
647
648 (defun gnus-article-delete-text-of-type (type)
649   "Delete text of TYPE in the current buffer."
650   (save-excursion
651     (let ((b (point-min)))
652       (while (setq b (text-property-any b (point-max) 'article-type type))
653         (delete-region
654          b (or (text-property-not-all b (point-max) 'article-type type)
655                (point-max)))))))
656
657 (defun gnus-article-delete-invisible-text ()
658   "Delete all invisible text in the current buffer."
659   (save-excursion
660     (let ((b (point-min)))
661       (while (setq b (text-property-any b (point-max) 'invisible t))
662         (delete-region
663          b (or (text-property-not-all b (point-max) 'invisible t)
664                (point-max)))))))
665
666 (defun gnus-article-text-type-exists-p (type)
667   "Say whether any text of type TYPE exists in the buffer."
668   (text-property-any (point-min) (point-max) 'article-type type))
669
670 (defsubst gnus-article-header-rank ()
671   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
672   (let ((list gnus-sorted-header-list)
673         (i 0))
674     (while list
675       (when (looking-at (car list))
676         (setq list nil))
677       (setq list (cdr list))
678       (incf i))
679     i))
680
681 (defun article-hide-headers (&optional arg delete)
682   "Toggle whether to hide unwanted headers and possibly sort them as well.
683 If given a negative prefix, always show; if given a positive prefix,
684 always hide."
685   (interactive (gnus-article-hidden-arg))
686   (current-buffer)
687   (if (gnus-article-check-hidden-text 'headers arg)
688       ;; Show boring headers as well.
689       (gnus-article-show-hidden-text 'boring-headers)
690     ;; This function might be inhibited.
691     (unless gnus-inhibit-hiding
692       (save-excursion
693         (save-restriction
694           (let ((buffer-read-only nil)
695                 (case-fold-search t)
696                 (props (nconc (list 'article-type 'headers)
697                               gnus-hidden-properties))
698                 (max (1+ (length gnus-sorted-header-list)))
699                 (ignored (when (not gnus-visible-headers)
700                            (cond ((stringp gnus-ignored-headers)
701                                   gnus-ignored-headers)
702                                  ((listp gnus-ignored-headers)
703                                   (mapconcat 'identity gnus-ignored-headers
704                                              "\\|")))))
705                 (visible
706                  (cond ((stringp gnus-visible-headers)
707                         gnus-visible-headers)
708                        ((and gnus-visible-headers
709                              (listp gnus-visible-headers))
710                         (mapconcat 'identity gnus-visible-headers "\\|"))))
711                 (inhibit-point-motion-hooks t)
712                 beg)
713             ;; First we narrow to just the headers.
714             (widen)
715             (goto-char (point-min))
716             ;; Hide any "From " lines at the beginning of (mail) articles.
717             (while (looking-at "From ")
718               (forward-line 1))
719             (unless (bobp)
720               (if delete
721                   (delete-region (point-min) (point))
722                 (gnus-article-hide-text (point-min) (point) props)))
723             ;; Then treat the rest of the header lines.
724             (narrow-to-region
725              (point)
726              (if (search-forward "\n\n" nil t) ; if there's a body
727                  (progn (forward-line -1) (point))
728                (point-max)))
729             ;; Then we use the two regular expressions
730             ;; `gnus-ignored-headers' and `gnus-visible-headers' to
731             ;; select which header lines is to remain visible in the
732             ;; article buffer.
733             (goto-char (point-min))
734             (while (re-search-forward "^[^ \t]*:" nil t)
735               (beginning-of-line)
736               ;; Mark the rank of the header.
737               (put-text-property
738                (point) (1+ (point)) 'message-rank
739                (if (or (and visible (looking-at visible))
740                        (and ignored
741                             (not (looking-at ignored))))
742                    (gnus-article-header-rank)
743                  (+ 2 max)))
744               (forward-line 1))
745             (message-sort-headers-1)
746             (when (setq beg (text-property-any
747                              (point-min) (point-max) 'message-rank (+ 2 max)))
748               ;; We make the unwanted headers invisible.
749               (if delete
750                   (delete-region beg (point-max))
751                 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
752                 (gnus-article-hide-text-type beg (point-max) 'headers))
753               ;; Work around XEmacs lossage.
754               (put-text-property (point-min) beg 'invisible nil))))))))
755
756 (defun article-hide-boring-headers (&optional arg)
757   "Toggle hiding of headers that aren't very interesting.
758 If given a negative prefix, always show; if given a positive prefix,
759 always hide."
760   (interactive (gnus-article-hidden-arg))
761   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
762              (not gnus-show-all-headers))
763     (save-excursion
764       (save-restriction
765         (let ((buffer-read-only nil)
766               (list gnus-boring-article-headers)
767               (inhibit-point-motion-hooks t)
768               elem)
769           (nnheader-narrow-to-headers)
770           (while list
771             (setq elem (pop list))
772             (goto-char (point-min))
773             (cond
774              ;; Hide empty headers.
775              ((eq elem 'empty)
776               (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
777                 (forward-line -1)
778                 (gnus-article-hide-text-type
779                  (progn (beginning-of-line) (point))
780                  (progn
781                    (end-of-line)
782                    (if (re-search-forward "^[^ \t]" nil t)
783                        (match-beginning 0)
784                      (point-max)))
785                  'boring-headers)))
786              ;; Hide boring Newsgroups header.
787              ((eq elem 'newsgroups)
788               (when (equal (gnus-fetch-field "newsgroups")
789                            (gnus-group-real-name
790                             (if (boundp 'gnus-newsgroup-name)
791                                 gnus-newsgroup-name
792                               "")))
793                 (gnus-article-hide-header "newsgroups")))
794              ((eq elem 'followup-to)
795               (when (equal (message-fetch-field "followup-to")
796                            (message-fetch-field "newsgroups"))
797                 (gnus-article-hide-header "followup-to")))
798              ((eq elem 'reply-to)
799               (let ((from (message-fetch-field "from"))
800                     (reply-to (message-fetch-field "reply-to")))
801                 (when (and
802                        from reply-to
803                        (ignore-errors
804                          (equal
805                           (nth 1 (funcall gnus-extract-address-components from))
806                           (nth 1 (funcall gnus-extract-address-components reply-to)))))
807                   (gnus-article-hide-header "reply-to"))))
808              ((eq elem 'date)
809               (let ((date (message-fetch-field "date")))
810                 (when (and date
811                            (< (days-between (current-time-string) date)
812                               4))
813                   (gnus-article-hide-header "date"))))
814              ((eq elem 'long-to)
815               (let ((to (message-fetch-field "to")))
816                 (when (> (length to) 1024)
817                   (gnus-article-hide-header "to"))))
818              ((eq elem 'many-to)
819               (let ((to-count 0))
820                 (goto-char (point-min))
821                 (while (re-search-forward "^to:" nil t)
822                   (setq to-count (1+ to-count)))
823                 (when (> to-count 1)
824                   (while (> to-count 0)
825                     (goto-char (point-min))
826                     (save-restriction
827                       (re-search-forward "^to:" nil nil to-count)
828                       (forward-line -1)
829                       (narrow-to-region (point) (point-max))
830                       (gnus-article-hide-header "to"))
831                     (setq to-count (1- to-count)))))))))))))
832
833 (defun gnus-article-hide-header (header)
834   (save-excursion
835     (goto-char (point-min))
836     (when (re-search-forward (concat "^" header ":") nil t)
837       (gnus-article-hide-text-type
838        (progn (beginning-of-line) (point))
839        (progn
840          (end-of-line)
841          (if (re-search-forward "^[^ \t]" nil t)
842              (match-beginning 0)
843            (point-max)))
844        'boring-headers))))
845
846 (defun article-treat-dumbquotes ()
847   "Translate M******** sm*rtq**t*s into proper text."
848   (interactive)
849   (article-translate-strings gnus-article-dumbquotes-map))
850
851 (defun article-translate-characters (from to)
852   "Translate all characters in the body of the article according to FROM and TO.
853 FROM is a string of characters to translate from; to is a string of
854 characters to translate to."
855   (save-excursion
856     (goto-char (point-min))
857     (when (search-forward "\n\n" nil t)
858       (let ((buffer-read-only nil)
859             (x (make-string 225 ?x))
860             (i -1))
861         (while (< (incf i) (length x))
862           (aset x i i))
863         (setq i 0)
864         (while (< i (length from))
865           (aset x (aref from i) (aref to i))
866           (incf i))
867         (translate-region (point) (point-max) x)))))
868
869 (defun article-translate-strings (map)
870   "Translate all string in the body of the article according to MAP.
871 MAP is an alist where the elements are on the form (\"from\" \"to\")."
872   (save-excursion
873     (goto-char (point-min))
874     (when (search-forward "\n\n" nil t)
875       (let ((buffer-read-only nil)
876             elem)
877         (while (setq elem (pop map))
878           (save-excursion
879             (while (search-forward (car elem) nil t)
880               (replace-match (cadr elem)))))))))
881
882 (defun article-treat-overstrike ()
883   "Translate overstrikes into bold text."
884   (interactive)
885   (save-excursion
886     (goto-char (point-min))
887     (when (search-forward "\n\n" nil t)
888       (let ((buffer-read-only nil))
889         (while (search-forward "\b" nil t)
890           (let ((next (following-char))
891                 (previous (char-after (- (point) 2))))
892             ;; We do the boldification/underlining by hiding the
893             ;; overstrikes and putting the proper text property
894             ;; on the letters.
895             (cond
896              ((eq next previous)
897               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
898               (put-text-property (point) (1+ (point)) 'face 'bold))
899              ((eq next ?_)
900               (gnus-article-hide-text-type
901                (1- (point)) (1+ (point)) 'overstrike)
902               (put-text-property
903                (- (point) 2) (1- (point)) 'face 'underline))
904              ((eq previous ?_)
905               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
906               (put-text-property
907                (point) (1+ (point)) 'face 'underline)))))))))
908
909 (defun article-fill ()
910   "Format too long lines."
911   (interactive)
912   (save-excursion
913     (let ((buffer-read-only nil))
914       (widen)
915       (goto-char (point-min))
916       (search-forward "\n\n" nil t)
917       (end-of-line 1)
918       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
919             (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
920             (adaptive-fill-mode t))
921         (while (not (eobp))
922           (and (>= (current-column) (min fill-column (window-width)))
923                (/= (preceding-char) ?:)
924                (fill-paragraph nil))
925           (end-of-line 2))))))
926
927 (defun article-remove-cr ()
928   "Remove carriage returns from an article."
929   (interactive)
930   (save-excursion
931     (let ((buffer-read-only nil))
932       (goto-char (point-min))
933       (while (search-forward "\r" nil t)
934         (replace-match "" t t)))))
935
936 (defun article-remove-trailing-blank-lines ()
937   "Remove all trailing blank lines from the article."
938   (interactive)
939   (save-excursion
940     (let ((buffer-read-only nil))
941       (goto-char (point-max))
942       (delete-region
943        (point)
944        (progn
945          (while (and (not (bobp))
946                      (looking-at "^[ \t]*$")
947                      (not (gnus-annotation-in-region-p
948                            (point) (gnus-point-at-eol))))
949            (forward-line -1))
950          (forward-line 1)
951          (point))))))
952
953 (defun article-display-x-face (&optional force)
954   "Look for an X-Face header and display it if present."
955   (interactive (list 'force))
956   (save-excursion
957     ;; Delete the old process, if any.
958     (when (process-status "article-x-face")
959       (delete-process "article-x-face"))
960     (let ((inhibit-point-motion-hooks t)
961           (case-fold-search t)
962           from last)
963       (save-restriction
964         (nnheader-narrow-to-headers)
965         (setq from (message-fetch-field "from"))
966         (goto-char (point-min))
967         (while (and gnus-article-x-face-command
968                     (not last)
969                     (or force
970                         ;; Check whether this face is censored.
971                         (not gnus-article-x-face-too-ugly)
972                         (and gnus-article-x-face-too-ugly from
973                              (not (string-match gnus-article-x-face-too-ugly
974                                                 from))))
975                     ;; Has to be present.
976                     (re-search-forward "^X-Face: " nil t))
977           ;; This used to try to do multiple faces (`while' instead of
978           ;; `when' above), but (a) sending multiple EOFs to xv doesn't
979           ;; work (b) it can crash some versions of Emacs (c) are
980           ;; multiple faces really something to encourage?
981           (when (stringp gnus-article-x-face-command)
982             (setq last t))
983           ;; We now have the area of the buffer where the X-Face is stored.
984           (save-excursion
985             (let ((beg (point))
986                   (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
987               ;; We display the face.
988               (if (symbolp gnus-article-x-face-command)
989                   ;; The command is a lisp function, so we call it.
990                   (if (gnus-functionp gnus-article-x-face-command)
991                       (funcall gnus-article-x-face-command beg end)
992                     (error "%s is not a function" gnus-article-x-face-command))
993                 ;; The command is a string, so we interpret the command
994                 ;; as a, well, command, and fork it off.
995                 (let ((process-connection-type nil))
996                   (process-kill-without-query
997                    (start-process
998                     "article-x-face" nil shell-file-name shell-command-switch
999                     gnus-article-x-face-command))
1000                   (process-send-region "article-x-face" beg end)
1001                   (process-send-eof "article-x-face"))))))))))
1002
1003 (defun article-decode-mime-words ()
1004   "Decode all MIME-encoded words in the article."
1005   (interactive)
1006   (save-excursion
1007     (set-buffer gnus-article-buffer)
1008     (let ((inhibit-point-motion-hooks t)
1009           buffer-read-only)
1010       (mail-decode-encoded-word-region (point-min) (point-max)))))
1011
1012 (defun article-decode-charset (&optional prompt)
1013   "Decode charset-encoded text in the article.
1014 If PROMPT (the prefix), prompt for a coding system to use."
1015   (interactive "P")
1016   (save-excursion
1017     (save-restriction
1018       (message-narrow-to-head)
1019       (let* ((inhibit-point-motion-hooks t)
1020              (case-fold-search t)
1021              (ct (message-fetch-field "Content-Type" t))
1022              (cte (message-fetch-field "Content-Transfer-Encoding" t))
1023              (ctl (and ct (condition-case ()
1024                               (mail-header-parse-content-type ct)
1025                             (error nil))))
1026              (charset (cond
1027                        (prompt
1028                         (mm-read-coding-system "Charset to decode: "))
1029                        (ctl
1030                         (mail-content-type-get ctl 'charset))
1031                        (gnus-newsgroup-name
1032                         (gnus-group-find-parameter
1033                          gnus-newsgroup-name 'charset))))
1034              buffer-read-only)
1035         (goto-char (point-max))
1036         (widen)
1037         (forward-line 1)
1038         (narrow-to-region (point) (point-max))
1039         (when (or (not ct)
1040                   (equal (car ctl) "text/plain"))
1041           (mm-decode-body
1042            charset (and cte (intern (downcase
1043                                      (gnus-strip-whitespace cte))))))))))
1044
1045 (defun article-decode-encoded-words ()
1046   "Remove encoded-word encoding from headers."
1047   (let (buffer-read-only)
1048     (let ((charset (save-excursion
1049                      (set-buffer gnus-summary-buffer)
1050                      default-mime-charset)))
1051       (eword-decode-header charset)
1052       )))
1053
1054 (defun article-de-quoted-unreadable (&optional force)
1055   "Translate a quoted-printable-encoded article.
1056 If FORCE, decode the article whether it is marked as quoted-printable
1057 or not."
1058   (interactive (list 'force))
1059   (save-excursion
1060     (let ((buffer-read-only nil)
1061           (type (gnus-fetch-field "content-transfer-encoding")))
1062       (when (or force
1063                 (and type (string-match "quoted-printable" (downcase type))))
1064         (goto-char (point-min))
1065         (search-forward "\n\n" nil 'move)
1066         (quoted-printable-decode-region (point) (point-max))
1067         (when mm-default-coding-system
1068           (mm-decode-body mm-default-coding-system))))))
1069
1070 (defun article-mime-decode-quoted-printable-buffer ()
1071   "Decode Quoted-Printable in the current buffer."
1072   (quoted-printable-decode-region (point-min) (point-max)))
1073
1074 (defun article-hide-pgp (&optional arg)
1075   "Toggle hiding of any PGP headers and signatures in the current article.
1076 If given a negative prefix, always show; if given a positive prefix,
1077 always hide."
1078   (interactive (gnus-article-hidden-arg))
1079   (unless (gnus-article-check-hidden-text 'pgp arg)
1080     (save-excursion
1081       (let ((inhibit-point-motion-hooks t)
1082             buffer-read-only beg end)
1083         (widen)
1084         (goto-char (point-min))
1085         ;; Hide the "header".
1086         (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1087           (delete-region (1+ (match-beginning 0)) (match-end 0))
1088           ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1089           (when (looking-at "Hash:.*$")
1090             (delete-region (point) (1+ (gnus-point-at-eol))))
1091           (setq beg (point))
1092           ;; Hide the actual signature.
1093           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1094                (setq end (1+ (match-beginning 0)))
1095                (delete-region
1096                 end
1097                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1098                     (match-end 0)
1099                   ;; Perhaps we shouldn't hide to the end of the buffer
1100                   ;; if there is no end to the signature?
1101                   (point-max))))
1102           ;; Hide "- " PGP quotation markers.
1103           (when (and beg end)
1104             (narrow-to-region beg end)
1105             (goto-char (point-min))
1106             (while (re-search-forward "^- " nil t)
1107               (delete-region
1108                (match-beginning 0) (match-end 0)))
1109             (widen))
1110           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1111
1112 (defun article-hide-pem (&optional arg)
1113   "Toggle hiding of any PEM headers and signatures in the current article.
1114 If given a negative prefix, always show; if given a positive prefix,
1115 always hide."
1116   (interactive (gnus-article-hidden-arg))
1117   (unless (gnus-article-check-hidden-text 'pem arg)
1118     (save-excursion
1119       (let (buffer-read-only end)
1120         (widen)
1121         (goto-char (point-min))
1122         ;; hide the horrendously ugly "header".
1123         (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1124                              nil
1125                              t)
1126              (setq end (1+ (match-beginning 0)))
1127              (gnus-article-hide-text-type
1128               end
1129               (if (search-forward "\n\n" nil t)
1130                   (match-end 0)
1131                 (point-max))
1132               'pem))
1133         ;; hide the trailer as well
1134         (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1135                              nil
1136                              t)
1137              (gnus-article-hide-text-type
1138               (match-beginning 0) (match-end 0) 'pem))))))
1139
1140 (defun article-hide-signature (&optional arg)
1141   "Hide the signature in the current article.
1142 If given a negative prefix, always show; if given a positive prefix,
1143 always hide."
1144   (interactive (gnus-article-hidden-arg))
1145   (unless (gnus-article-check-hidden-text 'signature arg)
1146     (save-excursion
1147       (save-restriction
1148         (let ((buffer-read-only nil))
1149           (when (gnus-article-narrow-to-signature)
1150             (gnus-article-hide-text-type
1151              (point-min) (point-max) 'signature)))))))
1152
1153 (defun article-strip-leading-blank-lines ()
1154   "Remove all blank lines from the beginning of the article."
1155   (interactive)
1156   (save-excursion
1157     (let ((inhibit-point-motion-hooks t)
1158           buffer-read-only)
1159       (goto-char (point-min))
1160       (when (search-forward "\n\n" nil t)
1161         (while (and (not (eobp))
1162                     (looking-at "[ \t]*$"))
1163           (gnus-delete-line))))))
1164
1165 (defun article-strip-multiple-blank-lines ()
1166   "Replace consecutive blank lines with one empty line."
1167   (interactive)
1168   (save-excursion
1169     (let ((inhibit-point-motion-hooks t)
1170           buffer-read-only)
1171       ;; First make all blank lines empty.
1172       (goto-char (point-min))
1173       (search-forward "\n\n" nil t)
1174       (while (re-search-forward "^[ \t]+$" nil t)
1175         (unless (gnus-annotation-in-region-p
1176                  (match-beginning 0) (match-end 0))
1177           (replace-match "" nil t)))
1178       ;; Then replace multiple empty lines with a single empty line.
1179       (goto-char (point-min))
1180       (search-forward "\n\n" nil t)
1181       (while (re-search-forward "\n\n\n+" nil t)
1182         (unless (gnus-annotation-in-region-p
1183                  (match-beginning 0) (match-end 0))
1184           (replace-match "\n\n" t t))))))
1185
1186 (defun article-strip-leading-space ()
1187   "Remove all white space from the beginning of the lines in the article."
1188   (interactive)
1189   (save-excursion
1190     (let ((inhibit-point-motion-hooks t)
1191           buffer-read-only)
1192       (goto-char (point-min))
1193       (search-forward "\n\n" nil t)
1194       (while (re-search-forward "^[ \t]+" nil t)
1195         (replace-match "" t t)))))
1196
1197 (defun article-strip-blank-lines ()
1198   "Strip leading, trailing and multiple blank lines."
1199   (interactive)
1200   (article-strip-leading-blank-lines)
1201   (article-remove-trailing-blank-lines)
1202   (article-strip-multiple-blank-lines))
1203
1204 (defun article-strip-all-blank-lines ()
1205   "Strip all blank lines."
1206   (interactive)
1207   (save-excursion
1208     (let ((inhibit-point-motion-hooks t)
1209           buffer-read-only)
1210       (goto-char (point-min))
1211       (search-forward "\n\n" nil t)
1212       (while (re-search-forward "^[ \t]*\n" nil t)
1213         (replace-match "" t t)))))
1214
1215 (defun gnus-article-narrow-to-signature ()
1216   "Narrow to the signature; return t if a signature is found, else nil."
1217   (widen)
1218   (let ((inhibit-point-motion-hooks t))
1219     (when (gnus-article-search-signature)
1220       (forward-line 1)
1221       ;; Check whether we have some limits to what we consider
1222       ;; to be a signature.
1223       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1224                       (list gnus-signature-limit)))
1225             limit limited)
1226         (while (setq limit (pop limits))
1227           (if (or (and (integerp limit)
1228                        (< (- (point-max) (point)) limit))
1229                   (and (floatp limit)
1230                        (< (count-lines (point) (point-max)) limit))
1231                   (and (gnus-functionp limit)
1232                        (funcall limit))
1233                   (and (stringp limit)
1234                        (not (re-search-forward limit nil t))))
1235               ()                        ; This limit did not succeed.
1236             (setq limited t
1237                   limits nil)))
1238         (unless limited
1239           (narrow-to-region (point) (point-max))
1240           t)))))
1241
1242 (defun gnus-article-search-signature ()
1243   "Search the current buffer for the signature separator.
1244 Put point at the beginning of the signature separator."
1245   (let ((cur (point)))
1246     (goto-char (point-max))
1247     (if (if (stringp gnus-signature-separator)
1248             (re-search-backward gnus-signature-separator nil t)
1249           (let ((seps gnus-signature-separator))
1250             (while (and seps
1251                         (not (re-search-backward (car seps) nil t)))
1252               (pop seps))
1253             seps))
1254         t
1255       (goto-char cur)
1256       nil)))
1257
1258 (eval-and-compile
1259   (autoload 'w3-display "w3-parse")
1260   (autoload 'w3-do-setup "w3" "" t)
1261   (autoload 'w3-region "w3-display" "" t))
1262
1263 (defun gnus-article-treat-html ()
1264   "Render HTML."
1265   (interactive)
1266   (let ((cbuf (current-buffer)))
1267     (set-buffer gnus-article-buffer)
1268     (let (buf buffer-read-only b e)
1269       (w3-do-setup)
1270       (goto-char (point-min))
1271       (narrow-to-region
1272        (if (search-forward "\n\n" nil t)
1273            (setq b (point))
1274          (point-max))
1275        (setq e (point-max)))
1276       (with-temp-buffer
1277         (insert-buffer-substring gnus-article-buffer b e)
1278         (require 'url)
1279         (save-window-excursion
1280           (w3-region (point-min) (point-max))
1281           (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1282       (when buf
1283         (delete-region (point-min) (point-max))
1284         (insert buf))
1285       (widen)
1286       (goto-char (point-min))
1287       (set-window-start (get-buffer-window (current-buffer)) (point-min))
1288       (set-buffer cbuf))))
1289
1290 (defun gnus-article-hidden-arg ()
1291   "Return the current prefix arg as a number, or 0 if no prefix."
1292   (list (if current-prefix-arg
1293             (prefix-numeric-value current-prefix-arg)
1294           0)))
1295
1296 (defun gnus-article-check-hidden-text (type arg)
1297   "Return nil if hiding is necessary.
1298 Arg can be nil or a number.  Nil and positive means hide, negative
1299 means show, 0 means toggle."
1300   (save-excursion
1301     (save-restriction
1302       (widen)
1303       (let ((hide (gnus-article-hidden-text-p type)))
1304         (cond
1305          ((or (null arg)
1306               (> arg 0))
1307           nil)
1308          ((< arg 0)
1309           (gnus-article-show-hidden-text type))
1310          (t
1311           (if (eq hide 'hidden)
1312               (gnus-article-show-hidden-text type)
1313             nil)))))))
1314
1315 (defun gnus-article-hidden-text-p (type)
1316   "Say whether the current buffer contains hidden text of type TYPE."
1317   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1318     (while (and pos
1319                 (not (get-text-property pos 'invisible)))
1320       (setq pos
1321             (text-property-any (1+ pos) (point-max) 'article-type type)))
1322     (if pos
1323         'hidden
1324       'shown)))
1325
1326 (defun gnus-article-show-hidden-text (type &optional hide)
1327   "Show all hidden text of type TYPE.
1328 If HIDE, hide the text instead."
1329   (save-excursion
1330     (let ((buffer-read-only nil)
1331           (inhibit-point-motion-hooks t)
1332           (end (point-min))
1333           beg)
1334       (while (setq beg (text-property-any end (point-max) 'article-type type))
1335         (goto-char beg)
1336         (setq end (or
1337                    (text-property-not-all beg (point-max) 'article-type type)
1338                    (point-max)))
1339         (if hide
1340             (gnus-article-hide-text beg end gnus-hidden-properties)
1341           (gnus-article-unhide-text beg end))
1342         (goto-char end))
1343       t)))
1344
1345 (defconst article-time-units
1346   `((year . ,(* 365.25 24 60 60))
1347     (week . ,(* 7 24 60 60))
1348     (day . ,(* 24 60 60))
1349     (hour . ,(* 60 60))
1350     (minute . 60)
1351     (second . 1))
1352   "Mapping from time units to seconds.")
1353
1354 (defun article-date-ut (&optional type highlight header)
1355   "Convert DATE date to universal time in the current article.
1356 If TYPE is `local', convert to local time; if it is `lapsed', output
1357 how much time has lapsed since DATE."
1358   (interactive (list 'ut t))
1359   (let* ((header (or header
1360                      (mail-header-date gnus-current-headers)
1361                      (message-fetch-field "date")
1362                      ""))
1363          (date (if (vectorp header) (mail-header-date header)
1364                  header))
1365          (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1366          (inhibit-point-motion-hooks t)
1367          bface eface newline)
1368     (when (and date (not (string= date "")))
1369       (save-excursion
1370         (save-restriction
1371           (nnheader-narrow-to-headers)
1372           (let ((buffer-read-only nil))
1373             ;; Delete any old Date headers.
1374             (if (re-search-forward date-regexp nil t)
1375                 (progn
1376                   (setq bface (get-text-property (gnus-point-at-bol) 'face)
1377                         eface (get-text-property (1- (gnus-point-at-eol))
1378                                                  'face))
1379                   (delete-region (progn (beginning-of-line) (point))
1380                                  (progn (end-of-line) (point)))
1381                   (beginning-of-line))
1382               (goto-char (point-max))
1383               (setq newline t))
1384             (insert (article-make-date-line date type))
1385             ;; Do highlighting.
1386             (beginning-of-line)
1387             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1388               (put-text-property (match-beginning 1) (1+ (match-end 1))
1389                                  'face bface)
1390               (put-text-property (match-beginning 2) (match-end 2)
1391                                  'face eface))
1392             (when newline
1393               (end-of-line)
1394               (insert "\n"))))))))
1395
1396 (defun article-make-date-line (date type)
1397   "Return a DATE line of TYPE."
1398   (let ((time (condition-case ()
1399                   (date-to-time date)
1400                 (error '(0 0)))))
1401     (cond
1402      ;; Convert to the local timezone.  We have to slap a
1403      ;; `condition-case' round the calls to the timezone
1404      ;; functions since they aren't particularly resistant to
1405      ;; buggy dates.
1406      ((eq type 'local)
1407       (let ((tz (car (current-time-zone))))
1408         (format "Date: %s %s%04d" (current-time-string time)
1409                 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1410      ;; Convert to Universal Time.
1411      ((eq type 'ut)
1412       (concat "Date: "
1413               (current-time-string
1414                (let* ((e (parse-time-string date))
1415                      (tm (apply 'encode-time e))
1416                      (ms (car tm))
1417                      (ls (- (cadr tm) (car (current-time-zone)))))
1418                  (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1419                        ((> ls 65535) (list (1+ ms) (- ls 65536)))
1420                        (t (list ms ls)))))
1421               " UT"))
1422      ;; Get the original date from the article.
1423      ((eq type 'original)
1424       (concat "Date: " (if (string-match "\n+$" date)
1425                            (substring date 0 (match-beginning 0))
1426                          date)))
1427      ;; Let the user define the format.
1428      ((eq type 'user)
1429       (if (gnus-functionp gnus-article-time-format)
1430           (funcall gnus-article-time-format time)
1431         (concat
1432          "Date: "
1433          (format-time-string gnus-article-time-format time))))
1434      ;; ISO 8601.
1435      ((eq type 'iso8601)
1436       (concat
1437        "Date: "
1438        (format-time-string "%Y%M%DT%h%m%s" time)))
1439      ;; Do an X-Sent lapsed format.
1440      ((eq type 'lapsed)
1441       ;; If the date is seriously mangled, the timezone functions are
1442       ;; liable to bug out, so we ignore all errors.
1443       (let* ((now (current-time))
1444              (real-time (subtract-time now time))
1445              (real-sec (and real-time
1446                             (+ (* (float (car real-time)) 65536)
1447                                (cadr real-time))))
1448              (sec (and real-time (abs real-sec)))
1449              num prev)
1450         (cond
1451          ((null real-time)
1452           "X-Sent: Unknown")
1453          ((zerop sec)
1454           "X-Sent: Now")
1455          (t
1456           (concat
1457            "X-Sent: "
1458            ;; This is a bit convoluted, but basically we go
1459            ;; through the time units for years, weeks, etc,
1460            ;; and divide things to see whether that results
1461            ;; in positive answers.
1462            (mapconcat
1463             (lambda (unit)
1464               (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1465                   ;; The (remaining) seconds are too few to
1466                   ;; be divided into this time unit.
1467                   ""
1468                 ;; It's big enough, so we output it.
1469                 (setq sec (- sec (* num (cdr unit))))
1470                 (prog1
1471                     (concat (if prev ", " "") (int-to-string
1472                                                (floor num))
1473                             " " (symbol-name (car unit))
1474                             (if (> num 1) "s" ""))
1475                   (setq prev t))))
1476             article-time-units "")
1477            ;; If dates are odd, then it might appear like the
1478            ;; article was sent in the future.
1479            (if (> real-sec 0)
1480                " ago"
1481              " in the future"))))))
1482      (t
1483       (error "Unknown conversion type: %s" type)))))
1484
1485 (defun article-date-local (&optional highlight)
1486   "Convert the current article date to the local timezone."
1487   (interactive (list t))
1488   (article-date-ut 'local highlight))
1489
1490 (defun article-date-original (&optional highlight)
1491   "Convert the current article date to what it was originally.
1492 This is only useful if you have used some other date conversion
1493 function and want to see what the date was before converting."
1494   (interactive (list t))
1495   (article-date-ut 'original highlight))
1496
1497 (defun article-date-lapsed (&optional highlight)
1498   "Convert the current article date to time lapsed since it was sent."
1499   (interactive (list t))
1500   (article-date-ut 'lapsed highlight))
1501
1502 (defun article-update-date-lapsed ()
1503   "Function to be run from a timer to update the lapsed time line."
1504   (let (deactivate-mark)
1505     (save-excursion
1506       (ignore-errors
1507         (walk-windows
1508          (lambda (w)
1509            (set-buffer (window-buffer w))
1510            (when (eq major-mode 'gnus-article-mode)
1511              (goto-char (point-min))
1512              (when (re-search-forward "^X-Sent:" nil t)
1513                (article-date-lapsed t)))))))))
1514
1515 (defun gnus-start-date-timer (&optional n)
1516   "Start a timer to update the X-Sent header in the article buffers.
1517 The numerical prefix says how frequently (in seconds) the function
1518 is to run."
1519   (interactive "p")
1520   (unless n
1521     (setq n 1))
1522   (gnus-stop-date-timer)
1523   (setq article-lapsed-timer
1524         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1525
1526 (defun gnus-stop-date-timer ()
1527   "Stop the X-Sent timer."
1528   (interactive)
1529   (when article-lapsed-timer
1530     (nnheader-cancel-timer article-lapsed-timer)
1531     (setq article-lapsed-timer nil)))
1532
1533 (defun article-date-user (&optional highlight)
1534   "Convert the current article date to the user-defined format.
1535 This format is defined by the `gnus-article-time-format' variable."
1536   (interactive (list t))
1537   (article-date-ut 'user highlight))
1538
1539 (defun article-date-iso8601 (&optional highlight)
1540   "Convert the current article date to ISO8601."
1541   (interactive (list t))
1542   (article-date-ut 'iso8601 highlight))
1543
1544 (defun article-show-all ()
1545   "Show all hidden text in the article buffer."
1546   (interactive)
1547   (save-excursion
1548     (let ((buffer-read-only nil))
1549       (gnus-article-unhide-text (point-min) (point-max)))))
1550
1551 (defun article-emphasize (&optional arg)
1552   "Emphasize text according to `gnus-emphasis-alist'."
1553   (interactive (gnus-article-hidden-arg))
1554   (unless (gnus-article-check-hidden-text 'emphasis arg)
1555     (save-excursion
1556       (let ((alist gnus-emphasis-alist)
1557             (buffer-read-only nil)
1558             (props (append '(article-type emphasis)
1559                            gnus-hidden-properties))
1560             regexp elem beg invisible visible face)
1561         (goto-char (point-min))
1562         (search-forward "\n\n" nil t)
1563         (setq beg (point))
1564         (while (setq elem (pop alist))
1565           (goto-char beg)
1566           (setq regexp (car elem)
1567                 invisible (nth 1 elem)
1568                 visible (nth 2 elem)
1569                 face (nth 3 elem))
1570           (while (re-search-forward regexp nil t)
1571             (when (and (match-beginning visible) (match-beginning invisible))
1572               (gnus-article-hide-text
1573                (match-beginning invisible) (match-end invisible) props)
1574               (gnus-article-unhide-text-type
1575                (match-beginning visible) (match-end visible) 'emphasis)
1576               (gnus-put-text-property-excluding-newlines
1577                (match-beginning visible) (match-end visible) 'face face)
1578               (goto-char (match-end invisible)))))))))
1579
1580 (defvar gnus-summary-article-menu)
1581 (defvar gnus-summary-post-menu)
1582
1583 ;;; Saving functions.
1584
1585 (defun gnus-article-save (save-buffer file &optional num)
1586   "Save the currently selected article."
1587   (unless gnus-save-all-headers
1588     ;; Remove headers according to `gnus-saved-headers'.
1589     (let ((gnus-visible-headers
1590            (or gnus-saved-headers gnus-visible-headers))
1591           (gnus-article-buffer save-buffer))
1592       (save-excursion
1593         (set-buffer save-buffer)
1594         (article-hide-headers 1 t))))
1595   (save-window-excursion
1596     (if (not gnus-default-article-saver)
1597         (error "No default saver is defined")
1598       ;; !!! Magic!  The saving functions all save
1599       ;; `gnus-save-article-buffer' (or so they think), but we
1600       ;; bind that variable to our save-buffer.
1601       (set-buffer gnus-article-buffer)
1602       (let* ((gnus-save-article-buffer save-buffer)
1603              (filename
1604               (cond
1605                ((not gnus-prompt-before-saving) 'default)
1606                ((eq gnus-prompt-before-saving 'always) nil)
1607                (t file)))
1608              (gnus-number-of-articles-to-be-saved
1609               (when (eq gnus-prompt-before-saving t)
1610                 num)))                  ; Magic
1611         (set-buffer gnus-article-current-summary)
1612         (funcall gnus-default-article-saver filename)))))
1613
1614 (defun gnus-read-save-file-name (prompt &optional filename
1615                                         function group headers variable)
1616   (let ((default-name
1617           (funcall function group headers (symbol-value variable)))
1618         result)
1619     (setq
1620      result
1621      (cond
1622       ((eq filename 'default)
1623        default-name)
1624       ((eq filename t)
1625        default-name)
1626       (filename filename)
1627       (t
1628        (let* ((split-name (gnus-get-split-value gnus-split-methods))
1629               (prompt
1630                (format prompt
1631                        (if (and gnus-number-of-articles-to-be-saved
1632                                 (> gnus-number-of-articles-to-be-saved 1))
1633                            (format "these %d articles"
1634                                    gnus-number-of-articles-to-be-saved)
1635                          "this article")))
1636               (file
1637                ;; Let the split methods have their say.
1638                (cond
1639                 ;; No split name was found.
1640                 ((null split-name)
1641                  (read-file-name
1642                   (concat prompt " (default "
1643                           (file-name-nondirectory default-name) ") ")
1644                   (file-name-directory default-name)
1645                   default-name))
1646                 ;; A single group name is returned.
1647                 ((stringp split-name)
1648                  (setq default-name
1649                        (funcall function split-name headers
1650                                 (symbol-value variable)))
1651                  (read-file-name
1652                   (concat prompt " (default "
1653                           (file-name-nondirectory default-name) ") ")
1654                   (file-name-directory default-name)
1655                   default-name))
1656                 ;; A single split name was found
1657                 ((= 1 (length split-name))
1658                  (let* ((name (expand-file-name
1659                                (car split-name) gnus-article-save-directory))
1660                         (dir (cond ((file-directory-p name)
1661                                     (file-name-as-directory name))
1662                                    ((file-exists-p name) name)
1663                                    (t gnus-article-save-directory))))
1664                    (read-file-name
1665                     (concat prompt " (default " name ") ")
1666                     dir name)))
1667                 ;; A list of splits was found.
1668                 (t
1669                  (setq split-name (nreverse split-name))
1670                  (let (result)
1671                    (let ((file-name-history
1672                           (nconc split-name file-name-history)))
1673                      (setq result
1674                            (expand-file-name
1675                             (read-file-name
1676                              (concat prompt " (`M-p' for defaults) ")
1677                              gnus-article-save-directory
1678                              (car split-name))
1679                             gnus-article-save-directory)))
1680                    (car (push result file-name-history)))))))
1681          ;; Create the directory.
1682          (gnus-make-directory (file-name-directory file))
1683          ;; If we have read a directory, we append the default file name.
1684          (when (file-directory-p file)
1685            (setq file (concat (file-name-as-directory file)
1686                               (file-name-nondirectory default-name))))
1687          ;; Possibly translate some characters.
1688          (nnheader-translate-file-chars file)))))
1689     (gnus-make-directory (file-name-directory result))
1690     (set variable result)))
1691
1692 (defun gnus-article-archive-name (group)
1693   "Return the first instance of an \"Archive-name\" in the current buffer."
1694   (let ((case-fold-search t))
1695     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1696       (nnheader-concat gnus-article-save-directory
1697                        (match-string 1)))))
1698
1699 (defun gnus-article-nndoc-name (group)
1700   "If GROUP is an nndoc group, return the name of the parent group."
1701   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1702     (gnus-group-get-parameter group 'save-article-group)))
1703
1704 (defun gnus-summary-save-in-rmail (&optional filename)
1705   "Append this article to Rmail file.
1706 Optional argument FILENAME specifies file name.
1707 Directory to save to is default to `gnus-article-save-directory'."
1708   (setq filename (gnus-read-save-file-name
1709                   "Save %s in rmail file:" filename
1710                   gnus-rmail-save-name gnus-newsgroup-name
1711                   gnus-current-headers 'gnus-newsgroup-last-rmail))
1712   (gnus-eval-in-buffer-window gnus-save-article-buffer
1713     (save-excursion
1714       (save-restriction
1715         (widen)
1716         (rmail-output-to-rmail-file filename))))
1717   filename)
1718
1719 (defun gnus-summary-save-in-mail (&optional filename)
1720   "Append this article to Unix mail file.
1721 Optional argument FILENAME specifies file name.
1722 Directory to save to is default to `gnus-article-save-directory'."
1723   (setq filename (gnus-read-save-file-name
1724                   "Save %s in Unix mail file:" filename
1725                   gnus-mail-save-name gnus-newsgroup-name
1726                   gnus-current-headers 'gnus-newsgroup-last-mail))
1727   (gnus-eval-in-buffer-window gnus-save-article-buffer
1728     (save-excursion
1729       (save-restriction
1730         (widen)
1731         (if (and (file-readable-p filename)
1732                  (mail-file-babyl-p filename))
1733             (rmail-output-to-rmail-file filename t)
1734           (gnus-output-to-mail filename)))))
1735   filename)
1736
1737 (defun gnus-summary-save-in-file (&optional filename overwrite)
1738   "Append this article to file.
1739 Optional argument FILENAME specifies file name.
1740 Directory to save to is default to `gnus-article-save-directory'."
1741   (setq filename (gnus-read-save-file-name
1742                   "Save %s in file:" filename
1743                   gnus-file-save-name gnus-newsgroup-name
1744                   gnus-current-headers 'gnus-newsgroup-last-file))
1745   (gnus-eval-in-buffer-window gnus-save-article-buffer
1746     (save-excursion
1747       (save-restriction
1748         (widen)
1749         (when (and overwrite
1750                    (file-exists-p filename))
1751           (delete-file filename))
1752         (gnus-output-to-file filename))))
1753   filename)
1754
1755 (defun gnus-summary-write-to-file (&optional filename)
1756   "Write this article to a file.
1757 Optional argument FILENAME specifies file name.
1758 The directory to save in defaults to `gnus-article-save-directory'."
1759   (gnus-summary-save-in-file nil t))
1760
1761 (defun gnus-summary-save-body-in-file (&optional filename)
1762   "Append this article body to a file.
1763 Optional argument FILENAME specifies file name.
1764 The directory to save in defaults to `gnus-article-save-directory'."
1765   (setq filename (gnus-read-save-file-name
1766                   "Save %s body in file:" filename
1767                   gnus-file-save-name gnus-newsgroup-name
1768                   gnus-current-headers 'gnus-newsgroup-last-file))
1769   (gnus-eval-in-buffer-window gnus-save-article-buffer
1770     (save-excursion
1771       (save-restriction
1772         (widen)
1773         (goto-char (point-min))
1774         (when (search-forward "\n\n" nil t)
1775           (narrow-to-region (point) (point-max)))
1776         (gnus-output-to-file filename))))
1777   filename)
1778
1779 (defun gnus-summary-save-in-pipe (&optional command)
1780   "Pipe this article to subprocess."
1781   (setq command
1782         (cond ((and (eq command 'default)
1783                     gnus-last-shell-command)
1784                gnus-last-shell-command)
1785               (command command)
1786               (t (read-string
1787                   (format
1788                    "Shell command on %s: "
1789                    (if (and gnus-number-of-articles-to-be-saved
1790                             (> gnus-number-of-articles-to-be-saved 1))
1791                        (format "these %d articles"
1792                                gnus-number-of-articles-to-be-saved)
1793                      "this article"))
1794                   gnus-last-shell-command))))
1795   (when (string-equal command "")
1796     (setq command gnus-last-shell-command))
1797   (gnus-eval-in-buffer-window gnus-article-buffer
1798     (save-restriction
1799       (widen)
1800       (shell-command-on-region (point-min) (point-max) command nil)))
1801   (setq gnus-last-shell-command command))
1802
1803 ;;; Article file names when saving.
1804
1805 (defun gnus-capitalize-newsgroup (newsgroup)
1806   "Capitalize NEWSGROUP name."
1807   (when (not (zerop (length newsgroup)))
1808     (concat (char-to-string (upcase (aref newsgroup 0)))
1809             (substring newsgroup 1))))
1810
1811 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1812   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1813 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1814 Otherwise, it is like ~/News/news/group/num."
1815   (let ((default
1816           (expand-file-name
1817            (concat (if (gnus-use-long-file-name 'not-save)
1818                        (gnus-capitalize-newsgroup newsgroup)
1819                      (gnus-newsgroup-directory-form newsgroup))
1820                    "/" (int-to-string (mail-header-number headers)))
1821            gnus-article-save-directory)))
1822     (if (and last-file
1823              (string-equal (file-name-directory default)
1824                            (file-name-directory last-file))
1825              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1826         default
1827       (or last-file default))))
1828
1829 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1830   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1831 If variable `gnus-use-long-file-name' is non-nil, it is
1832 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
1833   (let ((default
1834           (expand-file-name
1835            (concat (if (gnus-use-long-file-name 'not-save)
1836                        newsgroup
1837                      (gnus-newsgroup-directory-form newsgroup))
1838                    "/" (int-to-string (mail-header-number headers)))
1839            gnus-article-save-directory)))
1840     (if (and last-file
1841              (string-equal (file-name-directory default)
1842                            (file-name-directory last-file))
1843              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1844         default
1845       (or last-file default))))
1846
1847 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1848   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1849 If variable `gnus-use-long-file-name' is non-nil, it is
1850 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
1851   (or last-file
1852       (expand-file-name
1853        (if (gnus-use-long-file-name 'not-save)
1854            (gnus-capitalize-newsgroup newsgroup)
1855          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1856        gnus-article-save-directory)))
1857
1858 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1859   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1860 If variable `gnus-use-long-file-name' is non-nil, it is
1861 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
1862   (or last-file
1863       (expand-file-name
1864        (if (gnus-use-long-file-name 'not-save)
1865            newsgroup
1866          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1867        gnus-article-save-directory)))
1868
1869 (eval-and-compile
1870   (mapcar
1871    (lambda (func)
1872      (let (afunc gfunc)
1873        (if (consp func)
1874            (setq afunc (car func)
1875                  gfunc (cdr func))
1876          (setq afunc func
1877                gfunc (intern (format "gnus-%s" func))))
1878        (fset gfunc
1879              (if (not (fboundp afunc))
1880                  nil
1881                `(lambda (&optional interactive &rest args)
1882                   ,(documentation afunc t)
1883                   (interactive (list t))
1884                   (save-excursion
1885                     (set-buffer gnus-article-buffer)
1886                     (if interactive
1887                         (call-interactively ',afunc)
1888                       (apply ',afunc args))))))))
1889    '(article-hide-headers
1890      article-hide-boring-headers
1891      article-treat-overstrike
1892      (article-fill . gnus-article-word-wrap)
1893      article-remove-cr
1894      article-display-x-face
1895      article-hide-pgp
1896      article-hide-pem
1897      article-hide-signature
1898      article-remove-trailing-blank-lines
1899      article-strip-leading-blank-lines
1900      article-strip-multiple-blank-lines
1901      article-strip-leading-space
1902      article-strip-blank-lines
1903      article-strip-all-blank-lines
1904      article-date-local
1905      article-date-iso8601
1906      article-date-original
1907      article-date-ut
1908      article-date-user
1909      article-date-lapsed
1910      article-emphasize
1911      article-treat-dumbquotes
1912      (article-show-all . gnus-article-show-all-headers))))
1913 \f
1914 ;;;
1915 ;;; Gnus article mode
1916 ;;;
1917
1918 (put 'gnus-article-mode 'mode-class 'special)
1919
1920 (gnus-define-keys gnus-article-mode-map
1921   " " gnus-article-goto-next-page
1922   "\177" gnus-article-goto-prev-page
1923   [delete] gnus-article-goto-prev-page
1924   "\C-c^" gnus-article-refer-article
1925   "h" gnus-article-show-summary
1926   "s" gnus-article-show-summary
1927   "\C-c\C-m" gnus-article-mail
1928   "?" gnus-article-describe-briefly
1929   gnus-mouse-2 gnus-article-push-button
1930   "\r" gnus-article-press-button
1931   "\t" gnus-article-next-button
1932   "\M-\t" gnus-article-prev-button
1933   "e" gnus-article-edit
1934   "<" beginning-of-buffer
1935   ">" end-of-buffer
1936   "\C-c\C-i" gnus-info-find-node
1937   "\C-c\C-b" gnus-bug
1938
1939   "\C-d" gnus-article-read-summary-keys
1940   "\M-*" gnus-article-read-summary-keys
1941   "\M-#" gnus-article-read-summary-keys
1942   "\M-^" gnus-article-read-summary-keys
1943   "\M-g" gnus-article-read-summary-keys)
1944
1945 (substitute-key-definition
1946  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1947
1948 (defun gnus-article-make-menu-bar ()
1949   (gnus-turn-off-edit-menu 'article)
1950   (unless (boundp 'gnus-article-article-menu)
1951     (easy-menu-define
1952      gnus-article-article-menu gnus-article-mode-map ""
1953      '("Article"
1954        ["Scroll forwards" gnus-article-goto-next-page t]
1955        ["Scroll backwards" gnus-article-goto-prev-page t]
1956        ["Show summary" gnus-article-show-summary t]
1957        ["Fetch Message-ID at point" gnus-article-refer-article t]
1958        ["Mail to address at point" gnus-article-mail t]
1959        ["Send a bug report" gnus-bug t]))
1960
1961     (easy-menu-define
1962      gnus-article-treatment-menu gnus-article-mode-map ""
1963      '("Treatment"
1964        ["Hide headers" gnus-article-hide-headers t]
1965        ["Hide signature" gnus-article-hide-signature t]
1966        ["Hide citation" gnus-article-hide-citation t]
1967        ["Treat overstrike" gnus-article-treat-overstrike t]
1968        ["Remove carriage return" gnus-article-remove-cr t]))
1969
1970     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1971
1972     (when (boundp 'gnus-summary-post-menu)
1973       (define-key gnus-article-mode-map [menu-bar post]
1974         (cons "Post" gnus-summary-post-menu)))
1975
1976     (gnus-run-hooks 'gnus-article-menu-hook)))
1977
1978 (defun gnus-article-mode ()
1979   "Major mode for displaying an article.
1980
1981 All normal editing commands are switched off.
1982
1983 The following commands are available in addition to all summary mode
1984 commands:
1985 \\<gnus-article-mode-map>
1986 \\[gnus-article-next-page]\t Scroll the article one page forwards
1987 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1988 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1989 \\[gnus-article-show-summary]\t Display the summary buffer
1990 \\[gnus-article-mail]\t Send a reply to the address near point
1991 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1992 \\[gnus-info-find-node]\t Go to the Gnus info node"
1993   (interactive)
1994   (when (gnus-visual-p 'article-menu 'menu)
1995     (gnus-article-make-menu-bar))
1996   (gnus-simplify-mode-line)
1997   (setq mode-name "Article")
1998   (setq major-mode 'gnus-article-mode)
1999   (make-local-variable 'minor-mode-alist)
2000   (unless (assq 'gnus-show-mime minor-mode-alist)
2001     (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2002   (use-local-map gnus-article-mode-map)
2003   (gnus-update-format-specifications nil 'article-mode)
2004   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2005   (make-local-variable 'gnus-page-broken)
2006   (make-local-variable 'gnus-button-marker-list)
2007   (make-local-variable 'gnus-article-current-summary)
2008   (gnus-set-default-directory)
2009   (buffer-disable-undo)
2010   (setq buffer-read-only t)
2011   (set-syntax-table gnus-article-mode-syntax-table)
2012   (gnus-run-hooks 'gnus-article-mode-hook))
2013
2014 (defun gnus-article-setup-buffer ()
2015   "Initialize the article buffer."
2016   (let* ((name (if gnus-single-article-buffer "*Article*"
2017                  (concat "*Article " gnus-newsgroup-name "*")))
2018          (original
2019           (progn (string-match "\\*Article" name)
2020                  (concat " *Original Article"
2021                          (substring name (match-end 0))))))
2022     (setq gnus-article-buffer name)
2023     (setq gnus-original-article-buffer original)
2024     (setq gnus-article-mime-handle-alist nil)
2025     ;; This might be a variable local to the summary buffer.
2026     (unless gnus-single-article-buffer
2027       (save-excursion
2028         (set-buffer gnus-summary-buffer)
2029         (setq gnus-article-buffer name)
2030         (setq gnus-original-article-buffer original)
2031         (gnus-set-global-variables)))
2032     ;; Init original article buffer.
2033     (save-excursion
2034       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2035       (setq major-mode 'gnus-original-article-mode)
2036       (make-local-variable 'gnus-original-article))
2037     (if (get-buffer name)
2038         (save-excursion
2039           (set-buffer name)
2040           (buffer-disable-undo)
2041           (setq buffer-read-only t)
2042           (unless (eq major-mode 'gnus-article-mode)
2043             (gnus-article-mode))
2044           (current-buffer))
2045       (save-excursion
2046         (set-buffer (gnus-get-buffer-create name))
2047         (gnus-article-mode)
2048         (make-local-variable 'gnus-summary-buffer)
2049         (gnus-summary-set-local-parameters gnus-newsgroup-name)
2050         (current-buffer)))))
2051
2052 ;; Set article window start at LINE, where LINE is the number of lines
2053 ;; from the head of the article.
2054 (defun gnus-article-set-window-start (&optional line)
2055   (set-window-start
2056    (get-buffer-window gnus-article-buffer t)
2057    (save-excursion
2058      (set-buffer gnus-article-buffer)
2059      (goto-char (point-min))
2060      (if (not line)
2061          (point-min)
2062        (gnus-message 6 "Moved to bookmark")
2063        (search-forward "\n\n" nil t)
2064        (forward-line line)
2065        (point)))))
2066
2067 ;;; @@ article filters
2068 ;;;
2069
2070 (defun gnus-article-display-mime-message ()
2071   "Article display method for MIME message."
2072   ;; called from `gnus-original-article-buffer'.
2073   (let ((default-mime-charset (save-excursion
2074                                 (set-buffer gnus-summary-buffer)
2075                                 default-mime-charset)))
2076     (mime-display-message mime-message-structure
2077                           gnus-article-buffer nil gnus-article-mode-map))
2078   ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2079   (make-local-variable 'mime-button-mother-dispatcher)
2080   (setq mime-button-mother-dispatcher
2081         (function gnus-article-push-button))
2082   (run-hooks 'gnus-mime-article-prepare-hook))
2083
2084 (defun gnus-article-display-traditional-message ()
2085   "Article display method for traditional message."
2086   (set-buffer gnus-article-buffer)
2087   (let (buffer-read-only)
2088     (erase-buffer)
2089     (insert-buffer-substring gnus-original-article-buffer)))
2090
2091 (defun gnus-article-display-message-with-encoded-word ()
2092   "Article display method for message with encoded-words."
2093   (let ((charset (save-excursion
2094                    (set-buffer gnus-summary-buffer)
2095                    default-mime-charset)))
2096     (gnus-article-display-traditional-message)
2097     (let (buffer-read-only)
2098       (eword-decode-header charset)
2099       (goto-char (point-min))
2100       (if (search-forward "\n\n" nil t)
2101           (decode-mime-charset-region (match-end 0) (point-max) charset)))
2102     (mime-maybe-hide-echo-buffer))
2103   (gnus-run-hooks 'gnus-mime-article-prepare-hook))
2104
2105 (defun gnus-article-prepare (article &optional all-headers header)
2106   "Prepare ARTICLE in article mode buffer.
2107 ARTICLE should either be an article number or a Message-ID.
2108 If ARTICLE is an id, HEADER should be the article headers.
2109 If ALL-HEADERS is non-nil, no headers are hidden."
2110   (save-excursion
2111     ;; Make sure we start in a summary buffer.
2112     (unless (eq major-mode 'gnus-summary-mode)
2113       (set-buffer gnus-summary-buffer))
2114     (setq gnus-summary-buffer (current-buffer))
2115     (let* ((gnus-article (if header (mail-header-number header) article))
2116            (summary-buffer (current-buffer))
2117            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2118            (group gnus-newsgroup-name)
2119            result)
2120       (save-excursion
2121         (gnus-article-setup-buffer)
2122         (set-buffer gnus-original-article-buffer)
2123         ;; Deactivate active regions.
2124         (when (and (boundp 'transient-mark-mode)
2125                    transient-mark-mode)
2126           (setq mark-active nil))
2127         (if (not (setq result (let ((buffer-read-only nil))
2128                                 (gnus-request-article-this-buffer
2129                                  article group))))
2130             ;; There is no such article.
2131             (save-excursion
2132               (when (and (numberp article)
2133                          (not (memq article gnus-newsgroup-sparse)))
2134                 (setq gnus-article-current
2135                       (cons gnus-newsgroup-name article))
2136                 (set-buffer gnus-summary-buffer)
2137                 (setq gnus-current-article article)
2138                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2139                     (progn
2140                       (gnus-summary-set-agent-mark article)
2141                       (message "Message marked for downloading"))
2142                   (gnus-summary-mark-article article gnus-canceled-mark)
2143                   (unless (memq article gnus-newsgroup-sparse)
2144                     (gnus-error 1
2145                      "No such article (may have expired or been canceled)")))))
2146           (if (or (eq result 'pseudo)
2147                   (eq result 'nneething))
2148               (progn
2149                 (save-excursion
2150                   (set-buffer summary-buffer)
2151                   (push article gnus-newsgroup-history)
2152                   (setq gnus-last-article gnus-current-article
2153                         gnus-current-article 0
2154                         gnus-current-headers nil
2155                         gnus-article-current nil)
2156                   (if (eq result 'nneething)
2157                       (gnus-configure-windows 'summary)
2158                     (gnus-configure-windows 'article))
2159                   (gnus-set-global-variables))
2160                 (gnus-set-mode-line 'article))
2161             ;; The result from the `request' was an actual article -
2162             ;; or at least some text that is now displayed in the
2163             ;; article buffer.
2164             (when (and (numberp article)
2165                        (not (eq article gnus-current-article)))
2166               ;; Seems like a new article has been selected.
2167               ;; `gnus-current-article' must be an article number.
2168               (save-excursion
2169                 (set-buffer summary-buffer)
2170                 (push article gnus-newsgroup-history)
2171                 (setq gnus-last-article gnus-current-article
2172                       gnus-current-article article
2173                       gnus-current-headers
2174                       (gnus-summary-article-header gnus-current-article)
2175                       gnus-article-current
2176                       (cons gnus-newsgroup-name gnus-current-article))
2177                 (unless (vectorp gnus-current-headers)
2178                   (setq gnus-current-headers nil))
2179                 (gnus-summary-goto-subject gnus-current-article)
2180                 (when (gnus-summary-show-thread)
2181                   ;; If the summary buffer really was folded, the
2182                   ;; previous goto may not actually have gone to
2183                   ;; the right article, but the thread root instead.
2184                   ;; So we go again.
2185                   (gnus-summary-goto-subject gnus-current-article))
2186                 (gnus-run-hooks 'gnus-mark-article-hook)
2187                 (gnus-set-mode-line 'summary)
2188                 (when (gnus-visual-p 'article-highlight 'highlight)
2189                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
2190                 ;; Set the global newsgroup variables here.
2191                 ;; Suggested by Jim Sisolak
2192                 ;; <sisolak@trans4.neep.wisc.edu>.
2193                 (gnus-set-global-variables)
2194                 (setq gnus-have-all-headers
2195                       (or all-headers gnus-show-all-headers))))
2196             (when (or (numberp article)
2197                       (stringp article))
2198               (gnus-article-prepare-display)
2199               ;; Do page break.
2200               (goto-char (point-min))
2201               (setq gnus-page-broken
2202                     (when gnus-break-pages
2203                       (gnus-narrow-to-page)
2204                       t)))
2205             (gnus-set-mode-line 'article)
2206             (gnus-configure-windows 'article)
2207             (goto-char (point-min))
2208             (search-forward "\n\n" nil t)
2209             (set-window-point (get-buffer-window (current-buffer)) (point))
2210             t))))))
2211
2212 (defun gnus-article-prepare-display ()
2213   "Make the current buffer look like a nice article."
2214   (let ((method (if gnus-show-mime
2215                     (progn
2216                       (mime-parse-buffer)
2217                       gnus-article-display-method-for-mime)
2218                   gnus-article-display-method-for-traditional)))
2219     ;; Hooks for getting information from the article.
2220     ;; This hook must be called before being narrowed.
2221     (gnus-run-hooks 'gnus-tmp-internal-hook)
2222     (gnus-run-hooks 'gnus-article-prepare-hook)
2223     ;; Display message.
2224     (funcall method)
2225     ;; Associate this article with the current summary buffer.
2226     (setq gnus-article-current-summary (current-buffer))
2227     ;; Perform the article display hooks.
2228     (gnus-run-hooks 'gnus-article-display-hook)))
2229
2230 ;;;
2231 ;;; Gnus MIME viewing functions
2232 ;;;
2233
2234 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2235   "The following specs can be used:
2236 %t  The MIME type
2237 %n  The `name' parameter
2238 %d  The description, if any
2239 %l  The length of the encoded part
2240 %p  The part identifier
2241 %e  Dots if the part isn't displayed")
2242
2243 (defvar gnus-mime-button-line-format-alist
2244   '((?t gnus-tmp-type ?s)
2245     (?n gnus-tmp-name ?s)
2246     (?d gnus-tmp-description ?s)
2247     (?p gnus-tmp-id ?s)
2248     (?l gnus-tmp-length ?d)
2249     (?e gnus-tmp-dots ?s)))
2250
2251 (defvar gnus-mime-button-commands
2252   '((gnus-article-press-button  "\r"    "Toggle Display")
2253     ;(gnus-mime-view-part       "\M-\r" "View Interactively...")
2254     (gnus-mime-view-part        "v"     "View Interactively...")
2255     (gnus-mime-save-part        "o"     "Save...")
2256     (gnus-mime-copy-part        "c"     "View In Buffer")
2257     (gnus-mime-inline-part      "i"     "View Inline")
2258     (gnus-mime-pipe-part        "|"     "Pipe To Command...")))
2259
2260 (defvar gnus-mime-button-map nil)
2261 (unless gnus-mime-button-map
2262   (setq gnus-mime-button-map (make-sparse-keymap))
2263   (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2264   (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2265   (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2266   (mapcar (lambda (c)
2267             (define-key gnus-mime-button-map (cadr c) (car c)))
2268           gnus-mime-button-commands))
2269
2270 (defun gnus-mime-button-menu (event)
2271   "Construct a context-sensitive menu of MIME commands."
2272   (interactive "e")
2273   )
2274
2275 (defun gnus-mime-view-all-parts ()
2276   "View all the MIME parts."
2277   (interactive)
2278   (let ((handles gnus-article-mime-handles))
2279     (while handles
2280       (mm-display-part (pop handles)))))
2281
2282 (defun gnus-mime-save-part ()
2283   "Save the MIME part under point."
2284   (interactive)
2285   (let ((data (get-text-property (point) 'gnus-data)))
2286     (mm-save-part data)))
2287
2288 (defun gnus-mime-pipe-part ()
2289   "Pipe the MIME part under point to a process."
2290   (interactive)
2291   (let ((data (get-text-property (point) 'gnus-data)))
2292     (mm-pipe-part data)))
2293
2294 (defun gnus-mime-view-part ()
2295   "Interactively choose a view method for the MIME part under point."
2296   (interactive)
2297   (let ((data (get-text-property (point) 'gnus-data))
2298         (url-standalone-mode (not gnus-plugged)))
2299     (mm-interactively-view-part data)))
2300
2301 (defun gnus-mime-copy-part ()
2302   "Put the the MIME part under point into a new buffer."
2303   (interactive)
2304   (let* ((handle (get-text-property (point) 'gnus-data))
2305          (contents (mm-get-part handle))
2306          (buffer (generate-new-buffer
2307                        (file-name-nondirectory
2308                         (or
2309                          (mail-content-type-get (mm-handle-type handle) 'name)
2310                          (mail-content-type-get (mm-handle-type handle)
2311                                                 'filename)
2312                          "*decoded*")))))
2313     (set-buffer-major-mode buffer)
2314     (switch-to-buffer buffer)
2315     (insert contents)
2316     (goto-char (point-min))))
2317
2318 (defun gnus-mime-inline-part ()
2319   "Insert the MIME part under point into the current buffer."
2320   (interactive)
2321   (let* ((data (get-text-property (point) 'gnus-data))
2322          (contents (mm-get-part data))
2323          (url-standalone-mode (not gnus-plugged))
2324          (b (point))
2325          buffer-read-only)
2326     (if (mm-handle-undisplayer data)
2327         (mm-remove-part data)
2328       (forward-line 2)
2329       (mm-insert-inline data contents)
2330       (goto-char b))))
2331
2332 (defun gnus-article-view-part (n)
2333   "View MIME part N, which is the numerical prefix."
2334   (interactive "p")
2335   (save-current-buffer
2336     (set-buffer gnus-article-buffer)
2337     (when (> n (length gnus-article-mime-handle-alist))
2338       (error "No such part"))
2339     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2340       (gnus-article-goto-part n)
2341       (gnus-set-window-start)
2342       (gnus-mm-display-part handle))))
2343
2344 (defun gnus-mm-display-part (handle)
2345   "Display HANDLE and fix MIME button."
2346   (let ((id (get-text-property (point) 'gnus-part))
2347         (point (point))
2348         buffer-read-only)
2349     (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2350     (gnus-insert-mime-button
2351      handle id (list (not (mm-handle-displayed-p handle))))
2352     (mm-display-part handle)
2353     (goto-char point)))
2354
2355 (defun gnus-article-goto-part (n)
2356   "Go to MIME part N."
2357   (goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
2358
2359 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2360   (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2361         (gnus-tmp-type (car (mm-handle-type handle)))
2362         (gnus-tmp-description (mm-handle-description handle))
2363         (gnus-tmp-dots
2364          (if (if displayed (car displayed)
2365                (mm-handle-displayed-p handle))
2366              "" "..."))
2367         (gnus-tmp-length (save-excursion
2368                            (set-buffer (mm-handle-buffer handle))
2369                            (buffer-size)))
2370         b e)
2371     (setq gnus-tmp-name
2372           (if gnus-tmp-name
2373               (concat " (" gnus-tmp-name ")")
2374             ""))
2375     (setq gnus-tmp-description
2376           (if gnus-tmp-description
2377               (concat " (" gnus-tmp-description ")")
2378             ""))
2379     (setq b (point))
2380     (gnus-eval-format
2381      gnus-mime-button-line-format gnus-mime-button-line-format-alist
2382      `(local-map ,gnus-mime-button-map
2383                  keymap ,gnus-mime-button-map
2384                  gnus-callback gnus-mm-display-part
2385                  gnus-part ,gnus-tmp-id
2386                  gnus-type annotation
2387                  gnus-data ,handle))
2388     (setq e (point))
2389     (widget-convert-button 'link from to :action 'gnus-widget-press-button
2390                            :button-keymap gnus-mime-button-map)))
2391
2392 (defun gnus-widget-press-button (elems el)
2393   (goto-char (widget-get elems :from))
2394   (let ((url-standalone-mode (not gnus-plugged)))
2395     (gnus-article-press-button)))
2396
2397 (defun gnus-display-mime (&optional ihandles)
2398   "Insert MIME buttons in the buffer."
2399   (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2400          handle name type b e display)
2401     (when handles
2402       (unless ihandles
2403         ;; Top-level call; we clean up.
2404         (mm-destroy-parts gnus-article-mime-handles)
2405         (setq gnus-article-mime-handles handles
2406               gnus-article-mime-handle-alist nil)
2407         (goto-char (point-min))
2408         (search-forward "\n\n" nil t)
2409         (delete-region (point) (point-max)))
2410       (if (stringp (car handles))
2411           (if (equal (car handles) "multipart/alternative")
2412               (gnus-mime-display-alternative (cdr handles))
2413             (gnus-mime-display-mixed (cdr handles)))
2414         (gnus-mime-display-single handles)))))
2415
2416 (defun gnus-mime-display-mixed (handles)
2417   (let (handle)
2418     (while (setq handle (pop handles))
2419       (gnus-mime-display-single handle))))
2420
2421 (defun gnus-mime-display-single (handle)
2422   (let (display)
2423     (when (and (mm-automatic-display-p
2424                 (car (mm-handle-type handle)))
2425                (mm-inlinable-part-p (car (mm-handle-type handle)))
2426                (or (not (mm-handle-disposition handle))
2427                    (equal (car (mm-handle-disposition handle))
2428                           "inline")))
2429       (setq display t))
2430     (let ((id (1+ (length gnus-article-mime-handle-alist))))
2431       (push (cons id handle) gnus-article-mime-handle-alist)
2432       (gnus-insert-mime-button handle id (list display)))
2433     (insert "\n\n")
2434     (when display
2435       (forward-line -2)
2436       (mm-display-part handle t)
2437       (goto-char (point-max)))))
2438
2439 (defun gnus-mime-display-alternative (handles &optional preferred)
2440   (let* ((preferred (mm-preferred-alternative handles preferred))
2441          (ihandles handles)
2442          (point (point))
2443          handle buffer-read-only from)
2444     (goto-char (point-min))
2445     (search-forward "\n\n" nil t)
2446     (delete-region (point) (point-max))
2447     (when preferred
2448       ;; Top-level call; we clean up.
2449       (mm-remove-parts gnus-article-mime-handles)
2450       (setq gnus-article-mime-handles handles
2451             gnus-article-mime-handle-alist nil))
2452     (while (setq handle (pop handles))
2453       (gnus-add-text-properties
2454        (setq from (point))
2455        (progn
2456          (insert (format "[%c] %-18s"
2457                          (if (equal handle preferred) ?* ? )
2458                          (if (stringp (car handle))
2459                              (car handle)
2460                            (car (mm-handle-type handle)))))
2461          (point))
2462        `(local-map ,gnus-mime-button-map
2463                    ,gnus-mouse-face-prop ,gnus-article-mouse-face
2464                    face ,gnus-article-button-face
2465                    keymap ,gnus-mime-button-map
2466                    gnus-callback
2467                    (lambda (handles)
2468                      (gnus-mime-display-alternative
2469                       ',ihandles ,(if (stringp (car handle))
2470                                       (car handle)
2471                                     (car (mm-handle-type handle)))))
2472                    gnus-data ,handle))
2473       (widget-convert-button 'link from (point)
2474                              :action 'gnus-widget-press-button
2475                              :button-keymap gnus-widget-button-keymap)
2476       (insert "  "))
2477     (insert "\n\n")
2478     (when preferred
2479       (if (stringp (car preferred))
2480           (gnus-display-mime preferred)
2481         (mm-display-part preferred)))
2482     (goto-char point)))
2483
2484 (defun gnus-article-wash-status ()
2485   "Return a string which display status of article washing."
2486   (save-excursion
2487     (set-buffer gnus-article-buffer)
2488     (let ((cite (gnus-article-hidden-text-p 'cite))
2489           (headers (gnus-article-hidden-text-p 'headers))
2490           (boring (gnus-article-hidden-text-p 'boring-headers))
2491           (pgp (gnus-article-hidden-text-p 'pgp))
2492           (pem (gnus-article-hidden-text-p 'pem))
2493           (signature (gnus-article-hidden-text-p 'signature))
2494           (overstrike (gnus-article-hidden-text-p 'overstrike))
2495           (emphasis (gnus-article-hidden-text-p 'emphasis))
2496           (mime gnus-show-mime))
2497       (format "%c%c%c%c%c%c%c"
2498               (if cite ?c ? )
2499               (if (or headers boring) ?h ? )
2500               (if (or pgp pem) ?p ? )
2501               (if signature ?s ? )
2502               (if overstrike ?o ? )
2503               (if mime ?m ? )
2504               (if emphasis ?e ? )))))
2505
2506 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2507
2508 (defun gnus-article-maybe-hide-headers ()
2509   "Hide unwanted headers if `gnus-have-all-headers' is nil.
2510 Provided for backwards compatibility."
2511   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2512       gnus-inhibit-hiding
2513       (gnus-article-hide-headers)))
2514
2515 ;;; Article savers.
2516
2517 (defun gnus-output-to-file (file-name)
2518   "Append the current article to a file named FILE-NAME."
2519   (let ((artbuf (current-buffer)))
2520     (with-temp-buffer
2521       (insert-buffer-substring artbuf)
2522       ;; Append newline at end of the buffer as separator, and then
2523       ;; save it to file.
2524       (goto-char (point-max))
2525       (insert "\n")
2526       (append-to-file (point-min) (point-max) file-name)
2527       t)))
2528
2529 (defun gnus-narrow-to-page (&optional arg)
2530   "Narrow the article buffer to a page.
2531 If given a numerical ARG, move forward ARG pages."
2532   (interactive "P")
2533   (setq arg (if arg (prefix-numeric-value arg) 0))
2534   (save-excursion
2535     (set-buffer gnus-article-buffer)
2536     (goto-char (point-min))
2537     (widen)
2538     ;; Remove any old next/prev buttons.
2539     (when (gnus-visual-p 'page-marker)
2540       (let ((buffer-read-only nil))
2541         (gnus-remove-text-with-property 'gnus-prev)
2542         (gnus-remove-text-with-property 'gnus-next)))
2543     (when
2544         (cond ((< arg 0)
2545                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2546               ((> arg 0)
2547                (re-search-forward page-delimiter nil 'move arg)))
2548       (goto-char (match-end 0)))
2549     (narrow-to-region
2550      (point)
2551      (if (re-search-forward page-delimiter nil 'move)
2552          (match-beginning 0)
2553        (point)))
2554     (when (and (gnus-visual-p 'page-marker)
2555                (not (= (point-min) 1)))
2556       (save-excursion
2557         (goto-char (point-min))
2558         (gnus-insert-prev-page-button)))
2559     (when (and (gnus-visual-p 'page-marker)
2560                (< (+ (point-max) 2) (buffer-size)))
2561       (save-excursion
2562         (goto-char (point-max))
2563         (gnus-insert-next-page-button)))))
2564
2565 ;; Article mode commands
2566
2567 (defun gnus-article-goto-next-page ()
2568   "Show the next page of the article."
2569   (interactive)
2570   (when (gnus-article-next-page)
2571     (goto-char (point-min))
2572     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2573
2574 (defun gnus-article-goto-prev-page ()
2575   "Show the next page of the article."
2576   (interactive)
2577   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2578     (gnus-article-prev-page nil)))
2579
2580 (defun gnus-article-next-page (&optional lines)
2581   "Show the next page of the current article.
2582 If end of article, return non-nil.  Otherwise return nil.
2583 Argument LINES specifies lines to be scrolled up."
2584   (interactive "p")
2585   (move-to-window-line -1)
2586   (if (save-excursion
2587         (end-of-line)
2588         (and (pos-visible-in-window-p)  ;Not continuation line.
2589              (eobp)))
2590       ;; Nothing in this page.
2591       (if (or (not gnus-page-broken)
2592               (save-excursion
2593                 (save-restriction
2594                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2595           t                             ;Nothing more.
2596         (gnus-narrow-to-page 1)         ;Go to next page.
2597         nil)
2598     ;; More in this page.
2599     (let ((scroll-in-place nil))
2600       (condition-case ()
2601           (scroll-up lines)
2602         (end-of-buffer
2603          ;; Long lines may cause an end-of-buffer error.
2604          (goto-char (point-max)))))
2605     (move-to-window-line 0)
2606     nil))
2607
2608 (defun gnus-article-prev-page (&optional lines)
2609   "Show previous page of current article.
2610 Argument LINES specifies lines to be scrolled down."
2611   (interactive "p")
2612   (move-to-window-line 0)
2613   (if (and gnus-page-broken
2614            (bobp)
2615            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2616       (progn
2617         (gnus-narrow-to-page -1)        ;Go to previous page.
2618         (goto-char (point-max))
2619         (recenter -1))
2620     (let ((scroll-in-place nil))
2621       (prog1
2622           (condition-case ()
2623               (scroll-down lines)
2624             (beginning-of-buffer
2625              (goto-char (point-min))))
2626         (move-to-window-line 0)))))
2627
2628 (defun gnus-article-refer-article ()
2629   "Read article specified by message-id around point."
2630   (interactive)
2631   (let ((point (point)))
2632     (search-forward ">" nil t)          ;Move point to end of "<....>".
2633     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2634         (let ((message-id (match-string 1)))
2635           (goto-char point)
2636           (set-buffer gnus-summary-buffer)
2637           (gnus-summary-refer-article message-id))
2638       (goto-char (point))
2639       (error "No references around point"))))
2640
2641 (defun gnus-article-show-summary ()
2642   "Reconfigure windows to show summary buffer."
2643   (interactive)
2644   (if (not (gnus-buffer-live-p gnus-summary-buffer))
2645       (error "There is no summary buffer for this article buffer")
2646     (gnus-article-set-globals)
2647     (gnus-configure-windows 'article)
2648     (gnus-summary-goto-subject gnus-current-article)
2649     (gnus-summary-position-point)))
2650
2651 (defun gnus-article-describe-briefly ()
2652   "Describe article mode commands briefly."
2653   (interactive)
2654   (gnus-message 6
2655                 (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")))
2656
2657 (defun gnus-article-summary-command ()
2658   "Execute the last keystroke in the summary buffer."
2659   (interactive)
2660   (let ((obuf (current-buffer))
2661         (owin (current-window-configuration))
2662         func)
2663     (switch-to-buffer gnus-article-current-summary 'norecord)
2664     (setq func (lookup-key (current-local-map) (this-command-keys)))
2665     (call-interactively func)
2666     (set-buffer obuf)
2667     (set-window-configuration owin)
2668     (set-window-point (get-buffer-window (current-buffer)) (point))))
2669
2670 (defun gnus-article-summary-command-nosave ()
2671   "Execute the last keystroke in the summary buffer."
2672   (interactive)
2673   (let (func)
2674     (pop-to-buffer gnus-article-current-summary 'norecord)
2675     (setq func (lookup-key (current-local-map) (this-command-keys)))
2676     (call-interactively func)))
2677
2678 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2679   "Read a summary buffer key sequence and execute it from the article buffer."
2680   (interactive "P")
2681   (let ((nosaves
2682          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
2683            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2684            "=" "^" "\M-^" "|"))
2685         (nosave-but-article
2686          '("A\r"))
2687         (nosave-in-article
2688          '("\C-d"))
2689         (up-to-top
2690          '("n" "Gn" "p" "Gp"))
2691         keys new-sum-point)
2692     (save-excursion
2693       (set-buffer gnus-article-current-summary)
2694       (let (gnus-pick-mode)
2695         (push (or key last-command-event) unread-command-events)
2696         (setq keys (read-key-sequence nil))))
2697     (message "")
2698
2699     (if (or (member keys nosaves)
2700             (member keys nosave-but-article)
2701             (member keys nosave-in-article))
2702         (let (func)
2703           (save-window-excursion
2704             (pop-to-buffer gnus-article-current-summary 'norecord)
2705             ;; We disable the pick minor mode commands.
2706             (let (gnus-pick-mode)
2707               (setq func (lookup-key (current-local-map) keys))))
2708           (if (not func)
2709               (ding)
2710             (unless (member keys nosave-in-article)
2711               (set-buffer gnus-article-current-summary))
2712             (call-interactively func)
2713             (setq new-sum-point (point)))
2714           (when (member keys nosave-but-article)
2715             (pop-to-buffer gnus-article-buffer 'norecord)))
2716       ;; These commands should restore window configuration.
2717       (let ((obuf (current-buffer))
2718             (owin (current-window-configuration))
2719             (opoint (point))
2720             (summary gnus-article-current-summary)
2721             func in-buffer selected)
2722         (if not-restore-window
2723             (pop-to-buffer summary 'norecord)
2724           (switch-to-buffer summary 'norecord))
2725         (setq in-buffer (current-buffer))
2726         ;; We disable the pick minor mode commands.
2727         (if (setq func (let (gnus-pick-mode)
2728                          (lookup-key (current-local-map) keys)))
2729             (progn
2730               (call-interactively func)
2731               (setq new-sum-point (point)))
2732           (ding))
2733         (when (eq in-buffer (current-buffer))
2734           (setq selected (gnus-summary-select-article))
2735           (set-buffer obuf)
2736           (unless not-restore-window
2737             (set-window-configuration owin))
2738           (unless (or (not (eq selected 'old)) (member keys up-to-top))
2739             (set-window-point (get-buffer-window (current-buffer))
2740                               opoint))
2741           (let ((win (get-buffer-window gnus-article-current-summary)))
2742             (when win
2743               (set-window-point win new-sum-point))))))))
2744
2745 (defun gnus-article-hide (&optional arg force)
2746   "Hide all the gruft in the current article.
2747 This means that PGP stuff, signatures, cited text and (some)
2748 headers will be hidden.
2749 If given a prefix, show the hidden text instead."
2750   (interactive (append (gnus-article-hidden-arg) (list 'force)))
2751   (gnus-article-hide-headers arg)
2752   (gnus-article-hide-pgp arg)
2753   (gnus-article-hide-citation-maybe arg force)
2754   (gnus-article-hide-signature arg))
2755
2756 (defun gnus-article-maybe-highlight ()
2757   "Do some article highlighting if article highlighting is requested."
2758   (when (gnus-visual-p 'article-highlight 'highlight)
2759     (gnus-article-highlight-some)))
2760
2761 (defun gnus-check-group-server ()
2762   ;; Make sure the connection to the server is alive.
2763   (unless (gnus-server-opened
2764            (gnus-find-method-for-group gnus-newsgroup-name))
2765     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2766     (gnus-request-group gnus-newsgroup-name t)))
2767
2768 (defun gnus-request-article-this-buffer (article group)
2769   "Get an article and insert it into this buffer."
2770   (let (do-update-line sparse-header)
2771     (prog1
2772         (save-excursion
2773           (erase-buffer)
2774           (gnus-kill-all-overlays)
2775           (setq group (or group gnus-newsgroup-name))
2776
2777           ;; Using `gnus-request-article' directly will insert the article into
2778           ;; `nntp-server-buffer' - so we'll save some time by not having to
2779           ;; copy it from the server buffer into the article buffer.
2780
2781           ;; We only request an article by message-id when we do not have the
2782           ;; headers for it, so we'll have to get those.
2783           (when (stringp article)
2784             (let ((gnus-override-method gnus-refer-article-method))
2785               (gnus-read-header article)))
2786
2787           ;; If the article number is negative, that means that this article
2788           ;; doesn't belong in this newsgroup (possibly), so we find its
2789           ;; message-id and request it by id instead of number.
2790           (when (and (numberp article)
2791                      gnus-summary-buffer
2792                      (get-buffer gnus-summary-buffer)
2793                      (gnus-buffer-exists-p gnus-summary-buffer))
2794             (save-excursion
2795               (set-buffer gnus-summary-buffer)
2796               (let ((header (gnus-summary-article-header article)))
2797                 (when (< article 0)
2798                   (cond
2799                    ((memq article gnus-newsgroup-sparse)
2800                     ;; This is a sparse gap article.
2801                     (setq do-update-line article)
2802                     (setq article (mail-header-id header))
2803                     (let ((gnus-override-method gnus-refer-article-method))
2804                       (setq sparse-header (gnus-read-header article)))
2805                     (setq gnus-newsgroup-sparse
2806                           (delq article gnus-newsgroup-sparse)))
2807                    ((vectorp header)
2808                     ;; It's a real article.
2809                     (setq article (mail-header-id header)))
2810                    (t
2811                     ;; It is an extracted pseudo-article.
2812                     (setq article 'pseudo)
2813                     (gnus-request-pseudo-article header))))
2814
2815                 (let ((method (gnus-find-method-for-group
2816                                gnus-newsgroup-name)))
2817                   (when (and (eq (car method) 'nneething)
2818                              (vectorp header))
2819                     (let ((dir (concat
2820                                 (file-name-as-directory
2821                                  (or (cadr (assq 'nneething-address method))
2822                                      (nth 1 method)))
2823                                 (mail-header-subject header))))
2824                       (when (file-directory-p dir)
2825                         (setq article 'nneething)
2826                         (gnus-group-enter-directory dir))))))))
2827
2828           (cond
2829            ;; Refuse to select canceled articles.
2830            ((and (numberp article)
2831                  gnus-summary-buffer
2832                  (get-buffer gnus-summary-buffer)
2833                  (gnus-buffer-exists-p gnus-summary-buffer)
2834                  (eq (cdr (save-excursion
2835                             (set-buffer gnus-summary-buffer)
2836                             (assq article gnus-newsgroup-reads)))
2837                      gnus-canceled-mark))
2838             nil)
2839            ;; Check the backlog.
2840            ((and gnus-keep-backlog
2841                  (gnus-backlog-request-article group article (current-buffer)))
2842             'article)
2843            ;; Check asynchronous pre-fetch.
2844            ((gnus-async-request-fetched-article group article (current-buffer))
2845             (gnus-async-prefetch-next group article gnus-summary-buffer)
2846             (when (and (numberp article) gnus-keep-backlog)
2847               (gnus-backlog-enter-article group article (current-buffer)))
2848             'article)
2849            ;; Check the cache.
2850            ((and gnus-use-cache
2851                  (numberp article)
2852                  (gnus-cache-request-article article group))
2853             'article)
2854            ;; Get the article and put into the article buffer.
2855            ((or (stringp article) (numberp article))
2856             (let ((gnus-override-method
2857                    (and (stringp article) gnus-refer-article-method))
2858                   (buffer-read-only nil))
2859               (erase-buffer)
2860               (gnus-kill-all-overlays)
2861               (gnus-check-group-server)
2862               (when (gnus-request-article article group (current-buffer))
2863                 (when (numberp article)
2864                   (gnus-async-prefetch-next group article gnus-summary-buffer)
2865                   (when gnus-keep-backlog
2866                     (gnus-backlog-enter-article
2867                      group article (current-buffer))))
2868                 'article)))
2869            ;; It was a pseudo.
2870            (t article)))
2871
2872       ;; Associate this article with the current summary buffer.
2873       (setq gnus-article-current-summary gnus-summary-buffer)
2874
2875       ;; Take the article from the original article buffer
2876       ;; and place it in the buffer it's supposed to be in.
2877       (when (and (get-buffer gnus-article-buffer)
2878                  (equal (buffer-name (current-buffer))
2879                         (buffer-name (get-buffer gnus-article-buffer))))
2880         (save-excursion
2881           (if (get-buffer gnus-original-article-buffer)
2882               (set-buffer gnus-original-article-buffer)
2883             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2884             (buffer-disable-undo)
2885             (setq major-mode 'gnus-original-article-mode)
2886             (setq buffer-read-only t))
2887           (let (buffer-read-only)
2888             (erase-buffer)
2889             (insert-buffer-substring gnus-article-buffer))
2890           (setq gnus-original-article (cons group article)))
2891
2892         ;; Decode charsets.
2893         (run-hooks 'gnus-article-decode-hook)
2894         ;; Mark article as decoded or not.
2895         (setq gnus-article-decoded-p gnus-article-decode-hook))
2896
2897       ;; Update sparse articles.
2898       (when (and do-update-line
2899                  (or (numberp article)
2900                      (stringp article)))
2901         (let ((buf (current-buffer)))
2902           (set-buffer gnus-summary-buffer)
2903           (gnus-summary-update-article do-update-line sparse-header)
2904           (gnus-summary-goto-subject do-update-line nil t)
2905           (set-window-point (get-buffer-window (current-buffer) t)
2906                             (point))
2907           (set-buffer buf))))))
2908
2909 ;;;
2910 ;;; Article editing
2911 ;;;
2912
2913 (defcustom gnus-article-edit-mode-hook nil
2914   "Hook run in article edit mode buffers."
2915   :group 'gnus-article-various
2916   :type 'hook)
2917
2918 (defvar gnus-article-edit-done-function nil)
2919
2920 (defvar gnus-article-edit-mode-map nil)
2921
2922 ;; Should we be using derived.el for this?
2923 (unless gnus-article-edit-mode-map
2924   (setq gnus-article-edit-mode-map (make-sparse-keymap))
2925   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
2926
2927   (gnus-define-keys gnus-article-edit-mode-map
2928     "\C-c\C-c" gnus-article-edit-done
2929     "\C-c\C-k" gnus-article-edit-exit)
2930
2931   (gnus-define-keys (gnus-article-edit-wash-map
2932                      "\C-c\C-w" gnus-article-edit-mode-map)
2933     "f" gnus-article-edit-full-stops))
2934
2935 (defun gnus-article-edit-mode ()
2936   "Major mode for editing articles.
2937 This is an extended text-mode.
2938
2939 \\{gnus-article-edit-mode-map}"
2940   (interactive)
2941   (setq major-mode 'gnus-article-edit-mode)
2942   (setq mode-name "Article Edit")
2943   (use-local-map gnus-article-edit-mode-map)
2944   (make-local-variable 'gnus-article-edit-done-function)
2945   (make-local-variable 'gnus-prev-winconf)
2946   (setq buffer-read-only nil)
2947   (buffer-enable-undo)
2948   (widen)
2949   (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2950
2951 (defun gnus-article-edit (&optional force)
2952   "Edit the current article.
2953 This will have permanent effect only in mail groups.
2954 If FORCE is non-nil, allow editing of articles even in read-only
2955 groups."
2956   (interactive "P")
2957   (when (and (not force)
2958              (gnus-group-read-only-p))
2959     (error "The current newsgroup does not support article editing"))
2960   (gnus-article-date-original)
2961   (gnus-article-edit-article
2962    `(lambda (no-highlight)
2963       (gnus-summary-edit-article-done
2964        ,(or (mail-header-references gnus-current-headers) "")
2965        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2966
2967 (defun gnus-article-edit-article (exit-func)
2968   "Start editing the contents of the current article buffer."
2969   (let ((winconf (current-window-configuration)))
2970     (set-buffer gnus-article-buffer)
2971     (gnus-article-edit-mode)
2972     (gnus-article-delete-text-of-type 'annotation)
2973     (gnus-set-text-properties (point-min) (point-max) nil)
2974     (gnus-configure-windows 'edit-article)
2975     (setq gnus-article-edit-done-function exit-func)
2976     (setq gnus-prev-winconf winconf)
2977     (gnus-message 6 "C-c C-c to end edits")))
2978
2979 (defun gnus-article-edit-done (&optional arg)
2980   "Update the article edits and exit."
2981   (interactive "P")
2982   (save-excursion
2983     (save-restriction
2984       (widen)
2985       (goto-char (point-min))
2986       (when (search-forward "\n\n" nil 1)
2987         (let ((lines (count-lines (point) (point-max)))
2988               (length (- (point-max) (point)))
2989               (case-fold-search t)
2990               (body (copy-marker (point))))
2991           (goto-char (point-min))
2992           (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2993             (delete-region (match-beginning 1) (match-end 1))
2994             (insert (number-to-string length)))
2995           (goto-char (point-min))
2996           (when (re-search-forward
2997                  "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2998             (delete-region (match-beginning 1) (match-end 1))
2999             (insert (number-to-string length)))
3000           (goto-char (point-min))
3001           (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3002             (delete-region (match-beginning 1) (match-end 1))
3003             (insert (number-to-string lines)))))))
3004   (let ((func gnus-article-edit-done-function)
3005         (buf (current-buffer))
3006         (start (window-start)))
3007     (gnus-article-edit-exit)
3008     (save-excursion
3009       (set-buffer buf)
3010       (let ((buffer-read-only nil))
3011         (funcall func arg))
3012       ;; The cache and backlog have to be flushed somewhat.
3013       (when gnus-keep-backlog
3014         (gnus-backlog-remove-article
3015          (car gnus-article-current) (cdr gnus-article-current)))
3016       ;; Flush original article as well.
3017       (save-excursion
3018         (when (get-buffer gnus-original-article-buffer)
3019           (set-buffer gnus-original-article-buffer)
3020           (setq gnus-original-article nil)))
3021       (when gnus-use-cache
3022         (gnus-cache-update-article
3023          (car gnus-article-current) (cdr gnus-article-current))))
3024     (set-buffer buf)
3025     (set-window-start (get-buffer-window buf) start)
3026     (set-window-point (get-buffer-window buf) (point))))
3027
3028 (defun gnus-article-edit-exit ()
3029   "Exit the article editing without updating."
3030   (interactive)
3031   ;; We remove all text props from the article buffer.
3032   (let ((buf (format "%s" (buffer-string)))
3033         (curbuf (current-buffer))
3034         (p (point))
3035         (window-start (window-start)))
3036     (erase-buffer)
3037     (insert buf)
3038     (let ((winconf gnus-prev-winconf))
3039       (gnus-article-mode)
3040       (set-window-configuration winconf)
3041       ;; Tippy-toe some to make sure that point remains where it was.
3042       (save-current-buffer
3043         (set-buffer curbuf)
3044         (set-window-start (get-buffer-window (current-buffer)) window-start)
3045         (goto-char p)))))
3046
3047 (defun gnus-article-edit-full-stops ()
3048   "Interactively repair spacing at end of sentences."
3049   (interactive)
3050   (save-excursion
3051     (goto-char (point-min))
3052     (search-forward-regexp "^$" nil t)
3053     (let ((case-fold-search nil))
3054       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3055
3056 ;;;
3057 ;;; Article highlights
3058 ;;;
3059
3060 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3061
3062 ;;; Internal Variables:
3063
3064 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)"
3065   "Regular expression that matches URLs."
3066   :group 'gnus-article-buttons
3067   :type 'regexp)
3068
3069 (defcustom gnus-button-alist
3070   `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
3071      gnus-button-message-id 2)
3072     ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
3073     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3074      1 t
3075      gnus-button-fetch-group 4)
3076     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3077     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3078      t gnus-button-message-id 3)
3079     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3080     ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3081     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3082     ;; This is how URLs _should_ be embedded in text...
3083     ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3084     ;; Raw URLs.
3085     (,gnus-button-url-regexp 0 t gnus-button-url 0))
3086   "*Alist of regexps matching buttons in article bodies.
3087
3088 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3089 REGEXP: is the string matching text around the button,
3090 BUTTON: is the number of the regexp grouping actually matching the button,
3091 FORM: is a lisp expression which must eval to true for the button to
3092 be added,
3093 CALLBACK: is the function to call when the user push this button, and each
3094 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3095
3096 CALLBACK can also be a variable, in that case the value of that
3097 variable it the real callback function."
3098   :group 'gnus-article-buttons
3099   :type '(repeat (list regexp
3100                        (integer :tag "Button")
3101                        (sexp :tag "Form")
3102                        (function :tag "Callback")
3103                        (repeat :tag "Par"
3104                                :inline t
3105                                (integer :tag "Regexp group")))))
3106
3107 (defcustom gnus-header-button-alist
3108   `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3109      0 t gnus-button-message-id 0)
3110     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3111     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3112      0 t gnus-button-mailto 0)
3113     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3114     ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3115     ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3116     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3117      gnus-button-message-id 3))
3118   "*Alist of headers and regexps to match buttons in article heads.
3119
3120 This alist is very similar to `gnus-button-alist', except that each
3121 alist has an additional HEADER element first in each entry:
3122
3123 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3124
3125 HEADER is a regexp to match a header.  For a fuller explanation, see
3126 `gnus-button-alist'."
3127   :group 'gnus-article-buttons
3128   :group 'gnus-article-headers
3129   :type '(repeat (list (regexp :tag "Header")
3130                        regexp
3131                        (integer :tag "Button")
3132                        (sexp :tag "Form")
3133                        (function :tag "Callback")
3134                        (repeat :tag "Par"
3135                                :inline t
3136                                (integer :tag "Regexp group")))))
3137
3138 (defvar gnus-button-regexp nil)
3139 (defvar gnus-button-marker-list nil)
3140 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3141
3142 (defvar gnus-button-last nil)
3143 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3144
3145 ;;; Commands:
3146
3147 (defun gnus-article-push-button (event)
3148   "Check text under the mouse pointer for a callback function.
3149 If the text under the mouse pointer has a `gnus-callback' property,
3150 call it with the value of the `gnus-data' text property."
3151   (interactive "e")
3152   (set-buffer (window-buffer (posn-window (event-start event))))
3153   (let* ((pos (posn-point (event-start event)))
3154          (data (get-text-property pos 'gnus-data))
3155          (fun (get-text-property pos 'gnus-callback)))
3156     (goto-char pos)
3157     (when fun
3158       (funcall fun data))))
3159
3160 (defun gnus-article-press-button ()
3161   "Check text at point for a callback function.
3162 If the text at point has a `gnus-callback' property,
3163 call it with the value of the `gnus-data' text property."
3164   (interactive)
3165   (let* ((data (get-text-property (point) 'gnus-data))
3166          (fun (get-text-property (point) 'gnus-callback)))
3167     (when fun
3168       (funcall fun data))))
3169
3170 (defun gnus-article-prev-button (n)
3171   "Move point to N buttons backward.
3172 If N is negative, move forward instead."
3173   (interactive "p")
3174   (gnus-article-next-button (- n)))
3175
3176 (defun gnus-article-next-button (n)
3177   "Move point to N buttons forward.
3178 If N is negative, move backward instead."
3179   (interactive "p")
3180   (let ((function (if (< n 0) 'previous-single-property-change
3181                     'next-single-property-change))
3182         (inhibit-point-motion-hooks t)
3183         (backward (< n 0))
3184         (limit (if (< n 0) (point-min) (point-max))))
3185     (setq n (abs n))
3186     (while (and (not (= limit (point)))
3187                 (> n 0))
3188       ;; Skip past the current button.
3189       (when (get-text-property (point) 'gnus-callback)
3190         (goto-char (funcall function (point) 'gnus-callback nil limit)))
3191       ;; Go to the next (or previous) button.
3192       (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
3193       ;; Put point at the start of the button.
3194       (when (and backward (not (get-text-property (point) 'gnus-callback)))
3195         (goto-char (funcall function (point) 'gnus-callback nil limit)))
3196       ;; Skip past intangible buttons.
3197       (when (get-text-property (point) 'intangible)
3198         (incf n))
3199       (decf n))
3200     (unless (zerop n)
3201       (gnus-message 5 "No more buttons"))
3202     n))
3203
3204 (defun gnus-article-highlight (&optional force)
3205   "Highlight current article.
3206 This function calls `gnus-article-highlight-headers',
3207 `gnus-article-highlight-citation',
3208 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3209 do the highlighting.  See the documentation for those functions."
3210   (interactive (list 'force))
3211   (gnus-article-highlight-headers)
3212   (gnus-article-highlight-citation force)
3213   (gnus-article-highlight-signature)
3214   (gnus-article-add-buttons force)
3215   (gnus-article-add-buttons-to-head))
3216
3217 (defun gnus-article-highlight-some (&optional force)
3218   "Highlight current article.
3219 This function calls `gnus-article-highlight-headers',
3220 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3221 do the highlighting.  See the documentation for those functions."
3222   (interactive (list 'force))
3223   (gnus-article-highlight-headers)
3224   (gnus-article-highlight-signature)
3225   (gnus-article-add-buttons))
3226
3227 (defun gnus-article-highlight-headers ()
3228   "Highlight article headers as specified by `gnus-header-face-alist'."
3229   (interactive)
3230   (save-excursion
3231     (set-buffer gnus-article-buffer)
3232     (save-restriction
3233       (let ((alist gnus-header-face-alist)
3234             (buffer-read-only nil)
3235             (case-fold-search t)
3236             (inhibit-point-motion-hooks t)
3237             entry regexp header-face field-face from hpoints fpoints)
3238         (message-narrow-to-head)
3239         (while (setq entry (pop alist))
3240           (goto-char (point-min))
3241           (setq regexp (concat "^\\("
3242                                (if (string-equal "" (nth 0 entry))
3243                                    "[^\t ]"
3244                                  (nth 0 entry))
3245                                "\\)")
3246                 header-face (nth 1 entry)
3247                 field-face (nth 2 entry))
3248           (while (and (re-search-forward regexp nil t)
3249                       (not (eobp)))
3250             (beginning-of-line)
3251             (setq from (point))
3252             (unless (search-forward ":" nil t)
3253               (forward-char 1))
3254             (when (and header-face
3255                        (not (memq (point) hpoints)))
3256               (push (point) hpoints)
3257               (gnus-put-text-property from (point) 'face header-face))
3258             (when (and field-face
3259                        (not (memq (setq from (point)) fpoints)))
3260               (push from fpoints)
3261               (if (re-search-forward "^[^ \t]" nil t)
3262                   (forward-char -2)
3263                 (goto-char (point-max)))
3264               (gnus-put-text-property from (point) 'face field-face))))))))
3265
3266 (defun gnus-article-highlight-signature ()
3267   "Highlight the signature in an article.
3268 It does this by highlighting everything after
3269 `gnus-signature-separator' using `gnus-signature-face'."
3270   (interactive)
3271   (save-excursion
3272     (set-buffer gnus-article-buffer)
3273     (let ((buffer-read-only nil)
3274           (inhibit-point-motion-hooks t))
3275       (save-restriction
3276         (when (and gnus-signature-face
3277                    (gnus-article-narrow-to-signature))
3278           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3279                             'face gnus-signature-face)
3280           (widen)
3281           (gnus-article-search-signature)
3282           (let ((start (match-beginning 0))
3283                 (end (set-marker (make-marker) (1+ (match-end 0)))))
3284             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3285                                      end)))))))
3286
3287 (defun gnus-button-in-region-p (b e prop)
3288   "Say whether PROP exists in the region."
3289   (text-property-not-all b e prop nil))
3290
3291 (defun gnus-article-add-buttons (&optional force)
3292   "Find external references in the article and make buttons of them.
3293 \"External references\" are things like Message-IDs and URLs, as
3294 specified by `gnus-button-alist'."
3295   (interactive (list 'force))
3296   (save-excursion
3297     (set-buffer gnus-article-buffer)
3298     (let ((buffer-read-only nil)
3299           (inhibit-point-motion-hooks t)
3300           (case-fold-search t)
3301           (alist gnus-button-alist)
3302           beg entry regexp)
3303       ;; Remove all old markers.
3304       (let (marker entry)
3305         (while (setq marker (pop gnus-button-marker-list))
3306           (goto-char marker)
3307           (when (setq entry (gnus-button-entry))
3308             (put-text-property (match-beginning (nth 1 entry))
3309                                (match-end (nth 1 entry))
3310                                'gnus-callback nil))
3311           (set-marker marker nil)))
3312       ;; We skip the headers.
3313       (goto-char (point-min))
3314       (unless (search-forward "\n\n" nil t)
3315         (goto-char (point-max)))
3316       (setq beg (point))
3317       (while (setq entry (pop alist))
3318         (setq regexp (car entry))
3319         (goto-char beg)
3320         (while (re-search-forward regexp nil t)
3321           (let* ((start (and entry (match-beginning (nth 1 entry))))
3322                  (end (and entry (match-end (nth 1 entry))))
3323                  (from (match-beginning 0)))
3324             (when (and (or (eq t (nth 2 entry))
3325                            (eval (nth 2 entry)))
3326                        (not (gnus-button-in-region-p
3327                              start end 'gnus-callback)))
3328               ;; That optional form returned non-nil, so we add the
3329               ;; button.
3330               (gnus-article-add-button
3331                start end 'gnus-button-push
3332                (car (push (set-marker (make-marker) from)
3333                           gnus-button-marker-list))))))))))
3334
3335 ;; Add buttons to the head of an article.
3336 (defun gnus-article-add-buttons-to-head ()
3337   "Add buttons to the head of the article."
3338   (interactive)
3339   (save-excursion
3340     (set-buffer gnus-article-buffer)
3341     (let ((buffer-read-only nil)
3342           (inhibit-point-motion-hooks t)
3343           (case-fold-search t)
3344           (alist gnus-header-button-alist)
3345           entry beg end)
3346       (nnheader-narrow-to-headers)
3347       (while alist
3348         ;; Each alist entry.
3349         (setq entry (car alist)
3350               alist (cdr alist))
3351         (goto-char (point-min))
3352         (while (re-search-forward (car entry) nil t)
3353           ;; Each header matching the entry.
3354           (setq beg (match-beginning 0))
3355           (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3356                              (match-beginning 0))
3357                         (point-max)))
3358           (goto-char beg)
3359           (while (re-search-forward (nth 1 entry) end t)
3360             ;; Each match within a header.
3361             (let* ((entry (cdr entry))
3362                    (start (match-beginning (nth 1 entry)))
3363                    (end (match-end (nth 1 entry)))
3364                    (form (nth 2 entry)))
3365               (goto-char (match-end 0))
3366               (when (eval form)
3367                 (gnus-article-add-button
3368                  start end (nth 3 entry)
3369                  (buffer-substring (match-beginning (nth 4 entry))
3370                                    (match-end (nth 4 entry)))))))
3371           (goto-char end))))
3372     (widen)))
3373
3374 ;;; External functions:
3375
3376 (defun gnus-article-add-button (from to fun &optional data)
3377   "Create a button between FROM and TO with callback FUN and data DATA."
3378   (when gnus-article-button-face
3379     (gnus-overlay-put (gnus-make-overlay from to)
3380                       'face gnus-article-button-face))
3381   (gnus-add-text-properties
3382    from to
3383    (nconc (and gnus-article-mouse-face
3384                (list gnus-mouse-face-prop gnus-article-mouse-face))
3385           (list 'gnus-callback fun)
3386           (and data (list 'gnus-data data)))))
3387
3388 ;;; Internal functions:
3389
3390 (defun gnus-article-set-globals ()
3391   (save-excursion
3392     (set-buffer gnus-summary-buffer)
3393     (gnus-set-global-variables)))
3394
3395 (defun gnus-signature-toggle (end)
3396   (save-excursion
3397     (set-buffer gnus-article-buffer)
3398     (let ((buffer-read-only nil)
3399           (inhibit-point-motion-hooks t))
3400       (if (get-text-property end 'invisible)
3401           (gnus-article-unhide-text end (point-max))
3402         (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3403
3404 (defun gnus-button-entry ()
3405   ;; Return the first entry in `gnus-button-alist' matching this place.
3406   (let ((alist gnus-button-alist)
3407         (entry nil))
3408     (while alist
3409       (setq entry (pop alist))
3410       (if (looking-at (car entry))
3411           (setq alist nil)
3412         (setq entry nil)))
3413     entry))
3414
3415 (defun gnus-button-push (marker)
3416   ;; Push button starting at MARKER.
3417   (save-excursion
3418     (set-buffer gnus-article-buffer)
3419     (goto-char marker)
3420     (let* ((entry (gnus-button-entry))
3421            (inhibit-point-motion-hooks t)
3422            (fun (nth 3 entry))
3423            (args (mapcar (lambda (group)
3424                            (let ((string (match-string group)))
3425                              (gnus-set-text-properties
3426                               0 (length string) nil string)
3427                              string))
3428                          (nthcdr 4 entry))))
3429       (cond
3430        ((fboundp fun)
3431         (apply fun args))
3432        ((and (boundp fun)
3433              (fboundp (symbol-value fun)))
3434         (apply (symbol-value fun) args))
3435        (t
3436         (gnus-message 1 "You must define `%S' to use this button"
3437                       (cons fun args)))))))
3438
3439 (defun gnus-button-message-id (message-id)
3440   "Fetch MESSAGE-ID."
3441   (save-excursion
3442     (set-buffer gnus-summary-buffer)
3443     (gnus-summary-refer-article message-id)))
3444
3445 (defun gnus-button-fetch-group (address)
3446   "Fetch GROUP specified by ADDRESS."
3447   (if (not (string-match "[:/]" address))
3448       ;; This is just a simple group url.
3449       (gnus-group-read-ephemeral-group address gnus-select-method)
3450     (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3451                            address))
3452         (error "Can't parse %s" address)
3453       (gnus-group-read-ephemeral-group
3454        (match-string 4 address)
3455        `(nntp ,(match-string 1 address)
3456               (nntp-address ,(match-string 1 address))
3457               (nntp-port-number ,(if (match-end 3)
3458                                      (match-string 3 address)
3459                                    "nntp")))))))
3460
3461 (defun gnus-url-parse-query-string (query &optional downcase)
3462   (let (retval pairs cur key val)
3463     (setq pairs (split-string query "&"))
3464     (while pairs
3465       (setq cur (car pairs)
3466             pairs (cdr pairs))
3467       (if (not (string-match "=" cur))
3468           nil                           ; Grace
3469         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3470               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3471         (if downcase
3472             (setq key (downcase key)))
3473         (setq cur (assoc key retval))
3474         (if cur
3475             (setcdr cur (cons val (cdr cur)))
3476           (setq retval (cons (list key val) retval)))))
3477     retval))
3478
3479 (defun gnus-url-unhex (x)
3480   (if (> x ?9)
3481       (if (>= x ?a)
3482           (+ 10 (- x ?a))
3483         (+ 10 (- x ?A)))
3484     (- x ?0)))
3485
3486 (defun gnus-url-unhex-string (str &optional allow-newlines)
3487   "Remove %XXX embedded spaces, etc in a url.
3488 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3489 decoding of carriage returns and line feeds in the string, which is normally
3490 forbidden in URL encoding."
3491   (setq str (or str ""))
3492   (let ((tmp "")
3493         (case-fold-search t))
3494     (while (string-match "%[0-9a-f][0-9a-f]" str)
3495       (let* ((start (match-beginning 0))
3496              (ch1 (gnus-url-unhex (elt str (+ start 1))))
3497              (code (+ (* 16 ch1)
3498                       (gnus-url-unhex (elt str (+ start 2))))))
3499         (setq tmp (concat
3500                    tmp (substring str 0 start)
3501                    (cond
3502                     (allow-newlines
3503                      (char-to-string code))
3504                     ((or (= code ?\n) (= code ?\r))
3505                      " ")
3506                     (t (char-to-string code))))
3507               str (substring str (match-end 0)))))
3508     (setq tmp (concat tmp str))
3509     tmp))
3510
3511 (defun gnus-url-mailto (url)
3512   ;; Send mail to someone
3513   (when (string-match "mailto:/*\\(.*\\)" url)
3514     (setq url (substring url (match-beginning 1) nil)))
3515   (let (to args subject func)
3516     (if (string-match (regexp-quote "?") url)
3517         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3518               args (gnus-url-parse-query-string
3519                     (substring url (match-end 0) nil) t))
3520       (setq to (gnus-url-unhex-string url)))
3521     (setq args (cons (list "to" to) args)
3522           subject (cdr-safe (assoc "subject" args)))
3523     (gnus-setup-message 'reply
3524       (message-mail)
3525       (while args
3526         (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3527         (if (fboundp func)
3528             (funcall func)
3529           (message-position-on-field (caar args)))
3530         (insert (mapconcat 'identity (cdar args) ", "))
3531         (setq args (cdr args)))
3532       (if subject
3533           (message-goto-body)
3534         (message-goto-subject)))))
3535
3536 (defun gnus-button-mailto (address)
3537   ;; Mail to ADDRESS.
3538   (set-buffer (gnus-copy-article-buffer))
3539   (gnus-setup-message 'reply
3540     (message-reply address)))
3541
3542 (defun gnus-button-reply (address)
3543   ;; Reply to ADDRESS.
3544   (gnus-setup-message 'reply
3545     (message-reply address)))
3546
3547 (defun gnus-button-url (address)
3548   "Browse ADDRESS."
3549   ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3550   (if (listp browse-url-browser-function)
3551       (browse-url address)
3552     (funcall browse-url-browser-function address)))
3553
3554 (defun gnus-button-embedded-url (address)
3555   "Browse ADDRESS."
3556   ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3557   (if (listp browse-url-browser-function)
3558       (browse-url (gnus-strip-whitespace address))
3559     (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3560
3561 ;;; Next/prev buttons in the article buffer.
3562
3563 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3564 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3565
3566 (defvar gnus-prev-page-map nil)
3567 (unless gnus-prev-page-map
3568   (setq gnus-prev-page-map (make-sparse-keymap))
3569   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3570   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3571
3572 (defun gnus-insert-prev-page-button ()
3573   (let ((buffer-read-only nil))
3574     (gnus-eval-format
3575      gnus-prev-page-line-format nil
3576      `(gnus-prev t local-map ,gnus-prev-page-map
3577                  gnus-callback gnus-article-button-prev-page
3578                  gnus-type annotation))))
3579
3580 (defvar gnus-next-page-map nil)
3581 (unless gnus-next-page-map
3582   (setq gnus-next-page-map (make-keymap))
3583   (suppress-keymap gnus-prev-page-map)
3584   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3585   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3586
3587 (defun gnus-button-next-page ()
3588   "Go to the next page."
3589   (interactive)
3590   (let ((win (selected-window)))
3591     (select-window (get-buffer-window gnus-article-buffer t))
3592     (gnus-article-next-page)
3593     (select-window win)))
3594
3595 (defun gnus-button-prev-page ()
3596   "Go to the prev page."
3597   (interactive)
3598   (let ((win (selected-window)))
3599     (select-window (get-buffer-window gnus-article-buffer t))
3600     (gnus-article-prev-page)
3601     (select-window win)))
3602
3603 (defun gnus-insert-next-page-button ()
3604   (let ((buffer-read-only nil))
3605     (gnus-eval-format gnus-next-page-line-format nil
3606                       `(gnus-next
3607                         t local-map ,gnus-next-page-map
3608                         gnus-callback gnus-article-button-next-page
3609                         gnus-type annotation))))
3610
3611 (defun gnus-article-button-next-page (arg)
3612   "Go to the next page."
3613   (interactive "P")
3614   (let ((win (selected-window)))
3615     (select-window (get-buffer-window gnus-article-buffer t))
3616     (gnus-article-next-page)
3617     (select-window win)))
3618
3619 (defun gnus-article-button-prev-page (arg)
3620   "Go to the prev page."
3621   (interactive "P")
3622   (let ((win (selected-window)))
3623     (select-window (get-buffer-window gnus-article-buffer t))
3624     (gnus-article-prev-page)
3625     (select-window win)))
3626
3627
3628 ;;; @ for mime-view
3629 ;;;
3630
3631 (defun gnus-article-header-presentation-method (entity situation)
3632   (mime-insert-decoded-header entity)
3633   )
3634
3635 (set-alist 'mime-header-presentation-method-alist
3636            'gnus-original-article-mode
3637            #'gnus-article-header-presentation-method)
3638
3639 (defun gnus-mime-preview-quitting-method ()
3640   (if gnus-show-mime
3641       (gnus-article-show-summary)
3642     (mime-preview-kill-buffer)
3643     (delete-other-windows)
3644     (gnus-article-show-summary)
3645     (gnus-summary-select-article nil t)
3646     ))
3647
3648 (set-alist 'mime-preview-quitting-method-alist
3649            'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
3650
3651 (defun gnus-following-method (buf)
3652   (set-buffer buf)
3653   (message-followup)
3654   (message-yank-original)
3655   (kill-buffer buf)
3656   (goto-char (point-min))
3657   )
3658
3659 (set-alist 'mime-preview-following-method-alist
3660            'gnus-original-article-mode #'gnus-following-method)
3661
3662
3663 ;;; @ end
3664 ;;;
3665
3666 (gnus-ems-redefine)
3667
3668 (provide 'gnus-art)
3669
3670 (run-hooks 'gnus-art-load-hook)
3671
3672 ;;; gnus-art.el ends here