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))
40 (defgroup gnus-article nil
42 :link '(custom-manual "(gnus)The Article Buffer")
45 (defgroup gnus-article-hiding nil
46 "Hiding article parts."
47 :link '(custom-manual "(gnus)Article Hiding")
50 (defgroup gnus-article-highlight nil
51 "Article highlighting."
52 :link '(custom-manual "(gnus)Article Highlighting")
56 (defgroup gnus-article-signature nil
58 :link '(custom-manual "(gnus)Article Signature")
61 (defgroup gnus-article-headers nil
63 :link '(custom-manual "(gnus)Hiding Headers")
66 (defgroup gnus-article-washing nil
67 "Special commands on articles."
68 :link '(custom-manual "(gnus)Article Washing")
71 (defgroup gnus-article-emphasis nil
72 "Fontisizing articles."
73 :link '(custom-manual "(gnus)Article Fontisizing")
76 (defgroup gnus-article-saving nil
78 :link '(custom-manual "(gnus)Saving Articles")
81 (defgroup gnus-article-mime nil
82 "Worshiping the MIME wonder."
83 :link '(custom-manual "(gnus)Using MIME")
86 (defgroup gnus-article-buttons nil
87 "Pushable buttons in the article buffer."
88 :link '(custom-manual "(gnus)Article Buttons")
91 (defgroup gnus-article-various nil
92 "Other article options."
93 :link '(custom-manual "(gnus)Misc Article")
96 (defcustom gnus-ignored-headers
97 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
98 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
99 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
100 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
101 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
102 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
103 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
104 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
105 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
106 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
107 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
108 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
109 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
110 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
111 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
112 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
113 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
114 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
116 "*All headers that start with this regexp will be hidden.
117 This variable can also be a list of regexps of headers to be ignored.
118 If `gnus-visible-headers' is non-nil, this variable will be ignored."
119 :type '(choice :custom-show nil
122 :group 'gnus-article-hiding)
124 (defcustom gnus-visible-headers
125 "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:"
126 "*All headers that do not match this regexp will be hidden.
127 This variable can also be a list of regexp of headers to remain visible.
128 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
129 :type '(repeat :value-to-internal (lambda (widget value)
130 (custom-split-regexp-maybe value))
131 :match (lambda (widget value)
133 (widget-editable-list-match widget value)))
135 :group 'gnus-article-hiding)
137 (defcustom gnus-sorted-header-list
138 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
139 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
140 "*This variable is a list of regular expressions.
141 If it is non-nil, headers that match the regular expressions will
142 be placed first in the article buffer in the sequence specified by
144 :type '(repeat regexp)
145 :group 'gnus-article-hiding)
147 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
148 "Headers that are only to be displayed if they have interesting data.
149 Possible values in this list are `empty', `newsgroups', `followup-to',
150 `reply-to', `date', `long-to', and `many-to'."
151 :type '(set (const :tag "Headers with no content." empty)
152 (const :tag "Newsgroups with only one group." newsgroups)
153 (const :tag "Followup-to identical to newsgroups." followup-to)
154 (const :tag "Reply-to identical to from." reply-to)
155 (const :tag "Date less than four days old." date)
156 (const :tag "Very long To header." long-to)
157 (const :tag "Multiple To headers." many-to))
158 :group 'gnus-article-hiding)
160 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
161 "Regexp matching signature separator.
162 This can also be a list of regexps. In that case, it will be checked
163 from head to tail looking for a separator. Searches will be done from
164 the end of the buffer."
165 :type '(repeat string)
166 :group 'gnus-article-signature)
168 (defcustom gnus-signature-limit nil
169 "Provide a limit to what is considered a signature.
170 If it is a number, no signature may not be longer (in characters) than
171 that number. If it is a floating point number, no signature may be
172 longer (in lines) than that number. If it is a function, the function
173 will be called without any parameters, and if it returns nil, there is
174 no signature in the buffer. If it is a string, it will be used as a
175 regexp. If it matches, the text in question is not a signature."
176 :type '(choice (integer :value 200)
178 (function :value fun)
179 (regexp :value ".*"))
180 :group 'gnus-article-signature)
182 (defcustom gnus-hidden-properties '(invisible t intangible t)
183 "Property list to use for hiding text."
185 :group 'gnus-article-hiding)
187 (defcustom gnus-article-x-face-command
188 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
189 "*String or function to be executed to display an X-Face header.
190 If it is a string, the command will be executed in a sub-shell
191 asynchronously. The compressed face will be piped to this command."
192 :type 'string ;Leave function case to Lisp.
193 :group 'gnus-article-washing)
195 (defcustom gnus-article-x-face-too-ugly nil
196 "Regexp matching posters whose face shouldn't be shown automatically."
197 :type '(choice regexp (const nil))
198 :group 'gnus-article-washing)
200 (defcustom gnus-emphasis-alist
202 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
204 '(("_" "_" underline)
207 ("_/" "/_" underline-italic)
208 ("_\\*" "\\*_" underline-bold)
209 ("\\*/" "/\\*" bold-italic)
210 ("_\\*/" "/\\*_" underline-bold-italic))))
211 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
212 2 3 gnus-emphasis-underline)
216 (format format (car spec) (cadr spec))
217 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
219 "*Alist that says how to fontify certain phrases.
220 Each item looks like this:
222 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
224 The first element is a regular expression to be matched. The second
225 is a number that says what regular expression grouping used to find
226 the entire emphasized word. The third is a number that says what
227 regexp grouping should be displayed and highlighted. The fourth
228 is the face used for highlighting."
229 :type '(repeat (list :value ("" 0 0 default)
231 (integer :tag "Match group")
232 (integer :tag "Emphasize group")
234 :group 'gnus-article-emphasis)
236 (defface gnus-emphasis-bold '((t (:bold t)))
237 "Face used for displaying strong emphasized text (*word*)."
238 :group 'gnus-article-emphasis)
240 (defface gnus-emphasis-italic '((t (:italic t)))
241 "Face used for displaying italic emphasized text (/word/)."
242 :group 'gnus-article-emphasis)
244 (defface gnus-emphasis-underline '((t (:underline t)))
245 "Face used for displaying underlined emphasized text (_word_)."
246 :group 'gnus-article-emphasis)
248 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
249 "Face used for displaying underlined bold emphasized text (_*word*_)."
250 :group 'gnus-article-emphasis)
252 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
253 "Face used for displaying underlined italic emphasized text (_*word*_)."
254 :group 'gnus-article-emphasis)
256 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
257 "Face used for displaying bold italic emphasized text (/*word*/)."
258 :group 'gnus-article-emphasis)
260 (defface gnus-emphasis-underline-bold-italic
261 '((t (:bold t :italic t :underline t)))
262 "Face used for displaying underlined bold italic emphasized text.
263 Esample: (_/*word*/_)."
264 :group 'gnus-article-emphasis)
266 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
267 "Format for display of Date headers in article bodies.
268 See `format-time-string' for the possible values.
270 The variable can also be function, which should return a complete Date
271 header. The function is called with one argument, the time, which can
272 be fed to `format-time-string'."
273 :type '(choice string symbol)
274 :link '(custom-manual "(gnus)Article Date")
275 :group 'gnus-article-washing)
278 (autoload 'mail-extract-address-components "mail-extr"))
280 (defcustom gnus-save-all-headers t
281 "*If non-nil, don't remove any headers before saving."
282 :group 'gnus-article-saving
285 (defcustom gnus-prompt-before-saving 'always
286 "*This variable says how much prompting is to be done when saving articles.
287 If it is nil, no prompting will be done, and the articles will be
288 saved to the default files. If this variable is `always', each and
289 every article that is saved will be preceded by a prompt, even when
290 saving large batches of articles. If this variable is neither nil not
291 `always', there the user will be prompted once for a file name for
292 each invocation of the saving commands."
293 :group 'gnus-article-saving
294 :type '(choice (item always)
295 (item :tag "never" nil)
296 (sexp :tag "once" :format "%t\n" :value t)))
298 (defcustom gnus-saved-headers gnus-visible-headers
299 "Headers to keep if `gnus-save-all-headers' is nil.
300 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
301 If that variable is nil, however, all headers that match this regexp
302 will be kept while the rest will be deleted before saving."
303 :group 'gnus-article-saving
306 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
307 "A function to save articles in your favourite format.
308 The function must be interactively callable (in other words, it must
309 be an Emacs command).
311 Gnus provides the following functions:
313 * gnus-summary-save-in-rmail (Rmail format)
314 * gnus-summary-save-in-mail (Unix mail format)
315 * gnus-summary-save-in-folder (MH folder)
316 * gnus-summary-save-in-file (article format)
317 * gnus-summary-save-in-vm (use VM's folder format)
318 * gnus-summary-write-to-file (article format -- overwrite)."
319 :group 'gnus-article-saving
320 :type '(radio (function-item gnus-summary-save-in-rmail)
321 (function-item gnus-summary-save-in-mail)
322 (function-item gnus-summary-save-in-folder)
323 (function-item gnus-summary-save-in-file)
324 (function-item gnus-summary-save-in-vm)
325 (function-item gnus-summary-write-to-file)))
327 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
328 "A function generating a file name to save articles in Rmail format.
329 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
330 :group 'gnus-article-saving
333 (defcustom gnus-mail-save-name 'gnus-plain-save-name
334 "A function generating a file name to save articles in Unix mail format.
335 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
336 :group 'gnus-article-saving
339 (defcustom gnus-folder-save-name 'gnus-folder-save-name
340 "A function generating a file name to save articles in MH folder.
341 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
342 :group 'gnus-article-saving
345 (defcustom gnus-file-save-name 'gnus-numeric-save-name
346 "A function generating a file name to save articles in article format.
347 The function is called with NEWSGROUP, HEADERS, and optional
349 :group 'gnus-article-saving
352 (defcustom gnus-split-methods
353 '((gnus-article-archive-name)
354 (gnus-article-nndoc-name))
355 "*Variable used to suggest where articles are to be saved.
356 For instance, if you would like to save articles related to Gnus in
357 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
358 you could set this variable to something like:
360 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
361 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
363 This variable is an alist where the where the key is the match and the
364 value is a list of possible files to save in if the match is non-nil.
366 If the match is a string, it is used as a regexp match on the
367 article. If the match is a symbol, that symbol will be funcalled
368 from the buffer of the article to be saved with the newsgroup as the
369 parameter. If it is a list, it will be evaled in the same buffer.
371 If this form or function returns a string, this string will be used as
372 a possible file name; and if it returns a non-nil list, that list will
373 be used as possible file names."
374 :group 'gnus-article-saving
375 :type '(repeat (choice (list :value (fun) function)
376 (cons :value ("" "") regexp (repeat string))
379 (defcustom gnus-page-delimiter "^\^L"
380 "*Regexp describing what to use as article page delimiters.
381 The default value is \"^\^L\", which is a form linefeed at the
382 beginning of a line."
384 :group 'gnus-article-various)
386 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
387 "*The format specification for the article mode line.
388 See `gnus-summary-mode-line-format' for a closer description."
390 :group 'gnus-article-various)
392 (defcustom gnus-article-mode-hook nil
393 "*A hook for Gnus article mode."
395 :group 'gnus-article-various)
397 (defcustom gnus-article-menu-hook nil
398 "*Hook run after the creation of the article mode menu."
400 :group 'gnus-article-various)
402 (defcustom gnus-article-prepare-hook nil
403 "*A hook called after an article has been prepared in the article buffer.
404 If you want to run a special decoding program like nkf, use this hook."
406 :group 'gnus-article-various)
408 (defcustom gnus-article-hide-pgp-hook nil
409 "*A hook called after successfully hiding a PGP signature."
411 :group 'gnus-article-various)
413 (defcustom gnus-article-button-face 'bold
414 "Face used for highlighting buttons in the article buffer.
416 An article button is a piece of text that you can activate by pressing
417 `RET' or `mouse-2' above it."
419 :group 'gnus-article-buttons)
421 (defcustom gnus-article-mouse-face 'highlight
422 "Face used for mouse highlighting in the article buffer.
424 Article buttons will be displayed in this face when the cursor is
427 :group 'gnus-article-buttons)
429 (defcustom gnus-signature-face 'gnus-signature-face
430 "Face used for highlighting a signature in the article buffer.
431 Obsolete; use the face `gnus-signature-face' for customizations instead."
433 :group 'gnus-article-highlight
434 :group 'gnus-article-signature)
436 (defface gnus-signature-face
439 "Face used for highlighting a signature in the article buffer."
440 :group 'gnus-article-highlight
441 :group 'gnus-article-signature)
443 (defface gnus-header-from-face
446 (:foreground "spring green"))
449 (:foreground "red3"))
452 "Face used for displaying from headers."
453 :group 'gnus-article-headers
454 :group 'gnus-article-highlight)
456 (defface gnus-header-subject-face
459 (:foreground "SeaGreen3"))
462 (:foreground "red4"))
464 (:bold t :italic t)))
465 "Face used for displaying subject headers."
466 :group 'gnus-article-headers
467 :group 'gnus-article-highlight)
469 (defface gnus-header-newsgroups-face
472 (:foreground "yellow" :italic t))
475 (:foreground "MidnightBlue" :italic t))
478 "Face used for displaying newsgroups headers."
479 :group 'gnus-article-headers
480 :group 'gnus-article-highlight)
482 (defface gnus-header-name-face
485 (:foreground "SeaGreen"))
488 (:foreground "maroon"))
491 "Face used for displaying header names."
492 :group 'gnus-article-headers
493 :group 'gnus-article-highlight)
495 (defface gnus-header-content-face
498 (:foreground "forest green" :italic t))
501 (:foreground "indianred4" :italic t))
503 (:italic t))) "Face used for displaying header content."
504 :group 'gnus-article-headers
505 :group 'gnus-article-highlight)
507 (defcustom gnus-header-face-alist
508 '(("From" nil gnus-header-from-face)
509 ("Subject" nil gnus-header-subject-face)
510 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
511 ("" gnus-header-name-face gnus-header-content-face))
512 "*Controls highlighting of article header.
514 An alist of the form (HEADER NAME CONTENT).
516 HEADER is a regular expression which should match the name of an
517 header header and NAME and CONTENT are either face names or nil.
519 The name of each header field will be displayed using the face
520 specified by the first element in the list where HEADER match the
521 header name and NAME is non-nil. Similarly, the content will be
522 displayed by the first non-nil matching CONTENT face."
523 :group 'gnus-article-headers
524 :group 'gnus-article-highlight
525 :type '(repeat (list (regexp :tag "Header")
527 (item :tag "skip" nil)
528 (face :value default))
529 (choice :tag "Content"
530 (item :tag "skip" nil)
531 (face :value default)))))
533 (defcustom gnus-article-decode-hook
534 '(article-decode-charset article-decode-rfc1522)
535 "*Hook run to decode charsets in articles."
536 :group 'gnus-article-headers
539 (defcustom gnus-display-mime-function 'gnus-display-mime
540 "Function to display MIME articles."
541 :group 'gnus-article-headers
544 ;;; Internal variables
546 (defvar article-lapsed-timer nil)
547 (defvar gnus-article-current-summary nil)
549 (defvar gnus-article-mode-syntax-table
550 (let ((table (copy-syntax-table text-mode-syntax-table)))
551 (modify-syntax-entry ?- "w" table)
552 (modify-syntax-entry ?> ")" table)
553 (modify-syntax-entry ?< "(" table)
555 "Syntax table used in article mode buffers.
556 Initialized from `text-mode-syntax-table.")
558 (defvar gnus-save-article-buffer nil)
560 (defvar gnus-article-mode-line-format-alist
561 (nconc '((?w (gnus-article-wash-status) ?s))
562 gnus-summary-mode-line-format-alist))
564 (defvar gnus-number-of-articles-to-be-saved nil)
566 (defvar gnus-inhibit-hiding nil)
568 (defsubst gnus-article-hide-text (b e props)
569 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
570 (add-text-properties b e props)
571 (when (memq 'intangible props)
573 (max (1- b) (point-min))
574 b 'intangible (cddr (memq 'intangible props)))))
576 (defsubst gnus-article-unhide-text (b e)
577 "Remove hidden text properties from region between B and E."
578 (remove-text-properties b e gnus-hidden-properties)
579 (when (memq 'intangible gnus-hidden-properties)
580 (put-text-property (max (1- b) (point-min))
583 (defun gnus-article-hide-text-type (b e type)
584 "Hide text of TYPE between B and E."
585 (gnus-article-hide-text
586 b e (cons 'article-type (cons type gnus-hidden-properties))))
588 (defun gnus-article-unhide-text-type (b e type)
589 "Unhide text of TYPE between B and E."
590 (remove-text-properties
591 b e (cons 'article-type (cons type gnus-hidden-properties)))
592 (when (memq 'intangible gnus-hidden-properties)
593 (put-text-property (max (1- b) (point-min))
596 (defun gnus-article-hide-text-of-type (type)
597 "Hide text of TYPE in the current buffer."
599 (let ((b (point-min))
601 (while (setq b (text-property-any b e 'article-type type))
602 (add-text-properties b (incf b) gnus-hidden-properties)))))
604 (defun gnus-article-delete-text-of-type (type)
605 "Delete text of TYPE in the current buffer."
607 (let ((b (point-min)))
608 (while (setq b (text-property-any b (point-max) 'article-type type))
610 b (or (text-property-not-all b (point-max) 'article-type type)
613 (defun gnus-article-delete-invisible-text ()
614 "Delete all invisible text in the current buffer."
616 (let ((b (point-min)))
617 (while (setq b (text-property-any b (point-max) 'invisible t))
619 b (or (text-property-not-all b (point-max) 'invisible t)
622 (defun gnus-article-text-type-exists-p (type)
623 "Say whether any text of type TYPE exists in the buffer."
624 (text-property-any (point-min) (point-max) 'article-type type))
626 (defsubst gnus-article-header-rank ()
627 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
628 (let ((list gnus-sorted-header-list)
631 (when (looking-at (car list))
633 (setq list (cdr list))
637 (defun article-hide-headers (&optional arg delete)
638 "Toggle whether to hide unwanted headers and possibly sort them as well.
639 If given a negative prefix, always show; if given a positive prefix,
641 (interactive (gnus-article-hidden-arg))
643 (if (gnus-article-check-hidden-text 'headers arg)
644 ;; Show boring headers as well.
645 (gnus-article-show-hidden-text 'boring-headers)
646 ;; This function might be inhibited.
647 (unless gnus-inhibit-hiding
650 (let ((buffer-read-only nil)
652 (props (nconc (list 'article-type 'headers)
653 gnus-hidden-properties))
654 (max (1+ (length gnus-sorted-header-list)))
655 (ignored (when (not gnus-visible-headers)
656 (cond ((stringp gnus-ignored-headers)
657 gnus-ignored-headers)
658 ((listp gnus-ignored-headers)
659 (mapconcat 'identity gnus-ignored-headers
662 (cond ((stringp gnus-visible-headers)
663 gnus-visible-headers)
664 ((and gnus-visible-headers
665 (listp gnus-visible-headers))
666 (mapconcat 'identity gnus-visible-headers "\\|"))))
667 (inhibit-point-motion-hooks t)
669 ;; First we narrow to just the headers.
671 (goto-char (point-min))
672 ;; Hide any "From " lines at the beginning of (mail) articles.
673 (while (looking-at "From ")
677 (delete-region (point-min) (point))
678 (gnus-article-hide-text (point-min) (point) props)))
679 ;; Then treat the rest of the header lines.
682 (if (search-forward "\n\n" nil t) ; if there's a body
683 (progn (forward-line -1) (point))
685 ;; Then we use the two regular expressions
686 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
687 ;; select which header lines is to remain visible in the
689 (goto-char (point-min))
690 (while (re-search-forward "^[^ \t]*:" nil t)
692 ;; Mark the rank of the header.
694 (point) (1+ (point)) 'message-rank
695 (if (or (and visible (looking-at visible))
697 (not (looking-at ignored))))
698 (gnus-article-header-rank)
701 (message-sort-headers-1)
702 (when (setq beg (text-property-any
703 (point-min) (point-max) 'message-rank (+ 2 max)))
704 ;; We make the unwanted headers invisible.
706 (delete-region beg (point-max))
707 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
708 (gnus-article-hide-text-type beg (point-max) 'headers))
709 ;; Work around XEmacs lossage.
710 (put-text-property (point-min) beg 'invisible nil))))))))
712 (defun article-hide-boring-headers (&optional arg)
713 "Toggle hiding of headers that aren't very interesting.
714 If given a negative prefix, always show; if given a positive prefix,
716 (interactive (gnus-article-hidden-arg))
717 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
718 (not gnus-show-all-headers))
721 (let ((buffer-read-only nil)
722 (list gnus-boring-article-headers)
723 (inhibit-point-motion-hooks t)
725 (nnheader-narrow-to-headers)
727 (setq elem (pop list))
728 (goto-char (point-min))
730 ;; Hide empty headers.
732 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
734 (gnus-article-hide-text-type
735 (progn (beginning-of-line) (point))
738 (if (re-search-forward "^[^ \t]" nil t)
742 ;; Hide boring Newsgroups header.
743 ((eq elem 'newsgroups)
744 (when (equal (gnus-fetch-field "newsgroups")
745 (gnus-group-real-name
746 (if (boundp 'gnus-newsgroup-name)
749 (gnus-article-hide-header "newsgroups")))
750 ((eq elem 'followup-to)
751 (when (equal (message-fetch-field "followup-to")
752 (message-fetch-field "newsgroups"))
753 (gnus-article-hide-header "followup-to")))
755 (let ((from (message-fetch-field "from"))
756 (reply-to (message-fetch-field "reply-to")))
761 (nth 1 (mail-extract-address-components from))
762 (nth 1 (mail-extract-address-components reply-to)))))
763 (gnus-article-hide-header "reply-to"))))
765 (let ((date (message-fetch-field "date")))
767 (< (days-between (current-time-string) date)
769 (gnus-article-hide-header "date"))))
771 (let ((to (message-fetch-field "to")))
772 (when (> (length to) 1024)
773 (gnus-article-hide-header "to"))))
776 (goto-char (point-min))
777 (while (re-search-forward "^to:" nil t)
778 (setq to-count (1+ to-count)))
780 (while (> to-count 0)
781 (goto-char (point-min))
783 (re-search-forward "^to:" nil nil to-count)
785 (narrow-to-region (point) (point-max))
786 (gnus-article-hide-header "to"))
787 (setq to-count (1- to-count)))))))))))))
789 (defun gnus-article-hide-header (header)
791 (goto-char (point-min))
792 (when (re-search-forward (concat "^" header ":") nil t)
793 (gnus-article-hide-text-type
794 (progn (beginning-of-line) (point))
797 (if (re-search-forward "^[^ \t]" nil t)
802 (defun article-treat-dumbquotes ()
803 "Translate M******** sm*rtq**t*s into proper text."
805 (article-translate-characters "\221\222\223\224" "`'\"\""))
807 (defun article-translate-characters (from to)
808 "Translate all characters in the body of the article according to FROM and TO.
809 FROM is a string of characters to translate from; to is a string of
810 characters to translate to."
812 (goto-char (point-min))
813 (when (search-forward "\n\n" nil t)
814 (let ((buffer-read-only nil)
815 (x (make-string 225 ?x))
817 (while (< (incf i) (length x))
820 (while (< i (length from))
821 (aset x (aref from i) (aref to i))
823 (translate-region (point) (point-max) x)))))
825 (defun article-treat-overstrike ()
826 "Translate overstrikes into bold text."
829 (goto-char (point-min))
830 (when (search-forward "\n\n" nil t)
831 (let ((buffer-read-only nil))
832 (while (search-forward "\b" nil t)
833 (let ((next (following-char))
834 (previous (char-after (- (point) 2))))
835 ;; We do the boldification/underlining by hiding the
836 ;; overstrikes and putting the proper text property
840 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
841 (put-text-property (point) (1+ (point)) 'face 'bold))
843 (gnus-article-hide-text-type
844 (1- (point)) (1+ (point)) 'overstrike)
846 (- (point) 2) (1- (point)) 'face 'underline))
848 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
850 (point) (1+ (point)) 'face 'underline)))))))))
852 (defun article-fill ()
853 "Format too long lines."
856 (let ((buffer-read-only nil))
858 (goto-char (point-min))
859 (search-forward "\n\n" nil t)
861 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
862 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
863 (adaptive-fill-mode t))
865 (and (>= (current-column) (min fill-column (window-width)))
866 (/= (preceding-char) ?:)
867 (fill-paragraph nil))
870 (defun article-remove-cr ()
871 "Remove carriage returns from an article."
874 (let ((buffer-read-only nil))
875 (goto-char (point-min))
876 (while (search-forward "\r" nil t)
877 (replace-match "" t t)))))
879 (defun article-remove-trailing-blank-lines ()
880 "Remove all trailing blank lines from the article."
883 (let ((buffer-read-only nil))
884 (goto-char (point-max))
888 (while (and (not (bobp))
889 (looking-at "^[ \t]*$")
890 (not (gnus-annotation-in-region-p
891 (point) (gnus-point-at-eol))))
896 (defun article-display-x-face (&optional force)
897 "Look for an X-Face header and display it if present."
898 (interactive (list 'force))
900 ;; Delete the old process, if any.
901 (when (process-status "article-x-face")
902 (delete-process "article-x-face"))
903 (let ((inhibit-point-motion-hooks t)
907 (nnheader-narrow-to-headers)
908 (setq from (message-fetch-field "from"))
909 (goto-char (point-min))
910 (while (and gnus-article-x-face-command
913 ;; Check whether this face is censored.
914 (not gnus-article-x-face-too-ugly)
915 (and gnus-article-x-face-too-ugly from
916 (not (string-match gnus-article-x-face-too-ugly
918 ;; Has to be present.
919 (re-search-forward "^X-Face: " nil t))
920 ;; This used to try to do multiple faces (`while' instead of
921 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
922 ;; work (b) it can crash some versions of Emacs (c) are
923 ;; multiple faces really something to encourage?
924 (when (stringp gnus-article-x-face-command)
926 ;; We now have the area of the buffer where the X-Face is stored.
929 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
930 ;; We display the face.
931 (if (symbolp gnus-article-x-face-command)
932 ;; The command is a lisp function, so we call it.
933 (if (gnus-functionp gnus-article-x-face-command)
934 (funcall gnus-article-x-face-command beg end)
935 (error "%s is not a function" gnus-article-x-face-command))
936 ;; The command is a string, so we interpret the command
937 ;; as a, well, command, and fork it off.
938 (let ((process-connection-type nil))
939 (process-kill-without-query
941 "article-x-face" nil shell-file-name shell-command-switch
942 gnus-article-x-face-command))
943 (process-send-region "article-x-face" beg end)
944 (process-send-eof "article-x-face"))))))))))
946 (defun article-decode-mime-words ()
947 "Decode all MIME-encoded words in the article."
950 (set-buffer gnus-article-buffer)
951 (let ((inhibit-point-motion-hooks t)
953 (rfc2047-decode-region (point-min) (point-max)))))
955 (defun article-decode-charset (&optional prompt)
956 "Decode charset-encoded text in the article.
957 If PROMPT (the prefix), prompt for a coding system to use."
961 (message-narrow-to-head)
962 (let* ((inhibit-point-motion-hooks t)
963 (ct (message-fetch-field "Content-Type" t))
964 (cte (message-fetch-field "Content-Transfer-Encoding" t))
965 (ctl (and ct (condition-case () (drums-parse-content-type ct)
969 (mm-read-coding-system "Charset to decode: "))
971 (drums-content-type-get ctl 'charset))
973 (gnus-group-find-parameter
974 gnus-newsgroup-name 'charset))))
976 (goto-char (point-max))
978 (narrow-to-region (point) (point-max))
980 (equal (car ctl) "text/plain"))
982 charset (and cte (intern (downcase
983 (gnus-strip-whitespace cte))))))))))
985 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
986 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
987 (defun article-decode-rfc1522 ()
988 "Remove QP encoding from headers."
989 (let ((inhibit-point-motion-hooks t)
990 (buffer-read-only nil))
992 (message-narrow-to-head)
993 (rfc2047-decode-region (point-min) (point-max)))))
995 (defun article-de-quoted-unreadable (&optional force)
996 "Translate a quoted-printable-encoded article.
997 If FORCE, decode the article whether it is marked as quoted-printable
999 (interactive (list 'force))
1001 (let ((buffer-read-only nil)
1002 (type (gnus-fetch-field "content-transfer-encoding")))
1003 ;;(gnus-article-decode-rfc1522)
1005 (and type (string-match "quoted-printable" (downcase type))))
1006 (goto-char (point-min))
1007 (search-forward "\n\n" nil 'move)
1008 (quoted-printable-decode-region (point) (point-max))))))
1010 (defun article-mime-decode-quoted-printable-buffer ()
1011 "Decode Quoted-Printable in the current buffer."
1012 (quoted-printable-decode-region (point-min) (point-max)))
1014 (defun article-hide-pgp (&optional arg)
1015 "Toggle hiding of any PGP headers and signatures in the current article.
1016 If given a negative prefix, always show; if given a positive prefix,
1018 (interactive (gnus-article-hidden-arg))
1019 (unless (gnus-article-check-hidden-text 'pgp arg)
1021 (let ((inhibit-point-motion-hooks t)
1022 buffer-read-only beg end)
1024 (goto-char (point-min))
1025 ;; Hide the "header".
1026 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1027 (delete-region (1+ (match-beginning 0)) (match-end 0))
1029 ;; Hide the actual signature.
1030 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1031 (setq end (1+ (match-beginning 0)))
1034 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1036 ;; Perhaps we shouldn't hide to the end of the buffer
1037 ;; if there is no end to the signature?
1039 ;; Hide "- " PGP quotation markers.
1041 (narrow-to-region beg end)
1042 (goto-char (point-min))
1043 (while (re-search-forward "^- " nil t)
1045 (match-beginning 0) (match-end 0)))
1047 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1049 (defun article-hide-pem (&optional arg)
1050 "Toggle hiding of any PEM headers and signatures in the current article.
1051 If given a negative prefix, always show; if given a positive prefix,
1053 (interactive (gnus-article-hidden-arg))
1054 (unless (gnus-article-check-hidden-text 'pem arg)
1056 (let (buffer-read-only end)
1058 (goto-char (point-min))
1059 ;; hide the horrendously ugly "header".
1060 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1063 (setq end (1+ (match-beginning 0)))
1064 (gnus-article-hide-text-type
1066 (if (search-forward "\n\n" nil t)
1070 ;; hide the trailer as well
1071 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1074 (gnus-article-hide-text-type
1075 (match-beginning 0) (match-end 0) 'pem))))))
1077 (defun article-hide-signature (&optional arg)
1078 "Hide the signature in the current article.
1079 If given a negative prefix, always show; if given a positive prefix,
1081 (interactive (gnus-article-hidden-arg))
1082 (unless (gnus-article-check-hidden-text 'signature arg)
1085 (let ((buffer-read-only nil))
1086 (when (gnus-article-narrow-to-signature)
1087 (gnus-article-hide-text-type
1088 (point-min) (point-max) 'signature)))))))
1090 (defun article-strip-leading-blank-lines ()
1091 "Remove all blank lines from the beginning of the article."
1094 (let ((inhibit-point-motion-hooks t)
1096 (goto-char (point-min))
1097 (when (search-forward "\n\n" nil t)
1098 (while (and (not (eobp))
1099 (looking-at "[ \t]*$"))
1100 (gnus-delete-line))))))
1102 (defun article-strip-multiple-blank-lines ()
1103 "Replace consecutive blank lines with one empty line."
1106 (let ((inhibit-point-motion-hooks t)
1108 ;; First make all blank lines empty.
1109 (goto-char (point-min))
1110 (search-forward "\n\n" nil t)
1111 (while (re-search-forward "^[ \t]+$" nil t)
1112 (replace-match "" nil t))
1113 ;; Then replace multiple empty lines with a single empty line.
1114 (goto-char (point-min))
1115 (search-forward "\n\n" nil t)
1116 (while (re-search-forward "\n\n\n+" nil t)
1117 (unless (gnus-annotation-in-region-p
1118 (match-beginning 0) (match-end 0))
1119 (replace-match "\n\n" t t))))))
1121 (defun article-strip-leading-space ()
1122 "Remove all white space from the beginning of the lines in the article."
1125 (let ((inhibit-point-motion-hooks t)
1127 (goto-char (point-min))
1128 (search-forward "\n\n" nil t)
1129 (while (re-search-forward "^[ \t]+" nil t)
1130 (replace-match "" t t)))))
1132 (defun article-strip-blank-lines ()
1133 "Strip leading, trailing and multiple blank lines."
1135 (article-strip-leading-blank-lines)
1136 (article-remove-trailing-blank-lines)
1137 (article-strip-multiple-blank-lines))
1139 (defun article-strip-all-blank-lines ()
1140 "Strip all blank lines."
1143 (let ((inhibit-point-motion-hooks t)
1145 (goto-char (point-min))
1146 (search-forward "\n\n" nil t)
1147 (while (re-search-forward "^[ \t]*\n" nil t)
1148 (replace-match "" t t)))))
1150 (defvar mime::preview/content-list)
1151 (defvar mime::preview-content-info/point-min)
1152 (defun gnus-article-narrow-to-signature ()
1153 "Narrow to the signature; return t if a signature is found, else nil."
1155 (let ((inhibit-point-motion-hooks t))
1156 (when (and (boundp 'mime::preview/content-list)
1157 mime::preview/content-list)
1158 ;; We have a MIMEish article, so we use the MIME data to narrow.
1159 (let ((pcinfo (car (last mime::preview/content-list))))
1162 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1165 (when (gnus-article-search-signature)
1167 ;; Check whether we have some limits to what we consider
1168 ;; to be a signature.
1169 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1170 (list gnus-signature-limit)))
1172 (while (setq limit (pop limits))
1173 (if (or (and (integerp limit)
1174 (< (- (point-max) (point)) limit))
1176 (< (count-lines (point) (point-max)) limit))
1177 (and (gnus-functionp limit)
1179 (and (stringp limit)
1180 (not (re-search-forward limit nil t))))
1181 () ; This limit did not succeed.
1185 (narrow-to-region (point) (point-max))
1188 (defun gnus-article-search-signature ()
1189 "Search the current buffer for the signature separator.
1190 Put point at the beginning of the signature separator."
1191 (let ((cur (point)))
1192 (goto-char (point-max))
1193 (if (if (stringp gnus-signature-separator)
1194 (re-search-backward gnus-signature-separator nil t)
1195 (let ((seps gnus-signature-separator))
1197 (not (re-search-backward (car seps) nil t)))
1205 (autoload 'w3-display "w3-parse")
1206 (autoload 'w3-do-setup "w3" "" t)
1207 (autoload 'w3-region "w3-display" "" t))
1209 (defun gnus-article-treat-html ()
1212 (let ((cbuf (current-buffer)))
1213 (set-buffer gnus-article-buffer)
1214 (let (buf buffer-read-only b e)
1216 (goto-char (point-min))
1218 (if (search-forward "\n\n" nil t)
1221 (setq e (point-max)))
1223 (insert-buffer-substring gnus-article-buffer b e)
1225 (save-window-excursion
1226 (w3-region (point-min) (point-max))
1227 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1229 (delete-region (point-min) (point-max))
1232 (goto-char (point-min))
1233 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1234 (set-buffer cbuf))))
1236 (defun gnus-article-hidden-arg ()
1237 "Return the current prefix arg as a number, or 0 if no prefix."
1238 (list (if current-prefix-arg
1239 (prefix-numeric-value current-prefix-arg)
1242 (defun gnus-article-check-hidden-text (type arg)
1243 "Return nil if hiding is necessary.
1244 Arg can be nil or a number. Nil and positive means hide, negative
1245 means show, 0 means toggle."
1249 (let ((hide (gnus-article-hidden-text-p type)))
1255 (gnus-article-show-hidden-text type))
1257 (if (eq hide 'hidden)
1258 (gnus-article-show-hidden-text type)
1261 (defun gnus-article-hidden-text-p (type)
1262 "Say whether the current buffer contains hidden text of type TYPE."
1263 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1265 (not (get-text-property pos 'invisible)))
1267 (text-property-any (1+ pos) (point-max) 'article-type type)))
1272 (defun gnus-article-show-hidden-text (type &optional hide)
1273 "Show all hidden text of type TYPE.
1274 If HIDE, hide the text instead."
1276 (let ((buffer-read-only nil)
1277 (inhibit-point-motion-hooks t)
1280 (while (setq beg (text-property-any end (point-max) 'article-type type))
1283 (text-property-not-all beg (point-max) 'article-type type)
1286 (gnus-article-hide-text beg end gnus-hidden-properties)
1287 (gnus-article-unhide-text beg end))
1291 (defconst article-time-units
1292 `((year . ,(* 365.25 24 60 60))
1293 (week . ,(* 7 24 60 60))
1294 (day . ,(* 24 60 60))
1298 "Mapping from time units to seconds.")
1300 (defun article-date-ut (&optional type highlight header)
1301 "Convert DATE date to universal time in the current article.
1302 If TYPE is `local', convert to local time; if it is `lapsed', output
1303 how much time has lapsed since DATE."
1304 (interactive (list 'ut t))
1305 (let* ((header (or header
1306 (mail-header-date gnus-current-headers)
1307 (message-fetch-field "date")
1309 (date (if (vectorp header) (mail-header-date header)
1311 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1312 (inhibit-point-motion-hooks t)
1313 bface eface newline)
1314 (when (and date (not (string= date "")))
1317 (nnheader-narrow-to-headers)
1318 (let ((buffer-read-only nil))
1319 ;; Delete any old Date headers.
1320 (if (re-search-forward date-regexp nil t)
1322 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1323 eface (get-text-property (1- (gnus-point-at-eol))
1325 (delete-region (progn (beginning-of-line) (point))
1326 (progn (end-of-line) (point)))
1327 (beginning-of-line))
1328 (goto-char (point-max))
1330 (insert (article-make-date-line date type))
1333 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1334 (put-text-property (match-beginning 1) (1+ (match-end 1))
1336 (put-text-property (match-beginning 2) (match-end 2)
1340 (insert "\n"))))))))
1342 (defun article-make-date-line (date type)
1343 "Return a DATE line of TYPE."
1344 (let ((time (condition-case ()
1348 ;; Convert to the local timezone. We have to slap a
1349 ;; `condition-case' round the calls to the timezone
1350 ;; functions since they aren't particularly resistant to
1353 (let ((tz (car (current-time-zone))))
1354 (format "Date: %s %s%04d" (current-time-string time)
1355 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1356 ;; Convert to Universal Time.
1359 (current-time-string
1360 (let* ((e (parse-time-string date))
1361 (tm (apply 'encode-time e))
1363 (ls (- (cadr tm) (car (current-time-zone)))))
1364 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1365 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1368 ;; Get the original date from the article.
1369 ((eq type 'original)
1370 (concat "Date: " (if (string-match "\n+$" date)
1371 (substring date 0 (match-beginning 0))
1373 ;; Let the user define the format.
1375 (if (gnus-functionp gnus-article-time-format)
1376 (funcall gnus-article-time-format time)
1379 (format-time-string gnus-article-time-format time))))
1384 (format-time-string "%Y%M%DT%h%m%s" time)))
1385 ;; Do an X-Sent lapsed format.
1387 ;; If the date is seriously mangled, the timezone functions are
1388 ;; liable to bug out, so we ignore all errors.
1389 (let* ((now (current-time))
1390 (real-time (subtract-time now time))
1391 (real-sec (and real-time
1392 (+ (* (float (car real-time)) 65536)
1394 (sec (and real-time (abs real-sec)))
1404 ;; This is a bit convoluted, but basically we go
1405 ;; through the time units for years, weeks, etc,
1406 ;; and divide things to see whether that results
1407 ;; in positive answers.
1410 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1411 ;; The (remaining) seconds are too few to
1412 ;; be divided into this time unit.
1414 ;; It's big enough, so we output it.
1415 (setq sec (- sec (* num (cdr unit))))
1417 (concat (if prev ", " "") (int-to-string
1419 " " (symbol-name (car unit))
1420 (if (> num 1) "s" ""))
1422 article-time-units "")
1423 ;; If dates are odd, then it might appear like the
1424 ;; article was sent in the future.
1427 " in the future"))))))
1429 (error "Unknown conversion type: %s" type)))))
1431 (defun article-date-local (&optional highlight)
1432 "Convert the current article date to the local timezone."
1433 (interactive (list t))
1434 (article-date-ut 'local highlight))
1436 (defun article-date-original (&optional highlight)
1437 "Convert the current article date to what it was originally.
1438 This is only useful if you have used some other date conversion
1439 function and want to see what the date was before converting."
1440 (interactive (list t))
1441 (article-date-ut 'original highlight))
1443 (defun article-date-lapsed (&optional highlight)
1444 "Convert the current article date to time lapsed since it was sent."
1445 (interactive (list t))
1446 (article-date-ut 'lapsed highlight))
1448 (defun article-update-date-lapsed ()
1449 "Function to be run from a timer to update the lapsed time line."
1450 (let (deactivate-mark)
1453 (when (gnus-buffer-live-p gnus-article-buffer)
1454 (set-buffer gnus-article-buffer)
1455 (goto-char (point-min))
1456 (when (re-search-forward "^X-Sent:" nil t)
1457 (article-date-lapsed t)))))))
1459 (defun gnus-start-date-timer (&optional n)
1460 "Start a timer to update the X-Sent header in the article buffers.
1461 The numerical prefix says how frequently (in seconds) the function
1466 (gnus-stop-date-timer)
1467 (setq article-lapsed-timer
1468 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1470 (defun gnus-stop-date-timer ()
1471 "Stop the X-Sent timer."
1473 (when article-lapsed-timer
1474 (nnheader-cancel-timer article-lapsed-timer)
1475 (setq article-lapsed-timer nil)))
1477 (defun article-date-user (&optional highlight)
1478 "Convert the current article date to the user-defined format.
1479 This format is defined by the `gnus-article-time-format' variable."
1480 (interactive (list t))
1481 (article-date-ut 'user highlight))
1483 (defun article-date-iso8601 (&optional highlight)
1484 "Convert the current article date to ISO8601."
1485 (interactive (list t))
1486 (article-date-ut 'iso8601 highlight))
1488 (defun article-show-all ()
1489 "Show all hidden text in the article buffer."
1492 (let ((buffer-read-only nil))
1493 (gnus-article-unhide-text (point-min) (point-max)))))
1495 (defun article-emphasize (&optional arg)
1496 "Emphasize text according to `gnus-emphasis-alist'."
1497 (interactive (gnus-article-hidden-arg))
1498 (unless (gnus-article-check-hidden-text 'emphasis arg)
1500 (let ((alist gnus-emphasis-alist)
1501 (buffer-read-only nil)
1502 (props (append '(article-type emphasis)
1503 gnus-hidden-properties))
1504 regexp elem beg invisible visible face)
1505 (goto-char (point-min))
1506 (search-forward "\n\n" nil t)
1508 (while (setq elem (pop alist))
1510 (setq regexp (car elem)
1511 invisible (nth 1 elem)
1512 visible (nth 2 elem)
1514 (while (re-search-forward regexp nil t)
1515 (when (and (match-beginning visible) (match-beginning invisible))
1516 (gnus-article-hide-text
1517 (match-beginning invisible) (match-end invisible) props)
1518 (gnus-article-unhide-text-type
1519 (match-beginning visible) (match-end visible) 'emphasis)
1520 (gnus-put-text-property-excluding-newlines
1521 (match-beginning visible) (match-end visible) 'face face)
1522 (goto-char (match-end invisible)))))))))
1524 (defvar gnus-summary-article-menu)
1525 (defvar gnus-summary-post-menu)
1527 ;;; Saving functions.
1529 (defun gnus-article-save (save-buffer file &optional num)
1530 "Save the currently selected article."
1531 (unless gnus-save-all-headers
1532 ;; Remove headers according to `gnus-saved-headers'.
1533 (let ((gnus-visible-headers
1534 (or gnus-saved-headers gnus-visible-headers))
1535 (gnus-article-buffer save-buffer))
1537 (set-buffer save-buffer)
1538 (article-hide-headers 1 t))))
1539 (save-window-excursion
1540 (if (not gnus-default-article-saver)
1541 (error "No default saver is defined")
1542 ;; !!! Magic! The saving functions all save
1543 ;; `gnus-save-article-buffer' (or so they think), but we
1544 ;; bind that variable to our save-buffer.
1545 (set-buffer gnus-article-buffer)
1546 (let* ((gnus-save-article-buffer save-buffer)
1549 ((not gnus-prompt-before-saving) 'default)
1550 ((eq gnus-prompt-before-saving 'always) nil)
1552 (gnus-number-of-articles-to-be-saved
1553 (when (eq gnus-prompt-before-saving t)
1555 (set-buffer gnus-article-current-summary)
1556 (funcall gnus-default-article-saver filename)))))
1558 (defun gnus-read-save-file-name (prompt &optional filename
1559 function group headers variable)
1561 (funcall function group headers (symbol-value variable)))
1566 ((eq filename 'default)
1572 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1575 (if (and gnus-number-of-articles-to-be-saved
1576 (> gnus-number-of-articles-to-be-saved 1))
1577 (format "these %d articles"
1578 gnus-number-of-articles-to-be-saved)
1581 ;; Let the split methods have their say.
1583 ;; No split name was found.
1586 (concat prompt " (default "
1587 (file-name-nondirectory default-name) ") ")
1588 (file-name-directory default-name)
1590 ;; A single group name is returned.
1591 ((stringp split-name)
1593 (funcall function split-name headers
1594 (symbol-value variable)))
1596 (concat prompt " (default "
1597 (file-name-nondirectory default-name) ") ")
1598 (file-name-directory default-name)
1600 ;; A single split name was found
1601 ((= 1 (length split-name))
1602 (let* ((name (expand-file-name
1603 (car split-name) gnus-article-save-directory))
1604 (dir (cond ((file-directory-p name)
1605 (file-name-as-directory name))
1606 ((file-exists-p name) name)
1607 (t gnus-article-save-directory))))
1609 (concat prompt " (default " name ") ")
1611 ;; A list of splits was found.
1613 (setq split-name (nreverse split-name))
1615 (let ((file-name-history
1616 (nconc split-name file-name-history)))
1620 (concat prompt " (`M-p' for defaults) ")
1621 gnus-article-save-directory
1623 gnus-article-save-directory)))
1624 (car (push result file-name-history)))))))
1625 ;; Create the directory.
1626 (gnus-make-directory (file-name-directory file))
1627 ;; If we have read a directory, we append the default file name.
1628 (when (file-directory-p file)
1629 (setq file (concat (file-name-as-directory file)
1630 (file-name-nondirectory default-name))))
1631 ;; Possibly translate some characters.
1632 (nnheader-translate-file-chars file)))))
1633 (gnus-make-directory (file-name-directory result))
1634 (set variable result)))
1636 (defun gnus-article-archive-name (group)
1637 "Return the first instance of an \"Archive-name\" in the current buffer."
1638 (let ((case-fold-search t))
1639 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1640 (nnheader-concat gnus-article-save-directory
1641 (match-string 1)))))
1643 (defun gnus-article-nndoc-name (group)
1644 "If GROUP is an nndoc group, return the name of the parent group."
1645 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1646 (gnus-group-get-parameter group 'save-article-group)))
1648 (defun gnus-summary-save-in-rmail (&optional filename)
1649 "Append this article to Rmail file.
1650 Optional argument FILENAME specifies file name.
1651 Directory to save to is default to `gnus-article-save-directory'."
1652 (setq filename (gnus-read-save-file-name
1653 "Save %s in rmail file:" filename
1654 gnus-rmail-save-name gnus-newsgroup-name
1655 gnus-current-headers 'gnus-newsgroup-last-rmail))
1656 (gnus-eval-in-buffer-window gnus-save-article-buffer
1660 (rmail-output-to-rmail-file filename))))
1663 (defun gnus-summary-save-in-mail (&optional filename)
1664 "Append this article to Unix mail file.
1665 Optional argument FILENAME specifies file name.
1666 Directory to save to is default to `gnus-article-save-directory'."
1667 (setq filename (gnus-read-save-file-name
1668 "Save %s in Unix mail file:" filename
1669 gnus-mail-save-name gnus-newsgroup-name
1670 gnus-current-headers 'gnus-newsgroup-last-mail))
1671 (gnus-eval-in-buffer-window gnus-save-article-buffer
1675 (if (and (file-readable-p filename)
1676 (mail-file-babyl-p filename))
1677 (rmail-output-to-rmail-file filename t)
1678 (gnus-output-to-mail filename)))))
1681 (defun gnus-summary-save-in-file (&optional filename overwrite)
1682 "Append this article to file.
1683 Optional argument FILENAME specifies file name.
1684 Directory to save to is default to `gnus-article-save-directory'."
1685 (setq filename (gnus-read-save-file-name
1686 "Save %s in file:" filename
1687 gnus-file-save-name gnus-newsgroup-name
1688 gnus-current-headers 'gnus-newsgroup-last-file))
1689 (gnus-eval-in-buffer-window gnus-save-article-buffer
1693 (when (and overwrite
1694 (file-exists-p filename))
1695 (delete-file filename))
1696 (gnus-output-to-file filename))))
1699 (defun gnus-summary-write-to-file (&optional filename)
1700 "Write this article to a file.
1701 Optional argument FILENAME specifies file name.
1702 The directory to save in defaults to `gnus-article-save-directory'."
1703 (gnus-summary-save-in-file nil t))
1705 (defun gnus-summary-save-body-in-file (&optional filename)
1706 "Append this article body to a file.
1707 Optional argument FILENAME specifies file name.
1708 The directory to save in defaults to `gnus-article-save-directory'."
1709 (setq filename (gnus-read-save-file-name
1710 "Save %s body in file:" filename
1711 gnus-file-save-name gnus-newsgroup-name
1712 gnus-current-headers 'gnus-newsgroup-last-file))
1713 (gnus-eval-in-buffer-window gnus-save-article-buffer
1717 (goto-char (point-min))
1718 (when (search-forward "\n\n" nil t)
1719 (narrow-to-region (point) (point-max)))
1720 (gnus-output-to-file filename))))
1723 (defun gnus-summary-save-in-pipe (&optional command)
1724 "Pipe this article to subprocess."
1726 (cond ((eq command 'default)
1727 gnus-last-shell-command)
1731 "Shell command on %s: "
1732 (if (and gnus-number-of-articles-to-be-saved
1733 (> gnus-number-of-articles-to-be-saved 1))
1734 (format "these %d articles"
1735 gnus-number-of-articles-to-be-saved)
1737 gnus-last-shell-command))))
1738 (when (string-equal command "")
1739 (setq command gnus-last-shell-command))
1740 (gnus-eval-in-buffer-window gnus-article-buffer
1743 (shell-command-on-region (point-min) (point-max) command nil)))
1744 (setq gnus-last-shell-command command))
1746 ;;; Article file names when saving.
1748 (defun gnus-capitalize-newsgroup (newsgroup)
1749 "Capitalize NEWSGROUP name."
1750 (when (not (zerop (length newsgroup)))
1751 (concat (char-to-string (upcase (aref newsgroup 0)))
1752 (substring newsgroup 1))))
1754 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1755 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1756 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1757 Otherwise, it is like ~/News/news/group/num."
1760 (concat (if (gnus-use-long-file-name 'not-save)
1761 (gnus-capitalize-newsgroup newsgroup)
1762 (gnus-newsgroup-directory-form newsgroup))
1763 "/" (int-to-string (mail-header-number headers)))
1764 gnus-article-save-directory)))
1766 (string-equal (file-name-directory default)
1767 (file-name-directory last-file))
1768 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1770 (or last-file default))))
1772 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1773 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1774 If variable `gnus-use-long-file-name' is non-nil, it is
1775 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1778 (concat (if (gnus-use-long-file-name 'not-save)
1780 (gnus-newsgroup-directory-form newsgroup))
1781 "/" (int-to-string (mail-header-number headers)))
1782 gnus-article-save-directory)))
1784 (string-equal (file-name-directory default)
1785 (file-name-directory last-file))
1786 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1788 (or last-file default))))
1790 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1791 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1792 If variable `gnus-use-long-file-name' is non-nil, it is
1793 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1796 (if (gnus-use-long-file-name 'not-save)
1797 (gnus-capitalize-newsgroup newsgroup)
1798 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1799 gnus-article-save-directory)))
1801 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1802 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1803 If variable `gnus-use-long-file-name' is non-nil, it is
1804 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1807 (if (gnus-use-long-file-name 'not-save)
1809 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1810 gnus-article-save-directory)))
1817 (setq afunc (car func)
1820 gfunc (intern (format "gnus-%s" func))))
1822 (if (not (fboundp afunc))
1824 `(lambda (&optional interactive &rest args)
1825 ,(documentation afunc t)
1826 (interactive (list t))
1828 (set-buffer gnus-article-buffer)
1830 (call-interactively ',afunc)
1831 (apply ',afunc args))))))))
1832 '(article-hide-headers
1833 article-hide-boring-headers
1834 article-treat-overstrike
1835 (article-fill . gnus-article-word-wrap)
1837 article-display-x-face
1838 article-de-quoted-unreadable
1839 article-mime-decode-quoted-printable
1842 article-hide-signature
1843 article-remove-trailing-blank-lines
1844 article-strip-leading-blank-lines
1845 article-strip-multiple-blank-lines
1846 article-strip-leading-space
1847 article-strip-blank-lines
1848 article-strip-all-blank-lines
1850 article-date-iso8601
1851 article-date-original
1853 article-decode-mime-words
1857 article-treat-dumbquotes
1858 (article-show-all . gnus-article-show-all-headers))))
1861 ;;; Gnus article mode
1864 (put 'gnus-article-mode 'mode-class 'special)
1866 (gnus-define-keys gnus-article-mode-map
1867 " " gnus-article-goto-next-page
1868 "\177" gnus-article-goto-prev-page
1869 [delete] gnus-article-goto-prev-page
1870 "\C-c^" gnus-article-refer-article
1871 "h" gnus-article-show-summary
1872 "s" gnus-article-show-summary
1873 "\C-c\C-m" gnus-article-mail
1874 "?" gnus-article-describe-briefly
1875 gnus-mouse-2 gnus-article-push-button
1876 "\r" gnus-article-press-button
1877 "\t" gnus-article-next-button
1878 "\M-\t" gnus-article-prev-button
1879 "e" gnus-article-edit
1880 "<" beginning-of-buffer
1882 "\C-c\C-i" gnus-info-find-node
1885 "\C-d" gnus-article-read-summary-keys
1886 "\M-*" gnus-article-read-summary-keys
1887 "\M-#" gnus-article-read-summary-keys
1888 "\M-^" gnus-article-read-summary-keys
1889 "\M-g" gnus-article-read-summary-keys)
1891 (substitute-key-definition
1892 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1894 (defun gnus-article-make-menu-bar ()
1895 (gnus-turn-off-edit-menu 'article)
1896 (unless (boundp 'gnus-article-article-menu)
1898 gnus-article-article-menu gnus-article-mode-map ""
1900 ["Scroll forwards" gnus-article-goto-next-page t]
1901 ["Scroll backwards" gnus-article-goto-prev-page t]
1902 ["Show summary" gnus-article-show-summary t]
1903 ["Fetch Message-ID at point" gnus-article-refer-article t]
1904 ["Mail to address at point" gnus-article-mail t]
1905 ["Send a bug report" gnus-bug t]))
1908 gnus-article-treatment-menu gnus-article-mode-map ""
1910 ["Hide headers" gnus-article-hide-headers t]
1911 ["Hide signature" gnus-article-hide-signature t]
1912 ["Hide citation" gnus-article-hide-citation t]
1913 ["Treat overstrike" gnus-article-treat-overstrike t]
1914 ["Remove carriage return" gnus-article-remove-cr t]
1915 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1917 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1919 (when (boundp 'gnus-summary-post-menu)
1920 (define-key gnus-article-mode-map [menu-bar post]
1921 (cons "Post" gnus-summary-post-menu)))
1923 (gnus-run-hooks 'gnus-article-menu-hook)))
1925 (defun gnus-article-mode ()
1926 "Major mode for displaying an article.
1928 All normal editing commands are switched off.
1930 The following commands are available in addition to all summary mode
1932 \\<gnus-article-mode-map>
1933 \\[gnus-article-next-page]\t Scroll the article one page forwards
1934 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1935 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1936 \\[gnus-article-show-summary]\t Display the summary buffer
1937 \\[gnus-article-mail]\t Send a reply to the address near point
1938 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1939 \\[gnus-info-find-node]\t Go to the Gnus info node"
1941 (when (gnus-visual-p 'article-menu 'menu)
1942 (gnus-article-make-menu-bar))
1943 (gnus-simplify-mode-line)
1944 (setq mode-name "Article")
1945 (setq major-mode 'gnus-article-mode)
1946 (make-local-variable 'minor-mode-alist)
1947 (use-local-map gnus-article-mode-map)
1948 (gnus-update-format-specifications nil 'article-mode)
1949 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1950 (make-local-variable 'gnus-page-broken)
1951 (make-local-variable 'gnus-button-marker-list)
1952 (make-local-variable 'gnus-article-current-summary)
1953 (make-local-variable 'gnus-article-mime-handles)
1954 (gnus-set-default-directory)
1955 (buffer-disable-undo (current-buffer))
1956 (setq buffer-read-only t)
1957 (set-syntax-table gnus-article-mode-syntax-table)
1958 (mm-enable-multibyte)
1959 (gnus-run-hooks 'gnus-article-mode-hook))
1961 (defun gnus-article-setup-buffer ()
1962 "Initialize the article buffer."
1963 (let* ((name (if gnus-single-article-buffer "*Article*"
1964 (concat "*Article " gnus-newsgroup-name "*")))
1966 (progn (string-match "\\*Article" name)
1967 (concat " *Original Article"
1968 (substring name (match-end 0))))))
1969 (setq gnus-article-buffer name)
1970 (setq gnus-original-article-buffer original)
1971 ;; This might be a variable local to the summary buffer.
1972 (unless gnus-single-article-buffer
1974 (set-buffer gnus-summary-buffer)
1975 (setq gnus-article-buffer name)
1976 (setq gnus-original-article-buffer original)
1977 (gnus-set-global-variables)))
1978 ;; Init original article buffer.
1980 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1981 (mm-enable-multibyte)
1982 (setq major-mode 'gnus-original-article-mode)
1983 (make-local-variable 'gnus-original-article))
1984 (if (get-buffer name)
1987 (buffer-disable-undo (current-buffer))
1988 (setq buffer-read-only t)
1989 (unless (eq major-mode 'gnus-article-mode)
1990 (gnus-article-mode))
1993 (set-buffer (gnus-get-buffer-create name))
1995 (make-local-variable 'gnus-summary-buffer)
1996 (current-buffer)))))
1998 ;; Set article window start at LINE, where LINE is the number of lines
1999 ;; from the head of the article.
2000 (defun gnus-article-set-window-start (&optional line)
2002 (get-buffer-window gnus-article-buffer t)
2004 (set-buffer gnus-article-buffer)
2005 (goto-char (point-min))
2008 (gnus-message 6 "Moved to bookmark")
2009 (search-forward "\n\n" nil t)
2013 (defun gnus-article-prepare (article &optional all-headers header)
2014 "Prepare ARTICLE in article mode buffer.
2015 ARTICLE should either be an article number or a Message-ID.
2016 If ARTICLE is an id, HEADER should be the article headers.
2017 If ALL-HEADERS is non-nil, no headers are hidden."
2019 ;; Make sure we start in a summary buffer.
2020 (unless (eq major-mode 'gnus-summary-mode)
2021 (set-buffer gnus-summary-buffer))
2022 (setq gnus-summary-buffer (current-buffer))
2023 (let* ((gnus-article (if header (mail-header-number header) article))
2024 (summary-buffer (current-buffer))
2025 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2026 (group gnus-newsgroup-name)
2029 (gnus-article-setup-buffer)
2030 (set-buffer gnus-article-buffer)
2031 ;; Deactivate active regions.
2032 (when (and (boundp 'transient-mark-mode)
2033 transient-mark-mode)
2034 (setq mark-active nil))
2035 (if (not (setq result (let ((buffer-read-only nil))
2036 (gnus-request-article-this-buffer
2038 ;; There is no such article.
2040 (when (and (numberp article)
2041 (not (memq article gnus-newsgroup-sparse)))
2042 (setq gnus-article-current
2043 (cons gnus-newsgroup-name article))
2044 (set-buffer gnus-summary-buffer)
2045 (setq gnus-current-article article)
2046 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2048 (gnus-summary-set-agent-mark article)
2049 (message "Message marked for downloading"))
2050 (gnus-summary-mark-article article gnus-canceled-mark)
2051 (unless (memq article gnus-newsgroup-sparse)
2053 "No such article (may have expired or been canceled)")))))
2054 (if (or (eq result 'pseudo)
2055 (eq result 'nneething))
2058 (set-buffer summary-buffer)
2059 (push article gnus-newsgroup-history)
2060 (setq gnus-last-article gnus-current-article
2061 gnus-current-article 0
2062 gnus-current-headers nil
2063 gnus-article-current nil)
2064 (if (eq result 'nneething)
2065 (gnus-configure-windows 'summary)
2066 (gnus-configure-windows 'article))
2067 (gnus-set-global-variables))
2068 (gnus-set-mode-line 'article))
2069 ;; The result from the `request' was an actual article -
2070 ;; or at least some text that is now displayed in the
2072 (when (and (numberp article)
2073 (not (eq article gnus-current-article)))
2074 ;; Seems like a new article has been selected.
2075 ;; `gnus-current-article' must be an article number.
2077 (set-buffer summary-buffer)
2078 (push article gnus-newsgroup-history)
2079 (setq gnus-last-article gnus-current-article
2080 gnus-current-article article
2081 gnus-current-headers
2082 (gnus-summary-article-header gnus-current-article)
2083 gnus-article-current
2084 (cons gnus-newsgroup-name gnus-current-article))
2085 (unless (vectorp gnus-current-headers)
2086 (setq gnus-current-headers nil))
2087 (gnus-summary-goto-subject gnus-current-article)
2088 (when (gnus-summary-show-thread)
2089 ;; If the summary buffer really was folded, the
2090 ;; previous goto may not actually have gone to
2091 ;; the right article, but the thread root instead.
2093 (gnus-summary-goto-subject gnus-current-article))
2094 (gnus-run-hooks 'gnus-mark-article-hook)
2095 (gnus-set-mode-line 'summary)
2096 (when (gnus-visual-p 'article-highlight 'highlight)
2097 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2098 ;; Set the global newsgroup variables here.
2099 ;; Suggested by Jim Sisolak
2100 ;; <sisolak@trans4.neep.wisc.edu>.
2101 (gnus-set-global-variables)
2102 (setq gnus-have-all-headers
2103 (or all-headers gnus-show-all-headers))))
2104 (when (or (numberp article)
2106 ;; Hooks for getting information from the article.
2107 ;; This hook must be called before being narrowed.
2108 (let (buffer-read-only)
2109 (gnus-run-hooks 'gnus-tmp-internal-hook)
2110 (gnus-run-hooks 'gnus-article-prepare-hook)
2111 (when gnus-display-mime-function
2112 (funcall gnus-display-mime-function))
2113 ;; Perform the article display hooks.
2114 (gnus-run-hooks 'gnus-article-display-hook))
2116 (goto-char (point-min))
2117 (setq gnus-page-broken
2118 (when gnus-break-pages
2119 (gnus-narrow-to-page)
2121 (gnus-set-mode-line 'article)
2122 (gnus-configure-windows 'article)
2123 (goto-char (point-min))
2124 (search-forward "\n\n" nil t)
2125 (set-window-point (get-buffer-window (current-buffer)) (point))
2129 ;;; Gnus MIME viewing functions
2132 (defvar gnus-mime-button-line-format "%{%([%t%n]%)%}\n")
2133 (defvar gnus-mime-button-line-format-alist
2134 '((?t gnus-tmp-type ?s)
2135 (?n gnus-tmp-name ?s)))
2137 (defvar gnus-mime-button-map nil)
2138 (unless gnus-mime-button-map
2139 (setq gnus-mime-button-map (make-sparse-keymap))
2140 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2141 (define-key gnus-mime-button-map "\r" 'gnus-article-press-button)
2142 (define-key gnus-mime-button-map "\M-\r" 'gnus-mime-view-part)
2143 (define-key gnus-mime-button-map "o" 'gnus-mime-save-part)
2144 (define-key gnus-mime-button-map "|" 'gnus-mime-pipe-part))
2146 (defun gnus-mime-save-part ()
2147 "Save the MIME part under point."
2149 (let ((data (get-text-property (point) 'gnus-data)))
2150 (mm-save-part data)))
2152 (defun gnus-mime-pipe-part ()
2153 "Pipe the MIME part under point to a process."
2155 (let ((data (get-text-property (point) 'gnus-data)))
2156 (mm-pipe-part data)))
2158 (defun gnus-mime-view-part ()
2159 "Interactively choose a view method for the MIME part under point."
2161 (let ((data (get-text-property (point) 'gnus-data)))
2162 (mm-interactively-view-part data)))
2164 (defun gnus-insert-mime-button (handle)
2165 (let ((gnus-tmp-name (drums-content-type-get (cadr handle) 'name))
2166 (gnus-tmp-type (caadr handle)))
2168 (setq gnus-tmp-name (concat " (" gnus-tmp-name ")")))
2170 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2171 `(local-map ,gnus-mime-button-map
2172 keymap ,gnus-mime-button-map
2173 gnus-callback mm-display-part
2174 gnus-data ,handle))))
2176 (defun gnus-display-mime ()
2177 (let ((handles (mm-dissect-buffer))
2178 handle name type b e)
2179 (mapcar 'mm-destroy-part gnus-article-mime-handles)
2180 (setq gnus-article-mime-handles nil)
2181 (setq gnus-article-mime-handles (nconc gnus-article-mime-handles handles))
2183 (goto-char (point-min))
2184 (search-forward "\n\n" nil t)
2185 (delete-region (point) (point-max))
2186 (while (setq handle (pop handles))
2187 (gnus-insert-mime-button handle)
2189 (when (mm-automatic-display-p (caadr handle))
2191 (mm-display-part handle)
2192 (goto-char (point-max)))))))
2194 (defun gnus-article-wash-status ()
2195 "Return a string which display status of article washing."
2197 (set-buffer gnus-article-buffer)
2198 (let ((cite (gnus-article-hidden-text-p 'cite))
2199 (headers (gnus-article-hidden-text-p 'headers))
2200 (boring (gnus-article-hidden-text-p 'boring-headers))
2201 (pgp (gnus-article-hidden-text-p 'pgp))
2202 (pem (gnus-article-hidden-text-p 'pem))
2203 (signature (gnus-article-hidden-text-p 'signature))
2204 (overstrike (gnus-article-hidden-text-p 'overstrike))
2205 (emphasis (gnus-article-hidden-text-p 'emphasis)))
2206 (format "%c%c%c%c%c%c%c"
2208 (if (or headers boring) ?h ? )
2209 (if (or pgp pem) ?p ? )
2210 (if signature ?s ? )
2211 (if overstrike ?o ? )
2212 (if emphasis ?e ? )))))
2214 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2216 (defun gnus-article-maybe-hide-headers ()
2217 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2218 Provided for backwards compatibility."
2219 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2221 (gnus-article-hide-headers)))
2225 (defun gnus-output-to-file (file-name)
2226 "Append the current article to a file named FILE-NAME."
2227 (let ((artbuf (current-buffer)))
2229 (insert-buffer-substring artbuf)
2230 ;; Append newline at end of the buffer as separator, and then
2232 (goto-char (point-max))
2234 (append-to-file (point-min) (point-max) file-name)
2237 (defun gnus-narrow-to-page (&optional arg)
2238 "Narrow the article buffer to a page.
2239 If given a numerical ARG, move forward ARG pages."
2241 (setq arg (if arg (prefix-numeric-value arg) 0))
2243 (set-buffer gnus-article-buffer)
2244 (goto-char (point-min))
2246 ;; Remove any old next/prev buttons.
2247 (when (gnus-visual-p 'page-marker)
2248 (let ((buffer-read-only nil))
2249 (gnus-remove-text-with-property 'gnus-prev)
2250 (gnus-remove-text-with-property 'gnus-next)))
2253 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2255 (re-search-forward page-delimiter nil 'move arg)))
2256 (goto-char (match-end 0)))
2259 (if (re-search-forward page-delimiter nil 'move)
2262 (when (and (gnus-visual-p 'page-marker)
2263 (not (= (point-min) 1)))
2265 (goto-char (point-min))
2266 (gnus-insert-prev-page-button)))
2267 (when (and (gnus-visual-p 'page-marker)
2268 (< (+ (point-max) 2) (buffer-size)))
2270 (goto-char (point-max))
2271 (gnus-insert-next-page-button)))))
2273 ;; Article mode commands
2275 (defun gnus-article-goto-next-page ()
2276 "Show the next page of the article."
2278 (when (gnus-article-next-page)
2279 (goto-char (point-min))
2280 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2282 (defun gnus-article-goto-prev-page ()
2283 "Show the next page of the article."
2285 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2286 (gnus-article-prev-page nil)))
2288 (defun gnus-article-next-page (&optional lines)
2289 "Show the next page of the current article.
2290 If end of article, return non-nil. Otherwise return nil.
2291 Argument LINES specifies lines to be scrolled up."
2293 (move-to-window-line -1)
2296 (and (pos-visible-in-window-p) ;Not continuation line.
2298 ;; Nothing in this page.
2299 (if (or (not gnus-page-broken)
2302 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2304 (gnus-narrow-to-page 1) ;Go to next page.
2306 ;; More in this page.
2307 (let ((scroll-in-place nil))
2311 ;; Long lines may cause an end-of-buffer error.
2312 (goto-char (point-max)))))
2313 (move-to-window-line 0)
2316 (defun gnus-article-prev-page (&optional lines)
2317 "Show previous page of current article.
2318 Argument LINES specifies lines to be scrolled down."
2320 (move-to-window-line 0)
2321 (if (and gnus-page-broken
2323 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2325 (gnus-narrow-to-page -1) ;Go to previous page.
2326 (goto-char (point-max))
2328 (let ((scroll-in-place nil))
2332 (beginning-of-buffer
2333 (goto-char (point-min))))
2334 (move-to-window-line 0)))))
2336 (defun gnus-article-refer-article ()
2337 "Read article specified by message-id around point."
2339 (let ((point (point)))
2340 (search-forward ">" nil t) ;Move point to end of "<....>".
2341 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2342 (let ((message-id (match-string 1)))
2344 (set-buffer gnus-summary-buffer)
2345 (gnus-summary-refer-article message-id))
2347 (error "No references around point"))))
2349 (defun gnus-article-show-summary ()
2350 "Reconfigure windows to show summary buffer."
2352 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2353 (error "There is no summary buffer for this article buffer")
2354 (gnus-article-set-globals)
2355 (gnus-configure-windows 'article)
2356 (gnus-summary-goto-subject gnus-current-article)
2357 (gnus-summary-position-point)))
2359 (defun gnus-article-describe-briefly ()
2360 "Describe article mode commands briefly."
2363 (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")))
2365 (defun gnus-article-summary-command ()
2366 "Execute the last keystroke in the summary buffer."
2368 (let ((obuf (current-buffer))
2369 (owin (current-window-configuration))
2371 (switch-to-buffer gnus-article-current-summary 'norecord)
2372 (setq func (lookup-key (current-local-map) (this-command-keys)))
2373 (call-interactively func)
2375 (set-window-configuration owin)
2376 (set-window-point (get-buffer-window (current-buffer)) (point))))
2378 (defun gnus-article-summary-command-nosave ()
2379 "Execute the last keystroke in the summary buffer."
2382 (pop-to-buffer gnus-article-current-summary 'norecord)
2383 (setq func (lookup-key (current-local-map) (this-command-keys)))
2384 (call-interactively func)))
2386 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2387 "Read a summary buffer key sequence and execute it from the article buffer."
2390 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2391 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2392 "=" "^" "\M-^" "|"))
2398 '("n" "Gn" "p" "Gp"))
2401 (set-buffer gnus-article-current-summary)
2402 (let (gnus-pick-mode)
2403 (push (or key last-command-event) unread-command-events)
2404 (setq keys (read-key-sequence nil))))
2407 (if (or (member keys nosaves)
2408 (member keys nosave-but-article)
2409 (member keys nosave-in-article))
2411 (save-window-excursion
2412 (pop-to-buffer gnus-article-current-summary 'norecord)
2413 ;; We disable the pick minor mode commands.
2414 (let (gnus-pick-mode)
2415 (setq func (lookup-key (current-local-map) keys))))
2418 (unless (member keys nosave-in-article)
2419 (set-buffer gnus-article-current-summary))
2420 (call-interactively func)
2421 (setq new-sum-point (point)))
2422 (when (member keys nosave-but-article)
2423 (pop-to-buffer gnus-article-buffer 'norecord)))
2424 ;; These commands should restore window configuration.
2425 (let ((obuf (current-buffer))
2426 (owin (current-window-configuration))
2428 (summary gnus-article-current-summary)
2429 func in-buffer selected)
2430 (if not-restore-window
2431 (pop-to-buffer summary 'norecord)
2432 (switch-to-buffer summary 'norecord))
2433 (setq in-buffer (current-buffer))
2434 ;; We disable the pick minor mode commands.
2435 (if (setq func (let (gnus-pick-mode)
2436 (lookup-key (current-local-map) keys)))
2438 (call-interactively func)
2439 (setq new-sum-point (point)))
2441 (when (eq in-buffer (current-buffer))
2442 (setq selected (gnus-summary-select-article))
2444 (unless not-restore-window
2445 (set-window-configuration owin))
2446 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2447 (set-window-point (get-buffer-window (current-buffer))
2449 (let ((win (get-buffer-window gnus-article-current-summary)))
2451 (set-window-point win new-sum-point))))))))
2453 (defun gnus-article-hide (&optional arg force)
2454 "Hide all the gruft in the current article.
2455 This means that PGP stuff, signatures, cited text and (some)
2456 headers will be hidden.
2457 If given a prefix, show the hidden text instead."
2458 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2459 (gnus-article-hide-headers arg)
2460 (gnus-article-hide-pgp arg)
2461 (gnus-article-hide-citation-maybe arg force)
2462 (gnus-article-hide-signature arg))
2464 (defun gnus-article-maybe-highlight ()
2465 "Do some article highlighting if article highlighting is requested."
2466 (when (gnus-visual-p 'article-highlight 'highlight)
2467 (gnus-article-highlight-some)))
2469 (defun gnus-check-group-server ()
2470 ;; Make sure the connection to the server is alive.
2471 (unless (gnus-server-opened
2472 (gnus-find-method-for-group gnus-newsgroup-name))
2473 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2474 (gnus-request-group gnus-newsgroup-name t)))
2476 (defun gnus-request-article-this-buffer (article group)
2477 "Get an article and insert it into this buffer."
2478 (let (do-update-line sparse-header)
2482 (gnus-kill-all-overlays)
2483 (setq group (or group gnus-newsgroup-name))
2485 ;; Using `gnus-request-article' directly will insert the article into
2486 ;; `nntp-server-buffer' - so we'll save some time by not having to
2487 ;; copy it from the server buffer into the article buffer.
2489 ;; We only request an article by message-id when we do not have the
2490 ;; headers for it, so we'll have to get those.
2491 (when (stringp article)
2492 (let ((gnus-override-method gnus-refer-article-method))
2493 (gnus-read-header article)))
2495 ;; If the article number is negative, that means that this article
2496 ;; doesn't belong in this newsgroup (possibly), so we find its
2497 ;; message-id and request it by id instead of number.
2498 (when (and (numberp article)
2500 (get-buffer gnus-summary-buffer)
2501 (gnus-buffer-exists-p gnus-summary-buffer))
2503 (set-buffer gnus-summary-buffer)
2504 (let ((header (gnus-summary-article-header article)))
2507 ((memq article gnus-newsgroup-sparse)
2508 ;; This is a sparse gap article.
2509 (setq do-update-line article)
2510 (setq article (mail-header-id header))
2511 (let ((gnus-override-method gnus-refer-article-method))
2512 (setq sparse-header (gnus-read-header article)))
2513 (setq gnus-newsgroup-sparse
2514 (delq article gnus-newsgroup-sparse)))
2516 ;; It's a real article.
2517 (setq article (mail-header-id header)))
2519 ;; It is an extracted pseudo-article.
2520 (setq article 'pseudo)
2521 (gnus-request-pseudo-article header))))
2523 (let ((method (gnus-find-method-for-group
2524 gnus-newsgroup-name)))
2525 (when (and (eq (car method) 'nneething)
2528 (file-name-as-directory
2529 (or (cadr (assq 'nneething-address method))
2531 (mail-header-subject header))))
2532 (when (file-directory-p dir)
2533 (setq article 'nneething)
2534 (gnus-group-enter-directory dir))))))))
2537 ;; Refuse to select canceled articles.
2538 ((and (numberp article)
2540 (get-buffer gnus-summary-buffer)
2541 (gnus-buffer-exists-p gnus-summary-buffer)
2542 (eq (cdr (save-excursion
2543 (set-buffer gnus-summary-buffer)
2544 (assq article gnus-newsgroup-reads)))
2545 gnus-canceled-mark))
2547 ;; We first check `gnus-original-article-buffer'.
2548 ((and (get-buffer gnus-original-article-buffer)
2551 (set-buffer gnus-original-article-buffer)
2552 (and (equal (car gnus-original-article) group)
2553 (eq (cdr gnus-original-article) article))))
2554 (insert-buffer-substring gnus-original-article-buffer)
2556 ;; Check the backlog.
2557 ((and gnus-keep-backlog
2558 (gnus-backlog-request-article group article (current-buffer)))
2560 ;; Check asynchronous pre-fetch.
2561 ((gnus-async-request-fetched-article group article (current-buffer))
2562 (gnus-async-prefetch-next group article gnus-summary-buffer)
2563 (when (and (numberp article) gnus-keep-backlog)
2564 (gnus-backlog-enter-article group article (current-buffer)))
2567 ((and gnus-use-cache
2569 (gnus-cache-request-article article group))
2571 ;; Get the article and put into the article buffer.
2572 ((or (stringp article) (numberp article))
2573 (let ((gnus-override-method
2574 (and (stringp article) gnus-refer-article-method))
2575 (buffer-read-only nil))
2577 (gnus-kill-all-overlays)
2578 (gnus-check-group-server)
2579 (when (gnus-request-article article group (current-buffer))
2580 (when (numberp article)
2581 (gnus-async-prefetch-next group article gnus-summary-buffer)
2582 (when gnus-keep-backlog
2583 (gnus-backlog-enter-article
2584 group article (current-buffer))))
2589 ;; Associate this article with the current summary buffer.
2590 (setq gnus-article-current-summary gnus-summary-buffer)
2592 ;; Take the article from the original article buffer
2593 ;; and place it in the buffer it's supposed to be in.
2594 (when (and (get-buffer gnus-article-buffer)
2595 (equal (buffer-name (current-buffer))
2596 (buffer-name (get-buffer gnus-article-buffer))))
2598 (if (get-buffer gnus-original-article-buffer)
2599 (set-buffer gnus-original-article-buffer)
2600 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2601 (buffer-disable-undo (current-buffer))
2602 (setq major-mode 'gnus-original-article-mode)
2603 (setq buffer-read-only t))
2604 (let (buffer-read-only)
2606 (insert-buffer-substring gnus-article-buffer))
2607 (setq gnus-original-article (cons group article))))
2610 (run-hooks 'gnus-article-decode-hook)
2612 ;; Update sparse articles.
2613 (when (and do-update-line
2614 (or (numberp article)
2616 (let ((buf (current-buffer)))
2617 (set-buffer gnus-summary-buffer)
2618 (gnus-summary-update-article do-update-line sparse-header)
2619 (gnus-summary-goto-subject do-update-line nil t)
2620 (set-window-point (get-buffer-window (current-buffer) t)
2622 (set-buffer buf))))))
2628 (defcustom gnus-article-edit-mode-hook nil
2629 "Hook run in article edit mode buffers."
2630 :group 'gnus-article-various
2633 (defvar gnus-article-edit-done-function nil)
2635 (defvar gnus-article-edit-mode-map nil)
2637 (unless gnus-article-edit-mode-map
2638 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2640 (gnus-define-keys gnus-article-edit-mode-map
2641 "\C-c\C-c" gnus-article-edit-done
2642 "\C-c\C-k" gnus-article-edit-exit)
2644 (gnus-define-keys (gnus-article-edit-wash-map
2645 "\C-c\C-w" gnus-article-edit-mode-map)
2646 "f" gnus-article-edit-full-stops))
2648 (defun gnus-article-edit-mode ()
2649 "Major mode for editing articles.
2650 This is an extended text-mode.
2652 \\{gnus-article-edit-mode-map}"
2654 (setq major-mode 'gnus-article-edit-mode)
2655 (setq mode-name "Article Edit")
2656 (use-local-map gnus-article-edit-mode-map)
2657 (make-local-variable 'gnus-article-edit-done-function)
2658 (make-local-variable 'gnus-prev-winconf)
2659 (setq buffer-read-only nil)
2660 (buffer-enable-undo)
2662 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2664 (defun gnus-article-edit (&optional force)
2665 "Edit the current article.
2666 This will have permanent effect only in mail groups.
2667 If FORCE is non-nil, allow editing of articles even in read-only
2670 (when (and (not force)
2671 (gnus-group-read-only-p))
2672 (error "The current newsgroup does not support article editing"))
2673 (gnus-article-date-original)
2674 (gnus-article-edit-article
2675 `(lambda (no-highlight)
2676 (gnus-summary-edit-article-done
2677 ,(or (mail-header-references gnus-current-headers) "")
2678 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2680 (defun gnus-article-edit-article (exit-func)
2681 "Start editing the contents of the current article buffer."
2682 (let ((winconf (current-window-configuration)))
2683 (set-buffer gnus-article-buffer)
2684 (gnus-article-edit-mode)
2685 (gnus-article-delete-text-of-type 'annotation)
2686 (gnus-set-text-properties (point-min) (point-max) nil)
2687 (gnus-configure-windows 'edit-article)
2688 (setq gnus-article-edit-done-function exit-func)
2689 (setq gnus-prev-winconf winconf)
2690 (gnus-message 6 "C-c C-c to end edits")))
2692 (defun gnus-article-edit-done (&optional arg)
2693 "Update the article edits and exit."
2698 (goto-char (point-min))
2699 (when (search-forward "\n\n" nil 1)
2700 (let ((lines (count-lines (point) (point-max)))
2701 (length (- (point-max) (point)))
2702 (case-fold-search t)
2703 (body (copy-marker (point))))
2704 (goto-char (point-min))
2705 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2706 (delete-region (match-beginning 1) (match-end 1))
2707 (insert (number-to-string length)))
2708 (goto-char (point-min))
2709 (when (re-search-forward
2710 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2711 (delete-region (match-beginning 1) (match-end 1))
2712 (insert (number-to-string length)))
2713 (goto-char (point-min))
2714 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2715 (delete-region (match-beginning 1) (match-end 1))
2716 (insert (number-to-string lines)))))))
2717 (let ((func gnus-article-edit-done-function)
2718 (buf (current-buffer))
2719 (start (window-start)))
2720 (gnus-article-edit-exit)
2723 (let ((buffer-read-only nil))
2724 (funcall func arg)))
2726 (set-window-start (get-buffer-window buf) start)
2727 (set-window-point (get-buffer-window buf) (point))))
2729 (defun gnus-article-edit-exit ()
2730 "Exit the article editing without updating."
2732 ;; We remove all text props from the article buffer.
2733 (let ((buf (format "%s" (buffer-string)))
2734 (curbuf (current-buffer))
2736 (window-start (window-start)))
2739 (let ((winconf gnus-prev-winconf))
2741 ;; The cache and backlog have to be flushed somewhat.
2742 (when gnus-use-cache
2743 (gnus-cache-update-article
2744 (car gnus-article-current) (cdr gnus-article-current)))
2745 (when gnus-keep-backlog
2746 (gnus-backlog-remove-article
2747 (car gnus-article-current) (cdr gnus-article-current)))
2748 ;; Flush original article as well.
2750 (when (get-buffer gnus-original-article-buffer)
2751 (set-buffer gnus-original-article-buffer)
2752 (setq gnus-original-article nil)))
2753 (set-window-configuration winconf)
2754 ;; Tippy-toe some to make sure that point remains where it was.
2755 (let ((buf (current-buffer)))
2757 (set-window-start (get-buffer-window (current-buffer)) window-start)
2759 (set-buffer buf)))))
2761 (defun gnus-article-edit-full-stops ()
2762 "Interactively repair spacing at end of sentences."
2765 (goto-char (point-min))
2766 (search-forward-regexp "^$" nil t)
2767 (let ((case-fold-search nil))
2768 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2771 ;;; Article highlights
2774 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2776 ;;; Internal Variables:
2778 (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\\)"
2779 "Regular expression that matches URLs."
2780 :group 'gnus-article-buttons
2783 (defcustom gnus-button-alist
2784 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2785 gnus-button-message-id 2)
2786 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2787 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2789 gnus-button-fetch-group 4)
2790 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2791 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2792 t gnus-button-message-id 3)
2793 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2794 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2795 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2796 ;; This is how URLs _should_ be embedded in text...
2797 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2799 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2800 "*Alist of regexps matching buttons in article bodies.
2802 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2803 REGEXP: is the string matching text around the button,
2804 BUTTON: is the number of the regexp grouping actually matching the button,
2805 FORM: is a lisp expression which must eval to true for the button to
2807 CALLBACK: is the function to call when the user push this button, and each
2808 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2810 CALLBACK can also be a variable, in that case the value of that
2811 variable it the real callback function."
2812 :group 'gnus-article-buttons
2813 :type '(repeat (list regexp
2814 (integer :tag "Button")
2816 (function :tag "Callback")
2819 (integer :tag "Regexp group")))))
2821 (defcustom gnus-header-button-alist
2822 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2823 0 t gnus-button-message-id 0)
2824 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2825 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2826 0 t gnus-button-mailto 0)
2827 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2828 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2829 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2830 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2831 gnus-button-message-id 3))
2832 "*Alist of headers and regexps to match buttons in article heads.
2834 This alist is very similar to `gnus-button-alist', except that each
2835 alist has an additional HEADER element first in each entry:
2837 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2839 HEADER is a regexp to match a header. For a fuller explanation, see
2840 `gnus-button-alist'."
2841 :group 'gnus-article-buttons
2842 :group 'gnus-article-headers
2843 :type '(repeat (list (regexp :tag "Header")
2845 (integer :tag "Button")
2847 (function :tag "Callback")
2850 (integer :tag "Regexp group")))))
2852 (defvar gnus-button-regexp nil)
2853 (defvar gnus-button-marker-list nil)
2854 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2856 (defvar gnus-button-last nil)
2857 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2861 (defun gnus-article-push-button (event)
2862 "Check text under the mouse pointer for a callback function.
2863 If the text under the mouse pointer has a `gnus-callback' property,
2864 call it with the value of the `gnus-data' text property."
2866 (set-buffer (window-buffer (posn-window (event-start event))))
2867 (let* ((pos (posn-point (event-start event)))
2868 (data (get-text-property pos 'gnus-data))
2869 (fun (get-text-property pos 'gnus-callback)))
2872 (funcall fun data))))
2874 (defun gnus-article-press-button ()
2875 "Check text at point for a callback function.
2876 If the text at point has a `gnus-callback' property,
2877 call it with the value of the `gnus-data' text property."
2879 (let* ((data (get-text-property (point) 'gnus-data))
2880 (fun (get-text-property (point) 'gnus-callback)))
2882 (funcall fun data))))
2884 (defun gnus-article-prev-button (n)
2885 "Move point to N buttons backward.
2886 If N is negative, move forward instead."
2888 (gnus-article-next-button (- n)))
2890 (defun gnus-article-next-button (n)
2891 "Move point to N buttons forward.
2892 If N is negative, move backward instead."
2894 (let ((function (if (< n 0) 'previous-single-property-change
2895 'next-single-property-change))
2896 (inhibit-point-motion-hooks t)
2898 (limit (if (< n 0) (point-min) (point-max))))
2900 (while (and (not (= limit (point)))
2902 ;; Skip past the current button.
2903 (when (get-text-property (point) 'gnus-callback)
2904 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2905 ;; Go to the next (or previous) button.
2906 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2907 ;; Put point at the start of the button.
2908 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2909 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2910 ;; Skip past intangible buttons.
2911 (when (get-text-property (point) 'intangible)
2915 (gnus-message 5 "No more buttons"))
2918 (defun gnus-article-highlight (&optional force)
2919 "Highlight current article.
2920 This function calls `gnus-article-highlight-headers',
2921 `gnus-article-highlight-citation',
2922 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2923 do the highlighting. See the documentation for those functions."
2924 (interactive (list 'force))
2925 (gnus-article-highlight-headers)
2926 (gnus-article-highlight-citation force)
2927 (gnus-article-highlight-signature)
2928 (gnus-article-add-buttons force)
2929 (gnus-article-add-buttons-to-head))
2931 (defun gnus-article-highlight-some (&optional force)
2932 "Highlight current article.
2933 This function calls `gnus-article-highlight-headers',
2934 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2935 do the highlighting. See the documentation for those functions."
2936 (interactive (list 'force))
2937 (gnus-article-highlight-headers)
2938 (gnus-article-highlight-signature)
2939 (gnus-article-add-buttons))
2941 (defun gnus-article-highlight-headers ()
2942 "Highlight article headers as specified by `gnus-header-face-alist'."
2945 (set-buffer gnus-article-buffer)
2947 (let ((alist gnus-header-face-alist)
2948 (buffer-read-only nil)
2949 (case-fold-search t)
2950 (inhibit-point-motion-hooks t)
2951 entry regexp header-face field-face from hpoints fpoints)
2952 (message-narrow-to-head)
2953 (while (setq entry (pop alist))
2954 (goto-char (point-min))
2955 (setq regexp (concat "^\\("
2956 (if (string-equal "" (nth 0 entry))
2960 header-face (nth 1 entry)
2961 field-face (nth 2 entry))
2962 (while (and (re-search-forward regexp nil t)
2966 (unless (search-forward ":" nil t)
2968 (when (and header-face
2969 (not (memq (point) hpoints)))
2970 (push (point) hpoints)
2971 (gnus-put-text-property from (point) 'face header-face))
2972 (when (and field-face
2973 (not (memq (setq from (point)) fpoints)))
2975 (if (re-search-forward "^[^ \t]" nil t)
2977 (goto-char (point-max)))
2978 (gnus-put-text-property from (point) 'face field-face))))))))
2980 (defun gnus-article-highlight-signature ()
2981 "Highlight the signature in an article.
2982 It does this by highlighting everything after
2983 `gnus-signature-separator' using `gnus-signature-face'."
2986 (set-buffer gnus-article-buffer)
2987 (let ((buffer-read-only nil)
2988 (inhibit-point-motion-hooks t))
2990 (when (and gnus-signature-face
2991 (gnus-article-narrow-to-signature))
2992 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2993 'face gnus-signature-face)
2995 (gnus-article-search-signature)
2996 (let ((start (match-beginning 0))
2997 (end (set-marker (make-marker) (1+ (match-end 0)))))
2998 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3001 (defun gnus-button-in-region-p (b e prop)
3002 "Say whether PROP exists in the region."
3003 (text-property-not-all b e prop nil))
3005 (defun gnus-article-add-buttons (&optional force)
3006 "Find external references in the article and make buttons of them.
3007 \"External references\" are things like Message-IDs and URLs, as
3008 specified by `gnus-button-alist'."
3009 (interactive (list 'force))
3011 (set-buffer gnus-article-buffer)
3012 (let ((buffer-read-only nil)
3013 (inhibit-point-motion-hooks t)
3014 (case-fold-search t)
3015 (alist gnus-button-alist)
3017 ;; Remove all old markers.
3019 (while (setq marker (pop gnus-button-marker-list))
3021 (when (setq entry (gnus-button-entry))
3022 (put-text-property (match-beginning (nth 1 entry))
3023 (match-end (nth 1 entry))
3024 'gnus-callback nil))
3025 (set-marker marker nil)))
3026 ;; We skip the headers.
3027 (goto-char (point-min))
3028 (unless (search-forward "\n\n" nil t)
3029 (goto-char (point-max)))
3031 (while (setq entry (pop alist))
3032 (setq regexp (car entry))
3034 (while (re-search-forward regexp nil t)
3035 (let* ((start (and entry (match-beginning (nth 1 entry))))
3036 (end (and entry (match-end (nth 1 entry))))
3037 (from (match-beginning 0)))
3038 (when (and (or (eq t (nth 2 entry))
3039 (eval (nth 2 entry)))
3040 (not (gnus-button-in-region-p
3041 start end 'gnus-callback)))
3042 ;; That optional form returned non-nil, so we add the
3044 (gnus-article-add-button
3045 start end 'gnus-button-push
3046 (car (push (set-marker (make-marker) from)
3047 gnus-button-marker-list))))))))))
3049 ;; Add buttons to the head of an article.
3050 (defun gnus-article-add-buttons-to-head ()
3051 "Add buttons to the head of the article."
3054 (set-buffer gnus-article-buffer)
3055 (let ((buffer-read-only nil)
3056 (inhibit-point-motion-hooks t)
3057 (case-fold-search t)
3058 (alist gnus-header-button-alist)
3060 (nnheader-narrow-to-headers)
3062 ;; Each alist entry.
3063 (setq entry (car alist)
3065 (goto-char (point-min))
3066 (while (re-search-forward (car entry) nil t)
3067 ;; Each header matching the entry.
3068 (setq beg (match-beginning 0))
3069 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3070 (match-beginning 0))
3073 (while (re-search-forward (nth 1 entry) end t)
3074 ;; Each match within a header.
3075 (let* ((entry (cdr entry))
3076 (start (match-beginning (nth 1 entry)))
3077 (end (match-end (nth 1 entry)))
3078 (form (nth 2 entry)))
3079 (goto-char (match-end 0))
3081 (gnus-article-add-button
3082 start end (nth 3 entry)
3083 (buffer-substring (match-beginning (nth 4 entry))
3084 (match-end (nth 4 entry)))))))
3088 ;;; External functions:
3090 (defun gnus-article-add-button (from to fun &optional data)
3091 "Create a button between FROM and TO with callback FUN and data DATA."
3092 (when gnus-article-button-face
3093 (gnus-overlay-put (gnus-make-overlay from to)
3094 'face gnus-article-button-face))
3095 (gnus-add-text-properties
3097 (nconc (and gnus-article-mouse-face
3098 (list gnus-mouse-face-prop gnus-article-mouse-face))
3099 (list 'gnus-callback fun)
3100 (and data (list 'gnus-data data)))))
3102 ;;; Internal functions:
3104 (defun gnus-article-set-globals ()
3106 (set-buffer gnus-summary-buffer)
3107 (gnus-set-global-variables)))
3109 (defun gnus-signature-toggle (end)
3111 (set-buffer gnus-article-buffer)
3112 (let ((buffer-read-only nil)
3113 (inhibit-point-motion-hooks t))
3114 (if (get-text-property end 'invisible)
3115 (gnus-article-unhide-text end (point-max))
3116 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3118 (defun gnus-button-entry ()
3119 ;; Return the first entry in `gnus-button-alist' matching this place.
3120 (let ((alist gnus-button-alist)
3123 (setq entry (pop alist))
3124 (if (looking-at (car entry))
3129 (defun gnus-button-push (marker)
3130 ;; Push button starting at MARKER.
3132 (set-buffer gnus-article-buffer)
3134 (let* ((entry (gnus-button-entry))
3135 (inhibit-point-motion-hooks t)
3137 (args (mapcar (lambda (group)
3138 (let ((string (match-string group)))
3139 (gnus-set-text-properties
3140 0 (length string) nil string)
3147 (fboundp (symbol-value fun)))
3148 (apply (symbol-value fun) args))
3150 (gnus-message 1 "You must define `%S' to use this button"
3151 (cons fun args)))))))
3153 (defun gnus-button-message-id (message-id)
3156 (set-buffer gnus-summary-buffer)
3157 (gnus-summary-refer-article message-id)))
3159 (defun gnus-button-fetch-group (address)
3160 "Fetch GROUP specified by ADDRESS."
3161 (if (not (string-match "[:/]" address))
3162 ;; This is just a simple group url.
3163 (gnus-group-read-ephemeral-group address gnus-select-method)
3164 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3166 (error "Can't parse %s" address)
3167 (gnus-group-read-ephemeral-group
3168 (match-string 4 address)
3169 `(nntp ,(match-string 1 address)
3170 (nntp-address ,(match-string 1 address))
3171 (nntp-port-number ,(if (match-end 3)
3172 (match-string 3 address)
3175 (defun gnus-url-parse-query-string (query &optional downcase)
3176 (let (retval pairs cur key val)
3177 (setq pairs (split-string query "&"))
3179 (setq cur (car pairs)
3181 (if (not (string-match "=" cur))
3183 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3184 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3186 (setq key (downcase key)))
3187 (setq cur (assoc key retval))
3189 (setcdr cur (cons val (cdr cur)))
3190 (setq retval (cons (list key val) retval)))))
3193 (defun gnus-url-unhex (x)
3200 (defun gnus-url-unhex-string (str &optional allow-newlines)
3201 "Remove %XXX embedded spaces, etc in a url.
3202 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3203 decoding of carriage returns and line feeds in the string, which is normally
3204 forbidden in URL encoding."
3205 (setq str (or str ""))
3207 (case-fold-search t))
3208 (while (string-match "%[0-9a-f][0-9a-f]" str)
3209 (let* ((start (match-beginning 0))
3210 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3212 (gnus-url-unhex (elt str (+ start 2))))))
3214 tmp (substring str 0 start)
3217 (char-to-string code))
3218 ((or (= code ?\n) (= code ?\r))
3220 (t (char-to-string code))))
3221 str (substring str (match-end 0)))))
3222 (setq tmp (concat tmp str))
3225 (defun gnus-url-mailto (url)
3226 ;; Send mail to someone
3227 (when (string-match "mailto:/*\\(.*\\)" url)
3228 (setq url (substring url (match-beginning 1) nil)))
3229 (let (to args subject func)
3230 (if (string-match (regexp-quote "?") url)
3231 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3232 args (gnus-url-parse-query-string
3233 (substring url (match-end 0) nil) t))
3234 (setq to (gnus-url-unhex-string url)))
3235 (setq args (cons (list "to" to) args)
3236 subject (cdr-safe (assoc "subject" args)))
3239 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3242 (message-position-on-field (caar args)))
3243 (insert (mapconcat 'identity (cdar args) ", "))
3244 (setq args (cdr args)))
3247 (message-goto-subject))))
3249 (defun gnus-button-mailto (address)
3251 (set-buffer (gnus-copy-article-buffer))
3252 (message-reply address))
3254 (defun gnus-button-reply (address)
3255 ;; Reply to ADDRESS.
3256 (message-reply address))
3258 (defun gnus-button-url (address)
3260 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3261 (if (listp browse-url-browser-function)
3262 (browse-url address)
3263 (funcall browse-url-browser-function address)))
3265 (defun gnus-button-embedded-url (address)
3267 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3268 (if (listp browse-url-browser-function)
3269 (browse-url (gnus-strip-whitespace address))
3270 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3272 ;;; Next/prev buttons in the article buffer.
3274 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3275 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3277 (defvar gnus-prev-page-map nil)
3278 (unless gnus-prev-page-map
3279 (setq gnus-prev-page-map (make-sparse-keymap))
3280 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3281 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3283 (defun gnus-insert-prev-page-button ()
3284 (let ((buffer-read-only nil))
3286 gnus-prev-page-line-format nil
3287 `(gnus-prev t local-map ,gnus-prev-page-map
3288 gnus-callback gnus-article-button-prev-page
3289 gnus-type annotation))))
3291 (defvar gnus-next-page-map nil)
3292 (unless gnus-next-page-map
3293 (setq gnus-next-page-map (make-keymap))
3294 (suppress-keymap gnus-prev-page-map)
3295 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3296 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3298 (defun gnus-button-next-page ()
3299 "Go to the next page."
3301 (let ((win (selected-window)))
3302 (select-window (get-buffer-window gnus-article-buffer t))
3303 (gnus-article-next-page)
3304 (select-window win)))
3306 (defun gnus-button-prev-page ()
3307 "Go to the prev page."
3309 (let ((win (selected-window)))
3310 (select-window (get-buffer-window gnus-article-buffer t))
3311 (gnus-article-prev-page)
3312 (select-window win)))
3314 (defun gnus-insert-next-page-button ()
3315 (let ((buffer-read-only nil))
3316 (gnus-eval-format gnus-next-page-line-format nil
3318 t local-map ,gnus-next-page-map
3319 gnus-callback gnus-article-button-next-page
3320 gnus-type annotation))))
3322 (defun gnus-article-button-next-page (arg)
3323 "Go to the next page."
3325 (let ((win (selected-window)))
3326 (select-window (get-buffer-window gnus-article-buffer t))
3327 (gnus-article-next-page)
3328 (select-window win)))
3330 (defun gnus-article-button-prev-page (arg)
3331 "Go to the prev page."
3333 (let ((win (selected-window)))
3334 (select-window (get-buffer-window gnus-article-buffer t))
3335 (gnus-article-prev-page)
3336 (select-window win)))
3342 (run-hooks 'gnus-art-load-hook)
3344 ;;; gnus-art.el ends here