1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98,99 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-treat nil
59 "Treating article parts."
60 :link '(custom-manual "(gnus)Article Hiding")
63 (defgroup gnus-article-hiding nil
64 "Hiding article parts."
65 :link '(custom-manual "(gnus)Article Hiding")
68 (defgroup gnus-article-highlight nil
69 "Article highlighting."
70 :link '(custom-manual "(gnus)Article Highlighting")
74 (defgroup gnus-article-signature nil
76 :link '(custom-manual "(gnus)Article Signature")
79 (defgroup gnus-article-headers nil
81 :link '(custom-manual "(gnus)Hiding Headers")
84 (defgroup gnus-article-washing nil
85 "Special commands on articles."
86 :link '(custom-manual "(gnus)Article Washing")
89 (defgroup gnus-article-emphasis nil
90 "Fontisizing articles."
91 :link '(custom-manual "(gnus)Article Fontisizing")
94 (defgroup gnus-article-saving nil
96 :link '(custom-manual "(gnus)Saving Articles")
99 (defgroup gnus-article-mime nil
100 "Worshiping the MIME wonder."
101 :link '(custom-manual "(gnus)Using MIME")
102 :group 'gnus-article)
104 (defgroup gnus-article-buttons nil
105 "Pushable buttons in the article buffer."
106 :link '(custom-manual "(gnus)Article Buttons")
107 :group 'gnus-article)
109 (defgroup gnus-article-various nil
110 "Other article options."
111 :link '(custom-manual "(gnus)Misc Article")
112 :group 'gnus-article)
114 (defcustom gnus-ignored-headers
115 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
116 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
117 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
118 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
119 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
120 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
121 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
122 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
123 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
124 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
125 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
126 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
127 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
128 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
129 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
130 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
131 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
132 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
134 "*All headers that start with this regexp will be hidden.
135 This variable can also be a list of regexps of headers to be ignored.
136 If `gnus-visible-headers' is non-nil, this variable will be ignored."
137 :type '(choice :custom-show nil
140 :group 'gnus-article-hiding)
142 (defcustom gnus-visible-headers
143 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
144 "*All headers that do not match this regexp will be hidden.
145 This variable can also be a list of regexp of headers to remain visible.
146 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
147 :type '(repeat :value-to-internal (lambda (widget value)
148 (custom-split-regexp-maybe value))
149 :match (lambda (widget value)
151 (widget-editable-list-match widget value)))
153 :group 'gnus-article-hiding)
155 (defcustom gnus-sorted-header-list
156 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
157 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
158 "*This variable is a list of regular expressions.
159 If it is non-nil, headers that match the regular expressions will
160 be placed first in the article buffer in the sequence specified by
162 :type '(repeat regexp)
163 :group 'gnus-article-hiding)
165 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
166 "Headers that are only to be displayed if they have interesting data.
167 Possible values in this list are `empty', `newsgroups', `followup-to',
168 `reply-to', `date', `long-to', and `many-to'."
169 :type '(set (const :tag "Headers with no content." empty)
170 (const :tag "Newsgroups with only one group." newsgroups)
171 (const :tag "Followup-to identical to newsgroups." followup-to)
172 (const :tag "Reply-to identical to from." reply-to)
173 (const :tag "Date less than four days old." date)
174 (const :tag "Very long To header." long-to)
175 (const :tag "Multiple To headers." many-to))
176 :group 'gnus-article-hiding)
178 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
179 "Regexp matching signature separator.
180 This can also be a list of regexps. In that case, it will be checked
181 from head to tail looking for a separator. Searches will be done from
182 the end of the buffer."
183 :type '(repeat string)
184 :group 'gnus-article-signature)
186 (defcustom gnus-signature-limit nil
187 "Provide a limit to what is considered a signature.
188 If it is a number, no signature may not be longer (in characters) than
189 that number. If it is a floating point number, no signature may be
190 longer (in lines) than that number. If it is a function, the function
191 will be called without any parameters, and if it returns nil, there is
192 no signature in the buffer. If it is a string, it will be used as a
193 regexp. If it matches, the text in question is not a signature."
194 :type '(choice (integer :value 200)
196 (function :value fun)
197 (regexp :value ".*"))
198 :group 'gnus-article-signature)
200 (defcustom gnus-hidden-properties '(invisible t intangible t)
201 "Property list to use for hiding text."
203 :group 'gnus-article-hiding)
205 (defcustom gnus-article-x-face-command
206 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
207 "*String or function to be executed to display an X-Face header.
208 If it is a string, the command will be executed in a sub-shell
209 asynchronously. The compressed face will be piped to this command."
210 :type 'string ;Leave function case to Lisp.
211 :group 'gnus-article-washing)
213 (defcustom gnus-article-x-face-too-ugly nil
214 "Regexp matching posters whose face shouldn't be shown automatically."
215 :type '(choice regexp (const nil))
216 :group 'gnus-article-washing)
218 (defcustom gnus-emphasis-alist
220 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
222 '(("_" "_" underline)
225 ("_/" "/_" underline-italic)
226 ("_\\*" "\\*_" underline-bold)
227 ("\\*/" "/\\*" bold-italic)
228 ("_\\*/" "/\\*_" underline-bold-italic))))
229 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
230 2 3 gnus-emphasis-underline)
234 (format format (car spec) (cadr spec))
235 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
237 "*Alist that says how to fontify certain phrases.
238 Each item looks like this:
240 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
242 The first element is a regular expression to be matched. The second
243 is a number that says what regular expression grouping used to find
244 the entire emphasized word. The third is a number that says what
245 regexp grouping should be displayed and highlighted. The fourth
246 is the face used for highlighting."
247 :type '(repeat (list :value ("" 0 0 default)
249 (integer :tag "Match group")
250 (integer :tag "Emphasize group")
252 :group 'gnus-article-emphasis)
254 (defface gnus-emphasis-bold '((t (:bold t)))
255 "Face used for displaying strong emphasized text (*word*)."
256 :group 'gnus-article-emphasis)
258 (defface gnus-emphasis-italic '((t (:italic t)))
259 "Face used for displaying italic emphasized text (/word/)."
260 :group 'gnus-article-emphasis)
262 (defface gnus-emphasis-underline '((t (:underline t)))
263 "Face used for displaying underlined emphasized text (_word_)."
264 :group 'gnus-article-emphasis)
266 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
267 "Face used for displaying underlined bold emphasized text (_*word*_)."
268 :group 'gnus-article-emphasis)
270 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
271 "Face used for displaying underlined italic emphasized text (_*word*_)."
272 :group 'gnus-article-emphasis)
274 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
275 "Face used for displaying bold italic emphasized text (/*word*/)."
276 :group 'gnus-article-emphasis)
278 (defface gnus-emphasis-underline-bold-italic
279 '((t (:bold t :italic t :underline t)))
280 "Face used for displaying underlined bold italic emphasized text.
281 Esample: (_/*word*/_)."
282 :group 'gnus-article-emphasis)
284 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
285 "Format for display of Date headers in article bodies.
286 See `format-time-string' for the possible values.
288 The variable can also be function, which should return a complete Date
289 header. The function is called with one argument, the time, which can
290 be fed to `format-time-string'."
291 :type '(choice string symbol)
292 :link '(custom-manual "(gnus)Article Date")
293 :group 'gnus-article-washing)
296 (autoload 'mail-extract-address-components "mail-extr"))
298 (defcustom gnus-save-all-headers t
299 "*If non-nil, don't remove any headers before saving."
300 :group 'gnus-article-saving
303 (defcustom gnus-prompt-before-saving 'always
304 "*This variable says how much prompting is to be done when saving articles.
305 If it is nil, no prompting will be done, and the articles will be
306 saved to the default files. If this variable is `always', each and
307 every article that is saved will be preceded by a prompt, even when
308 saving large batches of articles. If this variable is neither nil not
309 `always', there the user will be prompted once for a file name for
310 each invocation of the saving commands."
311 :group 'gnus-article-saving
312 :type '(choice (item always)
313 (item :tag "never" nil)
314 (sexp :tag "once" :format "%t\n" :value t)))
316 (defcustom gnus-saved-headers gnus-visible-headers
317 "Headers to keep if `gnus-save-all-headers' is nil.
318 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
319 If that variable is nil, however, all headers that match this regexp
320 will be kept while the rest will be deleted before saving."
321 :group 'gnus-article-saving
324 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
325 "A function to save articles in your favourite format.
326 The function must be interactively callable (in other words, it must
327 be an Emacs command).
329 Gnus provides the following functions:
331 * gnus-summary-save-in-rmail (Rmail format)
332 * gnus-summary-save-in-mail (Unix mail format)
333 * gnus-summary-save-in-folder (MH folder)
334 * gnus-summary-save-in-file (article format)
335 * gnus-summary-save-in-vm (use VM's folder format)
336 * gnus-summary-write-to-file (article format -- overwrite)."
337 :group 'gnus-article-saving
338 :type '(radio (function-item gnus-summary-save-in-rmail)
339 (function-item gnus-summary-save-in-mail)
340 (function-item gnus-summary-save-in-folder)
341 (function-item gnus-summary-save-in-file)
342 (function-item gnus-summary-save-in-vm)
343 (function-item gnus-summary-write-to-file)))
345 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
346 "A function generating a file name to save articles in Rmail format.
347 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
348 :group 'gnus-article-saving
351 (defcustom gnus-mail-save-name 'gnus-plain-save-name
352 "A function generating a file name to save articles in Unix mail format.
353 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
354 :group 'gnus-article-saving
357 (defcustom gnus-folder-save-name 'gnus-folder-save-name
358 "A function generating a file name to save articles in MH folder.
359 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
360 :group 'gnus-article-saving
363 (defcustom gnus-file-save-name 'gnus-numeric-save-name
364 "A function generating a file name to save articles in article format.
365 The function is called with NEWSGROUP, HEADERS, and optional
367 :group 'gnus-article-saving
370 (defcustom gnus-split-methods
371 '((gnus-article-archive-name)
372 (gnus-article-nndoc-name))
373 "*Variable used to suggest where articles are to be saved.
374 For instance, if you would like to save articles related to Gnus in
375 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
376 you could set this variable to something like:
378 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
379 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
381 This variable is an alist where the where the key is the match and the
382 value is a list of possible files to save in if the match is non-nil.
384 If the match is a string, it is used as a regexp match on the
385 article. If the match is a symbol, that symbol will be funcalled
386 from the buffer of the article to be saved with the newsgroup as the
387 parameter. If it is a list, it will be evaled in the same buffer.
389 If this form or function returns a string, this string will be used as
390 a possible file name; and if it returns a non-nil list, that list will
391 be used as possible file names."
392 :group 'gnus-article-saving
393 :type '(repeat (choice (list :value (fun) function)
394 (cons :value ("" "") regexp (repeat string))
397 (defcustom gnus-article-display-method-for-mime
398 'gnus-article-display-mime-message
399 "Function to display a MIME message.
400 The function is called from the article buffer."
401 :group 'gnus-article-mime
404 (defcustom gnus-article-display-method-for-traditional
405 'gnus-article-display-traditional-message
406 "*Function to display a traditional message.
407 The function is called from the article buffer."
408 :group 'gnus-article-mime
411 (defcustom gnus-page-delimiter "^\^L"
412 "*Regexp describing what to use as article page delimiters.
413 The default value is \"^\^L\", which is a form linefeed at the
414 beginning of a line."
416 :group 'gnus-article-various)
418 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
419 "*The format specification for the article mode line.
420 See `gnus-summary-mode-line-format' for a closer description.
422 The following additional specs are available:
424 %w The article washing status.
425 %m The number of MIME parts in the article."
427 :group 'gnus-article-various)
429 (defcustom gnus-article-mode-hook nil
430 "*A hook for Gnus article mode."
432 :group 'gnus-article-various)
434 (defcustom gnus-article-menu-hook nil
435 "*Hook run after the creation of the article mode menu."
437 :group 'gnus-article-various)
439 (defcustom gnus-article-prepare-hook nil
440 "*A hook called after an article has been prepared in the article buffer."
442 :group 'gnus-article-various)
444 (defcustom gnus-article-hide-pgp-hook nil
445 "*A hook called after successfully hiding a PGP signature."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-button-face 'bold
450 "Face used for highlighting buttons in the article buffer.
452 An article button is a piece of text that you can activate by pressing
453 `RET' or `mouse-2' above it."
455 :group 'gnus-article-buttons)
457 (defcustom gnus-article-mouse-face 'highlight
458 "Face used for mouse highlighting in the article buffer.
460 Article buttons will be displayed in this face when the cursor is
463 :group 'gnus-article-buttons)
465 (defcustom gnus-signature-face 'gnus-signature-face
466 "Face used for highlighting a signature in the article buffer.
467 Obsolete; use the face `gnus-signature-face' for customizations instead."
469 :group 'gnus-article-highlight
470 :group 'gnus-article-signature)
472 (defface gnus-signature-face
475 "Face used for highlighting a signature in the article buffer."
476 :group 'gnus-article-highlight
477 :group 'gnus-article-signature)
479 (defface gnus-header-from-face
482 (:foreground "spring green"))
485 (:foreground "red3"))
488 "Face used for displaying from headers."
489 :group 'gnus-article-headers
490 :group 'gnus-article-highlight)
492 (defface gnus-header-subject-face
495 (:foreground "SeaGreen3"))
498 (:foreground "red4"))
500 (:bold t :italic t)))
501 "Face used for displaying subject headers."
502 :group 'gnus-article-headers
503 :group 'gnus-article-highlight)
505 (defface gnus-header-newsgroups-face
508 (:foreground "yellow" :italic t))
511 (:foreground "MidnightBlue" :italic t))
514 "Face used for displaying newsgroups headers."
515 :group 'gnus-article-headers
516 :group 'gnus-article-highlight)
518 (defface gnus-header-name-face
521 (:foreground "SeaGreen"))
524 (:foreground "maroon"))
527 "Face used for displaying header names."
528 :group 'gnus-article-headers
529 :group 'gnus-article-highlight)
531 (defface gnus-header-content-face
534 (:foreground "forest green" :italic t))
537 (:foreground "indianred4" :italic t))
539 (:italic t))) "Face used for displaying header content."
540 :group 'gnus-article-headers
541 :group 'gnus-article-highlight)
543 (defcustom gnus-header-face-alist
544 '(("From" nil gnus-header-from-face)
545 ("Subject" nil gnus-header-subject-face)
546 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
547 ("" gnus-header-name-face gnus-header-content-face))
548 "*Controls highlighting of article header.
550 An alist of the form (HEADER NAME CONTENT).
552 HEADER is a regular expression which should match the name of an
553 header header and NAME and CONTENT are either face names or nil.
555 The name of each header field will be displayed using the face
556 specified by the first element in the list where HEADER match the
557 header name and NAME is non-nil. Similarly, the content will be
558 displayed by the first non-nil matching CONTENT face."
559 :group 'gnus-article-headers
560 :group 'gnus-article-highlight
561 :type '(repeat (list (regexp :tag "Header")
563 (item :tag "skip" nil)
564 (face :value default))
565 (choice :tag "Content"
566 (item :tag "skip" nil)
567 (face :value default)))))
569 (defcustom gnus-article-decode-hook nil
570 "*Hook run to decode charsets in articles."
571 :group 'gnus-article-headers
574 (defcustom gnus-display-mime-function 'gnus-display-mime
575 "Function to display MIME articles."
576 :group 'gnus-article-mime
579 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
580 "Function used to decode headers.")
582 (defvar gnus-article-dumbquotes-map
600 "Table for MS-to-Latin1 translation.")
602 (defcustom gnus-ignored-mime-types nil
603 "List of MIME types that should be ignored by Gnus."
604 :group 'gnus-article-mime
605 :type '(repeat regexp))
607 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
608 "List of MIME types that should not be given buttons when rendered."
609 :group 'gnus-article-mime
610 :type '(repeat regexp))
612 (defcustom gnus-article-mime-part-function nil
613 "Function called with a MIME handle as the argument.
614 This is meant for people who want to do something automatic based
615 on parts -- for instance, adding Vcard info to a database."
616 :group 'gnus-article-mime
620 ;;; The treatment variables
623 (defvar gnus-part-display-hook nil
624 "Hook called on parts that are to receive treatment.")
626 (defvar gnus-article-treat-custom
627 '(choice (const :tag "Off" nil)
629 (const :tag "Header" head)
630 (const :tag "Last" last)
631 (integer :tag "Less")
632 (sexp :tag "Predicate")))
634 (defvar gnus-article-treat-types '("text/plain")
637 (defvar gnus-inhibit-treatment nil
638 "Whether to inhibit treatment.")
640 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
641 "Highlight the signature."
642 :group 'gnus-article-treat
643 :type gnus-article-treat-custom)
645 (defcustom gnus-treat-buttonize t
647 :group 'gnus-article-treat
648 :type gnus-article-treat-custom)
650 (defcustom gnus-treat-buttonize-head 'head
651 "Add buttons to the head."
652 :group 'gnus-article-treat
653 :type gnus-article-treat-custom)
655 (defcustom gnus-treat-emphasize t
657 :group 'gnus-article-treat
658 :type gnus-article-treat-custom)
660 (defcustom gnus-treat-strip-cr nil
661 "Remove carriage returns."
662 :group 'gnus-article-treat
663 :type gnus-article-treat-custom)
665 (defcustom gnus-treat-hide-headers 'head
667 :group 'gnus-article-treat
668 :type gnus-article-treat-custom)
670 (defcustom gnus-treat-hide-boring-headers nil
671 "Hide boring headers."
672 :group 'gnus-article-treat
673 :type gnus-article-treat-custom)
675 (defcustom gnus-treat-hide-signature nil
676 "Hide the signature."
677 :group 'gnus-article-treat
678 :type gnus-article-treat-custom)
680 (defcustom gnus-treat-fill-article nil
682 :group 'gnus-article-treat
683 :type gnus-article-treat-custom)
685 (defcustom gnus-treat-hide-citation nil
687 :group 'gnus-article-treat
688 :type gnus-article-treat-custom)
690 (defcustom gnus-treat-strip-pgp t
691 "Strip PGP signatures."
692 :group 'gnus-article-treat
693 :type gnus-article-treat-custom)
695 (defcustom gnus-treat-strip-pem nil
696 "Strip PEM signatures."
697 :group 'gnus-article-treat
698 :type gnus-article-treat-custom)
700 (defcustom gnus-treat-highlight-headers 'head
701 "Highlight the headers."
702 :group 'gnus-article-treat
703 :type gnus-article-treat-custom)
705 (defcustom gnus-treat-highlight-citation t
706 "Highlight cited text."
707 :group 'gnus-article-treat
708 :type gnus-article-treat-custom)
710 (defcustom gnus-treat-date-ut nil
711 "Display the Date in UT (GMT)."
712 :group 'gnus-article-treat
713 :type gnus-article-treat-custom)
715 (defcustom gnus-treat-date-local nil
716 "Display the Date in the local timezone."
717 :group 'gnus-article-treat
718 :type gnus-article-treat-custom)
720 (defcustom gnus-treat-date-lapsed nil
721 "Display the Date header in a way that says how much time has elapsed."
722 :group 'gnus-article-treat
723 :type gnus-article-treat-custom)
725 (defcustom gnus-treat-date-original nil
726 "Display the date in the original timezone."
727 :group 'gnus-article-treat
728 :type gnus-article-treat-custom)
730 (defcustom gnus-treat-strip-trailing-blank-lines nil
731 "Strip trailing blank lines."
732 :group 'gnus-article-treat
733 :type gnus-article-treat-custom)
735 (defcustom gnus-treat-strip-leading-blank-lines nil
736 "Strip leading blank lines."
737 :group 'gnus-article-treat
738 :type gnus-article-treat-custom)
740 (defcustom gnus-treat-strip-multiple-blank-lines nil
741 "Strip multiple blank lines."
742 :group 'gnus-article-treat
743 :type gnus-article-treat-custom)
745 (defcustom gnus-treat-strip-blank-lines nil
746 "Strip all blank lines."
747 :group 'gnus-article-treat
748 :type gnus-article-treat-custom)
750 (defcustom gnus-treat-overstrike t
751 "Treat overstrike highlighting."
752 :group 'gnus-article-treat
753 :type gnus-article-treat-custom)
755 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
757 "Display X-Face headers."
758 :group 'gnus-article-treat
759 :type gnus-article-treat-custom)
761 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
765 :group 'gnus-article-treat
766 :type gnus-article-treat-custom)
768 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
770 :group 'gnus-article-treat
771 :type gnus-article-treat-custom)
773 ;;; Internal variables
775 (defvar article-goto-body-goes-to-point-min-p nil)
777 (defvar gnus-article-mime-handle-alist-1 nil)
778 (defvar gnus-treatment-function-alist
779 '((gnus-treat-highlight-signature gnus-article-highlight-signature)
780 (gnus-treat-buttonize gnus-article-add-buttons)
781 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
782 (gnus-treat-fill-article gnus-article-fill-cited-article)
783 (gnus-treat-strip-cr gnus-article-remove-cr)
784 (gnus-treat-hide-headers gnus-article-hide-headers)
785 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
786 (gnus-treat-hide-signature gnus-article-hide-signature)
787 (gnus-treat-hide-citation gnus-article-hide-citation)
788 (gnus-treat-strip-pgp gnus-article-hide-pgp)
789 (gnus-treat-strip-pem gnus-article-hide-pem)
790 (gnus-treat-highlight-headers gnus-article-highlight-headers)
791 (gnus-treat-highlight-citation gnus-article-highlight-citation)
792 (gnus-treat-highlight-signature gnus-article-highlight-signature)
793 (gnus-treat-emphasize gnus-article-emphasize)
794 (gnus-treat-date-ut gnus-article-date-ut)
795 (gnus-treat-date-local gnus-article-date-local)
796 (gnus-treat-date-lapsed gnus-article-date-lapsed)
797 (gnus-treat-date-original gnus-article-date-original)
798 (gnus-treat-strip-trailing-blank-lines
799 gnus-article-remove-trailing-blank-lines)
800 (gnus-treat-strip-leading-blank-lines
801 gnus-article-strip-leading-blank-lines)
802 (gnus-treat-strip-multiple-blank-lines
803 gnus-article-strip-multiple-blank-lines)
804 (gnus-treat-strip-blank-lines gnus-article-strip-blank-lines)
805 (gnus-treat-overstrike gnus-article-treat-overstrike)
806 (gnus-treat-display-xface gnus-article-display-x-face)
807 (gnus-treat-display-smileys gnus-smiley-display)
808 (gnus-treat-display-picons gnus-article-display-picons)))
810 (defvar gnus-article-mime-handle-alist nil)
811 (defvar article-lapsed-timer nil)
812 (defvar gnus-article-current-summary nil)
814 (defvar gnus-article-mode-syntax-table
815 (let ((table (copy-syntax-table text-mode-syntax-table)))
816 (modify-syntax-entry ?- "w" table)
817 (modify-syntax-entry ?> ")" table)
818 (modify-syntax-entry ?< "(" table)
820 "Syntax table used in article mode buffers.
821 Initialized from `text-mode-syntax-table.")
823 (defvar gnus-save-article-buffer nil)
825 (defvar gnus-article-mode-line-format-alist
826 (nconc '((?w (gnus-article-wash-status) ?s)
827 (?m (gnus-article-mime-part-status) ?s))
828 gnus-summary-mode-line-format-alist))
830 (defvar gnus-number-of-articles-to-be-saved nil)
832 (defvar gnus-inhibit-hiding nil)
834 (defsubst gnus-article-hide-text (b e props)
835 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
836 (add-text-properties b e props)
837 (when (memq 'intangible props)
839 (max (1- b) (point-min))
840 b 'intangible (cddr (memq 'intangible props)))))
842 (defmacro gnus-with-article (article &rest forms)
843 "Select ARTICLE and perform FORMS in the original article buffer.
844 Then replace the article with the result."
846 ;; We don't want the article to be marked as read.
847 (let (gnus-mark-article-hook)
848 (gnus-summary-select-article t t nil ,article))
849 (set-buffer gnus-original-article-buffer)
851 (if (not (gnus-check-backend-function
852 'request-replace-article (car gnus-article-current)))
853 (gnus-message 5 "Read-only group; not replacing")
854 (unless (gnus-request-replace-article
855 ,article (car gnus-article-current)
857 (error "Couldn't replace article")))
858 ;; The cache and backlog have to be flushed somewhat.
859 (when gnus-keep-backlog
860 (gnus-backlog-remove-article
861 (car gnus-article-current) (cdr gnus-article-current)))
863 (gnus-cache-update-article
864 (car gnus-article-current) (cdr gnus-article-current)))))
866 (put 'gnus-with-article 'lisp-indent-function 1)
867 (put 'gnus-with-article 'edebug-form-spec '(form body))
869 (defsubst gnus-article-unhide-text (b e)
870 "Remove hidden text properties from region between B and E."
871 (remove-text-properties b e gnus-hidden-properties)
872 (when (memq 'intangible gnus-hidden-properties)
873 (put-text-property (max (1- b) (point-min))
876 (defun gnus-article-hide-text-type (b e type)
877 "Hide text of TYPE between B and E."
878 (gnus-article-hide-text
879 b e (cons 'article-type (cons type gnus-hidden-properties))))
881 (defun gnus-article-unhide-text-type (b e type)
882 "Unhide text of TYPE between B and E."
883 (remove-text-properties
884 b e (cons 'article-type (cons type gnus-hidden-properties)))
885 (when (memq 'intangible gnus-hidden-properties)
886 (put-text-property (max (1- b) (point-min))
889 (defun gnus-article-hide-text-of-type (type)
890 "Hide text of TYPE in the current buffer."
892 (let ((b (point-min))
894 (while (setq b (text-property-any b e 'article-type type))
895 (add-text-properties b (incf b) gnus-hidden-properties)))))
897 (defun gnus-article-delete-text-of-type (type)
898 "Delete text of TYPE in the current buffer."
900 (let ((b (point-min)))
901 (while (setq b (text-property-any b (point-max) 'article-type type))
903 b (or (text-property-not-all b (point-max) 'article-type type)
906 (defun gnus-article-delete-invisible-text ()
907 "Delete all invisible text in the current buffer."
909 (let ((b (point-min)))
910 (while (setq b (text-property-any b (point-max) 'invisible t))
912 b (or (text-property-not-all b (point-max) 'invisible t)
915 (defun gnus-article-text-type-exists-p (type)
916 "Say whether any text of type TYPE exists in the buffer."
917 (text-property-any (point-min) (point-max) 'article-type type))
919 (defsubst gnus-article-header-rank ()
920 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
921 (let ((list gnus-sorted-header-list)
924 (when (looking-at (car list))
926 (setq list (cdr list))
930 (defun article-hide-headers (&optional arg delete)
931 "Toggle whether to hide unwanted headers and possibly sort them as well.
932 If given a negative prefix, always show; if given a positive prefix,
934 (interactive (gnus-article-hidden-arg))
936 (if (gnus-article-check-hidden-text 'headers arg)
937 ;; Show boring headers as well.
938 (gnus-article-show-hidden-text 'boring-headers)
939 ;; This function might be inhibited.
940 (unless gnus-inhibit-hiding
943 (let ((buffer-read-only nil)
945 (props (nconc (list 'article-type 'headers)
946 gnus-hidden-properties))
947 (max (1+ (length gnus-sorted-header-list)))
948 (ignored (when (not gnus-visible-headers)
949 (cond ((stringp gnus-ignored-headers)
950 gnus-ignored-headers)
951 ((listp gnus-ignored-headers)
952 (mapconcat 'identity gnus-ignored-headers
955 (cond ((stringp gnus-visible-headers)
956 gnus-visible-headers)
957 ((and gnus-visible-headers
958 (listp gnus-visible-headers))
959 (mapconcat 'identity gnus-visible-headers "\\|"))))
960 (inhibit-point-motion-hooks t)
962 ;; First we narrow to just the headers.
964 (goto-char (point-min))
965 ;; Hide any "From " lines at the beginning of (mail) articles.
966 (while (looking-at "From ")
970 (delete-region (point-min) (point))
971 (gnus-article-hide-text (point-min) (point) props)))
972 ;; Then treat the rest of the header lines.
975 (if (search-forward "\n\n" nil t) ; if there's a body
976 (progn (forward-line -1) (point))
978 ;; Then we use the two regular expressions
979 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
980 ;; select which header lines is to remain visible in the
982 (goto-char (point-min))
983 (while (re-search-forward "^[^ \t]*:" nil t)
985 ;; Mark the rank of the header.
987 (point) (1+ (point)) 'message-rank
988 (if (or (and visible (looking-at visible))
990 (not (looking-at ignored))))
991 (gnus-article-header-rank)
994 (message-sort-headers-1)
995 (when (setq beg (text-property-any
996 (point-min) (point-max) 'message-rank (+ 2 max)))
997 ;; We make the unwanted headers invisible.
999 (delete-region beg (point-max))
1000 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1001 (gnus-article-hide-text-type beg (point-max) 'headers))
1002 ;; Work around XEmacs lossage.
1003 (put-text-property (point-min) beg 'invisible nil))))))))
1005 (defun article-hide-boring-headers (&optional arg)
1006 "Toggle hiding of headers that aren't very interesting.
1007 If given a negative prefix, always show; if given a positive prefix,
1009 (interactive (gnus-article-hidden-arg))
1010 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1011 (not gnus-show-all-headers))
1014 (let ((buffer-read-only nil)
1015 (list gnus-boring-article-headers)
1016 (inhibit-point-motion-hooks t)
1018 (nnheader-narrow-to-headers)
1020 (setq elem (pop list))
1021 (goto-char (point-min))
1023 ;; Hide empty headers.
1025 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
1027 (gnus-article-hide-text-type
1028 (progn (beginning-of-line) (point))
1031 (if (re-search-forward "^[^ \t]" nil t)
1035 ;; Hide boring Newsgroups header.
1036 ((eq elem 'newsgroups)
1037 (when (equal (gnus-fetch-field "newsgroups")
1038 (gnus-group-real-name
1039 (if (boundp 'gnus-newsgroup-name)
1042 (gnus-article-hide-header "newsgroups")))
1043 ((eq elem 'followup-to)
1044 (when (equal (message-fetch-field "followup-to")
1045 (message-fetch-field "newsgroups"))
1046 (gnus-article-hide-header "followup-to")))
1047 ((eq elem 'reply-to)
1048 (let ((from (message-fetch-field "from"))
1049 (reply-to (message-fetch-field "reply-to")))
1054 (nth 1 (funcall gnus-extract-address-components from))
1055 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1056 (gnus-article-hide-header "reply-to"))))
1058 (let ((date (message-fetch-field "date")))
1060 (< (days-between (current-time-string) date)
1062 (gnus-article-hide-header "date"))))
1064 (let ((to (message-fetch-field "to")))
1065 (when (> (length to) 1024)
1066 (gnus-article-hide-header "to"))))
1069 (goto-char (point-min))
1070 (while (re-search-forward "^to:" nil t)
1071 (setq to-count (1+ to-count)))
1072 (when (> to-count 1)
1073 (while (> to-count 0)
1074 (goto-char (point-min))
1076 (re-search-forward "^to:" nil nil to-count)
1078 (narrow-to-region (point) (point-max))
1079 (gnus-article-hide-header "to"))
1080 (setq to-count (1- to-count)))))))))))))
1082 (defun gnus-article-hide-header (header)
1084 (goto-char (point-min))
1085 (when (re-search-forward (concat "^" header ":") nil t)
1086 (gnus-article-hide-text-type
1087 (progn (beginning-of-line) (point))
1090 (if (re-search-forward "^[^ \t]" nil t)
1095 (defvar gnus-article-normalized-header-length 40
1096 "Length of normalized headers.")
1098 (defun article-normalize-headers ()
1099 "Make all header lines 40 characters long."
1101 (let ((buffer-read-only nil)
1105 (message-narrow-to-head)
1108 ((< (setq column (- (gnus-point-at-eol) (point)))
1109 gnus-article-normalized-header-length)
1111 (insert (make-string
1112 (- gnus-article-normalized-header-length column)
1114 ((> column gnus-article-normalized-header-length)
1115 (gnus-put-text-property
1117 (forward-char gnus-article-normalized-header-length)
1124 (forward-line 1))))))
1126 (defun article-treat-dumbquotes ()
1127 "Translate M******** sm*rtq**t*s into proper text.
1128 Note that this function guesses whether a character is a sm*rtq**t* or
1129 not, so it should only be used interactively."
1131 (article-translate-strings gnus-article-dumbquotes-map))
1133 (defun article-translate-characters (from to)
1134 "Translate all characters in the body of the article according to FROM and TO.
1135 FROM is a string of characters to translate from; to is a string of
1136 characters to translate to."
1138 (when (article-goto-body)
1139 (let ((buffer-read-only nil)
1140 (x (make-string 225 ?x))
1142 (while (< (incf i) (length x))
1145 (while (< i (length from))
1146 (aset x (aref from i) (aref to i))
1148 (translate-region (point) (point-max) x)))))
1150 (defun article-translate-strings (map)
1151 "Translate all string in the body of the article according to MAP.
1152 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1154 (when (article-goto-body)
1155 (let ((buffer-read-only nil)
1157 (while (setq elem (pop map))
1159 (while (search-forward (car elem) nil t)
1160 (replace-match (cadr elem)))))))))
1162 (defun article-treat-overstrike ()
1163 "Translate overstrikes into bold text."
1166 (when (article-goto-body)
1167 (let ((buffer-read-only nil))
1168 (while (search-forward "\b" nil t)
1169 (let ((next (char-after))
1170 (previous (char-after (- (point) 2))))
1171 ;; We do the boldification/underlining by hiding the
1172 ;; overstrikes and putting the proper text property
1176 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1177 (put-text-property (point) (1+ (point)) 'face 'bold))
1179 (gnus-article-hide-text-type
1180 (1- (point)) (1+ (point)) 'overstrike)
1182 (- (point) 2) (1- (point)) 'face 'underline))
1184 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1186 (point) (1+ (point)) 'face 'underline)))))))))
1188 (defun article-fill-long-lines ()
1189 "Fill lines that are wider than the window width."
1192 (let ((buffer-read-only nil)
1193 (width (window-width (get-buffer-window (current-buffer)))))
1197 (let ((adaptive-fill-mode nil))
1200 (when (>= (current-column) (min fill-column width))
1201 (narrow-to-region (point) (gnus-point-at-bol))
1202 (fill-paragraph nil)
1203 (goto-char (point-max))
1205 (forward-line 1)))))))
1207 (defun article-remove-cr ()
1208 "Translate CRLF pairs into LF, and then CR into LF.."
1211 (let ((buffer-read-only nil))
1212 (goto-char (point-min))
1213 (while (search-forward "\r$" nil t)
1214 (replace-match "" t t))
1215 (goto-char (point-min))
1216 (while (search-forward "\r" nil t)
1217 (replace-match "\n" t t)))))
1219 (defun article-remove-trailing-blank-lines ()
1220 "Remove all trailing blank lines from the article."
1223 (let ((buffer-read-only nil))
1224 (goto-char (point-max))
1228 (while (and (not (bobp))
1229 (looking-at "^[ \t]*$")
1230 (not (gnus-annotation-in-region-p
1231 (point) (gnus-point-at-eol))))
1236 (defun article-display-x-face (&optional force)
1237 "Look for an X-Face header and display it if present."
1238 (interactive (list 'force))
1240 ;; Delete the old process, if any.
1241 (when (process-status "article-x-face")
1242 (delete-process "article-x-face"))
1243 (let ((inhibit-point-motion-hooks t)
1244 (case-fold-search t)
1247 (nnheader-narrow-to-headers)
1248 (setq from (message-fetch-field "from"))
1249 (goto-char (point-min))
1250 (while (and gnus-article-x-face-command
1253 ;; Check whether this face is censored.
1254 (not gnus-article-x-face-too-ugly)
1255 (and gnus-article-x-face-too-ugly from
1256 (not (string-match gnus-article-x-face-too-ugly
1258 ;; Has to be present.
1259 (re-search-forward "^X-Face: " nil t))
1260 ;; This used to try to do multiple faces (`while' instead of
1261 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1262 ;; work (b) it can crash some versions of Emacs (c) are
1263 ;; multiple faces really something to encourage?
1264 (when (stringp gnus-article-x-face-command)
1266 ;; We now have the area of the buffer where the X-Face is stored.
1269 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1270 ;; We display the face.
1271 (if (symbolp gnus-article-x-face-command)
1272 ;; The command is a lisp function, so we call it.
1273 (if (gnus-functionp gnus-article-x-face-command)
1274 (funcall gnus-article-x-face-command beg end)
1275 (error "%s is not a function" gnus-article-x-face-command))
1276 ;; The command is a string, so we interpret the command
1277 ;; as a, well, command, and fork it off.
1278 (let ((process-connection-type nil))
1279 (process-kill-without-query
1281 "article-x-face" nil shell-file-name shell-command-switch
1282 gnus-article-x-face-command))
1283 (process-send-region "article-x-face" beg end)
1284 (process-send-eof "article-x-face"))))))))))
1286 (defun article-decode-mime-words ()
1287 "Decode all MIME-encoded words in the article."
1290 (set-buffer gnus-article-buffer)
1291 (let ((inhibit-point-motion-hooks t)
1293 (mail-parse-charset gnus-newsgroup-charset))
1294 (mail-decode-encoded-word-region (point-min) (point-max)))))
1296 (defun article-decode-charset (&optional prompt)
1297 "Decode charset-encoded text in the article.
1298 If PROMPT (the prefix), prompt for a coding system to use."
1302 (message-narrow-to-head)
1303 (let* ((inhibit-point-motion-hooks t)
1304 (case-fold-search t)
1305 (ct (message-fetch-field "Content-Type" t))
1306 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1307 (ctl (and ct (condition-case ()
1308 (mail-header-parse-content-type ct)
1312 (mm-read-coding-system "Charset to decode: "))
1314 (mail-content-type-get ctl 'charset))))
1315 (mail-parse-charset gnus-newsgroup-charset)
1317 (goto-char (point-max))
1320 (narrow-to-region (point) (point-max))
1321 (when (and (or (not ctl)
1322 (equal (car ctl) "text/plain"))
1325 charset (and cte (intern (downcase
1326 (gnus-strip-whitespace cte))))
1329 (defun article-decode-encoded-words ()
1330 "Remove encoded-word encoding from headers."
1331 (let (buffer-read-only)
1332 (let ((charset (save-excursion
1333 (set-buffer gnus-summary-buffer)
1334 default-mime-charset)))
1335 (mime-decode-header-in-buffer charset)
1338 (defun article-de-quoted-unreadable (&optional force)
1339 "Translate a quoted-printable-encoded article.
1340 If FORCE, decode the article whether it is marked as quoted-printable
1342 (interactive (list 'force))
1344 (let ((buffer-read-only nil)
1345 (type (gnus-fetch-field "content-transfer-encoding"))
1346 (charset gnus-newsgroup-charset))
1348 (and type (string-match "quoted-printable" (downcase type))))
1351 (narrow-to-region (point) (point-max))
1352 (quoted-printable-decode-region (point-min) (point-max))
1354 (mm-decode-body charset)))))))
1356 (defun article-hide-pgp (&optional arg)
1357 "Toggle hiding of any PGP headers and signatures in the current article.
1358 If given a negative prefix, always show; if given a positive prefix,
1360 (interactive (gnus-article-hidden-arg))
1361 (unless (gnus-article-check-hidden-text 'pgp arg)
1363 (let ((inhibit-point-motion-hooks t)
1364 buffer-read-only beg end)
1366 (goto-char (point-min))
1367 ;; Hide the "header".
1368 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1369 (delete-region (1+ (match-beginning 0)) (match-end 0))
1370 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1371 (when (looking-at "Hash:.*$")
1372 (delete-region (point) (1+ (gnus-point-at-eol))))
1374 ;; Hide the actual signature.
1375 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1376 (setq end (1+ (match-beginning 0)))
1379 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1381 ;; Perhaps we shouldn't hide to the end of the buffer
1382 ;; if there is no end to the signature?
1384 ;; Hide "- " PGP quotation markers.
1386 (narrow-to-region beg end)
1387 (goto-char (point-min))
1388 (while (re-search-forward "^- " nil t)
1390 (match-beginning 0) (match-end 0)))
1392 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1394 (defun article-hide-pem (&optional arg)
1395 "Toggle hiding of any PEM headers and signatures in the current article.
1396 If given a negative prefix, always show; if given a positive prefix,
1398 (interactive (gnus-article-hidden-arg))
1399 (unless (gnus-article-check-hidden-text 'pem arg)
1401 (let (buffer-read-only end)
1403 (goto-char (point-min))
1404 ;; hide the horrendously ugly "header".
1405 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1408 (setq end (1+ (match-beginning 0)))
1409 (gnus-article-hide-text-type
1411 (if (search-forward "\n\n" nil t)
1415 ;; hide the trailer as well
1416 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1419 (gnus-article-hide-text-type
1420 (match-beginning 0) (match-end 0) 'pem))))))
1422 (defun article-hide-signature (&optional arg)
1423 "Hide the signature in the current article.
1424 If given a negative prefix, always show; if given a positive prefix,
1426 (interactive (gnus-article-hidden-arg))
1427 (unless (gnus-article-check-hidden-text 'signature arg)
1430 (let ((buffer-read-only nil))
1431 (when (gnus-article-narrow-to-signature)
1432 (gnus-article-hide-text-type
1433 (point-min) (point-max) 'signature)))))))
1435 (defun article-strip-leading-blank-lines ()
1436 "Remove all blank lines from the beginning of the article."
1439 (let ((inhibit-point-motion-hooks t)
1441 (when (article-goto-body)
1442 (while (and (not (eobp))
1443 (looking-at "[ \t]*$"))
1444 (gnus-delete-line))))))
1446 (defun article-goto-body ()
1447 "Place point at the start of the body."
1448 (goto-char (point-min))
1450 (article-goto-body-goes-to-point-min-p
1452 ((search-forward "\n\n" nil t)
1455 (goto-char (point-max))
1458 (defun article-strip-multiple-blank-lines ()
1459 "Replace consecutive blank lines with one empty line."
1462 (let ((inhibit-point-motion-hooks t)
1464 ;; First make all blank lines empty.
1466 (while (re-search-forward "^[ \t]+$" nil t)
1467 (unless (gnus-annotation-in-region-p
1468 (match-beginning 0) (match-end 0))
1469 (replace-match "" nil t)))
1470 ;; Then replace multiple empty lines with a single empty line.
1472 (while (re-search-forward "\n\n\n+" nil t)
1473 (unless (gnus-annotation-in-region-p
1474 (match-beginning 0) (match-end 0))
1475 (replace-match "\n\n" t t))))))
1477 (defun article-strip-leading-space ()
1478 "Remove all white space from the beginning of the lines in the article."
1481 (let ((inhibit-point-motion-hooks t)
1484 (while (re-search-forward "^[ \t]+" nil t)
1485 (replace-match "" t t)))))
1487 (defun article-strip-trailing-space ()
1488 "Remove all white space from the end of the lines in the article."
1491 (let ((inhibit-point-motion-hooks t)
1494 (while (re-search-forward "[ \t]+$" nil t)
1495 (replace-match "" t t)))))
1497 (defun article-strip-blank-lines ()
1498 "Strip leading, trailing and multiple blank lines."
1500 (article-strip-leading-blank-lines)
1501 (article-remove-trailing-blank-lines)
1502 (article-strip-multiple-blank-lines))
1504 (defun article-strip-all-blank-lines ()
1505 "Strip all blank lines."
1508 (let ((inhibit-point-motion-hooks t)
1511 (while (re-search-forward "^[ \t]*\n" nil t)
1512 (replace-match "" t t)))))
1514 (defun gnus-article-narrow-to-signature ()
1515 "Narrow to the signature; return t if a signature is found, else nil."
1517 (let ((inhibit-point-motion-hooks t))
1518 (when (gnus-article-search-signature)
1520 ;; Check whether we have some limits to what we consider
1521 ;; to be a signature.
1522 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1523 (list gnus-signature-limit)))
1525 (while (setq limit (pop limits))
1526 (if (or (and (integerp limit)
1527 (< (- (point-max) (point)) limit))
1529 (< (count-lines (point) (point-max)) limit))
1530 (and (gnus-functionp limit)
1532 (and (stringp limit)
1533 (not (re-search-forward limit nil t))))
1534 () ; This limit did not succeed.
1538 (narrow-to-region (point) (point-max))
1541 (defun gnus-article-search-signature ()
1542 "Search the current buffer for the signature separator.
1543 Put point at the beginning of the signature separator."
1544 (let ((cur (point)))
1545 (goto-char (point-max))
1546 (if (if (stringp gnus-signature-separator)
1547 (re-search-backward gnus-signature-separator nil t)
1548 (let ((seps gnus-signature-separator))
1550 (not (re-search-backward (car seps) nil t)))
1558 (autoload 'w3-display "w3-parse")
1559 (autoload 'w3-do-setup "w3" "" t)
1560 (autoload 'w3-region "w3-display" "" t))
1562 (defun gnus-article-treat-html ()
1565 (let ((cbuf (current-buffer)))
1566 (set-buffer gnus-article-buffer)
1567 (let (buf buffer-read-only b e)
1569 (goto-char (point-min))
1571 (if (search-forward "\n\n" nil t)
1574 (setq e (point-max)))
1576 (insert-buffer-substring gnus-article-buffer b e)
1578 (save-window-excursion
1579 (w3-region (point-min) (point-max))
1580 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1582 (delete-region (point-min) (point-max))
1585 (goto-char (point-min))
1586 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1587 (set-buffer cbuf))))
1589 (defun gnus-article-hidden-arg ()
1590 "Return the current prefix arg as a number, or 0 if no prefix."
1591 (list (if current-prefix-arg
1592 (prefix-numeric-value current-prefix-arg)
1595 (defun gnus-article-check-hidden-text (type arg)
1596 "Return nil if hiding is necessary.
1597 Arg can be nil or a number. Nil and positive means hide, negative
1598 means show, 0 means toggle."
1602 (let ((hide (gnus-article-hidden-text-p type)))
1608 (gnus-article-show-hidden-text type))
1610 (if (eq hide 'hidden)
1611 (gnus-article-show-hidden-text type)
1614 (defun gnus-article-hidden-text-p (type)
1615 "Say whether the current buffer contains hidden text of type TYPE."
1616 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1618 (not (get-text-property pos 'invisible)))
1620 (text-property-any (1+ pos) (point-max) 'article-type type)))
1625 (defun gnus-article-show-hidden-text (type &optional hide)
1626 "Show all hidden text of type TYPE.
1627 If HIDE, hide the text instead."
1629 (let ((buffer-read-only nil)
1630 (inhibit-point-motion-hooks t)
1633 (while (setq beg (text-property-any end (point-max) 'article-type type))
1636 (text-property-not-all beg (point-max) 'article-type type)
1639 (gnus-article-hide-text beg end gnus-hidden-properties)
1640 (gnus-article-unhide-text beg end))
1644 (defconst article-time-units
1645 `((year . ,(* 365.25 24 60 60))
1646 (week . ,(* 7 24 60 60))
1647 (day . ,(* 24 60 60))
1651 "Mapping from time units to seconds.")
1653 (defun article-date-ut (&optional type highlight header)
1654 "Convert DATE date to universal time in the current article.
1655 If TYPE is `local', convert to local time; if it is `lapsed', output
1656 how much time has lapsed since DATE."
1657 (interactive (list 'ut t))
1658 (let* ((header (or header
1659 (mail-header-date (save-excursion
1660 (set-buffer gnus-summary-buffer)
1661 gnus-current-headers))
1662 (message-fetch-field "date")
1664 (date (if (vectorp header) (mail-header-date header)
1666 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1667 (inhibit-point-motion-hooks t)
1668 bface eface newline)
1669 (when (and date (not (string= date "")))
1672 (nnheader-narrow-to-headers)
1673 (let ((buffer-read-only nil))
1674 ;; Delete any old Date headers.
1675 (if (re-search-forward date-regexp nil t)
1677 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1678 eface (get-text-property (1- (gnus-point-at-eol))
1680 (delete-region (progn (beginning-of-line) (point))
1681 (progn (end-of-line) (point)))
1682 (beginning-of-line))
1683 (goto-char (point-max))
1685 (insert (article-make-date-line date type))
1688 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1689 (put-text-property (match-beginning 1) (1+ (match-end 1))
1691 (put-text-property (match-beginning 2) (match-end 2)
1695 (insert "\n"))))))))
1697 (defun article-make-date-line (date type)
1698 "Return a DATE line of TYPE."
1699 (let ((time (condition-case ()
1703 ;; Convert to the local timezone. We have to slap a
1704 ;; `condition-case' round the calls to the timezone
1705 ;; functions since they aren't particularly resistant to
1708 (let ((tz (car (current-time-zone))))
1709 (format "Date: %s %s%04d" (current-time-string time)
1710 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1711 ;; Convert to Universal Time.
1714 (current-time-string
1715 (let* ((e (parse-time-string date))
1716 (tm (apply 'encode-time e))
1718 (ls (- (cadr tm) (car (current-time-zone)))))
1719 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1720 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1723 ;; Get the original date from the article.
1724 ((eq type 'original)
1725 (concat "Date: " (if (string-match "\n+$" date)
1726 (substring date 0 (match-beginning 0))
1728 ;; Let the user define the format.
1730 (if (gnus-functionp gnus-article-time-format)
1731 (funcall gnus-article-time-format time)
1734 (format-time-string gnus-article-time-format time))))
1739 (format-time-string "%Y%m%dT%H%M%S" time)))
1740 ;; Do an X-Sent lapsed format.
1742 ;; If the date is seriously mangled, the timezone functions are
1743 ;; liable to bug out, so we ignore all errors.
1744 (let* ((now (current-time))
1745 (real-time (subtract-time now time))
1746 (real-sec (and real-time
1747 (+ (* (float (car real-time)) 65536)
1749 (sec (and real-time (abs real-sec)))
1759 ;; This is a bit convoluted, but basically we go
1760 ;; through the time units for years, weeks, etc,
1761 ;; and divide things to see whether that results
1762 ;; in positive answers.
1765 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1766 ;; The (remaining) seconds are too few to
1767 ;; be divided into this time unit.
1769 ;; It's big enough, so we output it.
1770 (setq sec (- sec (* num (cdr unit))))
1772 (concat (if prev ", " "") (int-to-string
1774 " " (symbol-name (car unit))
1775 (if (> num 1) "s" ""))
1777 article-time-units "")
1778 ;; If dates are odd, then it might appear like the
1779 ;; article was sent in the future.
1782 " in the future"))))))
1784 (error "Unknown conversion type: %s" type)))))
1786 (defun article-date-local (&optional highlight)
1787 "Convert the current article date to the local timezone."
1788 (interactive (list t))
1789 (article-date-ut 'local highlight))
1791 (defun article-date-original (&optional highlight)
1792 "Convert the current article date to what it was originally.
1793 This is only useful if you have used some other date conversion
1794 function and want to see what the date was before converting."
1795 (interactive (list t))
1796 (article-date-ut 'original highlight))
1798 (defun article-date-lapsed (&optional highlight)
1799 "Convert the current article date to time lapsed since it was sent."
1800 (interactive (list t))
1801 (article-date-ut 'lapsed highlight))
1803 (defun article-update-date-lapsed ()
1804 "Function to be run from a timer to update the lapsed time line."
1805 (let (deactivate-mark)
1810 (set-buffer (window-buffer w))
1811 (when (eq major-mode 'gnus-article-mode)
1812 (goto-char (point-min))
1813 (when (re-search-forward "^X-Sent:" nil t)
1814 (article-date-lapsed t))))
1817 (defun gnus-start-date-timer (&optional n)
1818 "Start a timer to update the X-Sent header in the article buffers.
1819 The numerical prefix says how frequently (in seconds) the function
1824 (gnus-stop-date-timer)
1825 (setq article-lapsed-timer
1826 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1828 (defun gnus-stop-date-timer ()
1829 "Stop the X-Sent timer."
1831 (when article-lapsed-timer
1832 (nnheader-cancel-timer article-lapsed-timer)
1833 (setq article-lapsed-timer nil)))
1835 (defun article-date-user (&optional highlight)
1836 "Convert the current article date to the user-defined format.
1837 This format is defined by the `gnus-article-time-format' variable."
1838 (interactive (list t))
1839 (article-date-ut 'user highlight))
1841 (defun article-date-iso8601 (&optional highlight)
1842 "Convert the current article date to ISO8601."
1843 (interactive (list t))
1844 (article-date-ut 'iso8601 highlight))
1846 (defun article-show-all ()
1847 "Show all hidden text in the article buffer."
1850 (let ((buffer-read-only nil))
1851 (gnus-article-unhide-text (point-min) (point-max)))))
1853 (defun article-emphasize (&optional arg)
1854 "Emphasize text according to `gnus-emphasis-alist'."
1855 (interactive (gnus-article-hidden-arg))
1856 (unless (gnus-article-check-hidden-text 'emphasis arg)
1858 (let ((alist gnus-emphasis-alist)
1859 (buffer-read-only nil)
1860 (props (append '(article-type emphasis)
1861 gnus-hidden-properties))
1862 regexp elem beg invisible visible face)
1865 (while (setq elem (pop alist))
1867 (setq regexp (car elem)
1868 invisible (nth 1 elem)
1869 visible (nth 2 elem)
1871 (while (re-search-forward regexp nil t)
1872 (when (and (match-beginning visible) (match-beginning invisible))
1873 (gnus-article-hide-text
1874 (match-beginning invisible) (match-end invisible) props)
1875 (gnus-article-unhide-text-type
1876 (match-beginning visible) (match-end visible) 'emphasis)
1877 (gnus-put-text-property-excluding-newlines
1878 (match-beginning visible) (match-end visible) 'face face)
1879 (goto-char (match-end invisible)))))))))
1881 (defvar gnus-summary-article-menu)
1882 (defvar gnus-summary-post-menu)
1884 ;;; Saving functions.
1886 (defun gnus-article-save (save-buffer file &optional num)
1887 "Save the currently selected article."
1888 (unless gnus-save-all-headers
1889 ;; Remove headers according to `gnus-saved-headers'.
1890 (let ((gnus-visible-headers
1891 (or gnus-saved-headers gnus-visible-headers))
1892 (gnus-article-buffer save-buffer))
1894 (set-buffer save-buffer)
1895 (article-hide-headers 1 t))))
1896 (save-window-excursion
1897 (if (not gnus-default-article-saver)
1898 (error "No default saver is defined")
1899 ;; !!! Magic! The saving functions all save
1900 ;; `gnus-save-article-buffer' (or so they think), but we
1901 ;; bind that variable to our save-buffer.
1902 (set-buffer gnus-article-buffer)
1903 (let* ((gnus-save-article-buffer save-buffer)
1906 ((not gnus-prompt-before-saving) 'default)
1907 ((eq gnus-prompt-before-saving 'always) nil)
1909 (gnus-number-of-articles-to-be-saved
1910 (when (eq gnus-prompt-before-saving t)
1912 (set-buffer gnus-article-current-summary)
1913 (funcall gnus-default-article-saver filename)))))
1915 (defun gnus-read-save-file-name (prompt &optional filename
1916 function group headers variable)
1918 (funcall function group headers (symbol-value variable)))
1923 ((eq filename 'default)
1929 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1932 (if (and gnus-number-of-articles-to-be-saved
1933 (> gnus-number-of-articles-to-be-saved 1))
1934 (format "these %d articles"
1935 gnus-number-of-articles-to-be-saved)
1938 ;; Let the split methods have their say.
1940 ;; No split name was found.
1943 (concat prompt " (default "
1944 (file-name-nondirectory default-name) ") ")
1945 (file-name-directory default-name)
1947 ;; A single group name is returned.
1948 ((stringp split-name)
1950 (funcall function split-name headers
1951 (symbol-value variable)))
1953 (concat prompt " (default "
1954 (file-name-nondirectory default-name) ") ")
1955 (file-name-directory default-name)
1957 ;; A single split name was found
1958 ((= 1 (length split-name))
1959 (let* ((name (expand-file-name
1960 (car split-name) gnus-article-save-directory))
1961 (dir (cond ((file-directory-p name)
1962 (file-name-as-directory name))
1963 ((file-exists-p name) name)
1964 (t gnus-article-save-directory))))
1966 (concat prompt " (default " name ") ")
1968 ;; A list of splits was found.
1970 (setq split-name (nreverse split-name))
1972 (let ((file-name-history
1973 (nconc split-name file-name-history)))
1977 (concat prompt " (`M-p' for defaults) ")
1978 gnus-article-save-directory
1980 gnus-article-save-directory)))
1981 (car (push result file-name-history)))))))
1982 ;; Create the directory.
1983 (gnus-make-directory (file-name-directory file))
1984 ;; If we have read a directory, we append the default file name.
1985 (when (file-directory-p file)
1986 (setq file (concat (file-name-as-directory file)
1987 (file-name-nondirectory default-name))))
1988 ;; Possibly translate some characters.
1989 (nnheader-translate-file-chars file)))))
1990 (gnus-make-directory (file-name-directory result))
1991 (set variable result)))
1993 (defun gnus-article-archive-name (group)
1994 "Return the first instance of an \"Archive-name\" in the current buffer."
1995 (let ((case-fold-search t))
1996 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1997 (nnheader-concat gnus-article-save-directory
1998 (match-string 1)))))
2000 (defun gnus-article-nndoc-name (group)
2001 "If GROUP is an nndoc group, return the name of the parent group."
2002 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2003 (gnus-group-get-parameter group 'save-article-group)))
2005 (defun gnus-summary-save-in-rmail (&optional filename)
2006 "Append this article to Rmail file.
2007 Optional argument FILENAME specifies file name.
2008 Directory to save to is default to `gnus-article-save-directory'."
2009 (setq filename (gnus-read-save-file-name
2010 "Save %s in rmail file:" filename
2011 gnus-rmail-save-name gnus-newsgroup-name
2012 gnus-current-headers 'gnus-newsgroup-last-rmail))
2013 (gnus-eval-in-buffer-window gnus-save-article-buffer
2017 (gnus-output-to-rmail filename))))
2020 (defun gnus-summary-save-in-mail (&optional filename)
2021 "Append this article to Unix mail file.
2022 Optional argument FILENAME specifies file name.
2023 Directory to save to is default to `gnus-article-save-directory'."
2024 (setq filename (gnus-read-save-file-name
2025 "Save %s in Unix mail file:" filename
2026 gnus-mail-save-name gnus-newsgroup-name
2027 gnus-current-headers 'gnus-newsgroup-last-mail))
2028 (gnus-eval-in-buffer-window gnus-save-article-buffer
2032 (if (and (file-readable-p filename)
2033 (mail-file-babyl-p filename))
2034 (rmail-output-to-rmail-file filename t)
2035 (gnus-output-to-mail filename)))))
2038 (defun gnus-summary-save-in-file (&optional filename overwrite)
2039 "Append this article to file.
2040 Optional argument FILENAME specifies file name.
2041 Directory to save to is default to `gnus-article-save-directory'."
2042 (setq filename (gnus-read-save-file-name
2043 "Save %s in file:" filename
2044 gnus-file-save-name gnus-newsgroup-name
2045 gnus-current-headers 'gnus-newsgroup-last-file))
2046 (gnus-eval-in-buffer-window gnus-save-article-buffer
2050 (when (and overwrite
2051 (file-exists-p filename))
2052 (delete-file filename))
2053 (gnus-output-to-file filename))))
2056 (defun gnus-summary-write-to-file (&optional filename)
2057 "Write this article to a file.
2058 Optional argument FILENAME specifies file name.
2059 The directory to save in defaults to `gnus-article-save-directory'."
2060 (gnus-summary-save-in-file nil t))
2062 (defun gnus-summary-save-body-in-file (&optional filename)
2063 "Append this article body to a file.
2064 Optional argument FILENAME specifies file name.
2065 The directory to save in defaults to `gnus-article-save-directory'."
2066 (setq filename (gnus-read-save-file-name
2067 "Save %s body in file:" filename
2068 gnus-file-save-name gnus-newsgroup-name
2069 gnus-current-headers 'gnus-newsgroup-last-file))
2070 (gnus-eval-in-buffer-window gnus-save-article-buffer
2074 (when (article-goto-body)
2075 (narrow-to-region (point) (point-max)))
2076 (gnus-output-to-file filename))))
2079 (defun gnus-summary-save-in-pipe (&optional command)
2080 "Pipe this article to subprocess."
2082 (cond ((and (eq command 'default)
2083 gnus-last-shell-command)
2084 gnus-last-shell-command)
2088 "Shell command on %s: "
2089 (if (and gnus-number-of-articles-to-be-saved
2090 (> gnus-number-of-articles-to-be-saved 1))
2091 (format "these %d articles"
2092 gnus-number-of-articles-to-be-saved)
2094 gnus-last-shell-command))))
2095 (when (string-equal command "")
2096 (setq command gnus-last-shell-command))
2097 (gnus-eval-in-buffer-window gnus-article-buffer
2100 (shell-command-on-region (point-min) (point-max) command nil)))
2101 (setq gnus-last-shell-command command))
2103 ;;; Article file names when saving.
2105 (defun gnus-capitalize-newsgroup (newsgroup)
2106 "Capitalize NEWSGROUP name."
2107 (when (not (zerop (length newsgroup)))
2108 (concat (char-to-string (upcase (aref newsgroup 0)))
2109 (substring newsgroup 1))))
2111 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2112 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2113 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2114 Otherwise, it is like ~/News/news/group/num."
2117 (concat (if (gnus-use-long-file-name 'not-save)
2118 (gnus-capitalize-newsgroup newsgroup)
2119 (gnus-newsgroup-directory-form newsgroup))
2120 "/" (int-to-string (mail-header-number headers)))
2121 gnus-article-save-directory)))
2123 (string-equal (file-name-directory default)
2124 (file-name-directory last-file))
2125 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2127 (or last-file default))))
2129 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2130 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2131 If variable `gnus-use-long-file-name' is non-nil, it is
2132 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2135 (concat (if (gnus-use-long-file-name 'not-save)
2137 (gnus-newsgroup-directory-form newsgroup))
2138 "/" (int-to-string (mail-header-number headers)))
2139 gnus-article-save-directory)))
2141 (string-equal (file-name-directory default)
2142 (file-name-directory last-file))
2143 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2145 (or last-file default))))
2147 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2148 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2149 If variable `gnus-use-long-file-name' is non-nil, it is
2150 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2153 (if (gnus-use-long-file-name 'not-save)
2154 (gnus-capitalize-newsgroup newsgroup)
2155 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2156 gnus-article-save-directory)))
2158 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2159 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2160 If variable `gnus-use-long-file-name' is non-nil, it is
2161 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2164 (if (gnus-use-long-file-name 'not-save)
2166 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2167 gnus-article-save-directory)))
2174 (setq afunc (car func)
2177 gfunc (intern (format "gnus-%s" func))))
2179 (if (not (fboundp afunc))
2181 `(lambda (&optional interactive &rest args)
2182 ,(documentation afunc t)
2183 (interactive (list t))
2185 (set-buffer gnus-article-buffer)
2187 (call-interactively ',afunc)
2188 (apply ',afunc args))))))))
2189 '(article-hide-headers
2190 article-hide-boring-headers
2191 article-treat-overstrike
2192 article-fill-long-lines
2194 article-display-x-face
2195 article-de-quoted-unreadable
2196 article-mime-decode-quoted-printable
2199 article-hide-signature
2200 article-remove-trailing-blank-lines
2201 article-strip-leading-blank-lines
2202 article-strip-multiple-blank-lines
2203 article-strip-leading-space
2204 article-strip-trailing-space
2205 article-strip-blank-lines
2206 article-strip-all-blank-lines
2208 article-date-iso8601
2209 article-date-original
2211 article-decode-mime-words
2212 article-decode-charset
2213 article-decode-encoded-words
2217 article-treat-dumbquotes
2218 article-normalize-headers
2219 (article-show-all . gnus-article-show-all-headers))))
2222 ;;; Gnus article mode
2225 (put 'gnus-article-mode 'mode-class 'special)
2227 (gnus-define-keys gnus-article-mode-map
2228 " " gnus-article-goto-next-page
2229 "\177" gnus-article-goto-prev-page
2230 [delete] gnus-article-goto-prev-page
2231 [backspace] gnus-article-goto-prev-page
2232 "\C-c^" gnus-article-refer-article
2233 "h" gnus-article-show-summary
2234 "s" gnus-article-show-summary
2235 "\C-c\C-m" gnus-article-mail
2236 "?" gnus-article-describe-briefly
2237 gnus-mouse-2 gnus-article-push-button
2238 "\r" gnus-article-press-button
2239 "\t" gnus-article-next-button
2240 "\M-\t" gnus-article-prev-button
2241 "e" gnus-article-edit
2242 "<" beginning-of-buffer
2244 "\C-c\C-i" gnus-info-find-node
2247 "\C-d" gnus-article-read-summary-keys
2248 "\M-*" gnus-article-read-summary-keys
2249 "\M-#" gnus-article-read-summary-keys
2250 "\M-^" gnus-article-read-summary-keys
2251 "\M-g" gnus-article-read-summary-keys)
2253 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2256 (unless (lookup-key gnus-article-mode-map key)
2257 (define-key gnus-article-mode-map key
2258 'gnus-article-read-summary-keys)))
2263 (let ((key (car elt)))
2264 (and (> (length key) 0)
2265 (not (eq 'menu-bar (aref key 0)))
2266 (symbolp (lookup-key gnus-summary-mode-map key))
2268 (accessible-keymaps gnus-summary-mode-map))
2272 (push (char-to-string c) keys)
2276 (defun gnus-article-make-menu-bar ()
2277 (gnus-turn-off-edit-menu 'article)
2278 (unless (boundp 'gnus-article-article-menu)
2280 gnus-article-article-menu gnus-article-mode-map ""
2282 ["Scroll forwards" gnus-article-goto-next-page t]
2283 ["Scroll backwards" gnus-article-goto-prev-page t]
2284 ["Show summary" gnus-article-show-summary t]
2285 ["Fetch Message-ID at point" gnus-article-refer-article t]
2286 ["Mail to address at point" gnus-article-mail t]
2287 ["Send a bug report" gnus-bug t]))
2290 gnus-article-treatment-menu gnus-article-mode-map ""
2292 ["Hide headers" gnus-article-hide-headers t]
2293 ["Hide signature" gnus-article-hide-signature t]
2294 ["Hide citation" gnus-article-hide-citation t]
2295 ["Treat overstrike" gnus-article-treat-overstrike t]
2296 ["Remove carriage return" gnus-article-remove-cr t]))
2298 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2300 (when (boundp 'gnus-summary-post-menu)
2301 (define-key gnus-article-mode-map [menu-bar post]
2302 (cons "Post" gnus-summary-post-menu)))
2304 (gnus-run-hooks 'gnus-article-menu-hook)))
2306 (defun gnus-article-mode ()
2307 "Major mode for displaying an article.
2309 All normal editing commands are switched off.
2311 The following commands are available in addition to all summary mode
2313 \\<gnus-article-mode-map>
2314 \\[gnus-article-next-page]\t Scroll the article one page forwards
2315 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2316 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2317 \\[gnus-article-show-summary]\t Display the summary buffer
2318 \\[gnus-article-mail]\t Send a reply to the address near point
2319 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2320 \\[gnus-info-find-node]\t Go to the Gnus info node"
2322 (when (gnus-visual-p 'article-menu 'menu)
2323 (gnus-article-make-menu-bar))
2324 (gnus-simplify-mode-line)
2325 (setq mode-name "Article")
2326 (setq major-mode 'gnus-article-mode)
2327 (make-local-variable 'minor-mode-alist)
2328 (unless (assq 'gnus-show-mime minor-mode-alist)
2329 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2330 (use-local-map gnus-article-mode-map)
2331 (gnus-update-format-specifications nil 'article-mode)
2332 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2333 (make-local-variable 'gnus-page-broken)
2334 (make-local-variable 'gnus-button-marker-list)
2335 (make-local-variable 'gnus-article-current-summary)
2336 (make-local-variable 'gnus-article-mime-handles)
2337 (make-local-variable 'gnus-article-decoded-p)
2338 (make-local-variable 'gnus-article-mime-handle-alist)
2339 (gnus-set-default-directory)
2340 (buffer-disable-undo)
2341 (setq buffer-read-only t)
2342 (set-syntax-table gnus-article-mode-syntax-table)
2343 (gnus-run-hooks 'gnus-article-mode-hook))
2345 (defun gnus-article-setup-buffer ()
2346 "Initialize the article buffer."
2347 (let* ((name (if gnus-single-article-buffer "*Article*"
2348 (concat "*Article " gnus-newsgroup-name "*")))
2350 (progn (string-match "\\*Article" name)
2351 (concat " *Original Article"
2352 (substring name (match-end 0))))))
2353 (setq gnus-article-buffer name)
2354 (setq gnus-original-article-buffer original)
2355 (setq gnus-article-mime-handle-alist nil)
2356 ;; This might be a variable local to the summary buffer.
2357 (unless gnus-single-article-buffer
2359 (set-buffer gnus-summary-buffer)
2360 (setq gnus-article-buffer name)
2361 (setq gnus-original-article-buffer original)
2362 (gnus-set-global-variables)))
2363 ;; Init original article buffer.
2365 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2366 (setq major-mode 'gnus-original-article-mode)
2367 (make-local-variable 'gnus-original-article))
2368 (if (get-buffer name)
2371 (buffer-disable-undo)
2372 (setq buffer-read-only t)
2373 (unless (eq major-mode 'gnus-article-mode)
2374 (gnus-article-mode))
2377 (set-buffer (gnus-get-buffer-create name))
2379 (make-local-variable 'gnus-summary-buffer)
2380 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2381 (current-buffer)))))
2383 ;; Set article window start at LINE, where LINE is the number of lines
2384 ;; from the head of the article.
2385 (defun gnus-article-set-window-start (&optional line)
2387 (get-buffer-window gnus-article-buffer t)
2389 (set-buffer gnus-article-buffer)
2390 (goto-char (point-min))
2393 (gnus-message 6 "Moved to bookmark")
2394 (search-forward "\n\n" nil t)
2398 ;;; @@ article filters
2401 (defun gnus-article-display-mime-message ()
2402 "Article display method for MIME message."
2403 ;; called from `gnus-original-article-buffer'.
2404 (let (charset all-headers)
2405 (with-current-buffer gnus-summary-buffer
2406 (setq charset default-mime-charset
2407 all-headers gnus-have-all-headers))
2408 (make-local-variable 'default-mime-charset)
2409 (setq default-mime-charset charset)
2410 (mime-display-message mime-message-structure
2411 gnus-article-buffer nil gnus-article-mode-map)
2413 (gnus-article-hide-headers nil -1))
2414 (make-local-variable 'default-mime-charset)
2415 (setq default-mime-charset charset)
2417 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2418 (make-local-variable 'mime-button-mother-dispatcher)
2419 (setq mime-button-mother-dispatcher
2420 (function gnus-article-push-button))
2421 (run-hooks 'gnus-mime-article-prepare-hook))
2423 (defun gnus-article-display-traditional-message ()
2424 "Article display method for traditional message."
2425 (set-buffer gnus-article-buffer)
2426 (let (buffer-read-only)
2428 (insert-buffer-substring gnus-original-article-buffer)))
2430 (defun gnus-article-make-full-mail-header (&optional number charset)
2431 "Create a new mail header structure in a raw article buffer."
2432 (unless (and number charset)
2433 (save-current-buffer
2434 (set-buffer gnus-summary-buffer)
2436 (setq number (or (cdr gnus-article-current) 0)))
2438 (setq charset (or default-mime-charset 'x-ctext)))))
2439 (goto-char (point-min))
2440 (let ((header-end (if (search-forward "\n\n" nil t)
2442 (goto-char (point-max))))
2443 (chars (- (point-max) (point)))
2444 (lines (count-lines (point) (point-max)))
2445 (default-mime-charset charset)
2447 (narrow-to-region (point-min) header-end)
2448 (setq xref (std11-fetch-field "xref"))
2450 (make-full-mail-header
2452 (std11-fetch-field "subject")
2453 (std11-fetch-field "from")
2454 (std11-fetch-field "date")
2455 (std11-fetch-field "message-id")
2456 (std11-fetch-field "references")
2459 (when xref (concat "Xref: " xref)))
2462 (defun gnus-article-prepare (article &optional all-headers header)
2463 "Prepare ARTICLE in article mode buffer.
2464 ARTICLE should either be an article number or a Message-ID.
2465 If ARTICLE is an id, HEADER should be the article headers.
2466 If ALL-HEADERS is non-nil, no headers are hidden."
2468 ;; Make sure we start in a summary buffer.
2469 (unless (eq major-mode 'gnus-summary-mode)
2470 (set-buffer gnus-summary-buffer))
2471 (setq gnus-summary-buffer (current-buffer))
2472 (let* ((gnus-article (if header (mail-header-number header) article))
2473 (summary-buffer (current-buffer))
2474 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2475 (group gnus-newsgroup-name)
2478 (gnus-article-setup-buffer)
2479 (set-buffer gnus-original-article-buffer)
2480 ;; Deactivate active regions.
2481 (when (and (boundp 'transient-mark-mode)
2482 transient-mark-mode)
2483 (setq mark-active nil))
2484 (if (not (setq result (let ((buffer-read-only nil))
2485 (gnus-request-article-this-buffer
2487 ;; There is no such article.
2489 (when (and (numberp article)
2490 (not (memq article gnus-newsgroup-sparse)))
2491 (setq gnus-article-current
2492 (cons gnus-newsgroup-name article))
2493 (set-buffer gnus-summary-buffer)
2494 (setq gnus-current-article article)
2495 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2497 (gnus-summary-set-agent-mark article)
2498 (message "Message marked for downloading"))
2499 (gnus-summary-mark-article article gnus-canceled-mark)
2500 (unless (memq article gnus-newsgroup-sparse)
2502 "No such article (may have expired or been canceled)")))))
2503 (if (or (eq result 'pseudo)
2504 (eq result 'nneething))
2507 (set-buffer summary-buffer)
2508 (push article gnus-newsgroup-history)
2509 (setq gnus-last-article gnus-current-article
2510 gnus-current-article 0
2511 gnus-current-headers nil
2512 gnus-article-current nil)
2513 (if (eq result 'nneething)
2514 (gnus-configure-windows 'summary)
2515 (gnus-configure-windows 'article))
2516 (gnus-set-global-variables))
2517 (let ((gnus-article-mime-handle-alist-1
2518 gnus-article-mime-handle-alist))
2519 (gnus-set-mode-line 'article)))
2520 ;; The result from the `request' was an actual article -
2521 ;; or at least some text that is now displayed in the
2523 (when (and (numberp article)
2524 (not (eq article gnus-current-article)))
2525 ;; Seems like a new article has been selected.
2526 ;; `gnus-current-article' must be an article number.
2528 (set-buffer summary-buffer)
2529 (push article gnus-newsgroup-history)
2530 (setq gnus-last-article gnus-current-article
2531 gnus-current-article article
2532 gnus-current-headers
2533 (gnus-summary-article-header gnus-current-article)
2534 gnus-article-current
2535 (cons gnus-newsgroup-name gnus-current-article))
2536 (unless (vectorp gnus-current-headers)
2537 (setq gnus-current-headers nil))
2538 (gnus-summary-goto-subject gnus-current-article)
2539 (when (gnus-summary-show-thread)
2540 ;; If the summary buffer really was folded, the
2541 ;; previous goto may not actually have gone to
2542 ;; the right article, but the thread root instead.
2544 (gnus-summary-goto-subject gnus-current-article))
2545 (gnus-run-hooks 'gnus-mark-article-hook)
2546 (gnus-set-mode-line 'summary)
2547 (when (gnus-visual-p 'article-highlight 'highlight)
2548 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2549 ;; Set the global newsgroup variables here.
2550 ;; Suggested by Jim Sisolak
2551 ;; <sisolak@trans4.neep.wisc.edu>.
2552 (gnus-set-global-variables)
2553 (setq gnus-have-all-headers
2554 (or all-headers gnus-show-all-headers))))
2555 (when (or (numberp article)
2557 (gnus-article-prepare-display)
2559 (goto-char (point-min))
2560 (setq gnus-page-broken
2561 (when gnus-break-pages
2562 (gnus-narrow-to-page)
2564 (let ((gnus-article-mime-handle-alist-1
2565 gnus-article-mime-handle-alist))
2566 (gnus-set-mode-line 'article))
2567 (gnus-configure-windows 'article)
2569 (set-window-point (get-buffer-window (current-buffer)) (point))
2573 (defun gnus-article-prepare-display ()
2574 "Make the current buffer look like a nice article."
2578 (setq mime-message-structure gnus-current-headers)
2579 gnus-article-display-method-for-mime)
2580 gnus-article-display-method-for-traditional)))
2581 (gnus-run-hooks 'gnus-tmp-internal-hook)
2582 (gnus-run-hooks 'gnus-article-prepare-hook)
2585 ;; Associate this article with the current summary buffer.
2586 (setq gnus-article-current-summary gnus-summary-buffer)
2587 ;; Perform the article display hooks.
2588 (gnus-run-hooks 'gnus-article-display-hook)))
2591 ;;; Gnus MIME viewing functions
2594 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2595 "The following specs can be used:
2597 %T MIME type, along with additional info
2598 %n The `name' parameter
2599 %d The description, if any
2600 %l The length of the encoded part
2601 %p The part identifier number
2602 %e Dots if the part isn't displayed")
2604 (defvar gnus-mime-button-line-format-alist
2605 '((?t gnus-tmp-type ?s)
2606 (?T gnus-tmp-type-long ?s)
2607 (?n gnus-tmp-name ?s)
2608 (?d gnus-tmp-description ?s)
2610 (?l gnus-tmp-length ?d)
2611 (?e gnus-tmp-dots ?s)))
2613 (defvar gnus-mime-button-commands
2614 '((gnus-article-press-button "\r" "Toggle Display")
2615 (gnus-mime-view-part "v" "View Interactively...")
2616 (gnus-mime-save-part "o" "Save...")
2617 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2618 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2619 (gnus-mime-internalize-part "E" "View Internally")
2620 (gnus-mime-externalize-part "e" "View Externally")
2621 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2623 (defun gnus-article-mime-part-status ()
2624 (if gnus-article-mime-handle-alist-1
2625 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2628 (defvar gnus-mime-button-map nil)
2629 (unless gnus-mime-button-map
2630 (setq gnus-mime-button-map (make-sparse-keymap))
2631 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2632 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2633 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2635 (define-key gnus-mime-button-map (cadr c) (car c)))
2636 gnus-mime-button-commands))
2638 (defun gnus-mime-button-menu (event)
2639 "Construct a context-sensitive menu of MIME commands."
2642 (let ((pos (event-start event)))
2643 (set-buffer (window-buffer (posn-window pos)))
2644 (goto-char (posn-point pos))
2645 (gnus-article-check-buffer)
2646 (let ((response (x-popup-menu
2648 ("" ,@(mapcar (lambda (c)
2649 (cons (caddr c) (car c)))
2650 gnus-mime-button-commands))))))
2652 (funcall response))))))
2654 (defun gnus-mime-view-all-parts (&optional handles)
2655 "View all the MIME parts."
2657 (save-current-buffer
2658 (set-buffer gnus-article-buffer)
2659 (let ((handles (or handles gnus-article-mime-handles))
2660 (mail-parse-charset gnus-newsgroup-charset))
2661 (if (stringp (car handles))
2662 (gnus-mime-view-all-parts (cdr handles))
2663 (mapcar 'mm-display-part handles)))))
2665 (defun gnus-mime-save-part ()
2666 "Save the MIME part under point."
2668 (gnus-article-check-buffer)
2669 (let ((data (get-text-property (point) 'gnus-data)))
2670 (mm-save-part data)))
2672 (defun gnus-mime-pipe-part ()
2673 "Pipe the MIME part under point to a process."
2675 (gnus-article-check-buffer)
2676 (let ((data (get-text-property (point) 'gnus-data)))
2677 (mm-pipe-part data)))
2679 (defun gnus-mime-view-part ()
2680 "Interactively choose a view method for the MIME part under point."
2682 (gnus-article-check-buffer)
2683 (let ((data (get-text-property (point) 'gnus-data)))
2684 (mm-interactively-view-part data)))
2686 (defun gnus-mime-copy-part (&optional handle)
2687 "Put the the MIME part under point into a new buffer."
2689 (gnus-article-check-buffer)
2690 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2691 (contents (mm-get-part handle))|
2692 (base (file-name-nondirectory
2694 (mail-content-type-get (mm-handle-type handle) 'name)
2695 (mail-content-type-get (mm-handle-type handle)
2698 (buffer (generate-new-buffer base)))
2699 (switch-to-buffer buffer)
2701 ;; We do it this way to make `normal-mode' set the appropriate mode.
2704 (setq buffer-file-name (expand-file-name base))
2706 (setq buffer-file-name nil))
2707 (goto-char (point-min))))
2709 (defun gnus-mime-inline-part (&optional charset)
2710 "Insert the MIME part under point into the current buffer."
2711 (interactive "P") ; For compatibility reasons we are not using "z".
2712 (gnus-article-check-buffer)
2713 (let* ((data (get-text-property (point) 'gnus-data))
2717 (if (mm-handle-undisplayer data)
2718 (mm-remove-part data)
2719 (setq contents (mm-get-part data))
2722 (unless (symbolp charset)
2723 (setq charset (mm-read-coding-system "Charset: ")))
2724 (setq contents (mm-decode-coding-string contents charset)))
2725 (mm-insert-inline data contents)
2728 (defun gnus-mime-externalize-part (&optional handle)
2729 "View the MIME part under point with an external viewer."
2731 (gnus-article-check-buffer)
2732 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2733 (mm-user-display-methods nil)
2734 (mm-all-images-fit t)
2735 (mail-parse-charset gnus-newsgroup-charset))
2736 (if (mm-handle-undisplayer handle)
2737 (mm-remove-part handle)
2738 (mm-display-part handle))))
2740 (defun gnus-mime-internalize-part (&optional handle)
2741 "View the MIME part under point with an internal viewer."
2743 (gnus-article-check-buffer)
2744 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2745 (mm-user-display-methods '((".*" . inline)))
2746 (mm-all-images-fit t)
2747 (mail-parse-charset gnus-newsgroup-charset))
2748 (if (mm-handle-undisplayer handle)
2749 (mm-remove-part handle)
2750 (mm-display-part handle))))
2752 (defun gnus-article-part-wrapper (n function)
2753 (save-current-buffer
2754 (set-buffer gnus-article-buffer)
2755 (when (> n (length gnus-article-mime-handle-alist))
2756 (error "No such part"))
2757 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2758 (funcall function handle))))
2760 (defun gnus-article-pipe-part (n)
2761 "Pipe MIME part N, which is the numerical prefix."
2763 (gnus-article-part-wrapper n 'mm-pipe-part))
2765 (defun gnus-article-save-part (n)
2766 "Save MIME part N, which is the numerical prefix."
2768 (gnus-article-part-wrapper n 'mm-save-part))
2770 (defun gnus-article-interactively-view-part (n)
2771 "Pipe MIME part N, which is the numerical prefix."
2773 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2775 (defun gnus-article-copy-part (n)
2776 "Pipe MIME part N, which is the numerical prefix."
2778 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2780 (defun gnus-article-externalize-part (n)
2781 "Pipe MIME part N, which is the numerical prefix."
2783 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2785 (defun gnus-article-view-part (n)
2786 "View MIME part N, which is the numerical prefix."
2788 (save-current-buffer
2789 (set-buffer gnus-article-buffer)
2790 (when (> n (length gnus-article-mime-handle-alist))
2791 (error "No such part"))
2792 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2793 (when (gnus-article-goto-part n)
2794 (if (equal (car handle) "multipart/alternative")
2795 (gnus-article-press-button)
2796 (when (eq (gnus-mm-display-part handle) 'internal)
2797 (gnus-set-window-start)))))))
2799 (defun gnus-mm-display-part (handle)
2800 "Display HANDLE and fix MIME button."
2801 (let ((id (get-text-property (point) 'gnus-part))
2806 (let ((window (selected-window))
2807 (mail-parse-charset gnus-newsgroup-charset))
2810 (let ((win (get-buffer-window (current-buffer) t))
2813 (select-window win))
2816 (if (mm-handle-displayed-p handle)
2817 ;; This will remove the part.
2818 (mm-display-part handle)
2820 (narrow-to-region (point) (1+ (point)))
2821 (mm-display-part handle)
2824 (1- (length gnus-article-mime-handles))
2825 (car (mm-handle-type handle))))))
2826 (select-window window))))
2828 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2829 (gnus-insert-mime-button
2830 handle id (list (mm-handle-displayed-p handle)))
2831 (goto-char point))))
2833 (defun gnus-article-goto-part (n)
2834 "Go to MIME part N."
2835 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2837 (goto-char point))))
2839 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2840 (let ((gnus-tmp-name
2841 (or (mail-content-type-get (mm-handle-type handle)
2843 (mail-content-type-get (mm-handle-disposition handle)
2846 (gnus-tmp-type (car (mm-handle-type handle)))
2847 (gnus-tmp-description
2848 (mail-decode-encoded-word-string (or (mm-handle-description handle)
2851 (if (if displayed (car displayed)
2852 (mm-handle-displayed-p handle))
2854 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2856 gnus-tmp-type-long b e)
2857 (when (string-match ".*/" gnus-tmp-name)
2858 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2859 (setq gnus-tmp-type-long (concat gnus-tmp-type
2860 (and (not (equal gnus-tmp-name ""))
2861 (concat "; " gnus-tmp-name))))
2862 (or (equal gnus-tmp-description "")
2863 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2868 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2869 `(local-map ,gnus-mime-button-map
2870 keymap ,gnus-mime-button-map
2871 gnus-callback gnus-mm-display-part
2872 gnus-part ,gnus-tmp-id
2873 article-type annotation
2876 (widget-convert-button 'link b e
2878 :action 'gnus-widget-press-button
2879 :button-keymap gnus-mime-button-map
2882 ;; Needed to properly clear the message
2883 ;; due to a bug in wid-edit
2884 (setq help-echo-owns-message t)
2886 "Click to %s the MIME part; %s for more options"
2887 (if (mm-handle-displayed-p
2888 (widget-get widget :mime-handle))
2890 (if gnus-xemacs "button3" "mouse-3"))))))
2892 (defun gnus-widget-press-button (elems el)
2893 (goto-char (widget-get elems :from))
2894 (gnus-article-press-button))
2896 (defun gnus-display-mime (&optional ihandles)
2897 "Display the MIME parts."
2899 (save-selected-window
2900 (let ((window (get-buffer-window gnus-article-buffer))
2903 (select-window window)
2904 ;; We have to do this since selecting the window
2905 ;; may change the point. So we set the window point.
2906 (set-window-point window point)))
2907 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2908 handle name type b e display)
2910 ;; Top-level call; we clean up.
2911 (mm-destroy-parts gnus-article-mime-handles)
2912 (setq gnus-article-mime-handles handles
2913 gnus-article-mime-handle-alist nil)
2914 ;; We allow users to glean info from the handles.
2915 (when gnus-article-mime-part-function
2916 (gnus-mime-part-function handles)))
2918 (or (not (stringp (car handles)))
2922 ;; Clean up for mime parts.
2924 (delete-region (point) (point-max)))
2925 (gnus-mime-display-part handles))
2928 (narrow-to-region (point) (point-max))
2929 (gnus-treat-article nil 1 1)))
2930 ;; Highlight the headers.
2934 (narrow-to-region (point-min) (point))
2935 (gnus-treat-article 'head)))))))
2937 (defvar gnus-mime-display-multipart-as-mixed nil)
2939 (defun gnus-mime-display-part (handle)
2942 ((not (stringp (car handle)))
2943 (gnus-mime-display-single handle))
2944 ;; multipart/alternative
2945 ((and (equal (car handle) "multipart/alternative")
2946 (not gnus-mime-display-multipart-as-mixed))
2947 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2948 (push (cons id handle) gnus-article-mime-handle-alist)
2949 (gnus-mime-display-alternative (cdr handle) nil nil id)))
2950 ;; multipart/related
2951 ((and (equal (car handle) "multipart/related")
2952 (not gnus-mime-display-multipart-as-mixed))
2953 ;;;!!!We should find the start part, but we just default
2954 ;;;!!!to the first part.
2955 (gnus-mime-display-part (cadr handle)))
2956 ;; Other multiparts are handled like multipart/mixed.
2958 (gnus-mime-display-mixed (cdr handle)))))
2960 (defun gnus-mime-part-function (handles)
2961 (if (stringp (car handles))
2962 (mapcar 'gnus-mime-part-function (cdr handles))
2963 (funcall gnus-article-mime-part-function handles)))
2965 (defun gnus-mime-display-mixed (handles)
2966 (mapcar 'gnus-mime-display-part handles))
2968 (defun gnus-mime-display-single (handle)
2969 (let ((type (car (mm-handle-type handle)))
2970 (ignored gnus-ignored-mime-types)
2977 (when (string-match (pop ignored) type)
2978 (throw 'ignored nil)))
2979 (if (and (setq not-attachment
2980 (or (not (mm-handle-disposition handle))
2981 (equal (car (mm-handle-disposition handle))
2983 (mm-attachment-override-p type)))
2984 (mm-automatic-display-p type)
2985 (or (mm-inlinable-part-p type)
2986 (mm-automatic-external-display-p type)))
2988 (when (equal (car (split-string type "/"))
2991 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2992 (push (cons id handle) gnus-article-mime-handle-alist)
2993 (when (or (not display)
2994 (not (gnus-unbuttonized-mime-type-p type)))
2995 (gnus-article-insert-newline)
2996 (gnus-insert-mime-button
2997 handle id (list (or display (and not-attachment text))))
2998 (gnus-article-insert-newline)
2999 (gnus-article-insert-newline)
3001 (let ((beg (point)))
3006 (let ((mail-parse-charset gnus-newsgroup-charset))
3007 (mm-display-part handle t))
3008 (goto-char (point-max)))
3009 ((and text not-attachment)
3012 (gnus-article-insert-newline)
3013 (mm-insert-inline handle (mm-get-part handle))
3014 (goto-char (point-max))))
3018 (narrow-to-region beg (point))
3020 nil (length gnus-article-mime-handle-alist)
3021 (1- (length gnus-article-mime-handles))
3022 (car (mm-handle-type handle))))))))))
3024 (defun gnus-unbuttonized-mime-type-p (type)
3025 "Say whether TYPE is to be unbuttonized."
3026 (unless gnus-inhibit-mime-unbuttonizing
3028 (let ((types gnus-unbuttonized-mime-types))
3030 (when (string-match (pop types) type)
3031 (throw 'found t)))))))
3033 (defun gnus-article-insert-newline ()
3034 "Insert a newline, but mark it as undeletable."
3035 (gnus-put-text-property
3036 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3038 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3039 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3042 handle buffer-read-only from props begend not-pref)
3043 (save-window-excursion
3046 (narrow-to-region (car ibegend)
3049 (goto-char (car ibegend))
3052 (delete-region (point-min) (point-max))
3053 (mm-remove-parts handles))
3054 (setq begend (list (point-marker)))
3056 (unless (setq not-pref (cadr (member preferred ihandles)))
3057 (setq not-pref (car ihandles)))
3059 (not (gnus-unbuttonized-mime-type-p
3060 "multipart/alternative")))
3061 (gnus-add-text-properties
3064 (insert (format "%d. " id))
3068 (unless ,(not ibegend)
3069 (setq gnus-article-mime-handle-alist
3070 ',gnus-article-mime-handle-alist))
3071 (gnus-mime-display-alternative
3072 ',ihandles ',not-pref ',begend ,id))
3073 local-map ,gnus-mime-button-map
3074 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3075 face ,gnus-article-button-face
3076 keymap ,gnus-mime-button-map
3079 (widget-convert-button 'link from (point)
3080 :action 'gnus-widget-press-button
3081 :button-keymap gnus-widget-button-keymap)
3083 (while (setq handle (pop handles))
3084 (gnus-add-text-properties
3087 (insert (format "(%c) %-18s"
3088 (if (equal handle preferred) ?* ? )
3089 (if (stringp (car handle))
3091 (car (mm-handle-type handle)))))
3095 (unless ,(not ibegend)
3096 (setq gnus-article-mime-handle-alist
3097 ',gnus-article-mime-handle-alist))
3098 (gnus-mime-display-alternative
3099 ',ihandles ',handle ',begend ,id))
3100 local-map ,gnus-mime-button-map
3101 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3102 face ,gnus-article-button-face
3103 keymap ,gnus-mime-button-map
3106 (widget-convert-button 'link from (point)
3107 :action 'gnus-widget-press-button
3108 :button-keymap gnus-widget-button-keymap)
3112 (if (stringp (car preferred))
3113 (gnus-display-mime preferred)
3114 (let ((mail-parse-charset gnus-newsgroup-charset))
3115 (mm-display-part preferred)))
3116 (goto-char (point-max))
3117 (setcdr begend (point-marker)))))
3119 (goto-char point))))
3121 (defun gnus-article-wash-status ()
3122 "Return a string which display status of article washing."
3124 (set-buffer gnus-article-buffer)
3125 (let ((cite (gnus-article-hidden-text-p 'cite))
3126 (headers (gnus-article-hidden-text-p 'headers))
3127 (boring (gnus-article-hidden-text-p 'boring-headers))
3128 (pgp (gnus-article-hidden-text-p 'pgp))
3129 (pem (gnus-article-hidden-text-p 'pem))
3130 (signature (gnus-article-hidden-text-p 'signature))
3131 (overstrike (gnus-article-hidden-text-p 'overstrike))
3132 (emphasis (gnus-article-hidden-text-p 'emphasis))
3133 (mime gnus-show-mime))
3134 (format "%c%c%c%c%c%c%c"
3136 (if (or headers boring) ?h ? )
3137 (if (or pgp pem) ?p ? )
3138 (if signature ?s ? )
3139 (if overstrike ?o ? )
3141 (if emphasis ?e ? )))))
3143 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3145 (defun gnus-article-maybe-hide-headers ()
3146 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3147 Provided for backwards compatibility."
3148 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3149 (not (save-excursion (set-buffer gnus-summary-buffer)
3150 gnus-have-all-headers)))
3151 (not gnus-inhibit-hiding))
3152 (gnus-article-hide-headers)))
3156 (defun gnus-output-to-file (file-name)
3157 "Append the current article to a file named FILE-NAME."
3158 (let ((artbuf (current-buffer)))
3160 (insert-buffer-substring artbuf)
3161 ;; Append newline at end of the buffer as separator, and then
3163 (goto-char (point-max))
3165 (append-to-file (point-min) (point-max) file-name)
3168 (defun gnus-narrow-to-page (&optional arg)
3169 "Narrow the article buffer to a page.
3170 If given a numerical ARG, move forward ARG pages."
3172 (setq arg (if arg (prefix-numeric-value arg) 0))
3174 (set-buffer gnus-article-buffer)
3175 (goto-char (point-min))
3177 ;; Remove any old next/prev buttons.
3178 (when (gnus-visual-p 'page-marker)
3179 (let ((buffer-read-only nil))
3180 (gnus-remove-text-with-property 'gnus-prev)
3181 (gnus-remove-text-with-property 'gnus-next)))
3184 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3186 (re-search-forward page-delimiter nil 'move arg)))
3187 (goto-char (match-end 0)))
3190 (if (re-search-forward page-delimiter nil 'move)
3193 (when (and (gnus-visual-p 'page-marker)
3194 (not (= (point-min) 1)))
3196 (goto-char (point-min))
3197 (gnus-insert-prev-page-button)))
3198 (when (and (gnus-visual-p 'page-marker)
3199 (< (+ (point-max) 2) (buffer-size)))
3201 (goto-char (point-max))
3202 (gnus-insert-next-page-button)))))
3204 ;; Article mode commands
3206 (defun gnus-article-goto-next-page ()
3207 "Show the next page of the article."
3209 (when (gnus-article-next-page)
3210 (goto-char (point-min))
3211 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3213 (defun gnus-article-goto-prev-page ()
3214 "Show the next page of the article."
3216 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3217 (gnus-article-prev-page nil)))
3219 (defun gnus-article-next-page (&optional lines)
3220 "Show the next page of the current article.
3221 If end of article, return non-nil. Otherwise return nil.
3222 Argument LINES specifies lines to be scrolled up."
3224 (move-to-window-line -1)
3227 (and (pos-visible-in-window-p) ;Not continuation line.
3229 ;; Nothing in this page.
3230 (if (or (not gnus-page-broken)
3233 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3235 (gnus-narrow-to-page 1) ;Go to next page.
3237 ;; More in this page.
3238 (let ((scroll-in-place nil))
3242 ;; Long lines may cause an end-of-buffer error.
3243 (goto-char (point-max)))))
3244 (move-to-window-line 0)
3247 (defun gnus-article-prev-page (&optional lines)
3248 "Show previous page of current article.
3249 Argument LINES specifies lines to be scrolled down."
3251 (move-to-window-line 0)
3252 (if (and gnus-page-broken
3254 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3256 (gnus-narrow-to-page -1) ;Go to previous page.
3257 (goto-char (point-max))
3259 (let ((scroll-in-place nil))
3263 (beginning-of-buffer
3264 (goto-char (point-min))))
3265 (move-to-window-line 0)))))
3267 (defun gnus-article-refer-article ()
3268 "Read article specified by message-id around point."
3270 (let ((point (point)))
3271 (search-forward ">" nil t) ;Move point to end of "<....>".
3272 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3273 (let ((message-id (match-string 1)))
3275 (set-buffer gnus-summary-buffer)
3276 (gnus-summary-refer-article message-id))
3278 (error "No references around point"))))
3280 (defun gnus-article-show-summary ()
3281 "Reconfigure windows to show summary buffer."
3283 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3284 (error "There is no summary buffer for this article buffer")
3285 (gnus-article-set-globals)
3286 (gnus-configure-windows 'article)
3287 (gnus-summary-goto-subject gnus-current-article)
3288 (gnus-summary-position-point)))
3290 (defun gnus-article-describe-briefly ()
3291 "Describe article mode commands briefly."
3293 (gnus-message 6 (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")))
3295 (defun gnus-article-summary-command ()
3296 "Execute the last keystroke in the summary buffer."
3298 (let ((obuf (current-buffer))
3299 (owin (current-window-configuration))
3301 (switch-to-buffer gnus-article-current-summary 'norecord)
3302 (setq func (lookup-key (current-local-map) (this-command-keys)))
3303 (call-interactively func)
3305 (set-window-configuration owin)
3306 (set-window-point (get-buffer-window (current-buffer)) (point))))
3308 (defun gnus-article-summary-command-nosave ()
3309 "Execute the last keystroke in the summary buffer."
3312 (pop-to-buffer gnus-article-current-summary 'norecord)
3313 (setq func (lookup-key (current-local-map) (this-command-keys)))
3314 (call-interactively func)))
3316 (defun gnus-article-check-buffer ()
3317 "Beep if not in an article buffer."
3318 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3319 (error "Command invoked outside of a Gnus article buffer")))
3321 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3322 "Read a summary buffer key sequence and execute it from the article buffer."
3324 (gnus-article-check-buffer)
3326 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3327 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3328 "=" "^" "\M-^" "|"))
3334 '("n" "Gn" "p" "Gp"))
3337 (set-buffer gnus-article-current-summary)
3338 (let (gnus-pick-mode)
3339 (push (or key last-command-event) unread-command-events)
3340 (setq keys (read-key-sequence nil))))
3343 (if (or (member keys nosaves)
3344 (member keys nosave-but-article)
3345 (member keys nosave-in-article))
3347 (save-window-excursion
3348 (pop-to-buffer gnus-article-current-summary 'norecord)
3349 ;; We disable the pick minor mode commands.
3350 (let (gnus-pick-mode)
3351 (setq func (lookup-key (current-local-map) keys))))
3354 (unless (member keys nosave-in-article)
3355 (set-buffer gnus-article-current-summary))
3356 (call-interactively func)
3357 (setq new-sum-point (point)))
3358 (when (member keys nosave-but-article)
3359 (pop-to-buffer gnus-article-buffer 'norecord)))
3360 ;; These commands should restore window configuration.
3361 (let ((obuf (current-buffer))
3362 (owin (current-window-configuration))
3364 (summary gnus-article-current-summary)
3365 func in-buffer selected)
3366 (if not-restore-window
3367 (pop-to-buffer summary 'norecord)
3368 (switch-to-buffer summary 'norecord))
3369 (setq in-buffer (current-buffer))
3370 ;; We disable the pick minor mode commands.
3371 (if (setq func (let (gnus-pick-mode)
3372 (lookup-key (current-local-map) keys)))
3374 (call-interactively func)
3375 (setq new-sum-point (point)))
3377 (when (eq in-buffer (current-buffer))
3378 (setq selected (gnus-summary-select-article))
3380 (unless not-restore-window
3381 (set-window-configuration owin))
3382 (unless (or (not (eq selected 'old)) (member keys up-to-top))
3383 (set-window-point (get-buffer-window (current-buffer))
3385 (let ((win (get-buffer-window gnus-article-current-summary)))
3387 (set-window-point win new-sum-point))))))))
3389 (defun gnus-article-hide (&optional arg force)
3390 "Hide all the gruft in the current article.
3391 This means that PGP stuff, signatures, cited text and (some)
3392 headers will be hidden.
3393 If given a prefix, show the hidden text instead."
3394 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3395 (gnus-article-hide-headers arg)
3396 (gnus-article-hide-pgp arg)
3397 (gnus-article-hide-citation-maybe arg force)
3398 (gnus-article-hide-signature arg))
3400 (defun gnus-article-maybe-highlight ()
3401 "Do some article highlighting if article highlighting is requested."
3402 (when (gnus-visual-p 'article-highlight 'highlight)
3403 (gnus-article-highlight-some)))
3405 (defun gnus-check-group-server ()
3406 ;; Make sure the connection to the server is alive.
3407 (unless (gnus-server-opened
3408 (gnus-find-method-for-group gnus-newsgroup-name))
3409 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3410 (gnus-request-group gnus-newsgroup-name t)))
3412 (defun gnus-request-article-this-buffer (article group)
3413 "Get an article and insert it into this buffer."
3414 (let (do-update-line sparse-header)
3418 (gnus-kill-all-overlays)
3419 (setq group (or group gnus-newsgroup-name))
3421 ;; Using `gnus-request-article' directly will insert the article into
3422 ;; `nntp-server-buffer' - so we'll save some time by not having to
3423 ;; copy it from the server buffer into the article buffer.
3425 ;; We only request an article by message-id when we do not have the
3426 ;; headers for it, so we'll have to get those.
3427 (when (stringp article)
3428 (let ((gnus-override-method gnus-refer-article-method))
3429 (gnus-read-header article)))
3431 ;; If the article number is negative, that means that this article
3432 ;; doesn't belong in this newsgroup (possibly), so we find its
3433 ;; message-id and request it by id instead of number.
3434 (when (and (numberp article)
3436 (get-buffer gnus-summary-buffer)
3437 (gnus-buffer-exists-p gnus-summary-buffer))
3439 (set-buffer gnus-summary-buffer)
3440 (let ((header (gnus-summary-article-header article)))
3443 ((memq article gnus-newsgroup-sparse)
3444 ;; This is a sparse gap article.
3445 (setq do-update-line article)
3446 (setq article (mail-header-id header))
3447 (let ((gnus-override-method gnus-refer-article-method))
3448 (setq sparse-header (gnus-read-header article)))
3449 (setq gnus-newsgroup-sparse
3450 (delq article gnus-newsgroup-sparse)))
3452 ;; It's a real article.
3453 (setq article (mail-header-id header)))
3455 ;; It is an extracted pseudo-article.
3456 (setq article 'pseudo)
3457 (gnus-request-pseudo-article header))))
3459 (let ((method (gnus-find-method-for-group
3460 gnus-newsgroup-name)))
3461 (when (and (eq (car method) 'nneething)
3464 (file-name-as-directory
3465 (or (cadr (assq 'nneething-address method))
3467 (mail-header-subject header))))
3468 (when (file-directory-p dir)
3469 (setq article 'nneething)
3470 (gnus-group-enter-directory dir))))))))
3473 ;; Refuse to select canceled articles.
3474 ((and (numberp article)
3476 (get-buffer gnus-summary-buffer)
3477 (gnus-buffer-exists-p gnus-summary-buffer)
3478 (eq (cdr (save-excursion
3479 (set-buffer gnus-summary-buffer)
3480 (assq article gnus-newsgroup-reads)))
3481 gnus-canceled-mark))
3483 ;; Check the backlog.
3484 ((and gnus-keep-backlog
3485 (gnus-backlog-request-article group article (current-buffer)))
3487 ;; Check asynchronous pre-fetch.
3488 ((gnus-async-request-fetched-article group article (current-buffer))
3489 (gnus-async-prefetch-next group article gnus-summary-buffer)
3490 (when (and (numberp article) gnus-keep-backlog)
3491 (gnus-backlog-enter-article group article (current-buffer)))
3494 ((and gnus-use-cache
3496 (gnus-cache-request-article article group))
3498 ;; Get the article and put into the article buffer.
3499 ((or (stringp article) (numberp article))
3500 (let ((gnus-override-method
3501 (and (stringp article) gnus-refer-article-method))
3502 (buffer-read-only nil))
3504 (gnus-kill-all-overlays)
3505 (gnus-check-group-server)
3506 (when (gnus-request-article article group (current-buffer))
3507 (when (numberp article)
3508 (gnus-async-prefetch-next group article gnus-summary-buffer)
3509 (when gnus-keep-backlog
3510 (gnus-backlog-enter-article
3511 group article (current-buffer))))
3516 ;; Associate this article with the current summary buffer.
3517 (setq gnus-article-current-summary gnus-summary-buffer)
3519 ;; Take the article from the original article buffer
3520 ;; and place it in the buffer it's supposed to be in.
3521 (when (and (get-buffer gnus-article-buffer)
3522 (equal (buffer-name (current-buffer))
3523 (buffer-name (get-buffer gnus-article-buffer))))
3525 (if (get-buffer gnus-original-article-buffer)
3526 (set-buffer gnus-original-article-buffer)
3527 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3528 (buffer-disable-undo)
3529 (setq major-mode 'gnus-original-article-mode)
3530 (setq buffer-read-only t))
3531 (let (buffer-read-only)
3533 (insert-buffer-substring gnus-article-buffer))
3534 (setq gnus-original-article (cons group article)))
3537 (run-hooks 'gnus-article-decode-hook)
3538 ;; Mark article as decoded or not.
3539 (setq gnus-article-decoded-p gnus-article-decode-hook))
3541 ;; Update sparse articles.
3542 (when (and do-update-line
3543 (or (numberp article)
3545 (let ((buf (current-buffer)))
3546 (set-buffer gnus-summary-buffer)
3547 (gnus-summary-update-article do-update-line sparse-header)
3548 (gnus-summary-goto-subject do-update-line nil t)
3549 (set-window-point (get-buffer-window (current-buffer) t)
3551 (set-buffer buf))))))
3557 (defcustom gnus-article-edit-mode-hook nil
3558 "Hook run in article edit mode buffers."
3559 :group 'gnus-article-various
3562 (defcustom gnus-article-edit-article-setup-function
3563 'gnus-article-mime-edit-article-setup
3564 "Function called to setup an editing article buffer."
3565 :group 'gnus-article-various
3568 (defvar gnus-article-edit-done-function nil)
3570 (defvar gnus-article-edit-mode-map nil)
3572 ;; Should we be using derived.el for this?
3573 (unless gnus-article-edit-mode-map
3574 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3575 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3577 (gnus-define-keys gnus-article-edit-mode-map
3578 "\C-c\C-c" gnus-article-edit-done
3579 "\C-c\C-k" gnus-article-edit-exit)
3581 (gnus-define-keys (gnus-article-edit-wash-map
3582 "\C-c\C-w" gnus-article-edit-mode-map)
3583 "f" gnus-article-edit-full-stops))
3585 (defun gnus-article-edit-mode ()
3586 "Major mode for editing articles.
3587 This is an extended text-mode.
3589 \\{gnus-article-edit-mode-map}"
3591 (setq major-mode 'gnus-article-edit-mode)
3592 (setq mode-name "Article Edit")
3593 (use-local-map gnus-article-edit-mode-map)
3594 (make-local-variable 'gnus-article-edit-done-function)
3595 (make-local-variable 'gnus-prev-winconf)
3596 (setq buffer-read-only nil)
3597 (buffer-enable-undo)
3599 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3601 (defun gnus-article-edit (&optional force)
3602 "Edit the current article.
3603 This will have permanent effect only in mail groups.
3604 If FORCE is non-nil, allow editing of articles even in read-only
3607 (when (and (not force)
3608 (gnus-group-read-only-p))
3609 (error "The current newsgroup does not support article editing"))
3610 (gnus-article-date-original)
3611 (gnus-article-edit-article
3612 `(lambda (no-highlight)
3613 (gnus-summary-edit-article-done
3614 ,(or (mail-header-references gnus-current-headers) "")
3615 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3617 (defun gnus-article-edit-article (exit-func)
3618 "Start editing the contents of the current article buffer."
3619 (let ((winconf (current-window-configuration)))
3620 (set-buffer gnus-article-buffer)
3621 (gnus-article-edit-mode)
3622 (gnus-article-delete-text-of-type 'annotation)
3623 (gnus-set-text-properties (point-min) (point-max) nil)
3624 (gnus-configure-windows 'edit-article)
3625 (setq gnus-article-edit-done-function exit-func)
3626 (setq gnus-prev-winconf winconf)
3627 (when gnus-article-edit-article-setup-function
3628 (funcall gnus-article-edit-article-setup-function))
3629 (gnus-message 6 "C-c C-c to end edits")))
3631 (defun gnus-article-edit-done (&optional arg)
3632 "Update the article edits and exit."
3637 (when (article-goto-body)
3638 (let ((lines (count-lines (point) (point-max)))
3639 (length (- (point-max) (point)))
3640 (case-fold-search t)
3641 (body (copy-marker (point))))
3642 (goto-char (point-min))
3643 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3644 (delete-region (match-beginning 1) (match-end 1))
3645 (insert (number-to-string length)))
3646 (goto-char (point-min))
3647 (when (re-search-forward
3648 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3649 (delete-region (match-beginning 1) (match-end 1))
3650 (insert (number-to-string length)))
3651 (goto-char (point-min))
3652 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3653 (delete-region (match-beginning 1) (match-end 1))
3654 (insert (number-to-string lines)))))))
3655 (let ((func gnus-article-edit-done-function)
3656 (buf (current-buffer))
3657 (start (window-start)))
3658 (remove-hook 'gnus-article-mode-hook
3659 'gnus-article-mime-edit-article-unwind)
3660 (gnus-article-edit-exit)
3663 (let ((buffer-read-only nil))
3665 ;; The cache and backlog have to be flushed somewhat.
3666 (when gnus-keep-backlog
3667 (gnus-backlog-remove-article
3668 (car gnus-article-current) (cdr gnus-article-current)))
3669 ;; Flush original article as well.
3671 (when (get-buffer gnus-original-article-buffer)
3672 (set-buffer gnus-original-article-buffer)
3673 (setq gnus-original-article nil)))
3674 (when gnus-use-cache
3675 (gnus-cache-update-article
3676 (car gnus-article-current) (cdr gnus-article-current))))
3678 (set-window-start (get-buffer-window buf) start)
3679 (set-window-point (get-buffer-window buf) (point))))
3681 (defun gnus-article-edit-exit ()
3682 "Exit the article editing without updating."
3684 ;; We remove all text props from the article buffer.
3685 (let ((buf (format "%s" (buffer-string)))
3686 (curbuf (current-buffer))
3688 (window-start (window-start)))
3691 (let ((winconf gnus-prev-winconf))
3693 (set-window-configuration winconf)
3694 ;; Tippy-toe some to make sure that point remains where it was.
3695 (save-current-buffer
3697 (set-window-start (get-buffer-window (current-buffer)) window-start)
3700 (defun gnus-article-edit-full-stops ()
3701 "Interactively repair spacing at end of sentences."
3704 (goto-char (point-min))
3705 (search-forward-regexp "^$" nil t)
3706 (let ((case-fold-search nil))
3707 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3710 ;;; Article editing with MIME-Edit
3713 (defcustom gnus-article-mime-edit-article-setup-hook nil
3714 "Hook run after setting up a MIME editing article buffer."
3715 :group 'gnus-article-various
3718 (defun gnus-article-mime-edit-article-unwind ()
3719 "Unwind `gnus-article-buffer' if article editing was given up."
3720 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3721 (when mime-edit-mode-flag
3722 (mime-edit-exit 'nomime 'no-error)
3724 (when (featurep 'font-lock)
3725 (setq font-lock-defaults nil)
3726 (font-lock-mode 0)))
3728 (defun gnus-article-mime-edit-article-setup ()
3729 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
3730 after replacing with the original article."
3731 (setq gnus-show-mime t)
3732 (setq gnus-article-edit-done-function
3733 `(lambda (&rest args)
3734 (when mime-edit-mode-flag
3737 (goto-char (point-min))
3738 (let (case-fold-search)
3739 (when (re-search-forward
3740 (format "^%s$" (regexp-quote mail-header-separator))
3742 (replace-match "")))
3743 (when (featurep 'font-lock)
3744 (setq font-lock-defaults nil)
3746 (apply ,gnus-article-edit-done-function args)
3747 (set-buffer gnus-original-article-buffer)
3749 (insert-buffer gnus-article-buffer)
3750 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3751 (gnus-article-prepare-display)))
3752 (substitute-key-definition
3753 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
3754 gnus-article-edit-mode-map)
3756 (insert-buffer gnus-original-article-buffer)
3758 (when (featurep 'font-lock)
3759 (set (make-local-variable 'font-lock-defaults)
3760 '(message-font-lock-keywords t))
3761 (font-lock-set-defaults)
3762 (turn-on-font-lock))
3763 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3764 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
3766 (defun gnus-article-mime-edit-exit ()
3767 "Exit the article MIME editing without updating."
3769 (let ((winconf gnus-prev-winconf)
3771 (when mime-edit-mode-flag
3774 (goto-char (point-min))
3775 (let (case-fold-search)
3776 (when (re-search-forward
3777 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
3778 (replace-match "")))
3779 (when (featurep 'font-lock)
3780 (setq font-lock-defaults nil)
3782 ;; We remove all text props from the article buffer.
3783 (setq buf (format "%s" (buffer-string)))
3784 (set-buffer (get-buffer-create gnus-original-article-buffer))
3787 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3788 (gnus-article-prepare-display)
3789 (set-window-configuration winconf)))
3792 ;;; Article highlights
3795 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3797 ;;; Internal Variables:
3799 (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\\)"
3800 "Regular expression that matches URLs."
3801 :group 'gnus-article-buttons
3804 (defcustom gnus-button-alist
3805 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3806 0 t gnus-button-message-id 2)
3807 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3808 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3810 gnus-button-fetch-group 4)
3811 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3812 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3813 t gnus-button-message-id 3)
3814 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3815 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3816 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3817 ;; This is how URLs _should_ be embedded in text...
3818 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3820 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3821 "*Alist of regexps matching buttons in article bodies.
3823 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3824 REGEXP: is the string matching text around the button,
3825 BUTTON: is the number of the regexp grouping actually matching the button,
3826 FORM: is a lisp expression which must eval to true for the button to
3828 CALLBACK: is the function to call when the user push this button, and each
3829 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3831 CALLBACK can also be a variable, in that case the value of that
3832 variable it the real callback function."
3833 :group 'gnus-article-buttons
3834 :type '(repeat (list regexp
3835 (integer :tag "Button")
3837 (function :tag "Callback")
3840 (integer :tag "Regexp group")))))
3842 (defcustom gnus-header-button-alist
3843 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3844 0 t gnus-button-message-id 0)
3845 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3846 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3847 0 t gnus-button-mailto 0)
3848 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3849 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3850 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3851 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3852 gnus-button-message-id 3))
3853 "*Alist of headers and regexps to match buttons in article heads.
3855 This alist is very similar to `gnus-button-alist', except that each
3856 alist has an additional HEADER element first in each entry:
3858 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3860 HEADER is a regexp to match a header. For a fuller explanation, see
3861 `gnus-button-alist'."
3862 :group 'gnus-article-buttons
3863 :group 'gnus-article-headers
3864 :type '(repeat (list (regexp :tag "Header")
3866 (integer :tag "Button")
3868 (function :tag "Callback")
3871 (integer :tag "Regexp group")))))
3873 (defvar gnus-button-regexp nil)
3874 (defvar gnus-button-marker-list nil)
3875 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3877 (defvar gnus-button-last nil)
3878 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3882 (defun gnus-article-push-button (event)
3883 "Check text under the mouse pointer for a callback function.
3884 If the text under the mouse pointer has a `gnus-callback' property,
3885 call it with the value of the `gnus-data' text property."
3887 (set-buffer (window-buffer (posn-window (event-start event))))
3888 (let* ((pos (posn-point (event-start event)))
3889 (data (get-text-property pos 'gnus-data))
3890 (fun (get-text-property pos 'gnus-callback)))
3893 (funcall fun data))))
3895 (defun gnus-article-press-button ()
3896 "Check text at point for a callback function.
3897 If the text at point has a `gnus-callback' property,
3898 call it with the value of the `gnus-data' text property."
3900 (let* ((data (get-text-property (point) 'gnus-data))
3901 (fun (get-text-property (point) 'gnus-callback)))
3903 (funcall fun data))))
3905 (defun gnus-article-prev-button (n)
3906 "Move point to N buttons backward.
3907 If N is negative, move forward instead."
3909 (gnus-article-next-button (- n)))
3911 (defun gnus-article-next-button (n)
3912 "Move point to N buttons forward.
3913 If N is negative, move backward instead."
3915 (let ((function (if (< n 0) 'previous-single-property-change
3916 'next-single-property-change))
3917 (inhibit-point-motion-hooks t)
3919 (limit (if (< n 0) (point-min) (point-max))))
3921 (while (and (not (= limit (point)))
3923 ;; Skip past the current button.
3924 (when (get-text-property (point) 'gnus-callback)
3925 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3926 ;; Go to the next (or previous) button.
3927 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
3928 ;; Put point at the start of the button.
3929 (when (and backward (not (get-text-property (point) 'gnus-callback)))
3930 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3931 ;; Skip past intangible buttons.
3932 (when (get-text-property (point) 'intangible)
3936 (gnus-message 5 "No more buttons"))
3939 (defun gnus-article-highlight (&optional force)
3940 "Highlight current article.
3941 This function calls `gnus-article-highlight-headers',
3942 `gnus-article-highlight-citation',
3943 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3944 do the highlighting. See the documentation for those functions."
3945 (interactive (list 'force))
3946 (gnus-article-highlight-headers)
3947 (gnus-article-highlight-citation force)
3948 (gnus-article-highlight-signature)
3949 (gnus-article-add-buttons force)
3950 (gnus-article-add-buttons-to-head))
3952 (defun gnus-article-highlight-some (&optional force)
3953 "Highlight current article.
3954 This function calls `gnus-article-highlight-headers',
3955 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3956 do the highlighting. See the documentation for those functions."
3957 (interactive (list 'force))
3958 (gnus-article-highlight-headers)
3959 (gnus-article-highlight-signature)
3960 (gnus-article-add-buttons))
3962 (defun gnus-article-highlight-headers ()
3963 "Highlight article headers as specified by `gnus-header-face-alist'."
3966 (set-buffer gnus-article-buffer)
3968 (let ((alist gnus-header-face-alist)
3969 (buffer-read-only nil)
3970 (case-fold-search t)
3971 (inhibit-point-motion-hooks t)
3972 entry regexp header-face field-face from hpoints fpoints)
3973 (message-narrow-to-head)
3974 (while (setq entry (pop alist))
3975 (goto-char (point-min))
3976 (setq regexp (concat "^\\("
3977 (if (string-equal "" (nth 0 entry))
3981 header-face (nth 1 entry)
3982 field-face (nth 2 entry))
3983 (while (and (re-search-forward regexp nil t)
3987 (unless (search-forward ":" nil t)
3989 (when (and header-face
3990 (not (memq (point) hpoints)))
3991 (push (point) hpoints)
3992 (gnus-put-text-property from (point) 'face header-face))
3993 (when (and field-face
3994 (not (memq (setq from (point)) fpoints)))
3996 (if (re-search-forward "^[^ \t]" nil t)
3998 (goto-char (point-max)))
3999 (gnus-put-text-property from (point) 'face field-face))))))))
4001 (defun gnus-article-highlight-signature ()
4002 "Highlight the signature in an article.
4003 It does this by highlighting everything after
4004 `gnus-signature-separator' using `gnus-signature-face'."
4007 (set-buffer gnus-article-buffer)
4008 (let ((buffer-read-only nil)
4009 (inhibit-point-motion-hooks t))
4011 (when (and gnus-signature-face
4012 (gnus-article-narrow-to-signature))
4013 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4014 'face gnus-signature-face)
4016 (gnus-article-search-signature)
4017 (let ((start (match-beginning 0))
4018 (end (set-marker (make-marker) (1+ (match-end 0)))))
4019 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4022 (defun gnus-button-in-region-p (b e prop)
4023 "Say whether PROP exists in the region."
4024 (text-property-not-all b e prop nil))
4026 (defun gnus-article-add-buttons (&optional force)
4027 "Find external references in the article and make buttons of them.
4028 \"External references\" are things like Message-IDs and URLs, as
4029 specified by `gnus-button-alist'."
4030 (interactive (list 'force))
4032 (set-buffer gnus-article-buffer)
4033 (let ((buffer-read-only nil)
4034 (inhibit-point-motion-hooks t)
4035 (case-fold-search t)
4036 (alist gnus-button-alist)
4038 ;; Remove all old markers.
4040 (while (setq marker (pop gnus-button-marker-list))
4042 (when (setq entry (gnus-button-entry))
4043 (put-text-property (match-beginning (nth 1 entry))
4044 (match-end (nth 1 entry))
4045 'gnus-callback nil))
4046 (set-marker marker nil)))
4047 ;; We skip the headers.
4050 (while (setq entry (pop alist))
4051 (setq regexp (car entry))
4053 (while (re-search-forward regexp nil t)
4054 (let* ((start (and entry (match-beginning (nth 1 entry))))
4055 (end (and entry (match-end (nth 1 entry))))
4056 (from (match-beginning 0)))
4057 (when (and (or (eq t (nth 2 entry))
4058 (eval (nth 2 entry)))
4059 (not (gnus-button-in-region-p
4060 start end 'gnus-callback)))
4061 ;; That optional form returned non-nil, so we add the
4063 (gnus-article-add-button
4064 start end 'gnus-button-push
4065 (car (push (set-marker (make-marker) from)
4066 gnus-button-marker-list))))))))))
4068 ;; Add buttons to the head of an article.
4069 (defun gnus-article-add-buttons-to-head ()
4070 "Add buttons to the head of the article."
4073 (set-buffer gnus-article-buffer)
4074 (let ((buffer-read-only nil)
4075 (inhibit-point-motion-hooks t)
4076 (case-fold-search t)
4077 (alist gnus-header-button-alist)
4079 (nnheader-narrow-to-headers)
4081 ;; Each alist entry.
4082 (setq entry (car alist)
4084 (goto-char (point-min))
4085 (while (re-search-forward (car entry) nil t)
4086 ;; Each header matching the entry.
4087 (setq beg (match-beginning 0))
4088 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4089 (match-beginning 0))
4092 (while (re-search-forward (nth 1 entry) end t)
4093 ;; Each match within a header.
4094 (let* ((entry (cdr entry))
4095 (start (match-beginning (nth 1 entry)))
4096 (end (match-end (nth 1 entry)))
4097 (form (nth 2 entry)))
4098 (goto-char (match-end 0))
4100 (gnus-article-add-button
4101 start end (nth 3 entry)
4102 (buffer-substring (match-beginning (nth 4 entry))
4103 (match-end (nth 4 entry)))))))
4107 ;;; External functions:
4109 (defun gnus-article-add-button (from to fun &optional data)
4110 "Create a button between FROM and TO with callback FUN and data DATA."
4111 (when gnus-article-button-face
4112 (gnus-overlay-put (gnus-make-overlay from to)
4113 'face gnus-article-button-face))
4114 (gnus-add-text-properties
4116 (nconc (and gnus-article-mouse-face
4117 (list gnus-mouse-face-prop gnus-article-mouse-face))
4118 (list 'gnus-callback fun)
4119 (and data (list 'gnus-data data)))))
4121 ;;; Internal functions:
4123 (defun gnus-article-set-globals ()
4125 (set-buffer gnus-summary-buffer)
4126 (gnus-set-global-variables)))
4128 (defun gnus-signature-toggle (end)
4130 (set-buffer gnus-article-buffer)
4131 (let ((buffer-read-only nil)
4132 (inhibit-point-motion-hooks t))
4133 (if (get-text-property end 'invisible)
4134 (gnus-article-unhide-text end (point-max))
4135 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4137 (defun gnus-button-entry ()
4138 ;; Return the first entry in `gnus-button-alist' matching this place.
4139 (let ((alist gnus-button-alist)
4142 (setq entry (pop alist))
4143 (if (looking-at (car entry))
4148 (defun gnus-button-push (marker)
4149 ;; Push button starting at MARKER.
4152 (let* ((entry (gnus-button-entry))
4153 (inhibit-point-motion-hooks t)
4155 (args (mapcar (lambda (group)
4156 (let ((string (match-string group)))
4157 (gnus-set-text-properties
4158 0 (length string) nil string)
4165 (fboundp (symbol-value fun)))
4166 (apply (symbol-value fun) args))
4168 (gnus-message 1 "You must define `%S' to use this button"
4169 (cons fun args)))))))
4171 (defun gnus-button-message-id (message-id)
4174 (set-buffer gnus-summary-buffer)
4175 (gnus-summary-refer-article message-id)))
4177 (defun gnus-button-fetch-group (address)
4178 "Fetch GROUP specified by ADDRESS."
4179 (if (not (string-match "[:/]" address))
4180 ;; This is just a simple group url.
4181 (gnus-group-read-ephemeral-group address gnus-select-method)
4182 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4184 (error "Can't parse %s" address)
4185 (gnus-group-read-ephemeral-group
4186 (match-string 4 address)
4187 `(nntp ,(match-string 1 address)
4188 (nntp-address ,(match-string 1 address))
4189 (nntp-port-number ,(if (match-end 3)
4190 (match-string 3 address)
4193 (defun gnus-url-parse-query-string (query &optional downcase)
4194 (let (retval pairs cur key val)
4195 (setq pairs (split-string query "&"))
4197 (setq cur (car pairs)
4199 (if (not (string-match "=" cur))
4201 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4202 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4204 (setq key (downcase key)))
4205 (setq cur (assoc key retval))
4207 (setcdr cur (cons val (cdr cur)))
4208 (setq retval (cons (list key val) retval)))))
4211 (defun gnus-url-unhex (x)
4218 (defun gnus-url-unhex-string (str &optional allow-newlines)
4219 "Remove %XXX embedded spaces, etc in a url.
4220 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4221 decoding of carriage returns and line feeds in the string, which is normally
4222 forbidden in URL encoding."
4223 (setq str (or str ""))
4225 (case-fold-search t))
4226 (while (string-match "%[0-9a-f][0-9a-f]" str)
4227 (let* ((start (match-beginning 0))
4228 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4230 (gnus-url-unhex (elt str (+ start 2))))))
4232 tmp (substring str 0 start)
4235 (char-to-string code))
4236 ((or (= code ?\n) (= code ?\r))
4238 (t (char-to-string code))))
4239 str (substring str (match-end 0)))))
4240 (setq tmp (concat tmp str))
4243 (defun gnus-url-mailto (url)
4244 ;; Send mail to someone
4245 (when (string-match "mailto:/*\\(.*\\)" url)
4246 (setq url (substring url (match-beginning 1) nil)))
4247 (let (to args subject func)
4248 (if (string-match (regexp-quote "?") url)
4249 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4250 args (gnus-url-parse-query-string
4251 (substring url (match-end 0) nil) t))
4252 (setq to (gnus-url-unhex-string url)))
4253 (setq args (cons (list "to" to) args)
4254 subject (cdr-safe (assoc "subject" args)))
4255 (gnus-setup-message 'reply
4258 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4261 (message-position-on-field (caar args)))
4262 (insert (mapconcat 'identity (cdar args) ", "))
4263 (setq args (cdr args)))
4266 (message-goto-subject)))))
4268 (defun gnus-button-mailto (address)
4270 (set-buffer (gnus-copy-article-buffer))
4271 (gnus-setup-message 'reply
4272 (message-reply address)))
4274 (defun gnus-button-reply (address)
4275 ;; Reply to ADDRESS.
4276 (gnus-setup-message 'reply
4277 (message-reply address)))
4279 (defun gnus-button-url (address)
4281 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4282 (if (listp browse-url-browser-function)
4283 (browse-url address)
4284 (funcall browse-url-browser-function address)))
4286 (defun gnus-button-embedded-url (address)
4288 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4289 (if (listp browse-url-browser-function)
4290 (browse-url (gnus-strip-whitespace address))
4291 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4293 ;;; Next/prev buttons in the article buffer.
4295 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4296 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4298 (defvar gnus-prev-page-map nil)
4299 (unless gnus-prev-page-map
4300 (setq gnus-prev-page-map (make-sparse-keymap))
4301 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4302 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4304 (defun gnus-insert-prev-page-button ()
4305 (let ((buffer-read-only nil))
4307 gnus-prev-page-line-format nil
4308 `(gnus-prev t local-map ,gnus-prev-page-map
4309 gnus-callback gnus-article-button-prev-page
4310 article-type annotation))))
4312 (defvar gnus-next-page-map nil)
4313 (unless gnus-next-page-map
4314 (setq gnus-next-page-map (make-keymap))
4315 (suppress-keymap gnus-prev-page-map)
4316 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4317 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4319 (defun gnus-button-next-page ()
4320 "Go to the next page."
4322 (let ((win (selected-window)))
4323 (select-window (get-buffer-window gnus-article-buffer t))
4324 (gnus-article-next-page)
4325 (select-window win)))
4327 (defun gnus-button-prev-page ()
4328 "Go to the prev page."
4330 (let ((win (selected-window)))
4331 (select-window (get-buffer-window gnus-article-buffer t))
4332 (gnus-article-prev-page)
4333 (select-window win)))
4335 (defun gnus-insert-next-page-button ()
4336 (let ((buffer-read-only nil))
4337 (gnus-eval-format gnus-next-page-line-format nil
4339 t local-map ,gnus-next-page-map
4340 gnus-callback gnus-article-button-next-page
4341 article-type annotation))))
4343 (defun gnus-article-button-next-page (arg)
4344 "Go to the next page."
4346 (let ((win (selected-window)))
4347 (select-window (get-buffer-window gnus-article-buffer t))
4348 (gnus-article-next-page)
4349 (select-window win)))
4351 (defun gnus-article-button-prev-page (arg)
4352 "Go to the prev page."
4354 (let ((win (selected-window)))
4355 (select-window (get-buffer-window gnus-article-buffer t))
4356 (gnus-article-prev-page)
4357 (select-window win)))
4359 (defvar gnus-decode-header-methods
4360 '(mail-decode-encoded-word-region)
4361 "List of methods used to decode headers.
4363 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4364 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4365 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4366 whose names match REGEXP.
4369 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4370 mail-decode-encoded-word-region
4371 (\"chinese\" . rfc1843-decode-region))
4374 (defvar gnus-decode-header-methods-cache nil)
4376 (defun gnus-multi-decode-header (start end)
4377 "Apply the functions from `gnus-encoded-word-methods' that match."
4378 (unless (and gnus-decode-header-methods-cache
4379 (eq gnus-newsgroup-name
4380 (car gnus-decode-header-methods-cache)))
4381 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4384 (nconc gnus-decode-header-methods-cache (list x))
4385 (if (and gnus-newsgroup-name
4386 (string-match (car x) gnus-newsgroup-name))
4387 (nconc gnus-decode-header-methods-cache
4389 gnus-decode-header-methods))
4390 (let ((xlist gnus-decode-header-methods-cache))
4393 (narrow-to-region start end)
4395 (funcall (pop xlist) (point-min) (point-max))))))
4398 ;;; Treatment top-level handling.
4401 (defun gnus-treat-article (condition &optional part-number total-parts type)
4402 (let ((length (- (point-max) (point-min)))
4403 (alist gnus-treatment-function-alist)
4404 (article-goto-body-goes-to-point-min-p t)
4408 (let ((list gnus-article-treat-types))
4410 (when (string-match (pop list) type)
4411 (throw 'found t)))))))
4413 (when (gnus-visual-p 'article-highlight 'highlight)
4414 (gnus-run-hooks 'gnus-part-display-hook)
4415 (while (setq elem (pop alist))
4416 (setq val (symbol-value (car elem)))
4417 (when (and (or (consp val)
4419 (gnus-treat-predicate val))
4420 (funcall (cadr elem)))))))
4422 ;; Dynamic variables.
4423 (defvar part-number)
4424 (defvar total-parts)
4428 (defun gnus-treat-predicate (val)
4439 (eq part-number total-parts))
4443 (let ((pred (pop val)))
4446 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4448 (apply 'gnus-and (mapcar 'gnus-tread-predicate val)))
4450 (not (gnus-treat-predicate val)))
4452 (equal (cadr val) type))
4454 (error "%S is not a valid predicate" pred)))))
4456 (error "%S is not a valid value" val))))
4462 (defun gnus-article-header-presentation-method (entity situation)
4463 (mime-insert-header entity)
4466 (set-alist 'mime-header-presentation-method-alist
4467 'gnus-original-article-mode
4468 #'gnus-article-header-presentation-method)
4470 (defun gnus-mime-preview-quitting-method ()
4471 (mime-preview-kill-buffer)
4472 (delete-other-windows)
4473 (gnus-article-show-summary)
4474 (gnus-summary-select-article gnus-show-all-headers t))
4476 (set-alist 'mime-preview-quitting-method-alist
4477 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
4479 (defun gnus-following-method (buf)
4482 (message-yank-original)
4484 (goto-char (point-min))
4487 (set-alist 'mime-preview-following-method-alist
4488 'gnus-original-article-mode #'gnus-following-method)
4490 (set-alist 'mime-preview-over-to-previous-method-alist
4491 'gnus-original-article-mode
4493 (gnus-article-read-summary-keys
4494 nil (gnus-character-to-event ?P))))
4496 (set-alist 'mime-preview-over-to-next-method-alist
4497 'gnus-original-article-mode'
4499 (gnus-article-read-summary-keys
4500 nil (gnus-character-to-event ?N))))
4510 (run-hooks 'gnus-art-load-hook)
4512 ;;; gnus-art.el ends here