1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 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))
31 (eval-when-compile (require 'static))
42 ;; Avoid byte-compile warnings.
51 (defgroup gnus-article nil
53 :link '(custom-manual "(gnus)The Article Buffer")
56 (defgroup gnus-article-treat nil
57 "Treating article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-hiding nil
62 "Hiding article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-highlight nil
67 "Article highlighting."
68 :link '(custom-manual "(gnus)Article Highlighting")
72 (defgroup gnus-article-signature nil
74 :link '(custom-manual "(gnus)Article Signature")
77 (defgroup gnus-article-headers nil
79 :link '(custom-manual "(gnus)Hiding Headers")
82 (defgroup gnus-article-washing nil
83 "Special commands on articles."
84 :link '(custom-manual "(gnus)Article Washing")
87 (defgroup gnus-article-emphasis nil
88 "Fontisizing articles."
89 :link '(custom-manual "(gnus)Article Fontisizing")
92 (defgroup gnus-article-saving nil
94 :link '(custom-manual "(gnus)Saving Articles")
97 (defgroup gnus-article-mime nil
98 "Worshiping the MIME wonder."
99 :link '(custom-manual "(gnus)Using MIME")
100 :group 'gnus-article)
102 (defgroup gnus-article-buttons nil
103 "Pushable buttons in the article buffer."
104 :link '(custom-manual "(gnus)Article Buttons")
105 :group 'gnus-article)
107 (defgroup gnus-article-various nil
108 "Other article options."
109 :link '(custom-manual "(gnus)Misc Article")
110 :group 'gnus-article)
112 (defcustom gnus-ignored-headers
113 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
114 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
115 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
116 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
117 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
118 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
119 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
120 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
121 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
122 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
123 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
124 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
125 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
126 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
127 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
128 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
129 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
130 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
131 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
132 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
133 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
134 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
135 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
136 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
137 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
138 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
139 "^X-Received:" "^Content-length:" "X-precedence:")
140 "*All headers that start with this regexp will be hidden.
141 This variable can also be a list of regexps of headers to be ignored.
142 If `gnus-visible-headers' is non-nil, this variable will be ignored."
143 :type '(choice :custom-show nil
146 :group 'gnus-article-hiding)
148 (defcustom gnus-visible-headers
149 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
150 "*All headers that do not match this regexp will be hidden.
151 This variable can also be a list of regexp of headers to remain visible.
152 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
153 :type '(repeat :value-to-internal (lambda (widget value)
154 (custom-split-regexp-maybe value))
155 :match (lambda (widget value)
157 (widget-editable-list-match widget value)))
159 :group 'gnus-article-hiding)
161 (defcustom gnus-sorted-header-list
162 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
163 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
164 "*This variable is a list of regular expressions.
165 If it is non-nil, headers that match the regular expressions will
166 be placed first in the article buffer in the sequence specified by
168 :type '(repeat regexp)
169 :group 'gnus-article-hiding)
171 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
172 "Headers that are only to be displayed if they have interesting data.
173 Possible values in this list are `empty', `newsgroups', `followup-to',
174 `reply-to', `date', `long-to', and `many-to'."
175 :type '(set (const :tag "Headers with no content." empty)
176 (const :tag "Newsgroups with only one group." newsgroups)
177 (const :tag "Followup-to identical to newsgroups." followup-to)
178 (const :tag "Reply-to identical to from." reply-to)
179 (const :tag "Date less than four days old." date)
180 (const :tag "Very long To and/or Cc header." long-to)
181 (const :tag "Multiple To and/or Cc headers." many-to))
182 :group 'gnus-article-hiding)
184 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
185 "Regexp matching signature separator.
186 This can also be a list of regexps. In that case, it will be checked
187 from head to tail looking for a separator. Searches will be done from
188 the end of the buffer."
189 :type '(repeat string)
190 :group 'gnus-article-signature)
192 (defcustom gnus-signature-limit nil
193 "Provide a limit to what is considered a signature.
194 If it is a number, no signature may not be longer (in characters) than
195 that number. If it is a floating point number, no signature may be
196 longer (in lines) than that number. If it is a function, the function
197 will be called without any parameters, and if it returns nil, there is
198 no signature in the buffer. If it is a string, it will be used as a
199 regexp. If it matches, the text in question is not a signature."
200 :type '(choice (integer :value 200)
202 (function :value fun)
203 (regexp :value ".*"))
204 :group 'gnus-article-signature)
206 (defcustom gnus-hidden-properties '(invisible t intangible t)
207 "Property list to use for hiding text."
209 :group 'gnus-article-hiding)
211 ;; Fixme: This isn't the right thing for mixed graphical and and
212 ;; non-graphical frames in a session.
213 (defcustom gnus-article-x-face-command
215 ((and (fboundp 'image-type-available-p)
216 (module-installed-p 'x-face-e21))
217 'x-face-decode-message-header)
218 ((and (fboundp 'image-type-available-p)
219 (image-type-available-p 'xbm))
220 'gnus-article-display-xface)
221 ((and (not (featurep 'xemacs))
223 (module-installed-p 'x-face-mule))
224 'x-face-mule-gnus-article-display-x-face)
226 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"))
227 "*String or function to be executed to display an X-Face header.
228 If it is a string, the command will be executed in a sub-shell
229 asynchronously. The compressed face will be piped to this command."
230 :type '(choice string
232 :tag "x-face-decode-message-header (x-face-e21)"
233 x-face-decode-message-header)
234 (function-item gnus-article-display-xface)
235 (function-item x-face-mule-gnus-article-display-x-face)
237 :group 'gnus-article-washing)
239 (defcustom gnus-article-x-face-too-ugly nil
240 "Regexp matching posters whose face shouldn't be shown automatically."
241 :type '(choice regexp (const nil))
242 :group 'gnus-article-washing)
244 (defcustom gnus-article-banner-alist nil
245 "Banner alist for stripping.
247 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
248 :type '(repeat (cons symbol regexp))
249 :group 'gnus-article-washing)
251 (defcustom gnus-emphasis-alist
253 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
255 '(("_" "_" underline)
258 ("_/" "/_" underline-italic)
259 ("_\\*" "\\*_" underline-bold)
260 ("\\*/" "/\\*" bold-italic)
261 ("_\\*/" "/\\*_" underline-bold-italic))))
262 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
263 2 3 gnus-emphasis-underline)
267 (format format (car spec) (car (cdr spec)))
268 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
270 "*Alist that says how to fontify certain phrases.
271 Each item looks like this:
273 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
275 The first element is a regular expression to be matched. The second
276 is a number that says what regular expression grouping used to find
277 the entire emphasized word. The third is a number that says what
278 regexp grouping should be displayed and highlighted. The fourth
279 is the face used for highlighting."
280 :type '(repeat (list :value ("" 0 0 default)
282 (integer :tag "Match group")
283 (integer :tag "Emphasize group")
285 :group 'gnus-article-emphasis)
287 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
288 "A regexp to describe whitespace which should not be emphasized.
289 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
290 The former avoids underlining of leading and trailing whitespace,
291 and the latter avoids underlining any whitespace at all."
292 :group 'gnus-article-emphasis
295 (defface gnus-emphasis-bold '((t (:bold t)))
296 "Face used for displaying strong emphasized text (*word*)."
297 :group 'gnus-article-emphasis)
299 (defface gnus-emphasis-italic '((t (:italic t)))
300 "Face used for displaying italic emphasized text (/word/)."
301 :group 'gnus-article-emphasis)
303 (defface gnus-emphasis-underline '((t (:underline t)))
304 "Face used for displaying underlined emphasized text (_word_)."
305 :group 'gnus-article-emphasis)
307 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
308 "Face used for displaying underlined bold emphasized text (_*word*_)."
309 :group 'gnus-article-emphasis)
311 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
312 "Face used for displaying underlined italic emphasized text (_/word/_)."
313 :group 'gnus-article-emphasis)
315 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
316 "Face used for displaying bold italic emphasized text (/*word*/)."
317 :group 'gnus-article-emphasis)
319 (defface gnus-emphasis-underline-bold-italic
320 '((t (:bold t :italic t :underline t)))
321 "Face used for displaying underlined bold italic emphasized text.
322 Esample: (_/*word*/_)."
323 :group 'gnus-article-emphasis)
325 (defface gnus-emphasis-highlight-words
326 '((t (:background "black" :foreground "yellow")))
327 "Face used for displaying highlighted words."
328 :group 'gnus-article-emphasis)
330 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
331 "Format for display of Date headers in article bodies.
332 See `format-time-string' for the possible values.
334 The variable can also be function, which should return a complete Date
335 header. The function is called with one argument, the time, which can
336 be fed to `format-time-string'."
337 :type '(choice string symbol)
338 :link '(custom-manual "(gnus)Article Date")
339 :group 'gnus-article-washing)
342 (autoload 'mail-extract-address-components "mail-extr"))
344 (defcustom gnus-save-all-headers t
345 "*If non-nil, don't remove any headers before saving."
346 :group 'gnus-article-saving
349 (defcustom gnus-prompt-before-saving 'always
350 "*This variable says how much prompting is to be done when saving articles.
351 If it is nil, no prompting will be done, and the articles will be
352 saved to the default files. If this variable is `always', each and
353 every article that is saved will be preceded by a prompt, even when
354 saving large batches of articles. If this variable is neither nil not
355 `always', there the user will be prompted once for a file name for
356 each invocation of the saving commands."
357 :group 'gnus-article-saving
358 :type '(choice (item always)
359 (item :tag "never" nil)
360 (sexp :tag "once" :format "%t\n" :value t)))
362 (defcustom gnus-saved-headers gnus-visible-headers
363 "Headers to keep if `gnus-save-all-headers' is nil.
364 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
365 If that variable is nil, however, all headers that match this regexp
366 will be kept while the rest will be deleted before saving."
367 :group 'gnus-article-saving
370 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
371 "A function to save articles in your favourite format.
372 The function must be interactively callable (in other words, it must
373 be an Emacs command).
375 Gnus provides the following functions:
377 * gnus-summary-save-in-rmail (Rmail format)
378 * gnus-summary-save-in-mail (Unix mail format)
379 * gnus-summary-save-in-folder (MH folder)
380 * gnus-summary-save-in-file (article format)
381 * gnus-summary-save-in-vm (use VM's folder format)
382 * gnus-summary-write-to-file (article format -- overwrite)."
383 :group 'gnus-article-saving
384 :type '(radio (function-item gnus-summary-save-in-rmail)
385 (function-item gnus-summary-save-in-mail)
386 (function-item gnus-summary-save-in-folder)
387 (function-item gnus-summary-save-in-file)
388 (function-item gnus-summary-save-in-vm)
389 (function-item gnus-summary-write-to-file)))
391 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
392 "A function generating a file name to save articles in Rmail format.
393 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
394 :group 'gnus-article-saving
397 (defcustom gnus-mail-save-name 'gnus-plain-save-name
398 "A function generating a file name to save articles in Unix mail format.
399 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
400 :group 'gnus-article-saving
403 (defcustom gnus-folder-save-name 'gnus-folder-save-name
404 "A function generating a file name to save articles in MH folder.
405 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
406 :group 'gnus-article-saving
409 (defcustom gnus-file-save-name 'gnus-numeric-save-name
410 "A function generating a file name to save articles in article format.
411 The function is called with NEWSGROUP, HEADERS, and optional
413 :group 'gnus-article-saving
416 (defcustom gnus-split-methods
417 '((gnus-article-archive-name)
418 (gnus-article-nndoc-name))
419 "*Variable used to suggest where articles are to be saved.
420 For instance, if you would like to save articles related to Gnus in
421 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
422 you could set this variable to something like:
424 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
425 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
427 This variable is an alist where the where the key is the match and the
428 value is a list of possible files to save in if the match is non-nil.
430 If the match is a string, it is used as a regexp match on the
431 article. If the match is a symbol, that symbol will be funcalled
432 from the buffer of the article to be saved with the newsgroup as the
433 parameter. If it is a list, it will be evaled in the same buffer.
435 If this form or function returns a string, this string will be used as
436 a possible file name; and if it returns a non-nil list, that list will
437 be used as possible file names."
438 :group 'gnus-article-saving
439 :type '(repeat (choice (list :value (fun) function)
440 (cons :value ("" "") regexp (repeat string))
443 (defcustom gnus-article-display-method-for-mime
444 'gnus-article-display-mime-message
445 "Function to display a MIME message.
446 The function is called from the article buffer."
447 :group 'gnus-article-mime
450 (defcustom gnus-article-display-method-for-traditional
451 'gnus-article-display-traditional-message
452 "*Function to display a traditional message.
453 The function is called from the article buffer."
454 :group 'gnus-article-mime
457 (defcustom gnus-page-delimiter "^\^L"
458 "*Regexp describing what to use as article page delimiters.
459 The default value is \"^\^L\", which is a form linefeed at the
460 beginning of a line."
462 :group 'gnus-article-various)
464 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
465 "*The format specification for the article mode line.
466 See `gnus-summary-mode-line-format' for a closer description.
468 The following additional specs are available:
470 %w The article washing status.
471 %m The number of MIME parts in the article."
473 :group 'gnus-article-various)
475 (defcustom gnus-article-mode-hook nil
476 "*A hook for Gnus article mode."
478 :group 'gnus-article-various)
480 (defcustom gnus-article-menu-hook nil
481 "*Hook run after the creation of the article mode menu."
483 :group 'gnus-article-various)
485 (defcustom gnus-article-prepare-hook nil
486 "*A hook called after an article has been prepared in the article buffer."
488 :group 'gnus-article-various)
490 (defcustom gnus-article-hide-pgp-hook nil
491 "*A hook called after successfully hiding a PGP signature."
493 :group 'gnus-article-various)
495 (defcustom gnus-article-button-face 'bold
496 "Face used for highlighting buttons in the article buffer.
498 An article button is a piece of text that you can activate by pressing
499 `RET' or `mouse-2' above it."
501 :group 'gnus-article-buttons)
503 (defcustom gnus-article-mouse-face 'highlight
504 "Face used for mouse highlighting in the article buffer.
506 Article buttons will be displayed in this face when the cursor is
509 :group 'gnus-article-buttons)
511 (defcustom gnus-signature-face 'gnus-signature-face
512 "Face used for highlighting a signature in the article buffer.
513 Obsolete; use the face `gnus-signature-face' for customizations instead."
515 :group 'gnus-article-highlight
516 :group 'gnus-article-signature)
518 (defface gnus-signature-face
521 "Face used for highlighting a signature in the article buffer."
522 :group 'gnus-article-highlight
523 :group 'gnus-article-signature)
525 (defface gnus-header-from-face
528 (:foreground "spring green"))
531 (:foreground "red3"))
534 "Face used for displaying from headers."
535 :group 'gnus-article-headers
536 :group 'gnus-article-highlight)
538 (defface gnus-header-subject-face
541 (:foreground "SeaGreen3"))
544 (:foreground "red4"))
546 (:bold t :italic t)))
547 "Face used for displaying subject headers."
548 :group 'gnus-article-headers
549 :group 'gnus-article-highlight)
551 (defface gnus-header-newsgroups-face
554 (:foreground "yellow" :italic t))
557 (:foreground "MidnightBlue" :italic t))
560 "Face used for displaying newsgroups headers."
561 :group 'gnus-article-headers
562 :group 'gnus-article-highlight)
564 (defface gnus-header-name-face
567 (:foreground "SeaGreen"))
570 (:foreground "maroon"))
573 "Face used for displaying header names."
574 :group 'gnus-article-headers
575 :group 'gnus-article-highlight)
577 (defface gnus-header-content-face
580 (:foreground "forest green" :italic t))
583 (:foreground "indianred4" :italic t))
585 (:italic t))) "Face used for displaying header content."
586 :group 'gnus-article-headers
587 :group 'gnus-article-highlight)
589 (defcustom gnus-header-face-alist
590 '(("From" nil gnus-header-from-face)
591 ("Subject" nil gnus-header-subject-face)
592 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
593 ("" gnus-header-name-face gnus-header-content-face))
594 "*Controls highlighting of article header.
596 An alist of the form (HEADER NAME CONTENT).
598 HEADER is a regular expression which should match the name of an
599 header header and NAME and CONTENT are either face names or nil.
601 The name of each header field will be displayed using the face
602 specified by the first element in the list where HEADER match the
603 header name and NAME is non-nil. Similarly, the content will be
604 displayed by the first non-nil matching CONTENT face."
605 :group 'gnus-article-headers
606 :group 'gnus-article-highlight
607 :type '(repeat (list (regexp :tag "Header")
609 (item :tag "skip" nil)
610 (face :value default))
611 (choice :tag "Content"
612 (item :tag "skip" nil)
613 (face :value default)))))
615 (defcustom gnus-article-decode-hook nil
616 "*Hook run to decode charsets in articles."
617 :group 'gnus-article-headers
620 (defcustom gnus-display-mime-function 'gnus-display-mime
621 "Function to display MIME articles."
622 :group 'gnus-article-mime
625 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
626 "Function used to decode headers.")
628 (defvar gnus-article-dumbquotes-map
647 "Table for MS-to-Latin1 translation.")
649 (defcustom gnus-ignored-mime-types nil
650 "List of MIME types that should be ignored by Gnus."
651 :group 'gnus-article-mime
652 :type '(repeat regexp))
654 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
655 "List of MIME types that should not be given buttons when rendered inline."
656 :group 'gnus-article-mime
657 :type '(repeat regexp))
659 (defcustom gnus-article-mime-part-function nil
660 "Function called with a MIME handle as the argument.
661 This is meant for people who want to do something automatic based
662 on parts -- for instance, adding Vcard info to a database."
663 :group 'gnus-article-mime
666 (defcustom gnus-mime-multipart-functions nil
667 "An alist of MIME types to functions to display them."
668 :group 'gnus-article-mime
671 (defcustom gnus-article-date-lapsed-new-header nil
672 "Whether the X-Sent and Date headers can coexist.
673 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
674 either replace the old \"Date:\" header (if this variable is nil), or
675 be added below it (otherwise)."
676 :group 'gnus-article-headers
679 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
680 "Function called with a MIME handle as the argument.
681 This is meant for people who want to view first matched part.
682 For `undisplayed-alternative' (default), the first undisplayed
683 part or alternative part is used. For `undisplayed', the first
684 undisplayed part is used. For a function, the first part which
685 the function return `t' is used. For `nil', the first part is
687 :group 'gnus-article-mime
689 (item :tag "first" :value nil)
690 (item :tag "undisplayed" :value undisplayed)
691 (item :tag "undisplayed or alternative"
692 :value undisplayed-alternative)
695 (defcustom gnus-mime-action-alist
696 '(("save to file" . gnus-mime-save-part)
697 ("display as text" . gnus-mime-inline-part)
698 ("view the part" . gnus-mime-view-part)
699 ("pipe to command" . gnus-mime-pipe-part)
700 ("toggle display" . gnus-article-press-button)
701 ("view as type" . gnus-mime-view-part-as-type)
702 ("internalize type" . gnus-mime-internalize-part)
703 ("externalize type" . gnus-mime-externalize-part))
704 "An alist of actions that run on the MIME attachment."
705 :group 'gnus-article-mime
706 :type '(repeat (cons (string :tag "name")
710 ;;; The treatment variables
713 (defvar gnus-part-display-hook nil
714 "Hook called on parts that are to receive treatment.")
716 (defvar gnus-article-treat-custom
717 '(choice (const :tag "Off" nil)
719 (const :tag "Header" head)
720 (const :tag "Last" last)
721 (const :tag "Mime" mime)
722 (integer :tag "Less")
723 (repeat :tag "Groups" regexp)
724 (sexp :tag "Predicate")))
726 (defvar gnus-article-treat-head-custom
727 '(choice (const :tag "Off" nil)
728 (const :tag "Header" head)))
730 (defvar gnus-article-treat-types '("text/plain")
733 (defvar gnus-inhibit-treatment nil
734 "Whether to inhibit treatment.")
736 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
737 "Highlight the signature.
738 Valid values are nil, t, `head', `last', an integer or a predicate.
739 See the manual for details."
740 :group 'gnus-article-treat
741 :type gnus-article-treat-custom)
742 (put 'gnus-treat-highlight-signature 'highlight t)
744 (defcustom gnus-treat-buttonize 100000
746 Valid values are nil, t, `head', `last', an integer or a predicate.
747 See the manual for details."
748 :group 'gnus-article-treat
749 :type gnus-article-treat-custom)
750 (put 'gnus-treat-buttonize 'highlight t)
752 (defcustom gnus-treat-buttonize-head 'head
753 "Add buttons to the head.
754 Valid values are nil, t, `head', `last', an integer or a predicate.
755 See the manual for details."
756 :group 'gnus-article-treat
757 :type gnus-article-treat-head-custom)
758 (put 'gnus-treat-buttonize-head 'highlight t)
760 (defcustom gnus-treat-emphasize
761 (and (or window-system
763 (>= (string-to-number emacs-version) 21))
766 Valid values are nil, t, `head', `last', an integer or a predicate.
767 See the manual for details."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-custom)
770 (put 'gnus-treat-emphasize 'highlight t)
772 (defcustom gnus-treat-strip-cr nil
773 "Remove carriage returns.
774 Valid values are nil, t, `head', `last', an integer or a predicate.
775 See the manual for details."
776 :group 'gnus-article-treat
777 :type gnus-article-treat-custom)
779 (defcustom gnus-treat-hide-headers 'head
781 Valid values are nil, t, `head', `last', an integer or a predicate.
782 See the manual for details."
783 :group 'gnus-article-treat
784 :type gnus-article-treat-head-custom)
786 (defcustom gnus-treat-hide-boring-headers nil
787 "Hide boring headers.
788 Valid values are nil, t, `head', `last', an integer or a predicate.
789 See the manual for details."
790 :group 'gnus-article-treat
791 :type gnus-article-treat-head-custom)
793 (defcustom gnus-treat-hide-signature nil
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797 :group 'gnus-article-treat
798 :type gnus-article-treat-custom)
800 (defcustom gnus-treat-fill-article nil
802 Valid values are nil, t, `head', `last', an integer or a predicate.
803 See the manual for details."
804 :group 'gnus-article-treat
805 :type gnus-article-treat-custom)
807 (defcustom gnus-treat-hide-citation nil
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-custom)
814 (defcustom gnus-treat-hide-citation-maybe nil
816 Valid values are nil, t, `head', `last', an integer or a predicate.
817 See the manual for details."
818 :group 'gnus-article-treat
819 :type gnus-article-treat-custom)
821 (defcustom gnus-treat-strip-list-identifiers 'head
822 "Strip list identifiers from `gnus-list-identifiers`.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-custom)
828 (defcustom gnus-treat-strip-pgp t
829 "Strip PGP signatures.
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-custom)
835 (defcustom gnus-treat-strip-pem nil
836 "Strip PEM signatures.
837 Valid values are nil, t, `head', `last', an integer or a predicate.
838 See the manual for details."
839 :group 'gnus-article-treat
840 :type gnus-article-treat-custom)
842 (defcustom gnus-treat-strip-banner t
843 "Strip banners from articles.
844 The banner to be stripped is specified in the `banner' group parameter.
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847 :group 'gnus-article-treat
848 :type gnus-article-treat-custom)
850 (defcustom gnus-treat-highlight-headers 'head
851 "Highlight the headers.
852 Valid values are nil, t, `head', `last', an integer or a predicate.
853 See the manual for details."
854 :group 'gnus-article-treat
855 :type gnus-article-treat-head-custom)
856 (put 'gnus-treat-highlight-headers 'highlight t)
858 (defcustom gnus-treat-highlight-citation t
859 "Highlight cited text.
860 Valid values are nil, t, `head', `last', an integer or a predicate.
861 See the manual for details."
862 :group 'gnus-article-treat
863 :type gnus-article-treat-custom)
864 (put 'gnus-treat-highlight-citation 'highlight t)
866 (defcustom gnus-treat-date-ut nil
867 "Display the Date in UT (GMT).
868 Valid values are nil, t, `head', `last', an integer or a predicate.
869 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-head-custom)
873 (defcustom gnus-treat-date-local nil
874 "Display the Date in the local timezone.
875 Valid values are nil, t, `head', `last', an integer or a predicate.
876 See the manual for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-head-custom)
880 (defcustom gnus-treat-date-lapsed nil
881 "Display the Date header in a way that says how much time has elapsed.
882 Valid values are nil, t, `head', `last', an integer or a predicate.
883 See the manual for details."
884 :group 'gnus-article-treat
885 :type gnus-article-treat-head-custom)
887 (defcustom gnus-treat-date-original nil
888 "Display the date in the original timezone.
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891 :group 'gnus-article-treat
892 :type gnus-article-treat-head-custom)
894 (defcustom gnus-treat-date-iso8601 nil
895 "Display the date in the ISO8601 format.
896 Valid values are nil, t, `head', `last', an integer or a predicate.
897 See the manual for details."
898 :group 'gnus-article-treat
899 :type gnus-article-treat-head-custom)
901 (defcustom gnus-treat-date-user-defined nil
902 "Display the date in a user-defined format.
903 The format is defined by the `gnus-article-time-format' variable.
904 Valid values are nil, t, `head', `last', an integer or a predicate.
905 See the manual for details."
906 :group 'gnus-article-treat
907 :type gnus-article-treat-head-custom)
909 (defcustom gnus-treat-strip-headers-in-body t
910 "Strip the X-No-Archive header line from the beginning of the body.
911 Valid values are nil, t, `head', `last', an integer or a predicate.
912 See the manual for details."
913 :group 'gnus-article-treat
914 :type gnus-article-treat-custom)
916 (defcustom gnus-treat-strip-trailing-blank-lines nil
917 "Strip trailing blank lines.
918 Valid values are nil, t, `head', `last', an integer or a predicate.
919 See the manual for details."
920 :group 'gnus-article-treat
921 :type gnus-article-treat-custom)
923 (defcustom gnus-treat-strip-leading-blank-lines nil
924 "Strip leading blank lines.
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-custom)
930 (defcustom gnus-treat-strip-multiple-blank-lines nil
931 "Strip multiple blank lines.
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
934 :group 'gnus-article-treat
935 :type gnus-article-treat-custom)
937 (defcustom gnus-treat-overstrike t
938 "Treat overstrike highlighting.
939 Valid values are nil, t, `head', `last', an integer or a predicate.
940 See the manual for details."
941 :group 'gnus-article-treat
942 :type gnus-article-treat-custom)
943 (put 'gnus-treat-overstrike 'highlight t)
945 (defcustom gnus-treat-display-xface
946 (if (or (and (fboundp 'image-type-available-p)
947 (image-type-available-p 'xbm)
948 (string-match "^0x" (shell-command-to-string "uncompface")))
949 (and (featurep 'xemacs) (featurep 'xface))
950 (eq 'x-face-mule-gnus-article-display-x-face
951 gnus-article-x-face-command))
954 "Display X-Face headers.
955 Valid values are nil, t, `head', `last', an integer or a predicate.
956 See the manual for details."
957 :group 'gnus-article-treat
958 :type gnus-article-treat-head-custom)
959 (put 'gnus-treat-display-xface 'highlight t)
961 (defcustom gnus-treat-display-smileys
962 (if (or (and (featurep 'xemacs)
964 (and (fboundp 'image-type-available-p)
965 (image-type-available-p 'pbm))
966 (and (not (featurep 'xemacs))
968 (module-installed-p 'smiley-mule)))
972 Valid values are nil, t, `head', `last', an integer or a predicate.
973 See the manual for details."
974 :group 'gnus-article-treat
975 :type gnus-article-treat-custom)
976 (put 'gnus-treat-display-smileys 'highlight t)
978 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
980 Valid values are nil, t, `head', `last', an integer or a predicate.
981 See the manual for details."
982 :group 'gnus-article-treat
983 :type gnus-article-treat-head-custom)
984 (put 'gnus-treat-display-picons 'highlight t)
986 (defcustom gnus-treat-capitalize-sentences nil
987 "Capitalize sentence-starting words.
988 Valid values are nil, t, `head', `last', an integer or a predicate.
989 See the manual for details."
990 :group 'gnus-article-treat
991 :type gnus-article-treat-custom)
993 (defcustom gnus-treat-fill-long-lines nil
995 Valid values are nil, t, `head', `last', an integer or a predicate.
996 See the manual for details."
997 :group 'gnus-article-treat
998 :type gnus-article-treat-custom)
1000 (defcustom gnus-treat-play-sounds nil
1002 Valid values are nil, t, `head', `last', an integer or a predicate.
1003 See the manual for details."
1004 :group 'gnus-article-treat
1005 :type gnus-article-treat-custom)
1007 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1008 "Decode an article as `default-mime-charset'. For instance, if you want to
1009 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1010 you could set this variable to something like: nil for don't decode, t for
1011 decode the body, '(or header t) for the whole article, etc."
1012 :group 'gnus-article-treat
1013 :type '(radio (const :tag "Off" nil)
1014 (const :tag "Decode body" t)
1015 (const :tag "Decode all" (or head t))))
1017 (defcustom gnus-treat-translate nil
1018 "Translate articles from one language to another.
1019 Valid values are nil, t, `head', `last', an integer or a predicate.
1020 See the manual for details."
1021 :group 'gnus-article-treat
1022 :type gnus-article-treat-custom)
1024 ;;; Internal variables
1026 (defvar article-goto-body-goes-to-point-min-p nil)
1027 (defvar gnus-article-wash-types nil)
1028 (defvar gnus-article-emphasis-alist nil)
1030 (defvar gnus-article-mime-handle-alist-1 nil)
1031 (defvar gnus-treatment-function-alist
1032 '((gnus-treat-decode-article-as-default-mime-charset
1033 gnus-article-decode-article-as-default-mime-charset)
1034 (gnus-treat-strip-banner gnus-article-strip-banner)
1035 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1036 (gnus-treat-buttonize gnus-article-add-buttons)
1037 (gnus-treat-fill-article gnus-article-fill-cited-article)
1038 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1039 (gnus-treat-strip-cr gnus-article-remove-cr)
1040 (gnus-treat-display-xface gnus-article-display-x-face)
1041 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1042 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1043 (gnus-treat-hide-signature gnus-article-hide-signature)
1044 (gnus-treat-hide-citation gnus-article-hide-citation)
1045 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1046 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1047 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1048 (gnus-treat-strip-pem gnus-article-hide-pem)
1049 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1050 (gnus-treat-emphasize gnus-article-emphasize)
1051 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1052 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1053 (gnus-treat-date-ut gnus-article-date-ut)
1054 (gnus-treat-date-local gnus-article-date-local)
1055 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1056 (gnus-treat-date-original gnus-article-date-original)
1057 (gnus-treat-date-user-defined gnus-article-date-user)
1058 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1059 (gnus-treat-strip-trailing-blank-lines
1060 gnus-article-remove-trailing-blank-lines)
1061 (gnus-treat-strip-leading-blank-lines
1062 gnus-article-strip-leading-blank-lines)
1063 (gnus-treat-strip-multiple-blank-lines
1064 gnus-article-strip-multiple-blank-lines)
1065 (gnus-treat-overstrike gnus-article-treat-overstrike)
1066 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1067 (gnus-treat-display-smileys ,(if (or (featurep 'xemacs)
1068 (>= emacs-major-version 21))
1069 'gnus-smiley-display
1070 'gnus-article-smiley-display))
1071 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1072 (gnus-treat-display-picons gnus-article-display-picons)
1073 (gnus-treat-play-sounds gnus-earcon-display)))
1075 (defvar gnus-article-mime-handle-alist nil)
1076 (defvar article-lapsed-timer nil)
1077 (defvar gnus-article-current-summary nil)
1079 (defvar gnus-article-mode-syntax-table
1080 (let ((table (copy-syntax-table text-mode-syntax-table)))
1081 (modify-syntax-entry ?- "w" table)
1082 (modify-syntax-entry ?> ")" table)
1083 (modify-syntax-entry ?< "(" table)
1085 "Syntax table used in article mode buffers.
1086 Initialized from `text-mode-syntax-table.")
1088 (defvar gnus-save-article-buffer nil)
1090 (defvar gnus-article-mode-line-format-alist
1091 (nconc '((?w (gnus-article-wash-status) ?s)
1092 (?m (gnus-article-mime-part-status) ?s))
1093 gnus-summary-mode-line-format-alist))
1095 (defvar gnus-number-of-articles-to-be-saved nil)
1097 (defvar gnus-inhibit-hiding nil)
1099 (defsubst gnus-article-hide-text (b e props)
1100 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1101 (gnus-add-text-properties-when 'article-type nil b e props)
1102 (when (memq 'intangible props)
1104 (max (1- b) (point-min))
1105 b 'intangible (cddr (memq 'intangible props)))))
1107 (defsubst gnus-article-unhide-text (b e)
1108 "Remove hidden text properties from region between B and E."
1109 (remove-text-properties b e gnus-hidden-properties)
1110 (when (memq 'intangible gnus-hidden-properties)
1111 (put-text-property (max (1- b) (point-min))
1112 b 'intangible nil)))
1114 (defun gnus-article-hide-text-type (b e type)
1115 "Hide text of TYPE between B and E."
1116 (push type gnus-article-wash-types)
1117 (gnus-article-hide-text
1118 b e (cons 'article-type (cons type gnus-hidden-properties))))
1120 (defun gnus-article-unhide-text-type (b e type)
1121 "Unhide text of TYPE between B and E."
1122 (setq gnus-article-wash-types
1123 (delq type gnus-article-wash-types))
1124 (remove-text-properties
1125 b e (cons 'article-type (cons type gnus-hidden-properties)))
1126 (when (memq 'intangible gnus-hidden-properties)
1127 (put-text-property (max (1- b) (point-min))
1128 b 'intangible nil)))
1130 (defun gnus-article-hide-text-of-type (type)
1131 "Hide text of TYPE in the current buffer."
1133 (let ((b (point-min))
1135 (while (setq b (text-property-any b e 'article-type type))
1136 (add-text-properties b (incf b) gnus-hidden-properties)))))
1138 (defun gnus-article-delete-text-of-type (type)
1139 "Delete text of TYPE in the current buffer."
1141 (let ((b (point-min)))
1142 (while (setq b (text-property-any b (point-max) 'article-type type))
1144 b (or (text-property-not-all b (point-max) 'article-type type)
1147 (defun gnus-article-delete-invisible-text ()
1148 "Delete all invisible text in the current buffer."
1150 (let ((b (point-min)))
1151 (while (setq b (text-property-any b (point-max) 'invisible t))
1153 b (or (text-property-not-all b (point-max) 'invisible t)
1156 (defun gnus-article-text-type-exists-p (type)
1157 "Say whether any text of type TYPE exists in the buffer."
1158 (text-property-any (point-min) (point-max) 'article-type type))
1160 (defsubst gnus-article-header-rank ()
1161 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1162 (let ((list gnus-sorted-header-list)
1165 (when (looking-at (car list))
1167 (setq list (cdr list))
1171 (defun article-hide-headers (&optional arg delete)
1172 "Hide unwanted headers and possibly sort them as well."
1173 (interactive (gnus-article-hidden-arg))
1174 ;; Lars said that this function might be inhibited.
1175 (if (gnus-article-check-hidden-text 'headers arg)
1177 ;; Show boring headers as well.
1178 (gnus-article-show-hidden-text 'boring-headers)
1179 (when (eq 1 (point-min))
1180 (set-window-start (get-buffer-window (current-buffer)) 1)))
1181 (unless gnus-inhibit-hiding
1184 (let ((buffer-read-only nil)
1185 (inhibit-read-only t)
1186 (case-fold-search t)
1187 (max (1+ (length gnus-sorted-header-list)))
1188 (ignored (when (not gnus-visible-headers)
1189 (cond ((stringp gnus-ignored-headers)
1190 gnus-ignored-headers)
1191 ((listp gnus-ignored-headers)
1192 (mapconcat 'identity gnus-ignored-headers
1195 (cond ((stringp gnus-visible-headers)
1196 gnus-visible-headers)
1197 ((and gnus-visible-headers
1198 (listp gnus-visible-headers))
1199 (mapconcat 'identity gnus-visible-headers "\\|"))))
1200 (inhibit-point-motion-hooks t)
1202 ;; First we narrow to just the headers.
1203 (article-narrow-to-head)
1204 ;; Hide any "From " lines at the beginning of (mail) articles.
1205 (while (looking-at "From ")
1209 (delete-region (point-min) (point))
1210 (gnus-article-hide-text (point-min) (point)
1211 (nconc (list 'article-type 'headers)
1212 gnus-hidden-properties))))
1213 ;; Then treat the rest of the header lines.
1214 ;; Then we use the two regular expressions
1215 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1216 ;; select which header lines is to remain visible in the
1218 (while (re-search-forward "^[^ \t]*:" nil t)
1220 ;; Mark the rank of the header.
1222 (point) (1+ (point)) 'message-rank
1223 (if (or (and visible (looking-at visible))
1225 (not (looking-at ignored))))
1226 (gnus-article-header-rank)
1229 (message-sort-headers-1)
1230 (when (setq beg (text-property-any
1231 (point-min) (point-max) 'message-rank (+ 2 max)))
1232 ;; We delete or make invisible the unwanted headers.
1233 (push 'headers gnus-article-wash-types)
1236 (add-text-properties
1237 (point-min) (+ 5 (point-min))
1238 '(article-type headers dummy-invisible t))
1239 (delete-region beg (point-max)))
1240 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1243 (defun article-hide-boring-headers (&optional arg)
1244 "Toggle hiding of headers that aren't very interesting.
1245 If given a negative prefix, always show; if given a positive prefix,
1247 (interactive (gnus-article-hidden-arg))
1248 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1249 (not gnus-show-all-headers))
1252 (let ((buffer-read-only nil)
1253 (list gnus-boring-article-headers)
1254 (inhibit-point-motion-hooks t)
1256 (article-narrow-to-head)
1258 (setq elem (pop list))
1259 (goto-char (point-min))
1261 ;; Hide empty headers.
1263 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1265 (gnus-article-hide-text-type
1266 (progn (beginning-of-line) (point))
1269 (if (re-search-forward "^[^ \t]" nil t)
1273 ;; Hide boring Newsgroups header.
1274 ((eq elem 'newsgroups)
1275 (when (equal (gnus-fetch-field "newsgroups")
1276 (gnus-group-real-name
1277 (if (boundp 'gnus-newsgroup-name)
1280 (gnus-article-hide-header "newsgroups")))
1281 ((eq elem 'followup-to)
1282 (when (equal (message-fetch-field "followup-to")
1283 (message-fetch-field "newsgroups"))
1284 (gnus-article-hide-header "followup-to")))
1285 ((eq elem 'reply-to)
1286 (let ((from (message-fetch-field "from"))
1287 (reply-to (message-fetch-field "reply-to")))
1292 (nth 1 (funcall gnus-extract-address-components from))
1293 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1294 (gnus-article-hide-header "reply-to"))))
1296 (let ((date (message-fetch-field "date")))
1298 (< (days-between (current-time-string) date)
1300 (gnus-article-hide-header "date"))))
1302 (let ((to (message-fetch-field "to"))
1303 (cc (message-fetch-field "cc")))
1304 (when (> (length to) 1024)
1305 (gnus-article-hide-header "to"))
1306 (when (> (length cc) 1024)
1307 (gnus-article-hide-header "cc"))))
1311 (goto-char (point-min))
1312 (while (re-search-forward "^to:" nil t)
1313 (setq to-count (1+ to-count)))
1314 (when (> to-count 1)
1315 (while (> to-count 0)
1316 (goto-char (point-min))
1318 (re-search-forward "^to:" nil nil to-count)
1320 (narrow-to-region (point) (point-max))
1321 (gnus-article-hide-header "to"))
1322 (setq to-count (1- to-count))))
1323 (goto-char (point-min))
1324 (while (re-search-forward "^cc:" nil t)
1325 (setq cc-count (1+ cc-count)))
1326 (when (> cc-count 1)
1327 (while (> cc-count 0)
1328 (goto-char (point-min))
1330 (re-search-forward "^cc:" nil nil cc-count)
1332 (narrow-to-region (point) (point-max))
1333 (gnus-article-hide-header "cc"))
1334 (setq cc-count (1- cc-count)))))))))))))
1336 (defun gnus-article-hide-header (header)
1338 (goto-char (point-min))
1339 (when (re-search-forward (concat "^" header ":") nil t)
1340 (gnus-article-hide-text-type
1341 (progn (beginning-of-line) (point))
1344 (if (re-search-forward "^[^ \t]" nil t)
1349 (defun article-toggle-headers (&optional arg)
1350 "Toggle hiding of headers. If given a negative prefix, always show;
1351 if given a positive prefix, always hide."
1352 (interactive (gnus-article-hidden-arg))
1353 (let ((force (when (numberp arg)
1354 (cond ((> arg 0) 'always-hide)
1355 ((< arg 0) 'always-show))))
1356 (window (get-buffer-window gnus-article-buffer))
1357 (header-end (point-min))
1358 header-start field-end field-start
1359 (inhibit-point-motion-hooks t)
1360 (inhibit-read-only t)
1364 (while (and (setq header-start
1365 (text-property-any header-end (point-max)
1366 'article-treated-header t))
1368 (text-property-not-all header-start (point-max)
1369 'article-treated-header t)))
1370 (setq field-end header-start)
1372 (;; Hide exposed invisible fields.
1373 (and (not (eq 'always-show force))
1375 (text-property-any field-end header-end
1376 'exposed-invisible-field t)))
1377 (while (and field-start
1378 (setq field-end (text-property-not-all
1379 field-start header-end
1380 'exposed-invisible-field t)))
1381 (add-text-properties field-start field-end gnus-hidden-properties)
1382 (setq field-start (text-property-any field-end header-end
1383 'exposed-invisible-field t)))
1384 (put-text-property header-start header-end
1385 'exposed-invisible-field nil))
1386 (;; Expose invisible fields.
1387 (and (not (eq 'always-hide force))
1389 (text-property-any field-end header-end 'invisible t)))
1390 (while (and field-start
1391 (setq field-end (text-property-not-all
1392 field-start header-end
1394 ;; If the invisible text is not terminated with newline, we
1395 ;; won't expose it. Because it may be created by x-face-mule.
1396 ;; BTW, XEmacs sometimes fail in putting a invisible text
1397 ;; property with `gnus-article-hide-text' (really?). In that
1398 ;; case, the invisible text might be started from the middle of
1399 ;; a line so we will expose the sort of thing.
1400 (when (or (not (or (eq header-start field-start)
1401 (eq ?\n (char-before field-start))))
1402 (eq ?\n (char-before field-end)))
1403 (remove-text-properties field-start field-end
1404 gnus-hidden-properties)
1405 (put-text-property field-start field-end
1406 'exposed-invisible-field t))
1407 (setq field-start (text-property-any field-end header-end
1410 (not (eq 'always-show force))
1411 (narrow-to-region header-start header-end)
1412 (article-hide-headers)
1413 ;; Re-display X-Face image under XEmacs.
1414 (when (and (featurep 'xemacs)
1415 (gnus-functionp gnus-article-x-face-command))
1416 (let ((func (cadr (assq 'gnus-treat-display-xface
1417 gnus-treatment-function-alist)))
1419 (when (and (not gnus-inhibit-treatment)
1421 (gnus-treat-predicate gnus-treat-display-xface))
1423 (put-text-property header-start header-end 'read-only nil))))
1426 (goto-char (point-min))
1428 (set-window-start window (point-min))))))
1430 (defvar gnus-article-normalized-header-length 40
1431 "Length of normalized headers.")
1433 (defun article-normalize-headers ()
1434 "Make all header lines 40 characters long."
1436 (let ((buffer-read-only nil)
1440 (article-narrow-to-head)
1443 ((< (setq column (- (gnus-point-at-eol) (point)))
1444 gnus-article-normalized-header-length)
1446 (insert (make-string
1447 (- gnus-article-normalized-header-length column)
1449 ((> column gnus-article-normalized-header-length)
1450 (gnus-put-text-property
1452 (forward-char gnus-article-normalized-header-length)
1459 (forward-line 1))))))
1461 (defun article-treat-dumbquotes ()
1462 "Translate M****s*** sm*rtq**t*s into proper text.
1463 Note that this function guesses whether a character is a sm*rtq**t* or
1464 not, so it should only be used interactively.
1466 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1467 in an attempt to provide more quoting characters. If you see
1468 something like \\222 or \\264 where you're expecting some kind of
1469 apostrophe or quotation mark, then try this wash."
1471 (article-translate-strings gnus-article-dumbquotes-map))
1473 (defun article-translate-characters (from to)
1474 "Translate all characters in the body of the article according to FROM and TO.
1475 FROM is a string of characters to translate from; to is a string of
1476 characters to translate to."
1478 (when (article-goto-body)
1479 (let ((buffer-read-only nil)
1480 (x (make-string 225 ?x))
1482 (while (< (incf i) (length x))
1485 (while (< i (length from))
1486 (aset x (aref from i) (aref to i))
1488 (translate-region (point) (point-max) x)))))
1490 (defun article-translate-strings (map)
1491 "Translate all string in the body of the article according to MAP.
1492 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1494 (when (article-goto-body)
1495 (let ((buffer-read-only nil)
1497 (while (setq elem (pop map))
1499 (while (search-forward (car elem) nil t)
1500 (replace-match (cadr elem)))))))))
1502 (defun article-treat-overstrike ()
1503 "Translate overstrikes into bold text."
1506 (when (article-goto-body)
1507 (let ((buffer-read-only nil))
1508 (while (search-forward "\b" nil t)
1509 (let ((next (char-after))
1513 previous (char-after))
1517 ;; We do the boldification/underlining by hiding the
1518 ;; overstrikes and putting the proper text property
1522 (gnus-article-hide-text-type start (point) 'overstrike)
1523 (put-text-property (point) end 'face 'bold))
1525 (gnus-article-hide-text-type
1526 (1- (point)) (1+ (point)) 'overstrike)
1528 start (1- (point)) 'face 'underline))
1530 (gnus-article-hide-text-type start (point) 'overstrike)
1532 (point) end 'face 'underline)))))))))
1534 (defun article-fill-long-lines ()
1535 "Fill lines that are wider than the window width."
1538 (let ((buffer-read-only nil)
1539 (width (window-width (get-buffer-window (current-buffer)))))
1542 (let ((adaptive-fill-mode nil))
1545 (when (>= (current-column) (min fill-column width))
1546 (narrow-to-region (point) (gnus-point-at-bol))
1547 (fill-paragraph nil)
1548 (goto-char (point-max))
1550 (forward-line 1)))))))
1552 (defun article-capitalize-sentences ()
1553 "Capitalize the first word in each sentence."
1556 (let ((buffer-read-only nil)
1557 (paragraph-start "^[\n\^L]"))
1561 (forward-sentence)))))
1563 (defun article-remove-cr ()
1564 "Remove trailing CRs and then translate remaining CRs into LFs."
1567 (let ((buffer-read-only nil))
1568 (goto-char (point-min))
1569 (while (re-search-forward "\r+$" nil t)
1570 (replace-match "" t t))
1571 (goto-char (point-min))
1572 (while (search-forward "\r" nil t)
1573 (replace-match "\n" t t)))))
1575 (defun article-remove-trailing-blank-lines ()
1576 "Remove all trailing blank lines from the article."
1579 (let ((buffer-read-only nil))
1580 (goto-char (point-max))
1584 (while (and (not (bobp))
1585 (looking-at "^[ \t]*$")
1586 (not (gnus-annotation-in-region-p
1587 (point) (gnus-point-at-eol))))
1592 (defun article-display-x-face (&optional force)
1593 "Look for an X-Face header and display it if present."
1594 (interactive (list 'force))
1596 ;; Delete the old process, if any.
1597 (when (process-status "article-x-face")
1598 (delete-process "article-x-face"))
1599 (let ((inhibit-point-motion-hooks t)
1600 (case-fold-search t)
1603 (article-narrow-to-head)
1604 (goto-char (point-min))
1605 (setq from (message-fetch-field "from"))
1606 (goto-char (point-min))
1607 (while (and gnus-article-x-face-command
1610 ;; Check whether this face is censored.
1611 (not gnus-article-x-face-too-ugly)
1612 (and gnus-article-x-face-too-ugly from
1613 (not (string-match gnus-article-x-face-too-ugly
1615 ;; Has to be present.
1616 (re-search-forward "^X-Face:[ \t]*" nil t))
1617 ;; This used to try to do multiple faces (`while' instead of
1618 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1619 ;; work (b) it can crash some versions of Emacs (c) are
1620 ;; multiple faces really something to encourage?
1621 (when (stringp gnus-article-x-face-command)
1623 ;; We now have the area of the buffer where the X-Face is stored.
1626 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1627 ;; We display the face.
1628 (if (symbolp gnus-article-x-face-command)
1629 ;; The command is a lisp function, so we call it.
1630 (if (gnus-functionp gnus-article-x-face-command)
1631 (funcall gnus-article-x-face-command beg end)
1632 (error "%s is not a function" gnus-article-x-face-command))
1633 ;; The command is a string, so we interpret the command
1634 ;; as a, well, command, and fork it off.
1635 (let ((process-connection-type nil))
1636 (process-kill-without-query
1638 "article-x-face" nil shell-file-name shell-command-switch
1639 gnus-article-x-face-command))
1640 (process-send-region "article-x-face" beg end)
1641 (process-send-eof "article-x-face"))))))))))
1643 (defun article-decode-mime-words ()
1644 "Decode all MIME-encoded words in the article."
1647 (set-buffer gnus-article-buffer)
1648 (let ((inhibit-point-motion-hooks t)
1650 (mail-parse-charset gnus-newsgroup-charset)
1651 (mail-parse-ignored-charsets
1652 (save-excursion (set-buffer gnus-summary-buffer)
1653 gnus-newsgroup-ignored-charsets)))
1654 (mail-decode-encoded-word-region (point-min) (point-max)))))
1656 (defun article-decode-charset (&optional prompt)
1657 "Decode charset-encoded text in the article.
1658 If PROMPT (the prefix), prompt for a coding system to use."
1660 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1662 (mail-parse-charset gnus-newsgroup-charset)
1663 (mail-parse-ignored-charsets
1664 (save-excursion (condition-case nil
1665 (set-buffer gnus-summary-buffer)
1667 gnus-newsgroup-ignored-charsets))
1668 ct cte ctl charset format)
1671 (article-narrow-to-head)
1672 (setq ct (message-fetch-field "Content-Type" t)
1673 cte (message-fetch-field "Content-Transfer-Encoding" t)
1674 ctl (and ct (ignore-errors
1675 (mail-header-parse-content-type ct)))
1678 (mm-read-coding-system "Charset to decode: "))
1680 (mail-content-type-get ctl 'charset)))
1681 format (and ctl (mail-content-type-get ctl 'format)))
1683 (setq cte (mail-header-strip cte)))
1684 (if (and ctl (not (string-match "/" (car ctl))))
1686 (goto-char (point-max)))
1689 (narrow-to-region (point) (point-max))
1690 (when (and (eq mail-parse-charset 'gnus-decoded)
1691 (eq (mm-body-7-or-8) '8bit))
1692 ;; The text code could have been decoded.
1693 (setq charset mail-parse-charset))
1694 (when (and (or (not ctl)
1695 (equal (car ctl) "text/plain"))
1696 (not format)) ;; article with format will decode later.
1698 charset (and cte (intern (downcase
1699 (gnus-strip-whitespace cte))))
1702 (defun article-decode-encoded-words ()
1703 "Remove encoded-word encoding from headers."
1704 (let (buffer-read-only)
1705 (let ((charset (save-excursion
1706 (set-buffer gnus-summary-buffer)
1707 default-mime-charset)))
1708 (mime-decode-header-in-buffer charset)
1711 (defun article-de-quoted-unreadable (&optional force)
1712 "Translate a quoted-printable-encoded article.
1713 If FORCE, decode the article whether it is marked as quoted-printable
1715 (interactive (list 'force))
1717 (let ((buffer-read-only nil) type charset)
1718 (if (gnus-buffer-live-p gnus-original-article-buffer)
1719 (with-current-buffer gnus-original-article-buffer
1721 (gnus-fetch-field "content-transfer-encoding"))
1722 (let* ((ct (gnus-fetch-field "content-type"))
1725 (mail-header-parse-content-type ct)))))
1726 (setq charset (and ctl
1727 (mail-content-type-get ctl 'charset)))
1728 (if (stringp charset)
1729 (setq charset (intern (downcase charset)))))))
1731 (setq charset gnus-newsgroup-charset))
1733 (and type (let ((case-fold-search t))
1734 (string-match "quoted-printable" type))))
1736 (quoted-printable-decode-region
1737 (point) (point-max) (mm-charset-to-coding-system charset))))))
1739 (defun article-de-base64-unreadable (&optional force)
1740 "Translate a base64 article.
1741 If FORCE, decode the article whether it is marked as base64 not."
1742 (interactive (list 'force))
1744 (let ((buffer-read-only nil) type charset)
1745 (if (gnus-buffer-live-p gnus-original-article-buffer)
1746 (with-current-buffer gnus-original-article-buffer
1748 (gnus-fetch-field "content-transfer-encoding"))
1749 (let* ((ct (gnus-fetch-field "content-type"))
1752 (mail-header-parse-content-type ct)))))
1753 (setq charset (and ctl
1754 (mail-content-type-get ctl 'charset)))
1755 (if (stringp charset)
1756 (setq charset (intern (downcase charset)))))))
1758 (setq charset gnus-newsgroup-charset))
1760 (and type (let ((case-fold-search t))
1761 (string-match "base64" type))))
1764 (narrow-to-region (point) (point-max))
1765 (base64-decode-region (point-min) (point-max))
1766 (mm-decode-coding-region
1767 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1772 (defun article-decode-HZ ()
1773 "Translate a HZ-encoded article."
1777 (let ((buffer-read-only nil))
1778 (rfc1843-decode-region (point-min) (point-max)))))
1780 (defun article-wash-html ()
1781 "Format an html article."
1784 (let ((buffer-read-only nil)
1786 (if (gnus-buffer-live-p gnus-original-article-buffer)
1787 (with-current-buffer gnus-original-article-buffer
1788 (let* ((ct (gnus-fetch-field "content-type"))
1791 (mail-header-parse-content-type ct)))))
1792 (setq charset (and ctl
1793 (mail-content-type-get ctl 'charset)))
1794 (if (stringp charset)
1795 (setq charset (intern (downcase charset)))))))
1797 (setq charset gnus-newsgroup-charset))
1799 (save-window-excursion
1801 (narrow-to-region (point) (point-max))
1803 (let ((w3-strict-width (window-width))
1804 (url-standalone-mode t))
1806 (w3-region (point-min) (point-max))
1809 (defun article-hide-list-identifiers ()
1810 "Remove list identifies from the Subject header.
1811 The `gnus-list-identifiers' variable specifies what to do."
1815 (let ((inhibit-point-motion-hooks t)
1817 (article-narrow-to-head)
1818 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1819 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1821 (goto-char (point-min))
1822 (when (re-search-forward
1823 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1824 " *\\)\\)+\\(Re: +\\)?\\)")
1826 (let ((s (or (match-string 3) (match-string 5))))
1827 (delete-region (match-beginning 1) (match-end 1))
1829 (goto-char (match-beginning 1))
1832 (defun article-hide-pgp ()
1833 "Remove any PGP headers and signatures in the current article."
1837 (let ((inhibit-point-motion-hooks t)
1838 buffer-read-only beg end)
1840 ;; Hide the "header".
1841 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1842 (push 'pgp gnus-article-wash-types)
1843 (delete-region (match-beginning 0) (match-end 0))
1844 ;; Remove armor headers (rfc2440 6.2)
1845 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1848 ;; Hide the actual signature.
1849 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1850 (setq end (1+ (match-beginning 0)))
1853 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1855 ;; Perhaps we shouldn't hide to the end of the buffer
1856 ;; if there is no end to the signature?
1858 ;; Hide "- " PGP quotation markers.
1860 (narrow-to-region beg end)
1861 (goto-char (point-min))
1862 (while (re-search-forward "^- " nil t)
1864 (match-beginning 0) (match-end 0)))
1866 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1868 (defun article-hide-pem (&optional arg)
1869 "Toggle hiding of any PEM headers and signatures in the current article.
1870 If given a negative prefix, always show; if given a positive prefix,
1872 (interactive (gnus-article-hidden-arg))
1873 (unless (gnus-article-check-hidden-text 'pem arg)
1875 (let (buffer-read-only end)
1876 (goto-char (point-min))
1877 ;; Hide the horrendously ugly "header".
1878 (when (and (search-forward
1879 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1881 (setq end (1+ (match-beginning 0))))
1882 (push 'pem gnus-article-wash-types)
1883 (gnus-article-hide-text-type
1885 (if (search-forward "\n\n" nil t)
1889 ;; Hide the trailer as well
1890 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1892 (gnus-article-hide-text-type
1893 (match-beginning 0) (match-end 0) 'pem)))))))
1895 (defun article-strip-banner ()
1896 "Strip the banner specified by the `banner' group parameter."
1900 (let ((inhibit-point-motion-hooks t)
1901 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1902 (gnus-signature-limit nil)
1903 buffer-read-only beg end)
1907 ((eq banner 'signature)
1908 (when (gnus-article-narrow-to-signature)
1911 (delete-region (point) (point-max))))
1913 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1914 (while (re-search-forward banner nil t)
1915 (delete-region (match-beginning 0) (match-end 0)))))
1917 (while (re-search-forward banner nil t)
1918 (delete-region (match-beginning 0) (match-end 0))))))))))
1920 (defun article-babel ()
1921 "Translate article using an online translation service."
1925 (set-buffer gnus-article-buffer)
1926 (when (article-goto-body)
1927 (let* ((buffer-read-only nil)
1930 (orig (buffer-substring start end))
1931 (trans (babel-as-string orig)))
1933 (narrow-to-region start end)
1934 (delete-region start end)
1937 (defun article-hide-signature (&optional arg)
1938 "Hide the signature in the current article.
1939 If given a negative prefix, always show; if given a positive prefix,
1941 (interactive (gnus-article-hidden-arg))
1947 (article-goto-body))
1948 (goto-char (point-min)))
1949 (unless (gnus-article-check-hidden-text 'signature arg)
1950 (let ((buffer-read-only nil)
1952 (while (setq button (text-property-any button (point-max)
1954 'gnus-signature-toggle))
1955 (setq button (text-property-not-all button (point-max)
1957 'gnus-signature-toggle))
1958 (when (and button (not (eobp)))
1959 (gnus-article-hide-text-type
1961 (next-single-property-change (1+ button) 'mime-view-entity
1965 (defun article-strip-headers-in-body ()
1966 "Strip offensive headers from bodies."
1970 (let ((case-fold-search t))
1971 (when (looking-at "x-no-archive:")
1972 (gnus-delete-line)))))
1974 (defun article-strip-leading-blank-lines ()
1975 "Remove all blank lines from the beginning of the article."
1978 (let ((inhibit-point-motion-hooks t)
1980 (when (article-goto-body)
1981 (while (and (not (eobp))
1982 (looking-at "[ \t]*$"))
1983 (gnus-delete-line))))))
1985 (defun article-narrow-to-head ()
1986 "Narrow the buffer to the head of the message.
1987 Point is left at the beginning of the narrowed-to region."
1989 (goto-char (point-min))
1990 (if (search-forward "\n\n" nil 1)
1993 (goto-char (point-min)))
1995 (defun article-goto-body ()
1996 "Place point at the start of the body."
1997 (goto-char (point-min))
1999 ;; This variable is only bound when dealing with separate
2001 (article-goto-body-goes-to-point-min-p
2003 ((search-forward "\n\n" nil t)
2006 (goto-char (point-max))
2009 (defun article-strip-multiple-blank-lines ()
2010 "Replace consecutive blank lines with one empty line."
2013 (let ((inhibit-point-motion-hooks t)
2015 ;; First make all blank lines empty.
2017 (while (re-search-forward "^[ \t]+$" nil t)
2018 (unless (gnus-annotation-in-region-p
2019 (match-beginning 0) (match-end 0))
2020 (replace-match "" nil t)))
2021 ;; Then replace multiple empty lines with a single empty line.
2023 (while (re-search-forward "\n\n\n+" nil t)
2024 (unless (gnus-annotation-in-region-p
2025 (match-beginning 0) (match-end 0))
2026 (replace-match "\n\n" t t))))))
2028 (defun article-strip-leading-space ()
2029 "Remove all white space from the beginning of the lines in the article."
2032 (let ((inhibit-point-motion-hooks t)
2035 (while (re-search-forward "^[ \t]+" nil t)
2036 (replace-match "" t t)))))
2038 (defun article-strip-trailing-space ()
2039 "Remove all white space from the end of the lines in the article."
2042 (let ((inhibit-point-motion-hooks t)
2045 (while (re-search-forward "[ \t]+$" nil t)
2046 (replace-match "" t t)))))
2048 (defun article-strip-blank-lines ()
2049 "Strip leading, trailing and multiple blank lines."
2051 (article-strip-leading-blank-lines)
2052 (article-remove-trailing-blank-lines)
2053 (article-strip-multiple-blank-lines))
2055 (defun article-strip-all-blank-lines ()
2056 "Strip all blank lines."
2059 (let ((inhibit-point-motion-hooks t)
2062 (while (re-search-forward "^[ \t]*\n" nil t)
2063 (replace-match "" t t)))))
2065 (defun gnus-article-narrow-to-signature ()
2066 "Narrow to the signature; return t if a signature is found, else nil."
2067 (let ((inhibit-point-motion-hooks t))
2068 (when (gnus-article-search-signature)
2070 ;; Check whether we have some limits to what we consider
2071 ;; to be a signature.
2072 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2073 (list gnus-signature-limit)))
2075 (while (setq limit (pop limits))
2076 (if (or (and (integerp limit)
2077 (< (- (point-max) (point)) limit))
2079 (< (count-lines (point) (point-max)) limit))
2080 (and (gnus-functionp limit)
2082 (and (stringp limit)
2083 (not (re-search-forward limit nil t))))
2084 () ; This limit did not succeed.
2088 (narrow-to-region (point) (point-max))
2091 (defun gnus-article-search-signature ()
2092 "Search the current buffer for the signature separator.
2093 Put point at the beginning of the signature separator."
2094 (let ((cur (point)))
2095 (goto-char (point-max))
2096 (if (if (stringp gnus-signature-separator)
2097 (re-search-backward gnus-signature-separator nil t)
2098 (let ((seps gnus-signature-separator))
2100 (not (re-search-backward (car seps) nil t)))
2107 (defun gnus-article-hidden-arg ()
2108 "Return the current prefix arg as a number, or 0 if no prefix."
2109 (list (if current-prefix-arg
2110 (prefix-numeric-value current-prefix-arg)
2113 (defun gnus-article-check-hidden-text (type arg)
2114 "Return nil if hiding is necessary.
2115 Arg can be nil or a number. Nil and positive means hide, negative
2116 means show, 0 means toggle."
2119 (let ((hide (gnus-article-hidden-text-p type)))
2125 (gnus-article-show-hidden-text type)
2128 (if (eq hide 'hidden)
2130 (gnus-article-show-hidden-text type)
2134 (defun gnus-article-hidden-text-p (type)
2135 "Say whether the current buffer contains hidden text of type TYPE."
2136 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2138 (not (get-text-property pos 'invisible))
2139 (not (get-text-property pos 'dummy-invisible)))
2141 (text-property-any (1+ pos) (point-max) 'article-type type)))
2146 (defun gnus-article-show-hidden-text (type &optional dummy)
2147 "Show all hidden text of type TYPE.
2148 Originally it is hide instead of DUMMY."
2149 (let ((buffer-read-only nil)
2150 (inhibit-point-motion-hooks t))
2151 (gnus-remove-text-properties-when
2153 (point-min) (point-max)
2154 (cons 'article-type (cons type
2155 gnus-hidden-properties)))))
2157 (defconst article-time-units
2158 `((year . ,(* 365.25 24 60 60))
2159 (week . ,(* 7 24 60 60))
2160 (day . ,(* 24 60 60))
2164 "Mapping from time units to seconds.")
2166 (defun article-date-ut (&optional type highlight header)
2167 "Convert DATE date to universal time in the current article.
2168 If TYPE is `local', convert to local time; if it is `lapsed', output
2169 how much time has lapsed since DATE. For `lapsed', the value of
2170 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2171 should replace the \"Date:\" one, or should be added below it."
2172 (interactive (list 'ut t))
2173 (let* ((header (or header
2174 (and (eq 1 (point-min))
2175 (mail-header-date (save-excursion
2176 (set-buffer gnus-summary-buffer)
2177 gnus-current-headers)))
2178 (message-fetch-field "date")
2180 (date (if (vectorp header) (mail-header-date header)
2182 (inhibit-point-motion-hooks t)
2183 bface eface date-pos)
2184 (when (and date (not (string= date "")))
2187 (article-narrow-to-head)
2188 (when (or (and (eq type 'lapsed)
2189 gnus-article-date-lapsed-new-header
2190 ;; Attempt to get the face of X-Sent first.
2191 (re-search-forward "^X-Sent:[ \t]" nil t))
2192 (re-search-forward "^Date:[ \t]" nil t)
2193 ;; If Date is missing, try again for X-Sent.
2194 (re-search-forward "^X-Sent:[ \t]" nil t))
2195 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2196 date (or (get-text-property (gnus-point-at-bol)
2199 eface (get-text-property (1- (gnus-point-at-eol))
2201 (let ((buffer-read-only nil))
2202 ;; Delete any old X-Sent headers.
2203 (when (setq date-pos
2204 (text-property-any (point-min) (point-max)
2205 'article-date-lapsed t))
2206 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2207 (delete-region (match-beginning 0)
2208 (progn (forward-line 1) (point))))
2209 (goto-char (point-min))
2210 ;; Delete any old Date headers.
2211 (while (re-search-forward "^Date:[ \t]" nil t)
2213 (setq date-pos (match-beginning 0)))
2214 (unless (and (eq type 'lapsed)
2215 gnus-article-date-lapsed-new-header)
2216 (delete-region (match-beginning 0)
2217 (progn (message-next-header) (point)))))
2220 (goto-char date-pos)
2222 ;; Possibly, Date has been deleted.
2224 (when (and (eq type 'lapsed)
2225 gnus-article-date-lapsed-new-header
2226 (looking-at "Date:"))
2228 (goto-char (point-min)))
2229 (insert (article-make-date-line date type))
2230 (when (eq type 'lapsed)
2231 (put-text-property (gnus-point-at-bol) (point)
2232 'article-date-lapsed t))
2236 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2237 (put-text-property (match-beginning 1) (1+ (match-end 1))
2238 'original-date date)
2239 (put-text-property (match-beginning 1) (1+ (match-end 1))
2241 (put-text-property (match-beginning 2) (match-end 2)
2244 (defun article-make-date-line (date type)
2245 "Return a DATE line of TYPE."
2246 (let ((time (condition-case ()
2250 ;; Convert to the local timezone. We have to slap a
2251 ;; `condition-case' round the calls to the timezone
2252 ;; functions since they aren't particularly resistant to
2255 (let ((tz (car (current-time-zone time))))
2256 (format "Date: %s %s%02d%02d" (current-time-string time)
2257 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2258 (/ (% (abs tz) 3600) 60))))
2259 ;; Convert to Universal Time.
2262 (current-time-string
2263 (let* ((e (parse-time-string date))
2264 (tm (apply 'encode-time e))
2266 (ls (- (cadr tm) (car (current-time-zone time)))))
2267 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2268 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2271 ;; Get the original date from the article.
2272 ((eq type 'original)
2273 (concat "Date: " (if (string-match "\n+$" date)
2274 (substring date 0 (match-beginning 0))
2276 ;; Let the user define the format.
2278 (if (gnus-functionp gnus-article-time-format)
2279 (funcall gnus-article-time-format time)
2282 (format-time-string gnus-article-time-format time))))
2285 (let ((tz (car (current-time-zone time))))
2288 (format-time-string "%Y%m%dT%H%M%S" time)
2289 (format "%s%02d%02d"
2290 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2291 (/ (% (abs tz) 3600) 60)))))
2292 ;; Do an X-Sent lapsed format.
2294 ;; If the date is seriously mangled, the timezone functions are
2295 ;; liable to bug out, so we ignore all errors.
2296 (let* ((now (current-time))
2297 (real-time (subtract-time now time))
2298 (real-sec (and real-time
2299 (+ (* (float (car real-time)) 65536)
2301 (sec (and real-time (abs real-sec)))
2311 ;; This is a bit convoluted, but basically we go
2312 ;; through the time units for years, weeks, etc,
2313 ;; and divide things to see whether that results
2314 ;; in positive answers.
2317 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2318 ;; The (remaining) seconds are too few to
2319 ;; be divided into this time unit.
2321 ;; It's big enough, so we output it.
2322 (setq sec (- sec (* num (cdr unit))))
2324 (concat (if prev ", " "") (int-to-string
2326 " " (symbol-name (car unit))
2327 (if (> num 1) "s" ""))
2329 article-time-units "")
2330 ;; If dates are odd, then it might appear like the
2331 ;; article was sent in the future.
2334 " in the future"))))))
2336 (error "Unknown conversion type: %s" type)))))
2338 (defun article-date-local (&optional highlight)
2339 "Convert the current article date to the local timezone."
2340 (interactive (list t))
2341 (article-date-ut 'local highlight))
2343 (defun article-date-original (&optional highlight)
2344 "Convert the current article date to what it was originally.
2345 This is only useful if you have used some other date conversion
2346 function and want to see what the date was before converting."
2347 (interactive (list t))
2348 (article-date-ut 'original highlight))
2350 (defun article-date-lapsed (&optional highlight)
2351 "Convert the current article date to time lapsed since it was sent."
2352 (interactive (list t))
2353 (article-date-ut 'lapsed highlight))
2355 (defun article-update-date-lapsed ()
2356 "Function to be run from a timer to update the lapsed time line."
2357 (let (deactivate-mark)
2362 (set-buffer (window-buffer w))
2363 (when (eq major-mode 'gnus-article-mode)
2364 (goto-char (point-min))
2365 (when (re-search-forward "^X-Sent:" nil t)
2366 (article-date-lapsed t))))
2369 (defun gnus-start-date-timer (&optional n)
2370 "Start a timer to update the X-Sent header in the article buffers.
2371 The numerical prefix says how frequently (in seconds) the function
2376 (gnus-stop-date-timer)
2377 (setq article-lapsed-timer
2378 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2380 (defun gnus-stop-date-timer ()
2381 "Stop the X-Sent timer."
2383 (when article-lapsed-timer
2384 (nnheader-cancel-timer article-lapsed-timer)
2385 (setq article-lapsed-timer nil)))
2387 (defun article-date-user (&optional highlight)
2388 "Convert the current article date to the user-defined format.
2389 This format is defined by the `gnus-article-time-format' variable."
2390 (interactive (list t))
2391 (article-date-ut 'user highlight))
2393 (defun article-date-iso8601 (&optional highlight)
2394 "Convert the current article date to ISO8601."
2395 (interactive (list t))
2396 (article-date-ut 'iso8601 highlight))
2398 (defun article-show-all ()
2399 "Show all hidden text in the article buffer."
2403 (let ((buffer-read-only nil))
2404 (gnus-article-unhide-text (point-min) (point-max))
2405 (gnus-remove-text-with-property 'gnus-prev)
2406 (gnus-remove-text-with-property 'gnus-next))))
2408 (defun article-show-all-headers ()
2409 "Show all hidden headers in the article buffer."
2414 (article-narrow-to-head)
2415 (let ((buffer-read-only nil))
2416 (gnus-article-unhide-text (point-min) (point-max))))))
2418 (defun article-emphasize (&optional arg)
2419 "Emphasize text according to `gnus-emphasis-alist'."
2420 (interactive (gnus-article-hidden-arg))
2421 (unless (gnus-article-check-hidden-text 'emphasis arg)
2425 (with-current-buffer gnus-summary-buffer
2426 gnus-article-emphasis-alist)
2428 gnus-emphasis-alist))
2429 (buffer-read-only nil)
2430 (props (append '(article-type emphasis)
2431 gnus-hidden-properties))
2432 regexp elem beg invisible visible face)
2435 (while (setq elem (pop alist))
2437 (setq regexp (car elem)
2438 invisible (nth 1 elem)
2439 visible (nth 2 elem)
2441 (while (re-search-forward regexp nil t)
2442 (when (and (match-beginning visible) (match-beginning invisible))
2443 (push 'emphasis gnus-article-wash-types)
2444 (gnus-article-hide-text
2445 (match-beginning invisible) (match-end invisible) props)
2446 (gnus-article-unhide-text-type
2447 (match-beginning visible) (match-end visible) 'emphasis)
2448 (gnus-put-text-property-excluding-newlines
2449 (match-beginning visible) (match-end visible) 'face face)
2450 (goto-char (match-end invisible)))))))))
2452 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2453 "Setup newsgroup emphasis alist."
2454 (unless gnus-article-emphasis-alist
2455 (let ((name (and gnus-newsgroup-name
2456 (gnus-group-real-name gnus-newsgroup-name))))
2457 (make-local-variable 'gnus-article-emphasis-alist)
2458 (setq gnus-article-emphasis-alist
2460 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2461 (while (setq elem (pop alist))
2462 (when (and name (string-match (car elem) name))
2464 highlight (copy-sequence (cdr elem)))))
2466 (copy-sequence highlight-words)
2467 (if gnus-newsgroup-name
2468 (copy-sequence (gnus-group-find-parameter
2469 gnus-newsgroup-name 'highlight-words t)))
2470 gnus-emphasis-alist)))))
2472 (defvar gnus-summary-article-menu)
2473 (defvar gnus-summary-post-menu)
2475 ;;; Saving functions.
2477 (defun gnus-article-save (save-buffer file &optional num)
2478 "Save the currently selected article."
2479 (unless gnus-save-all-headers
2480 ;; Remove headers according to `gnus-saved-headers'.
2481 (let ((gnus-visible-headers
2482 (or gnus-saved-headers gnus-visible-headers))
2483 (gnus-article-buffer save-buffer))
2485 (set-buffer save-buffer)
2486 (article-hide-headers 1 t))))
2487 (save-window-excursion
2488 (if (not gnus-default-article-saver)
2489 (error "No default saver is defined")
2490 ;; !!! Magic! The saving functions all save
2491 ;; `gnus-save-article-buffer' (or so they think), but we
2492 ;; bind that variable to our save-buffer.
2493 (set-buffer gnus-article-buffer)
2494 (let* ((gnus-save-article-buffer save-buffer)
2497 ((not gnus-prompt-before-saving) 'default)
2498 ((eq gnus-prompt-before-saving 'always) nil)
2500 (gnus-number-of-articles-to-be-saved
2501 (when (eq gnus-prompt-before-saving t)
2503 (set-buffer gnus-article-current-summary)
2504 (funcall gnus-default-article-saver filename)))))
2506 (defun gnus-read-save-file-name (prompt &optional filename
2507 function group headers variable)
2509 (funcall function group headers (symbol-value variable)))
2514 ((eq filename 'default)
2520 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2523 (if (and gnus-number-of-articles-to-be-saved
2524 (> gnus-number-of-articles-to-be-saved 1))
2525 (format "these %d articles"
2526 gnus-number-of-articles-to-be-saved)
2529 ;; Let the split methods have their say.
2531 ;; No split name was found.
2534 (concat prompt " (default "
2535 (file-name-nondirectory default-name) ") ")
2536 (file-name-directory default-name)
2538 ;; A single group name is returned.
2539 ((stringp split-name)
2541 (funcall function split-name headers
2542 (symbol-value variable)))
2544 (concat prompt " (default "
2545 (file-name-nondirectory default-name) ") ")
2546 (file-name-directory default-name)
2548 ;; A single split name was found
2549 ((= 1 (length split-name))
2550 (let* ((name (expand-file-name
2552 gnus-article-save-directory))
2553 (dir (cond ((file-directory-p name)
2554 (file-name-as-directory name))
2555 ((file-exists-p name) name)
2556 (t gnus-article-save-directory))))
2558 (concat prompt " (default " name ") ")
2560 ;; A list of splits was found.
2562 (setq split-name (nreverse split-name))
2564 (let ((file-name-history
2565 (nconc split-name file-name-history)))
2569 (concat prompt " (`M-p' for defaults) ")
2570 gnus-article-save-directory
2572 gnus-article-save-directory)))
2573 (car (push result file-name-history)))))))
2574 ;; Create the directory.
2575 (gnus-make-directory (file-name-directory file))
2576 ;; If we have read a directory, we append the default file name.
2577 (when (file-directory-p file)
2578 (setq file (expand-file-name (file-name-nondirectory
2580 (file-name-as-directory file))))
2581 ;; Possibly translate some characters.
2582 (nnheader-translate-file-chars file))))))
2583 (gnus-make-directory (file-name-directory result))
2584 (set variable result)))
2586 (defun gnus-article-archive-name (group)
2587 "Return the first instance of an \"Archive-name\" in the current buffer."
2588 (let ((case-fold-search t))
2589 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2590 (nnheader-concat gnus-article-save-directory
2591 (match-string 1)))))
2593 (defun gnus-article-nndoc-name (group)
2594 "If GROUP is an nndoc group, return the name of the parent group."
2595 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2596 (gnus-group-get-parameter group 'save-article-group)))
2598 (defun gnus-summary-save-in-rmail (&optional filename)
2599 "Append this article to Rmail file.
2600 Optional argument FILENAME specifies file name.
2601 Directory to save to is default to `gnus-article-save-directory'."
2602 (setq filename (gnus-read-save-file-name
2603 "Save %s in rmail file:" filename
2604 gnus-rmail-save-name gnus-newsgroup-name
2605 gnus-current-headers 'gnus-newsgroup-last-rmail))
2606 (gnus-eval-in-buffer-window gnus-save-article-buffer
2610 (gnus-output-to-rmail filename))))
2613 (defun gnus-summary-save-in-mail (&optional filename)
2614 "Append this article to Unix mail file.
2615 Optional argument FILENAME specifies file name.
2616 Directory to save to is default to `gnus-article-save-directory'."
2617 (setq filename (gnus-read-save-file-name
2618 "Save %s in Unix mail file:" filename
2619 gnus-mail-save-name gnus-newsgroup-name
2620 gnus-current-headers 'gnus-newsgroup-last-mail))
2621 (gnus-eval-in-buffer-window gnus-save-article-buffer
2625 (if (and (file-readable-p filename)
2626 (mail-file-babyl-p filename))
2627 (rmail-output-to-rmail-file filename t)
2628 (gnus-output-to-mail filename)))))
2631 (defun gnus-summary-save-in-file (&optional filename overwrite)
2632 "Append this article to file.
2633 Optional argument FILENAME specifies file name.
2634 Directory to save to is default to `gnus-article-save-directory'."
2635 (setq filename (gnus-read-save-file-name
2636 "Save %s in file:" filename
2637 gnus-file-save-name gnus-newsgroup-name
2638 gnus-current-headers 'gnus-newsgroup-last-file))
2639 (gnus-eval-in-buffer-window gnus-save-article-buffer
2643 (when (and overwrite
2644 (file-exists-p filename))
2645 (delete-file filename))
2646 (gnus-output-to-file filename))))
2649 (defun gnus-summary-write-to-file (&optional filename)
2650 "Write this article to a file.
2651 Optional argument FILENAME specifies file name.
2652 The directory to save in defaults to `gnus-article-save-directory'."
2653 (gnus-summary-save-in-file nil t))
2655 (defun gnus-summary-save-body-in-file (&optional filename)
2656 "Append this article body to a file.
2657 Optional argument FILENAME specifies file name.
2658 The directory to save in defaults to `gnus-article-save-directory'."
2659 (setq filename (gnus-read-save-file-name
2660 "Save %s body in file:" filename
2661 gnus-file-save-name gnus-newsgroup-name
2662 gnus-current-headers 'gnus-newsgroup-last-file))
2663 (gnus-eval-in-buffer-window gnus-save-article-buffer
2667 (when (article-goto-body)
2668 (narrow-to-region (point) (point-max)))
2669 (gnus-output-to-file filename))))
2672 (defun gnus-summary-save-in-pipe (&optional command)
2673 "Pipe this article to subprocess."
2675 (cond ((and (eq command 'default)
2676 gnus-last-shell-command)
2677 gnus-last-shell-command)
2681 "Shell command on %s: "
2682 (if (and gnus-number-of-articles-to-be-saved
2683 (> gnus-number-of-articles-to-be-saved 1))
2684 (format "these %d articles"
2685 gnus-number-of-articles-to-be-saved)
2687 gnus-last-shell-command))))
2688 (when (string-equal command "")
2689 (setq command gnus-last-shell-command))
2690 (gnus-eval-in-buffer-window gnus-article-buffer
2693 (shell-command-on-region (point-min) (point-max) command nil)))
2694 (setq gnus-last-shell-command command))
2696 ;;; Article file names when saving.
2698 (defun gnus-capitalize-newsgroup (newsgroup)
2699 "Capitalize NEWSGROUP name."
2700 (when (not (zerop (length newsgroup)))
2701 (concat (char-to-string (upcase (aref newsgroup 0)))
2702 (substring newsgroup 1))))
2704 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2705 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2706 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2707 Otherwise, it is like ~/News/news/group/num."
2710 (concat (if (gnus-use-long-file-name 'not-save)
2711 (gnus-capitalize-newsgroup newsgroup)
2712 (gnus-newsgroup-directory-form newsgroup))
2713 "/" (int-to-string (mail-header-number headers)))
2714 gnus-article-save-directory)))
2716 (string-equal (file-name-directory default)
2717 (file-name-directory last-file))
2718 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2720 (or last-file default))))
2722 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2723 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2724 If variable `gnus-use-long-file-name' is non-nil, it is
2725 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2728 (concat (if (gnus-use-long-file-name 'not-save)
2730 (gnus-newsgroup-directory-form newsgroup))
2731 "/" (int-to-string (mail-header-number headers)))
2732 gnus-article-save-directory)))
2734 (string-equal (file-name-directory default)
2735 (file-name-directory last-file))
2736 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2738 (or last-file default))))
2740 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2741 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2742 If variable `gnus-use-long-file-name' is non-nil, it is
2743 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2746 (if (gnus-use-long-file-name 'not-save)
2748 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2749 gnus-article-save-directory)))
2756 (setq afunc (car func)
2759 gfunc (intern (format "gnus-%s" func))))
2762 `(lambda (&optional interactive &rest args)
2763 ,(documentation afunc t)
2764 (interactive (list t))
2766 (set-buffer gnus-article-buffer)
2768 (call-interactively ',afunc)
2769 (apply ',afunc args))))))))
2770 '(article-hide-headers
2771 article-hide-boring-headers
2772 article-toggle-headers
2773 article-treat-overstrike
2774 article-fill-long-lines
2775 article-capitalize-sentences
2777 article-display-x-face
2778 article-de-quoted-unreadable
2779 article-de-base64-unreadable
2782 article-hide-list-identifiers
2784 article-strip-banner
2787 article-hide-signature
2788 article-strip-headers-in-body
2789 article-remove-trailing-blank-lines
2790 article-strip-leading-blank-lines
2791 article-strip-multiple-blank-lines
2792 article-strip-leading-space
2793 article-strip-trailing-space
2794 article-strip-blank-lines
2795 article-strip-all-blank-lines
2797 article-date-iso8601
2798 article-date-original
2800 article-decode-mime-words
2801 article-decode-charset
2802 article-decode-encoded-words
2806 article-treat-dumbquotes
2807 article-normalize-headers
2808 (article-show-all-headers . gnus-article-show-all-headers)
2809 (article-show-all . gnus-article-show-all))))
2812 ;;; Gnus article mode
2815 (put 'gnus-article-mode 'mode-class 'special)
2817 (gnus-define-keys gnus-article-mode-map
2818 " " gnus-article-goto-next-page
2819 "\177" gnus-article-goto-prev-page
2820 [delete] gnus-article-goto-prev-page
2821 [backspace] gnus-article-goto-prev-page
2822 "\C-c^" gnus-article-refer-article
2823 "h" gnus-article-show-summary
2824 "s" gnus-article-show-summary
2825 "\C-c\C-m" gnus-article-mail
2826 "?" gnus-article-describe-briefly
2827 "e" gnus-summary-edit-article
2828 "<" beginning-of-buffer
2830 "\C-c\C-i" gnus-info-find-node
2832 "\C-hk" gnus-article-describe-key
2833 "\C-hc" gnus-article-describe-key-briefly
2835 "\C-d" gnus-article-read-summary-keys
2836 "\M-*" gnus-article-read-summary-keys
2837 "\M-#" gnus-article-read-summary-keys
2838 "\M-^" gnus-article-read-summary-keys
2839 "\M-g" gnus-article-read-summary-keys)
2841 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2844 (unless (lookup-key gnus-article-mode-map key)
2845 (define-key gnus-article-mode-map key
2846 'gnus-article-read-summary-keys)))
2851 (let ((key (car elt)))
2852 (and (> (length key) 0)
2853 (not (eq 'menu-bar (aref key 0)))
2854 (symbolp (lookup-key gnus-summary-mode-map key))
2856 (accessible-keymaps gnus-summary-mode-map))
2860 (push (char-to-string c) keys)
2865 (defvar gnus-article-commands-menu))
2867 (defun gnus-article-make-menu-bar ()
2868 (gnus-turn-off-edit-menu 'article)
2869 (unless (boundp 'gnus-article-article-menu)
2871 gnus-article-article-menu gnus-article-mode-map ""
2873 ["Scroll forwards" gnus-article-goto-next-page t]
2874 ["Scroll backwards" gnus-article-goto-prev-page t]
2875 ["Show summary" gnus-article-show-summary t]
2876 ["Fetch Message-ID at point" gnus-article-refer-article t]
2877 ["Mail to address at point" gnus-article-mail t]
2878 ["Send a bug report" gnus-bug t]))
2881 gnus-article-treatment-menu gnus-article-mode-map ""
2883 ["Hide headers" gnus-article-toggle-headers t]
2884 ["Hide signature" gnus-article-hide-signature t]
2885 ["Hide citation" gnus-article-hide-citation t]
2886 ["Treat overstrike" gnus-article-treat-overstrike t]
2887 ["Remove carriage return" gnus-article-remove-cr t]
2888 ["Decode HZ" gnus-article-decode-HZ t]))
2890 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2892 (when (boundp 'gnus-summary-post-menu)
2893 (define-key gnus-article-mode-map [menu-bar post]
2894 (cons "Post" gnus-summary-post-menu)))
2896 (gnus-run-hooks 'gnus-article-menu-hook))
2898 (when (boundp 'gnus-article-commands-menu)
2899 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
2900 (when (boundp 'gnus-summary-post-menu)
2901 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
2903 (defun gnus-article-mode ()
2904 "Major mode for displaying an article.
2906 All normal editing commands are switched off.
2908 The following commands are available in addition to all summary mode
2910 \\<gnus-article-mode-map>
2911 \\[gnus-article-next-page]\t Scroll the article one page forwards
2912 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2913 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2914 \\[gnus-article-show-summary]\t Display the summary buffer
2915 \\[gnus-article-mail]\t Send a reply to the address near point
2916 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2917 \\[gnus-info-find-node]\t Go to the Gnus info node"
2919 (when (gnus-visual-p 'article-menu 'menu)
2920 (gnus-article-make-menu-bar))
2921 (gnus-simplify-mode-line)
2922 (setq mode-name "Article")
2923 (setq major-mode 'gnus-article-mode)
2924 (make-local-variable 'minor-mode-alist)
2925 (unless (assq 'gnus-show-mime minor-mode-alist)
2926 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2927 (use-local-map gnus-article-mode-map)
2928 (gnus-update-format-specifications nil 'article-mode)
2929 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2930 (make-local-variable 'gnus-page-broken)
2931 (make-local-variable 'gnus-button-marker-list)
2932 (make-local-variable 'gnus-article-current-summary)
2933 (make-local-variable 'gnus-article-mime-handles)
2934 (make-local-variable 'gnus-article-decoded-p)
2935 (make-local-variable 'gnus-article-mime-handle-alist)
2936 (make-local-variable 'gnus-article-wash-types)
2937 (gnus-set-default-directory)
2938 (buffer-disable-undo)
2939 (setq buffer-read-only t)
2940 (set-syntax-table gnus-article-mode-syntax-table)
2941 (gnus-run-hooks 'gnus-article-mode-hook))
2943 (defun gnus-article-setup-buffer ()
2944 "Initialize the article buffer."
2945 (let* ((name (if gnus-single-article-buffer "*Article*"
2946 (concat "*Article " gnus-newsgroup-name "*")))
2948 (progn (string-match "\\*Article" name)
2949 (concat " *Original Article"
2950 (substring name (match-end 0))))))
2951 (setq gnus-article-buffer name)
2952 (setq gnus-original-article-buffer original)
2953 (setq gnus-article-mime-handle-alist nil)
2954 ;; This might be a variable local to the summary buffer.
2955 (unless gnus-single-article-buffer
2957 (set-buffer gnus-summary-buffer)
2958 (setq gnus-article-buffer name)
2959 (setq gnus-original-article-buffer original)
2960 (gnus-set-global-variables)))
2961 (gnus-article-setup-highlight-words)
2962 ;; Init original article buffer.
2964 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2965 (set-buffer-multibyte nil)
2966 (setq major-mode 'gnus-original-article-mode)
2967 (make-local-variable 'gnus-original-article))
2968 (if (get-buffer name)
2971 (buffer-disable-undo)
2972 (setq buffer-read-only t)
2973 (unless (eq major-mode 'gnus-article-mode)
2974 (gnus-article-mode))
2977 (set-buffer (gnus-get-buffer-create name))
2979 (make-local-variable 'gnus-summary-buffer)
2980 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2981 (current-buffer)))))
2983 ;; Set article window start at LINE, where LINE is the number of lines
2984 ;; from the head of the article.
2985 (defun gnus-article-set-window-start (&optional line)
2987 (get-buffer-window gnus-article-buffer t)
2989 (set-buffer gnus-article-buffer)
2990 (goto-char (point-min))
2993 (gnus-message 6 "Moved to bookmark")
2994 (search-forward "\n\n" nil t)
2998 ;;; @@ article filters
3001 (defun gnus-article-display-mime-message ()
3002 "Article display method for MIME message."
3003 ;; called from `gnus-original-article-buffer'.
3004 (let (charset all-headers)
3005 (with-current-buffer gnus-summary-buffer
3006 (setq charset default-mime-charset
3007 all-headers gnus-have-all-headers))
3008 (make-local-variable 'default-mime-charset)
3009 (setq default-mime-charset charset)
3010 (with-current-buffer (get-buffer-create gnus-article-buffer)
3011 (make-local-variable 'default-mime-charset)
3012 (setq default-mime-charset charset))
3013 (mime-display-message mime-message-structure
3014 gnus-article-buffer nil gnus-article-mode-map)
3016 (gnus-article-hide-headers nil -1)))
3017 (run-hooks 'gnus-mime-article-prepare-hook))
3019 (defun gnus-article-display-traditional-message ()
3020 "Article display method for traditional message."
3021 (set-buffer gnus-article-buffer)
3022 (let (buffer-read-only)
3024 (insert-buffer-substring gnus-original-article-buffer)))
3026 (defun gnus-article-make-full-mail-header (&optional number charset)
3027 "Create a new mail header structure in a raw article buffer."
3028 (unless (and number charset)
3029 (save-current-buffer
3030 (set-buffer gnus-summary-buffer)
3032 (setq number (or (cdr gnus-article-current) 0)))
3034 (setq charset (or default-mime-charset 'x-ctext)))))
3035 (goto-char (point-min))
3036 (let ((header-end (if (search-forward "\n\n" nil t)
3038 (goto-char (point-max))))
3039 (chars (- (point-max) (point)))
3040 (lines (count-lines (point) (point-max)))
3041 (default-mime-charset charset)
3043 (narrow-to-region (point-min) header-end)
3044 (setq xref (std11-fetch-field "xref"))
3046 (make-full-mail-header
3048 (std11-fetch-field "subject")
3049 (std11-fetch-field "from")
3050 (std11-fetch-field "date")
3051 (std11-fetch-field "message-id")
3052 (std11-fetch-field "references")
3055 (when xref (concat "Xref: " xref)))
3058 (defun gnus-article-prepare (article &optional all-headers header)
3059 "Prepare ARTICLE in article mode buffer.
3060 ARTICLE should either be an article number or a Message-ID.
3061 If ARTICLE is an id, HEADER should be the article headers.
3062 If ALL-HEADERS is non-nil, no headers are hidden."
3064 ;; Make sure we start in a summary buffer.
3065 (unless (eq major-mode 'gnus-summary-mode)
3066 (set-buffer gnus-summary-buffer))
3067 (setq gnus-summary-buffer (current-buffer))
3068 (let* ((gnus-article (if header (mail-header-number header) article))
3069 (summary-buffer (current-buffer))
3070 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3071 (group gnus-newsgroup-name)
3074 (gnus-article-setup-buffer)
3075 (set-buffer gnus-original-article-buffer)
3076 ;; Deactivate active regions.
3077 (when (and (boundp 'transient-mark-mode)
3078 transient-mark-mode)
3079 (setq mark-active nil))
3080 (if (not (setq result (let ((buffer-read-only nil))
3081 (gnus-request-article-this-buffer
3083 ;; There is no such article.
3085 (when (and (numberp article)
3086 (not (memq article gnus-newsgroup-sparse)))
3087 (setq gnus-article-current
3088 (cons gnus-newsgroup-name article))
3089 (set-buffer gnus-summary-buffer)
3090 (setq gnus-current-article article)
3091 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3093 (gnus-summary-set-agent-mark article)
3094 (message "Message marked for downloading"))
3095 (gnus-summary-mark-article article gnus-canceled-mark)
3096 (unless (memq article gnus-newsgroup-sparse)
3097 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3098 (if (or (eq result 'pseudo)
3099 (eq result 'nneething))
3102 (set-buffer summary-buffer)
3103 (push article gnus-newsgroup-history)
3104 (setq gnus-last-article gnus-current-article
3105 gnus-current-article 0
3106 gnus-current-headers nil
3107 gnus-article-current nil)
3108 (if (eq result 'nneething)
3109 (gnus-configure-windows 'summary)
3110 (gnus-configure-windows 'article))
3111 (gnus-set-global-variables))
3112 (let ((gnus-article-mime-handle-alist-1
3113 gnus-article-mime-handle-alist))
3114 (gnus-set-mode-line 'article)))
3115 ;; The result from the `request' was an actual article -
3116 ;; or at least some text that is now displayed in the
3118 (when (and (numberp article)
3119 (not (eq article gnus-current-article)))
3120 ;; Seems like a new article has been selected.
3121 ;; `gnus-current-article' must be an article number.
3123 (set-buffer summary-buffer)
3124 (push article gnus-newsgroup-history)
3125 (setq gnus-last-article gnus-current-article
3126 gnus-current-article article
3127 gnus-current-headers
3128 (gnus-summary-article-header gnus-current-article)
3129 gnus-article-current
3130 (cons gnus-newsgroup-name gnus-current-article))
3131 (unless (vectorp gnus-current-headers)
3132 (setq gnus-current-headers nil))
3133 (gnus-summary-goto-subject gnus-current-article)
3134 (when (gnus-summary-show-thread)
3135 ;; If the summary buffer really was folded, the
3136 ;; previous goto may not actually have gone to
3137 ;; the right article, but the thread root instead.
3139 (gnus-summary-goto-subject gnus-current-article))
3140 (gnus-run-hooks 'gnus-mark-article-hook)
3141 (gnus-set-mode-line 'summary)
3142 (when (gnus-visual-p 'article-highlight 'highlight)
3143 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3144 ;; Set the global newsgroup variables here.
3145 (gnus-set-global-variables)
3146 (setq gnus-have-all-headers
3147 (or all-headers gnus-show-all-headers))))
3149 (gnus-configure-windows 'article))
3150 (when (or (numberp article)
3152 (gnus-article-prepare-display)
3154 (goto-char (point-min))
3155 (setq gnus-page-broken
3156 (when gnus-break-pages
3157 (gnus-narrow-to-page)
3159 (let ((gnus-article-mime-handle-alist-1
3160 gnus-article-mime-handle-alist))
3161 (gnus-set-mode-line 'article))
3163 (set-window-point (get-buffer-window (current-buffer)) (point))
3164 (gnus-configure-windows 'article)
3167 (defun gnus-article-prepare-mime-display (&optional number)
3168 (goto-char (point-min))
3169 (when (re-search-forward "^[^\t ]+:" nil t)
3170 (goto-char (match-beginning 0)))
3171 (let ((entity (if (eq 1 (point-min))
3172 (get-text-property 1 'mime-view-entity)
3173 (get-text-property (point) 'mime-view-entity)))
3174 last-entity child-entity next type)
3175 (setq child-entity (mime-entity-children entity))
3177 (setq last-entity (nth (1- (length child-entity))
3179 (setq last-entity entity))
3181 (narrow-to-region (point)
3182 (if (search-forward "\n\n" nil t)
3185 (gnus-treat-article 'head)
3186 (put-text-property (point-min) (point-max) 'article-treated-header t)
3187 (goto-char (point-max)))
3188 (while (and (not (eobp)) entity)
3189 (setq next (set-marker
3191 (next-single-property-change (point) 'mime-view-entity
3193 (let ((types (mime-entity-content-type entity)))
3194 (while (eq 'multipart (mime-content-type-primary-type types))
3195 (setq entity (car (mime-entity-children entity))
3196 types (mime-entity-content-type entity)))
3198 (setq type (format "%s/%s"
3199 (mime-content-type-primary-type types)
3200 (mime-content-type-subtype types)))))
3201 (if (string-equal type "message/rfc822")
3204 (let ((children (mime-entity-children entity))
3207 (setq last-children (nth (1- (length children)) children))
3210 (not (eq last-children
3211 (get-text-property next 'mime-view-entity)))
3213 (next-single-property-change next
3215 nil (point-max)))))))
3216 (setq next (next-single-property-change next 'mime-view-entity
3219 (narrow-to-region (point) next)
3220 (gnus-article-prepare-mime-display)
3221 (goto-char (point-max)))
3222 (setq entity (get-text-property (point) 'mime-view-entity)))
3224 (narrow-to-region (point) next)
3225 ;; Kludge. We have to count true number, but for now,
3226 ;; part number is here only to achieve `last'.
3227 (gnus-treat-article nil 1
3228 (if (eq entity last-entity)
3231 (goto-char (point-max)))
3232 (setq entity (get-text-property next 'mime-view-entity))))))
3235 (defun gnus-article-prepare-display ()
3236 "Make the current buffer look like a nice article."
3237 (setq gnus-article-wash-types nil)
3238 (gnus-run-hooks 'gnus-tmp-internal-hook)
3239 (gnus-run-hooks 'gnus-article-prepare-hook)
3241 (let (mime-display-header-hook mime-display-text/plain-hook)
3242 (funcall (if gnus-show-mime
3244 (setq mime-message-structure gnus-current-headers)
3245 (mime-buffer-entity-set-buffer-internal
3246 mime-message-structure
3247 gnus-original-article-buffer)
3248 (mime-entity-set-representation-type-internal
3249 mime-message-structure 'mime-buffer-entity)
3250 (luna-send mime-message-structure
3251 'initialize-instance
3252 mime-message-structure)
3253 gnus-article-display-method-for-mime)
3254 gnus-article-display-method-for-traditional)))
3255 ;; Associate this article with the current summary buffer.
3256 (setq gnus-article-current-summary gnus-summary-buffer)
3257 ;; Call the treatment functions.
3258 (let ((inhibit-read-only t)
3263 (gnus-article-prepare-mime-display)
3264 (narrow-to-region (goto-char (point-min))
3265 (if (search-forward "\n\n" nil t)
3268 (gnus-treat-article 'head)
3269 (put-text-property (point-min) (point-max) 'article-treated-header t)
3270 (goto-char (point-max))
3272 (narrow-to-region (point) (point-max))
3273 (gnus-treat-article nil))
3274 (put-text-property (point-min) (point-max) 'read-only nil)))
3275 ;; Perform the article display hooks. Incidentally, this hook is
3276 ;; an obsolete variable by now.
3277 (gnus-run-hooks 'gnus-article-display-hook))
3279 (defun gnus-article-decode-article-as-default-mime-charset ()
3280 "Decode an article as `default-mime-charset'. It won't work if the
3281 value of the variable `gnus-show-mime' is non-nil."
3282 (unless gnus-show-mime
3283 (decode-mime-charset-region (point-min) (point-max)
3284 (with-current-buffer gnus-summary-buffer
3285 default-mime-charset))))
3288 ;;; Gnus MIME viewing functions
3291 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3292 "The following specs can be used:
3294 %T MIME type, along with additional info
3295 %n The `name' parameter
3296 %d The description, if any
3297 %l The length of the encoded part
3298 %p The part identifier number
3299 %e Dots if the part isn't displayed")
3301 (defvar gnus-mime-button-line-format-alist
3302 '((?t gnus-tmp-type ?s)
3303 (?T gnus-tmp-type-long ?s)
3304 (?n gnus-tmp-name ?s)
3305 (?d gnus-tmp-description ?s)
3307 (?l gnus-tmp-length ?d)
3308 (?e gnus-tmp-dots ?s)))
3310 (defvar gnus-mime-button-commands
3311 '((gnus-article-press-button "\r" "Toggle Display")
3312 (gnus-mime-view-part "v" "View Interactively...")
3313 (gnus-mime-view-part-as-type "t" "View As Type...")
3314 (gnus-mime-save-part "o" "Save...")
3315 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3316 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3317 (gnus-mime-internalize-part "E" "View Internally")
3318 (gnus-mime-externalize-part "e" "View Externally")
3319 (gnus-mime-pipe-part "|" "Pipe To Command...")
3320 (gnus-mime-action-on-part "." "Take action on the part")))
3322 (defun gnus-article-mime-part-status ()
3323 (if gnus-article-mime-handle-alist-1
3324 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
3327 (defvar gnus-mime-button-map
3328 (let ((map (make-sparse-keymap)))
3329 (set-keymap-parent map gnus-article-mode-map)
3330 (define-key map gnus-mouse-2 'gnus-article-push-button)
3331 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3332 (dolist (c gnus-mime-button-commands)
3333 (define-key map (cadr c) (car c)))
3336 (defun gnus-mime-button-menu (event)
3337 "Construct a context-sensitive menu of MIME commands."
3339 (save-window-excursion
3340 (let ((pos (event-start event)))
3341 (select-window (posn-window pos))
3342 (goto-char (posn-point pos))
3343 (gnus-article-check-buffer)
3344 (let ((response (x-popup-menu
3346 ("" ,@(mapcar (lambda (c)
3347 (cons (caddr c) (car c)))
3348 gnus-mime-button-commands))))))
3350 (call-interactively response))))))
3352 (defun gnus-mime-view-all-parts (&optional handles)
3353 "View all the MIME parts."
3355 (save-current-buffer
3356 (set-buffer gnus-article-buffer)
3357 (let ((handles (or handles gnus-article-mime-handles))
3358 (mail-parse-charset gnus-newsgroup-charset)
3359 (mail-parse-ignored-charsets
3360 (save-excursion (set-buffer gnus-summary-buffer)
3361 gnus-newsgroup-ignored-charsets)))
3362 (if (stringp (car handles))
3363 (gnus-mime-view-all-parts (cdr handles))
3364 (mapcar 'mm-display-part handles)))))
3366 (defun gnus-mime-save-part ()
3367 "Save the MIME part under point."
3369 (gnus-article-check-buffer)
3370 (let ((data (get-text-property (point) 'gnus-data)))
3372 (mm-save-part data))))
3374 (defun gnus-mime-pipe-part ()
3375 "Pipe the MIME part under point to a process."
3377 (gnus-article-check-buffer)
3378 (let ((data (get-text-property (point) 'gnus-data)))
3380 (mm-pipe-part data))))
3382 (defun gnus-mime-view-part ()
3383 "Interactively choose a viewing method for the MIME part under point."
3385 (gnus-article-check-buffer)
3386 (let ((data (get-text-property (point) 'gnus-data)))
3388 (mm-interactively-view-part data))))
3390 (defun gnus-mime-view-part-as-type-internal ()
3391 (gnus-article-check-buffer)
3392 (let* ((name (mail-content-type-get
3393 (mm-handle-type (get-text-property (point) 'gnus-data))
3395 (def-type (and name (mm-default-file-encoding name))))
3396 (and def-type (cons def-type 0))))
3398 (defun gnus-mime-view-part-as-type (mime-type)
3399 "Choose a MIME media type, and view the part as such."
3401 (list (completing-read
3402 "View as MIME type: "
3403 (mapcar #'list (mailcap-mime-types))
3405 (gnus-mime-view-part-as-type-internal))))
3406 (gnus-article-check-buffer)
3407 (let ((handle (get-text-property (point) 'gnus-data)))
3409 (gnus-mm-display-part
3410 (mm-make-handle (mm-handle-buffer handle)
3411 (cons mime-type (cdr (mm-handle-type handle)))
3412 (mm-handle-encoding handle)
3413 (mm-handle-undisplayer handle)
3414 (mm-handle-disposition handle)
3415 (mm-handle-description handle)
3416 (mm-handle-cache handle)
3417 (mm-handle-id handle))))))
3419 (defun gnus-mime-copy-part (&optional handle)
3420 "Put the the MIME part under point into a new buffer."
3422 (gnus-article-check-buffer)
3423 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3424 (contents (and handle (mm-get-part handle)))
3426 (file-name-nondirectory
3428 (mail-content-type-get (mm-handle-type handle) 'name)
3429 (mail-content-type-get (mm-handle-type handle)
3432 (buffer (and base (generate-new-buffer base))))
3434 (switch-to-buffer buffer)
3436 ;; We do it this way to make `normal-mode' set the appropriate mode.
3439 (setq buffer-file-name (expand-file-name base))
3441 (setq buffer-file-name nil))
3442 (goto-char (point-min)))))
3444 (defun gnus-mime-inline-part (&optional handle arg)
3445 "Insert the MIME part under point into the current buffer."
3446 (interactive (list nil current-prefix-arg))
3447 (gnus-article-check-buffer)
3448 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3453 (if (and (not arg) (mm-handle-undisplayer handle))
3454 (mm-remove-part handle)
3455 (setq contents (mm-get-part handle))
3458 (setq charset (or (mail-content-type-get
3459 (mm-handle-type handle) 'charset)
3460 gnus-newsgroup-charset)))
3462 (if (mm-handle-undisplayer handle)
3463 (mm-remove-part handle))
3466 gnus-summary-show-article-charset-alist))
3467 (read-coding-system "Charset: ")))))
3469 (mm-insert-inline handle
3471 (setq charset (mm-charset-to-coding-system
3473 (not (eq charset 'ascii)))
3474 (mm-decode-coding-string contents charset)
3478 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3479 "Insert the MIME part under point into the current buffer."
3480 (interactive (list nil current-prefix-arg))
3481 (gnus-article-check-buffer)
3482 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3487 (if (mm-handle-undisplayer handle)
3488 (mm-remove-part handle))
3489 (let ((gnus-newsgroup-charset
3491 gnus-summary-show-article-charset-alist))
3492 (read-coding-system "Charset: ")))
3493 (gnus-newsgroup-ignored-charsets 'gnus-all))
3494 (gnus-article-press-button)))))
3496 (defun gnus-mime-externalize-part (&optional handle)
3497 "View the MIME part under point with an external viewer."
3499 (gnus-article-check-buffer)
3500 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3501 (mm-user-display-methods nil)
3502 (mm-inlined-types nil)
3503 (mail-parse-charset gnus-newsgroup-charset)
3504 (mail-parse-ignored-charsets
3505 (save-excursion (set-buffer gnus-summary-buffer)
3506 gnus-newsgroup-ignored-charsets)))
3508 (if (mm-handle-undisplayer handle)
3509 (mm-remove-part handle)
3510 (mm-display-part handle)))))
3512 (defun gnus-mime-internalize-part (&optional handle)
3513 "View the MIME part under point with an internal viewer.
3514 In no internal viewer is available, use an external viewer."
3516 (gnus-article-check-buffer)
3517 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3518 (mm-inlined-types '(".*"))
3519 (mm-inline-large-images t)
3520 (mail-parse-charset gnus-newsgroup-charset)
3521 (mail-parse-ignored-charsets
3522 (save-excursion (set-buffer gnus-summary-buffer)
3523 gnus-newsgroup-ignored-charsets)))
3525 (if (mm-handle-undisplayer handle)
3526 (mm-remove-part handle)
3527 (mm-display-part handle)))))
3529 (defun gnus-mime-action-on-part (&optional action)
3530 "Do something with the MIME attachment at \(point\)."
3532 (list (completing-read "Action: " gnus-mime-action-alist)))
3533 (gnus-article-check-buffer)
3534 (let ((action-pair (assoc action gnus-mime-action-alist)))
3536 (funcall (cdr action-pair)))))
3538 (defun gnus-article-part-wrapper (n function)
3539 (save-current-buffer
3540 (set-buffer gnus-article-buffer)
3541 (when (> n (length gnus-article-mime-handle-alist))
3542 (error "No such part"))
3543 (gnus-article-goto-part n)
3544 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3545 (funcall function handle))))
3547 (defun gnus-article-pipe-part (n)
3548 "Pipe MIME part N, which is the numerical prefix."
3550 (gnus-article-part-wrapper n 'mm-pipe-part))
3552 (defun gnus-article-save-part (n)
3553 "Save MIME part N, which is the numerical prefix."
3555 (gnus-article-part-wrapper n 'mm-save-part))
3557 (defun gnus-article-interactively-view-part (n)
3558 "View MIME part N interactively, which is the numerical prefix."
3560 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3562 (defun gnus-article-copy-part (n)
3563 "Copy MIME part N, which is the numerical prefix."
3565 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3567 (defun gnus-article-externalize-part (n)
3568 "View MIME part N externally, which is the numerical prefix."
3570 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3572 (defun gnus-article-inline-part (n)
3573 "Inline MIME part N, which is the numerical prefix."
3575 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3577 (defun gnus-article-mime-match-handle-first (condition)
3579 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3580 (while (setq ihandle (pop alist))
3582 ((functionp condition)
3583 (funcall condition (cdr ihandle)))
3584 ((eq condition 'undisplayed)
3585 (not (or (mm-handle-undisplayer (cdr ihandle))
3586 (equal (mm-handle-media-type (cdr ihandle))
3587 "multipart/alternative"))))
3588 ((eq condition 'undisplayed-alternative)
3589 (not (mm-handle-undisplayer (cdr ihandle))))
3591 (gnus-article-goto-part (car ihandle))
3592 (or (not n) (< (car ihandle) n)))
3593 (setq n (car ihandle))))
3597 (defun gnus-article-view-part (&optional n)
3598 "View MIME part N, which is the numerical prefix."
3600 (save-current-buffer
3601 (set-buffer gnus-article-buffer)
3602 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3603 gnus-article-mime-match-handle-function)))
3604 (when (> n (length gnus-article-mime-handle-alist))
3605 (error "No such part"))
3606 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3607 (when (gnus-article-goto-part n)
3608 (if (equal (car handle) "multipart/alternative")
3609 (gnus-article-press-button)
3610 (when (eq (gnus-mm-display-part handle) 'internal)
3611 (gnus-set-window-start)))))))
3613 (defsubst gnus-article-mime-total-parts ()
3614 (if (bufferp (car gnus-article-mime-handles))
3616 (1- (length gnus-article-mime-handles))))
3618 (defun gnus-mm-display-part (handle)
3619 "Display HANDLE and fix MIME button."
3620 (let ((id (get-text-property (point) 'gnus-part))
3625 (let ((window (selected-window))
3626 (mail-parse-charset gnus-newsgroup-charset)
3627 (mail-parse-ignored-charsets
3628 (save-excursion (set-buffer gnus-summary-buffer)
3629 gnus-newsgroup-ignored-charsets)))
3632 (let ((win (get-buffer-window (current-buffer) t))
3635 (select-window win))
3638 (if (mm-handle-displayed-p handle)
3639 ;; This will remove the part.
3640 (mm-display-part handle)
3642 (narrow-to-region (point) (1+ (point)))
3643 (mm-display-part handle)
3644 ;; We narrow to the part itself and
3645 ;; then call the treatment functions.
3646 (goto-char (point-min))
3648 (narrow-to-region (point) (point-max))
3651 (gnus-article-mime-total-parts)
3652 (mm-handle-media-type handle)))))
3653 (select-window window))))
3655 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3656 (gnus-insert-mime-button
3657 handle id (list (mm-handle-displayed-p handle)))
3658 (goto-char point))))
3660 (defun gnus-article-goto-part (n)
3661 "Go to MIME part N."
3662 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3664 (goto-char point))))
3666 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3667 (let ((gnus-tmp-name
3668 (or (mail-content-type-get (mm-handle-type handle)
3670 (mail-content-type-get (mm-handle-disposition handle)
3673 (gnus-tmp-type (mm-handle-media-type handle))
3674 (gnus-tmp-description
3675 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3678 (if (if displayed (car displayed)
3679 (mm-handle-displayed-p handle))
3681 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3683 gnus-tmp-type-long b e)
3684 (when (string-match ".*/" gnus-tmp-name)
3685 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3686 (setq gnus-tmp-type-long (concat gnus-tmp-type
3687 (and (not (equal gnus-tmp-name ""))
3688 (concat "; " gnus-tmp-name))))
3689 (or (equal gnus-tmp-description "")
3690 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3695 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3696 `(local-map ,gnus-mime-button-map
3697 keymap ,gnus-mime-button-map
3698 gnus-callback gnus-mm-display-part
3699 gnus-part ,gnus-tmp-id
3700 article-type annotation
3703 (widget-convert-button
3706 :action 'gnus-widget-press-button
3707 :button-keymap gnus-mime-button-map
3709 (lambda (widget/window &optional overlay pos)
3710 ;; Needed to properly clear the message due to a bug in
3711 ;; wid-edit (XEmacs only).
3712 (if (boundp 'help-echo-owns-message)
3713 (setq help-echo-owns-message t))
3715 "%S: %s the MIME part; %S: more options"
3716 (aref gnus-mouse-2 0)
3717 ;; XEmacs will get a single widget arg; Emacs 21 will get
3718 ;; window, overlay, position.
3719 (if (mm-handle-displayed-p
3721 (with-current-buffer (gnus-overlay-buffer overlay)
3722 (widget-get (widget-at (gnus-overlay-start overlay))
3724 (widget-get widget/window :mime-handle)))
3726 (aref gnus-down-mouse-3 0))))))
3728 (defun gnus-widget-press-button (elems el)
3729 (goto-char (widget-get elems :from))
3730 (gnus-article-press-button))
3732 (defvar gnus-displaying-mime nil)
3734 (defun gnus-display-mime (&optional ihandles)
3735 "Display the MIME parts."
3737 (save-selected-window
3738 (let ((window (get-buffer-window gnus-article-buffer))
3741 (select-window window)
3742 ;; We have to do this since selecting the window
3743 ;; may change the point. So we set the window point.
3744 (set-window-point window point)))
3745 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3746 buffer-read-only handle name type b e display)
3747 (when (and (not ihandles)
3748 (not gnus-displaying-mime))
3749 ;; Top-level call; we clean up.
3750 (when gnus-article-mime-handles
3751 (mm-destroy-parts gnus-article-mime-handles)
3752 (setq gnus-article-mime-handle-alist nil));; A trick.
3753 (setq gnus-article-mime-handles handles)
3754 ;; We allow users to glean info from the handles.
3755 (when gnus-article-mime-part-function
3756 (gnus-mime-part-function handles)))
3758 (or (not (stringp (car handles)))
3761 (when (and (not ihandles)
3762 (not gnus-displaying-mime))
3763 ;; Clean up for mime parts.
3765 (delete-region (point) (point-max)))
3766 (let ((gnus-displaying-mime t))
3767 (gnus-mime-display-part handles)))
3770 (narrow-to-region (point) (point-max))
3771 (gnus-treat-article nil 1 1)
3774 ;; Highlight the headers.
3778 (narrow-to-region (point-min) (point))
3779 (gnus-treat-article 'head))))))))
3781 (defvar gnus-mime-display-multipart-as-mixed nil)
3783 (defun gnus-mime-display-part (handle)
3786 ((not (stringp (car handle)))
3787 (gnus-mime-display-single handle))
3788 ;; User-defined multipart
3789 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3790 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3792 ;; multipart/alternative
3793 ((and (equal (car handle) "multipart/alternative")
3794 (not gnus-mime-display-multipart-as-mixed))
3795 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3796 (push (cons id handle) gnus-article-mime-handle-alist)
3797 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3798 ;; multipart/related
3799 ((and (equal (car handle) "multipart/related")
3800 (not gnus-mime-display-multipart-as-mixed))
3801 ;;;!!!We should find the start part, but we just default
3802 ;;;!!!to the first part.
3803 (gnus-mime-display-part (cadr handle)))
3804 ;; Other multiparts are handled like multipart/mixed.
3806 (gnus-mime-display-mixed (cdr handle)))))
3808 (defun gnus-mime-part-function (handles)
3809 (if (stringp (car handles))
3810 (mapcar 'gnus-mime-part-function (cdr handles))
3811 (funcall gnus-article-mime-part-function handles)))
3813 (defun gnus-mime-display-mixed (handles)
3814 (mapcar 'gnus-mime-display-part handles))
3816 (defun gnus-mime-display-single (handle)
3817 (let ((type (mm-handle-media-type handle))
3818 (ignored gnus-ignored-mime-types)
3825 (when (string-match (pop ignored) type)
3826 (throw 'ignored nil)))
3827 (if (and (setq not-attachment
3828 (and (not (mm-inline-override-p handle))
3829 (or (not (mm-handle-disposition handle))
3830 (equal (car (mm-handle-disposition handle))
3832 (mm-attachment-override-p handle))))
3833 (mm-automatic-display-p handle)
3834 (or (mm-inlined-p handle)
3835 (mm-automatic-external-display-p type)))
3837 (when (equal (mm-handle-media-supertype handle) "text")
3839 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3841 (push (cons id handle) gnus-article-mime-handle-alist)
3842 (when (or (not display)
3843 (not (gnus-unbuttonized-mime-type-p type)))
3844 ;(gnus-article-insert-newline)
3845 (gnus-insert-mime-button
3846 handle id (list (or display (and not-attachment text))))
3847 (gnus-article-insert-newline)
3848 ;(gnus-article-insert-newline)
3849 ;; Remember modify the number of forward lines.
3857 (let ((mail-parse-charset gnus-newsgroup-charset)
3858 (mail-parse-ignored-charsets
3859 (save-excursion (condition-case ()
3860 (set-buffer gnus-summary-buffer)
3862 gnus-newsgroup-ignored-charsets)))
3863 (mm-display-part handle t))
3864 (goto-char (point-max)))
3865 ((and text not-attachment)
3869 (gnus-article-insert-newline)
3870 (mm-insert-inline handle (mm-get-part handle))
3871 (goto-char (point-max))))
3875 (narrow-to-region beg (point))
3878 (gnus-article-mime-total-parts)
3879 (mm-handle-media-type handle)))))))))
3881 (defun gnus-unbuttonized-mime-type-p (type)
3882 "Say whether TYPE is to be unbuttonized."
3883 (unless gnus-inhibit-mime-unbuttonizing
3885 (let ((types gnus-unbuttonized-mime-types))
3887 (when (string-match (pop types) type)
3888 (throw 'found t)))))))
3890 (defun gnus-article-insert-newline ()
3891 "Insert a newline, but mark it as undeletable."
3892 (gnus-put-text-property
3893 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3895 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3896 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3899 handle buffer-read-only from props begend not-pref)
3900 (save-window-excursion
3903 (narrow-to-region (car ibegend)
3906 (goto-char (car ibegend))
3909 (delete-region (point-min) (point-max))
3910 (mm-remove-parts handles))
3911 (setq begend (list (point-marker)))
3913 (unless (setq not-pref (cadr (member preferred ihandles)))
3914 (setq not-pref (car ihandles)))
3917 (not (gnus-unbuttonized-mime-type-p
3918 "multipart/alternative")))
3919 (gnus-add-text-properties
3922 (insert (format "%d. " id))
3926 (unless ,(not ibegend)
3927 (setq gnus-article-mime-handle-alist
3928 ',gnus-article-mime-handle-alist))
3929 (gnus-mime-display-alternative
3930 ',ihandles ',not-pref ',begend ,id))
3931 local-map ,gnus-mime-button-map
3932 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3933 face ,gnus-article-button-face
3934 keymap ,gnus-mime-button-map
3937 (widget-convert-button 'link from (point)
3938 :action 'gnus-widget-press-button
3939 :button-keymap gnus-widget-button-keymap)
3941 (while (setq handle (pop handles))
3942 (gnus-add-text-properties
3945 (insert (format "(%c) %-18s"
3946 (if (equal handle preferred) ?* ? )
3947 (mm-handle-media-type handle)))
3951 (unless ,(not ibegend)
3952 (setq gnus-article-mime-handle-alist
3953 ',gnus-article-mime-handle-alist))
3954 (gnus-mime-display-alternative
3955 ',ihandles ',handle ',begend ,id))
3956 local-map ,gnus-mime-button-map
3957 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3958 face ,gnus-article-button-face
3959 keymap ,gnus-mime-button-map
3962 (widget-convert-button 'link from (point)
3963 :action 'gnus-widget-press-button
3964 :button-keymap gnus-widget-button-keymap)
3968 (if (stringp (car preferred))
3969 (gnus-display-mime preferred)
3970 (let ((mail-parse-charset gnus-newsgroup-charset)
3971 (mail-parse-ignored-charsets
3972 (save-excursion (set-buffer gnus-summary-buffer)
3973 gnus-newsgroup-ignored-charsets)))
3974 (mm-display-part preferred)
3978 (narrow-to-region (car begend) (point-max))
3980 nil (length gnus-article-mime-handle-alist)
3981 (gnus-article-mime-total-parts)
3982 (mm-handle-media-type handle))))))
3983 (goto-char (point-max))
3984 (setcdr begend (point-marker)))))
3986 (goto-char point))))
3988 (defun gnus-article-wash-status ()
3989 "Return a string which display status of article washing."
3991 (set-buffer gnus-article-buffer)
3992 (let ((cite (memq 'cite gnus-article-wash-types))
3993 (headers (memq 'headers gnus-article-wash-types))
3994 (boring (memq 'boring-headers gnus-article-wash-types))
3995 (pgp (memq 'pgp gnus-article-wash-types))
3996 (pem (memq 'pem gnus-article-wash-types))
3997 (signature (memq 'signature gnus-article-wash-types))
3998 (overstrike (memq 'overstrike gnus-article-wash-types))
3999 (emphasis (memq 'emphasis gnus-article-wash-types)))
4000 (format "%c%c%c%c%c%c%c"
4002 (if (or headers boring) ?h ? )
4003 (if (or pgp pem) ?p ? )
4004 (if signature ?s ? )
4005 (if overstrike ?o ? )
4006 (if gnus-show-mime ?m ? )
4007 (if emphasis ?e ? )))))
4009 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4011 (defun gnus-article-maybe-hide-headers ()
4012 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4013 Provided for backwards compatibility."
4014 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4015 (not (save-excursion (set-buffer gnus-summary-buffer)
4016 gnus-have-all-headers)))
4017 (not gnus-inhibit-hiding))
4018 (gnus-article-hide-headers)))
4022 (defun gnus-output-to-file (file-name)
4023 "Append the current article to a file named FILE-NAME."
4024 (let ((artbuf (current-buffer)))
4026 (insert-buffer-substring artbuf)
4027 ;; Append newline at end of the buffer as separator, and then
4029 (goto-char (point-max))
4031 (write-region-as-binary (point-min) (point-max) file-name 'append)
4034 (defun gnus-narrow-to-page (&optional arg)
4035 "Narrow the article buffer to a page.
4036 If given a numerical ARG, move forward ARG pages."
4038 (setq arg (if arg (prefix-numeric-value arg) 0))
4040 (set-buffer gnus-article-buffer)
4041 (goto-char (point-min))
4043 ;; Remove any old next/prev buttons.
4044 (when (gnus-visual-p 'page-marker)
4045 (let ((buffer-read-only nil))
4046 (gnus-remove-text-with-property 'gnus-prev)
4047 (gnus-remove-text-with-property 'gnus-next)))
4050 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4052 (re-search-forward page-delimiter nil 'move arg)))
4053 (goto-char (match-end 0)))
4056 (if (re-search-forward page-delimiter nil 'move)
4059 (when (and (gnus-visual-p 'page-marker)
4060 (not (= (point-min) 1)))
4062 (goto-char (point-min))
4063 (gnus-insert-prev-page-button)))
4064 (when (and (gnus-visual-p 'page-marker)
4065 (< (+ (point-max) 2) (buffer-size)))
4067 (goto-char (point-max))
4068 (gnus-insert-next-page-button)))))
4070 ;; Article mode commands
4072 (defun gnus-article-goto-next-page ()
4073 "Show the next page of the article."
4075 (when (gnus-article-next-page)
4076 (goto-char (point-min))
4077 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4079 (defun gnus-article-goto-prev-page ()
4080 "Show the next page of the article."
4082 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4083 (gnus-article-prev-page nil)))
4085 (defun gnus-article-next-page (&optional lines)
4086 "Show the next page of the current article.
4087 If end of article, return non-nil. Otherwise return nil.
4088 Argument LINES specifies lines to be scrolled up."
4090 (let ((start (window-start))
4091 end-of-buffer end-of-page)
4093 (move-to-window-line -1)
4094 (if (<= (point) start)
4097 (setq start (point)))
4100 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4101 (and (pos-visible-in-window-p)
4102 (setq end-of-buffer t)))
4104 (setq end-of-page t)))
4106 (move-to-window-line lines)
4107 (unless (search-backward "\n\n" nil t)
4108 (setq start (point)))))
4109 (cond (end-of-buffer t)
4111 (gnus-narrow-to-page 1)
4115 (set-window-start (selected-window) start)
4116 (let (window-pixel-scroll-increment)
4120 (defun gnus-article-prev-page (&optional lines)
4121 "Show previous page of current article.
4122 Argument LINES specifies lines to be scrolled down."
4124 (let (beginning-of-buffer beginning-of-page)
4126 (move-to-window-line 0)
4127 (cond ((eq 1 (point))
4128 (setq beginning-of-buffer t))
4130 (setq beginning-of-page t))))
4131 (cond (beginning-of-buffer)
4133 (gnus-narrow-to-page -1))
4136 (let (window-pixel-scroll-increment)
4137 (scroll-down lines))
4138 (beginning-of-buffer
4139 (goto-char (point-min))))))))
4141 (defun gnus-article-refer-article ()
4142 "Read article specified by message-id around point."
4144 (let ((point (point)))
4145 (search-forward ">" nil t) ;Move point to end of "<....>".
4146 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4147 (let ((message-id (match-string 1)))
4149 (set-buffer gnus-summary-buffer)
4150 (gnus-summary-refer-article message-id))
4152 (error "No references around point"))))
4154 (defun gnus-article-show-summary ()
4155 "Reconfigure windows to show summary buffer."
4157 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4158 (error "There is no summary buffer for this article buffer")
4159 (gnus-article-set-globals)
4160 (gnus-configure-windows 'article)
4161 (gnus-summary-goto-subject gnus-current-article)
4162 (gnus-summary-position-point)))
4164 (defun gnus-article-describe-briefly ()
4165 "Describe article mode commands briefly."
4167 (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")))
4169 (defun gnus-article-summary-command ()
4170 "Execute the last keystroke in the summary buffer."
4172 (let ((obuf (current-buffer))
4173 (owin (current-window-configuration))
4175 (switch-to-buffer gnus-article-current-summary 'norecord)
4176 (setq func (lookup-key (current-local-map) (this-command-keys)))
4177 (call-interactively func)
4179 (set-window-configuration owin)
4180 (set-window-point (get-buffer-window (current-buffer)) (point))))
4182 (defun gnus-article-summary-command-nosave ()
4183 "Execute the last keystroke in the summary buffer."
4186 (pop-to-buffer gnus-article-current-summary 'norecord)
4187 (setq func (lookup-key (current-local-map) (this-command-keys)))
4188 (call-interactively func)))
4190 (defun gnus-article-check-buffer ()
4191 "Beep if not in an article buffer."
4192 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4193 (error "Command invoked outside of a Gnus article buffer")))
4195 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4196 "Read a summary buffer key sequence and execute it from the article buffer."
4198 (gnus-article-check-buffer)
4200 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4201 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4202 "=" "^" "\M-^" "|"))
4208 '("n" "Gn" "p" "Gp"))
4211 (set-buffer gnus-article-current-summary)
4212 (let (gnus-pick-mode)
4213 (push (or key last-command-event) unread-command-events)
4214 (setq keys (static-if (featurep 'xemacs)
4215 (events-to-keys (read-key-sequence nil))
4216 (read-key-sequence nil)))))
4219 (if (or (member keys nosaves)
4220 (member keys nosave-but-article)
4221 (member keys nosave-in-article))
4223 (save-window-excursion
4224 (pop-to-buffer gnus-article-current-summary 'norecord)
4225 ;; We disable the pick minor mode commands.
4226 (let (gnus-pick-mode)
4227 (setq func (lookup-key (current-local-map) keys))))
4231 (unless (member keys nosave-in-article)
4232 (set-buffer gnus-article-current-summary))
4233 (call-interactively func)
4234 (setq new-sum-point (point)))
4235 (when (member keys nosave-but-article)
4236 (pop-to-buffer gnus-article-buffer 'norecord)))
4237 ;; These commands should restore window configuration.
4238 (let ((obuf (current-buffer))
4239 (owin (current-window-configuration))
4241 (summary gnus-article-current-summary)
4242 func in-buffer selected)
4243 (if not-restore-window
4244 (pop-to-buffer summary 'norecord)
4245 (switch-to-buffer summary 'norecord))
4246 (setq in-buffer (current-buffer))
4247 ;; We disable the pick minor mode commands.
4248 (if (and (setq func (let (gnus-pick-mode)
4249 (lookup-key (current-local-map) keys)))
4252 (call-interactively func)
4253 (setq new-sum-point (point))
4254 (when (eq in-buffer (current-buffer))
4255 (setq selected (gnus-summary-select-article))
4257 (unless not-restore-window
4258 (set-window-configuration owin))
4259 (when (eq selected 'old)
4261 (set-window-start (get-buffer-window (current-buffer))
4263 (set-window-point (get-buffer-window (current-buffer))
4265 (let ((win (get-buffer-window gnus-article-current-summary)))
4267 (set-window-point win new-sum-point)))) )
4268 (switch-to-buffer gnus-article-buffer)
4271 (defun gnus-article-describe-key (key)
4272 "Display documentation of the function invoked by KEY. KEY is a string."
4273 (interactive "kDescribe key: ")
4274 (gnus-article-check-buffer)
4275 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4277 (set-buffer gnus-article-current-summary)
4278 (let (gnus-pick-mode)
4279 (push (elt key 0) unread-command-events)
4280 (setq key (if (featurep 'xemacs)
4281 (events-to-keys (read-key-sequence "Describe key: "))
4282 (read-key-sequence "Describe key: "))))
4284 (describe-key key)))
4286 (defun gnus-article-describe-key-briefly (key &optional insert)
4287 "Display documentation of the function invoked by KEY. KEY is a string."
4288 (interactive "kDescribe key: \nP")
4289 (gnus-article-check-buffer)
4290 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4292 (set-buffer gnus-article-current-summary)
4293 (let (gnus-pick-mode)
4294 (push (elt key 0) unread-command-events)
4295 (setq key (if (featurep 'xemacs)
4296 (events-to-keys (read-key-sequence "Describe key: "))
4297 (read-key-sequence "Describe key: "))))
4298 (describe-key-briefly key insert))
4299 (describe-key-briefly key insert)))
4301 (defun gnus-article-hide (&optional arg force)
4302 "Hide all the gruft in the current article.
4303 This means that PGP stuff, signatures, cited text and (some)
4304 headers will be hidden.
4305 If given a prefix, show the hidden text instead."
4306 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4307 (gnus-article-hide-headers arg)
4308 (gnus-article-hide-list-identifiers arg)
4309 (gnus-article-hide-pgp arg)
4310 (gnus-article-hide-citation-maybe arg force)
4311 (gnus-article-hide-signature arg))
4313 (defun gnus-article-maybe-highlight ()
4314 "Do some article highlighting if article highlighting is requested."
4315 (when (gnus-visual-p 'article-highlight 'highlight)
4316 (gnus-article-highlight-some)))
4318 (defun gnus-check-group-server ()
4319 ;; Make sure the connection to the server is alive.
4320 (unless (gnus-server-opened
4321 (gnus-find-method-for-group gnus-newsgroup-name))
4322 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4323 (gnus-request-group gnus-newsgroup-name t)))
4325 (defun gnus-request-article-this-buffer (article group)
4326 "Get an article and insert it into this buffer."
4327 (let (do-update-line sparse-header)
4331 (gnus-kill-all-overlays)
4332 (setq group (or group gnus-newsgroup-name))
4334 ;; Using `gnus-request-article' directly will insert the article into
4335 ;; `nntp-server-buffer' - so we'll save some time by not having to
4336 ;; copy it from the server buffer into the article buffer.
4338 ;; We only request an article by message-id when we do not have the
4339 ;; headers for it, so we'll have to get those.
4340 (when (stringp article)
4341 (gnus-read-header article))
4343 ;; If the article number is negative, that means that this article
4344 ;; doesn't belong in this newsgroup (possibly), so we find its
4345 ;; message-id and request it by id instead of number.
4346 (when (and (numberp article)
4348 (get-buffer gnus-summary-buffer)
4349 (gnus-buffer-exists-p gnus-summary-buffer))
4351 (set-buffer gnus-summary-buffer)
4352 (let ((header (gnus-summary-article-header article)))
4355 ((memq article gnus-newsgroup-sparse)
4356 ;; This is a sparse gap article.
4357 (setq do-update-line article)
4358 (setq article (mail-header-id header))
4359 (setq sparse-header (gnus-read-header article))
4360 (setq gnus-newsgroup-sparse
4361 (delq article gnus-newsgroup-sparse)))
4363 ;; It's a real article.
4364 (setq article (mail-header-id header)))
4366 ;; It is an extracted pseudo-article.
4367 (setq article 'pseudo)
4368 (gnus-request-pseudo-article header))))
4370 (let ((method (gnus-find-method-for-group
4371 gnus-newsgroup-name)))
4372 (when (and (eq (car method) 'nneething)
4374 (let ((dir (expand-file-name
4375 (mail-header-subject header)
4376 (file-name-as-directory
4377 (or (cadr (assq 'nneething-address method))
4379 (when (file-directory-p dir)
4380 (setq article 'nneething)
4381 (gnus-group-enter-directory dir))))))))
4384 ;; Refuse to select canceled articles.
4385 ((and (numberp article)
4387 (get-buffer gnus-summary-buffer)
4388 (gnus-buffer-exists-p gnus-summary-buffer)
4389 (eq (cdr (save-excursion
4390 (set-buffer gnus-summary-buffer)
4391 (assq article gnus-newsgroup-reads)))
4392 gnus-canceled-mark))
4394 ;; Check the backlog.
4395 ((and gnus-keep-backlog
4396 (gnus-backlog-request-article group article (current-buffer)))
4398 ;; Check asynchronous pre-fetch.
4399 ((gnus-async-request-fetched-article group article (current-buffer))
4400 (gnus-async-prefetch-next group article gnus-summary-buffer)
4401 (when (and (numberp article) gnus-keep-backlog)
4402 (gnus-backlog-enter-article group article (current-buffer)))
4405 ((and gnus-use-cache
4407 (gnus-cache-request-article article group))
4409 ;; Get the article and put into the article buffer.
4410 ((or (stringp article)
4412 (let ((gnus-override-method gnus-override-method)
4413 (methods (and (stringp article)
4414 gnus-refer-article-method))
4416 (buffer-read-only nil))
4417 (if (or (not (listp methods))
4418 (and (symbolp (car methods))
4419 (assq (car methods) nnoo-definition-alist)))
4420 (setq methods (list methods)))
4421 (when (and (null gnus-override-method)
4423 (setq gnus-override-method (pop methods)))
4425 (when (eq gnus-override-method 'current)
4426 (setq gnus-override-method gnus-current-select-method))
4428 (gnus-kill-all-overlays)
4429 (let ((gnus-newsgroup-name group))
4430 (gnus-check-group-server))
4431 (when (gnus-request-article article group (current-buffer))
4432 (when (numberp article)
4433 (gnus-async-prefetch-next group article
4434 gnus-summary-buffer)
4435 (when gnus-keep-backlog
4436 (gnus-backlog-enter-article
4437 group article (current-buffer))))
4438 (setq result 'article))
4441 (setq gnus-override-method (pop methods))
4442 (setq result 'done))))
4443 (and (eq result 'article) 'article)))
4447 ;; Associate this article with the current summary buffer.
4448 (setq gnus-article-current-summary gnus-summary-buffer)
4450 ;; Take the article from the original article buffer
4451 ;; and place it in the buffer it's supposed to be in.
4452 (when (and (get-buffer gnus-article-buffer)
4453 (equal (buffer-name (current-buffer))
4454 (buffer-name (get-buffer gnus-article-buffer))))
4456 (if (get-buffer gnus-original-article-buffer)
4457 (set-buffer gnus-original-article-buffer)
4458 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4459 (set-buffer-multibyte nil)
4460 (buffer-disable-undo)
4461 (setq major-mode 'gnus-original-article-mode)
4462 (setq buffer-read-only t))
4463 (let (buffer-read-only)
4465 (insert-buffer-substring gnus-article-buffer))
4466 (setq gnus-original-article (cons group article)))
4469 (run-hooks 'gnus-article-decode-hook)
4470 ;; Mark article as decoded or not.
4471 (setq gnus-article-decoded-p gnus-article-decode-hook))
4473 ;; Update sparse articles.
4474 (when (and do-update-line
4475 (or (numberp article)
4477 (let ((buf (current-buffer)))
4478 (set-buffer gnus-summary-buffer)
4479 (gnus-summary-update-article do-update-line sparse-header)
4480 (gnus-summary-goto-subject do-update-line nil t)
4481 (set-window-point (get-buffer-window (current-buffer) t)
4483 (set-buffer buf))))))
4489 (defcustom gnus-article-edit-mode-hook nil
4490 "Hook run in article edit mode buffers."
4491 :group 'gnus-article-various
4494 (defcustom gnus-article-edit-article-setup-function
4495 'gnus-article-mime-edit-article-setup
4496 "Function called to setup an editing article buffer."
4497 :group 'gnus-article-various
4500 (defvar gnus-article-edit-done-function nil)
4502 (defvar gnus-article-edit-mode-map nil)
4504 ;; Should we be using derived.el for this?
4505 (unless gnus-article-edit-mode-map
4506 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4507 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4509 (gnus-define-keys gnus-article-edit-mode-map
4510 "\C-c\C-c" gnus-article-edit-done
4511 "\C-c\C-k" gnus-article-edit-exit)
4513 (gnus-define-keys (gnus-article-edit-wash-map
4514 "\C-c\C-w" gnus-article-edit-mode-map)
4515 "f" gnus-article-edit-full-stops))
4517 (defun gnus-article-edit-mode ()
4518 "Major mode for editing articles.
4519 This is an extended text-mode.
4521 \\{gnus-article-edit-mode-map}"
4523 (setq major-mode 'gnus-article-edit-mode)
4524 (setq mode-name "Article Edit")
4525 (use-local-map gnus-article-edit-mode-map)
4526 (make-local-variable 'gnus-article-edit-done-function)
4527 (make-local-variable 'gnus-prev-winconf)
4528 (setq buffer-read-only nil)
4529 (buffer-enable-undo)
4531 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4533 (defun gnus-article-edit (&optional force)
4534 "Edit the current article.
4535 This will have permanent effect only in mail groups.
4536 If FORCE is non-nil, allow editing of articles even in read-only
4539 (when (and (not force)
4540 (gnus-group-read-only-p))
4541 (error "The current newsgroup does not support article editing"))
4542 (gnus-article-date-original)
4543 (gnus-article-edit-article
4545 `(lambda (no-highlight)
4547 (gnus-summary-edit-article-done
4548 ,(or (mail-header-references gnus-current-headers) "")
4549 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4551 (defun gnus-article-edit-article (start-func exit-func)
4552 "Start editing the contents of the current article buffer."
4553 (let ((winconf (current-window-configuration)))
4554 (set-buffer gnus-article-buffer)
4555 (gnus-article-edit-mode)
4556 (funcall start-func)
4557 (gnus-configure-windows 'edit-article)
4558 (setq gnus-article-edit-done-function exit-func)
4559 (setq gnus-prev-winconf winconf)
4560 (when gnus-article-edit-article-setup-function
4561 (funcall gnus-article-edit-article-setup-function))
4562 (gnus-message 6 "C-c C-c to end edits")))
4564 (defun gnus-article-edit-done (&optional arg)
4565 "Update the article edits and exit."
4567 (let ((func gnus-article-edit-done-function)
4568 (buf (current-buffer))
4569 (start (window-start)))
4570 (remove-hook 'gnus-article-mode-hook
4571 'gnus-article-mime-edit-article-unwind)
4572 (gnus-article-edit-exit)
4575 (let ((buffer-read-only nil))
4577 ;; The cache and backlog have to be flushed somewhat.
4578 (when gnus-keep-backlog
4579 (gnus-backlog-remove-article
4580 (car gnus-article-current) (cdr gnus-article-current)))
4581 ;; Flush original article as well.
4583 (when (get-buffer gnus-original-article-buffer)
4584 (set-buffer gnus-original-article-buffer)
4585 (setq gnus-original-article nil)))
4586 (when gnus-use-cache
4587 (gnus-cache-update-article
4588 (car gnus-article-current) (cdr gnus-article-current))))
4590 (set-window-start (get-buffer-window buf) start)
4591 (set-window-point (get-buffer-window buf) (point))))
4593 (defun gnus-article-edit-exit ()
4594 "Exit the article editing without updating."
4596 ;; We remove all text props from the article buffer.
4597 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4598 (curbuf (current-buffer))
4600 (window-start (window-start)))
4603 (let ((winconf gnus-prev-winconf))
4605 (set-window-configuration winconf)
4606 ;; Tippy-toe some to make sure that point remains where it was.
4607 (save-current-buffer
4609 (set-window-start (get-buffer-window (current-buffer)) window-start)
4612 (defun gnus-article-edit-full-stops ()
4613 "Interactively repair spacing at end of sentences."
4616 (goto-char (point-min))
4617 (search-forward-regexp "^$" nil t)
4618 (let ((case-fold-search nil))
4619 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4622 ;;; Article editing with MIME-Edit
4625 (defcustom gnus-article-mime-edit-article-setup-hook nil
4626 "Hook run after setting up a MIME editing article buffer."
4627 :group 'gnus-article-various
4630 (defun gnus-article-mime-edit-article-unwind ()
4631 "Unwind `gnus-article-buffer' if article editing was given up."
4632 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4633 (when mime-edit-mode-flag
4634 (mime-edit-exit 'nomime 'no-error)
4636 (when (featurep 'font-lock)
4637 (setq font-lock-defaults nil)
4638 (font-lock-mode 0)))
4640 (defun gnus-article-mime-edit-article-setup ()
4641 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4642 after replacing with the original article."
4643 (setq gnus-show-mime t)
4644 (setq gnus-article-edit-done-function
4645 `(lambda (&rest args)
4646 (when mime-edit-mode-flag
4649 (goto-char (point-min))
4650 (let (case-fold-search)
4651 (when (re-search-forward
4652 (format "^%s$" (regexp-quote mail-header-separator))
4654 (replace-match "")))
4655 (when (featurep 'font-lock)
4656 (setq font-lock-defaults nil)
4658 (apply ,gnus-article-edit-done-function args)
4659 (set-buffer gnus-original-article-buffer)
4661 (insert-buffer gnus-article-buffer)
4662 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4663 (gnus-article-prepare-display)))
4664 (substitute-key-definition
4665 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4666 gnus-article-edit-mode-map)
4668 (insert-buffer gnus-original-article-buffer)
4670 (when (featurep 'font-lock)
4671 (set (make-local-variable 'font-lock-defaults)
4672 '(message-font-lock-keywords t))
4673 (font-lock-set-defaults)
4674 (turn-on-font-lock))
4675 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4676 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4678 (defun gnus-article-mime-edit-exit ()
4679 "Exit the article MIME editing without updating."
4681 (let ((winconf gnus-prev-winconf)
4683 (when mime-edit-mode-flag
4686 (goto-char (point-min))
4687 (let (case-fold-search)
4688 (when (re-search-forward
4689 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4690 (replace-match "")))
4691 (when (featurep 'font-lock)
4692 (setq font-lock-defaults nil)
4694 ;; We remove all text props from the article buffer.
4695 (setq buf (format "%s" (buffer-string)))
4696 (set-buffer (get-buffer-create gnus-original-article-buffer))
4699 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4700 (gnus-article-prepare-display)
4701 (set-window-configuration winconf)))
4704 ;;; Article highlights
4707 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4709 ;;; Internal Variables:
4711 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(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\\)\\)"
4712 "Regular expression that matches URLs."
4713 :group 'gnus-article-buttons
4716 (defcustom gnus-button-alist
4717 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4718 0 t gnus-button-message-id 2)
4719 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4720 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4722 gnus-button-fetch-group 4)
4723 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4724 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4725 t gnus-button-message-id 3)
4726 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4727 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4728 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4729 ;; This is how URLs _should_ be embedded in text...
4730 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4732 (,gnus-button-url-regexp 0 t browse-url 0))
4733 "*Alist of regexps matching buttons in article bodies.
4735 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4736 REGEXP: is the string matching text around the button,
4737 BUTTON: is the number of the regexp grouping actually matching the button,
4738 FORM: is a lisp expression which must eval to true for the button to
4740 CALLBACK: is the function to call when the user push this button, and each
4741 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4743 CALLBACK can also be a variable, in that case the value of that
4744 variable it the real callback function."
4745 :group 'gnus-article-buttons
4746 :type '(repeat (list regexp
4747 (integer :tag "Button")
4749 (function :tag "Callback")
4752 (integer :tag "Regexp group")))))
4754 (defcustom gnus-header-button-alist
4755 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4756 0 t gnus-button-message-id 0)
4757 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4758 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4759 0 t gnus-button-mailto 0)
4760 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4761 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4762 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4763 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4764 gnus-button-message-id 3))
4765 "*Alist of headers and regexps to match buttons in article heads.
4767 This alist is very similar to `gnus-button-alist', except that each
4768 alist has an additional HEADER element first in each entry:
4770 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4772 HEADER is a regexp to match a header. For a fuller explanation, see
4773 `gnus-button-alist'."
4774 :group 'gnus-article-buttons
4775 :group 'gnus-article-headers
4776 :type '(repeat (list (regexp :tag "Header")
4778 (integer :tag "Button")
4780 (function :tag "Callback")
4783 (integer :tag "Regexp group")))))
4785 (defvar gnus-button-regexp nil)
4786 (defvar gnus-button-marker-list nil)
4787 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4789 (defvar gnus-button-last nil)
4790 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4794 (defun gnus-article-push-button (event)
4795 "Check text under the mouse pointer for a callback function.
4796 If the text under the mouse pointer has a `gnus-callback' property,
4797 call it with the value of the `gnus-data' text property."
4799 (set-buffer (window-buffer (posn-window (event-start event))))
4800 (let* ((pos (posn-point (event-start event)))
4801 (data (get-text-property pos 'gnus-data))
4802 (fun (get-text-property pos 'gnus-callback)))
4805 (funcall fun data))))
4807 (defun gnus-article-press-button ()
4808 "Check text at point for a callback function.
4809 If the text at point has a `gnus-callback' property,
4810 call it with the value of the `gnus-data' text property."
4812 (let* ((data (get-text-property (point) 'gnus-data))
4813 (fun (get-text-property (point) 'gnus-callback)))
4815 (funcall fun data))))
4817 (defun gnus-article-prev-button (n)
4818 "Move point to N buttons backward.
4819 If N is negative, move forward instead."
4821 (gnus-article-next-button (- n)))
4823 (defun gnus-article-next-button (n)
4824 "Move point to N buttons forward.
4825 If N is negative, move backward instead."
4827 (let ((function (if (< n 0) 'previous-single-property-change
4828 'next-single-property-change))
4829 (inhibit-point-motion-hooks t)
4831 (limit (if (< n 0) (point-min) (point-max))))
4833 (while (and (not (= limit (point)))
4835 ;; Skip past the current button.
4836 (when (get-text-property (point) 'gnus-callback)
4837 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4838 ;; Go to the next (or previous) button.
4839 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4840 ;; Put point at the start of the button.
4841 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4842 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4843 ;; Skip past intangible buttons.
4844 (when (get-text-property (point) 'intangible)
4848 (gnus-message 5 "No more buttons"))
4851 (defun gnus-article-highlight (&optional force)
4852 "Highlight current article.
4853 This function calls `gnus-article-highlight-headers',
4854 `gnus-article-highlight-citation',
4855 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4856 do the highlighting. See the documentation for those functions."
4857 (interactive (list 'force))
4858 (gnus-article-highlight-headers)
4859 (gnus-article-highlight-citation force)
4860 (gnus-article-highlight-signature)
4861 (gnus-article-add-buttons force)
4862 (gnus-article-add-buttons-to-head))
4864 (defun gnus-article-highlight-some (&optional force)
4865 "Highlight current article.
4866 This function calls `gnus-article-highlight-headers',
4867 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4868 do the highlighting. See the documentation for those functions."
4869 (interactive (list 'force))
4870 (gnus-article-highlight-headers)
4871 (gnus-article-highlight-signature)
4872 (gnus-article-add-buttons))
4874 (defun gnus-article-highlight-headers ()
4875 "Highlight article headers as specified by `gnus-header-face-alist'."
4878 (set-buffer gnus-article-buffer)
4880 (let ((alist gnus-header-face-alist)
4881 (buffer-read-only nil)
4882 (case-fold-search t)
4883 (inhibit-point-motion-hooks t)
4884 entry regexp header-face field-face from hpoints fpoints)
4885 (article-narrow-to-head)
4886 (while (setq entry (pop alist))
4887 (goto-char (point-min))
4888 (setq regexp (concat "^\\("
4889 (if (string-equal "" (nth 0 entry))
4893 header-face (nth 1 entry)
4894 field-face (nth 2 entry))
4895 (while (and (re-search-forward regexp nil t)
4899 (unless (search-forward ":" nil t)
4901 (when (and header-face
4902 (not (memq (point) hpoints)))
4903 (push (point) hpoints)
4904 (gnus-put-text-property from (point) 'face header-face))
4905 (when (and field-face
4906 (not (memq (setq from (point)) fpoints)))
4908 (if (re-search-forward "^[^ \t]" nil t)
4910 (goto-char (point-max)))
4911 (gnus-put-text-property from (point) 'face field-face))))))))
4913 (defun gnus-article-highlight-signature ()
4914 "Highlight the signature in an article.
4915 It does this by highlighting everything after
4916 `gnus-signature-separator' using `gnus-signature-face'."
4918 (when gnus-signature-face
4920 (set-buffer gnus-article-buffer)
4921 (let ((buffer-read-only nil)
4922 (inhibit-point-motion-hooks t))
4924 (when (gnus-article-narrow-to-signature)
4925 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4926 'face gnus-signature-face)))))))
4928 (defun gnus-article-buttonize-signature ()
4929 "Add button to the signature."
4932 (set-buffer gnus-article-buffer)
4933 (let ((buffer-read-only nil)
4934 (inhibit-point-motion-hooks t))
4935 (when (gnus-article-search-signature)
4936 (gnus-article-add-button (match-beginning 0) (match-end 0)
4937 'gnus-signature-toggle
4938 (set-marker (make-marker)
4939 (1+ (match-end 0))))))))
4941 (defun gnus-button-in-region-p (b e prop)
4942 "Say whether PROP exists in the region."
4943 (text-property-not-all b e prop nil))
4945 (defun gnus-article-add-buttons (&optional force)
4946 "Find external references in the article and make buttons of them.
4947 \"External references\" are things like Message-IDs and URLs, as
4948 specified by `gnus-button-alist'."
4949 (interactive (list 'force))
4951 (set-buffer gnus-article-buffer)
4952 (let ((buffer-read-only nil)
4953 (inhibit-point-motion-hooks t)
4954 (case-fold-search t)
4955 (alist gnus-button-alist)
4957 ;; Remove all old markers.
4958 (let (marker entry new-list)
4959 (while (setq marker (pop gnus-button-marker-list))
4960 (if (or (< marker (point-min)) (>= marker (point-max)))
4961 (push marker new-list)
4963 (when (setq entry (gnus-button-entry))
4964 (put-text-property (match-beginning (nth 1 entry))
4965 (match-end (nth 1 entry))
4966 'gnus-callback nil))
4967 (set-marker marker nil)))
4968 (setq gnus-button-marker-list new-list))
4969 ;; We skip the headers.
4972 (while (setq entry (pop alist))
4973 (setq regexp (car entry))
4975 (while (re-search-forward regexp nil t)
4976 (let* ((start (and entry (match-beginning (nth 1 entry))))
4977 (end (and entry (match-end (nth 1 entry))))
4978 (from (match-beginning 0)))
4979 (when (and (or (eq t (nth 2 entry))
4980 (eval (nth 2 entry)))
4981 (not (gnus-button-in-region-p
4982 start end 'gnus-callback)))
4983 ;; That optional form returned non-nil, so we add the
4985 (gnus-article-add-button
4986 start end 'gnus-button-push
4987 (car (push (set-marker (make-marker) from)
4988 gnus-button-marker-list))))))))))
4990 ;; Add buttons to the head of an article.
4991 (defun gnus-article-add-buttons-to-head ()
4992 "Add buttons to the head of the article."
4995 (set-buffer gnus-article-buffer)
4997 (let ((buffer-read-only nil)
4998 (inhibit-point-motion-hooks t)
4999 (case-fold-search t)
5000 (alist gnus-header-button-alist)
5002 (article-narrow-to-head)
5004 ;; Each alist entry.
5005 (setq entry (car alist)
5007 (goto-char (point-min))
5008 (while (re-search-forward (car entry) nil t)
5009 ;; Each header matching the entry.
5010 (setq beg (match-beginning 0))
5011 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5012 (match-beginning 0))
5015 (while (re-search-forward (nth 1 entry) end t)
5016 ;; Each match within a header.
5017 (let* ((entry (cdr entry))
5018 (start (match-beginning (nth 1 entry)))
5019 (end (match-end (nth 1 entry)))
5020 (form (nth 2 entry)))
5021 (goto-char (match-end 0))
5023 (gnus-article-add-button
5024 start end (nth 3 entry)
5025 (buffer-substring (match-beginning (nth 4 entry))
5026 (match-end (nth 4 entry)))))))
5027 (goto-char end)))))))
5029 ;;; External functions:
5031 (defun gnus-article-add-button (from to fun &optional data)
5032 "Create a button between FROM and TO with callback FUN and data DATA."
5033 (when gnus-article-button-face
5034 (gnus-overlay-put (gnus-make-overlay from to)
5035 'face gnus-article-button-face))
5036 (gnus-add-text-properties
5038 (nconc (and gnus-article-mouse-face
5039 (list gnus-mouse-face-prop gnus-article-mouse-face))
5040 (list 'gnus-callback fun)
5041 (and data (list 'gnus-data data))))
5042 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5043 ;; Quote `:button-keymap' for Mule 2.3
5044 ;; but it won't work.
5045 ':button-keymap gnus-widget-button-keymap))
5047 ;;; Internal functions:
5049 (defun gnus-article-set-globals ()
5051 (set-buffer gnus-summary-buffer)
5052 (gnus-set-global-variables)))
5054 (defun gnus-signature-toggle (end)
5056 (set-buffer gnus-article-buffer)
5057 (let ((buffer-read-only nil)
5058 (inhibit-point-motion-hooks t)
5059 (limit (next-single-property-change end 'mime-view-entity
5061 (if (text-property-any end limit 'article-type 'signature)
5062 (gnus-remove-text-properties-when
5063 'article-type 'signature end limit
5064 (cons 'article-type (cons 'signature
5065 gnus-hidden-properties)))
5066 (gnus-add-text-properties-when
5067 'article-type nil end limit
5068 (cons 'article-type (cons 'signature
5069 gnus-hidden-properties)))))))
5071 (defun gnus-button-entry ()
5072 ;; Return the first entry in `gnus-button-alist' matching this place.
5073 (let ((alist gnus-button-alist)
5076 (setq entry (pop alist))
5077 (if (looking-at (car entry))
5082 (defun gnus-button-push (marker)
5083 ;; Push button starting at MARKER.
5086 (let* ((entry (gnus-button-entry))
5087 (inhibit-point-motion-hooks t)
5089 (args (mapcar (lambda (group)
5090 (let ((string (match-string group)))
5091 (gnus-set-text-properties
5092 0 (length string) nil string)
5099 (fboundp (symbol-value fun)))
5100 (apply (symbol-value fun) args))
5102 (gnus-message 1 "You must define `%S' to use this button"
5103 (cons fun args)))))))
5105 (defun gnus-button-message-id (message-id)
5108 (set-buffer gnus-summary-buffer)
5109 (gnus-summary-refer-article message-id)))
5111 (defun gnus-button-fetch-group (address)
5112 "Fetch GROUP specified by ADDRESS."
5113 (if (not (string-match "[:/]" address))
5114 ;; This is just a simple group url.
5115 (gnus-group-read-ephemeral-group address gnus-select-method)
5116 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5118 (error "Can't parse %s" address)
5119 (gnus-group-read-ephemeral-group
5120 (match-string 4 address)
5121 `(nntp ,(match-string 1 address)
5122 (nntp-address ,(match-string 1 address))
5123 (nntp-port-number ,(if (match-end 3)
5124 (match-string 3 address)
5127 (defun gnus-url-parse-query-string (query &optional downcase)
5128 (let (retval pairs cur key val)
5129 (setq pairs (split-string query "&"))
5131 (setq cur (car pairs)
5133 (if (not (string-match "=" cur))
5135 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5136 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5138 (setq key (downcase key)))
5139 (setq cur (assoc key retval))
5141 (setcdr cur (cons val (cdr cur)))
5142 (setq retval (cons (list key val) retval)))))
5145 (defun gnus-url-unhex (x)
5152 (defun gnus-url-unhex-string (str &optional allow-newlines)
5153 "Remove %XXX embedded spaces, etc in a url.
5154 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5155 decoding of carriage returns and line feeds in the string, which is normally
5156 forbidden in URL encoding."
5157 (setq str (or str ""))
5159 (case-fold-search t))
5160 (while (string-match "%[0-9a-f][0-9a-f]" str)
5161 (let* ((start (match-beginning 0))
5162 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5164 (gnus-url-unhex (elt str (+ start 2))))))
5166 tmp (substring str 0 start)
5169 (char-to-string code))
5170 ((or (= code ?\n) (= code ?\r))
5172 (t (char-to-string code))))
5173 str (substring str (match-end 0)))))
5174 (setq tmp (concat tmp str))
5177 (defun gnus-url-mailto (url)
5178 ;; Send mail to someone
5179 (when (string-match "mailto:/*\\(.*\\)" url)
5180 (setq url (substring url (match-beginning 1) nil)))
5181 (let (to args subject func)
5182 (if (string-match (regexp-quote "?") url)
5183 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5184 args (gnus-url-parse-query-string
5185 (substring url (match-end 0) nil) t))
5186 (setq to (gnus-url-unhex-string url)))
5187 (setq args (cons (list "to" to) args)
5188 subject (cdr-safe (assoc "subject" args)))
5189 (gnus-setup-message 'reply
5192 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5195 (message-position-on-field (caar args)))
5196 (insert (mapconcat 'identity (cdar args) ", "))
5197 (setq args (cdr args)))
5200 (message-goto-subject)))))
5202 (defun gnus-button-mailto (address)
5204 (set-buffer (gnus-copy-article-buffer))
5205 (message-reply address))
5207 (defalias 'gnus-button-reply 'message-reply)
5209 (defun gnus-button-embedded-url (address)
5210 "Activate ADDRESS with `browse-url'."
5211 (browse-url (gnus-strip-whitespace address)))
5214 ;; Silence the byte-compiler.
5215 (autoload 'smiley-toggle-buffer "gnus-bitmap"))
5216 (defun gnus-article-smiley-display ()
5217 "Display \"smileys\" as small graphical icons."
5218 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5220 ;;; Next/prev buttons in the article buffer.
5222 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5223 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5225 (defvar gnus-prev-page-map nil)
5226 (unless gnus-prev-page-map
5227 (setq gnus-prev-page-map (make-sparse-keymap))
5228 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5229 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5231 (static-if (featurep 'xemacs)
5232 (defun gnus-insert-prev-page-button ()
5233 (let ((buffer-read-only nil))
5235 gnus-prev-page-line-format nil
5236 `(gnus-prev t local-map ,gnus-prev-page-map
5237 gnus-callback gnus-article-button-prev-page
5238 article-type annotation))))
5239 (defun gnus-insert-prev-page-button ()
5240 (let ((buffer-read-only nil)
5241 (situation (get-text-property (point-min) 'mime-view-situation)))
5242 (set-keymap-parent gnus-prev-page-map (current-local-map))
5244 gnus-prev-page-line-format nil
5245 `(gnus-prev t local-map ,gnus-prev-page-map
5246 gnus-callback gnus-article-button-prev-page
5247 article-type annotation
5248 mime-view-situation ,situation))))
5251 (defvar gnus-next-page-map nil)
5252 (unless gnus-next-page-map
5253 (setq gnus-next-page-map (make-sparse-keymap))
5254 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5255 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5257 (defun gnus-button-next-page ()
5258 "Go to the next page."
5260 (let ((win (selected-window)))
5261 (select-window (get-buffer-window gnus-article-buffer t))
5262 (gnus-article-next-page)
5263 (select-window win)))
5265 (defun gnus-button-prev-page ()
5266 "Go to the prev page."
5268 (let ((win (selected-window)))
5269 (select-window (get-buffer-window gnus-article-buffer t))
5270 (gnus-article-prev-page)
5271 (select-window win)))
5273 (static-if (featurep 'xemacs)
5274 (defun gnus-insert-next-page-button ()
5275 (let ((buffer-read-only nil))
5276 (gnus-eval-format gnus-next-page-line-format nil
5278 t local-map ,gnus-next-page-map
5279 gnus-callback gnus-article-button-next-page
5280 article-type annotation))))
5281 (defun gnus-insert-next-page-button ()
5282 (let ((buffer-read-only nil)
5283 (situation (get-text-property (point-min) 'mime-view-situation)))
5284 (set-keymap-parent gnus-next-page-map (current-local-map))
5285 (gnus-eval-format gnus-next-page-line-format nil
5287 t local-map ,gnus-next-page-map
5288 gnus-callback gnus-article-button-next-page
5289 article-type annotation
5290 mime-view-situation ,situation))))
5293 (defun gnus-article-button-next-page (arg)
5294 "Go to the next page."
5296 (let ((win (selected-window)))
5297 (select-window (get-buffer-window gnus-article-buffer t))
5298 (gnus-article-next-page)
5299 (select-window win)))
5301 (defun gnus-article-button-prev-page (arg)
5302 "Go to the prev page."
5304 (let ((win (selected-window)))
5305 (select-window (get-buffer-window gnus-article-buffer t))
5306 (gnus-article-prev-page)
5307 (select-window win)))
5309 (defvar gnus-decode-header-methods
5310 '(mail-decode-encoded-word-region)
5311 "List of methods used to decode headers.
5313 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5314 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5315 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5316 whose names match REGEXP.
5319 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5320 mail-decode-encoded-word-region
5321 (\"chinese\" . rfc1843-decode-region))
5324 (defvar gnus-decode-header-methods-cache nil)
5326 (defun gnus-multi-decode-header (start end)
5327 "Apply the functions from `gnus-encoded-word-methods' that match."
5328 (unless (and gnus-decode-header-methods-cache
5329 (eq gnus-newsgroup-name
5330 (car gnus-decode-header-methods-cache)))
5331 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5334 (nconc gnus-decode-header-methods-cache (list x))
5335 (if (and gnus-newsgroup-name
5336 (string-match (car x) gnus-newsgroup-name))
5337 (nconc gnus-decode-header-methods-cache
5339 gnus-decode-header-methods))
5340 (let ((xlist gnus-decode-header-methods-cache))
5343 (narrow-to-region start end)
5345 (funcall (pop xlist) (point-min) (point-max))))))
5348 ;;; Treatment top-level handling.
5351 (defun gnus-treat-article (condition &optional part-number total-parts type)
5352 (let ((length (- (point-max) (point-min)))
5353 (alist gnus-treatment-function-alist)
5354 (article-goto-body-goes-to-point-min-p t)
5358 (let ((list gnus-article-treat-types))
5360 (when (string-match (pop list) type)
5361 (throw 'found t)))))))
5362 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5363 (entity (static-unless (featurep 'xemacs)
5364 (when (eq 'head condition)
5365 (get-text-property (point-min) 'mime-view-entity))))
5366 val elem buttonized)
5367 (gnus-run-hooks 'gnus-part-display-hook)
5368 (unless gnus-inhibit-treatment
5369 (while (setq elem (pop alist))
5372 (if (gnus-buffer-live-p gnus-summary-buffer)
5373 (set-buffer gnus-summary-buffer))
5374 (symbol-value (car elem))))
5375 (when (and (or (consp val)
5377 (gnus-treat-predicate val)
5378 (or (not (get (car elem) 'highlight))
5380 (when (and (not buttonized)
5382 '(gnus-treat-hide-signature
5383 gnus-treat-highlight-signature)))
5384 (gnus-article-buttonize-signature)
5385 (setq buttonized t))
5387 (funcall (cadr elem)))))
5388 ;; FSF Emacsen does not inherit the existing text properties
5389 ;; in the new text, so we should do it for `mime-view-entity'.
5390 (static-unless (featurep 'xemacs)
5392 (put-text-property (point-min) (point-max)
5393 'mime-view-entity entity))))))
5395 ;; Dynamic variables.
5397 (defvar part-number)
5398 (defvar total-parts)
5403 (defun gnus-treat-predicate (val)
5408 (stringp (car val)))
5409 (apply 'gnus-or (mapcar `(lambda (s)
5410 (string-match s ,(or gnus-newsgroup-name "")))
5413 (let ((pred (pop val)))
5416 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5418 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5420 (not (gnus-treat-predicate (car val))))
5422 (equal (car val) type))
5424 (error "%S is not a valid predicate" pred)))))
5434 (eq part-number total-parts))
5438 (error "%S is not a valid value" val))))
5443 (defun gnus-article-header-presentation-method (entity situation)
5444 (mime-insert-header entity)
5447 (set-alist 'mime-header-presentation-method-alist
5448 'gnus-original-article-mode
5449 #'gnus-article-header-presentation-method)
5451 (defun gnus-mime-preview-quitting-method ()
5452 (mime-preview-kill-buffer)
5453 (delete-other-windows)
5454 (gnus-article-show-summary)
5455 (gnus-summary-select-article gnus-show-all-headers t))
5457 (set-alist 'mime-preview-quitting-method-alist
5458 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5460 (set-alist 'mime-preview-following-method-alist
5461 'gnus-original-article-mode #'gnus-following-method)
5463 (set-alist 'mime-preview-over-to-previous-method-alist
5464 'gnus-original-article-mode
5466 (if (> (point-min) 1)
5467 (gnus-article-prev-page)
5468 (gnus-article-read-summary-keys
5469 nil (gnus-character-to-event ?P)))))
5471 (set-alist 'mime-preview-over-to-next-method-alist
5472 'gnus-original-article-mode'
5474 (if (< (point-max) (buffer-size))
5475 (gnus-article-next-page)
5476 (gnus-article-read-summary-keys
5477 nil (gnus-character-to-event ?N)))))
5487 (run-hooks 'gnus-art-load-hook)
5489 ;;; gnus-art.el ends here