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 ;; Avoid byte-compile warnings.
43 (defvar gnus-article-decoded-p)
44 (defvar gnus-article-mime-handles)
53 (defgroup gnus-article nil
55 :link '(custom-manual "(gnus)The Article Buffer")
58 (defgroup gnus-article-hiding nil
59 "Hiding article parts."
60 :link '(custom-manual "(gnus)Article Hiding")
63 (defgroup gnus-article-highlight nil
64 "Article highlighting."
65 :link '(custom-manual "(gnus)Article Highlighting")
69 (defgroup gnus-article-signature nil
71 :link '(custom-manual "(gnus)Article Signature")
74 (defgroup gnus-article-headers nil
76 :link '(custom-manual "(gnus)Hiding Headers")
79 (defgroup gnus-article-washing nil
80 "Special commands on articles."
81 :link '(custom-manual "(gnus)Article Washing")
84 (defgroup gnus-article-emphasis nil
85 "Fontisizing articles."
86 :link '(custom-manual "(gnus)Article Fontisizing")
89 (defgroup gnus-article-saving nil
91 :link '(custom-manual "(gnus)Saving Articles")
94 (defgroup gnus-article-mime nil
95 "Worshiping the MIME wonder."
96 :link '(custom-manual "(gnus)Using MIME")
99 (defgroup gnus-article-buttons nil
100 "Pushable buttons in the article buffer."
101 :link '(custom-manual "(gnus)Article Buttons")
102 :group 'gnus-article)
104 (defgroup gnus-article-various nil
105 "Other article options."
106 :link '(custom-manual "(gnus)Misc Article")
107 :group 'gnus-article)
109 (defcustom gnus-ignored-headers
110 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
111 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
112 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
113 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
114 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
115 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
116 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
117 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
118 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
119 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
120 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
121 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
122 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
123 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
124 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
125 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
126 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
127 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
129 "*All headers that start with this regexp will be hidden.
130 This variable can also be a list of regexps of headers to be ignored.
131 If `gnus-visible-headers' is non-nil, this variable will be ignored."
132 :type '(choice :custom-show nil
135 :group 'gnus-article-hiding)
137 (defcustom gnus-visible-headers
138 "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:"
139 "*All headers that do not match this regexp will be hidden.
140 This variable can also be a list of regexp of headers to remain visible.
141 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
142 :type '(repeat :value-to-internal (lambda (widget value)
143 (custom-split-regexp-maybe value))
144 :match (lambda (widget value)
146 (widget-editable-list-match widget value)))
148 :group 'gnus-article-hiding)
150 (defcustom gnus-sorted-header-list
151 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
152 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
153 "*This variable is a list of regular expressions.
154 If it is non-nil, headers that match the regular expressions will
155 be placed first in the article buffer in the sequence specified by
157 :type '(repeat regexp)
158 :group 'gnus-article-hiding)
160 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
161 "Headers that are only to be displayed if they have interesting data.
162 Possible values in this list are `empty', `newsgroups', `followup-to',
163 `reply-to', `date', `long-to', and `many-to'."
164 :type '(set (const :tag "Headers with no content." empty)
165 (const :tag "Newsgroups with only one group." newsgroups)
166 (const :tag "Followup-to identical to newsgroups." followup-to)
167 (const :tag "Reply-to identical to from." reply-to)
168 (const :tag "Date less than four days old." date)
169 (const :tag "Very long To header." long-to)
170 (const :tag "Multiple To headers." many-to))
171 :group 'gnus-article-hiding)
173 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
174 "Regexp matching signature separator.
175 This can also be a list of regexps. In that case, it will be checked
176 from head to tail looking for a separator. Searches will be done from
177 the end of the buffer."
178 :type '(repeat string)
179 :group 'gnus-article-signature)
181 (defcustom gnus-signature-limit nil
182 "Provide a limit to what is considered a signature.
183 If it is a number, no signature may not be longer (in characters) than
184 that number. If it is a floating point number, no signature may be
185 longer (in lines) than that number. If it is a function, the function
186 will be called without any parameters, and if it returns nil, there is
187 no signature in the buffer. If it is a string, it will be used as a
188 regexp. If it matches, the text in question is not a signature."
189 :type '(choice (integer :value 200)
191 (function :value fun)
192 (regexp :value ".*"))
193 :group 'gnus-article-signature)
195 (defcustom gnus-hidden-properties '(invisible t intangible t)
196 "Property list to use for hiding text."
198 :group 'gnus-article-hiding)
200 (defcustom gnus-article-x-face-command
201 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
202 "*String or function to be executed to display an X-Face header.
203 If it is a string, the command will be executed in a sub-shell
204 asynchronously. The compressed face will be piped to this command."
205 :type 'string ;Leave function case to Lisp.
206 :group 'gnus-article-washing)
208 (defcustom gnus-article-x-face-too-ugly nil
209 "Regexp matching posters whose face shouldn't be shown automatically."
210 :type '(choice regexp (const nil))
211 :group 'gnus-article-washing)
213 (defcustom gnus-emphasis-alist
215 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
217 '(("_" "_" underline)
220 ("_/" "/_" underline-italic)
221 ("_\\*" "\\*_" underline-bold)
222 ("\\*/" "/\\*" bold-italic)
223 ("_\\*/" "/\\*_" underline-bold-italic))))
224 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
225 2 3 gnus-emphasis-underline)
229 (format format (car spec) (cadr spec))
230 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
232 "*Alist that says how to fontify certain phrases.
233 Each item looks like this:
235 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
237 The first element is a regular expression to be matched. The second
238 is a number that says what regular expression grouping used to find
239 the entire emphasized word. The third is a number that says what
240 regexp grouping should be displayed and highlighted. The fourth
241 is the face used for highlighting."
242 :type '(repeat (list :value ("" 0 0 default)
244 (integer :tag "Match group")
245 (integer :tag "Emphasize group")
247 :group 'gnus-article-emphasis)
249 (defface gnus-emphasis-bold '((t (:bold t)))
250 "Face used for displaying strong emphasized text (*word*)."
251 :group 'gnus-article-emphasis)
253 (defface gnus-emphasis-italic '((t (:italic t)))
254 "Face used for displaying italic emphasized text (/word/)."
255 :group 'gnus-article-emphasis)
257 (defface gnus-emphasis-underline '((t (:underline t)))
258 "Face used for displaying underlined emphasized text (_word_)."
259 :group 'gnus-article-emphasis)
261 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
262 "Face used for displaying underlined bold emphasized text (_*word*_)."
263 :group 'gnus-article-emphasis)
265 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
266 "Face used for displaying underlined italic emphasized text (_*word*_)."
267 :group 'gnus-article-emphasis)
269 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
270 "Face used for displaying bold italic emphasized text (/*word*/)."
271 :group 'gnus-article-emphasis)
273 (defface gnus-emphasis-underline-bold-italic
274 '((t (:bold t :italic t :underline t)))
275 "Face used for displaying underlined bold italic emphasized text.
276 Esample: (_/*word*/_)."
277 :group 'gnus-article-emphasis)
279 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
280 "Format for display of Date headers in article bodies.
281 See `format-time-string' for the possible values.
283 The variable can also be function, which should return a complete Date
284 header. The function is called with one argument, the time, which can
285 be fed to `format-time-string'."
286 :type '(choice string symbol)
287 :link '(custom-manual "(gnus)Article Date")
288 :group 'gnus-article-washing)
291 (autoload 'mail-extract-address-components "mail-extr"))
293 (defcustom gnus-save-all-headers t
294 "*If non-nil, don't remove any headers before saving."
295 :group 'gnus-article-saving
298 (defcustom gnus-prompt-before-saving 'always
299 "*This variable says how much prompting is to be done when saving articles.
300 If it is nil, no prompting will be done, and the articles will be
301 saved to the default files. If this variable is `always', each and
302 every article that is saved will be preceded by a prompt, even when
303 saving large batches of articles. If this variable is neither nil not
304 `always', there the user will be prompted once for a file name for
305 each invocation of the saving commands."
306 :group 'gnus-article-saving
307 :type '(choice (item always)
308 (item :tag "never" nil)
309 (sexp :tag "once" :format "%t\n" :value t)))
311 (defcustom gnus-saved-headers gnus-visible-headers
312 "Headers to keep if `gnus-save-all-headers' is nil.
313 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
314 If that variable is nil, however, all headers that match this regexp
315 will be kept while the rest will be deleted before saving."
316 :group 'gnus-article-saving
319 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
320 "A function to save articles in your favourite format.
321 The function must be interactively callable (in other words, it must
322 be an Emacs command).
324 Gnus provides the following functions:
326 * gnus-summary-save-in-rmail (Rmail format)
327 * gnus-summary-save-in-mail (Unix mail format)
328 * gnus-summary-save-in-folder (MH folder)
329 * gnus-summary-save-in-file (article format)
330 * gnus-summary-save-in-vm (use VM's folder format)
331 * gnus-summary-write-to-file (article format -- overwrite)."
332 :group 'gnus-article-saving
333 :type '(radio (function-item gnus-summary-save-in-rmail)
334 (function-item gnus-summary-save-in-mail)
335 (function-item gnus-summary-save-in-folder)
336 (function-item gnus-summary-save-in-file)
337 (function-item gnus-summary-save-in-vm)
338 (function-item gnus-summary-write-to-file)))
340 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
341 "A function generating a file name to save articles in Rmail format.
342 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
343 :group 'gnus-article-saving
346 (defcustom gnus-mail-save-name 'gnus-plain-save-name
347 "A function generating a file name to save articles in Unix mail format.
348 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
349 :group 'gnus-article-saving
352 (defcustom gnus-folder-save-name 'gnus-folder-save-name
353 "A function generating a file name to save articles in MH folder.
354 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
355 :group 'gnus-article-saving
358 (defcustom gnus-file-save-name 'gnus-numeric-save-name
359 "A function generating a file name to save articles in article format.
360 The function is called with NEWSGROUP, HEADERS, and optional
362 :group 'gnus-article-saving
365 (defcustom gnus-split-methods
366 '((gnus-article-archive-name)
367 (gnus-article-nndoc-name))
368 "*Variable used to suggest where articles are to be saved.
369 For instance, if you would like to save articles related to Gnus in
370 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
371 you could set this variable to something like:
373 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
374 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
376 This variable is an alist where the where the key is the match and the
377 value is a list of possible files to save in if the match is non-nil.
379 If the match is a string, it is used as a regexp match on the
380 article. If the match is a symbol, that symbol will be funcalled
381 from the buffer of the article to be saved with the newsgroup as the
382 parameter. If it is a list, it will be evaled in the same buffer.
384 If this form or function returns a string, this string will be used as
385 a possible file name; and if it returns a non-nil list, that list will
386 be used as possible file names."
387 :group 'gnus-article-saving
388 :type '(repeat (choice (list :value (fun) function)
389 (cons :value ("" "") regexp (repeat string))
392 (defcustom gnus-article-display-method-for-mime
393 'gnus-article-display-mime-message
394 "Function to display a MIME message.
395 The function is called from the article buffer."
396 :group 'gnus-article-mime
399 (defcustom gnus-article-display-method-for-traditional
400 'gnus-article-display-traditional-message
401 "*Function to display a traditional message.
402 The function is called from the article buffer."
403 :group 'gnus-article-mime
406 (defcustom gnus-page-delimiter "^\^L"
407 "*Regexp describing what to use as article page delimiters.
408 The default value is \"^\^L\", which is a form linefeed at the
409 beginning of a line."
411 :group 'gnus-article-various)
413 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
414 "*The format specification for the article mode line.
415 See `gnus-summary-mode-line-format' for a closer description.
417 The following additional specs are available:
419 %w The article washing status.
420 %m The number of MIME parts in the article."
422 :group 'gnus-article-various)
424 (defcustom gnus-article-mode-hook nil
425 "*A hook for Gnus article mode."
427 :group 'gnus-article-various)
429 (defcustom gnus-article-menu-hook nil
430 "*Hook run after the creation of the article mode menu."
432 :group 'gnus-article-various)
434 (defcustom gnus-article-prepare-hook nil
435 "*A hook called after an article has been prepared in the article buffer.
436 If you want to run a special decoding program like nkf, use this hook."
438 :group 'gnus-article-various)
440 (defcustom gnus-article-hide-pgp-hook nil
441 "*A hook called after successfully hiding a PGP signature."
443 :group 'gnus-article-various)
445 (defcustom gnus-article-button-face 'bold
446 "Face used for highlighting buttons in the article buffer.
448 An article button is a piece of text that you can activate by pressing
449 `RET' or `mouse-2' above it."
451 :group 'gnus-article-buttons)
453 (defcustom gnus-article-mouse-face 'highlight
454 "Face used for mouse highlighting in the article buffer.
456 Article buttons will be displayed in this face when the cursor is
459 :group 'gnus-article-buttons)
461 (defcustom gnus-signature-face 'gnus-signature-face
462 "Face used for highlighting a signature in the article buffer.
463 Obsolete; use the face `gnus-signature-face' for customizations instead."
465 :group 'gnus-article-highlight
466 :group 'gnus-article-signature)
468 (defface gnus-signature-face
471 "Face used for highlighting a signature in the article buffer."
472 :group 'gnus-article-highlight
473 :group 'gnus-article-signature)
475 (defface gnus-header-from-face
478 (:foreground "spring green"))
481 (:foreground "red3"))
484 "Face used for displaying from headers."
485 :group 'gnus-article-headers
486 :group 'gnus-article-highlight)
488 (defface gnus-header-subject-face
491 (:foreground "SeaGreen3"))
494 (:foreground "red4"))
496 (:bold t :italic t)))
497 "Face used for displaying subject headers."
498 :group 'gnus-article-headers
499 :group 'gnus-article-highlight)
501 (defface gnus-header-newsgroups-face
504 (:foreground "yellow" :italic t))
507 (:foreground "MidnightBlue" :italic t))
510 "Face used for displaying newsgroups headers."
511 :group 'gnus-article-headers
512 :group 'gnus-article-highlight)
514 (defface gnus-header-name-face
517 (:foreground "SeaGreen"))
520 (:foreground "maroon"))
523 "Face used for displaying header names."
524 :group 'gnus-article-headers
525 :group 'gnus-article-highlight)
527 (defface gnus-header-content-face
530 (:foreground "forest green" :italic t))
533 (:foreground "indianred4" :italic t))
535 (:italic t))) "Face used for displaying header content."
536 :group 'gnus-article-headers
537 :group 'gnus-article-highlight)
539 (defcustom gnus-header-face-alist
540 '(("From" nil gnus-header-from-face)
541 ("Subject" nil gnus-header-subject-face)
542 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
543 ("" gnus-header-name-face gnus-header-content-face))
544 "*Controls highlighting of article header.
546 An alist of the form (HEADER NAME CONTENT).
548 HEADER is a regular expression which should match the name of an
549 header header and NAME and CONTENT are either face names or nil.
551 The name of each header field will be displayed using the face
552 specified by the first element in the list where HEADER match the
553 header name and NAME is non-nil. Similarly, the content will be
554 displayed by the first non-nil matching CONTENT face."
555 :group 'gnus-article-headers
556 :group 'gnus-article-highlight
557 :type '(repeat (list (regexp :tag "Header")
559 (item :tag "skip" nil)
560 (face :value default))
561 (choice :tag "Content"
562 (item :tag "skip" nil)
563 (face :value default)))))
565 (defcustom gnus-article-decode-hook nil
566 "*Hook run to decode charsets in articles."
567 :group 'gnus-article-headers
570 (defcustom gnus-display-mime-function 'gnus-display-mime
571 "Function to display MIME articles."
572 :group 'gnus-article-mime
575 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
576 "Function used to decode headers.")
578 (defvar gnus-article-dumbquotes-map
597 "Table for MS-to-Latin1 translation.")
599 (defcustom gnus-ignored-mime-types nil
600 "List of MIME types that should be ignored by Gnus."
601 :group 'gnus-article-mime
602 :type '(repeat regexp))
604 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
605 "List of MIME types that should not be given buttons when rendered."
606 :group 'gnus-article-mime
607 :type '(repeat regexp))
609 (defcustom gnus-treat-body-highlight-signature t
610 "Highlight the signature."
612 :type '(choice (const :tag "Off" nil)
614 (const :tag "Last" last)
615 (integer :tag "Less")
616 (sexp :tag "Predicate")))
618 (defcustom gnus-article-mime-part-function nil
619 "Function called with a MIME handle as the argument."
620 :group 'gnus-article-mime
623 ;;; Internal variables
625 (defvar gnus-article-mime-handle-alist-1 nil)
626 (defvar gnus-treatment-function-alist
627 '((gnus-treat-body-highlight-signature gnus-article-highlight-signature nil)
630 (defvar gnus-article-mime-handle-alist nil)
631 (defvar article-lapsed-timer nil)
632 (defvar gnus-article-current-summary nil)
634 (defvar gnus-article-mode-syntax-table
635 (let ((table (copy-syntax-table text-mode-syntax-table)))
636 (modify-syntax-entry ?- "w" table)
637 (modify-syntax-entry ?> ")" table)
638 (modify-syntax-entry ?< "(" table)
640 "Syntax table used in article mode buffers.
641 Initialized from `text-mode-syntax-table.")
643 (defvar gnus-save-article-buffer nil)
645 (defvar gnus-article-mode-line-format-alist
646 (nconc '((?w (gnus-article-wash-status) ?s)
647 (?m (gnus-article-mime-part-status) ?s))
648 gnus-summary-mode-line-format-alist))
650 (defvar gnus-number-of-articles-to-be-saved nil)
652 (defvar gnus-inhibit-hiding nil)
654 (defsubst gnus-article-hide-text (b e props)
655 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
656 (add-text-properties b e props)
657 (when (memq 'intangible props)
659 (max (1- b) (point-min))
660 b 'intangible (cddr (memq 'intangible props)))))
662 (defmacro gnus-with-article (article &rest forms)
663 "Select ARTICLE and perform FORMS in the original article buffer.
664 Then replace the article with the result."
666 ;; We don't want the article to be marked as read.
667 (let (gnus-mark-article-hook)
668 (gnus-summary-select-article t t nil ,article))
669 (set-buffer gnus-original-article-buffer)
671 (if (not (gnus-check-backend-function
672 'request-replace-article (car gnus-article-current)))
673 (gnus-message 5 "Read-only group; not replacing")
674 (unless (gnus-request-replace-article
675 ,article (car gnus-article-current)
677 (error "Couldn't replace article")))
678 ;; The cache and backlog have to be flushed somewhat.
679 (when gnus-keep-backlog
680 (gnus-backlog-remove-article
681 (car gnus-article-current) (cdr gnus-article-current)))
683 (gnus-cache-update-article
684 (car gnus-article-current) (cdr gnus-article-current)))))
686 (put 'gnus-with-article 'lisp-indent-function 1)
687 (put 'gnus-with-article 'edebug-form-spec '(form body))
689 (defsubst gnus-article-unhide-text (b e)
690 "Remove hidden text properties from region between B and E."
691 (remove-text-properties b e gnus-hidden-properties)
692 (when (memq 'intangible gnus-hidden-properties)
693 (put-text-property (max (1- b) (point-min))
696 (defun gnus-article-hide-text-type (b e type)
697 "Hide text of TYPE between B and E."
698 (gnus-article-hide-text
699 b e (cons 'article-type (cons type gnus-hidden-properties))))
701 (defun gnus-article-unhide-text-type (b e type)
702 "Unhide text of TYPE between B and E."
703 (remove-text-properties
704 b e (cons 'article-type (cons type gnus-hidden-properties)))
705 (when (memq 'intangible gnus-hidden-properties)
706 (put-text-property (max (1- b) (point-min))
709 (defun gnus-article-hide-text-of-type (type)
710 "Hide text of TYPE in the current buffer."
712 (let ((b (point-min))
714 (while (setq b (text-property-any b e 'article-type type))
715 (add-text-properties b (incf b) gnus-hidden-properties)))))
717 (defun gnus-article-delete-text-of-type (type)
718 "Delete text of TYPE in the current buffer."
720 (let ((b (point-min)))
721 (while (setq b (text-property-any b (point-max) 'article-type type))
723 b (or (text-property-not-all b (point-max) 'article-type type)
726 (defun gnus-article-delete-invisible-text ()
727 "Delete all invisible text in the current buffer."
729 (let ((b (point-min)))
730 (while (setq b (text-property-any b (point-max) 'invisible t))
732 b (or (text-property-not-all b (point-max) 'invisible t)
735 (defun gnus-article-text-type-exists-p (type)
736 "Say whether any text of type TYPE exists in the buffer."
737 (text-property-any (point-min) (point-max) 'article-type type))
739 (defsubst gnus-article-header-rank ()
740 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
741 (let ((list gnus-sorted-header-list)
744 (when (looking-at (car list))
746 (setq list (cdr list))
750 (defun article-hide-headers (&optional arg delete)
751 "Toggle whether to hide unwanted headers and possibly sort them as well.
752 If given a negative prefix, always show; if given a positive prefix,
754 (interactive (gnus-article-hidden-arg))
756 (if (gnus-article-check-hidden-text 'headers arg)
757 ;; Show boring headers as well.
758 (gnus-article-show-hidden-text 'boring-headers)
759 ;; This function might be inhibited.
760 (unless gnus-inhibit-hiding
763 (let ((buffer-read-only nil)
765 (props (nconc (list 'article-type 'headers)
766 gnus-hidden-properties))
767 (max (1+ (length gnus-sorted-header-list)))
768 (ignored (when (not gnus-visible-headers)
769 (cond ((stringp gnus-ignored-headers)
770 gnus-ignored-headers)
771 ((listp gnus-ignored-headers)
772 (mapconcat 'identity gnus-ignored-headers
775 (cond ((stringp gnus-visible-headers)
776 gnus-visible-headers)
777 ((and gnus-visible-headers
778 (listp gnus-visible-headers))
779 (mapconcat 'identity gnus-visible-headers "\\|"))))
780 (inhibit-point-motion-hooks t)
782 ;; First we narrow to just the headers.
784 (goto-char (point-min))
785 ;; Hide any "From " lines at the beginning of (mail) articles.
786 (while (looking-at "From ")
790 (delete-region (point-min) (point))
791 (gnus-article-hide-text (point-min) (point) props)))
792 ;; Then treat the rest of the header lines.
795 (if (search-forward "\n\n" nil t) ; if there's a body
796 (progn (forward-line -1) (point))
798 ;; Then we use the two regular expressions
799 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
800 ;; select which header lines is to remain visible in the
802 (goto-char (point-min))
803 (while (re-search-forward "^[^ \t]*:" nil t)
805 ;; Mark the rank of the header.
807 (point) (1+ (point)) 'message-rank
808 (if (or (and visible (looking-at visible))
810 (not (looking-at ignored))))
811 (gnus-article-header-rank)
814 (message-sort-headers-1)
815 (when (setq beg (text-property-any
816 (point-min) (point-max) 'message-rank (+ 2 max)))
817 ;; We make the unwanted headers invisible.
819 (delete-region beg (point-max))
820 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
821 (gnus-article-hide-text-type beg (point-max) 'headers))
822 ;; Work around XEmacs lossage.
823 (put-text-property (point-min) beg 'invisible nil))))))))
825 (defun article-hide-boring-headers (&optional arg)
826 "Toggle hiding of headers that aren't very interesting.
827 If given a negative prefix, always show; if given a positive prefix,
829 (interactive (gnus-article-hidden-arg))
830 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
831 (not gnus-show-all-headers))
834 (let ((buffer-read-only nil)
835 (list gnus-boring-article-headers)
836 (inhibit-point-motion-hooks t)
838 (nnheader-narrow-to-headers)
840 (setq elem (pop list))
841 (goto-char (point-min))
843 ;; Hide empty headers.
845 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
847 (gnus-article-hide-text-type
848 (progn (beginning-of-line) (point))
851 (if (re-search-forward "^[^ \t]" nil t)
855 ;; Hide boring Newsgroups header.
856 ((eq elem 'newsgroups)
857 (when (equal (gnus-fetch-field "newsgroups")
858 (gnus-group-real-name
859 (if (boundp 'gnus-newsgroup-name)
862 (gnus-article-hide-header "newsgroups")))
863 ((eq elem 'followup-to)
864 (when (equal (message-fetch-field "followup-to")
865 (message-fetch-field "newsgroups"))
866 (gnus-article-hide-header "followup-to")))
868 (let ((from (message-fetch-field "from"))
869 (reply-to (message-fetch-field "reply-to")))
874 (nth 1 (funcall gnus-extract-address-components from))
875 (nth 1 (funcall gnus-extract-address-components reply-to)))))
876 (gnus-article-hide-header "reply-to"))))
878 (let ((date (message-fetch-field "date")))
880 (< (days-between (current-time-string) date)
882 (gnus-article-hide-header "date"))))
884 (let ((to (message-fetch-field "to")))
885 (when (> (length to) 1024)
886 (gnus-article-hide-header "to"))))
889 (goto-char (point-min))
890 (while (re-search-forward "^to:" nil t)
891 (setq to-count (1+ to-count)))
893 (while (> to-count 0)
894 (goto-char (point-min))
896 (re-search-forward "^to:" nil nil to-count)
898 (narrow-to-region (point) (point-max))
899 (gnus-article-hide-header "to"))
900 (setq to-count (1- to-count)))))))))))))
902 (defun gnus-article-hide-header (header)
904 (goto-char (point-min))
905 (when (re-search-forward (concat "^" header ":") nil t)
906 (gnus-article-hide-text-type
907 (progn (beginning-of-line) (point))
910 (if (re-search-forward "^[^ \t]" nil t)
915 (defun article-treat-dumbquotes ()
916 "Translate M******** sm*rtq**t*s into proper text."
918 (article-translate-strings gnus-article-dumbquotes-map))
920 (defun article-translate-characters (from to)
921 "Translate all characters in the body of the article according to FROM and TO.
922 FROM is a string of characters to translate from; to is a string of
923 characters to translate to."
925 (when (article-goto-body)
926 (let ((buffer-read-only nil)
927 (x (make-string 225 ?x))
929 (while (< (incf i) (length x))
932 (while (< i (length from))
933 (aset x (aref from i) (aref to i))
935 (translate-region (point) (point-max) x)))))
937 (defun article-translate-strings (map)
938 "Translate all string in the body of the article according to MAP.
939 MAP is an alist where the elements are on the form (\"from\" \"to\")."
941 (when (article-goto-body)
942 (let ((buffer-read-only nil)
944 (while (setq elem (pop map))
946 (while (search-forward (car elem) nil t)
947 (replace-match (cadr elem)))))))))
949 (defun article-treat-overstrike ()
950 "Translate overstrikes into bold text."
953 (when (article-goto-body)
954 (let ((buffer-read-only nil))
955 (while (search-forward "\b" nil t)
956 (let ((next (char-after))
957 (previous (char-after (- (point) 2))))
958 ;; We do the boldification/underlining by hiding the
959 ;; overstrikes and putting the proper text property
963 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
964 (put-text-property (point) (1+ (point)) 'face 'bold))
966 (gnus-article-hide-text-type
967 (1- (point)) (1+ (point)) 'overstrike)
969 (- (point) 2) (1- (point)) 'face 'underline))
971 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
973 (point) (1+ (point)) 'face 'underline)))))))))
975 (defun article-fill ()
976 "Format too long lines."
979 (let ((buffer-read-only nil))
983 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
984 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
985 (adaptive-fill-mode t))
987 (and (>= (current-column) (min fill-column (window-width)))
988 (/= (preceding-char) ?:)
989 (fill-paragraph nil))
992 (defun article-remove-cr ()
993 "Translate CRLF pairs into LF, and then CR into LF.."
996 (let ((buffer-read-only nil))
997 (goto-char (point-min))
998 (while (search-forward "\r$" nil t)
999 (replace-match "" t t))
1000 (goto-char (point-min))
1001 (while (search-forward "\r" nil t)
1002 (replace-match "\n" t t)))))
1004 (defun article-remove-trailing-blank-lines ()
1005 "Remove all trailing blank lines from the article."
1008 (let ((buffer-read-only nil))
1009 (goto-char (point-max))
1013 (while (and (not (bobp))
1014 (looking-at "^[ \t]*$")
1015 (not (gnus-annotation-in-region-p
1016 (point) (gnus-point-at-eol))))
1021 (defun article-display-x-face (&optional force)
1022 "Look for an X-Face header and display it if present."
1023 (interactive (list 'force))
1025 ;; Delete the old process, if any.
1026 (when (process-status "article-x-face")
1027 (delete-process "article-x-face"))
1028 (let ((inhibit-point-motion-hooks t)
1029 (case-fold-search t)
1032 (nnheader-narrow-to-headers)
1033 (setq from (message-fetch-field "from"))
1034 (goto-char (point-min))
1035 (while (and gnus-article-x-face-command
1038 ;; Check whether this face is censored.
1039 (not gnus-article-x-face-too-ugly)
1040 (and gnus-article-x-face-too-ugly from
1041 (not (string-match gnus-article-x-face-too-ugly
1043 ;; Has to be present.
1044 (re-search-forward "^X-Face: " nil t))
1045 ;; This used to try to do multiple faces (`while' instead of
1046 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1047 ;; work (b) it can crash some versions of Emacs (c) are
1048 ;; multiple faces really something to encourage?
1049 (when (stringp gnus-article-x-face-command)
1051 ;; We now have the area of the buffer where the X-Face is stored.
1054 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1055 ;; We display the face.
1056 (if (symbolp gnus-article-x-face-command)
1057 ;; The command is a lisp function, so we call it.
1058 (if (gnus-functionp gnus-article-x-face-command)
1059 (funcall gnus-article-x-face-command beg end)
1060 (error "%s is not a function" gnus-article-x-face-command))
1061 ;; The command is a string, so we interpret the command
1062 ;; as a, well, command, and fork it off.
1063 (let ((process-connection-type nil))
1064 (process-kill-without-query
1066 "article-x-face" nil shell-file-name shell-command-switch
1067 gnus-article-x-face-command))
1068 (process-send-region "article-x-face" beg end)
1069 (process-send-eof "article-x-face"))))))))))
1071 (defun article-decode-mime-words ()
1072 "Decode all MIME-encoded words in the article."
1075 (set-buffer gnus-article-buffer)
1076 (let ((inhibit-point-motion-hooks t)
1078 (rfc2047-default-charset gnus-newsgroup-default-charset)
1079 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1080 (mail-decode-encoded-word-region (point-min) (point-max)))))
1082 (defun article-decode-charset (&optional prompt)
1083 "Decode charset-encoded text in the article.
1084 If PROMPT (the prefix), prompt for a coding system to use."
1088 (message-narrow-to-head)
1089 (let* ((inhibit-point-motion-hooks t)
1090 (case-fold-search t)
1091 (ct (message-fetch-field "Content-Type" t))
1092 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1093 (ctl (and ct (condition-case ()
1094 (mail-header-parse-content-type ct)
1098 (mm-read-coding-system "Charset to decode: "))
1100 (mail-content-type-get ctl 'charset))))
1101 (rfc2047-default-charset gnus-newsgroup-default-charset)
1102 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
1104 (goto-char (point-max))
1107 (narrow-to-region (point) (point-max))
1108 (when (and (or (not ctl)
1109 (equal (car ctl) "text/plain"))
1112 charset (and cte (intern (downcase
1113 (gnus-strip-whitespace cte))))
1116 (defun article-decode-encoded-words ()
1117 "Remove encoded-word encoding from headers."
1118 (let (buffer-read-only)
1119 (let ((charset (save-excursion
1120 (set-buffer gnus-summary-buffer)
1121 default-mime-charset)))
1122 (mime-decode-header-in-buffer charset)
1125 (defun article-de-quoted-unreadable (&optional force)
1126 "Translate a quoted-printable-encoded article.
1127 If FORCE, decode the article whether it is marked as quoted-printable
1129 (interactive (list 'force))
1131 (let ((buffer-read-only nil)
1132 (type (gnus-fetch-field "content-transfer-encoding"))
1134 (or gnus-newsgroup-default-charset mm-default-coding-system))
1135 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1137 (and type (string-match "quoted-printable" (downcase type))))
1140 (narrow-to-region (point) (point-max))
1141 (quoted-printable-decode-region (point-min) (point-max))
1143 (mm-decode-body charset)))))))
1145 (defun article-hide-pgp (&optional arg)
1146 "Toggle hiding of any PGP headers and signatures in the current article.
1147 If given a negative prefix, always show; if given a positive prefix,
1149 (interactive (gnus-article-hidden-arg))
1150 (unless (gnus-article-check-hidden-text 'pgp arg)
1152 (let ((inhibit-point-motion-hooks t)
1153 buffer-read-only beg end)
1155 (goto-char (point-min))
1156 ;; Hide the "header".
1157 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1158 (delete-region (1+ (match-beginning 0)) (match-end 0))
1159 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1160 (when (looking-at "Hash:.*$")
1161 (delete-region (point) (1+ (gnus-point-at-eol))))
1163 ;; Hide the actual signature.
1164 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1165 (setq end (1+ (match-beginning 0)))
1168 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1170 ;; Perhaps we shouldn't hide to the end of the buffer
1171 ;; if there is no end to the signature?
1173 ;; Hide "- " PGP quotation markers.
1175 (narrow-to-region beg end)
1176 (goto-char (point-min))
1177 (while (re-search-forward "^- " nil t)
1179 (match-beginning 0) (match-end 0)))
1181 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1183 (defun article-hide-pem (&optional arg)
1184 "Toggle hiding of any PEM headers and signatures in the current article.
1185 If given a negative prefix, always show; if given a positive prefix,
1187 (interactive (gnus-article-hidden-arg))
1188 (unless (gnus-article-check-hidden-text 'pem arg)
1190 (let (buffer-read-only end)
1192 (goto-char (point-min))
1193 ;; hide the horrendously ugly "header".
1194 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1197 (setq end (1+ (match-beginning 0)))
1198 (gnus-article-hide-text-type
1200 (if (search-forward "\n\n" nil t)
1204 ;; hide the trailer as well
1205 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1208 (gnus-article-hide-text-type
1209 (match-beginning 0) (match-end 0) 'pem))))))
1211 (defun article-hide-signature (&optional arg)
1212 "Hide the signature in the current article.
1213 If given a negative prefix, always show; if given a positive prefix,
1215 (interactive (gnus-article-hidden-arg))
1216 (unless (gnus-article-check-hidden-text 'signature arg)
1219 (let ((buffer-read-only nil))
1220 (when (gnus-article-narrow-to-signature)
1221 (gnus-article-hide-text-type
1222 (point-min) (point-max) 'signature)))))))
1224 (defun article-strip-leading-blank-lines ()
1225 "Remove all blank lines from the beginning of the article."
1228 (let ((inhibit-point-motion-hooks t)
1230 (when (article-goto-body)
1231 (while (and (not (eobp))
1232 (looking-at "[ \t]*$"))
1233 (gnus-delete-line))))))
1235 (defun article-goto-body ()
1236 "Place point at the start of the body."
1237 (goto-char (point-min))
1238 (if (search-forward "\n\n" nil t)
1240 (goto-char (point-max))
1243 (defun article-strip-multiple-blank-lines ()
1244 "Replace consecutive blank lines with one empty line."
1247 (let ((inhibit-point-motion-hooks t)
1249 ;; First make all blank lines empty.
1251 (while (re-search-forward "^[ \t]+$" nil t)
1252 (unless (gnus-annotation-in-region-p
1253 (match-beginning 0) (match-end 0))
1254 (replace-match "" nil t)))
1255 ;; Then replace multiple empty lines with a single empty line.
1257 (while (re-search-forward "\n\n\n+" nil t)
1258 (unless (gnus-annotation-in-region-p
1259 (match-beginning 0) (match-end 0))
1260 (replace-match "\n\n" t t))))))
1262 (defun article-strip-leading-space ()
1263 "Remove all white space from the beginning of the lines in the article."
1266 (let ((inhibit-point-motion-hooks t)
1269 (while (re-search-forward "^[ \t]+" nil t)
1270 (replace-match "" t t)))))
1272 (defun article-strip-trailing-space ()
1273 "Remove all white space from the end of the lines in the article."
1276 (let ((inhibit-point-motion-hooks t)
1279 (while (re-search-forward "[ \t]+$" nil t)
1280 (replace-match "" t t)))))
1282 (defun article-strip-blank-lines ()
1283 "Strip leading, trailing and multiple blank lines."
1285 (article-strip-leading-blank-lines)
1286 (article-remove-trailing-blank-lines)
1287 (article-strip-multiple-blank-lines))
1289 (defun article-strip-all-blank-lines ()
1290 "Strip all blank lines."
1293 (let ((inhibit-point-motion-hooks t)
1296 (while (re-search-forward "^[ \t]*\n" nil t)
1297 (replace-match "" t t)))))
1299 (defun gnus-article-narrow-to-signature ()
1300 "Narrow to the signature; return t if a signature is found, else nil."
1302 (let ((inhibit-point-motion-hooks t))
1303 (when (gnus-article-search-signature)
1305 ;; Check whether we have some limits to what we consider
1306 ;; to be a signature.
1307 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1308 (list gnus-signature-limit)))
1310 (while (setq limit (pop limits))
1311 (if (or (and (integerp limit)
1312 (< (- (point-max) (point)) limit))
1314 (< (count-lines (point) (point-max)) limit))
1315 (and (gnus-functionp limit)
1317 (and (stringp limit)
1318 (not (re-search-forward limit nil t))))
1319 () ; This limit did not succeed.
1323 (narrow-to-region (point) (point-max))
1326 (defun gnus-article-search-signature ()
1327 "Search the current buffer for the signature separator.
1328 Put point at the beginning of the signature separator."
1329 (let ((cur (point)))
1330 (goto-char (point-max))
1331 (if (if (stringp gnus-signature-separator)
1332 (re-search-backward gnus-signature-separator nil t)
1333 (let ((seps gnus-signature-separator))
1335 (not (re-search-backward (car seps) nil t)))
1343 (autoload 'w3-display "w3-parse")
1344 (autoload 'w3-do-setup "w3" "" t)
1345 (autoload 'w3-region "w3-display" "" t))
1347 (defun gnus-article-treat-html ()
1350 (let ((cbuf (current-buffer)))
1351 (set-buffer gnus-article-buffer)
1352 (let (buf buffer-read-only b e)
1354 (goto-char (point-min))
1356 (if (search-forward "\n\n" nil t)
1359 (setq e (point-max)))
1361 (insert-buffer-substring gnus-article-buffer b e)
1363 (save-window-excursion
1364 (w3-region (point-min) (point-max))
1365 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1367 (delete-region (point-min) (point-max))
1370 (goto-char (point-min))
1371 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1372 (set-buffer cbuf))))
1374 (defun gnus-article-hidden-arg ()
1375 "Return the current prefix arg as a number, or 0 if no prefix."
1376 (list (if current-prefix-arg
1377 (prefix-numeric-value current-prefix-arg)
1380 (defun gnus-article-check-hidden-text (type arg)
1381 "Return nil if hiding is necessary.
1382 Arg can be nil or a number. Nil and positive means hide, negative
1383 means show, 0 means toggle."
1387 (let ((hide (gnus-article-hidden-text-p type)))
1393 (gnus-article-show-hidden-text type))
1395 (if (eq hide 'hidden)
1396 (gnus-article-show-hidden-text type)
1399 (defun gnus-article-hidden-text-p (type)
1400 "Say whether the current buffer contains hidden text of type TYPE."
1401 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1403 (not (get-text-property pos 'invisible)))
1405 (text-property-any (1+ pos) (point-max) 'article-type type)))
1410 (defun gnus-article-show-hidden-text (type &optional hide)
1411 "Show all hidden text of type TYPE.
1412 If HIDE, hide the text instead."
1414 (let ((buffer-read-only nil)
1415 (inhibit-point-motion-hooks t)
1418 (while (setq beg (text-property-any end (point-max) 'article-type type))
1421 (text-property-not-all beg (point-max) 'article-type type)
1424 (gnus-article-hide-text beg end gnus-hidden-properties)
1425 (gnus-article-unhide-text beg end))
1429 (defconst article-time-units
1430 `((year . ,(* 365.25 24 60 60))
1431 (week . ,(* 7 24 60 60))
1432 (day . ,(* 24 60 60))
1436 "Mapping from time units to seconds.")
1438 (defun article-date-ut (&optional type highlight header)
1439 "Convert DATE date to universal time in the current article.
1440 If TYPE is `local', convert to local time; if it is `lapsed', output
1441 how much time has lapsed since DATE."
1442 (interactive (list 'ut t))
1443 (let* ((header (or header
1444 (mail-header-date gnus-current-headers)
1445 (message-fetch-field "date")
1447 (date (if (vectorp header) (mail-header-date header)
1449 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1450 (inhibit-point-motion-hooks t)
1451 bface eface newline)
1452 (when (and date (not (string= date "")))
1455 (nnheader-narrow-to-headers)
1456 (let ((buffer-read-only nil))
1457 ;; Delete any old Date headers.
1458 (if (re-search-forward date-regexp nil t)
1460 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1461 eface (get-text-property (1- (gnus-point-at-eol))
1463 (delete-region (progn (beginning-of-line) (point))
1464 (progn (end-of-line) (point)))
1465 (beginning-of-line))
1466 (goto-char (point-max))
1468 (insert (article-make-date-line date type))
1471 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1472 (put-text-property (match-beginning 1) (1+ (match-end 1))
1474 (put-text-property (match-beginning 2) (match-end 2)
1478 (insert "\n"))))))))
1480 (defun article-make-date-line (date type)
1481 "Return a DATE line of TYPE."
1482 (let ((time (condition-case ()
1486 ;; Convert to the local timezone. We have to slap a
1487 ;; `condition-case' round the calls to the timezone
1488 ;; functions since they aren't particularly resistant to
1491 (let ((tz (car (current-time-zone))))
1492 (format "Date: %s %s%04d" (current-time-string time)
1493 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1494 ;; Convert to Universal Time.
1497 (current-time-string
1498 (let* ((e (parse-time-string date))
1499 (tm (apply 'encode-time e))
1501 (ls (- (cadr tm) (car (current-time-zone)))))
1502 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1503 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1506 ;; Get the original date from the article.
1507 ((eq type 'original)
1508 (concat "Date: " (if (string-match "\n+$" date)
1509 (substring date 0 (match-beginning 0))
1511 ;; Let the user define the format.
1513 (if (gnus-functionp gnus-article-time-format)
1514 (funcall gnus-article-time-format time)
1517 (format-time-string gnus-article-time-format time))))
1522 (format-time-string "%Y%M%DT%h%m%s" time)))
1523 ;; Do an X-Sent lapsed format.
1525 ;; If the date is seriously mangled, the timezone functions are
1526 ;; liable to bug out, so we ignore all errors.
1527 (let* ((now (current-time))
1528 (real-time (subtract-time now time))
1529 (real-sec (and real-time
1530 (+ (* (float (car real-time)) 65536)
1532 (sec (and real-time (abs real-sec)))
1542 ;; This is a bit convoluted, but basically we go
1543 ;; through the time units for years, weeks, etc,
1544 ;; and divide things to see whether that results
1545 ;; in positive answers.
1548 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1549 ;; The (remaining) seconds are too few to
1550 ;; be divided into this time unit.
1552 ;; It's big enough, so we output it.
1553 (setq sec (- sec (* num (cdr unit))))
1555 (concat (if prev ", " "") (int-to-string
1557 " " (symbol-name (car unit))
1558 (if (> num 1) "s" ""))
1560 article-time-units "")
1561 ;; If dates are odd, then it might appear like the
1562 ;; article was sent in the future.
1565 " in the future"))))))
1567 (error "Unknown conversion type: %s" type)))))
1569 (defun article-date-local (&optional highlight)
1570 "Convert the current article date to the local timezone."
1571 (interactive (list t))
1572 (article-date-ut 'local highlight))
1574 (defun article-date-original (&optional highlight)
1575 "Convert the current article date to what it was originally.
1576 This is only useful if you have used some other date conversion
1577 function and want to see what the date was before converting."
1578 (interactive (list t))
1579 (article-date-ut 'original highlight))
1581 (defun article-date-lapsed (&optional highlight)
1582 "Convert the current article date to time lapsed since it was sent."
1583 (interactive (list t))
1584 (article-date-ut 'lapsed highlight))
1586 (defun article-update-date-lapsed ()
1587 "Function to be run from a timer to update the lapsed time line."
1588 (let (deactivate-mark)
1593 (set-buffer (window-buffer w))
1594 (when (eq major-mode 'gnus-article-mode)
1595 (goto-char (point-min))
1596 (when (re-search-forward "^X-Sent:" nil t)
1597 (article-date-lapsed t)))))))))
1599 (defun gnus-start-date-timer (&optional n)
1600 "Start a timer to update the X-Sent header in the article buffers.
1601 The numerical prefix says how frequently (in seconds) the function
1606 (gnus-stop-date-timer)
1607 (setq article-lapsed-timer
1608 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1610 (defun gnus-stop-date-timer ()
1611 "Stop the X-Sent timer."
1613 (when article-lapsed-timer
1614 (nnheader-cancel-timer article-lapsed-timer)
1615 (setq article-lapsed-timer nil)))
1617 (defun article-date-user (&optional highlight)
1618 "Convert the current article date to the user-defined format.
1619 This format is defined by the `gnus-article-time-format' variable."
1620 (interactive (list t))
1621 (article-date-ut 'user highlight))
1623 (defun article-date-iso8601 (&optional highlight)
1624 "Convert the current article date to ISO8601."
1625 (interactive (list t))
1626 (article-date-ut 'iso8601 highlight))
1628 (defun article-show-all ()
1629 "Show all hidden text in the article buffer."
1632 (let ((buffer-read-only nil))
1633 (gnus-article-unhide-text (point-min) (point-max)))))
1635 (defun article-emphasize (&optional arg)
1636 "Emphasize text according to `gnus-emphasis-alist'."
1637 (interactive (gnus-article-hidden-arg))
1638 (unless (gnus-article-check-hidden-text 'emphasis arg)
1640 (let ((alist gnus-emphasis-alist)
1641 (buffer-read-only nil)
1642 (props (append '(article-type emphasis)
1643 gnus-hidden-properties))
1644 regexp elem beg invisible visible face)
1647 (while (setq elem (pop alist))
1649 (setq regexp (car elem)
1650 invisible (nth 1 elem)
1651 visible (nth 2 elem)
1653 (while (re-search-forward regexp nil t)
1654 (when (and (match-beginning visible) (match-beginning invisible))
1655 (gnus-article-hide-text
1656 (match-beginning invisible) (match-end invisible) props)
1657 (gnus-article-unhide-text-type
1658 (match-beginning visible) (match-end visible) 'emphasis)
1659 (gnus-put-text-property-excluding-newlines
1660 (match-beginning visible) (match-end visible) 'face face)
1661 (goto-char (match-end invisible)))))))))
1663 (defvar gnus-summary-article-menu)
1664 (defvar gnus-summary-post-menu)
1666 ;;; Saving functions.
1668 (defun gnus-article-save (save-buffer file &optional num)
1669 "Save the currently selected article."
1670 (unless gnus-save-all-headers
1671 ;; Remove headers according to `gnus-saved-headers'.
1672 (let ((gnus-visible-headers
1673 (or gnus-saved-headers gnus-visible-headers))
1674 (gnus-article-buffer save-buffer))
1676 (set-buffer save-buffer)
1677 (article-hide-headers 1 t))))
1678 (save-window-excursion
1679 (if (not gnus-default-article-saver)
1680 (error "No default saver is defined")
1681 ;; !!! Magic! The saving functions all save
1682 ;; `gnus-save-article-buffer' (or so they think), but we
1683 ;; bind that variable to our save-buffer.
1684 (set-buffer gnus-article-buffer)
1685 (let* ((gnus-save-article-buffer save-buffer)
1688 ((not gnus-prompt-before-saving) 'default)
1689 ((eq gnus-prompt-before-saving 'always) nil)
1691 (gnus-number-of-articles-to-be-saved
1692 (when (eq gnus-prompt-before-saving t)
1694 (set-buffer gnus-article-current-summary)
1695 (funcall gnus-default-article-saver filename)))))
1697 (defun gnus-read-save-file-name (prompt &optional filename
1698 function group headers variable)
1700 (funcall function group headers (symbol-value variable)))
1705 ((eq filename 'default)
1711 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1714 (if (and gnus-number-of-articles-to-be-saved
1715 (> gnus-number-of-articles-to-be-saved 1))
1716 (format "these %d articles"
1717 gnus-number-of-articles-to-be-saved)
1720 ;; Let the split methods have their say.
1722 ;; No split name was found.
1725 (concat prompt " (default "
1726 (file-name-nondirectory default-name) ") ")
1727 (file-name-directory default-name)
1729 ;; A single group name is returned.
1730 ((stringp split-name)
1732 (funcall function split-name headers
1733 (symbol-value variable)))
1735 (concat prompt " (default "
1736 (file-name-nondirectory default-name) ") ")
1737 (file-name-directory default-name)
1739 ;; A single split name was found
1740 ((= 1 (length split-name))
1741 (let* ((name (expand-file-name
1742 (car split-name) gnus-article-save-directory))
1743 (dir (cond ((file-directory-p name)
1744 (file-name-as-directory name))
1745 ((file-exists-p name) name)
1746 (t gnus-article-save-directory))))
1748 (concat prompt " (default " name ") ")
1750 ;; A list of splits was found.
1752 (setq split-name (nreverse split-name))
1754 (let ((file-name-history
1755 (nconc split-name file-name-history)))
1759 (concat prompt " (`M-p' for defaults) ")
1760 gnus-article-save-directory
1762 gnus-article-save-directory)))
1763 (car (push result file-name-history)))))))
1764 ;; Create the directory.
1765 (gnus-make-directory (file-name-directory file))
1766 ;; If we have read a directory, we append the default file name.
1767 (when (file-directory-p file)
1768 (setq file (concat (file-name-as-directory file)
1769 (file-name-nondirectory default-name))))
1770 ;; Possibly translate some characters.
1771 (nnheader-translate-file-chars file)))))
1772 (gnus-make-directory (file-name-directory result))
1773 (set variable result)))
1775 (defun gnus-article-archive-name (group)
1776 "Return the first instance of an \"Archive-name\" in the current buffer."
1777 (let ((case-fold-search t))
1778 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1779 (nnheader-concat gnus-article-save-directory
1780 (match-string 1)))))
1782 (defun gnus-article-nndoc-name (group)
1783 "If GROUP is an nndoc group, return the name of the parent group."
1784 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1785 (gnus-group-get-parameter group 'save-article-group)))
1787 (defun gnus-summary-save-in-rmail (&optional filename)
1788 "Append this article to Rmail file.
1789 Optional argument FILENAME specifies file name.
1790 Directory to save to is default to `gnus-article-save-directory'."
1791 (setq filename (gnus-read-save-file-name
1792 "Save %s in rmail file:" filename
1793 gnus-rmail-save-name gnus-newsgroup-name
1794 gnus-current-headers 'gnus-newsgroup-last-rmail))
1795 (gnus-eval-in-buffer-window gnus-save-article-buffer
1799 (gnus-output-to-rmail filename))))
1802 (defun gnus-summary-save-in-mail (&optional filename)
1803 "Append this article to Unix mail file.
1804 Optional argument FILENAME specifies file name.
1805 Directory to save to is default to `gnus-article-save-directory'."
1806 (setq filename (gnus-read-save-file-name
1807 "Save %s in Unix mail file:" filename
1808 gnus-mail-save-name gnus-newsgroup-name
1809 gnus-current-headers 'gnus-newsgroup-last-mail))
1810 (gnus-eval-in-buffer-window gnus-save-article-buffer
1814 (if (and (file-readable-p filename)
1815 (mail-file-babyl-p filename))
1816 (rmail-output-to-rmail-file filename t)
1817 (gnus-output-to-mail filename)))))
1820 (defun gnus-summary-save-in-file (&optional filename overwrite)
1821 "Append this article to file.
1822 Optional argument FILENAME specifies file name.
1823 Directory to save to is default to `gnus-article-save-directory'."
1824 (setq filename (gnus-read-save-file-name
1825 "Save %s in file:" filename
1826 gnus-file-save-name gnus-newsgroup-name
1827 gnus-current-headers 'gnus-newsgroup-last-file))
1828 (gnus-eval-in-buffer-window gnus-save-article-buffer
1832 (when (and overwrite
1833 (file-exists-p filename))
1834 (delete-file filename))
1835 (gnus-output-to-file filename))))
1838 (defun gnus-summary-write-to-file (&optional filename)
1839 "Write this article to a file.
1840 Optional argument FILENAME specifies file name.
1841 The directory to save in defaults to `gnus-article-save-directory'."
1842 (gnus-summary-save-in-file nil t))
1844 (defun gnus-summary-save-body-in-file (&optional filename)
1845 "Append this article body to a file.
1846 Optional argument FILENAME specifies file name.
1847 The directory to save in defaults to `gnus-article-save-directory'."
1848 (setq filename (gnus-read-save-file-name
1849 "Save %s body in file:" filename
1850 gnus-file-save-name gnus-newsgroup-name
1851 gnus-current-headers 'gnus-newsgroup-last-file))
1852 (gnus-eval-in-buffer-window gnus-save-article-buffer
1856 (when (article-goto-body)
1857 (narrow-to-region (point) (point-max)))
1858 (gnus-output-to-file filename))))
1861 (defun gnus-summary-save-in-pipe (&optional command)
1862 "Pipe this article to subprocess."
1864 (cond ((and (eq command 'default)
1865 gnus-last-shell-command)
1866 gnus-last-shell-command)
1870 "Shell command on %s: "
1871 (if (and gnus-number-of-articles-to-be-saved
1872 (> gnus-number-of-articles-to-be-saved 1))
1873 (format "these %d articles"
1874 gnus-number-of-articles-to-be-saved)
1876 gnus-last-shell-command))))
1877 (when (string-equal command "")
1878 (setq command gnus-last-shell-command))
1879 (gnus-eval-in-buffer-window gnus-article-buffer
1882 (shell-command-on-region (point-min) (point-max) command nil)))
1883 (setq gnus-last-shell-command command))
1885 ;;; Article file names when saving.
1887 (defun gnus-capitalize-newsgroup (newsgroup)
1888 "Capitalize NEWSGROUP name."
1889 (when (not (zerop (length newsgroup)))
1890 (concat (char-to-string (upcase (aref newsgroup 0)))
1891 (substring newsgroup 1))))
1893 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1894 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1895 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1896 Otherwise, it is like ~/News/news/group/num."
1899 (concat (if (gnus-use-long-file-name 'not-save)
1900 (gnus-capitalize-newsgroup newsgroup)
1901 (gnus-newsgroup-directory-form newsgroup))
1902 "/" (int-to-string (mail-header-number headers)))
1903 gnus-article-save-directory)))
1905 (string-equal (file-name-directory default)
1906 (file-name-directory last-file))
1907 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1909 (or last-file default))))
1911 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1912 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1913 If variable `gnus-use-long-file-name' is non-nil, it is
1914 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1917 (concat (if (gnus-use-long-file-name 'not-save)
1919 (gnus-newsgroup-directory-form newsgroup))
1920 "/" (int-to-string (mail-header-number headers)))
1921 gnus-article-save-directory)))
1923 (string-equal (file-name-directory default)
1924 (file-name-directory last-file))
1925 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1927 (or last-file default))))
1929 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1930 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1931 If variable `gnus-use-long-file-name' is non-nil, it is
1932 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1935 (if (gnus-use-long-file-name 'not-save)
1936 (gnus-capitalize-newsgroup newsgroup)
1937 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1938 gnus-article-save-directory)))
1940 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1941 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1942 If variable `gnus-use-long-file-name' is non-nil, it is
1943 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1946 (if (gnus-use-long-file-name 'not-save)
1948 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1949 gnus-article-save-directory)))
1956 (setq afunc (car func)
1959 gfunc (intern (format "gnus-%s" func))))
1961 (if (not (fboundp afunc))
1963 `(lambda (&optional interactive &rest args)
1964 ,(documentation afunc t)
1965 (interactive (list t))
1967 (set-buffer gnus-article-buffer)
1969 (call-interactively ',afunc)
1970 (apply ',afunc args))))))))
1971 '(article-hide-headers
1972 article-hide-boring-headers
1973 article-treat-overstrike
1974 (article-fill . gnus-article-word-wrap)
1976 article-display-x-face
1977 article-de-quoted-unreadable
1978 article-mime-decode-quoted-printable
1981 article-hide-signature
1982 article-remove-trailing-blank-lines
1983 article-strip-leading-blank-lines
1984 article-strip-multiple-blank-lines
1985 article-strip-leading-space
1986 article-strip-trailing-space
1987 article-strip-blank-lines
1988 article-strip-all-blank-lines
1990 article-date-iso8601
1991 article-date-original
1993 article-decode-mime-words
1994 article-decode-charset
1995 article-decode-encoded-words
1999 article-treat-dumbquotes
2000 (article-show-all . gnus-article-show-all-headers))))
2003 ;;; Gnus article mode
2006 (put 'gnus-article-mode 'mode-class 'special)
2008 (gnus-define-keys gnus-article-mode-map
2009 " " gnus-article-goto-next-page
2010 "\177" gnus-article-goto-prev-page
2011 [delete] gnus-article-goto-prev-page
2012 "\C-c^" gnus-article-refer-article
2013 "h" gnus-article-show-summary
2014 "s" gnus-article-show-summary
2015 "\C-c\C-m" gnus-article-mail
2016 "?" gnus-article-describe-briefly
2017 gnus-mouse-2 gnus-article-push-button
2018 "\r" gnus-article-press-button
2019 "\t" gnus-article-next-button
2020 "\M-\t" gnus-article-prev-button
2021 "e" gnus-article-edit
2022 "<" beginning-of-buffer
2024 "\C-c\C-i" gnus-info-find-node
2027 "\C-d" gnus-article-read-summary-keys
2028 "\M-*" gnus-article-read-summary-keys
2029 "\M-#" gnus-article-read-summary-keys
2030 "\M-^" gnus-article-read-summary-keys
2031 "\M-g" gnus-article-read-summary-keys)
2033 (substitute-key-definition
2034 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2036 (defun gnus-article-make-menu-bar ()
2037 (gnus-turn-off-edit-menu 'article)
2038 (unless (boundp 'gnus-article-article-menu)
2040 gnus-article-article-menu gnus-article-mode-map ""
2042 ["Scroll forwards" gnus-article-goto-next-page t]
2043 ["Scroll backwards" gnus-article-goto-prev-page t]
2044 ["Show summary" gnus-article-show-summary t]
2045 ["Fetch Message-ID at point" gnus-article-refer-article t]
2046 ["Mail to address at point" gnus-article-mail t]
2047 ["Send a bug report" gnus-bug t]))
2050 gnus-article-treatment-menu gnus-article-mode-map ""
2052 ["Hide headers" gnus-article-hide-headers t]
2053 ["Hide signature" gnus-article-hide-signature t]
2054 ["Hide citation" gnus-article-hide-citation t]
2055 ["Treat overstrike" gnus-article-treat-overstrike t]
2056 ["Remove carriage return" gnus-article-remove-cr t]))
2058 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2060 (when (boundp 'gnus-summary-post-menu)
2061 (define-key gnus-article-mode-map [menu-bar post]
2062 (cons "Post" gnus-summary-post-menu)))
2064 (gnus-run-hooks 'gnus-article-menu-hook)))
2066 (defun gnus-article-mode ()
2067 "Major mode for displaying an article.
2069 All normal editing commands are switched off.
2071 The following commands are available in addition to all summary mode
2073 \\<gnus-article-mode-map>
2074 \\[gnus-article-next-page]\t Scroll the article one page forwards
2075 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2076 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2077 \\[gnus-article-show-summary]\t Display the summary buffer
2078 \\[gnus-article-mail]\t Send a reply to the address near point
2079 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2080 \\[gnus-info-find-node]\t Go to the Gnus info node"
2082 (when (gnus-visual-p 'article-menu 'menu)
2083 (gnus-article-make-menu-bar))
2084 (gnus-simplify-mode-line)
2085 (setq mode-name "Article")
2086 (setq major-mode 'gnus-article-mode)
2087 (make-local-variable 'minor-mode-alist)
2088 (unless (assq 'gnus-show-mime minor-mode-alist)
2089 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2090 (use-local-map gnus-article-mode-map)
2091 (gnus-update-format-specifications nil 'article-mode)
2092 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2093 (make-local-variable 'gnus-page-broken)
2094 (make-local-variable 'gnus-button-marker-list)
2095 (make-local-variable 'gnus-article-current-summary)
2096 (make-local-variable 'gnus-article-mime-handles)
2097 (make-local-variable 'gnus-article-decoded-p)
2098 (make-local-variable 'gnus-article-mime-handle-alist)
2099 (gnus-set-default-directory)
2100 (buffer-disable-undo)
2101 (setq buffer-read-only t)
2102 (set-syntax-table gnus-article-mode-syntax-table)
2103 (gnus-run-hooks 'gnus-article-mode-hook))
2105 (defun gnus-article-setup-buffer ()
2106 "Initialize the article buffer."
2107 (let* ((name (if gnus-single-article-buffer "*Article*"
2108 (concat "*Article " gnus-newsgroup-name "*")))
2110 (progn (string-match "\\*Article" name)
2111 (concat " *Original Article"
2112 (substring name (match-end 0))))))
2113 (setq gnus-article-buffer name)
2114 (setq gnus-original-article-buffer original)
2115 (setq gnus-article-mime-handle-alist nil)
2116 ;; This might be a variable local to the summary buffer.
2117 (unless gnus-single-article-buffer
2119 (set-buffer gnus-summary-buffer)
2120 (setq gnus-article-buffer name)
2121 (setq gnus-original-article-buffer original)
2122 (gnus-set-global-variables)))
2123 ;; Init original article buffer.
2125 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2126 (setq major-mode 'gnus-original-article-mode)
2127 (make-local-variable 'gnus-original-article))
2128 (if (get-buffer name)
2131 (buffer-disable-undo)
2132 (setq buffer-read-only t)
2133 (unless (eq major-mode 'gnus-article-mode)
2134 (gnus-article-mode))
2137 (set-buffer (gnus-get-buffer-create name))
2139 (make-local-variable 'gnus-summary-buffer)
2140 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2141 (current-buffer)))))
2143 ;; Set article window start at LINE, where LINE is the number of lines
2144 ;; from the head of the article.
2145 (defun gnus-article-set-window-start (&optional line)
2147 (get-buffer-window gnus-article-buffer t)
2149 (set-buffer gnus-article-buffer)
2150 (goto-char (point-min))
2153 (gnus-message 6 "Moved to bookmark")
2154 (search-forward "\n\n" nil t)
2158 ;;; @@ article filters
2161 (defun gnus-article-display-mime-message ()
2162 "Article display method for MIME message."
2163 ;; called from `gnus-original-article-buffer'.
2164 (let ((charset (with-current-buffer gnus-summary-buffer
2165 default-mime-charset)))
2166 (make-local-variable 'default-mime-charset)
2167 (setq default-mime-charset charset)
2168 (mime-display-message mime-message-structure
2169 gnus-article-buffer nil gnus-article-mode-map)
2170 (make-local-variable 'default-mime-charset)
2171 (setq default-mime-charset charset)
2173 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2174 (make-local-variable 'mime-button-mother-dispatcher)
2175 (setq mime-button-mother-dispatcher
2176 (function gnus-article-push-button))
2177 (run-hooks 'gnus-mime-article-prepare-hook))
2179 (defun gnus-article-display-traditional-message ()
2180 "Article display method for traditional message."
2181 (set-buffer gnus-article-buffer)
2182 (let (buffer-read-only)
2184 (insert-buffer-substring gnus-original-article-buffer)))
2186 (defun gnus-article-make-full-mail-header (&optional number charset)
2187 "Create a new mail header structure in a raw article buffer."
2188 (unless (and number charset)
2189 (save-current-buffer
2190 (set-buffer gnus-summary-buffer)
2192 (setq number (or (cdr gnus-article-current) 0)))
2194 (setq charset (or default-mime-charset 'x-ctext)))))
2195 (goto-char (point-min))
2196 (let ((header-end (if (search-forward "\n\n" nil t)
2198 (goto-char (point-max))))
2199 (chars (- (point-max) (point)))
2200 (lines (count-lines (point) (point-max)))
2201 (default-mime-charset charset)
2203 (narrow-to-region (point-min) header-end)
2204 (setq xref (std11-fetch-field "xref"))
2206 (make-full-mail-header
2208 (std11-fetch-field "subject")
2209 (std11-fetch-field "from")
2210 (std11-fetch-field "date")
2211 (std11-fetch-field "message-id")
2212 (std11-fetch-field "references")
2215 (when xref (concat "Xref: " xref)))
2218 (defun gnus-article-prepare (article &optional all-headers header)
2219 "Prepare ARTICLE in article mode buffer.
2220 ARTICLE should either be an article number or a Message-ID.
2221 If ARTICLE is an id, HEADER should be the article headers.
2222 If ALL-HEADERS is non-nil, no headers are hidden."
2224 ;; Make sure we start in a summary buffer.
2225 (unless (eq major-mode 'gnus-summary-mode)
2226 (set-buffer gnus-summary-buffer))
2227 (setq gnus-summary-buffer (current-buffer))
2228 (let* ((gnus-article (if header (mail-header-number header) article))
2229 (summary-buffer (current-buffer))
2230 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2231 (group gnus-newsgroup-name)
2234 (gnus-article-setup-buffer)
2235 (set-buffer gnus-original-article-buffer)
2236 ;; Deactivate active regions.
2237 (when (and (boundp 'transient-mark-mode)
2238 transient-mark-mode)
2239 (setq mark-active nil))
2240 (if (not (setq result (let ((buffer-read-only nil))
2241 (gnus-request-article-this-buffer
2243 ;; There is no such article.
2245 (when (and (numberp article)
2246 (not (memq article gnus-newsgroup-sparse)))
2247 (setq gnus-article-current
2248 (cons gnus-newsgroup-name article))
2249 (set-buffer gnus-summary-buffer)
2250 (setq gnus-current-article article)
2251 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2253 (gnus-summary-set-agent-mark article)
2254 (message "Message marked for downloading"))
2255 (gnus-summary-mark-article article gnus-canceled-mark)
2256 (unless (memq article gnus-newsgroup-sparse)
2258 "No such article (may have expired or been canceled)")))))
2259 (if (or (eq result 'pseudo)
2260 (eq result 'nneething))
2263 (set-buffer summary-buffer)
2264 (push article gnus-newsgroup-history)
2265 (setq gnus-last-article gnus-current-article
2266 gnus-current-article 0
2267 gnus-current-headers nil
2268 gnus-article-current nil)
2269 (if (eq result 'nneething)
2270 (gnus-configure-windows 'summary)
2271 (gnus-configure-windows 'article))
2272 (gnus-set-global-variables))
2273 (let ((gnus-article-mime-handle-alist-1
2274 gnus-article-mime-handle-alist))
2275 (gnus-set-mode-line 'article)))
2276 ;; The result from the `request' was an actual article -
2277 ;; or at least some text that is now displayed in the
2279 (when (and (numberp article)
2280 (not (eq article gnus-current-article)))
2281 ;; Seems like a new article has been selected.
2282 ;; `gnus-current-article' must be an article number.
2284 (set-buffer summary-buffer)
2285 (push article gnus-newsgroup-history)
2286 (setq gnus-last-article gnus-current-article
2287 gnus-current-article article
2288 gnus-current-headers
2289 (gnus-summary-article-header gnus-current-article)
2290 gnus-article-current
2291 (cons gnus-newsgroup-name gnus-current-article))
2292 (unless (vectorp gnus-current-headers)
2293 (setq gnus-current-headers nil))
2294 (gnus-summary-goto-subject gnus-current-article)
2295 (when (gnus-summary-show-thread)
2296 ;; If the summary buffer really was folded, the
2297 ;; previous goto may not actually have gone to
2298 ;; the right article, but the thread root instead.
2300 (gnus-summary-goto-subject gnus-current-article))
2301 (gnus-run-hooks 'gnus-mark-article-hook)
2302 (gnus-set-mode-line 'summary)
2303 (when (gnus-visual-p 'article-highlight 'highlight)
2304 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2305 ;; Set the global newsgroup variables here.
2306 ;; Suggested by Jim Sisolak
2307 ;; <sisolak@trans4.neep.wisc.edu>.
2308 (gnus-set-global-variables)
2309 (setq gnus-have-all-headers
2310 (or all-headers gnus-show-all-headers))))
2311 (when (or (numberp article)
2313 (gnus-article-prepare-display)
2315 (goto-char (point-min))
2316 (setq gnus-page-broken
2317 (when gnus-break-pages
2318 (gnus-narrow-to-page)
2320 (let ((gnus-article-mime-handle-alist-1
2321 gnus-article-mime-handle-alist))
2322 (gnus-set-mode-line 'article))
2323 (gnus-configure-windows 'article)
2325 (set-window-point (get-buffer-window (current-buffer)) (point))
2328 (defun gnus-article-prepare-display ()
2329 "Make the current buffer look like a nice article."
2333 (setq mime-message-structure gnus-current-headers)
2334 gnus-article-display-method-for-mime)
2335 gnus-article-display-method-for-traditional)))
2336 (gnus-run-hooks 'gnus-tmp-internal-hook)
2337 (gnus-run-hooks 'gnus-article-prepare-hook)
2340 ;; Associate this article with the current summary buffer.
2341 (setq gnus-article-current-summary (current-buffer))
2342 ;; Perform the article display hooks.
2343 (gnus-run-hooks 'gnus-article-display-hook)))
2346 ;;; Gnus MIME viewing functions
2349 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2350 "The following specs can be used:
2352 %n The `name' parameter
2353 %d The description, if any
2354 %l The length of the encoded part
2355 %p The part identifier
2356 %e Dots if the part isn't displayed")
2358 (defvar gnus-mime-button-line-format-alist
2359 '((?t gnus-tmp-type ?s)
2360 (?n gnus-tmp-name ?s)
2361 (?d gnus-tmp-description ?s)
2363 (?l gnus-tmp-length ?d)
2364 (?e gnus-tmp-dots ?s)))
2366 (defvar gnus-mime-button-commands
2367 '((gnus-article-press-button "\r" "Toggle Display")
2368 (gnus-mime-view-part "v" "View Interactively...")
2369 (gnus-mime-save-part "o" "Save...")
2370 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2371 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2372 (gnus-mime-internalize-part "E" "View Internally")
2373 (gnus-mime-externalize-part "e" "View Externally")
2374 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2376 (defun gnus-article-mime-part-status ()
2377 (if gnus-article-mime-handle-alist-1
2378 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2381 (defvar gnus-mime-button-map nil)
2382 (unless gnus-mime-button-map
2383 (setq gnus-mime-button-map (make-sparse-keymap))
2384 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2385 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2386 (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2388 (define-key gnus-mime-button-map (cadr c) (car c)))
2389 gnus-mime-button-commands))
2391 (defun gnus-mime-button-menu (event)
2392 "Construct a context-sensitive menu of MIME commands."
2394 (gnus-article-check-buffer)
2395 (let ((response (x-popup-menu
2397 ("" ,@(mapcar (lambda (c)
2398 (cons (caddr c) (car c)))
2399 gnus-mime-button-commands)))))
2400 (pos (event-start event)))
2402 (set-buffer (window-buffer (posn-window pos)))
2403 (goto-char (posn-point pos))
2404 (funcall response))))
2406 (defun gnus-mime-view-all-parts ()
2407 "View all the MIME parts."
2409 (save-current-buffer
2410 (set-buffer gnus-article-buffer)
2411 (let ((handles gnus-article-mime-handles)
2412 (rfc2047-default-charset gnus-newsgroup-default-charset)
2413 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2415 (mm-display-part (pop handles))))))
2417 (defun gnus-mime-save-part ()
2418 "Save the MIME part under point."
2420 (gnus-article-check-buffer)
2421 (let ((data (get-text-property (point) 'gnus-data)))
2422 (mm-save-part data)))
2424 (defun gnus-mime-pipe-part ()
2425 "Pipe the MIME part under point to a process."
2427 (gnus-article-check-buffer)
2428 (let ((data (get-text-property (point) 'gnus-data)))
2429 (mm-pipe-part data)))
2431 (defun gnus-mime-view-part ()
2432 "Interactively choose a view method for the MIME part under point."
2434 (gnus-article-check-buffer)
2435 (let ((data (get-text-property (point) 'gnus-data))
2436 (url-standalone-mode (not gnus-plugged)))
2437 (mm-interactively-view-part data)))
2439 (defun gnus-mime-copy-part (&optional handle)
2440 "Put the the MIME part under point into a new buffer."
2442 (gnus-article-check-buffer)
2443 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2444 (contents (mm-get-part handle))|
2445 (base (file-name-nondirectory
2447 (mail-content-type-get (mm-handle-type handle) 'name)
2448 (mail-content-type-get (mm-handle-type handle)
2451 (buffer (generate-new-buffer base)))
2452 (switch-to-buffer buffer)
2454 ;; We do it this way to make `normal-mode' set the appropriate mode.
2457 (setq buffer-file-name (expand-file-name base))
2459 (setq buffer-file-name nil))
2460 (goto-char (point-min))))
2462 (defun gnus-mime-inline-part (&optional charset)
2463 "Insert the MIME part under point into the current buffer."
2464 (interactive "P") ; For compatibility reasons we are not using "z".
2465 (gnus-article-check-buffer)
2466 (let* ((data (get-text-property (point) 'gnus-data))
2468 (url-standalone-mode (not gnus-plugged))
2471 (if (mm-handle-undisplayer data)
2472 (mm-remove-part data)
2473 (setq contents (mm-get-part data))
2476 (unless (symbolp charset)
2477 (setq charset (mm-read-coding-system "Charset: ")))
2478 (setq contents (mm-decode-coding-string contents charset)))
2479 (mm-insert-inline data contents)
2482 (defun gnus-mime-externalize-part (&optional handle)
2483 "View the MIME part under point with an external viewer."
2485 (gnus-article-check-buffer)
2486 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2487 (url-standalone-mode (not gnus-plugged))
2488 (mm-user-display-methods nil)
2489 (mm-all-images-fit t)
2490 (rfc2047-default-charset gnus-newsgroup-default-charset)
2491 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2492 (if (mm-handle-undisplayer handle)
2493 (mm-remove-part handle)
2494 (mm-display-part handle))))
2496 (defun gnus-mime-internalize-part (&optional handle)
2497 "View the MIME part under point with an internal viewer."
2499 (gnus-article-check-buffer)
2500 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2501 (url-standalone-mode (not gnus-plugged))
2502 (mm-user-display-methods '(".*"))
2503 (rfc2047-default-charset gnus-newsgroup-default-charset)
2504 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2505 (if (mm-handle-undisplayer handle)
2506 (mm-remove-part handle)
2507 (mm-display-part handle))))
2509 (defun gnus-article-part-wrapper (n function)
2510 (save-current-buffer
2511 (set-buffer gnus-article-buffer)
2512 (when (> n (length gnus-article-mime-handle-alist))
2513 (error "No such part"))
2514 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2515 (funcall function handle))))
2517 (defun gnus-article-pipe-part (n)
2518 "Pipe MIME part N, which is the numerical prefix."
2520 (gnus-article-part-wrapper n 'mm-pipe-part))
2522 (defun gnus-article-save-part (n)
2523 "Save MIME part N, which is the numerical prefix."
2525 (gnus-article-part-wrapper n 'mm-save-part))
2527 (defun gnus-article-interactively-view-part (n)
2528 "Pipe MIME part N, which is the numerical prefix."
2530 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2532 (defun gnus-article-copy-part (n)
2533 "Pipe MIME part N, which is the numerical prefix."
2535 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2537 (defun gnus-article-externalize-part (n)
2538 "Pipe MIME part N, which is the numerical prefix."
2540 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2542 (defun gnus-article-view-part (n)
2543 "View MIME part N, which is the numerical prefix."
2545 (save-current-buffer
2546 (set-buffer gnus-article-buffer)
2547 (when (> n (length gnus-article-mime-handle-alist))
2548 (error "No such part"))
2549 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2550 (when (gnus-article-goto-part n)
2551 (if (equal (car handle) "multipart/alternative")
2552 (gnus-article-press-button)
2553 (when (eq (gnus-mm-display-part handle) 'internal)
2554 (gnus-set-window-start)))))))
2556 (defun gnus-mm-display-part (handle)
2557 "Display HANDLE and fix MIME button."
2558 (let ((id (get-text-property (point) 'gnus-part))
2561 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2562 (gnus-insert-mime-button
2563 handle id (list (not (mm-handle-displayed-p handle))))
2565 (let ((window (selected-window))
2566 (rfc2047-default-charset gnus-newsgroup-default-charset)
2567 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2570 (let ((win (get-buffer-window (current-buffer) t)))
2572 (select-window win))
2575 (mm-display-part handle))
2576 (select-window window))))
2577 (goto-char point))))
2579 (defun gnus-article-goto-part (n)
2580 "Go to MIME part N."
2581 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2583 (goto-char point))))
2585 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2586 (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2587 (filename (mail-content-type-get (mm-handle-disposition handle)
2589 (gnus-tmp-type (car (mm-handle-type handle)))
2590 (gnus-tmp-description (mm-handle-description handle))
2592 (if (if displayed (car displayed)
2593 (mm-handle-displayed-p handle))
2595 (gnus-tmp-length (save-excursion
2596 (set-buffer (mm-handle-buffer handle))
2599 (setq gnus-tmp-name (or gnus-tmp-name filename))
2602 (concat " (" gnus-tmp-name ")")
2604 (setq gnus-tmp-description
2605 (if gnus-tmp-description
2606 (concat " (" gnus-tmp-description ")")
2612 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2613 `(local-map ,gnus-mime-button-map
2614 keymap ,gnus-mime-button-map
2615 gnus-callback gnus-mm-display-part
2616 gnus-part ,gnus-tmp-id
2617 article-type annotation
2620 (widget-convert-button 'link b e :action 'gnus-widget-press-button
2621 :button-keymap gnus-mime-button-map)))
2623 (defun gnus-widget-press-button (elems el)
2624 (goto-char (widget-get elems :from))
2625 (let ((url-standalone-mode (not gnus-plugged)))
2626 (gnus-article-press-button)))
2628 (defun gnus-display-mime (&optional ihandles)
2629 "Insert MIME buttons in the buffer."
2631 (save-selected-window
2632 (let ((window (get-buffer-window gnus-article-buffer)))
2634 (select-window window)))
2635 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2636 handle name type b e display)
2638 ;; Top-level call; we clean up.
2639 (mm-destroy-parts gnus-article-mime-handles)
2640 (setq gnus-article-mime-handles handles
2641 gnus-article-mime-handle-alist nil)
2642 ;; We allow users to glean info from the handles.
2643 (when gnus-article-mime-part-function
2644 (gnus-mime-part-function handles)))
2646 (or (not (stringp (car handles)))
2649 ;; Clean up for mime parts.
2651 (delete-region (point) (point-max)))
2652 (gnus-mime-display-part handles))))))
2654 (defun gnus-mime-display-part (handle)
2657 ((not (stringp (car handle)))
2658 (gnus-mime-display-single handle))
2659 ;; multipart/alternative
2660 ((equal (car handle) "multipart/alternative")
2661 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2662 (push (cons id handle) gnus-article-mime-handle-alist)
2663 (gnus-mime-display-alternative (cdr handle) nil nil id)))
2664 ;; multipart/related
2665 ((equal (car handle) "multipart/related")
2666 ;;;!!!We should find the start part, but we just default
2667 ;;;!!!to the first part.
2668 (gnus-mime-display-part (cadr handle)))
2669 ;; Other multiparts are handled like multipart/mixed.
2671 (gnus-mime-display-mixed (cdr handle)))))
2673 (defun gnus-mime-part-function (handles)
2674 (if (stringp (car handles))
2675 (mapcar 'gnus-mime-part-function (cdr handles))
2676 (funcall gnus-article-mime-part-function handles)))
2678 (defun gnus-mime-display-mixed (handles)
2679 (mapcar 'gnus-mime-display-part handles))
2681 (defun gnus-mime-display-single (handle)
2682 (let ((type (car (mm-handle-type handle)))
2683 (ignored gnus-ignored-mime-types)
2690 (when (string-match (pop ignored) type)
2691 (throw 'ignored nil)))
2692 (if (and (mm-automatic-display-p type)
2693 (or (mm-inlinable-part-p type)
2694 (mm-automatic-external-display-p type))
2695 (setq not-attachment
2696 (or (not (mm-handle-disposition handle))
2697 (equal (car (mm-handle-disposition handle))
2700 (when (equal (car (split-string type "/"))
2703 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2704 (push (cons id handle) gnus-article-mime-handle-alist)
2705 (when (or (not display)
2706 (not (gnus-unbuttonized-mime-type-p type)))
2707 (gnus-article-insert-newline)
2708 (gnus-insert-mime-button
2709 handle id (list (or display
2710 (and not-attachment text))))
2711 (gnus-article-insert-newline)
2712 (gnus-article-insert-newline)
2718 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2719 (mm-charset-iso-8859-1-forced
2720 gnus-newsgroup-iso-8859-1-forced))
2721 (mm-display-part handle t))
2722 (goto-char (point-max)))
2723 ((and text not-attachment)
2726 (gnus-article-insert-newline)
2727 (mm-insert-inline handle (mm-get-part handle))
2728 (goto-char (point-max))))))))
2730 (defun gnus-unbuttonized-mime-type-p (type)
2731 "Say whether TYPE is to be unbuttonized."
2732 (unless gnus-inhibit-mime-unbuttonizing
2734 (let ((types gnus-unbuttonized-mime-types))
2736 (when (string-match (pop types) type)
2737 (throw 'found t)))))))
2739 (defun gnus-article-insert-newline ()
2740 "Insert a newline, but mark it as undeletable."
2741 (gnus-put-text-property
2742 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2744 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2745 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2748 handle buffer-read-only from props begend not-pref)
2749 (save-window-excursion
2752 (narrow-to-region (car ibegend)
2755 (goto-char (car ibegend))
2758 (delete-region (point-min) (point-max))
2759 (mm-remove-parts handles))
2760 (setq begend (list (point-marker)))
2762 (unless (setq not-pref (cadr (member preferred ihandles)))
2763 (setq not-pref (car ihandles)))
2765 (not (gnus-unbuttonized-mime-type-p
2766 "multipart/alternative")))
2767 (gnus-add-text-properties
2770 (insert (format "%d. " id))
2774 (unless ,(not ibegend)
2775 (setq gnus-article-mime-handle-alist
2776 ',gnus-article-mime-handle-alist))
2777 (gnus-mime-display-alternative
2778 ',ihandles ',not-pref ',begend ,id))
2779 local-map ,gnus-mime-button-map
2780 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2781 face ,gnus-article-button-face
2782 keymap ,gnus-mime-button-map
2785 (widget-convert-button 'link from (point)
2786 :action 'gnus-widget-press-button
2787 :button-keymap gnus-widget-button-keymap)
2789 (while (setq handle (pop handles))
2790 (gnus-add-text-properties
2793 (insert (format "[%c] %-18s"
2794 (if (equal handle preferred) ?* ? )
2795 (if (stringp (car handle))
2797 (car (mm-handle-type handle)))))
2801 (unless ,(not ibegend)
2802 (setq gnus-article-mime-handle-alist
2803 ',gnus-article-mime-handle-alist))
2804 (gnus-mime-display-alternative
2805 ',ihandles ',handle ',begend ,id))
2806 local-map ,gnus-mime-button-map
2807 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2808 face ,gnus-article-button-face
2809 keymap ,gnus-mime-button-map
2812 (widget-convert-button 'link from (point)
2813 :action 'gnus-widget-press-button
2814 :button-keymap gnus-widget-button-keymap)
2818 (if (stringp (car preferred))
2819 (gnus-display-mime preferred)
2820 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2821 (mm-charset-iso-8859-1-forced
2822 gnus-newsgroup-iso-8859-1-forced))
2823 (mm-display-part preferred)))
2824 (goto-char (point-max))
2825 (setcdr begend (point-marker)))))
2827 (goto-char point))))
2829 (defun gnus-article-wash-status ()
2830 "Return a string which display status of article washing."
2832 (set-buffer gnus-article-buffer)
2833 (let ((cite (gnus-article-hidden-text-p 'cite))
2834 (headers (gnus-article-hidden-text-p 'headers))
2835 (boring (gnus-article-hidden-text-p 'boring-headers))
2836 (pgp (gnus-article-hidden-text-p 'pgp))
2837 (pem (gnus-article-hidden-text-p 'pem))
2838 (signature (gnus-article-hidden-text-p 'signature))
2839 (overstrike (gnus-article-hidden-text-p 'overstrike))
2840 (emphasis (gnus-article-hidden-text-p 'emphasis))
2841 (mime gnus-show-mime))
2842 (format "%c%c%c%c%c%c%c"
2844 (if (or headers boring) ?h ? )
2845 (if (or pgp pem) ?p ? )
2846 (if signature ?s ? )
2847 (if overstrike ?o ? )
2849 (if emphasis ?e ? )))))
2851 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2853 (defun gnus-article-maybe-hide-headers ()
2854 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2855 Provided for backwards compatibility."
2856 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2858 (gnus-article-hide-headers)))
2862 (defun gnus-output-to-file (file-name)
2863 "Append the current article to a file named FILE-NAME."
2864 (let ((artbuf (current-buffer)))
2866 (insert-buffer-substring artbuf)
2867 ;; Append newline at end of the buffer as separator, and then
2869 (goto-char (point-max))
2871 (append-to-file (point-min) (point-max) file-name)
2874 (defun gnus-narrow-to-page (&optional arg)
2875 "Narrow the article buffer to a page.
2876 If given a numerical ARG, move forward ARG pages."
2878 (setq arg (if arg (prefix-numeric-value arg) 0))
2880 (set-buffer gnus-article-buffer)
2881 (goto-char (point-min))
2883 ;; Remove any old next/prev buttons.
2884 (when (gnus-visual-p 'page-marker)
2885 (let ((buffer-read-only nil))
2886 (gnus-remove-text-with-property 'gnus-prev)
2887 (gnus-remove-text-with-property 'gnus-next)))
2890 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2892 (re-search-forward page-delimiter nil 'move arg)))
2893 (goto-char (match-end 0)))
2896 (if (re-search-forward page-delimiter nil 'move)
2899 (when (and (gnus-visual-p 'page-marker)
2900 (not (= (point-min) 1)))
2902 (goto-char (point-min))
2903 (gnus-insert-prev-page-button)))
2904 (when (and (gnus-visual-p 'page-marker)
2905 (< (+ (point-max) 2) (buffer-size)))
2907 (goto-char (point-max))
2908 (gnus-insert-next-page-button)))))
2910 ;; Article mode commands
2912 (defun gnus-article-goto-next-page ()
2913 "Show the next page of the article."
2915 (when (gnus-article-next-page)
2916 (goto-char (point-min))
2917 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2919 (defun gnus-article-goto-prev-page ()
2920 "Show the next page of the article."
2922 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2923 (gnus-article-prev-page nil)))
2925 (defun gnus-article-next-page (&optional lines)
2926 "Show the next page of the current article.
2927 If end of article, return non-nil. Otherwise return nil.
2928 Argument LINES specifies lines to be scrolled up."
2930 (move-to-window-line -1)
2933 (and (pos-visible-in-window-p) ;Not continuation line.
2935 ;; Nothing in this page.
2936 (if (or (not gnus-page-broken)
2939 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2941 (gnus-narrow-to-page 1) ;Go to next page.
2943 ;; More in this page.
2944 (let ((scroll-in-place nil))
2948 ;; Long lines may cause an end-of-buffer error.
2949 (goto-char (point-max)))))
2950 (move-to-window-line 0)
2953 (defun gnus-article-prev-page (&optional lines)
2954 "Show previous page of current article.
2955 Argument LINES specifies lines to be scrolled down."
2957 (move-to-window-line 0)
2958 (if (and gnus-page-broken
2960 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2962 (gnus-narrow-to-page -1) ;Go to previous page.
2963 (goto-char (point-max))
2965 (let ((scroll-in-place nil))
2969 (beginning-of-buffer
2970 (goto-char (point-min))))
2971 (move-to-window-line 0)))))
2973 (defun gnus-article-refer-article ()
2974 "Read article specified by message-id around point."
2976 (let ((point (point)))
2977 (search-forward ">" nil t) ;Move point to end of "<....>".
2978 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2979 (let ((message-id (match-string 1)))
2981 (set-buffer gnus-summary-buffer)
2982 (gnus-summary-refer-article message-id))
2984 (error "No references around point"))))
2986 (defun gnus-article-show-summary ()
2987 "Reconfigure windows to show summary buffer."
2989 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2990 (error "There is no summary buffer for this article buffer")
2991 (gnus-article-set-globals)
2992 (gnus-configure-windows 'article)
2993 (gnus-summary-goto-subject gnus-current-article)
2994 (gnus-summary-position-point)))
2996 (defun gnus-article-describe-briefly ()
2997 "Describe article mode commands briefly."
3000 (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")))
3002 (defun gnus-article-summary-command ()
3003 "Execute the last keystroke in the summary buffer."
3005 (let ((obuf (current-buffer))
3006 (owin (current-window-configuration))
3008 (switch-to-buffer gnus-article-current-summary 'norecord)
3009 (setq func (lookup-key (current-local-map) (this-command-keys)))
3010 (call-interactively func)
3012 (set-window-configuration owin)
3013 (set-window-point (get-buffer-window (current-buffer)) (point))))
3015 (defun gnus-article-summary-command-nosave ()
3016 "Execute the last keystroke in the summary buffer."
3019 (pop-to-buffer gnus-article-current-summary 'norecord)
3020 (setq func (lookup-key (current-local-map) (this-command-keys)))
3021 (call-interactively func)))
3023 (defun gnus-article-check-buffer ()
3024 "Beep if not in an article buffer."
3025 (unless (equal major-mode 'gnus-article-mode)
3026 (error "Command invoked outside of a Gnus article buffer")))
3028 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3029 "Read a summary buffer key sequence and execute it from the article buffer."
3031 (gnus-article-check-buffer)
3033 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3034 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3035 "=" "^" "\M-^" "|"))
3041 '("n" "Gn" "p" "Gp"))
3044 (set-buffer gnus-article-current-summary)
3045 (let (gnus-pick-mode)
3046 (push (or key last-command-event) unread-command-events)
3047 (setq keys (read-key-sequence nil))))
3050 (if (or (member keys nosaves)
3051 (member keys nosave-but-article)
3052 (member keys nosave-in-article))
3054 (save-window-excursion
3055 (pop-to-buffer gnus-article-current-summary 'norecord)
3056 ;; We disable the pick minor mode commands.
3057 (let (gnus-pick-mode)
3058 (setq func (lookup-key (current-local-map) keys))))
3061 (unless (member keys nosave-in-article)
3062 (set-buffer gnus-article-current-summary))
3063 (call-interactively func)
3064 (setq new-sum-point (point)))
3065 (when (member keys nosave-but-article)
3066 (pop-to-buffer gnus-article-buffer 'norecord)))
3067 ;; These commands should restore window configuration.
3068 (let ((obuf (current-buffer))
3069 (owin (current-window-configuration))
3071 (summary gnus-article-current-summary)
3072 func in-buffer selected)
3073 (if not-restore-window
3074 (pop-to-buffer summary 'norecord)
3075 (switch-to-buffer summary 'norecord))
3076 (setq in-buffer (current-buffer))
3077 ;; We disable the pick minor mode commands.
3078 (if (setq func (let (gnus-pick-mode)
3079 (lookup-key (current-local-map) keys)))
3081 (call-interactively func)
3082 (setq new-sum-point (point)))
3084 (when (eq in-buffer (current-buffer))
3085 (setq selected (gnus-summary-select-article))
3087 (unless not-restore-window
3088 (set-window-configuration owin))
3089 (unless (or (not (eq selected 'old)) (member keys up-to-top))
3090 (set-window-point (get-buffer-window (current-buffer))
3092 (let ((win (get-buffer-window gnus-article-current-summary)))
3094 (set-window-point win new-sum-point))))))))
3096 (defun gnus-article-hide (&optional arg force)
3097 "Hide all the gruft in the current article.
3098 This means that PGP stuff, signatures, cited text and (some)
3099 headers will be hidden.
3100 If given a prefix, show the hidden text instead."
3101 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3102 (gnus-article-hide-headers arg)
3103 (gnus-article-hide-pgp arg)
3104 (gnus-article-hide-citation-maybe arg force)
3105 (gnus-article-hide-signature arg))
3107 (defun gnus-article-maybe-highlight ()
3108 "Do some article highlighting if article highlighting is requested."
3109 (when (gnus-visual-p 'article-highlight 'highlight)
3110 (gnus-article-highlight-some)))
3112 (defun gnus-check-group-server ()
3113 ;; Make sure the connection to the server is alive.
3114 (unless (gnus-server-opened
3115 (gnus-find-method-for-group gnus-newsgroup-name))
3116 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3117 (gnus-request-group gnus-newsgroup-name t)))
3119 (defun gnus-request-article-this-buffer (article group)
3120 "Get an article and insert it into this buffer."
3121 (let (do-update-line sparse-header)
3125 (gnus-kill-all-overlays)
3126 (setq group (or group gnus-newsgroup-name))
3128 ;; Using `gnus-request-article' directly will insert the article into
3129 ;; `nntp-server-buffer' - so we'll save some time by not having to
3130 ;; copy it from the server buffer into the article buffer.
3132 ;; We only request an article by message-id when we do not have the
3133 ;; headers for it, so we'll have to get those.
3134 (when (stringp article)
3135 (let ((gnus-override-method gnus-refer-article-method))
3136 (gnus-read-header article)))
3138 ;; If the article number is negative, that means that this article
3139 ;; doesn't belong in this newsgroup (possibly), so we find its
3140 ;; message-id and request it by id instead of number.
3141 (when (and (numberp article)
3143 (get-buffer gnus-summary-buffer)
3144 (gnus-buffer-exists-p gnus-summary-buffer))
3146 (set-buffer gnus-summary-buffer)
3147 (let ((header (gnus-summary-article-header article)))
3150 ((memq article gnus-newsgroup-sparse)
3151 ;; This is a sparse gap article.
3152 (setq do-update-line article)
3153 (setq article (mail-header-id header))
3154 (let ((gnus-override-method gnus-refer-article-method))
3155 (setq sparse-header (gnus-read-header article)))
3156 (setq gnus-newsgroup-sparse
3157 (delq article gnus-newsgroup-sparse)))
3159 ;; It's a real article.
3160 (setq article (mail-header-id header)))
3162 ;; It is an extracted pseudo-article.
3163 (setq article 'pseudo)
3164 (gnus-request-pseudo-article header))))
3166 (let ((method (gnus-find-method-for-group
3167 gnus-newsgroup-name)))
3168 (when (and (eq (car method) 'nneething)
3171 (file-name-as-directory
3172 (or (cadr (assq 'nneething-address method))
3174 (mail-header-subject header))))
3175 (when (file-directory-p dir)
3176 (setq article 'nneething)
3177 (gnus-group-enter-directory dir))))))))
3180 ;; Refuse to select canceled articles.
3181 ((and (numberp article)
3183 (get-buffer gnus-summary-buffer)
3184 (gnus-buffer-exists-p gnus-summary-buffer)
3185 (eq (cdr (save-excursion
3186 (set-buffer gnus-summary-buffer)
3187 (assq article gnus-newsgroup-reads)))
3188 gnus-canceled-mark))
3190 ;; Check the backlog.
3191 ((and gnus-keep-backlog
3192 (gnus-backlog-request-article group article (current-buffer)))
3194 ;; Check asynchronous pre-fetch.
3195 ((gnus-async-request-fetched-article group article (current-buffer))
3196 (gnus-async-prefetch-next group article gnus-summary-buffer)
3197 (when (and (numberp article) gnus-keep-backlog)
3198 (gnus-backlog-enter-article group article (current-buffer)))
3201 ((and gnus-use-cache
3203 (gnus-cache-request-article article group))
3205 ;; Get the article and put into the article buffer.
3206 ((or (stringp article) (numberp article))
3207 (let ((gnus-override-method
3208 (and (stringp article) gnus-refer-article-method))
3209 (buffer-read-only nil))
3211 (gnus-kill-all-overlays)
3212 (gnus-check-group-server)
3213 (when (gnus-request-article article group (current-buffer))
3214 (when (numberp article)
3215 (gnus-async-prefetch-next group article gnus-summary-buffer)
3216 (when gnus-keep-backlog
3217 (gnus-backlog-enter-article
3218 group article (current-buffer))))
3223 ;; Associate this article with the current summary buffer.
3224 (setq gnus-article-current-summary gnus-summary-buffer)
3226 ;; Take the article from the original article buffer
3227 ;; and place it in the buffer it's supposed to be in.
3228 (when (and (get-buffer gnus-article-buffer)
3229 (equal (buffer-name (current-buffer))
3230 (buffer-name (get-buffer gnus-article-buffer))))
3232 (if (get-buffer gnus-original-article-buffer)
3233 (set-buffer gnus-original-article-buffer)
3234 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3235 (buffer-disable-undo)
3236 (setq major-mode 'gnus-original-article-mode)
3237 (setq buffer-read-only t))
3238 (let (buffer-read-only)
3240 (insert-buffer-substring gnus-article-buffer))
3241 (setq gnus-original-article (cons group article)))
3244 (run-hooks 'gnus-article-decode-hook)
3245 ;; Mark article as decoded or not.
3246 (setq gnus-article-decoded-p gnus-article-decode-hook))
3248 ;; Update sparse articles.
3249 (when (and do-update-line
3250 (or (numberp article)
3252 (let ((buf (current-buffer)))
3253 (set-buffer gnus-summary-buffer)
3254 (gnus-summary-update-article do-update-line sparse-header)
3255 (gnus-summary-goto-subject do-update-line nil t)
3256 (set-window-point (get-buffer-window (current-buffer) t)
3258 (set-buffer buf))))))
3264 (defcustom gnus-article-edit-mode-hook nil
3265 "Hook run in article edit mode buffers."
3266 :group 'gnus-article-various
3269 (defcustom gnus-article-edit-article-setup-function
3270 'gnus-article-mime-edit-article-setup
3271 "Function called to setup an editing article buffer."
3272 :group 'gnus-article-various
3275 (defvar gnus-article-edit-done-function nil)
3277 (defvar gnus-article-edit-mode-map nil)
3279 ;; Should we be using derived.el for this?
3280 (unless gnus-article-edit-mode-map
3281 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3282 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3284 (gnus-define-keys gnus-article-edit-mode-map
3285 "\C-c\C-c" gnus-article-edit-done
3286 "\C-c\C-k" gnus-article-edit-exit)
3288 (gnus-define-keys (gnus-article-edit-wash-map
3289 "\C-c\C-w" gnus-article-edit-mode-map)
3290 "f" gnus-article-edit-full-stops))
3292 (defun gnus-article-edit-mode ()
3293 "Major mode for editing articles.
3294 This is an extended text-mode.
3296 \\{gnus-article-edit-mode-map}"
3298 (setq major-mode 'gnus-article-edit-mode)
3299 (setq mode-name "Article Edit")
3300 (use-local-map gnus-article-edit-mode-map)
3301 (make-local-variable 'gnus-article-edit-done-function)
3302 (make-local-variable 'gnus-prev-winconf)
3303 (setq buffer-read-only nil)
3304 (buffer-enable-undo)
3306 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3308 (defun gnus-article-edit (&optional force)
3309 "Edit the current article.
3310 This will have permanent effect only in mail groups.
3311 If FORCE is non-nil, allow editing of articles even in read-only
3314 (when (and (not force)
3315 (gnus-group-read-only-p))
3316 (error "The current newsgroup does not support article editing"))
3317 (gnus-article-date-original)
3318 (gnus-article-edit-article
3319 `(lambda (no-highlight)
3320 (gnus-summary-edit-article-done
3321 ,(or (mail-header-references gnus-current-headers) "")
3322 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3324 (defun gnus-article-edit-article (exit-func)
3325 "Start editing the contents of the current article buffer."
3326 (let ((winconf (current-window-configuration)))
3327 (set-buffer gnus-article-buffer)
3328 (gnus-article-edit-mode)
3329 (gnus-article-delete-text-of-type 'annotation)
3330 (gnus-set-text-properties (point-min) (point-max) nil)
3331 (gnus-configure-windows 'edit-article)
3332 (setq gnus-article-edit-done-function exit-func)
3333 (setq gnus-prev-winconf winconf)
3334 (when gnus-article-edit-article-setup-function
3335 (funcall gnus-article-edit-article-setup-function))
3336 (gnus-message 6 "C-c C-c to end edits")))
3338 (defun gnus-article-edit-done (&optional arg)
3339 "Update the article edits and exit."
3344 (when (article-goto-body)
3345 (let ((lines (count-lines (point) (point-max)))
3346 (length (- (point-max) (point)))
3347 (case-fold-search t)
3348 (body (copy-marker (point))))
3349 (goto-char (point-min))
3350 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3351 (delete-region (match-beginning 1) (match-end 1))
3352 (insert (number-to-string length)))
3353 (goto-char (point-min))
3354 (when (re-search-forward
3355 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3356 (delete-region (match-beginning 1) (match-end 1))
3357 (insert (number-to-string length)))
3358 (goto-char (point-min))
3359 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3360 (delete-region (match-beginning 1) (match-end 1))
3361 (insert (number-to-string lines)))))))
3362 (let ((func gnus-article-edit-done-function)
3363 (buf (current-buffer))
3364 (start (window-start)))
3365 (remove-hook 'gnus-article-mode-hook
3366 'gnus-article-mime-edit-article-unwind)
3367 (gnus-article-edit-exit)
3370 (let ((buffer-read-only nil))
3372 ;; The cache and backlog have to be flushed somewhat.
3373 (when gnus-keep-backlog
3374 (gnus-backlog-remove-article
3375 (car gnus-article-current) (cdr gnus-article-current)))
3376 ;; Flush original article as well.
3378 (when (get-buffer gnus-original-article-buffer)
3379 (set-buffer gnus-original-article-buffer)
3380 (setq gnus-original-article nil)))
3381 (when gnus-use-cache
3382 (gnus-cache-update-article
3383 (car gnus-article-current) (cdr gnus-article-current))))
3385 (set-window-start (get-buffer-window buf) start)
3386 (set-window-point (get-buffer-window buf) (point))))
3388 (defun gnus-article-edit-exit ()
3389 "Exit the article editing without updating."
3391 ;; We remove all text props from the article buffer.
3392 (let ((buf (format "%s" (buffer-string)))
3393 (curbuf (current-buffer))
3395 (window-start (window-start)))
3398 (let ((winconf gnus-prev-winconf))
3400 (set-window-configuration winconf)
3401 ;; Tippy-toe some to make sure that point remains where it was.
3402 (save-current-buffer
3404 (set-window-start (get-buffer-window (current-buffer)) window-start)
3407 (defun gnus-article-edit-full-stops ()
3408 "Interactively repair spacing at end of sentences."
3411 (goto-char (point-min))
3412 (search-forward-regexp "^$" nil t)
3413 (let ((case-fold-search nil))
3414 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3417 ;;; Article editing with MIME-Edit
3420 (defcustom gnus-article-mime-edit-article-setup-hook nil
3421 "Hook run after setting up a MIME editing article buffer."
3422 :group 'gnus-article-various
3425 (defun gnus-article-mime-edit-article-unwind ()
3426 "Unwind `gnus-article-buffer' if article editing was given up."
3427 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3428 (when mime-edit-mode-flag
3429 (mime-edit-exit 'nomime 'no-error)
3431 (when (featurep 'font-lock)
3432 (setq font-lock-defaults nil)
3433 (font-lock-mode 0)))
3435 (defun gnus-article-mime-edit-article-setup ()
3436 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
3437 after replacing with the original article."
3438 (setq gnus-show-mime t)
3439 (setq gnus-article-edit-done-function
3440 `(lambda (&rest args)
3441 (when mime-edit-mode-flag
3444 (goto-char (point-min))
3445 (let (case-fold-search)
3446 (when (re-search-forward
3447 (format "^%s$" (regexp-quote mail-header-separator))
3449 (replace-match "")))
3450 (when (featurep 'font-lock)
3451 (setq font-lock-defaults nil)
3453 (apply ,gnus-article-edit-done-function args)
3454 (set-buffer gnus-original-article-buffer)
3456 (insert-buffer gnus-article-buffer)
3457 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3458 (gnus-article-prepare-display)))
3459 (substitute-key-definition
3460 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
3461 gnus-article-edit-mode-map)
3463 (insert-buffer gnus-original-article-buffer)
3465 (when (featurep 'font-lock)
3466 (set (make-local-variable 'font-lock-defaults)
3467 '(message-font-lock-keywords t))
3468 (font-lock-set-defaults)
3469 (turn-on-font-lock))
3470 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3471 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
3473 (defun gnus-article-mime-edit-exit ()
3474 "Exit the article MIME editing without updating."
3476 (let ((winconf gnus-prev-winconf)
3478 (when mime-edit-mode-flag
3481 (goto-char (point-min))
3482 (let (case-fold-search)
3483 (when (re-search-forward
3484 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
3485 (replace-match "")))
3486 (when (featurep 'font-lock)
3487 (setq font-lock-defaults nil)
3489 ;; We remove all text props from the article buffer.
3490 (setq buf (format "%s" (buffer-string)))
3491 (set-buffer (get-buffer-create gnus-original-article-buffer))
3494 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3495 (gnus-article-prepare-display)
3496 (set-window-configuration winconf)))
3499 ;;; Article highlights
3502 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3504 ;;; Internal Variables:
3506 (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\\)"
3507 "Regular expression that matches URLs."
3508 :group 'gnus-article-buttons
3511 (defcustom gnus-button-alist
3512 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3513 0 t gnus-button-message-id 2)
3514 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3515 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3517 gnus-button-fetch-group 4)
3518 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3519 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3520 t gnus-button-message-id 3)
3521 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3522 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3523 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3524 ;; This is how URLs _should_ be embedded in text...
3525 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3527 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3528 "*Alist of regexps matching buttons in article bodies.
3530 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3531 REGEXP: is the string matching text around the button,
3532 BUTTON: is the number of the regexp grouping actually matching the button,
3533 FORM: is a lisp expression which must eval to true for the button to
3535 CALLBACK: is the function to call when the user push this button, and each
3536 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3538 CALLBACK can also be a variable, in that case the value of that
3539 variable it the real callback function."
3540 :group 'gnus-article-buttons
3541 :type '(repeat (list regexp
3542 (integer :tag "Button")
3544 (function :tag "Callback")
3547 (integer :tag "Regexp group")))))
3549 (defcustom gnus-header-button-alist
3550 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3551 0 t gnus-button-message-id 0)
3552 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3553 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3554 0 t gnus-button-mailto 0)
3555 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3556 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3557 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3558 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3559 gnus-button-message-id 3))
3560 "*Alist of headers and regexps to match buttons in article heads.
3562 This alist is very similar to `gnus-button-alist', except that each
3563 alist has an additional HEADER element first in each entry:
3565 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3567 HEADER is a regexp to match a header. For a fuller explanation, see
3568 `gnus-button-alist'."
3569 :group 'gnus-article-buttons
3570 :group 'gnus-article-headers
3571 :type '(repeat (list (regexp :tag "Header")
3573 (integer :tag "Button")
3575 (function :tag "Callback")
3578 (integer :tag "Regexp group")))))
3580 (defvar gnus-button-regexp nil)
3581 (defvar gnus-button-marker-list nil)
3582 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3584 (defvar gnus-button-last nil)
3585 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3589 (defun gnus-article-push-button (event)
3590 "Check text under the mouse pointer for a callback function.
3591 If the text under the mouse pointer has a `gnus-callback' property,
3592 call it with the value of the `gnus-data' text property."
3594 (set-buffer (window-buffer (posn-window (event-start event))))
3595 (let* ((pos (posn-point (event-start event)))
3596 (data (get-text-property pos 'gnus-data))
3597 (fun (get-text-property pos 'gnus-callback)))
3600 (funcall fun data))))
3602 (defun gnus-article-press-button ()
3603 "Check text at point for a callback function.
3604 If the text at point has a `gnus-callback' property,
3605 call it with the value of the `gnus-data' text property."
3607 (let* ((data (get-text-property (point) 'gnus-data))
3608 (fun (get-text-property (point) 'gnus-callback)))
3610 (funcall fun data))))
3612 (defun gnus-article-prev-button (n)
3613 "Move point to N buttons backward.
3614 If N is negative, move forward instead."
3616 (gnus-article-next-button (- n)))
3618 (defun gnus-article-next-button (n)
3619 "Move point to N buttons forward.
3620 If N is negative, move backward instead."
3622 (let ((function (if (< n 0) 'previous-single-property-change
3623 'next-single-property-change))
3624 (inhibit-point-motion-hooks t)
3626 (limit (if (< n 0) (point-min) (point-max))))
3628 (while (and (not (= limit (point)))
3630 ;; Skip past the current button.
3631 (when (get-text-property (point) 'gnus-callback)
3632 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3633 ;; Go to the next (or previous) button.
3634 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
3635 ;; Put point at the start of the button.
3636 (when (and backward (not (get-text-property (point) 'gnus-callback)))
3637 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3638 ;; Skip past intangible buttons.
3639 (when (get-text-property (point) 'intangible)
3643 (gnus-message 5 "No more buttons"))
3646 (defun gnus-article-highlight (&optional force)
3647 "Highlight current article.
3648 This function calls `gnus-article-highlight-headers',
3649 `gnus-article-highlight-citation',
3650 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3651 do the highlighting. See the documentation for those functions."
3652 (interactive (list 'force))
3653 (gnus-article-highlight-headers)
3654 (gnus-article-highlight-citation force)
3655 (gnus-article-highlight-signature)
3656 (gnus-article-add-buttons force)
3657 (gnus-article-add-buttons-to-head))
3659 (defun gnus-article-highlight-some (&optional force)
3660 "Highlight current article.
3661 This function calls `gnus-article-highlight-headers',
3662 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3663 do the highlighting. See the documentation for those functions."
3664 (interactive (list 'force))
3665 (gnus-article-highlight-headers)
3666 (gnus-article-highlight-signature)
3667 (gnus-article-add-buttons))
3669 (defun gnus-article-highlight-headers ()
3670 "Highlight article headers as specified by `gnus-header-face-alist'."
3673 (set-buffer gnus-article-buffer)
3675 (let ((alist gnus-header-face-alist)
3676 (buffer-read-only nil)
3677 (case-fold-search t)
3678 (inhibit-point-motion-hooks t)
3679 entry regexp header-face field-face from hpoints fpoints)
3680 (message-narrow-to-head)
3681 (while (setq entry (pop alist))
3682 (goto-char (point-min))
3683 (setq regexp (concat "^\\("
3684 (if (string-equal "" (nth 0 entry))
3688 header-face (nth 1 entry)
3689 field-face (nth 2 entry))
3690 (while (and (re-search-forward regexp nil t)
3694 (unless (search-forward ":" nil t)
3696 (when (and header-face
3697 (not (memq (point) hpoints)))
3698 (push (point) hpoints)
3699 (gnus-put-text-property from (point) 'face header-face))
3700 (when (and field-face
3701 (not (memq (setq from (point)) fpoints)))
3703 (if (re-search-forward "^[^ \t]" nil t)
3705 (goto-char (point-max)))
3706 (gnus-put-text-property from (point) 'face field-face))))))))
3708 (defun gnus-article-highlight-signature ()
3709 "Highlight the signature in an article.
3710 It does this by highlighting everything after
3711 `gnus-signature-separator' using `gnus-signature-face'."
3714 (set-buffer gnus-article-buffer)
3715 (let ((buffer-read-only nil)
3716 (inhibit-point-motion-hooks t))
3718 (when (and gnus-signature-face
3719 (gnus-article-narrow-to-signature))
3720 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3721 'face gnus-signature-face)
3723 (gnus-article-search-signature)
3724 (let ((start (match-beginning 0))
3725 (end (set-marker (make-marker) (1+ (match-end 0)))))
3726 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3729 (defun gnus-button-in-region-p (b e prop)
3730 "Say whether PROP exists in the region."
3731 (text-property-not-all b e prop nil))
3733 (defun gnus-article-add-buttons (&optional force)
3734 "Find external references in the article and make buttons of them.
3735 \"External references\" are things like Message-IDs and URLs, as
3736 specified by `gnus-button-alist'."
3737 (interactive (list 'force))
3739 (set-buffer gnus-article-buffer)
3740 (let ((buffer-read-only nil)
3741 (inhibit-point-motion-hooks t)
3742 (case-fold-search t)
3743 (alist gnus-button-alist)
3745 ;; Remove all old markers.
3747 (while (setq marker (pop gnus-button-marker-list))
3749 (when (setq entry (gnus-button-entry))
3750 (put-text-property (match-beginning (nth 1 entry))
3751 (match-end (nth 1 entry))
3752 'gnus-callback nil))
3753 (set-marker marker nil)))
3754 ;; We skip the headers.
3757 (while (setq entry (pop alist))
3758 (setq regexp (car entry))
3760 (while (re-search-forward regexp nil t)
3761 (let* ((start (and entry (match-beginning (nth 1 entry))))
3762 (end (and entry (match-end (nth 1 entry))))
3763 (from (match-beginning 0)))
3764 (when (and (or (eq t (nth 2 entry))
3765 (eval (nth 2 entry)))
3766 (not (gnus-button-in-region-p
3767 start end 'gnus-callback)))
3768 ;; That optional form returned non-nil, so we add the
3770 (gnus-article-add-button
3771 start end 'gnus-button-push
3772 (car (push (set-marker (make-marker) from)
3773 gnus-button-marker-list))))))))))
3775 ;; Add buttons to the head of an article.
3776 (defun gnus-article-add-buttons-to-head ()
3777 "Add buttons to the head of the article."
3780 (set-buffer gnus-article-buffer)
3781 (let ((buffer-read-only nil)
3782 (inhibit-point-motion-hooks t)
3783 (case-fold-search t)
3784 (alist gnus-header-button-alist)
3786 (nnheader-narrow-to-headers)
3788 ;; Each alist entry.
3789 (setq entry (car alist)
3791 (goto-char (point-min))
3792 (while (re-search-forward (car entry) nil t)
3793 ;; Each header matching the entry.
3794 (setq beg (match-beginning 0))
3795 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3796 (match-beginning 0))
3799 (while (re-search-forward (nth 1 entry) end t)
3800 ;; Each match within a header.
3801 (let* ((entry (cdr entry))
3802 (start (match-beginning (nth 1 entry)))
3803 (end (match-end (nth 1 entry)))
3804 (form (nth 2 entry)))
3805 (goto-char (match-end 0))
3807 (gnus-article-add-button
3808 start end (nth 3 entry)
3809 (buffer-substring (match-beginning (nth 4 entry))
3810 (match-end (nth 4 entry)))))))
3814 ;;; External functions:
3816 (defun gnus-article-add-button (from to fun &optional data)
3817 "Create a button between FROM and TO with callback FUN and data DATA."
3818 (when gnus-article-button-face
3819 (gnus-overlay-put (gnus-make-overlay from to)
3820 'face gnus-article-button-face))
3821 (gnus-add-text-properties
3823 (nconc (and gnus-article-mouse-face
3824 (list gnus-mouse-face-prop gnus-article-mouse-face))
3825 (list 'gnus-callback fun)
3826 (and data (list 'gnus-data data)))))
3828 ;;; Internal functions:
3830 (defun gnus-article-set-globals ()
3832 (set-buffer gnus-summary-buffer)
3833 (gnus-set-global-variables)))
3835 (defun gnus-signature-toggle (end)
3837 (set-buffer gnus-article-buffer)
3838 (let ((buffer-read-only nil)
3839 (inhibit-point-motion-hooks t))
3840 (if (get-text-property end 'invisible)
3841 (gnus-article-unhide-text end (point-max))
3842 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3844 (defun gnus-button-entry ()
3845 ;; Return the first entry in `gnus-button-alist' matching this place.
3846 (let ((alist gnus-button-alist)
3849 (setq entry (pop alist))
3850 (if (looking-at (car entry))
3855 (defun gnus-button-push (marker)
3856 ;; Push button starting at MARKER.
3859 (let* ((entry (gnus-button-entry))
3860 (inhibit-point-motion-hooks t)
3862 (args (mapcar (lambda (group)
3863 (let ((string (match-string group)))
3864 (gnus-set-text-properties
3865 0 (length string) nil string)
3872 (fboundp (symbol-value fun)))
3873 (apply (symbol-value fun) args))
3875 (gnus-message 1 "You must define `%S' to use this button"
3876 (cons fun args)))))))
3878 (defun gnus-button-message-id (message-id)
3881 (set-buffer gnus-summary-buffer)
3882 (gnus-summary-refer-article message-id)))
3884 (defun gnus-button-fetch-group (address)
3885 "Fetch GROUP specified by ADDRESS."
3886 (if (not (string-match "[:/]" address))
3887 ;; This is just a simple group url.
3888 (gnus-group-read-ephemeral-group address gnus-select-method)
3889 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3891 (error "Can't parse %s" address)
3892 (gnus-group-read-ephemeral-group
3893 (match-string 4 address)
3894 `(nntp ,(match-string 1 address)
3895 (nntp-address ,(match-string 1 address))
3896 (nntp-port-number ,(if (match-end 3)
3897 (match-string 3 address)
3900 (defun gnus-url-parse-query-string (query &optional downcase)
3901 (let (retval pairs cur key val)
3902 (setq pairs (split-string query "&"))
3904 (setq cur (car pairs)
3906 (if (not (string-match "=" cur))
3908 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3909 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3911 (setq key (downcase key)))
3912 (setq cur (assoc key retval))
3914 (setcdr cur (cons val (cdr cur)))
3915 (setq retval (cons (list key val) retval)))))
3918 (defun gnus-url-unhex (x)
3925 (defun gnus-url-unhex-string (str &optional allow-newlines)
3926 "Remove %XXX embedded spaces, etc in a url.
3927 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3928 decoding of carriage returns and line feeds in the string, which is normally
3929 forbidden in URL encoding."
3930 (setq str (or str ""))
3932 (case-fold-search t))
3933 (while (string-match "%[0-9a-f][0-9a-f]" str)
3934 (let* ((start (match-beginning 0))
3935 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3937 (gnus-url-unhex (elt str (+ start 2))))))
3939 tmp (substring str 0 start)
3942 (char-to-string code))
3943 ((or (= code ?\n) (= code ?\r))
3945 (t (char-to-string code))))
3946 str (substring str (match-end 0)))))
3947 (setq tmp (concat tmp str))
3950 (defun gnus-url-mailto (url)
3951 ;; Send mail to someone
3952 (when (string-match "mailto:/*\\(.*\\)" url)
3953 (setq url (substring url (match-beginning 1) nil)))
3954 (let (to args subject func)
3955 (if (string-match (regexp-quote "?") url)
3956 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3957 args (gnus-url-parse-query-string
3958 (substring url (match-end 0) nil) t))
3959 (setq to (gnus-url-unhex-string url)))
3960 (setq args (cons (list "to" to) args)
3961 subject (cdr-safe (assoc "subject" args)))
3962 (gnus-setup-message 'reply
3965 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3968 (message-position-on-field (caar args)))
3969 (insert (mapconcat 'identity (cdar args) ", "))
3970 (setq args (cdr args)))
3973 (message-goto-subject)))))
3975 (defun gnus-button-mailto (address)
3977 (set-buffer (gnus-copy-article-buffer))
3978 (gnus-setup-message 'reply
3979 (message-reply address)))
3981 (defun gnus-button-reply (address)
3982 ;; Reply to ADDRESS.
3983 (gnus-setup-message 'reply
3984 (message-reply address)))
3986 (defun gnus-button-url (address)
3988 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3989 (if (listp browse-url-browser-function)
3990 (browse-url address)
3991 (funcall browse-url-browser-function address)))
3993 (defun gnus-button-embedded-url (address)
3995 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3996 (if (listp browse-url-browser-function)
3997 (browse-url (gnus-strip-whitespace address))
3998 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4000 ;;; Next/prev buttons in the article buffer.
4002 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4003 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4005 (defvar gnus-prev-page-map nil)
4006 (unless gnus-prev-page-map
4007 (setq gnus-prev-page-map (make-sparse-keymap))
4008 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4009 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4011 (defun gnus-insert-prev-page-button ()
4012 (let ((buffer-read-only nil))
4014 gnus-prev-page-line-format nil
4015 `(gnus-prev t local-map ,gnus-prev-page-map
4016 gnus-callback gnus-article-button-prev-page
4017 article-type annotation))))
4019 (defvar gnus-next-page-map nil)
4020 (unless gnus-next-page-map
4021 (setq gnus-next-page-map (make-keymap))
4022 (suppress-keymap gnus-prev-page-map)
4023 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4024 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4026 (defun gnus-button-next-page ()
4027 "Go to the next page."
4029 (let ((win (selected-window)))
4030 (select-window (get-buffer-window gnus-article-buffer t))
4031 (gnus-article-next-page)
4032 (select-window win)))
4034 (defun gnus-button-prev-page ()
4035 "Go to the prev page."
4037 (let ((win (selected-window)))
4038 (select-window (get-buffer-window gnus-article-buffer t))
4039 (gnus-article-prev-page)
4040 (select-window win)))
4042 (defun gnus-insert-next-page-button ()
4043 (let ((buffer-read-only nil))
4044 (gnus-eval-format gnus-next-page-line-format nil
4046 t local-map ,gnus-next-page-map
4047 gnus-callback gnus-article-button-next-page
4048 article-type annotation))))
4050 (defun gnus-article-button-next-page (arg)
4051 "Go to the next page."
4053 (let ((win (selected-window)))
4054 (select-window (get-buffer-window gnus-article-buffer t))
4055 (gnus-article-next-page)
4056 (select-window win)))
4058 (defun gnus-article-button-prev-page (arg)
4059 "Go to the prev page."
4061 (let ((win (selected-window)))
4062 (select-window (get-buffer-window gnus-article-buffer t))
4063 (gnus-article-prev-page)
4064 (select-window win)))
4066 (defvar gnus-decode-header-methods
4067 '(gnus-decode-with-mail-decode-encoded-word-region)
4068 "List of methods used to decode headers
4070 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4071 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4072 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4073 whose names match REGEXP.
4076 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4077 mail-decode-encoded-word-region
4078 (\"chinese\" . rfc1843-decode-region))
4081 (defvar gnus-decode-header-methods-cache nil)
4083 (defun gnus-decode-with-mail-decode-encoded-word-region (start end)
4084 (let ((rfc2047-default-charset gnus-default-charset))
4085 (mail-decode-encoded-word-region start end)))
4087 (defun gnus-multi-decode-header (start end)
4088 "Apply the functions from `gnus-encoded-word-methods' that match."
4089 (unless (and gnus-decode-header-methods-cache
4090 (eq gnus-newsgroup-name
4091 (car gnus-decode-header-methods-cache)))
4092 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4095 (nconc gnus-decode-header-methods-cache (list x))
4096 (if (and gnus-newsgroup-name
4097 (string-match (car x) gnus-newsgroup-name))
4098 (nconc gnus-decode-header-methods-cache
4100 gnus-decode-header-methods))
4101 (let ((xlist gnus-decode-header-methods-cache))
4104 (narrow-to-region start end)
4106 (funcall (pop xlist) (point-min) (point-max))))))
4112 (defun gnus-article-header-presentation-method (entity situation)
4113 (mime-insert-header entity)
4116 (set-alist 'mime-header-presentation-method-alist
4117 'gnus-original-article-mode
4118 #'gnus-article-header-presentation-method)
4120 (defun gnus-mime-preview-quitting-method ()
4122 (gnus-article-show-summary)
4123 (mime-preview-kill-buffer)
4124 (delete-other-windows)
4125 (gnus-article-show-summary)
4126 (gnus-summary-select-article nil t)
4129 (set-alist 'mime-preview-quitting-method-alist
4130 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
4132 (defun gnus-following-method (buf)
4135 (message-yank-original)
4137 (goto-char (point-min))
4140 (set-alist 'mime-preview-following-method-alist
4141 'gnus-original-article-mode #'gnus-following-method)
4151 (run-hooks 'gnus-art-load-hook)
4153 ;;; gnus-art.el ends here