* gnus-int.el (gnus-request-accept-article): Use gnus-get-function.
[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-article-washing)
246
247 (defcustom gnus-article-x-face-too-ugly nil
248   "Regexp matching posters whose face shouldn't be shown automatically."
249   :type '(choice regexp (const nil))
250   :group 'gnus-article-washing)
251
252 (defcustom gnus-article-banner-alist nil
253   "Banner alist for stripping.
254 For example,
255      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
256   :version "21.1"
257   :type '(repeat (cons symbol regexp))
258   :group 'gnus-article-washing)
259
260 (gnus-define-group-parameter
261  banner
262  :variable-document
263  "Alist of regexps (to match group names) and banner."
264  :variable-group gnus-article-washing
265  :parameter-type
266  '(choice :tag "Banner"
267           :value nil
268           (const :tag "Remove signature" signature)
269           (symbol :tag "Item in `gnus-article-banner-alist'" none)
270           regexp
271           (const :tag "None" nil))
272  :parameter-document
273  "If non-nil, specify how to remove `banners' from articles.
274
275 Symbol `signature' means to remove signatures delimited by
276 `gnus-signature-separator'.  Any other symbol is used to look up a
277 regular expression to match the banner in `gnus-article-banner-alist'.
278 A string is used as a regular expression to match the banner
279 directly.")
280
281 (defcustom gnus-emphasis-alist
282   (let ((format
283          "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
284         (types
285          '(("\\*" "\\*" bold)
286            ("_" "_" underline)
287            ("/" "/" italic)
288            ("_/" "/_" underline-italic)
289            ("_\\*" "\\*_" underline-bold)
290            ("\\*/" "/\\*" bold-italic)
291            ("_\\*/" "/\\*_" underline-bold-italic))))
292     `(,@(mapcar
293          (lambda (spec)
294            (list
295             (format format (car spec) (cadr spec))
296             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
297          types)
298         ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
299          2 3 gnus-emphasis-underline)))
300   "*Alist that says how to fontify certain phrases.
301 Each item looks like this:
302
303   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
304
305 The first element is a regular expression to be matched.  The second
306 is a number that says what regular expression grouping used to find
307 the entire emphasized word.  The third is a number that says what
308 regexp grouping should be displayed and highlighted.  The fourth
309 is the face used for highlighting."
310   :type '(repeat (list :value ("" 0 0 default)
311                        regexp
312                        (integer :tag "Match group")
313                        (integer :tag "Emphasize group")
314                        face))
315   :group 'gnus-article-emphasis)
316
317 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
318   "A regexp to describe whitespace which should not be emphasized.
319 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
320 The former avoids underlining of leading and trailing whitespace,
321 and the latter avoids underlining any whitespace at all."
322   :version "21.1"
323   :group 'gnus-article-emphasis
324   :type 'regexp)
325
326 (defface gnus-emphasis-bold '((t (:bold t)))
327   "Face used for displaying strong emphasized text (*word*)."
328   :group 'gnus-article-emphasis)
329
330 (defface gnus-emphasis-italic '((t (:italic t)))
331   "Face used for displaying italic emphasized text (/word/)."
332   :group 'gnus-article-emphasis)
333
334 (defface gnus-emphasis-underline '((t (:underline t)))
335   "Face used for displaying underlined emphasized text (_word_)."
336   :group 'gnus-article-emphasis)
337
338 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
339   "Face used for displaying underlined bold emphasized text (_*word*_)."
340   :group 'gnus-article-emphasis)
341
342 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
343   "Face used for displaying underlined italic emphasized text (_/word/_)."
344   :group 'gnus-article-emphasis)
345
346 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
347   "Face used for displaying bold italic emphasized text (/*word*/)."
348   :group 'gnus-article-emphasis)
349
350 (defface gnus-emphasis-underline-bold-italic
351   '((t (:bold t :italic t :underline t)))
352   "Face used for displaying underlined bold italic emphasized text.
353 Esample: (_/*word*/_)."
354   :group 'gnus-article-emphasis)
355
356 (defface gnus-emphasis-highlight-words
357   '((t (:background "black" :foreground "yellow")))
358   "Face used for displaying highlighted words."
359   :group 'gnus-article-emphasis)
360
361 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
362   "Format for display of Date headers in article bodies.
363 See `format-time-string' for the possible values.
364
365 The variable can also be function, which should return a complete Date
366 header.  The function is called with one argument, the time, which can
367 be fed to `format-time-string'."
368   :type '(choice string symbol)
369   :link '(custom-manual "(gnus)Article Date")
370   :group 'gnus-article-washing)
371
372 (eval-and-compile
373   (autoload 'mail-extract-address-components "mail-extr"))
374
375 (defcustom gnus-save-all-headers t
376   "*If non-nil, don't remove any headers before saving."
377   :group 'gnus-article-saving
378   :type 'boolean)
379
380 (defcustom gnus-prompt-before-saving 'always
381   "*This variable says how much prompting is to be done when saving articles.
382 If it is nil, no prompting will be done, and the articles will be
383 saved to the default files.  If this variable is `always', each and
384 every article that is saved will be preceded by a prompt, even when
385 saving large batches of articles.  If this variable is neither nil not
386 `always', there the user will be prompted once for a file name for
387 each invocation of the saving commands."
388   :group 'gnus-article-saving
389   :type '(choice (item always)
390                  (item :tag "never" nil)
391                  (sexp :tag "once" :format "%t\n" :value t)))
392
393 (defcustom gnus-saved-headers gnus-visible-headers
394   "Headers to keep if `gnus-save-all-headers' is nil.
395 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
396 If that variable is nil, however, all headers that match this regexp
397 will be kept while the rest will be deleted before saving."
398   :group 'gnus-article-saving
399   :type 'regexp)
400
401 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
402   "A function to save articles in your favourite format.
403 The function must be interactively callable (in other words, it must
404 be an Emacs command).
405
406 Gnus provides the following functions:
407
408 * gnus-summary-save-in-rmail (Rmail format)
409 * gnus-summary-save-in-mail (Unix mail format)
410 * gnus-summary-save-in-folder (MH folder)
411 * gnus-summary-save-in-file (article format)
412 * gnus-summary-save-body-in-file (article body)
413 * gnus-summary-save-in-vm (use VM's folder format)
414 * gnus-summary-write-to-file (article format -- overwrite)."
415   :group 'gnus-article-saving
416   :type '(radio (function-item gnus-summary-save-in-rmail)
417                 (function-item gnus-summary-save-in-mail)
418                 (function-item gnus-summary-save-in-folder)
419                 (function-item gnus-summary-save-in-file)
420                 (function-item gnus-summary-save-body-in-file)
421                 (function-item gnus-summary-save-in-vm)
422                 (function-item gnus-summary-write-to-file)))
423
424 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
425   "A function generating a file name to save articles in Rmail format.
426 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
427   :group 'gnus-article-saving
428   :type 'function)
429
430 (defcustom gnus-mail-save-name 'gnus-plain-save-name
431   "A function generating a file name to save articles in Unix mail format.
432 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
433   :group 'gnus-article-saving
434   :type 'function)
435
436 (defcustom gnus-folder-save-name 'gnus-folder-save-name
437   "A function generating a file name to save articles in MH folder.
438 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
439   :group 'gnus-article-saving
440   :type 'function)
441
442 (defcustom gnus-file-save-name 'gnus-numeric-save-name
443   "A function generating a file name to save articles in article format.
444 The function is called with NEWSGROUP, HEADERS, and optional
445 LAST-FILE."
446   :group 'gnus-article-saving
447   :type 'function)
448
449 (defcustom gnus-split-methods
450   '((gnus-article-archive-name)
451     (gnus-article-nndoc-name))
452   "*Variable used to suggest where articles are to be saved.
453 For instance, if you would like to save articles related to Gnus in
454 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
455 you could set this variable to something like:
456
457  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
458    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
459
460 This variable is an alist where the where the key is the match and the
461 value is a list of possible files to save in if the match is non-nil.
462
463 If the match is a string, it is used as a regexp match on the
464 article.  If the match is a symbol, that symbol will be funcalled
465 from the buffer of the article to be saved with the newsgroup as the
466 parameter.  If it is a list, it will be evaled in the same buffer.
467
468 If this form or function returns a string, this string will be used as
469 a possible file name; and if it returns a non-nil list, that list will
470 be used as possible file names."
471   :group 'gnus-article-saving
472   :type '(repeat (choice (list :value (fun) function)
473                          (cons :value ("" "") regexp (repeat string))
474                          (sexp :value nil))))
475
476 (defcustom gnus-page-delimiter "^\^L"
477   "*Regexp describing what to use as article page delimiters.
478 The default value is \"^\^L\", which is a form linefeed at the
479 beginning of a line."
480   :type 'regexp
481   :group 'gnus-article-various)
482
483 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
484   "*The format specification for the article mode line.
485 See `gnus-summary-mode-line-format' for a closer description.
486
487 The following additional specs are available:
488
489 %w  The article washing status.
490 %m  The number of MIME parts in the article."
491   :type 'string
492   :group 'gnus-article-various)
493
494 (defcustom gnus-article-mode-hook nil
495   "*A hook for Gnus article mode."
496   :type 'hook
497   :group 'gnus-article-various)
498
499 (when (featurep 'xemacs)
500   ;; Extracted from gnus-xmas-define in order to preserve user settings
501   (when (fboundp 'turn-off-scroll-in-place)
502     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
503   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
504   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
505
506 (defcustom gnus-article-menu-hook nil
507   "*Hook run after the creation of the article mode menu."
508   :type 'hook
509   :group 'gnus-article-various)
510
511 (defcustom gnus-article-prepare-hook nil
512   "*A hook called after an article has been prepared in the article buffer."
513   :type 'hook
514   :group 'gnus-article-various)
515
516 (defcustom gnus-article-hide-pgp-hook nil
517   "*A hook called after successfully hiding a PGP signature."
518   :type 'hook
519   :group 'gnus-article-various)
520
521 (defcustom gnus-article-button-face 'bold
522   "Face used for highlighting buttons in the article buffer.
523
524 An article button is a piece of text that you can activate by pressing
525 `RET' or `mouse-2' above it."
526   :type 'face
527   :group 'gnus-article-buttons)
528
529 (defcustom gnus-article-mouse-face 'highlight
530   "Face used for mouse highlighting in the article buffer.
531
532 Article buttons will be displayed in this face when the cursor is
533 above them."
534   :type 'face
535   :group 'gnus-article-buttons)
536
537 (defcustom gnus-signature-face 'gnus-signature-face
538   "Face used for highlighting a signature in the article buffer.
539 Obsolete; use the face `gnus-signature-face' for customizations instead."
540   :type 'face
541   :group 'gnus-article-highlight
542   :group 'gnus-article-signature)
543
544 (defface gnus-signature-face
545   '((t
546      (:italic t)))
547   "Face used for highlighting a signature in the article buffer."
548   :group 'gnus-article-highlight
549   :group 'gnus-article-signature)
550
551 (defface gnus-header-from-face
552   '((((class color)
553       (background dark))
554      (:foreground "spring green"))
555     (((class color)
556       (background light))
557      (:foreground "red3"))
558     (t
559      (:italic t)))
560   "Face used for displaying from headers."
561   :group 'gnus-article-headers
562   :group 'gnus-article-highlight)
563
564 (defface gnus-header-subject-face
565   '((((class color)
566       (background dark))
567      (:foreground "SeaGreen3"))
568     (((class color)
569       (background light))
570      (:foreground "red4"))
571     (t
572      (:bold t :italic t)))
573   "Face used for displaying subject headers."
574   :group 'gnus-article-headers
575   :group 'gnus-article-highlight)
576
577 (defface gnus-header-newsgroups-face
578   '((((class color)
579       (background dark))
580      (:foreground "yellow" :italic t))
581     (((class color)
582       (background light))
583      (:foreground "MidnightBlue" :italic t))
584     (t
585      (:italic t)))
586   "Face used for displaying newsgroups headers."
587   :group 'gnus-article-headers
588   :group 'gnus-article-highlight)
589
590 (defface gnus-header-name-face
591   '((((class color)
592       (background dark))
593      (:foreground "SeaGreen"))
594     (((class color)
595       (background light))
596      (:foreground "maroon"))
597     (t
598      (:bold t)))
599   "Face used for displaying header names."
600   :group 'gnus-article-headers
601   :group 'gnus-article-highlight)
602
603 (defface gnus-header-content-face
604   '((((class color)
605       (background dark))
606      (:foreground "forest green" :italic t))
607     (((class color)
608       (background light))
609      (:foreground "indianred4" :italic t))
610     (t
611      (:italic t)))  "Face used for displaying header content."
612   :group 'gnus-article-headers
613   :group 'gnus-article-highlight)
614
615 (defcustom gnus-header-face-alist
616   '(("From" nil gnus-header-from-face)
617     ("Subject" nil gnus-header-subject-face)
618     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
619     ("" gnus-header-name-face gnus-header-content-face))
620   "*Controls highlighting of article header.
621
622 An alist of the form (HEADER NAME CONTENT).
623
624 HEADER is a regular expression which should match the name of an
625 header header and NAME and CONTENT are either face names or nil.
626
627 The name of each header field will be displayed using the face
628 specified by the first element in the list where HEADER match the
629 header name and NAME is non-nil.  Similarly, the content will be
630 displayed by the first non-nil matching CONTENT face."
631   :group 'gnus-article-headers
632   :group 'gnus-article-highlight
633   :type '(repeat (list (regexp :tag "Header")
634                        (choice :tag "Name"
635                                (item :tag "skip" nil)
636                                (face :value default))
637                        (choice :tag "Content"
638                                (item :tag "skip" nil)
639                                (face :value default)))))
640
641 (defcustom gnus-article-decode-hook
642   '(article-decode-charset article-decode-encoded-words
643                            article-decode-group-name)
644   "*Hook run to decode charsets in articles."
645   :group 'gnus-article-headers
646   :type 'hook)
647
648 (defcustom gnus-display-mime-function 'gnus-display-mime
649   "Function to display MIME articles."
650   :group 'gnus-article-mime
651   :type 'function)
652
653 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
654   "Function used to decode headers.")
655
656 (defvar gnus-article-dumbquotes-map
657   '(("\200" "EUR")
658     ("\202" ",")
659     ("\203" "f")
660     ("\204" ",,")
661     ("\205" "...")
662     ("\213" "<")
663     ("\214" "OE")
664     ("\221" "`")
665     ("\222" "'")
666     ("\223" "``")
667     ("\224" "\"")
668     ("\225" "*")
669     ("\226" "-")
670     ("\227" "--")
671     ("\231" "(TM)")
672     ("\233" ">")
673     ("\234" "oe")
674     ("\264" "'"))
675   "Table for MS-to-Latin1 translation.")
676
677 (defcustom gnus-ignored-mime-types nil
678   "List of MIME types that should be ignored by Gnus."
679   :version "21.1"
680   :group 'gnus-article-mime
681   :type '(repeat regexp))
682
683 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
684   "List of MIME types that should not be given buttons when rendered inline.
685 See also `gnus-buttonized-mime-types' which may override this variable."
686   :version "21.1"
687   :group 'gnus-article-mime
688   :type '(repeat regexp))
689
690 (defcustom gnus-buttonized-mime-types nil
691   "List of MIME types that should be given buttons when rendered inline.
692 If set, this variable overrides `gnus-unbuttonized-mime-types'.
693 To see e.g. security buttons you could set this to
694 `(\"multipart/signed\")'."
695   :version "21.1"
696   :group 'gnus-article-mime
697   :type '(repeat regexp))
698
699 (defcustom gnus-body-boundary-delimiter "_"
700   "String used to delimit header and body.
701 This variable is used by `gnus-article-treat-body-boundary' which can
702 be controlled by `gnus-treat-body-boundary'."
703   :group 'gnus-article-various
704   :type '(choice (item :tag "None" :value nil)
705                  string))
706
707 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces")
708   "*Defines the location of the faces database.
709 For information on obtaining this database of pretty pictures, please
710 see http://www.cs.indiana.edu/picons/ftp/index.html"
711   :type 'directory
712   :group 'gnus-picon)
713
714 (defun gnus-picons-installed-p ()
715   "Say whether picons are installed on your machine."
716   (let ((installed nil))
717     (dolist (database gnus-picon-databases)
718       (when (file-exists-p database)
719         (setq installed t)))
720     installed))
721
722 (defcustom gnus-article-mime-part-function nil
723   "Function called with a MIME handle as the argument.
724 This is meant for people who want to do something automatic based
725 on parts -- for instance, adding Vcard info to a database."
726   :group 'gnus-article-mime
727   :type 'function)
728
729 (defcustom gnus-mime-multipart-functions nil
730   "An alist of MIME types to functions to display them."
731   :version "21.1"
732   :group 'gnus-article-mime
733   :type 'alist)
734
735 (defcustom gnus-article-date-lapsed-new-header nil
736   "Whether the X-Sent and Date headers can coexist.
737 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
738 either replace the old \"Date:\" header (if this variable is nil), or
739 be added below it (otherwise)."
740   :version "21.1"
741   :group 'gnus-article-headers
742   :type 'boolean)
743
744 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
745   "Function called with a MIME handle as the argument.
746 This is meant for people who want to view first matched part.
747 For `undisplayed-alternative' (default), the first undisplayed
748 part or alternative part is used.  For `undisplayed', the first
749 undisplayed part is used.  For a function, the first part which
750 the function return `t' is used.  For `nil', the first part is
751 used."
752   :version "21.1"
753   :group 'gnus-article-mime
754   :type '(choice
755           (item :tag "first" :value nil)
756           (item :tag "undisplayed" :value undisplayed)
757           (item :tag "undisplayed or alternative"
758                 :value undisplayed-alternative)
759           (function)))
760
761 (defcustom gnus-mime-action-alist
762   '(("save to file" . gnus-mime-save-part)
763     ("save and strip" . gnus-mime-save-part-and-strip)
764     ("display as text" . gnus-mime-inline-part)
765     ("view the part" . gnus-mime-view-part)
766     ("pipe to command" . gnus-mime-pipe-part)
767     ("toggle display" . gnus-article-press-button)
768     ("toggle display" . gnus-article-view-part-as-charset)
769     ("view as type" . gnus-mime-view-part-as-type)
770     ("internalize type" . gnus-mime-internalize-part)
771     ("externalize type" . gnus-mime-externalize-part))
772   "An alist of actions that run on the MIME attachment."
773   :group 'gnus-article-mime
774   :type '(repeat (cons (string :tag "name")
775                        (function))))
776
777 (defcustom gnus-mime-action-alist
778   '(("save to file" . gnus-mime-save-part)
779     ("display as text" . gnus-mime-inline-part)
780     ("view the part" . gnus-mime-view-part)
781     ("pipe to command" . gnus-mime-pipe-part)
782     ("toggle display" . gnus-article-press-button)
783     ("view as type" . gnus-mime-view-part-as-type)
784     ("internalize type" . gnus-mime-internalize-part)
785     ("externalize type" . gnus-mime-externalize-part))
786   "An alist of actions that run on the MIME attachment."
787   :version "21.1"
788   :group 'gnus-article-mime
789   :type '(repeat (cons (string :tag "name")
790                        (function))))
791
792 ;;;
793 ;;; The treatment variables
794 ;;;
795
796 (defvar gnus-part-display-hook nil
797   "Hook called on parts that are to receive treatment.")
798
799 (defvar gnus-article-treat-custom
800   '(choice (const :tag "Off" nil)
801            (const :tag "On" t)
802            (const :tag "Header" head)
803            (const :tag "Last" last)
804            (integer :tag "Less")
805            (repeat :tag "Groups" regexp)
806            (sexp :tag "Predicate")))
807
808 (defvar gnus-article-treat-head-custom
809   '(choice (const :tag "Off" nil)
810            (const :tag "Header" head)))
811
812 (defvar gnus-article-treat-types '("text/plain")
813   "Parts to treat.")
814
815 (defvar gnus-inhibit-treatment nil
816   "Whether to inhibit treatment.")
817
818 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
819   "Highlight the signature.
820 Valid values are nil, t, `head', `last', an integer or a predicate.
821 See Info node `(gnus)Customizing Articles'."
822   :group 'gnus-article-treat
823   :type gnus-article-treat-custom)
824 (put 'gnus-treat-highlight-signature 'highlight t)
825
826 (defcustom gnus-treat-buttonize 100000
827   "Add buttons.
828 Valid values are nil, t, `head', `last', an integer or a predicate.
829 See Info node `(gnus)Customizing Articles'."
830   :group 'gnus-article-treat
831   :type gnus-article-treat-custom)
832 (put 'gnus-treat-buttonize 'highlight t)
833
834 (defcustom gnus-treat-buttonize-head 'head
835   "Add buttons to the head.
836 Valid values are nil, t, `head', `last', an integer or a predicate.
837 See Info node `(gnus)Customizing Articles' for details."
838   :group 'gnus-article-treat
839   :type gnus-article-treat-head-custom)
840 (put 'gnus-treat-buttonize-head 'highlight t)
841
842 (defcustom gnus-treat-emphasize
843   (and (or window-system
844            (featurep 'xemacs)
845            (>= (string-to-number emacs-version) 21))
846        50000)
847   "Emphasize text.
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See Info node `(gnus)Customizing Articles' for details."
850   :group 'gnus-article-treat
851   :type gnus-article-treat-custom)
852 (put 'gnus-treat-emphasize 'highlight t)
853
854 (defcustom gnus-treat-strip-cr nil
855   "Remove carriage returns.
856 Valid values are nil, t, `head', `last', an integer or a predicate.
857 See Info node `(gnus)Customizing Articles' for details."
858   :group 'gnus-article-treat
859   :type gnus-article-treat-custom)
860
861 (defcustom gnus-treat-leading-whitespace nil
862   "Remove leading whitespace in headers.
863 Valid values are nil, t, `head', `last', an integer or a predicate.
864 See Info node `(gnus)Customizing Articles' for details."
865   :group 'gnus-article-treat
866   :type gnus-article-treat-custom)
867
868 (defcustom gnus-treat-hide-headers 'head
869   "Hide headers.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See Info node `(gnus)Customizing Articles' for details."
872   :group 'gnus-article-treat
873   :type gnus-article-treat-head-custom)
874
875 (defcustom gnus-treat-hide-boring-headers nil
876   "Hide boring headers.
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See Info node `(gnus)Customizing Articles' for details."
879   :group 'gnus-article-treat
880   :type gnus-article-treat-head-custom)
881
882 (defcustom gnus-treat-hide-signature nil
883   "Hide the signature.
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   :type gnus-article-treat-custom)
888
889 (defcustom gnus-treat-fill-article nil
890   "Fill the article.
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See Info node `(gnus)Customizing Articles' for details."
893   :group 'gnus-article-treat
894   :type gnus-article-treat-custom)
895
896 (defcustom gnus-treat-hide-citation nil
897   "Hide cited text.
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See Info node `(gnus)Customizing Articles' for details."
900   :group 'gnus-article-treat
901   :type gnus-article-treat-custom)
902
903 (defcustom gnus-treat-hide-citation-maybe nil
904   "Hide cited text.
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See Info node `(gnus)Customizing Articles' for details."
907   :group 'gnus-article-treat
908   :type gnus-article-treat-custom)
909
910 (defcustom gnus-treat-strip-list-identifiers 'head
911   "Strip list identifiers from `gnus-list-identifiers`.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See Info node `(gnus)Customizing Articles' for details."
914   :version "21.1"
915   :group 'gnus-article-treat
916   :type gnus-article-treat-custom)
917
918 (defcustom gnus-treat-strip-pgp t
919   "Strip PGP signatures.
920 Valid values are nil, t, `head', `last', an integer or a predicate.
921 See Info node `(gnus)Customizing Articles' for details."
922   :group 'gnus-article-treat
923   :type gnus-article-treat-custom)
924
925 (defcustom gnus-treat-strip-pem nil
926   "Strip PEM signatures.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See Info node `(gnus)Customizing Articles' for details."
929   :group 'gnus-article-treat
930   :type gnus-article-treat-custom)
931
932 (defcustom gnus-treat-strip-banner t
933   "Strip banners from articles.
934 The banner to be stripped is specified in the `banner' group parameter.
935 Valid values are nil, t, `head', `last', an integer or a predicate.
936 See Info node `(gnus)Customizing Articles' for details."
937   :group 'gnus-article-treat
938   :type gnus-article-treat-custom)
939
940 (defcustom gnus-treat-highlight-headers 'head
941   "Highlight the headers.
942 Valid values are nil, t, `head', `last', an integer or a predicate.
943 See Info node `(gnus)Customizing Articles' for details."
944   :group 'gnus-article-treat
945   :type gnus-article-treat-head-custom)
946 (put 'gnus-treat-highlight-headers 'highlight t)
947
948 (defcustom gnus-treat-highlight-citation t
949   "Highlight cited text.
950 Valid values are nil, t, `head', `last', an integer or a predicate.
951 See Info node `(gnus)Customizing Articles' for details."
952   :group 'gnus-article-treat
953   :type gnus-article-treat-custom)
954 (put 'gnus-treat-highlight-citation 'highlight t)
955
956 (defcustom gnus-treat-date-ut nil
957   "Display the Date in UT (GMT).
958 Valid values are nil, t, `head', `last', an integer or a predicate.
959 See Info node `(gnus)Customizing Articles' for details."
960   :group 'gnus-article-treat
961   :type gnus-article-treat-head-custom)
962
963 (defcustom gnus-treat-date-local nil
964   "Display the Date in the local timezone.
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   :type gnus-article-treat-head-custom)
969
970 (defcustom gnus-treat-date-english nil
971   "Display the Date in a format that can be read aloud in English.
972 Valid values are nil, t, `head', `last', an integer or a predicate.
973 See Info node `(gnus)Customizing Articles' for details."
974   :group 'gnus-article-treat
975   :type gnus-article-treat-head-custom)
976
977 (defcustom gnus-treat-date-lapsed nil
978   "Display the Date header in a way that says how much time has elapsed.
979 Valid values are nil, t, `head', `last', an integer or a predicate.
980 See Info node `(gnus)Customizing Articles' for details."
981   :group 'gnus-article-treat
982   :type gnus-article-treat-head-custom)
983
984 (defcustom gnus-treat-date-original nil
985   "Display the date in the original timezone.
986 Valid values are nil, t, `head', `last', an integer or a predicate.
987 See Info node `(gnus)Customizing Articles' for details."
988   :group 'gnus-article-treat
989   :type gnus-article-treat-head-custom)
990
991 (defcustom gnus-treat-date-iso8601 nil
992   "Display the date in the ISO8601 format.
993 Valid values are nil, t, `head', `last', an integer or a predicate.
994 See Info node `(gnus)Customizing Articles' for details."
995   :version "21.1"
996   :group 'gnus-article-treat
997   :type gnus-article-treat-head-custom)
998
999 (defcustom gnus-treat-date-user-defined nil
1000   "Display the date in a user-defined format.
1001 The format is defined by the `gnus-article-time-format' variable.
1002 Valid values are nil, t, `head', `last', an integer or a predicate.
1003 See Info node `(gnus)Customizing Articles' for details."
1004   :group 'gnus-article-treat
1005   :type gnus-article-treat-head-custom)
1006
1007 (defcustom gnus-treat-strip-headers-in-body t
1008   "Strip the X-No-Archive header line from the beginning of the body.
1009 Valid values are nil, t, `head', `last', an integer or a predicate.
1010 See Info node `(gnus)Customizing Articles' for details."
1011   :version "21.1"
1012   :group 'gnus-article-treat
1013   :type gnus-article-treat-custom)
1014
1015 (defcustom gnus-treat-strip-trailing-blank-lines nil
1016   "Strip trailing blank lines.
1017 Valid values are nil, t, `head', `last', an integer or a predicate.
1018 See Info node `(gnus)Customizing Articles' for details."
1019   :group 'gnus-article-treat
1020   :type gnus-article-treat-custom)
1021
1022 (defcustom gnus-treat-strip-leading-blank-lines nil
1023   "Strip leading blank lines.
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   :type gnus-article-treat-custom)
1028
1029 (defcustom gnus-treat-strip-multiple-blank-lines nil
1030   "Strip multiple blank lines.
1031 Valid values are nil, t, `head', `last', an integer or a predicate.
1032 See Info node `(gnus)Customizing Articles' for details."
1033   :group 'gnus-article-treat
1034   :type gnus-article-treat-custom)
1035
1036 (defcustom gnus-treat-unfold-headers 'head
1037   "Unfold folded header lines.
1038 Valid values are nil, t, `head', `last', an integer or a predicate.
1039 See Info node `(gnus)Customizing Articles' for details."
1040   :group 'gnus-article-treat
1041   :type gnus-article-treat-custom)
1042
1043 (defcustom gnus-treat-fold-headers nil
1044   "Fold headers.
1045 Valid values are nil, t, `head', `last', an integer or a predicate.
1046 See Info node `(gnus)Customizing Articles' for details."
1047   :group 'gnus-article-treat
1048   :type gnus-article-treat-custom)
1049
1050 (defcustom gnus-treat-fold-newsgroups 'head
1051   "Fold the Newsgroups and Followup-To headers.
1052 Valid values are nil, t, `head', `last', an integer or a predicate.
1053 See Info node `(gnus)Customizing Articles' for details."
1054   :group 'gnus-article-treat
1055   :type gnus-article-treat-custom)
1056
1057 (defcustom gnus-treat-overstrike t
1058   "Treat overstrike highlighting.
1059 Valid values are nil, t, `head', `last', an integer or a predicate.
1060 See Info node `(gnus)Customizing Articles' for details."
1061   :group 'gnus-article-treat
1062   :type gnus-article-treat-custom)
1063 (put 'gnus-treat-overstrike 'highlight t)
1064
1065 (defcustom gnus-treat-display-xface
1066   (and (or (and (fboundp 'image-type-available-p)
1067                 (image-type-available-p 'xbm)
1068                 (string-match "^0x" (shell-command-to-string "uncompface")))
1069            (and (featurep 'xemacs)
1070                 (featurep 'xface)))
1071        'head)
1072   "Display X-Face headers.
1073 Valid values are nil, t, `head', `last', an integer or a predicate.
1074 See Info node `(gnus)Customizing Articles' and Info node
1075 `(gnus)X-Face' for details."
1076   :group 'gnus-article-treat
1077   :version "21.1"
1078   :type gnus-article-treat-head-custom)
1079 (put 'gnus-treat-display-xface 'highlight t)
1080
1081 (defcustom gnus-treat-display-smileys
1082   (if (or (and (featurep 'xemacs)
1083                (featurep 'xpm))
1084           (and (fboundp 'image-type-available-p)
1085                (image-type-available-p 'pbm)))
1086       t nil)
1087   "Display smileys.
1088 Valid values are nil, t, `head', `last', an integer or a predicate.
1089 See Info node `(gnus)Customizing Articles' and Info node
1090 `(gnus)Smileys' for details."
1091   :group 'gnus-article-treat
1092   :version "21.1"
1093   :type gnus-article-treat-custom)
1094 (put 'gnus-treat-display-smileys 'highlight t)
1095
1096 (defcustom gnus-treat-from-picon
1097   (if (and (gnus-image-type-available-p 'xpm)
1098            (gnus-picons-installed-p))
1099       'head nil)
1100   "Display picons in the From header.
1101 Valid values are nil, t, `head', `last', an integer or a predicate.
1102 See Info node `(gnus)Customizing Articles' and Info node
1103 `(gnus)Picons' for details."
1104   :group 'gnus-article-treat
1105   :type gnus-article-treat-head-custom)
1106 (put 'gnus-treat-from-picon 'highlight t)
1107
1108 (defcustom gnus-treat-mail-picon
1109   (if (and (gnus-image-type-available-p 'xpm)
1110            (gnus-picons-installed-p))
1111       'head nil)
1112   "Display picons in To and Cc headers.
1113 Valid values are nil, t, `head', `last', an integer or a predicate.
1114 See Info node `(gnus)Customizing Articles' and Info node
1115 `(gnus)Picons' for details."
1116   :group 'gnus-article-treat
1117   :type gnus-article-treat-head-custom)
1118 (put 'gnus-treat-mail-picon 'highlight t)
1119
1120 (defcustom gnus-treat-newsgroups-picon
1121   (if (and (gnus-image-type-available-p 'xpm)
1122            (gnus-picons-installed-p))
1123       'head nil)
1124   "Display picons in the Newsgroups and Followup-To headers.
1125 Valid values are nil, t, `head', `last', an integer or a predicate.
1126 See Info node `(gnus)Customizing Articles' and Info node
1127 `(gnus)Picons' for details."
1128   :group 'gnus-article-treat
1129   :type gnus-article-treat-head-custom)
1130 (put 'gnus-treat-newsgroups-picon 'highlight t)
1131
1132 (defcustom gnus-treat-body-boundary
1133   (if (or gnus-treat-newsgroups-picon
1134           gnus-treat-mail-picon
1135           gnus-treat-from-picon)
1136       'head nil)
1137   "Draw a boundary at the end of the headers.
1138 Valid values are nil, t, `head', `last', an integer or a predicate.
1139 See Info node `(gnus)Customizing Articles' for details."
1140   :version "21.1"
1141   :group 'gnus-article-treat
1142   :type gnus-article-treat-custom)
1143
1144 (defcustom gnus-treat-capitalize-sentences nil
1145   "Capitalize sentence-starting words.
1146 Valid values are nil, t, `head', `last', an integer or a predicate.
1147 See Info node `(gnus)Customizing Articles' for details."
1148   :version "21.1"
1149   :group 'gnus-article-treat
1150   :type gnus-article-treat-custom)
1151
1152 (defcustom gnus-treat-fill-long-lines nil
1153   "Fill long lines.
1154 Valid values are nil, t, `head', `last', an integer or a predicate.
1155 See Info node `(gnus)Customizing Articles' for details."
1156   :group 'gnus-article-treat
1157   :type gnus-article-treat-custom)
1158
1159 (defcustom gnus-treat-play-sounds nil
1160   "Play sounds.
1161 Valid values are nil, t, `head', `last', an integer or a predicate.
1162 See Info node `(gnus)Customizing Articles' for details."
1163   :version "21.1"
1164   :group 'gnus-article-treat
1165   :type gnus-article-treat-custom)
1166
1167 (defcustom gnus-treat-translate nil
1168   "Translate articles from one language to another.
1169 Valid values are nil, t, `head', `last', an integer or a predicate.
1170 See Info node `(gnus)Customizing Articles' for details."
1171   :version "21.1"
1172   :group 'gnus-article-treat
1173   :type gnus-article-treat-custom)
1174
1175 (defcustom gnus-treat-x-pgp-sig nil
1176   "Verify X-PGP-Sig.
1177 To automatically treat X-PGP-Sig, set it to head.
1178 Valid values are nil, t, `head', `last', an integer or a predicate.
1179 See Info node `(gnus)Customizing Articles' for details."
1180   :group 'gnus-article-treat
1181   :group 'mime-security
1182   :type gnus-article-treat-custom)
1183
1184 (defvar gnus-article-encrypt-protocol-alist
1185   '(("PGP" . mml2015-self-encrypt)))
1186
1187 ;; Set to nil if more than one protocol added to
1188 ;; gnus-article-encrypt-protocol-alist.
1189 (defcustom gnus-article-encrypt-protocol "PGP"
1190   "The protocol used for encrypt articles.
1191 It is a string, such as \"PGP\". If nil, ask user."
1192   :type 'string
1193   :group 'mime-security)
1194
1195 (defcustom gnus-article-wash-function
1196   (cond ((locate-library "w3")
1197          'gnus-article-wash-html-with-w3)
1198         ((locate-library "w3m")
1199          'gnus-article-wash-html-with-w3m))
1200   "Function used for converting HTML into text."
1201   :type '(radio (function-item gnus-article-wash-html-with-w3)
1202                 (function-item gnus-article-wash-html-with-w3m))
1203   :group 'gnus-article)
1204
1205 ;;; Internal variables
1206
1207 (defvar gnus-english-month-names
1208   '("January" "February" "March" "April" "May" "June" "July" "August"
1209     "September" "October" "November" "December"))
1210
1211 (defvar article-goto-body-goes-to-point-min-p nil)
1212 (defvar gnus-article-wash-types nil)
1213 (defvar gnus-article-emphasis-alist nil)
1214 (defvar gnus-article-image-alist nil)
1215
1216 (defvar gnus-article-mime-handle-alist-1 nil)
1217 (defvar gnus-treatment-function-alist
1218   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1219     (gnus-treat-strip-banner gnus-article-strip-banner)
1220     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1221     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1222     (gnus-treat-buttonize gnus-article-add-buttons)
1223     (gnus-treat-fill-article gnus-article-fill-cited-article)
1224     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1225     (gnus-treat-strip-cr gnus-article-remove-cr)
1226     (gnus-treat-date-ut gnus-article-date-ut)
1227     (gnus-treat-date-local gnus-article-date-local)
1228     (gnus-treat-date-english gnus-article-date-english)
1229     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1230     (gnus-treat-date-original gnus-article-date-original)
1231     (gnus-treat-date-user-defined gnus-article-date-user)
1232     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1233     (gnus-treat-display-xface gnus-article-display-x-face)
1234     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1235     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1236     (gnus-treat-hide-signature gnus-article-hide-signature)
1237     (gnus-treat-hide-citation gnus-article-hide-citation)
1238     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1239     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1240     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1241     (gnus-treat-strip-pgp gnus-article-hide-pgp)
1242     (gnus-treat-strip-pem gnus-article-hide-pem)
1243     (gnus-treat-from-picon gnus-treat-from-picon)
1244     (gnus-treat-mail-picon gnus-treat-mail-picon)
1245     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1246     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1247     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1248     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1249     (gnus-treat-strip-trailing-blank-lines
1250      gnus-article-remove-trailing-blank-lines)
1251     (gnus-treat-strip-leading-blank-lines
1252      gnus-article-strip-leading-blank-lines)
1253     (gnus-treat-strip-multiple-blank-lines
1254      gnus-article-strip-multiple-blank-lines)
1255     (gnus-treat-overstrike gnus-article-treat-overstrike)
1256     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1257     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1258     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1259     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1260     (gnus-treat-display-smileys gnus-treat-smiley)
1261     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1262     (gnus-treat-emphasize gnus-article-emphasize)
1263     (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1264     (gnus-treat-play-sounds gnus-earcon-display)))
1265
1266 (defvar gnus-article-mime-handle-alist nil)
1267 (defvar article-lapsed-timer nil)
1268 (defvar gnus-article-current-summary nil)
1269
1270 (defvar gnus-article-mode-syntax-table
1271   (let ((table (copy-syntax-table text-mode-syntax-table)))
1272     ;; This causes the citation match run O(2^n).
1273     ;; (modify-syntax-entry ?- "w" table)
1274     (modify-syntax-entry ?> ")" table)
1275     (modify-syntax-entry ?< "(" table)
1276     table)
1277   "Syntax table used in article mode buffers.
1278 Initialized from `text-mode-syntax-table.")
1279
1280 (defvar gnus-save-article-buffer nil)
1281
1282 (defvar gnus-article-mode-line-format-alist
1283   (nconc '((?w (gnus-article-wash-status) ?s)
1284            (?m (gnus-article-mime-part-status) ?s))
1285          gnus-summary-mode-line-format-alist))
1286
1287 (defvar gnus-number-of-articles-to-be-saved nil)
1288
1289 (defvar gnus-inhibit-hiding nil)
1290
1291 ;;; Macros for dealing with the article buffer.
1292
1293 (defmacro gnus-with-article-headers (&rest forms)
1294   `(save-excursion
1295      (set-buffer gnus-article-buffer)
1296      (save-restriction
1297        (let ((buffer-read-only nil)
1298              (inhibit-point-motion-hooks t)
1299              (case-fold-search t))
1300          (article-narrow-to-head)
1301          ,@forms))))
1302
1303 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1304 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1305
1306 (defmacro gnus-with-article-buffer (&rest forms)
1307   `(save-excursion
1308      (set-buffer gnus-article-buffer)
1309      (let ((buffer-read-only nil))
1310        ,@forms)))
1311
1312 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1313 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1314
1315 (defun gnus-article-goto-header (header)
1316   "Go to HEADER, which is a regular expression."
1317   (re-search-forward (concat "^\\(" header "\\):") nil t))
1318
1319 (defsubst gnus-article-hide-text (b e props)
1320   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1321   (gnus-add-text-properties-when 'article-type nil b e props)
1322   (when (memq 'intangible props)
1323     (put-text-property
1324      (max (1- b) (point-min))
1325      b 'intangible (cddr (memq 'intangible props)))))
1326
1327 (defsubst gnus-article-unhide-text (b e)
1328   "Remove hidden text properties from region between B and E."
1329   (remove-text-properties b e gnus-hidden-properties)
1330   (when (memq 'intangible gnus-hidden-properties)
1331     (put-text-property (max (1- b) (point-min))
1332                        b 'intangible nil)))
1333
1334 (defun gnus-article-hide-text-type (b e type)
1335   "Hide text of TYPE between B and E."
1336   (gnus-add-wash-type type)
1337   (gnus-article-hide-text
1338    b e (cons 'article-type (cons type gnus-hidden-properties))))
1339
1340 (defun gnus-article-unhide-text-type (b e type)
1341   "Unhide text of TYPE between B and E."
1342   (gnus-delete-wash-type type)
1343   (remove-text-properties
1344    b e (cons 'article-type (cons type gnus-hidden-properties)))
1345   (when (memq 'intangible gnus-hidden-properties)
1346     (put-text-property (max (1- b) (point-min))
1347                        b 'intangible nil)))
1348
1349 (defun gnus-article-hide-text-of-type (type)
1350   "Hide text of TYPE in the current buffer."
1351   (save-excursion
1352     (let ((b (point-min))
1353           (e (point-max)))
1354       (while (setq b (text-property-any b e 'article-type type))
1355         (add-text-properties b (incf b) gnus-hidden-properties)))))
1356
1357 (defun gnus-article-delete-text-of-type (type)
1358   "Delete text of TYPE in the current buffer."
1359   (save-excursion
1360     (let ((b (point-min)))
1361       (while (setq b (text-property-any b (point-max) 'article-type type))
1362         (delete-region
1363          b (or (text-property-not-all b (point-max) 'article-type type)
1364                (point-max)))))))
1365
1366 (defun gnus-article-delete-invisible-text ()
1367   "Delete all invisible text in the current buffer."
1368   (save-excursion
1369     (let ((b (point-min)))
1370       (while (setq b (text-property-any b (point-max) 'invisible t))
1371         (delete-region
1372          b (or (text-property-not-all b (point-max) 'invisible t)
1373                (point-max)))))))
1374
1375 (defun gnus-article-text-type-exists-p (type)
1376   "Say whether any text of type TYPE exists in the buffer."
1377   (text-property-any (point-min) (point-max) 'article-type type))
1378
1379 (defsubst gnus-article-header-rank ()
1380   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1381   (let ((list gnus-sorted-header-list)
1382         (i 0))
1383     (while list
1384       (when (looking-at (car list))
1385         (setq list nil))
1386       (setq list (cdr list))
1387       (incf i))
1388     i))
1389
1390 (defun article-hide-headers (&optional arg delete)
1391   "Hide unwanted headers and possibly sort them as well."
1392   (interactive)
1393   ;; This function might be inhibited.
1394   (unless gnus-inhibit-hiding
1395     (save-excursion
1396       (save-restriction
1397         (let ((buffer-read-only nil)
1398               (case-fold-search t)
1399               (max (1+ (length gnus-sorted-header-list)))
1400               (ignored (when (not gnus-visible-headers)
1401                          (cond ((stringp gnus-ignored-headers)
1402                                 gnus-ignored-headers)
1403                                ((listp gnus-ignored-headers)
1404                                 (mapconcat 'identity gnus-ignored-headers
1405                                            "\\|")))))
1406               (visible
1407                (cond ((stringp gnus-visible-headers)
1408                       gnus-visible-headers)
1409                      ((and gnus-visible-headers
1410                            (listp gnus-visible-headers))
1411                       (mapconcat 'identity gnus-visible-headers "\\|"))))
1412               (inhibit-point-motion-hooks t)
1413               beg)
1414           ;; First we narrow to just the headers.
1415           (article-narrow-to-head)
1416           ;; Hide any "From " lines at the beginning of (mail) articles.
1417           (while (looking-at "From ")
1418             (forward-line 1))
1419           (unless (bobp)
1420             (delete-region (point-min) (point)))
1421           ;; Then treat the rest of the header lines.
1422           ;; Then we use the two regular expressions
1423           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1424           ;; select which header lines is to remain visible in the
1425           ;; article buffer.
1426           (while (re-search-forward "^[^ \t:]*:" nil t)
1427             (beginning-of-line)
1428             ;; Mark the rank of the header.
1429             (put-text-property
1430              (point) (1+ (point)) 'message-rank
1431              (if (or (and visible (looking-at visible))
1432                      (and ignored
1433                           (not (looking-at ignored))))
1434                  (gnus-article-header-rank)
1435                (+ 2 max)))
1436             (forward-line 1))
1437           (message-sort-headers-1)
1438           (when (setq beg (text-property-any
1439                            (point-min) (point-max) 'message-rank (+ 2 max)))
1440             ;; We delete the unwanted headers.
1441             (gnus-add-wash-type 'headers)
1442             (add-text-properties (point-min) (+ 5 (point-min))
1443                                  '(article-type headers dummy-invisible t))
1444             (delete-region beg (point-max))))))))
1445
1446 (defun article-hide-boring-headers (&optional arg)
1447   "Toggle hiding of headers that aren't very interesting.
1448 If given a negative prefix, always show; if given a positive prefix,
1449 always hide."
1450   (interactive (gnus-article-hidden-arg))
1451   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1452              (not gnus-show-all-headers))
1453     (save-excursion
1454       (save-restriction
1455         (let ((buffer-read-only nil)
1456               (list gnus-boring-article-headers)
1457               (inhibit-point-motion-hooks t)
1458               elem)
1459           (article-narrow-to-head)
1460           (while list
1461             (setq elem (pop list))
1462             (goto-char (point-min))
1463             (cond
1464              ;; Hide empty headers.
1465              ((eq elem 'empty)
1466               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1467                 (forward-line -1)
1468                 (gnus-article-hide-text-type
1469                  (progn (beginning-of-line) (point))
1470                  (progn
1471                    (end-of-line)
1472                    (if (re-search-forward "^[^ \t]" nil t)
1473                        (match-beginning 0)
1474                      (point-max)))
1475                  'boring-headers)))
1476              ;; Hide boring Newsgroups header.
1477              ((eq elem 'newsgroups)
1478               (when (gnus-string-equal
1479                      (gnus-fetch-field "newsgroups")
1480                      (gnus-group-real-name
1481                       (if (boundp 'gnus-newsgroup-name)
1482                           gnus-newsgroup-name
1483                         "")))
1484                 (gnus-article-hide-header "newsgroups")))
1485              ((eq elem 'to-address)
1486               (let ((to (message-fetch-field "to"))
1487                     (to-address
1488                      (gnus-parameter-to-address
1489                       (if (boundp 'gnus-newsgroup-name)
1490                           gnus-newsgroup-name ""))))
1491                 (when (and to to-address
1492                            (ignore-errors
1493                              (gnus-string-equal
1494                               ;; only one address in To
1495                               (nth 1 (mail-extract-address-components to))
1496                               to-address)))
1497                   (gnus-article-hide-header "to"))))
1498              ((eq elem 'followup-to)
1499               (when (gnus-string-equal
1500                      (message-fetch-field "followup-to")
1501                      (message-fetch-field "newsgroups"))
1502                 (gnus-article-hide-header "followup-to")))
1503              ((eq elem 'reply-to)
1504               (let ((from (message-fetch-field "from"))
1505                     (reply-to (message-fetch-field "reply-to")))
1506                 (when (and
1507                        from reply-to
1508                        (ignore-errors
1509                          (gnus-string-equal
1510                           (nth 1 (mail-extract-address-components from))
1511                           (nth 1 (mail-extract-address-components reply-to)))))
1512                   (gnus-article-hide-header "reply-to"))))
1513              ((eq elem 'date)
1514               (let ((date (message-fetch-field "date")))
1515                 (when (and date
1516                            (< (days-between (current-time-string) date)
1517                               4))
1518                   (gnus-article-hide-header "date"))))
1519              ((eq elem 'long-to)
1520               (let ((to (message-fetch-field "to"))
1521                     (cc (message-fetch-field "cc")))
1522                 (when (> (length to) 1024)
1523                   (gnus-article-hide-header "to"))
1524                 (when (> (length cc) 1024)
1525                   (gnus-article-hide-header "cc"))))
1526              ((eq elem 'many-to)
1527               (let ((to-count 0)
1528                     (cc-count 0))
1529                 (goto-char (point-min))
1530                 (while (re-search-forward "^to:" nil t)
1531                   (setq to-count (1+ to-count)))
1532                 (when (> to-count 1)
1533                   (while (> to-count 0)
1534                     (goto-char (point-min))
1535                     (save-restriction
1536                       (re-search-forward "^to:" nil nil to-count)
1537                       (forward-line -1)
1538                       (narrow-to-region (point) (point-max))
1539                       (gnus-article-hide-header "to"))
1540                     (setq to-count (1- to-count))))
1541                 (goto-char (point-min))
1542                 (while (re-search-forward "^cc:" nil t)
1543                   (setq cc-count (1+ cc-count)))
1544                 (when (> cc-count 1)
1545                   (while (> cc-count 0)
1546                     (goto-char (point-min))
1547                     (save-restriction
1548                       (re-search-forward "^cc:" nil nil cc-count)
1549                       (forward-line -1)
1550                       (narrow-to-region (point) (point-max))
1551                       (gnus-article-hide-header "cc"))
1552                     (setq cc-count (1- cc-count)))))))))))))
1553
1554 (defun gnus-article-hide-header (header)
1555   (save-excursion
1556     (goto-char (point-min))
1557     (when (re-search-forward (concat "^" header ":") nil t)
1558       (gnus-article-hide-text-type
1559        (progn (beginning-of-line) (point))
1560        (progn
1561          (end-of-line)
1562          (if (re-search-forward "^[^ \t]" nil t)
1563              (match-beginning 0)
1564            (point-max)))
1565        'boring-headers))))
1566
1567 (defvar gnus-article-normalized-header-length 40
1568   "Length of normalized headers.")
1569
1570 (defun article-normalize-headers ()
1571   "Make all header lines 40 characters long."
1572   (interactive)
1573   (let ((buffer-read-only nil)
1574         column)
1575     (save-excursion
1576       (save-restriction
1577         (article-narrow-to-head)
1578         (while (not (eobp))
1579           (cond
1580            ((< (setq column (- (gnus-point-at-eol) (point)))
1581                gnus-article-normalized-header-length)
1582             (end-of-line)
1583             (insert (make-string
1584                      (- gnus-article-normalized-header-length column)
1585                      ? )))
1586            ((> column gnus-article-normalized-header-length)
1587             (gnus-put-text-property
1588              (progn
1589                (forward-char gnus-article-normalized-header-length)
1590                (point))
1591              (gnus-point-at-eol)
1592              'invisible t))
1593            (t
1594             ;; Do nothing.
1595             ))
1596           (forward-line 1))))))
1597
1598 (defun article-treat-dumbquotes ()
1599   "Translate M****s*** sm*rtq**t*s into proper text.
1600 Note that this function guesses whether a character is a sm*rtq**t* or
1601 not, so it should only be used interactively.
1602
1603 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1604 in an attempt to provide more quoting characters.  If you see
1605 something like \\222 or \\264 where you're expecting some kind of
1606 apostrophe or quotation mark, then try this wash."
1607   (interactive)
1608   (article-translate-strings gnus-article-dumbquotes-map))
1609
1610 (defun article-translate-characters (from to)
1611   "Translate all characters in the body of the article according to FROM and TO.
1612 FROM is a string of characters to translate from; to is a string of
1613 characters to translate to."
1614   (save-excursion
1615     (when (article-goto-body)
1616       (let ((buffer-read-only nil)
1617             (x (make-string 225 ?x))
1618             (i -1))
1619         (while (< (incf i) (length x))
1620           (aset x i i))
1621         (setq i 0)
1622         (while (< i (length from))
1623           (aset x (aref from i) (aref to i))
1624           (incf i))
1625         (translate-region (point) (point-max) x)))))
1626
1627 (defun article-translate-strings (map)
1628   "Translate all string in the body of the article according to MAP.
1629 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1630   (save-excursion
1631     (when (article-goto-body)
1632       (let ((buffer-read-only nil)
1633             elem)
1634         (while (setq elem (pop map))
1635           (save-excursion
1636             (while (search-forward (car elem) nil t)
1637               (replace-match (cadr elem)))))))))
1638
1639 (defun article-treat-overstrike ()
1640   "Translate overstrikes into bold text."
1641   (interactive)
1642   (save-excursion
1643     (when (article-goto-body)
1644       (let ((buffer-read-only nil))
1645         (while (search-forward "\b" nil t)
1646           (let ((next (char-after))
1647                 (previous (char-after (- (point) 2))))
1648             ;; We do the boldification/underlining by hiding the
1649             ;; overstrikes and putting the proper text property
1650             ;; on the letters.
1651             (cond
1652              ((eq next previous)
1653               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1654               (put-text-property (point) (1+ (point)) 'face 'bold))
1655              ((eq next ?_)
1656               (gnus-article-hide-text-type
1657                (1- (point)) (1+ (point)) 'overstrike)
1658               (put-text-property
1659                (- (point) 2) (1- (point)) 'face 'underline))
1660              ((eq previous ?_)
1661               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1662               (put-text-property
1663                (point) (1+ (point)) 'face 'underline)))))))))
1664
1665 (defun gnus-article-treat-unfold-headers ()
1666   "Unfold folded message headers.
1667 Only the headers that fit into the current window width will be
1668 unfolded."
1669   (interactive)
1670   (gnus-with-article-headers
1671     (let (length)
1672       (while (not (eobp))
1673         (save-restriction
1674           (mail-header-narrow-to-field)
1675           (let ((header (buffer-substring (point-min) (point-max))))
1676             (with-temp-buffer
1677               (insert header)
1678               (goto-char (point-min))
1679               (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1680                 (replace-match " " t t)))
1681             (setq length (- (point-max) (point-min) 1)))
1682           (when (< length (window-width))
1683             (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1684               (replace-match " " t t)))
1685           (goto-char (point-max)))))))
1686
1687 (defun gnus-article-treat-fold-headers ()
1688   "Fold message headers."
1689   (interactive)
1690   (gnus-with-article-headers
1691     (while (not (eobp))
1692       (save-restriction
1693         (mail-header-narrow-to-field)
1694         (mail-header-fold-field)
1695         (goto-char (point-max))))))
1696
1697 (defun gnus-treat-smiley ()
1698   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
1699   (interactive)
1700   (gnus-with-article-buffer
1701     (if (memq 'smiley gnus-article-wash-types)
1702         (gnus-delete-images 'smiley)
1703       (article-goto-body)
1704       (let ((images (smiley-region (point) (point-max))))
1705         (when images
1706           (gnus-add-wash-type 'smiley)
1707           (dolist (image images)
1708             (gnus-add-image 'smiley image)))))))
1709
1710 (defun gnus-article-remove-images ()
1711   "Remove all images from the article buffer."
1712   (interactive)
1713   (gnus-with-article-buffer
1714     (dolist (elem gnus-article-image-alist)
1715       (gnus-delete-images (car elem)))))
1716
1717 (defun gnus-article-treat-fold-newsgroups ()
1718   "Unfold folded message headers.
1719 Only the headers that fit into the current window width will be
1720 unfolded."
1721   (interactive)
1722   (gnus-with-article-headers
1723     (while (gnus-article-goto-header "newsgroups\\|followup-to")
1724       (save-restriction
1725         (mail-header-narrow-to-field)
1726         (while (re-search-forward ", *" nil t)
1727           (replace-match ", " t t))
1728         (mail-header-fold-field)
1729         (goto-char (point-max))))))
1730
1731 (defun gnus-article-treat-body-boundary ()
1732   "Place a boundary line at the end of the headers."
1733   (interactive)
1734   (when (and gnus-body-boundary-delimiter
1735              (> (length gnus-body-boundary-delimiter) 0))
1736     (gnus-with-article-headers
1737       (goto-char (point-max))
1738       (let ((start (point)))
1739         (insert "X-Boundary: ")
1740         (gnus-add-text-properties start (point) '(invisible t intangible t))
1741         (insert (let (str)
1742                   (while (>= (1- (window-width)) (length str))
1743                     (setq str (concat str gnus-body-boundary-delimiter)))
1744                   (substring str 0 (1- (window-width))))
1745                 "\n")))))
1746
1747 (defun article-fill-long-lines ()
1748   "Fill lines that are wider than the window width."
1749   (interactive)
1750   (save-excursion
1751     (let ((buffer-read-only nil)
1752           (width (window-width (get-buffer-window (current-buffer)))))
1753       (save-restriction
1754         (article-goto-body)
1755         (let ((adaptive-fill-mode nil)) ;Why?  -sm
1756           (while (not (eobp))
1757             (end-of-line)
1758             (when (>= (current-column) (min fill-column width))
1759               (narrow-to-region (point) (gnus-point-at-bol))
1760               (fill-paragraph nil)
1761               (goto-char (point-max))
1762               (widen))
1763             (forward-line 1)))))))
1764
1765 (defun article-capitalize-sentences ()
1766   "Capitalize the first word in each sentence."
1767   (interactive)
1768   (save-excursion
1769     (let ((buffer-read-only nil)
1770           (paragraph-start "^[\n\^L]"))
1771       (article-goto-body)
1772       (while (not (eobp))
1773         (capitalize-word 1)
1774         (forward-sentence)))))
1775
1776 (defun article-remove-cr ()
1777   "Remove trailing CRs and then translate remaining CRs into LFs."
1778   (interactive)
1779   (save-excursion
1780     (let ((buffer-read-only nil))
1781       (goto-char (point-min))
1782       (while (re-search-forward "\r+$" nil t)
1783         (replace-match "" t t))
1784       (goto-char (point-min))
1785       (while (search-forward "\r" nil t)
1786         (replace-match "\n" t t)))))
1787
1788 (defun article-remove-trailing-blank-lines ()
1789   "Remove all trailing blank lines from the article."
1790   (interactive)
1791   (save-excursion
1792     (let ((buffer-read-only nil))
1793       (goto-char (point-max))
1794       (delete-region
1795        (point)
1796        (progn
1797          (while (and (not (bobp))
1798                      (looking-at "^[ \t]*$")
1799                      (not (gnus-annotation-in-region-p
1800                            (point) (gnus-point-at-eol))))
1801            (forward-line -1))
1802          (forward-line 1)
1803          (point))))))
1804
1805 (defun article-display-x-face (&optional force)
1806   "Look for an X-Face header and display it if present."
1807   (interactive (list 'force))
1808   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
1809     (gnus-with-article-headers
1810       ;; Delete the old process, if any.
1811       (when (process-status "article-x-face")
1812         (delete-process "article-x-face"))
1813       (if (memq 'xface gnus-article-wash-types)
1814           ;; We have already displayed X-Faces, so we remove them
1815           ;; instead.
1816           (gnus-delete-images 'xface)
1817         ;; Display X-Faces.
1818         (let (x-faces from face grey)
1819           (save-excursion
1820             (when (and wash-face-p
1821                        (progn
1822                          (goto-char (point-min))
1823                          (not (re-search-forward
1824                                "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
1825                        (gnus-buffer-live-p gnus-original-article-buffer))
1826               ;; If type `W f', use gnus-original-article-buffer,
1827               ;; otherwise use the current buffer because displaying
1828               ;; RFC822 parts calls this function too.
1829               (set-buffer gnus-original-article-buffer))
1830             (save-restriction
1831               (mail-narrow-to-head)
1832               (while (gnus-article-goto-header "x-face\\(-[0-9]+\\)?")
1833                 (when (match-beginning 2)
1834                   (setq grey t))
1835                 (push (mail-header-field-value) x-faces))
1836               (setq from (message-fetch-field "from"))))
1837           (if grey
1838               (let ((xpm (gnus-convert-gray-x-face-to-xpm x-faces))
1839                     image)
1840                 (when xpm
1841                   (setq image (gnus-create-image xpm 'xpm t))
1842                   (gnus-article-goto-header "from")
1843                   (when (bobp)
1844                     (insert "From: [no `from' set]\n")
1845                     (forward-char -17))
1846                   (gnus-add-wash-type 'xface)
1847                   (gnus-add-image 'xface image)
1848                   (gnus-put-image image)))
1849             ;; Sending multiple EOFs to xv doesn't work, so we only do a
1850             ;; single external face.
1851             (when (stringp gnus-article-x-face-command)
1852               (setq x-faces (list (car x-faces))))
1853             (while (and (setq face (pop x-faces))
1854                         gnus-article-x-face-command
1855                         (or force
1856                             ;; Check whether this face is censored.
1857                             (not gnus-article-x-face-too-ugly)
1858                             (and gnus-article-x-face-too-ugly from
1859                                  (not (string-match gnus-article-x-face-too-ugly
1860                                                     from)))))
1861               ;; We display the face.
1862               (if (symbolp gnus-article-x-face-command)
1863                   ;; The command is a lisp function, so we call it.
1864                   (if (gnus-functionp gnus-article-x-face-command)
1865                       (funcall gnus-article-x-face-command face)
1866                     (error "%s is not a function" gnus-article-x-face-command))
1867                 ;; The command is a string, so we interpret the command
1868                 ;; as a, well, command, and fork it off.
1869                 (let ((process-connection-type nil))
1870                   (process-kill-without-query
1871                    (start-process
1872                     "article-x-face" nil shell-file-name shell-command-switch
1873                     gnus-article-x-face-command))
1874                   (with-temp-buffer
1875                     (insert face)
1876                     (process-send-region "article-x-face"
1877                                          (point-min) (point-max)))
1878                   (process-send-eof "article-x-face"))))))))))
1879
1880 (defun article-decode-mime-words ()
1881   "Decode all MIME-encoded words in the article."
1882   (interactive)
1883   (save-excursion
1884     (set-buffer gnus-article-buffer)
1885     (let ((inhibit-point-motion-hooks t)
1886           buffer-read-only
1887           (mail-parse-charset gnus-newsgroup-charset)
1888           (mail-parse-ignored-charsets
1889            (save-excursion (set-buffer gnus-summary-buffer)
1890                            gnus-newsgroup-ignored-charsets)))
1891       (mail-decode-encoded-word-region (point-min) (point-max)))))
1892
1893 (defun article-decode-charset (&optional prompt)
1894   "Decode charset-encoded text in the article.
1895 If PROMPT (the prefix), prompt for a coding system to use."
1896   (interactive "P")
1897   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1898         buffer-read-only
1899         (mail-parse-charset gnus-newsgroup-charset)
1900         (mail-parse-ignored-charsets
1901          (save-excursion (condition-case nil
1902                              (set-buffer gnus-summary-buffer)
1903                            (error))
1904                          gnus-newsgroup-ignored-charsets))
1905         ct cte ctl charset format)
1906   (save-excursion
1907     (save-restriction
1908       (article-narrow-to-head)
1909       (setq ct (message-fetch-field "Content-Type" t)
1910             cte (message-fetch-field "Content-Transfer-Encoding" t)
1911             ctl (and ct (ignore-errors
1912                           (mail-header-parse-content-type ct)))
1913             charset (cond
1914                      (prompt
1915                       (mm-read-coding-system "Charset to decode: "))
1916                      (ctl
1917                       (mail-content-type-get ctl 'charset)))
1918             format (and ctl (mail-content-type-get ctl 'format)))
1919       (when cte
1920         (setq cte (mail-header-strip cte)))
1921       (if (and ctl (not (string-match "/" (car ctl))))
1922           (setq ctl nil))
1923       (goto-char (point-max)))
1924     (forward-line 1)
1925     (save-restriction
1926       (narrow-to-region (point) (point-max))
1927       (when (and (eq mail-parse-charset 'gnus-decoded)
1928                  (eq (mm-body-7-or-8) '8bit))
1929         ;; The text code could have been decoded.
1930         (setq charset mail-parse-charset))
1931       (when (and (or (not ctl)
1932                      (equal (car ctl) "text/plain"))
1933                  (not format)) ;; article with format will decode later.
1934         (mm-decode-body
1935          charset (and cte (intern (downcase
1936                                    (gnus-strip-whitespace cte))))
1937          (car ctl)))))))
1938
1939 (defun article-decode-encoded-words ()
1940   "Remove encoded-word encoding from headers."
1941   (let ((inhibit-point-motion-hooks t)
1942         (mail-parse-charset gnus-newsgroup-charset)
1943         (mail-parse-ignored-charsets
1944          (save-excursion (condition-case nil
1945                              (set-buffer gnus-summary-buffer)
1946                            (error))
1947                          gnus-newsgroup-ignored-charsets))
1948         buffer-read-only)
1949     (save-restriction
1950       (article-narrow-to-head)
1951       (funcall gnus-decode-header-function (point-min) (point-max)))))
1952
1953 (defun article-decode-group-name ()
1954   "Decode group names in `Newsgroups:'."
1955   (let ((inhibit-point-motion-hooks t)
1956         buffer-read-only
1957         (method (gnus-find-method-for-group gnus-newsgroup-name)))
1958     (when (and (or gnus-group-name-charset-method-alist
1959                    gnus-group-name-charset-group-alist)
1960                (gnus-buffer-live-p gnus-original-article-buffer))
1961       (when (nnmail-fetch-field "Newsgroups")
1962         (nnheader-replace-header "Newsgroups"
1963                                  (gnus-decode-newsgroups
1964                                   (with-current-buffer
1965                                       gnus-original-article-buffer
1966                                     (nnmail-fetch-field "Newsgroups"))
1967                                   gnus-newsgroup-name method)))
1968       (when (nnmail-fetch-field "Followup-To")
1969         (nnheader-replace-header "Followup-To"
1970                                  (gnus-decode-newsgroups
1971                                   (with-current-buffer
1972                                       gnus-original-article-buffer
1973                                     (nnmail-fetch-field "Followup-To"))
1974                                   gnus-newsgroup-name method))))))
1975
1976 (defun article-de-quoted-unreadable (&optional force read-charset)
1977   "Translate a quoted-printable-encoded article.
1978 If FORCE, decode the article whether it is marked as quoted-printable
1979 or not.
1980 If READ-CHARSET, ask for a coding system."
1981   (interactive (list 'force current-prefix-arg))
1982   (save-excursion
1983     (let ((buffer-read-only nil) type charset)
1984       (if (gnus-buffer-live-p gnus-original-article-buffer)
1985           (with-current-buffer gnus-original-article-buffer
1986             (setq type
1987                   (gnus-fetch-field "content-transfer-encoding"))
1988             (let* ((ct (gnus-fetch-field "content-type"))
1989                    (ctl (and ct
1990                              (ignore-errors
1991                                (mail-header-parse-content-type ct)))))
1992               (setq charset (and ctl
1993                                  (mail-content-type-get ctl 'charset)))
1994               (if (stringp charset)
1995                   (setq charset (intern (downcase charset)))))))
1996       (if read-charset
1997           (setq charset (mm-read-coding-system "Charset: " charset)))
1998       (unless charset
1999         (setq charset gnus-newsgroup-charset))
2000       (when (or force
2001                 (and type (let ((case-fold-search t))
2002                             (string-match "quoted-printable" type))))
2003         (article-goto-body)
2004         (quoted-printable-decode-region
2005          (point) (point-max) (mm-charset-to-coding-system charset))))))
2006
2007 (defun article-de-base64-unreadable (&optional force read-charset)
2008   "Translate a base64 article.
2009 If FORCE, decode the article whether it is marked as base64 not.
2010 If READ-CHARSET, ask for a coding system."
2011   (interactive (list 'force current-prefix-arg))
2012   (save-excursion
2013     (let ((buffer-read-only nil) type charset)
2014       (if (gnus-buffer-live-p gnus-original-article-buffer)
2015           (with-current-buffer gnus-original-article-buffer
2016             (setq type
2017                   (gnus-fetch-field "content-transfer-encoding"))
2018             (let* ((ct (gnus-fetch-field "content-type"))
2019                    (ctl (and ct
2020                              (ignore-errors
2021                                (mail-header-parse-content-type ct)))))
2022               (setq charset (and ctl
2023                                  (mail-content-type-get ctl 'charset)))
2024               (if (stringp charset)
2025                   (setq charset (intern (downcase charset)))))))
2026       (if read-charset
2027           (setq charset (mm-read-coding-system "Charset: " charset)))
2028       (unless charset
2029         (setq charset gnus-newsgroup-charset))
2030       (when (or force
2031                 (and type (let ((case-fold-search t))
2032                             (string-match "base64" type))))
2033         (article-goto-body)
2034         (save-restriction
2035           (narrow-to-region (point) (point-max))
2036           (base64-decode-region (point-min) (point-max))
2037           (mm-decode-coding-region
2038            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2039
2040 (eval-when-compile
2041   (require 'rfc1843))
2042
2043 (defun article-decode-HZ ()
2044   "Translate a HZ-encoded article."
2045   (interactive)
2046   (require 'rfc1843)
2047   (save-excursion
2048     (let ((buffer-read-only nil))
2049       (rfc1843-decode-region (point-min) (point-max)))))
2050
2051 (defun article-wash-html (&optional read-charset)
2052   "Format an html article.
2053 If READ-CHARSET, ask for a coding system."
2054   (interactive "P")
2055   (save-excursion
2056     (let ((buffer-read-only nil)
2057           charset)
2058       (if (gnus-buffer-live-p gnus-original-article-buffer)
2059           (with-current-buffer gnus-original-article-buffer
2060             (let* ((ct (gnus-fetch-field "content-type"))
2061                    (ctl (and ct
2062                              (ignore-errors
2063                                (mail-header-parse-content-type ct)))))
2064               (setq charset (and ctl
2065                                  (mail-content-type-get ctl 'charset)))
2066               (if (stringp charset)
2067                   (setq charset (intern (downcase charset)))))))
2068       (if read-charset
2069           (setq charset (mm-read-coding-system "Charset: " charset)))
2070       (unless charset
2071         (setq charset gnus-newsgroup-charset))
2072       (article-goto-body)
2073       (save-window-excursion
2074         (save-restriction
2075           (narrow-to-region (point) (point-max))
2076           (funcall gnus-article-wash-function))))))
2077
2078 (defun gnus-article-wash-html-with-w3 ()
2079   "Wash the current buffer with w3."
2080   (mm-setup-w3)
2081   (let ((w3-strict-width (window-width))
2082         (url-standalone-mode t)
2083         (w3-honor-stylesheets nil)
2084         (w3-delay-image-loads t))
2085     (condition-case var
2086         (w3-region (point-min) (point-max))
2087       (error))))
2088
2089 (defun gnus-article-wash-html-with-w3m ()
2090   "Wash the current buffer with emacs-w3m."
2091   (mm-setup-w3m)
2092   (save-restriction
2093     (narrow-to-region (point) (point-max))
2094     (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
2095                                    nil
2096                                  "\\`cid:"))
2097           (w3m-display-inline-images mm-inline-text-html-with-images)
2098           w3m-force-redisplay)
2099       (w3m-region (point-min) (point-max)))
2100     (when mm-inline-text-html-with-w3m-keymap
2101       (add-text-properties
2102        (point-min) (point-max)
2103        (append '(mm-inline-text-html-with-w3m t)
2104                (gnus-local-map-property mm-w3m-mode-map))))))
2105
2106 (defun article-hide-list-identifiers ()
2107   "Remove list identifies from the Subject header.
2108 The `gnus-list-identifiers' variable specifies what to do."
2109   (interactive)
2110   (let ((inhibit-point-motion-hooks t)
2111         (regexp (if (consp gnus-list-identifiers)
2112                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2113                   gnus-list-identifiers))
2114         buffer-read-only)
2115     (when regexp
2116       (save-excursion
2117         (save-restriction
2118           (article-narrow-to-head)
2119           (goto-char (point-min))
2120           (while (re-search-forward
2121                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2122                   nil t)
2123             (delete-region (match-beginning 2) (match-end 0))
2124             (beginning-of-line))
2125           (when (re-search-forward
2126                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2127             (delete-region (match-beginning 1) (match-end 1))))))))
2128
2129 (defun article-hide-pgp ()
2130   "Remove any PGP headers and signatures in the current article."
2131   (interactive)
2132   (save-excursion
2133     (save-restriction
2134       (let ((inhibit-point-motion-hooks t)
2135             buffer-read-only beg end)
2136         (article-goto-body)
2137         ;; Hide the "header".
2138         (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2139           (gnus-add-wash-type 'pgp)
2140           (delete-region (match-beginning 0) (match-end 0))
2141           ;; Remove armor headers (rfc2440 6.2)
2142           (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2143                                      (point)))
2144           (setq beg (point))
2145           ;; Hide the actual signature.
2146           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2147                (setq end (1+ (match-beginning 0)))
2148                (delete-region
2149                 end
2150                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2151                     (match-end 0)
2152                   ;; Perhaps we shouldn't hide to the end of the buffer
2153                   ;; if there is no end to the signature?
2154                   (point-max))))
2155           ;; Hide "- " PGP quotation markers.
2156           (when (and beg end)
2157             (narrow-to-region beg end)
2158             (goto-char (point-min))
2159             (while (re-search-forward "^- " nil t)
2160               (delete-region
2161                (match-beginning 0) (match-end 0)))
2162             (widen))
2163           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2164
2165 (defun article-hide-pem (&optional arg)
2166   "Toggle hiding of any PEM headers and signatures in the current article.
2167 If given a negative prefix, always show; if given a positive prefix,
2168 always hide."
2169   (interactive (gnus-article-hidden-arg))
2170   (unless (gnus-article-check-hidden-text 'pem arg)
2171     (save-excursion
2172       (let (buffer-read-only end)
2173         (goto-char (point-min))
2174         ;; Hide the horrendously ugly "header".
2175         (when (and (search-forward
2176                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2177                     nil t)
2178                    (setq end (1+ (match-beginning 0))))
2179           (gnus-add-wash-type 'pem)
2180           (gnus-article-hide-text-type
2181            end
2182            (if (search-forward "\n\n" nil t)
2183                (match-end 0)
2184              (point-max))
2185            'pem)
2186           ;; Hide the trailer as well
2187           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2188                                 nil t)
2189             (gnus-article-hide-text-type
2190              (match-beginning 0) (match-end 0) 'pem)))))))
2191
2192 (defun article-strip-banner ()
2193   "Strip the banner specified by the `banner' group parameter."
2194   (interactive)
2195   (save-excursion
2196     (save-restriction
2197       (let ((inhibit-point-motion-hooks t)
2198             (banner (gnus-parameter-banner gnus-newsgroup-name))
2199             (gnus-signature-limit nil)
2200             buffer-read-only beg end)
2201         (when banner
2202           (article-goto-body)
2203           (cond
2204            ((eq banner 'signature)
2205             (when (gnus-article-narrow-to-signature)
2206               (widen)
2207               (forward-line -1)
2208               (delete-region (point) (point-max))))
2209            ((symbolp banner)
2210             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2211                 (while (re-search-forward banner nil t)
2212                   (delete-region (match-beginning 0) (match-end 0)))))
2213            ((stringp banner)
2214             (while (re-search-forward banner nil t)
2215               (delete-region (match-beginning 0) (match-end 0))))))))))
2216
2217 (defun article-babel ()
2218   "Translate article using an online translation service."
2219   (interactive)
2220   (require 'babel)
2221   (save-excursion
2222     (set-buffer gnus-article-buffer)
2223     (when (article-goto-body)
2224       (let* ((buffer-read-only nil)
2225              (start (point))
2226              (end (point-max))
2227              (orig (buffer-substring start end))
2228              (trans (babel-as-string orig)))
2229         (save-restriction
2230           (narrow-to-region start end)
2231           (delete-region start end)
2232           (insert trans))))))
2233
2234 (defun article-hide-signature (&optional arg)
2235   "Hide the signature in the current article.
2236 If given a negative prefix, always show; if given a positive prefix,
2237 always hide."
2238   (interactive (gnus-article-hidden-arg))
2239   (unless (gnus-article-check-hidden-text 'signature arg)
2240     (save-excursion
2241       (save-restriction
2242         (let ((buffer-read-only nil))
2243           (when (gnus-article-narrow-to-signature)
2244             (gnus-article-hide-text-type
2245              (point-min) (point-max) 'signature))))))
2246   (gnus-set-mode-line 'article))
2247
2248 (defun article-strip-headers-in-body ()
2249   "Strip offensive headers from bodies."
2250   (interactive)
2251   (save-excursion
2252     (article-goto-body)
2253     (let ((case-fold-search t))
2254       (when (looking-at "x-no-archive:")
2255         (gnus-delete-line)))))
2256
2257 (defun article-strip-leading-blank-lines ()
2258   "Remove all blank lines from the beginning of the article."
2259   (interactive)
2260   (save-excursion
2261     (let ((inhibit-point-motion-hooks t)
2262           buffer-read-only)
2263       (when (article-goto-body)
2264         (while (and (not (eobp))
2265                     (looking-at "[ \t]*$"))
2266           (gnus-delete-line))))))
2267
2268 (defun article-narrow-to-head ()
2269   "Narrow the buffer to the head of the message.
2270 Point is left at the beginning of the narrowed-to region."
2271   (narrow-to-region
2272    (goto-char (point-min))
2273    (if (search-forward "\n\n" nil 1)
2274        (1- (point))
2275      (point-max)))
2276   (goto-char (point-min)))
2277
2278 (defun article-goto-body ()
2279   "Place point at the start of the body."
2280   (goto-char (point-min))
2281   (cond
2282    ;; This variable is only bound when dealing with separate
2283    ;; MIME body parts.
2284    (article-goto-body-goes-to-point-min-p
2285     t)
2286    ((search-forward "\n\n" nil t)
2287     t)
2288    (t
2289     (goto-char (point-max))
2290     nil)))
2291
2292 (defun article-strip-multiple-blank-lines ()
2293   "Replace consecutive blank lines with one empty line."
2294   (interactive)
2295   (save-excursion
2296     (let ((inhibit-point-motion-hooks t)
2297           buffer-read-only)
2298       ;; First make all blank lines empty.
2299       (article-goto-body)
2300       (while (re-search-forward "^[ \t]+$" nil t)
2301         (unless (gnus-annotation-in-region-p
2302                  (match-beginning 0) (match-end 0))
2303           (replace-match "" nil t)))
2304       ;; Then replace multiple empty lines with a single empty line.
2305       (article-goto-body)
2306       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2307         (unless (gnus-annotation-in-region-p
2308                  (match-beginning 0) (match-end 0))
2309           (delete-region (match-beginning 1) (match-end 1)))))))
2310
2311 (defun article-strip-leading-space ()
2312   "Remove all white space from the beginning of the lines in the article."
2313   (interactive)
2314   (save-excursion
2315     (let ((inhibit-point-motion-hooks t)
2316           buffer-read-only)
2317       (article-goto-body)
2318       (while (re-search-forward "^[ \t]+" nil t)
2319         (replace-match "" t t)))))
2320
2321 (defun article-strip-trailing-space ()
2322   "Remove all white space from the end of the lines in the article."
2323   (interactive)
2324   (save-excursion
2325     (let ((inhibit-point-motion-hooks t)
2326           buffer-read-only)
2327       (article-goto-body)
2328       (while (re-search-forward "[ \t]+$" nil t)
2329         (replace-match "" t t)))))
2330
2331 (defun article-strip-blank-lines ()
2332   "Strip leading, trailing and multiple blank lines."
2333   (interactive)
2334   (article-strip-leading-blank-lines)
2335   (article-remove-trailing-blank-lines)
2336   (article-strip-multiple-blank-lines))
2337
2338 (defun article-strip-all-blank-lines ()
2339   "Strip all blank lines."
2340   (interactive)
2341   (save-excursion
2342     (let ((inhibit-point-motion-hooks t)
2343           buffer-read-only)
2344       (article-goto-body)
2345       (while (re-search-forward "^[ \t]*\n" nil t)
2346         (replace-match "" t t)))))
2347
2348 (defun gnus-article-narrow-to-signature ()
2349   "Narrow to the signature; return t if a signature is found, else nil."
2350   (let ((inhibit-point-motion-hooks t))
2351     (when (gnus-article-search-signature)
2352       (forward-line 1)
2353       ;; Check whether we have some limits to what we consider
2354       ;; to be a signature.
2355       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2356                       (list gnus-signature-limit)))
2357             limit limited)
2358         (while (setq limit (pop limits))
2359           (if (or (and (integerp limit)
2360                        (< (- (point-max) (point)) limit))
2361                   (and (floatp limit)
2362                        (< (count-lines (point) (point-max)) limit))
2363                   (and (gnus-functionp limit)
2364                        (funcall limit))
2365                   (and (stringp limit)
2366                        (not (re-search-forward limit nil t))))
2367               ()                        ; This limit did not succeed.
2368             (setq limited t
2369                   limits nil)))
2370         (unless limited
2371           (narrow-to-region (point) (point-max))
2372           t)))))
2373
2374 (defun gnus-article-search-signature ()
2375   "Search the current buffer for the signature separator.
2376 Put point at the beginning of the signature separator."
2377   (let ((cur (point)))
2378     (goto-char (point-max))
2379     (if (if (stringp gnus-signature-separator)
2380             (re-search-backward gnus-signature-separator nil t)
2381           (let ((seps gnus-signature-separator))
2382             (while (and seps
2383                         (not (re-search-backward (car seps) nil t)))
2384               (pop seps))
2385             seps))
2386         t
2387       (goto-char cur)
2388       nil)))
2389
2390 (defun gnus-article-hidden-arg ()
2391   "Return the current prefix arg as a number, or 0 if no prefix."
2392   (list (if current-prefix-arg
2393             (prefix-numeric-value current-prefix-arg)
2394           0)))
2395
2396 (defun gnus-article-check-hidden-text (type arg)
2397   "Return nil if hiding is necessary.
2398 Arg can be nil or a number.  nil and positive means hide, negative
2399 means show, 0 means toggle."
2400   (save-excursion
2401     (save-restriction
2402       (let ((hide (gnus-article-hidden-text-p type)))
2403         (cond
2404          ((or (null arg)
2405               (> arg 0))
2406           nil)
2407          ((< arg 0)
2408           (gnus-article-show-hidden-text type)
2409           t)
2410          (t
2411           (if (eq hide 'hidden)
2412               (progn
2413                 (gnus-article-show-hidden-text type)
2414                 t)
2415             nil)))))))
2416
2417 (defun gnus-article-hidden-text-p (type)
2418   "Say whether the current buffer contains hidden text of type TYPE."
2419   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2420     (while (and pos
2421                 (not (get-text-property pos 'invisible))
2422                 (not (get-text-property pos 'dummy-invisible)))
2423       (setq pos
2424             (text-property-any (1+ pos) (point-max) 'article-type type)))
2425     (if pos
2426         'hidden
2427       nil)))
2428
2429 (defun gnus-article-show-hidden-text (type &optional dummy)
2430   "Show all hidden text of type TYPE.
2431 Originally it is hide instead of DUMMY."
2432   (let ((buffer-read-only nil)
2433         (inhibit-point-motion-hooks t))
2434     (gnus-remove-text-properties-when
2435      'article-type type
2436      (point-min) (point-max)
2437      (cons 'article-type (cons type
2438                                gnus-hidden-properties)))
2439     (gnus-delete-wash-type type)))
2440
2441 (defconst article-time-units
2442   `((year . ,(* 365.25 24 60 60))
2443     (week . ,(* 7 24 60 60))
2444     (day . ,(* 24 60 60))
2445     (hour . ,(* 60 60))
2446     (minute . 60)
2447     (second . 1))
2448   "Mapping from time units to seconds.")
2449
2450 (defun article-date-ut (&optional type highlight header)
2451   "Convert DATE date to universal time in the current article.
2452 If TYPE is `local', convert to local time; if it is `lapsed', output
2453 how much time has lapsed since DATE.  For `lapsed', the value of
2454 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2455 should replace the \"Date:\" one, or should be added below it."
2456   (interactive (list 'ut t))
2457   (let* ((header (or header
2458                      (message-fetch-field "date")
2459                      ""))
2460          (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2461          (date-regexp
2462           (cond
2463            ((not gnus-article-date-lapsed-new-header)
2464             tdate-regexp)
2465            ((eq type 'lapsed)
2466             "^X-Sent:[ \t]")
2467            (t
2468             "^Date:[ \t]")))
2469          (date (if (vectorp header) (mail-header-date header)
2470                  header))
2471          (inhibit-point-motion-hooks t)
2472          pos
2473          bface eface)
2474     (save-excursion
2475       (save-restriction
2476         (article-narrow-to-head)
2477         (when (re-search-forward tdate-regexp nil t)
2478           (setq bface (get-text-property (gnus-point-at-bol) 'face)
2479                 date (or (get-text-property (gnus-point-at-bol)
2480                                             'original-date)
2481                          date)
2482                 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2483           (forward-line 1))
2484         (when (and date (not (string= date "")))
2485           (goto-char (point-min))
2486           (let ((buffer-read-only nil))
2487             ;; Delete any old Date headers.
2488             (while (re-search-forward date-regexp nil t)
2489               (if pos
2490                   (delete-region (progn (beginning-of-line) (point))
2491                                  (progn (forward-line 1) (point)))
2492                 (delete-region (progn (beginning-of-line) (point))
2493                                (progn (end-of-line) (point)))
2494                 (setq pos (point))))
2495             (when (and (not pos) (re-search-forward tdate-regexp nil t))
2496               (forward-line 1))
2497             (if pos (goto-char pos))
2498             (insert (article-make-date-line date (or type 'ut)))
2499             (when (not pos)
2500               (insert "\n")
2501               (forward-line -1))
2502             ;; Do highlighting.
2503             (beginning-of-line)
2504             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2505               (put-text-property (match-beginning 1) (1+ (match-end 1))
2506                                  'original-date date)
2507               (put-text-property (match-beginning 1) (1+ (match-end 1))
2508                                  'face bface)
2509               (put-text-property (match-beginning 2) (match-end 2)
2510                                  'face eface))))))))
2511
2512 (defun article-make-date-line (date type)
2513   "Return a DATE line of TYPE."
2514   (unless (memq type '(local ut original user iso8601 lapsed english))
2515     (error "Unknown conversion type: %s" type))
2516   (condition-case ()
2517       (let ((time (date-to-time date)))
2518         (cond
2519          ;; Convert to the local timezone.
2520          ((eq type 'local)
2521           (let ((tz (car (current-time-zone time))))
2522             (format "Date: %s %s%02d%02d" (current-time-string time)
2523                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2524                     (/ (% (abs tz) 3600) 60))))
2525          ;; Convert to Universal Time.
2526          ((eq type 'ut)
2527           (concat "Date: "
2528                   (current-time-string
2529                    (let* ((e (parse-time-string date))
2530                           (tm (apply 'encode-time e))
2531                           (ms (car tm))
2532                           (ls (- (cadr tm) (car (current-time-zone time)))))
2533                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2534                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2535                            (t (list ms ls)))))
2536                   " UT"))
2537          ;; Get the original date from the article.
2538          ((eq type 'original)
2539           (concat "Date: " (if (string-match "\n+$" date)
2540                                (substring date 0 (match-beginning 0))
2541                              date)))
2542          ;; Let the user define the format.
2543          ((eq type 'user)
2544           (if (gnus-functionp gnus-article-time-format)
2545               (funcall gnus-article-time-format time)
2546             (concat
2547              "Date: "
2548              (format-time-string gnus-article-time-format time))))
2549          ;; ISO 8601.
2550          ((eq type 'iso8601)
2551           (let ((tz (car (current-time-zone time))))
2552             (concat
2553              "Date: "
2554              (format-time-string "%Y%m%dT%H%M%S" time)
2555              (format "%s%02d%02d"
2556                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2557                      (/ (% (abs tz) 3600) 60)))))
2558          ;; Do an X-Sent lapsed format.
2559          ((eq type 'lapsed)
2560           ;; If the date is seriously mangled, the timezone functions are
2561           ;; liable to bug out, so we ignore all errors.
2562           (let* ((now (current-time))
2563                  (real-time (subtract-time now time))
2564                  (real-sec (and real-time
2565                                 (+ (* (float (car real-time)) 65536)
2566                                    (cadr real-time))))
2567                  (sec (and real-time (abs real-sec)))
2568                  num prev)
2569             (cond
2570              ((null real-time)
2571               "X-Sent: Unknown")
2572              ((zerop sec)
2573               "X-Sent: Now")
2574              (t
2575               (concat
2576                "X-Sent: "
2577                ;; This is a bit convoluted, but basically we go
2578                ;; through the time units for years, weeks, etc,
2579                ;; and divide things to see whether that results
2580                ;; in positive answers.
2581                (mapconcat
2582                 (lambda (unit)
2583                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2584                       ;; The (remaining) seconds are too few to
2585                       ;; be divided into this time unit.
2586                       ""
2587                     ;; It's big enough, so we output it.
2588                     (setq sec (- sec (* num (cdr unit))))
2589                     (prog1
2590                         (concat (if prev ", " "") (int-to-string
2591                                                    (floor num))
2592                                 " " (symbol-name (car unit))
2593                                 (if (> num 1) "s" ""))
2594                       (setq prev t))))
2595                 article-time-units "")
2596                ;; If dates are odd, then it might appear like the
2597                ;; article was sent in the future.
2598                (if (> real-sec 0)
2599                    " ago"
2600                  " in the future"))))))
2601          ;; Display the date in proper English
2602          ((eq type 'english)
2603           (let ((dtime (decode-time time)))
2604             (concat
2605              "Date: the "
2606              (number-to-string (nth 3 dtime))
2607              (let ((digit (% (nth 3 dtime) 10)))
2608                (cond
2609                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2610                 ((= digit 1) "st")
2611                 ((= digit 2) "nd")
2612                 ((= digit 3) "rd")
2613                 (t "th")))
2614              " of "
2615              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2616              " "
2617              (number-to-string (nth 5 dtime))
2618              " at "
2619              (format "%02d" (nth 2 dtime))
2620              ":"
2621              (format "%02d" (nth 1 dtime)))))))
2622         (error
2623          (format "Date: %s (from Oort)" date))))
2624
2625 (defun article-date-local (&optional highlight)
2626   "Convert the current article date to the local timezone."
2627   (interactive (list t))
2628   (article-date-ut 'local highlight))
2629
2630 (defun article-date-english (&optional highlight)
2631   "Convert the current article date to something that is proper English."
2632   (interactive (list t))
2633   (article-date-ut 'english highlight))
2634
2635 (defun article-date-original (&optional highlight)
2636   "Convert the current article date to what it was originally.
2637 This is only useful if you have used some other date conversion
2638 function and want to see what the date was before converting."
2639   (interactive (list t))
2640   (article-date-ut 'original highlight))
2641
2642 (defun article-date-lapsed (&optional highlight)
2643   "Convert the current article date to time lapsed since it was sent."
2644   (interactive (list t))
2645   (article-date-ut 'lapsed highlight))
2646
2647 (defun article-update-date-lapsed ()
2648   "Function to be run from a timer to update the lapsed time line."
2649   (let (deactivate-mark)
2650     (save-excursion
2651       (ignore-errors
2652         (walk-windows
2653          (lambda (w)
2654            (set-buffer (window-buffer w))
2655            (when (eq major-mode 'gnus-article-mode)
2656              (goto-char (point-min))
2657              (when (re-search-forward "^X-Sent:" nil t)
2658                (article-date-lapsed t))))
2659          nil 'visible)))))
2660
2661 (defun gnus-start-date-timer (&optional n)
2662   "Start a timer to update the X-Sent header in the article buffers.
2663 The numerical prefix says how frequently (in seconds) the function
2664 is to run."
2665   (interactive "p")
2666   (unless n
2667     (setq n 1))
2668   (gnus-stop-date-timer)
2669   (setq article-lapsed-timer
2670         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2671
2672 (defun gnus-stop-date-timer ()
2673   "Stop the X-Sent timer."
2674   (interactive)
2675   (when article-lapsed-timer
2676     (nnheader-cancel-timer article-lapsed-timer)
2677     (setq article-lapsed-timer nil)))
2678
2679 (defun article-date-user (&optional highlight)
2680   "Convert the current article date to the user-defined format.
2681 This format is defined by the `gnus-article-time-format' variable."
2682   (interactive (list t))
2683   (article-date-ut 'user highlight))
2684
2685 (defun article-date-iso8601 (&optional highlight)
2686   "Convert the current article date to ISO8601."
2687   (interactive (list t))
2688   (article-date-ut 'iso8601 highlight))
2689
2690 ;; (defun article-show-all ()
2691 ;;   "Show all hidden text in the article buffer."
2692 ;;   (interactive)
2693 ;;   (save-excursion
2694 ;;     (let ((buffer-read-only nil))
2695 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
2696
2697 (defun article-remove-leading-whitespace ()
2698   "Remove excessive whitespace from all headers."
2699   (interactive)
2700   (save-excursion
2701     (save-restriction
2702       (let ((buffer-read-only nil))
2703         (article-narrow-to-head)
2704         (goto-char (point-min))
2705         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2706           (delete-region (match-beginning 1) (match-end 1)))))))
2707
2708 (defun article-emphasize (&optional arg)
2709   "Emphasize text according to `gnus-emphasis-alist'."
2710   (interactive (gnus-article-hidden-arg))
2711   (unless (gnus-article-check-hidden-text 'emphasis arg)
2712     (save-excursion
2713       (let ((alist (or
2714                     (condition-case nil
2715                         (with-current-buffer gnus-summary-buffer
2716                           gnus-article-emphasis-alist)
2717                       (error))
2718                     gnus-emphasis-alist))
2719             (buffer-read-only nil)
2720             (props (append '(article-type emphasis)
2721                            gnus-hidden-properties))
2722             regexp elem beg invisible visible face)
2723         (article-goto-body)
2724         (setq beg (point))
2725         (while (setq elem (pop alist))
2726           (goto-char beg)
2727           (setq regexp (car elem)
2728                 invisible (nth 1 elem)
2729                 visible (nth 2 elem)
2730                 face (nth 3 elem))
2731           (while (re-search-forward regexp nil t)
2732             (when (and (match-beginning visible) (match-beginning invisible))
2733               (gnus-article-hide-text
2734                (match-beginning invisible) (match-end invisible) props)
2735               (gnus-article-unhide-text-type
2736                (match-beginning visible) (match-end visible) 'emphasis)
2737               (gnus-put-overlay-excluding-newlines
2738                (match-beginning visible) (match-end visible) 'face face)
2739               (gnus-add-wash-type 'emphasis)
2740               (goto-char (match-end invisible)))))))))
2741
2742 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2743   "Setup newsgroup emphasis alist."
2744   (unless gnus-article-emphasis-alist
2745     (let ((name (and gnus-newsgroup-name
2746                      (gnus-group-real-name gnus-newsgroup-name))))
2747       (make-local-variable 'gnus-article-emphasis-alist)
2748       (setq gnus-article-emphasis-alist
2749             (nconc
2750              (let ((alist gnus-group-highlight-words-alist) elem highlight)
2751                (while (setq elem (pop alist))
2752                  (when (and name (string-match (car elem) name))
2753                    (setq alist nil
2754                          highlight (copy-sequence (cdr elem)))))
2755                highlight)
2756              (copy-sequence highlight-words)
2757              (if gnus-newsgroup-name
2758                  (copy-sequence (gnus-group-find-parameter
2759                                  gnus-newsgroup-name 'highlight-words t)))
2760              gnus-emphasis-alist)))))
2761
2762 (eval-when-compile
2763   (defvar gnus-summary-article-menu)
2764   (defvar gnus-summary-post-menu))
2765
2766 ;;; Saving functions.
2767
2768 (defun gnus-article-save (save-buffer file &optional num)
2769   "Save the currently selected article."
2770   (unless gnus-save-all-headers
2771     ;; Remove headers according to `gnus-saved-headers'.
2772     (let ((gnus-visible-headers
2773            (or gnus-saved-headers gnus-visible-headers))
2774           (gnus-article-buffer save-buffer))
2775       (save-excursion
2776         (set-buffer save-buffer)
2777         (article-hide-headers 1 t))))
2778   (save-window-excursion
2779     (if (not gnus-default-article-saver)
2780         (error "No default saver is defined")
2781       ;; !!! Magic!  The saving functions all save
2782       ;; `gnus-save-article-buffer' (or so they think), but we
2783       ;; bind that variable to our save-buffer.
2784       (set-buffer gnus-article-buffer)
2785       (let* ((gnus-save-article-buffer save-buffer)
2786              (filename
2787               (cond
2788                ((not gnus-prompt-before-saving) 'default)
2789                ((eq gnus-prompt-before-saving 'always) nil)
2790                (t file)))
2791              (gnus-number-of-articles-to-be-saved
2792               (when (eq gnus-prompt-before-saving t)
2793                 num)))                  ; Magic
2794         (set-buffer gnus-article-current-summary)
2795         (funcall gnus-default-article-saver filename)))))
2796
2797 (defun gnus-read-save-file-name (prompt &optional filename
2798                                         function group headers variable)
2799   (let ((default-name
2800           (funcall function group headers (symbol-value variable)))
2801         result)
2802     (setq result
2803           (expand-file-name
2804            (cond
2805             ((eq filename 'default)
2806              default-name)
2807             ((eq filename t)
2808              default-name)
2809             (filename filename)
2810             (t
2811              (let* ((split-name (gnus-get-split-value gnus-split-methods))
2812                     (prompt
2813                      (format prompt
2814                              (if (and gnus-number-of-articles-to-be-saved
2815                                       (> gnus-number-of-articles-to-be-saved 1))
2816                                  (format "these %d articles"
2817                                          gnus-number-of-articles-to-be-saved)
2818                                "this article")))
2819                     (file
2820                      ;; Let the split methods have their say.
2821                      (cond
2822                       ;; No split name was found.
2823                       ((null split-name)
2824                        (read-file-name
2825                         (concat prompt " (default "
2826                                 (file-name-nondirectory default-name) ") ")
2827                         (file-name-directory default-name)
2828                         default-name))
2829                       ;; A single group name is returned.
2830                       ((stringp split-name)
2831                        (setq default-name
2832                              (funcall function split-name headers
2833                                       (symbol-value variable)))
2834                        (read-file-name
2835                         (concat prompt " (default "
2836                                 (file-name-nondirectory default-name) ") ")
2837                         (file-name-directory default-name)
2838                         default-name))
2839                       ;; A single split name was found
2840                       ((= 1 (length split-name))
2841                        (let* ((name (expand-file-name
2842                                      (car split-name)
2843                                      gnus-article-save-directory))
2844                               (dir (cond ((file-directory-p name)
2845                                           (file-name-as-directory name))
2846                                          ((file-exists-p name) name)
2847                                          (t gnus-article-save-directory))))
2848                          (read-file-name
2849                           (concat prompt " (default " name ") ")
2850                           dir name)))
2851                       ;; A list of splits was found.
2852                       (t
2853                        (setq split-name (nreverse split-name))
2854                        (let (result)
2855                          (let ((file-name-history
2856                                 (nconc split-name file-name-history)))
2857                            (setq result
2858                                  (expand-file-name
2859                                   (read-file-name
2860                                    (concat prompt " (`M-p' for defaults) ")
2861                                    gnus-article-save-directory
2862                                    (car split-name))
2863                                   gnus-article-save-directory)))
2864                          (car (push result file-name-history)))))))
2865                ;; Create the directory.
2866                (gnus-make-directory (file-name-directory file))
2867       ;; If we have read a directory, we append the default file name.
2868                (when (file-directory-p file)
2869                  (setq file (expand-file-name (file-name-nondirectory
2870                                                default-name)
2871                                               (file-name-as-directory file))))
2872                ;; Possibly translate some characters.
2873                (nnheader-translate-file-chars file))))))
2874     (gnus-make-directory (file-name-directory result))
2875     (set variable result)))
2876
2877 (defun gnus-article-archive-name (group)
2878   "Return the first instance of an \"Archive-name\" in the current buffer."
2879   (let ((case-fold-search t))
2880     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2881       (nnheader-concat gnus-article-save-directory
2882                        (match-string 1)))))
2883
2884 (defun gnus-article-nndoc-name (group)
2885   "If GROUP is an nndoc group, return the name of the parent group."
2886   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2887     (gnus-group-get-parameter group 'save-article-group)))
2888
2889 (defun gnus-summary-save-in-rmail (&optional filename)
2890   "Append this article to Rmail file.
2891 Optional argument FILENAME specifies file name.
2892 Directory to save to is default to `gnus-article-save-directory'."
2893   (setq filename (gnus-read-save-file-name
2894                   "Save %s in rmail file:" filename
2895                   gnus-rmail-save-name gnus-newsgroup-name
2896                   gnus-current-headers 'gnus-newsgroup-last-rmail))
2897   (gnus-eval-in-buffer-window gnus-save-article-buffer
2898     (save-excursion
2899       (save-restriction
2900         (widen)
2901         (gnus-output-to-rmail filename))))
2902   filename)
2903
2904 (defun gnus-summary-save-in-mail (&optional filename)
2905   "Append this article to Unix mail file.
2906 Optional argument FILENAME specifies file name.
2907 Directory to save to is default to `gnus-article-save-directory'."
2908   (setq filename (gnus-read-save-file-name
2909                   "Save %s in Unix mail file:" filename
2910                   gnus-mail-save-name gnus-newsgroup-name
2911                   gnus-current-headers 'gnus-newsgroup-last-mail))
2912   (gnus-eval-in-buffer-window gnus-save-article-buffer
2913     (save-excursion
2914       (save-restriction
2915         (widen)
2916         (if (and (file-readable-p filename)
2917                  (mail-file-babyl-p filename))
2918             (rmail-output-to-rmail-file filename t)
2919           (gnus-output-to-mail filename)))))
2920   filename)
2921
2922 (defun gnus-summary-save-in-file (&optional filename overwrite)
2923   "Append this article to file.
2924 Optional argument FILENAME specifies file name.
2925 Directory to save to is default to `gnus-article-save-directory'."
2926   (setq filename (gnus-read-save-file-name
2927                   "Save %s in file:" filename
2928                   gnus-file-save-name gnus-newsgroup-name
2929                   gnus-current-headers 'gnus-newsgroup-last-file))
2930   (gnus-eval-in-buffer-window gnus-save-article-buffer
2931     (save-excursion
2932       (save-restriction
2933         (widen)
2934         (when (and overwrite
2935                    (file-exists-p filename))
2936           (delete-file filename))
2937         (gnus-output-to-file filename))))
2938   filename)
2939
2940 (defun gnus-summary-write-to-file (&optional filename)
2941   "Write this article to a file, overwriting it if the file exists.
2942 Optional argument FILENAME specifies file name.
2943 The directory to save in defaults to `gnus-article-save-directory'."
2944   (gnus-summary-save-in-file nil t))
2945
2946 (defun gnus-summary-save-body-in-file (&optional filename)
2947   "Append this article body to a file.
2948 Optional argument FILENAME specifies file name.
2949 The directory to save in defaults to `gnus-article-save-directory'."
2950   (setq filename (gnus-read-save-file-name
2951                   "Save %s body in file:" filename
2952                   gnus-file-save-name gnus-newsgroup-name
2953                   gnus-current-headers 'gnus-newsgroup-last-file))
2954   (gnus-eval-in-buffer-window gnus-save-article-buffer
2955     (save-excursion
2956       (save-restriction
2957         (widen)
2958         (when (article-goto-body)
2959           (narrow-to-region (point) (point-max)))
2960         (gnus-output-to-file filename))))
2961   filename)
2962
2963 (defun gnus-summary-save-in-pipe (&optional command)
2964   "Pipe this article to subprocess."
2965   (setq command
2966         (cond ((and (eq command 'default)
2967                     gnus-last-shell-command)
2968                gnus-last-shell-command)
2969               ((stringp command)
2970                command)
2971               (t (read-string
2972                   (format
2973                    "Shell command on %s: "
2974                    (if (and gnus-number-of-articles-to-be-saved
2975                             (> gnus-number-of-articles-to-be-saved 1))
2976                        (format "these %d articles"
2977                                gnus-number-of-articles-to-be-saved)
2978                      "this article"))
2979                   gnus-last-shell-command))))
2980   (when (string-equal command "")
2981     (if gnus-last-shell-command
2982         (setq command gnus-last-shell-command)
2983       (error "A command is required")))
2984   (gnus-eval-in-buffer-window gnus-article-buffer
2985     (save-restriction
2986       (widen)
2987       (shell-command-on-region (point-min) (point-max) command nil)))
2988   (setq gnus-last-shell-command command))
2989
2990 (defun gnus-summary-pipe-to-muttprint (&optional command)
2991   "Pipe this article to muttprint."
2992   (setq command (read-string
2993                  "Print using command: " gnus-summary-muttprint-program
2994                  nil gnus-summary-muttprint-program))
2995   (gnus-summary-save-in-pipe command))
2996
2997 ;;; Article file names when saving.
2998
2999 (defun gnus-capitalize-newsgroup (newsgroup)
3000   "Capitalize NEWSGROUP name."
3001   (when (not (zerop (length newsgroup)))
3002     (concat (char-to-string (upcase (aref newsgroup 0)))
3003             (substring newsgroup 1))))
3004
3005 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3006   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3007 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3008 Otherwise, it is like ~/News/news/group/num."
3009   (let ((default
3010           (expand-file-name
3011            (concat (if (gnus-use-long-file-name 'not-save)
3012                        (gnus-capitalize-newsgroup newsgroup)
3013                      (gnus-newsgroup-directory-form newsgroup))
3014                    "/" (int-to-string (mail-header-number headers)))
3015            gnus-article-save-directory)))
3016     (if (and last-file
3017              (string-equal (file-name-directory default)
3018                            (file-name-directory last-file))
3019              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3020         default
3021       (or last-file default))))
3022
3023 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3024   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3025 If variable `gnus-use-long-file-name' is non-nil, it is
3026 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3027   (let ((default
3028           (expand-file-name
3029            (concat (if (gnus-use-long-file-name 'not-save)
3030                        newsgroup
3031                      (gnus-newsgroup-directory-form newsgroup))
3032                    "/" (int-to-string (mail-header-number headers)))
3033            gnus-article-save-directory)))
3034     (if (and last-file
3035              (string-equal (file-name-directory default)
3036                            (file-name-directory last-file))
3037              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3038         default
3039       (or last-file default))))
3040
3041 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3042   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3043 If variable `gnus-use-long-file-name' is non-nil, it is
3044 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3045   (or last-file
3046       (expand-file-name
3047        (if (gnus-use-long-file-name 'not-save)
3048            newsgroup
3049          (file-relative-name
3050           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3051           default-directory))
3052        gnus-article-save-directory)))
3053
3054 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3055   "Generate file name from sender."
3056   (let ((from (mail-header-from headers)))
3057     (expand-file-name
3058      (if (and from (string-match "\\([^ <]+\\)@" from))
3059          (match-string 1 from)
3060        "nobody")
3061      gnus-article-save-directory)))
3062
3063 (defun article-verify-x-pgp-sig ()
3064   "Verify X-PGP-Sig."
3065   (interactive)
3066   (if (gnus-buffer-live-p gnus-original-article-buffer)
3067       (let ((sig (with-current-buffer gnus-original-article-buffer
3068                    (gnus-fetch-field "X-PGP-Sig")))
3069             items info headers)
3070         (when (and sig
3071                    mml2015-use
3072                    (mml2015-clear-verify-function))
3073           (with-temp-buffer
3074             (insert-buffer gnus-original-article-buffer)
3075             (setq items (split-string sig))
3076             (message-narrow-to-head)
3077             (let ((inhibit-point-motion-hooks t)
3078                   (case-fold-search t))
3079               ;; Don't verify multiple headers.
3080               (setq headers (mapconcat (lambda (header)
3081                                          (concat header ": "
3082                                                  (mail-fetch-field header) "\n"))
3083                                        (split-string (nth 1 items) ",") "")))
3084             (delete-region (point-min) (point-max))
3085             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3086             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3087             (insert headers)
3088             (widen)
3089             (forward-line)
3090             (while (not (eobp))
3091               (if (looking-at "^-")
3092                   (insert "- "))
3093               (forward-line))
3094             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3095             (insert "Version: " (car items) "\n\n")
3096             (insert (mapconcat 'identity (cddr items) "\n"))
3097             (insert "\n-----END PGP SIGNATURE-----\n")
3098             (let ((mm-security-handle (list (format "multipart/signed"))))
3099               (mml2015-clean-buffer)
3100               (let ((coding-system-for-write (or gnus-newsgroup-charset
3101                                                  'iso-8859-1)))
3102                 (funcall (mml2015-clear-verify-function)))
3103               (setq info
3104                     (or (mm-handle-multipart-ctl-parameter
3105                          mm-security-handle 'gnus-details)
3106                         (mm-handle-multipart-ctl-parameter
3107                          mm-security-handle 'gnus-info)))))
3108           (when info
3109             (let (buffer-read-only bface eface)
3110               (save-restriction
3111                 (message-narrow-to-head)
3112                 (goto-char (point-max))
3113                 (forward-line -1)
3114                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3115                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3116                 (message-remove-header "X-Gnus-PGP-Verify")
3117                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3118                     (forward-line)
3119                   (goto-char (point-max)))
3120                 (narrow-to-region (point) (point))
3121                 (insert "X-Gnus-PGP-Verify: " info "\n")
3122                 (goto-char (point-min))
3123                 (forward-line)
3124                 (while (not (eobp))
3125                   (if (not (looking-at "^[ \t]"))
3126                       (insert " "))
3127                   (forward-line))
3128                 ;; Do highlighting.
3129                 (goto-char (point-min))
3130                 (when (looking-at "\\([^:]+\\): *")
3131                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3132                                      'face bface)
3133                   (put-text-property (match-end 0) (point-max)
3134                                      'face eface)))))))))
3135
3136 (defun article-verify-cancel-lock ()
3137   "Verify Cancel-Lock header."
3138   (interactive)
3139   (if (gnus-buffer-live-p gnus-original-article-buffer)
3140       (canlock-verify gnus-original-article-buffer)))
3141
3142 (eval-and-compile
3143   (mapcar
3144    (lambda (func)
3145      (let (afunc gfunc)
3146        (if (consp func)
3147            (setq afunc (car func)
3148                  gfunc (cdr func))
3149          (setq afunc func
3150                gfunc (intern (format "gnus-%s" func))))
3151        (defalias gfunc
3152          (when (fboundp afunc)
3153            `(lambda (&optional interactive &rest args)
3154               ,(documentation afunc t)
3155               (interactive (list t))
3156               (save-excursion
3157                 (set-buffer gnus-article-buffer)
3158                 (if interactive
3159                     (call-interactively ',afunc)
3160                   (apply ',afunc args))))))))
3161    '(article-hide-headers
3162      article-verify-x-pgp-sig
3163      article-verify-cancel-lock
3164      article-hide-boring-headers
3165      article-treat-overstrike
3166      article-fill-long-lines
3167      article-capitalize-sentences
3168      article-remove-cr
3169      article-remove-leading-whitespace
3170      article-display-x-face
3171      article-de-quoted-unreadable
3172      article-de-base64-unreadable
3173      article-decode-HZ
3174      article-wash-html
3175      article-hide-list-identifiers
3176      article-hide-pgp
3177      article-strip-banner
3178      article-babel
3179      article-hide-pem
3180      article-hide-signature
3181      article-strip-headers-in-body
3182      article-remove-trailing-blank-lines
3183      article-strip-leading-blank-lines
3184      article-strip-multiple-blank-lines
3185      article-strip-leading-space
3186      article-strip-trailing-space
3187      article-strip-blank-lines
3188      article-strip-all-blank-lines
3189      article-replace-with-quoted-text
3190      article-date-local
3191      article-date-english
3192      article-date-iso8601
3193      article-date-original
3194      article-date-ut
3195      article-decode-mime-words
3196      article-decode-charset
3197      article-decode-encoded-words
3198      article-date-user
3199      article-date-lapsed
3200      article-emphasize
3201      article-treat-dumbquotes
3202      article-normalize-headers
3203 ;;     (article-show-all . gnus-article-show-all-headers)
3204      )))
3205 \f
3206 ;;;
3207 ;;; Gnus article mode
3208 ;;;
3209
3210 (put 'gnus-article-mode 'mode-class 'special)
3211
3212 (set-keymap-parent gnus-article-mode-map widget-keymap)
3213
3214 (gnus-define-keys gnus-article-mode-map
3215   " " gnus-article-goto-next-page
3216   "\177" gnus-article-goto-prev-page
3217   [delete] gnus-article-goto-prev-page
3218   [backspace] gnus-article-goto-prev-page
3219   "\C-c^" gnus-article-refer-article
3220   "h" gnus-article-show-summary
3221   "s" gnus-article-show-summary
3222   "\C-c\C-m" gnus-article-mail
3223   "?" gnus-article-describe-briefly
3224   "e" gnus-summary-edit-article
3225   "<" beginning-of-buffer
3226   ">" end-of-buffer
3227   "\C-c\C-i" gnus-info-find-node
3228   "\C-c\C-b" gnus-bug
3229   "R" gnus-article-reply-with-original
3230   "F" gnus-article-followup-with-original
3231   "\C-hk" gnus-article-describe-key
3232   "\C-hc" gnus-article-describe-key-briefly
3233
3234   "\C-d" gnus-article-read-summary-keys
3235   "\M-*" gnus-article-read-summary-keys
3236   "\M-#" gnus-article-read-summary-keys
3237   "\M-^" gnus-article-read-summary-keys
3238   "\M-g" gnus-article-read-summary-keys)
3239
3240 (substitute-key-definition
3241  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3242
3243 (defun gnus-article-make-menu-bar ()
3244   (unless (boundp 'gnus-article-commands-menu)
3245     (gnus-summary-make-menu-bar))
3246   (gnus-turn-off-edit-menu 'article)
3247   (unless (boundp 'gnus-article-article-menu)
3248     (easy-menu-define
3249      gnus-article-article-menu gnus-article-mode-map ""
3250      '("Article"
3251        ["Scroll forwards" gnus-article-goto-next-page t]
3252        ["Scroll backwards" gnus-article-goto-prev-page t]
3253        ["Show summary" gnus-article-show-summary t]
3254        ["Fetch Message-ID at point" gnus-article-refer-article t]
3255        ["Mail to address at point" gnus-article-mail t]
3256        ["Send a bug report" gnus-bug t]))
3257
3258     (easy-menu-define
3259      gnus-article-treatment-menu gnus-article-mode-map ""
3260      ;; Fixme: this should use :active (and maybe :visible).
3261      '("Treatment"
3262        ["Hide headers" gnus-article-hide-headers t]
3263        ["Hide signature" gnus-article-hide-signature t]
3264        ["Hide citation" gnus-article-hide-citation t]
3265        ["Treat overstrike" gnus-article-treat-overstrike t]
3266        ["Remove carriage return" gnus-article-remove-cr t]
3267        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3268        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3269        ["Remove base64" gnus-article-de-base64-unreadable t]
3270        ["Treat html" gnus-article-wash-html t]
3271        ["Decode HZ" gnus-article-decode-HZ t]))
3272
3273     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3274
3275     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3276
3277     (gnus-run-hooks 'gnus-article-menu-hook)))
3278
3279 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3280 ;; Summary.
3281
3282 (defun gnus-article-mode ()
3283   "Major mode for displaying an article.
3284
3285 All normal editing commands are switched off.
3286
3287 The following commands are available in addition to all summary mode
3288 commands:
3289 \\<gnus-article-mode-map>
3290 \\[gnus-article-next-page]\t Scroll the article one page forwards
3291 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3292 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3293 \\[gnus-article-show-summary]\t Display the summary buffer
3294 \\[gnus-article-mail]\t Send a reply to the address near point
3295 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3296 \\[gnus-info-find-node]\t Go to the Gnus info node"
3297   (interactive)
3298   (gnus-simplify-mode-line)
3299   (setq mode-name "Article")
3300   (setq major-mode 'gnus-article-mode)
3301   (make-local-variable 'minor-mode-alist)
3302   (use-local-map gnus-article-mode-map)
3303   (when (gnus-visual-p 'article-menu 'menu)
3304     (gnus-article-make-menu-bar))
3305   (gnus-update-format-specifications nil 'article-mode)
3306   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3307   (make-local-variable 'gnus-page-broken)
3308   (make-local-variable 'gnus-button-marker-list)
3309   (make-local-variable 'gnus-article-current-summary)
3310   (make-local-variable 'gnus-article-mime-handles)
3311   (make-local-variable 'gnus-article-decoded-p)
3312   (make-local-variable 'gnus-article-mime-handle-alist)
3313   (make-local-variable 'gnus-article-wash-types)
3314   (make-local-variable 'gnus-article-image-alist)
3315   (make-local-variable 'gnus-article-charset)
3316   (make-local-variable 'gnus-article-ignored-charsets)
3317   (gnus-set-default-directory)
3318   (buffer-disable-undo)
3319   (setq buffer-read-only t)
3320   (set-syntax-table gnus-article-mode-syntax-table)
3321   (mm-enable-multibyte)
3322   (gnus-run-hooks 'gnus-article-mode-hook))
3323
3324 (defun gnus-article-setup-buffer ()
3325   "Initialize the article buffer."
3326   (let* ((name (if gnus-single-article-buffer "*Article*"
3327                  (concat "*Article " gnus-newsgroup-name "*")))
3328          (original
3329           (progn (string-match "\\*Article" name)
3330                  (concat " *Original Article"
3331                          (substring name (match-end 0))))))
3332     (setq gnus-article-buffer name)
3333     (setq gnus-original-article-buffer original)
3334     (setq gnus-article-mime-handle-alist nil)
3335     ;; This might be a variable local to the summary buffer.
3336     (unless gnus-single-article-buffer
3337       (save-excursion
3338         (set-buffer gnus-summary-buffer)
3339         (setq gnus-article-buffer name)
3340         (setq gnus-original-article-buffer original)
3341         (gnus-set-global-variables)))
3342     (gnus-article-setup-highlight-words)
3343     ;; Init original article buffer.
3344     (save-excursion
3345       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3346       (mm-enable-multibyte)
3347       (setq major-mode 'gnus-original-article-mode)
3348       (make-local-variable 'gnus-original-article))
3349     (if (get-buffer name)
3350         (save-excursion
3351           (set-buffer name)
3352           (when gnus-article-mime-handles
3353             (mm-destroy-parts gnus-article-mime-handles)
3354             (setq gnus-article-mime-handles nil))
3355           ;; Set it to nil in article-buffer!
3356           (setq gnus-article-mime-handle-alist nil)
3357           (buffer-disable-undo)
3358           (setq buffer-read-only t)
3359           (unless (eq major-mode 'gnus-article-mode)
3360             (gnus-article-mode))
3361           (current-buffer))
3362       (save-excursion
3363         (set-buffer (gnus-get-buffer-create name))
3364         (gnus-article-mode)
3365         (make-local-variable 'gnus-summary-buffer)
3366         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3367         (current-buffer)))))
3368
3369 ;; Set article window start at LINE, where LINE is the number of lines
3370 ;; from the head of the article.
3371 (defun gnus-article-set-window-start (&optional line)
3372   (set-window-start
3373    (gnus-get-buffer-window gnus-article-buffer t)
3374    (save-excursion
3375      (set-buffer gnus-article-buffer)
3376      (goto-char (point-min))
3377      (if (not line)
3378          (point-min)
3379        (gnus-message 6 "Moved to bookmark")
3380        (search-forward "\n\n" nil t)
3381        (forward-line line)
3382        (point)))))
3383
3384 (defun gnus-article-prepare (article &optional all-headers header)
3385   "Prepare ARTICLE in article mode buffer.
3386 ARTICLE should either be an article number or a Message-ID.
3387 If ARTICLE is an id, HEADER should be the article headers.
3388 If ALL-HEADERS is non-nil, no headers are hidden."
3389   (save-excursion
3390     ;; Make sure we start in a summary buffer.
3391     (unless (eq major-mode 'gnus-summary-mode)
3392       (set-buffer gnus-summary-buffer))
3393     (setq gnus-summary-buffer (current-buffer))
3394     (let* ((gnus-article (if header (mail-header-number header) article))
3395            (summary-buffer (current-buffer))
3396            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3397            (group gnus-newsgroup-name)
3398            result)
3399       (save-excursion
3400         (gnus-article-setup-buffer)
3401         (set-buffer gnus-article-buffer)
3402         ;; Deactivate active regions.
3403         (when (and (boundp 'transient-mark-mode)
3404                    transient-mark-mode)
3405           (setq mark-active nil))
3406         (if (not (setq result (let ((buffer-read-only nil))
3407                                 (gnus-request-article-this-buffer
3408                                  article group))))
3409             ;; There is no such article.
3410             (save-excursion
3411               (when (and (numberp article)
3412                          (not (memq article gnus-newsgroup-sparse)))
3413                 (setq gnus-article-current
3414                       (cons gnus-newsgroup-name article))
3415                 (set-buffer gnus-summary-buffer)
3416                 (setq gnus-current-article article)
3417                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3418                     (progn
3419                       (gnus-summary-set-agent-mark article)
3420                       (message "Message marked for downloading"))
3421                   (gnus-summary-mark-article article gnus-canceled-mark)
3422                   (unless (memq article gnus-newsgroup-sparse)
3423                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3424           (if (or (eq result 'pseudo)
3425                   (eq result 'nneething))
3426               (progn
3427                 (save-excursion
3428                   (set-buffer summary-buffer)
3429                   (push article gnus-newsgroup-history)
3430                   (setq gnus-last-article gnus-current-article
3431                         gnus-current-article 0
3432                         gnus-current-headers nil
3433                         gnus-article-current nil)
3434                   (if (eq result 'nneething)
3435                       (gnus-configure-windows 'summary)
3436                     (gnus-configure-windows 'article))
3437                   (gnus-set-global-variables))