1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
41 (defgroup gnus-article nil
43 :link '(custom-manual "(gnus)The Article Buffer")
46 (defgroup gnus-article-hiding nil
47 "Hiding article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
51 (defgroup gnus-article-highlight nil
52 "Article highlighting."
53 :link '(custom-manual "(gnus)Article Highlighting")
57 (defgroup gnus-article-signature nil
59 :link '(custom-manual "(gnus)Article Signature")
62 (defgroup gnus-article-headers nil
64 :link '(custom-manual "(gnus)Hiding Headers")
67 (defgroup gnus-article-washing nil
68 "Special commands on articles."
69 :link '(custom-manual "(gnus)Article Washing")
72 (defgroup gnus-article-emphasis nil
73 "Fontisizing articles."
74 :link '(custom-manual "(gnus)Article Fontisizing")
77 (defgroup gnus-article-saving nil
79 :link '(custom-manual "(gnus)Saving Articles")
82 (defgroup gnus-article-mime nil
83 "Worshiping the MIME wonder."
84 :link '(custom-manual "(gnus)Using MIME")
87 (defgroup gnus-article-buttons nil
88 "Pushable buttons in the article buffer."
89 :link '(custom-manual "(gnus)Article Buttons")
92 (defgroup gnus-article-various nil
93 "Other article options."
94 :link '(custom-manual "(gnus)Misc Article")
97 (defcustom gnus-ignored-headers
98 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
99 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
100 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
101 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
102 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
103 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
104 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
105 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
106 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
107 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
108 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
109 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
110 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
111 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
112 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
113 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
114 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
115 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
117 "*All headers that start with this regexp will be hidden.
118 This variable can also be a list of regexps of headers to be ignored.
119 If `gnus-visible-headers' is non-nil, this variable will be ignored."
120 :type '(choice :custom-show nil
123 :group 'gnus-article-hiding)
125 (defcustom gnus-visible-headers
126 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
127 "*All headers that do not match this regexp will be hidden.
128 This variable can also be a list of regexp of headers to remain visible.
129 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
130 :type '(repeat :value-to-internal (lambda (widget value)
131 (custom-split-regexp-maybe value))
132 :match (lambda (widget value)
134 (widget-editable-list-match widget value)))
136 :group 'gnus-article-hiding)
138 (defcustom gnus-sorted-header-list
139 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
140 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
141 "*This variable is a list of regular expressions.
142 If it is non-nil, headers that match the regular expressions will
143 be placed first in the article buffer in the sequence specified by
145 :type '(repeat regexp)
146 :group 'gnus-article-hiding)
148 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
149 "Headers that are only to be displayed if they have interesting data.
150 Possible values in this list are `empty', `newsgroups', `followup-to',
151 `reply-to', `date', `long-to', and `many-to'."
152 :type '(set (const :tag "Headers with no content." empty)
153 (const :tag "Newsgroups with only one group." newsgroups)
154 (const :tag "Followup-to identical to newsgroups." followup-to)
155 (const :tag "Reply-to identical to from." reply-to)
156 (const :tag "Date less than four days old." date)
157 (const :tag "Very long To header." long-to)
158 (const :tag "Multiple To headers." many-to))
159 :group 'gnus-article-hiding)
161 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
162 "Regexp matching signature separator.
163 This can also be a list of regexps. In that case, it will be checked
164 from head to tail looking for a separator. Searches will be done from
165 the end of the buffer."
166 :type '(repeat string)
167 :group 'gnus-article-signature)
169 (defcustom gnus-signature-limit nil
170 "Provide a limit to what is considered a signature.
171 If it is a number, no signature may not be longer (in characters) than
172 that number. If it is a floating point number, no signature may be
173 longer (in lines) than that number. If it is a function, the function
174 will be called without any parameters, and if it returns nil, there is
175 no signature in the buffer. If it is a string, it will be used as a
176 regexp. If it matches, the text in question is not a signature."
177 :type '(choice (integer :value 200)
179 (function :value fun)
180 (regexp :value ".*"))
181 :group 'gnus-article-signature)
183 (defcustom gnus-hidden-properties '(invisible t intangible t)
184 "Property list to use for hiding text."
186 :group 'gnus-article-hiding)
188 (defcustom gnus-article-x-face-command
189 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
190 "*String or function to be executed to display an X-Face header.
191 If it is a string, the command will be executed in a sub-shell
192 asynchronously. The compressed face will be piped to this command."
193 :type 'string ;Leave function case to Lisp.
194 :group 'gnus-article-washing)
196 (defcustom gnus-article-x-face-too-ugly nil
197 "Regexp matching posters whose face shouldn't be shown automatically."
198 :type '(choice regexp (const nil))
199 :group 'gnus-article-washing)
201 (defcustom gnus-emphasis-alist
203 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
205 '(("_" "_" underline)
208 ("_/" "/_" underline-italic)
209 ("_\\*" "\\*_" underline-bold)
210 ("\\*/" "/\\*" bold-italic)
211 ("_\\*/" "/\\*_" underline-bold-italic))))
212 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
213 2 3 gnus-emphasis-underline)
217 (format format (car spec) (cadr spec))
218 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
220 "*Alist that says how to fontify certain phrases.
221 Each item looks like this:
223 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
225 The first element is a regular expression to be matched. The second
226 is a number that says what regular expression grouping used to find
227 the entire emphasized word. The third is a number that says what
228 regexp grouping should be displayed and highlighted. The fourth
229 is the face used for highlighting."
230 :type '(repeat (list :value ("" 0 0 default)
232 (integer :tag "Match group")
233 (integer :tag "Emphasize group")
235 :group 'gnus-article-emphasis)
237 (defface gnus-emphasis-bold '((t (:bold t)))
238 "Face used for displaying strong emphasized text (*word*)."
239 :group 'gnus-article-emphasis)
241 (defface gnus-emphasis-italic '((t (:italic t)))
242 "Face used for displaying italic emphasized text (/word/)."
243 :group 'gnus-article-emphasis)
245 (defface gnus-emphasis-underline '((t (:underline t)))
246 "Face used for displaying underlined emphasized text (_word_)."
247 :group 'gnus-article-emphasis)
249 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
250 "Face used for displaying underlined bold emphasized text (_*word*_)."
251 :group 'gnus-article-emphasis)
253 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
254 "Face used for displaying underlined italic emphasized text (_*word*_)."
255 :group 'gnus-article-emphasis)
257 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
258 "Face used for displaying bold italic emphasized text (/*word*/)."
259 :group 'gnus-article-emphasis)
261 (defface gnus-emphasis-underline-bold-italic
262 '((t (:bold t :italic t :underline t)))
263 "Face used for displaying underlined bold italic emphasized text.
264 Esample: (_/*word*/_)."
265 :group 'gnus-article-emphasis)
267 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
268 "Format for display of Date headers in article bodies.
269 See `format-time-string' for the possible values.
271 The variable can also be function, which should return a complete Date
272 header. The function is called with one argument, the time, which can
273 be fed to `format-time-string'."
274 :type '(choice string symbol)
275 :link '(custom-manual "(gnus)Article Date")
276 :group 'gnus-article-washing)
279 (autoload 'hexl-hex-string-to-integer "hexl")
280 (autoload 'timezone-make-date-arpa-standard "timezone")
281 (autoload 'mail-extract-address-components "mail-extr"))
283 (defcustom gnus-save-all-headers t
284 "*If non-nil, don't remove any headers before saving."
285 :group 'gnus-article-saving
288 (defcustom gnus-prompt-before-saving 'always
289 "*This variable says how much prompting is to be done when saving articles.
290 If it is nil, no prompting will be done, and the articles will be
291 saved to the default files. If this variable is `always', each and
292 every article that is saved will be preceded by a prompt, even when
293 saving large batches of articles. If this variable is neither nil not
294 `always', there the user will be prompted once for a file name for
295 each invocation of the saving commands."
296 :group 'gnus-article-saving
297 :type '(choice (item always)
298 (item :tag "never" nil)
299 (sexp :tag "once" :format "%t\n" :value t)))
301 (defcustom gnus-saved-headers gnus-visible-headers
302 "Headers to keep if `gnus-save-all-headers' is nil.
303 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
304 If that variable is nil, however, all headers that match this regexp
305 will be kept while the rest will be deleted before saving."
306 :group 'gnus-article-saving
309 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
310 "A function to save articles in your favourite format.
311 The function must be interactively callable (in other words, it must
312 be an Emacs command).
314 Gnus provides the following functions:
316 * gnus-summary-save-in-rmail (Rmail format)
317 * gnus-summary-save-in-mail (Unix mail format)
318 * gnus-summary-save-in-folder (MH folder)
319 * gnus-summary-save-in-file (article format)
320 * gnus-summary-save-in-vm (use VM's folder format)
321 * gnus-summary-write-to-file (article format -- overwrite)."
322 :group 'gnus-article-saving
323 :type '(radio (function-item gnus-summary-save-in-rmail)
324 (function-item gnus-summary-save-in-mail)
325 (function-item gnus-summary-save-in-folder)
326 (function-item gnus-summary-save-in-file)
327 (function-item gnus-summary-save-in-vm)
328 (function-item gnus-summary-write-to-file)))
330 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
331 "A function generating a file name to save articles in Rmail format.
332 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
333 :group 'gnus-article-saving
336 (defcustom gnus-mail-save-name 'gnus-plain-save-name
337 "A function generating a file name to save articles in Unix mail format.
338 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
339 :group 'gnus-article-saving
342 (defcustom gnus-folder-save-name 'gnus-folder-save-name
343 "A function generating a file name to save articles in MH folder.
344 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
345 :group 'gnus-article-saving
348 (defcustom gnus-file-save-name 'gnus-numeric-save-name
349 "A function generating a file name to save articles in article format.
350 The function is called with NEWSGROUP, HEADERS, and optional
352 :group 'gnus-article-saving
355 (defcustom gnus-split-methods
356 '((gnus-article-archive-name)
357 (gnus-article-nndoc-name))
358 "*Variable used to suggest where articles are to be saved.
359 For instance, if you would like to save articles related to Gnus in
360 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
361 you could set this variable to something like:
363 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
364 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
366 This variable is an alist where the where the key is the match and the
367 value is a list of possible files to save in if the match is non-nil.
369 If the match is a string, it is used as a regexp match on the
370 article. If the match is a symbol, that symbol will be funcalled
371 from the buffer of the article to be saved with the newsgroup as the
372 parameter. If it is a list, it will be evaled in the same buffer.
374 If this form or function returns a string, this string will be used as
375 a possible file name; and if it returns a non-nil list, that list will
376 be used as possible file names."
377 :group 'gnus-article-saving
378 :type '(repeat (choice (list :value (fun) function)
379 (cons :value ("" "") regexp (repeat string))
382 (defcustom gnus-strict-mime t
383 "*If nil, MIME-decode even if there is no MIME-Version header."
384 :group 'gnus-article-mime
387 (defcustom gnus-article-display-method-for-mime
388 'gnus-article-display-mime-message
389 "Function to display a MIME message.
390 The function is called from the article buffer."
391 :group 'gnus-article-mime
394 (defcustom gnus-article-display-method-for-encoded-word
395 'gnus-article-display-message-with-encoded-word
396 "*Function to display a message with MIME encoded-words.
397 The function is called from the article buffer."
398 :group 'gnus-article-mime
401 (defcustom gnus-article-display-method-for-traditional
402 'gnus-article-display-traditional-message
403 "*Function to display a traditional message.
404 The function is called from the article buffer."
405 :group 'gnus-article-mime
408 (defcustom gnus-page-delimiter "^\^L"
409 "*Regexp describing what to use as article page delimiters.
410 The default value is \"^\^L\", which is a form linefeed at the
411 beginning of a line."
413 :group 'gnus-article-various)
415 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
416 "*The format specification for the article mode line.
417 See `gnus-summary-mode-line-format' for a closer description."
419 :group 'gnus-article-various)
421 (defcustom gnus-article-mode-hook nil
422 "*A hook for Gnus article mode."
424 :group 'gnus-article-various)
426 (defcustom gnus-article-menu-hook nil
427 "*Hook run after the creation of the article mode menu."
429 :group 'gnus-article-various)
431 (defcustom gnus-article-prepare-hook nil
432 "*A hook called after an article has been prepared in the article buffer.
433 If you want to run a special decoding program like nkf, use this hook."
435 :group 'gnus-article-various)
437 (defcustom gnus-article-hide-pgp-hook nil
438 "*A hook called after successfully hiding a PGP signature."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-button-face 'bold
443 "Face used for highlighting buttons in the article buffer.
445 An article button is a piece of text that you can activate by pressing
446 `RET' or `mouse-2' above it."
448 :group 'gnus-article-buttons)
450 (defcustom gnus-article-mouse-face 'highlight
451 "Face used for mouse highlighting in the article buffer.
453 Article buttons will be displayed in this face when the cursor is
456 :group 'gnus-article-buttons)
458 (defcustom gnus-signature-face 'gnus-signature-face
459 "Face used for highlighting a signature in the article buffer.
460 Obsolete; use the face `gnus-signature-face' for customizations instead."
462 :group 'gnus-article-highlight
463 :group 'gnus-article-signature)
465 (defface gnus-signature-face
468 "Face used for highlighting a signature in the article buffer."
469 :group 'gnus-article-highlight
470 :group 'gnus-article-signature)
472 (defface gnus-header-from-face
475 (:foreground "spring green"))
478 (:foreground "red3"))
481 "Face used for displaying from headers."
482 :group 'gnus-article-headers
483 :group 'gnus-article-highlight)
485 (defface gnus-header-subject-face
488 (:foreground "SeaGreen3"))
491 (:foreground "red4"))
493 (:bold t :italic t)))
494 "Face used for displaying subject headers."
495 :group 'gnus-article-headers
496 :group 'gnus-article-highlight)
498 (defface gnus-header-newsgroups-face
501 (:foreground "yellow" :italic t))
504 (:foreground "MidnightBlue" :italic t))
507 "Face used for displaying newsgroups headers."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defface gnus-header-name-face
514 (:foreground "SeaGreen"))
517 (:foreground "maroon"))
520 "Face used for displaying header names."
521 :group 'gnus-article-headers
522 :group 'gnus-article-highlight)
524 (defface gnus-header-content-face
527 (:foreground "forest green" :italic t))
530 (:foreground "indianred4" :italic t))
532 (:italic t))) "Face used for displaying header content."
533 :group 'gnus-article-headers
534 :group 'gnus-article-highlight)
536 (defcustom gnus-header-face-alist
537 '(("From" nil gnus-header-from-face)
538 ("Subject" nil gnus-header-subject-face)
539 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
540 ("" gnus-header-name-face gnus-header-content-face))
541 "*Controls highlighting of article header.
543 An alist of the form (HEADER NAME CONTENT).
545 HEADER is a regular expression which should match the name of an
546 header header and NAME and CONTENT are either face names or nil.
548 The name of each header field will be displayed using the face
549 specified by the first element in the list where HEADER match the
550 header name and NAME is non-nil. Similarly, the content will be
551 displayed by the first non-nil matching CONTENT face."
552 :group 'gnus-article-headers
553 :group 'gnus-article-highlight
554 :type '(repeat (list (regexp :tag "Header")
556 (item :tag "skip" nil)
557 (face :value default))
558 (choice :tag "Content"
559 (item :tag "skip" nil)
560 (face :value default)))))
562 ;;; Internal variables
564 (defvar article-lapsed-timer nil)
565 (defvar gnus-article-current-summary nil)
567 (defvar gnus-article-mode-syntax-table
568 (let ((table (copy-syntax-table text-mode-syntax-table)))
569 (modify-syntax-entry ?- "w" table)
570 (modify-syntax-entry ?> ")" table)
571 (modify-syntax-entry ?< "(" table)
573 "Syntax table used in article mode buffers.
574 Initialized from `text-mode-syntax-table.")
576 (defvar gnus-save-article-buffer nil)
578 (defvar gnus-article-mode-line-format-alist
579 (nconc '((?w (gnus-article-wash-status) ?s))
580 gnus-summary-mode-line-format-alist))
582 (defvar gnus-number-of-articles-to-be-saved nil)
584 (defvar gnus-inhibit-hiding nil)
586 (defsubst gnus-article-hide-text (b e props)
587 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
588 (add-text-properties b e props)
589 (when (memq 'intangible props)
591 (max (1- b) (point-min))
592 b 'intangible (cddr (memq 'intangible props)))))
594 (defsubst gnus-article-unhide-text (b e)
595 "Remove hidden text properties from region between B and E."
596 (remove-text-properties b e gnus-hidden-properties)
597 (when (memq 'intangible gnus-hidden-properties)
598 (put-text-property (max (1- b) (point-min))
601 (defun gnus-article-hide-text-type (b e type)
602 "Hide text of TYPE between B and E."
603 (gnus-article-hide-text
604 b e (cons 'article-type (cons type gnus-hidden-properties))))
606 (defun gnus-article-unhide-text-type (b e type)
607 "Unhide text of TYPE between B and E."
608 (remove-text-properties
609 b e (cons 'article-type (cons type gnus-hidden-properties)))
610 (when (memq 'intangible gnus-hidden-properties)
611 (put-text-property (max (1- b) (point-min))
614 (defun gnus-article-hide-text-of-type (type)
615 "Hide text of TYPE in the current buffer."
617 (let ((b (point-min))
619 (while (setq b (text-property-any b e 'article-type type))
620 (add-text-properties b (incf b) gnus-hidden-properties)))))
622 (defun gnus-article-delete-text-of-type (type)
623 "Delete text of TYPE in the current buffer."
625 (let ((b (point-min)))
626 (while (setq b (text-property-any b (point-max) 'article-type type))
628 b (or (text-property-not-all b (point-max) 'article-type type)
631 (defun gnus-article-delete-invisible-text ()
632 "Delete all invisible text in the current buffer."
634 (let ((b (point-min)))
635 (while (setq b (text-property-any b (point-max) 'invisible t))
637 b (or (text-property-not-all b (point-max) 'invisible t)
640 (defun gnus-article-text-type-exists-p (type)
641 "Say whether any text of type TYPE exists in the buffer."
642 (text-property-any (point-min) (point-max) 'article-type type))
644 (defsubst gnus-article-header-rank ()
645 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
646 (let ((list gnus-sorted-header-list)
649 (when (looking-at (car list))
651 (setq list (cdr list))
655 (defun article-hide-headers (&optional arg delete)
656 "Toggle whether to hide unwanted headers and possibly sort them as well.
657 If given a negative prefix, always show; if given a positive prefix,
659 (interactive (gnus-article-hidden-arg))
661 (if (gnus-article-check-hidden-text 'headers arg)
662 ;; Show boring headers as well.
664 (gnus-article-show-hidden-text 'boring-headers)
665 (when (eq 1 (point-min))
666 (set-window-start (get-buffer-window (current-buffer)) 1)))
667 ;; This function might be inhibited.
668 (unless gnus-inhibit-hiding
671 (let ((buffer-read-only nil)
673 (props (nconc (list 'article-type 'headers)
674 gnus-hidden-properties))
675 (max (1+ (length gnus-sorted-header-list)))
676 (ignored (when (not gnus-visible-headers)
677 (cond ((stringp gnus-ignored-headers)
678 gnus-ignored-headers)
679 ((listp gnus-ignored-headers)
680 (mapconcat 'identity gnus-ignored-headers
683 (cond ((stringp gnus-visible-headers)
684 gnus-visible-headers)
685 ((and gnus-visible-headers
686 (listp gnus-visible-headers))
687 (mapconcat 'identity gnus-visible-headers "\\|"))))
688 (inhibit-point-motion-hooks t)
690 ;; First we narrow to just the headers.
692 (goto-char (point-min))
693 ;; Hide any "From " lines at the beginning of (mail) articles.
694 (while (looking-at "From ")
698 (delete-region (point-min) (point))
699 (gnus-article-hide-text (point-min) (point) props)))
700 ;; Then treat the rest of the header lines.
703 (if (search-forward "\n\n" nil t) ; if there's a body
704 (progn (forward-line -1) (point))
706 ;; Then we use the two regular expressions
707 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
708 ;; select which header lines is to remain visible in the
710 (goto-char (point-min))
711 (while (re-search-forward "^[^ \t]*:" nil t)
713 ;; Mark the rank of the header.
715 (point) (1+ (point)) 'message-rank
716 (if (or (and visible (looking-at visible))
718 (not (looking-at ignored))))
719 (gnus-article-header-rank)
722 (message-sort-headers-1)
723 (when (setq beg (text-property-any
724 (point-min) (point-max) 'message-rank (+ 2 max)))
725 ;; We make the unwanted headers invisible.
727 (delete-region beg (point-max))
728 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
729 (gnus-article-hide-text-type beg (point-max) 'headers))
730 ;; Work around XEmacs lossage.
731 (put-text-property (point-min) beg 'invisible nil))))))))
733 (defun article-hide-boring-headers (&optional arg)
734 "Toggle hiding of headers that aren't very interesting.
735 If given a negative prefix, always show; if given a positive prefix,
737 (interactive (gnus-article-hidden-arg))
738 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
739 (not gnus-show-all-headers))
742 (let ((buffer-read-only nil)
743 (list gnus-boring-article-headers)
744 (inhibit-point-motion-hooks t)
746 (nnheader-narrow-to-headers)
748 (setq elem (pop list))
749 (goto-char (point-min))
751 ;; Hide empty headers.
753 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
755 (gnus-article-hide-text-type
756 (progn (beginning-of-line) (point))
759 (if (re-search-forward "^[^ \t]" nil t)
763 ;; Hide boring Newsgroups header.
764 ((eq elem 'newsgroups)
765 (when (equal (gnus-fetch-field "newsgroups")
766 (gnus-group-real-name
767 (if (boundp 'gnus-newsgroup-name)
770 (gnus-article-hide-header "newsgroups")))
771 ((eq elem 'followup-to)
772 (when (equal (message-fetch-field "followup-to")
773 (message-fetch-field "newsgroups"))
774 (gnus-article-hide-header "followup-to")))
776 (let ((from (message-fetch-field "from"))
777 (reply-to (message-fetch-field "reply-to")))
782 (nth 1 (funcall gnus-extract-address-components from))
783 (nth 1 (funcall gnus-extract-address-components reply-to)))))
784 (gnus-article-hide-header "reply-to"))))
786 (let ((date (message-fetch-field "date")))
788 (< (gnus-days-between (current-time-string) date)
790 (gnus-article-hide-header "date"))))
792 (let ((to (message-fetch-field "to")))
793 (when (> (length to) 1024)
794 (gnus-article-hide-header "to"))))
797 (goto-char (point-min))
798 (while (re-search-forward "^to:" nil t)
799 (setq to-count (1+ to-count)))
801 (while (> to-count 0)
802 (goto-char (point-min))
804 (re-search-forward "^to:" nil nil to-count)
806 (narrow-to-region (point) (point-max))
807 (gnus-article-hide-header "to"))
808 (setq to-count (1- to-count)))))))))))))
810 (defun gnus-article-hide-header (header)
812 (goto-char (point-min))
813 (when (re-search-forward (concat "^" header ":") nil t)
814 (gnus-article-hide-text-type
815 (progn (beginning-of-line) (point))
818 (if (re-search-forward "^[^ \t]" nil t)
823 (defun article-treat-dumbquotes ()
824 "Translate M******** sm*rtq**t*s into proper text."
826 (article-translate-characters "\221\222\223\223" "`'\"\""))
828 (defun article-translate-characters (from to)
829 "Translate all characters in the body of the article according to FROM and TO.
830 FROM is a string of characters to translate from; to is a string of
831 characters to translate to."
833 (goto-char (point-min))
834 (when (search-forward "\n\n" nil t)
835 (let ((buffer-read-only nil)
836 (x (make-string 225 ?x))
838 (while (< (incf i) (length x))
841 (while (< i (length from))
842 (aset x (aref from i) (aref to i))
844 (translate-region (point) (point-max) x)))))
846 (defun article-treat-overstrike ()
847 "Translate overstrikes into bold text."
850 (goto-char (point-min))
851 (when (search-forward "\n\n" nil t)
852 (let ((buffer-read-only nil))
853 (while (search-forward "\b" nil t)
854 (let ((next (char-after))
855 (previous (char-after (- (point) 2))))
856 ;; We do the boldification/underlining by hiding the
857 ;; overstrikes and putting the proper text property
861 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
862 (put-text-property (point) (1+ (point)) 'face 'bold))
864 (gnus-article-hide-text-type
865 (1- (point)) (1+ (point)) 'overstrike)
867 (- (point) 2) (1- (point)) 'face 'underline))
869 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
871 (point) (1+ (point)) 'face 'underline)))))))))
873 (defun article-fill ()
874 "Format too long lines."
877 (let ((buffer-read-only nil))
879 (goto-char (point-min))
880 (search-forward "\n\n" nil t)
882 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
883 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
884 (adaptive-fill-mode t))
886 (and (>= (current-column) (min fill-column (window-width)))
887 (not (eq (char-before) ?:))
888 (fill-paragraph nil))
891 (defun article-remove-cr ()
892 "Remove carriage returns from an article."
895 (let ((buffer-read-only nil))
896 (goto-char (point-min))
897 (while (search-forward "\r" nil t)
898 (replace-match "" t t)))))
900 (defun article-remove-trailing-blank-lines ()
901 "Remove all trailing blank lines from the article."
904 (let ((buffer-read-only nil))
905 (goto-char (point-max))
909 (while (and (not (bobp))
910 (looking-at "^[ \t]*$"))
915 (defun article-display-x-face (&optional force)
916 "Look for an X-Face header and display it if present."
917 (interactive (list 'force))
919 ;; Delete the old process, if any.
920 (when (process-status "article-x-face")
921 (delete-process "article-x-face"))
922 (let ((inhibit-point-motion-hooks t)
926 (nnheader-narrow-to-headers)
927 (setq from (message-fetch-field "from"))
928 (goto-char (point-min))
929 (while (and gnus-article-x-face-command
932 ;; Check whether this face is censored.
933 (not gnus-article-x-face-too-ugly)
934 (and gnus-article-x-face-too-ugly from
935 (not (string-match gnus-article-x-face-too-ugly
937 ;; Has to be present.
938 (re-search-forward "^X-Face: " nil t))
939 ;; This used to try to do multiple faces (`while' instead of
940 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
941 ;; work (b) it can crash some versions of Emacs (c) are
942 ;; multiple faces really something to encourage?
943 (when (stringp gnus-article-x-face-command)
945 ;; We now have the area of the buffer where the X-Face is stored.
948 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
949 ;; We display the face.
950 (if (symbolp gnus-article-x-face-command)
951 ;; The command is a lisp function, so we call it.
952 (if (gnus-functionp gnus-article-x-face-command)
953 (funcall gnus-article-x-face-command beg end)
954 (error "%s is not a function" gnus-article-x-face-command))
955 ;; The command is a string, so we interpret the command
956 ;; as a, well, command, and fork it off.
957 (let ((process-connection-type nil))
958 (process-kill-without-query
960 "article-x-face" nil shell-file-name shell-command-switch
961 gnus-article-x-face-command))
962 (process-send-region "article-x-face" beg end)
963 (process-send-eof "article-x-face"))))))))))
965 (defun gnus-article-decode-rfc1522 ()
966 "Decode MIME encoded-words in header fields."
967 (let (buffer-read-only)
968 (let ((charset (save-excursion
969 (set-buffer gnus-summary-buffer)
970 default-mime-charset)))
971 (mime-decode-header-in-buffer charset)
974 (defun article-hide-pgp (&optional arg)
975 "Toggle hiding of any PGP headers and signatures in the current article.
976 If given a negative prefix, always show; if given a positive prefix,
978 (interactive (gnus-article-hidden-arg))
979 (unless (gnus-article-check-hidden-text 'pgp arg)
981 (let ((inhibit-point-motion-hooks t)
982 buffer-read-only beg end)
984 (goto-char (point-min))
985 ;; Hide the "header".
986 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
987 (delete-region (1+ (match-beginning 0)) (match-end 0))
989 ;; Hide the actual signature.
990 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
991 (setq end (1+ (match-beginning 0)))
994 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
996 ;; Perhaps we shouldn't hide to the end of the buffer
997 ;; if there is no end to the signature?
999 ;; Hide "- " PGP quotation markers.
1001 (narrow-to-region beg end)
1002 (goto-char (point-min))
1003 (while (re-search-forward "^- " nil t)
1005 (match-beginning 0) (match-end 0)))
1007 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1009 (defun article-hide-pem (&optional arg)
1010 "Toggle hiding of any PEM headers and signatures in the current article.
1011 If given a negative prefix, always show; if given a positive prefix,
1013 (interactive (gnus-article-hidden-arg))
1014 (unless (gnus-article-check-hidden-text 'pem arg)
1016 (let (buffer-read-only end)
1018 (goto-char (point-min))
1019 ;; hide the horrendously ugly "header".
1020 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1023 (setq end (1+ (match-beginning 0)))
1024 (gnus-article-hide-text-type
1026 (if (search-forward "\n\n" nil t)
1030 ;; hide the trailer as well
1031 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1034 (gnus-article-hide-text-type
1035 (match-beginning 0) (match-end 0) 'pem))))))
1037 (defun article-hide-signature (&optional arg)
1038 "Hide the signature in the current article.
1039 If given a negative prefix, always show; if given a positive prefix,
1041 (interactive (gnus-article-hidden-arg))
1042 (unless (gnus-article-check-hidden-text 'signature arg)
1045 (let ((buffer-read-only nil))
1046 (when (gnus-article-narrow-to-signature)
1047 (gnus-article-hide-text-type
1048 (point-min) (point-max) 'signature)))))))
1050 (defun article-strip-leading-blank-lines ()
1051 "Remove all blank lines from the beginning of the article."
1054 (let ((inhibit-point-motion-hooks t)
1056 (goto-char (point-min))
1057 (when (search-forward "\n\n" nil t)
1058 (while (and (not (eobp))
1059 (looking-at "[ \t]*$"))
1060 (gnus-delete-line))))))
1062 (defun article-strip-multiple-blank-lines ()
1063 "Replace consecutive blank lines with one empty line."
1066 (let ((inhibit-point-motion-hooks t)
1068 ;; First make all blank lines empty.
1069 (goto-char (point-min))
1070 (search-forward "\n\n" nil t)
1071 (while (re-search-forward "^[ \t]+$" nil t)
1072 (replace-match "" nil t))
1073 ;; Then replace multiple empty lines with a single empty line.
1074 (goto-char (point-min))
1075 (search-forward "\n\n" nil t)
1076 (while (re-search-forward "\n\n\n+" nil t)
1077 (replace-match "\n\n" t t)))))
1079 (defun article-strip-leading-space ()
1080 "Remove all white space from the beginning of the lines in the article."
1083 (let ((inhibit-point-motion-hooks t)
1085 (goto-char (point-min))
1086 (search-forward "\n\n" nil t)
1087 (while (re-search-forward "^[ \t]+" nil t)
1088 (replace-match "" t t)))))
1090 (defun article-strip-blank-lines ()
1091 "Strip leading, trailing and multiple blank lines."
1093 (article-strip-leading-blank-lines)
1094 (article-remove-trailing-blank-lines)
1095 (article-strip-multiple-blank-lines))
1097 (defun article-strip-all-blank-lines ()
1098 "Strip all blank lines."
1101 (let ((inhibit-point-motion-hooks t)
1103 (goto-char (point-min))
1104 (search-forward "\n\n" nil t)
1105 (while (re-search-forward "^[ \t]*\n" nil t)
1106 (replace-match "" t t)))))
1108 (defun gnus-article-narrow-to-signature ()
1109 "Narrow to the signature; return t if a signature is found, else nil."
1111 (let ((inhibit-point-motion-hooks t))
1112 (when (gnus-article-search-signature)
1114 ;; Check whether we have some limits to what we consider
1115 ;; to be a signature.
1116 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1117 (list gnus-signature-limit)))
1119 (while (setq limit (pop limits))
1120 (if (or (and (integerp limit)
1121 (< (- (point-max) (point)) limit))
1123 (< (count-lines (point) (point-max)) limit))
1124 (and (gnus-functionp limit)
1126 (and (stringp limit)
1127 (not (re-search-forward limit nil t))))
1128 () ; This limit did not succeed.
1132 (narrow-to-region (point) (point-max))
1135 (defun gnus-article-search-signature ()
1136 "Search the current buffer for the signature separator.
1137 Put point at the beginning of the signature separator."
1138 (let ((cur (point)))
1139 (goto-char (point-max))
1140 (if (if (stringp gnus-signature-separator)
1141 (re-search-backward gnus-signature-separator nil t)
1142 (let ((seps gnus-signature-separator))
1144 (not (re-search-backward (car seps) nil t)))
1152 (autoload 'w3-display "w3-parse")
1153 (autoload 'w3-do-setup "w3" "" t)
1154 (autoload 'w3-region "w3-display" "" t))
1156 (defun gnus-article-treat-html ()
1159 (let ((cbuf (current-buffer)))
1160 (set-buffer gnus-article-buffer)
1161 (let (buf buffer-read-only b e)
1163 (goto-char (point-min))
1165 (if (search-forward "\n\n" nil t)
1168 (setq e (point-max)))
1169 (nnheader-temp-write nil
1170 (insert-buffer-substring gnus-article-buffer b e)
1172 (save-window-excursion
1173 (w3-region (point-min) (point-max))
1174 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1176 (delete-region (point-min) (point-max))
1179 (goto-char (point-min))
1180 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1181 (set-buffer cbuf))))
1183 (defun gnus-article-hidden-arg ()
1184 "Return the current prefix arg as a number, or 0 if no prefix."
1185 (list (if current-prefix-arg
1186 (prefix-numeric-value current-prefix-arg)
1189 (defun gnus-article-check-hidden-text (type arg)
1190 "Return nil if hiding is necessary.
1191 Arg can be nil or a number. Nil and positive means hide, negative
1192 means show, 0 means toggle."
1196 (let ((hide (gnus-article-hidden-text-p type)))
1202 (gnus-article-show-hidden-text type))
1204 (if (eq hide 'hidden)
1205 (gnus-article-show-hidden-text type)
1208 (defun gnus-article-hidden-text-p (type)
1209 "Say whether the current buffer contains hidden text of type TYPE."
1210 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1212 (not (get-text-property pos 'invisible)))
1214 (text-property-any (1+ pos) (point-max) 'article-type type)))
1219 (defun gnus-article-show-hidden-text (type &optional hide)
1220 "Show all hidden text of type TYPE.
1221 If HIDE, hide the text instead."
1223 (let ((buffer-read-only nil)
1224 (inhibit-point-motion-hooks t)
1227 (while (setq beg (text-property-any end (point-max) 'article-type type))
1230 (text-property-not-all beg (point-max) 'article-type type)
1233 (gnus-article-hide-text beg end gnus-hidden-properties)
1234 (gnus-article-unhide-text beg end))
1238 (defconst article-time-units
1239 `((year . ,(* 365.25 24 60 60))
1240 (week . ,(* 7 24 60 60))
1241 (day . ,(* 24 60 60))
1245 "Mapping from time units to seconds.")
1247 (defun article-date-ut (&optional type highlight header)
1248 "Convert DATE date to universal time in the current article.
1249 If TYPE is `local', convert to local time; if it is `lapsed', output
1250 how much time has lapsed since DATE."
1251 (interactive (list 'ut t))
1252 (let* ((header (or header
1253 (mail-header-date gnus-current-headers)
1254 (message-fetch-field "date")
1256 (date (if (vectorp header) (mail-header-date header)
1258 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1259 (inhibit-point-motion-hooks t)
1260 bface eface newline)
1261 (when (and date (not (string= date "")))
1264 (nnheader-narrow-to-headers)
1265 (let ((buffer-read-only nil))
1266 ;; Delete any old Date headers.
1267 (if (re-search-forward date-regexp nil t)
1269 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1270 eface (get-text-property (1- (gnus-point-at-eol))
1272 (delete-region (progn (beginning-of-line) (point))
1273 (progn (end-of-line) (point)))
1274 (beginning-of-line))
1275 (goto-char (point-max))
1277 (insert (article-make-date-line date type))
1280 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1281 (put-text-property (match-beginning 1) (1+ (match-end 1))
1283 (put-text-property (match-beginning 2) (match-end 2)
1287 (insert "\n"))))))))
1289 (defun article-make-date-line (date type)
1290 "Return a DATE line of TYPE."
1292 ;; Convert to the local timezone. We have to slap a
1293 ;; `condition-case' round the calls to the timezone
1294 ;; functions since they aren't particularly resistant to
1297 (concat "Date: " (condition-case ()
1298 (timezone-make-date-arpa-standard date)
1300 ;; Convert to Universal Time.
1304 (timezone-make-date-arpa-standard date nil "UT")
1306 ;; Get the original date from the article.
1307 ((eq type 'original)
1308 (concat "Date: " date))
1309 ;; Let the user define the format.
1311 (if (gnus-functionp gnus-article-time-format)
1313 gnus-article-time-format
1316 (timezone-make-date-arpa-standard
1320 (format-time-string gnus-article-time-format
1323 (timezone-make-date-arpa-standard
1324 date nil "UT")))))))
1329 (format-time-string "%Y%M%DT%h%m%s"
1332 (timezone-make-date-arpa-standard
1334 ;; Do an X-Sent lapsed format.
1336 ;; If the date is seriously mangled, the timezone functions are
1337 ;; liable to bug out, so we ignore all errors.
1338 (let* ((now (current-time))
1343 (timezone-make-date-arpa-standard
1344 (current-time-string now)
1345 (current-time-zone now) "UT"))
1347 (timezone-make-date-arpa-standard
1349 (real-sec (and real-time
1350 (+ (* (float (car real-time)) 65536)
1352 (sec (and real-time (abs real-sec)))
1362 ;; This is a bit convoluted, but basically we go
1363 ;; through the time units for years, weeks, etc,
1364 ;; and divide things to see whether that results
1365 ;; in positive answers.
1368 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1369 ;; The (remaining) seconds are too few to
1370 ;; be divided into this time unit.
1372 ;; It's big enough, so we output it.
1373 (setq sec (- sec (* num (cdr unit))))
1375 (concat (if prev ", " "") (int-to-string
1377 " " (symbol-name (car unit))
1378 (if (> num 1) "s" ""))
1380 article-time-units "")
1381 ;; If dates are odd, then it might appear like the
1382 ;; article was sent in the future.
1385 " in the future"))))))
1387 (error "Unknown conversion type: %s" type))))
1389 (defun article-date-local (&optional highlight)
1390 "Convert the current article date to the local timezone."
1391 (interactive (list t))
1392 (article-date-ut 'local highlight))
1394 (defun article-date-original (&optional highlight)
1395 "Convert the current article date to what it was originally.
1396 This is only useful if you have used some other date conversion
1397 function and want to see what the date was before converting."
1398 (interactive (list t))
1399 (article-date-ut 'original highlight))
1401 (defun article-date-lapsed (&optional highlight)
1402 "Convert the current article date to time lapsed since it was sent."
1403 (interactive (list t))
1404 (article-date-ut 'lapsed highlight))
1406 (defun article-update-date-lapsed ()
1407 "Function to be run from a timer to update the lapsed time line."
1408 (let (deactivate-mark)
1411 (when (gnus-buffer-live-p gnus-article-buffer)
1412 (set-buffer gnus-article-buffer)
1413 (goto-char (point-min))
1414 (when (re-search-forward "^X-Sent:" nil t)
1415 (article-date-lapsed t)))))))
1417 (defun gnus-start-date-timer (&optional n)
1418 "Start a timer to update the X-Sent header in the article buffers.
1419 The numerical prefix says how frequently (in seconds) the function
1424 (gnus-stop-date-timer)
1425 (setq article-lapsed-timer
1426 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1428 (defun gnus-stop-date-timer ()
1429 "Stop the X-Sent timer."
1431 (when article-lapsed-timer
1432 (nnheader-cancel-timer article-lapsed-timer)
1433 (setq article-lapsed-timer nil)))
1435 (defun article-date-user (&optional highlight)
1436 "Convert the current article date to the user-defined format.
1437 This format is defined by the `gnus-article-time-format' variable."
1438 (interactive (list t))
1439 (article-date-ut 'user highlight))
1441 (defun article-date-iso8601 (&optional highlight)
1442 "Convert the current article date to ISO8601."
1443 (interactive (list t))
1444 (article-date-ut 'iso8601 highlight))
1446 (defun article-show-all ()
1447 "Show all hidden text in the article buffer."
1450 (let ((buffer-read-only nil))
1451 (gnus-article-unhide-text (point-min) (point-max)))))
1453 (defun article-emphasize (&optional arg)
1454 "Emphasize text according to `gnus-emphasis-alist'."
1455 (interactive (gnus-article-hidden-arg))
1456 (unless (gnus-article-check-hidden-text 'emphasis arg)
1458 (let ((alist gnus-emphasis-alist)
1459 (buffer-read-only nil)
1460 (props (append '(article-type emphasis)
1461 gnus-hidden-properties))
1462 regexp elem beg invisible visible face)
1463 (goto-char (point-min))
1464 (search-forward "\n\n" nil t)
1466 (while (setq elem (pop alist))
1468 (setq regexp (car elem)
1469 invisible (nth 1 elem)
1470 visible (nth 2 elem)
1472 (while (re-search-forward regexp nil t)
1473 (when (and (match-beginning visible) (match-beginning invisible))
1474 (gnus-article-hide-text
1475 (match-beginning invisible) (match-end invisible) props)
1476 (gnus-article-unhide-text-type
1477 (match-beginning visible) (match-end visible) 'emphasis)
1478 (gnus-put-text-property-excluding-newlines
1479 (match-beginning visible) (match-end visible) 'face face)
1480 (goto-char (match-end invisible)))))))))
1482 (defvar gnus-summary-article-menu)
1483 (defvar gnus-summary-post-menu)
1485 ;;; Saving functions.
1487 (defun gnus-article-save (save-buffer file &optional num)
1488 "Save the currently selected article."
1489 (unless gnus-save-all-headers
1490 ;; Remove headers according to `gnus-saved-headers'.
1491 (let ((gnus-visible-headers
1492 (or gnus-saved-headers gnus-visible-headers))
1493 (gnus-article-buffer save-buffer))
1495 (set-buffer save-buffer)
1496 (article-hide-headers 1 t))))
1497 (save-window-excursion
1498 (if (not gnus-default-article-saver)
1499 (error "No default saver is defined")
1500 ;; !!! Magic! The saving functions all save
1501 ;; `gnus-original-article-buffer' (or so they think), but we
1502 ;; bind that variable to our save-buffer.
1503 (set-buffer gnus-article-buffer)
1504 (let* ((gnus-save-article-buffer save-buffer)
1507 ((not gnus-prompt-before-saving) 'default)
1508 ((eq gnus-prompt-before-saving 'always) nil)
1510 (gnus-number-of-articles-to-be-saved
1511 (when (eq gnus-prompt-before-saving t)
1513 (set-buffer gnus-article-current-summary)
1514 (funcall gnus-default-article-saver filename)))))
1516 (defun gnus-read-save-file-name (prompt &optional filename
1517 function group headers variable)
1519 (funcall function group headers (symbol-value variable)))
1524 ((eq filename 'default)
1530 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1533 (if (and gnus-number-of-articles-to-be-saved
1534 (> gnus-number-of-articles-to-be-saved 1))
1535 (format "these %d articles"
1536 gnus-number-of-articles-to-be-saved)
1539 ;; Let the split methods have their say.
1541 ;; No split name was found.
1544 (concat prompt " (default "
1545 (file-name-nondirectory default-name) ") ")
1546 (file-name-directory default-name)
1548 ;; A single group name is returned.
1549 ((stringp split-name)
1551 (funcall function split-name headers
1552 (symbol-value variable)))
1554 (concat prompt " (default "
1555 (file-name-nondirectory default-name) ") ")
1556 (file-name-directory default-name)
1558 ;; A single split name was found
1559 ((= 1 (length split-name))
1560 (let* ((name (expand-file-name
1561 (car split-name) gnus-article-save-directory))
1562 (dir (cond ((file-directory-p name)
1563 (file-name-as-directory name))
1564 ((file-exists-p name) name)
1565 (t gnus-article-save-directory))))
1567 (concat prompt " (default " name ") ")
1569 ;; A list of splits was found.
1571 (setq split-name (nreverse split-name))
1573 (let ((file-name-history
1574 (nconc split-name file-name-history)))
1578 (concat prompt " (`M-p' for defaults) ")
1579 gnus-article-save-directory
1581 gnus-article-save-directory)))
1582 (car (push result file-name-history)))))))
1583 ;; Create the directory.
1584 (gnus-make-directory (file-name-directory file))
1585 ;; If we have read a directory, we append the default file name.
1586 (when (file-directory-p file)
1587 (setq file (concat (file-name-as-directory file)
1588 (file-name-nondirectory default-name))))
1589 ;; Possibly translate some characters.
1590 (nnheader-translate-file-chars file)))))
1591 (gnus-make-directory (file-name-directory result))
1592 (set variable result)))
1594 (defun gnus-article-archive-name (group)
1595 "Return the first instance of an \"Archive-name\" in the current buffer."
1596 (let ((case-fold-search t))
1597 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1598 (nnheader-concat gnus-article-save-directory
1599 (match-string 1)))))
1601 (defun gnus-article-nndoc-name (group)
1602 "If GROUP is an nndoc group, return the name of the parent group."
1603 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1604 (gnus-group-get-parameter group 'save-article-group)))
1606 (defun gnus-summary-save-in-rmail (&optional filename)
1607 "Append this article to Rmail file.
1608 Optional argument FILENAME specifies file name.
1609 Directory to save to is default to `gnus-article-save-directory'."
1610 (setq filename (gnus-read-save-file-name
1611 "Save %s in rmail file:" filename
1612 gnus-rmail-save-name gnus-newsgroup-name
1613 gnus-current-headers 'gnus-newsgroup-last-rmail))
1614 (gnus-eval-in-buffer-window gnus-save-article-buffer
1618 (gnus-output-to-rmail filename))))
1621 (defun gnus-summary-save-in-mail (&optional filename)
1622 "Append this article to Unix mail file.
1623 Optional argument FILENAME specifies file name.
1624 Directory to save to is default to `gnus-article-save-directory'."
1625 (setq filename (gnus-read-save-file-name
1626 "Save %s in Unix mail file:" filename
1627 gnus-mail-save-name gnus-newsgroup-name
1628 gnus-current-headers 'gnus-newsgroup-last-mail))
1629 (gnus-eval-in-buffer-window gnus-save-article-buffer
1633 (if (and (file-readable-p filename)
1634 (mail-file-babyl-p filename))
1635 (gnus-output-to-rmail filename t)
1636 (gnus-output-to-mail filename)))))
1639 (defun gnus-summary-save-in-file (&optional filename overwrite)
1640 "Append this article to file.
1641 Optional argument FILENAME specifies file name.
1642 Directory to save to is default to `gnus-article-save-directory'."
1643 (setq filename (gnus-read-save-file-name
1644 "Save %s in file:" filename
1645 gnus-file-save-name gnus-newsgroup-name
1646 gnus-current-headers 'gnus-newsgroup-last-file))
1647 (gnus-eval-in-buffer-window gnus-save-article-buffer
1651 (when (and overwrite
1652 (file-exists-p filename))
1653 (delete-file filename))
1654 (gnus-output-to-file filename))))
1657 (defun gnus-summary-write-to-file (&optional filename)
1658 "Write this article to a file.
1659 Optional argument FILENAME specifies file name.
1660 The directory to save in defaults to `gnus-article-save-directory'."
1661 (gnus-summary-save-in-file nil t))
1663 (defun gnus-summary-save-body-in-file (&optional filename)
1664 "Append this article body to a file.
1665 Optional argument FILENAME specifies file name.
1666 The directory to save in defaults to `gnus-article-save-directory'."
1667 (setq filename (gnus-read-save-file-name
1668 "Save %s body in file:" filename
1669 gnus-file-save-name gnus-newsgroup-name
1670 gnus-current-headers 'gnus-newsgroup-last-file))
1671 (gnus-eval-in-buffer-window gnus-save-article-buffer
1675 (goto-char (point-min))
1676 (when (search-forward "\n\n" nil t)
1677 (narrow-to-region (point) (point-max)))
1678 (gnus-output-to-file filename))))
1681 (defun gnus-summary-save-in-pipe (&optional command)
1682 "Pipe this article to subprocess."
1684 (cond ((eq command 'default)
1685 gnus-last-shell-command)
1689 "Shell command on %s: "
1690 (if (and gnus-number-of-articles-to-be-saved
1691 (> gnus-number-of-articles-to-be-saved 1))
1692 (format "these %d articles"
1693 gnus-number-of-articles-to-be-saved)
1695 gnus-last-shell-command))))
1696 (when (string-equal command "")
1697 (setq command gnus-last-shell-command))
1698 (gnus-eval-in-buffer-window gnus-article-buffer
1701 (shell-command-on-region (point-min) (point-max) command nil)))
1702 (setq gnus-last-shell-command command))
1704 ;;; Article file names when saving.
1706 (defun gnus-capitalize-newsgroup (newsgroup)
1707 "Capitalize NEWSGROUP name."
1708 (when (not (zerop (length newsgroup)))
1709 (concat (char-to-string (upcase (aref newsgroup 0)))
1710 (substring newsgroup 1))))
1712 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1713 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1714 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1715 Otherwise, it is like ~/News/news/group/num."
1718 (concat (if (gnus-use-long-file-name 'not-save)
1719 (gnus-capitalize-newsgroup newsgroup)
1720 (gnus-newsgroup-directory-form newsgroup))
1721 "/" (int-to-string (mail-header-number headers)))
1722 gnus-article-save-directory)))
1724 (string-equal (file-name-directory default)
1725 (file-name-directory last-file))
1726 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1728 (or last-file default))))
1730 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1731 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1732 If variable `gnus-use-long-file-name' is non-nil, it is
1733 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1736 (concat (if (gnus-use-long-file-name 'not-save)
1738 (gnus-newsgroup-directory-form newsgroup))
1739 "/" (int-to-string (mail-header-number headers)))
1740 gnus-article-save-directory)))
1742 (string-equal (file-name-directory default)
1743 (file-name-directory last-file))
1744 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1746 (or last-file default))))
1748 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1749 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1750 If variable `gnus-use-long-file-name' is non-nil, it is
1751 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1754 (if (gnus-use-long-file-name 'not-save)
1755 (gnus-capitalize-newsgroup newsgroup)
1756 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1757 gnus-article-save-directory)))
1759 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1760 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1761 If variable `gnus-use-long-file-name' is non-nil, it is
1762 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1765 (if (gnus-use-long-file-name 'not-save)
1767 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1768 gnus-article-save-directory)))
1775 (setq afunc (car func)
1778 gfunc (intern (format "gnus-%s" func))))
1780 (if (not (fboundp afunc))
1782 `(lambda (&optional interactive &rest args)
1783 ,(documentation afunc t)
1784 (interactive (list t))
1786 (set-buffer gnus-article-buffer)
1788 (call-interactively ',afunc)
1789 (apply ',afunc args))))))))
1790 '(article-hide-headers
1791 article-hide-boring-headers
1792 article-treat-overstrike
1793 (article-fill . gnus-article-word-wrap)
1795 article-display-x-face
1798 article-hide-signature
1799 article-remove-trailing-blank-lines
1800 article-strip-leading-blank-lines
1801 article-strip-multiple-blank-lines
1802 article-strip-leading-space
1803 article-strip-blank-lines
1804 article-strip-all-blank-lines
1806 article-date-iso8601
1807 article-date-original
1812 article-treat-dumbquotes
1813 (article-show-all . gnus-article-show-all-headers))))
1816 ;;; Gnus article mode
1819 (put 'gnus-article-mode 'mode-class 'special)
1821 (gnus-define-keys gnus-article-mode-map
1822 " " gnus-article-goto-next-page
1823 "\177" gnus-article-goto-prev-page
1824 [delete] gnus-article-goto-prev-page
1825 "\C-c^" gnus-article-refer-article
1826 "h" gnus-article-show-summary
1827 "s" gnus-article-show-summary
1828 "\C-c\C-m" gnus-article-mail
1829 "?" gnus-article-describe-briefly
1830 gnus-mouse-2 gnus-article-push-button
1831 "\r" gnus-article-press-button
1832 "\t" gnus-article-next-button
1833 "\M-\t" gnus-article-prev-button
1834 "e" gnus-article-edit
1835 "<" beginning-of-buffer
1837 "\C-c\C-i" gnus-info-find-node
1840 "\C-d" gnus-article-read-summary-keys
1841 "\M-*" gnus-article-read-summary-keys
1842 "\M-#" gnus-article-read-summary-keys
1843 "\M-^" gnus-article-read-summary-keys
1844 "\M-g" gnus-article-read-summary-keys)
1846 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
1849 (unless (lookup-key gnus-article-mode-map key)
1850 (define-key gnus-article-mode-map key
1851 'gnus-article-read-summary-keys)))
1856 (let ((key (car elt)))
1857 (and (> (length key) 0)
1858 (not (eq 'menu-bar (aref key 0)))
1859 (symbolp (lookup-key gnus-summary-mode-map key))
1861 (accessible-keymaps gnus-summary-mode-map))
1865 (push (char-to-string c) keys)
1869 (defun gnus-article-make-menu-bar ()
1870 (gnus-turn-off-edit-menu 'article)
1871 (unless (boundp 'gnus-article-article-menu)
1873 gnus-article-article-menu gnus-article-mode-map ""
1875 ["Scroll forwards" gnus-article-goto-next-page t]
1876 ["Scroll backwards" gnus-article-goto-prev-page t]
1877 ["Show summary" gnus-article-show-summary t]
1878 ["Fetch Message-ID at point" gnus-article-refer-article t]
1879 ["Mail to address at point" gnus-article-mail t]
1880 ["Send a bug report" gnus-bug t]))
1883 gnus-article-treatment-menu gnus-article-mode-map ""
1885 ["Hide headers" gnus-article-hide-headers t]
1886 ["Hide signature" gnus-article-hide-signature t]
1887 ["Hide citation" gnus-article-hide-citation t]
1888 ["Treat overstrike" gnus-article-treat-overstrike t]
1889 ["Remove carriage return" gnus-article-remove-cr t]
1892 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1894 (when (boundp 'gnus-summary-post-menu)
1895 (define-key gnus-article-mode-map [menu-bar post]
1896 (cons "Post" gnus-summary-post-menu)))
1898 (gnus-run-hooks 'gnus-article-menu-hook)))
1900 (defun gnus-article-mode ()
1901 "Major mode for displaying an article.
1903 All normal editing commands are switched off.
1905 The following commands are available in addition to all summary mode
1907 \\<gnus-article-mode-map>
1908 \\[gnus-article-next-page]\t Scroll the article one page forwards
1909 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1910 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1911 \\[gnus-article-show-summary]\t Display the summary buffer
1912 \\[gnus-article-mail]\t Send a reply to the address near point
1913 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1914 \\[gnus-info-find-node]\t Go to the Gnus info node"
1916 (when (gnus-visual-p 'article-menu 'menu)
1917 (gnus-article-make-menu-bar))
1918 (gnus-simplify-mode-line)
1919 (setq mode-name "Article")
1920 (setq major-mode 'gnus-article-mode)
1921 (make-local-variable 'minor-mode-alist)
1922 (unless (assq 'gnus-show-mime minor-mode-alist)
1923 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1924 (use-local-map gnus-article-mode-map)
1925 (gnus-update-format-specifications nil 'article-mode)
1926 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1927 (make-local-variable 'gnus-page-broken)
1928 (make-local-variable 'gnus-button-marker-list)
1929 (make-local-variable 'gnus-article-current-summary)
1930 (gnus-set-default-directory)
1931 (buffer-disable-undo (current-buffer))
1932 (setq buffer-read-only t)
1933 (set-syntax-table gnus-article-mode-syntax-table)
1934 (gnus-run-hooks 'gnus-article-mode-hook))
1936 (defun gnus-article-setup-buffer ()
1937 "Initialize the article buffer."
1938 (let* ((name (if gnus-single-article-buffer "*Article*"
1939 (concat "*Article " gnus-newsgroup-name "*")))
1941 (progn (string-match "\\*Article" name)
1942 (concat " *Original Article"
1943 (substring name (match-end 0))))))
1944 (setq gnus-article-buffer name)
1945 (setq gnus-original-article-buffer original)
1946 ;; This might be a variable local to the summary buffer.
1947 (unless gnus-single-article-buffer
1949 (set-buffer gnus-summary-buffer)
1950 (setq gnus-article-buffer name)
1951 (setq gnus-original-article-buffer original)
1952 (gnus-set-global-variables)))
1953 ;; Init original article buffer.
1955 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1956 (buffer-disable-undo (current-buffer))
1957 (setq major-mode 'gnus-original-article-mode)
1958 (make-local-variable 'gnus-original-article))
1959 (if (get-buffer name)
1962 (buffer-disable-undo (current-buffer))
1963 (setq buffer-read-only t)
1964 (unless (eq major-mode 'gnus-article-mode)
1965 (gnus-article-mode))
1968 (set-buffer (gnus-get-buffer-create name))
1970 (make-local-variable 'gnus-summary-buffer)
1971 (current-buffer)))))
1973 ;; Set article window start at LINE, where LINE is the number of lines
1974 ;; from the head of the article.
1975 (defun gnus-article-set-window-start (&optional line)
1977 (get-buffer-window gnus-article-buffer t)
1979 (set-buffer gnus-article-buffer)
1980 (goto-char (point-min))
1983 (gnus-message 6 "Moved to bookmark")
1984 (search-forward "\n\n" nil t)
1988 ;;; @@ article filters
1991 (defun gnus-article-display-mime-message ()
1992 "Article display method for MIME message."
1993 ;; called from `gnus-original-article-buffer'.
1994 (let (charset all-headers)
1995 (with-current-buffer gnus-summary-buffer
1996 (setq charset default-mime-charset
1997 all-headers gnus-have-all-headers))
1998 (make-local-variable 'default-mime-charset)
1999 (setq default-mime-charset charset)
2000 (with-current-buffer (get-buffer-create gnus-article-buffer)
2001 (make-local-variable 'default-mime-charset)
2002 (setq default-mime-charset charset))
2003 (mime-display-message mime-message-structure
2004 gnus-article-buffer nil gnus-article-mode-map)
2006 (gnus-article-hide-headers nil -1))
2008 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2009 (make-local-variable 'mime-button-mother-dispatcher)
2010 (setq mime-button-mother-dispatcher
2011 (function gnus-article-push-button))
2012 (run-hooks 'gnus-mime-article-prepare-hook))
2014 (defun gnus-article-display-traditional-message ()
2015 "Article display method for traditional message."
2016 (set-buffer gnus-article-buffer)
2017 (let (buffer-read-only)
2019 (insert-buffer-substring gnus-original-article-buffer)))
2021 (defun gnus-article-display-message-with-encoded-word ()
2022 "Article display method for message with encoded-words."
2023 (let ((charset (save-excursion
2024 (set-buffer gnus-summary-buffer)
2025 default-mime-charset)))
2026 (make-local-variable 'default-mime-charset)
2027 (setq default-mime-charset charset)
2028 (gnus-article-display-traditional-message)
2029 (make-local-variable 'default-mime-charset)
2030 (setq default-mime-charset charset)
2031 (let (buffer-read-only)
2032 (mime-decode-header-in-buffer charset)
2033 (goto-char (point-min))
2034 (if (search-forward "\n\n" nil t)
2035 (decode-mime-charset-region (match-end 0) (point-max) charset)))
2036 (mime-maybe-hide-echo-buffer))
2037 (gnus-run-hooks 'gnus-mime-article-prepare-hook))
2039 (defun gnus-article-prepare (article &optional all-headers header)
2040 "Prepare ARTICLE in article mode buffer.
2041 ARTICLE should either be an article number or a Message-ID.
2042 If ARTICLE is an id, HEADER should be the article headers.
2043 If ALL-HEADERS is non-nil, no headers are hidden."
2045 ;; Make sure we start in a summary buffer.
2046 (unless (eq major-mode 'gnus-summary-mode)
2047 (set-buffer gnus-summary-buffer))
2048 (setq gnus-summary-buffer (current-buffer))
2049 (let* ((gnus-article (if header (mail-header-number header) article))
2050 (summary-buffer (current-buffer))
2051 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2052 (group gnus-newsgroup-name)
2055 (gnus-article-setup-buffer)
2056 (set-buffer gnus-original-article-buffer)
2057 ;; Deactivate active regions.
2058 (when (and (boundp 'transient-mark-mode)
2059 transient-mark-mode)
2060 (setq mark-active nil))
2061 (if (not (setq result (let ((buffer-read-only nil))
2062 (gnus-request-article-this-buffer
2064 ;; There is no such article.
2066 (when (and (numberp article)
2067 (not (memq article gnus-newsgroup-sparse)))
2068 (setq gnus-article-current
2069 (cons gnus-newsgroup-name article))
2070 (set-buffer gnus-summary-buffer)
2071 (setq gnus-current-article article)
2072 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2074 (gnus-summary-set-agent-mark article)
2075 (message "Message marked for downloading"))
2076 (gnus-summary-mark-article article gnus-canceled-mark)
2077 (unless (memq article gnus-newsgroup-sparse)
2079 "No such article (may have expired or been canceled)")))))
2080 (if (or (eq result 'pseudo)
2081 (eq result 'nneething))
2084 (set-buffer summary-buffer)
2085 (push article gnus-newsgroup-history)
2086 (setq gnus-last-article gnus-current-article
2087 gnus-current-article 0
2088 gnus-current-headers nil
2089 gnus-article-current nil)
2090 (if (eq result 'nneething)
2091 (gnus-configure-windows 'summary)
2092 (gnus-configure-windows 'article))
2093 (gnus-set-global-variables))
2094 (gnus-set-mode-line 'article))
2095 ;; The result from the `request' was an actual article -
2096 ;; or at least some text that is now displayed in the
2098 (when (and (numberp article)
2099 (not (eq article gnus-current-article)))
2100 ;; Seems like a new article has been selected.
2101 ;; `gnus-current-article' must be an article number.
2103 (set-buffer summary-buffer)
2104 (push article gnus-newsgroup-history)
2105 (setq gnus-last-article gnus-current-article
2106 gnus-current-article article
2107 gnus-current-headers
2108 (gnus-summary-article-header gnus-current-article)
2109 gnus-article-current
2110 (cons gnus-newsgroup-name gnus-current-article))
2111 (unless (vectorp gnus-current-headers)
2112 (setq gnus-current-headers nil))
2113 (gnus-summary-goto-subject gnus-current-article)
2114 (when (gnus-summary-show-thread)
2115 ;; If the summary buffer really was folded, the
2116 ;; previous goto may not actually have gone to
2117 ;; the right article, but the thread root instead.
2119 (gnus-summary-goto-subject gnus-current-article))
2120 (gnus-run-hooks 'gnus-mark-article-hook)
2121 (gnus-set-mode-line 'summary)
2122 (when (gnus-visual-p 'article-highlight 'highlight)
2123 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2124 ;; Set the global newsgroup variables here.
2125 ;; Suggested by Jim Sisolak
2126 ;; <sisolak@trans4.neep.wisc.edu>.
2127 (gnus-set-global-variables)
2128 (setq gnus-have-all-headers
2129 (or all-headers gnus-show-all-headers))))
2130 (when (or (numberp article)
2132 ;; Hooks for getting information from the article.
2133 ;; This hook must be called before being narrowed.
2137 (setq mime-message-structure gnus-current-headers)
2138 (mime-buffer-entity-set-buffer-internal
2139 mime-message-structure
2140 gnus-original-article-buffer)
2141 (mime-entity-set-representation-type-internal
2142 mime-message-structure 'mime-buffer-entity)
2143 (luna-send mime-message-structure
2144 'initialize-instance
2145 mime-message-structure)
2146 (if (or (not gnus-strict-mime)
2147 (mime-fetch-field "MIME-Version"))
2148 gnus-article-display-method-for-mime
2149 gnus-article-display-method-for-encoded-word))
2150 gnus-article-display-method-for-traditional)))
2151 (gnus-run-hooks 'gnus-tmp-internal-hook)
2152 (gnus-run-hooks 'gnus-article-prepare-hook)
2155 ;; Associate this article with the current summary buffer.
2156 (setq gnus-article-current-summary summary-buffer)
2157 ;; Perform the article display hooks.
2158 (gnus-run-hooks 'gnus-article-display-hook))
2160 (goto-char (point-min))
2161 (setq gnus-page-broken
2162 (when gnus-break-pages
2163 (gnus-narrow-to-page)
2165 (gnus-set-mode-line 'article)
2166 (gnus-configure-windows 'article)
2167 (goto-char (point-min))
2168 (search-forward "\n\n" nil t)
2169 (set-window-point (get-buffer-window (current-buffer)) (point))
2172 (defun gnus-article-wash-status ()
2173 "Return a string which display status of article washing."
2175 (set-buffer gnus-article-buffer)
2176 (let ((cite (gnus-article-hidden-text-p 'cite))
2177 (headers (gnus-article-hidden-text-p 'headers))
2178 (boring (gnus-article-hidden-text-p 'boring-headers))
2179 (pgp (gnus-article-hidden-text-p 'pgp))
2180 (pem (gnus-article-hidden-text-p 'pem))
2181 (signature (gnus-article-hidden-text-p 'signature))
2182 (overstrike (gnus-article-hidden-text-p 'overstrike))
2183 (emphasis (gnus-article-hidden-text-p 'emphasis))
2184 (mime gnus-show-mime))
2185 (format "%c%c%c%c%c%c%c"
2187 (if (or headers boring) ?h ? )
2188 (if (or pgp pem) ?p ? )
2189 (if signature ?s ? )
2190 (if overstrike ?o ? )
2192 (if emphasis ?e ? )))))
2194 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2196 (defun gnus-article-maybe-hide-headers ()
2197 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2198 Provided for backwards compatibility."
2199 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2201 (gnus-article-hide-headers)))
2205 (defun gnus-output-to-file (file-name)
2206 "Append the current article to a file named FILE-NAME."
2207 (let ((artbuf (current-buffer)))
2208 (nnheader-temp-write nil
2209 (insert-buffer-substring artbuf)
2210 ;; Append newline at end of the buffer as separator, and then
2212 (goto-char (point-max))
2214 (append-to-file (point-min) (point-max) file-name)
2217 (defun gnus-narrow-to-page (&optional arg)
2218 "Narrow the article buffer to a page.
2219 If given a numerical ARG, move forward ARG pages."
2221 (setq arg (if arg (prefix-numeric-value arg) 0))
2223 (set-buffer gnus-article-buffer)
2224 (goto-char (point-min))
2226 ;; Remove any old next/prev buttons.
2227 (when (gnus-visual-p 'page-marker)
2228 (let ((buffer-read-only nil))
2229 (gnus-remove-text-with-property 'gnus-prev)
2230 (gnus-remove-text-with-property 'gnus-next)))
2233 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2235 (re-search-forward page-delimiter nil 'move arg)))
2236 (goto-char (match-end 0)))
2239 (if (re-search-forward page-delimiter nil 'move)
2242 (when (and (gnus-visual-p 'page-marker)
2243 (not (= (point-min) 1)))
2245 (goto-char (point-min))
2246 (gnus-insert-prev-page-button)))
2247 (when (and (gnus-visual-p 'page-marker)
2248 (< (+ (point-max) 2) (buffer-size)))
2250 (goto-char (point-max))
2251 (gnus-insert-next-page-button)))))
2253 ;; Article mode commands
2255 (defun gnus-article-goto-next-page ()
2256 "Show the next page of the article."
2258 (when (gnus-article-next-page)
2259 (goto-char (point-min))
2260 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2262 (defun gnus-article-goto-prev-page ()
2263 "Show the next page of the article."
2265 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2266 (gnus-article-prev-page nil)))
2268 (defun gnus-article-next-page (&optional lines)
2269 "Show the next page of the current article.
2270 If end of article, return non-nil. Otherwise return nil.
2271 Argument LINES specifies lines to be scrolled up."
2273 (move-to-window-line -1)
2276 (and (pos-visible-in-window-p) ;Not continuation line.
2278 ;; Nothing in this page.
2279 (if (or (not gnus-page-broken)
2282 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2284 (gnus-narrow-to-page 1) ;Go to next page.
2286 ;; More in this page.
2287 (let ((scroll-in-place nil))
2291 ;; Long lines may cause an end-of-buffer error.
2292 (goto-char (point-max)))))
2293 (move-to-window-line 0)
2296 (defun gnus-article-prev-page (&optional lines)
2297 "Show previous page of current article.
2298 Argument LINES specifies lines to be scrolled down."
2300 (move-to-window-line 0)
2301 (if (and gnus-page-broken
2303 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2305 (gnus-narrow-to-page -1) ;Go to previous page.
2306 (goto-char (point-max))
2308 (let ((scroll-in-place nil))
2312 (beginning-of-buffer
2313 (goto-char (point-min))))
2314 (move-to-window-line 0)))))
2316 (defun gnus-article-refer-article ()
2317 "Read article specified by message-id around point."
2319 (let ((point (point)))
2320 (search-forward ">" nil t) ;Move point to end of "<....>".
2321 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2322 (let ((message-id (match-string 1)))
2324 (set-buffer gnus-summary-buffer)
2325 (gnus-summary-refer-article message-id))
2327 (error "No references around point"))))
2329 (defun gnus-article-show-summary ()
2330 "Reconfigure windows to show summary buffer."
2332 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2333 (error "There is no summary buffer for this article buffer")
2334 (gnus-article-set-globals)
2335 (gnus-configure-windows 'article)
2336 (gnus-summary-goto-subject gnus-current-article)
2337 (gnus-summary-position-point)))
2339 (defun gnus-article-describe-briefly ()
2340 "Describe article mode commands briefly."
2343 (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")))
2345 (defun gnus-article-summary-command ()
2346 "Execute the last keystroke in the summary buffer."
2348 (let ((obuf (current-buffer))
2349 (owin (current-window-configuration))
2351 (switch-to-buffer gnus-article-current-summary 'norecord)
2352 (setq func (lookup-key (current-local-map) (this-command-keys)))
2353 (call-interactively func)
2355 (set-window-configuration owin)
2356 (set-window-point (get-buffer-window (current-buffer)) (point))))
2358 (defun gnus-article-summary-command-nosave ()
2359 "Execute the last keystroke in the summary buffer."
2362 (pop-to-buffer gnus-article-current-summary 'norecord)
2363 (setq func (lookup-key (current-local-map) (this-command-keys)))
2364 (call-interactively func)))
2366 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2367 "Read a summary buffer key sequence and execute it from the article buffer."
2370 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2371 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2372 "=" "^" "\M-^" "|"))
2378 '("n" "Gn" "p" "Gp"))
2381 (set-buffer gnus-article-current-summary)
2382 (let (gnus-pick-mode)
2383 (push (or key last-command-event) unread-command-events)
2384 (setq keys (read-key-sequence nil))))
2387 (if (or (member keys nosaves)
2388 (member keys nosave-but-article)
2389 (member keys nosave-in-article))
2391 (save-window-excursion
2392 (pop-to-buffer gnus-article-current-summary 'norecord)
2393 ;; We disable the pick minor mode commands.
2394 (let (gnus-pick-mode)
2395 (setq func (lookup-key (current-local-map) keys))))
2398 (unless (member keys nosave-in-article)
2399 (set-buffer gnus-article-current-summary))
2400 (call-interactively func)
2401 (setq new-sum-point (point)))
2402 (when (member keys nosave-but-article)
2403 (pop-to-buffer gnus-article-buffer 'norecord)))
2404 ;; These commands should restore window configuration.
2405 (let ((obuf (current-buffer))
2406 (owin (current-window-configuration))
2408 (summary gnus-article-current-summary)
2409 func in-buffer selected)
2410 (if not-restore-window
2411 (pop-to-buffer summary 'norecord)
2412 (switch-to-buffer summary 'norecord))
2413 (setq in-buffer (current-buffer))
2414 ;; We disable the pick minor mode commands.
2415 (if (setq func (let (gnus-pick-mode)
2416 (lookup-key (current-local-map) keys)))
2418 (call-interactively func)
2419 (setq new-sum-point (point)))
2421 (when (eq in-buffer (current-buffer))
2422 (setq selected (gnus-summary-select-article))
2424 (unless not-restore-window
2425 (set-window-configuration owin))
2426 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2427 (set-window-point (get-buffer-window (current-buffer))
2429 (let ((win (get-buffer-window gnus-article-current-summary)))
2431 (set-window-point win new-sum-point))))))))
2433 (defun gnus-article-hide (&optional arg force)
2434 "Hide all the gruft in the current article.
2435 This means that PGP stuff, signatures, cited text and (some)
2436 headers will be hidden.
2437 If given a prefix, show the hidden text instead."
2438 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2439 (gnus-article-hide-headers arg)
2440 (gnus-article-hide-pgp arg)
2441 (gnus-article-hide-citation-maybe arg force)
2442 (gnus-article-hide-signature arg))
2444 (defun gnus-article-maybe-highlight ()
2445 "Do some article highlighting if article highlighting is requested."
2446 (when (gnus-visual-p 'article-highlight 'highlight)
2447 (gnus-article-highlight-some)))
2449 (defun gnus-check-group-server ()
2450 ;; Make sure the connection to the server is alive.
2451 (unless (gnus-server-opened
2452 (gnus-find-method-for-group gnus-newsgroup-name))
2453 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2454 (gnus-request-group gnus-newsgroup-name t)))
2456 (defun gnus-request-article-this-buffer (article group)
2457 "Get an article and insert it into this buffer."
2458 (let (do-update-line sparse-header)
2462 (gnus-kill-all-overlays)
2463 (setq group (or group gnus-newsgroup-name))
2465 ;; Using `gnus-request-article' directly will insert the article into
2466 ;; `nntp-server-buffer' - so we'll save some time by not having to
2467 ;; copy it from the server buffer into the article buffer.
2469 ;; We only request an article by message-id when we do not have the
2470 ;; headers for it, so we'll have to get those.
2471 (when (stringp article)
2472 (let ((gnus-override-method gnus-refer-article-method))
2473 (gnus-read-header article)))
2475 ;; If the article number is negative, that means that this article
2476 ;; doesn't belong in this newsgroup (possibly), so we find its
2477 ;; message-id and request it by id instead of number.
2478 (when (and (numberp article)
2480 (get-buffer gnus-summary-buffer)
2481 (gnus-buffer-exists-p gnus-summary-buffer))
2483 (set-buffer gnus-summary-buffer)
2484 (let ((header (gnus-summary-article-header article)))
2487 ((memq article gnus-newsgroup-sparse)
2488 ;; This is a sparse gap article.
2489 (setq do-update-line article)
2490 (setq article (mail-header-id header))
2491 (let ((gnus-override-method gnus-refer-article-method))
2492 (setq sparse-header (gnus-read-header article)))
2493 (setq gnus-newsgroup-sparse
2494 (delq article gnus-newsgroup-sparse)))
2496 ;; It's a real article.
2497 (setq article (mail-header-id header)))
2499 ;; It is an extracted pseudo-article.
2500 (setq article 'pseudo)
2501 (gnus-request-pseudo-article header))))
2503 (let ((method (gnus-find-method-for-group
2504 gnus-newsgroup-name)))
2505 (when (and (eq (car method) 'nneething)
2508 (file-name-as-directory
2509 (or (cadr (assq 'nneething-address method))
2511 (mail-header-subject header))))
2512 (when (file-directory-p dir)
2513 (setq article 'nneething)
2514 (gnus-group-enter-directory dir))))))))
2517 ;; Refuse to select canceled articles.
2518 ((and (numberp article)
2520 (get-buffer gnus-summary-buffer)
2521 (gnus-buffer-exists-p gnus-summary-buffer)
2522 (eq (cdr (save-excursion
2523 (set-buffer gnus-summary-buffer)
2524 (assq article gnus-newsgroup-reads)))
2525 gnus-canceled-mark))
2527 ;; Check the backlog.
2528 ((and gnus-keep-backlog
2529 (gnus-backlog-request-article group article (current-buffer)))
2531 ;; Check asynchronous pre-fetch.
2532 ((gnus-async-request-fetched-article group article (current-buffer))
2533 (gnus-async-prefetch-next group article gnus-summary-buffer)
2534 (when (and (numberp article) gnus-keep-backlog)
2535 (gnus-backlog-enter-article group article (current-buffer)))
2538 ((and gnus-use-cache
2540 (gnus-cache-request-article article group))
2542 ;; Get the article and put into the article buffer.
2543 ((or (stringp article) (numberp article))
2544 (let ((gnus-override-method
2545 (and (stringp article) gnus-refer-article-method))
2546 (buffer-read-only nil))
2548 (gnus-kill-all-overlays)
2549 (gnus-check-group-server)
2550 (when (gnus-request-article article group (current-buffer))
2551 (when (numberp article)
2552 (gnus-async-prefetch-next group article gnus-summary-buffer)
2553 (when gnus-keep-backlog
2554 (gnus-backlog-enter-article
2555 group article (current-buffer))))
2560 ;; Associate this article with the current summary buffer.
2561 (setq gnus-article-current-summary gnus-summary-buffer)
2563 ;; Take the article from the original article buffer
2564 ;; and place it in the buffer it's supposed to be in.
2565 (when (and (get-buffer gnus-article-buffer)
2566 (equal (buffer-name (current-buffer))
2567 (buffer-name (get-buffer gnus-article-buffer))))
2569 (if (get-buffer gnus-original-article-buffer)
2570 (set-buffer gnus-original-article-buffer)
2571 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2572 (buffer-disable-undo (current-buffer))
2573 (setq major-mode 'gnus-original-article-mode)
2574 (setq buffer-read-only t))
2575 (let (buffer-read-only)
2577 (insert-buffer-substring gnus-article-buffer))
2578 (setq gnus-original-article (cons group article))))
2580 ;; Update sparse articles.
2581 (when (and do-update-line
2582 (or (numberp article)
2584 (let ((buf (current-buffer)))
2585 (set-buffer gnus-summary-buffer)
2586 (gnus-summary-update-article do-update-line sparse-header)
2587 (gnus-summary-goto-subject do-update-line nil t)
2588 (set-window-point (get-buffer-window (current-buffer) t)
2590 (set-buffer buf))))))
2596 (defcustom gnus-article-edit-mode-hook nil
2597 "Hook run in article edit mode buffers."
2598 :group 'gnus-article-various
2601 (defvar gnus-article-edit-done-function nil)
2603 (defvar gnus-article-edit-mode-map nil)
2605 (unless gnus-article-edit-mode-map
2606 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2608 (gnus-define-keys gnus-article-edit-mode-map
2609 "\C-c\C-c" gnus-article-edit-done
2610 "\C-c\C-k" gnus-article-edit-exit)
2612 (gnus-define-keys (gnus-article-edit-wash-map
2613 "\C-c\C-w" gnus-article-edit-mode-map)
2614 "f" gnus-article-edit-full-stops))
2616 (defun gnus-article-edit-mode ()
2617 "Major mode for editing articles.
2618 This is an extended text-mode.
2620 \\{gnus-article-edit-mode-map}"
2622 (setq major-mode 'gnus-article-edit-mode)
2623 (setq mode-name "Article Edit")
2624 (use-local-map gnus-article-edit-mode-map)
2625 (make-local-variable 'gnus-article-edit-done-function)
2626 (make-local-variable 'gnus-prev-winconf)
2627 (setq buffer-read-only nil)
2628 (buffer-enable-undo)
2630 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2632 (defun gnus-article-edit (&optional force)
2633 "Edit the current article.
2634 This will have permanent effect only in mail groups.
2635 If FORCE is non-nil, allow editing of articles even in read-only
2638 (when (and (not force)
2639 (gnus-group-read-only-p))
2640 (error "The current newsgroup does not support article editing"))
2641 (gnus-article-date-original)
2642 (gnus-article-edit-article
2643 `(lambda (no-highlight)
2644 (gnus-summary-edit-article-done
2645 ,(or (mail-header-references gnus-current-headers) "")
2646 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2648 (defun gnus-article-edit-article (exit-func)
2649 "Start editing the contents of the current article buffer."
2650 (let ((winconf (current-window-configuration)))
2651 (set-buffer gnus-article-buffer)
2652 (gnus-article-edit-mode)
2653 (gnus-article-delete-text-of-type 'annotation)
2654 (gnus-set-text-properties (point-min) (point-max) nil)
2655 (gnus-configure-windows 'edit-article)
2656 (setq gnus-article-edit-done-function exit-func)
2657 (setq gnus-prev-winconf winconf)
2658 (gnus-message 6 "C-c C-c to end edits")))
2660 (defun gnus-article-edit-done (&optional arg)
2661 "Update the article edits and exit."
2666 (goto-char (point-min))
2667 (when (search-forward "\n\n" nil 1)
2668 (let ((lines (count-lines (point) (point-max)))
2669 (length (- (point-max) (point)))
2670 (case-fold-search t)
2671 (body (copy-marker (point))))
2672 (goto-char (point-min))
2673 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2674 (delete-region (match-beginning 1) (match-end 1))
2675 (insert (number-to-string length)))
2676 (goto-char (point-min))
2677 (when (re-search-forward
2678 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2679 (delete-region (match-beginning 1) (match-end 1))
2680 (insert (number-to-string length)))
2681 (goto-char (point-min))
2682 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2683 (delete-region (match-beginning 1) (match-end 1))
2684 (insert (number-to-string lines)))))))
2685 (let ((func gnus-article-edit-done-function)
2686 (buf (current-buffer))
2687 (start (window-start)))
2688 (gnus-article-edit-exit)
2691 (let ((buffer-read-only nil))
2692 (funcall func arg)))
2694 (set-window-start (get-buffer-window buf) start)
2695 (set-window-point (get-buffer-window buf) (point))))
2697 (defun gnus-article-edit-exit ()
2698 "Exit the article editing without updating."
2700 ;; We remove all text props from the article buffer.
2701 (let ((buf (format "%s" (buffer-string)))
2702 (curbuf (current-buffer))
2704 (window-start (window-start)))
2707 (let ((winconf gnus-prev-winconf))
2709 ;; The cache and backlog have to be flushed somewhat.
2710 (when gnus-use-cache
2711 (gnus-cache-update-article
2712 (car gnus-article-current) (cdr gnus-article-current)))
2713 (when gnus-keep-backlog
2714 (gnus-backlog-remove-article
2715 (car gnus-article-current) (cdr gnus-article-current)))
2716 ;; Flush original article as well.
2718 (when (get-buffer gnus-original-article-buffer)
2719 (set-buffer gnus-original-article-buffer)
2720 (setq gnus-original-article nil)))
2721 (set-window-configuration winconf)
2722 ;; Tippy-toe some to make sure that point remains where it was.
2723 (let ((buf (current-buffer)))
2725 (set-window-start (get-buffer-window (current-buffer)) window-start)
2727 (set-buffer buf)))))
2729 (defun gnus-article-edit-full-stops ()
2730 "Interactively repair spacing at end of sentences."
2733 (goto-char (point-min))
2734 (search-forward-regexp "^$" nil t)
2735 (let ((case-fold-search nil))
2736 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2739 ;;; Article highlights
2742 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2744 ;;; Internal Variables:
2746 (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\\)"
2747 "Regular expression that matches URLs."
2748 :group 'gnus-article-buttons
2751 (defcustom gnus-button-alist
2752 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2753 gnus-button-message-id 2)
2754 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2755 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2757 gnus-button-fetch-group 4)
2758 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2759 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2760 t gnus-button-message-id 3)
2761 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2762 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2763 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2764 ;; This is how URLs _should_ be embedded in text...
2765 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2767 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2768 "*Alist of regexps matching buttons in article bodies.
2770 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2771 REGEXP: is the string matching text around the button,
2772 BUTTON: is the number of the regexp grouping actually matching the button,
2773 FORM: is a lisp expression which must eval to true for the button to
2775 CALLBACK: is the function to call when the user push this button, and each
2776 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2778 CALLBACK can also be a variable, in that case the value of that
2779 variable it the real callback function."
2780 :group 'gnus-article-buttons
2781 :type '(repeat (list regexp
2782 (integer :tag "Button")
2784 (function :tag "Callback")
2787 (integer :tag "Regexp group")))))
2789 (defcustom gnus-header-button-alist
2790 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2791 0 t gnus-button-message-id 0)
2792 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2793 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2794 0 t gnus-button-mailto 0)
2795 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2796 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2797 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2798 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2799 gnus-button-message-id 3))
2800 "*Alist of headers and regexps to match buttons in article heads.
2802 This alist is very similar to `gnus-button-alist', except that each
2803 alist has an additional HEADER element first in each entry:
2805 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2807 HEADER is a regexp to match a header. For a fuller explanation, see
2808 `gnus-button-alist'."
2809 :group 'gnus-article-buttons
2810 :group 'gnus-article-headers
2811 :type '(repeat (list (regexp :tag "Header")
2813 (integer :tag "Button")
2815 (function :tag "Callback")
2818 (integer :tag "Regexp group")))))
2820 (defvar gnus-button-regexp nil)
2821 (defvar gnus-button-marker-list nil)
2822 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2824 (defvar gnus-button-last nil)
2825 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2829 (defun gnus-article-push-button (event)
2830 "Check text under the mouse pointer for a callback function.
2831 If the text under the mouse pointer has a `gnus-callback' property,
2832 call it with the value of the `gnus-data' text property."
2834 (set-buffer (window-buffer (posn-window (event-start event))))
2835 (let* ((pos (posn-point (event-start event)))
2836 (data (get-text-property pos 'gnus-data))
2837 (fun (get-text-property pos 'gnus-callback)))
2840 (funcall fun data))))
2842 (defun gnus-article-press-button ()
2843 "Check text at point for a callback function.
2844 If the text at point has a `gnus-callback' property,
2845 call it with the value of the `gnus-data' text property."
2847 (let* ((data (get-text-property (point) 'gnus-data))
2848 (fun (get-text-property (point) 'gnus-callback)))
2850 (funcall fun data))))
2852 (defun gnus-article-prev-button (n)
2853 "Move point to N buttons backward.
2854 If N is negative, move forward instead."
2856 (gnus-article-next-button (- n)))
2858 (defun gnus-article-next-button (n)
2859 "Move point to N buttons forward.
2860 If N is negative, move backward instead."
2862 (let ((function (if (< n 0) 'previous-single-property-change
2863 'next-single-property-change))
2864 (inhibit-point-motion-hooks t)
2866 (limit (if (< n 0) (point-min) (point-max))))
2868 (while (and (not (= limit (point)))
2870 ;; Skip past the current button.
2871 (when (get-text-property (point) 'gnus-callback)
2872 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2873 ;; Go to the next (or previous) button.
2874 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2875 ;; Put point at the start of the button.
2876 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2877 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2878 ;; Skip past intangible buttons.
2879 (when (get-text-property (point) 'intangible)
2883 (gnus-message 5 "No more buttons"))
2886 (defun gnus-article-highlight (&optional force)
2887 "Highlight current article.
2888 This function calls `gnus-article-highlight-headers',
2889 `gnus-article-highlight-citation',
2890 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2891 do the highlighting. See the documentation for those functions."
2892 (interactive (list 'force))
2893 (gnus-article-highlight-headers)
2894 (gnus-article-highlight-citation force)
2895 (gnus-article-highlight-signature)
2896 (gnus-article-add-buttons force)
2897 (gnus-article-add-buttons-to-head))
2899 (defun gnus-article-highlight-some (&optional force)
2900 "Highlight current article.
2901 This function calls `gnus-article-highlight-headers',
2902 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2903 do the highlighting. See the documentation for those functions."
2904 (interactive (list 'force))
2905 (gnus-article-highlight-headers)
2906 (gnus-article-highlight-signature)
2907 (gnus-article-add-buttons))
2909 (defun gnus-article-highlight-headers ()
2910 "Highlight article headers as specified by `gnus-header-face-alist'."
2913 (set-buffer gnus-article-buffer)
2915 (let ((alist gnus-header-face-alist)
2916 (buffer-read-only nil)
2917 (case-fold-search t)
2918 (inhibit-point-motion-hooks t)
2919 entry regexp header-face field-face from hpoints fpoints)
2920 (message-narrow-to-head)
2921 (while (setq entry (pop alist))
2922 (goto-char (point-min))
2923 (setq regexp (concat "^\\("
2924 (if (string-equal "" (nth 0 entry))
2928 header-face (nth 1 entry)
2929 field-face (nth 2 entry))
2930 (while (and (re-search-forward regexp nil t)
2934 (unless (search-forward ":" nil t)
2936 (when (and header-face
2937 (not (memq (point) hpoints)))
2938 (push (point) hpoints)
2939 (gnus-put-text-property from (point) 'face header-face))
2940 (when (and field-face
2941 (not (memq (setq from (point)) fpoints)))
2943 (if (re-search-forward "^[^ \t]" nil t)
2945 (goto-char (point-max)))
2946 (gnus-put-text-property from (point) 'face field-face))))))))
2948 (defun gnus-article-highlight-signature ()
2949 "Highlight the signature in an article.
2950 It does this by highlighting everything after
2951 `gnus-signature-separator' using `gnus-signature-face'."
2954 (set-buffer gnus-article-buffer)
2955 (let ((buffer-read-only nil)
2956 (inhibit-point-motion-hooks t))
2958 (when (and gnus-signature-face
2959 (gnus-article-narrow-to-signature))
2960 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2961 'face gnus-signature-face)
2963 (gnus-article-search-signature)
2964 (let ((start (match-beginning 0))
2965 (end (set-marker (make-marker) (1+ (match-end 0)))))
2966 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2969 (defun gnus-button-in-region-p (b e prop)
2970 "Say whether PROP exists in the region."
2971 (text-property-not-all b e prop nil))
2973 (defun gnus-article-add-buttons (&optional force)
2974 "Find external references in the article and make buttons of them.
2975 \"External references\" are things like Message-IDs and URLs, as
2976 specified by `gnus-button-alist'."
2977 (interactive (list 'force))
2979 (set-buffer gnus-article-buffer)
2980 (let ((buffer-read-only nil)
2981 (inhibit-point-motion-hooks t)
2982 (case-fold-search t)
2983 (alist gnus-button-alist)
2985 ;; Remove all old markers.
2987 (while (setq marker (pop gnus-button-marker-list))
2989 (when (setq entry (gnus-button-entry))
2990 (put-text-property (match-beginning (nth 1 entry))
2991 (match-end (nth 1 entry))
2992 'gnus-callback nil))
2993 (set-marker marker nil)))
2994 ;; We skip the headers.
2995 (goto-char (point-min))
2996 (unless (search-forward "\n\n" nil t)
2997 (goto-char (point-max)))
2999 (while (setq entry (pop alist))
3000 (setq regexp (car entry))
3002 (while (re-search-forward regexp nil t)
3003 (let* ((start (and entry (match-beginning (nth 1 entry))))
3004 (end (and entry (match-end (nth 1 entry))))
3005 (from (match-beginning 0)))
3006 (when (and (or (eq t (nth 2 entry))
3007 (eval (nth 2 entry)))
3008 (not (gnus-button-in-region-p
3009 start end 'gnus-callback)))
3010 ;; That optional form returned non-nil, so we add the
3012 (gnus-article-add-button
3013 start end 'gnus-button-push
3014 (car (push (set-marker (make-marker) from)
3015 gnus-button-marker-list))))))))))
3017 ;; Add buttons to the head of an article.
3018 (defun gnus-article-add-buttons-to-head ()
3019 "Add buttons to the head of the article."
3022 (set-buffer gnus-article-buffer)
3023 (let ((buffer-read-only nil)
3024 (inhibit-point-motion-hooks t)
3025 (case-fold-search t)
3026 (alist gnus-header-button-alist)
3028 (nnheader-narrow-to-headers)
3030 ;; Each alist entry.
3031 (setq entry (car alist)
3033 (goto-char (point-min))
3034 (while (re-search-forward (car entry) nil t)
3035 ;; Each header matching the entry.
3036 (setq beg (match-beginning 0))
3037 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3038 (match-beginning 0))
3041 (while (re-search-forward (nth 1 entry) end t)
3042 ;; Each match within a header.
3043 (let* ((entry (cdr entry))
3044 (start (match-beginning (nth 1 entry)))
3045 (end (match-end (nth 1 entry)))
3046 (form (nth 2 entry)))
3047 (goto-char (match-end 0))
3049 (gnus-article-add-button
3050 start end (nth 3 entry)
3051 (buffer-substring (match-beginning (nth 4 entry))
3052 (match-end (nth 4 entry)))))))
3056 ;;; External functions:
3058 (defun gnus-article-add-button (from to fun &optional data)
3059 "Create a button between FROM and TO with callback FUN and data DATA."
3060 (when gnus-article-button-face
3061 (gnus-overlay-put (gnus-make-overlay from to)
3062 'face gnus-article-button-face))
3063 (gnus-add-text-properties
3065 (nconc (and gnus-article-mouse-face
3066 (list gnus-mouse-face-prop gnus-article-mouse-face))
3067 (list 'gnus-callback fun)
3068 (and data (list 'gnus-data data)))))
3070 ;;; Internal functions:
3072 (defun gnus-article-set-globals ()
3074 (set-buffer gnus-summary-buffer)
3075 (gnus-set-global-variables)))
3077 (defun gnus-signature-toggle (end)
3079 (set-buffer gnus-article-buffer)
3080 (let ((buffer-read-only nil)
3081 (inhibit-point-motion-hooks t))
3082 (if (get-text-property end 'invisible)
3083 (gnus-article-unhide-text end (point-max))
3084 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3086 (defun gnus-button-entry ()
3087 ;; Return the first entry in `gnus-button-alist' matching this place.
3088 (let ((alist gnus-button-alist)
3091 (setq entry (pop alist))
3092 (if (looking-at (car entry))
3097 (defun gnus-button-push (marker)
3098 ;; Push button starting at MARKER.
3100 (set-buffer gnus-article-buffer)
3102 (let* ((entry (gnus-button-entry))
3103 (inhibit-point-motion-hooks t)
3105 (args (mapcar (lambda (group)
3106 (let ((string (match-string group)))
3107 (gnus-set-text-properties
3108 0 (length string) nil string)
3115 (fboundp (symbol-value fun)))
3116 (apply (symbol-value fun) args))
3118 (gnus-message 1 "You must define `%S' to use this button"
3119 (cons fun args)))))))
3121 (defun gnus-button-message-id (message-id)
3124 (set-buffer gnus-summary-buffer)
3125 (gnus-summary-refer-article message-id)))
3127 (defun gnus-button-fetch-group (address)
3128 "Fetch GROUP specified by ADDRESS."
3129 (if (not (string-match "[:/]" address))
3130 ;; This is just a simple group url.
3131 (gnus-group-read-ephemeral-group address gnus-select-method)
3132 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3134 (error "Can't parse %s" address)
3135 (gnus-group-read-ephemeral-group
3136 (match-string 4 address)
3137 `(nntp ,(match-string 1 address)
3138 (nntp-address ,(match-string 1 address))
3139 (nntp-port-number ,(if (match-end 3)
3140 (match-string 3 address)
3143 (defun gnus-url-parse-query-string (query &optional downcase)
3144 (let (retval pairs cur key val)
3145 (setq pairs (gnus-split-string query "&"))
3147 (setq cur (car pairs)
3149 (if (not (string-match "=" cur))
3151 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3152 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3154 (setq key (downcase key)))
3155 (setq cur (assoc key retval))
3157 (setcdr cur (cons val (cdr cur)))
3158 (setq retval (cons (list key val) retval)))))
3161 (defun gnus-url-unhex (x)
3168 (defun gnus-url-unhex-string (str &optional allow-newlines)
3169 "Remove %XXX embedded spaces, etc in a url.
3170 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3171 decoding of carriage returns and line feeds in the string, which is normally
3172 forbidden in URL encoding."
3173 (setq str (or str ""))
3175 (case-fold-search t))
3176 (while (string-match "%[0-9a-f][0-9a-f]" str)
3177 (let* ((start (match-beginning 0))
3178 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3180 (gnus-url-unhex (elt str (+ start 2))))))
3182 tmp (substring str 0 start)
3185 (char-to-string code))
3186 ((or (= code ?\n) (= code ?\r))
3188 (t (char-to-string code))))
3189 str (substring str (match-end 0)))))
3190 (setq tmp (concat tmp str))
3193 (defun gnus-url-mailto (url)
3194 ;; Send mail to someone
3195 (when (string-match "mailto:/*\\(.*\\)" url)
3196 (setq url (substring url (match-beginning 1) nil)))
3197 (let (to args subject func)
3198 (if (string-match (regexp-quote "?") url)
3199 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3200 args (gnus-url-parse-query-string
3201 (substring url (match-end 0) nil) t))
3202 (setq to (gnus-url-unhex-string url)))
3203 (setq args (cons (list "to" to) args)
3204 subject (cdr-safe (assoc "subject" args)))
3205 (gnus-setup-message 'reply
3208 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3211 (message-position-on-field (caar args)))
3212 (insert (mapconcat 'identity (cdar args) ", "))
3213 (setq args (cdr args)))
3216 (message-goto-subject)))))
3218 (defun gnus-button-mailto (address)
3220 (set-buffer (gnus-copy-article-buffer))
3221 (gnus-setup-message 'reply
3222 (message-reply address)))
3224 (defun gnus-button-reply (address)
3225 ;; Reply to ADDRESS.
3226 (gnus-setup-message 'reply
3227 (message-reply address)))
3229 (defun gnus-button-url (address)
3231 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3232 (if (listp browse-url-browser-function)
3233 (browse-url address)
3234 (funcall browse-url-browser-function address)))
3236 (defun gnus-button-embedded-url (address)
3238 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3239 (if (listp browse-url-browser-function)
3240 (browse-url (gnus-strip-whitespace address))
3241 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3243 ;;; Next/prev buttons in the article buffer.
3245 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3246 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3248 (defvar gnus-prev-page-map nil)
3249 (unless gnus-prev-page-map
3250 (setq gnus-prev-page-map (make-sparse-keymap))
3251 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3252 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3254 (defun gnus-insert-prev-page-button ()
3255 (let ((buffer-read-only nil))
3257 gnus-prev-page-line-format nil
3258 `(gnus-prev t local-map ,gnus-prev-page-map
3259 gnus-callback gnus-article-button-prev-page
3260 gnus-type annotation))))
3262 (defvar gnus-next-page-map nil)
3263 (unless gnus-next-page-map
3264 (setq gnus-next-page-map (make-keymap))
3265 (suppress-keymap gnus-prev-page-map)
3266 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3267 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3269 (defun gnus-button-next-page ()
3270 "Go to the next page."
3272 (let ((win (selected-window)))
3273 (select-window (get-buffer-window gnus-article-buffer t))
3274 (gnus-article-next-page)
3275 (select-window win)))
3277 (defun gnus-button-prev-page ()
3278 "Go to the prev page."
3280 (let ((win (selected-window)))
3281 (select-window (get-buffer-window gnus-article-buffer t))
3282 (gnus-article-prev-page)
3283 (select-window win)))
3285 (defun gnus-insert-next-page-button ()
3286 (let ((buffer-read-only nil))
3287 (gnus-eval-format gnus-next-page-line-format nil
3289 t local-map ,gnus-next-page-map
3290 gnus-callback gnus-article-button-next-page
3291 gnus-type annotation))))
3293 (defun gnus-article-button-next-page (arg)
3294 "Go to the next page."
3296 (let ((win (selected-window)))
3297 (select-window (get-buffer-window gnus-article-buffer t))
3298 (gnus-article-next-page)
3299 (select-window win)))
3301 (defun gnus-article-button-prev-page (arg)
3302 "Go to the prev page."
3304 (let ((win (selected-window)))
3305 (select-window (get-buffer-window gnus-article-buffer t))
3306 (gnus-article-prev-page)
3307 (select-window win)))
3313 (defun gnus-article-header-presentation-method (entity situation)
3314 (mime-insert-header entity)
3317 (set-alist 'mime-header-presentation-method-alist
3318 'gnus-original-article-mode
3319 #'gnus-article-header-presentation-method)
3321 (defun gnus-mime-preview-quitting-method ()
3323 (gnus-article-show-summary)
3324 (mime-preview-kill-buffer)
3325 (delete-other-windows)
3326 (gnus-article-show-summary)
3327 (gnus-summary-select-article nil t)
3330 (set-alist 'mime-preview-quitting-method-alist
3331 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
3333 (defun gnus-following-method (buf)
3335 (if (gnus-group-find-parameter gnus-newsgroup-name 'newsgroup)
3337 (message-wide-reply))
3338 (message-yank-original)
3340 (goto-char (point-min))
3343 (set-alist 'mime-preview-following-method-alist
3344 'gnus-original-article-mode #'gnus-following-method)
3354 (run-hooks 'gnus-art-load-hook)
3356 ;;; gnus-art.el ends here