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))
41 ;; 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 ((and (fboundp 'image-type-available-p)
214 (or (image-type-available-p 'xpm)
215 (image-type-available-p 'xbm)))
216 'gnus-article-display-xface)
217 ((and (not gnus-xemacs)
219 (module-installed-p 'x-face-mule))
220 'x-face-mule-gnus-article-display-x-face)
222 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"))
223 "*String or function to be executed to display an X-Face header.
224 If it is a string, the command will be executed in a sub-shell
225 asynchronously. The compressed face will be piped to this command."
226 :type '(choice string
227 (function-item gnus-article-display-xface)
228 (function-item x-face-mule-gnus-article-display-x-face)
230 :group 'gnus-article-washing)
232 (defcustom gnus-article-x-face-too-ugly nil
233 "Regexp matching posters whose face shouldn't be shown automatically."
234 :type '(choice regexp (const nil))
235 :group 'gnus-article-washing)
237 (defcustom gnus-emphasis-alist
239 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
241 '(("_" "_" underline)
244 ("_/" "/_" underline-italic)
245 ("_\\*" "\\*_" underline-bold)
246 ("\\*/" "/\\*" bold-italic)
247 ("_\\*/" "/\\*_" underline-bold-italic))))
248 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
249 2 3 gnus-emphasis-underline)
253 (format format (car spec) (car (cdr spec)))
254 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
256 "*Alist that says how to fontify certain phrases.
257 Each item looks like this:
259 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
261 The first element is a regular expression to be matched. The second
262 is a number that says what regular expression grouping used to find
263 the entire emphasized word. The third is a number that says what
264 regexp grouping should be displayed and highlighted. The fourth
265 is the face used for highlighting."
266 :type '(repeat (list :value ("" 0 0 default)
268 (integer :tag "Match group")
269 (integer :tag "Emphasize group")
271 :group 'gnus-article-emphasis)
273 (defface gnus-emphasis-bold '((t (:bold t)))
274 "Face used for displaying strong emphasized text (*word*)."
275 :group 'gnus-article-emphasis)
277 (defface gnus-emphasis-italic '((t (:italic t)))
278 "Face used for displaying italic emphasized text (/word/)."
279 :group 'gnus-article-emphasis)
281 (defface gnus-emphasis-underline '((t (:underline t)))
282 "Face used for displaying underlined emphasized text (_word_)."
283 :group 'gnus-article-emphasis)
285 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
286 "Face used for displaying underlined bold emphasized text (_*word*_)."
287 :group 'gnus-article-emphasis)
289 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
290 "Face used for displaying underlined italic emphasized text (_/word/_)."
291 :group 'gnus-article-emphasis)
293 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
294 "Face used for displaying bold italic emphasized text (/*word*/)."
295 :group 'gnus-article-emphasis)
297 (defface gnus-emphasis-underline-bold-italic
298 '((t (:bold t :italic t :underline t)))
299 "Face used for displaying underlined bold italic emphasized text.
300 Esample: (_/*word*/_)."
301 :group 'gnus-article-emphasis)
303 (defface gnus-emphasis-highlight-words
304 '((t (:background "black" :foreground "yellow")))
305 "Face used for displaying highlighted words."
306 :group 'gnus-article-emphasis)
308 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
309 "Format for display of Date headers in article bodies.
310 See `format-time-string' for the possible values.
312 The variable can also be function, which should return a complete Date
313 header. The function is called with one argument, the time, which can
314 be fed to `format-time-string'."
315 :type '(choice string symbol)
316 :link '(custom-manual "(gnus)Article Date")
317 :group 'gnus-article-washing)
320 (autoload 'mail-extract-address-components "mail-extr"))
322 (defcustom gnus-save-all-headers t
323 "*If non-nil, don't remove any headers before saving."
324 :group 'gnus-article-saving
327 (defcustom gnus-prompt-before-saving 'always
328 "*This variable says how much prompting is to be done when saving articles.
329 If it is nil, no prompting will be done, and the articles will be
330 saved to the default files. If this variable is `always', each and
331 every article that is saved will be preceded by a prompt, even when
332 saving large batches of articles. If this variable is neither nil not
333 `always', there the user will be prompted once for a file name for
334 each invocation of the saving commands."
335 :group 'gnus-article-saving
336 :type '(choice (item always)
337 (item :tag "never" nil)
338 (sexp :tag "once" :format "%t\n" :value t)))
340 (defcustom gnus-saved-headers gnus-visible-headers
341 "Headers to keep if `gnus-save-all-headers' is nil.
342 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
343 If that variable is nil, however, all headers that match this regexp
344 will be kept while the rest will be deleted before saving."
345 :group 'gnus-article-saving
348 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
349 "A function to save articles in your favourite format.
350 The function must be interactively callable (in other words, it must
351 be an Emacs command).
353 Gnus provides the following functions:
355 * gnus-summary-save-in-rmail (Rmail format)
356 * gnus-summary-save-in-mail (Unix mail format)
357 * gnus-summary-save-in-folder (MH folder)
358 * gnus-summary-save-in-file (article format)
359 * gnus-summary-save-in-vm (use VM's folder format)
360 * gnus-summary-write-to-file (article format -- overwrite)."
361 :group 'gnus-article-saving
362 :type '(radio (function-item gnus-summary-save-in-rmail)
363 (function-item gnus-summary-save-in-mail)
364 (function-item gnus-summary-save-in-folder)
365 (function-item gnus-summary-save-in-file)
366 (function-item gnus-summary-save-in-vm)
367 (function-item gnus-summary-write-to-file)))
369 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
370 "A function generating a file name to save articles in Rmail format.
371 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
372 :group 'gnus-article-saving
375 (defcustom gnus-mail-save-name 'gnus-plain-save-name
376 "A function generating a file name to save articles in Unix mail format.
377 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
378 :group 'gnus-article-saving
381 (defcustom gnus-folder-save-name 'gnus-folder-save-name
382 "A function generating a file name to save articles in MH folder.
383 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
384 :group 'gnus-article-saving
387 (defcustom gnus-file-save-name 'gnus-numeric-save-name
388 "A function generating a file name to save articles in article format.
389 The function is called with NEWSGROUP, HEADERS, and optional
391 :group 'gnus-article-saving
394 (defcustom gnus-split-methods
395 '((gnus-article-archive-name)
396 (gnus-article-nndoc-name))
397 "*Variable used to suggest where articles are to be saved.
398 For instance, if you would like to save articles related to Gnus in
399 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
400 you could set this variable to something like:
402 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
403 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
405 This variable is an alist where the where the key is the match and the
406 value is a list of possible files to save in if the match is non-nil.
408 If the match is a string, it is used as a regexp match on the
409 article. If the match is a symbol, that symbol will be funcalled
410 from the buffer of the article to be saved with the newsgroup as the
411 parameter. If it is a list, it will be evaled in the same buffer.
413 If this form or function returns a string, this string will be used as
414 a possible file name; and if it returns a non-nil list, that list will
415 be used as possible file names."
416 :group 'gnus-article-saving
417 :type '(repeat (choice (list :value (fun) function)
418 (cons :value ("" "") regexp (repeat string))
421 (defcustom gnus-article-display-method-for-mime
422 'gnus-article-display-mime-message
423 "Function to display a MIME message.
424 The function is called from the article buffer."
425 :group 'gnus-article-mime
428 (defcustom gnus-article-display-method-for-traditional
429 'gnus-article-display-traditional-message
430 "*Function to display a traditional message.
431 The function is called from the article buffer."
432 :group 'gnus-article-mime
435 (defcustom gnus-page-delimiter "^\^L"
436 "*Regexp describing what to use as article page delimiters.
437 The default value is \"^\^L\", which is a form linefeed at the
438 beginning of a line."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
443 "*The format specification for the article mode line.
444 See `gnus-summary-mode-line-format' for a closer description.
446 The following additional specs are available:
448 %w The article washing status.
449 %m The number of MIME parts in the article."
451 :group 'gnus-article-various)
453 (defcustom gnus-article-mode-hook nil
454 "*A hook for Gnus article mode."
456 :group 'gnus-article-various)
458 (defcustom gnus-article-menu-hook nil
459 "*Hook run after the creation of the article mode menu."
461 :group 'gnus-article-various)
463 (defcustom gnus-article-prepare-hook nil
464 "*A hook called after an article has been prepared in the article buffer."
466 :group 'gnus-article-various)
468 (defcustom gnus-article-hide-pgp-hook nil
469 "*A hook called after successfully hiding a PGP signature."
471 :group 'gnus-article-various)
473 (defcustom gnus-article-button-face 'bold
474 "Face used for highlighting buttons in the article buffer.
476 An article button is a piece of text that you can activate by pressing
477 `RET' or `mouse-2' above it."
479 :group 'gnus-article-buttons)
481 (defcustom gnus-article-mouse-face 'highlight
482 "Face used for mouse highlighting in the article buffer.
484 Article buttons will be displayed in this face when the cursor is
487 :group 'gnus-article-buttons)
489 (defcustom gnus-signature-face 'gnus-signature-face
490 "Face used for highlighting a signature in the article buffer.
491 Obsolete; use the face `gnus-signature-face' for customizations instead."
493 :group 'gnus-article-highlight
494 :group 'gnus-article-signature)
496 (defface gnus-signature-face
498 "Face used for highlighting a signature in the article buffer."
499 :group 'gnus-article-highlight
500 :group 'gnus-article-signature)
502 (defface gnus-header-from-face
505 (:foreground "spring green"))
508 (:foreground "red3"))
511 "Face used for displaying from headers."
512 :group 'gnus-article-headers
513 :group 'gnus-article-highlight)
515 (defface gnus-header-subject-face
518 (:foreground "SeaGreen3"))
521 (:foreground "red4"))
523 (:bold t :italic t)))
524 "Face used for displaying subject headers."
525 :group 'gnus-article-headers
526 :group 'gnus-article-highlight)
528 (defface gnus-header-newsgroups-face
531 (:foreground "yellow" :italic t))
534 (:foreground "MidnightBlue" :italic t))
537 "Face used for displaying newsgroups headers."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight)
541 (defface gnus-header-name-face
544 (:foreground "SeaGreen"))
547 (:foreground "maroon"))
550 "Face used for displaying header names."
551 :group 'gnus-article-headers
552 :group 'gnus-article-highlight)
554 (defface gnus-header-content-face
557 (:foreground "forest green" :italic t))
560 (:foreground "indianred4" :italic t))
562 (:italic t))) "Face used for displaying header content."
563 :group 'gnus-article-headers
564 :group 'gnus-article-highlight)
566 (defcustom gnus-header-face-alist
567 '(("From" nil gnus-header-from-face)
568 ("Subject" nil gnus-header-subject-face)
569 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
570 ("" gnus-header-name-face gnus-header-content-face))
571 "*Controls highlighting of article header.
573 An alist of the form (HEADER NAME CONTENT).
575 HEADER is a regular expression which should match the name of an
576 header header and NAME and CONTENT are either face names or nil.
578 The name of each header field will be displayed using the face
579 specified by the first element in the list where HEADER match the
580 header name and NAME is non-nil. Similarly, the content will be
581 displayed by the first non-nil matching CONTENT face."
582 :group 'gnus-article-headers
583 :group 'gnus-article-highlight
584 :type '(repeat (list (regexp :tag "Header")
586 (item :tag "skip" nil)
587 (face :value default))
588 (choice :tag "Content"
589 (item :tag "skip" nil)
590 (face :value default)))))
592 (defcustom gnus-article-decode-hook nil
593 "*Hook run to decode charsets in articles."
594 :group 'gnus-article-headers
597 (defcustom gnus-display-mime-function 'gnus-display-mime
598 "Function to display MIME articles."
599 :group 'gnus-article-mime
602 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
603 "Function used to decode headers.")
605 (defvar gnus-article-dumbquotes-map
623 "Table for MS-to-Latin1 translation.")
625 (defcustom gnus-ignored-mime-types nil
626 "List of MIME types that should be ignored by Gnus."
627 :group 'gnus-article-mime
628 :type '(repeat regexp))
630 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
631 "List of MIME types that should not be given buttons when rendered inline."
632 :group 'gnus-article-mime
633 :type '(repeat regexp))
635 (defcustom gnus-article-mime-part-function nil
636 "Function called with a MIME handle as the argument.
637 This is meant for people who want to do something automatic based
638 on parts -- for instance, adding Vcard info to a database."
639 :group 'gnus-article-mime
642 (defcustom gnus-mime-multipart-functions nil
643 "An alist of MIME types to functions to display them.")
645 (defcustom gnus-article-date-lapsed-new-header nil
646 "Whether the X-Sent and Date headers can coexist.
647 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
648 either replace the old \"Date:\" header (if this variable is nil), or
649 be added below it (otherwise)."
650 :group 'gnus-article-headers
653 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
654 "Function called with a MIME handle as the argument.
655 This is meant for people who want to view first matched part.
656 For `undisplayed-alternative' (default), the first undisplayed
657 part or alternative part is used. For `undisplayed', the first
658 undisplayed part is used. For a function, the first part which
659 the function return `t' is used. For `nil', the first part is
661 :group 'gnus-article-mime
663 (item :tag "first" :value nil)
664 (item :tag "undisplayed" :value undisplayed)
665 (item :tag "undisplayed or alternative"
666 :value undisplayed-alternative)
670 ;;; The treatment variables
673 (defvar gnus-part-display-hook nil
674 "Hook called on parts that are to receive treatment.")
676 (defvar gnus-article-treat-custom
677 '(choice (const :tag "Off" nil)
679 (const :tag "Header" head)
680 (const :tag "Last" last)
681 (const :tag "Mime" mime)
682 (integer :tag "Less")
683 (repeat :tag "Groups" regexp)
684 (sexp :tag "Predicate")))
686 (defvar gnus-article-treat-head-custom
687 '(choice (const :tag "Off" nil)
688 (const :tag "Header" head)))
690 (defvar gnus-article-treat-types '("text/plain")
693 (defvar gnus-inhibit-treatment nil
694 "Whether to inhibit treatment.")
696 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
697 "Highlight the signature.
698 Valid values are nil, t, `head', `last', an integer or a predicate.
699 See the manual for details."
700 :group 'gnus-article-treat
701 :type gnus-article-treat-custom)
702 (put 'gnus-treat-highlight-signature 'highlight t)
704 (defcustom gnus-treat-buttonize 100000
706 Valid values are nil, t, `head', `last', an integer or a predicate.
707 See the manual for details."
708 :group 'gnus-article-treat
709 :type gnus-article-treat-custom)
710 (put 'gnus-treat-buttonize 'highlight t)
712 (defcustom gnus-treat-buttonize-head 'head
713 "Add buttons to the head.
714 Valid values are nil, t, `head', `last', an integer or a predicate.
715 See the manual for details."
716 :group 'gnus-article-treat
717 :type gnus-article-treat-head-custom)
718 (put 'gnus-treat-buttonize-head 'highlight t)
720 (defcustom gnus-treat-emphasize nil
722 Valid values are nil, t, `head', `last', an integer or a predicate.
723 See the manual for details."
724 :group 'gnus-article-treat
725 :type gnus-article-treat-custom)
726 (put 'gnus-treat-emphasize 'highlight t)
728 (defcustom gnus-treat-strip-cr nil
729 "Remove carriage returns.
730 Valid values are nil, t, `head', `last', an integer or a predicate.
731 See the manual for details."
732 :group 'gnus-article-treat
733 :type gnus-article-treat-custom)
735 (defcustom gnus-treat-hide-headers 'head
737 Valid values are nil, t, `head', `last', an integer or a predicate.
738 See the manual for details."
739 :group 'gnus-article-treat
740 :type gnus-article-treat-head-custom)
742 (defcustom gnus-treat-hide-boring-headers nil
743 "Hide boring headers.
744 Valid values are nil, t, `head', `last', an integer or a predicate.
745 See the manual for details."
746 :group 'gnus-article-treat
747 :type gnus-article-treat-head-custom)
749 (defcustom gnus-treat-hide-signature nil
751 Valid values are nil, t, `head', `last', an integer or a predicate.
752 See the manual for details."
753 :group 'gnus-article-treat
754 :type gnus-article-treat-custom)
756 (defcustom gnus-treat-fill-article nil
758 Valid values are nil, t, `head', `last', an integer or a predicate.
759 See the manual for details."
760 :group 'gnus-article-treat
761 :type gnus-article-treat-custom)
763 (defcustom gnus-treat-hide-citation nil
765 Valid values are nil, t, `head', `last', an integer or a predicate.
766 See the manual for details."
767 :group 'gnus-article-treat
768 :type gnus-article-treat-custom)
770 (defcustom gnus-treat-strip-list-identifiers 'head
771 "Strip list identifiers from `gnus-list-identifiers`.
772 Valid values are nil, t, `head', `last', an integer or a predicate.
773 See the manual for details."
774 :group 'gnus-article-treat
775 :type gnus-article-treat-custom)
777 (defcustom gnus-treat-strip-pgp t
778 "Strip PGP signatures.
779 Valid values are nil, t, `head', `last', an integer or a predicate.
780 See the manual for details."
781 :group 'gnus-article-treat
782 :type gnus-article-treat-custom)
784 (defcustom gnus-treat-strip-pem nil
785 "Strip PEM signatures.
786 Valid values are nil, t, `head', `last', an integer or a predicate.
787 See the manual for details."
788 :group 'gnus-article-treat
789 :type gnus-article-treat-custom)
791 (defcustom gnus-treat-strip-banner t
792 "Strip banners from articles.
793 The banner to be stripped is specified in the `banner' group parameter.
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-custom)
799 (defcustom gnus-treat-highlight-headers 'head
800 "Highlight the headers.
801 Valid values are nil, t, `head', `last', an integer or a predicate.
802 See the manual for details."
803 :group 'gnus-article-treat
804 :type gnus-article-treat-head-custom)
805 (put 'gnus-treat-highlight-headers 'highlight t)
807 (defcustom gnus-treat-highlight-citation t
808 "Highlight cited text.
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-custom)
813 (put 'gnus-treat-highlight-citation 'highlight t)
815 (defcustom gnus-treat-date-ut nil
816 "Display the Date in UT (GMT).
817 Valid values are nil, t, `head', `last', an integer or a predicate.
818 See the manual for details."
819 :group 'gnus-article-treat
820 :type gnus-article-treat-head-custom)
822 (defcustom gnus-treat-date-local nil
823 "Display the Date in the local timezone.
824 Valid values are nil, t, `head', `last', an integer or a predicate.
825 See the manual for details."
826 :group 'gnus-article-treat
827 :type gnus-article-treat-head-custom)
829 (defcustom gnus-treat-date-lapsed nil
830 "Display the Date header in a way that says how much time has elapsed.
831 Valid values are nil, t, `head', `last', an integer or a predicate.
832 See the manual for details."
833 :group 'gnus-article-treat
834 :type gnus-article-treat-head-custom)
836 (defcustom gnus-treat-date-original nil
837 "Display the date in the original timezone.
838 Valid values are nil, t, `head', `last', an integer or a predicate.
839 See the manual for details."
840 :group 'gnus-article-treat
841 :type gnus-article-treat-head-custom)
843 (defcustom gnus-treat-date-iso8601 nil
844 "Display the date in the ISO8601 format.
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847 :group 'gnus-article-treat
848 :type gnus-article-treat-head-custom)
850 (defcustom gnus-treat-date-user-defined nil
851 "Display the date in a user-defined format.
852 The format is defined by the `gnus-article-time-format' variable.
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-head-custom)
858 (defcustom gnus-treat-strip-headers-in-body t
859 "Strip the X-No-Archive header line from the beginning of the body.
860 Valid values are nil, t, `head', `last', an integer or a predicate.
861 See the manual for details."
862 :group 'gnus-article-treat
863 :type gnus-article-treat-custom)
865 (defcustom gnus-treat-strip-trailing-blank-lines nil
866 "Strip trailing blank lines.
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-custom)
872 (defcustom gnus-treat-strip-leading-blank-lines nil
873 "Strip leading blank lines.
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
876 :group 'gnus-article-treat
877 :type gnus-article-treat-custom)
879 (defcustom gnus-treat-strip-multiple-blank-lines nil
880 "Strip multiple blank lines.
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See the manual for details."
883 :group 'gnus-article-treat
884 :type gnus-article-treat-custom)
886 (defcustom gnus-treat-overstrike t
887 "Treat overstrike highlighting.
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-custom)
892 (put 'gnus-treat-overstrike 'highlight t)
894 (defcustom gnus-treat-display-xface
895 (if (or (and gnus-xemacs (featurep 'xface))
896 (eq 'x-face-mule-gnus-article-display-x-face
897 gnus-article-x-face-command))
900 "Display X-Face headers.
901 Valid values are nil, t, `head', `last', an integer or a predicate.
902 See the manual for details."
903 :group 'gnus-article-treat
904 :type gnus-article-treat-head-custom)
905 (put 'gnus-treat-display-xface 'highlight t)
907 (defcustom gnus-treat-display-smileys
908 (if (or (and gnus-xemacs (featurep 'xpm))
909 (and (not gnus-xemacs)
911 (module-installed-p 'gnus-bitmap)))
915 Valid values are nil, t, `head', `last', an integer or a predicate.
916 See the manual for details."
917 :group 'gnus-article-treat
918 :type gnus-article-treat-custom)
919 (put 'gnus-treat-display-smileys 'highlight t)
921 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
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-head-custom)
927 (put 'gnus-treat-display-picons 'highlight t)
929 (defcustom gnus-treat-capitalize-sentences nil
930 "Capitalize sentence-starting words.
931 Valid values are nil, t, `head', `last', an integer or a predicate.
932 See the manual for details."
933 :group 'gnus-article-treat
934 :type gnus-article-treat-custom)
936 (defcustom gnus-treat-fill-long-lines nil
938 Valid values are nil, t, `head', `last', an integer or a predicate.
939 See the manual for details."
940 :group 'gnus-article-treat
941 :type gnus-article-treat-custom)
943 (defcustom gnus-treat-play-sounds nil
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-custom)
950 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
951 "Decode an article as `default-mime-charset'. For instance, if you want to
952 attempt to decode an article even if the value of `gnus-show-mime' is nil,
953 you could set this variable to something like: nil for don't decode, t for
954 decode the body, '(or header t) for the whole article, etc."
955 :group 'gnus-article-treat
956 :type '(radio (const :tag "Off" nil)
957 (const :tag "Decode body" t)
958 (const :tag "Decode all" (or head t))))
960 (defcustom gnus-treat-translate nil
961 "Translate articles from one language to another.
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See the manual for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-custom)
967 ;;; Internal variables
969 (defvar article-goto-body-goes-to-point-min-p nil)
970 (defvar gnus-article-wash-types nil)
971 (defvar gnus-article-emphasis-alist nil)
973 (defvar gnus-article-mime-handle-alist-1 nil)
974 (defvar gnus-treatment-function-alist
975 '((gnus-treat-decode-article-as-default-mime-charset
976 gnus-article-decode-article-as-default-mime-charset)
977 (gnus-treat-strip-banner gnus-article-strip-banner)
978 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
979 (gnus-treat-buttonize gnus-article-add-buttons)
980 (gnus-treat-fill-article gnus-article-fill-cited-article)
981 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
982 (gnus-treat-strip-cr gnus-article-remove-cr)
983 (gnus-treat-display-xface gnus-article-display-x-face)
984 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
985 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
986 (gnus-treat-hide-signature gnus-article-hide-signature)
987 (gnus-treat-hide-citation gnus-article-hide-citation)
988 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
989 (gnus-treat-strip-pgp gnus-article-hide-pgp)
990 (gnus-treat-strip-pem gnus-article-hide-pem)
991 (gnus-treat-highlight-headers gnus-article-highlight-headers)
992 (gnus-treat-emphasize gnus-article-emphasize)
993 (gnus-treat-highlight-citation gnus-article-highlight-citation)
994 (gnus-treat-highlight-signature gnus-article-highlight-signature)
995 (gnus-treat-date-ut gnus-article-date-ut)
996 (gnus-treat-date-local gnus-article-date-local)
997 (gnus-treat-date-lapsed gnus-article-date-lapsed)
998 (gnus-treat-date-original gnus-article-date-original)
999 (gnus-treat-date-user-defined gnus-article-date-user)
1000 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1001 (gnus-treat-strip-trailing-blank-lines
1002 gnus-article-remove-trailing-blank-lines)
1003 (gnus-treat-strip-leading-blank-lines
1004 gnus-article-strip-leading-blank-lines)
1005 (gnus-treat-strip-multiple-blank-lines
1006 gnus-article-strip-multiple-blank-lines)
1007 (gnus-treat-overstrike gnus-article-treat-overstrike)
1008 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1009 (gnus-treat-display-smileys gnus-article-smiley-display)
1010 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1011 (gnus-treat-display-picons gnus-article-display-picons)
1012 (gnus-treat-play-sounds gnus-earcon-display)))
1014 (defvar gnus-article-mime-handle-alist nil)
1015 (defvar article-lapsed-timer nil)
1016 (defvar gnus-article-current-summary nil)
1018 (defvar gnus-article-mode-syntax-table
1019 (let ((table (copy-syntax-table text-mode-syntax-table)))
1020 (modify-syntax-entry ?- "w" table)
1021 (modify-syntax-entry ?> ")" table)
1022 (modify-syntax-entry ?< "(" table)
1024 "Syntax table used in article mode buffers.
1025 Initialized from `text-mode-syntax-table.")
1027 (defvar gnus-save-article-buffer nil)
1029 (defvar gnus-article-mode-line-format-alist
1030 (nconc '((?w (gnus-article-wash-status) ?s)
1031 (?m (gnus-article-mime-part-status) ?s))
1032 gnus-summary-mode-line-format-alist))
1034 (defvar gnus-number-of-articles-to-be-saved nil)
1036 (defvar gnus-inhibit-hiding nil)
1038 (defsubst gnus-article-hide-text (b e props)
1039 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1040 (add-text-properties b e props)
1041 (when (memq 'intangible props)
1043 (max (1- b) (point-min))
1044 b 'intangible (cddr (memq 'intangible props)))))
1045 (defsubst gnus-article-unhide-text (b e)
1046 "Remove hidden text properties from region between B and E."
1047 (remove-text-properties b e gnus-hidden-properties)
1048 (when (memq 'intangible gnus-hidden-properties)
1049 (put-text-property (max (1- b) (point-min))
1050 b 'intangible nil)))
1052 (defun gnus-article-hide-text-type (b e type)
1053 "Hide text of TYPE between B and E."
1054 (push type gnus-article-wash-types)
1055 (gnus-article-hide-text
1056 b e (cons 'article-type (cons type gnus-hidden-properties))))
1058 (defun gnus-article-unhide-text-type (b e type)
1059 "Unhide text of TYPE between B and E."
1060 (setq gnus-article-wash-types
1061 (delq type gnus-article-wash-types))
1062 (remove-text-properties
1063 b e (cons 'article-type (cons type gnus-hidden-properties)))
1064 (when (memq 'intangible gnus-hidden-properties)
1065 (put-text-property (max (1- b) (point-min))
1066 b 'intangible nil)))
1068 (defun gnus-article-hide-text-of-type (type)
1069 "Hide text of TYPE in the current buffer."
1071 (let ((b (point-min))
1073 (while (setq b (text-property-any b e 'article-type type))
1074 (add-text-properties b (incf b) gnus-hidden-properties)))))
1076 (defun gnus-article-delete-text-of-type (type)
1077 "Delete text of TYPE in the current buffer."
1079 (let ((b (point-min)))
1080 (while (setq b (text-property-any b (point-max) 'article-type type))
1082 b (or (text-property-not-all b (point-max) 'article-type type)
1085 (defun gnus-article-delete-invisible-text ()
1086 "Delete all invisible text in the current buffer."
1088 (let ((b (point-min)))
1089 (while (setq b (text-property-any b (point-max) 'invisible t))
1091 b (or (text-property-not-all b (point-max) 'invisible t)
1094 (defun gnus-article-text-type-exists-p (type)
1095 "Say whether any text of type TYPE exists in the buffer."
1096 (text-property-any (point-min) (point-max) 'article-type type))
1098 (defsubst gnus-article-header-rank ()
1099 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1100 (let ((list gnus-sorted-header-list)
1103 (when (looking-at (car list))
1105 (setq list (cdr list))
1109 (defun article-hide-headers (&optional arg delete)
1110 "Hide unwanted headers and possibly sort them as well."
1111 (interactive (gnus-article-hidden-arg))
1112 ;; Lars said that this function might be inhibited.
1113 (if (gnus-article-check-hidden-text 'headers arg)
1115 ;; Show boring headers as well.
1116 (gnus-article-show-hidden-text 'boring-headers)
1117 (when (eq 1 (point-min))
1118 (set-window-start (get-buffer-window (current-buffer)) 1)))
1119 (unless gnus-inhibit-hiding
1122 (let ((buffer-read-only nil)
1123 (inhibit-read-only t)
1124 (case-fold-search t)
1125 (max (1+ (length gnus-sorted-header-list)))
1126 (ignored (when (not gnus-visible-headers)
1127 (cond ((stringp gnus-ignored-headers)
1128 gnus-ignored-headers)
1129 ((listp gnus-ignored-headers)
1130 (mapconcat 'identity gnus-ignored-headers
1133 (cond ((stringp gnus-visible-headers)
1134 gnus-visible-headers)
1135 ((and gnus-visible-headers
1136 (listp gnus-visible-headers))
1137 (mapconcat 'identity gnus-visible-headers "\\|"))))
1138 (inhibit-point-motion-hooks t)
1140 ;; First we narrow to just the headers.
1141 (article-narrow-to-head)
1142 ;; Hide any "From " lines at the beginning of (mail) articles.
1143 (while (looking-at "From ")
1147 (delete-region (point-min) (point))
1148 (gnus-article-hide-text (point-min) (point)
1149 (nconc (list 'article-type 'headers)
1150 gnus-hidden-properties))))
1151 ;; Then treat the rest of the header lines.
1152 ;; Then we use the two regular expressions
1153 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1154 ;; select which header lines is to remain visible in the
1156 (while (re-search-forward "^[^ \t]*:" nil t)
1158 ;; Mark the rank of the header.
1160 (point) (1+ (point)) 'message-rank
1161 (if (or (and visible (looking-at visible))
1163 (not (looking-at ignored))))
1164 (gnus-article-header-rank)
1167 (message-sort-headers-1)
1168 (when (setq beg (text-property-any
1169 (point-min) (point-max) 'message-rank (+ 2 max)))
1170 ;; We delete or make invisible the unwanted headers.
1171 (push 'headers gnus-article-wash-types)
1174 (add-text-properties
1175 (point-min) (+ 5 (point-min))
1176 '(article-type headers dummy-invisible t))
1177 (delete-region beg (point-max)))
1178 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1181 (defun article-hide-boring-headers (&optional arg)
1182 "Toggle hiding of headers that aren't very interesting.
1183 If given a negative prefix, always show; if given a positive prefix,
1185 (interactive (gnus-article-hidden-arg))
1186 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1187 (not gnus-show-all-headers))
1190 (let ((buffer-read-only nil)
1191 (list gnus-boring-article-headers)
1192 (inhibit-point-motion-hooks t)
1194 (article-narrow-to-head)
1196 (setq elem (pop list))
1197 (goto-char (point-min))
1199 ;; Hide empty headers.
1201 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1203 (gnus-article-hide-text-type
1204 (progn (beginning-of-line) (point))
1207 (if (re-search-forward "^[^ \t]" nil t)
1211 ;; Hide boring Newsgroups header.
1212 ((eq elem 'newsgroups)
1213 (when (equal (gnus-fetch-field "newsgroups")
1214 (gnus-group-real-name
1215 (if (boundp 'gnus-newsgroup-name)
1218 (gnus-article-hide-header "newsgroups")))
1219 ((eq elem 'followup-to)
1220 (when (equal (message-fetch-field "followup-to")
1221 (message-fetch-field "newsgroups"))
1222 (gnus-article-hide-header "followup-to")))
1223 ((eq elem 'reply-to)
1224 (let ((from (message-fetch-field "from"))
1225 (reply-to (message-fetch-field "reply-to")))
1230 (nth 1 (funcall gnus-extract-address-components from))
1231 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1232 (gnus-article-hide-header "reply-to"))))
1234 (let ((date (message-fetch-field "date")))
1236 (< (days-between (current-time-string) date)
1238 (gnus-article-hide-header "date"))))
1240 (let ((to (message-fetch-field "to"))
1241 (cc (message-fetch-field "cc")))
1242 (when (> (length to) 1024)
1243 (gnus-article-hide-header "to"))
1244 (when (> (length cc) 1024)
1245 (gnus-article-hide-header "cc"))))
1249 (goto-char (point-min))
1250 (while (re-search-forward "^to:" nil t)
1251 (setq to-count (1+ to-count)))
1252 (when (> to-count 1)
1253 (while (> to-count 0)
1254 (goto-char (point-min))
1256 (re-search-forward "^to:" nil nil to-count)
1258 (narrow-to-region (point) (point-max))
1259 (gnus-article-hide-header "to"))
1260 (setq to-count (1- to-count))))
1261 (goto-char (point-min))
1262 (while (re-search-forward "^cc:" nil t)
1263 (setq cc-count (1+ cc-count)))
1264 (when (> cc-count 1)
1265 (while (> cc-count 0)
1266 (goto-char (point-min))
1268 (re-search-forward "^cc:" nil nil cc-count)
1270 (narrow-to-region (point) (point-max))
1271 (gnus-article-hide-header "cc"))
1272 (setq cc-count (1- cc-count)))))))))))))
1274 (defun gnus-article-hide-header (header)
1276 (goto-char (point-min))
1277 (when (re-search-forward (concat "^" header ":") nil t)
1278 (gnus-article-hide-text-type
1279 (progn (beginning-of-line) (point))
1282 (if (re-search-forward "^[^ \t]" nil t)
1287 (defun article-toggle-headers (&optional arg)
1288 "Toggle hiding of headers. If given a negative prefix, always show;
1289 if given a positive prefix, always hide."
1290 (interactive (gnus-article-hidden-arg))
1291 (let ((force (when (numberp arg)
1292 (cond ((> arg 0) 'always-hide)
1293 ((< arg 0) 'always-show))))
1294 (window (get-buffer-window gnus-article-buffer))
1295 (header-end (point-min))
1296 header-start field-end field-start
1297 (inhibit-point-motion-hooks t)
1298 (inhibit-read-only t)
1302 (while (and (setq header-start
1303 (text-property-any header-end (point-max)
1304 'article-treated-header t))
1306 (text-property-not-all header-start (point-max)
1307 'article-treated-header t)))
1308 (setq field-end header-start)
1310 (;; Hide exposed invisible fields.
1311 (and (not (eq 'always-show force))
1313 (text-property-any field-end header-end
1314 'exposed-invisible-field t)))
1315 (while (and field-start
1316 (setq field-end (text-property-not-all
1317 field-start header-end
1318 'exposed-invisible-field t)))
1319 (add-text-properties field-start field-end gnus-hidden-properties)
1320 (setq field-start (text-property-any field-end header-end
1321 'exposed-invisible-field t)))
1322 (put-text-property header-start header-end
1323 'exposed-invisible-field nil))
1324 (;; Expose invisible fields.
1325 (and (not (eq 'always-hide force))
1327 (text-property-any field-end header-end 'invisible t)))
1328 (while (and field-start
1329 (setq field-end (text-property-not-all
1330 field-start header-end
1332 ;; If the invisible text is not terminated with newline, we
1333 ;; won't expose it. Because it may be created by x-face-mule.
1334 ;; BTW, XEmacs sometimes fail in putting a invisible text
1335 ;; property with `gnus-article-hide-text' (really?). In that
1336 ;; case, the invisible text might be started from the middle of
1337 ;; a line so we will expose the sort of thing.
1338 (when (or (not (or (eq header-start field-start)
1339 (eq ?\n (char-before field-start))))
1340 (eq ?\n (char-before field-end)))
1341 (remove-text-properties field-start field-end
1342 gnus-hidden-properties)
1343 (put-text-property field-start field-end
1344 'exposed-invisible-field t))
1345 (setq field-start (text-property-any field-end header-end
1348 (not (eq 'always-show force))
1349 (narrow-to-region header-start header-end)
1350 (article-hide-headers)
1351 ;; Re-display X-Face image under XEmacs.
1352 (when (and gnus-xemacs
1353 (gnus-functionp gnus-article-x-face-command))
1354 (let ((func (cadr (assq 'gnus-treat-display-xface
1355 gnus-treatment-function-alist)))
1357 (when (and (not gnus-inhibit-treatment)
1359 (gnus-treat-predicate gnus-treat-display-xface))
1361 (put-text-property header-start header-end 'read-only nil))))
1364 (goto-char (point-min))
1366 (set-window-start window (point-min))))))
1368 (defvar gnus-article-normalized-header-length 40
1369 "Length of normalized headers.")
1371 (defun article-normalize-headers ()
1372 "Make all header lines 40 characters long."
1374 (let ((buffer-read-only nil)
1378 (article-narrow-to-head)
1381 ((< (setq column (- (gnus-point-at-eol) (point)))
1382 gnus-article-normalized-header-length)
1384 (insert (make-string
1385 (- gnus-article-normalized-header-length column)
1387 ((> column gnus-article-normalized-header-length)
1388 (gnus-put-text-property
1390 (forward-char gnus-article-normalized-header-length)
1397 (forward-line 1))))))
1399 (defun article-treat-dumbquotes ()
1400 "Translate M******** sm*rtq**t*s into proper text.
1401 Note that this function guesses whether a character is a sm*rtq**t* or
1402 not, so it should only be used interactively."
1404 (article-translate-strings gnus-article-dumbquotes-map))
1406 (defun article-translate-characters (from to)
1407 "Translate all characters in the body of the article according to FROM and TO.
1408 FROM is a string of characters to translate from; to is a string of
1409 characters to translate to."
1411 (when (article-goto-body)
1412 (let ((buffer-read-only nil)
1413 (x (make-string 225 ?x))
1415 (while (< (incf i) (length x))
1418 (while (< i (length from))
1419 (aset x (aref from i) (aref to i))
1421 (translate-region (point) (point-max) x)))))
1423 (defun article-translate-strings (map)
1424 "Translate all string in the body of the article according to MAP.
1425 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1427 (when (article-goto-body)
1428 (let ((buffer-read-only nil)
1430 (while (setq elem (pop map))
1432 (while (search-forward (car elem) nil t)
1433 (replace-match (cadr elem)))))))))
1435 (defun article-treat-overstrike ()
1436 "Translate overstrikes into bold text."
1439 (when (article-goto-body)
1440 (let ((buffer-read-only nil))
1441 (while (search-forward "\b" nil t)
1442 (let ((next (char-after))
1446 previous (char-after))
1450 ;; We do the boldification/underlining by hiding the
1451 ;; overstrikes and putting the proper text property
1455 (gnus-article-hide-text-type start (point) 'overstrike)
1456 (put-text-property (point) end 'face 'bold))
1458 (gnus-article-hide-text-type
1459 (1- (point)) (1+ (point)) 'overstrike)
1461 start (1- (point)) 'face 'underline))
1463 (gnus-article-hide-text-type start (point) 'overstrike)
1465 (point) end 'face 'underline)))))))))
1467 (defun article-fill-long-lines ()
1468 "Fill lines that are wider than the window width."
1471 (let ((buffer-read-only nil)
1472 (width (window-width (get-buffer-window (current-buffer)))))
1475 (let ((adaptive-fill-mode nil))
1478 (when (>= (current-column) (min fill-column width))
1479 (narrow-to-region (point) (gnus-point-at-bol))
1480 (fill-paragraph nil)
1481 (goto-char (point-max))
1483 (forward-line 1)))))))
1485 (defun article-capitalize-sentences ()
1486 "Capitalize the first word in each sentence."
1489 (let ((buffer-read-only nil)
1490 (paragraph-start "^[\n\^L]"))
1494 (forward-sentence)))))
1496 (defun article-remove-cr ()
1497 "Remove trailing CRs and then translate remaining CRs into LFs."
1500 (let ((buffer-read-only nil))
1501 (goto-char (point-min))
1502 (while (re-search-forward "\r+$" nil t)
1503 (replace-match "" t t))
1504 (goto-char (point-min))
1505 (while (search-forward "\r" nil t)
1506 (replace-match "\n" t t)))))
1508 (defun article-remove-trailing-blank-lines ()
1509 "Remove all trailing blank lines from the article."
1512 (let ((buffer-read-only nil))
1513 (goto-char (point-max))
1517 (while (and (not (bobp))
1518 (looking-at "^[ \t]*$")
1519 (not (gnus-annotation-in-region-p
1520 (point) (gnus-point-at-eol))))
1525 (defun article-display-x-face (&optional force)
1526 "Look for an X-Face header and display it if present."
1527 (interactive (list 'force))
1529 ;; Delete the old process, if any.
1530 (when (process-status "article-x-face")
1531 (delete-process "article-x-face"))
1532 (let ((inhibit-point-motion-hooks t)
1533 (case-fold-search t)
1536 (article-narrow-to-head)
1537 (goto-char (point-min))
1538 (setq from (message-fetch-field "from"))
1539 (goto-char (point-min))
1540 (while (and gnus-article-x-face-command
1543 ;; Check whether this face is censored.
1544 (not gnus-article-x-face-too-ugly)
1545 (and gnus-article-x-face-too-ugly from
1546 (not (string-match gnus-article-x-face-too-ugly
1548 ;; Has to be present.
1549 (re-search-forward "^X-Face:[ \t]*" nil t))
1550 ;; This used to try to do multiple faces (`while' instead of
1551 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1552 ;; work (b) it can crash some versions of Emacs (c) are
1553 ;; multiple faces really something to encourage?
1554 (when (stringp gnus-article-x-face-command)
1556 ;; We now have the area of the buffer where the X-Face is stored.
1559 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1560 ;; We display the face.
1561 (if (symbolp gnus-article-x-face-command)
1562 ;; The command is a lisp function, so we call it.
1563 (if (gnus-functionp gnus-article-x-face-command)
1564 (funcall gnus-article-x-face-command beg end)
1565 (error "%s is not a function" gnus-article-x-face-command))
1566 ;; The command is a string, so we interpret the command
1567 ;; as a, well, command, and fork it off.
1568 (let ((process-connection-type nil))
1569 (process-kill-without-query
1571 "article-x-face" nil shell-file-name shell-command-switch
1572 gnus-article-x-face-command))
1573 (process-send-region "article-x-face" beg end)
1574 (process-send-eof "article-x-face"))))))))))
1576 (defun article-decode-mime-words ()
1577 "Decode all MIME-encoded words in the article."
1580 (set-buffer gnus-article-buffer)
1581 (let ((inhibit-point-motion-hooks t)
1583 (mail-parse-charset gnus-newsgroup-charset)
1584 (mail-parse-ignored-charsets
1585 (save-excursion (set-buffer gnus-summary-buffer)
1586 gnus-newsgroup-ignored-charsets)))
1587 (mail-decode-encoded-word-region (point-min) (point-max)))))
1589 (defun article-decode-charset (&optional prompt)
1590 "Decode charset-encoded text in the article.
1591 If PROMPT (the prefix), prompt for a coding system to use."
1593 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1595 (mail-parse-charset gnus-newsgroup-charset)
1596 (mail-parse-ignored-charsets
1597 (save-excursion (condition-case nil
1598 (set-buffer gnus-summary-buffer)
1600 gnus-newsgroup-ignored-charsets))
1604 (article-narrow-to-head)
1605 (setq ct (message-fetch-field "Content-Type" t)
1606 cte (message-fetch-field "Content-Transfer-Encoding" t)
1607 ctl (and ct (ignore-errors
1608 (mail-header-parse-content-type ct)))
1611 (mm-read-coding-system "Charset to decode: "))
1613 (mail-content-type-get ctl 'charset))))
1615 (setq cte (mail-header-strip cte)))
1616 (if (and ctl (not (string-match "/" (car ctl))))
1618 (goto-char (point-max)))
1621 (narrow-to-region (point) (point-max))
1622 (when (and (or (not ctl)
1623 (equal (car ctl) "text/plain")))
1625 charset (and cte (intern (downcase
1626 (gnus-strip-whitespace cte))))
1629 (defun article-decode-encoded-words ()
1630 "Remove encoded-word encoding from headers."
1631 (let (buffer-read-only)
1632 (let ((charset (save-excursion
1633 (set-buffer gnus-summary-buffer)
1634 default-mime-charset)))
1635 (mime-decode-header-in-buffer charset)
1638 (defun article-de-quoted-unreadable (&optional force)
1639 "Translate a quoted-printable-encoded article.
1640 If FORCE, decode the article whether it is marked as quoted-printable
1642 (interactive (list 'force))
1644 (let ((buffer-read-only nil)
1645 (type (gnus-fetch-field "content-transfer-encoding"))
1646 (charset gnus-newsgroup-charset))
1648 (and type (string-match "quoted-printable" (downcase type))))
1650 (quoted-printable-decode-region (point) (point-max) charset)))))
1655 (defun article-decode-HZ ()
1656 "Translate a HZ-encoded article."
1660 (let ((buffer-read-only nil))
1661 (rfc1843-decode-region (point-min) (point-max)))))
1663 (defun article-hide-list-identifiers ()
1664 "Remove list identifies from the Subject header.
1665 The `gnus-list-identifiers' variable specifies what to do."
1669 (let ((inhibit-point-motion-hooks t)
1671 (article-narrow-to-head)
1672 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1673 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1675 (goto-char (point-min))
1676 (when (re-search-forward
1677 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1679 (delete-region (match-beginning 2) (match-end 0)))))))))
1681 (defun article-hide-pgp ()
1682 "Remove any PGP headers and signatures in the current article."
1686 (let ((inhibit-point-motion-hooks t)
1687 buffer-read-only beg end)
1689 ;; Hide the "header".
1690 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1691 (push 'pgp gnus-article-wash-types)
1692 (delete-region (match-beginning 0) (match-end 0))
1693 ;; Remove armor headers (rfc2440 6.2)
1694 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1697 ;; Hide the actual signature.
1698 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1699 (setq end (1+ (match-beginning 0)))
1702 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1704 ;; Perhaps we shouldn't hide to the end of the buffer
1705 ;; if there is no end to the signature?
1707 ;; Hide "- " PGP quotation markers.
1709 (narrow-to-region beg end)
1710 (goto-char (point-min))
1711 (while (re-search-forward "^- " nil t)
1713 (match-beginning 0) (match-end 0)))
1715 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1717 (defun article-hide-pem (&optional arg)
1718 "Toggle hiding of any PEM headers and signatures in the current article.
1719 If given a negative prefix, always show; if given a positive prefix,
1721 (interactive (gnus-article-hidden-arg))
1722 (unless (gnus-article-check-hidden-text 'pem arg)
1724 (let (buffer-read-only end)
1725 (goto-char (point-min))
1726 ;; Hide the horrendously ugly "header".
1727 (when (and (search-forward
1728 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1730 (setq end (1+ (match-beginning 0))))
1731 (push 'pem gnus-article-wash-types)
1732 (gnus-article-hide-text-type
1734 (if (search-forward "\n\n" nil t)
1738 ;; Hide the trailer as well
1739 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1741 (gnus-article-hide-text-type
1742 (match-beginning 0) (match-end 0) 'pem)))))))
1744 (defun article-strip-banner ()
1745 "Strip the banner specified by the `banner' group parameter."
1749 (let ((inhibit-point-motion-hooks t)
1750 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1751 (gnus-signature-limit nil)
1752 buffer-read-only beg end)
1756 ((eq banner 'signature)
1757 (when (gnus-article-narrow-to-signature)
1760 (delete-region (point) (point-max))))
1762 (while (re-search-forward banner nil t)
1763 (delete-region (match-beginning 0) (match-end 0))))))))))
1765 (defun article-babel ()
1766 "Translate article using an online translation service."
1770 (set-buffer gnus-article-buffer)
1771 (when (article-goto-body)
1772 (let* ((buffer-read-only nil)
1775 (orig (buffer-substring start end))
1776 (trans (babel-as-string orig)))
1778 (narrow-to-region start end)
1779 (delete-region start end)
1782 (defun article-hide-signature (&optional arg)
1783 "Hide the signature in the current article.
1784 If given a negative prefix, always show; if given a positive prefix,
1786 (interactive (gnus-article-hidden-arg))
1792 (article-goto-body))
1793 (goto-char (point-min)))
1794 (unless (gnus-article-check-hidden-text 'signature arg)
1795 (let ((buffer-read-only nil)
1797 (while (setq button (text-property-any button (point-max)
1799 'gnus-signature-toggle))
1800 (setq button (text-property-not-all button (point-max)
1802 'gnus-signature-toggle))
1803 (when (and button (not (eobp)))
1804 (gnus-article-hide-text-type
1806 (next-single-property-change (1+ button) 'mime-view-entity
1810 (defun article-strip-headers-in-body ()
1811 "Strip offensive headers from bodies."
1815 (let ((case-fold-search t))
1816 (when (looking-at "x-no-archive:")
1817 (gnus-delete-line)))))
1819 (defun article-strip-leading-blank-lines ()
1820 "Remove all blank lines from the beginning of the article."
1823 (let ((inhibit-point-motion-hooks t)
1825 (when (article-goto-body)
1826 (while (and (not (eobp))
1827 (looking-at "[ \t]*$"))
1828 (gnus-delete-line))))))
1830 (defun article-narrow-to-head ()
1831 "Narrow the buffer to the head of the message.
1832 Point is left at the beginning of the narrowed-to region."
1834 (goto-char (point-min))
1835 (if (search-forward "\n\n" nil 1)
1838 (goto-char (point-min)))
1840 (defun article-goto-body ()
1841 "Place point at the start of the body."
1842 (goto-char (point-min))
1844 ;; This variable is only bound when dealing with separate
1846 (article-goto-body-goes-to-point-min-p
1848 ((search-forward "\n\n" nil t)
1851 (goto-char (point-max))
1854 (defun article-strip-multiple-blank-lines ()
1855 "Replace consecutive blank lines with one empty line."
1858 (let ((inhibit-point-motion-hooks t)
1860 ;; First make all blank lines empty.
1862 (while (re-search-forward "^[ \t]+$" nil t)
1863 (unless (gnus-annotation-in-region-p
1864 (match-beginning 0) (match-end 0))
1865 (replace-match "" nil t)))
1866 ;; Then replace multiple empty lines with a single empty line.
1868 (while (re-search-forward "\n\n\n+" nil t)
1869 (unless (gnus-annotation-in-region-p
1870 (match-beginning 0) (match-end 0))
1871 (replace-match "\n\n" t t))))))
1873 (defun article-strip-leading-space ()
1874 "Remove all white space from the beginning of the lines in the article."
1877 (let ((inhibit-point-motion-hooks t)
1880 (while (re-search-forward "^[ \t]+" nil t)
1881 (replace-match "" t t)))))
1883 (defun article-strip-trailing-space ()
1884 "Remove all white space from the end of the lines in the article."
1887 (let ((inhibit-point-motion-hooks t)
1890 (while (re-search-forward "[ \t]+$" nil t)
1891 (replace-match "" t t)))))
1893 (defun article-strip-blank-lines ()
1894 "Strip leading, trailing and multiple blank lines."
1896 (article-strip-leading-blank-lines)
1897 (article-remove-trailing-blank-lines)
1898 (article-strip-multiple-blank-lines))
1900 (defun article-strip-all-blank-lines ()
1901 "Strip all blank lines."
1904 (let ((inhibit-point-motion-hooks t)
1907 (while (re-search-forward "^[ \t]*\n" nil t)
1908 (replace-match "" t t)))))
1910 (defun gnus-article-narrow-to-signature ()
1911 "Narrow to the signature; return t if a signature is found, else nil."
1912 (let ((inhibit-point-motion-hooks t))
1913 (when (gnus-article-search-signature)
1915 ;; Check whether we have some limits to what we consider
1916 ;; to be a signature.
1917 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1918 (list gnus-signature-limit)))
1920 (while (setq limit (pop limits))
1921 (if (or (and (integerp limit)
1922 (< (- (point-max) (point)) limit))
1924 (< (count-lines (point) (point-max)) limit))
1925 (and (gnus-functionp limit)
1927 (and (stringp limit)
1928 (not (re-search-forward limit nil t))))
1929 () ; This limit did not succeed.
1933 (narrow-to-region (point) (point-max))
1936 (defun gnus-article-search-signature ()
1937 "Search the current buffer for the signature separator.
1938 Put point at the beginning of the signature separator."
1939 (let ((cur (point)))
1940 (goto-char (point-max))
1941 (if (if (stringp gnus-signature-separator)
1942 (re-search-backward gnus-signature-separator nil t)
1943 (let ((seps gnus-signature-separator))
1945 (not (re-search-backward (car seps) nil t)))
1952 (defun gnus-article-hidden-arg ()
1953 "Return the current prefix arg as a number, or 0 if no prefix."
1954 (list (if current-prefix-arg
1955 (prefix-numeric-value current-prefix-arg)
1958 (defun gnus-article-check-hidden-text (type arg)
1959 "Return nil if hiding is necessary.
1960 Arg can be nil or a number. Nil and positive means hide, negative
1961 means show, 0 means toggle."
1964 (let ((hide (gnus-article-hidden-text-p type)))
1970 (gnus-article-show-hidden-text type))
1972 (if (eq hide 'hidden)
1973 (gnus-article-show-hidden-text type)
1976 (defun gnus-article-hidden-text-p (type)
1977 "Say whether the current buffer contains hidden text of type TYPE."
1978 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1980 (not (get-text-property pos 'invisible))
1981 (not (get-text-property pos 'dummy-invisible)))
1983 (text-property-any (1+ pos) (point-max) 'article-type type)))
1988 (defun gnus-article-show-hidden-text (type &optional hide)
1989 "Show all hidden text of type TYPE.
1990 If HIDE, hide the text instead."
1992 (let ((buffer-read-only nil)
1993 (inhibit-point-motion-hooks t)
1996 (while (setq beg (text-property-any end (point-max) 'article-type type))
1999 (text-property-not-all beg (point-max) 'article-type type)
2002 (gnus-article-hide-text beg end gnus-hidden-properties)
2003 (gnus-article-unhide-text beg end))
2007 (defconst article-time-units
2008 `((year . ,(* 365.25 24 60 60))
2009 (week . ,(* 7 24 60 60))
2010 (day . ,(* 24 60 60))
2014 "Mapping from time units to seconds.")
2016 (defun article-date-ut (&optional type highlight header)
2017 "Convert DATE date to universal time in the current article.
2018 If TYPE is `local', convert to local time; if it is `lapsed', output
2019 how much time has lapsed since DATE. For `lapsed', the value of
2020 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2021 should replace the \"Date:\" one, or should be added below it."
2022 (interactive (list 'ut t))
2023 (let* ((header (or header
2024 (and (eq 1 (point-min))
2025 (mail-header-date (save-excursion
2026 (set-buffer gnus-summary-buffer)
2027 gnus-current-headers)))
2028 (message-fetch-field "date")
2030 (date (if (vectorp header) (mail-header-date header)
2032 (inhibit-point-motion-hooks t)
2033 bface eface date-pos)
2034 (when (and date (not (string= date "")))
2037 (article-narrow-to-head)
2038 (when (or (and (eq type 'lapsed)
2039 gnus-article-date-lapsed-new-header
2040 ;; Attempt to get the face of X-Sent first.
2041 (re-search-forward "^X-Sent:[ \t]" nil t))
2042 (re-search-forward "^Date:[ \t]" nil t)
2043 ;; If Date is missing, try again for X-Sent.
2044 (re-search-forward "^X-Sent:[ \t]" nil t))
2045 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2046 date (or (get-text-property (gnus-point-at-bol)
2049 eface (get-text-property (1- (gnus-point-at-eol))
2051 (let ((buffer-read-only nil))
2052 ;; Delete any old X-Sent headers.
2053 (when (setq date-pos
2054 (text-property-any (point-min) (point-max)
2055 'article-date-lapsed t))
2056 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2057 (delete-region (match-beginning 0)
2058 (progn (forward-line 1) (point))))
2059 (goto-char (point-min))
2060 ;; Delete any old Date headers.
2061 (while (re-search-forward "^Date:[ \t]" nil t)
2063 (setq date-pos (match-beginning 0)))
2064 (unless (and (eq type 'lapsed)
2065 gnus-article-date-lapsed-new-header)
2066 (delete-region (match-beginning 0)
2067 (progn (message-next-header) (point)))))
2070 (goto-char date-pos)
2072 ;; Possibly, Date has been deleted.
2074 (when (and (eq type 'lapsed)
2075 gnus-article-date-lapsed-new-header
2076 (looking-at "Date:"))
2078 (goto-char (point-min)))
2079 (insert (article-make-date-line date type))
2080 (when (eq type 'lapsed)
2081 (put-text-property (gnus-point-at-bol) (point)
2082 'article-date-lapsed t))
2086 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2087 (put-text-property (match-beginning 1) (1+ (match-end 1))
2088 'original-date date)
2089 (put-text-property (match-beginning 1) (1+ (match-end 1))
2091 (put-text-property (match-beginning 2) (match-end 2)
2094 (defun article-make-date-line (date type)
2095 "Return a DATE line of TYPE."
2096 (let ((time (condition-case ()
2100 ;; Convert to the local timezone. We have to slap a
2101 ;; `condition-case' round the calls to the timezone
2102 ;; functions since they aren't particularly resistant to
2105 (let ((tz (car (current-time-zone time))))
2106 (format "Date: %s %s%02d%02d" (current-time-string time)
2107 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2108 (/ (% (abs tz) 3600) 60))))
2109 ;; Convert to Universal Time.
2112 (current-time-string
2113 (let* ((e (parse-time-string date))
2114 (tm (apply 'encode-time e))
2116 (ls (- (cadr tm) (car (current-time-zone time)))))
2117 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2118 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2121 ;; Get the original date from the article.
2122 ((eq type 'original)
2123 (concat "Date: " (if (string-match "\n+$" date)
2124 (substring date 0 (match-beginning 0))
2126 ;; Let the user define the format.
2128 (if (gnus-functionp gnus-article-time-format)
2129 (funcall gnus-article-time-format time)
2132 (format-time-string gnus-article-time-format time))))
2135 (let ((tz (car (current-time-zone time))))
2138 (format-time-string "%Y%m%dT%H%M%S" time)
2139 (format "%s%02d%02d"
2140 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2141 (/ (% (abs tz) 3600) 60)))))
2142 ;; Do an X-Sent lapsed format.
2144 ;; If the date is seriously mangled, the timezone functions are
2145 ;; liable to bug out, so we ignore all errors.
2146 (let* ((now (current-time))
2147 (real-time (subtract-time now time))
2148 (real-sec (and real-time
2149 (+ (* (float (car real-time)) 65536)
2151 (sec (and real-time (abs real-sec)))
2161 ;; This is a bit convoluted, but basically we go
2162 ;; through the time units for years, weeks, etc,
2163 ;; and divide things to see whether that results
2164 ;; in positive answers.
2167 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2168 ;; The (remaining) seconds are too few to
2169 ;; be divided into this time unit.
2171 ;; It's big enough, so we output it.
2172 (setq sec (- sec (* num (cdr unit))))
2174 (concat (if prev ", " "") (int-to-string
2176 " " (symbol-name (car unit))
2177 (if (> num 1) "s" ""))
2179 article-time-units "")
2180 ;; If dates are odd, then it might appear like the
2181 ;; article was sent in the future.
2184 " in the future"))))))
2186 (error "Unknown conversion type: %s" type)))))
2188 (defun article-date-local (&optional highlight)
2189 "Convert the current article date to the local timezone."
2190 (interactive (list t))
2191 (article-date-ut 'local highlight))
2193 (defun article-date-original (&optional highlight)
2194 "Convert the current article date to what it was originally.
2195 This is only useful if you have used some other date conversion
2196 function and want to see what the date was before converting."
2197 (interactive (list t))
2198 (article-date-ut 'original highlight))
2200 (defun article-date-lapsed (&optional highlight)
2201 "Convert the current article date to time lapsed since it was sent."
2202 (interactive (list t))
2203 (article-date-ut 'lapsed highlight))
2205 (defun article-update-date-lapsed ()
2206 "Function to be run from a timer to update the lapsed time line."
2207 (let (deactivate-mark)
2212 (set-buffer (window-buffer w))
2213 (when (eq major-mode 'gnus-article-mode)
2214 (goto-char (point-min))
2215 (when (re-search-forward "^X-Sent:" nil t)
2216 (article-date-lapsed t))))
2219 (defun gnus-start-date-timer (&optional n)
2220 "Start a timer to update the X-Sent header in the article buffers.
2221 The numerical prefix says how frequently (in seconds) the function
2226 (gnus-stop-date-timer)
2227 (setq article-lapsed-timer
2228 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2230 (defun gnus-stop-date-timer ()
2231 "Stop the X-Sent timer."
2233 (when article-lapsed-timer
2234 (nnheader-cancel-timer article-lapsed-timer)
2235 (setq article-lapsed-timer nil)))
2237 (defun article-date-user (&optional highlight)
2238 "Convert the current article date to the user-defined format.
2239 This format is defined by the `gnus-article-time-format' variable."
2240 (interactive (list t))
2241 (article-date-ut 'user highlight))
2243 (defun article-date-iso8601 (&optional highlight)
2244 "Convert the current article date to ISO8601."
2245 (interactive (list t))
2246 (article-date-ut 'iso8601 highlight))
2248 (defun article-show-all ()
2249 "Show all hidden text in the article buffer."
2253 (let ((buffer-read-only nil))
2254 (gnus-article-unhide-text (point-min) (point-max))
2255 (gnus-remove-text-with-property 'gnus-prev)
2256 (gnus-remove-text-with-property 'gnus-next))))
2258 (defun article-show-all-headers ()
2259 "Show all hidden headers in the article buffer."
2264 (article-narrow-to-head)
2265 (let ((buffer-read-only nil))
2266 (gnus-article-unhide-text (point-min) (point-max))))))
2268 (defun article-emphasize (&optional arg)
2269 "Emphasize text according to `gnus-emphasis-alist'."
2270 (interactive (gnus-article-hidden-arg))
2271 (unless (gnus-article-check-hidden-text 'emphasis arg)
2275 (with-current-buffer gnus-summary-buffer
2276 gnus-article-emphasis-alist)
2278 gnus-emphasis-alist))
2279 (buffer-read-only nil)
2280 (props (append '(article-type emphasis)
2281 gnus-hidden-properties))
2282 regexp elem beg invisible visible face)
2285 (while (setq elem (pop alist))
2287 (setq regexp (car elem)
2288 invisible (nth 1 elem)
2289 visible (nth 2 elem)
2291 (while (re-search-forward regexp nil t)
2292 (when (and (match-beginning visible) (match-beginning invisible))
2293 (push 'emphasis gnus-article-wash-types)
2294 (gnus-article-hide-text
2295 (match-beginning invisible) (match-end invisible) props)
2296 (gnus-article-unhide-text-type
2297 (match-beginning visible) (match-end visible) 'emphasis)
2298 (gnus-put-text-property-excluding-newlines
2299 (match-beginning visible) (match-end visible) 'face face)
2300 (goto-char (match-end invisible)))))))))
2302 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2303 "Setup newsgroup emphasis alist."
2304 (unless gnus-article-emphasis-alist
2305 (let ((name (and gnus-newsgroup-name
2306 (gnus-group-real-name gnus-newsgroup-name))))
2307 (make-local-variable 'gnus-article-emphasis-alist)
2308 (setq gnus-article-emphasis-alist
2310 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2311 (while (setq elem (pop alist))
2312 (when (and name (string-match (car elem) name))
2314 highlight (copy-sequence (cdr elem)))))
2316 (copy-sequence highlight-words)
2317 (if gnus-newsgroup-name
2318 (copy-sequence (gnus-group-find-parameter
2319 gnus-newsgroup-name 'highlight-words t)))
2320 gnus-emphasis-alist)))))
2322 (defvar gnus-summary-article-menu)
2323 (defvar gnus-summary-post-menu)
2325 ;;; Saving functions.
2327 (defun gnus-article-save (save-buffer file &optional num)
2328 "Save the currently selected article."
2329 (unless gnus-save-all-headers
2330 ;; Remove headers according to `gnus-saved-headers'.
2331 (let ((gnus-visible-headers
2332 (or gnus-saved-headers gnus-visible-headers))
2333 (gnus-article-buffer save-buffer))
2335 (set-buffer save-buffer)
2336 (article-hide-headers 1 t))))
2337 (save-window-excursion
2338 (if (not gnus-default-article-saver)
2339 (error "No default saver is defined")
2340 ;; !!! Magic! The saving functions all save
2341 ;; `gnus-save-article-buffer' (or so they think), but we
2342 ;; bind that variable to our save-buffer.
2343 (set-buffer gnus-article-buffer)
2344 (let* ((gnus-save-article-buffer save-buffer)
2347 ((not gnus-prompt-before-saving) 'default)
2348 ((eq gnus-prompt-before-saving 'always) nil)
2350 (gnus-number-of-articles-to-be-saved
2351 (when (eq gnus-prompt-before-saving t)
2353 (set-buffer gnus-article-current-summary)
2354 (funcall gnus-default-article-saver filename)))))
2356 (defun gnus-read-save-file-name (prompt &optional filename
2357 function group headers variable)
2359 (funcall function group headers (symbol-value variable)))
2364 ((eq filename 'default)
2370 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2373 (if (and gnus-number-of-articles-to-be-saved
2374 (> gnus-number-of-articles-to-be-saved 1))
2375 (format "these %d articles"
2376 gnus-number-of-articles-to-be-saved)
2379 ;; Let the split methods have their say.
2381 ;; No split name was found.
2384 (concat prompt " (default "
2385 (file-name-nondirectory default-name) ") ")
2386 (file-name-directory default-name)
2388 ;; A single group name is returned.
2389 ((stringp split-name)
2391 (funcall function split-name headers
2392 (symbol-value variable)))
2394 (concat prompt " (default "
2395 (file-name-nondirectory default-name) ") ")
2396 (file-name-directory default-name)
2398 ;; A single split name was found
2399 ((= 1 (length split-name))
2400 (let* ((name (expand-file-name
2401 (car split-name) gnus-article-save-directory))
2402 (dir (cond ((file-directory-p name)
2403 (file-name-as-directory name))
2404 ((file-exists-p name) name)
2405 (t gnus-article-save-directory))))
2407 (concat prompt " (default " name ") ")
2409 ;; A list of splits was found.
2411 (setq split-name (nreverse split-name))
2413 (let ((file-name-history
2414 (nconc split-name file-name-history)))
2418 (concat prompt " (`M-p' for defaults) ")
2419 gnus-article-save-directory
2421 gnus-article-save-directory)))
2422 (car (push result file-name-history)))))))
2423 ;; Create the directory.
2424 (gnus-make-directory (file-name-directory file))
2425 ;; If we have read a directory, we append the default file name.
2426 (when (file-directory-p file)
2427 (setq file (concat (file-name-as-directory file)
2428 (file-name-nondirectory default-name))))
2429 ;; Possibly translate some characters.
2430 (nnheader-translate-file-chars file)))))
2431 (gnus-make-directory (file-name-directory result))
2432 (set variable result)))
2434 (defun gnus-article-archive-name (group)
2435 "Return the first instance of an \"Archive-name\" in the current buffer."
2436 (let ((case-fold-search t))
2437 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2438 (nnheader-concat gnus-article-save-directory
2439 (match-string 1)))))
2441 (defun gnus-article-nndoc-name (group)
2442 "If GROUP is an nndoc group, return the name of the parent group."
2443 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2444 (gnus-group-get-parameter group 'save-article-group)))
2446 (defun gnus-summary-save-in-rmail (&optional filename)
2447 "Append this article to Rmail file.
2448 Optional argument FILENAME specifies file name.
2449 Directory to save to is default to `gnus-article-save-directory'."
2450 (setq filename (gnus-read-save-file-name
2451 "Save %s in rmail file:" filename
2452 gnus-rmail-save-name gnus-newsgroup-name
2453 gnus-current-headers 'gnus-newsgroup-last-rmail))
2454 (gnus-eval-in-buffer-window gnus-save-article-buffer
2458 (gnus-output-to-rmail filename))))
2461 (defun gnus-summary-save-in-mail (&optional filename)
2462 "Append this article to Unix mail file.
2463 Optional argument FILENAME specifies file name.
2464 Directory to save to is default to `gnus-article-save-directory'."
2465 (setq filename (gnus-read-save-file-name
2466 "Save %s in Unix mail file:" filename
2467 gnus-mail-save-name gnus-newsgroup-name
2468 gnus-current-headers 'gnus-newsgroup-last-mail))
2469 (gnus-eval-in-buffer-window gnus-save-article-buffer
2473 (if (and (file-readable-p filename)
2474 (mail-file-babyl-p filename))
2475 (rmail-output-to-rmail-file filename t)
2476 (gnus-output-to-mail filename)))))
2479 (defun gnus-summary-save-in-file (&optional filename overwrite)
2480 "Append this article to file.
2481 Optional argument FILENAME specifies file name.
2482 Directory to save to is default to `gnus-article-save-directory'."
2483 (setq filename (gnus-read-save-file-name
2484 "Save %s in file:" filename
2485 gnus-file-save-name gnus-newsgroup-name
2486 gnus-current-headers 'gnus-newsgroup-last-file))
2487 (gnus-eval-in-buffer-window gnus-save-article-buffer
2491 (when (and overwrite
2492 (file-exists-p filename))
2493 (delete-file filename))
2494 (gnus-output-to-file filename))))
2497 (defun gnus-summary-write-to-file (&optional filename)
2498 "Write this article to a file.
2499 Optional argument FILENAME specifies file name.
2500 The directory to save in defaults to `gnus-article-save-directory'."
2501 (gnus-summary-save-in-file nil t))
2503 (defun gnus-summary-save-body-in-file (&optional filename)
2504 "Append this article body to a file.
2505 Optional argument FILENAME specifies file name.
2506 The directory to save in defaults to `gnus-article-save-directory'."
2507 (setq filename (gnus-read-save-file-name
2508 "Save %s body in file:" filename
2509 gnus-file-save-name gnus-newsgroup-name
2510 gnus-current-headers 'gnus-newsgroup-last-file))
2511 (gnus-eval-in-buffer-window gnus-save-article-buffer
2515 (when (article-goto-body)
2516 (narrow-to-region (point) (point-max)))
2517 (gnus-output-to-file filename))))
2520 (defun gnus-summary-save-in-pipe (&optional command)
2521 "Pipe this article to subprocess."
2523 (cond ((and (eq command 'default)
2524 gnus-last-shell-command)
2525 gnus-last-shell-command)
2529 "Shell command on %s: "
2530 (if (and gnus-number-of-articles-to-be-saved
2531 (> gnus-number-of-articles-to-be-saved 1))
2532 (format "these %d articles"
2533 gnus-number-of-articles-to-be-saved)
2535 gnus-last-shell-command))))
2536 (when (string-equal command "")
2537 (setq command gnus-last-shell-command))
2538 (gnus-eval-in-buffer-window gnus-article-buffer
2541 (shell-command-on-region (point-min) (point-max) command nil)))
2542 (setq gnus-last-shell-command command))
2544 ;;; Article file names when saving.
2546 (defun gnus-capitalize-newsgroup (newsgroup)
2547 "Capitalize NEWSGROUP name."
2548 (when (not (zerop (length newsgroup)))
2549 (concat (char-to-string (upcase (aref newsgroup 0)))
2550 (substring newsgroup 1))))
2552 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2553 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2554 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2555 Otherwise, it is like ~/News/news/group/num."
2558 (concat (if (gnus-use-long-file-name 'not-save)
2559 (gnus-capitalize-newsgroup newsgroup)
2560 (gnus-newsgroup-directory-form newsgroup))
2561 "/" (int-to-string (mail-header-number headers)))
2562 gnus-article-save-directory)))
2564 (string-equal (file-name-directory default)
2565 (file-name-directory last-file))
2566 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2568 (or last-file default))))
2570 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2571 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2572 If variable `gnus-use-long-file-name' is non-nil, it is
2573 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2576 (concat (if (gnus-use-long-file-name 'not-save)
2578 (gnus-newsgroup-directory-form newsgroup))
2579 "/" (int-to-string (mail-header-number headers)))
2580 gnus-article-save-directory)))
2582 (string-equal (file-name-directory default)
2583 (file-name-directory last-file))
2584 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2586 (or last-file default))))
2588 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2589 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2590 If variable `gnus-use-long-file-name' is non-nil, it is
2591 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2594 (if (gnus-use-long-file-name 'not-save)
2595 (gnus-capitalize-newsgroup newsgroup)
2596 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2597 gnus-article-save-directory)))
2599 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2600 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2601 If variable `gnus-use-long-file-name' is non-nil, it is
2602 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2605 (if (gnus-use-long-file-name 'not-save)
2607 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2608 gnus-article-save-directory)))
2615 (setq afunc (car func)
2618 gfunc (intern (format "gnus-%s" func))))
2620 (if (not (fboundp afunc))
2622 `(lambda (&optional interactive &rest args)
2623 ,(documentation afunc t)
2624 (interactive (list t))
2626 (set-buffer gnus-article-buffer)
2628 (call-interactively ',afunc)
2629 (apply ',afunc args))))))))
2630 '(article-hide-headers
2631 article-hide-boring-headers
2632 article-toggle-headers
2633 article-treat-overstrike
2634 article-fill-long-lines
2635 article-capitalize-sentences
2637 article-display-x-face
2638 article-de-quoted-unreadable
2640 article-hide-list-identifiers
2642 article-strip-banner
2645 article-hide-signature
2646 article-strip-headers-in-body
2647 article-remove-trailing-blank-lines
2648 article-strip-leading-blank-lines
2649 article-strip-multiple-blank-lines
2650 article-strip-leading-space
2651 article-strip-trailing-space
2652 article-strip-blank-lines
2653 article-strip-all-blank-lines
2655 article-date-iso8601
2656 article-date-original
2658 article-decode-mime-words
2659 article-decode-charset
2660 article-decode-encoded-words
2664 article-treat-dumbquotes
2665 article-normalize-headers
2666 (article-show-all-headers . gnus-article-show-all-headers)
2667 (article-show-all . gnus-article-show-all))))
2670 ;;; Gnus article mode
2673 (put 'gnus-article-mode 'mode-class 'special)
2675 (gnus-define-keys gnus-article-mode-map
2676 " " gnus-article-goto-next-page
2677 "\177" gnus-article-goto-prev-page
2678 [delete] gnus-article-goto-prev-page
2679 [backspace] gnus-article-goto-prev-page
2680 "\C-c^" gnus-article-refer-article
2681 "h" gnus-article-show-summary
2682 "s" gnus-article-show-summary
2683 "\C-c\C-m" gnus-article-mail
2684 "?" gnus-article-describe-briefly
2685 "e" gnus-summary-edit-article
2686 "<" beginning-of-buffer
2688 "\C-c\C-i" gnus-info-find-node
2691 "\C-d" gnus-article-read-summary-keys
2692 "\M-*" gnus-article-read-summary-keys
2693 "\M-#" gnus-article-read-summary-keys
2694 "\M-^" gnus-article-read-summary-keys
2695 "\M-g" gnus-article-read-summary-keys)
2697 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2700 (unless (lookup-key gnus-article-mode-map key)
2701 (define-key gnus-article-mode-map key
2702 'gnus-article-read-summary-keys)))
2707 (let ((key (car elt)))
2708 (and (> (length key) 0)
2709 (not (eq 'menu-bar (aref key 0)))
2710 (symbolp (lookup-key gnus-summary-mode-map key))
2712 (accessible-keymaps gnus-summary-mode-map))
2716 (push (char-to-string c) keys)
2720 (defun gnus-article-make-menu-bar ()
2721 (gnus-turn-off-edit-menu 'article)
2722 (unless (boundp 'gnus-article-article-menu)
2724 gnus-article-article-menu gnus-article-mode-map ""
2726 ["Scroll forwards" gnus-article-goto-next-page t]
2727 ["Scroll backwards" gnus-article-goto-prev-page t]
2728 ["Show summary" gnus-article-show-summary t]
2729 ["Fetch Message-ID at point" gnus-article-refer-article t]
2730 ["Mail to address at point" gnus-article-mail t]
2731 ["Send a bug report" gnus-bug t]))
2734 gnus-article-treatment-menu gnus-article-mode-map ""
2736 ["Hide headers" gnus-article-toggle-headers t]
2737 ["Hide signature" gnus-article-hide-signature t]
2738 ["Hide citation" gnus-article-hide-citation t]
2739 ["Treat overstrike" gnus-article-treat-overstrike t]
2740 ["Remove carriage return" gnus-article-remove-cr t]
2741 ["Decode HZ" gnus-article-decode-HZ t]))
2743 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2745 (when (boundp 'gnus-summary-post-menu)
2746 (define-key gnus-article-mode-map [menu-bar post]
2747 (cons "Post" gnus-summary-post-menu)))
2749 (gnus-run-hooks 'gnus-article-menu-hook)))
2751 (defun gnus-article-mode ()
2752 "Major mode for displaying an article.
2754 All normal editing commands are switched off.
2756 The following commands are available in addition to all summary mode
2758 \\<gnus-article-mode-map>
2759 \\[gnus-article-next-page]\t Scroll the article one page forwards
2760 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2761 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2762 \\[gnus-article-show-summary]\t Display the summary buffer
2763 \\[gnus-article-mail]\t Send a reply to the address near point
2764 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2765 \\[gnus-info-find-node]\t Go to the Gnus info node"
2767 (when (gnus-visual-p 'article-menu 'menu)
2768 (gnus-article-make-menu-bar))
2769 (gnus-simplify-mode-line)
2770 (setq mode-name "Article")
2771 (setq major-mode 'gnus-article-mode)
2772 (make-local-variable 'minor-mode-alist)
2773 (unless (assq 'gnus-show-mime minor-mode-alist)
2774 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2775 (use-local-map gnus-article-mode-map)
2776 (gnus-update-format-specifications nil 'article-mode)
2777 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2778 (make-local-variable 'gnus-page-broken)
2779 (make-local-variable 'gnus-button-marker-list)
2780 (make-local-variable 'gnus-article-current-summary)
2781 (make-local-variable 'gnus-article-mime-handles)
2782 (make-local-variable 'gnus-article-decoded-p)
2783 (make-local-variable 'gnus-article-mime-handle-alist)
2784 (make-local-variable 'gnus-article-wash-types)
2785 (gnus-set-default-directory)
2786 (buffer-disable-undo)
2787 (setq buffer-read-only t)
2788 (set-syntax-table gnus-article-mode-syntax-table)
2789 (gnus-run-hooks 'gnus-article-mode-hook))
2791 (defun gnus-article-setup-buffer ()
2792 "Initialize the article buffer."
2793 (let* ((name (if gnus-single-article-buffer "*Article*"
2794 (concat "*Article " gnus-newsgroup-name "*")))
2796 (progn (string-match "\\*Article" name)
2797 (concat " *Original Article"
2798 (substring name (match-end 0))))))
2799 (setq gnus-article-buffer name)
2800 (setq gnus-original-article-buffer original)
2801 (setq gnus-article-mime-handle-alist nil)
2802 ;; This might be a variable local to the summary buffer.
2803 (unless gnus-single-article-buffer
2805 (set-buffer gnus-summary-buffer)
2806 (setq gnus-article-buffer name)
2807 (setq gnus-original-article-buffer original)
2808 (gnus-set-global-variables)))
2809 (gnus-article-setup-highlight-words)
2810 ;; Init original article buffer.
2812 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2813 (setq major-mode 'gnus-original-article-mode)
2814 (make-local-variable 'gnus-original-article))
2815 (if (get-buffer name)
2818 (buffer-disable-undo)
2819 (setq buffer-read-only t)
2820 (unless (eq major-mode 'gnus-article-mode)
2821 (gnus-article-mode))
2824 (set-buffer (gnus-get-buffer-create name))
2826 (make-local-variable 'gnus-summary-buffer)
2827 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2828 (current-buffer)))))
2830 ;; Set article window start at LINE, where LINE is the number of lines
2831 ;; from the head of the article.
2832 (defun gnus-article-set-window-start (&optional line)
2834 (get-buffer-window gnus-article-buffer t)
2836 (set-buffer gnus-article-buffer)
2837 (goto-char (point-min))
2840 (gnus-message 6 "Moved to bookmark")
2841 (search-forward "\n\n" nil t)
2845 ;;; @@ article filters
2848 (defun gnus-article-display-mime-message ()
2849 "Article display method for MIME message."
2850 ;; called from `gnus-original-article-buffer'.
2851 (let (charset all-headers)
2852 (with-current-buffer gnus-summary-buffer
2853 (setq charset default-mime-charset
2854 all-headers gnus-have-all-headers))
2855 (make-local-variable 'default-mime-charset)
2856 (setq default-mime-charset charset)
2857 (with-current-buffer (get-buffer-create gnus-article-buffer)
2858 (make-local-variable 'default-mime-charset)
2859 (setq default-mime-charset charset))
2860 (mime-display-message mime-message-structure
2861 gnus-article-buffer nil gnus-article-mode-map)
2863 (gnus-article-hide-headers nil -1))
2865 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2866 (make-local-variable 'mime-button-mother-dispatcher)
2867 (setq mime-button-mother-dispatcher
2868 (function gnus-article-push-button))
2869 (run-hooks 'gnus-mime-article-prepare-hook))
2871 (defun gnus-article-display-traditional-message ()
2872 "Article display method for traditional message."
2873 (set-buffer gnus-article-buffer)
2874 (let (buffer-read-only)
2876 (insert-buffer-substring gnus-original-article-buffer)))
2878 (defun gnus-article-make-full-mail-header (&optional number charset)
2879 "Create a new mail header structure in a raw article buffer."
2880 (unless (and number charset)
2881 (save-current-buffer
2882 (set-buffer gnus-summary-buffer)
2884 (setq number (or (cdr gnus-article-current) 0)))
2886 (setq charset (or default-mime-charset 'x-ctext)))))
2887 (goto-char (point-min))
2888 (let ((header-end (if (search-forward "\n\n" nil t)
2890 (goto-char (point-max))))
2891 (chars (- (point-max) (point)))
2892 (lines (count-lines (point) (point-max)))
2893 (default-mime-charset charset)
2895 (narrow-to-region (point-min) header-end)
2896 (setq xref (std11-fetch-field "xref"))
2898 (make-full-mail-header
2900 (std11-fetch-field "subject")
2901 (std11-fetch-field "from")
2902 (std11-fetch-field "date")
2903 (std11-fetch-field "message-id")
2904 (std11-fetch-field "references")
2907 (when xref (concat "Xref: " xref)))
2910 (defun gnus-article-prepare (article &optional all-headers header)
2911 "Prepare ARTICLE in article mode buffer.
2912 ARTICLE should either be an article number or a Message-ID.
2913 If ARTICLE is an id, HEADER should be the article headers.
2914 If ALL-HEADERS is non-nil, no headers are hidden."
2916 ;; Make sure we start in a summary buffer.
2917 (unless (eq major-mode 'gnus-summary-mode)
2918 (set-buffer gnus-summary-buffer))
2919 (setq gnus-summary-buffer (current-buffer))
2920 (let* ((gnus-article (if header (mail-header-number header) article))
2921 (summary-buffer (current-buffer))
2922 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2923 (group gnus-newsgroup-name)
2926 (gnus-article-setup-buffer)
2927 (set-buffer gnus-original-article-buffer)
2928 ;; Deactivate active regions.
2929 (when (and (boundp 'transient-mark-mode)
2930 transient-mark-mode)
2931 (setq mark-active nil))
2932 (if (not (setq result (let ((buffer-read-only nil))
2933 (gnus-request-article-this-buffer
2935 ;; There is no such article.
2937 (when (and (numberp article)
2938 (not (memq article gnus-newsgroup-sparse)))
2939 (setq gnus-article-current
2940 (cons gnus-newsgroup-name article))
2941 (set-buffer gnus-summary-buffer)
2942 (setq gnus-current-article article)
2943 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2945 (gnus-summary-set-agent-mark article)
2946 (message "Message marked for downloading"))
2947 (gnus-summary-mark-article article gnus-canceled-mark)
2948 (unless (memq article gnus-newsgroup-sparse)
2949 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2950 (if (or (eq result 'pseudo)
2951 (eq result 'nneething))
2954 (set-buffer summary-buffer)
2955 (push article gnus-newsgroup-history)
2956 (setq gnus-last-article gnus-current-article
2957 gnus-current-article 0
2958 gnus-current-headers nil
2959 gnus-article-current nil)
2960 (if (eq result 'nneething)
2961 (gnus-configure-windows 'summary)
2962 (gnus-configure-windows 'article))
2963 (gnus-set-global-variables))
2964 (let ((gnus-article-mime-handle-alist-1
2965 gnus-article-mime-handle-alist))
2966 (gnus-set-mode-line 'article)))
2967 ;; The result from the `request' was an actual article -
2968 ;; or at least some text that is now displayed in the
2970 (when (and (numberp article)
2971 (not (eq article gnus-current-article)))
2972 ;; Seems like a new article has been selected.
2973 ;; `gnus-current-article' must be an article number.
2975 (set-buffer summary-buffer)
2976 (push article gnus-newsgroup-history)
2977 (setq gnus-last-article gnus-current-article
2978 gnus-current-article article
2979 gnus-current-headers
2980 (gnus-summary-article-header gnus-current-article)
2981 gnus-article-current
2982 (cons gnus-newsgroup-name gnus-current-article))
2983 (unless (vectorp gnus-current-headers)
2984 (setq gnus-current-headers nil))
2985 (gnus-summary-goto-subject gnus-current-article)
2986 (when (gnus-summary-show-thread)
2987 ;; If the summary buffer really was folded, the
2988 ;; previous goto may not actually have gone to
2989 ;; the right article, but the thread root instead.
2991 (gnus-summary-goto-subject gnus-current-article))
2992 (gnus-run-hooks 'gnus-mark-article-hook)
2993 (gnus-set-mode-line 'summary)
2994 (when (gnus-visual-p 'article-highlight 'highlight)
2995 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2996 ;; Set the global newsgroup variables here.
2997 (gnus-set-global-variables)
2998 (setq gnus-have-all-headers
2999 (or all-headers gnus-show-all-headers))))
3000 (when (or (numberp article)
3002 (gnus-article-prepare-display)
3004 (goto-char (point-min))
3005 (setq gnus-page-broken
3006 (when gnus-break-pages
3007 (gnus-narrow-to-page)
3009 (let ((gnus-article-mime-handle-alist-1
3010 gnus-article-mime-handle-alist))
3011 (gnus-set-mode-line 'article))
3013 (set-window-point (get-buffer-window (current-buffer)) (point))
3014 (gnus-configure-windows 'article)
3017 (defun gnus-article-prepare-mime-display (&optional number)
3018 (goto-char (point-min))
3019 (when (re-search-forward "^[^\t ]+:" nil t)
3020 (goto-char (match-beginning 0)))
3021 (let ((entity (if (eq 1 (point-min))
3022 (get-text-property 1 'mime-view-entity)
3023 (get-text-property (point) 'mime-view-entity)))
3024 last-entity child-entity next type)
3025 (setq child-entity (mime-entity-children entity))
3027 (setq last-entity (nth (1- (length child-entity))
3029 (setq last-entity entity))
3031 (narrow-to-region (point)
3032 (if (search-forward "\n\n" nil t)
3035 (gnus-treat-article 'head)
3036 (put-text-property (point-min) (point-max) 'article-treated-header t)
3037 (goto-char (point-max)))
3038 (while (and (not (eobp)) entity)
3039 (setq next (set-marker
3041 (next-single-property-change (point) 'mime-view-entity
3043 (let ((types (mime-entity-content-type entity)))
3044 (while (eq 'multipart (mime-content-type-primary-type types))
3045 (setq entity (car (mime-entity-children entity))
3046 types (mime-entity-content-type entity)))
3048 (setq type (format "%s/%s"
3049 (mime-content-type-primary-type types)
3050 (mime-content-type-subtype types)))))
3051 (if (string-equal type "message/rfc822")
3054 (let ((children (mime-entity-children entity))
3057 (setq last-children (nth (1- (length children)) children))
3060 (not (eq last-children
3061 (get-text-property next 'mime-view-entity)))
3063 (next-single-property-change next
3065 nil (point-max)))))))
3066 (setq next (next-single-property-change next 'mime-view-entity
3069 (narrow-to-region (point) next)
3070 (gnus-article-prepare-mime-display)
3071 (goto-char (point-max)))
3072 (setq entity (get-text-property (point) 'mime-view-entity)))
3074 (narrow-to-region (point) next)
3075 ;; Kludge. We have to count true number, but for now,
3076 ;; part number is here only to achieve `last'.
3077 (gnus-treat-article nil 1
3078 (if (eq entity last-entity)
3081 (goto-char (point-max)))
3082 (setq entity (get-text-property next 'mime-view-entity))))))
3085 (defun gnus-article-prepare-display ()
3086 "Make the current buffer look like a nice article."
3087 (setq gnus-article-wash-types nil)
3088 (gnus-run-hooks 'gnus-tmp-internal-hook)
3089 (gnus-run-hooks 'gnus-article-prepare-hook)
3091 (let (mime-display-header-hook mime-display-text/plain-hook)
3092 (funcall (if gnus-show-mime
3094 (setq mime-message-structure gnus-current-headers)
3095 (mime-buffer-entity-set-buffer-internal
3096 mime-message-structure
3097 gnus-original-article-buffer)
3098 (mime-entity-set-representation-type-internal
3099 mime-message-structure 'mime-buffer-entity)
3100 (luna-send mime-message-structure
3101 'initialize-instance
3102 mime-message-structure)
3103 gnus-article-display-method-for-mime)
3104 gnus-article-display-method-for-traditional)))
3105 ;; Associate this article with the current summary buffer.
3106 (setq gnus-article-current-summary gnus-summary-buffer)
3107 ;; Call the treatment functions.
3108 (let ((inhibit-read-only t)
3113 (gnus-article-prepare-mime-display)
3114 (narrow-to-region (goto-char (point-min))
3115 (if (search-forward "\n\n" nil t)
3118 (gnus-treat-article 'head)
3119 (put-text-property (point-min) (point-max) 'article-treated-header t)
3120 (goto-char (point-max))
3122 (narrow-to-region (point) (point-max))
3123 (gnus-treat-article nil))
3124 (put-text-property (point-min) (point-max) 'read-only nil)))
3125 ;; Perform the article display hooks. Incidentally, this hook is
3126 ;; an obsolete variable by now.
3127 (gnus-run-hooks 'gnus-article-display-hook))
3129 (defun gnus-article-decode-article-as-default-mime-charset ()
3130 "Decode an article as `default-mime-charset'. It won't work if the
3131 value of the variable `gnus-show-mime' is non-nil."
3132 (unless gnus-show-mime
3133 (decode-mime-charset-region (point-min) (point-max)
3134 (with-current-buffer gnus-summary-buffer
3135 default-mime-charset))))
3138 ;;; Gnus MIME viewing functions
3141 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3142 "The following specs can be used:
3144 %T MIME type, along with additional info
3145 %n The `name' parameter
3146 %d The description, if any
3147 %l The length of the encoded part
3148 %p The part identifier number
3149 %e Dots if the part isn't displayed")
3151 (defvar gnus-mime-button-line-format-alist
3152 '((?t gnus-tmp-type ?s)
3153 (?T gnus-tmp-type-long ?s)
3154 (?n gnus-tmp-name ?s)
3155 (?d gnus-tmp-description ?s)
3157 (?l gnus-tmp-length ?d)
3158 (?e gnus-tmp-dots ?s)))
3160 (defvar gnus-mime-button-commands
3161 '((gnus-article-press-button "\r" "Toggle Display")
3162 (gnus-mime-view-part "v" "View Interactively...")
3163 (gnus-mime-view-part-as-type "t" "View As Type...")
3164 (gnus-mime-save-part "o" "Save...")
3165 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3166 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3167 (gnus-mime-internalize-part "E" "View Internally")
3168 (gnus-mime-externalize-part "e" "View Externally")
3169 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3171 (defun gnus-article-mime-part-status ()
3172 (with-current-buffer gnus-article-buffer
3173 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3174 (if (and entity (mime-entity-children entity))
3175 (format " (%d parts)" (length (mime-entity-children entity)))
3178 (defvar gnus-mime-button-map nil)
3179 (unless gnus-mime-button-map
3180 (setq gnus-mime-button-map (make-sparse-keymap))
3181 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
3182 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
3183 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
3185 (define-key gnus-mime-button-map (cadr c) (car c)))
3186 gnus-mime-button-commands))
3188 (defun gnus-mime-button-menu (event)
3189 "Construct a context-sensitive menu of MIME commands."
3192 (let ((pos (event-start event)))
3193 (set-buffer (window-buffer (posn-window pos)))
3194 (goto-char (posn-point pos))
3195 (gnus-article-check-buffer)
3196 (let ((response (x-popup-menu
3198 ("" ,@(mapcar (lambda (c)
3199 (cons (caddr c) (car c)))
3200 gnus-mime-button-commands))))))
3202 (call-interactively response))))))
3204 (defun gnus-mime-view-all-parts (&optional handles)
3205 "View all the MIME parts."
3207 (save-current-buffer
3208 (set-buffer gnus-article-buffer)
3209 (let ((handles (or handles gnus-article-mime-handles))
3210 (mail-parse-charset gnus-newsgroup-charset)
3211 (mail-parse-ignored-charsets
3212 (save-excursion (set-buffer gnus-summary-buffer)
3213 gnus-newsgroup-ignored-charsets)))
3214 (if (stringp (car handles))
3215 (gnus-mime-view-all-parts (cdr handles))
3216 (mapcar 'mm-display-part handles)))))
3218 (defun gnus-mime-save-part ()
3219 "Save the MIME part under point."
3221 (gnus-article-check-buffer)
3222 (let ((data (get-text-property (point) 'gnus-data)))
3223 (mm-save-part data)))
3225 (defun gnus-mime-pipe-part ()
3226 "Pipe the MIME part under point to a process."
3228 (gnus-article-check-buffer)
3229 (let ((data (get-text-property (point) 'gnus-data)))
3230 (mm-pipe-part data)))
3232 (defun gnus-mime-view-part ()
3233 "Interactively choose a viewing method for the MIME part under point."
3235 (gnus-article-check-buffer)
3236 (let ((data (get-text-property (point) 'gnus-data)))
3237 (mm-interactively-view-part data)))
3239 (defun gnus-mime-view-part-as-type-internal ()
3240 (gnus-article-check-buffer)
3241 (let* ((name (mail-content-type-get
3242 (mm-handle-type (get-text-property (point) 'gnus-data))
3244 (def-type (and name (mm-default-file-encoding name))))
3245 (and def-type (cons def-type 0))))
3247 (defun gnus-mime-view-part-as-type (mime-type)
3248 "Choose a MIME media type, and view the part as such."
3250 (list (completing-read
3251 "View as MIME type: "
3252 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
3254 (gnus-mime-view-part-as-type-internal))))
3255 (gnus-article-check-buffer)
3256 (let ((handle (get-text-property (point) 'gnus-data)))
3257 (gnus-mm-display-part
3258 (mm-make-handle (mm-handle-buffer handle)
3259 (cons mime-type (cdr (mm-handle-type handle)))
3260 (mm-handle-encoding handle)
3261 (mm-handle-undisplayer handle)
3262 (mm-handle-disposition handle)
3263 (mm-handle-description handle)
3264 (mm-handle-cache handle)
3265 (mm-handle-id handle)))))
3267 (defun gnus-mime-copy-part (&optional handle)
3268 "Put the the MIME part under point into a new buffer."
3270 (gnus-article-check-buffer)
3271 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3272 (contents (mm-get-part handle))|
3273 (base (file-name-nondirectory
3275 (mail-content-type-get (mm-handle-type handle) 'name)
3276 (mail-content-type-get (mm-handle-type handle)
3279 (buffer (generate-new-buffer base)))
3280 (switch-to-buffer buffer)
3282 ;; We do it this way to make `normal-mode' set the appropriate mode.
3285 (setq buffer-file-name (expand-file-name base))
3287 (setq buffer-file-name nil))
3288 (goto-char (point-min))))
3290 (defun gnus-mime-inline-part (&optional handle)
3291 "Insert the MIME part under point into the current buffer."
3293 (gnus-article-check-buffer)
3294 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3298 (if (mm-handle-undisplayer handle)
3299 (mm-remove-part handle)
3300 (setq contents (mm-get-part handle))
3302 (mm-insert-inline handle contents)
3305 (defun gnus-mime-externalize-part (&optional handle)
3306 "View the MIME part under point with an external viewer."
3308 (gnus-article-check-buffer)
3309 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3310 (mm-user-display-methods nil)
3311 (mm-inline-large-images nil)
3312 (mail-parse-charset gnus-newsgroup-charset)
3313 (mail-parse-ignored-charsets
3314 (save-excursion (set-buffer gnus-summary-buffer)
3315 gnus-newsgroup-ignored-charsets)))
3316 (if (mm-handle-undisplayer handle)
3317 (mm-remove-part handle)
3318 (mm-display-part handle))))
3320 (defun gnus-mime-internalize-part (&optional handle)
3321 "View the MIME part under point with an internal viewer.
3322 In no internal viewer is available, use an external viewer."
3324 (gnus-article-check-buffer)
3325 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3326 (mm-inlined-types '(".*"))
3327 (mm-inline-large-images t)
3328 (mail-parse-charset gnus-newsgroup-charset)
3329 (mail-parse-ignored-charsets
3330 (save-excursion (set-buffer gnus-summary-buffer)
3331 gnus-newsgroup-ignored-charsets)))
3332 (if (mm-handle-undisplayer handle)
3333 (mm-remove-part handle)
3334 (mm-display-part handle))))
3336 (defun gnus-article-part-wrapper (n function)
3337 (save-current-buffer
3338 (set-buffer gnus-article-buffer)
3339 (when (> n (length gnus-article-mime-handle-alist))
3340 (error "No such part"))
3341 (gnus-article-goto-part n)
3342 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3343 (funcall function handle))))
3345 (defun gnus-article-pipe-part (n)
3346 "Pipe MIME part N, which is the numerical prefix."
3348 (gnus-article-part-wrapper n 'mm-pipe-part))
3350 (defun gnus-article-save-part (n)
3351 "Save MIME part N, which is the numerical prefix."
3353 (gnus-article-part-wrapper n 'mm-save-part))
3355 (defun gnus-article-interactively-view-part (n)
3356 "View MIME part N interactively, which is the numerical prefix."
3358 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3360 (defun gnus-article-copy-part (n)
3361 "Copy MIME part N, which is the numerical prefix."
3363 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3365 (defun gnus-article-externalize-part (n)
3366 "View MIME part N externally, which is the numerical prefix."
3368 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3370 (defun gnus-article-inline-part (n)
3371 "Inline MIME part N, which is the numerical prefix."
3373 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3375 (defun gnus-article-mime-match-handle-first (condition)
3377 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3378 (while (setq ihandle (pop alist))
3380 ((functionp condition)
3381 (funcall condition (cdr ihandle)))
3382 ((eq condition 'undisplayed)
3383 (not (or (mm-handle-undisplayer (cdr ihandle))
3384 (equal (mm-handle-media-type (cdr ihandle))
3385 "multipart/alternative"))))
3386 ((eq condition 'undisplayed-alternative)
3387 (not (mm-handle-undisplayer (cdr ihandle))))
3389 (gnus-article-goto-part (car ihandle))
3390 (or (not n) (< (car ihandle) n)))
3391 (setq n (car ihandle))))
3395 (defun gnus-article-view-part (&optional n)
3396 "View MIME part N, which is the numerical prefix."
3398 (save-current-buffer
3399 (set-buffer gnus-article-buffer)
3400 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3401 gnus-article-mime-match-handle-function)))
3402 (when (> n (length gnus-article-mime-handle-alist))
3403 (error "No such part"))
3404 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3405 (when (gnus-article-goto-part n)
3406 (if (equal (car handle) "multipart/alternative")
3407 (gnus-article-press-button)
3408 (when (eq (gnus-mm-display-part handle) 'internal)
3409 (gnus-set-window-start)))))))
3411 (defun gnus-mm-display-part (handle)
3412 "Display HANDLE and fix MIME button."
3413 (let ((id (get-text-property (point) 'gnus-part))
3418 (let ((window (selected-window))
3419 (mail-parse-charset gnus-newsgroup-charset)
3420 (mail-parse-ignored-charsets
3421 (save-excursion (set-buffer gnus-summary-buffer)
3422 gnus-newsgroup-ignored-charsets)))
3425 (let ((win (get-buffer-window (current-buffer) t))
3428 (select-window win))
3431 (if (mm-handle-displayed-p handle)
3432 ;; This will remove the part.
3433 (mm-display-part handle)
3435 (narrow-to-region (point) (1+ (point)))
3436 (mm-display-part handle)
3437 ;; We narrow to the part itself and
3438 ;; then call the treatment functions.
3439 (goto-char (point-min))
3441 (narrow-to-region (point) (point-max))
3444 (1- (length gnus-article-mime-handles))
3445 (mm-handle-media-type handle)))))
3446 (select-window window))))
3448 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3449 (gnus-insert-mime-button
3450 handle id (list (mm-handle-displayed-p handle)))
3451 (goto-char point))))
3453 (defun gnus-article-goto-part (n)
3454 "Go to MIME part N."
3455 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3457 (goto-char point))))
3459 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3460 (let ((gnus-tmp-name
3461 (or (mail-content-type-get (mm-handle-type handle)
3463 (mail-content-type-get (mm-handle-disposition handle)
3466 (gnus-tmp-type (mm-handle-media-type handle))
3467 (gnus-tmp-description
3468 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3471 (if (if displayed (car displayed)
3472 (mm-handle-displayed-p handle))
3474 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3476 gnus-tmp-type-long b e)
3477 (when (string-match ".*/" gnus-tmp-name)
3478 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3479 (setq gnus-tmp-type-long (concat gnus-tmp-type
3480 (and (not (equal gnus-tmp-name ""))
3481 (concat "; " gnus-tmp-name))))
3482 (or (equal gnus-tmp-description "")
3483 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3488 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3489 `(local-map ,gnus-mime-button-map
3490 keymap ,gnus-mime-button-map
3491 gnus-callback gnus-mm-display-part
3492 gnus-part ,gnus-tmp-id
3493 article-type annotation
3496 (widget-convert-button 'link b e
3498 :action 'gnus-widget-press-button
3499 :button-keymap gnus-mime-button-map
3502 ;; Needed to properly clear the message
3503 ;; due to a bug in wid-edit
3504 (setq help-echo-owns-message t)
3506 "Click to %s the MIME part; %s for more options"
3507 (if (mm-handle-displayed-p
3508 (widget-get widget :mime-handle))
3510 (if gnus-xemacs "button3" "mouse-3"))))))
3512 (defun gnus-widget-press-button (elems el)
3513 (goto-char (widget-get elems :from))
3514 (gnus-article-press-button))
3516 (defvar gnus-displaying-mime nil)
3518 (defun gnus-display-mime (&optional ihandles)
3519 "Display the MIME parts."
3521 (save-selected-window
3522 (let ((window (get-buffer-window gnus-article-buffer))
3525 (select-window window)
3526 ;; We have to do this since selecting the window
3527 ;; may change the point. So we set the window point.
3528 (set-window-point window point)))
3529 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3530 buffer-read-only handle name type b e display)
3531 (when (and (not ihandles)
3532 (not gnus-displaying-mime))
3533 ;; Top-level call; we clean up.
3534 (when gnus-article-mime-handles
3535 (mm-destroy-parts gnus-article-mime-handles)
3536 (setq gnus-article-mime-handle-alist nil));; A trick.
3537 (setq gnus-article-mime-handles handles)
3538 ;; We allow users to glean info from the handles.
3539 (when gnus-article-mime-part-function
3540 (gnus-mime-part-function handles)))
3542 (or (not (stringp (car handles)))
3545 (when (and (not ihandles)
3546 (not gnus-displaying-mime))
3547 ;; Clean up for mime parts.
3549 (delete-region (point) (point-max)))
3550 (let ((gnus-displaying-mime t))
3551 (gnus-mime-display-part handles)))
3554 (narrow-to-region (point) (point-max))
3555 (gnus-treat-article nil 1 1)
3558 ;; Highlight the headers.
3562 (narrow-to-region (point-min) (point))
3563 (gnus-treat-article 'head))))))))
3565 (defvar gnus-mime-display-multipart-as-mixed nil)
3567 (defun gnus-mime-display-part (handle)
3570 ((not (stringp (car handle)))
3571 (gnus-mime-display-single handle))
3572 ;; User-defined multipart
3573 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3574 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3576 ;; multipart/alternative
3577 ((and (equal (car handle) "multipart/alternative")
3578 (not gnus-mime-display-multipart-as-mixed))
3579 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3580 (push (cons id handle) gnus-article-mime-handle-alist)
3581 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3582 ;; multipart/related
3583 ((and (equal (car handle) "multipart/related")
3584 (not gnus-mime-display-multipart-as-mixed))
3585 ;;;!!!We should find the start part, but we just default
3586 ;;;!!!to the first part.
3587 (gnus-mime-display-part (cadr handle)))
3588 ;; Other multiparts are handled like multipart/mixed.
3590 (gnus-mime-display-mixed (cdr handle)))))
3592 (defun gnus-mime-part-function (handles)
3593 (if (stringp (car handles))
3594 (mapcar 'gnus-mime-part-function (cdr handles))
3595 (funcall gnus-article-mime-part-function handles)))
3597 (defun gnus-mime-display-mixed (handles)
3598 (mapcar 'gnus-mime-display-part handles))
3600 (defun gnus-mime-display-single (handle)
3601 (let ((type (mm-handle-media-type handle))
3602 (ignored gnus-ignored-mime-types)
3609 (when (string-match (pop ignored) type)
3610 (throw 'ignored nil)))
3611 (if (and (setq not-attachment
3612 (and (not (mm-inline-override-p handle))
3613 (or (not (mm-handle-disposition handle))
3614 (equal (car (mm-handle-disposition handle))
3616 (mm-attachment-override-p handle))))
3617 (mm-automatic-display-p handle)
3618 (or (mm-inlined-p handle)
3619 (mm-automatic-external-display-p type)))
3621 (when (equal (mm-handle-media-supertype handle) "text")
3623 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3624 (push (cons id handle) gnus-article-mime-handle-alist)
3625 (when (or (not display)
3626 (not (gnus-unbuttonized-mime-type-p type)))
3627 ;(gnus-article-insert-newline)
3628 (gnus-insert-mime-button
3629 handle id (list (or display (and not-attachment text))))
3630 (gnus-article-insert-newline)
3631 ;(gnus-article-insert-newline)
3633 (let ((beg (point)))
3639 (let ((mail-parse-charset gnus-newsgroup-charset)
3640 (mail-parse-ignored-charsets
3641 (save-excursion (condition-case ()
3642 (set-buffer gnus-summary-buffer)
3644 gnus-newsgroup-ignored-charsets)))
3645 (mm-display-part handle t))
3646 (goto-char (point-max)))
3647 ((and text not-attachment)
3651 (gnus-article-insert-newline)
3652 (mm-insert-inline handle (mm-get-part handle))
3653 (goto-char (point-max))))
3657 (narrow-to-region beg (point))
3659 nil (length gnus-article-mime-handle-alist)
3660 (1- (length gnus-article-mime-handles))
3661 (mm-handle-media-type handle)))))))))
3663 (defun gnus-unbuttonized-mime-type-p (type)
3664 "Say whether TYPE is to be unbuttonized."
3665 (unless gnus-inhibit-mime-unbuttonizing
3667 (let ((types gnus-unbuttonized-mime-types))
3669 (when (string-match (pop types) type)
3670 (throw 'found t)))))))
3672 (defun gnus-article-insert-newline ()
3673 "Insert a newline, but mark it as undeletable."
3674 (gnus-put-text-property
3675 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3677 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3678 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3681 handle buffer-read-only from props begend not-pref)
3682 (save-window-excursion
3685 (narrow-to-region (car ibegend)
3688 (goto-char (car ibegend))
3691 (delete-region (point-min) (point-max))
3692 (mm-remove-parts handles))
3693 (setq begend (list (point-marker)))
3695 (unless (setq not-pref (cadr (member preferred ihandles)))
3696 (setq not-pref (car ihandles)))
3698 (not (gnus-unbuttonized-mime-type-p
3699 "multipart/alternative")))
3700 (gnus-add-text-properties
3703 (insert (format "%d. " id))
3707 (unless ,(not ibegend)
3708 (setq gnus-article-mime-handle-alist
3709 ',gnus-article-mime-handle-alist))
3710 (gnus-mime-display-alternative
3711 ',ihandles ',not-pref ',begend ,id))
3712 local-map ,gnus-mime-button-map
3713 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3714 face ,gnus-article-button-face
3715 keymap ,gnus-mime-button-map
3718 (widget-convert-button 'link from (point)
3719 :action 'gnus-widget-press-button
3720 :button-keymap gnus-widget-button-keymap)
3722 (while (setq handle (pop handles))
3723 (gnus-add-text-properties
3726 (insert (format "(%c) %-18s"
3727 (if (equal handle preferred) ?* ? )
3728 (mm-handle-media-type handle)))
3732 (unless ,(not ibegend)
3733 (setq gnus-article-mime-handle-alist
3734 ',gnus-article-mime-handle-alist))
3735 (gnus-mime-display-alternative
3736 ',ihandles ',handle ',begend ,id))
3737 local-map ,gnus-mime-button-map
3738 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3739 face ,gnus-article-button-face
3740 keymap ,gnus-mime-button-map
3743 (widget-convert-button 'link from (point)
3744 :action 'gnus-widget-press-button
3745 :button-keymap gnus-widget-button-keymap)
3749 (if (stringp (car preferred))
3750 (gnus-display-mime preferred)
3751 (let ((mail-parse-charset gnus-newsgroup-charset)
3752 (mail-parse-ignored-charsets
3753 (save-excursion (set-buffer gnus-summary-buffer)
3754 gnus-newsgroup-ignored-charsets)))
3755 (mm-display-part preferred)
3759 (narrow-to-region (car begend) (point-max))
3761 nil (length gnus-article-mime-handle-alist)
3762 (1- (length gnus-article-mime-handles))
3763 (mm-handle-media-type handle))))))
3764 (goto-char (point-max))
3765 (setcdr begend (point-marker)))))
3767 (goto-char point))))
3769 (defun gnus-article-wash-status ()
3770 "Return a string which display status of article washing."
3772 (set-buffer gnus-article-buffer)
3773 (let ((cite (memq 'cite gnus-article-wash-types))
3774 (headers (memq 'headers gnus-article-wash-types))
3775 (boring (memq 'boring-headers gnus-article-wash-types))
3776 (pgp (memq 'pgp gnus-article-wash-types))
3777 (pem (memq 'pem gnus-article-wash-types))
3778 (signature (memq 'signature gnus-article-wash-types))
3779 (overstrike (memq 'overstrike gnus-article-wash-types))
3780 (emphasis (memq 'emphasis gnus-article-wash-types)))
3781 (format "%c%c%c%c%c%c%c"
3783 (if (or headers boring) ?h ? )
3784 (if (or pgp pem) ?p ? )
3785 (if signature ?s ? )
3786 (if overstrike ?o ? )
3787 (if gnus-show-mime ?m ? )
3788 (if emphasis ?e ? )))))
3790 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3792 (defun gnus-article-maybe-hide-headers ()
3793 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3794 Provided for backwards compatibility."
3795 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3796 (not (save-excursion (set-buffer gnus-summary-buffer)
3797 gnus-have-all-headers)))
3798 (not gnus-inhibit-hiding))
3799 (gnus-article-hide-headers)))
3803 (defun gnus-output-to-file (file-name)
3804 "Append the current article to a file named FILE-NAME."
3805 (let ((artbuf (current-buffer)))
3807 (insert-buffer-substring artbuf)
3808 ;; Append newline at end of the buffer as separator, and then
3810 (goto-char (point-max))
3812 (write-region-as-binary (point-min) (point-max) file-name 'append)
3815 (defun gnus-narrow-to-page (&optional arg)
3816 "Narrow the article buffer to a page.
3817 If given a numerical ARG, move forward ARG pages."
3819 (setq arg (if arg (prefix-numeric-value arg) 0))
3821 (set-buffer gnus-article-buffer)
3822 (goto-char (point-min))
3824 ;; Remove any old next/prev buttons.
3825 (when (gnus-visual-p 'page-marker)
3826 (let ((buffer-read-only nil))
3827 (gnus-remove-text-with-property 'gnus-prev)
3828 (gnus-remove-text-with-property 'gnus-next)))
3831 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3833 (re-search-forward page-delimiter nil 'move arg)))
3834 (goto-char (match-end 0)))
3837 (if (re-search-forward page-delimiter nil 'move)
3840 (when (and (gnus-visual-p 'page-marker)
3841 (not (= (point-min) 1)))
3843 (goto-char (point-min))
3844 (gnus-insert-prev-page-button)))
3845 (when (and (gnus-visual-p 'page-marker)
3846 (< (+ (point-max) 2) (buffer-size)))
3848 (goto-char (point-max))
3849 (gnus-insert-next-page-button)))))
3851 ;; Article mode commands
3853 (defun gnus-article-goto-next-page ()
3854 "Show the next page of the article."
3856 (when (gnus-article-next-page)
3857 (goto-char (point-min))
3858 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3860 (defun gnus-article-goto-prev-page ()
3861 "Show the next page of the article."
3863 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3864 (gnus-article-prev-page nil)))
3866 (defun gnus-article-next-page (&optional lines)
3867 "Show the next page of the current article.
3868 If end of article, return non-nil. Otherwise return nil.
3869 Argument LINES specifies lines to be scrolled up."
3871 (let ((start (window-start))
3872 end-of-buffer end-of-page)
3874 (move-to-window-line -1)
3875 (if (<= (point) start)
3878 (setq start (point)))
3881 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3882 (and (pos-visible-in-window-p)
3883 (setq end-of-buffer t)))
3885 (setq end-of-page t)))
3887 (move-to-window-line lines)
3888 (unless (search-backward "\n\n" nil t)
3889 (setq start (point)))))
3890 (cond (end-of-buffer t)
3892 (gnus-narrow-to-page 1)
3896 (set-window-start (selected-window) start)
3897 (let (window-pixel-scroll-increment)
3901 (defun gnus-article-prev-page (&optional lines)
3902 "Show previous page of current article.
3903 Argument LINES specifies lines to be scrolled down."
3905 (let (beginning-of-buffer beginning-of-page)
3907 (move-to-window-line 0)
3908 (cond ((eq 1 (point))
3909 (setq beginning-of-buffer t))
3911 (setq beginning-of-page t))))
3912 (cond (beginning-of-buffer)
3914 (gnus-narrow-to-page -1))
3917 (let (window-pixel-scroll-increment)
3918 (scroll-down lines))
3919 (beginning-of-buffer
3920 (goto-char (point-min))))))))
3922 (defun gnus-article-refer-article ()
3923 "Read article specified by message-id around point."
3925 (let ((point (point)))
3926 (search-forward ">" nil t) ;Move point to end of "<....>".
3927 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3928 (let ((message-id (match-string 1)))
3930 (set-buffer gnus-summary-buffer)
3931 (gnus-summary-refer-article message-id))
3933 (error "No references around point"))))
3935 (defun gnus-article-show-summary ()
3936 "Reconfigure windows to show summary buffer."
3938 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3939 (error "There is no summary buffer for this article buffer")
3940 (gnus-article-set-globals)
3941 (gnus-configure-windows 'article)
3942 (gnus-summary-goto-subject gnus-current-article)
3943 (gnus-summary-position-point)))
3945 (defun gnus-article-describe-briefly ()
3946 "Describe article mode commands briefly."
3948 (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")))
3950 (defun gnus-article-summary-command ()
3951 "Execute the last keystroke in the summary buffer."
3953 (let ((obuf (current-buffer))
3954 (owin (current-window-configuration))
3956 (switch-to-buffer gnus-article-current-summary 'norecord)
3957 (setq func (lookup-key (current-local-map) (this-command-keys)))
3958 (call-interactively func)
3960 (set-window-configuration owin)
3961 (set-window-point (get-buffer-window (current-buffer)) (point))))
3963 (defun gnus-article-summary-command-nosave ()
3964 "Execute the last keystroke in the summary buffer."
3967 (pop-to-buffer gnus-article-current-summary 'norecord)
3968 (setq func (lookup-key (current-local-map) (this-command-keys)))
3969 (call-interactively func)))
3971 (defun gnus-article-check-buffer ()
3972 "Beep if not in an article buffer."
3973 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3974 (error "Command invoked outside of a Gnus article buffer")))
3976 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3977 "Read a summary buffer key sequence and execute it from the article buffer."
3979 (gnus-article-check-buffer)
3981 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3982 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3983 "=" "^" "\M-^" "|"))
3989 '("n" "Gn" "p" "Gp"))
3992 (set-buffer gnus-article-current-summary)
3993 (let (gnus-pick-mode)
3994 (push (or key last-command-event) unread-command-events)
3995 (setq keys (static-if (featurep 'xemacs)
3996 (events-to-keys (read-key-sequence nil))
3997 (read-key-sequence nil)))))
4000 (if (or (member keys nosaves)
4001 (member keys nosave-but-article)
4002 (member keys nosave-in-article))
4004 (save-window-excursion
4005 (pop-to-buffer gnus-article-current-summary 'norecord)
4006 ;; We disable the pick minor mode commands.
4007 (let (gnus-pick-mode)
4008 (setq func (lookup-key (current-local-map) keys))))
4012 (unless (member keys nosave-in-article)
4013 (set-buffer gnus-article-current-summary))
4014 (call-interactively func)
4015 (setq new-sum-point (point)))
4016 (when (member keys nosave-but-article)
4017 (pop-to-buffer gnus-article-buffer 'norecord)))
4018 ;; These commands should restore window configuration.
4019 (let ((obuf (current-buffer))
4020 (owin (current-window-configuration))
4022 (summary gnus-article-current-summary)
4023 func in-buffer selected)
4024 (if not-restore-window
4025 (pop-to-buffer summary 'norecord)
4026 (switch-to-buffer summary 'norecord))
4027 (setq in-buffer (current-buffer))
4028 ;; We disable the pick minor mode commands.
4029 (if (setq func (let (gnus-pick-mode)
4030 (lookup-key (current-local-map) keys)))
4032 (call-interactively func)
4033 (setq new-sum-point (point)))
4035 (when (eq in-buffer (current-buffer))
4036 (setq selected (gnus-summary-select-article))
4038 (unless not-restore-window
4039 (set-window-configuration owin))
4040 (when (eq selected 'old)
4042 (set-window-start (get-buffer-window (current-buffer))
4044 (set-window-point (get-buffer-window (current-buffer))
4046 (let ((win (get-buffer-window gnus-article-current-summary)))
4048 (set-window-point win new-sum-point))))))))
4050 (defun gnus-article-hide (&optional arg force)
4051 "Hide all the gruft in the current article.
4052 This means that PGP stuff, signatures, cited text and (some)
4053 headers will be hidden.
4054 If given a prefix, show the hidden text instead."
4055 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4056 (gnus-article-hide-headers arg)
4057 (gnus-article-hide-list-identifiers arg)
4058 (gnus-article-hide-pgp arg)
4059 (gnus-article-hide-citation-maybe arg force)
4060 (gnus-article-hide-signature arg))
4062 (defun gnus-article-maybe-highlight ()
4063 "Do some article highlighting if article highlighting is requested."
4064 (when (gnus-visual-p 'article-highlight 'highlight)
4065 (gnus-article-highlight-some)))
4067 (defun gnus-check-group-server ()
4068 ;; Make sure the connection to the server is alive.
4069 (unless (gnus-server-opened
4070 (gnus-find-method-for-group gnus-newsgroup-name))
4071 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4072 (gnus-request-group gnus-newsgroup-name t)))
4074 (defun gnus-request-article-this-buffer (article group)
4075 "Get an article and insert it into this buffer."
4076 (let (do-update-line sparse-header)
4080 (gnus-kill-all-overlays)
4081 (setq group (or group gnus-newsgroup-name))
4083 ;; Using `gnus-request-article' directly will insert the article into
4084 ;; `nntp-server-buffer' - so we'll save some time by not having to
4085 ;; copy it from the server buffer into the article buffer.
4087 ;; We only request an article by message-id when we do not have the
4088 ;; headers for it, so we'll have to get those.
4089 (when (stringp article)
4090 (gnus-read-header article))
4092 ;; If the article number is negative, that means that this article
4093 ;; doesn't belong in this newsgroup (possibly), so we find its
4094 ;; message-id and request it by id instead of number.
4095 (when (and (numberp article)
4097 (get-buffer gnus-summary-buffer)
4098 (gnus-buffer-exists-p gnus-summary-buffer))
4100 (set-buffer gnus-summary-buffer)
4101 (let ((header (gnus-summary-article-header article)))
4104 ((memq article gnus-newsgroup-sparse)
4105 ;; This is a sparse gap article.
4106 (setq do-update-line article)
4107 (setq article (mail-header-id header))
4108 (setq sparse-header (gnus-read-header article))
4109 (setq gnus-newsgroup-sparse
4110 (delq article gnus-newsgroup-sparse)))
4112 ;; It's a real article.
4113 (setq article (mail-header-id header)))
4115 ;; It is an extracted pseudo-article.
4116 (setq article 'pseudo)
4117 (gnus-request-pseudo-article header))))
4119 (let ((method (gnus-find-method-for-group
4120 gnus-newsgroup-name)))
4121 (when (and (eq (car method) 'nneething)
4124 (file-name-as-directory
4125 (or (cadr (assq 'nneething-address method))
4127 (mail-header-subject header))))
4128 (when (file-directory-p dir)
4129 (setq article 'nneething)
4130 (gnus-group-enter-directory dir))))))))
4133 ;; Refuse to select canceled articles.
4134 ((and (numberp article)
4136 (get-buffer gnus-summary-buffer)
4137 (gnus-buffer-exists-p gnus-summary-buffer)
4138 (eq (cdr (save-excursion
4139 (set-buffer gnus-summary-buffer)
4140 (assq article gnus-newsgroup-reads)))
4141 gnus-canceled-mark))
4143 ;; Check the backlog.
4144 ((and gnus-keep-backlog
4145 (gnus-backlog-request-article group article (current-buffer)))
4147 ;; Check asynchronous pre-fetch.
4148 ((gnus-async-request-fetched-article group article (current-buffer))
4149 (gnus-async-prefetch-next group article gnus-summary-buffer)
4150 (when (and (numberp article) gnus-keep-backlog)
4151 (gnus-backlog-enter-article group article (current-buffer)))
4154 ((and gnus-use-cache
4156 (gnus-cache-request-article article group))
4158 ;; Get the article and put into the article buffer.
4159 ((or (stringp article)
4161 (let ((gnus-override-method gnus-override-method)
4162 (methods (and (stringp article)
4163 gnus-refer-article-method))
4165 (buffer-read-only nil))
4170 (when (and (null gnus-override-method)
4172 (setq gnus-override-method (pop methods)))
4174 (when (eq gnus-override-method 'current)
4175 (setq gnus-override-method gnus-current-select-method))
4177 (gnus-kill-all-overlays)
4178 (let ((gnus-newsgroup-name group))
4179 (gnus-check-group-server))
4180 (when (gnus-request-article article group (current-buffer))
4181 (when (numberp article)
4182 (gnus-async-prefetch-next group article
4183 gnus-summary-buffer)
4184 (when gnus-keep-backlog
4185 (gnus-backlog-enter-article
4186 group article (current-buffer))))
4187 (setq result 'article))
4190 (setq gnus-override-method (pop methods))
4191 (setq result 'done))))
4192 (and (eq result 'article) 'article)))
4196 ;; Associate this article with the current summary buffer.
4197 (setq gnus-article-current-summary gnus-summary-buffer)
4199 ;; Take the article from the original article buffer
4200 ;; and place it in the buffer it's supposed to be in.
4201 (when (and (get-buffer gnus-article-buffer)
4202 (equal (buffer-name (current-buffer))
4203 (buffer-name (get-buffer gnus-article-buffer))))
4205 (if (get-buffer gnus-original-article-buffer)
4206 (set-buffer gnus-original-article-buffer)
4207 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4208 (buffer-disable-undo)
4209 (setq major-mode 'gnus-original-article-mode)
4210 (setq buffer-read-only t))
4211 (let (buffer-read-only)
4213 (insert-buffer-substring gnus-article-buffer))
4214 (setq gnus-original-article (cons group article)))
4217 (run-hooks 'gnus-article-decode-hook)
4218 ;; Mark article as decoded or not.
4219 (setq gnus-article-decoded-p gnus-article-decode-hook))
4221 ;; Update sparse articles.
4222 (when (and do-update-line
4223 (or (numberp article)
4225 (let ((buf (current-buffer)))
4226 (set-buffer gnus-summary-buffer)
4227 (gnus-summary-update-article do-update-line sparse-header)
4228 (gnus-summary-goto-subject do-update-line nil t)
4229 (set-window-point (get-buffer-window (current-buffer) t)
4231 (set-buffer buf))))))
4237 (defcustom gnus-article-edit-mode-hook nil
4238 "Hook run in article edit mode buffers."
4239 :group 'gnus-article-various
4242 (defcustom gnus-article-edit-article-setup-function
4243 'gnus-article-mime-edit-article-setup
4244 "Function called to setup an editing article buffer."
4245 :group 'gnus-article-various
4248 (defvar gnus-article-edit-done-function nil)
4250 (defvar gnus-article-edit-mode-map nil)
4252 ;; Should we be using derived.el for this?
4253 (unless gnus-article-edit-mode-map
4254 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4255 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4257 (gnus-define-keys gnus-article-edit-mode-map
4258 "\C-c\C-c" gnus-article-edit-done
4259 "\C-c\C-k" gnus-article-edit-exit)
4261 (gnus-define-keys (gnus-article-edit-wash-map
4262 "\C-c\C-w" gnus-article-edit-mode-map)
4263 "f" gnus-article-edit-full-stops))
4265 (defun gnus-article-edit-mode ()
4266 "Major mode for editing articles.
4267 This is an extended text-mode.
4269 \\{gnus-article-edit-mode-map}"
4271 (setq major-mode 'gnus-article-edit-mode)
4272 (setq mode-name "Article Edit")
4273 (use-local-map gnus-article-edit-mode-map)
4274 (make-local-variable 'gnus-article-edit-done-function)
4275 (make-local-variable 'gnus-prev-winconf)
4276 (setq buffer-read-only nil)
4277 (buffer-enable-undo)
4279 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4281 (defun gnus-article-edit (&optional force)
4282 "Edit the current article.
4283 This will have permanent effect only in mail groups.
4284 If FORCE is non-nil, allow editing of articles even in read-only
4287 (when (and (not force)
4288 (gnus-group-read-only-p))
4289 (error "The current newsgroup does not support article editing"))
4290 (gnus-article-date-original)
4291 (gnus-article-edit-article
4293 `(lambda (no-highlight)
4295 (gnus-summary-edit-article-done
4296 ,(or (mail-header-references gnus-current-headers) "")
4297 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4299 (defun gnus-article-edit-article (start-func exit-func)
4300 "Start editing the contents of the current article buffer."
4301 (let ((winconf (current-window-configuration)))
4302 (set-buffer gnus-article-buffer)
4303 (gnus-article-edit-mode)
4304 (funcall start-func)
4305 (gnus-configure-windows 'edit-article)
4306 (setq gnus-article-edit-done-function exit-func)
4307 (setq gnus-prev-winconf winconf)
4308 (when gnus-article-edit-article-setup-function
4309 (funcall gnus-article-edit-article-setup-function))
4310 (gnus-message 6 "C-c C-c to end edits")))
4312 (defun gnus-article-edit-done (&optional arg)
4313 "Update the article edits and exit."
4318 (when (article-goto-body)
4319 (let ((lines (count-lines (point) (point-max)))
4320 (length (- (point-max) (point)))
4321 (case-fold-search t)
4322 (body (copy-marker (point))))
4323 (goto-char (point-min))
4324 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4325 (delete-region (match-beginning 1) (match-end 1))
4326 (insert (number-to-string length)))
4327 (goto-char (point-min))
4328 (when (re-search-forward
4329 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4330 (delete-region (match-beginning 1) (match-end 1))
4331 (insert (number-to-string length)))
4332 (goto-char (point-min))
4333 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4334 (delete-region (match-beginning 1) (match-end 1))
4335 (insert (number-to-string lines)))))))
4336 (let ((func gnus-article-edit-done-function)
4337 (buf (current-buffer))
4338 (start (window-start)))
4339 (remove-hook 'gnus-article-mode-hook
4340 'gnus-article-mime-edit-article-unwind)
4341 (gnus-article-edit-exit)
4344 (let ((buffer-read-only nil))
4346 ;; The cache and backlog have to be flushed somewhat.
4347 (when gnus-keep-backlog
4348 (gnus-backlog-remove-article
4349 (car gnus-article-current) (cdr gnus-article-current)))
4350 ;; Flush original article as well.
4352 (when (get-buffer gnus-original-article-buffer)
4353 (set-buffer gnus-original-article-buffer)
4354 (setq gnus-original-article nil)))
4355 (when gnus-use-cache
4356 (gnus-cache-update-article
4357 (car gnus-article-current) (cdr gnus-article-current))))
4359 (set-window-start (get-buffer-window buf) start)
4360 (set-window-point (get-buffer-window buf) (point))))
4362 (defun gnus-article-edit-exit ()
4363 "Exit the article editing without updating."
4365 ;; We remove all text props from the article buffer.
4366 (let ((buf (format "%s" (buffer-string)))
4367 (curbuf (current-buffer))
4369 (window-start (window-start)))
4372 (let ((winconf gnus-prev-winconf))
4374 (set-window-configuration winconf)
4375 ;; Tippy-toe some to make sure that point remains where it was.
4376 (save-current-buffer
4378 (set-window-start (get-buffer-window (current-buffer)) window-start)
4381 (defun gnus-article-edit-full-stops ()
4382 "Interactively repair spacing at end of sentences."
4385 (goto-char (point-min))
4386 (search-forward-regexp "^$" nil t)
4387 (let ((case-fold-search nil))
4388 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4391 ;;; Article editing with MIME-Edit
4394 (defcustom gnus-article-mime-edit-article-setup-hook nil
4395 "Hook run after setting up a MIME editing article buffer."
4396 :group 'gnus-article-various
4399 (defun gnus-article-mime-edit-article-unwind ()
4400 "Unwind `gnus-article-buffer' if article editing was given up."
4401 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4402 (when mime-edit-mode-flag
4403 (mime-edit-exit 'nomime 'no-error)
4405 (when (featurep 'font-lock)
4406 (setq font-lock-defaults nil)
4407 (font-lock-mode 0)))
4409 (defun gnus-article-mime-edit-article-setup ()
4410 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4411 after replacing with the original article."
4412 (setq gnus-show-mime t)
4413 (setq gnus-article-edit-done-function
4414 `(lambda (&rest args)
4415 (when mime-edit-mode-flag
4418 (goto-char (point-min))
4419 (let (case-fold-search)
4420 (when (re-search-forward
4421 (format "^%s$" (regexp-quote mail-header-separator))
4423 (replace-match "")))
4424 (when (featurep 'font-lock)
4425 (setq font-lock-defaults nil)
4427 (apply ,gnus-article-edit-done-function args)
4428 (set-buffer gnus-original-article-buffer)
4430 (insert-buffer gnus-article-buffer)
4431 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4432 (gnus-article-prepare-display)))
4433 (substitute-key-definition
4434 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4435 gnus-article-edit-mode-map)
4437 (insert-buffer gnus-original-article-buffer)
4439 (when (featurep 'font-lock)
4440 (set (make-local-variable 'font-lock-defaults)
4441 '(message-font-lock-keywords t))
4442 (font-lock-set-defaults)
4443 (turn-on-font-lock))
4444 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4445 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4447 (defun gnus-article-mime-edit-exit ()
4448 "Exit the article MIME editing without updating."
4450 (let ((winconf gnus-prev-winconf)
4452 (when mime-edit-mode-flag
4455 (goto-char (point-min))
4456 (let (case-fold-search)
4457 (when (re-search-forward
4458 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4459 (replace-match "")))
4460 (when (featurep 'font-lock)
4461 (setq font-lock-defaults nil)
4463 ;; We remove all text props from the article buffer.
4464 (setq buf (format "%s" (buffer-string)))
4465 (set-buffer (get-buffer-create gnus-original-article-buffer))
4468 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4469 (gnus-article-prepare-display)
4470 (set-window-configuration winconf)))
4473 ;;; Article highlights
4476 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4478 ;;; Internal Variables:
4480 (defcustom gnus-button-url-regexp "\\b\\(\\(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\\)\\)\\|[-a-zA-Z0-9_]+\\.[-a-zA-Z0-9_]+\\(\\.[-a-zA-Z0-9_]+[-a-zA-Z0-9_/]+\\)+"
4481 "Regular expression that matches URLs."
4482 :group 'gnus-article-buttons
4485 (defcustom gnus-button-alist
4486 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4487 0 t gnus-button-message-id 2)
4488 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4489 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4491 gnus-button-fetch-group 4)
4492 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4493 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4494 t gnus-button-message-id 3)
4495 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4496 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4497 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4498 ;; This is how URLs _should_ be embedded in text...
4499 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4501 (,gnus-button-url-regexp 0 t browse-url 0))
4502 "*Alist of regexps matching buttons in article bodies.
4504 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4505 REGEXP: is the string matching text around the button,
4506 BUTTON: is the number of the regexp grouping actually matching the button,
4507 FORM: is a lisp expression which must eval to true for the button to
4509 CALLBACK: is the function to call when the user push this button, and each
4510 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4512 CALLBACK can also be a variable, in that case the value of that
4513 variable it the real callback function."
4514 :group 'gnus-article-buttons
4515 :type '(repeat (list regexp
4516 (integer :tag "Button")
4518 (function :tag "Callback")
4521 (integer :tag "Regexp group")))))
4523 (defcustom gnus-header-button-alist
4524 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4525 0 t gnus-button-message-id 0)
4526 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4527 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4528 0 t gnus-button-mailto 0)
4529 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4530 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4531 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4532 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4533 gnus-button-message-id 3))
4534 "*Alist of headers and regexps to match buttons in article heads.
4536 This alist is very similar to `gnus-button-alist', except that each
4537 alist has an additional HEADER element first in each entry:
4539 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4541 HEADER is a regexp to match a header. For a fuller explanation, see
4542 `gnus-button-alist'."
4543 :group 'gnus-article-buttons
4544 :group 'gnus-article-headers
4545 :type '(repeat (list (regexp :tag "Header")
4547 (integer :tag "Button")
4549 (function :tag "Callback")
4552 (integer :tag "Regexp group")))))
4554 (defvar gnus-button-regexp nil)
4555 (defvar gnus-button-marker-list nil)
4556 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4558 (defvar gnus-button-last nil)
4559 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4563 (defun gnus-article-push-button (event)
4564 "Check text under the mouse pointer for a callback function.
4565 If the text under the mouse pointer has a `gnus-callback' property,
4566 call it with the value of the `gnus-data' text property."
4568 (set-buffer (window-buffer (posn-window (event-start event))))
4569 (let* ((pos (posn-point (event-start event)))
4570 (data (get-text-property pos 'gnus-data))
4571 (fun (get-text-property pos 'gnus-callback)))
4574 (funcall fun data))))
4576 (defun gnus-article-press-button ()
4577 "Check text at point for a callback function.
4578 If the text at point has a `gnus-callback' property,
4579 call it with the value of the `gnus-data' text property."
4581 (let* ((data (get-text-property (point) 'gnus-data))
4582 (fun (get-text-property (point) 'gnus-callback)))
4584 (funcall fun data))))
4586 (defun gnus-article-prev-button (n)
4587 "Move point to N buttons backward.
4588 If N is negative, move forward instead."
4590 (gnus-article-next-button (- n)))
4592 (defun gnus-article-next-button (n)
4593 "Move point to N buttons forward.
4594 If N is negative, move backward instead."
4596 (let ((function (if (< n 0) 'previous-single-property-change
4597 'next-single-property-change))
4598 (inhibit-point-motion-hooks t)
4600 (limit (if (< n 0) (point-min) (point-max))))
4602 (while (and (not (= limit (point)))
4604 ;; Skip past the current button.
4605 (when (get-text-property (point) 'gnus-callback)
4606 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4607 ;; Go to the next (or previous) button.
4608 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4609 ;; Put point at the start of the button.
4610 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4611 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4612 ;; Skip past intangible buttons.
4613 (when (get-text-property (point) 'intangible)
4617 (gnus-message 5 "No more buttons"))
4620 (defun gnus-article-highlight (&optional force)
4621 "Highlight current article.
4622 This function calls `gnus-article-highlight-headers',
4623 `gnus-article-highlight-citation',
4624 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4625 do the highlighting. See the documentation for those functions."
4626 (interactive (list 'force))
4627 (gnus-article-highlight-headers)
4628 (gnus-article-highlight-citation force)
4629 (gnus-article-highlight-signature)
4630 (gnus-article-add-buttons force)
4631 (gnus-article-add-buttons-to-head))
4633 (defun gnus-article-highlight-some (&optional force)
4634 "Highlight current article.
4635 This function calls `gnus-article-highlight-headers',
4636 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4637 do the highlighting. See the documentation for those functions."
4638 (interactive (list 'force))
4639 (gnus-article-highlight-headers)
4640 (gnus-article-highlight-signature)
4641 (gnus-article-add-buttons))
4643 (defun gnus-article-highlight-headers ()
4644 "Highlight article headers as specified by `gnus-header-face-alist'."
4647 (set-buffer gnus-article-buffer)
4649 (let ((alist gnus-header-face-alist)
4650 (buffer-read-only nil)
4651 (case-fold-search t)
4652 (inhibit-point-motion-hooks t)
4653 entry regexp header-face field-face from hpoints fpoints)
4654 (article-narrow-to-head)
4655 (while (setq entry (pop alist))
4656 (goto-char (point-min))
4657 (setq regexp (concat "^\\("
4658 (if (string-equal "" (nth 0 entry))
4662 header-face (nth 1 entry)
4663 field-face (nth 2 entry))
4664 (while (and (re-search-forward regexp nil t)
4668 (unless (search-forward ":" nil t)
4670 (when (and header-face
4671 (not (memq (point) hpoints)))
4672 (push (point) hpoints)
4673 (gnus-put-text-property from (point) 'face header-face))
4674 (when (and field-face
4675 (not (memq (setq from (point)) fpoints)))
4677 (if (re-search-forward "^[^ \t]" nil t)
4679 (goto-char (point-max)))
4680 (gnus-put-text-property from (point) 'face field-face))))))))
4682 (defun gnus-article-highlight-signature ()
4683 "Highlight the signature in an article.
4684 It does this by highlighting everything after
4685 `gnus-signature-separator' using `gnus-signature-face'."
4687 (when gnus-signature-face
4689 (set-buffer gnus-article-buffer)
4690 (let ((buffer-read-only nil)
4691 (inhibit-point-motion-hooks t))
4693 (when (gnus-article-narrow-to-signature)
4694 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4695 'face gnus-signature-face)))))))
4697 (defun gnus-article-buttonize-signature ()
4698 "Add button to the signature."
4701 (set-buffer gnus-article-buffer)
4702 (let ((buffer-read-only nil)
4703 (inhibit-point-motion-hooks t))
4704 (when (gnus-article-search-signature)
4705 (gnus-article-add-button (match-beginning 0) (match-end 0)
4706 'gnus-signature-toggle
4707 (set-marker (make-marker)
4708 (1+ (match-end 0))))))))
4710 (defun gnus-button-in-region-p (b e prop)
4711 "Say whether PROP exists in the region."
4712 (text-property-not-all b e prop nil))
4714 (defun gnus-article-add-buttons (&optional force)
4715 "Find external references in the article and make buttons of them.
4716 \"External references\" are things like Message-IDs and URLs, as
4717 specified by `gnus-button-alist'."
4718 (interactive (list 'force))
4720 (set-buffer gnus-article-buffer)
4721 (let ((buffer-read-only nil)
4722 (inhibit-point-motion-hooks t)
4723 (case-fold-search t)
4724 (alist gnus-button-alist)
4726 ;; Remove all old markers.
4727 (let (marker entry new-list)
4728 (while (setq marker (pop gnus-button-marker-list))
4729 (if (or (< marker (point-min)) (>= marker (point-max)))
4730 (push marker new-list)
4732 (when (setq entry (gnus-button-entry))
4733 (put-text-property (match-beginning (nth 1 entry))
4734 (match-end (nth 1 entry))
4735 'gnus-callback nil))
4736 (set-marker marker nil)))
4737 (setq gnus-button-marker-list new-list))
4738 ;; We skip the headers.
4741 (while (setq entry (pop alist))
4742 (setq regexp (car entry))
4744 (while (re-search-forward regexp nil t)
4745 (let* ((start (and entry (match-beginning (nth 1 entry))))
4746 (end (and entry (match-end (nth 1 entry))))
4747 (from (match-beginning 0)))
4748 (when (and (or (eq t (nth 2 entry))
4749 (eval (nth 2 entry)))
4750 (not (gnus-button-in-region-p
4751 start end 'gnus-callback)))
4752 ;; That optional form returned non-nil, so we add the
4754 (gnus-article-add-button
4755 start end 'gnus-button-push
4756 (car (push (set-marker (make-marker) from)
4757 gnus-button-marker-list))))))))))
4759 ;; Add buttons to the head of an article.
4760 (defun gnus-article-add-buttons-to-head ()
4761 "Add buttons to the head of the article."
4764 (set-buffer gnus-article-buffer)
4766 (let ((buffer-read-only nil)
4767 (inhibit-point-motion-hooks t)
4768 (case-fold-search t)
4769 (alist gnus-header-button-alist)
4771 (article-narrow-to-head)
4773 ;; Each alist entry.
4774 (setq entry (car alist)
4776 (goto-char (point-min))
4777 (while (re-search-forward (car entry) nil t)
4778 ;; Each header matching the entry.
4779 (setq beg (match-beginning 0))
4780 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4781 (match-beginning 0))
4784 (while (re-search-forward (nth 1 entry) end t)
4785 ;; Each match within a header.
4786 (let* ((entry (cdr entry))
4787 (start (match-beginning (nth 1 entry)))
4788 (end (match-end (nth 1 entry)))
4789 (form (nth 2 entry)))
4790 (goto-char (match-end 0))
4792 (gnus-article-add-button
4793 start end (nth 3 entry)
4794 (buffer-substring (match-beginning (nth 4 entry))
4795 (match-end (nth 4 entry)))))))
4796 (goto-char end)))))))
4798 ;;; External functions:
4800 (defun gnus-article-add-button (from to fun &optional data)
4801 "Create a button between FROM and TO with callback FUN and data DATA."
4802 (when gnus-article-button-face
4803 (gnus-overlay-put (gnus-make-overlay from to)
4804 'face gnus-article-button-face))
4805 (gnus-add-text-properties
4807 (nconc (and gnus-article-mouse-face
4808 (list gnus-mouse-face-prop gnus-article-mouse-face))
4809 (list 'gnus-callback fun)
4810 (and data (list 'gnus-data data)))))
4812 ;;; Internal functions:
4814 (defun gnus-article-set-globals ()
4816 (set-buffer gnus-summary-buffer)
4817 (gnus-set-global-variables)))
4819 (defun gnus-signature-toggle (end)
4821 (set-buffer gnus-article-buffer)
4822 (let ((buffer-read-only nil)
4823 (inhibit-point-motion-hooks t)
4824 (limit (next-single-property-change end 'mime-view-entity
4826 (if (get-text-property end 'invisible)
4827 (gnus-article-unhide-text end limit)
4828 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4830 (defun gnus-button-entry ()
4831 ;; Return the first entry in `gnus-button-alist' matching this place.
4832 (let ((alist gnus-button-alist)
4835 (setq entry (pop alist))
4836 (if (looking-at (car entry))
4841 (defun gnus-button-push (marker)
4842 ;; Push button starting at MARKER.
4845 (let* ((entry (gnus-button-entry))
4846 (inhibit-point-motion-hooks t)
4848 (args (mapcar (lambda (group)
4849 (let ((string (match-string group)))
4850 (gnus-set-text-properties
4851 0 (length string) nil string)
4858 (fboundp (symbol-value fun)))
4859 (apply (symbol-value fun) args))
4861 (gnus-message 1 "You must define `%S' to use this button"
4862 (cons fun args)))))))
4864 (defun gnus-button-message-id (message-id)
4867 (set-buffer gnus-summary-buffer)
4868 (gnus-summary-refer-article message-id)))
4870 (defun gnus-button-fetch-group (address)
4871 "Fetch GROUP specified by ADDRESS."
4872 (if (not (string-match "[:/]" address))
4873 ;; This is just a simple group url.
4874 (gnus-group-read-ephemeral-group address gnus-select-method)
4875 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4877 (error "Can't parse %s" address)
4878 (gnus-group-read-ephemeral-group
4879 (match-string 4 address)
4880 `(nntp ,(match-string 1 address)
4881 (nntp-address ,(match-string 1 address))
4882 (nntp-port-number ,(if (match-end 3)
4883 (match-string 3 address)
4886 (defun gnus-url-parse-query-string (query &optional downcase)
4887 (let (retval pairs cur key val)
4888 (setq pairs (split-string query "&"))
4890 (setq cur (car pairs)
4892 (if (not (string-match "=" cur))
4894 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4895 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4897 (setq key (downcase key)))
4898 (setq cur (assoc key retval))
4900 (setcdr cur (cons val (cdr cur)))
4901 (setq retval (cons (list key val) retval)))))
4904 (defun gnus-url-unhex (x)
4911 (defun gnus-url-unhex-string (str &optional allow-newlines)
4912 "Remove %XXX embedded spaces, etc in a url.
4913 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4914 decoding of carriage returns and line feeds in the string, which is normally
4915 forbidden in URL encoding."
4916 (setq str (or str ""))
4918 (case-fold-search t))
4919 (while (string-match "%[0-9a-f][0-9a-f]" str)
4920 (let* ((start (match-beginning 0))
4921 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4923 (gnus-url-unhex (elt str (+ start 2))))))
4925 tmp (substring str 0 start)
4928 (char-to-string code))
4929 ((or (= code ?\n) (= code ?\r))
4931 (t (char-to-string code))))
4932 str (substring str (match-end 0)))))
4933 (setq tmp (concat tmp str))
4936 (defun gnus-url-mailto (url)
4937 ;; Send mail to someone
4938 (when (string-match "mailto:/*\\(.*\\)" url)
4939 (setq url (substring url (match-beginning 1) nil)))
4940 (let (to args subject func)
4941 (if (string-match (regexp-quote "?") url)
4942 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4943 args (gnus-url-parse-query-string
4944 (substring url (match-end 0) nil) t))
4945 (setq to (gnus-url-unhex-string url)))
4946 (setq args (cons (list "to" to) args)
4947 subject (cdr-safe (assoc "subject" args)))
4948 (gnus-setup-message 'reply
4951 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4954 (message-position-on-field (caar args)))
4955 (insert (mapconcat 'identity (cdar args) ", "))
4956 (setq args (cdr args)))
4959 (message-goto-subject)))))
4961 (defun gnus-button-mailto (address)
4963 (set-buffer (gnus-copy-article-buffer))
4964 (gnus-setup-message 'reply
4965 (message-reply address)))
4967 (defun gnus-button-reply (address)
4968 ;; Reply to ADDRESS.
4969 (gnus-setup-message 'reply
4970 (message-reply address)))
4972 (defun gnus-button-embedded-url (address)
4974 (browse-url (gnus-strip-whitespace address)))
4976 (defun gnus-article-smiley-display ()
4977 "Display \"smileys\" as small graphical icons."
4978 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
4980 ;;; Next/prev buttons in the article buffer.
4982 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4983 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4985 (defvar gnus-prev-page-map nil)
4986 (unless gnus-prev-page-map
4987 (setq gnus-prev-page-map (make-sparse-keymap))
4988 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4989 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4991 (static-if (featurep 'xemacs)
4992 (defun gnus-insert-prev-page-button ()
4993 (let ((buffer-read-only nil))
4995 gnus-prev-page-line-format nil
4996 `(gnus-prev t local-map ,gnus-prev-page-map
4997 gnus-callback gnus-article-button-prev-page
4998 article-type annotation))))
4999 (defun gnus-insert-prev-page-button ()
5000 (let ((buffer-read-only nil)
5001 (situation (get-text-property (point-min) 'mime-view-situation)))
5002 (set-keymap-parent gnus-prev-page-map (current-local-map))
5004 gnus-prev-page-line-format nil
5005 `(gnus-prev t local-map ,gnus-prev-page-map
5006 gnus-callback gnus-article-button-prev-page
5007 article-type annotation
5008 mime-view-situation ,situation))))
5011 (defvar gnus-next-page-map nil)
5012 (unless gnus-next-page-map
5013 (setq gnus-next-page-map (make-sparse-keymap))
5014 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5015 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5017 (defun gnus-button-next-page ()
5018 "Go to the next page."
5020 (let ((win (selected-window)))
5021 (select-window (get-buffer-window gnus-article-buffer t))
5022 (gnus-article-next-page)
5023 (select-window win)))
5025 (defun gnus-button-prev-page ()
5026 "Go to the prev page."
5028 (let ((win (selected-window)))
5029 (select-window (get-buffer-window gnus-article-buffer t))
5030 (gnus-article-prev-page)
5031 (select-window win)))
5033 (static-if (featurep 'xemacs)
5034 (defun gnus-insert-next-page-button ()
5035 (let ((buffer-read-only nil))
5036 (gnus-eval-format gnus-next-page-line-format nil
5038 t local-map ,gnus-next-page-map
5039 gnus-callback gnus-article-button-next-page
5040 article-type annotation))))
5041 (defun gnus-insert-next-page-button ()
5042 (let ((buffer-read-only nil)
5043 (situation (get-text-property (point-min) 'mime-view-situation)))
5044 (set-keymap-parent gnus-next-page-map (current-local-map))
5045 (gnus-eval-format gnus-next-page-line-format nil
5047 t local-map ,gnus-next-page-map
5048 gnus-callback gnus-article-button-next-page
5049 article-type annotation
5050 mime-view-situation ,situation))))
5053 (defun gnus-article-button-next-page (arg)
5054 "Go to the next page."
5056 (let ((win (selected-window)))
5057 (select-window (get-buffer-window gnus-article-buffer t))
5058 (gnus-article-next-page)
5059 (select-window win)))
5061 (defun gnus-article-button-prev-page (arg)
5062 "Go to the prev page."
5064 (let ((win (selected-window)))
5065 (select-window (get-buffer-window gnus-article-buffer t))
5066 (gnus-article-prev-page)
5067 (select-window win)))
5069 (defvar gnus-decode-header-methods
5070 '(mail-decode-encoded-word-region)
5071 "List of methods used to decode headers.
5073 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5074 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5075 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5076 whose names match REGEXP.
5079 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5080 mail-decode-encoded-word-region
5081 (\"chinese\" . rfc1843-decode-region))
5084 (defvar gnus-decode-header-methods-cache nil)
5086 (defun gnus-multi-decode-header (start end)
5087 "Apply the functions from `gnus-encoded-word-methods' that match."
5088 (unless (and gnus-decode-header-methods-cache
5089 (eq gnus-newsgroup-name
5090 (car gnus-decode-header-methods-cache)))
5091 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5094 (nconc gnus-decode-header-methods-cache (list x))
5095 (if (and gnus-newsgroup-name
5096 (string-match (car x) gnus-newsgroup-name))
5097 (nconc gnus-decode-header-methods-cache
5099 gnus-decode-header-methods))
5100 (let ((xlist gnus-decode-header-methods-cache))
5103 (narrow-to-region start end)
5105 (funcall (pop xlist) (point-min) (point-max))))))
5108 ;;; Treatment top-level handling.
5111 (defun gnus-treat-article (condition &optional part-number total-parts type)
5112 (let ((length (- (point-max) (point-min)))
5113 (alist gnus-treatment-function-alist)
5114 (article-goto-body-goes-to-point-min-p t)
5118 (let ((list gnus-article-treat-types))
5120 (when (string-match (pop list) type)
5121 (throw 'found t)))))))
5122 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5123 (entity (static-unless (featurep 'xemacs)
5124 (when (eq 'head condition)
5125 (get-text-property (point-min) 'mime-view-entity))))
5126 val elem buttonized)
5127 (gnus-run-hooks 'gnus-part-display-hook)
5128 (unless gnus-inhibit-treatment
5129 (while (setq elem (pop alist))
5132 (if (gnus-buffer-live-p gnus-summary-buffer)
5133 (set-buffer gnus-summary-buffer))
5134 (symbol-value (car elem))))
5135 (when (and (or (consp val)
5137 (gnus-treat-predicate val)
5138 (or (not (get (car elem) 'highlight))
5140 (when (and (not buttonized)
5142 '(gnus-treat-hide-signature
5143 gnus-treat-highlight-signature)))
5144 (gnus-article-buttonize-signature)
5145 (setq buttonized t))
5147 (funcall (cadr elem)))))
5148 ;; FSF Emacsen does not inherit the existing text properties
5149 ;; in the new text, so we should do it for `mime-view-entity'.
5150 (static-unless (featurep 'xemacs)
5152 (put-text-property (point-min) (point-max)
5153 'mime-view-entity entity))))))
5155 ;; Dynamic variables.
5156 (defvar part-number)
5157 (defvar total-parts)
5161 (defun gnus-treat-predicate (val)
5166 (stringp (car val)))
5167 (apply 'gnus-or (mapcar `(lambda (s)
5168 (string-match s ,(or gnus-newsgroup-name "")))
5171 (let ((pred (pop val)))
5174 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5176 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5178 (not (gnus-treat-predicate (car val))))
5180 (equal (car val) type))
5182 (error "%S is not a valid predicate" pred)))))
5192 (eq part-number total-parts))
5196 (error "%S is not a valid value" val))))
5202 (defun gnus-article-header-presentation-method (entity situation)
5203 (mime-insert-header entity)
5206 (set-alist 'mime-header-presentation-method-alist
5207 'gnus-original-article-mode
5208 #'gnus-article-header-presentation-method)
5210 (defun gnus-mime-preview-quitting-method ()
5211 (mime-preview-kill-buffer)
5212 (delete-other-windows)
5213 (gnus-article-show-summary)
5214 (gnus-summary-select-article gnus-show-all-headers t))
5216 (set-alist 'mime-preview-quitting-method-alist
5217 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5219 (set-alist 'mime-preview-following-method-alist
5220 'gnus-original-article-mode #'gnus-following-method)
5222 (set-alist 'mime-preview-over-to-previous-method-alist
5223 'gnus-original-article-mode
5225 (if (> (point-min) 1)
5226 (gnus-article-prev-page)
5227 (gnus-article-read-summary-keys
5228 nil (gnus-character-to-event ?P)))))
5230 (set-alist 'mime-preview-over-to-next-method-alist
5231 'gnus-original-article-mode'
5233 (if (< (point-max) (buffer-size))
5234 (gnus-article-next-page)
5235 (gnus-article-read-summary-keys
5236 nil (gnus-character-to-event ?N)))))
5246 (run-hooks 'gnus-art-load-hook)
5248 ;;; gnus-art.el ends here