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 <morioka@jaist.ac.jp>
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-traditional
395 'gnus-article-display-traditional-message
396 "*Function to display a traditional message.
397 The function is called from the article buffer."
398 :group 'gnus-article-mime
401 (defcustom gnus-page-delimiter "^\^L"
402 "*Regexp describing what to use as article page delimiters.
403 The default value is \"^\^L\", which is a form linefeed at the
404 beginning of a line."
406 :group 'gnus-article-various)
408 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
409 "*The format specification for the article mode line.
410 See `gnus-summary-mode-line-format' for a closer description."
412 :group 'gnus-article-various)
414 (defcustom gnus-article-mode-hook nil
415 "*A hook for Gnus article mode."
417 :group 'gnus-article-various)
419 (defcustom gnus-article-menu-hook nil
420 "*Hook run after the creation of the article mode menu."
422 :group 'gnus-article-various)
424 (defcustom gnus-article-prepare-hook nil
425 "*A hook called after an article has been prepared in the article buffer.
426 If you want to run a special decoding program like nkf, use this hook."
428 :group 'gnus-article-various)
430 (defcustom gnus-article-hide-pgp-hook nil
431 "*A hook called after successfully hiding a PGP signature."
433 :group 'gnus-article-various)
435 (defcustom gnus-article-button-face 'bold
436 "Face used for highlighting buttons in the article buffer.
438 An article button is a piece of text that you can activate by pressing
439 `RET' or `mouse-2' above it."
441 :group 'gnus-article-buttons)
443 (defcustom gnus-article-mouse-face 'highlight
444 "Face used for mouse highlighting in the article buffer.
446 Article buttons will be displayed in this face when the cursor is
449 :group 'gnus-article-buttons)
451 (defcustom gnus-signature-face 'gnus-signature-face
452 "Face used for highlighting a signature in the article buffer.
453 Obsolete; use the face `gnus-signature-face' for customizations instead."
455 :group 'gnus-article-highlight
456 :group 'gnus-article-signature)
458 (defface gnus-signature-face
461 "Face used for highlighting a signature in the article buffer."
462 :group 'gnus-article-highlight
463 :group 'gnus-article-signature)
465 (defface gnus-header-from-face
468 (:foreground "spring green"))
471 (:foreground "red3"))
474 "Face used for displaying from headers."
475 :group 'gnus-article-headers
476 :group 'gnus-article-highlight)
478 (defface gnus-header-subject-face
481 (:foreground "SeaGreen3"))
484 (:foreground "red4"))
486 (:bold t :italic t)))
487 "Face used for displaying subject headers."
488 :group 'gnus-article-headers
489 :group 'gnus-article-highlight)
491 (defface gnus-header-newsgroups-face
494 (:foreground "yellow" :italic t))
497 (:foreground "MidnightBlue" :italic t))
500 "Face used for displaying newsgroups headers."
501 :group 'gnus-article-headers
502 :group 'gnus-article-highlight)
504 (defface gnus-header-name-face
507 (:foreground "SeaGreen"))
510 (:foreground "maroon"))
513 "Face used for displaying header names."
514 :group 'gnus-article-headers
515 :group 'gnus-article-highlight)
517 (defface gnus-header-content-face
520 (:foreground "forest green" :italic t))
523 (:foreground "indianred4" :italic t))
525 (:italic t))) "Face used for displaying header content."
526 :group 'gnus-article-headers
527 :group 'gnus-article-highlight)
529 (defcustom gnus-header-face-alist
530 '(("From" nil gnus-header-from-face)
531 ("Subject" nil gnus-header-subject-face)
532 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
533 ("" gnus-header-name-face gnus-header-content-face))
534 "*Controls highlighting of article header.
536 An alist of the form (HEADER NAME CONTENT).
538 HEADER is a regular expression which should match the name of an
539 header header and NAME and CONTENT are either face names or nil.
541 The name of each header field will be displayed using the face
542 specified by the first element in the list where HEADER match the
543 header name and NAME is non-nil. Similarly, the content will be
544 displayed by the first non-nil matching CONTENT face."
545 :group 'gnus-article-headers
546 :group 'gnus-article-highlight
547 :type '(repeat (list (regexp :tag "Header")
549 (item :tag "skip" nil)
550 (face :value default))
551 (choice :tag "Content"
552 (item :tag "skip" nil)
553 (face :value default)))))
555 ;;; Internal variables
557 (defvar article-lapsed-timer nil)
558 (defvar gnus-article-current-summary nil)
560 (defvar gnus-article-mode-syntax-table
561 (let ((table (copy-syntax-table text-mode-syntax-table)))
562 (modify-syntax-entry ?- "w" table)
563 (modify-syntax-entry ?> ")" table)
564 (modify-syntax-entry ?< "(" table)
566 "Syntax table used in article mode buffers.
567 Initialized from `text-mode-syntax-table.")
569 (defvar gnus-save-article-buffer nil)
571 (defvar gnus-article-mode-line-format-alist
572 (nconc '((?w (gnus-article-wash-status) ?s))
573 gnus-summary-mode-line-format-alist))
575 (defvar gnus-number-of-articles-to-be-saved nil)
577 (defvar gnus-inhibit-hiding nil)
579 (defsubst gnus-article-hide-text (b e props)
580 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
581 (add-text-properties b e props)
582 (when (memq 'intangible props)
584 (max (1- b) (point-min))
585 b 'intangible (cddr (memq 'intangible props)))))
587 (defsubst gnus-article-unhide-text (b e)
588 "Remove hidden text properties from region between B and E."
589 (remove-text-properties b e gnus-hidden-properties)
590 (when (memq 'intangible gnus-hidden-properties)
591 (put-text-property (max (1- b) (point-min))
594 (defun gnus-article-hide-text-type (b e type)
595 "Hide text of TYPE between B and E."
596 (gnus-article-hide-text
597 b e (cons 'article-type (cons type gnus-hidden-properties))))
599 (defun gnus-article-unhide-text-type (b e type)
600 "Unhide text of TYPE between B and E."
601 (remove-text-properties
602 b e (cons 'article-type (cons type gnus-hidden-properties)))
603 (when (memq 'intangible gnus-hidden-properties)
604 (put-text-property (max (1- b) (point-min))
607 (defun gnus-article-hide-text-of-type (type)
608 "Hide text of TYPE in the current buffer."
610 (let ((b (point-min))
612 (while (setq b (text-property-any b e 'article-type type))
613 (add-text-properties b (incf b) gnus-hidden-properties)))))
615 (defun gnus-article-delete-text-of-type (type)
616 "Delete text of TYPE in the current buffer."
618 (let ((b (point-min)))
619 (while (setq b (text-property-any b (point-max) 'article-type type))
621 b (or (text-property-not-all b (point-max) 'article-type type)
624 (defun gnus-article-delete-invisible-text ()
625 "Delete all invisible text in the current buffer."
627 (let ((b (point-min)))
628 (while (setq b (text-property-any b (point-max) 'invisible t))
630 b (or (text-property-not-all b (point-max) 'invisible t)
633 (defun gnus-article-text-type-exists-p (type)
634 "Say whether any text of type TYPE exists in the buffer."
635 (text-property-any (point-min) (point-max) 'article-type type))
637 (defsubst gnus-article-header-rank ()
638 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
639 (let ((list gnus-sorted-header-list)
642 (when (looking-at (car list))
644 (setq list (cdr list))
648 (defun article-hide-headers (&optional arg delete)
649 "Toggle whether to hide unwanted headers and possibly sort them as well.
650 If given a negative prefix, always show; if given a positive prefix,
652 (interactive (gnus-article-hidden-arg))
654 (if (gnus-article-check-hidden-text 'headers arg)
655 ;; Show boring headers as well.
657 (gnus-article-show-hidden-text 'boring-headers)
658 (when (eq 1 (point-min))
659 (set-window-start (get-buffer-window (current-buffer)) 1)))
660 ;; This function might be inhibited.
661 (unless gnus-inhibit-hiding
664 (let ((buffer-read-only nil)
666 (props (nconc (list 'article-type 'headers)
667 gnus-hidden-properties))
668 (max (1+ (length gnus-sorted-header-list)))
669 (ignored (when (not gnus-visible-headers)
670 (cond ((stringp gnus-ignored-headers)
671 gnus-ignored-headers)
672 ((listp gnus-ignored-headers)
673 (mapconcat 'identity gnus-ignored-headers
676 (cond ((stringp gnus-visible-headers)
677 gnus-visible-headers)
678 ((and gnus-visible-headers
679 (listp gnus-visible-headers))
680 (mapconcat 'identity gnus-visible-headers "\\|"))))
681 (inhibit-point-motion-hooks t)
683 ;; First we narrow to just the headers.
685 (goto-char (point-min))
686 ;; Hide any "From " lines at the beginning of (mail) articles.
687 (while (looking-at "From ")
691 (delete-region (point-min) (point))
692 (gnus-article-hide-text (point-min) (point) props)))
693 ;; Then treat the rest of the header lines.
696 (if (search-forward "\n\n" nil t) ; if there's a body
697 (progn (forward-line -1) (point))
699 ;; Then we use the two regular expressions
700 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
701 ;; select which header lines is to remain visible in the
703 (goto-char (point-min))
704 (while (memq (char-after) '(?\t ?\ ))
707 ;; Mark the rank of the header.
709 (point) (1+ (point)) 'message-rank
710 (if (or (and visible (looking-at visible))
712 (not (looking-at ignored))))
713 (gnus-article-header-rank)
716 (while (memq (char-after) '(?\t ?\ ))
718 (message-sort-headers-1)
719 (when (setq beg (text-property-any
720 (point-min) (point-max) 'message-rank (+ 2 max)))
721 ;; We make the unwanted headers invisible.
723 (delete-region beg (point-max))
724 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
725 (gnus-article-hide-text-type beg (point-max) 'headers))
726 ;; Work around XEmacs lossage.
727 (put-text-property (point-min) beg 'invisible nil))))))))
729 (defun article-hide-boring-headers (&optional arg)
730 "Toggle hiding of headers that aren't very interesting.
731 If given a negative prefix, always show; if given a positive prefix,
733 (interactive (gnus-article-hidden-arg))
734 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
735 (not gnus-show-all-headers))
738 (let ((buffer-read-only nil)
739 (list gnus-boring-article-headers)
740 (inhibit-point-motion-hooks t)
742 (nnheader-narrow-to-headers)
744 (setq elem (pop list))
745 (goto-char (point-min))
747 ;; Hide empty headers.
749 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
751 (gnus-article-hide-text-type
754 (while (and (zerop (forward-line 1))
755 (memq (char-after) '(?\t ?\ ))))
758 ;; Hide boring Newsgroups header.
759 ((eq elem 'newsgroups)
760 (when (equal (gnus-fetch-field "newsgroups")
761 (gnus-group-real-name
762 (if (boundp 'gnus-newsgroup-name)
765 (gnus-article-hide-header "newsgroups")))
766 ((eq elem 'followup-to)
767 (when (equal (message-fetch-field "followup-to")
768 (message-fetch-field "newsgroups"))
769 (gnus-article-hide-header "followup-to")))
771 (let ((from (message-fetch-field "from"))
772 (reply-to (message-fetch-field "reply-to")))
777 (nth 1 (funcall gnus-extract-address-components from))
778 (nth 1 (funcall gnus-extract-address-components reply-to)))))
779 (gnus-article-hide-header "reply-to"))))
781 (let ((date (message-fetch-field "date")))
783 (< (gnus-days-between (current-time-string) date)
785 (gnus-article-hide-header "date"))))
787 (let ((to (message-fetch-field "to")))
788 (when (> (length to) 1024)
789 (gnus-article-hide-header "to"))))
792 (goto-char (point-min))
793 (while (re-search-forward "^to:" nil t)
794 (setq to-count (1+ to-count)))
796 (while (> to-count 0)
797 (goto-char (point-min))
799 (re-search-forward "^to:" nil nil to-count)
801 (narrow-to-region (point) (point-max))
802 (gnus-article-hide-header "to"))
803 (setq to-count (1- to-count)))))))))))))
805 (defun gnus-article-hide-header (header)
807 (goto-char (point-min))
808 (when (re-search-forward (concat "^" header ":") nil t)
809 (gnus-article-hide-text-type
810 (progn (beginning-of-line) (point))
812 (while (and (zerop (forward-line 1))
813 (memq (char-after) '(?\t ?\ ))))
817 (defun article-treat-dumbquotes ()
818 "Translate M******** sm*rtq**t*s into proper text."
820 (article-translate-characters "\221\222\223\223" "`'\"\""))
822 (defun article-translate-characters (from to)
823 "Translate all characters in the body of the article according to FROM and TO.
824 FROM is a string of characters to translate from; to is a string of
825 characters to translate to."
827 (goto-char (point-min))
828 (when (search-forward "\n\n" nil t)
829 (let ((buffer-read-only nil)
830 (x (make-string 225 ?x))
832 (while (< (incf i) (length x))
835 (while (< i (length from))
836 (aset x (aref from i) (aref to i))
838 (translate-region (point) (point-max) x)))))
840 (defun article-treat-overstrike ()
841 "Translate overstrikes into bold text."
844 (goto-char (point-min))
845 (when (search-forward "\n\n" nil t)
846 (let ((buffer-read-only nil))
847 (while (search-forward "\b" nil t)
848 (let ((next (char-after))
849 (previous (char-after (- (point) 2))))
850 ;; We do the boldification/underlining by hiding the
851 ;; overstrikes and putting the proper text property
855 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
856 (put-text-property (point) (1+ (point)) 'face 'bold))
858 (gnus-article-hide-text-type
859 (1- (point)) (1+ (point)) 'overstrike)
861 (- (point) 2) (1- (point)) 'face 'underline))
863 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
865 (point) (1+ (point)) 'face 'underline)))))))))
867 (defun article-fill ()
868 "Format too long lines."
871 (let ((buffer-read-only nil))
873 (goto-char (point-min))
874 (search-forward "\n\n" nil t)
876 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
877 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
878 (adaptive-fill-mode t))
880 (and (>= (current-column) (min fill-column (window-width)))
881 (not (eq (preceding-char) ?:))
882 (fill-paragraph nil))
885 (defun article-remove-cr ()
886 "Remove carriage returns from an article."
889 (let ((buffer-read-only nil))
890 (goto-char (point-min))
891 (while (search-forward "\r" nil t)
892 (replace-match "" t t)))))
894 (defun article-remove-trailing-blank-lines ()
895 "Remove all trailing blank lines from the article."
898 (let ((buffer-read-only nil))
899 (goto-char (point-max))
903 (while (and (not (bobp))
904 (looking-at "^[ \t]*$"))
909 (defun article-display-x-face (&optional force)
910 "Look for an X-Face header and display it if present."
911 (interactive (list 'force))
913 ;; Delete the old process, if any.
914 (when (process-status "article-x-face")
915 (delete-process "article-x-face"))
916 (let ((inhibit-point-motion-hooks t)
920 (nnheader-narrow-to-headers)
921 (setq from (message-fetch-field "from"))
922 (goto-char (point-min))
923 (while (and gnus-article-x-face-command
926 ;; Check whether this face is censored.
927 (not gnus-article-x-face-too-ugly)
928 (and gnus-article-x-face-too-ugly from
929 (not (string-match gnus-article-x-face-too-ugly
931 ;; Has to be present.
932 (re-search-forward "^X-Face: " nil t))
933 ;; This used to try to do multiple faces (`while' instead of
934 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
935 ;; work (b) it can crash some versions of Emacs (c) are
936 ;; multiple faces really something to encourage?
937 (when (stringp gnus-article-x-face-command)
939 ;; We now have the area of the buffer where the X-Face is stored.
942 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
943 ;; We display the face.
944 (if (symbolp gnus-article-x-face-command)
945 ;; The command is a lisp function, so we call it.
946 (if (gnus-functionp gnus-article-x-face-command)
947 (funcall gnus-article-x-face-command beg end)
948 (error "%s is not a function" gnus-article-x-face-command))
949 ;; The command is a string, so we interpret the command
950 ;; as a, well, command, and fork it off.
951 (let ((process-connection-type nil))
952 (process-kill-without-query
954 "article-x-face" nil shell-file-name shell-command-switch
955 gnus-article-x-face-command))
956 (process-send-region "article-x-face" beg end)
957 (process-send-eof "article-x-face"))))))))))
959 (defun gnus-article-decode-rfc1522 ()
960 "Decode MIME encoded-words in header fields."
961 (let (buffer-read-only)
962 (let ((charset (save-excursion
963 (set-buffer gnus-summary-buffer)
964 default-mime-charset)))
965 (mime-decode-header-in-buffer charset)
968 (defun article-hide-pgp (&optional arg)
969 "Toggle hiding of any PGP headers and signatures in the current article.
970 If given a negative prefix, always show; if given a positive prefix,
972 (interactive (gnus-article-hidden-arg))
973 (unless (gnus-article-check-hidden-text 'pgp arg)
975 (let ((inhibit-point-motion-hooks t)
976 buffer-read-only beg end)
978 (goto-char (point-min))
979 ;; Hide the "header".
980 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
981 (delete-region (1+ (match-beginning 0)) (match-end 0))
983 ;; Hide the actual signature.
984 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
985 (setq end (1+ (match-beginning 0)))
988 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
990 ;; Perhaps we shouldn't hide to the end of the buffer
991 ;; if there is no end to the signature?
993 ;; Hide "- " PGP quotation markers.
995 (narrow-to-region beg end)
996 (goto-char (point-min))
997 (while (re-search-forward "^- " nil t)
999 (match-beginning 0) (match-end 0)))
1001 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1003 (defun article-hide-pem (&optional arg)
1004 "Toggle hiding of any PEM headers and signatures in the current article.
1005 If given a negative prefix, always show; if given a positive prefix,
1007 (interactive (gnus-article-hidden-arg))
1008 (unless (gnus-article-check-hidden-text 'pem arg)
1010 (let (buffer-read-only end)
1012 (goto-char (point-min))
1013 ;; hide the horrendously ugly "header".
1014 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1017 (setq end (1+ (match-beginning 0)))
1018 (gnus-article-hide-text-type
1020 (if (search-forward "\n\n" nil t)
1024 ;; hide the trailer as well
1025 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1028 (gnus-article-hide-text-type
1029 (match-beginning 0) (match-end 0) 'pem))))))
1031 (defun article-hide-signature (&optional arg)
1032 "Hide the signature in the current article.
1033 If given a negative prefix, always show; if given a positive prefix,
1035 (interactive (gnus-article-hidden-arg))
1036 (unless (gnus-article-check-hidden-text 'signature arg)
1039 (let ((buffer-read-only nil))
1040 (when (gnus-article-narrow-to-signature)
1041 (gnus-article-hide-text-type
1042 (point-min) (point-max) 'signature)))))))
1044 (defun article-strip-leading-blank-lines ()
1045 "Remove all blank lines from the beginning of the article."
1048 (let ((inhibit-point-motion-hooks t)
1050 (goto-char (point-min))
1051 (when (search-forward "\n\n" nil t)
1052 (while (and (not (eobp))
1053 (looking-at "[ \t]*$"))
1054 (gnus-delete-line))))))
1056 (defun article-strip-multiple-blank-lines ()
1057 "Replace consecutive blank lines with one empty line."
1060 (let ((inhibit-point-motion-hooks t)
1062 ;; First make all blank lines empty.
1063 (goto-char (point-min))
1064 (search-forward "\n\n" nil t)
1065 (while (re-search-forward "^[ \t]+$" nil t)
1066 (replace-match "" nil t))
1067 ;; Then replace multiple empty lines with a single empty line.
1068 (goto-char (point-min))
1069 (search-forward "\n\n" nil t)
1070 (while (re-search-forward "\n\n\n+" nil t)
1071 (replace-match "\n\n" t t)))))
1073 (defun article-strip-leading-space ()
1074 "Remove all white space from the beginning of the lines in the article."
1077 (let ((inhibit-point-motion-hooks t)
1079 (goto-char (point-min))
1080 (search-forward "\n\n" nil t)
1081 (while (re-search-forward "^[ \t]+" nil t)
1082 (replace-match "" t t)))))
1084 (defun article-strip-blank-lines ()
1085 "Strip leading, trailing and multiple blank lines."
1087 (article-strip-leading-blank-lines)
1088 (article-remove-trailing-blank-lines)
1089 (article-strip-multiple-blank-lines))
1091 (defun article-strip-all-blank-lines ()
1092 "Strip all blank lines."
1095 (let ((inhibit-point-motion-hooks t)
1097 (goto-char (point-min))
1098 (search-forward "\n\n" nil t)
1099 (while (re-search-forward "^[ \t]*\n" nil t)
1100 (replace-match "" t t)))))
1102 (defun gnus-article-narrow-to-signature ()
1103 "Narrow to the signature; return t if a signature is found, else nil."
1105 (let ((inhibit-point-motion-hooks t))
1106 (when (gnus-article-search-signature)
1108 ;; Check whether we have some limits to what we consider
1109 ;; to be a signature.
1110 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1111 (list gnus-signature-limit)))
1113 (while (setq limit (pop limits))
1114 (if (or (and (integerp limit)
1115 (< (- (point-max) (point)) limit))
1117 (< (count-lines (point) (point-max)) limit))
1118 (and (gnus-functionp limit)
1120 (and (stringp limit)
1121 (not (re-search-forward limit nil t))))
1122 () ; This limit did not succeed.
1126 (narrow-to-region (point) (point-max))
1129 (defun gnus-article-search-signature ()
1130 "Search the current buffer for the signature separator.
1131 Put point at the beginning of the signature separator."
1132 (let ((cur (point)))
1133 (goto-char (point-max))
1134 (if (if (stringp gnus-signature-separator)
1135 (re-search-backward gnus-signature-separator nil t)
1136 (let ((seps gnus-signature-separator))
1138 (not (re-search-backward (car seps) nil t)))
1146 (autoload 'w3-display "w3-parse")
1147 (autoload 'w3-do-setup "w3" "" t)
1148 (autoload 'w3-region "w3-display" "" t))
1150 (defun gnus-article-treat-html ()
1153 (let ((cbuf (current-buffer)))
1154 (set-buffer gnus-article-buffer)
1155 (let (buf buffer-read-only b e)
1157 (goto-char (point-min))
1159 (if (search-forward "\n\n" nil t)
1162 (setq e (point-max)))
1163 (nnheader-temp-write nil
1164 (insert-buffer-substring gnus-article-buffer b e)
1166 (save-window-excursion
1167 (w3-region (point-min) (point-max))
1168 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1170 (delete-region (point-min) (point-max))
1173 (goto-char (point-min))
1174 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1175 (set-buffer cbuf))))
1177 (defun gnus-article-hidden-arg ()
1178 "Return the current prefix arg as a number, or 0 if no prefix."
1179 (list (if current-prefix-arg
1180 (prefix-numeric-value current-prefix-arg)
1183 (defun gnus-article-check-hidden-text (type arg)
1184 "Return nil if hiding is necessary.
1185 Arg can be nil or a number. Nil and positive means hide, negative
1186 means show, 0 means toggle."
1190 (let ((hide (gnus-article-hidden-text-p type)))
1196 (gnus-article-show-hidden-text type))
1198 (if (eq hide 'hidden)
1199 (gnus-article-show-hidden-text type)
1202 (defun gnus-article-hidden-text-p (type)
1203 "Say whether the current buffer contains hidden text of type TYPE."
1204 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1206 (not (get-text-property pos 'invisible)))
1208 (text-property-any (1+ pos) (point-max) 'article-type type)))
1213 (defun gnus-article-show-hidden-text (type &optional hide)
1214 "Show all hidden text of type TYPE.
1215 If HIDE, hide the text instead."
1217 (let ((buffer-read-only nil)
1218 (inhibit-point-motion-hooks t)
1221 (while (setq beg (text-property-any end (point-max) 'article-type type))
1224 (text-property-not-all beg (point-max) 'article-type type)
1227 (gnus-article-hide-text beg end gnus-hidden-properties)
1228 (gnus-article-unhide-text beg end))
1232 (defconst article-time-units
1233 `((year . ,(* 365.25 24 60 60))
1234 (week . ,(* 7 24 60 60))
1235 (day . ,(* 24 60 60))
1239 "Mapping from time units to seconds.")
1241 (defun article-date-ut (&optional type highlight header)
1242 "Convert DATE date to universal time in the current article.
1243 If TYPE is `local', convert to local time; if it is `lapsed', output
1244 how much time has lapsed since DATE."
1245 (interactive (list 'ut t))
1246 (let* ((header (or header
1247 (mail-header-date gnus-current-headers)
1248 (message-fetch-field "date")
1250 (date (if (vectorp header) (mail-header-date header)
1252 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1253 (inhibit-point-motion-hooks t)
1254 bface eface newline)
1255 (when (and date (not (string= date "")))
1258 (nnheader-narrow-to-headers)
1259 (let ((buffer-read-only nil))
1260 ;; Delete any old Date headers.
1261 (if (re-search-forward date-regexp nil t)
1263 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1264 eface (get-text-property (1- (gnus-point-at-eol))
1266 (delete-region (progn (beginning-of-line) (point))
1267 (progn (end-of-line) (point)))
1268 (beginning-of-line))
1269 (goto-char (point-max))
1271 (insert (article-make-date-line date type))
1274 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1275 (put-text-property (match-beginning 1) (1+ (match-end 1))
1277 (put-text-property (match-beginning 2) (match-end 2)
1281 (insert "\n"))))))))
1283 (defun article-make-date-line (date type)
1284 "Return a DATE line of TYPE."
1286 ;; Convert to the local timezone. We have to slap a
1287 ;; `condition-case' round the calls to the timezone
1288 ;; functions since they aren't particularly resistant to
1291 (concat "Date: " (condition-case ()
1292 (timezone-make-date-arpa-standard date)
1294 ;; Convert to Universal Time.
1298 (timezone-make-date-arpa-standard date nil "UT")
1300 ;; Get the original date from the article.
1301 ((eq type 'original)
1302 (concat "Date: " date))
1303 ;; Let the user define the format.
1305 (if (gnus-functionp gnus-article-time-format)
1307 gnus-article-time-format
1310 (timezone-make-date-arpa-standard
1314 (format-time-string gnus-article-time-format
1317 (timezone-make-date-arpa-standard
1318 date nil "UT")))))))
1323 (format-time-string "%Y%M%DT%h%m%s"
1326 (timezone-make-date-arpa-standard
1328 ;; Do an X-Sent lapsed format.
1330 ;; If the date is seriously mangled, the timezone functions are
1331 ;; liable to bug out, so we ignore all errors.
1332 (let* ((now (current-time))
1337 (timezone-make-date-arpa-standard
1338 (current-time-string now)
1339 (current-time-zone now) "UT"))
1341 (timezone-make-date-arpa-standard
1343 (real-sec (and real-time
1344 (+ (* (float (car real-time)) 65536)
1346 (sec (and real-time (abs real-sec)))
1356 ;; This is a bit convoluted, but basically we go
1357 ;; through the time units for years, weeks, etc,
1358 ;; and divide things to see whether that results
1359 ;; in positive answers.
1362 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1363 ;; The (remaining) seconds are too few to
1364 ;; be divided into this time unit.
1366 ;; It's big enough, so we output it.
1367 (setq sec (- sec (* num (cdr unit))))
1369 (concat (if prev ", " "") (int-to-string
1371 " " (symbol-name (car unit))
1372 (if (> num 1) "s" ""))
1374 article-time-units "")
1375 ;; If dates are odd, then it might appear like the
1376 ;; article was sent in the future.
1379 " in the future"))))))
1381 (error "Unknown conversion type: %s" type))))
1383 (defun article-date-local (&optional highlight)
1384 "Convert the current article date to the local timezone."
1385 (interactive (list t))
1386 (article-date-ut 'local highlight))
1388 (defun article-date-original (&optional highlight)
1389 "Convert the current article date to what it was originally.
1390 This is only useful if you have used some other date conversion
1391 function and want to see what the date was before converting."
1392 (interactive (list t))
1393 (article-date-ut 'original highlight))
1395 (defun article-date-lapsed (&optional highlight)
1396 "Convert the current article date to time lapsed since it was sent."
1397 (interactive (list t))
1398 (article-date-ut 'lapsed highlight))
1400 (defun article-update-date-lapsed ()
1401 "Function to be run from a timer to update the lapsed time line."
1402 (let (deactivate-mark)
1405 (when (gnus-buffer-live-p gnus-article-buffer)
1406 (set-buffer gnus-article-buffer)
1407 (goto-char (point-min))
1408 (when (re-search-forward "^X-Sent:" nil t)
1409 (article-date-lapsed t)))))))
1411 (defun gnus-start-date-timer (&optional n)
1412 "Start a timer to update the X-Sent header in the article buffers.
1413 The numerical prefix says how frequently (in seconds) the function
1418 (gnus-stop-date-timer)
1419 (setq article-lapsed-timer
1420 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1422 (defun gnus-stop-date-timer ()
1423 "Stop the X-Sent timer."
1425 (when article-lapsed-timer
1426 (nnheader-cancel-timer article-lapsed-timer)
1427 (setq article-lapsed-timer nil)))
1429 (defun article-date-user (&optional highlight)
1430 "Convert the current article date to the user-defined format.
1431 This format is defined by the `gnus-article-time-format' variable."
1432 (interactive (list t))
1433 (article-date-ut 'user highlight))
1435 (defun article-date-iso8601 (&optional highlight)
1436 "Convert the current article date to ISO8601."
1437 (interactive (list t))
1438 (article-date-ut 'iso8601 highlight))
1440 (defun article-show-all ()
1441 "Show all hidden text in the article buffer."
1444 (let ((buffer-read-only nil))
1445 (gnus-article-unhide-text (point-min) (point-max)))))
1447 (defun article-emphasize (&optional arg)
1448 "Emphasize text according to `gnus-emphasis-alist'."
1449 (interactive (gnus-article-hidden-arg))
1450 (unless (gnus-article-check-hidden-text 'emphasis arg)
1452 (let ((alist gnus-emphasis-alist)
1453 (buffer-read-only nil)
1454 (props (append '(article-type emphasis)
1455 gnus-hidden-properties))
1456 regexp elem beg invisible visible face)
1457 (goto-char (point-min))
1458 (search-forward "\n\n" nil t)
1460 (while (setq elem (pop alist))
1462 (setq regexp (car elem)
1463 invisible (nth 1 elem)
1464 visible (nth 2 elem)
1466 (while (re-search-forward regexp nil t)
1467 (when (and (match-beginning visible) (match-beginning invisible))
1468 (gnus-article-hide-text
1469 (match-beginning invisible) (match-end invisible) props)
1470 (gnus-article-unhide-text-type
1471 (match-beginning visible) (match-end visible) 'emphasis)
1472 (gnus-put-text-property-excluding-newlines
1473 (match-beginning visible) (match-end visible) 'face face)
1474 (goto-char (match-end invisible)))))))))
1476 (defvar gnus-summary-article-menu)
1477 (defvar gnus-summary-post-menu)
1479 ;;; Saving functions.
1481 (defun gnus-article-save (save-buffer file &optional num)
1482 "Save the currently selected article."
1483 (unless gnus-save-all-headers
1484 ;; Remove headers according to `gnus-saved-headers'.
1485 (let ((gnus-visible-headers
1486 (or gnus-saved-headers gnus-visible-headers))
1487 (gnus-article-buffer save-buffer))
1489 (set-buffer save-buffer)
1490 (article-hide-headers 1 t))))
1491 (save-window-excursion
1492 (if (not gnus-default-article-saver)
1493 (error "No default saver is defined")
1494 ;; !!! Magic! The saving functions all save
1495 ;; `gnus-original-article-buffer' (or so they think), but we
1496 ;; bind that variable to our save-buffer.
1497 (set-buffer gnus-article-buffer)
1498 (let* ((gnus-save-article-buffer save-buffer)
1501 ((not gnus-prompt-before-saving) 'default)
1502 ((eq gnus-prompt-before-saving 'always) nil)
1504 (gnus-number-of-articles-to-be-saved
1505 (when (eq gnus-prompt-before-saving t)
1507 (set-buffer gnus-article-current-summary)
1508 (funcall gnus-default-article-saver filename)))))
1510 (defun gnus-read-save-file-name (prompt &optional filename
1511 function group headers variable)
1513 (funcall function group headers (symbol-value variable)))
1518 ((eq filename 'default)
1524 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1527 (if (and gnus-number-of-articles-to-be-saved
1528 (> gnus-number-of-articles-to-be-saved 1))
1529 (format "these %d articles"
1530 gnus-number-of-articles-to-be-saved)
1533 ;; Let the split methods have their say.
1535 ;; No split name was found.
1538 (concat prompt " (default "
1539 (file-name-nondirectory default-name) ") ")
1540 (file-name-directory default-name)
1542 ;; A single group name is returned.
1543 ((stringp split-name)
1545 (funcall function split-name headers
1546 (symbol-value variable)))
1548 (concat prompt " (default "
1549 (file-name-nondirectory default-name) ") ")
1550 (file-name-directory default-name)
1552 ;; A single split name was found
1553 ((= 1 (length split-name))
1554 (let* ((name (expand-file-name
1555 (car split-name) gnus-article-save-directory))
1556 (dir (cond ((file-directory-p name)
1557 (file-name-as-directory name))
1558 ((file-exists-p name) name)
1559 (t gnus-article-save-directory))))
1561 (concat prompt " (default " name ") ")
1563 ;; A list of splits was found.
1565 (setq split-name (nreverse split-name))
1567 (let ((file-name-history
1568 (nconc split-name file-name-history)))
1572 (concat prompt " (`M-p' for defaults) ")
1573 gnus-article-save-directory
1575 gnus-article-save-directory)))
1576 (car (push result file-name-history)))))))
1577 ;; Create the directory.
1578 (gnus-make-directory (file-name-directory file))
1579 ;; If we have read a directory, we append the default file name.
1580 (when (file-directory-p file)
1581 (setq file (concat (file-name-as-directory file)
1582 (file-name-nondirectory default-name))))
1583 ;; Possibly translate some characters.
1584 (nnheader-translate-file-chars file)))))
1585 (gnus-make-directory (file-name-directory result))
1586 (set variable result)))
1588 (defun gnus-article-archive-name (group)
1589 "Return the first instance of an \"Archive-name\" in the current buffer."
1590 (let ((case-fold-search t))
1591 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1592 (nnheader-concat gnus-article-save-directory
1593 (match-string 1)))))
1595 (defun gnus-article-nndoc-name (group)
1596 "If GROUP is an nndoc group, return the name of the parent group."
1597 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1598 (gnus-group-get-parameter group 'save-article-group)))
1600 (defun gnus-summary-save-in-rmail (&optional filename)
1601 "Append this article to Rmail file.
1602 Optional argument FILENAME specifies file name.
1603 Directory to save to is default to `gnus-article-save-directory'."
1604 (setq filename (gnus-read-save-file-name
1605 "Save %s in rmail file:" filename
1606 gnus-rmail-save-name gnus-newsgroup-name
1607 gnus-current-headers 'gnus-newsgroup-last-rmail))
1608 (gnus-eval-in-buffer-window gnus-save-article-buffer
1612 (gnus-output-to-rmail filename))))
1615 (defun gnus-summary-save-in-mail (&optional filename)
1616 "Append this article to Unix mail file.
1617 Optional argument FILENAME specifies file name.
1618 Directory to save to is default to `gnus-article-save-directory'."
1619 (setq filename (gnus-read-save-file-name
1620 "Save %s in Unix mail file:" filename
1621 gnus-mail-save-name gnus-newsgroup-name
1622 gnus-current-headers 'gnus-newsgroup-last-mail))
1623 (gnus-eval-in-buffer-window gnus-save-article-buffer
1627 (if (and (file-readable-p filename)
1628 (mail-file-babyl-p filename))
1629 (gnus-output-to-rmail filename t)
1630 (gnus-output-to-mail filename)))))
1633 (defun gnus-summary-save-in-file (&optional filename overwrite)
1634 "Append this article to file.
1635 Optional argument FILENAME specifies file name.
1636 Directory to save to is default to `gnus-article-save-directory'."
1637 (setq filename (gnus-read-save-file-name
1638 "Save %s in file:" filename
1639 gnus-file-save-name gnus-newsgroup-name
1640 gnus-current-headers 'gnus-newsgroup-last-file))
1641 (gnus-eval-in-buffer-window gnus-save-article-buffer
1645 (when (and overwrite
1646 (file-exists-p filename))
1647 (delete-file filename))
1648 (gnus-output-to-file filename))))
1651 (defun gnus-summary-write-to-file (&optional filename)
1652 "Write this article to a file.
1653 Optional argument FILENAME specifies file name.
1654 The directory to save in defaults to `gnus-article-save-directory'."
1655 (gnus-summary-save-in-file nil t))
1657 (defun gnus-summary-save-body-in-file (&optional filename)
1658 "Append this article body to a file.
1659 Optional argument FILENAME specifies file name.
1660 The directory to save in defaults to `gnus-article-save-directory'."
1661 (setq filename (gnus-read-save-file-name
1662 "Save %s body in file:" filename
1663 gnus-file-save-name gnus-newsgroup-name
1664 gnus-current-headers 'gnus-newsgroup-last-file))
1665 (gnus-eval-in-buffer-window gnus-save-article-buffer
1669 (goto-char (point-min))
1670 (when (search-forward "\n\n" nil t)
1671 (narrow-to-region (point) (point-max)))
1672 (gnus-output-to-file filename))))
1675 (defun gnus-summary-save-in-pipe (&optional command)
1676 "Pipe this article to subprocess."
1678 (cond ((eq command 'default)
1679 gnus-last-shell-command)
1683 "Shell command on %s: "
1684 (if (and gnus-number-of-articles-to-be-saved
1685 (> gnus-number-of-articles-to-be-saved 1))
1686 (format "these %d articles"
1687 gnus-number-of-articles-to-be-saved)
1689 gnus-last-shell-command))))
1690 (when (string-equal command "")
1691 (setq command gnus-last-shell-command))
1692 (gnus-eval-in-buffer-window gnus-article-buffer
1695 (shell-command-on-region (point-min) (point-max) command nil)))
1696 (setq gnus-last-shell-command command))
1698 ;;; Article file names when saving.
1700 (defun gnus-capitalize-newsgroup (newsgroup)
1701 "Capitalize NEWSGROUP name."
1702 (when (not (zerop (length newsgroup)))
1703 (concat (char-to-string (upcase (aref newsgroup 0)))
1704 (substring newsgroup 1))))
1706 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1707 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1708 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1709 Otherwise, it is like ~/News/news/group/num."
1712 (concat (if (gnus-use-long-file-name 'not-save)
1713 (gnus-capitalize-newsgroup newsgroup)
1714 (gnus-newsgroup-directory-form newsgroup))
1715 "/" (int-to-string (mail-header-number headers)))
1716 gnus-article-save-directory)))
1718 (string-equal (file-name-directory default)
1719 (file-name-directory last-file))
1720 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1722 (or last-file default))))
1724 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1725 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1726 If variable `gnus-use-long-file-name' is non-nil, it is
1727 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1730 (concat (if (gnus-use-long-file-name 'not-save)
1732 (gnus-newsgroup-directory-form newsgroup))
1733 "/" (int-to-string (mail-header-number headers)))
1734 gnus-article-save-directory)))
1736 (string-equal (file-name-directory default)
1737 (file-name-directory last-file))
1738 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1740 (or last-file default))))
1742 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1743 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1744 If variable `gnus-use-long-file-name' is non-nil, it is
1745 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1748 (if (gnus-use-long-file-name 'not-save)
1749 (gnus-capitalize-newsgroup newsgroup)
1750 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1751 gnus-article-save-directory)))
1753 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1754 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1755 If variable `gnus-use-long-file-name' is non-nil, it is
1756 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1759 (if (gnus-use-long-file-name 'not-save)
1761 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1762 gnus-article-save-directory)))
1769 (setq afunc (car func)
1772 gfunc (intern (format "gnus-%s" func))))
1774 (if (not (fboundp afunc))
1776 `(lambda (&optional interactive &rest args)
1777 ,(documentation afunc t)
1778 (interactive (list t))
1780 (set-buffer gnus-article-buffer)
1782 (call-interactively ',afunc)
1783 (apply ',afunc args))))))))
1784 '(article-hide-headers
1785 article-hide-boring-headers
1786 article-treat-overstrike
1787 (article-fill . gnus-article-word-wrap)
1789 article-display-x-face
1792 article-hide-signature
1793 article-remove-trailing-blank-lines
1794 article-strip-leading-blank-lines
1795 article-strip-multiple-blank-lines
1796 article-strip-leading-space
1797 article-strip-blank-lines
1798 article-strip-all-blank-lines
1800 article-date-iso8601
1801 article-date-original
1806 article-treat-dumbquotes
1807 (article-show-all . gnus-article-show-all-headers))))
1810 ;;; Gnus article mode
1813 (put 'gnus-article-mode 'mode-class 'special)
1815 (gnus-define-keys gnus-article-mode-map
1816 " " gnus-article-goto-next-page
1817 "\177" gnus-article-goto-prev-page
1818 [delete] gnus-article-goto-prev-page
1819 "\C-c^" gnus-article-refer-article
1820 "h" gnus-article-show-summary
1821 "s" gnus-article-show-summary
1822 "\C-c\C-m" gnus-article-mail
1823 "?" gnus-article-describe-briefly
1824 gnus-mouse-2 gnus-article-push-button
1825 "\r" gnus-article-press-button
1826 "\t" gnus-article-next-button
1827 "\M-\t" gnus-article-prev-button
1828 "e" gnus-article-edit
1829 "<" beginning-of-buffer
1831 "\C-c\C-i" gnus-info-find-node
1834 "\C-d" gnus-article-read-summary-keys
1835 "\M-*" gnus-article-read-summary-keys
1836 "\M-#" gnus-article-read-summary-keys
1837 "\M-^" gnus-article-read-summary-keys
1838 "\M-g" gnus-article-read-summary-keys)
1840 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
1843 (unless (lookup-key gnus-article-mode-map key)
1844 (define-key gnus-article-mode-map key
1845 'gnus-article-read-summary-keys)))
1850 (let ((key (car elt)))
1851 (and (> (length key) 0)
1852 (not (eq 'menu-bar (aref key 0)))
1853 (symbolp (lookup-key gnus-summary-mode-map key))
1855 (accessible-keymaps gnus-summary-mode-map))
1859 (push (char-to-string c) keys)
1863 (defun gnus-article-make-menu-bar ()
1864 (gnus-turn-off-edit-menu 'article)
1865 (unless (boundp 'gnus-article-article-menu)
1867 gnus-article-article-menu gnus-article-mode-map ""
1869 ["Scroll forwards" gnus-article-goto-next-page t]
1870 ["Scroll backwards" gnus-article-goto-prev-page t]
1871 ["Show summary" gnus-article-show-summary t]
1872 ["Fetch Message-ID at point" gnus-article-refer-article t]
1873 ["Mail to address at point" gnus-article-mail t]
1874 ["Send a bug report" gnus-bug t]))
1877 gnus-article-treatment-menu gnus-article-mode-map ""
1879 ["Hide headers" gnus-article-hide-headers t]
1880 ["Hide signature" gnus-article-hide-signature t]
1881 ["Hide citation" gnus-article-hide-citation t]
1882 ["Treat overstrike" gnus-article-treat-overstrike t]
1883 ["Remove carriage return" gnus-article-remove-cr t]
1886 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1888 (when (boundp 'gnus-summary-post-menu)
1889 (define-key gnus-article-mode-map [menu-bar post]
1890 (cons "Post" gnus-summary-post-menu)))
1892 (gnus-run-hooks 'gnus-article-menu-hook)))
1894 (defun gnus-article-mode ()
1895 "Major mode for displaying an article.
1897 All normal editing commands are switched off.
1899 The following commands are available in addition to all summary mode
1901 \\<gnus-article-mode-map>
1902 \\[gnus-article-next-page]\t Scroll the article one page forwards
1903 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1904 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1905 \\[gnus-article-show-summary]\t Display the summary buffer
1906 \\[gnus-article-mail]\t Send a reply to the address near point
1907 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1908 \\[gnus-info-find-node]\t Go to the Gnus info node"
1910 (when (gnus-visual-p 'article-menu 'menu)
1911 (gnus-article-make-menu-bar))
1912 (gnus-simplify-mode-line)
1913 (setq mode-name "Article")
1914 (setq major-mode 'gnus-article-mode)
1915 (make-local-variable 'minor-mode-alist)
1916 (unless (assq 'gnus-show-mime minor-mode-alist)
1917 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1918 (use-local-map gnus-article-mode-map)
1919 (gnus-update-format-specifications nil 'article-mode)
1920 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1921 (make-local-variable 'gnus-page-broken)
1922 (make-local-variable 'gnus-button-marker-list)
1923 (make-local-variable 'gnus-article-current-summary)
1924 (gnus-set-default-directory)
1925 (buffer-disable-undo (current-buffer))
1926 (setq buffer-read-only t)
1927 (set-syntax-table gnus-article-mode-syntax-table)
1928 (gnus-run-hooks 'gnus-article-mode-hook))
1930 (defun gnus-article-setup-buffer ()
1931 "Initialize the article buffer."
1932 (let* ((name (if gnus-single-article-buffer "*Article*"
1933 (concat "*Article " gnus-newsgroup-name "*")))
1935 (progn (string-match "\\*Article" name)
1936 (concat " *Original Article"
1937 (substring name (match-end 0))))))
1938 (setq gnus-article-buffer name)
1939 (setq gnus-original-article-buffer original)
1940 ;; This might be a variable local to the summary buffer.
1941 (unless gnus-single-article-buffer
1943 (set-buffer gnus-summary-buffer)
1944 (setq gnus-article-buffer name)
1945 (setq gnus-original-article-buffer original)
1946 (gnus-set-global-variables)))
1947 ;; Init original article buffer.
1949 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1950 (buffer-disable-undo (current-buffer))
1951 (setq major-mode 'gnus-original-article-mode)
1952 (make-local-variable 'gnus-original-article))
1953 (if (get-buffer name)
1956 (buffer-disable-undo (current-buffer))
1957 (setq buffer-read-only t)
1958 (unless (eq major-mode 'gnus-article-mode)
1959 (gnus-article-mode))
1962 (set-buffer (gnus-get-buffer-create name))
1964 (make-local-variable 'gnus-summary-buffer)
1965 (current-buffer)))))
1967 ;; Set article window start at LINE, where LINE is the number of lines
1968 ;; from the head of the article.
1969 (defun gnus-article-set-window-start (&optional line)
1971 (get-buffer-window gnus-article-buffer t)
1973 (set-buffer gnus-article-buffer)
1974 (goto-char (point-min))
1977 (gnus-message 6 "Moved to bookmark")
1978 (search-forward "\n\n" nil t)
1982 ;;; @@ article filters
1985 (defun gnus-article-display-mime-message ()
1986 "Article display method for MIME message."
1987 ;; called from `gnus-original-article-buffer'.
1988 (let (charset all-headers)
1989 (with-current-buffer gnus-summary-buffer
1990 (setq charset default-mime-charset
1991 all-headers gnus-have-all-headers))
1992 (make-local-variable 'default-mime-charset)
1993 (setq default-mime-charset charset)
1994 (with-current-buffer (get-buffer-create gnus-article-buffer)
1995 (make-local-variable 'default-mime-charset)
1996 (setq default-mime-charset charset))
1997 (mime-display-message mime-message-structure
1998 gnus-article-buffer nil gnus-article-mode-map)
2000 (gnus-article-hide-headers nil -1))
2002 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2003 (make-local-variable 'mime-button-mother-dispatcher)
2004 (setq mime-button-mother-dispatcher
2005 (function gnus-article-push-button))
2006 (run-hooks 'gnus-mime-article-prepare-hook))
2008 (defun gnus-article-display-traditional-message ()
2009 "Article display method for traditional message."
2010 (set-buffer gnus-article-buffer)
2011 (let (buffer-read-only)
2013 (insert-buffer-substring gnus-original-article-buffer)))
2015 (defun gnus-article-make-full-mail-header (&optional number charset)
2016 "Create a new mail header structure in a raw article buffer."
2017 (unless (and number charset)
2018 (save-current-buffer
2019 (set-buffer gnus-summary-buffer)
2021 (setq number (or (cdr gnus-article-current) 0)))
2023 (setq charset (or default-mime-charset 'x-ctext)))))
2024 (goto-char (point-min))
2025 (let ((header-end (if (search-forward "\n\n" nil t)
2027 (goto-char (point-max))))
2028 (chars (- (point-max) (point)))
2029 (lines (count-lines (point) (point-max)))
2030 (default-mime-charset charset)
2032 (narrow-to-region (point-min) header-end)
2033 (setq xref (std11-fetch-field "xref"))
2035 (make-full-mail-header
2037 (std11-fetch-field "subject")
2038 (std11-fetch-field "from")
2039 (std11-fetch-field "date")
2040 (std11-fetch-field "message-id")
2041 (std11-fetch-field "references")
2044 (when xref (concat "Xref: " xref)))
2047 (defun gnus-article-prepare (article &optional all-headers header)
2048 "Prepare ARTICLE in article mode buffer.
2049 ARTICLE should either be an article number or a Message-ID.
2050 If ARTICLE is an id, HEADER should be the article headers.
2051 If ALL-HEADERS is non-nil, no headers are hidden."
2053 ;; Make sure we start in a summary buffer.
2054 (unless (eq major-mode 'gnus-summary-mode)
2055 (set-buffer gnus-summary-buffer))
2056 (setq gnus-summary-buffer (current-buffer))
2057 (let* ((gnus-article (if header (mail-header-number header) article))
2058 (summary-buffer (current-buffer))
2059 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2060 (group gnus-newsgroup-name)
2063 (gnus-article-setup-buffer)
2064 (set-buffer gnus-original-article-buffer)
2065 ;; Deactivate active regions.
2066 (when (and (boundp 'transient-mark-mode)
2067 transient-mark-mode)
2068 (setq mark-active nil))
2069 (if (not (setq result (let ((buffer-read-only nil))
2070 (gnus-request-article-this-buffer
2072 ;; There is no such article.
2074 (when (and (numberp article)
2075 (not (memq article gnus-newsgroup-sparse)))
2076 (setq gnus-article-current
2077 (cons gnus-newsgroup-name article))
2078 (set-buffer gnus-summary-buffer)
2079 (setq gnus-current-article article)
2080 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2082 (gnus-summary-set-agent-mark article)
2083 (message "Message marked for downloading"))
2084 (gnus-summary-mark-article article gnus-canceled-mark)
2085 (unless (memq article gnus-newsgroup-sparse)
2087 "No such article (may have expired or been canceled)")))))
2088 (if (or (eq result 'pseudo)
2089 (eq result 'nneething))
2092 (set-buffer summary-buffer)
2093 (push article gnus-newsgroup-history)
2094 (setq gnus-last-article gnus-current-article
2095 gnus-current-article 0
2096 gnus-current-headers nil
2097 gnus-article-current nil)
2098 (if (eq result 'nneething)
2099 (gnus-configure-windows 'summary)
2100 (gnus-configure-windows 'article))
2101 (gnus-set-global-variables))
2102 (gnus-set-mode-line 'article))
2103 ;; The result from the `request' was an actual article -
2104 ;; or at least some text that is now displayed in the
2106 (when (and (numberp article)
2107 (not (eq article gnus-current-article)))
2108 ;; Seems like a new article has been selected.
2109 ;; `gnus-current-article' must be an article number.
2111 (set-buffer summary-buffer)
2112 (push article gnus-newsgroup-history)
2113 (setq gnus-last-article gnus-current-article
2114 gnus-current-article article
2115 gnus-current-headers
2116 (gnus-summary-article-header gnus-current-article)
2117 gnus-article-current
2118 (cons gnus-newsgroup-name gnus-current-article))
2119 (unless (vectorp gnus-current-headers)
2120 (setq gnus-current-headers nil))
2121 (gnus-summary-goto-subject gnus-current-article)
2122 (when (gnus-summary-show-thread)
2123 ;; If the summary buffer really was folded, the
2124 ;; previous goto may not actually have gone to
2125 ;; the right article, but the thread root instead.
2127 (gnus-summary-goto-subject gnus-current-article))
2128 (gnus-run-hooks 'gnus-mark-article-hook)
2129 (gnus-set-mode-line 'summary)
2130 (when (gnus-visual-p 'article-highlight 'highlight)
2131 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2132 ;; Set the global newsgroup variables here.
2133 ;; Suggested by Jim Sisolak
2134 ;; <sisolak@trans4.neep.wisc.edu>.
2135 (gnus-set-global-variables)
2136 (setq gnus-have-all-headers
2137 (or all-headers gnus-show-all-headers))))
2138 (when (or (numberp article)
2140 (gnus-article-prepare-display)
2142 (goto-char (point-min))
2143 (setq gnus-page-broken
2144 (when gnus-break-pages
2145 (gnus-narrow-to-page)
2147 (gnus-set-mode-line 'article)
2148 (gnus-configure-windows 'article)
2149 (goto-char (point-min))
2150 (search-forward "\n\n" nil t)
2151 (set-window-point (get-buffer-window (current-buffer)) (point))
2154 (defun gnus-article-prepare-display ()
2155 "Make the current buffer look like a nice article."
2159 (setq mime-message-structure gnus-current-headers)
2160 gnus-article-display-method-for-mime)
2161 gnus-article-display-method-for-traditional)))
2162 (gnus-run-hooks 'gnus-tmp-internal-hook)
2163 (gnus-run-hooks 'gnus-article-prepare-hook)
2166 ;; Associate this article with the current summary buffer.
2167 (setq gnus-article-current-summary gnus-summary-buffer)
2168 ;; Perform the article display hooks.
2169 (gnus-run-hooks 'gnus-article-display-hook)))
2171 (defun gnus-article-wash-status ()
2172 "Return a string which display status of article washing."
2174 (set-buffer gnus-article-buffer)
2175 (let ((cite (gnus-article-hidden-text-p 'cite))
2176 (headers (gnus-article-hidden-text-p 'headers))
2177 (boring (gnus-article-hidden-text-p 'boring-headers))
2178 (pgp (gnus-article-hidden-text-p 'pgp))
2179 (pem (gnus-article-hidden-text-p 'pem))
2180 (signature (gnus-article-hidden-text-p 'signature))
2181 (overstrike (gnus-article-hidden-text-p 'overstrike))
2182 (emphasis (gnus-article-hidden-text-p 'emphasis))
2183 (mime gnus-show-mime))
2184 (format "%c%c%c%c%c%c%c"
2186 (if (or headers boring) ?h ? )
2187 (if (or pgp pem) ?p ? )
2188 (if signature ?s ? )
2189 (if overstrike ?o ? )
2191 (if emphasis ?e ? )))))
2193 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2195 (defun gnus-article-maybe-hide-headers ()
2196 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2197 Provided for backwards compatibility."
2198 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2200 (gnus-article-hide-headers)))
2204 (defun gnus-output-to-file (file-name)
2205 "Append the current article to a file named FILE-NAME."
2206 (let ((artbuf (current-buffer)))
2207 (nnheader-temp-write nil
2208 (insert-buffer-substring artbuf)
2209 ;; Append newline at end of the buffer as separator, and then
2211 (goto-char (point-max))
2213 (append-to-file (point-min) (point-max) file-name)
2216 (defun gnus-narrow-to-page (&optional arg)
2217 "Narrow the article buffer to a page.
2218 If given a numerical ARG, move forward ARG pages."
2220 (setq arg (if arg (prefix-numeric-value arg) 0))
2222 (set-buffer gnus-article-buffer)
2223 (goto-char (point-min))
2225 ;; Remove any old next/prev buttons.
2226 (when (gnus-visual-p 'page-marker)
2227 (let ((buffer-read-only nil))
2228 (gnus-remove-text-with-property 'gnus-prev)
2229 (gnus-remove-text-with-property 'gnus-next)))
2232 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2234 (re-search-forward page-delimiter nil 'move arg)))
2235 (goto-char (match-end 0)))
2238 (if (re-search-forward page-delimiter nil 'move)
2241 (when (and (gnus-visual-p 'page-marker)
2242 (not (= (point-min) 1)))
2244 (goto-char (point-min))
2245 (gnus-insert-prev-page-button)))
2246 (when (and (gnus-visual-p 'page-marker)
2247 (< (+ (point-max) 2) (buffer-size)))
2249 (goto-char (point-max))
2250 (gnus-insert-next-page-button)))))
2252 ;; Article mode commands
2254 (defun gnus-article-goto-next-page ()
2255 "Show the next page of the article."
2257 (when (gnus-article-next-page)
2258 (goto-char (point-min))
2259 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2261 (defun gnus-article-goto-prev-page ()
2262 "Show the next page of the article."
2264 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2265 (gnus-article-prev-page nil)))
2267 (defun gnus-article-next-page (&optional lines)
2268 "Show the next page of the current article.
2269 If end of article, return non-nil. Otherwise return nil.
2270 Argument LINES specifies lines to be scrolled up."
2272 (move-to-window-line -1)
2275 (and (pos-visible-in-window-p) ;Not continuation line.
2277 ;; Nothing in this page.
2278 (if (or (not gnus-page-broken)
2281 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2283 (gnus-narrow-to-page 1) ;Go to next page.
2285 ;; More in this page.
2286 (let ((scroll-in-place nil))
2290 ;; Long lines may cause an end-of-buffer error.
2291 (goto-char (point-max)))))
2292 (move-to-window-line 0)
2295 (defun gnus-article-prev-page (&optional lines)
2296 "Show previous page of current article.
2297 Argument LINES specifies lines to be scrolled down."
2299 (move-to-window-line 0)
2300 (if (and gnus-page-broken
2302 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2304 (gnus-narrow-to-page -1) ;Go to previous page.
2305 (goto-char (point-max))
2307 (let ((scroll-in-place nil))
2311 (beginning-of-buffer
2312 (goto-char (point-min))))
2313 (move-to-window-line 0)))))
2315 (defun gnus-article-refer-article ()
2316 "Read article specified by message-id around point."
2318 (let ((point (point)))
2319 (search-forward ">" nil t) ;Move point to end of "<....>".
2320 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2321 (let ((message-id (match-string 1)))
2323 (set-buffer gnus-summary-buffer)
2324 (gnus-summary-refer-article message-id))
2326 (error "No references around point"))))
2328 (defun gnus-article-show-summary ()
2329 "Reconfigure windows to show summary buffer."
2331 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2332 (error "There is no summary buffer for this article buffer")
2333 (gnus-article-set-globals)
2334 (gnus-configure-windows 'article)
2335 (gnus-summary-goto-subject gnus-current-article)
2336 (gnus-summary-position-point)))
2338 (defun gnus-article-describe-briefly ()
2339 "Describe article mode commands briefly."
2342 (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")))
2344 (defun gnus-article-summary-command ()
2345 "Execute the last keystroke in the summary buffer."
2347 (let ((obuf (current-buffer))
2348 (owin (current-window-configuration))
2350 (switch-to-buffer gnus-article-current-summary 'norecord)
2351 (setq func (lookup-key (current-local-map) (this-command-keys)))
2352 (call-interactively func)
2354 (set-window-configuration owin)
2355 (set-window-point (get-buffer-window (current-buffer)) (point))))
2357 (defun gnus-article-summary-command-nosave ()
2358 "Execute the last keystroke in the summary buffer."
2361 (pop-to-buffer gnus-article-current-summary 'norecord)
2362 (setq func (lookup-key (current-local-map) (this-command-keys)))
2363 (call-interactively func)))
2365 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2366 "Read a summary buffer key sequence and execute it from the article buffer."
2369 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2370 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2371 "=" "^" "\M-^" "|"))
2377 '("n" "Gn" "p" "Gp"))
2380 (set-buffer gnus-article-current-summary)
2381 (let (gnus-pick-mode)
2382 (push (or key last-command-event) unread-command-events)
2383 (setq keys (read-key-sequence nil))))
2386 (if (or (member keys nosaves)
2387 (member keys nosave-but-article)
2388 (member keys nosave-in-article))
2390 (save-window-excursion
2391 (pop-to-buffer gnus-article-current-summary 'norecord)
2392 ;; We disable the pick minor mode commands.
2393 (let (gnus-pick-mode)
2394 (setq func (lookup-key (current-local-map) keys))))
2397 (unless (member keys nosave-in-article)
2398 (set-buffer gnus-article-current-summary))
2399 (call-interactively func)
2400 (setq new-sum-point (point)))
2401 (when (member keys nosave-but-article)
2402 (pop-to-buffer gnus-article-buffer 'norecord)))
2403 ;; These commands should restore window configuration.
2404 (let ((obuf (current-buffer))
2405 (owin (current-window-configuration))
2407 (summary gnus-article-current-summary)
2408 func in-buffer selected)
2409 (if not-restore-window
2410 (pop-to-buffer summary 'norecord)
2411 (switch-to-buffer summary 'norecord))
2412 (setq in-buffer (current-buffer))
2413 ;; We disable the pick minor mode commands.
2414 (if (setq func (let (gnus-pick-mode)
2415 (lookup-key (current-local-map) keys)))
2417 (call-interactively func)
2418 (setq new-sum-point (point)))
2420 (when (eq in-buffer (current-buffer))
2421 (setq selected (gnus-summary-select-article))
2423 (unless not-restore-window
2424 (set-window-configuration owin))
2425 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2426 (set-window-point (get-buffer-window (current-buffer))
2428 (let ((win (get-buffer-window gnus-article-current-summary)))
2430 (set-window-point win new-sum-point))))))))
2432 (defun gnus-article-hide (&optional arg force)
2433 "Hide all the gruft in the current article.
2434 This means that PGP stuff, signatures, cited text and (some)
2435 headers will be hidden.
2436 If given a prefix, show the hidden text instead."
2437 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2438 (gnus-article-hide-headers arg)
2439 (gnus-article-hide-pgp arg)
2440 (gnus-article-hide-citation-maybe arg force)
2441 (gnus-article-hide-signature arg))
2443 (defun gnus-article-maybe-highlight ()
2444 "Do some article highlighting if article highlighting is requested."
2445 (when (gnus-visual-p 'article-highlight 'highlight)
2446 (gnus-article-highlight-some)))
2448 (defun gnus-check-group-server ()
2449 ;; Make sure the connection to the server is alive.
2450 (unless (gnus-server-opened
2451 (gnus-find-method-for-group gnus-newsgroup-name))
2452 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2453 (gnus-request-group gnus-newsgroup-name t)))
2455 (defun gnus-request-article-this-buffer (article group)
2456 "Get an article and insert it into this buffer."
2457 (let (do-update-line sparse-header)
2461 (gnus-kill-all-overlays)
2462 (setq group (or group gnus-newsgroup-name))
2464 ;; Using `gnus-request-article' directly will insert the article into
2465 ;; `nntp-server-buffer' - so we'll save some time by not having to
2466 ;; copy it from the server buffer into the article buffer.
2468 ;; We only request an article by message-id when we do not have the
2469 ;; headers for it, so we'll have to get those.
2470 (when (stringp article)
2471 (let ((gnus-override-method gnus-refer-article-method))
2472 (gnus-read-header article)))
2474 ;; If the article number is negative, that means that this article
2475 ;; doesn't belong in this newsgroup (possibly), so we find its
2476 ;; message-id and request it by id instead of number.
2477 (when (and (numberp article)
2479 (get-buffer gnus-summary-buffer)
2480 (gnus-buffer-exists-p gnus-summary-buffer))
2482 (set-buffer gnus-summary-buffer)
2483 (let ((header (gnus-summary-article-header article)))
2486 ((memq article gnus-newsgroup-sparse)
2487 ;; This is a sparse gap article.
2488 (setq do-update-line article)
2489 (setq article (mail-header-id header))
2490 (let ((gnus-override-method gnus-refer-article-method))
2491 (setq sparse-header (gnus-read-header article)))
2492 (setq gnus-newsgroup-sparse
2493 (delq article gnus-newsgroup-sparse)))
2495 ;; It's a real article.
2496 (setq article (mail-header-id header)))
2498 ;; It is an extracted pseudo-article.
2499 (setq article 'pseudo)
2500 (gnus-request-pseudo-article header))))
2502 (let ((method (gnus-find-method-for-group
2503 gnus-newsgroup-name)))
2504 (when (and (eq (car method) 'nneething)
2507 (file-name-as-directory
2508 (or (cadr (assq 'nneething-address method))
2510 (mail-header-subject header))))
2511 (when (file-directory-p dir)
2512 (setq article 'nneething)
2513 (gnus-group-enter-directory dir))))))))
2516 ;; Refuse to select canceled articles.
2517 ((and (numberp article)
2519 (get-buffer gnus-summary-buffer)
2520 (gnus-buffer-exists-p gnus-summary-buffer)
2521 (eq (cdr (save-excursion
2522 (set-buffer gnus-summary-buffer)
2523 (assq article gnus-newsgroup-reads)))
2524 gnus-canceled-mark))
2526 ;; Check the backlog.
2527 ((and gnus-keep-backlog
2528 (gnus-backlog-request-article group article (current-buffer)))
2530 ;; Check asynchronous pre-fetch.
2531 ((gnus-async-request-fetched-article group article (current-buffer))
2532 (gnus-async-prefetch-next group article gnus-summary-buffer)
2533 (when (and (numberp article) gnus-keep-backlog)
2534 (gnus-backlog-enter-article group article (current-buffer)))
2537 ((and gnus-use-cache
2539 (gnus-cache-request-article article group))
2541 ;; Get the article and put into the article buffer.
2542 ((or (stringp article) (numberp article))
2543 (let ((gnus-override-method
2544 (and (stringp article) gnus-refer-article-method))
2545 (buffer-read-only nil))
2547 (gnus-kill-all-overlays)
2548 (gnus-check-group-server)
2549 (when (gnus-request-article article group (current-buffer))
2550 (when (numberp article)
2551 (gnus-async-prefetch-next group article gnus-summary-buffer)
2552 (when gnus-keep-backlog
2553 (gnus-backlog-enter-article
2554 group article (current-buffer))))
2559 ;; Associate this article with the current summary buffer.
2560 (setq gnus-article-current-summary gnus-summary-buffer)
2562 ;; Take the article from the original article buffer
2563 ;; and place it in the buffer it's supposed to be in.
2564 (when (and (get-buffer gnus-article-buffer)
2565 (equal (buffer-name (current-buffer))
2566 (buffer-name (get-buffer gnus-article-buffer))))
2568 (if (get-buffer gnus-original-article-buffer)
2569 (set-buffer gnus-original-article-buffer)
2570 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2571 (buffer-disable-undo (current-buffer))
2572 (setq major-mode 'gnus-original-article-mode)
2573 (setq buffer-read-only t))
2574 (let (buffer-read-only)
2576 (insert-buffer-substring gnus-article-buffer))
2577 (setq gnus-original-article (cons group article))))
2579 ;; Update sparse articles.
2580 (when (and do-update-line
2581 (or (numberp article)
2583 (let ((buf (current-buffer)))
2584 (set-buffer gnus-summary-buffer)
2585 (gnus-summary-update-article do-update-line sparse-header)
2586 (gnus-summary-goto-subject do-update-line nil t)
2587 (set-window-point (get-buffer-window (current-buffer) t)
2589 (set-buffer buf))))))
2595 (defcustom gnus-article-edit-mode-hook nil
2596 "Hook run in article edit mode buffers."
2597 :group 'gnus-article-various
2600 (defcustom gnus-article-edit-article-setup-function
2601 'gnus-article-mime-edit-article-setup
2602 "Function called to setup an editing article buffer."
2603 :group 'gnus-article-various
2606 (defvar gnus-article-edit-done-function nil)
2608 (defvar gnus-article-edit-mode-map nil)
2610 (unless gnus-article-edit-mode-map
2611 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2613 (gnus-define-keys gnus-article-edit-mode-map
2614 "\C-c\C-c" gnus-article-edit-done
2615 "\C-c\C-k" gnus-article-edit-exit)
2617 (gnus-define-keys (gnus-article-edit-wash-map
2618 "\C-c\C-w" gnus-article-edit-mode-map)
2619 "f" gnus-article-edit-full-stops))
2621 (defun gnus-article-edit-mode ()
2622 "Major mode for editing articles.
2623 This is an extended text-mode.
2625 \\{gnus-article-edit-mode-map}"
2627 (setq major-mode 'gnus-article-edit-mode)
2628 (setq mode-name "Article Edit")
2629 (use-local-map gnus-article-edit-mode-map)
2630 (make-local-variable 'gnus-article-edit-done-function)
2631 (make-local-variable 'gnus-prev-winconf)
2632 (setq buffer-read-only nil)
2633 (buffer-enable-undo)
2635 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2637 (defun gnus-article-edit (&optional force)
2638 "Edit the current article.
2639 This will have permanent effect only in mail groups.
2640 If FORCE is non-nil, allow editing of articles even in read-only
2643 (when (and (not force)
2644 (gnus-group-read-only-p))
2645 (error "The current newsgroup does not support article editing"))
2646 (gnus-article-date-original)
2647 (gnus-article-edit-article
2648 `(lambda (no-highlight)
2649 (gnus-summary-edit-article-done
2650 ,(or (mail-header-references gnus-current-headers) "")
2651 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2653 (defun gnus-article-edit-article (exit-func)
2654 "Start editing the contents of the current article buffer."
2655 (let ((winconf (current-window-configuration)))
2656 (set-buffer gnus-article-buffer)
2657 (gnus-article-edit-mode)
2658 (gnus-article-delete-text-of-type 'annotation)
2659 (gnus-set-text-properties (point-min) (point-max) nil)
2660 (gnus-configure-windows 'edit-article)
2661 (setq gnus-article-edit-done-function exit-func)
2662 (setq gnus-prev-winconf winconf)
2663 (when gnus-article-edit-article-setup-function
2664 (funcall gnus-article-edit-article-setup-function))
2665 (gnus-message 6 "C-c C-c to end edits")))
2667 (defun gnus-article-edit-done (&optional arg)
2668 "Update the article edits and exit."
2673 (goto-char (point-min))
2674 (when (search-forward "\n\n" nil 1)
2675 (let ((lines (count-lines (point) (point-max)))
2676 (length (- (point-max) (point)))
2677 (case-fold-search t)
2678 (body (copy-marker (point))))
2679 (goto-char (point-min))
2680 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2681 (delete-region (match-beginning 1) (match-end 1))
2682 (insert (number-to-string length)))
2683 (goto-char (point-min))
2684 (when (re-search-forward
2685 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2686 (delete-region (match-beginning 1) (match-end 1))
2687 (insert (number-to-string length)))
2688 (goto-char (point-min))
2689 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2690 (delete-region (match-beginning 1) (match-end 1))
2691 (insert (number-to-string lines)))))))
2692 (let ((func gnus-article-edit-done-function)
2693 (buf (current-buffer))
2694 (start (window-start)))
2695 (remove-hook 'gnus-article-mode-hook
2696 'gnus-article-mime-edit-article-unwind)
2697 (gnus-article-edit-exit)
2700 (let ((buffer-read-only nil))
2701 (funcall func arg)))
2703 (set-window-start (get-buffer-window buf) start)
2704 (set-window-point (get-buffer-window buf) (point))))
2706 (defun gnus-article-edit-exit ()
2707 "Exit the article editing without updating."
2709 ;; We remove all text props from the article buffer.
2710 (let ((buf (format "%s" (buffer-substring (point-min) (point-max))))
2711 (curbuf (current-buffer))
2713 (window-start (window-start)))
2716 (let ((winconf gnus-prev-winconf))
2718 ;; The cache and backlog have to be flushed somewhat.
2719 (when gnus-use-cache
2720 (gnus-cache-update-article
2721 (car gnus-article-current) (cdr gnus-article-current)))
2722 (when gnus-keep-backlog
2723 (gnus-backlog-remove-article
2724 (car gnus-article-current) (cdr gnus-article-current)))
2725 ;; Flush original article as well.
2727 (when (get-buffer gnus-original-article-buffer)
2728 (set-buffer gnus-original-article-buffer)
2729 (setq gnus-original-article nil)))
2730 (set-window-configuration winconf)
2731 ;; Tippy-toe some to make sure that point remains where it was.
2732 (let ((buf (current-buffer)))
2734 (set-window-start (get-buffer-window (current-buffer)) window-start)
2736 (set-buffer buf)))))
2738 (defun gnus-article-edit-full-stops ()
2739 "Interactively repair spacing at end of sentences."
2742 (goto-char (point-min))
2743 (search-forward-regexp "^$" nil t)
2744 (let ((case-fold-search nil))
2745 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2748 ;;; Article editing with MIME-Edit
2751 (defcustom gnus-article-mime-edit-article-setup-hook nil
2752 "Hook run after setting up a MIME editing article buffer."
2753 :group 'gnus-article-various
2756 (defun gnus-article-mime-edit-article-unwind ()
2757 "Unwind `gnus-article-buffer' if article editing was given up."
2758 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
2759 (when mime-edit-mode-flag
2760 (mime-edit-exit 'nomime 'no-error)
2762 (when (featurep 'font-lock)
2763 (setq font-lock-defaults nil)
2764 (font-lock-mode 0)))
2766 (defun gnus-article-mime-edit-article-setup ()
2767 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
2768 after replacing with the original article."
2769 (setq gnus-show-mime t)
2770 (setq gnus-article-edit-done-function
2771 `(lambda (&rest args)
2772 (when mime-edit-mode-flag
2775 (goto-char (point-min))
2776 (let (case-fold-search)
2777 (when (re-search-forward
2778 (format "^%s$" (regexp-quote mail-header-separator))
2780 (replace-match "")))
2781 (when (featurep 'font-lock)
2782 (setq font-lock-defaults nil)
2784 (apply ,gnus-article-edit-done-function args)
2785 (set-buffer gnus-original-article-buffer)
2787 (insert-buffer gnus-article-buffer)
2788 (setq gnus-current-headers (gnus-article-make-full-mail-header))
2789 (gnus-article-prepare-display)))
2790 (define-key (current-local-map) "\C-c\C-k" 'gnus-article-mime-edit-exit)
2792 (insert-buffer gnus-original-article-buffer)
2794 (when (featurep 'font-lock)
2795 (set (make-local-variable 'font-lock-defaults)
2796 '(message-font-lock-keywords t))
2797 (font-lock-set-defaults)
2798 (turn-on-font-lock))
2799 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
2800 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
2802 (defun gnus-article-mime-edit-exit ()
2803 "Exit the article MIME editing without updating."
2805 (let ((winconf gnus-prev-winconf)
2807 (when mime-edit-mode-flag
2810 (goto-char (point-min))
2811 (let (case-fold-search)
2812 (when (re-search-forward
2813 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
2814 (replace-match "")))
2815 (when (featurep 'font-lock)
2816 (setq font-lock-defaults nil)
2818 ;; We remove all text props from the article buffer.
2819 (setq buf (format "%s" (buffer-substring (point-min) (point-max))))
2820 (set-buffer (get-buffer-create gnus-original-article-buffer))
2823 (setq gnus-current-headers (gnus-article-make-full-mail-header))
2824 (gnus-article-prepare-display)
2825 (set-window-configuration winconf)))
2828 ;;; Article highlights
2831 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2833 ;;; Internal Variables:
2835 (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\\)"
2836 "Regular expression that matches URLs."
2837 :group 'gnus-article-buttons
2840 (defcustom gnus-button-alist
2841 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2842 gnus-button-message-id 2)
2843 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2844 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2846 gnus-button-fetch-group 4)
2847 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2848 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2849 t gnus-button-message-id 3)
2850 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2851 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2852 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2853 ;; This is how URLs _should_ be embedded in text...
2854 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2856 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2857 "*Alist of regexps matching buttons in article bodies.
2859 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2860 REGEXP: is the string matching text around the button,
2861 BUTTON: is the number of the regexp grouping actually matching the button,
2862 FORM: is a lisp expression which must eval to true for the button to
2864 CALLBACK: is the function to call when the user push this button, and each
2865 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2867 CALLBACK can also be a variable, in that case the value of that
2868 variable it the real callback function."
2869 :group 'gnus-article-buttons
2870 :type '(repeat (list regexp
2871 (integer :tag "Button")
2873 (function :tag "Callback")
2876 (integer :tag "Regexp group")))))
2878 (defcustom gnus-header-button-alist
2879 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2880 0 t gnus-button-message-id 0)
2881 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2882 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2883 0 t gnus-button-mailto 0)
2884 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2885 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2886 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2887 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2888 gnus-button-message-id 3))
2889 "*Alist of headers and regexps to match buttons in article heads.
2891 This alist is very similar to `gnus-button-alist', except that each
2892 alist has an additional HEADER element first in each entry:
2894 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2896 HEADER is a regexp to match a header. For a fuller explanation, see
2897 `gnus-button-alist'."
2898 :group 'gnus-article-buttons
2899 :group 'gnus-article-headers
2900 :type '(repeat (list (regexp :tag "Header")
2902 (integer :tag "Button")
2904 (function :tag "Callback")
2907 (integer :tag "Regexp group")))))
2909 (defvar gnus-button-regexp nil)
2910 (defvar gnus-button-marker-list nil)
2911 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2913 (defvar gnus-button-last nil)
2914 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2918 (defun gnus-article-push-button (event)
2919 "Check text under the mouse pointer for a callback function.
2920 If the text under the mouse pointer has a `gnus-callback' property,
2921 call it with the value of the `gnus-data' text property."
2923 (set-buffer (window-buffer (posn-window (event-start event))))
2924 (let* ((pos (posn-point (event-start event)))
2925 (data (get-text-property pos 'gnus-data))
2926 (fun (get-text-property pos 'gnus-callback)))
2929 (funcall fun data))))
2931 (defun gnus-article-press-button ()
2932 "Check text at point for a callback function.
2933 If the text at point has a `gnus-callback' property,
2934 call it with the value of the `gnus-data' text property."
2936 (let* ((data (get-text-property (point) 'gnus-data))
2937 (fun (get-text-property (point) 'gnus-callback)))
2939 (funcall fun data))))
2941 (defun gnus-article-prev-button (n)
2942 "Move point to N buttons backward.
2943 If N is negative, move forward instead."
2945 (gnus-article-next-button (- n)))
2947 (defun gnus-article-next-button (n)
2948 "Move point to N buttons forward.
2949 If N is negative, move backward instead."
2951 (let ((function (if (< n 0) 'previous-single-property-change
2952 'next-single-property-change))
2953 (inhibit-point-motion-hooks t)
2955 (limit (if (< n 0) (point-min) (point-max))))
2957 (while (and (not (= limit (point)))
2959 ;; Skip past the current button.
2960 (when (get-text-property (point) 'gnus-callback)
2961 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2962 ;; Go to the next (or previous) button.
2963 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2964 ;; Put point at the start of the button.
2965 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2966 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2967 ;; Skip past intangible buttons.
2968 (when (get-text-property (point) 'intangible)
2972 (gnus-message 5 "No more buttons"))
2975 (defun gnus-article-highlight (&optional force)
2976 "Highlight current article.
2977 This function calls `gnus-article-highlight-headers',
2978 `gnus-article-highlight-citation',
2979 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2980 do the highlighting. See the documentation for those functions."
2981 (interactive (list 'force))
2982 (gnus-article-highlight-headers)
2983 (gnus-article-highlight-citation force)
2984 (gnus-article-highlight-signature)
2985 (gnus-article-add-buttons force)
2986 (gnus-article-add-buttons-to-head))
2988 (defun gnus-article-highlight-some (&optional force)
2989 "Highlight current article.
2990 This function calls `gnus-article-highlight-headers',
2991 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2992 do the highlighting. See the documentation for those functions."
2993 (interactive (list 'force))
2994 (gnus-article-highlight-headers)
2995 (gnus-article-highlight-signature)
2996 (gnus-article-add-buttons))
2998 (defun gnus-article-highlight-headers ()
2999 "Highlight article headers as specified by `gnus-header-face-alist'."
3002 (set-buffer gnus-article-buffer)
3004 (let ((alist gnus-header-face-alist)
3005 (buffer-read-only nil)
3006 (case-fold-search t)
3007 (inhibit-point-motion-hooks t)
3008 entry regexp header-face field-face from hpoints fpoints)
3009 (message-narrow-to-head)
3010 (while (setq entry (pop alist))
3011 (goto-char (point-min))
3012 (setq regexp (concat "^\\("
3013 (if (string-equal "" (nth 0 entry))
3017 header-face (nth 1 entry)
3018 field-face (nth 2 entry))
3019 (while (and (re-search-forward regexp nil t)
3023 (unless (search-forward ":" nil t)
3025 (when (and header-face
3026 (not (memq (point) hpoints)))
3027 (push (point) hpoints)
3028 (gnus-put-text-property from (point) 'face header-face))
3029 (when (and field-face
3030 (not (memq (setq from (point)) fpoints)))
3032 (while (and (zerop (forward-line 1))
3033 (memq (char-after) '(?\t ?\ ))))
3035 ;; Go to the end of the previous line.
3037 (gnus-put-text-property from (point) 'face field-face))))))))
3039 (defun gnus-article-highlight-signature ()
3040 "Highlight the signature in an article.
3041 It does this by highlighting everything after
3042 `gnus-signature-separator' using `gnus-signature-face'."
3045 (set-buffer gnus-article-buffer)
3046 (let ((buffer-read-only nil)
3047 (inhibit-point-motion-hooks t))
3049 (when (and gnus-signature-face
3050 (gnus-article-narrow-to-signature))
3051 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3052 'face gnus-signature-face)
3054 (gnus-article-search-signature)
3055 (let ((start (match-beginning 0))
3056 (end (set-marker (make-marker) (1+ (match-end 0)))))
3057 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3060 (defun gnus-button-in-region-p (b e prop)
3061 "Say whether PROP exists in the region."
3062 (text-property-not-all b e prop nil))
3064 (defun gnus-article-add-buttons (&optional force)
3065 "Find external references in the article and make buttons of them.
3066 \"External references\" are things like Message-IDs and URLs, as
3067 specified by `gnus-button-alist'."
3068 (interactive (list 'force))
3070 (set-buffer gnus-article-buffer)
3071 (let ((buffer-read-only nil)
3072 (inhibit-point-motion-hooks t)
3073 (case-fold-search t)
3074 (alist gnus-button-alist)
3076 ;; Remove all old markers.
3078 (while (setq marker (pop gnus-button-marker-list))
3080 (when (setq entry (gnus-button-entry))
3081 (put-text-property (match-beginning (nth 1 entry))
3082 (match-end (nth 1 entry))
3083 'gnus-callback nil))
3084 (set-marker marker nil)))
3085 ;; We skip the headers.
3086 (goto-char (point-min))
3087 (unless (search-forward "\n\n" nil t)
3088 (goto-char (point-max)))
3090 (while (setq entry (pop alist))
3091 (setq regexp (car entry))
3093 (while (re-search-forward regexp nil t)
3094 (let* ((start (and entry (match-beginning (nth 1 entry))))
3095 (end (and entry (match-end (nth 1 entry))))
3096 (from (match-beginning 0)))
3097 (when (and (or (eq t (nth 2 entry))
3098 (eval (nth 2 entry)))
3099 (not (gnus-button-in-region-p
3100 start end 'gnus-callback)))
3101 ;; That optional form returned non-nil, so we add the
3103 (gnus-article-add-button
3104 start end 'gnus-button-push
3105 (car (push (set-marker (make-marker) from)
3106 gnus-button-marker-list))))))))))
3108 ;; Add buttons to the head of an article.
3109 (defun gnus-article-add-buttons-to-head ()
3110 "Add buttons to the head of the article."
3113 (set-buffer gnus-article-buffer)
3114 (let ((buffer-read-only nil)
3115 (inhibit-point-motion-hooks t)
3116 (case-fold-search t)
3117 (alist gnus-header-button-alist)
3119 (nnheader-narrow-to-headers)
3121 ;; Each alist entry.
3122 (setq entry (car alist)
3124 (goto-char (point-min))
3125 (while (re-search-forward (car entry) nil t)
3126 ;; Each header matching the entry.
3127 (setq beg (match-beginning 0))
3128 (while (and (zerop (forward-line 1))
3129 (memq (char-after) '(?\t ?\ ))))
3132 (while (re-search-forward (nth 1 entry) end t)
3133 ;; Each match within a header.
3134 (let* ((entry (cdr entry))
3135 (start (match-beginning (nth 1 entry)))
3136 (end (match-end (nth 1 entry)))
3137 (form (nth 2 entry)))
3138 (goto-char (match-end 0))
3140 (gnus-article-add-button
3141 start end (nth 3 entry)
3142 (buffer-substring (match-beginning (nth 4 entry))
3143 (match-end (nth 4 entry)))))))
3147 ;;; External functions:
3149 (defun gnus-article-add-button (from to fun &optional data)
3150 "Create a button between FROM and TO with callback FUN and data DATA."
3151 (when gnus-article-button-face
3152 (gnus-overlay-put (gnus-make-overlay from to)
3153 'face gnus-article-button-face))
3154 (gnus-add-text-properties
3156 (nconc (and gnus-article-mouse-face
3157 (list gnus-mouse-face-prop gnus-article-mouse-face))
3158 (list 'gnus-callback fun)
3159 (and data (list 'gnus-data data)))))
3161 ;;; Internal functions:
3163 (defun gnus-article-set-globals ()
3165 (set-buffer gnus-summary-buffer)
3166 (gnus-set-global-variables)))
3168 (defun gnus-signature-toggle (end)
3170 (set-buffer gnus-article-buffer)
3171 (let ((buffer-read-only nil)
3172 (inhibit-point-motion-hooks t))
3173 (if (get-text-property end 'invisible)
3174 (gnus-article-unhide-text end (point-max))
3175 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3177 (defun gnus-button-entry ()
3178 ;; Return the first entry in `gnus-button-alist' matching this place.
3179 (let ((alist gnus-button-alist)
3182 (setq entry (pop alist))
3183 (if (looking-at (car entry))
3188 (defun gnus-button-push (marker)
3189 ;; Push button starting at MARKER.
3191 (set-buffer gnus-article-buffer)
3193 (let* ((entry (gnus-button-entry))
3194 (inhibit-point-motion-hooks t)
3196 (args (mapcar (lambda (group)
3197 (let ((string (match-string group)))
3198 (gnus-set-text-properties
3199 0 (length string) nil string)
3206 (fboundp (symbol-value fun)))
3207 (apply (symbol-value fun) args))
3209 (gnus-message 1 "You must define `%S' to use this button"
3210 (cons fun args)))))))
3212 (defun gnus-button-message-id (message-id)
3215 (set-buffer gnus-summary-buffer)
3216 (gnus-summary-refer-article message-id)))
3218 (defun gnus-button-fetch-group (address)
3219 "Fetch GROUP specified by ADDRESS."
3220 (if (not (string-match "[:/]" address))
3221 ;; This is just a simple group url.
3222 (gnus-group-read-ephemeral-group address gnus-select-method)
3223 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3225 (error "Can't parse %s" address)
3226 (gnus-group-read-ephemeral-group
3227 (match-string 4 address)
3228 `(nntp ,(match-string 1 address)
3229 (nntp-address ,(match-string 1 address))
3230 (nntp-port-number ,(if (match-end 3)
3231 (match-string 3 address)
3234 (defun gnus-url-parse-query-string (query &optional downcase)
3235 (let (retval pairs cur key val)
3236 (setq pairs (gnus-split-string query "&"))
3238 (setq cur (car pairs)
3240 (if (not (string-match "=" cur))
3242 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3243 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3245 (setq key (downcase key)))
3246 (setq cur (assoc key retval))
3248 (setcdr cur (cons val (cdr cur)))
3249 (setq retval (cons (list key val) retval)))))
3252 (defun gnus-url-unhex (x)
3259 (defun gnus-url-unhex-string (str &optional allow-newlines)
3260 "Remove %XXX embedded spaces, etc in a url.
3261 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3262 decoding of carriage returns and line feeds in the string, which is normally
3263 forbidden in URL encoding."
3264 (setq str (or str ""))
3266 (case-fold-search t))
3267 (while (string-match "%[0-9a-f][0-9a-f]" str)
3268 (let* ((start (match-beginning 0))
3269 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3271 (gnus-url-unhex (elt str (+ start 2))))))
3273 tmp (substring str 0 start)
3276 (char-to-string code))
3277 ((or (= code ?\n) (= code ?\r))
3279 (t (char-to-string code))))
3280 str (substring str (match-end 0)))))
3281 (setq tmp (concat tmp str))
3284 (defun gnus-url-mailto (url)
3285 ;; Send mail to someone
3286 (when (string-match "mailto:/*\\(.*\\)" url)
3287 (setq url (substring url (match-beginning 1) nil)))
3288 (let (to args subject func)
3289 (if (string-match (regexp-quote "?") url)
3290 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3291 args (gnus-url-parse-query-string
3292 (substring url (match-end 0) nil) t))
3293 (setq to (gnus-url-unhex-string url)))
3294 (setq args (cons (list "to" to) args)
3295 subject (cdr-safe (assoc "subject" args)))
3296 (gnus-setup-message 'reply
3299 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3302 (message-position-on-field (caar args)))
3303 (insert (mapconcat 'identity (cdar args) ", "))
3304 (setq args (cdr args)))
3307 (message-goto-subject)))))
3309 (defun gnus-button-mailto (address)
3311 (set-buffer (gnus-copy-article-buffer))
3312 (gnus-setup-message 'reply
3313 (message-reply address)))
3315 (defun gnus-button-reply (address)
3316 ;; Reply to ADDRESS.
3317 (gnus-setup-message 'reply
3318 (message-reply address)))
3320 (defun gnus-button-url (address)
3322 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3323 (if (listp browse-url-browser-function)
3324 (browse-url address)
3325 (funcall browse-url-browser-function address)))
3327 (defun gnus-button-embedded-url (address)
3329 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3330 (if (listp browse-url-browser-function)
3331 (browse-url (gnus-strip-whitespace address))
3332 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3334 ;;; Next/prev buttons in the article buffer.
3336 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3337 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3339 (defvar gnus-prev-page-map nil)
3340 (unless gnus-prev-page-map
3341 (setq gnus-prev-page-map (make-sparse-keymap))
3342 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3343 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3345 (defun gnus-insert-prev-page-button ()
3346 (let ((buffer-read-only nil))
3348 gnus-prev-page-line-format nil
3349 `(gnus-prev t local-map ,gnus-prev-page-map
3350 gnus-callback gnus-article-button-prev-page
3351 gnus-type annotation))))
3353 (defvar gnus-next-page-map nil)
3354 (unless gnus-next-page-map
3355 (setq gnus-next-page-map (make-keymap))
3356 (suppress-keymap gnus-prev-page-map)
3357 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3358 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3360 (defun gnus-button-next-page ()
3361 "Go to the next page."
3363 (let ((win (selected-window)))
3364 (select-window (get-buffer-window gnus-article-buffer t))
3365 (gnus-article-next-page)
3366 (select-window win)))
3368 (defun gnus-button-prev-page ()
3369 "Go to the prev page."
3371 (let ((win (selected-window)))
3372 (select-window (get-buffer-window gnus-article-buffer t))
3373 (gnus-article-prev-page)
3374 (select-window win)))
3376 (defun gnus-insert-next-page-button ()
3377 (let ((buffer-read-only nil))
3378 (gnus-eval-format gnus-next-page-line-format nil
3380 t local-map ,gnus-next-page-map
3381 gnus-callback gnus-article-button-next-page
3382 gnus-type annotation))))
3384 (defun gnus-article-button-next-page (arg)
3385 "Go to the next page."
3387 (let ((win (selected-window)))
3388 (select-window (get-buffer-window gnus-article-buffer t))
3389 (gnus-article-next-page)
3390 (select-window win)))
3392 (defun gnus-article-button-prev-page (arg)
3393 "Go to the prev page."
3395 (let ((win (selected-window)))
3396 (select-window (get-buffer-window gnus-article-buffer t))
3397 (gnus-article-prev-page)
3398 (select-window win)))
3404 (defun gnus-article-header-presentation-method (entity situation)
3405 (mime-insert-header entity)
3408 (set-alist 'mime-header-presentation-method-alist
3409 'gnus-original-article-mode
3410 #'gnus-article-header-presentation-method)
3412 (defun gnus-mime-preview-quitting-method ()
3413 (mime-preview-kill-buffer)
3414 (delete-other-windows)
3415 (gnus-article-show-summary)
3416 (gnus-summary-select-article gnus-show-all-headers t))
3418 (set-alist 'mime-preview-quitting-method-alist
3419 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
3421 (defun gnus-following-method (buf)
3424 (message-yank-original)
3426 (goto-char (point-min))
3429 (set-alist 'mime-preview-following-method-alist
3430 'gnus-original-article-mode #'gnus-following-method)
3432 (set-alist 'mime-preview-over-to-previous-method-alist
3433 'gnus-original-article-mode
3435 (gnus-article-read-summary-keys
3436 nil (gnus-character-to-event ?P))))
3438 (set-alist 'mime-preview-over-to-next-method-alist
3439 'gnus-original-article-mode'
3441 (gnus-article-read-summary-keys
3442 nil (gnus-character-to-event ?N))))
3452 (run-hooks 'gnus-art-load-hook)
3454 ;;; gnus-art.el ends here