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