1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
31 (eval-when-compile (require 'static))
42 ;; Avoid byte-compile warnings.
51 (defgroup gnus-article nil
53 :link '(custom-manual "(gnus)The Article Buffer")
56 (defgroup gnus-article-treat nil
57 "Treating article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-hiding nil
62 "Hiding article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-highlight nil
67 "Article highlighting."
68 :link '(custom-manual "(gnus)Article Highlighting")
72 (defgroup gnus-article-signature nil
74 :link '(custom-manual "(gnus)Article Signature")
77 (defgroup gnus-article-headers nil
79 :link '(custom-manual "(gnus)Hiding Headers")
82 (defgroup gnus-article-washing nil
83 "Special commands on articles."
84 :link '(custom-manual "(gnus)Article Washing")
87 (defgroup gnus-article-emphasis nil
88 "Fontisizing articles."
89 :link '(custom-manual "(gnus)Article Fontisizing")
92 (defgroup gnus-article-saving nil
94 :link '(custom-manual "(gnus)Saving Articles")
97 (defgroup gnus-article-mime nil
98 "Worshiping the MIME wonder."
99 :link '(custom-manual "(gnus)Using MIME")
100 :group 'gnus-article)
102 (defgroup gnus-article-buttons nil
103 "Pushable buttons in the article buffer."
104 :link '(custom-manual "(gnus)Article Buttons")
105 :group 'gnus-article)
107 (defgroup gnus-article-various nil
108 "Other article options."
109 :link '(custom-manual "(gnus)Misc Article")
110 :group 'gnus-article)
112 (defcustom gnus-ignored-headers
113 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
114 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
115 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
116 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
117 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
118 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
119 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
120 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
121 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
122 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
123 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
124 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
125 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
126 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
127 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
128 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
129 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
130 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
131 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
132 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
133 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
134 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
135 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
136 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
137 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
138 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
139 "^X-Received:" "^Content-length:" "X-precedence:")
140 "*All headers that start with this regexp will be hidden.
141 This variable can also be a list of regexps of headers to be ignored.
142 If `gnus-visible-headers' is non-nil, this variable will be ignored."
143 :type '(choice :custom-show nil
146 :group 'gnus-article-hiding)
148 (defcustom gnus-visible-headers
149 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
150 "*All headers that do not match this regexp will be hidden.
151 This variable can also be a list of regexp of headers to remain visible.
152 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
153 :type '(repeat :value-to-internal (lambda (widget value)
154 (custom-split-regexp-maybe value))
155 :match (lambda (widget value)
157 (widget-editable-list-match widget value)))
159 :group 'gnus-article-hiding)
161 (defcustom gnus-sorted-header-list
162 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
163 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
164 "*This variable is a list of regular expressions.
165 If it is non-nil, headers that match the regular expressions will
166 be placed first in the article buffer in the sequence specified by
168 :type '(repeat regexp)
169 :group 'gnus-article-hiding)
171 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
172 "Headers that are only to be displayed if they have interesting data.
173 Possible values in this list are `empty', `newsgroups', `followup-to',
174 `reply-to', `date', `long-to', and `many-to'."
175 :type '(set (const :tag "Headers with no content." empty)
176 (const :tag "Newsgroups with only one group." newsgroups)
177 (const :tag "Followup-to identical to newsgroups." followup-to)
178 (const :tag "Reply-to identical to from." reply-to)
179 (const :tag "Date less than four days old." date)
180 (const :tag "Very long To and/or Cc header." long-to)
181 (const :tag "Multiple To and/or Cc headers." many-to))
182 :group 'gnus-article-hiding)
184 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
185 "Regexp matching signature separator.
186 This can also be a list of regexps. In that case, it will be checked
187 from head to tail looking for a separator. Searches will be done from
188 the end of the buffer."
189 :type '(repeat string)
190 :group 'gnus-article-signature)
192 (defcustom gnus-signature-limit nil
193 "Provide a limit to what is considered a signature.
194 If it is a number, no signature may not be longer (in characters) than
195 that number. If it is a floating point number, no signature may be
196 longer (in lines) than that number. If it is a function, the function
197 will be called without any parameters, and if it returns nil, there is
198 no signature in the buffer. If it is a string, it will be used as a
199 regexp. If it matches, the text in question is not a signature."
200 :type '(choice (integer :value 200)
202 (function :value fun)
203 (regexp :value ".*"))
204 :group 'gnus-article-signature)
206 (defcustom gnus-hidden-properties '(invisible t intangible t)
207 "Property list to use for hiding text."
209 :group 'gnus-article-hiding)
211 (defcustom gnus-article-x-face-command
213 ;; Fixme: This isn't the right thing for mixed graphical and and
214 ;; non-graphical frames in a session.
215 ;; gnus-xmas.el overrides this for XEmacs.
216 ((and (fboundp 'image-type-available-p)
217 (image-type-available-p 'xbm))
218 'gnus-article-display-xface)
219 ((and (not gnus-xemacs)
221 (module-installed-p 'x-face-mule))
222 'x-face-mule-gnus-article-display-x-face)
224 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"))
225 "*String or function to be executed to display an X-Face header.
226 If it is a string, the command will be executed in a sub-shell
227 asynchronously. The compressed face will be piped to this command."
228 :type '(choice string
229 (function-item gnus-article-display-xface)
230 (function-item x-face-mule-gnus-article-display-x-face)
232 :group 'gnus-article-washing)
234 (defcustom gnus-article-x-face-too-ugly nil
235 "Regexp matching posters whose face shouldn't be shown automatically."
236 :type '(choice regexp (const nil))
237 :group 'gnus-article-washing)
239 (defcustom gnus-article-banner-alist nil
240 "Banner alist for stripping.
242 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
243 :type '(repeat (cons symbol regexp))
244 :group 'gnus-article-washing)
246 (defcustom gnus-emphasis-alist
248 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
250 '(("_" "_" underline)
253 ("_/" "/_" underline-italic)
254 ("_\\*" "\\*_" underline-bold)
255 ("\\*/" "/\\*" bold-italic)
256 ("_\\*/" "/\\*_" underline-bold-italic))))
257 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
258 2 3 gnus-emphasis-underline)
262 (format format (car spec) (car (cdr spec)))
263 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
265 "*Alist that says how to fontify certain phrases.
266 Each item looks like this:
268 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
270 The first element is a regular expression to be matched. The second
271 is a number that says what regular expression grouping used to find
272 the entire emphasized word. The third is a number that says what
273 regexp grouping should be displayed and highlighted. The fourth
274 is the face used for highlighting."
275 :type '(repeat (list :value ("" 0 0 default)
277 (integer :tag "Match group")
278 (integer :tag "Emphasize group")
280 :group 'gnus-article-emphasis)
282 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
283 "A regexp to describe whitespace which should not be emphasized.
284 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
285 The former avoids underlining of leading and trailing whitespace,
286 and the latter avoids underlining any whitespace at all."
287 :group 'gnus-article-emphasis
290 (defface gnus-emphasis-bold '((t (:bold t)))
291 "Face used for displaying strong emphasized text (*word*)."
292 :group 'gnus-article-emphasis)
294 (defface gnus-emphasis-italic '((t (:italic t)))
295 "Face used for displaying italic emphasized text (/word/)."
296 :group 'gnus-article-emphasis)
298 (defface gnus-emphasis-underline '((t (:underline t)))
299 "Face used for displaying underlined emphasized text (_word_)."
300 :group 'gnus-article-emphasis)
302 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
303 "Face used for displaying underlined bold emphasized text (_*word*_)."
304 :group 'gnus-article-emphasis)
306 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
307 "Face used for displaying underlined italic emphasized text (_/word/_)."
308 :group 'gnus-article-emphasis)
310 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
311 "Face used for displaying bold italic emphasized text (/*word*/)."
312 :group 'gnus-article-emphasis)
314 (defface gnus-emphasis-underline-bold-italic
315 '((t (:bold t :italic t :underline t)))
316 "Face used for displaying underlined bold italic emphasized text.
317 Esample: (_/*word*/_)."
318 :group 'gnus-article-emphasis)
320 (defface gnus-emphasis-highlight-words
321 '((t (:background "black" :foreground "yellow")))
322 "Face used for displaying highlighted words."
323 :group 'gnus-article-emphasis)
325 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
326 "Format for display of Date headers in article bodies.
327 See `format-time-string' for the possible values.
329 The variable can also be function, which should return a complete Date
330 header. The function is called with one argument, the time, which can
331 be fed to `format-time-string'."
332 :type '(choice string symbol)
333 :link '(custom-manual "(gnus)Article Date")
334 :group 'gnus-article-washing)
337 (autoload 'mail-extract-address-components "mail-extr"))
339 (defcustom gnus-save-all-headers t
340 "*If non-nil, don't remove any headers before saving."
341 :group 'gnus-article-saving
344 (defcustom gnus-prompt-before-saving 'always
345 "*This variable says how much prompting is to be done when saving articles.
346 If it is nil, no prompting will be done, and the articles will be
347 saved to the default files. If this variable is `always', each and
348 every article that is saved will be preceded by a prompt, even when
349 saving large batches of articles. If this variable is neither nil not
350 `always', there the user will be prompted once for a file name for
351 each invocation of the saving commands."
352 :group 'gnus-article-saving
353 :type '(choice (item always)
354 (item :tag "never" nil)
355 (sexp :tag "once" :format "%t\n" :value t)))
357 (defcustom gnus-saved-headers gnus-visible-headers
358 "Headers to keep if `gnus-save-all-headers' is nil.
359 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
360 If that variable is nil, however, all headers that match this regexp
361 will be kept while the rest will be deleted before saving."
362 :group 'gnus-article-saving
365 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
366 "A function to save articles in your favourite format.
367 The function must be interactively callable (in other words, it must
368 be an Emacs command).
370 Gnus provides the following functions:
372 * gnus-summary-save-in-rmail (Rmail format)
373 * gnus-summary-save-in-mail (Unix mail format)
374 * gnus-summary-save-in-folder (MH folder)
375 * gnus-summary-save-in-file (article format)
376 * gnus-summary-save-in-vm (use VM's folder format)
377 * gnus-summary-write-to-file (article format -- overwrite)."
378 :group 'gnus-article-saving
379 :type '(radio (function-item gnus-summary-save-in-rmail)
380 (function-item gnus-summary-save-in-mail)
381 (function-item gnus-summary-save-in-folder)
382 (function-item gnus-summary-save-in-file)
383 (function-item gnus-summary-save-in-vm)
384 (function-item gnus-summary-write-to-file)))
386 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
387 "A function generating a file name to save articles in Rmail format.
388 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
389 :group 'gnus-article-saving
392 (defcustom gnus-mail-save-name 'gnus-plain-save-name
393 "A function generating a file name to save articles in Unix mail format.
394 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
395 :group 'gnus-article-saving
398 (defcustom gnus-folder-save-name 'gnus-folder-save-name
399 "A function generating a file name to save articles in MH folder.
400 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
401 :group 'gnus-article-saving
404 (defcustom gnus-file-save-name 'gnus-numeric-save-name
405 "A function generating a file name to save articles in article format.
406 The function is called with NEWSGROUP, HEADERS, and optional
408 :group 'gnus-article-saving
411 (defcustom gnus-split-methods
412 '((gnus-article-archive-name)
413 (gnus-article-nndoc-name))
414 "*Variable used to suggest where articles are to be saved.
415 For instance, if you would like to save articles related to Gnus in
416 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
417 you could set this variable to something like:
419 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
420 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
422 This variable is an alist where the where the key is the match and the
423 value is a list of possible files to save in if the match is non-nil.
425 If the match is a string, it is used as a regexp match on the
426 article. If the match is a symbol, that symbol will be funcalled
427 from the buffer of the article to be saved with the newsgroup as the
428 parameter. If it is a list, it will be evaled in the same buffer.
430 If this form or function returns a string, this string will be used as
431 a possible file name; and if it returns a non-nil list, that list will
432 be used as possible file names."
433 :group 'gnus-article-saving
434 :type '(repeat (choice (list :value (fun) function)
435 (cons :value ("" "") regexp (repeat string))
438 (defcustom gnus-article-display-method-for-mime
439 'gnus-article-display-mime-message
440 "Function to display a MIME message.
441 The function is called from the article buffer."
442 :group 'gnus-article-mime
445 (defcustom gnus-article-display-method-for-traditional
446 'gnus-article-display-traditional-message
447 "*Function to display a traditional message.
448 The function is called from the article buffer."
449 :group 'gnus-article-mime
452 (defcustom gnus-page-delimiter "^\^L"
453 "*Regexp describing what to use as article page delimiters.
454 The default value is \"^\^L\", which is a form linefeed at the
455 beginning of a line."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
460 "*The format specification for the article mode line.
461 See `gnus-summary-mode-line-format' for a closer description.
463 The following additional specs are available:
465 %w The article washing status.
466 %m The number of MIME parts in the article."
468 :group 'gnus-article-various)
470 (defcustom gnus-article-mode-hook nil
471 "*A hook for Gnus article mode."
473 :group 'gnus-article-various)
475 (defcustom gnus-article-menu-hook nil
476 "*Hook run after the creation of the article mode menu."
478 :group 'gnus-article-various)
480 (defcustom gnus-article-prepare-hook nil
481 "*A hook called after an article has been prepared in the article buffer."
483 :group 'gnus-article-various)
485 (defcustom gnus-article-hide-pgp-hook nil
486 "*A hook called after successfully hiding a PGP signature."
488 :group 'gnus-article-various)
490 (defcustom gnus-article-button-face 'bold
491 "Face used for highlighting buttons in the article buffer.
493 An article button is a piece of text that you can activate by pressing
494 `RET' or `mouse-2' above it."
496 :group 'gnus-article-buttons)
498 (defcustom gnus-article-mouse-face 'highlight
499 "Face used for mouse highlighting in the article buffer.
501 Article buttons will be displayed in this face when the cursor is
504 :group 'gnus-article-buttons)
506 (defcustom gnus-signature-face 'gnus-signature-face
507 "Face used for highlighting a signature in the article buffer.
508 Obsolete; use the face `gnus-signature-face' for customizations instead."
510 :group 'gnus-article-highlight
511 :group 'gnus-article-signature)
513 (defface gnus-signature-face
515 "Face used for highlighting a signature in the article buffer."
516 :group 'gnus-article-highlight
517 :group 'gnus-article-signature)
519 (defface gnus-header-from-face
522 (:foreground "spring green"))
525 (:foreground "red3"))
528 "Face used for displaying from headers."
529 :group 'gnus-article-headers
530 :group 'gnus-article-highlight)
532 (defface gnus-header-subject-face
535 (:foreground "SeaGreen3"))
538 (:foreground "red4"))
540 (:bold t :italic t)))
541 "Face used for displaying subject headers."
542 :group 'gnus-article-headers
543 :group 'gnus-article-highlight)
545 (defface gnus-header-newsgroups-face
548 (:foreground "yellow" :italic t))
551 (:foreground "MidnightBlue" :italic t))
554 "Face used for displaying newsgroups headers."
555 :group 'gnus-article-headers
556 :group 'gnus-article-highlight)
558 (defface gnus-header-name-face
561 (:foreground "SeaGreen"))
564 (:foreground "maroon"))
567 "Face used for displaying header names."
568 :group 'gnus-article-headers
569 :group 'gnus-article-highlight)
571 (defface gnus-header-content-face
574 (:foreground "forest green" :italic t))
577 (:foreground "indianred4" :italic t))
579 (:italic t))) "Face used for displaying header content."
580 :group 'gnus-article-headers
581 :group 'gnus-article-highlight)
583 (defcustom gnus-header-face-alist
584 '(("From" nil gnus-header-from-face)
585 ("Subject" nil gnus-header-subject-face)
586 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
587 ("" gnus-header-name-face gnus-header-content-face))
588 "*Controls highlighting of article header.
590 An alist of the form (HEADER NAME CONTENT).
592 HEADER is a regular expression which should match the name of an
593 header header and NAME and CONTENT are either face names or nil.
595 The name of each header field will be displayed using the face
596 specified by the first element in the list where HEADER match the
597 header name and NAME is non-nil. Similarly, the content will be
598 displayed by the first non-nil matching CONTENT face."
599 :group 'gnus-article-headers
600 :group 'gnus-article-highlight
601 :type '(repeat (list (regexp :tag "Header")
603 (item :tag "skip" nil)
604 (face :value default))
605 (choice :tag "Content"
606 (item :tag "skip" nil)
607 (face :value default)))))
609 (defcustom gnus-article-decode-hook nil
610 "*Hook run to decode charsets in articles."
611 :group 'gnus-article-headers
614 (defcustom gnus-display-mime-function 'gnus-display-mime
615 "Function to display MIME articles."
616 :group 'gnus-article-mime
619 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
620 "Function used to decode headers.")
622 (defvar gnus-article-dumbquotes-map
640 "Table for MS-to-Latin1 translation.")
642 (defcustom gnus-ignored-mime-types nil
643 "List of MIME types that should be ignored by Gnus."
644 :group 'gnus-article-mime
645 :type '(repeat regexp))
647 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
648 "List of MIME types that should not be given buttons when rendered inline."
649 :group 'gnus-article-mime
650 :type '(repeat regexp))
652 (defcustom gnus-article-mime-part-function nil
653 "Function called with a MIME handle as the argument.
654 This is meant for people who want to do something automatic based
655 on parts -- for instance, adding Vcard info to a database."
656 :group 'gnus-article-mime
659 (defcustom gnus-mime-multipart-functions nil
660 "An alist of MIME types to functions to display them.")
662 (defcustom gnus-article-date-lapsed-new-header nil
663 "Whether the X-Sent and Date headers can coexist.
664 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
665 either replace the old \"Date:\" header (if this variable is nil), or
666 be added below it (otherwise)."
667 :group 'gnus-article-headers
670 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
671 "Function called with a MIME handle as the argument.
672 This is meant for people who want to view first matched part.
673 For `undisplayed-alternative' (default), the first undisplayed
674 part or alternative part is used. For `undisplayed', the first
675 undisplayed part is used. For a function, the first part which
676 the function return `t' is used. For `nil', the first part is
678 :group 'gnus-article-mime
680 (item :tag "first" :value nil)
681 (item :tag "undisplayed" :value undisplayed)
682 (item :tag "undisplayed or alternative"
683 :value undisplayed-alternative)
687 ;;; The treatment variables
690 (defvar gnus-part-display-hook nil
691 "Hook called on parts that are to receive treatment.")
693 (defvar gnus-article-treat-custom
694 '(choice (const :tag "Off" nil)
696 (const :tag "Header" head)
697 (const :tag "Last" last)
698 (const :tag "Mime" mime)
699 (integer :tag "Less")
700 (repeat :tag "Groups" regexp)
701 (sexp :tag "Predicate")))
703 (defvar gnus-article-treat-head-custom
704 '(choice (const :tag "Off" nil)
705 (const :tag "Header" head)))
707 (defvar gnus-article-treat-types '("text/plain")
710 (defvar gnus-inhibit-treatment nil
711 "Whether to inhibit treatment.")
713 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
714 "Highlight the signature.
715 Valid values are nil, t, `head', `last', an integer or a predicate.
716 See the manual for details."
717 :group 'gnus-article-treat
718 :type gnus-article-treat-custom)
719 (put 'gnus-treat-highlight-signature 'highlight t)
721 (defcustom gnus-treat-buttonize 100000
723 Valid values are nil, t, `head', `last', an integer or a predicate.
724 See the manual for details."
725 :group 'gnus-article-treat
726 :type gnus-article-treat-custom)
727 (put 'gnus-treat-buttonize 'highlight t)
729 (defcustom gnus-treat-buttonize-head 'head
730 "Add buttons to the head.
731 Valid values are nil, t, `head', `last', an integer or a predicate.
732 See the manual for details."
733 :group 'gnus-article-treat
734 :type gnus-article-treat-head-custom)
735 (put 'gnus-treat-buttonize-head 'highlight t)
737 (defcustom gnus-treat-emphasize nil
739 Valid values are nil, t, `head', `last', an integer or a predicate.
740 See the manual for details."
741 :group 'gnus-article-treat
742 :type gnus-article-treat-custom)
743 (put 'gnus-treat-emphasize 'highlight t)
745 (defcustom gnus-treat-strip-cr nil
746 "Remove carriage returns.
747 Valid values are nil, t, `head', `last', an integer or a predicate.
748 See the manual for details."
749 :group 'gnus-article-treat
750 :type gnus-article-treat-custom)
752 (defcustom gnus-treat-hide-headers 'head
754 Valid values are nil, t, `head', `last', an integer or a predicate.
755 See the manual for details."
756 :group 'gnus-article-treat
757 :type gnus-article-treat-head-custom)
759 (defcustom gnus-treat-hide-boring-headers nil
760 "Hide boring headers.
761 Valid values are nil, t, `head', `last', an integer or a predicate.
762 See the manual for details."
763 :group 'gnus-article-treat
764 :type gnus-article-treat-head-custom)
766 (defcustom gnus-treat-hide-signature nil
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770 :group 'gnus-article-treat
771 :type gnus-article-treat-custom)
773 (defcustom gnus-treat-fill-article nil
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-custom)
780 (defcustom gnus-treat-hide-citation nil
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784 :group 'gnus-article-treat
785 :type gnus-article-treat-custom)
787 (defcustom gnus-treat-strip-list-identifiers 'head
788 "Strip list identifiers from `gnus-list-identifiers`.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-custom)
794 (defcustom gnus-treat-strip-pgp t
795 "Strip PGP signatures.
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798 :group 'gnus-article-treat
799 :type gnus-article-treat-custom)
801 (defcustom gnus-treat-strip-pem nil
802 "Strip PEM signatures.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-custom)
808 (defcustom gnus-treat-strip-banner t
809 "Strip banners from articles.
810 The banner to be stripped is specified in the `banner' group parameter.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-custom)
816 (defcustom gnus-treat-highlight-headers 'head
817 "Highlight the headers.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-head-custom)
822 (put 'gnus-treat-highlight-headers 'highlight t)
824 (defcustom gnus-treat-highlight-citation t
825 "Highlight cited text.
826 Valid values are nil, t, `head', `last', an integer or a predicate.
827 See the manual for details."
828 :group 'gnus-article-treat
829 :type gnus-article-treat-custom)
830 (put 'gnus-treat-highlight-citation 'highlight t)
832 (defcustom gnus-treat-date-ut nil
833 "Display the Date in UT (GMT).
834 Valid values are nil, t, `head', `last', an integer or a predicate.
835 See the manual for details."
836 :group 'gnus-article-treat
837 :type gnus-article-treat-head-custom)
839 (defcustom gnus-treat-date-local nil
840 "Display the Date in the local timezone.
841 Valid values are nil, t, `head', `last', an integer or a predicate.
842 See the manual for details."
843 :group 'gnus-article-treat
844 :type gnus-article-treat-head-custom)
846 (defcustom gnus-treat-date-lapsed nil
847 "Display the Date header in a way that says how much time has elapsed.
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See the manual for details."
850 :group 'gnus-article-treat
851 :type gnus-article-treat-head-custom)
853 (defcustom gnus-treat-date-original nil
854 "Display the date in the original timezone.
855 Valid values are nil, t, `head', `last', an integer or a predicate.
856 See the manual for details."
857 :group 'gnus-article-treat
858 :type gnus-article-treat-head-custom)
860 (defcustom gnus-treat-date-iso8601 nil
861 "Display the date in the ISO8601 format.
862 Valid values are nil, t, `head', `last', an integer or a predicate.
863 See the manual for details."
864 :group 'gnus-article-treat
865 :type gnus-article-treat-head-custom)
867 (defcustom gnus-treat-date-user-defined nil
868 "Display the date in a user-defined format.
869 The format is defined by the `gnus-article-time-format' variable.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See the manual for details."
872 :group 'gnus-article-treat
873 :type gnus-article-treat-head-custom)
875 (defcustom gnus-treat-strip-headers-in-body t
876 "Strip the X-No-Archive header line from the beginning of the body.
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See the manual for details."
879 :group 'gnus-article-treat
880 :type gnus-article-treat-custom)
882 (defcustom gnus-treat-strip-trailing-blank-lines nil
883 "Strip trailing blank lines.
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See the manual for details."
886 :group 'gnus-article-treat
887 :type gnus-article-treat-custom)
889 (defcustom gnus-treat-strip-leading-blank-lines nil
890 "Strip leading blank lines.
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See the manual for details."
893 :group 'gnus-article-treat
894 :type gnus-article-treat-custom)
896 (defcustom gnus-treat-strip-multiple-blank-lines nil
897 "Strip multiple blank lines.
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See the manual for details."
900 :group 'gnus-article-treat
901 :type gnus-article-treat-custom)
903 (defcustom gnus-treat-overstrike t
904 "Treat overstrike highlighting.
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See the manual for details."
907 :group 'gnus-article-treat
908 :type gnus-article-treat-custom)
909 (put 'gnus-treat-overstrike 'highlight t)
911 (defcustom gnus-treat-display-xface
912 (and (or (and (fboundp 'image-type-available-p)
913 (image-type-available-p 'xbm))
914 (and gnus-xemacs (featurep 'xface))
915 (eq 'x-face-mule-gnus-article-display-x-face
916 gnus-article-x-face-command))
918 "Display X-Face headers.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921 :group 'gnus-article-treat
922 :type gnus-article-treat-head-custom)
923 (put 'gnus-treat-display-xface 'highlight t)
925 (defcustom gnus-treat-display-smileys
926 (if (or (and gnus-xemacs (featurep 'xpm))
927 (and (not gnus-xemacs)
929 (module-installed-p 'gnus-bitmap)))
933 Valid values are nil, t, `head', `last', an integer or a predicate.
934 See the manual for details."
935 :group 'gnus-article-treat
936 :type gnus-article-treat-custom)
937 (put 'gnus-treat-display-smileys 'highlight t)
939 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See the manual for details."
943 :group 'gnus-article-treat
944 :type gnus-article-treat-head-custom)
945 (put 'gnus-treat-display-picons 'highlight t)
947 (defcustom gnus-treat-capitalize-sentences nil
948 "Capitalize sentence-starting words.
949 Valid values are nil, t, `head', `last', an integer or a predicate.
950 See the manual for details."
951 :group 'gnus-article-treat
952 :type gnus-article-treat-custom)
954 (defcustom gnus-treat-fill-long-lines nil
956 Valid values are nil, t, `head', `last', an integer or a predicate.
957 See the manual for details."
958 :group 'gnus-article-treat
959 :type gnus-article-treat-custom)
961 (defcustom gnus-treat-play-sounds nil
963 Valid values are nil, t, `head', `last', an integer or a predicate.
964 See the manual for details."
965 :group 'gnus-article-treat
966 :type gnus-article-treat-custom)
968 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
969 "Decode an article as `default-mime-charset'. For instance, if you want to
970 attempt to decode an article even if the value of `gnus-show-mime' is nil,
971 you could set this variable to something like: nil for don't decode, t for
972 decode the body, '(or header t) for the whole article, etc."
973 :group 'gnus-article-treat
974 :type '(radio (const :tag "Off" nil)
975 (const :tag "Decode body" t)
976 (const :tag "Decode all" (or head t))))
978 (defcustom gnus-treat-translate nil
979 "Translate articles from one language to another.
980 Valid values are nil, t, `head', `last', an integer or a predicate.
981 See the manual for details."
982 :group 'gnus-article-treat
983 :type gnus-article-treat-custom)
985 ;;; Internal variables
987 (defvar article-goto-body-goes-to-point-min-p nil)
988 (defvar gnus-article-wash-types nil)
989 (defvar gnus-article-emphasis-alist nil)
991 (defvar gnus-article-mime-handle-alist-1 nil)
992 (defvar gnus-treatment-function-alist
993 '((gnus-treat-decode-article-as-default-mime-charset
994 gnus-article-decode-article-as-default-mime-charset)
995 (gnus-treat-strip-banner gnus-article-strip-banner)
996 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
997 (gnus-treat-buttonize gnus-article-add-buttons)
998 (gnus-treat-fill-article gnus-article-fill-cited-article)
999 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1000 (gnus-treat-strip-cr gnus-article-remove-cr)
1001 (gnus-treat-display-xface gnus-article-display-x-face)
1002 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1003 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1004 (gnus-treat-hide-signature gnus-article-hide-signature)
1005 (gnus-treat-hide-citation gnus-article-hide-citation)
1006 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1007 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1008 (gnus-treat-strip-pem gnus-article-hide-pem)
1009 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1010 (gnus-treat-emphasize gnus-article-emphasize)
1011 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1012 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1013 (gnus-treat-date-ut gnus-article-date-ut)
1014 (gnus-treat-date-local gnus-article-date-local)
1015 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1016 (gnus-treat-date-original gnus-article-date-original)
1017 (gnus-treat-date-user-defined gnus-article-date-user)
1018 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1019 (gnus-treat-strip-trailing-blank-lines
1020 gnus-article-remove-trailing-blank-lines)
1021 (gnus-treat-strip-leading-blank-lines
1022 gnus-article-strip-leading-blank-lines)
1023 (gnus-treat-strip-multiple-blank-lines
1024 gnus-article-strip-multiple-blank-lines)
1025 (gnus-treat-overstrike gnus-article-treat-overstrike)
1026 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1027 (gnus-treat-display-smileys gnus-article-smiley-display)
1028 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1029 (gnus-treat-display-picons gnus-article-display-picons)
1030 (gnus-treat-play-sounds gnus-earcon-display)))
1032 (defvar gnus-article-mime-handle-alist nil)
1033 (defvar article-lapsed-timer nil)
1034 (defvar gnus-article-current-summary nil)
1036 (defvar gnus-article-mode-syntax-table
1037 (let ((table (copy-syntax-table text-mode-syntax-table)))
1038 (modify-syntax-entry ?- "w" table)
1039 (modify-syntax-entry ?> ")" table)
1040 (modify-syntax-entry ?< "(" table)
1042 "Syntax table used in article mode buffers.
1043 Initialized from `text-mode-syntax-table.")
1045 (defvar gnus-save-article-buffer nil)
1047 (defvar gnus-article-mode-line-format-alist
1048 (nconc '((?w (gnus-article-wash-status) ?s)
1049 (?m (gnus-article-mime-part-status) ?s))
1050 gnus-summary-mode-line-format-alist))
1052 (defvar gnus-number-of-articles-to-be-saved nil)
1054 (defvar gnus-inhibit-hiding nil)
1056 (defsubst gnus-article-hide-text (b e props)
1057 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1058 (add-text-properties b e props)
1059 (when (memq 'intangible props)
1061 (max (1- b) (point-min))
1062 b 'intangible (cddr (memq 'intangible props)))))
1063 (defsubst gnus-article-unhide-text (b e)
1064 "Remove hidden text properties from region between B and E."
1065 (remove-text-properties b e gnus-hidden-properties)
1066 (when (memq 'intangible gnus-hidden-properties)
1067 (put-text-property (max (1- b) (point-min))
1068 b 'intangible nil)))
1070 (defun gnus-article-hide-text-type (b e type)
1071 "Hide text of TYPE between B and E."
1072 (push type gnus-article-wash-types)
1073 (gnus-article-hide-text
1074 b e (cons 'article-type (cons type gnus-hidden-properties))))
1076 (defun gnus-article-unhide-text-type (b e type)
1077 "Unhide text of TYPE between B and E."
1078 (setq gnus-article-wash-types
1079 (delq type gnus-article-wash-types))
1080 (remove-text-properties
1081 b e (cons 'article-type (cons type gnus-hidden-properties)))
1082 (when (memq 'intangible gnus-hidden-properties)
1083 (put-text-property (max (1- b) (point-min))
1084 b 'intangible nil)))
1086 (defun gnus-article-hide-text-of-type (type)
1087 "Hide text of TYPE in the current buffer."
1089 (let ((b (point-min))
1091 (while (setq b (text-property-any b e 'article-type type))
1092 (add-text-properties b (incf b) gnus-hidden-properties)))))
1094 (defun gnus-article-delete-text-of-type (type)
1095 "Delete text of TYPE in the current buffer."
1097 (let ((b (point-min)))
1098 (while (setq b (text-property-any b (point-max) 'article-type type))
1100 b (or (text-property-not-all b (point-max) 'article-type type)
1103 (defun gnus-article-delete-invisible-text ()
1104 "Delete all invisible text in the current buffer."
1106 (let ((b (point-min)))
1107 (while (setq b (text-property-any b (point-max) 'invisible t))
1109 b (or (text-property-not-all b (point-max) 'invisible t)
1112 (defun gnus-article-text-type-exists-p (type)
1113 "Say whether any text of type TYPE exists in the buffer."
1114 (text-property-any (point-min) (point-max) 'article-type type))
1116 (defsubst gnus-article-header-rank ()
1117 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1118 (let ((list gnus-sorted-header-list)
1121 (when (looking-at (car list))
1123 (setq list (cdr list))
1127 (defun article-hide-headers (&optional arg delete)
1128 "Hide unwanted headers and possibly sort them as well."
1129 (interactive (gnus-article-hidden-arg))
1130 ;; Lars said that this function might be inhibited.
1131 (if (gnus-article-check-hidden-text 'headers arg)
1133 ;; Show boring headers as well.
1134 (gnus-article-show-hidden-text 'boring-headers)
1135 (when (eq 1 (point-min))
1136 (set-window-start (get-buffer-window (current-buffer)) 1)))
1137 (unless gnus-inhibit-hiding
1140 (let ((buffer-read-only nil)
1141 (inhibit-read-only t)
1142 (case-fold-search t)
1143 (max (1+ (length gnus-sorted-header-list)))
1144 (ignored (when (not gnus-visible-headers)
1145 (cond ((stringp gnus-ignored-headers)
1146 gnus-ignored-headers)
1147 ((listp gnus-ignored-headers)
1148 (mapconcat 'identity gnus-ignored-headers
1151 (cond ((stringp gnus-visible-headers)
1152 gnus-visible-headers)
1153 ((and gnus-visible-headers
1154 (listp gnus-visible-headers))
1155 (mapconcat 'identity gnus-visible-headers "\\|"))))
1156 (inhibit-point-motion-hooks t)
1158 ;; First we narrow to just the headers.
1159 (article-narrow-to-head)
1160 ;; Hide any "From " lines at the beginning of (mail) articles.
1161 (while (looking-at "From ")
1165 (delete-region (point-min) (point))
1166 (gnus-article-hide-text (point-min) (point)
1167 (nconc (list 'article-type 'headers)
1168 gnus-hidden-properties))))
1169 ;; Then treat the rest of the header lines.
1170 ;; Then we use the two regular expressions
1171 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1172 ;; select which header lines is to remain visible in the
1174 (while (re-search-forward "^[^ \t]*:" nil t)
1176 ;; Mark the rank of the header.
1178 (point) (1+ (point)) 'message-rank
1179 (if (or (and visible (looking-at visible))
1181 (not (looking-at ignored))))
1182 (gnus-article-header-rank)
1185 (message-sort-headers-1)
1186 (when (setq beg (text-property-any
1187 (point-min) (point-max) 'message-rank (+ 2 max)))
1188 ;; We delete or make invisible the unwanted headers.
1189 (push 'headers gnus-article-wash-types)
1192 (add-text-properties
1193 (point-min) (+ 5 (point-min))
1194 '(article-type headers dummy-invisible t))
1195 (delete-region beg (point-max)))
1196 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1199 (defun article-hide-boring-headers (&optional arg)
1200 "Toggle hiding of headers that aren't very interesting.
1201 If given a negative prefix, always show; if given a positive prefix,
1203 (interactive (gnus-article-hidden-arg))
1204 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1205 (not gnus-show-all-headers))
1208 (let ((buffer-read-only nil)
1209 (list gnus-boring-article-headers)
1210 (inhibit-point-motion-hooks t)
1212 (article-narrow-to-head)
1214 (setq elem (pop list))
1215 (goto-char (point-min))
1217 ;; Hide empty headers.
1219 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1221 (gnus-article-hide-text-type
1222 (progn (beginning-of-line) (point))
1225 (if (re-search-forward "^[^ \t]" nil t)
1229 ;; Hide boring Newsgroups header.
1230 ((eq elem 'newsgroups)
1231 (when (equal (gnus-fetch-field "newsgroups")
1232 (gnus-group-real-name
1233 (if (boundp 'gnus-newsgroup-name)
1236 (gnus-article-hide-header "newsgroups")))
1237 ((eq elem 'followup-to)
1238 (when (equal (message-fetch-field "followup-to")
1239 (message-fetch-field "newsgroups"))
1240 (gnus-article-hide-header "followup-to")))
1241 ((eq elem 'reply-to)
1242 (let ((from (message-fetch-field "from"))
1243 (reply-to (message-fetch-field "reply-to")))
1248 (nth 1 (funcall gnus-extract-address-components from))
1249 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1250 (gnus-article-hide-header "reply-to"))))
1252 (let ((date (message-fetch-field "date")))
1254 (< (days-between (current-time-string) date)
1256 (gnus-article-hide-header "date"))))
1258 (let ((to (message-fetch-field "to"))
1259 (cc (message-fetch-field "cc")))
1260 (when (> (length to) 1024)
1261 (gnus-article-hide-header "to"))
1262 (when (> (length cc) 1024)
1263 (gnus-article-hide-header "cc"))))
1267 (goto-char (point-min))
1268 (while (re-search-forward "^to:" nil t)
1269 (setq to-count (1+ to-count)))
1270 (when (> to-count 1)
1271 (while (> to-count 0)
1272 (goto-char (point-min))
1274 (re-search-forward "^to:" nil nil to-count)
1276 (narrow-to-region (point) (point-max))
1277 (gnus-article-hide-header "to"))
1278 (setq to-count (1- to-count))))
1279 (goto-char (point-min))
1280 (while (re-search-forward "^cc:" nil t)
1281 (setq cc-count (1+ cc-count)))
1282 (when (> cc-count 1)
1283 (while (> cc-count 0)
1284 (goto-char (point-min))
1286 (re-search-forward "^cc:" nil nil cc-count)
1288 (narrow-to-region (point) (point-max))
1289 (gnus-article-hide-header "cc"))
1290 (setq cc-count (1- cc-count)))))))))))))
1292 (defun gnus-article-hide-header (header)
1294 (goto-char (point-min))
1295 (when (re-search-forward (concat "^" header ":") nil t)
1296 (gnus-article-hide-text-type
1297 (progn (beginning-of-line) (point))
1300 (if (re-search-forward "^[^ \t]" nil t)
1305 (defun article-toggle-headers (&optional arg)
1306 "Toggle hiding of headers. If given a negative prefix, always show;
1307 if given a positive prefix, always hide."
1308 (interactive (gnus-article-hidden-arg))
1309 (let ((force (when (numberp arg)
1310 (cond ((> arg 0) 'always-hide)
1311 ((< arg 0) 'always-show))))
1312 (window (get-buffer-window gnus-article-buffer))
1313 (header-end (point-min))
1314 header-start field-end field-start
1315 (inhibit-point-motion-hooks t)
1316 (inhibit-read-only t)
1320 (while (and (setq header-start
1321 (text-property-any header-end (point-max)
1322 'article-treated-header t))
1324 (text-property-not-all header-start (point-max)
1325 'article-treated-header t)))
1326 (setq field-end header-start)
1328 (;; Hide exposed invisible fields.
1329 (and (not (eq 'always-show force))
1331 (text-property-any field-end header-end
1332 'exposed-invisible-field t)))
1333 (while (and field-start
1334 (setq field-end (text-property-not-all
1335 field-start header-end
1336 'exposed-invisible-field t)))
1337 (add-text-properties field-start field-end gnus-hidden-properties)
1338 (setq field-start (text-property-any field-end header-end
1339 'exposed-invisible-field t)))
1340 (put-text-property header-start header-end
1341 'exposed-invisible-field nil))
1342 (;; Expose invisible fields.
1343 (and (not (eq 'always-hide force))
1345 (text-property-any field-end header-end 'invisible t)))
1346 (while (and field-start
1347 (setq field-end (text-property-not-all
1348 field-start header-end
1350 ;; If the invisible text is not terminated with newline, we
1351 ;; won't expose it. Because it may be created by x-face-mule.
1352 ;; BTW, XEmacs sometimes fail in putting a invisible text
1353 ;; property with `gnus-article-hide-text' (really?). In that
1354 ;; case, the invisible text might be started from the middle of
1355 ;; a line so we will expose the sort of thing.
1356 (when (or (not (or (eq header-start field-start)
1357 (eq ?\n (char-before field-start))))
1358 (eq ?\n (char-before field-end)))
1359 (remove-text-properties field-start field-end
1360 gnus-hidden-properties)
1361 (put-text-property field-start field-end
1362 'exposed-invisible-field t))
1363 (setq field-start (text-property-any field-end header-end
1366 (not (eq 'always-show force))
1367 (narrow-to-region header-start header-end)
1368 (article-hide-headers)
1369 ;; Re-display X-Face image under XEmacs.
1370 (when (and gnus-xemacs
1371 (gnus-functionp gnus-article-x-face-command))
1372 (let ((func (cadr (assq 'gnus-treat-display-xface
1373 gnus-treatment-function-alist)))
1375 (when (and (not gnus-inhibit-treatment)
1377 (gnus-treat-predicate gnus-treat-display-xface))
1379 (put-text-property header-start header-end 'read-only nil))))
1382 (goto-char (point-min))
1384 (set-window-start window (point-min))))))
1386 (defvar gnus-article-normalized-header-length 40
1387 "Length of normalized headers.")
1389 (defun article-normalize-headers ()
1390 "Make all header lines 40 characters long."
1392 (let ((buffer-read-only nil)
1396 (article-narrow-to-head)
1399 ((< (setq column (- (gnus-point-at-eol) (point)))
1400 gnus-article-normalized-header-length)
1402 (insert (make-string
1403 (- gnus-article-normalized-header-length column)
1405 ((> column gnus-article-normalized-header-length)
1406 (gnus-put-text-property
1408 (forward-char gnus-article-normalized-header-length)
1415 (forward-line 1))))))
1417 (defun article-treat-dumbquotes ()
1418 "Translate M******** sm*rtq**t*s into proper text.
1419 Note that this function guesses whether a character is a sm*rtq**t* or
1420 not, so it should only be used interactively."
1422 (article-translate-strings gnus-article-dumbquotes-map))
1424 (defun article-translate-characters (from to)
1425 "Translate all characters in the body of the article according to FROM and TO.
1426 FROM is a string of characters to translate from; to is a string of
1427 characters to translate to."
1429 (when (article-goto-body)
1430 (let ((buffer-read-only nil)
1431 (x (make-string 225 ?x))
1433 (while (< (incf i) (length x))
1436 (while (< i (length from))
1437 (aset x (aref from i) (aref to i))
1439 (translate-region (point) (point-max) x)))))
1441 (defun article-translate-strings (map)
1442 "Translate all string in the body of the article according to MAP.
1443 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1445 (when (article-goto-body)
1446 (let ((buffer-read-only nil)
1448 (while (setq elem (pop map))
1450 (while (search-forward (car elem) nil t)
1451 (replace-match (cadr elem)))))))))
1453 (defun article-treat-overstrike ()
1454 "Translate overstrikes into bold text."
1457 (when (article-goto-body)
1458 (let ((buffer-read-only nil))
1459 (while (search-forward "\b" nil t)
1460 (let ((next (char-after))
1464 previous (char-after))
1468 ;; We do the boldification/underlining by hiding the
1469 ;; overstrikes and putting the proper text property
1473 (gnus-article-hide-text-type start (point) 'overstrike)
1474 (put-text-property (point) end 'face 'bold))
1476 (gnus-article-hide-text-type
1477 (1- (point)) (1+ (point)) 'overstrike)
1479 start (1- (point)) 'face 'underline))
1481 (gnus-article-hide-text-type start (point) 'overstrike)
1483 (point) end 'face 'underline)))))))))
1485 (defun article-fill-long-lines ()
1486 "Fill lines that are wider than the window width."
1489 (let ((buffer-read-only nil)
1490 (width (window-width (get-buffer-window (current-buffer)))))
1493 (let ((adaptive-fill-mode nil))
1496 (when (>= (current-column) (min fill-column width))
1497 (narrow-to-region (point) (gnus-point-at-bol))
1498 (fill-paragraph nil)
1499 (goto-char (point-max))
1501 (forward-line 1)))))))
1503 (defun article-capitalize-sentences ()
1504 "Capitalize the first word in each sentence."
1507 (let ((buffer-read-only nil)
1508 (paragraph-start "^[\n\^L]"))
1512 (forward-sentence)))))
1514 (defun article-remove-cr ()
1515 "Remove trailing CRs and then translate remaining CRs into LFs."
1518 (let ((buffer-read-only nil))
1519 (goto-char (point-min))
1520 (while (re-search-forward "\r+$" nil t)
1521 (replace-match "" t t))
1522 (goto-char (point-min))
1523 (while (search-forward "\r" nil t)
1524 (replace-match "\n" t t)))))
1526 (defun article-remove-trailing-blank-lines ()
1527 "Remove all trailing blank lines from the article."
1530 (let ((buffer-read-only nil))
1531 (goto-char (point-max))
1535 (while (and (not (bobp))
1536 (looking-at "^[ \t]*$")
1537 (not (gnus-annotation-in-region-p
1538 (point) (gnus-point-at-eol))))
1543 (defun article-display-x-face (&optional force)
1544 "Look for an X-Face header and display it if present."
1545 (interactive (list 'force))
1547 ;; Delete the old process, if any.
1548 (when (process-status "article-x-face")
1549 (delete-process "article-x-face"))
1550 (let ((inhibit-point-motion-hooks t)
1551 (case-fold-search t)
1554 (article-narrow-to-head)
1555 (goto-char (point-min))
1556 (setq from (message-fetch-field "from"))
1557 (goto-char (point-min))
1558 (while (and gnus-article-x-face-command
1561 ;; Check whether this face is censored.
1562 (not gnus-article-x-face-too-ugly)
1563 (and gnus-article-x-face-too-ugly from
1564 (not (string-match gnus-article-x-face-too-ugly
1566 ;; Has to be present.
1567 (re-search-forward "^X-Face:[ \t]*" nil t))
1568 ;; This used to try to do multiple faces (`while' instead of
1569 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1570 ;; work (b) it can crash some versions of Emacs (c) are
1571 ;; multiple faces really something to encourage?
1572 (when (stringp gnus-article-x-face-command)
1574 ;; We now have the area of the buffer where the X-Face is stored.
1577 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1578 ;; We display the face.
1579 (if (symbolp gnus-article-x-face-command)
1580 ;; The command is a lisp function, so we call it.
1581 (if (gnus-functionp gnus-article-x-face-command)
1582 (funcall gnus-article-x-face-command beg end)
1583 (error "%s is not a function" gnus-article-x-face-command))
1584 ;; The command is a string, so we interpret the command
1585 ;; as a, well, command, and fork it off.
1586 (let ((process-connection-type nil))
1587 (process-kill-without-query
1589 "article-x-face" nil shell-file-name shell-command-switch
1590 gnus-article-x-face-command))
1591 (process-send-region "article-x-face" beg end)
1592 (process-send-eof "article-x-face"))))))))))
1594 (defun article-decode-mime-words ()
1595 "Decode all MIME-encoded words in the article."
1598 (set-buffer gnus-article-buffer)
1599 (let ((inhibit-point-motion-hooks t)
1601 (mail-parse-charset gnus-newsgroup-charset)
1602 (mail-parse-ignored-charsets
1603 (save-excursion (set-buffer gnus-summary-buffer)
1604 gnus-newsgroup-ignored-charsets)))
1605 (mail-decode-encoded-word-region (point-min) (point-max)))))
1607 (defun article-decode-charset (&optional prompt)
1608 "Decode charset-encoded text in the article.
1609 If PROMPT (the prefix), prompt for a coding system to use."
1611 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1613 (mail-parse-charset gnus-newsgroup-charset)
1614 (mail-parse-ignored-charsets
1615 (save-excursion (condition-case nil
1616 (set-buffer gnus-summary-buffer)
1618 gnus-newsgroup-ignored-charsets))
1619 ct cte ctl charset format)
1622 (article-narrow-to-head)
1623 (setq ct (message-fetch-field "Content-Type" t)
1624 cte (message-fetch-field "Content-Transfer-Encoding" t)
1625 ctl (and ct (ignore-errors
1626 (mail-header-parse-content-type ct)))
1629 (mm-read-coding-system "Charset to decode: "))
1631 (mail-content-type-get ctl 'charset)))
1632 format (and ctl (mail-content-type-get ctl 'format)))
1634 (setq cte (mail-header-strip cte)))
1635 (if (and ctl (not (string-match "/" (car ctl))))
1637 (goto-char (point-max)))
1640 (narrow-to-region (point) (point-max))
1641 (when (and (eq mail-parse-charset 'gnus-decoded)
1642 (eq (mm-body-7-or-8) '8bit))
1643 ;; The text code could have been decoded.
1644 (setq charset mail-parse-charset))
1645 (when (and (or (not ctl)
1646 (equal (car ctl) "text/plain"))
1647 (not format)) ;; article with format will decode later.
1649 charset (and cte (intern (downcase
1650 (gnus-strip-whitespace cte))))
1653 (defun article-decode-encoded-words ()
1654 "Remove encoded-word encoding from headers."
1655 (let (buffer-read-only)
1656 (let ((charset (save-excursion
1657 (set-buffer gnus-summary-buffer)
1658 default-mime-charset)))
1659 (mime-decode-header-in-buffer charset)
1662 (defun article-de-quoted-unreadable (&optional force)
1663 "Translate a quoted-printable-encoded article.
1664 If FORCE, decode the article whether it is marked as quoted-printable
1666 (interactive (list 'force))
1668 (let ((buffer-read-only nil) type charset)
1669 (if (gnus-buffer-live-p gnus-original-article-buffer)
1670 (with-current-buffer gnus-original-article-buffer
1672 (gnus-fetch-field "content-transfer-encoding"))
1673 (let* ((ct (gnus-fetch-field "content-type"))
1676 (mail-header-parse-content-type ct)))))
1677 (setq charset (and ctl
1678 (mail-content-type-get ctl 'charset)))
1679 (if (stringp charset)
1680 (setq charset (intern (downcase charset)))))))
1682 (setq charset gnus-newsgroup-charset))
1684 (and type (string-match "quoted-printable" (downcase type))))
1686 (quoted-printable-decode-region (point) (point-max) charset)))))
1688 (defun article-de-base64-unreadable (&optional force)
1689 "Translate a base64 article.
1690 If FORCE, decode the article whether it is marked as base64 not."
1691 (interactive (list 'force))
1693 (let ((buffer-read-only nil) type charset)
1694 (if (gnus-buffer-live-p gnus-original-article-buffer)
1695 (with-current-buffer gnus-original-article-buffer
1697 (gnus-fetch-field "content-transfer-encoding"))
1698 (let* ((ct (gnus-fetch-field "content-type"))
1701 (mail-header-parse-content-type ct)))))
1702 (setq charset (and ctl
1703 (mail-content-type-get ctl 'charset)))
1704 (if (stringp charset)
1705 (setq charset (intern (downcase charset)))))))
1707 (setq charset gnus-newsgroup-charset))
1709 (and type (string-match "base64" (downcase type))))
1712 (narrow-to-region (point) (point-max))
1713 (base64-decode-region (point-min) (point-max))
1714 (if (mm-coding-system-p charset)
1715 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1720 (defun article-decode-HZ ()
1721 "Translate a HZ-encoded article."
1725 (let ((buffer-read-only nil))
1726 (rfc1843-decode-region (point-min) (point-max)))))
1728 (defun article-wash-html ()
1729 "Format an html article."
1732 (let ((buffer-read-only nil)
1734 (if (gnus-buffer-live-p gnus-original-article-buffer)
1735 (with-current-buffer gnus-original-article-buffer
1736 (let* ((ct (gnus-fetch-field "content-type"))
1739 (mail-header-parse-content-type ct)))))
1740 (setq charset (and ctl
1741 (mail-content-type-get ctl 'charset)))
1742 (if (stringp charset)
1743 (setq charset (intern (downcase charset)))))))
1745 (setq charset gnus-newsgroup-charset))
1747 (save-window-excursion
1749 (narrow-to-region (point) (point-max))
1751 (let ((w3-strict-width (window-width))
1752 (url-standalone-mode t))
1754 (w3-region (point-min) (point-max))
1757 (defun article-hide-list-identifiers ()
1758 "Remove list identifies from the Subject header.
1759 The `gnus-list-identifiers' variable specifies what to do."
1763 (let ((inhibit-point-motion-hooks t)
1765 (article-narrow-to-head)
1766 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1767 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1769 (goto-char (point-min))
1770 (when (re-search-forward
1771 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1772 " *\\)\\)+\\(Re: +\\)?\\)")
1774 (let ((s (or (match-string 3) (match-string 5))))
1775 (delete-region (match-beginning 1) (match-end 1))
1777 (goto-char (match-beginning 1))
1780 (defun article-hide-pgp ()
1781 "Remove any PGP headers and signatures in the current article."
1785 (let ((inhibit-point-motion-hooks t)
1786 buffer-read-only beg end)
1788 ;; Hide the "header".
1789 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1790 (push 'pgp gnus-article-wash-types)
1791 (delete-region (match-beginning 0) (match-end 0))
1792 ;; Remove armor headers (rfc2440 6.2)
1793 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1796 ;; Hide the actual signature.
1797 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1798 (setq end (1+ (match-beginning 0)))
1801 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1803 ;; Perhaps we shouldn't hide to the end of the buffer
1804 ;; if there is no end to the signature?
1806 ;; Hide "- " PGP quotation markers.
1808 (narrow-to-region beg end)
1809 (goto-char (point-min))
1810 (while (re-search-forward "^- " nil t)
1812 (match-beginning 0) (match-end 0)))
1814 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1816 (defun article-hide-pem (&optional arg)
1817 "Toggle hiding of any PEM headers and signatures in the current article.
1818 If given a negative prefix, always show; if given a positive prefix,
1820 (interactive (gnus-article-hidden-arg))
1821 (unless (gnus-article-check-hidden-text 'pem arg)
1823 (let (buffer-read-only end)
1824 (goto-char (point-min))
1825 ;; Hide the horrendously ugly "header".
1826 (when (and (search-forward
1827 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1829 (setq end (1+ (match-beginning 0))))
1830 (push 'pem gnus-article-wash-types)
1831 (gnus-article-hide-text-type
1833 (if (search-forward "\n\n" nil t)
1837 ;; Hide the trailer as well
1838 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1840 (gnus-article-hide-text-type
1841 (match-beginning 0) (match-end 0) 'pem)))))))
1843 (defun article-strip-banner ()
1844 "Strip the banner specified by the `banner' group parameter."
1848 (let ((inhibit-point-motion-hooks t)
1849 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1850 (gnus-signature-limit nil)
1851 buffer-read-only beg end)
1855 ((eq banner 'signature)
1856 (when (gnus-article-narrow-to-signature)
1859 (delete-region (point) (point-max))))
1861 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1862 (while (re-search-forward banner nil t)
1863 (delete-region (match-beginning 0) (match-end 0)))))
1865 (while (re-search-forward banner nil t)
1866 (delete-region (match-beginning 0) (match-end 0))))))))))
1868 (defun article-babel ()
1869 "Translate article using an online translation service."
1873 (set-buffer gnus-article-buffer)
1874 (when (article-goto-body)
1875 (let* ((buffer-read-only nil)
1878 (orig (buffer-substring start end))
1879 (trans (babel-as-string orig)))
1881 (narrow-to-region start end)
1882 (delete-region start end)
1885 (defun article-hide-signature (&optional arg)
1886 "Hide the signature in the current article.
1887 If given a negative prefix, always show; if given a positive prefix,
1889 (interactive (gnus-article-hidden-arg))
1895 (article-goto-body))
1896 (goto-char (point-min)))
1897 (unless (gnus-article-check-hidden-text 'signature arg)
1898 (let ((buffer-read-only nil)
1900 (while (setq button (text-property-any button (point-max)
1902 'gnus-signature-toggle))
1903 (setq button (text-property-not-all button (point-max)
1905 'gnus-signature-toggle))
1906 (when (and button (not (eobp)))
1907 (gnus-article-hide-text-type
1909 (next-single-property-change (1+ button) 'mime-view-entity
1913 (defun article-strip-headers-in-body ()
1914 "Strip offensive headers from bodies."
1918 (let ((case-fold-search t))
1919 (when (looking-at "x-no-archive:")
1920 (gnus-delete-line)))))
1922 (defun article-strip-leading-blank-lines ()
1923 "Remove all blank lines from the beginning of the article."
1926 (let ((inhibit-point-motion-hooks t)
1928 (when (article-goto-body)
1929 (while (and (not (eobp))
1930 (looking-at "[ \t]*$"))
1931 (gnus-delete-line))))))
1933 (defun article-narrow-to-head ()
1934 "Narrow the buffer to the head of the message.
1935 Point is left at the beginning of the narrowed-to region."
1937 (goto-char (point-min))
1938 (if (search-forward "\n\n" nil 1)
1941 (goto-char (point-min)))
1943 (defun article-goto-body ()
1944 "Place point at the start of the body."
1945 (goto-char (point-min))
1947 ;; This variable is only bound when dealing with separate
1949 (article-goto-body-goes-to-point-min-p
1951 ((search-forward "\n\n" nil t)
1954 (goto-char (point-max))
1957 (defun article-strip-multiple-blank-lines ()
1958 "Replace consecutive blank lines with one empty line."
1961 (let ((inhibit-point-motion-hooks t)
1963 ;; First make all blank lines empty.
1965 (while (re-search-forward "^[ \t]+$" nil t)
1966 (unless (gnus-annotation-in-region-p
1967 (match-beginning 0) (match-end 0))
1968 (replace-match "" nil t)))
1969 ;; Then replace multiple empty lines with a single empty line.
1971 (while (re-search-forward "\n\n\n+" nil t)
1972 (unless (gnus-annotation-in-region-p
1973 (match-beginning 0) (match-end 0))
1974 (replace-match "\n\n" t t))))))
1976 (defun article-strip-leading-space ()
1977 "Remove all white space from the beginning of the lines in the article."
1980 (let ((inhibit-point-motion-hooks t)
1983 (while (re-search-forward "^[ \t]+" nil t)
1984 (replace-match "" t t)))))
1986 (defun article-strip-trailing-space ()
1987 "Remove all white space from the end of the lines in the article."
1990 (let ((inhibit-point-motion-hooks t)
1993 (while (re-search-forward "[ \t]+$" nil t)
1994 (replace-match "" t t)))))
1996 (defun article-strip-blank-lines ()
1997 "Strip leading, trailing and multiple blank lines."
1999 (article-strip-leading-blank-lines)
2000 (article-remove-trailing-blank-lines)
2001 (article-strip-multiple-blank-lines))
2003 (defun article-strip-all-blank-lines ()
2004 "Strip all blank lines."
2007 (let ((inhibit-point-motion-hooks t)
2010 (while (re-search-forward "^[ \t]*\n" nil t)
2011 (replace-match "" t t)))))
2013 (defun gnus-article-narrow-to-signature ()
2014 "Narrow to the signature; return t if a signature is found, else nil."
2015 (let ((inhibit-point-motion-hooks t))
2016 (when (gnus-article-search-signature)
2018 ;; Check whether we have some limits to what we consider
2019 ;; to be a signature.
2020 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2021 (list gnus-signature-limit)))
2023 (while (setq limit (pop limits))
2024 (if (or (and (integerp limit)
2025 (< (- (point-max) (point)) limit))
2027 (< (count-lines (point) (point-max)) limit))
2028 (and (gnus-functionp limit)
2030 (and (stringp limit)
2031 (not (re-search-forward limit nil t))))
2032 () ; This limit did not succeed.
2036 (narrow-to-region (point) (point-max))
2039 (defun gnus-article-search-signature ()
2040 "Search the current buffer for the signature separator.
2041 Put point at the beginning of the signature separator."
2042 (let ((cur (point)))
2043 (goto-char (point-max))
2044 (if (if (stringp gnus-signature-separator)
2045 (re-search-backward gnus-signature-separator nil t)
2046 (let ((seps gnus-signature-separator))
2048 (not (re-search-backward (car seps) nil t)))
2055 (defun gnus-article-hidden-arg ()
2056 "Return the current prefix arg as a number, or 0 if no prefix."
2057 (list (if current-prefix-arg
2058 (prefix-numeric-value current-prefix-arg)
2061 (defun gnus-article-check-hidden-text (type arg)
2062 "Return nil if hiding is necessary.
2063 Arg can be nil or a number. Nil and positive means hide, negative
2064 means show, 0 means toggle."
2067 (let ((hide (gnus-article-hidden-text-p type)))
2073 (gnus-article-show-hidden-text type))
2075 (if (eq hide 'hidden)
2076 (gnus-article-show-hidden-text type)
2079 (defun gnus-article-hidden-text-p (type)
2080 "Say whether the current buffer contains hidden text of type TYPE."
2081 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2083 (not (get-text-property pos 'invisible))
2084 (not (get-text-property pos 'dummy-invisible)))
2086 (text-property-any (1+ pos) (point-max) 'article-type type)))
2091 (defun gnus-article-show-hidden-text (type &optional hide)
2092 "Show all hidden text of type TYPE.
2093 If HIDE, hide the text instead."
2095 (let ((buffer-read-only nil)
2096 (inhibit-point-motion-hooks t)
2099 (while (setq beg (text-property-any end (point-max) 'article-type type))
2102 (text-property-not-all beg (point-max) 'article-type type)
2105 (gnus-article-hide-text beg end gnus-hidden-properties)
2106 (gnus-article-unhide-text beg end))
2110 (defconst article-time-units
2111 `((year . ,(* 365.25 24 60 60))
2112 (week . ,(* 7 24 60 60))
2113 (day . ,(* 24 60 60))
2117 "Mapping from time units to seconds.")
2119 (defun article-date-ut (&optional type highlight header)
2120 "Convert DATE date to universal time in the current article.
2121 If TYPE is `local', convert to local time; if it is `lapsed', output
2122 how much time has lapsed since DATE. For `lapsed', the value of
2123 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2124 should replace the \"Date:\" one, or should be added below it."
2125 (interactive (list 'ut t))
2126 (let* ((header (or header
2127 (and (eq 1 (point-min))
2128 (mail-header-date (save-excursion
2129 (set-buffer gnus-summary-buffer)
2130 gnus-current-headers)))
2131 (message-fetch-field "date")
2133 (date (if (vectorp header) (mail-header-date header)
2135 (inhibit-point-motion-hooks t)
2136 bface eface date-pos)
2137 (when (and date (not (string= date "")))
2140 (article-narrow-to-head)
2141 (when (or (and (eq type 'lapsed)
2142 gnus-article-date-lapsed-new-header
2143 ;; Attempt to get the face of X-Sent first.
2144 (re-search-forward "^X-Sent:[ \t]" nil t))
2145 (re-search-forward "^Date:[ \t]" nil t)
2146 ;; If Date is missing, try again for X-Sent.
2147 (re-search-forward "^X-Sent:[ \t]" nil t))
2148 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2149 date (or (get-text-property (gnus-point-at-bol)
2152 eface (get-text-property (1- (gnus-point-at-eol))
2154 (let ((buffer-read-only nil))
2155 ;; Delete any old X-Sent headers.
2156 (when (setq date-pos
2157 (text-property-any (point-min) (point-max)
2158 'article-date-lapsed t))
2159 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2160 (delete-region (match-beginning 0)
2161 (progn (forward-line 1) (point))))
2162 (goto-char (point-min))
2163 ;; Delete any old Date headers.
2164 (while (re-search-forward "^Date:[ \t]" nil t)
2166 (setq date-pos (match-beginning 0)))
2167 (unless (and (eq type 'lapsed)
2168 gnus-article-date-lapsed-new-header)
2169 (delete-region (match-beginning 0)
2170 (progn (message-next-header) (point)))))
2173 (goto-char date-pos)
2175 ;; Possibly, Date has been deleted.
2177 (when (and (eq type 'lapsed)
2178 gnus-article-date-lapsed-new-header
2179 (looking-at "Date:"))
2181 (goto-char (point-min)))
2182 (insert (article-make-date-line date type))
2183 (when (eq type 'lapsed)
2184 (put-text-property (gnus-point-at-bol) (point)
2185 'article-date-lapsed t))
2189 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2190 (put-text-property (match-beginning 1) (1+ (match-end 1))
2191 'original-date date)
2192 (put-text-property (match-beginning 1) (1+ (match-end 1))
2194 (put-text-property (match-beginning 2) (match-end 2)
2197 (defun article-make-date-line (date type)
2198 "Return a DATE line of TYPE."
2199 (let ((time (condition-case ()
2203 ;; Convert to the local timezone. We have to slap a
2204 ;; `condition-case' round the calls to the timezone
2205 ;; functions since they aren't particularly resistant to
2208 (let ((tz (car (current-time-zone time))))
2209 (format "Date: %s %s%02d%02d" (current-time-string time)
2210 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2211 (/ (% (abs tz) 3600) 60))))
2212 ;; Convert to Universal Time.
2215 (current-time-string
2216 (let* ((e (parse-time-string date))
2217 (tm (apply 'encode-time e))
2219 (ls (- (cadr tm) (car (current-time-zone time)))))
2220 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2221 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2224 ;; Get the original date from the article.
2225 ((eq type 'original)
2226 (concat "Date: " (if (string-match "\n+$" date)
2227 (substring date 0 (match-beginning 0))
2229 ;; Let the user define the format.
2231 (if (gnus-functionp gnus-article-time-format)
2232 (funcall gnus-article-time-format time)
2235 (format-time-string gnus-article-time-format time))))
2238 (let ((tz (car (current-time-zone time))))
2241 (format-time-string "%Y%m%dT%H%M%S" time)
2242 (format "%s%02d%02d"
2243 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2244 (/ (% (abs tz) 3600) 60)))))
2245 ;; Do an X-Sent lapsed format.
2247 ;; If the date is seriously mangled, the timezone functions are
2248 ;; liable to bug out, so we ignore all errors.
2249 (let* ((now (current-time))
2250 (real-time (subtract-time now time))
2251 (real-sec (and real-time
2252 (+ (* (float (car real-time)) 65536)
2254 (sec (and real-time (abs real-sec)))
2264 ;; This is a bit convoluted, but basically we go
2265 ;; through the time units for years, weeks, etc,
2266 ;; and divide things to see whether that results
2267 ;; in positive answers.
2270 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2271 ;; The (remaining) seconds are too few to
2272 ;; be divided into this time unit.
2274 ;; It's big enough, so we output it.
2275 (setq sec (- sec (* num (cdr unit))))
2277 (concat (if prev ", " "") (int-to-string
2279 " " (symbol-name (car unit))
2280 (if (> num 1) "s" ""))
2282 article-time-units "")
2283 ;; If dates are odd, then it might appear like the
2284 ;; article was sent in the future.
2287 " in the future"))))))
2289 (error "Unknown conversion type: %s" type)))))
2291 (defun article-date-local (&optional highlight)
2292 "Convert the current article date to the local timezone."
2293 (interactive (list t))
2294 (article-date-ut 'local highlight))
2296 (defun article-date-original (&optional highlight)
2297 "Convert the current article date to what it was originally.
2298 This is only useful if you have used some other date conversion
2299 function and want to see what the date was before converting."
2300 (interactive (list t))
2301 (article-date-ut 'original highlight))
2303 (defun article-date-lapsed (&optional highlight)
2304 "Convert the current article date to time lapsed since it was sent."
2305 (interactive (list t))
2306 (article-date-ut 'lapsed highlight))
2308 (defun article-update-date-lapsed ()
2309 "Function to be run from a timer to update the lapsed time line."
2310 (let (deactivate-mark)
2315 (set-buffer (window-buffer w))
2316 (when (eq major-mode 'gnus-article-mode)
2317 (goto-char (point-min))
2318 (when (re-search-forward "^X-Sent:" nil t)
2319 (article-date-lapsed t))))
2322 (defun gnus-start-date-timer (&optional n)
2323 "Start a timer to update the X-Sent header in the article buffers.
2324 The numerical prefix says how frequently (in seconds) the function
2329 (gnus-stop-date-timer)
2330 (setq article-lapsed-timer
2331 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2333 (defun gnus-stop-date-timer ()
2334 "Stop the X-Sent timer."
2336 (when article-lapsed-timer
2337 (nnheader-cancel-timer article-lapsed-timer)
2338 (setq article-lapsed-timer nil)))
2340 (defun article-date-user (&optional highlight)
2341 "Convert the current article date to the user-defined format.
2342 This format is defined by the `gnus-article-time-format' variable."
2343 (interactive (list t))
2344 (article-date-ut 'user highlight))
2346 (defun article-date-iso8601 (&optional highlight)
2347 "Convert the current article date to ISO8601."
2348 (interactive (list t))
2349 (article-date-ut 'iso8601 highlight))
2351 (defun article-show-all ()
2352 "Show all hidden text in the article buffer."
2356 (let ((buffer-read-only nil))
2357 (gnus-article-unhide-text (point-min) (point-max))
2358 (gnus-remove-text-with-property 'gnus-prev)
2359 (gnus-remove-text-with-property 'gnus-next))))
2361 (defun article-show-all-headers ()
2362 "Show all hidden headers in the article buffer."
2367 (article-narrow-to-head)
2368 (let ((buffer-read-only nil))
2369 (gnus-article-unhide-text (point-min) (point-max))))))
2371 (defun article-emphasize (&optional arg)
2372 "Emphasize text according to `gnus-emphasis-alist'."
2373 (interactive (gnus-article-hidden-arg))
2374 (unless (gnus-article-check-hidden-text 'emphasis arg)
2378 (with-current-buffer gnus-summary-buffer
2379 gnus-article-emphasis-alist)
2381 gnus-emphasis-alist))
2382 (buffer-read-only nil)
2383 (props (append '(article-type emphasis)
2384 gnus-hidden-properties))
2385 regexp elem beg invisible visible face)
2388 (while (setq elem (pop alist))
2390 (setq regexp (car elem)
2391 invisible (nth 1 elem)
2392 visible (nth 2 elem)
2394 (while (re-search-forward regexp nil t)
2395 (when (and (match-beginning visible) (match-beginning invisible))
2396 (push 'emphasis gnus-article-wash-types)
2397 (gnus-article-hide-text
2398 (match-beginning invisible) (match-end invisible) props)
2399 (gnus-article-unhide-text-type
2400 (match-beginning visible) (match-end visible) 'emphasis)
2401 (gnus-put-text-property-excluding-newlines
2402 (match-beginning visible) (match-end visible) 'face face)
2403 (goto-char (match-end invisible)))))))))
2405 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2406 "Setup newsgroup emphasis alist."
2407 (unless gnus-article-emphasis-alist
2408 (let ((name (and gnus-newsgroup-name
2409 (gnus-group-real-name gnus-newsgroup-name))))
2410 (make-local-variable 'gnus-article-emphasis-alist)
2411 (setq gnus-article-emphasis-alist
2413 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2414 (while (setq elem (pop alist))
2415 (when (and name (string-match (car elem) name))
2417 highlight (copy-sequence (cdr elem)))))
2419 (copy-sequence highlight-words)
2420 (if gnus-newsgroup-name
2421 (copy-sequence (gnus-group-find-parameter
2422 gnus-newsgroup-name 'highlight-words t)))
2423 gnus-emphasis-alist)))))
2425 (defvar gnus-summary-article-menu)
2426 (defvar gnus-summary-post-menu)
2428 ;;; Saving functions.
2430 (defun gnus-article-save (save-buffer file &optional num)
2431 "Save the currently selected article."
2432 (unless gnus-save-all-headers
2433 ;; Remove headers according to `gnus-saved-headers'.
2434 (let ((gnus-visible-headers
2435 (or gnus-saved-headers gnus-visible-headers))
2436 (gnus-article-buffer save-buffer))
2438 (set-buffer save-buffer)
2439 (article-hide-headers 1 t))))
2440 (save-window-excursion
2441 (if (not gnus-default-article-saver)
2442 (error "No default saver is defined")
2443 ;; !!! Magic! The saving functions all save
2444 ;; `gnus-save-article-buffer' (or so they think), but we
2445 ;; bind that variable to our save-buffer.
2446 (set-buffer gnus-article-buffer)
2447 (let* ((gnus-save-article-buffer save-buffer)
2450 ((not gnus-prompt-before-saving) 'default)
2451 ((eq gnus-prompt-before-saving 'always) nil)
2453 (gnus-number-of-articles-to-be-saved
2454 (when (eq gnus-prompt-before-saving t)
2456 (set-buffer gnus-article-current-summary)
2457 (funcall gnus-default-article-saver filename)))))
2459 (defun gnus-read-save-file-name (prompt &optional filename
2460 function group headers variable)
2462 (funcall function group headers (symbol-value variable)))
2467 ((eq filename 'default)
2473 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2476 (if (and gnus-number-of-articles-to-be-saved
2477 (> gnus-number-of-articles-to-be-saved 1))
2478 (format "these %d articles"
2479 gnus-number-of-articles-to-be-saved)
2482 ;; Let the split methods have their say.
2484 ;; No split name was found.
2487 (concat prompt " (default "
2488 (file-name-nondirectory default-name) ") ")
2489 (file-name-directory default-name)
2491 ;; A single group name is returned.
2492 ((stringp split-name)
2494 (funcall function split-name headers
2495 (symbol-value variable)))
2497 (concat prompt " (default "
2498 (file-name-nondirectory default-name) ") ")
2499 (file-name-directory default-name)
2501 ;; A single split name was found
2502 ((= 1 (length split-name))
2503 (let* ((name (expand-file-name
2504 (car split-name) gnus-article-save-directory))
2505 (dir (cond ((file-directory-p name)
2506 (file-name-as-directory name))
2507 ((file-exists-p name) name)
2508 (t gnus-article-save-directory))))
2510 (concat prompt " (default " name ") ")
2512 ;; A list of splits was found.
2514 (setq split-name (nreverse split-name))
2516 (let ((file-name-history
2517 (nconc split-name file-name-history)))
2521 (concat prompt " (`M-p' for defaults) ")
2522 gnus-article-save-directory
2524 gnus-article-save-directory)))
2525 (car (push result file-name-history)))))))
2526 ;; Create the directory.
2527 (gnus-make-directory (file-name-directory file))
2528 ;; If we have read a directory, we append the default file name.
2529 (when (file-directory-p file)
2530 (setq file (expand-file-name (file-name-nondirectory default-name)
2531 (file-name-as-directory file))))
2532 ;; Possibly translate some characters.
2533 (nnheader-translate-file-chars file))))))
2534 (gnus-make-directory (file-name-directory result))
2535 (set variable result)))
2537 (defun gnus-article-archive-name (group)
2538 "Return the first instance of an \"Archive-name\" in the current buffer."
2539 (let ((case-fold-search t))
2540 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2541 (nnheader-concat gnus-article-save-directory
2542 (match-string 1)))))
2544 (defun gnus-article-nndoc-name (group)
2545 "If GROUP is an nndoc group, return the name of the parent group."
2546 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2547 (gnus-group-get-parameter group 'save-article-group)))
2549 (defun gnus-summary-save-in-rmail (&optional filename)
2550 "Append this article to Rmail file.
2551 Optional argument FILENAME specifies file name.
2552 Directory to save to is default to `gnus-article-save-directory'."
2553 (setq filename (gnus-read-save-file-name
2554 "Save %s in rmail file:" filename
2555 gnus-rmail-save-name gnus-newsgroup-name
2556 gnus-current-headers 'gnus-newsgroup-last-rmail))
2557 (gnus-eval-in-buffer-window gnus-save-article-buffer
2561 (gnus-output-to-rmail filename))))
2564 (defun gnus-summary-save-in-mail (&optional filename)
2565 "Append this article to Unix mail file.
2566 Optional argument FILENAME specifies file name.
2567 Directory to save to is default to `gnus-article-save-directory'."
2568 (setq filename (gnus-read-save-file-name
2569 "Save %s in Unix mail file:" filename
2570 gnus-mail-save-name gnus-newsgroup-name
2571 gnus-current-headers 'gnus-newsgroup-last-mail))
2572 (gnus-eval-in-buffer-window gnus-save-article-buffer
2576 (if (and (file-readable-p filename)
2577 (mail-file-babyl-p filename))
2578 (rmail-output-to-rmail-file filename t)
2579 (gnus-output-to-mail filename)))))
2582 (defun gnus-summary-save-in-file (&optional filename overwrite)
2583 "Append this article to file.
2584 Optional argument FILENAME specifies file name.
2585 Directory to save to is default to `gnus-article-save-directory'."
2586 (setq filename (gnus-read-save-file-name
2587 "Save %s in file:" filename
2588 gnus-file-save-name gnus-newsgroup-name
2589 gnus-current-headers 'gnus-newsgroup-last-file))
2590 (gnus-eval-in-buffer-window gnus-save-article-buffer
2594 (when (and overwrite
2595 (file-exists-p filename))
2596 (delete-file filename))
2597 (gnus-output-to-file filename))))
2600 (defun gnus-summary-write-to-file (&optional filename)
2601 "Write this article to a file.
2602 Optional argument FILENAME specifies file name.
2603 The directory to save in defaults to `gnus-article-save-directory'."
2604 (gnus-summary-save-in-file nil t))
2606 (defun gnus-summary-save-body-in-file (&optional filename)
2607 "Append this article body to a file.
2608 Optional argument FILENAME specifies file name.
2609 The directory to save in defaults to `gnus-article-save-directory'."
2610 (setq filename (gnus-read-save-file-name
2611 "Save %s body in file:" filename
2612 gnus-file-save-name gnus-newsgroup-name
2613 gnus-current-headers 'gnus-newsgroup-last-file))
2614 (gnus-eval-in-buffer-window gnus-save-article-buffer
2618 (when (article-goto-body)
2619 (narrow-to-region (point) (point-max)))
2620 (gnus-output-to-file filename))))
2623 (defun gnus-summary-save-in-pipe (&optional command)
2624 "Pipe this article to subprocess."
2626 (cond ((and (eq command 'default)
2627 gnus-last-shell-command)
2628 gnus-last-shell-command)
2632 "Shell command on %s: "
2633 (if (and gnus-number-of-articles-to-be-saved
2634 (> gnus-number-of-articles-to-be-saved 1))
2635 (format "these %d articles"
2636 gnus-number-of-articles-to-be-saved)
2638 gnus-last-shell-command))))
2639 (when (string-equal command "")
2640 (setq command gnus-last-shell-command))
2641 (gnus-eval-in-buffer-window gnus-article-buffer
2644 (shell-command-on-region (point-min) (point-max) command nil)))
2645 (setq gnus-last-shell-command command))
2647 ;;; Article file names when saving.
2649 (defun gnus-capitalize-newsgroup (newsgroup)
2650 "Capitalize NEWSGROUP name."
2651 (when (not (zerop (length newsgroup)))
2652 (concat (char-to-string (upcase (aref newsgroup 0)))
2653 (substring newsgroup 1))))
2655 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2656 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2657 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2658 Otherwise, it is like ~/News/news/group/num."
2661 (concat (if (gnus-use-long-file-name 'not-save)
2662 (gnus-capitalize-newsgroup newsgroup)
2663 (gnus-newsgroup-directory-form newsgroup))
2664 "/" (int-to-string (mail-header-number headers)))
2665 gnus-article-save-directory)))
2667 (string-equal (file-name-directory default)
2668 (file-name-directory last-file))
2669 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2671 (or last-file default))))
2673 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2674 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2675 If variable `gnus-use-long-file-name' is non-nil, it is
2676 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2679 (concat (if (gnus-use-long-file-name 'not-save)
2681 (gnus-newsgroup-directory-form newsgroup))
2682 "/" (int-to-string (mail-header-number headers)))
2683 gnus-article-save-directory)))
2685 (string-equal (file-name-directory default)
2686 (file-name-directory last-file))
2687 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2689 (or last-file default))))
2691 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2692 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2693 If variable `gnus-use-long-file-name' is non-nil, it is
2694 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2697 (if (gnus-use-long-file-name 'not-save)
2699 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2700 gnus-article-save-directory)))
2707 (setq afunc (car func)
2710 gfunc (intern (format "gnus-%s" func))))
2713 `(lambda (&optional interactive &rest args)
2714 ,(documentation afunc t)
2715 (interactive (list t))
2717 (set-buffer gnus-article-buffer)
2719 (call-interactively ',afunc)
2720 (apply ',afunc args))))))))
2721 '(article-hide-headers
2722 article-hide-boring-headers
2723 article-toggle-headers
2724 article-treat-overstrike
2725 article-fill-long-lines
2726 article-capitalize-sentences
2728 article-display-x-face
2729 article-de-quoted-unreadable
2730 article-de-base64-unreadable
2733 article-hide-list-identifiers
2735 article-strip-banner
2738 article-hide-signature
2739 article-strip-headers-in-body
2740 article-remove-trailing-blank-lines
2741 article-strip-leading-blank-lines
2742 article-strip-multiple-blank-lines
2743 article-strip-leading-space
2744 article-strip-trailing-space
2745 article-strip-blank-lines
2746 article-strip-all-blank-lines
2748 article-date-iso8601
2749 article-date-original
2751 article-decode-mime-words
2752 article-decode-charset
2753 article-decode-encoded-words
2757 article-treat-dumbquotes
2758 article-normalize-headers
2759 (article-show-all-headers . gnus-article-show-all-headers)
2760 (article-show-all . gnus-article-show-all))))
2763 ;;; Gnus article mode
2766 (put 'gnus-article-mode 'mode-class 'special)
2768 (gnus-define-keys gnus-article-mode-map
2769 " " gnus-article-goto-next-page
2770 "\177" gnus-article-goto-prev-page
2771 [delete] gnus-article-goto-prev-page
2772 [backspace] gnus-article-goto-prev-page
2773 "\C-c^" gnus-article-refer-article
2774 "h" gnus-article-show-summary
2775 "s" gnus-article-show-summary
2776 "\C-c\C-m" gnus-article-mail
2777 "?" gnus-article-describe-briefly
2778 "e" gnus-summary-edit-article
2779 "<" beginning-of-buffer
2781 "\C-c\C-i" gnus-info-find-node
2784 "\C-d" gnus-article-read-summary-keys
2785 "\M-*" gnus-article-read-summary-keys
2786 "\M-#" gnus-article-read-summary-keys
2787 "\M-^" gnus-article-read-summary-keys
2788 "\M-g" gnus-article-read-summary-keys)
2790 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2793 (unless (lookup-key gnus-article-mode-map key)
2794 (define-key gnus-article-mode-map key
2795 'gnus-article-read-summary-keys)))
2800 (let ((key (car elt)))
2801 (and (> (length key) 0)
2802 (not (eq 'menu-bar (aref key 0)))
2803 (symbolp (lookup-key gnus-summary-mode-map key))
2805 (accessible-keymaps gnus-summary-mode-map))
2809 (push (char-to-string c) keys)
2813 (defun gnus-article-make-menu-bar ()
2814 (gnus-turn-off-edit-menu 'article)
2815 (unless (boundp 'gnus-article-article-menu)
2817 gnus-article-article-menu gnus-article-mode-map ""
2819 ["Scroll forwards" gnus-article-goto-next-page t]
2820 ["Scroll backwards" gnus-article-goto-prev-page t]
2821 ["Show summary" gnus-article-show-summary t]
2822 ["Fetch Message-ID at point" gnus-article-refer-article t]
2823 ["Mail to address at point" gnus-article-mail t]
2824 ["Send a bug report" gnus-bug t]))
2827 gnus-article-treatment-menu gnus-article-mode-map ""
2829 ["Hide headers" gnus-article-toggle-headers t]
2830 ["Hide signature" gnus-article-hide-signature t]
2831 ["Hide citation" gnus-article-hide-citation t]
2832 ["Treat overstrike" gnus-article-treat-overstrike t]
2833 ["Remove carriage return" gnus-article-remove-cr t]
2834 ["Decode HZ" gnus-article-decode-HZ t]))
2836 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2838 (when (boundp 'gnus-summary-post-menu)
2839 (define-key gnus-article-mode-map [menu-bar post]
2840 (cons "Post" gnus-summary-post-menu)))
2842 (gnus-run-hooks 'gnus-article-menu-hook)))
2844 (defun gnus-article-mode ()
2845 "Major mode for displaying an article.
2847 All normal editing commands are switched off.
2849 The following commands are available in addition to all summary mode
2851 \\<gnus-article-mode-map>
2852 \\[gnus-article-next-page]\t Scroll the article one page forwards
2853 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2854 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2855 \\[gnus-article-show-summary]\t Display the summary buffer
2856 \\[gnus-article-mail]\t Send a reply to the address near point
2857 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2858 \\[gnus-info-find-node]\t Go to the Gnus info node"
2860 (when (gnus-visual-p 'article-menu 'menu)
2861 (gnus-article-make-menu-bar))
2862 (gnus-simplify-mode-line)
2863 (setq mode-name "Article")
2864 (setq major-mode 'gnus-article-mode)
2865 (make-local-variable 'minor-mode-alist)
2866 (unless (assq 'gnus-show-mime minor-mode-alist)
2867 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2868 (use-local-map gnus-article-mode-map)
2869 (gnus-update-format-specifications nil 'article-mode)
2870 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2871 (make-local-variable 'gnus-page-broken)
2872 (make-local-variable 'gnus-button-marker-list)
2873 (make-local-variable 'gnus-article-current-summary)
2874 (make-local-variable 'gnus-article-mime-handles)
2875 (make-local-variable 'gnus-article-decoded-p)
2876 (make-local-variable 'gnus-article-mime-handle-alist)
2877 (make-local-variable 'gnus-article-wash-types)
2878 (gnus-set-default-directory)
2879 (buffer-disable-undo)
2880 (setq buffer-read-only t)
2881 (set-syntax-table gnus-article-mode-syntax-table)
2882 (gnus-run-hooks 'gnus-article-mode-hook))
2884 (defun gnus-article-setup-buffer ()
2885 "Initialize the article buffer."
2886 (let* ((name (if gnus-single-article-buffer "*Article*"
2887 (concat "*Article " gnus-newsgroup-name "*")))
2889 (progn (string-match "\\*Article" name)
2890 (concat " *Original Article"
2891 (substring name (match-end 0))))))
2892 (setq gnus-article-buffer name)
2893 (setq gnus-original-article-buffer original)
2894 (setq gnus-article-mime-handle-alist nil)
2895 ;; This might be a variable local to the summary buffer.
2896 (unless gnus-single-article-buffer
2898 (set-buffer gnus-summary-buffer)
2899 (setq gnus-article-buffer name)
2900 (setq gnus-original-article-buffer original)
2901 (gnus-set-global-variables)))
2902 (gnus-article-setup-highlight-words)
2903 ;; Init original article buffer.
2905 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2906 (set-buffer-multibyte nil)
2907 (setq major-mode 'gnus-original-article-mode)
2908 (make-local-variable 'gnus-original-article))
2909 (if (get-buffer name)
2912 (buffer-disable-undo)
2913 (setq buffer-read-only t)
2914 (unless (eq major-mode 'gnus-article-mode)
2915 (gnus-article-mode))
2918 (set-buffer (gnus-get-buffer-create name))
2920 (make-local-variable 'gnus-summary-buffer)
2921 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2922 (current-buffer)))))
2924 ;; Set article window start at LINE, where LINE is the number of lines
2925 ;; from the head of the article.
2926 (defun gnus-article-set-window-start (&optional line)
2928 (get-buffer-window gnus-article-buffer t)
2930 (set-buffer gnus-article-buffer)
2931 (goto-char (point-min))
2934 (gnus-message 6 "Moved to bookmark")
2935 (search-forward "\n\n" nil t)
2939 ;;; @@ article filters
2942 (defun gnus-article-display-mime-message ()
2943 "Article display method for MIME message."
2944 ;; called from `gnus-original-article-buffer'.
2945 (let (charset all-headers)
2946 (with-current-buffer gnus-summary-buffer
2947 (setq charset default-mime-charset
2948 all-headers gnus-have-all-headers))
2949 (make-local-variable 'default-mime-charset)
2950 (setq default-mime-charset charset)
2951 (with-current-buffer (get-buffer-create gnus-article-buffer)
2952 (make-local-variable 'default-mime-charset)
2953 (setq default-mime-charset charset))
2954 (mime-display-message mime-message-structure
2955 gnus-article-buffer nil gnus-article-mode-map)
2957 (gnus-article-hide-headers nil -1)))
2958 (run-hooks 'gnus-mime-article-prepare-hook))
2960 (defun gnus-article-display-traditional-message ()
2961 "Article display method for traditional message."
2962 (set-buffer gnus-article-buffer)
2963 (let (buffer-read-only)
2965 (insert-buffer-substring gnus-original-article-buffer)))
2967 (defun gnus-article-make-full-mail-header (&optional number charset)
2968 "Create a new mail header structure in a raw article buffer."
2969 (unless (and number charset)
2970 (save-current-buffer
2971 (set-buffer gnus-summary-buffer)
2973 (setq number (or (cdr gnus-article-current) 0)))
2975 (setq charset (or default-mime-charset 'x-ctext)))))
2976 (goto-char (point-min))
2977 (let ((header-end (if (search-forward "\n\n" nil t)
2979 (goto-char (point-max))))
2980 (chars (- (point-max) (point)))
2981 (lines (count-lines (point) (point-max)))
2982 (default-mime-charset charset)
2984 (narrow-to-region (point-min) header-end)
2985 (setq xref (std11-fetch-field "xref"))
2987 (make-full-mail-header
2989 (std11-fetch-field "subject")
2990 (std11-fetch-field "from")
2991 (std11-fetch-field "date")
2992 (std11-fetch-field "message-id")
2993 (std11-fetch-field "references")
2996 (when xref (concat "Xref: " xref)))
2999 (defun gnus-article-prepare (article &optional all-headers header)
3000 "Prepare ARTICLE in article mode buffer.
3001 ARTICLE should either be an article number or a Message-ID.
3002 If ARTICLE is an id, HEADER should be the article headers.
3003 If ALL-HEADERS is non-nil, no headers are hidden."
3005 ;; Make sure we start in a summary buffer.
3006 (unless (eq major-mode 'gnus-summary-mode)
3007 (set-buffer gnus-summary-buffer))
3008 (setq gnus-summary-buffer (current-buffer))
3009 (let* ((gnus-article (if header (mail-header-number header) article))
3010 (summary-buffer (current-buffer))
3011 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3012 (group gnus-newsgroup-name)
3015 (gnus-article-setup-buffer)
3016 (set-buffer gnus-original-article-buffer)
3017 ;; Deactivate active regions.
3018 (when (and (boundp 'transient-mark-mode)
3019 transient-mark-mode)
3020 (setq mark-active nil))
3021 (if (not (setq result (let ((buffer-read-only nil))
3022 (gnus-request-article-this-buffer
3024 ;; There is no such article.
3026 (when (and (numberp article)
3027 (not (memq article gnus-newsgroup-sparse)))
3028 (setq gnus-article-current
3029 (cons gnus-newsgroup-name article))
3030 (set-buffer gnus-summary-buffer)
3031 (setq gnus-current-article article)
3032 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3034 (gnus-summary-set-agent-mark article)
3035 (message "Message marked for downloading"))
3036 (gnus-summary-mark-article article gnus-canceled-mark)
3037 (unless (memq article gnus-newsgroup-sparse)
3038 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3039 (if (or (eq result 'pseudo)
3040 (eq result 'nneething))
3043 (set-buffer summary-buffer)
3044 (push article gnus-newsgroup-history)
3045 (setq gnus-last-article gnus-current-article
3046 gnus-current-article 0
3047 gnus-current-headers nil
3048 gnus-article-current nil)
3049 (if (eq result 'nneething)
3050 (gnus-configure-windows 'summary)
3051 (gnus-configure-windows 'article))
3052 (gnus-set-global-variables))
3053 (let ((gnus-article-mime-handle-alist-1
3054 gnus-article-mime-handle-alist))
3055 (gnus-set-mode-line 'article)))
3056 ;; The result from the `request' was an actual article -
3057 ;; or at least some text that is now displayed in the
3059 (when (and (numberp article)
3060 (not (eq article gnus-current-article)))
3061 ;; Seems like a new article has been selected.
3062 ;; `gnus-current-article' must be an article number.
3064 (set-buffer summary-buffer)
3065 (push article gnus-newsgroup-history)
3066 (setq gnus-last-article gnus-current-article
3067 gnus-current-article article
3068 gnus-current-headers
3069 (gnus-summary-article-header gnus-current-article)
3070 gnus-article-current
3071 (cons gnus-newsgroup-name gnus-current-article))
3072 (unless (vectorp gnus-current-headers)
3073 (setq gnus-current-headers nil))
3074 (gnus-summary-goto-subject gnus-current-article)
3075 (when (gnus-summary-show-thread)
3076 ;; If the summary buffer really was folded, the
3077 ;; previous goto may not actually have gone to
3078 ;; the right article, but the thread root instead.
3080 (gnus-summary-goto-subject gnus-current-article))
3081 (gnus-run-hooks 'gnus-mark-article-hook)
3082 (gnus-set-mode-line 'summary)
3083 (when (gnus-visual-p 'article-highlight 'highlight)
3084 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3085 ;; Set the global newsgroup variables here.
3086 (gnus-set-global-variables)
3087 (setq gnus-have-all-headers
3088 (or all-headers gnus-show-all-headers))))
3089 (when (or (numberp article)
3091 (gnus-article-prepare-display)
3093 (goto-char (point-min))
3094 (setq gnus-page-broken
3095 (when gnus-break-pages
3096 (gnus-narrow-to-page)
3098 (let ((gnus-article-mime-handle-alist-1
3099 gnus-article-mime-handle-alist))
3100 (gnus-set-mode-line 'article))
3102 (set-window-point (get-buffer-window (current-buffer)) (point))
3103 (gnus-configure-windows 'article)
3106 (defun gnus-article-prepare-mime-display (&optional number)
3107 (goto-char (point-min))
3108 (when (re-search-forward "^[^\t ]+:" nil t)
3109 (goto-char (match-beginning 0)))
3110 (let ((entity (if (eq 1 (point-min))
3111 (get-text-property 1 'mime-view-entity)
3112 (get-text-property (point) 'mime-view-entity)))
3113 last-entity child-entity next type)
3114 (setq child-entity (mime-entity-children entity))
3116 (setq last-entity (nth (1- (length child-entity))
3118 (setq last-entity entity))
3120 (narrow-to-region (point)
3121 (if (search-forward "\n\n" nil t)
3124 (gnus-treat-article 'head)
3125 (put-text-property (point-min) (point-max) 'article-treated-header t)
3126 (goto-char (point-max)))
3127 (while (and (not (eobp)) entity)
3128 (setq next (set-marker
3130 (next-single-property-change (point) 'mime-view-entity
3132 (let ((types (mime-entity-content-type entity)))
3133 (while (eq 'multipart (mime-content-type-primary-type types))
3134 (setq entity (car (mime-entity-children entity))
3135 types (mime-entity-content-type entity)))
3137 (setq type (format "%s/%s"
3138 (mime-content-type-primary-type types)
3139 (mime-content-type-subtype types)))))
3140 (if (string-equal type "message/rfc822")
3143 (let ((children (mime-entity-children entity))
3146 (setq last-children (nth (1- (length children)) children))
3149 (not (eq last-children
3150 (get-text-property next 'mime-view-entity)))
3152 (next-single-property-change next
3154 nil (point-max)))))))
3155 (setq next (next-single-property-change next 'mime-view-entity
3158 (narrow-to-region (point) next)
3159 (gnus-article-prepare-mime-display)
3160 (goto-char (point-max)))
3161 (setq entity (get-text-property (point) 'mime-view-entity)))
3163 (narrow-to-region (point) next)
3164 ;; Kludge. We have to count true number, but for now,
3165 ;; part number is here only to achieve `last'.
3166 (gnus-treat-article nil 1
3167 (if (eq entity last-entity)
3170 (goto-char (point-max)))
3171 (setq entity (get-text-property next 'mime-view-entity))))))
3174 (defun gnus-article-prepare-display ()
3175 "Make the current buffer look like a nice article."
3176 (setq gnus-article-wash-types nil)
3177 (gnus-run-hooks 'gnus-tmp-internal-hook)
3178 (gnus-run-hooks 'gnus-article-prepare-hook)
3180 (let (mime-display-header-hook mime-display-text/plain-hook)
3181 (funcall (if gnus-show-mime
3183 (setq mime-message-structure gnus-current-headers)
3184 (mime-buffer-entity-set-buffer-internal
3185 mime-message-structure
3186 gnus-original-article-buffer)
3187 (mime-entity-set-representation-type-internal
3188 mime-message-structure 'mime-buffer-entity)
3189 (luna-send mime-message-structure
3190 'initialize-instance
3191 mime-message-structure)
3192 gnus-article-display-method-for-mime)
3193 gnus-article-display-method-for-traditional)))
3194 ;; Associate this article with the current summary buffer.
3195 (setq gnus-article-current-summary gnus-summary-buffer)
3196 ;; Call the treatment functions.
3197 (let ((inhibit-read-only t)
3202 (gnus-article-prepare-mime-display)
3203 (narrow-to-region (goto-char (point-min))
3204 (if (search-forward "\n\n" nil t)
3207 (gnus-treat-article 'head)
3208 (put-text-property (point-min) (point-max) 'article-treated-header t)
3209 (goto-char (point-max))
3211 (narrow-to-region (point) (point-max))
3212 (gnus-treat-article nil))
3213 (put-text-property (point-min) (point-max) 'read-only nil)))
3214 ;; Perform the article display hooks. Incidentally, this hook is
3215 ;; an obsolete variable by now.
3216 (gnus-run-hooks 'gnus-article-display-hook))
3218 (defun gnus-article-decode-article-as-default-mime-charset ()
3219 "Decode an article as `default-mime-charset'. It won't work if the
3220 value of the variable `gnus-show-mime' is non-nil."
3221 (unless gnus-show-mime
3222 (decode-mime-charset-region (point-min) (point-max)
3223 (with-current-buffer gnus-summary-buffer
3224 default-mime-charset))))
3227 ;;; Gnus MIME viewing functions
3230 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3231 "The following specs can be used:
3233 %T MIME type, along with additional info
3234 %n The `name' parameter
3235 %d The description, if any
3236 %l The length of the encoded part
3237 %p The part identifier number
3238 %e Dots if the part isn't displayed")
3240 (defvar gnus-mime-button-line-format-alist
3241 '((?t gnus-tmp-type ?s)
3242 (?T gnus-tmp-type-long ?s)
3243 (?n gnus-tmp-name ?s)
3244 (?d gnus-tmp-description ?s)
3246 (?l gnus-tmp-length ?d)
3247 (?e gnus-tmp-dots ?s)))
3249 (defvar gnus-mime-button-commands
3250 '((gnus-article-press-button "\r" "Toggle Display")
3251 (gnus-mime-view-part "v" "View Interactively...")
3252 (gnus-mime-view-part-as-type "t" "View As Type...")
3253 (gnus-mime-save-part "o" "Save...")
3254 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3255 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3256 (gnus-mime-internalize-part "E" "View Internally")
3257 (gnus-mime-externalize-part "e" "View Externally")
3258 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3260 (defun gnus-article-mime-part-status ()
3261 (with-current-buffer gnus-article-buffer
3262 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3263 (if (and entity (mime-entity-children entity))
3264 (format " (%d parts)" (length (mime-entity-children entity)))
3267 (defvar gnus-mime-button-map
3268 (let ((map (make-sparse-keymap)))
3269 (set-keymap-parent map gnus-article-mode-map)
3270 (define-key map gnus-mouse-2 'gnus-article-push-button)
3271 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3272 (dolist (c gnus-mime-button-commands)
3273 (define-key map (cadr c) (car c)))
3276 (defun gnus-mime-button-menu (event)
3277 "Construct a context-sensitive menu of MIME commands."
3280 (let ((pos (event-start event)))
3281 (set-buffer (window-buffer (posn-window pos)))
3282 (goto-char (posn-point pos))
3283 (gnus-article-check-buffer)
3284 (let ((response (x-popup-menu
3286 ("" ,@(mapcar (lambda (c)
3287 (cons (caddr c) (car c)))
3288 gnus-mime-button-commands))))))
3290 (call-interactively response))))))
3292 (defun gnus-mime-view-all-parts (&optional handles)
3293 "View all the MIME parts."
3295 (save-current-buffer
3296 (set-buffer gnus-article-buffer)
3297 (let ((handles (or handles gnus-article-mime-handles))
3298 (mail-parse-charset gnus-newsgroup-charset)
3299 (mail-parse-ignored-charsets
3300 (save-excursion (set-buffer gnus-summary-buffer)
3301 gnus-newsgroup-ignored-charsets)))
3302 (if (stringp (car handles))
3303 (gnus-mime-view-all-parts (cdr handles))
3304 (mapcar 'mm-display-part handles)))))
3306 (defun gnus-mime-save-part ()
3307 "Save the MIME part under point."
3309 (gnus-article-check-buffer)
3310 (let ((data (get-text-property (point) 'gnus-data)))
3311 (mm-save-part data)))
3313 (defun gnus-mime-pipe-part ()
3314 "Pipe the MIME part under point to a process."
3316 (gnus-article-check-buffer)
3317 (let ((data (get-text-property (point) 'gnus-data)))
3318 (mm-pipe-part data)))
3320 (defun gnus-mime-view-part ()
3321 "Interactively choose a viewing method for the MIME part under point."
3323 (gnus-article-check-buffer)
3324 (let ((data (get-text-property (point) 'gnus-data)))
3325 (mm-interactively-view-part data)))
3327 (defun gnus-mime-view-part-as-type-internal ()
3328 (gnus-article-check-buffer)
3329 (let* ((name (mail-content-type-get
3330 (mm-handle-type (get-text-property (point) 'gnus-data))
3332 (def-type (and name (mm-default-file-encoding name))))
3333 (and def-type (cons def-type 0))))
3335 (defun gnus-mime-view-part-as-type (mime-type)
3336 "Choose a MIME media type, and view the part as such."
3338 (list (completing-read
3339 "View as MIME type: "
3340 (mapcar #'list (mailcap-mime-types))
3342 (gnus-mime-view-part-as-type-internal))))
3343 (gnus-article-check-buffer)
3344 (let ((handle (get-text-property (point) 'gnus-data)))
3345 (gnus-mm-display-part
3346 (mm-make-handle (mm-handle-buffer handle)
3347 (cons mime-type (cdr (mm-handle-type handle)))
3348 (mm-handle-encoding handle)
3349 (mm-handle-undisplayer handle)
3350 (mm-handle-disposition handle)
3351 (mm-handle-description handle)
3352 (mm-handle-cache handle)
3353 (mm-handle-id handle)))))
3355 (defun gnus-mime-copy-part (&optional handle)
3356 "Put the the MIME part under point into a new buffer."
3358 (gnus-article-check-buffer)
3359 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3360 (contents (mm-get-part handle))|
3361 (base (file-name-nondirectory
3363 (mail-content-type-get (mm-handle-type handle) 'name)
3364 (mail-content-type-get (mm-handle-type handle)
3367 (buffer (generate-new-buffer base)))
3368 (switch-to-buffer buffer)
3370 ;; We do it this way to make `normal-mode' set the appropriate mode.
3373 (setq buffer-file-name (expand-file-name base))
3375 (setq buffer-file-name nil))
3376 (goto-char (point-min))))
3378 (defun gnus-mime-inline-part (&optional handle)
3379 "Insert the MIME part under point into the current buffer."
3381 (gnus-article-check-buffer)
3382 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3386 (if (mm-handle-undisplayer handle)
3387 (mm-remove-part handle)
3388 (setq contents (mm-get-part handle))
3390 (mm-insert-inline handle contents)
3393 (defun gnus-mime-externalize-part (&optional handle)
3394 "View the MIME part under point with an external viewer."
3396 (gnus-article-check-buffer)
3397 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3398 (mm-user-display-methods nil)
3399 (mm-inlined-types nil)
3400 (mail-parse-charset gnus-newsgroup-charset)
3401 (mail-parse-ignored-charsets
3402 (save-excursion (set-buffer gnus-summary-buffer)
3403 gnus-newsgroup-ignored-charsets)))
3404 (if (mm-handle-undisplayer handle)
3405 (mm-remove-part handle)
3406 (mm-display-part handle))))
3408 (defun gnus-mime-internalize-part (&optional handle)
3409 "View the MIME part under point with an internal viewer.
3410 In no internal viewer is available, use an external viewer."
3412 (gnus-article-check-buffer)
3413 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3414 (mm-inlined-types '(".*"))
3415 (mm-inline-large-images t)
3416 (mail-parse-charset gnus-newsgroup-charset)
3417 (mail-parse-ignored-charsets
3418 (save-excursion (set-buffer gnus-summary-buffer)
3419 gnus-newsgroup-ignored-charsets)))
3420 (if (mm-handle-undisplayer handle)
3421 (mm-remove-part handle)
3422 (mm-display-part handle))))
3424 (defun gnus-article-part-wrapper (n function)
3425 (save-current-buffer
3426 (set-buffer gnus-article-buffer)
3427 (when (> n (length gnus-article-mime-handle-alist))
3428 (error "No such part"))
3429 (gnus-article-goto-part n)
3430 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3431 (funcall function handle))))
3433 (defun gnus-article-pipe-part (n)
3434 "Pipe MIME part N, which is the numerical prefix."
3436 (gnus-article-part-wrapper n 'mm-pipe-part))
3438 (defun gnus-article-save-part (n)
3439 "Save MIME part N, which is the numerical prefix."
3441 (gnus-article-part-wrapper n 'mm-save-part))
3443 (defun gnus-article-interactively-view-part (n)
3444 "View MIME part N interactively, which is the numerical prefix."
3446 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3448 (defun gnus-article-copy-part (n)
3449 "Copy MIME part N, which is the numerical prefix."
3451 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3453 (defun gnus-article-externalize-part (n)
3454 "View MIME part N externally, which is the numerical prefix."
3456 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3458 (defun gnus-article-inline-part (n)
3459 "Inline MIME part N, which is the numerical prefix."
3461 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3463 (defun gnus-article-mime-match-handle-first (condition)
3465 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3466 (while (setq ihandle (pop alist))
3468 ((functionp condition)
3469 (funcall condition (cdr ihandle)))
3470 ((eq condition 'undisplayed)
3471 (not (or (mm-handle-undisplayer (cdr ihandle))
3472 (equal (mm-handle-media-type (cdr ihandle))
3473 "multipart/alternative"))))
3474 ((eq condition 'undisplayed-alternative)
3475 (not (mm-handle-undisplayer (cdr ihandle))))
3477 (gnus-article-goto-part (car ihandle))
3478 (or (not n) (< (car ihandle) n)))
3479 (setq n (car ihandle))))
3483 (defun gnus-article-view-part (&optional n)
3484 "View MIME part N, which is the numerical prefix."
3486 (save-current-buffer
3487 (set-buffer gnus-article-buffer)
3488 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3489 gnus-article-mime-match-handle-function)))
3490 (when (> n (length gnus-article-mime-handle-alist))
3491 (error "No such part"))
3492 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3493 (when (gnus-article-goto-part n)
3494 (if (equal (car handle) "multipart/alternative")
3495 (gnus-article-press-button)
3496 (when (eq (gnus-mm-display-part handle) 'internal)
3497 (gnus-set-window-start)))))))
3499 (defun gnus-mm-display-part (handle)
3500 "Display HANDLE and fix MIME button."
3501 (let ((id (get-text-property (point) 'gnus-part))
3506 (let ((window (selected-window))
3507 (mail-parse-charset gnus-newsgroup-charset)
3508 (mail-parse-ignored-charsets
3509 (save-excursion (set-buffer gnus-summary-buffer)
3510 gnus-newsgroup-ignored-charsets)))
3513 (let ((win (get-buffer-window (current-buffer) t))
3516 (select-window win))
3519 (if (mm-handle-displayed-p handle)
3520 ;; This will remove the part.
3521 (mm-display-part handle)
3523 (narrow-to-region (point) (1+ (point)))
3524 (mm-display-part handle)
3525 ;; We narrow to the part itself and
3526 ;; then call the treatment functions.
3527 (goto-char (point-min))
3529 (narrow-to-region (point) (point-max))
3532 (1- (length gnus-article-mime-handles))
3533 (mm-handle-media-type handle)))))
3534 (select-window window))))
3536 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3537 (gnus-insert-mime-button
3538 handle id (list (mm-handle-displayed-p handle)))
3539 (goto-char point))))
3541 (defun gnus-article-goto-part (n)
3542 "Go to MIME part N."
3543 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3545 (goto-char point))))
3547 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3548 (let ((gnus-tmp-name
3549 (or (mail-content-type-get (mm-handle-type handle)
3551 (mail-content-type-get (mm-handle-disposition handle)
3554 (gnus-tmp-type (mm-handle-media-type handle))
3555 (gnus-tmp-description
3556 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3559 (if (if displayed (car displayed)
3560 (mm-handle-displayed-p handle))
3562 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3564 gnus-tmp-type-long b e)
3565 (when (string-match ".*/" gnus-tmp-name)
3566 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3567 (setq gnus-tmp-type-long (concat gnus-tmp-type
3568 (and (not (equal gnus-tmp-name ""))
3569 (concat "; " gnus-tmp-name))))
3570 (or (equal gnus-tmp-description "")
3571 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3576 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3577 `(local-map ,gnus-mime-button-map
3578 keymap ,gnus-mime-button-map
3579 gnus-callback gnus-mm-display-part
3580 gnus-part ,gnus-tmp-id
3581 article-type annotation
3584 (widget-convert-button
3587 :action 'gnus-widget-press-button
3588 :button-keymap gnus-mime-button-map
3590 (lambda (widget/window &optional overlay pos)
3591 ;; Needed to properly clear the message due to a bug in
3592 ;; wid-edit (XEmacs only).
3593 (if (boundp 'help-echo-owns-message)
3594 (setq help-echo-owns-message t))
3596 "%S: %s the MIME part; %S: more options"
3597 (aref gnus-mouse-2 0)
3598 ;; XEmacs will get a single widget arg; Emacs 21 will get
3599 ;; window, overlay, position.
3600 (if (mm-handle-displayed-p
3602 (with-current-buffer (overlay-buffer overlay)
3603 (widget-get (widget-at (overlay-start overlay))
3605 (widget-get widget/window :mime-handle)))
3607 (aref gnus-down-mouse-3 0))))))
3609 (defun gnus-widget-press-button (elems el)
3610 (goto-char (widget-get elems :from))
3611 (gnus-article-press-button))
3613 (defvar gnus-displaying-mime nil)
3615 (defun gnus-display-mime (&optional ihandles)
3616 "Display the MIME parts."
3618 (save-selected-window
3619 (let ((window (get-buffer-window gnus-article-buffer))
3622 (select-window window)
3623 ;; We have to do this since selecting the window
3624 ;; may change the point. So we set the window point.
3625 (set-window-point window point)))
3626 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3627 buffer-read-only handle name type b e display)
3628 (when (and (not ihandles)
3629 (not gnus-displaying-mime))
3630 ;; Top-level call; we clean up.
3631 (when gnus-article-mime-handles
3632 (mm-destroy-parts gnus-article-mime-handles)
3633 (setq gnus-article-mime-handle-alist nil));; A trick.
3634 (setq gnus-article-mime-handles handles)
3635 ;; We allow users to glean info from the handles.
3636 (when gnus-article-mime-part-function
3637 (gnus-mime-part-function handles)))
3639 (or (not (stringp (car handles)))
3642 (when (and (not ihandles)
3643 (not gnus-displaying-mime))
3644 ;; Clean up for mime parts.
3646 (delete-region (point) (point-max)))
3647 (let ((gnus-displaying-mime t))
3648 (gnus-mime-display-part handles)))
3651 (narrow-to-region (point) (point-max))
3652 (gnus-treat-article nil 1 1)
3655 ;; Highlight the headers.
3659 (narrow-to-region (point-min) (point))
3660 (gnus-treat-article 'head))))))))
3662 (defvar gnus-mime-display-multipart-as-mixed nil)
3664 (defun gnus-mime-display-part (handle)
3667 ((not (stringp (car handle)))
3668 (gnus-mime-display-single handle))
3669 ;; User-defined multipart
3670 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3671 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3673 ;; multipart/alternative
3674 ((and (equal (car handle) "multipart/alternative")
3675 (not gnus-mime-display-multipart-as-mixed))
3676 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3677 (push (cons id handle) gnus-article-mime-handle-alist)
3678 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3679 ;; multipart/related
3680 ((and (equal (car handle) "multipart/related")
3681 (not gnus-mime-display-multipart-as-mixed))
3682 ;;;!!!We should find the start part, but we just default
3683 ;;;!!!to the first part.
3684 (gnus-mime-display-part (cadr handle)))
3685 ;; Other multiparts are handled like multipart/mixed.
3687 (gnus-mime-display-mixed (cdr handle)))))
3689 (defun gnus-mime-part-function (handles)
3690 (if (stringp (car handles))
3691 (mapcar 'gnus-mime-part-function (cdr handles))
3692 (funcall gnus-article-mime-part-function handles)))
3694 (defun gnus-mime-display-mixed (handles)
3695 (mapcar 'gnus-mime-display-part handles))
3697 (defun gnus-mime-display-single (handle)
3698 (let ((type (mm-handle-media-type handle))
3699 (ignored gnus-ignored-mime-types)
3706 (when (string-match (pop ignored) type)
3707 (throw 'ignored nil)))
3708 (if (and (setq not-attachment
3709 (and (not (mm-inline-override-p handle))
3710 (or (not (mm-handle-disposition handle))
3711 (equal (car (mm-handle-disposition handle))
3713 (mm-attachment-override-p handle))))
3714 (mm-automatic-display-p handle)
3715 (or (mm-inlined-p handle)
3716 (mm-automatic-external-display-p type)))
3718 (when (equal (mm-handle-media-supertype handle) "text")
3720 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3721 (push (cons id handle) gnus-article-mime-handle-alist)
3722 (when (or (not display)
3723 (not (gnus-unbuttonized-mime-type-p type)))
3724 ;(gnus-article-insert-newline)
3725 (gnus-insert-mime-button
3726 handle id (list (or display (and not-attachment text))))
3727 (gnus-article-insert-newline)
3728 ;(gnus-article-insert-newline)
3730 (let ((beg (point)))
3736 (let ((mail-parse-charset gnus-newsgroup-charset)
3737 (mail-parse-ignored-charsets
3738 (save-excursion (condition-case ()
3739 (set-buffer gnus-summary-buffer)
3741 gnus-newsgroup-ignored-charsets)))
3742 (mm-display-part handle t))
3743 (goto-char (point-max)))
3744 ((and text not-attachment)
3748 (gnus-article-insert-newline)
3749 (mm-insert-inline handle (mm-get-part handle))
3750 (goto-char (point-max))))
3754 (narrow-to-region beg (point))
3756 nil (length gnus-article-mime-handle-alist)
3757 (1- (length gnus-article-mime-handles))
3758 (mm-handle-media-type handle)))))))))
3760 (defun gnus-unbuttonized-mime-type-p (type)
3761 "Say whether TYPE is to be unbuttonized."
3762 (unless gnus-inhibit-mime-unbuttonizing
3764 (let ((types gnus-unbuttonized-mime-types))
3766 (when (string-match (pop types) type)
3767 (throw 'found t)))))))
3769 (defun gnus-article-insert-newline ()
3770 "Insert a newline, but mark it as undeletable."
3771 (gnus-put-text-property
3772 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3774 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3775 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3778 handle buffer-read-only from props begend not-pref)
3779 (save-window-excursion
3782 (narrow-to-region (car ibegend)
3785 (goto-char (car ibegend))
3788 (delete-region (point-min) (point-max))
3789 (mm-remove-parts handles))
3790 (setq begend (list (point-marker)))
3792 (unless (setq not-pref (cadr (member preferred ihandles)))
3793 (setq not-pref (car ihandles)))
3795 (not (gnus-unbuttonized-mime-type-p
3796 "multipart/alternative")))
3797 (gnus-add-text-properties
3800 (insert (format "%d. " id))
3804 (unless ,(not ibegend)
3805 (setq gnus-article-mime-handle-alist
3806 ',gnus-article-mime-handle-alist))
3807 (gnus-mime-display-alternative
3808 ',ihandles ',not-pref ',begend ,id))
3809 local-map ,gnus-mime-button-map
3810 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3811 face ,gnus-article-button-face
3812 keymap ,gnus-mime-button-map
3815 (widget-convert-button 'link from (point)
3816 :action 'gnus-widget-press-button
3817 :button-keymap gnus-widget-button-keymap)
3819 (while (setq handle (pop handles))
3820 (gnus-add-text-properties
3823 (insert (format "(%c) %-18s"
3824 (if (equal handle preferred) ?* ? )
3825 (mm-handle-media-type handle)))
3829 (unless ,(not ibegend)
3830 (setq gnus-article-mime-handle-alist
3831 ',gnus-article-mime-handle-alist))
3832 (gnus-mime-display-alternative
3833 ',ihandles ',handle ',begend ,id))
3834 local-map ,gnus-mime-button-map
3835 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3836 face ,gnus-article-button-face
3837 keymap ,gnus-mime-button-map
3840 (widget-convert-button 'link from (point)
3841 :action 'gnus-widget-press-button
3842 :button-keymap gnus-widget-button-keymap)
3846 (if (stringp (car preferred))
3847 (gnus-display-mime preferred)
3848 (let ((mail-parse-charset gnus-newsgroup-charset)
3849 (mail-parse-ignored-charsets
3850 (save-excursion (set-buffer gnus-summary-buffer)
3851 gnus-newsgroup-ignored-charsets)))
3852 (mm-display-part preferred)
3856 (narrow-to-region (car begend) (point-max))
3858 nil (length gnus-article-mime-handle-alist)
3859 (1- (length gnus-article-mime-handles))
3860 (mm-handle-media-type handle))))))
3861 (goto-char (point-max))
3862 (setcdr begend (point-marker)))))
3864 (goto-char point))))
3866 (defun gnus-article-wash-status ()
3867 "Return a string which display status of article washing."
3869 (set-buffer gnus-article-buffer)
3870 (let ((cite (memq 'cite gnus-article-wash-types))
3871 (headers (memq 'headers gnus-article-wash-types))
3872 (boring (memq 'boring-headers gnus-article-wash-types))
3873 (pgp (memq 'pgp gnus-article-wash-types))
3874 (pem (memq 'pem gnus-article-wash-types))
3875 (signature (memq 'signature gnus-article-wash-types))
3876 (overstrike (memq 'overstrike gnus-article-wash-types))
3877 (emphasis (memq 'emphasis gnus-article-wash-types)))
3878 (format "%c%c%c%c%c%c%c"
3880 (if (or headers boring) ?h ? )
3881 (if (or pgp pem) ?p ? )
3882 (if signature ?s ? )
3883 (if overstrike ?o ? )
3884 (if gnus-show-mime ?m ? )
3885 (if emphasis ?e ? )))))
3887 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3889 (defun gnus-article-maybe-hide-headers ()
3890 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3891 Provided for backwards compatibility."
3892 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3893 (not (save-excursion (set-buffer gnus-summary-buffer)
3894 gnus-have-all-headers)))
3895 (not gnus-inhibit-hiding))
3896 (gnus-article-hide-headers)))
3900 (defun gnus-output-to-file (file-name)
3901 "Append the current article to a file named FILE-NAME."
3902 (let ((artbuf (current-buffer)))
3904 (insert-buffer-substring artbuf)
3905 ;; Append newline at end of the buffer as separator, and then
3907 (goto-char (point-max))
3909 (write-region-as-binary (point-min) (point-max) file-name 'append)
3912 (defun gnus-narrow-to-page (&optional arg)
3913 "Narrow the article buffer to a page.
3914 If given a numerical ARG, move forward ARG pages."
3916 (setq arg (if arg (prefix-numeric-value arg) 0))
3918 (set-buffer gnus-article-buffer)
3919 (goto-char (point-min))
3921 ;; Remove any old next/prev buttons.
3922 (when (gnus-visual-p 'page-marker)
3923 (let ((buffer-read-only nil))
3924 (gnus-remove-text-with-property 'gnus-prev)
3925 (gnus-remove-text-with-property 'gnus-next)))
3928 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3930 (re-search-forward page-delimiter nil 'move arg)))
3931 (goto-char (match-end 0)))
3934 (if (re-search-forward page-delimiter nil 'move)
3937 (when (and (gnus-visual-p 'page-marker)
3938 (not (= (point-min) 1)))
3940 (goto-char (point-min))
3941 (gnus-insert-prev-page-button)))
3942 (when (and (gnus-visual-p 'page-marker)
3943 (< (+ (point-max) 2) (buffer-size)))
3945 (goto-char (point-max))
3946 (gnus-insert-next-page-button)))))
3948 ;; Article mode commands
3950 (defun gnus-article-goto-next-page ()
3951 "Show the next page of the article."
3953 (when (gnus-article-next-page)
3954 (goto-char (point-min))
3955 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3957 (defun gnus-article-goto-prev-page ()
3958 "Show the next page of the article."
3960 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3961 (gnus-article-prev-page nil)))
3963 (defun gnus-article-next-page (&optional lines)
3964 "Show the next page of the current article.
3965 If end of article, return non-nil. Otherwise return nil.
3966 Argument LINES specifies lines to be scrolled up."
3968 (let ((start (window-start))
3969 end-of-buffer end-of-page)
3971 (move-to-window-line -1)
3972 (if (<= (point) start)
3975 (setq start (point)))
3978 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3979 (and (pos-visible-in-window-p)
3980 (setq end-of-buffer t)))
3982 (setq end-of-page t)))
3984 (move-to-window-line lines)
3985 (unless (search-backward "\n\n" nil t)
3986 (setq start (point)))))
3987 (cond (end-of-buffer t)
3989 (gnus-narrow-to-page 1)
3993 (set-window-start (selected-window) start)
3994 (let (window-pixel-scroll-increment)
3998 (defun gnus-article-prev-page (&optional lines)
3999 "Show previous page of current article.
4000 Argument LINES specifies lines to be scrolled down."
4002 (let (beginning-of-buffer beginning-of-page)
4004 (move-to-window-line 0)
4005 (cond ((eq 1 (point))
4006 (setq beginning-of-buffer t))
4008 (setq beginning-of-page t))))
4009 (cond (beginning-of-buffer)
4011 (gnus-narrow-to-page -1))
4014 (let (window-pixel-scroll-increment)
4015 (scroll-down lines))
4016 (beginning-of-buffer
4017 (goto-char (point-min))))))))
4019 (defun gnus-article-refer-article ()
4020 "Read article specified by message-id around point."
4022 (let ((point (point)))
4023 (search-forward ">" nil t) ;Move point to end of "<....>".
4024 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4025 (let ((message-id (match-string 1)))
4027 (set-buffer gnus-summary-buffer)
4028 (gnus-summary-refer-article message-id))
4030 (error "No references around point"))))
4032 (defun gnus-article-show-summary ()
4033 "Reconfigure windows to show summary buffer."
4035 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4036 (error "There is no summary buffer for this article buffer")
4037 (gnus-article-set-globals)
4038 (gnus-configure-windows 'article)
4039 (gnus-summary-goto-subject gnus-current-article)
4040 (gnus-summary-position-point)))
4042 (defun gnus-article-describe-briefly ()
4043 "Describe article mode commands briefly."
4045 (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")))
4047 (defun gnus-article-summary-command ()
4048 "Execute the last keystroke in the summary buffer."
4050 (let ((obuf (current-buffer))
4051 (owin (current-window-configuration))
4053 (switch-to-buffer gnus-article-current-summary 'norecord)
4054 (setq func (lookup-key (current-local-map) (this-command-keys)))
4055 (call-interactively func)
4057 (set-window-configuration owin)
4058 (set-window-point (get-buffer-window (current-buffer)) (point))))
4060 (defun gnus-article-summary-command-nosave ()
4061 "Execute the last keystroke in the summary buffer."
4064 (pop-to-buffer gnus-article-current-summary 'norecord)
4065 (setq func (lookup-key (current-local-map) (this-command-keys)))
4066 (call-interactively func)))
4068 (defun gnus-article-check-buffer ()
4069 "Beep if not in an article buffer."
4070 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4071 (error "Command invoked outside of a Gnus article buffer")))
4073 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4074 "Read a summary buffer key sequence and execute it from the article buffer."
4076 (gnus-article-check-buffer)
4078 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4079 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4080 "=" "^" "\M-^" "|"))
4086 '("n" "Gn" "p" "Gp"))
4089 (set-buffer gnus-article-current-summary)
4090 (let (gnus-pick-mode)
4091 (push (or key last-command-event) unread-command-events)
4092 (setq keys (static-if (featurep 'xemacs)
4093 (events-to-keys (read-key-sequence nil))
4094 (read-key-sequence nil)))))
4097 (if (or (member keys nosaves)
4098 (member keys nosave-but-article)
4099 (member keys nosave-in-article))
4101 (save-window-excursion
4102 (pop-to-buffer gnus-article-current-summary 'norecord)
4103 ;; We disable the pick minor mode commands.
4104 (let (gnus-pick-mode)
4105 (setq func (lookup-key (current-local-map) keys))))
4109 (unless (member keys nosave-in-article)
4110 (set-buffer gnus-article-current-summary))
4111 (call-interactively func)
4112 (setq new-sum-point (point)))
4113 (when (member keys nosave-but-article)
4114 (pop-to-buffer gnus-article-buffer 'norecord)))
4115 ;; These commands should restore window configuration.
4116 (let ((obuf (current-buffer))
4117 (owin (current-window-configuration))
4119 (summary gnus-article-current-summary)
4120 func in-buffer selected)
4121 (if not-restore-window
4122 (pop-to-buffer summary 'norecord)
4123 (switch-to-buffer summary 'norecord))
4124 (setq in-buffer (current-buffer))
4125 ;; We disable the pick minor mode commands.
4126 (if (setq func (let (gnus-pick-mode)
4127 (lookup-key (current-local-map) keys)))
4129 (call-interactively func)
4130 (setq new-sum-point (point)))
4132 (when (eq in-buffer (current-buffer))
4133 (setq selected (gnus-summary-select-article))
4135 (unless not-restore-window
4136 (set-window-configuration owin))
4137 (when (eq selected 'old)
4139 (set-window-start (get-buffer-window (current-buffer))
4141 (set-window-point (get-buffer-window (current-buffer))
4143 (let ((win (get-buffer-window gnus-article-current-summary)))
4145 (set-window-point win new-sum-point))))))))
4147 (defun gnus-article-hide (&optional arg force)
4148 "Hide all the gruft in the current article.
4149 This means that PGP stuff, signatures, cited text and (some)
4150 headers will be hidden.
4151 If given a prefix, show the hidden text instead."
4152 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4153 (gnus-article-hide-headers arg)
4154 (gnus-article-hide-list-identifiers arg)
4155 (gnus-article-hide-pgp arg)
4156 (gnus-article-hide-citation-maybe arg force)
4157 (gnus-article-hide-signature arg))
4159 (defun gnus-article-maybe-highlight ()
4160 "Do some article highlighting if article highlighting is requested."
4161 (when (gnus-visual-p 'article-highlight 'highlight)
4162 (gnus-article-highlight-some)))
4164 (defun gnus-check-group-server ()
4165 ;; Make sure the connection to the server is alive.
4166 (unless (gnus-server-opened
4167 (gnus-find-method-for-group gnus-newsgroup-name))
4168 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4169 (gnus-request-group gnus-newsgroup-name t)))
4171 (defun gnus-request-article-this-buffer (article group)
4172 "Get an article and insert it into this buffer."
4173 (let (do-update-line sparse-header)
4177 (gnus-kill-all-overlays)
4178 (setq group (or group gnus-newsgroup-name))
4180 ;; Using `gnus-request-article' directly will insert the article into
4181 ;; `nntp-server-buffer' - so we'll save some time by not having to
4182 ;; copy it from the server buffer into the article buffer.
4184 ;; We only request an article by message-id when we do not have the
4185 ;; headers for it, so we'll have to get those.
4186 (when (stringp article)
4187 (gnus-read-header article))
4189 ;; If the article number is negative, that means that this article
4190 ;; doesn't belong in this newsgroup (possibly), so we find its
4191 ;; message-id and request it by id instead of number.
4192 (when (and (numberp article)
4194 (get-buffer gnus-summary-buffer)
4195 (gnus-buffer-exists-p gnus-summary-buffer))
4197 (set-buffer gnus-summary-buffer)
4198 (let ((header (gnus-summary-article-header article)))
4201 ((memq article gnus-newsgroup-sparse)
4202 ;; This is a sparse gap article.
4203 (setq do-update-line article)
4204 (setq article (mail-header-id header))
4205 (setq sparse-header (gnus-read-header article))
4206 (setq gnus-newsgroup-sparse
4207 (delq article gnus-newsgroup-sparse)))
4209 ;; It's a real article.
4210 (setq article (mail-header-id header)))
4212 ;; It is an extracted pseudo-article.
4213 (setq article 'pseudo)
4214 (gnus-request-pseudo-article header))))
4216 (let ((method (gnus-find-method-for-group
4217 gnus-newsgroup-name)))
4218 (when (and (eq (car method) 'nneething)
4220 (let ((dir (expand-file-name
4221 (mail-header-subject header)
4222 (file-name-as-directory
4223 (or (cadr (assq 'nneething-address method))
4225 (when (file-directory-p dir)
4226 (setq article 'nneething)
4227 (gnus-group-enter-directory dir))))))))
4230 ;; Refuse to select canceled articles.
4231 ((and (numberp article)
4233 (get-buffer gnus-summary-buffer)
4234 (gnus-buffer-exists-p gnus-summary-buffer)
4235 (eq (cdr (save-excursion
4236 (set-buffer gnus-summary-buffer)
4237 (assq article gnus-newsgroup-reads)))
4238 gnus-canceled-mark))
4240 ;; Check the backlog.
4241 ((and gnus-keep-backlog
4242 (gnus-backlog-request-article group article (current-buffer)))
4244 ;; Check asynchronous pre-fetch.
4245 ((gnus-async-request-fetched-article group article (current-buffer))
4246 (gnus-async-prefetch-next group article gnus-summary-buffer)
4247 (when (and (numberp article) gnus-keep-backlog)
4248 (gnus-backlog-enter-article group article (current-buffer)))
4251 ((and gnus-use-cache
4253 (gnus-cache-request-article article group))
4255 ;; Get the article and put into the article buffer.
4256 ((or (stringp article)
4258 (let ((gnus-override-method gnus-override-method)
4259 (methods (and (stringp article)
4260 gnus-refer-article-method))
4262 (buffer-read-only nil))
4267 (when (and (null gnus-override-method)
4269 (setq gnus-override-method (pop methods)))
4271 (when (eq gnus-override-method 'current)
4272 (setq gnus-override-method gnus-current-select-method))
4274 (gnus-kill-all-overlays)
4275 (let ((gnus-newsgroup-name group))
4276 (gnus-check-group-server))
4277 (when (gnus-request-article article group (current-buffer))
4278 (when (numberp article)
4279 (gnus-async-prefetch-next group article
4280 gnus-summary-buffer)
4281 (when gnus-keep-backlog
4282 (gnus-backlog-enter-article
4283 group article (current-buffer))))
4284 (setq result 'article))
4287 (setq gnus-override-method (pop methods))
4288 (setq result 'done))))
4289 (and (eq result 'article) 'article)))
4293 ;; Associate this article with the current summary buffer.
4294 (setq gnus-article-current-summary gnus-summary-buffer)
4296 ;; Take the article from the original article buffer
4297 ;; and place it in the buffer it's supposed to be in.
4298 (when (and (get-buffer gnus-article-buffer)
4299 (equal (buffer-name (current-buffer))
4300 (buffer-name (get-buffer gnus-article-buffer))))
4302 (if (get-buffer gnus-original-article-buffer)
4303 (set-buffer gnus-original-article-buffer)
4304 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4305 (set-buffer-multibyte nil)
4306 (buffer-disable-undo)
4307 (setq major-mode 'gnus-original-article-mode)
4308 (setq buffer-read-only t))
4309 (let (buffer-read-only)
4311 (insert-buffer-substring gnus-article-buffer))
4312 (setq gnus-original-article (cons group article)))
4315 (run-hooks 'gnus-article-decode-hook)
4316 ;; Mark article as decoded or not.
4317 (setq gnus-article-decoded-p gnus-article-decode-hook))
4319 ;; Update sparse articles.
4320 (when (and do-update-line
4321 (or (numberp article)
4323 (let ((buf (current-buffer)))
4324 (set-buffer gnus-summary-buffer)
4325 (gnus-summary-update-article do-update-line sparse-header)
4326 (gnus-summary-goto-subject do-update-line nil t)
4327 (set-window-point (get-buffer-window (current-buffer) t)
4329 (set-buffer buf))))))
4335 (defcustom gnus-article-edit-mode-hook nil
4336 "Hook run in article edit mode buffers."
4337 :group 'gnus-article-various
4340 (defcustom gnus-article-edit-article-setup-function
4341 'gnus-article-mime-edit-article-setup
4342 "Function called to setup an editing article buffer."
4343 :group 'gnus-article-various
4346 (defvar gnus-article-edit-done-function nil)
4348 (defvar gnus-article-edit-mode-map nil)
4350 ;; Should we be using derived.el for this?
4351 (unless gnus-article-edit-mode-map
4352 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4353 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4355 (gnus-define-keys gnus-article-edit-mode-map
4356 "\C-c\C-c" gnus-article-edit-done
4357 "\C-c\C-k" gnus-article-edit-exit)
4359 (gnus-define-keys (gnus-article-edit-wash-map
4360 "\C-c\C-w" gnus-article-edit-mode-map)
4361 "f" gnus-article-edit-full-stops))
4363 (defun gnus-article-edit-mode ()
4364 "Major mode for editing articles.
4365 This is an extended text-mode.
4367 \\{gnus-article-edit-mode-map}"
4369 (setq major-mode 'gnus-article-edit-mode)
4370 (setq mode-name "Article Edit")
4371 (use-local-map gnus-article-edit-mode-map)
4372 (make-local-variable 'gnus-article-edit-done-function)
4373 (make-local-variable 'gnus-prev-winconf)
4374 (setq buffer-read-only nil)
4375 (buffer-enable-undo)
4377 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4379 (defun gnus-article-edit (&optional force)
4380 "Edit the current article.
4381 This will have permanent effect only in mail groups.
4382 If FORCE is non-nil, allow editing of articles even in read-only
4385 (when (and (not force)
4386 (gnus-group-read-only-p))
4387 (error "The current newsgroup does not support article editing"))
4388 (gnus-article-date-original)
4389 (gnus-article-edit-article
4391 `(lambda (no-highlight)
4393 (gnus-summary-edit-article-done
4394 ,(or (mail-header-references gnus-current-headers) "")
4395 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4397 (defun gnus-article-edit-article (start-func exit-func)
4398 "Start editing the contents of the current article buffer."
4399 (let ((winconf (current-window-configuration)))
4400 (set-buffer gnus-article-buffer)
4401 (gnus-article-edit-mode)
4402 (funcall start-func)
4403 (gnus-configure-windows 'edit-article)
4404 (setq gnus-article-edit-done-function exit-func)
4405 (setq gnus-prev-winconf winconf)
4406 (when gnus-article-edit-article-setup-function
4407 (funcall gnus-article-edit-article-setup-function))
4408 (gnus-message 6 "C-c C-c to end edits")))
4410 (defun gnus-article-edit-done (&optional arg)
4411 "Update the article edits and exit."
4416 (when (article-goto-body)
4417 (let ((lines (count-lines (point) (point-max)))
4418 (length (- (point-max) (point)))
4419 (case-fold-search t)
4420 (body (copy-marker (point))))
4421 (goto-char (point-min))
4422 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4423 (delete-region (match-beginning 1) (match-end 1))
4424 (insert (number-to-string length)))
4425 (goto-char (point-min))
4426 (when (re-search-forward
4427 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4428 (delete-region (match-beginning 1) (match-end 1))
4429 (insert (number-to-string length)))
4430 (goto-char (point-min))
4431 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4432 (delete-region (match-beginning 1) (match-end 1))
4433 (insert (number-to-string lines)))))))
4434 (let ((func gnus-article-edit-done-function)
4435 (buf (current-buffer))
4436 (start (window-start)))
4437 (remove-hook 'gnus-article-mode-hook
4438 'gnus-article-mime-edit-article-unwind)
4439 (gnus-article-edit-exit)
4442 (let ((buffer-read-only nil))
4444 ;; The cache and backlog have to be flushed somewhat.
4445 (when gnus-keep-backlog
4446 (gnus-backlog-remove-article
4447 (car gnus-article-current) (cdr gnus-article-current)))
4448 ;; Flush original article as well.
4450 (when (get-buffer gnus-original-article-buffer)
4451 (set-buffer gnus-original-article-buffer)
4452 (setq gnus-original-article nil)))
4453 (when gnus-use-cache
4454 (gnus-cache-update-article
4455 (car gnus-article-current) (cdr gnus-article-current))))
4457 (set-window-start (get-buffer-window buf) start)
4458 (set-window-point (get-buffer-window buf) (point))))
4460 (defun gnus-article-edit-exit ()
4461 "Exit the article editing without updating."
4463 ;; We remove all text props from the article buffer.
4464 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4465 (curbuf (current-buffer))
4467 (window-start (window-start)))
4470 (let ((winconf gnus-prev-winconf))
4472 (set-window-configuration winconf)
4473 ;; Tippy-toe some to make sure that point remains where it was.
4474 (save-current-buffer
4476 (set-window-start (get-buffer-window (current-buffer)) window-start)
4479 (defun gnus-article-edit-full-stops ()
4480 "Interactively repair spacing at end of sentences."
4483 (goto-char (point-min))
4484 (search-forward-regexp "^$" nil t)
4485 (let ((case-fold-search nil))
4486 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4489 ;;; Article editing with MIME-Edit
4492 (defcustom gnus-article-mime-edit-article-setup-hook nil
4493 "Hook run after setting up a MIME editing article buffer."
4494 :group 'gnus-article-various
4497 (defun gnus-article-mime-edit-article-unwind ()
4498 "Unwind `gnus-article-buffer' if article editing was given up."
4499 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4500 (when mime-edit-mode-flag
4501 (mime-edit-exit 'nomime 'no-error)
4503 (when (featurep 'font-lock)
4504 (setq font-lock-defaults nil)
4505 (font-lock-mode 0)))
4507 (defun gnus-article-mime-edit-article-setup ()
4508 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4509 after replacing with the original article."
4510 (setq gnus-show-mime t)
4511 (setq gnus-article-edit-done-function
4512 `(lambda (&rest args)
4513 (when mime-edit-mode-flag
4516 (goto-char (point-min))
4517 (let (case-fold-search)
4518 (when (re-search-forward
4519 (format "^%s$" (regexp-quote mail-header-separator))
4521 (replace-match "")))
4522 (when (featurep 'font-lock)
4523 (setq font-lock-defaults nil)
4525 (apply ,gnus-article-edit-done-function args)
4526 (set-buffer gnus-original-article-buffer)
4528 (insert-buffer gnus-article-buffer)
4529 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4530 (gnus-article-prepare-display)))
4531 (substitute-key-definition
4532 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4533 gnus-article-edit-mode-map)
4535 (insert-buffer gnus-original-article-buffer)
4537 (when (featurep 'font-lock)
4538 (set (make-local-variable 'font-lock-defaults)
4539 '(message-font-lock-keywords t))
4540 (font-lock-set-defaults)
4541 (turn-on-font-lock))
4542 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4543 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4545 (defun gnus-article-mime-edit-exit ()
4546 "Exit the article MIME editing without updating."
4548 (let ((winconf gnus-prev-winconf)
4550 (when mime-edit-mode-flag
4553 (goto-char (point-min))
4554 (let (case-fold-search)
4555 (when (re-search-forward
4556 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4557 (replace-match "")))
4558 (when (featurep 'font-lock)
4559 (setq font-lock-defaults nil)
4561 ;; We remove all text props from the article buffer.
4562 (setq buf (format "%s" (buffer-string)))
4563 (set-buffer (get-buffer-create gnus-original-article-buffer))
4566 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4567 (gnus-article-prepare-display)
4568 (set-window-configuration winconf)))
4571 ;;; Article highlights
4574 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4576 ;;; Internal Variables:
4578 (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\\)\\)"
4579 "Regular expression that matches URLs."
4580 :group 'gnus-article-buttons
4583 (defcustom gnus-button-alist
4584 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4585 0 t gnus-button-message-id 2)
4586 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4587 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4589 gnus-button-fetch-group 4)
4590 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4591 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4592 t gnus-button-message-id 3)
4593 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4594 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4595 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4596 ;; This is how URLs _should_ be embedded in text...
4597 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4599 (,gnus-button-url-regexp 0 t browse-url 0))
4600 "*Alist of regexps matching buttons in article bodies.
4602 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4603 REGEXP: is the string matching text around the button,
4604 BUTTON: is the number of the regexp grouping actually matching the button,
4605 FORM: is a lisp expression which must eval to true for the button to
4607 CALLBACK: is the function to call when the user push this button, and each
4608 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4610 CALLBACK can also be a variable, in that case the value of that
4611 variable it the real callback function."
4612 :group 'gnus-article-buttons
4613 :type '(repeat (list regexp
4614 (integer :tag "Button")
4616 (function :tag "Callback")
4619 (integer :tag "Regexp group")))))
4621 (defcustom gnus-header-button-alist
4622 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4623 0 t gnus-button-message-id 0)
4624 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4625 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4626 0 t gnus-button-mailto 0)
4627 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4628 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4629 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4630 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4631 gnus-button-message-id 3))
4632 "*Alist of headers and regexps to match buttons in article heads.
4634 This alist is very similar to `gnus-button-alist', except that each
4635 alist has an additional HEADER element first in each entry:
4637 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4639 HEADER is a regexp to match a header. For a fuller explanation, see
4640 `gnus-button-alist'."
4641 :group 'gnus-article-buttons
4642 :group 'gnus-article-headers
4643 :type '(repeat (list (regexp :tag "Header")
4645 (integer :tag "Button")
4647 (function :tag "Callback")
4650 (integer :tag "Regexp group")))))
4652 (defvar gnus-button-regexp nil)
4653 (defvar gnus-button-marker-list nil)
4654 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4656 (defvar gnus-button-last nil)
4657 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4661 (defun gnus-article-push-button (event)
4662 "Check text under the mouse pointer for a callback function.
4663 If the text under the mouse pointer has a `gnus-callback' property,
4664 call it with the value of the `gnus-data' text property."
4666 (set-buffer (window-buffer (posn-window (event-start event))))
4667 (let* ((pos (posn-point (event-start event)))
4668 (data (get-text-property pos 'gnus-data))
4669 (fun (get-text-property pos 'gnus-callback)))
4672 (funcall fun data))))
4674 (defun gnus-article-press-button ()
4675 "Check text at point for a callback function.
4676 If the text at point has a `gnus-callback' property,
4677 call it with the value of the `gnus-data' text property."
4679 (let* ((data (get-text-property (point) 'gnus-data))
4680 (fun (get-text-property (point) 'gnus-callback)))
4682 (funcall fun data))))
4684 (defun gnus-article-prev-button (n)
4685 "Move point to N buttons backward.
4686 If N is negative, move forward instead."
4688 (gnus-article-next-button (- n)))
4690 (defun gnus-article-next-button (n)
4691 "Move point to N buttons forward.
4692 If N is negative, move backward instead."
4694 (let ((function (if (< n 0) 'previous-single-property-change
4695 'next-single-property-change))
4696 (inhibit-point-motion-hooks t)
4698 (limit (if (< n 0) (point-min) (point-max))))
4700 (while (and (not (= limit (point)))
4702 ;; Skip past the current button.
4703 (when (get-text-property (point) 'gnus-callback)
4704 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4705 ;; Go to the next (or previous) button.
4706 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4707 ;; Put point at the start of the button.
4708 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4709 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4710 ;; Skip past intangible buttons.
4711 (when (get-text-property (point) 'intangible)
4715 (gnus-message 5 "No more buttons"))
4718 (defun gnus-article-highlight (&optional force)
4719 "Highlight current article.
4720 This function calls `gnus-article-highlight-headers',
4721 `gnus-article-highlight-citation',
4722 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4723 do the highlighting. See the documentation for those functions."
4724 (interactive (list 'force))
4725 (gnus-article-highlight-headers)
4726 (gnus-article-highlight-citation force)
4727 (gnus-article-highlight-signature)
4728 (gnus-article-add-buttons force)
4729 (gnus-article-add-buttons-to-head))
4731 (defun gnus-article-highlight-some (&optional force)
4732 "Highlight current article.
4733 This function calls `gnus-article-highlight-headers',
4734 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4735 do the highlighting. See the documentation for those functions."
4736 (interactive (list 'force))
4737 (gnus-article-highlight-headers)
4738 (gnus-article-highlight-signature)
4739 (gnus-article-add-buttons))
4741 (defun gnus-article-highlight-headers ()
4742 "Highlight article headers as specified by `gnus-header-face-alist'."
4745 (set-buffer gnus-article-buffer)
4747 (let ((alist gnus-header-face-alist)
4748 (buffer-read-only nil)
4749 (case-fold-search t)
4750 (inhibit-point-motion-hooks t)
4751 entry regexp header-face field-face from hpoints fpoints)
4752 (article-narrow-to-head)
4753 (while (setq entry (pop alist))
4754 (goto-char (point-min))
4755 (setq regexp (concat "^\\("
4756 (if (string-equal "" (nth 0 entry))
4760 header-face (nth 1 entry)
4761 field-face (nth 2 entry))
4762 (while (and (re-search-forward regexp nil t)
4766 (unless (search-forward ":" nil t)
4768 (when (and header-face
4769 (not (memq (point) hpoints)))
4770 (push (point) hpoints)
4771 (gnus-put-text-property from (point) 'face header-face))
4772 (when (and field-face
4773 (not (memq (setq from (point)) fpoints)))
4775 (if (re-search-forward "^[^ \t]" nil t)
4777 (goto-char (point-max)))
4778 (gnus-put-text-property from (point) 'face field-face))))))))
4780 (defun gnus-article-highlight-signature ()
4781 "Highlight the signature in an article.
4782 It does this by highlighting everything after
4783 `gnus-signature-separator' using `gnus-signature-face'."
4785 (when gnus-signature-face
4787 (set-buffer gnus-article-buffer)
4788 (let ((buffer-read-only nil)
4789 (inhibit-point-motion-hooks t))
4791 (when (gnus-article-narrow-to-signature)
4792 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4793 'face gnus-signature-face)))))))
4795 (defun gnus-article-buttonize-signature ()
4796 "Add button to the signature."
4799 (set-buffer gnus-article-buffer)
4800 (let ((buffer-read-only nil)
4801 (inhibit-point-motion-hooks t))
4802 (when (gnus-article-search-signature)
4803 (gnus-article-add-button (match-beginning 0) (match-end 0)
4804 'gnus-signature-toggle
4805 (set-marker (make-marker)
4806 (1+ (match-end 0))))))))
4808 (defun gnus-button-in-region-p (b e prop)
4809 "Say whether PROP exists in the region."
4810 (text-property-not-all b e prop nil))
4812 (defun gnus-article-add-buttons (&optional force)
4813 "Find external references in the article and make buttons of them.
4814 \"External references\" are things like Message-IDs and URLs, as
4815 specified by `gnus-button-alist'."
4816 (interactive (list 'force))
4818 (set-buffer gnus-article-buffer)
4819 (let ((buffer-read-only nil)
4820 (inhibit-point-motion-hooks t)
4821 (case-fold-search t)
4822 (alist gnus-button-alist)
4824 ;; Remove all old markers.
4825 (let (marker entry new-list)
4826 (while (setq marker (pop gnus-button-marker-list))
4827 (if (or (< marker (point-min)) (>= marker (point-max)))
4828 (push marker new-list)
4830 (when (setq entry (gnus-button-entry))
4831 (put-text-property (match-beginning (nth 1 entry))
4832 (match-end (nth 1 entry))
4833 'gnus-callback nil))
4834 (set-marker marker nil)))
4835 (setq gnus-button-marker-list new-list))
4836 ;; We skip the headers.
4839 (while (setq entry (pop alist))
4840 (setq regexp (car entry))
4842 (while (re-search-forward regexp nil t)
4843 (let* ((start (and entry (match-beginning (nth 1 entry))))
4844 (end (and entry (match-end (nth 1 entry))))
4845 (from (match-beginning 0)))
4846 (when (and (or (eq t (nth 2 entry))
4847 (eval (nth 2 entry)))
4848 (not (gnus-button-in-region-p
4849 start end 'gnus-callback)))
4850 ;; That optional form returned non-nil, so we add the
4852 (gnus-article-add-button
4853 start end 'gnus-button-push
4854 (car (push (set-marker (make-marker) from)
4855 gnus-button-marker-list))))))))))
4857 ;; Add buttons to the head of an article.
4858 (defun gnus-article-add-buttons-to-head ()
4859 "Add buttons to the head of the article."
4862 (set-buffer gnus-article-buffer)
4864 (let ((buffer-read-only nil)
4865 (inhibit-point-motion-hooks t)
4866 (case-fold-search t)
4867 (alist gnus-header-button-alist)
4869 (article-narrow-to-head)
4871 ;; Each alist entry.
4872 (setq entry (car alist)
4874 (goto-char (point-min))
4875 (while (re-search-forward (car entry) nil t)
4876 ;; Each header matching the entry.
4877 (setq beg (match-beginning 0))
4878 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4879 (match-beginning 0))
4882 (while (re-search-forward (nth 1 entry) end t)
4883 ;; Each match within a header.
4884 (let* ((entry (cdr entry))
4885 (start (match-beginning (nth 1 entry)))
4886 (end (match-end (nth 1 entry)))
4887 (form (nth 2 entry)))
4888 (goto-char (match-end 0))
4890 (gnus-article-add-button
4891 start end (nth 3 entry)
4892 (buffer-substring (match-beginning (nth 4 entry))
4893 (match-end (nth 4 entry)))))))
4894 (goto-char end)))))))
4896 ;;; External functions:
4898 (defun gnus-article-add-button (from to fun &optional data)
4899 "Create a button between FROM and TO with callback FUN and data DATA."
4900 (when gnus-article-button-face
4901 (gnus-overlay-put (gnus-make-overlay from to)
4902 'face gnus-article-button-face))
4903 (gnus-add-text-properties
4905 (nconc (and gnus-article-mouse-face
4906 (list gnus-mouse-face-prop gnus-article-mouse-face))
4907 (list 'gnus-callback fun)
4908 (and data (list 'gnus-data data))))
4909 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4910 ;; Quote `:button-keymap' for Mule 2.3
4911 ;; but it won't work.
4912 ':button-keymap gnus-widget-button-keymap))
4914 ;;; Internal functions:
4916 (defun gnus-article-set-globals ()
4918 (set-buffer gnus-summary-buffer)
4919 (gnus-set-global-variables)))
4921 (defun gnus-signature-toggle (end)
4923 (set-buffer gnus-article-buffer)
4924 (let ((buffer-read-only nil)
4925 (inhibit-point-motion-hooks t)
4926 (limit (next-single-property-change end 'mime-view-entity
4928 (if (get-text-property end 'invisible)
4929 (gnus-article-unhide-text end limit)
4930 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4932 (defun gnus-button-entry ()
4933 ;; Return the first entry in `gnus-button-alist' matching this place.
4934 (let ((alist gnus-button-alist)
4937 (setq entry (pop alist))
4938 (if (looking-at (car entry))
4943 (defun gnus-button-push (marker)
4944 ;; Push button starting at MARKER.
4947 (let* ((entry (gnus-button-entry))
4948 (inhibit-point-motion-hooks t)
4950 (args (mapcar (lambda (group)
4951 (let ((string (match-string group)))
4952 (gnus-set-text-properties
4953 0 (length string) nil string)
4960 (fboundp (symbol-value fun)))
4961 (apply (symbol-value fun) args))
4963 (gnus-message 1 "You must define `%S' to use this button"
4964 (cons fun args)))))))
4966 (defun gnus-button-message-id (message-id)
4969 (set-buffer gnus-summary-buffer)
4970 (gnus-summary-refer-article message-id)))
4972 (defun gnus-button-fetch-group (address)
4973 "Fetch GROUP specified by ADDRESS."
4974 (if (not (string-match "[:/]" address))
4975 ;; This is just a simple group url.
4976 (gnus-group-read-ephemeral-group address gnus-select-method)
4977 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4979 (error "Can't parse %s" address)
4980 (gnus-group-read-ephemeral-group
4981 (match-string 4 address)
4982 `(nntp ,(match-string 1 address)
4983 (nntp-address ,(match-string 1 address))
4984 (nntp-port-number ,(if (match-end 3)
4985 (match-string 3 address)
4988 (defun gnus-url-parse-query-string (query &optional downcase)
4989 (let (retval pairs cur key val)
4990 (setq pairs (split-string query "&"))
4992 (setq cur (car pairs)
4994 (if (not (string-match "=" cur))
4996 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4997 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4999 (setq key (downcase key)))
5000 (setq cur (assoc key retval))
5002 (setcdr cur (cons val (cdr cur)))
5003 (setq retval (cons (list key val) retval)))))
5006 (defun gnus-url-unhex (x)
5013 (defun gnus-url-unhex-string (str &optional allow-newlines)
5014 "Remove %XXX embedded spaces, etc in a url.
5015 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5016 decoding of carriage returns and line feeds in the string, which is normally
5017 forbidden in URL encoding."
5018 (setq str (or str ""))
5020 (case-fold-search t))
5021 (while (string-match "%[0-9a-f][0-9a-f]" str)
5022 (let* ((start (match-beginning 0))
5023 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5025 (gnus-url-unhex (elt str (+ start 2))))))
5027 tmp (substring str 0 start)
5030 (char-to-string code))
5031 ((or (= code ?\n) (= code ?\r))
5033 (t (char-to-string code))))
5034 str (substring str (match-end 0)))))
5035 (setq tmp (concat tmp str))
5038 (defun gnus-url-mailto (url)
5039 ;; Send mail to someone
5040 (when (string-match "mailto:/*\\(.*\\)" url)
5041 (setq url (substring url (match-beginning 1) nil)))
5042 (let (to args subject func)
5043 (if (string-match (regexp-quote "?") url)
5044 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5045 args (gnus-url-parse-query-string
5046 (substring url (match-end 0) nil) t))
5047 (setq to (gnus-url-unhex-string url)))
5048 (setq args (cons (list "to" to) args)
5049 subject (cdr-safe (assoc "subject" args)))
5050 (gnus-setup-message 'reply
5053 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5056 (message-position-on-field (caar args)))
5057 (insert (mapconcat 'identity (cdar args) ", "))
5058 (setq args (cdr args)))
5061 (message-goto-subject)))))
5063 (defun gnus-button-mailto (address)
5065 (set-buffer (gnus-copy-article-buffer))
5066 (gnus-setup-message 'reply
5067 (message-reply address)))
5069 (defun gnus-button-reply (address)
5070 ;; Reply to ADDRESS.
5071 (gnus-setup-message 'reply
5072 (message-reply address)))
5074 (defun gnus-button-embedded-url (address)
5076 (browse-url (gnus-strip-whitespace address)))
5078 (defun gnus-article-smiley-display ()
5079 "Display \"smileys\" as small graphical icons."
5080 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5082 ;;; Next/prev buttons in the article buffer.
5084 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5085 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5087 (defvar gnus-prev-page-map nil)
5088 (unless gnus-prev-page-map
5089 (setq gnus-prev-page-map (make-sparse-keymap))
5090 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5091 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5093 (static-if (featurep 'xemacs)
5094 (defun gnus-insert-prev-page-button ()
5095 (let ((buffer-read-only nil))
5097 gnus-prev-page-line-format nil
5098 `(gnus-prev t local-map ,gnus-prev-page-map
5099 gnus-callback gnus-article-button-prev-page
5100 article-type annotation))))
5101 (defun gnus-insert-prev-page-button ()
5102 (let ((buffer-read-only nil)
5103 (situation (get-text-property (point-min) 'mime-view-situation)))
5104 (set-keymap-parent gnus-prev-page-map (current-local-map))
5106 gnus-prev-page-line-format nil
5107 `(gnus-prev t local-map ,gnus-prev-page-map
5108 gnus-callback gnus-article-button-prev-page
5109 article-type annotation
5110 mime-view-situation ,situation))))
5113 (defvar gnus-next-page-map nil)
5114 (unless gnus-next-page-map
5115 (setq gnus-next-page-map (make-sparse-keymap))
5116 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5117 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5119 (defun gnus-button-next-page ()
5120 "Go to the next page."
5122 (let ((win (selected-window)))
5123 (select-window (get-buffer-window gnus-article-buffer t))
5124 (gnus-article-next-page)
5125 (select-window win)))
5127 (defun gnus-button-prev-page ()
5128 "Go to the prev page."
5130 (let ((win (selected-window)))
5131 (select-window (get-buffer-window gnus-article-buffer t))
5132 (gnus-article-prev-page)
5133 (select-window win)))
5135 (static-if (featurep 'xemacs)
5136 (defun gnus-insert-next-page-button ()
5137 (let ((buffer-read-only nil))
5138 (gnus-eval-format gnus-next-page-line-format nil
5140 t local-map ,gnus-next-page-map
5141 gnus-callback gnus-article-button-next-page
5142 article-type annotation))))
5143 (defun gnus-insert-next-page-button ()
5144 (let ((buffer-read-only nil)
5145 (situation (get-text-property (point-min) 'mime-view-situation)))
5146 (set-keymap-parent gnus-next-page-map (current-local-map))
5147 (gnus-eval-format gnus-next-page-line-format nil
5149 t local-map ,gnus-next-page-map
5150 gnus-callback gnus-article-button-next-page
5151 article-type annotation
5152 mime-view-situation ,situation))))
5155 (defun gnus-article-button-next-page (arg)
5156 "Go to the next page."
5158 (let ((win (selected-window)))
5159 (select-window (get-buffer-window gnus-article-buffer t))
5160 (gnus-article-next-page)
5161 (select-window win)))
5163 (defun gnus-article-button-prev-page (arg)
5164 "Go to the prev page."
5166 (let ((win (selected-window)))
5167 (select-window (get-buffer-window gnus-article-buffer t))
5168 (gnus-article-prev-page)
5169 (select-window win)))
5171 (defvar gnus-decode-header-methods
5172 '(mail-decode-encoded-word-region)
5173 "List of methods used to decode headers.
5175 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5176 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5177 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5178 whose names match REGEXP.
5181 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5182 mail-decode-encoded-word-region
5183 (\"chinese\" . rfc1843-decode-region))
5186 (defvar gnus-decode-header-methods-cache nil)
5188 (defun gnus-multi-decode-header (start end)
5189 "Apply the functions from `gnus-encoded-word-methods' that match."
5190 (unless (and gnus-decode-header-methods-cache
5191 (eq gnus-newsgroup-name
5192 (car gnus-decode-header-methods-cache)))
5193 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5196 (nconc gnus-decode-header-methods-cache (list x))
5197 (if (and gnus-newsgroup-name
5198 (string-match (car x) gnus-newsgroup-name))
5199 (nconc gnus-decode-header-methods-cache
5201 gnus-decode-header-methods))
5202 (let ((xlist gnus-decode-header-methods-cache))
5205 (narrow-to-region start end)
5207 (funcall (pop xlist) (point-min) (point-max))))))
5210 ;;; Treatment top-level handling.
5213 (defun gnus-treat-article (condition &optional part-number total-parts type)
5214 (let ((length (- (point-max) (point-min)))
5215 (alist gnus-treatment-function-alist)
5216 (article-goto-body-goes-to-point-min-p t)
5220 (let ((list gnus-article-treat-types))
5222 (when (string-match (pop list) type)
5223 (throw 'found t)))))))
5224 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5225 (entity (static-unless (featurep 'xemacs)
5226 (when (eq 'head condition)
5227 (get-text-property (point-min) 'mime-view-entity))))
5228 val elem buttonized)
5229 (gnus-run-hooks 'gnus-part-display-hook)
5230 (unless gnus-inhibit-treatment
5231 (while (setq elem (pop alist))
5234 (if (gnus-buffer-live-p gnus-summary-buffer)
5235 (set-buffer gnus-summary-buffer))
5236 (symbol-value (car elem))))
5237 (when (and (or (consp val)
5239 (gnus-treat-predicate val)
5240 (or (not (get (car elem) 'highlight))
5242 (when (and (not buttonized)
5244 '(gnus-treat-hide-signature
5245 gnus-treat-highlight-signature)))
5246 (gnus-article-buttonize-signature)
5247 (setq buttonized t))
5249 (funcall (cadr elem)))))
5250 ;; FSF Emacsen does not inherit the existing text properties
5251 ;; in the new text, so we should do it for `mime-view-entity'.
5252 (static-unless (featurep 'xemacs)
5254 (put-text-property (point-min) (point-max)
5255 'mime-view-entity entity))))))
5257 ;; Dynamic variables.
5258 (defvar part-number)
5259 (defvar total-parts)
5263 (defun gnus-treat-predicate (val)
5268 (stringp (car val)))
5269 (apply 'gnus-or (mapcar `(lambda (s)
5270 (string-match s ,(or gnus-newsgroup-name "")))
5273 (let ((pred (pop val)))
5276 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5278 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5280 (not (gnus-treat-predicate (car val))))
5282 (equal (car val) type))
5284 (error "%S is not a valid predicate" pred)))))
5294 (eq part-number total-parts))
5298 (error "%S is not a valid value" val))))
5304 (defun gnus-article-header-presentation-method (entity situation)
5305 (mime-insert-header entity)
5308 (set-alist 'mime-header-presentation-method-alist
5309 'gnus-original-article-mode
5310 #'gnus-article-header-presentation-method)
5312 (defun gnus-mime-preview-quitting-method ()
5313 (mime-preview-kill-buffer)
5314 (delete-other-windows)
5315 (gnus-article-show-summary)
5316 (gnus-summary-select-article gnus-show-all-headers t))
5318 (set-alist 'mime-preview-quitting-method-alist
5319 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5321 (set-alist 'mime-preview-following-method-alist
5322 'gnus-original-article-mode #'gnus-following-method)
5324 (set-alist 'mime-preview-over-to-previous-method-alist
5325 'gnus-original-article-mode
5327 (if (> (point-min) 1)
5328 (gnus-article-prev-page)
5329 (gnus-article-read-summary-keys
5330 nil (gnus-character-to-event ?P)))))
5332 (set-alist 'mime-preview-over-to-next-method-alist
5333 'gnus-original-article-mode'
5335 (if (< (point-max) (buffer-size))
5336 (gnus-article-next-page)
5337 (gnus-article-read-summary-keys
5338 nil (gnus-character-to-event ?N)))))
5348 (run-hooks 'gnus-art-load-hook)
5350 ;;; gnus-art.el ends here