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:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
150 "*All headers that do not match this regexp will be hidden.
151 This variable can also be a list of regexp of headers to remain visible.
152 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
153 :type '(repeat :value-to-internal (lambda (widget value)
154 (custom-split-regexp-maybe value))
155 :match (lambda (widget value)
157 (widget-editable-list-match widget value)))
159 :group 'gnus-article-hiding)
161 (defcustom gnus-sorted-header-list
162 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
163 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
164 "*This variable is a list of regular expressions.
165 If it is non-nil, headers that match the regular expressions will
166 be placed first in the article buffer in the sequence specified by
168 :type '(repeat regexp)
169 :group 'gnus-article-hiding)
171 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
172 "Headers that are only to be displayed if they have interesting data.
173 Possible values in this list are `empty', `newsgroups', `followup-to',
174 `reply-to', `date', `long-to', and `many-to'."
175 :type '(set (const :tag "Headers with no content." empty)
176 (const :tag "Newsgroups with only one group." newsgroups)
177 (const :tag "Followup-to identical to newsgroups." followup-to)
178 (const :tag "Reply-to identical to from." reply-to)
179 (const :tag "Date less than four days old." date)
180 (const :tag "Very long To and/or Cc header." long-to)
181 (const :tag "Multiple To and/or Cc headers." many-to))
182 :group 'gnus-article-hiding)
184 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
185 "Regexp matching signature separator.
186 This can also be a list of regexps. In that case, it will be checked
187 from head to tail looking for a separator. Searches will be done from
188 the end of the buffer."
189 :type '(repeat string)
190 :group 'gnus-article-signature)
192 (defcustom gnus-signature-limit nil
193 "Provide a limit to what is considered a signature.
194 If it is a number, no signature may not be longer (in characters) than
195 that number. If it is a floating point number, no signature may be
196 longer (in lines) than that number. If it is a function, the function
197 will be called without any parameters, and if it returns nil, there is
198 no signature in the buffer. If it is a string, it will be used as a
199 regexp. If it matches, the text in question is not a signature."
200 :type '(choice (integer :value 200)
202 (function :value fun)
203 (regexp :value ".*"))
204 :group 'gnus-article-signature)
206 (defcustom gnus-hidden-properties '(invisible t intangible t)
207 "Property list to use for hiding text."
209 :group 'gnus-article-hiding)
211 (defcustom gnus-article-x-face-command
213 ;; Fixme: This isn't the right thing for mixed graphical and and
214 ;; non-graphical frames in a session.
215 ;; gnus-xmas.el overrides this for XEmacs.
216 ((and (fboundp 'image-type-available-p)
217 (image-type-available-p 'xbm))
218 'gnus-article-display-xface)
219 ((and (not (featurep 'xemacs))
221 (module-installed-p 'x-face-mule))
222 'x-face-mule-gnus-article-display-x-face)
223 (gnus-article-compface-xbm
224 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -")
226 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
228 "*String or function to be executed to display an X-Face header.
229 If it is a string, the command will be executed in a sub-shell
230 asynchronously. The compressed face will be piped to this command."
231 :type '(choice string
232 (function-item gnus-article-display-xface)
233 (function-item x-face-mule-gnus-article-display-x-face)
235 :group 'gnus-article-washing)
237 (defcustom gnus-article-x-face-too-ugly nil
238 "Regexp matching posters whose face shouldn't be shown automatically."
239 :type '(choice regexp (const nil))
240 :group 'gnus-article-washing)
242 (defcustom gnus-article-banner-alist nil
243 "Banner alist for stripping.
245 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
246 :type '(repeat (cons symbol regexp))
247 :group 'gnus-article-washing)
249 (defcustom gnus-emphasis-alist
251 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
253 '(("_" "_" underline)
256 ("_/" "/_" underline-italic)
257 ("_\\*" "\\*_" underline-bold)
258 ("\\*/" "/\\*" bold-italic)
259 ("_\\*/" "/\\*_" underline-bold-italic))))
260 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
261 2 3 gnus-emphasis-underline)
265 (format format (car spec) (car (cdr spec)))
266 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
268 "*Alist that says how to fontify certain phrases.
269 Each item looks like this:
271 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
273 The first element is a regular expression to be matched. The second
274 is a number that says what regular expression grouping used to find
275 the entire emphasized word. The third is a number that says what
276 regexp grouping should be displayed and highlighted. The fourth
277 is the face used for highlighting."
278 :type '(repeat (list :value ("" 0 0 default)
280 (integer :tag "Match group")
281 (integer :tag "Emphasize group")
283 :group 'gnus-article-emphasis)
285 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
286 "A regexp to describe whitespace which should not be emphasized.
287 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
288 The former avoids underlining of leading and trailing whitespace,
289 and the latter avoids underlining any whitespace at all."
290 :group 'gnus-article-emphasis
293 (defface gnus-emphasis-bold '((t (:bold t)))
294 "Face used for displaying strong emphasized text (*word*)."
295 :group 'gnus-article-emphasis)
297 (defface gnus-emphasis-italic '((t (:italic t)))
298 "Face used for displaying italic emphasized text (/word/)."
299 :group 'gnus-article-emphasis)
301 (defface gnus-emphasis-underline '((t (:underline t)))
302 "Face used for displaying underlined emphasized text (_word_)."
303 :group 'gnus-article-emphasis)
305 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
306 "Face used for displaying underlined bold emphasized text (_*word*_)."
307 :group 'gnus-article-emphasis)
309 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
310 "Face used for displaying underlined italic emphasized text (_/word/_)."
311 :group 'gnus-article-emphasis)
313 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
314 "Face used for displaying bold italic emphasized text (/*word*/)."
315 :group 'gnus-article-emphasis)
317 (defface gnus-emphasis-underline-bold-italic
318 '((t (:bold t :italic t :underline t)))
319 "Face used for displaying underlined bold italic emphasized text.
320 Esample: (_/*word*/_)."
321 :group 'gnus-article-emphasis)
323 (defface gnus-emphasis-highlight-words
324 '((t (:background "black" :foreground "yellow")))
325 "Face used for displaying highlighted words."
326 :group 'gnus-article-emphasis)
328 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
329 "Format for display of Date headers in article bodies.
330 See `format-time-string' for the possible values.
332 The variable can also be function, which should return a complete Date
333 header. The function is called with one argument, the time, which can
334 be fed to `format-time-string'."
335 :type '(choice string symbol)
336 :link '(custom-manual "(gnus)Article Date")
337 :group 'gnus-article-washing)
340 (autoload 'mail-extract-address-components "mail-extr"))
342 (defcustom gnus-save-all-headers t
343 "*If non-nil, don't remove any headers before saving."
344 :group 'gnus-article-saving
347 (defcustom gnus-prompt-before-saving 'always
348 "*This variable says how much prompting is to be done when saving articles.
349 If it is nil, no prompting will be done, and the articles will be
350 saved to the default files. If this variable is `always', each and
351 every article that is saved will be preceded by a prompt, even when
352 saving large batches of articles. If this variable is neither nil not
353 `always', there the user will be prompted once for a file name for
354 each invocation of the saving commands."
355 :group 'gnus-article-saving
356 :type '(choice (item always)
357 (item :tag "never" nil)
358 (sexp :tag "once" :format "%t\n" :value t)))
360 (defcustom gnus-saved-headers gnus-visible-headers
361 "Headers to keep if `gnus-save-all-headers' is nil.
362 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
363 If that variable is nil, however, all headers that match this regexp
364 will be kept while the rest will be deleted before saving."
365 :group 'gnus-article-saving
368 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
369 "A function to save articles in your favourite format.
370 The function must be interactively callable (in other words, it must
371 be an Emacs command).
373 Gnus provides the following functions:
375 * gnus-summary-save-in-rmail (Rmail format)
376 * gnus-summary-save-in-mail (Unix mail format)
377 * gnus-summary-save-in-folder (MH folder)
378 * gnus-summary-save-in-file (article format)
379 * gnus-summary-save-in-vm (use VM's folder format)
380 * gnus-summary-write-to-file (article format -- overwrite)."
381 :group 'gnus-article-saving
382 :type '(radio (function-item gnus-summary-save-in-rmail)
383 (function-item gnus-summary-save-in-mail)
384 (function-item gnus-summary-save-in-folder)
385 (function-item gnus-summary-save-in-file)
386 (function-item gnus-summary-save-in-vm)
387 (function-item gnus-summary-write-to-file)))
389 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
390 "A function generating a file name to save articles in Rmail format.
391 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
392 :group 'gnus-article-saving
395 (defcustom gnus-mail-save-name 'gnus-plain-save-name
396 "A function generating a file name to save articles in Unix mail format.
397 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
398 :group 'gnus-article-saving
401 (defcustom gnus-folder-save-name 'gnus-folder-save-name
402 "A function generating a file name to save articles in MH folder.
403 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
404 :group 'gnus-article-saving
407 (defcustom gnus-file-save-name 'gnus-numeric-save-name
408 "A function generating a file name to save articles in article format.
409 The function is called with NEWSGROUP, HEADERS, and optional
411 :group 'gnus-article-saving
414 (defcustom gnus-split-methods
415 '((gnus-article-archive-name)
416 (gnus-article-nndoc-name))
417 "*Variable used to suggest where articles are to be saved.
418 For instance, if you would like to save articles related to Gnus in
419 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
420 you could set this variable to something like:
422 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
423 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
425 This variable is an alist where the where the key is the match and the
426 value is a list of possible files to save in if the match is non-nil.
428 If the match is a string, it is used as a regexp match on the
429 article. If the match is a symbol, that symbol will be funcalled
430 from the buffer of the article to be saved with the newsgroup as the
431 parameter. If it is a list, it will be evaled in the same buffer.
433 If this form or function returns a string, this string will be used as
434 a possible file name; and if it returns a non-nil list, that list will
435 be used as possible file names."
436 :group 'gnus-article-saving
437 :type '(repeat (choice (list :value (fun) function)
438 (cons :value ("" "") regexp (repeat string))
441 (defcustom gnus-article-display-method-for-mime
442 'gnus-article-display-mime-message
443 "Function to display a MIME message.
444 The function is called from the article buffer."
445 :group 'gnus-article-mime
448 (defcustom gnus-article-display-method-for-traditional
449 'gnus-article-display-traditional-message
450 "*Function to display a traditional message.
451 The function is called from the article buffer."
452 :group 'gnus-article-mime
455 (defcustom gnus-page-delimiter "^\^L"
456 "*Regexp describing what to use as article page delimiters.
457 The default value is \"^\^L\", which is a form linefeed at the
458 beginning of a line."
460 :group 'gnus-article-various)
462 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
463 "*The format specification for the article mode line.
464 See `gnus-summary-mode-line-format' for a closer description.
466 The following additional specs are available:
468 %w The article washing status.
469 %m The number of MIME parts in the article."
471 :group 'gnus-article-various)
473 (defcustom gnus-article-mode-hook nil
474 "*A hook for Gnus article mode."
476 :group 'gnus-article-various)
478 (defcustom gnus-article-menu-hook nil
479 "*Hook run after the creation of the article mode menu."
481 :group 'gnus-article-various)
483 (defcustom gnus-article-prepare-hook nil
484 "*A hook called after an article has been prepared in the article buffer."
486 :group 'gnus-article-various)
488 (defcustom gnus-article-hide-pgp-hook nil
489 "*A hook called after successfully hiding a PGP signature."
491 :group 'gnus-article-various)
493 (defcustom gnus-article-button-face 'bold
494 "Face used for highlighting buttons in the article buffer.
496 An article button is a piece of text that you can activate by pressing
497 `RET' or `mouse-2' above it."
499 :group 'gnus-article-buttons)
501 (defcustom gnus-article-mouse-face 'highlight
502 "Face used for mouse highlighting in the article buffer.
504 Article buttons will be displayed in this face when the cursor is
507 :group 'gnus-article-buttons)
509 (defcustom gnus-signature-face 'gnus-signature-face
510 "Face used for highlighting a signature in the article buffer.
511 Obsolete; use the face `gnus-signature-face' for customizations instead."
513 :group 'gnus-article-highlight
514 :group 'gnus-article-signature)
516 (defface gnus-signature-face
519 "Face used for highlighting a signature in the article buffer."
520 :group 'gnus-article-highlight
521 :group 'gnus-article-signature)
523 (defface gnus-header-from-face
526 (:foreground "spring green"))
529 (:foreground "red3"))
532 "Face used for displaying from headers."
533 :group 'gnus-article-headers
534 :group 'gnus-article-highlight)
536 (defface gnus-header-subject-face
539 (:foreground "SeaGreen3"))
542 (:foreground "red4"))
544 (:bold t :italic t)))
545 "Face used for displaying subject headers."
546 :group 'gnus-article-headers
547 :group 'gnus-article-highlight)
549 (defface gnus-header-newsgroups-face
552 (:foreground "yellow" :italic t))
555 (:foreground "MidnightBlue" :italic t))
558 "Face used for displaying newsgroups headers."
559 :group 'gnus-article-headers
560 :group 'gnus-article-highlight)
562 (defface gnus-header-name-face
565 (:foreground "SeaGreen"))
568 (:foreground "maroon"))
571 "Face used for displaying header names."
572 :group 'gnus-article-headers
573 :group 'gnus-article-highlight)
575 (defface gnus-header-content-face
578 (:foreground "forest green" :italic t))
581 (:foreground "indianred4" :italic t))
583 (:italic t))) "Face used for displaying header content."
584 :group 'gnus-article-headers
585 :group 'gnus-article-highlight)
587 (defcustom gnus-header-face-alist
588 '(("From" nil gnus-header-from-face)
589 ("Subject" nil gnus-header-subject-face)
590 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
591 ("" gnus-header-name-face gnus-header-content-face))
592 "*Controls highlighting of article header.
594 An alist of the form (HEADER NAME CONTENT).
596 HEADER is a regular expression which should match the name of an
597 header header and NAME and CONTENT are either face names or nil.
599 The name of each header field will be displayed using the face
600 specified by the first element in the list where HEADER match the
601 header name and NAME is non-nil. Similarly, the content will be
602 displayed by the first non-nil matching CONTENT face."
603 :group 'gnus-article-headers
604 :group 'gnus-article-highlight
605 :type '(repeat (list (regexp :tag "Header")
607 (item :tag "skip" nil)
608 (face :value default))
609 (choice :tag "Content"
610 (item :tag "skip" nil)
611 (face :value default)))))
613 (defcustom gnus-article-decode-hook nil
614 "*Hook run to decode charsets in articles."
615 :group 'gnus-article-headers
618 (defcustom gnus-display-mime-function 'gnus-display-mime
619 "Function to display MIME articles."
620 :group 'gnus-article-mime
623 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
624 "Function used to decode headers.")
626 (defvar gnus-article-dumbquotes-map
644 "Table for MS-to-Latin1 translation.")
646 (defcustom gnus-ignored-mime-types nil
647 "List of MIME types that should be ignored by Gnus."
648 :group 'gnus-article-mime
649 :type '(repeat regexp))
651 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
652 "List of MIME types that should not be given buttons when rendered inline."
653 :group 'gnus-article-mime
654 :type '(repeat regexp))
656 (defcustom gnus-article-mime-part-function nil
657 "Function called with a MIME handle as the argument.
658 This is meant for people who want to do something automatic based
659 on parts -- for instance, adding Vcard info to a database."
660 :group 'gnus-article-mime
663 (defcustom gnus-mime-multipart-functions nil
664 "An alist of MIME types to functions to display them.")
666 (defcustom gnus-article-date-lapsed-new-header nil
667 "Whether the X-Sent and Date headers can coexist.
668 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
669 either replace the old \"Date:\" header (if this variable is nil), or
670 be added below it (otherwise)."
671 :group 'gnus-article-headers
674 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
675 "Function called with a MIME handle as the argument.
676 This is meant for people who want to view first matched part.
677 For `undisplayed-alternative' (default), the first undisplayed
678 part or alternative part is used. For `undisplayed', the first
679 undisplayed part is used. For a function, the first part which
680 the function return `t' is used. For `nil', the first part is
682 :group 'gnus-article-mime
684 (item :tag "first" :value nil)
685 (item :tag "undisplayed" :value undisplayed)
686 (item :tag "undisplayed or alternative"
687 :value undisplayed-alternative)
690 (defcustom gnus-mime-action-alist
691 '(("save to file" . gnus-mime-save-part)
692 ("save and strip" . gnus-mime-save-part-and-strip)
693 ("display as text" . gnus-mime-inline-part)
694 ("view the part" . gnus-mime-view-part)
695 ("pipe to command" . gnus-mime-pipe-part)
696 ("toggle display" . gnus-article-press-button)
697 ("toggle display" . gnus-article-view-part-as-charset)
698 ("view as type" . gnus-mime-view-part-as-type)
699 ("internalize type" . gnus-mime-internalize-part)
700 ("externalize type" . gnus-mime-externalize-part))
701 "An alist of actions that run on the MIME attachment."
702 :group 'gnus-article-mime
703 :type '(repeat (cons (string :tag "name")
707 ;;; The treatment variables
710 (defvar gnus-part-display-hook nil
711 "Hook called on parts that are to receive treatment.")
713 (defvar gnus-article-treat-custom
714 '(choice (const :tag "Off" nil)
716 (const :tag "Header" head)
717 (const :tag "Last" last)
718 (const :tag "Mime" mime)
719 (integer :tag "Less")
720 (repeat :tag "Groups" regexp)
721 (sexp :tag "Predicate")))
723 (defvar gnus-article-treat-head-custom
724 '(choice (const :tag "Off" nil)
725 (const :tag "Header" head)))
727 (defvar gnus-article-treat-types '("text/plain")
730 (defvar gnus-inhibit-treatment nil
731 "Whether to inhibit treatment.")
733 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
734 "Highlight the signature.
735 Valid values are nil, t, `head', `last', an integer or a predicate.
736 See the manual for details."
737 :group 'gnus-article-treat
738 :type gnus-article-treat-custom)
739 (put 'gnus-treat-highlight-signature 'highlight t)
741 (defcustom gnus-treat-buttonize 100000
743 Valid values are nil, t, `head', `last', an integer or a predicate.
744 See the manual for details."
745 :group 'gnus-article-treat
746 :type gnus-article-treat-custom)
747 (put 'gnus-treat-buttonize 'highlight t)
749 (defcustom gnus-treat-buttonize-head 'head
750 "Add buttons to the head.
751 Valid values are nil, t, `head', `last', an integer or a predicate.
752 See the manual for details."
753 :group 'gnus-article-treat
754 :type gnus-article-treat-head-custom)
755 (put 'gnus-treat-buttonize-head 'highlight t)
757 (defcustom gnus-treat-emphasize nil
759 Valid values are nil, t, `head', `last', an integer or a predicate.
760 See the manual for details."
761 :group 'gnus-article-treat
762 :type gnus-article-treat-custom)
763 (put 'gnus-treat-emphasize 'highlight t)
765 (defcustom gnus-treat-strip-cr nil
766 "Remove carriage returns.
767 Valid values are nil, t, `head', `last', an integer or a predicate.
768 See the manual for details."
769 :group 'gnus-article-treat
770 :type gnus-article-treat-custom)
772 (defcustom gnus-treat-hide-headers 'head
774 Valid values are nil, t, `head', `last', an integer or a predicate.
775 See the manual for details."
776 :group 'gnus-article-treat
777 :type gnus-article-treat-head-custom)
779 (defcustom gnus-treat-hide-boring-headers nil
780 "Hide boring headers.
781 Valid values are nil, t, `head', `last', an integer or a predicate.
782 See the manual for details."
783 :group 'gnus-article-treat
784 :type gnus-article-treat-head-custom)
786 (defcustom gnus-treat-hide-signature nil
788 Valid values are nil, t, `head', `last', an integer or a predicate.
789 See the manual for details."
790 :group 'gnus-article-treat
791 :type gnus-article-treat-custom)
793 (defcustom gnus-treat-fill-article nil
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797 :group 'gnus-article-treat
798 :type gnus-article-treat-custom)
800 (defcustom gnus-treat-hide-citation nil
802 Valid values are nil, t, `head', `last', an integer or a predicate.
803 See the manual for details."
804 :group 'gnus-article-treat
805 :type gnus-article-treat-custom)
807 (defcustom gnus-treat-hide-citation-maybe nil
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-custom)
814 (defcustom gnus-treat-strip-list-identifiers 'head
815 "Strip list identifiers from `gnus-list-identifiers`.
816 Valid values are nil, t, `head', `last', an integer or a predicate.
817 See the manual for details."
818 :group 'gnus-article-treat
819 :type gnus-article-treat-custom)
821 (defcustom gnus-treat-strip-pgp t
822 "Strip PGP signatures.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-custom)
828 (defcustom gnus-treat-strip-pem nil
829 "Strip PEM signatures.
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-custom)
835 (defcustom gnus-treat-strip-banner t
836 "Strip banners from articles.
837 The banner to be stripped is specified in the `banner' group parameter.
838 Valid values are nil, t, `head', `last', an integer or a predicate.
839 See the manual for details."
840 :group 'gnus-article-treat
841 :type gnus-article-treat-custom)
843 (defcustom gnus-treat-highlight-headers 'head
844 "Highlight the headers.
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847 :group 'gnus-article-treat
848 :type gnus-article-treat-head-custom)
849 (put 'gnus-treat-highlight-headers 'highlight t)
851 (defcustom gnus-treat-highlight-citation t
852 "Highlight cited text.
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-custom)
857 (put 'gnus-treat-highlight-citation 'highlight t)
859 (defcustom gnus-treat-date-ut nil
860 "Display the Date in UT (GMT).
861 Valid values are nil, t, `head', `last', an integer or a predicate.
862 See the manual for details."
863 :group 'gnus-article-treat
864 :type gnus-article-treat-head-custom)
866 (defcustom gnus-treat-date-local nil
867 "Display the Date in the local timezone.
868 Valid values are nil, t, `head', `last', an integer or a predicate.
869 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-head-custom)
873 (defcustom gnus-treat-date-lapsed nil
874 "Display the Date header in a way that says how much time has elapsed.
875 Valid values are nil, t, `head', `last', an integer or a predicate.
876 See the manual for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-head-custom)
880 (defcustom gnus-treat-date-original nil
881 "Display the date in the original timezone.
882 Valid values are nil, t, `head', `last', an integer or a predicate.
883 See the manual for details."
884 :group 'gnus-article-treat
885 :type gnus-article-treat-head-custom)
887 (defcustom gnus-treat-date-iso8601 nil
888 "Display the date in the ISO8601 format.
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891 :group 'gnus-article-treat
892 :type gnus-article-treat-head-custom)
894 (defcustom gnus-treat-date-user-defined nil
895 "Display the date in a user-defined format.
896 The format is defined by the `gnus-article-time-format' variable.
897 Valid values are nil, t, `head', `last', an integer or a predicate.
898 See the manual for details."
899 :group 'gnus-article-treat
900 :type gnus-article-treat-head-custom)
902 (defcustom gnus-treat-strip-headers-in-body t
903 "Strip the X-No-Archive header line from the beginning of the body.
904 Valid values are nil, t, `head', `last', an integer or a predicate.
905 See the manual for details."
906 :group 'gnus-article-treat
907 :type gnus-article-treat-custom)
909 (defcustom gnus-treat-strip-trailing-blank-lines nil
910 "Strip trailing blank lines.
911 Valid values are nil, t, `head', `last', an integer or a predicate.
912 See the manual for details."
913 :group 'gnus-article-treat
914 :type gnus-article-treat-custom)
916 (defcustom gnus-treat-strip-leading-blank-lines nil
917 "Strip leading blank lines.
918 Valid values are nil, t, `head', `last', an integer or a predicate.
919 See the manual for details."
920 :group 'gnus-article-treat
921 :type gnus-article-treat-custom)
923 (defcustom gnus-treat-strip-multiple-blank-lines nil
924 "Strip multiple blank lines.
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-custom)
930 (defcustom gnus-treat-overstrike t
931 "Treat overstrike highlighting.
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
934 :group 'gnus-article-treat
935 :type gnus-article-treat-custom)
936 (put 'gnus-treat-overstrike 'highlight t)
938 (defcustom gnus-treat-display-xface
939 (and (or (and (fboundp 'image-type-available-p)
940 (image-type-available-p 'xbm)
941 (string-match "^0x" (shell-command-to-string "uncompface")))
942 (and (featurep 'xemacs) (featurep 'xface))
943 (eq 'x-face-mule-gnus-article-display-x-face
944 gnus-article-x-face-command))
946 "Display X-Face headers.
947 Valid values are nil, t, `head', `last', an integer or a predicate.
948 See the manual for details."
949 :group 'gnus-article-treat
950 :type gnus-article-treat-head-custom)
951 (put 'gnus-treat-display-xface 'highlight t)
953 (defcustom gnus-treat-display-smileys
954 (if (or (and (featurep 'xemacs)
956 (and (fboundp 'image-type-available-p)
957 (image-type-available-p 'pbm))
958 (and (not (featurep 'xemacs))
960 (module-installed-p 'gnus-bitmap)))
964 Valid values are nil, t, `head', `last', an integer or a predicate.
965 See the manual for details."
966 :group 'gnus-article-treat
967 :type gnus-article-treat-custom)
968 (put 'gnus-treat-display-smileys 'highlight t)
970 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
972 Valid values are nil, t, `head', `last', an integer or a predicate.
973 See the manual for details."
974 :group 'gnus-article-treat
975 :type gnus-article-treat-head-custom)
976 (put 'gnus-treat-display-picons 'highlight t)
978 (defcustom gnus-treat-capitalize-sentences nil
979 "Capitalize sentence-starting words.
980 Valid values are nil, t, `head', `last', an integer or a predicate.
981 See the manual for details."
982 :group 'gnus-article-treat
983 :type gnus-article-treat-custom)
985 (defcustom gnus-treat-fill-long-lines nil
987 Valid values are nil, t, `head', `last', an integer or a predicate.
988 See the manual for details."
989 :group 'gnus-article-treat
990 :type gnus-article-treat-custom)
992 (defcustom gnus-treat-play-sounds nil
994 Valid values are nil, t, `head', `last', an integer or a predicate.
995 See the manual for details."
996 :group 'gnus-article-treat
997 :type gnus-article-treat-custom)
999 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1000 "Decode an article as `default-mime-charset'. For instance, if you want to
1001 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1002 you could set this variable to something like: nil for don't decode, t for
1003 decode the body, '(or header t) for the whole article, etc."
1004 :group 'gnus-article-treat
1005 :type '(radio (const :tag "Off" nil)
1006 (const :tag "Decode body" t)
1007 (const :tag "Decode all" (or head t))))
1009 (defcustom gnus-treat-translate nil
1010 "Translate articles from one language to another.
1011 Valid values are nil, t, `head', `last', an integer or a predicate.
1012 See the manual for details."
1013 :group 'gnus-article-treat
1014 :type gnus-article-treat-custom)
1016 (defcustom gnus-treat-x-pgp-sig nil
1018 Valid values are nil, t, `head', `last', an integer or a predicate.
1019 See the manual for details."
1020 :group 'gnus-article-treat
1021 :group 'mime-security
1022 :type gnus-article-treat-custom)
1024 (defvar gnus-article-encrypt-protocol-alist
1025 '(("PGP" . mml2015-self-encrypt)))
1027 ;; Set to nil if more than one protocol added to
1028 ;; gnus-article-encrypt-protocol-alist.
1029 (defcustom gnus-article-encrypt-protocol "PGP"
1030 "The protocol used for encrypt articles.
1031 It is a string, such as \"PGP\". If nil, ask user."
1033 :group 'mime-security)
1035 ;;; Internal variables
1037 (defvar article-goto-body-goes-to-point-min-p nil)
1038 (defvar gnus-article-wash-types nil)
1039 (defvar gnus-article-emphasis-alist nil)
1041 (defvar gnus-article-mime-handle-alist-1 nil)
1042 (defvar gnus-treatment-function-alist
1043 '((gnus-treat-decode-article-as-default-mime-charset
1044 gnus-article-decode-article-as-default-mime-charset)
1045 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1046 (gnus-treat-strip-banner gnus-article-strip-banner)
1047 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1048 (gnus-treat-buttonize gnus-article-add-buttons)
1049 (gnus-treat-fill-article gnus-article-fill-cited-article)
1050 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1051 (gnus-treat-strip-cr gnus-article-remove-cr)
1052 (gnus-treat-display-xface gnus-article-display-x-face)
1053 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1054 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1055 (gnus-treat-hide-signature gnus-article-hide-signature)
1056 (gnus-treat-hide-citation gnus-article-hide-citation)
1057 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1058 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1059 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1060 (gnus-treat-strip-pem gnus-article-hide-pem)
1061 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1062 (gnus-treat-emphasize gnus-article-emphasize)
1063 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1064 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1065 (gnus-treat-date-ut gnus-article-date-ut)
1066 (gnus-treat-date-local gnus-article-date-local)
1067 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1068 (gnus-treat-date-original gnus-article-date-original)
1069 (gnus-treat-date-user-defined gnus-article-date-user)
1070 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1071 (gnus-treat-strip-trailing-blank-lines
1072 gnus-article-remove-trailing-blank-lines)
1073 (gnus-treat-strip-leading-blank-lines
1074 gnus-article-strip-leading-blank-lines)
1075 (gnus-treat-strip-multiple-blank-lines
1076 gnus-article-strip-multiple-blank-lines)
1077 (gnus-treat-overstrike gnus-article-treat-overstrike)
1078 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1079 (gnus-treat-display-smileys gnus-article-smiley-display)
1080 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1081 (gnus-treat-display-picons gnus-article-display-picons)
1082 (gnus-treat-play-sounds gnus-earcon-display)))
1084 (defvar gnus-article-mime-handle-alist nil)
1085 (defvar article-lapsed-timer nil)
1086 (defvar gnus-article-current-summary nil)
1088 (defvar gnus-article-mode-syntax-table
1089 (let ((table (copy-syntax-table text-mode-syntax-table)))
1090 ;; This causes the citation match run O(2^n).
1091 ;; (modify-syntax-entry ?- "w" table)
1092 (modify-syntax-entry ?> ")" table)
1093 (modify-syntax-entry ?< "(" table)
1095 "Syntax table used in article mode buffers.
1096 Initialized from `text-mode-syntax-table.")
1098 (defvar gnus-save-article-buffer nil)
1100 (defvar gnus-article-mode-line-format-alist
1101 (nconc '((?w (gnus-article-wash-status) ?s)
1102 (?m (gnus-article-mime-part-status) ?s))
1103 gnus-summary-mode-line-format-alist))
1105 (defvar gnus-number-of-articles-to-be-saved nil)
1107 (defvar gnus-inhibit-hiding nil)
1109 (defsubst gnus-article-hide-text (b e props)
1110 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1111 (add-text-properties b e props)
1112 (when (memq 'intangible props)
1114 (max (1- b) (point-min))
1115 b 'intangible (cddr (memq 'intangible props)))))
1116 (defsubst gnus-article-unhide-text (b e)
1117 "Remove hidden text properties from region between B and E."
1118 (remove-text-properties b e gnus-hidden-properties)
1119 (when (memq 'intangible gnus-hidden-properties)
1120 (put-text-property (max (1- b) (point-min))
1121 b 'intangible nil)))
1123 (defun gnus-article-hide-text-type (b e type)
1124 "Hide text of TYPE between B and E."
1125 (push type gnus-article-wash-types)
1126 (gnus-article-hide-text
1127 b e (cons 'article-type (cons type gnus-hidden-properties))))
1129 (defun gnus-article-unhide-text-type (b e type)
1130 "Unhide text of TYPE between B and E."
1131 (setq gnus-article-wash-types
1132 (delq type gnus-article-wash-types))
1133 (remove-text-properties
1134 b e (cons 'article-type (cons type gnus-hidden-properties)))
1135 (when (memq 'intangible gnus-hidden-properties)
1136 (put-text-property (max (1- b) (point-min))
1137 b 'intangible nil)))
1139 (defun gnus-article-hide-text-of-type (type)
1140 "Hide text of TYPE in the current buffer."
1142 (let ((b (point-min))
1144 (while (setq b (text-property-any b e 'article-type type))
1145 (add-text-properties b (incf b) gnus-hidden-properties)))))
1147 (defun gnus-article-delete-text-of-type (type)
1148 "Delete text of TYPE in the current buffer."
1150 (let ((b (point-min)))
1151 (while (setq b (text-property-any b (point-max) 'article-type type))
1153 b (or (text-property-not-all b (point-max) 'article-type type)
1156 (defun gnus-article-delete-invisible-text ()
1157 "Delete all invisible text in the current buffer."
1159 (let ((b (point-min)))
1160 (while (setq b (text-property-any b (point-max) 'invisible t))
1162 b (or (text-property-not-all b (point-max) 'invisible t)
1165 (defun gnus-article-text-type-exists-p (type)
1166 "Say whether any text of type TYPE exists in the buffer."
1167 (text-property-any (point-min) (point-max) 'article-type type))
1169 (defsubst gnus-article-header-rank ()
1170 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1171 (let ((list gnus-sorted-header-list)
1174 (when (looking-at (car list))
1176 (setq list (cdr list))
1180 (defun article-hide-headers (&optional arg delete)
1181 "Hide unwanted headers and possibly sort them as well."
1182 (interactive (gnus-article-hidden-arg))
1183 ;; Lars said that this function might be inhibited.
1184 (if (gnus-article-check-hidden-text 'headers arg)
1186 ;; Show boring headers as well.
1187 (gnus-article-show-hidden-text 'boring-headers)
1188 (when (eq 1 (point-min))
1189 (set-window-start (get-buffer-window (current-buffer)) 1)))
1190 (unless gnus-inhibit-hiding
1193 (let ((buffer-read-only nil)
1194 (inhibit-read-only t)
1195 (case-fold-search t)
1196 (max (1+ (length gnus-sorted-header-list)))
1197 (ignored (when (not gnus-visible-headers)
1198 (cond ((stringp gnus-ignored-headers)
1199 gnus-ignored-headers)
1200 ((listp gnus-ignored-headers)
1201 (mapconcat 'identity gnus-ignored-headers
1204 (cond ((stringp gnus-visible-headers)
1205 gnus-visible-headers)
1206 ((and gnus-visible-headers
1207 (listp gnus-visible-headers))
1208 (mapconcat 'identity gnus-visible-headers "\\|"))))
1209 (inhibit-point-motion-hooks t)
1211 ;; First we narrow to just the headers.
1212 (article-narrow-to-head)
1213 ;; Hide any "From " lines at the beginning of (mail) articles.
1214 (while (looking-at "From ")
1218 (delete-region (point-min) (point))
1219 (gnus-article-hide-text (point-min) (point)
1220 (nconc (list 'article-type 'headers)
1221 gnus-hidden-properties))))
1222 ;; Then treat the rest of the header lines.
1223 ;; Then we use the two regular expressions
1224 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1225 ;; select which header lines is to remain visible in the
1227 (while (re-search-forward "^[^ \t]*:" nil t)
1229 ;; Mark the rank of the header.
1231 (point) (1+ (point)) 'message-rank
1232 (if (or (and visible (looking-at visible))
1234 (not (looking-at ignored))))
1235 (gnus-article-header-rank)
1238 (message-sort-headers-1)
1239 (when (setq beg (text-property-any
1240 (point-min) (point-max) 'message-rank (+ 2 max)))
1241 ;; We delete or make invisible the unwanted headers.
1242 (push 'headers gnus-article-wash-types)
1245 (add-text-properties
1246 (point-min) (+ 5 (point-min))
1247 '(article-type headers dummy-invisible t))
1248 (delete-region beg (point-max)))
1249 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1252 (defun article-hide-boring-headers (&optional arg)
1253 "Toggle hiding of headers that aren't very interesting.
1254 If given a negative prefix, always show; if given a positive prefix,
1256 (interactive (gnus-article-hidden-arg))
1257 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1258 (not gnus-show-all-headers))
1261 (let ((buffer-read-only nil)
1262 (list gnus-boring-article-headers)
1263 (inhibit-point-motion-hooks t)
1265 (article-narrow-to-head)
1267 (setq elem (pop list))
1268 (goto-char (point-min))
1270 ;; Hide empty headers.
1272 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1274 (gnus-article-hide-text-type
1275 (progn (beginning-of-line) (point))
1278 (if (re-search-forward "^[^ \t]" nil t)
1282 ;; Hide boring Newsgroups header.
1283 ((eq elem 'newsgroups)
1284 (when (equal (gnus-fetch-field "newsgroups")
1285 (gnus-group-real-name
1286 (if (boundp 'gnus-newsgroup-name)
1289 (gnus-article-hide-header "newsgroups")))
1290 ((eq elem 'followup-to)
1291 (when (equal (message-fetch-field "followup-to")
1292 (message-fetch-field "newsgroups"))
1293 (gnus-article-hide-header "followup-to")))
1294 ((eq elem 'reply-to)
1295 (let ((from (message-fetch-field "from"))
1296 (reply-to (message-fetch-field "reply-to")))
1301 (nth 1 (funcall gnus-extract-address-components from))
1302 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1303 (gnus-article-hide-header "reply-to"))))
1305 (let ((date (message-fetch-field "date")))
1307 (< (days-between (current-time-string) date)
1309 (gnus-article-hide-header "date"))))
1311 (let ((to (message-fetch-field "to"))
1312 (cc (message-fetch-field "cc")))
1313 (when (> (length to) 1024)
1314 (gnus-article-hide-header "to"))
1315 (when (> (length cc) 1024)
1316 (gnus-article-hide-header "cc"))))
1320 (goto-char (point-min))
1321 (while (re-search-forward "^to:" nil t)
1322 (setq to-count (1+ to-count)))
1323 (when (> to-count 1)
1324 (while (> to-count 0)
1325 (goto-char (point-min))
1327 (re-search-forward "^to:" nil nil to-count)
1329 (narrow-to-region (point) (point-max))
1330 (gnus-article-hide-header "to"))
1331 (setq to-count (1- to-count))))
1332 (goto-char (point-min))
1333 (while (re-search-forward "^cc:" nil t)
1334 (setq cc-count (1+ cc-count)))
1335 (when (> cc-count 1)
1336 (while (> cc-count 0)
1337 (goto-char (point-min))
1339 (re-search-forward "^cc:" nil nil cc-count)
1341 (narrow-to-region (point) (point-max))
1342 (gnus-article-hide-header "cc"))
1343 (setq cc-count (1- cc-count)))))))))))))
1345 (defun gnus-article-hide-header (header)
1347 (goto-char (point-min))
1348 (when (re-search-forward (concat "^" header ":") nil t)
1349 (gnus-article-hide-text-type
1350 (progn (beginning-of-line) (point))
1353 (if (re-search-forward "^[^ \t]" nil t)
1358 (defun article-toggle-headers (&optional arg)
1359 "Toggle hiding of headers. If given a negative prefix, always show;
1360 if given a positive prefix, always hide."
1361 (interactive (gnus-article-hidden-arg))
1362 (let ((force (when (numberp arg)
1363 (cond ((> arg 0) 'always-hide)
1364 ((< arg 0) 'always-show))))
1365 (window (get-buffer-window gnus-article-buffer))
1366 (header-end (point-min))
1367 header-start field-end field-start
1368 (inhibit-point-motion-hooks t)
1369 (inhibit-read-only t)
1373 (while (and (setq header-start
1374 (text-property-any header-end (point-max)
1375 'article-treated-header t))
1377 (text-property-not-all header-start (point-max)
1378 'article-treated-header t)))
1379 (setq field-end header-start)
1381 (;; Hide exposed invisible fields.
1382 (and (not (eq 'always-show force))
1384 (text-property-any field-end header-end
1385 'exposed-invisible-field t)))
1386 (while (and field-start
1387 (setq field-end (text-property-not-all
1388 field-start header-end
1389 'exposed-invisible-field t)))
1390 (add-text-properties field-start field-end gnus-hidden-properties)
1391 (setq field-start (text-property-any field-end header-end
1392 'exposed-invisible-field t)))
1393 (put-text-property header-start header-end
1394 'exposed-invisible-field nil))
1395 (;; Expose invisible fields.
1396 (and (not (eq 'always-hide force))
1398 (text-property-any field-end header-end 'invisible t)))
1399 (while (and field-start
1400 (setq field-end (text-property-not-all
1401 field-start header-end
1403 ;; If the invisible text is not terminated with newline, we
1404 ;; won't expose it. Because it may be created by x-face-mule.
1405 ;; BTW, XEmacs sometimes fail in putting a invisible text
1406 ;; property with `gnus-article-hide-text' (really?). In that
1407 ;; case, the invisible text might be started from the middle of
1408 ;; a line so we will expose the sort of thing.
1409 (when (or (not (or (eq header-start field-start)
1410 (eq ?\n (char-before field-start))))
1411 (eq ?\n (char-before field-end)))
1412 (remove-text-properties field-start field-end
1413 gnus-hidden-properties)
1414 (put-text-property field-start field-end
1415 'exposed-invisible-field t))
1416 (setq field-start (text-property-any field-end header-end
1419 (not (eq 'always-show force))
1420 (narrow-to-region header-start header-end)
1421 (article-hide-headers)
1422 ;; Re-display X-Face image under XEmacs.
1423 (when (and (featurep 'xemacs)
1424 (gnus-functionp gnus-article-x-face-command))
1425 (let ((func (cadr (assq 'gnus-treat-display-xface
1426 gnus-treatment-function-alist)))
1428 (when (and (not gnus-inhibit-treatment)
1430 (gnus-treat-predicate gnus-treat-display-xface))
1432 (put-text-property header-start header-end 'read-only nil))))
1435 (goto-char (point-min))
1437 (set-window-start window (point-min))))))
1439 (defvar gnus-article-normalized-header-length 40
1440 "Length of normalized headers.")
1442 (defun article-normalize-headers ()
1443 "Make all header lines 40 characters long."
1445 (let ((buffer-read-only nil)
1449 (article-narrow-to-head)
1452 ((< (setq column (- (gnus-point-at-eol) (point)))
1453 gnus-article-normalized-header-length)
1455 (insert (make-string
1456 (- gnus-article-normalized-header-length column)
1458 ((> column gnus-article-normalized-header-length)
1459 (gnus-put-text-property
1461 (forward-char gnus-article-normalized-header-length)
1468 (forward-line 1))))))
1470 (defun article-treat-dumbquotes ()
1471 "Translate M******** sm*rtq**t*s into proper text.
1472 Note that this function guesses whether a character is a sm*rtq**t* or
1473 not, so it should only be used interactively."
1475 (article-translate-strings gnus-article-dumbquotes-map))
1477 (defun article-translate-characters (from to)
1478 "Translate all characters in the body of the article according to FROM and TO.
1479 FROM is a string of characters to translate from; to is a string of
1480 characters to translate to."
1482 (when (article-goto-body)
1483 (let ((buffer-read-only nil)
1484 (x (make-string 225 ?x))
1486 (while (< (incf i) (length x))
1489 (while (< i (length from))
1490 (aset x (aref from i) (aref to i))
1492 (translate-region (point) (point-max) x)))))
1494 (defun article-translate-strings (map)
1495 "Translate all string in the body of the article according to MAP.
1496 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1498 (when (article-goto-body)
1499 (let ((buffer-read-only nil)
1501 (while (setq elem (pop map))
1503 (while (search-forward (car elem) nil t)
1504 (replace-match (cadr elem)))))))))
1506 (defun article-treat-overstrike ()
1507 "Translate overstrikes into bold text."
1510 (when (article-goto-body)
1511 (let ((buffer-read-only nil))
1512 (while (search-forward "\b" nil t)
1513 (let ((next (char-after))
1517 previous (char-after))
1521 ;; We do the boldification/underlining by hiding the
1522 ;; overstrikes and putting the proper text property
1526 (gnus-article-hide-text-type start (point) 'overstrike)
1527 (put-text-property (point) end 'face 'bold))
1529 (gnus-article-hide-text-type
1530 (1- (point)) (1+ (point)) 'overstrike)
1532 start (1- (point)) 'face 'underline))
1534 (gnus-article-hide-text-type start (point) 'overstrike)
1536 (point) end 'face 'underline)))))))))
1538 (defun article-fill-long-lines ()
1539 "Fill lines that are wider than the window width."
1542 (let ((buffer-read-only nil)
1543 (width (window-width (get-buffer-window (current-buffer)))))
1546 (let ((adaptive-fill-mode nil))
1549 (when (>= (current-column) (min fill-column width))
1550 (narrow-to-region (point) (gnus-point-at-bol))
1551 (fill-paragraph nil)
1552 (goto-char (point-max))
1554 (forward-line 1)))))))
1556 (defun article-capitalize-sentences ()
1557 "Capitalize the first word in each sentence."
1560 (let ((buffer-read-only nil)
1561 (paragraph-start "^[\n\^L]"))
1565 (forward-sentence)))))
1567 (defun article-remove-cr ()
1568 "Remove trailing CRs and then translate remaining CRs into LFs."
1571 (let ((buffer-read-only nil))
1572 (goto-char (point-min))
1573 (while (re-search-forward "\r+$" nil t)
1574 (replace-match "" t t))
1575 (goto-char (point-min))
1576 (while (search-forward "\r" nil t)
1577 (replace-match "\n" t t)))))
1579 (defun article-remove-trailing-blank-lines ()
1580 "Remove all trailing blank lines from the article."
1583 (let ((buffer-read-only nil))
1584 (goto-char (point-max))
1588 (while (and (not (bobp))
1589 (looking-at "^[ \t]*$")
1590 (not (gnus-annotation-in-region-p
1591 (point) (gnus-point-at-eol))))
1596 (defun article-display-x-face (&optional force)
1597 "Look for an X-Face header and display it if present."
1598 (interactive (list 'force))
1600 ;; Delete the old process, if any.
1601 (when (process-status "article-x-face")
1602 (delete-process "article-x-face"))
1603 (let ((inhibit-point-motion-hooks t)
1604 (case-fold-search t)
1607 (article-narrow-to-head)
1608 (goto-char (point-min))
1609 (setq from (message-fetch-field "from"))
1610 (goto-char (point-min))
1611 (while (and gnus-article-x-face-command
1614 ;; Check whether this face is censored.
1615 (not gnus-article-x-face-too-ugly)
1616 (and gnus-article-x-face-too-ugly from
1617 (not (string-match gnus-article-x-face-too-ugly
1619 ;; Has to be present.
1620 (re-search-forward "^X-Face:[ \t]*" nil t))
1621 ;; This used to try to do multiple faces (`while' instead of
1622 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1623 ;; work (b) it can crash some versions of Emacs (c) are
1624 ;; multiple faces really something to encourage?
1625 (when (stringp gnus-article-x-face-command)
1627 ;; We now have the area of the buffer where the X-Face is stored.
1630 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1631 ;; We display the face.
1632 (if (symbolp gnus-article-x-face-command)
1633 ;; The command is a lisp function, so we call it.
1634 (if (gnus-functionp gnus-article-x-face-command)
1635 (funcall gnus-article-x-face-command beg end)
1636 (error "%s is not a function" gnus-article-x-face-command))
1637 ;; The command is a string, so we interpret the command
1638 ;; as a, well, command, and fork it off.
1639 (let ((process-connection-type nil))
1640 (process-kill-without-query
1642 "article-x-face" nil shell-file-name shell-command-switch
1643 gnus-article-x-face-command))
1644 (process-send-region "article-x-face" beg end)
1645 (process-send-eof "article-x-face"))))))))))
1647 (defun article-decode-mime-words ()
1648 "Decode all MIME-encoded words in the article."
1651 (set-buffer gnus-article-buffer)
1652 (let ((inhibit-point-motion-hooks t)
1654 (mail-parse-charset gnus-newsgroup-charset)
1655 (mail-parse-ignored-charsets
1656 (save-excursion (set-buffer gnus-summary-buffer)
1657 gnus-newsgroup-ignored-charsets)))
1658 (mail-decode-encoded-word-region (point-min) (point-max)))))
1660 (defun article-decode-charset (&optional prompt)
1661 "Decode charset-encoded text in the article.
1662 If PROMPT (the prefix), prompt for a coding system to use."
1664 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1666 (mail-parse-charset gnus-newsgroup-charset)
1667 (mail-parse-ignored-charsets
1668 (save-excursion (condition-case nil
1669 (set-buffer gnus-summary-buffer)
1671 gnus-newsgroup-ignored-charsets))
1672 ct cte ctl charset format)
1675 (article-narrow-to-head)
1676 (setq ct (message-fetch-field "Content-Type" t)
1677 cte (message-fetch-field "Content-Transfer-Encoding" t)
1678 ctl (and ct (ignore-errors
1679 (mail-header-parse-content-type ct)))
1682 (mm-read-coding-system "Charset to decode: "))
1684 (mail-content-type-get ctl 'charset)))
1685 format (and ctl (mail-content-type-get ctl 'format)))
1687 (setq cte (mail-header-strip cte)))
1688 (if (and ctl (not (string-match "/" (car ctl))))
1690 (goto-char (point-max)))
1693 (narrow-to-region (point) (point-max))
1694 (when (and (eq mail-parse-charset 'gnus-decoded)
1695 (eq (mm-body-7-or-8) '8bit))
1696 ;; The text code could have been decoded.
1697 (setq charset mail-parse-charset))
1698 (when (and (or (not ctl)
1699 (equal (car ctl) "text/plain"))
1700 (not format)) ;; article with format will decode later.
1702 charset (and cte (intern (downcase
1703 (gnus-strip-whitespace cte))))
1706 (defun article-decode-encoded-words ()
1707 "Remove encoded-word encoding from headers."
1708 (let (buffer-read-only)
1709 (let ((charset (save-excursion
1710 (set-buffer gnus-summary-buffer)
1711 default-mime-charset)))
1712 (mime-decode-header-in-buffer charset)
1715 (defun article-de-quoted-unreadable (&optional force)
1716 "Translate a quoted-printable-encoded article.
1717 If FORCE, decode the article whether it is marked as quoted-printable
1719 (interactive (list 'force))
1721 (let ((buffer-read-only nil) type charset)
1722 (if (gnus-buffer-live-p gnus-original-article-buffer)
1723 (with-current-buffer gnus-original-article-buffer
1725 (gnus-fetch-field "content-transfer-encoding"))
1726 (let* ((ct (gnus-fetch-field "content-type"))
1729 (mail-header-parse-content-type ct)))))
1730 (setq charset (and ctl
1731 (mail-content-type-get ctl 'charset)))
1732 (if (stringp charset)
1733 (setq charset (intern (downcase charset)))))))
1735 (setq charset gnus-newsgroup-charset))
1737 (and type (let ((case-fold-search t))
1738 (string-match "quoted-printable" type))))
1740 (quoted-printable-decode-region
1741 (point) (point-max) (mm-charset-to-coding-system charset))))))
1743 (defun article-de-base64-unreadable (&optional force)
1744 "Translate a base64 article.
1745 If FORCE, decode the article whether it is marked as base64 not."
1746 (interactive (list 'force))
1748 (let ((buffer-read-only nil) type charset)
1749 (if (gnus-buffer-live-p gnus-original-article-buffer)
1750 (with-current-buffer gnus-original-article-buffer
1752 (gnus-fetch-field "content-transfer-encoding"))
1753 (let* ((ct (gnus-fetch-field "content-type"))
1756 (mail-header-parse-content-type ct)))))
1757 (setq charset (and ctl
1758 (mail-content-type-get ctl 'charset)))
1759 (if (stringp charset)
1760 (setq charset (intern (downcase charset)))))))
1762 (setq charset gnus-newsgroup-charset))
1764 (and type (let ((case-fold-search t))
1765 (string-match "base64" type))))
1768 (narrow-to-region (point) (point-max))
1769 (base64-decode-region (point-min) (point-max))
1770 (mm-decode-coding-region
1771 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1776 (defun article-decode-HZ ()
1777 "Translate a HZ-encoded article."
1781 (let ((buffer-read-only nil))
1782 (rfc1843-decode-region (point-min) (point-max)))))
1784 (defun article-wash-html ()
1785 "Format an html article."
1788 (let ((buffer-read-only nil)
1790 (if (gnus-buffer-live-p gnus-original-article-buffer)
1791 (with-current-buffer gnus-original-article-buffer
1792 (let* ((ct (gnus-fetch-field "content-type"))
1795 (mail-header-parse-content-type ct)))))
1796 (setq charset (and ctl
1797 (mail-content-type-get ctl 'charset)))
1798 (if (stringp charset)
1799 (setq charset (intern (downcase charset)))))))
1801 (setq charset gnus-newsgroup-charset))
1803 (save-window-excursion
1805 (narrow-to-region (point) (point-max))
1807 (let ((w3-strict-width (window-width))
1808 (url-standalone-mode t))
1810 (w3-region (point-min) (point-max))
1813 (defun article-hide-list-identifiers ()
1814 "Remove list identifies from the Subject header.
1815 The `gnus-list-identifiers' variable specifies what to do."
1819 (let ((inhibit-point-motion-hooks t)
1821 (article-narrow-to-head)
1822 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1823 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1825 (goto-char (point-min))
1826 (when (re-search-forward
1827 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1828 " *\\)\\)+\\(Re: +\\)?\\)")
1830 (let ((s (or (match-string 3) (match-string 5))))
1831 (delete-region (match-beginning 1) (match-end 1))
1833 (goto-char (match-beginning 1))
1836 (defun article-hide-pgp ()
1837 "Remove any PGP headers and signatures in the current article."
1841 (let ((inhibit-point-motion-hooks t)
1842 buffer-read-only beg end)
1844 ;; Hide the "header".
1845 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1846 (push 'pgp gnus-article-wash-types)
1847 (delete-region (match-beginning 0) (match-end 0))
1848 ;; Remove armor headers (rfc2440 6.2)
1849 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1852 ;; Hide the actual signature.
1853 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1854 (setq end (1+ (match-beginning 0)))
1857 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1859 ;; Perhaps we shouldn't hide to the end of the buffer
1860 ;; if there is no end to the signature?
1862 ;; Hide "- " PGP quotation markers.
1864 (narrow-to-region beg end)
1865 (goto-char (point-min))
1866 (while (re-search-forward "^- " nil t)
1868 (match-beginning 0) (match-end 0)))
1870 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1872 (defun article-hide-pem (&optional arg)
1873 "Toggle hiding of any PEM headers and signatures in the current article.
1874 If given a negative prefix, always show; if given a positive prefix,
1876 (interactive (gnus-article-hidden-arg))
1877 (unless (gnus-article-check-hidden-text 'pem arg)
1879 (let (buffer-read-only end)
1880 (goto-char (point-min))
1881 ;; Hide the horrendously ugly "header".
1882 (when (and (search-forward
1883 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1885 (setq end (1+ (match-beginning 0))))
1886 (push 'pem gnus-article-wash-types)
1887 (gnus-article-hide-text-type
1889 (if (search-forward "\n\n" nil t)
1893 ;; Hide the trailer as well
1894 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1896 (gnus-article-hide-text-type
1897 (match-beginning 0) (match-end 0) 'pem)))))))
1899 (defun article-strip-banner ()
1900 "Strip the banner specified by the `banner' group parameter."
1904 (let ((inhibit-point-motion-hooks t)
1905 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1906 (gnus-signature-limit nil)
1907 buffer-read-only beg end)
1911 ((eq banner 'signature)
1912 (when (gnus-article-narrow-to-signature)
1915 (delete-region (point) (point-max))))
1917 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1918 (while (re-search-forward banner nil t)
1919 (delete-region (match-beginning 0) (match-end 0)))))
1921 (while (re-search-forward banner nil t)
1922 (delete-region (match-beginning 0) (match-end 0))))))))))
1924 (defun article-babel ()
1925 "Translate article using an online translation service."
1929 (set-buffer gnus-article-buffer)
1930 (when (article-goto-body)
1931 (let* ((buffer-read-only nil)
1934 (orig (buffer-substring start end))
1935 (trans (babel-as-string orig)))
1937 (narrow-to-region start end)
1938 (delete-region start end)
1941 (defun article-hide-signature (&optional arg)
1942 "Hide the signature in the current article.
1943 If given a negative prefix, always show; if given a positive prefix,
1945 (interactive (gnus-article-hidden-arg))
1951 (article-goto-body))
1952 (goto-char (point-min)))
1953 (unless (gnus-article-check-hidden-text 'signature arg)
1954 (let ((buffer-read-only nil)
1956 (while (setq button (text-property-any button (point-max)
1958 'gnus-signature-toggle))
1959 (setq button (text-property-not-all button (point-max)
1961 'gnus-signature-toggle))
1962 (when (and button (not (eobp)))
1963 (gnus-article-hide-text-type
1965 (next-single-property-change (1+ button) 'mime-view-entity
1969 (defun article-strip-headers-in-body ()
1970 "Strip offensive headers from bodies."
1974 (let ((case-fold-search t))
1975 (when (looking-at "x-no-archive:")
1976 (gnus-delete-line)))))
1978 (defun article-strip-leading-blank-lines ()
1979 "Remove all blank lines from the beginning of the article."
1982 (let ((inhibit-point-motion-hooks t)
1984 (when (article-goto-body)
1985 (while (and (not (eobp))
1986 (looking-at "[ \t]*$"))
1987 (gnus-delete-line))))))
1989 (defun article-narrow-to-head ()
1990 "Narrow the buffer to the head of the message.
1991 Point is left at the beginning of the narrowed-to region."
1993 (goto-char (point-min))
1994 (if (search-forward "\n\n" nil 1)
1997 (goto-char (point-min)))
1999 (defun article-goto-body ()
2000 "Place point at the start of the body."
2001 (goto-char (point-min))
2003 ;; This variable is only bound when dealing with separate
2005 (article-goto-body-goes-to-point-min-p
2007 ((search-forward "\n\n" nil t)
2010 (goto-char (point-max))
2013 (defun article-strip-multiple-blank-lines ()
2014 "Replace consecutive blank lines with one empty line."
2017 (let ((inhibit-point-motion-hooks t)
2019 ;; First make all blank lines empty.
2021 (while (re-search-forward "^[ \t]+$" nil t)
2022 (unless (gnus-annotation-in-region-p
2023 (match-beginning 0) (match-end 0))
2024 (replace-match "" nil t)))
2025 ;; Then replace multiple empty lines with a single empty line.
2027 (while (re-search-forward "\n\n\n+" nil t)
2028 (unless (gnus-annotation-in-region-p
2029 (match-beginning 0) (match-end 0))
2030 (replace-match "\n\n" t t))))))
2032 (defun article-strip-leading-space ()
2033 "Remove all white space from the beginning of the lines in the article."
2036 (let ((inhibit-point-motion-hooks t)
2039 (while (re-search-forward "^[ \t]+" nil t)
2040 (replace-match "" t t)))))
2042 (defun article-strip-trailing-space ()
2043 "Remove all white space from the end of the lines in the article."
2046 (let ((inhibit-point-motion-hooks t)
2049 (while (re-search-forward "[ \t]+$" nil t)
2050 (replace-match "" t t)))))
2052 (defun article-strip-blank-lines ()
2053 "Strip leading, trailing and multiple blank lines."
2055 (article-strip-leading-blank-lines)
2056 (article-remove-trailing-blank-lines)
2057 (article-strip-multiple-blank-lines))
2059 (defun article-strip-all-blank-lines ()
2060 "Strip all blank lines."
2063 (let ((inhibit-point-motion-hooks t)
2066 (while (re-search-forward "^[ \t]*\n" nil t)
2067 (replace-match "" t t)))))
2069 (defun gnus-article-narrow-to-signature ()
2070 "Narrow to the signature; return t if a signature is found, else nil."
2071 (let ((inhibit-point-motion-hooks t))
2072 (when (gnus-article-search-signature)
2074 ;; Check whether we have some limits to what we consider
2075 ;; to be a signature.
2076 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2077 (list gnus-signature-limit)))
2079 (while (setq limit (pop limits))
2080 (if (or (and (integerp limit)
2081 (< (- (point-max) (point)) limit))
2083 (< (count-lines (point) (point-max)) limit))
2084 (and (gnus-functionp limit)
2086 (and (stringp limit)
2087 (not (re-search-forward limit nil t))))
2088 () ; This limit did not succeed.
2092 (narrow-to-region (point) (point-max))
2095 (defun gnus-article-search-signature ()
2096 "Search the current buffer for the signature separator.
2097 Put point at the beginning of the signature separator."
2098 (let ((cur (point)))
2099 (goto-char (point-max))
2100 (if (if (stringp gnus-signature-separator)
2101 (re-search-backward gnus-signature-separator nil t)
2102 (let ((seps gnus-signature-separator))
2104 (not (re-search-backward (car seps) nil t)))
2111 (defun gnus-article-hidden-arg ()
2112 "Return the current prefix arg as a number, or 0 if no prefix."
2113 (list (if current-prefix-arg
2114 (prefix-numeric-value current-prefix-arg)
2117 (defun gnus-article-check-hidden-text (type arg)
2118 "Return nil if hiding is necessary.
2119 Arg can be nil or a number. Nil and positive means hide, negative
2120 means show, 0 means toggle."
2123 (let ((hide (gnus-article-hidden-text-p type)))
2129 (gnus-article-show-hidden-text type))
2131 (if (eq hide 'hidden)
2132 (gnus-article-show-hidden-text type)
2135 (defun gnus-article-hidden-text-p (type)
2136 "Say whether the current buffer contains hidden text of type TYPE."
2137 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2139 (not (get-text-property pos 'invisible))
2140 (not (get-text-property pos 'dummy-invisible)))
2142 (text-property-any (1+ pos) (point-max) 'article-type type)))
2147 (defun gnus-article-show-hidden-text (type &optional hide)
2148 "Show all hidden text of type TYPE.
2149 If HIDE, hide the text instead."
2151 (let ((buffer-read-only nil)
2152 (inhibit-point-motion-hooks t)
2155 (while (setq beg (text-property-any end (point-max) 'article-type type))
2158 (text-property-not-all beg (point-max) 'article-type type)
2161 (gnus-article-hide-text beg end gnus-hidden-properties)
2162 (gnus-article-unhide-text beg end))
2166 (defconst article-time-units
2167 `((year . ,(* 365.25 24 60 60))
2168 (week . ,(* 7 24 60 60))
2169 (day . ,(* 24 60 60))
2173 "Mapping from time units to seconds.")
2175 (defun article-date-ut (&optional type highlight header)
2176 "Convert DATE date to universal time in the current article.
2177 If TYPE is `local', convert to local time; if it is `lapsed', output
2178 how much time has lapsed since DATE. For `lapsed', the value of
2179 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2180 should replace the \"Date:\" one, or should be added below it."
2181 (interactive (list 'ut t))
2182 (let* ((header (or header
2183 (and (eq 1 (point-min))
2184 (mail-header-date (save-excursion
2185 (set-buffer gnus-summary-buffer)
2186 gnus-current-headers)))
2187 (message-fetch-field "date")
2189 (date (if (vectorp header) (mail-header-date header)
2191 (inhibit-point-motion-hooks t)
2192 bface eface date-pos)
2193 (when (and date (not (string= date "")))
2196 (article-narrow-to-head)
2197 (when (or (and (eq type 'lapsed)
2198 gnus-article-date-lapsed-new-header
2199 ;; Attempt to get the face of X-Sent first.
2200 (re-search-forward "^X-Sent:[ \t]" nil t))
2201 (re-search-forward "^Date:[ \t]" nil t)
2202 ;; If Date is missing, try again for X-Sent.
2203 (re-search-forward "^X-Sent:[ \t]" nil t))
2204 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2205 date (or (get-text-property (gnus-point-at-bol)
2208 eface (get-text-property (1- (gnus-point-at-eol))
2210 (let ((buffer-read-only nil))
2211 ;; Delete any old X-Sent headers.
2212 (when (setq date-pos
2213 (text-property-any (point-min) (point-max)
2214 'article-date-lapsed t))
2215 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2216 (delete-region (match-beginning 0)
2217 (progn (forward-line 1) (point))))
2218 (goto-char (point-min))
2219 ;; Delete any old Date headers.
2220 (while (re-search-forward "^Date:[ \t]" nil t)
2222 (setq date-pos (match-beginning 0)))
2223 (unless (and (eq type 'lapsed)
2224 gnus-article-date-lapsed-new-header)
2225 (delete-region (match-beginning 0)
2226 (progn (message-next-header) (point)))))
2229 (goto-char date-pos)
2231 ;; Possibly, Date has been deleted.
2233 (when (and (eq type 'lapsed)
2234 gnus-article-date-lapsed-new-header
2235 (looking-at "Date:"))
2237 (goto-char (point-min)))
2238 (insert (article-make-date-line date type))
2239 (when (eq type 'lapsed)
2240 (put-text-property (gnus-point-at-bol) (point)
2241 'article-date-lapsed t))
2245 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2246 (put-text-property (match-beginning 1) (1+ (match-end 1))
2247 'original-date date)
2248 (put-text-property (match-beginning 1) (1+ (match-end 1))
2250 (put-text-property (match-beginning 2) (match-end 2)
2253 (defun article-make-date-line (date type)
2254 "Return a DATE line of TYPE."
2255 (let ((time (condition-case ()
2259 ;; Convert to the local timezone. We have to slap a
2260 ;; `condition-case' round the calls to the timezone
2261 ;; functions since they aren't particularly resistant to
2264 (let ((tz (car (current-time-zone time))))
2265 (format "Date: %s %s%02d%02d" (current-time-string time)
2266 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2267 (/ (% (abs tz) 3600) 60))))
2268 ;; Convert to Universal Time.
2271 (current-time-string
2272 (let* ((e (parse-time-string date))
2273 (tm (apply 'encode-time e))
2275 (ls (- (cadr tm) (car (current-time-zone time)))))
2276 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2277 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2280 ;; Get the original date from the article.
2281 ((eq type 'original)
2282 (concat "Date: " (if (string-match "\n+$" date)
2283 (substring date 0 (match-beginning 0))
2285 ;; Let the user define the format.
2287 (if (gnus-functionp gnus-article-time-format)
2288 (funcall gnus-article-time-format time)
2291 (format-time-string gnus-article-time-format time))))
2294 (let ((tz (car (current-time-zone time))))
2297 (format-time-string "%Y%m%dT%H%M%S" time)
2298 (format "%s%02d%02d"
2299 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2300 (/ (% (abs tz) 3600) 60)))))
2301 ;; Do an X-Sent lapsed format.
2303 ;; If the date is seriously mangled, the timezone functions are
2304 ;; liable to bug out, so we ignore all errors.
2305 (let* ((now (current-time))
2306 (real-time (subtract-time now time))
2307 (real-sec (and real-time
2308 (+ (* (float (car real-time)) 65536)
2310 (sec (and real-time (abs real-sec)))
2320 ;; This is a bit convoluted, but basically we go
2321 ;; through the time units for years, weeks, etc,
2322 ;; and divide things to see whether that results
2323 ;; in positive answers.
2326 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2327 ;; The (remaining) seconds are too few to
2328 ;; be divided into this time unit.
2330 ;; It's big enough, so we output it.
2331 (setq sec (- sec (* num (cdr unit))))
2333 (concat (if prev ", " "") (int-to-string
2335 " " (symbol-name (car unit))
2336 (if (> num 1) "s" ""))
2338 article-time-units "")
2339 ;; If dates are odd, then it might appear like the
2340 ;; article was sent in the future.
2343 " in the future"))))))
2345 (error "Unknown conversion type: %s" type)))))
2347 (defun article-date-local (&optional highlight)
2348 "Convert the current article date to the local timezone."
2349 (interactive (list t))
2350 (article-date-ut 'local highlight))
2352 (defun article-date-original (&optional highlight)
2353 "Convert the current article date to what it was originally.
2354 This is only useful if you have used some other date conversion
2355 function and want to see what the date was before converting."
2356 (interactive (list t))
2357 (article-date-ut 'original highlight))
2359 (defun article-date-lapsed (&optional highlight)
2360 "Convert the current article date to time lapsed since it was sent."
2361 (interactive (list t))
2362 (article-date-ut 'lapsed highlight))
2364 (defun article-update-date-lapsed ()
2365 "Function to be run from a timer to update the lapsed time line."
2366 (let (deactivate-mark)
2371 (set-buffer (window-buffer w))
2372 (when (eq major-mode 'gnus-article-mode)
2373 (goto-char (point-min))
2374 (when (re-search-forward "^X-Sent:" nil t)
2375 (article-date-lapsed t))))
2378 (defun gnus-start-date-timer (&optional n)
2379 "Start a timer to update the X-Sent header in the article buffers.
2380 The numerical prefix says how frequently (in seconds) the function
2385 (gnus-stop-date-timer)
2386 (setq article-lapsed-timer
2387 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2389 (defun gnus-stop-date-timer ()
2390 "Stop the X-Sent timer."
2392 (when article-lapsed-timer
2393 (nnheader-cancel-timer article-lapsed-timer)
2394 (setq article-lapsed-timer nil)))
2396 (defun article-date-user (&optional highlight)
2397 "Convert the current article date to the user-defined format.
2398 This format is defined by the `gnus-article-time-format' variable."
2399 (interactive (list t))
2400 (article-date-ut 'user highlight))
2402 (defun article-date-iso8601 (&optional highlight)
2403 "Convert the current article date to ISO8601."
2404 (interactive (list t))
2405 (article-date-ut 'iso8601 highlight))
2407 (defun article-show-all ()
2408 "Show all hidden text in the article buffer."
2412 (let ((buffer-read-only nil))
2413 (gnus-article-unhide-text (point-min) (point-max))
2414 (gnus-remove-text-with-property 'gnus-prev)
2415 (gnus-remove-text-with-property 'gnus-next))))
2417 (defun article-show-all-headers ()
2418 "Show all hidden headers in the article buffer."
2423 (article-narrow-to-head)
2424 (let ((buffer-read-only nil))
2425 (gnus-article-unhide-text (point-min) (point-max))))))
2427 (defun article-emphasize (&optional arg)
2428 "Emphasize text according to `gnus-emphasis-alist'."
2429 (interactive (gnus-article-hidden-arg))
2430 (unless (gnus-article-check-hidden-text 'emphasis arg)
2434 (with-current-buffer gnus-summary-buffer
2435 gnus-article-emphasis-alist)
2437 gnus-emphasis-alist))
2438 (buffer-read-only nil)
2439 (props (append '(article-type emphasis)
2440 gnus-hidden-properties))
2441 regexp elem beg invisible visible face)
2444 (while (setq elem (pop alist))
2446 (setq regexp (car elem)
2447 invisible (nth 1 elem)
2448 visible (nth 2 elem)
2450 (while (re-search-forward regexp nil t)
2451 (when (and (match-beginning visible) (match-beginning invisible))
2452 (push 'emphasis gnus-article-wash-types)
2453 (gnus-article-hide-text
2454 (match-beginning invisible) (match-end invisible) props)
2455 (gnus-article-unhide-text-type
2456 (match-beginning visible) (match-end visible) 'emphasis)
2457 (gnus-put-text-property-excluding-newlines
2458 (match-beginning visible) (match-end visible) 'face face)
2459 (goto-char (match-end invisible)))))))))
2461 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2462 "Setup newsgroup emphasis alist."
2463 (unless gnus-article-emphasis-alist
2464 (let ((name (and gnus-newsgroup-name
2465 (gnus-group-real-name gnus-newsgroup-name))))
2466 (make-local-variable 'gnus-article-emphasis-alist)
2467 (setq gnus-article-emphasis-alist
2469 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2470 (while (setq elem (pop alist))
2471 (when (and name (string-match (car elem) name))
2473 highlight (copy-sequence (cdr elem)))))
2475 (copy-sequence highlight-words)
2476 (if gnus-newsgroup-name
2477 (copy-sequence (gnus-group-find-parameter
2478 gnus-newsgroup-name 'highlight-words t)))
2479 gnus-emphasis-alist)))))
2481 (defvar gnus-summary-article-menu)
2482 (defvar gnus-summary-post-menu)
2484 ;;; Saving functions.
2486 (defun gnus-article-save (save-buffer file &optional num)
2487 "Save the currently selected article."
2488 (unless gnus-save-all-headers
2489 ;; Remove headers according to `gnus-saved-headers'.
2490 (let ((gnus-visible-headers
2491 (or gnus-saved-headers gnus-visible-headers))
2492 (gnus-article-buffer save-buffer))
2494 (set-buffer save-buffer)
2495 (article-hide-headers 1 t))))
2496 (save-window-excursion
2497 (if (not gnus-default-article-saver)
2498 (error "No default saver is defined")
2499 ;; !!! Magic! The saving functions all save
2500 ;; `gnus-save-article-buffer' (or so they think), but we
2501 ;; bind that variable to our save-buffer.
2502 (set-buffer gnus-article-buffer)
2503 (let* ((gnus-save-article-buffer save-buffer)
2506 ((not gnus-prompt-before-saving) 'default)
2507 ((eq gnus-prompt-before-saving 'always) nil)
2509 (gnus-number-of-articles-to-be-saved
2510 (when (eq gnus-prompt-before-saving t)
2512 (set-buffer gnus-article-current-summary)
2513 (funcall gnus-default-article-saver filename)))))
2515 (defun gnus-read-save-file-name (prompt &optional filename
2516 function group headers variable)
2518 (funcall function group headers (symbol-value variable)))
2523 ((eq filename 'default)
2529 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2532 (if (and gnus-number-of-articles-to-be-saved
2533 (> gnus-number-of-articles-to-be-saved 1))
2534 (format "these %d articles"
2535 gnus-number-of-articles-to-be-saved)
2538 ;; Let the split methods have their say.
2540 ;; No split name was found.
2543 (concat prompt " (default "
2544 (file-name-nondirectory default-name) ") ")
2545 (file-name-directory default-name)
2547 ;; A single group name is returned.
2548 ((stringp split-name)
2550 (funcall function split-name headers
2551 (symbol-value variable)))
2553 (concat prompt " (default "
2554 (file-name-nondirectory default-name) ") ")
2555 (file-name-directory default-name)
2557 ;; A single split name was found
2558 ((= 1 (length split-name))
2559 (let* ((name (expand-file-name
2561 gnus-article-save-directory))
2562 (dir (cond ((file-directory-p name)
2563 (file-name-as-directory name))
2564 ((file-exists-p name) name)
2565 (t gnus-article-save-directory))))
2567 (concat prompt " (default " name ") ")
2569 ;; A list of splits was found.
2571 (setq split-name (nreverse split-name))
2573 (let ((file-name-history
2574 (nconc split-name file-name-history)))
2578 (concat prompt " (`M-p' for defaults) ")
2579 gnus-article-save-directory
2581 gnus-article-save-directory)))
2582 (car (push result file-name-history)))))))
2583 ;; Create the directory.
2584 (gnus-make-directory (file-name-directory file))
2585 ;; If we have read a directory, we append the default file name.
2586 (when (file-directory-p file)
2587 (setq file (expand-file-name (file-name-nondirectory
2589 (file-name-as-directory file))))
2590 ;; Possibly translate some characters.
2591 (nnheader-translate-file-chars file))))))
2592 (gnus-make-directory (file-name-directory result))
2593 (set variable result)))
2595 (defun gnus-article-archive-name (group)
2596 "Return the first instance of an \"Archive-name\" in the current buffer."
2597 (let ((case-fold-search t))
2598 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2599 (nnheader-concat gnus-article-save-directory
2600 (match-string 1)))))
2602 (defun gnus-article-nndoc-name (group)
2603 "If GROUP is an nndoc group, return the name of the parent group."
2604 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2605 (gnus-group-get-parameter group 'save-article-group)))
2607 (defun gnus-summary-save-in-rmail (&optional filename)
2608 "Append this article to Rmail file.
2609 Optional argument FILENAME specifies file name.
2610 Directory to save to is default to `gnus-article-save-directory'."
2611 (setq filename (gnus-read-save-file-name
2612 "Save %s in rmail file:" filename
2613 gnus-rmail-save-name gnus-newsgroup-name
2614 gnus-current-headers 'gnus-newsgroup-last-rmail))
2615 (gnus-eval-in-buffer-window gnus-save-article-buffer
2619 (gnus-output-to-rmail filename))))
2622 (defun gnus-summary-save-in-mail (&optional filename)
2623 "Append this article to Unix mail file.
2624 Optional argument FILENAME specifies file name.
2625 Directory to save to is default to `gnus-article-save-directory'."
2626 (setq filename (gnus-read-save-file-name
2627 "Save %s in Unix mail file:" filename
2628 gnus-mail-save-name gnus-newsgroup-name
2629 gnus-current-headers 'gnus-newsgroup-last-mail))
2630 (gnus-eval-in-buffer-window gnus-save-article-buffer
2634 (if (and (file-readable-p filename)
2635 (mail-file-babyl-p filename))
2636 (rmail-output-to-rmail-file filename t)
2637 (gnus-output-to-mail filename)))))
2640 (defun gnus-summary-save-in-file (&optional filename overwrite)
2641 "Append this article to file.
2642 Optional argument FILENAME specifies file name.
2643 Directory to save to is default to `gnus-article-save-directory'."
2644 (setq filename (gnus-read-save-file-name
2645 "Save %s in file:" filename
2646 gnus-file-save-name gnus-newsgroup-name
2647 gnus-current-headers 'gnus-newsgroup-last-file))
2648 (gnus-eval-in-buffer-window gnus-save-article-buffer
2652 (when (and overwrite
2653 (file-exists-p filename))
2654 (delete-file filename))
2655 (gnus-output-to-file filename))))
2658 (defun gnus-summary-write-to-file (&optional filename)
2659 "Write this article to a file.
2660 Optional argument FILENAME specifies file name.
2661 The directory to save in defaults to `gnus-article-save-directory'."
2662 (gnus-summary-save-in-file nil t))
2664 (defun gnus-summary-save-body-in-file (&optional filename)
2665 "Append this article body to a file.
2666 Optional argument FILENAME specifies file name.
2667 The directory to save in defaults to `gnus-article-save-directory'."
2668 (setq filename (gnus-read-save-file-name
2669 "Save %s body in file:" filename
2670 gnus-file-save-name gnus-newsgroup-name
2671 gnus-current-headers 'gnus-newsgroup-last-file))
2672 (gnus-eval-in-buffer-window gnus-save-article-buffer
2676 (when (article-goto-body)
2677 (narrow-to-region (point) (point-max)))
2678 (gnus-output-to-file filename))))
2681 (defun gnus-summary-save-in-pipe (&optional command)
2682 "Pipe this article to subprocess."
2684 (cond ((and (eq command 'default)
2685 gnus-last-shell-command)
2686 gnus-last-shell-command)
2690 "Shell command on %s: "
2691 (if (and gnus-number-of-articles-to-be-saved
2692 (> gnus-number-of-articles-to-be-saved 1))
2693 (format "these %d articles"
2694 gnus-number-of-articles-to-be-saved)
2696 gnus-last-shell-command))))
2697 (when (string-equal command "")
2698 (setq command gnus-last-shell-command))
2699 (gnus-eval-in-buffer-window gnus-article-buffer
2702 (shell-command-on-region (point-min) (point-max) command nil)))
2703 (setq gnus-last-shell-command command))
2705 ;;; Article file names when saving.
2707 (defun gnus-capitalize-newsgroup (newsgroup)
2708 "Capitalize NEWSGROUP name."
2709 (when (not (zerop (length newsgroup)))
2710 (concat (char-to-string (upcase (aref newsgroup 0)))
2711 (substring newsgroup 1))))
2713 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2714 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2715 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2716 Otherwise, it is like ~/News/news/group/num."
2719 (concat (if (gnus-use-long-file-name 'not-save)
2720 (gnus-capitalize-newsgroup newsgroup)
2721 (gnus-newsgroup-directory-form newsgroup))
2722 "/" (int-to-string (mail-header-number headers)))
2723 gnus-article-save-directory)))
2725 (string-equal (file-name-directory default)
2726 (file-name-directory last-file))
2727 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2729 (or last-file default))))
2731 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2732 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2733 If variable `gnus-use-long-file-name' is non-nil, it is
2734 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2737 (concat (if (gnus-use-long-file-name 'not-save)
2739 (gnus-newsgroup-directory-form newsgroup))
2740 "/" (int-to-string (mail-header-number headers)))
2741 gnus-article-save-directory)))
2743 (string-equal (file-name-directory default)
2744 (file-name-directory last-file))
2745 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2747 (or last-file default))))
2749 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2750 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2751 If variable `gnus-use-long-file-name' is non-nil, it is
2752 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2755 (if (gnus-use-long-file-name 'not-save)
2757 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2758 gnus-article-save-directory)))
2760 (autoload 'mm-uu-pgp-signed-test "mm-uu")
2762 (defun article-verify-x-pgp-sig ()
2765 (if (gnus-buffer-live-p gnus-original-article-buffer)
2766 (let ((sig (with-current-buffer gnus-original-article-buffer
2767 (gnus-fetch-field "X-PGP-Sig")))
2769 (when (and sig (mm-uu-pgp-signed-test))
2771 (insert-buffer gnus-original-article-buffer)
2772 (setq items (split-string sig))
2773 (message-narrow-to-head)
2774 (let ((inhibit-point-motion-hooks t)
2775 (case-fold-search t))
2776 ;; Don't verify multiple headers.
2777 (setq headers (mapconcat (lambda (header)
2779 (mail-fetch-field header) "\n"))
2780 (split-string (nth 1 items) ",") "")))
2781 (delete-region (point-min) (point-max))
2782 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2783 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2788 (if (looking-at "^-")
2791 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2792 (insert "Version: " (car items) "\n\n")
2793 (insert (mapconcat 'identity (cddr items) "\n"))
2794 (insert "\n-----END PGP SIGNATURE-----\n")
2795 (let ((mm-security-handle (list (format "multipart/signed"))))
2796 (mml2015-clean-buffer)
2797 (let ((coding-system-for-write (or gnus-newsgroup-charset
2799 (funcall (mml2015-clear-verify-function)))
2801 (or (mm-handle-multipart-ctl-parameter
2802 mm-security-handle 'gnus-details)
2803 (mm-handle-multipart-ctl-parameter
2804 mm-security-handle 'gnus-info)))))
2806 (let (buffer-read-only bface eface)
2808 (message-narrow-to-head)
2809 (goto-char (point-max))
2811 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2812 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2813 (message-remove-header "X-Gnus-PGP-Verify")
2814 (if (re-search-forward "^X-PGP-Sig:" nil t)
2816 (goto-char (point-max)))
2817 (narrow-to-region (point) (point))
2818 (insert "X-Gnus-PGP-Verify: " info "\n")
2819 (goto-char (point-min))
2822 (if (not (looking-at "^[ \t]"))
2826 (goto-char (point-min))
2827 (when (looking-at "\\([^:]+\\): *")
2828 (put-text-property (match-beginning 1) (1+ (match-end 1))
2830 (put-text-property (match-end 0) (point-max)
2831 'face eface)))))))))
2838 (setq afunc (car func)
2841 gfunc (intern (format "gnus-%s" func))))
2844 `(lambda (&optional interactive &rest args)
2845 ,(documentation afunc t)
2846 (interactive (list t))
2848 (set-buffer gnus-article-buffer)
2850 (call-interactively ',afunc)
2851 (apply ',afunc args))))))))
2852 '(article-hide-headers
2853 article-verify-x-pgp-sig
2854 article-hide-boring-headers
2855 article-toggle-headers
2856 article-treat-overstrike
2857 article-fill-long-lines
2858 article-capitalize-sentences
2860 article-display-x-face
2861 article-de-quoted-unreadable
2862 article-de-base64-unreadable
2865 article-hide-list-identifiers
2867 article-strip-banner
2870 article-hide-signature
2871 article-strip-headers-in-body
2872 article-remove-trailing-blank-lines
2873 article-strip-leading-blank-lines
2874 article-strip-multiple-blank-lines
2875 article-strip-leading-space
2876 article-strip-trailing-space
2877 article-strip-blank-lines
2878 article-strip-all-blank-lines
2880 article-date-iso8601
2881 article-date-original
2883 article-decode-mime-words
2884 article-decode-charset
2885 article-decode-encoded-words
2889 article-treat-dumbquotes
2890 article-normalize-headers
2891 (article-show-all-headers . gnus-article-show-all-headers)
2892 (article-show-all . gnus-article-show-all))))
2895 ;;; Gnus article mode
2898 (put 'gnus-article-mode 'mode-class 'special)
2900 (gnus-define-keys gnus-article-mode-map
2901 " " gnus-article-goto-next-page
2902 "\177" gnus-article-goto-prev-page
2903 [delete] gnus-article-goto-prev-page
2904 [backspace] gnus-article-goto-prev-page
2905 "\C-c^" gnus-article-refer-article
2906 "h" gnus-article-show-summary
2907 "s" gnus-article-show-summary
2908 "\C-c\C-m" gnus-article-mail
2909 "?" gnus-article-describe-briefly
2910 "e" gnus-summary-edit-article
2911 "<" beginning-of-buffer
2913 "\C-c\C-i" gnus-info-find-node
2915 "\C-hk" gnus-article-describe-key
2916 "\C-hc" gnus-article-describe-key-briefly
2918 "\C-d" gnus-article-read-summary-keys
2919 "\M-*" gnus-article-read-summary-keys
2920 "\M-#" gnus-article-read-summary-keys
2921 "\M-^" gnus-article-read-summary-keys
2922 "\M-g" gnus-article-read-summary-keys)
2924 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2927 (unless (lookup-key gnus-article-mode-map key)
2928 (define-key gnus-article-mode-map key
2929 'gnus-article-read-summary-keys)))
2934 (let ((key (car elt)))
2935 (and (> (length key) 0)
2936 (not (eq 'menu-bar (aref key 0)))
2937 (symbolp (lookup-key gnus-summary-mode-map key))
2939 (accessible-keymaps gnus-summary-mode-map))
2943 (push (char-to-string c) keys)
2948 (defvar gnus-article-commands-menu))
2950 (defun gnus-article-make-menu-bar ()
2951 (gnus-turn-off-edit-menu 'article)
2952 (unless (boundp 'gnus-article-article-menu)
2954 gnus-article-article-menu gnus-article-mode-map ""
2956 ["Scroll forwards" gnus-article-goto-next-page t]
2957 ["Scroll backwards" gnus-article-goto-prev-page t]
2958 ["Show summary" gnus-article-show-summary t]
2959 ["Fetch Message-ID at point" gnus-article-refer-article t]
2960 ["Mail to address at point" gnus-article-mail t]
2961 ["Send a bug report" gnus-bug t]))
2964 gnus-article-treatment-menu gnus-article-mode-map ""
2966 ["Hide headers" gnus-article-toggle-headers t]
2967 ["Hide signature" gnus-article-hide-signature t]
2968 ["Hide citation" gnus-article-hide-citation t]
2969 ["Treat overstrike" gnus-article-treat-overstrike t]
2970 ["Remove carriage return" gnus-article-remove-cr t]
2971 ["Decode HZ" gnus-article-decode-HZ t]))
2973 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2975 (when (boundp 'gnus-summary-post-menu)
2976 (define-key gnus-article-mode-map [menu-bar post]
2977 (cons "Post" gnus-summary-post-menu)))
2979 (gnus-run-hooks 'gnus-article-menu-hook))
2981 (when (boundp 'gnus-article-commands-menu)
2982 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
2983 (when (boundp 'gnus-summary-post-menu)
2984 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
2986 (defun gnus-article-mode ()
2987 "Major mode for displaying an article.
2989 All normal editing commands are switched off.
2991 The following commands are available in addition to all summary mode
2993 \\<gnus-article-mode-map>
2994 \\[gnus-article-next-page]\t Scroll the article one page forwards
2995 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2996 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2997 \\[gnus-article-show-summary]\t Display the summary buffer
2998 \\[gnus-article-mail]\t Send a reply to the address near point
2999 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3000 \\[gnus-info-find-node]\t Go to the Gnus info node"
3002 (when (gnus-visual-p 'article-menu 'menu)
3003 (gnus-article-make-menu-bar))
3004 (gnus-simplify-mode-line)
3005 (setq mode-name "Article")
3006 (setq major-mode 'gnus-article-mode)
3007 (make-local-variable 'minor-mode-alist)
3008 (unless (assq 'gnus-show-mime minor-mode-alist)
3009 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3010 (use-local-map gnus-article-mode-map)
3011 (gnus-update-format-specifications nil 'article-mode)
3012 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3013 (make-local-variable 'gnus-page-broken)
3014 (make-local-variable 'gnus-button-marker-list)
3015 (make-local-variable 'gnus-article-current-summary)
3016 (make-local-variable 'gnus-article-mime-handles)
3017 (make-local-variable 'gnus-article-decoded-p)
3018 (make-local-variable 'gnus-article-mime-handle-alist)
3019 (make-local-variable 'gnus-article-wash-types)
3020 (make-local-variable 'gnus-article-charset)
3021 (make-local-variable 'gnus-article-ignored-charsets)
3022 (gnus-set-default-directory)
3023 (buffer-disable-undo)
3024 (setq buffer-read-only t)
3025 (set-syntax-table gnus-article-mode-syntax-table)
3026 (gnus-run-hooks 'gnus-article-mode-hook))
3028 (defun gnus-article-setup-buffer ()
3029 "Initialize the article buffer."
3030 (let* ((name (if gnus-single-article-buffer "*Article*"
3031 (concat "*Article " gnus-newsgroup-name "*")))
3033 (progn (string-match "\\*Article" name)
3034 (concat " *Original Article"
3035 (substring name (match-end 0))))))
3036 (setq gnus-article-buffer name)
3037 (setq gnus-original-article-buffer original)
3038 (setq gnus-article-mime-handle-alist nil)
3039 ;; This might be a variable local to the summary buffer.
3040 (unless gnus-single-article-buffer
3042 (set-buffer gnus-summary-buffer)
3043 (setq gnus-article-buffer name)
3044 (setq gnus-original-article-buffer original)
3045 (gnus-set-global-variables)))
3046 (gnus-article-setup-highlight-words)
3047 ;; Init original article buffer.
3049 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3050 (set-buffer-multibyte nil)
3051 (setq major-mode 'gnus-original-article-mode)
3052 (make-local-variable 'gnus-original-article))
3053 (if (get-buffer name)
3056 (buffer-disable-undo)
3057 (setq buffer-read-only t)
3058 (unless (eq major-mode 'gnus-article-mode)
3059 (gnus-article-mode))
3062 (set-buffer (gnus-get-buffer-create name))
3064 (make-local-variable 'gnus-summary-buffer)
3065 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3066 (current-buffer)))))
3068 ;; Set article window start at LINE, where LINE is the number of lines
3069 ;; from the head of the article.
3070 (defun gnus-article-set-window-start (&optional line)
3072 (get-buffer-window gnus-article-buffer t)
3074 (set-buffer gnus-article-buffer)
3075 (goto-char (point-min))
3078 (gnus-message 6 "Moved to bookmark")
3079 (search-forward "\n\n" nil t)
3083 ;;; @@ article filters
3086 (defun gnus-article-display-mime-message ()
3087 "Article display method for MIME message."
3088 ;; called from `gnus-original-article-buffer'.
3089 (let (charset all-headers)
3090 (with-current-buffer gnus-summary-buffer
3091 (setq charset default-mime-charset
3092 all-headers gnus-have-all-headers))
3093 (make-local-variable 'default-mime-charset)
3094 (setq default-mime-charset charset)
3095 (with-current-buffer (get-buffer-create gnus-article-buffer)
3096 (make-local-variable 'default-mime-charset)
3097 (setq default-mime-charset charset))
3098 (mime-display-message mime-message-structure
3099 gnus-article-buffer nil gnus-article-mode-map)
3101 (gnus-article-hide-headers nil -1)))
3102 (run-hooks 'gnus-mime-article-prepare-hook))
3104 (defun gnus-article-display-traditional-message ()
3105 "Article display method for traditional message."
3106 (set-buffer gnus-article-buffer)
3107 (let (buffer-read-only)
3109 (insert-buffer-substring gnus-original-article-buffer)))
3111 (defun gnus-article-make-full-mail-header (&optional number charset)
3112 "Create a new mail header structure in a raw article buffer."
3113 (unless (and number charset)
3114 (save-current-buffer
3115 (set-buffer gnus-summary-buffer)
3117 (setq number (or (cdr gnus-article-current) 0)))
3119 (setq charset (or default-mime-charset 'x-ctext)))))
3120 (goto-char (point-min))
3121 (let ((header-end (if (search-forward "\n\n" nil t)
3123 (goto-char (point-max))))
3124 (chars (- (point-max) (point)))
3125 (lines (count-lines (point) (point-max)))
3126 (default-mime-charset charset)
3128 (narrow-to-region (point-min) header-end)
3129 (setq xref (std11-fetch-field "xref"))
3131 (make-full-mail-header
3133 (std11-fetch-field "subject")
3134 (std11-fetch-field "from")
3135 (std11-fetch-field "date")
3136 (std11-fetch-field "message-id")
3137 (std11-fetch-field "references")
3140 (when xref (concat "Xref: " xref)))
3143 (defun gnus-article-prepare (article &optional all-headers header)
3144 "Prepare ARTICLE in article mode buffer.
3145 ARTICLE should either be an article number or a Message-ID.
3146 If ARTICLE is an id, HEADER should be the article headers.
3147 If ALL-HEADERS is non-nil, no headers are hidden."
3149 ;; Make sure we start in a summary buffer.
3150 (unless (eq major-mode 'gnus-summary-mode)
3151 (set-buffer gnus-summary-buffer))
3152 (setq gnus-summary-buffer (current-buffer))
3153 (let* ((gnus-article (if header (mail-header-number header) article))
3154 (summary-buffer (current-buffer))
3155 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3156 (group gnus-newsgroup-name)
3159 (gnus-article-setup-buffer)
3160 (set-buffer gnus-original-article-buffer)
3161 ;; Deactivate active regions.
3162 (when (and (boundp 'transient-mark-mode)
3163 transient-mark-mode)
3164 (setq mark-active nil))
3165 (if (not (setq result (let ((buffer-read-only nil))
3166 (gnus-request-article-this-buffer
3168 ;; There is no such article.
3170 (when (and (numberp article)
3171 (not (memq article gnus-newsgroup-sparse)))
3172 (setq gnus-article-current
3173 (cons gnus-newsgroup-name article))
3174 (set-buffer gnus-summary-buffer)
3175 (setq gnus-current-article article)
3176 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3178 (gnus-summary-set-agent-mark article)
3179 (message "Message marked for downloading"))
3180 (gnus-summary-mark-article article gnus-canceled-mark)
3181 (unless (memq article gnus-newsgroup-sparse)
3182 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3183 (if (or (eq result 'pseudo)
3184 (eq result 'nneething))
3187 (set-buffer summary-buffer)
3188 (push article gnus-newsgroup-history)
3189 (setq gnus-last-article gnus-current-article
3190 gnus-current-article 0
3191 gnus-current-headers nil
3192 gnus-article-current nil)
3193 (if (eq result 'nneething)
3194 (gnus-configure-windows 'summary)
3195 (gnus-configure-windows 'article))
3196 (gnus-set-global-variables))
3197 (let ((gnus-article-mime-handle-alist-1
3198 gnus-article-mime-handle-alist))
3199 (gnus-set-mode-line 'article)))
3200 ;; The result from the `request' was an actual article -
3201 ;; or at least some text that is now displayed in the
3203 (when (and (numberp article)
3204 (not (eq article gnus-current-article)))
3205 ;; Seems like a new article has been selected.
3206 ;; `gnus-current-article' must be an article number.
3208 (set-buffer summary-buffer)
3209 (push article gnus-newsgroup-history)
3210 (setq gnus-last-article gnus-current-article
3211 gnus-current-article article
3212 gnus-current-headers
3213 (gnus-summary-article-header gnus-current-article)
3214 gnus-article-current
3215 (cons gnus-newsgroup-name gnus-current-article))
3216 (unless (vectorp gnus-current-headers)
3217 (setq gnus-current-headers nil))
3218 (gnus-summary-goto-subject gnus-current-article)
3219 (when (gnus-summary-show-thread)
3220 ;; If the summary buffer really was folded, the
3221 ;; previous goto may not actually have gone to
3222 ;; the right article, but the thread root instead.
3224 (gnus-summary-goto-subject gnus-current-article))
3225 (gnus-run-hooks 'gnus-mark-article-hook)
3226 (gnus-set-mode-line 'summary)
3227 (when (gnus-visual-p 'article-highlight 'highlight)
3228 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3229 ;; Set the global newsgroup variables here.
3230 (gnus-set-global-variables)
3231 (setq gnus-have-all-headers
3232 (or all-headers gnus-show-all-headers))))
3234 (gnus-configure-windows 'article))
3235 (when (or (numberp article)
3237 (gnus-article-prepare-display)
3239 (goto-char (point-min))
3240 (setq gnus-page-broken
3241 (when gnus-break-pages
3242 (gnus-narrow-to-page)
3244 (let ((gnus-article-mime-handle-alist-1
3245 gnus-article-mime-handle-alist))
3246 (gnus-set-mode-line 'article))
3248 (set-window-point (get-buffer-window (current-buffer)) (point))
3249 (gnus-configure-windows 'article)
3252 (defun gnus-article-prepare-mime-display (&optional number)
3253 (goto-char (point-min))
3254 (when (re-search-forward "^[^\t ]+:" nil t)
3255 (goto-char (match-beginning 0)))
3256 (let ((entity (if (eq 1 (point-min))
3257 (get-text-property 1 'mime-view-entity)
3258 (get-text-property (point) 'mime-view-entity)))
3259 last-entity child-entity next type)
3260 (setq child-entity (mime-entity-children entity))
3262 (setq last-entity (nth (1- (length child-entity))
3264 (setq last-entity entity))
3266 (narrow-to-region (point)
3267 (if (search-forward "\n\n" nil t)
3270 (gnus-treat-article 'head)
3271 (put-text-property (point-min) (point-max) 'article-treated-header t)
3272 (goto-char (point-max)))
3273 (while (and (not (eobp)) entity)
3274 (setq next (set-marker
3276 (next-single-property-change (point) 'mime-view-entity
3278 (let ((types (mime-entity-content-type entity)))
3279 (while (eq 'multipart (mime-content-type-primary-type types))
3280 (setq entity (car (mime-entity-children entity))
3281 types (mime-entity-content-type entity)))
3283 (setq type (format "%s/%s"
3284 (mime-content-type-primary-type types)
3285 (mime-content-type-subtype types)))))
3286 (if (string-equal type "message/rfc822")
3289 (let ((children (mime-entity-children entity))
3292 (setq last-children (nth (1- (length children)) children))
3295 (not (eq last-children
3296 (get-text-property next 'mime-view-entity)))
3298 (next-single-property-change next
3300 nil (point-max)))))))
3301 (setq next (next-single-property-change next 'mime-view-entity
3304 (narrow-to-region (point) next)
3305 (gnus-article-prepare-mime-display)
3306 (goto-char (point-max)))
3307 (setq entity (get-text-property (point) 'mime-view-entity)))
3309 (narrow-to-region (point) next)
3310 ;; Kludge. We have to count true number, but for now,
3311 ;; part number is here only to achieve `last'.
3312 (gnus-treat-article nil 1
3313 (if (eq entity last-entity)
3316 (goto-char (point-max)))
3317 (setq entity (get-text-property next 'mime-view-entity))))))
3320 (defun gnus-article-prepare-display ()
3321 "Make the current buffer look like a nice article."
3322 (setq gnus-article-wash-types nil)
3323 (gnus-run-hooks 'gnus-tmp-internal-hook)
3324 (gnus-run-hooks 'gnus-article-prepare-hook)
3326 (let (mime-display-header-hook mime-display-text/plain-hook)
3327 (funcall (if gnus-show-mime
3329 (setq mime-message-structure gnus-current-headers)
3330 (mime-buffer-entity-set-buffer-internal
3331 mime-message-structure
3332 gnus-original-article-buffer)
3333 (mime-entity-set-representation-type-internal
3334 mime-message-structure 'mime-buffer-entity)
3335 (luna-send mime-message-structure
3336 'initialize-instance
3337 mime-message-structure)
3338 gnus-article-display-method-for-mime)
3339 gnus-article-display-method-for-traditional)))
3340 ;; Associate this article with the current summary buffer.
3341 (setq gnus-article-current-summary gnus-summary-buffer)
3342 ;; Call the treatment functions.
3343 (let ((inhibit-read-only t)
3348 (gnus-article-prepare-mime-display)
3349 (narrow-to-region (goto-char (point-min))
3350 (if (search-forward "\n\n" nil t)
3353 (gnus-treat-article 'head)
3354 (put-text-property (point-min) (point-max) 'article-treated-header t)
3355 (goto-char (point-max))
3357 (narrow-to-region (point) (point-max))
3358 (gnus-treat-article nil))
3359 (put-text-property (point-min) (point-max) 'read-only nil)))
3360 ;; Perform the article display hooks. Incidentally, this hook is
3361 ;; an obsolete variable by now.
3362 (gnus-run-hooks 'gnus-article-display-hook))
3364 (defun gnus-article-decode-article-as-default-mime-charset ()
3365 "Decode an article as `default-mime-charset'. It won't work if the
3366 value of the variable `gnus-show-mime' is non-nil."
3367 (unless gnus-show-mime
3368 (decode-mime-charset-region (point-min) (point-max)
3369 (with-current-buffer gnus-summary-buffer
3370 default-mime-charset))))
3373 ;;; Gnus MIME viewing functions
3376 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3377 "The following specs can be used:
3379 %T MIME type, along with additional info
3380 %n The `name' parameter
3381 %d The description, if any
3382 %l The length of the encoded part
3383 %p The part identifier number
3384 %e Dots if the part isn't displayed")
3386 (defvar gnus-mime-button-line-format-alist
3387 '((?t gnus-tmp-type ?s)
3388 (?T gnus-tmp-type-long ?s)
3389 (?n gnus-tmp-name ?s)
3390 (?d gnus-tmp-description ?s)
3392 (?l gnus-tmp-length ?d)
3393 (?e gnus-tmp-dots ?s)))
3395 (defvar gnus-mime-button-commands
3396 '((gnus-article-press-button "\r" "Toggle Display")
3397 (gnus-mime-view-part "v" "View Interactively...")
3398 (gnus-mime-view-part-as-type "t" "View As Type...")
3399 (gnus-mime-view-part-as-charset "C" "View As charset...")
3400 (gnus-mime-save-part "o" "Save...")
3401 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3402 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3403 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3404 (gnus-mime-internalize-part "E" "View Internally")
3405 (gnus-mime-externalize-part "e" "View Externally")
3406 (gnus-mime-pipe-part "|" "Pipe To Command...")
3407 (gnus-mime-action-on-part "." "Take action on the part")))
3409 (defun gnus-article-mime-part-status ()
3410 (with-current-buffer gnus-article-buffer
3411 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3412 (if (and entity (mime-entity-children entity))
3413 (format " (%d parts)" (length (mime-entity-children entity)))
3416 (defvar gnus-mime-button-map
3417 (let ((map (make-sparse-keymap)))
3418 (set-keymap-parent map gnus-article-mode-map)
3419 (define-key map gnus-mouse-2 'gnus-article-push-button)
3420 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3421 (dolist (c gnus-mime-button-commands)
3422 (define-key map (cadr c) (car c)))
3425 (defun gnus-mime-button-menu (event)
3426 "Construct a context-sensitive menu of MIME commands."
3428 (save-window-excursion
3429 (let ((pos (event-start event)))
3430 (select-window (posn-window pos))
3431 (goto-char (posn-point pos))
3432 (gnus-article-check-buffer)
3433 (let ((response (x-popup-menu
3435 ("" ,@(mapcar (lambda (c)
3436 (cons (caddr c) (car c)))
3437 gnus-mime-button-commands))))))
3439 (call-interactively response))))))
3441 (defun gnus-mime-view-all-parts (&optional handles)
3442 "View all the MIME parts."
3444 (save-current-buffer
3445 (set-buffer gnus-article-buffer)
3446 (let ((handles (or handles gnus-article-mime-handles))
3447 (mail-parse-charset gnus-newsgroup-charset)
3448 (mail-parse-ignored-charsets
3449 (with-current-buffer gnus-summary-buffer
3450 gnus-newsgroup-ignored-charsets)))
3451 (mm-remove-parts handles)
3452 (goto-char (point-min))
3453 (or (search-forward "\n\n") (goto-char (point-max)))
3454 (let (buffer-read-only)
3455 (delete-region (point) (point-max)))
3456 (mm-display-parts handles))))
3458 (defun gnus-mime-save-part-and-strip ()
3459 "Save the MIME part under point then replace it with an external body."
3461 (gnus-article-check-buffer)
3462 (let* ((data (get-text-property (point) 'gnus-data))
3463 (file (mm-save-part data))
3466 (with-current-buffer (mm-handle-buffer data)
3468 (insert "Content-Type: " (mm-handle-media-type data))
3469 (mml-insert-parameter-string (cdr (mm-handle-type data))
3472 (insert "Content-ID: " (message-make-message-id) "\n")
3473 (insert "Content-Transfer-Encoding: binary\n")
3476 (cdr (mm-make-handle nil
3477 `("message/external-body"
3478 (access-type . "LOCAL-FILE")
3480 (set-buffer gnus-summary-buffer)
3481 (gnus-article-edit-article
3484 (let ((mail-parse-charset (or gnus-article-charset
3485 ',gnus-newsgroup-charset))
3486 (mail-parse-ignored-charsets
3487 (or gnus-article-ignored-charsets
3488 ',gnus-newsgroup-ignored-charsets))
3489 (mbl mml-buffer-list))
3490 (setq mml-buffer-list nil)
3491 (insert-buffer gnus-original-article-buffer)
3492 (mime-to-mml gnus-article-mime-handles)
3493 (setq gnus-article-mime-handles nil)
3494 (make-local-hook 'kill-buffer-hook)
3495 (let ((mbl1 mml-buffer-list))
3496 (setq mml-buffer-list mbl)
3497 (set (make-local-variable 'mml-buffer-list) mbl1))
3498 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3499 `(lambda (no-highlight)
3500 (let ((mail-parse-charset (or gnus-article-charset
3501 ',gnus-newsgroup-charset))
3502 (message-options message-options)
3503 (message-options-set-recipient)
3504 (mail-parse-ignored-charsets
3505 (or gnus-article-ignored-charsets
3506 ',gnus-newsgroup-ignored-charsets)))
3508 (mml-destroy-buffers)
3509 (remove-hook 'kill-buffer-hook
3510 'mml-destroy-buffers t)
3511 (kill-local-variable 'mml-buffer-list))
3512 (gnus-summary-edit-article-done
3513 ,(or (mail-header-references gnus-current-headers) "")
3514 ,(gnus-group-read-only-p)
3515 ,gnus-summary-buffer no-highlight))))))
3517 (defun gnus-mime-save-part ()
3518 "Save the MIME part under point."
3520 (gnus-article-check-buffer)
3521 (let ((data (get-text-property (point) 'gnus-data)))
3522 (mm-save-part data)))
3524 (defun gnus-mime-pipe-part ()
3525 "Pipe the MIME part under point to a process."
3527 (gnus-article-check-buffer)
3528 (let ((data (get-text-property (point) 'gnus-data)))
3529 (mm-pipe-part data)))
3531 (defun gnus-mime-view-part ()
3532 "Interactively choose a viewing method for the MIME part under point."
3534 (gnus-article-check-buffer)
3535 (let ((data (get-text-property (point) 'gnus-data)))
3536 (mm-interactively-view-part data)))
3538 (defun gnus-mime-view-part-as-type-internal ()
3539 (gnus-article-check-buffer)
3540 (let* ((name (mail-content-type-get
3541 (mm-handle-type (get-text-property (point) 'gnus-data))
3543 (def-type (and name (mm-default-file-encoding name))))
3544 (and def-type (cons def-type 0))))
3546 (defun gnus-mime-view-part-as-type (mime-type)
3547 "Choose a MIME media type, and view the part as such."
3549 (list (completing-read
3550 "View as MIME type: "
3551 (mapcar #'list (mailcap-mime-types))
3553 (gnus-mime-view-part-as-type-internal))))
3554 (gnus-article-check-buffer)
3555 (let ((handle (get-text-property (point) 'gnus-data)))
3556 (gnus-mm-display-part
3557 (mm-make-handle (mm-handle-buffer handle)
3558 (cons mime-type (cdr (mm-handle-type handle)))
3559 (mm-handle-encoding handle)
3560 (mm-handle-undisplayer handle)
3561 (mm-handle-disposition handle)
3562 (mm-handle-description handle)
3563 (mm-handle-cache handle)
3564 (mm-handle-id handle)))))
3566 (defun gnus-mime-copy-part (&optional handle)
3567 "Put the the MIME part under point into a new buffer."
3569 (gnus-article-check-buffer)
3570 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3571 (contents (mm-get-part handle))|
3572 (base (file-name-nondirectory
3574 (mail-content-type-get (mm-handle-type handle) 'name)
3575 (mail-content-type-get (mm-handle-type handle)
3578 (buffer (generate-new-buffer base)))
3579 (switch-to-buffer buffer)
3581 ;; We do it this way to make `normal-mode' set the appropriate mode.
3584 (setq buffer-file-name (expand-file-name base))
3586 (setq buffer-file-name nil))
3587 (goto-char (point-min))))
3589 (defun gnus-mime-inline-part (&optional handle arg)
3590 "Insert the MIME part under point into the current buffer."
3591 (interactive (list nil current-prefix-arg))
3592 (gnus-article-check-buffer)
3593 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3597 (if (and (not arg) (mm-handle-undisplayer handle))
3598 (mm-remove-part handle)
3599 (setq contents (mm-get-part handle))
3602 (setq charset (or (mail-content-type-get
3603 (mm-handle-type handle) 'charset)
3604 gnus-newsgroup-charset)))
3606 (if (mm-handle-undisplayer handle)
3607 (mm-remove-part handle))
3610 gnus-summary-show-article-charset-alist))
3611 (read-coding-system "Charset: ")))))
3613 (mm-insert-inline handle
3615 (setq charset (mm-charset-to-coding-system
3617 (not (eq charset 'ascii)))
3618 (mm-decode-coding-string contents charset)
3622 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3623 "Insert the MIME part under point into the current buffer."
3624 (interactive (list nil current-prefix-arg))
3625 (gnus-article-check-buffer)
3626 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3630 (if (mm-handle-undisplayer handle)
3631 (mm-remove-part handle))
3632 (let ((gnus-newsgroup-charset
3634 gnus-summary-show-article-charset-alist))
3635 (read-coding-system "Charset: ")))
3636 (gnus-newsgroup-ignored-charsets 'gnus-all))
3637 (gnus-article-press-button))))
3639 (defun gnus-mime-externalize-part (&optional handle)
3640 "View the MIME part under point with an external viewer."
3642 (gnus-article-check-buffer)
3643 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3644 (mm-user-display-methods nil)
3645 (mm-inlined-types nil)
3646 (mail-parse-charset gnus-newsgroup-charset)
3647 (mail-parse-ignored-charsets
3648 (save-excursion (set-buffer gnus-summary-buffer)
3649 gnus-newsgroup-ignored-charsets)))
3650 (if (mm-handle-undisplayer handle)
3651 (mm-remove-part handle)
3652 (mm-display-part handle))))
3654 (defun gnus-mime-internalize-part (&optional handle)
3655 "View the MIME part under point with an internal viewer.
3656 In no internal viewer is available, use an external viewer."
3658 (gnus-article-check-buffer)
3659 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3660 (mm-inlined-types '(".*"))
3661 (mm-inline-large-images t)
3662 (mail-parse-charset gnus-newsgroup-charset)
3663 (mail-parse-ignored-charsets
3664 (save-excursion (set-buffer gnus-summary-buffer)
3665 gnus-newsgroup-ignored-charsets)))
3666 (if (mm-handle-undisplayer handle)
3667 (mm-remove-part handle)
3668 (mm-display-part handle))))
3670 (defun gnus-mime-action-on-part (&optional action)
3671 "Do something with the MIME attachment at \(point\)."
3673 (list (completing-read "Action: " gnus-mime-action-alist)))
3674 (gnus-article-check-buffer)
3675 (let ((action-pair (assoc action gnus-mime-action-alist)))
3677 (funcall (cdr action-pair)))))
3680 (defun gnus-article-part-wrapper (n function)
3681 (save-current-buffer
3682 (set-buffer gnus-article-buffer)
3683 (when (> n (length gnus-article-mime-handle-alist))
3684 (error "No such part"))
3685 (gnus-article-goto-part n)
3686 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3687 (funcall function handle))))
3689 (defun gnus-article-pipe-part (n)
3690 "Pipe MIME part N, which is the numerical prefix."
3692 (gnus-article-part-wrapper n 'mm-pipe-part))
3694 (defun gnus-article-save-part (n)
3695 "Save MIME part N, which is the numerical prefix."
3697 (gnus-article-part-wrapper n 'mm-save-part))
3699 (defun gnus-article-interactively-view-part (n)
3700 "View MIME part N interactively, which is the numerical prefix."
3702 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3704 (defun gnus-article-copy-part (n)
3705 "Copy MIME part N, which is the numerical prefix."
3707 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3709 (defun gnus-article-view-part-as-charset (n)
3710 "Copy MIME part N, which is the numerical prefix."
3712 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3714 (defun gnus-article-externalize-part (n)
3715 "View MIME part N externally, which is the numerical prefix."
3717 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3719 (defun gnus-article-inline-part (n)
3720 "Inline MIME part N, which is the numerical prefix."
3722 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3724 (defun gnus-article-mime-match-handle-first (condition)
3726 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3727 (while (setq ihandle (pop alist))
3729 ((functionp condition)
3730 (funcall condition (cdr ihandle)))
3731 ((eq condition 'undisplayed)
3732 (not (or (mm-handle-undisplayer (cdr ihandle))
3733 (equal (mm-handle-media-type (cdr ihandle))
3734 "multipart/alternative"))))
3735 ((eq condition 'undisplayed-alternative)
3736 (not (mm-handle-undisplayer (cdr ihandle))))
3738 (gnus-article-goto-part (car ihandle))
3739 (or (not n) (< (car ihandle) n)))
3740 (setq n (car ihandle))))
3744 (defun gnus-article-view-part (&optional n)
3745 "View MIME part N, which is the numerical prefix."
3747 (save-current-buffer
3748 (set-buffer gnus-article-buffer)
3749 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3750 gnus-article-mime-match-handle-function)))
3751 (when (> n (length gnus-article-mime-handle-alist))
3752 (error "No such part"))
3753 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3754 (when (gnus-article-goto-part n)
3755 (if (equal (car handle) "multipart/alternative")
3756 (gnus-article-press-button)
3757 (when (eq (gnus-mm-display-part handle) 'internal)
3758 (gnus-set-window-start)))))))
3760 (defsubst gnus-article-mime-total-parts ()
3761 (if (bufferp (car gnus-article-mime-handles))
3763 (1- (length gnus-article-mime-handles))))
3765 (defun gnus-mm-display-part (handle)
3766 "Display HANDLE and fix MIME button."
3767 (let ((id (get-text-property (point) 'gnus-part))
3772 (let ((window (selected-window))
3773 (mail-parse-charset gnus-newsgroup-charset)
3774 (mail-parse-ignored-charsets
3775 (save-excursion (set-buffer gnus-summary-buffer)
3776 gnus-newsgroup-ignored-charsets)))
3779 (let ((win (get-buffer-window (current-buffer) t))
3782 (select-window win))
3785 (if (mm-handle-displayed-p handle)
3786 ;; This will remove the part.
3787 (mm-display-part handle)
3789 (narrow-to-region (point) (1+ (point)))
3790 (mm-display-part handle)
3791 ;; We narrow to the part itself and
3792 ;; then call the treatment functions.
3793 (goto-char (point-min))
3795 (narrow-to-region (point) (point-max))
3798 (gnus-article-mime-total-parts)
3799 (mm-handle-media-type handle)))))
3800 (select-window window))))
3802 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3803 (gnus-insert-mime-button
3804 handle id (list (mm-handle-displayed-p handle)))
3805 (goto-char point))))
3807 (defun gnus-article-goto-part (n)
3808 "Go to MIME part N."
3809 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3811 (goto-char point))))
3813 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3814 (let ((gnus-tmp-name
3815 (or (mail-content-type-get (mm-handle-type handle)
3817 (mail-content-type-get (mm-handle-disposition handle)
3819 (mail-content-type-get (mm-handle-type handle)
3822 (gnus-tmp-type (mm-handle-media-type handle))
3823 (gnus-tmp-description
3824 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3827 (if (if displayed (car displayed)
3828 (mm-handle-displayed-p handle))
3830 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3832 gnus-tmp-type-long b e)
3833 (when (string-match ".*/" gnus-tmp-name)
3834 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3835 (setq gnus-tmp-type-long (concat gnus-tmp-type
3836 (and (not (equal gnus-tmp-name ""))
3837 (concat "; " gnus-tmp-name))))
3838 (or (equal gnus-tmp-description "")
3839 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3844 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3845 `(local-map ,gnus-mime-button-map
3846 keymap ,gnus-mime-button-map
3847 gnus-callback gnus-mm-display-part
3848 gnus-part ,gnus-tmp-id
3849 article-type annotation
3852 (widget-convert-button
3855 :action 'gnus-widget-press-button
3856 :button-keymap gnus-mime-button-map
3858 (lambda (widget/window &optional overlay pos)
3859 ;; Needed to properly clear the message due to a bug in
3860 ;; wid-edit (XEmacs only).
3861 (if (boundp 'help-echo-owns-message)
3862 (setq help-echo-owns-message t))
3864 "%S: %s the MIME part; %S: more options"
3865 (aref gnus-mouse-2 0)
3866 ;; XEmacs will get a single widget arg; Emacs 21 will get
3867 ;; window, overlay, position.
3868 (if (mm-handle-displayed-p
3870 (with-current-buffer (gnus-overlay-buffer overlay)
3871 (widget-get (widget-at (gnus-overlay-start overlay))
3873 (widget-get widget/window :mime-handle)))
3875 (aref gnus-down-mouse-3 0))))))
3877 (defun gnus-widget-press-button (elems el)
3878 (goto-char (widget-get elems :from))
3879 (gnus-article-press-button))
3881 (defvar gnus-displaying-mime nil)
3883 (defun gnus-display-mime (&optional ihandles)
3884 "Display the MIME parts."
3886 (save-selected-window
3887 (let ((window (get-buffer-window gnus-article-buffer))
3890 (select-window window)
3891 ;; We have to do this since selecting the window
3892 ;; may change the point. So we set the window point.
3893 (set-window-point window point)))
3894 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3895 buffer-read-only handle name type b e display)
3896 (when (and (not ihandles)
3897 (not gnus-displaying-mime))
3898 ;; Top-level call; we clean up.
3899 (when gnus-article-mime-handles
3900 (mm-destroy-parts gnus-article-mime-handles)
3901 (setq gnus-article-mime-handle-alist nil));; A trick.
3902 (setq gnus-article-mime-handles handles)
3903 ;; We allow users to glean info from the handles.
3904 (when gnus-article-mime-part-function
3905 (gnus-mime-part-function handles)))
3907 (or (not (stringp (car handles)))
3910 (when (and (not ihandles)
3911 (not gnus-displaying-mime))
3912 ;; Clean up for mime parts.
3914 (delete-region (point) (point-max)))
3915 (let ((gnus-displaying-mime t))
3916 (gnus-mime-display-part handles)))
3919 (narrow-to-region (point) (point-max))
3920 (gnus-treat-article nil 1 1)
3923 ;; Highlight the headers.
3927 (narrow-to-region (point-min) (point))
3928 (gnus-treat-article 'head))))))))
3930 (defvar gnus-mime-display-multipart-as-mixed nil)
3932 (defun gnus-mime-display-part (handle)
3935 ((not (stringp (car handle)))
3936 (gnus-mime-display-single handle))
3937 ;; User-defined multipart
3938 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3939 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3941 ;; multipart/alternative
3942 ((and (equal (car handle) "multipart/alternative")
3943 (not gnus-mime-display-multipart-as-mixed))
3944 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3945 (push (cons id handle) gnus-article-mime-handle-alist)
3946 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3947 ;; multipart/related
3948 ((and (equal (car handle) "multipart/related")
3949 (not gnus-mime-display-multipart-as-mixed))
3950 ;;;!!!We should find the start part, but we just default
3951 ;;;!!!to the first part.
3952 ;;(gnus-mime-display-part (cadr handle))
3953 ;;;!!! Most multipart/related is an HTML message plus images.
3954 ;;;!!! Unfortunately we are unable to let W3 display those
3955 ;;;!!! included images, so we just display it as a mixed multipart.
3956 (gnus-mime-display-mixed (cdr handle)))
3957 ((equal (car handle) "multipart/signed")
3958 (or (memq 'signed gnus-article-wash-types)
3959 (push 'signed gnus-article-wash-types))
3960 (gnus-mime-display-security handle))
3961 ((equal (car handle) "multipart/encrypted")
3962 (or (memq 'encrypted gnus-article-wash-types)
3963 (push 'encrypted gnus-article-wash-types))
3964 (gnus-mime-display-security handle))
3965 ;; Other multiparts are handled like multipart/mixed.
3967 (gnus-mime-display-mixed (cdr handle)))))
3969 (defun gnus-mime-part-function (handles)
3970 (if (stringp (car handles))
3971 (mapcar 'gnus-mime-part-function (cdr handles))
3972 (funcall gnus-article-mime-part-function handles)))
3974 (defun gnus-mime-display-mixed (handles)
3975 (mapcar 'gnus-mime-display-part handles))
3977 (defun gnus-mime-display-single (handle)
3978 (let ((type (mm-handle-media-type handle))
3979 (ignored gnus-ignored-mime-types)
3986 (when (string-match (pop ignored) type)
3987 (throw 'ignored nil)))
3988 (if (and (setq not-attachment
3989 (and (not (mm-inline-override-p handle))
3990 (or (not (mm-handle-disposition handle))
3991 (equal (car (mm-handle-disposition handle))
3993 (mm-attachment-override-p handle))))
3994 (mm-automatic-display-p handle)
3995 (or (mm-inlined-p handle)
3996 (mm-automatic-external-display-p type)))
3998 (when (equal (mm-handle-media-supertype handle) "text")
4000 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4002 (push (cons id handle) gnus-article-mime-handle-alist)
4003 (when (or (not display)
4004 (not (gnus-unbuttonized-mime-type-p type)))
4005 ;(gnus-article-insert-newline)
4006 (gnus-insert-mime-button
4007 handle id (list (or display (and not-attachment text))))
4008 (gnus-article-insert-newline)
4009 ;(gnus-article-insert-newline)
4010 ;; Remember modify the number of forward lines.
4018 (let ((mail-parse-charset gnus-newsgroup-charset)
4019 (mail-parse-ignored-charsets
4020 (save-excursion (condition-case ()
4021 (set-buffer gnus-summary-buffer)
4023 gnus-newsgroup-ignored-charsets)))
4024 (mm-display-part handle t))
4025 (goto-char (point-max)))
4026 ((and text not-attachment)
4030 (gnus-article-insert-newline)
4031 (mm-insert-inline handle (mm-get-part handle))
4032 (goto-char (point-max))))
4036 (narrow-to-region beg (point))
4039 (gnus-article-mime-total-parts)
4040 (mm-handle-media-type handle)))))))))
4042 (defun gnus-unbuttonized-mime-type-p (type)
4043 "Say whether TYPE is to be unbuttonized."
4044 (unless gnus-inhibit-mime-unbuttonizing
4046 (let ((types gnus-unbuttonized-mime-types))
4048 (when (string-match (pop types) type)
4049 (throw 'found t)))))))
4051 (defun gnus-article-insert-newline ()
4052 "Insert a newline, but mark it as undeletable."
4053 (gnus-put-text-property
4054 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4056 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4057 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4060 handle buffer-read-only from props begend not-pref)
4061 (save-window-excursion
4064 (narrow-to-region (car ibegend)
4067 (goto-char (car ibegend))
4070 (delete-region (point-min) (point-max))
4071 (mm-remove-parts handles))
4072 (setq begend (list (point-marker)))
4074 (unless (setq not-pref (cadr (member preferred ihandles)))
4075 (setq not-pref (car ihandles)))
4078 (not (gnus-unbuttonized-mime-type-p
4079 "multipart/alternative")))
4080 (gnus-add-text-properties
4083 (insert (format "%d. " id))
4087 (unless ,(not ibegend)
4088 (setq gnus-article-mime-handle-alist
4089 ',gnus-article-mime-handle-alist))
4090 (gnus-mime-display-alternative
4091 ',ihandles ',not-pref ',begend ,id))
4092 local-map ,gnus-mime-button-map
4093 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4094 face ,gnus-article-button-face
4095 keymap ,gnus-mime-button-map
4098 (widget-convert-button 'link from (point)
4099 :action 'gnus-widget-press-button
4100 :button-keymap gnus-widget-button-keymap)
4102 (while (setq handle (pop handles))
4103 (gnus-add-text-properties
4106 (insert (format "(%c) %-18s"
4107 (if (equal handle preferred) ?* ? )
4108 (mm-handle-media-type handle)))
4112 (unless ,(not ibegend)
4113 (setq gnus-article-mime-handle-alist
4114 ',gnus-article-mime-handle-alist))
4115 (gnus-mime-display-alternative
4116 ',ihandles ',handle ',begend ,id))
4117 local-map ,gnus-mime-button-map
4118 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4119 face ,gnus-article-button-face
4120 keymap ,gnus-mime-button-map
4123 (widget-convert-button 'link from (point)
4124 :action 'gnus-widget-press-button
4125 :button-keymap gnus-widget-button-keymap)
4129 (if (stringp (car preferred))
4130 (gnus-display-mime preferred)
4131 (let ((mail-parse-charset gnus-newsgroup-charset)
4132 (mail-parse-ignored-charsets
4133 (save-excursion (set-buffer gnus-summary-buffer)
4134 gnus-newsgroup-ignored-charsets)))
4135 (mm-display-part preferred)
4139 (narrow-to-region (car begend) (point-max))
4141 nil (length gnus-article-mime-handle-alist)
4142 (gnus-article-mime-total-parts)
4143 (mm-handle-media-type handle))))))
4144 (goto-char (point-max))
4145 (setcdr begend (point-marker)))))
4147 (goto-char point))))
4149 (defun gnus-article-wash-status ()
4150 "Return a string which display status of article washing."
4152 (set-buffer gnus-article-buffer)
4153 (let ((cite (memq 'cite gnus-article-wash-types))
4154 (headers (memq 'headers gnus-article-wash-types))
4155 (boring (memq 'boring-headers gnus-article-wash-types))
4156 (pgp (memq 'pgp gnus-article-wash-types))
4157 (pem (memq 'pem gnus-article-wash-types))
4158 (signed (memq 'signed gnus-article-wash-types))
4159 (encrypted (memq 'encrypted gnus-article-wash-types))
4160 (signature (memq 'signature gnus-article-wash-types))
4161 (overstrike (memq 'overstrike gnus-article-wash-types))
4162 (emphasis (memq 'emphasis gnus-article-wash-types)))
4163 (format "%c%c%c%c%c%c%c"
4165 (if (or headers boring) ?h ? )
4166 (if (or pgp pem signed encrypted) ?p ? )
4167 (if signature ?s ? )
4168 (if overstrike ?o ? )
4169 (if gnus-show-mime ?m ? )
4170 (if emphasis ?e ? )))))
4172 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4174 (defun gnus-article-maybe-hide-headers ()
4175 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4176 Provided for backwards compatibility."
4177 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4178 (not (save-excursion (set-buffer gnus-summary-buffer)
4179 gnus-have-all-headers)))
4180 (not gnus-inhibit-hiding))
4181 (gnus-article-hide-headers)))
4185 (defun gnus-output-to-file (file-name)
4186 "Append the current article to a file named FILE-NAME."
4187 (let ((artbuf (current-buffer)))
4189 (insert-buffer-substring artbuf)
4190 ;; Append newline at end of the buffer as separator, and then
4192 (goto-char (point-max))
4194 (write-region-as-binary (point-min) (point-max) file-name 'append)
4197 (defun gnus-narrow-to-page (&optional arg)
4198 "Narrow the article buffer to a page.
4199 If given a numerical ARG, move forward ARG pages."
4201 (setq arg (if arg (prefix-numeric-value arg) 0))
4203 (set-buffer gnus-article-buffer)
4204 (goto-char (point-min))
4206 ;; Remove any old next/prev buttons.
4207 (when (gnus-visual-p 'page-marker)
4208 (let ((buffer-read-only nil))
4209 (gnus-remove-text-with-property 'gnus-prev)
4210 (gnus-remove-text-with-property 'gnus-next)))
4213 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4215 (re-search-forward page-delimiter nil 'move arg)))
4216 (goto-char (match-end 0)))
4219 (if (re-search-forward page-delimiter nil 'move)
4222 (when (and (gnus-visual-p 'page-marker)
4223 (not (= (point-min) 1)))
4225 (goto-char (point-min))
4226 (gnus-insert-prev-page-button)))
4227 (when (and (gnus-visual-p 'page-marker)
4228 (< (+ (point-max) 2) (buffer-size)))
4230 (goto-char (point-max))
4231 (gnus-insert-next-page-button)))))
4233 ;; Article mode commands
4235 (defun gnus-article-goto-next-page ()
4236 "Show the next page of the article."
4238 (when (gnus-article-next-page)
4239 (goto-char (point-min))
4240 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4242 (defun gnus-article-goto-prev-page ()
4243 "Show the next page of the article."
4245 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4246 (gnus-article-prev-page nil)))
4248 (defun gnus-article-next-page (&optional lines)
4249 "Show the next page of the current article.
4250 If end of article, return non-nil. Otherwise return nil.
4251 Argument LINES specifies lines to be scrolled up."
4253 (let ((start (window-start))
4254 end-of-buffer end-of-page)
4256 (move-to-window-line -1)
4257 (if (<= (point) start)
4260 (setq start (point)))
4263 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4264 (and (pos-visible-in-window-p)
4265 (setq end-of-buffer t)))
4267 (setq end-of-page t)))
4269 (move-to-window-line lines)
4270 (unless (search-backward "\n\n" nil t)
4271 (setq start (point)))))
4272 (cond (end-of-buffer t)
4274 (gnus-narrow-to-page 1)
4278 (set-window-start (selected-window) start)
4279 (let (window-pixel-scroll-increment)
4283 (defun gnus-article-prev-page (&optional lines)
4284 "Show previous page of current article.
4285 Argument LINES specifies lines to be scrolled down."
4287 (let (beginning-of-buffer beginning-of-page)
4289 (move-to-window-line 0)
4290 (cond ((eq 1 (point))
4291 (setq beginning-of-buffer t))
4293 (setq beginning-of-page t))))
4294 (cond (beginning-of-buffer)
4296 (gnus-narrow-to-page -1))
4299 (let (window-pixel-scroll-increment)
4300 (scroll-down lines))
4301 (beginning-of-buffer
4302 (goto-char (point-min))))))))
4304 (defun gnus-article-refer-article ()
4305 "Read article specified by message-id around point."
4307 (let ((point (point)))
4308 (search-forward ">" nil t) ;Move point to end of "<....>".
4309 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4310 (let ((message-id (match-string 1)))
4312 (set-buffer gnus-summary-buffer)
4313 (gnus-summary-refer-article message-id))
4315 (error "No references around point"))))
4317 (defun gnus-article-show-summary ()
4318 "Reconfigure windows to show summary buffer."
4320 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4321 (error "There is no summary buffer for this article buffer")
4322 (gnus-article-set-globals)
4323 (gnus-configure-windows 'article)
4324 (gnus-summary-goto-subject gnus-current-article)
4325 (gnus-summary-position-point)))
4327 (defun gnus-article-describe-briefly ()
4328 "Describe article mode commands briefly."
4330 (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")))
4332 (defun gnus-article-summary-command ()
4333 "Execute the last keystroke in the summary buffer."
4335 (let ((obuf (current-buffer))
4336 (owin (current-window-configuration))
4338 (switch-to-buffer gnus-article-current-summary 'norecord)
4339 (setq func (lookup-key (current-local-map) (this-command-keys)))
4340 (call-interactively func)
4342 (set-window-configuration owin)
4343 (set-window-point (get-buffer-window (current-buffer)) (point))))
4345 (defun gnus-article-summary-command-nosave ()
4346 "Execute the last keystroke in the summary buffer."
4349 (pop-to-buffer gnus-article-current-summary 'norecord)
4350 (setq func (lookup-key (current-local-map) (this-command-keys)))
4351 (call-interactively func)))
4353 (defun gnus-article-check-buffer ()
4354 "Beep if not in an article buffer."
4355 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4356 (error "Command invoked outside of a Gnus article buffer")))
4358 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4359 "Read a summary buffer key sequence and execute it from the article buffer."
4361 (gnus-article-check-buffer)
4363 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4364 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4365 "=" "^" "\M-^" "|"))
4371 '("n" "Gn" "p" "Gp"))
4374 (set-buffer gnus-article-current-summary)
4375 (let (gnus-pick-mode)
4376 (push (or key last-command-event) unread-command-events)
4377 (setq keys (static-if (featurep 'xemacs)
4378 (events-to-keys (read-key-sequence nil))
4379 (read-key-sequence nil)))))
4382 (if (or (member keys nosaves)
4383 (member keys nosave-but-article)
4384 (member keys nosave-in-article))
4386 (save-window-excursion
4387 (pop-to-buffer gnus-article-current-summary 'norecord)
4388 ;; We disable the pick minor mode commands.
4389 (let (gnus-pick-mode)
4390 (setq func (lookup-key (current-local-map) keys))))
4394 (unless (member keys nosave-in-article)
4395 (set-buffer gnus-article-current-summary))
4396 (call-interactively func)
4397 (setq new-sum-point (point)))
4398 (when (member keys nosave-but-article)
4399 (pop-to-buffer gnus-article-buffer 'norecord)))
4400 ;; These commands should restore window configuration.
4401 (let ((obuf (current-buffer))
4402 (owin (current-window-configuration))
4404 (summary gnus-article-current-summary)
4405 func in-buffer selected)
4406 (if not-restore-window
4407 (pop-to-buffer summary 'norecord)
4408 (switch-to-buffer summary 'norecord))
4409 (setq in-buffer (current-buffer))
4410 ;; We disable the pick minor mode commands.
4411 (if (and (setq func (let (gnus-pick-mode)
4412 (lookup-key (current-local-map) keys)))
4415 (call-interactively func)
4416 (setq new-sum-point (point))
4417 (when (eq in-buffer (current-buffer))
4418 (setq selected (gnus-summary-select-article))
4420 (unless not-restore-window
4421 (set-window-configuration owin))
4422 (when (eq selected 'old)
4424 (set-window-start (get-buffer-window (current-buffer))
4426 (set-window-point (get-buffer-window (current-buffer))
4428 (let ((win (get-buffer-window gnus-article-current-summary)))
4430 (set-window-point win new-sum-point)))) )
4431 (switch-to-buffer gnus-article-buffer)
4434 (defun gnus-article-describe-key (key)
4435 "Display documentation of the function invoked by KEY. KEY is a string."
4436 (interactive "kDescribe key: ")
4437 (gnus-article-check-buffer)
4438 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4440 (set-buffer gnus-article-current-summary)
4441 (let (gnus-pick-mode)
4442 (push (elt key 0) unread-command-events)
4443 (setq key (if (featurep 'xemacs)
4444 (events-to-keys (read-key-sequence "Describe key: "))
4445 (read-key-sequence "Describe key: "))))
4447 (describe-key key)))
4449 (defun gnus-article-describe-key-briefly (key &optional insert)
4450 "Display documentation of the function invoked by KEY. KEY is a string."
4451 (interactive "kDescribe key: \nP")
4452 (gnus-article-check-buffer)
4453 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4455 (set-buffer gnus-article-current-summary)
4456 (let (gnus-pick-mode)
4457 (push (elt key 0) unread-command-events)
4458 (setq key (if (featurep 'xemacs)
4459 (events-to-keys (read-key-sequence "Describe key: "))
4460 (read-key-sequence "Describe key: "))))
4461 (describe-key-briefly key insert))
4462 (describe-key-briefly key insert)))
4464 (defun gnus-article-hide (&optional arg force)
4465 "Hide all the gruft in the current article.
4466 This means that PGP stuff, signatures, cited text and (some)
4467 headers will be hidden.
4468 If given a prefix, show the hidden text instead."
4469 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4470 (gnus-article-hide-headers arg)
4471 (gnus-article-hide-list-identifiers arg)
4472 (gnus-article-hide-pgp arg)
4473 (gnus-article-hide-citation-maybe arg force)
4474 (gnus-article-hide-signature arg))
4476 (defun gnus-article-maybe-highlight ()
4477 "Do some article highlighting if article highlighting is requested."
4478 (when (gnus-visual-p 'article-highlight 'highlight)
4479 (gnus-article-highlight-some)))
4481 (defun gnus-check-group-server ()
4482 ;; Make sure the connection to the server is alive.
4483 (unless (gnus-server-opened
4484 (gnus-find-method-for-group gnus-newsgroup-name))
4485 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4486 (gnus-request-group gnus-newsgroup-name t)))
4488 (defun gnus-request-article-this-buffer (article group)
4489 "Get an article and insert it into this buffer."
4490 (let (do-update-line sparse-header)
4494 (gnus-kill-all-overlays)
4495 (setq group (or group gnus-newsgroup-name))
4497 ;; Using `gnus-request-article' directly will insert the article into
4498 ;; `nntp-server-buffer' - so we'll save some time by not having to
4499 ;; copy it from the server buffer into the article buffer.
4501 ;; We only request an article by message-id when we do not have the
4502 ;; headers for it, so we'll have to get those.
4503 (when (stringp article)
4504 (gnus-read-header article))
4506 ;; If the article number is negative, that means that this article
4507 ;; doesn't belong in this newsgroup (possibly), so we find its
4508 ;; message-id and request it by id instead of number.
4509 (when (and (numberp article)
4511 (get-buffer gnus-summary-buffer)
4512 (gnus-buffer-exists-p gnus-summary-buffer))
4514 (set-buffer gnus-summary-buffer)
4515 (let ((header (gnus-summary-article-header article)))
4518 ((memq article gnus-newsgroup-sparse)
4519 ;; This is a sparse gap article.
4520 (setq do-update-line article)
4521 (setq article (mail-header-id header))
4522 (setq sparse-header (gnus-read-header article))
4523 (setq gnus-newsgroup-sparse
4524 (delq article gnus-newsgroup-sparse)))
4526 ;; It's a real article.
4527 (setq article (mail-header-id header)))
4529 ;; It is an extracted pseudo-article.
4530 (setq article 'pseudo)
4531 (gnus-request-pseudo-article header))))
4533 (let ((method (gnus-find-method-for-group
4534 gnus-newsgroup-name)))
4535 (when (and (eq (car method) 'nneething)
4537 (let ((dir (expand-file-name
4538 (mail-header-subject header)
4539 (file-name-as-directory
4540 (or (cadr (assq 'nneething-address method))
4542 (when (file-directory-p dir)
4543 (setq article 'nneething)
4544 (gnus-group-enter-directory dir))))))))
4547 ;; Refuse to select canceled articles.
4548 ((and (numberp article)
4550 (get-buffer gnus-summary-buffer)
4551 (gnus-buffer-exists-p gnus-summary-buffer)
4552 (eq (cdr (save-excursion
4553 (set-buffer gnus-summary-buffer)
4554 (assq article gnus-newsgroup-reads)))
4555 gnus-canceled-mark))
4557 ;; Check the backlog.
4558 ((and gnus-keep-backlog
4559 (gnus-backlog-request-article group article (current-buffer)))
4561 ;; Check asynchronous pre-fetch.
4562 ((gnus-async-request-fetched-article group article (current-buffer))
4563 (gnus-async-prefetch-next group article gnus-summary-buffer)
4564 (when (and (numberp article) gnus-keep-backlog)
4565 (gnus-backlog-enter-article group article (current-buffer)))
4568 ((and gnus-use-cache
4570 (gnus-cache-request-article article group))
4572 ;; Get the article and put into the article buffer.
4573 ((or (stringp article)
4575 (let ((gnus-override-method gnus-override-method)
4576 (methods (and (stringp article)
4577 gnus-refer-article-method))
4579 (buffer-read-only nil))
4580 (if (or (not (listp methods))
4581 (and (symbolp (car methods))
4582 (assq (car methods) nnoo-definition-alist)))
4583 (setq methods (list methods)))
4584 (when (and (null gnus-override-method)
4586 (setq gnus-override-method (pop methods)))
4588 (when (eq gnus-override-method 'current)
4589 (setq gnus-override-method gnus-current-select-method))
4591 (gnus-kill-all-overlays)
4592 (let ((gnus-newsgroup-name group))
4593 (gnus-check-group-server))
4594 (when (gnus-request-article article group (current-buffer))
4595 (when (numberp article)
4596 (gnus-async-prefetch-next group article
4597 gnus-summary-buffer)
4598 (when gnus-keep-backlog
4599 (gnus-backlog-enter-article
4600 group article (current-buffer))))
4601 (setq result 'article))
4604 (setq gnus-override-method (pop methods))
4605 (setq result 'done))))
4606 (and (eq result 'article) 'article)))
4610 ;; Associate this article with the current summary buffer.
4611 (setq gnus-article-current-summary gnus-summary-buffer)
4613 ;; Take the article from the original article buffer
4614 ;; and place it in the buffer it's supposed to be in.
4615 (when (and (get-buffer gnus-article-buffer)
4616 (equal (buffer-name (current-buffer))
4617 (buffer-name (get-buffer gnus-article-buffer))))
4619 (if (get-buffer gnus-original-article-buffer)
4620 (set-buffer gnus-original-article-buffer)
4621 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4622 (set-buffer-multibyte nil)
4623 (buffer-disable-undo)
4624 (setq major-mode 'gnus-original-article-mode)
4625 (setq buffer-read-only t))
4626 (let (buffer-read-only)
4628 (insert-buffer-substring gnus-article-buffer))
4629 (setq gnus-original-article (cons group article)))
4632 (run-hooks 'gnus-article-decode-hook)
4633 ;; Mark article as decoded or not.
4634 (setq gnus-article-decoded-p gnus-article-decode-hook))
4636 ;; Update sparse articles.
4637 (when (and do-update-line
4638 (or (numberp article)
4640 (let ((buf (current-buffer)))
4641 (set-buffer gnus-summary-buffer)
4642 (gnus-summary-update-article do-update-line sparse-header)
4643 (gnus-summary-goto-subject do-update-line nil t)
4644 (set-window-point (get-buffer-window (current-buffer) t)
4646 (set-buffer buf))))))
4652 (defcustom gnus-article-edit-mode-hook nil
4653 "Hook run in article edit mode buffers."
4654 :group 'gnus-article-various
4657 (defcustom gnus-article-edit-article-setup-function
4658 'gnus-article-mime-edit-article-setup
4659 "Function called to setup an editing article buffer."
4660 :group 'gnus-article-various
4663 (defvar gnus-article-edit-done-function nil)
4665 (defvar gnus-article-edit-mode-map nil)
4667 ;; Should we be using derived.el for this?
4668 (unless gnus-article-edit-mode-map
4669 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4670 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4672 (gnus-define-keys gnus-article-edit-mode-map
4673 "\C-c\C-c" gnus-article-edit-done
4674 "\C-c\C-k" gnus-article-edit-exit)
4676 (gnus-define-keys (gnus-article-edit-wash-map
4677 "\C-c\C-w" gnus-article-edit-mode-map)
4678 "f" gnus-article-edit-full-stops))
4680 (defun gnus-article-edit-mode ()
4681 "Major mode for editing articles.
4682 This is an extended text-mode.
4684 \\{gnus-article-edit-mode-map}"
4686 (setq major-mode 'gnus-article-edit-mode)
4687 (setq mode-name "Article Edit")
4688 (use-local-map gnus-article-edit-mode-map)
4689 (make-local-variable 'gnus-article-edit-done-function)
4690 (make-local-variable 'gnus-prev-winconf)
4691 (setq buffer-read-only nil)
4692 (buffer-enable-undo)
4694 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4696 (defun gnus-article-edit (&optional force)
4697 "Edit the current article.
4698 This will have permanent effect only in mail groups.
4699 If FORCE is non-nil, allow editing of articles even in read-only
4702 (when (and (not force)
4703 (gnus-group-read-only-p))
4704 (error "The current newsgroup does not support article editing"))
4705 (gnus-article-date-original)
4706 (gnus-article-edit-article
4708 `(lambda (no-highlight)
4710 (gnus-summary-edit-article-done
4711 ,(or (mail-header-references gnus-current-headers) "")
4712 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4714 (defun gnus-article-edit-article (start-func exit-func)
4715 "Start editing the contents of the current article buffer."
4716 (let ((winconf (current-window-configuration)))
4717 (set-buffer gnus-article-buffer)
4718 (gnus-article-edit-mode)
4719 (funcall start-func)
4720 (gnus-configure-windows 'edit-article)
4721 (setq gnus-article-edit-done-function exit-func)
4722 (setq gnus-prev-winconf winconf)
4723 (when gnus-article-edit-article-setup-function
4724 (funcall gnus-article-edit-article-setup-function))
4725 (gnus-message 6 "C-c C-c to end edits")))
4727 (defun gnus-article-edit-done (&optional arg)
4728 "Update the article edits and exit."
4730 (let ((func gnus-article-edit-done-function)
4731 (buf (current-buffer))
4732 (start (window-start)))
4733 (remove-hook 'gnus-article-mode-hook
4734 'gnus-article-mime-edit-article-unwind)
4735 (gnus-article-edit-exit)
4738 (let ((buffer-read-only nil))
4740 ;; The cache and backlog have to be flushed somewhat.
4741 (when gnus-keep-backlog
4742 (gnus-backlog-remove-article
4743 (car gnus-article-current) (cdr gnus-article-current)))
4744 ;; Flush original article as well.
4746 (when (get-buffer gnus-original-article-buffer)
4747 (set-buffer gnus-original-article-buffer)
4748 (setq gnus-original-article nil)))
4749 (when gnus-use-cache
4750 (gnus-cache-update-article
4751 (car gnus-article-current) (cdr gnus-article-current))))
4753 (set-window-start (get-buffer-window buf) start)
4754 (set-window-point (get-buffer-window buf) (point))))
4756 (defun gnus-article-edit-exit ()
4757 "Exit the article editing without updating."
4759 ;; We remove all text props from the article buffer.
4760 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4761 (curbuf (current-buffer))
4763 (window-start (window-start)))
4766 (let ((winconf gnus-prev-winconf))
4768 (set-window-configuration winconf)
4769 ;; Tippy-toe some to make sure that point remains where it was.
4770 (save-current-buffer
4772 (set-window-start (get-buffer-window (current-buffer)) window-start)
4775 (defun gnus-article-edit-full-stops ()
4776 "Interactively repair spacing at end of sentences."
4779 (goto-char (point-min))
4780 (search-forward-regexp "^$" nil t)
4781 (let ((case-fold-search nil))
4782 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4785 ;;; Article editing with MIME-Edit
4788 (defcustom gnus-article-mime-edit-article-setup-hook nil
4789 "Hook run after setting up a MIME editing article buffer."
4790 :group 'gnus-article-various
4793 (defun gnus-article-mime-edit-article-unwind ()
4794 "Unwind `gnus-article-buffer' if article editing was given up."
4795 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4796 (when mime-edit-mode-flag
4797 (mime-edit-exit 'nomime 'no-error)
4799 (when (featurep 'font-lock)
4800 (setq font-lock-defaults nil)
4801 (font-lock-mode 0)))
4803 (defun gnus-article-mime-edit-article-setup ()
4804 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4805 after replacing with the original article."
4806 (setq gnus-show-mime t)
4807 (setq gnus-article-edit-done-function
4808 `(lambda (&rest args)
4809 (when mime-edit-mode-flag
4812 (goto-char (point-min))
4813 (let (case-fold-search)
4814 (when (re-search-forward
4815 (format "^%s$" (regexp-quote mail-header-separator))
4817 (replace-match "")))
4818 (when (featurep 'font-lock)
4819 (setq font-lock-defaults nil)
4821 (apply ,gnus-article-edit-done-function args)
4822 (set-buffer gnus-original-article-buffer)
4824 (insert-buffer gnus-article-buffer)
4825 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4826 (gnus-article-prepare-display)))
4827 (substitute-key-definition
4828 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4829 gnus-article-edit-mode-map)
4831 (insert-buffer gnus-original-article-buffer)
4833 (when (featurep 'font-lock)
4834 (set (make-local-variable 'font-lock-defaults)
4835 '(message-font-lock-keywords t))
4836 (font-lock-set-defaults)
4837 (turn-on-font-lock))
4838 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4839 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4841 (defun gnus-article-mime-edit-exit ()
4842 "Exit the article MIME editing without updating."
4844 (let ((winconf gnus-prev-winconf)
4846 (when mime-edit-mode-flag
4849 (goto-char (point-min))
4850 (let (case-fold-search)
4851 (when (re-search-forward
4852 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4853 (replace-match "")))
4854 (when (featurep 'font-lock)
4855 (setq font-lock-defaults nil)
4857 ;; We remove all text props from the article buffer.
4858 (setq buf (format "%s" (buffer-string)))
4859 (set-buffer (get-buffer-create gnus-original-article-buffer))
4862 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4863 (gnus-article-prepare-display)
4864 (set-window-configuration winconf)))
4867 ;;; Article highlights
4870 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4872 ;;; Internal Variables:
4874 (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\\)\\)"
4875 "Regular expression that matches URLs."
4876 :group 'gnus-article-buttons
4879 (defcustom gnus-button-alist
4880 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4881 0 t gnus-button-message-id 2)
4882 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4883 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4885 gnus-button-fetch-group 4)
4886 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4887 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4888 t gnus-button-message-id 3)
4889 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4890 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4891 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4892 ;; This is how URLs _should_ be embedded in text...
4893 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4895 (,gnus-button-url-regexp 0 t browse-url 0))
4896 "*Alist of regexps matching buttons in article bodies.
4898 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4899 REGEXP: is the string matching text around the button,
4900 BUTTON: is the number of the regexp grouping actually matching the button,
4901 FORM: is a lisp expression which must eval to true for the button to
4903 CALLBACK: is the function to call when the user push this button, and each
4904 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4906 CALLBACK can also be a variable, in that case the value of that
4907 variable it the real callback function."
4908 :group 'gnus-article-buttons
4909 :type '(repeat (list regexp
4910 (integer :tag "Button")
4912 (function :tag "Callback")
4915 (integer :tag "Regexp group")))))
4917 (defcustom gnus-header-button-alist
4918 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4919 0 t gnus-button-message-id 0)
4920 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4921 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4922 0 t gnus-button-mailto 0)
4923 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4924 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4925 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4926 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4927 gnus-button-message-id 3))
4928 "*Alist of headers and regexps to match buttons in article heads.
4930 This alist is very similar to `gnus-button-alist', except that each
4931 alist has an additional HEADER element first in each entry:
4933 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4935 HEADER is a regexp to match a header. For a fuller explanation, see
4936 `gnus-button-alist'."
4937 :group 'gnus-article-buttons
4938 :group 'gnus-article-headers
4939 :type '(repeat (list (regexp :tag "Header")
4941 (integer :tag "Button")
4943 (function :tag "Callback")
4946 (integer :tag "Regexp group")))))
4948 (defvar gnus-button-regexp nil)
4949 (defvar gnus-button-marker-list nil)
4950 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4952 (defvar gnus-button-last nil)
4953 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4957 (defun gnus-article-push-button (event)
4958 "Check text under the mouse pointer for a callback function.
4959 If the text under the mouse pointer has a `gnus-callback' property,
4960 call it with the value of the `gnus-data' text property."
4962 (set-buffer (window-buffer (posn-window (event-start event))))
4963 (let* ((pos (posn-point (event-start event)))
4964 (data (get-text-property pos 'gnus-data))
4965 (fun (get-text-property pos 'gnus-callback)))
4968 (funcall fun data))))
4970 (defun gnus-article-press-button ()
4971 "Check text at point for a callback function.
4972 If the text at point has a `gnus-callback' property,
4973 call it with the value of the `gnus-data' text property."
4975 (let* ((data (get-text-property (point) 'gnus-data))
4976 (fun (get-text-property (point) 'gnus-callback)))
4978 (funcall fun data))))
4980 (defun gnus-article-prev-button (n)
4981 "Move point to N buttons backward.
4982 If N is negative, move forward instead."
4984 (gnus-article-next-button (- n)))
4986 (defun gnus-article-next-button (n)
4987 "Move point to N buttons forward.
4988 If N is negative, move backward instead."
4990 (let ((function (if (< n 0) 'previous-single-property-change
4991 'next-single-property-change))
4992 (inhibit-point-motion-hooks t)
4994 (limit (if (< n 0) (point-min) (point-max))))
4996 (while (and (not (= limit (point)))
4998 ;; Skip past the current button.
4999 (when (get-text-property (point) 'gnus-callback)
5000 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5001 ;; Go to the next (or previous) button.
5002 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5003 ;; Put point at the start of the button.
5004 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5005 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5006 ;; Skip past intangible buttons.
5007 (when (get-text-property (point) 'intangible)
5011 (gnus-message 5 "No more buttons"))
5014 (defun gnus-article-highlight (&optional force)
5015 "Highlight current article.
5016 This function calls `gnus-article-highlight-headers',
5017 `gnus-article-highlight-citation',
5018 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5019 do the highlighting. See the documentation for those functions."
5020 (interactive (list 'force))
5021 (gnus-article-highlight-headers)
5022 (gnus-article-highlight-citation force)
5023 (gnus-article-highlight-signature)
5024 (gnus-article-add-buttons force)
5025 (gnus-article-add-buttons-to-head))
5027 (defun gnus-article-highlight-some (&optional force)
5028 "Highlight current article.
5029 This function calls `gnus-article-highlight-headers',
5030 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5031 do the highlighting. See the documentation for those functions."
5032 (interactive (list 'force))
5033 (gnus-article-highlight-headers)
5034 (gnus-article-highlight-signature)
5035 (gnus-article-add-buttons))
5037 (defun gnus-article-highlight-headers ()
5038 "Highlight article headers as specified by `gnus-header-face-alist'."
5041 (set-buffer gnus-article-buffer)
5043 (let ((alist gnus-header-face-alist)
5044 (buffer-read-only nil)
5045 (case-fold-search t)
5046 (inhibit-point-motion-hooks t)
5047 entry regexp header-face field-face from hpoints fpoints)
5048 (article-narrow-to-head)
5049 (while (setq entry (pop alist))
5050 (goto-char (point-min))
5051 (setq regexp (concat "^\\("
5052 (if (string-equal "" (nth 0 entry))
5056 header-face (nth 1 entry)
5057 field-face (nth 2 entry))
5058 (while (and (re-search-forward regexp nil t)
5062 (unless (search-forward ":" nil t)
5064 (when (and header-face
5065 (not (memq (point) hpoints)))
5066 (push (point) hpoints)
5067 (gnus-put-text-property from (point) 'face header-face))
5068 (when (and field-face
5069 (not (memq (setq from (point)) fpoints)))
5071 (if (re-search-forward "^[^ \t]" nil t)
5073 (goto-char (point-max)))
5074 (gnus-put-text-property from (point) 'face field-face))))))))
5076 (defun gnus-article-highlight-signature ()
5077 "Highlight the signature in an article.
5078 It does this by highlighting everything after
5079 `gnus-signature-separator' using `gnus-signature-face'."
5081 (when gnus-signature-face
5083 (set-buffer gnus-article-buffer)
5084 (let ((buffer-read-only nil)
5085 (inhibit-point-motion-hooks t))
5087 (when (gnus-article-narrow-to-signature)
5088 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5089 'face gnus-signature-face)))))))
5091 (defun gnus-article-buttonize-signature ()
5092 "Add button to the signature."
5095 (set-buffer gnus-article-buffer)
5096 (let ((buffer-read-only nil)
5097 (inhibit-point-motion-hooks t))
5098 (when (gnus-article-search-signature)
5099 (gnus-article-add-button (match-beginning 0) (match-end 0)
5100 'gnus-signature-toggle
5101 (set-marker (make-marker)
5102 (1+ (match-end 0))))))))
5104 (defun gnus-button-in-region-p (b e prop)
5105 "Say whether PROP exists in the region."
5106 (text-property-not-all b e prop nil))
5108 (defun gnus-article-add-buttons (&optional force)
5109 "Find external references in the article and make buttons of them.
5110 \"External references\" are things like Message-IDs and URLs, as
5111 specified by `gnus-button-alist'."
5112 (interactive (list 'force))
5114 (set-buffer gnus-article-buffer)
5115 (let ((buffer-read-only nil)
5116 (inhibit-point-motion-hooks t)
5117 (case-fold-search t)
5118 (alist gnus-button-alist)
5120 ;; Remove all old markers.
5121 (let (marker entry new-list)
5122 (while (setq marker (pop gnus-button-marker-list))
5123 (if (or (< marker (point-min)) (>= marker (point-max)))
5124 (push marker new-list)
5126 (when (setq entry (gnus-button-entry))
5127 (put-text-property (match-beginning (nth 1 entry))
5128 (match-end (nth 1 entry))
5129 'gnus-callback nil))
5130 (set-marker marker nil)))
5131 (setq gnus-button-marker-list new-list))
5132 ;; We skip the headers.
5135 (while (setq entry (pop alist))
5136 (setq regexp (car entry))
5138 (while (re-search-forward regexp nil t)
5139 (let* ((start (and entry (match-beginning (nth 1 entry))))
5140 (end (and entry (match-end (nth 1 entry))))
5141 (from (match-beginning 0)))
5142 (when (and (or (eq t (nth 2 entry))
5143 (eval (nth 2 entry)))
5144 (not (gnus-button-in-region-p
5145 start end 'gnus-callback)))
5146 ;; That optional form returned non-nil, so we add the
5148 (gnus-article-add-button
5149 start end 'gnus-button-push
5150 (car (push (set-marker (make-marker) from)
5151 gnus-button-marker-list))))))))))
5153 ;; Add buttons to the head of an article.
5154 (defun gnus-article-add-buttons-to-head ()
5155 "Add buttons to the head of the article."
5158 (set-buffer gnus-article-buffer)
5160 (let ((buffer-read-only nil)
5161 (inhibit-point-motion-hooks t)
5162 (case-fold-search t)
5163 (alist gnus-header-button-alist)
5165 (article-narrow-to-head)
5167 ;; Each alist entry.
5168 (setq entry (car alist)
5170 (goto-char (point-min))
5171 (while (re-search-forward (car entry) nil t)
5172 ;; Each header matching the entry.
5173 (setq beg (match-beginning 0))
5174 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5175 (match-beginning 0))
5178 (while (re-search-forward (nth 1 entry) end t)
5179 ;; Each match within a header.
5180 (let* ((entry (cdr entry))
5181 (start (match-beginning (nth 1 entry)))
5182 (end (match-end (nth 1 entry)))
5183 (form (nth 2 entry)))
5184 (goto-char (match-end 0))
5186 (gnus-article-add-button
5187 start end (nth 3 entry)
5188 (buffer-substring (match-beginning (nth 4 entry))
5189 (match-end (nth 4 entry)))))))
5190 (goto-char end)))))))
5192 ;;; External functions:
5194 (defun gnus-article-add-button (from to fun &optional data)
5195 "Create a button between FROM and TO with callback FUN and data DATA."
5196 (when gnus-article-button-face
5197 (gnus-overlay-put (gnus-make-overlay from to)
5198 'face gnus-article-button-face))
5199 (gnus-add-text-properties
5201 (nconc (and gnus-article-mouse-face
5202 (list gnus-mouse-face-prop gnus-article-mouse-face))
5203 (list 'gnus-callback fun)
5204 (and data (list 'gnus-data data))))
5205 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5206 ;; Quote `:button-keymap' for Mule 2.3
5207 ;; but it won't work.
5208 ':button-keymap gnus-widget-button-keymap))
5210 ;;; Internal functions:
5212 (defun gnus-article-set-globals ()
5214 (set-buffer gnus-summary-buffer)
5215 (gnus-set-global-variables)))
5217 (defun gnus-signature-toggle (end)
5219 (set-buffer gnus-article-buffer)
5220 (let ((buffer-read-only nil)
5221 (inhibit-point-motion-hooks t)
5222 (limit (next-single-property-change end 'mime-view-entity
5224 (if (get-text-property end 'invisible)
5225 (gnus-article-unhide-text end limit)
5226 (gnus-article-hide-text end limit gnus-hidden-properties)))))
5228 (defun gnus-button-entry ()
5229 ;; Return the first entry in `gnus-button-alist' matching this place.
5230 (let ((alist gnus-button-alist)
5233 (setq entry (pop alist))
5234 (if (looking-at (car entry))
5239 (defun gnus-button-push (marker)
5240 ;; Push button starting at MARKER.
5243 (let* ((entry (gnus-button-entry))
5244 (inhibit-point-motion-hooks t)
5246 (args (mapcar (lambda (group)
5247 (let ((string (match-string group)))
5248 (gnus-set-text-properties
5249 0 (length string) nil string)
5256 (fboundp (symbol-value fun)))
5257 (apply (symbol-value fun) args))
5259 (gnus-message 1 "You must define `%S' to use this button"
5260 (cons fun args)))))))
5262 (defun gnus-button-message-id (message-id)
5265 (set-buffer gnus-summary-buffer)
5266 (gnus-summary-refer-article message-id)))
5268 (defun gnus-button-fetch-group (address)
5269 "Fetch GROUP specified by ADDRESS."
5270 (if (not (string-match "[:/]" address))
5271 ;; This is just a simple group url.
5272 (gnus-group-read-ephemeral-group address gnus-select-method)
5273 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5275 (error "Can't parse %s" address)
5276 (gnus-group-read-ephemeral-group
5277 (match-string 4 address)
5278 `(nntp ,(match-string 1 address)
5279 (nntp-address ,(match-string 1 address))
5280 (nntp-port-number ,(if (match-end 3)
5281 (match-string 3 address)
5284 (defun gnus-url-parse-query-string (query &optional downcase)
5285 (let (retval pairs cur key val)
5286 (setq pairs (split-string query "&"))
5288 (setq cur (car pairs)
5290 (if (not (string-match "=" cur))
5292 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5293 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5295 (setq key (downcase key)))
5296 (setq cur (assoc key retval))
5298 (setcdr cur (cons val (cdr cur)))
5299 (setq retval (cons (list key val) retval)))))
5302 (defun gnus-url-unhex (x)
5309 (defun gnus-url-unhex-string (str &optional allow-newlines)
5310 "Remove %XXX embedded spaces, etc in a url.
5311 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5312 decoding of carriage returns and line feeds in the string, which is normally
5313 forbidden in URL encoding."
5314 (setq str (or str ""))
5316 (case-fold-search t))
5317 (while (string-match "%[0-9a-f][0-9a-f]" str)
5318 (let* ((start (match-beginning 0))
5319 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5321 (gnus-url-unhex (elt str (+ start 2))))))
5323 tmp (substring str 0 start)
5326 (char-to-string code))
5327 ((or (= code ?\n) (= code ?\r))
5329 (t (char-to-string code))))
5330 str (substring str (match-end 0)))))
5331 (setq tmp (concat tmp str))
5334 (defun gnus-url-mailto (url)
5335 ;; Send mail to someone
5336 (when (string-match "mailto:/*\\(.*\\)" url)
5337 (setq url (substring url (match-beginning 1) nil)))
5338 (let (to args subject func)
5339 (if (string-match (regexp-quote "?") url)
5340 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5341 args (gnus-url-parse-query-string
5342 (substring url (match-end 0) nil) t))
5343 (setq to (gnus-url-unhex-string url)))
5344 (setq args (cons (list "to" to) args)
5345 subject (cdr-safe (assoc "subject" args)))
5346 (gnus-setup-message 'reply
5349 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5352 (message-position-on-field (caar args)))
5353 (insert (mapconcat 'identity (cdar args) ", "))
5354 (setq args (cdr args)))
5357 (message-goto-subject)))))
5359 (defun gnus-button-mailto (address)
5361 (set-buffer (gnus-copy-article-buffer))
5362 (message-reply address))
5364 (defalias 'gnus-button-reply 'message-reply)
5366 (defun gnus-button-embedded-url (address)
5367 "Activate ADDRESS with `browse-url'."
5368 (browse-url (gnus-strip-whitespace address)))
5370 (defun gnus-article-smiley-display ()
5371 "Display \"smileys\" as small graphical icons."
5372 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5374 ;;; Next/prev buttons in the article buffer.
5376 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5377 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5379 (defvar gnus-prev-page-map nil)
5380 (unless gnus-prev-page-map
5381 (setq gnus-prev-page-map (make-sparse-keymap))
5382 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5383 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5385 (static-if (featurep 'xemacs)
5386 (defun gnus-insert-prev-page-button ()
5387 (let ((buffer-read-only nil))
5389 gnus-prev-page-line-format nil
5390 `(gnus-prev t local-map ,gnus-prev-page-map
5391 gnus-callback gnus-article-button-prev-page
5392 article-type annotation))))
5393 (defun gnus-insert-prev-page-button ()
5394 (let ((buffer-read-only nil)
5395 (situation (get-text-property (point-min) 'mime-view-situation)))
5396 (set-keymap-parent gnus-prev-page-map (current-local-map))
5398 gnus-prev-page-line-format nil
5399 `(gnus-prev t local-map ,gnus-prev-page-map
5400 gnus-callback gnus-article-button-prev-page
5401 article-type annotation
5402 mime-view-situation ,situation))))
5405 (defvar gnus-next-page-map nil)
5406 (unless gnus-next-page-map
5407 (setq gnus-next-page-map (make-sparse-keymap))
5408 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5409 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5411 (defun gnus-button-next-page ()
5412 "Go to the next page."
5414 (let ((win (selected-window)))
5415 (select-window (get-buffer-window gnus-article-buffer t))
5416 (gnus-article-next-page)
5417 (select-window win)))
5419 (defun gnus-button-prev-page ()
5420 "Go to the prev page."
5422 (let ((win (selected-window)))
5423 (select-window (get-buffer-window gnus-article-buffer t))
5424 (gnus-article-prev-page)
5425 (select-window win)))
5427 (static-if (featurep 'xemacs)
5428 (defun gnus-insert-next-page-button ()
5429 (let ((buffer-read-only nil))
5430 (gnus-eval-format gnus-next-page-line-format nil
5432 t local-map ,gnus-next-page-map
5433 gnus-callback gnus-article-button-next-page
5434 article-type annotation))))
5435 (defun gnus-insert-next-page-button ()
5436 (let ((buffer-read-only nil)
5437 (situation (get-text-property (point-min) 'mime-view-situation)))
5438 (set-keymap-parent gnus-next-page-map (current-local-map))
5439 (gnus-eval-format gnus-next-page-line-format nil
5441 t local-map ,gnus-next-page-map
5442 gnus-callback gnus-article-button-next-page
5443 article-type annotation
5444 mime-view-situation ,situation))))
5447 (defun gnus-article-button-next-page (arg)
5448 "Go to the next page."
5450 (let ((win (selected-window)))
5451 (select-window (get-buffer-window gnus-article-buffer t))
5452 (gnus-article-next-page)
5453 (select-window win)))
5455 (defun gnus-article-button-prev-page (arg)
5456 "Go to the prev page."
5458 (let ((win (selected-window)))
5459 (select-window (get-buffer-window gnus-article-buffer t))
5460 (gnus-article-prev-page)
5461 (select-window win)))
5463 (defvar gnus-decode-header-methods
5464 '(mail-decode-encoded-word-region)
5465 "List of methods used to decode headers.
5467 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5468 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5469 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5470 whose names match REGEXP.
5473 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5474 mail-decode-encoded-word-region
5475 (\"chinese\" . rfc1843-decode-region))
5478 (defvar gnus-decode-header-methods-cache nil)
5480 (defun gnus-multi-decode-header (start end)
5481 "Apply the functions from `gnus-encoded-word-methods' that match."
5482 (unless (and gnus-decode-header-methods-cache
5483 (eq gnus-newsgroup-name
5484 (car gnus-decode-header-methods-cache)))
5485 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5488 (nconc gnus-decode-header-methods-cache (list x))
5489 (if (and gnus-newsgroup-name
5490 (string-match (car x) gnus-newsgroup-name))
5491 (nconc gnus-decode-header-methods-cache
5493 gnus-decode-header-methods))
5494 (let ((xlist gnus-decode-header-methods-cache))
5497 (narrow-to-region start end)
5499 (funcall (pop xlist) (point-min) (point-max))))))
5502 ;;; Treatment top-level handling.
5505 (defun gnus-treat-article (condition &optional part-number total-parts type)
5506 (let ((length (- (point-max) (point-min)))
5507 (alist gnus-treatment-function-alist)
5508 (article-goto-body-goes-to-point-min-p t)
5512 (let ((list gnus-article-treat-types))
5514 (when (string-match (pop list) type)
5515 (throw 'found t)))))))
5516 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5517 (entity (static-unless (featurep 'xemacs)
5518 (when (eq 'head condition)
5519 (get-text-property (point-min) 'mime-view-entity))))
5520 val elem buttonized)
5521 (gnus-run-hooks 'gnus-part-display-hook)
5522 (unless gnus-inhibit-treatment
5523 (while (setq elem (pop alist))
5526 (if (gnus-buffer-live-p gnus-summary-buffer)
5527 (set-buffer gnus-summary-buffer))
5528 (symbol-value (car elem))))
5529 (when (and (or (consp val)
5531 (gnus-treat-predicate val)
5532 (or (not (get (car elem) 'highlight))
5534 (when (and (not buttonized)
5536 '(gnus-treat-hide-signature
5537 gnus-treat-highlight-signature)))
5538 (gnus-article-buttonize-signature)
5539 (setq buttonized t))
5541 (funcall (cadr elem)))))
5542 ;; FSF Emacsen does not inherit the existing text properties
5543 ;; in the new text, so we should do it for `mime-view-entity'.
5544 (static-unless (featurep 'xemacs)
5546 (put-text-property (point-min) (point-max)
5547 'mime-view-entity entity))))))
5549 ;; Dynamic variables.
5551 (defvar part-number)
5552 (defvar total-parts)
5557 (defun gnus-treat-predicate (val)
5562 (stringp (car val)))
5563 (apply 'gnus-or (mapcar `(lambda (s)
5564 (string-match s ,(or gnus-newsgroup-name "")))
5567 (let ((pred (pop val)))
5570 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5572 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5574 (not (gnus-treat-predicate (car val))))
5576 (equal (car val) type))
5578 (error "%S is not a valid predicate" pred)))))
5588 (eq part-number total-parts))
5592 (error "%S is not a valid value" val))))
5594 (defun gnus-article-encrypt-body (protocol &optional n)
5595 "Encrypt the article body."
5598 (or gnus-article-encrypt-protocol
5599 (completing-read "Encrypt protocol: "
5600 gnus-article-encrypt-protocol-alist
5602 current-prefix-arg))
5603 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5605 (error (format "Can't find the encrypt protocol %s" protocol)))
5606 (if (equal gnus-newsgroup-name "nndraft:drafts")
5607 (error "Can't encrypt the article in group nndraft:drafts."))
5608 (if (equal gnus-newsgroup-name "nndraft:queue")
5609 (error "Don't encrypt the article in group nndraft:queue."))
5610 (gnus-summary-iterate n
5612 (set-buffer gnus-summary-buffer)
5613 (let ((mail-parse-charset gnus-newsgroup-charset)
5614 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5615 (summary-buffer gnus-summary-buffer)
5617 (gnus-set-global-variables)
5618 (when (gnus-group-read-only-p)
5619 (error "The current newsgroup does not support article encrypt"))
5620 (gnus-summary-show-article t)
5622 (or (mail-header-references gnus-current-headers) ""))
5623 (set-buffer gnus-article-buffer)
5624 (let* ((buffer-read-only nil)
5626 (mapcar (lambda (field)
5627 (and (save-restriction
5628 (message-narrow-to-head)
5629 (goto-char (point-min))
5630 (search-forward field nil t))
5632 (message-narrow-to-field)
5633 (buffer-substring (point-min) (point-max))
5634 (delete-region (point-min) (point-max))
5636 '("Content-Type:" "Content-Transfer-Encoding:"
5637 "Content-Disposition:"))))
5638 (message-narrow-to-head)
5639 (message-remove-header "MIME-Version")
5640 (goto-char (point-max))
5641 (setq point (point))
5642 (insert (apply 'concat headers))
5644 (narrow-to-region point (point-max))
5645 (let ((message-options message-options))
5646 (message-options-set 'message-sender user-mail-address)
5647 (message-options-set 'message-recipients user-mail-address)
5648 (message-options-set 'message-sign-encrypt 'not)
5650 (goto-char (point-min))
5651 (insert "MIME-Version: 1.0\n")
5653 (gnus-summary-edit-article-done
5654 references nil summary-buffer t))
5655 (when gnus-keep-backlog
5656 (gnus-backlog-remove-article
5657 (car gnus-article-current) (cdr gnus-article-current)))
5659 (when (get-buffer gnus-original-article-buffer)
5660 (set-buffer gnus-original-article-buffer)
5661 (setq gnus-original-article nil)))
5662 (when gnus-use-cache
5663 (gnus-cache-update-article
5664 (car gnus-article-current) (cdr gnus-article-current))))))))
5666 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]]%)%}\n"
5667 "The following specs can be used:
5668 %t The security MIME type
5669 %i Additional info")
5671 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]]%)%}\n"
5672 "The following specs can be used:
5673 %t The security MIME type
5674 %i Additional info")
5676 (defvar gnus-mime-security-button-line-format-alist
5677 '((?t gnus-tmp-type ?s)
5678 (?i gnus-tmp-info ?s)))
5680 (defvar gnus-mime-security-button-map
5681 (let ((map (make-sparse-keymap)))
5682 (set-keymap-parent map gnus-article-mode-map)
5683 (define-key map gnus-mouse-2 'gnus-article-push-button)
5684 (define-key map "\r" 'gnus-article-press-button)
5687 (defvar gnus-mime-security-details-buffer nil)
5689 (defun gnus-mime-security-verify-or-decrypt (handle)
5690 (mm-remove-parts (cdr handle))
5691 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5694 (delete-region (car region) (cdr region))
5695 (set-marker (car region) nil)
5696 (set-marker (cdr region) nil)))
5697 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5698 (let* ((mm-verify-option 'known)
5699 (mm-decrypt-option 'known)
5700 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5701 (unless (eq nparts (cdr handle))
5702 (mm-destroy-parts (cdr handle))
5703 (setcdr handle nparts))))
5704 (let ((point (point))
5706 (gnus-mime-display-security handle)
5709 (defun gnus-mime-security-show-details (handle)
5710 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5713 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5714 (with-current-buffer gnus-mime-security-details-buffer
5717 (setq gnus-mime-security-details-buffer
5718 (gnus-get-buffer-create "*MIME Security Details*")))
5719 (with-current-buffer gnus-mime-security-details-buffer
5721 (pop-to-buffer gnus-mime-security-details-buffer))
5722 (gnus-message 5 "No details."))))
5724 (defun gnus-mime-security-press-button (handle)
5725 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5726 (gnus-mime-security-show-details handle)
5727 (gnus-mime-security-verify-or-decrypt handle)))
5729 (defun gnus-insert-mime-security-button (handle &optional displayed)
5730 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5733 (or (nth 2 (assoc protocol mm-verify-function-alist))
5734 (nth 2 (assoc protocol mm-decrypt-function-alist))
5736 (if (equal (car handle) "multipart/signed")
5737 " Signed" " Encrypted")
5740 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5747 gnus-mime-security-button-line-format
5748 gnus-mime-security-button-line-format-alist
5749 `(local-map ,gnus-mime-security-button-map
5750 keymap ,gnus-mime-security-button-map
5751 gnus-callback gnus-mime-security-press-button
5752 article-type annotation
5755 (widget-convert-button
5758 :action 'gnus-widget-press-button
5759 :button-keymap gnus-mime-security-button-map
5761 (lambda (widget/window &optional overlay pos)
5762 ;; Needed to properly clear the message due to a bug in
5763 ;; wid-edit (XEmacs only).
5764 (if (boundp 'help-echo-owns-message)
5765 (setq help-echo-owns-message t))
5768 (aref gnus-mouse-2 0))))))
5770 (defun gnus-mime-display-security (handle)
5772 (narrow-to-region (point) (point))
5773 (gnus-insert-mime-security-button handle)
5774 (gnus-mime-display-mixed (cdr handle))
5777 (let ((gnus-mime-security-button-line-format
5778 gnus-mime-security-button-end-line-format))
5779 (gnus-insert-mime-security-button handle))
5780 (mm-set-handle-multipart-parameter handle 'gnus-region
5781 (cons (set-marker (make-marker)
5783 (set-marker (make-marker)
5790 (defun gnus-article-header-presentation-method (entity situation)
5791 (mime-insert-header entity)
5794 (set-alist 'mime-header-presentation-method-alist
5795 'gnus-original-article-mode
5796 #'gnus-article-header-presentation-method)
5798 (defun gnus-mime-preview-quitting-method ()
5799 (mime-preview-kill-buffer)
5800 (delete-other-windows)
5801 (gnus-article-show-summary)
5802 (gnus-summary-select-article gnus-show-all-headers t))
5804 (set-alist 'mime-preview-quitting-method-alist
5805 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5807 (set-alist 'mime-preview-following-method-alist
5808 'gnus-original-article-mode #'gnus-following-method)
5810 (set-alist 'mime-preview-over-to-previous-method-alist
5811 'gnus-original-article-mode
5813 (if (> (point-min) 1)
5814 (gnus-article-prev-page)
5815 (gnus-article-read-summary-keys
5816 nil (gnus-character-to-event ?P)))))
5818 (set-alist 'mime-preview-over-to-next-method-alist
5819 'gnus-original-article-mode'
5821 (if (< (point-max) (buffer-size))
5822 (gnus-article-next-page)
5823 (gnus-article-read-summary-keys
5824 nil (gnus-character-to-event ?N)))))
5834 (run-hooks 'gnus-art-load-hook)
5836 ;;; gnus-art.el ends here