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