5de5d42a415d61b79c61143d9b7a2c6b3df411e9
[gnus] / lisp / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-sum)
33 (require 'gnus-spec)
34 (require 'gnus-int)
35 (require 'gnus-win)
36 (require 'mm-bodies)
37 (require 'mail-parse)
38 (require 'mm-decode)
39 (require 'mm-view)
40 (require 'wid-edit)
41 (require 'mm-uu)
42
43 (autoload 'gnus-msg-mail "gnus-msg" nil t)
44 (autoload 'gnus-button-mailto "gnus-msg")
45 (autoload 'gnus-button-reply "gnus-msg" nil t)
46
47 (defgroup gnus-article nil
48   "Article display."
49   :link '(custom-manual "(gnus)The Article Buffer")
50   :group 'gnus)
51
52 (defgroup gnus-article-treat nil
53   "Treating article parts."
54   :link '(custom-manual "(gnus)Article Hiding")
55   :group 'gnus-article)
56
57 (defgroup gnus-article-hiding nil
58   "Hiding article parts."
59   :link '(custom-manual "(gnus)Article Hiding")
60   :group 'gnus-article)
61
62 (defgroup gnus-article-highlight nil
63   "Article highlighting."
64   :link '(custom-manual "(gnus)Article Highlighting")
65   :group 'gnus-article
66   :group 'gnus-visual)
67
68 (defgroup gnus-article-signature nil
69   "Article signatures."
70   :link '(custom-manual "(gnus)Article Signature")
71   :group 'gnus-article)
72
73 (defgroup gnus-article-headers nil
74   "Article headers."
75   :link '(custom-manual "(gnus)Hiding Headers")
76   :group 'gnus-article)
77
78 (defgroup gnus-article-washing nil
79   "Special commands on articles."
80   :link '(custom-manual "(gnus)Article Washing")
81   :group 'gnus-article)
82
83 (defgroup gnus-article-emphasis nil
84   "Fontisizing articles."
85   :link '(custom-manual "(gnus)Article Fontisizing")
86   :group 'gnus-article)
87
88 (defgroup gnus-article-saving nil
89   "Saving articles."
90   :link '(custom-manual "(gnus)Saving Articles")
91   :group 'gnus-article)
92
93 (defgroup gnus-article-mime nil
94   "Worshiping the MIME wonder."
95   :link '(custom-manual "(gnus)Using MIME")
96   :group 'gnus-article)
97
98 (defgroup gnus-article-buttons nil
99   "Pushable buttons in the article buffer."
100   :link '(custom-manual "(gnus)Article Buttons")
101   :group 'gnus-article)
102
103 (defgroup gnus-article-various nil
104   "Other article options."
105   :link '(custom-manual "(gnus)Misc Article")
106   :group 'gnus-article)
107
108 (defcustom gnus-ignored-headers
109   '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
110     "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
111     "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
112     "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
113     "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
114     "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face"
115     "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
116     "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
117     "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
118     "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
119     "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
120     "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
121     "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
122     "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
123     "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
124     "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
125     "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
126     "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
127     "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
128     "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
129     "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
130     "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
131     "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
132     "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
133     "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
134     "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
135     "^X-Received:" "^Content-length:" "X-precedence:"
136     "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
137     "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
138     "^X-Abuse-Info:" "^X-From_:" "^X-Accept-Language:" "^Errors-To:"
139     "^X-BeenThere:" "^X-Mailman-Version:" "^List-Help:" "^List-Post:"
140     "^List-Subscribe:" "^List-Id:" "^List-Unsubscribe:" "^List-Archive:"
141      "^X-Content-length:" "^X-Posting-Agent:" "^Original-Received:"
142      "^X-Request-PGP:" "^X-Fingerprint:" "^X-WRIEnvto:" "^X-WRIEnvfrom:"
143      "^X-Virus-Scanned:" "^X-Delivery-Agent:" "^Posted-Date:" "^X-Gateway:"
144      "^X-Local-Origin:" "^X-Local-Destination:" "^X-UserInfo1:"
145      "^X-Received-Date:")
146   "*All headers that start with this regexp will be hidden.
147 This variable can also be a list of regexps of headers to be ignored.
148 If `gnus-visible-headers' is non-nil, this variable will be ignored."
149   :type '(choice :custom-show nil
150                  regexp
151                  (repeat regexp))
152   :group 'gnus-article-hiding)
153
154 (defcustom gnus-visible-headers
155   "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
156   "*All headers that do not match this regexp will be hidden.
157 This variable can also be a list of regexp of headers to remain visible.
158 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
159   :type '(repeat :value-to-internal (lambda (widget value)
160                                       (custom-split-regexp-maybe value))
161                  :match (lambda (widget value)
162                           (or (stringp value)
163                               (widget-editable-list-match widget value)))
164                  regexp)
165   :group 'gnus-article-hiding)
166
167 (defcustom gnus-sorted-header-list
168   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
169     "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
170   "*This variable is a list of regular expressions.
171 If it is non-nil, headers that match the regular expressions will
172 be placed first in the article buffer in the sequence specified by
173 this list."
174   :type '(repeat regexp)
175   :group 'gnus-article-hiding)
176
177 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
178   "Headers that are only to be displayed if they have interesting data.
179 Possible values in this list are:
180
181   'empty       Headers with no content.
182   'newsgroups  Newsgroup identical to Gnus group.
183   'to-address  To identical to To-address.
184   'followup-to Followup-to identical to Newsgroups.
185   'reply-to    Reply-to identical to From.
186   'date        Date less than four days old.
187   'long-to     To and/or Cc longer than 1024 characters.
188   'many-to     Multiple To and/or Cc."
189   :type '(set (const :tag "Headers with no content." empty)
190               (const :tag "Newsgroups identical to Gnus group." newsgroups)
191               (const :tag "To identical to To-address." to-address)
192               (const :tag "Followup-to identical to Newsgroups." followup-to)
193               (const :tag "Reply-to identical to From." reply-to)
194               (const :tag "Date less than four days old." date)
195               (const :tag "To and/or Cc longer than 1024 characters." long-to)
196               (const :tag "Multiple To and/or Cc headers." many-to))
197   :group 'gnus-article-hiding)
198
199 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
200   "Regexp matching signature separator.
201 This can also be a list of regexps.  In that case, it will be checked
202 from head to tail looking for a separator.  Searches will be done from
203 the end of the buffer."
204   :type '(repeat string)
205   :group 'gnus-article-signature)
206
207 (defcustom gnus-signature-limit nil
208   "Provide a limit to what is considered a signature.
209 If it is a number, no signature may not be longer (in characters) than
210 that number.  If it is a floating point number, no signature may be
211 longer (in lines) than that number.  If it is a function, the function
212 will be called without any parameters, and if it returns nil, there is
213 no signature in the buffer.  If it is a string, it will be used as a
214 regexp.  If it matches, the text in question is not a signature."
215   :type '(choice (integer :value 200)
216                  (number :value 4.0)
217                  (function :value fun)
218                  (regexp :value ".*"))
219   :group 'gnus-article-signature)
220
221 (defcustom gnus-hidden-properties '(invisible t intangible t)
222   "Property list to use for hiding text."
223   :type 'sexp
224   :group 'gnus-article-hiding)
225
226 ;; Fixme: This isn't the right thing for mixed graphical and and
227 ;; non-graphical frames in a session.
228 (defcustom gnus-article-x-face-command
229   (if (featurep 'xemacs)
230       (if (or (gnus-image-type-available-p 'xface)
231               (gnus-image-type-available-p 'pbm))
232           'gnus-display-x-face-in-from
233         "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
234     (if (gnus-image-type-available-p 'pbm)
235         'gnus-display-x-face-in-from
236       "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
237 display -"))
238   "*String or function to be executed to display an X-Face header.
239 If it is a string, the command will be executed in a sub-shell
240 asynchronously.  The compressed face will be piped to this command."
241   :type `(choice string
242                  (function-item gnus-display-x-face-in-from)
243                  function)
244   :version "21.1"
245   :group 'gnus-article-washing)
246
247 (defcustom gnus-article-x-face-too-ugly nil
248   "Regexp matching posters whose face shouldn't be shown automatically."
249   :type '(choice regexp (const nil))
250   :group 'gnus-article-washing)
251
252 (defcustom gnus-article-banner-alist nil
253   "Banner alist for stripping.
254 For example,
255      ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
256   :version "21.1"
257   :type '(repeat (cons symbol regexp))
258   :group 'gnus-article-washing)
259
260 (gnus-define-group-parameter
261  banner
262  :variable-document
263  "Alist of regexps (to match group names) and banner."
264  :variable-group gnus-article-washing
265  :parameter-type
266  '(choice :tag "Banner"
267           :value nil
268           (const :tag "Remove signature" signature)
269           (symbol :tag "Item in `gnus-article-banner-alist'" none)
270           regexp
271           (const :tag "None" nil))
272  :parameter-document
273  "If non-nil, specify how to remove `banners' from articles.
274
275 Symbol `signature' means to remove signatures delimited by
276 `gnus-signature-separator'.  Any other symbol is used to look up a
277 regular expression to match the banner in `gnus-article-banner-alist'.
278 A string is used as a regular expression to match the banner
279 directly.")
280
281 (defcustom gnus-emphasis-alist
282   (let ((format
283          "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
284         (types
285          '(("\\*" "\\*" bold)
286            ("_" "_" underline)
287            ("/" "/" italic)
288            ("_/" "/_" underline-italic)
289            ("_\\*" "\\*_" underline-bold)
290            ("\\*/" "/\\*" bold-italic)
291            ("_\\*/" "/\\*_" underline-bold-italic))))
292     `(,@(mapcar
293          (lambda (spec)
294            (list
295             (format format (car spec) (cadr spec))
296             2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
297          types)
298         ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
299          2 3 gnus-emphasis-underline)))
300   "*Alist that says how to fontify certain phrases.
301 Each item looks like this:
302
303   (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
304
305 The first element is a regular expression to be matched.  The second
306 is a number that says what regular expression grouping used to find
307 the entire emphasized word.  The third is a number that says what
308 regexp grouping should be displayed and highlighted.  The fourth
309 is the face used for highlighting."
310   :type '(repeat (list :value ("" 0 0 default)
311                        regexp
312                        (integer :tag "Match group")
313                        (integer :tag "Emphasize group")
314                        face))
315   :group 'gnus-article-emphasis)
316
317 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
318   "A regexp to describe whitespace which should not be emphasized.
319 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
320 The former avoids underlining of leading and trailing whitespace,
321 and the latter avoids underlining any whitespace at all."
322   :version "21.1"
323   :group 'gnus-article-emphasis
324   :type 'regexp)
325
326 (defface gnus-emphasis-bold '((t (:bold t)))
327   "Face used for displaying strong emphasized text (*word*)."
328   :group 'gnus-article-emphasis)
329
330 (defface gnus-emphasis-italic '((t (:italic t)))
331   "Face used for displaying italic emphasized text (/word/)."
332   :group 'gnus-article-emphasis)
333
334 (defface gnus-emphasis-underline '((t (:underline t)))
335   "Face used for displaying underlined emphasized text (_word_)."
336   :group 'gnus-article-emphasis)
337
338 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
339   "Face used for displaying underlined bold emphasized text (_*word*_)."
340   :group 'gnus-article-emphasis)
341
342 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
343   "Face used for displaying underlined italic emphasized text (_/word/_)."
344   :group 'gnus-article-emphasis)
345
346 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
347   "Face used for displaying bold italic emphasized text (/*word*/)."
348   :group 'gnus-article-emphasis)
349
350 (defface gnus-emphasis-underline-bold-italic
351   '((t (:bold t :italic t :underline t)))
352   "Face used for displaying underlined bold italic emphasized text.
353 Esample: (_/*word*/_)."
354   :group 'gnus-article-emphasis)
355
356 (defface gnus-emphasis-highlight-words
357   '((t (:background "black" :foreground "yellow")))
358   "Face used for displaying highlighted words."
359   :group 'gnus-article-emphasis)
360
361 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
362   "Format for display of Date headers in article bodies.
363 See `format-time-string' for the possible values.
364
365 The variable can also be function, which should return a complete Date
366 header.  The function is called with one argument, the time, which can
367 be fed to `format-time-string'."
368   :type '(choice string symbol)
369   :link '(custom-manual "(gnus)Article Date")
370   :group 'gnus-article-washing)
371
372 (eval-and-compile
373   (autoload 'mail-extract-address-components "mail-extr"))
374
375 (defcustom gnus-save-all-headers t
376   "*If non-nil, don't remove any headers before saving."
377   :group 'gnus-article-saving
378   :type 'boolean)
379
380 (defcustom gnus-prompt-before-saving 'always
381   "*This variable says how much prompting is to be done when saving articles.
382 If it is nil, no prompting will be done, and the articles will be
383 saved to the default files.  If this variable is `always', each and
384 every article that is saved will be preceded by a prompt, even when
385 saving large batches of articles.  If this variable is neither nil not
386 `always', there the user will be prompted once for a file name for
387 each invocation of the saving commands."
388   :group 'gnus-article-saving
389   :type '(choice (item always)
390                  (item :tag "never" nil)
391                  (sexp :tag "once" :format "%t\n" :value t)))
392
393 (defcustom gnus-saved-headers gnus-visible-headers
394   "Headers to keep if `gnus-save-all-headers' is nil.
395 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
396 If that variable is nil, however, all headers that match this regexp
397 will be kept while the rest will be deleted before saving."
398   :group 'gnus-article-saving
399   :type 'regexp)
400
401 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
402   "A function to save articles in your favourite format.
403 The function must be interactively callable (in other words, it must
404 be an Emacs command).
405
406 Gnus provides the following functions:
407
408 * gnus-summary-save-in-rmail (Rmail format)
409 * gnus-summary-save-in-mail (Unix mail format)
410 * gnus-summary-save-in-folder (MH folder)
411 * gnus-summary-save-in-file (article format)
412 * gnus-summary-save-body-in-file (article body)
413 * gnus-summary-save-in-vm (use VM's folder format)
414 * gnus-summary-write-to-file (article format -- overwrite)."
415   :group 'gnus-article-saving
416   :type '(radio (function-item gnus-summary-save-in-rmail)
417                 (function-item gnus-summary-save-in-mail)
418                 (function-item gnus-summary-save-in-folder)
419                 (function-item gnus-summary-save-in-file)
420                 (function-item gnus-summary-save-body-in-file)
421                 (function-item gnus-summary-save-in-vm)
422                 (function-item gnus-summary-write-to-file)))
423
424 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
425   "A function generating a file name to save articles in Rmail format.
426 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
427   :group 'gnus-article-saving
428   :type 'function)
429
430 (defcustom gnus-mail-save-name 'gnus-plain-save-name
431   "A function generating a file name to save articles in Unix mail format.
432 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
433   :group 'gnus-article-saving
434   :type 'function)
435
436 (defcustom gnus-folder-save-name 'gnus-folder-save-name
437   "A function generating a file name to save articles in MH folder.
438 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
439   :group 'gnus-article-saving
440   :type 'function)
441
442 (defcustom gnus-file-save-name 'gnus-numeric-save-name
443   "A function generating a file name to save articles in article format.
444 The function is called with NEWSGROUP, HEADERS, and optional
445 LAST-FILE."
446   :group 'gnus-article-saving
447   :type 'function)
448
449 (defcustom gnus-split-methods
450   '((gnus-article-archive-name)
451     (gnus-article-nndoc-name))
452   "*Variable used to suggest where articles are to be saved.
453 For instance, if you would like to save articles related to Gnus in
454 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
455 you could set this variable to something like:
456
457  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
458    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
459
460 This variable is an alist where the where the key is the match and the
461 value is a list of possible files to save in if the match is non-nil.
462
463 If the match is a string, it is used as a regexp match on the
464 article.  If the match is a symbol, that symbol will be funcalled
465 from the buffer of the article to be saved with the newsgroup as the
466 parameter.  If it is a list, it will be evaled in the same buffer.
467
468 If this form or function returns a string, this string will be used as
469 a possible file name; and if it returns a non-nil list, that list will
470 be used as possible file names."
471   :group 'gnus-article-saving
472   :type '(repeat (choice (list :value (fun) function)
473                          (cons :value ("" "") regexp (repeat string))
474                          (sexp :value nil))))
475
476 (defcustom gnus-page-delimiter "^\^L"
477   "*Regexp describing what to use as article page delimiters.
478 The default value is \"^\^L\", which is a form linefeed at the
479 beginning of a line."
480   :type 'regexp
481   :group 'gnus-article-various)
482
483 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
484   "*The format specification for the article mode line.
485 See `gnus-summary-mode-line-format' for a closer description.
486
487 The following additional specs are available:
488
489 %w  The article washing status.
490 %m  The number of MIME parts in the article."
491   :type 'string
492   :group 'gnus-article-various)
493
494 (defcustom gnus-article-mode-hook nil
495   "*A hook for Gnus article mode."
496   :type 'hook
497   :group 'gnus-article-various)
498
499 (when (featurep 'xemacs)
500   ;; Extracted from gnus-xmas-define in order to preserve user settings
501   (when (fboundp 'turn-off-scroll-in-place)
502     (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
503   ;; Extracted from gnus-xmas-redefine in order to preserve user settings
504   (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
505
506 (defcustom gnus-article-menu-hook nil
507   "*Hook run after the creation of the article mode menu."
508   :type 'hook
509   :group 'gnus-article-various)
510
511 (defcustom gnus-article-prepare-hook nil
512   "*A hook called after an article has been prepared in the article buffer."
513   :type 'hook
514   :group 'gnus-article-various)
515
516 (defcustom gnus-article-hide-pgp-hook nil
517   "*A hook called after successfully hiding a PGP signature."
518   :type 'hook
519   :group 'gnus-article-various)
520
521 (defcustom gnus-article-button-face 'bold
522   "Face used for highlighting buttons in the article buffer.
523
524 An article button is a piece of text that you can activate by pressing
525 `RET' or `mouse-2' above it."
526   :type 'face
527   :group 'gnus-article-buttons)
528
529 (defcustom gnus-article-mouse-face 'highlight
530   "Face used for mouse highlighting in the article buffer.
531
532 Article buttons will be displayed in this face when the cursor is
533 above them."
534   :type 'face
535   :group 'gnus-article-buttons)
536
537 (defcustom gnus-signature-face 'gnus-signature-face
538   "Face used for highlighting a signature in the article buffer.
539 Obsolete; use the face `gnus-signature-face' for customizations instead."
540   :type 'face
541   :group 'gnus-article-highlight
542   :group 'gnus-article-signature)
543
544 (defface gnus-signature-face
545   '((t
546      (:italic t)))
547   "Face used for highlighting a signature in the article buffer."
548   :group 'gnus-article-highlight
549   :group 'gnus-article-signature)
550
551 (defface gnus-header-from-face
552   '((((class color)
553       (background dark))
554      (:foreground "spring green"))
555     (((class color)
556       (background light))
557      (:foreground "red3"))
558     (t
559      (:italic t)))
560   "Face used for displaying from headers."
561   :group 'gnus-article-headers
562   :group 'gnus-article-highlight)
563
564 (defface gnus-header-subject-face
565   '((((class color)
566       (background dark))
567      (:foreground "SeaGreen3"))
568     (((class color)
569       (background light))
570      (:foreground "red4"))
571     (t
572      (:bold t :italic t)))
573   "Face used for displaying subject headers."
574   :group 'gnus-article-headers
575   :group 'gnus-article-highlight)
576
577 (defface gnus-header-newsgroups-face
578   '((((class color)
579       (background dark))
580      (:foreground "yellow" :italic t))
581     (((class color)
582       (background light))
583      (:foreground "MidnightBlue" :italic t))
584     (t
585      (:italic t)))
586   "Face used for displaying newsgroups headers."
587   :group 'gnus-article-headers
588   :group 'gnus-article-highlight)
589
590 (defface gnus-header-name-face
591   '((((class color)
592       (background dark))
593      (:foreground "SeaGreen"))
594     (((class color)
595       (background light))
596      (:foreground "maroon"))
597     (t
598      (:bold t)))
599   "Face used for displaying header names."
600   :group 'gnus-article-headers
601   :group 'gnus-article-highlight)
602
603 (defface gnus-header-content-face
604   '((((class color)
605       (background dark))
606      (:foreground "forest green" :italic t))
607     (((class color)
608       (background light))
609      (:foreground "indianred4" :italic t))
610     (t
611      (:italic t)))  "Face used for displaying header content."
612   :group 'gnus-article-headers
613   :group 'gnus-article-highlight)
614
615 (defcustom gnus-header-face-alist
616   '(("From" nil gnus-header-from-face)
617     ("Subject" nil gnus-header-subject-face)
618     ("Newsgroups:.*," nil gnus-header-newsgroups-face)
619     ("" gnus-header-name-face gnus-header-content-face))
620   "*Controls highlighting of article header.
621
622 An alist of the form (HEADER NAME CONTENT).
623
624 HEADER is a regular expression which should match the name of an
625 header header and NAME and CONTENT are either face names or nil.
626
627 The name of each header field will be displayed using the face
628 specified by the first element in the list where HEADER match the
629 header name and NAME is non-nil.  Similarly, the content will be
630 displayed by the first non-nil matching CONTENT face."
631   :group 'gnus-article-headers
632   :group 'gnus-article-highlight
633   :type '(repeat (list (regexp :tag "Header")
634                        (choice :tag "Name"
635                                (item :tag "skip" nil)
636                                (face :value default))
637                        (choice :tag "Content"
638                                (item :tag "skip" nil)
639                                (face :value default)))))
640
641 (defcustom gnus-article-decode-hook
642   '(article-decode-charset article-decode-encoded-words
643                            article-decode-group-name)
644   "*Hook run to decode charsets in articles."
645   :group 'gnus-article-headers
646   :type 'hook)
647
648 (defcustom gnus-display-mime-function 'gnus-display-mime
649   "Function to display MIME articles."
650   :group 'gnus-article-mime
651   :type 'function)
652
653 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
654   "Function used to decode headers.")
655
656 (defvar gnus-article-dumbquotes-map
657   '(("\200" "EUR")
658     ("\202" ",")
659     ("\203" "f")
660     ("\204" ",,")
661     ("\205" "...")
662     ("\213" "<")
663     ("\214" "OE")
664     ("\221" "`")
665     ("\222" "'")
666     ("\223" "``")
667     ("\224" "\"")
668     ("\225" "*")
669     ("\226" "-")
670     ("\227" "--")
671     ("\231" "(TM)")
672     ("\233" ">")
673     ("\234" "oe")
674     ("\264" "'"))
675   "Table for MS-to-Latin1 translation.")
676
677 (defcustom gnus-ignored-mime-types nil
678   "List of MIME types that should be ignored by Gnus."
679   :version "21.1"
680   :group 'gnus-article-mime
681   :type '(repeat regexp))
682
683 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
684   "List of MIME types that should not be given buttons when rendered inline.
685 See also `gnus-buttonized-mime-types' which may override this variable."
686   :version "21.1"
687   :group 'gnus-article-mime
688   :type '(repeat regexp))
689
690 (defcustom gnus-buttonized-mime-types nil
691   "List of MIME types that should be given buttons when rendered inline.
692 If set, this variable overrides `gnus-unbuttonized-mime-types'.
693 To see e.g. security buttons you could set this to
694 `(\"multipart/signed\")'."
695   :version "21.1"
696   :group 'gnus-article-mime
697   :type '(repeat regexp))
698
699 (defcustom gnus-body-boundary-delimiter "_"
700   "String used to delimit header and body.
701 This variable is used by `gnus-article-treat-body-boundary' which can
702 be controlled by `gnus-treat-body-boundary'."
703   :group 'gnus-article-various
704   :type '(choice (item :tag "None" :value nil)
705                  string))
706
707 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces")
708   "*Defines the location of the faces database.
709 For information on obtaining this database of pretty pictures, please
710 see http://www.cs.indiana.edu/picons/ftp/index.html"
711   :type 'directory
712   :group 'gnus-picon)
713
714 (defun gnus-picons-installed-p ()
715   "Say whether picons are installed on your machine."
716   (let ((installed nil))
717     (dolist (database gnus-picon-databases)
718       (when (file-exists-p database)
719         (setq installed t)))
720     installed))
721
722 (defcustom gnus-article-mime-part-function nil
723   "Function called with a MIME handle as the argument.
724 This is meant for people who want to do something automatic based
725 on parts -- for instance, adding Vcard info to a database."
726   :group 'gnus-article-mime
727   :type 'function)
728
729 (defcustom gnus-mime-multipart-functions nil
730   "An alist of MIME types to functions to display them."
731   :version "21.1"
732   :group 'gnus-article-mime
733   :type 'alist)
734
735 (defcustom gnus-article-date-lapsed-new-header nil
736   "Whether the X-Sent and Date headers can coexist.
737 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
738 either replace the old \"Date:\" header (if this variable is nil), or
739 be added below it (otherwise)."
740   :version "21.1"
741   :group 'gnus-article-headers
742   :type 'boolean)
743
744 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
745   "Function called with a MIME handle as the argument.
746 This is meant for people who want to view first matched part.
747 For `undisplayed-alternative' (default), the first undisplayed
748 part or alternative part is used.  For `undisplayed', the first
749 undisplayed part is used.  For a function, the first part which
750 the function return `t' is used.  For `nil', the first part is
751 used."
752   :version "21.1"
753   :group 'gnus-article-mime
754   :type '(choice
755           (item :tag "first" :value nil)
756           (item :tag "undisplayed" :value undisplayed)
757           (item :tag "undisplayed or alternative"
758                 :value undisplayed-alternative)
759           (function)))
760
761 (defcustom gnus-mime-action-alist
762   '(("save to file" . gnus-mime-save-part)
763     ("save and strip" . gnus-mime-save-part-and-strip)
764     ("display as text" . gnus-mime-inline-part)
765     ("view the part" . gnus-mime-view-part)
766     ("pipe to command" . gnus-mime-pipe-part)
767     ("toggle display" . gnus-article-press-button)
768     ("toggle display" . gnus-article-view-part-as-charset)
769     ("view as type" . gnus-mime-view-part-as-type)
770     ("internalize type" . gnus-mime-internalize-part)
771     ("externalize type" . gnus-mime-externalize-part))
772   "An alist of actions that run on the MIME attachment."
773   :group 'gnus-article-mime
774   :type '(repeat (cons (string :tag "name")
775                        (function))))
776
777 (defcustom gnus-mime-action-alist
778   '(("save to file" . gnus-mime-save-part)
779     ("display as text" . gnus-mime-inline-part)
780     ("view the part" . gnus-mime-view-part)
781     ("pipe to command" . gnus-mime-pipe-part)
782     ("toggle display" . gnus-article-press-button)
783     ("view as type" . gnus-mime-view-part-as-type)
784     ("internalize type" . gnus-mime-internalize-part)
785     ("externalize type" . gnus-mime-externalize-part))
786   "An alist of actions that run on the MIME attachment."
787   :version "21.1"
788   :group 'gnus-article-mime
789   :type '(repeat (cons (string :tag "name")
790                        (function))))
791
792 ;;;
793 ;;; The treatment variables
794 ;;;
795
796 (defvar gnus-part-display-hook nil
797   "Hook called on parts that are to receive treatment.")
798
799 (defvar gnus-article-treat-custom
800   '(choice (const :tag "Off" nil)
801            (const :tag "On" t)
802            (const :tag "Header" head)
803            (const :tag "Last" last)
804            (integer :tag "Less")
805            (repeat :tag "Groups" regexp)
806            (sexp :tag "Predicate")))
807
808 (defvar gnus-article-treat-head-custom
809   '(choice (const :tag "Off" nil)
810            (const :tag "Header" head)))
811
812 (defvar gnus-article-treat-types '("text/plain")
813   "Parts to treat.")
814
815 (defvar gnus-inhibit-treatment nil
816   "Whether to inhibit treatment.")
817
818 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
819   "Highlight the signature.
820 Valid values are nil, t, `head', `last', an integer or a predicate.
821 See Info node `(gnus)Customizing Articles'."
822   :group 'gnus-article-treat
823   :type gnus-article-treat-custom)
824 (put 'gnus-treat-highlight-signature 'highlight t)
825
826 (defcustom gnus-treat-buttonize 100000
827   "Add buttons.
828 Valid values are nil, t, `head', `last', an integer or a predicate.
829 See Info node `(gnus)Customizing Articles'."
830   :group 'gnus-article-treat
831   :type gnus-article-treat-custom)
832 (put 'gnus-treat-buttonize 'highlight t)
833
834 (defcustom gnus-treat-buttonize-head 'head
835   "Add buttons to the head.
836 Valid values are nil, t, `head', `last', an integer or a predicate.
837 See Info node `(gnus)Customizing Articles' for details."
838   :group 'gnus-article-treat
839   :type gnus-article-treat-head-custom)
840 (put 'gnus-treat-buttonize-head 'highlight t)
841
842 (defcustom gnus-treat-emphasize
843   (and (or window-system
844            (featurep 'xemacs)
845            (>= (string-to-number emacs-version) 21))
846        50000)
847   "Emphasize text.
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See Info node `(gnus)Customizing Articles' for details."
850   :group 'gnus-article-treat
851   :type gnus-article-treat-custom)
852 (put 'gnus-treat-emphasize 'highlight t)
853
854 (defcustom gnus-treat-strip-cr nil
855   "Remove carriage returns.
856 Valid values are nil, t, `head', `last', an integer or a predicate.
857 See Info node `(gnus)Customizing Articles' for details."
858   :group 'gnus-article-treat
859   :type gnus-article-treat-custom)
860
861 (defcustom gnus-treat-unsplit-urls nil
862   "Remove newlines from within URLs.
863 Valid values are nil, t, `head', `last', an integer or a predicate.
864 See Info node `(gnus)Customizing Articles' for details."
865   :group 'gnus-article-treat
866   :type gnus-article-treat-custom)
867
868 (defcustom gnus-treat-leading-whitespace nil
869   "Remove leading whitespace in headers.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See Info node `(gnus)Customizing Articles' for details."
872   :group 'gnus-article-treat
873   :type gnus-article-treat-custom)
874
875 (defcustom gnus-treat-hide-headers 'head
876   "Hide headers.
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See Info node `(gnus)Customizing Articles' for details."
879   :group 'gnus-article-treat
880   :type gnus-article-treat-head-custom)
881
882 (defcustom gnus-treat-hide-boring-headers nil
883   "Hide boring headers.
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See Info node `(gnus)Customizing Articles' for details."
886   :group 'gnus-article-treat
887   :type gnus-article-treat-head-custom)
888
889 (defcustom gnus-treat-hide-signature nil
890   "Hide the signature.
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See Info node `(gnus)Customizing Articles' for details."
893   :group 'gnus-article-treat
894   :type gnus-article-treat-custom)
895
896 (defcustom gnus-treat-fill-article nil
897   "Fill the article.
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See Info node `(gnus)Customizing Articles' for details."
900   :group 'gnus-article-treat
901   :type gnus-article-treat-custom)
902
903 (defcustom gnus-treat-hide-citation nil
904   "Hide cited text.
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See Info node `(gnus)Customizing Articles' for details."
907   :group 'gnus-article-treat
908   :type gnus-article-treat-custom)
909
910 (defcustom gnus-treat-hide-citation-maybe nil
911   "Hide cited text.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See Info node `(gnus)Customizing Articles' for details."
914   :group 'gnus-article-treat
915   :type gnus-article-treat-custom)
916
917 (defcustom gnus-treat-strip-list-identifiers 'head
918   "Strip list identifiers from `gnus-list-identifiers`.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See Info node `(gnus)Customizing Articles' for details."
921   :version "21.1"
922   :group 'gnus-article-treat
923   :type gnus-article-treat-custom)
924
925 (defcustom gnus-treat-strip-pgp t
926   "Strip PGP signatures.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See Info node `(gnus)Customizing Articles' for details."
929   :group 'gnus-article-treat
930   :type gnus-article-treat-custom)
931
932 (defcustom gnus-treat-strip-pem nil
933   "Strip PEM signatures.
934 Valid values are nil, t, `head', `last', an integer or a predicate.
935 See Info node `(gnus)Customizing Articles' for details."
936   :group 'gnus-article-treat
937   :type gnus-article-treat-custom)
938
939 (defcustom gnus-treat-strip-banner t
940   "Strip banners from articles.
941 The banner to be stripped is specified in the `banner' group parameter.
942 Valid values are nil, t, `head', `last', an integer or a predicate.
943 See Info node `(gnus)Customizing Articles' for details."
944   :group 'gnus-article-treat
945   :type gnus-article-treat-custom)
946
947 (defcustom gnus-treat-highlight-headers 'head
948   "Highlight the headers.
949 Valid values are nil, t, `head', `last', an integer or a predicate.
950 See Info node `(gnus)Customizing Articles' for details."
951   :group 'gnus-article-treat
952   :type gnus-article-treat-head-custom)
953 (put 'gnus-treat-highlight-headers 'highlight t)
954
955 (defcustom gnus-treat-highlight-citation t
956   "Highlight cited text.
957 Valid values are nil, t, `head', `last', an integer or a predicate.
958 See Info node `(gnus)Customizing Articles' for details."
959   :group 'gnus-article-treat
960   :type gnus-article-treat-custom)
961 (put 'gnus-treat-highlight-citation 'highlight t)
962
963 (defcustom gnus-treat-date-ut nil
964   "Display the Date in UT (GMT).
965 Valid values are nil, t, `head', `last', an integer or a predicate.
966 See Info node `(gnus)Customizing Articles' for details."
967   :group 'gnus-article-treat
968   :type gnus-article-treat-head-custom)
969
970 (defcustom gnus-treat-date-local nil
971   "Display the Date in the local timezone.
972 Valid values are nil, t, `head', `last', an integer or a predicate.
973 See Info node `(gnus)Customizing Articles' for details."
974   :group 'gnus-article-treat
975   :type gnus-article-treat-head-custom)
976
977 (defcustom gnus-treat-date-english nil
978   "Display the Date in a format that can be read aloud in English.
979 Valid values are nil, t, `head', `last', an integer or a predicate.
980 See Info node `(gnus)Customizing Articles' for details."
981   :group 'gnus-article-treat
982   :type gnus-article-treat-head-custom)
983
984 (defcustom gnus-treat-date-lapsed nil
985   "Display the Date header in a way that says how much time has elapsed.
986 Valid values are nil, t, `head', `last', an integer or a predicate.
987 See Info node `(gnus)Customizing Articles' for details."
988   :group 'gnus-article-treat
989   :type gnus-article-treat-head-custom)
990
991 (defcustom gnus-treat-date-original nil
992   "Display the date in the original timezone.
993 Valid values are nil, t, `head', `last', an integer or a predicate.
994 See Info node `(gnus)Customizing Articles' for details."
995   :group 'gnus-article-treat
996   :type gnus-article-treat-head-custom)
997
998 (defcustom gnus-treat-date-iso8601 nil
999   "Display the date in the ISO8601 format.
1000 Valid values are nil, t, `head', `last', an integer or a predicate.
1001 See Info node `(gnus)Customizing Articles' for details."
1002   :version "21.1"
1003   :group 'gnus-article-treat
1004   :type gnus-article-treat-head-custom)
1005
1006 (defcustom gnus-treat-date-user-defined nil
1007   "Display the date in a user-defined format.
1008 The format is defined by the `gnus-article-time-format' variable.
1009 Valid values are nil, t, `head', `last', an integer or a predicate.
1010 See Info node `(gnus)Customizing Articles' for details."
1011   :group 'gnus-article-treat
1012   :type gnus-article-treat-head-custom)
1013
1014 (defcustom gnus-treat-strip-headers-in-body t
1015   "Strip the X-No-Archive header line from the beginning of the body.
1016 Valid values are nil, t, `head', `last', an integer or a predicate.
1017 See Info node `(gnus)Customizing Articles' for details."
1018   :version "21.1"
1019   :group 'gnus-article-treat
1020   :type gnus-article-treat-custom)
1021
1022 (defcustom gnus-treat-strip-trailing-blank-lines nil
1023   "Strip trailing blank lines.
1024 Valid values are nil, t, `head', `last', an integer or a predicate.
1025 See Info node `(gnus)Customizing Articles' for details."
1026   :group 'gnus-article-treat
1027   :type gnus-article-treat-custom)
1028
1029 (defcustom gnus-treat-strip-leading-blank-lines nil
1030   "Strip leading blank lines.
1031 Valid values are nil, t, `head', `last', an integer or a predicate.
1032 See Info node `(gnus)Customizing Articles' for details."
1033   :group 'gnus-article-treat
1034   :type gnus-article-treat-custom)
1035
1036 (defcustom gnus-treat-strip-multiple-blank-lines nil
1037   "Strip multiple blank lines.
1038 Valid values are nil, t, `head', `last', an integer or a predicate.
1039 See Info node `(gnus)Customizing Articles' for details."
1040   :group 'gnus-article-treat
1041   :type gnus-article-treat-custom)
1042
1043 (defcustom gnus-treat-unfold-headers 'head
1044   "Unfold folded header lines.
1045 Valid values are nil, t, `head', `last', an integer or a predicate.
1046 See Info node `(gnus)Customizing Articles' for details."
1047   :group 'gnus-article-treat
1048   :type gnus-article-treat-custom)
1049
1050 (defcustom gnus-treat-fold-headers nil
1051   "Fold headers.
1052 Valid values are nil, t, `head', `last', an integer or a predicate.
1053 See Info node `(gnus)Customizing Articles' for details."
1054   :group 'gnus-article-treat
1055   :type gnus-article-treat-custom)
1056
1057 (defcustom gnus-treat-fold-newsgroups 'head
1058   "Fold the Newsgroups and Followup-To headers.
1059 Valid values are nil, t, `head', `last', an integer or a predicate.
1060 See Info node `(gnus)Customizing Articles' for details."
1061   :group 'gnus-article-treat
1062   :type gnus-article-treat-custom)
1063
1064 (defcustom gnus-treat-overstrike t
1065   "Treat overstrike highlighting.
1066 Valid values are nil, t, `head', `last', an integer or a predicate.
1067 See Info node `(gnus)Customizing Articles' for details."
1068   :group 'gnus-article-treat
1069   :type gnus-article-treat-custom)
1070 (put 'gnus-treat-overstrike 'highlight t)
1071
1072 (defcustom gnus-treat-display-xface
1073   (and (or (and (fboundp 'image-type-available-p)
1074                 (image-type-available-p 'xbm)
1075                 (string-match "^0x" (shell-command-to-string "uncompface")))
1076            (and (featurep 'xemacs)
1077                 (featurep 'xface)))
1078        'head)
1079   "Display X-Face headers.
1080 Valid values are nil, t, `head', `last', an integer or a predicate.
1081 See Info node `(gnus)Customizing Articles' and Info node
1082 `(gnus)X-Face' for details."
1083   :group 'gnus-article-treat
1084   :version "21.1"
1085   :type gnus-article-treat-head-custom)
1086 (put 'gnus-treat-display-xface 'highlight t)
1087
1088 (defcustom gnus-treat-display-smileys
1089   (if (or (and (featurep 'xemacs)
1090                (featurep 'xpm))
1091           (and (fboundp 'image-type-available-p)
1092                (image-type-available-p 'pbm)))
1093       t nil)
1094   "Display smileys.
1095 Valid values are nil, t, `head', `last', an integer or a predicate.
1096 See Info node `(gnus)Customizing Articles' and Info node
1097 `(gnus)Smileys' for details."
1098   :group 'gnus-article-treat
1099   :version "21.1"
1100   :type gnus-article-treat-custom)
1101 (put 'gnus-treat-display-smileys 'highlight t)
1102
1103 (defcustom gnus-treat-from-picon
1104   (if (and (gnus-image-type-available-p 'xpm)
1105            (gnus-picons-installed-p))
1106       'head nil)
1107   "Display picons in the From header.
1108 Valid values are nil, t, `head', `last', an integer or a predicate.
1109 See Info node `(gnus)Customizing Articles' and Info node
1110 `(gnus)Picons' for details."
1111   :group 'gnus-article-treat
1112   :type gnus-article-treat-head-custom)
1113 (put 'gnus-treat-from-picon 'highlight t)
1114
1115 (defcustom gnus-treat-mail-picon
1116   (if (and (gnus-image-type-available-p 'xpm)
1117            (gnus-picons-installed-p))
1118       'head nil)
1119   "Display picons in To and Cc headers.
1120 Valid values are nil, t, `head', `last', an integer or a predicate.
1121 See Info node `(gnus)Customizing Articles' and Info node
1122 `(gnus)Picons' for details."
1123   :group 'gnus-article-treat
1124   :type gnus-article-treat-head-custom)
1125 (put 'gnus-treat-mail-picon 'highlight t)
1126
1127 (defcustom gnus-treat-newsgroups-picon
1128   (if (and (gnus-image-type-available-p 'xpm)
1129            (gnus-picons-installed-p))
1130       'head nil)
1131   "Display picons in the Newsgroups and Followup-To headers.
1132 Valid values are nil, t, `head', `last', an integer or a predicate.
1133 See Info node `(gnus)Customizing Articles' and Info node
1134 `(gnus)Picons' for details."
1135   :group 'gnus-article-treat
1136   :type gnus-article-treat-head-custom)
1137 (put 'gnus-treat-newsgroups-picon 'highlight t)
1138
1139 (defcustom gnus-treat-body-boundary
1140   (if (or gnus-treat-newsgroups-picon
1141           gnus-treat-mail-picon
1142           gnus-treat-from-picon)
1143       'head nil)
1144   "Draw a boundary at the end of the headers.
1145 Valid values are nil, t, `head', `last', an integer or a predicate.
1146 See Info node `(gnus)Customizing Articles' for details."
1147   :version "21.1"
1148   :group 'gnus-article-treat
1149   :type gnus-article-treat-custom)
1150
1151 (defcustom gnus-treat-capitalize-sentences nil
1152   "Capitalize sentence-starting words.
1153 Valid values are nil, t, `head', `last', an integer or a predicate.
1154 See Info node `(gnus)Customizing Articles' for details."
1155   :version "21.1"
1156   :group 'gnus-article-treat
1157   :type gnus-article-treat-custom)
1158
1159 (defcustom gnus-treat-fill-long-lines nil
1160   "Fill long lines.
1161 Valid values are nil, t, `head', `last', an integer or a predicate.
1162 See Info node `(gnus)Customizing Articles' for details."
1163   :group 'gnus-article-treat
1164   :type gnus-article-treat-custom)
1165
1166 (defcustom gnus-treat-play-sounds nil
1167   "Play sounds.
1168 Valid values are nil, t, `head', `last', an integer or a predicate.
1169 See Info node `(gnus)Customizing Articles' for details."
1170   :version "21.1"
1171   :group 'gnus-article-treat
1172   :type gnus-article-treat-custom)
1173
1174 (defcustom gnus-treat-translate nil
1175   "Translate articles from one language to another.
1176 Valid values are nil, t, `head', `last', an integer or a predicate.
1177 See Info node `(gnus)Customizing Articles' for details."
1178   :version "21.1"
1179   :group 'gnus-article-treat
1180   :type gnus-article-treat-custom)
1181
1182 (defcustom gnus-treat-x-pgp-sig nil
1183   "Verify X-PGP-Sig.
1184 To automatically treat X-PGP-Sig, set it to head.
1185 Valid values are nil, t, `head', `last', an integer or a predicate.
1186 See Info node `(gnus)Customizing Articles' for details."
1187   :group 'gnus-article-treat
1188   :group 'mime-security
1189   :type gnus-article-treat-custom)
1190
1191 (defvar gnus-article-encrypt-protocol-alist
1192   '(("PGP" . mml2015-self-encrypt)))
1193
1194 ;; Set to nil if more than one protocol added to
1195 ;; gnus-article-encrypt-protocol-alist.
1196 (defcustom gnus-article-encrypt-protocol "PGP"
1197   "The protocol used for encrypt articles.
1198 It is a string, such as \"PGP\". If nil, ask user."
1199   :type 'string
1200   :group 'mime-security)
1201
1202 (defcustom gnus-article-wash-function
1203   (cond ((locate-library "w3")
1204          'gnus-article-wash-html-with-w3)
1205         ((locate-library "w3m")
1206          'gnus-article-wash-html-with-w3m))
1207   "Function used for converting HTML into text."
1208   :type '(radio (function-item gnus-article-wash-html-with-w3)
1209                 (function-item gnus-article-wash-html-with-w3m))
1210   :group 'gnus-article)
1211
1212 ;;; Internal variables
1213
1214 (defvar gnus-english-month-names
1215   '("January" "February" "March" "April" "May" "June" "July" "August"
1216     "September" "October" "November" "December"))
1217
1218 (defvar article-goto-body-goes-to-point-min-p nil)
1219 (defvar gnus-article-wash-types nil)
1220 (defvar gnus-article-emphasis-alist nil)
1221 (defvar gnus-article-image-alist nil)
1222
1223 (defvar gnus-article-mime-handle-alist-1 nil)
1224 (defvar gnus-treatment-function-alist
1225   '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1226     (gnus-treat-strip-banner gnus-article-strip-banner)
1227     (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1228     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1229     (gnus-treat-buttonize gnus-article-add-buttons)
1230     (gnus-treat-fill-article gnus-article-fill-cited-article)
1231     (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1232     (gnus-treat-strip-cr gnus-article-remove-cr)
1233     (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1234     (gnus-treat-date-ut gnus-article-date-ut)
1235     (gnus-treat-date-local gnus-article-date-local)
1236     (gnus-treat-date-english gnus-article-date-english)
1237     (gnus-treat-date-lapsed gnus-article-date-lapsed)
1238     (gnus-treat-date-original gnus-article-date-original)
1239     (gnus-treat-date-user-defined gnus-article-date-user)
1240     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1241     (gnus-treat-display-xface gnus-article-display-x-face)
1242     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1243     (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1244     (gnus-treat-hide-signature gnus-article-hide-signature)
1245     (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1246     (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1247     (gnus-treat-strip-pgp gnus-article-hide-pgp)
1248     (gnus-treat-strip-pem gnus-article-hide-pem)
1249     (gnus-treat-from-picon gnus-treat-from-picon)
1250     (gnus-treat-mail-picon gnus-treat-mail-picon)
1251     (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1252     (gnus-treat-highlight-headers gnus-article-highlight-headers)
1253     (gnus-treat-highlight-signature gnus-article-highlight-signature)
1254     (gnus-treat-strip-trailing-blank-lines
1255      gnus-article-remove-trailing-blank-lines)
1256     (gnus-treat-strip-leading-blank-lines
1257      gnus-article-strip-leading-blank-lines)
1258     (gnus-treat-strip-multiple-blank-lines
1259      gnus-article-strip-multiple-blank-lines)
1260     (gnus-treat-overstrike gnus-article-treat-overstrike)
1261     (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1262     (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1263     (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1264     (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1265     (gnus-treat-display-smileys gnus-treat-smiley)
1266     (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1267     (gnus-treat-emphasize gnus-article-emphasize)
1268     (gnus-treat-hide-citation gnus-article-hide-citation)
1269     (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1270     (gnus-treat-highlight-citation gnus-article-highlight-citation)
1271     (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1272     (gnus-treat-play-sounds gnus-earcon-display)))
1273
1274 (defvar gnus-article-mime-handle-alist nil)
1275 (defvar article-lapsed-timer nil)
1276 (defvar gnus-article-current-summary nil)
1277
1278 (defvar gnus-article-mode-syntax-table
1279   (let ((table (copy-syntax-table text-mode-syntax-table)))
1280     ;; This causes the citation match run O(2^n).
1281     ;; (modify-syntax-entry ?- "w" table)
1282     (modify-syntax-entry ?> ")" table)
1283     (modify-syntax-entry ?< "(" table)
1284     table)
1285   "Syntax table used in article mode buffers.
1286 Initialized from `text-mode-syntax-table.")
1287
1288 (defvar gnus-save-article-buffer nil)
1289
1290 (defvar gnus-article-mode-line-format-alist
1291   (nconc '((?w (gnus-article-wash-status) ?s)
1292            (?m (gnus-article-mime-part-status) ?s))
1293          gnus-summary-mode-line-format-alist))
1294
1295 (defvar gnus-number-of-articles-to-be-saved nil)
1296
1297 (defvar gnus-inhibit-hiding nil)
1298
1299 ;;; Macros for dealing with the article buffer.
1300
1301 (defmacro gnus-with-article-headers (&rest forms)
1302   `(save-excursion
1303      (set-buffer gnus-article-buffer)
1304      (save-restriction
1305        (let ((buffer-read-only nil)
1306              (inhibit-point-motion-hooks t)
1307              (case-fold-search t))
1308          (article-narrow-to-head)
1309          ,@forms))))
1310
1311 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1312 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1313
1314 (defmacro gnus-with-article-buffer (&rest forms)
1315   `(save-excursion
1316      (set-buffer gnus-article-buffer)
1317      (let ((buffer-read-only nil))
1318        ,@forms)))
1319
1320 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1321 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1322
1323 (defun gnus-article-goto-header (header)
1324   "Go to HEADER, which is a regular expression."
1325   (re-search-forward (concat "^\\(" header "\\):") nil t))
1326
1327 (defsubst gnus-article-hide-text (b e props)
1328   "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1329   (gnus-add-text-properties-when 'article-type nil b e props)
1330   (when (memq 'intangible props)
1331     (put-text-property
1332      (max (1- b) (point-min))
1333      b 'intangible (cddr (memq 'intangible props)))))
1334
1335 (defsubst gnus-article-unhide-text (b e)
1336   "Remove hidden text properties from region between B and E."
1337   (remove-text-properties b e gnus-hidden-properties)
1338   (when (memq 'intangible gnus-hidden-properties)
1339     (put-text-property (max (1- b) (point-min))
1340                        b 'intangible nil)))
1341
1342 (defun gnus-article-hide-text-type (b e type)
1343   "Hide text of TYPE between B and E."
1344   (gnus-add-wash-type type)
1345   (gnus-article-hide-text
1346    b e (cons 'article-type (cons type gnus-hidden-properties))))
1347
1348 (defun gnus-article-unhide-text-type (b e type)
1349   "Unhide text of TYPE between B and E."
1350   (gnus-delete-wash-type type)
1351   (remove-text-properties
1352    b e (cons 'article-type (cons type gnus-hidden-properties)))
1353   (when (memq 'intangible gnus-hidden-properties)
1354     (put-text-property (max (1- b) (point-min))
1355                        b 'intangible nil)))
1356
1357 (defun gnus-article-hide-text-of-type (type)
1358   "Hide text of TYPE in the current buffer."
1359   (save-excursion
1360     (let ((b (point-min))
1361           (e (point-max)))
1362       (while (setq b (text-property-any b e 'article-type type))
1363         (add-text-properties b (incf b) gnus-hidden-properties)))))
1364
1365 (defun gnus-article-delete-text-of-type (type)
1366   "Delete text of TYPE in the current buffer."
1367   (save-excursion
1368     (let ((b (point-min)))
1369       (while (setq b (text-property-any b (point-max) 'article-type type))
1370         (delete-region
1371          b (or (text-property-not-all b (point-max) 'article-type type)
1372                (point-max)))))))
1373
1374 (defun gnus-article-delete-invisible-text ()
1375   "Delete all invisible text in the current buffer."
1376   (save-excursion
1377     (let ((b (point-min)))
1378       (while (setq b (text-property-any b (point-max) 'invisible t))
1379         (delete-region
1380          b (or (text-property-not-all b (point-max) 'invisible t)
1381                (point-max)))))))
1382
1383 (defun gnus-article-text-type-exists-p (type)
1384   "Say whether any text of type TYPE exists in the buffer."
1385   (text-property-any (point-min) (point-max) 'article-type type))
1386
1387 (defsubst gnus-article-header-rank ()
1388   "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1389   (let ((list gnus-sorted-header-list)
1390         (i 0))
1391     (while list
1392       (when (looking-at (car list))
1393         (setq list nil))
1394       (setq list (cdr list))
1395       (incf i))
1396     i))
1397
1398 (defun article-hide-headers (&optional arg delete)
1399   "Hide unwanted headers and possibly sort them as well."
1400   (interactive)
1401   ;; This function might be inhibited.
1402   (unless gnus-inhibit-hiding
1403     (save-excursion
1404       (save-restriction
1405         (let ((buffer-read-only nil)
1406               (case-fold-search t)
1407               (max (1+ (length gnus-sorted-header-list)))
1408               (ignored (when (not gnus-visible-headers)
1409                          (cond ((stringp gnus-ignored-headers)
1410                                 gnus-ignored-headers)
1411                                ((listp gnus-ignored-headers)
1412                                 (mapconcat 'identity gnus-ignored-headers
1413                                            "\\|")))))
1414               (visible
1415                (cond ((stringp gnus-visible-headers)
1416                       gnus-visible-headers)
1417                      ((and gnus-visible-headers
1418                            (listp gnus-visible-headers))
1419                       (mapconcat 'identity gnus-visible-headers "\\|"))))
1420               (inhibit-point-motion-hooks t)
1421               beg)
1422           ;; First we narrow to just the headers.
1423           (article-narrow-to-head)
1424           ;; Hide any "From " lines at the beginning of (mail) articles.
1425           (while (looking-at "From ")
1426             (forward-line 1))
1427           (unless (bobp)
1428             (delete-region (point-min) (point)))
1429           ;; Then treat the rest of the header lines.
1430           ;; Then we use the two regular expressions
1431           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1432           ;; select which header lines is to remain visible in the
1433           ;; article buffer.
1434           (while (re-search-forward "^[^ \t:]*:" nil t)
1435             (beginning-of-line)
1436             ;; Mark the rank of the header.
1437             (put-text-property
1438              (point) (1+ (point)) 'message-rank
1439              (if (or (and visible (looking-at visible))
1440                      (and ignored
1441                           (not (looking-at ignored))))
1442                  (gnus-article-header-rank)
1443                (+ 2 max)))
1444             (forward-line 1))
1445           (message-sort-headers-1)
1446           (when (setq beg (text-property-any
1447                            (point-min) (point-max) 'message-rank (+ 2 max)))
1448             ;; We delete the unwanted headers.
1449             (gnus-add-wash-type 'headers)
1450             (add-text-properties (point-min) (+ 5 (point-min))
1451                                  '(article-type headers dummy-invisible t))
1452             (delete-region beg (point-max))))))))
1453
1454 (defun article-hide-boring-headers (&optional arg)
1455   "Toggle hiding of headers that aren't very interesting.
1456 If given a negative prefix, always show; if given a positive prefix,
1457 always hide."
1458   (interactive (gnus-article-hidden-arg))
1459   (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1460              (not gnus-show-all-headers))
1461     (save-excursion
1462       (save-restriction
1463         (let ((buffer-read-only nil)
1464               (list gnus-boring-article-headers)
1465               (inhibit-point-motion-hooks t)
1466               elem)
1467           (article-narrow-to-head)
1468           (while list
1469             (setq elem (pop list))
1470             (goto-char (point-min))
1471             (cond
1472              ;; Hide empty headers.
1473              ((eq elem 'empty)
1474               (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1475                 (forward-line -1)
1476                 (gnus-article-hide-text-type
1477                  (progn (beginning-of-line) (point))
1478                  (progn
1479                    (end-of-line)
1480                    (if (re-search-forward "^[^ \t]" nil t)
1481                        (match-beginning 0)
1482                      (point-max)))
1483                  'boring-headers)))
1484              ;; Hide boring Newsgroups header.
1485              ((eq elem 'newsgroups)
1486               (when (gnus-string-equal
1487                      (gnus-fetch-field "newsgroups")
1488                      (gnus-group-real-name
1489                       (if (boundp 'gnus-newsgroup-name)
1490                           gnus-newsgroup-name
1491                         "")))
1492                 (gnus-article-hide-header "newsgroups")))
1493              ((eq elem 'to-address)
1494               (let ((to (message-fetch-field "to"))
1495                     (to-address
1496                      (gnus-parameter-to-address
1497                       (if (boundp 'gnus-newsgroup-name)
1498                           gnus-newsgroup-name ""))))
1499                 (when (and to to-address
1500                            (ignore-errors
1501                              (gnus-string-equal
1502                               ;; only one address in To
1503                               (nth 1 (mail-extract-address-components to))
1504                               to-address)))
1505                   (gnus-article-hide-header "to"))))
1506              ((eq elem 'followup-to)
1507               (when (gnus-string-equal
1508                      (message-fetch-field "followup-to")
1509                      (message-fetch-field "newsgroups"))
1510                 (gnus-article-hide-header "followup-to")))
1511              ((eq elem 'reply-to)
1512               (let ((from (message-fetch-field "from"))
1513                     (reply-to (message-fetch-field "reply-to")))
1514                 (when (and
1515                        from reply-to
1516                        (ignore-errors
1517                          (gnus-string-equal
1518                           (nth 1 (mail-extract-address-components from))
1519                           (nth 1 (mail-extract-address-components reply-to)))))
1520                   (gnus-article-hide-header "reply-to"))))
1521              ((eq elem 'date)
1522               (let ((date (message-fetch-field "date")))
1523                 (when (and date
1524                            (< (days-between (current-time-string) date)
1525                               4))
1526                   (gnus-article-hide-header "date"))))
1527              ((eq elem 'long-to)
1528               (let ((to (message-fetch-field "to"))
1529                     (cc (message-fetch-field "cc")))
1530                 (when (> (length to) 1024)
1531                   (gnus-article-hide-header "to"))
1532                 (when (> (length cc) 1024)
1533                   (gnus-article-hide-header "cc"))))
1534              ((eq elem 'many-to)
1535               (let ((to-count 0)
1536                     (cc-count 0))
1537                 (goto-char (point-min))
1538                 (while (re-search-forward "^to:" nil t)
1539                   (setq to-count (1+ to-count)))
1540                 (when (> to-count 1)
1541                   (while (> to-count 0)
1542                     (goto-char (point-min))
1543                     (save-restriction
1544                       (re-search-forward "^to:" nil nil to-count)
1545                       (forward-line -1)
1546                       (narrow-to-region (point) (point-max))
1547                       (gnus-article-hide-header "to"))
1548                     (setq to-count (1- to-count))))
1549                 (goto-char (point-min))
1550                 (while (re-search-forward "^cc:" nil t)
1551                   (setq cc-count (1+ cc-count)))
1552                 (when (> cc-count 1)
1553                   (while (> cc-count 0)
1554                     (goto-char (point-min))
1555                     (save-restriction
1556                       (re-search-forward "^cc:" nil nil cc-count)
1557                       (forward-line -1)
1558                       (narrow-to-region (point) (point-max))
1559                       (gnus-article-hide-header "cc"))
1560                     (setq cc-count (1- cc-count)))))))))))))
1561
1562 (defun gnus-article-hide-header (header)
1563   (save-excursion
1564     (goto-char (point-min))
1565     (when (re-search-forward (concat "^" header ":") nil t)
1566       (gnus-article-hide-text-type
1567        (progn (beginning-of-line) (point))
1568        (progn
1569          (end-of-line)
1570          (if (re-search-forward "^[^ \t]" nil t)
1571              (match-beginning 0)
1572            (point-max)))
1573        'boring-headers))))
1574
1575 (defvar gnus-article-normalized-header-length 40
1576   "Length of normalized headers.")
1577
1578 (defun article-normalize-headers ()
1579   "Make all header lines 40 characters long."
1580   (interactive)
1581   (let ((buffer-read-only nil)
1582         column)
1583     (save-excursion
1584       (save-restriction
1585         (article-narrow-to-head)
1586         (while (not (eobp))
1587           (cond
1588            ((< (setq column (- (gnus-point-at-eol) (point)))
1589                gnus-article-normalized-header-length)
1590             (end-of-line)
1591             (insert (make-string
1592                      (- gnus-article-normalized-header-length column)
1593                      ? )))
1594            ((> column gnus-article-normalized-header-length)
1595             (gnus-put-text-property
1596              (progn
1597                (forward-char gnus-article-normalized-header-length)
1598                (point))
1599              (gnus-point-at-eol)
1600              'invisible t))
1601            (t
1602             ;; Do nothing.
1603             ))
1604           (forward-line 1))))))
1605
1606 (defun article-treat-dumbquotes ()
1607   "Translate M****s*** sm*rtq**t*s into proper text.
1608 Note that this function guesses whether a character is a sm*rtq**t* or
1609 not, so it should only be used interactively.
1610
1611 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1612 in an attempt to provide more quoting characters.  If you see
1613 something like \\222 or \\264 where you're expecting some kind of
1614 apostrophe or quotation mark, then try this wash."
1615   (interactive)
1616   (article-translate-strings gnus-article-dumbquotes-map))
1617
1618 (defun article-translate-characters (from to)
1619   "Translate all characters in the body of the article according to FROM and TO.
1620 FROM is a string of characters to translate from; to is a string of
1621 characters to translate to."
1622   (save-excursion
1623     (when (article-goto-body)
1624       (let ((buffer-read-only nil)
1625             (x (make-string 225 ?x))
1626             (i -1))
1627         (while (< (incf i) (length x))
1628           (aset x i i))
1629         (setq i 0)
1630         (while (< i (length from))
1631           (aset x (aref from i) (aref to i))
1632           (incf i))
1633         (translate-region (point) (point-max) x)))))
1634
1635 (defun article-translate-strings (map)
1636   "Translate all string in the body of the article according to MAP.
1637 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1638   (save-excursion
1639     (when (article-goto-body)
1640       (let ((buffer-read-only nil)
1641             elem)
1642         (while (setq elem (pop map))
1643           (save-excursion
1644             (while (search-forward (car elem) nil t)
1645               (replace-match (cadr elem)))))))))
1646
1647 (defun article-treat-overstrike ()
1648   "Translate overstrikes into bold text."
1649   (interactive)
1650   (save-excursion
1651     (when (article-goto-body)
1652       (let ((buffer-read-only nil))
1653         (while (search-forward "\b" nil t)
1654           (let ((next (char-after))
1655                 (previous (char-after (- (point) 2))))
1656             ;; We do the boldification/underlining by hiding the
1657             ;; overstrikes and putting the proper text property
1658             ;; on the letters.
1659             (cond
1660              ((eq next previous)
1661               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1662               (put-text-property (point) (1+ (point)) 'face 'bold))
1663              ((eq next ?_)
1664               (gnus-article-hide-text-type
1665                (1- (point)) (1+ (point)) 'overstrike)
1666               (put-text-property
1667                (- (point) 2) (1- (point)) 'face 'underline))
1668              ((eq previous ?_)
1669               (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1670               (put-text-property
1671                (point) (1+ (point)) 'face 'underline)))))))))
1672
1673 (defun gnus-article-treat-unfold-headers ()
1674   "Unfold folded message headers.
1675 Only the headers that fit into the current window width will be
1676 unfolded."
1677   (interactive)
1678   (gnus-with-article-headers
1679     (let (length)
1680       (while (not (eobp))
1681         (save-restriction
1682           (mail-header-narrow-to-field)
1683           (let ((header (buffer-substring (point-min) (point-max))))
1684             (with-temp-buffer
1685               (insert header)
1686               (goto-char (point-min))
1687               (while (re-search-forward "\n[\t ]" nil t)
1688                 (replace-match " " t t)))
1689             (setq length (- (point-max) (point-min) 1)))
1690           (when (< length (window-width))
1691             (while (re-search-forward "\n[\t ]" nil t)
1692               (replace-match " " t t)))
1693           (goto-char (point-max)))))))
1694
1695 (defun gnus-article-treat-fold-headers ()
1696   "Fold message headers."
1697   (interactive)
1698   (gnus-with-article-headers
1699     (while (not (eobp))
1700       (save-restriction
1701         (mail-header-narrow-to-field)
1702         (mail-header-fold-field)
1703         (goto-char (point-max))))))
1704
1705 (defun gnus-treat-smiley ()
1706   "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
1707   (interactive)
1708   (gnus-with-article-buffer
1709     (if (memq 'smiley gnus-article-wash-types)
1710         (gnus-delete-images 'smiley)
1711       (article-goto-body)
1712       (let ((images (smiley-region (point) (point-max))))
1713         (when images
1714           (gnus-add-wash-type 'smiley)
1715           (dolist (image images)
1716             (gnus-add-image 'smiley image)))))))
1717
1718 (defun gnus-article-remove-images ()
1719   "Remove all images from the article buffer."
1720   (interactive)
1721   (gnus-with-article-buffer
1722     (dolist (elem gnus-article-image-alist)
1723       (gnus-delete-images (car elem)))))
1724
1725 (defun gnus-article-treat-fold-newsgroups ()
1726   "Unfold folded message headers.
1727 Only the headers that fit into the current window width will be
1728 unfolded."
1729   (interactive)
1730   (gnus-with-article-headers
1731     (while (gnus-article-goto-header "newsgroups\\|followup-to")
1732       (save-restriction
1733         (mail-header-narrow-to-field)
1734         (while (re-search-forward ", *" nil t)
1735           (replace-match ", " t t))
1736         (mail-header-fold-field)
1737         (goto-char (point-max))))))
1738
1739 (defun gnus-article-treat-body-boundary ()
1740   "Place a boundary line at the end of the headers."
1741   (interactive)
1742   (when (and gnus-body-boundary-delimiter
1743              (> (length gnus-body-boundary-delimiter) 0))
1744     (gnus-with-article-headers
1745       (goto-char (point-max))
1746       (let ((start (point)))
1747         (insert "X-Boundary: ")
1748         (gnus-add-text-properties start (point) '(invisible t intangible t))
1749         (insert (let (str)
1750                   (while (>= (1- (window-width)) (length str))
1751                     (setq str (concat str gnus-body-boundary-delimiter)))
1752                   (substring str 0 (1- (window-width))))
1753                 "\n")
1754         (gnus-add-text-properties start (point) '(gnus-decoration 'header))))))
1755
1756 (defun article-fill-long-lines ()
1757   "Fill lines that are wider than the window width."
1758   (interactive)
1759   (save-excursion
1760     (let ((buffer-read-only nil)
1761           (width (window-width (get-buffer-window (current-buffer)))))
1762       (save-restriction
1763         (article-goto-body)
1764         (let ((adaptive-fill-mode nil)) ;Why?  -sm
1765           (while (not (eobp))
1766             (end-of-line)
1767             (when (>= (current-column) (min fill-column width))
1768               (narrow-to-region (point) (gnus-point-at-bol))
1769               (fill-paragraph nil)
1770               (goto-char (point-max))
1771               (widen))
1772             (forward-line 1)))))))
1773
1774 (defun article-capitalize-sentences ()
1775   "Capitalize the first word in each sentence."
1776   (interactive)
1777   (save-excursion
1778     (let ((buffer-read-only nil)
1779           (paragraph-start "^[\n\^L]"))
1780       (article-goto-body)
1781       (while (not (eobp))
1782         (capitalize-word 1)
1783         (forward-sentence)))))
1784
1785 (defun article-remove-cr ()
1786   "Remove trailing CRs and then translate remaining CRs into LFs."
1787   (interactive)
1788   (save-excursion
1789     (let ((buffer-read-only nil))
1790       (goto-char (point-min))
1791       (while (re-search-forward "\r+$" nil t)
1792         (replace-match "" t t))
1793       (goto-char (point-min))
1794       (while (search-forward "\r" nil t)
1795         (replace-match "\n" t t)))))
1796
1797 (defun article-remove-trailing-blank-lines ()
1798   "Remove all trailing blank lines from the article."
1799   (interactive)
1800   (save-excursion
1801     (let ((buffer-read-only nil))
1802       (goto-char (point-max))
1803       (delete-region
1804        (point)
1805        (progn
1806          (while (and (not (bobp))
1807                      (looking-at "^[ \t]*$")
1808                      (not (gnus-annotation-in-region-p
1809                            (point) (gnus-point-at-eol))))
1810            (forward-line -1))
1811          (forward-line 1)
1812          (point))))))
1813
1814 (defun article-display-x-face (&optional force)
1815   "Look for an X-Face header and display it if present."
1816   (interactive (list 'force))
1817   (let ((wash-face-p buffer-read-only)) ;; When type `W f'
1818     (gnus-with-article-headers
1819       ;; Delete the old process, if any.
1820       (when (process-status "article-x-face")
1821         (delete-process "article-x-face"))
1822       (if (memq 'xface gnus-article-wash-types)
1823           ;; We have already displayed X-Faces, so we remove them
1824           ;; instead.
1825           (gnus-delete-images 'xface)
1826         ;; Display X-Faces.
1827         (let (x-faces from face grey)
1828           (save-excursion
1829             (when (and wash-face-p
1830                        (progn
1831                          (goto-char (point-min))
1832                          (not (re-search-forward
1833                                "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
1834                        (gnus-buffer-live-p gnus-original-article-buffer))
1835               ;; If type `W f', use gnus-original-article-buffer,
1836               ;; otherwise use the current buffer because displaying
1837               ;; RFC822 parts calls this function too.
1838               (set-buffer gnus-original-article-buffer))
1839             (save-restriction
1840               (mail-narrow-to-head)
1841               (while (gnus-article-goto-header "x-face\\(-[0-9]+\\)?")
1842                 (when (match-beginning 2)
1843                   (setq grey t))
1844                 (push (mail-header-field-value) x-faces))
1845               (setq from (message-fetch-field "from"))))
1846           (if grey
1847               (let ((xpm (gnus-convert-gray-x-face-to-xpm x-faces))
1848                     image)
1849                 (when xpm
1850                   (setq image (gnus-create-image xpm 'xpm t))
1851                   (gnus-article-goto-header "from")
1852                   (when (bobp)
1853                     (insert "From: [no `from' set]\n")
1854                     (forward-char -17))
1855                   (gnus-add-wash-type 'xface)
1856                   (gnus-add-image 'xface image)
1857                   (gnus-put-image image)))
1858             ;; Sending multiple EOFs to xv doesn't work, so we only do a
1859             ;; single external face.
1860             (when (stringp gnus-article-x-face-command)
1861               (setq x-faces (list (car x-faces))))
1862             (while (and (setq face (pop x-faces))
1863                         gnus-article-x-face-command
1864                         (or force
1865                             ;; Check whether this face is censored.
1866                             (not gnus-article-x-face-too-ugly)
1867                             (and gnus-article-x-face-too-ugly from
1868                                  (not (string-match gnus-article-x-face-too-ugly
1869                                                     from)))))
1870               ;; We display the face.
1871               (if (symbolp gnus-article-x-face-command)
1872                   ;; The command is a lisp function, so we call it.
1873                   (if (gnus-functionp gnus-article-x-face-command)
1874                       (funcall gnus-article-x-face-command face)
1875                     (error "%s is not a function" gnus-article-x-face-command))
1876                 ;; The command is a string, so we interpret the command
1877                 ;; as a, well, command, and fork it off.
1878                 (let ((process-connection-type nil))
1879                   (process-kill-without-query
1880                    (start-process
1881                     "article-x-face" nil shell-file-name shell-command-switch
1882                     gnus-article-x-face-command))
1883                   (with-temp-buffer
1884                     (insert face)
1885                     (process-send-region "article-x-face"
1886                                          (point-min) (point-max)))
1887                   (process-send-eof "article-x-face"))))))))))
1888
1889 (defun article-decode-mime-words ()
1890   "Decode all MIME-encoded words in the article."
1891   (interactive)
1892   (save-excursion
1893     (set-buffer gnus-article-buffer)
1894     (let ((inhibit-point-motion-hooks t)
1895           buffer-read-only
1896           (mail-parse-charset gnus-newsgroup-charset)
1897           (mail-parse-ignored-charsets
1898            (save-excursion (set-buffer gnus-summary-buffer)
1899                            gnus-newsgroup-ignored-charsets)))
1900       (mail-decode-encoded-word-region (point-min) (point-max)))))
1901
1902 (defun article-decode-charset (&optional prompt)
1903   "Decode charset-encoded text in the article.
1904 If PROMPT (the prefix), prompt for a coding system to use."
1905   (interactive "P")
1906   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1907         buffer-read-only
1908         (mail-parse-charset gnus-newsgroup-charset)
1909         (mail-parse-ignored-charsets
1910          (save-excursion (condition-case nil
1911                              (set-buffer gnus-summary-buffer)
1912                            (error))
1913                          gnus-newsgroup-ignored-charsets))
1914         ct cte ctl charset format)
1915   (save-excursion
1916     (save-restriction
1917       (article-narrow-to-head)
1918       (setq ct (message-fetch-field "Content-Type" t)
1919             cte (message-fetch-field "Content-Transfer-Encoding" t)
1920             ctl (and ct (ignore-errors
1921                           (mail-header-parse-content-type ct)))
1922             charset (cond
1923                      (prompt
1924                       (mm-read-coding-system "Charset to decode: "))
1925                      (ctl
1926                       (mail-content-type-get ctl 'charset)))
1927             format (and ctl (mail-content-type-get ctl 'format)))
1928       (when cte
1929         (setq cte (mail-header-strip cte)))
1930       (if (and ctl (not (string-match "/" (car ctl))))
1931           (setq ctl nil))
1932       (goto-char (point-max)))
1933     (forward-line 1)
1934     (save-restriction
1935       (narrow-to-region (point) (point-max))
1936       (when (and (eq mail-parse-charset 'gnus-decoded)
1937                  (eq (mm-body-7-or-8) '8bit))
1938         ;; The text code could have been decoded.
1939         (setq charset mail-parse-charset))
1940       (when (and (or (not ctl)
1941                      (equal (car ctl) "text/plain"))
1942                  (not format)) ;; article with format will decode later.
1943         (mm-decode-body
1944          charset (and cte (intern (downcase
1945                                    (gnus-strip-whitespace cte))))
1946          (car ctl)))))))
1947
1948 (defun article-decode-encoded-words ()
1949   "Remove encoded-word encoding from headers."
1950   (let ((inhibit-point-motion-hooks t)
1951         (mail-parse-charset gnus-newsgroup-charset)
1952         (mail-parse-ignored-charsets
1953          (save-excursion (condition-case nil
1954                              (set-buffer gnus-summary-buffer)
1955                            (error))
1956                          gnus-newsgroup-ignored-charsets))
1957         buffer-read-only)
1958     (save-restriction
1959       (article-narrow-to-head)
1960       (funcall gnus-decode-header-function (point-min) (point-max)))))
1961
1962 (defun article-decode-group-name ()
1963   "Decode group names in `Newsgroups:'."
1964   (let ((inhibit-point-motion-hooks t)
1965         buffer-read-only
1966         (method (gnus-find-method-for-group gnus-newsgroup-name)))
1967     (when (and (or gnus-group-name-charset-method-alist
1968                    gnus-group-name-charset-group-alist)
1969                (gnus-buffer-live-p gnus-original-article-buffer))
1970       (when (nnmail-fetch-field "Newsgroups")
1971         (nnheader-replace-header "Newsgroups"
1972                                  (gnus-decode-newsgroups
1973                                   (with-current-buffer
1974                                       gnus-original-article-buffer
1975                                     (nnmail-fetch-field "Newsgroups"))
1976                                   gnus-newsgroup-name method)))
1977       (when (nnmail-fetch-field "Followup-To")
1978         (nnheader-replace-header "Followup-To"
1979                                  (gnus-decode-newsgroups
1980                                   (with-current-buffer
1981                                       gnus-original-article-buffer
1982                                     (nnmail-fetch-field "Followup-To"))
1983                                   gnus-newsgroup-name method))))))
1984
1985 (defun article-de-quoted-unreadable (&optional force read-charset)
1986   "Translate a quoted-printable-encoded article.
1987 If FORCE, decode the article whether it is marked as quoted-printable
1988 or not.
1989 If READ-CHARSET, ask for a coding system."
1990   (interactive (list 'force current-prefix-arg))
1991   (save-excursion
1992     (let ((buffer-read-only nil) type charset)
1993       (if (gnus-buffer-live-p gnus-original-article-buffer)
1994           (with-current-buffer gnus-original-article-buffer
1995             (setq type
1996                   (gnus-fetch-field "content-transfer-encoding"))
1997             (let* ((ct (gnus-fetch-field "content-type"))
1998                    (ctl (and ct
1999                              (ignore-errors
2000                                (mail-header-parse-content-type ct)))))
2001               (setq charset (and ctl
2002                                  (mail-content-type-get ctl 'charset)))
2003               (if (stringp charset)
2004                   (setq charset (intern (downcase charset)))))))
2005       (if read-charset
2006           (setq charset (mm-read-coding-system "Charset: " charset)))
2007       (unless charset
2008         (setq charset gnus-newsgroup-charset))
2009       (when (or force
2010                 (and type (let ((case-fold-search t))
2011                             (string-match "quoted-printable" type))))
2012         (article-goto-body)
2013         (quoted-printable-decode-region
2014          (point) (point-max) (mm-charset-to-coding-system charset))))))
2015
2016 (defun article-de-base64-unreadable (&optional force read-charset)
2017   "Translate a base64 article.
2018 If FORCE, decode the article whether it is marked as base64 not.
2019 If READ-CHARSET, ask for a coding system."
2020   (interactive (list 'force current-prefix-arg))
2021   (save-excursion
2022     (let ((buffer-read-only nil) type charset)
2023       (if (gnus-buffer-live-p gnus-original-article-buffer)
2024           (with-current-buffer gnus-original-article-buffer
2025             (setq type
2026                   (gnus-fetch-field "content-transfer-encoding"))
2027             (let* ((ct (gnus-fetch-field "content-type"))
2028                    (ctl (and ct
2029                              (ignore-errors
2030                                (mail-header-parse-content-type ct)))))
2031               (setq charset (and ctl
2032                                  (mail-content-type-get ctl 'charset)))
2033               (if (stringp charset)
2034                   (setq charset (intern (downcase charset)))))))
2035       (if read-charset
2036           (setq charset (mm-read-coding-system "Charset: " charset)))
2037       (unless charset
2038         (setq charset gnus-newsgroup-charset))
2039       (when (or force
2040                 (and type (let ((case-fold-search t))
2041                             (string-match "base64" type))))
2042         (article-goto-body)
2043         (save-restriction
2044           (narrow-to-region (point) (point-max))
2045           (base64-decode-region (point-min) (point-max))
2046           (mm-decode-coding-region
2047            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2048
2049 (eval-when-compile
2050   (require 'rfc1843))
2051
2052 (defun article-decode-HZ ()
2053   "Translate a HZ-encoded article."
2054   (interactive)
2055   (require 'rfc1843)
2056   (save-excursion
2057     (let ((buffer-read-only nil))
2058       (rfc1843-decode-region (point-min) (point-max)))))
2059
2060 (defun article-unsplit-urls ()
2061   "Remove the newlines that some other mailers insert into URLs."
2062   (interactive)
2063   (save-excursion
2064     (let ((buffer-read-only nil))
2065       (goto-char (point-min))
2066       (while (re-search-forward
2067               "^\\(\\(https?\\|ftp\\)://\\S-+\\)\n\\(\\S-+\\)" nil t)
2068         (replace-match "\\1\\3" t)))))
2069
2070 (defun article-wash-html (&optional read-charset)
2071   "Format an html article.
2072 If READ-CHARSET, ask for a coding system."
2073   (interactive "P")
2074   (save-excursion
2075     (let ((buffer-read-only nil)
2076           charset)
2077       (if (gnus-buffer-live-p gnus-original-article-buffer)
2078           (with-current-buffer gnus-original-article-buffer
2079             (let* ((ct (gnus-fetch-field "content-type"))
2080                    (ctl (and ct
2081                              (ignore-errors
2082                                (mail-header-parse-content-type ct)))))
2083               (setq charset (and ctl
2084                                  (mail-content-type-get ctl 'charset)))
2085               (if (stringp charset)
2086                   (setq charset (intern (downcase charset)))))))
2087       (if read-charset
2088           (setq charset (mm-read-coding-system "Charset: " charset)))
2089       (unless charset
2090         (setq charset gnus-newsgroup-charset))
2091       (article-goto-body)
2092       (save-window-excursion
2093         (save-restriction
2094           (narrow-to-region (point) (point-max))
2095           (funcall gnus-article-wash-function))))))
2096
2097 (defun gnus-article-wash-html-with-w3 ()
2098   "Wash the current buffer with w3."
2099   (mm-setup-w3)
2100   (let ((w3-strict-width (window-width))
2101         (url-standalone-mode t)
2102         (url-gateway-unplugged t)
2103         (w3-honor-stylesheets nil)
2104         (w3-delay-image-loads t))
2105     (condition-case var
2106         (w3-region (point-min) (point-max))
2107       (error))))
2108
2109 (defun gnus-article-wash-html-with-w3m ()
2110   "Wash the current buffer with emacs-w3m."
2111   (mm-setup-w3m)
2112   (save-restriction
2113     (narrow-to-region (point) (point-max))
2114     (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
2115                                    nil
2116                                  "\\`cid:"))
2117           (w3m-display-inline-images mm-inline-text-html-with-images)
2118           w3m-force-redisplay)
2119       (w3m-region (point-min) (point-max)))
2120     (when mm-inline-text-html-with-w3m-keymap
2121       (add-text-properties
2122        (point-min) (point-max)
2123        (append '(mm-inline-text-html-with-w3m t)
2124                (gnus-local-map-property mm-w3m-mode-map))))))
2125
2126 (defun article-hide-list-identifiers ()
2127   "Remove list identifies from the Subject header.
2128 The `gnus-list-identifiers' variable specifies what to do."
2129   (interactive)
2130   (let ((inhibit-point-motion-hooks t)
2131         (regexp (if (consp gnus-list-identifiers)
2132                     (mapconcat 'identity gnus-list-identifiers " *\\|")
2133                   gnus-list-identifiers))
2134         buffer-read-only)
2135     (when regexp
2136       (save-excursion
2137         (save-restriction
2138           (article-narrow-to-head)
2139           (goto-char (point-min))
2140           (while (re-search-forward
2141                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2142                   nil t)
2143             (delete-region (match-beginning 2) (match-end 0))
2144             (beginning-of-line))
2145           (when (re-search-forward
2146                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2147             (delete-region (match-beginning 1) (match-end 1))))))))
2148
2149 (defun article-hide-pgp ()
2150   "Remove any PGP headers and signatures in the current article."
2151   (interactive)
2152   (save-excursion
2153     (save-restriction
2154       (let ((inhibit-point-motion-hooks t)
2155             buffer-read-only beg end)
2156         (article-goto-body)
2157         ;; Hide the "header".
2158         (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2159           (gnus-add-wash-type 'pgp)
2160           (delete-region (match-beginning 0) (match-end 0))
2161           ;; Remove armor headers (rfc2440 6.2)
2162           (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2163                                      (point)))
2164           (setq beg (point))
2165           ;; Hide the actual signature.
2166           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2167                (setq end (1+ (match-beginning 0)))
2168                (delete-region
2169                 end
2170                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2171                     (match-end 0)
2172                   ;; Perhaps we shouldn't hide to the end of the buffer
2173                   ;; if there is no end to the signature?
2174                   (point-max))))
2175           ;; Hide "- " PGP quotation markers.
2176           (when (and beg end)
2177             (narrow-to-region beg end)
2178             (goto-char (point-min))
2179             (while (re-search-forward "^- " nil t)
2180               (delete-region
2181                (match-beginning 0) (match-end 0)))
2182             (widen))
2183           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2184
2185 (defun article-hide-pem (&optional arg)
2186   "Toggle hiding of any PEM headers and signatures in the current article.
2187 If given a negative prefix, always show; if given a positive prefix,
2188 always hide."
2189   (interactive (gnus-article-hidden-arg))
2190   (unless (gnus-article-check-hidden-text 'pem arg)
2191     (save-excursion
2192       (let (buffer-read-only end)
2193         (goto-char (point-min))
2194         ;; Hide the horrendously ugly "header".
2195         (when (and (search-forward
2196                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2197                     nil t)
2198                    (setq end (1+ (match-beginning 0))))
2199           (gnus-add-wash-type 'pem)
2200           (gnus-article-hide-text-type
2201            end
2202            (if (search-forward "\n\n" nil t)
2203                (match-end 0)
2204              (point-max))
2205            'pem)
2206           ;; Hide the trailer as well
2207           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2208                                 nil t)
2209             (gnus-article-hide-text-type
2210              (match-beginning 0) (match-end 0) 'pem)))))))
2211
2212 (defun article-strip-banner ()
2213   "Strip the banner specified by the `banner' group parameter."
2214   (interactive)
2215   (save-excursion
2216     (save-restriction
2217       (let ((inhibit-point-motion-hooks t)
2218             (banner (gnus-parameter-banner gnus-newsgroup-name))
2219             (gnus-signature-limit nil)
2220             buffer-read-only beg end)
2221         (when banner
2222           (article-goto-body)
2223           (cond
2224            ((eq banner 'signature)
2225             (when (gnus-article-narrow-to-signature)
2226               (widen)
2227               (forward-line -1)
2228               (delete-region (point) (point-max))))
2229            ((symbolp banner)
2230             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2231                 (while (re-search-forward banner nil t)
2232                   (delete-region (match-beginning 0) (match-end 0)))))
2233            ((stringp banner)
2234             (while (re-search-forward banner nil t)
2235               (delete-region (match-beginning 0) (match-end 0))))))))))
2236
2237 (defun article-babel ()
2238   "Translate article using an online translation service."
2239   (interactive)
2240   (require 'babel)
2241   (save-excursion
2242     (set-buffer gnus-article-buffer)
2243     (when (article-goto-body)
2244       (let* ((buffer-read-only nil)
2245              (start (point))
2246              (end (point-max))
2247              (orig (buffer-substring start end))
2248              (trans (babel-as-string orig)))
2249         (save-restriction
2250           (narrow-to-region start end)
2251           (delete-region start end)
2252           (insert trans))))))
2253
2254 (defun article-hide-signature (&optional arg)
2255   "Hide the signature in the current article.
2256 If given a negative prefix, always show; if given a positive prefix,
2257 always hide."
2258   (interactive (gnus-article-hidden-arg))
2259   (unless (gnus-article-check-hidden-text 'signature arg)
2260     (save-excursion
2261       (save-restriction
2262         (let ((buffer-read-only nil))
2263           (when (gnus-article-narrow-to-signature)
2264             (gnus-article-hide-text-type
2265              (point-min) (point-max) 'signature))))))
2266   (gnus-set-mode-line 'article))
2267
2268 (defun article-strip-headers-in-body ()
2269   "Strip offensive headers from bodies."
2270   (interactive)
2271   (save-excursion
2272     (article-goto-body)
2273     (let ((case-fold-search t))
2274       (when (looking-at "x-no-archive:")
2275         (gnus-delete-line)))))
2276
2277 (defun article-strip-leading-blank-lines ()
2278   "Remove all blank lines from the beginning of the article."
2279   (interactive)
2280   (save-excursion
2281     (let ((inhibit-point-motion-hooks t)
2282           buffer-read-only)
2283       (when (article-goto-body)
2284         (while (and (not (eobp))
2285                     (looking-at "[ \t]*$"))
2286           (gnus-delete-line))))))
2287
2288 (defun article-narrow-to-head ()
2289   "Narrow the buffer to the head of the message.
2290 Point is left at the beginning of the narrowed-to region."
2291   (narrow-to-region
2292    (goto-char (point-min))
2293    (if (search-forward "\n\n" nil 1)
2294        (1- (point))
2295      (point-max)))
2296   (goto-char (point-min)))
2297
2298 (defun article-goto-body ()
2299   "Place point at the start of the body."
2300   (goto-char (point-min))
2301   (cond
2302    ;; This variable is only bound when dealing with separate
2303    ;; MIME body parts.
2304    (article-goto-body-goes-to-point-min-p
2305     t)
2306    ((search-forward "\n\n" nil t)
2307     t)
2308    (t
2309     (goto-char (point-max))
2310     nil)))
2311
2312 (defun article-strip-multiple-blank-lines ()
2313   "Replace consecutive blank lines with one empty line."
2314   (interactive)
2315   (save-excursion
2316     (let ((inhibit-point-motion-hooks t)
2317           buffer-read-only)
2318       ;; First make all blank lines empty.
2319       (article-goto-body)
2320       (while (re-search-forward "^[ \t]+$" nil t)
2321         (unless (gnus-annotation-in-region-p
2322                  (match-beginning 0) (match-end 0))
2323           (replace-match "" nil t)))
2324       ;; Then replace multiple empty lines with a single empty line.
2325       (article-goto-body)
2326       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2327         (unless (gnus-annotation-in-region-p
2328                  (match-beginning 0) (match-end 0))
2329           (delete-region (match-beginning 1) (match-end 1)))))))
2330
2331 (defun article-strip-leading-space ()
2332   "Remove all white space from the beginning of the lines in the article."
2333   (interactive)
2334   (save-excursion
2335     (let ((inhibit-point-motion-hooks t)
2336           buffer-read-only)
2337       (article-goto-body)
2338       (while (re-search-forward "^[ \t]+" nil t)
2339         (replace-match "" t t)))))
2340
2341 (defun article-strip-trailing-space ()
2342   "Remove all white space from the end of the lines in the article."
2343   (interactive)
2344   (save-excursion
2345     (let ((inhibit-point-motion-hooks t)
2346           buffer-read-only)
2347       (article-goto-body)
2348       (while (re-search-forward "[ \t]+$" nil t)
2349         (replace-match "" t t)))))
2350
2351 (defun article-strip-blank-lines ()
2352   "Strip leading, trailing and multiple blank lines."
2353   (interactive)
2354   (article-strip-leading-blank-lines)
2355   (article-remove-trailing-blank-lines)
2356   (article-strip-multiple-blank-lines))
2357
2358 (defun article-strip-all-blank-lines ()
2359   "Strip all blank lines."
2360   (interactive)
2361   (save-excursion
2362     (let ((inhibit-point-motion-hooks t)
2363           buffer-read-only)
2364       (article-goto-body)
2365       (while (re-search-forward "^[ \t]*\n" nil t)
2366         (replace-match "" t t)))))
2367
2368 (defun gnus-article-narrow-to-signature ()
2369   "Narrow to the signature; return t if a signature is found, else nil."
2370   (let ((inhibit-point-motion-hooks t))
2371     (when (gnus-article-search-signature)
2372       (forward-line 1)
2373       ;; Check whether we have some limits to what we consider
2374       ;; to be a signature.
2375       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2376                       (list gnus-signature-limit)))
2377             limit limited)
2378         (while (setq limit (pop limits))
2379           (if (or (and (integerp limit)
2380                        (< (- (point-max) (point)) limit))
2381                   (and (floatp limit)
2382                        (< (count-lines (point) (point-max)) limit))
2383                   (and (gnus-functionp limit)
2384                        (funcall limit))
2385                   (and (stringp limit)
2386                        (not (re-search-forward limit nil t))))
2387               ()                        ; This limit did not succeed.
2388             (setq limited t
2389                   limits nil)))
2390         (unless limited
2391           (narrow-to-region (point) (point-max))
2392           t)))))
2393
2394 (defun gnus-article-search-signature ()
2395   "Search the current buffer for the signature separator.
2396 Put point at the beginning of the signature separator."
2397   (let ((cur (point)))
2398     (goto-char (point-max))
2399     (if (if (stringp gnus-signature-separator)
2400             (re-search-backward gnus-signature-separator nil t)
2401           (let ((seps gnus-signature-separator))
2402             (while (and seps
2403                         (not (re-search-backward (car seps) nil t)))
2404               (pop seps))
2405             seps))
2406         t
2407       (goto-char cur)
2408       nil)))
2409
2410 (defun gnus-article-hidden-arg ()
2411   "Return the current prefix arg as a number, or 0 if no prefix."
2412   (list (if current-prefix-arg
2413             (prefix-numeric-value current-prefix-arg)
2414           0)))
2415
2416 (defun gnus-article-check-hidden-text (type arg)
2417   "Return nil if hiding is necessary.
2418 Arg can be nil or a number.  nil and positive means hide, negative
2419 means show, 0 means toggle."
2420   (save-excursion
2421     (save-restriction
2422       (let ((hide (gnus-article-hidden-text-p type)))
2423         (cond
2424          ((or (null arg)
2425               (> arg 0))
2426           nil)
2427          ((< arg 0)
2428           (gnus-article-show-hidden-text type)
2429           t)
2430          (t
2431           (if (eq hide 'hidden)
2432               (progn
2433                 (gnus-article-show-hidden-text type)
2434                 t)
2435             nil)))))))
2436
2437 (defun gnus-article-hidden-text-p (type)
2438   "Say whether the current buffer contains hidden text of type TYPE."
2439   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2440     (while (and pos
2441                 (not (get-text-property pos 'invisible))
2442                 (not (get-text-property pos 'dummy-invisible)))
2443       (setq pos
2444             (text-property-any (1+ pos) (point-max) 'article-type type)))
2445     (if pos
2446         'hidden
2447       nil)))
2448
2449 (defun gnus-article-show-hidden-text (type &optional dummy)
2450   "Show all hidden text of type TYPE.
2451 Originally it is hide instead of DUMMY."
2452   (let ((buffer-read-only nil)
2453         (inhibit-point-motion-hooks t))
2454     (gnus-remove-text-properties-when
2455      'article-type type
2456      (point-min) (point-max)
2457      (cons 'article-type (cons type
2458                                gnus-hidden-properties)))
2459     (gnus-delete-wash-type type)))
2460
2461 (defconst article-time-units
2462   `((year . ,(* 365.25 24 60 60))
2463     (week . ,(* 7 24 60 60))
2464     (day . ,(* 24 60 60))
2465     (hour . ,(* 60 60))
2466     (minute . 60)
2467     (second . 1))
2468   "Mapping from time units to seconds.")
2469
2470 (defun article-date-ut (&optional type highlight header)
2471   "Convert DATE date to universal time in the current article.
2472 If TYPE is `local', convert to local time; if it is `lapsed', output
2473 how much time has lapsed since DATE.  For `lapsed', the value of
2474 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2475 should replace the \"Date:\" one, or should be added below it."
2476   (interactive (list 'ut t))
2477   (let* ((header (or header
2478                      (message-fetch-field "date")
2479                      ""))
2480          (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2481          (date-regexp
2482           (cond
2483            ((not gnus-article-date-lapsed-new-header)
2484             tdate-regexp)
2485            ((eq type 'lapsed)
2486             "^X-Sent:[ \t]")
2487            (t
2488             "^Date:[ \t]")))
2489          (date (if (vectorp header) (mail-header-date header)
2490                  header))
2491          (inhibit-point-motion-hooks t)
2492          pos
2493          bface eface)
2494     (save-excursion
2495       (save-restriction
2496         (article-narrow-to-head)
2497         (when (re-search-forward tdate-regexp nil t)
2498           (setq bface (get-text-property (gnus-point-at-bol) 'face)
2499                 date (or (get-text-property (gnus-point-at-bol)
2500                                             'original-date)
2501                          date)
2502                 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2503           (forward-line 1))
2504         (when (and date (not (string= date "")))
2505           (goto-char (point-min))
2506           (let ((buffer-read-only nil))
2507             ;; Delete any old Date headers.
2508             (while (re-search-forward date-regexp nil t)
2509               (if pos
2510                   (delete-region (progn (beginning-of-line) (point))
2511                                  (progn (forward-line 1) (point)))
2512                 (delete-region (progn (beginning-of-line) (point))
2513                                (progn (end-of-line) (point)))
2514                 (setq pos (point))))
2515             (when (and (not pos) (re-search-forward tdate-regexp nil t))
2516               (forward-line 1))
2517             (if pos (goto-char pos))
2518             (insert (article-make-date-line date (or type 'ut)))
2519             (when (not pos)
2520               (insert "\n")
2521               (forward-line -1))
2522             ;; Do highlighting.
2523             (beginning-of-line)
2524             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2525               (put-text-property (match-beginning 1) (1+ (match-end 1))
2526                                  'original-date date)
2527               (put-text-property (match-beginning 1) (1+ (match-end 1))
2528                                  'face bface)
2529               (put-text-property (match-beginning 2) (match-end 2)
2530                                  'face eface))))))))
2531
2532 (defun article-make-date-line (date type)
2533   "Return a DATE line of TYPE."
2534   (unless (memq type '(local ut original user iso8601 lapsed english))
2535     (error "Unknown conversion type: %s" type))
2536   (condition-case ()
2537       (let ((time (date-to-time date)))
2538         (cond
2539          ;; Convert to the local timezone.
2540          ((eq type 'local)
2541           (let ((tz (car (current-time-zone time))))
2542             (format "Date: %s %s%02d%02d" (current-time-string time)
2543                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2544                     (/ (% (abs tz) 3600) 60))))
2545          ;; Convert to Universal Time.
2546          ((eq type 'ut)
2547           (concat "Date: "
2548                   (current-time-string
2549                    (let* ((e (parse-time-string date))
2550                           (tm (apply 'encode-time e))
2551                           (ms (car tm))
2552                           (ls (- (cadr tm) (car (current-time-zone time)))))
2553                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2554                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2555                            (t (list ms ls)))))
2556                   " UT"))
2557          ;; Get the original date from the article.
2558          ((eq type 'original)
2559           (concat "Date: " (if (string-match "\n+$" date)
2560                                (substring date 0 (match-beginning 0))
2561                              date)))
2562          ;; Let the user define the format.
2563          ((eq type 'user)
2564           (if (gnus-functionp gnus-article-time-format)
2565               (funcall gnus-article-time-format time)
2566             (concat
2567              "Date: "
2568              (format-time-string gnus-article-time-format time))))
2569          ;; ISO 8601.
2570          ((eq type 'iso8601)
2571           (let ((tz (car (current-time-zone time))))
2572             (concat
2573              "Date: "
2574              (format-time-string "%Y%m%dT%H%M%S" time)
2575              (format "%s%02d%02d"
2576                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2577                      (/ (% (abs tz) 3600) 60)))))
2578          ;; Do an X-Sent lapsed format.
2579          ((eq type 'lapsed)
2580           ;; If the date is seriously mangled, the timezone functions are
2581           ;; liable to bug out, so we ignore all errors.
2582           (let* ((now (current-time))
2583                  (real-time (subtract-time now time))
2584                  (real-sec (and real-time
2585                                 (+ (* (float (car real-time)) 65536)
2586                                    (cadr real-time))))
2587                  (sec (and real-time (abs real-sec)))
2588                  num prev)
2589             (cond
2590              ((null real-time)
2591               "X-Sent: Unknown")
2592              ((zerop sec)
2593               "X-Sent: Now")
2594              (t
2595               (concat
2596                "X-Sent: "
2597                ;; This is a bit convoluted, but basically we go
2598                ;; through the time units for years, weeks, etc,
2599                ;; and divide things to see whether that results
2600                ;; in positive answers.
2601                (mapconcat
2602                 (lambda (unit)
2603                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2604                       ;; The (remaining) seconds are too few to
2605                       ;; be divided into this time unit.
2606                       ""
2607                     ;; It's big enough, so we output it.
2608                     (setq sec (- sec (* num (cdr unit))))
2609                     (prog1
2610                         (concat (if prev ", " "") (int-to-string
2611                                                    (floor num))
2612                                 " " (symbol-name (car unit))
2613                                 (if (> num 1) "s" ""))
2614                       (setq prev t))))
2615                 article-time-units "")
2616                ;; If dates are odd, then it might appear like the
2617                ;; article was sent in the future.
2618                (if (> real-sec 0)
2619                    " ago"
2620                  " in the future"))))))
2621          ;; Display the date in proper English
2622          ((eq type 'english)
2623           (let ((dtime (decode-time time)))
2624             (concat
2625              "Date: the "
2626              (number-to-string (nth 3 dtime))
2627              (let ((digit (% (nth 3 dtime) 10)))
2628                (cond
2629                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2630                 ((= digit 1) "st")
2631                 ((= digit 2) "nd")
2632                 ((= digit 3) "rd")
2633                 (t "th")))
2634              " of "
2635              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2636              " "
2637              (number-to-string (nth 5 dtime))
2638              " at "
2639              (format "%02d" (nth 2 dtime))
2640              ":"
2641              (format "%02d" (nth 1 dtime)))))))
2642         (error
2643          (format "Date: %s (from Oort)" date))))
2644
2645 (defun article-date-local (&optional highlight)
2646   "Convert the current article date to the local timezone."
2647   (interactive (list t))
2648   (article-date-ut 'local highlight))
2649
2650 (defun article-date-english (&optional highlight)
2651   "Convert the current article date to something that is proper English."
2652   (interactive (list t))
2653   (article-date-ut 'english highlight))
2654
2655 (defun article-date-original (&optional highlight)
2656   "Convert the current article date to what it was originally.
2657 This is only useful if you have used some other date conversion
2658 function and want to see what the date was before converting."
2659   (interactive (list t))
2660   (article-date-ut 'original highlight))
2661
2662 (defun article-date-lapsed (&optional highlight)
2663   "Convert the current article date to time lapsed since it was sent."
2664   (interactive (list t))
2665   (article-date-ut 'lapsed highlight))
2666
2667 (defun article-update-date-lapsed ()
2668   "Function to be run from a timer to update the lapsed time line."
2669   (let (deactivate-mark)
2670     (save-excursion
2671       (ignore-errors
2672         (walk-windows
2673          (lambda (w)
2674            (set-buffer (window-buffer w))
2675            (when (eq major-mode 'gnus-article-mode)
2676              (goto-char (point-min))
2677              (when (re-search-forward "^X-Sent:" nil t)
2678                (article-date-lapsed t))))
2679          nil 'visible)))))
2680
2681 (defun gnus-start-date-timer (&optional n)
2682   "Start a timer to update the X-Sent header in the article buffers.
2683 The numerical prefix says how frequently (in seconds) the function
2684 is to run."
2685   (interactive "p")
2686   (unless n
2687     (setq n 1))
2688   (gnus-stop-date-timer)
2689   (setq article-lapsed-timer
2690         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2691
2692 (defun gnus-stop-date-timer ()
2693   "Stop the X-Sent timer."
2694   (interactive)
2695   (when article-lapsed-timer
2696     (nnheader-cancel-timer article-lapsed-timer)
2697     (setq article-lapsed-timer nil)))
2698
2699 (defun article-date-user (&optional highlight)
2700   "Convert the current article date to the user-defined format.
2701 This format is defined by the `gnus-article-time-format' variable."
2702   (interactive (list t))
2703   (article-date-ut 'user highlight))
2704
2705 (defun article-date-iso8601 (&optional highlight)
2706   "Convert the current article date to ISO8601."
2707   (interactive (list t))
2708   (article-date-ut 'iso8601 highlight))
2709
2710 ;; (defun article-show-all ()
2711 ;;   "Show all hidden text in the article buffer."
2712 ;;   (interactive)
2713 ;;   (save-excursion
2714 ;;     (let ((buffer-read-only nil))
2715 ;;       (gnus-article-unhide-text (point-min) (point-max)))))
2716
2717 (defun article-remove-leading-whitespace ()
2718   "Remove excessive whitespace from all headers."
2719   (interactive)
2720   (save-excursion
2721     (save-restriction
2722       (let ((buffer-read-only nil))
2723         (article-narrow-to-head)
2724         (goto-char (point-min))
2725         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2726           (delete-region (match-beginning 1) (match-end 1)))))))
2727
2728 (defun article-emphasize (&optional arg)
2729   "Emphasize text according to `gnus-emphasis-alist'."
2730   (interactive (gnus-article-hidden-arg))
2731   (unless (gnus-article-check-hidden-text 'emphasis arg)
2732     (save-excursion
2733       (let ((alist (or
2734                     (condition-case nil
2735                         (with-current-buffer gnus-summary-buffer
2736                           gnus-article-emphasis-alist)
2737                       (error))
2738                     gnus-emphasis-alist))
2739             (buffer-read-only nil)
2740             (props (append '(article-type emphasis)
2741                            gnus-hidden-properties))
2742             regexp elem beg invisible visible face)
2743         (article-goto-body)
2744         (setq beg (point))
2745         (while (setq elem (pop alist))
2746           (goto-char beg)
2747           (setq regexp (car elem)
2748                 invisible (nth 1 elem)
2749                 visible (nth 2 elem)
2750                 face (nth 3 elem))
2751           (while (re-search-forward regexp nil t)
2752             (when (and (match-beginning visible) (match-beginning invisible))
2753               (gnus-article-hide-text
2754                (match-beginning invisible) (match-end invisible) props)
2755               (gnus-article-unhide-text-type
2756                (match-beginning visible) (match-end visible) 'emphasis)
2757               (gnus-put-overlay-excluding-newlines
2758                (match-beginning visible) (match-end visible) 'face face)
2759               (gnus-add-wash-type 'emphasis)
2760               (goto-char (match-end invisible)))))))))
2761
2762 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2763   "Setup newsgroup emphasis alist."
2764   (unless gnus-article-emphasis-alist
2765     (let ((name (and gnus-newsgroup-name
2766                      (gnus-group-real-name gnus-newsgroup-name))))
2767       (make-local-variable 'gnus-article-emphasis-alist)
2768       (setq gnus-article-emphasis-alist
2769             (nconc
2770              (let ((alist gnus-group-highlight-words-alist) elem highlight)
2771                (while (setq elem (pop alist))
2772                  (when (and name (string-match (car elem) name))
2773                    (setq alist nil
2774                          highlight (copy-sequence (cdr elem)))))
2775                highlight)
2776              (copy-sequence highlight-words)
2777              (if gnus-newsgroup-name
2778                  (copy-sequence (gnus-group-find-parameter
2779                                  gnus-newsgroup-name 'highlight-words t)))
2780              gnus-emphasis-alist)))))
2781
2782 (eval-when-compile
2783   (defvar gnus-summary-article-menu)
2784   (defvar gnus-summary-post-menu))
2785
2786 ;;; Saving functions.
2787
2788 (defun gnus-article-save (save-buffer file &optional num)
2789   "Save the currently selected article."
2790   (unless gnus-save-all-headers
2791     ;; Remove headers according to `gnus-saved-headers'.
2792     (let ((gnus-visible-headers
2793            (or gnus-saved-headers gnus-visible-headers))
2794           (gnus-article-buffer save-buffer))
2795       (save-excursion
2796         (set-buffer save-buffer)
2797         (article-hide-headers 1 t))))
2798   (save-window-excursion
2799     (if (not gnus-default-article-saver)
2800         (error "No default saver is defined")
2801       ;; !!! Magic!  The saving functions all save
2802       ;; `gnus-save-article-buffer' (or so they think), but we
2803       ;; bind that variable to our save-buffer.
2804       (set-buffer gnus-article-buffer)
2805       (let* ((gnus-save-article-buffer save-buffer)
2806              (filename
2807               (cond
2808                ((not gnus-prompt-before-saving) 'default)
2809                ((eq gnus-prompt-before-saving 'always) nil)
2810                (t file)))
2811              (gnus-number-of-articles-to-be-saved
2812               (when (eq gnus-prompt-before-saving t)
2813                 num)))                  ; Magic
2814         (set-buffer gnus-article-current-summary)
2815         (funcall gnus-default-article-saver filename)))))
2816
2817 (defun gnus-read-save-file-name (prompt &optional filename
2818                                         function group headers variable)
2819   (let ((default-name
2820           (funcall function group headers (symbol-value variable)))
2821         result)
2822     (setq result
2823           (expand-file-name
2824            (cond
2825             ((eq filename 'default)
2826              default-name)
2827             ((eq filename t)
2828              default-name)
2829             (filename filename)
2830             (t
2831              (let* ((split-name (gnus-get-split-value gnus-split-methods))
2832                     (prompt
2833                      (format prompt
2834                              (if (and gnus-number-of-articles-to-be-saved
2835                                       (> gnus-number-of-articles-to-be-saved 1))
2836                                  (format "these %d articles"
2837                                          gnus-number-of-articles-to-be-saved)
2838                                "this article")))
2839                     (file
2840                      ;; Let the split methods have their say.
2841                      (cond
2842                       ;; No split name was found.
2843                       ((null split-name)
2844                        (read-file-name
2845                         (concat prompt " (default "
2846                                 (file-name-nondirectory default-name) ") ")
2847                         (file-name-directory default-name)
2848                         default-name))
2849                       ;; A single group name is returned.
2850                       ((stringp split-name)
2851                        (setq default-name
2852                              (funcall function split-name headers
2853                                       (symbol-value variable)))
2854                        (read-file-name
2855                         (concat prompt " (default "
2856                                 (file-name-nondirectory default-name) ") ")
2857                         (file-name-directory default-name)
2858                         default-name))
2859                       ;; A single split name was found
2860                       ((= 1 (length split-name))
2861                        (let* ((name (expand-file-name
2862                                      (car split-name)
2863                                      gnus-article-save-directory))
2864                               (dir (cond ((file-directory-p name)
2865                                           (file-name-as-directory name))
2866                                          ((file-exists-p name) name)
2867                                          (t gnus-article-save-directory))))
2868                          (read-file-name
2869                           (concat prompt " (default " name ") ")
2870                           dir name)))
2871                       ;; A list of splits was found.
2872                       (t
2873                        (setq split-name (nreverse split-name))
2874                        (let (result)
2875                          (let ((file-name-history
2876                                 (nconc split-name file-name-history)))
2877                            (setq result
2878                                  (expand-file-name
2879                                   (read-file-name
2880                                    (concat prompt " (`M-p' for defaults) ")
2881                                    gnus-article-save-directory
2882                                    (car split-name))
2883                                   gnus-article-save-directory)))
2884                          (car (push result file-name-history)))))))
2885                ;; Create the directory.
2886                (gnus-make-directory (file-name-directory file))
2887       ;; If we have read a directory, we append the default file name.
2888                (when (file-directory-p file)
2889                  (setq file (expand-file-name (file-name-nondirectory
2890                                                default-name)
2891                                               (file-name-as-directory file))))
2892                ;; Possibly translate some characters.
2893                (nnheader-translate-file-chars file))))))
2894     (gnus-make-directory (file-name-directory result))
2895     (set variable result)))
2896
2897 (defun gnus-article-archive-name (group)
2898   "Return the first instance of an \"Archive-name\" in the current buffer."
2899   (let ((case-fold-search t))
2900     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2901       (nnheader-concat gnus-article-save-directory
2902                        (match-string 1)))))
2903
2904 (defun gnus-article-nndoc-name (group)
2905   "If GROUP is an nndoc group, return the name of the parent group."
2906   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2907     (gnus-group-get-parameter group 'save-article-group)))
2908
2909 (defun gnus-summary-save-in-rmail (&optional filename)
2910   "Append this article to Rmail file.
2911 Optional argument FILENAME specifies file name.
2912 Directory to save to is default to `gnus-article-save-directory'."
2913   (setq filename (gnus-read-save-file-name
2914                   "Save %s in rmail file:" filename
2915                   gnus-rmail-save-name gnus-newsgroup-name
2916                   gnus-current-headers 'gnus-newsgroup-last-rmail))
2917   (gnus-eval-in-buffer-window gnus-save-article-buffer
2918     (save-excursion
2919       (save-restriction
2920         (widen)
2921         (gnus-output-to-rmail filename))))
2922   filename)
2923
2924 (defun gnus-summary-save-in-mail (&optional filename)
2925   "Append this article to Unix mail file.
2926 Optional argument FILENAME specifies file name.
2927 Directory to save to is default to `gnus-article-save-directory'."
2928   (setq filename (gnus-read-save-file-name
2929                   "Save %s in Unix mail file:" filename
2930                   gnus-mail-save-name gnus-newsgroup-name
2931                   gnus-current-headers 'gnus-newsgroup-last-mail))
2932   (gnus-eval-in-buffer-window gnus-save-article-buffer
2933     (save-excursion
2934       (save-restriction
2935         (widen)
2936         (if (and (file-readable-p filename)
2937                  (mail-file-babyl-p filename))
2938             (rmail-output-to-rmail-file filename t)
2939           (gnus-output-to-mail filename)))))
2940   filename)
2941
2942 (defun gnus-summary-save-in-file (&optional filename overwrite)
2943   "Append this article to file.
2944 Optional argument FILENAME specifies file name.
2945 Directory to save to is default to `gnus-article-save-directory'."
2946   (setq filename (gnus-read-save-file-name
2947                   "Save %s in file:" filename
2948                   gnus-file-save-name gnus-newsgroup-name
2949                   gnus-current-headers 'gnus-newsgroup-last-file))
2950   (gnus-eval-in-buffer-window gnus-save-article-buffer
2951     (save-excursion
2952       (save-restriction
2953         (widen)
2954         (when (and overwrite
2955                    (file-exists-p filename))
2956           (delete-file filename))
2957         (gnus-output-to-file filename))))
2958   filename)
2959
2960 (defun gnus-summary-write-to-file (&optional filename)
2961   "Write this article to a file, overwriting it if the file exists.
2962 Optional argument FILENAME specifies file name.
2963 The directory to save in defaults to `gnus-article-save-directory'."
2964   (gnus-summary-save-in-file nil t))
2965
2966 (defun gnus-summary-save-body-in-file (&optional filename)
2967   "Append this article body to a file.
2968 Optional argument FILENAME specifies file name.
2969 The directory to save in defaults to `gnus-article-save-directory'."
2970   (setq filename (gnus-read-save-file-name
2971                   "Save %s body in file:" filename
2972                   gnus-file-save-name gnus-newsgroup-name
2973                   gnus-current-headers 'gnus-newsgroup-last-file))
2974   (gnus-eval-in-buffer-window gnus-save-article-buffer
2975     (save-excursion
2976       (save-restriction
2977         (widen)
2978         (when (article-goto-body)
2979           (narrow-to-region (point) (point-max)))
2980         (gnus-output-to-file filename))))
2981   filename)
2982
2983 (defun gnus-summary-save-in-pipe (&optional command)
2984   "Pipe this article to subprocess."
2985   (setq command
2986         (cond ((and (eq command 'default)
2987                     gnus-last-shell-command)
2988                gnus-last-shell-command)
2989               ((stringp command)
2990                command)
2991               (t (read-string
2992                   (format
2993                    "Shell command on %s: "
2994                    (if (and gnus-number-of-articles-to-be-saved
2995                             (> gnus-number-of-articles-to-be-saved 1))
2996                        (format "these %d articles"
2997                                gnus-number-of-articles-to-be-saved)
2998                      "this article"))
2999                   gnus-last-shell-command))))
3000   (when (string-equal command "")
3001     (if gnus-last-shell-command
3002         (setq command gnus-last-shell-command)
3003       (error "A command is required")))
3004   (gnus-eval-in-buffer-window gnus-article-buffer
3005     (save-restriction
3006       (widen)
3007       (shell-command-on-region (point-min) (point-max) command nil)))
3008   (setq gnus-last-shell-command command))
3009
3010 (defun gnus-summary-pipe-to-muttprint (&optional command)
3011   "Pipe this article to muttprint."
3012   (setq command (read-string
3013                  "Print using command: " gnus-summary-muttprint-program
3014                  nil gnus-summary-muttprint-program))
3015   (gnus-summary-save-in-pipe command))
3016
3017 ;;; Article file names when saving.
3018
3019 (defun gnus-capitalize-newsgroup (newsgroup)
3020   "Capitalize NEWSGROUP name."
3021   (when (not (zerop (length newsgroup)))
3022     (concat (char-to-string (upcase (aref newsgroup 0)))
3023             (substring newsgroup 1))))
3024
3025 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3026   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3027 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3028 Otherwise, it is like ~/News/news/group/num."
3029   (let ((default
3030           (expand-file-name
3031            (concat (if (gnus-use-long-file-name 'not-save)
3032                        (gnus-capitalize-newsgroup newsgroup)
3033                      (gnus-newsgroup-directory-form newsgroup))
3034                    "/" (int-to-string (mail-header-number headers)))
3035            gnus-article-save-directory)))
3036     (if (and last-file
3037              (string-equal (file-name-directory default)
3038                            (file-name-directory last-file))
3039              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3040         default
3041       (or last-file default))))
3042
3043 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3044   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3045 If variable `gnus-use-long-file-name' is non-nil, it is
3046 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
3047   (let ((default
3048           (expand-file-name
3049            (concat (if (gnus-use-long-file-name 'not-save)
3050                        newsgroup
3051                      (gnus-newsgroup-directory-form newsgroup))
3052                    "/" (int-to-string (mail-header-number headers)))
3053            gnus-article-save-directory)))
3054     (if (and last-file
3055              (string-equal (file-name-directory default)
3056                            (file-name-directory last-file))
3057              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3058         default
3059       (or last-file default))))
3060
3061 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3062   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3063 If variable `gnus-use-long-file-name' is non-nil, it is
3064 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
3065   (or last-file
3066       (expand-file-name
3067        (if (gnus-use-long-file-name 'not-save)
3068            newsgroup
3069          (file-relative-name
3070           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3071           default-directory))
3072        gnus-article-save-directory)))
3073
3074 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3075   "Generate file name from sender."
3076   (let ((from (mail-header-from headers)))
3077     (expand-file-name
3078      (if (and from (string-match "\\([^ <]+\\)@" from))
3079          (match-string 1 from)
3080        "nobody")
3081      gnus-article-save-directory)))
3082
3083 (defun article-verify-x-pgp-sig ()
3084   "Verify X-PGP-Sig."
3085   (interactive)
3086   (if (gnus-buffer-live-p gnus-original-article-buffer)
3087       (let ((sig (with-current-buffer gnus-original-article-buffer
3088                    (gnus-fetch-field "X-PGP-Sig")))
3089             items info headers)
3090         (when (and sig
3091                    mml2015-use
3092                    (mml2015-clear-verify-function))
3093           (with-temp-buffer
3094             (insert-buffer gnus-original-article-buffer)
3095             (setq items (split-string sig))
3096             (message-narrow-to-head)
3097             (let ((inhibit-point-motion-hooks t)
3098                   (case-fold-search t))
3099               ;; Don't verify multiple headers.
3100               (setq headers (mapconcat (lambda (header)
3101                                          (concat header ": "
3102                                                  (mail-fetch-field header) "\n"))
3103                                        (split-string (nth 1 items) ",") "")))
3104             (delete-region (point-min) (point-max))
3105             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3106             (insert "X-Signed-Headers: " (nth 1 items) "\n")
3107             (insert headers)
3108             (widen)
3109             (forward-line)
3110             (while (not (eobp))
3111               (if (looking-at "^-")
3112                   (insert "- "))
3113               (forward-line))
3114             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3115             (insert "Version: " (car items) "\n\n")
3116             (insert (mapconcat 'identity (cddr items) "\n"))
3117             (insert "\n-----END PGP SIGNATURE-----\n")
3118             (let ((mm-security-handle (list (format "multipart/signed"))))
3119               (mml2015-clean-buffer)
3120               (let ((coding-system-for-write (or gnus-newsgroup-charset
3121                                                  'iso-8859-1)))
3122                 (funcall (mml2015-clear-verify-function)))
3123               (setq info
3124                     (or (mm-handle-multipart-ctl-parameter
3125                          mm-security-handle 'gnus-details)
3126                         (mm-handle-multipart-ctl-parameter
3127                          mm-security-handle 'gnus-info)))))
3128           (when info
3129             (let (buffer-read-only bface eface)
3130               (save-restriction
3131                 (message-narrow-to-head)
3132                 (goto-char (point-max))
3133                 (forward-line -1)
3134                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3135                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3136                 (message-remove-header "X-Gnus-PGP-Verify")
3137                 (if (re-search-forward "^X-PGP-Sig:" nil t)
3138                     (forward-line)
3139                   (goto-char (point-max)))
3140                 (narrow-to-region (point) (point))
3141                 (insert "X-Gnus-PGP-Verify: " info "\n")
3142                 (goto-char (point-min))
3143                 (forward-line)
3144                 (while (not (eobp))
3145                   (if (not (looking-at "^[ \t]"))
3146                       (insert " "))
3147                   (forward-line))
3148                 ;; Do highlighting.
3149                 (goto-char (point-min))
3150                 (when (looking-at "\\([^:]+\\): *")
3151                   (put-text-property (match-beginning 1) (1+ (match-end 1))
3152                                      'face bface)
3153                   (put-text-property (match-end 0) (point-max)
3154                                      'face eface)))))))))
3155
3156 (defun article-verify-cancel-lock ()
3157   "Verify Cancel-Lock header."
3158   (interactive)
3159   (if (gnus-buffer-live-p gnus-original-article-buffer)
3160       (canlock-verify gnus-original-article-buffer)))
3161
3162 (eval-and-compile
3163   (mapcar
3164    (lambda (func)
3165      (let (afunc gfunc)
3166        (if (consp func)
3167            (setq afunc (car func)
3168                  gfunc (cdr func))
3169          (setq afunc func
3170                gfunc (intern (format "gnus-%s" func))))
3171        (defalias gfunc
3172          (when (fboundp afunc)
3173            `(lambda (&optional interactive &rest args)
3174               ,(documentation afunc t)
3175               (interactive (list t))
3176               (save-excursion
3177                 (set-buffer gnus-article-buffer)
3178                 (if interactive
3179                     (call-interactively ',afunc)
3180                   (apply ',afunc args))))))))
3181    '(article-hide-headers
3182      article-verify-x-pgp-sig
3183      article-verify-cancel-lock
3184      article-hide-boring-headers
3185      article-treat-overstrike
3186      article-fill-long-lines
3187      article-capitalize-sentences
3188      article-remove-cr
3189      article-remove-leading-whitespace
3190      article-display-x-face
3191      article-de-quoted-unreadable
3192      article-de-base64-unreadable
3193      article-decode-HZ
3194      article-wash-html
3195      article-unsplit-urls
3196      article-hide-list-identifiers
3197      article-hide-pgp
3198      article-strip-banner
3199      article-babel
3200      article-hide-pem
3201      article-hide-signature
3202      article-strip-headers-in-body
3203      article-remove-trailing-blank-lines
3204      article-strip-leading-blank-lines
3205      article-strip-multiple-blank-lines
3206      article-strip-leading-space
3207      article-strip-trailing-space
3208      article-strip-blank-lines
3209      article-strip-all-blank-lines
3210      article-replace-with-quoted-text
3211      article-date-local
3212      article-date-english
3213      article-date-iso8601
3214      article-date-original
3215      article-date-ut
3216      article-decode-mime-words
3217      article-decode-charset
3218      article-decode-encoded-words
3219      article-date-user
3220      article-date-lapsed
3221      article-emphasize
3222      article-treat-dumbquotes
3223      article-normalize-headers
3224 ;;     (article-show-all . gnus-article-show-all-headers)
3225      )))
3226 \f
3227 ;;;
3228 ;;; Gnus article mode
3229 ;;;
3230
3231 (put 'gnus-article-mode 'mode-class 'special)
3232
3233 (set-keymap-parent gnus-article-mode-map widget-keymap)
3234
3235 (gnus-define-keys gnus-article-mode-map
3236   " " gnus-article-goto-next-page
3237   "\177" gnus-article-goto-prev-page
3238   [delete] gnus-article-goto-prev-page
3239   [backspace] gnus-article-goto-prev-page
3240   "\C-c^" gnus-article-refer-article
3241   "h" gnus-article-show-summary
3242   "s" gnus-article-show-summary
3243   "\C-c\C-m" gnus-article-mail
3244   "?" gnus-article-describe-briefly
3245   "e" gnus-summary-edit-article
3246   "<" beginning-of-buffer
3247   ">" end-of-buffer
3248   "\C-c\C-i" gnus-info-find-node
3249   "\C-c\C-b" gnus-bug
3250   "R" gnus-article-reply-with-original
3251   "F" gnus-article-followup-with-original
3252   "\C-hk" gnus-article-describe-key
3253   "\C-hc" gnus-article-describe-key-briefly
3254
3255   "\C-d" gnus-article-read-summary-keys
3256   "\M-*" gnus-article-read-summary-keys
3257   "\M-#" gnus-article-read-summary-keys
3258   "\M-^" gnus-article-read-summary-keys
3259   "\M-g" gnus-article-read-summary-keys)
3260
3261 (substitute-key-definition
3262  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3263
3264 (defun gnus-article-make-menu-bar ()
3265   (unless (boundp 'gnus-article-commands-menu)
3266     (gnus-summary-make-menu-bar))
3267   (gnus-turn-off-edit-menu 'article)
3268   (unless (boundp 'gnus-article-article-menu)
3269     (easy-menu-define
3270      gnus-article-article-menu gnus-article-mode-map ""
3271      '("Article"
3272        ["Scroll forwards" gnus-article-goto-next-page t]
3273        ["Scroll backwards" gnus-article-goto-prev-page t]
3274        ["Show summary" gnus-article-show-summary t]
3275        ["Fetch Message-ID at point" gnus-article-refer-article t]
3276        ["Mail to address at point" gnus-article-mail t]
3277        ["Send a bug report" gnus-bug t]))
3278
3279     (easy-menu-define
3280      gnus-article-treatment-menu gnus-article-mode-map ""
3281      ;; Fixme: this should use :active (and maybe :visible).
3282      '("Treatment"
3283        ["Hide headers" gnus-article-hide-headers t]
3284        ["Hide signature" gnus-article-hide-signature t]
3285        ["Hide citation" gnus-article-hide-citation t]
3286        ["Treat overstrike" gnus-article-treat-overstrike t]
3287        ["Remove carriage return" gnus-article-remove-cr t]
3288        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3289        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3290        ["Remove base64" gnus-article-de-base64-unreadable t]
3291        ["Treat html" gnus-article-wash-html t]
3292        ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3293        ["Decode HZ" gnus-article-decode-HZ t]))
3294
3295     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3296
3297     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3298
3299     (gnus-run-hooks 'gnus-article-menu-hook)))
3300
3301 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3302 ;; Summary.
3303
3304 (defun gnus-article-mode ()
3305   "Major mode for displaying an article.
3306
3307 All normal editing commands are switched off.
3308
3309 The following commands are available in addition to all summary mode
3310 commands:
3311 \\<gnus-article-mode-map>
3312 \\[gnus-article-next-page]\t Scroll the article one page forwards
3313 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3314 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3315 \\[gnus-article-show-summary]\t Display the summary buffer
3316 \\[gnus-article-mail]\t Send a reply to the address near point
3317 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3318 \\[gnus-info-find-node]\t Go to the Gnus info node"
3319   (interactive)
3320   (gnus-simplify-mode-line)
3321   (setq mode-name "Article")
3322   (setq major-mode 'gnus-article-mode)
3323   (make-local-variable 'minor-mode-alist)
3324   (use-local-map gnus-article-mode-map)
3325   (when (gnus-visual-p 'article-menu 'menu)
3326     (gnus-article-make-menu-bar))
3327   (gnus-update-format-specifications nil 'article-mode)
3328   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3329   (make-local-variable 'gnus-page-broken)
3330   (make-local-variable 'gnus-button-marker-list)
3331   (make-local-variable 'gnus-article-current-summary)
3332   (make-local-variable 'gnus-article-mime-handles)
3333   (make-local-variable 'gnus-article-decoded-p)
3334   (make-local-variable 'gnus-article-mime-handle-alist)
3335   (make-local-variable 'gnus-article-wash-types)
3336   (make-local-variable 'gnus-article-image-alist)
3337   (make-local-variable 'gnus-article-charset)
3338   (make-local-variable 'gnus-article-ignored-charsets)
3339   (gnus-set-default-directory)
3340   (buffer-disable-undo)
3341   (setq buffer-read-only t)
3342   (set-syntax-table gnus-article-mode-syntax-table)
3343   (mm-enable-multibyte)
3344   (gnus-run-hooks 'gnus-article-mode-hook))
3345
3346 (defun gnus-article-setup-buffer ()
3347   "Initialize the article buffer."
3348   (let* ((name (if gnus-single-article-buffer "*Article*"
3349                  (concat "*Article " gnus-newsgroup-name "*")))
3350          (original
3351           (progn (string-match "\\*Article" name)
3352                  (concat " *Original Article"
3353                          (substring name (match-end 0))))))
3354     (setq gnus-article-buffer name)
3355     (setq gnus-original-article-buffer original)
3356     (setq gnus-article-mime-handle-alist nil)
3357     ;; This might be a variable local to the summary buffer.
3358     (unless gnus-single-article-buffer
3359       (save-excursion
3360         (set-buffer gnus-summary-buffer)
3361         (setq gnus-article-buffer name)
3362         (setq gnus-original-article-buffer original)
3363         (gnus-set-global-variables)))
3364     (gnus-article-setup-highlight-words)
3365     ;; Init original article buffer.
3366     (save-excursion
3367       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3368       (mm-enable-multibyte)
3369       (setq major-mode 'gnus-original-article-mode)
3370       (make-local-variable 'gnus-original-article))
3371     (if (get-buffer name)
3372         (save-excursion
3373           (set-buffer name)
3374           (when gnus-article-mime-handles
3375             (mm-destroy-parts gnus-article-mime-handles)
3376             (setq gnus-article-mime-handles nil))
3377           ;; Set it to nil in article-buffer!
3378           (setq gnus-article-mime-handle-alist nil)
3379           (buffer-disable-undo)
3380           (setq buffer-read-only t)
3381           (unless (eq major-mode 'gnus-article-mode)
3382             (gnus-article-mode))
3383           (current-buffer))
3384       (save-excursion
3385         (set-buffer (gnus-get-buffer-create name))
3386         (gnus-article-mode)
3387         (make-local-variable 'gnus-summary-buffer)
3388         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3389         (current-buffer)))))
3390
3391 ;; Set article window start at LINE, where LINE is the number of lines
3392 ;; from the head of the article.
3393 (defun gnus-article-set-window-start (&optional line)
3394   (set-window-start
3395    (gnus-get-buffer-window gnus-article-buffer t)
3396    (save-excursion
3397      (set-buffer gnus-article-buffer)
3398      (goto-char (point-min))
3399      (if (not line)
3400          (point-min)
3401        (gnus-message 6 "Moved to bookmark")
3402        (search-forward "\n\n" nil t)
3403        (forward-line line)
3404        (point)))))
3405
3406 (defun gnus-article-prepare (article &optional all-headers header)
3407   "Prepare ARTICLE in article mode buffer.
3408 ARTICLE should either be an article number or a Message-ID.
3409 If ARTICLE is an id, HEADER should be the article headers.
3410 If ALL-HEADERS is non-nil, no headers are hidden."
3411   (save-excursion
3412     ;; Make sure we start in a summary buffer.
3413     (unless (eq major-mode 'gnus-summary-mode)
3414       (set-buffer gnus-summary-buffer))
3415     (setq gnus-summary-buffer (current-buffer))
3416     (let* ((gnus-article (if header (mail-header-number header) article))
3417            (summary-buffer (current-buffer))
3418            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3419            (group gnus-newsgroup-name)
3420            result)
3421       (save-excursion
3422         (gnus-article-setup-buffer)
3423         (set-buffer gnus-article-buffer)
3424         ;; Deactivate active regions.
3425         (when (and (boundp 'transient-mark-mode)
3426                    transient-mark-mode)
3427           (setq mark-active nil))
3428         (if (not (setq result (let ((buffer-read-only nil))
3429                                 (gnus-request-article-this-buffer
3430                                  article group))))
3431             ;; There is no such article.
3432             (save-excursion
3433               (when (and (numberp article)
3434                          (not (memq article gnus-newsgroup-sparse)))
3435                 (setq gnus-article-current
3436                       (cons gnus-newsgroup-name article))
3437                 (set-buffer gnus-summary-buffer)
3438                 (setq gnus-current-article article)
3439                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3440                     (progn
3441                       (gnus-summary-set-agent-mark article)
3442                       (message "Message marked for downloading"))
3443                   (gnus-summary-mark-article article gnus-canceled-mark)
3444                   (unless (memq article gnus-newsgroup-sparse)
3445                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3446           (if (or (eq result 'pseudo)
3447                   (eq result 'nneething))
3448               (progn
3449                 (save-excursion
3450                   (set-buffer summary-buffer)
3451                   (push article gnus-newsgroup-history)
3452                   (setq gnus-last-article gnus-current-article
3453                         gnus-current-article 0
3454                         gnus-current-headers nil
3455                         gnus-article-current nil)
3456                   (if (eq result 'nneething)
3457                       (gnus-configure-windows 'summary)
3458                     (gnus-configure-windows 'article))
3459                   (gnus-set-global-variables))
3460                 (let ((gnus-article-mime-handle-alist-1
3461                        gnus-article-mime-handle-alist))
3462                   (gnus-set-mode-line 'article)))
3463             ;; The result from the `request' was an actual article -
3464             ;; or at least some text that is now displayed in the
3465             ;; article buffer.
3466             (when (and (numberp article)
3467                        (not (eq article gnus-current-article)))
3468               ;; Seems like a new article has been selected.
3469               ;; `gnus-current-article' must be an article number.
3470               (save-excursion
3471                 (set-buffer summary-buffer)
3472                 (push article gnus-newsgroup-history)
3473                 (setq gnus-last-article gnus-current-article
3474                       gnus-current-article article
3475                       gnus-current-headers
3476                       (gnus-summary-article-header gnus-current-article)
3477                       gnus-article-current
3478                       (cons gnus-newsgroup-name gnus-current-article))
3479                 (unless (vectorp gnus-current-headers)
3480                   (setq gnus-current-headers nil))
3481                 (gnus-summary-goto-subject gnus-current-article)
3482                 (when (gnus-summary-show-thread)
3483                   ;; If the summary buffer really was folded, the
3484                   ;; previous goto may not actually have gone to
3485                   ;; the right article, but the thread root instead.
3486                   ;; So we go again.
3487                   (gnus-summary-goto-subject gnus-current-article))
3488                 (gnus-run-hooks 'gnus-mark-article-hook)
3489                 (gnus-set-mode-line 'summary)
3490                 (when (gnus-visual-p 'article-highlight 'highlight)
3491                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3492                 ;; Set the global newsgroup variables here.
3493                 (gnus-set-global-variables)
3494                 (setq gnus-have-all-headers
3495                       (or all-headers gnus-show-all-headers))))
3496             (save-excursion
3497               (gnus-configure-windows 'article))
3498             (when (or (numberp article)
3499                       (stringp article))
3500               (gnus-article-prepare-display)
3501               ;; Do page break.
3502               (goto-char (point-min))
3503               (setq gnus-page-broken
3504                     (when gnus-break-pages
3505                       (gnus-narrow-to-page)
3506                       t)))
3507             (let ((gnus-article-mime-handle-alist-1
3508                    gnus-article-mime-handle-alist))
3509               (gnus-set-mode-line 'article))
3510             (article-goto-body)
3511             (set-window-point (get-buffer-window (current-buffer)) (point))
3512             (gnus-configure-windows 'article)
3513             t))))))
3514
3515 ;;;###autoload
3516 (defun gnus-article-prepare-display ()
3517   "Make the current buffer look like a nice article."
3518   ;; Hooks for getting information from the article.
3519   ;; This hook must be called before being narrowed.
3520   (let ((gnus-article-buffer (current-buffer))
3521         buffer-read-only)
3522     (unless (eq major-mode 'gnus-article-mode)
3523       (gnus-article-mode))
3524     (setq buffer-read-only nil
3525           gnus-article-wash-types nil
3526           gnus-article-image-alist nil)
3527     (gnus-run-hooks 'gnus-tmp-internal-hook)
3528     (when gnus-display-mime-function
3529       (funcall gnus-display-mime-function))
3530     (gnus-run-hooks 'gnus-article-prepare-hook)))
3531
3532 ;;;
3533 ;;; Gnus MIME viewing functions
3534 ;;;
3535
3536 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3537   "Format of the MIME buttons.
3538
3539 Valid specifiers include:
3540 %t  The MIME type
3541 %T  MIME type, along with additional info
3542 %n  The `name' parameter
3543 %d  The description, if any
3544 %l  The length of the encoded part
3545 %p  The part identifier number
3546 %e  Dots if the part isn't displayed
3547
3548 General format specifiers can also be used.  See
3549 (gnus)Formatting Variables.")
3550
3551 (defvar gnus-mime-button-line-format-alist
3552   '((?t gnus-tmp-type ?s)
3553     (?T gnus-tmp-type-long ?s)
3554     (?n gnus-tmp-name ?s)
3555     (?d gnus-tmp-description ?s)
3556     (?p gnus-tmp-id ?s)
3557     (?l gnus-tmp-length ?d)
3558     (?e gnus-tmp-dots ?s)))
3559
3560 (defvar gnus-mime-button-commands
3561   '((gnus-article-press-button "\r" "Toggle Display")
3562     (gnus-mime-view-part "v" "View Interactively...")
3563     (gnus-mime-view-part-as-type "t" "View As Type...")
3564     (gnus-mime-view-part-as-charset "C" "View As charset...")
3565     (gnus-mime-save-part "o" "Save...")
3566     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3567     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3568     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3569     (gnus-mime-internalize-part "E" "View Internally")
3570     (gnus-mime-externalize-part "e" "View Externally")
3571     (gnus-mime-print-part "p" "Print")
3572     (gnus-mime-pipe-part "|" "Pipe To Command...")
3573     (gnus-mime-action-on-part "." "Take action on the part")))
3574
3575 (defun gnus-article-mime-part-status ()
3576   (if gnus-article-mime-handle-alist-1
3577       (if (eq 1 (length gnus-article-mime-handle-alist-1))
3578           " (1 part)"
3579         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3580     ""))
3581
3582 (defvar gnus-mime-button-map
3583   (let ((map (make-sparse-keymap)))
3584     (unless (>= (string-to-number emacs-version) 21)
3585       ;; XEmacs doesn't care.
3586       (set-keymap-parent map gnus-article-mode-map))
3587     (define-key map gnus-mouse-2 'gnus-article-push-button)
3588     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3589     (dolist (c gnus-mime-button-commands)
3590       (define-key map (cadr c) (car c)))
3591     map))
3592
3593 (defun gnus-mime-button-menu (event)
3594   "Construct a context-sensitive menu of MIME commands."
3595   (interactive "e")
3596   (save-window-excursion
3597     (let ((pos (event-start event)))
3598       (select-window (posn-window pos))
3599       (goto-char (posn-point pos))
3600       (gnus-article-check-buffer)
3601       (let ((response (x-popup-menu
3602                        t `("MIME Part"
3603                            ("" ,@(mapcar (lambda (c)
3604                                            (cons (caddr c) (car c)))
3605                                          gnus-mime-button-commands))))))
3606         (if response
3607             (call-interactively response))))))
3608
3609 (defun gnus-mime-view-all-parts (&optional handles)
3610   "View all the MIME parts."
3611   (interactive)
3612   (save-current-buffer
3613     (set-buffer gnus-article-buffer)
3614     (let ((handles (or handles gnus-article-mime-handles))
3615           (mail-parse-charset gnus-newsgroup-charset)
3616           (mail-parse-ignored-charsets
3617            (with-current-buffer gnus-summary-buffer
3618              gnus-newsgroup-ignored-charsets)))
3619       (when handles
3620         (mm-remove-parts handles)
3621         (goto-char (point-min))
3622         (or (search-forward "\n\n") (goto-char (point-max)))
3623         (let (buffer-read-only)
3624           (delete-region (point) (point-max))
3625           (mm-display-parts handles))))))
3626
3627 (defun gnus-mime-save-part-and-strip ()
3628   "Save the MIME part under point then replace it with an external body."
3629   (interactive)
3630   (gnus-article-check-buffer)
3631   (let* ((data (get-text-property (point) 'gnus-data))
3632          file param
3633          (handles gnus-article-mime-handles))
3634     (if (mm-multiple-handles gnus-article-mime-handles)
3635         (error "This function is not implemented"))
3636     (setq file (and data (mm-save-part data)))
3637     (when file
3638       (with-current-buffer (mm-handle-buffer data)
3639         (erase-buffer)
3640         (insert "Content-Type: " (mm-handle-media-type data))
3641         (mml-insert-parameter-string (cdr (mm-handle-type data))
3642                                      '(charset))
3643         (insert "\n")
3644         (insert "Content-ID: " (message-make-message-id) "\n")
3645         (insert "Content-Transfer-Encoding: binary\n")
3646         (insert "\n"))
3647       (setcdr data
3648               (cdr (mm-make-handle nil
3649                                    `("message/external-body"
3650                                      (access-type . "LOCAL-FILE")
3651                                      (name . ,file)))))
3652       (set-buffer gnus-summary-buffer)
3653       (gnus-article-edit-article
3654        `(lambda ()
3655            (erase-buffer)
3656            (let ((mail-parse-charset (or gnus-article-charset
3657                                          ',gnus-newsgroup-charset))
3658                  (mail-parse-ignored-charsets
3659                   (or gnus-article-ignored-charsets
3660                       ',gnus-newsgroup-ignored-charsets))
3661                  (mbl mml-buffer-list))
3662              (setq mml-buffer-list nil)
3663              (insert-buffer gnus-original-article-buffer)
3664              (mime-to-mml ',handles)
3665              (setq gnus-article-mime-handles nil)
3666              (let ((mbl1 mml-buffer-list))
3667                (setq mml-buffer-list mbl)
3668                (set (make-local-variable 'mml-buffer-list) mbl1))
3669              ;; LOCAL argument of add-hook differs between GNU Emacs
3670              ;; and XEmacs. make-local-hook makes sure they are local.
3671              (make-local-hook 'kill-buffer-hook)
3672              (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3673        `(lambda (no-highlight)
3674           (let ((mail-parse-charset (or gnus-article-charset
3675                                         ',gnus-newsgroup-charset))
3676                 (message-options message-options)
3677                 (message-options-set-recipient)
3678                 (mail-parse-ignored-charsets
3679                  (or gnus-article-ignored-charsets
3680                      ',gnus-newsgroup-ignored-charsets)))
3681            (mml-to-mime)
3682            (mml-destroy-buffers)
3683            (remove-hook 'kill-buffer-hook
3684                         'mml-destroy-buffers t)
3685            (kill-local-variable 'mml-buffer-list))
3686           (gnus-summary-edit-article-done
3687            ,(or (mail-header-references gnus-current-headers) "")
3688            ,(gnus-group-read-only-p)
3689            ,gnus-summary-buffer no-highlight))))))
3690
3691 (defun gnus-mime-save-part ()
3692   "Save the MIME part under point."
3693   (interactive)
3694   (gnus-article-check-buffer)
3695   (let ((data (get-text-property (point) 'gnus-data)))
3696     (when data
3697       (mm-save-part data))))
3698
3699 (defun gnus-mime-pipe-part ()
3700   "Pipe the MIME part under point to a process."
3701   (interactive)
3702   (gnus-article-check-buffer)
3703   (let ((data (get-text-property (point) 'gnus-data)))
3704     (when data
3705       (mm-pipe-part data))))
3706
3707 (defun gnus-mime-view-part ()
3708   "Interactively choose a viewing method for the MIME part under point."
3709   (interactive)
3710   (gnus-article-check-buffer)
3711   (let ((data (get-text-property (point) 'gnus-data)))
3712     (when data
3713       (setq gnus-article-mime-handles
3714             (mm-merge-handles
3715              gnus-article-mime-handles (setq data (copy-sequence data))))
3716       (mm-interactively-view-part data))))
3717
3718 (defun gnus-mime-view-part-as-type-internal ()
3719   (gnus-article-check-buffer)
3720   (let* ((name (mail-content-type-get
3721                 (mm-handle-type (get-text-property (point) 'gnus-data))
3722                 'name))
3723          (def-type (and name (mm-default-file-encoding name))))
3724     (and def-type (cons def-type 0))))
3725
3726 (defun gnus-mime-view-part-as-type (&optional mime-type)
3727   "Choose a MIME media type, and view the part as such."
3728   (interactive)
3729   (unless mime-type
3730     (setq mime-type (completing-read
3731                      "View as MIME type: "
3732                      (mapcar #'list (mailcap-mime-types))
3733                      nil nil
3734                      (gnus-mime-view-part-as-type-internal))))
3735   (gnus-article-check-buffer)
3736   (let ((handle (get-text-property (point) 'gnus-data)))
3737     (when handle
3738       (setq handle
3739             (mm-make-handle (mm-handle-buffer handle)
3740                             (cons mime-type (cdr (mm-handle-type handle)))
3741                             (mm-handle-encoding handle)
3742                             (mm-handle-undisplayer handle)
3743                             (mm-handle-disposition handle)
3744                             (mm-handle-description handle)
3745                             nil
3746                             (mm-handle-id handle)))
3747       (setq gnus-article-mime-handles
3748             (mm-merge-handles gnus-article-mime-handles handle))
3749       (gnus-mm-display-part handle))))
3750
3751 (defun gnus-mime-copy-part (&optional handle)
3752   "Put the MIME part under point into a new buffer."
3753   (interactive)
3754   (gnus-article-check-buffer)
3755   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3756          (contents (and handle (mm-get-part handle)))
3757          (base (and handle
3758                     (file-name-nondirectory
3759                      (or
3760                       (mail-content-type-get (mm-handle-type handle) 'name)
3761                       (mail-content-type-get (mm-handle-type handle)
3762                                              'filename)
3763                       "*decoded*"))))
3764          (buffer (and base (generate-new-buffer base))))
3765     (when contents
3766       (switch-to-buffer buffer)
3767       (insert contents)
3768       ;; We do it this way to make `normal-mode' set the appropriate mode.
3769       (unwind-protect
3770           (progn
3771             (setq buffer-file-name (expand-file-name base))
3772             (normal-mode))
3773         (setq buffer-file-name nil))
3774       (goto-char (point-min)))))
3775
3776 (defun gnus-mime-print-part (&optional handle filename)
3777   "Print the MIME part under point."
3778   (interactive (list nil (ps-print-preprint current-prefix-arg)))
3779   (gnus-article-check-buffer)
3780   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3781          (contents (and handle (mm-get-part handle)))
3782          (file (make-temp-name (expand-file-name "mm." mm-tmp-directory)))
3783          (printer (mailcap-mime-info (mm-handle-type handle) "print")))
3784     (when contents
3785         (if printer
3786             (unwind-protect
3787                 (progn
3788                   (with-temp-file file
3789                     (insert contents))
3790                   (call-process shell-file-name nil
3791                                 (generate-new-buffer " *mm*")
3792                                 nil
3793                                 shell-command-switch
3794                                 (mm-mailcap-command
3795                                  printer file (mm-handle-type handle))))
3796               (delete-file file))
3797           (with-temp-buffer
3798             (insert contents)
3799             (gnus-print-buffer))
3800           (ps-despool filename)))))
3801
3802 (defun gnus-mime-inline-part (&optional handle arg)
3803   "Insert the MIME part under point into the current buffer."
3804   (interactive (list nil current-prefix-arg))
3805   (gnus-article-check-buffer)
3806   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3807          contents charset
3808          (b (point))
3809          buffer-read-only)
3810     (when handle
3811       (if (and (not arg) (mm-handle-undisplayer handle))
3812           (mm-remove-part handle)
3813         (setq contents (mm-get-part handle))
3814         (cond
3815          ((not arg)
3816           (setq charset (or (mail-content-type-get
3817                              (mm-handle-type handle) 'charset)
3818                             gnus-newsgroup-charset)))
3819          ((numberp arg)
3820           (if (mm-handle-undisplayer handle)
3821               (mm-remove-part handle))
3822           (setq charset
3823                 (or (cdr (assq arg
3824                                gnus-summary-show-article-charset-alist))
3825                     (mm-read-coding-system "Charset: ")))))
3826         (forward-line 2)
3827         (mm-insert-inline handle
3828                           (if (and charset
3829                                    (setq charset (mm-charset-to-coding-system
3830                                                   charset))
3831                                    (not (eq charset 'ascii)))
3832                               (mm-decode-coding-string contents charset)
3833                             contents))
3834         (goto-char b)))))
3835
3836 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3837   "Insert the MIME part under point into the current buffer using the
3838 specified charset."
3839   (interactive (list nil current-prefix-arg))
3840   (gnus-article-check-buffer)
3841   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3842          contents charset
3843          (b (point))
3844          buffer-read-only)
3845     (when handle
3846       (if (mm-handle-undisplayer handle)
3847           (mm-remove-part handle))
3848       (let ((gnus-newsgroup-charset
3849              (or (cdr (assq arg
3850                             gnus-summary-show-article-charset-alist))
3851                  (mm-read-coding-system "Charset: ")))
3852           (gnus-newsgroup-ignored-charsets 'gnus-all))
3853         (gnus-article-press-button)))))
3854
3855 (defun gnus-mime-externalize-part (&optional handle)
3856   "View the MIME part under point with an external viewer."
3857   (interactive)
3858   (gnus-article-check-buffer)
3859   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3860          (mm-user-display-methods nil)
3861          (mm-inlined-types nil)
3862          (mail-parse-charset gnus-newsgroup-charset)
3863          (mail-parse-ignored-charsets
3864           (save-excursion (set-buffer gnus-summary-buffer)
3865                           gnus-newsgroup-ignored-charsets)))
3866     (when handle
3867       (if (mm-handle-undisplayer handle)
3868           (mm-remove-part handle)
3869         (mm-display-part handle)))))
3870
3871 (defun gnus-mime-internalize-part (&optional handle)
3872   "View the MIME part under point with an internal viewer.
3873 If no internal viewer is available, use an external viewer."
3874   (interactive)
3875   (gnus-article-check-buffer)
3876   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3877          (mm-inlined-types '(".*"))
3878          (mm-inline-large-images t)
3879          (mail-parse-charset gnus-newsgroup-charset)
3880          (mail-parse-ignored-charsets
3881           (save-excursion (set-buffer gnus-summary-buffer)
3882                           gnus-newsgroup-ignored-charsets)))
3883     (when handle
3884       (if (mm-handle-undisplayer handle)
3885           (mm-remove-part handle)
3886         (mm-display-part handle)))))
3887
3888 (defun gnus-mime-action-on-part (&optional action)
3889   "Do something with the MIME attachment at \(point\)."
3890   (interactive
3891    (list (completing-read "Action: " gnus-mime-action-alist)))
3892   (gnus-article-check-buffer)
3893   (let ((action-pair (assoc action gnus-mime-action-alist)))
3894     (if action-pair
3895         (funcall (cdr action-pair)))))
3896
3897 (defun gnus-article-part-wrapper (n function)
3898   (save-current-buffer
3899     (set-buffer gnus-article-buffer)
3900     (when (> n (length gnus-article-mime-handle-alist))
3901       (error "No such part"))
3902     (gnus-article-goto-part n)
3903     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3904       (funcall function handle))))
3905
3906 (defun gnus-article-pipe-part (n)
3907   "Pipe MIME part N, which is the numerical prefix."
3908   (interactive "p")
3909   (gnus-article-part-wrapper n 'mm-pipe-part))
3910
3911 (defun gnus-article-save-part (n)
3912   "Save MIME part N, which is the numerical prefix."
3913   (interactive "p")
3914   (gnus-article-part-wrapper n 'mm-save-part))
3915
3916 (defun gnus-article-interactively-view-part (n)
3917   "View MIME part N interactively, which is the numerical prefix."
3918   (interactive "p")
3919   (gnus-article-part-wrapper n 'mm-interactively-view-part))
3920
3921 (defun gnus-article-copy-part (n)
3922   "Copy MIME part N, which is the numerical prefix."
3923   (interactive "p")
3924   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3925
3926 (defun gnus-article-view-part-as-charset (n)
3927   "Copy MIME part N, which is the numerical prefix."
3928   (interactive "p")
3929   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3930
3931 (defun gnus-article-externalize-part (n)
3932   "View MIME part N externally, which is the numerical prefix."
3933   (interactive "p")
3934   (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3935
3936 (defun gnus-article-inline-part (n)
3937   "Inline MIME part N, which is the numerical prefix."
3938   (interactive "p")
3939   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3940
3941 (defun gnus-article-mime-match-handle-first (condition)
3942   (if condition
3943       (let ((alist gnus-article-mime-handle-alist) ihandle n)
3944         (while (setq ihandle (pop alist))
3945           (if (and (cond
3946                     ((functionp condition)
3947                      (funcall condition (cdr ihandle)))
3948                     ((eq condition 'undisplayed)
3949                      (not (or (mm-handle-undisplayer (cdr ihandle))
3950                               (equal (mm-handle-media-type (cdr ihandle))
3951                                      "multipart/alternative"))))
3952                     ((eq condition 'undisplayed-alternative)
3953                      (not (mm-handle-undisplayer (cdr ihandle))))
3954                     (t t))
3955                    (gnus-article-goto-part (car ihandle))
3956                    (or (not n) (< (car ihandle) n)))
3957               (setq n (car ihandle))))
3958         (or n 1))
3959     1))
3960
3961 (defun gnus-article-view-part (&optional n)
3962   "View MIME part N, which is the numerical prefix."
3963   (interactive "P")
3964   (save-current-buffer
3965     (set-buffer gnus-article-buffer)
3966     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3967                              gnus-article-mime-match-handle-function)))
3968     (when (> n (length gnus-article-mime-handle-alist))
3969       (error "No such part"))
3970     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3971       (when (gnus-article-goto-part n)
3972         (if (equal (car handle) "multipart/alternative")
3973             (gnus-article-press-button)
3974           (when (eq (gnus-mm-display-part handle) 'internal)
3975             (gnus-set-window-start)))))))
3976
3977 (defsubst gnus-article-mime-total-parts ()
3978   (if (bufferp (car gnus-article-mime-handles))
3979       1 ;; single part
3980     (1- (length gnus-article-mime-handles))))
3981
3982 (defun gnus-mm-display-part (handle)
3983   "Display HANDLE and fix MIME button."
3984   (let ((id (get-text-property (point) 'gnus-part))
3985         (point (point))
3986         buffer-read-only)
3987     (forward-line 1)
3988     (prog1
3989         (let ((window (selected-window))
3990               (mail-parse-charset gnus-newsgroup-charset)
3991               (mail-parse-ignored-charsets
3992                (if (gnus-buffer-live-p gnus-summary-buffer)
3993                    (save-excursion
3994                      (set-buffer gnus-summary-buffer)
3995                      gnus-newsgroup-ignored-charsets)
3996                  nil)))
3997           (save-excursion
3998             (unwind-protect
3999                 (let ((win (gnus-get-buffer-window (current-buffer) t))
4000                       (beg (point)))
4001                   (when win
4002                     (select-window win))
4003                   (goto-char point)
4004                   (forward-line)
4005                   (if (mm-handle-displayed-p handle)
4006                       ;; This will remove the part.
4007                       (mm-display-part handle)
4008                     (save-restriction
4009                       (narrow-to-region (point)
4010                                         (if (eobp) (point) (1+ (point))))
4011                       (mm-display-part handle)
4012                       ;; We narrow to the part itself and
4013                       ;; then call the treatment functions.
4014                       (goto-char (point-min))
4015                       (forward-line 1)
4016                       (narrow-to-region (point) (point-max))
4017                       (gnus-treat-article
4018                        nil id
4019                        (gnus-article-mime-total-parts)
4020                        (mm-handle-media-type handle)))))
4021               (if (window-live-p window)
4022                   (select-window window)))))
4023       (goto-char point)
4024       (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4025       (gnus-insert-mime-button
4026        handle id (list (mm-handle-displayed-p handle)))
4027       (goto-char point))))
4028
4029 (defun gnus-article-goto-part (n)
4030   "Go to MIME part N."
4031   (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4032     (when point
4033       (goto-char point))))
4034
4035 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4036   (let ((gnus-tmp-name
4037          (or (mail-content-type-get (mm-handle-type handle) 'name)
4038              (mail-content-type-get (mm-handle-disposition handle) 'filename)
4039              (mail-content-type-get (mm-handle-type handle) 'url)
4040              ""))
4041         (gnus-tmp-type (mm-handle-media-type handle))
4042         (gnus-tmp-description
4043          (mail-decode-encoded-word-string (or (mm-handle-description handle)
4044                                               "")))
4045         (gnus-tmp-dots
4046          (if (if displayed (car displayed)
4047                (mm-handle-displayed-p handle))
4048              "" "..."))
4049         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4050                            (buffer-size)))
4051         gnus-tmp-type-long b e)
4052     (when (string-match ".*/" gnus-tmp-name)
4053       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4054     (setq gnus-tmp-type-long (concat gnus-tmp-type
4055                                      (and (not (equal gnus-tmp-name ""))
4056                                           (concat "; " gnus-tmp-name))))
4057     (unless (equal gnus-tmp-description "")
4058       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4059     (unless (bolp)
4060       (insert "\n"))
4061     (setq b (point))
4062     (gnus-eval-format
4063      gnus-mime-button-line-format gnus-mime-button-line-format-alist
4064      `(,@(gnus-local-map-property gnus-mime-button-map)
4065          gnus-callback gnus-mm-display-part
4066          gnus-part ,gnus-tmp-id
4067          article-type annotation
4068          gnus-data ,handle))
4069     (setq e (point))
4070     (widget-convert-button
4071      'link b e
4072      :mime-handle handle
4073      :action 'gnus-widget-press-button
4074      :button-keymap gnus-mime-button-map
4075      :help-echo
4076      (lambda (widget/window &optional overlay pos)
4077        ;; Needed to properly clear the message due to a bug in
4078        ;; wid-edit (XEmacs only).
4079        (if (boundp 'help-echo-owns-message)
4080            (setq help-echo-owns-message t))
4081        (format
4082         "%S: %s the MIME part; %S: more options"
4083         (aref gnus-mouse-2 0)
4084         ;; XEmacs will get a single widget arg; Emacs 21 will get
4085         ;; window, overlay, position.
4086         (if (mm-handle-displayed-p
4087              (if overlay
4088                  (with-current-buffer (gnus-overlay-buffer overlay)
4089                    (widget-get (widget-at (gnus-overlay-start overlay))
4090                                :mime-handle))
4091                (widget-get widget/window :mime-handle)))
4092             "hide" "show")
4093         (aref gnus-down-mouse-3 0))))))
4094
4095 (defun gnus-widget-press-button (elems el)
4096   (goto-char (widget-get elems :from))
4097   (gnus-article-press-button))
4098
4099 (defvar gnus-displaying-mime nil)
4100
4101 (defun gnus-display-mime (&optional ihandles)
4102   "Display the MIME parts."
4103   (save-excursion
4104     (save-selected-window
4105       (let ((window (get-buffer-window gnus-article-buffer))
4106             (point (point)))
4107         (when window
4108           (select-window window)
4109           ;; We have to do this since selecting the window
4110           ;; may change the point.  So we set the window point.
4111           (set-window-point window point)))
4112       (let* ((handles (or ihandles (mm-dissect-buffer 
4113                                     gnus-article-no-strict-mime)
4114                           (mm-uu-dissect)))
4115              buffer-read-only handle name type b e display)
4116         (when (and (not ihandles)
4117                    (not gnus-displaying-mime))
4118           ;; Top-level call; we clean up.
4119           (when gnus-article-mime-handles
4120             (mm-destroy-parts gnus-article-mime-handles)
4121             (setq gnus-article-mime-handle-alist nil));; A trick.
4122           (setq gnus-article-mime-handles handles)
4123           ;; We allow users to glean info from the handles.
4124           (when gnus-article-mime-part-function
4125             (gnus-mime-part-function handles)))
4126         (if (and handles
4127                  (or (not (stringp (car handles)))
4128                      (cdr handles)))
4129             (progn
4130               (when (and (not ihandles)
4131                          (not gnus-displaying-mime))
4132                 ;; Clean up for mime parts.
4133                 (article-goto-body)
4134                 (delete-region (point) (point-max)))
4135               (let ((gnus-displaying-mime t))
4136                 (gnus-mime-display-part handles)))
4137           (save-restriction
4138             (article-goto-body)
4139             (narrow-to-region (point) (point-max))
4140             (gnus-treat-article nil 1 1)
4141             (widen)))
4142         (unless ihandles
4143           ;; Highlight the headers.
4144           (save-excursion
4145             (save-restriction
4146               (article-goto-body)
4147               (narrow-to-region (point-min) (point))
4148               (gnus-treat-article 'head))))))))
4149
4150 (defvar gnus-mime-display-multipart-as-mixed nil)
4151 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4152 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4153
4154 (defun gnus-mime-display-part (handle)
4155   (cond
4156    ;; Single part.
4157    ((not (stringp (car handle)))
4158     (gnus-mime-display-single handle))
4159    ;; User-defined multipart
4160    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4161     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4162              handle))
4163    ;; multipart/alternative
4164    ((and (equal (car handle) "multipart/alternative")
4165          (not (or gnus-mime-display-multipart-as-mixed
4166                   gnus-mime-display-multipart-alternative-as-mixed)))
4167     (let ((id (1+ (length gnus-article-mime-handle-alist))))
4168       (push (cons id handle) gnus-article-mime-handle-alist)
4169       (gnus-mime-display-alternative (cdr handle) nil nil id)))
4170    ;; multipart/related
4171    ((and (equal (car handle) "multipart/related")
4172          (not (or gnus-mime-display-multipart-as-mixed
4173                   gnus-mime-display-multipart-related-as-mixed)))
4174     ;;;!!!We should find the start part, but we just default
4175     ;;;!!!to the first part.
4176     ;;(gnus-mime-display-part (cadr handle))
4177     ;;;!!! Most multipart/related is an HTML message plus images.
4178     ;;;!!! Unfortunately we are unable to let W3 display those
4179     ;;;!!! included images, so we just display it as a mixed multipart.
4180     ;;(gnus-mime-display-mixed (cdr handle))
4181     ;;;!!! No, w3 can display everything just fine.
4182     (gnus-mime-display-part (cadr handle)))
4183    ((equal (car handle) "multipart/signed")
4184     (gnus-add-wash-type 'signed)
4185     (gnus-mime-display-security handle))
4186    ((equal (car handle) "multipart/encrypted")
4187     (gnus-add-wash-type 'encrypted)
4188     (gnus-mime-display-security handle))
4189    ;; Other multiparts are handled like multipart/mixed.
4190    (t
4191     (gnus-mime-display-mixed (cdr handle)))))
4192
4193 (defun gnus-mime-part-function (handles)
4194   (if (stringp (car handles))
4195       (mapcar 'gnus-mime-part-function (cdr handles))
4196     (funcall gnus-article-mime-part-function handles)))
4197
4198 (defun gnus-mime-display-mixed (handles)
4199   (mapcar 'gnus-mime-display-part handles))
4200
4201 (defun gnus-mime-display-single (handle)
4202   (let ((type (mm-handle-media-type handle))
4203         (ignored gnus-ignored-mime-types)
4204         (not-attachment t)
4205         (move nil)
4206         display text)
4207     (catch 'ignored
4208       (progn
4209         (while ignored
4210           (when (string-match (pop ignored) type)
4211             (throw 'ignored nil)))
4212         (if (and (setq not-attachment
4213                        (and (not (mm-inline-override-p handle))
4214                             (or (not (mm-handle-disposition handle))
4215                                 (equal (car (mm-handle-disposition handle))
4216                                        "inline")
4217                                 (mm-attachment-override-p handle))))
4218                  (mm-automatic-display-p handle)
4219                  (or (and
4220                       (mm-inlinable-p handle)
4221                       (mm-inlined-p handle))
4222                      (mm-automatic-external-display-p type)))
4223             (setq display t)
4224           (when (equal (mm-handle-media-supertype handle) "text")
4225             (setq text t)))
4226         (let ((id (1+ (length gnus-article-mime-handle-alist)))
4227               beg)
4228           (push (cons id handle) gnus-article-mime-handle-alist)
4229           (when (or (not display)
4230                     (not (gnus-unbuttonized-mime-type-p type)))
4231             ;(gnus-article-insert-newline)
4232             (gnus-insert-mime-button
4233              handle id (list (or display (and not-attachment text))))
4234             (gnus-article-insert-newline)
4235             ;(gnus-article-insert-newline)
4236             ;; Remember modify the number of forward lines.
4237             (setq move t))
4238           (setq beg (point))
4239           (cond
4240            (display
4241             (when move
4242               (forward-line -1)
4243               (setq beg (point)))
4244             (let ((mail-parse-charset gnus-newsgroup-charset)
4245                   (mail-parse-ignored-charsets
4246                    (save-excursion (condition-case ()
4247                                        (set-buffer gnus-summary-buffer)
4248                                      (error))
4249                                    gnus-newsgroup-ignored-charsets)))
4250               (mm-display-part handle t))
4251             (goto-char (point-max)))
4252            ((and text not-attachment)
4253             (when move
4254               (forward-line -1)
4255               (setq beg (point)))
4256             (gnus-article-insert-newline)
4257             (mm-insert-inline handle (mm-get-part handle))
4258             (goto-char (point-max))))
4259           ;; Do highlighting.
4260           (save-excursion
4261             (save-restriction
4262               (narrow-to-region beg (point))
4263               (gnus-treat-article
4264                nil id
4265                (gnus-article-mime-total-parts)
4266                (mm-handle-media-type handle)))))))))
4267
4268 (defun gnus-unbuttonized-mime-type-p (type)
4269   "Say whether TYPE is to be unbuttonized."
4270   (unless gnus-inhibit-mime-unbuttonizing
4271     (when (catch 'found
4272             (let ((types gnus-unbuttonized-mime-types))
4273               (while types
4274                 (when (string-match (pop types) type)
4275                   (throw 'found t)))))
4276       (not (catch 'found
4277              (let ((types gnus-buttonized-mime-types))
4278                (while types
4279                  (when (string-match (pop types) type)
4280                    (throw 'found t)))))))))
4281
4282 (defun gnus-article-insert-newline ()
4283   "Insert a newline, but mark it as undeletable."
4284   (gnus-put-text-property
4285    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4286
4287 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4288   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4289          (ihandles handles)
4290          (point (point))
4291          handle buffer-read-only from props begend not-pref)
4292     (save-window-excursion
4293       (save-restriction
4294         (when ibegend
4295           (narrow-to-region (car ibegend)
4296                             (or (cdr ibegend)
4297                                 (progn
4298                                   (goto-char (car ibegend))
4299                                   (forward-line 2)
4300                                   (point))))
4301           (delete-region (point-min) (point-max))
4302           (mm-remove-parts handles))
4303         (setq begend (list (point-marker)))
4304         ;; Do the toggle.
4305         (unless (setq not-pref (cadr (member preferred ihandles)))
4306           (setq not-pref (car ihandles)))
4307         (when (or ibegend
4308                   (not preferred)
4309                   (not (gnus-unbuttonized-mime-type-p
4310                         "multipart/alternative")))
4311           (gnus-add-text-properties
4312            (setq from (point))
4313            (progn
4314              (insert (format "%d.  " id))
4315              (point))
4316            `(gnus-callback
4317              (lambda (handles)
4318                (unless ,(not ibegend)
4319                  (setq gnus-article-mime-handle-alist
4320                        ',gnus-article-mime-handle-alist))
4321                (gnus-mime-display-alternative
4322                 ',ihandles ',not-pref ',begend ,id))
4323              ,@(gnus-local-map-property gnus-mime-button-map)
4324              ,gnus-mouse-face-prop ,gnus-article-mouse-face
4325              face ,gnus-article-button-face
4326              gnus-part ,id
4327              gnus-data ,handle))
4328           (widget-convert-button 'link from (point)
4329                                  :action 'gnus-widget-press-button
4330                                  :button-keymap gnus-widget-button-keymap)
4331           ;; Do the handles
4332           (while (setq handle (pop handles))
4333             (gnus-add-text-properties
4334              (setq from (point))
4335              (progn
4336                (insert (format "(%c) %-18s"
4337                                (if (equal handle preferred) ?* ? )
4338                                (mm-handle-media-type handle)))
4339                (point))
4340              `(gnus-callback
4341                (lambda (handles)
4342                  (unless ,(not ibegend)
4343                    (setq gnus-article-mime-handle-alist
4344                          ',gnus-article-mime-handle-alist))
4345                  (gnus-mime-display-alternative
4346                   ',ihandles ',handle ',begend ,id))
4347                ,@(gnus-local-map-property gnus-mime-button-map)
4348                ,gnus-mouse-face-prop ,gnus-article-mouse-face
4349                face ,gnus-article-button-face
4350                gnus-part ,id
4351                gnus-data ,handle))
4352             (widget-convert-button 'link from (point)
4353                                    :action 'gnus-widget-press-button
4354                                    :button-keymap gnus-widget-button-keymap)
4355             (insert "  "))
4356           (insert "\n\n"))
4357         (when preferred
4358           (if (stringp (car preferred))
4359               (gnus-display-mime preferred)
4360             (let ((mail-parse-charset gnus-newsgroup-charset)
4361                   (mail-parse-ignored-charsets
4362                    (save-excursion (set-buffer gnus-summary-buffer)
4363                                    gnus-newsgroup-ignored-charsets)))
4364               (mm-display-part preferred)
4365               ;; Do highlighting.
4366               (save-excursion
4367                 (save-restriction
4368                   (narrow-to-region (car begend) (point-max))
4369                   (gnus-treat-article
4370                    nil (length gnus-article-mime-handle-alist)
4371                    (gnus-article-mime-total-parts)
4372                    (mm-handle-media-type handle))))))
4373           (goto-char (point-max))
4374           (setcdr begend (point-marker)))))
4375     (when ibegend
4376       (goto-char point))))
4377
4378 (defconst gnus-article-wash-status-strings
4379   (let ((alist '((cite "c" "Possible hidden citation text"
4380                        " " "All citation text visible")
4381                  (headers "h" "Hidden headers"
4382                           " " "All headers visible.")
4383                  (pgp "p" "Encrypted or signed message status hidden"
4384                       " " "No hidden encryption nor digital signature status")
4385                  (signature "s" "Signature has been hidden"
4386                             " " "Signature is visible")
4387                  (overstrike "o" "Overstrike (^H) characters applied"
4388                              " " "No overstrike characters applied")
4389                  (emphasis "e" "/*_Emphasis_*/ characters applied"
4390                            " " "No /*_emphasis_*/ characters applied")))
4391         result)
4392     (dolist (entry alist result)
4393       (let ((key (nth 0 entry))
4394             (on (copy-sequence (nth 1 entry)))
4395             (on-help (nth 2 entry))
4396             (off (copy-sequence (nth 3 entry)))
4397             (off-help (nth 4 entry)))
4398         (put-text-property 0 1 'help-echo on-help on)
4399         (put-text-property 0 1 'help-echo off-help off)
4400         (push (list key on off) result))))
4401   "Alist of strings describing wash status in the mode line.
4402 Each entry has the form (KEY ON OF), where the KEY is a symbol
4403 representing the particular washing function, ON is the string to use
4404 in the article mode line when the washing function is active, and OFF
4405 is the string to use when it is inactive.")
4406
4407 (defun gnus-article-wash-status-entry (key value)
4408   (let ((entry (assoc key gnus-article-wash-status-strings)))
4409     (if value (nth 1 entry) (nth 2 entry))))
4410
4411 (defun gnus-article-wash-status ()
4412   "Return a string which display status of article washing."
4413   (save-excursion
4414     (set-buffer gnus-article-buffer)
4415     (let ((cite (memq 'cite gnus-article-wash-types))
4416           (headers (memq 'headers gnus-article-wash-types))
4417           (boring (memq 'boring-headers gnus-article-wash-types))
4418           (pgp (memq 'pgp gnus-article-wash-types))
4419           (pem (memq 'pem gnus-article-wash-types))
4420           (signed (memq 'signed gnus-article-wash-types))
4421           (encrypted (memq 'encrypted gnus-article-wash-types))
4422           (signature (memq 'signature gnus-article-wash-types))
4423           (overstrike (memq 'overstrike gnus-article-wash-types))
4424           (emphasis (memq 'emphasis gnus-article-wash-types)))
4425       (concat
4426        (gnus-article-wash-status-entry 'cite cite)
4427        (gnus-article-wash-status-entry 'headers (or headers boring))
4428        (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4429        (gnus-article-wash-status-entry 'signature signature)
4430        (gnus-article-wash-status-entry 'overstrike overstrike)
4431        (gnus-article-wash-status-entry 'emphasis emphasis)))))
4432
4433 (defun gnus-add-wash-type (type)
4434   "Add a washing of TYPE to the current status."
4435   (add-to-list 'gnus-article-wash-types type))
4436
4437 (defun gnus-delete-wash-type (type)
4438   "Add a washing of TYPE to the current status."
4439   (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4440
4441 (defun gnus-add-image (category image)
4442   "Add IMAGE of CATEGORY to the list of displayed images."
4443   (let ((entry (assq category gnus-article-image-alist)))
4444     (unless entry
4445       (setq entry (list category))
4446       (push entry gnus-article-image-alist))
4447     (nconc entry (list image))))
4448
4449 (defun gnus-delete-images (category)
4450   "Delete all images in CATEGORY."
4451   (let ((entry (assq category gnus-article-image-alist)))
4452     (dolist (image (cdr entry))
4453       (gnus-remove-image image))
4454     (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4455     (gnus-delete-wash-type category)))
4456
4457 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4458
4459 (defun gnus-article-maybe-hide-headers ()
4460   "Hide unwanted headers if `gnus-have-all-headers' is nil.
4461 Provided for backwards compatibility."
4462   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4463                  (not (save-excursion (set-buffer gnus-summary-buffer)
4464                                       gnus-have-all-headers)))
4465              (not gnus-inhibit-hiding))
4466     (gnus-article-hide-headers)))
4467
4468 ;;; Article savers.
4469
4470 (defun gnus-output-to-file (file-name)
4471   "Append the current article to a file named FILE-NAME."
4472   (let ((artbuf (current-buffer)))
4473     (with-temp-buffer
4474       (insert-buffer-substring artbuf)
4475       ;; Append newline at end of the buffer as separator, and then
4476       ;; save it to file.
4477       (goto-char (point-max))
4478       (insert "\n")
4479       (let ((file-name-coding-system nnmail-pathname-coding-system))
4480         (mm-append-to-file (point-min) (point-max) file-name))
4481       t)))
4482
4483 (defun gnus-narrow-to-page (&optional arg)
4484   "Narrow the article buffer to a page.
4485 If given a numerical ARG, move forward ARG pages."
4486   (interactive "P")
4487   (setq arg (if arg (prefix-numeric-value arg) 0))
4488   (save-excursion
4489     (set-buffer gnus-article-buffer)
4490     (goto-char (point-min))
4491     (widen)
4492     ;; Remove any old next/prev buttons.
4493     (when (gnus-visual-p 'page-marker)
4494       (let ((buffer-read-only nil))
4495         (gnus-remove-text-with-property 'gnus-prev)
4496         (gnus-remove-text-with-property 'gnus-next)))
4497     (when
4498         (cond ((< arg 0)
4499                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4500               ((> arg 0)
4501                (re-search-forward page-delimiter nil 'move arg)))
4502       (goto-char (match-end 0)))
4503     (narrow-to-region
4504      (point)
4505      (if (re-search-forward page-delimiter nil 'move)
4506          (match-beginning 0)
4507        (point)))
4508     (when (and (gnus-visual-p 'page-marker)
4509                (not (= (point-min) 1)))
4510       (save-excursion
4511         (goto-char (point-min))
4512         (gnus-insert-prev-page-button)))
4513     (when (and (gnus-visual-p 'page-marker)
4514                (< (+ (point-max) 2) (buffer-size)))
4515       (save-excursion
4516         (goto-char (point-max))
4517         (gnus-insert-next-page-button)))))
4518
4519 ;; Article mode commands
4520
4521 (defun gnus-article-goto-next-page ()
4522   "Show the next page of the article."
4523   (interactive)
4524   (when (gnus-article-next-page)
4525     (goto-char (point-min))
4526     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4527
4528 (defun gnus-article-goto-prev-page ()
4529   "Show the next page of the article."
4530   (interactive)
4531   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4532     (gnus-article-prev-page nil)))
4533
4534 (defun gnus-article-next-page (&optional lines)
4535   "Show the next page of the current article.
4536 If end of article, return non-nil.  Otherwise return nil.
4537 Argument LINES specifies lines to be scrolled up."
4538   (interactive "p")
4539   (move-to-window-line -1)
4540   (if (save-excursion
4541         (end-of-line)
4542         (and (pos-visible-in-window-p)  ;Not continuation line.
4543              (eobp)))
4544       ;; Nothing in this page.
4545       (if (or (not gnus-page-broken)
4546               (save-excursion
4547                 (save-restriction
4548                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4549           t                             ;Nothing more.
4550         (gnus-narrow-to-page 1)         ;Go to next page.
4551         nil)
4552     ;; More in this page.
4553     (let ((scroll-in-place nil))
4554       (condition-case ()
4555           (scroll-up lines)
4556         (end-of-buffer
4557          ;; Long lines may cause an end-of-buffer error.
4558          (goto-char (point-max)))))
4559     (move-to-window-line 0)
4560     nil))
4561
4562 (defun gnus-article-prev-page (&optional lines)
4563   "Show previous page of current article.
4564 Argument LINES specifies lines to be scrolled down."
4565   (interactive "p")
4566   (move-to-window-line 0)
4567   (if (and gnus-page-broken
4568            (bobp)
4569            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4570       (progn
4571         (gnus-narrow-to-page -1)        ;Go to previous page.
4572         (goto-char (point-max))
4573         (recenter -1))
4574     (let ((scroll-in-place nil))
4575       (prog1
4576           (condition-case ()
4577               (scroll-down lines)
4578             (beginning-of-buffer
4579              (goto-char (point-min))))
4580         (move-to-window-line 0)))))
4581
4582 (defun gnus-article-refer-article ()
4583   "Read article specified by message-id around point."
4584   (interactive)
4585   (let ((point (point)))
4586     (search-forward ">" nil t)          ;Move point to end of "<....>".
4587     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4588         (let ((message-id (match-string 1)))
4589           (goto-char point)
4590           (set-buffer gnus-summary-buffer)
4591           (gnus-summary-refer-article message-id))
4592       (goto-char (point))
4593       (error "No references around point"))))
4594
4595 (defun gnus-article-show-summary ()
4596   "Reconfigure windows to show summary buffer."
4597   (interactive)
4598   (if (not (gnus-buffer-live-p gnus-summary-buffer))
4599       (error "There is no summary buffer for this article buffer")
4600     (gnus-article-set-globals)
4601     (gnus-configure-windows 'article)
4602     (gnus-summary-goto-subject gnus-current-article)
4603     (gnus-summary-position-point)))
4604
4605 (defun gnus-article-describe-briefly ()
4606   "Describe article mode commands briefly."
4607   (interactive)
4608   (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")))
4609
4610 (defun gnus-article-summary-command ()
4611   "Execute the last keystroke in the summary buffer."
4612   (interactive)
4613   (let ((obuf (current-buffer))
4614         (owin (current-window-configuration))
4615         func)
4616     (switch-to-buffer gnus-article-current-summary 'norecord)
4617     (setq func (lookup-key (current-local-map) (this-command-keys)))
4618     (call-interactively func)
4619     (set-buffer obuf)
4620     (set-window-configuration owin)
4621     (set-window-point (get-buffer-window (current-buffer)) (point))))
4622
4623 (defun gnus-article-summary-command-nosave ()
4624   "Execute the last keystroke in the summary buffer."
4625   (interactive)
4626   (let (func)
4627     (pop-to-buffer gnus-article-current-summary 'norecord)
4628     (setq func (lookup-key (current-local-map) (this-command-keys)))
4629     (call-interactively func)))
4630
4631 (defun gnus-article-check-buffer ()
4632   "Beep if not in an article buffer."
4633   (unless (equal major-mode 'gnus-article-mode)
4634     (error "Command invoked outside of a Gnus article buffer")))
4635
4636 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4637   "Read a summary buffer key sequence and execute it from the article buffer."
4638   (interactive "P")
4639   (gnus-article-check-buffer)
4640   (let ((nosaves
4641          '("q" "Q"  "c" "r" "\C-c\C-f" "m"  "a" "f"
4642            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4643            "=" "^" "\M-^" "|"))
4644         (nosave-but-article
4645          '("A\r"))
4646         (nosave-in-article
4647          '("\C-d"))
4648         (up-to-top
4649          '("n" "Gn" "p" "Gp"))
4650         keys new-sum-point)
4651     (save-excursion
4652       (set-buffer gnus-article-current-summary)
4653       (let (gnus-pick-mode)
4654         (push (or key last-command-event) unread-command-events)
4655         (setq keys (if (featurep 'xemacs)
4656                        (events-to-keys (read-key-sequence nil))
4657                      (read-key-sequence nil)))))
4658
4659     (message "")
4660
4661     (if (or (member keys nosaves)
4662             (member keys nosave-but-article)
4663             (member keys nosave-in-article))
4664         (let (func)
4665           (save-window-excursion
4666             (pop-to-buffer gnus-article-current-summary 'norecord)
4667             ;; We disable the pick minor mode commands.
4668             (let (gnus-pick-mode)
4669               (setq func (lookup-key (current-local-map) keys))))
4670           (if (or (not func)
4671                   (numberp func))
4672               (ding)
4673             (unless (member keys nosave-in-article)
4674               (set-buffer gnus-article-current-summary))
4675             (call-interactively func)
4676             (setq new-sum-point (point)))
4677           (when (member keys nosave-but-article)
4678             (pop-to-buffer gnus-article-buffer 'norecord)))
4679       ;; These commands should restore window configuration.
4680       (let ((obuf (current-buffer))
4681             (owin (current-window-configuration))
4682             (opoint (point))
4683             (summary gnus-article-current-summary)
4684             func in-buffer selected)
4685         (if not-restore-window
4686             (pop-to-buffer summary 'norecord)
4687           (switch-to-buffer summary 'norecord))
4688         (setq in-buffer (current-buffer))
4689         ;; We disable the pick minor mode commands.
4690         (if (and (setq func (let (gnus-pick-mode)
4691                               (lookup-key (current-local-map) keys)))
4692                  (functionp func))
4693             (progn
4694               (call-interactively func)
4695               (setq new-sum-point (point))
4696               (when (eq in-buffer (current-buffer))
4697                 (setq selected (gnus-summary-select-article))
4698                 (set-buffer obuf)
4699                 (unless not-restore-window
4700                   (set-window-configuration owin))
4701                 (when (eq selected 'old)
4702                   (article-goto-body)
4703                   (set-window-start (get-buffer-window (current-buffer))
4704                                     1)
4705                   (set-window-point (get-buffer-window (current-buffer))
4706                                     (point)))
4707                 (let ((win (get-buffer-window gnus-article-current-summary)))
4708                   (when win
4709                     (set-window-point win new-sum-point))))    )
4710           (switch-to-buffer gnus-article-buffer)
4711           (ding))))))
4712
4713 (defun gnus-article-describe-key (key)
4714   "Display documentation of the function invoked by KEY.  KEY is a string."
4715   (interactive "kDescribe key: ")
4716   (gnus-article-check-buffer)
4717   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4718       (save-excursion
4719         (set-buffer gnus-article-current-summary)
4720         (let (gnus-pick-mode)
4721           (if (featurep 'xemacs)
4722               (progn
4723                 (push (elt key 0) unread-command-events)
4724                 (setq key (events-to-keys
4725                            (read-key-sequence "Describe key: "))))
4726             (setq unread-command-events
4727                   (mapcar
4728                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4729                    (string-to-list key)))
4730             (setq key (read-key-sequence "Describe key: "))))
4731         (describe-key key))
4732     (describe-key key)))
4733
4734 (defun gnus-article-describe-key-briefly (key &optional insert)
4735   "Display documentation of the function invoked by KEY.  KEY is a string."
4736   (interactive "kDescribe key: \nP")
4737   (gnus-article-check-buffer)
4738   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4739       (save-excursion
4740         (set-buffer gnus-article-current-summary)
4741         (let (gnus-pick-mode)
4742           (if (featurep 'xemacs)
4743               (progn
4744                 (push (elt key 0) unread-command-events)
4745                 (setq key (events-to-keys
4746                            (read-key-sequence "Describe key: "))))
4747             (setq unread-command-events
4748                   (mapcar
4749                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4750                    (string-to-list key)))
4751             (setq key (read-key-sequence "Describe key: "))))
4752         (describe-key-briefly key insert))
4753     (describe-key-briefly key insert)))
4754
4755 (defun gnus-article-reply-with-original (&optional wide)
4756   "Start composing a reply mail to the current message.
4757 The text in the region will be yanked.  If the region isn't active,
4758 the entire article will be yanked."
4759   (interactive "P")
4760   (let ((article (cdr gnus-article-current)) cont)
4761     (if (not (mark t))
4762         (gnus-summary-reply (list (list article)) wide)
4763       (setq cont (buffer-substring (point) (mark t)))
4764       ;; Deactivate active regions.
4765       (when (and (boundp 'transient-mark-mode)
4766                  transient-mark-mode)
4767         (setq mark-active nil))
4768       (gnus-summary-reply
4769        (list (list article cont)) wide))))
4770
4771 (defun gnus-article-followup-with-original ()
4772   "Compose a followup to the current article.
4773 The text in the region will be yanked.  If the region isn't active,
4774 the entire article will be yanked."
4775   (interactive)
4776   (let ((article (cdr gnus-article-current))
4777         cont)
4778     (if (not (mark t))
4779         (gnus-summary-followup (list (list article)))
4780       (setq cont (buffer-substring (point) (mark t)))
4781       ;; Deactivate active regions.
4782       (when (and (boundp 'transient-mark-mode)
4783                  transient-mark-mode)
4784         (setq mark-active nil))
4785       (gnus-summary-followup
4786        (list (list article cont))))))
4787
4788 (defun gnus-article-hide (&optional arg force)
4789   "Hide all the gruft in the current article.
4790 This means that PGP stuff, signatures, cited text and (some)
4791 headers will be hidden.
4792 If given a prefix, show the hidden text instead."
4793   (interactive (append (gnus-article-hidden-arg) (list 'force)))
4794   (gnus-article-hide-headers arg)
4795   (gnus-article-hide-list-identifiers arg)
4796   (gnus-article-hide-pgp arg)
4797   (gnus-article-hide-citation-maybe arg force)
4798   (gnus-article-hide-signature arg))
4799
4800 (defun gnus-article-maybe-highlight ()
4801   "Do some article highlighting if article highlighting is requested."
4802   (when (gnus-visual-p 'article-highlight 'highlight)
4803     (gnus-article-highlight-some)))
4804
4805 (defun gnus-check-group-server ()
4806   ;; Make sure the connection to the server is alive.
4807   (unless (gnus-server-opened
4808            (gnus-find-method-for-group gnus-newsgroup-name))
4809     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4810     (gnus-request-group gnus-newsgroup-name t)))
4811
4812 (eval-when-compile
4813   (autoload 'nneething-get-file-name "nneething"))
4814
4815 (defun gnus-request-article-this-buffer (article group)
4816   "Get an article and insert it into this buffer."
4817   (let (do-update-line sparse-header)
4818     (prog1
4819         (save-excursion
4820           (erase-buffer)
4821           (gnus-kill-all-overlays)
4822           (setq group (or group gnus-newsgroup-name))
4823
4824           ;; Using `gnus-request-article' directly will insert the article into
4825           ;; `nntp-server-buffer' - so we'll save some time by not having to
4826           ;; copy it from the server buffer into the article buffer.
4827
4828           ;; We only request an article by message-id when we do not have the
4829           ;; headers for it, so we'll have to get those.
4830           (when (stringp article)
4831             (gnus-read-header article))
4832
4833           ;; If the article number is negative, that means that this article
4834           ;; doesn't belong in this newsgroup (possibly), so we find its
4835           ;; message-id and request it by id instead of number.
4836           (when (and (numberp article)
4837                      gnus-summary-buffer
4838                      (get-buffer gnus-summary-buffer)
4839                      (gnus-buffer-exists-p gnus-summary-buffer))
4840             (save-excursion
4841               (set-buffer gnus-summary-buffer)
4842               (let ((header (gnus-summary-article-header article)))
4843                 (when (< article 0)
4844                   (cond
4845                    ((memq article gnus-newsgroup-sparse)
4846                     ;; This is a sparse gap article.
4847                     (setq do-update-line article)
4848                     (setq article (mail-header-id header))
4849                     (setq sparse-header (gnus-read-header article))
4850                     (setq gnus-newsgroup-sparse
4851                           (delq article gnus-newsgroup-sparse)))
4852                    ((vectorp header)
4853                     ;; It's a real article.
4854                     (setq article (mail-header-id header)))
4855                    (t
4856                     ;; It is an extracted pseudo-article.
4857                     (setq article 'pseudo)
4858                     (gnus-request-pseudo-article header))))
4859
4860                 (let ((method (gnus-find-method-for-group
4861                                gnus-newsgroup-name)))
4862                   (when (and (eq (car method) 'nneething)
4863                              (vectorp header))
4864                     (let ((dir (nneething-get-file-name
4865                                 (mail-header-id header))))
4866                       (when (and (stringp dir)
4867                                  (file-directory-p dir))
4868                         (setq article 'nneething)
4869                         (gnus-group-enter-directory dir))))))))
4870
4871           (cond
4872            ;; Refuse to select canceled articles.
4873            ((and (numberp article)
4874                  gnus-summary-buffer
4875                  (get-buffer gnus-summary-buffer)
4876                  (gnus-buffer-exists-p gnus-summary-buffer)
4877                  (eq (cdr (save-excursion
4878                             (set-buffer gnus-summary-buffer)
4879                             (assq article gnus-newsgroup-reads)))
4880                      gnus-canceled-mark))
4881             nil)
4882            ;; We first check `gnus-original-article-buffer'.
4883            ((and (get-buffer gnus-original-article-buffer)
4884                  (numberp article)
4885                  (save-excursion
4886                    (set-buffer gnus-original-article-buffer)
4887                    (and (equal (car gnus-original-article) group)
4888                         (eq (cdr gnus-original-article) article))))
4889             (insert-buffer-substring gnus-original-article-buffer)
4890             'article)
4891            ;; Check the backlog.
4892            ((and gnus-keep-backlog
4893                  (gnus-backlog-request-article group article (current-buffer)))
4894             'article)
4895            ;; Check asynchronous pre-fetch.
4896            ((gnus-async-request-fetched-article group article (current-buffer))
4897             (gnus-async-prefetch-next group article gnus-summary-buffer)
4898             (when (and (numberp article) gnus-keep-backlog)
4899               (gnus-backlog-enter-article group article (current-buffer)))
4900             'article)
4901            ;; Check the cache.
4902            ((and gnus-use-cache
4903                  (numberp article)
4904                  (gnus-cache-request-article article group))
4905             'article)
4906            ;; Check the agent cache.
4907            ((and gnus-agent gnus-agent-cache gnus-plugged
4908                  (numberp article)
4909                  (gnus-agent-request-article article group))
4910             'article)
4911            ;; Get the article and put into the article buffer.
4912            ((or (stringp article)
4913                 (numberp article))
4914             (let ((gnus-override-method gnus-override-method)
4915                   (methods (and (stringp article)
4916                                 gnus-refer-article-method))
4917                   result
4918                   (buffer-read-only nil))
4919               (if (or (not (listp methods))
4920                       (and (symbolp (car methods))
4921                            (assq (car methods) nnoo-definition-alist)))
4922                   (setq methods (list methods)))
4923               (when (and (null gnus-override-method)
4924                          methods)
4925                 (setq gnus-override-method (pop methods)))
4926               (while (not result)
4927                 (when (eq gnus-override-method 'current)
4928                   (setq gnus-override-method
4929                         (with-current-buffer gnus-summary-buffer
4930                           gnus-current-select-method)))
4931                 (erase-buffer)
4932                 (gnus-kill-all-overlays)
4933                 (let ((gnus-newsgroup-name group))
4934                   (gnus-check-group-server))
4935                 (when (gnus-request-article article group (current-buffer))
4936                   (when (numberp article)
4937                     (gnus-async-prefetch-next group article
4938                                               gnus-summary-buffer)
4939                     (when gnus-keep-backlog
4940                       (gnus-backlog-enter-article
4941                        group article (current-buffer))))
4942                   (setq result 'article))
4943                 (if (not result)
4944                     (if methods
4945                         (setq gnus-override-method (pop methods))
4946                       (setq result 'done))))
4947               (and (eq result 'article) 'article)))
4948            ;; It was a pseudo.
4949            (t article)))
4950
4951       ;; Associate this article with the current summary buffer.
4952       (setq gnus-article-current-summary gnus-summary-buffer)
4953
4954       ;; Take the article from the original article buffer
4955       ;; and place it in the buffer it's supposed to be in.
4956       (when (and (get-buffer gnus-article-buffer)
4957                  (equal (buffer-name (current-buffer))
4958                         (buffer-name (get-buffer gnus-article-buffer))))
4959         (save-excursion
4960           (if (get-buffer gnus-original-article-buffer)
4961               (set-buffer gnus-original-article-buffer)
4962             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4963             (buffer-disable-undo)
4964             (setq major-mode 'gnus-original-article-mode)
4965             (setq buffer-read-only t))
4966           (let (buffer-read-only)
4967             (erase-buffer)
4968             (insert-buffer-substring gnus-article-buffer))
4969           (setq gnus-original-article (cons group article)))
4970
4971         ;; Decode charsets.
4972         (run-hooks 'gnus-article-decode-hook)
4973         ;; Mark article as decoded or not.
4974         (setq gnus-article-decoded-p gnus-article-decode-hook))
4975
4976       ;; Update sparse articles.
4977       (when (and do-update-line
4978                  (or (numberp article)
4979                      (stringp article)))
4980         (let ((buf (current-buffer)))
4981           (set-buffer gnus-summary-buffer)
4982           (gnus-summary-update-article do-update-line sparse-header)
4983           (gnus-summary-goto-subject do-update-line nil t)
4984           (set-window-point (gnus-get-buffer-window (current-buffer) t)
4985                             (point))
4986           (set-buffer buf))))))
4987
4988 ;;;
4989 ;;; Article editing
4990 ;;;
4991
4992 (defcustom gnus-article-edit-mode-hook nil
4993   "Hook run in article edit mode buffers."
4994   :group 'gnus-article-various
4995   :type 'hook)
4996
4997 (defvar gnus-article-edit-done-function nil)
4998
4999 (defvar gnus-article-edit-mode-map nil)
5000
5001 ;; Should we be using derived.el for this?
5002 (unless gnus-article-edit-mode-map
5003   (setq gnus-article-edit-mode-map (make-sparse-keymap))
5004   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5005
5006   (gnus-define-keys gnus-article-edit-mode-map
5007     "\C-c\C-c" gnus-article-edit-done
5008     "\C-c\C-k" gnus-article-edit-exit)
5009
5010   (gnus-define-keys (gnus-article-edit-wash-map
5011                      "\C-c\C-w" gnus-article-edit-mode-map)
5012     "f" gnus-article-edit-full-stops))
5013
5014 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5015   "Major mode for editing articles.
5016 This is an extended text-mode.
5017
5018 \\{gnus-article-edit-mode-map}"
5019   (make-local-variable 'gnus-article-edit-done-function)
5020   (make-local-variable 'gnus-prev-winconf)
5021   (set (make-local-variable 'font-lock-defaults)
5022        '(message-font-lock-keywords t))
5023   (setq buffer-read-only nil)
5024   (buffer-enable-undo)
5025   (widen))
5026
5027 (defun gnus-article-edit (&optional force)
5028   "Edit the current article.
5029 This will have permanent effect only in mail groups.
5030 If FORCE is non-nil, allow editing of articles even in read-only
5031 groups."
5032   (interactive "P")
5033   (when (and (not force)
5034              (gnus-group-read-only-p))
5035     (error "The current newsgroup does not support article editing"))
5036   (gnus-article-date-original)
5037   (gnus-article-edit-article
5038    'ignore
5039    `(lambda (no-highlight)
5040       'ignore
5041       (gnus-summary-edit-article-done
5042        ,(or (mail-header-references gnus-current-headers) "")
5043        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5044
5045 (defun gnus-article-edit-article (start-func exit-func)
5046   "Start editing the contents of the current article buffer."
5047   (let ((winconf (current-window-configuration)))
5048     (set-buffer gnus-article-buffer)
5049     (gnus-article-edit-mode)
5050     (funcall start-func)
5051     (set-buffer-modified-p nil)
5052     (gnus-configure-windows 'edit-article)
5053     (setq gnus-article-edit-done-function exit-func)
5054     (setq gnus-prev-winconf winconf)
5055     (gnus-message 6 "C-c C-c to end edits")))
5056
5057 (defun gnus-article-edit-done (&optional arg)
5058   "Update the article edits and exit."
5059   (interactive "P")
5060   (let ((func gnus-article-edit-done-function)
5061         (buf (current-buffer))
5062         (start (window-start)))
5063     ;; We remove all text props from the article buffer.
5064     (let ((content
5065            (buffer-substring-no-properties (point-min) (point-max)))
5066           (p (point)))
5067       (erase-buffer)
5068       (insert content)
5069       (let ((winconf gnus-prev-winconf))
5070         (gnus-article-mode)
5071         (set-window-configuration winconf)
5072         ;; Tippy-toe some to make sure that point remains where it was.
5073         (save-current-buffer
5074           (set-buffer buf)
5075           (set-window-start (get-buffer-window (current-buffer)) start)
5076           (goto-char p))))
5077     (save-excursion
5078       (set-buffer buf)
5079       (let ((buffer-read-only nil))
5080         (funcall func arg))
5081       ;; The cache and backlog have to be flushed somewhat.
5082       (when gnus-keep-backlog
5083         (gnus-backlog-remove-article
5084          (car gnus-article-current) (cdr gnus-article-current)))
5085       ;; Flush original article as well.
5086       (save-excursion
5087         (when (get-buffer gnus-original-article-buffer)
5088           (set-buffer gnus-original-article-buffer)
5089           (setq gnus-original-article nil)))
5090       (when gnus-use-cache
5091         (gnus-cache-update-article
5092          (car gnus-article-current) (cdr gnus-article-current))))
5093     (set-buffer buf)
5094     (set-window-start (get-buffer-window buf) start)
5095     (set-window-point (get-buffer-window buf) (point))))
5096
5097 (defun gnus-article-edit-exit ()
5098   "Exit the article editing without updating."
5099   (interactive)
5100   (when (or (not (buffer-modified-p))
5101             (yes-or-no-p "Article modified; kill anyway? "))
5102     (let ((curbuf (current-buffer))
5103           (p (point))
5104           (window-start (window-start)))
5105       (erase-buffer)
5106       (if (gnus-buffer-live-p gnus-original-article-buffer)
5107           (insert-buffer gnus-original-article-buffer))
5108       (let ((winconf gnus-prev-winconf))
5109         (gnus-article-mode)
5110         (set-window-configuration winconf)
5111         ;; Tippy-toe some to make sure that point remains where it was.
5112         (save-current-buffer
5113           (set-buffer curbuf)
5114           (set-window-start (get-buffer-window (current-buffer)) window-start)
5115           (goto-char p))))))
5116
5117 (defun gnus-article-edit-full-stops ()
5118   "Interactively repair spacing at end of sentences."
5119   (interactive)
5120   (save-excursion
5121     (goto-char (point-min))
5122     (search-forward-regexp "^$" nil t)
5123     (let ((case-fold-search nil))
5124       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5125
5126 ;;;
5127 ;;; Article highlights
5128 ;;;
5129
5130 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5131
5132 ;;; Internal Variables:
5133
5134 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)"
5135   "Regular expression that matches URLs."
5136   :group 'gnus-article-buttons
5137   :type 'regexp)
5138
5139 (defcustom gnus-button-alist
5140   `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5141      0 t gnus-button-handle-news 3)
5142     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5143      gnus-button-handle-news 2)
5144     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5145      1 t
5146      gnus-button-fetch-group 4)
5147     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5148     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5149      t gnus-button-message-id 3)
5150     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5151     ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5152     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5153     ;; This is info
5154     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
5155      gnus-button-handle-info 2)
5156     ;; This is how URLs _should_ be embedded in text...
5157     ("<URL: *\\([^<>]*\\)>" 1 t gnus-button-embedded-url 1)
5158     ;; Raw URLs.
5159     (,gnus-button-url-regexp 0 t browse-url 0))
5160   "*Alist of regexps matching buttons in article bodies.
5161
5162 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5163 REGEXP: is the string matching text around the button,
5164 BUTTON: is the number of the regexp grouping actually matching the button,
5165 FORM: is a lisp expression which must eval to true for the button to
5166 be added,
5167 CALLBACK: is the function to call when the user push this button, and each
5168 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5169
5170 CALLBACK can also be a variable, in that case the value of that
5171 variable it the real callback function."
5172   :group 'gnus-article-buttons
5173   :type '(repeat (list regexp
5174                        (integer :tag "Button")
5175                        (sexp :tag "Form")
5176                        (function :tag "Callback")
5177                        (repeat :tag "Par"
5178                                :inline t
5179                                (integer :tag "Regexp group")))))
5180
5181 (defcustom gnus-header-button-alist
5182   `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5183      0 t gnus-button-message-id 0)
5184     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5185     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5186      0 t gnus-button-mailto 0)
5187     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5188     ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5189     ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5190     ("^[^:]+:" "\\bmailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5191     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5192      gnus-button-message-id 3))
5193   "*Alist of headers and regexps to match buttons in article heads.
5194
5195 This alist is very similar to `gnus-button-alist', except that each
5196 alist has an additional HEADER element first in each entry:
5197
5198 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5199
5200 HEADER is a regexp to match a header.  For a fuller explanation, see
5201 `gnus-button-alist'."
5202   :group 'gnus-article-buttons
5203   :group 'gnus-article-headers
5204   :type '(repeat (list (regexp :tag "Header")
5205                        regexp
5206                        (integer :tag "Button")
5207                        (sexp :tag "Form")
5208                        (function :tag "Callback")
5209                        (repeat :tag "Par"
5210                                :inline t
5211                                (integer :tag "Regexp group")))))
5212
5213 (defvar gnus-button-regexp nil)
5214 (defvar gnus-button-marker-list nil)
5215 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5216
5217 (defvar gnus-button-last nil)
5218 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5219
5220 ;;; Commands:
5221
5222 (defun gnus-article-push-button (event)
5223   "Check text under the mouse pointer for a callback function.
5224 If the text under the mouse pointer has a `gnus-callback' property,
5225 call it with the value of the `gnus-data' text property."
5226   (interactive "e")
5227   (set-buffer (window-buffer (posn-window (event-start event))))
5228   (let* ((pos (posn-point (event-start event)))
5229          (data (get-text-property pos 'gnus-data))
5230          (fun (get-text-property pos 'gnus-callback)))
5231     (goto-char pos)
5232     (when fun
5233       (funcall fun data))))
5234
5235 (defun gnus-article-press-button ()
5236   "Check text at point for a callback function.
5237 If the text at point has a `gnus-callback' property,
5238 call it with the value of the `gnus-data' text property."
5239   (interactive)
5240   (let* ((data (get-text-property (point) 'gnus-data))
5241          (fun (get-text-property (point) 'gnus-callback)))
5242     (when fun
5243       (funcall fun data))))
5244
5245 (defun gnus-article-highlight (&optional force)
5246   "Highlight current article.
5247 This function calls `gnus-article-highlight-headers',
5248 `gnus-article-highlight-citation',
5249 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5250 do the highlighting.  See the documentation for those functions."
5251   (interactive (list 'force))
5252   (gnus-article-highlight-headers)
5253   (gnus-article-highlight-citation force)
5254   (gnus-article-highlight-signature)
5255   (gnus-article-add-buttons force)
5256   (gnus-article-add-buttons-to-head))
5257
5258 (defun gnus-article-highlight-some (&optional force)
5259   "Highlight current article.
5260 This function calls `gnus-article-highlight-headers',
5261 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5262 do the highlighting.  See the documentation for those functions."
5263   (interactive (list 'force))
5264   (gnus-article-highlight-headers)
5265   (gnus-article-highlight-signature)
5266   (gnus-article-add-buttons))
5267
5268 (defun gnus-article-highlight-headers ()
5269   "Highlight article headers as specified by `gnus-header-face-alist'."
5270   (interactive)
5271   (save-excursion
5272     (set-buffer gnus-article-buffer)
5273     (save-restriction
5274       (let ((alist gnus-header-face-alist)
5275             (buffer-read-only nil)
5276             (case-fold-search t)
5277             (inhibit-point-motion-hooks t)
5278             entry regexp header-face field-face from hpoints fpoints)
5279         (article-narrow-to-head)
5280         (while (setq entry (pop alist))
5281           (goto-char (point-min))
5282           (setq regexp (concat "^\\("
5283                                (if (string-equal "" (nth 0 entry))
5284                                    "[^\t ]"
5285                                  (nth 0 entry))
5286                                "\\)")
5287                 header-face (nth 1 entry)
5288                 field-face (nth 2 entry))
5289           (while (and (re-search-forward regexp nil t)
5290                       (not (eobp)))
5291             (beginning-of-line)
5292             (setq from (point))
5293             (unless (search-forward ":" nil t)
5294               (forward-char 1))
5295             (when (and header-face
5296                        (not (memq (point) hpoints)))
5297               (push (point) hpoints)
5298               (gnus-put-text-property from (point) 'face header-face))
5299             (when (and field-face
5300                        (not (memq (setq from (point)) fpoints)))
5301               (push from fpoints)
5302               (if (re-search-forward "^[^ \t]" nil t)
5303                   (forward-char -2)
5304                 (goto-char (point-max)))
5305               (gnus-put-text-property from (point) 'face field-face))))))))
5306
5307 (defun gnus-article-highlight-signature ()
5308   "Highlight the signature in an article.
5309 It does this by highlighting everything after
5310 `gnus-signature-separator' using `gnus-signature-face'."
5311   (interactive)
5312   (save-excursion
5313     (set-buffer gnus-article-buffer)
5314     (let ((buffer-read-only nil)
5315           (inhibit-point-motion-hooks t))
5316       (save-restriction
5317         (when (and gnus-signature-face
5318                    (gnus-article-narrow-to-signature))
5319           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5320                             'face gnus-signature-face)
5321           (widen)
5322           (gnus-article-search-signature)
5323           (let ((start (match-beginning 0))
5324                 (end (set-marker (make-marker) (1+ (match-end 0)))))
5325             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
5326                                      end)))))))
5327
5328 (defun gnus-button-in-region-p (b e prop)
5329   "Say whether PROP exists in the region."
5330   (text-property-not-all b e prop nil))
5331
5332 (defun gnus-article-add-buttons (&optional force)
5333   "Find external references in the article and make buttons of them.
5334 \"External references\" are things like Message-IDs and URLs, as
5335 specified by `gnus-button-alist'."
5336   (interactive (list 'force))
5337   (save-excursion
5338     (set-buffer gnus-article-buffer)
5339     (let ((buffer-read-only nil)
5340           (inhibit-point-motion-hooks t)
5341           (case-fold-search t)
5342           (alist gnus-button-alist)
5343           beg entry regexp)
5344       ;; Remove all old markers.
5345       (let (marker entry new-list)
5346         (while (setq marker (pop gnus-button-marker-list))
5347           (if (or (< marker (point-min)) (>= marker (point-max)))
5348               (push marker new-list)
5349             (goto-char marker)
5350             (when (setq entry (gnus-button-entry))
5351               (put-text-property (match-beginning (nth 1 entry))
5352                                  (match-end (nth 1 entry))
5353                                  'gnus-callback nil))
5354             (set-marker marker nil)))
5355         (setq gnus-button-marker-list new-list))
5356       ;; We skip the headers.
5357       (article-goto-body)
5358       (setq beg (point))
5359       (while (setq entry (pop alist))
5360         (setq regexp (car entry))
5361         (goto-char beg)
5362         (while (re-search-forward regexp nil t)
5363           (let* ((start (and entry (match-beginning (nth 1 entry))))
5364                  (end (and entry (match-end (nth 1 entry))))
5365                  (from (match-beginning 0)))
5366             (when (and (or (eq t (nth 2 entry))
5367                            (eval (nth 2 entry)))
5368                        (not (gnus-button-in-region-p
5369                              start end 'gnus-callback)))
5370               ;; That optional form returned non-nil, so we add the
5371               ;; button.
5372               (gnus-article-add-button
5373                start end 'gnus-button-push
5374                (car (push (set-marker (make-marker) from)
5375                           gnus-button-marker-list))))))))))
5376
5377 ;; Add buttons to the head of an article.
5378 (defun gnus-article-add-buttons-to-head ()
5379   "Add buttons to the head of the article."
5380   (interactive)
5381   (save-excursion
5382     (set-buffer gnus-article-buffer)
5383     (save-restriction
5384       (let ((buffer-read-only nil)
5385             (inhibit-point-motion-hooks t)
5386             (case-fold-search t)
5387             (alist gnus-header-button-alist)
5388             entry beg end)
5389         (article-narrow-to-head)
5390         (while alist
5391           ;; Each alist entry.
5392           (setq entry (car alist)
5393                 alist (cdr alist))
5394           (goto-char (point-min))
5395           (while (re-search-forward (car entry) nil t)
5396             ;; Each header matching the entry.
5397             (setq beg (match-beginning 0))
5398             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5399                                (match-beginning 0))
5400                           (point-max)))
5401             (goto-char beg)
5402             (while (re-search-forward (nth 1 entry) end t)
5403               ;; Each match within a header.
5404               (let* ((entry (cdr entry))
5405                      (start (match-beginning (nth 1 entry)))
5406                      (end (match-end (nth 1 entry)))
5407                      (form (nth 2 entry)))
5408                 (goto-char (match-end 0))
5409                 (when (eval form)
5410                   (gnus-article-add-button
5411                    start end (nth 3 entry)
5412                    (buffer-substring (match-beginning (nth 4 entry))
5413                                      (match-end (nth 4 entry)))))))
5414             (goto-char end)))))))
5415
5416 ;;; External functions:
5417
5418 (defun gnus-article-add-button (from to fun &optional data)
5419   "Create a button between FROM and TO with callback FUN and data DATA."
5420   (when gnus-article-button-face
5421     (gnus-overlay-put (gnus-make-overlay from to)
5422                       'face gnus-article-button-face))
5423   (gnus-add-text-properties
5424    from to
5425    (nconc (and gnus-article-mouse-face
5426                (list gnus-mouse-face-prop gnus-article-mouse-face))
5427           (list 'gnus-callback fun)
5428           (and data (list 'gnus-data data))))
5429   (widget-convert-button 'link from to :action 'gnus-widget-press-button
5430                          :button-keymap gnus-widget-button-keymap))
5431
5432 ;;; Internal functions:
5433
5434 (defun gnus-article-set-globals ()
5435   (save-excursion
5436     (set-buffer gnus-summary-buffer)
5437     (gnus-set-global-variables)))
5438
5439 (defun gnus-signature-toggle (end)
5440   (save-excursion
5441     (set-buffer gnus-article-buffer)
5442     (let ((buffer-read-only nil)
5443           (inhibit-point-motion-hooks t))
5444       (if (text-property-any end (point-max) 'article-type 'signature)
5445           (progn
5446             (gnus-delete-wash-type 'signature)
5447             (gnus-remove-text-properties-when
5448              'article-type 'signature end (point-max)
5449              (cons 'article-type (cons 'signature
5450                                        gnus-hidden-properties))))
5451         (gnus-add-wash-type 'signature)
5452         (gnus-add-text-properties-when
5453          'article-type nil end (point-max)
5454          (cons 'article-type (cons 'signature
5455                                    gnus-hidden-properties)))))
5456     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
5457       (gnus-set-mode-line 'article))))
5458
5459 (defun gnus-button-entry ()
5460   ;; Return the first entry in `gnus-button-alist' matching this place.
5461   (let ((alist gnus-button-alist)
5462         (entry nil))
5463     (while alist
5464       (setq entry (pop alist))
5465       (if (looking-at (car entry))
5466           (setq alist nil)
5467         (setq entry nil)))
5468     entry))
5469
5470 (defun gnus-button-push (marker)
5471   ;; Push button starting at MARKER.
5472   (save-excursion
5473     (goto-char marker)
5474     (let* ((entry (gnus-button-entry))
5475            (inhibit-point-motion-hooks t)
5476            (fun (nth 3 entry))
5477            (args (mapcar (lambda (group)
5478                            (let ((string (match-string group)))
5479                              (gnus-set-text-properties
5480                               0 (length string) nil string)
5481                              string))
5482                          (nthcdr 4 entry))))
5483       (cond
5484        ((fboundp fun)
5485         (apply fun args))
5486        ((and (boundp fun)
5487              (fboundp (symbol-value fun)))
5488         (apply (symbol-value fun) args))
5489        (t
5490         (gnus-message 1 "You must define `%S' to use this button"
5491                       (cons fun args)))))))
5492
5493 (defun gnus-parse-news-url (url)
5494   (let (scheme server group message-id articles)
5495     (with-temp-buffer
5496       (insert url)
5497       (goto-char (point-min))
5498       (when (looking-at "\\([A-Za-z]+\\):")
5499         (setq scheme (match-string 1))
5500         (goto-char (match-end 0)))
5501       (when (looking-at "//\\([^/]+\\)/")
5502         (setq server (match-string 1))
5503         (goto-char (match-end 0)))
5504
5505       (cond
5506        ((looking-at "\\(.*@.*\\)")
5507         (setq message-id (match-string 1)))
5508        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
5509         (setq group (match-string 1)
5510               articles (split-string (match-string 2) "-")))
5511        ((looking-at "\\([^/]+\\)/?")
5512         (setq group (match-string 1)))
5513        (t
5514         (error "Unknown news URL syntax"))))
5515     (list scheme server group message-id articles)))
5516
5517 (defun gnus-button-handle-news (url)
5518   "Fetch a news URL."
5519   (destructuring-bind (scheme server group message-id articles)
5520       (gnus-parse-news-url url)
5521     (cond
5522      (message-id
5523       (save-excursion
5524         (set-buffer gnus-summary-buffer)
5525         (if server
5526             (let ((gnus-refer-article-method (list (list 'nntp server))))
5527               (gnus-summary-refer-article message-id))
5528           (gnus-summary-refer-article message-id))))
5529      (group
5530       (gnus-button-fetch-group url)))))
5531
5532 (defun gnus-button-handle-info (url)
5533   "Fetch an info URL."
5534   (if (string-match
5535        "^\\([^:/]+\\)?/\\(.*\\)"
5536        url)
5537       (gnus-info-find-node
5538        (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
5539                        "Gnus")
5540                ")"
5541                (gnus-url-unhex-string (match-string 2 url))))
5542     (error "Can't parse %s" url)))
5543
5544 (defun gnus-button-message-id (message-id)
5545   "Fetch MESSAGE-ID."
5546   (save-excursion
5547     (set-buffer gnus-summary-buffer)
5548     (gnus-summary-refer-article message-id)))
5549
5550 (defun gnus-button-fetch-group (address)
5551   "Fetch GROUP specified by ADDRESS."
5552   (if (not (string-match "[:/]" address))
5553       ;; This is just a simple group url.
5554       (gnus-group-read-ephemeral-group address gnus-select-method)
5555     (if (not
5556          (string-match
5557           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
5558           address))
5559         (error "Can't parse %s" address)
5560       (gnus-group-read-ephemeral-group
5561        (match-string 4 address)
5562        `(nntp ,(match-string 1 address)
5563               (nntp-address ,(match-string 1 address))
5564               (nntp-port-number ,(if (match-end 3)
5565                                      (match-string 3 address)
5566                                    "nntp")))
5567        nil nil nil
5568        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
5569
5570 (defun gnus-url-parse-query-string (query &optional downcase)
5571   (let (retval pairs cur key val)
5572     (setq pairs (split-string query "&"))
5573     (while pairs
5574       (setq cur (car pairs)
5575             pairs (cdr pairs))
5576       (if (not (string-match "=" cur))
5577           nil                           ; Grace
5578         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5579               val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
5580         (if downcase
5581             (setq key (downcase key)))
5582         (setq cur (assoc key retval))
5583         (if cur
5584             (setcdr cur (cons val (cdr cur)))
5585           (setq retval (cons (list key val) retval)))))
5586     retval))
5587
5588 (defun gnus-url-mailto (url)
5589   ;; Send mail to someone
5590   (when (string-match "mailto:/*\\(.*\\)" url)
5591     (setq url (substring url (match-beginning 1) nil)))
5592   (let (to args subject func)
5593     (if (string-match (regexp-quote "?") url)
5594         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5595               args (gnus-url-parse-query-string
5596                     (substring url (match-end 0) nil) t))
5597       (setq to (gnus-url-unhex-string url)))
5598     (setq args (cons (list "to" to) args)
5599           subject (cdr-safe (assoc "subject" args)))
5600     (gnus-msg-mail)
5601     (while args
5602       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5603       (if (fboundp func)
5604           (funcall func)
5605         (message-position-on-field (caar args)))
5606       (insert (mapconcat 'identity (cdar args) ", "))
5607       (setq args (cdr args)))
5608     (if subject
5609         (message-goto-body)
5610       (message-goto-subject))))
5611
5612 (defun gnus-button-embedded-url (address)
5613   "Activate ADDRESS with `browse-url'."
5614   (browse-url (gnus-strip-whitespace address)))
5615
5616 ;;; Next/prev buttons in the article buffer.
5617
5618 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5619 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5620
5621 (defvar gnus-prev-page-map
5622   (let ((map (make-sparse-keymap)))
5623     (unless (>= emacs-major-version 21)
5624       ;; XEmacs doesn't care.
5625       (set-keymap-parent map gnus-article-mode-map))
5626     (define-key map gnus-mouse-2 'gnus-button-prev-page)
5627     (define-key map "\r" 'gnus-button-prev-page)
5628     map))
5629
5630 (defun gnus-insert-prev-page-button ()
5631   (let ((b (point))
5632         (buffer-read-only nil))
5633     (gnus-eval-format
5634      gnus-prev-page-line-format nil
5635      `(,@(gnus-local-map-property gnus-prev-page-map)
5636          gnus-prev t
5637          gnus-callback gnus-article-button-prev-page
5638          article-type annotation))
5639     (widget-convert-button
5640      'link b (point)
5641      :action 'gnus-button-prev-page
5642      :button-keymap gnus-prev-page-map)))
5643
5644 (defvar gnus-prev-page-map
5645   (let ((map (make-sparse-keymap)))
5646     (unless (>= emacs-major-version 21)
5647       ;; XEmacs doesn't care.
5648       (set-keymap-parent map gnus-article-mode-map))
5649     (define-key map gnus-mouse-2 'gnus-button-prev-page)
5650     (define-key map "\r" 'gnus-button-prev-page)
5651     map))
5652
5653 (defvar gnus-next-page-map
5654   (let ((map (make-sparse-keymap)))
5655     (unless (>= emacs-major-version 21)
5656       ;; XEmacs doesn't care.
5657       (set-keymap-parent map gnus-article-mode-map))
5658     (define-key map gnus-mouse-2 'gnus-button-next-page)
5659     (define-key map "\r" 'gnus-button-next-page)
5660     map))
5661
5662 (defun gnus-button-next-page (&optional args more-args)
5663   "Go to the next page."
5664   (interactive)
5665   (let ((win (selected-window)))
5666     (select-window (gnus-get-buffer-window gnus-article-buffer t))
5667     (gnus-article-next-page)
5668     (select-window win)))
5669
5670 (defun gnus-button-prev-page (&optional args more-args)
5671   "Go to the prev page."
5672   (interactive)
5673   (let ((win (selected-window)))
5674     (select-window (gnus-get-buffer-window gnus-article-buffer t))
5675     (gnus-article-prev-page)
5676     (select-window win)))
5677
5678 (defun gnus-insert-next-page-button ()
5679   (let ((b (point))
5680         (buffer-read-only nil))
5681     (gnus-eval-format gnus-next-page-line-format nil
5682                       `(,@(gnus-local-map-property gnus-next-page-map)
5683                           gnus-next t
5684                           gnus-callback gnus-article-button-next-page
5685                           article-type annotation))
5686     (widget-convert-button
5687      'link b (point)
5688      :action 'gnus-button-next-page
5689      :button-keymap gnus-next-page-map)))
5690
5691 (defun gnus-article-button-next-page (arg)
5692   "Go to the next page."
5693   (interactive "P")
5694   (let ((win (selected-window)))
5695     (select-window (gnus-get-buffer-window gnus-article-buffer t))
5696     (gnus-article-next-page)
5697     (select-window win)))
5698
5699 (defun gnus-article-button-prev-page (arg)
5700   "Go to the prev page."
5701   (interactive "P")
5702   (let ((win (selected-window)))
5703     (select-window (gnus-get-buffer-window gnus-article-buffer t))
5704     (gnus-article-prev-page)
5705     (select-window win)))
5706
5707 (defvar gnus-decode-header-methods
5708   '(mail-decode-encoded-word-region)
5709   "List of methods used to decode headers.
5710
5711 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
5712 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
5713 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5714 whose names match REGEXP.
5715
5716 For example:
5717 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5718  mail-decode-encoded-word-region
5719  (\"chinese\" . rfc1843-decode-region))
5720 ")
5721
5722 (defvar gnus-decode-header-methods-cache nil)
5723
5724 (defun gnus-multi-decode-header (start end)
5725   "Apply the functions from `gnus-encoded-word-methods' that match."
5726   (unless (and gnus-decode-header-methods-cache
5727                (eq gnus-newsgroup-name
5728                    (car gnus-decode-header-methods-cache)))
5729     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5730     (mapcar (lambda (x)
5731               (if (symbolp x)
5732                   (nconc gnus-decode-header-methods-cache (list x))
5733                 (if (and gnus-newsgroup-name
5734                          (string-match (car x) gnus-newsgroup-name))
5735                     (nconc gnus-decode-header-methods-cache
5736                            (list (cdr x))))))
5737           gnus-decode-header-methods))
5738   (let ((xlist gnus-decode-header-methods-cache))
5739     (pop xlist)
5740     (save-restriction
5741       (narrow-to-region start end)
5742       (while xlist
5743         (funcall (pop xlist) (point-min) (point-max))))))
5744
5745 ;;;
5746 ;;; Treatment top-level handling.
5747 ;;;
5748
5749 (defun gnus-treat-article (condition &optional part-number total-parts type)
5750   (let ((length (- (point-max) (point-min)))
5751         (alist gnus-treatment-function-alist)
5752         (article-goto-body-goes-to-point-min-p t)
5753         (treated-type
5754          (or (not type)
5755              (catch 'found
5756                (let ((list gnus-article-treat-types))
5757                  (while list
5758                    (when (string-match (pop list) type)
5759                      (throw 'found t)))))))
5760         (highlightp (gnus-visual-p 'article-highlight 'highlight))
5761         val elem)
5762     (gnus-run-hooks 'gnus-part-display-hook)
5763     (while (setq elem (pop alist))
5764       (setq val
5765             (save-excursion
5766               (if (gnus-buffer-live-p gnus-summary-buffer)
5767                   (set-buffer gnus-summary-buffer))
5768               (symbol-value (car elem))))
5769       (when (and (or (consp val)
5770                      treated-type)
5771                  (gnus-treat-predicate val)
5772                  (or (not (get (car elem) 'highlight))
5773                      highlightp))
5774         (save-restriction
5775           (funcall (cadr elem)))))))
5776
5777 ;; Dynamic variables.
5778 (eval-when-compile
5779   (defvar part-number)
5780   (defvar total-parts)
5781   (defvar type)
5782   (defvar condition)
5783   (defvar length))
5784
5785 (defun gnus-treat-predicate (val)
5786   (cond
5787    ((null val)
5788     nil)
5789    ((and (listp val)
5790          (stringp (car val)))
5791     (apply 'gnus-or (mapcar `(lambda (s)
5792                                (string-match s ,(or gnus-newsgroup-name "")))
5793                             val)))
5794    ((listp val)
5795     (let ((pred (pop val)))
5796       (cond
5797        ((eq pred 'or)
5798         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5799        ((eq pred 'and)
5800         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5801        ((eq pred 'not)
5802         (not (gnus-treat-predicate (car val))))
5803        ((eq pred 'typep)
5804         (equal (car val) type))
5805        (t
5806         (error "%S is not a valid predicate" pred)))))
5807    (condition
5808     (eq condition val))
5809    ((eq val t)
5810     t)
5811    ((eq val 'head)
5812     nil)
5813    ((eq val 'last)
5814     (eq part-number total-parts))
5815    ((numberp val)
5816     (< length val))
5817    (t
5818     (error "%S is not a valid value" val))))
5819
5820 (defun gnus-article-encrypt-body (protocol &optional n)
5821   "Encrypt the article body."
5822   (interactive
5823    (list
5824     (or gnus-article-encrypt-protocol
5825         (completing-read "Encrypt protocol: "
5826                          gnus-article-encrypt-protocol-alist
5827                          nil t))
5828     current-prefix-arg))
5829   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5830     (unless func
5831       (error (format "Can't find the encrypt protocol %s" protocol)))
5832     (if (equal gnus-newsgroup-name "nndraft:drafts")
5833         (error "Can't encrypt the article in group nndraft:drafts"))
5834     (if (equal gnus-newsgroup-name "nndraft:queue")
5835         (error "Don't encrypt the article in group nndraft:queue"))
5836     (gnus-summary-iterate n
5837       (save-excursion
5838         (set-buffer gnus-summary-buffer)
5839         (let ((mail-parse-charset gnus-newsgroup-charset)
5840               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5841               (summary-buffer gnus-summary-buffer)
5842               references point)
5843           (gnus-set-global-variables)
5844           (when (gnus-group-read-only-p)
5845             (error "The current newsgroup does not support article encrypt"))
5846           (gnus-summary-show-article t)
5847           (setq references
5848               (or (mail-header-references gnus-current-headers) ""))
5849           (set-buffer gnus-article-buffer)
5850           (let* ((buffer-read-only nil)
5851                  (headers
5852                   (mapcar (lambda (field)
5853                             (and (save-restriction
5854                                    (message-narrow-to-head)
5855                                    (goto-char (point-min))
5856                                    (search-forward field nil t))
5857                                  (prog2
5858                                      (message-narrow-to-field)
5859                                      (buffer-substring (point-min) (point-max))
5860                                    (delete-region (point-min) (point-max))
5861                                    (widen))))
5862                           '("Content-Type:" "Content-Transfer-Encoding:"
5863                             "Content-Disposition:"))))
5864             (message-narrow-to-head)
5865             (message-remove-header "MIME-Version")
5866             (goto-char (point-max))
5867             (setq point (point))
5868             (insert (apply 'concat headers))
5869             (widen)
5870             (narrow-to-region point (point-max))
5871             (let ((message-options message-options))
5872               (message-options-set 'message-sender user-mail-address)
5873               (message-options-set 'message-recipients user-mail-address)
5874               (message-options-set 'message-sign-encrypt 'not)
5875               (funcall func))
5876             (goto-char (point-min))
5877             (insert "MIME-Version: 1.0\n")
5878             (widen)
5879             (gnus-summary-edit-article-done
5880              references nil summary-buffer t))
5881           (when gnus-keep-backlog
5882             (gnus-backlog-remove-article
5883              (car gnus-article-current) (cdr gnus-article-current)))
5884           (save-excursion
5885             (when (get-buffer gnus-original-article-buffer)
5886               (set-buffer gnus-original-article-buffer)
5887               (setq gnus-original-article nil)))
5888           (when gnus-use-cache
5889             (gnus-cache-update-article
5890              (car gnus-article-current) (cdr gnus-article-current))))))))
5891
5892 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5893   "The following specs can be used:
5894 %t  The security MIME type
5895 %i  Additional info
5896 %d  Details
5897 %D  Details if button is pressed")
5898
5899 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5900   "The following specs can be used:
5901 %t  The security MIME type
5902 %i  Additional info
5903 %d  Details
5904 %D  Details if button is pressed")
5905
5906 (defvar gnus-mime-security-button-line-format-alist
5907   '((?t gnus-tmp-type ?s)
5908     (?i gnus-tmp-info ?s)
5909     (?d gnus-tmp-details ?s)
5910     (?D gnus-tmp-pressed-details ?s)))
5911
5912 (defvar gnus-mime-security-button-map
5913   (let ((map (make-sparse-keymap)))
5914     (unless (>= (string-to-number emacs-version) 21)
5915       (set-keymap-parent map gnus-article-mode-map))
5916     (define-key map gnus-mouse-2 'gnus-article-push-button)
5917     (define-key map "\r" 'gnus-article-press-button)
5918     map))
5919
5920 (defvar gnus-mime-security-details-buffer nil)
5921
5922 (defvar gnus-mime-security-button-pressed nil)
5923
5924 (defvar gnus-mime-security-show-details-inline t
5925   "If non-nil, show details in the article buffer.")
5926
5927 (defun gnus-mime-security-verify-or-decrypt (handle)
5928   (mm-remove-parts (cdr handle))
5929   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5930         point buffer-read-only)
5931     (if region
5932         (goto-char (car region)))
5933     (save-restriction
5934       (narrow-to-region (point) (point))
5935       (with-current-buffer (mm-handle-multipart-original-buffer handle)
5936         (let* ((mm-verify-option 'known)
5937                (mm-decrypt-option 'known)
5938                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5939           (unless (eq nparts (cdr handle))
5940             (mm-destroy-parts (cdr handle))
5941             (setcdr handle nparts))))
5942       (setq point (point))
5943       (gnus-mime-display-security handle)
5944       (goto-char (point-max)))
5945     (when region
5946       (delete-region (point) (cdr region))
5947       (set-marker (car region) nil)
5948       (set-marker (cdr region) nil))
5949     (goto-char point)))
5950
5951 (defun gnus-mime-security-show-details (handle)
5952   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5953     (if details
5954         (if gnus-mime-security-show-details-inline
5955             (let ((gnus-mime-security-button-pressed t)
5956                   (gnus-mime-security-button-line-format
5957                    (get-text-property (point) 'gnus-line-format))
5958                 buffer-read-only)
5959               (forward-char -1)
5960               (while (eq (get-text-property (point) 'gnus-line-format)
5961                          gnus-mime-security-button-line-format)
5962                 (forward-char -1))
5963               (forward-char)
5964               (save-restriction
5965                 (narrow-to-region (point) (point))
5966                 (gnus-insert-mime-security-button handle))
5967               (delete-region (point)
5968                              (or (text-property-not-all
5969                                   (point) (point-max)
5970                                   'gnus-line-format
5971                                   gnus-mime-security-button-line-format)
5972                                  (point-max))))
5973           (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5974               (with-current-buffer gnus-mime-security-details-buffer
5975                 (erase-buffer)
5976                 t)
5977             (setq gnus-mime-security-details-buffer
5978                   (gnus-get-buffer-create "*MIME Security Details*")))
5979           (with-current-buffer gnus-mime-security-details-buffer
5980             (insert details)
5981             (goto-char (point-min)))
5982           (pop-to-buffer gnus-mime-security-details-buffer))
5983       (gnus-message 5 "No details."))))
5984
5985 (defun gnus-mime-security-press-button (handle)
5986   (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5987       (gnus-mime-security-show-details handle)
5988     (gnus-mime-security-verify-or-decrypt handle)))
5989
5990 (defun gnus-insert-mime-security-button (handle &optional displayed)
5991   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5992          (gnus-tmp-type
5993           (concat
5994            (or (nth 2 (assoc protocol mm-verify-function-alist))
5995                (nth 2 (assoc protocol mm-decrypt-function-alist))
5996                "Unknown")
5997            (if (equal (car handle) "multipart/signed")
5998                " Signed" " Encrypted")
5999            " Part"))
6000          (gnus-tmp-info
6001           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6002               "Undecided"))
6003          (gnus-tmp-details
6004           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6005          gnus-tmp-pressed-details
6006          b e)
6007     (setq gnus-tmp-details
6008           (if gnus-tmp-details
6009               (concat "\n" gnus-tmp-details) ""))
6010     (setq gnus-tmp-pressed-details
6011           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6012     (unless (bolp)
6013       (insert "\n"))
6014     (setq b (point))
6015     (gnus-eval-format
6016      gnus-mime-security-button-line-format
6017      gnus-mime-security-button-line-format-alist
6018      `(,@(gnus-local-map-property gnus-mime-security-button-map)
6019          gnus-callback gnus-mime-security-press-button
6020          gnus-line-format ,gnus-mime-security-button-line-format
6021          article-type annotation
6022          gnus-data ,handle))
6023     (setq e (point))
6024     (widget-convert-button
6025      'link b e
6026      :mime-handle handle
6027      :action 'gnus-widget-press-button
6028      :button-keymap gnus-mime-security-button-map
6029      :help-echo
6030      (lambda (widget/window &optional overlay pos)
6031        ;; Needed to properly clear the message due to a bug in
6032        ;; wid-edit (XEmacs only).
6033        (if (boundp 'help-echo-owns-message)
6034            (setq help-echo-owns-message t))
6035        (format
6036         "%S: show detail"
6037         (aref gnus-mouse-2 0))))))
6038
6039 (defun gnus-mime-display-security (handle)
6040   (save-restriction
6041     (narrow-to-region (point) (point))
6042     (unless (gnus-unbuttonized-mime-type-p (car handle))
6043       (gnus-insert-mime-security-button handle))
6044     (gnus-mime-display-mixed (cdr handle))
6045     (unless (bolp)
6046       (insert "\n"))
6047     (unless (gnus-unbuttonized-mime-type-p (car handle))
6048       (let ((gnus-mime-security-button-line-format
6049              gnus-mime-security-button-end-line-format))
6050         (gnus-insert-mime-security-button handle)))
6051     (mm-set-handle-multipart-parameter
6052      handle 'gnus-region
6053      (cons (set-marker (make-marker) (point-min))
6054            (set-marker (make-marker) (point-max))))))
6055
6056 (gnus-ems-redefine)
6057
6058 (provide 'gnus-art)
6059
6060 (run-hooks 'gnus-art-load-hook)
6061
6062 ;;; gnus-art.el ends here