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 gnus-xemacs t nil)
741 :group 'gnus-article-treat
742 :type gnus-article-treat-custom)
744 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
746 :group 'gnus-article-treat
747 :type gnus-article-treat-custom)
749 ;;; Internal variables
751 (defvar article-goto-body-goes-to-point-min-p nil)
753 (defvar gnus-article-mime-handle-alist-1 nil)
754 (defvar gnus-treatment-function-alist
755 '((gnus-treat-highlight-signature gnus-article-highlight-signature)
756 (gnus-treat-buttonize gnus-article-add-buttons)
757 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
758 (gnus-treat-emphasize gnus-article-emphasize)
759 (gnus-treat-fill-article gnus-article-fill-cited-article)
760 (gnus-treat-strip-cr gnus-article-remove-cr)
761 (gnus-treat-hide-headers gnus-article-hide-headers)
762 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
763 (gnus-treat-hide-signature gnus-article-hide-signature)
764 (gnus-treat-hide-citation gnus-article-hide-citation)
765 (gnus-treat-strip-pgp gnus-article-hide-pgp)
766 (gnus-treat-strip-pem gnus-article-hide-pem)
767 (gnus-treat-highlight-headers gnus-article-highlight-headers)
768 (gnus-treat-highlight-citation gnus-article-highlight-citation)
769 (gnus-treat-highlight-signature gnus-article-highlight-signature)
770 (gnus-treat-date-ut gnus-article-date-ut)
771 (gnus-treat-date-local gnus-article-date-local)
772 (gnus-treat-date-lapsed gnus-article-date-lapsed)
773 (gnus-treat-date-original gnus-article-date-original)
774 (gnus-treat-strip-trailing-blank-lines
775 gnus-article-remove-trailing-blank-lines)
776 (gnus-treat-strip-leading-blank-lines
777 gnus-article-strip-leading-blank-lines)
778 (gnus-treat-strip-multiple-blank-lines
779 gnus-article-strip-multiple-blank-lines)
780 (gnus-treat-strip-blank-lines gnus-article-strip-blank-lines)
781 (gnus-treat-overstrike gnus-article-treat-overstrike)
782 (gnus-treat-display-xface gnus-article-display-x-face)
783 (gnus-treat-display-smileys gnus-smiley-display)
784 (gnus-treat-display-picons gnus-article-display-picons)))
786 (defvar gnus-article-mime-handle-alist nil)
787 (defvar article-lapsed-timer nil)
788 (defvar gnus-article-current-summary nil)
790 (defvar gnus-article-mode-syntax-table
791 (let ((table (copy-syntax-table text-mode-syntax-table)))
792 (modify-syntax-entry ?- "w" table)
793 (modify-syntax-entry ?> ")" table)
794 (modify-syntax-entry ?< "(" table)
796 "Syntax table used in article mode buffers.
797 Initialized from `text-mode-syntax-table.")
799 (defvar gnus-save-article-buffer nil)
801 (defvar gnus-article-mode-line-format-alist
802 (nconc '((?w (gnus-article-wash-status) ?s)
803 (?m (gnus-article-mime-part-status) ?s))
804 gnus-summary-mode-line-format-alist))
806 (defvar gnus-number-of-articles-to-be-saved nil)
808 (defvar gnus-inhibit-hiding nil)
810 (defsubst gnus-article-hide-text (b e props)
811 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
812 (add-text-properties b e props)
813 (when (memq 'intangible props)
815 (max (1- b) (point-min))
816 b 'intangible (cddr (memq 'intangible props)))))
818 (defmacro gnus-with-article (article &rest forms)
819 "Select ARTICLE and perform FORMS in the original article buffer.
820 Then replace the article with the result."
822 ;; We don't want the article to be marked as read.
823 (let (gnus-mark-article-hook)
824 (gnus-summary-select-article t t nil ,article))
825 (set-buffer gnus-original-article-buffer)
827 (if (not (gnus-check-backend-function
828 'request-replace-article (car gnus-article-current)))
829 (gnus-message 5 "Read-only group; not replacing")
830 (unless (gnus-request-replace-article
831 ,article (car gnus-article-current)
833 (error "Couldn't replace article")))
834 ;; The cache and backlog have to be flushed somewhat.
835 (when gnus-keep-backlog
836 (gnus-backlog-remove-article
837 (car gnus-article-current) (cdr gnus-article-current)))
839 (gnus-cache-update-article
840 (car gnus-article-current) (cdr gnus-article-current)))))
842 (put 'gnus-with-article 'lisp-indent-function 1)
843 (put 'gnus-with-article 'edebug-form-spec '(form body))
845 (defsubst gnus-article-unhide-text (b e)
846 "Remove hidden text properties from region between B and E."
847 (remove-text-properties b e gnus-hidden-properties)
848 (when (memq 'intangible gnus-hidden-properties)
849 (put-text-property (max (1- b) (point-min))
852 (defun gnus-article-hide-text-type (b e type)
853 "Hide text of TYPE between B and E."
854 (gnus-article-hide-text
855 b e (cons 'article-type (cons type gnus-hidden-properties))))
857 (defun gnus-article-unhide-text-type (b e type)
858 "Unhide text of TYPE between B and E."
859 (remove-text-properties
860 b e (cons 'article-type (cons type gnus-hidden-properties)))
861 (when (memq 'intangible gnus-hidden-properties)
862 (put-text-property (max (1- b) (point-min))
865 (defun gnus-article-hide-text-of-type (type)
866 "Hide text of TYPE in the current buffer."
868 (let ((b (point-min))
870 (while (setq b (text-property-any b e 'article-type type))
871 (add-text-properties b (incf b) gnus-hidden-properties)))))
873 (defun gnus-article-delete-text-of-type (type)
874 "Delete text of TYPE in the current buffer."
876 (let ((b (point-min)))
877 (while (setq b (text-property-any b (point-max) 'article-type type))
879 b (or (text-property-not-all b (point-max) 'article-type type)
882 (defun gnus-article-delete-invisible-text ()
883 "Delete all invisible text in the current buffer."
885 (let ((b (point-min)))
886 (while (setq b (text-property-any b (point-max) 'invisible t))
888 b (or (text-property-not-all b (point-max) 'invisible t)
891 (defun gnus-article-text-type-exists-p (type)
892 "Say whether any text of type TYPE exists in the buffer."
893 (text-property-any (point-min) (point-max) 'article-type type))
895 (defsubst gnus-article-header-rank ()
896 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
897 (let ((list gnus-sorted-header-list)
900 (when (looking-at (car list))
902 (setq list (cdr list))
906 (defun article-hide-headers (&optional arg delete)
907 "Toggle whether to hide unwanted headers and possibly sort them as well.
908 If given a negative prefix, always show; if given a positive prefix,
910 (interactive (gnus-article-hidden-arg))
912 (if (gnus-article-check-hidden-text 'headers arg)
913 ;; Show boring headers as well.
914 (gnus-article-show-hidden-text 'boring-headers)
915 ;; This function might be inhibited.
916 (unless gnus-inhibit-hiding
919 (let ((buffer-read-only nil)
921 (props (nconc (list 'article-type 'headers)
922 gnus-hidden-properties))
923 (max (1+ (length gnus-sorted-header-list)))
924 (ignored (when (not gnus-visible-headers)
925 (cond ((stringp gnus-ignored-headers)
926 gnus-ignored-headers)
927 ((listp gnus-ignored-headers)
928 (mapconcat 'identity gnus-ignored-headers
931 (cond ((stringp gnus-visible-headers)
932 gnus-visible-headers)
933 ((and gnus-visible-headers
934 (listp gnus-visible-headers))
935 (mapconcat 'identity gnus-visible-headers "\\|"))))
936 (inhibit-point-motion-hooks t)
938 ;; First we narrow to just the headers.
940 (goto-char (point-min))
941 ;; Hide any "From " lines at the beginning of (mail) articles.
942 (while (looking-at "From ")
946 (delete-region (point-min) (point))
947 (gnus-article-hide-text (point-min) (point) props)))
948 ;; Then treat the rest of the header lines.
951 (if (search-forward "\n\n" nil t) ; if there's a body
952 (progn (forward-line -1) (point))
954 ;; Then we use the two regular expressions
955 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
956 ;; select which header lines is to remain visible in the
958 (goto-char (point-min))
959 (while (re-search-forward "^[^ \t]*:" nil t)
961 ;; Mark the rank of the header.
963 (point) (1+ (point)) 'message-rank
964 (if (or (and visible (looking-at visible))
966 (not (looking-at ignored))))
967 (gnus-article-header-rank)
970 (message-sort-headers-1)
971 (when (setq beg (text-property-any
972 (point-min) (point-max) 'message-rank (+ 2 max)))
973 ;; We make the unwanted headers invisible.
975 (delete-region beg (point-max))
976 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
977 (gnus-article-hide-text-type beg (point-max) 'headers))
978 ;; Work around XEmacs lossage.
979 (put-text-property (point-min) beg 'invisible nil))))))))
981 (defun article-hide-boring-headers (&optional arg)
982 "Toggle hiding of headers that aren't very interesting.
983 If given a negative prefix, always show; if given a positive prefix,
985 (interactive (gnus-article-hidden-arg))
986 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
987 (not gnus-show-all-headers))
990 (let ((buffer-read-only nil)
991 (list gnus-boring-article-headers)
992 (inhibit-point-motion-hooks t)
994 (nnheader-narrow-to-headers)
996 (setq elem (pop list))
997 (goto-char (point-min))
999 ;; Hide empty headers.
1001 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
1003 (gnus-article-hide-text-type
1004 (progn (beginning-of-line) (point))
1007 (if (re-search-forward "^[^ \t]" nil t)
1011 ;; Hide boring Newsgroups header.
1012 ((eq elem 'newsgroups)
1013 (when (equal (gnus-fetch-field "newsgroups")
1014 (gnus-group-real-name
1015 (if (boundp 'gnus-newsgroup-name)
1018 (gnus-article-hide-header "newsgroups")))
1019 ((eq elem 'followup-to)
1020 (when (equal (message-fetch-field "followup-to")
1021 (message-fetch-field "newsgroups"))
1022 (gnus-article-hide-header "followup-to")))
1023 ((eq elem 'reply-to)
1024 (let ((from (message-fetch-field "from"))
1025 (reply-to (message-fetch-field "reply-to")))
1030 (nth 1 (mail-extract-address-components from))
1031 (nth 1 (mail-extract-address-components reply-to)))))
1032 (gnus-article-hide-header "reply-to"))))
1034 (let ((date (message-fetch-field "date")))
1036 (< (days-between (current-time-string) date)
1038 (gnus-article-hide-header "date"))))
1040 (let ((to (message-fetch-field "to")))
1041 (when (> (length to) 1024)
1042 (gnus-article-hide-header "to"))))
1045 (goto-char (point-min))
1046 (while (re-search-forward "^to:" nil t)
1047 (setq to-count (1+ to-count)))
1048 (when (> to-count 1)
1049 (while (> to-count 0)
1050 (goto-char (point-min))
1052 (re-search-forward "^to:" nil nil to-count)
1054 (narrow-to-region (point) (point-max))
1055 (gnus-article-hide-header "to"))
1056 (setq to-count (1- to-count)))))))))))))
1058 (defun gnus-article-hide-header (header)
1060 (goto-char (point-min))
1061 (when (re-search-forward (concat "^" header ":") nil t)
1062 (gnus-article-hide-text-type
1063 (progn (beginning-of-line) (point))
1066 (if (re-search-forward "^[^ \t]" nil t)
1071 (defvar gnus-article-normalized-header-length 40
1072 "Length of normalized headers.")
1074 (defun article-normalize-headers ()
1075 "Make all header lines 40 characters long."
1077 (let ((buffer-read-only nil)
1081 (message-narrow-to-head)
1084 ((< (setq column (- (gnus-point-at-eol) (point)))
1085 gnus-article-normalized-header-length)
1087 (insert (make-string
1088 (- gnus-article-normalized-header-length column)
1090 ((> column gnus-article-normalized-header-length)
1091 (gnus-put-text-property
1093 (forward-char gnus-article-normalized-header-length)
1100 (forward-line 1))))))
1102 (defun article-treat-dumbquotes ()
1103 "Translate M******** sm*rtq**t*s into proper text.
1104 Note that this function guesses whether a character is a sm*rtq**t* or
1105 not, so it should only be used interactively."
1107 (article-translate-strings gnus-article-dumbquotes-map))
1109 (defun article-translate-characters (from to)
1110 "Translate all characters in the body of the article according to FROM and TO.
1111 FROM is a string of characters to translate from; to is a string of
1112 characters to translate to."
1114 (when (article-goto-body)
1115 (let ((buffer-read-only nil)
1116 (x (make-string 225 ?x))
1118 (while (< (incf i) (length x))
1121 (while (< i (length from))
1122 (aset x (aref from i) (aref to i))
1124 (translate-region (point) (point-max) x)))))
1126 (defun article-translate-strings (map)
1127 "Translate all string in the body of the article according to MAP.
1128 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1130 (when (article-goto-body)
1131 (let ((buffer-read-only nil)
1133 (while (setq elem (pop map))
1135 (while (search-forward (car elem) nil t)
1136 (replace-match (cadr elem)))))))))
1138 (defun article-treat-overstrike ()
1139 "Translate overstrikes into bold text."
1142 (when (article-goto-body)
1143 (let ((buffer-read-only nil))
1144 (while (search-forward "\b" nil t)
1145 (let ((next (char-after))
1146 (previous (char-after (- (point) 2))))
1147 ;; We do the boldification/underlining by hiding the
1148 ;; overstrikes and putting the proper text property
1152 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1153 (put-text-property (point) (1+ (point)) 'face 'bold))
1155 (gnus-article-hide-text-type
1156 (1- (point)) (1+ (point)) 'overstrike)
1158 (- (point) 2) (1- (point)) 'face 'underline))
1160 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1162 (point) (1+ (point)) 'face 'underline)))))))))
1164 (defun article-fill ()
1165 "Format too long lines."
1168 (let ((buffer-read-only nil))
1172 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
1173 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
1174 (adaptive-fill-mode t))
1176 (and (>= (current-column) (min fill-column (window-width)))
1177 (/= (preceding-char) ?:)
1178 (fill-paragraph nil))
1179 (end-of-line 2))))))
1181 (defun article-remove-cr ()
1182 "Translate CRLF pairs into LF, and then CR into LF.."
1185 (let ((buffer-read-only nil))
1186 (goto-char (point-min))
1187 (while (search-forward "\r$" nil t)
1188 (replace-match "" t t))
1189 (goto-char (point-min))
1190 (while (search-forward "\r" nil t)
1191 (replace-match "\n" t t)))))
1193 (defun article-remove-trailing-blank-lines ()
1194 "Remove all trailing blank lines from the article."
1197 (let ((buffer-read-only nil))
1198 (goto-char (point-max))
1202 (while (and (not (bobp))
1203 (looking-at "^[ \t]*$")
1204 (not (gnus-annotation-in-region-p
1205 (point) (gnus-point-at-eol))))
1210 (defun article-display-x-face (&optional force)
1211 "Look for an X-Face header and display it if present."
1212 (interactive (list 'force))
1214 ;; Delete the old process, if any.
1215 (when (process-status "article-x-face")
1216 (delete-process "article-x-face"))
1217 (let ((inhibit-point-motion-hooks t)
1218 (case-fold-search t)
1221 (nnheader-narrow-to-headers)
1222 (setq from (message-fetch-field "from"))
1223 (goto-char (point-min))
1224 (while (and gnus-article-x-face-command
1227 ;; Check whether this face is censored.
1228 (not gnus-article-x-face-too-ugly)
1229 (and gnus-article-x-face-too-ugly from
1230 (not (string-match gnus-article-x-face-too-ugly
1232 ;; Has to be present.
1233 (re-search-forward "^X-Face: " nil t))
1234 ;; This used to try to do multiple faces (`while' instead of
1235 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1236 ;; work (b) it can crash some versions of Emacs (c) are
1237 ;; multiple faces really something to encourage?
1238 (when (stringp gnus-article-x-face-command)
1240 ;; We now have the area of the buffer where the X-Face is stored.
1243 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1244 ;; We display the face.
1245 (if (symbolp gnus-article-x-face-command)
1246 ;; The command is a lisp function, so we call it.
1247 (if (gnus-functionp gnus-article-x-face-command)
1248 (funcall gnus-article-x-face-command beg end)
1249 (error "%s is not a function" gnus-article-x-face-command))
1250 ;; The command is a string, so we interpret the command
1251 ;; as a, well, command, and fork it off.
1252 (let ((process-connection-type nil))
1253 (process-kill-without-query
1255 "article-x-face" nil shell-file-name shell-command-switch
1256 gnus-article-x-face-command))
1257 (process-send-region "article-x-face" beg end)
1258 (process-send-eof "article-x-face"))))))))))
1260 (defun article-decode-mime-words ()
1261 "Decode all MIME-encoded words in the article."
1264 (set-buffer gnus-article-buffer)
1265 (let ((inhibit-point-motion-hooks t)
1267 (mail-parse-charset gnus-newsgroup-charset))
1268 (mail-decode-encoded-word-region (point-min) (point-max)))))
1270 (defun article-decode-charset (&optional prompt)
1271 "Decode charset-encoded text in the article.
1272 If PROMPT (the prefix), prompt for a coding system to use."
1276 (message-narrow-to-head)
1277 (let* ((inhibit-point-motion-hooks t)
1278 (case-fold-search t)
1279 (ct (message-fetch-field "Content-Type" t))
1280 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1281 (ctl (and ct (condition-case ()
1282 (mail-header-parse-content-type ct)
1286 (mm-read-coding-system "Charset to decode: "))
1288 (mail-content-type-get ctl 'charset))))
1289 (mail-parse-charset gnus-newsgroup-charset)
1291 (goto-char (point-max))
1294 (narrow-to-region (point) (point-max))
1295 (when (and (or (not ctl)
1296 (equal (car ctl) "text/plain"))
1299 charset (and cte (intern (downcase
1300 (gnus-strip-whitespace cte))))
1303 (defun article-decode-encoded-words ()
1304 "Remove encoded-word encoding from headers."
1305 (let ((inhibit-point-motion-hooks t)
1306 (mail-parse-charset gnus-newsgroup-charset)
1309 (message-narrow-to-head)
1310 (funcall gnus-decode-header-function (point-min) (point-max)))))
1312 (defun article-de-quoted-unreadable (&optional force)
1313 "Translate a quoted-printable-encoded article.
1314 If FORCE, decode the article whether it is marked as quoted-printable
1316 (interactive (list 'force))
1318 (let ((buffer-read-only nil)
1319 (type (gnus-fetch-field "content-transfer-encoding"))
1320 (charset gnus-newsgroup-charset))
1322 (and type (string-match "quoted-printable" (downcase type))))
1325 (narrow-to-region (point) (point-max))
1326 (quoted-printable-decode-region (point-min) (point-max))
1328 (mm-decode-body charset)))))))
1330 (defun article-hide-pgp (&optional arg)
1331 "Toggle hiding of any PGP headers and signatures in the current article.
1332 If given a negative prefix, always show; if given a positive prefix,
1334 (interactive (gnus-article-hidden-arg))
1335 (unless (gnus-article-check-hidden-text 'pgp arg)
1337 (let ((inhibit-point-motion-hooks t)
1338 buffer-read-only beg end)
1340 (goto-char (point-min))
1341 ;; Hide the "header".
1342 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1343 (delete-region (1+ (match-beginning 0)) (match-end 0))
1344 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1345 (when (looking-at "Hash:.*$")
1346 (delete-region (point) (1+ (gnus-point-at-eol))))
1348 ;; Hide the actual signature.
1349 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1350 (setq end (1+ (match-beginning 0)))
1353 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1355 ;; Perhaps we shouldn't hide to the end of the buffer
1356 ;; if there is no end to the signature?
1358 ;; Hide "- " PGP quotation markers.
1360 (narrow-to-region beg end)
1361 (goto-char (point-min))
1362 (while (re-search-forward "^- " nil t)
1364 (match-beginning 0) (match-end 0)))
1366 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1368 (defun article-hide-pem (&optional arg)
1369 "Toggle hiding of any PEM headers and signatures in the current article.
1370 If given a negative prefix, always show; if given a positive prefix,
1372 (interactive (gnus-article-hidden-arg))
1373 (unless (gnus-article-check-hidden-text 'pem arg)
1375 (let (buffer-read-only end)
1377 (goto-char (point-min))
1378 ;; hide the horrendously ugly "header".
1379 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1382 (setq end (1+ (match-beginning 0)))
1383 (gnus-article-hide-text-type
1385 (if (search-forward "\n\n" nil t)
1389 ;; hide the trailer as well
1390 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1393 (gnus-article-hide-text-type
1394 (match-beginning 0) (match-end 0) 'pem))))))
1396 (defun article-hide-signature (&optional arg)
1397 "Hide the signature in the current article.
1398 If given a negative prefix, always show; if given a positive prefix,
1400 (interactive (gnus-article-hidden-arg))
1401 (unless (gnus-article-check-hidden-text 'signature arg)
1404 (let ((buffer-read-only nil))
1405 (when (gnus-article-narrow-to-signature)
1406 (gnus-article-hide-text-type
1407 (point-min) (point-max) 'signature)))))))
1409 (defun article-strip-leading-blank-lines ()
1410 "Remove all blank lines from the beginning of the article."
1413 (let ((inhibit-point-motion-hooks t)
1415 (when (article-goto-body)
1416 (while (and (not (eobp))
1417 (looking-at "[ \t]*$"))
1418 (gnus-delete-line))))))
1420 (defun article-goto-body ()
1421 "Place point at the start of the body."
1422 (goto-char (point-min))
1424 (article-goto-body-goes-to-point-min-p
1426 ((search-forward "\n\n" nil t)
1429 (goto-char (point-max))
1432 (defun article-strip-multiple-blank-lines ()
1433 "Replace consecutive blank lines with one empty line."
1436 (let ((inhibit-point-motion-hooks t)
1438 ;; First make all blank lines empty.
1440 (while (re-search-forward "^[ \t]+$" nil t)
1441 (unless (gnus-annotation-in-region-p
1442 (match-beginning 0) (match-end 0))
1443 (replace-match "" nil t)))
1444 ;; Then replace multiple empty lines with a single empty line.
1446 (while (re-search-forward "\n\n\n+" nil t)
1447 (unless (gnus-annotation-in-region-p
1448 (match-beginning 0) (match-end 0))
1449 (replace-match "\n\n" t t))))))
1451 (defun article-strip-leading-space ()
1452 "Remove all white space from the beginning of the lines in the article."
1455 (let ((inhibit-point-motion-hooks t)
1458 (while (re-search-forward "^[ \t]+" nil t)
1459 (replace-match "" t t)))))
1461 (defun article-strip-trailing-space ()
1462 "Remove all white space from the end of the lines in the article."
1465 (let ((inhibit-point-motion-hooks t)
1468 (while (re-search-forward "[ \t]+$" nil t)
1469 (replace-match "" t t)))))
1471 (defun article-strip-blank-lines ()
1472 "Strip leading, trailing and multiple blank lines."
1474 (article-strip-leading-blank-lines)
1475 (article-remove-trailing-blank-lines)
1476 (article-strip-multiple-blank-lines))
1478 (defun article-strip-all-blank-lines ()
1479 "Strip all blank lines."
1482 (let ((inhibit-point-motion-hooks t)
1485 (while (re-search-forward "^[ \t]*\n" nil t)
1486 (replace-match "" t t)))))
1488 (defun gnus-article-narrow-to-signature ()
1489 "Narrow to the signature; return t if a signature is found, else nil."
1491 (let ((inhibit-point-motion-hooks t))
1492 (when (gnus-article-search-signature)
1494 ;; Check whether we have some limits to what we consider
1495 ;; to be a signature.
1496 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1497 (list gnus-signature-limit)))
1499 (while (setq limit (pop limits))
1500 (if (or (and (integerp limit)
1501 (< (- (point-max) (point)) limit))
1503 (< (count-lines (point) (point-max)) limit))
1504 (and (gnus-functionp limit)
1506 (and (stringp limit)
1507 (not (re-search-forward limit nil t))))
1508 () ; This limit did not succeed.
1512 (narrow-to-region (point) (point-max))
1515 (defun gnus-article-search-signature ()
1516 "Search the current buffer for the signature separator.
1517 Put point at the beginning of the signature separator."
1518 (let ((cur (point)))
1519 (goto-char (point-max))
1520 (if (if (stringp gnus-signature-separator)
1521 (re-search-backward gnus-signature-separator nil t)
1522 (let ((seps gnus-signature-separator))
1524 (not (re-search-backward (car seps) nil t)))
1532 (autoload 'w3-display "w3-parse")
1533 (autoload 'w3-do-setup "w3" "" t)
1534 (autoload 'w3-region "w3-display" "" t))
1536 (defun gnus-article-treat-html ()
1539 (let ((cbuf (current-buffer)))
1540 (set-buffer gnus-article-buffer)
1541 (let (buf buffer-read-only b e)
1543 (goto-char (point-min))
1545 (if (search-forward "\n\n" nil t)
1548 (setq e (point-max)))
1550 (insert-buffer-substring gnus-article-buffer b e)
1552 (save-window-excursion
1553 (w3-region (point-min) (point-max))
1554 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1556 (delete-region (point-min) (point-max))
1559 (goto-char (point-min))
1560 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1561 (set-buffer cbuf))))
1563 (defun gnus-article-hidden-arg ()
1564 "Return the current prefix arg as a number, or 0 if no prefix."
1565 (list (if current-prefix-arg
1566 (prefix-numeric-value current-prefix-arg)
1569 (defun gnus-article-check-hidden-text (type arg)
1570 "Return nil if hiding is necessary.
1571 Arg can be nil or a number. Nil and positive means hide, negative
1572 means show, 0 means toggle."
1576 (let ((hide (gnus-article-hidden-text-p type)))
1582 (gnus-article-show-hidden-text type))
1584 (if (eq hide 'hidden)
1585 (gnus-article-show-hidden-text type)
1588 (defun gnus-article-hidden-text-p (type)
1589 "Say whether the current buffer contains hidden text of type TYPE."
1590 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1592 (not (get-text-property pos 'invisible)))
1594 (text-property-any (1+ pos) (point-max) 'article-type type)))
1599 (defun gnus-article-show-hidden-text (type &optional hide)
1600 "Show all hidden text of type TYPE.
1601 If HIDE, hide the text instead."
1603 (let ((buffer-read-only nil)
1604 (inhibit-point-motion-hooks t)
1607 (while (setq beg (text-property-any end (point-max) 'article-type type))
1610 (text-property-not-all beg (point-max) 'article-type type)
1613 (gnus-article-hide-text beg end gnus-hidden-properties)
1614 (gnus-article-unhide-text beg end))
1618 (defconst article-time-units
1619 `((year . ,(* 365.25 24 60 60))
1620 (week . ,(* 7 24 60 60))
1621 (day . ,(* 24 60 60))
1625 "Mapping from time units to seconds.")
1627 (defun article-date-ut (&optional type highlight header)
1628 "Convert DATE date to universal time in the current article.
1629 If TYPE is `local', convert to local time; if it is `lapsed', output
1630 how much time has lapsed since DATE."
1631 (interactive (list 'ut t))
1632 (let* ((header (or header
1633 (mail-header-date (save-excursion
1634 (set-buffer gnus-summary-buffer)
1635 gnus-current-headers))
1636 (message-fetch-field "date")
1638 (date (if (vectorp header) (mail-header-date header)
1640 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1641 (inhibit-point-motion-hooks t)
1642 bface eface newline)
1643 (when (and date (not (string= date "")))
1646 (nnheader-narrow-to-headers)
1647 (let ((buffer-read-only nil))
1648 ;; Delete any old Date headers.
1649 (if (re-search-forward date-regexp nil t)
1651 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1652 eface (get-text-property (1- (gnus-point-at-eol))
1654 (delete-region (progn (beginning-of-line) (point))
1655 (progn (end-of-line) (point)))
1656 (beginning-of-line))
1657 (goto-char (point-max))
1659 (insert (article-make-date-line date type))
1662 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1663 (put-text-property (match-beginning 1) (1+ (match-end 1))
1665 (put-text-property (match-beginning 2) (match-end 2)
1669 (insert "\n"))))))))
1671 (defun article-make-date-line (date type)
1672 "Return a DATE line of TYPE."
1673 (let ((time (condition-case ()
1677 ;; Convert to the local timezone. We have to slap a
1678 ;; `condition-case' round the calls to the timezone
1679 ;; functions since they aren't particularly resistant to
1682 (let ((tz (car (current-time-zone))))
1683 (format "Date: %s %s%04d" (current-time-string time)
1684 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1685 ;; Convert to Universal Time.
1688 (current-time-string
1689 (let* ((e (parse-time-string date))
1690 (tm (apply 'encode-time e))
1692 (ls (- (cadr tm) (car (current-time-zone)))))
1693 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1694 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1697 ;; Get the original date from the article.
1698 ((eq type 'original)
1699 (concat "Date: " (if (string-match "\n+$" date)
1700 (substring date 0 (match-beginning 0))
1702 ;; Let the user define the format.
1704 (if (gnus-functionp gnus-article-time-format)
1705 (funcall gnus-article-time-format time)
1708 (format-time-string gnus-article-time-format time))))
1713 (format-time-string "%Y%M%DT%h%m%s" time)))
1714 ;; Do an X-Sent lapsed format.
1716 ;; If the date is seriously mangled, the timezone functions are
1717 ;; liable to bug out, so we ignore all errors.
1718 (let* ((now (current-time))
1719 (real-time (subtract-time now time))
1720 (real-sec (and real-time
1721 (+ (* (float (car real-time)) 65536)
1723 (sec (and real-time (abs real-sec)))
1733 ;; This is a bit convoluted, but basically we go
1734 ;; through the time units for years, weeks, etc,
1735 ;; and divide things to see whether that results
1736 ;; in positive answers.
1739 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1740 ;; The (remaining) seconds are too few to
1741 ;; be divided into this time unit.
1743 ;; It's big enough, so we output it.
1744 (setq sec (- sec (* num (cdr unit))))
1746 (concat (if prev ", " "") (int-to-string
1748 " " (symbol-name (car unit))
1749 (if (> num 1) "s" ""))
1751 article-time-units "")
1752 ;; If dates are odd, then it might appear like the
1753 ;; article was sent in the future.
1756 " in the future"))))))
1758 (error "Unknown conversion type: %s" type)))))
1760 (defun article-date-local (&optional highlight)
1761 "Convert the current article date to the local timezone."
1762 (interactive (list t))
1763 (article-date-ut 'local highlight))
1765 (defun article-date-original (&optional highlight)
1766 "Convert the current article date to what it was originally.
1767 This is only useful if you have used some other date conversion
1768 function and want to see what the date was before converting."
1769 (interactive (list t))
1770 (article-date-ut 'original highlight))
1772 (defun article-date-lapsed (&optional highlight)
1773 "Convert the current article date to time lapsed since it was sent."
1774 (interactive (list t))
1775 (article-date-ut 'lapsed highlight))
1777 (defun article-update-date-lapsed ()
1778 "Function to be run from a timer to update the lapsed time line."
1779 (let (deactivate-mark)
1784 (set-buffer (window-buffer w))
1785 (when (eq major-mode 'gnus-article-mode)
1786 (goto-char (point-min))
1787 (when (re-search-forward "^X-Sent:" nil t)
1788 (article-date-lapsed t))))
1791 (defun gnus-start-date-timer (&optional n)
1792 "Start a timer to update the X-Sent header in the article buffers.
1793 The numerical prefix says how frequently (in seconds) the function
1798 (gnus-stop-date-timer)
1799 (setq article-lapsed-timer
1800 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1802 (defun gnus-stop-date-timer ()
1803 "Stop the X-Sent timer."
1805 (when article-lapsed-timer
1806 (nnheader-cancel-timer article-lapsed-timer)
1807 (setq article-lapsed-timer nil)))
1809 (defun article-date-user (&optional highlight)
1810 "Convert the current article date to the user-defined format.
1811 This format is defined by the `gnus-article-time-format' variable."
1812 (interactive (list t))
1813 (article-date-ut 'user highlight))
1815 (defun article-date-iso8601 (&optional highlight)
1816 "Convert the current article date to ISO8601."
1817 (interactive (list t))
1818 (article-date-ut 'iso8601 highlight))
1820 (defun article-show-all ()
1821 "Show all hidden text in the article buffer."
1824 (let ((buffer-read-only nil))
1825 (gnus-article-unhide-text (point-min) (point-max)))))
1827 (defun article-emphasize (&optional arg)
1828 "Emphasize text according to `gnus-emphasis-alist'."
1829 (interactive (gnus-article-hidden-arg))
1830 (unless (gnus-article-check-hidden-text 'emphasis arg)
1832 (let ((alist gnus-emphasis-alist)
1833 (buffer-read-only nil)
1834 (props (append '(article-type emphasis)
1835 gnus-hidden-properties))
1836 regexp elem beg invisible visible face)
1839 (while (setq elem (pop alist))
1841 (setq regexp (car elem)
1842 invisible (nth 1 elem)
1843 visible (nth 2 elem)
1845 (while (re-search-forward regexp nil t)
1846 (when (and (match-beginning visible) (match-beginning invisible))
1847 (gnus-article-hide-text
1848 (match-beginning invisible) (match-end invisible) props)
1849 (gnus-article-unhide-text-type
1850 (match-beginning visible) (match-end visible) 'emphasis)
1851 (gnus-put-text-property-excluding-newlines
1852 (match-beginning visible) (match-end visible) 'face face)
1853 (goto-char (match-end invisible)))))))))
1855 (defvar gnus-summary-article-menu)
1856 (defvar gnus-summary-post-menu)
1858 ;;; Saving functions.
1860 (defun gnus-article-save (save-buffer file &optional num)
1861 "Save the currently selected article."
1862 (unless gnus-save-all-headers
1863 ;; Remove headers according to `gnus-saved-headers'.
1864 (let ((gnus-visible-headers
1865 (or gnus-saved-headers gnus-visible-headers))
1866 (gnus-article-buffer save-buffer))
1868 (set-buffer save-buffer)
1869 (article-hide-headers 1 t))))
1870 (save-window-excursion
1871 (if (not gnus-default-article-saver)
1872 (error "No default saver is defined")
1873 ;; !!! Magic! The saving functions all save
1874 ;; `gnus-save-article-buffer' (or so they think), but we
1875 ;; bind that variable to our save-buffer.
1876 (set-buffer gnus-article-buffer)
1877 (let* ((gnus-save-article-buffer save-buffer)
1880 ((not gnus-prompt-before-saving) 'default)
1881 ((eq gnus-prompt-before-saving 'always) nil)
1883 (gnus-number-of-articles-to-be-saved
1884 (when (eq gnus-prompt-before-saving t)
1886 (set-buffer gnus-article-current-summary)
1887 (funcall gnus-default-article-saver filename)))))
1889 (defun gnus-read-save-file-name (prompt &optional filename
1890 function group headers variable)
1892 (funcall function group headers (symbol-value variable)))
1897 ((eq filename 'default)
1903 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1906 (if (and gnus-number-of-articles-to-be-saved
1907 (> gnus-number-of-articles-to-be-saved 1))
1908 (format "these %d articles"
1909 gnus-number-of-articles-to-be-saved)
1912 ;; Let the split methods have their say.
1914 ;; No split name was found.
1917 (concat prompt " (default "
1918 (file-name-nondirectory default-name) ") ")
1919 (file-name-directory default-name)
1921 ;; A single group name is returned.
1922 ((stringp split-name)
1924 (funcall function split-name headers
1925 (symbol-value variable)))
1927 (concat prompt " (default "
1928 (file-name-nondirectory default-name) ") ")
1929 (file-name-directory default-name)
1931 ;; A single split name was found
1932 ((= 1 (length split-name))
1933 (let* ((name (expand-file-name
1934 (car split-name) gnus-article-save-directory))
1935 (dir (cond ((file-directory-p name)
1936 (file-name-as-directory name))
1937 ((file-exists-p name) name)
1938 (t gnus-article-save-directory))))
1940 (concat prompt " (default " name ") ")
1942 ;; A list of splits was found.
1944 (setq split-name (nreverse split-name))
1946 (let ((file-name-history
1947 (nconc split-name file-name-history)))
1951 (concat prompt " (`M-p' for defaults) ")
1952 gnus-article-save-directory
1954 gnus-article-save-directory)))
1955 (car (push result file-name-history)))))))
1956 ;; Create the directory.
1957 (gnus-make-directory (file-name-directory file))
1958 ;; If we have read a directory, we append the default file name.
1959 (when (file-directory-p file)
1960 (setq file (concat (file-name-as-directory file)
1961 (file-name-nondirectory default-name))))
1962 ;; Possibly translate some characters.
1963 (nnheader-translate-file-chars file)))))
1964 (gnus-make-directory (file-name-directory result))
1965 (set variable result)))
1967 (defun gnus-article-archive-name (group)
1968 "Return the first instance of an \"Archive-name\" in the current buffer."
1969 (let ((case-fold-search t))
1970 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1971 (nnheader-concat gnus-article-save-directory
1972 (match-string 1)))))
1974 (defun gnus-article-nndoc-name (group)
1975 "If GROUP is an nndoc group, return the name of the parent group."
1976 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1977 (gnus-group-get-parameter group 'save-article-group)))
1979 (defun gnus-summary-save-in-rmail (&optional filename)
1980 "Append this article to Rmail file.
1981 Optional argument FILENAME specifies file name.
1982 Directory to save to is default to `gnus-article-save-directory'."
1983 (setq filename (gnus-read-save-file-name
1984 "Save %s in rmail file:" filename
1985 gnus-rmail-save-name gnus-newsgroup-name
1986 gnus-current-headers 'gnus-newsgroup-last-rmail))
1987 (gnus-eval-in-buffer-window gnus-save-article-buffer
1991 (gnus-output-to-rmail filename))))
1994 (defun gnus-summary-save-in-mail (&optional filename)
1995 "Append this article to Unix mail file.
1996 Optional argument FILENAME specifies file name.
1997 Directory to save to is default to `gnus-article-save-directory'."
1998 (setq filename (gnus-read-save-file-name
1999 "Save %s in Unix mail file:" filename
2000 gnus-mail-save-name gnus-newsgroup-name
2001 gnus-current-headers 'gnus-newsgroup-last-mail))
2002 (gnus-eval-in-buffer-window gnus-save-article-buffer
2006 (if (and (file-readable-p filename)
2007 (mail-file-babyl-p filename))
2008 (rmail-output-to-rmail-file filename t)
2009 (gnus-output-to-mail filename)))))
2012 (defun gnus-summary-save-in-file (&optional filename overwrite)
2013 "Append this article to file.
2014 Optional argument FILENAME specifies file name.
2015 Directory to save to is default to `gnus-article-save-directory'."
2016 (setq filename (gnus-read-save-file-name
2017 "Save %s in file:" filename
2018 gnus-file-save-name gnus-newsgroup-name
2019 gnus-current-headers 'gnus-newsgroup-last-file))
2020 (gnus-eval-in-buffer-window gnus-save-article-buffer
2024 (when (and overwrite
2025 (file-exists-p filename))
2026 (delete-file filename))
2027 (gnus-output-to-file filename))))
2030 (defun gnus-summary-write-to-file (&optional filename)
2031 "Write this article to a file.
2032 Optional argument FILENAME specifies file name.
2033 The directory to save in defaults to `gnus-article-save-directory'."
2034 (gnus-summary-save-in-file nil t))
2036 (defun gnus-summary-save-body-in-file (&optional filename)
2037 "Append this article body to a file.
2038 Optional argument FILENAME specifies file name.
2039 The directory to save in defaults to `gnus-article-save-directory'."
2040 (setq filename (gnus-read-save-file-name
2041 "Save %s body in file:" filename
2042 gnus-file-save-name gnus-newsgroup-name
2043 gnus-current-headers 'gnus-newsgroup-last-file))
2044 (gnus-eval-in-buffer-window gnus-save-article-buffer
2048 (when (article-goto-body)
2049 (narrow-to-region (point) (point-max)))
2050 (gnus-output-to-file filename))))
2053 (defun gnus-summary-save-in-pipe (&optional command)
2054 "Pipe this article to subprocess."
2056 (cond ((and (eq command 'default)
2057 gnus-last-shell-command)
2058 gnus-last-shell-command)
2062 "Shell command on %s: "
2063 (if (and gnus-number-of-articles-to-be-saved
2064 (> gnus-number-of-articles-to-be-saved 1))
2065 (format "these %d articles"
2066 gnus-number-of-articles-to-be-saved)
2068 gnus-last-shell-command))))
2069 (when (string-equal command "")
2070 (setq command gnus-last-shell-command))
2071 (gnus-eval-in-buffer-window gnus-article-buffer
2074 (shell-command-on-region (point-min) (point-max) command nil)))
2075 (setq gnus-last-shell-command command))
2077 ;;; Article file names when saving.
2079 (defun gnus-capitalize-newsgroup (newsgroup)
2080 "Capitalize NEWSGROUP name."
2081 (when (not (zerop (length newsgroup)))
2082 (concat (char-to-string (upcase (aref newsgroup 0)))
2083 (substring newsgroup 1))))
2085 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2086 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2087 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2088 Otherwise, it is like ~/News/news/group/num."
2091 (concat (if (gnus-use-long-file-name 'not-save)
2092 (gnus-capitalize-newsgroup newsgroup)
2093 (gnus-newsgroup-directory-form newsgroup))
2094 "/" (int-to-string (mail-header-number headers)))
2095 gnus-article-save-directory)))
2097 (string-equal (file-name-directory default)
2098 (file-name-directory last-file))
2099 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2101 (or last-file default))))
2103 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2104 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2105 If variable `gnus-use-long-file-name' is non-nil, it is
2106 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2109 (concat (if (gnus-use-long-file-name 'not-save)
2111 (gnus-newsgroup-directory-form newsgroup))
2112 "/" (int-to-string (mail-header-number headers)))
2113 gnus-article-save-directory)))
2115 (string-equal (file-name-directory default)
2116 (file-name-directory last-file))
2117 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2119 (or last-file default))))
2121 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2122 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2123 If variable `gnus-use-long-file-name' is non-nil, it is
2124 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2127 (if (gnus-use-long-file-name 'not-save)
2128 (gnus-capitalize-newsgroup newsgroup)
2129 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2130 gnus-article-save-directory)))
2132 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2133 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2134 If variable `gnus-use-long-file-name' is non-nil, it is
2135 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2138 (if (gnus-use-long-file-name 'not-save)
2140 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2141 gnus-article-save-directory)))
2148 (setq afunc (car func)
2151 gfunc (intern (format "gnus-%s" func))))
2153 (if (not (fboundp afunc))
2155 `(lambda (&optional interactive &rest args)
2156 ,(documentation afunc t)
2157 (interactive (list t))
2159 (set-buffer gnus-article-buffer)
2161 (call-interactively ',afunc)
2162 (apply ',afunc args))))))))
2163 '(article-hide-headers
2164 article-hide-boring-headers
2165 article-treat-overstrike
2166 (article-fill . gnus-article-word-wrap)
2168 article-display-x-face
2169 article-de-quoted-unreadable
2170 article-mime-decode-quoted-printable
2173 article-hide-signature
2174 article-remove-trailing-blank-lines
2175 article-strip-leading-blank-lines
2176 article-strip-multiple-blank-lines
2177 article-strip-leading-space
2178 article-strip-trailing-space
2179 article-strip-blank-lines
2180 article-strip-all-blank-lines
2182 article-date-iso8601
2183 article-date-original
2185 article-decode-mime-words
2186 article-decode-charset
2187 article-decode-encoded-words
2191 article-treat-dumbquotes
2192 article-normalize-headers
2193 (article-show-all . gnus-article-show-all-headers))))
2196 ;;; Gnus article mode
2199 (put 'gnus-article-mode 'mode-class 'special)
2201 (set-keymap-parent gnus-article-mode-map widget-keymap)
2203 (gnus-define-keys gnus-article-mode-map
2204 " " gnus-article-goto-next-page
2205 "\177" gnus-article-goto-prev-page
2206 [delete] gnus-article-goto-prev-page
2207 "\C-c^" gnus-article-refer-article
2208 "h" gnus-article-show-summary
2209 "s" gnus-article-show-summary
2210 "\C-c\C-m" gnus-article-mail
2211 "?" gnus-article-describe-briefly
2212 "e" gnus-article-edit
2213 "<" beginning-of-buffer
2215 "\C-c\C-i" gnus-info-find-node
2218 "\C-d" gnus-article-read-summary-keys
2219 "\M-*" gnus-article-read-summary-keys
2220 "\M-#" gnus-article-read-summary-keys
2221 "\M-^" gnus-article-read-summary-keys
2222 "\M-g" gnus-article-read-summary-keys)
2224 (substitute-key-definition
2225 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2227 (defun gnus-article-make-menu-bar ()
2228 (gnus-turn-off-edit-menu 'article)
2229 (unless (boundp 'gnus-article-article-menu)
2231 gnus-article-article-menu gnus-article-mode-map ""
2233 ["Scroll forwards" gnus-article-goto-next-page t]
2234 ["Scroll backwards" gnus-article-goto-prev-page t]
2235 ["Show summary" gnus-article-show-summary t]
2236 ["Fetch Message-ID at point" gnus-article-refer-article t]
2237 ["Mail to address at point" gnus-article-mail t]
2238 ["Send a bug report" gnus-bug t]))
2241 gnus-article-treatment-menu gnus-article-mode-map ""
2243 ["Hide headers" gnus-article-hide-headers t]
2244 ["Hide signature" gnus-article-hide-signature t]
2245 ["Hide citation" gnus-article-hide-citation t]
2246 ["Treat overstrike" gnus-article-treat-overstrike t]
2247 ["Remove carriage return" gnus-article-remove-cr t]
2248 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2250 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2252 (when (boundp 'gnus-summary-post-menu)
2253 (define-key gnus-article-mode-map [menu-bar post]
2254 (cons "Post" gnus-summary-post-menu)))
2256 (gnus-run-hooks 'gnus-article-menu-hook)))
2258 (defun gnus-article-mode ()
2259 "Major mode for displaying an article.
2261 All normal editing commands are switched off.
2263 The following commands are available in addition to all summary mode
2265 \\<gnus-article-mode-map>
2266 \\[gnus-article-next-page]\t Scroll the article one page forwards
2267 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2268 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2269 \\[gnus-article-show-summary]\t Display the summary buffer
2270 \\[gnus-article-mail]\t Send a reply to the address near point
2271 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2272 \\[gnus-info-find-node]\t Go to the Gnus info node"
2274 (when (gnus-visual-p 'article-menu 'menu)
2275 (gnus-article-make-menu-bar))
2276 (gnus-simplify-mode-line)
2277 (setq mode-name "Article")
2278 (setq major-mode 'gnus-article-mode)
2279 (make-local-variable 'minor-mode-alist)
2280 (use-local-map gnus-article-mode-map)
2281 (gnus-update-format-specifications nil 'article-mode)
2282 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2283 (make-local-variable 'gnus-page-broken)
2284 (make-local-variable 'gnus-button-marker-list)
2285 (make-local-variable 'gnus-article-current-summary)
2286 (make-local-variable 'gnus-article-mime-handles)
2287 (make-local-variable 'gnus-article-decoded-p)
2288 (make-local-variable 'gnus-article-mime-handle-alist)
2289 (gnus-set-default-directory)
2290 (buffer-disable-undo)
2291 (setq buffer-read-only t)
2292 (set-syntax-table gnus-article-mode-syntax-table)
2293 (mm-enable-multibyte)
2294 (gnus-run-hooks 'gnus-article-mode-hook))
2296 (defun gnus-article-setup-buffer ()
2297 "Initialize the article buffer."
2298 (let* ((name (if gnus-single-article-buffer "*Article*"
2299 (concat "*Article " gnus-newsgroup-name "*")))
2301 (progn (string-match "\\*Article" name)
2302 (concat " *Original Article"
2303 (substring name (match-end 0))))))
2304 (setq gnus-article-buffer name)
2305 (setq gnus-original-article-buffer original)
2306 (setq gnus-article-mime-handle-alist nil)
2307 ;; This might be a variable local to the summary buffer.
2308 (unless gnus-single-article-buffer
2310 (set-buffer gnus-summary-buffer)
2311 (setq gnus-article-buffer name)
2312 (setq gnus-original-article-buffer original)
2313 (gnus-set-global-variables)))
2314 ;; Init original article buffer.
2316 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2317 (mm-enable-multibyte)
2318 (setq major-mode 'gnus-original-article-mode)
2319 (make-local-variable 'gnus-original-article))
2320 (if (get-buffer name)
2323 (buffer-disable-undo)
2324 (setq buffer-read-only t)
2325 (unless (eq major-mode 'gnus-article-mode)
2326 (gnus-article-mode))
2329 (set-buffer (gnus-get-buffer-create name))
2331 (make-local-variable 'gnus-summary-buffer)
2332 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2333 (current-buffer)))))
2335 ;; Set article window start at LINE, where LINE is the number of lines
2336 ;; from the head of the article.
2337 (defun gnus-article-set-window-start (&optional line)
2339 (get-buffer-window gnus-article-buffer t)
2341 (set-buffer gnus-article-buffer)
2342 (goto-char (point-min))
2345 (gnus-message 6 "Moved to bookmark")
2346 (search-forward "\n\n" nil t)
2350 (defun gnus-article-prepare (article &optional all-headers header)
2351 "Prepare ARTICLE in article mode buffer.
2352 ARTICLE should either be an article number or a Message-ID.
2353 If ARTICLE is an id, HEADER should be the article headers.
2354 If ALL-HEADERS is non-nil, no headers are hidden."
2356 ;; Make sure we start in a summary buffer.
2357 (unless (eq major-mode 'gnus-summary-mode)
2358 (set-buffer gnus-summary-buffer))
2359 (setq gnus-summary-buffer (current-buffer))
2360 (let* ((gnus-article (if header (mail-header-number header) article))
2361 (summary-buffer (current-buffer))
2362 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2363 (group gnus-newsgroup-name)
2366 (gnus-article-setup-buffer)
2367 (set-buffer gnus-article-buffer)
2368 ;; Deactivate active regions.
2369 (when (and (boundp 'transient-mark-mode)
2370 transient-mark-mode)
2371 (setq mark-active nil))
2372 (if (not (setq result (let ((buffer-read-only nil))
2373 (gnus-request-article-this-buffer
2375 ;; There is no such article.
2377 (when (and (numberp article)
2378 (not (memq article gnus-newsgroup-sparse)))
2379 (setq gnus-article-current
2380 (cons gnus-newsgroup-name article))
2381 (set-buffer gnus-summary-buffer)
2382 (setq gnus-current-article article)
2383 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2385 (gnus-summary-set-agent-mark article)
2386 (message "Message marked for downloading"))
2387 (gnus-summary-mark-article article gnus-canceled-mark)
2388 (unless (memq article gnus-newsgroup-sparse)
2390 "No such article (may have expired or been canceled)")))))
2391 (if (or (eq result 'pseudo)
2392 (eq result 'nneething))
2395 (set-buffer summary-buffer)
2396 (push article gnus-newsgroup-history)
2397 (setq gnus-last-article gnus-current-article
2398 gnus-current-article 0
2399 gnus-current-headers nil
2400 gnus-article-current nil)
2401 (if (eq result 'nneething)
2402 (gnus-configure-windows 'summary)
2403 (gnus-configure-windows 'article))
2404 (gnus-set-global-variables))
2405 (let ((gnus-article-mime-handle-alist-1
2406 gnus-article-mime-handle-alist))
2407 (gnus-set-mode-line 'article)))
2408 ;; The result from the `request' was an actual article -
2409 ;; or at least some text that is now displayed in the
2411 (when (and (numberp article)
2412 (not (eq article gnus-current-article)))
2413 ;; Seems like a new article has been selected.
2414 ;; `gnus-current-article' must be an article number.
2416 (set-buffer summary-buffer)
2417 (push article gnus-newsgroup-history)
2418 (setq gnus-last-article gnus-current-article
2419 gnus-current-article article
2420 gnus-current-headers
2421 (gnus-summary-article-header gnus-current-article)
2422 gnus-article-current
2423 (cons gnus-newsgroup-name gnus-current-article))
2424 (unless (vectorp gnus-current-headers)
2425 (setq gnus-current-headers nil))
2426 (gnus-summary-goto-subject gnus-current-article)
2427 (when (gnus-summary-show-thread)
2428 ;; If the summary buffer really was folded, the
2429 ;; previous goto may not actually have gone to
2430 ;; the right article, but the thread root instead.
2432 (gnus-summary-goto-subject gnus-current-article))
2433 (gnus-run-hooks 'gnus-mark-article-hook)
2434 (gnus-set-mode-line 'summary)
2435 (when (gnus-visual-p 'article-highlight 'highlight)
2436 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2437 ;; Set the global newsgroup variables here.
2438 ;; Suggested by Jim Sisolak
2439 ;; <sisolak@trans4.neep.wisc.edu>.
2440 (gnus-set-global-variables)
2441 (setq gnus-have-all-headers
2442 (or all-headers gnus-show-all-headers))))
2443 (when (or (numberp article)
2445 (gnus-article-prepare-display)
2447 (goto-char (point-min))
2448 (setq gnus-page-broken
2449 (when gnus-break-pages
2450 (gnus-narrow-to-page)
2452 (let ((gnus-article-mime-handle-alist-1
2453 gnus-article-mime-handle-alist))
2454 (gnus-set-mode-line 'article))
2455 (gnus-configure-windows 'article)
2457 (set-window-point (get-buffer-window (current-buffer)) (point))
2461 (defun gnus-article-prepare-display ()
2462 "Make the current buffer look like a nice article."
2463 ;; Hooks for getting information from the article.
2464 ;; This hook must be called before being narrowed.
2465 (let ((gnus-article-buffer (current-buffer))
2467 (unless (eq major-mode 'gnus-article-mode)
2468 (gnus-article-mode))
2469 (setq buffer-read-only nil)
2470 (gnus-run-hooks 'gnus-tmp-internal-hook)
2471 (gnus-run-hooks 'gnus-article-prepare-hook)
2472 (when gnus-display-mime-function
2473 (funcall gnus-display-mime-function))))
2476 ;;; Gnus MIME viewing functions
2479 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2480 "The following specs can be used:
2482 %T MIME type, along with additional info
2483 %n The `name' parameter
2484 %d The description, if any
2485 %l The length of the encoded part
2486 %p The part identifier number
2487 %e Dots if the part isn't displayed")
2489 (defvar gnus-mime-button-line-format-alist
2490 '((?t gnus-tmp-type ?s)
2491 (?T gnus-tmp-type-long ?s)
2492 (?n gnus-tmp-name ?s)
2493 (?d gnus-tmp-description ?s)
2495 (?l gnus-tmp-length ?d)
2496 (?e gnus-tmp-dots ?s)))
2498 (defvar gnus-mime-button-commands
2499 '((gnus-article-press-button "\r" "Toggle Display")
2500 (gnus-mime-view-part "v" "View Interactively...")
2501 (gnus-mime-save-part "o" "Save...")
2502 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2503 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2504 (gnus-mime-internalize-part "E" "View Internally")
2505 (gnus-mime-externalize-part "e" "View Externally")
2506 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2508 (defun gnus-article-mime-part-status ()
2509 (if gnus-article-mime-handle-alist-1
2510 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2513 (defvar gnus-mime-button-map nil)
2514 (unless gnus-mime-button-map
2515 (setq gnus-mime-button-map (make-sparse-keymap))
2516 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2517 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2518 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2520 (define-key gnus-mime-button-map (cadr c) (car c)))
2521 gnus-mime-button-commands))
2523 (defun gnus-mime-button-menu (event)
2524 "Construct a context-sensitive menu of MIME commands."
2527 (let ((pos (event-start event)))
2528 (set-buffer (window-buffer (posn-window pos)))
2529 (goto-char (posn-point pos))
2530 (gnus-article-check-buffer)
2531 (let ((response (x-popup-menu
2533 ("" ,@(mapcar (lambda (c)
2534 (cons (caddr c) (car c)))
2535 gnus-mime-button-commands))))))
2537 (funcall response))))))
2539 (defun gnus-mime-view-all-parts (&optional handles)
2540 "View all the MIME parts."
2542 (save-current-buffer
2543 (set-buffer gnus-article-buffer)
2544 (let ((handles (or handles gnus-article-mime-handles))
2545 (mail-parse-charset gnus-newsgroup-charset))
2546 (if (stringp (car handles))
2547 (gnus-mime-view-all-parts (cdr handles))
2548 (mapcar 'mm-display-part handles)))))
2550 (defun gnus-mime-save-part ()
2551 "Save the MIME part under point."
2553 (gnus-article-check-buffer)
2554 (let ((data (get-text-property (point) 'gnus-data)))
2555 (mm-save-part data)))
2557 (defun gnus-mime-pipe-part ()
2558 "Pipe the MIME part under point to a process."
2560 (gnus-article-check-buffer)
2561 (let ((data (get-text-property (point) 'gnus-data)))
2562 (mm-pipe-part data)))
2564 (defun gnus-mime-view-part ()
2565 "Interactively choose a view method for the MIME part under point."
2567 (gnus-article-check-buffer)
2568 (let ((data (get-text-property (point) 'gnus-data)))
2569 (mm-interactively-view-part data)))
2571 (defun gnus-mime-copy-part (&optional handle)
2572 "Put the the MIME part under point into a new buffer."
2574 (gnus-article-check-buffer)
2575 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2576 (contents (mm-get-part handle))|
2577 (base (file-name-nondirectory
2579 (mail-content-type-get (mm-handle-type handle) 'name)
2580 (mail-content-type-get (mm-handle-type handle)
2583 (buffer (generate-new-buffer base)))
2584 (switch-to-buffer buffer)
2586 ;; We do it this way to make `normal-mode' set the appropriate mode.
2589 (setq buffer-file-name (expand-file-name base))
2591 (setq buffer-file-name nil))
2592 (goto-char (point-min))))
2594 (defun gnus-mime-inline-part (&optional charset)
2595 "Insert the MIME part under point into the current buffer."
2596 (interactive "P") ; For compatibility reasons we are not using "z".
2597 (gnus-article-check-buffer)
2598 (let* ((data (get-text-property (point) 'gnus-data))
2602 (if (mm-handle-undisplayer data)
2603 (mm-remove-part data)
2604 (setq contents (mm-get-part data))
2607 (unless (symbolp charset)
2608 (setq charset (mm-read-coding-system "Charset: ")))
2609 (setq contents (mm-decode-coding-string contents charset)))
2610 (mm-insert-inline data contents)
2613 (defun gnus-mime-externalize-part (&optional handle)
2614 "View the MIME part under point with an external viewer."
2616 (gnus-article-check-buffer)
2617 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2618 (mm-user-display-methods nil)
2619 (mm-all-images-fit t)
2620 (mail-parse-charset gnus-newsgroup-charset))
2621 (if (mm-handle-undisplayer handle)
2622 (mm-remove-part handle)
2623 (mm-display-part handle))))
2625 (defun gnus-mime-internalize-part (&optional handle)
2626 "View the MIME part under point with an internal viewer."
2628 (gnus-article-check-buffer)
2629 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2630 (mm-user-display-methods '((".*" . inline)))
2631 (mm-all-images-fit t)
2632 (mail-parse-charset gnus-newsgroup-charset))
2633 (if (mm-handle-undisplayer handle)
2634 (mm-remove-part handle)
2635 (mm-display-part handle))))
2637 (defun gnus-article-part-wrapper (n function)
2638 (save-current-buffer
2639 (set-buffer gnus-article-buffer)
2640 (when (> n (length gnus-article-mime-handle-alist))
2641 (error "No such part"))
2642 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2643 (funcall function handle))))
2645 (defun gnus-article-pipe-part (n)
2646 "Pipe MIME part N, which is the numerical prefix."
2648 (gnus-article-part-wrapper n 'mm-pipe-part))
2650 (defun gnus-article-save-part (n)
2651 "Save MIME part N, which is the numerical prefix."
2653 (gnus-article-part-wrapper n 'mm-save-part))
2655 (defun gnus-article-interactively-view-part (n)
2656 "Pipe MIME part N, which is the numerical prefix."
2658 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2660 (defun gnus-article-copy-part (n)
2661 "Pipe MIME part N, which is the numerical prefix."
2663 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2665 (defun gnus-article-externalize-part (n)
2666 "Pipe MIME part N, which is the numerical prefix."
2668 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2670 (defun gnus-article-view-part (n)
2671 "View MIME part N, which is the numerical prefix."
2673 (save-current-buffer
2674 (set-buffer gnus-article-buffer)
2675 (when (> n (length gnus-article-mime-handle-alist))
2676 (error "No such part"))
2677 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2678 (when (gnus-article-goto-part n)
2679 (if (equal (car handle) "multipart/alternative")
2680 (gnus-article-press-button)
2681 (when (eq (gnus-mm-display-part handle) 'internal)
2682 (gnus-set-window-start)))))))
2684 (defun gnus-mm-display-part (handle)
2685 "Display HANDLE and fix MIME button."
2686 (let ((id (get-text-property (point) 'gnus-part))
2691 (let ((window (selected-window))
2692 (mail-parse-charset gnus-newsgroup-charset))
2695 (let ((win (get-buffer-window (current-buffer) t))
2698 (select-window win))
2701 (if (mm-handle-displayed-p handle)
2702 ;; This will remove the part.
2703 (mm-display-part handle)
2705 (narrow-to-region (point) (1+ (point)))
2706 (mm-display-part handle)
2709 (1- (length gnus-article-mime-handles))
2710 (car (mm-handle-type handle))))))
2711 (select-window window))))
2713 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2714 (gnus-insert-mime-button
2715 handle id (list (mm-handle-displayed-p handle)))
2716 (goto-char point))))
2718 (defun gnus-article-goto-part (n)
2719 "Go to MIME part N."
2720 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2722 (goto-char point))))
2724 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2725 (let ((gnus-tmp-name
2726 (or (mail-content-type-get (mm-handle-type handle)
2728 (mail-content-type-get (mm-handle-disposition handle)
2731 (gnus-tmp-type (car (mm-handle-type handle)))
2732 (gnus-tmp-description
2733 (mail-decode-encoded-word-string (or (mm-handle-description handle)
2736 (if (if displayed (car displayed)
2737 (mm-handle-displayed-p handle))
2739 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2741 gnus-tmp-type-long b e)
2742 (when (string-match ".*/" gnus-tmp-name)
2743 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2744 (setq gnus-tmp-type-long (concat gnus-tmp-type
2745 (and (not (equal gnus-tmp-name ""))
2746 (concat "; " gnus-tmp-name))))
2747 (or (equal gnus-tmp-description "")
2748 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2753 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2754 `(local-map ,gnus-mime-button-map
2755 keymap ,gnus-mime-button-map
2756 gnus-callback gnus-mm-display-part
2757 gnus-part ,gnus-tmp-id
2758 article-type annotation
2761 (widget-convert-button 'link b e
2763 :action 'gnus-widget-press-button
2764 :button-keymap gnus-mime-button-map
2767 ;; Needed to properly clear the message
2768 ;; due to a bug in wid-edit
2769 (setq help-echo-owns-message t)
2771 "Click to %s the MIME part; %s for more options"
2772 (if (mm-handle-displayed-p
2773 (widget-get widget :mime-handle))
2775 (if gnus-xemacs "button3" "mouse-3"))))))
2777 (defun gnus-widget-press-button (elems el)
2778 (goto-char (widget-get elems :from))
2779 (gnus-article-press-button))
2781 (defun gnus-display-mime (&optional ihandles)
2782 "Display the MIME parts."
2784 (save-selected-window
2785 (let ((window (get-buffer-window gnus-article-buffer))
2788 (select-window window)
2789 ;; We have to do this since selecting the window
2790 ;; may change the point. So we set the window point.
2791 (set-window-point window point)))
2792 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2793 handle name type b e display)
2795 ;; Top-level call; we clean up.
2796 (mm-destroy-parts gnus-article-mime-handles)
2797 (setq gnus-article-mime-handles handles
2798 gnus-article-mime-handle-alist nil)
2799 ;; We allow users to glean info from the handles.
2800 (when gnus-article-mime-part-function
2801 (gnus-mime-part-function handles)))
2803 (or (not (stringp (car handles)))
2807 ;; Clean up for mime parts.
2809 (delete-region (point) (point-max)))
2810 (gnus-mime-display-part handles))
2813 (narrow-to-region (point) (point-max))
2814 (gnus-treat-article nil 1 1)))
2815 ;; Highlight the headers.
2819 (narrow-to-region (point-min) (point))
2820 (gnus-treat-article 'head)))))))
2822 (defvar gnus-mime-display-multipart-as-mixed nil)
2824 (defun gnus-mime-display-part (handle)
2827 ((not (stringp (car handle)))
2828 (gnus-mime-display-single handle))
2829 ;; multipart/alternative
2830 ((and (equal (car handle) "multipart/alternative")
2831 (not gnus-mime-display-multipart-as-mixed))
2832 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2833 (push (cons id handle) gnus-article-mime-handle-alist)
2834 (gnus-mime-display-alternative (cdr handle) nil nil id)))
2835 ;; multipart/related
2836 ((and (equal (car handle) "multipart/related")
2837 (not gnus-mime-display-multipart-as-mixed))
2838 ;;;!!!We should find the start part, but we just default
2839 ;;;!!!to the first part.
2840 (gnus-mime-display-part (cadr handle)))
2841 ;; Other multiparts are handled like multipart/mixed.
2843 (gnus-mime-display-mixed (cdr handle)))))
2845 (defun gnus-mime-part-function (handles)
2846 (if (stringp (car handles))
2847 (mapcar 'gnus-mime-part-function (cdr handles))
2848 (funcall gnus-article-mime-part-function handles)))
2850 (defun gnus-mime-display-mixed (handles)
2851 (mapcar 'gnus-mime-display-part handles))
2853 (defun gnus-mime-display-single (handle)
2854 (let ((type (car (mm-handle-type handle)))
2855 (ignored gnus-ignored-mime-types)
2862 (when (string-match (pop ignored) type)
2863 (throw 'ignored nil)))
2864 (if (and (setq not-attachment
2865 (or (not (mm-handle-disposition handle))
2866 (equal (car (mm-handle-disposition handle))
2868 (mm-automatic-display-p type)
2869 (or (mm-inlinable-part-p type)
2870 (mm-automatic-external-display-p type)))
2872 (when (equal (car (split-string type "/"))
2875 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2876 (push (cons id handle) gnus-article-mime-handle-alist)
2877 (when (or (not display)
2878 (not (gnus-unbuttonized-mime-type-p type)))
2879 (gnus-article-insert-newline)
2880 (gnus-insert-mime-button
2881 handle id (list (or display (and not-attachment text))))
2882 (gnus-article-insert-newline)
2883 (gnus-article-insert-newline)
2885 (let ((beg (point)))
2890 (let ((mail-parse-charset gnus-newsgroup-charset))
2891 (mm-display-part handle t))
2892 (goto-char (point-max)))
2893 ((and text not-attachment)
2896 (gnus-article-insert-newline)
2897 (mm-insert-inline handle (mm-get-part handle))
2898 (goto-char (point-max))))
2902 (narrow-to-region beg (point))
2904 nil (length gnus-article-mime-handle-alist)
2905 (1- (length gnus-article-mime-handles))
2906 (car (mm-handle-type handle))))))))))
2908 (defun gnus-unbuttonized-mime-type-p (type)
2909 "Say whether TYPE is to be unbuttonized."
2910 (unless gnus-inhibit-mime-unbuttonizing
2912 (let ((types gnus-unbuttonized-mime-types))
2914 (when (string-match (pop types) type)
2915 (throw 'found t)))))))
2917 (defun gnus-article-insert-newline ()
2918 "Insert a newline, but mark it as undeletable."
2919 (gnus-put-text-property
2920 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2922 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2923 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2926 handle buffer-read-only from props begend not-pref)
2927 (save-window-excursion
2930 (narrow-to-region (car ibegend)
2933 (goto-char (car ibegend))
2936 (delete-region (point-min) (point-max))
2937 (mm-remove-parts handles))
2938 (setq begend (list (point-marker)))
2940 (unless (setq not-pref (cadr (member preferred ihandles)))
2941 (setq not-pref (car ihandles)))
2943 (not (gnus-unbuttonized-mime-type-p
2944 "multipart/alternative")))
2945 (gnus-add-text-properties
2948 (insert (format "%d. " id))
2952 (unless ,(not ibegend)
2953 (setq gnus-article-mime-handle-alist
2954 ',gnus-article-mime-handle-alist))
2955 (gnus-mime-display-alternative
2956 ',ihandles ',not-pref ',begend ,id))
2957 local-map ,gnus-mime-button-map
2958 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2959 face ,gnus-article-button-face
2960 keymap ,gnus-mime-button-map
2963 (widget-convert-button 'link from (point)
2964 :action 'gnus-widget-press-button
2965 :button-keymap gnus-widget-button-keymap)
2967 (while (setq handle (pop handles))
2968 (gnus-add-text-properties
2971 (insert (format "(%c) %-18s"
2972 (if (equal handle preferred) ?* ? )
2973 (if (stringp (car handle))
2975 (car (mm-handle-type handle)))))
2979 (unless ,(not ibegend)
2980 (setq gnus-article-mime-handle-alist
2981 ',gnus-article-mime-handle-alist))
2982 (gnus-mime-display-alternative
2983 ',ihandles ',handle ',begend ,id))
2984 local-map ,gnus-mime-button-map
2985 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2986 face ,gnus-article-button-face
2987 keymap ,gnus-mime-button-map
2990 (widget-convert-button 'link from (point)
2991 :action 'gnus-widget-press-button
2992 :button-keymap gnus-widget-button-keymap)
2996 (if (stringp (car preferred))
2997 (gnus-display-mime preferred)
2998 (let ((mail-parse-charset gnus-newsgroup-charset))
2999 (mm-display-part preferred)))
3000 (goto-char (point-max))
3001 (setcdr begend (point-marker)))))
3003 (goto-char point))))
3005 (defun gnus-article-wash-status ()
3006 "Return a string which display status of article washing."
3008 (set-buffer gnus-article-buffer)
3009 (let ((cite (gnus-article-hidden-text-p 'cite))
3010 (headers (gnus-article-hidden-text-p 'headers))
3011 (boring (gnus-article-hidden-text-p 'boring-headers))
3012 (pgp (gnus-article-hidden-text-p 'pgp))
3013 (pem (gnus-article-hidden-text-p 'pem))
3014 (signature (gnus-article-hidden-text-p 'signature))
3015 (overstrike (gnus-article-hidden-text-p 'overstrike))
3016 (emphasis (gnus-article-hidden-text-p 'emphasis)))
3017 (format "%c%c%c%c%c%c"
3019 (if (or headers boring) ?h ? )
3020 (if (or pgp pem) ?p ? )
3021 (if signature ?s ? )
3022 (if overstrike ?o ? )
3023 (if emphasis ?e ? )))))
3025 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3027 (defun gnus-article-maybe-hide-headers ()
3028 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3029 Provided for backwards compatibility."
3030 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3031 (not (save-excursion (set-buffer gnus-summary-buffer)
3032 gnus-have-all-headers)))
3033 (not gnus-inhibit-hiding))
3034 (gnus-article-hide-headers)))
3038 (defun gnus-output-to-file (file-name)
3039 "Append the current article to a file named FILE-NAME."
3040 (let ((artbuf (current-buffer)))
3042 (insert-buffer-substring artbuf)
3043 ;; Append newline at end of the buffer as separator, and then
3045 (goto-char (point-max))
3047 (append-to-file (point-min) (point-max) file-name)
3050 (defun gnus-narrow-to-page (&optional arg)
3051 "Narrow the article buffer to a page.
3052 If given a numerical ARG, move forward ARG pages."
3054 (setq arg (if arg (prefix-numeric-value arg) 0))
3056 (set-buffer gnus-article-buffer)
3057 (goto-char (point-min))
3059 ;; Remove any old next/prev buttons.
3060 (when (gnus-visual-p 'page-marker)
3061 (let ((buffer-read-only nil))
3062 (gnus-remove-text-with-property 'gnus-prev)
3063 (gnus-remove-text-with-property 'gnus-next)))
3066 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3068 (re-search-forward page-delimiter nil 'move arg)))
3069 (goto-char (match-end 0)))
3072 (if (re-search-forward page-delimiter nil 'move)
3075 (when (and (gnus-visual-p 'page-marker)
3076 (not (= (point-min) 1)))
3078 (goto-char (point-min))
3079 (gnus-insert-prev-page-button)))
3080 (when (and (gnus-visual-p 'page-marker)
3081 (< (+ (point-max) 2) (buffer-size)))
3083 (goto-char (point-max))
3084 (gnus-insert-next-page-button)))))
3086 ;; Article mode commands
3088 (defun gnus-article-goto-next-page ()
3089 "Show the next page of the article."
3091 (when (gnus-article-next-page)
3092 (goto-char (point-min))
3093 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3095 (defun gnus-article-goto-prev-page ()
3096 "Show the next page of the article."
3098 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3099 (gnus-article-prev-page nil)))
3101 (defun gnus-article-next-page (&optional lines)
3102 "Show the next page of the current article.
3103 If end of article, return non-nil. Otherwise return nil.
3104 Argument LINES specifies lines to be scrolled up."
3106 (move-to-window-line -1)
3109 (and (pos-visible-in-window-p) ;Not continuation line.
3111 ;; Nothing in this page.
3112 (if (or (not gnus-page-broken)
3115 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3117 (gnus-narrow-to-page 1) ;Go to next page.
3119 ;; More in this page.
3120 (let ((scroll-in-place nil))
3124 ;; Long lines may cause an end-of-buffer error.
3125 (goto-char (point-max)))))
3126 (move-to-window-line 0)
3129 (defun gnus-article-prev-page (&optional lines)
3130 "Show previous page of current article.
3131 Argument LINES specifies lines to be scrolled down."
3133 (move-to-window-line 0)
3134 (if (and gnus-page-broken
3136 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3138 (gnus-narrow-to-page -1) ;Go to previous page.
3139 (goto-char (point-max))
3141 (let ((scroll-in-place nil))
3145 (beginning-of-buffer
3146 (goto-char (point-min))))
3147 (move-to-window-line 0)))))
3149 (defun gnus-article-refer-article ()
3150 "Read article specified by message-id around point."
3152 (let ((point (point)))
3153 (search-forward ">" nil t) ;Move point to end of "<....>".
3154 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3155 (let ((message-id (match-string 1)))
3157 (set-buffer gnus-summary-buffer)
3158 (gnus-summary-refer-article message-id))
3160 (error "No references around point"))))
3162 (defun gnus-article-show-summary ()
3163 "Reconfigure windows to show summary buffer."
3165 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3166 (error "There is no summary buffer for this article buffer")
3167 (gnus-article-set-globals)
3168 (gnus-configure-windows 'article)
3169 (gnus-summary-goto-subject gnus-current-article)
3170 (gnus-summary-position-point)))
3172 (defun gnus-article-describe-briefly ()
3173 "Describe article mode commands briefly."
3175 (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")))
3177 (defun gnus-article-summary-command ()
3178 "Execute the last keystroke in the summary buffer."
3180 (let ((obuf (current-buffer))
3181 (owin (current-window-configuration))
3183 (switch-to-buffer gnus-article-current-summary 'norecord)
3184 (setq func (lookup-key (current-local-map) (this-command-keys)))
3185 (call-interactively func)
3187 (set-window-configuration owin)
3188 (set-window-point (get-buffer-window (current-buffer)) (point))))
3190 (defun gnus-article-summary-command-nosave ()
3191 "Execute the last keystroke in the summary buffer."
3194 (pop-to-buffer gnus-article-current-summary 'norecord)
3195 (setq func (lookup-key (current-local-map) (this-command-keys)))
3196 (call-interactively func)))
3198 (defun gnus-article-check-buffer ()
3199 "Beep if not in an article buffer."
3200 (unless (equal major-mode 'gnus-article-mode)
3201 (error "Command invoked outside of a Gnus article buffer")))
3203 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3204 "Read a summary buffer key sequence and execute it from the article buffer."
3206 (gnus-article-check-buffer)
3208 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3209 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3210 "=" "^" "\M-^" "|"))
3216 '("n" "Gn" "p" "Gp"))
3219 (set-buffer gnus-article-current-summary)
3220 (let (gnus-pick-mode)
3221 (push (or key last-command-event) unread-command-events)
3222 (setq keys (read-key-sequence nil))))
3225 (if (or (member keys nosaves)
3226 (member keys nosave-but-article)
3227 (member keys nosave-in-article))
3229 (save-window-excursion
3230 (pop-to-buffer gnus-article-current-summary 'norecord)
3231 ;; We disable the pick minor mode commands.
3232 (let (gnus-pick-mode)
3233 (setq func (lookup-key (current-local-map) keys))))
3236 (unless (member keys nosave-in-article)
3237 (set-buffer gnus-article-current-summary))
3238 (call-interactively func)
3239 (setq new-sum-point (point)))
3240 (when (member keys nosave-but-article)
3241 (pop-to-buffer gnus-article-buffer 'norecord)))
3242 ;; These commands should restore window configuration.
3243 (let ((obuf (current-buffer))
3244 (owin (current-window-configuration))
3246 (summary gnus-article-current-summary)
3247 func in-buffer selected)
3248 (if not-restore-window
3249 (pop-to-buffer summary 'norecord)
3250 (switch-to-buffer summary 'norecord))
3251 (setq in-buffer (current-buffer))
3252 ;; We disable the pick minor mode commands.
3253 (if (setq func (let (gnus-pick-mode)
3254 (lookup-key (current-local-map) keys)))
3256 (call-interactively func)
3257 (setq new-sum-point (point)))
3259 (when (eq in-buffer (current-buffer))
3260 (setq selected (gnus-summary-select-article))
3262 (unless not-restore-window
3263 (set-window-configuration owin))
3264 (unless (or (not (eq selected 'old)) (member keys up-to-top))
3265 (set-window-point (get-buffer-window (current-buffer))
3267 (let ((win (get-buffer-window gnus-article-current-summary)))
3269 (set-window-point win new-sum-point))))))))
3271 (defun gnus-article-hide (&optional arg force)
3272 "Hide all the gruft in the current article.
3273 This means that PGP stuff, signatures, cited text and (some)
3274 headers will be hidden.
3275 If given a prefix, show the hidden text instead."
3276 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3277 (gnus-article-hide-headers arg)
3278 (gnus-article-hide-pgp arg)
3279 (gnus-article-hide-citation-maybe arg force)
3280 (gnus-article-hide-signature arg))
3282 (defun gnus-article-maybe-highlight ()
3283 "Do some article highlighting if article highlighting is requested."
3284 (when (gnus-visual-p 'article-highlight 'highlight)
3285 (gnus-article-highlight-some)))
3287 (defun gnus-check-group-server ()
3288 ;; Make sure the connection to the server is alive.
3289 (unless (gnus-server-opened
3290 (gnus-find-method-for-group gnus-newsgroup-name))
3291 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3292 (gnus-request-group gnus-newsgroup-name t)))
3294 (defun gnus-request-article-this-buffer (article group)
3295 "Get an article and insert it into this buffer."
3296 (let (do-update-line sparse-header)
3300 (gnus-kill-all-overlays)
3301 (setq group (or group gnus-newsgroup-name))
3303 ;; Using `gnus-request-article' directly will insert the article into
3304 ;; `nntp-server-buffer' - so we'll save some time by not having to
3305 ;; copy it from the server buffer into the article buffer.
3307 ;; We only request an article by message-id when we do not have the
3308 ;; headers for it, so we'll have to get those.
3309 (when (stringp article)
3310 (let ((gnus-override-method gnus-refer-article-method))
3311 (gnus-read-header article)))
3313 ;; If the article number is negative, that means that this article
3314 ;; doesn't belong in this newsgroup (possibly), so we find its
3315 ;; message-id and request it by id instead of number.
3316 (when (and (numberp article)
3318 (get-buffer gnus-summary-buffer)
3319 (gnus-buffer-exists-p gnus-summary-buffer))
3321 (set-buffer gnus-summary-buffer)
3322 (let ((header (gnus-summary-article-header article)))
3325 ((memq article gnus-newsgroup-sparse)
3326 ;; This is a sparse gap article.
3327 (setq do-update-line article)
3328 (setq article (mail-header-id header))
3329 (let ((gnus-override-method gnus-refer-article-method))
3330 (setq sparse-header (gnus-read-header article)))
3331 (setq gnus-newsgroup-sparse
3332 (delq article gnus-newsgroup-sparse)))
3334 ;; It's a real article.
3335 (setq article (mail-header-id header)))
3337 ;; It is an extracted pseudo-article.
3338 (setq article 'pseudo)
3339 (gnus-request-pseudo-article header))))
3341 (let ((method (gnus-find-method-for-group
3342 gnus-newsgroup-name)))
3343 (when (and (eq (car method) 'nneething)
3346 (file-name-as-directory
3347 (or (cadr (assq 'nneething-address method))
3349 (mail-header-subject header))))
3350 (when (file-directory-p dir)
3351 (setq article 'nneething)
3352 (gnus-group-enter-directory dir))))))))
3355 ;; Refuse to select canceled articles.
3356 ((and (numberp article)
3358 (get-buffer gnus-summary-buffer)
3359 (gnus-buffer-exists-p gnus-summary-buffer)
3360 (eq (cdr (save-excursion
3361 (set-buffer gnus-summary-buffer)
3362 (assq article gnus-newsgroup-reads)))
3363 gnus-canceled-mark))
3365 ;; We first check `gnus-original-article-buffer'.
3366 ((and (get-buffer gnus-original-article-buffer)
3369 (set-buffer gnus-original-article-buffer)
3370 (and (equal (car gnus-original-article) group)
3371 (eq (cdr gnus-original-article) article))))
3372 (insert-buffer-substring gnus-original-article-buffer)
3374 ;; Check the backlog.
3375 ((and gnus-keep-backlog
3376 (gnus-backlog-request-article group article (current-buffer)))
3378 ;; Check asynchronous pre-fetch.
3379 ((gnus-async-request-fetched-article group article (current-buffer))
3380 (gnus-async-prefetch-next group article gnus-summary-buffer)
3381 (when (and (numberp article) gnus-keep-backlog)
3382 (gnus-backlog-enter-article group article (current-buffer)))
3385 ((and gnus-use-cache
3387 (gnus-cache-request-article article group))
3389 ;; Get the article and put into the article buffer.
3390 ((or (stringp article) (numberp article))
3391 (let ((gnus-override-method
3392 (and (stringp article) gnus-refer-article-method))
3393 (buffer-read-only nil))
3395 (gnus-kill-all-overlays)
3396 (gnus-check-group-server)
3397 (when (gnus-request-article article group (current-buffer))
3398 (when (numberp article)
3399 (gnus-async-prefetch-next group article gnus-summary-buffer)
3400 (when gnus-keep-backlog
3401 (gnus-backlog-enter-article
3402 group article (current-buffer))))
3407 ;; Associate this article with the current summary buffer.
3408 (setq gnus-article-current-summary gnus-summary-buffer)
3410 ;; Take the article from the original article buffer
3411 ;; and place it in the buffer it's supposed to be in.
3412 (when (and (get-buffer gnus-article-buffer)
3413 (equal (buffer-name (current-buffer))
3414 (buffer-name (get-buffer gnus-article-buffer))))
3416 (if (get-buffer gnus-original-article-buffer)
3417 (set-buffer gnus-original-article-buffer)
3418 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3419 (buffer-disable-undo)
3420 (setq major-mode 'gnus-original-article-mode)
3421 (setq buffer-read-only t))
3422 (let (buffer-read-only)
3424 (insert-buffer-substring gnus-article-buffer))
3425 (setq gnus-original-article (cons group article)))
3428 (run-hooks 'gnus-article-decode-hook)
3429 ;; Mark article as decoded or not.
3430 (setq gnus-article-decoded-p gnus-article-decode-hook))
3432 ;; Update sparse articles.
3433 (when (and do-update-line
3434 (or (numberp article)
3436 (let ((buf (current-buffer)))
3437 (set-buffer gnus-summary-buffer)
3438 (gnus-summary-update-article do-update-line sparse-header)
3439 (gnus-summary-goto-subject do-update-line nil t)
3440 (set-window-point (get-buffer-window (current-buffer) t)
3442 (set-buffer buf))))))
3448 (defcustom gnus-article-edit-mode-hook nil
3449 "Hook run in article edit mode buffers."
3450 :group 'gnus-article-various
3453 (defvar gnus-article-edit-done-function nil)
3455 (defvar gnus-article-edit-mode-map nil)
3457 ;; Should we be using derived.el for this?
3458 (unless gnus-article-edit-mode-map
3459 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3460 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3462 (gnus-define-keys gnus-article-edit-mode-map
3463 "\C-c\C-c" gnus-article-edit-done
3464 "\C-c\C-k" gnus-article-edit-exit)
3466 (gnus-define-keys (gnus-article-edit-wash-map
3467 "\C-c\C-w" gnus-article-edit-mode-map)
3468 "f" gnus-article-edit-full-stops))
3470 (defun gnus-article-edit-mode ()
3471 "Major mode for editing articles.
3472 This is an extended text-mode.
3474 \\{gnus-article-edit-mode-map}"
3476 (setq major-mode 'gnus-article-edit-mode)
3477 (setq mode-name "Article Edit")
3478 (use-local-map gnus-article-edit-mode-map)
3479 (make-local-variable 'gnus-article-edit-done-function)
3480 (make-local-variable 'gnus-prev-winconf)
3481 (setq buffer-read-only nil)
3482 (buffer-enable-undo)
3484 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3486 (defun gnus-article-edit (&optional force)
3487 "Edit the current article.
3488 This will have permanent effect only in mail groups.
3489 If FORCE is non-nil, allow editing of articles even in read-only
3492 (when (and (not force)
3493 (gnus-group-read-only-p))
3494 (error "The current newsgroup does not support article editing"))
3495 (gnus-article-date-original)
3496 (gnus-article-edit-article
3497 `(lambda (no-highlight)
3498 (gnus-summary-edit-article-done
3499 ,(or (mail-header-references gnus-current-headers) "")
3500 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3502 (defun gnus-article-edit-article (exit-func)
3503 "Start editing the contents of the current article buffer."
3504 (let ((winconf (current-window-configuration)))
3505 (set-buffer gnus-article-buffer)
3506 (gnus-article-edit-mode)
3507 (gnus-article-delete-text-of-type 'annotation)
3508 (gnus-set-text-properties (point-min) (point-max) nil)
3509 (gnus-configure-windows 'edit-article)
3510 (setq gnus-article-edit-done-function exit-func)
3511 (setq gnus-prev-winconf winconf)
3512 (gnus-message 6 "C-c C-c to end edits")))
3514 (defun gnus-article-edit-done (&optional arg)
3515 "Update the article edits and exit."
3520 (when (article-goto-body)
3521 (let ((lines (count-lines (point) (point-max)))
3522 (length (- (point-max) (point)))
3523 (case-fold-search t)
3524 (body (copy-marker (point))))
3525 (goto-char (point-min))
3526 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3527 (delete-region (match-beginning 1) (match-end 1))
3528 (insert (number-to-string length)))
3529 (goto-char (point-min))
3530 (when (re-search-forward
3531 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3532 (delete-region (match-beginning 1) (match-end 1))
3533 (insert (number-to-string length)))
3534 (goto-char (point-min))
3535 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3536 (delete-region (match-beginning 1) (match-end 1))
3537 (insert (number-to-string lines)))))))
3538 (let ((func gnus-article-edit-done-function)
3539 (buf (current-buffer))
3540 (start (window-start)))
3541 (gnus-article-edit-exit)
3544 (let ((buffer-read-only nil))
3546 ;; The cache and backlog have to be flushed somewhat.
3547 (when gnus-keep-backlog
3548 (gnus-backlog-remove-article
3549 (car gnus-article-current) (cdr gnus-article-current)))
3550 ;; Flush original article as well.
3552 (when (get-buffer gnus-original-article-buffer)
3553 (set-buffer gnus-original-article-buffer)
3554 (setq gnus-original-article nil)))
3555 (when gnus-use-cache
3556 (gnus-cache-update-article
3557 (car gnus-article-current) (cdr gnus-article-current))))
3559 (set-window-start (get-buffer-window buf) start)
3560 (set-window-point (get-buffer-window buf) (point))))
3562 (defun gnus-article-edit-exit ()
3563 "Exit the article editing without updating."
3565 ;; We remove all text props from the article buffer.
3566 (let ((buf (format "%s" (buffer-string)))
3567 (curbuf (current-buffer))
3569 (window-start (window-start)))
3572 (let ((winconf gnus-prev-winconf))
3574 (set-window-configuration winconf)
3575 ;; Tippy-toe some to make sure that point remains where it was.
3576 (save-current-buffer
3578 (set-window-start (get-buffer-window (current-buffer)) window-start)
3581 (defun gnus-article-edit-full-stops ()
3582 "Interactively repair spacing at end of sentences."
3585 (goto-char (point-min))
3586 (search-forward-regexp "^$" nil t)
3587 (let ((case-fold-search nil))
3588 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3591 ;;; Article highlights
3594 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3596 ;;; Internal Variables:
3598 (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\\)"
3599 "Regular expression that matches URLs."
3600 :group 'gnus-article-buttons
3603 (defcustom gnus-button-alist
3604 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3605 0 t gnus-button-message-id 2)
3606 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3607 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3609 gnus-button-fetch-group 4)
3610 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3611 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3612 t gnus-button-message-id 3)
3613 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3614 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3615 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3616 ;; This is how URLs _should_ be embedded in text...
3617 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3619 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3620 "*Alist of regexps matching buttons in article bodies.
3622 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3623 REGEXP: is the string matching text around the button,
3624 BUTTON: is the number of the regexp grouping actually matching the button,
3625 FORM: is a lisp expression which must eval to true for the button to
3627 CALLBACK: is the function to call when the user push this button, and each
3628 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3630 CALLBACK can also be a variable, in that case the value of that
3631 variable it the real callback function."
3632 :group 'gnus-article-buttons
3633 :type '(repeat (list regexp
3634 (integer :tag "Button")
3636 (function :tag "Callback")
3639 (integer :tag "Regexp group")))))
3641 (defcustom gnus-header-button-alist
3642 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3643 0 t gnus-button-message-id 0)
3644 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3645 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3646 0 t gnus-button-mailto 0)
3647 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3648 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3649 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3650 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3651 gnus-button-message-id 3))
3652 "*Alist of headers and regexps to match buttons in article heads.
3654 This alist is very similar to `gnus-button-alist', except that each
3655 alist has an additional HEADER element first in each entry:
3657 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3659 HEADER is a regexp to match a header. For a fuller explanation, see
3660 `gnus-button-alist'."
3661 :group 'gnus-article-buttons
3662 :group 'gnus-article-headers
3663 :type '(repeat (list (regexp :tag "Header")
3665 (integer :tag "Button")
3667 (function :tag "Callback")
3670 (integer :tag "Regexp group")))))
3672 (defvar gnus-button-regexp nil)
3673 (defvar gnus-button-marker-list nil)
3674 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3676 (defvar gnus-button-last nil)
3677 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3681 (defun gnus-article-push-button (event)
3682 "Check text under the mouse pointer for a callback function.
3683 If the text under the mouse pointer has a `gnus-callback' property,
3684 call it with the value of the `gnus-data' text property."
3686 (set-buffer (window-buffer (posn-window (event-start event))))
3687 (let* ((pos (posn-point (event-start event)))
3688 (data (get-text-property pos 'gnus-data))
3689 (fun (get-text-property pos 'gnus-callback)))
3692 (funcall fun data))))
3694 (defun gnus-article-press-button ()
3695 "Check text at point for a callback function.
3696 If the text at point has a `gnus-callback' property,
3697 call it with the value of the `gnus-data' text property."
3699 (let* ((data (get-text-property (point) 'gnus-data))
3700 (fun (get-text-property (point) 'gnus-callback)))
3702 (funcall fun data))))
3704 (defun gnus-article-highlight (&optional force)
3705 "Highlight current article.
3706 This function calls `gnus-article-highlight-headers',
3707 `gnus-article-highlight-citation',
3708 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3709 do the highlighting. See the documentation for those functions."
3710 (interactive (list 'force))
3711 (gnus-article-highlight-headers)
3712 (gnus-article-highlight-citation force)
3713 (gnus-article-highlight-signature)
3714 (gnus-article-add-buttons force)
3715 (gnus-article-add-buttons-to-head))
3717 (defun gnus-article-highlight-some (&optional force)
3718 "Highlight current article.
3719 This function calls `gnus-article-highlight-headers',
3720 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3721 do the highlighting. See the documentation for those functions."
3722 (interactive (list 'force))
3723 (gnus-article-highlight-headers)
3724 (gnus-article-highlight-signature)
3725 (gnus-article-add-buttons))
3727 (defun gnus-article-highlight-headers ()
3728 "Highlight article headers as specified by `gnus-header-face-alist'."
3731 (set-buffer gnus-article-buffer)
3733 (let ((alist gnus-header-face-alist)
3734 (buffer-read-only nil)
3735 (case-fold-search t)
3736 (inhibit-point-motion-hooks t)
3737 entry regexp header-face field-face from hpoints fpoints)
3738 (message-narrow-to-head)
3739 (while (setq entry (pop alist))
3740 (goto-char (point-min))
3741 (setq regexp (concat "^\\("
3742 (if (string-equal "" (nth 0 entry))
3746 header-face (nth 1 entry)
3747 field-face (nth 2 entry))
3748 (while (and (re-search-forward regexp nil t)
3752 (unless (search-forward ":" nil t)
3754 (when (and header-face
3755 (not (memq (point) hpoints)))
3756 (push (point) hpoints)
3757 (gnus-put-text-property from (point) 'face header-face))
3758 (when (and field-face
3759 (not (memq (setq from (point)) fpoints)))
3761 (if (re-search-forward "^[^ \t]" nil t)
3763 (goto-char (point-max)))
3764 (gnus-put-text-property from (point) 'face field-face))))))))
3766 (defun gnus-article-highlight-signature ()
3767 "Highlight the signature in an article.
3768 It does this by highlighting everything after
3769 `gnus-signature-separator' using `gnus-signature-face'."
3772 (set-buffer gnus-article-buffer)
3773 (let ((buffer-read-only nil)
3774 (inhibit-point-motion-hooks t))
3776 (when (and gnus-signature-face
3777 (gnus-article-narrow-to-signature))
3778 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3779 'face gnus-signature-face)
3781 (gnus-article-search-signature)
3782 (let ((start (match-beginning 0))
3783 (end (set-marker (make-marker) (1+ (match-end 0)))))
3784 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3787 (defun gnus-button-in-region-p (b e prop)
3788 "Say whether PROP exists in the region."
3789 (text-property-not-all b e prop nil))
3791 (defun gnus-article-add-buttons (&optional force)
3792 "Find external references in the article and make buttons of them.
3793 \"External references\" are things like Message-IDs and URLs, as
3794 specified by `gnus-button-alist'."
3795 (interactive (list 'force))
3797 (set-buffer gnus-article-buffer)
3798 (let ((buffer-read-only nil)
3799 (inhibit-point-motion-hooks t)
3800 (case-fold-search t)
3801 (alist gnus-button-alist)
3803 ;; Remove all old markers.
3805 (while (setq marker (pop gnus-button-marker-list))
3807 (when (setq entry (gnus-button-entry))
3808 (put-text-property (match-beginning (nth 1 entry))
3809 (match-end (nth 1 entry))
3810 'gnus-callback nil))
3811 (set-marker marker nil)))
3812 ;; We skip the headers.
3815 (while (setq entry (pop alist))
3816 (setq regexp (car entry))
3818 (while (re-search-forward regexp nil t)
3819 (let* ((start (and entry (match-beginning (nth 1 entry))))
3820 (end (and entry (match-end (nth 1 entry))))
3821 (from (match-beginning 0)))
3822 (when (and (or (eq t (nth 2 entry))
3823 (eval (nth 2 entry)))
3824 (not (gnus-button-in-region-p
3825 start end 'gnus-callback)))
3826 ;; That optional form returned non-nil, so we add the
3828 (gnus-article-add-button
3829 start end 'gnus-button-push
3830 (car (push (set-marker (make-marker) from)
3831 gnus-button-marker-list))))))))))
3833 ;; Add buttons to the head of an article.
3834 (defun gnus-article-add-buttons-to-head ()
3835 "Add buttons to the head of the article."
3838 (set-buffer gnus-article-buffer)
3839 (let ((buffer-read-only nil)
3840 (inhibit-point-motion-hooks t)
3841 (case-fold-search t)
3842 (alist gnus-header-button-alist)
3844 (nnheader-narrow-to-headers)
3846 ;; Each alist entry.
3847 (setq entry (car alist)
3849 (goto-char (point-min))
3850 (while (re-search-forward (car entry) nil t)
3851 ;; Each header matching the entry.
3852 (setq beg (match-beginning 0))
3853 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3854 (match-beginning 0))
3857 (while (re-search-forward (nth 1 entry) end t)
3858 ;; Each match within a header.
3859 (let* ((entry (cdr entry))
3860 (start (match-beginning (nth 1 entry)))
3861 (end (match-end (nth 1 entry)))
3862 (form (nth 2 entry)))
3863 (goto-char (match-end 0))
3865 (gnus-article-add-button
3866 start end (nth 3 entry)
3867 (buffer-substring (match-beginning (nth 4 entry))
3868 (match-end (nth 4 entry)))))))
3872 ;;; External functions:
3874 (defun gnus-article-add-button (from to fun &optional data)
3875 "Create a button between FROM and TO with callback FUN and data DATA."
3876 (when gnus-article-button-face
3877 (gnus-overlay-put (gnus-make-overlay from to)
3878 'face gnus-article-button-face))
3879 (gnus-add-text-properties
3881 (nconc (and gnus-article-mouse-face
3882 (list gnus-mouse-face-prop gnus-article-mouse-face))
3883 (list 'gnus-callback fun)
3884 (and data (list 'gnus-data data))))
3885 (widget-convert-button 'link from to :action 'gnus-widget-press-button
3886 :button-keymap gnus-widget-button-keymap))
3888 ;;; Internal functions:
3890 (defun gnus-article-set-globals ()
3892 (set-buffer gnus-summary-buffer)
3893 (gnus-set-global-variables)))
3895 (defun gnus-signature-toggle (end)
3897 (set-buffer gnus-article-buffer)
3898 (let ((buffer-read-only nil)
3899 (inhibit-point-motion-hooks t))
3900 (if (get-text-property end 'invisible)
3901 (gnus-article-unhide-text end (point-max))
3902 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3904 (defun gnus-button-entry ()
3905 ;; Return the first entry in `gnus-button-alist' matching this place.
3906 (let ((alist gnus-button-alist)
3909 (setq entry (pop alist))
3910 (if (looking-at (car entry))
3915 (defun gnus-button-push (marker)
3916 ;; Push button starting at MARKER.
3919 (let* ((entry (gnus-button-entry))
3920 (inhibit-point-motion-hooks t)
3922 (args (mapcar (lambda (group)
3923 (let ((string (match-string group)))
3924 (gnus-set-text-properties
3925 0 (length string) nil string)
3932 (fboundp (symbol-value fun)))
3933 (apply (symbol-value fun) args))
3935 (gnus-message 1 "You must define `%S' to use this button"
3936 (cons fun args)))))))
3938 (defun gnus-button-message-id (message-id)
3941 (set-buffer gnus-summary-buffer)
3942 (gnus-summary-refer-article message-id)))
3944 (defun gnus-button-fetch-group (address)
3945 "Fetch GROUP specified by ADDRESS."
3946 (if (not (string-match "[:/]" address))
3947 ;; This is just a simple group url.
3948 (gnus-group-read-ephemeral-group address gnus-select-method)
3949 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3951 (error "Can't parse %s" address)
3952 (gnus-group-read-ephemeral-group
3953 (match-string 4 address)
3954 `(nntp ,(match-string 1 address)
3955 (nntp-address ,(match-string 1 address))
3956 (nntp-port-number ,(if (match-end 3)
3957 (match-string 3 address)
3960 (defun gnus-url-parse-query-string (query &optional downcase)
3961 (let (retval pairs cur key val)
3962 (setq pairs (split-string query "&"))
3964 (setq cur (car pairs)
3966 (if (not (string-match "=" cur))
3968 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3969 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3971 (setq key (downcase key)))
3972 (setq cur (assoc key retval))
3974 (setcdr cur (cons val (cdr cur)))
3975 (setq retval (cons (list key val) retval)))))
3978 (defun gnus-url-unhex (x)
3985 (defun gnus-url-unhex-string (str &optional allow-newlines)
3986 "Remove %XXX embedded spaces, etc in a url.
3987 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3988 decoding of carriage returns and line feeds in the string, which is normally
3989 forbidden in URL encoding."
3990 (setq str (or str ""))
3992 (case-fold-search t))
3993 (while (string-match "%[0-9a-f][0-9a-f]" str)
3994 (let* ((start (match-beginning 0))
3995 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3997 (gnus-url-unhex (elt str (+ start 2))))))
3999 tmp (substring str 0 start)
4002 (char-to-string code))
4003 ((or (= code ?\n) (= code ?\r))
4005 (t (char-to-string code))))
4006 str (substring str (match-end 0)))))
4007 (setq tmp (concat tmp str))
4010 (defun gnus-url-mailto (url)
4011 ;; Send mail to someone
4012 (when (string-match "mailto:/*\\(.*\\)" url)
4013 (setq url (substring url (match-beginning 1) nil)))
4014 (let (to args subject func)
4015 (if (string-match (regexp-quote "?") url)
4016 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4017 args (gnus-url-parse-query-string
4018 (substring url (match-end 0) nil) t))
4019 (setq to (gnus-url-unhex-string url)))
4020 (setq args (cons (list "to" to) args)
4021 subject (cdr-safe (assoc "subject" args)))
4024 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4027 (message-position-on-field (caar args)))
4028 (insert (mapconcat 'identity (cdar args) ", "))
4029 (setq args (cdr args)))
4032 (message-goto-subject))))
4034 (defun gnus-button-mailto (address)
4036 (set-buffer (gnus-copy-article-buffer))
4037 (message-reply address))
4039 (defun gnus-button-reply (address)
4040 ;; Reply to ADDRESS.
4041 (message-reply address))
4043 (defun gnus-button-url (address)
4045 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4046 (if (listp browse-url-browser-function)
4047 (browse-url address)
4048 (funcall browse-url-browser-function address)))
4050 (defun gnus-button-embedded-url (address)
4052 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4053 (if (listp browse-url-browser-function)
4054 (browse-url (gnus-strip-whitespace address))
4055 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4057 ;;; Next/prev buttons in the article buffer.
4059 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4060 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4062 (defvar gnus-prev-page-map nil)
4063 (unless gnus-prev-page-map
4064 (setq gnus-prev-page-map (make-sparse-keymap))
4065 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4066 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4068 (defun gnus-insert-prev-page-button ()
4069 (let ((buffer-read-only nil))
4071 gnus-prev-page-line-format nil
4072 `(gnus-prev t local-map ,gnus-prev-page-map
4073 gnus-callback gnus-article-button-prev-page
4074 article-type annotation))))
4076 (defvar gnus-next-page-map nil)
4077 (unless gnus-next-page-map
4078 (setq gnus-next-page-map (make-keymap))
4079 (suppress-keymap gnus-prev-page-map)
4080 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4081 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4083 (defun gnus-button-next-page ()
4084 "Go to the next page."
4086 (let ((win (selected-window)))
4087 (select-window (get-buffer-window gnus-article-buffer t))
4088 (gnus-article-next-page)
4089 (select-window win)))
4091 (defun gnus-button-prev-page ()
4092 "Go to the prev page."
4094 (let ((win (selected-window)))
4095 (select-window (get-buffer-window gnus-article-buffer t))
4096 (gnus-article-prev-page)
4097 (select-window win)))
4099 (defun gnus-insert-next-page-button ()
4100 (let ((buffer-read-only nil))
4101 (gnus-eval-format gnus-next-page-line-format nil
4103 t local-map ,gnus-next-page-map
4104 gnus-callback gnus-article-button-next-page
4105 article-type annotation))))
4107 (defun gnus-article-button-next-page (arg)
4108 "Go to the next page."
4110 (let ((win (selected-window)))
4111 (select-window (get-buffer-window gnus-article-buffer t))
4112 (gnus-article-next-page)
4113 (select-window win)))
4115 (defun gnus-article-button-prev-page (arg)
4116 "Go to the prev page."
4118 (let ((win (selected-window)))
4119 (select-window (get-buffer-window gnus-article-buffer t))
4120 (gnus-article-prev-page)
4121 (select-window win)))
4123 (defvar gnus-decode-header-methods
4124 '(mail-decode-encoded-word-region)
4125 "List of methods used to decode headers.
4127 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4128 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4129 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4130 whose names match REGEXP.
4133 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4134 mail-decode-encoded-word-region
4135 (\"chinese\" . rfc1843-decode-region))
4138 (defvar gnus-decode-header-methods-cache nil)
4140 (defun gnus-multi-decode-header (start end)
4141 "Apply the functions from `gnus-encoded-word-methods' that match."
4142 (unless (and gnus-decode-header-methods-cache
4143 (eq gnus-newsgroup-name
4144 (car gnus-decode-header-methods-cache)))
4145 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4148 (nconc gnus-decode-header-methods-cache (list x))
4149 (if (and gnus-newsgroup-name
4150 (string-match (car x) gnus-newsgroup-name))
4151 (nconc gnus-decode-header-methods-cache
4153 gnus-decode-header-methods))
4154 (let ((xlist gnus-decode-header-methods-cache))
4157 (narrow-to-region start end)
4159 (funcall (pop xlist) (point-min) (point-max))))))
4162 ;;; Treatment top-level handling.
4165 (defun gnus-treat-article (condition &optional part-number total-parts type)
4166 (let ((length (- (point-max) (point-min)))
4167 (alist gnus-treatment-function-alist)
4168 (article-goto-body-goes-to-point-min-p t)
4170 (when (and (gnus-visual-p 'article-highlight 'highlight)
4173 (let ((list gnus-article-treat-types))
4175 (when (string-match (pop list) type)
4176 (throw 'found t)))))))
4177 (gnus-run-hooks 'gnus-part-display-hook)
4178 (while (setq elem (pop alist))
4179 (setq val (symbol-value (car elem)))
4190 (eq part-number total-parts))
4195 (funcall (cadr elem)))))))
4201 (run-hooks 'gnus-art-load-hook)
4203 ;;; gnus-art.el ends here