1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 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))
38 (defgroup gnus-article nil
40 :link '(custom-manual "(gnus)The Article Buffer")
43 (defgroup gnus-article-hiding nil
44 "Hiding article parts."
45 :link '(custom-manual "(gnus)Article Hiding")
48 (defgroup gnus-article-highlight nil
49 "Article highlighting."
50 :link '(custom-manual "(gnus)Article Highlighting")
54 (defgroup gnus-article-signature nil
56 :link '(custom-manual "(gnus)Article Signature")
59 (defgroup gnus-article-headers nil
61 :link '(custom-manual "(gnus)Hiding Headers")
64 (defgroup gnus-article-washing nil
65 "Special commands on articles."
66 :link '(custom-manual "(gnus)Article Washing")
69 (defgroup gnus-article-emphasis nil
70 "Fontisizing articles."
71 :link '(custom-manual "(gnus)Article Fontisizing")
74 (defgroup gnus-article-saving nil
76 :link '(custom-manual "(gnus)Saving Articles")
79 (defgroup gnus-article-mime nil
80 "Worshiping the MIME wonder."
81 :link '(custom-manual "(gnus)Using MIME")
84 (defgroup gnus-article-buttons nil
85 "Pushable buttons in the article buffer."
86 :link '(custom-manual "(gnus)Article Buttons")
89 (defgroup gnus-article-various nil
90 "Other article options."
91 :link '(custom-manual "(gnus)Misc Article")
94 (defcustom gnus-ignored-headers
95 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
96 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
97 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
98 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
99 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
100 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
101 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
102 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
103 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
104 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
105 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
106 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
107 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
108 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
109 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
110 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
111 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
112 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
114 "*All headers that start with this regexp will be hidden.
115 This variable can also be a list of regexps of headers to be ignored.
116 If `gnus-visible-headers' is non-nil, this variable will be ignored."
117 :type '(choice :custom-show nil
120 :group 'gnus-article-hiding)
122 (defcustom gnus-visible-headers
123 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
124 "*All headers that do not match this regexp will be hidden.
125 This variable can also be a list of regexp of headers to remain visible.
126 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
127 :type '(repeat :value-to-internal (lambda (widget value)
128 (custom-split-regexp-maybe value))
129 :match (lambda (widget value)
131 (widget-editable-list-match widget value)))
133 :group 'gnus-article-hiding)
135 (defcustom gnus-sorted-header-list
136 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
137 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
138 "*This variable is a list of regular expressions.
139 If it is non-nil, headers that match the regular expressions will
140 be placed first in the article buffer in the sequence specified by
142 :type '(repeat regexp)
143 :group 'gnus-article-hiding)
145 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
146 "Headers that are only to be displayed if they have interesting data.
147 Possible values in this list are `empty', `newsgroups', `followup-to',
148 `reply-to', `date', `long-to', and `many-to'."
149 :type '(set (const :tag "Headers with no content." empty)
150 (const :tag "Newsgroups with only one group." newsgroups)
151 (const :tag "Followup-to identical to newsgroups." followup-to)
152 (const :tag "Reply-to identical to from." reply-to)
153 (const :tag "Date less than four days old." date)
154 (const :tag "Very long To header." long-to)
155 (const :tag "Multiple To headers." many-to))
156 :group 'gnus-article-hiding)
158 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
159 "Regexp matching signature separator.
160 This can also be a list of regexps. In that case, it will be checked
161 from head to tail looking for a separator. Searches will be done from
162 the end of the buffer."
163 :type '(repeat string)
164 :group 'gnus-article-signature)
166 (defcustom gnus-signature-limit nil
167 "Provide a limit to what is considered a signature.
168 If it is a number, no signature may not be longer (in characters) than
169 that number. If it is a floating point number, no signature may be
170 longer (in lines) than that number. If it is a function, the function
171 will be called without any parameters, and if it returns nil, there is
172 no signature in the buffer. If it is a string, it will be used as a
173 regexp. If it matches, the text in question is not a signature."
174 :type '(choice (integer :value 200)
176 (function :value fun)
177 (regexp :value ".*"))
178 :group 'gnus-article-signature)
180 (defcustom gnus-hidden-properties '(invisible t intangible t)
181 "Property list to use for hiding text."
183 :group 'gnus-article-hiding)
185 (defcustom gnus-article-x-face-command
186 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
187 "*String or function to be executed to display an X-Face header.
188 If it is a string, the command will be executed in a sub-shell
189 asynchronously. The compressed face will be piped to this command."
190 :type 'string ;Leave function case to Lisp.
191 :group 'gnus-article-washing)
193 (defcustom gnus-article-x-face-too-ugly nil
194 "Regexp matching posters whose face shouldn't be shown automatically."
195 :type '(choice regexp (const nil))
196 :group 'gnus-article-washing)
198 (defcustom gnus-emphasis-alist
200 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
202 '(("_" "_" underline)
205 ("_/" "/_" underline-italic)
206 ("_\\*" "\\*_" underline-bold)
207 ("\\*/" "/\\*" bold-italic)
208 ("_\\*/" "/\\*_" underline-bold-italic))))
209 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
210 2 3 gnus-emphasis-underline)
214 (format format (car spec) (cadr spec))
215 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
217 "*Alist that says how to fontify certain phrases.
218 Each item looks like this:
220 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
222 The first element is a regular expression to be matched. The second
223 is a number that says what regular expression grouping used to find
224 the entire emphasized word. The third is a number that says what
225 regexp grouping should be displayed and highlighted. The fourth
226 is the face used for highlighting."
227 :type '(repeat (list :value ("" 0 0 default)
229 (integer :tag "Match group")
230 (integer :tag "Emphasize group")
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-bold '((t (:bold t)))
235 "Face used for displaying strong emphasized text (*word*)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-italic '((t (:italic t)))
239 "Face used for displaying italic emphasized text (/word/)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-underline '((t (:underline t)))
243 "Face used for displaying underlined emphasized text (_word_)."
244 :group 'gnus-article-emphasis)
246 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
247 "Face used for displaying underlined bold emphasized text (_*word*_)."
248 :group 'gnus-article-emphasis)
250 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
251 "Face used for displaying underlined italic emphasized text (_*word*_)."
252 :group 'gnus-article-emphasis)
254 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
255 "Face used for displaying bold italic emphasized text (/*word*/)."
256 :group 'gnus-article-emphasis)
258 (defface gnus-emphasis-underline-bold-italic
259 '((t (:bold t :italic t :underline t)))
260 "Face used for displaying underlined bold italic emphasized text.
261 Esample: (_/*word*/_)."
262 :group 'gnus-article-emphasis)
264 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
265 "Format for display of Date headers in article bodies.
266 See `format-time-string' for the possible values.
268 The variable can also be function, which should return a complete Date
269 header. The function is called with one argument, the time, which can
270 be fed to `format-time-string'."
271 :type '(choice string symbol)
272 :link '(custom-manual "(gnus)Article Date")
273 :group 'gnus-article-washing)
276 (autoload 'mail-extract-address-components "mail-extr"))
278 (defcustom gnus-save-all-headers t
279 "*If non-nil, don't remove any headers before saving."
280 :group 'gnus-article-saving
283 (defcustom gnus-prompt-before-saving 'always
284 "*This variable says how much prompting is to be done when saving articles.
285 If it is nil, no prompting will be done, and the articles will be
286 saved to the default files. If this variable is `always', each and
287 every article that is saved will be preceded by a prompt, even when
288 saving large batches of articles. If this variable is neither nil not
289 `always', there the user will be prompted once for a file name for
290 each invocation of the saving commands."
291 :group 'gnus-article-saving
292 :type '(choice (item always)
293 (item :tag "never" nil)
294 (sexp :tag "once" :format "%t\n" :value t)))
296 (defcustom gnus-saved-headers gnus-visible-headers
297 "Headers to keep if `gnus-save-all-headers' is nil.
298 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
299 If that variable is nil, however, all headers that match this regexp
300 will be kept while the rest will be deleted before saving."
301 :group 'gnus-article-saving
304 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
305 "A function to save articles in your favourite format.
306 The function must be interactively callable (in other words, it must
307 be an Emacs command).
309 Gnus provides the following functions:
311 * gnus-summary-save-in-rmail (Rmail format)
312 * gnus-summary-save-in-mail (Unix mail format)
313 * gnus-summary-save-in-folder (MH folder)
314 * gnus-summary-save-in-file (article format)
315 * gnus-summary-save-in-vm (use VM's folder format)
316 * gnus-summary-write-to-file (article format -- overwrite)."
317 :group 'gnus-article-saving
318 :type '(radio (function-item gnus-summary-save-in-rmail)
319 (function-item gnus-summary-save-in-mail)
320 (function-item gnus-summary-save-in-folder)
321 (function-item gnus-summary-save-in-file)
322 (function-item gnus-summary-save-in-vm)
323 (function-item gnus-summary-write-to-file)))
325 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
326 "A function generating a file name to save articles in Rmail format.
327 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
328 :group 'gnus-article-saving
331 (defcustom gnus-mail-save-name 'gnus-plain-save-name
332 "A function generating a file name to save articles in Unix mail format.
333 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
334 :group 'gnus-article-saving
337 (defcustom gnus-folder-save-name 'gnus-folder-save-name
338 "A function generating a file name to save articles in MH folder.
339 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
340 :group 'gnus-article-saving
343 (defcustom gnus-file-save-name 'gnus-numeric-save-name
344 "A function generating a file name to save articles in article format.
345 The function is called with NEWSGROUP, HEADERS, and optional
347 :group 'gnus-article-saving
350 (defcustom gnus-split-methods
351 '((gnus-article-archive-name)
352 (gnus-article-nndoc-name))
353 "*Variable used to suggest where articles are to be saved.
354 For instance, if you would like to save articles related to Gnus in
355 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
356 you could set this variable to something like:
358 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
359 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
361 This variable is an alist where the where the key is the match and the
362 value is a list of possible files to save in if the match is non-nil.
364 If the match is a string, it is used as a regexp match on the
365 article. If the match is a symbol, that symbol will be funcalled
366 from the buffer of the article to be saved with the newsgroup as the
367 parameter. If it is a list, it will be evaled in the same buffer.
369 If this form or function returns a string, this string will be used as
370 a possible file name; and if it returns a non-nil list, that list will
371 be used as possible file names."
372 :group 'gnus-article-saving
373 :type '(repeat (choice (list :value (fun) function)
374 (cons :value ("" "") regexp (repeat string))
377 (defcustom gnus-strict-mime t
378 "*If nil, MIME-decode even if there is no Mime-Version header."
379 :group 'gnus-article-mime
382 (defcustom gnus-show-mime-method 'metamail-buffer
383 "Function to process a MIME message.
384 The function is called from the article buffer."
385 :group 'gnus-article-mime
388 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
389 "*Function to decode MIME encoded words.
390 The function is called from the article buffer."
391 :group 'gnus-article-mime
394 (defcustom gnus-page-delimiter "^\^L"
395 "*Regexp describing what to use as article page delimiters.
396 The default value is \"^\^L\", which is a form linefeed at the
397 beginning of a line."
399 :group 'gnus-article-various)
401 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
402 "*The format specification for the article mode line.
403 See `gnus-summary-mode-line-format' for a closer description."
405 :group 'gnus-article-various)
407 (defcustom gnus-article-mode-hook nil
408 "*A hook for Gnus article mode."
410 :group 'gnus-article-various)
412 (defcustom gnus-article-menu-hook nil
413 "*Hook run after the creation of the article mode menu."
415 :group 'gnus-article-various)
417 (defcustom gnus-article-prepare-hook nil
418 "*A hook called after an article has been prepared in the article buffer.
419 If you want to run a special decoding program like nkf, use this hook."
421 :group 'gnus-article-various)
423 (defcustom gnus-article-hide-pgp-hook nil
424 "*A hook called after successfully hiding a PGP signature."
426 :group 'gnus-article-various)
428 (defcustom gnus-article-button-face 'bold
429 "Face used for highlighting buttons in the article buffer.
431 An article button is a piece of text that you can activate by pressing
432 `RET' or `mouse-2' above it."
434 :group 'gnus-article-buttons)
436 (defcustom gnus-article-mouse-face 'highlight
437 "Face used for mouse highlighting in the article buffer.
439 Article buttons will be displayed in this face when the cursor is
442 :group 'gnus-article-buttons)
444 (defcustom gnus-signature-face 'gnus-signature-face
445 "Face used for highlighting a signature in the article buffer.
446 Obsolete; use the face `gnus-signature-face' for customizations instead."
448 :group 'gnus-article-highlight
449 :group 'gnus-article-signature)
451 (defface gnus-signature-face
454 "Face used for highlighting a signature in the article buffer."
455 :group 'gnus-article-highlight
456 :group 'gnus-article-signature)
458 (defface gnus-header-from-face
461 (:foreground "spring green"))
464 (:foreground "red3"))
467 "Face used for displaying from headers."
468 :group 'gnus-article-headers
469 :group 'gnus-article-highlight)
471 (defface gnus-header-subject-face
474 (:foreground "SeaGreen3"))
477 (:foreground "red4"))
479 (:bold t :italic t)))
480 "Face used for displaying subject headers."
481 :group 'gnus-article-headers
482 :group 'gnus-article-highlight)
484 (defface gnus-header-newsgroups-face
487 (:foreground "yellow" :italic t))
490 (:foreground "MidnightBlue" :italic t))
493 "Face used for displaying newsgroups headers."
494 :group 'gnus-article-headers
495 :group 'gnus-article-highlight)
497 (defface gnus-header-name-face
500 (:foreground "SeaGreen"))
503 (:foreground "maroon"))
506 "Face used for displaying header names."
507 :group 'gnus-article-headers
508 :group 'gnus-article-highlight)
510 (defface gnus-header-content-face
513 (:foreground "forest green" :italic t))
516 (:foreground "indianred4" :italic t))
518 (:italic t))) "Face used for displaying header content."
519 :group 'gnus-article-headers
520 :group 'gnus-article-highlight)
522 (defcustom gnus-header-face-alist
523 '(("From" nil gnus-header-from-face)
524 ("Subject" nil gnus-header-subject-face)
525 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
526 ("" gnus-header-name-face gnus-header-content-face))
527 "*Controls highlighting of article header.
529 An alist of the form (HEADER NAME CONTENT).
531 HEADER is a regular expression which should match the name of an
532 header header and NAME and CONTENT are either face names or nil.
534 The name of each header field will be displayed using the face
535 specified by the first element in the list where HEADER match the
536 header name and NAME is non-nil. Similarly, the content will be
537 displayed by the first non-nil matching CONTENT face."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight
540 :type '(repeat (list (regexp :tag "Header")
542 (item :tag "skip" nil)
543 (face :value default))
544 (choice :tag "Content"
545 (item :tag "skip" nil)
546 (face :value default)))))
548 ;;; Internal variables
550 (defvar article-lapsed-timer nil)
551 (defvar gnus-article-current-summary nil)
553 (defvar gnus-article-mode-syntax-table
554 (let ((table (copy-syntax-table text-mode-syntax-table)))
555 (modify-syntax-entry ?- "w" table)
556 (modify-syntax-entry ?> ")" table)
557 (modify-syntax-entry ?< "(" table)
559 "Syntax table used in article mode buffers.
560 Initialized from `text-mode-syntax-table.")
562 (defvar gnus-save-article-buffer nil)
564 (defvar gnus-article-mode-line-format-alist
565 (nconc '((?w (gnus-article-wash-status) ?s))
566 gnus-summary-mode-line-format-alist))
568 (defvar gnus-number-of-articles-to-be-saved nil)
570 (defvar gnus-inhibit-hiding nil)
572 (defsubst gnus-article-hide-text (b e props)
573 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
574 (add-text-properties b e props)
575 (when (memq 'intangible props)
577 (max (1- b) (point-min))
578 b 'intangible (cddr (memq 'intangible props)))))
580 (defsubst gnus-article-unhide-text (b e)
581 "Remove hidden text properties from region between B and E."
582 (remove-text-properties b e gnus-hidden-properties)
583 (when (memq 'intangible gnus-hidden-properties)
584 (put-text-property (max (1- b) (point-min))
587 (defun gnus-article-hide-text-type (b e type)
588 "Hide text of TYPE between B and E."
589 (gnus-article-hide-text
590 b e (cons 'article-type (cons type gnus-hidden-properties))))
592 (defun gnus-article-unhide-text-type (b e type)
593 "Unhide text of TYPE between B and E."
594 (remove-text-properties
595 b e (cons 'article-type (cons type gnus-hidden-properties)))
596 (when (memq 'intangible gnus-hidden-properties)
597 (put-text-property (max (1- b) (point-min))
600 (defun gnus-article-hide-text-of-type (type)
601 "Hide text of TYPE in the current buffer."
603 (let ((b (point-min))
605 (while (setq b (text-property-any b e 'article-type type))
606 (add-text-properties b (incf b) gnus-hidden-properties)))))
608 (defun gnus-article-delete-text-of-type (type)
609 "Delete text of TYPE in the current buffer."
611 (let ((b (point-min)))
612 (while (setq b (text-property-any b (point-max) 'article-type type))
614 b (or (text-property-not-all b (point-max) 'article-type type)
617 (defun gnus-article-delete-invisible-text ()
618 "Delete all invisible text in the current buffer."
620 (let ((b (point-min)))
621 (while (setq b (text-property-any b (point-max) 'invisible t))
623 b (or (text-property-not-all b (point-max) 'invisible t)
626 (defun gnus-article-text-type-exists-p (type)
627 "Say whether any text of type TYPE exists in the buffer."
628 (text-property-any (point-min) (point-max) 'article-type type))
630 (defsubst gnus-article-header-rank ()
631 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
632 (let ((list gnus-sorted-header-list)
635 (when (looking-at (car list))
637 (setq list (cdr list))
641 (defun article-hide-headers (&optional arg delete)
642 "Toggle whether to hide unwanted headers and possibly sort them as well.
643 If given a negative prefix, always show; if given a positive prefix,
645 (interactive (gnus-article-hidden-arg))
647 (if (gnus-article-check-hidden-text 'headers arg)
648 ;; Show boring headers as well.
649 (gnus-article-show-hidden-text 'boring-headers)
650 ;; This function might be inhibited.
651 (unless gnus-inhibit-hiding
654 (let ((buffer-read-only nil)
656 (props (nconc (list 'article-type 'headers)
657 gnus-hidden-properties))
658 (max (1+ (length gnus-sorted-header-list)))
659 (ignored (when (not gnus-visible-headers)
660 (cond ((stringp gnus-ignored-headers)
661 gnus-ignored-headers)
662 ((listp gnus-ignored-headers)
663 (mapconcat 'identity gnus-ignored-headers
666 (cond ((stringp gnus-visible-headers)
667 gnus-visible-headers)
668 ((and gnus-visible-headers
669 (listp gnus-visible-headers))
670 (mapconcat 'identity gnus-visible-headers "\\|"))))
671 (inhibit-point-motion-hooks t)
673 ;; First we narrow to just the headers.
675 (goto-char (point-min))
676 ;; Hide any "From " lines at the beginning of (mail) articles.
677 (while (looking-at "From ")
681 (delete-region (point-min) (point))
682 (gnus-article-hide-text (point-min) (point) props)))
683 ;; Then treat the rest of the header lines.
686 (if (search-forward "\n\n" nil t) ; if there's a body
687 (progn (forward-line -1) (point))
689 ;; Then we use the two regular expressions
690 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
691 ;; select which header lines is to remain visible in the
693 (goto-char (point-min))
694 (while (re-search-forward "^[^ \t]*:" nil t)
696 ;; Mark the rank of the header.
698 (point) (1+ (point)) 'message-rank
699 (if (or (and visible (looking-at visible))
701 (not (looking-at ignored))))
702 (gnus-article-header-rank)
705 (message-sort-headers-1)
706 (when (setq beg (text-property-any
707 (point-min) (point-max) 'message-rank (+ 2 max)))
708 ;; We make the unwanted headers invisible.
710 (delete-region beg (point-max))
711 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
712 (gnus-article-hide-text-type beg (point-max) 'headers))
713 ;; Work around XEmacs lossage.
714 (put-text-property (point-min) beg 'invisible nil))))))))
716 (defun article-hide-boring-headers (&optional arg)
717 "Toggle hiding of headers that aren't very interesting.
718 If given a negative prefix, always show; if given a positive prefix,
720 (interactive (gnus-article-hidden-arg))
721 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
722 (not gnus-show-all-headers))
725 (let ((buffer-read-only nil)
726 (list gnus-boring-article-headers)
727 (inhibit-point-motion-hooks t)
729 (nnheader-narrow-to-headers)
731 (setq elem (pop list))
732 (goto-char (point-min))
734 ;; Hide empty headers.
736 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
738 (gnus-article-hide-text-type
739 (progn (beginning-of-line) (point))
742 (if (re-search-forward "^[^ \t]" nil t)
746 ;; Hide boring Newsgroups header.
747 ((eq elem 'newsgroups)
748 (when (equal (gnus-fetch-field "newsgroups")
749 (gnus-group-real-name
750 (if (boundp 'gnus-newsgroup-name)
753 (gnus-article-hide-header "newsgroups")))
754 ((eq elem 'followup-to)
755 (when (equal (message-fetch-field "followup-to")
756 (message-fetch-field "newsgroups"))
757 (gnus-article-hide-header "followup-to")))
759 (let ((from (message-fetch-field "from"))
760 (reply-to (message-fetch-field "reply-to")))
765 (nth 1 (mail-extract-address-components from))
766 (nth 1 (mail-extract-address-components reply-to)))))
767 (gnus-article-hide-header "reply-to"))))
769 (let ((date (message-fetch-field "date")))
771 (< (days-between (current-time-string) date)
773 (gnus-article-hide-header "date"))))
775 (let ((to (message-fetch-field "to")))
776 (when (> (length to) 1024)
777 (gnus-article-hide-header "to"))))
780 (goto-char (point-min))
781 (while (re-search-forward "^to:" nil t)
782 (setq to-count (1+ to-count)))
784 (while (> to-count 0)
785 (goto-char (point-min))
787 (re-search-forward "^to:" nil nil to-count)
789 (narrow-to-region (point) (point-max))
790 (gnus-article-hide-header "to"))
791 (setq to-count (1- to-count)))))))))))))
793 (defun gnus-article-hide-header (header)
795 (goto-char (point-min))
796 (when (re-search-forward (concat "^" header ":") nil t)
797 (gnus-article-hide-text-type
798 (progn (beginning-of-line) (point))
801 (if (re-search-forward "^[^ \t]" nil t)
806 (defun article-treat-dumbquotes ()
807 "Translate M******** sm*rtq**t*s into proper text."
809 (article-translate-characters "\221\222\223\223" "`'\"\""))
811 (defun article-translate-characters (from to)
812 "Translate all characters in the body of the article according to FROM and TO.
813 FROM is a string of characters to translate from; to is a string of
814 characters to translate to."
816 (goto-char (point-min))
817 (when (search-forward "\n\n" nil t)
818 (let ((buffer-read-only nil)
819 (x (make-string 225 ?x))
821 (while (< (incf i) (length x))
824 (while (< i (length from))
825 (aset x (aref from i) (aref to i))
827 (translate-region (point) (point-max) x)))))
829 (defun article-treat-overstrike ()
830 "Translate overstrikes into bold text."
833 (goto-char (point-min))
834 (when (search-forward "\n\n" nil t)
835 (let ((buffer-read-only nil))
836 (while (search-forward "\b" nil t)
837 (let ((next (following-char))
838 (previous (char-after (- (point) 2))))
839 ;; We do the boldification/underlining by hiding the
840 ;; overstrikes and putting the proper text property
844 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
845 (put-text-property (point) (1+ (point)) 'face 'bold))
847 (gnus-article-hide-text-type
848 (1- (point)) (1+ (point)) 'overstrike)
850 (- (point) 2) (1- (point)) 'face 'underline))
852 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
854 (point) (1+ (point)) 'face 'underline)))))))))
856 (defun article-fill ()
857 "Format too long lines."
860 (let ((buffer-read-only nil))
862 (goto-char (point-min))
863 (search-forward "\n\n" nil t)
865 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
866 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
867 (adaptive-fill-mode t))
869 (and (>= (current-column) (min fill-column (window-width)))
870 (/= (preceding-char) ?:)
871 (fill-paragraph nil))
874 (defun article-remove-cr ()
875 "Remove carriage returns from an article."
878 (let ((buffer-read-only nil))
879 (goto-char (point-min))
880 (while (search-forward "\r" nil t)
881 (replace-match "" t t)))))
883 (defun article-remove-trailing-blank-lines ()
884 "Remove all trailing blank lines from the article."
887 (let ((buffer-read-only nil))
888 (goto-char (point-max))
892 (while (and (not (bobp))
893 (looking-at "^[ \t]*$"))
898 (defun article-display-x-face (&optional force)
899 "Look for an X-Face header and display it if present."
900 (interactive (list 'force))
902 ;; Delete the old process, if any.
903 (when (process-status "article-x-face")
904 (delete-process "article-x-face"))
905 (let ((inhibit-point-motion-hooks t)
909 (nnheader-narrow-to-headers)
910 (setq from (message-fetch-field "from"))
911 (goto-char (point-min))
912 (while (and gnus-article-x-face-command
915 ;; Check whether this face is censored.
916 (not gnus-article-x-face-too-ugly)
917 (and gnus-article-x-face-too-ugly from
918 (not (string-match gnus-article-x-face-too-ugly
920 ;; Has to be present.
921 (re-search-forward "^X-Face: " nil t))
922 ;; This used to try to do multiple faces (`while' instead of
923 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
924 ;; work (b) it can crash some versions of Emacs (c) are
925 ;; multiple faces really something to encourage?
926 (when (stringp gnus-article-x-face-command)
928 ;; We now have the area of the buffer where the X-Face is stored.
931 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
932 ;; We display the face.
933 (if (symbolp gnus-article-x-face-command)
934 ;; The command is a lisp function, so we call it.
935 (if (gnus-functionp gnus-article-x-face-command)
936 (funcall gnus-article-x-face-command beg end)
937 (error "%s is not a function" gnus-article-x-face-command))
938 ;; The command is a string, so we interpret the command
939 ;; as a, well, command, and fork it off.
940 (let ((process-connection-type nil))
941 (process-kill-without-query
943 "article-x-face" nil shell-file-name shell-command-switch
944 gnus-article-x-face-command))
945 (process-send-region "article-x-face" beg end)
946 (process-send-eof "article-x-face"))))))))))
948 (defun gnus-article-decode-mime-words ()
949 "Decode all MIME-encoded words in the article."
952 (set-buffer gnus-article-buffer)
953 (let ((inhibit-point-motion-hooks t)
955 (rfc2047-decode-region (point-min) (point-max)))))
957 (defun gnus-article-decode-charset (&optional prompt)
958 "Decode charset-encoded text in the article.
959 If PROMPT (the prefix), prompt for a coding system to use."
962 (set-buffer gnus-article-buffer)
964 (message-narrow-to-head)
965 (let* ((inhibit-point-motion-hooks t)
966 (ct (message-fetch-field "Content-Type" t))
967 (cte (message-fetch-field "Content-Transfer-Encoding" t))
970 (mm-read-coding-system "Charset to decode: "))
972 (mm-content-type-charset ct))
974 (gnus-group-find-parameter
975 gnus-newsgroup-name 'charset))))
977 (goto-char (point-max))
979 (narrow-to-region (point) (point-max))
981 charset (and cte (intern (downcase (gnus-strip-whitespace cte)))))))))
983 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
984 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
985 (defun article-decode-rfc1522 ()
986 "Remove QP encoding from headers."
987 (let ((inhibit-point-motion-hooks t)
988 (buffer-read-only nil))
990 (message-narrow-to-head)
991 (rfc2047-decode-region (point-min) (point-max)))))
993 (defun article-de-quoted-unreadable (&optional force)
994 "Translate a quoted-printable-encoded article.
995 If FORCE, decode the article whether it is marked as quoted-printable
997 (interactive (list 'force))
999 (let ((buffer-read-only nil)
1000 (type (gnus-fetch-field "content-transfer-encoding")))
1001 (gnus-article-decode-rfc1522)
1003 (and type (string-match "quoted-printable" (downcase type))))
1004 (goto-char (point-min))
1005 (search-forward "\n\n" nil 'move)
1006 (quoted-printable-decode-region (point) (point-max))))))
1008 (defun article-mime-decode-quoted-printable-buffer ()
1009 "Decode Quoted-Printable in the current buffer."
1010 (quoted-printable-decode-region (point-min) (point-max)))
1012 (defun article-hide-pgp (&optional arg)
1013 "Toggle hiding of any PGP headers and signatures in the current article.
1014 If given a negative prefix, always show; if given a positive prefix,
1016 (interactive (gnus-article-hidden-arg))
1017 (unless (gnus-article-check-hidden-text 'pgp arg)
1019 (let ((inhibit-point-motion-hooks t)
1020 buffer-read-only beg end)
1022 (goto-char (point-min))
1023 ;; Hide the "header".
1024 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1025 (delete-region (1+ (match-beginning 0)) (match-end 0))
1027 ;; Hide the actual signature.
1028 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1029 (setq end (1+ (match-beginning 0)))
1032 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1034 ;; Perhaps we shouldn't hide to the end of the buffer
1035 ;; if there is no end to the signature?
1037 ;; Hide "- " PGP quotation markers.
1039 (narrow-to-region beg end)
1040 (goto-char (point-min))
1041 (while (re-search-forward "^- " nil t)
1043 (match-beginning 0) (match-end 0)))
1045 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1047 (defun article-hide-pem (&optional arg)
1048 "Toggle hiding of any PEM headers and signatures in the current article.
1049 If given a negative prefix, always show; if given a positive prefix,
1051 (interactive (gnus-article-hidden-arg))
1052 (unless (gnus-article-check-hidden-text 'pem arg)
1054 (let (buffer-read-only end)
1056 (goto-char (point-min))
1057 ;; hide the horrendously ugly "header".
1058 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1061 (setq end (1+ (match-beginning 0)))
1062 (gnus-article-hide-text-type
1064 (if (search-forward "\n\n" nil t)
1068 ;; hide the trailer as well
1069 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1072 (gnus-article-hide-text-type
1073 (match-beginning 0) (match-end 0) 'pem))))))
1075 (defun article-hide-signature (&optional arg)
1076 "Hide the signature in the current article.
1077 If given a negative prefix, always show; if given a positive prefix,
1079 (interactive (gnus-article-hidden-arg))
1080 (unless (gnus-article-check-hidden-text 'signature arg)
1083 (let ((buffer-read-only nil))
1084 (when (gnus-article-narrow-to-signature)
1085 (gnus-article-hide-text-type
1086 (point-min) (point-max) 'signature)))))))
1088 (defun article-strip-leading-blank-lines ()
1089 "Remove all blank lines from the beginning of the article."
1092 (let ((inhibit-point-motion-hooks t)
1094 (goto-char (point-min))
1095 (when (search-forward "\n\n" nil t)
1096 (while (and (not (eobp))
1097 (looking-at "[ \t]*$"))
1098 (gnus-delete-line))))))
1100 (defun article-strip-multiple-blank-lines ()
1101 "Replace consecutive blank lines with one empty line."
1104 (let ((inhibit-point-motion-hooks t)
1106 ;; First make all blank lines empty.
1107 (goto-char (point-min))
1108 (search-forward "\n\n" nil t)
1109 (while (re-search-forward "^[ \t]+$" nil t)
1110 (replace-match "" nil t))
1111 ;; Then replace multiple empty lines with a single empty line.
1112 (goto-char (point-min))
1113 (search-forward "\n\n" nil t)
1114 (while (re-search-forward "\n\n\n+" nil t)
1115 (replace-match "\n\n" t t)))))
1117 (defun article-strip-leading-space ()
1118 "Remove all white space from the beginning of the lines in the article."
1121 (let ((inhibit-point-motion-hooks t)
1123 (goto-char (point-min))
1124 (search-forward "\n\n" nil t)
1125 (while (re-search-forward "^[ \t]+" nil t)
1126 (replace-match "" t t)))))
1128 (defun article-strip-blank-lines ()
1129 "Strip leading, trailing and multiple blank lines."
1131 (article-strip-leading-blank-lines)
1132 (article-remove-trailing-blank-lines)
1133 (article-strip-multiple-blank-lines))
1135 (defun article-strip-all-blank-lines ()
1136 "Strip all blank lines."
1139 (let ((inhibit-point-motion-hooks t)
1141 (goto-char (point-min))
1142 (search-forward "\n\n" nil t)
1143 (while (re-search-forward "^[ \t]*\n" nil t)
1144 (replace-match "" t t)))))
1146 (defvar mime::preview/content-list)
1147 (defvar mime::preview-content-info/point-min)
1148 (defun gnus-article-narrow-to-signature ()
1149 "Narrow to the signature; return t if a signature is found, else nil."
1151 (let ((inhibit-point-motion-hooks t))
1152 (when (and (boundp 'mime::preview/content-list)
1153 mime::preview/content-list)
1154 ;; We have a MIMEish article, so we use the MIME data to narrow.
1155 (let ((pcinfo (car (last mime::preview/content-list))))
1158 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1161 (when (gnus-article-search-signature)
1163 ;; Check whether we have some limits to what we consider
1164 ;; to be a signature.
1165 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1166 (list gnus-signature-limit)))
1168 (while (setq limit (pop limits))
1169 (if (or (and (integerp limit)
1170 (< (- (point-max) (point)) limit))
1172 (< (count-lines (point) (point-max)) limit))
1173 (and (gnus-functionp limit)
1175 (and (stringp limit)
1176 (not (re-search-forward limit nil t))))
1177 () ; This limit did not succeed.
1181 (narrow-to-region (point) (point-max))
1184 (defun gnus-article-search-signature ()
1185 "Search the current buffer for the signature separator.
1186 Put point at the beginning of the signature separator."
1187 (let ((cur (point)))
1188 (goto-char (point-max))
1189 (if (if (stringp gnus-signature-separator)
1190 (re-search-backward gnus-signature-separator nil t)
1191 (let ((seps gnus-signature-separator))
1193 (not (re-search-backward (car seps) nil t)))
1201 (autoload 'w3-display "w3-parse")
1202 (autoload 'w3-do-setup "w3" "" t)
1203 (autoload 'w3-region "w3-display" "" t))
1205 (defun gnus-article-treat-html ()
1208 (let ((cbuf (current-buffer)))
1209 (set-buffer gnus-article-buffer)
1210 (let (buf buffer-read-only b e)
1212 (goto-char (point-min))
1214 (if (search-forward "\n\n" nil t)
1217 (setq e (point-max)))
1219 (insert-buffer-substring gnus-article-buffer b e)
1221 (save-window-excursion
1222 (w3-region (point-min) (point-max))
1223 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1225 (delete-region (point-min) (point-max))
1228 (goto-char (point-min))
1229 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1230 (set-buffer cbuf))))
1232 (defun gnus-article-hidden-arg ()
1233 "Return the current prefix arg as a number, or 0 if no prefix."
1234 (list (if current-prefix-arg
1235 (prefix-numeric-value current-prefix-arg)
1238 (defun gnus-article-check-hidden-text (type arg)
1239 "Return nil if hiding is necessary.
1240 Arg can be nil or a number. Nil and positive means hide, negative
1241 means show, 0 means toggle."
1245 (let ((hide (gnus-article-hidden-text-p type)))
1251 (gnus-article-show-hidden-text type))
1253 (if (eq hide 'hidden)
1254 (gnus-article-show-hidden-text type)
1257 (defun gnus-article-hidden-text-p (type)
1258 "Say whether the current buffer contains hidden text of type TYPE."
1259 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1261 (not (get-text-property pos 'invisible)))
1263 (text-property-any (1+ pos) (point-max) 'article-type type)))
1268 (defun gnus-article-show-hidden-text (type &optional hide)
1269 "Show all hidden text of type TYPE.
1270 If HIDE, hide the text instead."
1272 (let ((buffer-read-only nil)
1273 (inhibit-point-motion-hooks t)
1276 (while (setq beg (text-property-any end (point-max) 'article-type type))
1279 (text-property-not-all beg (point-max) 'article-type type)
1282 (gnus-article-hide-text beg end gnus-hidden-properties)
1283 (gnus-article-unhide-text beg end))
1287 (defconst article-time-units
1288 `((year . ,(* 365.25 24 60 60))
1289 (week . ,(* 7 24 60 60))
1290 (day . ,(* 24 60 60))
1294 "Mapping from time units to seconds.")
1296 (defun article-date-ut (&optional type highlight header)
1297 "Convert DATE date to universal time in the current article.
1298 If TYPE is `local', convert to local time; if it is `lapsed', output
1299 how much time has lapsed since DATE."
1300 (interactive (list 'ut t))
1301 (let* ((header (or header
1302 (mail-header-date gnus-current-headers)
1303 (message-fetch-field "date")
1305 (date (if (vectorp header) (mail-header-date header)
1307 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1308 (inhibit-point-motion-hooks t)
1309 bface eface newline)
1310 (when (and date (not (string= date "")))
1313 (nnheader-narrow-to-headers)
1314 (let ((buffer-read-only nil))
1315 ;; Delete any old Date headers.
1316 (if (re-search-forward date-regexp nil t)
1318 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1319 eface (get-text-property (1- (gnus-point-at-eol))
1321 (delete-region (progn (beginning-of-line) (point))
1322 (progn (end-of-line) (point)))
1323 (beginning-of-line))
1324 (goto-char (point-max))
1326 (insert (article-make-date-line date type))
1329 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1330 (put-text-property (match-beginning 1) (1+ (match-end 1))
1332 (put-text-property (match-beginning 2) (match-end 2)
1336 (insert "\n"))))))))
1338 (defun article-make-date-line (date type)
1339 "Return a DATE line of TYPE."
1341 ;; Convert to the local timezone. We have to slap a
1342 ;; `condition-case' round the calls to the timezone
1343 ;; functions since they aren't particularly resistant to
1346 (concat "Date: " (current-time-string (date-to-time date))))
1347 ;; Convert to Universal Time.
1350 (current-time-string
1351 (let ((e (parse-time-string date)))
1354 ;; Get the original date from the article.
1355 ((eq type 'original)
1356 (concat "Date: " date))
1357 ;; Let the user define the format.
1359 (if (gnus-functionp gnus-article-time-format)
1360 (funcall gnus-article-time-format (date-to-time date))
1363 (format-time-string gnus-article-time-format (date-to-time date)))))
1368 (format-time-string "%Y%M%DT%h%m%s" (date-to-time date))))
1369 ;; Do an X-Sent lapsed format.
1371 ;; If the date is seriously mangled, the timezone functions are
1372 ;; liable to bug out, so we ignore all errors.
1373 (let* ((now (current-time))
1374 (real-time (subtract-time now (date-to-time date)))
1375 (real-sec (and real-time
1376 (+ (* (float (car real-time)) 65536)
1378 (sec (and real-time (abs real-sec)))
1388 ;; This is a bit convoluted, but basically we go
1389 ;; through the time units for years, weeks, etc,
1390 ;; and divide things to see whether that results
1391 ;; in positive answers.
1394 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1395 ;; The (remaining) seconds are too few to
1396 ;; be divided into this time unit.
1398 ;; It's big enough, so we output it.
1399 (setq sec (- sec (* num (cdr unit))))
1401 (concat (if prev ", " "") (int-to-string
1403 " " (symbol-name (car unit))
1404 (if (> num 1) "s" ""))
1406 article-time-units "")
1407 ;; If dates are odd, then it might appear like the
1408 ;; article was sent in the future.
1411 " in the future"))))))
1413 (error "Unknown conversion type: %s" type))))
1415 (defun article-date-local (&optional highlight)
1416 "Convert the current article date to the local timezone."
1417 (interactive (list t))
1418 (article-date-ut 'local highlight))
1420 (defun article-date-original (&optional highlight)
1421 "Convert the current article date to what it was originally.
1422 This is only useful if you have used some other date conversion
1423 function and want to see what the date was before converting."
1424 (interactive (list t))
1425 (article-date-ut 'original highlight))
1427 (defun article-date-lapsed (&optional highlight)
1428 "Convert the current article date to time lapsed since it was sent."
1429 (interactive (list t))
1430 (article-date-ut 'lapsed highlight))
1432 (defun article-update-date-lapsed ()
1433 "Function to be run from a timer to update the lapsed time line."
1434 (let (deactivate-mark)
1437 (when (gnus-buffer-live-p gnus-article-buffer)
1438 (set-buffer gnus-article-buffer)
1439 (goto-char (point-min))
1440 (when (re-search-forward "^X-Sent:" nil t)
1441 (article-date-lapsed t)))))))
1443 (defun gnus-start-date-timer (&optional n)
1444 "Start a timer to update the X-Sent header in the article buffers.
1445 The numerical prefix says how frequently (in seconds) the function
1450 (gnus-stop-date-timer)
1451 (setq article-lapsed-timer
1452 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1454 (defun gnus-stop-date-timer ()
1455 "Stop the X-Sent timer."
1457 (when article-lapsed-timer
1458 (nnheader-cancel-timer article-lapsed-timer)
1459 (setq article-lapsed-timer nil)))
1461 (defun article-date-user (&optional highlight)
1462 "Convert the current article date to the user-defined format.
1463 This format is defined by the `gnus-article-time-format' variable."
1464 (interactive (list t))
1465 (article-date-ut 'user highlight))
1467 (defun article-date-iso8601 (&optional highlight)
1468 "Convert the current article date to ISO8601."
1469 (interactive (list t))
1470 (article-date-ut 'iso8601 highlight))
1472 (defun article-show-all ()
1473 "Show all hidden text in the article buffer."
1476 (let ((buffer-read-only nil))
1477 (gnus-article-unhide-text (point-min) (point-max)))))
1479 (defun article-emphasize (&optional arg)
1480 "Emphasize text according to `gnus-emphasis-alist'."
1481 (interactive (gnus-article-hidden-arg))
1482 (unless (gnus-article-check-hidden-text 'emphasis arg)
1484 (let ((alist gnus-emphasis-alist)
1485 (buffer-read-only nil)
1486 (props (append '(article-type emphasis)
1487 gnus-hidden-properties))
1488 regexp elem beg invisible visible face)
1489 (goto-char (point-min))
1490 (search-forward "\n\n" nil t)
1492 (while (setq elem (pop alist))
1494 (setq regexp (car elem)
1495 invisible (nth 1 elem)
1496 visible (nth 2 elem)
1498 (while (re-search-forward regexp nil t)
1499 (when (and (match-beginning visible) (match-beginning invisible))
1500 (gnus-article-hide-text
1501 (match-beginning invisible) (match-end invisible) props)
1502 (gnus-article-unhide-text-type
1503 (match-beginning visible) (match-end visible) 'emphasis)
1504 (gnus-put-text-property-excluding-newlines
1505 (match-beginning visible) (match-end visible) 'face face)
1506 (goto-char (match-end invisible)))))))))
1508 (defvar gnus-summary-article-menu)
1509 (defvar gnus-summary-post-menu)
1511 ;;; Saving functions.
1513 (defun gnus-article-save (save-buffer file &optional num)
1514 "Save the currently selected article."
1515 (unless gnus-save-all-headers
1516 ;; Remove headers according to `gnus-saved-headers'.
1517 (let ((gnus-visible-headers
1518 (or gnus-saved-headers gnus-visible-headers))
1519 (gnus-article-buffer save-buffer))
1521 (set-buffer save-buffer)
1522 (article-hide-headers 1 t))))
1523 (save-window-excursion
1524 (if (not gnus-default-article-saver)
1525 (error "No default saver is defined")
1526 ;; !!! Magic! The saving functions all save
1527 ;; `gnus-original-article-buffer' (or so they think), but we
1528 ;; bind that variable to our save-buffer.
1529 (set-buffer gnus-article-buffer)
1530 (let* ((gnus-save-article-buffer save-buffer)
1533 ((not gnus-prompt-before-saving) 'default)
1534 ((eq gnus-prompt-before-saving 'always) nil)
1536 (gnus-number-of-articles-to-be-saved
1537 (when (eq gnus-prompt-before-saving t)
1539 (set-buffer gnus-article-current-summary)
1540 (funcall gnus-default-article-saver filename)))))
1542 (defun gnus-read-save-file-name (prompt &optional filename
1543 function group headers variable)
1545 (funcall function group headers (symbol-value variable)))
1550 ((eq filename 'default)
1556 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1559 (if (and gnus-number-of-articles-to-be-saved
1560 (> gnus-number-of-articles-to-be-saved 1))
1561 (format "these %d articles"
1562 gnus-number-of-articles-to-be-saved)
1565 ;; Let the split methods have their say.
1567 ;; No split name was found.
1570 (concat prompt " (default "
1571 (file-name-nondirectory default-name) ") ")
1572 (file-name-directory default-name)
1574 ;; A single group name is returned.
1575 ((stringp split-name)
1577 (funcall function split-name headers
1578 (symbol-value variable)))
1580 (concat prompt " (default "
1581 (file-name-nondirectory default-name) ") ")
1582 (file-name-directory default-name)
1584 ;; A single split name was found
1585 ((= 1 (length split-name))
1586 (let* ((name (expand-file-name
1587 (car split-name) gnus-article-save-directory))
1588 (dir (cond ((file-directory-p name)
1589 (file-name-as-directory name))
1590 ((file-exists-p name) name)
1591 (t gnus-article-save-directory))))
1593 (concat prompt " (default " name ") ")
1595 ;; A list of splits was found.
1597 (setq split-name (nreverse split-name))
1599 (let ((file-name-history
1600 (nconc split-name file-name-history)))
1604 (concat prompt " (`M-p' for defaults) ")
1605 gnus-article-save-directory
1607 gnus-article-save-directory)))
1608 (car (push result file-name-history)))))))
1609 ;; Create the directory.
1610 (gnus-make-directory (file-name-directory file))
1611 ;; If we have read a directory, we append the default file name.
1612 (when (file-directory-p file)
1613 (setq file (concat (file-name-as-directory file)
1614 (file-name-nondirectory default-name))))
1615 ;; Possibly translate some characters.
1616 (nnheader-translate-file-chars file)))))
1617 (gnus-make-directory (file-name-directory result))
1618 (set variable result)))
1620 (defun gnus-article-archive-name (group)
1621 "Return the first instance of an \"Archive-name\" in the current buffer."
1622 (let ((case-fold-search t))
1623 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1624 (nnheader-concat gnus-article-save-directory
1625 (match-string 1)))))
1627 (defun gnus-article-nndoc-name (group)
1628 "If GROUP is an nndoc group, return the name of the parent group."
1629 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1630 (gnus-group-get-parameter group 'save-article-group)))
1632 (defun gnus-summary-save-in-rmail (&optional filename)
1633 "Append this article to Rmail file.
1634 Optional argument FILENAME specifies file name.
1635 Directory to save to is default to `gnus-article-save-directory'."
1636 (setq filename (gnus-read-save-file-name
1637 "Save %s in rmail file:" filename
1638 gnus-rmail-save-name gnus-newsgroup-name
1639 gnus-current-headers 'gnus-newsgroup-last-rmail))
1640 (gnus-eval-in-buffer-window gnus-save-article-buffer
1644 (rmail-output-to-rmail-file filename))))
1647 (defun gnus-summary-save-in-mail (&optional filename)
1648 "Append this article to Unix mail file.
1649 Optional argument FILENAME specifies file name.
1650 Directory to save to is default to `gnus-article-save-directory'."
1651 (setq filename (gnus-read-save-file-name
1652 "Save %s in Unix mail file:" filename
1653 gnus-mail-save-name gnus-newsgroup-name
1654 gnus-current-headers 'gnus-newsgroup-last-mail))
1655 (gnus-eval-in-buffer-window gnus-save-article-buffer
1659 (if (and (file-readable-p filename)
1660 (mail-file-babyl-p filename))
1661 (rmail-output-to-rmail-file filename t)
1662 (gnus-output-to-mail filename)))))
1665 (defun gnus-summary-save-in-file (&optional filename overwrite)
1666 "Append this article to file.
1667 Optional argument FILENAME specifies file name.
1668 Directory to save to is default to `gnus-article-save-directory'."
1669 (setq filename (gnus-read-save-file-name
1670 "Save %s in file:" filename
1671 gnus-file-save-name gnus-newsgroup-name
1672 gnus-current-headers 'gnus-newsgroup-last-file))
1673 (gnus-eval-in-buffer-window gnus-save-article-buffer
1677 (when (and overwrite
1678 (file-exists-p filename))
1679 (delete-file filename))
1680 (gnus-output-to-file filename))))
1683 (defun gnus-summary-write-to-file (&optional filename)
1684 "Write this article to a file.
1685 Optional argument FILENAME specifies file name.
1686 The directory to save in defaults to `gnus-article-save-directory'."
1687 (gnus-summary-save-in-file nil t))
1689 (defun gnus-summary-save-body-in-file (&optional filename)
1690 "Append this article body to a file.
1691 Optional argument FILENAME specifies file name.
1692 The directory to save in defaults to `gnus-article-save-directory'."
1693 (setq filename (gnus-read-save-file-name
1694 "Save %s body in file:" filename
1695 gnus-file-save-name gnus-newsgroup-name
1696 gnus-current-headers 'gnus-newsgroup-last-file))
1697 (gnus-eval-in-buffer-window gnus-save-article-buffer
1701 (goto-char (point-min))
1702 (when (search-forward "\n\n" nil t)
1703 (narrow-to-region (point) (point-max)))
1704 (gnus-output-to-file filename))))
1707 (defun gnus-summary-save-in-pipe (&optional command)
1708 "Pipe this article to subprocess."
1710 (cond ((eq command 'default)
1711 gnus-last-shell-command)
1715 "Shell command on %s: "
1716 (if (and gnus-number-of-articles-to-be-saved
1717 (> gnus-number-of-articles-to-be-saved 1))
1718 (format "these %d articles"
1719 gnus-number-of-articles-to-be-saved)
1721 gnus-last-shell-command))))
1722 (when (string-equal command "")
1723 (setq command gnus-last-shell-command))
1724 (gnus-eval-in-buffer-window gnus-article-buffer
1727 (shell-command-on-region (point-min) (point-max) command nil)))
1728 (setq gnus-last-shell-command command))
1730 ;;; Article file names when saving.
1732 (defun gnus-capitalize-newsgroup (newsgroup)
1733 "Capitalize NEWSGROUP name."
1734 (when (not (zerop (length newsgroup)))
1735 (concat (char-to-string (upcase (aref newsgroup 0)))
1736 (substring newsgroup 1))))
1738 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1739 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1740 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1741 Otherwise, it is like ~/News/news/group/num."
1744 (concat (if (gnus-use-long-file-name 'not-save)
1745 (gnus-capitalize-newsgroup newsgroup)
1746 (gnus-newsgroup-directory-form newsgroup))
1747 "/" (int-to-string (mail-header-number headers)))
1748 gnus-article-save-directory)))
1750 (string-equal (file-name-directory default)
1751 (file-name-directory last-file))
1752 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1754 (or last-file default))))
1756 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1757 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1758 If variable `gnus-use-long-file-name' is non-nil, it is
1759 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1762 (concat (if (gnus-use-long-file-name 'not-save)
1764 (gnus-newsgroup-directory-form newsgroup))
1765 "/" (int-to-string (mail-header-number headers)))
1766 gnus-article-save-directory)))
1768 (string-equal (file-name-directory default)
1769 (file-name-directory last-file))
1770 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1772 (or last-file default))))
1774 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1775 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1776 If variable `gnus-use-long-file-name' is non-nil, it is
1777 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1780 (if (gnus-use-long-file-name 'not-save)
1781 (gnus-capitalize-newsgroup newsgroup)
1782 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1783 gnus-article-save-directory)))
1785 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1786 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1787 If variable `gnus-use-long-file-name' is non-nil, it is
1788 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1791 (if (gnus-use-long-file-name 'not-save)
1793 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1794 gnus-article-save-directory)))
1801 (setq afunc (car func)
1804 gfunc (intern (format "gnus-%s" func))))
1806 (if (not (fboundp afunc))
1808 `(lambda (&optional interactive &rest args)
1809 ,(documentation afunc t)
1810 (interactive (list t))
1812 (set-buffer gnus-article-buffer)
1814 (call-interactively ',afunc)
1815 (apply ',afunc args))))))))
1816 '(article-hide-headers
1817 article-hide-boring-headers
1818 article-treat-overstrike
1819 (article-fill . gnus-article-word-wrap)
1821 article-display-x-face
1822 article-de-quoted-unreadable
1823 article-mime-decode-quoted-printable
1826 article-hide-signature
1827 article-remove-trailing-blank-lines
1828 article-strip-leading-blank-lines
1829 article-strip-multiple-blank-lines
1830 article-strip-leading-space
1831 article-strip-blank-lines
1832 article-strip-all-blank-lines
1834 article-date-iso8601
1835 article-date-original
1840 article-treat-dumbquotes
1841 (article-show-all . gnus-article-show-all-headers))))
1844 ;;; Gnus article mode
1847 (put 'gnus-article-mode 'mode-class 'special)
1849 (gnus-define-keys gnus-article-mode-map
1850 " " gnus-article-goto-next-page
1851 "\177" gnus-article-goto-prev-page
1852 [delete] gnus-article-goto-prev-page
1853 "\C-c^" gnus-article-refer-article
1854 "h" gnus-article-show-summary
1855 "s" gnus-article-show-summary
1856 "\C-c\C-m" gnus-article-mail
1857 "?" gnus-article-describe-briefly
1858 gnus-mouse-2 gnus-article-push-button
1859 "\r" gnus-article-press-button
1860 "\t" gnus-article-next-button
1861 "\M-\t" gnus-article-prev-button
1862 "e" gnus-article-edit
1863 "<" beginning-of-buffer
1865 "\C-c\C-i" gnus-info-find-node
1868 "\C-d" gnus-article-read-summary-keys
1869 "\M-*" gnus-article-read-summary-keys
1870 "\M-#" gnus-article-read-summary-keys
1871 "\M-^" gnus-article-read-summary-keys
1872 "\M-g" gnus-article-read-summary-keys)
1874 (substitute-key-definition
1875 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1877 (defun gnus-article-make-menu-bar ()
1878 (gnus-turn-off-edit-menu 'article)
1879 (unless (boundp 'gnus-article-article-menu)
1881 gnus-article-article-menu gnus-article-mode-map ""
1883 ["Scroll forwards" gnus-article-goto-next-page t]
1884 ["Scroll backwards" gnus-article-goto-prev-page t]
1885 ["Show summary" gnus-article-show-summary t]
1886 ["Fetch Message-ID at point" gnus-article-refer-article t]
1887 ["Mail to address at point" gnus-article-mail t]
1888 ["Send a bug report" gnus-bug t]))
1891 gnus-article-treatment-menu gnus-article-mode-map ""
1893 ["Hide headers" gnus-article-hide-headers t]
1894 ["Hide signature" gnus-article-hide-signature t]
1895 ["Hide citation" gnus-article-hide-citation t]
1896 ["Treat overstrike" gnus-article-treat-overstrike t]
1897 ["Remove carriage return" gnus-article-remove-cr t]
1898 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1900 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1902 (when (boundp 'gnus-summary-post-menu)
1903 (define-key gnus-article-mode-map [menu-bar post]
1904 (cons "Post" gnus-summary-post-menu)))
1906 (gnus-run-hooks 'gnus-article-menu-hook)))
1908 (defun gnus-article-mode ()
1909 "Major mode for displaying an article.
1911 All normal editing commands are switched off.
1913 The following commands are available in addition to all summary mode
1915 \\<gnus-article-mode-map>
1916 \\[gnus-article-next-page]\t Scroll the article one page forwards
1917 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1918 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1919 \\[gnus-article-show-summary]\t Display the summary buffer
1920 \\[gnus-article-mail]\t Send a reply to the address near point
1921 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1922 \\[gnus-info-find-node]\t Go to the Gnus info node"
1924 (when (gnus-visual-p 'article-menu 'menu)
1925 (gnus-article-make-menu-bar))
1926 (gnus-simplify-mode-line)
1927 (setq mode-name "Article")
1928 (setq major-mode 'gnus-article-mode)
1929 (make-local-variable 'minor-mode-alist)
1930 (unless (assq 'gnus-show-mime minor-mode-alist)
1931 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1932 (use-local-map gnus-article-mode-map)
1933 (gnus-update-format-specifications nil 'article-mode)
1934 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1935 (make-local-variable 'gnus-page-broken)
1936 (make-local-variable 'gnus-button-marker-list)
1937 (make-local-variable 'gnus-article-current-summary)
1938 (gnus-set-default-directory)
1939 (buffer-disable-undo (current-buffer))
1940 (setq buffer-read-only t)
1941 (set-syntax-table gnus-article-mode-syntax-table)
1942 (mm-enable-multibyte)
1943 (gnus-run-hooks 'gnus-article-mode-hook))
1945 (defun gnus-article-setup-buffer ()
1946 "Initialize the article buffer."
1947 (let* ((name (if gnus-single-article-buffer "*Article*"
1948 (concat "*Article " gnus-newsgroup-name "*")))
1950 (progn (string-match "\\*Article" name)
1951 (concat " *Original Article"
1952 (substring name (match-end 0))))))
1953 (setq gnus-article-buffer name)
1954 (setq gnus-original-article-buffer original)
1955 ;; This might be a variable local to the summary buffer.
1956 (unless gnus-single-article-buffer
1958 (set-buffer gnus-summary-buffer)
1959 (setq gnus-article-buffer name)
1960 (setq gnus-original-article-buffer original)
1961 (gnus-set-global-variables)))
1962 ;; Init original article buffer.
1964 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1965 (buffer-disable-undo (current-buffer))
1966 (setq major-mode 'gnus-original-article-mode)
1967 (make-local-variable 'gnus-original-article))
1968 (if (get-buffer name)
1971 (buffer-disable-undo (current-buffer))
1972 (setq buffer-read-only t)
1973 (unless (eq major-mode 'gnus-article-mode)
1974 (gnus-article-mode))
1977 (set-buffer (gnus-get-buffer-create name))
1979 (make-local-variable 'gnus-summary-buffer)
1980 (current-buffer)))))
1982 ;; Set article window start at LINE, where LINE is the number of lines
1983 ;; from the head of the article.
1984 (defun gnus-article-set-window-start (&optional line)
1986 (get-buffer-window gnus-article-buffer t)
1988 (set-buffer gnus-article-buffer)
1989 (goto-char (point-min))
1992 (gnus-message 6 "Moved to bookmark")
1993 (search-forward "\n\n" nil t)
1997 (defun gnus-article-prepare (article &optional all-headers header)
1998 "Prepare ARTICLE in article mode buffer.
1999 ARTICLE should either be an article number or a Message-ID.
2000 If ARTICLE is an id, HEADER should be the article headers.
2001 If ALL-HEADERS is non-nil, no headers are hidden."
2003 ;; Make sure we start in a summary buffer.
2004 (unless (eq major-mode 'gnus-summary-mode)
2005 (set-buffer gnus-summary-buffer))
2006 (setq gnus-summary-buffer (current-buffer))
2007 (let* ((gnus-article (if header (mail-header-number header) article))
2008 (summary-buffer (current-buffer))
2009 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2010 (group gnus-newsgroup-name)
2013 (gnus-article-setup-buffer)
2014 (set-buffer gnus-article-buffer)
2015 ;; Deactivate active regions.
2016 (when (and (boundp 'transient-mark-mode)
2017 transient-mark-mode)
2018 (setq mark-active nil))
2019 (if (not (setq result (let ((buffer-read-only nil))
2020 (gnus-request-article-this-buffer
2022 ;; There is no such article.
2024 (when (and (numberp article)
2025 (not (memq article gnus-newsgroup-sparse)))
2026 (setq gnus-article-current
2027 (cons gnus-newsgroup-name article))
2028 (set-buffer gnus-summary-buffer)
2029 (setq gnus-current-article article)
2030 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2032 (gnus-summary-set-agent-mark article)
2033 (message "Message marked for downloading"))
2034 (gnus-summary-mark-article article gnus-canceled-mark)
2035 (unless (memq article gnus-newsgroup-sparse)
2037 "No such article (may have expired or been canceled)")))))
2038 (if (or (eq result 'pseudo)
2039 (eq result 'nneething))
2042 (set-buffer summary-buffer)
2043 (push article gnus-newsgroup-history)
2044 (setq gnus-last-article gnus-current-article
2045 gnus-current-article 0
2046 gnus-current-headers nil
2047 gnus-article-current nil)
2048 (if (eq result 'nneething)
2049 (gnus-configure-windows 'summary)
2050 (gnus-configure-windows 'article))
2051 (gnus-set-global-variables))
2052 (gnus-set-mode-line 'article))
2053 ;; The result from the `request' was an actual article -
2054 ;; or at least some text that is now displayed in the
2056 (when (and (numberp article)
2057 (not (eq article gnus-current-article)))
2058 ;; Seems like a new article has been selected.
2059 ;; `gnus-current-article' must be an article number.
2061 (set-buffer summary-buffer)
2062 (push article gnus-newsgroup-history)
2063 (setq gnus-last-article gnus-current-article
2064 gnus-current-article article
2065 gnus-current-headers
2066 (gnus-summary-article-header gnus-current-article)
2067 gnus-article-current
2068 (cons gnus-newsgroup-name gnus-current-article))
2069 (unless (vectorp gnus-current-headers)
2070 (setq gnus-current-headers nil))
2071 (gnus-summary-goto-subject gnus-current-article)
2072 (when (gnus-summary-show-thread)
2073 ;; If the summary buffer really was folded, the
2074 ;; previous goto may not actually have gone to
2075 ;; the right article, but the thread root instead.
2077 (gnus-summary-goto-subject gnus-current-article))
2078 (gnus-run-hooks 'gnus-mark-article-hook)
2079 (gnus-set-mode-line 'summary)
2080 (when (gnus-visual-p 'article-highlight 'highlight)
2081 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2082 ;; Set the global newsgroup variables here.
2083 ;; Suggested by Jim Sisolak
2084 ;; <sisolak@trans4.neep.wisc.edu>.
2085 (gnus-set-global-variables)
2086 (setq gnus-have-all-headers
2087 (or all-headers gnus-show-all-headers))))
2088 (when (or (numberp article)
2090 ;; Hooks for getting information from the article.
2091 ;; This hook must be called before being narrowed.
2092 (let (buffer-read-only)
2093 (gnus-run-hooks 'gnus-tmp-internal-hook)
2094 (gnus-run-hooks 'gnus-article-prepare-hook)
2095 ;; Decode MIME message.
2096 (when gnus-show-mime
2097 (if (or (not gnus-strict-mime)
2098 (gnus-fetch-field "Mime-Version"))
2099 (let ((coding-system-for-write 'binary)
2100 (coding-system-for-read 'binary))
2101 (funcall gnus-show-mime-method))
2102 (funcall gnus-decode-encoded-word-method)))
2103 ;; Perform the article display hooks.
2104 (gnus-run-hooks 'gnus-article-display-hook))
2106 (goto-char (point-min))
2107 (setq gnus-page-broken
2108 (when gnus-break-pages
2109 (gnus-narrow-to-page)
2111 (gnus-set-mode-line 'article)
2112 (gnus-configure-windows 'article)
2113 (goto-char (point-min))
2114 (search-forward "\n\n" nil t)
2115 (set-window-point (get-buffer-window (current-buffer)) (point))
2118 (defun gnus-article-wash-status ()
2119 "Return a string which display status of article washing."
2121 (set-buffer gnus-article-buffer)
2122 (let ((cite (gnus-article-hidden-text-p 'cite))
2123 (headers (gnus-article-hidden-text-p 'headers))
2124 (boring (gnus-article-hidden-text-p 'boring-headers))
2125 (pgp (gnus-article-hidden-text-p 'pgp))
2126 (pem (gnus-article-hidden-text-p 'pem))
2127 (signature (gnus-article-hidden-text-p 'signature))
2128 (overstrike (gnus-article-hidden-text-p 'overstrike))
2129 (emphasis (gnus-article-hidden-text-p 'emphasis))
2130 (mime gnus-show-mime))
2131 (format "%c%c%c%c%c%c%c"
2133 (if (or headers boring) ?h ? )
2134 (if (or pgp pem) ?p ? )
2135 (if signature ?s ? )
2136 (if overstrike ?o ? )
2138 (if emphasis ?e ? )))))
2140 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2142 (defun gnus-article-maybe-hide-headers ()
2143 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2144 Provided for backwards compatibility."
2145 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2147 (gnus-article-hide-headers)))
2151 (defun gnus-output-to-file (file-name)
2152 "Append the current article to a file named FILE-NAME."
2153 (let ((artbuf (current-buffer)))
2155 (insert-buffer-substring artbuf)
2156 ;; Append newline at end of the buffer as separator, and then
2158 (goto-char (point-max))
2160 (append-to-file (point-min) (point-max) file-name)
2163 (defun gnus-narrow-to-page (&optional arg)
2164 "Narrow the article buffer to a page.
2165 If given a numerical ARG, move forward ARG pages."
2167 (setq arg (if arg (prefix-numeric-value arg) 0))
2169 (set-buffer gnus-article-buffer)
2170 (goto-char (point-min))
2172 ;; Remove any old next/prev buttons.
2173 (when (gnus-visual-p 'page-marker)
2174 (let ((buffer-read-only nil))
2175 (gnus-remove-text-with-property 'gnus-prev)
2176 (gnus-remove-text-with-property 'gnus-next)))
2179 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2181 (re-search-forward page-delimiter nil 'move arg)))
2182 (goto-char (match-end 0)))
2185 (if (re-search-forward page-delimiter nil 'move)
2188 (when (and (gnus-visual-p 'page-marker)
2189 (not (= (point-min) 1)))
2191 (goto-char (point-min))
2192 (gnus-insert-prev-page-button)))
2193 (when (and (gnus-visual-p 'page-marker)
2194 (< (+ (point-max) 2) (buffer-size)))
2196 (goto-char (point-max))
2197 (gnus-insert-next-page-button)))))
2199 ;; Article mode commands
2201 (defun gnus-article-goto-next-page ()
2202 "Show the next page of the article."
2204 (when (gnus-article-next-page)
2205 (goto-char (point-min))
2206 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2208 (defun gnus-article-goto-prev-page ()
2209 "Show the next page of the article."
2211 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2212 (gnus-article-prev-page nil)))
2214 (defun gnus-article-next-page (&optional lines)
2215 "Show the next page of the current article.
2216 If end of article, return non-nil. Otherwise return nil.
2217 Argument LINES specifies lines to be scrolled up."
2219 (move-to-window-line -1)
2222 (and (pos-visible-in-window-p) ;Not continuation line.
2224 ;; Nothing in this page.
2225 (if (or (not gnus-page-broken)
2228 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2230 (gnus-narrow-to-page 1) ;Go to next page.
2232 ;; More in this page.
2233 (let ((scroll-in-place nil))
2237 ;; Long lines may cause an end-of-buffer error.
2238 (goto-char (point-max)))))
2239 (move-to-window-line 0)
2242 (defun gnus-article-prev-page (&optional lines)
2243 "Show previous page of current article.
2244 Argument LINES specifies lines to be scrolled down."
2246 (move-to-window-line 0)
2247 (if (and gnus-page-broken
2249 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2251 (gnus-narrow-to-page -1) ;Go to previous page.
2252 (goto-char (point-max))
2254 (let ((scroll-in-place nil))
2258 (beginning-of-buffer
2259 (goto-char (point-min))))
2260 (move-to-window-line 0)))))
2262 (defun gnus-article-refer-article ()
2263 "Read article specified by message-id around point."
2265 (let ((point (point)))
2266 (search-forward ">" nil t) ;Move point to end of "<....>".
2267 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2268 (let ((message-id (match-string 1)))
2270 (set-buffer gnus-summary-buffer)
2271 (gnus-summary-refer-article message-id))
2273 (error "No references around point"))))
2275 (defun gnus-article-show-summary ()
2276 "Reconfigure windows to show summary buffer."
2278 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2279 (error "There is no summary buffer for this article buffer")
2280 (gnus-article-set-globals)
2281 (gnus-configure-windows 'article)
2282 (gnus-summary-goto-subject gnus-current-article)
2283 (gnus-summary-position-point)))
2285 (defun gnus-article-describe-briefly ()
2286 "Describe article mode commands briefly."
2289 (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")))
2291 (defun gnus-article-summary-command ()
2292 "Execute the last keystroke in the summary buffer."
2294 (let ((obuf (current-buffer))
2295 (owin (current-window-configuration))
2297 (switch-to-buffer gnus-article-current-summary 'norecord)
2298 (setq func (lookup-key (current-local-map) (this-command-keys)))
2299 (call-interactively func)
2301 (set-window-configuration owin)
2302 (set-window-point (get-buffer-window (current-buffer)) (point))))
2304 (defun gnus-article-summary-command-nosave ()
2305 "Execute the last keystroke in the summary buffer."
2308 (pop-to-buffer gnus-article-current-summary 'norecord)
2309 (setq func (lookup-key (current-local-map) (this-command-keys)))
2310 (call-interactively func)))
2312 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2313 "Read a summary buffer key sequence and execute it from the article buffer."
2316 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2317 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2318 "=" "^" "\M-^" "|"))
2324 '("n" "Gn" "p" "Gp"))
2327 (set-buffer gnus-article-current-summary)
2328 (let (gnus-pick-mode)
2329 (push (or key last-command-event) unread-command-events)
2330 (setq keys (read-key-sequence nil))))
2333 (if (or (member keys nosaves)
2334 (member keys nosave-but-article)
2335 (member keys nosave-in-article))
2337 (save-window-excursion
2338 (pop-to-buffer gnus-article-current-summary 'norecord)
2339 ;; We disable the pick minor mode commands.
2340 (let (gnus-pick-mode)
2341 (setq func (lookup-key (current-local-map) keys))))
2344 (unless (member keys nosave-in-article)
2345 (set-buffer gnus-article-current-summary))
2346 (call-interactively func)
2347 (setq new-sum-point (point)))
2348 (when (member keys nosave-but-article)
2349 (pop-to-buffer gnus-article-buffer 'norecord)))
2350 ;; These commands should restore window configuration.
2351 (let ((obuf (current-buffer))
2352 (owin (current-window-configuration))
2354 (summary gnus-article-current-summary)
2355 func in-buffer selected)
2356 (if not-restore-window
2357 (pop-to-buffer summary 'norecord)
2358 (switch-to-buffer summary 'norecord))
2359 (setq in-buffer (current-buffer))
2360 ;; We disable the pick minor mode commands.
2361 (if (setq func (let (gnus-pick-mode)
2362 (lookup-key (current-local-map) keys)))
2364 (call-interactively func)
2365 (setq new-sum-point (point)))
2367 (when (eq in-buffer (current-buffer))
2368 (setq selected (gnus-summary-select-article))
2370 (unless not-restore-window
2371 (set-window-configuration owin))
2372 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2373 (set-window-point (get-buffer-window (current-buffer))
2375 (let ((win (get-buffer-window gnus-article-current-summary)))
2377 (set-window-point win new-sum-point))))))))
2379 (defun gnus-article-hide (&optional arg force)
2380 "Hide all the gruft in the current article.
2381 This means that PGP stuff, signatures, cited text and (some)
2382 headers will be hidden.
2383 If given a prefix, show the hidden text instead."
2384 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2385 (gnus-article-hide-headers arg)
2386 (gnus-article-hide-pgp arg)
2387 (gnus-article-hide-citation-maybe arg force)
2388 (gnus-article-hide-signature arg))
2390 (defun gnus-article-maybe-highlight ()
2391 "Do some article highlighting if article highlighting is requested."
2392 (when (gnus-visual-p 'article-highlight 'highlight)
2393 (gnus-article-highlight-some)))
2395 (defun gnus-check-group-server ()
2396 ;; Make sure the connection to the server is alive.
2397 (unless (gnus-server-opened
2398 (gnus-find-method-for-group gnus-newsgroup-name))
2399 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2400 (gnus-request-group gnus-newsgroup-name t)))
2402 (defun gnus-request-article-this-buffer (article group)
2403 "Get an article and insert it into this buffer."
2404 (let (do-update-line sparse-header)
2408 (gnus-kill-all-overlays)
2409 (setq group (or group gnus-newsgroup-name))
2411 ;; Using `gnus-request-article' directly will insert the article into
2412 ;; `nntp-server-buffer' - so we'll save some time by not having to
2413 ;; copy it from the server buffer into the article buffer.
2415 ;; We only request an article by message-id when we do not have the
2416 ;; headers for it, so we'll have to get those.
2417 (when (stringp article)
2418 (let ((gnus-override-method gnus-refer-article-method))
2419 (gnus-read-header article)))
2421 ;; If the article number is negative, that means that this article
2422 ;; doesn't belong in this newsgroup (possibly), so we find its
2423 ;; message-id and request it by id instead of number.
2424 (when (and (numberp article)
2426 (get-buffer gnus-summary-buffer)
2427 (gnus-buffer-exists-p gnus-summary-buffer))
2429 (set-buffer gnus-summary-buffer)
2430 (let ((header (gnus-summary-article-header article)))
2433 ((memq article gnus-newsgroup-sparse)
2434 ;; This is a sparse gap article.
2435 (setq do-update-line article)
2436 (setq article (mail-header-id header))
2437 (let ((gnus-override-method gnus-refer-article-method))
2438 (setq sparse-header (gnus-read-header article)))
2439 (setq gnus-newsgroup-sparse
2440 (delq article gnus-newsgroup-sparse)))
2442 ;; It's a real article.
2443 (setq article (mail-header-id header)))
2445 ;; It is an extracted pseudo-article.
2446 (setq article 'pseudo)
2447 (gnus-request-pseudo-article header))))
2449 (let ((method (gnus-find-method-for-group
2450 gnus-newsgroup-name)))
2451 (when (and (eq (car method) 'nneething)
2454 (file-name-as-directory
2455 (or (cadr (assq 'nneething-address method))
2457 (mail-header-subject header))))
2458 (when (file-directory-p dir)
2459 (setq article 'nneething)
2460 (gnus-group-enter-directory dir))))))))
2463 ;; Refuse to select canceled articles.
2464 ((and (numberp article)
2466 (get-buffer gnus-summary-buffer)
2467 (gnus-buffer-exists-p gnus-summary-buffer)
2468 (eq (cdr (save-excursion
2469 (set-buffer gnus-summary-buffer)
2470 (assq article gnus-newsgroup-reads)))
2471 gnus-canceled-mark))
2473 ;; We first check `gnus-original-article-buffer'.
2474 ((and (get-buffer gnus-original-article-buffer)
2477 (set-buffer gnus-original-article-buffer)
2478 (and (equal (car gnus-original-article) group)
2479 (eq (cdr gnus-original-article) article))))
2480 (insert-buffer-substring gnus-original-article-buffer)
2482 ;; Check the backlog.
2483 ((and gnus-keep-backlog
2484 (gnus-backlog-request-article group article (current-buffer)))
2486 ;; Check asynchronous pre-fetch.
2487 ((gnus-async-request-fetched-article group article (current-buffer))
2488 (gnus-async-prefetch-next group article gnus-summary-buffer)
2489 (when (and (numberp article) gnus-keep-backlog)
2490 (gnus-backlog-enter-article group article (current-buffer)))
2493 ((and gnus-use-cache
2495 (gnus-cache-request-article article group))
2497 ;; Get the article and put into the article buffer.
2498 ((or (stringp article) (numberp article))
2499 (let ((gnus-override-method
2500 (and (stringp article) gnus-refer-article-method))
2501 (buffer-read-only nil))
2503 (gnus-kill-all-overlays)
2504 (gnus-check-group-server)
2505 (when (gnus-request-article article group (current-buffer))
2506 (when (numberp article)
2507 (gnus-async-prefetch-next group article gnus-summary-buffer)
2508 (when gnus-keep-backlog
2509 (gnus-backlog-enter-article
2510 group article (current-buffer))))
2515 ;; Associate this article with the current summary buffer.
2516 (setq gnus-article-current-summary gnus-summary-buffer)
2518 ;; Take the article from the original article buffer
2519 ;; and place it in the buffer it's supposed to be in.
2520 (when (and (get-buffer gnus-article-buffer)
2521 (equal (buffer-name (current-buffer))
2522 (buffer-name (get-buffer gnus-article-buffer))))
2524 (if (get-buffer gnus-original-article-buffer)
2525 (set-buffer gnus-original-article-buffer)
2526 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2527 (buffer-disable-undo (current-buffer))
2528 (setq major-mode 'gnus-original-article-mode)
2529 (setq buffer-read-only t))
2530 (let (buffer-read-only)
2532 (insert-buffer-substring gnus-article-buffer))
2533 (setq gnus-original-article (cons group article))))
2535 ;; Update sparse articles.
2536 (when (and do-update-line
2537 (or (numberp article)
2539 (let ((buf (current-buffer)))
2540 (set-buffer gnus-summary-buffer)
2541 (gnus-summary-update-article do-update-line sparse-header)
2542 (gnus-summary-goto-subject do-update-line nil t)
2543 (set-window-point (get-buffer-window (current-buffer) t)
2545 (set-buffer buf))))))
2551 (defcustom gnus-article-edit-mode-hook nil
2552 "Hook run in article edit mode buffers."
2553 :group 'gnus-article-various
2556 (defvar gnus-article-edit-done-function nil)
2558 (defvar gnus-article-edit-mode-map nil)
2560 (unless gnus-article-edit-mode-map
2561 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2563 (gnus-define-keys gnus-article-edit-mode-map
2564 "\C-c\C-c" gnus-article-edit-done
2565 "\C-c\C-k" gnus-article-edit-exit)
2567 (gnus-define-keys (gnus-article-edit-wash-map
2568 "\C-c\C-w" gnus-article-edit-mode-map)
2569 "f" gnus-article-edit-full-stops))
2571 (defun gnus-article-edit-mode ()
2572 "Major mode for editing articles.
2573 This is an extended text-mode.
2575 \\{gnus-article-edit-mode-map}"
2577 (setq major-mode 'gnus-article-edit-mode)
2578 (setq mode-name "Article Edit")
2579 (use-local-map gnus-article-edit-mode-map)
2580 (make-local-variable 'gnus-article-edit-done-function)
2581 (make-local-variable 'gnus-prev-winconf)
2582 (setq buffer-read-only nil)
2583 (buffer-enable-undo)
2585 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2587 (defun gnus-article-edit (&optional force)
2588 "Edit the current article.
2589 This will have permanent effect only in mail groups.
2590 If FORCE is non-nil, allow editing of articles even in read-only
2593 (when (and (not force)
2594 (gnus-group-read-only-p))
2595 (error "The current newsgroup does not support article editing"))
2596 (gnus-article-date-original)
2597 (gnus-article-edit-article
2598 `(lambda (no-highlight)
2599 (gnus-summary-edit-article-done
2600 ,(or (mail-header-references gnus-current-headers) "")
2601 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2603 (defun gnus-article-edit-article (exit-func)
2604 "Start editing the contents of the current article buffer."
2605 (let ((winconf (current-window-configuration)))
2606 (set-buffer gnus-article-buffer)
2607 (gnus-article-edit-mode)
2608 (gnus-article-delete-text-of-type 'annotation)
2609 (gnus-set-text-properties (point-min) (point-max) nil)
2610 (gnus-configure-windows 'edit-article)
2611 (setq gnus-article-edit-done-function exit-func)
2612 (setq gnus-prev-winconf winconf)
2613 (gnus-message 6 "C-c C-c to end edits")))
2615 (defun gnus-article-edit-done (&optional arg)
2616 "Update the article edits and exit."
2621 (goto-char (point-min))
2622 (when (search-forward "\n\n" nil 1)
2623 (let ((lines (count-lines (point) (point-max)))
2624 (length (- (point-max) (point)))
2625 (case-fold-search t)
2626 (body (copy-marker (point))))
2627 (goto-char (point-min))
2628 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2629 (delete-region (match-beginning 1) (match-end 1))
2630 (insert (number-to-string length)))
2631 (goto-char (point-min))
2632 (when (re-search-forward
2633 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2634 (delete-region (match-beginning 1) (match-end 1))
2635 (insert (number-to-string length)))
2636 (goto-char (point-min))
2637 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2638 (delete-region (match-beginning 1) (match-end 1))
2639 (insert (number-to-string lines)))))))
2640 (let ((func gnus-article-edit-done-function)
2641 (buf (current-buffer))
2642 (start (window-start)))
2643 (gnus-article-edit-exit)
2646 (let ((buffer-read-only nil))
2647 (funcall func arg)))
2649 (set-window-start (get-buffer-window buf) start)
2650 (set-window-point (get-buffer-window buf) (point))))
2652 (defun gnus-article-edit-exit ()
2653 "Exit the article editing without updating."
2655 ;; We remove all text props from the article buffer.
2656 (let ((buf (format "%s" (buffer-string)))
2657 (curbuf (current-buffer))
2659 (window-start (window-start)))
2662 (let ((winconf gnus-prev-winconf))
2664 ;; The cache and backlog have to be flushed somewhat.
2665 (when gnus-use-cache
2666 (gnus-cache-update-article
2667 (car gnus-article-current) (cdr gnus-article-current)))
2668 (when gnus-keep-backlog
2669 (gnus-backlog-remove-article
2670 (car gnus-article-current) (cdr gnus-article-current)))
2671 ;; Flush original article as well.
2673 (when (get-buffer gnus-original-article-buffer)
2674 (set-buffer gnus-original-article-buffer)
2675 (setq gnus-original-article nil)))
2676 (set-window-configuration winconf)
2677 ;; Tippy-toe some to make sure that point remains where it was.
2678 (let ((buf (current-buffer)))
2680 (set-window-start (get-buffer-window (current-buffer)) window-start)
2682 (set-buffer buf)))))
2684 (defun gnus-article-edit-full-stops ()
2685 "Interactively repair spacing at end of sentences."
2688 (goto-char (point-min))
2689 (search-forward-regexp "^$" nil t)
2690 (let ((case-fold-search nil))
2691 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2694 ;;; Article highlights
2697 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2699 ;;; Internal Variables:
2701 (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\\)"
2702 "Regular expression that matches URLs."
2703 :group 'gnus-article-buttons
2706 (defcustom gnus-button-alist
2707 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2708 gnus-button-message-id 2)
2709 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2710 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2712 gnus-button-fetch-group 4)
2713 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2714 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2715 t gnus-button-message-id 3)
2716 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2717 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2718 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2719 ;; This is how URLs _should_ be embedded in text...
2720 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2722 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2723 "*Alist of regexps matching buttons in article bodies.
2725 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2726 REGEXP: is the string matching text around the button,
2727 BUTTON: is the number of the regexp grouping actually matching the button,
2728 FORM: is a lisp expression which must eval to true for the button to
2730 CALLBACK: is the function to call when the user push this button, and each
2731 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2733 CALLBACK can also be a variable, in that case the value of that
2734 variable it the real callback function."
2735 :group 'gnus-article-buttons
2736 :type '(repeat (list regexp
2737 (integer :tag "Button")
2739 (function :tag "Callback")
2742 (integer :tag "Regexp group")))))
2744 (defcustom gnus-header-button-alist
2745 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2746 0 t gnus-button-message-id 0)
2747 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2748 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2749 0 t gnus-button-mailto 0)
2750 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2751 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2752 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2753 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2754 gnus-button-message-id 3))
2755 "*Alist of headers and regexps to match buttons in article heads.
2757 This alist is very similar to `gnus-button-alist', except that each
2758 alist has an additional HEADER element first in each entry:
2760 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2762 HEADER is a regexp to match a header. For a fuller explanation, see
2763 `gnus-button-alist'."
2764 :group 'gnus-article-buttons
2765 :group 'gnus-article-headers
2766 :type '(repeat (list (regexp :tag "Header")
2768 (integer :tag "Button")
2770 (function :tag "Callback")
2773 (integer :tag "Regexp group")))))
2775 (defvar gnus-button-regexp nil)
2776 (defvar gnus-button-marker-list nil)
2777 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2779 (defvar gnus-button-last nil)
2780 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2784 (defun gnus-article-push-button (event)
2785 "Check text under the mouse pointer for a callback function.
2786 If the text under the mouse pointer has a `gnus-callback' property,
2787 call it with the value of the `gnus-data' text property."
2789 (set-buffer (window-buffer (posn-window (event-start event))))
2790 (let* ((pos (posn-point (event-start event)))
2791 (data (get-text-property pos 'gnus-data))
2792 (fun (get-text-property pos 'gnus-callback)))
2795 (funcall fun data))))
2797 (defun gnus-article-press-button ()
2798 "Check text at point for a callback function.
2799 If the text at point has a `gnus-callback' property,
2800 call it with the value of the `gnus-data' text property."
2802 (let* ((data (get-text-property (point) 'gnus-data))
2803 (fun (get-text-property (point) 'gnus-callback)))
2805 (funcall fun data))))
2807 (defun gnus-article-prev-button (n)
2808 "Move point to N buttons backward.
2809 If N is negative, move forward instead."
2811 (gnus-article-next-button (- n)))
2813 (defun gnus-article-next-button (n)
2814 "Move point to N buttons forward.
2815 If N is negative, move backward instead."
2817 (let ((function (if (< n 0) 'previous-single-property-change
2818 'next-single-property-change))
2819 (inhibit-point-motion-hooks t)
2821 (limit (if (< n 0) (point-min) (point-max))))
2823 (while (and (not (= limit (point)))
2825 ;; Skip past the current button.
2826 (when (get-text-property (point) 'gnus-callback)
2827 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2828 ;; Go to the next (or previous) button.
2829 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2830 ;; Put point at the start of the button.
2831 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2832 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2833 ;; Skip past intangible buttons.
2834 (when (get-text-property (point) 'intangible)
2838 (gnus-message 5 "No more buttons"))
2841 (defun gnus-article-highlight (&optional force)
2842 "Highlight current article.
2843 This function calls `gnus-article-highlight-headers',
2844 `gnus-article-highlight-citation',
2845 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2846 do the highlighting. See the documentation for those functions."
2847 (interactive (list 'force))
2848 (gnus-article-highlight-headers)
2849 (gnus-article-highlight-citation force)
2850 (gnus-article-highlight-signature)
2851 (gnus-article-add-buttons force)
2852 (gnus-article-add-buttons-to-head))
2854 (defun gnus-article-highlight-some (&optional force)
2855 "Highlight current article.
2856 This function calls `gnus-article-highlight-headers',
2857 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2858 do the highlighting. See the documentation for those functions."
2859 (interactive (list 'force))
2860 (gnus-article-highlight-headers)
2861 (gnus-article-highlight-signature)
2862 (gnus-article-add-buttons))
2864 (defun gnus-article-highlight-headers ()
2865 "Highlight article headers as specified by `gnus-header-face-alist'."
2868 (set-buffer gnus-article-buffer)
2870 (let ((alist gnus-header-face-alist)
2871 (buffer-read-only nil)
2872 (case-fold-search t)
2873 (inhibit-point-motion-hooks t)
2874 entry regexp header-face field-face from hpoints fpoints)
2875 (message-narrow-to-head)
2876 (while (setq entry (pop alist))
2877 (goto-char (point-min))
2878 (setq regexp (concat "^\\("
2879 (if (string-equal "" (nth 0 entry))
2883 header-face (nth 1 entry)
2884 field-face (nth 2 entry))
2885 (while (and (re-search-forward regexp nil t)
2889 (unless (search-forward ":" nil t)
2891 (when (and header-face
2892 (not (memq (point) hpoints)))
2893 (push (point) hpoints)
2894 (gnus-put-text-property from (point) 'face header-face))
2895 (when (and field-face
2896 (not (memq (setq from (point)) fpoints)))
2898 (if (re-search-forward "^[^ \t]" nil t)
2900 (goto-char (point-max)))
2901 (gnus-put-text-property from (point) 'face field-face))))))))
2903 (defun gnus-article-highlight-signature ()
2904 "Highlight the signature in an article.
2905 It does this by highlighting everything after
2906 `gnus-signature-separator' using `gnus-signature-face'."
2909 (set-buffer gnus-article-buffer)
2910 (let ((buffer-read-only nil)
2911 (inhibit-point-motion-hooks t))
2913 (when (and gnus-signature-face
2914 (gnus-article-narrow-to-signature))
2915 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2916 'face gnus-signature-face)
2918 (gnus-article-search-signature)
2919 (let ((start (match-beginning 0))
2920 (end (set-marker (make-marker) (1+ (match-end 0)))))
2921 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2924 (defun gnus-button-in-region-p (b e prop)
2925 "Say whether PROP exists in the region."
2926 (text-property-not-all b e prop nil))
2928 (defun gnus-article-add-buttons (&optional force)
2929 "Find external references in the article and make buttons of them.
2930 \"External references\" are things like Message-IDs and URLs, as
2931 specified by `gnus-button-alist'."
2932 (interactive (list 'force))
2934 (set-buffer gnus-article-buffer)
2935 (let ((buffer-read-only nil)
2936 (inhibit-point-motion-hooks t)
2937 (case-fold-search t)
2938 (alist gnus-button-alist)
2940 ;; Remove all old markers.
2942 (while (setq marker (pop gnus-button-marker-list))
2944 (when (setq entry (gnus-button-entry))
2945 (put-text-property (match-beginning (nth 1 entry))
2946 (match-end (nth 1 entry))
2947 'gnus-callback nil))
2948 (set-marker marker nil)))
2949 ;; We skip the headers.
2950 (goto-char (point-min))
2951 (unless (search-forward "\n\n" nil t)
2952 (goto-char (point-max)))
2954 (while (setq entry (pop alist))
2955 (setq regexp (car entry))
2957 (while (re-search-forward regexp nil t)
2958 (let* ((start (and entry (match-beginning (nth 1 entry))))
2959 (end (and entry (match-end (nth 1 entry))))
2960 (from (match-beginning 0)))
2961 (when (and (or (eq t (nth 2 entry))
2962 (eval (nth 2 entry)))
2963 (not (gnus-button-in-region-p
2964 start end 'gnus-callback)))
2965 ;; That optional form returned non-nil, so we add the
2967 (gnus-article-add-button
2968 start end 'gnus-button-push
2969 (car (push (set-marker (make-marker) from)
2970 gnus-button-marker-list))))))))))
2972 ;; Add buttons to the head of an article.
2973 (defun gnus-article-add-buttons-to-head ()
2974 "Add buttons to the head of the article."
2977 (set-buffer gnus-article-buffer)
2978 (let ((buffer-read-only nil)
2979 (inhibit-point-motion-hooks t)
2980 (case-fold-search t)
2981 (alist gnus-header-button-alist)
2983 (nnheader-narrow-to-headers)
2985 ;; Each alist entry.
2986 (setq entry (car alist)
2988 (goto-char (point-min))
2989 (while (re-search-forward (car entry) nil t)
2990 ;; Each header matching the entry.
2991 (setq beg (match-beginning 0))
2992 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2993 (match-beginning 0))
2996 (while (re-search-forward (nth 1 entry) end t)
2997 ;; Each match within a header.
2998 (let* ((entry (cdr entry))
2999 (start (match-beginning (nth 1 entry)))
3000 (end (match-end (nth 1 entry)))
3001 (form (nth 2 entry)))
3002 (goto-char (match-end 0))
3004 (gnus-article-add-button
3005 start end (nth 3 entry)
3006 (buffer-substring (match-beginning (nth 4 entry))
3007 (match-end (nth 4 entry)))))))
3011 ;;; External functions:
3013 (defun gnus-article-add-button (from to fun &optional data)
3014 "Create a button between FROM and TO with callback FUN and data DATA."
3015 (when gnus-article-button-face
3016 (gnus-overlay-put (gnus-make-overlay from to)
3017 'face gnus-article-button-face))
3018 (gnus-add-text-properties
3020 (nconc (and gnus-article-mouse-face
3021 (list gnus-mouse-face-prop gnus-article-mouse-face))
3022 (list 'gnus-callback fun)
3023 (and data (list 'gnus-data data)))))
3025 ;;; Internal functions:
3027 (defun gnus-article-set-globals ()
3029 (set-buffer gnus-summary-buffer)
3030 (gnus-set-global-variables)))
3032 (defun gnus-signature-toggle (end)
3034 (set-buffer gnus-article-buffer)
3035 (let ((buffer-read-only nil)
3036 (inhibit-point-motion-hooks t))
3037 (if (get-text-property end 'invisible)
3038 (gnus-article-unhide-text end (point-max))
3039 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3041 (defun gnus-button-entry ()
3042 ;; Return the first entry in `gnus-button-alist' matching this place.
3043 (let ((alist gnus-button-alist)
3046 (setq entry (pop alist))
3047 (if (looking-at (car entry))
3052 (defun gnus-button-push (marker)
3053 ;; Push button starting at MARKER.
3055 (set-buffer gnus-article-buffer)
3057 (let* ((entry (gnus-button-entry))
3058 (inhibit-point-motion-hooks t)
3060 (args (mapcar (lambda (group)
3061 (let ((string (match-string group)))
3062 (gnus-set-text-properties
3063 0 (length string) nil string)
3070 (fboundp (symbol-value fun)))
3071 (apply (symbol-value fun) args))
3073 (gnus-message 1 "You must define `%S' to use this button"
3074 (cons fun args)))))))
3076 (defun gnus-button-message-id (message-id)
3079 (set-buffer gnus-summary-buffer)
3080 (gnus-summary-refer-article message-id)))
3082 (defun gnus-button-fetch-group (address)
3083 "Fetch GROUP specified by ADDRESS."
3084 (if (not (string-match "[:/]" address))
3085 ;; This is just a simple group url.
3086 (gnus-group-read-ephemeral-group address gnus-select-method)
3087 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3089 (error "Can't parse %s" address)
3090 (gnus-group-read-ephemeral-group
3091 (match-string 4 address)
3092 `(nntp ,(match-string 1 address)
3093 (nntp-address ,(match-string 1 address))
3094 (nntp-port-number ,(if (match-end 3)
3095 (match-string 3 address)
3098 (defun gnus-url-parse-query-string (query &optional downcase)
3099 (let (retval pairs cur key val)
3100 (setq pairs (split-string query "&"))
3102 (setq cur (car pairs)
3104 (if (not (string-match "=" cur))
3106 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3107 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3109 (setq key (downcase key)))
3110 (setq cur (assoc key retval))
3112 (setcdr cur (cons val (cdr cur)))
3113 (setq retval (cons (list key val) retval)))))
3116 (defun gnus-url-unhex (x)
3123 (defun gnus-url-unhex-string (str &optional allow-newlines)
3124 "Remove %XXX embedded spaces, etc in a url.
3125 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3126 decoding of carriage returns and line feeds in the string, which is normally
3127 forbidden in URL encoding."
3128 (setq str (or str ""))
3130 (case-fold-search t))
3131 (while (string-match "%[0-9a-f][0-9a-f]" str)
3132 (let* ((start (match-beginning 0))
3133 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3135 (gnus-url-unhex (elt str (+ start 2))))))
3137 tmp (substring str 0 start)
3140 (char-to-string code))
3141 ((or (= code ?\n) (= code ?\r))
3143 (t (char-to-string code))))
3144 str (substring str (match-end 0)))))
3145 (setq tmp (concat tmp str))
3148 (defun gnus-url-mailto (url)
3149 ;; Send mail to someone
3150 (when (string-match "mailto:/*\\(.*\\)" url)
3151 (setq url (substring url (match-beginning 1) nil)))
3152 (let (to args subject func)
3153 (if (string-match (regexp-quote "?") url)
3154 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3155 args (gnus-url-parse-query-string
3156 (substring url (match-end 0) nil) t))
3157 (setq to (gnus-url-unhex-string url)))
3158 (setq args (cons (list "to" to) args)
3159 subject (cdr-safe (assoc "subject" args)))
3162 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3165 (message-position-on-field (caar args)))
3166 (insert (mapconcat 'identity (cdar args) ", "))
3167 (setq args (cdr args)))
3170 (message-goto-subject))))
3172 (defun gnus-button-mailto (address)
3174 (set-buffer (gnus-copy-article-buffer))
3175 (message-reply address))
3177 (defun gnus-button-reply (address)
3178 ;; Reply to ADDRESS.
3179 (message-reply address))
3181 (defun gnus-button-url (address)
3183 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3184 (if (listp browse-url-browser-function)
3185 (browse-url address)
3186 (funcall browse-url-browser-function address)))
3188 (defun gnus-button-embedded-url (address)
3190 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3191 (if (listp browse-url-browser-function)
3192 (browse-url (gnus-strip-whitespace address))
3193 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3195 ;;; Next/prev buttons in the article buffer.
3197 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3198 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3200 (defvar gnus-prev-page-map nil)
3201 (unless gnus-prev-page-map
3202 (setq gnus-prev-page-map (make-sparse-keymap))
3203 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3204 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3206 (defun gnus-insert-prev-page-button ()
3207 (let ((buffer-read-only nil))
3209 gnus-prev-page-line-format nil
3210 `(gnus-prev t local-map ,gnus-prev-page-map
3211 gnus-callback gnus-article-button-prev-page
3212 gnus-type annotation))))
3214 (defvar gnus-next-page-map nil)
3215 (unless gnus-next-page-map
3216 (setq gnus-next-page-map (make-keymap))
3217 (suppress-keymap gnus-prev-page-map)
3218 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3219 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3221 (defun gnus-button-next-page ()
3222 "Go to the next page."
3224 (let ((win (selected-window)))
3225 (select-window (get-buffer-window gnus-article-buffer t))
3226 (gnus-article-next-page)
3227 (select-window win)))
3229 (defun gnus-button-prev-page ()
3230 "Go to the prev page."
3232 (let ((win (selected-window)))
3233 (select-window (get-buffer-window gnus-article-buffer t))
3234 (gnus-article-prev-page)
3235 (select-window win)))
3237 (defun gnus-insert-next-page-button ()
3238 (let ((buffer-read-only nil))
3239 (gnus-eval-format gnus-next-page-line-format nil
3241 t local-map ,gnus-next-page-map
3242 gnus-callback gnus-article-button-next-page
3243 gnus-type annotation))))
3245 (defun gnus-article-button-next-page (arg)
3246 "Go to the next page."
3248 (let ((win (selected-window)))
3249 (select-window (get-buffer-window gnus-article-buffer t))
3250 (gnus-article-next-page)
3251 (select-window win)))
3253 (defun gnus-article-button-prev-page (arg)
3254 "Go to the prev page."
3256 (let ((win (selected-window)))
3257 (select-window (get-buffer-window gnus-article-buffer t))
3258 (gnus-article-prev-page)
3259 (select-window win)))
3265 (run-hooks 'gnus-art-load-hook)
3267 ;;; gnus-art.el ends here