1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
31 (eval-when-compile (require 'static))
42 ;; Avoid byte-compile warnings.
51 (defgroup gnus-article nil
53 :link '(custom-manual "(gnus)The Article Buffer")
56 (defgroup gnus-article-treat nil
57 "Treating article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-hiding nil
62 "Hiding article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-highlight nil
67 "Article highlighting."
68 :link '(custom-manual "(gnus)Article Highlighting")
72 (defgroup gnus-article-signature nil
74 :link '(custom-manual "(gnus)Article Signature")
77 (defgroup gnus-article-headers nil
79 :link '(custom-manual "(gnus)Hiding Headers")
82 (defgroup gnus-article-washing nil
83 "Special commands on articles."
84 :link '(custom-manual "(gnus)Article Washing")
87 (defgroup gnus-article-emphasis nil
88 "Fontisizing articles."
89 :link '(custom-manual "(gnus)Article Fontisizing")
92 (defgroup gnus-article-saving nil
94 :link '(custom-manual "(gnus)Saving Articles")
97 (defgroup gnus-article-mime nil
98 "Worshiping the MIME wonder."
99 :link '(custom-manual "(gnus)Using MIME")
100 :group 'gnus-article)
102 (defgroup gnus-article-buttons nil
103 "Pushable buttons in the article buffer."
104 :link '(custom-manual "(gnus)Article Buttons")
105 :group 'gnus-article)
107 (defgroup gnus-article-various nil
108 "Other article options."
109 :link '(custom-manual "(gnus)Misc Article")
110 :group 'gnus-article)
112 (defcustom gnus-ignored-headers
113 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
114 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
115 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
116 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
117 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
118 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
119 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
120 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
121 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
122 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
123 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
124 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
125 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
126 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
127 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
128 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
129 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
130 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
131 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
132 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
133 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
134 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
135 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
136 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
137 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
138 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
139 "^X-Received:" "^Content-length:" "X-precedence:")
140 "*All headers that start with this regexp will be hidden.
141 This variable can also be a list of regexps of headers to be ignored.
142 If `gnus-visible-headers' is non-nil, this variable will be ignored."
143 :type '(choice :custom-show nil
146 :group 'gnus-article-hiding)
148 (defcustom gnus-visible-headers
149 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
150 "*All headers that do not match this regexp will be hidden.
151 This variable can also be a list of regexp of headers to remain visible.
152 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
153 :type '(repeat :value-to-internal (lambda (widget value)
154 (custom-split-regexp-maybe value))
155 :match (lambda (widget value)
157 (widget-editable-list-match widget value)))
159 :group 'gnus-article-hiding)
161 (defcustom gnus-sorted-header-list
162 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
163 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
164 "*This variable is a list of regular expressions.
165 If it is non-nil, headers that match the regular expressions will
166 be placed first in the article buffer in the sequence specified by
168 :type '(repeat regexp)
169 :group 'gnus-article-hiding)
171 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
172 "Headers that are only to be displayed if they have interesting data.
173 Possible values in this list are `empty', `newsgroups', `followup-to',
174 `reply-to', `date', `long-to', and `many-to'."
175 :type '(set (const :tag "Headers with no content." empty)
176 (const :tag "Newsgroups with only one group." newsgroups)
177 (const :tag "Followup-to identical to newsgroups." followup-to)
178 (const :tag "Reply-to identical to from." reply-to)
179 (const :tag "Date less than four days old." date)
180 (const :tag "Very long To and/or Cc header." long-to)
181 (const :tag "Multiple To and/or Cc headers." many-to))
182 :group 'gnus-article-hiding)
184 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
185 "Regexp matching signature separator.
186 This can also be a list of regexps. In that case, it will be checked
187 from head to tail looking for a separator. Searches will be done from
188 the end of the buffer."
189 :type '(repeat string)
190 :group 'gnus-article-signature)
192 (defcustom gnus-signature-limit nil
193 "Provide a limit to what is considered a signature.
194 If it is a number, no signature may not be longer (in characters) than
195 that number. If it is a floating point number, no signature may be
196 longer (in lines) than that number. If it is a function, the function
197 will be called without any parameters, and if it returns nil, there is
198 no signature in the buffer. If it is a string, it will be used as a
199 regexp. If it matches, the text in question is not a signature."
200 :type '(choice (integer :value 200)
202 (function :value fun)
203 (regexp :value ".*"))
204 :group 'gnus-article-signature)
206 (defcustom gnus-hidden-properties '(invisible t intangible t)
207 "Property list to use for hiding text."
209 :group 'gnus-article-hiding)
211 (defcustom gnus-article-x-face-command
213 ;; Fixme: This isn't the right thing for mixed graphical and and
214 ;; non-graphical frames in a session.
215 ;; gnus-xmas.el overrides this for XEmacs.
216 ((and (fboundp 'image-type-available-p)
217 (image-type-available-p 'xbm))
218 'gnus-article-display-xface)
219 ((and (not gnus-xemacs)
221 (module-installed-p 'x-face-mule))
222 'x-face-mule-gnus-article-display-x-face)
224 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"))
225 "*String or function to be executed to display an X-Face header.
226 If it is a string, the command will be executed in a sub-shell
227 asynchronously. The compressed face will be piped to this command."
228 :type '(choice string
229 (function-item gnus-article-display-xface)
230 (function-item x-face-mule-gnus-article-display-x-face)
232 :group 'gnus-article-washing)
234 (defcustom gnus-article-x-face-too-ugly nil
235 "Regexp matching posters whose face shouldn't be shown automatically."
236 :type '(choice regexp (const nil))
237 :group 'gnus-article-washing)
239 (defcustom gnus-emphasis-alist
241 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
243 '(("_" "_" underline)
246 ("_/" "/_" underline-italic)
247 ("_\\*" "\\*_" underline-bold)
248 ("\\*/" "/\\*" bold-italic)
249 ("_\\*/" "/\\*_" underline-bold-italic))))
250 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
251 2 3 gnus-emphasis-underline)
255 (format format (car spec) (car (cdr spec)))
256 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
258 "*Alist that says how to fontify certain phrases.
259 Each item looks like this:
261 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
263 The first element is a regular expression to be matched. The second
264 is a number that says what regular expression grouping used to find
265 the entire emphasized word. The third is a number that says what
266 regexp grouping should be displayed and highlighted. The fourth
267 is the face used for highlighting."
268 :type '(repeat (list :value ("" 0 0 default)
270 (integer :tag "Match group")
271 (integer :tag "Emphasize group")
273 :group 'gnus-article-emphasis)
275 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
276 "A regexp to describe whitespace which should not be emphasized.
277 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
278 The former avoids underlining of leading and trailing whitespace,
279 and the latter avoids underlining any whitespace at all."
280 :group 'gnus-article-emphasis
283 (defface gnus-emphasis-bold '((t (:bold t)))
284 "Face used for displaying strong emphasized text (*word*)."
285 :group 'gnus-article-emphasis)
287 (defface gnus-emphasis-italic '((t (:italic t)))
288 "Face used for displaying italic emphasized text (/word/)."
289 :group 'gnus-article-emphasis)
291 (defface gnus-emphasis-underline '((t (:underline t)))
292 "Face used for displaying underlined emphasized text (_word_)."
293 :group 'gnus-article-emphasis)
295 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
296 "Face used for displaying underlined bold emphasized text (_*word*_)."
297 :group 'gnus-article-emphasis)
299 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
300 "Face used for displaying underlined italic emphasized text (_/word/_)."
301 :group 'gnus-article-emphasis)
303 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
304 "Face used for displaying bold italic emphasized text (/*word*/)."
305 :group 'gnus-article-emphasis)
307 (defface gnus-emphasis-underline-bold-italic
308 '((t (:bold t :italic t :underline t)))
309 "Face used for displaying underlined bold italic emphasized text.
310 Esample: (_/*word*/_)."
311 :group 'gnus-article-emphasis)
313 (defface gnus-emphasis-highlight-words
314 '((t (:background "black" :foreground "yellow")))
315 "Face used for displaying highlighted words."
316 :group 'gnus-article-emphasis)
318 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
319 "Format for display of Date headers in article bodies.
320 See `format-time-string' for the possible values.
322 The variable can also be function, which should return a complete Date
323 header. The function is called with one argument, the time, which can
324 be fed to `format-time-string'."
325 :type '(choice string symbol)
326 :link '(custom-manual "(gnus)Article Date")
327 :group 'gnus-article-washing)
330 (autoload 'mail-extract-address-components "mail-extr"))
332 (defcustom gnus-save-all-headers t
333 "*If non-nil, don't remove any headers before saving."
334 :group 'gnus-article-saving
337 (defcustom gnus-prompt-before-saving 'always
338 "*This variable says how much prompting is to be done when saving articles.
339 If it is nil, no prompting will be done, and the articles will be
340 saved to the default files. If this variable is `always', each and
341 every article that is saved will be preceded by a prompt, even when
342 saving large batches of articles. If this variable is neither nil not
343 `always', there the user will be prompted once for a file name for
344 each invocation of the saving commands."
345 :group 'gnus-article-saving
346 :type '(choice (item always)
347 (item :tag "never" nil)
348 (sexp :tag "once" :format "%t\n" :value t)))
350 (defcustom gnus-saved-headers gnus-visible-headers
351 "Headers to keep if `gnus-save-all-headers' is nil.
352 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
353 If that variable is nil, however, all headers that match this regexp
354 will be kept while the rest will be deleted before saving."
355 :group 'gnus-article-saving
358 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
359 "A function to save articles in your favourite format.
360 The function must be interactively callable (in other words, it must
361 be an Emacs command).
363 Gnus provides the following functions:
365 * gnus-summary-save-in-rmail (Rmail format)
366 * gnus-summary-save-in-mail (Unix mail format)
367 * gnus-summary-save-in-folder (MH folder)
368 * gnus-summary-save-in-file (article format)
369 * gnus-summary-save-in-vm (use VM's folder format)
370 * gnus-summary-write-to-file (article format -- overwrite)."
371 :group 'gnus-article-saving
372 :type '(radio (function-item gnus-summary-save-in-rmail)
373 (function-item gnus-summary-save-in-mail)
374 (function-item gnus-summary-save-in-folder)
375 (function-item gnus-summary-save-in-file)
376 (function-item gnus-summary-save-in-vm)
377 (function-item gnus-summary-write-to-file)))
379 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
380 "A function generating a file name to save articles in Rmail format.
381 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
382 :group 'gnus-article-saving
385 (defcustom gnus-mail-save-name 'gnus-plain-save-name
386 "A function generating a file name to save articles in Unix mail format.
387 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
388 :group 'gnus-article-saving
391 (defcustom gnus-folder-save-name 'gnus-folder-save-name
392 "A function generating a file name to save articles in MH folder.
393 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
394 :group 'gnus-article-saving
397 (defcustom gnus-file-save-name 'gnus-numeric-save-name
398 "A function generating a file name to save articles in article format.
399 The function is called with NEWSGROUP, HEADERS, and optional
401 :group 'gnus-article-saving
404 (defcustom gnus-split-methods
405 '((gnus-article-archive-name)
406 (gnus-article-nndoc-name))
407 "*Variable used to suggest where articles are to be saved.
408 For instance, if you would like to save articles related to Gnus in
409 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
410 you could set this variable to something like:
412 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
413 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
415 This variable is an alist where the where the key is the match and the
416 value is a list of possible files to save in if the match is non-nil.
418 If the match is a string, it is used as a regexp match on the
419 article. If the match is a symbol, that symbol will be funcalled
420 from the buffer of the article to be saved with the newsgroup as the
421 parameter. If it is a list, it will be evaled in the same buffer.
423 If this form or function returns a string, this string will be used as
424 a possible file name; and if it returns a non-nil list, that list will
425 be used as possible file names."
426 :group 'gnus-article-saving
427 :type '(repeat (choice (list :value (fun) function)
428 (cons :value ("" "") regexp (repeat string))
431 (defcustom gnus-article-display-method-for-mime
432 'gnus-article-display-mime-message
433 "Function to display a MIME message.
434 The function is called from the article buffer."
435 :group 'gnus-article-mime
438 (defcustom gnus-article-display-method-for-traditional
439 'gnus-article-display-traditional-message
440 "*Function to display a traditional message.
441 The function is called from the article buffer."
442 :group 'gnus-article-mime
445 (defcustom gnus-page-delimiter "^\^L"
446 "*Regexp describing what to use as article page delimiters.
447 The default value is \"^\^L\", which is a form linefeed at the
448 beginning of a line."
450 :group 'gnus-article-various)
452 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
453 "*The format specification for the article mode line.
454 See `gnus-summary-mode-line-format' for a closer description.
456 The following additional specs are available:
458 %w The article washing status.
459 %m The number of MIME parts in the article."
461 :group 'gnus-article-various)
463 (defcustom gnus-article-mode-hook nil
464 "*A hook for Gnus article mode."
466 :group 'gnus-article-various)
468 (defcustom gnus-article-menu-hook nil
469 "*Hook run after the creation of the article mode menu."
471 :group 'gnus-article-various)
473 (defcustom gnus-article-prepare-hook nil
474 "*A hook called after an article has been prepared in the article buffer."
476 :group 'gnus-article-various)
478 (defcustom gnus-article-hide-pgp-hook nil
479 "*A hook called after successfully hiding a PGP signature."
481 :group 'gnus-article-various)
483 (defcustom gnus-article-button-face 'bold
484 "Face used for highlighting buttons in the article buffer.
486 An article button is a piece of text that you can activate by pressing
487 `RET' or `mouse-2' above it."
489 :group 'gnus-article-buttons)
491 (defcustom gnus-article-mouse-face 'highlight
492 "Face used for mouse highlighting in the article buffer.
494 Article buttons will be displayed in this face when the cursor is
497 :group 'gnus-article-buttons)
499 (defcustom gnus-signature-face 'gnus-signature-face
500 "Face used for highlighting a signature in the article buffer.
501 Obsolete; use the face `gnus-signature-face' for customizations instead."
503 :group 'gnus-article-highlight
504 :group 'gnus-article-signature)
506 (defface gnus-signature-face
508 "Face used for highlighting a signature in the article buffer."
509 :group 'gnus-article-highlight
510 :group 'gnus-article-signature)
512 (defface gnus-header-from-face
515 (:foreground "spring green"))
518 (:foreground "red3"))
521 "Face used for displaying from headers."
522 :group 'gnus-article-headers
523 :group 'gnus-article-highlight)
525 (defface gnus-header-subject-face
528 (:foreground "SeaGreen3"))
531 (:foreground "red4"))
533 (:bold t :italic t)))
534 "Face used for displaying subject headers."
535 :group 'gnus-article-headers
536 :group 'gnus-article-highlight)
538 (defface gnus-header-newsgroups-face
541 (:foreground "yellow" :italic t))
544 (:foreground "MidnightBlue" :italic t))
547 "Face used for displaying newsgroups headers."
548 :group 'gnus-article-headers
549 :group 'gnus-article-highlight)
551 (defface gnus-header-name-face
554 (:foreground "SeaGreen"))
557 (:foreground "maroon"))
560 "Face used for displaying header names."
561 :group 'gnus-article-headers
562 :group 'gnus-article-highlight)
564 (defface gnus-header-content-face
567 (:foreground "forest green" :italic t))
570 (:foreground "indianred4" :italic t))
572 (:italic t))) "Face used for displaying header content."
573 :group 'gnus-article-headers
574 :group 'gnus-article-highlight)
576 (defcustom gnus-header-face-alist
577 '(("From" nil gnus-header-from-face)
578 ("Subject" nil gnus-header-subject-face)
579 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
580 ("" gnus-header-name-face gnus-header-content-face))
581 "*Controls highlighting of article header.
583 An alist of the form (HEADER NAME CONTENT).
585 HEADER is a regular expression which should match the name of an
586 header header and NAME and CONTENT are either face names or nil.
588 The name of each header field will be displayed using the face
589 specified by the first element in the list where HEADER match the
590 header name and NAME is non-nil. Similarly, the content will be
591 displayed by the first non-nil matching CONTENT face."
592 :group 'gnus-article-headers
593 :group 'gnus-article-highlight
594 :type '(repeat (list (regexp :tag "Header")
596 (item :tag "skip" nil)
597 (face :value default))
598 (choice :tag "Content"
599 (item :tag "skip" nil)
600 (face :value default)))))
602 (defcustom gnus-article-decode-hook nil
603 "*Hook run to decode charsets in articles."
604 :group 'gnus-article-headers
607 (defcustom gnus-display-mime-function 'gnus-display-mime
608 "Function to display MIME articles."
609 :group 'gnus-article-mime
612 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
613 "Function used to decode headers.")
615 (defvar gnus-article-dumbquotes-map
633 "Table for MS-to-Latin1 translation.")
635 (defcustom gnus-ignored-mime-types nil
636 "List of MIME types that should be ignored by Gnus."
637 :group 'gnus-article-mime
638 :type '(repeat regexp))
640 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
641 "List of MIME types that should not be given buttons when rendered inline."
642 :group 'gnus-article-mime
643 :type '(repeat regexp))
645 (defcustom gnus-article-mime-part-function nil
646 "Function called with a MIME handle as the argument.
647 This is meant for people who want to do something automatic based
648 on parts -- for instance, adding Vcard info to a database."
649 :group 'gnus-article-mime
652 (defcustom gnus-mime-multipart-functions nil
653 "An alist of MIME types to functions to display them.")
655 (defcustom gnus-article-date-lapsed-new-header nil
656 "Whether the X-Sent and Date headers can coexist.
657 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
658 either replace the old \"Date:\" header (if this variable is nil), or
659 be added below it (otherwise)."
660 :group 'gnus-article-headers
663 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
664 "Function called with a MIME handle as the argument.
665 This is meant for people who want to view first matched part.
666 For `undisplayed-alternative' (default), the first undisplayed
667 part or alternative part is used. For `undisplayed', the first
668 undisplayed part is used. For a function, the first part which
669 the function return `t' is used. For `nil', the first part is
671 :group 'gnus-article-mime
673 (item :tag "first" :value nil)
674 (item :tag "undisplayed" :value undisplayed)
675 (item :tag "undisplayed or alternative"
676 :value undisplayed-alternative)
680 ;;; The treatment variables
683 (defvar gnus-part-display-hook nil
684 "Hook called on parts that are to receive treatment.")
686 (defvar gnus-article-treat-custom
687 '(choice (const :tag "Off" nil)
689 (const :tag "Header" head)
690 (const :tag "Last" last)
691 (const :tag "Mime" mime)
692 (integer :tag "Less")
693 (repeat :tag "Groups" regexp)
694 (sexp :tag "Predicate")))
696 (defvar gnus-article-treat-head-custom
697 '(choice (const :tag "Off" nil)
698 (const :tag "Header" head)))
700 (defvar gnus-article-treat-types '("text/plain")
703 (defvar gnus-inhibit-treatment nil
704 "Whether to inhibit treatment.")
706 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
707 "Highlight the signature.
708 Valid values are nil, t, `head', `last', an integer or a predicate.
709 See the manual for details."
710 :group 'gnus-article-treat
711 :type gnus-article-treat-custom)
712 (put 'gnus-treat-highlight-signature 'highlight t)
714 (defcustom gnus-treat-buttonize 100000
716 Valid values are nil, t, `head', `last', an integer or a predicate.
717 See the manual for details."
718 :group 'gnus-article-treat
719 :type gnus-article-treat-custom)
720 (put 'gnus-treat-buttonize 'highlight t)
722 (defcustom gnus-treat-buttonize-head 'head
723 "Add buttons to the head.
724 Valid values are nil, t, `head', `last', an integer or a predicate.
725 See the manual for details."
726 :group 'gnus-article-treat
727 :type gnus-article-treat-head-custom)
728 (put 'gnus-treat-buttonize-head 'highlight t)
730 (defcustom gnus-treat-emphasize nil
732 Valid values are nil, t, `head', `last', an integer or a predicate.
733 See the manual for details."
734 :group 'gnus-article-treat
735 :type gnus-article-treat-custom)
736 (put 'gnus-treat-emphasize 'highlight t)
738 (defcustom gnus-treat-strip-cr nil
739 "Remove carriage returns.
740 Valid values are nil, t, `head', `last', an integer or a predicate.
741 See the manual for details."
742 :group 'gnus-article-treat
743 :type gnus-article-treat-custom)
745 (defcustom gnus-treat-hide-headers 'head
747 Valid values are nil, t, `head', `last', an integer or a predicate.
748 See the manual for details."
749 :group 'gnus-article-treat
750 :type gnus-article-treat-head-custom)
752 (defcustom gnus-treat-hide-boring-headers nil
753 "Hide boring headers.
754 Valid values are nil, t, `head', `last', an integer or a predicate.
755 See the manual for details."
756 :group 'gnus-article-treat
757 :type gnus-article-treat-head-custom)
759 (defcustom gnus-treat-hide-signature nil
761 Valid values are nil, t, `head', `last', an integer or a predicate.
762 See the manual for details."
763 :group 'gnus-article-treat
764 :type gnus-article-treat-custom)
766 (defcustom gnus-treat-fill-article nil
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770 :group 'gnus-article-treat
771 :type gnus-article-treat-custom)
773 (defcustom gnus-treat-hide-citation nil
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-custom)
780 (defcustom gnus-treat-strip-list-identifiers 'head
781 "Strip list identifiers from `gnus-list-identifiers`.
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784 :group 'gnus-article-treat
785 :type gnus-article-treat-custom)
787 (defcustom gnus-treat-strip-pgp t
788 "Strip PGP signatures.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-custom)
794 (defcustom gnus-treat-strip-pem nil
795 "Strip PEM signatures.
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798 :group 'gnus-article-treat
799 :type gnus-article-treat-custom)
801 (defcustom gnus-treat-strip-banner t
802 "Strip banners from articles.
803 The banner to be stripped is specified in the `banner' group parameter.
804 Valid values are nil, t, `head', `last', an integer or a predicate.
805 See the manual for details."
806 :group 'gnus-article-treat
807 :type gnus-article-treat-custom)
809 (defcustom gnus-treat-highlight-headers 'head
810 "Highlight the headers.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-head-custom)
815 (put 'gnus-treat-highlight-headers 'highlight t)
817 (defcustom gnus-treat-highlight-citation t
818 "Highlight cited text.
819 Valid values are nil, t, `head', `last', an integer or a predicate.
820 See the manual for details."
821 :group 'gnus-article-treat
822 :type gnus-article-treat-custom)
823 (put 'gnus-treat-highlight-citation 'highlight t)
825 (defcustom gnus-treat-date-ut nil
826 "Display the Date in UT (GMT).
827 Valid values are nil, t, `head', `last', an integer or a predicate.
828 See the manual for details."
829 :group 'gnus-article-treat
830 :type gnus-article-treat-head-custom)
832 (defcustom gnus-treat-date-local nil
833 "Display the Date in the local timezone.
834 Valid values are nil, t, `head', `last', an integer or a predicate.
835 See the manual for details."
836 :group 'gnus-article-treat
837 :type gnus-article-treat-head-custom)
839 (defcustom gnus-treat-date-lapsed nil
840 "Display the Date header in a way that says how much time has elapsed.
841 Valid values are nil, t, `head', `last', an integer or a predicate.
842 See the manual for details."
843 :group 'gnus-article-treat
844 :type gnus-article-treat-head-custom)
846 (defcustom gnus-treat-date-original nil
847 "Display the date in the original timezone.
848 Valid values are nil, t, `head', `last', an integer or a predicate.
849 See the manual for details."
850 :group 'gnus-article-treat
851 :type gnus-article-treat-head-custom)
853 (defcustom gnus-treat-date-iso8601 nil
854 "Display the date in the ISO8601 format.
855 Valid values are nil, t, `head', `last', an integer or a predicate.
856 See the manual for details."
857 :group 'gnus-article-treat
858 :type gnus-article-treat-head-custom)
860 (defcustom gnus-treat-date-user-defined nil
861 "Display the date in a user-defined format.
862 The format is defined by the `gnus-article-time-format' variable.
863 Valid values are nil, t, `head', `last', an integer or a predicate.
864 See the manual for details."
865 :group 'gnus-article-treat
866 :type gnus-article-treat-head-custom)
868 (defcustom gnus-treat-strip-headers-in-body t
869 "Strip the X-No-Archive header line from the beginning of the body.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See the manual for details."
872 :group 'gnus-article-treat
873 :type gnus-article-treat-custom)
875 (defcustom gnus-treat-strip-trailing-blank-lines nil
876 "Strip trailing blank lines.
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See the manual for details."
879 :group 'gnus-article-treat
880 :type gnus-article-treat-custom)
882 (defcustom gnus-treat-strip-leading-blank-lines nil
883 "Strip leading blank lines.
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See the manual for details."
886 :group 'gnus-article-treat
887 :type gnus-article-treat-custom)
889 (defcustom gnus-treat-strip-multiple-blank-lines nil
890 "Strip multiple blank lines.
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See the manual for details."
893 :group 'gnus-article-treat
894 :type gnus-article-treat-custom)
896 (defcustom gnus-treat-overstrike t
897 "Treat overstrike highlighting.
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See the manual for details."
900 :group 'gnus-article-treat
901 :type gnus-article-treat-custom)
902 (put 'gnus-treat-overstrike 'highlight t)
904 (defcustom gnus-treat-display-xface
905 (and (or (and (fboundp 'image-type-available-p)
906 (image-type-available-p 'xbm))
907 (and gnus-xemacs (featurep 'xface))
908 (eq 'x-face-mule-gnus-article-display-x-face
909 gnus-article-x-face-command))
911 "Display X-Face headers.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
914 :group 'gnus-article-treat
915 :type gnus-article-treat-head-custom)
916 (put 'gnus-treat-display-xface 'highlight t)
918 (defcustom gnus-treat-display-smileys
919 (if (or (and gnus-xemacs (featurep 'xpm))
920 (and (not gnus-xemacs)
922 (module-installed-p 'gnus-bitmap)))
926 Valid values are nil, t, `head', `last', an integer or a predicate.
927 See the manual for details."
928 :group 'gnus-article-treat
929 :type gnus-article-treat-custom)
930 (put 'gnus-treat-display-smileys 'highlight t)
932 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head 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-head-custom)
938 (put 'gnus-treat-display-picons 'highlight t)
940 (defcustom gnus-treat-capitalize-sentences nil
941 "Capitalize sentence-starting words.
942 Valid values are nil, t, `head', `last', an integer or a predicate.
943 See the manual for details."
944 :group 'gnus-article-treat
945 :type gnus-article-treat-custom)
947 (defcustom gnus-treat-fill-long-lines nil
949 Valid values are nil, t, `head', `last', an integer or a predicate.
950 See the manual for details."
951 :group 'gnus-article-treat
952 :type gnus-article-treat-custom)
954 (defcustom gnus-treat-play-sounds nil
956 Valid values are nil, t, `head', `last', an integer or a predicate.
957 See the manual for details."
958 :group 'gnus-article-treat
959 :type gnus-article-treat-custom)
961 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
962 "Decode an article as `default-mime-charset'. For instance, if you want to
963 attempt to decode an article even if the value of `gnus-show-mime' is nil,
964 you could set this variable to something like: nil for don't decode, t for
965 decode the body, '(or header t) for the whole article, etc."
966 :group 'gnus-article-treat
967 :type '(radio (const :tag "Off" nil)
968 (const :tag "Decode body" t)
969 (const :tag "Decode all" (or head t))))
971 (defcustom gnus-treat-translate nil
972 "Translate articles from one language to another.
973 Valid values are nil, t, `head', `last', an integer or a predicate.
974 See the manual for details."
975 :group 'gnus-article-treat
976 :type gnus-article-treat-custom)
978 ;;; Internal variables
980 (defvar article-goto-body-goes-to-point-min-p nil)
981 (defvar gnus-article-wash-types nil)
982 (defvar gnus-article-emphasis-alist nil)
984 (defvar gnus-article-mime-handle-alist-1 nil)
985 (defvar gnus-treatment-function-alist
986 '((gnus-treat-decode-article-as-default-mime-charset
987 gnus-article-decode-article-as-default-mime-charset)
988 (gnus-treat-strip-banner gnus-article-strip-banner)
989 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
990 (gnus-treat-buttonize gnus-article-add-buttons)
991 (gnus-treat-fill-article gnus-article-fill-cited-article)
992 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
993 (gnus-treat-strip-cr gnus-article-remove-cr)
994 (gnus-treat-display-xface gnus-article-display-x-face)
995 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
996 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
997 (gnus-treat-hide-signature gnus-article-hide-signature)
998 (gnus-treat-hide-citation gnus-article-hide-citation)
999 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1000 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1001 (gnus-treat-strip-pem gnus-article-hide-pem)
1002 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1003 (gnus-treat-emphasize gnus-article-emphasize)
1004 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1005 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1006 (gnus-treat-date-ut gnus-article-date-ut)
1007 (gnus-treat-date-local gnus-article-date-local)
1008 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1009 (gnus-treat-date-original gnus-article-date-original)
1010 (gnus-treat-date-user-defined gnus-article-date-user)
1011 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1012 (gnus-treat-strip-trailing-blank-lines
1013 gnus-article-remove-trailing-blank-lines)
1014 (gnus-treat-strip-leading-blank-lines
1015 gnus-article-strip-leading-blank-lines)
1016 (gnus-treat-strip-multiple-blank-lines
1017 gnus-article-strip-multiple-blank-lines)
1018 (gnus-treat-overstrike gnus-article-treat-overstrike)
1019 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1020 (gnus-treat-display-smileys gnus-article-smiley-display)
1021 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1022 (gnus-treat-display-picons gnus-article-display-picons)
1023 (gnus-treat-play-sounds gnus-earcon-display)))
1025 (defvar gnus-article-mime-handle-alist nil)
1026 (defvar article-lapsed-timer nil)
1027 (defvar gnus-article-current-summary nil)
1029 (defvar gnus-article-mode-syntax-table
1030 (let ((table (copy-syntax-table text-mode-syntax-table)))
1031 (modify-syntax-entry ?- "w" table)
1032 (modify-syntax-entry ?> ")" table)
1033 (modify-syntax-entry ?< "(" table)
1035 "Syntax table used in article mode buffers.
1036 Initialized from `text-mode-syntax-table.")
1038 (defvar gnus-save-article-buffer nil)
1040 (defvar gnus-article-mode-line-format-alist
1041 (nconc '((?w (gnus-article-wash-status) ?s)
1042 (?m (gnus-article-mime-part-status) ?s))
1043 gnus-summary-mode-line-format-alist))
1045 (defvar gnus-number-of-articles-to-be-saved nil)
1047 (defvar gnus-inhibit-hiding nil)
1049 (defsubst gnus-article-hide-text (b e props)
1050 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1051 (add-text-properties b e props)
1052 (when (memq 'intangible props)
1054 (max (1- b) (point-min))
1055 b 'intangible (cddr (memq 'intangible props)))))
1056 (defsubst gnus-article-unhide-text (b e)
1057 "Remove hidden text properties from region between B and E."
1058 (remove-text-properties b e gnus-hidden-properties)
1059 (when (memq 'intangible gnus-hidden-properties)
1060 (put-text-property (max (1- b) (point-min))
1061 b 'intangible nil)))
1063 (defun gnus-article-hide-text-type (b e type)
1064 "Hide text of TYPE between B and E."
1065 (push type gnus-article-wash-types)
1066 (gnus-article-hide-text
1067 b e (cons 'article-type (cons type gnus-hidden-properties))))
1069 (defun gnus-article-unhide-text-type (b e type)
1070 "Unhide text of TYPE between B and E."
1071 (setq gnus-article-wash-types
1072 (delq type gnus-article-wash-types))
1073 (remove-text-properties
1074 b e (cons 'article-type (cons type gnus-hidden-properties)))
1075 (when (memq 'intangible gnus-hidden-properties)
1076 (put-text-property (max (1- b) (point-min))
1077 b 'intangible nil)))
1079 (defun gnus-article-hide-text-of-type (type)
1080 "Hide text of TYPE in the current buffer."
1082 (let ((b (point-min))
1084 (while (setq b (text-property-any b e 'article-type type))
1085 (add-text-properties b (incf b) gnus-hidden-properties)))))
1087 (defun gnus-article-delete-text-of-type (type)
1088 "Delete text of TYPE in the current buffer."
1090 (let ((b (point-min)))
1091 (while (setq b (text-property-any b (point-max) 'article-type type))
1093 b (or (text-property-not-all b (point-max) 'article-type type)
1096 (defun gnus-article-delete-invisible-text ()
1097 "Delete all invisible text in the current buffer."
1099 (let ((b (point-min)))
1100 (while (setq b (text-property-any b (point-max) 'invisible t))
1102 b (or (text-property-not-all b (point-max) 'invisible t)
1105 (defun gnus-article-text-type-exists-p (type)
1106 "Say whether any text of type TYPE exists in the buffer."
1107 (text-property-any (point-min) (point-max) 'article-type type))
1109 (defsubst gnus-article-header-rank ()
1110 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1111 (let ((list gnus-sorted-header-list)
1114 (when (looking-at (car list))
1116 (setq list (cdr list))
1120 (defun article-hide-headers (&optional arg delete)
1121 "Hide unwanted headers and possibly sort them as well."
1122 (interactive (gnus-article-hidden-arg))
1123 ;; Lars said that this function might be inhibited.
1124 (if (gnus-article-check-hidden-text 'headers arg)
1126 ;; Show boring headers as well.
1127 (gnus-article-show-hidden-text 'boring-headers)
1128 (when (eq 1 (point-min))
1129 (set-window-start (get-buffer-window (current-buffer)) 1)))
1130 (unless gnus-inhibit-hiding
1133 (let ((buffer-read-only nil)
1134 (inhibit-read-only t)
1135 (case-fold-search t)
1136 (max (1+ (length gnus-sorted-header-list)))
1137 (ignored (when (not gnus-visible-headers)
1138 (cond ((stringp gnus-ignored-headers)
1139 gnus-ignored-headers)
1140 ((listp gnus-ignored-headers)
1141 (mapconcat 'identity gnus-ignored-headers
1144 (cond ((stringp gnus-visible-headers)
1145 gnus-visible-headers)
1146 ((and gnus-visible-headers
1147 (listp gnus-visible-headers))
1148 (mapconcat 'identity gnus-visible-headers "\\|"))))
1149 (inhibit-point-motion-hooks t)
1151 ;; First we narrow to just the headers.
1152 (article-narrow-to-head)
1153 ;; Hide any "From " lines at the beginning of (mail) articles.
1154 (while (looking-at "From ")
1158 (delete-region (point-min) (point))
1159 (gnus-article-hide-text (point-min) (point)
1160 (nconc (list 'article-type 'headers)
1161 gnus-hidden-properties))))
1162 ;; Then treat the rest of the header lines.
1163 ;; Then we use the two regular expressions
1164 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1165 ;; select which header lines is to remain visible in the
1167 (while (re-search-forward "^[^ \t]*:" nil t)
1169 ;; Mark the rank of the header.
1171 (point) (1+ (point)) 'message-rank
1172 (if (or (and visible (looking-at visible))
1174 (not (looking-at ignored))))
1175 (gnus-article-header-rank)
1178 (message-sort-headers-1)
1179 (when (setq beg (text-property-any
1180 (point-min) (point-max) 'message-rank (+ 2 max)))
1181 ;; We delete or make invisible the unwanted headers.
1182 (push 'headers gnus-article-wash-types)
1185 (add-text-properties
1186 (point-min) (+ 5 (point-min))
1187 '(article-type headers dummy-invisible t))
1188 (delete-region beg (point-max)))
1189 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1192 (defun article-hide-boring-headers (&optional arg)
1193 "Toggle hiding of headers that aren't very interesting.
1194 If given a negative prefix, always show; if given a positive prefix,
1196 (interactive (gnus-article-hidden-arg))
1197 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1198 (not gnus-show-all-headers))
1201 (let ((buffer-read-only nil)
1202 (list gnus-boring-article-headers)
1203 (inhibit-point-motion-hooks t)
1205 (article-narrow-to-head)
1207 (setq elem (pop list))
1208 (goto-char (point-min))
1210 ;; Hide empty headers.
1212 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1214 (gnus-article-hide-text-type
1215 (progn (beginning-of-line) (point))
1218 (if (re-search-forward "^[^ \t]" nil t)
1222 ;; Hide boring Newsgroups header.
1223 ((eq elem 'newsgroups)
1224 (when (equal (gnus-fetch-field "newsgroups")
1225 (gnus-group-real-name
1226 (if (boundp 'gnus-newsgroup-name)
1229 (gnus-article-hide-header "newsgroups")))
1230 ((eq elem 'followup-to)
1231 (when (equal (message-fetch-field "followup-to")
1232 (message-fetch-field "newsgroups"))
1233 (gnus-article-hide-header "followup-to")))
1234 ((eq elem 'reply-to)
1235 (let ((from (message-fetch-field "from"))
1236 (reply-to (message-fetch-field "reply-to")))
1241 (nth 1 (funcall gnus-extract-address-components from))
1242 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1243 (gnus-article-hide-header "reply-to"))))
1245 (let ((date (message-fetch-field "date")))
1247 (< (days-between (current-time-string) date)
1249 (gnus-article-hide-header "date"))))
1251 (let ((to (message-fetch-field "to"))
1252 (cc (message-fetch-field "cc")))
1253 (when (> (length to) 1024)
1254 (gnus-article-hide-header "to"))
1255 (when (> (length cc) 1024)
1256 (gnus-article-hide-header "cc"))))
1260 (goto-char (point-min))
1261 (while (re-search-forward "^to:" nil t)
1262 (setq to-count (1+ to-count)))
1263 (when (> to-count 1)
1264 (while (> to-count 0)
1265 (goto-char (point-min))
1267 (re-search-forward "^to:" nil nil to-count)
1269 (narrow-to-region (point) (point-max))
1270 (gnus-article-hide-header "to"))
1271 (setq to-count (1- to-count))))
1272 (goto-char (point-min))
1273 (while (re-search-forward "^cc:" nil t)
1274 (setq cc-count (1+ cc-count)))
1275 (when (> cc-count 1)
1276 (while (> cc-count 0)
1277 (goto-char (point-min))
1279 (re-search-forward "^cc:" nil nil cc-count)
1281 (narrow-to-region (point) (point-max))
1282 (gnus-article-hide-header "cc"))
1283 (setq cc-count (1- cc-count)))))))))))))
1285 (defun gnus-article-hide-header (header)
1287 (goto-char (point-min))
1288 (when (re-search-forward (concat "^" header ":") nil t)
1289 (gnus-article-hide-text-type
1290 (progn (beginning-of-line) (point))
1293 (if (re-search-forward "^[^ \t]" nil t)
1298 (defun article-toggle-headers (&optional arg)
1299 "Toggle hiding of headers. If given a negative prefix, always show;
1300 if given a positive prefix, always hide."
1301 (interactive (gnus-article-hidden-arg))
1302 (let ((force (when (numberp arg)
1303 (cond ((> arg 0) 'always-hide)
1304 ((< arg 0) 'always-show))))
1305 (window (get-buffer-window gnus-article-buffer))
1306 (header-end (point-min))
1307 header-start field-end field-start
1308 (inhibit-point-motion-hooks t)
1309 (inhibit-read-only t)
1313 (while (and (setq header-start
1314 (text-property-any header-end (point-max)
1315 'article-treated-header t))
1317 (text-property-not-all header-start (point-max)
1318 'article-treated-header t)))
1319 (setq field-end header-start)
1321 (;; Hide exposed invisible fields.
1322 (and (not (eq 'always-show force))
1324 (text-property-any field-end header-end
1325 'exposed-invisible-field t)))
1326 (while (and field-start
1327 (setq field-end (text-property-not-all
1328 field-start header-end
1329 'exposed-invisible-field t)))
1330 (add-text-properties field-start field-end gnus-hidden-properties)
1331 (setq field-start (text-property-any field-end header-end
1332 'exposed-invisible-field t)))
1333 (put-text-property header-start header-end
1334 'exposed-invisible-field nil))
1335 (;; Expose invisible fields.
1336 (and (not (eq 'always-hide force))
1338 (text-property-any field-end header-end 'invisible t)))
1339 (while (and field-start
1340 (setq field-end (text-property-not-all
1341 field-start header-end
1343 ;; If the invisible text is not terminated with newline, we
1344 ;; won't expose it. Because it may be created by x-face-mule.
1345 ;; BTW, XEmacs sometimes fail in putting a invisible text
1346 ;; property with `gnus-article-hide-text' (really?). In that
1347 ;; case, the invisible text might be started from the middle of
1348 ;; a line so we will expose the sort of thing.
1349 (when (or (not (or (eq header-start field-start)
1350 (eq ?\n (char-before field-start))))
1351 (eq ?\n (char-before field-end)))
1352 (remove-text-properties field-start field-end
1353 gnus-hidden-properties)
1354 (put-text-property field-start field-end
1355 'exposed-invisible-field t))
1356 (setq field-start (text-property-any field-end header-end
1359 (not (eq 'always-show force))
1360 (narrow-to-region header-start header-end)
1361 (article-hide-headers)
1362 ;; Re-display X-Face image under XEmacs.
1363 (when (and gnus-xemacs
1364 (gnus-functionp gnus-article-x-face-command))
1365 (let ((func (cadr (assq 'gnus-treat-display-xface
1366 gnus-treatment-function-alist)))
1368 (when (and (not gnus-inhibit-treatment)
1370 (gnus-treat-predicate gnus-treat-display-xface))
1372 (put-text-property header-start header-end 'read-only nil))))
1375 (goto-char (point-min))
1377 (set-window-start window (point-min))))))
1379 (defvar gnus-article-normalized-header-length 40
1380 "Length of normalized headers.")
1382 (defun article-normalize-headers ()
1383 "Make all header lines 40 characters long."
1385 (let ((buffer-read-only nil)
1389 (article-narrow-to-head)
1392 ((< (setq column (- (gnus-point-at-eol) (point)))
1393 gnus-article-normalized-header-length)
1395 (insert (make-string
1396 (- gnus-article-normalized-header-length column)
1398 ((> column gnus-article-normalized-header-length)
1399 (gnus-put-text-property
1401 (forward-char gnus-article-normalized-header-length)
1408 (forward-line 1))))))
1410 (defun article-treat-dumbquotes ()
1411 "Translate M******** sm*rtq**t*s into proper text.
1412 Note that this function guesses whether a character is a sm*rtq**t* or
1413 not, so it should only be used interactively."
1415 (article-translate-strings gnus-article-dumbquotes-map))
1417 (defun article-translate-characters (from to)
1418 "Translate all characters in the body of the article according to FROM and TO.
1419 FROM is a string of characters to translate from; to is a string of
1420 characters to translate to."
1422 (when (article-goto-body)
1423 (let ((buffer-read-only nil)
1424 (x (make-string 225 ?x))
1426 (while (< (incf i) (length x))
1429 (while (< i (length from))
1430 (aset x (aref from i) (aref to i))
1432 (translate-region (point) (point-max) x)))))
1434 (defun article-translate-strings (map)
1435 "Translate all string in the body of the article according to MAP.
1436 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1438 (when (article-goto-body)
1439 (let ((buffer-read-only nil)
1441 (while (setq elem (pop map))
1443 (while (search-forward (car elem) nil t)
1444 (replace-match (cadr elem)))))))))
1446 (defun article-treat-overstrike ()
1447 "Translate overstrikes into bold text."
1450 (when (article-goto-body)
1451 (let ((buffer-read-only nil))
1452 (while (search-forward "\b" nil t)
1453 (let ((next (char-after))
1457 previous (char-after))
1461 ;; We do the boldification/underlining by hiding the
1462 ;; overstrikes and putting the proper text property
1466 (gnus-article-hide-text-type start (point) 'overstrike)
1467 (put-text-property (point) end 'face 'bold))
1469 (gnus-article-hide-text-type
1470 (1- (point)) (1+ (point)) 'overstrike)
1472 start (1- (point)) 'face 'underline))
1474 (gnus-article-hide-text-type start (point) 'overstrike)
1476 (point) end 'face 'underline)))))))))
1478 (defun article-fill-long-lines ()
1479 "Fill lines that are wider than the window width."
1482 (let ((buffer-read-only nil)
1483 (width (window-width (get-buffer-window (current-buffer)))))
1486 (let ((adaptive-fill-mode nil))
1489 (when (>= (current-column) (min fill-column width))
1490 (narrow-to-region (point) (gnus-point-at-bol))
1491 (fill-paragraph nil)
1492 (goto-char (point-max))
1494 (forward-line 1)))))))
1496 (defun article-capitalize-sentences ()
1497 "Capitalize the first word in each sentence."
1500 (let ((buffer-read-only nil)
1501 (paragraph-start "^[\n\^L]"))
1505 (forward-sentence)))))
1507 (defun article-remove-cr ()
1508 "Remove trailing CRs and then translate remaining CRs into LFs."
1511 (let ((buffer-read-only nil))
1512 (goto-char (point-min))
1513 (while (re-search-forward "\r+$" nil t)
1514 (replace-match "" t t))
1515 (goto-char (point-min))
1516 (while (search-forward "\r" nil t)
1517 (replace-match "\n" t t)))))
1519 (defun article-remove-trailing-blank-lines ()
1520 "Remove all trailing blank lines from the article."
1523 (let ((buffer-read-only nil))
1524 (goto-char (point-max))
1528 (while (and (not (bobp))
1529 (looking-at "^[ \t]*$")
1530 (not (gnus-annotation-in-region-p
1531 (point) (gnus-point-at-eol))))
1536 (defun article-display-x-face (&optional force)
1537 "Look for an X-Face header and display it if present."
1538 (interactive (list 'force))
1540 ;; Delete the old process, if any.
1541 (when (process-status "article-x-face")
1542 (delete-process "article-x-face"))
1543 (let ((inhibit-point-motion-hooks t)
1544 (case-fold-search t)
1547 (article-narrow-to-head)
1548 (goto-char (point-min))
1549 (setq from (message-fetch-field "from"))
1550 (goto-char (point-min))
1551 (while (and gnus-article-x-face-command
1554 ;; Check whether this face is censored.
1555 (not gnus-article-x-face-too-ugly)
1556 (and gnus-article-x-face-too-ugly from
1557 (not (string-match gnus-article-x-face-too-ugly
1559 ;; Has to be present.
1560 (re-search-forward "^X-Face:[ \t]*" nil t))
1561 ;; This used to try to do multiple faces (`while' instead of
1562 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1563 ;; work (b) it can crash some versions of Emacs (c) are
1564 ;; multiple faces really something to encourage?
1565 (when (stringp gnus-article-x-face-command)
1567 ;; We now have the area of the buffer where the X-Face is stored.
1570 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1571 ;; We display the face.
1572 (if (symbolp gnus-article-x-face-command)
1573 ;; The command is a lisp function, so we call it.
1574 (if (gnus-functionp gnus-article-x-face-command)
1575 (funcall gnus-article-x-face-command beg end)
1576 (error "%s is not a function" gnus-article-x-face-command))
1577 ;; The command is a string, so we interpret the command
1578 ;; as a, well, command, and fork it off.
1579 (let ((process-connection-type nil))
1580 (process-kill-without-query
1582 "article-x-face" nil shell-file-name shell-command-switch
1583 gnus-article-x-face-command))
1584 (process-send-region "article-x-face" beg end)
1585 (process-send-eof "article-x-face"))))))))))
1587 (defun article-decode-mime-words ()
1588 "Decode all MIME-encoded words in the article."
1591 (set-buffer gnus-article-buffer)
1592 (let ((inhibit-point-motion-hooks t)
1594 (mail-parse-charset gnus-newsgroup-charset)
1595 (mail-parse-ignored-charsets
1596 (save-excursion (set-buffer gnus-summary-buffer)
1597 gnus-newsgroup-ignored-charsets)))
1598 (mail-decode-encoded-word-region (point-min) (point-max)))))
1600 (defun article-decode-charset (&optional prompt)
1601 "Decode charset-encoded text in the article.
1602 If PROMPT (the prefix), prompt for a coding system to use."
1604 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1606 (mail-parse-charset gnus-newsgroup-charset)
1607 (mail-parse-ignored-charsets
1608 (save-excursion (condition-case nil
1609 (set-buffer gnus-summary-buffer)
1611 gnus-newsgroup-ignored-charsets))
1612 ct cte ctl charset format)
1615 (article-narrow-to-head)
1616 (setq ct (message-fetch-field "Content-Type" t)
1617 cte (message-fetch-field "Content-Transfer-Encoding" t)
1618 ctl (and ct (ignore-errors
1619 (mail-header-parse-content-type ct)))
1622 (mm-read-coding-system "Charset to decode: "))
1624 (mail-content-type-get ctl 'charset)))
1625 format (and ctl (mail-content-type-get ctl 'format)))
1627 (setq cte (mail-header-strip cte)))
1628 (if (and ctl (not (string-match "/" (car ctl))))
1630 (goto-char (point-max)))
1633 (narrow-to-region (point) (point-max))
1634 (when (and (eq mail-parse-charset 'gnus-decoded)
1635 (eq (mm-body-7-or-8) '8bit))
1636 ;; The text code could have been decoded.
1637 (setq charset mail-parse-charset))
1638 (when (and (or (not ctl)
1639 (equal (car ctl) "text/plain"))
1640 (not format)) ;; article with format will decode later.
1642 charset (and cte (intern (downcase
1643 (gnus-strip-whitespace cte))))
1646 (defun article-decode-encoded-words ()
1647 "Remove encoded-word encoding from headers."
1648 (let (buffer-read-only)
1649 (let ((charset (save-excursion
1650 (set-buffer gnus-summary-buffer)
1651 default-mime-charset)))
1652 (mime-decode-header-in-buffer charset)
1655 (defun article-de-quoted-unreadable (&optional force)
1656 "Translate a quoted-printable-encoded article.
1657 If FORCE, decode the article whether it is marked as quoted-printable
1659 (interactive (list 'force))
1661 (let ((buffer-read-only nil) type charset)
1662 (if (gnus-buffer-live-p gnus-original-article-buffer)
1663 (with-current-buffer gnus-original-article-buffer
1665 (gnus-fetch-field "content-transfer-encoding"))
1666 (let* ((ct (gnus-fetch-field "content-type"))
1669 (mail-header-parse-content-type ct)))))
1670 (setq charset (and ctl
1671 (mail-content-type-get ctl 'charset)))
1672 (if (stringp charset)
1673 (setq charset (intern (downcase charset)))))))
1675 (setq charset gnus-newsgroup-charset))
1677 (and type (string-match "quoted-printable" (downcase type))))
1679 (quoted-printable-decode-region (point) (point-max) charset)))))
1681 (defun article-de-base64-unreadable (&optional force)
1682 "Translate a base64 article.
1683 If FORCE, decode the article whether it is marked as base64 not."
1684 (interactive (list 'force))
1686 (let ((buffer-read-only nil) type charset)
1687 (if (gnus-buffer-live-p gnus-original-article-buffer)
1688 (with-current-buffer gnus-original-article-buffer
1690 (gnus-fetch-field "content-transfer-encoding"))
1691 (let* ((ct (gnus-fetch-field "content-type"))
1694 (mail-header-parse-content-type ct)))))
1695 (setq charset (and ctl
1696 (mail-content-type-get ctl 'charset)))
1697 (if (stringp charset)
1698 (setq charset (intern (downcase charset)))))))
1700 (setq charset gnus-newsgroup-charset))
1702 (and type (string-match "base64" (downcase type))))
1705 (narrow-to-region (point) (point-max))
1706 (base64-decode-region (point-min) (point-max))
1707 (if (mm-coding-system-p charset)
1708 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1713 (defun article-decode-HZ ()
1714 "Translate a HZ-encoded article."
1718 (let ((buffer-read-only nil))
1719 (rfc1843-decode-region (point-min) (point-max)))))
1721 (defun article-wash-html ()
1722 "Format an html article."
1725 (let ((buffer-read-only nil)
1727 (if (gnus-buffer-live-p gnus-original-article-buffer)
1728 (with-current-buffer gnus-original-article-buffer
1729 (let* ((ct (gnus-fetch-field "content-type"))
1732 (mail-header-parse-content-type ct)))))
1733 (setq charset (and ctl
1734 (mail-content-type-get ctl 'charset)))
1735 (if (stringp charset)
1736 (setq charset (intern (downcase charset)))))))
1738 (setq charset gnus-newsgroup-charset))
1740 (save-window-excursion
1742 (narrow-to-region (point) (point-max))
1744 (let ((w3-strict-width (window-width))
1745 (url-standalone-mode t))
1747 (w3-region (point-min) (point-max))
1750 (defun article-hide-list-identifiers ()
1751 "Remove list identifies from the Subject header.
1752 The `gnus-list-identifiers' variable specifies what to do."
1756 (let ((inhibit-point-motion-hooks t)
1758 (article-narrow-to-head)
1759 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1760 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1762 (goto-char (point-min))
1763 (when (re-search-forward
1764 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1765 " *\\)\\)+\\(Re: +\\)?\\)")
1767 (let ((s (or (match-string 3) (match-string 5))))
1768 (delete-region (match-beginning 1) (match-end 1))
1770 (goto-char (match-beginning 1))
1773 (defun article-hide-pgp ()
1774 "Remove any PGP headers and signatures in the current article."
1778 (let ((inhibit-point-motion-hooks t)
1779 buffer-read-only beg end)
1781 ;; Hide the "header".
1782 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1783 (push 'pgp gnus-article-wash-types)
1784 (delete-region (match-beginning 0) (match-end 0))
1785 ;; Remove armor headers (rfc2440 6.2)
1786 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1789 ;; Hide the actual signature.
1790 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1791 (setq end (1+ (match-beginning 0)))
1794 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1796 ;; Perhaps we shouldn't hide to the end of the buffer
1797 ;; if there is no end to the signature?
1799 ;; Hide "- " PGP quotation markers.
1801 (narrow-to-region beg end)
1802 (goto-char (point-min))
1803 (while (re-search-forward "^- " nil t)
1805 (match-beginning 0) (match-end 0)))
1807 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1809 (defun article-hide-pem (&optional arg)
1810 "Toggle hiding of any PEM headers and signatures in the current article.
1811 If given a negative prefix, always show; if given a positive prefix,
1813 (interactive (gnus-article-hidden-arg))
1814 (unless (gnus-article-check-hidden-text 'pem arg)
1816 (let (buffer-read-only end)
1817 (goto-char (point-min))
1818 ;; Hide the horrendously ugly "header".
1819 (when (and (search-forward
1820 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1822 (setq end (1+ (match-beginning 0))))
1823 (push 'pem gnus-article-wash-types)
1824 (gnus-article-hide-text-type
1826 (if (search-forward "\n\n" nil t)
1830 ;; Hide the trailer as well
1831 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1833 (gnus-article-hide-text-type
1834 (match-beginning 0) (match-end 0) 'pem)))))))
1836 (defun article-strip-banner ()
1837 "Strip the banner specified by the `banner' group parameter."
1841 (let ((inhibit-point-motion-hooks t)
1842 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1843 (gnus-signature-limit nil)
1844 buffer-read-only beg end)
1848 ((eq banner 'signature)
1849 (when (gnus-article-narrow-to-signature)
1852 (delete-region (point) (point-max))))
1854 (while (re-search-forward banner nil t)
1855 (delete-region (match-beginning 0) (match-end 0))))))))))
1857 (defun article-babel ()
1858 "Translate article using an online translation service."
1862 (set-buffer gnus-article-buffer)
1863 (when (article-goto-body)
1864 (let* ((buffer-read-only nil)
1867 (orig (buffer-substring start end))
1868 (trans (babel-as-string orig)))
1870 (narrow-to-region start end)
1871 (delete-region start end)
1874 (defun article-hide-signature (&optional arg)
1875 "Hide the signature in the current article.
1876 If given a negative prefix, always show; if given a positive prefix,
1878 (interactive (gnus-article-hidden-arg))
1884 (article-goto-body))
1885 (goto-char (point-min)))
1886 (unless (gnus-article-check-hidden-text 'signature arg)
1887 (let ((buffer-read-only nil)
1889 (while (setq button (text-property-any button (point-max)
1891 'gnus-signature-toggle))
1892 (setq button (text-property-not-all button (point-max)
1894 'gnus-signature-toggle))
1895 (when (and button (not (eobp)))
1896 (gnus-article-hide-text-type
1898 (next-single-property-change (1+ button) 'mime-view-entity
1902 (defun article-strip-headers-in-body ()
1903 "Strip offensive headers from bodies."
1907 (let ((case-fold-search t))
1908 (when (looking-at "x-no-archive:")
1909 (gnus-delete-line)))))
1911 (defun article-strip-leading-blank-lines ()
1912 "Remove all blank lines from the beginning of the article."
1915 (let ((inhibit-point-motion-hooks t)
1917 (when (article-goto-body)
1918 (while (and (not (eobp))
1919 (looking-at "[ \t]*$"))
1920 (gnus-delete-line))))))
1922 (defun article-narrow-to-head ()
1923 "Narrow the buffer to the head of the message.
1924 Point is left at the beginning of the narrowed-to region."
1926 (goto-char (point-min))
1927 (if (search-forward "\n\n" nil 1)
1930 (goto-char (point-min)))
1932 (defun article-goto-body ()
1933 "Place point at the start of the body."
1934 (goto-char (point-min))
1936 ;; This variable is only bound when dealing with separate
1938 (article-goto-body-goes-to-point-min-p
1940 ((search-forward "\n\n" nil t)
1943 (goto-char (point-max))
1946 (defun article-strip-multiple-blank-lines ()
1947 "Replace consecutive blank lines with one empty line."
1950 (let ((inhibit-point-motion-hooks t)
1952 ;; First make all blank lines empty.
1954 (while (re-search-forward "^[ \t]+$" nil t)
1955 (unless (gnus-annotation-in-region-p
1956 (match-beginning 0) (match-end 0))
1957 (replace-match "" nil t)))
1958 ;; Then replace multiple empty lines with a single empty line.
1960 (while (re-search-forward "\n\n\n+" nil t)
1961 (unless (gnus-annotation-in-region-p
1962 (match-beginning 0) (match-end 0))
1963 (replace-match "\n\n" t t))))))
1965 (defun article-strip-leading-space ()
1966 "Remove all white space from the beginning of the lines in the article."
1969 (let ((inhibit-point-motion-hooks t)
1972 (while (re-search-forward "^[ \t]+" nil t)
1973 (replace-match "" t t)))))
1975 (defun article-strip-trailing-space ()
1976 "Remove all white space from the end of the lines in the article."
1979 (let ((inhibit-point-motion-hooks t)
1982 (while (re-search-forward "[ \t]+$" nil t)
1983 (replace-match "" t t)))))
1985 (defun article-strip-blank-lines ()
1986 "Strip leading, trailing and multiple blank lines."
1988 (article-strip-leading-blank-lines)
1989 (article-remove-trailing-blank-lines)
1990 (article-strip-multiple-blank-lines))
1992 (defun article-strip-all-blank-lines ()
1993 "Strip all blank lines."
1996 (let ((inhibit-point-motion-hooks t)
1999 (while (re-search-forward "^[ \t]*\n" nil t)
2000 (replace-match "" t t)))))
2002 (defun gnus-article-narrow-to-signature ()
2003 "Narrow to the signature; return t if a signature is found, else nil."
2004 (let ((inhibit-point-motion-hooks t))
2005 (when (gnus-article-search-signature)
2007 ;; Check whether we have some limits to what we consider
2008 ;; to be a signature.
2009 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2010 (list gnus-signature-limit)))
2012 (while (setq limit (pop limits))
2013 (if (or (and (integerp limit)
2014 (< (- (point-max) (point)) limit))
2016 (< (count-lines (point) (point-max)) limit))
2017 (and (gnus-functionp limit)
2019 (and (stringp limit)
2020 (not (re-search-forward limit nil t))))
2021 () ; This limit did not succeed.
2025 (narrow-to-region (point) (point-max))
2028 (defun gnus-article-search-signature ()
2029 "Search the current buffer for the signature separator.
2030 Put point at the beginning of the signature separator."
2031 (let ((cur (point)))
2032 (goto-char (point-max))
2033 (if (if (stringp gnus-signature-separator)
2034 (re-search-backward gnus-signature-separator nil t)
2035 (let ((seps gnus-signature-separator))
2037 (not (re-search-backward (car seps) nil t)))
2044 (defun gnus-article-hidden-arg ()
2045 "Return the current prefix arg as a number, or 0 if no prefix."
2046 (list (if current-prefix-arg
2047 (prefix-numeric-value current-prefix-arg)
2050 (defun gnus-article-check-hidden-text (type arg)
2051 "Return nil if hiding is necessary.
2052 Arg can be nil or a number. Nil and positive means hide, negative
2053 means show, 0 means toggle."
2056 (let ((hide (gnus-article-hidden-text-p type)))
2062 (gnus-article-show-hidden-text type))
2064 (if (eq hide 'hidden)
2065 (gnus-article-show-hidden-text type)
2068 (defun gnus-article-hidden-text-p (type)
2069 "Say whether the current buffer contains hidden text of type TYPE."
2070 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2072 (not (get-text-property pos 'invisible))
2073 (not (get-text-property pos 'dummy-invisible)))
2075 (text-property-any (1+ pos) (point-max) 'article-type type)))
2080 (defun gnus-article-show-hidden-text (type &optional hide)
2081 "Show all hidden text of type TYPE.
2082 If HIDE, hide the text instead."
2084 (let ((buffer-read-only nil)
2085 (inhibit-point-motion-hooks t)
2088 (while (setq beg (text-property-any end (point-max) 'article-type type))
2091 (text-property-not-all beg (point-max) 'article-type type)
2094 (gnus-article-hide-text beg end gnus-hidden-properties)
2095 (gnus-article-unhide-text beg end))
2099 (defconst article-time-units
2100 `((year . ,(* 365.25 24 60 60))
2101 (week . ,(* 7 24 60 60))
2102 (day . ,(* 24 60 60))
2106 "Mapping from time units to seconds.")
2108 (defun article-date-ut (&optional type highlight header)
2109 "Convert DATE date to universal time in the current article.
2110 If TYPE is `local', convert to local time; if it is `lapsed', output
2111 how much time has lapsed since DATE. For `lapsed', the value of
2112 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2113 should replace the \"Date:\" one, or should be added below it."
2114 (interactive (list 'ut t))
2115 (let* ((header (or header
2116 (and (eq 1 (point-min))
2117 (mail-header-date (save-excursion
2118 (set-buffer gnus-summary-buffer)
2119 gnus-current-headers)))
2120 (message-fetch-field "date")
2122 (date (if (vectorp header) (mail-header-date header)
2124 (inhibit-point-motion-hooks t)
2125 bface eface date-pos)
2126 (when (and date (not (string= date "")))
2129 (article-narrow-to-head)
2130 (when (or (and (eq type 'lapsed)
2131 gnus-article-date-lapsed-new-header
2132 ;; Attempt to get the face of X-Sent first.
2133 (re-search-forward "^X-Sent:[ \t]" nil t))
2134 (re-search-forward "^Date:[ \t]" nil t)
2135 ;; If Date is missing, try again for X-Sent.
2136 (re-search-forward "^X-Sent:[ \t]" nil t))
2137 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2138 date (or (get-text-property (gnus-point-at-bol)
2141 eface (get-text-property (1- (gnus-point-at-eol))
2143 (let ((buffer-read-only nil))
2144 ;; Delete any old X-Sent headers.
2145 (when (setq date-pos
2146 (text-property-any (point-min) (point-max)
2147 'article-date-lapsed t))
2148 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2149 (delete-region (match-beginning 0)
2150 (progn (forward-line 1) (point))))
2151 (goto-char (point-min))
2152 ;; Delete any old Date headers.
2153 (while (re-search-forward "^Date:[ \t]" nil t)
2155 (setq date-pos (match-beginning 0)))
2156 (unless (and (eq type 'lapsed)
2157 gnus-article-date-lapsed-new-header)
2158 (delete-region (match-beginning 0)
2159 (progn (message-next-header) (point)))))
2162 (goto-char date-pos)
2164 ;; Possibly, Date has been deleted.
2166 (when (and (eq type 'lapsed)
2167 gnus-article-date-lapsed-new-header
2168 (looking-at "Date:"))
2170 (goto-char (point-min)))
2171 (insert (article-make-date-line date type))
2172 (when (eq type 'lapsed)
2173 (put-text-property (gnus-point-at-bol) (point)
2174 'article-date-lapsed t))
2178 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2179 (put-text-property (match-beginning 1) (1+ (match-end 1))
2180 'original-date date)
2181 (put-text-property (match-beginning 1) (1+ (match-end 1))
2183 (put-text-property (match-beginning 2) (match-end 2)
2186 (defun article-make-date-line (date type)
2187 "Return a DATE line of TYPE."
2188 (let ((time (condition-case ()
2192 ;; Convert to the local timezone. We have to slap a
2193 ;; `condition-case' round the calls to the timezone
2194 ;; functions since they aren't particularly resistant to
2197 (let ((tz (car (current-time-zone time))))
2198 (format "Date: %s %s%02d%02d" (current-time-string time)
2199 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2200 (/ (% (abs tz) 3600) 60))))
2201 ;; Convert to Universal Time.
2204 (current-time-string
2205 (let* ((e (parse-time-string date))
2206 (tm (apply 'encode-time e))
2208 (ls (- (cadr tm) (car (current-time-zone time)))))
2209 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2210 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2213 ;; Get the original date from the article.
2214 ((eq type 'original)
2215 (concat "Date: " (if (string-match "\n+$" date)
2216 (substring date 0 (match-beginning 0))
2218 ;; Let the user define the format.
2220 (if (gnus-functionp gnus-article-time-format)
2221 (funcall gnus-article-time-format time)
2224 (format-time-string gnus-article-time-format time))))
2227 (let ((tz (car (current-time-zone time))))
2230 (format-time-string "%Y%m%dT%H%M%S" time)
2231 (format "%s%02d%02d"
2232 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2233 (/ (% (abs tz) 3600) 60)))))
2234 ;; Do an X-Sent lapsed format.
2236 ;; If the date is seriously mangled, the timezone functions are
2237 ;; liable to bug out, so we ignore all errors.
2238 (let* ((now (current-time))
2239 (real-time (subtract-time now time))
2240 (real-sec (and real-time
2241 (+ (* (float (car real-time)) 65536)
2243 (sec (and real-time (abs real-sec)))
2253 ;; This is a bit convoluted, but basically we go
2254 ;; through the time units for years, weeks, etc,
2255 ;; and divide things to see whether that results
2256 ;; in positive answers.
2259 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2260 ;; The (remaining) seconds are too few to
2261 ;; be divided into this time unit.
2263 ;; It's big enough, so we output it.
2264 (setq sec (- sec (* num (cdr unit))))
2266 (concat (if prev ", " "") (int-to-string
2268 " " (symbol-name (car unit))
2269 (if (> num 1) "s" ""))
2271 article-time-units "")
2272 ;; If dates are odd, then it might appear like the
2273 ;; article was sent in the future.
2276 " in the future"))))))
2278 (error "Unknown conversion type: %s" type)))))
2280 (defun article-date-local (&optional highlight)
2281 "Convert the current article date to the local timezone."
2282 (interactive (list t))
2283 (article-date-ut 'local highlight))
2285 (defun article-date-original (&optional highlight)
2286 "Convert the current article date to what it was originally.
2287 This is only useful if you have used some other date conversion
2288 function and want to see what the date was before converting."
2289 (interactive (list t))
2290 (article-date-ut 'original highlight))
2292 (defun article-date-lapsed (&optional highlight)
2293 "Convert the current article date to time lapsed since it was sent."
2294 (interactive (list t))
2295 (article-date-ut 'lapsed highlight))
2297 (defun article-update-date-lapsed ()
2298 "Function to be run from a timer to update the lapsed time line."
2299 (let (deactivate-mark)
2304 (set-buffer (window-buffer w))
2305 (when (eq major-mode 'gnus-article-mode)
2306 (goto-char (point-min))
2307 (when (re-search-forward "^X-Sent:" nil t)
2308 (article-date-lapsed t))))
2311 (defun gnus-start-date-timer (&optional n)
2312 "Start a timer to update the X-Sent header in the article buffers.
2313 The numerical prefix says how frequently (in seconds) the function
2318 (gnus-stop-date-timer)
2319 (setq article-lapsed-timer
2320 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2322 (defun gnus-stop-date-timer ()
2323 "Stop the X-Sent timer."
2325 (when article-lapsed-timer
2326 (nnheader-cancel-timer article-lapsed-timer)
2327 (setq article-lapsed-timer nil)))
2329 (defun article-date-user (&optional highlight)
2330 "Convert the current article date to the user-defined format.
2331 This format is defined by the `gnus-article-time-format' variable."
2332 (interactive (list t))
2333 (article-date-ut 'user highlight))
2335 (defun article-date-iso8601 (&optional highlight)
2336 "Convert the current article date to ISO8601."
2337 (interactive (list t))
2338 (article-date-ut 'iso8601 highlight))
2340 (defun article-show-all ()
2341 "Show all hidden text in the article buffer."
2345 (let ((buffer-read-only nil))
2346 (gnus-article-unhide-text (point-min) (point-max))
2347 (gnus-remove-text-with-property 'gnus-prev)
2348 (gnus-remove-text-with-property 'gnus-next))))
2350 (defun article-show-all-headers ()
2351 "Show all hidden headers in the article buffer."
2356 (article-narrow-to-head)
2357 (let ((buffer-read-only nil))
2358 (gnus-article-unhide-text (point-min) (point-max))))))
2360 (defun article-emphasize (&optional arg)
2361 "Emphasize text according to `gnus-emphasis-alist'."
2362 (interactive (gnus-article-hidden-arg))
2363 (unless (gnus-article-check-hidden-text 'emphasis arg)
2367 (with-current-buffer gnus-summary-buffer
2368 gnus-article-emphasis-alist)
2370 gnus-emphasis-alist))
2371 (buffer-read-only nil)
2372 (props (append '(article-type emphasis)
2373 gnus-hidden-properties))
2374 regexp elem beg invisible visible face)
2377 (while (setq elem (pop alist))
2379 (setq regexp (car elem)
2380 invisible (nth 1 elem)
2381 visible (nth 2 elem)
2383 (while (re-search-forward regexp nil t)
2384 (when (and (match-beginning visible) (match-beginning invisible))
2385 (push 'emphasis gnus-article-wash-types)
2386 (gnus-article-hide-text
2387 (match-beginning invisible) (match-end invisible) props)
2388 (gnus-article-unhide-text-type
2389 (match-beginning visible) (match-end visible) 'emphasis)
2390 (gnus-put-text-property-excluding-newlines
2391 (match-beginning visible) (match-end visible) 'face face)
2392 (goto-char (match-end invisible)))))))))
2394 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2395 "Setup newsgroup emphasis alist."
2396 (unless gnus-article-emphasis-alist
2397 (let ((name (and gnus-newsgroup-name
2398 (gnus-group-real-name gnus-newsgroup-name))))
2399 (make-local-variable 'gnus-article-emphasis-alist)
2400 (setq gnus-article-emphasis-alist
2402 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2403 (while (setq elem (pop alist))
2404 (when (and name (string-match (car elem) name))
2406 highlight (copy-sequence (cdr elem)))))
2408 (copy-sequence highlight-words)
2409 (if gnus-newsgroup-name
2410 (copy-sequence (gnus-group-find-parameter
2411 gnus-newsgroup-name 'highlight-words t)))
2412 gnus-emphasis-alist)))))
2414 (defvar gnus-summary-article-menu)
2415 (defvar gnus-summary-post-menu)
2417 ;;; Saving functions.
2419 (defun gnus-article-save (save-buffer file &optional num)
2420 "Save the currently selected article."
2421 (unless gnus-save-all-headers
2422 ;; Remove headers according to `gnus-saved-headers'.
2423 (let ((gnus-visible-headers
2424 (or gnus-saved-headers gnus-visible-headers))
2425 (gnus-article-buffer save-buffer))
2427 (set-buffer save-buffer)
2428 (article-hide-headers 1 t))))
2429 (save-window-excursion
2430 (if (not gnus-default-article-saver)
2431 (error "No default saver is defined")
2432 ;; !!! Magic! The saving functions all save
2433 ;; `gnus-save-article-buffer' (or so they think), but we
2434 ;; bind that variable to our save-buffer.
2435 (set-buffer gnus-article-buffer)
2436 (let* ((gnus-save-article-buffer save-buffer)
2439 ((not gnus-prompt-before-saving) 'default)
2440 ((eq gnus-prompt-before-saving 'always) nil)
2442 (gnus-number-of-articles-to-be-saved
2443 (when (eq gnus-prompt-before-saving t)
2445 (set-buffer gnus-article-current-summary)
2446 (funcall gnus-default-article-saver filename)))))
2448 (defun gnus-read-save-file-name (prompt &optional filename
2449 function group headers variable)
2451 (funcall function group headers (symbol-value variable)))
2456 ((eq filename 'default)
2462 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2465 (if (and gnus-number-of-articles-to-be-saved
2466 (> gnus-number-of-articles-to-be-saved 1))
2467 (format "these %d articles"
2468 gnus-number-of-articles-to-be-saved)
2471 ;; Let the split methods have their say.
2473 ;; No split name was found.
2476 (concat prompt " (default "
2477 (file-name-nondirectory default-name) ") ")
2478 (file-name-directory default-name)
2480 ;; A single group name is returned.
2481 ((stringp split-name)
2483 (funcall function split-name headers
2484 (symbol-value variable)))
2486 (concat prompt " (default "
2487 (file-name-nondirectory default-name) ") ")
2488 (file-name-directory default-name)
2490 ;; A single split name was found
2491 ((= 1 (length split-name))
2492 (let* ((name (expand-file-name
2493 (car split-name) gnus-article-save-directory))
2494 (dir (cond ((file-directory-p name)
2495 (file-name-as-directory name))
2496 ((file-exists-p name) name)
2497 (t gnus-article-save-directory))))
2499 (concat prompt " (default " name ") ")
2501 ;; A list of splits was found.
2503 (setq split-name (nreverse split-name))
2505 (let ((file-name-history
2506 (nconc split-name file-name-history)))
2510 (concat prompt " (`M-p' for defaults) ")
2511 gnus-article-save-directory
2513 gnus-article-save-directory)))
2514 (car (push result file-name-history)))))))
2515 ;; Create the directory.
2516 (gnus-make-directory (file-name-directory file))
2517 ;; If we have read a directory, we append the default file name.
2518 (when (file-directory-p file)
2519 (setq file (expand-file-name (file-name-nondirectory default-name)
2520 (file-name-as-directory file))))
2521 ;; Possibly translate some characters.
2522 (nnheader-translate-file-chars file))))))
2523 (gnus-make-directory (file-name-directory result))
2524 (set variable result)))
2526 (defun gnus-article-archive-name (group)
2527 "Return the first instance of an \"Archive-name\" in the current buffer."
2528 (let ((case-fold-search t))
2529 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2530 (nnheader-concat gnus-article-save-directory
2531 (match-string 1)))))
2533 (defun gnus-article-nndoc-name (group)
2534 "If GROUP is an nndoc group, return the name of the parent group."
2535 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2536 (gnus-group-get-parameter group 'save-article-group)))
2538 (defun gnus-summary-save-in-rmail (&optional filename)
2539 "Append this article to Rmail file.
2540 Optional argument FILENAME specifies file name.
2541 Directory to save to is default to `gnus-article-save-directory'."
2542 (setq filename (gnus-read-save-file-name
2543 "Save %s in rmail file:" filename
2544 gnus-rmail-save-name gnus-newsgroup-name
2545 gnus-current-headers 'gnus-newsgroup-last-rmail))
2546 (gnus-eval-in-buffer-window gnus-save-article-buffer
2550 (gnus-output-to-rmail filename))))
2553 (defun gnus-summary-save-in-mail (&optional filename)
2554 "Append this article to Unix mail file.
2555 Optional argument FILENAME specifies file name.
2556 Directory to save to is default to `gnus-article-save-directory'."
2557 (setq filename (gnus-read-save-file-name
2558 "Save %s in Unix mail file:" filename
2559 gnus-mail-save-name gnus-newsgroup-name
2560 gnus-current-headers 'gnus-newsgroup-last-mail))
2561 (gnus-eval-in-buffer-window gnus-save-article-buffer
2565 (if (and (file-readable-p filename)
2566 (mail-file-babyl-p filename))
2567 (rmail-output-to-rmail-file filename t)
2568 (gnus-output-to-mail filename)))))
2571 (defun gnus-summary-save-in-file (&optional filename overwrite)
2572 "Append this article to file.
2573 Optional argument FILENAME specifies file name.
2574 Directory to save to is default to `gnus-article-save-directory'."
2575 (setq filename (gnus-read-save-file-name
2576 "Save %s in file:" filename
2577 gnus-file-save-name gnus-newsgroup-name
2578 gnus-current-headers 'gnus-newsgroup-last-file))
2579 (gnus-eval-in-buffer-window gnus-save-article-buffer
2583 (when (and overwrite
2584 (file-exists-p filename))
2585 (delete-file filename))
2586 (gnus-output-to-file filename))))
2589 (defun gnus-summary-write-to-file (&optional filename)
2590 "Write this article to a file.
2591 Optional argument FILENAME specifies file name.
2592 The directory to save in defaults to `gnus-article-save-directory'."
2593 (gnus-summary-save-in-file nil t))
2595 (defun gnus-summary-save-body-in-file (&optional filename)
2596 "Append this article body to a file.
2597 Optional argument FILENAME specifies file name.
2598 The directory to save in defaults to `gnus-article-save-directory'."
2599 (setq filename (gnus-read-save-file-name
2600 "Save %s body in file:" filename
2601 gnus-file-save-name gnus-newsgroup-name
2602 gnus-current-headers 'gnus-newsgroup-last-file))
2603 (gnus-eval-in-buffer-window gnus-save-article-buffer
2607 (when (article-goto-body)
2608 (narrow-to-region (point) (point-max)))
2609 (gnus-output-to-file filename))))
2612 (defun gnus-summary-save-in-pipe (&optional command)
2613 "Pipe this article to subprocess."
2615 (cond ((and (eq command 'default)
2616 gnus-last-shell-command)
2617 gnus-last-shell-command)
2621 "Shell command on %s: "
2622 (if (and gnus-number-of-articles-to-be-saved
2623 (> gnus-number-of-articles-to-be-saved 1))
2624 (format "these %d articles"
2625 gnus-number-of-articles-to-be-saved)
2627 gnus-last-shell-command))))
2628 (when (string-equal command "")
2629 (setq command gnus-last-shell-command))
2630 (gnus-eval-in-buffer-window gnus-article-buffer
2633 (shell-command-on-region (point-min) (point-max) command nil)))
2634 (setq gnus-last-shell-command command))
2636 ;;; Article file names when saving.
2638 (defun gnus-capitalize-newsgroup (newsgroup)
2639 "Capitalize NEWSGROUP name."
2640 (when (not (zerop (length newsgroup)))
2641 (concat (char-to-string (upcase (aref newsgroup 0)))
2642 (substring newsgroup 1))))
2644 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2645 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2646 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2647 Otherwise, it is like ~/News/news/group/num."
2650 (concat (if (gnus-use-long-file-name 'not-save)
2651 (gnus-capitalize-newsgroup newsgroup)
2652 (gnus-newsgroup-directory-form newsgroup))
2653 "/" (int-to-string (mail-header-number headers)))
2654 gnus-article-save-directory)))
2656 (string-equal (file-name-directory default)
2657 (file-name-directory last-file))
2658 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2660 (or last-file default))))
2662 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2663 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2664 If variable `gnus-use-long-file-name' is non-nil, it is
2665 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2668 (concat (if (gnus-use-long-file-name 'not-save)
2670 (gnus-newsgroup-directory-form newsgroup))
2671 "/" (int-to-string (mail-header-number headers)))
2672 gnus-article-save-directory)))
2674 (string-equal (file-name-directory default)
2675 (file-name-directory last-file))
2676 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2678 (or last-file default))))
2680 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2681 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2682 If variable `gnus-use-long-file-name' is non-nil, it is
2683 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2686 (if (gnus-use-long-file-name 'not-save)
2688 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2689 gnus-article-save-directory)))
2696 (setq afunc (car func)
2699 gfunc (intern (format "gnus-%s" func))))
2702 `(lambda (&optional interactive &rest args)
2703 ,(documentation afunc t)
2704 (interactive (list t))
2706 (set-buffer gnus-article-buffer)
2708 (call-interactively ',afunc)
2709 (apply ',afunc args))))))))
2710 '(article-hide-headers
2711 article-hide-boring-headers
2712 article-toggle-headers
2713 article-treat-overstrike
2714 article-fill-long-lines
2715 article-capitalize-sentences
2717 article-display-x-face
2718 article-de-quoted-unreadable
2719 article-de-base64-unreadable
2722 article-hide-list-identifiers
2724 article-strip-banner
2727 article-hide-signature
2728 article-strip-headers-in-body
2729 article-remove-trailing-blank-lines
2730 article-strip-leading-blank-lines
2731 article-strip-multiple-blank-lines
2732 article-strip-leading-space
2733 article-strip-trailing-space
2734 article-strip-blank-lines
2735 article-strip-all-blank-lines
2737 article-date-iso8601
2738 article-date-original
2740 article-decode-mime-words
2741 article-decode-charset
2742 article-decode-encoded-words
2746 article-treat-dumbquotes
2747 article-normalize-headers
2748 (article-show-all-headers . gnus-article-show-all-headers)
2749 (article-show-all . gnus-article-show-all))))
2752 ;;; Gnus article mode
2755 (put 'gnus-article-mode 'mode-class 'special)
2757 (gnus-define-keys gnus-article-mode-map
2758 " " gnus-article-goto-next-page
2759 "\177" gnus-article-goto-prev-page
2760 [delete] gnus-article-goto-prev-page
2761 [backspace] gnus-article-goto-prev-page
2762 "\C-c^" gnus-article-refer-article
2763 "h" gnus-article-show-summary
2764 "s" gnus-article-show-summary
2765 "\C-c\C-m" gnus-article-mail
2766 "?" gnus-article-describe-briefly
2767 "e" gnus-summary-edit-article
2768 "<" beginning-of-buffer
2770 "\C-c\C-i" gnus-info-find-node
2773 "\C-d" gnus-article-read-summary-keys
2774 "\M-*" gnus-article-read-summary-keys
2775 "\M-#" gnus-article-read-summary-keys
2776 "\M-^" gnus-article-read-summary-keys
2777 "\M-g" gnus-article-read-summary-keys)
2779 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2782 (unless (lookup-key gnus-article-mode-map key)
2783 (define-key gnus-article-mode-map key
2784 'gnus-article-read-summary-keys)))
2789 (let ((key (car elt)))
2790 (and (> (length key) 0)
2791 (not (eq 'menu-bar (aref key 0)))
2792 (symbolp (lookup-key gnus-summary-mode-map key))
2794 (accessible-keymaps gnus-summary-mode-map))
2798 (push (char-to-string c) keys)
2802 (defun gnus-article-make-menu-bar ()
2803 (gnus-turn-off-edit-menu 'article)
2804 (unless (boundp 'gnus-article-article-menu)
2806 gnus-article-article-menu gnus-article-mode-map ""
2808 ["Scroll forwards" gnus-article-goto-next-page t]
2809 ["Scroll backwards" gnus-article-goto-prev-page t]
2810 ["Show summary" gnus-article-show-summary t]
2811 ["Fetch Message-ID at point" gnus-article-refer-article t]
2812 ["Mail to address at point" gnus-article-mail t]
2813 ["Send a bug report" gnus-bug t]))
2816 gnus-article-treatment-menu gnus-article-mode-map ""
2818 ["Hide headers" gnus-article-toggle-headers t]
2819 ["Hide signature" gnus-article-hide-signature t]
2820 ["Hide citation" gnus-article-hide-citation t]
2821 ["Treat overstrike" gnus-article-treat-overstrike t]
2822 ["Remove carriage return" gnus-article-remove-cr t]
2823 ["Decode HZ" gnus-article-decode-HZ t]))
2825 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2827 (when (boundp 'gnus-summary-post-menu)
2828 (define-key gnus-article-mode-map [menu-bar post]
2829 (cons "Post" gnus-summary-post-menu)))
2831 (gnus-run-hooks 'gnus-article-menu-hook)))
2833 (defun gnus-article-mode ()
2834 "Major mode for displaying an article.
2836 All normal editing commands are switched off.
2838 The following commands are available in addition to all summary mode
2840 \\<gnus-article-mode-map>
2841 \\[gnus-article-next-page]\t Scroll the article one page forwards
2842 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2843 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2844 \\[gnus-article-show-summary]\t Display the summary buffer
2845 \\[gnus-article-mail]\t Send a reply to the address near point
2846 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2847 \\[gnus-info-find-node]\t Go to the Gnus info node"
2849 (when (gnus-visual-p 'article-menu 'menu)
2850 (gnus-article-make-menu-bar))
2851 (gnus-simplify-mode-line)
2852 (setq mode-name "Article")
2853 (setq major-mode 'gnus-article-mode)
2854 (make-local-variable 'minor-mode-alist)
2855 (unless (assq 'gnus-show-mime minor-mode-alist)
2856 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2857 (use-local-map gnus-article-mode-map)
2858 (gnus-update-format-specifications nil 'article-mode)
2859 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2860 (make-local-variable 'gnus-page-broken)
2861 (make-local-variable 'gnus-button-marker-list)
2862 (make-local-variable 'gnus-article-current-summary)
2863 (make-local-variable 'gnus-article-mime-handles)
2864 (make-local-variable 'gnus-article-decoded-p)
2865 (make-local-variable 'gnus-article-mime-handle-alist)
2866 (make-local-variable 'gnus-article-wash-types)
2867 (gnus-set-default-directory)
2868 (buffer-disable-undo)
2869 (setq buffer-read-only t)
2870 (set-syntax-table gnus-article-mode-syntax-table)
2871 (gnus-run-hooks 'gnus-article-mode-hook))
2873 (defun gnus-article-setup-buffer ()
2874 "Initialize the article buffer."
2875 (let* ((name (if gnus-single-article-buffer "*Article*"
2876 (concat "*Article " gnus-newsgroup-name "*")))
2878 (progn (string-match "\\*Article" name)
2879 (concat " *Original Article"
2880 (substring name (match-end 0))))))
2881 (setq gnus-article-buffer name)
2882 (setq gnus-original-article-buffer original)
2883 (setq gnus-article-mime-handle-alist nil)
2884 ;; This might be a variable local to the summary buffer.
2885 (unless gnus-single-article-buffer
2887 (set-buffer gnus-summary-buffer)
2888 (setq gnus-article-buffer name)
2889 (setq gnus-original-article-buffer original)
2890 (gnus-set-global-variables)))
2891 (gnus-article-setup-highlight-words)
2892 ;; Init original article buffer.
2894 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2895 (set-buffer-multibyte nil)
2896 (setq major-mode 'gnus-original-article-mode)
2897 (make-local-variable 'gnus-original-article))
2898 (if (get-buffer name)
2901 (buffer-disable-undo)
2902 (setq buffer-read-only t)
2903 (unless (eq major-mode 'gnus-article-mode)
2904 (gnus-article-mode))
2907 (set-buffer (gnus-get-buffer-create name))
2909 (make-local-variable 'gnus-summary-buffer)
2910 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2911 (current-buffer)))))
2913 ;; Set article window start at LINE, where LINE is the number of lines
2914 ;; from the head of the article.
2915 (defun gnus-article-set-window-start (&optional line)
2917 (get-buffer-window gnus-article-buffer t)
2919 (set-buffer gnus-article-buffer)
2920 (goto-char (point-min))
2923 (gnus-message 6 "Moved to bookmark")
2924 (search-forward "\n\n" nil t)
2928 ;;; @@ article filters
2931 (defun gnus-article-display-mime-message ()
2932 "Article display method for MIME message."
2933 ;; called from `gnus-original-article-buffer'.
2934 (let (charset all-headers)
2935 (with-current-buffer gnus-summary-buffer
2936 (setq charset default-mime-charset
2937 all-headers gnus-have-all-headers))
2938 (make-local-variable 'default-mime-charset)
2939 (setq default-mime-charset charset)
2940 (with-current-buffer (get-buffer-create gnus-article-buffer)
2941 (make-local-variable 'default-mime-charset)
2942 (setq default-mime-charset charset))
2943 (mime-display-message mime-message-structure
2944 gnus-article-buffer nil gnus-article-mode-map)
2946 (gnus-article-hide-headers nil -1)))
2947 (run-hooks 'gnus-mime-article-prepare-hook))
2949 (defun gnus-article-display-traditional-message ()
2950 "Article display method for traditional message."
2951 (set-buffer gnus-article-buffer)
2952 (let (buffer-read-only)
2954 (insert-buffer-substring gnus-original-article-buffer)))
2956 (defun gnus-article-make-full-mail-header (&optional number charset)
2957 "Create a new mail header structure in a raw article buffer."
2958 (unless (and number charset)
2959 (save-current-buffer
2960 (set-buffer gnus-summary-buffer)
2962 (setq number (or (cdr gnus-article-current) 0)))
2964 (setq charset (or default-mime-charset 'x-ctext)))))
2965 (goto-char (point-min))
2966 (let ((header-end (if (search-forward "\n\n" nil t)
2968 (goto-char (point-max))))
2969 (chars (- (point-max) (point)))
2970 (lines (count-lines (point) (point-max)))
2971 (default-mime-charset charset)
2973 (narrow-to-region (point-min) header-end)
2974 (setq xref (std11-fetch-field "xref"))
2976 (make-full-mail-header
2978 (std11-fetch-field "subject")
2979 (std11-fetch-field "from")
2980 (std11-fetch-field "date")
2981 (std11-fetch-field "message-id")
2982 (std11-fetch-field "references")
2985 (when xref (concat "Xref: " xref)))
2988 (defun gnus-article-prepare (article &optional all-headers header)
2989 "Prepare ARTICLE in article mode buffer.
2990 ARTICLE should either be an article number or a Message-ID.
2991 If ARTICLE is an id, HEADER should be the article headers.
2992 If ALL-HEADERS is non-nil, no headers are hidden."
2994 ;; Make sure we start in a summary buffer.
2995 (unless (eq major-mode 'gnus-summary-mode)
2996 (set-buffer gnus-summary-buffer))
2997 (setq gnus-summary-buffer (current-buffer))
2998 (let* ((gnus-article (if header (mail-header-number header) article))
2999 (summary-buffer (current-buffer))
3000 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3001 (group gnus-newsgroup-name)
3004 (gnus-article-setup-buffer)
3005 (set-buffer gnus-original-article-buffer)
3006 ;; Deactivate active regions.
3007 (when (and (boundp 'transient-mark-mode)
3008 transient-mark-mode)
3009 (setq mark-active nil))
3010 (if (not (setq result (let ((buffer-read-only nil))
3011 (gnus-request-article-this-buffer
3013 ;; There is no such article.
3015 (when (and (numberp article)
3016 (not (memq article gnus-newsgroup-sparse)))
3017 (setq gnus-article-current
3018 (cons gnus-newsgroup-name article))
3019 (set-buffer gnus-summary-buffer)
3020 (setq gnus-current-article article)
3021 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3023 (gnus-summary-set-agent-mark article)
3024 (message "Message marked for downloading"))
3025 (gnus-summary-mark-article article gnus-canceled-mark)
3026 (unless (memq article gnus-newsgroup-sparse)
3027 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3028 (if (or (eq result 'pseudo)
3029 (eq result 'nneething))
3032 (set-buffer summary-buffer)
3033 (push article gnus-newsgroup-history)
3034 (setq gnus-last-article gnus-current-article
3035 gnus-current-article 0
3036 gnus-current-headers nil
3037 gnus-article-current nil)
3038 (if (eq result 'nneething)
3039 (gnus-configure-windows 'summary)
3040 (gnus-configure-windows 'article))
3041 (gnus-set-global-variables))
3042 (let ((gnus-article-mime-handle-alist-1
3043 gnus-article-mime-handle-alist))
3044 (gnus-set-mode-line 'article)))
3045 ;; The result from the `request' was an actual article -
3046 ;; or at least some text that is now displayed in the
3048 (when (and (numberp article)
3049 (not (eq article gnus-current-article)))
3050 ;; Seems like a new article has been selected.
3051 ;; `gnus-current-article' must be an article number.
3053 (set-buffer summary-buffer)
3054 (push article gnus-newsgroup-history)
3055 (setq gnus-last-article gnus-current-article
3056 gnus-current-article article
3057 gnus-current-headers
3058 (gnus-summary-article-header gnus-current-article)
3059 gnus-article-current
3060 (cons gnus-newsgroup-name gnus-current-article))
3061 (unless (vectorp gnus-current-headers)
3062 (setq gnus-current-headers nil))
3063 (gnus-summary-goto-subject gnus-current-article)
3064 (when (gnus-summary-show-thread)
3065 ;; If the summary buffer really was folded, the
3066 ;; previous goto may not actually have gone to
3067 ;; the right article, but the thread root instead.
3069 (gnus-summary-goto-subject gnus-current-article))
3070 (gnus-run-hooks 'gnus-mark-article-hook)
3071 (gnus-set-mode-line 'summary)
3072 (when (gnus-visual-p 'article-highlight 'highlight)
3073 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3074 ;; Set the global newsgroup variables here.
3075 (gnus-set-global-variables)
3076 (setq gnus-have-all-headers
3077 (or all-headers gnus-show-all-headers))))
3078 (when (or (numberp article)
3080 (gnus-article-prepare-display)
3082 (goto-char (point-min))
3083 (setq gnus-page-broken
3084 (when gnus-break-pages
3085 (gnus-narrow-to-page)
3087 (let ((gnus-article-mime-handle-alist-1
3088 gnus-article-mime-handle-alist))
3089 (gnus-set-mode-line 'article))
3091 (set-window-point (get-buffer-window (current-buffer)) (point))
3092 (gnus-configure-windows 'article)
3095 (defun gnus-article-prepare-mime-display (&optional number)
3096 (goto-char (point-min))
3097 (when (re-search-forward "^[^\t ]+:" nil t)
3098 (goto-char (match-beginning 0)))
3099 (let ((entity (if (eq 1 (point-min))
3100 (get-text-property 1 'mime-view-entity)
3101 (get-text-property (point) 'mime-view-entity)))
3102 last-entity child-entity next type)
3103 (setq child-entity (mime-entity-children entity))
3105 (setq last-entity (nth (1- (length child-entity))
3107 (setq last-entity entity))
3109 (narrow-to-region (point)
3110 (if (search-forward "\n\n" nil t)
3113 (gnus-treat-article 'head)
3114 (put-text-property (point-min) (point-max) 'article-treated-header t)
3115 (goto-char (point-max)))
3116 (while (and (not (eobp)) entity)
3117 (setq next (set-marker
3119 (next-single-property-change (point) 'mime-view-entity
3121 (let ((types (mime-entity-content-type entity)))
3122 (while (eq 'multipart (mime-content-type-primary-type types))
3123 (setq entity (car (mime-entity-children entity))
3124 types (mime-entity-content-type entity)))
3126 (setq type (format "%s/%s"
3127 (mime-content-type-primary-type types)
3128 (mime-content-type-subtype types)))))
3129 (if (string-equal type "message/rfc822")
3132 (let ((children (mime-entity-children entity))
3135 (setq last-children (nth (1- (length children)) children))
3138 (not (eq last-children
3139 (get-text-property next 'mime-view-entity)))
3141 (next-single-property-change next
3143 nil (point-max)))))))
3144 (setq next (next-single-property-change next 'mime-view-entity
3147 (narrow-to-region (point) next)
3148 (gnus-article-prepare-mime-display)
3149 (goto-char (point-max)))
3150 (setq entity (get-text-property (point) 'mime-view-entity)))
3152 (narrow-to-region (point) next)
3153 ;; Kludge. We have to count true number, but for now,
3154 ;; part number is here only to achieve `last'.
3155 (gnus-treat-article nil 1
3156 (if (eq entity last-entity)
3159 (goto-char (point-max)))
3160 (setq entity (get-text-property next 'mime-view-entity))))))
3163 (defun gnus-article-prepare-display ()
3164 "Make the current buffer look like a nice article."
3165 (setq gnus-article-wash-types nil)
3166 (gnus-run-hooks 'gnus-tmp-internal-hook)
3167 (gnus-run-hooks 'gnus-article-prepare-hook)
3169 (let (mime-display-header-hook mime-display-text/plain-hook)
3170 (funcall (if gnus-show-mime
3172 (setq mime-message-structure gnus-current-headers)
3173 (mime-buffer-entity-set-buffer-internal
3174 mime-message-structure
3175 gnus-original-article-buffer)
3176 (mime-entity-set-representation-type-internal
3177 mime-message-structure 'mime-buffer-entity)
3178 (luna-send mime-message-structure
3179 'initialize-instance
3180 mime-message-structure)
3181 gnus-article-display-method-for-mime)
3182 gnus-article-display-method-for-traditional)))
3183 ;; Associate this article with the current summary buffer.
3184 (setq gnus-article-current-summary gnus-summary-buffer)
3185 ;; Call the treatment functions.
3186 (let ((inhibit-read-only t)
3191 (gnus-article-prepare-mime-display)
3192 (narrow-to-region (goto-char (point-min))
3193 (if (search-forward "\n\n" nil t)
3196 (gnus-treat-article 'head)
3197 (put-text-property (point-min) (point-max) 'article-treated-header t)
3198 (goto-char (point-max))
3200 (narrow-to-region (point) (point-max))
3201 (gnus-treat-article nil))
3202 (put-text-property (point-min) (point-max) 'read-only nil)))
3203 ;; Perform the article display hooks. Incidentally, this hook is
3204 ;; an obsolete variable by now.
3205 (gnus-run-hooks 'gnus-article-display-hook))
3207 (defun gnus-article-decode-article-as-default-mime-charset ()
3208 "Decode an article as `default-mime-charset'. It won't work if the
3209 value of the variable `gnus-show-mime' is non-nil."
3210 (unless gnus-show-mime
3211 (decode-mime-charset-region (point-min) (point-max)
3212 (with-current-buffer gnus-summary-buffer
3213 default-mime-charset))))
3216 ;;; Gnus MIME viewing functions
3219 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3220 "The following specs can be used:
3222 %T MIME type, along with additional info
3223 %n The `name' parameter
3224 %d The description, if any
3225 %l The length of the encoded part
3226 %p The part identifier number
3227 %e Dots if the part isn't displayed")
3229 (defvar gnus-mime-button-line-format-alist
3230 '((?t gnus-tmp-type ?s)
3231 (?T gnus-tmp-type-long ?s)
3232 (?n gnus-tmp-name ?s)
3233 (?d gnus-tmp-description ?s)
3235 (?l gnus-tmp-length ?d)
3236 (?e gnus-tmp-dots ?s)))
3238 (defvar gnus-mime-button-commands
3239 '((gnus-article-press-button "\r" "Toggle Display")
3240 (gnus-mime-view-part "v" "View Interactively...")
3241 (gnus-mime-view-part-as-type "t" "View As Type...")
3242 (gnus-mime-save-part "o" "Save...")
3243 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3244 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3245 (gnus-mime-internalize-part "E" "View Internally")
3246 (gnus-mime-externalize-part "e" "View Externally")
3247 (gnus-mime-pipe-part "|" "Pipe To Command...")))
3249 (defun gnus-article-mime-part-status ()
3250 (with-current-buffer gnus-article-buffer
3251 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3252 (if (and entity (mime-entity-children entity))
3253 (format " (%d parts)" (length (mime-entity-children entity)))
3256 (defvar gnus-mime-button-map
3257 (let ((map (make-sparse-keymap)))
3258 (set-keymap-parent map gnus-article-mode-map)
3259 (define-key map gnus-mouse-2 'gnus-article-push-button)
3260 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3261 (dolist (c gnus-mime-button-commands)
3262 (define-key map (cadr c) (car c)))
3265 (defun gnus-mime-button-menu (event)
3266 "Construct a context-sensitive menu of MIME commands."
3269 (let ((pos (event-start event)))
3270 (set-buffer (window-buffer (posn-window pos)))
3271 (goto-char (posn-point pos))
3272 (gnus-article-check-buffer)
3273 (let ((response (x-popup-menu
3275 ("" ,@(mapcar (lambda (c)
3276 (cons (caddr c) (car c)))
3277 gnus-mime-button-commands))))))
3279 (call-interactively response))))))
3281 (defun gnus-mime-view-all-parts (&optional handles)
3282 "View all the MIME parts."
3284 (save-current-buffer
3285 (set-buffer gnus-article-buffer)
3286 (let ((handles (or handles gnus-article-mime-handles))
3287 (mail-parse-charset gnus-newsgroup-charset)
3288 (mail-parse-ignored-charsets
3289 (save-excursion (set-buffer gnus-summary-buffer)
3290 gnus-newsgroup-ignored-charsets)))
3291 (if (stringp (car handles))
3292 (gnus-mime-view-all-parts (cdr handles))
3293 (mapcar 'mm-display-part handles)))))
3295 (defun gnus-mime-save-part ()
3296 "Save the MIME part under point."
3298 (gnus-article-check-buffer)
3299 (let ((data (get-text-property (point) 'gnus-data)))
3300 (mm-save-part data)))
3302 (defun gnus-mime-pipe-part ()
3303 "Pipe the MIME part under point to a process."
3305 (gnus-article-check-buffer)
3306 (let ((data (get-text-property (point) 'gnus-data)))
3307 (mm-pipe-part data)))
3309 (defun gnus-mime-view-part ()
3310 "Interactively choose a viewing method for the MIME part under point."
3312 (gnus-article-check-buffer)
3313 (let ((data (get-text-property (point) 'gnus-data)))
3314 (mm-interactively-view-part data)))
3316 (defun gnus-mime-view-part-as-type-internal ()
3317 (gnus-article-check-buffer)
3318 (let* ((name (mail-content-type-get
3319 (mm-handle-type (get-text-property (point) 'gnus-data))
3321 (def-type (and name (mm-default-file-encoding name))))
3322 (and def-type (cons def-type 0))))
3324 (defun gnus-mime-view-part-as-type (mime-type)
3325 "Choose a MIME media type, and view the part as such."
3327 (list (completing-read
3328 "View as MIME type: "
3329 (mapcar #'list (mailcap-mime-types))
3331 (gnus-mime-view-part-as-type-internal))))
3332 (gnus-article-check-buffer)
3333 (let ((handle (get-text-property (point) 'gnus-data)))
3334 (gnus-mm-display-part
3335 (mm-make-handle (mm-handle-buffer handle)
3336 (cons mime-type (cdr (mm-handle-type handle)))
3337 (mm-handle-encoding handle)
3338 (mm-handle-undisplayer handle)
3339 (mm-handle-disposition handle)
3340 (mm-handle-description handle)
3341 (mm-handle-cache handle)
3342 (mm-handle-id handle)))))
3344 (defun gnus-mime-copy-part (&optional handle)
3345 "Put the the MIME part under point into a new buffer."
3347 (gnus-article-check-buffer)
3348 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3349 (contents (mm-get-part handle))|
3350 (base (file-name-nondirectory
3352 (mail-content-type-get (mm-handle-type handle) 'name)
3353 (mail-content-type-get (mm-handle-type handle)
3356 (buffer (generate-new-buffer base)))
3357 (switch-to-buffer buffer)
3359 ;; We do it this way to make `normal-mode' set the appropriate mode.
3362 (setq buffer-file-name (expand-file-name base))
3364 (setq buffer-file-name nil))
3365 (goto-char (point-min))))
3367 (defun gnus-mime-inline-part (&optional handle)
3368 "Insert the MIME part under point into the current buffer."
3370 (gnus-article-check-buffer)
3371 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3375 (if (mm-handle-undisplayer handle)
3376 (mm-remove-part handle)
3377 (setq contents (mm-get-part handle))
3379 (mm-insert-inline handle contents)
3382 (defun gnus-mime-externalize-part (&optional handle)
3383 "View the MIME part under point with an external viewer."
3385 (gnus-article-check-buffer)
3386 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3387 (mm-user-display-methods nil)
3388 (mm-inlined-types nil)
3389 (mail-parse-charset gnus-newsgroup-charset)
3390 (mail-parse-ignored-charsets
3391 (save-excursion (set-buffer gnus-summary-buffer)
3392 gnus-newsgroup-ignored-charsets)))
3393 (if (mm-handle-undisplayer handle)
3394 (mm-remove-part handle)
3395 (mm-display-part handle))))
3397 (defun gnus-mime-internalize-part (&optional handle)
3398 "View the MIME part under point with an internal viewer.
3399 In no internal viewer is available, use an external viewer."
3401 (gnus-article-check-buffer)
3402 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3403 (mm-inlined-types '(".*"))
3404 (mm-inline-large-images t)
3405 (mail-parse-charset gnus-newsgroup-charset)
3406 (mail-parse-ignored-charsets
3407 (save-excursion (set-buffer gnus-summary-buffer)
3408 gnus-newsgroup-ignored-charsets)))
3409 (if (mm-handle-undisplayer handle)
3410 (mm-remove-part handle)
3411 (mm-display-part handle))))
3413 (defun gnus-article-part-wrapper (n function)
3414 (save-current-buffer
3415 (set-buffer gnus-article-buffer)
3416 (when (> n (length gnus-article-mime-handle-alist))
3417 (error "No such part"))
3418 (gnus-article-goto-part n)
3419 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3420 (funcall function handle))))
3422 (defun gnus-article-pipe-part (n)
3423 "Pipe MIME part N, which is the numerical prefix."
3425 (gnus-article-part-wrapper n 'mm-pipe-part))
3427 (defun gnus-article-save-part (n)
3428 "Save MIME part N, which is the numerical prefix."
3430 (gnus-article-part-wrapper n 'mm-save-part))
3432 (defun gnus-article-interactively-view-part (n)
3433 "View MIME part N interactively, which is the numerical prefix."
3435 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3437 (defun gnus-article-copy-part (n)
3438 "Copy MIME part N, which is the numerical prefix."
3440 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3442 (defun gnus-article-externalize-part (n)
3443 "View MIME part N externally, which is the numerical prefix."
3445 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3447 (defun gnus-article-inline-part (n)
3448 "Inline MIME part N, which is the numerical prefix."
3450 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3452 (defun gnus-article-mime-match-handle-first (condition)
3454 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3455 (while (setq ihandle (pop alist))
3457 ((functionp condition)
3458 (funcall condition (cdr ihandle)))
3459 ((eq condition 'undisplayed)
3460 (not (or (mm-handle-undisplayer (cdr ihandle))
3461 (equal (mm-handle-media-type (cdr ihandle))
3462 "multipart/alternative"))))
3463 ((eq condition 'undisplayed-alternative)
3464 (not (mm-handle-undisplayer (cdr ihandle))))
3466 (gnus-article-goto-part (car ihandle))
3467 (or (not n) (< (car ihandle) n)))
3468 (setq n (car ihandle))))
3472 (defun gnus-article-view-part (&optional n)
3473 "View MIME part N, which is the numerical prefix."
3475 (save-current-buffer
3476 (set-buffer gnus-article-buffer)
3477 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3478 gnus-article-mime-match-handle-function)))
3479 (when (> n (length gnus-article-mime-handle-alist))
3480 (error "No such part"))
3481 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3482 (when (gnus-article-goto-part n)
3483 (if (equal (car handle) "multipart/alternative")
3484 (gnus-article-press-button)
3485 (when (eq (gnus-mm-display-part handle) 'internal)
3486 (gnus-set-window-start)))))))
3488 (defun gnus-mm-display-part (handle)
3489 "Display HANDLE and fix MIME button."
3490 (let ((id (get-text-property (point) 'gnus-part))
3495 (let ((window (selected-window))
3496 (mail-parse-charset gnus-newsgroup-charset)
3497 (mail-parse-ignored-charsets
3498 (save-excursion (set-buffer gnus-summary-buffer)
3499 gnus-newsgroup-ignored-charsets)))
3502 (let ((win (get-buffer-window (current-buffer) t))
3505 (select-window win))
3508 (if (mm-handle-displayed-p handle)
3509 ;; This will remove the part.
3510 (mm-display-part handle)
3512 (narrow-to-region (point) (1+ (point)))
3513 (mm-display-part handle)
3514 ;; We narrow to the part itself and
3515 ;; then call the treatment functions.
3516 (goto-char (point-min))
3518 (narrow-to-region (point) (point-max))
3521 (1- (length gnus-article-mime-handles))
3522 (mm-handle-media-type handle)))))
3523 (select-window window))))
3525 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3526 (gnus-insert-mime-button
3527 handle id (list (mm-handle-displayed-p handle)))
3528 (goto-char point))))
3530 (defun gnus-article-goto-part (n)
3531 "Go to MIME part N."
3532 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3534 (goto-char point))))
3536 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3537 (let ((gnus-tmp-name
3538 (or (mail-content-type-get (mm-handle-type handle)
3540 (mail-content-type-get (mm-handle-disposition handle)
3543 (gnus-tmp-type (mm-handle-media-type handle))
3544 (gnus-tmp-description
3545 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3548 (if (if displayed (car displayed)
3549 (mm-handle-displayed-p handle))
3551 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3553 gnus-tmp-type-long b e)
3554 (when (string-match ".*/" gnus-tmp-name)
3555 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3556 (setq gnus-tmp-type-long (concat gnus-tmp-type
3557 (and (not (equal gnus-tmp-name ""))
3558 (concat "; " gnus-tmp-name))))
3559 (or (equal gnus-tmp-description "")
3560 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3565 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3566 `(local-map ,gnus-mime-button-map
3567 keymap ,gnus-mime-button-map
3568 gnus-callback gnus-mm-display-part
3569 gnus-part ,gnus-tmp-id
3570 article-type annotation
3573 (widget-convert-button
3576 :action 'gnus-widget-press-button
3577 :button-keymap gnus-mime-button-map
3579 (lambda (widget/window &optional overlay pos)
3580 ;; Needed to properly clear the message due to a bug in
3581 ;; wid-edit (XEmacs only).
3582 (if (boundp 'help-echo-owns-message)
3583 (setq help-echo-owns-message t))
3585 "%S: %s the MIME part; %S: more options"
3586 (aref gnus-mouse-2 0)
3587 ;; XEmacs will get a single widget arg; Emacs 21 will get
3588 ;; window, overlay, position.
3589 (if (mm-handle-displayed-p
3591 (with-current-buffer (overlay-buffer overlay)
3592 (widget-get (widget-at (overlay-start overlay))
3594 (widget-get widget/window :mime-handle)))
3596 (aref gnus-down-mouse-3 0))))))
3598 (defun gnus-widget-press-button (elems el)
3599 (goto-char (widget-get elems :from))
3600 (gnus-article-press-button))
3602 (defvar gnus-displaying-mime nil)
3604 (defun gnus-display-mime (&optional ihandles)
3605 "Display the MIME parts."
3607 (save-selected-window
3608 (let ((window (get-buffer-window gnus-article-buffer))
3611 (select-window window)
3612 ;; We have to do this since selecting the window
3613 ;; may change the point. So we set the window point.
3614 (set-window-point window point)))
3615 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3616 buffer-read-only handle name type b e display)
3617 (when (and (not ihandles)
3618 (not gnus-displaying-mime))
3619 ;; Top-level call; we clean up.
3620 (when gnus-article-mime-handles
3621 (mm-destroy-parts gnus-article-mime-handles)
3622 (setq gnus-article-mime-handle-alist nil));; A trick.
3623 (setq gnus-article-mime-handles handles)
3624 ;; We allow users to glean info from the handles.
3625 (when gnus-article-mime-part-function
3626 (gnus-mime-part-function handles)))
3628 (or (not (stringp (car handles)))
3631 (when (and (not ihandles)
3632 (not gnus-displaying-mime))
3633 ;; Clean up for mime parts.
3635 (delete-region (point) (point-max)))
3636 (let ((gnus-displaying-mime t))
3637 (gnus-mime-display-part handles)))
3640 (narrow-to-region (point) (point-max))
3641 (gnus-treat-article nil 1 1)
3644 ;; Highlight the headers.
3648 (narrow-to-region (point-min) (point))
3649 (gnus-treat-article 'head))))))))
3651 (defvar gnus-mime-display-multipart-as-mixed nil)
3653 (defun gnus-mime-display-part (handle)
3656 ((not (stringp (car handle)))
3657 (gnus-mime-display-single handle))
3658 ;; User-defined multipart
3659 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3660 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3662 ;; multipart/alternative
3663 ((and (equal (car handle) "multipart/alternative")
3664 (not gnus-mime-display-multipart-as-mixed))
3665 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3666 (push (cons id handle) gnus-article-mime-handle-alist)
3667 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3668 ;; multipart/related
3669 ((and (equal (car handle) "multipart/related")
3670 (not gnus-mime-display-multipart-as-mixed))
3671 ;;;!!!We should find the start part, but we just default
3672 ;;;!!!to the first part.
3673 (gnus-mime-display-part (cadr handle)))
3674 ;; Other multiparts are handled like multipart/mixed.
3676 (gnus-mime-display-mixed (cdr handle)))))
3678 (defun gnus-mime-part-function (handles)
3679 (if (stringp (car handles))
3680 (mapcar 'gnus-mime-part-function (cdr handles))
3681 (funcall gnus-article-mime-part-function handles)))
3683 (defun gnus-mime-display-mixed (handles)
3684 (mapcar 'gnus-mime-display-part handles))
3686 (defun gnus-mime-display-single (handle)
3687 (let ((type (mm-handle-media-type handle))
3688 (ignored gnus-ignored-mime-types)
3695 (when (string-match (pop ignored) type)
3696 (throw 'ignored nil)))
3697 (if (and (setq not-attachment
3698 (and (not (mm-inline-override-p handle))
3699 (or (not (mm-handle-disposition handle))
3700 (equal (car (mm-handle-disposition handle))
3702 (mm-attachment-override-p handle))))
3703 (mm-automatic-display-p handle)
3704 (or (mm-inlined-p handle)
3705 (mm-automatic-external-display-p type)))
3707 (when (equal (mm-handle-media-supertype handle) "text")
3709 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3710 (push (cons id handle) gnus-article-mime-handle-alist)
3711 (when (or (not display)
3712 (not (gnus-unbuttonized-mime-type-p type)))
3713 ;(gnus-article-insert-newline)
3714 (gnus-insert-mime-button
3715 handle id (list (or display (and not-attachment text))))
3716 (gnus-article-insert-newline)
3717 ;(gnus-article-insert-newline)
3719 (let ((beg (point)))
3725 (let ((mail-parse-charset gnus-newsgroup-charset)
3726 (mail-parse-ignored-charsets
3727 (save-excursion (condition-case ()
3728 (set-buffer gnus-summary-buffer)
3730 gnus-newsgroup-ignored-charsets)))
3731 (mm-display-part handle t))
3732 (goto-char (point-max)))
3733 ((and text not-attachment)
3737 (gnus-article-insert-newline)
3738 (mm-insert-inline handle (mm-get-part handle))
3739 (goto-char (point-max))))
3743 (narrow-to-region beg (point))
3745 nil (length gnus-article-mime-handle-alist)
3746 (1- (length gnus-article-mime-handles))
3747 (mm-handle-media-type handle)))))))))
3749 (defun gnus-unbuttonized-mime-type-p (type)
3750 "Say whether TYPE is to be unbuttonized."
3751 (unless gnus-inhibit-mime-unbuttonizing
3753 (let ((types gnus-unbuttonized-mime-types))
3755 (when (string-match (pop types) type)
3756 (throw 'found t)))))))
3758 (defun gnus-article-insert-newline ()
3759 "Insert a newline, but mark it as undeletable."
3760 (gnus-put-text-property
3761 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3763 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3764 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3767 handle buffer-read-only from props begend not-pref)
3768 (save-window-excursion
3771 (narrow-to-region (car ibegend)
3774 (goto-char (car ibegend))
3777 (delete-region (point-min) (point-max))
3778 (mm-remove-parts handles))
3779 (setq begend (list (point-marker)))
3781 (unless (setq not-pref (cadr (member preferred ihandles)))
3782 (setq not-pref (car ihandles)))
3784 (not (gnus-unbuttonized-mime-type-p
3785 "multipart/alternative")))
3786 (gnus-add-text-properties
3789 (insert (format "%d. " id))
3793 (unless ,(not ibegend)
3794 (setq gnus-article-mime-handle-alist
3795 ',gnus-article-mime-handle-alist))
3796 (gnus-mime-display-alternative
3797 ',ihandles ',not-pref ',begend ,id))
3798 local-map ,gnus-mime-button-map
3799 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3800 face ,gnus-article-button-face
3801 keymap ,gnus-mime-button-map
3804 (widget-convert-button 'link from (point)
3805 :action 'gnus-widget-press-button
3806 :button-keymap gnus-widget-button-keymap)
3808 (while (setq handle (pop handles))
3809 (gnus-add-text-properties
3812 (insert (format "(%c) %-18s"
3813 (if (equal handle preferred) ?* ? )
3814 (mm-handle-media-type handle)))
3818 (unless ,(not ibegend)
3819 (setq gnus-article-mime-handle-alist
3820 ',gnus-article-mime-handle-alist))
3821 (gnus-mime-display-alternative
3822 ',ihandles ',handle ',begend ,id))
3823 local-map ,gnus-mime-button-map
3824 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3825 face ,gnus-article-button-face
3826 keymap ,gnus-mime-button-map
3829 (widget-convert-button 'link from (point)
3830 :action 'gnus-widget-press-button
3831 :button-keymap gnus-widget-button-keymap)
3835 (if (stringp (car preferred))
3836 (gnus-display-mime preferred)
3837 (let ((mail-parse-charset gnus-newsgroup-charset)
3838 (mail-parse-ignored-charsets
3839 (save-excursion (set-buffer gnus-summary-buffer)
3840 gnus-newsgroup-ignored-charsets)))
3841 (mm-display-part preferred)
3845 (narrow-to-region (car begend) (point-max))
3847 nil (length gnus-article-mime-handle-alist)
3848 (1- (length gnus-article-mime-handles))
3849 (mm-handle-media-type handle))))))
3850 (goto-char (point-max))
3851 (setcdr begend (point-marker)))))
3853 (goto-char point))))
3855 (defun gnus-article-wash-status ()
3856 "Return a string which display status of article washing."
3858 (set-buffer gnus-article-buffer)
3859 (let ((cite (memq 'cite gnus-article-wash-types))
3860 (headers (memq 'headers gnus-article-wash-types))
3861 (boring (memq 'boring-headers gnus-article-wash-types))
3862 (pgp (memq 'pgp gnus-article-wash-types))
3863 (pem (memq 'pem gnus-article-wash-types))
3864 (signature (memq 'signature gnus-article-wash-types))
3865 (overstrike (memq 'overstrike gnus-article-wash-types))
3866 (emphasis (memq 'emphasis gnus-article-wash-types)))
3867 (format "%c%c%c%c%c%c%c"
3869 (if (or headers boring) ?h ? )
3870 (if (or pgp pem) ?p ? )
3871 (if signature ?s ? )
3872 (if overstrike ?o ? )
3873 (if gnus-show-mime ?m ? )
3874 (if emphasis ?e ? )))))
3876 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3878 (defun gnus-article-maybe-hide-headers ()
3879 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3880 Provided for backwards compatibility."
3881 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3882 (not (save-excursion (set-buffer gnus-summary-buffer)
3883 gnus-have-all-headers)))
3884 (not gnus-inhibit-hiding))
3885 (gnus-article-hide-headers)))
3889 (defun gnus-output-to-file (file-name)
3890 "Append the current article to a file named FILE-NAME."
3891 (let ((artbuf (current-buffer)))
3893 (insert-buffer-substring artbuf)
3894 ;; Append newline at end of the buffer as separator, and then
3896 (goto-char (point-max))
3898 (write-region-as-binary (point-min) (point-max) file-name 'append)
3901 (defun gnus-narrow-to-page (&optional arg)
3902 "Narrow the article buffer to a page.
3903 If given a numerical ARG, move forward ARG pages."
3905 (setq arg (if arg (prefix-numeric-value arg) 0))
3907 (set-buffer gnus-article-buffer)
3908 (goto-char (point-min))
3910 ;; Remove any old next/prev buttons.
3911 (when (gnus-visual-p 'page-marker)
3912 (let ((buffer-read-only nil))
3913 (gnus-remove-text-with-property 'gnus-prev)
3914 (gnus-remove-text-with-property 'gnus-next)))
3917 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3919 (re-search-forward page-delimiter nil 'move arg)))
3920 (goto-char (match-end 0)))
3923 (if (re-search-forward page-delimiter nil 'move)
3926 (when (and (gnus-visual-p 'page-marker)
3927 (not (= (point-min) 1)))
3929 (goto-char (point-min))
3930 (gnus-insert-prev-page-button)))
3931 (when (and (gnus-visual-p 'page-marker)
3932 (< (+ (point-max) 2) (buffer-size)))
3934 (goto-char (point-max))
3935 (gnus-insert-next-page-button)))))
3937 ;; Article mode commands
3939 (defun gnus-article-goto-next-page ()
3940 "Show the next page of the article."
3942 (when (gnus-article-next-page)
3943 (goto-char (point-min))
3944 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3946 (defun gnus-article-goto-prev-page ()
3947 "Show the next page of the article."
3949 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3950 (gnus-article-prev-page nil)))
3952 (defun gnus-article-next-page (&optional lines)
3953 "Show the next page of the current article.
3954 If end of article, return non-nil. Otherwise return nil.
3955 Argument LINES specifies lines to be scrolled up."
3957 (let ((start (window-start))
3958 end-of-buffer end-of-page)
3960 (move-to-window-line -1)
3961 (if (<= (point) start)
3964 (setq start (point)))
3967 (unless (or (cond ((eq (1+ (buffer-size)) (point))
3968 (and (pos-visible-in-window-p)
3969 (setq end-of-buffer t)))
3971 (setq end-of-page t)))
3973 (move-to-window-line lines)
3974 (unless (search-backward "\n\n" nil t)
3975 (setq start (point)))))
3976 (cond (end-of-buffer t)
3978 (gnus-narrow-to-page 1)
3982 (set-window-start (selected-window) start)
3983 (let (window-pixel-scroll-increment)
3987 (defun gnus-article-prev-page (&optional lines)
3988 "Show previous page of current article.
3989 Argument LINES specifies lines to be scrolled down."
3991 (let (beginning-of-buffer beginning-of-page)
3993 (move-to-window-line 0)
3994 (cond ((eq 1 (point))
3995 (setq beginning-of-buffer t))
3997 (setq beginning-of-page t))))
3998 (cond (beginning-of-buffer)
4000 (gnus-narrow-to-page -1))
4003 (let (window-pixel-scroll-increment)
4004 (scroll-down lines))
4005 (beginning-of-buffer
4006 (goto-char (point-min))))))))
4008 (defun gnus-article-refer-article ()
4009 "Read article specified by message-id around point."
4011 (let ((point (point)))
4012 (search-forward ">" nil t) ;Move point to end of "<....>".
4013 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4014 (let ((message-id (match-string 1)))
4016 (set-buffer gnus-summary-buffer)
4017 (gnus-summary-refer-article message-id))
4019 (error "No references around point"))))
4021 (defun gnus-article-show-summary ()
4022 "Reconfigure windows to show summary buffer."
4024 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4025 (error "There is no summary buffer for this article buffer")
4026 (gnus-article-set-globals)
4027 (gnus-configure-windows 'article)
4028 (gnus-summary-goto-subject gnus-current-article)
4029 (gnus-summary-position-point)))
4031 (defun gnus-article-describe-briefly ()
4032 "Describe article mode commands briefly."
4034 (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")))
4036 (defun gnus-article-summary-command ()
4037 "Execute the last keystroke in the summary buffer."
4039 (let ((obuf (current-buffer))
4040 (owin (current-window-configuration))
4042 (switch-to-buffer gnus-article-current-summary 'norecord)
4043 (setq func (lookup-key (current-local-map) (this-command-keys)))
4044 (call-interactively func)
4046 (set-window-configuration owin)
4047 (set-window-point (get-buffer-window (current-buffer)) (point))))
4049 (defun gnus-article-summary-command-nosave ()
4050 "Execute the last keystroke in the summary buffer."
4053 (pop-to-buffer gnus-article-current-summary 'norecord)
4054 (setq func (lookup-key (current-local-map) (this-command-keys)))
4055 (call-interactively func)))
4057 (defun gnus-article-check-buffer ()
4058 "Beep if not in an article buffer."
4059 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4060 (error "Command invoked outside of a Gnus article buffer")))
4062 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4063 "Read a summary buffer key sequence and execute it from the article buffer."
4065 (gnus-article-check-buffer)
4067 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4068 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4069 "=" "^" "\M-^" "|"))
4075 '("n" "Gn" "p" "Gp"))
4078 (set-buffer gnus-article-current-summary)
4079 (let (gnus-pick-mode)
4080 (push (or key last-command-event) unread-command-events)
4081 (setq keys (static-if (featurep 'xemacs)
4082 (events-to-keys (read-key-sequence nil))
4083 (read-key-sequence nil)))))
4086 (if (or (member keys nosaves)
4087 (member keys nosave-but-article)
4088 (member keys nosave-in-article))
4090 (save-window-excursion
4091 (pop-to-buffer gnus-article-current-summary 'norecord)
4092 ;; We disable the pick minor mode commands.
4093 (let (gnus-pick-mode)
4094 (setq func (lookup-key (current-local-map) keys))))
4098 (unless (member keys nosave-in-article)
4099 (set-buffer gnus-article-current-summary))
4100 (call-interactively func)
4101 (setq new-sum-point (point)))
4102 (when (member keys nosave-but-article)
4103 (pop-to-buffer gnus-article-buffer 'norecord)))
4104 ;; These commands should restore window configuration.
4105 (let ((obuf (current-buffer))
4106 (owin (current-window-configuration))
4108 (summary gnus-article-current-summary)
4109 func in-buffer selected)
4110 (if not-restore-window
4111 (pop-to-buffer summary 'norecord)
4112 (switch-to-buffer summary 'norecord))
4113 (setq in-buffer (current-buffer))
4114 ;; We disable the pick minor mode commands.
4115 (if (setq func (let (gnus-pick-mode)
4116 (lookup-key (current-local-map) keys)))
4118 (call-interactively func)
4119 (setq new-sum-point (point)))
4121 (when (eq in-buffer (current-buffer))
4122 (setq selected (gnus-summary-select-article))
4124 (unless not-restore-window
4125 (set-window-configuration owin))
4126 (when (eq selected 'old)
4128 (set-window-start (get-buffer-window (current-buffer))
4130 (set-window-point (get-buffer-window (current-buffer))
4132 (let ((win (get-buffer-window gnus-article-current-summary)))
4134 (set-window-point win new-sum-point))))))))
4136 (defun gnus-article-hide (&optional arg force)
4137 "Hide all the gruft in the current article.
4138 This means that PGP stuff, signatures, cited text and (some)
4139 headers will be hidden.
4140 If given a prefix, show the hidden text instead."
4141 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4142 (gnus-article-hide-headers arg)
4143 (gnus-article-hide-list-identifiers arg)
4144 (gnus-article-hide-pgp arg)
4145 (gnus-article-hide-citation-maybe arg force)
4146 (gnus-article-hide-signature arg))
4148 (defun gnus-article-maybe-highlight ()
4149 "Do some article highlighting if article highlighting is requested."
4150 (when (gnus-visual-p 'article-highlight 'highlight)
4151 (gnus-article-highlight-some)))
4153 (defun gnus-check-group-server ()
4154 ;; Make sure the connection to the server is alive.
4155 (unless (gnus-server-opened
4156 (gnus-find-method-for-group gnus-newsgroup-name))
4157 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4158 (gnus-request-group gnus-newsgroup-name t)))
4160 (defun gnus-request-article-this-buffer (article group)
4161 "Get an article and insert it into this buffer."
4162 (let (do-update-line sparse-header)
4166 (gnus-kill-all-overlays)
4167 (setq group (or group gnus-newsgroup-name))
4169 ;; Using `gnus-request-article' directly will insert the article into
4170 ;; `nntp-server-buffer' - so we'll save some time by not having to
4171 ;; copy it from the server buffer into the article buffer.
4173 ;; We only request an article by message-id when we do not have the
4174 ;; headers for it, so we'll have to get those.
4175 (when (stringp article)
4176 (gnus-read-header article))
4178 ;; If the article number is negative, that means that this article
4179 ;; doesn't belong in this newsgroup (possibly), so we find its
4180 ;; message-id and request it by id instead of number.
4181 (when (and (numberp article)
4183 (get-buffer gnus-summary-buffer)
4184 (gnus-buffer-exists-p gnus-summary-buffer))
4186 (set-buffer gnus-summary-buffer)
4187 (let ((header (gnus-summary-article-header article)))
4190 ((memq article gnus-newsgroup-sparse)
4191 ;; This is a sparse gap article.
4192 (setq do-update-line article)
4193 (setq article (mail-header-id header))
4194 (setq sparse-header (gnus-read-header article))
4195 (setq gnus-newsgroup-sparse
4196 (delq article gnus-newsgroup-sparse)))
4198 ;; It's a real article.
4199 (setq article (mail-header-id header)))
4201 ;; It is an extracted pseudo-article.
4202 (setq article 'pseudo)
4203 (gnus-request-pseudo-article header))))
4205 (let ((method (gnus-find-method-for-group
4206 gnus-newsgroup-name)))
4207 (when (and (eq (car method) 'nneething)
4209 (let ((dir (expand-file-name
4210 (mail-header-subject header)
4211 (file-name-as-directory
4212 (or (cadr (assq 'nneething-address method))
4214 (when (file-directory-p dir)
4215 (setq article 'nneething)
4216 (gnus-group-enter-directory dir))))))))
4219 ;; Refuse to select canceled articles.
4220 ((and (numberp article)
4222 (get-buffer gnus-summary-buffer)
4223 (gnus-buffer-exists-p gnus-summary-buffer)
4224 (eq (cdr (save-excursion
4225 (set-buffer gnus-summary-buffer)
4226 (assq article gnus-newsgroup-reads)))
4227 gnus-canceled-mark))
4229 ;; Check the backlog.
4230 ((and gnus-keep-backlog
4231 (gnus-backlog-request-article group article (current-buffer)))
4233 ;; Check asynchronous pre-fetch.
4234 ((gnus-async-request-fetched-article group article (current-buffer))
4235 (gnus-async-prefetch-next group article gnus-summary-buffer)
4236 (when (and (numberp article) gnus-keep-backlog)
4237 (gnus-backlog-enter-article group article (current-buffer)))
4240 ((and gnus-use-cache
4242 (gnus-cache-request-article article group))
4244 ;; Get the article and put into the article buffer.
4245 ((or (stringp article)
4247 (let ((gnus-override-method gnus-override-method)
4248 (methods (and (stringp article)
4249 gnus-refer-article-method))
4251 (buffer-read-only nil))
4256 (when (and (null gnus-override-method)
4258 (setq gnus-override-method (pop methods)))
4260 (when (eq gnus-override-method 'current)
4261 (setq gnus-override-method gnus-current-select-method))
4263 (gnus-kill-all-overlays)
4264 (let ((gnus-newsgroup-name group))
4265 (gnus-check-group-server))
4266 (when (gnus-request-article article group (current-buffer))
4267 (when (numberp article)
4268 (gnus-async-prefetch-next group article
4269 gnus-summary-buffer)
4270 (when gnus-keep-backlog
4271 (gnus-backlog-enter-article
4272 group article (current-buffer))))
4273 (setq result 'article))
4276 (setq gnus-override-method (pop methods))
4277 (setq result 'done))))
4278 (and (eq result 'article) 'article)))
4282 ;; Associate this article with the current summary buffer.
4283 (setq gnus-article-current-summary gnus-summary-buffer)
4285 ;; Take the article from the original article buffer
4286 ;; and place it in the buffer it's supposed to be in.
4287 (when (and (get-buffer gnus-article-buffer)
4288 (equal (buffer-name (current-buffer))
4289 (buffer-name (get-buffer gnus-article-buffer))))
4291 (if (get-buffer gnus-original-article-buffer)
4292 (set-buffer gnus-original-article-buffer)
4293 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4294 (set-buffer-multibyte nil)
4295 (buffer-disable-undo)
4296 (setq major-mode 'gnus-original-article-mode)
4297 (setq buffer-read-only t))
4298 (let (buffer-read-only)
4300 (insert-buffer-substring gnus-article-buffer))
4301 (setq gnus-original-article (cons group article)))
4304 (run-hooks 'gnus-article-decode-hook)
4305 ;; Mark article as decoded or not.
4306 (setq gnus-article-decoded-p gnus-article-decode-hook))
4308 ;; Update sparse articles.
4309 (when (and do-update-line
4310 (or (numberp article)
4312 (let ((buf (current-buffer)))
4313 (set-buffer gnus-summary-buffer)
4314 (gnus-summary-update-article do-update-line sparse-header)
4315 (gnus-summary-goto-subject do-update-line nil t)
4316 (set-window-point (get-buffer-window (current-buffer) t)
4318 (set-buffer buf))))))
4324 (defcustom gnus-article-edit-mode-hook nil
4325 "Hook run in article edit mode buffers."
4326 :group 'gnus-article-various
4329 (defcustom gnus-article-edit-article-setup-function
4330 'gnus-article-mime-edit-article-setup
4331 "Function called to setup an editing article buffer."
4332 :group 'gnus-article-various
4335 (defvar gnus-article-edit-done-function nil)
4337 (defvar gnus-article-edit-mode-map nil)
4339 ;; Should we be using derived.el for this?
4340 (unless gnus-article-edit-mode-map
4341 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4342 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4344 (gnus-define-keys gnus-article-edit-mode-map
4345 "\C-c\C-c" gnus-article-edit-done
4346 "\C-c\C-k" gnus-article-edit-exit)
4348 (gnus-define-keys (gnus-article-edit-wash-map
4349 "\C-c\C-w" gnus-article-edit-mode-map)
4350 "f" gnus-article-edit-full-stops))
4352 (defun gnus-article-edit-mode ()
4353 "Major mode for editing articles.
4354 This is an extended text-mode.
4356 \\{gnus-article-edit-mode-map}"
4358 (setq major-mode 'gnus-article-edit-mode)
4359 (setq mode-name "Article Edit")
4360 (use-local-map gnus-article-edit-mode-map)
4361 (make-local-variable 'gnus-article-edit-done-function)
4362 (make-local-variable 'gnus-prev-winconf)
4363 (setq buffer-read-only nil)
4364 (buffer-enable-undo)
4366 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4368 (defun gnus-article-edit (&optional force)
4369 "Edit the current article.
4370 This will have permanent effect only in mail groups.
4371 If FORCE is non-nil, allow editing of articles even in read-only
4374 (when (and (not force)
4375 (gnus-group-read-only-p))
4376 (error "The current newsgroup does not support article editing"))
4377 (gnus-article-date-original)
4378 (gnus-article-edit-article
4380 `(lambda (no-highlight)
4382 (gnus-summary-edit-article-done
4383 ,(or (mail-header-references gnus-current-headers) "")
4384 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4386 (defun gnus-article-edit-article (start-func exit-func)
4387 "Start editing the contents of the current article buffer."
4388 (let ((winconf (current-window-configuration)))
4389 (set-buffer gnus-article-buffer)
4390 (gnus-article-edit-mode)
4391 (funcall start-func)
4392 (gnus-configure-windows 'edit-article)
4393 (setq gnus-article-edit-done-function exit-func)
4394 (setq gnus-prev-winconf winconf)
4395 (when gnus-article-edit-article-setup-function
4396 (funcall gnus-article-edit-article-setup-function))
4397 (gnus-message 6 "C-c C-c to end edits")))
4399 (defun gnus-article-edit-done (&optional arg)
4400 "Update the article edits and exit."
4405 (when (article-goto-body)
4406 (let ((lines (count-lines (point) (point-max)))
4407 (length (- (point-max) (point)))
4408 (case-fold-search t)
4409 (body (copy-marker (point))))
4410 (goto-char (point-min))
4411 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4412 (delete-region (match-beginning 1) (match-end 1))
4413 (insert (number-to-string length)))
4414 (goto-char (point-min))
4415 (when (re-search-forward
4416 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4417 (delete-region (match-beginning 1) (match-end 1))
4418 (insert (number-to-string length)))
4419 (goto-char (point-min))
4420 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4421 (delete-region (match-beginning 1) (match-end 1))
4422 (insert (number-to-string lines)))))))
4423 (let ((func gnus-article-edit-done-function)
4424 (buf (current-buffer))
4425 (start (window-start)))
4426 (remove-hook 'gnus-article-mode-hook
4427 'gnus-article-mime-edit-article-unwind)
4428 (gnus-article-edit-exit)
4431 (let ((buffer-read-only nil))
4433 ;; The cache and backlog have to be flushed somewhat.
4434 (when gnus-keep-backlog
4435 (gnus-backlog-remove-article
4436 (car gnus-article-current) (cdr gnus-article-current)))
4437 ;; Flush original article as well.
4439 (when (get-buffer gnus-original-article-buffer)
4440 (set-buffer gnus-original-article-buffer)
4441 (setq gnus-original-article nil)))
4442 (when gnus-use-cache
4443 (gnus-cache-update-article
4444 (car gnus-article-current) (cdr gnus-article-current))))
4446 (set-window-start (get-buffer-window buf) start)
4447 (set-window-point (get-buffer-window buf) (point))))
4449 (defun gnus-article-edit-exit ()
4450 "Exit the article editing without updating."
4452 ;; We remove all text props from the article buffer.
4453 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4454 (curbuf (current-buffer))
4456 (window-start (window-start)))
4459 (let ((winconf gnus-prev-winconf))
4461 (set-window-configuration winconf)
4462 ;; Tippy-toe some to make sure that point remains where it was.
4463 (save-current-buffer
4465 (set-window-start (get-buffer-window (current-buffer)) window-start)
4468 (defun gnus-article-edit-full-stops ()
4469 "Interactively repair spacing at end of sentences."
4472 (goto-char (point-min))
4473 (search-forward-regexp "^$" nil t)
4474 (let ((case-fold-search nil))
4475 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4478 ;;; Article editing with MIME-Edit
4481 (defcustom gnus-article-mime-edit-article-setup-hook nil
4482 "Hook run after setting up a MIME editing article buffer."
4483 :group 'gnus-article-various
4486 (defun gnus-article-mime-edit-article-unwind ()
4487 "Unwind `gnus-article-buffer' if article editing was given up."
4488 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4489 (when mime-edit-mode-flag
4490 (mime-edit-exit 'nomime 'no-error)
4492 (when (featurep 'font-lock)
4493 (setq font-lock-defaults nil)
4494 (font-lock-mode 0)))
4496 (defun gnus-article-mime-edit-article-setup ()
4497 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4498 after replacing with the original article."
4499 (setq gnus-show-mime t)
4500 (setq gnus-article-edit-done-function
4501 `(lambda (&rest args)
4502 (when mime-edit-mode-flag
4505 (goto-char (point-min))
4506 (let (case-fold-search)
4507 (when (re-search-forward
4508 (format "^%s$" (regexp-quote mail-header-separator))
4510 (replace-match "")))
4511 (when (featurep 'font-lock)
4512 (setq font-lock-defaults nil)
4514 (apply ,gnus-article-edit-done-function args)
4515 (set-buffer gnus-original-article-buffer)
4517 (insert-buffer gnus-article-buffer)
4518 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4519 (gnus-article-prepare-display)))
4520 (substitute-key-definition
4521 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4522 gnus-article-edit-mode-map)
4524 (insert-buffer gnus-original-article-buffer)
4526 (when (featurep 'font-lock)
4527 (set (make-local-variable 'font-lock-defaults)
4528 '(message-font-lock-keywords t))
4529 (font-lock-set-defaults)
4530 (turn-on-font-lock))
4531 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4532 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4534 (defun gnus-article-mime-edit-exit ()
4535 "Exit the article MIME editing without updating."
4537 (let ((winconf gnus-prev-winconf)
4539 (when mime-edit-mode-flag
4542 (goto-char (point-min))
4543 (let (case-fold-search)
4544 (when (re-search-forward
4545 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4546 (replace-match "")))
4547 (when (featurep 'font-lock)
4548 (setq font-lock-defaults nil)
4550 ;; We remove all text props from the article buffer.
4551 (setq buf (format "%s" (buffer-string)))
4552 (set-buffer (get-buffer-create gnus-original-article-buffer))
4555 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4556 (gnus-article-prepare-display)
4557 (set-window-configuration winconf)))
4560 ;;; Article highlights
4563 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4565 ;;; Internal Variables:
4567 (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\\)\\)"
4568 "Regular expression that matches URLs."
4569 :group 'gnus-article-buttons
4572 (defcustom gnus-button-alist
4573 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4574 0 t gnus-button-message-id 2)
4575 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4576 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4578 gnus-button-fetch-group 4)
4579 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4580 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4581 t gnus-button-message-id 3)
4582 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4583 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4584 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4585 ;; This is how URLs _should_ be embedded in text...
4586 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4588 (,gnus-button-url-regexp 0 t browse-url 0))
4589 "*Alist of regexps matching buttons in article bodies.
4591 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4592 REGEXP: is the string matching text around the button,
4593 BUTTON: is the number of the regexp grouping actually matching the button,
4594 FORM: is a lisp expression which must eval to true for the button to
4596 CALLBACK: is the function to call when the user push this button, and each
4597 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4599 CALLBACK can also be a variable, in that case the value of that
4600 variable it the real callback function."
4601 :group 'gnus-article-buttons
4602 :type '(repeat (list regexp
4603 (integer :tag "Button")
4605 (function :tag "Callback")
4608 (integer :tag "Regexp group")))))
4610 (defcustom gnus-header-button-alist
4611 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4612 0 t gnus-button-message-id 0)
4613 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4614 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4615 0 t gnus-button-mailto 0)
4616 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4617 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4618 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4619 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4620 gnus-button-message-id 3))
4621 "*Alist of headers and regexps to match buttons in article heads.
4623 This alist is very similar to `gnus-button-alist', except that each
4624 alist has an additional HEADER element first in each entry:
4626 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4628 HEADER is a regexp to match a header. For a fuller explanation, see
4629 `gnus-button-alist'."
4630 :group 'gnus-article-buttons
4631 :group 'gnus-article-headers
4632 :type '(repeat (list (regexp :tag "Header")
4634 (integer :tag "Button")
4636 (function :tag "Callback")
4639 (integer :tag "Regexp group")))))
4641 (defvar gnus-button-regexp nil)
4642 (defvar gnus-button-marker-list nil)
4643 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4645 (defvar gnus-button-last nil)
4646 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4650 (defun gnus-article-push-button (event)
4651 "Check text under the mouse pointer for a callback function.
4652 If the text under the mouse pointer has a `gnus-callback' property,
4653 call it with the value of the `gnus-data' text property."
4655 (set-buffer (window-buffer (posn-window (event-start event))))
4656 (let* ((pos (posn-point (event-start event)))
4657 (data (get-text-property pos 'gnus-data))
4658 (fun (get-text-property pos 'gnus-callback)))
4661 (funcall fun data))))
4663 (defun gnus-article-press-button ()
4664 "Check text at point for a callback function.
4665 If the text at point has a `gnus-callback' property,
4666 call it with the value of the `gnus-data' text property."
4668 (let* ((data (get-text-property (point) 'gnus-data))
4669 (fun (get-text-property (point) 'gnus-callback)))
4671 (funcall fun data))))
4673 (defun gnus-article-prev-button (n)
4674 "Move point to N buttons backward.
4675 If N is negative, move forward instead."
4677 (gnus-article-next-button (- n)))
4679 (defun gnus-article-next-button (n)
4680 "Move point to N buttons forward.
4681 If N is negative, move backward instead."
4683 (let ((function (if (< n 0) 'previous-single-property-change
4684 'next-single-property-change))
4685 (inhibit-point-motion-hooks t)
4687 (limit (if (< n 0) (point-min) (point-max))))
4689 (while (and (not (= limit (point)))
4691 ;; Skip past the current button.
4692 (when (get-text-property (point) 'gnus-callback)
4693 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4694 ;; Go to the next (or previous) button.
4695 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4696 ;; Put point at the start of the button.
4697 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4698 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4699 ;; Skip past intangible buttons.
4700 (when (get-text-property (point) 'intangible)
4704 (gnus-message 5 "No more buttons"))
4707 (defun gnus-article-highlight (&optional force)
4708 "Highlight current article.
4709 This function calls `gnus-article-highlight-headers',
4710 `gnus-article-highlight-citation',
4711 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4712 do the highlighting. See the documentation for those functions."
4713 (interactive (list 'force))
4714 (gnus-article-highlight-headers)
4715 (gnus-article-highlight-citation force)
4716 (gnus-article-highlight-signature)
4717 (gnus-article-add-buttons force)
4718 (gnus-article-add-buttons-to-head))
4720 (defun gnus-article-highlight-some (&optional force)
4721 "Highlight current article.
4722 This function calls `gnus-article-highlight-headers',
4723 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4724 do the highlighting. See the documentation for those functions."
4725 (interactive (list 'force))
4726 (gnus-article-highlight-headers)
4727 (gnus-article-highlight-signature)
4728 (gnus-article-add-buttons))
4730 (defun gnus-article-highlight-headers ()
4731 "Highlight article headers as specified by `gnus-header-face-alist'."
4734 (set-buffer gnus-article-buffer)
4736 (let ((alist gnus-header-face-alist)
4737 (buffer-read-only nil)
4738 (case-fold-search t)
4739 (inhibit-point-motion-hooks t)
4740 entry regexp header-face field-face from hpoints fpoints)
4741 (article-narrow-to-head)
4742 (while (setq entry (pop alist))
4743 (goto-char (point-min))
4744 (setq regexp (concat "^\\("
4745 (if (string-equal "" (nth 0 entry))
4749 header-face (nth 1 entry)
4750 field-face (nth 2 entry))
4751 (while (and (re-search-forward regexp nil t)
4755 (unless (search-forward ":" nil t)
4757 (when (and header-face
4758 (not (memq (point) hpoints)))
4759 (push (point) hpoints)
4760 (gnus-put-text-property from (point) 'face header-face))
4761 (when (and field-face
4762 (not (memq (setq from (point)) fpoints)))
4764 (if (re-search-forward "^[^ \t]" nil t)
4766 (goto-char (point-max)))
4767 (gnus-put-text-property from (point) 'face field-face))))))))
4769 (defun gnus-article-highlight-signature ()
4770 "Highlight the signature in an article.
4771 It does this by highlighting everything after
4772 `gnus-signature-separator' using `gnus-signature-face'."
4774 (when gnus-signature-face
4776 (set-buffer gnus-article-buffer)
4777 (let ((buffer-read-only nil)
4778 (inhibit-point-motion-hooks t))
4780 (when (gnus-article-narrow-to-signature)
4781 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4782 'face gnus-signature-face)))))))
4784 (defun gnus-article-buttonize-signature ()
4785 "Add button to the signature."
4788 (set-buffer gnus-article-buffer)
4789 (let ((buffer-read-only nil)
4790 (inhibit-point-motion-hooks t))
4791 (when (gnus-article-search-signature)
4792 (gnus-article-add-button (match-beginning 0) (match-end 0)
4793 'gnus-signature-toggle
4794 (set-marker (make-marker)
4795 (1+ (match-end 0))))))))
4797 (defun gnus-button-in-region-p (b e prop)
4798 "Say whether PROP exists in the region."
4799 (text-property-not-all b e prop nil))
4801 (defun gnus-article-add-buttons (&optional force)
4802 "Find external references in the article and make buttons of them.
4803 \"External references\" are things like Message-IDs and URLs, as
4804 specified by `gnus-button-alist'."
4805 (interactive (list 'force))
4807 (set-buffer gnus-article-buffer)
4808 (let ((buffer-read-only nil)
4809 (inhibit-point-motion-hooks t)
4810 (case-fold-search t)
4811 (alist gnus-button-alist)
4813 ;; Remove all old markers.
4814 (let (marker entry new-list)
4815 (while (setq marker (pop gnus-button-marker-list))
4816 (if (or (< marker (point-min)) (>= marker (point-max)))
4817 (push marker new-list)
4819 (when (setq entry (gnus-button-entry))
4820 (put-text-property (match-beginning (nth 1 entry))
4821 (match-end (nth 1 entry))
4822 'gnus-callback nil))
4823 (set-marker marker nil)))
4824 (setq gnus-button-marker-list new-list))
4825 ;; We skip the headers.
4828 (while (setq entry (pop alist))
4829 (setq regexp (car entry))
4831 (while (re-search-forward regexp nil t)
4832 (let* ((start (and entry (match-beginning (nth 1 entry))))
4833 (end (and entry (match-end (nth 1 entry))))
4834 (from (match-beginning 0)))
4835 (when (and (or (eq t (nth 2 entry))
4836 (eval (nth 2 entry)))
4837 (not (gnus-button-in-region-p
4838 start end 'gnus-callback)))
4839 ;; That optional form returned non-nil, so we add the
4841 (gnus-article-add-button
4842 start end 'gnus-button-push
4843 (car (push (set-marker (make-marker) from)
4844 gnus-button-marker-list))))))))))
4846 ;; Add buttons to the head of an article.
4847 (defun gnus-article-add-buttons-to-head ()
4848 "Add buttons to the head of the article."
4851 (set-buffer gnus-article-buffer)
4853 (let ((buffer-read-only nil)
4854 (inhibit-point-motion-hooks t)
4855 (case-fold-search t)
4856 (alist gnus-header-button-alist)
4858 (article-narrow-to-head)
4860 ;; Each alist entry.
4861 (setq entry (car alist)
4863 (goto-char (point-min))
4864 (while (re-search-forward (car entry) nil t)
4865 ;; Each header matching the entry.
4866 (setq beg (match-beginning 0))
4867 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4868 (match-beginning 0))
4871 (while (re-search-forward (nth 1 entry) end t)
4872 ;; Each match within a header.
4873 (let* ((entry (cdr entry))
4874 (start (match-beginning (nth 1 entry)))
4875 (end (match-end (nth 1 entry)))
4876 (form (nth 2 entry)))
4877 (goto-char (match-end 0))
4879 (gnus-article-add-button
4880 start end (nth 3 entry)
4881 (buffer-substring (match-beginning (nth 4 entry))
4882 (match-end (nth 4 entry)))))))
4883 (goto-char end)))))))
4885 ;;; External functions:
4887 (defun gnus-article-add-button (from to fun &optional data)
4888 "Create a button between FROM and TO with callback FUN and data DATA."
4889 (when gnus-article-button-face
4890 (gnus-overlay-put (gnus-make-overlay from to)
4891 'face gnus-article-button-face))
4892 (gnus-add-text-properties
4894 (nconc (and gnus-article-mouse-face
4895 (list gnus-mouse-face-prop gnus-article-mouse-face))
4896 (list 'gnus-callback fun)
4897 (and data (list 'gnus-data data))))
4898 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4899 :button-keymap gnus-widget-button-keymap))
4901 ;;; Internal functions:
4903 (defun gnus-article-set-globals ()
4905 (set-buffer gnus-summary-buffer)
4906 (gnus-set-global-variables)))
4908 (defun gnus-signature-toggle (end)
4910 (set-buffer gnus-article-buffer)
4911 (let ((buffer-read-only nil)
4912 (inhibit-point-motion-hooks t)
4913 (limit (next-single-property-change end 'mime-view-entity
4915 (if (get-text-property end 'invisible)
4916 (gnus-article-unhide-text end limit)
4917 (gnus-article-hide-text end limit gnus-hidden-properties)))))
4919 (defun gnus-button-entry ()
4920 ;; Return the first entry in `gnus-button-alist' matching this place.
4921 (let ((alist gnus-button-alist)
4924 (setq entry (pop alist))
4925 (if (looking-at (car entry))
4930 (defun gnus-button-push (marker)
4931 ;; Push button starting at MARKER.
4934 (let* ((entry (gnus-button-entry))
4935 (inhibit-point-motion-hooks t)
4937 (args (mapcar (lambda (group)
4938 (let ((string (match-string group)))
4939 (gnus-set-text-properties
4940 0 (length string) nil string)
4947 (fboundp (symbol-value fun)))
4948 (apply (symbol-value fun) args))
4950 (gnus-message 1 "You must define `%S' to use this button"
4951 (cons fun args)))))))
4953 (defun gnus-button-message-id (message-id)
4956 (set-buffer gnus-summary-buffer)
4957 (gnus-summary-refer-article message-id)))
4959 (defun gnus-button-fetch-group (address)
4960 "Fetch GROUP specified by ADDRESS."
4961 (if (not (string-match "[:/]" address))
4962 ;; This is just a simple group url.
4963 (gnus-group-read-ephemeral-group address gnus-select-method)
4964 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4966 (error "Can't parse %s" address)
4967 (gnus-group-read-ephemeral-group
4968 (match-string 4 address)
4969 `(nntp ,(match-string 1 address)
4970 (nntp-address ,(match-string 1 address))
4971 (nntp-port-number ,(if (match-end 3)
4972 (match-string 3 address)
4975 (defun gnus-url-parse-query-string (query &optional downcase)
4976 (let (retval pairs cur key val)
4977 (setq pairs (split-string query "&"))
4979 (setq cur (car pairs)
4981 (if (not (string-match "=" cur))
4983 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4984 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4986 (setq key (downcase key)))
4987 (setq cur (assoc key retval))
4989 (setcdr cur (cons val (cdr cur)))
4990 (setq retval (cons (list key val) retval)))))
4993 (defun gnus-url-unhex (x)
5000 (defun gnus-url-unhex-string (str &optional allow-newlines)
5001 "Remove %XXX embedded spaces, etc in a url.
5002 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5003 decoding of carriage returns and line feeds in the string, which is normally
5004 forbidden in URL encoding."
5005 (setq str (or str ""))
5007 (case-fold-search t))
5008 (while (string-match "%[0-9a-f][0-9a-f]" str)
5009 (let* ((start (match-beginning 0))
5010 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5012 (gnus-url-unhex (elt str (+ start 2))))))
5014 tmp (substring str 0 start)
5017 (char-to-string code))
5018 ((or (= code ?\n) (= code ?\r))
5020 (t (char-to-string code))))
5021 str (substring str (match-end 0)))))
5022 (setq tmp (concat tmp str))
5025 (defun gnus-url-mailto (url)
5026 ;; Send mail to someone
5027 (when (string-match "mailto:/*\\(.*\\)" url)
5028 (setq url (substring url (match-beginning 1) nil)))
5029 (let (to args subject func)
5030 (if (string-match (regexp-quote "?") url)
5031 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5032 args (gnus-url-parse-query-string
5033 (substring url (match-end 0) nil) t))
5034 (setq to (gnus-url-unhex-string url)))
5035 (setq args (cons (list "to" to) args)
5036 subject (cdr-safe (assoc "subject" args)))
5037 (gnus-setup-message 'reply
5040 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5043 (message-position-on-field (caar args)))
5044 (insert (mapconcat 'identity (cdar args) ", "))
5045 (setq args (cdr args)))
5048 (message-goto-subject)))))
5050 (defun gnus-button-mailto (address)
5052 (set-buffer (gnus-copy-article-buffer))
5053 (gnus-setup-message 'reply
5054 (message-reply address)))
5056 (defun gnus-button-reply (address)
5057 ;; Reply to ADDRESS.
5058 (gnus-setup-message 'reply
5059 (message-reply address)))
5061 (defun gnus-button-embedded-url (address)
5063 (browse-url (gnus-strip-whitespace address)))
5065 (defun gnus-article-smiley-display ()
5066 "Display \"smileys\" as small graphical icons."
5067 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5069 ;;; Next/prev buttons in the article buffer.
5071 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5072 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5074 (defvar gnus-prev-page-map nil)
5075 (unless gnus-prev-page-map
5076 (setq gnus-prev-page-map (make-sparse-keymap))
5077 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5078 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5080 (static-if (featurep 'xemacs)
5081 (defun gnus-insert-prev-page-button ()
5082 (let ((buffer-read-only nil))
5084 gnus-prev-page-line-format nil
5085 `(gnus-prev t local-map ,gnus-prev-page-map
5086 gnus-callback gnus-article-button-prev-page
5087 article-type annotation))))
5088 (defun gnus-insert-prev-page-button ()
5089 (let ((buffer-read-only nil)
5090 (situation (get-text-property (point-min) 'mime-view-situation)))
5091 (set-keymap-parent gnus-prev-page-map (current-local-map))
5093 gnus-prev-page-line-format nil
5094 `(gnus-prev t local-map ,gnus-prev-page-map
5095 gnus-callback gnus-article-button-prev-page
5096 article-type annotation
5097 mime-view-situation ,situation))))
5100 (defvar gnus-next-page-map nil)
5101 (unless gnus-next-page-map
5102 (setq gnus-next-page-map (make-sparse-keymap))
5103 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5104 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5106 (defun gnus-button-next-page ()
5107 "Go to the next page."
5109 (let ((win (selected-window)))
5110 (select-window (get-buffer-window gnus-article-buffer t))
5111 (gnus-article-next-page)
5112 (select-window win)))
5114 (defun gnus-button-prev-page ()
5115 "Go to the prev page."
5117 (let ((win (selected-window)))
5118 (select-window (get-buffer-window gnus-article-buffer t))
5119 (gnus-article-prev-page)
5120 (select-window win)))
5122 (static-if (featurep 'xemacs)
5123 (defun gnus-insert-next-page-button ()
5124 (let ((buffer-read-only nil))
5125 (gnus-eval-format gnus-next-page-line-format nil
5127 t local-map ,gnus-next-page-map
5128 gnus-callback gnus-article-button-next-page
5129 article-type annotation))))
5130 (defun gnus-insert-next-page-button ()
5131 (let ((buffer-read-only nil)
5132 (situation (get-text-property (point-min) 'mime-view-situation)))
5133 (set-keymap-parent gnus-next-page-map (current-local-map))
5134 (gnus-eval-format gnus-next-page-line-format nil
5136 t local-map ,gnus-next-page-map
5137 gnus-callback gnus-article-button-next-page
5138 article-type annotation
5139 mime-view-situation ,situation))))
5142 (defun gnus-article-button-next-page (arg)
5143 "Go to the next page."
5145 (let ((win (selected-window)))
5146 (select-window (get-buffer-window gnus-article-buffer t))
5147 (gnus-article-next-page)
5148 (select-window win)))
5150 (defun gnus-article-button-prev-page (arg)
5151 "Go to the prev page."
5153 (let ((win (selected-window)))
5154 (select-window (get-buffer-window gnus-article-buffer t))
5155 (gnus-article-prev-page)
5156 (select-window win)))
5158 (defvar gnus-decode-header-methods
5159 '(mail-decode-encoded-word-region)
5160 "List of methods used to decode headers.
5162 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5163 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5164 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5165 whose names match REGEXP.
5168 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5169 mail-decode-encoded-word-region
5170 (\"chinese\" . rfc1843-decode-region))
5173 (defvar gnus-decode-header-methods-cache nil)
5175 (defun gnus-multi-decode-header (start end)
5176 "Apply the functions from `gnus-encoded-word-methods' that match."
5177 (unless (and gnus-decode-header-methods-cache
5178 (eq gnus-newsgroup-name
5179 (car gnus-decode-header-methods-cache)))
5180 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5183 (nconc gnus-decode-header-methods-cache (list x))
5184 (if (and gnus-newsgroup-name
5185 (string-match (car x) gnus-newsgroup-name))
5186 (nconc gnus-decode-header-methods-cache
5188 gnus-decode-header-methods))
5189 (let ((xlist gnus-decode-header-methods-cache))
5192 (narrow-to-region start end)
5194 (funcall (pop xlist) (point-min) (point-max))))))
5197 ;;; Treatment top-level handling.
5200 (defun gnus-treat-article (condition &optional part-number total-parts type)
5201 (let ((length (- (point-max) (point-min)))
5202 (alist gnus-treatment-function-alist)
5203 (article-goto-body-goes-to-point-min-p t)
5207 (let ((list gnus-article-treat-types))
5209 (when (string-match (pop list) type)
5210 (throw 'found t)))))))
5211 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5212 (entity (static-unless (featurep 'xemacs)
5213 (when (eq 'head condition)
5214 (get-text-property (point-min) 'mime-view-entity))))
5215 val elem buttonized)
5216 (gnus-run-hooks 'gnus-part-display-hook)
5217 (unless gnus-inhibit-treatment
5218 (while (setq elem (pop alist))
5221 (if (gnus-buffer-live-p gnus-summary-buffer)
5222 (set-buffer gnus-summary-buffer))
5223 (symbol-value (car elem))))
5224 (when (and (or (consp val)
5226 (gnus-treat-predicate val)
5227 (or (not (get (car elem) 'highlight))
5229 (when (and (not buttonized)
5231 '(gnus-treat-hide-signature
5232 gnus-treat-highlight-signature)))
5233 (gnus-article-buttonize-signature)
5234 (setq buttonized t))
5236 (funcall (cadr elem)))))
5237 ;; FSF Emacsen does not inherit the existing text properties
5238 ;; in the new text, so we should do it for `mime-view-entity'.
5239 (static-unless (featurep 'xemacs)
5241 (put-text-property (point-min) (point-max)
5242 'mime-view-entity entity))))))
5244 ;; Dynamic variables.
5245 (defvar part-number)
5246 (defvar total-parts)
5250 (defun gnus-treat-predicate (val)
5255 (stringp (car val)))
5256 (apply 'gnus-or (mapcar `(lambda (s)
5257 (string-match s ,(or gnus-newsgroup-name "")))
5260 (let ((pred (pop val)))
5263 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5265 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5267 (not (gnus-treat-predicate (car val))))
5269 (equal (car val) type))
5271 (error "%S is not a valid predicate" pred)))))
5281 (eq part-number total-parts))
5285 (error "%S is not a valid value" val))))
5291 (defun gnus-article-header-presentation-method (entity situation)
5292 (mime-insert-header entity)
5295 (set-alist 'mime-header-presentation-method-alist
5296 'gnus-original-article-mode
5297 #'gnus-article-header-presentation-method)
5299 (defun gnus-mime-preview-quitting-method ()
5300 (mime-preview-kill-buffer)
5301 (delete-other-windows)
5302 (gnus-article-show-summary)
5303 (gnus-summary-select-article gnus-show-all-headers t))
5305 (set-alist 'mime-preview-quitting-method-alist
5306 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5308 (set-alist 'mime-preview-following-method-alist
5309 'gnus-original-article-mode #'gnus-following-method)
5311 (set-alist 'mime-preview-over-to-previous-method-alist
5312 'gnus-original-article-mode
5314 (if (> (point-min) 1)
5315 (gnus-article-prev-page)
5316 (gnus-article-read-summary-keys
5317 nil (gnus-character-to-event ?P)))))
5319 (set-alist 'mime-preview-over-to-next-method-alist
5320 'gnus-original-article-mode'
5322 (if (< (point-max) (buffer-size))
5323 (gnus-article-next-page)
5324 (gnus-article-read-summary-keys
5325 nil (gnus-character-to-event ?N)))))
5335 (run-hooks 'gnus-art-load-hook)
5337 ;;; gnus-art.el ends here