1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
43 (defgroup gnus-article nil
45 :link '(custom-manual "(gnus)The Article Buffer")
48 (defgroup gnus-article-treat nil
49 "Treating article parts."
50 :link '(custom-manual "(gnus)Article Hiding")
53 (defgroup gnus-article-hiding nil
54 "Hiding article parts."
55 :link '(custom-manual "(gnus)Article Hiding")
58 (defgroup gnus-article-highlight nil
59 "Article highlighting."
60 :link '(custom-manual "(gnus)Article Highlighting")
64 (defgroup gnus-article-signature nil
66 :link '(custom-manual "(gnus)Article Signature")
69 (defgroup gnus-article-headers nil
71 :link '(custom-manual "(gnus)Hiding Headers")
74 (defgroup gnus-article-washing nil
75 "Special commands on articles."
76 :link '(custom-manual "(gnus)Article Washing")
79 (defgroup gnus-article-emphasis nil
80 "Fontisizing articles."
81 :link '(custom-manual "(gnus)Article Fontisizing")
84 (defgroup gnus-article-saving nil
86 :link '(custom-manual "(gnus)Saving Articles")
89 (defgroup gnus-article-mime nil
90 "Worshiping the MIME wonder."
91 :link '(custom-manual "(gnus)Using MIME")
94 (defgroup gnus-article-buttons nil
95 "Pushable buttons in the article buffer."
96 :link '(custom-manual "(gnus)Article Buttons")
99 (defgroup gnus-article-various nil
100 "Other article options."
101 :link '(custom-manual "(gnus)Misc Article")
102 :group 'gnus-article)
104 (defcustom gnus-ignored-headers
105 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
106 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
107 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
108 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
109 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
110 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
111 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
112 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
113 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
114 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
115 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
116 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
117 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
118 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
119 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
120 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
121 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
122 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
124 "*All headers that start with this regexp will be hidden.
125 This variable can also be a list of regexps of headers to be ignored.
126 If `gnus-visible-headers' is non-nil, this variable will be ignored."
127 :type '(choice :custom-show nil
130 :group 'gnus-article-hiding)
132 (defcustom gnus-visible-headers
133 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
134 "*All headers that do not match this regexp will be hidden.
135 This variable can also be a list of regexp of headers to remain visible.
136 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
137 :type '(repeat :value-to-internal (lambda (widget value)
138 (custom-split-regexp-maybe value))
139 :match (lambda (widget value)
141 (widget-editable-list-match widget value)))
143 :group 'gnus-article-hiding)
145 (defcustom gnus-sorted-header-list
146 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
147 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
148 "*This variable is a list of regular expressions.
149 If it is non-nil, headers that match the regular expressions will
150 be placed first in the article buffer in the sequence specified by
152 :type '(repeat regexp)
153 :group 'gnus-article-hiding)
155 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
156 "Headers that are only to be displayed if they have interesting data.
157 Possible values in this list are `empty', `newsgroups', `followup-to',
158 `reply-to', `date', `long-to', and `many-to'."
159 :type '(set (const :tag "Headers with no content." empty)
160 (const :tag "Newsgroups with only one group." newsgroups)
161 (const :tag "Followup-to identical to newsgroups." followup-to)
162 (const :tag "Reply-to identical to from." reply-to)
163 (const :tag "Date less than four days old." date)
164 (const :tag "Very long To header." long-to)
165 (const :tag "Multiple To headers." many-to))
166 :group 'gnus-article-hiding)
168 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
169 "Regexp matching signature separator.
170 This can also be a list of regexps. In that case, it will be checked
171 from head to tail looking for a separator. Searches will be done from
172 the end of the buffer."
173 :type '(repeat string)
174 :group 'gnus-article-signature)
176 (defcustom gnus-signature-limit nil
177 "Provide a limit to what is considered a signature.
178 If it is a number, no signature may not be longer (in characters) than
179 that number. If it is a floating point number, no signature may be
180 longer (in lines) than that number. If it is a function, the function
181 will be called without any parameters, and if it returns nil, there is
182 no signature in the buffer. If it is a string, it will be used as a
183 regexp. If it matches, the text in question is not a signature."
184 :type '(choice (integer :value 200)
186 (function :value fun)
187 (regexp :value ".*"))
188 :group 'gnus-article-signature)
190 (defcustom gnus-hidden-properties '(invisible t intangible t)
191 "Property list to use for hiding text."
193 :group 'gnus-article-hiding)
195 (defcustom gnus-article-x-face-command
196 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
197 "*String or function to be executed to display an X-Face header.
198 If it is a string, the command will be executed in a sub-shell
199 asynchronously. The compressed face will be piped to this command."
200 :type 'string ;Leave function case to Lisp.
201 :group 'gnus-article-washing)
203 (defcustom gnus-article-x-face-too-ugly nil
204 "Regexp matching posters whose face shouldn't be shown automatically."
205 :type '(choice regexp (const nil))
206 :group 'gnus-article-washing)
208 (defcustom gnus-emphasis-alist
210 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
212 '(("_" "_" underline)
215 ("_/" "/_" underline-italic)
216 ("_\\*" "\\*_" underline-bold)
217 ("\\*/" "/\\*" bold-italic)
218 ("_\\*/" "/\\*_" underline-bold-italic))))
219 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
220 2 3 gnus-emphasis-underline)
224 (format format (car spec) (cadr spec))
225 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
227 "*Alist that says how to fontify certain phrases.
228 Each item looks like this:
230 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
232 The first element is a regular expression to be matched. The second
233 is a number that says what regular expression grouping used to find
234 the entire emphasized word. The third is a number that says what
235 regexp grouping should be displayed and highlighted. The fourth
236 is the face used for highlighting."
237 :type '(repeat (list :value ("" 0 0 default)
239 (integer :tag "Match group")
240 (integer :tag "Emphasize group")
242 :group 'gnus-article-emphasis)
244 (defface gnus-emphasis-bold '((t (:bold t)))
245 "Face used for displaying strong emphasized text (*word*)."
246 :group 'gnus-article-emphasis)
248 (defface gnus-emphasis-italic '((t (:italic t)))
249 "Face used for displaying italic emphasized text (/word/)."
250 :group 'gnus-article-emphasis)
252 (defface gnus-emphasis-underline '((t (:underline t)))
253 "Face used for displaying underlined emphasized text (_word_)."
254 :group 'gnus-article-emphasis)
256 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
257 "Face used for displaying underlined bold emphasized text (_*word*_)."
258 :group 'gnus-article-emphasis)
260 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
261 "Face used for displaying underlined italic emphasized text (_*word*_)."
262 :group 'gnus-article-emphasis)
264 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
265 "Face used for displaying bold italic emphasized text (/*word*/)."
266 :group 'gnus-article-emphasis)
268 (defface gnus-emphasis-underline-bold-italic
269 '((t (:bold t :italic t :underline t)))
270 "Face used for displaying underlined bold italic emphasized text.
271 Esample: (_/*word*/_)."
272 :group 'gnus-article-emphasis)
274 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
275 "Format for display of Date headers in article bodies.
276 See `format-time-string' for the possible values.
278 The variable can also be function, which should return a complete Date
279 header. The function is called with one argument, the time, which can
280 be fed to `format-time-string'."
281 :type '(choice string symbol)
282 :link '(custom-manual "(gnus)Article Date")
283 :group 'gnus-article-washing)
286 (autoload 'mail-extract-address-components "mail-extr"))
288 (defcustom gnus-save-all-headers t
289 "*If non-nil, don't remove any headers before saving."
290 :group 'gnus-article-saving
293 (defcustom gnus-prompt-before-saving 'always
294 "*This variable says how much prompting is to be done when saving articles.
295 If it is nil, no prompting will be done, and the articles will be
296 saved to the default files. If this variable is `always', each and
297 every article that is saved will be preceded by a prompt, even when
298 saving large batches of articles. If this variable is neither nil not
299 `always', there the user will be prompted once for a file name for
300 each invocation of the saving commands."
301 :group 'gnus-article-saving
302 :type '(choice (item always)
303 (item :tag "never" nil)
304 (sexp :tag "once" :format "%t\n" :value t)))
306 (defcustom gnus-saved-headers gnus-visible-headers
307 "Headers to keep if `gnus-save-all-headers' is nil.
308 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
309 If that variable is nil, however, all headers that match this regexp
310 will be kept while the rest will be deleted before saving."
311 :group 'gnus-article-saving
314 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
315 "A function to save articles in your favourite format.
316 The function must be interactively callable (in other words, it must
317 be an Emacs command).
319 Gnus provides the following functions:
321 * gnus-summary-save-in-rmail (Rmail format)
322 * gnus-summary-save-in-mail (Unix mail format)
323 * gnus-summary-save-in-folder (MH folder)
324 * gnus-summary-save-in-file (article format)
325 * gnus-summary-save-in-vm (use VM's folder format)
326 * gnus-summary-write-to-file (article format -- overwrite)."
327 :group 'gnus-article-saving
328 :type '(radio (function-item gnus-summary-save-in-rmail)
329 (function-item gnus-summary-save-in-mail)
330 (function-item gnus-summary-save-in-folder)
331 (function-item gnus-summary-save-in-file)
332 (function-item gnus-summary-save-in-vm)
333 (function-item gnus-summary-write-to-file)))
335 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
336 "A function generating a file name to save articles in Rmail format.
337 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
338 :group 'gnus-article-saving
341 (defcustom gnus-mail-save-name 'gnus-plain-save-name
342 "A function generating a file name to save articles in Unix mail format.
343 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
344 :group 'gnus-article-saving
347 (defcustom gnus-folder-save-name 'gnus-folder-save-name
348 "A function generating a file name to save articles in MH folder.
349 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
350 :group 'gnus-article-saving
353 (defcustom gnus-file-save-name 'gnus-numeric-save-name
354 "A function generating a file name to save articles in article format.
355 The function is called with NEWSGROUP, HEADERS, and optional
357 :group 'gnus-article-saving
360 (defcustom gnus-split-methods
361 '((gnus-article-archive-name)
362 (gnus-article-nndoc-name))
363 "*Variable used to suggest where articles are to be saved.
364 For instance, if you would like to save articles related to Gnus in
365 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
366 you could set this variable to something like:
368 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
369 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
371 This variable is an alist where the where the key is the match and the
372 value is a list of possible files to save in if the match is non-nil.
374 If the match is a string, it is used as a regexp match on the
375 article. If the match is a symbol, that symbol will be funcalled
376 from the buffer of the article to be saved with the newsgroup as the
377 parameter. If it is a list, it will be evaled in the same buffer.
379 If this form or function returns a string, this string will be used as
380 a possible file name; and if it returns a non-nil list, that list will
381 be used as possible file names."
382 :group 'gnus-article-saving
383 :type '(repeat (choice (list :value (fun) function)
384 (cons :value ("" "") regexp (repeat string))
387 (defcustom gnus-page-delimiter "^\^L"
388 "*Regexp describing what to use as article page delimiters.
389 The default value is \"^\^L\", which is a form linefeed at the
390 beginning of a line."
392 :group 'gnus-article-various)
394 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
395 "*The format specification for the article mode line.
396 See `gnus-summary-mode-line-format' for a closer description.
398 The following additional specs are available:
400 %w The article washing status.
401 %m The number of MIME parts in the article."
403 :group 'gnus-article-various)
405 (defcustom gnus-article-mode-hook nil
406 "*A hook for Gnus article mode."
408 :group 'gnus-article-various)
410 (defcustom gnus-article-menu-hook nil
411 "*Hook run after the creation of the article mode menu."
413 :group 'gnus-article-various)
415 (defcustom gnus-article-prepare-hook nil
416 "*A hook called after an article has been prepared in the article buffer.
417 If you want to run a special decoding program like nkf, use this hook."
419 :group 'gnus-article-various)
421 (defcustom gnus-article-hide-pgp-hook nil
422 "*A hook called after successfully hiding a PGP signature."
424 :group 'gnus-article-various)
426 (defcustom gnus-article-button-face 'bold
427 "Face used for highlighting buttons in the article buffer.
429 An article button is a piece of text that you can activate by pressing
430 `RET' or `mouse-2' above it."
432 :group 'gnus-article-buttons)
434 (defcustom gnus-article-mouse-face 'highlight
435 "Face used for mouse highlighting in the article buffer.
437 Article buttons will be displayed in this face when the cursor is
440 :group 'gnus-article-buttons)
442 (defcustom gnus-signature-face 'gnus-signature-face
443 "Face used for highlighting a signature in the article buffer.
444 Obsolete; use the face `gnus-signature-face' for customizations instead."
446 :group 'gnus-article-highlight
447 :group 'gnus-article-signature)
449 (defface gnus-signature-face
452 "Face used for highlighting a signature in the article buffer."
453 :group 'gnus-article-highlight
454 :group 'gnus-article-signature)
456 (defface gnus-header-from-face
459 (:foreground "spring green"))
462 (:foreground "red3"))
465 "Face used for displaying from headers."
466 :group 'gnus-article-headers
467 :group 'gnus-article-highlight)
469 (defface gnus-header-subject-face
472 (:foreground "SeaGreen3"))
475 (:foreground "red4"))
477 (:bold t :italic t)))
478 "Face used for displaying subject headers."
479 :group 'gnus-article-headers
480 :group 'gnus-article-highlight)
482 (defface gnus-header-newsgroups-face
485 (:foreground "yellow" :italic t))
488 (:foreground "MidnightBlue" :italic t))
491 "Face used for displaying newsgroups headers."
492 :group 'gnus-article-headers
493 :group 'gnus-article-highlight)
495 (defface gnus-header-name-face
498 (:foreground "SeaGreen"))
501 (:foreground "maroon"))
504 "Face used for displaying header names."
505 :group 'gnus-article-headers
506 :group 'gnus-article-highlight)
508 (defface gnus-header-content-face
511 (:foreground "forest green" :italic t))
514 (:foreground "indianred4" :italic t))
516 (:italic t))) "Face used for displaying header content."
517 :group 'gnus-article-headers
518 :group 'gnus-article-highlight)
520 (defcustom gnus-header-face-alist
521 '(("From" nil gnus-header-from-face)
522 ("Subject" nil gnus-header-subject-face)
523 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
524 ("" gnus-header-name-face gnus-header-content-face))
525 "*Controls highlighting of article header.
527 An alist of the form (HEADER NAME CONTENT).
529 HEADER is a regular expression which should match the name of an
530 header header and NAME and CONTENT are either face names or nil.
532 The name of each header field will be displayed using the face
533 specified by the first element in the list where HEADER match the
534 header name and NAME is non-nil. Similarly, the content will be
535 displayed by the first non-nil matching CONTENT face."
536 :group 'gnus-article-headers
537 :group 'gnus-article-highlight
538 :type '(repeat (list (regexp :tag "Header")
540 (item :tag "skip" nil)
541 (face :value default))
542 (choice :tag "Content"
543 (item :tag "skip" nil)
544 (face :value default)))))
546 (defcustom gnus-article-decode-hook
547 '(article-decode-charset article-decode-encoded-words)
548 "*Hook run to decode charsets in articles."
549 :group 'gnus-article-headers
552 (defcustom gnus-display-mime-function 'gnus-display-mime
553 "Function to display MIME articles."
554 :group 'gnus-article-mime
557 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
558 "Function used to decode headers.")
560 (defvar gnus-article-dumbquotes-map
578 "Table for MS-to-Latin1 translation.")
580 (defcustom gnus-ignored-mime-types nil
581 "List of MIME types that should be ignored by Gnus."
582 :group 'gnus-article-mime
583 :type '(repeat regexp))
585 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
586 "List of MIME types that should not be given buttons when rendered."
587 :group 'gnus-article-mime
588 :type '(repeat regexp))
590 (defcustom gnus-article-mime-part-function nil
591 "Function called with a MIME handle as the argument.
592 This is meant for people who want to do something automatic based
593 on parts -- for instance, adding Vcard info to a database."
594 :group 'gnus-article-mime
598 ;;; The treatment variables
601 (defvar gnus-part-display-hook nil
602 "Hook called on parts that are to receive treatment.")
604 (defvar gnus-article-treat-custom
605 '(choice (const :tag "Off" nil)
607 (const :tag "Header" head)
608 (const :tag "Last" last)
609 (integer :tag "Less")
610 (sexp :tag "Predicate")))
612 (defvar gnus-article-treat-types '("text/plain")
615 (defvar gnus-inhibit-treatment nil
616 "Whether to inhibit treatment.")
618 (defcustom gnus-treat-highlight-signature 'last
619 "Highlight the signature."
620 :group 'gnus-article-treat
621 :type gnus-article-treat-custom)
623 (defcustom gnus-treat-buttonize t
625 :group 'gnus-article-treat
626 :type gnus-article-treat-custom)
628 (defcustom gnus-treat-buttonize-head 'head
629 "Add buttons to the head."
630 :group 'gnus-article-treat
631 :type gnus-article-treat-custom)
633 (defcustom gnus-treat-emphasize t
635 :group 'gnus-article-treat
636 :type gnus-article-treat-custom)
638 (defcustom gnus-treat-strip-cr nil
639 "Remove carriage returns."
640 :group 'gnus-article-treat
641 :type gnus-article-treat-custom)
643 (defcustom gnus-treat-hide-headers 'head
645 :group 'gnus-article-treat
646 :type gnus-article-treat-custom)
648 (defcustom gnus-treat-hide-boring-headers nil
649 "Hide boring headers."
650 :group 'gnus-article-treat
651 :type gnus-article-treat-custom)
653 (defcustom gnus-treat-hide-signature nil
654 "Hide the signature."
655 :group 'gnus-article-treat
656 :type gnus-article-treat-custom)
658 (defcustom gnus-treat-fill-article nil
660 :group 'gnus-article-treat
661 :type gnus-article-treat-custom)
663 (defcustom gnus-treat-hide-citation nil
665 :group 'gnus-article-treat
666 :type gnus-article-treat-custom)
668 (defcustom gnus-treat-strip-pgp t
669 "Strip PGP signatures."
670 :group 'gnus-article-treat
671 :type gnus-article-treat-custom)
673 (defcustom gnus-treat-strip-pem nil
674 "Strip PEM signatures."
675 :group 'gnus-article-treat
676 :type gnus-article-treat-custom)
678 (defcustom gnus-treat-highlight-headers 'head
679 "Highlight the headers."
680 :group 'gnus-article-treat
681 :type gnus-article-treat-custom)
683 (defcustom gnus-treat-highlight-citation t
684 "Highlight cited text."
685 :group 'gnus-article-treat
686 :type gnus-article-treat-custom)
688 (defcustom gnus-treat-date-ut nil
689 "Display the Date in UT (GMT)."
690 :group 'gnus-article-treat
691 :type gnus-article-treat-custom)
693 (defcustom gnus-treat-date-local nil
694 "Display the Date in the local timezone."
695 :group 'gnus-article-treat
696 :type gnus-article-treat-custom)
698 (defcustom gnus-treat-date-lapsed nil
699 "Display the Date header in a way that says how much time has elapsed."
700 :group 'gnus-article-treat
701 :type gnus-article-treat-custom)
703 (defcustom gnus-treat-date-original nil
704 "Display the date in the original timezone."
705 :group 'gnus-article-treat
706 :type gnus-article-treat-custom)
708 (defcustom gnus-treat-strip-trailing-blank-lines nil
709 "Strip trailing blank lines."
710 :group 'gnus-article-treat
711 :type gnus-article-treat-custom)
713 (defcustom gnus-treat-strip-leading-blank-lines nil
714 "Strip leading blank lines."
715 :group 'gnus-article-treat
716 :type gnus-article-treat-custom)
718 (defcustom gnus-treat-strip-multiple-blank-lines nil
719 "Strip multiple blank lines."
720 :group 'gnus-article-treat
721 :type gnus-article-treat-custom)
723 (defcustom gnus-treat-strip-blank-lines nil
724 "Strip all blank lines."
725 :group 'gnus-article-treat
726 :type gnus-article-treat-custom)
728 (defcustom gnus-treat-overstrike t
729 "Treat overstrike highlighting."
730 :group 'gnus-article-treat
731 :type gnus-article-treat-custom)
733 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
735 "Display X-Face headers."
736 :group 'gnus-article-treat
737 :type gnus-article-treat-custom)
739 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
743 :group 'gnus-article-treat
744 :type gnus-article-treat-custom)
746 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
748 :group 'gnus-article-treat
749 :type gnus-article-treat-custom)
751 ;;; Internal variables
753 (defvar article-goto-body-goes-to-point-min-p nil)
755 (defvar gnus-article-mime-handle-alist-1 nil)
756 (defvar gnus-treatment-function-alist
757 '((gnus-treat-highlight-signature gnus-article-highlight-signature)
758 (gnus-treat-buttonize gnus-article-add-buttons)
759 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
760 (gnus-treat-emphasize gnus-article-emphasize)
761 (gnus-treat-fill-article gnus-article-fill-cited-article)
762 (gnus-treat-strip-cr gnus-article-remove-cr)
763 (gnus-treat-hide-headers gnus-article-hide-headers)
764 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
765 (gnus-treat-hide-signature gnus-article-hide-signature)
766 (gnus-treat-hide-citation gnus-article-hide-citation)
767 (gnus-treat-strip-pgp gnus-article-hide-pgp)
768 (gnus-treat-strip-pem gnus-article-hide-pem)
769 (gnus-treat-highlight-headers gnus-article-highlight-headers)
770 (gnus-treat-highlight-citation gnus-article-highlight-citation)
771 (gnus-treat-highlight-signature gnus-article-highlight-signature)
772 (gnus-treat-date-ut gnus-article-date-ut)
773 (gnus-treat-date-local gnus-article-date-local)
774 (gnus-treat-date-lapsed gnus-article-date-lapsed)
775 (gnus-treat-date-original gnus-article-date-original)
776 (gnus-treat-strip-trailing-blank-lines
777 gnus-article-remove-trailing-blank-lines)
778 (gnus-treat-strip-leading-blank-lines
779 gnus-article-strip-leading-blank-lines)
780 (gnus-treat-strip-multiple-blank-lines
781 gnus-article-strip-multiple-blank-lines)
782 (gnus-treat-strip-blank-lines gnus-article-strip-blank-lines)
783 (gnus-treat-overstrike gnus-article-treat-overstrike)
784 (gnus-treat-display-xface gnus-article-display-x-face)
785 (gnus-treat-display-smileys gnus-smiley-display)
786 (gnus-treat-display-picons gnus-article-display-picons)))
788 (defvar gnus-article-mime-handle-alist nil)
789 (defvar article-lapsed-timer nil)
790 (defvar gnus-article-current-summary nil)
792 (defvar gnus-article-mode-syntax-table
793 (let ((table (copy-syntax-table text-mode-syntax-table)))
794 (modify-syntax-entry ?- "w" table)
795 (modify-syntax-entry ?> ")" table)
796 (modify-syntax-entry ?< "(" table)
798 "Syntax table used in article mode buffers.
799 Initialized from `text-mode-syntax-table.")
801 (defvar gnus-save-article-buffer nil)
803 (defvar gnus-article-mode-line-format-alist
804 (nconc '((?w (gnus-article-wash-status) ?s)
805 (?m (gnus-article-mime-part-status) ?s))
806 gnus-summary-mode-line-format-alist))
808 (defvar gnus-number-of-articles-to-be-saved nil)
810 (defvar gnus-inhibit-hiding nil)
812 (defsubst gnus-article-hide-text (b e props)
813 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
814 (add-text-properties b e props)
815 (when (memq 'intangible props)
817 (max (1- b) (point-min))
818 b 'intangible (cddr (memq 'intangible props)))))
820 (defmacro gnus-with-article (article &rest forms)
821 "Select ARTICLE and perform FORMS in the original article buffer.
822 Then replace the article with the result."
824 ;; We don't want the article to be marked as read.
825 (let (gnus-mark-article-hook)
826 (gnus-summary-select-article t t nil ,article))
827 (set-buffer gnus-original-article-buffer)
829 (if (not (gnus-check-backend-function
830 'request-replace-article (car gnus-article-current)))
831 (gnus-message 5 "Read-only group; not replacing")
832 (unless (gnus-request-replace-article
833 ,article (car gnus-article-current)
835 (error "Couldn't replace article")))
836 ;; The cache and backlog have to be flushed somewhat.
837 (when gnus-keep-backlog
838 (gnus-backlog-remove-article
839 (car gnus-article-current) (cdr gnus-article-current)))
841 (gnus-cache-update-article
842 (car gnus-article-current) (cdr gnus-article-current)))))
844 (put 'gnus-with-article 'lisp-indent-function 1)
845 (put 'gnus-with-article 'edebug-form-spec '(form body))
847 (defsubst gnus-article-unhide-text (b e)
848 "Remove hidden text properties from region between B and E."
849 (remove-text-properties b e gnus-hidden-properties)
850 (when (memq 'intangible gnus-hidden-properties)
851 (put-text-property (max (1- b) (point-min))
854 (defun gnus-article-hide-text-type (b e type)
855 "Hide text of TYPE between B and E."
856 (gnus-article-hide-text
857 b e (cons 'article-type (cons type gnus-hidden-properties))))
859 (defun gnus-article-unhide-text-type (b e type)
860 "Unhide text of TYPE between B and E."
861 (remove-text-properties
862 b e (cons 'article-type (cons type gnus-hidden-properties)))
863 (when (memq 'intangible gnus-hidden-properties)
864 (put-text-property (max (1- b) (point-min))
867 (defun gnus-article-hide-text-of-type (type)
868 "Hide text of TYPE in the current buffer."
870 (let ((b (point-min))
872 (while (setq b (text-property-any b e 'article-type type))
873 (add-text-properties b (incf b) gnus-hidden-properties)))))
875 (defun gnus-article-delete-text-of-type (type)
876 "Delete text of TYPE in the current buffer."
878 (let ((b (point-min)))
879 (while (setq b (text-property-any b (point-max) 'article-type type))
881 b (or (text-property-not-all b (point-max) 'article-type type)
884 (defun gnus-article-delete-invisible-text ()
885 "Delete all invisible text in the current buffer."
887 (let ((b (point-min)))
888 (while (setq b (text-property-any b (point-max) 'invisible t))
890 b (or (text-property-not-all b (point-max) 'invisible t)
893 (defun gnus-article-text-type-exists-p (type)
894 "Say whether any text of type TYPE exists in the buffer."
895 (text-property-any (point-min) (point-max) 'article-type type))
897 (defsubst gnus-article-header-rank ()
898 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
899 (let ((list gnus-sorted-header-list)
902 (when (looking-at (car list))
904 (setq list (cdr list))
908 (defun article-hide-headers (&optional arg delete)
909 "Toggle whether to hide unwanted headers and possibly sort them as well.
910 If given a negative prefix, always show; if given a positive prefix,
912 (interactive (gnus-article-hidden-arg))
914 (if (gnus-article-check-hidden-text 'headers arg)
915 ;; Show boring headers as well.
916 (gnus-article-show-hidden-text 'boring-headers)
917 ;; This function might be inhibited.
918 (unless gnus-inhibit-hiding
921 (let ((buffer-read-only nil)
923 (props (nconc (list 'article-type 'headers)
924 gnus-hidden-properties))
925 (max (1+ (length gnus-sorted-header-list)))
926 (ignored (when (not gnus-visible-headers)
927 (cond ((stringp gnus-ignored-headers)
928 gnus-ignored-headers)
929 ((listp gnus-ignored-headers)
930 (mapconcat 'identity gnus-ignored-headers
933 (cond ((stringp gnus-visible-headers)
934 gnus-visible-headers)
935 ((and gnus-visible-headers
936 (listp gnus-visible-headers))
937 (mapconcat 'identity gnus-visible-headers "\\|"))))
938 (inhibit-point-motion-hooks t)
940 ;; First we narrow to just the headers.
942 (goto-char (point-min))
943 ;; Hide any "From " lines at the beginning of (mail) articles.
944 (while (looking-at "From ")
948 (delete-region (point-min) (point))
949 (gnus-article-hide-text (point-min) (point) props)))
950 ;; Then treat the rest of the header lines.
953 (if (search-forward "\n\n" nil t) ; if there's a body
954 (progn (forward-line -1) (point))
956 ;; Then we use the two regular expressions
957 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
958 ;; select which header lines is to remain visible in the
960 (goto-char (point-min))
961 (while (re-search-forward "^[^ \t]*:" nil t)
963 ;; Mark the rank of the header.
965 (point) (1+ (point)) 'message-rank
966 (if (or (and visible (looking-at visible))
968 (not (looking-at ignored))))
969 (gnus-article-header-rank)
972 (message-sort-headers-1)
973 (when (setq beg (text-property-any
974 (point-min) (point-max) 'message-rank (+ 2 max)))
975 ;; We make the unwanted headers invisible.
977 (delete-region beg (point-max))
978 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
979 (gnus-article-hide-text-type beg (point-max) 'headers))
980 ;; Work around XEmacs lossage.
981 (put-text-property (point-min) beg 'invisible nil))))))))
983 (defun article-hide-boring-headers (&optional arg)
984 "Toggle hiding of headers that aren't very interesting.
985 If given a negative prefix, always show; if given a positive prefix,
987 (interactive (gnus-article-hidden-arg))
988 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
989 (not gnus-show-all-headers))
992 (let ((buffer-read-only nil)
993 (list gnus-boring-article-headers)
994 (inhibit-point-motion-hooks t)
996 (nnheader-narrow-to-headers)
998 (setq elem (pop list))
999 (goto-char (point-min))
1001 ;; Hide empty headers.
1003 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
1005 (gnus-article-hide-text-type
1006 (progn (beginning-of-line) (point))
1009 (if (re-search-forward "^[^ \t]" nil t)
1013 ;; Hide boring Newsgroups header.
1014 ((eq elem 'newsgroups)
1015 (when (equal (gnus-fetch-field "newsgroups")
1016 (gnus-group-real-name
1017 (if (boundp 'gnus-newsgroup-name)
1020 (gnus-article-hide-header "newsgroups")))
1021 ((eq elem 'followup-to)
1022 (when (equal (message-fetch-field "followup-to")
1023 (message-fetch-field "newsgroups"))
1024 (gnus-article-hide-header "followup-to")))
1025 ((eq elem 'reply-to)
1026 (let ((from (message-fetch-field "from"))
1027 (reply-to (message-fetch-field "reply-to")))
1032 (nth 1 (mail-extract-address-components from))
1033 (nth 1 (mail-extract-address-components reply-to)))))
1034 (gnus-article-hide-header "reply-to"))))
1036 (let ((date (message-fetch-field "date")))
1038 (< (days-between (current-time-string) date)
1040 (gnus-article-hide-header "date"))))
1042 (let ((to (message-fetch-field "to")))
1043 (when (> (length to) 1024)
1044 (gnus-article-hide-header "to"))))
1047 (goto-char (point-min))
1048 (while (re-search-forward "^to:" nil t)
1049 (setq to-count (1+ to-count)))
1050 (when (> to-count 1)
1051 (while (> to-count 0)
1052 (goto-char (point-min))
1054 (re-search-forward "^to:" nil nil to-count)
1056 (narrow-to-region (point) (point-max))
1057 (gnus-article-hide-header "to"))
1058 (setq to-count (1- to-count)))))))))))))
1060 (defun gnus-article-hide-header (header)
1062 (goto-char (point-min))
1063 (when (re-search-forward (concat "^" header ":") nil t)
1064 (gnus-article-hide-text-type
1065 (progn (beginning-of-line) (point))
1068 (if (re-search-forward "^[^ \t]" nil t)
1073 (defvar gnus-article-normalized-header-length 40
1074 "Length of normalized headers.")
1076 (defun article-normalize-headers ()
1077 "Make all header lines 40 characters long."
1079 (let ((buffer-read-only nil)
1083 (message-narrow-to-head)
1086 ((< (setq column (- (gnus-point-at-eol) (point)))
1087 gnus-article-normalized-header-length)
1089 (insert (make-string
1090 (- gnus-article-normalized-header-length column)
1092 ((> column gnus-article-normalized-header-length)
1093 (gnus-put-text-property
1095 (forward-char gnus-article-normalized-header-length)
1102 (forward-line 1))))))
1104 (defun article-treat-dumbquotes ()
1105 "Translate M******** sm*rtq**t*s into proper text.
1106 Note that this function guesses whether a character is a sm*rtq**t* or
1107 not, so it should only be used interactively."
1109 (article-translate-strings gnus-article-dumbquotes-map))
1111 (defun article-translate-characters (from to)
1112 "Translate all characters in the body of the article according to FROM and TO.
1113 FROM is a string of characters to translate from; to is a string of
1114 characters to translate to."
1116 (when (article-goto-body)
1117 (let ((buffer-read-only nil)
1118 (x (make-string 225 ?x))
1120 (while (< (incf i) (length x))
1123 (while (< i (length from))
1124 (aset x (aref from i) (aref to i))
1126 (translate-region (point) (point-max) x)))))
1128 (defun article-translate-strings (map)
1129 "Translate all string in the body of the article according to MAP.
1130 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1132 (when (article-goto-body)
1133 (let ((buffer-read-only nil)
1135 (while (setq elem (pop map))
1137 (while (search-forward (car elem) nil t)
1138 (replace-match (cadr elem)))))))))
1140 (defun article-treat-overstrike ()
1141 "Translate overstrikes into bold text."
1144 (when (article-goto-body)
1145 (let ((buffer-read-only nil))
1146 (while (search-forward "\b" nil t)
1147 (let ((next (char-after))
1148 (previous (char-after (- (point) 2))))
1149 ;; We do the boldification/underlining by hiding the
1150 ;; overstrikes and putting the proper text property
1154 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1155 (put-text-property (point) (1+ (point)) 'face 'bold))
1157 (gnus-article-hide-text-type
1158 (1- (point)) (1+ (point)) 'overstrike)
1160 (- (point) 2) (1- (point)) 'face 'underline))
1162 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1164 (point) (1+ (point)) 'face 'underline)))))))))
1166 (defun article-fill ()
1167 "Format too long lines."
1170 (let ((buffer-read-only nil))
1174 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
1175 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
1176 (adaptive-fill-mode t))
1178 (and (>= (current-column) (min fill-column (window-width)))
1179 (/= (preceding-char) ?:)
1180 (fill-paragraph nil))
1181 (end-of-line 2))))))
1183 (defun article-remove-cr ()
1184 "Translate CRLF pairs into LF, and then CR into LF.."
1187 (let ((buffer-read-only nil))
1188 (goto-char (point-min))
1189 (while (search-forward "\r$" nil t)
1190 (replace-match "" t t))
1191 (goto-char (point-min))
1192 (while (search-forward "\r" nil t)
1193 (replace-match "\n" t t)))))
1195 (defun article-remove-trailing-blank-lines ()
1196 "Remove all trailing blank lines from the article."
1199 (let ((buffer-read-only nil))
1200 (goto-char (point-max))
1204 (while (and (not (bobp))
1205 (looking-at "^[ \t]*$")
1206 (not (gnus-annotation-in-region-p
1207 (point) (gnus-point-at-eol))))
1212 (defun article-display-x-face (&optional force)
1213 "Look for an X-Face header and display it if present."
1214 (interactive (list 'force))
1216 ;; Delete the old process, if any.
1217 (when (process-status "article-x-face")
1218 (delete-process "article-x-face"))
1219 (let ((inhibit-point-motion-hooks t)
1220 (case-fold-search t)
1223 (nnheader-narrow-to-headers)
1224 (setq from (message-fetch-field "from"))
1225 (goto-char (point-min))
1226 (while (and gnus-article-x-face-command
1229 ;; Check whether this face is censored.
1230 (not gnus-article-x-face-too-ugly)
1231 (and gnus-article-x-face-too-ugly from
1232 (not (string-match gnus-article-x-face-too-ugly
1234 ;; Has to be present.
1235 (re-search-forward "^X-Face: " nil t))
1236 ;; This used to try to do multiple faces (`while' instead of
1237 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1238 ;; work (b) it can crash some versions of Emacs (c) are
1239 ;; multiple faces really something to encourage?
1240 (when (stringp gnus-article-x-face-command)
1242 ;; We now have the area of the buffer where the X-Face is stored.
1245 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1246 ;; We display the face.
1247 (if (symbolp gnus-article-x-face-command)
1248 ;; The command is a lisp function, so we call it.
1249 (if (gnus-functionp gnus-article-x-face-command)
1250 (funcall gnus-article-x-face-command beg end)
1251 (error "%s is not a function" gnus-article-x-face-command))
1252 ;; The command is a string, so we interpret the command
1253 ;; as a, well, command, and fork it off.
1254 (let ((process-connection-type nil))
1255 (process-kill-without-query
1257 "article-x-face" nil shell-file-name shell-command-switch
1258 gnus-article-x-face-command))
1259 (process-send-region "article-x-face" beg end)
1260 (process-send-eof "article-x-face"))))))))))
1262 (defun article-decode-mime-words ()
1263 "Decode all MIME-encoded words in the article."
1266 (set-buffer gnus-article-buffer)
1267 (let ((inhibit-point-motion-hooks t)
1269 (mail-parse-charset gnus-newsgroup-charset))
1270 (mail-decode-encoded-word-region (point-min) (point-max)))))
1272 (defun article-decode-charset (&optional prompt)
1273 "Decode charset-encoded text in the article.
1274 If PROMPT (the prefix), prompt for a coding system to use."
1278 (message-narrow-to-head)
1279 (let* ((inhibit-point-motion-hooks t)
1280 (case-fold-search t)
1281 (ct (message-fetch-field "Content-Type" t))
1282 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1283 (ctl (and ct (condition-case ()
1284 (mail-header-parse-content-type ct)
1288 (mm-read-coding-system "Charset to decode: "))
1290 (mail-content-type-get ctl 'charset))))
1291 (mail-parse-charset gnus-newsgroup-charset)
1293 (goto-char (point-max))
1296 (narrow-to-region (point) (point-max))
1297 (when (and (or (not ctl)
1298 (equal (car ctl) "text/plain"))
1301 charset (and cte (intern (downcase
1302 (gnus-strip-whitespace cte))))
1305 (defun article-decode-encoded-words ()
1306 "Remove encoded-word encoding from headers."
1307 (let ((inhibit-point-motion-hooks t)
1308 (mail-parse-charset gnus-newsgroup-charset)
1311 (message-narrow-to-head)
1312 (funcall gnus-decode-header-function (point-min) (point-max)))))
1314 (defun article-de-quoted-unreadable (&optional force)
1315 "Translate a quoted-printable-encoded article.
1316 If FORCE, decode the article whether it is marked as quoted-printable
1318 (interactive (list 'force))
1320 (let ((buffer-read-only nil)
1321 (type (gnus-fetch-field "content-transfer-encoding"))
1322 (charset gnus-newsgroup-charset))
1324 (and type (string-match "quoted-printable" (downcase type))))
1327 (narrow-to-region (point) (point-max))
1328 (quoted-printable-decode-region (point-min) (point-max))
1330 (mm-decode-body charset)))))))
1332 (defun article-hide-pgp (&optional arg)
1333 "Toggle hiding of any PGP headers and signatures in the current article.
1334 If given a negative prefix, always show; if given a positive prefix,
1336 (interactive (gnus-article-hidden-arg))
1337 (unless (gnus-article-check-hidden-text 'pgp arg)
1339 (let ((inhibit-point-motion-hooks t)
1340 buffer-read-only beg end)
1342 (goto-char (point-min))
1343 ;; Hide the "header".
1344 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1345 (delete-region (1+ (match-beginning 0)) (match-end 0))
1346 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1347 (when (looking-at "Hash:.*$")
1348 (delete-region (point) (1+ (gnus-point-at-eol))))
1350 ;; Hide the actual signature.
1351 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1352 (setq end (1+ (match-beginning 0)))
1355 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1357 ;; Perhaps we shouldn't hide to the end of the buffer
1358 ;; if there is no end to the signature?
1360 ;; Hide "- " PGP quotation markers.
1362 (narrow-to-region beg end)
1363 (goto-char (point-min))
1364 (while (re-search-forward "^- " nil t)
1366 (match-beginning 0) (match-end 0)))
1368 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1370 (defun article-hide-pem (&optional arg)
1371 "Toggle hiding of any PEM headers and signatures in the current article.
1372 If given a negative prefix, always show; if given a positive prefix,
1374 (interactive (gnus-article-hidden-arg))
1375 (unless (gnus-article-check-hidden-text 'pem arg)
1377 (let (buffer-read-only end)
1379 (goto-char (point-min))
1380 ;; hide the horrendously ugly "header".
1381 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1384 (setq end (1+ (match-beginning 0)))
1385 (gnus-article-hide-text-type
1387 (if (search-forward "\n\n" nil t)
1391 ;; hide the trailer as well
1392 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1395 (gnus-article-hide-text-type
1396 (match-beginning 0) (match-end 0) 'pem))))))
1398 (defun article-hide-signature (&optional arg)
1399 "Hide the signature in the current article.
1400 If given a negative prefix, always show; if given a positive prefix,
1402 (interactive (gnus-article-hidden-arg))
1403 (unless (gnus-article-check-hidden-text 'signature arg)
1406 (let ((buffer-read-only nil))
1407 (when (gnus-article-narrow-to-signature)
1408 (gnus-article-hide-text-type
1409 (point-min) (point-max) 'signature)))))))
1411 (defun article-strip-leading-blank-lines ()
1412 "Remove all blank lines from the beginning of the article."
1415 (let ((inhibit-point-motion-hooks t)
1417 (when (article-goto-body)
1418 (while (and (not (eobp))
1419 (looking-at "[ \t]*$"))
1420 (gnus-delete-line))))))
1422 (defun article-goto-body ()
1423 "Place point at the start of the body."
1424 (goto-char (point-min))
1426 (article-goto-body-goes-to-point-min-p
1428 ((search-forward "\n\n" nil t)
1431 (goto-char (point-max))
1434 (defun article-strip-multiple-blank-lines ()
1435 "Replace consecutive blank lines with one empty line."
1438 (let ((inhibit-point-motion-hooks t)
1440 ;; First make all blank lines empty.
1442 (while (re-search-forward "^[ \t]+$" nil t)
1443 (unless (gnus-annotation-in-region-p
1444 (match-beginning 0) (match-end 0))
1445 (replace-match "" nil t)))
1446 ;; Then replace multiple empty lines with a single empty line.
1448 (while (re-search-forward "\n\n\n+" nil t)
1449 (unless (gnus-annotation-in-region-p
1450 (match-beginning 0) (match-end 0))
1451 (replace-match "\n\n" t t))))))
1453 (defun article-strip-leading-space ()
1454 "Remove all white space from the beginning of the lines in the article."
1457 (let ((inhibit-point-motion-hooks t)
1460 (while (re-search-forward "^[ \t]+" nil t)
1461 (replace-match "" t t)))))
1463 (defun article-strip-trailing-space ()
1464 "Remove all white space from the end of the lines in the article."
1467 (let ((inhibit-point-motion-hooks t)
1470 (while (re-search-forward "[ \t]+$" nil t)
1471 (replace-match "" t t)))))
1473 (defun article-strip-blank-lines ()
1474 "Strip leading, trailing and multiple blank lines."
1476 (article-strip-leading-blank-lines)
1477 (article-remove-trailing-blank-lines)
1478 (article-strip-multiple-blank-lines))
1480 (defun article-strip-all-blank-lines ()
1481 "Strip all blank lines."
1484 (let ((inhibit-point-motion-hooks t)
1487 (while (re-search-forward "^[ \t]*\n" nil t)
1488 (replace-match "" t t)))))
1490 (defun gnus-article-narrow-to-signature ()
1491 "Narrow to the signature; return t if a signature is found, else nil."
1493 (let ((inhibit-point-motion-hooks t))
1494 (when (gnus-article-search-signature)
1496 ;; Check whether we have some limits to what we consider
1497 ;; to be a signature.
1498 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1499 (list gnus-signature-limit)))
1501 (while (setq limit (pop limits))
1502 (if (or (and (integerp limit)
1503 (< (- (point-max) (point)) limit))
1505 (< (count-lines (point) (point-max)) limit))
1506 (and (gnus-functionp limit)
1508 (and (stringp limit)
1509 (not (re-search-forward limit nil t))))
1510 () ; This limit did not succeed.
1514 (narrow-to-region (point) (point-max))
1517 (defun gnus-article-search-signature ()
1518 "Search the current buffer for the signature separator.
1519 Put point at the beginning of the signature separator."
1520 (let ((cur (point)))
1521 (goto-char (point-max))
1522 (if (if (stringp gnus-signature-separator)
1523 (re-search-backward gnus-signature-separator nil t)
1524 (let ((seps gnus-signature-separator))
1526 (not (re-search-backward (car seps) nil t)))
1534 (autoload 'w3-display "w3-parse")
1535 (autoload 'w3-do-setup "w3" "" t)
1536 (autoload 'w3-region "w3-display" "" t))
1538 (defun gnus-article-treat-html ()
1541 (let ((cbuf (current-buffer)))
1542 (set-buffer gnus-article-buffer)
1543 (let (buf buffer-read-only b e)
1545 (goto-char (point-min))
1547 (if (search-forward "\n\n" nil t)
1550 (setq e (point-max)))
1552 (insert-buffer-substring gnus-article-buffer b e)
1554 (save-window-excursion
1555 (w3-region (point-min) (point-max))
1556 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1558 (delete-region (point-min) (point-max))
1561 (goto-char (point-min))
1562 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1563 (set-buffer cbuf))))
1565 (defun gnus-article-hidden-arg ()
1566 "Return the current prefix arg as a number, or 0 if no prefix."
1567 (list (if current-prefix-arg
1568 (prefix-numeric-value current-prefix-arg)
1571 (defun gnus-article-check-hidden-text (type arg)
1572 "Return nil if hiding is necessary.
1573 Arg can be nil or a number. Nil and positive means hide, negative
1574 means show, 0 means toggle."
1578 (let ((hide (gnus-article-hidden-text-p type)))
1584 (gnus-article-show-hidden-text type))
1586 (if (eq hide 'hidden)
1587 (gnus-article-show-hidden-text type)
1590 (defun gnus-article-hidden-text-p (type)
1591 "Say whether the current buffer contains hidden text of type TYPE."
1592 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1594 (not (get-text-property pos 'invisible)))
1596 (text-property-any (1+ pos) (point-max) 'article-type type)))
1601 (defun gnus-article-show-hidden-text (type &optional hide)
1602 "Show all hidden text of type TYPE.
1603 If HIDE, hide the text instead."
1605 (let ((buffer-read-only nil)
1606 (inhibit-point-motion-hooks t)
1609 (while (setq beg (text-property-any end (point-max) 'article-type type))
1612 (text-property-not-all beg (point-max) 'article-type type)
1615 (gnus-article-hide-text beg end gnus-hidden-properties)
1616 (gnus-article-unhide-text beg end))
1620 (defconst article-time-units
1621 `((year . ,(* 365.25 24 60 60))
1622 (week . ,(* 7 24 60 60))
1623 (day . ,(* 24 60 60))
1627 "Mapping from time units to seconds.")
1629 (defun article-date-ut (&optional type highlight header)
1630 "Convert DATE date to universal time in the current article.
1631 If TYPE is `local', convert to local time; if it is `lapsed', output
1632 how much time has lapsed since DATE."
1633 (interactive (list 'ut t))
1634 (let* ((header (or header
1635 (mail-header-date (save-excursion
1636 (set-buffer gnus-summary-buffer)
1637 gnus-current-headers))
1638 (message-fetch-field "date")
1640 (date (if (vectorp header) (mail-header-date header)
1642 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1643 (inhibit-point-motion-hooks t)
1644 bface eface newline)
1645 (when (and date (not (string= date "")))
1648 (nnheader-narrow-to-headers)
1649 (let ((buffer-read-only nil))
1650 ;; Delete any old Date headers.
1651 (if (re-search-forward date-regexp nil t)
1653 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1654 eface (get-text-property (1- (gnus-point-at-eol))
1656 (delete-region (progn (beginning-of-line) (point))
1657 (progn (end-of-line) (point)))
1658 (beginning-of-line))
1659 (goto-char (point-max))
1661 (insert (article-make-date-line date type))
1664 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1665 (put-text-property (match-beginning 1) (1+ (match-end 1))
1667 (put-text-property (match-beginning 2) (match-end 2)
1671 (insert "\n"))))))))
1673 (defun article-make-date-line (date type)
1674 "Return a DATE line of TYPE."
1675 (let ((time (condition-case ()
1679 ;; Convert to the local timezone. We have to slap a
1680 ;; `condition-case' round the calls to the timezone
1681 ;; functions since they aren't particularly resistant to
1684 (let ((tz (car (current-time-zone))))
1685 (format "Date: %s %s%04d" (current-time-string time)
1686 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1687 ;; Convert to Universal Time.
1690 (current-time-string
1691 (let* ((e (parse-time-string date))
1692 (tm (apply 'encode-time e))
1694 (ls (- (cadr tm) (car (current-time-zone)))))
1695 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1696 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1699 ;; Get the original date from the article.
1700 ((eq type 'original)
1701 (concat "Date: " (if (string-match "\n+$" date)
1702 (substring date 0 (match-beginning 0))
1704 ;; Let the user define the format.
1706 (if (gnus-functionp gnus-article-time-format)
1707 (funcall gnus-article-time-format time)
1710 (format-time-string gnus-article-time-format time))))
1715 (format-time-string "%Y%m%dT%H%M%S" time)))
1716 ;; Do an X-Sent lapsed format.
1718 ;; If the date is seriously mangled, the timezone functions are
1719 ;; liable to bug out, so we ignore all errors.
1720 (let* ((now (current-time))
1721 (real-time (subtract-time now time))
1722 (real-sec (and real-time
1723 (+ (* (float (car real-time)) 65536)
1725 (sec (and real-time (abs real-sec)))
1735 ;; This is a bit convoluted, but basically we go
1736 ;; through the time units for years, weeks, etc,
1737 ;; and divide things to see whether that results
1738 ;; in positive answers.
1741 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1742 ;; The (remaining) seconds are too few to
1743 ;; be divided into this time unit.
1745 ;; It's big enough, so we output it.
1746 (setq sec (- sec (* num (cdr unit))))
1748 (concat (if prev ", " "") (int-to-string
1750 " " (symbol-name (car unit))
1751 (if (> num 1) "s" ""))
1753 article-time-units "")
1754 ;; If dates are odd, then it might appear like the
1755 ;; article was sent in the future.
1758 " in the future"))))))
1760 (error "Unknown conversion type: %s" type)))))
1762 (defun article-date-local (&optional highlight)
1763 "Convert the current article date to the local timezone."
1764 (interactive (list t))
1765 (article-date-ut 'local highlight))
1767 (defun article-date-original (&optional highlight)
1768 "Convert the current article date to what it was originally.
1769 This is only useful if you have used some other date conversion
1770 function and want to see what the date was before converting."
1771 (interactive (list t))
1772 (article-date-ut 'original highlight))
1774 (defun article-date-lapsed (&optional highlight)
1775 "Convert the current article date to time lapsed since it was sent."
1776 (interactive (list t))
1777 (article-date-ut 'lapsed highlight))
1779 (defun article-update-date-lapsed ()
1780 "Function to be run from a timer to update the lapsed time line."
1781 (let (deactivate-mark)
1786 (set-buffer (window-buffer w))
1787 (when (eq major-mode 'gnus-article-mode)
1788 (goto-char (point-min))
1789 (when (re-search-forward "^X-Sent:" nil t)
1790 (article-date-lapsed t))))
1793 (defun gnus-start-date-timer (&optional n)
1794 "Start a timer to update the X-Sent header in the article buffers.
1795 The numerical prefix says how frequently (in seconds) the function
1800 (gnus-stop-date-timer)
1801 (setq article-lapsed-timer
1802 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1804 (defun gnus-stop-date-timer ()
1805 "Stop the X-Sent timer."
1807 (when article-lapsed-timer
1808 (nnheader-cancel-timer article-lapsed-timer)
1809 (setq article-lapsed-timer nil)))
1811 (defun article-date-user (&optional highlight)
1812 "Convert the current article date to the user-defined format.
1813 This format is defined by the `gnus-article-time-format' variable."
1814 (interactive (list t))
1815 (article-date-ut 'user highlight))
1817 (defun article-date-iso8601 (&optional highlight)
1818 "Convert the current article date to ISO8601."
1819 (interactive (list t))
1820 (article-date-ut 'iso8601 highlight))
1822 (defun article-show-all ()
1823 "Show all hidden text in the article buffer."
1826 (let ((buffer-read-only nil))
1827 (gnus-article-unhide-text (point-min) (point-max)))))
1829 (defun article-emphasize (&optional arg)
1830 "Emphasize text according to `gnus-emphasis-alist'."
1831 (interactive (gnus-article-hidden-arg))
1832 (unless (gnus-article-check-hidden-text 'emphasis arg)
1834 (let ((alist gnus-emphasis-alist)
1835 (buffer-read-only nil)
1836 (props (append '(article-type emphasis)
1837 gnus-hidden-properties))
1838 regexp elem beg invisible visible face)
1841 (while (setq elem (pop alist))
1843 (setq regexp (car elem)
1844 invisible (nth 1 elem)
1845 visible (nth 2 elem)
1847 (while (re-search-forward regexp nil t)
1848 (when (and (match-beginning visible) (match-beginning invisible))
1849 (gnus-article-hide-text
1850 (match-beginning invisible) (match-end invisible) props)
1851 (gnus-article-unhide-text-type
1852 (match-beginning visible) (match-end visible) 'emphasis)
1853 (gnus-put-text-property-excluding-newlines
1854 (match-beginning visible) (match-end visible) 'face face)
1855 (goto-char (match-end invisible)))))))))
1857 (defvar gnus-summary-article-menu)
1858 (defvar gnus-summary-post-menu)
1860 ;;; Saving functions.
1862 (defun gnus-article-save (save-buffer file &optional num)
1863 "Save the currently selected article."
1864 (unless gnus-save-all-headers
1865 ;; Remove headers according to `gnus-saved-headers'.
1866 (let ((gnus-visible-headers
1867 (or gnus-saved-headers gnus-visible-headers))
1868 (gnus-article-buffer save-buffer))
1870 (set-buffer save-buffer)
1871 (article-hide-headers 1 t))))
1872 (save-window-excursion
1873 (if (not gnus-default-article-saver)
1874 (error "No default saver is defined")
1875 ;; !!! Magic! The saving functions all save
1876 ;; `gnus-save-article-buffer' (or so they think), but we
1877 ;; bind that variable to our save-buffer.
1878 (set-buffer gnus-article-buffer)
1879 (let* ((gnus-save-article-buffer save-buffer)
1882 ((not gnus-prompt-before-saving) 'default)
1883 ((eq gnus-prompt-before-saving 'always) nil)
1885 (gnus-number-of-articles-to-be-saved
1886 (when (eq gnus-prompt-before-saving t)
1888 (set-buffer gnus-article-current-summary)
1889 (funcall gnus-default-article-saver filename)))))
1891 (defun gnus-read-save-file-name (prompt &optional filename
1892 function group headers variable)
1894 (funcall function group headers (symbol-value variable)))
1899 ((eq filename 'default)
1905 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1908 (if (and gnus-number-of-articles-to-be-saved
1909 (> gnus-number-of-articles-to-be-saved 1))
1910 (format "these %d articles"
1911 gnus-number-of-articles-to-be-saved)
1914 ;; Let the split methods have their say.
1916 ;; No split name was found.
1919 (concat prompt " (default "
1920 (file-name-nondirectory default-name) ") ")
1921 (file-name-directory default-name)
1923 ;; A single group name is returned.
1924 ((stringp split-name)
1926 (funcall function split-name headers
1927 (symbol-value variable)))
1929 (concat prompt " (default "
1930 (file-name-nondirectory default-name) ") ")
1931 (file-name-directory default-name)
1933 ;; A single split name was found
1934 ((= 1 (length split-name))
1935 (let* ((name (expand-file-name
1936 (car split-name) gnus-article-save-directory))
1937 (dir (cond ((file-directory-p name)
1938 (file-name-as-directory name))
1939 ((file-exists-p name) name)
1940 (t gnus-article-save-directory))))
1942 (concat prompt " (default " name ") ")
1944 ;; A list of splits was found.
1946 (setq split-name (nreverse split-name))
1948 (let ((file-name-history
1949 (nconc split-name file-name-history)))
1953 (concat prompt " (`M-p' for defaults) ")
1954 gnus-article-save-directory
1956 gnus-article-save-directory)))
1957 (car (push result file-name-history)))))))
1958 ;; Create the directory.
1959 (gnus-make-directory (file-name-directory file))
1960 ;; If we have read a directory, we append the default file name.
1961 (when (file-directory-p file)
1962 (setq file (concat (file-name-as-directory file)
1963 (file-name-nondirectory default-name))))
1964 ;; Possibly translate some characters.
1965 (nnheader-translate-file-chars file)))))
1966 (gnus-make-directory (file-name-directory result))
1967 (set variable result)))
1969 (defun gnus-article-archive-name (group)
1970 "Return the first instance of an \"Archive-name\" in the current buffer."
1971 (let ((case-fold-search t))
1972 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1973 (nnheader-concat gnus-article-save-directory
1974 (match-string 1)))))
1976 (defun gnus-article-nndoc-name (group)
1977 "If GROUP is an nndoc group, return the name of the parent group."
1978 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1979 (gnus-group-get-parameter group 'save-article-group)))
1981 (defun gnus-summary-save-in-rmail (&optional filename)
1982 "Append this article to Rmail file.
1983 Optional argument FILENAME specifies file name.
1984 Directory to save to is default to `gnus-article-save-directory'."
1985 (setq filename (gnus-read-save-file-name
1986 "Save %s in rmail file:" filename
1987 gnus-rmail-save-name gnus-newsgroup-name
1988 gnus-current-headers 'gnus-newsgroup-last-rmail))
1989 (gnus-eval-in-buffer-window gnus-save-article-buffer
1993 (gnus-output-to-rmail filename))))
1996 (defun gnus-summary-save-in-mail (&optional filename)
1997 "Append this article to Unix mail file.
1998 Optional argument FILENAME specifies file name.
1999 Directory to save to is default to `gnus-article-save-directory'."
2000 (setq filename (gnus-read-save-file-name
2001 "Save %s in Unix mail file:" filename
2002 gnus-mail-save-name gnus-newsgroup-name
2003 gnus-current-headers 'gnus-newsgroup-last-mail))
2004 (gnus-eval-in-buffer-window gnus-save-article-buffer
2008 (if (and (file-readable-p filename)
2009 (mail-file-babyl-p filename))
2010 (rmail-output-to-rmail-file filename t)
2011 (gnus-output-to-mail filename)))))
2014 (defun gnus-summary-save-in-file (&optional filename overwrite)
2015 "Append this article to file.
2016 Optional argument FILENAME specifies file name.
2017 Directory to save to is default to `gnus-article-save-directory'."
2018 (setq filename (gnus-read-save-file-name
2019 "Save %s in file:" filename
2020 gnus-file-save-name gnus-newsgroup-name
2021 gnus-current-headers 'gnus-newsgroup-last-file))
2022 (gnus-eval-in-buffer-window gnus-save-article-buffer
2026 (when (and overwrite
2027 (file-exists-p filename))
2028 (delete-file filename))
2029 (gnus-output-to-file filename))))
2032 (defun gnus-summary-write-to-file (&optional filename)
2033 "Write this article to a file.
2034 Optional argument FILENAME specifies file name.
2035 The directory to save in defaults to `gnus-article-save-directory'."
2036 (gnus-summary-save-in-file nil t))
2038 (defun gnus-summary-save-body-in-file (&optional filename)
2039 "Append this article body to a file.
2040 Optional argument FILENAME specifies file name.
2041 The directory to save in defaults to `gnus-article-save-directory'."
2042 (setq filename (gnus-read-save-file-name
2043 "Save %s body in file:" filename
2044 gnus-file-save-name gnus-newsgroup-name
2045 gnus-current-headers 'gnus-newsgroup-last-file))
2046 (gnus-eval-in-buffer-window gnus-save-article-buffer
2050 (when (article-goto-body)
2051 (narrow-to-region (point) (point-max)))
2052 (gnus-output-to-file filename))))
2055 (defun gnus-summary-save-in-pipe (&optional command)
2056 "Pipe this article to subprocess."
2058 (cond ((and (eq command 'default)
2059 gnus-last-shell-command)
2060 gnus-last-shell-command)
2064 "Shell command on %s: "
2065 (if (and gnus-number-of-articles-to-be-saved
2066 (> gnus-number-of-articles-to-be-saved 1))
2067 (format "these %d articles"
2068 gnus-number-of-articles-to-be-saved)
2070 gnus-last-shell-command))))
2071 (when (string-equal command "")
2072 (setq command gnus-last-shell-command))
2073 (gnus-eval-in-buffer-window gnus-article-buffer
2076 (shell-command-on-region (point-min) (point-max) command nil)))
2077 (setq gnus-last-shell-command command))
2079 ;;; Article file names when saving.
2081 (defun gnus-capitalize-newsgroup (newsgroup)
2082 "Capitalize NEWSGROUP name."
2083 (when (not (zerop (length newsgroup)))
2084 (concat (char-to-string (upcase (aref newsgroup 0)))
2085 (substring newsgroup 1))))
2087 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2088 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2089 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2090 Otherwise, it is like ~/News/news/group/num."
2093 (concat (if (gnus-use-long-file-name 'not-save)
2094 (gnus-capitalize-newsgroup newsgroup)
2095 (gnus-newsgroup-directory-form newsgroup))
2096 "/" (int-to-string (mail-header-number headers)))
2097 gnus-article-save-directory)))
2099 (string-equal (file-name-directory default)
2100 (file-name-directory last-file))
2101 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2103 (or last-file default))))
2105 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2106 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2107 If variable `gnus-use-long-file-name' is non-nil, it is
2108 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2111 (concat (if (gnus-use-long-file-name 'not-save)
2113 (gnus-newsgroup-directory-form newsgroup))
2114 "/" (int-to-string (mail-header-number headers)))
2115 gnus-article-save-directory)))
2117 (string-equal (file-name-directory default)
2118 (file-name-directory last-file))
2119 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2121 (or last-file default))))
2123 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2124 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2125 If variable `gnus-use-long-file-name' is non-nil, it is
2126 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2129 (if (gnus-use-long-file-name 'not-save)
2130 (gnus-capitalize-newsgroup newsgroup)
2131 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2132 gnus-article-save-directory)))
2134 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2135 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2136 If variable `gnus-use-long-file-name' is non-nil, it is
2137 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2140 (if (gnus-use-long-file-name 'not-save)
2142 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2143 gnus-article-save-directory)))
2150 (setq afunc (car func)
2153 gfunc (intern (format "gnus-%s" func))))
2155 (if (not (fboundp afunc))
2157 `(lambda (&optional interactive &rest args)
2158 ,(documentation afunc t)
2159 (interactive (list t))
2161 (set-buffer gnus-article-buffer)
2163 (call-interactively ',afunc)
2164 (apply ',afunc args))))))))
2165 '(article-hide-headers
2166 article-hide-boring-headers
2167 article-treat-overstrike
2168 (article-fill . gnus-article-word-wrap)
2170 article-display-x-face
2171 article-de-quoted-unreadable
2172 article-mime-decode-quoted-printable
2175 article-hide-signature
2176 article-remove-trailing-blank-lines
2177 article-strip-leading-blank-lines
2178 article-strip-multiple-blank-lines
2179 article-strip-leading-space
2180 article-strip-trailing-space
2181 article-strip-blank-lines
2182 article-strip-all-blank-lines
2184 article-date-iso8601
2185 article-date-original
2187 article-decode-mime-words
2188 article-decode-charset
2189 article-decode-encoded-words
2193 article-treat-dumbquotes
2194 article-normalize-headers
2195 (article-show-all . gnus-article-show-all-headers))))
2198 ;;; Gnus article mode
2201 (put 'gnus-article-mode 'mode-class 'special)
2203 (set-keymap-parent gnus-article-mode-map widget-keymap)
2205 (gnus-define-keys gnus-article-mode-map
2206 " " gnus-article-goto-next-page
2207 "\177" gnus-article-goto-prev-page
2208 [delete] gnus-article-goto-prev-page
2209 [backspace] gnus-article-goto-prev-page
2210 "\C-c^" gnus-article-refer-article
2211 "h" gnus-article-show-summary
2212 "s" gnus-article-show-summary
2213 "\C-c\C-m" gnus-article-mail
2214 "?" gnus-article-describe-briefly
2215 "e" gnus-article-edit
2216 "<" beginning-of-buffer
2218 "\C-c\C-i" gnus-info-find-node
2221 "\C-d" gnus-article-read-summary-keys
2222 "\M-*" gnus-article-read-summary-keys
2223 "\M-#" gnus-article-read-summary-keys
2224 "\M-^" gnus-article-read-summary-keys
2225 "\M-g" gnus-article-read-summary-keys)
2227 (substitute-key-definition
2228 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2230 (defun gnus-article-make-menu-bar ()
2231 (gnus-turn-off-edit-menu 'article)
2232 (unless (boundp 'gnus-article-article-menu)
2234 gnus-article-article-menu gnus-article-mode-map ""
2236 ["Scroll forwards" gnus-article-goto-next-page t]
2237 ["Scroll backwards" gnus-article-goto-prev-page t]
2238 ["Show summary" gnus-article-show-summary t]
2239 ["Fetch Message-ID at point" gnus-article-refer-article t]
2240 ["Mail to address at point" gnus-article-mail t]
2241 ["Send a bug report" gnus-bug t]))
2244 gnus-article-treatment-menu gnus-article-mode-map ""
2246 ["Hide headers" gnus-article-hide-headers t]
2247 ["Hide signature" gnus-article-hide-signature t]
2248 ["Hide citation" gnus-article-hide-citation t]
2249 ["Treat overstrike" gnus-article-treat-overstrike t]
2250 ["Remove carriage return" gnus-article-remove-cr t]
2251 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2253 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2255 (when (boundp 'gnus-summary-post-menu)
2256 (define-key gnus-article-mode-map [menu-bar post]
2257 (cons "Post" gnus-summary-post-menu)))
2259 (gnus-run-hooks 'gnus-article-menu-hook)))
2261 (defun gnus-article-mode ()
2262 "Major mode for displaying an article.
2264 All normal editing commands are switched off.
2266 The following commands are available in addition to all summary mode
2268 \\<gnus-article-mode-map>
2269 \\[gnus-article-next-page]\t Scroll the article one page forwards
2270 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2271 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2272 \\[gnus-article-show-summary]\t Display the summary buffer
2273 \\[gnus-article-mail]\t Send a reply to the address near point
2274 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2275 \\[gnus-info-find-node]\t Go to the Gnus info node"
2277 (when (gnus-visual-p 'article-menu 'menu)
2278 (gnus-article-make-menu-bar))
2279 (gnus-simplify-mode-line)
2280 (setq mode-name "Article")
2281 (setq major-mode 'gnus-article-mode)
2282 (make-local-variable 'minor-mode-alist)
2283 (use-local-map gnus-article-mode-map)
2284 (gnus-update-format-specifications nil 'article-mode)
2285 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2286 (make-local-variable 'gnus-page-broken)
2287 (make-local-variable 'gnus-button-marker-list)
2288 (make-local-variable 'gnus-article-current-summary)
2289 (make-local-variable 'gnus-article-mime-handles)
2290 (make-local-variable 'gnus-article-decoded-p)
2291 (make-local-variable 'gnus-article-mime-handle-alist)
2292 (gnus-set-default-directory)
2293 (buffer-disable-undo)
2294 (setq buffer-read-only t)
2295 (set-syntax-table gnus-article-mode-syntax-table)
2296 (mm-enable-multibyte)
2297 (gnus-run-hooks 'gnus-article-mode-hook))
2299 (defun gnus-article-setup-buffer ()
2300 "Initialize the article buffer."
2301 (let* ((name (if gnus-single-article-buffer "*Article*"
2302 (concat "*Article " gnus-newsgroup-name "*")))
2304 (progn (string-match "\\*Article" name)
2305 (concat " *Original Article"
2306 (substring name (match-end 0))))))
2307 (setq gnus-article-buffer name)
2308 (setq gnus-original-article-buffer original)
2309 (setq gnus-article-mime-handle-alist nil)
2310 ;; This might be a variable local to the summary buffer.
2311 (unless gnus-single-article-buffer
2313 (set-buffer gnus-summary-buffer)
2314 (setq gnus-article-buffer name)
2315 (setq gnus-original-article-buffer original)
2316 (gnus-set-global-variables)))
2317 ;; Init original article buffer.
2319 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2320 (mm-enable-multibyte)
2321 (setq major-mode 'gnus-original-article-mode)
2322 (make-local-variable 'gnus-original-article))
2323 (if (get-buffer name)
2326 (buffer-disable-undo)
2327 (setq buffer-read-only t)
2328 (unless (eq major-mode 'gnus-article-mode)
2329 (gnus-article-mode))
2332 (set-buffer (gnus-get-buffer-create name))
2334 (make-local-variable 'gnus-summary-buffer)
2335 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2336 (current-buffer)))))
2338 ;; Set article window start at LINE, where LINE is the number of lines
2339 ;; from the head of the article.
2340 (defun gnus-article-set-window-start (&optional line)
2342 (get-buffer-window gnus-article-buffer t)
2344 (set-buffer gnus-article-buffer)
2345 (goto-char (point-min))
2348 (gnus-message 6 "Moved to bookmark")
2349 (search-forward "\n\n" nil t)
2353 (defun gnus-article-prepare (article &optional all-headers header)
2354 "Prepare ARTICLE in article mode buffer.
2355 ARTICLE should either be an article number or a Message-ID.
2356 If ARTICLE is an id, HEADER should be the article headers.
2357 If ALL-HEADERS is non-nil, no headers are hidden."
2359 ;; Make sure we start in a summary buffer.
2360 (unless (eq major-mode 'gnus-summary-mode)
2361 (set-buffer gnus-summary-buffer))
2362 (setq gnus-summary-buffer (current-buffer))
2363 (let* ((gnus-article (if header (mail-header-number header) article))
2364 (summary-buffer (current-buffer))
2365 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2366 (group gnus-newsgroup-name)
2369 (gnus-article-setup-buffer)
2370 (set-buffer gnus-article-buffer)
2371 ;; Deactivate active regions.
2372 (when (and (boundp 'transient-mark-mode)
2373 transient-mark-mode)
2374 (setq mark-active nil))
2375 (if (not (setq result (let ((buffer-read-only nil))
2376 (gnus-request-article-this-buffer
2378 ;; There is no such article.
2380 (when (and (numberp article)
2381 (not (memq article gnus-newsgroup-sparse)))
2382 (setq gnus-article-current
2383 (cons gnus-newsgroup-name article))
2384 (set-buffer gnus-summary-buffer)
2385 (setq gnus-current-article article)
2386 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2388 (gnus-summary-set-agent-mark article)
2389 (message "Message marked for downloading"))
2390 (gnus-summary-mark-article article gnus-canceled-mark)
2391 (unless (memq article gnus-newsgroup-sparse)
2393 "No such article (may have expired or been canceled)")))))
2394 (if (or (eq result 'pseudo)
2395 (eq result 'nneething))
2398 (set-buffer summary-buffer)
2399 (push article gnus-newsgroup-history)
2400 (setq gnus-last-article gnus-current-article
2401 gnus-current-article 0
2402 gnus-current-headers nil
2403 gnus-article-current nil)
2404 (if (eq result 'nneething)
2405 (gnus-configure-windows 'summary)
2406 (gnus-configure-windows 'article))
2407 (gnus-set-global-variables))
2408 (let ((gnus-article-mime-handle-alist-1
2409 gnus-article-mime-handle-alist))
2410 (gnus-set-mode-line 'article)))
2411 ;; The result from the `request' was an actual article -
2412 ;; or at least some text that is now displayed in the
2414 (when (and (numberp article)
2415 (not (eq article gnus-current-article)))
2416 ;; Seems like a new article has been selected.
2417 ;; `gnus-current-article' must be an article number.
2419 (set-buffer summary-buffer)
2420 (push article gnus-newsgroup-history)
2421 (setq gnus-last-article gnus-current-article
2422 gnus-current-article article
2423 gnus-current-headers
2424 (gnus-summary-article-header gnus-current-article)
2425 gnus-article-current
2426 (cons gnus-newsgroup-name gnus-current-article))
2427 (unless (vectorp gnus-current-headers)
2428 (setq gnus-current-headers nil))
2429 (gnus-summary-goto-subject gnus-current-article)
2430 (when (gnus-summary-show-thread)
2431 ;; If the summary buffer really was folded, the
2432 ;; previous goto may not actually have gone to
2433 ;; the right article, but the thread root instead.
2435 (gnus-summary-goto-subject gnus-current-article))
2436 (gnus-run-hooks 'gnus-mark-article-hook)
2437 (gnus-set-mode-line 'summary)
2438 (when (gnus-visual-p 'article-highlight 'highlight)
2439 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2440 ;; Set the global newsgroup variables here.
2441 ;; Suggested by Jim Sisolak
2442 ;; <sisolak@trans4.neep.wisc.edu>.
2443 (gnus-set-global-variables)
2444 (setq gnus-have-all-headers
2445 (or all-headers gnus-show-all-headers))))
2446 (when (or (numberp article)
2448 (gnus-article-prepare-display)
2450 (goto-char (point-min))
2451 (setq gnus-page-broken
2452 (when gnus-break-pages
2453 (gnus-narrow-to-page)
2455 (let ((gnus-article-mime-handle-alist-1
2456 gnus-article-mime-handle-alist))
2457 (gnus-set-mode-line 'article))
2458 (gnus-configure-windows 'article)
2460 (set-window-point (get-buffer-window (current-buffer)) (point))
2464 (defun gnus-article-prepare-display ()
2465 "Make the current buffer look like a nice article."
2466 ;; Hooks for getting information from the article.
2467 ;; This hook must be called before being narrowed.
2468 (let ((gnus-article-buffer (current-buffer))
2470 (unless (eq major-mode 'gnus-article-mode)
2471 (gnus-article-mode))
2472 (setq buffer-read-only nil)
2473 (gnus-run-hooks 'gnus-tmp-internal-hook)
2474 (gnus-run-hooks 'gnus-article-prepare-hook)
2475 (when gnus-display-mime-function
2476 (funcall gnus-display-mime-function))))
2479 ;;; Gnus MIME viewing functions
2482 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2483 "The following specs can be used:
2485 %T MIME type, along with additional info
2486 %n The `name' parameter
2487 %d The description, if any
2488 %l The length of the encoded part
2489 %p The part identifier number
2490 %e Dots if the part isn't displayed")
2492 (defvar gnus-mime-button-line-format-alist
2493 '((?t gnus-tmp-type ?s)
2494 (?T gnus-tmp-type-long ?s)
2495 (?n gnus-tmp-name ?s)
2496 (?d gnus-tmp-description ?s)
2498 (?l gnus-tmp-length ?d)
2499 (?e gnus-tmp-dots ?s)))
2501 (defvar gnus-mime-button-commands
2502 '((gnus-article-press-button "\r" "Toggle Display")
2503 (gnus-mime-view-part "v" "View Interactively...")
2504 (gnus-mime-save-part "o" "Save...")
2505 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2506 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2507 (gnus-mime-internalize-part "E" "View Internally")
2508 (gnus-mime-externalize-part "e" "View Externally")
2509 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2511 (defun gnus-article-mime-part-status ()
2512 (if gnus-article-mime-handle-alist-1
2513 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2516 (defvar gnus-mime-button-map nil)
2517 (unless gnus-mime-button-map
2518 (setq gnus-mime-button-map (make-sparse-keymap))
2519 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2520 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2521 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2523 (define-key gnus-mime-button-map (cadr c) (car c)))
2524 gnus-mime-button-commands))
2526 (defun gnus-mime-button-menu (event)
2527 "Construct a context-sensitive menu of MIME commands."
2530 (let ((pos (event-start event)))
2531 (set-buffer (window-buffer (posn-window pos)))
2532 (goto-char (posn-point pos))
2533 (gnus-article-check-buffer)
2534 (let ((response (x-popup-menu
2536 ("" ,@(mapcar (lambda (c)
2537 (cons (caddr c) (car c)))
2538 gnus-mime-button-commands))))))
2540 (funcall response))))))
2542 (defun gnus-mime-view-all-parts (&optional handles)
2543 "View all the MIME parts."
2545 (save-current-buffer
2546 (set-buffer gnus-article-buffer)
2547 (let ((handles (or handles gnus-article-mime-handles))
2548 (mail-parse-charset gnus-newsgroup-charset))
2549 (if (stringp (car handles))
2550 (gnus-mime-view-all-parts (cdr handles))
2551 (mapcar 'mm-display-part handles)))))
2553 (defun gnus-mime-save-part ()
2554 "Save the MIME part under point."
2556 (gnus-article-check-buffer)
2557 (let ((data (get-text-property (point) 'gnus-data)))
2558 (mm-save-part data)))
2560 (defun gnus-mime-pipe-part ()
2561 "Pipe the MIME part under point to a process."
2563 (gnus-article-check-buffer)
2564 (let ((data (get-text-property (point) 'gnus-data)))
2565 (mm-pipe-part data)))
2567 (defun gnus-mime-view-part ()
2568 "Interactively choose a view method for the MIME part under point."
2570 (gnus-article-check-buffer)
2571 (let ((data (get-text-property (point) 'gnus-data)))
2572 (mm-interactively-view-part data)))
2574 (defun gnus-mime-copy-part (&optional handle)
2575 "Put the the MIME part under point into a new buffer."
2577 (gnus-article-check-buffer)
2578 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2579 (contents (mm-get-part handle))|
2580 (base (file-name-nondirectory
2582 (mail-content-type-get (mm-handle-type handle) 'name)
2583 (mail-content-type-get (mm-handle-type handle)
2586 (buffer (generate-new-buffer base)))
2587 (switch-to-buffer buffer)
2589 ;; We do it this way to make `normal-mode' set the appropriate mode.
2592 (setq buffer-file-name (expand-file-name base))
2594 (setq buffer-file-name nil))
2595 (goto-char (point-min))))
2597 (defun gnus-mime-inline-part (&optional charset)
2598 "Insert the MIME part under point into the current buffer."
2599 (interactive "P") ; For compatibility reasons we are not using "z".
2600 (gnus-article-check-buffer)
2601 (let* ((data (get-text-property (point) 'gnus-data))
2605 (if (mm-handle-undisplayer data)
2606 (mm-remove-part data)
2607 (setq contents (mm-get-part data))
2610 (unless (symbolp charset)
2611 (setq charset (mm-read-coding-system "Charset: ")))
2612 (setq contents (mm-decode-coding-string contents charset)))
2613 (mm-insert-inline data contents)
2616 (defun gnus-mime-externalize-part (&optional handle)
2617 "View the MIME part under point with an external viewer."
2619 (gnus-article-check-buffer)
2620 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2621 (mm-user-display-methods nil)
2622 (mm-all-images-fit t)
2623 (mail-parse-charset gnus-newsgroup-charset))
2624 (if (mm-handle-undisplayer handle)
2625 (mm-remove-part handle)
2626 (mm-display-part handle))))
2628 (defun gnus-mime-internalize-part (&optional handle)
2629 "View the MIME part under point with an internal viewer."
2631 (gnus-article-check-buffer)
2632 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2633 (mm-user-display-methods '((".*" . inline)))
2634 (mm-all-images-fit t)
2635 (mail-parse-charset gnus-newsgroup-charset))
2636 (if (mm-handle-undisplayer handle)
2637 (mm-remove-part handle)
2638 (mm-display-part handle))))
2640 (defun gnus-article-part-wrapper (n function)
2641 (save-current-buffer
2642 (set-buffer gnus-article-buffer)
2643 (when (> n (length gnus-article-mime-handle-alist))
2644 (error "No such part"))
2645 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2646 (funcall function handle))))
2648 (defun gnus-article-pipe-part (n)
2649 "Pipe MIME part N, which is the numerical prefix."
2651 (gnus-article-part-wrapper n 'mm-pipe-part))
2653 (defun gnus-article-save-part (n)
2654 "Save MIME part N, which is the numerical prefix."
2656 (gnus-article-part-wrapper n 'mm-save-part))
2658 (defun gnus-article-interactively-view-part (n)
2659 "Pipe MIME part N, which is the numerical prefix."
2661 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2663 (defun gnus-article-copy-part (n)
2664 "Pipe MIME part N, which is the numerical prefix."
2666 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2668 (defun gnus-article-externalize-part (n)
2669 "Pipe MIME part N, which is the numerical prefix."
2671 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2673 (defun gnus-article-view-part (n)
2674 "View MIME part N, which is the numerical prefix."
2676 (save-current-buffer
2677 (set-buffer gnus-article-buffer)
2678 (when (> n (length gnus-article-mime-handle-alist))
2679 (error "No such part"))
2680 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2681 (when (gnus-article-goto-part n)
2682 (if (equal (car handle) "multipart/alternative")
2683 (gnus-article-press-button)
2684 (when (eq (gnus-mm-display-part handle) 'internal)
2685 (gnus-set-window-start)))))))
2687 (defun gnus-mm-display-part (handle)
2688 "Display HANDLE and fix MIME button."
2689 (let ((id (get-text-property (point) 'gnus-part))
2694 (let ((window (selected-window))
2695 (mail-parse-charset gnus-newsgroup-charset))
2698 (let ((win (get-buffer-window (current-buffer) t))
2701 (select-window win))
2704 (if (mm-handle-displayed-p handle)
2705 ;; This will remove the part.
2706 (mm-display-part handle)
2708 (narrow-to-region (point) (1+ (point)))
2709 (mm-display-part handle)
2712 (1- (length gnus-article-mime-handles))
2713 (car (mm-handle-type handle))))))
2714 (select-window window))))
2716 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2717 (gnus-insert-mime-button
2718 handle id (list (mm-handle-displayed-p handle)))
2719 (goto-char point))))
2721 (defun gnus-article-goto-part (n)
2722 "Go to MIME part N."
2723 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2725 (goto-char point))))
2727 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2728 (let ((gnus-tmp-name
2729 (or (mail-content-type-get (mm-handle-type handle)
2731 (mail-content-type-get (mm-handle-disposition handle)
2734 (gnus-tmp-type (car (mm-handle-type handle)))
2735 (gnus-tmp-description
2736 (mail-decode-encoded-word-string (or (mm-handle-description handle)
2739 (if (if displayed (car displayed)
2740 (mm-handle-displayed-p handle))
2742 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2744 gnus-tmp-type-long b e)
2745 (when (string-match ".*/" gnus-tmp-name)
2746 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2747 (setq gnus-tmp-type-long (concat gnus-tmp-type
2748 (and (not (equal gnus-tmp-name ""))
2749 (concat "; " gnus-tmp-name))))
2750 (or (equal gnus-tmp-description "")
2751 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2756 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2757 `(local-map ,gnus-mime-button-map
2758 keymap ,gnus-mime-button-map
2759 gnus-callback gnus-mm-display-part
2760 gnus-part ,gnus-tmp-id
2761 article-type annotation
2764 (widget-convert-button 'link b e
2766 :action 'gnus-widget-press-button
2767 :button-keymap gnus-mime-button-map
2770 ;; Needed to properly clear the message
2771 ;; due to a bug in wid-edit
2772 (setq help-echo-owns-message t)
2774 "Click to %s the MIME part; %s for more options"
2775 (if (mm-handle-displayed-p
2776 (widget-get widget :mime-handle))
2778 (if gnus-xemacs "button3" "mouse-3"))))))
2780 (defun gnus-widget-press-button (elems el)
2781 (goto-char (widget-get elems :from))
2782 (gnus-article-press-button))
2784 (defun gnus-display-mime (&optional ihandles)
2785 "Display the MIME parts."
2787 (save-selected-window
2788 (let ((window (get-buffer-window gnus-article-buffer))
2791 (select-window window)
2792 ;; We have to do this since selecting the window
2793 ;; may change the point. So we set the window point.
2794 (set-window-point window point)))
2795 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2796 handle name type b e display)
2798 ;; Top-level call; we clean up.
2799 (mm-destroy-parts gnus-article-mime-handles)
2800 (setq gnus-article-mime-handles handles
2801 gnus-article-mime-handle-alist nil)
2802 ;; We allow users to glean info from the handles.
2803 (when gnus-article-mime-part-function
2804 (gnus-mime-part-function handles)))
2806 (or (not (stringp (car handles)))
2810 ;; Clean up for mime parts.
2812 (delete-region (point) (point-max)))
2813 (gnus-mime-display-part handles))
2816 (narrow-to-region (point) (point-max))
2817 (gnus-treat-article nil 1 1)))
2818 ;; Highlight the headers.
2822 (narrow-to-region (point-min) (point))
2823 (gnus-treat-article 'head)))))))
2825 (defvar gnus-mime-display-multipart-as-mixed nil)
2827 (defun gnus-mime-display-part (handle)
2830 ((not (stringp (car handle)))
2831 (gnus-mime-display-single handle))
2832 ;; multipart/alternative
2833 ((and (equal (car handle) "multipart/alternative")
2834 (not gnus-mime-display-multipart-as-mixed))
2835 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2836 (push (cons id handle) gnus-article-mime-handle-alist)
2837 (gnus-mime-display-alternative (cdr handle) nil nil id)))
2838 ;; multipart/related
2839 ((and (equal (car handle) "multipart/related")
2840 (not gnus-mime-display-multipart-as-mixed))
2841 ;;;!!!We should find the start part, but we just default
2842 ;;;!!!to the first part.
2843 (gnus-mime-display-part (cadr handle)))
2844 ;; Other multiparts are handled like multipart/mixed.
2846 (gnus-mime-display-mixed (cdr handle)))))
2848 (defun gnus-mime-part-function (handles)
2849 (if (stringp (car handles))
2850 (mapcar 'gnus-mime-part-function (cdr handles))
2851 (funcall gnus-article-mime-part-function handles)))
2853 (defun gnus-mime-display-mixed (handles)
2854 (mapcar 'gnus-mime-display-part handles))
2856 (defun gnus-mime-display-single (handle)
2857 (let ((type (car (mm-handle-type handle)))
2858 (ignored gnus-ignored-mime-types)
2865 (when (string-match (pop ignored) type)
2866 (throw 'ignored nil)))
2867 (if (and (setq not-attachment
2868 (or (not (mm-handle-disposition handle))
2869 (equal (car (mm-handle-disposition handle))
2871 (mm-automatic-display-p type)
2872 (or (mm-inlinable-part-p type)
2873 (mm-automatic-external-display-p type)))
2875 (when (equal (car (split-string type "/"))
2878 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2879 (push (cons id handle) gnus-article-mime-handle-alist)
2880 (when (or (not display)
2881 (not (gnus-unbuttonized-mime-type-p type)))
2882 (gnus-article-insert-newline)
2883 (gnus-insert-mime-button
2884 handle id (list (or display (and not-attachment text))))
2885 (gnus-article-insert-newline)
2886 (gnus-article-insert-newline)
2888 (let ((beg (point)))
2893 (let ((mail-parse-charset gnus-newsgroup-charset))
2894 (mm-display-part handle t))
2895 (goto-char (point-max)))
2896 ((and text not-attachment)
2899 (gnus-article-insert-newline)
2900 (mm-insert-inline handle (mm-get-part handle))
2901 (goto-char (point-max))))
2905 (narrow-to-region beg (point))
2907 nil (length gnus-article-mime-handle-alist)
2908 (1- (length gnus-article-mime-handles))
2909 (car (mm-handle-type handle))))))))))
2911 (defun gnus-unbuttonized-mime-type-p (type)
2912 "Say whether TYPE is to be unbuttonized."
2913 (unless gnus-inhibit-mime-unbuttonizing
2915 (let ((types gnus-unbuttonized-mime-types))
2917 (when (string-match (pop types) type)
2918 (throw 'found t)))))))
2920 (defun gnus-article-insert-newline ()
2921 "Insert a newline, but mark it as undeletable."
2922 (gnus-put-text-property
2923 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2925 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2926 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2929 handle buffer-read-only from props begend not-pref)
2930 (save-window-excursion
2933 (narrow-to-region (car ibegend)
2936 (goto-char (car ibegend))
2939 (delete-region (point-min) (point-max))
2940 (mm-remove-parts handles))
2941 (setq begend (list (point-marker)))
2943 (unless (setq not-pref (cadr (member preferred ihandles)))
2944 (setq not-pref (car ihandles)))
2946 (not (gnus-unbuttonized-mime-type-p
2947 "multipart/alternative")))
2948 (gnus-add-text-properties
2951 (insert (format "%d. " id))
2955 (unless ,(not ibegend)
2956 (setq gnus-article-mime-handle-alist
2957 ',gnus-article-mime-handle-alist))
2958 (gnus-mime-display-alternative
2959 ',ihandles ',not-pref ',begend ,id))
2960 local-map ,gnus-mime-button-map
2961 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2962 face ,gnus-article-button-face
2963 keymap ,gnus-mime-button-map
2966 (widget-convert-button 'link from (point)
2967 :action 'gnus-widget-press-button
2968 :button-keymap gnus-widget-button-keymap)
2970 (while (setq handle (pop handles))
2971 (gnus-add-text-properties
2974 (insert (format "(%c) %-18s"
2975 (if (equal handle preferred) ?* ? )
2976 (if (stringp (car handle))
2978 (car (mm-handle-type handle)))))
2982 (unless ,(not ibegend)
2983 (setq gnus-article-mime-handle-alist
2984 ',gnus-article-mime-handle-alist))
2985 (gnus-mime-display-alternative
2986 ',ihandles ',handle ',begend ,id))
2987 local-map ,gnus-mime-button-map
2988 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2989 face ,gnus-article-button-face
2990 keymap ,gnus-mime-button-map
2993 (widget-convert-button 'link from (point)
2994 :action 'gnus-widget-press-button
2995 :button-keymap gnus-widget-button-keymap)
2999 (if (stringp (car preferred))
3000 (gnus-display-mime preferred)
3001 (let ((mail-parse-charset gnus-newsgroup-charset))
3002 (mm-display-part preferred)))
3003 (goto-char (point-max))
3004 (setcdr begend (point-marker)))))
3006 (goto-char point))))
3008 (defun gnus-article-wash-status ()
3009 "Return a string which display status of article washing."
3011 (set-buffer gnus-article-buffer)
3012 (let ((cite (gnus-article-hidden-text-p 'cite))
3013 (headers (gnus-article-hidden-text-p 'headers))
3014 (boring (gnus-article-hidden-text-p 'boring-headers))
3015 (pgp (gnus-article-hidden-text-p 'pgp))
3016 (pem (gnus-article-hidden-text-p 'pem))
3017 (signature (gnus-article-hidden-text-p 'signature))
3018 (overstrike (gnus-article-hidden-text-p 'overstrike))
3019 (emphasis (gnus-article-hidden-text-p 'emphasis)))
3020 (format "%c%c%c%c%c%c"
3022 (if (or headers boring) ?h ? )
3023 (if (or pgp pem) ?p ? )
3024 (if signature ?s ? )
3025 (if overstrike ?o ? )
3026 (if emphasis ?e ? )))))
3028 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3030 (defun gnus-article-maybe-hide-headers ()
3031 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3032 Provided for backwards compatibility."
3033 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3034 (not (save-excursion (set-buffer gnus-summary-buffer)
3035 gnus-have-all-headers)))
3036 (not gnus-inhibit-hiding))
3037 (gnus-article-hide-headers)))
3041 (defun gnus-output-to-file (file-name)
3042 "Append the current article to a file named FILE-NAME."
3043 (let ((artbuf (current-buffer)))
3045 (insert-buffer-substring artbuf)
3046 ;; Append newline at end of the buffer as separator, and then
3048 (goto-char (point-max))
3050 (append-to-file (point-min) (point-max) file-name)
3053 (defun gnus-narrow-to-page (&optional arg)
3054 "Narrow the article buffer to a page.
3055 If given a numerical ARG, move forward ARG pages."
3057 (setq arg (if arg (prefix-numeric-value arg) 0))
3059 (set-buffer gnus-article-buffer)
3060 (goto-char (point-min))
3062 ;; Remove any old next/prev buttons.
3063 (when (gnus-visual-p 'page-marker)
3064 (let ((buffer-read-only nil))
3065 (gnus-remove-text-with-property 'gnus-prev)
3066 (gnus-remove-text-with-property 'gnus-next)))
3069 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3071 (re-search-forward page-delimiter nil 'move arg)))
3072 (goto-char (match-end 0)))
3075 (if (re-search-forward page-delimiter nil 'move)
3078 (when (and (gnus-visual-p 'page-marker)
3079 (not (= (point-min) 1)))
3081 (goto-char (point-min))
3082 (gnus-insert-prev-page-button)))
3083 (when (and (gnus-visual-p 'page-marker)
3084 (< (+ (point-max) 2) (buffer-size)))
3086 (goto-char (point-max))
3087 (gnus-insert-next-page-button)))))
3089 ;; Article mode commands
3091 (defun gnus-article-goto-next-page ()
3092 "Show the next page of the article."
3094 (when (gnus-article-next-page)
3095 (goto-char (point-min))
3096 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3098 (defun gnus-article-goto-prev-page ()
3099 "Show the next page of the article."
3101 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3102 (gnus-article-prev-page nil)))
3104 (defun gnus-article-next-page (&optional lines)
3105 "Show the next page of the current article.
3106 If end of article, return non-nil. Otherwise return nil.
3107 Argument LINES specifies lines to be scrolled up."
3109 (move-to-window-line -1)
3112 (and (pos-visible-in-window-p) ;Not continuation line.
3114 ;; Nothing in this page.
3115 (if (or (not gnus-page-broken)
3118 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3120 (gnus-narrow-to-page 1) ;Go to next page.
3122 ;; More in this page.
3123 (let ((scroll-in-place nil))
3127 ;; Long lines may cause an end-of-buffer error.
3128 (goto-char (point-max)))))
3129 (move-to-window-line 0)
3132 (defun gnus-article-prev-page (&optional lines)
3133 "Show previous page of current article.
3134 Argument LINES specifies lines to be scrolled down."
3136 (move-to-window-line 0)
3137 (if (and gnus-page-broken
3139 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3141 (gnus-narrow-to-page -1) ;Go to previous page.
3142 (goto-char (point-max))
3144 (let ((scroll-in-place nil))
3148 (beginning-of-buffer
3149 (goto-char (point-min))))
3150 (move-to-window-line 0)))))
3152 (defun gnus-article-refer-article ()
3153 "Read article specified by message-id around point."
3155 (let ((point (point)))
3156 (search-forward ">" nil t) ;Move point to end of "<....>".
3157 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3158 (let ((message-id (match-string 1)))
3160 (set-buffer gnus-summary-buffer)
3161 (gnus-summary-refer-article message-id))
3163 (error "No references around point"))))
3165 (defun gnus-article-show-summary ()
3166 "Reconfigure windows to show summary buffer."
3168 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3169 (error "There is no summary buffer for this article buffer")
3170 (gnus-article-set-globals)
3171 (gnus-configure-windows 'article)
3172 (gnus-summary-goto-subject gnus-current-article)
3173 (gnus-summary-position-point)))
3175 (defun gnus-article-describe-briefly ()
3176 "Describe article mode commands briefly."
3178 (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")))
3180 (defun gnus-article-summary-command ()
3181 "Execute the last keystroke in the summary buffer."
3183 (let ((obuf (current-buffer))
3184 (owin (current-window-configuration))
3186 (switch-to-buffer gnus-article-current-summary 'norecord)
3187 (setq func (lookup-key (current-local-map) (this-command-keys)))
3188 (call-interactively func)
3190 (set-window-configuration owin)
3191 (set-window-point (get-buffer-window (current-buffer)) (point))))
3193 (defun gnus-article-summary-command-nosave ()
3194 "Execute the last keystroke in the summary buffer."
3197 (pop-to-buffer gnus-article-current-summary 'norecord)
3198 (setq func (lookup-key (current-local-map) (this-command-keys)))
3199 (call-interactively func)))
3201 (defun gnus-article-check-buffer ()
3202 "Beep if not in an article buffer."
3203 (unless (equal major-mode 'gnus-article-mode)
3204 (error "Command invoked outside of a Gnus article buffer")))
3206 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3207 "Read a summary buffer key sequence and execute it from the article buffer."
3209 (gnus-article-check-buffer)
3211 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3212 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3213 "=" "^" "\M-^" "|"))
3219 '("n" "Gn" "p" "Gp"))
3222 (set-buffer gnus-article-current-summary)
3223 (let (gnus-pick-mode)
3224 (push (or key last-command-event) unread-command-events)
3225 (setq keys (read-key-sequence nil))))
3228 (if (or (member keys nosaves)
3229 (member keys nosave-but-article)
3230 (member keys nosave-in-article))
3232 (save-window-excursion
3233 (pop-to-buffer gnus-article-current-summary 'norecord)
3234 ;; We disable the pick minor mode commands.
3235 (let (gnus-pick-mode)
3236 (setq func (lookup-key (current-local-map) keys))))
3239 (unless (member keys nosave-in-article)
3240 (set-buffer gnus-article-current-summary))
3241 (call-interactively func)
3242 (setq new-sum-point (point)))
3243 (when (member keys nosave-but-article)
3244 (pop-to-buffer gnus-article-buffer 'norecord)))
3245 ;; These commands should restore window configuration.
3246 (let ((obuf (current-buffer))
3247 (owin (current-window-configuration))
3249 (summary gnus-article-current-summary)
3250 func in-buffer selected)
3251 (if not-restore-window
3252 (pop-to-buffer summary 'norecord)
3253 (switch-to-buffer summary 'norecord))
3254 (setq in-buffer (current-buffer))
3255 ;; We disable the pick minor mode commands.
3256 (if (setq func (let (gnus-pick-mode)
3257 (lookup-key (current-local-map) keys)))
3259 (call-interactively func)
3260 (setq new-sum-point (point)))
3262 (when (eq in-buffer (current-buffer))
3263 (setq selected (gnus-summary-select-article))
3265 (unless not-restore-window
3266 (set-window-configuration owin))
3267 (unless (or (not (eq selected 'old)) (member keys up-to-top))
3268 (set-window-point (get-buffer-window (current-buffer))
3270 (let ((win (get-buffer-window gnus-article-current-summary)))
3272 (set-window-point win new-sum-point))))))))
3274 (defun gnus-article-hide (&optional arg force)
3275 "Hide all the gruft in the current article.
3276 This means that PGP stuff, signatures, cited text and (some)
3277 headers will be hidden.
3278 If given a prefix, show the hidden text instead."
3279 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3280 (gnus-article-hide-headers arg)
3281 (gnus-article-hide-pgp arg)
3282 (gnus-article-hide-citation-maybe arg force)
3283 (gnus-article-hide-signature arg))
3285 (defun gnus-article-maybe-highlight ()
3286 "Do some article highlighting if article highlighting is requested."
3287 (when (gnus-visual-p 'article-highlight 'highlight)
3288 (gnus-article-highlight-some)))
3290 (defun gnus-check-group-server ()
3291 ;; Make sure the connection to the server is alive.
3292 (unless (gnus-server-opened
3293 (gnus-find-method-for-group gnus-newsgroup-name))
3294 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3295 (gnus-request-group gnus-newsgroup-name t)))
3297 (defun gnus-request-article-this-buffer (article group)
3298 "Get an article and insert it into this buffer."
3299 (let (do-update-line sparse-header)
3303 (gnus-kill-all-overlays)
3304 (setq group (or group gnus-newsgroup-name))
3306 ;; Using `gnus-request-article' directly will insert the article into
3307 ;; `nntp-server-buffer' - so we'll save some time by not having to
3308 ;; copy it from the server buffer into the article buffer.
3310 ;; We only request an article by message-id when we do not have the
3311 ;; headers for it, so we'll have to get those.
3312 (when (stringp article)
3313 (let ((gnus-override-method gnus-refer-article-method))
3314 (gnus-read-header article)))
3316 ;; If the article number is negative, that means that this article
3317 ;; doesn't belong in this newsgroup (possibly), so we find its
3318 ;; message-id and request it by id instead of number.
3319 (when (and (numberp article)
3321 (get-buffer gnus-summary-buffer)
3322 (gnus-buffer-exists-p gnus-summary-buffer))
3324 (set-buffer gnus-summary-buffer)
3325 (let ((header (gnus-summary-article-header article)))
3328 ((memq article gnus-newsgroup-sparse)
3329 ;; This is a sparse gap article.
3330 (setq do-update-line article)
3331 (setq article (mail-header-id header))
3332 (let ((gnus-override-method gnus-refer-article-method))
3333 (setq sparse-header (gnus-read-header article)))
3334 (setq gnus-newsgroup-sparse
3335 (delq article gnus-newsgroup-sparse)))
3337 ;; It's a real article.
3338 (setq article (mail-header-id header)))
3340 ;; It is an extracted pseudo-article.
3341 (setq article 'pseudo)
3342 (gnus-request-pseudo-article header))))
3344 (let ((method (gnus-find-method-for-group
3345 gnus-newsgroup-name)))
3346 (when (and (eq (car method) 'nneething)
3349 (file-name-as-directory
3350 (or (cadr (assq 'nneething-address method))
3352 (mail-header-subject header))))
3353 (when (file-directory-p dir)
3354 (setq article 'nneething)
3355 (gnus-group-enter-directory dir))))))))
3358 ;; Refuse to select canceled articles.
3359 ((and (numberp article)
3361 (get-buffer gnus-summary-buffer)
3362 (gnus-buffer-exists-p gnus-summary-buffer)
3363 (eq (cdr (save-excursion
3364 (set-buffer gnus-summary-buffer)
3365 (assq article gnus-newsgroup-reads)))
3366 gnus-canceled-mark))
3368 ;; We first check `gnus-original-article-buffer'.
3369 ((and (get-buffer gnus-original-article-buffer)
3372 (set-buffer gnus-original-article-buffer)
3373 (and (equal (car gnus-original-article) group)
3374 (eq (cdr gnus-original-article) article))))
3375 (insert-buffer-substring gnus-original-article-buffer)
3377 ;; Check the backlog.
3378 ((and gnus-keep-backlog
3379 (gnus-backlog-request-article group article (current-buffer)))
3381 ;; Check asynchronous pre-fetch.
3382 ((gnus-async-request-fetched-article group article (current-buffer))
3383 (gnus-async-prefetch-next group article gnus-summary-buffer)
3384 (when (and (numberp article) gnus-keep-backlog)
3385 (gnus-backlog-enter-article group article (current-buffer)))
3388 ((and gnus-use-cache
3390 (gnus-cache-request-article article group))
3392 ;; Get the article and put into the article buffer.
3393 ((or (stringp article) (numberp article))
3394 (let ((gnus-override-method
3395 (and (stringp article) gnus-refer-article-method))
3396 (buffer-read-only nil))
3398 (gnus-kill-all-overlays)
3399 (gnus-check-group-server)
3400 (when (gnus-request-article article group (current-buffer))
3401 (when (numberp article)
3402 (gnus-async-prefetch-next group article gnus-summary-buffer)
3403 (when gnus-keep-backlog
3404 (gnus-backlog-enter-article
3405 group article (current-buffer))))
3410 ;; Associate this article with the current summary buffer.
3411 (setq gnus-article-current-summary gnus-summary-buffer)
3413 ;; Take the article from the original article buffer
3414 ;; and place it in the buffer it's supposed to be in.
3415 (when (and (get-buffer gnus-article-buffer)
3416 (equal (buffer-name (current-buffer))
3417 (buffer-name (get-buffer gnus-article-buffer))))
3419 (if (get-buffer gnus-original-article-buffer)
3420 (set-buffer gnus-original-article-buffer)
3421 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3422 (buffer-disable-undo)
3423 (setq major-mode 'gnus-original-article-mode)
3424 (setq buffer-read-only t))
3425 (let (buffer-read-only)
3427 (insert-buffer-substring gnus-article-buffer))
3428 (setq gnus-original-article (cons group article)))
3431 (run-hooks 'gnus-article-decode-hook)
3432 ;; Mark article as decoded or not.
3433 (setq gnus-article-decoded-p gnus-article-decode-hook))
3435 ;; Update sparse articles.
3436 (when (and do-update-line
3437 (or (numberp article)
3439 (let ((buf (current-buffer)))
3440 (set-buffer gnus-summary-buffer)
3441 (gnus-summary-update-article do-update-line sparse-header)
3442 (gnus-summary-goto-subject do-update-line nil t)
3443 (set-window-point (get-buffer-window (current-buffer) t)
3445 (set-buffer buf))))))
3451 (defcustom gnus-article-edit-mode-hook nil
3452 "Hook run in article edit mode buffers."
3453 :group 'gnus-article-various
3456 (defvar gnus-article-edit-done-function nil)
3458 (defvar gnus-article-edit-mode-map nil)
3460 ;; Should we be using derived.el for this?
3461 (unless gnus-article-edit-mode-map
3462 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3463 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3465 (gnus-define-keys gnus-article-edit-mode-map
3466 "\C-c\C-c" gnus-article-edit-done
3467 "\C-c\C-k" gnus-article-edit-exit)
3469 (gnus-define-keys (gnus-article-edit-wash-map
3470 "\C-c\C-w" gnus-article-edit-mode-map)
3471 "f" gnus-article-edit-full-stops))
3473 (defun gnus-article-edit-mode ()
3474 "Major mode for editing articles.
3475 This is an extended text-mode.
3477 \\{gnus-article-edit-mode-map}"
3479 (setq major-mode 'gnus-article-edit-mode)
3480 (setq mode-name "Article Edit")
3481 (use-local-map gnus-article-edit-mode-map)
3482 (make-local-variable 'gnus-article-edit-done-function)
3483 (make-local-variable 'gnus-prev-winconf)
3484 (setq buffer-read-only nil)
3485 (buffer-enable-undo)
3487 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3489 (defun gnus-article-edit (&optional force)
3490 "Edit the current article.
3491 This will have permanent effect only in mail groups.
3492 If FORCE is non-nil, allow editing of articles even in read-only
3495 (when (and (not force)
3496 (gnus-group-read-only-p))
3497 (error "The current newsgroup does not support article editing"))
3498 (gnus-article-date-original)
3499 (gnus-article-edit-article
3500 `(lambda (no-highlight)
3501 (gnus-summary-edit-article-done
3502 ,(or (mail-header-references gnus-current-headers) "")
3503 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3505 (defun gnus-article-edit-article (exit-func)
3506 "Start editing the contents of the current article buffer."
3507 (let ((winconf (current-window-configuration)))
3508 (set-buffer gnus-article-buffer)
3509 (gnus-article-edit-mode)
3510 (gnus-article-delete-text-of-type 'annotation)
3511 (gnus-set-text-properties (point-min) (point-max) nil)
3512 (gnus-configure-windows 'edit-article)
3513 (setq gnus-article-edit-done-function exit-func)
3514 (setq gnus-prev-winconf winconf)
3515 (gnus-message 6 "C-c C-c to end edits")))
3517 (defun gnus-article-edit-done (&optional arg)
3518 "Update the article edits and exit."
3523 (when (article-goto-body)
3524 (let ((lines (count-lines (point) (point-max)))
3525 (length (- (point-max) (point)))
3526 (case-fold-search t)
3527 (body (copy-marker (point))))
3528 (goto-char (point-min))
3529 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3530 (delete-region (match-beginning 1) (match-end 1))
3531 (insert (number-to-string length)))
3532 (goto-char (point-min))
3533 (when (re-search-forward
3534 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3535 (delete-region (match-beginning 1) (match-end 1))
3536 (insert (number-to-string length)))
3537 (goto-char (point-min))
3538 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3539 (delete-region (match-beginning 1) (match-end 1))
3540 (insert (number-to-string lines)))))))
3541 (let ((func gnus-article-edit-done-function)
3542 (buf (current-buffer))
3543 (start (window-start)))
3544 (gnus-article-edit-exit)
3547 (let ((buffer-read-only nil))
3549 ;; The cache and backlog have to be flushed somewhat.
3550 (when gnus-keep-backlog
3551 (gnus-backlog-remove-article
3552 (car gnus-article-current) (cdr gnus-article-current)))
3553 ;; Flush original article as well.
3555 (when (get-buffer gnus-original-article-buffer)
3556 (set-buffer gnus-original-article-buffer)
3557 (setq gnus-original-article nil)))
3558 (when gnus-use-cache
3559 (gnus-cache-update-article
3560 (car gnus-article-current) (cdr gnus-article-current))))
3562 (set-window-start (get-buffer-window buf) start)
3563 (set-window-point (get-buffer-window buf) (point))))
3565 (defun gnus-article-edit-exit ()
3566 "Exit the article editing without updating."
3568 ;; We remove all text props from the article buffer.
3569 (let ((buf (format "%s" (buffer-string)))
3570 (curbuf (current-buffer))
3572 (window-start (window-start)))
3575 (let ((winconf gnus-prev-winconf))
3577 (set-window-configuration winconf)
3578 ;; Tippy-toe some to make sure that point remains where it was.
3579 (save-current-buffer
3581 (set-window-start (get-buffer-window (current-buffer)) window-start)
3584 (defun gnus-article-edit-full-stops ()
3585 "Interactively repair spacing at end of sentences."
3588 (goto-char (point-min))
3589 (search-forward-regexp "^$" nil t)
3590 (let ((case-fold-search nil))
3591 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3594 ;;; Article highlights
3597 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3599 ;;; Internal Variables:
3601 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)"
3602 "Regular expression that matches URLs."
3603 :group 'gnus-article-buttons
3606 (defcustom gnus-button-alist
3607 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3608 0 t gnus-button-message-id 2)
3609 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3610 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3612 gnus-button-fetch-group 4)
3613 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3614 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3615 t gnus-button-message-id 3)
3616 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3617 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3618 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3619 ;; This is how URLs _should_ be embedded in text...
3620 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3622 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3623 "*Alist of regexps matching buttons in article bodies.
3625 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3626 REGEXP: is the string matching text around the button,
3627 BUTTON: is the number of the regexp grouping actually matching the button,
3628 FORM: is a lisp expression which must eval to true for the button to
3630 CALLBACK: is the function to call when the user push this button, and each
3631 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3633 CALLBACK can also be a variable, in that case the value of that
3634 variable it the real callback function."
3635 :group 'gnus-article-buttons
3636 :type '(repeat (list regexp
3637 (integer :tag "Button")
3639 (function :tag "Callback")
3642 (integer :tag "Regexp group")))))
3644 (defcustom gnus-header-button-alist
3645 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3646 0 t gnus-button-message-id 0)
3647 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3648 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3649 0 t gnus-button-mailto 0)
3650 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3651 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3652 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3653 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3654 gnus-button-message-id 3))
3655 "*Alist of headers and regexps to match buttons in article heads.
3657 This alist is very similar to `gnus-button-alist', except that each
3658 alist has an additional HEADER element first in each entry:
3660 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3662 HEADER is a regexp to match a header. For a fuller explanation, see
3663 `gnus-button-alist'."
3664 :group 'gnus-article-buttons
3665 :group 'gnus-article-headers
3666 :type '(repeat (list (regexp :tag "Header")
3668 (integer :tag "Button")
3670 (function :tag "Callback")
3673 (integer :tag "Regexp group")))))
3675 (defvar gnus-button-regexp nil)
3676 (defvar gnus-button-marker-list nil)
3677 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3679 (defvar gnus-button-last nil)
3680 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3684 (defun gnus-article-push-button (event)
3685 "Check text under the mouse pointer for a callback function.
3686 If the text under the mouse pointer has a `gnus-callback' property,
3687 call it with the value of the `gnus-data' text property."
3689 (set-buffer (window-buffer (posn-window (event-start event))))
3690 (let* ((pos (posn-point (event-start event)))
3691 (data (get-text-property pos 'gnus-data))
3692 (fun (get-text-property pos 'gnus-callback)))
3695 (funcall fun data))))
3697 (defun gnus-article-press-button ()
3698 "Check text at point for a callback function.
3699 If the text at point has a `gnus-callback' property,
3700 call it with the value of the `gnus-data' text property."
3702 (let* ((data (get-text-property (point) 'gnus-data))
3703 (fun (get-text-property (point) 'gnus-callback)))
3705 (funcall fun data))))
3707 (defun gnus-article-highlight (&optional force)
3708 "Highlight current article.
3709 This function calls `gnus-article-highlight-headers',
3710 `gnus-article-highlight-citation',
3711 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3712 do the highlighting. See the documentation for those functions."
3713 (interactive (list 'force))
3714 (gnus-article-highlight-headers)
3715 (gnus-article-highlight-citation force)
3716 (gnus-article-highlight-signature)
3717 (gnus-article-add-buttons force)
3718 (gnus-article-add-buttons-to-head))
3720 (defun gnus-article-highlight-some (&optional force)
3721 "Highlight current article.
3722 This function calls `gnus-article-highlight-headers',
3723 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3724 do the highlighting. See the documentation for those functions."
3725 (interactive (list 'force))
3726 (gnus-article-highlight-headers)
3727 (gnus-article-highlight-signature)
3728 (gnus-article-add-buttons))
3730 (defun gnus-article-highlight-headers ()
3731 "Highlight article headers as specified by `gnus-header-face-alist'."
3734 (set-buffer gnus-article-buffer)
3736 (let ((alist gnus-header-face-alist)
3737 (buffer-read-only nil)
3738 (case-fold-search t)
3739 (inhibit-point-motion-hooks t)
3740 entry regexp header-face field-face from hpoints fpoints)
3741 (message-narrow-to-head)
3742 (while (setq entry (pop alist))
3743 (goto-char (point-min))
3744 (setq regexp (concat "^\\("
3745 (if (string-equal "" (nth 0 entry))
3749 header-face (nth 1 entry)
3750 field-face (nth 2 entry))
3751 (while (and (re-search-forward regexp nil t)
3755 (unless (search-forward ":" nil t)
3757 (when (and header-face
3758 (not (memq (point) hpoints)))
3759 (push (point) hpoints)
3760 (gnus-put-text-property from (point) 'face header-face))
3761 (when (and field-face
3762 (not (memq (setq from (point)) fpoints)))
3764 (if (re-search-forward "^[^ \t]" nil t)
3766 (goto-char (point-max)))
3767 (gnus-put-text-property from (point) 'face field-face))))))))
3769 (defun gnus-article-highlight-signature ()
3770 "Highlight the signature in an article.
3771 It does this by highlighting everything after
3772 `gnus-signature-separator' using `gnus-signature-face'."
3775 (set-buffer gnus-article-buffer)
3776 (let ((buffer-read-only nil)
3777 (inhibit-point-motion-hooks t))
3779 (when (and gnus-signature-face
3780 (gnus-article-narrow-to-signature))
3781 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3782 'face gnus-signature-face)
3784 (gnus-article-search-signature)
3785 (let ((start (match-beginning 0))
3786 (end (set-marker (make-marker) (1+ (match-end 0)))))
3787 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3790 (defun gnus-button-in-region-p (b e prop)
3791 "Say whether PROP exists in the region."
3792 (text-property-not-all b e prop nil))
3794 (defun gnus-article-add-buttons (&optional force)
3795 "Find external references in the article and make buttons of them.
3796 \"External references\" are things like Message-IDs and URLs, as
3797 specified by `gnus-button-alist'."
3798 (interactive (list 'force))
3800 (set-buffer gnus-article-buffer)
3801 (let ((buffer-read-only nil)
3802 (inhibit-point-motion-hooks t)
3803 (case-fold-search t)
3804 (alist gnus-button-alist)
3806 ;; Remove all old markers.
3808 (while (setq marker (pop gnus-button-marker-list))
3810 (when (setq entry (gnus-button-entry))
3811 (put-text-property (match-beginning (nth 1 entry))
3812 (match-end (nth 1 entry))
3813 'gnus-callback nil))
3814 (set-marker marker nil)))
3815 ;; We skip the headers.
3818 (while (setq entry (pop alist))
3819 (setq regexp (car entry))
3821 (while (re-search-forward regexp nil t)
3822 (let* ((start (and entry (match-beginning (nth 1 entry))))
3823 (end (and entry (match-end (nth 1 entry))))
3824 (from (match-beginning 0)))
3825 (when (and (or (eq t (nth 2 entry))
3826 (eval (nth 2 entry)))
3827 (not (gnus-button-in-region-p
3828 start end 'gnus-callback)))
3829 ;; That optional form returned non-nil, so we add the
3831 (gnus-article-add-button
3832 start end 'gnus-button-push
3833 (car (push (set-marker (make-marker) from)
3834 gnus-button-marker-list))))))))))
3836 ;; Add buttons to the head of an article.
3837 (defun gnus-article-add-buttons-to-head ()
3838 "Add buttons to the head of the article."
3841 (set-buffer gnus-article-buffer)
3842 (let ((buffer-read-only nil)
3843 (inhibit-point-motion-hooks t)
3844 (case-fold-search t)
3845 (alist gnus-header-button-alist)
3847 (nnheader-narrow-to-headers)
3849 ;; Each alist entry.
3850 (setq entry (car alist)
3852 (goto-char (point-min))
3853 (while (re-search-forward (car entry) nil t)
3854 ;; Each header matching the entry.
3855 (setq beg (match-beginning 0))
3856 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3857 (match-beginning 0))
3860 (while (re-search-forward (nth 1 entry) end t)
3861 ;; Each match within a header.
3862 (let* ((entry (cdr entry))
3863 (start (match-beginning (nth 1 entry)))
3864 (end (match-end (nth 1 entry)))
3865 (form (nth 2 entry)))
3866 (goto-char (match-end 0))
3868 (gnus-article-add-button
3869 start end (nth 3 entry)
3870 (buffer-substring (match-beginning (nth 4 entry))
3871 (match-end (nth 4 entry)))))))
3875 ;;; External functions:
3877 (defun gnus-article-add-button (from to fun &optional data)
3878 "Create a button between FROM and TO with callback FUN and data DATA."
3879 (when gnus-article-button-face
3880 (gnus-overlay-put (gnus-make-overlay from to)
3881 'face gnus-article-button-face))
3882 (gnus-add-text-properties
3884 (nconc (and gnus-article-mouse-face
3885 (list gnus-mouse-face-prop gnus-article-mouse-face))
3886 (list 'gnus-callback fun)
3887 (and data (list 'gnus-data data))))
3888 (widget-convert-button 'link from to :action 'gnus-widget-press-button
3889 :button-keymap gnus-widget-button-keymap))
3891 ;;; Internal functions:
3893 (defun gnus-article-set-globals ()
3895 (set-buffer gnus-summary-buffer)
3896 (gnus-set-global-variables)))
3898 (defun gnus-signature-toggle (end)
3900 (set-buffer gnus-article-buffer)
3901 (let ((buffer-read-only nil)
3902 (inhibit-point-motion-hooks t))
3903 (if (get-text-property end 'invisible)
3904 (gnus-article-unhide-text end (point-max))
3905 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3907 (defun gnus-button-entry ()
3908 ;; Return the first entry in `gnus-button-alist' matching this place.
3909 (let ((alist gnus-button-alist)
3912 (setq entry (pop alist))
3913 (if (looking-at (car entry))
3918 (defun gnus-button-push (marker)
3919 ;; Push button starting at MARKER.
3922 (let* ((entry (gnus-button-entry))
3923 (inhibit-point-motion-hooks t)
3925 (args (mapcar (lambda (group)
3926 (let ((string (match-string group)))
3927 (gnus-set-text-properties
3928 0 (length string) nil string)
3935 (fboundp (symbol-value fun)))
3936 (apply (symbol-value fun) args))
3938 (gnus-message 1 "You must define `%S' to use this button"
3939 (cons fun args)))))))
3941 (defun gnus-button-message-id (message-id)
3944 (set-buffer gnus-summary-buffer)
3945 (gnus-summary-refer-article message-id)))
3947 (defun gnus-button-fetch-group (address)
3948 "Fetch GROUP specified by ADDRESS."
3949 (if (not (string-match "[:/]" address))
3950 ;; This is just a simple group url.
3951 (gnus-group-read-ephemeral-group address gnus-select-method)
3952 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3954 (error "Can't parse %s" address)
3955 (gnus-group-read-ephemeral-group
3956 (match-string 4 address)
3957 `(nntp ,(match-string 1 address)
3958 (nntp-address ,(match-string 1 address))
3959 (nntp-port-number ,(if (match-end 3)
3960 (match-string 3 address)
3963 (defun gnus-url-parse-query-string (query &optional downcase)
3964 (let (retval pairs cur key val)
3965 (setq pairs (split-string query "&"))
3967 (setq cur (car pairs)
3969 (if (not (string-match "=" cur))
3971 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3972 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3974 (setq key (downcase key)))
3975 (setq cur (assoc key retval))
3977 (setcdr cur (cons val (cdr cur)))
3978 (setq retval (cons (list key val) retval)))))
3981 (defun gnus-url-unhex (x)
3988 (defun gnus-url-unhex-string (str &optional allow-newlines)
3989 "Remove %XXX embedded spaces, etc in a url.
3990 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3991 decoding of carriage returns and line feeds in the string, which is normally
3992 forbidden in URL encoding."
3993 (setq str (or str ""))
3995 (case-fold-search t))
3996 (while (string-match "%[0-9a-f][0-9a-f]" str)
3997 (let* ((start (match-beginning 0))
3998 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4000 (gnus-url-unhex (elt str (+ start 2))))))
4002 tmp (substring str 0 start)
4005 (char-to-string code))
4006 ((or (= code ?\n) (= code ?\r))
4008 (t (char-to-string code))))
4009 str (substring str (match-end 0)))))
4010 (setq tmp (concat tmp str))
4013 (defun gnus-url-mailto (url)
4014 ;; Send mail to someone
4015 (when (string-match "mailto:/*\\(.*\\)" url)
4016 (setq url (substring url (match-beginning 1) nil)))
4017 (let (to args subject func)
4018 (if (string-match (regexp-quote "?") url)
4019 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4020 args (gnus-url-parse-query-string
4021 (substring url (match-end 0) nil) t))
4022 (setq to (gnus-url-unhex-string url)))
4023 (setq args (cons (list "to" to) args)
4024 subject (cdr-safe (assoc "subject" args)))
4027 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4030 (message-position-on-field (caar args)))
4031 (insert (mapconcat 'identity (cdar args) ", "))
4032 (setq args (cdr args)))
4035 (message-goto-subject))))
4037 (defun gnus-button-mailto (address)
4039 (set-buffer (gnus-copy-article-buffer))
4040 (message-reply address))
4042 (defun gnus-button-reply (address)
4043 ;; Reply to ADDRESS.
4044 (message-reply address))
4046 (defun gnus-button-url (address)
4048 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4049 (if (listp browse-url-browser-function)
4050 (browse-url address)
4051 (funcall browse-url-browser-function address)))
4053 (defun gnus-button-embedded-url (address)
4055 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4056 (if (listp browse-url-browser-function)
4057 (browse-url (gnus-strip-whitespace address))
4058 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4060 ;;; Next/prev buttons in the article buffer.
4062 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4063 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4065 (defvar gnus-prev-page-map nil)
4066 (unless gnus-prev-page-map
4067 (setq gnus-prev-page-map (make-sparse-keymap))
4068 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4069 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4071 (defun gnus-insert-prev-page-button ()
4072 (let ((buffer-read-only nil))
4074 gnus-prev-page-line-format nil
4075 `(gnus-prev t local-map ,gnus-prev-page-map
4076 gnus-callback gnus-article-button-prev-page
4077 article-type annotation))))
4079 (defvar gnus-next-page-map nil)
4080 (unless gnus-next-page-map
4081 (setq gnus-next-page-map (make-keymap))
4082 (suppress-keymap gnus-prev-page-map)
4083 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4084 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4086 (defun gnus-button-next-page ()
4087 "Go to the next page."
4089 (let ((win (selected-window)))
4090 (select-window (get-buffer-window gnus-article-buffer t))
4091 (gnus-article-next-page)
4092 (select-window win)))
4094 (defun gnus-button-prev-page ()
4095 "Go to the prev page."
4097 (let ((win (selected-window)))
4098 (select-window (get-buffer-window gnus-article-buffer t))
4099 (gnus-article-prev-page)
4100 (select-window win)))
4102 (defun gnus-insert-next-page-button ()
4103 (let ((buffer-read-only nil))
4104 (gnus-eval-format gnus-next-page-line-format nil
4106 t local-map ,gnus-next-page-map
4107 gnus-callback gnus-article-button-next-page
4108 article-type annotation))))
4110 (defun gnus-article-button-next-page (arg)
4111 "Go to the next page."
4113 (let ((win (selected-window)))
4114 (select-window (get-buffer-window gnus-article-buffer t))
4115 (gnus-article-next-page)
4116 (select-window win)))
4118 (defun gnus-article-button-prev-page (arg)
4119 "Go to the prev page."
4121 (let ((win (selected-window)))
4122 (select-window (get-buffer-window gnus-article-buffer t))
4123 (gnus-article-prev-page)
4124 (select-window win)))
4126 (defvar gnus-decode-header-methods
4127 '(mail-decode-encoded-word-region)
4128 "List of methods used to decode headers.
4130 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4131 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4132 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4133 whose names match REGEXP.
4136 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4137 mail-decode-encoded-word-region
4138 (\"chinese\" . rfc1843-decode-region))
4141 (defvar gnus-decode-header-methods-cache nil)
4143 (defun gnus-multi-decode-header (start end)
4144 "Apply the functions from `gnus-encoded-word-methods' that match."
4145 (unless (and gnus-decode-header-methods-cache
4146 (eq gnus-newsgroup-name
4147 (car gnus-decode-header-methods-cache)))
4148 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4151 (nconc gnus-decode-header-methods-cache (list x))
4152 (if (and gnus-newsgroup-name
4153 (string-match (car x) gnus-newsgroup-name))
4154 (nconc gnus-decode-header-methods-cache
4156 gnus-decode-header-methods))
4157 (let ((xlist gnus-decode-header-methods-cache))
4160 (narrow-to-region start end)
4162 (funcall (pop xlist) (point-min) (point-max))))))
4165 ;;; Treatment top-level handling.
4168 (defun gnus-treat-article (condition &optional part-number total-parts type)
4169 (let ((length (- (point-max) (point-min)))
4170 (alist gnus-treatment-function-alist)
4171 (article-goto-body-goes-to-point-min-p t)
4173 (when (and (gnus-visual-p 'article-highlight 'highlight)
4176 (let ((list gnus-article-treat-types))
4178 (when (string-match (pop list) type)
4179 (throw 'found t)))))))
4180 (gnus-run-hooks 'gnus-part-display-hook)
4181 (while (setq elem (pop alist))
4182 (setq val (symbol-value (car elem)))
4193 (eq part-number total-parts))
4198 (funcall (cadr elem)))))))
4204 (run-hooks 'gnus-art-load-hook)
4206 ;;; gnus-art.el ends here