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-encoded-word
395 'gnus-article-display-message-with-encoded-word
396 "*Function to display a message with MIME encoded-words.
397 The function is called from the article buffer."
398 :group 'gnus-article-mime
401 (defcustom gnus-article-display-method-for-traditional
402 'gnus-article-display-traditional-message
403 "*Function to display a traditional message.
404 The function is called from the article buffer."
405 :group 'gnus-article-mime
408 (defcustom gnus-page-delimiter "^\^L"
409 "*Regexp describing what to use as article page delimiters.
410 The default value is \"^\^L\", which is a form linefeed at the
411 beginning of a line."
413 :group 'gnus-article-various)
415 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
416 "*The format specification for the article mode line.
417 See `gnus-summary-mode-line-format' for a closer description."
419 :group 'gnus-article-various)
421 (defcustom gnus-article-mode-hook nil
422 "*A hook for Gnus article mode."
424 :group 'gnus-article-various)
426 (defcustom gnus-article-menu-hook nil
427 "*Hook run after the creation of the article mode menu."
429 :group 'gnus-article-various)
431 (defcustom gnus-article-prepare-hook nil
432 "*A hook called after an article has been prepared in the article buffer.
433 If you want to run a special decoding program like nkf, use this hook."
435 :group 'gnus-article-various)
437 (defcustom gnus-article-hide-pgp-hook nil
438 "*A hook called after successfully hiding a PGP signature."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-button-face 'bold
443 "Face used for highlighting buttons in the article buffer.
445 An article button is a piece of text that you can activate by pressing
446 `RET' or `mouse-2' above it."
448 :group 'gnus-article-buttons)
450 (defcustom gnus-article-mouse-face 'highlight
451 "Face used for mouse highlighting in the article buffer.
453 Article buttons will be displayed in this face when the cursor is
456 :group 'gnus-article-buttons)
458 (defcustom gnus-signature-face 'gnus-signature-face
459 "Face used for highlighting a signature in the article buffer.
460 Obsolete; use the face `gnus-signature-face' for customizations instead."
462 :group 'gnus-article-highlight
463 :group 'gnus-article-signature)
465 (defface gnus-signature-face
468 "Face used for highlighting a signature in the article buffer."
469 :group 'gnus-article-highlight
470 :group 'gnus-article-signature)
472 (defface gnus-header-from-face
475 (:foreground "spring green"))
478 (:foreground "red3"))
481 "Face used for displaying from headers."
482 :group 'gnus-article-headers
483 :group 'gnus-article-highlight)
485 (defface gnus-header-subject-face
488 (:foreground "SeaGreen3"))
491 (:foreground "red4"))
493 (:bold t :italic t)))
494 "Face used for displaying subject headers."
495 :group 'gnus-article-headers
496 :group 'gnus-article-highlight)
498 (defface gnus-header-newsgroups-face
501 (:foreground "yellow" :italic t))
504 (:foreground "MidnightBlue" :italic t))
507 "Face used for displaying newsgroups headers."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defface gnus-header-name-face
514 (:foreground "SeaGreen"))
517 (:foreground "maroon"))
520 "Face used for displaying header names."
521 :group 'gnus-article-headers
522 :group 'gnus-article-highlight)
524 (defface gnus-header-content-face
527 (:foreground "forest green" :italic t))
530 (:foreground "indianred4" :italic t))
532 (:italic t))) "Face used for displaying header content."
533 :group 'gnus-article-headers
534 :group 'gnus-article-highlight)
536 (defcustom gnus-header-face-alist
537 '(("From" nil gnus-header-from-face)
538 ("Subject" nil gnus-header-subject-face)
539 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
540 ("" gnus-header-name-face gnus-header-content-face))
541 "*Controls highlighting of article header.
543 An alist of the form (HEADER NAME CONTENT).
545 HEADER is a regular expression which should match the name of an
546 header header and NAME and CONTENT are either face names or nil.
548 The name of each header field will be displayed using the face
549 specified by the first element in the list where HEADER match the
550 header name and NAME is non-nil. Similarly, the content will be
551 displayed by the first non-nil matching CONTENT face."
552 :group 'gnus-article-headers
553 :group 'gnus-article-highlight
554 :type '(repeat (list (regexp :tag "Header")
556 (item :tag "skip" nil)
557 (face :value default))
558 (choice :tag "Content"
559 (item :tag "skip" nil)
560 (face :value default)))))
562 ;;; Internal variables
564 (defvar article-lapsed-timer nil)
565 (defvar gnus-article-current-summary nil)
567 (defvar gnus-article-mode-syntax-table
568 (let ((table (copy-syntax-table text-mode-syntax-table)))
569 (modify-syntax-entry ?- "w" table)
570 (modify-syntax-entry ?> ")" table)
571 (modify-syntax-entry ?< "(" table)
573 "Syntax table used in article mode buffers.
574 Initialized from `text-mode-syntax-table.")
576 (defvar gnus-save-article-buffer nil)
578 (defvar gnus-article-mode-line-format-alist
579 (nconc '((?w (gnus-article-wash-status) ?s))
580 gnus-summary-mode-line-format-alist))
582 (defvar gnus-number-of-articles-to-be-saved nil)
584 (defvar gnus-inhibit-hiding nil)
586 (defsubst gnus-article-hide-text (b e props)
587 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
588 (add-text-properties b e props)
589 (when (memq 'intangible props)
591 (max (1- b) (point-min))
592 b 'intangible (cddr (memq 'intangible props)))))
594 (defsubst gnus-article-unhide-text (b e)
595 "Remove hidden text properties from region between B and E."
596 (remove-text-properties b e gnus-hidden-properties)
597 (when (memq 'intangible gnus-hidden-properties)
598 (put-text-property (max (1- b) (point-min))
601 (defun gnus-article-hide-text-type (b e type)
602 "Hide text of TYPE between B and E."
603 (gnus-article-hide-text
604 b e (cons 'article-type (cons type gnus-hidden-properties))))
606 (defun gnus-article-unhide-text-type (b e type)
607 "Unhide text of TYPE between B and E."
608 (remove-text-properties
609 b e (cons 'article-type (cons type gnus-hidden-properties)))
610 (when (memq 'intangible gnus-hidden-properties)
611 (put-text-property (max (1- b) (point-min))
614 (defun gnus-article-hide-text-of-type (type)
615 "Hide text of TYPE in the current buffer."
617 (let ((b (point-min))
619 (while (setq b (text-property-any b e 'article-type type))
620 (add-text-properties b (incf b) gnus-hidden-properties)))))
622 (defun gnus-article-delete-text-of-type (type)
623 "Delete text of TYPE in the current buffer."
625 (let ((b (point-min)))
626 (while (setq b (text-property-any b (point-max) 'article-type type))
628 b (or (text-property-not-all b (point-max) 'article-type type)
631 (defun gnus-article-delete-invisible-text ()
632 "Delete all invisible text in the current buffer."
634 (let ((b (point-min)))
635 (while (setq b (text-property-any b (point-max) 'invisible t))
637 b (or (text-property-not-all b (point-max) 'invisible t)
640 (defun gnus-article-text-type-exists-p (type)
641 "Say whether any text of type TYPE exists in the buffer."
642 (text-property-any (point-min) (point-max) 'article-type type))
644 (defsubst gnus-article-header-rank ()
645 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
646 (let ((list gnus-sorted-header-list)
649 (when (looking-at (car list))
651 (setq list (cdr list))
655 (defun article-hide-headers (&optional arg delete)
656 "Toggle whether to hide unwanted headers and possibly sort them as well.
657 If given a negative prefix, always show; if given a positive prefix,
659 (interactive (gnus-article-hidden-arg))
661 (if (gnus-article-check-hidden-text 'headers arg)
662 ;; Show boring headers as well.
663 (gnus-article-show-hidden-text 'boring-headers)
664 ;; This function might be inhibited.
665 (unless gnus-inhibit-hiding
668 (let ((buffer-read-only nil)
670 (props (nconc (list 'article-type 'headers)
671 gnus-hidden-properties))
672 (max (1+ (length gnus-sorted-header-list)))
673 (ignored (when (not gnus-visible-headers)
674 (cond ((stringp gnus-ignored-headers)
675 gnus-ignored-headers)
676 ((listp gnus-ignored-headers)
677 (mapconcat 'identity gnus-ignored-headers
680 (cond ((stringp gnus-visible-headers)
681 gnus-visible-headers)
682 ((and gnus-visible-headers
683 (listp gnus-visible-headers))
684 (mapconcat 'identity gnus-visible-headers "\\|"))))
685 (inhibit-point-motion-hooks t)
687 ;; First we narrow to just the headers.
689 (goto-char (point-min))
690 ;; Hide any "From " lines at the beginning of (mail) articles.
691 (while (looking-at "From ")
695 (delete-region (point-min) (point))
696 (gnus-article-hide-text (point-min) (point) props)))
697 ;; Then treat the rest of the header lines.
700 (if (search-forward "\n\n" nil t) ; if there's a body
701 (progn (forward-line -1) (point))
703 ;; Then we use the two regular expressions
704 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
705 ;; select which header lines is to remain visible in the
707 (goto-char (point-min))
708 (while (re-search-forward "^[^ \t]*:" nil t)
710 ;; Mark the rank of the header.
712 (point) (1+ (point)) 'message-rank
713 (if (or (and visible (looking-at visible))
715 (not (looking-at ignored))))
716 (gnus-article-header-rank)
719 (message-sort-headers-1)
720 (when (setq beg (text-property-any
721 (point-min) (point-max) 'message-rank (+ 2 max)))
722 ;; We make the unwanted headers invisible.
724 (delete-region beg (point-max))
725 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
726 (gnus-article-hide-text-type beg (point-max) 'headers))
727 ;; Work around XEmacs lossage.
728 (put-text-property (point-min) beg 'invisible nil))))))))
730 (defun article-hide-boring-headers (&optional arg)
731 "Toggle hiding of headers that aren't very interesting.
732 If given a negative prefix, always show; if given a positive prefix,
734 (interactive (gnus-article-hidden-arg))
735 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
736 (not gnus-show-all-headers))
739 (let ((buffer-read-only nil)
740 (list gnus-boring-article-headers)
741 (inhibit-point-motion-hooks t)
743 (nnheader-narrow-to-headers)
745 (setq elem (pop list))
746 (goto-char (point-min))
748 ;; Hide empty headers.
750 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
752 (gnus-article-hide-text-type
753 (progn (beginning-of-line) (point))
756 (if (re-search-forward "^[^ \t]" nil t)
760 ;; Hide boring Newsgroups header.
761 ((eq elem 'newsgroups)
762 (when (equal (gnus-fetch-field "newsgroups")
763 (gnus-group-real-name
764 (if (boundp 'gnus-newsgroup-name)
767 (gnus-article-hide-header "newsgroups")))
768 ((eq elem 'followup-to)
769 (when (equal (message-fetch-field "followup-to")
770 (message-fetch-field "newsgroups"))
771 (gnus-article-hide-header "followup-to")))
773 (let ((from (message-fetch-field "from"))
774 (reply-to (message-fetch-field "reply-to")))
779 (nth 1 (funcall gnus-extract-address-components from))
780 (nth 1 (funcall gnus-extract-address-components reply-to)))))
781 (gnus-article-hide-header "reply-to"))))
783 (let ((date (message-fetch-field "date")))
785 (< (gnus-days-between (current-time-string) date)
787 (gnus-article-hide-header "date"))))
789 (let ((to (message-fetch-field "to")))
790 (when (> (length to) 1024)
791 (gnus-article-hide-header "to"))))
794 (goto-char (point-min))
795 (while (re-search-forward "^to:" nil t)
796 (setq to-count (1+ to-count)))
798 (while (> to-count 0)
799 (goto-char (point-min))
801 (re-search-forward "^to:" nil nil to-count)
803 (narrow-to-region (point) (point-max))
804 (gnus-article-hide-header "to"))
805 (setq to-count (1- to-count)))))))))))))
807 (defun gnus-article-hide-header (header)
809 (goto-char (point-min))
810 (when (re-search-forward (concat "^" header ":") nil t)
811 (gnus-article-hide-text-type
812 (progn (beginning-of-line) (point))
815 (if (re-search-forward "^[^ \t]" nil t)
820 (defun article-treat-dumbquotes ()
821 "Translate M******** sm*rtq**t*s into proper text."
823 (article-translate-characters "\221\222\223\223" "`'\"\""))
825 (defun article-translate-characters (from to)
826 "Translate all characters in the body of the article according to FROM and TO.
827 FROM is a string of characters to translate from; to is a string of
828 characters to translate to."
830 (goto-char (point-min))
831 (when (search-forward "\n\n" nil t)
832 (let ((buffer-read-only nil)
833 (x (make-string 225 ?x))
835 (while (< (incf i) (length x))
838 (while (< i (length from))
839 (aset x (aref from i) (aref to i))
841 (translate-region (point) (point-max) x)))))
843 (defun article-treat-overstrike ()
844 "Translate overstrikes into bold text."
847 (goto-char (point-min))
848 (when (search-forward "\n\n" nil t)
849 (let ((buffer-read-only nil))
850 (while (search-forward "\b" nil t)
851 (let ((next (following-char))
852 (previous (char-after (- (point) 2))))
853 ;; We do the boldification/underlining by hiding the
854 ;; overstrikes and putting the proper text property
858 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
859 (put-text-property (point) (1+ (point)) 'face 'bold))
861 (gnus-article-hide-text-type
862 (1- (point)) (1+ (point)) 'overstrike)
864 (- (point) 2) (1- (point)) 'face 'underline))
866 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
868 (point) (1+ (point)) 'face 'underline)))))))))
870 (defun article-fill ()
871 "Format too long lines."
874 (let ((buffer-read-only nil))
876 (goto-char (point-min))
877 (search-forward "\n\n" nil t)
879 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
880 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
881 (adaptive-fill-mode t))
883 (and (>= (current-column) (min fill-column (window-width)))
884 (/= (preceding-char) ?:)
885 (fill-paragraph nil))
888 (defun article-remove-cr ()
889 "Remove carriage returns from an article."
892 (let ((buffer-read-only nil))
893 (goto-char (point-min))
894 (while (search-forward "\r" nil t)
895 (replace-match "" t t)))))
897 (defun article-remove-trailing-blank-lines ()
898 "Remove all trailing blank lines from the article."
901 (let ((buffer-read-only nil))
902 (goto-char (point-max))
906 (while (and (not (bobp))
907 (looking-at "^[ \t]*$"))
912 (defun article-display-x-face (&optional force)
913 "Look for an X-Face header and display it if present."
914 (interactive (list 'force))
916 ;; Delete the old process, if any.
917 (when (process-status "article-x-face")
918 (delete-process "article-x-face"))
919 (let ((inhibit-point-motion-hooks t)
923 (nnheader-narrow-to-headers)
924 (setq from (message-fetch-field "from"))
925 (goto-char (point-min))
926 (while (and gnus-article-x-face-command
929 ;; Check whether this face is censored.
930 (not gnus-article-x-face-too-ugly)
931 (and gnus-article-x-face-too-ugly from
932 (not (string-match gnus-article-x-face-too-ugly
934 ;; Has to be present.
935 (re-search-forward "^X-Face: " nil t))
936 ;; This used to try to do multiple faces (`while' instead of
937 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
938 ;; work (b) it can crash some versions of Emacs (c) are
939 ;; multiple faces really something to encourage?
940 (when (stringp gnus-article-x-face-command)
942 ;; We now have the area of the buffer where the X-Face is stored.
945 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
946 ;; We display the face.
947 (if (symbolp gnus-article-x-face-command)
948 ;; The command is a lisp function, so we call it.
949 (if (gnus-functionp gnus-article-x-face-command)
950 (funcall gnus-article-x-face-command beg end)
951 (error "%s is not a function" gnus-article-x-face-command))
952 ;; The command is a string, so we interpret the command
953 ;; as a, well, command, and fork it off.
954 (let ((process-connection-type nil))
955 (process-kill-without-query
957 "article-x-face" nil shell-file-name shell-command-switch
958 gnus-article-x-face-command))
959 (process-send-region "article-x-face" beg end)
960 (process-send-eof "article-x-face"))))))))))
962 (defun gnus-article-decode-rfc1522 ()
963 "Decode MIME encoded-words in header fields."
964 (let (buffer-read-only)
965 (let ((charset (save-excursion
966 (set-buffer gnus-summary-buffer)
967 default-mime-charset)))
968 (eword-decode-header charset)
971 (defun article-hide-pgp (&optional arg)
972 "Toggle hiding of any PGP headers and signatures in the current article.
973 If given a negative prefix, always show; if given a positive prefix,
975 (interactive (gnus-article-hidden-arg))
976 (unless (gnus-article-check-hidden-text 'pgp arg)
978 (let ((inhibit-point-motion-hooks t)
979 buffer-read-only beg end)
981 (goto-char (point-min))
982 ;; Hide the "header".
983 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
984 (delete-region (1+ (match-beginning 0)) (match-end 0))
986 ;; Hide the actual signature.
987 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
988 (setq end (1+ (match-beginning 0)))
991 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
993 ;; Perhaps we shouldn't hide to the end of the buffer
994 ;; if there is no end to the signature?
996 ;; Hide "- " PGP quotation markers.
998 (narrow-to-region beg end)
999 (goto-char (point-min))
1000 (while (re-search-forward "^- " nil t)
1002 (match-beginning 0) (match-end 0)))
1004 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1006 (defun article-hide-pem (&optional arg)
1007 "Toggle hiding of any PEM headers and signatures in the current article.
1008 If given a negative prefix, always show; if given a positive prefix,
1010 (interactive (gnus-article-hidden-arg))
1011 (unless (gnus-article-check-hidden-text 'pem arg)
1013 (let (buffer-read-only end)
1015 (goto-char (point-min))
1016 ;; hide the horrendously ugly "header".
1017 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1020 (setq end (1+ (match-beginning 0)))
1021 (gnus-article-hide-text-type
1023 (if (search-forward "\n\n" nil t)
1027 ;; hide the trailer as well
1028 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1031 (gnus-article-hide-text-type
1032 (match-beginning 0) (match-end 0) 'pem))))))
1034 (defun article-hide-signature (&optional arg)
1035 "Hide the signature in the current article.
1036 If given a negative prefix, always show; if given a positive prefix,
1038 (interactive (gnus-article-hidden-arg))
1039 (unless (gnus-article-check-hidden-text 'signature arg)
1042 (let ((buffer-read-only nil))
1043 (when (gnus-article-narrow-to-signature)
1044 (gnus-article-hide-text-type
1045 (point-min) (point-max) 'signature)))))))
1047 (defun article-strip-leading-blank-lines ()
1048 "Remove all blank lines from the beginning of the article."
1051 (let ((inhibit-point-motion-hooks t)
1053 (goto-char (point-min))
1054 (when (search-forward "\n\n" nil t)
1055 (while (and (not (eobp))
1056 (looking-at "[ \t]*$"))
1057 (gnus-delete-line))))))
1059 (defun article-strip-multiple-blank-lines ()
1060 "Replace consecutive blank lines with one empty line."
1063 (let ((inhibit-point-motion-hooks t)
1065 ;; First make all blank lines empty.
1066 (goto-char (point-min))
1067 (search-forward "\n\n" nil t)
1068 (while (re-search-forward "^[ \t]+$" nil t)
1069 (replace-match "" nil t))
1070 ;; Then replace multiple empty lines with a single empty line.
1071 (goto-char (point-min))
1072 (search-forward "\n\n" nil t)
1073 (while (re-search-forward "\n\n\n+" nil t)
1074 (replace-match "\n\n" t t)))))
1076 (defun article-strip-leading-space ()
1077 "Remove all white space from the beginning of the lines in the article."
1080 (let ((inhibit-point-motion-hooks t)
1082 (goto-char (point-min))
1083 (search-forward "\n\n" nil t)
1084 (while (re-search-forward "^[ \t]+" nil t)
1085 (replace-match "" t t)))))
1087 (defun article-strip-blank-lines ()
1088 "Strip leading, trailing and multiple blank lines."
1090 (article-strip-leading-blank-lines)
1091 (article-remove-trailing-blank-lines)
1092 (article-strip-multiple-blank-lines))
1094 (defun article-strip-all-blank-lines ()
1095 "Strip all blank lines."
1098 (let ((inhibit-point-motion-hooks t)
1100 (goto-char (point-min))
1101 (search-forward "\n\n" nil t)
1102 (while (re-search-forward "^[ \t]*\n" nil t)
1103 (replace-match "" t t)))))
1105 (defun gnus-article-narrow-to-signature ()
1106 "Narrow to the signature; return t if a signature is found, else nil."
1108 (let ((inhibit-point-motion-hooks t))
1109 (when (gnus-article-search-signature)
1111 ;; Check whether we have some limits to what we consider
1112 ;; to be a signature.
1113 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1114 (list gnus-signature-limit)))
1116 (while (setq limit (pop limits))
1117 (if (or (and (integerp limit)
1118 (< (- (point-max) (point)) limit))
1120 (< (count-lines (point) (point-max)) limit))
1121 (and (gnus-functionp limit)
1123 (and (stringp limit)
1124 (not (re-search-forward limit nil t))))
1125 () ; This limit did not succeed.
1129 (narrow-to-region (point) (point-max))
1132 (defun gnus-article-search-signature ()
1133 "Search the current buffer for the signature separator.
1134 Put point at the beginning of the signature separator."
1135 (let ((cur (point)))
1136 (goto-char (point-max))
1137 (if (if (stringp gnus-signature-separator)
1138 (re-search-backward gnus-signature-separator nil t)
1139 (let ((seps gnus-signature-separator))
1141 (not (re-search-backward (car seps) nil t)))
1149 (autoload 'w3-display "w3-parse")
1150 (autoload 'w3-do-setup "w3" "" t)
1151 (autoload 'w3-region "w3-display" "" t))
1153 (defun gnus-article-treat-html ()
1156 (let ((cbuf (current-buffer)))
1157 (set-buffer gnus-article-buffer)
1158 (let (buf buffer-read-only b e)
1160 (goto-char (point-min))
1162 (if (search-forward "\n\n" nil t)
1165 (setq e (point-max)))
1166 (nnheader-temp-write nil
1167 (insert-buffer-substring gnus-article-buffer b e)
1169 (save-window-excursion
1170 (w3-region (point-min) (point-max))
1171 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1173 (delete-region (point-min) (point-max))
1176 (goto-char (point-min))
1177 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1178 (set-buffer cbuf))))
1180 (defun gnus-article-hidden-arg ()
1181 "Return the current prefix arg as a number, or 0 if no prefix."
1182 (list (if current-prefix-arg
1183 (prefix-numeric-value current-prefix-arg)
1186 (defun gnus-article-check-hidden-text (type arg)
1187 "Return nil if hiding is necessary.
1188 Arg can be nil or a number. Nil and positive means hide, negative
1189 means show, 0 means toggle."
1193 (let ((hide (gnus-article-hidden-text-p type)))
1199 (gnus-article-show-hidden-text type))
1201 (if (eq hide 'hidden)
1202 (gnus-article-show-hidden-text type)
1205 (defun gnus-article-hidden-text-p (type)
1206 "Say whether the current buffer contains hidden text of type TYPE."
1207 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1209 (not (get-text-property pos 'invisible)))
1211 (text-property-any (1+ pos) (point-max) 'article-type type)))
1216 (defun gnus-article-show-hidden-text (type &optional hide)
1217 "Show all hidden text of type TYPE.
1218 If HIDE, hide the text instead."
1220 (let ((buffer-read-only nil)
1221 (inhibit-point-motion-hooks t)
1224 (while (setq beg (text-property-any end (point-max) 'article-type type))
1227 (text-property-not-all beg (point-max) 'article-type type)
1230 (gnus-article-hide-text beg end gnus-hidden-properties)
1231 (gnus-article-unhide-text beg end))
1235 (defconst article-time-units
1236 `((year . ,(* 365.25 24 60 60))
1237 (week . ,(* 7 24 60 60))
1238 (day . ,(* 24 60 60))
1242 "Mapping from time units to seconds.")
1244 (defun article-date-ut (&optional type highlight header)
1245 "Convert DATE date to universal time in the current article.
1246 If TYPE is `local', convert to local time; if it is `lapsed', output
1247 how much time has lapsed since DATE."
1248 (interactive (list 'ut t))
1249 (let* ((header (or header
1250 (mail-header-date gnus-current-headers)
1251 (message-fetch-field "date")
1253 (date (if (vectorp header) (mail-header-date header)
1255 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1256 (inhibit-point-motion-hooks t)
1257 bface eface newline)
1258 (when (and date (not (string= date "")))
1261 (nnheader-narrow-to-headers)
1262 (let ((buffer-read-only nil))
1263 ;; Delete any old Date headers.
1264 (if (re-search-forward date-regexp nil t)
1266 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1267 eface (get-text-property (1- (gnus-point-at-eol))
1269 (delete-region (progn (beginning-of-line) (point))
1270 (progn (end-of-line) (point)))
1271 (beginning-of-line))
1272 (goto-char (point-max))
1274 (insert (article-make-date-line date type))
1277 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1278 (put-text-property (match-beginning 1) (1+ (match-end 1))
1280 (put-text-property (match-beginning 2) (match-end 2)
1284 (insert "\n"))))))))
1286 (defun article-make-date-line (date type)
1287 "Return a DATE line of TYPE."
1289 ;; Convert to the local timezone. We have to slap a
1290 ;; `condition-case' round the calls to the timezone
1291 ;; functions since they aren't particularly resistant to
1294 (concat "Date: " (condition-case ()
1295 (timezone-make-date-arpa-standard date)
1297 ;; Convert to Universal Time.
1301 (timezone-make-date-arpa-standard date nil "UT")
1303 ;; Get the original date from the article.
1304 ((eq type 'original)
1305 (concat "Date: " date))
1306 ;; Let the user define the format.
1308 (if (gnus-functionp gnus-article-time-format)
1310 gnus-article-time-format
1313 (timezone-make-date-arpa-standard
1317 (format-time-string gnus-article-time-format
1320 (timezone-make-date-arpa-standard
1321 date nil "UT")))))))
1326 (format-time-string "%Y%M%DT%h%m%s"
1329 (timezone-make-date-arpa-standard
1331 ;; Do an X-Sent lapsed format.
1333 ;; If the date is seriously mangled, the timezone functions are
1334 ;; liable to bug out, so we ignore all errors.
1335 (let* ((now (current-time))
1340 (timezone-make-date-arpa-standard
1341 (current-time-string now)
1342 (current-time-zone now) "UT"))
1344 (timezone-make-date-arpa-standard
1346 (real-sec (and real-time
1347 (+ (* (float (car real-time)) 65536)
1349 (sec (and real-time (abs real-sec)))
1359 ;; This is a bit convoluted, but basically we go
1360 ;; through the time units for years, weeks, etc,
1361 ;; and divide things to see whether that results
1362 ;; in positive answers.
1365 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1366 ;; The (remaining) seconds are too few to
1367 ;; be divided into this time unit.
1369 ;; It's big enough, so we output it.
1370 (setq sec (- sec (* num (cdr unit))))
1372 (concat (if prev ", " "") (int-to-string
1374 " " (symbol-name (car unit))
1375 (if (> num 1) "s" ""))
1377 article-time-units "")
1378 ;; If dates are odd, then it might appear like the
1379 ;; article was sent in the future.
1382 " in the future"))))))
1384 (error "Unknown conversion type: %s" type))))
1386 (defun article-date-local (&optional highlight)
1387 "Convert the current article date to the local timezone."
1388 (interactive (list t))
1389 (article-date-ut 'local highlight))
1391 (defun article-date-original (&optional highlight)
1392 "Convert the current article date to what it was originally.
1393 This is only useful if you have used some other date conversion
1394 function and want to see what the date was before converting."
1395 (interactive (list t))
1396 (article-date-ut 'original highlight))
1398 (defun article-date-lapsed (&optional highlight)
1399 "Convert the current article date to time lapsed since it was sent."
1400 (interactive (list t))
1401 (article-date-ut 'lapsed highlight))
1403 (defun article-update-date-lapsed ()
1404 "Function to be run from a timer to update the lapsed time line."
1405 (let (deactivate-mark)
1408 (when (gnus-buffer-live-p gnus-article-buffer)
1409 (set-buffer gnus-article-buffer)
1410 (goto-char (point-min))
1411 (when (re-search-forward "^X-Sent:" nil t)
1412 (article-date-lapsed t)))))))
1414 (defun gnus-start-date-timer (&optional n)
1415 "Start a timer to update the X-Sent header in the article buffers.
1416 The numerical prefix says how frequently (in seconds) the function
1421 (gnus-stop-date-timer)
1422 (setq article-lapsed-timer
1423 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1425 (defun gnus-stop-date-timer ()
1426 "Stop the X-Sent timer."
1428 (when article-lapsed-timer
1429 (nnheader-cancel-timer article-lapsed-timer)
1430 (setq article-lapsed-timer nil)))
1432 (defun article-date-user (&optional highlight)
1433 "Convert the current article date to the user-defined format.
1434 This format is defined by the `gnus-article-time-format' variable."
1435 (interactive (list t))
1436 (article-date-ut 'user highlight))
1438 (defun article-date-iso8601 (&optional highlight)
1439 "Convert the current article date to ISO8601."
1440 (interactive (list t))
1441 (article-date-ut 'iso8601 highlight))
1443 (defun article-show-all ()
1444 "Show all hidden text in the article buffer."
1447 (let ((buffer-read-only nil))
1448 (gnus-article-unhide-text (point-min) (point-max)))))
1450 (defun article-emphasize (&optional arg)
1451 "Emphasize text according to `gnus-emphasis-alist'."
1452 (interactive (gnus-article-hidden-arg))
1453 (unless (gnus-article-check-hidden-text 'emphasis arg)
1455 (let ((alist gnus-emphasis-alist)
1456 (buffer-read-only nil)
1457 (props (append '(article-type emphasis)
1458 gnus-hidden-properties))
1459 regexp elem beg invisible visible face)
1460 (goto-char (point-min))
1461 (search-forward "\n\n" nil t)
1463 (while (setq elem (pop alist))
1465 (setq regexp (car elem)
1466 invisible (nth 1 elem)
1467 visible (nth 2 elem)
1469 (while (re-search-forward regexp nil t)
1470 (when (and (match-beginning visible) (match-beginning invisible))
1471 (gnus-article-hide-text
1472 (match-beginning invisible) (match-end invisible) props)
1473 (gnus-article-unhide-text-type
1474 (match-beginning visible) (match-end visible) 'emphasis)
1475 (gnus-put-text-property-excluding-newlines
1476 (match-beginning visible) (match-end visible) 'face face)
1477 (goto-char (match-end invisible)))))))))
1479 (defvar gnus-summary-article-menu)
1480 (defvar gnus-summary-post-menu)
1482 ;;; Saving functions.
1484 (defun gnus-article-save (save-buffer file &optional num)
1485 "Save the currently selected article."
1486 (unless gnus-save-all-headers
1487 ;; Remove headers according to `gnus-saved-headers'.
1488 (let ((gnus-visible-headers
1489 (or gnus-saved-headers gnus-visible-headers))
1490 (gnus-article-buffer save-buffer))
1492 (set-buffer save-buffer)
1493 (article-hide-headers 1 t))))
1494 (save-window-excursion
1495 (if (not gnus-default-article-saver)
1496 (error "No default saver is defined")
1497 ;; !!! Magic! The saving functions all save
1498 ;; `gnus-original-article-buffer' (or so they think), but we
1499 ;; bind that variable to our save-buffer.
1500 (set-buffer gnus-article-buffer)
1501 (let* ((gnus-save-article-buffer save-buffer)
1504 ((not gnus-prompt-before-saving) 'default)
1505 ((eq gnus-prompt-before-saving 'always) nil)
1507 (gnus-number-of-articles-to-be-saved
1508 (when (eq gnus-prompt-before-saving t)
1510 (set-buffer gnus-article-current-summary)
1511 (funcall gnus-default-article-saver filename)))))
1513 (defun gnus-read-save-file-name (prompt &optional filename
1514 function group headers variable)
1516 (funcall function group headers (symbol-value variable)))
1521 ((eq filename 'default)
1527 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1530 (if (and gnus-number-of-articles-to-be-saved
1531 (> gnus-number-of-articles-to-be-saved 1))
1532 (format "these %d articles"
1533 gnus-number-of-articles-to-be-saved)
1536 ;; Let the split methods have their say.
1538 ;; No split name was found.
1541 (concat prompt " (default "
1542 (file-name-nondirectory default-name) ") ")
1543 (file-name-directory default-name)
1545 ;; A single group name is returned.
1546 ((stringp split-name)
1548 (funcall function split-name headers
1549 (symbol-value variable)))
1551 (concat prompt " (default "
1552 (file-name-nondirectory default-name) ") ")
1553 (file-name-directory default-name)
1555 ;; A single split name was found
1556 ((= 1 (length split-name))
1557 (let* ((name (expand-file-name
1558 (car split-name) gnus-article-save-directory))
1559 (dir (cond ((file-directory-p name)
1560 (file-name-as-directory name))
1561 ((file-exists-p name) name)
1562 (t gnus-article-save-directory))))
1564 (concat prompt " (default " name ") ")
1566 ;; A list of splits was found.
1568 (setq split-name (nreverse split-name))
1570 (let ((file-name-history
1571 (nconc split-name file-name-history)))
1575 (concat prompt " (`M-p' for defaults) ")
1576 gnus-article-save-directory
1578 gnus-article-save-directory)))
1579 (car (push result file-name-history)))))))
1580 ;; Create the directory.
1581 (gnus-make-directory (file-name-directory file))
1582 ;; If we have read a directory, we append the default file name.
1583 (when (file-directory-p file)
1584 (setq file (concat (file-name-as-directory file)
1585 (file-name-nondirectory default-name))))
1586 ;; Possibly translate some characters.
1587 (nnheader-translate-file-chars file)))))
1588 (gnus-make-directory (file-name-directory result))
1589 (set variable result)))
1591 (defun gnus-article-archive-name (group)
1592 "Return the first instance of an \"Archive-name\" in the current buffer."
1593 (let ((case-fold-search t))
1594 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1595 (nnheader-concat gnus-article-save-directory
1596 (match-string 1)))))
1598 (defun gnus-article-nndoc-name (group)
1599 "If GROUP is an nndoc group, return the name of the parent group."
1600 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1601 (gnus-group-get-parameter group 'save-article-group)))
1603 (defun gnus-summary-save-in-rmail (&optional filename)
1604 "Append this article to Rmail file.
1605 Optional argument FILENAME specifies file name.
1606 Directory to save to is default to `gnus-article-save-directory'."
1607 (setq filename (gnus-read-save-file-name
1608 "Save %s in rmail file:" filename
1609 gnus-rmail-save-name gnus-newsgroup-name
1610 gnus-current-headers 'gnus-newsgroup-last-rmail))
1611 (gnus-eval-in-buffer-window gnus-save-article-buffer
1615 (gnus-output-to-rmail filename))))
1618 (defun gnus-summary-save-in-mail (&optional filename)
1619 "Append this article to Unix mail file.
1620 Optional argument FILENAME specifies file name.
1621 Directory to save to is default to `gnus-article-save-directory'."
1622 (setq filename (gnus-read-save-file-name
1623 "Save %s in Unix mail file:" filename
1624 gnus-mail-save-name gnus-newsgroup-name
1625 gnus-current-headers 'gnus-newsgroup-last-mail))
1626 (gnus-eval-in-buffer-window gnus-save-article-buffer
1630 (if (and (file-readable-p filename)
1631 (mail-file-babyl-p filename))
1632 (gnus-output-to-rmail filename t)
1633 (gnus-output-to-mail filename)))))
1636 (defun gnus-summary-save-in-file (&optional filename overwrite)
1637 "Append this article to file.
1638 Optional argument FILENAME specifies file name.
1639 Directory to save to is default to `gnus-article-save-directory'."
1640 (setq filename (gnus-read-save-file-name
1641 "Save %s in file:" filename
1642 gnus-file-save-name gnus-newsgroup-name
1643 gnus-current-headers 'gnus-newsgroup-last-file))
1644 (gnus-eval-in-buffer-window gnus-save-article-buffer
1648 (when (and overwrite
1649 (file-exists-p filename))
1650 (delete-file filename))
1651 (gnus-output-to-file filename))))
1654 (defun gnus-summary-write-to-file (&optional filename)
1655 "Write this article to a file.
1656 Optional argument FILENAME specifies file name.
1657 The directory to save in defaults to `gnus-article-save-directory'."
1658 (gnus-summary-save-in-file nil t))
1660 (defun gnus-summary-save-body-in-file (&optional filename)
1661 "Append this article body to a file.
1662 Optional argument FILENAME specifies file name.
1663 The directory to save in defaults to `gnus-article-save-directory'."
1664 (setq filename (gnus-read-save-file-name
1665 "Save %s body in file:" filename
1666 gnus-file-save-name gnus-newsgroup-name
1667 gnus-current-headers 'gnus-newsgroup-last-file))
1668 (gnus-eval-in-buffer-window gnus-save-article-buffer
1672 (goto-char (point-min))
1673 (when (search-forward "\n\n" nil t)
1674 (narrow-to-region (point) (point-max)))
1675 (gnus-output-to-file filename))))
1678 (defun gnus-summary-save-in-pipe (&optional command)
1679 "Pipe this article to subprocess."
1681 (cond ((eq command 'default)
1682 gnus-last-shell-command)
1686 "Shell command on %s: "
1687 (if (and gnus-number-of-articles-to-be-saved
1688 (> gnus-number-of-articles-to-be-saved 1))
1689 (format "these %d articles"
1690 gnus-number-of-articles-to-be-saved)
1692 gnus-last-shell-command))))
1693 (when (string-equal command "")
1694 (setq command gnus-last-shell-command))
1695 (gnus-eval-in-buffer-window gnus-article-buffer
1698 (shell-command-on-region (point-min) (point-max) command nil)))
1699 (setq gnus-last-shell-command command))
1701 ;;; Article file names when saving.
1703 (defun gnus-capitalize-newsgroup (newsgroup)
1704 "Capitalize NEWSGROUP name."
1705 (when (not (zerop (length newsgroup)))
1706 (concat (char-to-string (upcase (aref newsgroup 0)))
1707 (substring newsgroup 1))))
1709 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1710 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1711 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1712 Otherwise, it is like ~/News/news/group/num."
1715 (concat (if (gnus-use-long-file-name 'not-save)
1716 (gnus-capitalize-newsgroup newsgroup)
1717 (gnus-newsgroup-directory-form newsgroup))
1718 "/" (int-to-string (mail-header-number headers)))
1719 gnus-article-save-directory)))
1721 (string-equal (file-name-directory default)
1722 (file-name-directory last-file))
1723 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1725 (or last-file default))))
1727 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1728 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1729 If variable `gnus-use-long-file-name' is non-nil, it is
1730 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1733 (concat (if (gnus-use-long-file-name 'not-save)
1735 (gnus-newsgroup-directory-form newsgroup))
1736 "/" (int-to-string (mail-header-number headers)))
1737 gnus-article-save-directory)))
1739 (string-equal (file-name-directory default)
1740 (file-name-directory last-file))
1741 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1743 (or last-file default))))
1745 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1746 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1747 If variable `gnus-use-long-file-name' is non-nil, it is
1748 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1751 (if (gnus-use-long-file-name 'not-save)
1752 (gnus-capitalize-newsgroup newsgroup)
1753 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1754 gnus-article-save-directory)))
1756 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1757 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1758 If variable `gnus-use-long-file-name' is non-nil, it is
1759 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1762 (if (gnus-use-long-file-name 'not-save)
1764 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1765 gnus-article-save-directory)))
1772 (setq afunc (car func)
1775 gfunc (intern (format "gnus-%s" func))))
1777 (if (not (fboundp afunc))
1779 `(lambda (&optional interactive &rest args)
1780 ,(documentation afunc t)
1781 (interactive (list t))
1783 (set-buffer gnus-article-buffer)
1785 (call-interactively ',afunc)
1786 (apply ',afunc args))))))))
1787 '(article-hide-headers
1788 article-hide-boring-headers
1789 article-treat-overstrike
1790 (article-fill . gnus-article-word-wrap)
1792 article-display-x-face
1795 article-hide-signature
1796 article-remove-trailing-blank-lines
1797 article-strip-leading-blank-lines
1798 article-strip-multiple-blank-lines
1799 article-strip-leading-space
1800 article-strip-blank-lines
1801 article-strip-all-blank-lines
1803 article-date-iso8601
1804 article-date-original
1809 article-treat-dumbquotes
1810 (article-show-all . gnus-article-show-all-headers))))
1813 ;;; Gnus article mode
1816 (put 'gnus-article-mode 'mode-class 'special)
1818 (gnus-define-keys gnus-article-mode-map
1819 " " gnus-article-goto-next-page
1820 "\177" gnus-article-goto-prev-page
1821 [delete] gnus-article-goto-prev-page
1822 "\C-c^" gnus-article-refer-article
1823 "h" gnus-article-show-summary
1824 "s" gnus-article-show-summary
1825 "\C-c\C-m" gnus-article-mail
1826 "?" gnus-article-describe-briefly
1827 gnus-mouse-2 gnus-article-push-button
1828 "\r" gnus-article-press-button
1829 "\t" gnus-article-next-button
1830 "\M-\t" gnus-article-prev-button
1831 "e" gnus-article-edit
1832 "<" beginning-of-buffer
1834 "\C-c\C-i" gnus-info-find-node
1837 "\C-d" gnus-article-read-summary-keys
1838 "\M-*" gnus-article-read-summary-keys
1839 "\M-#" gnus-article-read-summary-keys
1840 "\M-^" gnus-article-read-summary-keys
1841 "\M-g" gnus-article-read-summary-keys)
1843 (substitute-key-definition
1844 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1846 (defun gnus-article-make-menu-bar ()
1847 (gnus-turn-off-edit-menu 'article)
1848 (unless (boundp 'gnus-article-article-menu)
1850 gnus-article-article-menu gnus-article-mode-map ""
1852 ["Scroll forwards" gnus-article-goto-next-page t]
1853 ["Scroll backwards" gnus-article-goto-prev-page t]
1854 ["Show summary" gnus-article-show-summary t]
1855 ["Fetch Message-ID at point" gnus-article-refer-article t]
1856 ["Mail to address at point" gnus-article-mail t]
1857 ["Send a bug report" gnus-bug t]))
1860 gnus-article-treatment-menu gnus-article-mode-map ""
1862 ["Hide headers" gnus-article-hide-headers t]
1863 ["Hide signature" gnus-article-hide-signature t]
1864 ["Hide citation" gnus-article-hide-citation t]
1865 ["Treat overstrike" gnus-article-treat-overstrike t]
1866 ["Remove carriage return" gnus-article-remove-cr t]
1869 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1871 (when (boundp 'gnus-summary-post-menu)
1872 (define-key gnus-article-mode-map [menu-bar post]
1873 (cons "Post" gnus-summary-post-menu)))
1875 (gnus-run-hooks 'gnus-article-menu-hook)))
1877 (defun gnus-article-mode ()
1878 "Major mode for displaying an article.
1880 All normal editing commands are switched off.
1882 The following commands are available in addition to all summary mode
1884 \\<gnus-article-mode-map>
1885 \\[gnus-article-next-page]\t Scroll the article one page forwards
1886 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1887 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1888 \\[gnus-article-show-summary]\t Display the summary buffer
1889 \\[gnus-article-mail]\t Send a reply to the address near point
1890 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1891 \\[gnus-info-find-node]\t Go to the Gnus info node"
1893 (when (gnus-visual-p 'article-menu 'menu)
1894 (gnus-article-make-menu-bar))
1895 (gnus-simplify-mode-line)
1896 (setq mode-name "Article")
1897 (setq major-mode 'gnus-article-mode)
1898 (make-local-variable 'minor-mode-alist)
1899 (unless (assq 'gnus-show-mime minor-mode-alist)
1900 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1901 (use-local-map gnus-article-mode-map)
1902 (gnus-update-format-specifications nil 'article-mode)
1903 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1904 (make-local-variable 'gnus-page-broken)
1905 (make-local-variable 'gnus-button-marker-list)
1906 (make-local-variable 'gnus-article-current-summary)
1907 (gnus-set-default-directory)
1908 (buffer-disable-undo (current-buffer))
1909 (setq buffer-read-only t)
1910 (set-syntax-table gnus-article-mode-syntax-table)
1911 (gnus-run-hooks 'gnus-article-mode-hook))
1913 (defun gnus-article-setup-buffer ()
1914 "Initialize the article buffer."
1915 (let* ((name (if gnus-single-article-buffer "*Article*"
1916 (concat "*Article " gnus-newsgroup-name "*")))
1918 (progn (string-match "\\*Article" name)
1919 (concat " *Original Article"
1920 (substring name (match-end 0))))))
1921 (setq gnus-article-buffer name)
1922 (setq gnus-original-article-buffer original)
1923 ;; This might be a variable local to the summary buffer.
1924 (unless gnus-single-article-buffer
1926 (set-buffer gnus-summary-buffer)
1927 (setq gnus-article-buffer name)
1928 (setq gnus-original-article-buffer original)
1929 (gnus-set-global-variables)))
1930 ;; Init original article buffer.
1932 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1933 (buffer-disable-undo (current-buffer))
1934 (setq major-mode 'gnus-original-article-mode)
1935 (make-local-variable 'gnus-original-article))
1936 (if (get-buffer name)
1939 (buffer-disable-undo (current-buffer))
1940 (setq buffer-read-only t)
1941 (unless (eq major-mode 'gnus-article-mode)
1942 (gnus-article-mode))
1945 (set-buffer (gnus-get-buffer-create name))
1947 (make-local-variable 'gnus-summary-buffer)
1948 (current-buffer)))))
1950 ;; Set article window start at LINE, where LINE is the number of lines
1951 ;; from the head of the article.
1952 (defun gnus-article-set-window-start (&optional line)
1954 (get-buffer-window gnus-article-buffer t)
1956 (set-buffer gnus-article-buffer)
1957 (goto-char (point-min))
1960 (gnus-message 6 "Moved to bookmark")
1961 (search-forward "\n\n" nil t)
1965 ;;; @@ article filters
1968 (defun gnus-article-display-mime-message ()
1969 "Article display method for MIME message."
1970 ;; called from `gnus-original-article-buffer'.
1971 (let ((default-mime-charset (save-excursion
1972 (set-buffer gnus-summary-buffer)
1973 default-mime-charset)))
1974 (mime-display-message mime-message-structure
1975 gnus-article-buffer nil gnus-article-mode-map))
1976 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
1977 (make-local-variable 'mime-button-mother-dispatcher)
1978 (setq mime-button-mother-dispatcher
1979 (function gnus-article-push-button))
1980 (run-hooks 'gnus-mime-article-prepare-hook))
1982 (defun gnus-article-display-traditional-message ()
1983 "Article display method for traditional message."
1984 (set-buffer gnus-article-buffer)
1985 (let (buffer-read-only)
1987 (insert-buffer-substring gnus-original-article-buffer)))
1989 (defun gnus-article-display-message-with-encoded-word ()
1990 "Article display method for message with encoded-words."
1991 (let ((charset (save-excursion
1992 (set-buffer gnus-summary-buffer)
1993 default-mime-charset)))
1994 (gnus-article-display-traditional-message)
1995 (let (buffer-read-only)
1996 (eword-decode-header charset)
1997 (goto-char (point-min))
1998 (if (search-forward "\n\n" nil t)
1999 (decode-mime-charset-region (match-end 0) (point-max) charset)))
2000 (mime-maybe-hide-echo-buffer))
2001 (gnus-run-hooks 'gnus-mime-article-prepare-hook))
2003 (defun gnus-article-make-full-mail-header (&optional number charset)
2004 "Create a new mail header structure in a raw article buffer."
2005 (unless (and number charset)
2006 (save-current-buffer
2007 (set-buffer gnus-summary-buffer)
2009 (setq number (or (cdr gnus-article-current) 0)))
2011 (setq charset (or default-mime-charset 'x-ctext)))))
2012 (goto-char (point-min))
2013 (let ((header-end (if (search-forward "\n\n" nil t)
2015 (goto-char (point-max))))
2016 (chars (- (point-max) (point)))
2017 (lines (count-lines (point) (point-max)))
2018 (default-mime-charset charset)
2020 (narrow-to-region (point-min) header-end)
2021 (setq xref (std11-fetch-field "xref"))
2023 (make-full-mail-header
2025 (std11-fetch-field "subject")
2026 (std11-fetch-field "from")
2027 (std11-fetch-field "date")
2028 (std11-fetch-field "message-id")
2029 (std11-fetch-field "references")
2032 (when xref (concat "Xref: " xref)))
2035 (defun gnus-article-prepare (article &optional all-headers header)
2036 "Prepare ARTICLE in article mode buffer.
2037 ARTICLE should either be an article number or a Message-ID.
2038 If ARTICLE is an id, HEADER should be the article headers.
2039 If ALL-HEADERS is non-nil, no headers are hidden."
2041 ;; Make sure we start in a summary buffer.
2042 (unless (eq major-mode 'gnus-summary-mode)
2043 (set-buffer gnus-summary-buffer))
2044 (setq gnus-summary-buffer (current-buffer))
2045 (let* ((gnus-article (if header (mail-header-number header) article))
2046 (summary-buffer (current-buffer))
2047 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2048 (group gnus-newsgroup-name)
2051 (gnus-article-setup-buffer)
2052 (set-buffer gnus-original-article-buffer)
2053 ;; Deactivate active regions.
2054 (when (and (boundp 'transient-mark-mode)
2055 transient-mark-mode)
2056 (setq mark-active nil))
2057 (if (not (setq result (let ((buffer-read-only nil))
2058 (gnus-request-article-this-buffer
2060 ;; There is no such article.
2062 (when (and (numberp article)
2063 (not (memq article gnus-newsgroup-sparse)))
2064 (setq gnus-article-current
2065 (cons gnus-newsgroup-name article))
2066 (set-buffer gnus-summary-buffer)
2067 (setq gnus-current-article article)
2068 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2070 (gnus-summary-set-agent-mark article)
2071 (message "Message marked for downloading"))
2072 (gnus-summary-mark-article article gnus-canceled-mark)
2073 (unless (memq article gnus-newsgroup-sparse)
2075 "No such article (may have expired or been canceled)")))))
2076 (if (or (eq result 'pseudo)
2077 (eq result 'nneething))
2080 (set-buffer summary-buffer)
2081 (push article gnus-newsgroup-history)
2082 (setq gnus-last-article gnus-current-article
2083 gnus-current-article 0
2084 gnus-current-headers nil
2085 gnus-article-current nil)
2086 (if (eq result 'nneething)
2087 (gnus-configure-windows 'summary)
2088 (gnus-configure-windows 'article))
2089 (gnus-set-global-variables))
2090 (gnus-set-mode-line 'article))
2091 ;; The result from the `request' was an actual article -
2092 ;; or at least some text that is now displayed in the
2094 (when (and (numberp article)
2095 (not (eq article gnus-current-article)))
2096 ;; Seems like a new article has been selected.
2097 ;; `gnus-current-article' must be an article number.
2099 (set-buffer summary-buffer)
2100 (push article gnus-newsgroup-history)
2101 (setq gnus-last-article gnus-current-article
2102 gnus-current-article article
2103 gnus-current-headers
2104 (gnus-summary-article-header gnus-current-article)
2105 gnus-article-current
2106 (cons gnus-newsgroup-name gnus-current-article))
2107 (unless (vectorp gnus-current-headers)
2108 (setq gnus-current-headers nil))
2109 (gnus-summary-goto-subject gnus-current-article)
2110 (when (gnus-summary-show-thread)
2111 ;; If the summary buffer really was folded, the
2112 ;; previous goto may not actually have gone to
2113 ;; the right article, but the thread root instead.
2115 (gnus-summary-goto-subject gnus-current-article))
2116 (gnus-run-hooks 'gnus-mark-article-hook)
2117 (gnus-set-mode-line 'summary)
2118 (when (gnus-visual-p 'article-highlight 'highlight)
2119 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2120 ;; Set the global newsgroup variables here.
2121 ;; Suggested by Jim Sisolak
2122 ;; <sisolak@trans4.neep.wisc.edu>.
2123 (gnus-set-global-variables)
2124 (setq gnus-have-all-headers
2125 (or all-headers gnus-show-all-headers))))
2126 (when (or (numberp article)
2128 (gnus-article-prepare-display)
2130 (goto-char (point-min))
2131 (setq gnus-page-broken
2132 (when gnus-break-pages
2133 (gnus-narrow-to-page)
2135 (gnus-set-mode-line 'article)
2136 (gnus-configure-windows 'article)
2137 (goto-char (point-min))
2138 (search-forward "\n\n" nil t)
2139 (set-window-point (get-buffer-window (current-buffer)) (point))
2142 (defun gnus-article-prepare-display ()
2143 "Make the current buffer look like a nice article."
2148 (if (or (not gnus-strict-mime)
2149 (mime-fetch-field "MIME-Version"))
2150 gnus-article-display-method-for-mime
2151 gnus-article-display-method-for-encoded-word))
2152 gnus-article-display-method-for-traditional)))
2153 (gnus-run-hooks 'gnus-tmp-internal-hook)
2154 (gnus-run-hooks 'gnus-article-prepare-hook)
2157 ;; Associate this article with the current summary buffer.
2158 (setq gnus-article-current-summary (current-buffer))
2159 ;; Perform the article display hooks.
2160 (gnus-run-hooks 'gnus-article-display-hook)))
2162 (defun gnus-article-wash-status ()
2163 "Return a string which display status of article washing."
2165 (set-buffer gnus-article-buffer)
2166 (let ((cite (gnus-article-hidden-text-p 'cite))
2167 (headers (gnus-article-hidden-text-p 'headers))
2168 (boring (gnus-article-hidden-text-p 'boring-headers))
2169 (pgp (gnus-article-hidden-text-p 'pgp))
2170 (pem (gnus-article-hidden-text-p 'pem))
2171 (signature (gnus-article-hidden-text-p 'signature))
2172 (overstrike (gnus-article-hidden-text-p 'overstrike))
2173 (emphasis (gnus-article-hidden-text-p 'emphasis))
2174 (mime gnus-show-mime))
2175 (format "%c%c%c%c%c%c%c"
2177 (if (or headers boring) ?h ? )
2178 (if (or pgp pem) ?p ? )
2179 (if signature ?s ? )
2180 (if overstrike ?o ? )
2182 (if emphasis ?e ? )))))
2184 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2186 (defun gnus-article-maybe-hide-headers ()
2187 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2188 Provided for backwards compatibility."
2189 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2191 (gnus-article-hide-headers)))
2195 (defun gnus-output-to-file (file-name)
2196 "Append the current article to a file named FILE-NAME."
2197 (let ((artbuf (current-buffer)))
2198 (nnheader-temp-write nil
2199 (insert-buffer-substring artbuf)
2200 ;; Append newline at end of the buffer as separator, and then
2202 (goto-char (point-max))
2204 (append-to-file (point-min) (point-max) file-name)
2207 (defun gnus-narrow-to-page (&optional arg)
2208 "Narrow the article buffer to a page.
2209 If given a numerical ARG, move forward ARG pages."
2211 (setq arg (if arg (prefix-numeric-value arg) 0))
2213 (set-buffer gnus-article-buffer)
2214 (goto-char (point-min))
2216 ;; Remove any old next/prev buttons.
2217 (when (gnus-visual-p 'page-marker)
2218 (let ((buffer-read-only nil))
2219 (gnus-remove-text-with-property 'gnus-prev)
2220 (gnus-remove-text-with-property 'gnus-next)))
2223 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2225 (re-search-forward page-delimiter nil 'move arg)))
2226 (goto-char (match-end 0)))
2229 (if (re-search-forward page-delimiter nil 'move)
2232 (when (and (gnus-visual-p 'page-marker)
2233 (not (= (point-min) 1)))
2235 (goto-char (point-min))
2236 (gnus-insert-prev-page-button)))
2237 (when (and (gnus-visual-p 'page-marker)
2238 (< (+ (point-max) 2) (buffer-size)))
2240 (goto-char (point-max))
2241 (gnus-insert-next-page-button)))))
2243 ;; Article mode commands
2245 (defun gnus-article-goto-next-page ()
2246 "Show the next page of the article."
2248 (when (gnus-article-next-page)
2249 (goto-char (point-min))
2250 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2252 (defun gnus-article-goto-prev-page ()
2253 "Show the next page of the article."
2255 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2256 (gnus-article-prev-page nil)))
2258 (defun gnus-article-next-page (&optional lines)
2259 "Show the next page of the current article.
2260 If end of article, return non-nil. Otherwise return nil.
2261 Argument LINES specifies lines to be scrolled up."
2263 (move-to-window-line -1)
2266 (and (pos-visible-in-window-p) ;Not continuation line.
2268 ;; Nothing in this page.
2269 (if (or (not gnus-page-broken)
2272 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2274 (gnus-narrow-to-page 1) ;Go to next page.
2276 ;; More in this page.
2277 (let ((scroll-in-place nil))
2281 ;; Long lines may cause an end-of-buffer error.
2282 (goto-char (point-max)))))
2283 (move-to-window-line 0)
2286 (defun gnus-article-prev-page (&optional lines)
2287 "Show previous page of current article.
2288 Argument LINES specifies lines to be scrolled down."
2290 (move-to-window-line 0)
2291 (if (and gnus-page-broken
2293 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2295 (gnus-narrow-to-page -1) ;Go to previous page.
2296 (goto-char (point-max))
2298 (let ((scroll-in-place nil))
2302 (beginning-of-buffer
2303 (goto-char (point-min))))
2304 (move-to-window-line 0)))))
2306 (defun gnus-article-refer-article ()
2307 "Read article specified by message-id around point."
2309 (let ((point (point)))
2310 (search-forward ">" nil t) ;Move point to end of "<....>".
2311 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2312 (let ((message-id (match-string 1)))
2314 (set-buffer gnus-summary-buffer)
2315 (gnus-summary-refer-article message-id))
2317 (error "No references around point"))))
2319 (defun gnus-article-show-summary ()
2320 "Reconfigure windows to show summary buffer."
2322 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2323 (error "There is no summary buffer for this article buffer")
2324 (gnus-article-set-globals)
2325 (gnus-configure-windows 'article)
2326 (gnus-summary-goto-subject gnus-current-article)
2327 (gnus-summary-position-point)))
2329 (defun gnus-article-describe-briefly ()
2330 "Describe article mode commands briefly."
2333 (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")))
2335 (defun gnus-article-summary-command ()
2336 "Execute the last keystroke in the summary buffer."
2338 (let ((obuf (current-buffer))
2339 (owin (current-window-configuration))
2341 (switch-to-buffer gnus-article-current-summary 'norecord)
2342 (setq func (lookup-key (current-local-map) (this-command-keys)))
2343 (call-interactively func)
2345 (set-window-configuration owin)
2346 (set-window-point (get-buffer-window (current-buffer)) (point))))
2348 (defun gnus-article-summary-command-nosave ()
2349 "Execute the last keystroke in the summary buffer."
2352 (pop-to-buffer gnus-article-current-summary 'norecord)
2353 (setq func (lookup-key (current-local-map) (this-command-keys)))
2354 (call-interactively func)))
2356 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2357 "Read a summary buffer key sequence and execute it from the article buffer."
2360 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2361 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2362 "=" "^" "\M-^" "|"))
2368 '("n" "Gn" "p" "Gp"))
2371 (set-buffer gnus-article-current-summary)
2372 (let (gnus-pick-mode)
2373 (push (or key last-command-event) unread-command-events)
2374 (setq keys (read-key-sequence nil))))
2377 (if (or (member keys nosaves)
2378 (member keys nosave-but-article)
2379 (member keys nosave-in-article))
2381 (save-window-excursion
2382 (pop-to-buffer gnus-article-current-summary 'norecord)
2383 ;; We disable the pick minor mode commands.
2384 (let (gnus-pick-mode)
2385 (setq func (lookup-key (current-local-map) keys))))
2388 (unless (member keys nosave-in-article)
2389 (set-buffer gnus-article-current-summary))
2390 (call-interactively func)
2391 (setq new-sum-point (point)))
2392 (when (member keys nosave-but-article)
2393 (pop-to-buffer gnus-article-buffer 'norecord)))
2394 ;; These commands should restore window configuration.
2395 (let ((obuf (current-buffer))
2396 (owin (current-window-configuration))
2398 (summary gnus-article-current-summary)
2399 func in-buffer selected)
2400 (if not-restore-window
2401 (pop-to-buffer summary 'norecord)
2402 (switch-to-buffer summary 'norecord))
2403 (setq in-buffer (current-buffer))
2404 ;; We disable the pick minor mode commands.
2405 (if (setq func (let (gnus-pick-mode)
2406 (lookup-key (current-local-map) keys)))
2408 (call-interactively func)
2409 (setq new-sum-point (point)))
2411 (when (eq in-buffer (current-buffer))
2412 (setq selected (gnus-summary-select-article))
2414 (unless not-restore-window
2415 (set-window-configuration owin))
2416 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2417 (set-window-point (get-buffer-window (current-buffer))
2419 (let ((win (get-buffer-window gnus-article-current-summary)))
2421 (set-window-point win new-sum-point))))))))
2423 (defun gnus-article-hide (&optional arg force)
2424 "Hide all the gruft in the current article.
2425 This means that PGP stuff, signatures, cited text and (some)
2426 headers will be hidden.
2427 If given a prefix, show the hidden text instead."
2428 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2429 (gnus-article-hide-headers arg)
2430 (gnus-article-hide-pgp arg)
2431 (gnus-article-hide-citation-maybe arg force)
2432 (gnus-article-hide-signature arg))
2434 (defun gnus-article-maybe-highlight ()
2435 "Do some article highlighting if article highlighting is requested."
2436 (when (gnus-visual-p 'article-highlight 'highlight)
2437 (gnus-article-highlight-some)))
2439 (defun gnus-check-group-server ()
2440 ;; Make sure the connection to the server is alive.
2441 (unless (gnus-server-opened
2442 (gnus-find-method-for-group gnus-newsgroup-name))
2443 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2444 (gnus-request-group gnus-newsgroup-name t)))
2446 (defun gnus-request-article-this-buffer (article group)
2447 "Get an article and insert it into this buffer."
2448 (let (do-update-line sparse-header)
2452 (gnus-kill-all-overlays)
2453 (setq group (or group gnus-newsgroup-name))
2455 ;; Using `gnus-request-article' directly will insert the article into
2456 ;; `nntp-server-buffer' - so we'll save some time by not having to
2457 ;; copy it from the server buffer into the article buffer.
2459 ;; We only request an article by message-id when we do not have the
2460 ;; headers for it, so we'll have to get those.
2461 (when (stringp article)
2462 (let ((gnus-override-method gnus-refer-article-method))
2463 (gnus-read-header article)))
2465 ;; If the article number is negative, that means that this article
2466 ;; doesn't belong in this newsgroup (possibly), so we find its
2467 ;; message-id and request it by id instead of number.
2468 (when (and (numberp article)
2470 (get-buffer gnus-summary-buffer)
2471 (gnus-buffer-exists-p gnus-summary-buffer))
2473 (set-buffer gnus-summary-buffer)
2474 (let ((header (gnus-summary-article-header article)))
2477 ((memq article gnus-newsgroup-sparse)
2478 ;; This is a sparse gap article.
2479 (setq do-update-line article)
2480 (setq article (mail-header-id header))
2481 (let ((gnus-override-method gnus-refer-article-method))
2482 (setq sparse-header (gnus-read-header article)))
2483 (setq gnus-newsgroup-sparse
2484 (delq article gnus-newsgroup-sparse)))
2486 ;; It's a real article.
2487 (setq article (mail-header-id header)))
2489 ;; It is an extracted pseudo-article.
2490 (setq article 'pseudo)
2491 (gnus-request-pseudo-article header))))
2493 (let ((method (gnus-find-method-for-group
2494 gnus-newsgroup-name)))
2495 (when (and (eq (car method) 'nneething)
2498 (file-name-as-directory
2499 (or (cadr (assq 'nneething-address method))
2501 (mail-header-subject header))))
2502 (when (file-directory-p dir)
2503 (setq article 'nneething)
2504 (gnus-group-enter-directory dir))))))))
2507 ;; Refuse to select canceled articles.
2508 ((and (numberp article)
2510 (get-buffer gnus-summary-buffer)
2511 (gnus-buffer-exists-p gnus-summary-buffer)
2512 (eq (cdr (save-excursion
2513 (set-buffer gnus-summary-buffer)
2514 (assq article gnus-newsgroup-reads)))
2515 gnus-canceled-mark))
2517 ;; Check the backlog.
2518 ((and gnus-keep-backlog
2519 (gnus-backlog-request-article group article (current-buffer)))
2521 ;; Check asynchronous pre-fetch.
2522 ((gnus-async-request-fetched-article group article (current-buffer))
2523 (gnus-async-prefetch-next group article gnus-summary-buffer)
2524 (when (and (numberp article) gnus-keep-backlog)
2525 (gnus-backlog-enter-article group article (current-buffer)))
2528 ((and gnus-use-cache
2530 (gnus-cache-request-article article group))
2532 ;; Get the article and put into the article buffer.
2533 ((or (stringp article) (numberp article))
2534 (let ((gnus-override-method
2535 (and (stringp article) gnus-refer-article-method))
2536 (buffer-read-only nil))
2538 (gnus-kill-all-overlays)
2539 (gnus-check-group-server)
2540 (when (gnus-request-article article group (current-buffer))
2541 (when (numberp article)
2542 (gnus-async-prefetch-next group article gnus-summary-buffer)
2543 (when gnus-keep-backlog
2544 (gnus-backlog-enter-article
2545 group article (current-buffer))))
2550 ;; Associate this article with the current summary buffer.
2551 (setq gnus-article-current-summary gnus-summary-buffer)
2553 ;; Take the article from the original article buffer
2554 ;; and place it in the buffer it's supposed to be in.
2555 (when (and (get-buffer gnus-article-buffer)
2556 (equal (buffer-name (current-buffer))
2557 (buffer-name (get-buffer gnus-article-buffer))))
2559 (if (get-buffer gnus-original-article-buffer)
2560 (set-buffer gnus-original-article-buffer)
2561 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2562 (buffer-disable-undo (current-buffer))
2563 (setq major-mode 'gnus-original-article-mode)
2564 (setq buffer-read-only t))
2565 (let (buffer-read-only)
2567 (insert-buffer-substring gnus-article-buffer))
2568 (setq gnus-original-article (cons group article))))
2570 ;; Update sparse articles.
2571 (when (and do-update-line
2572 (or (numberp article)
2574 (let ((buf (current-buffer)))
2575 (set-buffer gnus-summary-buffer)
2576 (gnus-summary-update-article do-update-line sparse-header)
2577 (gnus-summary-goto-subject do-update-line nil t)
2578 (set-window-point (get-buffer-window (current-buffer) t)
2580 (set-buffer buf))))))
2586 (defcustom gnus-article-edit-mode-hook nil
2587 "Hook run in article edit mode buffers."
2588 :group 'gnus-article-various
2591 (defcustom gnus-article-edit-article-setup-function
2592 'gnus-article-mime-edit-article-setup
2593 "Function called to setup an editing article buffer."
2594 :group 'gnus-article-various
2597 (defvar gnus-article-edit-done-function nil)
2599 (defvar gnus-article-edit-mode-map nil)
2601 (unless gnus-article-edit-mode-map
2602 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2604 (gnus-define-keys gnus-article-edit-mode-map
2605 "\C-c\C-c" gnus-article-edit-done
2606 "\C-c\C-k" gnus-article-edit-exit)
2608 (gnus-define-keys (gnus-article-edit-wash-map
2609 "\C-c\C-w" gnus-article-edit-mode-map)
2610 "f" gnus-article-edit-full-stops))
2612 (defun gnus-article-edit-mode ()
2613 "Major mode for editing articles.
2614 This is an extended text-mode.
2616 \\{gnus-article-edit-mode-map}"
2618 (setq major-mode 'gnus-article-edit-mode)
2619 (setq mode-name "Article Edit")
2620 (use-local-map gnus-article-edit-mode-map)
2621 (make-local-variable 'gnus-article-edit-done-function)
2622 (make-local-variable 'gnus-prev-winconf)
2623 (setq buffer-read-only nil)
2624 (buffer-enable-undo)
2626 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2628 (defun gnus-article-edit (&optional force)
2629 "Edit the current article.
2630 This will have permanent effect only in mail groups.
2631 If FORCE is non-nil, allow editing of articles even in read-only
2634 (when (and (not force)
2635 (gnus-group-read-only-p))
2636 (error "The current newsgroup does not support article editing"))
2637 (gnus-article-date-original)
2638 (gnus-article-edit-article
2639 `(lambda (no-highlight)
2640 (gnus-summary-edit-article-done
2641 ,(or (mail-header-references gnus-current-headers) "")
2642 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2644 (defun gnus-article-edit-article (exit-func)
2645 "Start editing the contents of the current article buffer."
2646 (let ((winconf (current-window-configuration)))
2647 (set-buffer gnus-article-buffer)
2648 (gnus-article-edit-mode)
2649 (gnus-article-delete-text-of-type 'annotation)
2650 (gnus-set-text-properties (point-min) (point-max) nil)
2651 (gnus-configure-windows 'edit-article)
2652 (setq gnus-article-edit-done-function exit-func)
2653 (setq gnus-prev-winconf winconf)
2654 (when gnus-article-edit-article-setup-function
2655 (funcall gnus-article-edit-article-setup-function))
2656 (gnus-message 6 "C-c C-c to end edits")))
2658 (defun gnus-article-edit-done (&optional arg)
2659 "Update the article edits and exit."
2664 (goto-char (point-min))
2665 (when (search-forward "\n\n" nil 1)
2666 (let ((lines (count-lines (point) (point-max)))
2667 (length (- (point-max) (point)))
2668 (case-fold-search t)
2669 (body (copy-marker (point))))
2670 (goto-char (point-min))
2671 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2672 (delete-region (match-beginning 1) (match-end 1))
2673 (insert (number-to-string length)))
2674 (goto-char (point-min))
2675 (when (re-search-forward
2676 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2677 (delete-region (match-beginning 1) (match-end 1))
2678 (insert (number-to-string length)))
2679 (goto-char (point-min))
2680 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2681 (delete-region (match-beginning 1) (match-end 1))
2682 (insert (number-to-string lines)))))))
2683 (let ((func gnus-article-edit-done-function)
2684 (buf (current-buffer))
2685 (start (window-start)))
2686 (remove-hook 'gnus-article-mode-hook
2687 'gnus-article-mime-edit-article-unwind)
2688 (gnus-article-edit-exit)
2691 (let ((buffer-read-only nil))
2692 (funcall func arg)))
2694 (set-window-start (get-buffer-window buf) start)
2695 (set-window-point (get-buffer-window buf) (point))))
2697 (defun gnus-article-edit-exit ()
2698 "Exit the article editing without updating."
2700 ;; We remove all text props from the article buffer.
2701 (let ((buf (format "%s" (buffer-string)))
2702 (curbuf (current-buffer))
2704 (window-start (window-start)))
2707 (let ((winconf gnus-prev-winconf))
2709 ;; The cache and backlog have to be flushed somewhat.
2710 (when gnus-use-cache
2711 (gnus-cache-update-article
2712 (car gnus-article-current) (cdr gnus-article-current)))
2713 (when gnus-keep-backlog
2714 (gnus-backlog-remove-article
2715 (car gnus-article-current) (cdr gnus-article-current)))
2716 ;; Flush original article as well.
2718 (when (get-buffer gnus-original-article-buffer)
2719 (set-buffer gnus-original-article-buffer)
2720 (setq gnus-original-article nil)))
2721 (set-window-configuration winconf)
2722 ;; Tippy-toe some to make sure that point remains where it was.
2723 (let ((buf (current-buffer)))
2725 (set-window-start (get-buffer-window (current-buffer)) window-start)
2727 (set-buffer buf)))))
2729 (defun gnus-article-edit-full-stops ()
2730 "Interactively repair spacing at end of sentences."
2733 (goto-char (point-min))
2734 (search-forward-regexp "^$" nil t)
2735 (let ((case-fold-search nil))
2736 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2739 ;;; Article editing with MIME-Edit
2742 (defcustom gnus-article-mime-edit-article-setup-hook nil
2743 "Hook run after setting up a MIME editing article buffer."
2744 :group 'gnus-article-various
2747 (defun gnus-article-mime-edit-article-unwind ()
2748 "Unwind `gnus-article-buffer' if article editing was given up."
2749 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
2750 (when mime-edit-mode-flag
2751 (mime-edit-exit 'nomime 'no-error)
2753 (when (featurep 'font-lock)
2754 (setq font-lock-defaults nil)
2755 (font-lock-mode 0)))
2757 (defun gnus-article-mime-edit-article-setup ()
2758 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
2759 after replacing with the original article."
2760 (setq gnus-show-mime t)
2761 (setq gnus-article-edit-done-function
2762 `(lambda (&rest args)
2763 (when mime-edit-mode-flag
2766 (goto-char (point-min))
2767 (let (case-fold-search)
2768 (when (re-search-forward
2769 (format "^%s$" (regexp-quote mail-header-separator))
2771 (replace-match "")))
2772 (when (featurep 'font-lock)
2773 (setq font-lock-defaults nil)
2775 (apply ,gnus-article-edit-done-function args)
2776 (set-buffer gnus-original-article-buffer)
2778 (insert-buffer gnus-article-buffer)
2779 (setq gnus-current-headers (gnus-article-make-full-mail-header))
2780 (gnus-article-prepare-display)))
2781 (define-key (current-local-map) "\C-c\C-k" 'gnus-article-mime-edit-exit)
2783 (insert-buffer gnus-original-article-buffer)
2785 (when (featurep 'font-lock)
2786 (set (make-local-variable 'font-lock-defaults)
2787 '(message-font-lock-keywords t))
2788 (font-lock-set-defaults)
2789 (turn-on-font-lock))
2790 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
2791 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
2793 (defun gnus-article-mime-edit-exit ()
2794 "Exit the article MIME editing without updating."
2796 (let ((winconf gnus-prev-winconf)
2798 (when mime-edit-mode-flag
2801 (goto-char (point-min))
2802 (let (case-fold-search)
2803 (when (re-search-forward
2804 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
2805 (replace-match "")))
2806 (when (featurep 'font-lock)
2807 (setq font-lock-defaults nil)
2809 ;; We remove all text props from the article buffer.
2810 (setq buf (format "%s" (buffer-string)))
2811 (set-buffer (get-buffer-create gnus-original-article-buffer))
2814 (setq gnus-current-headers (gnus-article-make-full-mail-header))
2815 (gnus-article-prepare-display)
2816 (set-window-configuration winconf)))
2819 ;;; Article highlights
2822 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2824 ;;; Internal Variables:
2826 (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\\)"
2827 "Regular expression that matches URLs."
2828 :group 'gnus-article-buttons
2831 (defcustom gnus-button-alist
2832 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2833 gnus-button-message-id 2)
2834 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2835 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2837 gnus-button-fetch-group 4)
2838 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2839 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2840 t gnus-button-message-id 3)
2841 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2842 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2843 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2844 ;; This is how URLs _should_ be embedded in text...
2845 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2847 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2848 "*Alist of regexps matching buttons in article bodies.
2850 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2851 REGEXP: is the string matching text around the button,
2852 BUTTON: is the number of the regexp grouping actually matching the button,
2853 FORM: is a lisp expression which must eval to true for the button to
2855 CALLBACK: is the function to call when the user push this button, and each
2856 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2858 CALLBACK can also be a variable, in that case the value of that
2859 variable it the real callback function."
2860 :group 'gnus-article-buttons
2861 :type '(repeat (list regexp
2862 (integer :tag "Button")
2864 (function :tag "Callback")
2867 (integer :tag "Regexp group")))))
2869 (defcustom gnus-header-button-alist
2870 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2871 0 t gnus-button-message-id 0)
2872 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2873 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2874 0 t gnus-button-mailto 0)
2875 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2876 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2877 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2878 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2879 gnus-button-message-id 3))
2880 "*Alist of headers and regexps to match buttons in article heads.
2882 This alist is very similar to `gnus-button-alist', except that each
2883 alist has an additional HEADER element first in each entry:
2885 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2887 HEADER is a regexp to match a header. For a fuller explanation, see
2888 `gnus-button-alist'."
2889 :group 'gnus-article-buttons
2890 :group 'gnus-article-headers
2891 :type '(repeat (list (regexp :tag "Header")
2893 (integer :tag "Button")
2895 (function :tag "Callback")
2898 (integer :tag "Regexp group")))))
2900 (defvar gnus-button-regexp nil)
2901 (defvar gnus-button-marker-list nil)
2902 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2904 (defvar gnus-button-last nil)
2905 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2909 (defun gnus-article-push-button (event)
2910 "Check text under the mouse pointer for a callback function.
2911 If the text under the mouse pointer has a `gnus-callback' property,
2912 call it with the value of the `gnus-data' text property."
2914 (set-buffer (window-buffer (posn-window (event-start event))))
2915 (let* ((pos (posn-point (event-start event)))
2916 (data (get-text-property pos 'gnus-data))
2917 (fun (get-text-property pos 'gnus-callback)))
2920 (funcall fun data))))
2922 (defun gnus-article-press-button ()
2923 "Check text at point for a callback function.
2924 If the text at point has a `gnus-callback' property,
2925 call it with the value of the `gnus-data' text property."
2927 (let* ((data (get-text-property (point) 'gnus-data))
2928 (fun (get-text-property (point) 'gnus-callback)))
2930 (funcall fun data))))
2932 (defun gnus-article-prev-button (n)
2933 "Move point to N buttons backward.
2934 If N is negative, move forward instead."
2936 (gnus-article-next-button (- n)))
2938 (defun gnus-article-next-button (n)
2939 "Move point to N buttons forward.
2940 If N is negative, move backward instead."
2942 (let ((function (if (< n 0) 'previous-single-property-change
2943 'next-single-property-change))
2944 (inhibit-point-motion-hooks t)
2946 (limit (if (< n 0) (point-min) (point-max))))
2948 (while (and (not (= limit (point)))
2950 ;; Skip past the current button.
2951 (when (get-text-property (point) 'gnus-callback)
2952 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2953 ;; Go to the next (or previous) button.
2954 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2955 ;; Put point at the start of the button.
2956 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2957 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2958 ;; Skip past intangible buttons.
2959 (when (get-text-property (point) 'intangible)
2963 (gnus-message 5 "No more buttons"))
2966 (defun gnus-article-highlight (&optional force)
2967 "Highlight current article.
2968 This function calls `gnus-article-highlight-headers',
2969 `gnus-article-highlight-citation',
2970 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2971 do the highlighting. See the documentation for those functions."
2972 (interactive (list 'force))
2973 (gnus-article-highlight-headers)
2974 (gnus-article-highlight-citation force)
2975 (gnus-article-highlight-signature)
2976 (gnus-article-add-buttons force)
2977 (gnus-article-add-buttons-to-head))
2979 (defun gnus-article-highlight-some (&optional force)
2980 "Highlight current article.
2981 This function calls `gnus-article-highlight-headers',
2982 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2983 do the highlighting. See the documentation for those functions."
2984 (interactive (list 'force))
2985 (gnus-article-highlight-headers)
2986 (gnus-article-highlight-signature)
2987 (gnus-article-add-buttons))
2989 (defun gnus-article-highlight-headers ()
2990 "Highlight article headers as specified by `gnus-header-face-alist'."
2993 (set-buffer gnus-article-buffer)
2995 (let ((alist gnus-header-face-alist)
2996 (buffer-read-only nil)
2997 (case-fold-search t)
2998 (inhibit-point-motion-hooks t)
2999 entry regexp header-face field-face from hpoints fpoints)
3000 (message-narrow-to-head)
3001 (while (setq entry (pop alist))
3002 (goto-char (point-min))
3003 (setq regexp (concat "^\\("
3004 (if (string-equal "" (nth 0 entry))
3008 header-face (nth 1 entry)
3009 field-face (nth 2 entry))
3010 (while (and (re-search-forward regexp nil t)
3014 (unless (search-forward ":" nil t)
3016 (when (and header-face
3017 (not (memq (point) hpoints)))
3018 (push (point) hpoints)
3019 (gnus-put-text-property from (point) 'face header-face))
3020 (when (and field-face
3021 (not (memq (setq from (point)) fpoints)))
3023 (if (re-search-forward "^[^ \t]" nil t)
3025 (goto-char (point-max)))
3026 (gnus-put-text-property from (point) 'face field-face))))))))
3028 (defun gnus-article-highlight-signature ()
3029 "Highlight the signature in an article.
3030 It does this by highlighting everything after
3031 `gnus-signature-separator' using `gnus-signature-face'."
3034 (set-buffer gnus-article-buffer)
3035 (let ((buffer-read-only nil)
3036 (inhibit-point-motion-hooks t))
3038 (when (and gnus-signature-face
3039 (gnus-article-narrow-to-signature))
3040 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3041 'face gnus-signature-face)
3043 (gnus-article-search-signature)
3044 (let ((start (match-beginning 0))
3045 (end (set-marker (make-marker) (1+ (match-end 0)))))
3046 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3049 (defun gnus-button-in-region-p (b e prop)
3050 "Say whether PROP exists in the region."
3051 (text-property-not-all b e prop nil))
3053 (defun gnus-article-add-buttons (&optional force)
3054 "Find external references in the article and make buttons of them.
3055 \"External references\" are things like Message-IDs and URLs, as
3056 specified by `gnus-button-alist'."
3057 (interactive (list 'force))
3059 (set-buffer gnus-article-buffer)
3060 (let ((buffer-read-only nil)
3061 (inhibit-point-motion-hooks t)
3062 (case-fold-search t)
3063 (alist gnus-button-alist)
3065 ;; Remove all old markers.
3067 (while (setq marker (pop gnus-button-marker-list))
3069 (when (setq entry (gnus-button-entry))
3070 (put-text-property (match-beginning (nth 1 entry))
3071 (match-end (nth 1 entry))
3072 'gnus-callback nil))
3073 (set-marker marker nil)))
3074 ;; We skip the headers.
3075 (goto-char (point-min))
3076 (unless (search-forward "\n\n" nil t)
3077 (goto-char (point-max)))
3079 (while (setq entry (pop alist))
3080 (setq regexp (car entry))
3082 (while (re-search-forward regexp nil t)
3083 (let* ((start (and entry (match-beginning (nth 1 entry))))
3084 (end (and entry (match-end (nth 1 entry))))
3085 (from (match-beginning 0)))
3086 (when (and (or (eq t (nth 2 entry))
3087 (eval (nth 2 entry)))
3088 (not (gnus-button-in-region-p
3089 start end 'gnus-callback)))
3090 ;; That optional form returned non-nil, so we add the
3092 (gnus-article-add-button
3093 start end 'gnus-button-push
3094 (car (push (set-marker (make-marker) from)
3095 gnus-button-marker-list))))))))))
3097 ;; Add buttons to the head of an article.
3098 (defun gnus-article-add-buttons-to-head ()
3099 "Add buttons to the head of the article."
3102 (set-buffer gnus-article-buffer)
3103 (let ((buffer-read-only nil)
3104 (inhibit-point-motion-hooks t)
3105 (case-fold-search t)
3106 (alist gnus-header-button-alist)
3108 (nnheader-narrow-to-headers)
3110 ;; Each alist entry.
3111 (setq entry (car alist)
3113 (goto-char (point-min))
3114 (while (re-search-forward (car entry) nil t)
3115 ;; Each header matching the entry.
3116 (setq beg (match-beginning 0))
3117 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3118 (match-beginning 0))
3121 (while (re-search-forward (nth 1 entry) end t)
3122 ;; Each match within a header.
3123 (let* ((entry (cdr entry))
3124 (start (match-beginning (nth 1 entry)))
3125 (end (match-end (nth 1 entry)))
3126 (form (nth 2 entry)))
3127 (goto-char (match-end 0))
3129 (gnus-article-add-button
3130 start end (nth 3 entry)
3131 (buffer-substring (match-beginning (nth 4 entry))
3132 (match-end (nth 4 entry)))))))
3136 ;;; External functions:
3138 (defun gnus-article-add-button (from to fun &optional data)
3139 "Create a button between FROM and TO with callback FUN and data DATA."
3140 (when gnus-article-button-face
3141 (gnus-overlay-put (gnus-make-overlay from to)
3142 'face gnus-article-button-face))
3143 (gnus-add-text-properties
3145 (nconc (and gnus-article-mouse-face
3146 (list gnus-mouse-face-prop gnus-article-mouse-face))
3147 (list 'gnus-callback fun)
3148 (and data (list 'gnus-data data)))))
3150 ;;; Internal functions:
3152 (defun gnus-article-set-globals ()
3154 (set-buffer gnus-summary-buffer)
3155 (gnus-set-global-variables)))
3157 (defun gnus-signature-toggle (end)
3159 (set-buffer gnus-article-buffer)
3160 (let ((buffer-read-only nil)
3161 (inhibit-point-motion-hooks t))
3162 (if (get-text-property end 'invisible)
3163 (gnus-article-unhide-text end (point-max))
3164 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3166 (defun gnus-button-entry ()
3167 ;; Return the first entry in `gnus-button-alist' matching this place.
3168 (let ((alist gnus-button-alist)
3171 (setq entry (pop alist))
3172 (if (looking-at (car entry))
3177 (defun gnus-button-push (marker)
3178 ;; Push button starting at MARKER.
3180 (set-buffer gnus-article-buffer)
3182 (let* ((entry (gnus-button-entry))
3183 (inhibit-point-motion-hooks t)
3185 (args (mapcar (lambda (group)
3186 (let ((string (match-string group)))
3187 (gnus-set-text-properties
3188 0 (length string) nil string)
3195 (fboundp (symbol-value fun)))
3196 (apply (symbol-value fun) args))
3198 (gnus-message 1 "You must define `%S' to use this button"
3199 (cons fun args)))))))
3201 (defun gnus-button-message-id (message-id)
3204 (set-buffer gnus-summary-buffer)
3205 (gnus-summary-refer-article message-id)))
3207 (defun gnus-button-fetch-group (address)
3208 "Fetch GROUP specified by ADDRESS."
3209 (if (not (string-match "[:/]" address))
3210 ;; This is just a simple group url.
3211 (gnus-group-read-ephemeral-group address gnus-select-method)
3212 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3214 (error "Can't parse %s" address)
3215 (gnus-group-read-ephemeral-group
3216 (match-string 4 address)
3217 `(nntp ,(match-string 1 address)
3218 (nntp-address ,(match-string 1 address))
3219 (nntp-port-number ,(if (match-end 3)
3220 (match-string 3 address)
3223 (defun gnus-url-parse-query-string (query &optional downcase)
3224 (let (retval pairs cur key val)
3225 (setq pairs (gnus-split-string query "&"))
3227 (setq cur (car pairs)
3229 (if (not (string-match "=" cur))
3231 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3232 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3234 (setq key (downcase key)))
3235 (setq cur (assoc key retval))
3237 (setcdr cur (cons val (cdr cur)))
3238 (setq retval (cons (list key val) retval)))))
3241 (defun gnus-url-unhex (x)
3248 (defun gnus-url-unhex-string (str &optional allow-newlines)
3249 "Remove %XXX embedded spaces, etc in a url.
3250 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3251 decoding of carriage returns and line feeds in the string, which is normally
3252 forbidden in URL encoding."
3253 (setq str (or str ""))
3255 (case-fold-search t))
3256 (while (string-match "%[0-9a-f][0-9a-f]" str)
3257 (let* ((start (match-beginning 0))
3258 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3260 (gnus-url-unhex (elt str (+ start 2))))))
3262 tmp (substring str 0 start)
3265 (char-to-string code))
3266 ((or (= code ?\n) (= code ?\r))
3268 (t (char-to-string code))))
3269 str (substring str (match-end 0)))))
3270 (setq tmp (concat tmp str))
3273 (defun gnus-url-mailto (url)
3274 ;; Send mail to someone
3275 (when (string-match "mailto:/*\\(.*\\)" url)
3276 (setq url (substring url (match-beginning 1) nil)))
3277 (let (to args subject func)
3278 (if (string-match (regexp-quote "?") url)
3279 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3280 args (gnus-url-parse-query-string
3281 (substring url (match-end 0) nil) t))
3282 (setq to (gnus-url-unhex-string url)))
3283 (setq args (cons (list "to" to) args)
3284 subject (cdr-safe (assoc "subject" args)))
3285 (gnus-setup-message 'reply
3288 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3291 (message-position-on-field (caar args)))
3292 (insert (mapconcat 'identity (cdar args) ", "))
3293 (setq args (cdr args)))
3296 (message-goto-subject)))))
3298 (defun gnus-button-mailto (address)
3300 (set-buffer (gnus-copy-article-buffer))
3301 (gnus-setup-message 'reply
3302 (message-reply address)))
3304 (defun gnus-button-reply (address)
3305 ;; Reply to ADDRESS.
3306 (gnus-setup-message 'reply
3307 (message-reply address)))
3309 (defun gnus-button-url (address)
3311 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3312 (if (listp browse-url-browser-function)
3313 (browse-url address)
3314 (funcall browse-url-browser-function address)))
3316 (defun gnus-button-embedded-url (address)
3318 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3319 (if (listp browse-url-browser-function)
3320 (browse-url (gnus-strip-whitespace address))
3321 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3323 ;;; Next/prev buttons in the article buffer.
3325 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3326 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3328 (defvar gnus-prev-page-map nil)
3329 (unless gnus-prev-page-map
3330 (setq gnus-prev-page-map (make-sparse-keymap))
3331 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3332 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3334 (defun gnus-insert-prev-page-button ()
3335 (let ((buffer-read-only nil))
3337 gnus-prev-page-line-format nil
3338 `(gnus-prev t local-map ,gnus-prev-page-map
3339 gnus-callback gnus-article-button-prev-page
3340 gnus-type annotation))))
3342 (defvar gnus-next-page-map nil)
3343 (unless gnus-next-page-map
3344 (setq gnus-next-page-map (make-keymap))
3345 (suppress-keymap gnus-prev-page-map)
3346 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3347 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3349 (defun gnus-button-next-page ()
3350 "Go to the next page."
3352 (let ((win (selected-window)))
3353 (select-window (get-buffer-window gnus-article-buffer t))
3354 (gnus-article-next-page)
3355 (select-window win)))
3357 (defun gnus-button-prev-page ()
3358 "Go to the prev page."
3360 (let ((win (selected-window)))
3361 (select-window (get-buffer-window gnus-article-buffer t))
3362 (gnus-article-prev-page)
3363 (select-window win)))
3365 (defun gnus-insert-next-page-button ()
3366 (let ((buffer-read-only nil))
3367 (gnus-eval-format gnus-next-page-line-format nil
3369 t local-map ,gnus-next-page-map
3370 gnus-callback gnus-article-button-next-page
3371 gnus-type annotation))))
3373 (defun gnus-article-button-next-page (arg)
3374 "Go to the next page."
3376 (let ((win (selected-window)))
3377 (select-window (get-buffer-window gnus-article-buffer t))
3378 (gnus-article-next-page)
3379 (select-window win)))
3381 (defun gnus-article-button-prev-page (arg)
3382 "Go to the prev page."
3384 (let ((win (selected-window)))
3385 (select-window (get-buffer-window gnus-article-buffer t))
3386 (gnus-article-prev-page)
3387 (select-window win)))
3393 (defun gnus-article-header-presentation-method (entity situation)
3394 (mime-insert-decoded-header entity)
3397 (set-alist 'mime-header-presentation-method-alist
3398 'gnus-original-article-mode
3399 #'gnus-article-header-presentation-method)
3401 (defun gnus-mime-preview-quitting-method ()
3403 (gnus-article-show-summary)
3404 (mime-preview-kill-buffer)
3405 (delete-other-windows)
3406 (gnus-article-show-summary)
3407 (gnus-summary-select-article nil t)
3410 (set-alist 'mime-preview-quitting-method-alist
3411 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
3413 (defun gnus-following-method (buf)
3416 (message-yank-original)
3418 (goto-char (point-min))
3421 (set-alist 'mime-preview-following-method-alist
3422 'gnus-original-article-mode #'gnus-following-method)
3432 (run-hooks 'gnus-art-load-hook)
3434 ;;; gnus-art.el ends here