1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
41 (defgroup gnus-article nil
43 :link '(custom-manual "(gnus)The Article Buffer")
46 (defgroup gnus-article-treat nil
47 "Treating article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
51 (defgroup gnus-article-hiding nil
52 "Hiding article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-highlight nil
57 "Article highlighting."
58 :link '(custom-manual "(gnus)Article Highlighting")
62 (defgroup gnus-article-signature nil
64 :link '(custom-manual "(gnus)Article Signature")
67 (defgroup gnus-article-headers nil
69 :link '(custom-manual "(gnus)Hiding Headers")
72 (defgroup gnus-article-washing nil
73 "Special commands on articles."
74 :link '(custom-manual "(gnus)Article Washing")
77 (defgroup gnus-article-emphasis nil
78 "Fontisizing articles."
79 :link '(custom-manual "(gnus)Article Fontisizing")
82 (defgroup gnus-article-saving nil
84 :link '(custom-manual "(gnus)Saving Articles")
87 (defgroup gnus-article-mime nil
88 "Worshiping the MIME wonder."
89 :link '(custom-manual "(gnus)Using MIME")
92 (defgroup gnus-article-buttons nil
93 "Pushable buttons in the article buffer."
94 :link '(custom-manual "(gnus)Article Buttons")
97 (defgroup gnus-article-various nil
98 "Other article options."
99 :link '(custom-manual "(gnus)Misc Article")
100 :group 'gnus-article)
102 (defcustom gnus-ignored-headers
103 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
104 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
105 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
106 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
107 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
108 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
109 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
110 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
111 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
112 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
113 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
114 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
115 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
116 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
117 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
118 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
119 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
120 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
121 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
122 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
123 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
124 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
125 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
126 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
127 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
128 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
129 "^X-Received:" "^Content-length:" "X-precedence:")
130 "*All headers that start with this regexp will be hidden.
131 This variable can also be a list of regexps of headers to be ignored.
132 If `gnus-visible-headers' is non-nil, this variable will be ignored."
133 :type '(choice :custom-show nil
136 :group 'gnus-article-hiding)
138 (defcustom gnus-visible-headers
139 "^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:"
140 "*All headers that do not match this regexp will be hidden.
141 This variable can also be a list of regexp of headers to remain visible.
142 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
143 :type '(repeat :value-to-internal (lambda (widget value)
144 (custom-split-regexp-maybe value))
145 :match (lambda (widget value)
147 (widget-editable-list-match widget value)))
149 :group 'gnus-article-hiding)
151 (defcustom gnus-sorted-header-list
152 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
153 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
154 "*This variable is a list of regular expressions.
155 If it is non-nil, headers that match the regular expressions will
156 be placed first in the article buffer in the sequence specified by
158 :type '(repeat regexp)
159 :group 'gnus-article-hiding)
161 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
162 "Headers that are only to be displayed if they have interesting data.
163 Possible values in this list are `empty', `newsgroups', `followup-to',
164 `reply-to', `date', `long-to', and `many-to'."
165 :type '(set (const :tag "Headers with no content." empty)
166 (const :tag "Newsgroups with only one group." newsgroups)
167 (const :tag "Followup-to identical to newsgroups." followup-to)
168 (const :tag "Reply-to identical to from." reply-to)
169 (const :tag "Date less than four days old." date)
170 (const :tag "Very long To and/or Cc header." long-to)
171 (const :tag "Multiple To and/or Cc headers." many-to))
172 :group 'gnus-article-hiding)
174 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
175 "Regexp matching signature separator.
176 This can also be a list of regexps. In that case, it will be checked
177 from head to tail looking for a separator. Searches will be done from
178 the end of the buffer."
179 :type '(repeat string)
180 :group 'gnus-article-signature)
182 (defcustom gnus-signature-limit nil
183 "Provide a limit to what is considered a signature.
184 If it is a number, no signature may not be longer (in characters) than
185 that number. If it is a floating point number, no signature may be
186 longer (in lines) than that number. If it is a function, the function
187 will be called without any parameters, and if it returns nil, there is
188 no signature in the buffer. If it is a string, it will be used as a
189 regexp. If it matches, the text in question is not a signature."
190 :type '(choice (integer :value 200)
192 (function :value fun)
193 (regexp :value ".*"))
194 :group 'gnus-article-signature)
196 (defcustom gnus-hidden-properties '(invisible t intangible t)
197 "Property list to use for hiding text."
199 :group 'gnus-article-hiding)
201 ;; Fixme: This isn't the right thing for mixed graphical and and
202 ;; non-graphical frames in a session.
203 ;; gnus-xmas.el overrides this for XEmacs.
204 (defcustom gnus-article-x-face-command
205 (if (and (fboundp 'image-type-available-p)
206 (image-type-available-p 'xbm))
207 'gnus-article-display-xface
208 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -")
209 "*String or function to be executed to display an X-Face header.
210 If it is a string, the command will be executed in a sub-shell
211 asynchronously. The compressed face will be piped to this command."
212 :type '(choice string
213 (function-item gnus-article-display-xface)
215 :group 'gnus-article-washing)
217 (defcustom gnus-article-x-face-too-ugly nil
218 "Regexp matching posters whose face shouldn't be shown automatically."
219 :type '(choice regexp (const nil))
220 :group 'gnus-article-washing)
222 (defcustom gnus-article-banner-alist nil
223 "Banner alist for stripping.
225 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
226 :type '(repeat (cons symbol regexp))
227 :group 'gnus-article-washing)
229 (defcustom gnus-emphasis-alist
231 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
233 '(("_" "_" underline)
236 ("_/" "/_" underline-italic)
237 ("_\\*" "\\*_" underline-bold)
238 ("\\*/" "/\\*" bold-italic)
239 ("_\\*/" "/\\*_" underline-bold-italic))))
240 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
241 2 3 gnus-emphasis-underline)
245 (format format (car spec) (cadr spec))
246 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
248 "*Alist that says how to fontify certain phrases.
249 Each item looks like this:
251 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
253 The first element is a regular expression to be matched. The second
254 is a number that says what regular expression grouping used to find
255 the entire emphasized word. The third is a number that says what
256 regexp grouping should be displayed and highlighted. The fourth
257 is the face used for highlighting."
258 :type '(repeat (list :value ("" 0 0 default)
260 (integer :tag "Match group")
261 (integer :tag "Emphasize group")
263 :group 'gnus-article-emphasis)
265 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
266 "A regexp to describe whitespace which should not be emphasized.
267 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
268 The former avoids underlining of leading and trailing whitespace,
269 and the latter avoids underlining any whitespace at all."
270 :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-page-delimiter "^\^L"
422 "*Regexp describing what to use as article page delimiters.
423 The default value is \"^\^L\", which is a form linefeed at the
424 beginning of a line."
426 :group 'gnus-article-various)
428 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
429 "*The format specification for the article mode line.
430 See `gnus-summary-mode-line-format' for a closer description.
432 The following additional specs are available:
434 %w The article washing status.
435 %m The number of MIME parts in the article."
437 :group 'gnus-article-various)
439 (defcustom gnus-article-mode-hook nil
440 "*A hook for Gnus article mode."
442 :group 'gnus-article-various)
444 (defcustom gnus-article-menu-hook nil
445 "*Hook run after the creation of the article mode menu."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-prepare-hook nil
450 "*A hook called after an article has been prepared in the article buffer."
452 :group 'gnus-article-various)
454 (defcustom gnus-article-hide-pgp-hook nil
455 "*A hook called after successfully hiding a PGP signature."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-button-face 'bold
460 "Face used for highlighting buttons in the article buffer.
462 An article button is a piece of text that you can activate by pressing
463 `RET' or `mouse-2' above it."
465 :group 'gnus-article-buttons)
467 (defcustom gnus-article-mouse-face 'highlight
468 "Face used for mouse highlighting in the article buffer.
470 Article buttons will be displayed in this face when the cursor is
473 :group 'gnus-article-buttons)
475 (defcustom gnus-signature-face 'gnus-signature-face
476 "Face used for highlighting a signature in the article buffer.
477 Obsolete; use the face `gnus-signature-face' for customizations instead."
479 :group 'gnus-article-highlight
480 :group 'gnus-article-signature)
482 (defface gnus-signature-face
485 "Face used for highlighting a signature in the article buffer."
486 :group 'gnus-article-highlight
487 :group 'gnus-article-signature)
489 (defface gnus-header-from-face
492 (:foreground "spring green"))
495 (:foreground "red3"))
498 "Face used for displaying from headers."
499 :group 'gnus-article-headers
500 :group 'gnus-article-highlight)
502 (defface gnus-header-subject-face
505 (:foreground "SeaGreen3"))
508 (:foreground "red4"))
510 (:bold t :italic t)))
511 "Face used for displaying subject headers."
512 :group 'gnus-article-headers
513 :group 'gnus-article-highlight)
515 (defface gnus-header-newsgroups-face
518 (:foreground "yellow" :italic t))
521 (:foreground "MidnightBlue" :italic t))
524 "Face used for displaying newsgroups headers."
525 :group 'gnus-article-headers
526 :group 'gnus-article-highlight)
528 (defface gnus-header-name-face
531 (:foreground "SeaGreen"))
534 (:foreground "maroon"))
537 "Face used for displaying header names."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight)
541 (defface gnus-header-content-face
544 (:foreground "forest green" :italic t))
547 (:foreground "indianred4" :italic t))
549 (:italic t))) "Face used for displaying header content."
550 :group 'gnus-article-headers
551 :group 'gnus-article-highlight)
553 (defcustom gnus-header-face-alist
554 '(("From" nil gnus-header-from-face)
555 ("Subject" nil gnus-header-subject-face)
556 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
557 ("" gnus-header-name-face gnus-header-content-face))
558 "*Controls highlighting of article header.
560 An alist of the form (HEADER NAME CONTENT).
562 HEADER is a regular expression which should match the name of an
563 header header and NAME and CONTENT are either face names or nil.
565 The name of each header field will be displayed using the face
566 specified by the first element in the list where HEADER match the
567 header name and NAME is non-nil. Similarly, the content will be
568 displayed by the first non-nil matching CONTENT face."
569 :group 'gnus-article-headers
570 :group 'gnus-article-highlight
571 :type '(repeat (list (regexp :tag "Header")
573 (item :tag "skip" nil)
574 (face :value default))
575 (choice :tag "Content"
576 (item :tag "skip" nil)
577 (face :value default)))))
579 (defcustom gnus-article-decode-hook
580 '(article-decode-charset article-decode-encoded-words)
581 "*Hook run to decode charsets in articles."
582 :group 'gnus-article-headers
585 (defcustom gnus-display-mime-function 'gnus-display-mime
586 "Function to display MIME articles."
587 :group 'gnus-article-mime
590 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
591 "Function used to decode headers.")
593 (defvar gnus-article-dumbquotes-map
611 "Table for MS-to-Latin1 translation.")
613 (defcustom gnus-ignored-mime-types nil
614 "List of MIME types that should be ignored by Gnus."
615 :group 'gnus-article-mime
616 :type '(repeat regexp))
618 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
619 "List of MIME types that should not be given buttons when rendered inline."
620 :group 'gnus-article-mime
621 :type '(repeat regexp))
623 (defcustom gnus-article-mime-part-function nil
624 "Function called with a MIME handle as the argument.
625 This is meant for people who want to do something automatic based
626 on parts -- for instance, adding Vcard info to a database."
627 :group 'gnus-article-mime
630 (defcustom gnus-mime-multipart-functions nil
631 "An alist of MIME types to functions to display them.")
633 (defcustom gnus-article-date-lapsed-new-header nil
634 "Whether the X-Sent and Date headers can coexist.
635 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
636 either replace the old \"Date:\" header (if this variable is nil), or
637 be added below it (otherwise)."
638 :group 'gnus-article-headers
641 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
642 "Function called with a MIME handle as the argument.
643 This is meant for people who want to view first matched part.
644 For `undisplayed-alternative' (default), the first undisplayed
645 part or alternative part is used. For `undisplayed', the first
646 undisplayed part is used. For a function, the first part which
647 the function return `t' is used. For `nil', the first part is
649 :group 'gnus-article-mime
651 (item :tag "first" :value nil)
652 (item :tag "undisplayed" :value undisplayed)
653 (item :tag "undisplayed or alternative"
654 :value undisplayed-alternative)
657 (defcustom gnus-mime-action-alist
658 '(("save to file" . gnus-mime-save-part)
659 ("display as text" . gnus-mime-inline-part)
660 ("view the part" . gnus-mime-view-part)
661 ("pipe to command" . gnus-mime-pipe-part)
662 ("toggle display" . gnus-article-press-button)
663 ("view as type" . gnus-mime-view-part-as-type)
664 ("internalize type" . gnus-mime-internalize-part)
665 ("externalize type" . gnus-mime-externalize-part))
666 "An alist of actions that run on the MIME attachment."
667 :group 'gnus-article-mime
668 :type '(repeat (cons (string :tag "name")
672 ;;; The treatment variables
675 (defvar gnus-part-display-hook nil
676 "Hook called on parts that are to receive treatment.")
678 (defvar gnus-article-treat-custom
679 '(choice (const :tag "Off" nil)
681 (const :tag "Header" head)
682 (const :tag "Last" last)
683 (integer :tag "Less")
684 (repeat :tag "Groups" regexp)
685 (sexp :tag "Predicate")))
687 (defvar gnus-article-treat-head-custom
688 '(choice (const :tag "Off" nil)
689 (const :tag "Header" head)))
691 (defvar gnus-article-treat-types '("text/plain")
694 (defvar gnus-inhibit-treatment nil
695 "Whether to inhibit treatment.")
697 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
698 "Highlight the signature.
699 Valid values are nil, t, `head', `last', an integer or a predicate.
700 See the manual for details."
701 :group 'gnus-article-treat
702 :type gnus-article-treat-custom)
703 (put 'gnus-treat-highlight-signature 'highlight t)
705 (defcustom gnus-treat-buttonize 100000
707 Valid values are nil, t, `head', `last', an integer or a predicate.
708 See the manual for details."
709 :group 'gnus-article-treat
710 :type gnus-article-treat-custom)
711 (put 'gnus-treat-buttonize 'highlight t)
713 (defcustom gnus-treat-buttonize-head 'head
714 "Add buttons to the head.
715 Valid values are nil, t, `head', `last', an integer or a predicate.
716 See the manual for details."
717 :group 'gnus-article-treat
718 :type gnus-article-treat-head-custom)
719 (put 'gnus-treat-buttonize-head 'highlight t)
721 (defcustom gnus-treat-emphasize 50000
723 Valid values are nil, t, `head', `last', an integer or a predicate.
724 See the manual for details."
725 :group 'gnus-article-treat
726 :type gnus-article-treat-custom)
727 (put 'gnus-treat-emphasize 'highlight t)
729 (defcustom gnus-treat-strip-cr nil
730 "Remove carriage returns.
731 Valid values are nil, t, `head', `last', an integer or a predicate.
732 See the manual for details."
733 :group 'gnus-article-treat
734 :type gnus-article-treat-custom)
736 (defcustom gnus-treat-hide-headers 'head
738 Valid values are nil, t, `head', `last', an integer or a predicate.
739 See the manual for details."
740 :group 'gnus-article-treat
741 :type gnus-article-treat-head-custom)
743 (defcustom gnus-treat-hide-boring-headers nil
744 "Hide boring headers.
745 Valid values are nil, t, `head', `last', an integer or a predicate.
746 See the manual for details."
747 :group 'gnus-article-treat
748 :type gnus-article-treat-head-custom)
750 (defcustom gnus-treat-hide-signature nil
752 Valid values are nil, t, `head', `last', an integer or a predicate.
753 See the manual for details."
754 :group 'gnus-article-treat
755 :type gnus-article-treat-custom)
757 (defcustom gnus-treat-fill-article nil
759 Valid values are nil, t, `head', `last', an integer or a predicate.
760 See the manual for details."
761 :group 'gnus-article-treat
762 :type gnus-article-treat-custom)
764 (defcustom gnus-treat-hide-citation nil
766 Valid values are nil, t, `head', `last', an integer or a predicate.
767 See the manual for details."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-custom)
771 (defcustom gnus-treat-strip-list-identifiers 'head
772 "Strip list identifiers from `gnus-list-identifiers`.
773 Valid values are nil, t, `head', `last', an integer or a predicate.
774 See the manual for details."
775 :group 'gnus-article-treat
776 :type gnus-article-treat-custom)
778 (defcustom gnus-treat-strip-pgp t
779 "Strip PGP signatures.
780 Valid values are nil, t, `head', `last', an integer or a predicate.
781 See the manual for details."
782 :group 'gnus-article-treat
783 :type gnus-article-treat-custom)
785 (defcustom gnus-treat-strip-pem nil
786 "Strip PEM signatures.
787 Valid values are nil, t, `head', `last', an integer or a predicate.
788 See the manual for details."
789 :group 'gnus-article-treat
790 :type gnus-article-treat-custom)
792 (defcustom gnus-treat-strip-banner t
793 "Strip banners from articles.
794 The banner to be stripped is specified in the `banner' group parameter.
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797 :group 'gnus-article-treat
798 :type gnus-article-treat-custom)
800 (defcustom gnus-treat-highlight-headers 'head
801 "Highlight the headers.
802 Valid values are nil, t, `head', `last', an integer or a predicate.
803 See the manual for details."
804 :group 'gnus-article-treat
805 :type gnus-article-treat-head-custom)
806 (put 'gnus-treat-highlight-headers 'highlight t)
808 (defcustom gnus-treat-highlight-citation t
809 "Highlight cited text.
810 Valid values are nil, t, `head', `last', an integer or a predicate.
811 See the manual for details."
812 :group 'gnus-article-treat
813 :type gnus-article-treat-custom)
814 (put 'gnus-treat-highlight-citation 'highlight t)
816 (defcustom gnus-treat-date-ut nil
817 "Display the Date in UT (GMT).
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-head-custom)
823 (defcustom gnus-treat-date-local nil
824 "Display the Date in the local timezone.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-head-custom)
830 (defcustom gnus-treat-date-lapsed nil
831 "Display the Date header in a way that says how much time has elapsed.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-head-custom)
837 (defcustom gnus-treat-date-original nil
838 "Display the date in the original timezone.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-head-custom)
844 (defcustom gnus-treat-date-iso8601 nil
845 "Display the date in the ISO8601 format.
846 Valid values are nil, t, `head', `last', an integer or a predicate.
847 See the manual for details."
848 :group 'gnus-article-treat
849 :type gnus-article-treat-head-custom)
851 (defcustom gnus-treat-date-user-defined nil
852 "Display the date in a user-defined format.
853 The format is defined by the `gnus-article-time-format' variable.
854 Valid values are nil, t, `head', `last', an integer or a predicate.
855 See the manual for details."
856 :group 'gnus-article-treat
857 :type gnus-article-treat-head-custom)
859 (defcustom gnus-treat-strip-headers-in-body t
860 "Strip the X-No-Archive header line from the beginning of the body.
861 Valid values are nil, t, `head', `last', an integer or a predicate.
862 See the manual for details."
863 :group 'gnus-article-treat
864 :type gnus-article-treat-custom)
866 (defcustom gnus-treat-strip-trailing-blank-lines nil
867 "Strip trailing blank lines.
868 Valid values are nil, t, `head', `last', an integer or a predicate.
869 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-custom)
873 (defcustom gnus-treat-strip-leading-blank-lines nil
874 "Strip leading blank lines.
875 Valid values are nil, t, `head', `last', an integer or a predicate.
876 See the manual for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-custom)
880 (defcustom gnus-treat-strip-multiple-blank-lines nil
881 "Strip multiple blank lines.
882 Valid values are nil, t, `head', `last', an integer or a predicate.
883 See the manual for details."
884 :group 'gnus-article-treat
885 :type gnus-article-treat-custom)
887 (defcustom gnus-treat-overstrike t
888 "Treat overstrike highlighting.
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891 :group 'gnus-article-treat
892 :type gnus-article-treat-custom)
893 (put 'gnus-treat-overstrike 'highlight t)
895 (defcustom gnus-treat-display-xface
896 (and (or (and (fboundp 'image-type-available-p)
897 (image-type-available-p 'xbm))
898 (and gnus-xemacs (featurep 'xface)))
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 (if (and gnus-xemacs
911 Valid values are nil, t, `head', `last', an integer or a predicate.
912 See the manual for details."
913 :group 'gnus-article-treat
914 :type gnus-article-treat-custom)
915 (put 'gnus-treat-display-smileys 'highlight t)
917 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921 :group 'gnus-article-treat
922 :type gnus-article-treat-head-custom)
923 (put 'gnus-treat-display-picons 'highlight t)
925 (defcustom gnus-treat-capitalize-sentences nil
926 "Capitalize sentence-starting words.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See the manual for details."
929 :group 'gnus-article-treat
930 :type gnus-article-treat-custom)
932 (defcustom gnus-treat-fill-long-lines nil
934 Valid values are nil, t, `head', `last', an integer or a predicate.
935 See the manual for details."
936 :group 'gnus-article-treat
937 :type gnus-article-treat-custom)
939 (defcustom gnus-treat-play-sounds nil
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See the manual for details."
943 :group 'gnus-article-treat
944 :type gnus-article-treat-custom)
946 (defcustom gnus-treat-translate nil
947 "Translate articles from one language to another.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See the manual for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-custom)
953 ;;; Internal variables
955 (defvar article-goto-body-goes-to-point-min-p nil)
956 (defvar gnus-article-wash-types nil)
957 (defvar gnus-article-emphasis-alist nil)
959 (defvar gnus-article-mime-handle-alist-1 nil)
960 (defvar gnus-treatment-function-alist
961 '((gnus-treat-strip-banner gnus-article-strip-banner)
962 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
963 (gnus-treat-highlight-signature gnus-article-highlight-signature)
964 (gnus-treat-buttonize gnus-article-add-buttons)
965 (gnus-treat-fill-article gnus-article-fill-cited-article)
966 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
967 (gnus-treat-strip-cr gnus-article-remove-cr)
968 (gnus-treat-emphasize gnus-article-emphasize)
969 (gnus-treat-display-xface gnus-article-display-x-face)
970 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
971 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
972 (gnus-treat-hide-signature gnus-article-hide-signature)
973 (gnus-treat-hide-citation gnus-article-hide-citation)
974 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
975 (gnus-treat-strip-pgp gnus-article-hide-pgp)
976 (gnus-treat-strip-pem gnus-article-hide-pem)
977 (gnus-treat-highlight-headers gnus-article-highlight-headers)
978 (gnus-treat-highlight-citation gnus-article-highlight-citation)
979 (gnus-treat-highlight-signature gnus-article-highlight-signature)
980 (gnus-treat-date-ut gnus-article-date-ut)
981 (gnus-treat-date-local gnus-article-date-local)
982 (gnus-treat-date-lapsed gnus-article-date-lapsed)
983 (gnus-treat-date-original gnus-article-date-original)
984 (gnus-treat-date-user-defined gnus-article-date-user)
985 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
986 (gnus-treat-strip-trailing-blank-lines
987 gnus-article-remove-trailing-blank-lines)
988 (gnus-treat-strip-leading-blank-lines
989 gnus-article-strip-leading-blank-lines)
990 (gnus-treat-strip-multiple-blank-lines
991 gnus-article-strip-multiple-blank-lines)
992 (gnus-treat-overstrike gnus-article-treat-overstrike)
993 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
994 (gnus-treat-display-smileys gnus-smiley-display)
995 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
996 (gnus-treat-display-picons gnus-article-display-picons)
997 (gnus-treat-play-sounds gnus-earcon-display)))
999 (defvar gnus-article-mime-handle-alist nil)
1000 (defvar article-lapsed-timer nil)
1001 (defvar gnus-article-current-summary nil)
1003 (defvar gnus-article-mode-syntax-table
1004 (let ((table (copy-syntax-table text-mode-syntax-table)))
1005 (modify-syntax-entry ?- "w" table)
1006 (modify-syntax-entry ?> ")" table)
1007 (modify-syntax-entry ?< "(" table)
1009 "Syntax table used in article mode buffers.
1010 Initialized from `text-mode-syntax-table.")
1012 (defvar gnus-save-article-buffer nil)
1014 (defvar gnus-article-mode-line-format-alist
1015 (nconc '((?w (gnus-article-wash-status) ?s)
1016 (?m (gnus-article-mime-part-status) ?s))
1017 gnus-summary-mode-line-format-alist))
1019 (defvar gnus-number-of-articles-to-be-saved nil)
1021 (defvar gnus-inhibit-hiding nil)
1023 (defsubst gnus-article-hide-text (b e props)
1024 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1025 (add-text-properties b e props)
1026 (when (memq 'intangible props)
1028 (max (1- b) (point-min))
1029 b 'intangible (cddr (memq 'intangible props)))))
1030 (defsubst gnus-article-unhide-text (b e)
1031 "Remove hidden text properties from region between B and E."
1032 (remove-text-properties b e gnus-hidden-properties)
1033 (when (memq 'intangible gnus-hidden-properties)
1034 (put-text-property (max (1- b) (point-min))
1035 b 'intangible nil)))
1037 (defun gnus-article-hide-text-type (b e type)
1038 "Hide text of TYPE between B and E."
1039 (push type gnus-article-wash-types)
1040 (gnus-article-hide-text
1041 b e (cons 'article-type (cons type gnus-hidden-properties))))
1043 (defun gnus-article-unhide-text-type (b e type)
1044 "Unhide text of TYPE between B and E."
1045 (setq gnus-article-wash-types
1046 (delq type gnus-article-wash-types))
1047 (remove-text-properties
1048 b e (cons 'article-type (cons type gnus-hidden-properties)))
1049 (when (memq 'intangible gnus-hidden-properties)
1050 (put-text-property (max (1- b) (point-min))
1051 b 'intangible nil)))
1053 (defun gnus-article-hide-text-of-type (type)
1054 "Hide text of TYPE in the current buffer."
1056 (let ((b (point-min))
1058 (while (setq b (text-property-any b e 'article-type type))
1059 (add-text-properties b (incf b) gnus-hidden-properties)))))
1061 (defun gnus-article-delete-text-of-type (type)
1062 "Delete text of TYPE in the current buffer."
1064 (let ((b (point-min)))
1065 (while (setq b (text-property-any b (point-max) 'article-type type))
1067 b (or (text-property-not-all b (point-max) 'article-type type)
1070 (defun gnus-article-delete-invisible-text ()
1071 "Delete all invisible text in the current buffer."
1073 (let ((b (point-min)))
1074 (while (setq b (text-property-any b (point-max) 'invisible t))
1076 b (or (text-property-not-all b (point-max) 'invisible t)
1079 (defun gnus-article-text-type-exists-p (type)
1080 "Say whether any text of type TYPE exists in the buffer."
1081 (text-property-any (point-min) (point-max) 'article-type type))
1083 (defsubst gnus-article-header-rank ()
1084 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1085 (let ((list gnus-sorted-header-list)
1088 (when (looking-at (car list))
1090 (setq list (cdr list))
1094 (defun article-hide-headers (&optional arg delete)
1095 "Hide unwanted headers and possibly sort them as well."
1097 ;; This function might be inhibited.
1098 (unless gnus-inhibit-hiding
1101 (let ((buffer-read-only nil)
1102 (case-fold-search t)
1103 (max (1+ (length gnus-sorted-header-list)))
1104 (ignored (when (not gnus-visible-headers)
1105 (cond ((stringp gnus-ignored-headers)
1106 gnus-ignored-headers)
1107 ((listp gnus-ignored-headers)
1108 (mapconcat 'identity gnus-ignored-headers
1111 (cond ((stringp gnus-visible-headers)
1112 gnus-visible-headers)
1113 ((and gnus-visible-headers
1114 (listp gnus-visible-headers))
1115 (mapconcat 'identity gnus-visible-headers "\\|"))))
1116 (inhibit-point-motion-hooks t)
1118 ;; First we narrow to just the headers.
1119 (article-narrow-to-head)
1120 ;; Hide any "From " lines at the beginning of (mail) articles.
1121 (while (looking-at "From ")
1124 (delete-region (point-min) (point)))
1125 ;; Then treat the rest of the header lines.
1126 ;; Then we use the two regular expressions
1127 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1128 ;; select which header lines is to remain visible in the
1130 (while (re-search-forward "^[^ \t]*:" nil t)
1132 ;; Mark the rank of the header.
1134 (point) (1+ (point)) 'message-rank
1135 (if (or (and visible (looking-at visible))
1137 (not (looking-at ignored))))
1138 (gnus-article-header-rank)
1141 (message-sort-headers-1)
1142 (when (setq beg (text-property-any
1143 (point-min) (point-max) 'message-rank (+ 2 max)))
1144 ;; We delete the unwanted headers.
1145 (push 'headers gnus-article-wash-types)
1146 (add-text-properties (point-min) (+ 5 (point-min))
1147 '(article-type headers dummy-invisible t))
1148 (delete-region beg (point-max))))))))
1150 (defun article-hide-boring-headers (&optional arg)
1151 "Toggle hiding of headers that aren't very interesting.
1152 If given a negative prefix, always show; if given a positive prefix,
1154 (interactive (gnus-article-hidden-arg))
1155 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1156 (not gnus-show-all-headers))
1159 (let ((buffer-read-only nil)
1160 (list gnus-boring-article-headers)
1161 (inhibit-point-motion-hooks t)
1163 (article-narrow-to-head)
1165 (setq elem (pop list))
1166 (goto-char (point-min))
1168 ;; Hide empty headers.
1170 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1172 (gnus-article-hide-text-type
1173 (progn (beginning-of-line) (point))
1176 (if (re-search-forward "^[^ \t]" nil t)
1180 ;; Hide boring Newsgroups header.
1181 ((eq elem 'newsgroups)
1182 (when (equal (gnus-fetch-field "newsgroups")
1183 (gnus-group-real-name
1184 (if (boundp 'gnus-newsgroup-name)
1187 (gnus-article-hide-header "newsgroups")))
1188 ((eq elem 'followup-to)
1189 (when (equal (message-fetch-field "followup-to")
1190 (message-fetch-field "newsgroups"))
1191 (gnus-article-hide-header "followup-to")))
1192 ((eq elem 'reply-to)
1193 (let ((from (message-fetch-field "from"))
1194 (reply-to (message-fetch-field "reply-to")))
1199 (nth 1 (mail-extract-address-components from))
1200 (nth 1 (mail-extract-address-components reply-to)))))
1201 (gnus-article-hide-header "reply-to"))))
1203 (let ((date (message-fetch-field "date")))
1205 (< (days-between (current-time-string) date)
1207 (gnus-article-hide-header "date"))))
1209 (let ((to (message-fetch-field "to"))
1210 (cc (message-fetch-field "cc")))
1211 (when (> (length to) 1024)
1212 (gnus-article-hide-header "to"))
1213 (when (> (length cc) 1024)
1214 (gnus-article-hide-header "cc"))))
1218 (goto-char (point-min))
1219 (while (re-search-forward "^to:" nil t)
1220 (setq to-count (1+ to-count)))
1221 (when (> to-count 1)
1222 (while (> to-count 0)
1223 (goto-char (point-min))
1225 (re-search-forward "^to:" nil nil to-count)
1227 (narrow-to-region (point) (point-max))
1228 (gnus-article-hide-header "to"))
1229 (setq to-count (1- to-count))))
1230 (goto-char (point-min))
1231 (while (re-search-forward "^cc:" nil t)
1232 (setq cc-count (1+ cc-count)))
1233 (when (> cc-count 1)
1234 (while (> cc-count 0)
1235 (goto-char (point-min))
1237 (re-search-forward "^cc:" nil nil cc-count)
1239 (narrow-to-region (point) (point-max))
1240 (gnus-article-hide-header "cc"))
1241 (setq cc-count (1- cc-count)))))))))))))
1243 (defun gnus-article-hide-header (header)
1245 (goto-char (point-min))
1246 (when (re-search-forward (concat "^" header ":") nil t)
1247 (gnus-article-hide-text-type
1248 (progn (beginning-of-line) (point))
1251 (if (re-search-forward "^[^ \t]" nil t)
1256 (defvar gnus-article-normalized-header-length 40
1257 "Length of normalized headers.")
1259 (defun article-normalize-headers ()
1260 "Make all header lines 40 characters long."
1262 (let ((buffer-read-only nil)
1266 (article-narrow-to-head)
1269 ((< (setq column (- (gnus-point-at-eol) (point)))
1270 gnus-article-normalized-header-length)
1272 (insert (make-string
1273 (- gnus-article-normalized-header-length column)
1275 ((> column gnus-article-normalized-header-length)
1276 (gnus-put-text-property
1278 (forward-char gnus-article-normalized-header-length)
1285 (forward-line 1))))))
1287 (defun article-treat-dumbquotes ()
1288 "Translate M******** sm*rtq**t*s into proper text.
1289 Note that this function guesses whether a character is a sm*rtq**t* or
1290 not, so it should only be used interactively."
1292 (article-translate-strings gnus-article-dumbquotes-map))
1294 (defun article-translate-characters (from to)
1295 "Translate all characters in the body of the article according to FROM and TO.
1296 FROM is a string of characters to translate from; to is a string of
1297 characters to translate to."
1299 (when (article-goto-body)
1300 (let ((buffer-read-only nil)
1301 (x (make-string 225 ?x))
1303 (while (< (incf i) (length x))
1306 (while (< i (length from))
1307 (aset x (aref from i) (aref to i))
1309 (translate-region (point) (point-max) x)))))
1311 (defun article-translate-strings (map)
1312 "Translate all string in the body of the article according to MAP.
1313 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1315 (when (article-goto-body)
1316 (let ((buffer-read-only nil)
1318 (while (setq elem (pop map))
1320 (while (search-forward (car elem) nil t)
1321 (replace-match (cadr elem)))))))))
1323 (defun article-treat-overstrike ()
1324 "Translate overstrikes into bold text."
1327 (when (article-goto-body)
1328 (let ((buffer-read-only nil))
1329 (while (search-forward "\b" nil t)
1330 (let ((next (char-after))
1331 (previous (char-after (- (point) 2))))
1332 ;; We do the boldification/underlining by hiding the
1333 ;; overstrikes and putting the proper text property
1337 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1338 (put-text-property (point) (1+ (point)) 'face 'bold))
1340 (gnus-article-hide-text-type
1341 (1- (point)) (1+ (point)) 'overstrike)
1343 (- (point) 2) (1- (point)) 'face 'underline))
1345 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1347 (point) (1+ (point)) 'face 'underline)))))))))
1349 (defun article-fill-long-lines ()
1350 "Fill lines that are wider than the window width."
1353 (let ((buffer-read-only nil)
1354 (width (window-width (get-buffer-window (current-buffer)))))
1357 (let ((adaptive-fill-mode nil))
1360 (when (>= (current-column) (min fill-column width))
1361 (narrow-to-region (point) (gnus-point-at-bol))
1362 (fill-paragraph nil)
1363 (goto-char (point-max))
1365 (forward-line 1)))))))
1367 (defun article-capitalize-sentences ()
1368 "Capitalize the first word in each sentence."
1371 (let ((buffer-read-only nil)
1372 (paragraph-start "^[\n\^L]"))
1376 (forward-sentence)))))
1378 (defun article-remove-cr ()
1379 "Remove trailing CRs and then translate remaining CRs into LFs."
1382 (let ((buffer-read-only nil))
1383 (goto-char (point-min))
1384 (while (re-search-forward "\r+$" nil t)
1385 (replace-match "" t t))
1386 (goto-char (point-min))
1387 (while (search-forward "\r" nil t)
1388 (replace-match "\n" t t)))))
1390 (defun article-remove-trailing-blank-lines ()
1391 "Remove all trailing blank lines from the article."
1394 (let ((buffer-read-only nil))
1395 (goto-char (point-max))
1399 (while (and (not (bobp))
1400 (looking-at "^[ \t]*$")
1401 (not (gnus-annotation-in-region-p
1402 (point) (gnus-point-at-eol))))
1407 (defun article-display-x-face (&optional force)
1408 "Look for an X-Face header and display it if present."
1409 (interactive (list 'force))
1411 ;; Delete the old process, if any.
1412 (when (process-status "article-x-face")
1413 (delete-process "article-x-face"))
1414 (let ((inhibit-point-motion-hooks t)
1415 (case-fold-search t)
1418 (article-narrow-to-head)
1419 (goto-char (point-min))
1420 (setq from (message-fetch-field "from"))
1421 (goto-char (point-min))
1422 (while (and gnus-article-x-face-command
1425 ;; Check whether this face is censored.
1426 (not gnus-article-x-face-too-ugly)
1427 (and gnus-article-x-face-too-ugly from
1428 (not (string-match gnus-article-x-face-too-ugly
1430 ;; Has to be present.
1431 (re-search-forward "^X-Face: " nil t))
1432 ;; This used to try to do multiple faces (`while' instead of
1433 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1434 ;; work (b) it can crash some versions of Emacs (c) are
1435 ;; multiple faces really something to encourage?
1436 (when (stringp gnus-article-x-face-command)
1438 ;; We now have the area of the buffer where the X-Face is stored.
1441 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1442 ;; We display the face.
1443 (if (symbolp gnus-article-x-face-command)
1444 ;; The command is a lisp function, so we call it.
1445 (if (gnus-functionp gnus-article-x-face-command)
1446 (funcall gnus-article-x-face-command beg end)
1447 (error "%s is not a function" gnus-article-x-face-command))
1448 ;; The command is a string, so we interpret the command
1449 ;; as a, well, command, and fork it off.
1450 (let ((process-connection-type nil))
1451 (process-kill-without-query
1453 "article-x-face" nil shell-file-name shell-command-switch
1454 gnus-article-x-face-command))
1455 (process-send-region "article-x-face" beg end)
1456 (process-send-eof "article-x-face"))))))))))
1458 (defun article-decode-mime-words ()
1459 "Decode all MIME-encoded words in the article."
1462 (set-buffer gnus-article-buffer)
1463 (let ((inhibit-point-motion-hooks t)
1465 (mail-parse-charset gnus-newsgroup-charset)
1466 (mail-parse-ignored-charsets
1467 (save-excursion (set-buffer gnus-summary-buffer)
1468 gnus-newsgroup-ignored-charsets)))
1469 (mail-decode-encoded-word-region (point-min) (point-max)))))
1471 (defun article-decode-charset (&optional prompt)
1472 "Decode charset-encoded text in the article.
1473 If PROMPT (the prefix), prompt for a coding system to use."
1475 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1477 (mail-parse-charset gnus-newsgroup-charset)
1478 (mail-parse-ignored-charsets
1479 (save-excursion (condition-case nil
1480 (set-buffer gnus-summary-buffer)
1482 gnus-newsgroup-ignored-charsets))
1483 ct cte ctl charset format)
1486 (article-narrow-to-head)
1487 (setq ct (message-fetch-field "Content-Type" t)
1488 cte (message-fetch-field "Content-Transfer-Encoding" t)
1489 ctl (and ct (ignore-errors
1490 (mail-header-parse-content-type ct)))
1493 (mm-read-coding-system "Charset to decode: "))
1495 (mail-content-type-get ctl 'charset)))
1496 format (and ctl (mail-content-type-get ctl 'format)))
1498 (setq cte (mail-header-strip cte)))
1499 (if (and ctl (not (string-match "/" (car ctl))))
1501 (goto-char (point-max)))
1504 (narrow-to-region (point) (point-max))
1505 (when (and (eq mail-parse-charset 'gnus-decoded)
1506 (eq (mm-body-7-or-8) '8bit))
1507 ;; The text code could have been decoded.
1508 (setq charset mail-parse-charset))
1509 (when (and (or (not ctl)
1510 (equal (car ctl) "text/plain"))
1511 (not format)) ;; article with format will decode later.
1513 charset (and cte (intern (downcase
1514 (gnus-strip-whitespace cte))))
1517 (defun article-decode-encoded-words ()
1518 "Remove encoded-word encoding from headers."
1519 (let ((inhibit-point-motion-hooks t)
1520 (mail-parse-charset gnus-newsgroup-charset)
1521 (mail-parse-ignored-charsets
1522 (save-excursion (condition-case nil
1523 (set-buffer gnus-summary-buffer)
1525 gnus-newsgroup-ignored-charsets))
1528 (article-narrow-to-head)
1529 (funcall gnus-decode-header-function (point-min) (point-max)))))
1531 (defun article-de-quoted-unreadable (&optional force)
1532 "Translate a quoted-printable-encoded article.
1533 If FORCE, decode the article whether it is marked as quoted-printable
1535 (interactive (list 'force))
1537 (let ((buffer-read-only nil) type charset)
1538 (if (gnus-buffer-live-p gnus-original-article-buffer)
1539 (with-current-buffer gnus-original-article-buffer
1541 (gnus-fetch-field "content-transfer-encoding"))
1542 (let* ((ct (gnus-fetch-field "content-type"))
1545 (mail-header-parse-content-type ct)))))
1546 (setq charset (and ctl
1547 (mail-content-type-get ctl 'charset)))
1548 (if (stringp charset)
1549 (setq charset (intern (downcase charset)))))))
1551 (setq charset gnus-newsgroup-charset))
1553 (and type (string-match "quoted-printable" (downcase type))))
1555 (quoted-printable-decode-region (point) (point-max) charset)))))
1557 (defun article-de-base64-unreadable (&optional force)
1558 "Translate a base64 article.
1559 If FORCE, decode the article whether it is marked as base64 not."
1560 (interactive (list 'force))
1562 (let ((buffer-read-only nil) type charset)
1563 (if (gnus-buffer-live-p gnus-original-article-buffer)
1564 (with-current-buffer gnus-original-article-buffer
1566 (gnus-fetch-field "content-transfer-encoding"))
1567 (let* ((ct (gnus-fetch-field "content-type"))
1570 (mail-header-parse-content-type ct)))))
1571 (setq charset (and ctl
1572 (mail-content-type-get ctl 'charset)))
1573 (if (stringp charset)
1574 (setq charset (intern (downcase charset)))))))
1576 (setq charset gnus-newsgroup-charset))
1578 (and type (string-match "base64" (downcase type))))
1581 (narrow-to-region (point) (point-max))
1582 (base64-decode-region (point-min) (point-max))
1583 (if (mm-coding-system-p charset)
1584 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1589 (defun article-decode-HZ ()
1590 "Translate a HZ-encoded article."
1594 (let ((buffer-read-only nil))
1595 (rfc1843-decode-region (point-min) (point-max)))))
1597 (defun article-wash-html ()
1598 "Format an html article."
1601 (let ((buffer-read-only nil)
1603 (if (gnus-buffer-live-p gnus-original-article-buffer)
1604 (with-current-buffer gnus-original-article-buffer
1605 (let* ((ct (gnus-fetch-field "content-type"))
1608 (mail-header-parse-content-type ct)))))
1609 (setq charset (and ctl
1610 (mail-content-type-get ctl 'charset)))
1611 (if (stringp charset)
1612 (setq charset (intern (downcase charset)))))))
1614 (setq charset gnus-newsgroup-charset))
1616 (save-window-excursion
1618 (narrow-to-region (point) (point-max))
1620 (let ((w3-strict-width (window-width))
1621 (url-standalone-mode t))
1623 (w3-region (point-min) (point-max))
1626 (defun article-hide-list-identifiers ()
1627 "Remove list identifies from the Subject header.
1628 The `gnus-list-identifiers' variable specifies what to do."
1632 (let ((inhibit-point-motion-hooks t)
1634 (article-narrow-to-head)
1635 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1636 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1638 (goto-char (point-min))
1639 (when (re-search-forward
1640 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1641 " *\\)\\)+\\(Re: +\\)?\\)")
1643 (let ((s (or (match-string 3) (match-string 5))))
1644 (delete-region (match-beginning 1) (match-end 1))
1646 (goto-char (match-beginning 1))
1649 (defun article-hide-pgp ()
1650 "Remove any PGP headers and signatures in the current article."
1654 (let ((inhibit-point-motion-hooks t)
1655 buffer-read-only beg end)
1657 ;; Hide the "header".
1658 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1659 (push 'pgp gnus-article-wash-types)
1660 (delete-region (match-beginning 0) (match-end 0))
1661 ;; Remove armor headers (rfc2440 6.2)
1662 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1665 ;; Hide the actual signature.
1666 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1667 (setq end (1+ (match-beginning 0)))
1670 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1672 ;; Perhaps we shouldn't hide to the end of the buffer
1673 ;; if there is no end to the signature?
1675 ;; Hide "- " PGP quotation markers.
1677 (narrow-to-region beg end)
1678 (goto-char (point-min))
1679 (while (re-search-forward "^- " nil t)
1681 (match-beginning 0) (match-end 0)))
1683 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1685 (defun article-hide-pem (&optional arg)
1686 "Toggle hiding of any PEM headers and signatures in the current article.
1687 If given a negative prefix, always show; if given a positive prefix,
1689 (interactive (gnus-article-hidden-arg))
1690 (unless (gnus-article-check-hidden-text 'pem arg)
1692 (let (buffer-read-only end)
1693 (goto-char (point-min))
1694 ;; Hide the horrendously ugly "header".
1695 (when (and (search-forward
1696 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1698 (setq end (1+ (match-beginning 0))))
1699 (push 'pem gnus-article-wash-types)
1700 (gnus-article-hide-text-type
1702 (if (search-forward "\n\n" nil t)
1706 ;; Hide the trailer as well
1707 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1709 (gnus-article-hide-text-type
1710 (match-beginning 0) (match-end 0) 'pem)))))))
1712 (defun article-strip-banner ()
1713 "Strip the banner specified by the `banner' group parameter."
1717 (let ((inhibit-point-motion-hooks t)
1718 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1719 (gnus-signature-limit nil)
1720 buffer-read-only beg end)
1724 ((eq banner 'signature)
1725 (when (gnus-article-narrow-to-signature)
1728 (delete-region (point) (point-max))))
1730 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1731 (while (re-search-forward banner nil t)
1732 (delete-region (match-beginning 0) (match-end 0)))))
1734 (while (re-search-forward banner nil t)
1735 (delete-region (match-beginning 0) (match-end 0))))))))))
1737 (defun article-babel ()
1738 "Translate article using an online translation service."
1742 (set-buffer gnus-article-buffer)
1743 (when (article-goto-body)
1744 (let* ((buffer-read-only nil)
1747 (orig (buffer-substring start end))
1748 (trans (babel-as-string orig)))
1750 (narrow-to-region start end)
1751 (delete-region start end)
1754 (defun article-hide-signature (&optional arg)
1755 "Hide the signature in the current article.
1756 If given a negative prefix, always show; if given a positive prefix,
1758 (interactive (gnus-article-hidden-arg))
1759 (unless (gnus-article-check-hidden-text 'signature arg)
1762 (let ((buffer-read-only nil))
1763 (when (gnus-article-narrow-to-signature)
1764 (gnus-article-hide-text-type
1765 (point-min) (point-max) 'signature)))))))
1767 (defun article-strip-headers-in-body ()
1768 "Strip offensive headers from bodies."
1772 (let ((case-fold-search t))
1773 (when (looking-at "x-no-archive:")
1774 (gnus-delete-line)))))
1776 (defun article-strip-leading-blank-lines ()
1777 "Remove all blank lines from the beginning of the article."
1780 (let ((inhibit-point-motion-hooks t)
1782 (when (article-goto-body)
1783 (while (and (not (eobp))
1784 (looking-at "[ \t]*$"))
1785 (gnus-delete-line))))))
1787 (defun article-narrow-to-head ()
1788 "Narrow the buffer to the head of the message.
1789 Point is left at the beginning of the narrowed-to region."
1791 (goto-char (point-min))
1792 (if (search-forward "\n\n" nil 1)
1795 (goto-char (point-min)))
1797 (defun article-goto-body ()
1798 "Place point at the start of the body."
1799 (goto-char (point-min))
1801 ;; This variable is only bound when dealing with separate
1803 (article-goto-body-goes-to-point-min-p
1805 ((search-forward "\n\n" nil t)
1808 (goto-char (point-max))
1811 (defun article-strip-multiple-blank-lines ()
1812 "Replace consecutive blank lines with one empty line."
1815 (let ((inhibit-point-motion-hooks t)
1817 ;; First make all blank lines empty.
1819 (while (re-search-forward "^[ \t]+$" nil t)
1820 (unless (gnus-annotation-in-region-p
1821 (match-beginning 0) (match-end 0))
1822 (replace-match "" nil t)))
1823 ;; Then replace multiple empty lines with a single empty line.
1825 (while (re-search-forward "\n\n\n+" nil t)
1826 (unless (gnus-annotation-in-region-p
1827 (match-beginning 0) (match-end 0))
1828 (replace-match "\n\n" t t))))))
1830 (defun article-strip-leading-space ()
1831 "Remove all white space from the beginning of the lines in the article."
1834 (let ((inhibit-point-motion-hooks t)
1837 (while (re-search-forward "^[ \t]+" nil t)
1838 (replace-match "" t t)))))
1840 (defun article-strip-trailing-space ()
1841 "Remove all white space from the end of the lines in the article."
1844 (let ((inhibit-point-motion-hooks t)
1847 (while (re-search-forward "[ \t]+$" nil t)
1848 (replace-match "" t t)))))
1850 (defun article-strip-blank-lines ()
1851 "Strip leading, trailing and multiple blank lines."
1853 (article-strip-leading-blank-lines)
1854 (article-remove-trailing-blank-lines)
1855 (article-strip-multiple-blank-lines))
1857 (defun article-strip-all-blank-lines ()
1858 "Strip all blank lines."
1861 (let ((inhibit-point-motion-hooks t)
1864 (while (re-search-forward "^[ \t]*\n" nil t)
1865 (replace-match "" t t)))))
1867 (defun gnus-article-narrow-to-signature ()
1868 "Narrow to the signature; return t if a signature is found, else nil."
1869 (let ((inhibit-point-motion-hooks t))
1870 (when (gnus-article-search-signature)
1872 ;; Check whether we have some limits to what we consider
1873 ;; to be a signature.
1874 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1875 (list gnus-signature-limit)))
1877 (while (setq limit (pop limits))
1878 (if (or (and (integerp limit)
1879 (< (- (point-max) (point)) limit))
1881 (< (count-lines (point) (point-max)) limit))
1882 (and (gnus-functionp limit)
1884 (and (stringp limit)
1885 (not (re-search-forward limit nil t))))
1886 () ; This limit did not succeed.
1890 (narrow-to-region (point) (point-max))
1893 (defun gnus-article-search-signature ()
1894 "Search the current buffer for the signature separator.
1895 Put point at the beginning of the signature separator."
1896 (let ((cur (point)))
1897 (goto-char (point-max))
1898 (if (if (stringp gnus-signature-separator)
1899 (re-search-backward gnus-signature-separator nil t)
1900 (let ((seps gnus-signature-separator))
1902 (not (re-search-backward (car seps) nil t)))
1909 (defun gnus-article-hidden-arg ()
1910 "Return the current prefix arg as a number, or 0 if no prefix."
1911 (list (if current-prefix-arg
1912 (prefix-numeric-value current-prefix-arg)
1915 (defun gnus-article-check-hidden-text (type arg)
1916 "Return nil if hiding is necessary.
1917 Arg can be nil or a number. Nil and positive means hide, negative
1918 means show, 0 means toggle."
1921 (let ((hide (gnus-article-hidden-text-p type)))
1927 (gnus-article-show-hidden-text type))
1929 (if (eq hide 'hidden)
1930 (gnus-article-show-hidden-text type)
1933 (defun gnus-article-hidden-text-p (type)
1934 "Say whether the current buffer contains hidden text of type TYPE."
1935 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1937 (not (get-text-property pos 'invisible))
1938 (not (get-text-property pos 'dummy-invisible)))
1940 (text-property-any (1+ pos) (point-max) 'article-type type)))
1945 (defun gnus-article-show-hidden-text (type &optional hide)
1946 "Show all hidden text of type TYPE.
1947 If HIDE, hide the text instead."
1949 (let ((buffer-read-only nil)
1950 (inhibit-point-motion-hooks t)
1953 (while (setq beg (text-property-any end (point-max) 'article-type type))
1956 (text-property-not-all beg (point-max) 'article-type type)
1959 (gnus-article-hide-text beg end gnus-hidden-properties)
1960 (gnus-article-unhide-text beg end))
1964 (defconst article-time-units
1965 `((year . ,(* 365.25 24 60 60))
1966 (week . ,(* 7 24 60 60))
1967 (day . ,(* 24 60 60))
1971 "Mapping from time units to seconds.")
1973 (defun article-date-ut (&optional type highlight header)
1974 "Convert DATE date to universal time in the current article.
1975 If TYPE is `local', convert to local time; if it is `lapsed', output
1976 how much time has lapsed since DATE. For `lapsed', the value of
1977 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1978 should replace the \"Date:\" one, or should be added below it."
1979 (interactive (list 'ut t))
1980 (let* ((header (or header
1981 (message-fetch-field "date")
1983 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1986 ((not gnus-article-date-lapsed-new-header)
1992 (date (if (vectorp header) (mail-header-date header)
1994 (inhibit-point-motion-hooks t)
1999 (article-narrow-to-head)
2000 (when (re-search-forward tdate-regexp nil t)
2001 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2002 date (or (get-text-property (gnus-point-at-bol)
2005 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2007 (when (and date (not (string= date "")))
2008 (goto-char (point-min))
2009 (let ((buffer-read-only nil))
2010 ;; Delete any old Date headers.
2011 (while (re-search-forward date-regexp nil t)
2013 (delete-region (progn (beginning-of-line) (point))
2014 (progn (forward-line 1) (point)))
2015 (delete-region (progn (beginning-of-line) (point))
2016 (progn (end-of-line) (point)))
2017 (setq pos (point))))
2018 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2020 (if pos (goto-char pos))
2021 (insert (article-make-date-line date (or type 'ut)))
2027 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2028 (put-text-property (match-beginning 1) (1+ (match-end 1))
2029 'original-date date)
2030 (put-text-property (match-beginning 1) (1+ (match-end 1))
2032 (put-text-property (match-beginning 2) (match-end 2)
2035 (defun article-make-date-line (date type)
2036 "Return a DATE line of TYPE."
2037 (let ((time (condition-case ()
2041 ;; Convert to the local timezone. We have to slap a
2042 ;; `condition-case' round the calls to the timezone
2043 ;; functions since they aren't particularly resistant to
2046 (let ((tz (car (current-time-zone time))))
2047 (format "Date: %s %s%02d%02d" (current-time-string time)
2048 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2049 (/ (% (abs tz) 3600) 60))))
2050 ;; Convert to Universal Time.
2053 (current-time-string
2054 (let* ((e (parse-time-string date))
2055 (tm (apply 'encode-time e))
2057 (ls (- (cadr tm) (car (current-time-zone time)))))
2058 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2059 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2062 ;; Get the original date from the article.
2063 ((eq type 'original)
2064 (concat "Date: " (if (string-match "\n+$" date)
2065 (substring date 0 (match-beginning 0))
2067 ;; Let the user define the format.
2069 (if (gnus-functionp gnus-article-time-format)
2070 (funcall gnus-article-time-format time)
2073 (format-time-string gnus-article-time-format time))))
2076 (let ((tz (car (current-time-zone time))))
2079 (format-time-string "%Y%m%dT%H%M%S" time)
2080 (format "%s%02d%02d"
2081 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2082 (/ (% (abs tz) 3600) 60)))))
2083 ;; Do an X-Sent lapsed format.
2085 ;; If the date is seriously mangled, the timezone functions are
2086 ;; liable to bug out, so we ignore all errors.
2087 (let* ((now (current-time))
2088 (real-time (subtract-time now time))
2089 (real-sec (and real-time
2090 (+ (* (float (car real-time)) 65536)
2092 (sec (and real-time (abs real-sec)))
2102 ;; This is a bit convoluted, but basically we go
2103 ;; through the time units for years, weeks, etc,
2104 ;; and divide things to see whether that results
2105 ;; in positive answers.
2108 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2109 ;; The (remaining) seconds are too few to
2110 ;; be divided into this time unit.
2112 ;; It's big enough, so we output it.
2113 (setq sec (- sec (* num (cdr unit))))
2115 (concat (if prev ", " "") (int-to-string
2117 " " (symbol-name (car unit))
2118 (if (> num 1) "s" ""))
2120 article-time-units "")
2121 ;; If dates are odd, then it might appear like the
2122 ;; article was sent in the future.
2125 " in the future"))))))
2127 (error "Unknown conversion type: %s" type)))))
2129 (defun article-date-local (&optional highlight)
2130 "Convert the current article date to the local timezone."
2131 (interactive (list t))
2132 (article-date-ut 'local highlight))
2134 (defun article-date-original (&optional highlight)
2135 "Convert the current article date to what it was originally.
2136 This is only useful if you have used some other date conversion
2137 function and want to see what the date was before converting."
2138 (interactive (list t))
2139 (article-date-ut 'original highlight))
2141 (defun article-date-lapsed (&optional highlight)
2142 "Convert the current article date to time lapsed since it was sent."
2143 (interactive (list t))
2144 (article-date-ut 'lapsed highlight))
2146 (defun article-update-date-lapsed ()
2147 "Function to be run from a timer to update the lapsed time line."
2148 (let (deactivate-mark)
2153 (set-buffer (window-buffer w))
2154 (when (eq major-mode 'gnus-article-mode)
2155 (goto-char (point-min))
2156 (when (re-search-forward "^X-Sent:" nil t)
2157 (article-date-lapsed t))))
2160 (defun gnus-start-date-timer (&optional n)
2161 "Start a timer to update the X-Sent header in the article buffers.
2162 The numerical prefix says how frequently (in seconds) the function
2167 (gnus-stop-date-timer)
2168 (setq article-lapsed-timer
2169 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2171 (defun gnus-stop-date-timer ()
2172 "Stop the X-Sent timer."
2174 (when article-lapsed-timer
2175 (nnheader-cancel-timer article-lapsed-timer)
2176 (setq article-lapsed-timer nil)))
2178 (defun article-date-user (&optional highlight)
2179 "Convert the current article date to the user-defined format.
2180 This format is defined by the `gnus-article-time-format' variable."
2181 (interactive (list t))
2182 (article-date-ut 'user highlight))
2184 (defun article-date-iso8601 (&optional highlight)
2185 "Convert the current article date to ISO8601."
2186 (interactive (list t))
2187 (article-date-ut 'iso8601 highlight))
2189 (defun article-show-all ()
2190 "Show all hidden text in the article buffer."
2193 (let ((buffer-read-only nil))
2194 (gnus-article-unhide-text (point-min) (point-max)))))
2196 (defun article-emphasize (&optional arg)
2197 "Emphasize text according to `gnus-emphasis-alist'."
2198 (interactive (gnus-article-hidden-arg))
2199 (unless (gnus-article-check-hidden-text 'emphasis arg)
2203 (with-current-buffer gnus-summary-buffer
2204 gnus-article-emphasis-alist)
2206 gnus-emphasis-alist))
2207 (buffer-read-only nil)
2208 (props (append '(article-type emphasis)
2209 gnus-hidden-properties))
2210 regexp elem beg invisible visible face)
2213 (while (setq elem (pop alist))
2215 (setq regexp (car elem)
2216 invisible (nth 1 elem)
2217 visible (nth 2 elem)
2219 (while (re-search-forward regexp nil t)
2220 (when (and (match-beginning visible) (match-beginning invisible))
2221 (push 'emphasis gnus-article-wash-types)
2222 (gnus-article-hide-text
2223 (match-beginning invisible) (match-end invisible) props)
2224 (gnus-article-unhide-text-type
2225 (match-beginning visible) (match-end visible) 'emphasis)
2226 (gnus-put-text-property-excluding-newlines
2227 (match-beginning visible) (match-end visible) 'face face)
2228 (goto-char (match-end invisible)))))))))
2230 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2231 "Setup newsgroup emphasis alist."
2232 (unless gnus-article-emphasis-alist
2233 (let ((name (and gnus-newsgroup-name
2234 (gnus-group-real-name gnus-newsgroup-name))))
2235 (make-local-variable 'gnus-article-emphasis-alist)
2236 (setq gnus-article-emphasis-alist
2238 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2239 (while (setq elem (pop alist))
2240 (when (and name (string-match (car elem) name))
2242 highlight (copy-sequence (cdr elem)))))
2244 (copy-sequence highlight-words)
2245 (if gnus-newsgroup-name
2246 (copy-sequence (gnus-group-find-parameter
2247 gnus-newsgroup-name 'highlight-words t)))
2248 gnus-emphasis-alist)))))
2250 (defvar gnus-summary-article-menu)
2251 (defvar gnus-summary-post-menu)
2253 ;;; Saving functions.
2255 (defun gnus-article-save (save-buffer file &optional num)
2256 "Save the currently selected article."
2257 (unless gnus-save-all-headers
2258 ;; Remove headers according to `gnus-saved-headers'.
2259 (let ((gnus-visible-headers
2260 (or gnus-saved-headers gnus-visible-headers))
2261 (gnus-article-buffer save-buffer))
2263 (set-buffer save-buffer)
2264 (article-hide-headers 1 t))))
2265 (save-window-excursion
2266 (if (not gnus-default-article-saver)
2267 (error "No default saver is defined")
2268 ;; !!! Magic! The saving functions all save
2269 ;; `gnus-save-article-buffer' (or so they think), but we
2270 ;; bind that variable to our save-buffer.
2271 (set-buffer gnus-article-buffer)
2272 (let* ((gnus-save-article-buffer save-buffer)
2275 ((not gnus-prompt-before-saving) 'default)
2276 ((eq gnus-prompt-before-saving 'always) nil)
2278 (gnus-number-of-articles-to-be-saved
2279 (when (eq gnus-prompt-before-saving t)
2281 (set-buffer gnus-article-current-summary)
2282 (funcall gnus-default-article-saver filename)))))
2284 (defun gnus-read-save-file-name (prompt &optional filename
2285 function group headers variable)
2287 (funcall function group headers (symbol-value variable)))
2292 ((eq filename 'default)
2298 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2301 (if (and gnus-number-of-articles-to-be-saved
2302 (> gnus-number-of-articles-to-be-saved 1))
2303 (format "these %d articles"
2304 gnus-number-of-articles-to-be-saved)
2307 ;; Let the split methods have their say.
2309 ;; No split name was found.
2312 (concat prompt " (default "
2313 (file-name-nondirectory default-name) ") ")
2314 (file-name-directory default-name)
2316 ;; A single group name is returned.
2317 ((stringp split-name)
2319 (funcall function split-name headers
2320 (symbol-value variable)))
2322 (concat prompt " (default "
2323 (file-name-nondirectory default-name) ") ")
2324 (file-name-directory default-name)
2326 ;; A single split name was found
2327 ((= 1 (length split-name))
2328 (let* ((name (expand-file-name
2329 (car split-name) gnus-article-save-directory))
2330 (dir (cond ((file-directory-p name)
2331 (file-name-as-directory name))
2332 ((file-exists-p name) name)
2333 (t gnus-article-save-directory))))
2335 (concat prompt " (default " name ") ")
2337 ;; A list of splits was found.
2339 (setq split-name (nreverse split-name))
2341 (let ((file-name-history
2342 (nconc split-name file-name-history)))
2346 (concat prompt " (`M-p' for defaults) ")
2347 gnus-article-save-directory
2349 gnus-article-save-directory)))
2350 (car (push result file-name-history)))))))
2351 ;; Create the directory.
2352 (gnus-make-directory (file-name-directory file))
2353 ;; If we have read a directory, we append the default file name.
2354 (when (file-directory-p file)
2355 (setq file (expand-file-name (file-name-nondirectory default-name)
2356 (file-name-as-directory file))))
2357 ;; Possibly translate some characters.
2358 (nnheader-translate-file-chars file))))))
2359 (gnus-make-directory (file-name-directory result))
2360 (set variable result)))
2362 (defun gnus-article-archive-name (group)
2363 "Return the first instance of an \"Archive-name\" in the current buffer."
2364 (let ((case-fold-search t))
2365 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2366 (nnheader-concat gnus-article-save-directory
2367 (match-string 1)))))
2369 (defun gnus-article-nndoc-name (group)
2370 "If GROUP is an nndoc group, return the name of the parent group."
2371 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2372 (gnus-group-get-parameter group 'save-article-group)))
2374 (defun gnus-summary-save-in-rmail (&optional filename)
2375 "Append this article to Rmail file.
2376 Optional argument FILENAME specifies file name.
2377 Directory to save to is default to `gnus-article-save-directory'."
2378 (setq filename (gnus-read-save-file-name
2379 "Save %s in rmail file:" filename
2380 gnus-rmail-save-name gnus-newsgroup-name
2381 gnus-current-headers 'gnus-newsgroup-last-rmail))
2382 (gnus-eval-in-buffer-window gnus-save-article-buffer
2386 (gnus-output-to-rmail filename))))
2389 (defun gnus-summary-save-in-mail (&optional filename)
2390 "Append this article to Unix mail file.
2391 Optional argument FILENAME specifies file name.
2392 Directory to save to is default to `gnus-article-save-directory'."
2393 (setq filename (gnus-read-save-file-name
2394 "Save %s in Unix mail file:" filename
2395 gnus-mail-save-name gnus-newsgroup-name
2396 gnus-current-headers 'gnus-newsgroup-last-mail))
2397 (gnus-eval-in-buffer-window gnus-save-article-buffer
2401 (if (and (file-readable-p filename)
2402 (mail-file-babyl-p filename))
2403 (rmail-output-to-rmail-file filename t)
2404 (gnus-output-to-mail filename)))))
2407 (defun gnus-summary-save-in-file (&optional filename overwrite)
2408 "Append this article to file.
2409 Optional argument FILENAME specifies file name.
2410 Directory to save to is default to `gnus-article-save-directory'."
2411 (setq filename (gnus-read-save-file-name
2412 "Save %s in file:" filename
2413 gnus-file-save-name gnus-newsgroup-name
2414 gnus-current-headers 'gnus-newsgroup-last-file))
2415 (gnus-eval-in-buffer-window gnus-save-article-buffer
2419 (when (and overwrite
2420 (file-exists-p filename))
2421 (delete-file filename))
2422 (gnus-output-to-file filename))))
2425 (defun gnus-summary-write-to-file (&optional filename)
2426 "Write this article to a file.
2427 Optional argument FILENAME specifies file name.
2428 The directory to save in defaults to `gnus-article-save-directory'."
2429 (gnus-summary-save-in-file nil t))
2431 (defun gnus-summary-save-body-in-file (&optional filename)
2432 "Append this article body to a file.
2433 Optional argument FILENAME specifies file name.
2434 The directory to save in defaults to `gnus-article-save-directory'."
2435 (setq filename (gnus-read-save-file-name
2436 "Save %s body in file:" filename
2437 gnus-file-save-name gnus-newsgroup-name
2438 gnus-current-headers 'gnus-newsgroup-last-file))
2439 (gnus-eval-in-buffer-window gnus-save-article-buffer
2443 (when (article-goto-body)
2444 (narrow-to-region (point) (point-max)))
2445 (gnus-output-to-file filename))))
2448 (defun gnus-summary-save-in-pipe (&optional command)
2449 "Pipe this article to subprocess."
2451 (cond ((and (eq command 'default)
2452 gnus-last-shell-command)
2453 gnus-last-shell-command)
2457 "Shell command on %s: "
2458 (if (and gnus-number-of-articles-to-be-saved
2459 (> gnus-number-of-articles-to-be-saved 1))
2460 (format "these %d articles"
2461 gnus-number-of-articles-to-be-saved)
2463 gnus-last-shell-command))))
2464 (when (string-equal command "")
2465 (setq command gnus-last-shell-command))
2466 (gnus-eval-in-buffer-window gnus-article-buffer
2469 (shell-command-on-region (point-min) (point-max) command nil)))
2470 (setq gnus-last-shell-command command))
2472 ;;; Article file names when saving.
2474 (defun gnus-capitalize-newsgroup (newsgroup)
2475 "Capitalize NEWSGROUP name."
2476 (when (not (zerop (length newsgroup)))
2477 (concat (char-to-string (upcase (aref newsgroup 0)))
2478 (substring newsgroup 1))))
2480 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2481 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2482 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2483 Otherwise, it is like ~/News/news/group/num."
2486 (concat (if (gnus-use-long-file-name 'not-save)
2487 (gnus-capitalize-newsgroup newsgroup)
2488 (gnus-newsgroup-directory-form newsgroup))
2489 "/" (int-to-string (mail-header-number headers)))
2490 gnus-article-save-directory)))
2492 (string-equal (file-name-directory default)
2493 (file-name-directory last-file))
2494 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2496 (or last-file default))))
2498 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2499 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2500 If variable `gnus-use-long-file-name' is non-nil, it is
2501 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2504 (concat (if (gnus-use-long-file-name 'not-save)
2506 (gnus-newsgroup-directory-form newsgroup))
2507 "/" (int-to-string (mail-header-number headers)))
2508 gnus-article-save-directory)))
2510 (string-equal (file-name-directory default)
2511 (file-name-directory last-file))
2512 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2514 (or last-file default))))
2516 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2517 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2518 If variable `gnus-use-long-file-name' is non-nil, it is
2519 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2522 (if (gnus-use-long-file-name 'not-save)
2524 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2525 gnus-article-save-directory)))
2532 (setq afunc (car func)
2535 gfunc (intern (format "gnus-%s" func))))
2538 `(lambda (&optional interactive &rest args)
2539 ,(documentation afunc t)
2540 (interactive (list t))
2542 (set-buffer gnus-article-buffer)
2544 (call-interactively ',afunc)
2545 (apply ',afunc args))))))))
2546 '(article-hide-headers
2547 article-hide-boring-headers
2548 article-treat-overstrike
2549 article-fill-long-lines
2550 article-capitalize-sentences
2552 article-display-x-face
2553 article-de-quoted-unreadable
2554 article-de-base64-unreadable
2557 article-hide-list-identifiers
2559 article-strip-banner
2562 article-hide-signature
2563 article-strip-headers-in-body
2564 article-remove-trailing-blank-lines
2565 article-strip-leading-blank-lines
2566 article-strip-multiple-blank-lines
2567 article-strip-leading-space
2568 article-strip-trailing-space
2569 article-strip-blank-lines
2570 article-strip-all-blank-lines
2572 article-date-iso8601
2573 article-date-original
2575 article-decode-mime-words
2576 article-decode-charset
2577 article-decode-encoded-words
2581 article-treat-dumbquotes
2582 article-normalize-headers
2583 (article-show-all . gnus-article-show-all-headers))))
2586 ;;; Gnus article mode
2589 (put 'gnus-article-mode 'mode-class 'special)
2591 (set-keymap-parent gnus-article-mode-map widget-keymap)
2593 (gnus-define-keys gnus-article-mode-map
2594 " " gnus-article-goto-next-page
2595 "\177" gnus-article-goto-prev-page
2596 [delete] gnus-article-goto-prev-page
2597 [backspace] gnus-article-goto-prev-page
2598 "\C-c^" gnus-article-refer-article
2599 "h" gnus-article-show-summary
2600 "s" gnus-article-show-summary
2601 "\C-c\C-m" gnus-article-mail
2602 "?" gnus-article-describe-briefly
2603 "e" gnus-summary-edit-article
2604 "<" beginning-of-buffer
2606 "\C-c\C-i" gnus-info-find-node
2609 "\C-d" gnus-article-read-summary-keys
2610 "\M-*" gnus-article-read-summary-keys
2611 "\M-#" gnus-article-read-summary-keys
2612 "\M-^" gnus-article-read-summary-keys
2613 "\M-g" gnus-article-read-summary-keys)
2615 (substitute-key-definition
2616 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2618 (defun gnus-article-make-menu-bar ()
2619 (gnus-turn-off-edit-menu 'article)
2620 (unless (boundp 'gnus-article-article-menu)
2622 gnus-article-article-menu gnus-article-mode-map ""
2624 ["Scroll forwards" gnus-article-goto-next-page t]
2625 ["Scroll backwards" gnus-article-goto-prev-page t]
2626 ["Show summary" gnus-article-show-summary t]
2627 ["Fetch Message-ID at point" gnus-article-refer-article t]
2628 ["Mail to address at point" gnus-article-mail t]
2629 ["Send a bug report" gnus-bug t]))
2632 gnus-article-treatment-menu gnus-article-mode-map ""
2634 ["Hide headers" gnus-article-hide-headers t]
2635 ["Hide signature" gnus-article-hide-signature t]
2636 ["Hide citation" gnus-article-hide-citation t]
2637 ["Treat overstrike" gnus-article-treat-overstrike t]
2638 ["Remove carriage return" gnus-article-remove-cr t]
2639 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2640 ["Remove base64" gnus-article-de-base64-unreadable t]
2641 ["Treat html" gnus-article-wash-html t]
2642 ["Decode HZ" gnus-article-decode-HZ t]))
2644 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2646 (when (boundp 'gnus-summary-post-menu)
2647 (define-key gnus-article-mode-map [menu-bar post]
2648 (cons "Post" gnus-summary-post-menu)))
2650 (gnus-run-hooks 'gnus-article-menu-hook)))
2652 (defun gnus-article-mode ()
2653 "Major mode for displaying an article.
2655 All normal editing commands are switched off.
2657 The following commands are available in addition to all summary mode
2659 \\<gnus-article-mode-map>
2660 \\[gnus-article-next-page]\t Scroll the article one page forwards
2661 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2662 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2663 \\[gnus-article-show-summary]\t Display the summary buffer
2664 \\[gnus-article-mail]\t Send a reply to the address near point
2665 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2666 \\[gnus-info-find-node]\t Go to the Gnus info node"
2668 (when (gnus-visual-p 'article-menu 'menu)
2669 (gnus-article-make-menu-bar))
2670 (gnus-simplify-mode-line)
2671 (setq mode-name "Article")
2672 (setq major-mode 'gnus-article-mode)
2673 (make-local-variable 'minor-mode-alist)
2674 (use-local-map gnus-article-mode-map)
2675 (gnus-update-format-specifications nil 'article-mode)
2676 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2677 (make-local-variable 'gnus-page-broken)
2678 (make-local-variable 'gnus-button-marker-list)
2679 (make-local-variable 'gnus-article-current-summary)
2680 (make-local-variable 'gnus-article-mime-handles)
2681 (make-local-variable 'gnus-article-decoded-p)
2682 (make-local-variable 'gnus-article-mime-handle-alist)
2683 (make-local-variable 'gnus-article-wash-types)
2684 (gnus-set-default-directory)
2685 (buffer-disable-undo)
2686 (setq buffer-read-only t)
2687 (set-syntax-table gnus-article-mode-syntax-table)
2688 (mm-enable-multibyte)
2689 (gnus-run-hooks 'gnus-article-mode-hook))
2691 (defun gnus-article-setup-buffer ()
2692 "Initialize the article buffer."
2693 (let* ((name (if gnus-single-article-buffer "*Article*"
2694 (concat "*Article " gnus-newsgroup-name "*")))
2696 (progn (string-match "\\*Article" name)
2697 (concat " *Original Article"
2698 (substring name (match-end 0))))))
2699 (setq gnus-article-buffer name)
2700 (setq gnus-original-article-buffer original)
2701 (setq gnus-article-mime-handle-alist nil)
2702 ;; This might be a variable local to the summary buffer.
2703 (unless gnus-single-article-buffer
2705 (set-buffer gnus-summary-buffer)
2706 (setq gnus-article-buffer name)
2707 (setq gnus-original-article-buffer original)
2708 (gnus-set-global-variables)))
2709 (gnus-article-setup-highlight-words)
2710 ;; Init original article buffer.
2712 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2713 (mm-enable-multibyte)
2714 (setq major-mode 'gnus-original-article-mode)
2715 (make-local-variable 'gnus-original-article))
2716 (if (get-buffer name)
2719 (when gnus-article-mime-handles
2720 (mm-destroy-parts gnus-article-mime-handles)
2721 (setq gnus-article-mime-handles nil))
2722 ;; Set it to nil in article-buffer!
2723 (setq gnus-article-mime-handle-alist nil)
2724 (buffer-disable-undo)
2725 (setq buffer-read-only t)
2726 (unless (eq major-mode 'gnus-article-mode)
2727 (gnus-article-mode))
2730 (set-buffer (gnus-get-buffer-create name))
2732 (make-local-variable 'gnus-summary-buffer)
2733 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2734 (current-buffer)))))
2736 ;; Set article window start at LINE, where LINE is the number of lines
2737 ;; from the head of the article.
2738 (defun gnus-article-set-window-start (&optional line)
2740 (get-buffer-window gnus-article-buffer t)
2742 (set-buffer gnus-article-buffer)
2743 (goto-char (point-min))
2746 (gnus-message 6 "Moved to bookmark")
2747 (search-forward "\n\n" nil t)
2751 (defun gnus-article-prepare (article &optional all-headers header)
2752 "Prepare ARTICLE in article mode buffer.
2753 ARTICLE should either be an article number or a Message-ID.
2754 If ARTICLE is an id, HEADER should be the article headers.
2755 If ALL-HEADERS is non-nil, no headers are hidden."
2757 ;; Make sure we start in a summary buffer.
2758 (unless (eq major-mode 'gnus-summary-mode)
2759 (set-buffer gnus-summary-buffer))
2760 (setq gnus-summary-buffer (current-buffer))
2761 (let* ((gnus-article (if header (mail-header-number header) article))
2762 (summary-buffer (current-buffer))
2763 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2764 (group gnus-newsgroup-name)
2767 (gnus-article-setup-buffer)
2768 (set-buffer gnus-article-buffer)
2769 ;; Deactivate active regions.
2770 (when (and (boundp 'transient-mark-mode)
2771 transient-mark-mode)
2772 (setq mark-active nil))
2773 (if (not (setq result (let ((buffer-read-only nil))
2774 (gnus-request-article-this-buffer
2776 ;; There is no such article.
2778 (when (and (numberp article)
2779 (not (memq article gnus-newsgroup-sparse)))
2780 (setq gnus-article-current
2781 (cons gnus-newsgroup-name article))
2782 (set-buffer gnus-summary-buffer)
2783 (setq gnus-current-article article)
2784 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2786 (gnus-summary-set-agent-mark article)
2787 (message "Message marked for downloading"))
2788 (gnus-summary-mark-article article gnus-canceled-mark)
2789 (unless (memq article gnus-newsgroup-sparse)
2790 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2791 (if (or (eq result 'pseudo)
2792 (eq result 'nneething))
2795 (set-buffer summary-buffer)
2796 (push article gnus-newsgroup-history)
2797 (setq gnus-last-article gnus-current-article
2798 gnus-current-article 0
2799 gnus-current-headers nil
2800 gnus-article-current nil)
2801 (if (eq result 'nneething)
2802 (gnus-configure-windows 'summary)
2803 (gnus-configure-windows 'article))
2804 (gnus-set-global-variables))
2805 (let ((gnus-article-mime-handle-alist-1
2806 gnus-article-mime-handle-alist))
2807 (gnus-set-mode-line 'article)))
2808 ;; The result from the `request' was an actual article -
2809 ;; or at least some text that is now displayed in the
2811 (when (and (numberp article)
2812 (not (eq article gnus-current-article)))
2813 ;; Seems like a new article has been selected.
2814 ;; `gnus-current-article' must be an article number.
2816 (set-buffer summary-buffer)
2817 (push article gnus-newsgroup-history)
2818 (setq gnus-last-article gnus-current-article
2819 gnus-current-article article
2820 gnus-current-headers
2821 (gnus-summary-article-header gnus-current-article)
2822 gnus-article-current
2823 (cons gnus-newsgroup-name gnus-current-article))
2824 (unless (vectorp gnus-current-headers)
2825 (setq gnus-current-headers nil))
2826 (gnus-summary-goto-subject gnus-current-article)
2827 (when (gnus-summary-show-thread)
2828 ;; If the summary buffer really was folded, the
2829 ;; previous goto may not actually have gone to
2830 ;; the right article, but the thread root instead.
2832 (gnus-summary-goto-subject gnus-current-article))
2833 (gnus-run-hooks 'gnus-mark-article-hook)
2834 (gnus-set-mode-line 'summary)
2835 (when (gnus-visual-p 'article-highlight 'highlight)
2836 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2837 ;; Set the global newsgroup variables here.
2838 (gnus-set-global-variables)
2839 (setq gnus-have-all-headers
2840 (or all-headers gnus-show-all-headers))))
2841 (when (or (numberp article)
2843 (gnus-article-prepare-display)
2845 (goto-char (point-min))
2846 (setq gnus-page-broken
2847 (when gnus-break-pages
2848 (gnus-narrow-to-page)
2850 (let ((gnus-article-mime-handle-alist-1
2851 gnus-article-mime-handle-alist))
2852 (gnus-set-mode-line 'article))
2854 (set-window-point (get-buffer-window (current-buffer)) (point))
2855 (gnus-configure-windows 'article)
2859 (defun gnus-article-prepare-display ()
2860 "Make the current buffer look like a nice article."
2861 ;; Hooks for getting information from the article.
2862 ;; This hook must be called before being narrowed.
2863 (let ((gnus-article-buffer (current-buffer))
2865 (unless (eq major-mode 'gnus-article-mode)
2866 (gnus-article-mode))
2867 (setq buffer-read-only nil
2868 gnus-article-wash-types nil)
2869 (gnus-run-hooks 'gnus-tmp-internal-hook)
2870 (when gnus-display-mime-function
2871 (funcall gnus-display-mime-function))
2872 (gnus-run-hooks 'gnus-article-prepare-hook)))
2875 ;;; Gnus MIME viewing functions
2878 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2879 "The following specs can be used:
2881 %T MIME type, along with additional info
2882 %n The `name' parameter
2883 %d The description, if any
2884 %l The length of the encoded part
2885 %p The part identifier number
2886 %e Dots if the part isn't displayed")
2888 (defvar gnus-mime-button-line-format-alist
2889 '((?t gnus-tmp-type ?s)
2890 (?T gnus-tmp-type-long ?s)
2891 (?n gnus-tmp-name ?s)
2892 (?d gnus-tmp-description ?s)
2894 (?l gnus-tmp-length ?d)
2895 (?e gnus-tmp-dots ?s)))
2897 (defvar gnus-mime-button-commands
2898 '((gnus-article-press-button "\r" "Toggle Display")
2899 (gnus-mime-view-part "v" "View Interactively...")
2900 (gnus-mime-view-part-as-type "t" "View As Type...")
2901 (gnus-mime-save-part "o" "Save...")
2902 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2903 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2904 (gnus-mime-internalize-part "E" "View Internally")
2905 (gnus-mime-externalize-part "e" "View Externally")
2906 (gnus-mime-pipe-part "|" "Pipe To Command...")
2907 (gnus-mime-action-on-part "." "Take action on the part")))
2909 (defun gnus-article-mime-part-status ()
2910 (if gnus-article-mime-handle-alist-1
2911 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2914 (defvar gnus-mime-button-map
2915 (let ((map (make-sparse-keymap)))
2916 (set-keymap-parent map gnus-article-mode-map)
2917 (define-key map gnus-mouse-2 'gnus-article-push-button)
2918 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2919 (dolist (c gnus-mime-button-commands)
2920 (define-key map (cadr c) (car c)))
2923 (defun gnus-mime-button-menu (event)
2924 "Construct a context-sensitive menu of MIME commands."
2927 (let ((pos (event-start event)))
2928 (set-buffer (window-buffer (posn-window pos)))
2929 (goto-char (posn-point pos))
2930 (gnus-article-check-buffer)
2931 (let ((response (x-popup-menu
2933 ("" ,@(mapcar (lambda (c)
2934 (cons (caddr c) (car c)))
2935 gnus-mime-button-commands))))))
2937 (call-interactively response))))))
2939 (defun gnus-mime-view-all-parts (&optional handles)
2940 "View all the MIME parts."
2942 (save-current-buffer
2943 (set-buffer gnus-article-buffer)
2944 (let ((handles (or handles gnus-article-mime-handles))
2945 (mail-parse-charset gnus-newsgroup-charset)
2946 (mail-parse-ignored-charsets
2947 (save-excursion (set-buffer gnus-summary-buffer)
2948 gnus-newsgroup-ignored-charsets)))
2949 (if (stringp (car handles))
2950 (gnus-mime-view-all-parts (cdr handles))
2951 (mapcar 'mm-display-part handles)))))
2953 (defun gnus-mime-save-part ()
2954 "Save the MIME part under point."
2956 (gnus-article-check-buffer)
2957 (let ((data (get-text-property (point) 'gnus-data)))
2958 (mm-save-part data)))
2960 (defun gnus-mime-pipe-part ()
2961 "Pipe the MIME part under point to a process."
2963 (gnus-article-check-buffer)
2964 (let ((data (get-text-property (point) 'gnus-data)))
2965 (mm-pipe-part data)))
2967 (defun gnus-mime-view-part ()
2968 "Interactively choose a viewing method for the MIME part under point."
2970 (gnus-article-check-buffer)
2971 (let ((data (get-text-property (point) 'gnus-data)))
2972 (mm-interactively-view-part data)))
2974 (defun gnus-mime-view-part-as-type-internal ()
2975 (gnus-article-check-buffer)
2976 (let* ((name (mail-content-type-get
2977 (mm-handle-type (get-text-property (point) 'gnus-data))
2979 (def-type (and name (mm-default-file-encoding name))))
2980 (and def-type (cons def-type 0))))
2982 (defun gnus-mime-view-part-as-type (mime-type)
2983 "Choose a MIME media type, and view the part as such."
2985 (list (completing-read
2986 "View as MIME type: "
2987 (mapcar #'list (mailcap-mime-types))
2989 (gnus-mime-view-part-as-type-internal))))
2990 (gnus-article-check-buffer)
2991 (let ((handle (get-text-property (point) 'gnus-data)))
2992 (gnus-mm-display-part
2993 (mm-make-handle (mm-handle-buffer handle)
2994 (cons mime-type (cdr (mm-handle-type handle)))
2995 (mm-handle-encoding handle)
2996 (mm-handle-undisplayer handle)
2997 (mm-handle-disposition handle)
2998 (mm-handle-description handle)
2999 (mm-handle-cache handle)
3000 (mm-handle-id handle)))))
3002 (defun gnus-mime-copy-part (&optional handle)
3003 "Put the the MIME part under point into a new buffer."
3005 (gnus-article-check-buffer)
3006 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3007 (contents (mm-get-part handle))|
3008 (base (file-name-nondirectory
3010 (mail-content-type-get (mm-handle-type handle) 'name)
3011 (mail-content-type-get (mm-handle-type handle)
3014 (buffer (generate-new-buffer base)))
3015 (switch-to-buffer buffer)
3017 ;; We do it this way to make `normal-mode' set the appropriate mode.
3020 (setq buffer-file-name (expand-file-name base))
3022 (setq buffer-file-name nil))
3023 (goto-char (point-min))))
3025 (defun gnus-mime-inline-part (&optional handle arg)
3026 "Insert the MIME part under point into the current buffer."
3027 (interactive (list nil current-prefix-arg))
3028 (gnus-article-check-buffer)
3029 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3033 (if (mm-handle-undisplayer handle)
3034 (mm-remove-part handle)
3035 (setq contents (mm-get-part handle))
3038 (setq charset (or (mail-content-type-get
3039 (mm-handle-type handle) 'charset)
3040 gnus-newsgroup-charset)))
3044 gnus-summary-show-article-charset-alist))
3045 (read-coding-system "Charset: ")))))
3047 (mm-insert-inline handle (if charset
3048 (mm-decode-coding-string contents charset)
3052 (defun gnus-mime-externalize-part (&optional handle)
3053 "View the MIME part under point with an external viewer."
3055 (gnus-article-check-buffer)
3056 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3057 (mm-user-display-methods nil)
3058 (mm-inlined-types nil)
3059 (mail-parse-charset gnus-newsgroup-charset)
3060 (mail-parse-ignored-charsets
3061 (save-excursion (set-buffer gnus-summary-buffer)
3062 gnus-newsgroup-ignored-charsets)))
3063 (if (mm-handle-undisplayer handle)
3064 (mm-remove-part handle)
3065 (mm-display-part handle))))
3067 (defun gnus-mime-internalize-part (&optional handle)
3068 "View the MIME part under point with an internal viewer.
3069 In no internal viewer is available, use an external viewer."
3071 (gnus-article-check-buffer)
3072 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3073 (mm-inlined-types '(".*"))
3074 (mm-inline-large-images t)
3075 (mail-parse-charset gnus-newsgroup-charset)
3076 (mail-parse-ignored-charsets
3077 (save-excursion (set-buffer gnus-summary-buffer)
3078 gnus-newsgroup-ignored-charsets)))
3079 (if (mm-handle-undisplayer handle)
3080 (mm-remove-part handle)
3081 (mm-display-part handle))))
3083 (defun gnus-mime-action-on-part (&optional action)
3084 "Do something with the MIME attachment at \(point\)."
3086 (list (completing-read "Action: " gnus-mime-action-alist)))
3087 (gnus-article-check-buffer)
3088 (let ((action-pair (assoc action gnus-mime-action-alist)))
3090 (funcall (cdr action-pair)))))
3093 (defun gnus-article-part-wrapper (n function)
3094 (save-current-buffer
3095 (set-buffer gnus-article-buffer)
3096 (when (> n (length gnus-article-mime-handle-alist))
3097 (error "No such part"))
3098 (gnus-article-goto-part n)
3099 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3100 (funcall function handle))))
3102 (defun gnus-article-pipe-part (n)
3103 "Pipe MIME part N, which is the numerical prefix."
3105 (gnus-article-part-wrapper n 'mm-pipe-part))
3107 (defun gnus-article-save-part (n)
3108 "Save MIME part N, which is the numerical prefix."
3110 (gnus-article-part-wrapper n 'mm-save-part))
3112 (defun gnus-article-interactively-view-part (n)
3113 "View MIME part N interactively, which is the numerical prefix."
3115 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3117 (defun gnus-article-copy-part (n)
3118 "Copy MIME part N, which is the numerical prefix."
3120 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3122 (defun gnus-article-externalize-part (n)
3123 "View MIME part N externally, which is the numerical prefix."
3125 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3127 (defun gnus-article-inline-part (n)
3128 "Inline MIME part N, which is the numerical prefix."
3130 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3132 (defun gnus-article-mime-match-handle-first (condition)
3134 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3135 (while (setq ihandle (pop alist))
3137 ((functionp condition)
3138 (funcall condition (cdr ihandle)))
3139 ((eq condition 'undisplayed)
3140 (not (or (mm-handle-undisplayer (cdr ihandle))
3141 (equal (mm-handle-media-type (cdr ihandle))
3142 "multipart/alternative"))))
3143 ((eq condition 'undisplayed-alternative)
3144 (not (mm-handle-undisplayer (cdr ihandle))))
3146 (gnus-article-goto-part (car ihandle))
3147 (or (not n) (< (car ihandle) n)))
3148 (setq n (car ihandle))))
3152 (defun gnus-article-view-part (&optional n)
3153 "View MIME part N, which is the numerical prefix."
3155 (save-current-buffer
3156 (set-buffer gnus-article-buffer)
3157 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3158 gnus-article-mime-match-handle-function)))
3159 (when (> n (length gnus-article-mime-handle-alist))
3160 (error "No such part"))
3161 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3162 (when (gnus-article-goto-part n)
3163 (if (equal (car handle) "multipart/alternative")
3164 (gnus-article-press-button)
3165 (when (eq (gnus-mm-display-part handle) 'internal)
3166 (gnus-set-window-start)))))))
3168 (defun gnus-mm-display-part (handle)
3169 "Display HANDLE and fix MIME button."
3170 (let ((id (get-text-property (point) 'gnus-part))
3175 (let ((window (selected-window))
3176 (mail-parse-charset gnus-newsgroup-charset)
3177 (mail-parse-ignored-charsets
3178 (save-excursion (set-buffer gnus-summary-buffer)
3179 gnus-newsgroup-ignored-charsets)))
3182 (let ((win (get-buffer-window (current-buffer) t))
3185 (select-window win))
3188 (if (mm-handle-displayed-p handle)
3189 ;; This will remove the part.
3190 (mm-display-part handle)
3192 (narrow-to-region (point) (1+ (point)))
3193 (mm-display-part handle)
3194 ;; We narrow to the part itself and
3195 ;; then call the treatment functions.
3196 (goto-char (point-min))
3198 (narrow-to-region (point) (point-max))
3201 (1- (length gnus-article-mime-handles))
3202 (mm-handle-media-type handle)))))
3203 (select-window window))))
3205 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3206 (gnus-insert-mime-button
3207 handle id (list (mm-handle-displayed-p handle)))
3208 (goto-char point))))
3210 (defun gnus-article-goto-part (n)
3211 "Go to MIME part N."
3212 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3214 (goto-char point))))
3216 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3217 (let ((gnus-tmp-name
3218 (or (mail-content-type-get (mm-handle-type handle)
3220 (mail-content-type-get (mm-handle-disposition handle)
3223 (gnus-tmp-type (mm-handle-media-type handle))
3224 (gnus-tmp-description
3225 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3228 (if (if displayed (car displayed)
3229 (mm-handle-displayed-p handle))
3231 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3233 gnus-tmp-type-long b e)
3234 (when (string-match ".*/" gnus-tmp-name)
3235 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3236 (setq gnus-tmp-type-long (concat gnus-tmp-type
3237 (and (not (equal gnus-tmp-name ""))
3238 (concat "; " gnus-tmp-name))))
3239 (or (equal gnus-tmp-description "")
3240 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3245 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3246 `(local-map ,gnus-mime-button-map
3247 keymap ,gnus-mime-button-map
3248 gnus-callback gnus-mm-display-part
3249 gnus-part ,gnus-tmp-id
3250 article-type annotation
3253 (widget-convert-button
3256 :action 'gnus-widget-press-button
3257 :button-keymap gnus-mime-button-map
3259 (lambda (widget/window &optional overlay pos)
3260 ;; Needed to properly clear the message due to a bug in
3261 ;; wid-edit (XEmacs only).
3262 (if (boundp 'help-echo-owns-message)
3263 (setq help-echo-owns-message t))
3265 "%S: %s the MIME part; %S: more options"
3266 (aref gnus-mouse-2 0)
3267 ;; XEmacs will get a single widget arg; Emacs 21 will get
3268 ;; window, overlay, position.
3269 (if (mm-handle-displayed-p
3271 (with-current-buffer (overlay-buffer overlay)
3272 (widget-get (widget-at (overlay-start overlay))
3274 (widget-get widget/window :mime-handle)))
3276 (aref gnus-down-mouse-3 0))))))
3278 (defun gnus-widget-press-button (elems el)
3279 (goto-char (widget-get elems :from))
3280 (gnus-article-press-button))
3282 (defvar gnus-displaying-mime nil)
3284 (defun gnus-display-mime (&optional ihandles)
3285 "Display the MIME parts."
3287 (save-selected-window
3288 (let ((window (get-buffer-window gnus-article-buffer))
3291 (select-window window)
3292 ;; We have to do this since selecting the window
3293 ;; may change the point. So we set the window point.
3294 (set-window-point window point)))
3295 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3296 buffer-read-only handle name type b e display)
3297 (when (and (not ihandles)
3298 (not gnus-displaying-mime))
3299 ;; Top-level call; we clean up.
3300 (when gnus-article-mime-handles
3301 (mm-destroy-parts gnus-article-mime-handles)
3302 (setq gnus-article-mime-handle-alist nil));; A trick.
3303 (setq gnus-article-mime-handles handles)
3304 ;; We allow users to glean info from the handles.
3305 (when gnus-article-mime-part-function
3306 (gnus-mime-part-function handles)))
3308 (or (not (stringp (car handles)))
3311 (when (and (not ihandles)
3312 (not gnus-displaying-mime))
3313 ;; Clean up for mime parts.
3315 (delete-region (point) (point-max)))
3316 (let ((gnus-displaying-mime t))
3317 (gnus-mime-display-part handles)))
3320 (narrow-to-region (point) (point-max))
3321 (gnus-treat-article nil 1 1)
3324 ;; Highlight the headers.
3328 (narrow-to-region (point-min) (point))
3329 (gnus-treat-article 'head))))))))
3331 (defvar gnus-mime-display-multipart-as-mixed nil)
3333 (defun gnus-mime-display-part (handle)
3336 ((not (stringp (car handle)))
3337 (gnus-mime-display-single handle))
3338 ;; User-defined multipart
3339 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3340 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3342 ;; multipart/alternative
3343 ((and (equal (car handle) "multipart/alternative")
3344 (not gnus-mime-display-multipart-as-mixed))
3345 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3346 (push (cons id handle) gnus-article-mime-handle-alist)
3347 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3348 ;; multipart/related
3349 ((and (equal (car handle) "multipart/related")
3350 (not gnus-mime-display-multipart-as-mixed))
3351 ;;;!!!We should find the start part, but we just default
3352 ;;;!!!to the first part.
3353 (gnus-mime-display-part (cadr handle)))
3354 ;; Other multiparts are handled like multipart/mixed.
3356 (gnus-mime-display-mixed (cdr handle)))))
3358 (defun gnus-mime-part-function (handles)
3359 (if (stringp (car handles))
3360 (mapcar 'gnus-mime-part-function (cdr handles))
3361 (funcall gnus-article-mime-part-function handles)))
3363 (defun gnus-mime-display-mixed (handles)
3364 (mapcar 'gnus-mime-display-part handles))
3366 (defun gnus-mime-display-single (handle)
3367 (let ((type (mm-handle-media-type handle))
3368 (ignored gnus-ignored-mime-types)
3375 (when (string-match (pop ignored) type)
3376 (throw 'ignored nil)))
3377 (if (and (setq not-attachment
3378 (and (not (mm-inline-override-p handle))
3379 (or (not (mm-handle-disposition handle))
3380 (equal (car (mm-handle-disposition handle))
3382 (mm-attachment-override-p handle))))
3383 (mm-automatic-display-p handle)
3384 (or (mm-inlined-p handle)
3385 (mm-automatic-external-display-p type)))
3387 (when (equal (mm-handle-media-supertype handle) "text")
3389 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3390 (push (cons id handle) gnus-article-mime-handle-alist)
3391 (when (or (not display)
3392 (not (gnus-unbuttonized-mime-type-p type)))
3393 ;(gnus-article-insert-newline)
3394 (gnus-insert-mime-button
3395 handle id (list (or display (and not-attachment text))))
3396 (gnus-article-insert-newline)
3397 ;(gnus-article-insert-newline)
3399 (let ((beg (point)))
3405 (let ((mail-parse-charset gnus-newsgroup-charset)
3406 (mail-parse-ignored-charsets
3407 (save-excursion (condition-case ()
3408 (set-buffer gnus-summary-buffer)
3410 gnus-newsgroup-ignored-charsets)))
3411 (mm-display-part handle t))
3412 (goto-char (point-max)))
3413 ((and text not-attachment)
3417 (gnus-article-insert-newline)
3418 (mm-insert-inline handle (mm-get-part handle))
3419 (goto-char (point-max))))
3423 (narrow-to-region beg (point))
3425 nil (length gnus-article-mime-handle-alist)
3426 (1- (length gnus-article-mime-handles))
3427 (mm-handle-media-type handle)))))))))
3429 (defun gnus-unbuttonized-mime-type-p (type)
3430 "Say whether TYPE is to be unbuttonized."
3431 (unless gnus-inhibit-mime-unbuttonizing
3433 (let ((types gnus-unbuttonized-mime-types))
3435 (when (string-match (pop types) type)
3436 (throw 'found t)))))))
3438 (defun gnus-article-insert-newline ()
3439 "Insert a newline, but mark it as undeletable."
3440 (gnus-put-text-property
3441 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3443 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3444 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3447 handle buffer-read-only from props begend not-pref)
3448 (save-window-excursion
3451 (narrow-to-region (car ibegend)
3454 (goto-char (car ibegend))
3457 (delete-region (point-min) (point-max))
3458 (mm-remove-parts handles))
3459 (setq begend (list (point-marker)))
3461 (unless (setq not-pref (cadr (member preferred ihandles)))
3462 (setq not-pref (car ihandles)))
3464 (not (gnus-unbuttonized-mime-type-p
3465 "multipart/alternative")))
3466 (gnus-add-text-properties
3469 (insert (format "%d. " id))
3473 (unless ,(not ibegend)
3474 (setq gnus-article-mime-handle-alist
3475 ',gnus-article-mime-handle-alist))
3476 (gnus-mime-display-alternative
3477 ',ihandles ',not-pref ',begend ,id))
3478 local-map ,gnus-mime-button-map
3479 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3480 face ,gnus-article-button-face
3481 keymap ,gnus-mime-button-map
3484 (widget-convert-button 'link from (point)
3485 :action 'gnus-widget-press-button
3486 :button-keymap gnus-widget-button-keymap)
3488 (while (setq handle (pop handles))
3489 (gnus-add-text-properties
3492 (insert (format "(%c) %-18s"
3493 (if (equal handle preferred) ?* ? )
3494 (mm-handle-media-type handle)))
3498 (unless ,(not ibegend)
3499 (setq gnus-article-mime-handle-alist
3500 ',gnus-article-mime-handle-alist))
3501 (gnus-mime-display-alternative
3502 ',ihandles ',handle ',begend ,id))
3503 local-map ,gnus-mime-button-map
3504 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3505 face ,gnus-article-button-face
3506 keymap ,gnus-mime-button-map
3509 (widget-convert-button 'link from (point)
3510 :action 'gnus-widget-press-button
3511 :button-keymap gnus-widget-button-keymap)
3515 (if (stringp (car preferred))
3516 (gnus-display-mime preferred)
3517 (let ((mail-parse-charset gnus-newsgroup-charset)
3518 (mail-parse-ignored-charsets
3519 (save-excursion (set-buffer gnus-summary-buffer)
3520 gnus-newsgroup-ignored-charsets)))
3521 (mm-display-part preferred)
3525 (narrow-to-region (car begend) (point-max))
3527 nil (length gnus-article-mime-handle-alist)
3528 (1- (length gnus-article-mime-handles))
3529 (mm-handle-media-type handle))))))
3530 (goto-char (point-max))
3531 (setcdr begend (point-marker)))))
3533 (goto-char point))))
3535 (defun gnus-article-wash-status ()
3536 "Return a string which display status of article washing."
3538 (set-buffer gnus-article-buffer)
3539 (let ((cite (memq 'cite gnus-article-wash-types))
3540 (headers (memq 'headers gnus-article-wash-types))
3541 (boring (memq 'boring-headers gnus-article-wash-types))
3542 (pgp (memq 'pgp gnus-article-wash-types))
3543 (pem (memq 'pem gnus-article-wash-types))
3544 (signature (memq 'signature gnus-article-wash-types))
3545 (overstrike (memq 'overstrike gnus-article-wash-types))
3546 (emphasis (memq 'emphasis gnus-article-wash-types)))
3547 (format "%c%c%c%c%c%c"
3549 (if (or headers boring) ?h ? )
3550 (if (or pgp pem) ?p ? )
3551 (if signature ?s ? )
3552 (if overstrike ?o ? )
3553 (if emphasis ?e ? )))))
3555 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3557 (defun gnus-article-maybe-hide-headers ()
3558 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3559 Provided for backwards compatibility."
3560 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3561 (not (save-excursion (set-buffer gnus-summary-buffer)
3562 gnus-have-all-headers)))
3563 (not gnus-inhibit-hiding))
3564 (gnus-article-hide-headers)))
3568 (defun gnus-output-to-file (file-name)
3569 "Append the current article to a file named FILE-NAME."
3570 (let ((artbuf (current-buffer)))
3572 (insert-buffer-substring artbuf)
3573 ;; Append newline at end of the buffer as separator, and then
3575 (goto-char (point-max))
3577 (mm-append-to-file (point-min) (point-max) file-name)
3580 (defun gnus-narrow-to-page (&optional arg)
3581 "Narrow the article buffer to a page.
3582 If given a numerical ARG, move forward ARG pages."
3584 (setq arg (if arg (prefix-numeric-value arg) 0))
3586 (set-buffer gnus-article-buffer)
3587 (goto-char (point-min))
3589 ;; Remove any old next/prev buttons.
3590 (when (gnus-visual-p 'page-marker)
3591 (let ((buffer-read-only nil))
3592 (gnus-remove-text-with-property 'gnus-prev)
3593 (gnus-remove-text-with-property 'gnus-next)))
3596 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3598 (re-search-forward page-delimiter nil 'move arg)))
3599 (goto-char (match-end 0)))
3602 (if (re-search-forward page-delimiter nil 'move)
3605 (when (and (gnus-visual-p 'page-marker)
3606 (not (= (point-min) 1)))
3608 (goto-char (point-min))
3609 (gnus-insert-prev-page-button)))
3610 (when (and (gnus-visual-p 'page-marker)
3611 (< (+ (point-max) 2) (buffer-size)))
3613 (goto-char (point-max))
3614 (gnus-insert-next-page-button)))))
3616 ;; Article mode commands
3618 (defun gnus-article-goto-next-page ()
3619 "Show the next page of the article."
3621 (when (gnus-article-next-page)
3622 (goto-char (point-min))
3623 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3625 (defun gnus-article-goto-prev-page ()
3626 "Show the next page of the article."
3628 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3629 (gnus-article-prev-page nil)))
3631 (defun gnus-article-next-page (&optional lines)
3632 "Show the next page of the current article.
3633 If end of article, return non-nil. Otherwise return nil.
3634 Argument LINES specifies lines to be scrolled up."
3636 (move-to-window-line -1)
3639 (and (pos-visible-in-window-p) ;Not continuation line.
3641 ;; Nothing in this page.
3642 (if (or (not gnus-page-broken)
3645 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3647 (gnus-narrow-to-page 1) ;Go to next page.
3649 ;; More in this page.
3650 (let ((scroll-in-place nil))
3654 ;; Long lines may cause an end-of-buffer error.
3655 (goto-char (point-max)))))
3656 (move-to-window-line 0)
3659 (defun gnus-article-prev-page (&optional lines)
3660 "Show previous page of current article.
3661 Argument LINES specifies lines to be scrolled down."
3663 (move-to-window-line 0)
3664 (if (and gnus-page-broken
3666 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3668 (gnus-narrow-to-page -1) ;Go to previous page.
3669 (goto-char (point-max))
3671 (let ((scroll-in-place nil))
3675 (beginning-of-buffer
3676 (goto-char (point-min))))
3677 (move-to-window-line 0)))))
3679 (defun gnus-article-refer-article ()
3680 "Read article specified by message-id around point."
3682 (let ((point (point)))
3683 (search-forward ">" nil t) ;Move point to end of "<....>".
3684 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3685 (let ((message-id (match-string 1)))
3687 (set-buffer gnus-summary-buffer)
3688 (gnus-summary-refer-article message-id))
3690 (error "No references around point"))))
3692 (defun gnus-article-show-summary ()
3693 "Reconfigure windows to show summary buffer."
3695 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3696 (error "There is no summary buffer for this article buffer")
3697 (gnus-article-set-globals)
3698 (gnus-configure-windows 'article)
3699 (gnus-summary-goto-subject gnus-current-article)
3700 (gnus-summary-position-point)))
3702 (defun gnus-article-describe-briefly ()
3703 "Describe article mode commands briefly."
3705 (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")))
3707 (defun gnus-article-summary-command ()
3708 "Execute the last keystroke in the summary buffer."
3710 (let ((obuf (current-buffer))
3711 (owin (current-window-configuration))
3713 (switch-to-buffer gnus-article-current-summary 'norecord)
3714 (setq func (lookup-key (current-local-map) (this-command-keys)))
3715 (call-interactively func)
3717 (set-window-configuration owin)
3718 (set-window-point (get-buffer-window (current-buffer)) (point))))
3720 (defun gnus-article-summary-command-nosave ()
3721 "Execute the last keystroke in the summary buffer."
3724 (pop-to-buffer gnus-article-current-summary 'norecord)
3725 (setq func (lookup-key (current-local-map) (this-command-keys)))
3726 (call-interactively func)))
3728 (defun gnus-article-check-buffer ()
3729 "Beep if not in an article buffer."
3730 (unless (equal major-mode 'gnus-article-mode)
3731 (error "Command invoked outside of a Gnus article buffer")))
3733 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3734 "Read a summary buffer key sequence and execute it from the article buffer."
3736 (gnus-article-check-buffer)
3738 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3739 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3740 "=" "^" "\M-^" "|"))
3746 '("n" "Gn" "p" "Gp"))
3749 (set-buffer gnus-article-current-summary)
3750 (let (gnus-pick-mode)
3751 (push (or key last-command-event) unread-command-events)
3752 (setq keys (if gnus-xemacs
3753 (events-to-keys (read-key-sequence nil))
3754 (read-key-sequence nil)))))
3758 (if (or (member keys nosaves)
3759 (member keys nosave-but-article)
3760 (member keys nosave-in-article))
3762 (save-window-excursion
3763 (pop-to-buffer gnus-article-current-summary 'norecord)
3764 ;; We disable the pick minor mode commands.
3765 (let (gnus-pick-mode)
3766 (setq func (lookup-key (current-local-map) keys))))
3770 (unless (member keys nosave-in-article)
3771 (set-buffer gnus-article-current-summary))
3772 (call-interactively func)
3773 (setq new-sum-point (point)))
3774 (when (member keys nosave-but-article)
3775 (pop-to-buffer gnus-article-buffer 'norecord)))
3776 ;; These commands should restore window configuration.
3777 (let ((obuf (current-buffer))
3778 (owin (current-window-configuration))
3780 (summary gnus-article-current-summary)
3781 func in-buffer selected)
3782 (if not-restore-window
3783 (pop-to-buffer summary 'norecord)
3784 (switch-to-buffer summary 'norecord))
3785 (setq in-buffer (current-buffer))
3786 ;; We disable the pick minor mode commands.
3787 (if (setq func (let (gnus-pick-mode)
3788 (lookup-key (current-local-map) keys)))
3790 (call-interactively func)
3791 (setq new-sum-point (point)))
3793 (when (eq in-buffer (current-buffer))
3794 (setq selected (gnus-summary-select-article))
3796 (unless not-restore-window
3797 (set-window-configuration owin))
3798 (when (eq selected 'old)
3800 (set-window-start (get-buffer-window (current-buffer))
3802 (set-window-point (get-buffer-window (current-buffer))
3804 (let ((win (get-buffer-window gnus-article-current-summary)))
3806 (set-window-point win new-sum-point))))))))
3808 (defun gnus-article-hide (&optional arg force)
3809 "Hide all the gruft in the current article.
3810 This means that PGP stuff, signatures, cited text and (some)
3811 headers will be hidden.
3812 If given a prefix, show the hidden text instead."
3813 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3814 (gnus-article-hide-headers arg)
3815 (gnus-article-hide-list-identifiers arg)
3816 (gnus-article-hide-pgp arg)
3817 (gnus-article-hide-citation-maybe arg force)
3818 (gnus-article-hide-signature arg))
3820 (defun gnus-article-maybe-highlight ()
3821 "Do some article highlighting if article highlighting is requested."
3822 (when (gnus-visual-p 'article-highlight 'highlight)
3823 (gnus-article-highlight-some)))
3825 (defun gnus-check-group-server ()
3826 ;; Make sure the connection to the server is alive.
3827 (unless (gnus-server-opened
3828 (gnus-find-method-for-group gnus-newsgroup-name))
3829 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3830 (gnus-request-group gnus-newsgroup-name t)))
3832 (defun gnus-request-article-this-buffer (article group)
3833 "Get an article and insert it into this buffer."
3834 (let (do-update-line sparse-header)
3838 (gnus-kill-all-overlays)
3839 (setq group (or group gnus-newsgroup-name))
3841 ;; Using `gnus-request-article' directly will insert the article into
3842 ;; `nntp-server-buffer' - so we'll save some time by not having to
3843 ;; copy it from the server buffer into the article buffer.
3845 ;; We only request an article by message-id when we do not have the
3846 ;; headers for it, so we'll have to get those.
3847 (when (stringp article)
3848 (gnus-read-header article))
3850 ;; If the article number is negative, that means that this article
3851 ;; doesn't belong in this newsgroup (possibly), so we find its
3852 ;; message-id and request it by id instead of number.
3853 (when (and (numberp article)
3855 (get-buffer gnus-summary-buffer)
3856 (gnus-buffer-exists-p gnus-summary-buffer))
3858 (set-buffer gnus-summary-buffer)
3859 (let ((header (gnus-summary-article-header article)))
3862 ((memq article gnus-newsgroup-sparse)
3863 ;; This is a sparse gap article.
3864 (setq do-update-line article)
3865 (setq article (mail-header-id header))
3866 (setq sparse-header (gnus-read-header article))
3867 (setq gnus-newsgroup-sparse
3868 (delq article gnus-newsgroup-sparse)))
3870 ;; It's a real article.
3871 (setq article (mail-header-id header)))
3873 ;; It is an extracted pseudo-article.
3874 (setq article 'pseudo)
3875 (gnus-request-pseudo-article header))))
3877 (let ((method (gnus-find-method-for-group
3878 gnus-newsgroup-name)))
3879 (when (and (eq (car method) 'nneething)
3881 (let ((dir (expand-file-name
3882 (mail-header-subject header)
3883 (file-name-as-directory
3884 (or (cadr (assq 'nneething-address method))
3886 (when (file-directory-p dir)
3887 (setq article 'nneething)
3888 (gnus-group-enter-directory dir))))))))
3891 ;; Refuse to select canceled articles.
3892 ((and (numberp article)
3894 (get-buffer gnus-summary-buffer)
3895 (gnus-buffer-exists-p gnus-summary-buffer)
3896 (eq (cdr (save-excursion
3897 (set-buffer gnus-summary-buffer)
3898 (assq article gnus-newsgroup-reads)))
3899 gnus-canceled-mark))
3901 ;; We first check `gnus-original-article-buffer'.
3902 ((and (get-buffer gnus-original-article-buffer)
3905 (set-buffer gnus-original-article-buffer)
3906 (and (equal (car gnus-original-article) group)
3907 (eq (cdr gnus-original-article) article))))
3908 (insert-buffer-substring gnus-original-article-buffer)
3910 ;; Check the backlog.
3911 ((and gnus-keep-backlog
3912 (gnus-backlog-request-article group article (current-buffer)))
3914 ;; Check asynchronous pre-fetch.
3915 ((gnus-async-request-fetched-article group article (current-buffer))
3916 (gnus-async-prefetch-next group article gnus-summary-buffer)
3917 (when (and (numberp article) gnus-keep-backlog)
3918 (gnus-backlog-enter-article group article (current-buffer)))
3921 ((and gnus-use-cache
3923 (gnus-cache-request-article article group))
3925 ;; Get the article and put into the article buffer.
3926 ((or (stringp article)
3928 (let ((gnus-override-method gnus-override-method)
3929 (methods (and (stringp article)
3930 gnus-refer-article-method))
3932 (buffer-read-only nil))
3937 (when (and (null gnus-override-method)
3939 (setq gnus-override-method (pop methods)))
3941 (when (eq gnus-override-method 'current)
3942 (setq gnus-override-method gnus-current-select-method))
3944 (gnus-kill-all-overlays)
3945 (let ((gnus-newsgroup-name group))
3946 (gnus-check-group-server))
3947 (when (gnus-request-article article group (current-buffer))
3948 (when (numberp article)
3949 (gnus-async-prefetch-next group article
3950 gnus-summary-buffer)
3951 (when gnus-keep-backlog
3952 (gnus-backlog-enter-article
3953 group article (current-buffer))))
3954 (setq result 'article))
3957 (setq gnus-override-method (pop methods))
3958 (setq result 'done))))
3959 (and (eq result 'article) 'article)))
3963 ;; Associate this article with the current summary buffer.
3964 (setq gnus-article-current-summary gnus-summary-buffer)
3966 ;; Take the article from the original article buffer
3967 ;; and place it in the buffer it's supposed to be in.
3968 (when (and (get-buffer gnus-article-buffer)
3969 (equal (buffer-name (current-buffer))
3970 (buffer-name (get-buffer gnus-article-buffer))))
3972 (if (get-buffer gnus-original-article-buffer)
3973 (set-buffer gnus-original-article-buffer)
3974 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3975 (buffer-disable-undo)
3976 (setq major-mode 'gnus-original-article-mode)
3977 (setq buffer-read-only t))
3978 (let (buffer-read-only)
3980 (insert-buffer-substring gnus-article-buffer))
3981 (setq gnus-original-article (cons group article)))
3984 (run-hooks 'gnus-article-decode-hook)
3985 ;; Mark article as decoded or not.
3986 (setq gnus-article-decoded-p gnus-article-decode-hook))
3988 ;; Update sparse articles.
3989 (when (and do-update-line
3990 (or (numberp article)
3992 (let ((buf (current-buffer)))
3993 (set-buffer gnus-summary-buffer)
3994 (gnus-summary-update-article do-update-line sparse-header)
3995 (gnus-summary-goto-subject do-update-line nil t)
3996 (set-window-point (get-buffer-window (current-buffer) t)
3998 (set-buffer buf))))))
4004 (defcustom gnus-article-edit-mode-hook nil
4005 "Hook run in article edit mode buffers."
4006 :group 'gnus-article-various
4009 (defvar gnus-article-edit-done-function nil)
4011 (defvar gnus-article-edit-mode-map nil)
4013 ;; Should we be using derived.el for this?
4014 (unless gnus-article-edit-mode-map
4015 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4016 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4018 (gnus-define-keys gnus-article-edit-mode-map
4019 "\C-c\C-c" gnus-article-edit-done
4020 "\C-c\C-k" gnus-article-edit-exit)
4022 (gnus-define-keys (gnus-article-edit-wash-map
4023 "\C-c\C-w" gnus-article-edit-mode-map)
4024 "f" gnus-article-edit-full-stops))
4026 (defun gnus-article-edit-mode ()
4027 "Major mode for editing articles.
4028 This is an extended text-mode.
4030 \\{gnus-article-edit-mode-map}"
4032 (setq major-mode 'gnus-article-edit-mode)
4033 (setq mode-name "Article Edit")
4034 (use-local-map gnus-article-edit-mode-map)
4035 (make-local-variable 'gnus-article-edit-done-function)
4036 (make-local-variable 'gnus-prev-winconf)
4037 (setq buffer-read-only nil)
4038 (buffer-enable-undo)
4040 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4042 (defun gnus-article-edit (&optional force)
4043 "Edit the current article.
4044 This will have permanent effect only in mail groups.
4045 If FORCE is non-nil, allow editing of articles even in read-only
4048 (when (and (not force)
4049 (gnus-group-read-only-p))
4050 (error "The current newsgroup does not support article editing"))
4051 (gnus-article-date-original)
4052 (gnus-article-edit-article
4054 `(lambda (no-highlight)
4056 (gnus-summary-edit-article-done
4057 ,(or (mail-header-references gnus-current-headers) "")
4058 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4060 (defun gnus-article-edit-article (start-func exit-func)
4061 "Start editing the contents of the current article buffer."
4062 (let ((winconf (current-window-configuration)))
4063 (set-buffer gnus-article-buffer)
4064 (gnus-article-edit-mode)
4065 (funcall start-func)
4066 (gnus-configure-windows 'edit-article)
4067 (setq gnus-article-edit-done-function exit-func)
4068 (setq gnus-prev-winconf winconf)
4069 (gnus-message 6 "C-c C-c to end edits")))
4071 (defun gnus-article-edit-done (&optional arg)
4072 "Update the article edits and exit."
4077 (when (article-goto-body)
4078 (let ((lines (count-lines (point) (point-max)))
4079 (length (- (point-max) (point)))
4080 (case-fold-search t)
4081 (body (copy-marker (point))))
4082 (goto-char (point-min))
4083 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4084 (delete-region (match-beginning 1) (match-end 1))
4085 (insert (number-to-string length)))
4086 (goto-char (point-min))
4087 (when (re-search-forward
4088 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4089 (delete-region (match-beginning 1) (match-end 1))
4090 (insert (number-to-string length)))
4091 (goto-char (point-min))
4092 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4093 (delete-region (match-beginning 1) (match-end 1))
4094 (insert (number-to-string lines)))))))
4095 (let ((func gnus-article-edit-done-function)
4096 (buf (current-buffer))
4097 (start (window-start)))
4098 (gnus-article-edit-exit)
4101 (let ((buffer-read-only nil))
4103 ;; The cache and backlog have to be flushed somewhat.
4104 (when gnus-keep-backlog
4105 (gnus-backlog-remove-article
4106 (car gnus-article-current) (cdr gnus-article-current)))
4107 ;; Flush original article as well.
4109 (when (get-buffer gnus-original-article-buffer)
4110 (set-buffer gnus-original-article-buffer)
4111 (setq gnus-original-article nil)))
4112 (when gnus-use-cache
4113 (gnus-cache-update-article
4114 (car gnus-article-current) (cdr gnus-article-current))))
4116 (set-window-start (get-buffer-window buf) start)
4117 (set-window-point (get-buffer-window buf) (point))))
4119 (defun gnus-article-edit-exit ()
4120 "Exit the article editing without updating."
4122 ;; We remove all text props from the article buffer.
4123 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4124 (curbuf (current-buffer))
4126 (window-start (window-start)))
4129 (let ((winconf gnus-prev-winconf))
4131 (set-window-configuration winconf)
4132 ;; Tippy-toe some to make sure that point remains where it was.
4133 (save-current-buffer
4135 (set-window-start (get-buffer-window (current-buffer)) window-start)
4138 (defun gnus-article-edit-full-stops ()
4139 "Interactively repair spacing at end of sentences."
4142 (goto-char (point-min))
4143 (search-forward-regexp "^$" nil t)
4144 (let ((case-fold-search nil))
4145 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4148 ;;; Article highlights
4151 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4153 ;;; Internal Variables:
4155 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)"
4156 "Regular expression that matches URLs."
4157 :group 'gnus-article-buttons
4160 (defcustom gnus-button-alist
4161 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4162 0 t gnus-button-message-id 2)
4163 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4164 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4166 gnus-button-fetch-group 4)
4167 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4168 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4169 t gnus-button-message-id 3)
4170 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4171 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4172 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4173 ;; This is how URLs _should_ be embedded in text...
4174 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4176 (,gnus-button-url-regexp 0 t browse-url 0))
4177 "*Alist of regexps matching buttons in article bodies.
4179 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4180 REGEXP: is the string matching text around the button,
4181 BUTTON: is the number of the regexp grouping actually matching the button,
4182 FORM: is a lisp expression which must eval to true for the button to
4184 CALLBACK: is the function to call when the user push this button, and each
4185 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4187 CALLBACK can also be a variable, in that case the value of that
4188 variable it the real callback function."
4189 :group 'gnus-article-buttons
4190 :type '(repeat (list regexp
4191 (integer :tag "Button")
4193 (function :tag "Callback")
4196 (integer :tag "Regexp group")))))
4198 (defcustom gnus-header-button-alist
4199 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4200 0 t gnus-button-message-id 0)
4201 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4202 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4203 0 t gnus-button-mailto 0)
4204 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4205 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4206 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4207 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4208 gnus-button-message-id 3))
4209 "*Alist of headers and regexps to match buttons in article heads.
4211 This alist is very similar to `gnus-button-alist', except that each
4212 alist has an additional HEADER element first in each entry:
4214 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4216 HEADER is a regexp to match a header. For a fuller explanation, see
4217 `gnus-button-alist'."
4218 :group 'gnus-article-buttons
4219 :group 'gnus-article-headers
4220 :type '(repeat (list (regexp :tag "Header")
4222 (integer :tag "Button")
4224 (function :tag "Callback")
4227 (integer :tag "Regexp group")))))
4229 (defvar gnus-button-regexp nil)
4230 (defvar gnus-button-marker-list nil)
4231 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4233 (defvar gnus-button-last nil)
4234 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4238 (defun gnus-article-push-button (event)
4239 "Check text under the mouse pointer for a callback function.
4240 If the text under the mouse pointer has a `gnus-callback' property,
4241 call it with the value of the `gnus-data' text property."
4243 (set-buffer (window-buffer (posn-window (event-start event))))
4244 (let* ((pos (posn-point (event-start event)))
4245 (data (get-text-property pos 'gnus-data))
4246 (fun (get-text-property pos 'gnus-callback)))
4249 (funcall fun data))))
4251 (defun gnus-article-press-button ()
4252 "Check text at point for a callback function.
4253 If the text at point has a `gnus-callback' property,
4254 call it with the value of the `gnus-data' text property."
4256 (let* ((data (get-text-property (point) 'gnus-data))
4257 (fun (get-text-property (point) 'gnus-callback)))
4259 (funcall fun data))))
4261 (defun gnus-article-highlight (&optional force)
4262 "Highlight current article.
4263 This function calls `gnus-article-highlight-headers',
4264 `gnus-article-highlight-citation',
4265 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4266 do the highlighting. See the documentation for those functions."
4267 (interactive (list 'force))
4268 (gnus-article-highlight-headers)
4269 (gnus-article-highlight-citation force)
4270 (gnus-article-highlight-signature)
4271 (gnus-article-add-buttons force)
4272 (gnus-article-add-buttons-to-head))
4274 (defun gnus-article-highlight-some (&optional force)
4275 "Highlight current article.
4276 This function calls `gnus-article-highlight-headers',
4277 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4278 do the highlighting. See the documentation for those functions."
4279 (interactive (list 'force))
4280 (gnus-article-highlight-headers)
4281 (gnus-article-highlight-signature)
4282 (gnus-article-add-buttons))
4284 (defun gnus-article-highlight-headers ()
4285 "Highlight article headers as specified by `gnus-header-face-alist'."
4288 (set-buffer gnus-article-buffer)
4290 (let ((alist gnus-header-face-alist)
4291 (buffer-read-only nil)
4292 (case-fold-search t)
4293 (inhibit-point-motion-hooks t)
4294 entry regexp header-face field-face from hpoints fpoints)
4295 (article-narrow-to-head)
4296 (while (setq entry (pop alist))
4297 (goto-char (point-min))
4298 (setq regexp (concat "^\\("
4299 (if (string-equal "" (nth 0 entry))
4303 header-face (nth 1 entry)
4304 field-face (nth 2 entry))
4305 (while (and (re-search-forward regexp nil t)
4309 (unless (search-forward ":" nil t)
4311 (when (and header-face
4312 (not (memq (point) hpoints)))
4313 (push (point) hpoints)
4314 (gnus-put-text-property from (point) 'face header-face))
4315 (when (and field-face
4316 (not (memq (setq from (point)) fpoints)))
4318 (if (re-search-forward "^[^ \t]" nil t)
4320 (goto-char (point-max)))
4321 (gnus-put-text-property from (point) 'face field-face))))))))
4323 (defun gnus-article-highlight-signature ()
4324 "Highlight the signature in an article.
4325 It does this by highlighting everything after
4326 `gnus-signature-separator' using `gnus-signature-face'."
4329 (set-buffer gnus-article-buffer)
4330 (let ((buffer-read-only nil)
4331 (inhibit-point-motion-hooks t))
4333 (when (and gnus-signature-face
4334 (gnus-article-narrow-to-signature))
4335 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4336 'face gnus-signature-face)
4338 (gnus-article-search-signature)
4339 (let ((start (match-beginning 0))
4340 (end (set-marker (make-marker) (1+ (match-end 0)))))
4341 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4344 (defun gnus-button-in-region-p (b e prop)
4345 "Say whether PROP exists in the region."
4346 (text-property-not-all b e prop nil))
4348 (defun gnus-article-add-buttons (&optional force)
4349 "Find external references in the article and make buttons of them.
4350 \"External references\" are things like Message-IDs and URLs, as
4351 specified by `gnus-button-alist'."
4352 (interactive (list 'force))
4354 (set-buffer gnus-article-buffer)
4355 (let ((buffer-read-only nil)
4356 (inhibit-point-motion-hooks t)
4357 (case-fold-search t)
4358 (alist gnus-button-alist)
4360 ;; Remove all old markers.
4361 (let (marker entry new-list)
4362 (while (setq marker (pop gnus-button-marker-list))
4363 (if (or (< marker (point-min)) (>= marker (point-max)))
4364 (push marker new-list)
4366 (when (setq entry (gnus-button-entry))
4367 (put-text-property (match-beginning (nth 1 entry))
4368 (match-end (nth 1 entry))
4369 'gnus-callback nil))
4370 (set-marker marker nil)))
4371 (setq gnus-button-marker-list new-list))
4372 ;; We skip the headers.
4375 (while (setq entry (pop alist))
4376 (setq regexp (car entry))
4378 (while (re-search-forward regexp nil t)
4379 (let* ((start (and entry (match-beginning (nth 1 entry))))
4380 (end (and entry (match-end (nth 1 entry))))
4381 (from (match-beginning 0)))
4382 (when (and (or (eq t (nth 2 entry))
4383 (eval (nth 2 entry)))
4384 (not (gnus-button-in-region-p
4385 start end 'gnus-callback)))
4386 ;; That optional form returned non-nil, so we add the
4388 (gnus-article-add-button
4389 start end 'gnus-button-push
4390 (car (push (set-marker (make-marker) from)
4391 gnus-button-marker-list))))))))))
4393 ;; Add buttons to the head of an article.
4394 (defun gnus-article-add-buttons-to-head ()
4395 "Add buttons to the head of the article."
4398 (set-buffer gnus-article-buffer)
4400 (let ((buffer-read-only nil)
4401 (inhibit-point-motion-hooks t)
4402 (case-fold-search t)
4403 (alist gnus-header-button-alist)
4405 (article-narrow-to-head)
4407 ;; Each alist entry.
4408 (setq entry (car alist)
4410 (goto-char (point-min))
4411 (while (re-search-forward (car entry) nil t)
4412 ;; Each header matching the entry.
4413 (setq beg (match-beginning 0))
4414 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4415 (match-beginning 0))
4418 (while (re-search-forward (nth 1 entry) end t)
4419 ;; Each match within a header.
4420 (let* ((entry (cdr entry))
4421 (start (match-beginning (nth 1 entry)))
4422 (end (match-end (nth 1 entry)))
4423 (form (nth 2 entry)))
4424 (goto-char (match-end 0))
4426 (gnus-article-add-button
4427 start end (nth 3 entry)
4428 (buffer-substring (match-beginning (nth 4 entry))
4429 (match-end (nth 4 entry)))))))
4430 (goto-char end)))))))
4432 ;;; External functions:
4434 (defun gnus-article-add-button (from to fun &optional data)
4435 "Create a button between FROM and TO with callback FUN and data DATA."
4436 (when gnus-article-button-face
4437 (gnus-overlay-put (gnus-make-overlay from to)
4438 'face gnus-article-button-face))
4439 (gnus-add-text-properties
4441 (nconc (and gnus-article-mouse-face
4442 (list gnus-mouse-face-prop gnus-article-mouse-face))
4443 (list 'gnus-callback fun)
4444 (and data (list 'gnus-data data))))
4445 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4446 :button-keymap gnus-widget-button-keymap))
4448 ;;; Internal functions:
4450 (defun gnus-article-set-globals ()
4452 (set-buffer gnus-summary-buffer)
4453 (gnus-set-global-variables)))
4455 (defun gnus-signature-toggle (end)
4457 (set-buffer gnus-article-buffer)
4458 (let ((buffer-read-only nil)
4459 (inhibit-point-motion-hooks t))
4460 (if (get-text-property end 'invisible)
4461 (gnus-article-unhide-text end (point-max))
4462 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4464 (defun gnus-button-entry ()
4465 ;; Return the first entry in `gnus-button-alist' matching this place.
4466 (let ((alist gnus-button-alist)
4469 (setq entry (pop alist))
4470 (if (looking-at (car entry))
4475 (defun gnus-button-push (marker)
4476 ;; Push button starting at MARKER.
4479 (let* ((entry (gnus-button-entry))
4480 (inhibit-point-motion-hooks t)
4482 (args (mapcar (lambda (group)
4483 (let ((string (match-string group)))
4484 (gnus-set-text-properties
4485 0 (length string) nil string)
4492 (fboundp (symbol-value fun)))
4493 (apply (symbol-value fun) args))
4495 (gnus-message 1 "You must define `%S' to use this button"
4496 (cons fun args)))))))
4498 (defun gnus-button-message-id (message-id)
4501 (set-buffer gnus-summary-buffer)
4502 (gnus-summary-refer-article message-id)))
4504 (defun gnus-button-fetch-group (address)
4505 "Fetch GROUP specified by ADDRESS."
4506 (if (not (string-match "[:/]" address))
4507 ;; This is just a simple group url.
4508 (gnus-group-read-ephemeral-group address gnus-select-method)
4509 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4511 (error "Can't parse %s" address)
4512 (gnus-group-read-ephemeral-group
4513 (match-string 4 address)
4514 `(nntp ,(match-string 1 address)
4515 (nntp-address ,(match-string 1 address))
4516 (nntp-port-number ,(if (match-end 3)
4517 (match-string 3 address)
4520 (defun gnus-url-parse-query-string (query &optional downcase)
4521 (let (retval pairs cur key val)
4522 (setq pairs (split-string query "&"))
4524 (setq cur (car pairs)
4526 (if (not (string-match "=" cur))
4528 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4529 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4531 (setq key (downcase key)))
4532 (setq cur (assoc key retval))
4534 (setcdr cur (cons val (cdr cur)))
4535 (setq retval (cons (list key val) retval)))))
4538 (defun gnus-url-unhex (x)
4545 (defun gnus-url-unhex-string (str &optional allow-newlines)
4546 "Remove %XXX embedded spaces, etc in a url.
4547 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4548 decoding of carriage returns and line feeds in the string, which is normally
4549 forbidden in URL encoding."
4550 (setq str (or str ""))
4552 (case-fold-search t))
4553 (while (string-match "%[0-9a-f][0-9a-f]" str)
4554 (let* ((start (match-beginning 0))
4555 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4557 (gnus-url-unhex (elt str (+ start 2))))))
4559 tmp (substring str 0 start)
4562 (char-to-string code))
4563 ((or (= code ?\n) (= code ?\r))
4565 (t (char-to-string code))))
4566 str (substring str (match-end 0)))))
4567 (setq tmp (concat tmp str))
4570 (defun gnus-url-mailto (url)
4571 ;; Send mail to someone
4572 (when (string-match "mailto:/*\\(.*\\)" url)
4573 (setq url (substring url (match-beginning 1) nil)))
4574 (let (to args subject func)
4575 (if (string-match (regexp-quote "?") url)
4576 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4577 args (gnus-url-parse-query-string
4578 (substring url (match-end 0) nil) t))
4579 (setq to (gnus-url-unhex-string url)))
4580 (setq args (cons (list "to" to) args)
4581 subject (cdr-safe (assoc "subject" args)))
4584 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4587 (message-position-on-field (caar args)))
4588 (insert (mapconcat 'identity (cdar args) ", "))
4589 (setq args (cdr args)))
4592 (message-goto-subject))))
4594 (defun gnus-button-mailto (address)
4596 (set-buffer (gnus-copy-article-buffer))
4597 (message-reply address))
4599 (defun gnus-button-reply (address)
4600 ;; Reply to ADDRESS.
4601 (message-reply address))
4603 (defun gnus-button-embedded-url (address)
4605 (browse-url (gnus-strip-whitespace address)))
4607 ;;; Next/prev buttons in the article buffer.
4609 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4610 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4612 (defvar gnus-prev-page-map nil)
4613 (unless gnus-prev-page-map
4614 (setq gnus-prev-page-map (make-sparse-keymap))
4615 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4616 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4618 (defun gnus-insert-prev-page-button ()
4619 (let ((buffer-read-only nil))
4621 gnus-prev-page-line-format nil
4622 `(gnus-prev t local-map ,gnus-prev-page-map
4623 gnus-callback gnus-article-button-prev-page
4624 article-type annotation))))
4626 (defvar gnus-next-page-map nil)
4627 (unless gnus-next-page-map
4628 (setq gnus-next-page-map (make-keymap))
4629 (suppress-keymap gnus-prev-page-map)
4630 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4631 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4633 (defun gnus-button-next-page ()
4634 "Go to the next page."
4636 (let ((win (selected-window)))
4637 (select-window (get-buffer-window gnus-article-buffer t))
4638 (gnus-article-next-page)
4639 (select-window win)))
4641 (defun gnus-button-prev-page ()
4642 "Go to the prev page."
4644 (let ((win (selected-window)))
4645 (select-window (get-buffer-window gnus-article-buffer t))
4646 (gnus-article-prev-page)
4647 (select-window win)))
4649 (defun gnus-insert-next-page-button ()
4650 (let ((buffer-read-only nil))
4651 (gnus-eval-format gnus-next-page-line-format nil
4653 t local-map ,gnus-next-page-map
4654 gnus-callback gnus-article-button-next-page
4655 article-type annotation))))
4657 (defun gnus-article-button-next-page (arg)
4658 "Go to the next page."
4660 (let ((win (selected-window)))
4661 (select-window (get-buffer-window gnus-article-buffer t))
4662 (gnus-article-next-page)
4663 (select-window win)))
4665 (defun gnus-article-button-prev-page (arg)
4666 "Go to the prev page."
4668 (let ((win (selected-window)))
4669 (select-window (get-buffer-window gnus-article-buffer t))
4670 (gnus-article-prev-page)
4671 (select-window win)))
4673 (defvar gnus-decode-header-methods
4674 '(mail-decode-encoded-word-region)
4675 "List of methods used to decode headers.
4677 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4678 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4679 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4680 whose names match REGEXP.
4683 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4684 mail-decode-encoded-word-region
4685 (\"chinese\" . rfc1843-decode-region))
4688 (defvar gnus-decode-header-methods-cache nil)
4690 (defun gnus-multi-decode-header (start end)
4691 "Apply the functions from `gnus-encoded-word-methods' that match."
4692 (unless (and gnus-decode-header-methods-cache
4693 (eq gnus-newsgroup-name
4694 (car gnus-decode-header-methods-cache)))
4695 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4698 (nconc gnus-decode-header-methods-cache (list x))
4699 (if (and gnus-newsgroup-name
4700 (string-match (car x) gnus-newsgroup-name))
4701 (nconc gnus-decode-header-methods-cache
4703 gnus-decode-header-methods))
4704 (let ((xlist gnus-decode-header-methods-cache))
4707 (narrow-to-region start end)
4709 (funcall (pop xlist) (point-min) (point-max))))))
4712 ;;; Treatment top-level handling.
4715 (defun gnus-treat-article (condition &optional part-number total-parts type)
4716 (let ((length (- (point-max) (point-min)))
4717 (alist gnus-treatment-function-alist)
4718 (article-goto-body-goes-to-point-min-p t)
4722 (let ((list gnus-article-treat-types))
4724 (when (string-match (pop list) type)
4725 (throw 'found t)))))))
4726 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4728 (gnus-run-hooks 'gnus-part-display-hook)
4729 (while (setq elem (pop alist))
4732 (if (gnus-buffer-live-p gnus-summary-buffer)
4733 (set-buffer gnus-summary-buffer))
4734 (symbol-value (car elem))))
4735 (when (and (or (consp val)
4737 (gnus-treat-predicate val)
4738 (or (not (get (car elem) 'highlight))
4741 (funcall (cadr elem)))))))
4743 ;; Dynamic variables.
4744 (defvar part-number)
4745 (defvar total-parts)
4749 (defun gnus-treat-predicate (val)
4754 (stringp (car val)))
4755 (apply 'gnus-or (mapcar `(lambda (s)
4756 (string-match s ,(or gnus-newsgroup-name "")))
4759 (let ((pred (pop val)))
4762 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4764 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4766 (not (gnus-treat-predicate (car val))))
4768 (equal (car val) type))
4770 (error "%S is not a valid predicate" pred)))))
4778 (eq part-number total-parts))
4782 (error "%S is not a valid value" val))))
4788 (run-hooks 'gnus-art-load-hook)
4790 ;;; gnus-art.el ends here