(gnus-article-next-page): Change last-line-displayed behaviour.
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2011 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 3 of the License, or
13 ;; (at your option) 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.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 ;; For Emacs <22.2 and XEmacs.
28 (eval-and-compile
29   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
30 (eval-when-compile
31   (require 'cl))
32 (defvar tool-bar-map)
33 (defvar w3m-minor-mode-map)
34
35 (require 'gnus)
36 (require 'gnus-sum)
37 (require 'gnus-spec)
38 (require 'gnus-int)
39 (require 'gnus-win)
40 (require 'mm-bodies)
41 (require 'mail-parse)
42 (require 'mm-decode)
43 (require 'mm-view)
44 (require 'wid-edit)
45 (require 'mm-uu)
46 (require 'message)
47
48 (autoload 'gnus-msg-mail "gnus-msg" nil t)
49 (autoload 'gnus-button-mailto "gnus-msg")
50 (autoload 'gnus-button-reply "gnus-msg" nil t)
51 (autoload 'parse-time-string "parse-time" nil nil)
52 (autoload 'ansi-color-apply-on-region "ansi-color")
53 (autoload 'mm-url-insert-file-contents-external "mm-url")
54 (autoload 'mm-extern-cache-contents "mm-extern")
55
56 (defgroup gnus-article nil
57   "Article display."
58   :link '(custom-manual "(gnus)Article Buffer")
59   :group 'gnus)
60
61 (defgroup gnus-article-treat nil
62   "Treating article parts."
63   :link '(custom-manual "(gnus)Article Hiding")
64   :group 'gnus-article)
65
66 (defgroup gnus-article-hiding nil
67   "Hiding article parts."
68   :link '(custom-manual "(gnus)Article Hiding")
69   :group 'gnus-article)
70
71 (defgroup gnus-article-highlight nil
72   "Article highlighting."
73   :link '(custom-manual "(gnus)Article Highlighting")
74   :group 'gnus-article
75   :group 'gnus-visual)
76
77 (defgroup gnus-article-signature nil
78   "Article signatures."
79   :link '(custom-manual "(gnus)Article Signature")
80   :group 'gnus-article)
81
82 (defgroup gnus-article-headers nil
83   "Article headers."
84   :link '(custom-manual "(gnus)Hiding Headers")
85   :group 'gnus-article)
86
87 (defgroup gnus-article-washing nil
88   "Special commands on articles."
89   :link '(custom-manual "(gnus)Article Washing")
90   :group 'gnus-article)
91
92 (defgroup gnus-article-emphasis nil
93   "Fontisizing articles."
94   :link '(custom-manual "(gnus)Article Fontisizing")
95   :group 'gnus-article)
96
97 (defgroup gnus-article-saving nil
98   "Saving articles."
99   :link '(custom-manual "(gnus)Saving Articles")
100   :group 'gnus-article)
101
102 (defgroup gnus-article-mime nil
103   "Worshiping the MIME wonder."
104   :link '(custom-manual "(gnus)Using MIME")
105   :group 'gnus-article)
106
107 (defgroup gnus-article-buttons nil
108   "Pushable buttons in the article buffer."
109   :link '(custom-manual "(gnus)Article Buttons")
110   :group 'gnus-article)
111
112 (defgroup gnus-article-various nil
113   "Other article options."
114   :link '(custom-manual "(gnus)Misc Article")
115   :group 'gnus-article)
116
117 (defcustom gnus-ignored-headers
118   (mapcar
119    (lambda (header)
120      (concat "^" header ":"))
121    '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
122      "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
123      "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
124      "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
125      "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
126      "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
127      "X-Attribution" "X-Originating-IP" "Delivered-To"
128      "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
129      "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
130      "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
131      "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
132      "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
133      "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
134      "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
135      "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
136      "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
137      "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
138      "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
139      "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
140      "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
141      "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
142      "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
143      "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
144      "List-[A-Za-z]+" "X-Listprocessor-Version"
145      "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
146      "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
147      "X-Received" "Content-length" "X-precedence"
148      "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
149      "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
150      "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
151      "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
152      "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
153      "X-Content-length" "X-Posting-Agent" "Original-Received"
154      "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
155      "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
156      "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
157      "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
158      "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
159      "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
160      "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
161      "Envelope-Sender" "Envelope-Recipients"))
162   "*All headers that start with this regexp will be hidden.
163 This variable can also be a list of regexps of headers to be ignored.
164 If `gnus-visible-headers' is non-nil, this variable will be ignored."
165   :type '(choice :custom-show nil
166                  regexp
167                  (repeat regexp))
168   :group 'gnus-article-hiding)
169
170 (defcustom gnus-visible-headers
171   "^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:"
172   "*All headers that do not match this regexp will be hidden.
173 This variable can also be a list of regexp of headers to remain visible.
174 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
175   :type '(choice
176           (repeat :value-to-internal (lambda (widget value)
177                                        (custom-split-regexp-maybe value))
178                   :match (lambda (widget value)
179                            (or (stringp value)
180                                (widget-editable-list-match widget value)))
181                   regexp)
182           (const :tag "Use gnus-ignored-headers" nil)
183           regexp)
184   :group 'gnus-article-hiding)
185
186 (defcustom gnus-sorted-header-list
187   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189   "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
192 this list."
193   :type '(repeat regexp)
194   :group 'gnus-article-hiding)
195
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197   "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
199
200   'empty       Headers with no content.
201   'newsgroups  Newsgroup identical to Gnus group.
202   'to-address  To identical to To-address.
203   'to-list     To identical to To-list.
204   'cc-list     CC identical to To-list.
205   'followup-to Followup-to identical to Newsgroups.
206   'reply-to    Reply-to identical to From.
207   'date        Date less than four days old.
208   'long-to     To and/or Cc longer than 1024 characters.
209   'many-to     Multiple To and/or Cc."
210   :type '(set (const :tag "Headers with no content." empty)
211               (const :tag "Newsgroups identical to Gnus group." newsgroups)
212               (const :tag "To identical to To-address." to-address)
213               (const :tag "To identical to To-list." to-list)
214               (const :tag "CC identical to To-list." cc-list)
215               (const :tag "Followup-to identical to Newsgroups." followup-to)
216               (const :tag "Reply-to identical to From." reply-to)
217               (const :tag "Date less than four days old." date)
218               (const :tag "To and/or Cc longer than 1024 characters." long-to)
219               (const :tag "Multiple To and/or Cc headers." many-to))
220   :group 'gnus-article-hiding)
221
222 (defcustom gnus-article-skip-boring nil
223   "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text.  Boring text is controlled by
227 `gnus-article-boring-faces'."
228   :version "22.1"
229   :type 'boolean
230   :group 'gnus-article-hiding)
231
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233   "Regexp matching signature separator.
234 This can also be a list of regexps.  In that case, it will be checked
235 from head to tail looking for a separator.  Searches will be done from
236 the end of the buffer."
237   :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
238                  (regexp)
239                  (repeat :tag "List of regexp" regexp))
240   :group 'gnus-article-signature)
241
242 (defcustom gnus-signature-limit nil
243   "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number.  If it is a floating point number, no signature may be
246 longer (in lines) than that number.  If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer.  If it is a string, it will be used as a
249 regexp.  If it matches, the text in question is not a signature.
250
251 This can also be a list of the above values."
252   :type '(choice (const nil)
253                  (integer :value 200)
254                  (number :value 4.0)
255                  function
256                  (regexp :value ".*"))
257   :group 'gnus-article-signature)
258
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260   "Property list to use for hiding text."
261   :type 'sexp
262   :group 'gnus-article-hiding)
263
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267   (if (featurep 'xemacs)
268       (if (or (gnus-image-type-available-p 'xface)
269               (gnus-image-type-available-p 'pbm))
270           'gnus-display-x-face-in-from
271         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
272     (if (gnus-image-type-available-p 'pbm)
273         'gnus-display-x-face-in-from
274       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
275 display -"))
276   "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously.  The compressed face will be piped to this command."
279   :type `(choice string
280                  (function-item gnus-display-x-face-in-from)
281                  function)
282   :version "21.1"
283   :group 'gnus-picon
284   :group 'gnus-article-washing)
285
286 (defcustom gnus-article-x-face-too-ugly nil
287   "Regexp matching posters whose face shouldn't be shown automatically."
288   :type '(choice regexp (const nil))
289   :group 'gnus-article-washing)
290
291 (defcustom gnus-article-banner-alist nil
292   "Banner alist for stripping.
293 For example,
294      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
295   :version "21.1"
296   :type '(repeat (cons symbol regexp))
297   :group 'gnus-article-washing)
298
299 (gnus-define-group-parameter
300  banner
301  :variable-document
302  "Alist of regexps (to match group names) and banner."
303  :variable-group gnus-article-washing
304  :parameter-type
305  '(choice :tag "Banner"
306           :value nil
307           (const :tag "Remove signature" signature)
308           (symbol :tag "Item in `gnus-article-banner-alist'" none)
309           regexp
310           (const :tag "None" nil))
311  :parameter-document
312  "If non-nil, specify how to remove `banners' from articles.
313
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'.  Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
318 directly.")
319
320 (defcustom gnus-article-address-banner-alist nil
321   "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements.  For example:
327
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
329 "
330   :type '(repeat
331           (cons
332            (regexp :tag "Address")
333            (choice :tag "Banner" :value nil
334                    (const :tag "Remove signature" signature)
335                    (symbol :tag "Item in `gnus-article-banner-alist'" none)
336                    regexp
337                    (const :tag "None" nil))))
338   :version "22.1"
339   :group 'gnus-article-washing)
340
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
342   `(let ((format "\
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
345      ,@body))
346
347 (defun gnus-emphasis-custom-value-to-external (value)
348   (gnus-emphasis-custom-with-format
349    (if (consp (car value))
350        (list (format format (car (car value)) (cdr (car value)))
351              2
352              (if (nth 1 value) 2 3)
353              (nth 2 value))
354      value)))
355
356 (defun gnus-emphasis-custom-value-to-internal (value)
357   (gnus-emphasis-custom-with-format
358    (let ((regexp (concat "\\`"
359                          (format (regexp-quote format)
360                                  "\\([^()]+\\)" "\\([^()]+\\)")
361                          "\\'"))
362          pattern)
363      (if (string-match regexp (setq pattern (car value)))
364          (list (cons (match-string 1 pattern) (match-string 2 pattern))
365                (= (nth 2 value) 2)
366                (nth 3 value))
367        value))))
368
369 (defcustom gnus-emphasis-alist
370   (let ((types
371          '(("\\*" "\\*" bold nil 2)
372            ("_" "_" underline)
373            ("/" "/" italic)
374            ("_/" "/_" underline-italic)
375            ("_\\*" "\\*_" underline-bold)
376            ("\\*/" "/\\*" bold-italic)
377            ("_\\*/" "/\\*_" underline-bold-italic))))
378     (nconc
379      (gnus-emphasis-custom-with-format
380       (mapcar (lambda (spec)
381                 (list (format format (car spec) (cadr spec))
382                       (or (nth 3 spec) 2)
383                       (or (nth 4 spec) 3)
384                       (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
385               types))
386      '(;; I've never seen anyone use this strikethru convention whereas I've
387        ;; several times seen it triggered by normal text.  --Stef
388        ;; Miles suggests that this form is sometimes used but for italics,
389        ;; so maybe we should map it to `italic'.
390        ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391        ;; 2 3 gnus-emphasis-strikethru)
392        ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393         2 3 gnus-emphasis-underline))))
394   "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
396
397   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
398
399 The first element is a regular expression to be matched.  The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word.  The third is a number that says what
402 regexp grouping should be displayed and highlighted.  The fourth
403 is the face used for highlighting."
404   :type
405   '(repeat
406     (menu-choice
407      :format "%[Customizing Style%]\n%v"
408      :indent 2
409      (group :tag "Default"
410             :value ("" 0 0 default)
411             :value-create
412             (lambda (widget)
413               (let ((value (widget-get
414                             (cadr (widget-get (widget-get widget :parent)
415                                               :args))
416                             :value)))
417                 (if (not (eq (nth 2 value) 'default))
418                     (widget-put
419                      widget
420                      :value
421                      (gnus-emphasis-custom-value-to-external value))))
422               (widget-group-value-create widget))
423             regexp
424             (integer :format "Match group: %v")
425             (integer :format "Emphasize group: %v")
426             face)
427      (group :tag "Simple"
428             :value (("_" . "_") nil default)
429             (cons :format "%v"
430                   (regexp :format "Start regexp: %v")
431                   (regexp :format "End regexp: %v"))
432             (boolean :format "Show start and end patterns: %[%v%]\n"
433                      :on " On " :off " Off ")
434             face)))
435   :get (lambda (symbol)
436          (mapcar 'gnus-emphasis-custom-value-to-internal
437                  (default-value symbol)))
438   :set (lambda (symbol value)
439          (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
440                                      value)))
441   :group 'gnus-article-emphasis)
442
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444   "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
448   :version "21.1"
449   :group 'gnus-article-emphasis
450   :type 'regexp)
451
452 (defface gnus-emphasis-bold '((t (:bold t)))
453   "Face used for displaying strong emphasized text (*word*)."
454   :group 'gnus-article-emphasis)
455
456 (defface gnus-emphasis-italic '((t (:italic t)))
457   "Face used for displaying italic emphasized text (/word/)."
458   :group 'gnus-article-emphasis)
459
460 (defface gnus-emphasis-underline '((t (:underline t)))
461   "Face used for displaying underlined emphasized text (_word_)."
462   :group 'gnus-article-emphasis)
463
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465   "Face used for displaying underlined bold emphasized text (_*word*_)."
466   :group 'gnus-article-emphasis)
467
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469   "Face used for displaying underlined italic emphasized text (_/word/_)."
470   :group 'gnus-article-emphasis)
471
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473   "Face used for displaying bold italic emphasized text (/*word*/)."
474   :group 'gnus-article-emphasis)
475
476 (defface gnus-emphasis-underline-bold-italic
477   '((t (:bold t :italic t :underline t)))
478   "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480   :group 'gnus-article-emphasis)
481
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483                                       '((t (:strikethru t)))
484                                     '((t (:strike-through t))))
485   "Face used for displaying strike-through text (-word-)."
486   :group 'gnus-article-emphasis)
487
488 (defface gnus-emphasis-highlight-words
489   '((t (:background "black" :foreground "yellow")))
490   "Face used for displaying highlighted words."
491   :group 'gnus-article-emphasis)
492
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494   "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
496
497 The variable can also be function, which should return a complete Date
498 header.  The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500   :type '(choice string function)
501   :link '(custom-manual "(gnus)Article Date")
502   :group 'gnus-article-washing)
503
504 (defcustom gnus-save-all-headers t
505   "*If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
508 might have."
509   :group 'gnus-article-saving
510   :type 'boolean)
511
512 (defcustom gnus-prompt-before-saving 'always
513   "*This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files.  If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles.  If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520   :group 'gnus-article-saving
521   :type '(choice (item always)
522                  (item :tag "never" nil)
523                  (sexp :tag "once" :format "%t\n" :value t)))
524
525 (defcustom gnus-saved-headers gnus-visible-headers
526   "Headers to keep if `gnus-save-all-headers' is nil.
527 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528 If that variable is nil, however, all headers that match this regexp
529 will be kept while the rest will be deleted before saving.  This and
530 `gnus-save-all-headers' will be overridden by the `:headers' property
531 that the symbol of the saver function, which is specified by
532 `gnus-default-article-saver', might have."
533   :group 'gnus-article-saving
534   :type 'regexp)
535
536 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
537 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
538   "A function to save articles in your favourite format.
539 The function will be called by way of the `gnus-summary-save-article'
540 command, and friends such as `gnus-summary-save-article-rmail'.
541
542 Gnus provides the following functions:
543
544 * gnus-summary-save-in-rmail (Rmail format)
545 * gnus-summary-save-in-mail (Unix mail format)
546 * gnus-summary-save-in-folder (MH folder)
547 * gnus-summary-save-in-file (article format)
548 * gnus-summary-save-body-in-file (article body)
549 * gnus-summary-save-in-vm (use VM's folder format)
550 * gnus-summary-write-to-file (article format -- overwrite)
551 * gnus-summary-write-body-to-file (article body -- overwrite)
552 * gnus-summary-save-in-pipe (article format)
553
554 The symbol of each function may have the following properties:
555
556 * :decode
557 The value non-nil means save decoded articles.  This is meaningful
558 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
559 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
560 `gnus-summary-save-in-pipe'.
561
562 * :function
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file.  This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file.  This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
568
569 * :headers
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved.  If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574   :group 'gnus-article-saving
575   :type '(radio (function-item gnus-summary-save-in-rmail)
576                 (function-item gnus-summary-save-in-mail)
577                 (function-item gnus-summary-save-in-folder)
578                 (function-item gnus-summary-save-in-file)
579                 (function-item gnus-summary-save-body-in-file)
580                 (function-item gnus-summary-save-in-vm)
581                 (function-item gnus-summary-write-to-file)
582                 (function-item gnus-summary-write-body-to-file)
583                 (function-item gnus-summary-save-in-pipe)
584                 (function)))
585
586 (defcustom gnus-article-save-coding-system
587   (or (and (mm-coding-system-p 'utf-8) 'utf-8)
588       (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
589       (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
590       (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
591   "Coding system used to save decoded articles to a file.
592
593 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
594 which can safely encode any characters in text.  This is used by the
595 commands including:
596
597 * gnus-summary-save-article-file
598 * gnus-summary-save-article-body-file
599 * gnus-summary-write-article-file
600 * gnus-summary-write-article-body-file
601
602 and the functions to which you may set `gnus-default-article-saver':
603
604 * gnus-summary-save-in-file
605 * gnus-summary-save-body-in-file
606 * gnus-summary-write-to-file
607 * gnus-summary-write-body-to-file
608
609 Those commands and functions save just text displayed in the article
610 buffer to a file if the value of this variable is non-nil.  Note that
611 buttonized MIME parts will be lost in a saved file in that case.
612 Otherwise, raw articles will be saved."
613   :group 'gnus-article-saving
614   :type `(choice
615           :format "%{%t%}:\n %[Value Menu%] %v"
616           (const :tag "Save raw articles" nil)
617           ,@(delq nil
618                   (mapcar
619                    (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
620                    '((const :tag "UTF-8" utf-8)
621                      (const :tag "iso-2022-7bit" iso-2022-7bit)
622                      (const :tag "Emacs internal" emacs-mule)
623                      (const :tag "escape-quoted" escape-quoted))))
624           (symbol :tag "Coding system")))
625
626 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
627   "A function generating a file name to save articles in Rmail format.
628 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
629   :group 'gnus-article-saving
630   :type 'function)
631
632 (defcustom gnus-mail-save-name 'gnus-plain-save-name
633   "A function generating a file name to save articles in Unix mail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635   :group 'gnus-article-saving
636   :type 'function)
637
638 (defcustom gnus-folder-save-name 'gnus-folder-save-name
639   "A function generating a file name to save articles in MH folder.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
641   :group 'gnus-article-saving
642   :type 'function)
643
644 (defcustom gnus-file-save-name 'gnus-numeric-save-name
645   "A function generating a file name to save articles in article format.
646 The function is called with NEWSGROUP, HEADERS, and optional
647 LAST-FILE."
648   :group 'gnus-article-saving
649   :type 'function)
650
651 (defcustom gnus-split-methods
652   '((gnus-article-archive-name)
653     (gnus-article-nndoc-name))
654   "*Variable used to suggest where articles are to be saved.
655 For instance, if you would like to save articles related to Gnus in
656 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
657 you could set this variable to something like:
658
659  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
660    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
661
662 This variable is an alist where the key is the match and the
663 value is a list of possible files to save in if the match is
664 non-nil.
665
666 If the match is a string, it is used as a regexp match on the
667 article.  If the match is a symbol, that symbol will be funcalled
668 from the buffer of the article to be saved with the newsgroup as the
669 parameter.  If it is a list, it will be evaled in the same buffer.
670
671 If this form or function returns a string, this string will be used as a
672 possible file name; and if it returns a non-nil list, that list will be
673 used as possible file names."
674   :group 'gnus-article-saving
675   :type '(repeat (choice (list :value (fun) function)
676                          (cons :value ("" "") regexp (repeat string))
677                          (sexp :value nil))))
678
679 (defcustom gnus-page-delimiter "^\^L"
680   "*Regexp describing what to use as article page delimiters.
681 The default value is \"^\^L\", which is a form linefeed at the
682 beginning of a line."
683   :type 'regexp
684   :group 'gnus-article-various)
685
686 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
687   "*The format specification for the article mode line.
688 See `gnus-summary-mode-line-format' for a closer description.
689
690 The following additional specs are available:
691
692 %w  The article washing status.
693 %m  The number of MIME parts in the article."
694   :type 'string
695   :group 'gnus-article-various)
696
697 (defcustom gnus-article-mode-hook nil
698   "*A hook for Gnus article mode."
699   :type 'hook
700   :group 'gnus-article-various)
701
702 (when (featurep 'xemacs)
703   ;; Extracted from gnus-xmas-define in order to preserve user settings
704   (when (fboundp 'turn-off-scroll-in-place)
705     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
706   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
707   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
708
709 (defcustom gnus-article-menu-hook nil
710   "*Hook run after the creation of the article mode menu."
711   :type 'hook
712   :group 'gnus-article-various)
713
714 (defcustom gnus-article-prepare-hook nil
715   "*A hook called after an article has been prepared in the article buffer."
716   :type 'hook
717   :group 'gnus-article-various)
718
719 (defcustom gnus-copy-article-ignored-headers nil
720   "List of headers to be removed when copying an article.
721 Each element is a regular expression."
722   :version "23.1" ;; No Gnus
723   :type '(repeat regexp)
724   :group 'gnus-article-various)
725
726 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
727                         "Gnus 5.10 (Emacs 22.1)")
728
729 (defface gnus-button
730   '((t (:weight bold)))
731   "Face used for highlighting a button in the article buffer."
732   :group 'gnus-article-buttons)
733
734 (defcustom gnus-article-button-face 'gnus-button
735   "Face used for highlighting buttons in the article buffer.
736
737 An article button is a piece of text that you can activate by pressing
738 `RET' or `mouse-2' above it."
739   :type 'face
740   :group 'gnus-article-buttons)
741
742 (defcustom gnus-article-mouse-face 'highlight
743   "Face used for mouse highlighting in the article buffer.
744
745 Article buttons will be displayed in this face when the cursor is
746 above them."
747   :type 'face
748   :group 'gnus-article-buttons)
749
750 (defcustom gnus-signature-face 'gnus-signature
751   "Face used for highlighting a signature in the article buffer.
752 Obsolete; use the face `gnus-signature' for customizations instead."
753   :type 'face
754   :group 'gnus-article-highlight
755   :group 'gnus-article-signature)
756
757 (defface gnus-signature
758   '((t
759      (:italic t)))
760   "Face used for highlighting a signature in the article buffer."
761   :group 'gnus-article-highlight
762   :group 'gnus-article-signature)
763 ;; backward-compatibility alias
764 (put 'gnus-signature-face 'face-alias 'gnus-signature)
765 (put 'gnus-signature-face 'obsolete-face "22.1")
766
767 (defface gnus-header-from
768   '((((class color)
769       (background dark))
770      (:foreground "PaleGreen1"))
771     (((class color)
772       (background light))
773      (:foreground "red3"))
774     (t
775      (:italic t)))
776   "Face used for displaying from headers."
777   :group 'gnus-article-headers
778   :group 'gnus-article-highlight)
779 ;; backward-compatibility alias
780 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
781 (put 'gnus-header-from-face 'obsolete-face "22.1")
782
783 (defface gnus-header-subject
784   '((((class color)
785       (background dark))
786      (:foreground "SeaGreen1"))
787     (((class color)
788       (background light))
789      (:foreground "red4"))
790     (t
791      (:bold t :italic t)))
792   "Face used for displaying subject headers."
793   :group 'gnus-article-headers
794   :group 'gnus-article-highlight)
795 ;; backward-compatibility alias
796 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
797 (put 'gnus-header-subject-face 'obsolete-face "22.1")
798
799 (defface gnus-header-newsgroups
800   '((((class color)
801       (background dark))
802      (:foreground "yellow" :italic t))
803     (((class color)
804       (background light))
805      (:foreground "MidnightBlue" :italic t))
806     (t
807      (:italic t)))
808   "Face used for displaying newsgroups headers.
809 In the default setup this face is only used for crossposted
810 articles."
811   :group 'gnus-article-headers
812   :group 'gnus-article-highlight)
813 ;; backward-compatibility alias
814 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
815 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
816
817 (defface gnus-header-name
818   '((((class color)
819       (background dark))
820      (:foreground "SpringGreen2"))
821     (((class color)
822       (background light))
823      (:foreground "maroon"))
824     (t
825      (:bold t)))
826   "Face used for displaying header names."
827   :group 'gnus-article-headers
828   :group 'gnus-article-highlight)
829 ;; backward-compatibility alias
830 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
831 (put 'gnus-header-name-face 'obsolete-face "22.1")
832
833 (defface gnus-header-content
834   '((((class color)
835       (background dark))
836      (:foreground "SpringGreen1" :italic t))
837     (((class color)
838       (background light))
839      (:foreground "indianred4" :italic t))
840     (t
841      (:italic t)))  "Face used for displaying header content."
842   :group 'gnus-article-headers
843   :group 'gnus-article-highlight)
844 ;; backward-compatibility alias
845 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
846 (put 'gnus-header-content-face 'obsolete-face "22.1")
847
848 (defcustom gnus-header-face-alist
849   '(("From" nil gnus-header-from)
850     ("Subject" nil gnus-header-subject)
851     ("Newsgroups:.*," nil gnus-header-newsgroups)
852     ("" gnus-header-name gnus-header-content))
853   "*Controls highlighting of article headers.
854
855 An alist of the form (HEADER NAME CONTENT).
856
857 HEADER is a regular expression which should match the name of a
858 header and NAME and CONTENT are either face names or nil.
859
860 The name of each header field will be displayed using the face
861 specified by the first element in the list where HEADER matches
862 the header name and NAME is non-nil.  Similarly, the content will
863 be displayed by the first non-nil matching CONTENT face."
864   :group 'gnus-article-headers
865   :group 'gnus-article-highlight
866   :type '(repeat (list (regexp :tag "Header")
867                        (choice :tag "Name"
868                                (item :tag "skip" nil)
869                                (face :value default))
870                        (choice :tag "Content"
871                                (item :tag "skip" nil)
872                                (face :value default)))))
873
874 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
875                                           '((xface . (:face gnus-x-face)))
876                                         '((pbm . (:face gnus-x-face))
877                                           (png . nil)))
878   "Alist of image types and properties applied to Face and X-Face images.
879 Here are examples:
880
881 ;; Specify the altitude of Face images in the From header.
882 \(setq gnus-face-properties-alist
883       '((pbm . (:face gnus-x-face :ascent 80))
884         (png . (:ascent 80))))
885
886 ;; Show Face images as pressed buttons.
887 \(setq gnus-face-properties-alist
888       '((pbm . (:face gnus-x-face :relief -2))
889         (png . (:relief -2))))
890
891 See the manual for the valid properties for various image types.
892 Currently, `pbm' is used for X-Face images and `png' is used for Face
893 images in Emacs.  Only the `:face' property is effective on the `xface'
894 image type in XEmacs if it is built with the libcompface library."
895   :version "23.1" ;; No Gnus
896   :group 'gnus-article-headers
897   :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
898
899 (defcustom gnus-article-decode-hook
900   '(article-decode-charset article-decode-encoded-words
901                            article-decode-group-name article-decode-idna-rhs)
902   "*Hook run to decode charsets in articles."
903   :group 'gnus-article-headers
904   :type 'hook)
905
906 (defcustom gnus-display-mime-function 'gnus-display-mime
907   "Function to display MIME articles."
908   :group 'gnus-article-mime
909   :type 'function)
910
911 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
912   "Function used to decode headers.")
913
914 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
915   "Function used to decode addresses.")
916
917 (defvar gnus-article-dumbquotes-map
918   '((?\200 "EUR")
919     (?\202 ",")
920     (?\203 "f")
921     (?\204 ",,")
922     (?\205 "...")
923     (?\213 "<")
924     (?\214 "OE")
925     (?\221 "`")
926     (?\222 "'")
927     (?\223 "``")
928     (?\224 "\"")
929     (?\225 "*")
930     (?\226 "-")
931     (?\227 "--")
932     (?\230 "~")
933     (?\231 "(TM)")
934     (?\233 ">")
935     (?\234 "oe")
936     (?\264 "'"))
937   "Table for MS-to-Latin1 translation.")
938
939 (defcustom gnus-ignored-mime-types nil
940   "List of MIME types that should be ignored by Gnus."
941   :version "21.1"
942   :group 'gnus-article-mime
943   :type '(repeat regexp))
944
945 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
946   "List of MIME types that should not be given buttons when rendered inline.
947 See also `gnus-buttonized-mime-types' which may override this variable.
948 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
949   :version "21.1"
950   :group 'gnus-article-mime
951   :type '(repeat regexp))
952
953 (defcustom gnus-buttonized-mime-types nil
954   "List of MIME types that should be given buttons when rendered inline.
955 If set, this variable overrides `gnus-unbuttonized-mime-types'.
956 To see e.g. security buttons you could set this to
957 `(\"multipart/signed\")'.  You could also add \"multipart/alternative\" to
958 this list to display radio buttons that allow you to choose one of two
959 media types those mails include.  See also `mm-discouraged-alternatives'.
960 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
961   :version "22.1"
962   :group 'gnus-article-mime
963   :type '(repeat regexp))
964
965 (defcustom gnus-inhibit-mime-unbuttonizing nil
966   "If non-nil, all MIME parts get buttons.
967 When nil (the default value), then some MIME parts do not get buttons,
968 as described by the variables `gnus-buttonized-mime-types' and
969 `gnus-unbuttonized-mime-types'."
970   :version "22.1"
971   :group 'gnus-article-mime
972   :type 'boolean)
973
974 (defcustom gnus-body-boundary-delimiter "_"
975   "String used to delimit header and body.
976 This variable is used by `gnus-article-treat-body-boundary' which can
977 be controlled by `gnus-treat-body-boundary'."
978   :version "22.1"
979   :group 'gnus-article-various
980   :type '(choice (item :tag "None" :value nil)
981                  string))
982
983 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
984                                   "/usr/share/picons")
985   "Defines the location of the faces database.
986 For information on obtaining this database of pretty pictures, please
987 see http://www.cs.indiana.edu/picons/ftp/index.html"
988   :version "22.1"
989   :type '(repeat directory)
990   :link '(url-link :tag "download"
991                    "http://www.cs.indiana.edu/picons/ftp/index.html")
992   :link '(custom-manual "(gnus)Picons")
993   :group 'gnus-picon)
994
995 (defun gnus-picons-installed-p ()
996   "Say whether picons are installed on your machine."
997   (let ((installed nil))
998     (dolist (database gnus-picon-databases)
999       (when (file-exists-p database)
1000         (setq installed t)))
1001     installed))
1002
1003 (defcustom gnus-article-mime-part-function nil
1004   "Function called with a MIME handle as the argument.
1005 This is meant for people who want to do something automatic based
1006 on parts -- for instance, adding Vcard info to a database."
1007   :group 'gnus-article-mime
1008   :type '(choice (const nil)
1009                  function))
1010
1011 (defcustom gnus-mime-multipart-functions nil
1012   "An alist of MIME types to functions to display them."
1013   :version "21.1"
1014   :group 'gnus-article-mime
1015   :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1016
1017 (defcustom gnus-article-date-lapsed-new-header nil
1018   "Whether the X-Sent and Date headers can coexist.
1019 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1020 either replace the old \"Date:\" header (if this variable is nil), or
1021 be added below it (otherwise)."
1022   :version "21.1"
1023   :group 'gnus-article-headers
1024   :type 'boolean)
1025
1026 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1027   "Function called with a MIME handle as the argument.
1028 This is meant for people who want to view first matched part.
1029 For `undisplayed-alternative' (default), the first undisplayed
1030 part or alternative part is used.  For `undisplayed', the first
1031 undisplayed part is used.  For a function, the first part which
1032 the function return t is used.  For nil, the first part is
1033 used."
1034   :version "21.1"
1035   :group 'gnus-article-mime
1036   :type '(choice
1037           (item :tag "first" :value nil)
1038           (item :tag "undisplayed" :value undisplayed)
1039           (item :tag "undisplayed or alternative"
1040                 :value undisplayed-alternative)
1041           (function)))
1042
1043 (defcustom gnus-mime-action-alist
1044   '(("save to file" . gnus-mime-save-part)
1045     ("save and strip" . gnus-mime-save-part-and-strip)
1046     ("replace with file" . gnus-mime-replace-part)
1047     ("delete part" . gnus-mime-delete-part)
1048     ("display as text" . gnus-mime-inline-part)
1049     ("view the part" . gnus-mime-view-part)
1050     ("pipe to command" . gnus-mime-pipe-part)
1051     ("toggle display" . gnus-article-press-button)
1052     ("toggle display" . gnus-article-view-part-as-charset)
1053     ("view as type" . gnus-mime-view-part-as-type)
1054     ("view internally" . gnus-mime-view-part-internally)
1055     ("view externally" . gnus-mime-view-part-externally))
1056   "An alist of actions that run on the MIME attachment."
1057   :group 'gnus-article-mime
1058   :type '(repeat (cons (string :tag "name")
1059                        (function))))
1060
1061 (defcustom gnus-auto-select-part 1
1062   "Advance to next MIME part when deleting or stripping parts.
1063
1064 When 0, point will be placed on the same part as before.  When
1065 positive (negative), move point forward (backwards) this many
1066 parts.  When nil, redisplay article."
1067   :version "23.1" ;; No Gnus
1068   :group 'gnus-article-mime
1069   :type '(choice (const nil :tag "Redisplay article.")
1070                  (const 1 :tag "Next part.")
1071                  (const 0 :tag "Current part.")
1072                  integer))
1073
1074 ;;;
1075 ;;; The treatment variables
1076 ;;;
1077
1078 (defvar gnus-part-display-hook nil
1079   "Hook called on parts that are to receive treatment.")
1080
1081 (defvar gnus-article-treat-custom
1082   '(choice (const :tag "Off" nil)
1083            (const :tag "On" t)
1084            (const :tag "Header" head)
1085            (const :tag "First" first)
1086            (const :tag "Last" last)
1087            (integer :tag "Less")
1088            (repeat :tag "Groups" regexp)
1089            (sexp :tag "Predicate")))
1090
1091 (defvar gnus-article-treat-head-custom
1092   '(choice (const :tag "Off" nil)
1093            (const :tag "Header" head)))
1094
1095 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1096                                    "text/x-patch")
1097   "Parts to treat.")
1098
1099 (defvar gnus-inhibit-treatment nil
1100   "Whether to inhibit treatment.")
1101
1102 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1103   "Highlight the signature.
1104 Valid values are nil, t, `head', `first', `last', an integer or a
1105 predicate.  See Info node `(gnus)Customizing Articles'."
1106   :group 'gnus-article-treat
1107   :link '(custom-manual "(gnus)Customizing Articles")
1108   :type gnus-article-treat-custom)
1109 (put 'gnus-treat-highlight-signature 'highlight t)
1110
1111 (defcustom gnus-treat-buttonize 100000
1112   "Add buttons.
1113 Valid values are nil, t, `head', `first', `last', an integer or a
1114 predicate.  See Info node `(gnus)Customizing Articles'."
1115   :group 'gnus-article-treat
1116   :link '(custom-manual "(gnus)Customizing Articles")
1117   :type gnus-article-treat-custom)
1118 (put 'gnus-treat-buttonize 'highlight t)
1119
1120 (defcustom gnus-treat-buttonize-head 'head
1121   "Add buttons to the head.
1122 Valid values are nil, t, `head', `first', `last', an integer or a
1123 predicate.  See Info node `(gnus)Customizing Articles'."
1124   :group 'gnus-article-treat
1125   :link '(custom-manual "(gnus)Customizing Articles")
1126   :type gnus-article-treat-head-custom)
1127 (put 'gnus-treat-buttonize-head 'highlight t)
1128
1129 (defcustom gnus-treat-emphasize 50000
1130   "Emphasize text.
1131 Valid values are nil, t, `head', `first', `last', an integer or a
1132 predicate.  See Info node `(gnus)Customizing Articles'."
1133   :group 'gnus-article-treat
1134   :link '(custom-manual "(gnus)Customizing Articles")
1135   :type gnus-article-treat-custom)
1136 (put 'gnus-treat-emphasize 'highlight t)
1137
1138 (defcustom gnus-treat-strip-cr nil
1139   "Remove carriage returns.
1140 Valid values are nil, t, `head', `first', `last', an integer or a
1141 predicate.  See Info node `(gnus)Customizing Articles'."
1142   :version "22.1"
1143   :group 'gnus-article-treat
1144   :link '(custom-manual "(gnus)Customizing Articles")
1145   :type gnus-article-treat-custom)
1146
1147 (defcustom gnus-treat-unsplit-urls nil
1148   "Remove newlines from within URLs.
1149 Valid values are nil, t, `head', `first', `last', an integer or a
1150 predicate.  See Info node `(gnus)Customizing Articles'."
1151   :version "22.1"
1152   :group 'gnus-article-treat
1153   :link '(custom-manual "(gnus)Customizing Articles")
1154   :type gnus-article-treat-custom)
1155
1156 (defcustom gnus-treat-leading-whitespace nil
1157   "Remove leading whitespace in headers.
1158 Valid values are nil, t, `head', `first', `last', an integer or a
1159 predicate.  See Info node `(gnus)Customizing Articles'."
1160   :version "22.1"
1161   :group 'gnus-article-treat
1162   :link '(custom-manual "(gnus)Customizing Articles")
1163   :type gnus-article-treat-custom)
1164
1165 (defcustom gnus-treat-hide-headers 'head
1166   "Hide headers.
1167 Valid values are nil, t, `head', `first', `last', an integer or a
1168 predicate.  See Info node `(gnus)Customizing Articles'."
1169   :group 'gnus-article-treat
1170   :link '(custom-manual "(gnus)Customizing Articles")
1171   :type gnus-article-treat-head-custom)
1172
1173 (defcustom gnus-treat-hide-boring-headers nil
1174   "Hide boring headers.
1175 Valid values are nil, t, `head', `first', `last', an integer or a
1176 predicate.  See Info node `(gnus)Customizing Articles'."
1177   :group 'gnus-article-treat
1178   :link '(custom-manual "(gnus)Customizing Articles")
1179   :type gnus-article-treat-head-custom)
1180
1181 (defcustom gnus-treat-hide-signature nil
1182   "Hide the signature.
1183 Valid values are nil, t, `head', `first', `last', an integer or a
1184 predicate.  See Info node `(gnus)Customizing Articles'."
1185   :group 'gnus-article-treat
1186   :link '(custom-manual "(gnus)Customizing Articles")
1187   :type gnus-article-treat-custom)
1188
1189 (defcustom gnus-treat-fill-article nil
1190   "Fill the article.
1191 Valid values are nil, t, `head', `first', `last', an integer or a
1192 predicate.  See Info node `(gnus)Customizing Articles'."
1193   :group 'gnus-article-treat
1194   :link '(custom-manual "(gnus)Customizing Articles")
1195   :type gnus-article-treat-custom)
1196
1197 (defcustom gnus-treat-hide-citation nil
1198   "Hide cited text.
1199 Valid values are nil, t, `head', `first', `last', an integer or a
1200 predicate.  See Info node `(gnus)Customizing Articles'."
1201   :group 'gnus-article-treat
1202   :link '(custom-manual "(gnus)Customizing Articles")
1203   :type gnus-article-treat-custom)
1204
1205 (defcustom gnus-treat-hide-citation-maybe nil
1206   "Hide cited text.
1207 Valid values are nil, t, `head', `first', `last', an integer or a
1208 predicate.  See Info node `(gnus)Customizing Articles'."
1209   :group 'gnus-article-treat
1210   :link '(custom-manual "(gnus)Customizing Articles")
1211   :type gnus-article-treat-custom)
1212
1213 (defcustom gnus-treat-strip-list-identifiers 'head
1214   "Strip list identifiers from `gnus-list-identifiers`.
1215 Valid values are nil, t, `head', `first', `last', an integer or a
1216 predicate.  See Info node `(gnus)Customizing Articles'."
1217   :version "21.1"
1218   :group 'gnus-article-treat
1219   :link '(custom-manual "(gnus)Customizing Articles")
1220   :type gnus-article-treat-custom)
1221
1222 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1223                         "Gnus 5.10 (Emacs 22.1)")
1224
1225 (defcustom gnus-treat-strip-pem nil
1226   "Strip PEM signatures.
1227 Valid values are nil, t, `head', `first', `last', an integer or a
1228 predicate.  See Info node `(gnus)Customizing Articles'."
1229   :group 'gnus-article-treat
1230   :link '(custom-manual "(gnus)Customizing Articles")
1231   :type gnus-article-treat-custom)
1232
1233 (defcustom gnus-treat-strip-banner t
1234   "Strip banners from articles.
1235 The banner to be stripped is specified in the `banner' group parameter.
1236 Valid values are nil, t, `head', `first', `last', an integer or a
1237 predicate.  See Info node `(gnus)Customizing Articles'."
1238   :group 'gnus-article-treat
1239   :link '(custom-manual "(gnus)Customizing Articles")
1240   :type gnus-article-treat-custom)
1241
1242 (defcustom gnus-treat-highlight-headers 'head
1243   "Highlight the headers.
1244 Valid values are nil, t, `head', `first', `last', an integer or a
1245 predicate.  See Info node `(gnus)Customizing Articles'."
1246   :group 'gnus-article-treat
1247   :link '(custom-manual "(gnus)Customizing Articles")
1248   :type gnus-article-treat-head-custom)
1249 (put 'gnus-treat-highlight-headers 'highlight t)
1250
1251 (defcustom gnus-treat-highlight-citation t
1252   "Highlight cited text.
1253 Valid values are nil, t, `head', `first', `last', an integer or a
1254 predicate.  See Info node `(gnus)Customizing Articles'."
1255   :group 'gnus-article-treat
1256   :link '(custom-manual "(gnus)Customizing Articles")
1257   :type gnus-article-treat-custom)
1258 (put 'gnus-treat-highlight-citation 'highlight t)
1259
1260 (defcustom gnus-treat-date-ut nil
1261   "Display the Date in UT (GMT).
1262 Valid values are nil, t, `head', `first', `last', an integer or a
1263 predicate.  See Info node `(gnus)Customizing Articles'."
1264   :group 'gnus-article-treat
1265   :link '(custom-manual "(gnus)Customizing Articles")
1266   :type gnus-article-treat-head-custom)
1267
1268 (defcustom gnus-treat-date-local nil
1269   "Display the Date in the local timezone.
1270 Valid values are nil, t, `head', `first', `last', an integer or a
1271 predicate.  See Info node `(gnus)Customizing Articles'."
1272   :group 'gnus-article-treat
1273   :link '(custom-manual "(gnus)Customizing Articles")
1274   :type gnus-article-treat-head-custom)
1275
1276 (defcustom gnus-treat-date-english nil
1277   "Display the Date in a format that can be read aloud in English.
1278 Valid values are nil, t, `head', `first', `last', an integer or a
1279 predicate.  See Info node `(gnus)Customizing Articles'."
1280   :version "22.1"
1281   :group 'gnus-article-treat
1282   :link '(custom-manual "(gnus)Customizing Articles")
1283   :type gnus-article-treat-head-custom)
1284
1285 (defcustom gnus-treat-date-lapsed nil
1286   "Display the Date header in a way that says how much time has elapsed.
1287 Valid values are nil, t, `head', `first', `last', an integer or a
1288 predicate.  See Info node `(gnus)Customizing Articles'."
1289   :group 'gnus-article-treat
1290   :link '(custom-manual "(gnus)Customizing Articles")
1291   :type gnus-article-treat-head-custom)
1292
1293 (defcustom gnus-treat-date-original nil
1294   "Display the date in the original timezone.
1295 Valid values are nil, t, `head', `first', `last', an integer or a
1296 predicate.  See Info node `(gnus)Customizing Articles'."
1297   :group 'gnus-article-treat
1298   :link '(custom-manual "(gnus)Customizing Articles")
1299   :type gnus-article-treat-head-custom)
1300
1301 (defcustom gnus-treat-date-iso8601 nil
1302   "Display the date in the ISO8601 format.
1303 Valid values are nil, t, `head', `first', `last', an integer or a
1304 predicate.  See Info node `(gnus)Customizing Articles'."
1305   :version "21.1"
1306   :group 'gnus-article-treat
1307   :link '(custom-manual "(gnus)Customizing Articles")
1308   :type gnus-article-treat-head-custom)
1309
1310 (defcustom gnus-treat-date-user-defined nil
1311   "Display the date in a user-defined format.
1312 The format is defined by the `gnus-article-time-format' variable.
1313 Valid values are nil, t, `head', `first', `last', an integer or a
1314 predicate.  See Info node `(gnus)Customizing Articles'."
1315   :group 'gnus-article-treat
1316   :link '(custom-manual "(gnus)Customizing Articles")
1317   :type gnus-article-treat-head-custom)
1318
1319 (defcustom gnus-treat-strip-headers-in-body t
1320   "Strip the X-No-Archive header line from the beginning of the body.
1321 Valid values are nil, t, `head', `first', `last', an integer or a
1322 predicate.  See Info node `(gnus)Customizing Articles'."
1323   :version "21.1"
1324   :group 'gnus-article-treat
1325   :link '(custom-manual "(gnus)Customizing Articles")
1326   :type gnus-article-treat-custom)
1327
1328 (defcustom gnus-treat-strip-trailing-blank-lines nil
1329   "Strip trailing blank lines.
1330 Valid values are nil, t, `head', `first', `last', an integer or a
1331 predicate.  See Info node `(gnus)Customizing Articles'.
1332
1333 When set to t, it also strips trailing blanks in all MIME parts.
1334 Consider to use `last' instead."
1335   :group 'gnus-article-treat
1336   :link '(custom-manual "(gnus)Customizing Articles")
1337   :type gnus-article-treat-custom)
1338
1339 (defcustom gnus-treat-strip-leading-blank-lines nil
1340   "Strip leading blank lines.
1341 Valid values are nil, t, `head', `first', `last', an integer or a
1342 predicate.  See Info node `(gnus)Customizing Articles'.
1343
1344 When set to t, it also strips trailing blanks in all MIME parts."
1345   :group 'gnus-article-treat
1346   :link '(custom-manual "(gnus)Customizing Articles")
1347   :type gnus-article-treat-custom)
1348
1349 (defcustom gnus-treat-strip-multiple-blank-lines nil
1350   "Strip multiple blank lines.
1351 Valid values are nil, t, `head', `first', `last', an integer or a
1352 predicate.  See Info node `(gnus)Customizing Articles'."
1353   :group 'gnus-article-treat
1354   :link '(custom-manual "(gnus)Customizing Articles")
1355   :type gnus-article-treat-custom)
1356
1357 (defcustom gnus-treat-unfold-headers 'head
1358   "Unfold folded header lines.
1359 Valid values are nil, t, `head', `first', `last', an integer or a
1360 predicate.  See Info node `(gnus)Customizing Articles'."
1361   :version "22.1"
1362   :group 'gnus-article-treat
1363   :link '(custom-manual "(gnus)Customizing Articles")
1364   :type gnus-article-treat-custom)
1365
1366 (defcustom gnus-article-unfold-long-headers nil
1367   "If non-nil, allow unfolding headers even if the header is long.
1368 If it is a regexp, only long headers matching this regexp are unfolded.
1369 If it is t, all long headers are unfolded.
1370
1371 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1372   :version "23.1" ;; No Gnus
1373   :group 'gnus-article-treat
1374   :type '(choice (const nil)
1375                  (const :tag "all" t)
1376                  (regexp)))
1377
1378 (defcustom gnus-treat-fold-headers nil
1379   "Fold headers.
1380 Valid values are nil, t, `head', `first', `last', an integer or a
1381 predicate.  See Info node `(gnus)Customizing Articles'."
1382   :version "22.1"
1383   :group 'gnus-article-treat
1384   :link '(custom-manual "(gnus)Customizing Articles")
1385   :type gnus-article-treat-custom)
1386
1387 (defcustom gnus-treat-fold-newsgroups 'head
1388   "Fold the Newsgroups and Followup-To headers.
1389 Valid values are nil, t, `head', `first', `last', an integer or a
1390 predicate.  See Info node `(gnus)Customizing Articles'."
1391   :version "22.1"
1392   :group 'gnus-article-treat
1393   :link '(custom-manual "(gnus)Customizing Articles")
1394   :type gnus-article-treat-custom)
1395
1396 (defcustom gnus-treat-overstrike t
1397   "Treat overstrike highlighting.
1398 Valid values are nil, t, `head', `first', `last', an integer or a
1399 predicate.  See Info node `(gnus)Customizing Articles'."
1400   :group 'gnus-article-treat
1401   :link '(custom-manual "(gnus)Customizing Articles")
1402   :type gnus-article-treat-custom)
1403 (put 'gnus-treat-overstrike 'highlight t)
1404
1405 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1406   "Treat ANSI SGR control sequences.
1407 Valid values are nil, t, `head', `first', `last', an integer or a
1408 predicate.  See Info node `(gnus)Customizing Articles'."
1409   :group 'gnus-article-treat
1410   :link '(custom-manual "(gnus)Customizing Articles")
1411   :type gnus-article-treat-custom)
1412
1413 (make-obsolete-variable 'gnus-treat-display-xface
1414                         'gnus-treat-display-x-face "Emacs 22.1")
1415
1416 (defcustom gnus-treat-display-x-face
1417   (and (not noninteractive)
1418        (gnus-image-type-available-p 'xbm)
1419        (if (featurep 'xemacs)
1420            (featurep 'xface)
1421          (condition-case nil
1422              (and (string-match "^0x" (shell-command-to-string "uncompface"))
1423                   (executable-find "icontopbm"))
1424            ;; shell-command-to-string may signal an error, e.g. if
1425            ;; shell-file-name is not found.
1426            (error nil)))
1427        'head)
1428   "Display X-Face headers.
1429 Valid values are nil and `head'.
1430 See Info node `(gnus)Customizing Articles' and Info node
1431 `(gnus)X-Face' for details."
1432   :group 'gnus-article-treat
1433   :version "21.1"
1434   :link '(custom-manual "(gnus)Customizing Articles")
1435   :link '(custom-manual "(gnus)X-Face")
1436   :type gnus-article-treat-head-custom
1437   :set (lambda (symbol value)
1438          (set-default
1439           symbol
1440           (cond ((or (boundp symbol) (get symbol 'saved-value))
1441                  value)
1442                 ((boundp 'gnus-treat-display-xface)
1443                  (message "\
1444 ** gnus-treat-display-xface is an obsolete variable;\
1445  use gnus-treat-display-x-face instead")
1446                  (default-value 'gnus-treat-display-xface))
1447                 ((get 'gnus-treat-display-xface 'saved-value)
1448                  (message "\
1449 ** gnus-treat-display-xface is an obsolete variable;\
1450  use gnus-treat-display-x-face instead")
1451                  (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1452                 (t
1453                  value)))))
1454 (put 'gnus-treat-display-x-face 'highlight t)
1455
1456 (defcustom gnus-treat-display-face
1457   (and (not noninteractive)
1458        (gnus-image-type-available-p 'png)
1459        'head)
1460   "Display Face headers.
1461 Valid values are nil, t, `head', `first', `last', an integer or a
1462 predicate.  See Info node `(gnus)Customizing Articles' and Info
1463 node `(gnus)Face' for details."
1464   :group 'gnus-article-treat
1465   :version "22.1"
1466   :link '(custom-manual "(gnus)Customizing Articles")
1467   :link '(custom-manual "(gnus)X-Face")
1468   :type gnus-article-treat-head-custom)
1469 (put 'gnus-treat-display-face 'highlight t)
1470
1471 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1472   "Display smileys.
1473 Valid values are nil, t, `head', `first', `last', an integer or a
1474 predicate.  See Info node `(gnus)Customizing Articles' and Info
1475 node `(gnus)Smileys' for details."
1476   :group 'gnus-article-treat
1477   :version "21.1"
1478   :link '(custom-manual "(gnus)Customizing Articles")
1479   :link '(custom-manual "(gnus)Smileys")
1480   :type gnus-article-treat-custom)
1481 (put 'gnus-treat-display-smileys 'highlight t)
1482
1483 (defcustom gnus-treat-from-picon
1484   (if (and (gnus-image-type-available-p 'xpm)
1485            (gnus-picons-installed-p))
1486       'head nil)
1487   "Display picons in the From header.
1488 Valid values are nil, t, `head', `first', `last', an integer or a
1489 predicate.  See Info node `(gnus)Customizing Articles' and Info
1490 node `(gnus)Picons' for details."
1491   :version "22.1"
1492   :group 'gnus-article-treat
1493   :group 'gnus-picon
1494   :link '(custom-manual "(gnus)Customizing Articles")
1495   :link '(custom-manual "(gnus)Picons")
1496   :type gnus-article-treat-head-custom)
1497 (put 'gnus-treat-from-picon 'highlight t)
1498
1499 (defcustom gnus-treat-mail-picon
1500   (if (and (gnus-image-type-available-p 'xpm)
1501            (gnus-picons-installed-p))
1502       'head nil)
1503   "Display picons in To and Cc headers.
1504 Valid values are nil, t, `head', `first', `last', an integer or a
1505 predicate.  See Info node `(gnus)Customizing Articles' and Info
1506 node `(gnus)Picons' for details."
1507   :version "22.1"
1508   :group 'gnus-article-treat
1509   :group 'gnus-picon
1510   :link '(custom-manual "(gnus)Customizing Articles")
1511   :link '(custom-manual "(gnus)Picons")
1512   :type gnus-article-treat-head-custom)
1513 (put 'gnus-treat-mail-picon 'highlight t)
1514
1515 (defcustom gnus-treat-newsgroups-picon
1516   (if (and (gnus-image-type-available-p 'xpm)
1517            (gnus-picons-installed-p))
1518       'head nil)
1519   "Display picons in the Newsgroups and Followup-To headers.
1520 Valid values are nil, t, `head', `first', `last', an integer or a
1521 predicate.  See Info node `(gnus)Customizing Articles' and Info
1522 node `(gnus)Picons' for details."
1523   :version "22.1"
1524   :group 'gnus-article-treat
1525   :group 'gnus-picon
1526   :link '(custom-manual "(gnus)Customizing Articles")
1527   :link '(custom-manual "(gnus)Picons")
1528   :type gnus-article-treat-head-custom)
1529 (put 'gnus-treat-newsgroups-picon 'highlight t)
1530
1531 (defcustom gnus-treat-from-gravatar nil
1532   "Display gravatars in the From header.
1533 Valid values are nil, t, `head', `first', `last', an integer or a
1534 predicate.  See Info node `(gnus)Customizing Articles' and Info
1535 node `(gnus)Gravatars' for details."
1536   :version "24.1"
1537   :group 'gnus-article-treat
1538   :group 'gnus-gravatar
1539   :link '(custom-manual "(gnus)Customizing Articles")
1540   :link '(custom-manual "(gnus)Gravatars")
1541   :type gnus-article-treat-head-custom)
1542 (put 'gnus-treat-from-gravatar 'highlight t)
1543
1544 (defcustom gnus-treat-mail-gravatar nil
1545   "Display gravatars in To and Cc headers.
1546 Valid values are nil, t, `head', `first', `last', an integer or a
1547 predicate.  See Info node `(gnus)Customizing Articles' and Info
1548 node `(gnus)Gravatars' for details."
1549   :version "24.1"
1550   :group 'gnus-article-treat
1551   :group 'gnus-gravatar
1552   :link '(custom-manual "(gnus)Customizing Articles")
1553   :link '(custom-manual "(gnus)Gravatars")
1554   :type gnus-article-treat-head-custom)
1555 (put 'gnus-treat-mail-gravatar 'highlight t)
1556
1557 (defcustom gnus-treat-body-boundary
1558   (if (or gnus-treat-newsgroups-picon
1559           gnus-treat-mail-picon
1560           gnus-treat-from-picon
1561           gnus-treat-from-gravatar
1562           gnus-treat-mail-gravatar)
1563       ;; If there's much decoration, the user might prefer a boundery.
1564       'head
1565     nil)
1566   "Draw a boundary at the end of the headers.
1567 Valid values are nil and `head'.
1568 See Info node `(gnus)Customizing Articles' for details."
1569   :version "22.1"
1570   :group 'gnus-article-treat
1571   :link '(custom-manual "(gnus)Customizing Articles")
1572   :type gnus-article-treat-head-custom)
1573
1574 (defcustom gnus-treat-capitalize-sentences nil
1575   "Capitalize sentence-starting words.
1576 Valid values are nil, t, `head', `first', `last', an integer or a
1577 predicate.  See Info node `(gnus)Customizing Articles'."
1578   :version "21.1"
1579   :group 'gnus-article-treat
1580   :link '(custom-manual "(gnus)Customizing Articles")
1581   :type gnus-article-treat-custom)
1582
1583 (defcustom gnus-treat-wash-html nil
1584   "Format as HTML.
1585 Valid values are nil, t, `head', `first', `last', an integer or a
1586 predicate.  See Info node `(gnus)Customizing Articles'."
1587   :version "22.1"
1588   :group 'gnus-article-treat
1589   :link '(custom-manual "(gnus)Customizing Articles")
1590   :type gnus-article-treat-custom)
1591
1592 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1593   "Fill long lines.
1594 Valid values are nil, t, `head', `first', `last', an integer or a
1595 predicate.  See Info node `(gnus)Customizing Articles'."
1596   :version "24.1"
1597   :group 'gnus-article-treat
1598   :link '(custom-manual "(gnus)Customizing Articles")
1599   :type gnus-article-treat-custom)
1600
1601 (defcustom gnus-treat-x-pgp-sig nil
1602   "Verify X-PGP-Sig.
1603 To automatically treat X-PGP-Sig, set it to head.
1604 Valid values are nil, t, `head', `first', `last', an integer or a
1605 predicate.  See Info node `(gnus)Customizing Articles'."
1606   :version "22.1"
1607   :group 'gnus-article-treat
1608   :group 'mime-security
1609   :link '(custom-manual "(gnus)Customizing Articles")
1610   :type gnus-article-treat-custom)
1611
1612 (defvar gnus-article-encrypt-protocol-alist
1613   '(("PGP" . mml2015-self-encrypt)))
1614
1615 ;; Set to nil if more than one protocol added to
1616 ;; gnus-article-encrypt-protocol-alist.
1617 (defcustom gnus-article-encrypt-protocol "PGP"
1618   "The protocol used for encrypt articles.
1619 It is a string, such as \"PGP\". If nil, ask user."
1620   :version "22.1"
1621   :type 'string
1622   :group 'mime-security)
1623
1624 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1625                               (mm-coding-system-p 'utf-8)
1626                               (executable-find idna-program))
1627   "Whether IDNA decoding of headers is used when viewing messages.
1628 This requires GNU Libidn, and by default only enabled if it is found."
1629   :version "22.1"
1630   :group 'gnus-article-headers
1631   :type 'boolean)
1632
1633 (defcustom gnus-article-over-scroll nil
1634   "If non-nil, allow scrolling the article buffer even when there no more text."
1635   :version "22.1"
1636   :group 'gnus-article
1637   :type 'boolean)
1638
1639 (defcustom gnus-inhibit-images nil
1640   "Non-nil means inhibit displaying of images inline in the article body."
1641   :version "24.1"
1642   :group 'gnus-article
1643   :type 'boolean)
1644
1645 (defcustom gnus-blocked-images 'gnus-block-private-groups
1646   "Images that have URLs matching this regexp will be blocked.
1647 This can also be a function to be evaluated.  If so, it will be
1648 called with the group name as the parameter, and should return a
1649 regexp."
1650   :version "24.1"
1651   :group 'gnus-art
1652   :type 'regexp)
1653
1654 ;;; Internal variables
1655
1656 (defvar gnus-english-month-names
1657   '("January" "February" "March" "April" "May" "June" "July" "August"
1658     "September" "October" "November" "December"))
1659
1660 (defvar article-goto-body-goes-to-point-min-p nil)
1661 (defvar gnus-article-wash-types nil)
1662 (defvar gnus-article-emphasis-alist nil)
1663 (defvar gnus-article-image-alist nil)
1664
1665 (defvar gnus-article-mime-handle-alist-1 nil)
1666 (defvar gnus-treatment-function-alist
1667   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1668     (gnus-treat-strip-banner gnus-article-strip-banner)
1669     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1670     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1671     (gnus-treat-buttonize gnus-article-add-buttons)
1672     (gnus-treat-fill-article gnus-article-fill-cited-article)
1673     (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1674     (gnus-treat-strip-cr gnus-article-remove-cr)
1675     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1676     (gnus-treat-date-ut gnus-article-date-ut)
1677     (gnus-treat-date-local gnus-article-date-local)
1678     (gnus-treat-date-english gnus-article-date-english)
1679     (gnus-treat-date-original gnus-article-date-original)
1680     (gnus-treat-date-user-defined gnus-article-date-user)
1681     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1682     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1683     (gnus-treat-display-x-face gnus-article-display-x-face)
1684     (gnus-treat-display-face gnus-article-display-face)
1685     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1686     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1687     (gnus-treat-hide-signature gnus-article-hide-signature)
1688     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1689     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1690     (gnus-treat-from-picon gnus-treat-from-picon)
1691     (gnus-treat-mail-picon gnus-treat-mail-picon)
1692     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1693     (gnus-treat-strip-pem gnus-article-hide-pem)
1694     (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1695     (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1696     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1697     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1698     (gnus-treat-strip-trailing-blank-lines
1699      gnus-article-remove-trailing-blank-lines)
1700     (gnus-treat-strip-leading-blank-lines
1701      gnus-article-strip-leading-blank-lines)
1702     (gnus-treat-strip-multiple-blank-lines
1703      gnus-article-strip-multiple-blank-lines)
1704     (gnus-treat-overstrike gnus-article-treat-overstrike)
1705     (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1706     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1707     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1708     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1709     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1710     (gnus-treat-display-smileys gnus-treat-smiley)
1711     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1712     (gnus-treat-wash-html gnus-article-wash-html)
1713     (gnus-treat-emphasize gnus-article-emphasize)
1714     (gnus-treat-hide-citation gnus-article-hide-citation)
1715     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1716     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1717     (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1718
1719 (defvar gnus-article-mime-handle-alist nil)
1720 (defvar article-lapsed-timer nil)
1721 (defvar gnus-article-current-summary nil)
1722
1723 (defvar gnus-article-mode-syntax-table
1724   (let ((table (copy-syntax-table text-mode-syntax-table)))
1725     ;; This causes the citation match run O(2^n).
1726     ;; (modify-syntax-entry ?- "w" table)
1727     (modify-syntax-entry ?> ")<" table)
1728     (modify-syntax-entry ?< "(>" table)
1729     ;; make M-. in article buffers work for `foo' strings
1730     (modify-syntax-entry ?' " " table)
1731     (modify-syntax-entry ?` " " table)
1732     table)
1733   "Syntax table used in article mode buffers.
1734 Initialized from `text-mode-syntax-table.")
1735
1736 (defvar gnus-save-article-buffer nil)
1737
1738 (defvar gnus-number-of-articles-to-be-saved nil)
1739
1740 (defvar gnus-inhibit-hiding nil)
1741
1742 (defvar gnus-article-edit-mode nil)
1743
1744 ;;; Macros for dealing with the article buffer.
1745
1746 (defmacro gnus-with-article-headers (&rest forms)
1747   `(with-current-buffer gnus-article-buffer
1748      (save-restriction
1749        (let ((inhibit-read-only t)
1750              (inhibit-point-motion-hooks t)
1751              (case-fold-search t))
1752          (article-narrow-to-head)
1753          ,@forms))))
1754
1755 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1756 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1757
1758 (defmacro gnus-with-article-buffer (&rest forms)
1759   `(with-current-buffer gnus-article-buffer
1760      (let ((inhibit-read-only t))
1761        ,@forms)))
1762
1763 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1764 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1765
1766 (defun gnus-article-goto-header (header)
1767   "Go to HEADER, which is a regular expression."
1768   (re-search-forward (concat "^\\(" header "\\):") nil t))
1769
1770 (defsubst gnus-article-hide-text (b e props)
1771   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1772   (gnus-add-text-properties-when 'article-type nil b e props)
1773   (when (memq 'intangible props)
1774     (put-text-property
1775      (max (1- b) (point-min))
1776      b 'intangible (cddr (memq 'intangible props)))))
1777
1778 (defsubst gnus-article-unhide-text (b e)
1779   "Remove hidden text properties from region between B and E."
1780   (remove-text-properties b e gnus-hidden-properties)
1781   (when (memq 'intangible gnus-hidden-properties)
1782     (put-text-property (max (1- b) (point-min))
1783                        b 'intangible nil)))
1784
1785 (defun gnus-article-hide-text-type (b e type)
1786   "Hide text of TYPE between B and E."
1787   (gnus-add-wash-type type)
1788   (gnus-article-hide-text
1789    b e (cons 'article-type (cons type gnus-hidden-properties))))
1790
1791 (defun gnus-article-unhide-text-type (b e type)
1792   "Unhide text of TYPE between B and E."
1793   (gnus-delete-wash-type type)
1794   (remove-text-properties
1795    b e (cons 'article-type (cons type gnus-hidden-properties)))
1796   (when (memq 'intangible gnus-hidden-properties)
1797     (put-text-property (max (1- b) (point-min))
1798                        b 'intangible nil)))
1799
1800 (defun gnus-article-hide-text-of-type (type)
1801   "Hide text of TYPE in the current buffer."
1802   (save-excursion
1803     (let ((b (point-min))
1804           (e (point-max)))
1805       (while (setq b (text-property-any b e 'article-type type))
1806         (add-text-properties b (incf b) gnus-hidden-properties)))))
1807
1808 (defun gnus-article-delete-text-of-type (type)
1809   "Delete text of TYPE in the current buffer."
1810   (save-excursion
1811     (let ((b (point-min)))
1812       (if (eq type 'multipart)
1813           ;; Remove MIME buttons associated with multipart/alternative parts.
1814           (progn
1815             (goto-char b)
1816             (while (if (get-text-property (point) 'gnus-part)
1817                        (setq b (point))
1818                      (when (setq b (next-single-property-change (point)
1819                                                                 'gnus-part))
1820                        (goto-char b)
1821                        t))
1822               (end-of-line)
1823               (skip-chars-forward "\n")
1824               (when (eq (get-text-property b 'article-type) 'multipart)
1825                 (delete-region b (point)))))
1826         (while (setq b (text-property-any b (point-max) 'article-type type))
1827           (delete-region
1828            b (or (text-property-not-all b (point-max) 'article-type type)
1829                  (point-max))))))))
1830
1831 (defun gnus-article-delete-invisible-text ()
1832   "Delete all invisible text in the current buffer."
1833   (save-excursion
1834     (let ((b (point-min)))
1835       (while (setq b (text-property-any b (point-max) 'invisible t))
1836         (delete-region
1837          b (or (text-property-not-all b (point-max) 'invisible t)
1838                (point-max)))))))
1839
1840 (defun gnus-article-text-type-exists-p (type)
1841   "Say whether any text of type TYPE exists in the buffer."
1842   (text-property-any (point-min) (point-max) 'article-type type))
1843
1844 (defsubst gnus-article-header-rank ()
1845   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1846   (let ((list gnus-sorted-header-list)
1847         (i 1))
1848     (while list
1849       (if (looking-at (car list))
1850           (setq list nil)
1851         (setq list (cdr list))
1852         (incf i)))
1853       i))
1854
1855 (defun article-hide-headers (&optional arg delete)
1856   "Hide unwanted headers and possibly sort them as well."
1857   (interactive)
1858   ;; This function might be inhibited.
1859   (unless gnus-inhibit-hiding
1860     (let ((inhibit-read-only t)
1861           (case-fold-search t)
1862           (max (1+ (length gnus-sorted-header-list)))
1863           (inhibit-point-motion-hooks t)
1864           (cur (current-buffer))
1865           ignored visible beg)
1866       (save-excursion
1867         ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1868         ;; group parameters, so we should go to the summary buffer.
1869         (when (prog1
1870                   (condition-case nil
1871                       (progn (set-buffer gnus-summary-buffer) t)
1872                     (error nil))
1873                 (setq ignored (when (not gnus-visible-headers)
1874                                 (cond ((stringp gnus-ignored-headers)
1875                                        gnus-ignored-headers)
1876                                       ((listp gnus-ignored-headers)
1877                                        (mapconcat 'identity
1878                                                   gnus-ignored-headers
1879                                                   "\\|"))))
1880                       visible (cond ((stringp gnus-visible-headers)
1881                                      gnus-visible-headers)
1882                                     ((and gnus-visible-headers
1883                                           (listp gnus-visible-headers))
1884                                      (mapconcat 'identity
1885                                                 gnus-visible-headers
1886                                                 "\\|")))))
1887           (set-buffer cur))
1888         (save-restriction
1889           ;; First we narrow to just the headers.
1890           (article-narrow-to-head)
1891           ;; Hide any "From " lines at the beginning of (mail) articles.
1892           (while (looking-at "From ")
1893             (forward-line 1))
1894           (unless (bobp)
1895             (delete-region (point-min) (point)))
1896           ;; Then treat the rest of the header lines.
1897           ;; Then we use the two regular expressions
1898           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1899           ;; select which header lines is to remain visible in the
1900           ;; article buffer.
1901           (while (re-search-forward "^[^ \t:]*:" nil t)
1902             (beginning-of-line)
1903             ;; Mark the rank of the header.
1904             (put-text-property
1905              (point) (1+ (point)) 'message-rank
1906              (if (or (and visible (looking-at visible))
1907                      (and ignored
1908                           (not (looking-at ignored))))
1909                  (gnus-article-header-rank)
1910                (+ 2 max)))
1911             (forward-line 1))
1912           (message-sort-headers-1)
1913           (when (setq beg (text-property-any
1914                            (point-min) (point-max) 'message-rank (+ 2 max)))
1915             ;; We delete the unwanted headers.
1916             (gnus-add-wash-type 'headers)
1917             (add-text-properties (point-min) (+ 5 (point-min))
1918                                  '(article-type headers dummy-invisible t))
1919             (delete-region beg (point-max))))))))
1920
1921 (defun article-hide-boring-headers (&optional arg)
1922   "Toggle hiding of headers that aren't very interesting.
1923 If given a negative prefix, always show; if given a positive prefix,
1924 always hide."
1925   (interactive (gnus-article-hidden-arg))
1926   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1927              (not gnus-show-all-headers))
1928     (save-excursion
1929       (save-restriction
1930         (let ((inhibit-read-only t)
1931               (inhibit-point-motion-hooks t))
1932           (article-narrow-to-head)
1933           (dolist (elem gnus-boring-article-headers)
1934             (goto-char (point-min))
1935             (cond
1936              ;; Hide empty headers.
1937              ((eq elem 'empty)
1938               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1939                 (forward-line -1)
1940                 (gnus-article-hide-text-type
1941                  (point-at-bol)
1942                  (progn
1943                    (end-of-line)
1944                    (if (re-search-forward "^[^ \t]" nil t)
1945                        (match-beginning 0)
1946                      (point-max)))
1947                  'boring-headers)))
1948              ;; Hide boring Newsgroups header.
1949              ((eq elem 'newsgroups)
1950               (when (gnus-string-equal
1951                      (gnus-fetch-field "newsgroups")
1952                      (gnus-group-real-name
1953                       (if (boundp 'gnus-newsgroup-name)
1954                           gnus-newsgroup-name
1955                         "")))
1956                 (gnus-article-hide-header "newsgroups")))
1957              ((eq elem 'to-address)
1958               (let ((to (message-fetch-field "to"))
1959                     (to-address
1960                      (gnus-parameter-to-address
1961                       (if (boundp 'gnus-newsgroup-name)
1962                           gnus-newsgroup-name ""))))
1963                 (when (and to to-address
1964                            (ignore-errors
1965                              (gnus-string-equal
1966                               ;; only one address in To
1967                               (nth 1 (mail-extract-address-components to))
1968                               to-address)))
1969                   (gnus-article-hide-header "to"))))
1970              ((eq elem 'to-list)
1971               (let ((to (message-fetch-field "to"))
1972                     (to-list
1973                      (gnus-parameter-to-list
1974                       (if (boundp 'gnus-newsgroup-name)
1975                           gnus-newsgroup-name ""))))
1976                 (when (and to to-list
1977                            (ignore-errors
1978                              (gnus-string-equal
1979                               ;; only one address in To
1980                               (nth 1 (mail-extract-address-components to))
1981                               to-list)))
1982                   (gnus-article-hide-header "to"))))
1983              ((eq elem 'cc-list)
1984               (let ((cc (message-fetch-field "cc"))
1985                     (to-list
1986                      (gnus-parameter-to-list
1987                       (if (boundp 'gnus-newsgroup-name)
1988                           gnus-newsgroup-name ""))))
1989                 (when (and cc to-list
1990                            (ignore-errors
1991                              (gnus-string-equal
1992                               ;; only one address in CC
1993                               (nth 1 (mail-extract-address-components cc))
1994                               to-list)))
1995                   (gnus-article-hide-header "cc"))))
1996              ((eq elem 'followup-to)
1997               (when (gnus-string-equal
1998                      (message-fetch-field "followup-to")
1999                      (message-fetch-field "newsgroups"))
2000                 (gnus-article-hide-header "followup-to")))
2001              ((eq elem 'reply-to)
2002               (if (gnus-group-find-parameter
2003                    gnus-newsgroup-name 'broken-reply-to)
2004                   (gnus-article-hide-header "reply-to")
2005                 (let ((from (message-fetch-field "from"))
2006                       (reply-to (message-fetch-field "reply-to")))
2007                   (when
2008                       (and
2009                        from reply-to
2010                        (ignore-errors
2011                          (equal
2012                           (sort (mapcar
2013                                  (lambda (x) (downcase (cadr x)))
2014                                  (mail-extract-address-components from t))
2015                                 'string<)
2016                           (sort (mapcar
2017                                  (lambda (x) (downcase (cadr x)))
2018                                  (mail-extract-address-components reply-to t))
2019                                 'string<))))
2020                     (gnus-article-hide-header "reply-to")))))
2021              ((eq elem 'date)
2022               (let ((date (with-current-buffer gnus-original-article-buffer
2023                             ;; If date in `gnus-article-buffer' is localized
2024                             ;; (`gnus-treat-date-user-defined'),
2025                             ;; `days-between' might fail.
2026                             (message-fetch-field "date"))))
2027                 (when (and date
2028                            (< (days-between (current-time-string) date)
2029                               4))
2030                   (gnus-article-hide-header "date"))))
2031              ((eq elem 'long-to)
2032               (let ((to (message-fetch-field "to"))
2033                     (cc (message-fetch-field "cc")))
2034                 (when (> (length to) 1024)
2035                   (gnus-article-hide-header "to"))
2036                 (when (> (length cc) 1024)
2037                   (gnus-article-hide-header "cc"))))
2038              ((eq elem 'many-to)
2039               (let ((to-count 0)
2040                     (cc-count 0))
2041                 (goto-char (point-min))
2042                 (while (re-search-forward "^to:" nil t)
2043                   (setq to-count (1+ to-count)))
2044                 (when (> to-count 1)
2045                   (while (> to-count 0)
2046                     (goto-char (point-min))
2047                     (save-restriction
2048                       (re-search-forward "^to:" nil nil to-count)
2049                       (forward-line -1)
2050                       (narrow-to-region (point) (point-max))
2051                       (gnus-article-hide-header "to"))
2052                     (setq to-count (1- to-count))))
2053                 (goto-char (point-min))
2054                 (while (re-search-forward "^cc:" nil t)
2055                   (setq cc-count (1+ cc-count)))
2056                 (when (> cc-count 1)
2057                   (while (> cc-count 0)
2058                     (goto-char (point-min))
2059                     (save-restriction
2060                       (re-search-forward "^cc:" nil nil cc-count)
2061                       (forward-line -1)
2062                       (narrow-to-region (point) (point-max))
2063                       (gnus-article-hide-header "cc"))
2064                     (setq cc-count (1- cc-count)))))))))))))
2065
2066 (defun gnus-article-hide-header (header)
2067   (save-excursion
2068     (goto-char (point-min))
2069     (when (re-search-forward (concat "^" header ":") nil t)
2070       (gnus-article-hide-text-type
2071        (point-at-bol)
2072        (progn
2073          (end-of-line)
2074          (if (re-search-forward "^[^ \t]" nil t)
2075              (match-beginning 0)
2076            (point-max)))
2077        'boring-headers))))
2078
2079 (defvar gnus-article-normalized-header-length 40
2080   "Length of normalized headers.")
2081
2082 (defun article-normalize-headers ()
2083   "Make all header lines 40 characters long."
2084   (interactive)
2085   (let ((inhibit-read-only t)
2086         column)
2087     (save-excursion
2088       (save-restriction
2089         (article-narrow-to-head)
2090         (while (not (eobp))
2091           (cond
2092            ((< (setq column (- (point-at-eol) (point)))
2093                gnus-article-normalized-header-length)
2094             (end-of-line)
2095             (insert (make-string
2096                      (- gnus-article-normalized-header-length column)
2097                      ? )))
2098            ((> column gnus-article-normalized-header-length)
2099             (gnus-put-text-property
2100              (progn
2101                (forward-char gnus-article-normalized-header-length)
2102                (point))
2103              (point-at-eol)
2104              'invisible t))
2105            (t
2106             ;; Do nothing.
2107             ))
2108           (forward-line 1))))))
2109
2110 (defun article-treat-dumbquotes ()
2111   "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2112 Note that this function guesses whether a character is a sm*rtq**t* or
2113 not, so it should only be used interactively.
2114
2115 Sm*rtq**t*s are M****s***'s unilateral extension to the
2116 iso-8859-1 character map in an attempt to provide more quoting
2117 characters.  If you see something like \\222 or \\264 where
2118 you're expecting some kind of apostrophe or quotation mark, then
2119 try this wash."
2120   (interactive)
2121   (article-translate-strings gnus-article-dumbquotes-map))
2122
2123 (defvar org-entities)
2124
2125 (defun article-treat-non-ascii ()
2126   "Translate many Unicode characters into their ASCII equivalents."
2127   (interactive)
2128   (require 'org-entities)
2129   (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2130     (dolist (elem org-entities)
2131       (when (and (listp elem)
2132                  (= (length (nth 6 elem)) 1))
2133         (if (featurep 'xemacs)
2134             (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2135           (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2136     (save-excursion
2137       (when (article-goto-body)
2138         (let ((inhibit-read-only t)
2139               replace props)
2140           (while (not (eobp))
2141             (if (not (setq replace (if (featurep 'xemacs)
2142                                        (get-char-table (following-char) table)
2143                                      (aref table (following-char)))))
2144                 (forward-char 1)
2145               (if (prog1
2146                       (setq props (text-properties-at (point)))
2147                     (delete-char 1))
2148                   (add-text-properties (point) (progn (insert replace) (point))
2149                                        props)
2150                 (insert replace)))))))))
2151
2152 (defun article-translate-characters (from to)
2153   "Translate all characters in the body of the article according to FROM and TO.
2154 FROM is a string of characters to translate from; to is a string of
2155 characters to translate to."
2156   (save-excursion
2157     (when (article-goto-body)
2158       (let ((inhibit-read-only t)
2159             (x (make-string 225 ?x))
2160             (i -1))
2161         (while (< (incf i) (length x))
2162           (aset x i i))
2163         (setq i 0)
2164         (while (< i (length from))
2165           (aset x (aref from i) (aref to i))
2166           (incf i))
2167         (translate-region (point) (point-max) x)))))
2168
2169 (defun article-translate-strings (map)
2170   "Translate all string in the body of the article according to MAP.
2171 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2172   (save-excursion
2173     (when (article-goto-body)
2174       (let ((inhibit-read-only t))
2175         (dolist (elem map)
2176           (let ((from (car elem))
2177                 (to (cadr elem)))
2178             (save-excursion
2179               (if (stringp from)
2180                   (while (search-forward from nil t)
2181                     (replace-match to))
2182                 (while (not (eobp))
2183                   (if (eq (following-char) from)
2184                       (progn
2185                         (delete-char 1)
2186                         (insert to))
2187                     (forward-char 1)))))))))))
2188
2189 (defun article-treat-overstrike ()
2190   "Translate overstrikes into bold text."
2191   (interactive)
2192   (save-excursion
2193     (when (article-goto-body)
2194       (let ((inhibit-read-only t))
2195         (while (search-forward "\b" nil t)
2196           (let ((next (char-after))
2197                 (previous (char-after (- (point) 2))))
2198             ;; We do the boldification/underlining by hiding the
2199             ;; overstrikes and putting the proper text property
2200             ;; on the letters.
2201             (cond
2202              ((eq next previous)
2203               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2204               (put-text-property (point) (1+ (point)) 'face 'bold))
2205              ((eq next ?_)
2206               (gnus-article-hide-text-type
2207                (1- (point)) (1+ (point)) 'overstrike)
2208               (put-text-property
2209                (- (point) 2) (1- (point)) 'face 'underline))
2210              ((eq previous ?_)
2211               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2212               (put-text-property
2213                (point) (1+ (point)) 'face 'underline)))))))))
2214
2215 (defun article-treat-ansi-sequences ()
2216   "Translate ANSI SGR control sequences into overlays or extents."
2217   (interactive)
2218   (save-excursion
2219     (when (article-goto-body)
2220       (let ((inhibit-read-only t))
2221         (ansi-color-apply-on-region (point) (point-max))))))
2222
2223 (defun gnus-article-treat-unfold-headers ()
2224   "Unfold folded message headers.
2225 Only the headers that fit into the current window width will be
2226 unfolded."
2227   (interactive)
2228   (gnus-with-article-headers
2229     (let (length)
2230       (while (not (eobp))
2231         (save-restriction
2232           (mail-header-narrow-to-field)
2233           (let* ((header (buffer-string))
2234                  (unfoldable
2235                   (or (equal gnus-article-unfold-long-headers t)
2236                       (and (stringp gnus-article-unfold-long-headers)
2237                            (string-match gnus-article-unfold-long-headers header)))))
2238             (with-temp-buffer
2239               (insert header)
2240               (goto-char (point-min))
2241               (while (re-search-forward "\n[\t ]" nil t)
2242                 (replace-match " " t t)))
2243             (setq length (- (point-max) (point-min) 1))
2244             (when (or unfoldable
2245                       (< length (window-width)))
2246               (while (re-search-forward "\n[\t ]" nil t)
2247                 (replace-match " " t t))))
2248           (goto-char (point-max)))))))
2249
2250 (defun gnus-article-treat-fold-headers ()
2251   "Fold message headers."
2252   (interactive)
2253   (gnus-with-article-headers
2254     (while (not (eobp))
2255       (save-restriction
2256         (mail-header-narrow-to-field)
2257         (mail-header-fold-field)
2258         (goto-char (point-max))))))
2259
2260 (defun gnus-treat-smiley ()
2261   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2262   (interactive)
2263   (gnus-with-article-buffer
2264     (if (memq 'smiley gnus-article-wash-types)
2265         (gnus-delete-images 'smiley)
2266       (article-goto-body)
2267       (let ((images (smiley-region (point) (point-max))))
2268         (when images
2269           (gnus-add-wash-type 'smiley)
2270           (dolist (image images)
2271             (gnus-add-image 'smiley image)))))))
2272
2273 (defun gnus-article-remove-images ()
2274   "Remove all images from the article buffer."
2275   (interactive)
2276   (gnus-with-article-buffer
2277     (save-restriction
2278       (widen)
2279       (dolist (elem gnus-article-image-alist)
2280         (gnus-delete-images (car elem))))))
2281
2282 (defun gnus-article-show-images ()
2283   "Show any images that are in the HTML-rendered article buffer.
2284 This only works if the article in question is HTML."
2285   (interactive)
2286   (gnus-with-article-buffer
2287     (save-restriction
2288       (widen)
2289       (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2290                                                       'image-displayer))
2291         (destructuring-bind (start end function) region
2292           (funcall function (get-text-property start 'image-url)
2293                    start end))))))
2294
2295 (defun gnus-article-treat-fold-newsgroups ()
2296   "Unfold folded message headers.
2297 Only the headers that fit into the current window width will be
2298 unfolded."
2299   (interactive)
2300   (gnus-with-article-headers
2301     (while (gnus-article-goto-header "newsgroups\\|followup-to")
2302       (save-restriction
2303         (mail-header-narrow-to-field)
2304         (while (re-search-forward ", *" nil t)
2305           (replace-match ", " t t))
2306         (mail-header-fold-field)
2307         (goto-char (point-max))))))
2308
2309 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2310   "Value of `truncate-lines' in Gnus Article buffer.
2311 Valid values are nil, t, `head', `first', `last', an integer or a
2312 predicate.  See Info node `(gnus)Customizing Articles'."
2313   :version "23.1" ;; No Gnus
2314   :group 'gnus-article
2315   ;; :link '(custom-manual "(gnus)Customizing Articles")
2316   :type 'boolean)
2317
2318 (defun gnus-article-toggle-truncate-lines (&optional arg)
2319   "Toggle whether to fold or truncate long lines in article the buffer.
2320 If ARG is non-nil and not a number, toggle
2321 `gnus-article-truncate-lines' too.  If ARG is a number, truncate
2322 long lines if and only if arg is positive."
2323   (interactive "P")
2324   (cond
2325    ((and (numberp arg) (> arg 0))
2326     (setq gnus-article-truncate-lines t))
2327    ((numberp arg)
2328     (setq gnus-article-truncate-lines nil))
2329    (arg
2330     (setq gnus-article-truncate-lines
2331           (not gnus-article-truncate-lines))))
2332   (gnus-with-article-buffer
2333     (cond
2334      ((and (numberp arg) (> arg 0))
2335       (setq truncate-lines nil))
2336      ((numberp arg)
2337       (setq truncate-lines t)))
2338     ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2339     ;; `toggle-truncate-lines' needs an argument.
2340     (toggle-truncate-lines)))
2341
2342 (defun gnus-article-treat-body-boundary ()
2343   "Place a boundary line at the end of the headers."
2344   (interactive)
2345   (when (and gnus-body-boundary-delimiter
2346              (> (length gnus-body-boundary-delimiter) 0))
2347     (gnus-with-article-headers
2348       (goto-char (point-max))
2349       (let ((start (point)))
2350         (insert "X-Boundary: ")
2351         (gnus-add-text-properties start (point) '(invisible t intangible t))
2352         (insert (let (str)
2353                   (while (>= (window-width) (length str))
2354                     (setq str (concat str gnus-body-boundary-delimiter)))
2355                   (substring str 0 (window-width)))
2356                 "\n")
2357         (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2358
2359 (defun article-fill-long-lines ()
2360   "Fill lines that are wider than the window width."
2361   (interactive)
2362   (save-excursion
2363     (let ((inhibit-read-only t)
2364           (width (window-width (get-buffer-window (current-buffer)))))
2365       (save-restriction
2366         (article-goto-body)
2367         (let ((adaptive-fill-mode nil)) ;Why?  -sm
2368           (while (not (eobp))
2369             (end-of-line)
2370             (when (>= (current-column) (min fill-column width))
2371               (narrow-to-region (min (1+ (point)) (point-max))
2372                                 (point-at-bol))
2373               (let ((goback (point-marker)))
2374                 (fill-paragraph nil)
2375                 (goto-char (marker-position goback)))
2376               (widen))
2377             (forward-line 1)))))))
2378
2379 (defun article-capitalize-sentences ()
2380   "Capitalize the first word in each sentence."
2381   (interactive)
2382   (save-excursion
2383     (let ((inhibit-read-only t)
2384           (paragraph-start "^[\n\^L]"))
2385       (article-goto-body)
2386       (while (not (eobp))
2387         (capitalize-word 1)
2388         (forward-sentence)))))
2389
2390 (defun article-remove-cr ()
2391   "Remove trailing CRs and then translate remaining CRs into LFs."
2392   (interactive)
2393   (save-excursion
2394     (let ((inhibit-read-only t))
2395       (goto-char (point-min))
2396       (while (re-search-forward "\r+$" nil t)
2397         (replace-match "" t t))
2398       (goto-char (point-min))
2399       (while (search-forward "\r" nil t)
2400         (replace-match "\n" t t)))))
2401
2402 (defun article-remove-trailing-blank-lines ()
2403   "Remove all trailing blank lines from the article."
2404   (interactive)
2405   (save-excursion
2406     (let ((inhibit-read-only t))
2407       (goto-char (point-max))
2408       (delete-region
2409        (point)
2410        (progn
2411          (while (and (not (bobp))
2412                      (looking-at "^[ \t]*$")
2413                      (not (gnus-annotation-in-region-p
2414                            (point) (point-at-eol))))
2415            (forward-line -1))
2416          (forward-line 1)
2417          (point))))))
2418
2419 (defvar gnus-face-properties-alist)
2420
2421 (defun article-display-face (&optional force)
2422   "Display any Face headers in the header."
2423   (interactive (list 'force))
2424   (let ((wash-face-p buffer-read-only))
2425     (gnus-with-article-headers
2426       ;; When displaying parts, this function can be called several times on
2427       ;; the same article, without any intended toggle semantic (as typing `W
2428       ;; D d' would have). So face deletion must occur only when we come from
2429       ;; an interactive command, that is when the *Article* buffer is
2430       ;; read-only.
2431       (if (and wash-face-p (memq 'face gnus-article-wash-types))
2432           (gnus-delete-images 'face)
2433         (let ((from (message-fetch-field "from"))
2434               face faces)
2435           (save-current-buffer
2436             (when (and wash-face-p
2437                        (gnus-buffer-live-p gnus-original-article-buffer)
2438                        (not (re-search-forward "^Face:[\t ]*" nil t)))
2439               (set-buffer gnus-original-article-buffer))
2440             (save-restriction
2441               (mail-narrow-to-head)
2442               (when (or force
2443                         ;; Check whether this face is censored.
2444                         (not (and gnus-article-x-face-too-ugly
2445                                   (or from
2446                                       (setq from (message-fetch-field "from")))
2447                                   (string-match gnus-article-x-face-too-ugly
2448                                                 from))))
2449                 (while (gnus-article-goto-header "Face")
2450                   (push (mail-header-field-value) faces)))))
2451           (when faces
2452             (goto-char (point-min))
2453             (let (png image)
2454               (unless (setq from (gnus-article-goto-header "from"))
2455                 (insert "From:")
2456                 (setq from (point))
2457                 (insert " [no `from' set]\n"))
2458               (while faces
2459                 (when (setq png (gnus-convert-face-to-png (pop faces)))
2460                   (setq image
2461                         (apply 'gnus-create-image png 'png t
2462                                (cdr (assq 'png gnus-face-properties-alist))))
2463                   (goto-char from)
2464                   (gnus-add-wash-type 'face)
2465                   (gnus-add-image 'face image)
2466                   (gnus-put-image image nil 'face))))))))))
2467
2468 (defun article-display-x-face (&optional force)
2469   "Look for an X-Face header and display it if present."
2470   (interactive (list 'force))
2471   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2472     (gnus-with-article-headers
2473       ;; Delete the old process, if any.
2474       (when (process-status "article-x-face")
2475         (delete-process "article-x-face"))
2476       ;; See the comment in `article-display-face'.
2477       (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2478           ;; We have already displayed X-Faces, so we remove them
2479           ;; instead.
2480           (gnus-delete-images 'xface)
2481         ;; Display X-Faces.
2482         (let ((from (message-fetch-field "from"))
2483               x-faces face)
2484           (save-current-buffer
2485             (when (and wash-face-p
2486                        (gnus-buffer-live-p gnus-original-article-buffer)
2487                        (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2488               ;; If type `W f', use gnus-original-article-buffer,
2489               ;; otherwise use the current buffer because displaying
2490               ;; RFC822 parts calls this function too.
2491               (set-buffer gnus-original-article-buffer))
2492             (save-restriction
2493               (mail-narrow-to-head)
2494               (and gnus-article-x-face-command
2495                    (or force
2496                        ;; Check whether this face is censored.
2497                        (not (and gnus-article-x-face-too-ugly
2498                                  (or from
2499                                      (setq from (message-fetch-field "from")))
2500                                  (string-match gnus-article-x-face-too-ugly
2501                                                from))))
2502                    (while (gnus-article-goto-header "X-Face")
2503                      (push (mail-header-field-value) x-faces)))))
2504           (when x-faces
2505             ;; We display the face.
2506             (cond ((functionp gnus-article-x-face-command)
2507                    ;; The command is a lisp function, so we call it.
2508                    (mapc gnus-article-x-face-command x-faces))
2509                   ((stringp gnus-article-x-face-command)
2510                    ;; The command is a string, so we interpret the command
2511                    ;; as a, well, command, and fork it off.
2512                    (let ((process-connection-type nil))
2513                      (gnus-set-process-query-on-exit-flag
2514                       (start-process
2515                        "article-x-face" nil shell-file-name
2516                        shell-command-switch gnus-article-x-face-command)
2517                       nil)
2518                      ;; Sending multiple EOFs to xv doesn't work,
2519                      ;; so we only do a single external face.
2520                      (with-temp-buffer
2521                        (insert (car x-faces))
2522                        (process-send-region "article-x-face"
2523                                             (point-min) (point-max)))
2524                      (process-send-eof "article-x-face")))
2525                   (t
2526                    (error "`%s' set to `%s' is not a function"
2527                           gnus-article-x-face-command
2528                           'gnus-article-x-face-command)))))))))
2529
2530 (defun article-decode-mime-words ()
2531   "Decode all MIME-encoded words in the article."
2532   (interactive)
2533   (gnus-with-article-buffer
2534     (let ((inhibit-point-motion-hooks t)
2535           (mail-parse-charset gnus-newsgroup-charset)
2536           (mail-parse-ignored-charsets
2537            (with-current-buffer gnus-summary-buffer
2538              gnus-newsgroup-ignored-charsets)))
2539       (mail-decode-encoded-word-region (point-min) (point-max)))))
2540
2541 (defun article-decode-charset (&optional prompt)
2542   "Decode charset-encoded text in the article.
2543 If PROMPT (the prefix), prompt for a coding system to use."
2544   (interactive "P")
2545   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2546         (inhibit-read-only t)
2547         (mail-parse-charset gnus-newsgroup-charset)
2548         (mail-parse-ignored-charsets
2549          (save-excursion (condition-case nil
2550                              (set-buffer gnus-summary-buffer)
2551                            (error))
2552                          gnus-newsgroup-ignored-charsets))
2553         ct cte ctl charset format)
2554     (save-excursion
2555       (save-restriction
2556         (article-narrow-to-head)
2557         (setq ct (message-fetch-field "Content-Type" t)
2558               cte (message-fetch-field "Content-Transfer-Encoding" t)
2559               ctl (and ct (mail-header-parse-content-type ct))
2560               charset (cond
2561                        (prompt
2562                         (mm-read-coding-system "Charset to decode: "))
2563                        (ctl
2564                         (mail-content-type-get ctl 'charset)))
2565               format (and ctl (mail-content-type-get ctl 'format)))
2566         (when cte
2567           (setq cte (mail-header-strip cte)))
2568         (if (and ctl (not (string-match "/" (car ctl))))
2569             (setq ctl nil))
2570         (goto-char (point-max)))
2571       (forward-line 1)
2572       (save-restriction
2573         (narrow-to-region (point) (point-max))
2574         (when (and (eq mail-parse-charset 'gnus-decoded)
2575                    (eq (mm-body-7-or-8) '8bit))
2576           ;; The text code could have been decoded.
2577           (setq charset mail-parse-charset))
2578         (when (and (or (not ctl)
2579                        (equal (car ctl) "text/plain"))
2580                    (not format)) ;; article with format will decode later.
2581           (mm-decode-body
2582            charset (and cte (intern (downcase
2583                                      (gnus-strip-whitespace cte))))
2584            (car ctl)))))))
2585
2586 (defun article-decode-encoded-words ()
2587   "Remove encoded-word encoding from headers."
2588   (let ((inhibit-point-motion-hooks t)
2589         (mail-parse-charset gnus-newsgroup-charset)
2590         (mail-parse-ignored-charsets
2591          (save-excursion (condition-case nil
2592                              (set-buffer gnus-summary-buffer)
2593                            (error))
2594                          gnus-newsgroup-ignored-charsets))
2595         (inhibit-read-only t)
2596         end start)
2597     (goto-char (point-min))
2598     (when (search-forward "\n\n" nil 'move)
2599       (forward-line -1))
2600     (setq end (point))
2601     (while (not (bobp))
2602       (while (progn
2603                (forward-line -1)
2604                (and (not (bobp))
2605                     (memq (char-after) '(?\t ? )))))
2606       (setq start (point))
2607       (if (looking-at "\
2608 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2609 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2610           (funcall gnus-decode-address-function start end)
2611         (funcall gnus-decode-header-function start end))
2612       (goto-char (setq end start)))))
2613
2614 (defun article-decode-group-name ()
2615   "Decode group names in Newsgroups, Followup-To and Xref headers."
2616   (let ((inhibit-point-motion-hooks t)
2617         (inhibit-read-only t)
2618         (method (gnus-find-method-for-group gnus-newsgroup-name))
2619         regexp)
2620     (when (and (or gnus-group-name-charset-method-alist
2621                    gnus-group-name-charset-group-alist)
2622                (gnus-buffer-live-p gnus-original-article-buffer))
2623       (save-restriction
2624         (article-narrow-to-head)
2625         (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2626           (with-current-buffer gnus-original-article-buffer
2627             (goto-char (point-min)))
2628           (setq regexp (concat "^" header
2629                                ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2630           (while (re-search-forward regexp nil t)
2631             (replace-match (save-match-data
2632                              (gnus-decode-newsgroups
2633                               ;; XXX how to use data in article buffer?
2634                               (with-current-buffer gnus-original-article-buffer
2635                                 (re-search-forward regexp nil t)
2636                                 (match-string 1))
2637                               gnus-newsgroup-name method))
2638                            t t nil 1))
2639           (goto-char (point-min)))))))
2640
2641 (autoload 'idna-to-unicode "idna")
2642
2643 (defun article-decode-idna-rhs ()
2644   "Decode IDNA strings in RHS in various headers in current buffer.
2645 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2646 Mail-Reply-To: and Mail-Followup-To:."
2647   (when gnus-use-idna
2648     (save-restriction
2649       (let ((inhibit-point-motion-hooks t)
2650             (inhibit-read-only t))
2651         (article-narrow-to-head)
2652         (goto-char (point-min))
2653         (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2654           (let (ace unicode)
2655             (when (save-match-data
2656                     (and (setq ace (match-string 1))
2657                          (save-excursion
2658                            (and (re-search-backward "^[^ \t]" nil t)
2659                                 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2660                          (setq unicode (idna-to-unicode ace))))
2661               (unless (string= ace unicode)
2662                 (replace-match unicode nil nil nil 1)))))))))
2663
2664 (defun article-de-quoted-unreadable (&optional force read-charset)
2665   "Translate a quoted-printable-encoded article.
2666 If FORCE, decode the article whether it is marked as quoted-printable
2667 or not.
2668 If READ-CHARSET, ask for a coding system."
2669   (interactive (list 'force current-prefix-arg))
2670   (save-excursion
2671     (let ((inhibit-read-only t) type charset)
2672       (if (gnus-buffer-live-p gnus-original-article-buffer)
2673           (with-current-buffer gnus-original-article-buffer
2674             (setq type
2675                   (gnus-fetch-field "content-transfer-encoding"))
2676             (let* ((ct (gnus-fetch-field "content-type"))
2677                    (ctl (and ct (mail-header-parse-content-type ct))))
2678               (setq charset (and ctl
2679                                  (mail-content-type-get ctl 'charset)))
2680               (if (stringp charset)
2681                   (setq charset (intern (downcase charset)))))))
2682       (if read-charset
2683           (setq charset (mm-read-coding-system "Charset: " charset)))
2684       (unless charset
2685         (setq charset gnus-newsgroup-charset))
2686       (when (or force
2687                 (and type (let ((case-fold-search t))
2688                             (string-match "quoted-printable" type))))
2689         (article-goto-body)
2690         (quoted-printable-decode-region
2691          (point) (point-max) (mm-charset-to-coding-system charset))))))
2692
2693 (defun article-de-base64-unreadable (&optional force read-charset)
2694   "Translate a base64 article.
2695 If FORCE, decode the article whether it is marked as base64 not.
2696 If READ-CHARSET, ask for a coding system."
2697   (interactive (list 'force current-prefix-arg))
2698   (save-excursion
2699     (let ((inhibit-read-only t) type charset)
2700       (if (gnus-buffer-live-p gnus-original-article-buffer)
2701           (with-current-buffer gnus-original-article-buffer
2702             (setq type
2703                   (gnus-fetch-field "content-transfer-encoding"))
2704             (let* ((ct (gnus-fetch-field "content-type"))
2705                    (ctl (and ct (mail-header-parse-content-type ct))))
2706               (setq charset (and ctl
2707                                  (mail-content-type-get ctl 'charset)))
2708               (if (stringp charset)
2709                   (setq charset (intern (downcase charset)))))))
2710       (if read-charset
2711           (setq charset (mm-read-coding-system "Charset: " charset)))
2712       (unless charset
2713         (setq charset gnus-newsgroup-charset))
2714       (when (or force
2715                 (and type (let ((case-fold-search t))
2716                             (string-match "base64" type))))
2717         (article-goto-body)
2718         (save-restriction
2719           (narrow-to-region (point) (point-max))
2720           (base64-decode-region (point-min) (point-max))
2721           (mm-decode-coding-region
2722            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2723
2724 (eval-when-compile
2725   (require 'rfc1843))
2726
2727 (defun article-decode-HZ ()
2728   "Translate a HZ-encoded article."
2729   (interactive)
2730   (require 'rfc1843)
2731   (save-excursion
2732     (let ((inhibit-read-only t))
2733       (rfc1843-decode-region (point-min) (point-max)))))
2734
2735 (defun article-unsplit-urls ()
2736   "Remove the newlines that some other mailers insert into URLs."
2737   (interactive)
2738   (save-excursion
2739     (let ((inhibit-read-only t))
2740       (goto-char (point-min))
2741       (while (re-search-forward
2742               "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2743         (replace-match "\\1\\3" t)))
2744     (when (interactive-p)
2745       (gnus-treat-article nil))))
2746
2747 (defun article-wash-html ()
2748   "Format an HTML article."
2749   (interactive)
2750   (let ((handles nil)
2751         (buffer-read-only nil))
2752     (when (gnus-buffer-live-p gnus-original-article-buffer)
2753       (setq handles (mm-dissect-buffer t t)))
2754     (article-goto-body)
2755     (delete-region (point) (point-max))
2756     (mm-inline-text-html handles)))
2757
2758 (defvar gnus-article-browse-html-temp-list nil
2759   "List of temporary files created by `gnus-article-browse-html-parts'.
2760 Internal variable.")
2761
2762 (defcustom gnus-article-browse-delete-temp 'ask
2763   "What to do with temporary files from `gnus-article-browse-html-parts'.
2764 If nil, don't delete temporary files.  If it is t, delete them on
2765 exit from the summary buffer.  If it is the symbol `file', query
2766 on each file, if it is `ask' ask once when exiting from the
2767 summary buffer."
2768   :group 'gnus-article
2769   :version "23.1" ;; No Gnus
2770   :type '(choice (const :tag "Don't delete" nil)
2771                  (const :tag "Don't ask" t)
2772                  (const :tag "Ask" ask)
2773                  (const :tag "Ask for each file" file)))
2774
2775 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2776
2777 (defun gnus-article-browse-delete-temp-files (&optional how)
2778   "Delete temp-files created by `gnus-article-browse-html-parts'."
2779   (when (and gnus-article-browse-html-temp-list
2780              (progn
2781                (or how (setq how gnus-article-browse-delete-temp))
2782                (if (eq how 'ask)
2783                    (let ((files (length gnus-article-browse-html-temp-list)))
2784                      (gnus-y-or-n-p (format
2785                                      "Delete all %s temporary HTML file%s? "
2786                                      files
2787                                      (if (> files 1) "s" ""))))
2788                  how)))
2789     (dolist (file gnus-article-browse-html-temp-list)
2790       (cond ((file-directory-p file)
2791              (when (or (not (eq how 'file))
2792                        (gnus-y-or-n-p
2793                         (format
2794                          "Delete temporary HTML file(s) in directory `%s'? "
2795                          (file-name-as-directory file))))
2796                (gnus-delete-directory file)))
2797             ((file-exists-p file)
2798              (when (or (not (eq how 'file))
2799                        (gnus-y-or-n-p
2800                         (format "Delete temporary HTML file `%s'? " file)))
2801                (delete-file file)))))
2802     ;; Also remove file from the list when not deleted or if file doesn't
2803     ;; exist anymore.
2804     (setq gnus-article-browse-html-temp-list nil))
2805   gnus-article-browse-html-temp-list)
2806
2807 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2808   "Find CID content in HANDLES and save it in a file in DIRECTORY.
2809 Return file name."
2810   (save-match-data
2811     (let (file type)
2812       (catch 'found
2813         (dolist (handle handles)
2814           (cond
2815            ((not (listp handle)))
2816            ((equal (mm-handle-media-supertype handle) "multipart")
2817             (when (setq file (gnus-article-browse-html-save-cid-content
2818                               cid handle directory))
2819               (throw 'found file)))
2820            ((equal (concat "<" cid ">") (mm-handle-id handle))
2821             (setq file
2822                   (expand-file-name
2823                    (or (mail-content-type-get
2824                         (mm-handle-disposition handle) 'filename)
2825                        (mail-content-type-get
2826                         (setq type (mm-handle-type handle)) 'name)
2827                        (concat
2828                         (make-temp-name "cid")
2829                         (car (rassoc (car type) mailcap-mime-extensions))))
2830                    directory))
2831             (mm-save-part-to-file handle file)
2832             (throw 'found file))))))))
2833
2834 (defun gnus-article-browse-html-parts (list &optional header)
2835   "View all \"text/html\" parts from LIST.
2836 Recurse into multiparts.  The optional HEADER that should be a decoded
2837 message header will be added to the bodies of the \"text/html\" parts."
2838   ;; Internal function used by `gnus-article-browse-html-article'.
2839   (let (type file charset content cid-dir tmp-file showed)
2840     ;; Find and show the html-parts.
2841     (dolist (handle list)
2842       ;; If HTML, show it:
2843       (cond ((not (listp handle)))
2844             ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2845                  (and (equal (car type) "message/external-body")
2846                       (or header
2847                           (setq file (or (mail-content-type-get type 'name)
2848                                          (mail-content-type-get
2849                                           (mm-handle-disposition handle)
2850                                           'filename))))
2851                       (or (mm-handle-cache handle)
2852                           (condition-case code
2853                               (progn (mm-extern-cache-contents handle) t)
2854                             (error
2855                              (gnus-message 3 "%s" (error-message-string code))
2856                              (when (>= gnus-verbose 3) (sit-for 2))
2857                              nil)))
2858                       (progn
2859                         (setq handle (mm-handle-cache handle)
2860                               type (mm-handle-type handle))
2861                         (equal (car type) "text/html"))))
2862              (setq charset (mail-content-type-get type 'charset)
2863                    content (mm-get-part handle))
2864              (with-temp-buffer
2865                (if (eq charset 'gnus-decoded)
2866                    (mm-enable-multibyte)
2867                  (mm-disable-multibyte))
2868                (insert content)
2869                ;; resolve cid contents
2870                (let ((case-fold-search t)
2871                      cid-file)
2872                  (goto-char (point-min))
2873                  (while (re-search-forward "\
2874 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2875                                            nil t)
2876                    (unless cid-dir
2877                      (setq cid-dir (mm-make-temp-file "cid" t))
2878                      (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2879                    (setq file nil
2880                          content nil)
2881                    (when (setq cid-file
2882                                (gnus-article-browse-html-save-cid-content
2883                                 (match-string 2)
2884                                 (with-current-buffer gnus-article-buffer
2885                                   gnus-article-mime-handles)
2886                                 cid-dir))
2887                      (replace-match (concat "file://" cid-file)
2888                                     nil nil nil 1))))
2889                (unless content (setq content (buffer-string))))
2890              (when (or charset header (not file))
2891                (setq tmp-file (mm-make-temp-file
2892                                ;; Do we need to care for 8.3 filenames?
2893                                "mm-" nil ".html")))
2894              ;; Add a meta html tag to specify charset and a header.
2895              (cond
2896               (header
2897                (let (title eheader body hcharset coding force-charset)
2898                  (with-temp-buffer
2899                    (mm-enable-multibyte)
2900                    (setq case-fold-search t)
2901                    (insert header "\n")
2902                    (setq title (message-fetch-field "subject"))
2903                    (goto-char (point-min))
2904                    (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2905                      (replace-match (cond ((match-beginning 1) "&lt;")
2906                                           ((match-beginning 2) "&gt;")
2907                                           (t "&amp;"))))
2908                    (goto-char (point-min))
2909                    (insert "<pre>\n")
2910                    (goto-char (point-max))
2911                    (insert "</pre>\n<hr>\n")
2912                    ;; We have to examine charset one by one since
2913                    ;; charset specified in parts might be different.
2914                    (if (eq charset 'gnus-decoded)
2915                        (setq charset 'utf-8
2916                              eheader (mm-encode-coding-string (buffer-string)
2917                                                               charset)
2918                              title (when title
2919                                      (mm-encode-coding-string title charset))
2920                              body (mm-encode-coding-string content charset)
2921                              force-charset t)
2922                      (setq hcharset (mm-find-mime-charset-region (point-min)
2923                                                                  (point-max)))
2924                      (cond ((= (length hcharset) 1)
2925                             (setq hcharset (car hcharset)
2926                                   coding (mm-charset-to-coding-system
2927                                           hcharset)))
2928                            ((> (length hcharset) 1)
2929                             (setq hcharset 'utf-8
2930                                   coding hcharset)))
2931                      (if coding
2932                          (if charset
2933                              (progn
2934                                (setq body
2935                                      (mm-charset-to-coding-system charset))
2936                                (if (eq coding body)
2937                                    (setq eheader (mm-encode-coding-string
2938                                                   (buffer-string) coding)
2939                                          title (when title
2940                                                  (mm-encode-coding-string
2941                                                   title coding))
2942                                          body content)
2943                                  (setq charset 'utf-8
2944                                        eheader (mm-encode-coding-string
2945                                                 (buffer-string) charset)
2946                                        title (when title
2947                                                (mm-encode-coding-string
2948                                                 title charset))
2949                                        body (mm-encode-coding-string
2950                                              (mm-decode-coding-string
2951                                               content body)
2952                                              charset)
2953                                        force-charset t)))
2954                            (setq charset hcharset
2955                                  eheader (mm-encode-coding-string
2956                                           (buffer-string) coding)
2957                                  title (when title
2958                                          (mm-encode-coding-string
2959                                           title coding))
2960                                  body content))
2961                        (setq eheader (mm-string-as-unibyte (buffer-string))
2962                              body content)))
2963                    (erase-buffer)
2964                    (mm-disable-multibyte)
2965                    (insert body)
2966                    (when charset
2967                      (mm-add-meta-html-tag handle charset force-charset))
2968                    (when title
2969                      (goto-char (point-min))
2970                      (unless (search-forward "<title>" nil t)
2971                        (re-search-forward "<head>\\s-*" nil t)
2972                        (insert "<title>" title "</title>\n")))
2973                    (goto-char (point-min))
2974                    (or (re-search-forward
2975                         "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2976                        (re-search-forward
2977                         "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2978                    (insert eheader)
2979                    (mm-write-region (point-min) (point-max)
2980                                     tmp-file nil nil nil 'binary t))))
2981               (charset
2982                (mm-with-unibyte-buffer
2983                  (insert (if (eq charset 'gnus-decoded)
2984                              (mm-encode-coding-string content
2985                                                       (setq charset 'utf-8))
2986                            content))
2987                  (if (or (mm-add-meta-html-tag handle charset)
2988                          (not file))
2989                      (mm-write-region (point-min) (point-max)
2990                                       tmp-file nil nil nil 'binary t)
2991                    (setq tmp-file nil))))
2992               (tmp-file
2993                (mm-save-part-to-file handle tmp-file)))
2994              (when tmp-file
2995                (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2996              (add-hook 'gnus-summary-prepare-exit-hook
2997                        'gnus-article-browse-delete-temp-files)
2998              (add-hook 'gnus-exit-gnus-hook
2999                        (lambda  ()
3000                          (gnus-article-browse-delete-temp-files t)))
3001              ;; FIXME: Warn if there's an <img> tag?
3002              (browse-url-of-file (or tmp-file (expand-file-name file)))
3003              (setq showed t))
3004             ;; If multipart, recurse
3005             ((equal (mm-handle-media-supertype handle) "multipart")
3006              (when (gnus-article-browse-html-parts handle header)
3007                (setq showed t)))
3008             ((equal (mm-handle-media-type handle) "message/rfc822")
3009              (mm-with-multibyte-buffer
3010                (mm-insert-part handle)
3011                (setq handle (mm-dissect-buffer t t))
3012                (when (and (bufferp (car handle))
3013                           (stringp (car (mm-handle-type handle))))
3014                  (setq handle (list handle)))
3015                (when header
3016                  (article-decode-encoded-words)
3017                  (let ((gnus-visible-headers
3018                         (or (get 'gnus-visible-headers 'standard-value)
3019                             gnus-visible-headers)))
3020                    (article-hide-headers))
3021                  (goto-char (point-min))
3022                  (search-forward "\n\n" nil 'move)
3023                  (skip-chars-backward "\t\n ")
3024                  (setq header (buffer-substring (point-min) (point)))))
3025              (when (prog1
3026                        (gnus-article-browse-html-parts handle header)
3027                      (mm-destroy-parts handle))
3028                (setq showed t)))))
3029     showed))
3030
3031 (defun gnus-article-browse-html-article (&optional arg)
3032   "View \"text/html\" parts of the current article with a WWW browser.
3033 Inline images embedded in a message using the cid scheme, as they are
3034 generally considered to be safe, will be processed properly.
3035 The message header is added to the beginning of every html part unless
3036 the prefix argument ARG is given.
3037
3038 Warning: Spammers use links to images (using the http scheme) in HTML
3039 articles to verify whether you have read the message.  As
3040 `gnus-article-browse-html-article' passes the HTML content to the
3041 browser without eliminating these \"web bugs\" you should only
3042 use it for mails from trusted senders.
3043
3044 If you always want to display HTML parts in the browser, set
3045 `mm-text-html-renderer' to nil.
3046
3047 This command creates temporary files to pass HTML contents including
3048 images if any to the browser, and deletes them when exiting the group
3049 \(if you want)."
3050   ;; Cf. `mm-w3m-safe-url-regexp'
3051   (interactive "P")
3052   (if arg
3053       (gnus-summary-show-article)
3054     (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3055                                     gnus-visible-headers))
3056           ;; As we insert a <hr>, there's no need for the body boundary.
3057           (gnus-treat-body-boundary nil))
3058       (gnus-summary-show-article)))
3059   (with-current-buffer gnus-article-buffer
3060     (let ((header (unless arg
3061                     (save-restriction
3062                       (widen)
3063                       (buffer-substring-no-properties
3064                        (goto-char (point-min))
3065                        (if (search-forward "\n\n" nil t)
3066                            (match-beginning 0)
3067                          (goto-char (point-max))
3068                          (skip-chars-backward "\t\n ")
3069                          (point))))))
3070           parts)
3071       (set-buffer gnus-original-article-buffer)
3072       (setq parts (mm-dissect-buffer t t))
3073       ;; If singlepart, enforce a list.
3074       (when (and (bufferp (car parts))
3075                  (stringp (car (mm-handle-type parts))))
3076         (setq parts (list parts)))
3077       ;; Process the list
3078       (unless (gnus-article-browse-html-parts parts header)
3079         (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3080       (mm-destroy-parts parts)
3081       (unless arg
3082         (gnus-summary-show-article)))))
3083
3084 (defun article-hide-list-identifiers ()
3085   "Remove list identifies from the Subject header.
3086 The `gnus-list-identifiers' variable specifies what to do."
3087   (interactive)
3088   (let ((inhibit-point-motion-hooks t)
3089         (regexp (if (consp gnus-list-identifiers)
3090                     (mapconcat 'identity gnus-list-identifiers " *\\|")
3091                   gnus-list-identifiers))
3092         (inhibit-read-only t))
3093     (when regexp
3094       (save-excursion
3095         (save-restriction
3096           (article-narrow-to-head)
3097           (goto-char (point-min))
3098           (while (re-search-forward
3099                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3100                   nil t)
3101             (delete-region (match-beginning 2) (match-end 0))
3102             (beginning-of-line))
3103           (when (re-search-forward
3104                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3105             (delete-region (match-beginning 1) (match-end 1))))))))
3106
3107 (defun article-hide-pem (&optional arg)
3108   "Toggle hiding of any PEM headers and signatures in the current article.
3109 If given a negative prefix, always show; if given a positive prefix,
3110 always hide."
3111   (interactive (gnus-article-hidden-arg))
3112   (unless (gnus-article-check-hidden-text 'pem arg)
3113     (save-excursion
3114       (let ((inhibit-read-only t) end)
3115         (goto-char (point-min))
3116         ;; Hide the horrendously ugly "header".
3117         (when (and (search-forward
3118                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3119                     nil t)
3120                    (setq end (1+ (match-beginning 0))))
3121           (gnus-add-wash-type 'pem)
3122           (gnus-article-hide-text-type
3123            end
3124            (if (search-forward "\n\n" nil t)
3125                (match-end 0)
3126              (point-max))
3127            'pem)
3128           ;; Hide the trailer as well
3129           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3130                                 nil t)
3131             (gnus-article-hide-text-type
3132              (match-beginning 0) (match-end 0) 'pem)))))))
3133
3134 (defun article-strip-banner ()
3135   "Strip the banners specified by the `banner' group parameter and by
3136 `gnus-article-address-banner-alist'."
3137   (interactive)
3138   (save-excursion
3139     (save-restriction
3140       (let ((inhibit-point-motion-hooks t))
3141         (when (gnus-parameter-banner gnus-newsgroup-name)
3142           (article-really-strip-banner
3143            (gnus-parameter-banner gnus-newsgroup-name)))
3144         (when gnus-article-address-banner-alist
3145           ;; Note that the From header is decoded here, so it is
3146           ;; required that the *-extract-address-components function
3147           ;; supports non-ASCII text.
3148           (let ((from (save-restriction
3149                         (widen)
3150                         (article-narrow-to-head)
3151                         (mail-fetch-field "from"))))
3152             (when (and from
3153                        (setq from
3154                              (cadr (funcall gnus-extract-address-components
3155                                             from))))
3156               (catch 'found
3157                 (dolist (pair gnus-article-address-banner-alist)
3158                   (when (string-match (car pair) from)
3159                     (throw 'found
3160                            (article-really-strip-banner (cdr pair)))))))))))))
3161
3162 (defun article-really-strip-banner (banner)
3163   "Strip the banner specified by the argument."
3164   (save-excursion
3165     (save-restriction
3166       (let ((inhibit-point-motion-hooks t)
3167             (gnus-signature-limit nil)
3168             (inhibit-read-only t))
3169         (article-goto-body)
3170         (cond
3171          ((eq banner 'signature)
3172           (when (gnus-article-narrow-to-signature)
3173             (widen)
3174             (forward-line -1)
3175             (delete-region (point) (point-max))))
3176          ((symbolp banner)
3177           (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3178               (while (re-search-forward banner nil t)
3179                 (delete-region (match-beginning 0) (match-end 0)))))
3180          ((stringp banner)
3181           (while (re-search-forward banner nil t)
3182             (delete-region (match-beginning 0) (match-end 0)))))))))
3183
3184 (defun article-babel ()
3185   "Translate article using an online translation service."
3186   (interactive)
3187   (require 'babel)
3188   (gnus-with-article-buffer
3189     (when (article-goto-body)
3190       (let* ((start (point))
3191              (end (point-max))
3192              (orig (buffer-substring start end))
3193              (trans (babel-as-string orig)))
3194         (save-restriction
3195           (narrow-to-region start end)
3196           (delete-region start end)
3197           (insert trans))))))
3198
3199 (defun article-hide-signature (&optional arg)
3200   "Hide the signature in the current article.
3201 If given a negative prefix, always show; if given a positive prefix,
3202 always hide."
3203   (interactive (gnus-article-hidden-arg))
3204   (unless (gnus-article-check-hidden-text 'signature arg)
3205     (save-excursion
3206       (save-restriction
3207         (let ((inhibit-read-only t))
3208           (when (gnus-article-narrow-to-signature)
3209             (gnus-article-hide-text-type
3210              (point-min) (point-max) 'signature))))))
3211   (gnus-set-mode-line 'article))
3212
3213 (defun article-strip-headers-in-body ()
3214   "Strip offensive headers from bodies."
3215   (interactive)
3216   (save-excursion
3217     (article-goto-body)
3218     (let ((case-fold-search t))
3219       (when (looking-at "x-no-archive:")
3220         (gnus-delete-line)))))
3221
3222 (defun article-strip-leading-blank-lines ()
3223   "Remove all blank lines from the beginning of the article."
3224   (interactive)
3225   (save-excursion
3226     (let ((inhibit-point-motion-hooks t)
3227           (inhibit-read-only t))
3228       (when (article-goto-body)
3229         (while (and (not (eobp))
3230                     (looking-at "[ \t]*$"))
3231           (gnus-delete-line))))))
3232
3233 (defun article-narrow-to-head ()
3234   "Narrow the buffer to the head of the message.
3235 Point is left at the beginning of the narrowed-to region."
3236   (narrow-to-region
3237    (goto-char (point-min))
3238    (if (search-forward "\n\n" nil 1)
3239        (1- (point))
3240      (point-max)))
3241   (goto-char (point-min)))
3242
3243 (defun article-goto-body ()
3244   "Place point at the start of the body."
3245   (goto-char (point-min))
3246   (cond
3247    ;; This variable is only bound when dealing with separate
3248    ;; MIME body parts.
3249    (article-goto-body-goes-to-point-min-p
3250     t)
3251    ((search-forward "\n\n" nil t)
3252     t)
3253    (t
3254     (goto-char (point-max))
3255     nil)))
3256
3257 (defun article-strip-multiple-blank-lines ()
3258   "Replace consecutive blank lines with one empty line."
3259   (interactive)
3260   (save-excursion
3261     (let ((inhibit-point-motion-hooks t)
3262           (inhibit-read-only t))
3263       ;; First make all blank lines empty.
3264       (article-goto-body)
3265       (while (re-search-forward "^[ \t]+$" nil t)
3266         (unless (gnus-annotation-in-region-p
3267                  (match-beginning 0) (match-end 0))
3268           (replace-match "" nil t)))
3269       ;; Then replace multiple empty lines with a single empty line.
3270       (article-goto-body)
3271       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3272         (unless (gnus-annotation-in-region-p
3273                  (match-beginning 0) (match-end 0))
3274           (delete-region (match-beginning 1) (match-end 1)))))))
3275
3276 (defun article-strip-leading-space ()
3277   "Remove all white space from the beginning of the lines in the article."
3278   (interactive)
3279   (save-excursion
3280     (let ((inhibit-point-motion-hooks t)
3281           (inhibit-read-only t))
3282       (article-goto-body)
3283       (while (re-search-forward "^[ \t]+" nil t)
3284         (replace-match "" t t)))))
3285
3286 (defun article-strip-trailing-space ()
3287   "Remove all white space from the end of the lines in the article."
3288   (interactive)
3289   (save-excursion
3290     (let ((inhibit-point-motion-hooks t)
3291           (inhibit-read-only t))
3292       (article-goto-body)
3293       (while (re-search-forward "[ \t]+$" nil t)
3294         (replace-match "" t t)))))
3295
3296 (defun article-strip-blank-lines ()
3297   "Strip leading, trailing and multiple blank lines."
3298   (interactive)
3299   (article-strip-leading-blank-lines)
3300   (article-remove-trailing-blank-lines)
3301   (article-strip-multiple-blank-lines))
3302
3303 (defun article-strip-all-blank-lines ()
3304   "Strip all blank lines."
3305   (interactive)
3306   (save-excursion
3307     (let ((inhibit-point-motion-hooks t)
3308           (inhibit-read-only t))
3309       (article-goto-body)
3310       (while (re-search-forward "^[ \t]*\n" nil t)
3311         (replace-match "" t t)))))
3312
3313 (defun gnus-article-narrow-to-signature ()
3314   "Narrow to the signature; return t if a signature is found, else nil."
3315   (let ((inhibit-point-motion-hooks t))
3316     (when (gnus-article-search-signature)
3317       (forward-line 1)
3318       ;; Check whether we have some limits to what we consider
3319       ;; to be a signature.
3320       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3321                       (list gnus-signature-limit)))
3322             limit limited)
3323         (while (setq limit (pop limits))
3324           (if (or (and (integerp limit)
3325                        (< (- (point-max) (point)) limit))
3326                   (and (floatp limit)
3327                        (< (count-lines (point) (point-max)) limit))
3328                   (and (functionp limit)
3329                        (funcall limit))
3330                   (and (stringp limit)
3331                        (not (re-search-forward limit nil t))))
3332               ()                        ; This limit did not succeed.
3333             (setq limited t
3334                   limits nil)))
3335         (unless limited
3336           (narrow-to-region (point) (point-max))
3337           t)))))
3338
3339 (defun gnus-article-search-signature ()
3340   "Search the current buffer for the signature separator.
3341 Put point at the beginning of the signature separator."
3342   (let ((cur (point)))
3343     (goto-char (point-max))
3344     (if (if (stringp gnus-signature-separator)
3345             (re-search-backward gnus-signature-separator nil t)
3346           (let ((seps gnus-signature-separator))
3347             (while (and seps
3348                         (not (re-search-backward (car seps) nil t)))
3349               (pop seps))
3350             seps))
3351         t
3352       (goto-char cur)
3353       nil)))
3354
3355 (defun gnus-article-hidden-arg ()
3356   "Return the current prefix arg as a number, or 0 if no prefix."
3357   (list (if current-prefix-arg
3358             (prefix-numeric-value current-prefix-arg)
3359           0)))
3360
3361 (defun gnus-article-check-hidden-text (type arg)
3362   "Return nil if hiding is necessary.
3363 Arg can be nil or a number.  nil and positive means hide, negative
3364 means show, 0 means toggle."
3365   (save-excursion
3366     (save-restriction
3367       (let ((hide (gnus-article-hidden-text-p type)))
3368         (cond
3369          ((or (null arg)
3370               (> arg 0))
3371           nil)
3372          ((< arg 0)
3373           (gnus-article-show-hidden-text type)
3374           t)
3375          (t
3376           (if (eq hide 'hidden)
3377               (progn
3378                 (gnus-article-show-hidden-text type)
3379                 t)
3380             nil)))))))
3381
3382 (defun gnus-article-hidden-text-p (type)
3383   "Say whether the current buffer contains hidden text of type TYPE."
3384   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3385     (while (and pos
3386                 (not (get-text-property pos 'invisible))
3387                 (not (get-text-property pos 'dummy-invisible)))
3388       (setq pos
3389             (text-property-any (1+ pos) (point-max) 'article-type type)))
3390     (if pos
3391         'hidden
3392       nil)))
3393
3394 (defun gnus-article-show-hidden-text (type &optional dummy)
3395   "Show all hidden text of type TYPE.
3396 Originally it is hide instead of DUMMY."
3397   (let ((inhibit-read-only t)
3398         (inhibit-point-motion-hooks t))
3399     (gnus-remove-text-properties-when
3400      'article-type type
3401      (point-min) (point-max)
3402      (cons 'article-type (cons type
3403                                gnus-hidden-properties)))
3404     (gnus-delete-wash-type type)))
3405
3406 (defconst article-time-units
3407   `((year . ,(* 365.25 24 60 60))
3408     (week . ,(* 7 24 60 60))
3409     (day . ,(* 24 60 60))
3410     (hour . ,(* 60 60))
3411     (minute . 60)
3412     (second . 1))
3413   "Mapping from time units to seconds.")
3414
3415 (defun gnus-article-forward-header ()
3416   "Move point to the start of the next header.
3417 If the current header is a continuation header, this can be several
3418 lines forward."
3419   (let ((ended nil))
3420     (while (not ended)
3421       (forward-line 1)
3422       (if (looking-at "[ \t]+[^ \t]")
3423           (forward-line 1)
3424         (setq ended t)))))
3425
3426 (defun article-date-ut (&optional type highlight)
3427   "Convert DATE date to universal time in the current article.
3428 If TYPE is `local', convert to local time; if it is `lapsed', output
3429 how much time has lapsed since DATE.  For `lapsed', the value of
3430 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3431 should replace the \"Date:\" one, or should be added below it."
3432   (interactive (list 'ut t))
3433   (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3434          (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3435                              tdate-regexp)
3436                             ((eq type 'lapsed)
3437                              "^X-Sent:[ \t]")
3438                             (article-lapsed-timer
3439                              "^Date:[ \t]")
3440                             (t
3441                              tdate-regexp)))
3442          (case-fold-search t)
3443          (inhibit-read-only t)
3444          (inhibit-point-motion-hooks t)
3445          pos date bface eface)
3446     (save-excursion
3447       (save-restriction
3448         (widen)
3449         (goto-char (point-min))
3450         (while (or (setq date (get-text-property (setq pos (point))
3451                                                  'original-date))
3452                    (when (setq pos (next-single-property-change
3453                                     (point) 'original-date))
3454                      (setq date (get-text-property pos 'original-date))
3455                      t))
3456           (narrow-to-region
3457            pos (if (setq pos (text-property-any pos (point-max)
3458                                                 'original-date nil))
3459                    (progn
3460                      (goto-char pos)
3461                      (if (or (bolp) (eobp))
3462                          (point)
3463                        (1+ (point))))
3464                  (point-max)))
3465           (goto-char (point-min))
3466           (when (re-search-forward tdate-regexp nil t)
3467             (setq bface (get-text-property (point-at-bol) 'face)
3468                   eface (get-text-property (1- (point-at-eol)) 'face)))
3469           (goto-char (point-min))
3470           (setq pos nil)
3471           ;; Delete any old Date headers.
3472           (while (re-search-forward date-regexp nil t)
3473             (if pos
3474                 (delete-region (point-at-bol) (progn
3475                                                 (gnus-article-forward-header)
3476                                                 (point)))
3477               (delete-region (point-at-bol) (progn
3478                                               (gnus-article-forward-header)
3479                                               (forward-char -1)
3480                                               (point)))
3481               (setq pos (point))))
3482           (when (and (not pos)
3483                      (re-search-forward tdate-regexp nil t))
3484             (forward-line 1))
3485           (gnus-goto-char pos)
3486           (insert (article-make-date-line date (or type 'ut)))
3487           (unless pos
3488             (insert "\n")
3489             (forward-line -1))
3490           ;; Do highlighting.
3491           (beginning-of-line)
3492           (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3493             (put-text-property (match-beginning 1) (1+ (match-end 1))
3494                                'face bface)
3495             (put-text-property (match-beginning 2) (match-end 2)
3496                                'face eface))
3497           (put-text-property (point-min) (1- (point-max)) 'original-date date)
3498           (goto-char (point-max))
3499           (widen))))))
3500
3501 (defun article-make-date-line (date type)
3502   "Return a DATE line of TYPE."
3503   (unless (memq type '(local ut original user iso8601 lapsed english))
3504     (error "Unknown conversion type: %s" type))
3505   (condition-case ()
3506       (let ((time (date-to-time date)))
3507         (cond
3508          ;; Convert to the local timezone.
3509          ((eq type 'local)
3510           (concat "Date: " (message-make-date time)))
3511          ;; Convert to Universal Time.
3512          ((eq type 'ut)
3513           (concat "Date: "
3514                   (substring
3515                    (message-make-date
3516                     (let* ((e (parse-time-string date))
3517                            (tm (apply 'encode-time e))
3518                            (ms (car tm))
3519                            (ls (- (cadr tm) (car (current-time-zone time)))))
3520                       (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3521                             ((> ls 65535) (list (1+ ms) (- ls 65536)))
3522                             (t (list ms ls)))))
3523                    0 -5)
3524                   "UT"))
3525          ;; Get the original date from the article.
3526          ((eq type 'original)
3527           (concat "Date: " (if (string-match "\n+$" date)
3528                                (substring date 0 (match-beginning 0))
3529                              date)))
3530          ;; Let the user define the format.
3531          ((eq type 'user)
3532           (let ((format (or (condition-case nil
3533                                 (with-current-buffer gnus-summary-buffer
3534                                   gnus-article-time-format)
3535                               (error nil))
3536                             gnus-article-time-format)))
3537             (if (functionp format)
3538                 (funcall format time)
3539               (concat "Date: " (format-time-string format time)))))
3540          ;; ISO 8601.
3541          ((eq type 'iso8601)
3542           (let ((tz (car (current-time-zone time))))
3543             (concat
3544              "Date: "
3545              (format-time-string "%Y%m%dT%H%M%S" time)
3546              (format "%s%02d%02d"
3547                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3548                      (/ (% (abs tz) 3600) 60)))))
3549          ;; Do an X-Sent lapsed format.
3550          ((eq type 'lapsed)
3551           ;; If the date is seriously mangled, the timezone functions are
3552           ;; liable to bug out, so we ignore all errors.
3553           (let* ((now (current-time))
3554                  (real-time (subtract-time now time))
3555                  (real-sec (and real-time
3556                                 (+ (* (float (car real-time)) 65536)
3557                                    (cadr real-time))))
3558                  (sec (and real-time (abs real-sec)))
3559                  num prev)
3560             (cond
3561              ((null real-time)
3562               "X-Sent: Unknown")
3563              ((zerop sec)
3564               "X-Sent: Now")
3565              (t
3566               (concat
3567                "X-Sent: "
3568                ;; This is a bit convoluted, but basically we go
3569                ;; through the time units for years, weeks, etc,
3570                ;; and divide things to see whether that results
3571                ;; in positive answers.
3572                (mapconcat
3573                 (lambda (unit)
3574                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3575                       ;; The (remaining) seconds are too few to
3576                       ;; be divided into this time unit.
3577                       ""
3578                     ;; It's big enough, so we output it.
3579                     (setq sec (- sec (* num (cdr unit))))
3580                     (prog1
3581                         (concat (if prev ", " "") (int-to-string
3582                                                    (floor num))
3583                                 " " (symbol-name (car unit))
3584                                 (if (> num 1) "s" ""))
3585                       (setq prev t))))
3586                 article-time-units "")
3587                ;; If dates are odd, then it might appear like the
3588                ;; article was sent in the future.
3589                (if (> real-sec 0)
3590                    " ago"
3591                  " in the future"))))))
3592          ;; Display the date in proper English
3593          ((eq type 'english)
3594           (let ((dtime (decode-time time)))
3595             (concat
3596              "Date: the "
3597              (number-to-string (nth 3 dtime))
3598              (let ((digit (% (nth 3 dtime) 10)))
3599                (cond
3600                 ((memq (nth 3 dtime) '(11 12 13)) "th")
3601                 ((= digit 1) "st")
3602                 ((= digit 2) "nd")
3603                 ((= digit 3) "rd")
3604                 (t "th")))
3605              " of "
3606              (nth (1- (nth 4 dtime)) gnus-english-month-names)
3607              " "
3608              (number-to-string (nth 5 dtime))
3609              " at "
3610              (format "%02d" (nth 2 dtime))
3611              ":"
3612              (format "%02d" (nth 1 dtime)))))))
3613     (error
3614      (format "Date: %s (from Gnus)" date))))
3615
3616 (defun article-date-local (&optional highlight)
3617   "Convert the current article date to the local timezone."
3618   (interactive (list t))
3619   (article-date-ut 'local highlight))
3620
3621 (defun article-date-english (&optional highlight)
3622   "Convert the current article date to something that is proper English."
3623   (interactive (list t))
3624   (article-date-ut 'english highlight))
3625
3626 (defun article-date-original (&optional highlight)
3627   "Convert the current article date to what it was originally.
3628 This is only useful if you have used some other date conversion
3629 function and want to see what the date was before converting."
3630   (interactive (list t))
3631   (article-date-ut 'original highlight))
3632
3633 (defun article-date-lapsed (&optional highlight)
3634   "Convert the current article date to time lapsed since it was sent."
3635   (interactive (list t))
3636   (article-date-ut 'lapsed highlight))
3637
3638 (defun article-update-date-lapsed ()
3639   "Function to be run from a timer to update the lapsed time line."
3640   (save-match-data
3641     (let (deactivate-mark)
3642       (save-excursion
3643         (ignore-errors
3644          (walk-windows
3645           (lambda (w)
3646             (set-buffer (window-buffer w))
3647             (when (eq major-mode 'gnus-article-mode)
3648               (let ((mark (point-marker)))
3649                 (goto-char (point-min))
3650                 (when (re-search-forward "^X-Sent:" nil t)
3651                   (article-date-lapsed t))
3652                 (goto-char (marker-position mark))
3653                 (move-marker mark nil))))
3654           nil 'visible))))))
3655
3656 (defun gnus-start-date-timer (&optional n)
3657   "Start a timer to update the X-Sent header in the article buffers.
3658 The numerical prefix says how frequently (in seconds) the function
3659 is to run."
3660   (interactive "p")
3661   (unless n
3662     (setq n 1))
3663   (gnus-stop-date-timer)
3664   (setq article-lapsed-timer
3665         (run-at-time 1 n 'article-update-date-lapsed)))
3666
3667 (defun gnus-stop-date-timer ()
3668   "Stop the X-Sent timer."
3669   (interactive)
3670   (when article-lapsed-timer
3671     (nnheader-cancel-timer article-lapsed-timer)
3672     (setq article-lapsed-timer nil)))
3673
3674 (defun article-date-user (&optional highlight)
3675   "Convert the current article date to the user-defined format.
3676 This format is defined by the `gnus-article-time-format' variable."
3677   (interactive (list t))
3678   (article-date-ut 'user highlight))
3679
3680 (defun article-date-iso8601 (&optional highlight)
3681   "Convert the current article date to ISO8601."
3682   (interactive (list t))
3683   (article-date-ut 'iso8601 highlight))
3684
3685 (defmacro gnus-article-save-original-date (&rest forms)
3686   "Save the original date as a text property and evaluate FORMS."
3687   `(let* ((case-fold-search t)
3688           (start (progn
3689                    (goto-char (point-min))
3690                    (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3691                               (not (bolp)))
3692                      (match-end 0))))
3693           (date (when (and start
3694                            (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3695                                               nil t))
3696                   (buffer-substring-no-properties start
3697                                                   (match-beginning 0)))))
3698      (goto-char (point-max))
3699      (skip-chars-backward "\n")
3700      (put-text-property (point-min) (point) 'original-date date)
3701      ,@forms
3702      (goto-char (point-max))
3703      (skip-chars-backward "\n")
3704      (put-text-property (point-min) (point) 'original-date date)))
3705
3706 ;; (defun article-show-all ()
3707 ;;   "Show all hidden text in the article buffer."
3708 ;;   (interactive)
3709 ;;   (save-excursion
3710 ;;     (let ((inhibit-read-only t))
3711 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
3712
3713 (defun article-remove-leading-whitespace ()
3714   "Remove excessive whitespace from all headers."
3715   (interactive)
3716   (save-excursion
3717     (save-restriction
3718       (let ((inhibit-read-only t))
3719         (article-narrow-to-head)
3720         (goto-char (point-min))
3721         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3722           (delete-region (match-beginning 1) (match-end 1)))))))
3723
3724 (defun article-emphasize (&optional arg)
3725   "Emphasize text according to `gnus-emphasis-alist'."
3726   (interactive (gnus-article-hidden-arg))
3727   (unless (gnus-article-check-hidden-text 'emphasis arg)
3728     (save-excursion
3729       (let ((alist (or
3730                     (condition-case nil
3731                         (with-current-buffer gnus-summary-buffer
3732                           gnus-article-emphasis-alist)
3733                       (error))
3734                     gnus-emphasis-alist))
3735             (inhibit-read-only t)
3736             (props (append '(article-type emphasis)
3737                            gnus-hidden-properties))
3738             regexp elem beg invisible visible face)
3739         (article-goto-body)
3740         (setq beg (point))
3741         (while (setq elem (pop alist))
3742           (goto-char beg)
3743           (setq regexp (car elem)
3744                 invisible (nth 1 elem)
3745                 visible (nth 2 elem)
3746                 face (nth 3 elem))
3747           (while (re-search-forward regexp nil t)
3748             (when (and (match-beginning visible) (match-beginning invisible))
3749               (gnus-article-hide-text
3750                (match-beginning invisible) (match-end invisible) props)
3751               (gnus-article-unhide-text-type
3752                (match-beginning visible) (match-end visible) 'emphasis)
3753               (gnus-put-overlay-excluding-newlines
3754                (match-beginning visible) (match-end visible) 'face face)
3755               (gnus-add-wash-type 'emphasis)
3756               (goto-char (match-end invisible)))))))))
3757
3758 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3759   "Setup newsgroup emphasis alist."
3760   (unless gnus-article-emphasis-alist
3761     (let ((name (and gnus-newsgroup-name
3762                      (gnus-group-real-name gnus-newsgroup-name))))
3763       (make-local-variable 'gnus-article-emphasis-alist)
3764       (setq gnus-article-emphasis-alist
3765             (nconc
3766              (let ((alist gnus-group-highlight-words-alist) elem highlight)
3767                (while (setq elem (pop alist))
3768                  (when (and name (string-match (car elem) name))
3769                    (setq alist nil
3770                          highlight (copy-sequence (cdr elem)))))
3771                highlight)
3772              (copy-sequence highlight-words)
3773              (if gnus-newsgroup-name
3774                  (copy-sequence (gnus-group-find-parameter
3775                                  gnus-newsgroup-name 'highlight-words t)))
3776              gnus-emphasis-alist)))))
3777
3778 (defvar gnus-summary-article-menu)
3779 (defvar gnus-summary-post-menu)
3780
3781 ;;; Saving functions.
3782
3783 (defun gnus-article-save (save-buffer file &optional num)
3784   "Save the currently selected article."
3785   (when (or (get gnus-default-article-saver :headers)
3786             (not gnus-save-all-headers))
3787     ;; Remove headers according to `gnus-saved-headers' or the value
3788     ;; of the `:headers' property that the saver function might have.
3789     (let ((gnus-visible-headers
3790            (or (symbol-value (get gnus-default-article-saver :headers))
3791                gnus-saved-headers gnus-visible-headers))
3792           ;; Ignore group parameter.  See `article-hide-headers'.
3793           (gnus-summary-buffer nil))
3794       (with-current-buffer save-buffer
3795         (article-hide-headers 1 t))))
3796   (save-window-excursion
3797     (if (not gnus-default-article-saver)
3798         (error "No default saver is defined")
3799       ;; !!! Magic!  The saving functions all save
3800       ;; `gnus-save-article-buffer' (or so they think), but we
3801       ;; bind that variable to our save-buffer.
3802       (set-buffer gnus-article-buffer)
3803       (let* ((gnus-save-article-buffer save-buffer)
3804              (filename
3805               (cond
3806                ((not gnus-prompt-before-saving) 'default)
3807                ((eq gnus-prompt-before-saving 'always) nil)
3808                (t file)))
3809              (gnus-number-of-articles-to-be-saved
3810               (when (eq gnus-prompt-before-saving t)
3811                 num)))                  ; Magic
3812         (set-buffer gnus-article-current-summary)
3813         (funcall gnus-default-article-saver filename)))))
3814
3815 (defun gnus-read-save-file-name (prompt &optional filename
3816                                         function group headers variable
3817                                         dir-var)
3818   (let ((default-name
3819           (funcall function group headers (symbol-value variable)))
3820         result)
3821     (setq result
3822           (expand-file-name
3823            (cond
3824             ((eq filename 'default)
3825              default-name)
3826             ((eq filename t)
3827              default-name)
3828             (filename filename)
3829             (t
3830              (when (symbol-value dir-var)
3831                (setq default-name (expand-file-name
3832                                    (file-name-nondirectory default-name)
3833                                    (symbol-value dir-var))))
3834              (let* ((split-name (gnus-get-split-value gnus-split-methods))
3835                     (prompt
3836                      (format prompt
3837                              (if (and gnus-number-of-articles-to-be-saved
3838                                       (> gnus-number-of-articles-to-be-saved 1))
3839                                  (format "these %d articles"
3840                                          gnus-number-of-articles-to-be-saved)
3841                                "this article")))
3842                     (file
3843                      ;; Let the split methods have their say.
3844                      (cond
3845                       ;; No split name was found.
3846                       ((null split-name)
3847                        (read-file-name
3848                         (concat prompt " (default "
3849                                 (file-name-nondirectory default-name) "): ")
3850                         (file-name-directory default-name)
3851                         default-name))
3852                       ;; A single group name is returned.
3853                       ((stringp split-name)
3854                        (setq default-name
3855                              (funcall function split-name headers
3856                                       (symbol-value variable)))
3857                        (read-file-name
3858                         (concat prompt " (default "
3859                                 (file-name-nondirectory default-name) "): ")
3860                         (file-name-directory default-name)
3861                         default-name))
3862                       ;; A single split name was found
3863                       ((= 1 (length split-name))
3864                        (let* ((name (expand-file-name
3865                                      (car split-name)
3866                                      gnus-article-save-directory))
3867                               (dir (cond ((file-directory-p name)
3868                                           (file-name-as-directory name))
3869                                          ((file-exists-p name) name)
3870                                          (t gnus-article-save-directory))))
3871                          (read-file-name
3872                           (concat prompt " (default " name "): ")
3873                           dir name)))
3874                       ;; A list of splits was found.
3875                       (t
3876                        (setq split-name (nreverse split-name))
3877                        (let (result)
3878                          (let ((file-name-history
3879                                 (nconc split-name file-name-history)))
3880                            (setq result
3881                                  (expand-file-name
3882                                   (read-file-name
3883                                    (concat prompt " (`M-p' for defaults): ")
3884                                    gnus-article-save-directory
3885                                    (car split-name))
3886                                   gnus-article-save-directory)))
3887                          (car (push result file-name-history)))))))
3888                ;; Create the directory.
3889                (gnus-make-directory (file-name-directory file))
3890                ;; If we have read a directory, we append the default file name.
3891                (when (file-directory-p file)
3892                  (setq file (expand-file-name (file-name-nondirectory
3893                                                default-name)
3894                                               (file-name-as-directory file))))
3895                ;; Possibly translate some characters.
3896                (nnheader-translate-file-chars file))))))
3897     (gnus-make-directory (file-name-directory result))
3898     (when variable
3899       (set variable result))
3900     (when dir-var
3901       (set dir-var (file-name-directory result)))
3902     result))
3903
3904 (defun gnus-article-archive-name (group)
3905   "Return the first instance of an \"Archive-name\" in the current buffer."
3906   (let ((case-fold-search t))
3907     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3908       (nnheader-concat gnus-article-save-directory
3909                        (match-string 1)))))
3910
3911 (defun gnus-article-nndoc-name (group)
3912   "If GROUP is an nndoc group, return the name of the parent group."
3913   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3914     (gnus-group-get-parameter group 'save-article-group)))
3915
3916 (defun gnus-summary-save-in-rmail (&optional filename)
3917   "Append this article to Rmail file.
3918 Optional argument FILENAME specifies file name.
3919 Directory to save to is default to `gnus-article-save-directory'."
3920   (setq filename (gnus-read-save-file-name
3921                   "Save %s in rmail file" filename
3922                   gnus-rmail-save-name gnus-newsgroup-name
3923                   gnus-current-headers 'gnus-newsgroup-last-rmail))
3924   (with-current-buffer gnus-save-article-buffer
3925     (save-excursion
3926       (save-restriction
3927         (widen)
3928         ;; Note that unlike gnus-summary-save-in-mail, there is no
3929         ;; check to see if filename is Babyl.  Rmail in Emacs 23 does
3930         ;; not use Babyl.
3931         (gnus-output-to-rmail filename))))
3932   filename)
3933
3934 (defun gnus-summary-save-in-mail (&optional filename)
3935   "Append this article to Unix mail file.
3936 Optional argument FILENAME specifies file name.
3937 Directory to save to is default to `gnus-article-save-directory'."
3938   (setq filename (gnus-read-save-file-name
3939                   "Save %s in Unix mail file" filename
3940                   gnus-mail-save-name gnus-newsgroup-name
3941                   gnus-current-headers 'gnus-newsgroup-last-mail))
3942   (with-current-buffer gnus-save-article-buffer
3943     (save-excursion
3944       (save-restriction
3945         (widen)
3946         (if (and (file-readable-p filename)
3947                  (file-regular-p filename)
3948                  (mail-file-babyl-p filename))
3949             (gnus-output-to-rmail filename)
3950           (gnus-output-to-mail filename)))))
3951   filename)
3952
3953 (put 'gnus-summary-save-in-file :decode t)
3954 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3955 (defun gnus-summary-save-in-file (&optional filename overwrite)
3956   "Append this article to file.
3957 Optional argument FILENAME specifies file name.
3958 Directory to save to is default to `gnus-article-save-directory'."
3959   (setq filename (gnus-read-save-file-name
3960                   "Save %s in file" filename
3961                   gnus-file-save-name gnus-newsgroup-name
3962                   gnus-current-headers 'gnus-newsgroup-last-file))
3963   (with-current-buffer gnus-save-article-buffer
3964     (save-excursion
3965       (save-restriction
3966         (widen)
3967         (when (and overwrite
3968                    (file-exists-p filename))
3969           (delete-file filename))
3970         (gnus-output-to-file filename))))
3971   filename)
3972
3973 (put 'gnus-summary-write-to-file :decode t)
3974 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3975 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3976 (defun gnus-summary-write-to-file (&optional filename)
3977   "Write this article to a file, overwriting it if the file exists.
3978 Optional argument FILENAME specifies file name.
3979 The directory to save in defaults to `gnus-article-save-directory'."
3980   (setq filename (gnus-read-save-file-name
3981                   "Save %s in file" filename
3982                   gnus-file-save-name gnus-newsgroup-name
3983                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
3984   (gnus-summary-save-in-file filename t))
3985
3986 (put 'gnus-summary-save-body-in-file :decode t)
3987 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3988   "Append this article body to a file.
3989 Optional argument FILENAME specifies file name.
3990 The directory to save in defaults to `gnus-article-save-directory'."
3991   (setq filename (gnus-read-save-file-name
3992                   "Save %s body in file" filename
3993                   gnus-file-save-name gnus-newsgroup-name
3994                   gnus-current-headers 'gnus-newsgroup-last-file))
3995   (with-current-buffer gnus-save-article-buffer
3996     (save-excursion
3997       (save-restriction
3998         (widen)
3999         (when (article-goto-body)
4000           (narrow-to-region (point) (point-max)))
4001         (when (and overwrite
4002                    (file-exists-p filename))
4003           (delete-file filename))
4004         (gnus-output-to-file filename))))
4005   filename)
4006
4007 (put 'gnus-summary-write-body-to-file :decode t)
4008 (put 'gnus-summary-write-body-to-file
4009      :function 'gnus-summary-save-body-in-file)
4010 (defun gnus-summary-write-body-to-file (&optional filename)
4011   "Write this article body to a file, overwriting it if the file exists.
4012 Optional argument FILENAME specifies file name.
4013 The directory to save in defaults to `gnus-article-save-directory'."
4014   (setq filename (gnus-read-save-file-name
4015                   "Save %s body in file" filename
4016                   gnus-file-save-name gnus-newsgroup-name
4017                   gnus-current-headers nil 'gnus-newsgroup-last-directory))
4018   (gnus-summary-save-body-in-file filename t))
4019
4020 (put 'gnus-summary-save-in-pipe :decode t)
4021 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4022 (defun gnus-summary-save-in-pipe (&optional command raw)
4023   "Pipe this article to subprocess COMMAND.
4024 Valid values for COMMAND include:
4025   a string
4026     The executable command name and possibly arguments.
4027   nil
4028     You will be prompted for the command in the minibuffer.
4029   the symbol `default'
4030     It will be replaced with the command which the variable
4031     `gnus-summary-pipe-output-default-command' holds or the command
4032     last used for saving.
4033 Non-nil value for RAW overrides `:decode' and `:headers' properties
4034 and the raw article including all headers will be piped."
4035   (let ((article (gnus-summary-article-number))
4036         (decode (unless raw
4037                   (get 'gnus-summary-save-in-pipe :decode)))
4038         save-buffer default)
4039     (if article
4040         (if (vectorp (gnus-summary-article-header article))
4041             (save-current-buffer
4042               (gnus-summary-select-article decode decode nil article)
4043               (insert-buffer-substring
4044                (prog1
4045                    (if decode
4046                        gnus-article-buffer
4047                      gnus-original-article-buffer)
4048                  (setq save-buffer
4049                        (nnheader-set-temp-buffer " *Gnus Save*"))))
4050               ;; Remove unwanted headers.
4051               (when (and (not raw)
4052                          (or (get 'gnus-summary-save-in-pipe :headers)
4053                              (not gnus-save-all-headers)))
4054                 (let ((gnus-visible-headers
4055                        (or (symbol-value (get 'gnus-summary-save-in-pipe
4056                                               :headers))
4057                            gnus-saved-headers gnus-visible-headers))
4058                       (gnus-summary-buffer nil))
4059                   (article-hide-headers 1 t))))
4060           (error "%d is not a real article" article))
4061       (error "No article to pipe"))
4062     (setq default (or gnus-summary-pipe-output-default-command
4063                       gnus-last-shell-command))
4064     (unless (stringp command)
4065       (setq command
4066             (if (and (eq command 'default) default)
4067                 default
4068               (gnus-read-shell-command "Shell command on this article: "
4069                                        default))))
4070     (when (string-equal command "")
4071       (if default
4072           (setq command default)
4073         (error "A command is required")))
4074     (with-current-buffer save-buffer
4075       (save-restriction
4076         (widen)
4077         (shell-command-on-region (point-min) (point-max) command nil)))
4078     (gnus-kill-buffer save-buffer))
4079   (setq gnus-summary-pipe-output-default-command command))
4080
4081 (defun gnus-summary-pipe-to-muttprint (&optional command)
4082   "Pipe this article to muttprint."
4083   (unless (stringp command)
4084     (setq command (read-string
4085                    "Print using command: " gnus-summary-muttprint-program
4086                    nil gnus-summary-muttprint-program)))
4087   (let ((gnus-summary-pipe-output-default-command
4088          gnus-summary-pipe-output-default-command))
4089     (gnus-summary-save-in-pipe command))
4090   (setq gnus-summary-muttprint-program command))
4091
4092 ;;; Article file names when saving.
4093
4094 (defun gnus-capitalize-newsgroup (newsgroup)
4095   "Capitalize NEWSGROUP name."
4096   (when (not (zerop (length newsgroup)))
4097     (concat (char-to-string (upcase (aref newsgroup 0)))
4098             (substring newsgroup 1))))
4099
4100 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4101   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4102 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4103 Otherwise, it is like ~/News/news/group/num."
4104   (let ((default
4105           (expand-file-name
4106            (concat (if (gnus-use-long-file-name 'not-save)
4107                        (gnus-capitalize-newsgroup newsgroup)
4108                      (gnus-newsgroup-directory-form newsgroup))
4109                    "/" (int-to-string (mail-header-number headers)))
4110            gnus-article-save-directory)))
4111     (if (and last-file
4112              (string-equal (file-name-directory default)
4113                            (file-name-directory last-file))
4114              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4115         default
4116       (or last-file default))))
4117
4118 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4119   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4120 If variable `gnus-use-long-file-name' is non-nil, it is
4121 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
4122   (let ((default
4123           (expand-file-name
4124            (concat (if (gnus-use-long-file-name 'not-save)
4125                        newsgroup
4126                      (gnus-newsgroup-directory-form newsgroup))
4127                    "/" (int-to-string (mail-header-number headers)))
4128            gnus-article-save-directory)))
4129     (if (and last-file
4130              (string-equal (file-name-directory default)
4131                            (file-name-directory last-file))
4132              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4133         default
4134       (or last-file default))))
4135
4136 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4137   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4138 If variable `gnus-use-long-file-name' is non-nil, it is
4139 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
4140   (or last-file
4141       (expand-file-name
4142        (if (gnus-use-long-file-name 'not-save)
4143            newsgroup
4144          (file-relative-name
4145           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4146           default-directory))
4147        gnus-article-save-directory)))
4148
4149 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4150   "Generate file name from sender."
4151   (let ((from (mail-header-from headers)))
4152     (expand-file-name
4153      (if (and from (string-match "\\([^ <]+\\)@" from))
4154          (match-string 1 from)
4155        "nobody")
4156      gnus-article-save-directory)))
4157
4158 (defun article-verify-x-pgp-sig ()
4159   "Verify X-PGP-Sig."
4160   ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4161   (interactive)
4162   (if (gnus-buffer-live-p gnus-original-article-buffer)
4163       (let ((sig (with-current-buffer gnus-original-article-buffer
4164                    (gnus-fetch-field "X-PGP-Sig")))
4165             items info headers)
4166         (when (and sig
4167                    mml2015-use
4168                    (mml2015-clear-verify-function))
4169           (with-temp-buffer
4170             (insert-buffer-substring gnus-original-article-buffer)
4171             (setq items (split-string sig))
4172             (message-narrow-to-head)
4173             (let ((inhibit-point-motion-hooks t)
4174                   (case-fold-search t))
4175               ;; Don't verify multiple headers.
4176               (setq headers (mapconcat (lambda (header)
4177                                          (concat header ": "
4178                                                  (mail-fetch-field header)
4179                                                  "\n"))
4180                                        (split-string (nth 1 items) ",") "")))
4181             (delete-region (point-min) (point-max))
4182             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4183             (insert "X-Signed-Headers: " (nth 1 items) "\n")
4184             (insert headers)
4185             (widen)
4186             (forward-line)
4187             (while (not (eobp))
4188               (if (looking-at "^-")
4189                   (insert "- "))
4190               (forward-line))
4191             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4192             (insert "Version: " (car items) "\n\n")
4193             (insert (mapconcat 'identity (cddr items) "\n"))
4194             (insert "\n-----END PGP SIGNATURE-----\n")
4195             (let ((mm-security-handle (list (format "multipart/signed"))))
4196               (mml2015-clean-buffer)
4197               (let ((coding-system-for-write (or gnus-newsgroup-charset
4198                                                  'iso-8859-1)))
4199                 (funcall (mml2015-clear-verify-function)))
4200               (setq info
4201                     (or (mm-handle-multipart-ctl-parameter
4202                          mm-security-handle 'gnus-details)
4203                         (mm-handle-multipart-ctl-parameter
4204                          mm-security-handle 'gnus-info)))))
4205           (when info
4206             (let ((inhibit-read-only t) bface eface)
4207               (save-restriction
4208                 (message-narrow-to-head)
4209                 (goto-char (point-max))
4210                 (forward-line -1)
4211                 (setq bface (get-text-property (point-at-bol) 'face)
4212                       eface (get-text-property (1- (point-at-eol)) 'face))
4213                 (message-remove-header "X-Gnus-PGP-Verify")
4214                 (if (re-search-forward "^X-PGP-Sig:" nil t)
4215                     (forward-line)
4216                   (goto-char (point-max)))
4217                 (narrow-to-region (point) (point))
4218                 (insert "X-Gnus-PGP-Verify: " info "\n")
4219                 (goto-char (point-min))
4220                 (forward-line)
4221                 (while (not (eobp))
4222                   (if (not (looking-at "^[ \t]"))
4223                       (insert " "))
4224                   (forward-line))
4225                 ;; Do highlighting.
4226                 (goto-char (point-min))
4227                 (when (looking-at "\\([^:]+\\): *")
4228                   (put-text-property (match-beginning 1) (1+ (match-end 1))
4229                                      'face bface)
4230                   (put-text-property (match-end 0) (point-max)
4231                                      'face eface)))))))))
4232
4233 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4234
4235 (defun article-verify-cancel-lock ()
4236   "Verify Cancel-Lock header."
4237   (interactive)
4238   (if (gnus-buffer-live-p gnus-original-article-buffer)
4239       (canlock-verify gnus-original-article-buffer)))
4240
4241 (eval-and-compile
4242   (mapc
4243    (lambda (func)
4244      (let (afunc gfunc)
4245        (if (consp func)
4246            (setq afunc (car func)
4247                  gfunc (cdr func))
4248          (setq afunc func
4249                gfunc (intern (format "gnus-%s" func))))
4250        (defalias gfunc
4251          (when (fboundp afunc)
4252            `(lambda (&optional interactive &rest args)
4253               ,(documentation afunc t)
4254               (interactive (list t))
4255               (with-current-buffer gnus-article-buffer
4256                 (if interactive
4257                     (call-interactively ',afunc)
4258                   (apply ',afunc args))))))))
4259    '(article-hide-headers
4260      article-verify-x-pgp-sig
4261      article-verify-cancel-lock
4262      article-hide-boring-headers
4263      article-treat-overstrike
4264      article-treat-ansi-sequences
4265      article-fill-long-lines
4266      article-capitalize-sentences
4267      article-remove-cr
4268      article-remove-leading-whitespace
4269      article-display-x-face
4270      article-display-face
4271      article-de-quoted-unreadable
4272      article-de-base64-unreadable
4273      article-decode-HZ
4274      article-wash-html
4275      article-unsplit-urls
4276      article-hide-list-identifiers
4277      article-strip-banner
4278      article-babel
4279      article-hide-pem
4280      article-hide-signature
4281      article-strip-headers-in-body
4282      article-remove-trailing-blank-lines
4283      article-strip-leading-blank-lines
4284      article-strip-multiple-blank-lines
4285      article-strip-leading-space
4286      article-strip-trailing-space
4287      article-strip-blank-lines
4288      article-strip-all-blank-lines
4289      article-date-local
4290      article-date-english
4291      article-date-iso8601
4292      article-date-original
4293      article-date-ut
4294      article-decode-mime-words
4295      article-decode-charset
4296      article-decode-encoded-words
4297      article-date-user
4298      article-date-lapsed
4299      article-emphasize
4300      article-treat-dumbquotes
4301      article-treat-non-ascii
4302      article-normalize-headers
4303      ;;(article-show-all . gnus-article-show-all-headers)
4304      )))
4305 \f
4306 ;;;
4307 ;;; Gnus article mode
4308 ;;;
4309
4310 (put 'gnus-article-mode 'mode-class 'special)
4311
4312 (set-keymap-parent gnus-article-mode-map widget-keymap)
4313
4314 (gnus-define-keys gnus-article-mode-map
4315   " " gnus-article-goto-next-page
4316   "\177" gnus-article-goto-prev-page
4317   [delete] gnus-article-goto-prev-page
4318   [backspace] gnus-article-goto-prev-page
4319   "\C-c^" gnus-article-refer-article
4320   "h" gnus-article-show-summary
4321   "s" gnus-article-show-summary
4322   "\C-c\C-m" gnus-article-mail
4323   "?" gnus-article-describe-briefly