2001-07-25 11:00:00 ShengHuo ZHU <zsh@cs.rochester.edu>
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
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 'mm-bodies)
36 (require 'mail-parse)
37 (require 'mm-decode)
38 (require 'mm-view)
39 (require 'wid-edit)
40 (require 'mm-uu)
41
42 (autoload 'gnus-msg-mail "gnus-msg" nil t)
43 (autoload 'gnus-button-mailto "gnus-msg")
44 (autoload 'gnus-button-reply "gnus-msg" nil t)
45
46 (defgroup gnus-article nil
47   "Article display."
48   :link '(custom-manual "(gnus)The Article Buffer")
49   :group 'gnus)
50
51 (defgroup gnus-article-treat nil
52   "Treating article parts."
53   :link '(custom-manual "(gnus)Article Hiding")
54   :group 'gnus-article)
55
56 (defgroup gnus-article-hiding nil
57   "Hiding article parts."
58   :link '(custom-manual "(gnus)Article Hiding")
59   :group 'gnus-article)
60
61 (defgroup gnus-article-highlight nil
62   "Article highlighting."
63   :link '(custom-manual "(gnus)Article Highlighting")
64   :group 'gnus-article
65   :group 'gnus-visual)
66
67 (defgroup gnus-article-signature nil
68   "Article signatures."
69   :link '(custom-manual "(gnus)Article Signature")
70   :group 'gnus-article)
71
72 (defgroup gnus-article-headers nil
73   "Article headers."
74   :link '(custom-manual "(gnus)Hiding Headers")
75   :group 'gnus-article)
76
77 (defgroup gnus-article-washing nil
78   "Special commands on articles."
79   :link '(custom-manual "(gnus)Article Washing")
80   :group 'gnus-article)
81
82 (defgroup gnus-article-emphasis nil
83   "Fontisizing articles."
84   :link '(custom-manual "(gnus)Article Fontisizing")
85   :group 'gnus-article)
86
87 (defgroup gnus-article-saving nil
88   "Saving articles."
89   :link '(custom-manual "(gnus)Saving Articles")
90   :group 'gnus-article)
91
92 (defgroup gnus-article-mime nil
93   "Worshiping the MIME wonder."
94   :link '(custom-manual "(gnus)Using MIME")
95   :group 'gnus-article)
96
97 (defgroup gnus-article-buttons nil
98   "Pushable buttons in the article buffer."
99   :link '(custom-manual "(gnus)Article Buttons")
100   :group 'gnus-article)
101
102 (defgroup gnus-article-various nil
103   "Other article options."
104   :link '(custom-manual "(gnus)Misc Article")
105   :group 'gnus-article)
106
107 (defcustom gnus-ignored-headers
108   '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
109     "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
110     "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
111     "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
112     "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
113     "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
114     "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
115     "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
116     "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
117     "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
118     "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
119     "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
120     "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
121     "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
122     "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
123     "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
124     "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
125     "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
126     "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
127     "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
128     "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
129     "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
130     "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
131     "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
132     "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
133     "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
134     "^X-Received:" "^Content-length:" "X-precedence:"
135     "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
136     "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
137     "^X-Abuse-Info:")
138   "*All headers that start with this regexp will be hidden.
139 This variable can also be a list of regexps of headers to be ignored.
140 If `gnus-visible-headers' is non-nil, this variable will be ignored."
141   :type '(choice :custom-show nil
142                  regexp
143                  (repeat regexp))
144   :group 'gnus-article-hiding)
145
146 (defcustom gnus-visible-headers
147   "^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:"
148   "*All headers that do not match this regexp will be hidden.
149 This variable can also be a list of regexp of headers to remain visible.
150 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
151   :type '(repeat :value-to-internal (lambda (widget value)
152                                       (custom-split-regexp-maybe value))
153                  :match (lambda (widget value)
154                           (or (stringp value)
155                               (widget-editable-list-match widget value)))
156                  regexp)
157   :group 'gnus-article-hiding)
158
159 (defcustom gnus-sorted-header-list
160   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
161     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
162   "*This variable is a list of regular expressions.
163 If it is non-nil, headers that match the regular expressions will
164 be placed first in the article buffer in the sequence specified by
165 this list."
166   :type '(repeat regexp)
167   :group 'gnus-article-hiding)
168
169 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
170   "Headers that are only to be displayed if they have interesting data.
171 Possible values in this list are:
172
173   'empty       Headers with no content.
174   'newsgroups  Newsgroup identical to Gnus group.
175   'to-address  To identical to To-address.
176   'followup-to Followup-to identical to Newsgroups.
177   'reply-to    Reply-to identical to From.
178   'date        Date less than four days old.
179   'long-to     To and/or Cc longer than 1024 characters.
180   'many-to     Multiple To and/or Cc."
181   :type '(set (const :tag "Headers with no content." empty)
182               (const :tag "Newsgroups identical to Gnus group." newsgroups)
183               (const :tag "To identical to To-address." to-address)
184               (const :tag "Followup-to identical to Newsgroups." followup-to)
185               (const :tag "Reply-to identical to From." reply-to)
186               (const :tag "Date less than four days old." date)
187               (const :tag "To and/or Cc longer than 1024 characters." long-to)
188               (const :tag "Multiple To and/or Cc headers." many-to))
189   :group 'gnus-article-hiding)
190
191 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
192   "Regexp matching signature separator.
193 This can also be a list of regexps.  In that case, it will be checked
194 from head to tail looking for a separator.  Searches will be done from
195 the end of the buffer."
196   :type '(repeat string)
197   :group 'gnus-article-signature)
198
199 (defcustom gnus-signature-limit nil
200   "Provide a limit to what is considered a signature.
201 If it is a number, no signature may not be longer (in characters) than
202 that number.  If it is a floating point number, no signature may be
203 longer (in lines) than that number.  If it is a function, the function
204 will be called without any parameters, and if it returns nil, there is
205 no signature in the buffer.  If it is a string, it will be used as a
206 regexp.  If it matches, the text in question is not a signature."
207   :type '(choice (integer :value 200)
208                  (number :value 4.0)
209                  (function :value fun)
210                  (regexp :value ".*"))
211   :group 'gnus-article-signature)
212
213 (defcustom gnus-hidden-properties '(invisible t intangible t)
214   "Property list to use for hiding text."
215   :type 'sexp
216   :group 'gnus-article-hiding)
217
218 ;; Fixme: This isn't the right thing for mixed graphical and and
219 ;; non-graphical frames in a session.
220 ;; gnus-xmas.el overrides this for XEmacs.
221 (defcustom gnus-article-x-face-command
222   (if (and (fboundp 'image-type-available-p)
223            (image-type-available-p 'xbm))
224       'gnus-article-display-xface
225     (if gnus-article-compface-xbm
226         "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
227       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
228 display -"))
229   "*String or function to be executed to display an X-Face header.
230 If it is a string, the command will be executed in a sub-shell
231 asynchronously.  The compressed face will be piped to this command."
232   :type '(choice string
233                  (function-item gnus-article-display-xface)
234                  function)
235   :version "21.1"
236   :group 'gnus-article-washing)
237
238 (defcustom gnus-article-x-face-too-ugly nil
239   "Regexp matching posters whose face shouldn't be shown automatically."
240   :type '(choice regexp (const nil))
241   :group 'gnus-article-washing)
242
243 (defcustom gnus-article-banner-alist nil
244   "Banner alist for stripping.
245 For example,
246      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
247   :version "21.1"
248   :type '(repeat (cons symbol regexp))
249   :group 'gnus-article-washing)
250
251 (gnus-define-group-parameter
252  banner
253  :variable-document
254  "Alist of regexps (to match group names) and banner."
255  :variable-group gnus-article-washing
256  :parameter-type
257  '(choice :tag "Banner"
258           :value nil
259           (const :tag "Remove signature" signature)
260           (symbol :tag "Item in `gnus-article-banner-alist'" none)
261           regexp
262           (const :tag "None" nil))
263  :parameter-document
264  "If non-nil, specify how to remove `banners' from articles.
265
266 Symbol `signature' means to remove signatures delimited by
267 `gnus-signature-separator'.  Any other symbol is used to look up a
268 regular expression to match the banner in `gnus-article-banner-alist'.
269 A string is used as a regular expression to match the banner
270 directly.")
271
272 (defcustom gnus-emphasis-alist
273   (let ((format
274          "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
275         (types
276          '(("_" "_" underline)
277            ("/" "/" italic)
278            ("\\*" "\\*" bold)
279            ("_/" "/_" underline-italic)
280            ("_\\*" "\\*_" underline-bold)
281            ("\\*/" "/\\*" bold-italic)
282            ("_\\*/" "/\\*_" underline-bold-italic))))
283     `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
284        2 3 gnus-emphasis-underline)
285       ,@(mapcar
286          (lambda (spec)
287            (list
288             (format format (car spec) (cadr spec))
289             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
290          types)))
291   "*Alist that says how to fontify certain phrases.
292 Each item looks like this:
293
294   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
295
296 The first element is a regular expression to be matched.  The second
297 is a number that says what regular expression grouping used to find
298 the entire emphasized word.  The third is a number that says what
299 regexp grouping should be displayed and highlighted.  The fourth
300 is the face used for highlighting."
301   :type '(repeat (list :value ("" 0 0 default)
302                        regexp
303                        (integer :tag "Match group")
304                        (integer :tag "Emphasize group")
305                        face))
306   :group 'gnus-article-emphasis)
307
308 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
309   "A regexp to describe whitespace which should not be emphasized.
310 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
311 The former avoids underlining of leading and trailing whitespace,
312 and the latter avoids underlining any whitespace at all."
313   :version "21.1"
314   :group 'gnus-article-emphasis
315   :type 'regexp)
316
317 (defface gnus-emphasis-bold '((t (:bold t)))
318   "Face used for displaying strong emphasized text (*word*)."
319   :group 'gnus-article-emphasis)
320
321 (defface gnus-emphasis-italic '((t (:italic t)))
322   "Face used for displaying italic emphasized text (/word/)."
323   :group 'gnus-article-emphasis)
324
325 (defface gnus-emphasis-underline '((t (:underline t)))
326   "Face used for displaying underlined emphasized text (_word_)."
327   :group 'gnus-article-emphasis)
328
329 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
330   "Face used for displaying underlined bold emphasized text (_*word*_)."
331   :group 'gnus-article-emphasis)
332
333 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
334   "Face used for displaying underlined italic emphasized text (_/word/_)."
335   :group 'gnus-article-emphasis)
336
337 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
338   "Face used for displaying bold italic emphasized text (/*word*/)."
339   :group 'gnus-article-emphasis)
340
341 (defface gnus-emphasis-underline-bold-italic
342   '((t (:bold t :italic t :underline t)))
343   "Face used for displaying underlined bold italic emphasized text.
344 Esample: (_/*word*/_)."
345   :group 'gnus-article-emphasis)
346
347 (defface gnus-emphasis-highlight-words
348   '((t (:background "black" :foreground "yellow")))
349   "Face used for displaying highlighted words."
350   :group 'gnus-article-emphasis)
351
352 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
353   "Format for display of Date headers in article bodies.
354 See `format-time-string' for the possible values.
355
356 The variable can also be function, which should return a complete Date
357 header.  The function is called with one argument, the time, which can
358 be fed to `format-time-string'."
359   :type '(choice string symbol)
360   :link '(custom-manual "(gnus)Article Date")
361   :group 'gnus-article-washing)
362
363 (eval-and-compile
364   (autoload 'mail-extract-address-components "mail-extr"))
365
366 (defcustom gnus-save-all-headers t
367   "*If non-nil, don't remove any headers before saving."
368   :group 'gnus-article-saving
369   :type 'boolean)
370
371 (defcustom gnus-prompt-before-saving 'always
372   "*This variable says how much prompting is to be done when saving articles.
373 If it is nil, no prompting will be done, and the articles will be
374 saved to the default files.  If this variable is `always', each and
375 every article that is saved will be preceded by a prompt, even when
376 saving large batches of articles.  If this variable is neither nil not
377 `always', there the user will be prompted once for a file name for
378 each invocation of the saving commands."
379   :group 'gnus-article-saving
380   :type '(choice (item always)
381                  (item :tag "never" nil)
382                  (sexp :tag "once" :format "%t\n" :value t)))
383
384 (defcustom gnus-saved-headers gnus-visible-headers
385   "Headers to keep if `gnus-save-all-headers' is nil.
386 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
387 If that variable is nil, however, all headers that match this regexp
388 will be kept while the rest will be deleted before saving."
389   :group 'gnus-article-saving
390   :type 'regexp)
391
392 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
393   "A function to save articles in your favourite format.
394 The function must be interactively callable (in other words, it must
395 be an Emacs command).
396
397 Gnus provides the following functions:
398
399 * gnus-summary-save-in-rmail (Rmail format)
400 * gnus-summary-save-in-mail (Unix mail format)
401 * gnus-summary-save-in-folder (MH folder)
402 * gnus-summary-save-in-file (article format)
403 * gnus-summary-save-in-vm (use VM's folder format)
404 * gnus-summary-write-to-file (article format -- overwrite)."
405   :group 'gnus-article-saving
406   :type '(radio (function-item gnus-summary-save-in-rmail)
407                 (function-item gnus-summary-save-in-mail)
408                 (function-item gnus-summary-save-in-folder)
409                 (function-item gnus-summary-save-in-file)
410                 (function-item gnus-summary-save-in-vm)
411                 (function-item gnus-summary-write-to-file)))
412
413 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
414   "A function generating a file name to save articles in Rmail format.
415 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
416   :group 'gnus-article-saving
417   :type 'function)
418
419 (defcustom gnus-mail-save-name 'gnus-plain-save-name
420   "A function generating a file name to save articles in Unix mail format.
421 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
422   :group 'gnus-article-saving
423   :type 'function)
424
425 (defcustom gnus-folder-save-name 'gnus-folder-save-name
426   "A function generating a file name to save articles in MH folder.
427 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
428   :group 'gnus-article-saving
429   :type 'function)
430
431 (defcustom gnus-file-save-name 'gnus-numeric-save-name
432   "A function generating a file name to save articles in article format.
433 The function is called with NEWSGROUP, HEADERS, and optional
434 LAST-FILE."
435   :group 'gnus-article-saving
436   :type 'function)
437
438 (defcustom gnus-split-methods
439   '((gnus-article-archive-name)
440     (gnus-article-nndoc-name))
441   "*Variable used to suggest where articles are to be saved.
442 For instance, if you would like to save articles related to Gnus in
443 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
444 you could set this variable to something like:
445
446  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
447    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
448
449 This variable is an alist where the where the key is the match and the
450 value is a list of possible files to save in if the match is non-nil.
451
452 If the match is a string, it is used as a regexp match on the
453 article.  If the match is a symbol, that symbol will be funcalled
454 from the buffer of the article to be saved with the newsgroup as the
455 parameter.  If it is a list, it will be evaled in the same buffer.
456
457 If this form or function returns a string, this string will be used as
458 a possible file name; and if it returns a non-nil list, that list will
459 be used as possible file names."
460   :group 'gnus-article-saving
461   :type '(repeat (choice (list :value (fun) function)
462                          (cons :value ("" "") regexp (repeat string))
463                          (sexp :value nil))))
464
465 (defcustom gnus-page-delimiter "^\^L"
466   "*Regexp describing what to use as article page delimiters.
467 The default value is \"^\^L\", which is a form linefeed at the
468 beginning of a line."
469   :type 'regexp
470   :group 'gnus-article-various)
471
472 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
473   "*The format specification for the article mode line.
474 See `gnus-summary-mode-line-format' for a closer description.
475
476 The following additional specs are available:
477
478 %w  The article washing status.
479 %m  The number of MIME parts in the article."
480   :type 'string
481   :group 'gnus-article-various)
482
483 (defcustom gnus-article-mode-hook nil
484   "*A hook for Gnus article mode."
485   :type 'hook
486   :group 'gnus-article-various)
487
488 (when (featurep 'xemacs)
489   ;; Extracted from gnus-xmas-define in order to preserve user settings
490   (when (fboundp 'turn-off-scroll-in-place)
491     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
492   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
493   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
494
495 (defcustom gnus-article-menu-hook nil
496   "*Hook run after the creation of the article mode menu."
497   :type 'hook
498   :group 'gnus-article-various)
499
500 (defcustom gnus-article-prepare-hook nil
501   "*A hook called after an article has been prepared in the article buffer."
502   :type 'hook
503   :group 'gnus-article-various)
504
505 (defcustom gnus-article-hide-pgp-hook nil
506   "*A hook called after successfully hiding a PGP signature."
507   :type 'hook
508   :group 'gnus-article-various)
509
510 (defcustom gnus-article-button-face 'bold
511   "Face used for highlighting buttons in the article buffer.
512
513 An article button is a piece of text that you can activate by pressing
514 `RET' or `mouse-2' above it."
515   :type 'face
516   :group 'gnus-article-buttons)
517
518 (defcustom gnus-article-mouse-face 'highlight
519   "Face used for mouse highlighting in the article buffer.
520
521 Article buttons will be displayed in this face when the cursor is
522 above them."
523   :type 'face
524   :group 'gnus-article-buttons)
525
526 (defcustom gnus-signature-face 'gnus-signature-face
527   "Face used for highlighting a signature in the article buffer.
528 Obsolete; use the face `gnus-signature-face' for customizations instead."
529   :type 'face
530   :group 'gnus-article-highlight
531   :group 'gnus-article-signature)
532
533 (defface gnus-signature-face
534   '((t
535      (:italic t)))
536   "Face used for highlighting a signature in the article buffer."
537   :group 'gnus-article-highlight
538   :group 'gnus-article-signature)
539
540 (defface gnus-header-from-face
541   '((((class color)
542       (background dark))
543      (:foreground "spring green"))
544     (((class color)
545       (background light))
546      (:foreground "red3"))
547     (t
548      (:italic t)))
549   "Face used for displaying from headers."
550   :group 'gnus-article-headers
551   :group 'gnus-article-highlight)
552
553 (defface gnus-header-subject-face
554   '((((class color)
555       (background dark))
556      (:foreground "SeaGreen3"))
557     (((class color)
558       (background light))
559      (:foreground "red4"))
560     (t
561      (:bold t :italic t)))
562   "Face used for displaying subject headers."
563   :group 'gnus-article-headers
564   :group 'gnus-article-highlight)
565
566 (defface gnus-header-newsgroups-face
567   '((((class color)
568       (background dark))
569      (:foreground "yellow" :italic t))
570     (((class color)
571       (background light))
572      (:foreground "MidnightBlue" :italic t))
573     (t
574      (:italic t)))
575   "Face used for displaying newsgroups headers."
576   :group 'gnus-article-headers
577   :group 'gnus-article-highlight)
578
579 (defface gnus-header-name-face
580   '((((class color)
581       (background dark))
582      (:foreground "SeaGreen"))
583     (((class color)
584       (background light))
585      (:foreground "maroon"))
586     (t
587      (:bold t)))
588   "Face used for displaying header names."
589   :group 'gnus-article-headers
590   :group 'gnus-article-highlight)
591
592 (defface gnus-header-content-face
593   '((((class color)
594       (background dark))
595      (:foreground "forest green" :italic t))
596     (((class color)
597       (background light))
598      (:foreground "indianred4" :italic t))
599     (t
600      (:italic t)))  "Face used for displaying header content."
601   :group 'gnus-article-headers
602   :group 'gnus-article-highlight)
603
604 (defcustom gnus-header-face-alist
605   '(("From" nil gnus-header-from-face)
606     ("Subject" nil gnus-header-subject-face)
607     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
608     ("" gnus-header-name-face gnus-header-content-face))
609   "*Controls highlighting of article header.
610
611 An alist of the form (HEADER NAME CONTENT).
612
613 HEADER is a regular expression which should match the name of an
614 header header and NAME and CONTENT are either face names or nil.
615
616 The name of each header field will be displayed using the face
617 specified by the first element in the list where HEADER match the
618 header name and NAME is non-nil.  Similarly, the content will be
619 displayed by the first non-nil matching CONTENT face."
620   :group 'gnus-article-headers
621   :group 'gnus-article-highlight
622   :type '(repeat (list (regexp :tag "Header")
623                        (choice :tag "Name"
624                                (item :tag "skip" nil)
625                                (face :value default))
626                        (choice :tag "Content"
627                                (item :tag "skip" nil)
628                                (face :value default)))))
629
630 (defcustom gnus-article-decode-hook
631   '(article-decode-charset article-decode-encoded-words)
632   "*Hook run to decode charsets in articles."
633   :group 'gnus-article-headers
634   :type 'hook)
635
636 (defcustom gnus-display-mime-function 'gnus-display-mime
637   "Function to display MIME articles."
638   :group 'gnus-article-mime
639   :type 'function)
640
641 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
642   "Function used to decode headers.")
643
644 (defvar gnus-article-dumbquotes-map
645   '(("\200" "EUR")
646     ("\202" ",")
647     ("\203" "f")
648     ("\204" ",,")
649     ("\205" "...")
650     ("\213" "<")
651     ("\214" "OE")
652     ("\221" "`")
653     ("\222" "'")
654     ("\223" "``")
655     ("\224" "\"")
656     ("\225" "*")
657     ("\226" "-")
658     ("\227" "--")
659     ("\231" "(TM)")
660     ("\233" ">")
661     ("\234" "oe")
662     ("\264" "'"))
663   "Table for MS-to-Latin1 translation.")
664
665 (defcustom gnus-ignored-mime-types nil
666   "List of MIME types that should be ignored by Gnus."
667   :version "21.1"
668   :group 'gnus-article-mime
669   :type '(repeat regexp))
670
671 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
672   "List of MIME types that should not be given buttons when rendered inline."
673   :version "21.1"
674   :group 'gnus-article-mime
675   :type '(repeat regexp))
676
677 (defcustom gnus-article-mime-part-function nil
678   "Function called with a MIME handle as the argument.
679 This is meant for people who want to do something automatic based
680 on parts -- for instance, adding Vcard info to a database."
681   :group 'gnus-article-mime
682   :type 'function)
683
684 (defcustom gnus-mime-multipart-functions nil
685   "An alist of MIME types to functions to display them."
686   :version "21.1"
687   :group 'gnus-article-mime
688   :type 'alist)
689
690 (defcustom gnus-article-date-lapsed-new-header nil
691   "Whether the X-Sent and Date headers can coexist.
692 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
693 either replace the old \"Date:\" header (if this variable is nil), or
694 be added below it (otherwise)."
695   :version "21.1"
696   :group 'gnus-article-headers
697   :type 'boolean)
698
699 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
700   "Function called with a MIME handle as the argument.
701 This is meant for people who want to view first matched part.
702 For `undisplayed-alternative' (default), the first undisplayed
703 part or alternative part is used.  For `undisplayed', the first
704 undisplayed part is used.  For a function, the first part which
705 the function return `t' is used.  For `nil', the first part is
706 used."
707   :version "21.1"
708   :group 'gnus-article-mime
709   :type '(choice
710           (item :tag "first" :value nil)
711           (item :tag "undisplayed" :value undisplayed)
712           (item :tag "undisplayed or alternative"
713                 :value undisplayed-alternative)
714           (function)))
715
716 (defcustom gnus-mime-action-alist
717   '(("save to file" . gnus-mime-save-part)
718     ("save and strip" . gnus-mime-save-part-and-strip)
719     ("display as text" . gnus-mime-inline-part)
720     ("view the part" . gnus-mime-view-part)
721     ("pipe to command" . gnus-mime-pipe-part)
722     ("toggle display" . gnus-article-press-button)
723     ("toggle display" . gnus-article-view-part-as-charset)
724     ("view as type" . gnus-mime-view-part-as-type)
725     ("internalize type" . gnus-mime-internalize-part)
726     ("externalize type" . gnus-mime-externalize-part))
727   "An alist of actions that run on the MIME attachment."
728   :group 'gnus-article-mime
729   :type '(repeat (cons (string :tag "name")
730                        (function))))
731
732 (defcustom gnus-mime-action-alist
733   '(("save to file" . gnus-mime-save-part)
734     ("display as text" . gnus-mime-inline-part)
735     ("view the part" . gnus-mime-view-part)
736     ("pipe to command" . gnus-mime-pipe-part)
737     ("toggle display" . gnus-article-press-button)
738     ("view as type" . gnus-mime-view-part-as-type)
739     ("internalize type" . gnus-mime-internalize-part)
740     ("externalize type" . gnus-mime-externalize-part))
741   "An alist of actions that run on the MIME attachment."
742   :version "21.1"
743   :group 'gnus-article-mime
744   :type '(repeat (cons (string :tag "name")
745                        (function))))
746
747 ;;;
748 ;;; The treatment variables
749 ;;;
750
751 (defvar gnus-part-display-hook nil
752   "Hook called on parts that are to receive treatment.")
753
754 (defvar gnus-article-treat-custom
755   '(choice (const :tag "Off" nil)
756            (const :tag "On" t)
757            (const :tag "Header" head)
758            (const :tag "Last" last)
759            (integer :tag "Less")
760            (repeat :tag "Groups" regexp)
761            (sexp :tag "Predicate")))
762
763 (defvar gnus-article-treat-head-custom
764   '(choice (const :tag "Off" nil)
765            (const :tag "Header" head)))
766
767 (defvar gnus-article-treat-types '("text/plain")
768   "Parts to treat.")
769
770 (defvar gnus-inhibit-treatment nil
771   "Whether to inhibit treatment.")
772
773 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
774   "Highlight the signature.
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777   :group 'gnus-article-treat
778   :type gnus-article-treat-custom)
779 (put 'gnus-treat-highlight-signature 'highlight t)
780
781 (defcustom gnus-treat-buttonize 100000
782   "Add buttons.
783 Valid values are nil, t, `head', `last', an integer or a predicate.
784 See the manual for details."
785   :group 'gnus-article-treat
786   :type gnus-article-treat-custom)
787 (put 'gnus-treat-buttonize 'highlight t)
788
789 (defcustom gnus-treat-buttonize-head 'head
790   "Add buttons to the head.
791 Valid values are nil, t, `head', `last', an integer or a predicate.
792 See the manual for details."
793   :group 'gnus-article-treat
794   :type gnus-article-treat-head-custom)
795 (put 'gnus-treat-buttonize-head 'highlight t)
796
797 (defcustom gnus-treat-emphasize
798   (and (or window-system
799            (featurep 'xemacs)
800            (>= (string-to-number emacs-version) 21))
801        50000)
802   "Emphasize text.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805   :group 'gnus-article-treat
806   :type gnus-article-treat-custom)
807 (put 'gnus-treat-emphasize 'highlight t)
808
809 (defcustom gnus-treat-strip-cr nil
810   "Remove carriage returns.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813   :group 'gnus-article-treat
814   :type gnus-article-treat-custom)
815
816 (defcustom gnus-treat-leading-whitespace nil
817   "Remove leading whitespace in headers.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820   :group 'gnus-article-treat
821   :type gnus-article-treat-custom)
822
823 (defcustom gnus-treat-hide-headers 'head
824   "Hide headers.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827   :group 'gnus-article-treat
828   :type gnus-article-treat-head-custom)
829
830 (defcustom gnus-treat-hide-boring-headers nil
831   "Hide boring headers.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834   :group 'gnus-article-treat
835   :type gnus-article-treat-head-custom)
836
837 (defcustom gnus-treat-hide-signature nil
838   "Hide the signature.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841   :group 'gnus-article-treat
842   :type gnus-article-treat-custom)
843
844 (defcustom gnus-treat-fill-article nil
845   "Fill the article.
846 Valid values are nil, t, `head', `last', an integer or a predicate.
847 See the manual for details."
848   :group 'gnus-article-treat
849   :type gnus-article-treat-custom)
850
851 (defcustom gnus-treat-hide-citation nil
852   "Hide cited text.
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855   :group 'gnus-article-treat
856   :type gnus-article-treat-custom)
857
858 (defcustom gnus-treat-hide-citation-maybe nil
859   "Hide cited text.
860 Valid values are nil, t, `head', `last', an integer or a predicate.
861 See the manual for details."
862   :group 'gnus-article-treat
863   :type gnus-article-treat-custom)
864
865 (defcustom gnus-treat-hide-citation-maybe nil
866   "Hide cited text.
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869   :group 'gnus-article-treat
870   :type gnus-article-treat-custom)
871
872 (defcustom gnus-treat-strip-list-identifiers 'head
873   "Strip list identifiers from `gnus-list-identifiers`.
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
876   :version "21.1"
877   :group 'gnus-article-treat
878   :type gnus-article-treat-custom)
879
880 (defcustom gnus-treat-strip-pgp t
881   "Strip PGP signatures.
882 Valid values are nil, t, `head', `last', an integer or a predicate.
883 See the manual for details."
884   :group 'gnus-article-treat
885   :type gnus-article-treat-custom)
886
887 (defcustom gnus-treat-strip-pem nil
888   "Strip PEM signatures.
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891   :group 'gnus-article-treat
892   :type gnus-article-treat-custom)
893
894 (defcustom gnus-treat-strip-banner t
895   "Strip banners from articles.
896 The banner to be stripped is specified in the `banner' group parameter.
897 Valid values are nil, t, `head', `last', an integer or a predicate.
898 See the manual for details."
899   :group 'gnus-article-treat
900   :type gnus-article-treat-custom)
901
902 (defcustom gnus-treat-highlight-headers 'head
903   "Highlight the headers.
904 Valid values are nil, t, `head', `last', an integer or a predicate.
905 See the manual for details."
906   :group 'gnus-article-treat
907   :type gnus-article-treat-head-custom)
908 (put 'gnus-treat-highlight-headers 'highlight t)
909
910 (defcustom gnus-treat-highlight-citation t
911   "Highlight cited text.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
914   :group 'gnus-article-treat
915   :type gnus-article-treat-custom)
916 (put 'gnus-treat-highlight-citation 'highlight t)
917
918 (defcustom gnus-treat-date-ut nil
919   "Display the Date in UT (GMT).
920 Valid values are nil, t, `head', `last', an integer or a predicate.
921 See the manual for details."
922   :group 'gnus-article-treat
923   :type gnus-article-treat-head-custom)
924
925 (defcustom gnus-treat-date-local nil
926   "Display the Date in the local timezone.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See the manual for details."
929   :group 'gnus-article-treat
930   :type gnus-article-treat-head-custom)
931
932 (defcustom gnus-treat-date-english nil
933   "Display the Date in a format that can be read aloud in English.
934 Valid values are nil, t, `head', `last', an integer or a predicate.
935 See the manual for details."
936   :group 'gnus-article-treat
937   :type gnus-article-treat-head-custom)
938
939 (defcustom gnus-treat-date-lapsed nil
940   "Display the Date header in a way that says how much time has elapsed.
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See the manual for details."
943   :group 'gnus-article-treat
944   :type gnus-article-treat-head-custom)
945
946 (defcustom gnus-treat-date-original nil
947   "Display the date in the original timezone.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See the manual for details."
950   :group 'gnus-article-treat
951   :type gnus-article-treat-head-custom)
952
953 (defcustom gnus-treat-date-iso8601 nil
954   "Display the date in the ISO8601 format.
955 Valid values are nil, t, `head', `last', an integer or a predicate.
956 See the manual for details."
957   :version "21.1"
958   :group 'gnus-article-treat
959   :type gnus-article-treat-head-custom)
960
961 (defcustom gnus-treat-date-user-defined nil
962   "Display the date in a user-defined format.
963 The format is defined by the `gnus-article-time-format' variable.
964 Valid values are nil, t, `head', `last', an integer or a predicate.
965 See the manual for details."
966   :group 'gnus-article-treat
967   :type gnus-article-treat-head-custom)
968
969 (defcustom gnus-treat-strip-headers-in-body t
970   "Strip the X-No-Archive header line from the beginning of the body.
971 Valid values are nil, t, `head', `last', an integer or a predicate.
972 See the manual for details."
973   :version "21.1"
974   :group 'gnus-article-treat
975   :type gnus-article-treat-custom)
976
977 (defcustom gnus-treat-strip-trailing-blank-lines nil
978   "Strip trailing blank lines.
979 Valid values are nil, t, `head', `last', an integer or a predicate.
980 See the manual for details."
981   :group 'gnus-article-treat
982   :type gnus-article-treat-custom)
983
984 (defcustom gnus-treat-strip-leading-blank-lines nil
985   "Strip leading blank lines.
986 Valid values are nil, t, `head', `last', an integer or a predicate.
987 See the manual for details."
988   :group 'gnus-article-treat
989   :type gnus-article-treat-custom)
990
991 (defcustom gnus-treat-strip-multiple-blank-lines nil
992   "Strip multiple blank lines.
993 Valid values are nil, t, `head', `last', an integer or a predicate.
994 See the manual for details."
995   :group 'gnus-article-treat
996   :type gnus-article-treat-custom)
997
998 (defcustom gnus-treat-overstrike t
999   "Treat overstrike highlighting.
1000 Valid values are nil, t, `head', `last', an integer or a predicate.
1001 See the manual for details."
1002   :group 'gnus-article-treat
1003   :type gnus-article-treat-custom)
1004 (put 'gnus-treat-overstrike 'highlight t)
1005
1006 (defcustom gnus-treat-display-xface
1007   (and (or (and (fboundp 'image-type-available-p)
1008                 (image-type-available-p 'xbm)
1009                 (string-match "^0x" (shell-command-to-string "uncompface")))
1010            (and (featurep 'xemacs) (featurep 'xface)))
1011        'head)
1012   "Display X-Face headers.
1013 Valid values are nil, t, `head', `last', an integer or a predicate.
1014 See the manual for details."
1015   :group 'gnus-article-treat
1016   :version "21.1"
1017   :type gnus-article-treat-head-custom)
1018 (put 'gnus-treat-display-xface 'highlight t)
1019
1020 (defcustom gnus-treat-display-smileys
1021   (if (or (and (featurep 'xemacs)
1022                (featurep 'xpm))
1023           (and (fboundp 'image-type-available-p)
1024                (image-type-available-p 'pbm)))
1025       t nil)
1026   "Display smileys.
1027 Valid values are nil, t, `head', `last', an integer or a predicate.
1028 See the manual for details."
1029   :group 'gnus-article-treat
1030   :version "21.1"
1031   :type gnus-article-treat-custom)
1032 (put 'gnus-treat-display-smileys 'highlight t)
1033
1034 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1035   "Display picons.
1036 Valid values are nil, t, `head', `last', an integer or a predicate.
1037 See the manual for details."
1038   :group 'gnus-article-treat
1039   :type gnus-article-treat-head-custom)
1040 (put 'gnus-treat-display-picons 'highlight t)
1041
1042 (defcustom gnus-treat-capitalize-sentences nil
1043   "Capitalize sentence-starting words.
1044 Valid values are nil, t, `head', `last', an integer or a predicate.
1045 See the manual for details."
1046   :version "21.1"
1047   :group 'gnus-article-treat
1048   :type gnus-article-treat-custom)
1049
1050 (defcustom gnus-treat-fill-long-lines nil
1051   "Fill long lines.
1052 Valid values are nil, t, `head', `last', an integer or a predicate.
1053 See the manual for details."
1054   :group 'gnus-article-treat
1055   :type gnus-article-treat-custom)
1056
1057 (defcustom gnus-treat-play-sounds nil
1058   "Play sounds.
1059 Valid values are nil, t, `head', `last', an integer or a predicate.
1060 See the manual for details."
1061   :version "21.1"
1062   :group 'gnus-article-treat
1063   :type gnus-article-treat-custom)
1064
1065 (defcustom gnus-treat-translate nil
1066   "Translate articles from one language to another.
1067 Valid values are nil, t, `head', `last', an integer or a predicate.
1068 See the manual for details."
1069   :version "21.1"
1070   :group 'gnus-article-treat
1071   :type gnus-article-treat-custom)
1072
1073 (defcustom gnus-treat-x-pgp-sig nil
1074   "Verify X-PGP-Sig.
1075 To automatically treat X-PGP-Sig, set it to head.
1076 Valid values are nil, t, `head', `last', an integer or a predicate.
1077 See the manual for details."
1078   :group 'gnus-article-treat
1079   :group 'mime-security
1080   :type gnus-article-treat-custom)
1081
1082 (defvar gnus-article-encrypt-protocol-alist
1083   '(("PGP" . mml2015-self-encrypt)))
1084
1085 ;; Set to nil if more than one protocol added to
1086 ;; gnus-article-encrypt-protocol-alist.
1087 (defcustom gnus-article-encrypt-protocol "PGP"
1088   "The protocol used for encrypt articles.
1089 It is a string, such as \"PGP\". If nil, ask user."
1090   :type 'string
1091   :group 'mime-security)
1092
1093 ;;; Internal variables
1094
1095 (defvar gnus-english-month-names
1096   '("January" "February" "March" "April" "May" "June" "July" "August"
1097     "September" "October" "November" "December"))
1098
1099 (defvar article-goto-body-goes-to-point-min-p nil)
1100 (defvar gnus-article-wash-types nil)
1101 (defvar gnus-article-emphasis-alist nil)
1102
1103 (defvar gnus-article-mime-handle-alist-1 nil)
1104 (defvar gnus-treatment-function-alist
1105   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1106     (gnus-treat-strip-banner gnus-article-strip-banner)
1107     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1108     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1109     (gnus-treat-buttonize gnus-article-add-buttons)
1110     (gnus-treat-fill-article gnus-article-fill-cited-article)
1111     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1112     (gnus-treat-strip-cr gnus-article-remove-cr)
1113     (gnus-treat-emphasize gnus-article-emphasize)
1114     (gnus-treat-display-xface gnus-article-display-x-face)
1115     (gnus-treat-date-ut gnus-article-date-ut)
1116     (gnus-treat-date-local gnus-article-date-local)
1117     (gnus-treat-date-english gnus-article-date-english)
1118     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1119     (gnus-treat-date-original gnus-article-date-original)
1120     (gnus-treat-date-user-defined gnus-article-date-user)
1121     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1122     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1123     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1124     (gnus-treat-hide-signature gnus-article-hide-signature)
1125     (gnus-treat-hide-citation gnus-article-hide-citation)
1126     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1127     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1128     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1129     (gnus-treat-strip-pgp gnus-article-hide-pgp)
1130     (gnus-treat-strip-pem gnus-article-hide-pem)
1131     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1132     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1133     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1134     (gnus-treat-strip-trailing-blank-lines
1135      gnus-article-remove-trailing-blank-lines)
1136     (gnus-treat-strip-leading-blank-lines
1137      gnus-article-strip-leading-blank-lines)
1138     (gnus-treat-strip-multiple-blank-lines
1139      gnus-article-strip-multiple-blank-lines)
1140     (gnus-treat-overstrike gnus-article-treat-overstrike)
1141     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1142     (gnus-treat-display-smileys gnus-smiley-display)
1143     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1144     (gnus-treat-display-picons gnus-article-display-picons)
1145     (gnus-treat-play-sounds gnus-earcon-display)))
1146
1147 (defvar gnus-article-mime-handle-alist nil)
1148 (defvar article-lapsed-timer nil)
1149 (defvar gnus-article-current-summary nil)
1150
1151 (defvar gnus-article-mode-syntax-table
1152   (let ((table (copy-syntax-table text-mode-syntax-table)))
1153     ;; This causes the citation match run O(2^n).
1154     ;; (modify-syntax-entry ?- "w" table)
1155     (modify-syntax-entry ?> ")" table)
1156     (modify-syntax-entry ?< "(" table)
1157     table)
1158   "Syntax table used in article mode buffers.
1159 Initialized from `text-mode-syntax-table.")
1160
1161 (defvar gnus-save-article-buffer nil)
1162
1163 (defvar gnus-article-mode-line-format-alist
1164   (nconc '((?w (gnus-article-wash-status) ?s)
1165            (?m (gnus-article-mime-part-status) ?s))
1166          gnus-summary-mode-line-format-alist))
1167
1168 (defvar gnus-number-of-articles-to-be-saved nil)
1169
1170 (defvar gnus-inhibit-hiding nil)
1171
1172 (defsubst gnus-article-hide-text (b e props)
1173   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1174   (gnus-add-text-properties-when 'article-type nil b e props)
1175   (when (memq 'intangible props)
1176     (put-text-property
1177      (max (1- b) (point-min))
1178      b 'intangible (cddr (memq 'intangible props)))))
1179
1180 (defsubst gnus-article-unhide-text (b e)
1181   "Remove hidden text properties from region between B and E."
1182   (remove-text-properties b e gnus-hidden-properties)
1183   (when (memq 'intangible gnus-hidden-properties)
1184     (put-text-property (max (1- b) (point-min))
1185                        b 'intangible nil)))
1186
1187 (defun gnus-article-hide-text-type (b e type)
1188   "Hide text of TYPE between B and E."
1189   (push type gnus-article-wash-types)
1190   (gnus-article-hide-text
1191    b e (cons 'article-type (cons type gnus-hidden-properties))))
1192
1193 (defun gnus-article-unhide-text-type (b e type)
1194   "Unhide text of TYPE between B and E."
1195   (setq gnus-article-wash-types
1196         (delq type gnus-article-wash-types))
1197   (remove-text-properties
1198    b e (cons 'article-type (cons type gnus-hidden-properties)))
1199   (when (memq 'intangible gnus-hidden-properties)
1200     (put-text-property (max (1- b) (point-min))
1201                        b 'intangible nil)))
1202
1203 (defun gnus-article-hide-text-of-type (type)
1204   "Hide text of TYPE in the current buffer."
1205   (save-excursion
1206     (let ((b (point-min))
1207           (e (point-max)))
1208       (while (setq b (text-property-any b e 'article-type type))
1209         (add-text-properties b (incf b) gnus-hidden-properties)))))
1210
1211 (defun gnus-article-delete-text-of-type (type)
1212   "Delete text of TYPE in the current buffer."
1213   (save-excursion
1214     (let ((b (point-min)))
1215       (while (setq b (text-property-any b (point-max) 'article-type type))
1216         (delete-region
1217          b (or (text-property-not-all b (point-max) 'article-type type)
1218                (point-max)))))))
1219
1220 (defun gnus-article-delete-invisible-text ()
1221   "Delete all invisible text in the current buffer."
1222   (save-excursion
1223     (let ((b (point-min)))
1224       (while (setq b (text-property-any b (point-max) 'invisible t))
1225         (delete-region
1226          b (or (text-property-not-all b (point-max) 'invisible t)
1227                (point-max)))))))
1228
1229 (defun gnus-article-text-type-exists-p (type)
1230   "Say whether any text of type TYPE exists in the buffer."
1231   (text-property-any (point-min) (point-max) 'article-type type))
1232
1233 (defsubst gnus-article-header-rank ()
1234   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1235   (let ((list gnus-sorted-header-list)
1236         (i 0))
1237     (while list
1238       (when (looking-at (car list))
1239         (setq list nil))
1240       (setq list (cdr list))
1241       (incf i))
1242     i))
1243
1244 (defun article-hide-headers (&optional arg delete)
1245   "Hide unwanted headers and possibly sort them as well."
1246   (interactive)
1247   ;; This function might be inhibited.
1248   (unless gnus-inhibit-hiding
1249     (save-excursion
1250       (save-restriction
1251         (let ((buffer-read-only nil)
1252               (case-fold-search t)
1253               (max (1+ (length gnus-sorted-header-list)))
1254               (ignored (when (not gnus-visible-headers)
1255                          (cond ((stringp gnus-ignored-headers)
1256                                 gnus-ignored-headers)
1257                                ((listp gnus-ignored-headers)
1258                                 (mapconcat 'identity gnus-ignored-headers
1259                                            "\\|")))))
1260               (visible
1261                (cond ((stringp gnus-visible-headers)
1262                       gnus-visible-headers)
1263                      ((and gnus-visible-headers
1264                            (listp gnus-visible-headers))
1265                       (mapconcat 'identity gnus-visible-headers "\\|"))))
1266               (inhibit-point-motion-hooks t)
1267               beg)
1268           ;; First we narrow to just the headers.
1269           (article-narrow-to-head)
1270           ;; Hide any "From " lines at the beginning of (mail) articles.
1271           (while (looking-at "From ")
1272             (forward-line 1))
1273           (unless (bobp)
1274             (delete-region (point-min) (point)))
1275           ;; Then treat the rest of the header lines.
1276           ;; Then we use the two regular expressions
1277           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1278           ;; select which header lines is to remain visible in the
1279           ;; article buffer.
1280           (while (re-search-forward "^[^ \t:]*:" nil t)
1281             (beginning-of-line)
1282             ;; Mark the rank of the header.
1283             (put-text-property
1284              (point) (1+ (point)) 'message-rank
1285              (if (or (and visible (looking-at visible))
1286                      (and ignored
1287                           (not (looking-at ignored))))
1288                  (gnus-article-header-rank)
1289                (+ 2 max)))
1290             (forward-line 1))
1291           (message-sort-headers-1)
1292           (when (setq beg (text-property-any
1293                            (point-min) (point-max) 'message-rank (+ 2 max)))
1294             ;; We delete the unwanted headers.
1295             (push 'headers gnus-article-wash-types)
1296             (add-text-properties (point-min) (+ 5 (point-min))
1297                                  '(article-type headers dummy-invisible t))
1298             (delete-region beg (point-max))))))))
1299
1300 (defun article-hide-boring-headers (&optional arg)
1301   "Toggle hiding of headers that aren't very interesting.
1302 If given a negative prefix, always show; if given a positive prefix,
1303 always hide."
1304   (interactive (gnus-article-hidden-arg))
1305   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1306              (not gnus-show-all-headers))
1307     (save-excursion
1308       (save-restriction
1309         (let ((buffer-read-only nil)
1310               (list gnus-boring-article-headers)
1311               (inhibit-point-motion-hooks t)
1312               elem)
1313           (article-narrow-to-head)
1314           (while list
1315             (setq elem (pop list))
1316             (goto-char (point-min))
1317             (cond
1318              ;; Hide empty headers.
1319              ((eq elem 'empty)
1320               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1321                 (forward-line -1)
1322                 (gnus-article-hide-text-type
1323                  (progn (beginning-of-line) (point))
1324                  (progn
1325                    (end-of-line)
1326                    (if (re-search-forward "^[^ \t]" nil t)
1327                        (match-beginning 0)
1328                      (point-max)))
1329                  'boring-headers)))
1330              ;; Hide boring Newsgroups header.
1331              ((eq elem 'newsgroups)
1332               (when (gnus-string-equal
1333                      (gnus-fetch-field "newsgroups")
1334                      (gnus-group-real-name
1335                       (if (boundp 'gnus-newsgroup-name)
1336                           gnus-newsgroup-name
1337                         "")))
1338                 (gnus-article-hide-header "newsgroups")))
1339              ((eq elem 'to-address)
1340               (let ((to (message-fetch-field "to"))
1341                     (to-address
1342                      (gnus-parameter-to-address
1343                       (if (boundp 'gnus-newsgroup-name)
1344                           gnus-newsgroup-name ""))))
1345                 (when (and to to-address
1346                            (ignore-errors
1347                              (gnus-string-equal
1348                               ;; only one address in To
1349                               (nth 1 (mail-extract-address-components to))
1350                               to-address)))
1351                   (gnus-article-hide-header "to"))))
1352              ((eq elem 'followup-to)
1353               (when (gnus-string-equal
1354                      (message-fetch-field "followup-to")
1355                      (message-fetch-field "newsgroups"))
1356                 (gnus-article-hide-header "followup-to")))
1357              ((eq elem 'reply-to)
1358               (let ((from (message-fetch-field "from"))
1359                     (reply-to (message-fetch-field "reply-to")))
1360                 (when (and
1361                        from reply-to
1362                        (ignore-errors
1363                          (gnus-string-equal
1364                           (nth 1 (mail-extract-address-components from))
1365                           (nth 1 (mail-extract-address-components reply-to)))))
1366                   (gnus-article-hide-header "reply-to"))))
1367              ((eq elem 'date)
1368               (let ((date (message-fetch-field "date")))
1369                 (when (and date
1370                            (< (days-between (current-time-string) date)
1371                               4))
1372                   (gnus-article-hide-header "date"))))
1373              ((eq elem 'long-to)
1374               (let ((to (message-fetch-field "to"))
1375                     (cc (message-fetch-field "cc")))
1376                 (when (> (length to) 1024)
1377                   (gnus-article-hide-header "to"))
1378                 (when (> (length cc) 1024)
1379                   (gnus-article-hide-header "cc"))))
1380              ((eq elem 'many-to)
1381               (let ((to-count 0)
1382                     (cc-count 0))
1383                 (goto-char (point-min))
1384                 (while (re-search-forward "^to:" nil t)
1385                   (setq to-count (1+ to-count)))
1386                 (when (> to-count 1)
1387                   (while (> to-count 0)
1388                     (goto-char (point-min))
1389                     (save-restriction
1390                       (re-search-forward "^to:" nil nil to-count)
1391                       (forward-line -1)
1392                       (narrow-to-region (point) (point-max))
1393                       (gnus-article-hide-header "to"))
1394                     (setq to-count (1- to-count))))
1395                 (goto-char (point-min))
1396                 (while (re-search-forward "^cc:" nil t)
1397                   (setq cc-count (1+ cc-count)))
1398                 (when (> cc-count 1)
1399                   (while (> cc-count 0)
1400                     (goto-char (point-min))
1401                     (save-restriction
1402                       (re-search-forward "^cc:" nil nil cc-count)
1403                       (forward-line -1)
1404                       (narrow-to-region (point) (point-max))
1405                       (gnus-article-hide-header "cc"))
1406                     (setq cc-count (1- cc-count)))))))))))))
1407
1408 (defun gnus-article-hide-header (header)
1409   (save-excursion
1410     (goto-char (point-min))
1411     (when (re-search-forward (concat "^" header ":") nil t)
1412       (gnus-article-hide-text-type
1413        (progn (beginning-of-line) (point))
1414        (progn
1415          (end-of-line)
1416          (if (re-search-forward "^[^ \t]" nil t)
1417              (match-beginning 0)
1418            (point-max)))
1419        'boring-headers))))
1420
1421 (defvar gnus-article-normalized-header-length 40
1422   "Length of normalized headers.")
1423
1424 (defun article-normalize-headers ()
1425   "Make all header lines 40 characters long."
1426   (interactive)
1427   (let ((buffer-read-only nil)
1428         column)
1429     (save-excursion
1430       (save-restriction
1431         (article-narrow-to-head)
1432         (while (not (eobp))
1433           (cond
1434            ((< (setq column (- (gnus-point-at-eol) (point)))
1435                gnus-article-normalized-header-length)
1436             (end-of-line)
1437             (insert (make-string
1438                      (- gnus-article-normalized-header-length column)
1439                      ? )))
1440            ((> column gnus-article-normalized-header-length)
1441             (gnus-put-text-property
1442              (progn
1443                (forward-char gnus-article-normalized-header-length)
1444                (point))
1445              (gnus-point-at-eol)
1446              'invisible t))
1447            (t
1448             ;; Do nothing.
1449             ))
1450           (forward-line 1))))))
1451
1452 (defun article-treat-dumbquotes ()
1453   "Translate M****s*** sm*rtq**t*s into proper text.
1454 Note that this function guesses whether a character is a sm*rtq**t* or
1455 not, so it should only be used interactively.
1456
1457 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1458 in an attempt to provide more quoting characters.  If you see
1459 something like \\222 or \\264 where you're expecting some kind of
1460 apostrophe or quotation mark, then try this wash."
1461   (interactive)
1462   (article-translate-strings gnus-article-dumbquotes-map))
1463
1464 (defun article-translate-characters (from to)
1465   "Translate all characters in the body of the article according to FROM and TO.
1466 FROM is a string of characters to translate from; to is a string of
1467 characters to translate to."
1468   (save-excursion
1469     (when (article-goto-body)
1470       (let ((buffer-read-only nil)
1471             (x (make-string 225 ?x))
1472             (i -1))
1473         (while (< (incf i) (length x))
1474           (aset x i i))
1475         (setq i 0)
1476         (while (< i (length from))
1477           (aset x (aref from i) (aref to i))
1478           (incf i))
1479         (translate-region (point) (point-max) x)))))
1480
1481 (defun article-translate-strings (map)
1482   "Translate all string in the body of the article according to MAP.
1483 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1484   (save-excursion
1485     (when (article-goto-body)
1486       (let ((buffer-read-only nil)
1487             elem)
1488         (while (setq elem (pop map))
1489           (save-excursion
1490             (while (search-forward (car elem) nil t)
1491               (replace-match (cadr elem)))))))))
1492
1493 (defun article-treat-overstrike ()
1494   "Translate overstrikes into bold text."
1495   (interactive)
1496   (save-excursion
1497     (when (article-goto-body)
1498       (let ((buffer-read-only nil))
1499         (while (search-forward "\b" nil t)
1500           (let ((next (char-after))
1501                 (previous (char-after (- (point) 2))))
1502             ;; We do the boldification/underlining by hiding the
1503             ;; overstrikes and putting the proper text property
1504             ;; on the letters.
1505             (cond
1506              ((eq next previous)
1507               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1508               (put-text-property (point) (1+ (point)) 'face 'bold))
1509              ((eq next ?_)
1510               (gnus-article-hide-text-type
1511                (1- (point)) (1+ (point)) 'overstrike)
1512               (put-text-property
1513                (- (point) 2) (1- (point)) 'face 'underline))
1514              ((eq previous ?_)
1515               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1516               (put-text-property
1517                (point) (1+ (point)) 'face 'underline)))))))))
1518
1519 (defun article-fill-long-lines ()
1520   "Fill lines that are wider than the window width."
1521   (interactive)
1522   (save-excursion
1523     (let ((buffer-read-only nil)
1524           (width (window-width (get-buffer-window (current-buffer)))))
1525       (save-restriction
1526         (article-goto-body)
1527         (let ((adaptive-fill-mode nil)) ;Why?  -sm
1528           (while (not (eobp))
1529             (end-of-line)
1530             (when (>= (current-column) (min fill-column width))
1531               (narrow-to-region (point) (gnus-point-at-bol))
1532               (fill-paragraph nil)
1533               (goto-char (point-max))
1534               (widen))
1535             (forward-line 1)))))))
1536
1537 (defun article-capitalize-sentences ()
1538   "Capitalize the first word in each sentence."
1539   (interactive)
1540   (save-excursion
1541     (let ((buffer-read-only nil)
1542           (paragraph-start "^[\n\^L]"))
1543       (article-goto-body)
1544       (while (not (eobp))
1545         (capitalize-word 1)
1546         (forward-sentence)))))
1547
1548 (defun article-remove-cr ()
1549   "Remove trailing CRs and then translate remaining CRs into LFs."
1550   (interactive)
1551   (save-excursion
1552     (let ((buffer-read-only nil))
1553       (goto-char (point-min))
1554       (while (re-search-forward "\r+$" nil t)
1555         (replace-match "" t t))
1556       (goto-char (point-min))
1557       (while (search-forward "\r" nil t)
1558         (replace-match "\n" t t)))))
1559
1560 (defun article-remove-trailing-blank-lines ()
1561   "Remove all trailing blank lines from the article."
1562   (interactive)
1563   (save-excursion
1564     (let ((buffer-read-only nil))
1565       (goto-char (point-max))
1566       (delete-region
1567        (point)
1568        (progn
1569          (while (and (not (bobp))
1570                      (looking-at "^[ \t]*$")
1571                      (not (gnus-annotation-in-region-p
1572                            (point) (gnus-point-at-eol))))
1573            (forward-line -1))
1574          (forward-line 1)
1575          (point))))))
1576
1577 (defun article-display-x-face (&optional force)
1578   "Look for an X-Face header and display it if present."
1579   (interactive (list 'force))
1580   (save-excursion
1581     ;; Delete the old process, if any.
1582     (when (process-status "article-x-face")
1583       (delete-process "article-x-face"))
1584     (let ((inhibit-point-motion-hooks t)
1585           x-faces
1586           (case-fold-search t)
1587           from last)
1588       (save-restriction
1589         (article-narrow-to-head)
1590         (when (and buffer-read-only ;; When type `W f'
1591                    (progn
1592                      (goto-char (point-min))
1593                      (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1594                    (gnus-buffer-live-p gnus-original-article-buffer))
1595           (with-current-buffer gnus-original-article-buffer
1596             (save-restriction
1597               (article-narrow-to-head)
1598               (while (re-search-forward "^X-Face:" nil t)
1599                 (setq x-faces
1600                       (concat
1601                        (or x-faces "")
1602                        (buffer-substring
1603                         (match-beginning 0)
1604                         (1- (re-search-forward
1605                              "^\\($\\|[^ \t]\\)" nil t))))))))
1606           (if x-faces
1607               (let (point start bface eface buffer-read-only)
1608                 (goto-char (point-max))
1609                 (forward-line -1)
1610                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1611                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1612                 (goto-char (point-max))
1613                 (setq point (point))
1614                 (insert x-faces)
1615                 (goto-char point)
1616                 (while (looking-at "\\([^:]+\\): *")
1617                   (put-text-property (match-beginning 1) (1+ (match-end 1))
1618                                      'face bface)
1619                   (setq start (match-end 0))
1620                   (forward-line 1)
1621                   (while (looking-at "[\t ]")
1622                     (forward-line 1))
1623                   (put-text-property start (point)
1624                                      'face eface)))))
1625         (goto-char (point-min))
1626         (setq from (message-fetch-field "from"))
1627         (goto-char (point-min))
1628         (while (and gnus-article-x-face-command
1629                     (not last)
1630                     (or force
1631                         ;; Check whether this face is censored.
1632                         (not gnus-article-x-face-too-ugly)
1633                         (and gnus-article-x-face-too-ugly from
1634                              (not (string-match gnus-article-x-face-too-ugly
1635                                                 from))))
1636                     ;; Has to be present.
1637                     (re-search-forward "^X-Face:[\t ]*" nil t))
1638           ;; This used to try to do multiple faces (`while' instead of
1639           ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1640           ;; work (b) it can crash some versions of Emacs (c) are
1641           ;; multiple faces really something to encourage?
1642           (when (stringp gnus-article-x-face-command)
1643             (setq last t))
1644           ;; We now have the area of the buffer where the X-Face is stored.
1645           (save-excursion
1646             (let ((beg (point))
1647                   (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1648               ;; We display the face.
1649               (if (symbolp gnus-article-x-face-command)
1650                   ;; The command is a lisp function, so we call it.
1651                   (if (gnus-functionp gnus-article-x-face-command)
1652                       (funcall gnus-article-x-face-command beg end)
1653                     (error "%s is not a function" gnus-article-x-face-command))
1654                 ;; The command is a string, so we interpret the command
1655                 ;; as a, well, command, and fork it off.
1656                 (let ((process-connection-type nil))
1657                   (process-kill-without-query
1658                    (start-process
1659                     "article-x-face" nil shell-file-name shell-command-switch
1660                     gnus-article-x-face-command))
1661                   (process-send-region "article-x-face" beg end)
1662                   (process-send-eof "article-x-face"))))))))))
1663
1664 (defun article-decode-mime-words ()
1665   "Decode all MIME-encoded words in the article."
1666   (interactive)
1667   (save-excursion
1668     (set-buffer gnus-article-buffer)
1669     (let ((inhibit-point-motion-hooks t)
1670           buffer-read-only
1671           (mail-parse-charset gnus-newsgroup-charset)
1672           (mail-parse-ignored-charsets
1673            (save-excursion (set-buffer gnus-summary-buffer)
1674                            gnus-newsgroup-ignored-charsets)))
1675       (mail-decode-encoded-word-region (point-min) (point-max)))))
1676
1677 (defun article-decode-charset (&optional prompt)
1678   "Decode charset-encoded text in the article.
1679 If PROMPT (the prefix), prompt for a coding system to use."
1680   (interactive "P")
1681   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1682         buffer-read-only
1683         (mail-parse-charset gnus-newsgroup-charset)
1684         (mail-parse-ignored-charsets
1685          (save-excursion (condition-case nil
1686                              (set-buffer gnus-summary-buffer)
1687                            (error))
1688                          gnus-newsgroup-ignored-charsets))
1689         ct cte ctl charset format)
1690   (save-excursion
1691     (save-restriction
1692       (article-narrow-to-head)
1693       (setq ct (message-fetch-field "Content-Type" t)
1694             cte (message-fetch-field "Content-Transfer-Encoding" t)
1695             ctl (and ct (ignore-errors
1696                           (mail-header-parse-content-type ct)))
1697             charset (cond
1698                      (prompt
1699                       (mm-read-coding-system "Charset to decode: "))
1700                      (ctl
1701                       (mail-content-type-get ctl 'charset)))
1702             format (and ctl (mail-content-type-get ctl 'format)))
1703       (when cte
1704         (setq cte (mail-header-strip cte)))
1705       (if (and ctl (not (string-match "/" (car ctl))))
1706           (setq ctl nil))
1707       (goto-char (point-max)))
1708     (forward-line 1)
1709     (save-restriction
1710       (narrow-to-region (point) (point-max))
1711       (when (and (eq mail-parse-charset 'gnus-decoded)
1712                  (eq (mm-body-7-or-8) '8bit))
1713         ;; The text code could have been decoded.
1714         (setq charset mail-parse-charset))
1715       (when (and (or (not ctl)
1716                      (equal (car ctl) "text/plain"))
1717                  (not format)) ;; article with format will decode later.
1718         (mm-decode-body
1719          charset (and cte (intern (downcase
1720                                    (gnus-strip-whitespace cte))))
1721          (car ctl)))))))
1722
1723 (defun article-decode-encoded-words ()
1724   "Remove encoded-word encoding from headers."
1725   (let ((inhibit-point-motion-hooks t)
1726         (mail-parse-charset gnus-newsgroup-charset)
1727         (mail-parse-ignored-charsets
1728          (save-excursion (condition-case nil
1729                              (set-buffer gnus-summary-buffer)
1730                            (error))
1731                          gnus-newsgroup-ignored-charsets))
1732         buffer-read-only)
1733     (save-restriction
1734       (article-narrow-to-head)
1735       (funcall gnus-decode-header-function (point-min) (point-max)))))
1736
1737 (defun article-de-quoted-unreadable (&optional force read-charset)
1738   "Translate a quoted-printable-encoded article.
1739 If FORCE, decode the article whether it is marked as quoted-printable
1740 or not.
1741 If READ-CHARSET, ask for a coding system."
1742   (interactive (list 'force current-prefix-arg))
1743   (save-excursion
1744     (let ((buffer-read-only nil) type charset)
1745       (if (gnus-buffer-live-p gnus-original-article-buffer)
1746           (with-current-buffer gnus-original-article-buffer
1747             (setq type
1748                   (gnus-fetch-field "content-transfer-encoding"))
1749             (let* ((ct (gnus-fetch-field "content-type"))
1750                    (ctl (and ct
1751                              (ignore-errors
1752                                (mail-header-parse-content-type ct)))))
1753               (setq charset (and ctl
1754                                  (mail-content-type-get ctl 'charset)))
1755               (if (stringp charset)
1756                   (setq charset (intern (downcase charset)))))))
1757       (if read-charset
1758           (setq charset (mm-read-coding-system "Charset: " charset)))
1759       (unless charset
1760         (setq charset gnus-newsgroup-charset))
1761       (when (or force
1762                 (and type (let ((case-fold-search t))
1763                             (string-match "quoted-printable" type))))
1764         (article-goto-body)
1765         (quoted-printable-decode-region
1766          (point) (point-max) (mm-charset-to-coding-system charset))))))
1767
1768 (defun article-de-base64-unreadable (&optional force read-charset)
1769   "Translate a base64 article.
1770 If FORCE, decode the article whether it is marked as base64 not.
1771 If READ-CHARSET, ask for a coding system."
1772   (interactive (list 'force current-prefix-arg))
1773   (save-excursion
1774     (let ((buffer-read-only nil) type charset)
1775       (if (gnus-buffer-live-p gnus-original-article-buffer)
1776           (with-current-buffer gnus-original-article-buffer
1777             (setq type
1778                   (gnus-fetch-field "content-transfer-encoding"))
1779             (let* ((ct (gnus-fetch-field "content-type"))
1780                    (ctl (and ct
1781                              (ignore-errors
1782                                (mail-header-parse-content-type ct)))))
1783               (setq charset (and ctl
1784                                  (mail-content-type-get ctl 'charset)))
1785               (if (stringp charset)
1786                   (setq charset (intern (downcase charset)))))))
1787       (if read-charset
1788           (setq charset (mm-read-coding-system "Charset: " charset)))
1789       (unless charset
1790         (setq charset gnus-newsgroup-charset))
1791       (when (or force
1792                 (and type (let ((case-fold-search t))
1793                             (string-match "base64" type))))
1794         (article-goto-body)
1795         (save-restriction
1796           (narrow-to-region (point) (point-max))
1797           (base64-decode-region (point-min) (point-max))
1798           (mm-decode-coding-region
1799            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1800
1801 (eval-when-compile
1802   (require 'rfc1843))
1803
1804 (defun article-decode-HZ ()
1805   "Translate a HZ-encoded article."
1806   (interactive)
1807   (require 'rfc1843)
1808   (save-excursion
1809     (let ((buffer-read-only nil))
1810       (rfc1843-decode-region (point-min) (point-max)))))
1811
1812 (defun article-wash-html (&optional read-charset)
1813   "Format an html article.
1814 If READ-CHARSET, ask for a coding system."
1815   (interactive "P")
1816   (save-excursion
1817     (let ((buffer-read-only nil)
1818           charset)
1819       (if (gnus-buffer-live-p gnus-original-article-buffer)
1820           (with-current-buffer gnus-original-article-buffer
1821             (let* ((ct (gnus-fetch-field "content-type"))
1822                    (ctl (and ct
1823                              (ignore-errors
1824                                (mail-header-parse-content-type ct)))))
1825               (setq charset (and ctl
1826                                  (mail-content-type-get ctl 'charset)))
1827               (if (stringp charset)
1828                   (setq charset (intern (downcase charset)))))))
1829       (if read-charset
1830           (setq charset (mm-read-coding-system "Charset: " charset)))
1831       (unless charset
1832         (setq charset gnus-newsgroup-charset))
1833       (article-goto-body)
1834       (save-window-excursion
1835         (save-restriction
1836           (narrow-to-region (point) (point-max))
1837           (mm-setup-w3)
1838           (let ((w3-strict-width (window-width))
1839                 (url-standalone-mode t))
1840             (condition-case var
1841                 (w3-region (point-min) (point-max))
1842               (error))))))))
1843
1844 (defun article-hide-list-identifiers ()
1845   "Remove list identifies from the Subject header.
1846 The `gnus-list-identifiers' variable specifies what to do."
1847   (interactive)
1848   (let ((inhibit-point-motion-hooks t)
1849         (regexp (if (consp gnus-list-identifiers)
1850                     (mapconcat 'identity gnus-list-identifiers " *\\|")
1851                   gnus-list-identifiers))
1852         buffer-read-only)
1853     (when regexp
1854       (save-excursion
1855         (save-restriction
1856           (article-narrow-to-head)
1857           (goto-char (point-min))
1858           (while (re-search-forward
1859                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
1860                   nil t)
1861             (delete-region (match-beginning 2) (match-end 0))
1862             (beginning-of-line))
1863           (when (re-search-forward
1864                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
1865             (delete-region (match-beginning 1) (match-end 1))))))))
1866
1867 (defun article-hide-pgp ()
1868   "Remove any PGP headers and signatures in the current article."
1869   (interactive)
1870   (save-excursion
1871     (save-restriction
1872       (let ((inhibit-point-motion-hooks t)
1873             buffer-read-only beg end)
1874         (article-goto-body)
1875         ;; Hide the "header".
1876         (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1877           (push 'pgp gnus-article-wash-types)
1878           (delete-region (match-beginning 0) (match-end 0))
1879           ;; Remove armor headers (rfc2440 6.2)
1880           (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1881                                      (point)))
1882           (setq beg (point))
1883           ;; Hide the actual signature.
1884           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1885                (setq end (1+ (match-beginning 0)))
1886                (delete-region
1887                 end
1888                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1889                     (match-end 0)
1890                   ;; Perhaps we shouldn't hide to the end of the buffer
1891                   ;; if there is no end to the signature?
1892                   (point-max))))
1893           ;; Hide "- " PGP quotation markers.
1894           (when (and beg end)
1895             (narrow-to-region beg end)
1896             (goto-char (point-min))
1897             (while (re-search-forward "^- " nil t)
1898               (delete-region
1899                (match-beginning 0) (match-end 0)))
1900             (widen))
1901           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1902
1903 (defun article-hide-pem (&optional arg)
1904   "Toggle hiding of any PEM headers and signatures in the current article.
1905 If given a negative prefix, always show; if given a positive prefix,
1906 always hide."
1907   (interactive (gnus-article-hidden-arg))
1908   (unless (gnus-article-check-hidden-text 'pem arg)
1909     (save-excursion
1910       (let (buffer-read-only end)
1911         (goto-char (point-min))
1912         ;; Hide the horrendously ugly "header".
1913         (when (and (search-forward
1914                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1915                     nil t)
1916                    (setq end (1+ (match-beginning 0))))
1917           (push 'pem gnus-article-wash-types)
1918           (gnus-article-hide-text-type
1919            end
1920            (if (search-forward "\n\n" nil t)
1921                (match-end 0)
1922              (point-max))
1923            'pem)
1924           ;; Hide the trailer as well
1925           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1926                                 nil t)
1927             (gnus-article-hide-text-type
1928              (match-beginning 0) (match-end 0) 'pem)))))))
1929
1930 (defun article-strip-banner ()
1931   "Strip the banner specified by the `banner' group parameter."
1932   (interactive)
1933   (save-excursion
1934     (save-restriction
1935       (let ((inhibit-point-motion-hooks t)
1936             (banner (gnus-parameter-banner gnus-newsgroup-name))
1937             (gnus-signature-limit nil)
1938             buffer-read-only beg end)
1939         (when banner
1940           (article-goto-body)
1941           (cond
1942            ((eq banner 'signature)
1943             (when (gnus-article-narrow-to-signature)
1944               (widen)
1945               (forward-line -1)
1946               (delete-region (point) (point-max))))
1947            ((symbolp banner)
1948             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1949                 (while (re-search-forward banner nil t)
1950                   (delete-region (match-beginning 0) (match-end 0)))))
1951            ((stringp banner)
1952             (while (re-search-forward banner nil t)
1953               (delete-region (match-beginning 0) (match-end 0))))))))))
1954
1955 (defun article-babel ()
1956   "Translate article using an online translation service."
1957   (interactive)
1958   (require 'babel)
1959   (save-excursion
1960     (set-buffer gnus-article-buffer)
1961     (when (article-goto-body)
1962       (let* ((buffer-read-only nil)
1963              (start (point))
1964              (end (point-max))
1965              (orig (buffer-substring start end))
1966              (trans (babel-as-string orig)))
1967         (save-restriction
1968           (narrow-to-region start end)
1969           (delete-region start end)
1970           (insert trans))))))
1971
1972 (defun article-hide-signature (&optional arg)
1973   "Hide the signature in the current article.
1974 If given a negative prefix, always show; if given a positive prefix,
1975 always hide."
1976   (interactive (gnus-article-hidden-arg))
1977   (unless (gnus-article-check-hidden-text 'signature arg)
1978     (save-excursion
1979       (save-restriction
1980         (let ((buffer-read-only nil))
1981           (when (gnus-article-narrow-to-signature)
1982             (gnus-article-hide-text-type
1983              (point-min) (point-max) 'signature)))))))
1984
1985 (defun article-strip-headers-in-body ()
1986   "Strip offensive headers from bodies."
1987   (interactive)
1988   (save-excursion
1989     (article-goto-body)
1990     (let ((case-fold-search t))
1991       (when (looking-at "x-no-archive:")
1992         (gnus-delete-line)))))
1993
1994 (defun article-strip-leading-blank-lines ()
1995   "Remove all blank lines from the beginning of the article."
1996   (interactive)
1997   (save-excursion
1998     (let ((inhibit-point-motion-hooks t)
1999           buffer-read-only)
2000       (when (article-goto-body)
2001         (while (and (not (eobp))
2002                     (looking-at "[ \t]*$"))
2003           (gnus-delete-line))))))
2004
2005 (defun article-narrow-to-head ()
2006   "Narrow the buffer to the head of the message.
2007 Point is left at the beginning of the narrowed-to region."
2008   (narrow-to-region
2009    (goto-char (point-min))
2010    (if (search-forward "\n\n" nil 1)
2011        (1- (point))
2012      (point-max)))
2013   (goto-char (point-min)))
2014
2015 (defun article-goto-body ()
2016   "Place point at the start of the body."
2017   (goto-char (point-min))
2018   (cond
2019    ;; This variable is only bound when dealing with separate
2020    ;; MIME body parts.
2021    (article-goto-body-goes-to-point-min-p
2022     t)
2023    ((search-forward "\n\n" nil t)
2024     t)
2025    (t
2026     (goto-char (point-max))
2027     nil)))
2028
2029 (defun article-strip-multiple-blank-lines ()
2030   "Replace consecutive blank lines with one empty line."
2031   (interactive)
2032   (save-excursion
2033     (let ((inhibit-point-motion-hooks t)
2034           buffer-read-only)
2035       ;; First make all blank lines empty.
2036       (article-goto-body)
2037       (while (re-search-forward "^[ \t]+$" nil t)
2038         (unless (gnus-annotation-in-region-p
2039                  (match-beginning 0) (match-end 0))
2040           (replace-match "" nil t)))
2041       ;; Then replace multiple empty lines with a single empty line.
2042       (article-goto-body)
2043       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2044         (unless (gnus-annotation-in-region-p
2045                  (match-beginning 0) (match-end 0))
2046           (delete-region (match-beginning 1) (match-end 1)))))))
2047
2048 (defun article-strip-leading-space ()
2049   "Remove all white space from the beginning of the lines in the article."
2050   (interactive)
2051   (save-excursion
2052     (let ((inhibit-point-motion-hooks t)
2053           buffer-read-only)
2054       (article-goto-body)
2055       (while (re-search-forward "^[ \t]+" nil t)
2056         (replace-match "" t t)))))
2057
2058 (defun article-strip-trailing-space ()
2059   "Remove all white space from the end of the lines in the article."
2060   (interactive)
2061   (save-excursion
2062     (let ((inhibit-point-motion-hooks t)
2063           buffer-read-only)
2064       (article-goto-body)
2065       (while (re-search-forward "[ \t]+$" nil t)
2066         (replace-match "" t t)))))
2067
2068 (defun article-strip-blank-lines ()
2069   "Strip leading, trailing and multiple blank lines."
2070   (interactive)
2071   (article-strip-leading-blank-lines)
2072   (article-remove-trailing-blank-lines)
2073   (article-strip-multiple-blank-lines))
2074
2075 (defun article-strip-all-blank-lines ()
2076   "Strip all blank lines."
2077   (interactive)
2078   (save-excursion
2079     (let ((inhibit-point-motion-hooks t)
2080           buffer-read-only)
2081       (article-goto-body)
2082       (while (re-search-forward "^[ \t]*\n" nil t)
2083         (replace-match "" t t)))))
2084
2085 (defun gnus-article-narrow-to-signature ()
2086   "Narrow to the signature; return t if a signature is found, else nil."
2087   (let ((inhibit-point-motion-hooks t))
2088     (when (gnus-article-search-signature)
2089       (forward-line 1)
2090       ;; Check whether we have some limits to what we consider
2091       ;; to be a signature.
2092       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2093                       (list gnus-signature-limit)))
2094             limit limited)
2095         (while (setq limit (pop limits))
2096           (if (or (and (integerp limit)
2097                        (< (- (point-max) (point)) limit))
2098                   (and (floatp limit)
2099                        (< (count-lines (point) (point-max)) limit))
2100                   (and (gnus-functionp limit)
2101                        (funcall limit))
2102                   (and (stringp limit)
2103                        (not (re-search-forward limit nil t))))
2104               ()                        ; This limit did not succeed.
2105             (setq limited t
2106                   limits nil)))
2107         (unless limited
2108           (narrow-to-region (point) (point-max))
2109           t)))))
2110
2111 (defun gnus-article-search-signature ()
2112   "Search the current buffer for the signature separator.
2113 Put point at the beginning of the signature separator."
2114   (let ((cur (point)))
2115     (goto-char (point-max))
2116     (if (if (stringp gnus-signature-separator)
2117             (re-search-backward gnus-signature-separator nil t)
2118           (let ((seps gnus-signature-separator))
2119             (while (and seps
2120                         (not (re-search-backward (car seps) nil t)))
2121               (pop seps))
2122             seps))
2123         t
2124       (goto-char cur)
2125       nil)))
2126
2127 (defun gnus-article-hidden-arg ()
2128   "Return the current prefix arg as a number, or 0 if no prefix."
2129   (list (if current-prefix-arg
2130             (prefix-numeric-value current-prefix-arg)
2131           0)))
2132
2133 (defun gnus-article-check-hidden-text (type arg)
2134   "Return nil if hiding is necessary.
2135 Arg can be nil or a number.  Nil and positive means hide, negative
2136 means show, 0 means toggle."
2137   (save-excursion
2138     (save-restriction
2139       (let ((hide (gnus-article-hidden-text-p type)))
2140         (cond
2141          ((or (null arg)
2142               (> arg 0))
2143           nil)
2144          ((< arg 0)
2145           (gnus-article-show-hidden-text type)
2146           t)
2147          (t
2148           (if (eq hide 'hidden)
2149               (progn
2150                 (gnus-article-show-hidden-text type)
2151                 t)
2152             nil)))))))
2153
2154 (defun gnus-article-hidden-text-p (type)
2155   "Say whether the current buffer contains hidden text of type TYPE."
2156   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2157     (while (and pos
2158                 (not (get-text-property pos 'invisible))
2159                 (not (get-text-property pos 'dummy-invisible)))
2160       (setq pos
2161             (text-property-any (1+ pos) (point-max) 'article-type type)))
2162     (if pos
2163         'hidden
2164       nil)))
2165
2166 (defun gnus-article-show-hidden-text (type &optional dummy)
2167   "Show all hidden text of type TYPE.
2168 Originally it is hide instead of DUMMY."
2169   (let ((buffer-read-only nil)
2170         (inhibit-point-motion-hooks t))
2171     (gnus-remove-text-properties-when
2172      'article-type type
2173      (point-min) (point-max)
2174      (cons 'article-type (cons type
2175                                gnus-hidden-properties)))))
2176
2177 (defconst article-time-units
2178   `((year . ,(* 365.25 24 60 60))
2179     (week . ,(* 7 24 60 60))
2180     (day . ,(* 24 60 60))
2181     (hour . ,(* 60 60))
2182     (minute . 60)
2183     (second . 1))
2184   "Mapping from time units to seconds.")
2185
2186 (defun article-date-ut (&optional type highlight header)
2187   "Convert DATE date to universal time in the current article.
2188 If TYPE is `local', convert to local time; if it is `lapsed', output
2189 how much time has lapsed since DATE.  For `lapsed', the value of
2190 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2191 should replace the \"Date:\" one, or should be added below it."
2192   (interactive (list 'ut t))
2193   (let* ((header (or header
2194                      (message-fetch-field "date")
2195                      ""))
2196          (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2197          (date-regexp
2198           (cond
2199            ((not gnus-article-date-lapsed-new-header)
2200             tdate-regexp)
2201            ((eq type 'lapsed)
2202             "^X-Sent:[ \t]")
2203            (t
2204             "^Date:[ \t]")))
2205          (date (if (vectorp header) (mail-header-date header)
2206                  header))
2207          (inhibit-point-motion-hooks t)
2208          pos
2209          bface eface)
2210     (save-excursion
2211       (save-restriction
2212         (article-narrow-to-head)
2213         (when (re-search-forward tdate-regexp nil t)
2214           (setq bface (get-text-property (gnus-point-at-bol) 'face)
2215                 date (or (get-text-property (gnus-point-at-bol)
2216                                             'original-date)
2217                          date)
2218                 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2219           (forward-line 1))
2220         (when (and date (not (string= date "")))
2221           (goto-char (point-min))
2222           (let ((buffer-read-only nil))
2223             ;; Delete any old Date headers.
2224             (while (re-search-forward date-regexp nil t)
2225               (if pos
2226                   (delete-region (progn (beginning-of-line) (point))
2227                                  (progn (forward-line 1) (point)))
2228                 (delete-region (progn (beginning-of-line) (point))
2229                                (progn (end-of-line) (point)))
2230                 (setq pos (point))))
2231             (when (and (not pos) (re-search-forward tdate-regexp nil t))
2232               (forward-line 1))
2233             (if pos (goto-char pos))
2234             (insert (article-make-date-line date (or type 'ut)))
2235             (when (not pos)
2236               (insert "\n")
2237               (forward-line -1))
2238             ;; Do highlighting.
2239             (beginning-of-line)
2240             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2241               (put-text-property (match-beginning 1) (1+ (match-end 1))
2242                                  'original-date date)
2243               (put-text-property (match-beginning 1) (1+ (match-end 1))
2244                                  'face bface)
2245               (put-text-property (match-beginning 2) (match-end 2)
2246                                  'face eface))))))))
2247
2248 (defun article-make-date-line (date type)
2249   "Return a DATE line of TYPE."
2250   (unless (memq type '(local ut original user iso8601 lapsed english))
2251     (error "Unknown conversion type: %s" type))
2252   (condition-case ()
2253       (let ((time (date-to-time date)))
2254         (cond
2255          ;; Convert to the local timezone.
2256          ((eq type 'local)
2257           (let ((tz (car (current-time-zone time))))
2258             (format "Date: %s %s%02d%02d" (current-time-string time)
2259                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2260                     (/ (% (abs tz) 3600) 60))))
2261          ;; Convert to Universal Time.
2262          ((eq type 'ut)
2263           (concat "Date: "
2264                   (current-time-string
2265                    (let* ((e (parse-time-string date))
2266                           (tm (apply 'encode-time e))
2267                           (ms (car tm))
2268                           (ls (- (cadr tm) (car (current-time-zone time)))))
2269                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2270                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2271                            (t (list ms ls)))))
2272                   " UT"))
2273          ;; Get the original date from the article.
2274          ((eq type 'original)
2275           (concat "Date: " (if (string-match "\n+$" date)
2276                                (substring date 0 (match-beginning 0))
2277                              date)))
2278          ;; Let the user define the format.
2279          ((eq type 'user)
2280           (if (gnus-functionp gnus-article-time-format)
2281               (funcall gnus-article-time-format time)
2282             (concat
2283              "Date: "
2284              (format-time-string gnus-article-time-format time))))
2285          ;; ISO 8601.
2286          ((eq type 'iso8601)
2287           (let ((tz (car (current-time-zone time))))
2288             (concat
2289              "Date: "
2290              (format-time-string "%Y%m%dT%H%M%S" time)
2291              (format "%s%02d%02d"
2292                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2293                      (/ (% (abs tz) 3600) 60)))))
2294          ;; Do an X-Sent lapsed format.
2295          ((eq type 'lapsed)
2296           ;; If the date is seriously mangled, the timezone functions are
2297           ;; liable to bug out, so we ignore all errors.
2298           (let* ((now (current-time))
2299                  (real-time (subtract-time now time))
2300                  (real-sec (and real-time
2301                                 (+ (* (float (car real-time)) 65536)
2302                                    (cadr real-time))))
2303                  (sec (and real-time (abs real-sec)))
2304                  num prev)
2305             (cond
2306              ((null real-time)
2307               "X-Sent: Unknown")
2308              ((zerop sec)
2309               "X-Sent: Now")
2310              (t
2311               (concat
2312                "X-Sent: "
2313                ;; This is a bit convoluted, but basically we go
2314                ;; through the time units for years, weeks, etc,
2315                ;; and divide things to see whether that results
2316                ;; in positive answers.
2317                (mapconcat
2318                 (lambda (unit)
2319                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2320                       ;; The (remaining) seconds are too few to
2321                       ;; be divided into this time unit.
2322                       ""
2323                     ;; It's big enough, so we output it.
2324                     (setq sec (- sec (* num (cdr unit))))
2325                     (prog1
2326                         (concat (if prev ", " "") (int-to-string
2327                                                    (floor num))
2328                                 " " (symbol-name (car unit))
2329                                 (if (> num 1) "s" ""))
2330                       (setq prev t))))
2331                 article-time-units "")
2332                ;; If dates are odd, then it might appear like the
2333                ;; article was sent in the future.
2334                (if (> real-sec 0)
2335                    " ago"
2336                  " in the future"))))))
2337          ;; Display the date in proper English
2338          ((eq type 'english)
2339           (let ((dtime (decode-time time)))
2340             (concat
2341              "Date: the "
2342              (number-to-string (nth 3 dtime))
2343              (let ((digit (% (nth 3 dtime) 10)))
2344                (cond
2345                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2346                 ((= digit 1) "st")
2347                 ((= digit 2) "nd")
2348                 ((= digit 3) "rd")
2349                 (t "th")))
2350              " of "
2351              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2352              " "
2353              (number-to-string (nth 5 dtime))
2354              " at "
2355              (format "%02d" (nth 2 dtime))
2356              ":"
2357              (format "%02d" (nth 1 dtime)))))))
2358         (error
2359          (format "Date: %s (from Oort)" date))))
2360
2361 (defun article-date-local (&optional highlight)
2362   "Convert the current article date to the local timezone."
2363   (interactive (list t))
2364   (article-date-ut 'local highlight))
2365
2366 (defun article-date-english (&optional highlight)
2367   "Convert the current article date to something that is proper English."
2368   (interactive (list t))
2369   (article-date-ut 'english highlight))
2370
2371 (defun article-date-original (&optional highlight)
2372   "Convert the current article date to what it was originally.
2373 This is only useful if you have used some other date conversion
2374 function and want to see what the date was before converting."
2375   (interactive (list t))
2376   (article-date-ut 'original highlight))
2377
2378 (defun article-date-lapsed (&optional highlight)
2379   "Convert the current article date to time lapsed since it was sent."
2380   (interactive (list t))
2381   (article-date-ut 'lapsed highlight))
2382
2383 (defun article-update-date-lapsed ()
2384   "Function to be run from a timer to update the lapsed time line."
2385   (let (deactivate-mark)
2386     (save-excursion
2387       (ignore-errors
2388         (walk-windows
2389          (lambda (w)
2390            (set-buffer (window-buffer w))
2391            (when (eq major-mode 'gnus-article-mode)
2392              (goto-char (point-min))
2393              (when (re-search-forward "^X-Sent:" nil t)
2394                (article-date-lapsed t))))
2395          nil 'visible)))))
2396
2397 (defun gnus-start-date-timer (&optional n)
2398   "Start a timer to update the X-Sent header in the article buffers.
2399 The numerical prefix says how frequently (in seconds) the function
2400 is to run."
2401   (interactive "p")
2402   (unless n
2403     (setq n 1))
2404   (gnus-stop-date-timer)
2405   (setq article-lapsed-timer
2406         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2407
2408 (defun gnus-stop-date-timer ()
2409   "Stop the X-Sent timer."
2410   (interactive)
2411   (when article-lapsed-timer
2412     (nnheader-cancel-timer article-lapsed-timer)
2413     (setq article-lapsed-timer nil)))
2414
2415 (defun article-date-user (&optional highlight)
2416   "Convert the current article date to the user-defined format.
2417 This format is defined by the `gnus-article-time-format' variable."
2418   (interactive (list t))
2419   (article-date-ut 'user highlight))
2420
2421 (defun article-date-iso8601 (&optional highlight)
2422   "Convert the current article date to ISO8601."
2423   (interactive (list t))
2424   (article-date-ut 'iso8601 highlight))
2425
2426 (defun article-show-all ()
2427   "Show all hidden text in the article buffer."
2428   (interactive)
2429   (save-excursion
2430     (let ((buffer-read-only nil))
2431       (gnus-article-unhide-text (point-min) (point-max)))))
2432
2433 (defun article-remove-leading-whitespace ()
2434   "Remove excessive whitespace from all headers."
2435   (interactive)
2436   (save-excursion
2437     (save-restriction
2438       (let ((buffer-read-only nil))
2439         (article-narrow-to-head)
2440         (goto-char (point-min))
2441         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2442           (delete-region (match-beginning 1) (match-end 1)))))))
2443
2444 (defun article-emphasize (&optional arg)
2445   "Emphasize text according to `gnus-emphasis-alist'."
2446   (interactive (gnus-article-hidden-arg))
2447   (unless (gnus-article-check-hidden-text 'emphasis arg)
2448     (save-excursion
2449       (let ((alist (or
2450                     (condition-case nil
2451                         (with-current-buffer gnus-summary-buffer
2452                           gnus-article-emphasis-alist)
2453                       (error))
2454                     gnus-emphasis-alist))
2455             (buffer-read-only nil)
2456             (props (append '(article-type emphasis)
2457                            gnus-hidden-properties))
2458             regexp elem beg invisible visible face)
2459         (article-goto-body)
2460         (setq beg (point))
2461         (while (setq elem (pop alist))
2462           (goto-char beg)
2463           (setq regexp (car elem)
2464                 invisible (nth 1 elem)
2465                 visible (nth 2 elem)
2466                 face (nth 3 elem))
2467           (while (re-search-forward regexp nil t)
2468             (when (and (match-beginning visible) (match-beginning invisible))
2469               (push 'emphasis gnus-article-wash-types)
2470               (gnus-article-hide-text
2471                (match-beginning invisible) (match-end invisible) props)
2472               (gnus-article-unhide-text-type
2473                (match-beginning visible) (match-end visible) 'emphasis)
2474               (gnus-put-text-property-excluding-newlines
2475                (match-beginning visible) (match-end visible) 'face face)
2476               (goto-char (match-end invisible)))))))))
2477
2478 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2479   "Setup newsgroup emphasis alist."
2480   (unless gnus-article-emphasis-alist
2481     (let ((name (and gnus-newsgroup-name
2482                      (gnus-group-real-name gnus-newsgroup-name))))
2483       (make-local-variable 'gnus-article-emphasis-alist)
2484       (setq gnus-article-emphasis-alist
2485             (nconc
2486              (let ((alist gnus-group-highlight-words-alist) elem highlight)
2487                (while (setq elem (pop alist))
2488                  (when (and name (string-match (car elem) name))
2489                    (setq alist nil
2490                          highlight (copy-sequence (cdr elem)))))
2491                highlight)
2492              (copy-sequence highlight-words)
2493              (if gnus-newsgroup-name
2494                  (copy-sequence (gnus-group-find-parameter
2495                                  gnus-newsgroup-name 'highlight-words t)))
2496              gnus-emphasis-alist)))))
2497
2498 (eval-when-compile
2499   (defvar gnus-summary-article-menu)
2500   (defvar gnus-summary-post-menu))
2501
2502 ;;; Saving functions.
2503
2504 (defun gnus-article-save (save-buffer file &optional num)
2505   "Save the currently selected article."
2506   (unless gnus-save-all-headers
2507     ;; Remove headers according to `gnus-saved-headers'.
2508     (let ((gnus-visible-headers
2509            (or gnus-saved-headers gnus-visible-headers))
2510           (gnus-article-buffer save-buffer))
2511       (save-excursion
2512         (set-buffer save-buffer)
2513         (article-hide-headers 1 t))))
2514   (save-window-excursion
2515     (if (not gnus-default-article-saver)
2516         (error "No default saver is defined")
2517       ;; !!! Magic!  The saving functions all save
2518       ;; `gnus-save-article-buffer' (or so they think), but we
2519       ;; bind that variable to our save-buffer.
2520       (set-buffer gnus-article-buffer)
2521       (let* ((gnus-save-article-buffer save-buffer)
2522              (filename
2523               (cond
2524                ((not gnus-prompt-before-saving) 'default)
2525                ((eq gnus-prompt-before-saving 'always) nil)
2526                (t file)))
2527              (gnus-number-of-articles-to-be-saved
2528               (when (eq gnus-prompt-before-saving t)
2529                 num)))                  ; Magic
2530         (set-buffer gnus-article-current-summary)
2531         (funcall gnus-default-article-saver filename)))))
2532
2533 (defun gnus-read-save-file-name (prompt &optional filename
2534                                         function group headers variable)
2535   (let ((default-name
2536           (funcall function group headers (symbol-value variable)))
2537         result)
2538     (setq result
2539           (expand-file-name
2540            (cond
2541             ((eq filename 'default)
2542              default-name)
2543             ((eq filename t)
2544              default-name)
2545             (filename filename)
2546             (t
2547              (let* ((split-name (gnus-get-split-value gnus-split-methods))
2548                     (prompt
2549                      (format prompt
2550                              (if (and gnus-number-of-articles-to-be-saved
2551                                       (> gnus-number-of-articles-to-be-saved 1))
2552                                  (format "these %d articles"
2553                                          gnus-number-of-articles-to-be-saved)
2554                                "this article")))
2555                     (file
2556                      ;; Let the split methods have their say.
2557                      (cond
2558                       ;; No split name was found.
2559                       ((null split-name)
2560                        (read-file-name
2561                         (concat prompt " (default "
2562                                 (file-name-nondirectory default-name) ") ")
2563                         (file-name-directory default-name)
2564                         default-name))
2565                       ;; A single group name is returned.
2566                       ((stringp split-name)
2567                        (setq default-name
2568                              (funcall function split-name headers
2569                                       (symbol-value variable)))
2570                        (read-file-name
2571                         (concat prompt " (default "
2572                                 (file-name-nondirectory default-name) ") ")
2573                         (file-name-directory default-name)
2574                         default-name))
2575                       ;; A single split name was found
2576                       ((= 1 (length split-name))
2577                        (let* ((name (expand-file-name
2578                                      (car split-name)
2579                                      gnus-article-save-directory))
2580                               (dir (cond ((file-directory-p name)
2581                                           (file-name-as-directory name))
2582                                          ((file-exists-p name) name)
2583                                          (t gnus-article-save-directory))))
2584                          (read-file-name
2585                           (concat prompt " (default " name ") ")
2586                           dir name)))
2587                       ;; A list of splits was found.
2588                       (t
2589                        (setq split-name (nreverse split-name))
2590                        (let (result)
2591                          (let ((file-name-history
2592                                 (nconc split-name file-name-history)))
2593                            (setq result
2594                                  (expand-file-name
2595                                   (read-file-name
2596                                    (concat prompt " (`M-p' for defaults) ")
2597                                    gnus-article-save-directory
2598                                    (car split-name))
2599                                   gnus-article-save-directory)))
2600                          (car (push result file-name-history)))))))
2601                ;; Create the directory.
2602                (gnus-make-directory (file-name-directory file))
2603       ;; If we have read a directory, we append the default file name.
2604                (when (file-directory-p file)
2605                  (setq file (expand-file-name (file-name-nondirectory
2606                                                default-name)
2607                                               (file-name-as-directory file))))
2608                ;; Possibly translate some characters.
2609                (nnheader-translate-file-chars file))))))
2610     (gnus-make-directory (file-name-directory result))
2611     (set variable result)))
2612
2613 (defun gnus-article-archive-name (group)
2614   "Return the first instance of an \"Archive-name\" in the current buffer."
2615   (let ((case-fold-search t))
2616     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2617       (nnheader-concat gnus-article-save-directory
2618                        (match-string 1)))))
2619
2620 (defun gnus-article-nndoc-name (group)
2621   "If GROUP is an nndoc group, return the name of the parent group."
2622   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2623     (gnus-group-get-parameter group 'save-article-group)))
2624
2625 (defun gnus-summary-save-in-rmail (&optional filename)
2626   "Append this article to Rmail file.
2627 Optional argument FILENAME specifies file name.
2628 Directory to save to is default to `gnus-article-save-directory'."
2629   (setq filename (gnus-read-save-file-name
2630                   "Save %s in rmail file:" filename
2631                   gnus-rmail-save-name gnus-newsgroup-name
2632                   gnus-current-headers 'gnus-newsgroup-last-rmail))
2633   (gnus-eval-in-buffer-window gnus-save-article-buffer
2634     (save-excursion
2635       (save-restriction
2636         (widen)
2637         (gnus-output-to-rmail filename))))
2638   filename)
2639
2640 (defun gnus-summary-save-in-mail (&optional filename)
2641   "Append this article to Unix mail file.
2642 Optional argument FILENAME specifies file name.
2643 Directory to save to is default to `gnus-article-save-directory'."
2644   (setq filename (gnus-read-save-file-name
2645                   "Save %s in Unix mail file:" filename
2646                   gnus-mail-save-name gnus-newsgroup-name
2647                   gnus-current-headers 'gnus-newsgroup-last-mail))
2648   (gnus-eval-in-buffer-window gnus-save-article-buffer
2649     (save-excursion
2650       (save-restriction
2651         (widen)
2652         (if (and (file-readable-p filename)
2653                  (mail-file-babyl-p filename))
2654             (rmail-output-to-rmail-file filename t)
2655           (gnus-output-to-mail filename)))))
2656   filename)
2657
2658 (defun gnus-summary-save-in-file (&optional filename overwrite)
2659   "Append this article to file.
2660 Optional argument FILENAME specifies file name.
2661 Directory to save to is default to `gnus-article-save-directory'."
2662   (setq filename (gnus-read-save-file-name
2663                   "Save %s in file:" filename
2664                   gnus-file-save-name gnus-newsgroup-name
2665                   gnus-current-headers 'gnus-newsgroup-last-file))
2666   (gnus-eval-in-buffer-window gnus-save-article-buffer
2667     (save-excursion
2668       (save-restriction
2669         (widen)
2670         (when (and overwrite
2671                    (file-exists-p filename))
2672           (delete-file filename))
2673         (gnus-output-to-file filename))))
2674   filename)
2675
2676 (defun gnus-summary-write-to-file (&optional filename)
2677   "Write this article to a file.
2678 Optional argument FILENAME specifies file name.
2679 The directory to save in defaults to `gnus-article-save-directory'."
2680   (gnus-summary-save-in-file nil t))
2681
2682 (defun gnus-summary-save-body-in-file (&optional filename)
2683   "Append this article body to a file.
2684 Optional argument FILENAME specifies file name.
2685 The directory to save in defaults to `gnus-article-save-directory'."
2686   (setq filename (gnus-read-save-file-name
2687                   "Save %s body in file:" filename
2688                   gnus-file-save-name gnus-newsgroup-name
2689                   gnus-current-headers 'gnus-newsgroup-last-file))
2690   (gnus-eval-in-buffer-window gnus-save-article-buffer
2691     (save-excursion
2692       (save-restriction
2693         (widen)
2694         (when (article-goto-body)
2695           (narrow-to-region (point) (point-max)))
2696         (gnus-output-to-file filename))))
2697   filename)
2698
2699 (defun gnus-summary-save-in-pipe (&optional command)
2700   "Pipe this article to subprocess."
2701   (setq command
2702         (cond ((and (eq command 'default)
2703                     gnus-last-shell-command)
2704                gnus-last-shell-command)
2705               ((stringp command)
2706                command)
2707               (t (read-string
2708                   (format
2709                    "Shell command on %s: "
2710                    (if (and gnus-number-of-articles-to-be-saved
2711                             (> gnus-number-of-articles-to-be-saved 1))
2712                        (format "these %d articles"
2713                                gnus-number-of-articles-to-be-saved)
2714                      "this article"))
2715                   gnus-last-shell-command))))
2716   (when (string-equal command "")
2717     (if gnus-last-shell-command
2718         (setq command gnus-last-shell-command)
2719       (error "A command is required")))
2720   (gnus-eval-in-buffer-window gnus-article-buffer
2721     (save-restriction
2722       (widen)
2723       (shell-command-on-region (point-min) (point-max) command nil)))
2724   (setq gnus-last-shell-command command))
2725
2726 ;;; Article file names when saving.
2727
2728 (defun gnus-capitalize-newsgroup (newsgroup)
2729   "Capitalize NEWSGROUP name."
2730   (when (not (zerop (length newsgroup)))
2731     (concat (char-to-string (upcase (aref newsgroup 0)))
2732             (substring newsgroup 1))))
2733
2734 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2735   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2736 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2737 Otherwise, it is like ~/News/news/group/num."
2738   (let ((default
2739           (expand-file-name
2740            (concat (if (gnus-use-long-file-name 'not-save)
2741                        (gnus-capitalize-newsgroup newsgroup)
2742                      (gnus-newsgroup-directory-form newsgroup))
2743                    "/" (int-to-string (mail-header-number headers)))
2744            gnus-article-save-directory)))
2745     (if (and last-file
2746              (string-equal (file-name-directory default)
2747                            (file-name-directory last-file))
2748              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2749         default
2750       (or last-file default))))
2751
2752 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2753   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2754 If variable `gnus-use-long-file-name' is non-nil, it is
2755 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
2756   (let ((default
2757           (expand-file-name
2758            (concat (if (gnus-use-long-file-name 'not-save)
2759                        newsgroup
2760                      (gnus-newsgroup-directory-form newsgroup))
2761                    "/" (int-to-string (mail-header-number headers)))
2762            gnus-article-save-directory)))
2763     (if (and last-file
2764              (string-equal (file-name-directory default)
2765                            (file-name-directory last-file))
2766              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2767         default
2768       (or last-file default))))
2769
2770 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2771   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2772 If variable `gnus-use-long-file-name' is non-nil, it is
2773 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
2774   (or last-file
2775       (expand-file-name
2776        (if (gnus-use-long-file-name 'not-save)
2777            newsgroup
2778          (file-relative-name
2779           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
2780           default-directory))
2781        gnus-article-save-directory)))
2782
2783 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2784   "Generate file name from sender."
2785   (let ((from (mail-header-from headers)))
2786     (expand-file-name
2787      (if (and from (string-match "\\([^ <]+\\)@" from))
2788          (match-string 1 from)
2789        "nobody")
2790      gnus-article-save-directory)))
2791
2792 (defun article-verify-x-pgp-sig ()
2793   "Verify X-PGP-Sig."
2794   (interactive)
2795   (if (gnus-buffer-live-p gnus-original-article-buffer)
2796       (let ((sig (with-current-buffer gnus-original-article-buffer
2797                    (gnus-fetch-field "X-PGP-Sig")))
2798             items info headers)
2799         (when (and sig
2800                    mml2015-use
2801                    (mml2015-clear-verify-function))
2802           (with-temp-buffer
2803             (insert-buffer gnus-original-article-buffer)
2804             (setq items (split-string sig))
2805             (message-narrow-to-head)
2806