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:\\|^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 (defcustom gnus-article-x-face-command
213 ;; Fixme: This isn't the right thing for mixed graphical and and
214 ;; non-graphical frames in a session.
215 ;; gnus-xmas.el overrides this for XEmacs.
216 ((and (fboundp 'image-type-available-p)
217 (image-type-available-p 'xbm))
218 'gnus-article-display-xface)
219 ((and (not gnus-xemacs)
221 (module-installed-p 'x-face-mule))
222 'x-face-mule-gnus-article-display-x-face)
224 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"))
225 "*String or function to be executed to display an X-Face header.
226 If it is a string, the command will be executed in a sub-shell
227 asynchronously. The compressed face will be piped to this command."
228 :type '(choice string
229 (function-item gnus-article-display-xface)
230 (function-item x-face-mule-gnus-article-display-x-face)
232 :group 'gnus-article-washing)
234 (defcustom gnus-article-x-face-too-ugly nil
235 "Regexp matching posters whose face shouldn't be shown automatically."
236 :type '(choice regexp (const nil))
237 :group 'gnus-article-washing)
239 (defcustom gnus-article-banner-alist nil
240 "Banner alist for stripping.
242 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
243 :type '(repeat (cons symbol regexp))
244 :group 'gnus-article-washing)
246 (defcustom gnus-emphasis-alist
248 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
250 '(("_" "_" underline)
253 ("_/" "/_" underline-italic)
254 ("_\\*" "\\*_" underline-bold)
255 ("\\*/" "/\\*" bold-italic)
256 ("_\\*/" "/\\*_" underline-bold-italic))))
257 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
258 2 3 gnus-emphasis-underline)
262 (format format (car spec) (car (cdr spec)))
263 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
265 "*Alist that says how to fontify certain phrases.
266 Each item looks like this:
268 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
270 The first element is a regular expression to be matched. The second
271 is a number that says what regular expression grouping used to find
272 the entire emphasized word. The third is a number that says what
273 regexp grouping should be displayed and highlighted. The fourth
274 is the face used for highlighting."
275 :type '(repeat (list :value ("" 0 0 default)
277 (integer :tag "Match group")
278 (integer :tag "Emphasize group")
280 :group 'gnus-article-emphasis)
282 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
283 "A regexp to describe whitespace which should not be emphasized.
284 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
285 The former avoids underlining of leading and trailing whitespace,
286 and the latter avoids underlining any whitespace at all."
287 :group 'gnus-article-emphasis
290 (defface gnus-emphasis-bold '((t (:bold t)))
291 "Face used for displaying strong emphasized text (*word*)."
292 :group 'gnus-article-emphasis)
294 (defface gnus-emphasis-italic '((t (:italic t)))
295 "Face used for displaying italic emphasized text (/word/)."
296 :group 'gnus-article-emphasis)
298 (defface gnus-emphasis-underline '((t (:underline t)))
299 "Face used for displaying underlined emphasized text (_word_)."
300 :group 'gnus-article-emphasis)
302 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
303 "Face used for displaying underlined bold emphasized text (_*word*_)."
304 :group 'gnus-article-emphasis)
306 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
307 "Face used for displaying underlined italic emphasized text (_/word/_)."
308 :group 'gnus-article-emphasis)
310 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
311 "Face used for displaying bold italic emphasized text (/*word*/)."
312 :group 'gnus-article-emphasis)
314 (defface gnus-emphasis-underline-bold-italic
315 '((t (:bold t :italic t :underline t)))
316 "Face used for displaying underlined bold italic emphasized text.
317 Esample: (_/*word*/_)."
318 :group 'gnus-article-emphasis)
320 (defface gnus-emphasis-highlight-words
321 '((t (:background "black" :foreground "yellow")))
322 "Face used for displaying highlighted words."
323 :group 'gnus-article-emphasis)
325 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
326 "Format for display of Date headers in article bodies.
327 See `format-time-string' for the possible values.
329 The variable can also be function, which should return a complete Date
330 header. The function is called with one argument, the time, which can
331 be fed to `format-time-string'."
332 :type '(choice string symbol)
333 :link '(custom-manual "(gnus)Article Date")
334 :group 'gnus-article-washing)
337 (autoload 'mail-extract-address-components "mail-extr"))
339 (defcustom gnus-save-all-headers t
340 "*If non-nil, don't remove any headers before saving."
341 :group 'gnus-article-saving
344 (defcustom gnus-prompt-before-saving 'always
345 "*This variable says how much prompting is to be done when saving articles.
346 If it is nil, no prompting will be done, and the articles will be
347 saved to the default files. If this variable is `always', each and
348 every article that is saved will be preceded by a prompt, even when
349 saving large batches of articles. If this variable is neither nil not
350 `always', there the user will be prompted once for a file name for
351 each invocation of the saving commands."
352 :group 'gnus-article-saving
353 :type '(choice (item always)
354 (item :tag "never" nil)
355 (sexp :tag "once" :format "%t\n" :value t)))
357 (defcustom gnus-saved-headers gnus-visible-headers
358 "Headers to keep if `gnus-save-all-headers' is nil.
359 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
360 If that variable is nil, however, all headers that match this regexp
361 will be kept while the rest will be deleted before saving."
362 :group 'gnus-article-saving
365 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
366 "A function to save articles in your favourite format.
367 The function must be interactively callable (in other words, it must
368 be an Emacs command).
370 Gnus provides the following functions:
372 * gnus-summary-save-in-rmail (Rmail format)
373 * gnus-summary-save-in-mail (Unix mail format)
374 * gnus-summary-save-in-folder (MH folder)
375 * gnus-summary-save-in-file (article format)
376 * gnus-summary-save-in-vm (use VM's folder format)
377 * gnus-summary-write-to-file (article format -- overwrite)."
378 :group 'gnus-article-saving
379 :type '(radio (function-item gnus-summary-save-in-rmail)
380 (function-item gnus-summary-save-in-mail)
381 (function-item gnus-summary-save-in-folder)
382 (function-item gnus-summary-save-in-file)
383 (function-item gnus-summary-save-in-vm)
384 (function-item gnus-summary-write-to-file)))
386 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
387 "A function generating a file name to save articles in Rmail format.
388 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
389 :group 'gnus-article-saving
392 (defcustom gnus-mail-save-name 'gnus-plain-save-name
393 "A function generating a file name to save articles in Unix mail format.
394 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
395 :group 'gnus-article-saving
398 (defcustom gnus-folder-save-name 'gnus-folder-save-name
399 "A function generating a file name to save articles in MH folder.
400 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
401 :group 'gnus-article-saving
404 (defcustom gnus-file-save-name 'gnus-numeric-save-name
405 "A function generating a file name to save articles in article format.
406 The function is called with NEWSGROUP, HEADERS, and optional
408 :group 'gnus-article-saving
411 (defcustom gnus-split-methods
412 '((gnus-article-archive-name)
413 (gnus-article-nndoc-name))
414 "*Variable used to suggest where articles are to be saved.
415 For instance, if you would like to save articles related to Gnus in
416 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
417 you could set this variable to something like:
419 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
420 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
422 This variable is an alist where the where the key is the match and the
423 value is a list of possible files to save in if the match is non-nil.
425 If the match is a string, it is used as a regexp match on the
426 article. If the match is a symbol, that symbol will be funcalled
427 from the buffer of the article to be saved with the newsgroup as the
428 parameter. If it is a list, it will be evaled in the same buffer.
430 If this form or function returns a string, this string will be used as
431 a possible file name; and if it returns a non-nil list, that list will
432 be used as possible file names."
433 :group 'gnus-article-saving
434 :type '(repeat (choice (list :value (fun) function)
435 (cons :value ("" "") regexp (repeat string))
438 (defcustom gnus-article-display-method-for-mime
439 'gnus-article-display-mime-message
440 "Function to display a MIME message.
441 The function is called from the article buffer."
442 :group 'gnus-article-mime
445 (defcustom gnus-article-display-method-for-traditional
446 'gnus-article-display-traditional-message
447 "*Function to display a traditional message.
448 The function is called from the article buffer."
449 :group 'gnus-article-mime
452 (defcustom gnus-page-delimiter "^\^L"
453 "*Regexp describing what to use as article page delimiters.
454 The default value is \"^\^L\", which is a form linefeed at the
455 beginning of a line."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
460 "*The format specification for the article mode line.
461 See `gnus-summary-mode-line-format' for a closer description.
463 The following additional specs are available:
465 %w The article washing status.
466 %m The number of MIME parts in the article."
468 :group 'gnus-article-various)
470 (defcustom gnus-article-mode-hook nil
471 "*A hook for Gnus article mode."
473 :group 'gnus-article-various)
475 (defcustom gnus-article-menu-hook nil
476 "*Hook run after the creation of the article mode menu."
478 :group 'gnus-article-various)
480 (defcustom gnus-article-prepare-hook nil
481 "*A hook called after an article has been prepared in the article buffer."
483 :group 'gnus-article-various)
485 (defcustom gnus-article-hide-pgp-hook nil
486 "*A hook called after successfully hiding a PGP signature."
488 :group 'gnus-article-various)
490 (defcustom gnus-article-button-face 'bold
491 "Face used for highlighting buttons in the article buffer.
493 An article button is a piece of text that you can activate by pressing
494 `RET' or `mouse-2' above it."
496 :group 'gnus-article-buttons)
498 (defcustom gnus-article-mouse-face 'highlight
499 "Face used for mouse highlighting in the article buffer.
501 Article buttons will be displayed in this face when the cursor is
504 :group 'gnus-article-buttons)
506 (defcustom gnus-signature-face 'gnus-signature-face
507 "Face used for highlighting a signature in the article buffer.
508 Obsolete; use the face `gnus-signature-face' for customizations instead."
510 :group 'gnus-article-highlight
511 :group 'gnus-article-signature)
513 (defface gnus-signature-face
515 "Face used for highlighting a signature in the article buffer."
516 :group 'gnus-article-highlight
517 :group 'gnus-article-signature)
519 (defface gnus-header-from-face
522 (:foreground "spring green"))
525 (:foreground "red3"))
528 "Face used for displaying from headers."
529 :group 'gnus-article-headers
530 :group 'gnus-article-highlight)
532 (defface gnus-header-subject-face
535 (:foreground "SeaGreen3"))
538 (:foreground "red4"))
540 (:bold t :italic t)))
541 "Face used for displaying subject headers."
542 :group 'gnus-article-headers
543 :group 'gnus-article-highlight)
545 (defface gnus-header-newsgroups-face
548 (:foreground "yellow" :italic t))
551 (:foreground "MidnightBlue" :italic t))
554 "Face used for displaying newsgroups headers."
555 :group 'gnus-article-headers
556 :group 'gnus-article-highlight)
558 (defface gnus-header-name-face
561 (:foreground "SeaGreen"))
564 (:foreground "maroon"))
567 "Face used for displaying header names."
568 :group 'gnus-article-headers
569 :group 'gnus-article-highlight)
571 (defface gnus-header-content-face
574 (:foreground "forest green" :italic t))
577 (:foreground "indianred4" :italic t))
579 (:italic t))) "Face used for displaying header content."
580 :group 'gnus-article-headers
581 :group 'gnus-article-highlight)
583 (defcustom gnus-header-face-alist
584 '(("From" nil gnus-header-from-face)
585 ("Subject" nil gnus-header-subject-face)
586 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
587 ("" gnus-header-name-face gnus-header-content-face))
588 "*Controls highlighting of article header.
590 An alist of the form (HEADER NAME CONTENT).
592 HEADER is a regular expression which should match the name of an
593 header header and NAME and CONTENT are either face names or nil.
595 The name of each header field will be displayed using the face
596 specified by the first element in the list where HEADER match the
597 header name and NAME is non-nil. Similarly, the content will be
598 displayed by the first non-nil matching CONTENT face."
599 :group 'gnus-article-headers
600 :group 'gnus-article-highlight
601 :type '(repeat (list (regexp :tag "Header")
603 (item :tag "skip" nil)
604 (face :value default))
605 (choice :tag "Content"
606 (item :tag "skip" nil)
607 (face :value default)))))
609 (defcustom gnus-article-decode-hook nil
610 "*Hook run to decode charsets in articles."
611 :group 'gnus-article-headers
614 (defcustom gnus-display-mime-function 'gnus-display-mime
615 "Function to display MIME articles."
616 :group 'gnus-article-mime
619 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
620 "Function used to decode headers.")
622 (defvar gnus-article-dumbquotes-map
640 "Table for MS-to-Latin1 translation.")
642 (defcustom gnus-ignored-mime-types nil
643 "List of MIME types that should be ignored by Gnus."
644 :group 'gnus-article-mime
645 :type '(repeat regexp))
647 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
648 "List of MIME types that should not be given buttons when rendered inline."
649 :group 'gnus-article-mime
650 :type '(repeat regexp))
652 (defcustom gnus-article-mime-part-function nil
653 "Function called with a MIME handle as the argument.
654 This is meant for people who want to do something automatic based
655 on parts -- for instance, adding Vcard info to a database."
656 :group 'gnus-article-mime
659 (defcustom gnus-mime-multipart-functions nil
660 "An alist of MIME types to functions to display them.")
662 (defcustom gnus-article-date-lapsed-new-header nil
663 "Whether the X-Sent and Date headers can coexist.
664 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
665 either replace the old \"Date:\" header (if this variable is nil), or
666 be added below it (otherwise)."
667 :group 'gnus-article-headers
670 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
671 "Function called with a MIME handle as the argument.
672 This is meant for people who want to view first matched part.
673 For `undisplayed-alternative' (default), the first undisplayed
674 part or alternative part is used. For `undisplayed', the first
675 undisplayed part is used. For a function, the first part which
676 the function return `t' is used. For `nil', the first part is
678 :group 'gnus-article-mime
680 (item :tag "first" :value nil)
681 (item :tag "undisplayed" :value undisplayed)
682 (item :tag "undisplayed or alternative"
683 :value undisplayed-alternative)
686 (defcustom gnus-mime-action-alist
687 '(("save to file" . gnus-mime-save-part)
688 ("display as text" . gnus-mime-inline-part)
689 ("view the part" . gnus-mime-view-part)
690 ("pipe to command" . gnus-mime-pipe-part)
691 ("toggle display" . gnus-article-press-button)
692 ("view as type" . gnus-mime-view-part-as-type)
693 ("internalize type" . gnus-mime-internalize-part)
694 ("externalize type" . gnus-mime-externalize-part))
695 "An alist of actions that run on the MIME attachment."
696 :group 'gnus-article-mime
697 :type '(repeat (cons (string :tag "name")
701 ;;; The treatment variables
704 (defvar gnus-part-display-hook nil
705 "Hook called on parts that are to receive treatment.")
707 (defvar gnus-article-treat-custom
708 '(choice (const :tag "Off" nil)
710 (const :tag "Header" head)
711 (const :tag "Last" last)
712 (const :tag "Mime" mime)
713 (integer :tag "Less")
714 (repeat :tag "Groups" regexp)
715 (sexp :tag "Predicate")))
717 (defvar gnus-article-treat-head-custom
718 '(choice (const :tag "Off" nil)
719 (const :tag "Header" head)))
721 (defvar gnus-article-treat-types '("text/plain")
724 (defvar gnus-inhibit-treatment nil
725 "Whether to inhibit treatment.")
727 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
728 "Highlight the signature.
729 Valid values are nil, t, `head', `last', an integer or a predicate.
730 See the manual for details."
731 :group 'gnus-article-treat
732 :type gnus-article-treat-custom)
733 (put 'gnus-treat-highlight-signature 'highlight t)
735 (defcustom gnus-treat-buttonize 100000
737 Valid values are nil, t, `head', `last', an integer or a predicate.
738 See the manual for details."
739 :group 'gnus-article-treat
740 :type gnus-article-treat-custom)
741 (put 'gnus-treat-buttonize 'highlight t)
743 (defcustom gnus-treat-buttonize-head 'head
744 "Add buttons to the head.
745 Valid values are nil, t, `head', `last', an integer or a predicate.
746 See the manual for details."
747 :group 'gnus-article-treat
748 :type gnus-article-treat-head-custom)
749 (put 'gnus-treat-buttonize-head 'highlight t)
751 (defcustom gnus-treat-emphasize nil
753 Valid values are nil, t, `head', `last', an integer or a predicate.
754 See the manual for details."
755 :group 'gnus-article-treat
756 :type gnus-article-treat-custom)
757 (put 'gnus-treat-emphasize 'highlight t)
759 (defcustom gnus-treat-strip-cr nil
760 "Remove carriage returns.
761 Valid values are nil, t, `head', `last', an integer or a predicate.
762 See the manual for details."
763 :group 'gnus-article-treat
764 :type gnus-article-treat-custom)
766 (defcustom gnus-treat-hide-headers 'head
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770 :group 'gnus-article-treat
771 :type gnus-article-treat-head-custom)
773 (defcustom gnus-treat-hide-boring-headers nil
774 "Hide boring headers.
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-head-custom)
780 (defcustom gnus-treat-hide-signature nil
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784 :group 'gnus-article-treat
785 :type gnus-article-treat-custom)
787 (defcustom gnus-treat-fill-article nil
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-custom)
794 (defcustom gnus-treat-hide-citation nil
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798 :group 'gnus-article-treat
799 :type gnus-article-treat-custom)
801 (defcustom gnus-treat-strip-list-identifiers 'head
802 "Strip list identifiers from `gnus-list-identifiers`.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-custom)
808 (defcustom gnus-treat-strip-pgp t
809 "Strip PGP signatures.
810 Valid values are nil, t, `head', `last', an integer or a predicate.
811 See the manual for details."
812 :group 'gnus-article-treat
813 :type gnus-article-treat-custom)
815 (defcustom gnus-treat-strip-pem nil
816 "Strip PEM signatures.
817 Valid values are nil, t, `head', `last', an integer or a predicate.
818 See the manual for details."
819 :group 'gnus-article-treat
820 :type gnus-article-treat-custom)
822 (defcustom gnus-treat-strip-banner t
823 "Strip banners from articles.
824 The banner to be stripped is specified in the `banner' group parameter.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-custom)
830 (defcustom gnus-treat-highlight-headers 'head
831 "Highlight the headers.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-head-custom)
836 (put 'gnus-treat-highlight-headers 'highlight t)
838 (defcustom gnus-treat-highlight-citation t
839 "Highlight cited text.
840 Valid values are nil, t, `head', `last', an integer or a predicate.
841 See the manual for details."
842 :group 'gnus-article-treat
843 :type gnus-article-treat-custom)
844 (put 'gnus-treat-highlight-citation 'highlight t)
846 (defcustom gnus-treat-date-ut nil
847 "Display the Date in UT (GMT).
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See the manual for details."
850 :group 'gnus-article-treat
851 :type gnus-article-treat-head-custom)
853 (defcustom gnus-treat-date-local nil
854 "Display the Date in the local timezone.
855 Valid values are nil, t, `head', `last', an integer or a predicate.
856 See the manual for details."
857 :group 'gnus-article-treat
858 :type gnus-article-treat-head-custom)
860 (defcustom gnus-treat-date-lapsed nil
861 "Display the Date header in a way that says how much time has elapsed.
862 Valid values are nil, t, `head', `last', an integer or a predicate.
863 See the manual for details."
864 :group 'gnus-article-treat
865 :type gnus-article-treat-head-custom)
867 (defcustom gnus-treat-date-original nil
868 "Display the date in the original timezone.
869 Valid values are nil, t, `head', `last', an integer or a predicate.
870 See the manual for details."
871 :group 'gnus-article-treat
872 :type gnus-article-treat-head-custom)
874 (defcustom gnus-treat-date-iso8601 nil
875 "Display the date in the ISO8601 format.
876 Valid values are nil, t, `head', `last', an integer or a predicate.
877 See the manual for details."
878 :group 'gnus-article-treat
879 :type gnus-article-treat-head-custom)
881 (defcustom gnus-treat-date-user-defined nil
882 "Display the date in a user-defined format.
883 The format is defined by the `gnus-article-time-format' variable.
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See the manual for details."
886 :group 'gnus-article-treat
887 :type gnus-article-treat-head-custom)
889 (defcustom gnus-treat-strip-headers-in-body t
890 "Strip the X-No-Archive header line from the beginning of the body.
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See the manual for details."
893 :group 'gnus-article-treat
894 :type gnus-article-treat-custom)
896 (defcustom gnus-treat-strip-trailing-blank-lines nil
897 "Strip trailing blank lines.
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See the manual for details."
900 :group 'gnus-article-treat
901 :type gnus-article-treat-custom)
903 (defcustom gnus-treat-strip-leading-blank-lines nil
904 "Strip leading blank lines.
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See the manual for details."
907 :group 'gnus-article-treat
908 :type gnus-article-treat-custom)
910 (defcustom gnus-treat-strip-multiple-blank-lines nil
911 "Strip multiple blank lines.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
914 :group 'gnus-article-treat
915 :type gnus-article-treat-custom)
917 (defcustom gnus-treat-overstrike t
918 "Treat overstrike highlighting.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921 :group 'gnus-article-treat
922 :type gnus-article-treat-custom)
923 (put 'gnus-treat-overstrike 'highlight t)
925 (defcustom gnus-treat-display-xface
926 (and (or (and (fboundp 'image-type-available-p)
927 (image-type-available-p 'xbm))
928 (and gnus-xemacs (featurep 'xface))
929 (eq 'x-face-mule-gnus-article-display-x-face
930 gnus-article-x-face-command))
932 "Display X-Face headers.
933 Valid values are nil, t, `head', `last', an integer or a predicate.
934 See the manual for details."
935 :group 'gnus-article-treat
936 :type gnus-article-treat-head-custom)
937 (put 'gnus-treat-display-xface 'highlight t)
939 (defcustom gnus-treat-display-smileys
940 (if (or (and gnus-xemacs (featurep 'xpm))
941 (and (not gnus-xemacs)
943 (module-installed-p 'gnus-bitmap)))
947 Valid values are nil, t, `head', `last', an integer or a predicate.
948 See the manual for details."
949 :group 'gnus-article-treat
950 :type gnus-article-treat-custom)
951 (put 'gnus-treat-display-smileys 'highlight t)
953 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
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-picons 'highlight t)
961 (defcustom gnus-treat-capitalize-sentences nil
962 "Capitalize sentence-starting words.
963 Valid values are nil, t, `head', `last', an integer or a predicate.
964 See the manual for details."
965 :group 'gnus-article-treat
966 :type gnus-article-treat-custom)
968 (defcustom gnus-treat-fill-long-lines nil
970 Valid values are nil, t, `head', `last', an integer or a predicate.
971 See the manual for details."
972 :group 'gnus-article-treat
973 :type gnus-article-treat-custom)
975 (defcustom gnus-treat-play-sounds nil
977 Valid values are nil, t, `head', `last', an integer or a predicate.
978 See the manual for details."
979 :group 'gnus-article-treat
980 :type gnus-article-treat-custom)
982 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
983 "Decode an article as `default-mime-charset'. For instance, if you want to
984 attempt to decode an article even if the value of `gnus-show-mime' is nil,
985 you could set this variable to something like: nil for don't decode, t for
986 decode the body, '(or header t) for the whole article, etc."
987 :group 'gnus-article-treat
988 :type '(radio (const :tag "Off" nil)
989 (const :tag "Decode body" t)
990 (const :tag "Decode all" (or head t))))
992 (defcustom gnus-treat-translate nil
993 "Translate articles from one language to another.
994 Valid values are nil, t, `head', `last', an integer or a predicate.
995 See the manual for details."
996 :group 'gnus-article-treat
997 :type gnus-article-treat-custom)
999 ;;; Internal variables
1001 (defvar article-goto-body-goes-to-point-min-p nil)
1002 (defvar gnus-article-wash-types nil)
1003 (defvar gnus-article-emphasis-alist nil)
1005 (defvar gnus-article-mime-handle-alist-1 nil)
1006 (defvar gnus-treatment-function-alist
1007 '((gnus-treat-decode-article-as-default-mime-charset
1008 gnus-article-decode-article-as-default-mime-charset)
1009 (gnus-treat-strip-banner gnus-article-strip-banner)
1010 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1011 (gnus-treat-buttonize gnus-article-add-buttons)
1012 (gnus-treat-fill-article gnus-article-fill-cited-article)
1013 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1014 (gnus-treat-strip-cr gnus-article-remove-cr)
1015 (gnus-treat-display-xface gnus-article-display-x-face)
1016 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1017 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1018 (gnus-treat-hide-signature gnus-article-hide-signature)
1019 (gnus-treat-hide-citation gnus-article-hide-citation)
1020 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1021 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1022 (gnus-treat-strip-pem gnus-article-hide-pem)
1023 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1024 (gnus-treat-emphasize gnus-article-emphasize)
1025 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1026 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1027 (gnus-treat-date-ut gnus-article-date-ut)
1028 (gnus-treat-date-local gnus-article-date-local)
1029 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1030 (gnus-treat-date-original gnus-article-date-original)
1031 (gnus-treat-date-user-defined gnus-article-date-user)
1032 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1033 (gnus-treat-strip-trailing-blank-lines
1034 gnus-article-remove-trailing-blank-lines)
1035 (gnus-treat-strip-leading-blank-lines
1036 gnus-article-strip-leading-blank-lines)
1037 (gnus-treat-strip-multiple-blank-lines
1038 gnus-article-strip-multiple-blank-lines)
1039 (gnus-treat-overstrike gnus-article-treat-overstrike)
1040 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1041 (gnus-treat-display-smileys gnus-article-smiley-display)
1042 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1043 (gnus-treat-display-picons gnus-article-display-picons)
1044 (gnus-treat-play-sounds gnus-earcon-display)))
1046 (defvar gnus-article-mime-handle-alist nil)
1047 (defvar article-lapsed-timer nil)
1048 (defvar gnus-article-current-summary nil)
1050 (defvar gnus-article-mode-syntax-table
1051 (let ((table (copy-syntax-table text-mode-syntax-table)))
1052 (modify-syntax-entry ?- "w" table)
1053 (modify-syntax-entry ?> ")" table)
1054 (modify-syntax-entry ?< "(" table)
1056 "Syntax table used in article mode buffers.
1057 Initialized from `text-mode-syntax-table.")
1059 (defvar gnus-save-article-buffer nil)
1061 (defvar gnus-article-mode-line-format-alist
1062 (nconc '((?w (gnus-article-wash-status) ?s)
1063 (?m (gnus-article-mime-part-status) ?s))
1064 gnus-summary-mode-line-format-alist))
1066 (defvar gnus-number-of-articles-to-be-saved nil)
1068 (defvar gnus-inhibit-hiding nil)
1070 (defsubst gnus-article-hide-text (b e props)
1071 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1072 (add-text-properties b e props)
1073 (when (memq 'intangible props)
1075 (max (1- b) (point-min))
1076 b 'intangible (cddr (memq 'intangible props)))))
1077 (defsubst gnus-article-unhide-text (b e)
1078 "Remove hidden text properties from region between B and E."
1079 (remove-text-properties b e gnus-hidden-properties)
1080 (when (memq 'intangible gnus-hidden-properties)
1081 (put-text-property (max (1- b) (point-min))
1082 b 'intangible nil)))
1084 (defun gnus-article-hide-text-type (b e type)
1085 "Hide text of TYPE between B and E."
1086 (push type gnus-article-wash-types)
1087 (gnus-article-hide-text
1088 b e (cons 'article-type (cons type gnus-hidden-properties))))
1090 (defun gnus-article-unhide-text-type (b e type)
1091 "Unhide text of TYPE between B and E."
1092 (setq gnus-article-wash-types
1093 (delq type gnus-article-wash-types))
1094 (remove-text-properties
1095 b e (cons 'article-type (cons type gnus-hidden-properties)))
1096 (when (memq 'intangible gnus-hidden-properties)
1097 (put-text-property (max (1- b) (point-min))
1098 b 'intangible nil)))
1100 (defun gnus-article-hide-text-of-type (type)
1101 "Hide text of TYPE in the current buffer."
1103 (let ((b (point-min))
1105 (while (setq b (text-property-any b e 'article-type type))
1106 (add-text-properties b (incf b) gnus-hidden-properties)))))
1108 (defun gnus-article-delete-text-of-type (type)
1109 "Delete text of TYPE in the current buffer."
1111 (let ((b (point-min)))
1112 (while (setq b (text-property-any b (point-max) 'article-type type))
1114 b (or (text-property-not-all b (point-max) 'article-type type)
1117 (defun gnus-article-delete-invisible-text ()
1118 "Delete all invisible text in the current buffer."
1120 (let ((b (point-min)))
1121 (while (setq b (text-property-any b (point-max) 'invisible t))
1123 b (or (text-property-not-all b (point-max) 'invisible t)
1126 (defun gnus-article-text-type-exists-p (type)
1127 "Say whether any text of type TYPE exists in the buffer."
1128 (text-property-any (point-min) (point-max) 'article-type type))
1130 (defsubst gnus-article-header-rank ()
1131 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1132 (let ((list gnus-sorted-header-list)
1135 (when (looking-at (car list))
1137 (setq list (cdr list))
1141 (defun article-hide-headers (&optional arg delete)
1142 "Hide unwanted headers and possibly sort them as well."
1143 (interactive (gnus-article-hidden-arg))
1144 ;; Lars said that this function might be inhibited.
1145 (if (gnus-article-check-hidden-text 'headers arg)
1147 ;; Show boring headers as well.
1148 (gnus-article-show-hidden-text 'boring-headers)
1149 (when (eq 1 (point-min))
1150 (set-window-start (get-buffer-window (current-buffer)) 1)))
1151 (unless gnus-inhibit-hiding
1154 (let ((buffer-read-only nil)
1155 (inhibit-read-only t)
1156 (case-fold-search t)
1157 (max (1+ (length gnus-sorted-header-list)))
1158 (ignored (when (not gnus-visible-headers)
1159 (cond ((stringp gnus-ignored-headers)
1160 gnus-ignored-headers)
1161 ((listp gnus-ignored-headers)
1162 (mapconcat 'identity gnus-ignored-headers
1165 (cond ((stringp gnus-visible-headers)
1166 gnus-visible-headers)
1167 ((and gnus-visible-headers
1168 (listp gnus-visible-headers))
1169 (mapconcat 'identity gnus-visible-headers "\\|"))))
1170 (inhibit-point-motion-hooks t)
1172 ;; First we narrow to just the headers.
1173 (article-narrow-to-head)
1174 ;; Hide any "From " lines at the beginning of (mail) articles.
1175 (while (looking-at "From ")
1179 (delete-region (point-min) (point))
1180 (gnus-article-hide-text (point-min) (point)
1181 (nconc (list 'article-type 'headers)
1182 gnus-hidden-properties))))
1183 ;; Then treat the rest of the header lines.
1184 ;; Then we use the two regular expressions
1185 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1186 ;; select which header lines is to remain visible in the
1188 (while (re-search-forward "^[^ \t]*:" nil t)
1190 ;; Mark the rank of the header.
1192 (point) (1+ (point)) 'message-rank
1193 (if (or (and visible (looking-at visible))
1195 (not (looking-at ignored))))
1196 (gnus-article-header-rank)
1199 (message-sort-headers-1)
1200 (when (setq beg (text-property-any
1201 (point-min) (point-max) 'message-rank (+ 2 max)))
1202 ;; We delete or make invisible the unwanted headers.
1203 (push 'headers gnus-article-wash-types)
1206 (add-text-properties
1207 (point-min) (+ 5 (point-min))
1208 '(article-type headers dummy-invisible t))
1209 (delete-region beg (point-max)))
1210 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1213 (defun article-hide-boring-headers (&optional arg)
1214 "Toggle hiding of headers that aren't very interesting.
1215 If given a negative prefix, always show; if given a positive prefix,
1217 (interactive (gnus-article-hidden-arg))
1218 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1219 (not gnus-show-all-headers))
1222 (let ((buffer-read-only nil)
1223 (list gnus-boring-article-headers)
1224 (inhibit-point-motion-hooks t)
1226 (article-narrow-to-head)
1228 (setq elem (pop list))
1229 (goto-char (point-min))
1231 ;; Hide empty headers.
1233 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1235 (gnus-article-hide-text-type
1236 (progn (beginning-of-line) (point))
1239 (if (re-search-forward "^[^ \t]" nil t)
1243 ;; Hide boring Newsgroups header.
1244 ((eq elem 'newsgroups)
1245 (when (equal (gnus-fetch-field "newsgroups")
1246 (gnus-group-real-name
1247 (if (boundp 'gnus-newsgroup-name)
1250 (gnus-article-hide-header "newsgroups")))
1251 ((eq elem 'followup-to)
1252 (when (equal (message-fetch-field "followup-to")
1253 (message-fetch-field "newsgroups"))
1254 (gnus-article-hide-header "followup-to")))
1255 ((eq elem 'reply-to)
1256 (let ((from (message-fetch-field "from"))
1257 (reply-to (message-fetch-field "reply-to")))
1262 (nth 1 (funcall gnus-extract-address-components from))
1263 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1264 (gnus-article-hide-header "reply-to"))))
1266 (let ((date (message-fetch-field "date")))
1268 (< (days-between (current-time-string) date)
1270 (gnus-article-hide-header "date"))))
1272 (let ((to (message-fetch-field "to"))
1273 (cc (message-fetch-field "cc")))
1274 (when (> (length to) 1024)
1275 (gnus-article-hide-header "to"))
1276 (when (> (length cc) 1024)
1277 (gnus-article-hide-header "cc"))))
1281 (goto-char (point-min))
1282 (while (re-search-forward "^to:" nil t)
1283 (setq to-count (1+ to-count)))
1284 (when (> to-count 1)
1285 (while (> to-count 0)
1286 (goto-char (point-min))
1288 (re-search-forward "^to:" nil nil to-count)
1290 (narrow-to-region (point) (point-max))
1291 (gnus-article-hide-header "to"))
1292 (setq to-count (1- to-count))))
1293 (goto-char (point-min))
1294 (while (re-search-forward "^cc:" nil t)
1295 (setq cc-count (1+ cc-count)))
1296 (when (> cc-count 1)
1297 (while (> cc-count 0)
1298 (goto-char (point-min))
1300 (re-search-forward "^cc:" nil nil cc-count)
1302 (narrow-to-region (point) (point-max))
1303 (gnus-article-hide-header "cc"))
1304 (setq cc-count (1- cc-count)))))))))))))
1306 (defun gnus-article-hide-header (header)
1308 (goto-char (point-min))
1309 (when (re-search-forward (concat "^" header ":") nil t)
1310 (gnus-article-hide-text-type
1311 (progn (beginning-of-line) (point))
1314 (if (re-search-forward "^[^ \t]" nil t)
1319 (defun article-toggle-headers (&optional arg)
1320 "Toggle hiding of headers. If given a negative prefix, always show;
1321 if given a positive prefix, always hide."
1322 (interactive (gnus-article-hidden-arg))
1323 (let ((force (when (numberp arg)
1324 (cond ((> arg 0) 'always-hide)
1325 ((< arg 0) 'always-show))))
1326 (window (get-buffer-window gnus-article-buffer))
1327 (header-end (point-min))
1328 header-start field-end field-start
1329 (inhibit-point-motion-hooks t)
1330 (inhibit-read-only t)
1334 (while (and (setq header-start
1335 (text-property-any header-end (point-max)
1336 'article-treated-header t))
1338 (text-property-not-all header-start (point-max)
1339 'article-treated-header t)))
1340 (setq field-end header-start)
1342 (;; Hide exposed invisible fields.
1343 (and (not (eq 'always-show force))
1345 (text-property-any field-end header-end
1346 'exposed-invisible-field t)))
1347 (while (and field-start
1348 (setq field-end (text-property-not-all
1349 field-start header-end
1350 'exposed-invisible-field t)))
1351 (add-text-properties field-start field-end gnus-hidden-properties)
1352 (setq field-start (text-property-any field-end header-end
1353 'exposed-invisible-field t)))
1354 (put-text-property header-start header-end
1355 'exposed-invisible-field nil))
1356 (;; Expose invisible fields.
1357 (and (not (eq 'always-hide force))
1359 (text-property-any field-end header-end 'invisible t)))
1360 (while (and field-start
1361 (setq field-end (text-property-not-all
1362 field-start header-end
1364 ;; If the invisible text is not terminated with newline, we
1365 ;; won't expose it. Because it may be created by x-face-mule.
1366 ;; BTW, XEmacs sometimes fail in putting a invisible text
1367 ;; property with `gnus-article-hide-text' (really?). In that
1368 ;; case, the invisible text might be started from the middle of
1369 ;; a line so we will expose the sort of thing.
1370 (when (or (not (or (eq header-start field-start)
1371 (eq ?\n (char-before field-start))))
1372 (eq ?\n (char-before field-end)))
1373 (remove-text-properties field-start field-end
1374 gnus-hidden-properties)
1375 (put-text-property field-start field-end
1376 'exposed-invisible-field t))
1377 (setq field-start (text-property-any field-end header-end
1380 (not (eq 'always-show force))
1381 (narrow-to-region header-start header-end)
1382 (article-hide-headers)
1383 ;; Re-display X-Face image under XEmacs.
1384 (when (and gnus-xemacs
1385 (gnus-functionp gnus-article-x-face-command))
1386 (let ((func (cadr (assq 'gnus-treat-display-xface
1387 gnus-treatment-function-alist)))
1389 (when (and (not gnus-inhibit-treatment)
1391 (gnus-treat-predicate gnus-treat-display-xface))
1393 (put-text-property header-start header-end 'read-only nil))))
1396 (goto-char (point-min))
1398 (set-window-start window (point-min))))))
1400 (defvar gnus-article-normalized-header-length 40
1401 "Length of normalized headers.")
1403 (defun article-normalize-headers ()
1404 "Make all header lines 40 characters long."
1406 (let ((buffer-read-only nil)
1410 (article-narrow-to-head)
1413 ((< (setq column (- (gnus-point-at-eol) (point)))
1414 gnus-article-normalized-header-length)
1416 (insert (make-string
1417 (- gnus-article-normalized-header-length column)
1419 ((> column gnus-article-normalized-header-length)
1420 (gnus-put-text-property
1422 (forward-char gnus-article-normalized-header-length)
1429 (forward-line 1))))))
1431 (defun article-treat-dumbquotes ()
1432 "Translate M******** sm*rtq**t*s into proper text.
1433 Note that this function guesses whether a character is a sm*rtq**t* or
1434 not, so it should only be used interactively."
1436 (article-translate-strings gnus-article-dumbquotes-map))
1438 (defun article-translate-characters (from to)
1439 "Translate all characters in the body of the article according to FROM and TO.
1440 FROM is a string of characters to translate from; to is a string of
1441 characters to translate to."
1443 (when (article-goto-body)
1444 (let ((buffer-read-only nil)
1445 (x (make-string 225 ?x))
1447 (while (< (incf i) (length x))
1450 (while (< i (length from))
1451 (aset x (aref from i) (aref to i))
1453 (translate-region (point) (point-max) x)))))
1455 (defun article-translate-strings (map)
1456 "Translate all string in the body of the article according to MAP.
1457 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1459 (when (article-goto-body)
1460 (let ((buffer-read-only nil)
1462 (while (setq elem (pop map))
1464 (while (search-forward (car elem) nil t)
1465 (replace-match (cadr elem)))))))))
1467 (defun article-treat-overstrike ()
1468 "Translate overstrikes into bold text."
1471 (when (article-goto-body)
1472 (let ((buffer-read-only nil))
1473 (while (search-forward "\b" nil t)
1474 (let ((next (char-after))
1478 previous (char-after))
1482 ;; We do the boldification/underlining by hiding the
1483 ;; overstrikes and putting the proper text property
1487 (gnus-article-hide-text-type start (point) 'overstrike)
1488 (put-text-property (point) end 'face 'bold))
1490 (gnus-article-hide-text-type
1491 (1- (point)) (1+ (point)) 'overstrike)
1493 start (1- (point)) 'face 'underline))
1495 (gnus-article-hide-text-type start (point) 'overstrike)
1497 (point) end 'face 'underline)))))))))
1499 (defun article-fill-long-lines ()
1500 "Fill lines that are wider than the window width."
1503 (let ((buffer-read-only nil)
1504 (width (window-width (get-buffer-window (current-buffer)))))
1507 (let ((adaptive-fill-mode nil))
1510 (when (>= (current-column) (min fill-column width))
1511 (narrow-to-region (point) (gnus-point-at-bol))
1512 (fill-paragraph nil)
1513 (goto-char (point-max))
1515 (forward-line 1)))))))
1517 (defun article-capitalize-sentences ()
1518 "Capitalize the first word in each sentence."
1521 (let ((buffer-read-only nil)
1522 (paragraph-start "^[\n\^L]"))
1526 (forward-sentence)))))
1528 (defun article-remove-cr ()
1529 "Remove trailing CRs and then translate remaining CRs into LFs."
1532 (let ((buffer-read-only nil))
1533 (goto-char (point-min))
1534 (while (re-search-forward "\r+$" nil t)
1535 (replace-match "" t t))
1536 (goto-char (point-min))
1537 (while (search-forward "\r" nil t)
1538 (replace-match "\n" t t)))))
1540 (defun article-remove-trailing-blank-lines ()
1541 "Remove all trailing blank lines from the article."
1544 (let ((buffer-read-only nil))
1545 (goto-char (point-max))
1549 (while (and (not (bobp))
1550 (looking-at "^[ \t]*$")
1551 (not (gnus-annotation-in-region-p
1552 (point) (gnus-point-at-eol))))
1557 (defun article-display-x-face (&optional force)
1558 "Look for an X-Face header and display it if present."
1559 (interactive (list 'force))
1561 ;; Delete the old process, if any.
1562 (when (process-status "article-x-face")
1563 (delete-process "article-x-face"))
1564 (let ((inhibit-point-motion-hooks t)
1565 (case-fold-search t)
1568 (article-narrow-to-head)
1569 (goto-char (point-min))
1570 (setq from (message-fetch-field "from"))
1571 (goto-char (point-min))
1572 (while (and gnus-article-x-face-command
1575 ;; Check whether this face is censored.
1576 (not gnus-article-x-face-too-ugly)
1577 (and gnus-article-x-face-too-ugly from
1578 (not (string-match gnus-article-x-face-too-ugly
1580 ;; Has to be present.
1581 (re-search-forward "^X-Face:[ \t]*" nil t))
1582 ;; This used to try to do multiple faces (`while' instead of
1583 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1584 ;; work (b) it can crash some versions of Emacs (c) are
1585 ;; multiple faces really something to encourage?
1586 (when (stringp gnus-article-x-face-command)
1588 ;; We now have the area of the buffer where the X-Face is stored.
1591 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1592 ;; We display the face.
1593 (if (symbolp gnus-article-x-face-command)
1594 ;; The command is a lisp function, so we call it.
1595 (if (gnus-functionp gnus-article-x-face-command)
1596 (funcall gnus-article-x-face-command beg end)
1597 (error "%s is not a function" gnus-article-x-face-command))
1598 ;; The command is a string, so we interpret the command
1599 ;; as a, well, command, and fork it off.
1600 (let ((process-connection-type nil))
1601 (process-kill-without-query
1603 "article-x-face" nil shell-file-name shell-command-switch
1604 gnus-article-x-face-command))
1605 (process-send-region "article-x-face" beg end)
1606 (process-send-eof "article-x-face"))))))))))
1608 (defun article-decode-mime-words ()
1609 "Decode all MIME-encoded words in the article."
1612 (set-buffer gnus-article-buffer)
1613 (let ((inhibit-point-motion-hooks t)
1615 (mail-parse-charset gnus-newsgroup-charset)
1616 (mail-parse-ignored-charsets
1617 (save-excursion (set-buffer gnus-summary-buffer)
1618 gnus-newsgroup-ignored-charsets)))
1619 (mail-decode-encoded-word-region (point-min) (point-max)))))
1621 (defun article-decode-charset (&optional prompt)
1622 "Decode charset-encoded text in the article.
1623 If PROMPT (the prefix), prompt for a coding system to use."
1625 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1627 (mail-parse-charset gnus-newsgroup-charset)
1628 (mail-parse-ignored-charsets
1629 (save-excursion (condition-case nil
1630 (set-buffer gnus-summary-buffer)
1632 gnus-newsgroup-ignored-charsets))
1633 ct cte ctl charset format)
1636 (article-narrow-to-head)
1637 (setq ct (message-fetch-field "Content-Type" t)
1638 cte (message-fetch-field "Content-Transfer-Encoding" t)
1639 ctl (and ct (ignore-errors
1640 (mail-header-parse-content-type ct)))
1643 (mm-read-coding-system "Charset to decode: "))
1645 (mail-content-type-get ctl 'charset)))
1646 format (and ctl (mail-content-type-get ctl 'format)))
1648 (setq cte (mail-header-strip cte)))
1649 (if (and ctl (not (string-match "/" (car ctl))))
1651 (goto-char (point-max)))
1654 (narrow-to-region (point) (point-max))
1655 (when (and (eq mail-parse-charset 'gnus-decoded)
1656 (eq (mm-body-7-or-8) '8bit))
1657 ;; The text code could have been decoded.
1658 (setq charset mail-parse-charset))
1659 (when (and (or (not ctl)
1660 (equal (car ctl) "text/plain"))
1661 (not format)) ;; article with format will decode later.
1663 charset (and cte (intern (downcase
1664 (gnus-strip-whitespace cte))))
1667 (defun article-decode-encoded-words ()
1668 "Remove encoded-word encoding from headers."
1669 (let (buffer-read-only)
1670 (let ((charset (save-excursion
1671 (set-buffer gnus-summary-buffer)
1672 default-mime-charset)))
1673 (mime-decode-header-in-buffer charset)
1676 (defun article-de-quoted-unreadable (&optional force)
1677 "Translate a quoted-printable-encoded article.
1678 If FORCE, decode the article whether it is marked as quoted-printable
1680 (interactive (list 'force))
1682 (let ((buffer-read-only nil) type charset)
1683 (if (gnus-buffer-live-p gnus-original-article-buffer)
1684 (with-current-buffer gnus-original-article-buffer
1686 (gnus-fetch-field "content-transfer-encoding"))
1687 (let* ((ct (gnus-fetch-field "content-type"))
1690 (mail-header-parse-content-type ct)))))
1691 (setq charset (and ctl
1692 (mail-content-type-get ctl 'charset)))
1693 (if (stringp charset)
1694 (setq charset (intern (downcase charset)))))))
1696 (setq charset gnus-newsgroup-charset))
1698 (and type (string-match "quoted-printable" (downcase type))))
1700 (quoted-printable-decode-region (point) (point-max) charset)))))
1702 (defun article-de-base64-unreadable (&optional force)
1703 "Translate a base64 article.
1704 If FORCE, decode the article whether it is marked as base64 not."
1705 (interactive (list 'force))
1707 (let ((buffer-read-only nil) type charset)
1708 (if (gnus-buffer-live-p gnus-original-article-buffer)
1709 (with-current-buffer gnus-original-article-buffer
1711 (gnus-fetch-field "content-transfer-encoding"))
1712 (let* ((ct (gnus-fetch-field "content-type"))
1715 (mail-header-parse-content-type ct)))))
1716 (setq charset (and ctl
1717 (mail-content-type-get ctl 'charset)))
1718 (if (stringp charset)
1719 (setq charset (intern (downcase charset)))))))
1721 (setq charset gnus-newsgroup-charset))
1723 (and type (string-match "base64" (downcase type))))
1726 (narrow-to-region (point) (point-max))
1727 (base64-decode-region (point-min) (point-max))
1728 (if (mm-coding-system-p charset)
1729 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1734 (defun article-decode-HZ ()
1735 "Translate a HZ-encoded article."
1739 (let ((buffer-read-only nil))
1740 (rfc1843-decode-region (point-min) (point-max)))))
1742 (defun article-wash-html ()
1743 "Format an html article."
1746 (let ((buffer-read-only nil)
1748 (if (gnus-buffer-live-p gnus-original-article-buffer)
1749 (with-current-buffer gnus-original-article-buffer
1750 (let* ((ct (gnus-fetch-field "content-type"))
1753 (mail-header-parse-content-type ct)))))
1754 (setq charset (and ctl
1755 (mail-content-type-get ctl 'charset)))
1756 (if (stringp charset)
1757 (setq charset (intern (downcase charset)))))))
1759 (setq charset gnus-newsgroup-charset))
1761 (save-window-excursion
1763 (narrow-to-region (point) (point-max))
1765 (let ((w3-strict-width (window-width))
1766 (url-standalone-mode t))
1768 (w3-region (point-min) (point-max))
1771 (defun article-hide-list-identifiers ()
1772 "Remove list identifies from the Subject header.
1773 The `gnus-list-identifiers' variable specifies what to do."
1777 (let ((inhibit-point-motion-hooks t)
1779 (article-narrow-to-head)
1780 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1781 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1783 (goto-char (point-min))
1784 (when (re-search-forward
1785 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1786 " *\\)\\)+\\(Re: +\\)?\\)")
1788 (let ((s (or (match-string 3) (match-string 5))))
1789 (delete-region (match-beginning 1) (match-end 1))
1791 (goto-char (match-beginning 1))
1794 (defun article-hide-pgp ()
1795 "Remove any PGP headers and signatures in the current article."
1799 (let ((inhibit-point-motion-hooks t)
1800 buffer-read-only beg end)
1802 ;; Hide the "header".
1803 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1804 (push 'pgp gnus-article-wash-types)
1805 (delete-region (match-beginning 0) (match-end 0))
1806 ;; Remove armor headers (rfc2440 6.2)
1807 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1810 ;; Hide the actual signature.
1811 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1812 (setq end (1+ (match-beginning 0)))
1815 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1817 ;; Perhaps we shouldn't hide to the end of the buffer
1818 ;; if there is no end to the signature?
1820 ;; Hide "- " PGP quotation markers.
1822 (narrow-to-region beg end)
1823 (goto-char (point-min))
1824 (while (re-search-forward "^- " nil t)
1826 (match-beginning 0) (match-end 0)))
1828 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1830 (defun article-hide-pem (&optional arg)
1831 "Toggle hiding of any PEM headers and signatures in the current article.
1832 If given a negative prefix, always show; if given a positive prefix,
1834 (interactive (gnus-article-hidden-arg))
1835 (unless (gnus-article-check-hidden-text 'pem arg)
1837 (let (buffer-read-only end)
1838 (goto-char (point-min))
1839 ;; Hide the horrendously ugly "header".
1840 (when (and (search-forward
1841 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1843 (setq end (1+ (match-beginning 0))))
1844 (push 'pem gnus-article-wash-types)
1845 (gnus-article-hide-text-type
1847 (if (search-forward "\n\n" nil t)
1851 ;; Hide the trailer as well
1852 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1854 (gnus-article-hide-text-type
1855 (match-beginning 0) (match-end 0) 'pem)))))))
1857 (defun article-strip-banner ()
1858 "Strip the banner specified by the `banner' group parameter."
1862 (let ((inhibit-point-motion-hooks t)
1863 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1864 (gnus-signature-limit nil)
1865 buffer-read-only beg end)
1869 ((eq banner 'signature)
1870 (when (gnus-article-narrow-to-signature)
1873 (delete-region (point) (point-max))))
1875 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1876 (while (re-search-forward banner nil t)
1877 (delete-region (match-beginning 0) (match-end 0)))))
1879 (while (re-search-forward banner nil t)
1880 (delete-region (match-beginning 0) (match-end 0))))))))))
1882 (defun article-babel ()
1883 "Translate article using an online translation service."
1887 (set-buffer gnus-article-buffer)
1888 (when (article-goto-body)
1889 (let* ((buffer-read-only nil)
1892 (orig (buffer-substring start end))
1893 (trans (babel-as-string orig)))
1895 (narrow-to-region start end)
1896 (delete-region start end)
1899 (defun article-hide-signature (&optional arg)
1900 "Hide the signature in the current article.
1901 If given a negative prefix, always show; if given a positive prefix,
1903 (interactive (gnus-article-hidden-arg))
1909 (article-goto-body))
1910 (goto-char (point-min)))
1911 (unless (gnus-article-check-hidden-text 'signature arg)
1912 (let ((buffer-read-only nil)
1914 (while (setq button (text-property-any button (point-max)
1916 'gnus-signature-toggle))
1917 (setq button (text-property-not-all button (point-max)
1919 'gnus-signature-toggle))
1920 (when (and button (not (eobp)))
1921 (gnus-article-hide-text-type
1923 (next-single-property-change (1+ button) 'mime-view-entity
1927 (defun article-strip-headers-in-body ()
1928 "Strip offensive headers from bodies."
1932 (let ((case-fold-search t))
1933 (when (looking-at "x-no-archive:")
1934 (gnus-delete-line)))))
1936 (defun article-strip-leading-blank-lines ()
1937 "Remove all blank lines from the beginning of the article."
1940 (let ((inhibit-point-motion-hooks t)
1942 (when (article-goto-body)
1943 (while (and (not (eobp))
1944 (looking-at "[ \t]*$"))
1945 (gnus-delete-line))))))
1947 (defun article-narrow-to-head ()
1948 "Narrow the buffer to the head of the message.
1949 Point is left at the beginning of the narrowed-to region."
1951 (goto-char (point-min))
1952 (if (search-forward "\n\n" nil 1)
1955 (goto-char (point-min)))
1957 (defun article-goto-body ()
1958 "Place point at the start of the body."
1959 (goto-char (point-min))
1961 ;; This variable is only bound when dealing with separate
1963 (article-goto-body-goes-to-point-min-p
1965 ((search-forward "\n\n" nil t)
1968 (goto-char (point-max))
1971 (defun article-strip-multiple-blank-lines ()
1972 "Replace consecutive blank lines with one empty line."
1975 (let ((inhibit-point-motion-hooks t)
1977 ;; First make all blank lines empty.
1979 (while (re-search-forward "^[ \t]+$" nil t)
1980 (unless (gnus-annotation-in-region-p
1981 (match-beginning 0) (match-end 0))
1982 (replace-match "" nil t)))
1983 ;; Then replace multiple empty lines with a single empty line.
1985 (while (re-search-forward "\n\n\n+" nil t)
1986 (unless (gnus-annotation-in-region-p
1987 (match-beginning 0) (match-end 0))
1988 (replace-match "\n\n" t t))))))
1990 (defun article-strip-leading-space ()
1991 "Remove all white space from the beginning of the lines in the article."
1994 (let ((inhibit-point-motion-hooks t)
1997 (while (re-search-forward "^[ \t]+" nil t)
1998 (replace-match "" t t)))))
2000 (defun article-strip-trailing-space ()
2001 "Remove all white space from the end of the lines in the article."
2004 (let ((inhibit-point-motion-hooks t)
2007 (while (re-search-forward "[ \t]+$" nil t)
2008 (replace-match "" t t)))))
2010 (defun article-strip-blank-lines ()
2011 "Strip leading, trailing and multiple blank lines."
2013 (article-strip-leading-blank-lines)
2014 (article-remove-trailing-blank-lines)
2015 (article-strip-multiple-blank-lines))
2017 (defun article-strip-all-blank-lines ()
2018 "Strip all blank lines."
2021 (let ((inhibit-point-motion-hooks t)
2024 (while (re-search-forward "^[ \t]*\n" nil t)
2025 (replace-match "" t t)))))
2027 (defun gnus-article-narrow-to-signature ()
2028 "Narrow to the signature; return t if a signature is found, else nil."
2029 (let ((inhibit-point-motion-hooks t))
2030 (when (gnus-article-search-signature)
2032 ;; Check whether we have some limits to what we consider
2033 ;; to be a signature.
2034 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2035 (list gnus-signature-limit)))
2037 (while (setq limit (pop limits))
2038 (if (or (and (integerp limit)
2039 (< (- (point-max) (point)) limit))
2041 (< (count-lines (point) (point-max)) limit))
2042 (and (gnus-functionp limit)
2044 (and (stringp limit)
2045 (not (re-search-forward limit nil t))))
2046 () ; This limit did not succeed.
2050 (narrow-to-region (point) (point-max))
2053 (defun gnus-article-search-signature ()
2054 "Search the current buffer for the signature separator.
2055 Put point at the beginning of the signature separator."
2056 (let ((cur (point)))
2057 (goto-char (point-max))
2058 (if (if (stringp gnus-signature-separator)
2059 (re-search-backward gnus-signature-separator nil t)
2060 (let ((seps gnus-signature-separator))
2062 (not (re-search-backward (car seps) nil t)))
2069 (defun gnus-article-hidden-arg ()
2070 "Return the current prefix arg as a number, or 0 if no prefix."
2071 (list (if current-prefix-arg
2072 (prefix-numeric-value current-prefix-arg)
2075 (defun gnus-article-check-hidden-text (type arg)
2076 "Return nil if hiding is necessary.
2077 Arg can be nil or a number. Nil and positive means hide, negative
2078 means show, 0 means toggle."
2081 (let ((hide (gnus-article-hidden-text-p type)))
2087 (gnus-article-show-hidden-text type))
2089 (if (eq hide 'hidden)
2090 (gnus-article-show-hidden-text type)
2093 (defun gnus-article-hidden-text-p (type)
2094 "Say whether the current buffer contains hidden text of type TYPE."
2095 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2097 (not (get-text-property pos 'invisible))
2098 (not (get-text-property pos 'dummy-invisible)))
2100 (text-property-any (1+ pos) (point-max) 'article-type type)))
2105 (defun gnus-article-show-hidden-text (type &optional hide)
2106 "Show all hidden text of type TYPE.
2107 If HIDE, hide the text instead."
2109 (let ((buffer-read-only nil)
2110 (inhibit-point-motion-hooks t)
2113 (while (setq beg (text-property-any end (point-max) 'article-type type))
2116 (text-property-not-all beg (point-max) 'article-type type)
2119 (gnus-article-hide-text beg end gnus-hidden-properties)
2120 (gnus-article-unhide-text beg end))
2124 (defconst article-time-units
2125 `((year . ,(* 365.25 24 60 60))
2126 (week . ,(* 7 24 60 60))
2127 (day . ,(* 24 60 60))
2131 "Mapping from time units to seconds.")
2133 (defun article-date-ut (&optional type highlight header)
2134 "Convert DATE date to universal time in the current article.
2135 If TYPE is `local', convert to local time; if it is `lapsed', output
2136 how much time has lapsed since DATE. For `lapsed', the value of
2137 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2138 should replace the \"Date:\" one, or should be added below it."
2139 (interactive (list 'ut t))
2140 (let* ((header (or header
2141 (and (eq 1 (point-min))
2142 (mail-header-date (save-excursion
2143 (set-buffer gnus-summary-buffer)
2144 gnus-current-headers)))
2145 (message-fetch-field "date")
2147 (date (if (vectorp header) (mail-header-date header)
2149 (inhibit-point-motion-hooks t)
2150 bface eface date-pos)
2151 (when (and date (not (string= date "")))
2154 (article-narrow-to-head)
2155 (when (or (and (eq type 'lapsed)
2156 gnus-article-date-lapsed-new-header
2157 ;; Attempt to get the face of X-Sent first.
2158 (re-search-forward "^X-Sent:[ \t]" nil t))
2159 (re-search-forward "^Date:[ \t]" nil t)
2160 ;; If Date is missing, try again for X-Sent.
2161 (re-search-forward "^X-Sent:[ \t]" nil t))
2162 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2163 date (or (get-text-property (gnus-point-at-bol)
2166 eface (get-text-property (1- (gnus-point-at-eol))
2168 (let ((buffer-read-only nil))
2169 ;; Delete any old X-Sent headers.
2170 (when (setq date-pos
2171 (text-property-any (point-min) (point-max)
2172 'article-date-lapsed t))
2173 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2174 (delete-region (match-beginning 0)
2175 (progn (forward-line 1) (point))))
2176 (goto-char (point-min))
2177 ;; Delete any old Date headers.
2178 (while (re-search-forward "^Date:[ \t]" nil t)
2180 (setq date-pos (match-beginning 0)))
2181 (unless (and (eq type 'lapsed)
2182 gnus-article-date-lapsed-new-header)
2183 (delete-region (match-beginning 0)
2184 (progn (message-next-header) (point)))))
2187 (goto-char date-pos)
2189 ;; Possibly, Date has been deleted.
2191 (when (and (eq type 'lapsed)
2192 gnus-article-date-lapsed-new-header
2193 (looking-at "Date:"))
2195 (goto-char (point-min)))
2196 (insert (article-make-date-line date type))
2197 (when (eq type 'lapsed)
2198 (put-text-property (gnus-point-at-bol) (point)
2199 'article-date-lapsed t))
2203 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2204 (put-text-property (match-beginning 1) (1+ (match-end 1))
2205 'original-date date)
2206 (put-text-property (match-beginning 1) (1+ (match-end 1))
2208 (put-text-property (match-beginning 2) (match-end 2)
2211 (defun article-make-date-line (date type)
2212 "Return a DATE line of TYPE."
2213 (let ((time (condition-case ()
2217 ;; Convert to the local timezone. We have to slap a
2218 ;; `condition-case' round the calls to the timezone
2219 ;; functions since they aren't particularly resistant to
2222 (let ((tz (car (current-time-zone time))))
2223 (format "Date: %s %s%02d%02d" (current-time-string time)
2224 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2225 (/ (% (abs tz) 3600) 60))))
2226 ;; Convert to Universal Time.
2229 (current-time-string
2230 (let* ((e (parse-time-string date))
2231 (tm (apply 'encode-time e))
2233 (ls (- (cadr tm) (car (current-time-zone time)))))
2234 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2235 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2238 ;; Get the original date from the article.
2239 ((eq type 'original)
2240 (concat "Date: " (if (string-match "\n+$" date)
2241 (substring date 0 (match-beginning 0))
2243 ;; Let the user define the format.
2245 (if (gnus-functionp gnus-article-time-format)
2246 (funcall gnus-article-time-format time)
2249 (format-time-string gnus-article-time-format time))))
2252 (let ((tz (car (current-time-zone time))))
2255 (format-time-string "%Y%m%dT%H%M%S" time)
2256 (format "%s%02d%02d"
2257 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2258 (/ (% (abs tz) 3600) 60)))))
2259 ;; Do an X-Sent lapsed format.
2261 ;; If the date is seriously mangled, the timezone functions are
2262 ;; liable to bug out, so we ignore all errors.
2263 (let* ((now (current-time))
2264 (real-time (subtract-time now time))
2265 (real-sec (and real-time
2266 (+ (* (float (car real-time)) 65536)
2268 (sec (and real-time (abs real-sec)))
2278 ;; This is a bit convoluted, but basically we go
2279 ;; through the time units for years, weeks, etc,
2280 ;; and divide things to see whether that results
2281 ;; in positive answers.
2284 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2285 ;; The (remaining) seconds are too few to
2286 ;; be divided into this time unit.
2288 ;; It's big enough, so we output it.
2289 (setq sec (- sec (* num (cdr unit))))
2291 (concat (if prev ", " "") (int-to-string
2293 " " (symbol-name (car unit))
2294 (if (> num 1) "s" ""))
2296 article-time-units "")
2297 ;; If dates are odd, then it might appear like the
2298 ;; article was sent in the future.
2301 " in the future"))))))
2303 (error "Unknown conversion type: %s" type)))))
2305 (defun article-date-local (&optional highlight)
2306 "Convert the current article date to the local timezone."
2307 (interactive (list t))
2308 (article-date-ut 'local highlight))
2310 (defun article-date-original (&optional highlight)
2311 "Convert the current article date to what it was originally.
2312 This is only useful if you have used some other date conversion
2313 function and want to see what the date was before converting."
2314 (interactive (list t))
2315 (article-date-ut 'original highlight))
2317 (defun article-date-lapsed (&optional highlight)
2318 "Convert the current article date to time lapsed since it was sent."
2319 (interactive (list t))
2320 (article-date-ut 'lapsed highlight))
2322 (defun article-update-date-lapsed ()
2323 "Function to be run from a timer to update the lapsed time line."
2324 (let (deactivate-mark)
2329 (set-buffer (window-buffer w))
2330 (when (eq major-mode 'gnus-article-mode)
2331 (goto-char (point-min))
2332 (when (re-search-forward "^X-Sent:" nil t)
2333 (article-date-lapsed t))))
2336 (defun gnus-start-date-timer (&optional n)
2337 "Start a timer to update the X-Sent header in the article buffers.
2338 The numerical prefix says how frequently (in seconds) the function
2343 (gnus-stop-date-timer)
2344 (setq article-lapsed-timer
2345 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2347 (defun gnus-stop-date-timer ()
2348 "Stop the X-Sent timer."
2350 (when article-lapsed-timer
2351 (nnheader-cancel-timer article-lapsed-timer)
2352 (setq article-lapsed-timer nil)))
2354 (defun article-date-user (&optional highlight)
2355 "Convert the current article date to the user-defined format.
2356 This format is defined by the `gnus-article-time-format' variable."
2357 (interactive (list t))
2358 (article-date-ut 'user highlight))
2360 (defun article-date-iso8601 (&optional highlight)
2361 "Convert the current article date to ISO8601."
2362 (interactive (list t))
2363 (article-date-ut 'iso8601 highlight))
2365 (defun article-show-all ()
2366 "Show all hidden text in the article buffer."
2370 (let ((buffer-read-only nil))
2371 (gnus-article-unhide-text (point-min) (point-max))
2372 (gnus-remove-text-with-property 'gnus-prev)
2373 (gnus-remove-text-with-property 'gnus-next))))
2375 (defun article-show-all-headers ()
2376 "Show all hidden headers in the article buffer."
2381 (article-narrow-to-head)
2382 (let ((buffer-read-only nil))
2383 (gnus-article-unhide-text (point-min) (point-max))))))
2385 (defun article-emphasize (&optional arg)
2386 "Emphasize text according to `gnus-emphasis-alist'."
2387 (interactive (gnus-article-hidden-arg))
2388 (unless (gnus-article-check-hidden-text 'emphasis arg)
2392 (with-current-buffer gnus-summary-buffer
2393 gnus-article-emphasis-alist)
2395 gnus-emphasis-alist))
2396 (buffer-read-only nil)
2397 (props (append '(article-type emphasis)
2398 gnus-hidden-properties))
2399 regexp elem beg invisible visible face)
2402 (while (setq elem (pop alist))
2404 (setq regexp (car elem)
2405 invisible (nth 1 elem)
2406 visible (nth 2 elem)
2408 (while (re-search-forward regexp nil t)
2409 (when (and (match-beginning visible) (match-beginning invisible))
2410 (push 'emphasis gnus-article-wash-types)
2411 (gnus-article-hide-text
2412 (match-beginning invisible) (match-end invisible) props)
2413 (gnus-article-unhide-text-type
2414 (match-beginning visible) (match-end visible) 'emphasis)
2415 (gnus-put-text-property-excluding-newlines
2416 (match-beginning visible) (match-end visible) 'face face)
2417 (goto-char (match-end invisible)))))))))
2419 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2420 "Setup newsgroup emphasis alist."
2421 (unless gnus-article-emphasis-alist
2422 (let ((name (and gnus-newsgroup-name
2423 (gnus-group-real-name gnus-newsgroup-name))))
2424 (make-local-variable 'gnus-article-emphasis-alist)
2425 (setq gnus-article-emphasis-alist
2427 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2428 (while (setq elem (pop alist))
2429 (when (and name (string-match (car elem) name))
2431 highlight (copy-sequence (cdr elem)))))
2433 (copy-sequence highlight-words)
2434 (if gnus-newsgroup-name
2435 (copy-sequence (gnus-group-find-parameter
2436 gnus-newsgroup-name 'highlight-words t)))
2437 gnus-emphasis-alist)))))
2439 (defvar gnus-summary-article-menu)
2440 (defvar gnus-summary-post-menu)
2442 ;;; Saving functions.
2444 (defun gnus-article-save (save-buffer file &optional num)
2445 "Save the currently selected article."
2446 (unless gnus-save-all-headers
2447 ;; Remove headers according to `gnus-saved-headers'.
2448 (let ((gnus-visible-headers
2449 (or gnus-saved-headers gnus-visible-headers))
2450 (gnus-article-buffer save-buffer))
2452 (set-buffer save-buffer)
2453 (article-hide-headers 1 t))))
2454 (save-window-excursion
2455 (if (not gnus-default-article-saver)
2456 (error "No default saver is defined")
2457 ;; !!! Magic! The saving functions all save
2458 ;; `gnus-save-article-buffer' (or so they think), but we
2459 ;; bind that variable to our save-buffer.
2460 (set-buffer gnus-article-buffer)
2461 (let* ((gnus-save-article-buffer save-buffer)
2464 ((not gnus-prompt-before-saving) 'default)
2465 ((eq gnus-prompt-before-saving 'always) nil)
2467 (gnus-number-of-articles-to-be-saved
2468 (when (eq gnus-prompt-before-saving t)
2470 (set-buffer gnus-article-current-summary)
2471 (funcall gnus-default-article-saver filename)))))
2473 (defun gnus-read-save-file-name (prompt &optional filename
2474 function group headers variable)
2476 (funcall function group headers (symbol-value variable)))
2481 ((eq filename 'default)
2487 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2490 (if (and gnus-number-of-articles-to-be-saved
2491 (> gnus-number-of-articles-to-be-saved 1))
2492 (format "these %d articles"
2493 gnus-number-of-articles-to-be-saved)
2496 ;; Let the split methods have their say.
2498 ;; No split name was found.
2501 (concat prompt " (default "
2502 (file-name-nondirectory default-name) ") ")
2503 (file-name-directory default-name)
2505 ;; A single group name is returned.
2506 ((stringp split-name)
2508 (funcall function split-name headers
2509 (symbol-value variable)))
2511 (concat prompt " (default "
2512 (file-name-nondirectory default-name) ") ")
2513 (file-name-directory default-name)
2515 ;; A single split name was found
2516 ((= 1 (length split-name))
2517 (let* ((name (expand-file-name
2518 (car split-name) gnus-article-save-directory))
2519 (dir (cond ((file-directory-p name)
2520 (file-name-as-directory name))
2521 ((file-exists-p name) name)
2522 (t gnus-article-save-directory))))
2524 (concat prompt " (default " name ") ")
2526 ;; A list of splits was found.
2528 (setq split-name (nreverse split-name))
2530 (let ((file-name-history
2531 (nconc split-name file-name-history)))
2535 (concat prompt " (`M-p' for defaults) ")
2536 gnus-article-save-directory
2538 gnus-article-save-directory)))
2539 (car (push result file-name-history)))))))
2540 ;; Create the directory.
2541 (gnus-make-directory (file-name-directory file))
2542 ;; If we have read a directory, we append the default file name.
2543 (when (file-directory-p file)
2544 (setq file (expand-file-name (file-name-nondirectory default-name)
2545 (file-name-as-directory file))))
2546 ;; Possibly translate some characters.
2547 (nnheader-translate-file-chars file))))))
2548 (gnus-make-directory (file-name-directory result))
2549 (set variable result)))
2551 (defun gnus-article-archive-name (group)
2552 "Return the first instance of an \"Archive-name\" in the current buffer."
2553 (let ((case-fold-search t))
2554 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2555 (nnheader-concat gnus-article-save-directory
2556 (match-string 1)))))
2558 (defun gnus-article-nndoc-name (group)
2559 "If GROUP is an nndoc group, return the name of the parent group."
2560 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2561 (gnus-group-get-parameter group 'save-article-group)))
2563 (defun gnus-summary-save-in-rmail (&optional filename)
2564 "Append this article to Rmail file.
2565 Optional argument FILENAME specifies file name.
2566 Directory to save to is default to `gnus-article-save-directory'."
2567 (setq filename (gnus-read-save-file-name
2568 "Save %s in rmail file:" filename
2569 gnus-rmail-save-name gnus-newsgroup-name
2570 gnus-current-headers 'gnus-newsgroup-last-rmail))
2571 (gnus-eval-in-buffer-window gnus-save-article-buffer
2575 (gnus-output-to-rmail filename))))
2578 (defun gnus-summary-save-in-mail (&optional filename)
2579 "Append this article to Unix mail file.
2580 Optional argument FILENAME specifies file name.
2581 Directory to save to is default to `gnus-article-save-directory'."
2582 (setq filename (gnus-read-save-file-name
2583 "Save %s in Unix mail file:" filename
2584 gnus-mail-save-name gnus-newsgroup-name
2585 gnus-current-headers 'gnus-newsgroup-last-mail))
2586 (gnus-eval-in-buffer-window gnus-save-article-buffer
2590 (if (and (file-readable-p filename)
2591 (mail-file-babyl-p filename))
2592 (rmail-output-to-rmail-file filename t)
2593 (gnus-output-to-mail filename)))))
2596 (defun gnus-summary-save-in-file (&optional filename overwrite)
2597 "Append this article to file.
2598 Optional argument FILENAME specifies file name.
2599 Directory to save to is default to `gnus-article-save-directory'."
2600 (setq filename (gnus-read-save-file-name
2601 "Save %s in file:" filename
2602 gnus-file-save-name gnus-newsgroup-name
2603 gnus-current-headers 'gnus-newsgroup-last-file))
2604 (gnus-eval-in-buffer-window gnus-save-article-buffer
2608 (when (and overwrite
2609 (file-exists-p filename))
2610 (delete-file filename))
2611 (gnus-output-to-file filename))))
2614 (defun gnus-summary-write-to-file (&optional filename)
2615 "Write this article to a file.
2616 Optional argument FILENAME specifies file name.
2617 The directory to save in defaults to `gnus-article-save-directory'."
2618 (gnus-summary-save-in-file nil t))
2620 (defun gnus-summary-save-body-in-file (&optional filename)
2621 "Append this article body to a file.
2622 Optional argument FILENAME specifies file name.
2623 The directory to save in defaults to `gnus-article-save-directory'."
2624 (setq filename (gnus-read-save-file-name
2625 "Save %s body in file:" filename
2626 gnus-file-save-name gnus-newsgroup-name
2627 gnus-current-headers 'gnus-newsgroup-last-file))
2628 (gnus-eval-in-buffer-window gnus-save-article-buffer
2632 (when (article-goto-body)
2633 (narrow-to-region (point) (point-max)))
2634 (gnus-output-to-file filename))))
2637 (defun gnus-summary-save-in-pipe (&optional command)
2638 "Pipe this article to subprocess."
2640 (cond ((and (eq command 'default)
2641 gnus-last-shell-command)
2642 gnus-last-shell-command)
2646 "Shell command on %s: "
2647 (if (and gnus-number-of-articles-to-be-saved
2648 (> gnus-number-of-articles-to-be-saved 1))
2649 (format "these %d articles"
2650 gnus-number-of-articles-to-be-saved)
2652 gnus-last-shell-command))))
2653 (when (string-equal command "")
2654 (setq command gnus-last-shell-command))
2655 (gnus-eval-in-buffer-window gnus-article-buffer
2658 (shell-command-on-region (point-min) (point-max) command nil)))
2659 (setq gnus-last-shell-command command))
2661 ;;; Article file names when saving.
2663 (defun gnus-capitalize-newsgroup (newsgroup)
2664 "Capitalize NEWSGROUP name."
2665 (when (not (zerop (length newsgroup)))
2666 (concat (char-to-string (upcase (aref newsgroup 0)))
2667 (substring newsgroup 1))))
2669 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2670 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2671 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2672 Otherwise, it is like ~/News/news/group/num."
2675 (concat (if (gnus-use-long-file-name 'not-save)
2676 (gnus-capitalize-newsgroup newsgroup)
2677 (gnus-newsgroup-directory-form newsgroup))
2678 "/" (int-to-string (mail-header-number headers)))
2679 gnus-article-save-directory)))
2681 (string-equal (file-name-directory default)
2682 (file-name-directory last-file))
2683 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2685 (or last-file default))))
2687 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2688 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2689 If variable `gnus-use-long-file-name' is non-nil, it is
2690 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2693 (concat (if (gnus-use-long-file-name 'not-save)
2695 (gnus-newsgroup-directory-form newsgroup))
2696 "/" (int-to-string (mail-header-number headers)))
2697 gnus-article-save-directory)))
2699 (string-equal (file-name-directory default)
2700 (file-name-directory last-file))
2701 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2703 (or last-file default))))
2705 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2706 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2707 If variable `gnus-use-long-file-name' is non-nil, it is
2708 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2711 (if (gnus-use-long-file-name 'not-save)
2713 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2714 gnus-article-save-directory)))
2721 (setq afunc (car func)
2724 gfunc (intern (format "gnus-%s" func))))
2727 `(lambda (&optional interactive &rest args)
2728 ,(documentation afunc t)
2729 (interactive (list t))
2731 (set-buffer gnus-article-buffer)
2733 (call-interactively ',afunc)
2734 (apply ',afunc args))))))))
2735 '(article-hide-headers
2736 article-hide-boring-headers
2737 article-toggle-headers
2738 article-treat-overstrike
2739 article-fill-long-lines
2740 article-capitalize-sentences
2742 article-display-x-face
2743 article-de-quoted-unreadable
2744 article-de-base64-unreadable
2747 article-hide-list-identifiers
2749 article-strip-banner
2752 article-hide-signature
2753 article-strip-headers-in-body
2754 article-remove-trailing-blank-lines
2755 article-strip-leading-blank-lines
2756 article-strip-multiple-blank-lines
2757 article-strip-leading-space
2758 article-strip-trailing-space
2759 article-strip-blank-lines
2760 article-strip-all-blank-lines
2762 article-date-iso8601
2763 article-date-original
2765 article-decode-mime-words
2766 article-decode-charset
2767 article-decode-encoded-words
2771 article-treat-dumbquotes
2772 article-normalize-headers
2773 (article-show-all-headers . gnus-article-show-all-headers)
2774 (article-show-all . gnus-article-show-all))))
2777 ;;; Gnus article mode
2780 (put 'gnus-article-mode 'mode-class 'special)
2782 (gnus-define-keys gnus-article-mode-map
2783 " " gnus-article-goto-next-page
2784 "\177" gnus-article-goto-prev-page
2785 [delete] gnus-article-goto-prev-page
2786 [backspace] gnus-article-goto-prev-page
2787 "\C-c^" gnus-article-refer-article
2788 "h" gnus-article-show-summary
2789 "s" gnus-article-show-summary
2790 "\C-c\C-m" gnus-article-mail
2791 "?" gnus-article-describe-briefly
2792 "e" gnus-summary-edit-article
2793 "<" beginning-of-buffer
2795 "\C-c\C-i" gnus-info-find-node
2798 "\C-d" gnus-article-read-summary-keys
2799 "\M-*" gnus-article-read-summary-keys
2800 "\M-#" gnus-article-read-summary-keys
2801 "\M-^" gnus-article-read-summary-keys
2802 "\M-g" gnus-article-read-summary-keys)
2804 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2807 (unless (lookup-key gnus-article-mode-map key)
2808 (define-key gnus-article-mode-map key
2809 'gnus-article-read-summary-keys)))
2814 (let ((key (car elt)))
2815 (and (> (length key) 0)
2816 (not (eq 'menu-bar (aref key 0)))
2817 (symbolp (lookup-key gnus-summary-mode-map key))
2819 (accessible-keymaps gnus-summary-mode-map))
2823 (push (char-to-string c) keys)
2827 (defun gnus-article-make-menu-bar ()
2828 (gnus-turn-off-edit-menu 'article)
2829 (unless (boundp 'gnus-article-article-menu)
2831 gnus-article-article-menu gnus-article-mode-map ""
2833 ["Scroll forwards" gnus-article-goto-next-page t]
2834 ["Scroll backwards" gnus-article-goto-prev-page t]
2835 ["Show summary" gnus-article-show-summary t]
2836 ["Fetch Message-ID at point" gnus-article-refer-article t]
2837 ["Mail to address at point" gnus-article-mail t]
2838 ["Send a bug report" gnus-bug t]))
2841 gnus-article-treatment-menu gnus-article-mode-map ""
2843 ["Hide headers" gnus-article-toggle-headers t]
2844 ["Hide signature" gnus-article-hide-signature t]
2845 ["Hide citation" gnus-article-hide-citation t]
2846 ["Treat overstrike" gnus-article-treat-overstrike t]
2847 ["Remove carriage return" gnus-article-remove-cr t]
2848 ["Decode HZ" gnus-article-decode-HZ t]))
2850 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2852 (when (boundp 'gnus-summary-post-menu)
2853 (define-key gnus-article-mode-map [menu-bar post]
2854 (cons "Post" gnus-summary-post-menu)))
2856 (gnus-run-hooks 'gnus-article-menu-hook)))
2858 (defun gnus-article-mode ()
2859 "Major mode for displaying an article.
2861 All normal editing commands are switched off.
2863 The following commands are available in addition to all summary mode
2865 \\<gnus-article-mode-map>
2866 \\[gnus-article-next-page]\t Scroll the article one page forwards
2867 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2868 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2869 \\[gnus-article-show-summary]\t Display the summary buffer
2870 \\[gnus-article-mail]\t Send a reply to the address near point
2871 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2872 \\[gnus-info-find-node]\t Go to the Gnus info node"
2874 (when (gnus-visual-p 'article-menu 'menu)
2875 (gnus-article-make-menu-bar))
2876 (gnus-simplify-mode-line)
2877 (setq mode-name "Article")
2878 (setq major-mode 'gnus-article-mode)
2879 (make-local-variable 'minor-mode-alist)
2880 (unless (assq 'gnus-show-mime minor-mode-alist)
2881 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2882 (use-local-map gnus-article-mode-map)
2883 (gnus-update-format-specifications nil 'article-mode)
2884 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2885 (make-local-variable 'gnus-page-broken)
2886 (make-local-variable 'gnus-button-marker-list)
2887 (make-local-variable 'gnus-article-current-summary)
2888 (make-local-variable 'gnus-article-mime-handles)
2889 (make-local-variable 'gnus-article-decoded-p)
2890 (make-local-variable 'gnus-article-mime-handle-alist)
2891 (make-local-variable 'gnus-article-wash-types)
2892 (gnus-set-default-directory)
2893 (buffer-disable-undo)
2894 (setq buffer-read-only t)
2895 (set-syntax-table gnus-article-mode-syntax-table)
2896 (gnus-run-hooks 'gnus-article-mode-hook))
2898 (defun gnus-article-setup-buffer ()
2899 "Initialize the article buffer."
2900 (let* ((name (if gnus-single-article-buffer "*Article*"
2901 (concat "*Article " gnus-newsgroup-name "*")))
2903 (progn (string-match "\\*Article" name)
2904 (concat " *Original Article"
2905 (substring name (match-end 0))))))
2906 (setq gnus-article-buffer name)
2907 (setq gnus-original-article-buffer original)
2908 (setq gnus-article-mime-handle-alist nil)
2909 ;; This might be a variable local to the summary buffer.
2910 (unless gnus-single-article-buffer
2912 (set-buffer gnus-summary-buffer)
2913 (setq gnus-article-buffer name)
2914 (setq gnus-original-article-buffer original)
2915 (gnus-set-global-variables)))
2916 (gnus-article-setup-highlight-words)
2917 ;; Init original article buffer.
2919 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2920 (set-buffer-multibyte nil)
2921 (setq major-mode 'gnus-original-article-mode)
2922 (make-local-variable 'gnus-original-article))
2923 (if (get-buffer name)
2926 (buffer-disable-undo)
2927 (setq buffer-read-only t)
2928 (unless (eq major-mode 'gnus-article-mode)
2929 (gnus-article-mode))
2932 (set-buffer (gnus-get-buffer-create name))
2934 (make-local-variable 'gnus-summary-buffer)
2935 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2936 (current-buffer)))))
2938 ;; Set article window start at LINE, where LINE is the number of lines
2939 ;; from the head of the article.
2940 (defun gnus-article-set-window-start (&optional line)
2942 (get-buffer-window gnus-article-buffer t)
2944 (set-buffer gnus-article-buffer)
2945 (goto-char (point-min))
2948 (gnus-message 6 "Moved to bookmark")
2949 (search-forward "\n\n" nil t)
2953 ;;; @@ article filters
2956 (defun gnus-article-display-mime-message ()
2957 "Article display method for MIME message."
2958 ;; called from `gnus-original-article-buffer'.
2959 (let (charset all-headers)
2960 (with-current-buffer gnus-summary-buffer
2961 (setq charset default-mime-charset
2962 all-headers gnus-have-all-headers))
2963 (make-local-variable 'default-mime-charset)
2964 (setq default-mime-charset charset)
2965 (with-current-buffer (get-buffer-create gnus-article-buffer)
2966 (make-local-variable 'default-mime-charset)
2967 (setq default-mime-charset charset))
2968 (mime-display-message mime-message-structure
2969 gnus-article-buffer nil gnus-article-mode-map)
2971 (gnus-article-hide-headers nil -1)))
2972 (run-hooks 'gnus-mime-article-prepare-hook))
2974 (defun gnus-article-display-traditional-message ()
2975 "Article display method for traditional message."
2976 (set-buffer gnus-article-buffer)
2977 (let (buffer-read-only)
2979 (insert-buffer-substring gnus-original-article-buffer)))
2981 (defun gnus-article-make-full-mail-header (&optional number charset)
2982 "Create a new mail header structure in a raw article buffer."
2983 (unless (and number charset)
2984 (save-current-buffer
2985 (set-buffer gnus-summary-buffer)
2987 (setq number (or (cdr gnus-article-current) 0)))
2989 (setq charset (or default-mime-charset 'x-ctext)))))
2990 (goto-char (point-min))
2991 (let ((header-end (if (search-forward "\n\n" nil t)
2993 (goto-char (point-max))))
2994 (chars (- (point-max) (point)))
2995 (lines (count-lines (point) (point-max)))
2996 (default-mime-charset charset)
2998 (narrow-to-region (point-min) header-end)
2999 (setq xref (std11-fetch-field "xref"))
3001 (make-full-mail-header
3003 (std11-fetch-field "subject")
3004 (std11-fetch-field "from")
3005 (std11-fetch-field "date")
3006 (std11-fetch-field "message-id")
3007 (std11-fetch-field "references")
3010 (when xref (concat "Xref: " xref)))
3013 (defun gnus-article-prepare (article &optional all-headers header)
3014 "Prepare ARTICLE in article mode buffer.
3015 ARTICLE should either be an article number or a Message-ID.
3016 If ARTICLE is an id, HEADER should be the article headers.
3017 If ALL-HEADERS is non-nil, no headers are hidden."
3019 ;; Make sure we start in a summary buffer.
3020 (unless (eq major-mode 'gnus-summary-mode)
3021 (set-buffer gnus-summary-buffer))
3022 (setq gnus-summary-buffer (current-buffer))
3023 (let* ((gnus-article (if header (mail-header-number header) article))
3024 (summary-buffer (current-buffer))
3025 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3026 (group gnus-newsgroup-name)
3029 (gnus-article-setup-buffer)
3030 (set-buffer gnus-original-article-buffer)
3031 ;; Deactivate active regions.
3032 (when (and (boundp 'transient-mark-mode)
3033 transient-mark-mode)
3034 (setq mark-active nil))
3035 (if (not (setq result (let ((buffer-read-only nil))
3036 (gnus-request-article-this-buffer
3038 ;; There is no such article.
3040 (when (and (numberp article)
3041 (not (memq article gnus-newsgroup-sparse)))
3042 (setq gnus-article-current
3043 (cons gnus-newsgroup-name article))
3044 (set-buffer gnus-summary-buffer)
3045 (setq gnus-current-article article)
3046 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3048 (gnus-summary-set-agent-mark article)
3049 (message "Message marked for downloading"))
3050 (gnus-summary-mark-article article gnus-canceled-mark)
3051 (unless (memq article gnus-newsgroup-sparse)
3052 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3053 (if (or (eq result 'pseudo)
3054 (eq result 'nneething))
3057 (set-buffer summary-buffer)
3058 (push article gnus-newsgroup-history)
3059 (setq gnus-last-article gnus-current-article
3060 gnus-current-article 0
3061 gnus-current-headers nil
3062 gnus-article-current nil)
3063 (if (eq result 'nneething)
3064 (gnus-configure-windows 'summary)
3065 (gnus-configure-windows 'article))
3066 (gnus-set-global-variables))
3067 (let ((gnus-article-mime-handle-alist-1
3068 gnus-article-mime-handle-alist))
3069 (gnus-set-mode-line 'article)))
3070 ;; The result from the `request' was an actual article -
3071 ;; or at least some text that is now displayed in the
3073 (when (and (numberp article)
3074 (not (eq article gnus-current-article)))
3075 ;; Seems like a new article has been selected.
3076 ;; `gnus-current-article' must be an article number.
3078 (set-buffer summary-buffer)
3079 (push article gnus-newsgroup-history)
3080 (setq gnus-last-article gnus-current-article
3081 gnus-current-article article
3082 gnus-current-headers
3083 (gnus-summary-article-header gnus-current-article)
3084 gnus-article-current
3085 (cons gnus-newsgroup-name gnus-current-article))
3086 (unless (vectorp gnus-current-headers)
3087 (setq gnus-current-headers nil))
3088 (gnus-summary-goto-subject gnus-current-article)
3089 (when (gnus-summary-show-thread)
3090 ;; If the summary buffer really was folded, the
3091 ;; previous goto may not actually have gone to
3092 ;; the right article, but the thread root instead.
3094 (gnus-summary-goto-subject gnus-current-article))
3095 (gnus-run-hooks 'gnus-mark-article-hook)
3096 (gnus-set-mode-line 'summary)
3097 (when (gnus-visual-p 'article-highlight 'highlight)
3098 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3099 ;; Set the global newsgroup variables here.
3100 (gnus-set-global-variables)
3101 (setq gnus-have-all-headers
3102 (or all-headers gnus-show-all-headers))))
3104 (gnus-configure-windows 'article))
3105 (when (or (numberp article)
3107 (gnus-article-prepare-display)
3109 (goto-char (point-min))
3110 (setq gnus-page-broken
3111 (when gnus-break-pages
3112 (gnus-narrow-to-page)
3114 (let ((gnus-article-mime-handle-alist-1
3115 gnus-article-mime-handle-alist))
3116 (gnus-set-mode-line 'article))
3118 (set-window-point (get-buffer-window (current-buffer)) (point))
3121 (defun gnus-article-prepare-mime-display (&optional number)
3122 (goto-char (point-min))
3123 (when (re-search-forward "^[^\t ]+:" nil t)
3124 (goto-char (match-beginning 0)))
3125 (let ((entity (if (eq 1 (point-min))
3126 (get-text-property 1 'mime-view-entity)
3127 (get-text-property (point) 'mime-view-entity)))
3128 last-entity child-entity next type)
3129 (setq child-entity (mime-entity-children entity))
3131 (setq last-entity (nth (1- (length child-entity))
3133 (setq last-entity entity))
3135 (narrow-to-region (point)
3136 (if (search-forward "\n\n" nil t)
3139 (gnus-treat-article 'head)
3140 (put-text-property (point-min) (point-max) 'article-treated-header t)
3141 (goto-char (point-max)))
3142 (while (and (not (eobp)) entity)
3143 (setq next (set-marker
3145 (next-single-property-change (point) 'mime-view-entity
3147 (let ((types (mime-entity-content-type entity)))
3148 (while (eq 'multipart (mime-content-type-primary-type types))
3149 (setq entity (car (mime-entity-children entity))
3150 types (mime-entity-content-type entity)))
3152 (setq type (format "%s/%s"
3153 (mime-content-type-primary-type types)
3154 (mime-content-type-subtype types)))))
3155 (if (string-equal type "message/rfc822")
3158 (let ((children (mime-entity-children entity))
3161 (setq last-children (nth (1- (length children)) children))
3164 (not (eq last-children
3165 (get-text-property next 'mime-view-entity)))
3167 (next-single-property-change next
3169 nil (point-max)))))))
3170 (setq next (next-single-property-change next 'mime-view-entity
3173 (narrow-to-region (point) next)
3174 (gnus-article-prepare-mime-display)
3175 (goto-char (point-max)))
3176 (setq entity (get-text-property (point) 'mime-view-entity)))
3178 (narrow-to-region (point) next)
3179 ;; Kludge. We have to count true number, but for now,
3180 ;; part number is here only to achieve `last'.
3181 (gnus-treat-article nil 1
3182 (if (eq entity last-entity)
3185 (goto-char (point-max)))
3186 (setq entity (get-text-property next 'mime-view-entity))))))
3189 (defun gnus-article-prepare-display ()
3190 "Make the current buffer look like a nice article."
3191 (setq gnus-article-wash-types nil)
3192 (gnus-run-hooks 'gnus-tmp-internal-hook)
3193 (gnus-run-hooks 'gnus-article-prepare-hook)
3195 (let (mime-display-header-hook mime-display-text/plain-hook)
3196 (funcall (if gnus-show-mime
3198 (setq mime-message-structure gnus-current-headers)
3199 (mime-buffer-entity-set-buffer-internal
3200 mime-message-structure
3201 gnus-original-article-buffer)
3202 (mime-entity-set-representation-type-internal
3203 mime-message-structure 'mime-buffer-entity)
3204 (luna-send mime-message-structure
3205 'initialize-instance
3206 mime-message-structure)
3207 gnus-article-display-method-for-mime)
3208 gnus-article-display-method-for-traditional)))
3209 ;; Associate this article with the current summary buffer.
3210 (setq gnus-article-current-summary gnus-summary-buffer)
3211 ;; Call the treatment functions.
3212 (let ((inhibit-read-only t)
3217 (gnus-article-prepare-mime-display)
3218 (narrow-to-region (goto-char (point-min))
3219 (if (search-forward "\n\n" nil t)
3222 (gnus-treat-article 'head)
3223 (put-text-property (point-min) (point-max) 'article-treated-header t)
3224 (goto-char (point-max))
3226 (narrow-to-region (point) (point-max))
3227 (gnus-treat-article nil))
3228 (put-text-property (point-min) (point-max) 'read-only nil)))
3229 ;; Perform the article display hooks. Incidentally, this hook is
3230 ;; an obsolete variable by now.
3231 (gnus-run-hooks 'gnus-article-display-hook))
3233 (defun gnus-article-decode-article-as-default-mime-charset ()
3234 "Decode an article as `default-mime-charset'. It won't work if the
3235 value of the variable `gnus-show-mime' is non-nil."
3236 (unless gnus-show-mime
3237 (decode-mime-charset-region (point-min) (point-max)
3238 (with-current-buffer gnus-summary-buffer
3239 default-mime-charset))))
3242 ;;; Gnus MIME viewing functions
3245 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3246 "The following specs can be used:
3248 %T MIME type, along with additional info
3249 %n The `name' parameter
3250 %d The description, if any
3251 %l The length of the encoded part
3252 %p The part identifier number
3253 %e Dots if the part isn't displayed")
3255 (defvar gnus-mime-button-line-format-alist
3256 '((?t gnus-tmp-type ?s)
3257 (?T gnus-tmp-type-long ?s)
3258 (?n gnus-tmp-name ?s)
3259 (?d gnus-tmp-description ?s)
3261 (?l gnus-tmp-length ?d)
3262 (?e gnus-tmp-dots ?s)))
3264 (defvar gnus-mime-button-commands
3265 '((gnus-article-press-button "\r" "Toggle Display")
3266 (gnus-mime-view-part "v" "View Interactively...")
3267 (gnus-mime-view-part-as-type "t" "View As Type...")
3268 (gnus-mime-save-part "o" "Save...")
3269 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3270 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3271 (gnus-mime-internalize-part "E" "View Internally")
3272 (gnus-mime-externalize-part "e" "View Externally")
3273 (gnus-mime-pipe-part "|" "Pipe To Command...")
3274 (gnus-mime-action-on-part "." "Take action on the part")))
3276 (defun gnus-article-mime-part-status ()
3277 (with-current-buffer gnus-article-buffer
3278 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3279 (if (and entity (mime-entity-children entity))
3280 (format " (%d parts)" (length (mime-entity-children entity)))
3283 (defvar gnus-mime-button-map
3284 (let ((map (make-sparse-keymap)))
3285 (set-keymap-parent map gnus-article-mode-map)
3286 (define-key map gnus-mouse-2 'gnus-article-push-button)
3287 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3288 (dolist (c gnus-mime-button-commands)
3289 (define-key map (cadr c) (car c)))
3292 (defun gnus-mime-button-menu (event)
3293 "Construct a context-sensitive menu of MIME commands."
3296 (let ((pos (event-start event)))
3297 (set-buffer (window-buffer (posn-window pos)))
3298 (goto-char (posn-point pos))
3299 (gnus-article-check-buffer)
3300 (let ((response (x-popup-menu
3302 ("" ,@(mapcar (lambda (c)
3303 (cons (caddr c) (car c)))
3304 gnus-mime-button-commands))))))
3306 (call-interactively response))))))
3308 (defun gnus-mime-view-all-parts (&optional handles)
3309 "View all the MIME parts."
3311 (save-current-buffer
3312 (set-buffer gnus-article-buffer)
3313 (let ((handles (or handles gnus-article-mime-handles))
3314 (mail-parse-charset gnus-newsgroup-charset)
3315 (mail-parse-ignored-charsets
3316 (save-excursion (set-buffer gnus-summary-buffer)
3317 gnus-newsgroup-ignored-charsets)))
3318 (if (stringp (car handles))
3319 (gnus-mime-view-all-parts (cdr handles))
3320 (mapcar 'mm-display-part handles)))))
3322 (defun gnus-mime-save-part ()
3323 "Save the MIME part under point."
3325 (gnus-article-check-buffer)
3326 (let ((data (get-text-property (point) 'gnus-data)))
3327 (mm-save-part data)))
3329 (defun gnus-mime-pipe-part ()
3330 "Pipe the MIME part under point to a process."
3332 (gnus-article-check-buffer)
3333 (let ((data (get-text-property (point) 'gnus-data)))
3334 (mm-pipe-part data)))
3336 (defun gnus-mime-view-part ()
3337 "Interactively choose a viewing method for the MIME part under point."
3339 (gnus-article-check-buffer)
3340 (let ((data (get-text-property (point) 'gnus-data)))
3341 (mm-interactively-view-part data)))
3343 (defun gnus-mime-view-part-as-type-internal ()
3344 (gnus-article-check-buffer)
3345 (let* ((name (mail-content-type-get
3346 (mm-handle-type (get-text-property (point) 'gnus-data))
3348 (def-type (and name (mm-default-file-encoding name))))
3349 (and def-type (cons def-type 0))))
3351 (defun gnus-mime-view-part-as-type (mime-type)
3352 "Choose a MIME media type, and view the part as such."
3354 (list (completing-read
3355 "View as MIME type: "
3356 (mapcar #'list (mailcap-mime-types))
3358 (gnus-mime-view-part-as-type-internal))))
3359 (gnus-article-check-buffer)
3360 (let ((handle (get-text-property (point) 'gnus-data)))
3361 (gnus-mm-display-part
3362 (mm-make-handle (mm-handle-buffer handle)
3363 (cons mime-type (cdr (mm-handle-type handle)))
3364 (mm-handle-encoding handle)
3365 (mm-handle-undisplayer handle)
3366 (mm-handle-disposition handle)
3367 (mm-handle-description handle)
3368 (mm-handle-cache handle)
3369 (mm-handle-id handle)))))
3371 (defun gnus-mime-copy-part (&optional handle)
3372 "Put the the MIME part under point into a new buffer."
3374 (gnus-article-check-buffer)
3375 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3376 (contents (mm-get-part handle))|
3377 (base (file-name-nondirectory
3379 (mail-content-type-get (mm-handle-type handle) 'name)
3380 (mail-content-type-get (mm-handle-type handle)
3383 (buffer (generate-new-buffer base)))
3384 (switch-to-buffer buffer)
3386 ;; We do it this way to make `normal-mode' set the appropriate mode.
3389 (setq buffer-file-name (expand-file-name base))
3391 (setq buffer-file-name nil))
3392 (goto-char (point-min))))
3394 (defun gnus-mime-inline-part (&optional handle arg)
3395 "Insert the MIME part under point into the current buffer."
3396 (interactive (list nil current-prefix-arg))
3397 (gnus-article-check-buffer)
3398 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3402 (if (mm-handle-undisplayer handle)
3403 (mm-remove-part handle)
3404 (setq contents (mm-get-part handle))
3407 (setq charset (or (mail-content-type-get
3408 (mm-handle-type handle) 'charset)
3409 gnus-newsgroup-charset)))
3413 gnus-summary-show-article-charset-alist))
3414 (read-coding-system "Charset: ")))))
3416 (mm-insert-inline handle (if charset
3417 (mm-decode-coding-string contents charset)
3421 (defun gnus-mime-externalize-part (&optional handle)
3422 "View the MIME part under point with an external viewer."
3424 (gnus-article-check-buffer)
3425 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3426 (mm-user-display-methods nil)
3427 (mm-inlined-types nil)
3428 (mail-parse-charset gnus-newsgroup-charset)
3429 (mail-parse-ignored-charsets
3430 (save-excursion (set-buffer gnus-summary-buffer)
3431 gnus-newsgroup-ignored-charsets)))
3432 (if (mm-handle-undisplayer handle)
3433 (mm-remove-part handle)
3434 (mm-display-part handle))))
3436 (defun gnus-mime-internalize-part (&optional handle)
3437 "View the MIME part under point with an internal viewer.
3438 In no internal viewer is available, use an external viewer."
3440 (gnus-article-check-buffer)
3441 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3442 (mm-inlined-types '(".*"))
3443 (mm-inline-large-images t)
3444 (mail-parse-charset gnus-newsgroup-charset)
3445 (mail-parse-ignored-charsets
3446 (save-excursion (set-buffer gnus-summary-buffer)
3447 gnus-newsgroup-ignored-charsets)))
3448 (if (mm-handle-undisplayer handle)
3449 (mm-remove-part handle)
3450 (mm-display-part handle))))
3452 (defun gnus-mime-action-on-part (&optional action)
3453 "Do something with the MIME attachment at \(point\)."
3455 (list (completing-read "Action: " gnus-mime-action-alist)))
3456 (gnus-article-check-buffer)
3457 (let ((action-pair (assoc action gnus-mime-action-alist)))
3459 (funcall (cdr action-pair)))))
3462 (defun gnus-article-part-wrapper (n function)
3463 (save-current-buffer
3464 (set-buffer gnus-article-buffer)
3465 (when (> n (length gnus-article-mime-handle-alist))
3466 (error "No such part"))
3467 (gnus-article-goto-part n)
3468 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3469 (funcall function handle))))
3471 (defun gnus-article-pipe-part (n)
3472 "Pipe MIME part N, which is the numerical prefix."
3474 (gnus-article-part-wrapper n 'mm-pipe-part))
3476 (defun gnus-article-save-part (n)
3477 "Save MIME part N, which is the numerical prefix."
3479 (gnus-article-part-wrapper n 'mm-save-part))
3481 (defun gnus-article-interactively-view-part (n)
3482 "View MIME part N interactively, which is the numerical prefix."
3484 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3486 (defun gnus-article-copy-part (n)
3487 "Copy MIME part N, which is the numerical prefix."
3489 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3491 (defun gnus-article-externalize-part (n)
3492 "View MIME part N externally, which is the numerical prefix."
3494 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3496 (defun gnus-article-inline-part (n)
3497 "Inline MIME part N, which is the numerical prefix."
3499 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3501 (defun gnus-article-mime-match-handle-first (condition)
3503 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3504 (while (setq ihandle (pop alist))
3506 ((functionp condition)
3507 (funcall condition (cdr ihandle)))
3508 ((eq condition 'undisplayed)
3509 (not (or (mm-handle-undisplayer (cdr ihandle))
3510 (equal (mm-handle-media-type (cdr ihandle))
3511 "multipart/alternative"))))
3512 ((eq condition 'undisplayed-alternative)
3513 (not (mm-handle-undisplayer (cdr ihandle))))
3515 (gnus-article-goto-part (car ihandle))
3516 (or (not n) (< (car ihandle) n)))
3517 (setq n (car ihandle))))
3521 (defun gnus-article-view-part (&optional n)
3522 "View MIME part N, which is the numerical prefix."
3524 (save-current-buffer
3525 (set-buffer gnus-article-buffer)
3526 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3527 gnus-article-mime-match-handle-function)))
3528 (when (> n (length gnus-article-mime-handle-alist))
3529 (error "No such part"))
3530 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3531 (when (gnus-article-goto-part n)
3532 (if (equal (car handle) "multipart/alternative")
3533 (gnus-article-press-button)
3534 (when (eq (gnus-mm-display-part handle) 'internal)
3535 (gnus-set-window-start)))))))
3537 (defun gnus-mm-display-part (handle)
3538 "Display HANDLE and fix MIME button."
3539 (let ((id (get-text-property (point) 'gnus-part))
3544 (let ((window (selected-window))
3545 (mail-parse-charset gnus-newsgroup-charset)
3546 (mail-parse-ignored-charsets
3547 (save-excursion (set-buffer gnus-summary-buffer)
3548 gnus-newsgroup-ignored-charsets)))
3551 (let ((win (get-buffer-window (current-buffer) t))
3554 (select-window win))
3557 (if (mm-handle-displayed-p handle)
3558 ;; This will remove the part.
3559 (mm-display-part handle)
3561 (narrow-to-region (point) (1+ (point)))
3562 (mm-display-part handle)
3563 ;; We narrow to the part itself and
3564 ;; then call the treatment functions.
3565 (goto-char (point-min))
3567 (narrow-to-region (point) (point-max))
3570 (1- (length gnus-article-mime-handles))
3571 (mm-handle-media-type handle)))))
3572 (select-window window))))
3574 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3575 (gnus-insert-mime-button
3576 handle id (list (mm-handle-displayed-p handle)))
3577 (goto-char point))))
3579 (defun gnus-article-goto-part (n)
3580 "Go to MIME part N."
3581 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3583 (goto-char point))))
3585 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3586 (let ((gnus-tmp-name
3587 (or (mail-content-type-get (mm-handle-type handle)
3589 (mail-content-type-get (mm-handle-disposition handle)
3592 (gnus-tmp-type (mm-handle-media-type handle))
3593 (gnus-tmp-description
3594 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3597 (if (if displayed (car displayed)
3598 (mm-handle-displayed-p handle))
3600 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3602 gnus-tmp-type-long b e)
3603 (when (string-match ".*/" gnus-tmp-name)
3604 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3605 (setq gnus-tmp-type-long (concat gnus-tmp-type
3606 (and (not (equal gnus-tmp-name ""))
3607 (concat "; " gnus-tmp-name))))
3608 (or (equal gnus-tmp-description "")
3609 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3614 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3615 `(local-map ,gnus-mime-button-map
3616 keymap ,gnus-mime-button-map
3617 gnus-callback gnus-mm-display-part
3618 gnus-part ,gnus-tmp-id
3619 article-type annotation
3622 (widget-convert-button
3625 :action 'gnus-widget-press-button
3626 :button-keymap gnus-mime-button-map
3628 (lambda (widget/window &optional overlay pos)
3629 ;; Needed to properly clear the message due to a bug in
3630 ;; wid-edit (XEmacs only).
3631 (if (boundp 'help-echo-owns-message)
3632 (setq help-echo-owns-message t))
3634 "%S: %s the MIME part; %S: more options"
3635 (aref gnus-mouse-2 0)
3636 ;; XEmacs will get a single widget arg; Emacs 21 will get
3637 ;; window, overlay, position.
3638 (if (mm-handle-displayed-p
3640 (with-current-buffer (overlay-buffer overlay)
3641 (widget-get (widget-at (overlay-start overlay))
3643 (widget-get widget/window :mime-handle)))
3645 (aref gnus-down-mouse-3 0))))))
3647 (defun gnus-widget-press-button (elems el)
3648 (goto-char (widget-get elems :from))
3649 (gnus-article-press-button))
3651 (defvar gnus-displaying-mime nil)
3653 (defun gnus-display-mime (&optional ihandles)
3654 "Display the MIME parts."
3656 (save-selected-window
3657 (let ((window (get-buffer-window gnus-article-buffer))
3660 (select-window window)
3661 ;; We have to do this since selecting the window
3662 ;; may change the point. So we set the window point.
3663 (set-window-point window point)))
3664 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3665 buffer-read-only handle name type b e display)
3666 (when (and (not ihandles)
3667 (not gnus-displaying-mime))
3668 ;; Top-level call; we clean up.
3669 (when gnus-article-mime-handles
3670 (mm-destroy-parts gnus-article-mime-handles)
3671 (setq gnus-article-mime-handle-alist nil));; A trick.
3672 (setq gnus-article-mime-handles handles)
3673 ;; We allow users to glean info from the handles.
3674 (when gnus-article-mime-part-function
3675 (gnus-mime-part-function handles)))
3677 (or (not (stringp (car handles)))
3680 (when (and (not ihandles)
3681 (not gnus-displaying-mime))
3682 ;; Clean up for mime parts.
3684 (delete-region (point) (point-max)))
3685 (let ((gnus-displaying-mime t))
3686 (gnus-mime-display-part handles)))
3689 (narrow-to-region (point) (point-max))
3690 (gnus-treat-article nil 1 1)
3693 ;; Highlight the headers.
3697 (narrow-to-region (point-min) (point))
3698 (gnus-treat-article 'head))))))))
3700 (defvar gnus-mime-display-multipart-as-mixed nil)
3702 (defun gnus-mime-display-part (handle)
3705 ((not (stringp (car handle)))
3706 (gnus-mime-display-single handle))
3707 ;; User-defined multipart
3708 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3709 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3711 ;; multipart/alternative
3712 ((and (equal (car handle) "multipart/alternative")
3713 (not gnus-mime-display-multipart-as-mixed))
3714 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3715 (push (cons id handle) gnus-article-mime-handle-alist)
3716 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3717 ;; multipart/related
3718 ((and (equal (car handle) "multipart/related")
3719 (not gnus-mime-display-multipart-as-mixed))
3720 ;;;!!!We should find the start part, but we just default
3721 ;;;!!!to the first part.
3722 (gnus-mime-display-part (cadr handle)))
3723 ;; Other multiparts are handled like multipart/mixed.
3725 (gnus-mime-display-mixed (cdr handle)))))
3727 (defun gnus-mime-part-function (handles)
3728 (if (stringp (car handles))
3729 (mapcar 'gnus-mime-part-function (cdr handles))
3730 (funcall gnus-article-mime-part-function handles)))
3732 (defun gnus-mime-display-mixed (handles)
3733 (mapcar 'gnus-mime-display-part handles))
3735 (defun gnus-mime-display-single (handle)
3736 (let ((type (mm-handle-media-type handle))
3737 (ignored gnus-ignored-mime-types)
3744 (when (string-match (pop ignored) type)
3745 (throw 'ignored nil)))
3746 (if (and (setq not-attachment
3747 (and (not (mm-inline-override-p handle))
3748 (or (not (mm-handle-disposition handle))
3749 (equal (car (mm-handle-disposition handle))
3751 (mm-attachment-override-p handle))))
3752 (mm-automatic-display-p handle)
3753 (or (mm-inlined-p handle)
3754 (mm-automatic-external-display-p type)))
3756 (when (equal (mm-handle-media-supertype handle) "text")
3758 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3759 (push (cons id handle) gnus-article-mime-handle-alist)
3760 (when (or (not display)
3761 (not (gnus-unbuttonized-mime-type-p type)))
3762 ;(gnus-article-insert-newline)
3763 (gnus-insert-mime-button
3764 handle id (list (or display (and not-attachment text))))
3765 (gnus-article-insert-newline)
3766 ;(gnus-article-insert-newline)
3768 (let ((beg (point)))
3774 (let ((mail-parse-charset gnus-newsgroup-charset)
3775 (mail-parse-ignored-charsets
3776 (save-excursion (condition-case ()
3777 (set-buffer gnus-summary-buffer)
3779 gnus-newsgroup-ignored-charsets)))
3780 (mm-display-part handle t))
3781 (goto-char (point-max)))
3782 ((and text not-attachment)
3786 (gnus-article-insert-newline)
3787 (mm-insert-inline handle (mm-get-part handle))
3788 (goto-char (point-max))))
3792 (narrow-to-region beg (point))
3794 nil (length gnus-article-mime-handle-alist)
3795 (1- (length gnus-article-mime-handles))
3796 (mm-handle-media-type handle)))))))))
3798 (defun gnus-unbuttonized-mime-type-p (type)
3799 "Say whether TYPE is to be unbuttonized."
3800 (unless gnus-inhibit-mime-unbuttonizing
3802 (let ((types gnus-unbuttonized-mime-types))
3804 (when (string-match (pop types) type)
3805 (throw 'found t)))))))
3807 (defun gnus-article-insert-newline ()
3808 "Insert a newline, but mark it as undeletable."
3809 (gnus-put-text-property
3810 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3812 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3813 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3816 handle buffer-read-only from props begend not-pref)
3817 (save-window-excursion
3820 (narrow-to-region (car ibegend)
3823 (goto-char (car ibegend))
3826 (delete-region (point-min) (point-max))
3827 (mm-remove-parts handles))
3828 (setq begend (list (point-marker)))
3830 (unless (setq not-pref (cadr (member preferred ihandles)))
3831 (setq not-pref (car ihandles)))
3833 (not (gnus-unbuttonized-mime-type-p
3834 "multipart/alternative")))
3835 (gnus-add-text-properties
3838 (insert (format "%d. " id))
3842 (unless ,(not ibegend)
3843 (setq gnus-article-mime-handle-alist
3844 ',gnus-article-mime-handle-alist))
3845 (gnus-mime-display-alternative
3846 ',ihandles ',not-pref ',begend ,id))
3847 local-map ,gnus-mime-button-map
3848 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3849 face ,gnus-article-button-face
3850 keymap ,gnus-mime-button-map
3853 (widget-convert-button 'link from (point)
3854 :action 'gnus-widget-press-button
3855 :button-keymap gnus-widget-button-keymap)
3857 (while (setq handle (pop handles))
3858 (gnus-add-text-properties
3861 (insert (format "(%c) %-18s"
3862 (if (equal handle preferred) ?* ? )
3863 (mm-handle-media-type handle)))
3867 (unless ,(not ibegend)
3868 (setq gnus-article-mime-handle-alist
3869 ',gnus-article-mime-handle-alist))
3870 (gnus-mime-display-alternative
3871 ',ihandles ',handle ',begend ,id))
3872 local-map ,gnus-mime-button-map
3873 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3874 face ,gnus-article-button-face
3875 keymap ,gnus-mime-button-map
3878 (widget-convert-button 'link from (point)
3879 :action 'gnus-widget-press-button
3880 :button-keymap gnus-widget-button-keymap)
3884 (if (stringp (car preferred))
3885 (gnus-display-mime preferred)
3886 (let ((mail-parse-charset gnus-newsgroup-charset)
3887 (mail-parse-ignored-charsets
3888 (save-excursion (set-buffer gnus-summary-buffer)
3889 gnus-newsgroup-ignored-charsets)))
3890 (mm-display-part preferred)
3894 (narrow-to-region (car begend) (point-max))
3896 nil (length gnus-article-mime-handle-alist)
3897 (1- (length gnus-article-mime-handles))
3898 (mm-handle-media-type handle))))))
3899 (goto-char (point-max))
3900 (setcdr begend (point-marker)))))
3902 (goto-char point))))
3904 (defun gnus-article-wash-status ()
3905 "Return a string which display status of article washing."
3907 (set-buffer gnus-article-buffer)
3908 (let ((cite (memq 'cite gnus-article-wash-types))
3909 (headers (memq 'headers gnus-article-wash-types))
3910 (boring (memq 'boring-headers gnus-article-wash-types))
3911 (pgp (memq 'pgp gnus-article-wash-types))
3912 (pem (memq 'pem gnus-article-wash-types))
3913 (signature (memq 'signature gnus-article-wash-types))
3914 (overstrike (memq 'overstrike gnus-article-wash-types))
3915 (emphasis (memq 'emphasis gnus-article-wash-types)))
3916 (format "%c%c%c%c%c%c%c"
3918 (if (or headers boring) ?h ? )
3919 (if (or pgp pem) ?p ? )
3920 (if signature ?s ? )
3921 (if overstrike ?o ? )
3922 (if gnus-show-mime ?m ? )
3923 (if emphasis ?e ? )))))
3925 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3927 (defun gnus-article-maybe-hide-headers ()
3928 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3929 Provided for backwards compatibility."
3930 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3931 (not (save-excursion (set-buffer gnus-summary-buffer)
3932 gnus-have-all-headers)))
3933 (not gnus-inhibit-hiding))
3934 (gnus-article-hide-headers)))
3938 (defun gnus-output-to-file (file-name)
3939 "Append the current article to a file named FILE-NAME."
3940 (let ((artbuf (current-buffer)))
3942 (insert-buffer-substring artbuf)
3943 ;; Append newline at end of the buffer as separator, and then
3945 (goto-char (point-max))
3947 (write-region-as-binary (point-min) (point-max) file-name 'append)
3950 (defun gnus-narrow-to-page (&optional arg)
3951 "Narrow the article buffer to a page.
3952 If given a numerical ARG, move forward ARG pages."
3954 (setq arg (if arg (prefix-numeric-value arg) 0))
3956 (set-buffer gnus-article-buffer)
3957 (goto-char (point-min))
3959 ;; Remove any old next/prev buttons.
3960 (when (gnus-visual-p 'page-marker)
3961 (let ((buffer-read-only nil))
3962 (gnus-remove-text-with-property 'gnus-prev)
3963 (gnus-remove-text-with-property 'gnus-next)))
3966 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3968 (re-search-forward page-delimiter nil 'move arg)))
3969 (goto-char (match-end 0)))
3972 (if (re-search-forward page-delimiter nil 'move)
3975 (when (and (gnus-visual-p 'page-marker)
3976 (not (= (point-min) 1)))
3978 (goto-char (point-min))
3979 (gnus-insert-prev-page-button)))
3980 (when (and (gnus-visual-p 'page-marker)
3981 (< (+ (point-max) 2) (buffer-size)))
3983 (goto-char (point-max))
3984 (gnus-insert-next-page-button)))))
3986 ;; Article mode commands
3988 (defun gnus-article-goto-next-page ()
3989 "Show the next page of the article."
3991 (when (gnus-article-next-page)
3992 (goto-char (point-min))
3993 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3995 (defun gnus-article-goto-prev-page ()
3996 "Show the next page of the article."
3998 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3999 (gnus-article-prev-page nil)))
4001 (defun gnus-article-next-page (&optional lines)
4002 "Show the next page of the current article.
4003 If end of article, return non-nil. Otherwise return nil.
4004 Argument LINES specifies lines to be scrolled up."
4006 (let ((start (window-start))
4007 end-of-buffer end-of-page)
4009 (move-to-window-line -1)
4010 (if (<= (point) start)
4013 (setq start (point)))
4016 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4017 (and (pos-visible-in-window-p)
4018 (setq end-of-buffer t)))
4020 (setq end-of-page t)))
4022 (move-to-window-line lines)
4023 (unless (search-backward "\n\n" nil t)
4024 (setq start (point)))))
4025 (cond (end-of-buffer t)
4027 (gnus-narrow-to-page 1)
4031 (set-window-start (selected-window) start)
4032 (let (window-pixel-scroll-increment)
4036 (defun gnus-article-prev-page (&optional lines)
4037 "Show previous page of current article.
4038 Argument LINES specifies lines to be scrolled down."
4040 (let (beginning-of-buffer beginning-of-page)
4042 (move-to-window-line 0)
4043 (cond ((eq 1 (point))
4044 (setq beginning-of-buffer t))
4046 (setq beginning-of-page t))))
4047 (cond (beginning-of-buffer)
4049 (gnus-narrow-to-page -1))
4052 (let (window-pixel-scroll-increment)
4053 (scroll-down lines))
4054 (beginning-of-buffer
4055 (goto-char (point-min))))))))
4057 (defun gnus-article-refer-article ()
4058 "Read article specified by message-id around point."
4060 (let ((point (point)))
4061 (search-forward ">" nil t) ;Move point to end of "<....>".
4062 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4063 (let ((message-id (match-string 1)))
4065 (set-buffer gnus-summary-buffer)
4066 (gnus-summary-refer-article message-id))
4068 (error "No references around point"))))
4070 (defun gnus-article-show-summary ()
4071 "Reconfigure windows to show summary buffer."
4073 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4074 (error "There is no summary buffer for this article buffer")
4075 (gnus-article-set-globals)
4076 (gnus-configure-windows 'article)
4077 (gnus-summary-goto-subject gnus-current-article)
4078 (gnus-summary-position-point)))
4080 (defun gnus-article-describe-briefly ()
4081 "Describe article mode commands briefly."
4083 (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")))
4085 (defun gnus-article-summary-command ()
4086 "Execute the last keystroke in the summary buffer."
4088 (let ((obuf (current-buffer))
4089 (owin (current-window-configuration))
4091 (switch-to-buffer gnus-article-current-summary 'norecord)
4092 (setq func (lookup-key (current-local-map) (this-command-keys)))
4093 (call-interactively func)
4095 (set-window-configuration owin)
4096 (set-window-point (get-buffer-window (current-buffer)) (point))))
4098 (defun gnus-article-summary-command-nosave ()
4099 "Execute the last keystroke in the summary buffer."
4102 (pop-to-buffer gnus-article-current-summary 'norecord)
4103 (setq func (lookup-key (current-local-map) (this-command-keys)))
4104 (call-interactively func)))
4106 (defun gnus-article-check-buffer ()
4107 "Beep if not in an article buffer."
4108 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4109 (error "Command invoked outside of a Gnus article buffer")))
4111 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4112 "Read a summary buffer key sequence and execute it from the article buffer."
4114 (gnus-article-check-buffer)
4116 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4117 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4118 "=" "^" "\M-^" "|"))
4124 '("n" "Gn" "p" "Gp"))
4127 (set-buffer gnus-article-current-summary)
4128 (let (gnus-pick-mode)
4129 (push (or key last-command-event) unread-command-events)
4130 (setq keys (static-if (featurep 'xemacs)
4131 (events-to-keys (read-key-sequence nil))
4132 (read-key-sequence nil)))))
4135 (if (or (member keys nosaves)
4136 (member keys nosave-but-article)
4137 (member keys nosave-in-article))
4139 (save-window-excursion
4140 (pop-to-buffer gnus-article-current-summary 'norecord)
4141 ;; We disable the pick minor mode commands.
4142 (let (gnus-pick-mode)
4143 (setq func (lookup-key (current-local-map) keys))))
4147 (unless (member keys nosave-in-article)
4148 (set-buffer gnus-article-current-summary))
4149 (call-interactively func)
4150 (setq new-sum-point (point)))
4151 (when (member keys nosave-but-article)
4152 (pop-to-buffer gnus-article-buffer 'norecord)))
4153 ;; These commands should restore window configuration.
4154 (let ((obuf (current-buffer))
4155 (owin (current-window-configuration))
4157 (summary gnus-article-current-summary)
4158 func in-buffer selected)
4159 (if not-restore-window
4160 (pop-to-buffer summary 'norecord)
4161 (switch-to-buffer summary 'norecord))
4162 (setq in-buffer (current-buffer))
4163 ;; We disable the pick minor mode commands.
4164 (if (setq func (let (gnus-pick-mode)
4165 (lookup-key (current-local-map) keys)))
4167 (call-interactively func)
4168 (setq new-sum-point (point)))
4170 (when (eq in-buffer (current-buffer))
4171 (setq selected (gnus-summary-select-article))
4173 (unless not-restore-window
4174 (set-window-configuration owin))
4175 (when (eq selected 'old)
4177 (set-window-start (get-buffer-window (current-buffer))
4179 (set-window-point (get-buffer-window (current-buffer))
4181 (let ((win (get-buffer-window gnus-article-current-summary)))
4183 (set-window-point win new-sum-point))))))))
4185 (defun gnus-article-hide (&optional arg force)
4186 "Hide all the gruft in the current article.
4187 This means that PGP stuff, signatures, cited text and (some)
4188 headers will be hidden.
4189 If given a prefix, show the hidden text instead."
4190 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4191 (gnus-article-hide-headers arg)
4192 (gnus-article-hide-list-identifiers arg)
4193 (gnus-article-hide-pgp arg)
4194 (gnus-article-hide-citation-maybe arg force)
4195 (gnus-article-hide-signature arg))
4197 (defun gnus-article-maybe-highlight ()
4198 "Do some article highlighting if article highlighting is requested."
4199 (when (gnus-visual-p 'article-highlight 'highlight)
4200 (gnus-article-highlight-some)))
4202 (defun gnus-check-group-server ()
4203 ;; Make sure the connection to the server is alive.
4204 (unless (gnus-server-opened
4205 (gnus-find-method-for-group gnus-newsgroup-name))
4206 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4207 (gnus-request-group gnus-newsgroup-name t)))
4209 (defun gnus-request-article-this-buffer (article group)
4210 "Get an article and insert it into this buffer."
4211 (let (do-update-line sparse-header)
4215 (gnus-kill-all-overlays)
4216 (setq group (or group gnus-newsgroup-name))
4218 ;; Using `gnus-request-article' directly will insert the article into
4219 ;; `nntp-server-buffer' - so we'll save some time by not having to
4220 ;; copy it from the server buffer into the article buffer.
4222 ;; We only request an article by message-id when we do not have the
4223 ;; headers for it, so we'll have to get those.
4224 (when (stringp article)
4225 (gnus-read-header article))
4227 ;; If the article number is negative, that means that this article
4228 ;; doesn't belong in this newsgroup (possibly), so we find its
4229 ;; message-id and request it by id instead of number.
4230 (when (and (numberp article)
4232 (get-buffer gnus-summary-buffer)
4233 (gnus-buffer-exists-p gnus-summary-buffer))
4235 (set-buffer gnus-summary-buffer)
4236 (let ((header (gnus-summary-article-header article)))
4239 ((memq article gnus-newsgroup-sparse)
4240 ;; This is a sparse gap article.
4241 (setq do-update-line article)
4242 (setq article (mail-header-id header))
4243 (setq sparse-header (gnus-read-header article))
4244 (setq gnus-newsgroup-sparse
4245 (delq article gnus-newsgroup-sparse)))
4247 ;; It's a real article.
4248 (setq article (mail-header-id header)))
4250 ;; It is an extracted pseudo-article.
4251 (setq article 'pseudo)
4252 (gnus-request-pseudo-article header))))
4254 (let ((method (gnus-find-method-for-group
4255 gnus-newsgroup-name)))
4256 (when (and (eq (car method) 'nneething)
4258 (let ((dir (expand-file-name
4259 (mail-header-subject header)
4260 (file-name-as-directory
4261 (or (cadr (assq 'nneething-address method))
4263 (when (file-directory-p dir)
4264 (setq article 'nneething)
4265 (gnus-group-enter-directory dir))))))))
4268 ;; Refuse to select canceled articles.
4269 ((and (numberp article)
4271 (get-buffer gnus-summary-buffer)
4272 (gnus-buffer-exists-p gnus-summary-buffer)
4273 (eq (cdr (save-excursion
4274 (set-buffer gnus-summary-buffer)
4275 (assq article gnus-newsgroup-reads)))
4276 gnus-canceled-mark))
4278 ;; Check the backlog.
4279 ((and gnus-keep-backlog
4280 (gnus-backlog-request-article group article (current-buffer)))
4282 ;; Check asynchronous pre-fetch.
4283 ((gnus-async-request-fetched-article group article (current-buffer))
4284 (gnus-async-prefetch-next group article gnus-summary-buffer)
4285 (when (and (numberp article) gnus-keep-backlog)
4286 (gnus-backlog-enter-article group article (current-buffer)))
4289 ((and gnus-use-cache
4291 (gnus-cache-request-article article group))
4293 ;; Get the article and put into the article buffer.
4294 ((or (stringp article)
4296 (let ((gnus-override-method gnus-override-method)
4297 (methods (and (stringp article)
4298 gnus-refer-article-method))
4300 (buffer-read-only nil))
4305 (when (and (null gnus-override-method)
4307 (setq gnus-override-method (pop methods)))
4309 (when (eq gnus-override-method 'current)
4310 (setq gnus-override-method gnus-current-select-method))
4312 (gnus-kill-all-overlays)
4313 (let ((gnus-newsgroup-name group))
4314 (gnus-check-group-server))
4315 (when (gnus-request-article article group (current-buffer))
4316 (when (numberp article)
4317 (gnus-async-prefetch-next group article
4318 gnus-summary-buffer)
4319 (when gnus-keep-backlog
4320 (gnus-backlog-enter-article
4321 group article (current-buffer))))
4322 (setq result 'article))
4325 (setq gnus-override-method (pop methods))
4326 (setq result 'done))))
4327 (and (eq result 'article) 'article)))
4331 ;; Associate this article with the current summary buffer.
4332 (setq gnus-article-current-summary gnus-summary-buffer)
4334 ;; Take the article from the original article buffer
4335 ;; and place it in the buffer it's supposed to be in.
4336 (when (and (get-buffer gnus-article-buffer)
4337 (equal (buffer-name (current-buffer))
4338 (buffer-name (get-buffer gnus-article-buffer))))
4340 (if (get-buffer gnus-original-article-buffer)
4341 (set-buffer gnus-original-article-buffer)
4342 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4343 (set-buffer-multibyte nil)
4344 (buffer-disable-undo)
4345 (setq major-mode 'gnus-original-article-mode)
4346 (setq buffer-read-only t))
4347 (let (buffer-read-only)
4349 (insert-buffer-substring gnus-article-buffer))
4350 (setq gnus-original-article (cons group article)))
4353 (run-hooks 'gnus-article-decode-hook)
4354 ;; Mark article as decoded or not.
4355 (setq gnus-article-decoded-p gnus-article-decode-hook))
4357 ;; Update sparse articles.
4358 (when (and do-update-line
4359 (or (numberp article)
4361 (let ((buf (current-buffer)))
4362 (set-buffer gnus-summary-buffer)
4363 (gnus-summary-update-article do-update-line sparse-header)
4364 (gnus-summary-goto-subject do-update-line nil t)
4365 (set-window-point (get-buffer-window (current-buffer) t)
4367 (set-buffer buf))))))
4373 (defcustom gnus-article-edit-mode-hook nil
4374 "Hook run in article edit mode buffers."
4375 :group 'gnus-article-various
4378 (defcustom gnus-article-edit-article-setup-function
4379 'gnus-article-mime-edit-article-setup
4380 "Function called to setup an editing article buffer."
4381 :group 'gnus-article-various
4384 (defvar gnus-article-edit-done-function nil)
4386 (defvar gnus-article-edit-mode-map nil)
4388 ;; Should we be using derived.el for this?
4389 (unless gnus-article-edit-mode-map
4390 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4391 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4393 (gnus-define-keys gnus-article-edit-mode-map
4394 "\C-c\C-c" gnus-article-edit-done
4395 "\C-c\C-k" gnus-article-edit-exit)
4397 (gnus-define-keys (gnus-article-edit-wash-map
4398 "\C-c\C-w" gnus-article-edit-mode-map)
4399 "f" gnus-article-edit-full-stops))
4401 (defun gnus-article-edit-mode ()
4402 "Major mode for editing articles.
4403 This is an extended text-mode.
4405 \\{gnus-article-edit-mode-map}"
4407 (setq major-mode 'gnus-article-edit-mode)
4408 (setq mode-name "Article Edit")
4409 (use-local-map gnus-article-edit-mode-map)
4410 (make-local-variable 'gnus-article-edit-done-function)
4411 (make-local-variable 'gnus-prev-winconf)
4412 (setq buffer-read-only nil)
4413 (buffer-enable-undo)
4415 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4417 (defun gnus-article-edit (&optional force)
4418 "Edit the current article.
4419 This will have permanent effect only in mail groups.
4420 If FORCE is non-nil, allow editing of articles even in read-only
4423 (when (and (not force)
4424 (gnus-group-read-only-p))
4425 (error "The current newsgroup does not support article editing"))
4426 (gnus-article-date-original)
4427 (gnus-article-edit-article
4429 `(lambda (no-highlight)
4431 (gnus-summary-edit-article-done
4432 ,(or (mail-header-references gnus-current-headers) "")
4433 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4435 (defun gnus-article-edit-article (start-func exit-func)
4436 "Start editing the contents of the current article buffer."
4437 (let ((winconf (current-window-configuration)))
4438 (set-buffer gnus-article-buffer)
4439 (gnus-article-edit-mode)
4440 (funcall start-func)
4441 (gnus-configure-windows 'edit-article)
4442 (setq gnus-article-edit-done-function exit-func)
4443 (setq gnus-prev-winconf winconf)
4444 (when gnus-article-edit-article-setup-function
4445 (funcall gnus-article-edit-article-setup-function))
4446 (gnus-message 6 "C-c C-c to end edits")))
4448 (defun gnus-article-edit-done (&optional arg)
4449 "Update the article edits and exit."
4454 (when (article-goto-body)
4455 (let ((lines (count-lines (point) (point-max)))
4456 (length (- (point-max) (point)))
4457 (case-fold-search t)
4458 (body (copy-marker (point))))
4459 (goto-char (point-min))
4460 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4461 (delete-region (match-beginning 1) (match-end 1))
4462 (insert (number-to-string length)))
4463 (goto-char (point-min))
4464 (when (re-search-forward
4465 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4466 (delete-region (match-beginning 1) (match-end 1))
4467 (insert (number-to-string length)))
4468 (goto-char (point-min))
4469 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4470 (delete-region (match-beginning 1) (match-end 1))
4471 (insert (number-to-string lines)))))))
4472 (let ((func gnus-article-edit-done-function)
4473 (buf (current-buffer))
4474 (start (window-start)))
4475 (remove-hook 'gnus-article-mode-hook
4476 'gnus-article-mime-edit-article-unwind)
4477 (gnus-article-edit-exit)
4480 (let ((buffer-read-only nil))
4482 ;; The cache and backlog have to be flushed somewhat.
4483 (when gnus-keep-backlog
4484 (gnus-backlog-remove-article
4485 (car gnus-article-current) (cdr gnus-article-current)))
4486 ;; Flush original article as well.
4488 (when (get-buffer gnus-original-article-buffer)
4489 (set-buffer gnus-original-article-buffer)
4490 (setq gnus-original-article nil)))
4491 (when gnus-use-cache
4492 (gnus-cache-update-article
4493 (car gnus-article-current) (cdr gnus-article-current))))
4495 (set-window-start (get-buffer-window buf) start)
4496 (set-window-point (get-buffer-window buf) (point))))
4498 (defun gnus-article-edit-exit ()
4499 "Exit the article editing without updating."
4501 ;; We remove all text props from the article buffer.
4502 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4503 (curbuf (current-buffer))
4505 (window-start (window-start)))
4508 (let ((winconf gnus-prev-winconf))
4510 (set-window-configuration winconf)
4511 ;; Tippy-toe some to make sure that point remains where it was.
4512 (save-current-buffer
4514 (set-window-start (get-buffer-window (current-buffer)) window-start)
4517 (defun gnus-article-edit-full-stops ()
4518 "Interactively repair spacing at end of sentences."
4521 (goto-char (point-min))
4522 (search-forward-regexp "^$" nil t)
4523 (let ((case-fold-search nil))
4524 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4527 ;;; Article editing with MIME-Edit
4530 (defcustom gnus-article-mime-edit-article-setup-hook nil
4531 "Hook run after setting up a MIME editing article buffer."
4532 :group 'gnus-article-various
4535 (defun gnus-article-mime-edit-article-unwind ()
4536 "Unwind `gnus-article-buffer' if article editing was given up."
4537 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4538 (when mime-edit-mode-flag
4539 (mime-edit-exit 'nomime 'no-error)
4541 (when (featurep 'font-lock)
4542 (setq font-lock-defaults nil)
4543 (font-lock-mode 0)))
4545 (defun gnus-article-mime-edit-article-setup ()
4546 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4547 after replacing with the original article."
4548 (setq gnus-show-mime t)
4549 (setq gnus-article-edit-done-function
4550 `(lambda (&rest args)
4551 (when mime-edit-mode-flag
4554 (goto-char (point-min))
4555 (let (case-fold-search)
4556 (when (re-search-forward
4557 (format "^%s$" (regexp-quote mail-header-separator))
4559 (replace-match "")))
4560 (when (featurep 'font-lock)
4561 (setq font-lock-defaults nil)
4563 (apply ,gnus-article-edit-done-function args)
4564 (set-buffer gnus-original-article-buffer)
4566 (insert-buffer gnus-article-buffer)
4567 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4568 (gnus-article-prepare-display)))
4569 (substitute-key-definition
4570 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4571 gnus-article-edit-mode-map)
4573 (insert-buffer gnus-original-article-buffer)
4575 (when (featurep 'font-lock)
4576 (set (make-local-variable 'font-lock-defaults)
4577 '(message-font-lock-keywords t))
4578 (font-lock-set-defaults)
4579 (turn-on-font-lock))
4580 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4581 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4583 (defun gnus-article-mime-edit-exit ()
4584 "Exit the article MIME editing without updating."
4586 (let ((winconf gnus-prev-winconf)
4588 (when mime-edit-mode-flag
4591 (goto-char (point-min))
4592 (let (case-fold-search)
4593 (when (re-search-forward
4594 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4595 (replace-match "")))
4596 (when (featurep 'font-lock)
4597 (setq font-lock-defaults nil)
4599 ;; We remove all text props from the article buffer.
4600 (setq buf (format "%s" (buffer-string)))
4601 (set-buffer (get-buffer-create gnus-original-article-buffer))
4604 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4605 (gnus-article-prepare-display)
4606 (set-window-configuration winconf)))
4609 ;;; Article highlights
4612 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4614 ;;; Internal Variables:
4616 (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\\)\\)"
4617 "Regular expression that matches URLs."
4618 :group 'gnus-article-buttons
4621 (defcustom gnus-button-alist
4622 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4623 0 t gnus-button-message-id 2)
4624 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4625 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4627 gnus-button-fetch-group 4)
4628 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4629 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4630 t gnus-button-message-id 3)
4631 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4632 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4633 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4634 ;; This is how URLs _should_ be embedded in text...
4635 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4637 (,gnus-button-url-regexp 0 t browse-url 0))
4638 "*Alist of regexps matching buttons in article bodies.
4640 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4641 REGEXP: is the string matching text around the button,
4642 BUTTON: is the number of the regexp grouping actually matching the button,
4643 FORM: is a lisp expression which must eval to true for the button to
4645 CALLBACK: is the function to call when the user push this button, and each
4646 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4648 CALLBACK can also be a variable, in that case the value of that
4649 variable it the real callback function."
4650 :group 'gnus-article-buttons
4651 :type '(repeat (list regexp
4652 (integer :tag "Button")
4654 (function :tag "Callback")
4657 (integer :tag "Regexp group")))))
4659 (defcustom gnus-header-button-alist
4660 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4661 0 t gnus-button-message-id 0)
4662 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4663 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4664 0 t gnus-button-mailto 0)
4665 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4666 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4667 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4668 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4669 gnus-button-message-id 3))
4670 "*Alist of headers and regexps to match buttons in article heads.
4672 This alist is very similar to `gnus-button-alist', except that each
4673 alist has an additional HEADER element first in each entry:
4675 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4677 HEADER is a regexp to match a header. For a fuller explanation, see
4678 `gnus-button-alist'."
4679 :group 'gnus-article-buttons
4680 :group 'gnus-article-headers
4681 :type '(repeat (list (regexp :tag "Header")
4683 (integer :tag "Button")
4685 (function :tag "Callback")
4688 (integer :tag "Regexp group")))))
4690 (defvar gnus-button-regexp nil)
4691 (defvar gnus-button-marker-list nil)
4692 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4694 (defvar gnus-button-last nil)
4695 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4699 (defun gnus-article-push-button (event)
4700 "Check text under the mouse pointer for a callback function.
4701 If the text under the mouse pointer has a `gnus-callback' property,
4702 call it with the value of the `gnus-data' text property."
4704 (set-buffer (window-buffer (posn-window (event-start event))))
4705 (let* ((pos (posn-point (event-start event)))
4706 (data (get-text-property pos 'gnus-data))
4707 (fun (get-text-property pos 'gnus-callback)))
4710 (funcall fun data))))
4712 (defun gnus-article-press-button ()
4713 "Check text at point for a callback function.
4714 If the text at point has a `gnus-callback' property,
4715 call it with the value of the `gnus-data' text property."
4717 (let* ((data (get-text-property (point) 'gnus-data))
4718 (fun (get-text-property (point) 'gnus-callback)))
4720 (funcall fun data))))
4722 (defun gnus-article-prev-button (n)
4723 "Move point to N buttons backward.
4724 If N is negative, move forward instead."
4726 (gnus-article-next-button (- n)))
4728 (defun gnus-article-next-button (n)
4729 "Move point to N buttons forward.
4730 If N is negative, move backward instead."
4732 (let ((function (if (< n 0) 'previous-single-property-change
4733 'next-single-property-change))
4734 (inhibit-point-motion-hooks t)
4736 (limit (if (< n 0) (point-min) (point-max))))
4738 (while (and (not (= limit (point)))
4740 ;; Skip past the current button.
4741 (when (get-text-property (point) 'gnus-callback)
4742 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4743 ;; Go to the next (or previous) button.
4744 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4745 ;; Put point at the start of the button.
4746 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4747 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4748 ;; Skip past intangible buttons.
4749 (when (get-text-property (point) 'intangible)
4753 (gnus-message 5 "No more buttons"))
4756 (defun gnus-article-highlight (&optional force)
4757 "Highlight current article.
4758 This function calls `gnus-article-highlight-headers',
4759 `gnus-article-highlight-citation',
4760 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4761 do the highlighting. See the documentation for those functions."
4762 (interactive (list 'force))
4763 (gnus-article-highlight-headers)
4764 (gnus-article-highlight-citation force)
4765 (gnus-article-highlight-signature)
4766 (gnus-article-add-buttons force)
4767 (gnus-article-add-buttons-to-head))
4769 (defun gnus-article-highlight-some (&optional force)
4770 "Highlight current article.
4771 This function calls `gnus-article-highlight-headers',
4772 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4773 do the highlighting. See the documentation for those functions."
4774 (interactive (list 'force))
4775 (gnus-article-highlight-headers)
4776 (gnus-article-highlight-signature)
4777 (gnus-article-add-buttons))
4779 (defun gnus-article-highlight-headers ()
4780 "Highlight article headers as specified by `gnus-header-face-alist'."
4783 (set-buffer gnus-article-buffer)
4785 (let ((alist gnus-header-face-alist)
4786 (buffer-read-only nil)
4787 (case-fold-search t)
4788 (inhibit-point-motion-hooks t)
4789 entry regexp header-face field-face from hpoints fpoints)
4790 (article-narrow-to-head)
4791 (while (setq entry (pop alist))
4792 (goto-char (point-min))
4793 (setq regexp (concat "^\\("
4794 (if (string-equal "" (nth 0 entry))
4798 header-face (nth 1 entry)
4799 field-face (nth 2 entry))
4800 (while (and (re-search-forward regexp nil t)
4804 (unless (search-forward ":" nil t)
4806 (when (and header-face
4807 (not (memq (point) hpoints)))
4808 (push (point) hpoints)
4809 (gnus-put-text-property from (point) 'face header-face))
4810 (when (and field-face
4811 (not (memq (setq from (point)) fpoints)))
4813 (if (re-search-forward "^[^ \t]" nil t)
4815 (goto-char (point-max)))
4816 (gnus-put-text-property from (point) 'face field-face))))))))
4818 (defun gnus-article-highlight-signature ()
4819 "Highlight the signature in an article.
4820 It does this by highlighting everything after
4821 `gnus-signature-separator' using `gnus-signature-face'."
4823 (when gnus-signature-face
4825 (set-buffer gnus-article-buffer)
4826 (let ((buffer-read-only nil)
4827 (inhibit-point-motion-hooks t))
4829 (when (gnus-article-narrow-to-signature)
4830 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4831 'face gnus-signature-face)))))))
4833 (defun gnus-article-buttonize-signature ()
4834 "Add button to the signature."
4837 (set-buffer gnus-article-buffer)
4838 (let ((buffer-read-only nil)
4839 (inhibit-point-motion-hooks t))
4840 (when (gnus-article-search-signature)
4841 (gnus-article-add-button (match-beginning 0) (match-end 0)
4842 'gnus-signature-toggle
4843 (set-marker (make-marker)
4844 (1+ (match-end 0))))))))
4846 (defun gnus-button-in-region-p (b e prop)
4847 "Say whether PROP exists in the region."
4848 (text-property-not-all b e prop nil))
4850 (defun gnus-article-add-buttons (&optional force)
4851 "Find external references in the article and make buttons of them.
4852 \"External references\" are things like Message-IDs and URLs, as
4853 specified by `gnus-button-alist'."
4854 (interactive (list 'force))
4856 (set-buffer gnus-article-buffer)
4857 (let ((buffer-read-only nil)
4858 (inhibit-point-motion-hooks t)
4859 (case-fold-search t)
4860 (alist gnus-button-alist)
4862 ;; Remove all old markers.
4863 (let (marker entry new-list)
4864 (while (setq marker (pop gnus-button-marker-list))
4865 (if (or (< marker (point-min)) (>= marker (point-max)))
4866 (push marker new-list)
4868 (when (setq entry (gnus-button-entry))
4869 (put-text-property (match-beginning (nth 1 entry))
4870 (match-end (nth 1 entry))
4871 'gnus-callback nil))
4872 (set-marker marker nil)))
4873 (setq gnus-button-marker-list new-list))
4874 ;; We skip the headers.
4877 (while (setq entry (pop alist))
4878 (setq regexp (car entry))
4880 (while (re-search-forward regexp nil t)
4881 (let* ((start (and entry (match-beginning (nth 1 entry))))
4882 (end (and entry (match-end (nth 1 entry))))
4883 (from (match-beginning 0)))
4884 (when (and (or (eq t (nth 2 entry))
4885 (eval (nth 2 entry)))
4886 (not (gnus-button-in-region-p
4887 start end 'gnus-callback)))
4888 ;; That optional form returned non-nil, so we add the
4890 (gnus-article-add-button
4891 start end 'gnus-button-push
4892 (car (push (set-marker (make-marker) from)
4893 gnus-button-marker-list))))))))))
4895 ;; Add buttons to the head of an article.
4896 (defun gnus-article-add-buttons-to-head ()
4897 "Add buttons to the head of the article."
4900 (set-buffer gnus-article-buffer)
4902 (let ((buffer-read-only nil)
4903 (inhibit-point-motion-hooks t)
4904 (case-fold-search t)
4905 (alist gnus-header-button-alist)
4907 (article-narrow-to-head)
4909 ;; Each alist entry.
4910 (setq entry (car alist)
4912 (goto-char (point-min))
4913 (while (re-search-forward (car entry) nil t)
4914 ;; Each header matching the entry.
4915 (setq beg (match-beginning 0))
4916 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4917 (match-beginning 0))
4920 (while (re-search-forward (nth 1 entry) end t)
4921 ;; Each match within a header.
4922 (let* ((entry (cdr entry))
4923 (start (match-beginning (nth 1 entry)))
4924 (end (match-end (nth 1 entry)))
4925 (form (nth 2 entry)))
4926 (goto-char (match-end 0))
4928 (gnus-article-add-button
4929 start end (nth 3 entry)
4930 (buffer-substring (match-beginning (nth 4 entry))
4931 (match-end (nth 4 entry)))))))
4932 (goto-char end)))))))
4934 ;;; External functions:
4936 (defun gnus-article-add-button (from to fun &optional data)
4937 "Create a button between FROM and TO with callback FUN and data DATA."
4938 (when gnus-article-button-face
4939 (gnus-overlay-put (gnus-make-overlay from to)
4940 'face gnus-article-button-face))
4941 (gnus-add-text-properties
4943 (nconc (and gnus-article-mouse-face
4944 (list gnus-mouse-face-prop gnus-article-mouse-face))
4945 (list 'gnus-callback fun)
4946 (and data (list 'gnus-data data))))
4947 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4948 ;; Quote `:button-keymap' for Mule 2.3
4949 ;; but it won't work.
4950 ':button-keymap gnus-widget-button-keymap))
4952 ;;; Internal functions:
4954 (defun gnus-article-set-globals ()
4956 (set-buffer gnus-summary-buffer)
4957 (gnus-set-global-variables)))
4959 (defun gnus-signature-toggle (end)
4961 (set-buffer gnus-article-buffer)
4962 (let ((buffer-read-only nil)
4963 (inhibit-point-motion-hooks t)
4964 (limit (next-single-property-change end 'mime-view-entity
4966 (if (get-text-property end 'invisible)
4967 (gnus-article-unhide-text end limit)
4968 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4970 (defun gnus-button-entry ()
4971 ;; Return the first entry in `gnus-button-alist' matching this place.
4972 (let ((alist gnus-button-alist)
4975 (setq entry (pop alist))
4976 (if (looking-at (car entry))
4981 (defun gnus-button-push (marker)
4982 ;; Push button starting at MARKER.
4985 (let* ((entry (gnus-button-entry))
4986 (inhibit-point-motion-hooks t)
4988 (args (mapcar (lambda (group)
4989 (let ((string (match-string group)))
4990 (gnus-set-text-properties
4991 0 (length string) nil string)
4998 (fboundp (symbol-value fun)))
4999 (apply (symbol-value fun) args))
5001 (gnus-message 1 "You must define `%S' to use this button"
5002 (cons fun args)))))))
5004 (defun gnus-button-message-id (message-id)
5007 (set-buffer gnus-summary-buffer)
5008 (gnus-summary-refer-article message-id)))
5010 (defun gnus-button-fetch-group (address)
5011 "Fetch GROUP specified by ADDRESS."
5012 (if (not (string-match "[:/]" address))
5013 ;; This is just a simple group url.
5014 (gnus-group-read-ephemeral-group address gnus-select-method)
5015 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5017 (error "Can't parse %s" address)
5018 (gnus-group-read-ephemeral-group
5019 (match-string 4 address)
5020 `(nntp ,(match-string 1 address)
5021 (nntp-address ,(match-string 1 address))
5022 (nntp-port-number ,(if (match-end 3)
5023 (match-string 3 address)
5026 (defun gnus-url-parse-query-string (query &optional downcase)
5027 (let (retval pairs cur key val)
5028 (setq pairs (split-string query "&"))
5030 (setq cur (car pairs)
5032 (if (not (string-match "=" cur))
5034 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5035 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5037 (setq key (downcase key)))
5038 (setq cur (assoc key retval))
5040 (setcdr cur (cons val (cdr cur)))
5041 (setq retval (cons (list key val) retval)))))
5044 (defun gnus-url-unhex (x)
5051 (defun gnus-url-unhex-string (str &optional allow-newlines)
5052 "Remove %XXX embedded spaces, etc in a url.
5053 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5054 decoding of carriage returns and line feeds in the string, which is normally
5055 forbidden in URL encoding."
5056 (setq str (or str ""))
5058 (case-fold-search t))
5059 (while (string-match "%[0-9a-f][0-9a-f]" str)
5060 (let* ((start (match-beginning 0))
5061 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5063 (gnus-url-unhex (elt str (+ start 2))))))
5065 tmp (substring str 0 start)
5068 (char-to-string code))
5069 ((or (= code ?\n) (= code ?\r))
5071 (t (char-to-string code))))
5072 str (substring str (match-end 0)))))
5073 (setq tmp (concat tmp str))
5076 (defun gnus-url-mailto (url)
5077 ;; Send mail to someone
5078 (when (string-match "mailto:/*\\(.*\\)" url)
5079 (setq url (substring url (match-beginning 1) nil)))
5080 (let (to args subject func)
5081 (if (string-match (regexp-quote "?") url)
5082 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5083 args (gnus-url-parse-query-string
5084 (substring url (match-end 0) nil) t))
5085 (setq to (gnus-url-unhex-string url)))
5086 (setq args (cons (list "to" to) args)
5087 subject (cdr-safe (assoc "subject" args)))
5088 (gnus-setup-message 'reply
5091 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5094 (message-position-on-field (caar args)))
5095 (insert (mapconcat 'identity (cdar args) ", "))
5096 (setq args (cdr args)))
5099 (message-goto-subject)))))
5101 (defun gnus-button-mailto (address)
5103 (set-buffer (gnus-copy-article-buffer))
5104 (gnus-setup-message 'reply
5105 (message-reply address)))
5107 (defun gnus-button-reply (address)
5108 ;; Reply to ADDRESS.
5109 (gnus-setup-message 'reply
5110 (message-reply address)))
5112 (defun gnus-button-embedded-url (address)
5114 (browse-url (gnus-strip-whitespace address)))
5116 (defun gnus-article-smiley-display ()
5117 "Display \"smileys\" as small graphical icons."
5118 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5120 ;;; Next/prev buttons in the article buffer.
5122 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5123 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5125 (defvar gnus-prev-page-map nil)
5126 (unless gnus-prev-page-map
5127 (setq gnus-prev-page-map (make-sparse-keymap))
5128 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5129 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5131 (static-if (featurep 'xemacs)
5132 (defun gnus-insert-prev-page-button ()
5133 (let ((buffer-read-only nil))
5135 gnus-prev-page-line-format nil
5136 `(gnus-prev t local-map ,gnus-prev-page-map
5137 gnus-callback gnus-article-button-prev-page
5138 article-type annotation))))
5139 (defun gnus-insert-prev-page-button ()
5140 (let ((buffer-read-only nil)
5141 (situation (get-text-property (point-min) 'mime-view-situation)))
5142 (set-keymap-parent gnus-prev-page-map (current-local-map))
5144 gnus-prev-page-line-format nil
5145 `(gnus-prev t local-map ,gnus-prev-page-map
5146 gnus-callback gnus-article-button-prev-page
5147 article-type annotation
5148 mime-view-situation ,situation))))
5151 (defvar gnus-next-page-map nil)
5152 (unless gnus-next-page-map
5153 (setq gnus-next-page-map (make-sparse-keymap))
5154 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5155 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5157 (defun gnus-button-next-page ()
5158 "Go to the next page."
5160 (let ((win (selected-window)))
5161 (select-window (get-buffer-window gnus-article-buffer t))
5162 (gnus-article-next-page)
5163 (select-window win)))
5165 (defun gnus-button-prev-page ()
5166 "Go to the prev page."
5168 (let ((win (selected-window)))
5169 (select-window (get-buffer-window gnus-article-buffer t))
5170 (gnus-article-prev-page)
5171 (select-window win)))
5173 (static-if (featurep 'xemacs)
5174 (defun gnus-insert-next-page-button ()
5175 (let ((buffer-read-only nil))
5176 (gnus-eval-format gnus-next-page-line-format nil
5178 t local-map ,gnus-next-page-map
5179 gnus-callback gnus-article-button-next-page
5180 article-type annotation))))
5181 (defun gnus-insert-next-page-button ()
5182 (let ((buffer-read-only nil)
5183 (situation (get-text-property (point-min) 'mime-view-situation)))
5184 (set-keymap-parent gnus-next-page-map (current-local-map))
5185 (gnus-eval-format gnus-next-page-line-format nil
5187 t local-map ,gnus-next-page-map
5188 gnus-callback gnus-article-button-next-page
5189 article-type annotation
5190 mime-view-situation ,situation))))
5193 (defun gnus-article-button-next-page (arg)
5194 "Go to the next page."
5196 (let ((win (selected-window)))
5197 (select-window (get-buffer-window gnus-article-buffer t))
5198 (gnus-article-next-page)
5199 (select-window win)))
5201 (defun gnus-article-button-prev-page (arg)
5202 "Go to the prev page."
5204 (let ((win (selected-window)))
5205 (select-window (get-buffer-window gnus-article-buffer t))
5206 (gnus-article-prev-page)
5207 (select-window win)))
5209 (defvar gnus-decode-header-methods
5210 '(mail-decode-encoded-word-region)
5211 "List of methods used to decode headers.
5213 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5214 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5215 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5216 whose names match REGEXP.
5219 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5220 mail-decode-encoded-word-region
5221 (\"chinese\" . rfc1843-decode-region))
5224 (defvar gnus-decode-header-methods-cache nil)
5226 (defun gnus-multi-decode-header (start end)
5227 "Apply the functions from `gnus-encoded-word-methods' that match."
5228 (unless (and gnus-decode-header-methods-cache
5229 (eq gnus-newsgroup-name
5230 (car gnus-decode-header-methods-cache)))
5231 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5234 (nconc gnus-decode-header-methods-cache (list x))
5235 (if (and gnus-newsgroup-name
5236 (string-match (car x) gnus-newsgroup-name))
5237 (nconc gnus-decode-header-methods-cache
5239 gnus-decode-header-methods))
5240 (let ((xlist gnus-decode-header-methods-cache))
5243 (narrow-to-region start end)
5245 (funcall (pop xlist) (point-min) (point-max))))))
5248 ;;; Treatment top-level handling.
5251 (defun gnus-treat-article (condition &optional part-number total-parts type)
5252 (let ((length (- (point-max) (point-min)))
5253 (alist gnus-treatment-function-alist)
5254 (article-goto-body-goes-to-point-min-p t)
5258 (let ((list gnus-article-treat-types))
5260 (when (string-match (pop list) type)
5261 (throw 'found t)))))))
5262 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5263 (entity (static-unless (featurep 'xemacs)
5264 (when (eq 'head condition)
5265 (get-text-property (point-min) 'mime-view-entity))))
5266 val elem buttonized)
5267 (gnus-run-hooks 'gnus-part-display-hook)
5268 (unless gnus-inhibit-treatment
5269 (while (setq elem (pop alist))
5272 (if (gnus-buffer-live-p gnus-summary-buffer)
5273 (set-buffer gnus-summary-buffer))
5274 (symbol-value (car elem))))
5275 (when (and (or (consp val)
5277 (gnus-treat-predicate val)
5278 (or (not (get (car elem) 'highlight))
5280 (when (and (not buttonized)
5282 '(gnus-treat-hide-signature
5283 gnus-treat-highlight-signature)))
5284 (gnus-article-buttonize-signature)
5285 (setq buttonized t))
5287 (funcall (cadr elem)))))
5288 ;; FSF Emacsen does not inherit the existing text properties
5289 ;; in the new text, so we should do it for `mime-view-entity'.
5290 (static-unless (featurep 'xemacs)
5292 (put-text-property (point-min) (point-max)
5293 'mime-view-entity entity))))))
5295 ;; Dynamic variables.
5296 (defvar part-number)
5297 (defvar total-parts)
5301 (defun gnus-treat-predicate (val)
5306 (stringp (car val)))
5307 (apply 'gnus-or (mapcar `(lambda (s)
5308 (string-match s ,(or gnus-newsgroup-name "")))
5311 (let ((pred (pop val)))
5314 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5316 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5318 (not (gnus-treat-predicate (car val))))
5320 (equal (car val) type))
5322 (error "%S is not a valid predicate" pred)))))
5332 (eq part-number total-parts))
5336 (error "%S is not a valid value" val))))
5342 (defun gnus-article-header-presentation-method (entity situation)
5343 (mime-insert-header entity)
5346 (set-alist 'mime-header-presentation-method-alist
5347 'gnus-original-article-mode
5348 #'gnus-article-header-presentation-method)
5350 (defun gnus-mime-preview-quitting-method ()
5351 (mime-preview-kill-buffer)
5352 (delete-other-windows)
5353 (gnus-article-show-summary)
5354 (gnus-summary-select-article gnus-show-all-headers t))
5356 (set-alist 'mime-preview-quitting-method-alist
5357 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5359 (set-alist 'mime-preview-following-method-alist
5360 'gnus-original-article-mode #'gnus-following-method)
5362 (set-alist 'mime-preview-over-to-previous-method-alist
5363 'gnus-original-article-mode
5365 (if (> (point-min) 1)
5366 (gnus-article-prev-page)
5367 (gnus-article-read-summary-keys
5368 nil (gnus-character-to-event ?P)))))
5370 (set-alist 'mime-preview-over-to-next-method-alist
5371 'gnus-original-article-mode'
5373 (if (< (point-max) (buffer-size))
5374 (gnus-article-next-page)
5375 (gnus-article-read-summary-keys
5376 nil (gnus-character-to-event ?N)))))
5386 (run-hooks 'gnus-art-load-hook)
5388 ;;; gnus-art.el ends here