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 ((and (fboundp 'image-type-available-p)
216 (image-type-available-p 'xbm))
217 (if (module-installed-p 'x-face-e21)
218 'x-face-decode-message-header
219 'gnus-article-display-xface))
220 ((and (not gnus-xemacs)
222 (module-installed-p 'x-face-mule))
223 'x-face-mule-gnus-article-display-x-face)
225 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"))
226 "*String or function to be executed to display an X-Face header.
227 If it is a string, the command will be executed in a sub-shell
228 asynchronously. The compressed face will be piped to this command."
229 :type '(choice string
231 :tag "x-face-decode-message-header (x-face-e21)"
232 x-face-decode-message-header)
233 (function-item gnus-article-display-xface)
234 (function-item x-face-mule-gnus-article-display-x-face)
236 :group 'gnus-article-washing)
238 (defcustom gnus-article-x-face-too-ugly nil
239 "Regexp matching posters whose face shouldn't be shown automatically."
240 :type '(choice regexp (const nil))
241 :group 'gnus-article-washing)
243 (defcustom gnus-emphasis-alist
245 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
247 '(("_" "_" underline)
250 ("_/" "/_" underline-italic)
251 ("_\\*" "\\*_" underline-bold)
252 ("\\*/" "/\\*" bold-italic)
253 ("_\\*/" "/\\*_" underline-bold-italic))))
254 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
255 2 3 gnus-emphasis-underline)
259 (format format (car spec) (car (cdr spec)))
260 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
262 "*Alist that says how to fontify certain phrases.
263 Each item looks like this:
265 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
267 The first element is a regular expression to be matched. The second
268 is a number that says what regular expression grouping used to find
269 the entire emphasized word. The third is a number that says what
270 regexp grouping should be displayed and highlighted. The fourth
271 is the face used for highlighting."
272 :type '(repeat (list :value ("" 0 0 default)
274 (integer :tag "Match group")
275 (integer :tag "Emphasize group")
277 :group 'gnus-article-emphasis)
279 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
280 "A regexp to describe whitespace which should not be emphasized.
281 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
282 The former avoids underlining of leading and trailing whitespace,
283 and the latter avoids underlining any whitespace at all."
284 :group 'gnus-article-emphasis
287 (defface gnus-emphasis-bold '((t (:bold t)))
288 "Face used for displaying strong emphasized text (*word*)."
289 :group 'gnus-article-emphasis)
291 (defface gnus-emphasis-italic '((t (:italic t)))
292 "Face used for displaying italic emphasized text (/word/)."
293 :group 'gnus-article-emphasis)
295 (defface gnus-emphasis-underline '((t (:underline t)))
296 "Face used for displaying underlined emphasized text (_word_)."
297 :group 'gnus-article-emphasis)
299 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
300 "Face used for displaying underlined bold emphasized text (_*word*_)."
301 :group 'gnus-article-emphasis)
303 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
304 "Face used for displaying underlined italic emphasized text (_/word/_)."
305 :group 'gnus-article-emphasis)
307 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
308 "Face used for displaying bold italic emphasized text (/*word*/)."
309 :group 'gnus-article-emphasis)
311 (defface gnus-emphasis-underline-bold-italic
312 '((t (:bold t :italic t :underline t)))
313 "Face used for displaying underlined bold italic emphasized text.
314 Esample: (_/*word*/_)."
315 :group 'gnus-article-emphasis)
317 (defface gnus-emphasis-highlight-words
318 '((t (:background "black" :foreground "yellow")))
319 "Face used for displaying highlighted words."
320 :group 'gnus-article-emphasis)
322 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
323 "Format for display of Date headers in article bodies.
324 See `format-time-string' for the possible values.
326 The variable can also be function, which should return a complete Date
327 header. The function is called with one argument, the time, which can
328 be fed to `format-time-string'."
329 :type '(choice string symbol)
330 :link '(custom-manual "(gnus)Article Date")
331 :group 'gnus-article-washing)
334 (autoload 'mail-extract-address-components "mail-extr"))
336 (defcustom gnus-save-all-headers t
337 "*If non-nil, don't remove any headers before saving."
338 :group 'gnus-article-saving
341 (defcustom gnus-prompt-before-saving 'always
342 "*This variable says how much prompting is to be done when saving articles.
343 If it is nil, no prompting will be done, and the articles will be
344 saved to the default files. If this variable is `always', each and
345 every article that is saved will be preceded by a prompt, even when
346 saving large batches of articles. If this variable is neither nil not
347 `always', there the user will be prompted once for a file name for
348 each invocation of the saving commands."
349 :group 'gnus-article-saving
350 :type '(choice (item always)
351 (item :tag "never" nil)
352 (sexp :tag "once" :format "%t\n" :value t)))
354 (defcustom gnus-saved-headers gnus-visible-headers
355 "Headers to keep if `gnus-save-all-headers' is nil.
356 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
357 If that variable is nil, however, all headers that match this regexp
358 will be kept while the rest will be deleted before saving."
359 :group 'gnus-article-saving
362 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
363 "A function to save articles in your favourite format.
364 The function must be interactively callable (in other words, it must
365 be an Emacs command).
367 Gnus provides the following functions:
369 * gnus-summary-save-in-rmail (Rmail format)
370 * gnus-summary-save-in-mail (Unix mail format)
371 * gnus-summary-save-in-folder (MH folder)
372 * gnus-summary-save-in-file (article format)
373 * gnus-summary-save-in-vm (use VM's folder format)
374 * gnus-summary-write-to-file (article format -- overwrite)."
375 :group 'gnus-article-saving
376 :type '(radio (function-item gnus-summary-save-in-rmail)
377 (function-item gnus-summary-save-in-mail)
378 (function-item gnus-summary-save-in-folder)
379 (function-item gnus-summary-save-in-file)
380 (function-item gnus-summary-save-in-vm)
381 (function-item gnus-summary-write-to-file)))
383 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
384 "A function generating a file name to save articles in Rmail format.
385 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
386 :group 'gnus-article-saving
389 (defcustom gnus-mail-save-name 'gnus-plain-save-name
390 "A function generating a file name to save articles in Unix mail format.
391 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
392 :group 'gnus-article-saving
395 (defcustom gnus-folder-save-name 'gnus-folder-save-name
396 "A function generating a file name to save articles in MH folder.
397 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
398 :group 'gnus-article-saving
401 (defcustom gnus-file-save-name 'gnus-numeric-save-name
402 "A function generating a file name to save articles in article format.
403 The function is called with NEWSGROUP, HEADERS, and optional
405 :group 'gnus-article-saving
408 (defcustom gnus-split-methods
409 '((gnus-article-archive-name)
410 (gnus-article-nndoc-name))
411 "*Variable used to suggest where articles are to be saved.
412 For instance, if you would like to save articles related to Gnus in
413 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
414 you could set this variable to something like:
416 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
417 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
419 This variable is an alist where the where the key is the match and the
420 value is a list of possible files to save in if the match is non-nil.
422 If the match is a string, it is used as a regexp match on the
423 article. If the match is a symbol, that symbol will be funcalled
424 from the buffer of the article to be saved with the newsgroup as the
425 parameter. If it is a list, it will be evaled in the same buffer.
427 If this form or function returns a string, this string will be used as
428 a possible file name; and if it returns a non-nil list, that list will
429 be used as possible file names."
430 :group 'gnus-article-saving
431 :type '(repeat (choice (list :value (fun) function)
432 (cons :value ("" "") regexp (repeat string))
435 (defcustom gnus-article-display-method-for-mime
436 'gnus-article-display-mime-message
437 "Function to display a MIME message.
438 The function is called from the article buffer."
439 :group 'gnus-article-mime
442 (defcustom gnus-article-display-method-for-traditional
443 'gnus-article-display-traditional-message
444 "*Function to display a traditional message.
445 The function is called from the article buffer."
446 :group 'gnus-article-mime
449 (defcustom gnus-page-delimiter "^\^L"
450 "*Regexp describing what to use as article page delimiters.
451 The default value is \"^\^L\", which is a form linefeed at the
452 beginning of a line."
454 :group 'gnus-article-various)
456 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
457 "*The format specification for the article mode line.
458 See `gnus-summary-mode-line-format' for a closer description.
460 The following additional specs are available:
462 %w The article washing status.
463 %m The number of MIME parts in the article."
465 :group 'gnus-article-various)
467 (defcustom gnus-article-mode-hook nil
468 "*A hook for Gnus article mode."
470 :group 'gnus-article-various)
472 (defcustom gnus-article-menu-hook nil
473 "*Hook run after the creation of the article mode menu."
475 :group 'gnus-article-various)
477 (defcustom gnus-article-prepare-hook nil
478 "*A hook called after an article has been prepared in the article buffer."
480 :group 'gnus-article-various)
482 (defcustom gnus-article-hide-pgp-hook nil
483 "*A hook called after successfully hiding a PGP signature."
485 :group 'gnus-article-various)
487 (defcustom gnus-article-button-face 'bold
488 "Face used for highlighting buttons in the article buffer.
490 An article button is a piece of text that you can activate by pressing
491 `RET' or `mouse-2' above it."
493 :group 'gnus-article-buttons)
495 (defcustom gnus-article-mouse-face 'highlight
496 "Face used for mouse highlighting in the article buffer.
498 Article buttons will be displayed in this face when the cursor is
501 :group 'gnus-article-buttons)
503 (defcustom gnus-signature-face 'gnus-signature-face
504 "Face used for highlighting a signature in the article buffer.
505 Obsolete; use the face `gnus-signature-face' for customizations instead."
507 :group 'gnus-article-highlight
508 :group 'gnus-article-signature)
510 (defface gnus-signature-face
512 "Face used for highlighting a signature in the article buffer."
513 :group 'gnus-article-highlight
514 :group 'gnus-article-signature)
516 (defface gnus-header-from-face
519 (:foreground "spring green"))
522 (:foreground "red3"))
525 "Face used for displaying from headers."
526 :group 'gnus-article-headers
527 :group 'gnus-article-highlight)
529 (defface gnus-header-subject-face
532 (:foreground "SeaGreen3"))
535 (:foreground "red4"))
537 (:bold t :italic t)))
538 "Face used for displaying subject headers."
539 :group 'gnus-article-headers
540 :group 'gnus-article-highlight)
542 (defface gnus-header-newsgroups-face
545 (:foreground "yellow" :italic t))
548 (:foreground "MidnightBlue" :italic t))
551 "Face used for displaying newsgroups headers."
552 :group 'gnus-article-headers
553 :group 'gnus-article-highlight)
555 (defface gnus-header-name-face
558 (:foreground "SeaGreen"))
561 (:foreground "maroon"))
564 "Face used for displaying header names."
565 :group 'gnus-article-headers
566 :group 'gnus-article-highlight)
568 (defface gnus-header-content-face
571 (:foreground "forest green" :italic t))
574 (:foreground "indianred4" :italic t))
576 (:italic t))) "Face used for displaying header content."
577 :group 'gnus-article-headers
578 :group 'gnus-article-highlight)
580 (defcustom gnus-header-face-alist
581 '(("From" nil gnus-header-from-face)
582 ("Subject" nil gnus-header-subject-face)
583 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
584 ("" gnus-header-name-face gnus-header-content-face))
585 "*Controls highlighting of article header.
587 An alist of the form (HEADER NAME CONTENT).
589 HEADER is a regular expression which should match the name of an
590 header header and NAME and CONTENT are either face names or nil.
592 The name of each header field will be displayed using the face
593 specified by the first element in the list where HEADER match the
594 header name and NAME is non-nil. Similarly, the content will be
595 displayed by the first non-nil matching CONTENT face."
596 :group 'gnus-article-headers
597 :group 'gnus-article-highlight
598 :type '(repeat (list (regexp :tag "Header")
600 (item :tag "skip" nil)
601 (face :value default))
602 (choice :tag "Content"
603 (item :tag "skip" nil)
604 (face :value default)))))
606 (defcustom gnus-article-decode-hook nil
607 "*Hook run to decode charsets in articles."
608 :group 'gnus-article-headers
611 (defcustom gnus-display-mime-function 'gnus-display-mime
612 "Function to display MIME articles."
613 :group 'gnus-article-mime
616 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
617 "Function used to decode headers.")
619 (defvar gnus-article-dumbquotes-map
637 "Table for MS-to-Latin1 translation.")
639 (defcustom gnus-ignored-mime-types nil
640 "List of MIME types that should be ignored by Gnus."
641 :group 'gnus-article-mime
642 :type '(repeat regexp))
644 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
645 "List of MIME types that should not be given buttons when rendered inline."
646 :group 'gnus-article-mime
647 :type '(repeat regexp))
649 (defcustom gnus-article-mime-part-function nil
650 "Function called with a MIME handle as the argument.
651 This is meant for people who want to do something automatic based
652 on parts -- for instance, adding Vcard info to a database."
653 :group 'gnus-article-mime
656 (defcustom gnus-mime-multipart-functions nil
657 "An alist of MIME types to functions to display them.")
659 (defcustom gnus-article-date-lapsed-new-header nil
660 "Whether the X-Sent and Date headers can coexist.
661 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
662 either replace the old \"Date:\" header (if this variable is nil), or
663 be added below it (otherwise)."
664 :group 'gnus-article-headers
667 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
668 "Function called with a MIME handle as the argument.
669 This is meant for people who want to view first matched part.
670 For `undisplayed-alternative' (default), the first undisplayed
671 part or alternative part is used. For `undisplayed', the first
672 undisplayed part is used. For a function, the first part which
673 the function return `t' is used. For `nil', the first part is
675 :group 'gnus-article-mime
677 (item :tag "first" :value nil)
678 (item :tag "undisplayed" :value undisplayed)
679 (item :tag "undisplayed or alternative"
680 :value undisplayed-alternative)
684 ;;; The treatment variables
687 (defvar gnus-part-display-hook nil
688 "Hook called on parts that are to receive treatment.")
690 (defvar gnus-article-treat-custom
691 '(choice (const :tag "Off" nil)
693 (const :tag "Header" head)
694 (const :tag "Last" last)
695 (const :tag "Mime" mime)
696 (integer :tag "Less")
697 (repeat :tag "Groups" regexp)
698 (sexp :tag "Predicate")))
700 (defvar gnus-article-treat-head-custom
701 '(choice (const :tag "Off" nil)
702 (const :tag "Header" head)))
704 (defvar gnus-article-treat-types '("text/plain")
707 (defvar gnus-inhibit-treatment nil
708 "Whether to inhibit treatment.")
710 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
711 "Highlight the signature.
712 Valid values are nil, t, `head', `last', an integer or a predicate.
713 See the manual for details."
714 :group 'gnus-article-treat
715 :type gnus-article-treat-custom)
716 (put 'gnus-treat-highlight-signature 'highlight t)
718 (defcustom gnus-treat-buttonize 100000
720 Valid values are nil, t, `head', `last', an integer or a predicate.
721 See the manual for details."
722 :group 'gnus-article-treat
723 :type gnus-article-treat-custom)
724 (put 'gnus-treat-buttonize 'highlight t)
726 (defcustom gnus-treat-buttonize-head 'head
727 "Add buttons to the head.
728 Valid values are nil, t, `head', `last', an integer or a predicate.
729 See the manual for details."
730 :group 'gnus-article-treat
731 :type gnus-article-treat-head-custom)
732 (put 'gnus-treat-buttonize-head 'highlight t)
734 (defcustom gnus-treat-emphasize nil
736 Valid values are nil, t, `head', `last', an integer or a predicate.
737 See the manual for details."
738 :group 'gnus-article-treat
739 :type gnus-article-treat-custom)
740 (put 'gnus-treat-emphasize 'highlight t)
742 (defcustom gnus-treat-strip-cr nil
743 "Remove carriage returns.
744 Valid values are nil, t, `head', `last', an integer or a predicate.
745 See the manual for details."
746 :group 'gnus-article-treat
747 :type gnus-article-treat-custom)
749 (defcustom gnus-treat-hide-headers 'head
751 Valid values are nil, t, `head', `last', an integer or a predicate.
752 See the manual for details."
753 :group 'gnus-article-treat
754 :type gnus-article-treat-head-custom)
756 (defcustom gnus-treat-hide-boring-headers nil
757 "Hide boring headers.
758 Valid values are nil, t, `head', `last', an integer or a predicate.
759 See the manual for details."
760 :group 'gnus-article-treat
761 :type gnus-article-treat-head-custom)
763 (defcustom gnus-treat-hide-signature nil
765 Valid values are nil, t, `head', `last', an integer or a predicate.
766 See the manual for details."
767 :group 'gnus-article-treat
768 :type gnus-article-treat-custom)
770 (defcustom gnus-treat-fill-article nil
772 Valid values are nil, t, `head', `last', an integer or a predicate.
773 See the manual for details."
774 :group 'gnus-article-treat
775 :type gnus-article-treat-custom)
777 (defcustom gnus-treat-hide-citation nil
779 Valid values are nil, t, `head', `last', an integer or a predicate.
780 See the manual for details."
781 :group 'gnus-article-treat
782 :type gnus-article-treat-custom)
784 (defcustom gnus-treat-strip-list-identifiers 'head
785 "Strip list identifiers from `gnus-list-identifiers`.
786 Valid values are nil, t, `head', `last', an integer or a predicate.
787 See the manual for details."
788 :group 'gnus-article-treat
789 :type gnus-article-treat-custom)
791 (defcustom gnus-treat-strip-pgp t
792 "Strip PGP signatures.
793 Valid values are nil, t, `head', `last', an integer or a predicate.
794 See the manual for details."
795 :group 'gnus-article-treat
796 :type gnus-article-treat-custom)
798 (defcustom gnus-treat-strip-pem nil
799 "Strip PEM signatures.
800 Valid values are nil, t, `head', `last', an integer or a predicate.
801 See the manual for details."
802 :group 'gnus-article-treat
803 :type gnus-article-treat-custom)
805 (defcustom gnus-treat-strip-banner t
806 "Strip banners from articles.
807 The banner to be stripped is specified in the `banner' group parameter.
808 Valid values are nil, t, `head', `last', an integer or a predicate.
809 See the manual for details."
810 :group 'gnus-article-treat
811 :type gnus-article-treat-custom)
813 (defcustom gnus-treat-highlight-headers 'head
814 "Highlight the headers.
815 Valid values are nil, t, `head', `last', an integer or a predicate.
816 See the manual for details."
817 :group 'gnus-article-treat
818 :type gnus-article-treat-head-custom)
819 (put 'gnus-treat-highlight-headers 'highlight t)
821 (defcustom gnus-treat-highlight-citation t
822 "Highlight cited text.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-custom)
827 (put 'gnus-treat-highlight-citation 'highlight t)
829 (defcustom gnus-treat-date-ut nil
830 "Display the Date in UT (GMT).
831 Valid values are nil, t, `head', `last', an integer or a predicate.
832 See the manual for details."
833 :group 'gnus-article-treat
834 :type gnus-article-treat-head-custom)
836 (defcustom gnus-treat-date-local nil
837 "Display the Date in the local timezone.
838 Valid values are nil, t, `head', `last', an integer or a predicate.
839 See the manual for details."
840 :group 'gnus-article-treat
841 :type gnus-article-treat-head-custom)
843 (defcustom gnus-treat-date-lapsed nil
844 "Display the Date header in a way that says how much time has elapsed.
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847 :group 'gnus-article-treat
848 :type gnus-article-treat-head-custom)
850 (defcustom gnus-treat-date-original nil
851 "Display the date in the original timezone.
852 Valid values are nil, t, `head', `last', an integer or a predicate.
853 See the manual for details."
854 :group 'gnus-article-treat
855 :type gnus-article-treat-head-custom)
857 (defcustom gnus-treat-date-iso8601 nil
858 "Display the date in the ISO8601 format.
859 Valid values are nil, t, `head', `last', an integer or a predicate.
860 See the manual for details."
861 :group 'gnus-article-treat
862 :type gnus-article-treat-head-custom)
864 (defcustom gnus-treat-date-user-defined nil
865 "Display the date in a user-defined format.
866 The format is defined by the `gnus-article-time-format' variable.
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-head-custom)
872 (defcustom gnus-treat-strip-headers-in-body t
873 "Strip the X-No-Archive header line from the beginning of the body.
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
876 :group 'gnus-article-treat
877 :type gnus-article-treat-custom)
879 (defcustom gnus-treat-strip-trailing-blank-lines nil
880 "Strip trailing blank lines.
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See the manual for details."
883 :group 'gnus-article-treat
884 :type gnus-article-treat-custom)
886 (defcustom gnus-treat-strip-leading-blank-lines nil
887 "Strip leading blank lines.
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-custom)
893 (defcustom gnus-treat-strip-multiple-blank-lines nil
894 "Strip multiple blank lines.
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-custom)
900 (defcustom gnus-treat-overstrike t
901 "Treat overstrike highlighting.
902 Valid values are nil, t, `head', `last', an integer or a predicate.
903 See the manual for details."
904 :group 'gnus-article-treat
905 :type gnus-article-treat-custom)
906 (put 'gnus-treat-overstrike 'highlight t)
908 (defcustom gnus-treat-display-xface
909 (if (or (and (fboundp 'image-type-available-p)
910 (image-type-available-p 'xbm)
911 (string-match "^0x" (shell-command-to-string "uncompface")))
912 (and gnus-xemacs (featurep 'xface))
913 (eq 'x-face-mule-gnus-article-display-x-face
914 gnus-article-x-face-command))
917 "Display X-Face headers.
918 Valid values are nil, t, `head', `last', an integer or a predicate.
919 See the manual for details."
920 :group 'gnus-article-treat
921 :type gnus-article-treat-head-custom)
922 (put 'gnus-treat-display-xface 'highlight t)
924 (defcustom gnus-treat-display-smileys
925 (if (or (and gnus-xemacs (featurep 'xpm))
926 (and (not gnus-xemacs)
928 (module-installed-p 'gnus-bitmap)))
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
934 :group 'gnus-article-treat
935 :type gnus-article-treat-custom)
936 (put 'gnus-treat-display-smileys 'highlight t)
938 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
940 Valid values are nil, t, `head', `last', an integer or a predicate.
941 See the manual for details."
942 :group 'gnus-article-treat
943 :type gnus-article-treat-head-custom)
944 (put 'gnus-treat-display-picons 'highlight t)
946 (defcustom gnus-treat-capitalize-sentences nil
947 "Capitalize sentence-starting words.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See the manual for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-custom)
953 (defcustom gnus-treat-fill-long-lines 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-custom)
960 (defcustom gnus-treat-play-sounds nil
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See the manual for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-custom)
967 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
968 "Decode an article as `default-mime-charset'. For instance, if you want to
969 attempt to decode an article even if the value of `gnus-show-mime' is nil,
970 you could set this variable to something like: nil for don't decode, t for
971 decode the body, '(or header t) for the whole article, etc."
972 :group 'gnus-article-treat
973 :type '(radio (const :tag "Off" nil)
974 (const :tag "Decode body" t)
975 (const :tag "Decode all" (or head t))))
977 (defcustom gnus-treat-translate nil
978 "Translate articles from one language to another.
979 Valid values are nil, t, `head', `last', an integer or a predicate.
980 See the manual for details."
981 :group 'gnus-article-treat
982 :type gnus-article-treat-custom)
984 ;;; Internal variables
986 (defvar article-goto-body-goes-to-point-min-p nil)
987 (defvar gnus-article-wash-types nil)
988 (defvar gnus-article-emphasis-alist nil)
990 (defvar gnus-article-mime-handle-alist-1 nil)
991 (defvar gnus-treatment-function-alist
992 '((gnus-treat-decode-article-as-default-mime-charset
993 gnus-article-decode-article-as-default-mime-charset)
994 (gnus-treat-strip-banner gnus-article-strip-banner)
995 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
996 (gnus-treat-buttonize gnus-article-add-buttons)
997 (gnus-treat-fill-article gnus-article-fill-cited-article)
998 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
999 (gnus-treat-strip-cr gnus-article-remove-cr)
1000 (gnus-treat-display-xface gnus-article-display-x-face)
1001 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1002 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1003 (gnus-treat-hide-signature gnus-article-hide-signature)
1004 (gnus-treat-hide-citation gnus-article-hide-citation)
1005 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1006 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1007 (gnus-treat-strip-pem gnus-article-hide-pem)
1008 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1009 (gnus-treat-emphasize gnus-article-emphasize)
1010 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1011 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1012 (gnus-treat-date-ut gnus-article-date-ut)
1013 (gnus-treat-date-local gnus-article-date-local)
1014 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1015 (gnus-treat-date-original gnus-article-date-original)
1016 (gnus-treat-date-user-defined gnus-article-date-user)
1017 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1018 (gnus-treat-strip-trailing-blank-lines
1019 gnus-article-remove-trailing-blank-lines)
1020 (gnus-treat-strip-leading-blank-lines
1021 gnus-article-strip-leading-blank-lines)
1022 (gnus-treat-strip-multiple-blank-lines
1023 gnus-article-strip-multiple-blank-lines)
1024 (gnus-treat-overstrike gnus-article-treat-overstrike)
1025 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1026 (gnus-treat-display-smileys gnus-article-smiley-display)
1027 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1028 (gnus-treat-display-picons gnus-article-display-picons)
1029 (gnus-treat-play-sounds gnus-earcon-display)))
1031 (defvar gnus-article-mime-handle-alist nil)
1032 (defvar article-lapsed-timer nil)
1033 (defvar gnus-article-current-summary nil)
1035 (defvar gnus-article-mode-syntax-table
1036 (let ((table (copy-syntax-table text-mode-syntax-table)))
1037 (modify-syntax-entry ?- "w" table)
1038 (modify-syntax-entry ?> ")" table)
1039 (modify-syntax-entry ?< "(" table)
1041 "Syntax table used in article mode buffers.
1042 Initialized from `text-mode-syntax-table.")
1044 (defvar gnus-save-article-buffer nil)
1046 (defvar gnus-article-mode-line-format-alist
1047 (nconc '((?w (gnus-article-wash-status) ?s)
1048 (?m (gnus-article-mime-part-status) ?s))
1049 gnus-summary-mode-line-format-alist))
1051 (defvar gnus-number-of-articles-to-be-saved nil)
1053 (defvar gnus-inhibit-hiding nil)
1055 (defsubst gnus-article-hide-text (b e props)
1056 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1057 (add-text-properties b e props)
1058 (when (memq 'intangible props)
1060 (max (1- b) (point-min))
1061 b 'intangible (cddr (memq 'intangible props)))))
1062 (defsubst gnus-article-unhide-text (b e)
1063 "Remove hidden text properties from region between B and E."
1064 (remove-text-properties b e gnus-hidden-properties)
1065 (when (memq 'intangible gnus-hidden-properties)
1066 (put-text-property (max (1- b) (point-min))
1067 b 'intangible nil)))
1069 (defun gnus-article-hide-text-type (b e type)
1070 "Hide text of TYPE between B and E."
1071 (push type gnus-article-wash-types)
1072 (gnus-article-hide-text
1073 b e (cons 'article-type (cons type gnus-hidden-properties))))
1075 (defun gnus-article-unhide-text-type (b e type)
1076 "Unhide text of TYPE between B and E."
1077 (setq gnus-article-wash-types
1078 (delq type gnus-article-wash-types))
1079 (remove-text-properties
1080 b e (cons 'article-type (cons type gnus-hidden-properties)))
1081 (when (memq 'intangible gnus-hidden-properties)
1082 (put-text-property (max (1- b) (point-min))
1083 b 'intangible nil)))
1085 (defun gnus-article-hide-text-of-type (type)
1086 "Hide text of TYPE in the current buffer."
1088 (let ((b (point-min))
1090 (while (setq b (text-property-any b e 'article-type type))
1091 (add-text-properties b (incf b) gnus-hidden-properties)))))
1093 (defun gnus-article-delete-text-of-type (type)
1094 "Delete text of TYPE in the current buffer."
1096 (let ((b (point-min)))
1097 (while (setq b (text-property-any b (point-max) 'article-type type))
1099 b (or (text-property-not-all b (point-max) 'article-type type)
1102 (defun gnus-article-delete-invisible-text ()
1103 "Delete all invisible text in the current buffer."
1105 (let ((b (point-min)))
1106 (while (setq b (text-property-any b (point-max) 'invisible t))
1108 b (or (text-property-not-all b (point-max) 'invisible t)
1111 (defun gnus-article-text-type-exists-p (type)
1112 "Say whether any text of type TYPE exists in the buffer."
1113 (text-property-any (point-min) (point-max) 'article-type type))
1115 (defsubst gnus-article-header-rank ()
1116 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1117 (let ((list gnus-sorted-header-list)
1120 (when (looking-at (car list))
1122 (setq list (cdr list))
1126 (defun article-hide-headers (&optional arg delete)
1127 "Hide unwanted headers and possibly sort them as well."
1128 (interactive (gnus-article-hidden-arg))
1129 ;; Lars said that this function might be inhibited.
1130 (if (gnus-article-check-hidden-text 'headers arg)
1132 ;; Show boring headers as well.
1133 (gnus-article-show-hidden-text 'boring-headers)
1134 (when (eq 1 (point-min))
1135 (set-window-start (get-buffer-window (current-buffer)) 1)))
1136 (unless gnus-inhibit-hiding
1139 (let ((buffer-read-only nil)
1140 (inhibit-read-only t)
1141 (case-fold-search t)
1142 (max (1+ (length gnus-sorted-header-list)))
1143 (ignored (when (not gnus-visible-headers)
1144 (cond ((stringp gnus-ignored-headers)
1145 gnus-ignored-headers)
1146 ((listp gnus-ignored-headers)
1147 (mapconcat 'identity gnus-ignored-headers
1150 (cond ((stringp gnus-visible-headers)
1151 gnus-visible-headers)
1152 ((and gnus-visible-headers
1153 (listp gnus-visible-headers))
1154 (mapconcat 'identity gnus-visible-headers "\\|"))))
1155 (inhibit-point-motion-hooks t)
1157 ;; First we narrow to just the headers.
1158 (article-narrow-to-head)
1159 ;; Hide any "From " lines at the beginning of (mail) articles.
1160 (while (looking-at "From ")
1164 (delete-region (point-min) (point))
1165 (gnus-article-hide-text (point-min) (point)
1166 (nconc (list 'article-type 'headers)
1167 gnus-hidden-properties))))
1168 ;; Then treat the rest of the header lines.
1169 ;; Then we use the two regular expressions
1170 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1171 ;; select which header lines is to remain visible in the
1173 (while (re-search-forward "^[^ \t]*:" nil t)
1175 ;; Mark the rank of the header.
1177 (point) (1+ (point)) 'message-rank
1178 (if (or (and visible (looking-at visible))
1180 (not (looking-at ignored))))
1181 (gnus-article-header-rank)
1184 (message-sort-headers-1)
1185 (when (setq beg (text-property-any
1186 (point-min) (point-max) 'message-rank (+ 2 max)))
1187 ;; We delete or make invisible the unwanted headers.
1188 (push 'headers gnus-article-wash-types)
1191 (add-text-properties
1192 (point-min) (+ 5 (point-min))
1193 '(article-type headers dummy-invisible t))
1194 (delete-region beg (point-max)))
1195 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1198 (defun article-hide-boring-headers (&optional arg)
1199 "Toggle hiding of headers that aren't very interesting.
1200 If given a negative prefix, always show; if given a positive prefix,
1202 (interactive (gnus-article-hidden-arg))
1203 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1204 (not gnus-show-all-headers))
1207 (let ((buffer-read-only nil)
1208 (list gnus-boring-article-headers)
1209 (inhibit-point-motion-hooks t)
1211 (article-narrow-to-head)
1213 (setq elem (pop list))
1214 (goto-char (point-min))
1216 ;; Hide empty headers.
1218 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1220 (gnus-article-hide-text-type
1221 (progn (beginning-of-line) (point))
1224 (if (re-search-forward "^[^ \t]" nil t)
1228 ;; Hide boring Newsgroups header.
1229 ((eq elem 'newsgroups)
1230 (when (equal (gnus-fetch-field "newsgroups")
1231 (gnus-group-real-name
1232 (if (boundp 'gnus-newsgroup-name)
1235 (gnus-article-hide-header "newsgroups")))
1236 ((eq elem 'followup-to)
1237 (when (equal (message-fetch-field "followup-to")
1238 (message-fetch-field "newsgroups"))
1239 (gnus-article-hide-header "followup-to")))
1240 ((eq elem 'reply-to)
1241 (let ((from (message-fetch-field "from"))
1242 (reply-to (message-fetch-field "reply-to")))
1247 (nth 1 (funcall gnus-extract-address-components from))
1248 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1249 (gnus-article-hide-header "reply-to"))))
1251 (let ((date (message-fetch-field "date")))
1253 (< (days-between (current-time-string) date)
1255 (gnus-article-hide-header "date"))))
1257 (let ((to (message-fetch-field "to"))
1258 (cc (message-fetch-field "cc")))
1259 (when (> (length to) 1024)
1260 (gnus-article-hide-header "to"))
1261 (when (> (length cc) 1024)
1262 (gnus-article-hide-header "cc"))))
1266 (goto-char (point-min))
1267 (while (re-search-forward "^to:" nil t)
1268 (setq to-count (1+ to-count)))
1269 (when (> to-count 1)
1270 (while (> to-count 0)
1271 (goto-char (point-min))
1273 (re-search-forward "^to:" nil nil to-count)
1275 (narrow-to-region (point) (point-max))
1276 (gnus-article-hide-header "to"))
1277 (setq to-count (1- to-count))))
1278 (goto-char (point-min))
1279 (while (re-search-forward "^cc:" nil t)
1280 (setq cc-count (1+ cc-count)))
1281 (when (> cc-count 1)
1282 (while (> cc-count 0)
1283 (goto-char (point-min))
1285 (re-search-forward "^cc:" nil nil cc-count)
1287 (narrow-to-region (point) (point-max))
1288 (gnus-article-hide-header "cc"))
1289 (setq cc-count (1- cc-count)))))))))))))
1291 (defun gnus-article-hide-header (header)
1293 (goto-char (point-min))
1294 (when (re-search-forward (concat "^" header ":") nil t)
1295 (gnus-article-hide-text-type
1296 (progn (beginning-of-line) (point))
1299 (if (re-search-forward "^[^ \t]" nil t)
1304 (defun article-toggle-headers (&optional arg)
1305 "Toggle hiding of headers. If given a negative prefix, always show;
1306 if given a positive prefix, always hide."
1307 (interactive (gnus-article-hidden-arg))
1308 (let ((force (when (numberp arg)
1309 (cond ((> arg 0) 'always-hide)
1310 ((< arg 0) 'always-show))))
1311 (window (get-buffer-window gnus-article-buffer))
1312 (header-end (point-min))
1313 header-start field-end field-start
1314 (inhibit-point-motion-hooks t)
1315 (inhibit-read-only t)
1319 (while (and (setq header-start
1320 (text-property-any header-end (point-max)
1321 'article-treated-header t))
1323 (text-property-not-all header-start (point-max)
1324 'article-treated-header t)))
1325 (setq field-end header-start)
1327 (;; Hide exposed invisible fields.
1328 (and (not (eq 'always-show force))
1330 (text-property-any field-end header-end
1331 'exposed-invisible-field t)))
1332 (while (and field-start
1333 (setq field-end (text-property-not-all
1334 field-start header-end
1335 'exposed-invisible-field t)))
1336 (add-text-properties field-start field-end gnus-hidden-properties)
1337 (setq field-start (text-property-any field-end header-end
1338 'exposed-invisible-field t)))
1339 (put-text-property header-start header-end
1340 'exposed-invisible-field nil))
1341 (;; Expose invisible fields.
1342 (and (not (eq 'always-hide force))
1344 (text-property-any field-end header-end 'invisible t)))
1345 (while (and field-start
1346 (setq field-end (text-property-not-all
1347 field-start header-end
1349 ;; If the invisible text is not terminated with newline, we
1350 ;; won't expose it. Because it may be created by x-face-mule.
1351 ;; BTW, XEmacs sometimes fail in putting a invisible text
1352 ;; property with `gnus-article-hide-text' (really?). In that
1353 ;; case, the invisible text might be started from the middle of
1354 ;; a line so we will expose the sort of thing.
1355 (when (or (not (or (eq header-start field-start)
1356 (eq ?\n (char-before field-start))))
1357 (eq ?\n (char-before field-end)))
1358 (remove-text-properties field-start field-end
1359 gnus-hidden-properties)
1360 (put-text-property field-start field-end
1361 'exposed-invisible-field t))
1362 (setq field-start (text-property-any field-end header-end
1365 (not (eq 'always-show force))
1366 (narrow-to-region header-start header-end)
1367 (article-hide-headers)
1368 ;; Re-display X-Face image under XEmacs.
1369 (when (and gnus-xemacs
1370 (gnus-functionp gnus-article-x-face-command))
1371 (let ((func (cadr (assq 'gnus-treat-display-xface
1372 gnus-treatment-function-alist)))
1374 (when (and (not gnus-inhibit-treatment)
1376 (gnus-treat-predicate gnus-treat-display-xface))
1378 (put-text-property header-start header-end 'read-only nil))))
1381 (goto-char (point-min))
1383 (set-window-start window (point-min))))))
1385 (defvar gnus-article-normalized-header-length 40
1386 "Length of normalized headers.")
1388 (defun article-normalize-headers ()
1389 "Make all header lines 40 characters long."
1391 (let ((buffer-read-only nil)
1395 (article-narrow-to-head)
1398 ((< (setq column (- (gnus-point-at-eol) (point)))
1399 gnus-article-normalized-header-length)
1401 (insert (make-string
1402 (- gnus-article-normalized-header-length column)
1404 ((> column gnus-article-normalized-header-length)
1405 (gnus-put-text-property
1407 (forward-char gnus-article-normalized-header-length)
1414 (forward-line 1))))))
1416 (defun article-treat-dumbquotes ()
1417 "Translate M******** sm*rtq**t*s into proper text.
1418 Note that this function guesses whether a character is a sm*rtq**t* or
1419 not, so it should only be used interactively."
1421 (article-translate-strings gnus-article-dumbquotes-map))
1423 (defun article-translate-characters (from to)
1424 "Translate all characters in the body of the article according to FROM and TO.
1425 FROM is a string of characters to translate from; to is a string of
1426 characters to translate to."
1428 (when (article-goto-body)
1429 (let ((buffer-read-only nil)
1430 (x (make-string 225 ?x))
1432 (while (< (incf i) (length x))
1435 (while (< i (length from))
1436 (aset x (aref from i) (aref to i))
1438 (translate-region (point) (point-max) x)))))
1440 (defun article-translate-strings (map)
1441 "Translate all string in the body of the article according to MAP.
1442 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1444 (when (article-goto-body)
1445 (let ((buffer-read-only nil)
1447 (while (setq elem (pop map))
1449 (while (search-forward (car elem) nil t)
1450 (replace-match (cadr elem)))))))))
1452 (defun article-treat-overstrike ()
1453 "Translate overstrikes into bold text."
1456 (when (article-goto-body)
1457 (let ((buffer-read-only nil))
1458 (while (search-forward "\b" nil t)
1459 (let ((next (char-after))
1463 previous (char-after))
1467 ;; We do the boldification/underlining by hiding the
1468 ;; overstrikes and putting the proper text property
1472 (gnus-article-hide-text-type start (point) 'overstrike)
1473 (put-text-property (point) end 'face 'bold))
1475 (gnus-article-hide-text-type
1476 (1- (point)) (1+ (point)) 'overstrike)
1478 start (1- (point)) 'face 'underline))
1480 (gnus-article-hide-text-type start (point) 'overstrike)
1482 (point) end 'face 'underline)))))))))
1484 (defun article-fill-long-lines ()
1485 "Fill lines that are wider than the window width."
1488 (let ((buffer-read-only nil)
1489 (width (window-width (get-buffer-window (current-buffer)))))
1492 (let ((adaptive-fill-mode nil))
1495 (when (>= (current-column) (min fill-column width))
1496 (narrow-to-region (point) (gnus-point-at-bol))
1497 (fill-paragraph nil)
1498 (goto-char (point-max))
1500 (forward-line 1)))))))
1502 (defun article-capitalize-sentences ()
1503 "Capitalize the first word in each sentence."
1506 (let ((buffer-read-only nil)
1507 (paragraph-start "^[\n\^L]"))
1511 (forward-sentence)))))
1513 (defun article-remove-cr ()
1514 "Remove trailing CRs and then translate remaining CRs into LFs."
1517 (let ((buffer-read-only nil))
1518 (goto-char (point-min))
1519 (while (re-search-forward "\r+$" nil t)
1520 (replace-match "" t t))
1521 (goto-char (point-min))
1522 (while (search-forward "\r" nil t)
1523 (replace-match "\n" t t)))))
1525 (defun article-remove-trailing-blank-lines ()
1526 "Remove all trailing blank lines from the article."
1529 (let ((buffer-read-only nil))
1530 (goto-char (point-max))
1534 (while (and (not (bobp))
1535 (looking-at "^[ \t]*$")
1536 (not (gnus-annotation-in-region-p
1537 (point) (gnus-point-at-eol))))
1542 (defun article-display-x-face (&optional force)
1543 "Look for an X-Face header and display it if present."
1544 (interactive (list 'force))
1546 ;; Delete the old process, if any.
1547 (when (process-status "article-x-face")
1548 (delete-process "article-x-face"))
1549 (let ((inhibit-point-motion-hooks t)
1550 (case-fold-search t)
1553 (article-narrow-to-head)
1554 (goto-char (point-min))
1555 (setq from (message-fetch-field "from"))
1556 (goto-char (point-min))
1557 (while (and gnus-article-x-face-command
1560 ;; Check whether this face is censored.
1561 (not gnus-article-x-face-too-ugly)
1562 (and gnus-article-x-face-too-ugly from
1563 (not (string-match gnus-article-x-face-too-ugly
1565 ;; Has to be present.
1566 (re-search-forward "^X-Face:[ \t]*" nil t))
1567 ;; This used to try to do multiple faces (`while' instead of
1568 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1569 ;; work (b) it can crash some versions of Emacs (c) are
1570 ;; multiple faces really something to encourage?
1571 (when (stringp gnus-article-x-face-command)
1573 ;; We now have the area of the buffer where the X-Face is stored.
1576 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1577 ;; We display the face.
1578 (if (symbolp gnus-article-x-face-command)
1579 ;; The command is a lisp function, so we call it.
1580 (if (gnus-functionp gnus-article-x-face-command)
1581 (funcall gnus-article-x-face-command beg end)
1582 (error "%s is not a function" gnus-article-x-face-command))
1583 ;; The command is a string, so we interpret the command
1584 ;; as a, well, command, and fork it off.
1585 (let ((process-connection-type nil))
1586 (process-kill-without-query
1588 "article-x-face" nil shell-file-name shell-command-switch
1589 gnus-article-x-face-command))
1590 (process-send-region "article-x-face" beg end)
1591 (process-send-eof "article-x-face"))))))))))
1593 (defun article-decode-mime-words ()
1594 "Decode all MIME-encoded words in the article."
1597 (set-buffer gnus-article-buffer)
1598 (let ((inhibit-point-motion-hooks t)
1600 (mail-parse-charset gnus-newsgroup-charset)
1601 (mail-parse-ignored-charsets
1602 (save-excursion (set-buffer gnus-summary-buffer)
1603 gnus-newsgroup-ignored-charsets)))
1604 (mail-decode-encoded-word-region (point-min) (point-max)))))
1606 (defun article-decode-charset (&optional prompt)
1607 "Decode charset-encoded text in the article.
1608 If PROMPT (the prefix), prompt for a coding system to use."
1610 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1612 (mail-parse-charset gnus-newsgroup-charset)
1613 (mail-parse-ignored-charsets
1614 (save-excursion (condition-case nil
1615 (set-buffer gnus-summary-buffer)
1617 gnus-newsgroup-ignored-charsets))
1618 ct cte ctl charset format)
1621 (article-narrow-to-head)
1622 (setq ct (message-fetch-field "Content-Type" t)
1623 cte (message-fetch-field "Content-Transfer-Encoding" t)
1624 ctl (and ct (ignore-errors
1625 (mail-header-parse-content-type ct)))
1628 (mm-read-coding-system "Charset to decode: "))
1630 (mail-content-type-get ctl 'charset)))
1631 format (and ctl (mail-content-type-get ctl 'format)))
1633 (setq cte (mail-header-strip cte)))
1634 (if (and ctl (not (string-match "/" (car ctl))))
1636 (goto-char (point-max)))
1639 (narrow-to-region (point) (point-max))
1640 (if (and (eq mail-parse-charset 'gnus-decoded)
1641 (eq (mm-body-7-or-8) '8bit))
1642 ;; The text code could have been decoded.
1643 (setq charset mail-parse-charset))
1644 (when (and (or (not ctl)
1645 (equal (car ctl) "text/plain"))
1646 (not format)) ;; article with format will decode later.
1648 charset (and cte (intern (downcase
1649 (gnus-strip-whitespace cte))))
1652 (defun article-decode-encoded-words ()
1653 "Remove encoded-word encoding from headers."
1654 (let (buffer-read-only)
1655 (let ((charset (save-excursion
1656 (set-buffer gnus-summary-buffer)
1657 default-mime-charset)))
1658 (mime-decode-header-in-buffer charset)
1661 (defun article-de-quoted-unreadable (&optional force)
1662 "Translate a quoted-printable-encoded article.
1663 If FORCE, decode the article whether it is marked as quoted-printable
1665 (interactive (list 'force))
1667 (let ((buffer-read-only nil)
1668 (type (gnus-fetch-field "content-transfer-encoding"))
1669 (charset gnus-newsgroup-charset))
1671 (and type (string-match "quoted-printable" (downcase type))))
1673 (quoted-printable-decode-region (point) (point-max) charset)))))
1675 (defun article-de-base64-unreadable (&optional force)
1676 "Translate a base64 article.
1677 If FORCE, decode the article whether it is marked as base64 not."
1678 (interactive (list 'force))
1680 (let ((buffer-read-only nil)
1681 (type (gnus-fetch-field "content-transfer-encoding"))
1682 (charset gnus-newsgroup-charset))
1684 (and type (string-match "quoted-printable" (downcase type))))
1687 (narrow-to-region (point) (point-max))
1688 (base64-decode-region (point-min) (point-max))
1689 (if (mm-coding-system-p charset)
1690 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1695 (defun article-decode-HZ ()
1696 "Translate a HZ-encoded article."
1700 (let ((buffer-read-only nil))
1701 (rfc1843-decode-region (point-min) (point-max)))))
1703 (defun article-wash-html ()
1704 "Format an html article."
1707 (let ((buffer-read-only nil)
1708 (charset gnus-newsgroup-charset))
1710 (save-window-excursion
1712 (narrow-to-region (point) (point-max))
1714 (let ((w3-strict-width (window-width))
1715 (url-standalone-mode t))
1717 (w3-region (point-min) (point-max))
1720 (defun article-hide-list-identifiers ()
1721 "Remove list identifies from the Subject header.
1722 The `gnus-list-identifiers' variable specifies what to do."
1726 (let ((inhibit-point-motion-hooks t)
1728 (article-narrow-to-head)
1729 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1730 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1732 (goto-char (point-min))
1733 (when (re-search-forward
1734 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1735 " *\\)\\)+\\(Re: +\\)?\\)")
1737 (let ((s (or (match-string 3) (match-string 5))))
1738 (delete-region (match-beginning 1) (match-end 1))
1740 (goto-char (match-beginning 1))
1743 (defun article-hide-pgp ()
1744 "Remove any PGP headers and signatures in the current article."
1748 (let ((inhibit-point-motion-hooks t)
1749 buffer-read-only beg end)
1751 ;; Hide the "header".
1752 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1753 (push 'pgp gnus-article-wash-types)
1754 (delete-region (match-beginning 0) (match-end 0))
1755 ;; Remove armor headers (rfc2440 6.2)
1756 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1759 ;; Hide the actual signature.
1760 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1761 (setq end (1+ (match-beginning 0)))
1764 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1766 ;; Perhaps we shouldn't hide to the end of the buffer
1767 ;; if there is no end to the signature?
1769 ;; Hide "- " PGP quotation markers.
1771 (narrow-to-region beg end)
1772 (goto-char (point-min))
1773 (while (re-search-forward "^- " nil t)
1775 (match-beginning 0) (match-end 0)))
1777 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1779 (defun article-hide-pem (&optional arg)
1780 "Toggle hiding of any PEM headers and signatures in the current article.
1781 If given a negative prefix, always show; if given a positive prefix,
1783 (interactive (gnus-article-hidden-arg))
1784 (unless (gnus-article-check-hidden-text 'pem arg)
1786 (let (buffer-read-only end)
1787 (goto-char (point-min))
1788 ;; Hide the horrendously ugly "header".
1789 (when (and (search-forward
1790 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1792 (setq end (1+ (match-beginning 0))))
1793 (push 'pem gnus-article-wash-types)
1794 (gnus-article-hide-text-type
1796 (if (search-forward "\n\n" nil t)
1800 ;; Hide the trailer as well
1801 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1803 (gnus-article-hide-text-type
1804 (match-beginning 0) (match-end 0) 'pem)))))))
1806 (defun article-strip-banner ()
1807 "Strip the banner specified by the `banner' group parameter."
1811 (let ((inhibit-point-motion-hooks t)
1812 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1813 (gnus-signature-limit nil)
1814 buffer-read-only beg end)
1818 ((eq banner 'signature)
1819 (when (gnus-article-narrow-to-signature)
1822 (delete-region (point) (point-max))))
1824 (while (re-search-forward banner nil t)
1825 (delete-region (match-beginning 0) (match-end 0))))))))))
1827 (defun article-babel ()
1828 "Translate article using an online translation service."
1832 (set-buffer gnus-article-buffer)
1833 (when (article-goto-body)
1834 (let* ((buffer-read-only nil)
1837 (orig (buffer-substring start end))
1838 (trans (babel-as-string orig)))
1840 (narrow-to-region start end)
1841 (delete-region start end)
1844 (defun article-hide-signature (&optional arg)
1845 "Hide the signature in the current article.
1846 If given a negative prefix, always show; if given a positive prefix,
1848 (interactive (gnus-article-hidden-arg))
1854 (article-goto-body))
1855 (goto-char (point-min)))
1856 (unless (gnus-article-check-hidden-text 'signature arg)
1857 (let ((buffer-read-only nil)
1859 (while (setq button (text-property-any button (point-max)
1861 'gnus-signature-toggle))
1862 (setq button (text-property-not-all button (point-max)
1864 'gnus-signature-toggle))
1865 (when (and button (not (eobp)))
1866 (gnus-article-hide-text-type
1868 (next-single-property-change (1+ button) 'mime-view-entity
1872 (defun article-strip-headers-in-body ()
1873 "Strip offensive headers from bodies."
1877 (let ((case-fold-search t))
1878 (when (looking-at "x-no-archive:")
1879 (gnus-delete-line)))))
1881 (defun article-strip-leading-blank-lines ()
1882 "Remove all blank lines from the beginning of the article."
1885 (let ((inhibit-point-motion-hooks t)
1887 (when (article-goto-body)
1888 (while (and (not (eobp))
1889 (looking-at "[ \t]*$"))
1890 (gnus-delete-line))))))
1892 (defun article-narrow-to-head ()
1893 "Narrow the buffer to the head of the message.
1894 Point is left at the beginning of the narrowed-to region."
1896 (goto-char (point-min))
1897 (if (search-forward "\n\n" nil 1)
1900 (goto-char (point-min)))
1902 (defun article-goto-body ()
1903 "Place point at the start of the body."
1904 (goto-char (point-min))
1906 ;; This variable is only bound when dealing with separate
1908 (article-goto-body-goes-to-point-min-p
1910 ((search-forward "\n\n" nil t)
1913 (goto-char (point-max))
1916 (defun article-strip-multiple-blank-lines ()
1917 "Replace consecutive blank lines with one empty line."
1920 (let ((inhibit-point-motion-hooks t)
1922 ;; First make all blank lines empty.
1924 (while (re-search-forward "^[ \t]+$" nil t)
1925 (unless (gnus-annotation-in-region-p
1926 (match-beginning 0) (match-end 0))
1927 (replace-match "" nil t)))
1928 ;; Then replace multiple empty lines with a single empty line.
1930 (while (re-search-forward "\n\n\n+" nil t)
1931 (unless (gnus-annotation-in-region-p
1932 (match-beginning 0) (match-end 0))
1933 (replace-match "\n\n" t t))))))
1935 (defun article-strip-leading-space ()
1936 "Remove all white space from the beginning of the lines in the article."
1939 (let ((inhibit-point-motion-hooks t)
1942 (while (re-search-forward "^[ \t]+" nil t)
1943 (replace-match "" t t)))))
1945 (defun article-strip-trailing-space ()
1946 "Remove all white space from the end of the lines in the article."
1949 (let ((inhibit-point-motion-hooks t)
1952 (while (re-search-forward "[ \t]+$" nil t)
1953 (replace-match "" t t)))))
1955 (defun article-strip-blank-lines ()
1956 "Strip leading, trailing and multiple blank lines."
1958 (article-strip-leading-blank-lines)
1959 (article-remove-trailing-blank-lines)
1960 (article-strip-multiple-blank-lines))
1962 (defun article-strip-all-blank-lines ()
1963 "Strip all blank lines."
1966 (let ((inhibit-point-motion-hooks t)
1969 (while (re-search-forward "^[ \t]*\n" nil t)
1970 (replace-match "" t t)))))
1972 (defun gnus-article-narrow-to-signature ()
1973 "Narrow to the signature; return t if a signature is found, else nil."
1974 (let ((inhibit-point-motion-hooks t))
1975 (when (gnus-article-search-signature)
1977 ;; Check whether we have some limits to what we consider
1978 ;; to be a signature.
1979 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1980 (list gnus-signature-limit)))
1982 (while (setq limit (pop limits))
1983 (if (or (and (integerp limit)
1984 (< (- (point-max) (point)) limit))
1986 (< (count-lines (point) (point-max)) limit))
1987 (and (gnus-functionp limit)
1989 (and (stringp limit)
1990 (not (re-search-forward limit nil t))))
1991 () ; This limit did not succeed.
1995 (narrow-to-region (point) (point-max))
1998 (defun gnus-article-search-signature ()
1999 "Search the current buffer for the signature separator.
2000 Put point at the beginning of the signature separator."
2001 (let ((cur (point)))
2002 (goto-char (point-max))
2003 (if (if (stringp gnus-signature-separator)
2004 (re-search-backward gnus-signature-separator nil t)
2005 (let ((seps gnus-signature-separator))
2007 (not (re-search-backward (car seps) nil t)))
2014 (defun gnus-article-hidden-arg ()
2015 "Return the current prefix arg as a number, or 0 if no prefix."
2016 (list (if current-prefix-arg
2017 (prefix-numeric-value current-prefix-arg)
2020 (defun gnus-article-check-hidden-text (type arg)
2021 "Return nil if hiding is necessary.
2022 Arg can be nil or a number. Nil and positive means hide, negative
2023 means show, 0 means toggle."
2026 (let ((hide (gnus-article-hidden-text-p type)))
2032 (gnus-article-show-hidden-text type))
2034 (if (eq hide 'hidden)
2035 (gnus-article-show-hidden-text type)
2038 (defun gnus-article-hidden-text-p (type)
2039 "Say whether the current buffer contains hidden text of type TYPE."
2040 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2042 (not (get-text-property pos 'invisible))
2043 (not (get-text-property pos 'dummy-invisible)))
2045 (text-property-any (1+ pos) (point-max) 'article-type type)))
2050 (defun gnus-article-show-hidden-text (type &optional hide)
2051 "Show all hidden text of type TYPE.
2052 If HIDE, hide the text instead."
2054 (let ((buffer-read-only nil)
2055 (inhibit-point-motion-hooks t)
2058 (while (setq beg (text-property-any end (point-max) 'article-type type))
2061 (text-property-not-all beg (point-max) 'article-type type)
2064 (gnus-article-hide-text beg end gnus-hidden-properties)
2065 (gnus-article-unhide-text beg end))
2069 (defconst article-time-units
2070 `((year . ,(* 365.25 24 60 60))
2071 (week . ,(* 7 24 60 60))
2072 (day . ,(* 24 60 60))
2076 "Mapping from time units to seconds.")
2078 (defun article-date-ut (&optional type highlight header)
2079 "Convert DATE date to universal time in the current article.
2080 If TYPE is `local', convert to local time; if it is `lapsed', output
2081 how much time has lapsed since DATE. For `lapsed', the value of
2082 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2083 should replace the \"Date:\" one, or should be added below it."
2084 (interactive (list 'ut t))
2085 (let* ((header (or header
2086 (and (eq 1 (point-min))
2087 (mail-header-date (save-excursion
2088 (set-buffer gnus-summary-buffer)
2089 gnus-current-headers)))
2090 (message-fetch-field "date")
2092 (date (if (vectorp header) (mail-header-date header)
2094 (inhibit-point-motion-hooks t)
2095 bface eface date-pos)
2096 (when (and date (not (string= date "")))
2099 (article-narrow-to-head)
2100 (when (or (and (eq type 'lapsed)
2101 gnus-article-date-lapsed-new-header
2102 ;; Attempt to get the face of X-Sent first.
2103 (re-search-forward "^X-Sent:[ \t]" nil t))
2104 (re-search-forward "^Date:[ \t]" nil t)
2105 ;; If Date is missing, try again for X-Sent.
2106 (re-search-forward "^X-Sent:[ \t]" nil t))
2107 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2108 date (or (get-text-property (gnus-point-at-bol)
2111 eface (get-text-property (1- (gnus-point-at-eol))
2113 (let ((buffer-read-only nil))
2114 ;; Delete any old X-Sent headers.
2115 (when (setq date-pos
2116 (text-property-any (point-min) (point-max)
2117 'article-date-lapsed t))
2118 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2119 (delete-region (match-beginning 0)
2120 (progn (forward-line 1) (point))))
2121 (goto-char (point-min))
2122 ;; Delete any old Date headers.
2123 (while (re-search-forward "^Date:[ \t]" nil t)
2125 (setq date-pos (match-beginning 0)))
2126 (unless (and (eq type 'lapsed)
2127 gnus-article-date-lapsed-new-header)
2128 (delete-region (match-beginning 0)
2129 (progn (message-next-header) (point)))))
2132 (goto-char date-pos)
2134 ;; Possibly, Date has been deleted.
2136 (when (and (eq type 'lapsed)
2137 gnus-article-date-lapsed-new-header
2138 (looking-at "Date:"))
2140 (goto-char (point-min)))
2141 (insert (article-make-date-line date type))
2142 (when (eq type 'lapsed)
2143 (put-text-property (gnus-point-at-bol) (point)
2144 'article-date-lapsed t))
2148 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2149 (put-text-property (match-beginning 1) (1+ (match-end 1))
2150 'original-date date)
2151 (put-text-property (match-beginning 1) (1+ (match-end 1))
2153 (put-text-property (match-beginning 2) (match-end 2)
2156 (defun article-make-date-line (date type)
2157 "Return a DATE line of TYPE."
2158 (let ((time (condition-case ()
2162 ;; Convert to the local timezone. We have to slap a
2163 ;; `condition-case' round the calls to the timezone
2164 ;; functions since they aren't particularly resistant to
2167 (let ((tz (car (current-time-zone time))))
2168 (format "Date: %s %s%02d%02d" (current-time-string time)
2169 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2170 (/ (% (abs tz) 3600) 60))))
2171 ;; Convert to Universal Time.
2174 (current-time-string
2175 (let* ((e (parse-time-string date))
2176 (tm (apply 'encode-time e))
2178 (ls (- (cadr tm) (car (current-time-zone time)))))
2179 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2180 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2183 ;; Get the original date from the article.
2184 ((eq type 'original)
2185 (concat "Date: " (if (string-match "\n+$" date)
2186 (substring date 0 (match-beginning 0))
2188 ;; Let the user define the format.
2190 (if (gnus-functionp gnus-article-time-format)
2191 (funcall gnus-article-time-format time)
2194 (format-time-string gnus-article-time-format time))))
2197 (let ((tz (car (current-time-zone time))))
2200 (format-time-string "%Y%m%dT%H%M%S" time)
2201 (format "%s%02d%02d"
2202 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2203 (/ (% (abs tz) 3600) 60)))))
2204 ;; Do an X-Sent lapsed format.
2206 ;; If the date is seriously mangled, the timezone functions are
2207 ;; liable to bug out, so we ignore all errors.
2208 (let* ((now (current-time))
2209 (real-time (subtract-time now time))
2210 (real-sec (and real-time
2211 (+ (* (float (car real-time)) 65536)
2213 (sec (and real-time (abs real-sec)))
2223 ;; This is a bit convoluted, but basically we go
2224 ;; through the time units for years, weeks, etc,
2225 ;; and divide things to see whether that results
2226 ;; in positive answers.
2229 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2230 ;; The (remaining) seconds are too few to
2231 ;; be divided into this time unit.
2233 ;; It's big enough, so we output it.
2234 (setq sec (- sec (* num (cdr unit))))
2236 (concat (if prev ", " "") (int-to-string
2238 " " (symbol-name (car unit))
2239 (if (> num 1) "s" ""))
2241 article-time-units "")
2242 ;; If dates are odd, then it might appear like the
2243 ;; article was sent in the future.
2246 " in the future"))))))
2248 (error "Unknown conversion type: %s" type)))))
2250 (defun article-date-local (&optional highlight)
2251 "Convert the current article date to the local timezone."
2252 (interactive (list t))
2253 (article-date-ut 'local highlight))
2255 (defun article-date-original (&optional highlight)
2256 "Convert the current article date to what it was originally.
2257 This is only useful if you have used some other date conversion
2258 function and want to see what the date was before converting."
2259 (interactive (list t))
2260 (article-date-ut 'original highlight))
2262 (defun article-date-lapsed (&optional highlight)
2263 "Convert the current article date to time lapsed since it was sent."
2264 (interactive (list t))
2265 (article-date-ut 'lapsed highlight))
2267 (defun article-update-date-lapsed ()
2268 "Function to be run from a timer to update the lapsed time line."
2269 (let (deactivate-mark)
2274 (set-buffer (window-buffer w))
2275 (when (eq major-mode 'gnus-article-mode)
2276 (goto-char (point-min))
2277 (when (re-search-forward "^X-Sent:" nil t)
2278 (article-date-lapsed t))))
2281 (defun gnus-start-date-timer (&optional n)
2282 "Start a timer to update the X-Sent header in the article buffers.
2283 The numerical prefix says how frequently (in seconds) the function
2288 (gnus-stop-date-timer)
2289 (setq article-lapsed-timer
2290 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2292 (defun gnus-stop-date-timer ()
2293 "Stop the X-Sent timer."
2295 (when article-lapsed-timer
2296 (nnheader-cancel-timer article-lapsed-timer)
2297 (setq article-lapsed-timer nil)))
2299 (defun article-date-user (&optional highlight)
2300 "Convert the current article date to the user-defined format.
2301 This format is defined by the `gnus-article-time-format' variable."
2302 (interactive (list t))
2303 (article-date-ut 'user highlight))
2305 (defun article-date-iso8601 (&optional highlight)
2306 "Convert the current article date to ISO8601."
2307 (interactive (list t))
2308 (article-date-ut 'iso8601 highlight))
2310 (defun article-show-all ()
2311 "Show all hidden text in the article buffer."
2315 (let ((buffer-read-only nil))
2316 (gnus-article-unhide-text (point-min) (point-max))
2317 (gnus-remove-text-with-property 'gnus-prev)
2318 (gnus-remove-text-with-property 'gnus-next))))
2320 (defun article-show-all-headers ()
2321 "Show all hidden headers in the article buffer."
2326 (article-narrow-to-head)
2327 (let ((buffer-read-only nil))
2328 (gnus-article-unhide-text (point-min) (point-max))))))
2330 (defun article-emphasize (&optional arg)
2331 "Emphasize text according to `gnus-emphasis-alist'."
2332 (interactive (gnus-article-hidden-arg))
2333 (unless (gnus-article-check-hidden-text 'emphasis arg)
2337 (with-current-buffer gnus-summary-buffer
2338 gnus-article-emphasis-alist)
2340 gnus-emphasis-alist))
2341 (buffer-read-only nil)
2342 (props (append '(article-type emphasis)
2343 gnus-hidden-properties))
2344 regexp elem beg invisible visible face)
2347 (while (setq elem (pop alist))
2349 (setq regexp (car elem)
2350 invisible (nth 1 elem)
2351 visible (nth 2 elem)
2353 (while (re-search-forward regexp nil t)
2354 (when (and (match-beginning visible) (match-beginning invisible))
2355 (push 'emphasis gnus-article-wash-types)
2356 (gnus-article-hide-text
2357 (match-beginning invisible) (match-end invisible) props)
2358 (gnus-article-unhide-text-type
2359 (match-beginning visible) (match-end visible) 'emphasis)
2360 (gnus-put-text-property-excluding-newlines
2361 (match-beginning visible) (match-end visible) 'face face)
2362 (goto-char (match-end invisible)))))))))
2364 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2365 "Setup newsgroup emphasis alist."
2366 (unless gnus-article-emphasis-alist
2367 (let ((name (and gnus-newsgroup-name
2368 (gnus-group-real-name gnus-newsgroup-name))))
2369 (make-local-variable 'gnus-article-emphasis-alist)
2370 (setq gnus-article-emphasis-alist
2372 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2373 (while (setq elem (pop alist))
2374 (when (and name (string-match (car elem) name))
2376 highlight (copy-sequence (cdr elem)))))
2378 (copy-sequence highlight-words)
2379 (if gnus-newsgroup-name
2380 (copy-sequence (gnus-group-find-parameter
2381 gnus-newsgroup-name 'highlight-words t)))
2382 gnus-emphasis-alist)))))
2384 (defvar gnus-summary-article-menu)
2385 (defvar gnus-summary-post-menu)
2387 ;;; Saving functions.
2389 (defun gnus-article-save (save-buffer file &optional num)
2390 "Save the currently selected article."
2391 (unless gnus-save-all-headers
2392 ;; Remove headers according to `gnus-saved-headers'.
2393 (let ((gnus-visible-headers
2394 (or gnus-saved-headers gnus-visible-headers))
2395 (gnus-article-buffer save-buffer))
2397 (set-buffer save-buffer)
2398 (article-hide-headers 1 t))))
2399 (save-window-excursion
2400 (if (not gnus-default-article-saver)
2401 (error "No default saver is defined")
2402 ;; !!! Magic! The saving functions all save
2403 ;; `gnus-save-article-buffer' (or so they think), but we
2404 ;; bind that variable to our save-buffer.
2405 (set-buffer gnus-article-buffer)
2406 (let* ((gnus-save-article-buffer save-buffer)
2409 ((not gnus-prompt-before-saving) 'default)
2410 ((eq gnus-prompt-before-saving 'always) nil)
2412 (gnus-number-of-articles-to-be-saved
2413 (when (eq gnus-prompt-before-saving t)
2415 (set-buffer gnus-article-current-summary)
2416 (funcall gnus-default-article-saver filename)))))
2418 (defun gnus-read-save-file-name (prompt &optional filename
2419 function group headers variable)
2421 (funcall function group headers (symbol-value variable)))
2426 ((eq filename 'default)
2432 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2435 (if (and gnus-number-of-articles-to-be-saved
2436 (> gnus-number-of-articles-to-be-saved 1))
2437 (format "these %d articles"
2438 gnus-number-of-articles-to-be-saved)
2441 ;; Let the split methods have their say.
2443 ;; No split name was found.
2446 (concat prompt " (default "
2447 (file-name-nondirectory default-name) ") ")
2448 (file-name-directory default-name)
2450 ;; A single group name is returned.
2451 ((stringp split-name)
2453 (funcall function split-name headers
2454 (symbol-value variable)))
2456 (concat prompt " (default "
2457 (file-name-nondirectory default-name) ") ")
2458 (file-name-directory default-name)
2460 ;; A single split name was found
2461 ((= 1 (length split-name))
2462 (let* ((name (expand-file-name
2463 (car split-name) gnus-article-save-directory))
2464 (dir (cond ((file-directory-p name)
2465 (file-name-as-directory name))
2466 ((file-exists-p name) name)
2467 (t gnus-article-save-directory))))
2469 (concat prompt " (default " name ") ")
2471 ;; A list of splits was found.
2473 (setq split-name (nreverse split-name))
2475 (let ((file-name-history
2476 (nconc split-name file-name-history)))
2480 (concat prompt " (`M-p' for defaults) ")
2481 gnus-article-save-directory
2483 gnus-article-save-directory)))
2484 (car (push result file-name-history)))))))
2485 ;; Create the directory.
2486 (gnus-make-directory (file-name-directory file))
2487 ;; If we have read a directory, we append the default file name.
2488 (when (file-directory-p file)
2489 (setq file (concat (file-name-as-directory file)
2490 (file-name-nondirectory default-name))))
2491 ;; Possibly translate some characters.
2492 (nnheader-translate-file-chars file)))))
2493 (gnus-make-directory (file-name-directory result))
2494 (set variable result)))
2496 (defun gnus-article-archive-name (group)
2497 "Return the first instance of an \"Archive-name\" in the current buffer."
2498 (let ((case-fold-search t))
2499 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2500 (nnheader-concat gnus-article-save-directory
2501 (match-string 1)))))
2503 (defun gnus-article-nndoc-name (group)
2504 "If GROUP is an nndoc group, return the name of the parent group."
2505 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2506 (gnus-group-get-parameter group 'save-article-group)))
2508 (defun gnus-summary-save-in-rmail (&optional filename)
2509 "Append this article to Rmail file.
2510 Optional argument FILENAME specifies file name.
2511 Directory to save to is default to `gnus-article-save-directory'."
2512 (setq filename (gnus-read-save-file-name
2513 "Save %s in rmail file:" filename
2514 gnus-rmail-save-name gnus-newsgroup-name
2515 gnus-current-headers 'gnus-newsgroup-last-rmail))
2516 (gnus-eval-in-buffer-window gnus-save-article-buffer
2520 (gnus-output-to-rmail filename))))
2523 (defun gnus-summary-save-in-mail (&optional filename)
2524 "Append this article to Unix mail file.
2525 Optional argument FILENAME specifies file name.
2526 Directory to save to is default to `gnus-article-save-directory'."
2527 (setq filename (gnus-read-save-file-name
2528 "Save %s in Unix mail file:" filename
2529 gnus-mail-save-name gnus-newsgroup-name
2530 gnus-current-headers 'gnus-newsgroup-last-mail))
2531 (gnus-eval-in-buffer-window gnus-save-article-buffer
2535 (if (and (file-readable-p filename)
2536 (mail-file-babyl-p filename))
2537 (rmail-output-to-rmail-file filename t)
2538 (gnus-output-to-mail filename)))))
2541 (defun gnus-summary-save-in-file (&optional filename overwrite)
2542 "Append this article to file.
2543 Optional argument FILENAME specifies file name.
2544 Directory to save to is default to `gnus-article-save-directory'."
2545 (setq filename (gnus-read-save-file-name
2546 "Save %s in file:" filename
2547 gnus-file-save-name gnus-newsgroup-name
2548 gnus-current-headers 'gnus-newsgroup-last-file))
2549 (gnus-eval-in-buffer-window gnus-save-article-buffer
2553 (when (and overwrite
2554 (file-exists-p filename))
2555 (delete-file filename))
2556 (gnus-output-to-file filename))))
2559 (defun gnus-summary-write-to-file (&optional filename)
2560 "Write this article to a file.
2561 Optional argument FILENAME specifies file name.
2562 The directory to save in defaults to `gnus-article-save-directory'."
2563 (gnus-summary-save-in-file nil t))
2565 (defun gnus-summary-save-body-in-file (&optional filename)
2566 "Append this article body to a file.
2567 Optional argument FILENAME specifies file name.
2568 The directory to save in defaults to `gnus-article-save-directory'."
2569 (setq filename (gnus-read-save-file-name
2570 "Save %s body in file:" filename
2571 gnus-file-save-name gnus-newsgroup-name
2572 gnus-current-headers 'gnus-newsgroup-last-file))
2573 (gnus-eval-in-buffer-window gnus-save-article-buffer
2577 (when (article-goto-body)
2578 (narrow-to-region (point) (point-max)))
2579 (gnus-output-to-file filename))))
2582 (defun gnus-summary-save-in-pipe (&optional command)
2583 "Pipe this article to subprocess."
2585 (cond ((and (eq command 'default)
2586 gnus-last-shell-command)
2587 gnus-last-shell-command)
2591 "Shell command on %s: "
2592 (if (and gnus-number-of-articles-to-be-saved
2593 (> gnus-number-of-articles-to-be-saved 1))
2594 (format "these %d articles"
2595 gnus-number-of-articles-to-be-saved)
2597 gnus-last-shell-command))))
2598 (when (string-equal command "")
2599 (setq command gnus-last-shell-command))
2600 (gnus-eval-in-buffer-window gnus-article-buffer
2603 (shell-command-on-region (point-min) (point-max) command nil)))
2604 (setq gnus-last-shell-command command))
2606 ;;; Article file names when saving.
2608 (defun gnus-capitalize-newsgroup (newsgroup)
2609 "Capitalize NEWSGROUP name."
2610 (when (not (zerop (length newsgroup)))
2611 (concat (char-to-string (upcase (aref newsgroup 0)))
2612 (substring newsgroup 1))))
2614 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2615 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2616 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2617 Otherwise, it is like ~/News/news/group/num."
2620 (concat (if (gnus-use-long-file-name 'not-save)
2621 (gnus-capitalize-newsgroup newsgroup)
2622 (gnus-newsgroup-directory-form newsgroup))
2623 "/" (int-to-string (mail-header-number headers)))
2624 gnus-article-save-directory)))
2626 (string-equal (file-name-directory default)
2627 (file-name-directory last-file))
2628 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2630 (or last-file default))))
2632 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2633 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2634 If variable `gnus-use-long-file-name' is non-nil, it is
2635 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2638 (concat (if (gnus-use-long-file-name 'not-save)
2640 (gnus-newsgroup-directory-form newsgroup))
2641 "/" (int-to-string (mail-header-number headers)))
2642 gnus-article-save-directory)))
2644 (string-equal (file-name-directory default)
2645 (file-name-directory last-file))
2646 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2648 (or last-file default))))
2650 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2651 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2652 If variable `gnus-use-long-file-name' is non-nil, it is
2653 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2656 (if (gnus-use-long-file-name 'not-save)
2657 (gnus-capitalize-newsgroup newsgroup)
2658 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2659 gnus-article-save-directory)))
2661 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2662 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2663 If variable `gnus-use-long-file-name' is non-nil, it is
2664 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2667 (if (gnus-use-long-file-name 'not-save)
2669 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2670 gnus-article-save-directory)))
2677 (setq afunc (car func)
2680 gfunc (intern (format "gnus-%s" func))))
2683 `(lambda (&optional interactive &rest args)
2684 ,(documentation afunc t)
2685 (interactive (list t))
2687 (set-buffer gnus-article-buffer)
2689 (call-interactively ',afunc)
2690 (apply ',afunc args))))))))
2691 '(article-hide-headers
2692 article-hide-boring-headers
2693 article-toggle-headers
2694 article-treat-overstrike
2695 article-fill-long-lines
2696 article-capitalize-sentences
2698 article-display-x-face
2699 article-de-quoted-unreadable
2700 article-de-base64-unreadable
2703 article-hide-list-identifiers
2705 article-strip-banner
2708 article-hide-signature
2709 article-strip-headers-in-body
2710 article-remove-trailing-blank-lines
2711 article-strip-leading-blank-lines
2712 article-strip-multiple-blank-lines
2713 article-strip-leading-space
2714 article-strip-trailing-space
2715 article-strip-blank-lines
2716 article-strip-all-blank-lines
2718 article-date-iso8601
2719 article-date-original
2721 article-decode-mime-words
2722 article-decode-charset
2723 article-decode-encoded-words
2727 article-treat-dumbquotes
2728 article-normalize-headers
2729 (article-show-all-headers . gnus-article-show-all-headers)
2730 (article-show-all . gnus-article-show-all))))
2733 ;;; Gnus article mode
2736 (put 'gnus-article-mode 'mode-class 'special)
2738 (gnus-define-keys gnus-article-mode-map
2739 " " gnus-article-goto-next-page
2740 "\177" gnus-article-goto-prev-page
2741 [delete] gnus-article-goto-prev-page
2742 [backspace] gnus-article-goto-prev-page
2743 "\C-c^" gnus-article-refer-article
2744 "h" gnus-article-show-summary
2745 "s" gnus-article-show-summary
2746 "\C-c\C-m" gnus-article-mail
2747 "?" gnus-article-describe-briefly
2748 "e" gnus-summary-edit-article
2749 "<" beginning-of-buffer
2751 "\C-c\C-i" gnus-info-find-node
2754 "\C-d" gnus-article-read-summary-keys
2755 "\M-*" gnus-article-read-summary-keys
2756 "\M-#" gnus-article-read-summary-keys
2757 "\M-^" gnus-article-read-summary-keys
2758 "\M-g" gnus-article-read-summary-keys)
2760 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2763 (unless (lookup-key gnus-article-mode-map key)
2764 (define-key gnus-article-mode-map key
2765 'gnus-article-read-summary-keys)))
2770 (let ((key (car elt)))
2771 (and (> (length key) 0)
2772 (not (eq 'menu-bar (aref key 0)))
2773 (symbolp (lookup-key gnus-summary-mode-map key))
2775 (accessible-keymaps gnus-summary-mode-map))
2779 (push (char-to-string c) keys)
2783 (defun gnus-article-make-menu-bar ()
2784 (gnus-turn-off-edit-menu 'article)
2785 (unless (boundp 'gnus-article-article-menu)
2787 gnus-article-article-menu gnus-article-mode-map ""
2789 ["Scroll forwards" gnus-article-goto-next-page t]
2790 ["Scroll backwards" gnus-article-goto-prev-page t]
2791 ["Show summary" gnus-article-show-summary t]
2792 ["Fetch Message-ID at point" gnus-article-refer-article t]
2793 ["Mail to address at point" gnus-article-mail t]
2794 ["Send a bug report" gnus-bug t]))
2797 gnus-article-treatment-menu gnus-article-mode-map ""
2799 ["Hide headers" gnus-article-toggle-headers t]
2800 ["Hide signature" gnus-article-hide-signature t]
2801 ["Hide citation" gnus-article-hide-citation t]
2802 ["Treat overstrike" gnus-article-treat-overstrike t]
2803 ["Remove carriage return" gnus-article-remove-cr t]
2804 ["Decode HZ" gnus-article-decode-HZ t]))
2806 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2808 (when (boundp 'gnus-summary-post-menu)
2809 (define-key gnus-article-mode-map [menu-bar post]
2810 (cons "Post" gnus-summary-post-menu)))
2812 (gnus-run-hooks 'gnus-article-menu-hook)))
2814 (defun gnus-article-mode ()
2815 "Major mode for displaying an article.
2817 All normal editing commands are switched off.
2819 The following commands are available in addition to all summary mode
2821 \\<gnus-article-mode-map>
2822 \\[gnus-article-next-page]\t Scroll the article one page forwards
2823 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2824 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2825 \\[gnus-article-show-summary]\t Display the summary buffer
2826 \\[gnus-article-mail]\t Send a reply to the address near point
2827 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2828 \\[gnus-info-find-node]\t Go to the Gnus info node"
2830 (when (gnus-visual-p 'article-menu 'menu)
2831 (gnus-article-make-menu-bar))
2832 (gnus-simplify-mode-line)
2833 (setq mode-name "Article")
2834 (setq major-mode 'gnus-article-mode)
2835 (make-local-variable 'minor-mode-alist)
2836 (unless (assq 'gnus-show-mime minor-mode-alist)
2837 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2838 (use-local-map gnus-article-mode-map)
2839 (gnus-update-format-specifications nil 'article-mode)
2840 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2841 (make-local-variable 'gnus-page-broken)
2842 (make-local-variable 'gnus-button-marker-list)
2843 (make-local-variable 'gnus-article-current-summary)
2844 (make-local-variable 'gnus-article-mime-handles)
2845 (make-local-variable 'gnus-article-decoded-p)
2846 (make-local-variable 'gnus-article-mime-handle-alist)
2847 (make-local-variable 'gnus-article-wash-types)
2848 (gnus-set-default-directory)
2849 (buffer-disable-undo)
2850 (setq buffer-read-only t)
2851 (set-syntax-table gnus-article-mode-syntax-table)
2852 (gnus-run-hooks 'gnus-article-mode-hook))
2854 (defun gnus-article-setup-buffer ()
2855 "Initialize the article buffer."
2856 (let* ((name (if gnus-single-article-buffer "*Article*"
2857 (concat "*Article " gnus-newsgroup-name "*")))
2859 (progn (string-match "\\*Article" name)
2860 (concat " *Original Article"
2861 (substring name (match-end 0))))))
2862 (setq gnus-article-buffer name)
2863 (setq gnus-original-article-buffer original)
2864 (setq gnus-article-mime-handle-alist nil)
2865 ;; This might be a variable local to the summary buffer.
2866 (unless gnus-single-article-buffer
2868 (set-buffer gnus-summary-buffer)
2869 (setq gnus-article-buffer name)
2870 (setq gnus-original-article-buffer original)
2871 (gnus-set-global-variables)))
2872 (gnus-article-setup-highlight-words)
2873 ;; Init original article buffer.
2875 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2876 (set-buffer-multibyte nil)
2877 (setq major-mode 'gnus-original-article-mode)
2878 (make-local-variable 'gnus-original-article))
2879 (if (get-buffer name)
2882 (buffer-disable-undo)
2883 (setq buffer-read-only t)
2884 (unless (eq major-mode 'gnus-article-mode)
2885 (gnus-article-mode))
2888 (set-buffer (gnus-get-buffer-create name))
2890 (make-local-variable 'gnus-summary-buffer)
2891 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2892 (current-buffer)))))
2894 ;; Set article window start at LINE, where LINE is the number of lines
2895 ;; from the head of the article.
2896 (defun gnus-article-set-window-start (&optional line)
2898 (get-buffer-window gnus-article-buffer t)
2900 (set-buffer gnus-article-buffer)
2901 (goto-char (point-min))
2904 (gnus-message 6 "Moved to bookmark")
2905 (search-forward "\n\n" nil t)
2909 ;;; @@ article filters
2912 (defun gnus-article-display-mime-message ()
2913 "Article display method for MIME message."
2914 ;; called from `gnus-original-article-buffer'.
2915 (let (charset all-headers)
2916 (with-current-buffer gnus-summary-buffer
2917 (setq charset default-mime-charset
2918 all-headers gnus-have-all-headers))
2919 (make-local-variable 'default-mime-charset)
2920 (setq default-mime-charset charset)
2921 (with-current-buffer (get-buffer-create gnus-article-buffer)
2922 (make-local-variable 'default-mime-charset)
2923 (setq default-mime-charset charset))
2924 (mime-display-message mime-message-structure
2925 gnus-article-buffer nil gnus-article-mode-map)
2927 (gnus-article-hide-headers nil -1)))
2928 (run-hooks 'gnus-mime-article-prepare-hook))
2930 (defun gnus-article-display-traditional-message ()
2931 "Article display method for traditional message."
2932 (set-buffer gnus-article-buffer)
2933 (let (buffer-read-only)
2935 (insert-buffer-substring gnus-original-article-buffer)))
2937 (defun gnus-article-make-full-mail-header (&optional number charset)
2938 "Create a new mail header structure in a raw article buffer."
2939 (unless (and number charset)
2940 (save-current-buffer
2941 (set-buffer gnus-summary-buffer)
2943 (setq number (or (cdr gnus-article-current) 0)))
2945 (setq charset (or default-mime-charset 'x-ctext)))))
2946 (goto-char (point-min))
2947 (let ((header-end (if (search-forward "\n\n" nil t)
2949 (goto-char (point-max))))
2950 (chars (- (point-max) (point)))
2951 (lines (count-lines (point) (point-max)))
2952 (default-mime-charset charset)
2954 (narrow-to-region (point-min) header-end)
2955 (setq xref (std11-fetch-field "xref"))
2957 (make-full-mail-header
2959 (std11-fetch-field "subject")
2960 (std11-fetch-field "from")
2961 (std11-fetch-field "date")
2962 (std11-fetch-field "message-id")
2963 (std11-fetch-field "references")
2966 (when xref (concat "Xref: " xref)))
2969 (defun gnus-article-prepare (article &optional all-headers header)
2970 "Prepare ARTICLE in article mode buffer.
2971 ARTICLE should either be an article number or a Message-ID.
2972 If ARTICLE is an id, HEADER should be the article headers.
2973 If ALL-HEADERS is non-nil, no headers are hidden."
2975 ;; Make sure we start in a summary buffer.
2976 (unless (eq major-mode 'gnus-summary-mode)
2977 (set-buffer gnus-summary-buffer))
2978 (setq gnus-summary-buffer (current-buffer))
2979 (let* ((gnus-article (if header (mail-header-number header) article))
2980 (summary-buffer (current-buffer))
2981 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2982 (group gnus-newsgroup-name)
2985 (gnus-article-setup-buffer)
2986 (set-buffer gnus-original-article-buffer)
2987 ;; Deactivate active regions.
2988 (when (and (boundp 'transient-mark-mode)
2989 transient-mark-mode)
2990 (setq mark-active nil))
2991 (if (not (setq result (let ((buffer-read-only nil))
2992 (gnus-request-article-this-buffer
2994 ;; There is no such article.
2996 (when (and (numberp article)
2997 (not (memq article gnus-newsgroup-sparse)))
2998 (setq gnus-article-current
2999 (cons gnus-newsgroup-name article))
3000 (set-buffer gnus-summary-buffer)
3001 (setq gnus-current-article article)
3002 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3004 (gnus-summary-set-agent-mark article)
3005 (message "Message marked for downloading"))
3006 (gnus-summary-mark-article article gnus-canceled-mark)
3007 (unless (memq article gnus-newsgroup-sparse)
3008 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3009 (if (or (eq result 'pseudo)
3010 (eq result 'nneething))
3013 (set-buffer summary-buffer)
3014 (push article gnus-newsgroup-history)
3015 (setq gnus-last-article gnus-current-article
3016 gnus-current-article 0
3017 gnus-current-headers nil
3018 gnus-article-current nil)
3019 (if (eq result 'nneething)
3020 (gnus-configure-windows 'summary)
3021 (gnus-configure-windows 'article))
3022 (gnus-set-global-variables))
3023 (let ((gnus-article-mime-handle-alist-1
3024 gnus-article-mime-handle-alist))
3025 (gnus-set-mode-line 'article)))
3026 ;; The result from the `request' was an actual article -
3027 ;; or at least some text that is now displayed in the
3029 (when (and (numberp article)
3030 (not (eq article gnus-current-article)))
3031 ;; Seems like a new article has been selected.
3032 ;; `gnus-current-article' must be an article number.
3034 (set-buffer summary-buffer)
3035 (push article gnus-newsgroup-history)
3036 (setq gnus-last-article gnus-current-article
3037 gnus-current-article article
3038 gnus-current-headers
3039 (gnus-summary-article-header gnus-current-article)
3040 gnus-article-current
3041 (cons gnus-newsgroup-name gnus-current-article))
3042 (unless (vectorp gnus-current-headers)
3043 (setq gnus-current-headers nil))
3044 (gnus-summary-goto-subject gnus-current-article)
3045 (when (gnus-summary-show-thread)
3046 ;; If the summary buffer really was folded, the
3047 ;; previous goto may not actually have gone to
3048 ;; the right article, but the thread root instead.
3050 (gnus-summary-goto-subject gnus-current-article))
3051 (gnus-run-hooks 'gnus-mark-article-hook)
3052 (gnus-set-mode-line 'summary)
3053 (when (gnus-visual-p 'article-highlight 'highlight)
3054 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3055 ;; Set the global newsgroup variables here.
3056 (gnus-set-global-variables)
3057 (setq gnus-have-all-headers
3058 (or all-headers gnus-show-all-headers))))
3059 (when (or (numberp article)
3061 (gnus-article-prepare-display)
3063 (goto-char (point-min))
3064 (setq gnus-page-broken
3065 (when gnus-break-pages
3066 (gnus-narrow-to-page)
3068 (let ((gnus-article-mime-handle-alist-1
3069 gnus-article-mime-handle-alist))
3070 (gnus-set-mode-line 'article))
3072 (set-window-point (get-buffer-window (current-buffer)) (point))
3073 (gnus-configure-windows 'article)
3076 (defun gnus-article-prepare-mime-display (&optional number)
3077 (goto-char (point-min))
3078 (when (re-search-forward "^[^\t ]+:" nil t)
3079 (goto-char (match-beginning 0)))
3080 (let ((entity (if (eq 1 (point-min))
3081 (get-text-property 1 'mime-view-entity)
3082 (get-text-property (point) 'mime-view-entity)))
3083 last-entity child-entity next type)
3084 (setq child-entity (mime-entity-children entity))
3086 (setq last-entity (nth (1- (length child-entity))
3088 (setq last-entity entity))
3090 (narrow-to-region (point)
3091 (if (search-forward "\n\n" nil t)
3094 (gnus-treat-article 'head)
3095 (put-text-property (point-min) (point-max) 'article-treated-header t)
3096 (goto-char (point-max)))
3097 (while (and (not (eobp)) entity)
3098 (setq next (set-marker
3100 (next-single-property-change (point) 'mime-view-entity
3102 (let ((types (mime-entity-content-type entity)))
3103 (while (eq 'multipart (mime-content-type-primary-type types))
3104 (setq entity (car (mime-entity-children entity))
3105 types (mime-entity-content-type entity)))
3107 (setq type (format "%s/%s"
3108 (mime-content-type-primary-type types)
3109 (mime-content-type-subtype types)))))
3110 (if (string-equal type "message/rfc822")
3113 (let ((children (mime-entity-children entity))
3116 (setq last-children (nth (1- (length children)) children))
3119 (not (eq last-children
3120 (get-text-property next 'mime-view-entity)))
3122 (next-single-property-change next
3124 nil (point-max)))))))
3125 (setq next (next-single-property-change next 'mime-view-entity
3128 (narrow-to-region (point) next)
3129 (gnus-article-prepare-mime-display)
3130 (goto-char (point-max)))
3131 (setq entity (get-text-property (point) 'mime-view-entity)))
3133 (narrow-to-region (point) next)
3134 ;; Kludge. We have to count true number, but for now,
3135 ;; part number is here only to achieve `last'.
3136 (gnus-treat-article nil 1
3137 (if (eq entity last-entity)
3140 (goto-char (point-max)))
3141 (setq entity (get-text-property next 'mime-view-entity))))))
3144 (defun gnus-article-prepare-display ()
3145 "Make the current buffer look like a nice article."
3146 (setq gnus-article-wash-types nil)
3147 (gnus-run-hooks 'gnus-tmp-internal-hook)
3148 (gnus-run-hooks 'gnus-article-prepare-hook)
3150 (let (mime-display-header-hook mime-display-text/plain-hook)
3151 (funcall (if gnus-show-mime
3153 (setq mime-message-structure gnus-current-headers)
3154 (mime-buffer-entity-set-buffer-internal
3155 mime-message-structure
3156 gnus-original-article-buffer)
3157 (mime-entity-set-representation-type-internal
3158 mime-message-structure 'mime-buffer-entity)
3159 (luna-send mime-message-structure
3160 'initialize-instance
3161 mime-message-structure)
3162 gnus-article-display-method-for-mime)
3163 gnus-article-display-method-for-traditional)))
3164 ;; Associate this article with the current summary buffer.
3165 (setq gnus-article-current-summary gnus-summary-buffer)
3166 ;; Call the treatment functions.
3167 (let ((inhibit-read-only t)
3172 (gnus-article-prepare-mime-display)
3173 (narrow-to-region (goto-char (point-min))
3174 (if (search-forward "\n\n" nil t)
3177 (gnus-treat-article 'head)
3178 (put-text-property (point-min) (point-max) 'article-treated-header t)
3179 (goto-char (point-max))
3181 (narrow-to-region (point) (point-max))
3182 (gnus-treat-article nil))
3183 (put-text-property (point-min) (point-max) 'read-only nil)))
3184 ;; Perform the article display hooks. Incidentally, this hook is
3185 ;; an obsolete variable by now.
3186 (gnus-run-hooks 'gnus-article-display-hook))
3188 (defun gnus-article-decode-article-as-default-mime-charset ()
3189 "Decode an article as `default-mime-charset'. It won't work if the
3190 value of the variable `gnus-show-mime' is non-nil."
3191 (unless gnus-show-mime
3192 (decode-mime-charset-region (point-min) (point-max)
3193 (with-current-buffer gnus-summary-buffer
3194 default-mime-charset))))
3197 ;;; Gnus MIME viewing functions
3200 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3201 "The following specs can be used:
3203 %T MIME type, along with additional info
3204 %n The `name' parameter
3205 %d The description, if any
3206 %l The length of the encoded part
3207 %p The part identifier number
3208 %e Dots if the part isn't displayed")
3210 (defvar gnus-mime-button-line-format-alist
3211 '((?t gnus-tmp-type ?s)
3212 (?T gnus-tmp-type-long ?s)
3213 (?n gnus-tmp-name ?s)
3214 (?d gnus-tmp-description ?s)
3216 (?l gnus-tmp-length ?d)
3217 (?e gnus-tmp-dots ?s)))
3219 (defvar gnus-mime-button-commands
3220 '((gnus-article-press-button "\r" "Toggle Display")
3221 (gnus-mime-view-part "v" "View Interactively...")
3222 (gnus-mime-view-part-as-type "t" "View As Type...")
3223 (gnus-mime-save-part "o" "Save...")
3224 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3225 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3226 (gnus-mime-internalize-part "E" "View Internally")
3227 (gnus-mime-externalize-part "e" "View Externally")
3228 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3230 (defun gnus-article-mime-part-status ()
3231 (with-current-buffer gnus-article-buffer
3232 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3233 (if (and entity (mime-entity-children entity))
3234 (format " (%d parts)" (length (mime-entity-children entity)))
3237 (defvar gnus-mime-button-map nil)
3238 (unless gnus-mime-button-map
3239 (setq gnus-mime-button-map (make-sparse-keymap))
3240 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3241 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3242 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3244 (define-key gnus-mime-button-map (cadr c) (car c)))
3245 gnus-mime-button-commands))
3247 (defun gnus-mime-button-menu (event)
3248 "Construct a context-sensitive menu of MIME commands."
3251 (let ((pos (event-start event)))
3252 (set-buffer (window-buffer (posn-window pos)))
3253 (goto-char (posn-point pos))
3254 (gnus-article-check-buffer)
3255 (let ((response (x-popup-menu
3257 ("" ,@(mapcar (lambda (c)
3258 (cons (caddr c) (car c)))
3259 gnus-mime-button-commands))))))
3261 (call-interactively response))))))
3263 (defun gnus-mime-view-all-parts (&optional handles)
3264 "View all the MIME parts."
3266 (save-current-buffer
3267 (set-buffer gnus-article-buffer)
3268 (let ((handles (or handles gnus-article-mime-handles))
3269 (mail-parse-charset gnus-newsgroup-charset)
3270 (mail-parse-ignored-charsets
3271 (save-excursion (set-buffer gnus-summary-buffer)
3272 gnus-newsgroup-ignored-charsets)))
3273 (if (stringp (car handles))
3274 (gnus-mime-view-all-parts (cdr handles))
3275 (mapcar 'mm-display-part handles)))))
3277 (defun gnus-mime-save-part ()
3278 "Save the MIME part under point."
3280 (gnus-article-check-buffer)
3281 (let ((data (get-text-property (point) 'gnus-data)))
3282 (mm-save-part data)))
3284 (defun gnus-mime-pipe-part ()
3285 "Pipe the MIME part under point to a process."
3287 (gnus-article-check-buffer)
3288 (let ((data (get-text-property (point) 'gnus-data)))
3289 (mm-pipe-part data)))
3291 (defun gnus-mime-view-part ()
3292 "Interactively choose a viewing method for the MIME part under point."
3294 (gnus-article-check-buffer)
3295 (let ((data (get-text-property (point) 'gnus-data)))
3296 (mm-interactively-view-part data)))
3298 (defun gnus-mime-view-part-as-type-internal ()
3299 (gnus-article-check-buffer)
3300 (let* ((name (mail-content-type-get
3301 (mm-handle-type (get-text-property (point) 'gnus-data))
3303 (def-type (and name (mm-default-file-encoding name))))
3304 (and def-type (cons def-type 0))))
3306 (defun gnus-mime-view-part-as-type (mime-type)
3307 "Choose a MIME media type, and view the part as such."
3309 (list (completing-read
3310 "View as MIME type: "
3311 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
3313 (gnus-mime-view-part-as-type-internal))))
3314 (gnus-article-check-buffer)
3315 (let ((handle (get-text-property (point) 'gnus-data)))
3316 (gnus-mm-display-part
3317 (mm-make-handle (mm-handle-buffer handle)
3318 (cons mime-type (cdr (mm-handle-type handle)))
3319 (mm-handle-encoding handle)
3320 (mm-handle-undisplayer handle)
3321 (mm-handle-disposition handle)
3322 (mm-handle-description handle)
3323 (mm-handle-cache handle)
3324 (mm-handle-id handle)))))
3326 (defun gnus-mime-copy-part (&optional handle)
3327 "Put the the MIME part under point into a new buffer."
3329 (gnus-article-check-buffer)
3330 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3331 (contents (mm-get-part handle))|
3332 (base (file-name-nondirectory
3334 (mail-content-type-get (mm-handle-type handle) 'name)
3335 (mail-content-type-get (mm-handle-type handle)
3338 (buffer (generate-new-buffer base)))
3339 (switch-to-buffer buffer)
3341 ;; We do it this way to make `normal-mode' set the appropriate mode.
3344 (setq buffer-file-name (expand-file-name base))
3346 (setq buffer-file-name nil))
3347 (goto-char (point-min))))
3349 (defun gnus-mime-inline-part (&optional handle)
3350 "Insert the MIME part under point into the current buffer."
3352 (gnus-article-check-buffer)
3353 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3357 (if (mm-handle-undisplayer handle)
3358 (mm-remove-part handle)
3359 (setq contents (mm-get-part handle))
3361 (mm-insert-inline handle contents)
3364 (defun gnus-mime-externalize-part (&optional handle)
3365 "View the MIME part under point with an external viewer."
3367 (gnus-article-check-buffer)
3368 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3369 (mm-user-display-methods nil)
3370 (mm-inlined-types nil)
3371 (mail-parse-charset gnus-newsgroup-charset)
3372 (mail-parse-ignored-charsets
3373 (save-excursion (set-buffer gnus-summary-buffer)
3374 gnus-newsgroup-ignored-charsets)))
3375 (if (mm-handle-undisplayer handle)
3376 (mm-remove-part handle)
3377 (mm-display-part handle))))
3379 (defun gnus-mime-internalize-part (&optional handle)
3380 "View the MIME part under point with an internal viewer.
3381 In no internal viewer is available, use an external viewer."
3383 (gnus-article-check-buffer)
3384 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3385 (mm-inlined-types '(".*"))
3386 (mm-inline-large-images t)
3387 (mail-parse-charset gnus-newsgroup-charset)
3388 (mail-parse-ignored-charsets
3389 (save-excursion (set-buffer gnus-summary-buffer)
3390 gnus-newsgroup-ignored-charsets)))
3391 (if (mm-handle-undisplayer handle)
3392 (mm-remove-part handle)
3393 (mm-display-part handle))))
3395 (defun gnus-article-part-wrapper (n function)
3396 (save-current-buffer
3397 (set-buffer gnus-article-buffer)
3398 (when (> n (length gnus-article-mime-handle-alist))
3399 (error "No such part"))
3400 (gnus-article-goto-part n)
3401 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3402 (funcall function handle))))
3404 (defun gnus-article-pipe-part (n)
3405 "Pipe MIME part N, which is the numerical prefix."
3407 (gnus-article-part-wrapper n 'mm-pipe-part))
3409 (defun gnus-article-save-part (n)
3410 "Save MIME part N, which is the numerical prefix."
3412 (gnus-article-part-wrapper n 'mm-save-part))
3414 (defun gnus-article-interactively-view-part (n)
3415 "View MIME part N interactively, which is the numerical prefix."
3417 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3419 (defun gnus-article-copy-part (n)
3420 "Copy MIME part N, which is the numerical prefix."
3422 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3424 (defun gnus-article-externalize-part (n)
3425 "View MIME part N externally, which is the numerical prefix."
3427 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3429 (defun gnus-article-inline-part (n)
3430 "Inline MIME part N, which is the numerical prefix."
3432 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3434 (defun gnus-article-mime-match-handle-first (condition)
3436 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3437 (while (setq ihandle (pop alist))
3439 ((functionp condition)
3440 (funcall condition (cdr ihandle)))
3441 ((eq condition 'undisplayed)
3442 (not (or (mm-handle-undisplayer (cdr ihandle))
3443 (equal (mm-handle-media-type (cdr ihandle))
3444 "multipart/alternative"))))
3445 ((eq condition 'undisplayed-alternative)
3446 (not (mm-handle-undisplayer (cdr ihandle))))
3448 (gnus-article-goto-part (car ihandle))
3449 (or (not n) (< (car ihandle) n)))
3450 (setq n (car ihandle))))
3454 (defun gnus-article-view-part (&optional n)
3455 "View MIME part N, which is the numerical prefix."
3457 (save-current-buffer
3458 (set-buffer gnus-article-buffer)
3459 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3460 gnus-article-mime-match-handle-function)))
3461 (when (> n (length gnus-article-mime-handle-alist))
3462 (error "No such part"))
3463 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3464 (when (gnus-article-goto-part n)
3465 (if (equal (car handle) "multipart/alternative")
3466 (gnus-article-press-button)
3467 (when (eq (gnus-mm-display-part handle) 'internal)
3468 (gnus-set-window-start)))))))
3470 (defun gnus-mm-display-part (handle)
3471 "Display HANDLE and fix MIME button."
3472 (let ((id (get-text-property (point) 'gnus-part))
3477 (let ((window (selected-window))
3478 (mail-parse-charset gnus-newsgroup-charset)
3479 (mail-parse-ignored-charsets
3480 (save-excursion (set-buffer gnus-summary-buffer)
3481 gnus-newsgroup-ignored-charsets)))
3484 (let ((win (get-buffer-window (current-buffer) t))
3487 (select-window win))
3490 (if (mm-handle-displayed-p handle)
3491 ;; This will remove the part.
3492 (mm-display-part handle)
3494 (narrow-to-region (point) (1+ (point)))
3495 (mm-display-part handle)
3496 ;; We narrow to the part itself and
3497 ;; then call the treatment functions.
3498 (goto-char (point-min))
3500 (narrow-to-region (point) (point-max))
3503 (1- (length gnus-article-mime-handles))
3504 (mm-handle-media-type handle)))))
3505 (select-window window))))
3507 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3508 (gnus-insert-mime-button
3509 handle id (list (mm-handle-displayed-p handle)))
3510 (goto-char point))))
3512 (defun gnus-article-goto-part (n)
3513 "Go to MIME part N."
3514 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3516 (goto-char point))))
3518 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3519 (let ((gnus-tmp-name
3520 (or (mail-content-type-get (mm-handle-type handle)
3522 (mail-content-type-get (mm-handle-disposition handle)
3525 (gnus-tmp-type (mm-handle-media-type handle))
3526 (gnus-tmp-description
3527 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3530 (if (if displayed (car displayed)
3531 (mm-handle-displayed-p handle))
3533 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3535 gnus-tmp-type-long b e)
3536 (when (string-match ".*/" gnus-tmp-name)
3537 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3538 (setq gnus-tmp-type-long (concat gnus-tmp-type
3539 (and (not (equal gnus-tmp-name ""))
3540 (concat "; " gnus-tmp-name))))
3541 (or (equal gnus-tmp-description "")
3542 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3547 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3548 `(local-map ,gnus-mime-button-map
3549 keymap ,gnus-mime-button-map
3550 gnus-callback gnus-mm-display-part
3551 gnus-part ,gnus-tmp-id
3552 article-type annotation
3555 (widget-convert-button 'link b e
3557 :action 'gnus-widget-press-button
3558 :button-keymap gnus-mime-button-map
3561 ;; Needed to properly clear the message
3562 ;; due to a bug in wid-edit
3563 (setq help-echo-owns-message t)
3565 "Click to %s the MIME part; %s for more options"
3566 (if (mm-handle-displayed-p
3567 (widget-get widget :mime-handle))
3569 (if gnus-xemacs "button3" "mouse-3"))))))
3571 (defun gnus-widget-press-button (elems el)
3572 (goto-char (widget-get elems :from))
3573 (gnus-article-press-button))
3575 (defvar gnus-displaying-mime nil)
3577 (defun gnus-display-mime (&optional ihandles)
3578 "Display the MIME parts."
3580 (save-selected-window
3581 (let ((window (get-buffer-window gnus-article-buffer))
3584 (select-window window)
3585 ;; We have to do this since selecting the window
3586 ;; may change the point. So we set the window point.
3587 (set-window-point window point)))
3588 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3589 buffer-read-only handle name type b e display)
3590 (when (and (not ihandles)
3591 (not gnus-displaying-mime))
3592 ;; Top-level call; we clean up.
3593 (when gnus-article-mime-handles
3594 (mm-destroy-parts gnus-article-mime-handles)
3595 (setq gnus-article-mime-handle-alist nil));; A trick.
3596 (setq gnus-article-mime-handles handles)
3597 ;; We allow users to glean info from the handles.
3598 (when gnus-article-mime-part-function
3599 (gnus-mime-part-function handles)))
3601 (or (not (stringp (car handles)))
3604 (when (and (not ihandles)
3605 (not gnus-displaying-mime))
3606 ;; Clean up for mime parts.
3608 (delete-region (point) (point-max)))
3609 (let ((gnus-displaying-mime t))
3610 (gnus-mime-display-part handles)))
3613 (narrow-to-region (point) (point-max))
3614 (gnus-treat-article nil 1 1)
3617 ;; Highlight the headers.
3621 (narrow-to-region (point-min) (point))
3622 (gnus-treat-article 'head))))))))
3624 (defvar gnus-mime-display-multipart-as-mixed nil)
3626 (defun gnus-mime-display-part (handle)
3629 ((not (stringp (car handle)))
3630 (gnus-mime-display-single handle))
3631 ;; User-defined multipart
3632 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3633 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3635 ;; multipart/alternative
3636 ((and (equal (car handle) "multipart/alternative")
3637 (not gnus-mime-display-multipart-as-mixed))
3638 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3639 (push (cons id handle) gnus-article-mime-handle-alist)
3640 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3641 ;; multipart/related
3642 ((and (equal (car handle) "multipart/related")
3643 (not gnus-mime-display-multipart-as-mixed))
3644 ;;;!!!We should find the start part, but we just default
3645 ;;;!!!to the first part.
3646 (gnus-mime-display-part (cadr handle)))
3647 ;; Other multiparts are handled like multipart/mixed.
3649 (gnus-mime-display-mixed (cdr handle)))))
3651 (defun gnus-mime-part-function (handles)
3652 (if (stringp (car handles))
3653 (mapcar 'gnus-mime-part-function (cdr handles))
3654 (funcall gnus-article-mime-part-function handles)))
3656 (defun gnus-mime-display-mixed (handles)
3657 (mapcar 'gnus-mime-display-part handles))
3659 (defun gnus-mime-display-single (handle)
3660 (let ((type (mm-handle-media-type handle))
3661 (ignored gnus-ignored-mime-types)
3668 (when (string-match (pop ignored) type)
3669 (throw 'ignored nil)))
3670 (if (and (setq not-attachment
3671 (and (not (mm-inline-override-p handle))
3672 (or (not (mm-handle-disposition handle))
3673 (equal (car (mm-handle-disposition handle))
3675 (mm-attachment-override-p handle))))
3676 (mm-automatic-display-p handle)
3677 (or (mm-inlined-p handle)
3678 (mm-automatic-external-display-p type)))
3680 (when (equal (mm-handle-media-supertype handle) "text")
3682 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3683 (push (cons id handle) gnus-article-mime-handle-alist)
3684 (when (or (not display)
3685 (not (gnus-unbuttonized-mime-type-p type)))
3686 ;(gnus-article-insert-newline)
3687 (gnus-insert-mime-button
3688 handle id (list (or display (and not-attachment text))))
3689 (gnus-article-insert-newline)
3690 ;(gnus-article-insert-newline)
3692 (let ((beg (point)))
3698 (let ((mail-parse-charset gnus-newsgroup-charset)
3699 (mail-parse-ignored-charsets
3700 (save-excursion (condition-case ()
3701 (set-buffer gnus-summary-buffer)
3703 gnus-newsgroup-ignored-charsets)))
3704 (mm-display-part handle t))
3705 (goto-char (point-max)))
3706 ((and text not-attachment)
3710 (gnus-article-insert-newline)
3711 (mm-insert-inline handle (mm-get-part handle))
3712 (goto-char (point-max))))
3716 (narrow-to-region beg (point))
3718 nil (length gnus-article-mime-handle-alist)
3719 (1- (length gnus-article-mime-handles))
3720 (mm-handle-media-type handle)))))))))
3722 (defun gnus-unbuttonized-mime-type-p (type)
3723 "Say whether TYPE is to be unbuttonized."
3724 (unless gnus-inhibit-mime-unbuttonizing
3726 (let ((types gnus-unbuttonized-mime-types))
3728 (when (string-match (pop types) type)
3729 (throw 'found t)))))))
3731 (defun gnus-article-insert-newline ()
3732 "Insert a newline, but mark it as undeletable."
3733 (gnus-put-text-property
3734 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3736 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3737 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3740 handle buffer-read-only from props begend not-pref)
3741 (save-window-excursion
3744 (narrow-to-region (car ibegend)
3747 (goto-char (car ibegend))
3750 (delete-region (point-min) (point-max))
3751 (mm-remove-parts handles))
3752 (setq begend (list (point-marker)))
3754 (unless (setq not-pref (cadr (member preferred ihandles)))
3755 (setq not-pref (car ihandles)))
3757 (not (gnus-unbuttonized-mime-type-p
3758 "multipart/alternative")))
3759 (gnus-add-text-properties
3762 (insert (format "%d. " id))
3766 (unless ,(not ibegend)
3767 (setq gnus-article-mime-handle-alist
3768 ',gnus-article-mime-handle-alist))
3769 (gnus-mime-display-alternative
3770 ',ihandles ',not-pref ',begend ,id))
3771 local-map ,gnus-mime-button-map
3772 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3773 face ,gnus-article-button-face
3774 keymap ,gnus-mime-button-map
3777 (widget-convert-button 'link from (point)
3778 :action 'gnus-widget-press-button
3779 :button-keymap gnus-widget-button-keymap)
3781 (while (setq handle (pop handles))
3782 (gnus-add-text-properties
3785 (insert (format "(%c) %-18s"
3786 (if (equal handle preferred) ?* ? )
3787 (mm-handle-media-type handle)))
3791 (unless ,(not ibegend)
3792 (setq gnus-article-mime-handle-alist
3793 ',gnus-article-mime-handle-alist))
3794 (gnus-mime-display-alternative
3795 ',ihandles ',handle ',begend ,id))
3796 local-map ,gnus-mime-button-map
3797 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3798 face ,gnus-article-button-face
3799 keymap ,gnus-mime-button-map
3802 (widget-convert-button 'link from (point)
3803 :action 'gnus-widget-press-button
3804 :button-keymap gnus-widget-button-keymap)
3808 (if (stringp (car preferred))
3809 (gnus-display-mime preferred)
3810 (let ((mail-parse-charset gnus-newsgroup-charset)
3811 (mail-parse-ignored-charsets
3812 (save-excursion (set-buffer gnus-summary-buffer)
3813 gnus-newsgroup-ignored-charsets)))
3814 (mm-display-part preferred)
3818 (narrow-to-region (car begend) (point-max))
3820 nil (length gnus-article-mime-handle-alist)
3821 (1- (length gnus-article-mime-handles))
3822 (mm-handle-media-type handle))))))
3823 (goto-char (point-max))
3824 (setcdr begend (point-marker)))))
3826 (goto-char point))))
3828 (defun gnus-article-wash-status ()
3829 "Return a string which display status of article washing."
3831 (set-buffer gnus-article-buffer)
3832 (let ((cite (memq 'cite gnus-article-wash-types))
3833 (headers (memq 'headers gnus-article-wash-types))
3834 (boring (memq 'boring-headers gnus-article-wash-types))
3835 (pgp (memq 'pgp gnus-article-wash-types))
3836 (pem (memq 'pem gnus-article-wash-types))
3837 (signature (memq 'signature gnus-article-wash-types))
3838 (overstrike (memq 'overstrike gnus-article-wash-types))
3839 (emphasis (memq 'emphasis gnus-article-wash-types)))
3840 (format "%c%c%c%c%c%c%c"
3842 (if (or headers boring) ?h ? )
3843 (if (or pgp pem) ?p ? )
3844 (if signature ?s ? )
3845 (if overstrike ?o ? )
3846 (if gnus-show-mime ?m ? )
3847 (if emphasis ?e ? )))))
3849 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3851 (defun gnus-article-maybe-hide-headers ()
3852 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3853 Provided for backwards compatibility."
3854 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3855 (not (save-excursion (set-buffer gnus-summary-buffer)
3856 gnus-have-all-headers)))
3857 (not gnus-inhibit-hiding))
3858 (gnus-article-hide-headers)))
3862 (defun gnus-output-to-file (file-name)
3863 "Append the current article to a file named FILE-NAME."
3864 (let ((artbuf (current-buffer)))
3866 (insert-buffer-substring artbuf)
3867 ;; Append newline at end of the buffer as separator, and then
3869 (goto-char (point-max))
3871 (write-region-as-binary (point-min) (point-max) file-name 'append)
3874 (defun gnus-narrow-to-page (&optional arg)
3875 "Narrow the article buffer to a page.
3876 If given a numerical ARG, move forward ARG pages."
3878 (setq arg (if arg (prefix-numeric-value arg) 0))
3880 (set-buffer gnus-article-buffer)
3881 (goto-char (point-min))
3883 ;; Remove any old next/prev buttons.
3884 (when (gnus-visual-p 'page-marker)
3885 (let ((buffer-read-only nil))
3886 (gnus-remove-text-with-property 'gnus-prev)
3887 (gnus-remove-text-with-property 'gnus-next)))
3890 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3892 (re-search-forward page-delimiter nil 'move arg)))
3893 (goto-char (match-end 0)))
3896 (if (re-search-forward page-delimiter nil 'move)
3899 (when (and (gnus-visual-p 'page-marker)
3900 (not (= (point-min) 1)))
3902 (goto-char (point-min))
3903 (gnus-insert-prev-page-button)))
3904 (when (and (gnus-visual-p 'page-marker)
3905 (< (+ (point-max) 2) (buffer-size)))
3907 (goto-char (point-max))
3908 (gnus-insert-next-page-button)))))
3910 ;; Article mode commands
3912 (defun gnus-article-goto-next-page ()
3913 "Show the next page of the article."
3915 (when (gnus-article-next-page)
3916 (goto-char (point-min))
3917 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3919 (defun gnus-article-goto-prev-page ()
3920 "Show the next page of the article."
3922 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3923 (gnus-article-prev-page nil)))
3925 (defun gnus-article-next-page (&optional lines)
3926 "Show the next page of the current article.
3927 If end of article, return non-nil. Otherwise return nil.
3928 Argument LINES specifies lines to be scrolled up."
3930 (let ((start (window-start))
3931 end-of-buffer end-of-page)
3933 (move-to-window-line -1)
3934 (if (<= (point) start)
3937 (setq start (point)))
3940 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3941 (and (pos-visible-in-window-p)
3942 (setq end-of-buffer t)))
3944 (setq end-of-page t)))
3946 (move-to-window-line lines)
3947 (unless (search-backward "\n\n" nil t)
3948 (setq start (point)))))
3949 (cond (end-of-buffer t)
3951 (gnus-narrow-to-page 1)
3955 (set-window-start (selected-window) start)
3956 (let (window-pixel-scroll-increment)
3960 (defun gnus-article-prev-page (&optional lines)
3961 "Show previous page of current article.
3962 Argument LINES specifies lines to be scrolled down."
3964 (let (beginning-of-buffer beginning-of-page)
3966 (move-to-window-line 0)
3967 (cond ((eq 1 (point))
3968 (setq beginning-of-buffer t))
3970 (setq beginning-of-page t))))
3971 (cond (beginning-of-buffer)
3973 (gnus-narrow-to-page -1))
3976 (let (window-pixel-scroll-increment)
3977 (scroll-down lines))
3978 (beginning-of-buffer
3979 (goto-char (point-min))))))))
3981 (defun gnus-article-refer-article ()
3982 "Read article specified by message-id around point."
3984 (let ((point (point)))
3985 (search-forward ">" nil t) ;Move point to end of "<....>".
3986 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3987 (let ((message-id (match-string 1)))
3989 (set-buffer gnus-summary-buffer)
3990 (gnus-summary-refer-article message-id))
3992 (error "No references around point"))))
3994 (defun gnus-article-show-summary ()
3995 "Reconfigure windows to show summary buffer."
3997 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3998 (error "There is no summary buffer for this article buffer")
3999 (gnus-article-set-globals)
4000 (gnus-configure-windows 'article)
4001 (gnus-summary-goto-subject gnus-current-article)
4002 (gnus-summary-position-point)))
4004 (defun gnus-article-describe-briefly ()
4005 "Describe article mode commands briefly."
4007 (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")))
4009 (defun gnus-article-summary-command ()
4010 "Execute the last keystroke in the summary buffer."
4012 (let ((obuf (current-buffer))
4013 (owin (current-window-configuration))
4015 (switch-to-buffer gnus-article-current-summary 'norecord)
4016 (setq func (lookup-key (current-local-map) (this-command-keys)))
4017 (call-interactively func)
4019 (set-window-configuration owin)
4020 (set-window-point (get-buffer-window (current-buffer)) (point))))
4022 (defun gnus-article-summary-command-nosave ()
4023 "Execute the last keystroke in the summary buffer."
4026 (pop-to-buffer gnus-article-current-summary 'norecord)
4027 (setq func (lookup-key (current-local-map) (this-command-keys)))
4028 (call-interactively func)))
4030 (defun gnus-article-check-buffer ()
4031 "Beep if not in an article buffer."
4032 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4033 (error "Command invoked outside of a Gnus article buffer")))
4035 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4036 "Read a summary buffer key sequence and execute it from the article buffer."
4038 (gnus-article-check-buffer)
4040 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4041 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4042 "=" "^" "\M-^" "|"))
4048 '("n" "Gn" "p" "Gp"))
4051 (set-buffer gnus-article-current-summary)
4052 (let (gnus-pick-mode)
4053 (push (or key last-command-event) unread-command-events)
4054 (setq keys (static-if (featurep 'xemacs)
4055 (events-to-keys (read-key-sequence nil))
4056 (read-key-sequence nil)))))
4059 (if (or (member keys nosaves)
4060 (member keys nosave-but-article)
4061 (member keys nosave-in-article))
4063 (save-window-excursion
4064 (pop-to-buffer gnus-article-current-summary 'norecord)
4065 ;; We disable the pick minor mode commands.
4066 (let (gnus-pick-mode)
4067 (setq func (lookup-key (current-local-map) keys))))
4071 (unless (member keys nosave-in-article)
4072 (set-buffer gnus-article-current-summary))
4073 (call-interactively func)
4074 (setq new-sum-point (point)))
4075 (when (member keys nosave-but-article)
4076 (pop-to-buffer gnus-article-buffer 'norecord)))
4077 ;; These commands should restore window configuration.
4078 (let ((obuf (current-buffer))
4079 (owin (current-window-configuration))
4081 (summary gnus-article-current-summary)
4082 func in-buffer selected)
4083 (if not-restore-window
4084 (pop-to-buffer summary 'norecord)
4085 (switch-to-buffer summary 'norecord))
4086 (setq in-buffer (current-buffer))
4087 ;; We disable the pick minor mode commands.
4088 (if (setq func (let (gnus-pick-mode)
4089 (lookup-key (current-local-map) keys)))
4091 (call-interactively func)
4092 (setq new-sum-point (point)))
4094 (when (eq in-buffer (current-buffer))
4095 (setq selected (gnus-summary-select-article))
4097 (unless not-restore-window
4098 (set-window-configuration owin))
4099 (when (eq selected 'old)
4101 (set-window-start (get-buffer-window (current-buffer))
4103 (set-window-point (get-buffer-window (current-buffer))
4105 (let ((win (get-buffer-window gnus-article-current-summary)))
4107 (set-window-point win new-sum-point))))))))
4109 (defun gnus-article-hide (&optional arg force)
4110 "Hide all the gruft in the current article.
4111 This means that PGP stuff, signatures, cited text and (some)
4112 headers will be hidden.
4113 If given a prefix, show the hidden text instead."
4114 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4115 (gnus-article-hide-headers arg)
4116 (gnus-article-hide-list-identifiers arg)
4117 (gnus-article-hide-pgp arg)
4118 (gnus-article-hide-citation-maybe arg force)
4119 (gnus-article-hide-signature arg))
4121 (defun gnus-article-maybe-highlight ()
4122 "Do some article highlighting if article highlighting is requested."
4123 (when (gnus-visual-p 'article-highlight 'highlight)
4124 (gnus-article-highlight-some)))
4126 (defun gnus-check-group-server ()
4127 ;; Make sure the connection to the server is alive.
4128 (unless (gnus-server-opened
4129 (gnus-find-method-for-group gnus-newsgroup-name))
4130 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4131 (gnus-request-group gnus-newsgroup-name t)))
4133 (defun gnus-request-article-this-buffer (article group)
4134 "Get an article and insert it into this buffer."
4135 (let (do-update-line sparse-header)
4139 (gnus-kill-all-overlays)
4140 (setq group (or group gnus-newsgroup-name))
4142 ;; Using `gnus-request-article' directly will insert the article into
4143 ;; `nntp-server-buffer' - so we'll save some time by not having to
4144 ;; copy it from the server buffer into the article buffer.
4146 ;; We only request an article by message-id when we do not have the
4147 ;; headers for it, so we'll have to get those.
4148 (when (stringp article)
4149 (gnus-read-header article))
4151 ;; If the article number is negative, that means that this article
4152 ;; doesn't belong in this newsgroup (possibly), so we find its
4153 ;; message-id and request it by id instead of number.
4154 (when (and (numberp article)
4156 (get-buffer gnus-summary-buffer)
4157 (gnus-buffer-exists-p gnus-summary-buffer))
4159 (set-buffer gnus-summary-buffer)
4160 (let ((header (gnus-summary-article-header article)))
4163 ((memq article gnus-newsgroup-sparse)
4164 ;; This is a sparse gap article.
4165 (setq do-update-line article)
4166 (setq article (mail-header-id header))
4167 (setq sparse-header (gnus-read-header article))
4168 (setq gnus-newsgroup-sparse
4169 (delq article gnus-newsgroup-sparse)))
4171 ;; It's a real article.
4172 (setq article (mail-header-id header)))
4174 ;; It is an extracted pseudo-article.
4175 (setq article 'pseudo)
4176 (gnus-request-pseudo-article header))))
4178 (let ((method (gnus-find-method-for-group
4179 gnus-newsgroup-name)))
4180 (when (and (eq (car method) 'nneething)
4183 (file-name-as-directory
4184 (or (cadr (assq 'nneething-address method))
4186 (mail-header-subject header))))
4187 (when (file-directory-p dir)
4188 (setq article 'nneething)
4189 (gnus-group-enter-directory dir))))))))
4192 ;; Refuse to select canceled articles.
4193 ((and (numberp article)
4195 (get-buffer gnus-summary-buffer)
4196 (gnus-buffer-exists-p gnus-summary-buffer)
4197 (eq (cdr (save-excursion
4198 (set-buffer gnus-summary-buffer)
4199 (assq article gnus-newsgroup-reads)))
4200 gnus-canceled-mark))
4202 ;; Check the backlog.
4203 ((and gnus-keep-backlog
4204 (gnus-backlog-request-article group article (current-buffer)))
4206 ;; Check asynchronous pre-fetch.
4207 ((gnus-async-request-fetched-article group article (current-buffer))
4208 (gnus-async-prefetch-next group article gnus-summary-buffer)
4209 (when (and (numberp article) gnus-keep-backlog)
4210 (gnus-backlog-enter-article group article (current-buffer)))
4213 ((and gnus-use-cache
4215 (gnus-cache-request-article article group))
4217 ;; Get the article and put into the article buffer.
4218 ((or (stringp article)
4220 (let ((gnus-override-method gnus-override-method)
4221 (methods (and (stringp article)
4222 gnus-refer-article-method))
4224 (buffer-read-only nil))
4229 (when (and (null gnus-override-method)
4231 (setq gnus-override-method (pop methods)))
4233 (when (eq gnus-override-method 'current)
4234 (setq gnus-override-method gnus-current-select-method))
4236 (gnus-kill-all-overlays)
4237 (let ((gnus-newsgroup-name group))
4238 (gnus-check-group-server))
4239 (when (gnus-request-article article group (current-buffer))
4240 (when (numberp article)
4241 (gnus-async-prefetch-next group article
4242 gnus-summary-buffer)
4243 (when gnus-keep-backlog
4244 (gnus-backlog-enter-article
4245 group article (current-buffer))))
4246 (setq result 'article))
4249 (setq gnus-override-method (pop methods))
4250 (setq result 'done))))
4251 (and (eq result 'article) 'article)))
4255 ;; Associate this article with the current summary buffer.
4256 (setq gnus-article-current-summary gnus-summary-buffer)
4258 ;; Take the article from the original article buffer
4259 ;; and place it in the buffer it's supposed to be in.
4260 (when (and (get-buffer gnus-article-buffer)
4261 (equal (buffer-name (current-buffer))
4262 (buffer-name (get-buffer gnus-article-buffer))))
4264 (if (get-buffer gnus-original-article-buffer)
4265 (set-buffer gnus-original-article-buffer)
4266 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4267 (set-buffer-multibyte nil)
4268 (buffer-disable-undo)
4269 (setq major-mode 'gnus-original-article-mode)
4270 (setq buffer-read-only t))
4271 (let (buffer-read-only)
4273 (insert-buffer-substring gnus-article-buffer))
4274 (setq gnus-original-article (cons group article)))
4277 (run-hooks 'gnus-article-decode-hook)
4278 ;; Mark article as decoded or not.
4279 (setq gnus-article-decoded-p gnus-article-decode-hook))
4281 ;; Update sparse articles.
4282 (when (and do-update-line
4283 (or (numberp article)
4285 (let ((buf (current-buffer)))
4286 (set-buffer gnus-summary-buffer)
4287 (gnus-summary-update-article do-update-line sparse-header)
4288 (gnus-summary-goto-subject do-update-line nil t)
4289 (set-window-point (get-buffer-window (current-buffer) t)
4291 (set-buffer buf))))))
4297 (defcustom gnus-article-edit-mode-hook nil
4298 "Hook run in article edit mode buffers."
4299 :group 'gnus-article-various
4302 (defcustom gnus-article-edit-article-setup-function
4303 'gnus-article-mime-edit-article-setup
4304 "Function called to setup an editing article buffer."
4305 :group 'gnus-article-various
4308 (defvar gnus-article-edit-done-function nil)
4310 (defvar gnus-article-edit-mode-map nil)
4312 ;; Should we be using derived.el for this?
4313 (unless gnus-article-edit-mode-map
4314 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4315 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4317 (gnus-define-keys gnus-article-edit-mode-map
4318 "\C-c\C-c" gnus-article-edit-done
4319 "\C-c\C-k" gnus-article-edit-exit)
4321 (gnus-define-keys (gnus-article-edit-wash-map
4322 "\C-c\C-w" gnus-article-edit-mode-map)
4323 "f" gnus-article-edit-full-stops))
4325 (defun gnus-article-edit-mode ()
4326 "Major mode for editing articles.
4327 This is an extended text-mode.
4329 \\{gnus-article-edit-mode-map}"
4331 (setq major-mode 'gnus-article-edit-mode)
4332 (setq mode-name "Article Edit")
4333 (use-local-map gnus-article-edit-mode-map)
4334 (make-local-variable 'gnus-article-edit-done-function)
4335 (make-local-variable 'gnus-prev-winconf)
4336 (setq buffer-read-only nil)
4337 (buffer-enable-undo)
4339 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4341 (defun gnus-article-edit (&optional force)
4342 "Edit the current article.
4343 This will have permanent effect only in mail groups.
4344 If FORCE is non-nil, allow editing of articles even in read-only
4347 (when (and (not force)
4348 (gnus-group-read-only-p))
4349 (error "The current newsgroup does not support article editing"))
4350 (gnus-article-date-original)
4351 (gnus-article-edit-article
4353 `(lambda (no-highlight)
4355 (gnus-summary-edit-article-done
4356 ,(or (mail-header-references gnus-current-headers) "")
4357 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4359 (defun gnus-article-edit-article (start-func exit-func)
4360 "Start editing the contents of the current article buffer."
4361 (let ((winconf (current-window-configuration)))
4362 (set-buffer gnus-article-buffer)
4363 (gnus-article-edit-mode)
4364 (funcall start-func)
4365 (gnus-configure-windows 'edit-article)
4366 (setq gnus-article-edit-done-function exit-func)
4367 (setq gnus-prev-winconf winconf)
4368 (when gnus-article-edit-article-setup-function
4369 (funcall gnus-article-edit-article-setup-function))
4370 (gnus-message 6 "C-c C-c to end edits")))
4372 (defun gnus-article-edit-done (&optional arg)
4373 "Update the article edits and exit."
4378 (when (article-goto-body)
4379 (let ((lines (count-lines (point) (point-max)))
4380 (length (- (point-max) (point)))
4381 (case-fold-search t)
4382 (body (copy-marker (point))))
4383 (goto-char (point-min))
4384 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4385 (delete-region (match-beginning 1) (match-end 1))
4386 (insert (number-to-string length)))
4387 (goto-char (point-min))
4388 (when (re-search-forward
4389 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4390 (delete-region (match-beginning 1) (match-end 1))
4391 (insert (number-to-string length)))
4392 (goto-char (point-min))
4393 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4394 (delete-region (match-beginning 1) (match-end 1))
4395 (insert (number-to-string lines)))))))
4396 (let ((func gnus-article-edit-done-function)
4397 (buf (current-buffer))
4398 (start (window-start)))
4399 (remove-hook 'gnus-article-mode-hook
4400 'gnus-article-mime-edit-article-unwind)
4401 (gnus-article-edit-exit)
4404 (let ((buffer-read-only nil))
4406 ;; The cache and backlog have to be flushed somewhat.
4407 (when gnus-keep-backlog
4408 (gnus-backlog-remove-article
4409 (car gnus-article-current) (cdr gnus-article-current)))
4410 ;; Flush original article as well.
4412 (when (get-buffer gnus-original-article-buffer)
4413 (set-buffer gnus-original-article-buffer)
4414 (setq gnus-original-article nil)))
4415 (when gnus-use-cache
4416 (gnus-cache-update-article
4417 (car gnus-article-current) (cdr gnus-article-current))))
4419 (set-window-start (get-buffer-window buf) start)
4420 (set-window-point (get-buffer-window buf) (point))))
4422 (defun gnus-article-edit-exit ()
4423 "Exit the article editing without updating."
4425 ;; We remove all text props from the article buffer.
4426 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4427 (curbuf (current-buffer))
4429 (window-start (window-start)))
4432 (let ((winconf gnus-prev-winconf))
4434 (set-window-configuration winconf)
4435 ;; Tippy-toe some to make sure that point remains where it was.
4436 (save-current-buffer
4438 (set-window-start (get-buffer-window (current-buffer)) window-start)
4441 (defun gnus-article-edit-full-stops ()
4442 "Interactively repair spacing at end of sentences."
4445 (goto-char (point-min))
4446 (search-forward-regexp "^$" nil t)
4447 (let ((case-fold-search nil))
4448 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4451 ;;; Article editing with MIME-Edit
4454 (defcustom gnus-article-mime-edit-article-setup-hook nil
4455 "Hook run after setting up a MIME editing article buffer."
4456 :group 'gnus-article-various
4459 (defun gnus-article-mime-edit-article-unwind ()
4460 "Unwind `gnus-article-buffer' if article editing was given up."
4461 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4462 (when mime-edit-mode-flag
4463 (mime-edit-exit 'nomime 'no-error)
4465 (when (featurep 'font-lock)
4466 (setq font-lock-defaults nil)
4467 (font-lock-mode 0)))
4469 (defun gnus-article-mime-edit-article-setup ()
4470 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4471 after replacing with the original article."
4472 (setq gnus-show-mime t)
4473 (setq gnus-article-edit-done-function
4474 `(lambda (&rest args)
4475 (when mime-edit-mode-flag
4478 (goto-char (point-min))
4479 (let (case-fold-search)
4480 (when (re-search-forward
4481 (format "^%s$" (regexp-quote mail-header-separator))
4483 (replace-match "")))
4484 (when (featurep 'font-lock)
4485 (setq font-lock-defaults nil)
4487 (apply ,gnus-article-edit-done-function args)
4488 (set-buffer gnus-original-article-buffer)
4490 (insert-buffer gnus-article-buffer)
4491 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4492 (gnus-article-prepare-display)))
4493 (substitute-key-definition
4494 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4495 gnus-article-edit-mode-map)
4497 (insert-buffer gnus-original-article-buffer)
4499 (when (featurep 'font-lock)
4500 (set (make-local-variable 'font-lock-defaults)
4501 '(message-font-lock-keywords t))
4502 (font-lock-set-defaults)
4503 (turn-on-font-lock))
4504 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4505 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4507 (defun gnus-article-mime-edit-exit ()
4508 "Exit the article MIME editing without updating."
4510 (let ((winconf gnus-prev-winconf)
4512 (when mime-edit-mode-flag
4515 (goto-char (point-min))
4516 (let (case-fold-search)
4517 (when (re-search-forward
4518 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4519 (replace-match "")))
4520 (when (featurep 'font-lock)
4521 (setq font-lock-defaults nil)
4523 ;; We remove all text props from the article buffer.
4524 (setq buf (format "%s" (buffer-string)))
4525 (set-buffer (get-buffer-create gnus-original-article-buffer))
4528 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4529 (gnus-article-prepare-display)
4530 (set-window-configuration winconf)))
4533 ;;; Article highlights
4536 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4538 ;;; Internal Variables:
4540 (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\\)\\)"
4541 "Regular expression that matches URLs."
4542 :group 'gnus-article-buttons
4545 (defcustom gnus-button-alist
4546 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4547 0 t gnus-button-message-id 2)
4548 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4549 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4551 gnus-button-fetch-group 4)
4552 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4553 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4554 t gnus-button-message-id 3)
4555 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4556 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4557 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4558 ;; This is how URLs _should_ be embedded in text...
4559 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4561 (,gnus-button-url-regexp 0 t browse-url 0))
4562 "*Alist of regexps matching buttons in article bodies.
4564 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4565 REGEXP: is the string matching text around the button,
4566 BUTTON: is the number of the regexp grouping actually matching the button,
4567 FORM: is a lisp expression which must eval to true for the button to
4569 CALLBACK: is the function to call when the user push this button, and each
4570 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4572 CALLBACK can also be a variable, in that case the value of that
4573 variable it the real callback function."
4574 :group 'gnus-article-buttons
4575 :type '(repeat (list regexp
4576 (integer :tag "Button")
4578 (function :tag "Callback")
4581 (integer :tag "Regexp group")))))
4583 (defcustom gnus-header-button-alist
4584 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4585 0 t gnus-button-message-id 0)
4586 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4587 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4588 0 t gnus-button-mailto 0)
4589 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4590 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4591 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4592 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4593 gnus-button-message-id 3))
4594 "*Alist of headers and regexps to match buttons in article heads.
4596 This alist is very similar to `gnus-button-alist', except that each
4597 alist has an additional HEADER element first in each entry:
4599 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4601 HEADER is a regexp to match a header. For a fuller explanation, see
4602 `gnus-button-alist'."
4603 :group 'gnus-article-buttons
4604 :group 'gnus-article-headers
4605 :type '(repeat (list (regexp :tag "Header")
4607 (integer :tag "Button")
4609 (function :tag "Callback")
4612 (integer :tag "Regexp group")))))
4614 (defvar gnus-button-regexp nil)
4615 (defvar gnus-button-marker-list nil)
4616 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4618 (defvar gnus-button-last nil)
4619 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4623 (defun gnus-article-push-button (event)
4624 "Check text under the mouse pointer for a callback function.
4625 If the text under the mouse pointer has a `gnus-callback' property,
4626 call it with the value of the `gnus-data' text property."
4628 (set-buffer (window-buffer (posn-window (event-start event))))
4629 (let* ((pos (posn-point (event-start event)))
4630 (data (get-text-property pos 'gnus-data))
4631 (fun (get-text-property pos 'gnus-callback)))
4634 (funcall fun data))))
4636 (defun gnus-article-press-button ()
4637 "Check text at point for a callback function.
4638 If the text at point has a `gnus-callback' property,
4639 call it with the value of the `gnus-data' text property."
4641 (let* ((data (get-text-property (point) 'gnus-data))
4642 (fun (get-text-property (point) 'gnus-callback)))
4644 (funcall fun data))))
4646 (defun gnus-article-prev-button (n)
4647 "Move point to N buttons backward.
4648 If N is negative, move forward instead."
4650 (gnus-article-next-button (- n)))
4652 (defun gnus-article-next-button (n)
4653 "Move point to N buttons forward.
4654 If N is negative, move backward instead."
4656 (let ((function (if (< n 0) 'previous-single-property-change
4657 'next-single-property-change))
4658 (inhibit-point-motion-hooks t)
4660 (limit (if (< n 0) (point-min) (point-max))))
4662 (while (and (not (= limit (point)))
4664 ;; Skip past the current button.
4665 (when (get-text-property (point) 'gnus-callback)
4666 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4667 ;; Go to the next (or previous) button.
4668 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4669 ;; Put point at the start of the button.
4670 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4671 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4672 ;; Skip past intangible buttons.
4673 (when (get-text-property (point) 'intangible)
4677 (gnus-message 5 "No more buttons"))
4680 (defun gnus-article-highlight (&optional force)
4681 "Highlight current article.
4682 This function calls `gnus-article-highlight-headers',
4683 `gnus-article-highlight-citation',
4684 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4685 do the highlighting. See the documentation for those functions."
4686 (interactive (list 'force))
4687 (gnus-article-highlight-headers)
4688 (gnus-article-highlight-citation force)
4689 (gnus-article-highlight-signature)
4690 (gnus-article-add-buttons force)
4691 (gnus-article-add-buttons-to-head))
4693 (defun gnus-article-highlight-some (&optional force)
4694 "Highlight current article.
4695 This function calls `gnus-article-highlight-headers',
4696 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4697 do the highlighting. See the documentation for those functions."
4698 (interactive (list 'force))
4699 (gnus-article-highlight-headers)
4700 (gnus-article-highlight-signature)
4701 (gnus-article-add-buttons))
4703 (defun gnus-article-highlight-headers ()
4704 "Highlight article headers as specified by `gnus-header-face-alist'."
4707 (set-buffer gnus-article-buffer)
4709 (let ((alist gnus-header-face-alist)
4710 (buffer-read-only nil)
4711 (case-fold-search t)
4712 (inhibit-point-motion-hooks t)
4713 entry regexp header-face field-face from hpoints fpoints)
4714 (article-narrow-to-head)
4715 (while (setq entry (pop alist))
4716 (goto-char (point-min))
4717 (setq regexp (concat "^\\("
4718 (if (string-equal "" (nth 0 entry))
4722 header-face (nth 1 entry)
4723 field-face (nth 2 entry))
4724 (while (and (re-search-forward regexp nil t)
4728 (unless (search-forward ":" nil t)
4730 (when (and header-face
4731 (not (memq (point) hpoints)))
4732 (push (point) hpoints)
4733 (gnus-put-text-property from (point) 'face header-face))
4734 (when (and field-face
4735 (not (memq (setq from (point)) fpoints)))
4737 (if (re-search-forward "^[^ \t]" nil t)
4739 (goto-char (point-max)))
4740 (gnus-put-text-property from (point) 'face field-face))))))))
4742 (defun gnus-article-highlight-signature ()
4743 "Highlight the signature in an article.
4744 It does this by highlighting everything after
4745 `gnus-signature-separator' using `gnus-signature-face'."
4747 (when gnus-signature-face
4749 (set-buffer gnus-article-buffer)
4750 (let ((buffer-read-only nil)
4751 (inhibit-point-motion-hooks t))
4753 (when (gnus-article-narrow-to-signature)
4754 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4755 'face gnus-signature-face)))))))
4757 (defun gnus-article-buttonize-signature ()
4758 "Add button to the signature."
4761 (set-buffer gnus-article-buffer)
4762 (let ((buffer-read-only nil)
4763 (inhibit-point-motion-hooks t))
4764 (when (gnus-article-search-signature)
4765 (gnus-article-add-button (match-beginning 0) (match-end 0)
4766 'gnus-signature-toggle
4767 (set-marker (make-marker)
4768 (1+ (match-end 0))))))))
4770 (defun gnus-button-in-region-p (b e prop)
4771 "Say whether PROP exists in the region."
4772 (text-property-not-all b e prop nil))
4774 (defun gnus-article-add-buttons (&optional force)
4775 "Find external references in the article and make buttons of them.
4776 \"External references\" are things like Message-IDs and URLs, as
4777 specified by `gnus-button-alist'."
4778 (interactive (list 'force))
4780 (set-buffer gnus-article-buffer)
4781 (let ((buffer-read-only nil)
4782 (inhibit-point-motion-hooks t)
4783 (case-fold-search t)
4784 (alist gnus-button-alist)
4786 ;; Remove all old markers.
4787 (let (marker entry new-list)
4788 (while (setq marker (pop gnus-button-marker-list))
4789 (if (or (< marker (point-min)) (>= marker (point-max)))
4790 (push marker new-list)
4792 (when (setq entry (gnus-button-entry))
4793 (put-text-property (match-beginning (nth 1 entry))
4794 (match-end (nth 1 entry))
4795 'gnus-callback nil))
4796 (set-marker marker nil)))
4797 (setq gnus-button-marker-list new-list))
4798 ;; We skip the headers.
4801 (while (setq entry (pop alist))
4802 (setq regexp (car entry))
4804 (while (re-search-forward regexp nil t)
4805 (let* ((start (and entry (match-beginning (nth 1 entry))))
4806 (end (and entry (match-end (nth 1 entry))))
4807 (from (match-beginning 0)))
4808 (when (and (or (eq t (nth 2 entry))
4809 (eval (nth 2 entry)))
4810 (not (gnus-button-in-region-p
4811 start end 'gnus-callback)))
4812 ;; That optional form returned non-nil, so we add the
4814 (gnus-article-add-button
4815 start end 'gnus-button-push
4816 (car (push (set-marker (make-marker) from)
4817 gnus-button-marker-list))))))))))
4819 ;; Add buttons to the head of an article.
4820 (defun gnus-article-add-buttons-to-head ()
4821 "Add buttons to the head of the article."
4824 (set-buffer gnus-article-buffer)
4826 (let ((buffer-read-only nil)
4827 (inhibit-point-motion-hooks t)
4828 (case-fold-search t)
4829 (alist gnus-header-button-alist)
4831 (article-narrow-to-head)
4833 ;; Each alist entry.
4834 (setq entry (car alist)
4836 (goto-char (point-min))
4837 (while (re-search-forward (car entry) nil t)
4838 ;; Each header matching the entry.
4839 (setq beg (match-beginning 0))
4840 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4841 (match-beginning 0))
4844 (while (re-search-forward (nth 1 entry) end t)
4845 ;; Each match within a header.
4846 (let* ((entry (cdr entry))
4847 (start (match-beginning (nth 1 entry)))
4848 (end (match-end (nth 1 entry)))
4849 (form (nth 2 entry)))
4850 (goto-char (match-end 0))
4852 (gnus-article-add-button
4853 start end (nth 3 entry)
4854 (buffer-substring (match-beginning (nth 4 entry))
4855 (match-end (nth 4 entry)))))))
4856 (goto-char end)))))))
4858 ;;; External functions:
4860 (defun gnus-article-add-button (from to fun &optional data)
4861 "Create a button between FROM and TO with callback FUN and data DATA."
4862 (when gnus-article-button-face
4863 (gnus-overlay-put (gnus-make-overlay from to)
4864 'face gnus-article-button-face))
4865 (gnus-add-text-properties
4867 (nconc (and gnus-article-mouse-face
4868 (list gnus-mouse-face-prop gnus-article-mouse-face))
4869 (list 'gnus-callback fun)
4870 (and data (list 'gnus-data data))))
4871 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4872 ;; Quote `:button-keymap' for Mule 2.3
4873 ;; but it won't work.
4874 ':button-keymap gnus-widget-button-keymap))
4876 ;;; Internal functions:
4878 (defun gnus-article-set-globals ()
4880 (set-buffer gnus-summary-buffer)
4881 (gnus-set-global-variables)))
4883 (defun gnus-signature-toggle (end)
4885 (set-buffer gnus-article-buffer)
4886 (let ((buffer-read-only nil)
4887 (inhibit-point-motion-hooks t)
4888 (limit (next-single-property-change end 'mime-view-entity
4890 (if (get-text-property end 'invisible)
4891 (gnus-article-unhide-text end limit)
4892 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4894 (defun gnus-button-entry ()
4895 ;; Return the first entry in `gnus-button-alist' matching this place.
4896 (let ((alist gnus-button-alist)
4899 (setq entry (pop alist))
4900 (if (looking-at (car entry))
4905 (defun gnus-button-push (marker)
4906 ;; Push button starting at MARKER.
4909 (let* ((entry (gnus-button-entry))
4910 (inhibit-point-motion-hooks t)
4912 (args (mapcar (lambda (group)
4913 (let ((string (match-string group)))
4914 (gnus-set-text-properties
4915 0 (length string) nil string)
4922 (fboundp (symbol-value fun)))
4923 (apply (symbol-value fun) args))
4925 (gnus-message 1 "You must define `%S' to use this button"
4926 (cons fun args)))))))
4928 (defun gnus-button-message-id (message-id)
4931 (set-buffer gnus-summary-buffer)
4932 (gnus-summary-refer-article message-id)))
4934 (defun gnus-button-fetch-group (address)
4935 "Fetch GROUP specified by ADDRESS."
4936 (if (not (string-match "[:/]" address))
4937 ;; This is just a simple group url.
4938 (gnus-group-read-ephemeral-group address gnus-select-method)
4939 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4941 (error "Can't parse %s" address)
4942 (gnus-group-read-ephemeral-group
4943 (match-string 4 address)
4944 `(nntp ,(match-string 1 address)
4945 (nntp-address ,(match-string 1 address))
4946 (nntp-port-number ,(if (match-end 3)
4947 (match-string 3 address)
4950 (defun gnus-url-parse-query-string (query &optional downcase)
4951 (let (retval pairs cur key val)
4952 (setq pairs (split-string query "&"))
4954 (setq cur (car pairs)
4956 (if (not (string-match "=" cur))
4958 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4959 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4961 (setq key (downcase key)))
4962 (setq cur (assoc key retval))
4964 (setcdr cur (cons val (cdr cur)))
4965 (setq retval (cons (list key val) retval)))))
4968 (defun gnus-url-unhex (x)
4975 (defun gnus-url-unhex-string (str &optional allow-newlines)
4976 "Remove %XXX embedded spaces, etc in a url.
4977 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4978 decoding of carriage returns and line feeds in the string, which is normally
4979 forbidden in URL encoding."
4980 (setq str (or str ""))
4982 (case-fold-search t))
4983 (while (string-match "%[0-9a-f][0-9a-f]" str)
4984 (let* ((start (match-beginning 0))
4985 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4987 (gnus-url-unhex (elt str (+ start 2))))))
4989 tmp (substring str 0 start)
4992 (char-to-string code))
4993 ((or (= code ?\n) (= code ?\r))
4995 (t (char-to-string code))))
4996 str (substring str (match-end 0)))))
4997 (setq tmp (concat tmp str))
5000 (defun gnus-url-mailto (url)
5001 ;; Send mail to someone
5002 (when (string-match "mailto:/*\\(.*\\)" url)
5003 (setq url (substring url (match-beginning 1) nil)))
5004 (let (to args subject func)
5005 (if (string-match (regexp-quote "?") url)
5006 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5007 args (gnus-url-parse-query-string
5008 (substring url (match-end 0) nil) t))
5009 (setq to (gnus-url-unhex-string url)))
5010 (setq args (cons (list "to" to) args)
5011 subject (cdr-safe (assoc "subject" args)))
5012 (gnus-setup-message 'reply
5015 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5018 (message-position-on-field (caar args)))
5019 (insert (mapconcat 'identity (cdar args) ", "))
5020 (setq args (cdr args)))
5023 (message-goto-subject)))))
5025 (defun gnus-button-mailto (address)
5027 (set-buffer (gnus-copy-article-buffer))
5028 (gnus-setup-message 'reply
5029 (message-reply address)))
5031 (defun gnus-button-reply (address)
5032 ;; Reply to ADDRESS.
5033 (gnus-setup-message 'reply
5034 (message-reply address)))
5036 (defun gnus-button-embedded-url (address)
5038 (browse-url (gnus-strip-whitespace address)))
5040 (defun gnus-article-smiley-display ()
5041 "Display \"smileys\" as small graphical icons."
5042 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5044 ;;; Next/prev buttons in the article buffer.
5046 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5047 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5049 (defvar gnus-prev-page-map nil)
5050 (unless gnus-prev-page-map
5051 (setq gnus-prev-page-map (make-sparse-keymap))
5052 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5053 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5055 (static-if (featurep 'xemacs)
5056 (defun gnus-insert-prev-page-button ()
5057 (let ((buffer-read-only nil))
5059 gnus-prev-page-line-format nil
5060 `(gnus-prev t local-map ,gnus-prev-page-map
5061 gnus-callback gnus-article-button-prev-page
5062 article-type annotation))))
5063 (defun gnus-insert-prev-page-button ()
5064 (let ((buffer-read-only nil)
5065 (situation (get-text-property (point-min) 'mime-view-situation)))
5066 (set-keymap-parent gnus-prev-page-map (current-local-map))
5068 gnus-prev-page-line-format nil
5069 `(gnus-prev t local-map ,gnus-prev-page-map
5070 gnus-callback gnus-article-button-prev-page
5071 article-type annotation
5072 mime-view-situation ,situation))))
5075 (defvar gnus-next-page-map nil)
5076 (unless gnus-next-page-map
5077 (setq gnus-next-page-map (make-sparse-keymap))
5078 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5079 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5081 (defun gnus-button-next-page ()
5082 "Go to the next page."
5084 (let ((win (selected-window)))
5085 (select-window (get-buffer-window gnus-article-buffer t))
5086 (gnus-article-next-page)
5087 (select-window win)))
5089 (defun gnus-button-prev-page ()
5090 "Go to the prev page."
5092 (let ((win (selected-window)))
5093 (select-window (get-buffer-window gnus-article-buffer t))
5094 (gnus-article-prev-page)
5095 (select-window win)))
5097 (static-if (featurep 'xemacs)
5098 (defun gnus-insert-next-page-button ()
5099 (let ((buffer-read-only nil))
5100 (gnus-eval-format gnus-next-page-line-format nil
5102 t local-map ,gnus-next-page-map
5103 gnus-callback gnus-article-button-next-page
5104 article-type annotation))))
5105 (defun gnus-insert-next-page-button ()
5106 (let ((buffer-read-only nil)
5107 (situation (get-text-property (point-min) 'mime-view-situation)))
5108 (set-keymap-parent gnus-next-page-map (current-local-map))
5109 (gnus-eval-format gnus-next-page-line-format nil
5111 t local-map ,gnus-next-page-map
5112 gnus-callback gnus-article-button-next-page
5113 article-type annotation
5114 mime-view-situation ,situation))))
5117 (defun gnus-article-button-next-page (arg)
5118 "Go to the next page."
5120 (let ((win (selected-window)))
5121 (select-window (get-buffer-window gnus-article-buffer t))
5122 (gnus-article-next-page)
5123 (select-window win)))
5125 (defun gnus-article-button-prev-page (arg)
5126 "Go to the prev page."
5128 (let ((win (selected-window)))
5129 (select-window (get-buffer-window gnus-article-buffer t))
5130 (gnus-article-prev-page)
5131 (select-window win)))
5133 (defvar gnus-decode-header-methods
5134 '(mail-decode-encoded-word-region)
5135 "List of methods used to decode headers.
5137 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5138 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5139 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5140 whose names match REGEXP.
5143 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5144 mail-decode-encoded-word-region
5145 (\"chinese\" . rfc1843-decode-region))
5148 (defvar gnus-decode-header-methods-cache nil)
5150 (defun gnus-multi-decode-header (start end)
5151 "Apply the functions from `gnus-encoded-word-methods' that match."
5152 (unless (and gnus-decode-header-methods-cache
5153 (eq gnus-newsgroup-name
5154 (car gnus-decode-header-methods-cache)))
5155 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5158 (nconc gnus-decode-header-methods-cache (list x))
5159 (if (and gnus-newsgroup-name
5160 (string-match (car x) gnus-newsgroup-name))
5161 (nconc gnus-decode-header-methods-cache
5163 gnus-decode-header-methods))
5164 (let ((xlist gnus-decode-header-methods-cache))
5167 (narrow-to-region start end)
5169 (funcall (pop xlist) (point-min) (point-max))))))
5172 ;;; Treatment top-level handling.
5175 (defun gnus-treat-article (condition &optional part-number total-parts type)
5176 (let ((length (- (point-max) (point-min)))
5177 (alist gnus-treatment-function-alist)
5178 (article-goto-body-goes-to-point-min-p t)
5182 (let ((list gnus-article-treat-types))
5184 (when (string-match (pop list) type)
5185 (throw 'found t)))))))
5186 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5187 (entity (static-unless (featurep 'xemacs)
5188 (when (eq 'head condition)
5189 (get-text-property (point-min) 'mime-view-entity))))
5190 val elem buttonized)
5191 (gnus-run-hooks 'gnus-part-display-hook)
5192 (unless gnus-inhibit-treatment
5193 (while (setq elem (pop alist))
5196 (if (gnus-buffer-live-p gnus-summary-buffer)
5197 (set-buffer gnus-summary-buffer))
5198 (symbol-value (car elem))))
5199 (when (and (or (consp val)
5201 (gnus-treat-predicate val)
5202 (or (not (get (car elem) 'highlight))
5204 (when (and (not buttonized)
5206 '(gnus-treat-hide-signature
5207 gnus-treat-highlight-signature)))
5208 (gnus-article-buttonize-signature)
5209 (setq buttonized t))
5211 (funcall (cadr elem)))))
5212 ;; FSF Emacsen does not inherit the existing text properties
5213 ;; in the new text, so we should do it for `mime-view-entity'.
5214 (static-unless (featurep 'xemacs)
5216 (put-text-property (point-min) (point-max)
5217 'mime-view-entity entity))))))
5219 ;; Dynamic variables.
5220 (defvar part-number)
5221 (defvar total-parts)
5225 (defun gnus-treat-predicate (val)
5230 (stringp (car val)))
5231 (apply 'gnus-or (mapcar `(lambda (s)
5232 (string-match s ,(or gnus-newsgroup-name "")))
5235 (let ((pred (pop val)))
5238 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5240 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5242 (not (gnus-treat-predicate (car val))))
5244 (equal (car val) type))
5246 (error "%S is not a valid predicate" pred)))))
5256 (eq part-number total-parts))
5260 (error "%S is not a valid value" val))))
5266 (defun gnus-article-header-presentation-method (entity situation)
5267 (mime-insert-header entity)
5270 (set-alist 'mime-header-presentation-method-alist
5271 'gnus-original-article-mode
5272 #'gnus-article-header-presentation-method)
5274 (defun gnus-mime-preview-quitting-method ()
5275 (mime-preview-kill-buffer)
5276 (delete-other-windows)
5277 (gnus-article-show-summary)
5278 (gnus-summary-select-article gnus-show-all-headers t))
5280 (set-alist 'mime-preview-quitting-method-alist
5281 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5283 (set-alist 'mime-preview-following-method-alist
5284 'gnus-original-article-mode #'gnus-following-method)
5286 (set-alist 'mime-preview-over-to-previous-method-alist
5287 'gnus-original-article-mode
5289 (if (> (point-min) 1)
5290 (gnus-article-prev-page)
5291 (gnus-article-read-summary-keys
5292 nil (gnus-character-to-event ?P)))))
5294 (set-alist 'mime-preview-over-to-next-method-alist
5295 'gnus-original-article-mode'
5297 (if (< (point-max) (buffer-size))
5298 (gnus-article-next-page)
5299 (gnus-article-read-summary-keys
5300 nil (gnus-character-to-event ?N)))))
5310 (run-hooks 'gnus-art-load-hook)
5312 ;;; gnus-art.el ends here