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