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 (featurep 'xemacs))
221 (module-installed-p 'x-face-mule))
222 'x-face-mule-gnus-article-display-x-face)
223 (gnus-article-compface-xbm
224 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -")
226 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
228 "*String or function to be executed to display an X-Face header.
229 If it is a string, the command will be executed in a sub-shell
230 asynchronously. The compressed face will be piped to this command."
231 :type '(choice string
232 (function-item gnus-article-display-xface)
233 (function-item x-face-mule-gnus-article-display-x-face)
235 :group 'gnus-article-washing)
237 (defcustom gnus-article-x-face-too-ugly nil
238 "Regexp matching posters whose face shouldn't be shown automatically."
239 :type '(choice regexp (const nil))
240 :group 'gnus-article-washing)
242 (defcustom gnus-article-banner-alist nil
243 "Banner alist for stripping.
245 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
246 :type '(repeat (cons symbol regexp))
247 :group 'gnus-article-washing)
249 (defcustom gnus-emphasis-alist
251 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
253 '(("_" "_" underline)
256 ("_/" "/_" underline-italic)
257 ("_\\*" "\\*_" underline-bold)
258 ("\\*/" "/\\*" bold-italic)
259 ("_\\*/" "/\\*_" underline-bold-italic))))
260 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
261 2 3 gnus-emphasis-underline)
265 (format format (car spec) (car (cdr spec)))
266 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
268 "*Alist that says how to fontify certain phrases.
269 Each item looks like this:
271 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
273 The first element is a regular expression to be matched. The second
274 is a number that says what regular expression grouping used to find
275 the entire emphasized word. The third is a number that says what
276 regexp grouping should be displayed and highlighted. The fourth
277 is the face used for highlighting."
278 :type '(repeat (list :value ("" 0 0 default)
280 (integer :tag "Match group")
281 (integer :tag "Emphasize group")
283 :group 'gnus-article-emphasis)
285 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
286 "A regexp to describe whitespace which should not be emphasized.
287 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
288 The former avoids underlining of leading and trailing whitespace,
289 and the latter avoids underlining any whitespace at all."
290 :group 'gnus-article-emphasis
293 (defface gnus-emphasis-bold '((t (:bold t)))
294 "Face used for displaying strong emphasized text (*word*)."
295 :group 'gnus-article-emphasis)
297 (defface gnus-emphasis-italic '((t (:italic t)))
298 "Face used for displaying italic emphasized text (/word/)."
299 :group 'gnus-article-emphasis)
301 (defface gnus-emphasis-underline '((t (:underline t)))
302 "Face used for displaying underlined emphasized text (_word_)."
303 :group 'gnus-article-emphasis)
305 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
306 "Face used for displaying underlined bold emphasized text (_*word*_)."
307 :group 'gnus-article-emphasis)
309 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
310 "Face used for displaying underlined italic emphasized text (_/word/_)."
311 :group 'gnus-article-emphasis)
313 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
314 "Face used for displaying bold italic emphasized text (/*word*/)."
315 :group 'gnus-article-emphasis)
317 (defface gnus-emphasis-underline-bold-italic
318 '((t (:bold t :italic t :underline t)))
319 "Face used for displaying underlined bold italic emphasized text.
320 Esample: (_/*word*/_)."
321 :group 'gnus-article-emphasis)
323 (defface gnus-emphasis-highlight-words
324 '((t (:background "black" :foreground "yellow")))
325 "Face used for displaying highlighted words."
326 :group 'gnus-article-emphasis)
328 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
329 "Format for display of Date headers in article bodies.
330 See `format-time-string' for the possible values.
332 The variable can also be function, which should return a complete Date
333 header. The function is called with one argument, the time, which can
334 be fed to `format-time-string'."
335 :type '(choice string symbol)
336 :link '(custom-manual "(gnus)Article Date")
337 :group 'gnus-article-washing)
340 (autoload 'mail-extract-address-components "mail-extr"))
342 (defcustom gnus-save-all-headers t
343 "*If non-nil, don't remove any headers before saving."
344 :group 'gnus-article-saving
347 (defcustom gnus-prompt-before-saving 'always
348 "*This variable says how much prompting is to be done when saving articles.
349 If it is nil, no prompting will be done, and the articles will be
350 saved to the default files. If this variable is `always', each and
351 every article that is saved will be preceded by a prompt, even when
352 saving large batches of articles. If this variable is neither nil not
353 `always', there the user will be prompted once for a file name for
354 each invocation of the saving commands."
355 :group 'gnus-article-saving
356 :type '(choice (item always)
357 (item :tag "never" nil)
358 (sexp :tag "once" :format "%t\n" :value t)))
360 (defcustom gnus-saved-headers gnus-visible-headers
361 "Headers to keep if `gnus-save-all-headers' is nil.
362 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
363 If that variable is nil, however, all headers that match this regexp
364 will be kept while the rest will be deleted before saving."
365 :group 'gnus-article-saving
368 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
369 "A function to save articles in your favourite format.
370 The function must be interactively callable (in other words, it must
371 be an Emacs command).
373 Gnus provides the following functions:
375 * gnus-summary-save-in-rmail (Rmail format)
376 * gnus-summary-save-in-mail (Unix mail format)
377 * gnus-summary-save-in-folder (MH folder)
378 * gnus-summary-save-in-file (article format)
379 * gnus-summary-save-in-vm (use VM's folder format)
380 * gnus-summary-write-to-file (article format -- overwrite)."
381 :group 'gnus-article-saving
382 :type '(radio (function-item gnus-summary-save-in-rmail)
383 (function-item gnus-summary-save-in-mail)
384 (function-item gnus-summary-save-in-folder)
385 (function-item gnus-summary-save-in-file)
386 (function-item gnus-summary-save-in-vm)
387 (function-item gnus-summary-write-to-file)))
389 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
390 "A function generating a file name to save articles in Rmail format.
391 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
392 :group 'gnus-article-saving
395 (defcustom gnus-mail-save-name 'gnus-plain-save-name
396 "A function generating a file name to save articles in Unix mail format.
397 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
398 :group 'gnus-article-saving
401 (defcustom gnus-folder-save-name 'gnus-folder-save-name
402 "A function generating a file name to save articles in MH folder.
403 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
404 :group 'gnus-article-saving
407 (defcustom gnus-file-save-name 'gnus-numeric-save-name
408 "A function generating a file name to save articles in article format.
409 The function is called with NEWSGROUP, HEADERS, and optional
411 :group 'gnus-article-saving
414 (defcustom gnus-split-methods
415 '((gnus-article-archive-name)
416 (gnus-article-nndoc-name))
417 "*Variable used to suggest where articles are to be saved.
418 For instance, if you would like to save articles related to Gnus in
419 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
420 you could set this variable to something like:
422 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
423 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
425 This variable is an alist where the where the key is the match and the
426 value is a list of possible files to save in if the match is non-nil.
428 If the match is a string, it is used as a regexp match on the
429 article. If the match is a symbol, that symbol will be funcalled
430 from the buffer of the article to be saved with the newsgroup as the
431 parameter. If it is a list, it will be evaled in the same buffer.
433 If this form or function returns a string, this string will be used as
434 a possible file name; and if it returns a non-nil list, that list will
435 be used as possible file names."
436 :group 'gnus-article-saving
437 :type '(repeat (choice (list :value (fun) function)
438 (cons :value ("" "") regexp (repeat string))
441 (defcustom gnus-article-display-method-for-mime
442 'gnus-article-display-mime-message
443 "Function to display a MIME message.
444 The function is called from the article buffer."
445 :group 'gnus-article-mime
448 (defcustom gnus-article-display-method-for-traditional
449 'gnus-article-display-traditional-message
450 "*Function to display a traditional message.
451 The function is called from the article buffer."
452 :group 'gnus-article-mime
455 (defcustom gnus-page-delimiter "^\^L"
456 "*Regexp describing what to use as article page delimiters.
457 The default value is \"^\^L\", which is a form linefeed at the
458 beginning of a line."
460 :group 'gnus-article-various)
462 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
463 "*The format specification for the article mode line.
464 See `gnus-summary-mode-line-format' for a closer description.
466 The following additional specs are available:
468 %w The article washing status.
469 %m The number of MIME parts in the article."
471 :group 'gnus-article-various)
473 (defcustom gnus-article-mode-hook nil
474 "*A hook for Gnus article mode."
476 :group 'gnus-article-various)
478 (defcustom gnus-article-menu-hook nil
479 "*Hook run after the creation of the article mode menu."
481 :group 'gnus-article-various)
483 (defcustom gnus-article-prepare-hook nil
484 "*A hook called after an article has been prepared in the article buffer."
486 :group 'gnus-article-various)
488 (defcustom gnus-article-hide-pgp-hook nil
489 "*A hook called after successfully hiding a PGP signature."
491 :group 'gnus-article-various)
493 (defcustom gnus-article-button-face 'bold
494 "Face used for highlighting buttons in the article buffer.
496 An article button is a piece of text that you can activate by pressing
497 `RET' or `mouse-2' above it."
499 :group 'gnus-article-buttons)
501 (defcustom gnus-article-mouse-face 'highlight
502 "Face used for mouse highlighting in the article buffer.
504 Article buttons will be displayed in this face when the cursor is
507 :group 'gnus-article-buttons)
509 (defcustom gnus-signature-face 'gnus-signature-face
510 "Face used for highlighting a signature in the article buffer.
511 Obsolete; use the face `gnus-signature-face' for customizations instead."
513 :group 'gnus-article-highlight
514 :group 'gnus-article-signature)
516 (defface gnus-signature-face
519 "Face used for highlighting a signature in the article buffer."
520 :group 'gnus-article-highlight
521 :group 'gnus-article-signature)
523 (defface gnus-header-from-face
526 (:foreground "spring green"))
529 (:foreground "red3"))
532 "Face used for displaying from headers."
533 :group 'gnus-article-headers
534 :group 'gnus-article-highlight)
536 (defface gnus-header-subject-face
539 (:foreground "SeaGreen3"))
542 (:foreground "red4"))
544 (:bold t :italic t)))
545 "Face used for displaying subject headers."
546 :group 'gnus-article-headers
547 :group 'gnus-article-highlight)
549 (defface gnus-header-newsgroups-face
552 (:foreground "yellow" :italic t))
555 (:foreground "MidnightBlue" :italic t))
558 "Face used for displaying newsgroups headers."
559 :group 'gnus-article-headers
560 :group 'gnus-article-highlight)
562 (defface gnus-header-name-face
565 (:foreground "SeaGreen"))
568 (:foreground "maroon"))
571 "Face used for displaying header names."
572 :group 'gnus-article-headers
573 :group 'gnus-article-highlight)
575 (defface gnus-header-content-face
578 (:foreground "forest green" :italic t))
581 (:foreground "indianred4" :italic t))
583 (:italic t))) "Face used for displaying header content."
584 :group 'gnus-article-headers
585 :group 'gnus-article-highlight)
587 (defcustom gnus-header-face-alist
588 '(("From" nil gnus-header-from-face)
589 ("Subject" nil gnus-header-subject-face)
590 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
591 ("" gnus-header-name-face gnus-header-content-face))
592 "*Controls highlighting of article header.
594 An alist of the form (HEADER NAME CONTENT).
596 HEADER is a regular expression which should match the name of an
597 header header and NAME and CONTENT are either face names or nil.
599 The name of each header field will be displayed using the face
600 specified by the first element in the list where HEADER match the
601 header name and NAME is non-nil. Similarly, the content will be
602 displayed by the first non-nil matching CONTENT face."
603 :group 'gnus-article-headers
604 :group 'gnus-article-highlight
605 :type '(repeat (list (regexp :tag "Header")
607 (item :tag "skip" nil)
608 (face :value default))
609 (choice :tag "Content"
610 (item :tag "skip" nil)
611 (face :value default)))))
613 (defcustom gnus-article-decode-hook nil
614 "*Hook run to decode charsets in articles."
615 :group 'gnus-article-headers
618 (defcustom gnus-display-mime-function 'gnus-display-mime
619 "Function to display MIME articles."
620 :group 'gnus-article-mime
623 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
624 "Function used to decode headers.")
626 (defvar gnus-article-dumbquotes-map
644 "Table for MS-to-Latin1 translation.")
646 (defcustom gnus-ignored-mime-types nil
647 "List of MIME types that should be ignored by Gnus."
648 :group 'gnus-article-mime
649 :type '(repeat regexp))
651 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
652 "List of MIME types that should not be given buttons when rendered inline."
653 :group 'gnus-article-mime
654 :type '(repeat regexp))
656 (defcustom gnus-article-mime-part-function nil
657 "Function called with a MIME handle as the argument.
658 This is meant for people who want to do something automatic based
659 on parts -- for instance, adding Vcard info to a database."
660 :group 'gnus-article-mime
663 (defcustom gnus-mime-multipart-functions nil
664 "An alist of MIME types to functions to display them.")
666 (defcustom gnus-article-date-lapsed-new-header nil
667 "Whether the X-Sent and Date headers can coexist.
668 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
669 either replace the old \"Date:\" header (if this variable is nil), or
670 be added below it (otherwise)."
671 :group 'gnus-article-headers
674 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
675 "Function called with a MIME handle as the argument.
676 This is meant for people who want to view first matched part.
677 For `undisplayed-alternative' (default), the first undisplayed
678 part or alternative part is used. For `undisplayed', the first
679 undisplayed part is used. For a function, the first part which
680 the function return `t' is used. For `nil', the first part is
682 :group 'gnus-article-mime
684 (item :tag "first" :value nil)
685 (item :tag "undisplayed" :value undisplayed)
686 (item :tag "undisplayed or alternative"
687 :value undisplayed-alternative)
690 (defcustom gnus-mime-action-alist
691 '(("save to file" . gnus-mime-save-part)
692 ("display as text" . gnus-mime-inline-part)
693 ("view the part" . gnus-mime-view-part)
694 ("pipe to command" . gnus-mime-pipe-part)
695 ("toggle display" . gnus-article-press-button)
696 ("view as type" . gnus-mime-view-part-as-type)
697 ("internalize type" . gnus-mime-internalize-part)
698 ("externalize type" . gnus-mime-externalize-part))
699 "An alist of actions that run on the MIME attachment."
700 :group 'gnus-article-mime
701 :type '(repeat (cons (string :tag "name")
705 ;;; The treatment variables
708 (defvar gnus-part-display-hook nil
709 "Hook called on parts that are to receive treatment.")
711 (defvar gnus-article-treat-custom
712 '(choice (const :tag "Off" nil)
714 (const :tag "Header" head)
715 (const :tag "Last" last)
716 (const :tag "Mime" mime)
717 (integer :tag "Less")
718 (repeat :tag "Groups" regexp)
719 (sexp :tag "Predicate")))
721 (defvar gnus-article-treat-head-custom
722 '(choice (const :tag "Off" nil)
723 (const :tag "Header" head)))
725 (defvar gnus-article-treat-types '("text/plain")
728 (defvar gnus-inhibit-treatment nil
729 "Whether to inhibit treatment.")
731 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
732 "Highlight the signature.
733 Valid values are nil, t, `head', `last', an integer or a predicate.
734 See the manual for details."
735 :group 'gnus-article-treat
736 :type gnus-article-treat-custom)
737 (put 'gnus-treat-highlight-signature 'highlight t)
739 (defcustom gnus-treat-buttonize 100000
741 Valid values are nil, t, `head', `last', an integer or a predicate.
742 See the manual for details."
743 :group 'gnus-article-treat
744 :type gnus-article-treat-custom)
745 (put 'gnus-treat-buttonize 'highlight t)
747 (defcustom gnus-treat-buttonize-head 'head
748 "Add buttons to the head.
749 Valid values are nil, t, `head', `last', an integer or a predicate.
750 See the manual for details."
751 :group 'gnus-article-treat
752 :type gnus-article-treat-head-custom)
753 (put 'gnus-treat-buttonize-head 'highlight t)
755 (defcustom gnus-treat-emphasize nil
757 Valid values are nil, t, `head', `last', an integer or a predicate.
758 See the manual for details."
759 :group 'gnus-article-treat
760 :type gnus-article-treat-custom)
761 (put 'gnus-treat-emphasize 'highlight t)
763 (defcustom gnus-treat-strip-cr nil
764 "Remove carriage returns.
765 Valid values are nil, t, `head', `last', an integer or a predicate.
766 See the manual for details."
767 :group 'gnus-article-treat
768 :type gnus-article-treat-custom)
770 (defcustom gnus-treat-hide-headers 'head
772 Valid values are nil, t, `head', `last', an integer or a predicate.
773 See the manual for details."
774 :group 'gnus-article-treat
775 :type gnus-article-treat-head-custom)
777 (defcustom gnus-treat-hide-boring-headers nil
778 "Hide boring headers.
779 Valid values are nil, t, `head', `last', an integer or a predicate.
780 See the manual for details."
781 :group 'gnus-article-treat
782 :type gnus-article-treat-head-custom)
784 (defcustom gnus-treat-hide-signature nil
786 Valid values are nil, t, `head', `last', an integer or a predicate.
787 See the manual for details."
788 :group 'gnus-article-treat
789 :type gnus-article-treat-custom)
791 (defcustom gnus-treat-fill-article nil
793 Valid values are nil, t, `head', `last', an integer or a predicate.
794 See the manual for details."
795 :group 'gnus-article-treat
796 :type gnus-article-treat-custom)
798 (defcustom gnus-treat-hide-citation nil
800 Valid values are nil, t, `head', `last', an integer or a predicate.
801 See the manual for details."
802 :group 'gnus-article-treat
803 :type gnus-article-treat-custom)
805 (defcustom gnus-treat-hide-citation-maybe nil
807 Valid values are nil, t, `head', `last', an integer or a predicate.
808 See the manual for details."
809 :group 'gnus-article-treat
810 :type gnus-article-treat-custom)
812 (defcustom gnus-treat-strip-list-identifiers 'head
813 "Strip list identifiers from `gnus-list-identifiers`.
814 Valid values are nil, t, `head', `last', an integer or a predicate.
815 See the manual for details."
816 :group 'gnus-article-treat
817 :type gnus-article-treat-custom)
819 (defcustom gnus-treat-strip-pgp t
820 "Strip PGP signatures.
821 Valid values are nil, t, `head', `last', an integer or a predicate.
822 See the manual for details."
823 :group 'gnus-article-treat
824 :type gnus-article-treat-custom)
826 (defcustom gnus-treat-strip-pem nil
827 "Strip PEM signatures.
828 Valid values are nil, t, `head', `last', an integer or a predicate.
829 See the manual for details."
830 :group 'gnus-article-treat
831 :type gnus-article-treat-custom)
833 (defcustom gnus-treat-strip-banner t
834 "Strip banners from articles.
835 The banner to be stripped is specified in the `banner' group parameter.
836 Valid values are nil, t, `head', `last', an integer or a predicate.
837 See the manual for details."
838 :group 'gnus-article-treat
839 :type gnus-article-treat-custom)
841 (defcustom gnus-treat-highlight-headers 'head
842 "Highlight the headers.
843 Valid values are nil, t, `head', `last', an integer or a predicate.
844 See the manual for details."
845 :group 'gnus-article-treat
846 :type gnus-article-treat-head-custom)
847 (put 'gnus-treat-highlight-headers 'highlight t)
849 (defcustom gnus-treat-highlight-citation t
850 "Highlight cited text.
851 Valid values are nil, t, `head', `last', an integer or a predicate.
852 See the manual for details."
853 :group 'gnus-article-treat
854 :type gnus-article-treat-custom)
855 (put 'gnus-treat-highlight-citation 'highlight t)
857 (defcustom gnus-treat-date-ut nil
858 "Display the Date in UT (GMT).
859 Valid values are nil, t, `head', `last', an integer or a predicate.
860 See the manual for details."
861 :group 'gnus-article-treat
862 :type gnus-article-treat-head-custom)
864 (defcustom gnus-treat-date-local nil
865 "Display the Date in the local timezone.
866 Valid values are nil, t, `head', `last', an integer or a predicate.
867 See the manual for details."
868 :group 'gnus-article-treat
869 :type gnus-article-treat-head-custom)
871 (defcustom gnus-treat-date-lapsed nil
872 "Display the Date header in a way that says how much time has elapsed.
873 Valid values are nil, t, `head', `last', an integer or a predicate.
874 See the manual for details."
875 :group 'gnus-article-treat
876 :type gnus-article-treat-head-custom)
878 (defcustom gnus-treat-date-original nil
879 "Display the date in the original timezone.
880 Valid values are nil, t, `head', `last', an integer or a predicate.
881 See the manual for details."
882 :group 'gnus-article-treat
883 :type gnus-article-treat-head-custom)
885 (defcustom gnus-treat-date-iso8601 nil
886 "Display the date in the ISO8601 format.
887 Valid values are nil, t, `head', `last', an integer or a predicate.
888 See the manual for details."
889 :group 'gnus-article-treat
890 :type gnus-article-treat-head-custom)
892 (defcustom gnus-treat-date-user-defined nil
893 "Display the date in a user-defined format.
894 The format is defined by the `gnus-article-time-format' variable.
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-head-custom)
900 (defcustom gnus-treat-strip-headers-in-body t
901 "Strip the X-No-Archive header line from the beginning of the body.
902 Valid values are nil, t, `head', `last', an integer or a predicate.
903 See the manual for details."
904 :group 'gnus-article-treat
905 :type gnus-article-treat-custom)
907 (defcustom gnus-treat-strip-trailing-blank-lines nil
908 "Strip trailing blank lines.
909 Valid values are nil, t, `head', `last', an integer or a predicate.
910 See the manual for details."
911 :group 'gnus-article-treat
912 :type gnus-article-treat-custom)
914 (defcustom gnus-treat-strip-leading-blank-lines nil
915 "Strip leading blank lines.
916 Valid values are nil, t, `head', `last', an integer or a predicate.
917 See the manual for details."
918 :group 'gnus-article-treat
919 :type gnus-article-treat-custom)
921 (defcustom gnus-treat-strip-multiple-blank-lines nil
922 "Strip multiple blank lines.
923 Valid values are nil, t, `head', `last', an integer or a predicate.
924 See the manual for details."
925 :group 'gnus-article-treat
926 :type gnus-article-treat-custom)
928 (defcustom gnus-treat-overstrike t
929 "Treat overstrike highlighting.
930 Valid values are nil, t, `head', `last', an integer or a predicate.
931 See the manual for details."
932 :group 'gnus-article-treat
933 :type gnus-article-treat-custom)
934 (put 'gnus-treat-overstrike 'highlight t)
936 (defcustom gnus-treat-display-xface
937 (and (or (and (fboundp 'image-type-available-p)
938 (image-type-available-p 'xbm)
939 (string-match "^0x" (shell-command-to-string "uncompface")))
940 (and (featurep 'xemacs) (featurep 'xface))
941 (eq 'x-face-mule-gnus-article-display-x-face
942 gnus-article-x-face-command))
944 "Display X-Face headers.
945 Valid values are nil, t, `head', `last', an integer or a predicate.
946 See the manual for details."
947 :group 'gnus-article-treat
948 :type gnus-article-treat-head-custom)
949 (put 'gnus-treat-display-xface 'highlight t)
951 (defcustom gnus-treat-display-smileys
952 (if (or (and (featurep 'xemacs)
954 (and (fboundp 'image-type-available-p)
955 (image-type-available-p 'pbm))
956 (and (not (featurep 'xemacs))
958 (module-installed-p 'gnus-bitmap)))
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See the manual for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-custom)
966 (put 'gnus-treat-display-smileys 'highlight t)
968 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
970 Valid values are nil, t, `head', `last', an integer or a predicate.
971 See the manual for details."
972 :group 'gnus-article-treat
973 :type gnus-article-treat-head-custom)
974 (put 'gnus-treat-display-picons 'highlight t)
976 (defcustom gnus-treat-capitalize-sentences nil
977 "Capitalize sentence-starting words.
978 Valid values are nil, t, `head', `last', an integer or a predicate.
979 See the manual for details."
980 :group 'gnus-article-treat
981 :type gnus-article-treat-custom)
983 (defcustom gnus-treat-fill-long-lines nil
985 Valid values are nil, t, `head', `last', an integer or a predicate.
986 See the manual for details."
987 :group 'gnus-article-treat
988 :type gnus-article-treat-custom)
990 (defcustom gnus-treat-play-sounds nil
992 Valid values are nil, t, `head', `last', an integer or a predicate.
993 See the manual for details."
994 :group 'gnus-article-treat
995 :type gnus-article-treat-custom)
997 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
998 "Decode an article as `default-mime-charset'. For instance, if you want to
999 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1000 you could set this variable to something like: nil for don't decode, t for
1001 decode the body, '(or header t) for the whole article, etc."
1002 :group 'gnus-article-treat
1003 :type '(radio (const :tag "Off" nil)
1004 (const :tag "Decode body" t)
1005 (const :tag "Decode all" (or head t))))
1007 (defcustom gnus-treat-translate nil
1008 "Translate articles from one language to another.
1009 Valid values are nil, t, `head', `last', an integer or a predicate.
1010 See the manual for details."
1011 :group 'gnus-article-treat
1012 :type gnus-article-treat-custom)
1014 ;;; Internal variables
1016 (defvar article-goto-body-goes-to-point-min-p nil)
1017 (defvar gnus-article-wash-types nil)
1018 (defvar gnus-article-emphasis-alist nil)
1020 (defvar gnus-article-mime-handle-alist-1 nil)
1021 (defvar gnus-treatment-function-alist
1022 '((gnus-treat-decode-article-as-default-mime-charset
1023 gnus-article-decode-article-as-default-mime-charset)
1024 (gnus-treat-strip-banner gnus-article-strip-banner)
1025 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1026 (gnus-treat-buttonize gnus-article-add-buttons)
1027 (gnus-treat-fill-article gnus-article-fill-cited-article)
1028 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1029 (gnus-treat-strip-cr gnus-article-remove-cr)
1030 (gnus-treat-display-xface gnus-article-display-x-face)
1031 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1032 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1033 (gnus-treat-hide-signature gnus-article-hide-signature)
1034 (gnus-treat-hide-citation gnus-article-hide-citation)
1035 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1036 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1037 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1038 (gnus-treat-strip-pem gnus-article-hide-pem)
1039 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1040 (gnus-treat-emphasize gnus-article-emphasize)
1041 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1042 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1043 (gnus-treat-date-ut gnus-article-date-ut)
1044 (gnus-treat-date-local gnus-article-date-local)
1045 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1046 (gnus-treat-date-original gnus-article-date-original)
1047 (gnus-treat-date-user-defined gnus-article-date-user)
1048 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1049 (gnus-treat-strip-trailing-blank-lines
1050 gnus-article-remove-trailing-blank-lines)
1051 (gnus-treat-strip-leading-blank-lines
1052 gnus-article-strip-leading-blank-lines)
1053 (gnus-treat-strip-multiple-blank-lines
1054 gnus-article-strip-multiple-blank-lines)
1055 (gnus-treat-overstrike gnus-article-treat-overstrike)
1056 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1057 (gnus-treat-display-smileys gnus-article-smiley-display)
1058 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1059 (gnus-treat-display-picons gnus-article-display-picons)
1060 (gnus-treat-play-sounds gnus-earcon-display)))
1062 (defvar gnus-article-mime-handle-alist nil)
1063 (defvar article-lapsed-timer nil)
1064 (defvar gnus-article-current-summary nil)
1066 (defvar gnus-article-mode-syntax-table
1067 (let ((table (copy-syntax-table text-mode-syntax-table)))
1068 (modify-syntax-entry ?- "w" table)
1069 (modify-syntax-entry ?> ")" table)
1070 (modify-syntax-entry ?< "(" table)
1072 "Syntax table used in article mode buffers.
1073 Initialized from `text-mode-syntax-table.")
1075 (defvar gnus-save-article-buffer nil)
1077 (defvar gnus-article-mode-line-format-alist
1078 (nconc '((?w (gnus-article-wash-status) ?s)
1079 (?m (gnus-article-mime-part-status) ?s))
1080 gnus-summary-mode-line-format-alist))
1082 (defvar gnus-number-of-articles-to-be-saved nil)
1084 (defvar gnus-inhibit-hiding nil)
1086 (defsubst gnus-article-hide-text (b e props)
1087 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1088 (add-text-properties b e props)
1089 (when (memq 'intangible props)
1091 (max (1- b) (point-min))
1092 b 'intangible (cddr (memq 'intangible props)))))
1093 (defsubst gnus-article-unhide-text (b e)
1094 "Remove hidden text properties from region between B and E."
1095 (remove-text-properties b e gnus-hidden-properties)
1096 (when (memq 'intangible gnus-hidden-properties)
1097 (put-text-property (max (1- b) (point-min))
1098 b 'intangible nil)))
1100 (defun gnus-article-hide-text-type (b e type)
1101 "Hide text of TYPE between B and E."
1102 (push type gnus-article-wash-types)
1103 (gnus-article-hide-text
1104 b e (cons 'article-type (cons type gnus-hidden-properties))))
1106 (defun gnus-article-unhide-text-type (b e type)
1107 "Unhide text of TYPE between B and E."
1108 (setq gnus-article-wash-types
1109 (delq type gnus-article-wash-types))
1110 (remove-text-properties
1111 b e (cons 'article-type (cons type gnus-hidden-properties)))
1112 (when (memq 'intangible gnus-hidden-properties)
1113 (put-text-property (max (1- b) (point-min))
1114 b 'intangible nil)))
1116 (defun gnus-article-hide-text-of-type (type)
1117 "Hide text of TYPE in the current buffer."
1119 (let ((b (point-min))
1121 (while (setq b (text-property-any b e 'article-type type))
1122 (add-text-properties b (incf b) gnus-hidden-properties)))))
1124 (defun gnus-article-delete-text-of-type (type)
1125 "Delete text of TYPE in the current buffer."
1127 (let ((b (point-min)))
1128 (while (setq b (text-property-any b (point-max) 'article-type type))
1130 b (or (text-property-not-all b (point-max) 'article-type type)
1133 (defun gnus-article-delete-invisible-text ()
1134 "Delete all invisible text in the current buffer."
1136 (let ((b (point-min)))
1137 (while (setq b (text-property-any b (point-max) 'invisible t))
1139 b (or (text-property-not-all b (point-max) 'invisible t)
1142 (defun gnus-article-text-type-exists-p (type)
1143 "Say whether any text of type TYPE exists in the buffer."
1144 (text-property-any (point-min) (point-max) 'article-type type))
1146 (defsubst gnus-article-header-rank ()
1147 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1148 (let ((list gnus-sorted-header-list)
1151 (when (looking-at (car list))
1153 (setq list (cdr list))
1157 (defun article-hide-headers (&optional arg delete)
1158 "Hide unwanted headers and possibly sort them as well."
1159 (interactive (gnus-article-hidden-arg))
1160 ;; Lars said that this function might be inhibited.
1161 (if (gnus-article-check-hidden-text 'headers arg)
1163 ;; Show boring headers as well.
1164 (gnus-article-show-hidden-text 'boring-headers)
1165 (when (eq 1 (point-min))
1166 (set-window-start (get-buffer-window (current-buffer)) 1)))
1167 (unless gnus-inhibit-hiding
1170 (let ((buffer-read-only nil)
1171 (inhibit-read-only t)
1172 (case-fold-search t)
1173 (max (1+ (length gnus-sorted-header-list)))
1174 (ignored (when (not gnus-visible-headers)
1175 (cond ((stringp gnus-ignored-headers)
1176 gnus-ignored-headers)
1177 ((listp gnus-ignored-headers)
1178 (mapconcat 'identity gnus-ignored-headers
1181 (cond ((stringp gnus-visible-headers)
1182 gnus-visible-headers)
1183 ((and gnus-visible-headers
1184 (listp gnus-visible-headers))
1185 (mapconcat 'identity gnus-visible-headers "\\|"))))
1186 (inhibit-point-motion-hooks t)
1188 ;; First we narrow to just the headers.
1189 (article-narrow-to-head)
1190 ;; Hide any "From " lines at the beginning of (mail) articles.
1191 (while (looking-at "From ")
1195 (delete-region (point-min) (point))
1196 (gnus-article-hide-text (point-min) (point)
1197 (nconc (list 'article-type 'headers)
1198 gnus-hidden-properties))))
1199 ;; Then treat the rest of the header lines.
1200 ;; Then we use the two regular expressions
1201 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1202 ;; select which header lines is to remain visible in the
1204 (while (re-search-forward "^[^ \t]*:" nil t)
1206 ;; Mark the rank of the header.
1208 (point) (1+ (point)) 'message-rank
1209 (if (or (and visible (looking-at visible))
1211 (not (looking-at ignored))))
1212 (gnus-article-header-rank)
1215 (message-sort-headers-1)
1216 (when (setq beg (text-property-any
1217 (point-min) (point-max) 'message-rank (+ 2 max)))
1218 ;; We delete or make invisible the unwanted headers.
1219 (push 'headers gnus-article-wash-types)
1222 (add-text-properties
1223 (point-min) (+ 5 (point-min))
1224 '(article-type headers dummy-invisible t))
1225 (delete-region beg (point-max)))
1226 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1229 (defun article-hide-boring-headers (&optional arg)
1230 "Toggle hiding of headers that aren't very interesting.
1231 If given a negative prefix, always show; if given a positive prefix,
1233 (interactive (gnus-article-hidden-arg))
1234 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1235 (not gnus-show-all-headers))
1238 (let ((buffer-read-only nil)
1239 (list gnus-boring-article-headers)
1240 (inhibit-point-motion-hooks t)
1242 (article-narrow-to-head)
1244 (setq elem (pop list))
1245 (goto-char (point-min))
1247 ;; Hide empty headers.
1249 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1251 (gnus-article-hide-text-type
1252 (progn (beginning-of-line) (point))
1255 (if (re-search-forward "^[^ \t]" nil t)
1259 ;; Hide boring Newsgroups header.
1260 ((eq elem 'newsgroups)
1261 (when (equal (gnus-fetch-field "newsgroups")
1262 (gnus-group-real-name
1263 (if (boundp 'gnus-newsgroup-name)
1266 (gnus-article-hide-header "newsgroups")))
1267 ((eq elem 'followup-to)
1268 (when (equal (message-fetch-field "followup-to")
1269 (message-fetch-field "newsgroups"))
1270 (gnus-article-hide-header "followup-to")))
1271 ((eq elem 'reply-to)
1272 (let ((from (message-fetch-field "from"))
1273 (reply-to (message-fetch-field "reply-to")))
1278 (nth 1 (funcall gnus-extract-address-components from))
1279 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1280 (gnus-article-hide-header "reply-to"))))
1282 (let ((date (message-fetch-field "date")))
1284 (< (days-between (current-time-string) date)
1286 (gnus-article-hide-header "date"))))
1288 (let ((to (message-fetch-field "to"))
1289 (cc (message-fetch-field "cc")))
1290 (when (> (length to) 1024)
1291 (gnus-article-hide-header "to"))
1292 (when (> (length cc) 1024)
1293 (gnus-article-hide-header "cc"))))
1297 (goto-char (point-min))
1298 (while (re-search-forward "^to:" nil t)
1299 (setq to-count (1+ to-count)))
1300 (when (> to-count 1)
1301 (while (> to-count 0)
1302 (goto-char (point-min))
1304 (re-search-forward "^to:" nil nil to-count)
1306 (narrow-to-region (point) (point-max))
1307 (gnus-article-hide-header "to"))
1308 (setq to-count (1- to-count))))
1309 (goto-char (point-min))
1310 (while (re-search-forward "^cc:" nil t)
1311 (setq cc-count (1+ cc-count)))
1312 (when (> cc-count 1)
1313 (while (> cc-count 0)
1314 (goto-char (point-min))
1316 (re-search-forward "^cc:" nil nil cc-count)
1318 (narrow-to-region (point) (point-max))
1319 (gnus-article-hide-header "cc"))
1320 (setq cc-count (1- cc-count)))))))))))))
1322 (defun gnus-article-hide-header (header)
1324 (goto-char (point-min))
1325 (when (re-search-forward (concat "^" header ":") nil t)
1326 (gnus-article-hide-text-type
1327 (progn (beginning-of-line) (point))
1330 (if (re-search-forward "^[^ \t]" nil t)
1335 (defun article-toggle-headers (&optional arg)
1336 "Toggle hiding of headers. If given a negative prefix, always show;
1337 if given a positive prefix, always hide."
1338 (interactive (gnus-article-hidden-arg))
1339 (let ((force (when (numberp arg)
1340 (cond ((> arg 0) 'always-hide)
1341 ((< arg 0) 'always-show))))
1342 (window (get-buffer-window gnus-article-buffer))
1343 (header-end (point-min))
1344 header-start field-end field-start
1345 (inhibit-point-motion-hooks t)
1346 (inhibit-read-only t)
1350 (while (and (setq header-start
1351 (text-property-any header-end (point-max)
1352 'article-treated-header t))
1354 (text-property-not-all header-start (point-max)
1355 'article-treated-header t)))
1356 (setq field-end header-start)
1358 (;; Hide exposed invisible fields.
1359 (and (not (eq 'always-show force))
1361 (text-property-any field-end header-end
1362 'exposed-invisible-field t)))
1363 (while (and field-start
1364 (setq field-end (text-property-not-all
1365 field-start header-end
1366 'exposed-invisible-field t)))
1367 (add-text-properties field-start field-end gnus-hidden-properties)
1368 (setq field-start (text-property-any field-end header-end
1369 'exposed-invisible-field t)))
1370 (put-text-property header-start header-end
1371 'exposed-invisible-field nil))
1372 (;; Expose invisible fields.
1373 (and (not (eq 'always-hide force))
1375 (text-property-any field-end header-end 'invisible t)))
1376 (while (and field-start
1377 (setq field-end (text-property-not-all
1378 field-start header-end
1380 ;; If the invisible text is not terminated with newline, we
1381 ;; won't expose it. Because it may be created by x-face-mule.
1382 ;; BTW, XEmacs sometimes fail in putting a invisible text
1383 ;; property with `gnus-article-hide-text' (really?). In that
1384 ;; case, the invisible text might be started from the middle of
1385 ;; a line so we will expose the sort of thing.
1386 (when (or (not (or (eq header-start field-start)
1387 (eq ?\n (char-before field-start))))
1388 (eq ?\n (char-before field-end)))
1389 (remove-text-properties field-start field-end
1390 gnus-hidden-properties)
1391 (put-text-property field-start field-end
1392 'exposed-invisible-field t))
1393 (setq field-start (text-property-any field-end header-end
1396 (not (eq 'always-show force))
1397 (narrow-to-region header-start header-end)
1398 (article-hide-headers)
1399 ;; Re-display X-Face image under XEmacs.
1400 (when (and (featurep 'xemacs)
1401 (gnus-functionp gnus-article-x-face-command))
1402 (let ((func (cadr (assq 'gnus-treat-display-xface
1403 gnus-treatment-function-alist)))
1405 (when (and (not gnus-inhibit-treatment)
1407 (gnus-treat-predicate gnus-treat-display-xface))
1409 (put-text-property header-start header-end 'read-only nil))))
1412 (goto-char (point-min))
1414 (set-window-start window (point-min))))))
1416 (defvar gnus-article-normalized-header-length 40
1417 "Length of normalized headers.")
1419 (defun article-normalize-headers ()
1420 "Make all header lines 40 characters long."
1422 (let ((buffer-read-only nil)
1426 (article-narrow-to-head)
1429 ((< (setq column (- (gnus-point-at-eol) (point)))
1430 gnus-article-normalized-header-length)
1432 (insert (make-string
1433 (- gnus-article-normalized-header-length column)
1435 ((> column gnus-article-normalized-header-length)
1436 (gnus-put-text-property
1438 (forward-char gnus-article-normalized-header-length)
1445 (forward-line 1))))))
1447 (defun article-treat-dumbquotes ()
1448 "Translate M******** sm*rtq**t*s into proper text.
1449 Note that this function guesses whether a character is a sm*rtq**t* or
1450 not, so it should only be used interactively."
1452 (article-translate-strings gnus-article-dumbquotes-map))
1454 (defun article-translate-characters (from to)
1455 "Translate all characters in the body of the article according to FROM and TO.
1456 FROM is a string of characters to translate from; to is a string of
1457 characters to translate to."
1459 (when (article-goto-body)
1460 (let ((buffer-read-only nil)
1461 (x (make-string 225 ?x))
1463 (while (< (incf i) (length x))
1466 (while (< i (length from))
1467 (aset x (aref from i) (aref to i))
1469 (translate-region (point) (point-max) x)))))
1471 (defun article-translate-strings (map)
1472 "Translate all string in the body of the article according to MAP.
1473 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1475 (when (article-goto-body)
1476 (let ((buffer-read-only nil)
1478 (while (setq elem (pop map))
1480 (while (search-forward (car elem) nil t)
1481 (replace-match (cadr elem)))))))))
1483 (defun article-treat-overstrike ()
1484 "Translate overstrikes into bold text."
1487 (when (article-goto-body)
1488 (let ((buffer-read-only nil))
1489 (while (search-forward "\b" nil t)
1490 (let ((next (char-after))
1494 previous (char-after))
1498 ;; We do the boldification/underlining by hiding the
1499 ;; overstrikes and putting the proper text property
1503 (gnus-article-hide-text-type start (point) 'overstrike)
1504 (put-text-property (point) end 'face 'bold))
1506 (gnus-article-hide-text-type
1507 (1- (point)) (1+ (point)) 'overstrike)
1509 start (1- (point)) 'face 'underline))
1511 (gnus-article-hide-text-type start (point) 'overstrike)
1513 (point) end 'face 'underline)))))))))
1515 (defun article-fill-long-lines ()
1516 "Fill lines that are wider than the window width."
1519 (let ((buffer-read-only nil)
1520 (width (window-width (get-buffer-window (current-buffer)))))
1523 (let ((adaptive-fill-mode nil))
1526 (when (>= (current-column) (min fill-column width))
1527 (narrow-to-region (point) (gnus-point-at-bol))
1528 (fill-paragraph nil)
1529 (goto-char (point-max))
1531 (forward-line 1)))))))
1533 (defun article-capitalize-sentences ()
1534 "Capitalize the first word in each sentence."
1537 (let ((buffer-read-only nil)
1538 (paragraph-start "^[\n\^L]"))
1542 (forward-sentence)))))
1544 (defun article-remove-cr ()
1545 "Remove trailing CRs and then translate remaining CRs into LFs."
1548 (let ((buffer-read-only nil))
1549 (goto-char (point-min))
1550 (while (re-search-forward "\r+$" nil t)
1551 (replace-match "" t t))
1552 (goto-char (point-min))
1553 (while (search-forward "\r" nil t)
1554 (replace-match "\n" t t)))))
1556 (defun article-remove-trailing-blank-lines ()
1557 "Remove all trailing blank lines from the article."
1560 (let ((buffer-read-only nil))
1561 (goto-char (point-max))
1565 (while (and (not (bobp))
1566 (looking-at "^[ \t]*$")
1567 (not (gnus-annotation-in-region-p
1568 (point) (gnus-point-at-eol))))
1573 (defun article-display-x-face (&optional force)
1574 "Look for an X-Face header and display it if present."
1575 (interactive (list 'force))
1577 ;; Delete the old process, if any.
1578 (when (process-status "article-x-face")
1579 (delete-process "article-x-face"))
1580 (let ((inhibit-point-motion-hooks t)
1581 (case-fold-search t)
1584 (article-narrow-to-head)
1585 (goto-char (point-min))
1586 (setq from (message-fetch-field "from"))
1587 (goto-char (point-min))
1588 (while (and gnus-article-x-face-command
1591 ;; Check whether this face is censored.
1592 (not gnus-article-x-face-too-ugly)
1593 (and gnus-article-x-face-too-ugly from
1594 (not (string-match gnus-article-x-face-too-ugly
1596 ;; Has to be present.
1597 (re-search-forward "^X-Face:[ \t]*" nil t))
1598 ;; This used to try to do multiple faces (`while' instead of
1599 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1600 ;; work (b) it can crash some versions of Emacs (c) are
1601 ;; multiple faces really something to encourage?
1602 (when (stringp gnus-article-x-face-command)
1604 ;; We now have the area of the buffer where the X-Face is stored.
1607 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1608 ;; We display the face.
1609 (if (symbolp gnus-article-x-face-command)
1610 ;; The command is a lisp function, so we call it.
1611 (if (gnus-functionp gnus-article-x-face-command)
1612 (funcall gnus-article-x-face-command beg end)
1613 (error "%s is not a function" gnus-article-x-face-command))
1614 ;; The command is a string, so we interpret the command
1615 ;; as a, well, command, and fork it off.
1616 (let ((process-connection-type nil))
1617 (process-kill-without-query
1619 "article-x-face" nil shell-file-name shell-command-switch
1620 gnus-article-x-face-command))
1621 (process-send-region "article-x-face" beg end)
1622 (process-send-eof "article-x-face"))))))))))
1624 (defun article-decode-mime-words ()
1625 "Decode all MIME-encoded words in the article."
1628 (set-buffer gnus-article-buffer)
1629 (let ((inhibit-point-motion-hooks t)
1631 (mail-parse-charset gnus-newsgroup-charset)
1632 (mail-parse-ignored-charsets
1633 (save-excursion (set-buffer gnus-summary-buffer)
1634 gnus-newsgroup-ignored-charsets)))
1635 (mail-decode-encoded-word-region (point-min) (point-max)))))
1637 (defun article-decode-charset (&optional prompt)
1638 "Decode charset-encoded text in the article.
1639 If PROMPT (the prefix), prompt for a coding system to use."
1641 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1643 (mail-parse-charset gnus-newsgroup-charset)
1644 (mail-parse-ignored-charsets
1645 (save-excursion (condition-case nil
1646 (set-buffer gnus-summary-buffer)
1648 gnus-newsgroup-ignored-charsets))
1649 ct cte ctl charset format)
1652 (article-narrow-to-head)
1653 (setq ct (message-fetch-field "Content-Type" t)
1654 cte (message-fetch-field "Content-Transfer-Encoding" t)
1655 ctl (and ct (ignore-errors
1656 (mail-header-parse-content-type ct)))
1659 (mm-read-coding-system "Charset to decode: "))
1661 (mail-content-type-get ctl 'charset)))
1662 format (and ctl (mail-content-type-get ctl 'format)))
1664 (setq cte (mail-header-strip cte)))
1665 (if (and ctl (not (string-match "/" (car ctl))))
1667 (goto-char (point-max)))
1670 (narrow-to-region (point) (point-max))
1671 (when (and (eq mail-parse-charset 'gnus-decoded)
1672 (eq (mm-body-7-or-8) '8bit))
1673 ;; The text code could have been decoded.
1674 (setq charset mail-parse-charset))
1675 (when (and (or (not ctl)
1676 (equal (car ctl) "text/plain"))
1677 (not format)) ;; article with format will decode later.
1679 charset (and cte (intern (downcase
1680 (gnus-strip-whitespace cte))))
1683 (defun article-decode-encoded-words ()
1684 "Remove encoded-word encoding from headers."
1685 (let (buffer-read-only)
1686 (let ((charset (save-excursion
1687 (set-buffer gnus-summary-buffer)
1688 default-mime-charset)))
1689 (mime-decode-header-in-buffer charset)
1692 (defun article-de-quoted-unreadable (&optional force)
1693 "Translate a quoted-printable-encoded article.
1694 If FORCE, decode the article whether it is marked as quoted-printable
1696 (interactive (list 'force))
1698 (let ((buffer-read-only nil) type charset)
1699 (if (gnus-buffer-live-p gnus-original-article-buffer)
1700 (with-current-buffer gnus-original-article-buffer
1702 (gnus-fetch-field "content-transfer-encoding"))
1703 (let* ((ct (gnus-fetch-field "content-type"))
1706 (mail-header-parse-content-type ct)))))
1707 (setq charset (and ctl
1708 (mail-content-type-get ctl 'charset)))
1709 (if (stringp charset)
1710 (setq charset (intern (downcase charset)))))))
1712 (setq charset gnus-newsgroup-charset))
1714 (and type (let ((case-fold-search t))
1715 (string-match "quoted-printable" type))))
1717 (quoted-printable-decode-region
1718 (point) (point-max) (mm-charset-to-coding-system charset))))))
1720 (defun article-de-base64-unreadable (&optional force)
1721 "Translate a base64 article.
1722 If FORCE, decode the article whether it is marked as base64 not."
1723 (interactive (list 'force))
1725 (let ((buffer-read-only nil) type charset)
1726 (if (gnus-buffer-live-p gnus-original-article-buffer)
1727 (with-current-buffer gnus-original-article-buffer
1729 (gnus-fetch-field "content-transfer-encoding"))
1730 (let* ((ct (gnus-fetch-field "content-type"))
1733 (mail-header-parse-content-type ct)))))
1734 (setq charset (and ctl
1735 (mail-content-type-get ctl 'charset)))
1736 (if (stringp charset)
1737 (setq charset (intern (downcase charset)))))))
1739 (setq charset gnus-newsgroup-charset))
1741 (and type (let ((case-fold-search t))
1742 (string-match "base64" type))))
1745 (narrow-to-region (point) (point-max))
1746 (base64-decode-region (point-min) (point-max))
1747 (mm-decode-coding-region
1748 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1753 (defun article-decode-HZ ()
1754 "Translate a HZ-encoded article."
1758 (let ((buffer-read-only nil))
1759 (rfc1843-decode-region (point-min) (point-max)))))
1761 (defun article-wash-html ()
1762 "Format an html article."
1765 (let ((buffer-read-only nil)
1767 (if (gnus-buffer-live-p gnus-original-article-buffer)
1768 (with-current-buffer gnus-original-article-buffer
1769 (let* ((ct (gnus-fetch-field "content-type"))
1772 (mail-header-parse-content-type ct)))))
1773 (setq charset (and ctl
1774 (mail-content-type-get ctl 'charset)))
1775 (if (stringp charset)
1776 (setq charset (intern (downcase charset)))))))
1778 (setq charset gnus-newsgroup-charset))
1780 (save-window-excursion
1782 (narrow-to-region (point) (point-max))
1784 (let ((w3-strict-width (window-width))
1785 (url-standalone-mode t))
1787 (w3-region (point-min) (point-max))
1790 (defun article-hide-list-identifiers ()
1791 "Remove list identifies from the Subject header.
1792 The `gnus-list-identifiers' variable specifies what to do."
1796 (let ((inhibit-point-motion-hooks t)
1798 (article-narrow-to-head)
1799 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1800 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1802 (goto-char (point-min))
1803 (when (re-search-forward
1804 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1805 " *\\)\\)+\\(Re: +\\)?\\)")
1807 (let ((s (or (match-string 3) (match-string 5))))
1808 (delete-region (match-beginning 1) (match-end 1))
1810 (goto-char (match-beginning 1))
1813 (defun article-hide-pgp ()
1814 "Remove any PGP headers and signatures in the current article."
1818 (let ((inhibit-point-motion-hooks t)
1819 buffer-read-only beg end)
1821 ;; Hide the "header".
1822 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1823 (push 'pgp gnus-article-wash-types)
1824 (delete-region (match-beginning 0) (match-end 0))
1825 ;; Remove armor headers (rfc2440 6.2)
1826 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1829 ;; Hide the actual signature.
1830 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1831 (setq end (1+ (match-beginning 0)))
1834 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1836 ;; Perhaps we shouldn't hide to the end of the buffer
1837 ;; if there is no end to the signature?
1839 ;; Hide "- " PGP quotation markers.
1841 (narrow-to-region beg end)
1842 (goto-char (point-min))
1843 (while (re-search-forward "^- " nil t)
1845 (match-beginning 0) (match-end 0)))
1847 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1849 (defun article-hide-pem (&optional arg)
1850 "Toggle hiding of any PEM headers and signatures in the current article.
1851 If given a negative prefix, always show; if given a positive prefix,
1853 (interactive (gnus-article-hidden-arg))
1854 (unless (gnus-article-check-hidden-text 'pem arg)
1856 (let (buffer-read-only end)
1857 (goto-char (point-min))
1858 ;; Hide the horrendously ugly "header".
1859 (when (and (search-forward
1860 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1862 (setq end (1+ (match-beginning 0))))
1863 (push 'pem gnus-article-wash-types)
1864 (gnus-article-hide-text-type
1866 (if (search-forward "\n\n" nil t)
1870 ;; Hide the trailer as well
1871 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1873 (gnus-article-hide-text-type
1874 (match-beginning 0) (match-end 0) 'pem)))))))
1876 (defun article-strip-banner ()
1877 "Strip the banner specified by the `banner' group parameter."
1881 (let ((inhibit-point-motion-hooks t)
1882 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1883 (gnus-signature-limit nil)
1884 buffer-read-only beg end)
1888 ((eq banner 'signature)
1889 (when (gnus-article-narrow-to-signature)
1892 (delete-region (point) (point-max))))
1894 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1895 (while (re-search-forward banner nil t)
1896 (delete-region (match-beginning 0) (match-end 0)))))
1898 (while (re-search-forward banner nil t)
1899 (delete-region (match-beginning 0) (match-end 0))))))))))
1901 (defun article-babel ()
1902 "Translate article using an online translation service."
1906 (set-buffer gnus-article-buffer)
1907 (when (article-goto-body)
1908 (let* ((buffer-read-only nil)
1911 (orig (buffer-substring start end))
1912 (trans (babel-as-string orig)))
1914 (narrow-to-region start end)
1915 (delete-region start end)
1918 (defun article-hide-signature (&optional arg)
1919 "Hide the signature in the current article.
1920 If given a negative prefix, always show; if given a positive prefix,
1922 (interactive (gnus-article-hidden-arg))
1928 (article-goto-body))
1929 (goto-char (point-min)))
1930 (unless (gnus-article-check-hidden-text 'signature arg)
1931 (let ((buffer-read-only nil)
1933 (while (setq button (text-property-any button (point-max)
1935 'gnus-signature-toggle))
1936 (setq button (text-property-not-all button (point-max)
1938 'gnus-signature-toggle))
1939 (when (and button (not (eobp)))
1940 (gnus-article-hide-text-type
1942 (next-single-property-change (1+ button) 'mime-view-entity
1946 (defun article-strip-headers-in-body ()
1947 "Strip offensive headers from bodies."
1951 (let ((case-fold-search t))
1952 (when (looking-at "x-no-archive:")
1953 (gnus-delete-line)))))
1955 (defun article-strip-leading-blank-lines ()
1956 "Remove all blank lines from the beginning of the article."
1959 (let ((inhibit-point-motion-hooks t)
1961 (when (article-goto-body)
1962 (while (and (not (eobp))
1963 (looking-at "[ \t]*$"))
1964 (gnus-delete-line))))))
1966 (defun article-narrow-to-head ()
1967 "Narrow the buffer to the head of the message.
1968 Point is left at the beginning of the narrowed-to region."
1970 (goto-char (point-min))
1971 (if (search-forward "\n\n" nil 1)
1974 (goto-char (point-min)))
1976 (defun article-goto-body ()
1977 "Place point at the start of the body."
1978 (goto-char (point-min))
1980 ;; This variable is only bound when dealing with separate
1982 (article-goto-body-goes-to-point-min-p
1984 ((search-forward "\n\n" nil t)
1987 (goto-char (point-max))
1990 (defun article-strip-multiple-blank-lines ()
1991 "Replace consecutive blank lines with one empty line."
1994 (let ((inhibit-point-motion-hooks t)
1996 ;; First make all blank lines empty.
1998 (while (re-search-forward "^[ \t]+$" nil t)
1999 (unless (gnus-annotation-in-region-p
2000 (match-beginning 0) (match-end 0))
2001 (replace-match "" nil t)))
2002 ;; Then replace multiple empty lines with a single empty line.
2004 (while (re-search-forward "\n\n\n+" nil t)
2005 (unless (gnus-annotation-in-region-p
2006 (match-beginning 0) (match-end 0))
2007 (replace-match "\n\n" t t))))))
2009 (defun article-strip-leading-space ()
2010 "Remove all white space from the beginning of the lines in the article."
2013 (let ((inhibit-point-motion-hooks t)
2016 (while (re-search-forward "^[ \t]+" nil t)
2017 (replace-match "" t t)))))
2019 (defun article-strip-trailing-space ()
2020 "Remove all white space from the end of the lines in the article."
2023 (let ((inhibit-point-motion-hooks t)
2026 (while (re-search-forward "[ \t]+$" nil t)
2027 (replace-match "" t t)))))
2029 (defun article-strip-blank-lines ()
2030 "Strip leading, trailing and multiple blank lines."
2032 (article-strip-leading-blank-lines)
2033 (article-remove-trailing-blank-lines)
2034 (article-strip-multiple-blank-lines))
2036 (defun article-strip-all-blank-lines ()
2037 "Strip all blank lines."
2040 (let ((inhibit-point-motion-hooks t)
2043 (while (re-search-forward "^[ \t]*\n" nil t)
2044 (replace-match "" t t)))))
2046 (defun gnus-article-narrow-to-signature ()
2047 "Narrow to the signature; return t if a signature is found, else nil."
2048 (let ((inhibit-point-motion-hooks t))
2049 (when (gnus-article-search-signature)
2051 ;; Check whether we have some limits to what we consider
2052 ;; to be a signature.
2053 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2054 (list gnus-signature-limit)))
2056 (while (setq limit (pop limits))
2057 (if (or (and (integerp limit)
2058 (< (- (point-max) (point)) limit))
2060 (< (count-lines (point) (point-max)) limit))
2061 (and (gnus-functionp limit)
2063 (and (stringp limit)
2064 (not (re-search-forward limit nil t))))
2065 () ; This limit did not succeed.
2069 (narrow-to-region (point) (point-max))
2072 (defun gnus-article-search-signature ()
2073 "Search the current buffer for the signature separator.
2074 Put point at the beginning of the signature separator."
2075 (let ((cur (point)))
2076 (goto-char (point-max))
2077 (if (if (stringp gnus-signature-separator)
2078 (re-search-backward gnus-signature-separator nil t)
2079 (let ((seps gnus-signature-separator))
2081 (not (re-search-backward (car seps) nil t)))
2088 (defun gnus-article-hidden-arg ()
2089 "Return the current prefix arg as a number, or 0 if no prefix."
2090 (list (if current-prefix-arg
2091 (prefix-numeric-value current-prefix-arg)
2094 (defun gnus-article-check-hidden-text (type arg)
2095 "Return nil if hiding is necessary.
2096 Arg can be nil or a number. Nil and positive means hide, negative
2097 means show, 0 means toggle."
2100 (let ((hide (gnus-article-hidden-text-p type)))
2106 (gnus-article-show-hidden-text type))
2108 (if (eq hide 'hidden)
2109 (gnus-article-show-hidden-text type)
2112 (defun gnus-article-hidden-text-p (type)
2113 "Say whether the current buffer contains hidden text of type TYPE."
2114 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2116 (not (get-text-property pos 'invisible))
2117 (not (get-text-property pos 'dummy-invisible)))
2119 (text-property-any (1+ pos) (point-max) 'article-type type)))
2124 (defun gnus-article-show-hidden-text (type &optional hide)
2125 "Show all hidden text of type TYPE.
2126 If HIDE, hide the text instead."
2128 (let ((buffer-read-only nil)
2129 (inhibit-point-motion-hooks t)
2132 (while (setq beg (text-property-any end (point-max) 'article-type type))
2135 (text-property-not-all beg (point-max) 'article-type type)
2138 (gnus-article-hide-text beg end gnus-hidden-properties)
2139 (gnus-article-unhide-text beg end))
2143 (defconst article-time-units
2144 `((year . ,(* 365.25 24 60 60))
2145 (week . ,(* 7 24 60 60))
2146 (day . ,(* 24 60 60))
2150 "Mapping from time units to seconds.")
2152 (defun article-date-ut (&optional type highlight header)
2153 "Convert DATE date to universal time in the current article.
2154 If TYPE is `local', convert to local time; if it is `lapsed', output
2155 how much time has lapsed since DATE. For `lapsed', the value of
2156 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2157 should replace the \"Date:\" one, or should be added below it."
2158 (interactive (list 'ut t))
2159 (let* ((header (or header
2160 (and (eq 1 (point-min))
2161 (mail-header-date (save-excursion
2162 (set-buffer gnus-summary-buffer)
2163 gnus-current-headers)))
2164 (message-fetch-field "date")
2166 (date (if (vectorp header) (mail-header-date header)
2168 (inhibit-point-motion-hooks t)
2169 bface eface date-pos)
2170 (when (and date (not (string= date "")))
2173 (article-narrow-to-head)
2174 (when (or (and (eq type 'lapsed)
2175 gnus-article-date-lapsed-new-header
2176 ;; Attempt to get the face of X-Sent first.
2177 (re-search-forward "^X-Sent:[ \t]" nil t))
2178 (re-search-forward "^Date:[ \t]" nil t)
2179 ;; If Date is missing, try again for X-Sent.
2180 (re-search-forward "^X-Sent:[ \t]" nil t))
2181 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2182 date (or (get-text-property (gnus-point-at-bol)
2185 eface (get-text-property (1- (gnus-point-at-eol))
2187 (let ((buffer-read-only nil))
2188 ;; Delete any old X-Sent headers.
2189 (when (setq date-pos
2190 (text-property-any (point-min) (point-max)
2191 'article-date-lapsed t))
2192 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2193 (delete-region (match-beginning 0)
2194 (progn (forward-line 1) (point))))
2195 (goto-char (point-min))
2196 ;; Delete any old Date headers.
2197 (while (re-search-forward "^Date:[ \t]" nil t)
2199 (setq date-pos (match-beginning 0)))
2200 (unless (and (eq type 'lapsed)
2201 gnus-article-date-lapsed-new-header)
2202 (delete-region (match-beginning 0)
2203 (progn (message-next-header) (point)))))
2206 (goto-char date-pos)
2208 ;; Possibly, Date has been deleted.
2210 (when (and (eq type 'lapsed)
2211 gnus-article-date-lapsed-new-header
2212 (looking-at "Date:"))
2214 (goto-char (point-min)))
2215 (insert (article-make-date-line date type))
2216 (when (eq type 'lapsed)
2217 (put-text-property (gnus-point-at-bol) (point)
2218 'article-date-lapsed t))
2222 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2223 (put-text-property (match-beginning 1) (1+ (match-end 1))
2224 'original-date date)
2225 (put-text-property (match-beginning 1) (1+ (match-end 1))
2227 (put-text-property (match-beginning 2) (match-end 2)
2230 (defun article-make-date-line (date type)
2231 "Return a DATE line of TYPE."
2232 (let ((time (condition-case ()
2236 ;; Convert to the local timezone. We have to slap a
2237 ;; `condition-case' round the calls to the timezone
2238 ;; functions since they aren't particularly resistant to
2241 (let ((tz (car (current-time-zone time))))
2242 (format "Date: %s %s%02d%02d" (current-time-string time)
2243 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2244 (/ (% (abs tz) 3600) 60))))
2245 ;; Convert to Universal Time.
2248 (current-time-string
2249 (let* ((e (parse-time-string date))
2250 (tm (apply 'encode-time e))
2252 (ls (- (cadr tm) (car (current-time-zone time)))))
2253 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2254 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2257 ;; Get the original date from the article.
2258 ((eq type 'original)
2259 (concat "Date: " (if (string-match "\n+$" date)
2260 (substring date 0 (match-beginning 0))
2262 ;; Let the user define the format.
2264 (if (gnus-functionp gnus-article-time-format)
2265 (funcall gnus-article-time-format time)
2268 (format-time-string gnus-article-time-format time))))
2271 (let ((tz (car (current-time-zone time))))
2274 (format-time-string "%Y%m%dT%H%M%S" time)
2275 (format "%s%02d%02d"
2276 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2277 (/ (% (abs tz) 3600) 60)))))
2278 ;; Do an X-Sent lapsed format.
2280 ;; If the date is seriously mangled, the timezone functions are
2281 ;; liable to bug out, so we ignore all errors.
2282 (let* ((now (current-time))
2283 (real-time (subtract-time now time))
2284 (real-sec (and real-time
2285 (+ (* (float (car real-time)) 65536)
2287 (sec (and real-time (abs real-sec)))
2297 ;; This is a bit convoluted, but basically we go
2298 ;; through the time units for years, weeks, etc,
2299 ;; and divide things to see whether that results
2300 ;; in positive answers.
2303 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2304 ;; The (remaining) seconds are too few to
2305 ;; be divided into this time unit.
2307 ;; It's big enough, so we output it.
2308 (setq sec (- sec (* num (cdr unit))))
2310 (concat (if prev ", " "") (int-to-string
2312 " " (symbol-name (car unit))
2313 (if (> num 1) "s" ""))
2315 article-time-units "")
2316 ;; If dates are odd, then it might appear like the
2317 ;; article was sent in the future.
2320 " in the future"))))))
2322 (error "Unknown conversion type: %s" type)))))
2324 (defun article-date-local (&optional highlight)
2325 "Convert the current article date to the local timezone."
2326 (interactive (list t))
2327 (article-date-ut 'local highlight))
2329 (defun article-date-original (&optional highlight)
2330 "Convert the current article date to what it was originally.
2331 This is only useful if you have used some other date conversion
2332 function and want to see what the date was before converting."
2333 (interactive (list t))
2334 (article-date-ut 'original highlight))
2336 (defun article-date-lapsed (&optional highlight)
2337 "Convert the current article date to time lapsed since it was sent."
2338 (interactive (list t))
2339 (article-date-ut 'lapsed highlight))
2341 (defun article-update-date-lapsed ()
2342 "Function to be run from a timer to update the lapsed time line."
2343 (let (deactivate-mark)
2348 (set-buffer (window-buffer w))
2349 (when (eq major-mode 'gnus-article-mode)
2350 (goto-char (point-min))
2351 (when (re-search-forward "^X-Sent:" nil t)
2352 (article-date-lapsed t))))
2355 (defun gnus-start-date-timer (&optional n)
2356 "Start a timer to update the X-Sent header in the article buffers.
2357 The numerical prefix says how frequently (in seconds) the function
2362 (gnus-stop-date-timer)
2363 (setq article-lapsed-timer
2364 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2366 (defun gnus-stop-date-timer ()
2367 "Stop the X-Sent timer."
2369 (when article-lapsed-timer
2370 (nnheader-cancel-timer article-lapsed-timer)
2371 (setq article-lapsed-timer nil)))
2373 (defun article-date-user (&optional highlight)
2374 "Convert the current article date to the user-defined format.
2375 This format is defined by the `gnus-article-time-format' variable."
2376 (interactive (list t))
2377 (article-date-ut 'user highlight))
2379 (defun article-date-iso8601 (&optional highlight)
2380 "Convert the current article date to ISO8601."
2381 (interactive (list t))
2382 (article-date-ut 'iso8601 highlight))
2384 (defun article-show-all ()
2385 "Show all hidden text in the article buffer."
2389 (let ((buffer-read-only nil))
2390 (gnus-article-unhide-text (point-min) (point-max))
2391 (gnus-remove-text-with-property 'gnus-prev)
2392 (gnus-remove-text-with-property 'gnus-next))))
2394 (defun article-show-all-headers ()
2395 "Show all hidden headers in the article buffer."
2400 (article-narrow-to-head)
2401 (let ((buffer-read-only nil))
2402 (gnus-article-unhide-text (point-min) (point-max))))))
2404 (defun article-emphasize (&optional arg)
2405 "Emphasize text according to `gnus-emphasis-alist'."
2406 (interactive (gnus-article-hidden-arg))
2407 (unless (gnus-article-check-hidden-text 'emphasis arg)
2411 (with-current-buffer gnus-summary-buffer
2412 gnus-article-emphasis-alist)
2414 gnus-emphasis-alist))
2415 (buffer-read-only nil)
2416 (props (append '(article-type emphasis)
2417 gnus-hidden-properties))
2418 regexp elem beg invisible visible face)
2421 (while (setq elem (pop alist))
2423 (setq regexp (car elem)
2424 invisible (nth 1 elem)
2425 visible (nth 2 elem)
2427 (while (re-search-forward regexp nil t)
2428 (when (and (match-beginning visible) (match-beginning invisible))
2429 (push 'emphasis gnus-article-wash-types)
2430 (gnus-article-hide-text
2431 (match-beginning invisible) (match-end invisible) props)
2432 (gnus-article-unhide-text-type
2433 (match-beginning visible) (match-end visible) 'emphasis)
2434 (gnus-put-text-property-excluding-newlines
2435 (match-beginning visible) (match-end visible) 'face face)
2436 (goto-char (match-end invisible)))))))))
2438 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2439 "Setup newsgroup emphasis alist."
2440 (unless gnus-article-emphasis-alist
2441 (let ((name (and gnus-newsgroup-name
2442 (gnus-group-real-name gnus-newsgroup-name))))
2443 (make-local-variable 'gnus-article-emphasis-alist)
2444 (setq gnus-article-emphasis-alist
2446 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2447 (while (setq elem (pop alist))
2448 (when (and name (string-match (car elem) name))
2450 highlight (copy-sequence (cdr elem)))))
2452 (copy-sequence highlight-words)
2453 (if gnus-newsgroup-name
2454 (copy-sequence (gnus-group-find-parameter
2455 gnus-newsgroup-name 'highlight-words t)))
2456 gnus-emphasis-alist)))))
2458 (defvar gnus-summary-article-menu)
2459 (defvar gnus-summary-post-menu)
2461 ;;; Saving functions.
2463 (defun gnus-article-save (save-buffer file &optional num)
2464 "Save the currently selected article."
2465 (unless gnus-save-all-headers
2466 ;; Remove headers according to `gnus-saved-headers'.
2467 (let ((gnus-visible-headers
2468 (or gnus-saved-headers gnus-visible-headers))
2469 (gnus-article-buffer save-buffer))
2471 (set-buffer save-buffer)
2472 (article-hide-headers 1 t))))
2473 (save-window-excursion
2474 (if (not gnus-default-article-saver)
2475 (error "No default saver is defined")
2476 ;; !!! Magic! The saving functions all save
2477 ;; `gnus-save-article-buffer' (or so they think), but we
2478 ;; bind that variable to our save-buffer.
2479 (set-buffer gnus-article-buffer)
2480 (let* ((gnus-save-article-buffer save-buffer)
2483 ((not gnus-prompt-before-saving) 'default)
2484 ((eq gnus-prompt-before-saving 'always) nil)
2486 (gnus-number-of-articles-to-be-saved
2487 (when (eq gnus-prompt-before-saving t)
2489 (set-buffer gnus-article-current-summary)
2490 (funcall gnus-default-article-saver filename)))))
2492 (defun gnus-read-save-file-name (prompt &optional filename
2493 function group headers variable)
2495 (funcall function group headers (symbol-value variable)))
2500 ((eq filename 'default)
2506 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2509 (if (and gnus-number-of-articles-to-be-saved
2510 (> gnus-number-of-articles-to-be-saved 1))
2511 (format "these %d articles"
2512 gnus-number-of-articles-to-be-saved)
2515 ;; Let the split methods have their say.
2517 ;; No split name was found.
2520 (concat prompt " (default "
2521 (file-name-nondirectory default-name) ") ")
2522 (file-name-directory default-name)
2524 ;; A single group name is returned.
2525 ((stringp split-name)
2527 (funcall function split-name headers
2528 (symbol-value variable)))
2530 (concat prompt " (default "
2531 (file-name-nondirectory default-name) ") ")
2532 (file-name-directory default-name)
2534 ;; A single split name was found
2535 ((= 1 (length split-name))
2536 (let* ((name (expand-file-name
2538 gnus-article-save-directory))
2539 (dir (cond ((file-directory-p name)
2540 (file-name-as-directory name))
2541 ((file-exists-p name) name)
2542 (t gnus-article-save-directory))))
2544 (concat prompt " (default " name ") ")
2546 ;; A list of splits was found.
2548 (setq split-name (nreverse split-name))
2550 (let ((file-name-history
2551 (nconc split-name file-name-history)))
2555 (concat prompt " (`M-p' for defaults) ")
2556 gnus-article-save-directory
2558 gnus-article-save-directory)))
2559 (car (push result file-name-history)))))))
2560 ;; Create the directory.
2561 (gnus-make-directory (file-name-directory file))
2562 ;; If we have read a directory, we append the default file name.
2563 (when (file-directory-p file)
2564 (setq file (expand-file-name (file-name-nondirectory
2566 (file-name-as-directory file))))
2567 ;; Possibly translate some characters.
2568 (nnheader-translate-file-chars file))))))
2569 (gnus-make-directory (file-name-directory result))
2570 (set variable result)))
2572 (defun gnus-article-archive-name (group)
2573 "Return the first instance of an \"Archive-name\" in the current buffer."
2574 (let ((case-fold-search t))
2575 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2576 (nnheader-concat gnus-article-save-directory
2577 (match-string 1)))))
2579 (defun gnus-article-nndoc-name (group)
2580 "If GROUP is an nndoc group, return the name of the parent group."
2581 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2582 (gnus-group-get-parameter group 'save-article-group)))
2584 (defun gnus-summary-save-in-rmail (&optional filename)
2585 "Append this article to Rmail file.
2586 Optional argument FILENAME specifies file name.
2587 Directory to save to is default to `gnus-article-save-directory'."
2588 (setq filename (gnus-read-save-file-name
2589 "Save %s in rmail file:" filename
2590 gnus-rmail-save-name gnus-newsgroup-name
2591 gnus-current-headers 'gnus-newsgroup-last-rmail))
2592 (gnus-eval-in-buffer-window gnus-save-article-buffer
2596 (gnus-output-to-rmail filename))))
2599 (defun gnus-summary-save-in-mail (&optional filename)
2600 "Append this article to Unix mail file.
2601 Optional argument FILENAME specifies file name.
2602 Directory to save to is default to `gnus-article-save-directory'."
2603 (setq filename (gnus-read-save-file-name
2604 "Save %s in Unix mail file:" filename
2605 gnus-mail-save-name gnus-newsgroup-name
2606 gnus-current-headers 'gnus-newsgroup-last-mail))
2607 (gnus-eval-in-buffer-window gnus-save-article-buffer
2611 (if (and (file-readable-p filename)
2612 (mail-file-babyl-p filename))
2613 (rmail-output-to-rmail-file filename t)
2614 (gnus-output-to-mail filename)))))
2617 (defun gnus-summary-save-in-file (&optional filename overwrite)
2618 "Append this article to file.
2619 Optional argument FILENAME specifies file name.
2620 Directory to save to is default to `gnus-article-save-directory'."
2621 (setq filename (gnus-read-save-file-name
2622 "Save %s in file:" filename
2623 gnus-file-save-name gnus-newsgroup-name
2624 gnus-current-headers 'gnus-newsgroup-last-file))
2625 (gnus-eval-in-buffer-window gnus-save-article-buffer
2629 (when (and overwrite
2630 (file-exists-p filename))
2631 (delete-file filename))
2632 (gnus-output-to-file filename))))
2635 (defun gnus-summary-write-to-file (&optional filename)
2636 "Write this article to a file.
2637 Optional argument FILENAME specifies file name.
2638 The directory to save in defaults to `gnus-article-save-directory'."
2639 (gnus-summary-save-in-file nil t))
2641 (defun gnus-summary-save-body-in-file (&optional filename)
2642 "Append this article body to a file.
2643 Optional argument FILENAME specifies file name.
2644 The directory to save in defaults to `gnus-article-save-directory'."
2645 (setq filename (gnus-read-save-file-name
2646 "Save %s body in file:" filename
2647 gnus-file-save-name gnus-newsgroup-name
2648 gnus-current-headers 'gnus-newsgroup-last-file))
2649 (gnus-eval-in-buffer-window gnus-save-article-buffer
2653 (when (article-goto-body)
2654 (narrow-to-region (point) (point-max)))
2655 (gnus-output-to-file filename))))
2658 (defun gnus-summary-save-in-pipe (&optional command)
2659 "Pipe this article to subprocess."
2661 (cond ((and (eq command 'default)
2662 gnus-last-shell-command)
2663 gnus-last-shell-command)
2667 "Shell command on %s: "
2668 (if (and gnus-number-of-articles-to-be-saved
2669 (> gnus-number-of-articles-to-be-saved 1))
2670 (format "these %d articles"
2671 gnus-number-of-articles-to-be-saved)
2673 gnus-last-shell-command))))
2674 (when (string-equal command "")
2675 (setq command gnus-last-shell-command))
2676 (gnus-eval-in-buffer-window gnus-article-buffer
2679 (shell-command-on-region (point-min) (point-max) command nil)))
2680 (setq gnus-last-shell-command command))
2682 ;;; Article file names when saving.
2684 (defun gnus-capitalize-newsgroup (newsgroup)
2685 "Capitalize NEWSGROUP name."
2686 (when (not (zerop (length newsgroup)))
2687 (concat (char-to-string (upcase (aref newsgroup 0)))
2688 (substring newsgroup 1))))
2690 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2691 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2692 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2693 Otherwise, it is like ~/News/news/group/num."
2696 (concat (if (gnus-use-long-file-name 'not-save)
2697 (gnus-capitalize-newsgroup newsgroup)
2698 (gnus-newsgroup-directory-form newsgroup))
2699 "/" (int-to-string (mail-header-number headers)))
2700 gnus-article-save-directory)))
2702 (string-equal (file-name-directory default)
2703 (file-name-directory last-file))
2704 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2706 (or last-file default))))
2708 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2709 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2710 If variable `gnus-use-long-file-name' is non-nil, it is
2711 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2714 (concat (if (gnus-use-long-file-name 'not-save)
2716 (gnus-newsgroup-directory-form newsgroup))
2717 "/" (int-to-string (mail-header-number headers)))
2718 gnus-article-save-directory)))
2720 (string-equal (file-name-directory default)
2721 (file-name-directory last-file))
2722 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2724 (or last-file default))))
2726 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2727 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2728 If variable `gnus-use-long-file-name' is non-nil, it is
2729 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2732 (if (gnus-use-long-file-name 'not-save)
2734 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2735 gnus-article-save-directory)))
2742 (setq afunc (car func)
2745 gfunc (intern (format "gnus-%s" func))))
2748 `(lambda (&optional interactive &rest args)
2749 ,(documentation afunc t)
2750 (interactive (list t))
2752 (set-buffer gnus-article-buffer)
2754 (call-interactively ',afunc)
2755 (apply ',afunc args))))))))
2756 '(article-hide-headers
2757 article-hide-boring-headers
2758 article-toggle-headers
2759 article-treat-overstrike
2760 article-fill-long-lines
2761 article-capitalize-sentences
2763 article-display-x-face
2764 article-de-quoted-unreadable
2765 article-de-base64-unreadable
2768 article-hide-list-identifiers
2770 article-strip-banner
2773 article-hide-signature
2774 article-strip-headers-in-body
2775 article-remove-trailing-blank-lines
2776 article-strip-leading-blank-lines
2777 article-strip-multiple-blank-lines
2778 article-strip-leading-space
2779 article-strip-trailing-space
2780 article-strip-blank-lines
2781 article-strip-all-blank-lines
2783 article-date-iso8601
2784 article-date-original
2786 article-decode-mime-words
2787 article-decode-charset
2788 article-decode-encoded-words
2792 article-treat-dumbquotes
2793 article-normalize-headers
2794 (article-show-all-headers . gnus-article-show-all-headers)
2795 (article-show-all . gnus-article-show-all))))
2798 ;;; Gnus article mode
2801 (put 'gnus-article-mode 'mode-class 'special)
2803 (gnus-define-keys gnus-article-mode-map
2804 " " gnus-article-goto-next-page
2805 "\177" gnus-article-goto-prev-page
2806 [delete] gnus-article-goto-prev-page
2807 [backspace] gnus-article-goto-prev-page
2808 "\C-c^" gnus-article-refer-article
2809 "h" gnus-article-show-summary
2810 "s" gnus-article-show-summary
2811 "\C-c\C-m" gnus-article-mail
2812 "?" gnus-article-describe-briefly
2813 "e" gnus-summary-edit-article
2814 "<" beginning-of-buffer
2816 "\C-c\C-i" gnus-info-find-node
2819 "\C-d" gnus-article-read-summary-keys
2820 "\M-*" gnus-article-read-summary-keys
2821 "\M-#" gnus-article-read-summary-keys
2822 "\M-^" gnus-article-read-summary-keys
2823 "\M-g" gnus-article-read-summary-keys)
2825 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2828 (unless (lookup-key gnus-article-mode-map key)
2829 (define-key gnus-article-mode-map key
2830 'gnus-article-read-summary-keys)))
2835 (let ((key (car elt)))
2836 (and (> (length key) 0)
2837 (not (eq 'menu-bar (aref key 0)))
2838 (symbolp (lookup-key gnus-summary-mode-map key))
2840 (accessible-keymaps gnus-summary-mode-map))
2844 (push (char-to-string c) keys)
2848 (defun gnus-article-make-menu-bar ()
2849 (gnus-turn-off-edit-menu 'article)
2850 (unless (boundp 'gnus-article-article-menu)
2852 gnus-article-article-menu gnus-article-mode-map ""
2854 ["Scroll forwards" gnus-article-goto-next-page t]
2855 ["Scroll backwards" gnus-article-goto-prev-page t]
2856 ["Show summary" gnus-article-show-summary t]
2857 ["Fetch Message-ID at point" gnus-article-refer-article t]
2858 ["Mail to address at point" gnus-article-mail t]
2859 ["Send a bug report" gnus-bug t]))
2862 gnus-article-treatment-menu gnus-article-mode-map ""
2864 ["Hide headers" gnus-article-toggle-headers t]
2865 ["Hide signature" gnus-article-hide-signature t]
2866 ["Hide citation" gnus-article-hide-citation t]
2867 ["Treat overstrike" gnus-article-treat-overstrike t]
2868 ["Remove carriage return" gnus-article-remove-cr t]
2869 ["Decode HZ" gnus-article-decode-HZ t]))
2871 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2873 (when (boundp 'gnus-summary-post-menu)
2874 (define-key gnus-article-mode-map [menu-bar post]
2875 (cons "Post" gnus-summary-post-menu)))
2877 (gnus-run-hooks 'gnus-article-menu-hook)))
2879 (defun gnus-article-mode ()
2880 "Major mode for displaying an article.
2882 All normal editing commands are switched off.
2884 The following commands are available in addition to all summary mode
2886 \\<gnus-article-mode-map>
2887 \\[gnus-article-next-page]\t Scroll the article one page forwards
2888 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2889 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2890 \\[gnus-article-show-summary]\t Display the summary buffer
2891 \\[gnus-article-mail]\t Send a reply to the address near point
2892 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2893 \\[gnus-info-find-node]\t Go to the Gnus info node"
2895 (when (gnus-visual-p 'article-menu 'menu)
2896 (gnus-article-make-menu-bar))
2897 (gnus-simplify-mode-line)
2898 (setq mode-name "Article")
2899 (setq major-mode 'gnus-article-mode)
2900 (make-local-variable 'minor-mode-alist)
2901 (unless (assq 'gnus-show-mime minor-mode-alist)
2902 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2903 (use-local-map gnus-article-mode-map)
2904 (gnus-update-format-specifications nil 'article-mode)
2905 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2906 (make-local-variable 'gnus-page-broken)
2907 (make-local-variable 'gnus-button-marker-list)
2908 (make-local-variable 'gnus-article-current-summary)
2909 (make-local-variable 'gnus-article-mime-handles)
2910 (make-local-variable 'gnus-article-decoded-p)
2911 (make-local-variable 'gnus-article-mime-handle-alist)
2912 (make-local-variable 'gnus-article-wash-types)
2913 (make-local-variable 'gnus-article-charset)
2914 (make-local-variable 'gnus-article-ignored-charsets)
2915 (gnus-set-default-directory)
2916 (buffer-disable-undo)
2917 (setq buffer-read-only t)
2918 (set-syntax-table gnus-article-mode-syntax-table)
2919 (gnus-run-hooks 'gnus-article-mode-hook))
2921 (defun gnus-article-setup-buffer ()
2922 "Initialize the article buffer."
2923 (let* ((name (if gnus-single-article-buffer "*Article*"
2924 (concat "*Article " gnus-newsgroup-name "*")))
2926 (progn (string-match "\\*Article" name)
2927 (concat " *Original Article"
2928 (substring name (match-end 0))))))
2929 (setq gnus-article-buffer name)
2930 (setq gnus-original-article-buffer original)
2931 (setq gnus-article-mime-handle-alist nil)
2932 ;; This might be a variable local to the summary buffer.
2933 (unless gnus-single-article-buffer
2935 (set-buffer gnus-summary-buffer)
2936 (setq gnus-article-buffer name)
2937 (setq gnus-original-article-buffer original)
2938 (gnus-set-global-variables)))
2939 (gnus-article-setup-highlight-words)
2940 ;; Init original article buffer.
2942 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2943 (set-buffer-multibyte nil)
2944 (setq major-mode 'gnus-original-article-mode)
2945 (make-local-variable 'gnus-original-article))
2946 (if (get-buffer name)
2949 (buffer-disable-undo)
2950 (setq buffer-read-only t)
2951 (unless (eq major-mode 'gnus-article-mode)
2952 (gnus-article-mode))
2955 (set-buffer (gnus-get-buffer-create name))
2957 (make-local-variable 'gnus-summary-buffer)
2958 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2959 (current-buffer)))))
2961 ;; Set article window start at LINE, where LINE is the number of lines
2962 ;; from the head of the article.
2963 (defun gnus-article-set-window-start (&optional line)
2965 (get-buffer-window gnus-article-buffer t)
2967 (set-buffer gnus-article-buffer)
2968 (goto-char (point-min))
2971 (gnus-message 6 "Moved to bookmark")
2972 (search-forward "\n\n" nil t)
2976 ;;; @@ article filters
2979 (defun gnus-article-display-mime-message ()
2980 "Article display method for MIME message."
2981 ;; called from `gnus-original-article-buffer'.
2982 (let (charset all-headers)
2983 (with-current-buffer gnus-summary-buffer
2984 (setq charset default-mime-charset
2985 all-headers gnus-have-all-headers))
2986 (make-local-variable 'default-mime-charset)
2987 (setq default-mime-charset charset)
2988 (with-current-buffer (get-buffer-create gnus-article-buffer)
2989 (make-local-variable 'default-mime-charset)
2990 (setq default-mime-charset charset))
2991 (mime-display-message mime-message-structure
2992 gnus-article-buffer nil gnus-article-mode-map)
2994 (gnus-article-hide-headers nil -1)))
2995 (run-hooks 'gnus-mime-article-prepare-hook))
2997 (defun gnus-article-display-traditional-message ()
2998 "Article display method for traditional message."
2999 (set-buffer gnus-article-buffer)
3000 (let (buffer-read-only)
3002 (insert-buffer-substring gnus-original-article-buffer)))
3004 (defun gnus-article-make-full-mail-header (&optional number charset)
3005 "Create a new mail header structure in a raw article buffer."
3006 (unless (and number charset)
3007 (save-current-buffer
3008 (set-buffer gnus-summary-buffer)
3010 (setq number (or (cdr gnus-article-current) 0)))
3012 (setq charset (or default-mime-charset 'x-ctext)))))
3013 (goto-char (point-min))
3014 (let ((header-end (if (search-forward "\n\n" nil t)
3016 (goto-char (point-max))))
3017 (chars (- (point-max) (point)))
3018 (lines (count-lines (point) (point-max)))
3019 (default-mime-charset charset)
3021 (narrow-to-region (point-min) header-end)
3022 (setq xref (std11-fetch-field "xref"))
3024 (make-full-mail-header
3026 (std11-fetch-field "subject")
3027 (std11-fetch-field "from")
3028 (std11-fetch-field "date")
3029 (std11-fetch-field "message-id")
3030 (std11-fetch-field "references")
3033 (when xref (concat "Xref: " xref)))
3036 (defun gnus-article-prepare (article &optional all-headers header)
3037 "Prepare ARTICLE in article mode buffer.
3038 ARTICLE should either be an article number or a Message-ID.
3039 If ARTICLE is an id, HEADER should be the article headers.
3040 If ALL-HEADERS is non-nil, no headers are hidden."
3042 ;; Make sure we start in a summary buffer.
3043 (unless (eq major-mode 'gnus-summary-mode)
3044 (set-buffer gnus-summary-buffer))
3045 (setq gnus-summary-buffer (current-buffer))
3046 (let* ((gnus-article (if header (mail-header-number header) article))
3047 (summary-buffer (current-buffer))
3048 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3049 (group gnus-newsgroup-name)
3052 (gnus-article-setup-buffer)
3053 (set-buffer gnus-original-article-buffer)
3054 ;; Deactivate active regions.
3055 (when (and (boundp 'transient-mark-mode)
3056 transient-mark-mode)
3057 (setq mark-active nil))
3058 (if (not (setq result (let ((buffer-read-only nil))
3059 (gnus-request-article-this-buffer
3061 ;; There is no such article.
3063 (when (and (numberp article)
3064 (not (memq article gnus-newsgroup-sparse)))
3065 (setq gnus-article-current
3066 (cons gnus-newsgroup-name article))
3067 (set-buffer gnus-summary-buffer)
3068 (setq gnus-current-article article)
3069 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3071 (gnus-summary-set-agent-mark article)
3072 (message "Message marked for downloading"))
3073 (gnus-summary-mark-article article gnus-canceled-mark)
3074 (unless (memq article gnus-newsgroup-sparse)
3075 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3076 (if (or (eq result 'pseudo)
3077 (eq result 'nneething))
3080 (set-buffer summary-buffer)
3081 (push article gnus-newsgroup-history)
3082 (setq gnus-last-article gnus-current-article
3083 gnus-current-article 0
3084 gnus-current-headers nil
3085 gnus-article-current nil)
3086 (if (eq result 'nneething)
3087 (gnus-configure-windows 'summary)
3088 (gnus-configure-windows 'article))
3089 (gnus-set-global-variables))
3090 (let ((gnus-article-mime-handle-alist-1
3091 gnus-article-mime-handle-alist))
3092 (gnus-set-mode-line 'article)))
3093 ;; The result from the `request' was an actual article -
3094 ;; or at least some text that is now displayed in the
3096 (when (and (numberp article)
3097 (not (eq article gnus-current-article)))
3098 ;; Seems like a new article has been selected.
3099 ;; `gnus-current-article' must be an article number.
3101 (set-buffer summary-buffer)
3102 (push article gnus-newsgroup-history)
3103 (setq gnus-last-article gnus-current-article
3104 gnus-current-article article
3105 gnus-current-headers
3106 (gnus-summary-article-header gnus-current-article)
3107 gnus-article-current
3108 (cons gnus-newsgroup-name gnus-current-article))
3109 (unless (vectorp gnus-current-headers)
3110 (setq gnus-current-headers nil))
3111 (gnus-summary-goto-subject gnus-current-article)
3112 (when (gnus-summary-show-thread)
3113 ;; If the summary buffer really was folded, the
3114 ;; previous goto may not actually have gone to
3115 ;; the right article, but the thread root instead.
3117 (gnus-summary-goto-subject gnus-current-article))
3118 (gnus-run-hooks 'gnus-mark-article-hook)
3119 (gnus-set-mode-line 'summary)
3120 (when (gnus-visual-p 'article-highlight 'highlight)
3121 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3122 ;; Set the global newsgroup variables here.
3123 (gnus-set-global-variables)
3124 (setq gnus-have-all-headers
3125 (or all-headers gnus-show-all-headers))))
3127 (gnus-configure-windows 'article))
3128 (when (or (numberp article)
3130 (gnus-article-prepare-display)
3132 (goto-char (point-min))
3133 (setq gnus-page-broken
3134 (when gnus-break-pages
3135 (gnus-narrow-to-page)
3137 (let ((gnus-article-mime-handle-alist-1
3138 gnus-article-mime-handle-alist))
3139 (gnus-set-mode-line 'article))
3141 (set-window-point (get-buffer-window (current-buffer)) (point))
3142 (gnus-configure-windows 'article)
3145 (defun gnus-article-prepare-mime-display (&optional number)
3146 (goto-char (point-min))
3147 (when (re-search-forward "^[^\t ]+:" nil t)
3148 (goto-char (match-beginning 0)))
3149 (let ((entity (if (eq 1 (point-min))
3150 (get-text-property 1 'mime-view-entity)
3151 (get-text-property (point) 'mime-view-entity)))
3152 last-entity child-entity next type)
3153 (setq child-entity (mime-entity-children entity))
3155 (setq last-entity (nth (1- (length child-entity))
3157 (setq last-entity entity))
3159 (narrow-to-region (point)
3160 (if (search-forward "\n\n" nil t)
3163 (gnus-treat-article 'head)
3164 (put-text-property (point-min) (point-max) 'article-treated-header t)
3165 (goto-char (point-max)))
3166 (while (and (not (eobp)) entity)
3167 (setq next (set-marker
3169 (next-single-property-change (point) 'mime-view-entity
3171 (let ((types (mime-entity-content-type entity)))
3172 (while (eq 'multipart (mime-content-type-primary-type types))
3173 (setq entity (car (mime-entity-children entity))
3174 types (mime-entity-content-type entity)))
3176 (setq type (format "%s/%s"
3177 (mime-content-type-primary-type types)
3178 (mime-content-type-subtype types)))))
3179 (if (string-equal type "message/rfc822")
3182 (let ((children (mime-entity-children entity))
3185 (setq last-children (nth (1- (length children)) children))
3188 (not (eq last-children
3189 (get-text-property next 'mime-view-entity)))
3191 (next-single-property-change next
3193 nil (point-max)))))))
3194 (setq next (next-single-property-change next 'mime-view-entity
3197 (narrow-to-region (point) next)
3198 (gnus-article-prepare-mime-display)
3199 (goto-char (point-max)))
3200 (setq entity (get-text-property (point) 'mime-view-entity)))
3202 (narrow-to-region (point) next)
3203 ;; Kludge. We have to count true number, but for now,
3204 ;; part number is here only to achieve `last'.
3205 (gnus-treat-article nil 1
3206 (if (eq entity last-entity)
3209 (goto-char (point-max)))
3210 (setq entity (get-text-property next 'mime-view-entity))))))
3213 (defun gnus-article-prepare-display ()
3214 "Make the current buffer look like a nice article."
3215 (setq gnus-article-wash-types nil)
3216 (gnus-run-hooks 'gnus-tmp-internal-hook)
3217 (gnus-run-hooks 'gnus-article-prepare-hook)
3219 (let (mime-display-header-hook mime-display-text/plain-hook)
3220 (funcall (if gnus-show-mime
3222 (setq mime-message-structure gnus-current-headers)
3223 (mime-buffer-entity-set-buffer-internal
3224 mime-message-structure
3225 gnus-original-article-buffer)
3226 (mime-entity-set-representation-type-internal
3227 mime-message-structure 'mime-buffer-entity)
3228 (luna-send mime-message-structure
3229 'initialize-instance
3230 mime-message-structure)
3231 gnus-article-display-method-for-mime)
3232 gnus-article-display-method-for-traditional)))
3233 ;; Associate this article with the current summary buffer.
3234 (setq gnus-article-current-summary gnus-summary-buffer)
3235 ;; Call the treatment functions.
3236 (let ((inhibit-read-only t)
3241 (gnus-article-prepare-mime-display)
3242 (narrow-to-region (goto-char (point-min))
3243 (if (search-forward "\n\n" nil t)
3246 (gnus-treat-article 'head)
3247 (put-text-property (point-min) (point-max) 'article-treated-header t)
3248 (goto-char (point-max))
3250 (narrow-to-region (point) (point-max))
3251 (gnus-treat-article nil))
3252 (put-text-property (point-min) (point-max) 'read-only nil)))
3253 ;; Perform the article display hooks. Incidentally, this hook is
3254 ;; an obsolete variable by now.
3255 (gnus-run-hooks 'gnus-article-display-hook))
3257 (defun gnus-article-decode-article-as-default-mime-charset ()
3258 "Decode an article as `default-mime-charset'. It won't work if the
3259 value of the variable `gnus-show-mime' is non-nil."
3260 (unless gnus-show-mime
3261 (decode-mime-charset-region (point-min) (point-max)
3262 (with-current-buffer gnus-summary-buffer
3263 default-mime-charset))))
3266 ;;; Gnus MIME viewing functions
3269 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3270 "The following specs can be used:
3272 %T MIME type, along with additional info
3273 %n The `name' parameter
3274 %d The description, if any
3275 %l The length of the encoded part
3276 %p The part identifier number
3277 %e Dots if the part isn't displayed")
3279 (defvar gnus-mime-button-line-format-alist
3280 '((?t gnus-tmp-type ?s)
3281 (?T gnus-tmp-type-long ?s)
3282 (?n gnus-tmp-name ?s)
3283 (?d gnus-tmp-description ?s)
3285 (?l gnus-tmp-length ?d)
3286 (?e gnus-tmp-dots ?s)))
3288 (defvar gnus-mime-button-commands
3289 '((gnus-article-press-button "\r" "Toggle Display")
3290 (gnus-mime-view-part "v" "View Interactively...")
3291 (gnus-mime-view-part-as-type "t" "View As Type...")
3292 (gnus-mime-save-part "o" "Save...")
3293 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3294 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3295 (gnus-mime-internalize-part "E" "View Internally")
3296 (gnus-mime-externalize-part "e" "View Externally")
3297 (gnus-mime-pipe-part "|" "Pipe To Command...")
3298 (gnus-mime-action-on-part "." "Take action on the part")))
3300 (defun gnus-article-mime-part-status ()
3301 (with-current-buffer gnus-article-buffer
3302 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3303 (if (and entity (mime-entity-children entity))
3304 (format " (%d parts)" (length (mime-entity-children entity)))
3307 (defvar gnus-mime-button-map
3308 (let ((map (make-sparse-keymap)))
3309 (set-keymap-parent map gnus-article-mode-map)
3310 (define-key map gnus-mouse-2 'gnus-article-push-button)
3311 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3312 (dolist (c gnus-mime-button-commands)
3313 (define-key map (cadr c) (car c)))
3316 (defun gnus-mime-button-menu (event)
3317 "Construct a context-sensitive menu of MIME commands."
3320 (let ((pos (event-start event)))
3321 (set-buffer (window-buffer (posn-window pos)))
3322 (goto-char (posn-point pos))
3323 (gnus-article-check-buffer)
3324 (let ((response (x-popup-menu
3326 ("" ,@(mapcar (lambda (c)
3327 (cons (caddr c) (car c)))
3328 gnus-mime-button-commands))))))
3330 (call-interactively response))))))
3332 (defun gnus-mime-view-all-parts (&optional handles)
3333 "View all the MIME parts."
3335 (save-current-buffer
3336 (set-buffer gnus-article-buffer)
3337 (let ((handles (or handles gnus-article-mime-handles))
3338 (mail-parse-charset gnus-newsgroup-charset)
3339 (mail-parse-ignored-charsets
3340 (save-excursion (set-buffer gnus-summary-buffer)
3341 gnus-newsgroup-ignored-charsets)))
3342 (if (stringp (car handles))
3343 (gnus-mime-view-all-parts (cdr handles))
3344 (mapcar 'mm-display-part handles)))))
3346 (defun gnus-mime-save-part ()
3347 "Save the MIME part under point."
3349 (gnus-article-check-buffer)
3350 (let ((data (get-text-property (point) 'gnus-data)))
3351 (mm-save-part data)))
3353 (defun gnus-mime-pipe-part ()
3354 "Pipe the MIME part under point to a process."
3356 (gnus-article-check-buffer)
3357 (let ((data (get-text-property (point) 'gnus-data)))
3358 (mm-pipe-part data)))
3360 (defun gnus-mime-view-part ()
3361 "Interactively choose a viewing method for the MIME part under point."
3363 (gnus-article-check-buffer)
3364 (let ((data (get-text-property (point) 'gnus-data)))
3365 (mm-interactively-view-part data)))
3367 (defun gnus-mime-view-part-as-type-internal ()
3368 (gnus-article-check-buffer)
3369 (let* ((name (mail-content-type-get
3370 (mm-handle-type (get-text-property (point) 'gnus-data))
3372 (def-type (and name (mm-default-file-encoding name))))
3373 (and def-type (cons def-type 0))))
3375 (defun gnus-mime-view-part-as-type (mime-type)
3376 "Choose a MIME media type, and view the part as such."
3378 (list (completing-read
3379 "View as MIME type: "
3380 (mapcar #'list (mailcap-mime-types))
3382 (gnus-mime-view-part-as-type-internal))))
3383 (gnus-article-check-buffer)
3384 (let ((handle (get-text-property (point) 'gnus-data)))
3385 (gnus-mm-display-part
3386 (mm-make-handle (mm-handle-buffer handle)
3387 (cons mime-type (cdr (mm-handle-type handle)))
3388 (mm-handle-encoding handle)
3389 (mm-handle-undisplayer handle)
3390 (mm-handle-disposition handle)
3391 (mm-handle-description handle)
3392 (mm-handle-cache handle)
3393 (mm-handle-id handle)))))
3395 (defun gnus-mime-copy-part (&optional handle)
3396 "Put the the MIME part under point into a new buffer."
3398 (gnus-article-check-buffer)
3399 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3400 (contents (mm-get-part handle))|
3401 (base (file-name-nondirectory
3403 (mail-content-type-get (mm-handle-type handle) 'name)
3404 (mail-content-type-get (mm-handle-type handle)
3407 (buffer (generate-new-buffer base)))
3408 (switch-to-buffer buffer)
3410 ;; We do it this way to make `normal-mode' set the appropriate mode.
3413 (setq buffer-file-name (expand-file-name base))
3415 (setq buffer-file-name nil))
3416 (goto-char (point-min))))
3418 (defun gnus-mime-inline-part (&optional handle arg)
3419 "Insert the MIME part under point into the current buffer."
3420 (interactive (list nil current-prefix-arg))
3421 (gnus-article-check-buffer)
3422 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3426 (if (mm-handle-undisplayer handle)
3427 (mm-remove-part handle)
3428 (setq contents (mm-get-part handle))
3431 (setq charset (or (mail-content-type-get
3432 (mm-handle-type handle) 'charset)
3433 gnus-newsgroup-charset)))
3437 gnus-summary-show-article-charset-alist))
3438 (read-coding-system "Charset: ")))))
3440 (mm-insert-inline handle
3442 (setq charset (mm-charset-to-coding-system
3444 (not (eq charset 'ascii)))
3445 (mm-decode-coding-string contents charset)
3449 (defun gnus-mime-externalize-part (&optional handle)
3450 "View the MIME part under point with an external viewer."
3452 (gnus-article-check-buffer)
3453 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3454 (mm-user-display-methods nil)
3455 (mm-inlined-types nil)
3456 (mail-parse-charset gnus-newsgroup-charset)
3457 (mail-parse-ignored-charsets
3458 (save-excursion (set-buffer gnus-summary-buffer)
3459 gnus-newsgroup-ignored-charsets)))
3460 (if (mm-handle-undisplayer handle)
3461 (mm-remove-part handle)
3462 (mm-display-part handle))))
3464 (defun gnus-mime-internalize-part (&optional handle)
3465 "View the MIME part under point with an internal viewer.
3466 In no internal viewer is available, use an external viewer."
3468 (gnus-article-check-buffer)
3469 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3470 (mm-inlined-types '(".*"))
3471 (mm-inline-large-images t)
3472 (mail-parse-charset gnus-newsgroup-charset)
3473 (mail-parse-ignored-charsets
3474 (save-excursion (set-buffer gnus-summary-buffer)
3475 gnus-newsgroup-ignored-charsets)))
3476 (if (mm-handle-undisplayer handle)
3477 (mm-remove-part handle)
3478 (mm-display-part handle))))
3480 (defun gnus-mime-action-on-part (&optional action)
3481 "Do something with the MIME attachment at \(point\)."
3483 (list (completing-read "Action: " gnus-mime-action-alist)))
3484 (gnus-article-check-buffer)
3485 (let ((action-pair (assoc action gnus-mime-action-alist)))
3487 (funcall (cdr action-pair)))))
3490 (defun gnus-article-part-wrapper (n function)
3491 (save-current-buffer
3492 (set-buffer gnus-article-buffer)
3493 (when (> n (length gnus-article-mime-handle-alist))
3494 (error "No such part"))
3495 (gnus-article-goto-part n)
3496 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3497 (funcall function handle))))
3499 (defun gnus-article-pipe-part (n)
3500 "Pipe MIME part N, which is the numerical prefix."
3502 (gnus-article-part-wrapper n 'mm-pipe-part))
3504 (defun gnus-article-save-part (n)
3505 "Save MIME part N, which is the numerical prefix."
3507 (gnus-article-part-wrapper n 'mm-save-part))
3509 (defun gnus-article-interactively-view-part (n)
3510 "View MIME part N interactively, which is the numerical prefix."
3512 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3514 (defun gnus-article-copy-part (n)
3515 "Copy MIME part N, which is the numerical prefix."
3517 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3519 (defun gnus-article-externalize-part (n)
3520 "View MIME part N externally, which is the numerical prefix."
3522 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3524 (defun gnus-article-inline-part (n)
3525 "Inline MIME part N, which is the numerical prefix."
3527 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3529 (defun gnus-article-mime-match-handle-first (condition)
3531 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3532 (while (setq ihandle (pop alist))
3534 ((functionp condition)
3535 (funcall condition (cdr ihandle)))
3536 ((eq condition 'undisplayed)
3537 (not (or (mm-handle-undisplayer (cdr ihandle))
3538 (equal (mm-handle-media-type (cdr ihandle))
3539 "multipart/alternative"))))
3540 ((eq condition 'undisplayed-alternative)
3541 (not (mm-handle-undisplayer (cdr ihandle))))
3543 (gnus-article-goto-part (car ihandle))
3544 (or (not n) (< (car ihandle) n)))
3545 (setq n (car ihandle))))
3549 (defun gnus-article-view-part (&optional n)
3550 "View MIME part N, which is the numerical prefix."
3552 (save-current-buffer
3553 (set-buffer gnus-article-buffer)
3554 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3555 gnus-article-mime-match-handle-function)))
3556 (when (> n (length gnus-article-mime-handle-alist))
3557 (error "No such part"))
3558 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3559 (when (gnus-article-goto-part n)
3560 (if (equal (car handle) "multipart/alternative")
3561 (gnus-article-press-button)
3562 (when (eq (gnus-mm-display-part handle) 'internal)
3563 (gnus-set-window-start)))))))
3565 (defsubst gnus-article-mime-total-parts ()
3566 (if (bufferp (car gnus-article-mime-handles))
3568 (1- (length gnus-article-mime-handles))))
3570 (defun gnus-mm-display-part (handle)
3571 "Display HANDLE and fix MIME button."
3572 (let ((id (get-text-property (point) 'gnus-part))
3577 (let ((window (selected-window))
3578 (mail-parse-charset gnus-newsgroup-charset)
3579 (mail-parse-ignored-charsets
3580 (save-excursion (set-buffer gnus-summary-buffer)
3581 gnus-newsgroup-ignored-charsets)))
3584 (let ((win (get-buffer-window (current-buffer) t))
3587 (select-window win))
3590 (if (mm-handle-displayed-p handle)
3591 ;; This will remove the part.
3592 (mm-display-part handle)
3594 (narrow-to-region (point) (1+ (point)))
3595 (mm-display-part handle)
3596 ;; We narrow to the part itself and
3597 ;; then call the treatment functions.
3598 (goto-char (point-min))
3600 (narrow-to-region (point) (point-max))
3603 (gnus-article-mime-total-parts)
3604 (mm-handle-media-type handle)))))
3605 (select-window window))))
3607 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3608 (gnus-insert-mime-button
3609 handle id (list (mm-handle-displayed-p handle)))
3610 (goto-char point))))
3612 (defun gnus-article-goto-part (n)
3613 "Go to MIME part N."
3614 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3616 (goto-char point))))
3618 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3619 (let ((gnus-tmp-name
3620 (or (mail-content-type-get (mm-handle-type handle)
3622 (mail-content-type-get (mm-handle-disposition handle)
3625 (gnus-tmp-type (mm-handle-media-type handle))
3626 (gnus-tmp-description
3627 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3630 (if (if displayed (car displayed)
3631 (mm-handle-displayed-p handle))
3633 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3635 gnus-tmp-type-long b e)
3636 (when (string-match ".*/" gnus-tmp-name)
3637 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3638 (setq gnus-tmp-type-long (concat gnus-tmp-type
3639 (and (not (equal gnus-tmp-name ""))
3640 (concat "; " gnus-tmp-name))))
3641 (or (equal gnus-tmp-description "")
3642 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3647 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3648 `(local-map ,gnus-mime-button-map
3649 keymap ,gnus-mime-button-map
3650 gnus-callback gnus-mm-display-part
3651 gnus-part ,gnus-tmp-id
3652 article-type annotation
3655 (widget-convert-button
3658 :action 'gnus-widget-press-button
3659 :button-keymap gnus-mime-button-map
3661 (lambda (widget/window &optional overlay pos)
3662 ;; Needed to properly clear the message due to a bug in
3663 ;; wid-edit (XEmacs only).
3664 (if (boundp 'help-echo-owns-message)
3665 (setq help-echo-owns-message t))
3667 "%S: %s the MIME part; %S: more options"
3668 (aref gnus-mouse-2 0)
3669 ;; XEmacs will get a single widget arg; Emacs 21 will get
3670 ;; window, overlay, position.
3671 (if (mm-handle-displayed-p
3673 (with-current-buffer (gnus-overlay-buffer overlay)
3674 (widget-get (widget-at (gnus-overlay-start overlay))
3676 (widget-get widget/window :mime-handle)))
3678 (aref gnus-down-mouse-3 0))))))
3680 (defun gnus-widget-press-button (elems el)
3681 (goto-char (widget-get elems :from))
3682 (gnus-article-press-button))
3684 (defvar gnus-displaying-mime nil)
3686 (defun gnus-display-mime (&optional ihandles)
3687 "Display the MIME parts."
3689 (save-selected-window
3690 (let ((window (get-buffer-window gnus-article-buffer))
3693 (select-window window)
3694 ;; We have to do this since selecting the window
3695 ;; may change the point. So we set the window point.
3696 (set-window-point window point)))
3697 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3698 buffer-read-only handle name type b e display)
3699 (when (and (not ihandles)
3700 (not gnus-displaying-mime))
3701 ;; Top-level call; we clean up.
3702 (when gnus-article-mime-handles
3703 (mm-destroy-parts gnus-article-mime-handles)
3704 (setq gnus-article-mime-handle-alist nil));; A trick.
3705 (setq gnus-article-mime-handles handles)
3706 ;; We allow users to glean info from the handles.
3707 (when gnus-article-mime-part-function
3708 (gnus-mime-part-function handles)))
3710 (or (not (stringp (car handles)))
3713 (when (and (not ihandles)
3714 (not gnus-displaying-mime))
3715 ;; Clean up for mime parts.
3717 (delete-region (point) (point-max)))
3718 (let ((gnus-displaying-mime t))
3719 (gnus-mime-display-part handles)))
3722 (narrow-to-region (point) (point-max))
3723 (gnus-treat-article nil 1 1)
3726 ;; Highlight the headers.
3730 (narrow-to-region (point-min) (point))
3731 (gnus-treat-article 'head))))))))
3733 (defvar gnus-mime-display-multipart-as-mixed nil)
3735 (defun gnus-mime-display-part (handle)
3738 ((not (stringp (car handle)))
3739 (gnus-mime-display-single handle))
3740 ;; User-defined multipart
3741 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3742 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3744 ;; multipart/alternative
3745 ((and (equal (car handle) "multipart/alternative")
3746 (not gnus-mime-display-multipart-as-mixed))
3747 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3748 (push (cons id handle) gnus-article-mime-handle-alist)
3749 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3750 ;; multipart/related
3751 ((and (equal (car handle) "multipart/related")
3752 (not gnus-mime-display-multipart-as-mixed))
3753 ;;;!!!We should find the start part, but we just default
3754 ;;;!!!to the first part.
3755 (gnus-mime-display-part (cadr handle)))
3756 ;; Other multiparts are handled like multipart/mixed.
3757 ((equal (car handle) "multipart/signed")
3758 (or (memq 'signed gnus-article-wash-types)
3759 (push 'signed gnus-article-wash-types))
3760 (gnus-mime-display-mixed (cdr handle)))
3761 ((equal (car handle) "multipart/encrypted")
3762 (or (memq 'encrypted gnus-article-wash-types)
3763 (push 'encrypted gnus-article-wash-types))
3764 (gnus-mime-display-mixed (cdr handle)))
3766 (gnus-mime-display-mixed (cdr handle)))))
3768 (defun gnus-mime-part-function (handles)
3769 (if (stringp (car handles))
3770 (mapcar 'gnus-mime-part-function (cdr handles))
3771 (funcall gnus-article-mime-part-function handles)))
3773 (defun gnus-mime-display-mixed (handles)
3774 (mapcar 'gnus-mime-display-part handles))
3776 (defun gnus-mime-display-single (handle)
3777 (let ((type (mm-handle-media-type handle))
3778 (ignored gnus-ignored-mime-types)
3785 (when (string-match (pop ignored) type)
3786 (throw 'ignored nil)))
3787 (if (and (setq not-attachment
3788 (and (not (mm-inline-override-p handle))
3789 (or (not (mm-handle-disposition handle))
3790 (equal (car (mm-handle-disposition handle))
3792 (mm-attachment-override-p handle))))
3793 (mm-automatic-display-p handle)
3794 (or (mm-inlined-p handle)
3795 (mm-automatic-external-display-p type)))
3797 (when (equal (mm-handle-media-supertype handle) "text")
3799 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3801 (push (cons id handle) gnus-article-mime-handle-alist)
3802 (when (or (not display)
3803 (not (gnus-unbuttonized-mime-type-p type)))
3804 ;(gnus-article-insert-newline)
3805 (gnus-insert-mime-button
3806 handle id (list (or display (and not-attachment text))))
3807 (gnus-article-insert-newline)
3808 ;(gnus-article-insert-newline)
3809 ;; Remember modify the number of forward lines.
3817 (let ((mail-parse-charset gnus-newsgroup-charset)
3818 (mail-parse-ignored-charsets
3819 (save-excursion (condition-case ()
3820 (set-buffer gnus-summary-buffer)
3822 gnus-newsgroup-ignored-charsets)))
3823 (mm-display-part handle t))
3824 (goto-char (point-max)))
3825 ((and text not-attachment)
3829 (gnus-article-insert-newline)
3830 (mm-insert-inline handle (mm-get-part handle))
3831 (goto-char (point-max))))
3835 (narrow-to-region beg (point))
3838 (gnus-article-mime-total-parts)
3839 (mm-handle-media-type handle)))))))))
3841 (defun gnus-unbuttonized-mime-type-p (type)
3842 "Say whether TYPE is to be unbuttonized."
3843 (unless gnus-inhibit-mime-unbuttonizing
3845 (let ((types gnus-unbuttonized-mime-types))
3847 (when (string-match (pop types) type)
3848 (throw 'found t)))))))
3850 (defun gnus-article-insert-newline ()
3851 "Insert a newline, but mark it as undeletable."
3852 (gnus-put-text-property
3853 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3855 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3856 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3859 handle buffer-read-only from props begend not-pref)
3860 (save-window-excursion
3863 (narrow-to-region (car ibegend)
3866 (goto-char (car ibegend))
3869 (delete-region (point-min) (point-max))
3870 (mm-remove-parts handles))
3871 (setq begend (list (point-marker)))
3873 (unless (setq not-pref (cadr (member preferred ihandles)))
3874 (setq not-pref (car ihandles)))
3876 (not (gnus-unbuttonized-mime-type-p
3877 "multipart/alternative")))
3878 (gnus-add-text-properties
3881 (insert (format "%d. " id))
3885 (unless ,(not ibegend)
3886 (setq gnus-article-mime-handle-alist
3887 ',gnus-article-mime-handle-alist))
3888 (gnus-mime-display-alternative
3889 ',ihandles ',not-pref ',begend ,id))
3890 local-map ,gnus-mime-button-map
3891 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3892 face ,gnus-article-button-face
3893 keymap ,gnus-mime-button-map
3896 (widget-convert-button 'link from (point)
3897 :action 'gnus-widget-press-button
3898 :button-keymap gnus-widget-button-keymap)
3900 (while (setq handle (pop handles))
3901 (gnus-add-text-properties
3904 (insert (format "(%c) %-18s"
3905 (if (equal handle preferred) ?* ? )
3906 (mm-handle-media-type handle)))
3910 (unless ,(not ibegend)
3911 (setq gnus-article-mime-handle-alist
3912 ',gnus-article-mime-handle-alist))
3913 (gnus-mime-display-alternative
3914 ',ihandles ',handle ',begend ,id))
3915 local-map ,gnus-mime-button-map
3916 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3917 face ,gnus-article-button-face
3918 keymap ,gnus-mime-button-map
3921 (widget-convert-button 'link from (point)
3922 :action 'gnus-widget-press-button
3923 :button-keymap gnus-widget-button-keymap)
3927 (if (stringp (car preferred))
3928 (gnus-display-mime preferred)
3929 (let ((mail-parse-charset gnus-newsgroup-charset)
3930 (mail-parse-ignored-charsets
3931 (save-excursion (set-buffer gnus-summary-buffer)
3932 gnus-newsgroup-ignored-charsets)))
3933 (mm-display-part preferred)
3937 (narrow-to-region (car begend) (point-max))
3939 nil (length gnus-article-mime-handle-alist)
3940 (gnus-article-mime-total-parts)
3941 (mm-handle-media-type handle))))))
3942 (goto-char (point-max))
3943 (setcdr begend (point-marker)))))
3945 (goto-char point))))
3947 (defun gnus-article-wash-status ()
3948 "Return a string which display status of article washing."
3950 (set-buffer gnus-article-buffer)
3951 (let ((cite (memq 'cite gnus-article-wash-types))
3952 (headers (memq 'headers gnus-article-wash-types))
3953 (boring (memq 'boring-headers gnus-article-wash-types))
3954 (pgp (memq 'pgp gnus-article-wash-types))
3955 (pem (memq 'pem gnus-article-wash-types))
3956 (signed (memq 'signed gnus-article-wash-types))
3957 (encrypted (memq 'encrypted gnus-article-wash-types))
3958 (signature (memq 'signature gnus-article-wash-types))
3959 (overstrike (memq 'overstrike gnus-article-wash-types))
3960 (emphasis (memq 'emphasis gnus-article-wash-types)))
3961 (format "%c%c%c%c%c%c%c"
3963 (if (or headers boring) ?h ? )
3964 (if (or pgp pem signed encrypted) ?p ? )
3965 (if signature ?s ? )
3966 (if overstrike ?o ? )
3967 (if gnus-show-mime ?m ? )
3968 (if emphasis ?e ? )))))
3970 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3972 (defun gnus-article-maybe-hide-headers ()
3973 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3974 Provided for backwards compatibility."
3975 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3976 (not (save-excursion (set-buffer gnus-summary-buffer)
3977 gnus-have-all-headers)))
3978 (not gnus-inhibit-hiding))
3979 (gnus-article-hide-headers)))
3983 (defun gnus-output-to-file (file-name)
3984 "Append the current article to a file named FILE-NAME."
3985 (let ((artbuf (current-buffer)))
3987 (insert-buffer-substring artbuf)
3988 ;; Append newline at end of the buffer as separator, and then
3990 (goto-char (point-max))
3992 (write-region-as-binary (point-min) (point-max) file-name 'append)
3995 (defun gnus-narrow-to-page (&optional arg)
3996 "Narrow the article buffer to a page.
3997 If given a numerical ARG, move forward ARG pages."
3999 (setq arg (if arg (prefix-numeric-value arg) 0))
4001 (set-buffer gnus-article-buffer)
4002 (goto-char (point-min))
4004 ;; Remove any old next/prev buttons.
4005 (when (gnus-visual-p 'page-marker)
4006 (let ((buffer-read-only nil))
4007 (gnus-remove-text-with-property 'gnus-prev)
4008 (gnus-remove-text-with-property 'gnus-next)))
4011 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4013 (re-search-forward page-delimiter nil 'move arg)))
4014 (goto-char (match-end 0)))
4017 (if (re-search-forward page-delimiter nil 'move)
4020 (when (and (gnus-visual-p 'page-marker)
4021 (not (= (point-min) 1)))
4023 (goto-char (point-min))
4024 (gnus-insert-prev-page-button)))
4025 (when (and (gnus-visual-p 'page-marker)
4026 (< (+ (point-max) 2) (buffer-size)))
4028 (goto-char (point-max))
4029 (gnus-insert-next-page-button)))))
4031 ;; Article mode commands
4033 (defun gnus-article-goto-next-page ()
4034 "Show the next page of the article."
4036 (when (gnus-article-next-page)
4037 (goto-char (point-min))
4038 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4040 (defun gnus-article-goto-prev-page ()
4041 "Show the next page of the article."
4043 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4044 (gnus-article-prev-page nil)))
4046 (defun gnus-article-next-page (&optional lines)
4047 "Show the next page of the current article.
4048 If end of article, return non-nil. Otherwise return nil.
4049 Argument LINES specifies lines to be scrolled up."
4051 (let ((start (window-start))
4052 end-of-buffer end-of-page)
4054 (move-to-window-line -1)
4055 (if (<= (point) start)
4058 (setq start (point)))
4061 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4062 (and (pos-visible-in-window-p)
4063 (setq end-of-buffer t)))
4065 (setq end-of-page t)))
4067 (move-to-window-line lines)
4068 (unless (search-backward "\n\n" nil t)
4069 (setq start (point)))))
4070 (cond (end-of-buffer t)
4072 (gnus-narrow-to-page 1)
4076 (set-window-start (selected-window) start)
4077 (let (window-pixel-scroll-increment)
4081 (defun gnus-article-prev-page (&optional lines)
4082 "Show previous page of current article.
4083 Argument LINES specifies lines to be scrolled down."
4085 (let (beginning-of-buffer beginning-of-page)
4087 (move-to-window-line 0)
4088 (cond ((eq 1 (point))
4089 (setq beginning-of-buffer t))
4091 (setq beginning-of-page t))))
4092 (cond (beginning-of-buffer)
4094 (gnus-narrow-to-page -1))
4097 (let (window-pixel-scroll-increment)
4098 (scroll-down lines))
4099 (beginning-of-buffer
4100 (goto-char (point-min))))))))
4102 (defun gnus-article-refer-article ()
4103 "Read article specified by message-id around point."
4105 (let ((point (point)))
4106 (search-forward ">" nil t) ;Move point to end of "<....>".
4107 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4108 (let ((message-id (match-string 1)))
4110 (set-buffer gnus-summary-buffer)
4111 (gnus-summary-refer-article message-id))
4113 (error "No references around point"))))
4115 (defun gnus-article-show-summary ()
4116 "Reconfigure windows to show summary buffer."
4118 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4119 (error "There is no summary buffer for this article buffer")
4120 (gnus-article-set-globals)
4121 (gnus-configure-windows 'article)
4122 (gnus-summary-goto-subject gnus-current-article)
4123 (gnus-summary-position-point)))
4125 (defun gnus-article-describe-briefly ()
4126 "Describe article mode commands briefly."
4128 (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")))
4130 (defun gnus-article-summary-command ()
4131 "Execute the last keystroke in the summary buffer."
4133 (let ((obuf (current-buffer))
4134 (owin (current-window-configuration))
4136 (switch-to-buffer gnus-article-current-summary 'norecord)
4137 (setq func (lookup-key (current-local-map) (this-command-keys)))
4138 (call-interactively func)
4140 (set-window-configuration owin)
4141 (set-window-point (get-buffer-window (current-buffer)) (point))))
4143 (defun gnus-article-summary-command-nosave ()
4144 "Execute the last keystroke in the summary buffer."
4147 (pop-to-buffer gnus-article-current-summary 'norecord)
4148 (setq func (lookup-key (current-local-map) (this-command-keys)))
4149 (call-interactively func)))
4151 (defun gnus-article-check-buffer ()
4152 "Beep if not in an article buffer."
4153 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4154 (error "Command invoked outside of a Gnus article buffer")))
4156 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4157 "Read a summary buffer key sequence and execute it from the article buffer."
4159 (gnus-article-check-buffer)
4161 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4162 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4163 "=" "^" "\M-^" "|"))
4169 '("n" "Gn" "p" "Gp"))
4172 (set-buffer gnus-article-current-summary)
4173 (let (gnus-pick-mode)
4174 (push (or key last-command-event) unread-command-events)
4175 (setq keys (static-if (featurep 'xemacs)
4176 (events-to-keys (read-key-sequence nil))
4177 (read-key-sequence nil)))))
4180 (if (or (member keys nosaves)
4181 (member keys nosave-but-article)
4182 (member keys nosave-in-article))
4184 (save-window-excursion
4185 (pop-to-buffer gnus-article-current-summary 'norecord)
4186 ;; We disable the pick minor mode commands.
4187 (let (gnus-pick-mode)
4188 (setq func (lookup-key (current-local-map) keys))))
4192 (unless (member keys nosave-in-article)
4193 (set-buffer gnus-article-current-summary))
4194 (call-interactively func)
4195 (setq new-sum-point (point)))
4196 (when (member keys nosave-but-article)
4197 (pop-to-buffer gnus-article-buffer 'norecord)))
4198 ;; These commands should restore window configuration.
4199 (let ((obuf (current-buffer))
4200 (owin (current-window-configuration))
4202 (summary gnus-article-current-summary)
4203 func in-buffer selected)
4204 (if not-restore-window
4205 (pop-to-buffer summary 'norecord)
4206 (switch-to-buffer summary 'norecord))
4207 (setq in-buffer (current-buffer))
4208 ;; We disable the pick minor mode commands.
4209 (if (setq func (let (gnus-pick-mode)
4210 (lookup-key (current-local-map) keys)))
4212 (call-interactively func)
4213 (setq new-sum-point (point)))
4215 (when (eq in-buffer (current-buffer))
4216 (setq selected (gnus-summary-select-article))
4218 (unless not-restore-window
4219 (set-window-configuration owin))
4220 (when (eq selected 'old)
4222 (set-window-start (get-buffer-window (current-buffer))
4224 (set-window-point (get-buffer-window (current-buffer))
4226 (let ((win (get-buffer-window gnus-article-current-summary)))
4228 (set-window-point win new-sum-point))))))))
4230 (defun gnus-article-hide (&optional arg force)
4231 "Hide all the gruft in the current article.
4232 This means that PGP stuff, signatures, cited text and (some)
4233 headers will be hidden.
4234 If given a prefix, show the hidden text instead."
4235 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4236 (gnus-article-hide-headers arg)
4237 (gnus-article-hide-list-identifiers arg)
4238 (gnus-article-hide-pgp arg)
4239 (gnus-article-hide-citation-maybe arg force)
4240 (gnus-article-hide-signature arg))
4242 (defun gnus-article-maybe-highlight ()
4243 "Do some article highlighting if article highlighting is requested."
4244 (when (gnus-visual-p 'article-highlight 'highlight)
4245 (gnus-article-highlight-some)))
4247 (defun gnus-check-group-server ()
4248 ;; Make sure the connection to the server is alive.
4249 (unless (gnus-server-opened
4250 (gnus-find-method-for-group gnus-newsgroup-name))
4251 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4252 (gnus-request-group gnus-newsgroup-name t)))
4254 (defun gnus-request-article-this-buffer (article group)
4255 "Get an article and insert it into this buffer."
4256 (let (do-update-line sparse-header)
4260 (gnus-kill-all-overlays)
4261 (setq group (or group gnus-newsgroup-name))
4263 ;; Using `gnus-request-article' directly will insert the article into
4264 ;; `nntp-server-buffer' - so we'll save some time by not having to
4265 ;; copy it from the server buffer into the article buffer.
4267 ;; We only request an article by message-id when we do not have the
4268 ;; headers for it, so we'll have to get those.
4269 (when (stringp article)
4270 (gnus-read-header article))
4272 ;; If the article number is negative, that means that this article
4273 ;; doesn't belong in this newsgroup (possibly), so we find its
4274 ;; message-id and request it by id instead of number.
4275 (when (and (numberp article)
4277 (get-buffer gnus-summary-buffer)
4278 (gnus-buffer-exists-p gnus-summary-buffer))
4280 (set-buffer gnus-summary-buffer)
4281 (let ((header (gnus-summary-article-header article)))
4284 ((memq article gnus-newsgroup-sparse)
4285 ;; This is a sparse gap article.
4286 (setq do-update-line article)
4287 (setq article (mail-header-id header))
4288 (setq sparse-header (gnus-read-header article))
4289 (setq gnus-newsgroup-sparse
4290 (delq article gnus-newsgroup-sparse)))
4292 ;; It's a real article.
4293 (setq article (mail-header-id header)))
4295 ;; It is an extracted pseudo-article.
4296 (setq article 'pseudo)
4297 (gnus-request-pseudo-article header))))
4299 (let ((method (gnus-find-method-for-group
4300 gnus-newsgroup-name)))
4301 (when (and (eq (car method) 'nneething)
4303 (let ((dir (expand-file-name
4304 (mail-header-subject header)
4305 (file-name-as-directory
4306 (or (cadr (assq 'nneething-address method))
4308 (when (file-directory-p dir)
4309 (setq article 'nneething)
4310 (gnus-group-enter-directory dir))))))))
4313 ;; Refuse to select canceled articles.
4314 ((and (numberp article)
4316 (get-buffer gnus-summary-buffer)
4317 (gnus-buffer-exists-p gnus-summary-buffer)
4318 (eq (cdr (save-excursion
4319 (set-buffer gnus-summary-buffer)
4320 (assq article gnus-newsgroup-reads)))
4321 gnus-canceled-mark))
4323 ;; Check the backlog.
4324 ((and gnus-keep-backlog
4325 (gnus-backlog-request-article group article (current-buffer)))
4327 ;; Check asynchronous pre-fetch.
4328 ((gnus-async-request-fetched-article group article (current-buffer))
4329 (gnus-async-prefetch-next group article gnus-summary-buffer)
4330 (when (and (numberp article) gnus-keep-backlog)
4331 (gnus-backlog-enter-article group article (current-buffer)))
4334 ((and gnus-use-cache
4336 (gnus-cache-request-article article group))
4338 ;; Get the article and put into the article buffer.
4339 ((or (stringp article)
4341 (let ((gnus-override-method gnus-override-method)
4342 (methods (and (stringp article)
4343 gnus-refer-article-method))
4345 (buffer-read-only nil))
4346 (if (or (not (listp methods))
4347 (and (symbolp (car methods))
4348 (assq (car methods) nnoo-definition-alist)))
4349 (setq methods (list methods)))
4350 (when (and (null gnus-override-method)
4352 (setq gnus-override-method (pop methods)))
4354 (when (eq gnus-override-method 'current)
4355 (setq gnus-override-method gnus-current-select-method))
4357 (gnus-kill-all-overlays)
4358 (let ((gnus-newsgroup-name group))
4359 (gnus-check-group-server))
4360 (when (gnus-request-article article group (current-buffer))
4361 (when (numberp article)
4362 (gnus-async-prefetch-next group article
4363 gnus-summary-buffer)
4364 (when gnus-keep-backlog
4365 (gnus-backlog-enter-article
4366 group article (current-buffer))))
4367 (setq result 'article))
4370 (setq gnus-override-method (pop methods))
4371 (setq result 'done))))
4372 (and (eq result 'article) 'article)))
4376 ;; Associate this article with the current summary buffer.
4377 (setq gnus-article-current-summary gnus-summary-buffer)
4379 ;; Take the article from the original article buffer
4380 ;; and place it in the buffer it's supposed to be in.
4381 (when (and (get-buffer gnus-article-buffer)
4382 (equal (buffer-name (current-buffer))
4383 (buffer-name (get-buffer gnus-article-buffer))))
4385 (if (get-buffer gnus-original-article-buffer)
4386 (set-buffer gnus-original-article-buffer)
4387 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4388 (set-buffer-multibyte nil)
4389 (buffer-disable-undo)
4390 (setq major-mode 'gnus-original-article-mode)
4391 (setq buffer-read-only t))
4392 (let (buffer-read-only)
4394 (insert-buffer-substring gnus-article-buffer))
4395 (setq gnus-original-article (cons group article)))
4398 (run-hooks 'gnus-article-decode-hook)
4399 ;; Mark article as decoded or not.
4400 (setq gnus-article-decoded-p gnus-article-decode-hook))
4402 ;; Update sparse articles.
4403 (when (and do-update-line
4404 (or (numberp article)
4406 (let ((buf (current-buffer)))
4407 (set-buffer gnus-summary-buffer)
4408 (gnus-summary-update-article do-update-line sparse-header)
4409 (gnus-summary-goto-subject do-update-line nil t)
4410 (set-window-point (get-buffer-window (current-buffer) t)
4412 (set-buffer buf))))))
4418 (defcustom gnus-article-edit-mode-hook nil
4419 "Hook run in article edit mode buffers."
4420 :group 'gnus-article-various
4423 (defcustom gnus-article-edit-article-setup-function
4424 'gnus-article-mime-edit-article-setup
4425 "Function called to setup an editing article buffer."
4426 :group 'gnus-article-various
4429 (defvar gnus-article-edit-done-function nil)
4431 (defvar gnus-article-edit-mode-map nil)
4433 ;; Should we be using derived.el for this?
4434 (unless gnus-article-edit-mode-map
4435 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4436 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4438 (gnus-define-keys gnus-article-edit-mode-map
4439 "\C-c\C-c" gnus-article-edit-done
4440 "\C-c\C-k" gnus-article-edit-exit)
4442 (gnus-define-keys (gnus-article-edit-wash-map
4443 "\C-c\C-w" gnus-article-edit-mode-map)
4444 "f" gnus-article-edit-full-stops))
4446 (defun gnus-article-edit-mode ()
4447 "Major mode for editing articles.
4448 This is an extended text-mode.
4450 \\{gnus-article-edit-mode-map}"
4452 (setq major-mode 'gnus-article-edit-mode)
4453 (setq mode-name "Article Edit")
4454 (use-local-map gnus-article-edit-mode-map)
4455 (make-local-variable 'gnus-article-edit-done-function)
4456 (make-local-variable 'gnus-prev-winconf)
4457 (setq buffer-read-only nil)
4458 (buffer-enable-undo)
4460 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4462 (defun gnus-article-edit (&optional force)
4463 "Edit the current article.
4464 This will have permanent effect only in mail groups.
4465 If FORCE is non-nil, allow editing of articles even in read-only
4468 (when (and (not force)
4469 (gnus-group-read-only-p))
4470 (error "The current newsgroup does not support article editing"))
4471 (gnus-article-date-original)
4472 (gnus-article-edit-article
4474 `(lambda (no-highlight)
4476 (gnus-summary-edit-article-done
4477 ,(or (mail-header-references gnus-current-headers) "")
4478 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4480 (defun gnus-article-edit-article (start-func exit-func)
4481 "Start editing the contents of the current article buffer."
4482 (let ((winconf (current-window-configuration)))
4483 (set-buffer gnus-article-buffer)
4484 (gnus-article-edit-mode)
4485 (funcall start-func)
4486 (gnus-configure-windows 'edit-article)
4487 (setq gnus-article-edit-done-function exit-func)
4488 (setq gnus-prev-winconf winconf)
4489 (when gnus-article-edit-article-setup-function
4490 (funcall gnus-article-edit-article-setup-function))
4491 (gnus-message 6 "C-c C-c to end edits")))
4493 (defun gnus-article-edit-done (&optional arg)
4494 "Update the article edits and exit."
4499 (when (article-goto-body)
4500 (let ((lines (count-lines (point) (point-max)))
4501 (length (- (point-max) (point)))
4502 (case-fold-search t)
4503 (body (copy-marker (point))))
4504 (goto-char (point-min))
4505 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4506 (delete-region (match-beginning 1) (match-end 1))
4507 (insert (number-to-string length)))
4508 (goto-char (point-min))
4509 (when (re-search-forward
4510 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4511 (delete-region (match-beginning 1) (match-end 1))
4512 (insert (number-to-string length)))
4513 (goto-char (point-min))
4514 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4515 (delete-region (match-beginning 1) (match-end 1))
4516 (insert (number-to-string lines)))))))
4517 (let ((func gnus-article-edit-done-function)
4518 (buf (current-buffer))
4519 (start (window-start)))
4520 (remove-hook 'gnus-article-mode-hook
4521 'gnus-article-mime-edit-article-unwind)
4522 (gnus-article-edit-exit)
4525 (let ((buffer-read-only nil))
4527 ;; The cache and backlog have to be flushed somewhat.
4528 (when gnus-keep-backlog
4529 (gnus-backlog-remove-article
4530 (car gnus-article-current) (cdr gnus-article-current)))
4531 ;; Flush original article as well.
4533 (when (get-buffer gnus-original-article-buffer)
4534 (set-buffer gnus-original-article-buffer)
4535 (setq gnus-original-article nil)))
4536 (when gnus-use-cache
4537 (gnus-cache-update-article
4538 (car gnus-article-current) (cdr gnus-article-current))))
4540 (set-window-start (get-buffer-window buf) start)
4541 (set-window-point (get-buffer-window buf) (point))))
4543 (defun gnus-article-edit-exit ()
4544 "Exit the article editing without updating."
4546 ;; We remove all text props from the article buffer.
4547 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4548 (curbuf (current-buffer))
4550 (window-start (window-start)))
4553 (let ((winconf gnus-prev-winconf))
4555 (set-window-configuration winconf)
4556 ;; Tippy-toe some to make sure that point remains where it was.
4557 (save-current-buffer
4559 (set-window-start (get-buffer-window (current-buffer)) window-start)
4562 (defun gnus-article-edit-full-stops ()
4563 "Interactively repair spacing at end of sentences."
4566 (goto-char (point-min))
4567 (search-forward-regexp "^$" nil t)
4568 (let ((case-fold-search nil))
4569 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4572 ;;; Article editing with MIME-Edit
4575 (defcustom gnus-article-mime-edit-article-setup-hook nil
4576 "Hook run after setting up a MIME editing article buffer."
4577 :group 'gnus-article-various
4580 (defun gnus-article-mime-edit-article-unwind ()
4581 "Unwind `gnus-article-buffer' if article editing was given up."
4582 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4583 (when mime-edit-mode-flag
4584 (mime-edit-exit 'nomime 'no-error)
4586 (when (featurep 'font-lock)
4587 (setq font-lock-defaults nil)
4588 (font-lock-mode 0)))
4590 (defun gnus-article-mime-edit-article-setup ()
4591 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4592 after replacing with the original article."
4593 (setq gnus-show-mime t)
4594 (setq gnus-article-edit-done-function
4595 `(lambda (&rest args)
4596 (when mime-edit-mode-flag
4599 (goto-char (point-min))
4600 (let (case-fold-search)
4601 (when (re-search-forward
4602 (format "^%s$" (regexp-quote mail-header-separator))
4604 (replace-match "")))
4605 (when (featurep 'font-lock)
4606 (setq font-lock-defaults nil)
4608 (apply ,gnus-article-edit-done-function args)
4609 (set-buffer gnus-original-article-buffer)
4611 (insert-buffer gnus-article-buffer)
4612 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4613 (gnus-article-prepare-display)))
4614 (substitute-key-definition
4615 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4616 gnus-article-edit-mode-map)
4618 (insert-buffer gnus-original-article-buffer)
4620 (when (featurep 'font-lock)
4621 (set (make-local-variable 'font-lock-defaults)
4622 '(message-font-lock-keywords t))
4623 (font-lock-set-defaults)
4624 (turn-on-font-lock))
4625 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4626 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4628 (defun gnus-article-mime-edit-exit ()
4629 "Exit the article MIME editing without updating."
4631 (let ((winconf gnus-prev-winconf)
4633 (when mime-edit-mode-flag
4636 (goto-char (point-min))
4637 (let (case-fold-search)
4638 (when (re-search-forward
4639 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4640 (replace-match "")))
4641 (when (featurep 'font-lock)
4642 (setq font-lock-defaults nil)
4644 ;; We remove all text props from the article buffer.
4645 (setq buf (format "%s" (buffer-string)))
4646 (set-buffer (get-buffer-create gnus-original-article-buffer))
4649 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4650 (gnus-article-prepare-display)
4651 (set-window-configuration winconf)))
4654 ;;; Article highlights
4657 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4659 ;;; Internal Variables:
4661 (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\\)\\)"
4662 "Regular expression that matches URLs."
4663 :group 'gnus-article-buttons
4666 (defcustom gnus-button-alist
4667 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4668 0 t gnus-button-message-id 2)
4669 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4670 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4672 gnus-button-fetch-group 4)
4673 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4674 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4675 t gnus-button-message-id 3)
4676 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4677 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4678 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4679 ;; This is how URLs _should_ be embedded in text...
4680 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4682 (,gnus-button-url-regexp 0 t browse-url 0))
4683 "*Alist of regexps matching buttons in article bodies.
4685 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4686 REGEXP: is the string matching text around the button,
4687 BUTTON: is the number of the regexp grouping actually matching the button,
4688 FORM: is a lisp expression which must eval to true for the button to
4690 CALLBACK: is the function to call when the user push this button, and each
4691 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4693 CALLBACK can also be a variable, in that case the value of that
4694 variable it the real callback function."
4695 :group 'gnus-article-buttons
4696 :type '(repeat (list regexp
4697 (integer :tag "Button")
4699 (function :tag "Callback")
4702 (integer :tag "Regexp group")))))
4704 (defcustom gnus-header-button-alist
4705 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4706 0 t gnus-button-message-id 0)
4707 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4708 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4709 0 t gnus-button-mailto 0)
4710 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4711 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4712 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4713 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4714 gnus-button-message-id 3))
4715 "*Alist of headers and regexps to match buttons in article heads.
4717 This alist is very similar to `gnus-button-alist', except that each
4718 alist has an additional HEADER element first in each entry:
4720 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4722 HEADER is a regexp to match a header. For a fuller explanation, see
4723 `gnus-button-alist'."
4724 :group 'gnus-article-buttons
4725 :group 'gnus-article-headers
4726 :type '(repeat (list (regexp :tag "Header")
4728 (integer :tag "Button")
4730 (function :tag "Callback")
4733 (integer :tag "Regexp group")))))
4735 (defvar gnus-button-regexp nil)
4736 (defvar gnus-button-marker-list nil)
4737 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4739 (defvar gnus-button-last nil)
4740 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4744 (defun gnus-article-push-button (event)
4745 "Check text under the mouse pointer for a callback function.
4746 If the text under the mouse pointer has a `gnus-callback' property,
4747 call it with the value of the `gnus-data' text property."
4749 (set-buffer (window-buffer (posn-window (event-start event))))
4750 (let* ((pos (posn-point (event-start event)))
4751 (data (get-text-property pos 'gnus-data))
4752 (fun (get-text-property pos 'gnus-callback)))
4755 (funcall fun data))))
4757 (defun gnus-article-press-button ()
4758 "Check text at point for a callback function.
4759 If the text at point has a `gnus-callback' property,
4760 call it with the value of the `gnus-data' text property."
4762 (let* ((data (get-text-property (point) 'gnus-data))
4763 (fun (get-text-property (point) 'gnus-callback)))
4765 (funcall fun data))))
4767 (defun gnus-article-prev-button (n)
4768 "Move point to N buttons backward.
4769 If N is negative, move forward instead."
4771 (gnus-article-next-button (- n)))
4773 (defun gnus-article-next-button (n)
4774 "Move point to N buttons forward.
4775 If N is negative, move backward instead."
4777 (let ((function (if (< n 0) 'previous-single-property-change
4778 'next-single-property-change))
4779 (inhibit-point-motion-hooks t)
4781 (limit (if (< n 0) (point-min) (point-max))))
4783 (while (and (not (= limit (point)))
4785 ;; Skip past the current button.
4786 (when (get-text-property (point) 'gnus-callback)
4787 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4788 ;; Go to the next (or previous) button.
4789 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4790 ;; Put point at the start of the button.
4791 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4792 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4793 ;; Skip past intangible buttons.
4794 (when (get-text-property (point) 'intangible)
4798 (gnus-message 5 "No more buttons"))
4801 (defun gnus-article-highlight (&optional force)
4802 "Highlight current article.
4803 This function calls `gnus-article-highlight-headers',
4804 `gnus-article-highlight-citation',
4805 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4806 do the highlighting. See the documentation for those functions."
4807 (interactive (list 'force))
4808 (gnus-article-highlight-headers)
4809 (gnus-article-highlight-citation force)
4810 (gnus-article-highlight-signature)
4811 (gnus-article-add-buttons force)
4812 (gnus-article-add-buttons-to-head))
4814 (defun gnus-article-highlight-some (&optional force)
4815 "Highlight current article.
4816 This function calls `gnus-article-highlight-headers',
4817 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4818 do the highlighting. See the documentation for those functions."
4819 (interactive (list 'force))
4820 (gnus-article-highlight-headers)
4821 (gnus-article-highlight-signature)
4822 (gnus-article-add-buttons))
4824 (defun gnus-article-highlight-headers ()
4825 "Highlight article headers as specified by `gnus-header-face-alist'."
4828 (set-buffer gnus-article-buffer)
4830 (let ((alist gnus-header-face-alist)
4831 (buffer-read-only nil)
4832 (case-fold-search t)
4833 (inhibit-point-motion-hooks t)
4834 entry regexp header-face field-face from hpoints fpoints)
4835 (article-narrow-to-head)
4836 (while (setq entry (pop alist))
4837 (goto-char (point-min))
4838 (setq regexp (concat "^\\("
4839 (if (string-equal "" (nth 0 entry))
4843 header-face (nth 1 entry)
4844 field-face (nth 2 entry))
4845 (while (and (re-search-forward regexp nil t)
4849 (unless (search-forward ":" nil t)
4851 (when (and header-face
4852 (not (memq (point) hpoints)))
4853 (push (point) hpoints)
4854 (gnus-put-text-property from (point) 'face header-face))
4855 (when (and field-face
4856 (not (memq (setq from (point)) fpoints)))
4858 (if (re-search-forward "^[^ \t]" nil t)
4860 (goto-char (point-max)))
4861 (gnus-put-text-property from (point) 'face field-face))))))))
4863 (defun gnus-article-highlight-signature ()
4864 "Highlight the signature in an article.
4865 It does this by highlighting everything after
4866 `gnus-signature-separator' using `gnus-signature-face'."
4868 (when gnus-signature-face
4870 (set-buffer gnus-article-buffer)
4871 (let ((buffer-read-only nil)
4872 (inhibit-point-motion-hooks t))
4874 (when (gnus-article-narrow-to-signature)
4875 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4876 'face gnus-signature-face)))))))
4878 (defun gnus-article-buttonize-signature ()
4879 "Add button to the signature."
4882 (set-buffer gnus-article-buffer)
4883 (let ((buffer-read-only nil)
4884 (inhibit-point-motion-hooks t))
4885 (when (gnus-article-search-signature)
4886 (gnus-article-add-button (match-beginning 0) (match-end 0)
4887 'gnus-signature-toggle
4888 (set-marker (make-marker)
4889 (1+ (match-end 0))))))))
4891 (defun gnus-button-in-region-p (b e prop)
4892 "Say whether PROP exists in the region."
4893 (text-property-not-all b e prop nil))
4895 (defun gnus-article-add-buttons (&optional force)
4896 "Find external references in the article and make buttons of them.
4897 \"External references\" are things like Message-IDs and URLs, as
4898 specified by `gnus-button-alist'."
4899 (interactive (list 'force))
4901 (set-buffer gnus-article-buffer)
4902 (let ((buffer-read-only nil)
4903 (inhibit-point-motion-hooks t)
4904 (case-fold-search t)
4905 (alist gnus-button-alist)
4907 ;; Remove all old markers.
4908 (let (marker entry new-list)
4909 (while (setq marker (pop gnus-button-marker-list))
4910 (if (or (< marker (point-min)) (>= marker (point-max)))
4911 (push marker new-list)
4913 (when (setq entry (gnus-button-entry))
4914 (put-text-property (match-beginning (nth 1 entry))
4915 (match-end (nth 1 entry))
4916 'gnus-callback nil))
4917 (set-marker marker nil)))
4918 (setq gnus-button-marker-list new-list))
4919 ;; We skip the headers.
4922 (while (setq entry (pop alist))
4923 (setq regexp (car entry))
4925 (while (re-search-forward regexp nil t)
4926 (let* ((start (and entry (match-beginning (nth 1 entry))))
4927 (end (and entry (match-end (nth 1 entry))))
4928 (from (match-beginning 0)))
4929 (when (and (or (eq t (nth 2 entry))
4930 (eval (nth 2 entry)))
4931 (not (gnus-button-in-region-p
4932 start end 'gnus-callback)))
4933 ;; That optional form returned non-nil, so we add the
4935 (gnus-article-add-button
4936 start end 'gnus-button-push
4937 (car (push (set-marker (make-marker) from)
4938 gnus-button-marker-list))))))))))
4940 ;; Add buttons to the head of an article.
4941 (defun gnus-article-add-buttons-to-head ()
4942 "Add buttons to the head of the article."
4945 (set-buffer gnus-article-buffer)
4947 (let ((buffer-read-only nil)
4948 (inhibit-point-motion-hooks t)
4949 (case-fold-search t)
4950 (alist gnus-header-button-alist)
4952 (article-narrow-to-head)
4954 ;; Each alist entry.
4955 (setq entry (car alist)
4957 (goto-char (point-min))
4958 (while (re-search-forward (car entry) nil t)
4959 ;; Each header matching the entry.
4960 (setq beg (match-beginning 0))
4961 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4962 (match-beginning 0))
4965 (while (re-search-forward (nth 1 entry) end t)
4966 ;; Each match within a header.
4967 (let* ((entry (cdr entry))
4968 (start (match-beginning (nth 1 entry)))
4969 (end (match-end (nth 1 entry)))
4970 (form (nth 2 entry)))
4971 (goto-char (match-end 0))
4973 (gnus-article-add-button
4974 start end (nth 3 entry)
4975 (buffer-substring (match-beginning (nth 4 entry))
4976 (match-end (nth 4 entry)))))))
4977 (goto-char end)))))))
4979 ;;; External functions:
4981 (defun gnus-article-add-button (from to fun &optional data)
4982 "Create a button between FROM and TO with callback FUN and data DATA."
4983 (when gnus-article-button-face
4984 (gnus-overlay-put (gnus-make-overlay from to)
4985 'face gnus-article-button-face))
4986 (gnus-add-text-properties
4988 (nconc (and gnus-article-mouse-face
4989 (list gnus-mouse-face-prop gnus-article-mouse-face))
4990 (list 'gnus-callback fun)
4991 (and data (list 'gnus-data data))))
4992 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4993 ;; Quote `:button-keymap' for Mule 2.3
4994 ;; but it won't work.
4995 ':button-keymap gnus-widget-button-keymap))
4997 ;;; Internal functions:
4999 (defun gnus-article-set-globals ()
5001 (set-buffer gnus-summary-buffer)
5002 (gnus-set-global-variables)))
5004 (defun gnus-signature-toggle (end)
5006 (set-buffer gnus-article-buffer)
5007 (let ((buffer-read-only nil)
5008 (inhibit-point-motion-hooks t)
5009 (limit (next-single-property-change end 'mime-view-entity
5011 (if (get-text-property end 'invisible)
5012 (gnus-article-unhide-text end limit)
5013 (gnus-article-hide-text end limit gnus-hidden-properties)))))
5015 (defun gnus-button-entry ()
5016 ;; Return the first entry in `gnus-button-alist' matching this place.
5017 (let ((alist gnus-button-alist)
5020 (setq entry (pop alist))
5021 (if (looking-at (car entry))
5026 (defun gnus-button-push (marker)
5027 ;; Push button starting at MARKER.
5030 (let* ((entry (gnus-button-entry))
5031 (inhibit-point-motion-hooks t)
5033 (args (mapcar (lambda (group)
5034 (let ((string (match-string group)))
5035 (gnus-set-text-properties
5036 0 (length string) nil string)
5043 (fboundp (symbol-value fun)))
5044 (apply (symbol-value fun) args))
5046 (gnus-message 1 "You must define `%S' to use this button"
5047 (cons fun args)))))))
5049 (defun gnus-button-message-id (message-id)
5052 (set-buffer gnus-summary-buffer)
5053 (gnus-summary-refer-article message-id)))
5055 (defun gnus-button-fetch-group (address)
5056 "Fetch GROUP specified by ADDRESS."
5057 (if (not (string-match "[:/]" address))
5058 ;; This is just a simple group url.
5059 (gnus-group-read-ephemeral-group address gnus-select-method)
5060 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5062 (error "Can't parse %s" address)
5063 (gnus-group-read-ephemeral-group
5064 (match-string 4 address)
5065 `(nntp ,(match-string 1 address)
5066 (nntp-address ,(match-string 1 address))
5067 (nntp-port-number ,(if (match-end 3)
5068 (match-string 3 address)
5071 (defun gnus-url-parse-query-string (query &optional downcase)
5072 (let (retval pairs cur key val)
5073 (setq pairs (split-string query "&"))
5075 (setq cur (car pairs)
5077 (if (not (string-match "=" cur))
5079 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5080 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5082 (setq key (downcase key)))
5083 (setq cur (assoc key retval))
5085 (setcdr cur (cons val (cdr cur)))
5086 (setq retval (cons (list key val) retval)))))
5089 (defun gnus-url-unhex (x)
5096 (defun gnus-url-unhex-string (str &optional allow-newlines)
5097 "Remove %XXX embedded spaces, etc in a url.
5098 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5099 decoding of carriage returns and line feeds in the string, which is normally
5100 forbidden in URL encoding."
5101 (setq str (or str ""))
5103 (case-fold-search t))
5104 (while (string-match "%[0-9a-f][0-9a-f]" str)
5105 (let* ((start (match-beginning 0))
5106 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5108 (gnus-url-unhex (elt str (+ start 2))))))
5110 tmp (substring str 0 start)
5113 (char-to-string code))
5114 ((or (= code ?\n) (= code ?\r))
5116 (t (char-to-string code))))
5117 str (substring str (match-end 0)))))
5118 (setq tmp (concat tmp str))
5121 (defun gnus-url-mailto (url)
5122 ;; Send mail to someone
5123 (when (string-match "mailto:/*\\(.*\\)" url)
5124 (setq url (substring url (match-beginning 1) nil)))
5125 (let (to args subject func)
5126 (if (string-match (regexp-quote "?") url)
5127 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5128 args (gnus-url-parse-query-string
5129 (substring url (match-end 0) nil) t))
5130 (setq to (gnus-url-unhex-string url)))
5131 (setq args (cons (list "to" to) args)
5132 subject (cdr-safe (assoc "subject" args)))
5133 (gnus-setup-message 'reply
5136 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5139 (message-position-on-field (caar args)))
5140 (insert (mapconcat 'identity (cdar args) ", "))
5141 (setq args (cdr args)))
5144 (message-goto-subject)))))
5146 (defun gnus-button-mailto (address)
5148 (set-buffer (gnus-copy-article-buffer))
5149 (message-reply address))
5151 (defalias 'gnus-button-reply 'message-reply)
5153 (defun gnus-button-embedded-url (address)
5154 "Activate ADDRESS with `browse-url'."
5155 (browse-url (gnus-strip-whitespace address)))
5157 (defun gnus-article-smiley-display ()
5158 "Display \"smileys\" as small graphical icons."
5159 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5161 ;;; Next/prev buttons in the article buffer.
5163 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5164 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5166 (defvar gnus-prev-page-map nil)
5167 (unless gnus-prev-page-map
5168 (setq gnus-prev-page-map (make-sparse-keymap))
5169 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5170 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5172 (static-if (featurep 'xemacs)
5173 (defun gnus-insert-prev-page-button ()
5174 (let ((buffer-read-only nil))
5176 gnus-prev-page-line-format nil
5177 `(gnus-prev t local-map ,gnus-prev-page-map
5178 gnus-callback gnus-article-button-prev-page
5179 article-type annotation))))
5180 (defun gnus-insert-prev-page-button ()
5181 (let ((buffer-read-only nil)
5182 (situation (get-text-property (point-min) 'mime-view-situation)))
5183 (set-keymap-parent gnus-prev-page-map (current-local-map))
5185 gnus-prev-page-line-format nil
5186 `(gnus-prev t local-map ,gnus-prev-page-map
5187 gnus-callback gnus-article-button-prev-page
5188 article-type annotation
5189 mime-view-situation ,situation))))
5192 (defvar gnus-next-page-map nil)
5193 (unless gnus-next-page-map
5194 (setq gnus-next-page-map (make-sparse-keymap))
5195 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5196 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5198 (defun gnus-button-next-page ()
5199 "Go to the next page."
5201 (let ((win (selected-window)))
5202 (select-window (get-buffer-window gnus-article-buffer t))
5203 (gnus-article-next-page)
5204 (select-window win)))
5206 (defun gnus-button-prev-page ()
5207 "Go to the prev page."
5209 (let ((win (selected-window)))
5210 (select-window (get-buffer-window gnus-article-buffer t))
5211 (gnus-article-prev-page)
5212 (select-window win)))
5214 (static-if (featurep 'xemacs)
5215 (defun gnus-insert-next-page-button ()
5216 (let ((buffer-read-only nil))
5217 (gnus-eval-format gnus-next-page-line-format nil
5219 t local-map ,gnus-next-page-map
5220 gnus-callback gnus-article-button-next-page
5221 article-type annotation))))
5222 (defun gnus-insert-next-page-button ()
5223 (let ((buffer-read-only nil)
5224 (situation (get-text-property (point-min) 'mime-view-situation)))
5225 (set-keymap-parent gnus-next-page-map (current-local-map))
5226 (gnus-eval-format gnus-next-page-line-format nil
5228 t local-map ,gnus-next-page-map
5229 gnus-callback gnus-article-button-next-page
5230 article-type annotation
5231 mime-view-situation ,situation))))
5234 (defun gnus-article-button-next-page (arg)
5235 "Go to the next page."
5237 (let ((win (selected-window)))
5238 (select-window (get-buffer-window gnus-article-buffer t))
5239 (gnus-article-next-page)
5240 (select-window win)))
5242 (defun gnus-article-button-prev-page (arg)
5243 "Go to the prev page."
5245 (let ((win (selected-window)))
5246 (select-window (get-buffer-window gnus-article-buffer t))
5247 (gnus-article-prev-page)
5248 (select-window win)))
5250 (defvar gnus-decode-header-methods
5251 '(mail-decode-encoded-word-region)
5252 "List of methods used to decode headers.
5254 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5255 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5256 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5257 whose names match REGEXP.
5260 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5261 mail-decode-encoded-word-region
5262 (\"chinese\" . rfc1843-decode-region))
5265 (defvar gnus-decode-header-methods-cache nil)
5267 (defun gnus-multi-decode-header (start end)
5268 "Apply the functions from `gnus-encoded-word-methods' that match."
5269 (unless (and gnus-decode-header-methods-cache
5270 (eq gnus-newsgroup-name
5271 (car gnus-decode-header-methods-cache)))
5272 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5275 (nconc gnus-decode-header-methods-cache (list x))
5276 (if (and gnus-newsgroup-name
5277 (string-match (car x) gnus-newsgroup-name))
5278 (nconc gnus-decode-header-methods-cache
5280 gnus-decode-header-methods))
5281 (let ((xlist gnus-decode-header-methods-cache))
5284 (narrow-to-region start end)
5286 (funcall (pop xlist) (point-min) (point-max))))))
5289 ;;; Treatment top-level handling.
5292 (defun gnus-treat-article (condition &optional part-number total-parts type)
5293 (let ((length (- (point-max) (point-min)))
5294 (alist gnus-treatment-function-alist)
5295 (article-goto-body-goes-to-point-min-p t)
5299 (let ((list gnus-article-treat-types))
5301 (when (string-match (pop list) type)
5302 (throw 'found t)))))))
5303 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5304 (entity (static-unless (featurep 'xemacs)
5305 (when (eq 'head condition)
5306 (get-text-property (point-min) 'mime-view-entity))))
5307 val elem buttonized)
5308 (gnus-run-hooks 'gnus-part-display-hook)
5309 (unless gnus-inhibit-treatment
5310 (while (setq elem (pop alist))
5313 (if (gnus-buffer-live-p gnus-summary-buffer)
5314 (set-buffer gnus-summary-buffer))
5315 (symbol-value (car elem))))
5316 (when (and (or (consp val)
5318 (gnus-treat-predicate val)
5319 (or (not (get (car elem) 'highlight))
5321 (when (and (not buttonized)
5323 '(gnus-treat-hide-signature
5324 gnus-treat-highlight-signature)))
5325 (gnus-article-buttonize-signature)
5326 (setq buttonized t))
5328 (funcall (cadr elem)))))
5329 ;; FSF Emacsen does not inherit the existing text properties
5330 ;; in the new text, so we should do it for `mime-view-entity'.
5331 (static-unless (featurep 'xemacs)
5333 (put-text-property (point-min) (point-max)
5334 'mime-view-entity entity))))))
5336 ;; Dynamic variables.
5338 (defvar part-number)
5339 (defvar total-parts)
5344 (defun gnus-treat-predicate (val)
5349 (stringp (car val)))
5350 (apply 'gnus-or (mapcar `(lambda (s)
5351 (string-match s ,(or gnus-newsgroup-name "")))
5354 (let ((pred (pop val)))
5357 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5359 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5361 (not (gnus-treat-predicate (car val))))
5363 (equal (car val) type))
5365 (error "%S is not a valid predicate" pred)))))
5375 (eq part-number total-parts))
5379 (error "%S is not a valid value" val))))
5385 (defun gnus-article-header-presentation-method (entity situation)
5386 (mime-insert-header entity)
5389 (set-alist 'mime-header-presentation-method-alist
5390 'gnus-original-article-mode
5391 #'gnus-article-header-presentation-method)
5393 (defun gnus-mime-preview-quitting-method ()
5394 (mime-preview-kill-buffer)
5395 (delete-other-windows)
5396 (gnus-article-show-summary)
5397 (gnus-summary-select-article gnus-show-all-headers t))
5399 (set-alist 'mime-preview-quitting-method-alist
5400 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5402 (set-alist 'mime-preview-following-method-alist
5403 'gnus-original-article-mode #'gnus-following-method)
5405 (set-alist 'mime-preview-over-to-previous-method-alist
5406 'gnus-original-article-mode
5408 (if (> (point-min) 1)
5409 (gnus-article-prev-page)
5410 (gnus-article-read-summary-keys
5411 nil (gnus-character-to-event ?P)))))
5413 (set-alist 'mime-preview-over-to-next-method-alist
5414 'gnus-original-article-mode'
5416 (if (< (point-max) (buffer-size))
5417 (gnus-article-next-page)
5418 (gnus-article-read-summary-keys
5419 nil (gnus-character-to-event ?N)))))
5429 (run-hooks 'gnus-art-load-hook)
5431 ;;; gnus-art.el ends here