1 ;;; gnus-art.el --- article mode commands for Semi-gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Katsumi Yamaoka <yamaoka@jpl.org>
9 ;; Keywords: mail, news, MIME
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
36 (defvar w3m-minor-mode-map))
40 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
42 (let ((recursive-load-depth-limit 100))
49 (when (static-if (featurep 'xemacs)
50 (console-on-window-system-p)
52 (require 'mime-image))
55 ;; Avoid byte-compile warnings.
65 (autoload 'gnus-msg-mail "gnus-msg" nil t)
66 (autoload 'gnus-button-mailto "gnus-msg")
67 (autoload 'gnus-button-reply "gnus-msg" nil t)
68 (autoload 'parse-time-string "parse-time" nil nil)
69 (autoload 'ansi-color-apply-on-region "ansi-color")
71 (defgroup gnus-article nil
73 :link '(custom-manual "(gnus)Article Buffer")
76 (defgroup gnus-article-treat nil
77 "Treating article parts."
78 :link '(custom-manual "(gnus)Article Hiding")
81 (defgroup gnus-article-hiding nil
82 "Hiding article parts."
83 :link '(custom-manual "(gnus)Article Hiding")
86 (defgroup gnus-article-highlight nil
87 "Article highlighting."
88 :link '(custom-manual "(gnus)Article Highlighting")
92 (defgroup gnus-article-signature nil
94 :link '(custom-manual "(gnus)Article Signature")
97 (defgroup gnus-article-headers nil
99 :link '(custom-manual "(gnus)Hiding Headers")
100 :group 'gnus-article)
102 (defgroup gnus-article-washing nil
103 "Special commands on articles."
104 :link '(custom-manual "(gnus)Article Washing")
105 :group 'gnus-article)
107 (defgroup gnus-article-emphasis nil
108 "Fontisizing articles."
109 :link '(custom-manual "(gnus)Article Fontisizing")
110 :group 'gnus-article)
112 (defgroup gnus-article-saving nil
114 :link '(custom-manual "(gnus)Saving Articles")
115 :group 'gnus-article)
117 (defgroup gnus-article-mime nil
118 "Worshiping the MIME wonder."
119 :link '(custom-manual "(gnus)Using MIME")
120 :group 'gnus-article)
122 (defgroup gnus-article-buttons nil
123 "Pushable buttons in the article buffer."
124 :link '(custom-manual "(gnus)Article Buttons")
125 :group 'gnus-article)
127 (defgroup gnus-article-various nil
128 "Other article options."
129 :link '(custom-manual "(gnus)Misc Article")
130 :group 'gnus-article)
132 (defcustom gnus-ignored-headers
135 (concat "^" header ":"))
136 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
137 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
138 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
139 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
140 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
141 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
142 "X-Attribution" "X-Originating-IP" "Delivered-To"
143 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
144 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
145 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
146 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
147 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
148 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
149 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
150 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
151 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
152 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
153 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
154 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
155 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
156 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
157 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
158 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
159 "List-[A-Za-z]+" "X-Listprocessor-Version"
160 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
161 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
162 "X-Received" "Content-length" "X-precedence"
163 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
164 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
165 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
166 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
167 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
168 "X-Content-length" "X-Posting-Agent" "Original-Received"
169 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
170 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
171 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
172 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
173 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
174 "*All headers that start with this regexp will be hidden.
175 This variable can also be a list of regexps of headers to be ignored.
176 If `gnus-visible-headers' is non-nil, this variable will be ignored."
177 :type '(choice :custom-show nil
180 :group 'gnus-article-hiding)
182 (defcustom gnus-visible-headers
183 "^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:"
184 "*All headers that do not match this regexp will be hidden.
185 This variable can also be a list of regexp of headers to remain visible.
186 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
187 :type '(repeat :value-to-internal (lambda (widget value)
188 (custom-split-regexp-maybe value))
189 :match (lambda (widget value)
191 (widget-editable-list-match widget value)))
193 :group 'gnus-article-hiding)
195 (defcustom gnus-sorted-header-list
196 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
197 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
198 "*This variable is a list of regular expressions.
199 If it is non-nil, headers that match the regular expressions will
200 be placed first in the article buffer in the sequence specified by
202 :type '(repeat regexp)
203 :group 'gnus-article-hiding)
205 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
206 "Headers that are only to be displayed if they have interesting data.
207 Possible values in this list are:
209 'empty Headers with no content.
210 'newsgroups Newsgroup identical to Gnus group.
211 'to-address To identical to To-address.
212 'to-list To identical to To-list.
213 'cc-list CC identical to To-list.
214 'followup-to Followup-to identical to Newsgroups.
215 'reply-to Reply-to identical to From.
216 'date Date less than four days old.
217 'long-to To and/or Cc longer than 1024 characters.
218 'many-to Multiple To and/or Cc."
219 :type '(set (const :tag "Headers with no content." empty)
220 (const :tag "Newsgroups identical to Gnus group." newsgroups)
221 (const :tag "To identical to To-address." to-address)
222 (const :tag "To identical to To-list." to-list)
223 (const :tag "CC identical to To-list." cc-list)
224 (const :tag "Followup-to identical to Newsgroups." followup-to)
225 (const :tag "Reply-to identical to From." reply-to)
226 (const :tag "Date less than four days old." date)
227 (const :tag "To and/or Cc longer than 1024 characters." long-to)
228 (const :tag "Multiple To and/or Cc headers." many-to))
229 :group 'gnus-article-hiding)
231 (defcustom gnus-article-skip-boring nil
232 "Skip over text that is not worth reading.
233 By default, if you set this t, then Gnus will display citations and
234 signatures, but will never scroll down to show you a page consisting
235 only of boring text. Boring text is controlled by
236 `gnus-article-boring-faces'."
239 :group 'gnus-article-hiding)
241 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
242 "Regexp matching signature separator.
243 This can also be a list of regexps. In that case, it will be checked
244 from head to tail looking for a separator. Searches will be done from
245 the end of the buffer."
246 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
248 (repeat :tag "List of regexp" regexp))
249 :group 'gnus-article-signature)
251 (defcustom gnus-signature-limit nil
252 "Provide a limit to what is considered a signature.
253 If it is a number, no signature may not be longer (in characters) than
254 that number. If it is a floating point number, no signature may be
255 longer (in lines) than that number. If it is a function, the function
256 will be called without any parameters, and if it returns nil, there is
257 no signature in the buffer. If it is a string, it will be used as a
258 regexp. If it matches, the text in question is not a signature.
260 This can also be a list of the above values."
261 :type '(choice (const nil)
264 (function :value fun)
265 (regexp :value ".*"))
266 :group 'gnus-article-signature)
268 (defcustom gnus-hidden-properties '(invisible t intangible t)
269 "Property list to use for hiding text."
271 :group 'gnus-article-hiding)
273 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
274 ;; frames in a session.
275 (defcustom gnus-article-x-face-command
280 (if (or (gnus-image-type-available-p 'xface)
281 (gnus-image-type-available-p 'pbm))
282 'gnus-display-x-face-in-from
283 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -"))
284 ((gnus-image-type-available-p 'pbm)
285 'gnus-display-x-face-in-from)
287 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
289 "*String or function to be executed to display an X-Face header.
290 If it is a string, the command will be executed in a sub-shell
291 asynchronously. The compressed face will be piped to this command."
293 :format "%{%t%}:\n%[Value Menu%] %v"
297 (if (or (gnus-image-type-available-p 'xface)
298 (gnus-image-type-available-p 'pbm))
299 '(function-item gnus-display-x-face-in-from))
303 :group 'gnus-article-washing)
305 (defcustom gnus-article-x-face-too-ugly nil
306 "Regexp matching posters whose face shouldn't be shown automatically."
307 :type '(choice regexp (const nil))
308 :group 'gnus-article-washing)
310 (defcustom gnus-article-banner-alist nil
311 "Banner alist for stripping.
313 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
315 :type '(repeat (cons symbol regexp))
316 :group 'gnus-article-washing)
318 (gnus-define-group-parameter
321 "Alist of regexps (to match group names) and banner."
322 :variable-group gnus-article-washing
324 '(choice :tag "Banner"
326 (const :tag "Remove signature" signature)
327 (symbol :tag "Item in `gnus-article-banner-alist'" none)
329 (const :tag "None" nil))
331 "If non-nil, specify how to remove `banners' from articles.
333 Symbol `signature' means to remove signatures delimited by
334 `gnus-signature-separator'. Any other symbol is used to look up a
335 regular expression to match the banner in `gnus-article-banner-alist'.
336 A string is used as a regular expression to match the banner
339 (defcustom gnus-article-address-banner-alist nil
340 "Alist of mail addresses and banners.
341 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
342 to match a mail address in the From: header, BANNER is one of a symbol
343 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
344 If ADDRESS matches author's mail address, it will remove things like
345 advertisements. For example:
347 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
351 (regexp :tag "Address")
352 (choice :tag "Banner" :value nil
353 (const :tag "Remove signature" signature)
354 (symbol :tag "Item in `gnus-article-banner-alist'" none)
356 (const :tag "None" nil))))
358 :group 'gnus-article-washing)
360 (defmacro gnus-emphasis-custom-with-format (&rest body)
362 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
363 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
366 (defun gnus-emphasis-custom-value-to-external (value)
367 (gnus-emphasis-custom-with-format
368 (if (consp (car value))
369 (list (format format (car (car value)) (cdr (car value)))
371 (if (nth 1 value) 2 3)
375 (defun gnus-emphasis-custom-value-to-internal (value)
376 (gnus-emphasis-custom-with-format
377 (let ((regexp (concat "\\`"
378 (format (regexp-quote format)
379 "\\([^()]+\\)" "\\([^()]+\\)")
382 (if (string-match regexp (setq pattern (car value)))
383 (list (cons (match-string 1 pattern) (match-string 2 pattern))
388 (defcustom gnus-emphasis-alist
390 '(("\\*" "\\*" bold nil 2)
393 ("_/" "/_" underline-italic)
394 ("_\\*" "\\*_" underline-bold)
395 ("\\*/" "/\\*" bold-italic)
396 ("_\\*/" "/\\*_" underline-bold-italic))))
398 (gnus-emphasis-custom-with-format
399 (mapcar (lambda (spec)
400 (list (format format (car spec) (cadr spec))
403 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
405 '(;; I've never seen anyone use this strikethru convention whereas I've
406 ;; several times seen it triggered by normal text. --Stef
407 ;; Miles suggests that this form is sometimes used but for italics,
408 ;; so maybe we should map it to `italic'.
409 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
410 ;; 2 3 gnus-emphasis-strikethru)
411 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
412 2 3 gnus-emphasis-underline))))
413 "*Alist that says how to fontify certain phrases.
414 Each item looks like this:
416 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
418 The first element is a regular expression to be matched. The second
419 is a number that says what regular expression grouping used to find
420 the entire emphasized word. The third is a number that says what
421 regexp grouping should be displayed and highlighted. The fourth
422 is the face used for highlighting."
426 :format "%[Customizing Style%]\n%v"
428 (group :tag "Default"
429 :value ("" 0 0 default)
432 (let ((value (widget-get
433 (cadr (widget-get (widget-get widget :parent)
436 (if (not (eq (nth 2 value) 'default))
440 (gnus-emphasis-custom-value-to-external value))))
441 (widget-group-value-create widget))
443 (integer :format "Match group: %v")
444 (integer :format "Emphasize group: %v")
447 :value (("_" . "_") nil default)
449 (regexp :format "Start regexp: %v")
450 (regexp :format "End regexp: %v"))
451 (boolean :format "Show start and end patterns: %[%v%]\n"
452 :on " On " :off " Off ")
454 :get (lambda (symbol)
455 (mapcar 'gnus-emphasis-custom-value-to-internal
456 (default-value symbol)))
457 :set (lambda (symbol value)
458 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
460 :group 'gnus-article-emphasis)
462 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
463 "A regexp to describe whitespace which should not be emphasized.
464 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
465 The former avoids underlining of leading and trailing whitespace,
466 and the latter avoids underlining any whitespace at all."
468 :group 'gnus-article-emphasis
471 (defface gnus-emphasis-bold '((t (:bold t)))
472 "Face used for displaying strong emphasized text (*word*)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-italic '((t (:italic t)))
476 "Face used for displaying italic emphasized text (/word/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline '((t (:underline t)))
480 "Face used for displaying underlined emphasized text (_word_)."
481 :group 'gnus-article-emphasis)
483 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
484 "Face used for displaying underlined bold emphasized text (_*word*_)."
485 :group 'gnus-article-emphasis)
487 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
488 "Face used for displaying underlined italic emphasized text (_/word/_)."
489 :group 'gnus-article-emphasis)
491 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
492 "Face used for displaying bold italic emphasized text (/*word*/)."
493 :group 'gnus-article-emphasis)
495 (defface gnus-emphasis-underline-bold-italic
496 '((t (:bold t :italic t :underline t)))
497 "Face used for displaying underlined bold italic emphasized text.
498 Example: (_/*word*/_)."
499 :group 'gnus-article-emphasis)
501 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
502 '((t (:strikethru t)))
503 '((t (:strike-through t))))
504 "Face used for displaying strike-through text (-word-)."
505 :group 'gnus-article-emphasis)
507 (defface gnus-emphasis-highlight-words
508 '((t (:background "black" :foreground "yellow")))
509 "Face used for displaying highlighted words."
510 :group 'gnus-article-emphasis)
512 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
513 "Format for display of Date headers in article bodies.
514 See `format-time-string' for the possible values.
516 The variable can also be function, which should return a complete Date
517 header. The function is called with one argument, the time, which can
518 be fed to `format-time-string'."
519 :type '(choice string function)
520 :link '(custom-manual "(gnus)Article Date")
521 :group 'gnus-article-washing)
523 (defcustom gnus-save-all-headers t
524 "*If non-nil, don't remove any headers before saving."
525 :group 'gnus-article-saving
528 (defcustom gnus-prompt-before-saving 'always
529 "*This variable says how much prompting is to be done when saving articles.
530 If it is nil, no prompting will be done, and the articles will be
531 saved to the default files. If this variable is `always', each and
532 every article that is saved will be preceded by a prompt, even when
533 saving large batches of articles. If this variable is neither nil not
534 `always', there the user will be prompted once for a file name for
535 each invocation of the saving commands."
536 :group 'gnus-article-saving
537 :type '(choice (item always)
538 (item :tag "never" nil)
539 (sexp :tag "once" :format "%t\n" :value t)))
541 (defcustom gnus-saved-headers gnus-visible-headers
542 "Headers to keep if `gnus-save-all-headers' is nil.
543 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
544 If that variable is nil, however, all headers that match this regexp
545 will be kept while the rest will be deleted before saving."
546 :group 'gnus-article-saving
549 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
550 "A function to save articles in your favourite format.
551 The function must be interactively callable (in other words, it must
552 be an Emacs command).
554 Gnus provides the following functions:
556 * gnus-summary-save-in-rmail (Rmail format)
557 * gnus-summary-save-in-mail (Unix mail format)
558 * gnus-summary-save-in-folder (MH folder)
559 * gnus-summary-save-in-file (article format)
560 * gnus-summary-save-body-in-file (article body)
561 * gnus-summary-save-in-vm (use VM's folder format)
562 * gnus-summary-write-to-file (article format -- overwrite)."
563 :group 'gnus-article-saving
564 :type '(radio (function-item gnus-summary-save-in-rmail)
565 (function-item gnus-summary-save-in-mail)
566 (function-item gnus-summary-save-in-folder)
567 (function-item gnus-summary-save-in-file)
568 (function-item gnus-summary-save-body-in-file)
569 (function-item gnus-summary-save-in-vm)
570 (function-item gnus-summary-write-to-file)
573 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
574 "A function generating a file name to save articles in Rmail format.
575 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
576 :group 'gnus-article-saving
579 (defcustom gnus-mail-save-name 'gnus-plain-save-name
580 "A function generating a file name to save articles in Unix mail format.
581 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
582 :group 'gnus-article-saving
585 (defcustom gnus-folder-save-name 'gnus-folder-save-name
586 "A function generating a file name to save articles in MH folder.
587 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
588 :group 'gnus-article-saving
591 (defcustom gnus-file-save-name 'gnus-numeric-save-name
592 "A function generating a file name to save articles in article format.
593 The function is called with NEWSGROUP, HEADERS, and optional
595 :group 'gnus-article-saving
598 (defcustom gnus-split-methods
599 '((gnus-article-archive-name)
600 (gnus-article-nndoc-name))
601 "*Variable used to suggest where articles are to be saved.
602 For instance, if you would like to save articles related to Gnus in
603 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
604 you could set this variable to something like:
606 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
607 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
609 This variable is an alist where the key is the match and the
610 value is a list of possible files to save in if the match is
613 If the match is a string, it is used as a regexp match on the
614 article. If the match is a symbol, that symbol will be funcalled
615 from the buffer of the article to be saved with the newsgroup as
616 the parameter. If it is a list, it will be evaled in the same
619 If this form or function returns a string, this string will be
620 used as a possible file name; and if it returns a non-nil list,
621 that list will be used as possible file names."
622 :group 'gnus-article-saving
623 :type '(repeat (choice (list :value (fun) function)
624 (cons :value ("" "") regexp (repeat string))
627 (defcustom gnus-article-display-method-for-mime
628 'gnus-article-display-mime-message
629 "Function to display a MIME message.
630 The function is called from the article buffer."
631 :group 'gnus-article-mime
634 (defcustom gnus-article-display-method-for-traditional
635 'gnus-article-display-traditional-message
636 "*Function to display a traditional message.
637 The function is called from the article buffer."
638 :group 'gnus-article-mime
641 (defcustom gnus-page-delimiter "^\^L"
642 "*Regexp describing what to use as article page delimiters.
643 The default value is \"^\^L\", which is a form linefeed at the
644 beginning of a line."
646 :group 'gnus-article-various)
648 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
649 "*The format specification for the article mode line.
650 See `gnus-summary-mode-line-format' for a closer description.
652 The following additional specs are available:
654 %w The article washing status.
655 %m The number of MIME parts in the article."
657 :group 'gnus-article-various)
659 (defcustom gnus-article-mode-hook nil
660 "*A hook for Gnus article mode."
662 :group 'gnus-article-various)
664 (when (featurep 'xemacs)
665 ;; Extracted from gnus-xmas-define in order to preserve user settings
666 (when (fboundp 'turn-off-scroll-in-place)
667 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
668 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
669 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
671 (defcustom gnus-article-menu-hook nil
672 "*Hook run after the creation of the article mode menu."
674 :group 'gnus-article-various)
676 (defcustom gnus-article-prepare-hook nil
677 "*A hook called after an article has been prepared in the article buffer."
679 :group 'gnus-article-various)
681 (defcustom gnus-copy-article-ignored-headers nil
682 "List of headers to be removed when copying an article.
683 Each element is a regular expression."
684 :version "23.0" ;; No Gnus
685 :type '(repeat regexp)
686 :group 'gnus-article-various)
688 (make-obsolete-variable 'gnus-article-hide-pgp-hook
689 "This variable is obsolete in Gnus 5.10.")
691 (defcustom gnus-article-button-face 'bold
692 "Face used for highlighting buttons in the article buffer.
694 An article button is a piece of text that you can activate by pressing
695 `RET' or `mouse-2' above it."
697 :group 'gnus-article-buttons)
699 (defcustom gnus-article-mouse-face 'highlight
700 "Face used for mouse highlighting in the article buffer.
702 Article buttons will be displayed in this face when the cursor is
705 :group 'gnus-article-buttons)
707 (defcustom gnus-signature-face 'gnus-signature
708 "Face used for highlighting a signature in the article buffer.
709 Obsolete; use the face `gnus-signature' for customizations instead."
711 :group 'gnus-article-highlight
712 :group 'gnus-article-signature)
714 (defface gnus-signature
717 "Face used for highlighting a signature in the article buffer."
718 :group 'gnus-article-highlight
719 :group 'gnus-article-signature)
720 ;; backward-compatibility alias
721 (put 'gnus-signature-face 'face-alias 'gnus-signature)
723 (defface gnus-header-from
726 (:foreground "spring green"))
729 (:foreground "red3"))
732 "Face used for displaying from headers."
733 :group 'gnus-article-headers
734 :group 'gnus-article-highlight)
735 ;; backward-compatibility alias
736 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
738 (defface gnus-header-subject
741 (:foreground "SeaGreen3"))
744 (:foreground "red4"))
746 (:bold t :italic t)))
747 "Face used for displaying subject headers."
748 :group 'gnus-article-headers
749 :group 'gnus-article-highlight)
750 ;; backward-compatibility alias
751 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
753 (defface gnus-header-newsgroups
756 (:foreground "yellow" :italic t))
759 (:foreground "MidnightBlue" :italic t))
762 "Face used for displaying newsgroups headers.
763 In the default setup this face is only used for crossposted
765 :group 'gnus-article-headers
766 :group 'gnus-article-highlight)
767 ;; backward-compatibility alias
768 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
770 (defface gnus-header-name
773 (:foreground "SeaGreen"))
776 (:foreground "maroon"))
779 "Face used for displaying header names."
780 :group 'gnus-article-headers
781 :group 'gnus-article-highlight)
782 ;; backward-compatibility alias
783 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
785 (defface gnus-header-content
788 (:foreground "forest green" :italic t))
791 (:foreground "indianred4" :italic t))
794 "Face used for displaying header content."
795 :group 'gnus-article-headers
796 :group 'gnus-article-highlight)
797 ;; backward-compatibility alias
798 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
800 (defcustom gnus-header-face-alist
801 '(("From" nil gnus-header-from)
802 ("Subject" nil gnus-header-subject)
803 ("Newsgroups:.*," nil gnus-header-newsgroups)
804 ("" gnus-header-name gnus-header-content))
805 "*Controls highlighting of article headers.
807 An alist of the form (HEADER NAME CONTENT).
809 HEADER is a regular expression which should match the name of a
810 header and NAME and CONTENT are either face names or nil.
812 The name of each header field will be displayed using the face
813 specified by the first element in the list where HEADER matches
814 the header name and NAME is non-nil. Similarly, the content will
815 be displayed by the first non-nil matching CONTENT face."
816 :group 'gnus-article-headers
817 :group 'gnus-article-highlight
818 :type '(repeat (list (regexp :tag "Header")
820 (item :tag "skip" nil)
821 (face :value default))
822 (choice :tag "Content"
823 (item :tag "skip" nil)
824 (face :value default)))))
826 (defcustom gnus-article-decode-hook
827 '(article-decode-group-name article-decode-idna-rhs)
828 "*Hook run to decode charsets in articles."
829 :group 'gnus-article-headers
832 (defcustom gnus-display-mime-function 'gnus-display-mime
833 "Function to display MIME articles."
834 :group 'gnus-article-mime
837 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
838 "Function used to decode headers.")
840 (defvar gnus-article-dumbquotes-map
860 "Table for MS-to-Latin1 translation.")
862 (defcustom gnus-ignored-mime-types nil
863 "List of MIME types that should be ignored by Gnus."
865 :group 'gnus-article-mime
866 :type '(repeat regexp))
868 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
869 "List of MIME types that should not be given buttons when rendered inline.
870 See also `gnus-buttonized-mime-types' which may override this variable.
871 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
873 :group 'gnus-article-mime
874 :type '(repeat regexp))
876 (defcustom gnus-buttonized-mime-types nil
877 "List of MIME types that should be given buttons when rendered inline.
878 If set, this variable overrides `gnus-unbuttonized-mime-types'.
879 To see e.g. security buttons you could set this to
880 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
881 this list to display radio buttons that allow you to choose one of two
882 media types those mails include. See also `mm-discouraged-alternatives'.
883 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
885 :group 'gnus-article-mime
886 :type '(repeat regexp))
888 (defcustom gnus-inhibit-mime-unbuttonizing nil
889 "If non-nil, all MIME parts get buttons.
890 When nil (the default value), then some MIME parts do not get buttons,
891 as described by the variables `gnus-buttonized-mime-types' and
892 `gnus-unbuttonized-mime-types'."
894 :group 'gnus-article-mime
897 (defcustom gnus-body-boundary-delimiter "_"
898 "String used to delimit header and body.
899 This variable is used by `gnus-article-treat-body-boundary' which can
900 be controlled by `gnus-treat-body-boundary'."
902 :group 'gnus-article-various
903 :type '(choice (item :tag "None" :value nil)
906 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
908 "Defines the location of the faces database.
909 For information on obtaining this database of pretty pictures, please
910 see http://www.cs.indiana.edu/picons/ftp/index.html"
912 :type '(repeat directory)
913 :link '(url-link :tag "download"
914 "http://www.cs.indiana.edu/picons/ftp/index.html")
915 :link '(custom-manual "(gnus)Picons")
918 (defun gnus-picons-installed-p ()
919 "Say whether picons are installed on your machine."
920 (let ((installed nil))
921 (dolist (database gnus-picon-databases)
922 (when (file-exists-p database)
926 (defcustom gnus-article-mime-part-function nil
927 "Function called with a MIME handle as the argument.
928 This is meant for people who want to do something automatic based
929 on parts -- for instance, adding Vcard info to a database."
930 :group 'gnus-article-mime
931 :type '(choice (const nil)
934 (defcustom gnus-mime-multipart-functions nil
935 "An alist of MIME types to functions to display them."
937 :group 'gnus-article-mime
938 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
940 (defcustom gnus-article-date-lapsed-new-header nil
941 "Whether the X-Sent and Date headers can coexist.
942 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
943 either replace the old \"Date:\" header (if this variable is nil), or
944 be added below it (otherwise)."
946 :group 'gnus-article-headers
949 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
950 "Function called with a MIME handle as the argument.
951 This is meant for people who want to view first matched part.
952 For `undisplayed-alternative' (default), the first undisplayed
953 part or alternative part is used. For `undisplayed', the first
954 undisplayed part is used. For a function, the first part which
955 the function return t is used. For nil, the first part is
958 :group 'gnus-article-mime
960 (item :tag "first" :value nil)
961 (item :tag "undisplayed" :value undisplayed)
962 (item :tag "undisplayed or alternative"
963 :value undisplayed-alternative)
966 (defcustom gnus-mime-action-alist
967 '(("save to file" . gnus-mime-save-part)
968 ("save and strip" . gnus-mime-save-part-and-strip)
969 ("replace with file" . gnus-mime-replace-part)
970 ("delete part" . gnus-mime-delete-part)
971 ("display as text" . gnus-mime-inline-part)
972 ("view the part" . gnus-mime-view-part)
973 ("pipe to command" . gnus-mime-pipe-part)
974 ("toggle display" . gnus-article-press-button)
975 ("toggle display" . gnus-article-view-part-as-charset)
976 ("view as type" . gnus-mime-view-part-as-type)
977 ("view internally" . gnus-mime-view-part-internally)
978 ("view externally" . gnus-mime-view-part-externally))
979 "An alist of actions that run on the MIME attachment."
980 :group 'gnus-article-mime
981 :type '(repeat (cons (string :tag "name")
984 (defcustom gnus-auto-select-part 1
985 "Advance to next MIME part when deleting or stripping parts.
987 When 0, point will be placed on the same part as before. When
988 positive (negative), move point forward (backwards) this many
989 parts. When nil, redisplay article."
990 :version "23.0" ;; No Gnus
991 :group 'gnus-article-mime
992 :type '(choice (const nil :tag "Redisplay article.")
993 (const 1 :tag "Next part.")
994 (const 0 :tag "Current part.")
998 ;;; The treatment variables
1001 (defvar gnus-part-display-hook nil
1002 "Hook called on parts that are to receive treatment.")
1004 (defvar gnus-article-treat-custom
1005 '(choice (const :tag "Off" nil)
1007 (const :tag "Header" head)
1008 (const :tag "First" first)
1009 (const :tag "Last" last)
1010 (const :tag "Mime" mime)
1011 (integer :tag "Less")
1012 (repeat :tag "Groups" regexp)
1013 (sexp :tag "Predicate")))
1015 (defvar gnus-article-treat-head-custom
1016 '(choice (const :tag "Off" nil)
1017 (const :tag "Header" head)))
1019 (defvar gnus-article-treat-types '("text/plain")
1022 (defvar gnus-inhibit-treatment nil
1023 "Whether to inhibit treatment.")
1025 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1026 "Highlight the signature.
1027 Valid values are nil, t, `head', `first', `last', an integer or a
1028 predicate. See Info node `(gnus)Customizing Articles'."
1029 :group 'gnus-article-treat
1030 :link '(custom-manual "(gnus)Customizing Articles")
1031 :type gnus-article-treat-custom)
1032 (put 'gnus-treat-highlight-signature 'highlight t)
1034 (defcustom gnus-treat-buttonize 100000
1036 Valid values are nil, t, `head', `first', `last', an integer or a
1037 predicate. See Info node `(gnus)Customizing Articles'."
1038 :group 'gnus-article-treat
1039 :link '(custom-manual "(gnus)Customizing Articles")
1040 :type gnus-article-treat-custom)
1041 (put 'gnus-treat-buttonize 'highlight t)
1043 (defcustom gnus-treat-buttonize-head 'head
1044 "Add buttons to the head.
1045 Valid values are nil, t, `head', `first', `last', an integer or a
1046 predicate. See Info node `(gnus)Customizing Articles'."
1047 :group 'gnus-article-treat
1048 :link '(custom-manual "(gnus)Customizing Articles")
1049 :type gnus-article-treat-head-custom)
1050 (put 'gnus-treat-buttonize-head 'highlight t)
1052 (defcustom gnus-treat-emphasize
1053 (and (or window-system
1057 Valid values are nil, t, `head', `first', `last', an integer or a
1058 predicate. See Info node `(gnus)Customizing Articles'."
1059 :group 'gnus-article-treat
1060 :link '(custom-manual "(gnus)Customizing Articles")
1061 :type gnus-article-treat-custom)
1062 (put 'gnus-treat-emphasize 'highlight t)
1064 (defcustom gnus-treat-strip-cr nil
1065 "Remove carriage returns.
1066 Valid values are nil, t, `head', `first', `last', an integer or a
1067 predicate. See Info node `(gnus)Customizing Articles'."
1069 :group 'gnus-article-treat
1070 :link '(custom-manual "(gnus)Customizing Articles")
1071 :type gnus-article-treat-custom)
1073 (defcustom gnus-treat-unsplit-urls nil
1074 "Remove newlines from within URLs.
1075 Valid values are nil, t, `head', `first', `last', an integer or a
1076 predicate. See Info node `(gnus)Customizing Articles'."
1078 :group 'gnus-article-treat
1079 :link '(custom-manual "(gnus)Customizing Articles")
1080 :type gnus-article-treat-custom)
1082 (defcustom gnus-treat-leading-whitespace nil
1083 "Remove leading whitespace in headers.
1084 Valid values are nil, t, `head', `first', `last', an integer or a
1085 predicate. See Info node `(gnus)Customizing Articles'."
1087 :group 'gnus-article-treat
1088 :link '(custom-manual "(gnus)Customizing Articles")
1089 :type gnus-article-treat-custom)
1091 (defcustom gnus-treat-hide-headers 'head
1093 Valid values are nil, t, `head', `first', `last', an integer or a
1094 predicate. See Info node `(gnus)Customizing Articles'."
1095 :group 'gnus-article-treat
1096 :link '(custom-manual "(gnus)Customizing Articles")
1097 :type gnus-article-treat-head-custom)
1099 (defcustom gnus-treat-hide-boring-headers nil
1100 "Hide boring headers.
1101 Valid values are nil, t, `head', `first', `last', an integer or a
1102 predicate. See Info node `(gnus)Customizing Articles'."
1103 :group 'gnus-article-treat
1104 :link '(custom-manual "(gnus)Customizing Articles")
1105 :type gnus-article-treat-head-custom)
1107 (defcustom gnus-treat-hide-signature nil
1108 "Hide the signature.
1109 Valid values are nil, t, `head', `first', `last', an integer or a
1110 predicate. See Info node `(gnus)Customizing Articles'."
1111 :group 'gnus-article-treat
1112 :link '(custom-manual "(gnus)Customizing Articles")
1113 :type gnus-article-treat-custom)
1115 (defcustom gnus-treat-fill-article nil
1117 Valid values are nil, t, `head', `first', `last', an integer or a
1118 predicate. See Info node `(gnus)Customizing Articles'."
1119 :group 'gnus-article-treat
1120 :link '(custom-manual "(gnus)Customizing Articles")
1121 :type gnus-article-treat-custom)
1123 (defcustom gnus-treat-hide-citation nil
1125 Valid values are nil, t, `head', `first', `last', an integer or a
1126 predicate. See Info node `(gnus)Customizing Articles'."
1127 :group 'gnus-article-treat
1128 :link '(custom-manual "(gnus)Customizing Articles")
1129 :type gnus-article-treat-custom)
1131 (defcustom gnus-treat-hide-citation-maybe nil
1133 Valid values are nil, t, `head', `first', `last', an integer or a
1134 predicate. See Info node `(gnus)Customizing Articles'."
1135 :group 'gnus-article-treat
1136 :link '(custom-manual "(gnus)Customizing Articles")
1137 :type gnus-article-treat-custom)
1139 (defcustom gnus-treat-strip-list-identifiers 'head
1140 "Strip list identifiers from `gnus-list-identifiers`.
1141 Valid values are nil, t, `head', `first', `last', an integer or a
1142 predicate. See Info node `(gnus)Customizing Articles'."
1144 :group 'gnus-article-treat
1145 :link '(custom-manual "(gnus)Customizing Articles")
1146 :type gnus-article-treat-custom)
1148 (make-obsolete-variable 'gnus-treat-strip-pgp
1149 "This option is obsolete in Gnus 5.10.")
1151 (defcustom gnus-treat-strip-pem nil
1152 "Strip PEM signatures.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate. See Info node `(gnus)Customizing Articles'."
1155 :group 'gnus-article-treat
1156 :link '(custom-manual "(gnus)Customizing Articles")
1157 :type gnus-article-treat-custom)
1159 (defcustom gnus-treat-strip-banner t
1160 "Strip banners from articles.
1161 The banner to be stripped is specified in the `banner' group parameter.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate. See Info node `(gnus)Customizing Articles'."
1164 :group 'gnus-article-treat
1165 :link '(custom-manual "(gnus)Customizing Articles")
1166 :type gnus-article-treat-custom)
1168 (defcustom gnus-treat-highlight-headers 'head
1169 "Highlight the headers.
1170 Valid values are nil, t, `head', `first', `last', an integer or a
1171 predicate. See Info node `(gnus)Customizing Articles'."
1172 :group 'gnus-article-treat
1173 :link '(custom-manual "(gnus)Customizing Articles")
1174 :type gnus-article-treat-head-custom)
1175 (put 'gnus-treat-highlight-headers 'highlight t)
1177 (defcustom gnus-treat-highlight-citation t
1178 "Highlight cited text.
1179 Valid values are nil, t, `head', `first', `last', an integer or a
1180 predicate. See Info node `(gnus)Customizing Articles'."
1181 :group 'gnus-article-treat
1182 :link '(custom-manual "(gnus)Customizing Articles")
1183 :type gnus-article-treat-custom)
1184 (put 'gnus-treat-highlight-citation 'highlight t)
1186 (defcustom gnus-treat-date-ut nil
1187 "Display the Date in UT (GMT).
1188 Valid values are nil, t, `head', `first', `last', an integer or a
1189 predicate. See Info node `(gnus)Customizing Articles'."
1190 :group 'gnus-article-treat
1191 :link '(custom-manual "(gnus)Customizing Articles")
1192 :type gnus-article-treat-head-custom)
1194 (defcustom gnus-treat-date-local nil
1195 "Display the Date in the local timezone.
1196 Valid values are nil, t, `head', `first', `last', an integer or a
1197 predicate. See Info node `(gnus)Customizing Articles'."
1198 :group 'gnus-article-treat
1199 :link '(custom-manual "(gnus)Customizing Articles")
1200 :type gnus-article-treat-head-custom)
1202 (defcustom gnus-treat-date-english nil
1203 "Display the Date in a format that can be read aloud in English.
1204 Valid values are nil, t, `head', `first', `last', an integer or a
1205 predicate. See Info node `(gnus)Customizing Articles'."
1207 :group 'gnus-article-treat
1208 :link '(custom-manual "(gnus)Customizing Articles")
1209 :type gnus-article-treat-head-custom)
1211 (defcustom gnus-treat-date-lapsed nil
1212 "Display the Date header in a way that says how much time has elapsed.
1213 Valid values are nil, t, `head', `first', `last', an integer or a
1214 predicate. See Info node `(gnus)Customizing Articles'."
1215 :group 'gnus-article-treat
1216 :link '(custom-manual "(gnus)Customizing Articles")
1217 :type gnus-article-treat-head-custom)
1219 (defcustom gnus-treat-date-original nil
1220 "Display the date in the original timezone.
1221 Valid values are nil, t, `head', `first', `last', an integer or a
1222 predicate. See Info node `(gnus)Customizing Articles'."
1223 :group 'gnus-article-treat
1224 :link '(custom-manual "(gnus)Customizing Articles")
1225 :type gnus-article-treat-head-custom)
1227 (defcustom gnus-treat-date-iso8601 nil
1228 "Display the date in the ISO8601 format.
1229 Valid values are nil, t, `head', `first', `last', an integer or a
1230 predicate. See Info node `(gnus)Customizing Articles'."
1232 :group 'gnus-article-treat
1233 :link '(custom-manual "(gnus)Customizing Articles")
1234 :type gnus-article-treat-head-custom)
1236 (defcustom gnus-treat-date-user-defined nil
1237 "Display the date in a user-defined format.
1238 The format is defined by the `gnus-article-time-format' variable.
1239 Valid values are nil, t, `head', `first', `last', an integer or a
1240 predicate. See Info node `(gnus)Customizing Articles'."
1241 :group 'gnus-article-treat
1242 :link '(custom-manual "(gnus)Customizing Articles")
1243 :type gnus-article-treat-head-custom)
1245 (defcustom gnus-treat-strip-headers-in-body t
1246 "Strip the X-No-Archive header line from the beginning of the body.
1247 Valid values are nil, t, `head', `first', `last', an integer or a
1248 predicate. See Info node `(gnus)Customizing Articles'."
1250 :group 'gnus-article-treat
1251 :link '(custom-manual "(gnus)Customizing Articles")
1252 :type gnus-article-treat-custom)
1254 (defcustom gnus-treat-strip-trailing-blank-lines nil
1255 "Strip trailing blank lines.
1256 Valid values are nil, t, `head', `first', `last', an integer or a
1257 predicate. See Info node `(gnus)Customizing Articles'.
1259 When set to t, it also strips trailing blanks in all MIME parts.
1260 Consider to use `last' instead."
1261 :group 'gnus-article-treat
1262 :link '(custom-manual "(gnus)Customizing Articles")
1263 :type gnus-article-treat-custom)
1265 (defcustom gnus-treat-strip-leading-blank-lines nil
1266 "Strip leading blank lines.
1267 Valid values are nil, t, `head', `first', `last', an integer or a
1268 predicate. See Info node `(gnus)Customizing Articles'.
1270 When set to t, it also strips trailing blanks in all MIME parts."
1271 :group 'gnus-article-treat
1272 :link '(custom-manual "(gnus)Customizing Articles")
1273 :type gnus-article-treat-custom)
1275 (defcustom gnus-treat-strip-multiple-blank-lines nil
1276 "Strip multiple blank lines.
1277 Valid values are nil, t, `head', `first', `last', an integer or a
1278 predicate. See Info node `(gnus)Customizing Articles'."
1279 :group 'gnus-article-treat
1280 :link '(custom-manual "(gnus)Customizing Articles")
1281 :type gnus-article-treat-custom)
1283 (defcustom gnus-treat-unfold-headers 'head
1284 "Unfold folded header lines.
1285 Valid values are nil, t, `head', `first', `last', an integer or a
1286 predicate. See Info node `(gnus)Customizing Articles'."
1288 :group 'gnus-article-treat
1289 :link '(custom-manual "(gnus)Customizing Articles")
1290 :type gnus-article-treat-custom)
1292 (defcustom gnus-treat-fold-headers nil
1294 Valid values are nil, t, `head', `first', `last', an integer or a
1295 predicate. See Info node `(gnus)Customizing Articles'."
1297 :group 'gnus-article-treat
1298 :link '(custom-manual "(gnus)Customizing Articles")
1299 :type gnus-article-treat-custom)
1301 (defcustom gnus-treat-fold-newsgroups 'head
1302 "Fold the Newsgroups and Followup-To headers.
1303 Valid values are nil, t, `head', `first', `last', an integer or a
1304 predicate. See Info node `(gnus)Customizing Articles'."
1306 :group 'gnus-article-treat
1307 :link '(custom-manual "(gnus)Customizing Articles")
1308 :type gnus-article-treat-custom)
1310 (defcustom gnus-treat-overstrike t
1311 "Treat overstrike highlighting.
1312 Valid values are nil, t, `head', `first', `last', an integer or a
1313 predicate. See Info node `(gnus)Customizing Articles'."
1314 :group 'gnus-article-treat
1315 :link '(custom-manual "(gnus)Customizing Articles")
1316 :type gnus-article-treat-custom)
1317 (put 'gnus-treat-overstrike 'highlight t)
1319 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1320 "Treat ANSI SGR control sequences.
1321 Valid values are nil, t, `head', `first', `last', an integer or a
1322 predicate. See Info node `(gnus)Customizing Articles'."
1323 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :type gnus-article-treat-custom)
1327 (make-obsolete-variable 'gnus-treat-display-xface
1328 'gnus-treat-display-x-face)
1330 (defcustom gnus-treat-display-x-face
1331 (and (not noninteractive)
1332 (or (and (fboundp 'image-type-available-p)
1333 (image-type-available-p 'xbm)
1334 (string-match "^0x" (shell-command-to-string "uncompface"))
1335 (executable-find "icontopbm"))
1336 (and (featurep 'xemacs)
1339 "Display X-Face headers.
1340 Valid values are nil, t, `head', `first', `last', an integer or a
1341 predicate. See Info node `(gnus)Customizing Articles' and Info
1342 node `(gnus)X-Face' for details."
1343 :group 'gnus-article-treat
1345 :link '(custom-manual "(gnus)Customizing Articles")
1346 :link '(custom-manual "(gnus)X-Face")
1347 :type gnus-article-treat-head-custom
1348 :set (lambda (symbol value)
1351 (cond ((or (boundp symbol) (get symbol 'saved-value))
1353 ((boundp 'gnus-treat-display-xface)
1355 ** gnus-treat-display-xface is an obsolete variable;\
1356 use gnus-treat-display-x-face instead")
1357 (default-value 'gnus-treat-display-xface))
1358 ((get 'gnus-treat-display-xface 'saved-value)
1360 ** gnus-treat-display-xface is an obsolete variable;\
1361 use gnus-treat-display-x-face instead")
1362 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1365 (put 'gnus-treat-display-x-face 'highlight t)
1367 (defcustom gnus-article-should-use-smiley-mule
1368 (not (or (featurep 'xemacs)
1369 (gnus-image-type-available-p 'xpm)
1370 (gnus-image-type-available-p 'pbm)))
1371 "Non-nil means use `smiley-mule' to show smileys rather than `smiley'.
1372 `smiley-mule' is boundled in BITMAP-MULE package. You can set it to t
1373 even if your Emacs supports images. It has no effect on XEmacs."
1374 :group 'gnus-article-various
1376 :get (lambda (symbol)
1377 (and (not noninteractive)
1378 (default-value symbol)
1379 (not (featurep 'xemacs))
1380 (module-installed-p 'smiley-mule)
1382 :set (lambda (symbol value)
1383 (set-default symbol (and (not noninteractive)
1385 (not (featurep 'xemacs))
1386 (module-installed-p 'smiley-mule)
1389 (defvar gnus-article-smiley-mule-loaded-p nil
1390 "Internal variable used to say whether `smiley-mule' is loaded (whether
1391 smiley functions are not overridden by `smiley').")
1393 (defcustom gnus-treat-display-face
1394 (and (not noninteractive)
1395 (or (and (fboundp 'image-type-available-p)
1396 (image-type-available-p 'png))
1397 (and (featurep 'xemacs)
1400 "Display Face headers.
1401 Valid values are nil, t, `head', `first', `last', an integer or a
1402 predicate. See Info node `(gnus)Customizing Articles' and Info
1403 node `(gnus)X-Face' for details."
1404 :group 'gnus-article-treat
1406 :link '(custom-manual "(gnus)Customizing Articles")
1407 :link '(custom-manual "(gnus)X-Face")
1408 :type gnus-article-treat-head-custom)
1409 (put 'gnus-treat-display-face 'highlight t)
1411 (defcustom gnus-treat-display-smileys
1412 (if (and (not noninteractive)
1413 (or (and (featurep 'xemacs)
1415 (gnus-image-type-available-p 'xpm)
1416 (gnus-image-type-available-p 'pbm)
1417 (and (not (featurep 'xemacs))
1419 (module-installed-p 'smiley-mule))))
1423 Valid values are nil, t, `head', `first', `last', an integer or a
1424 predicate. See Info node `(gnus)Customizing Articles' and Info
1425 node `(gnus)Smileys' for details."
1426 :group 'gnus-article-treat
1428 :link '(custom-manual "(gnus)Customizing Articles")
1429 :link '(custom-manual "(gnus)Smileys")
1430 :type gnus-article-treat-custom)
1431 (put 'gnus-treat-display-smileys 'highlight t)
1433 (defcustom gnus-treat-from-picon
1434 (if (and (gnus-image-type-available-p 'xpm)
1435 (gnus-picons-installed-p))
1437 "Display picons in the From header.
1438 Valid values are nil, t, `head', `first', `last', an integer or a
1439 predicate. See Info node `(gnus)Customizing Articles' and Info
1440 node `(gnus)Picons' for details."
1442 :group 'gnus-article-treat
1444 :link '(custom-manual "(gnus)Customizing Articles")
1445 :link '(custom-manual "(gnus)Picons")
1446 :type gnus-article-treat-head-custom)
1447 (put 'gnus-treat-from-picon 'highlight t)
1449 (defcustom gnus-treat-mail-picon
1450 (if (and (gnus-image-type-available-p 'xpm)
1451 (gnus-picons-installed-p))
1453 "Display picons in To and Cc headers.
1454 Valid values are nil, t, `head', `first', `last', an integer or a
1455 predicate. See Info node `(gnus)Customizing Articles' and Info
1456 node `(gnus)Picons' for details."
1458 :group 'gnus-article-treat
1460 :link '(custom-manual "(gnus)Customizing Articles")
1461 :link '(custom-manual "(gnus)Picons")
1462 :type gnus-article-treat-head-custom)
1463 (put 'gnus-treat-mail-picon 'highlight t)
1465 (defcustom gnus-treat-newsgroups-picon
1466 (if (and (gnus-image-type-available-p 'xpm)
1467 (gnus-picons-installed-p))
1469 "Display picons in the Newsgroups and Followup-To headers.
1470 Valid values are nil, t, `head', `first', `last', an integer or a
1471 predicate. See Info node `(gnus)Customizing Articles' and Info
1472 node `(gnus)Picons' for details."
1474 :group 'gnus-article-treat
1476 :link '(custom-manual "(gnus)Customizing Articles")
1477 :link '(custom-manual "(gnus)Picons")
1478 :type gnus-article-treat-head-custom)
1479 (put 'gnus-treat-newsgroups-picon 'highlight t)
1481 (defcustom gnus-treat-body-boundary
1482 (if (and (eq window-system 'x)
1483 (or gnus-treat-newsgroups-picon
1484 gnus-treat-mail-picon
1485 gnus-treat-from-picon))
1487 "Draw a boundary at the end of the headers.
1488 Valid values are nil and `head'.
1489 See Info node `(gnus)Customizing Articles' for details."
1491 :group 'gnus-article-treat
1492 :link '(custom-manual "(gnus)Customizing Articles")
1493 :type gnus-article-treat-head-custom)
1495 (defcustom gnus-treat-capitalize-sentences nil
1496 "Capitalize sentence-starting words.
1497 Valid values are nil, t, `head', `first', `last', an integer or a
1498 predicate. See Info node `(gnus)Customizing Articles'."
1500 :group 'gnus-article-treat
1501 :link '(custom-manual "(gnus)Customizing Articles")
1502 :type gnus-article-treat-custom)
1504 (defcustom gnus-treat-wash-html nil
1506 Valid values are nil, t, `head', `first', `last', an integer or a
1507 predicate. See Info node `(gnus)Customizing Articles'."
1509 :group 'gnus-article-treat
1510 :link '(custom-manual "(gnus)Customizing Articles")
1511 :type gnus-article-treat-custom)
1513 (defcustom gnus-treat-fill-long-lines nil
1515 Valid values are nil, t, `head', `first', `last', an integer or a
1516 predicate. See Info node `(gnus)Customizing Articles'."
1517 :group 'gnus-article-treat
1518 :link '(custom-manual "(gnus)Customizing Articles")
1519 :type gnus-article-treat-custom)
1521 (defcustom gnus-treat-play-sounds nil
1523 Valid values are nil, t, `head', `first', `last', an integer or a
1524 predicate. See Info node `(gnus)Customizing Articles'."
1526 :group 'gnus-article-treat
1527 :link '(custom-manual "(gnus)Customizing Articles")
1528 :type gnus-article-treat-custom)
1530 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1531 "Decode an article as `default-mime-charset'. For instance, if you want to
1532 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1533 you could set this variable to something like: nil for don't decode, t for
1534 decode the body, '(or header t) for the whole article, etc."
1535 :group 'gnus-article-treat
1536 :type '(radio (const :tag "Off" nil)
1537 (const :tag "Decode body" t)
1538 (const :tag "Decode all" (or head t))))
1540 (defcustom gnus-treat-translate nil
1541 "Translate articles from one language to another.
1542 Valid values are nil, t, `head', `first', `last', an integer or a
1543 predicate. See Info node `(gnus)Customizing Articles'."
1545 :group 'gnus-article-treat
1546 :link '(custom-manual "(gnus)Customizing Articles")
1547 :type gnus-article-treat-custom)
1549 (defcustom gnus-treat-x-pgp-sig nil
1551 To automatically treat X-PGP-Sig, set it to head.
1552 Valid values are nil, t, `head', `first', `last', an integer or a
1553 predicate. See Info node `(gnus)Customizing Articles'."
1555 :group 'gnus-article-treat
1556 :group 'mime-security
1557 :type gnus-article-treat-custom)
1559 (defcustom gnus-treat-monafy nil
1560 "Display body part with mona font.
1561 Valid values are nil, t, `head', `last', an integer or a predicate.
1562 See Info node `(gnus)Customizing Articles' for details."
1563 :group 'gnus-article-treat
1564 :group 'mime-security
1565 :link '(custom-manual "(gnus)Customizing Articles")
1566 :type gnus-article-treat-custom)
1568 (defvar gnus-article-encrypt-protocol-alist
1569 '(("PGP" . mml2015-self-encrypt)))
1571 ;; Set to nil if more than one protocol added to
1572 ;; gnus-article-encrypt-protocol-alist.
1573 (defcustom gnus-article-encrypt-protocol "PGP"
1574 "The protocol used for encrypt articles.
1575 It is a string, such as \"PGP\". If nil, ask user."
1578 :group 'mime-security)
1580 (defvar gnus-article-wash-function nil
1581 "Function used for converting HTML into text.")
1583 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1584 (mm-coding-system-p 'utf-8)
1585 (executable-find idna-program))
1586 "Whether IDNA decoding of headers is used when viewing messages.
1587 This requires GNU Libidn, and by default only enabled if it is found."
1589 :group 'gnus-article-headers
1592 (defcustom gnus-article-over-scroll nil
1593 "If non-nil, allow scrolling the article buffer even when there no more text."
1595 :group 'gnus-article
1598 ;;; Internal variables
1600 (defvar gnus-english-month-names
1601 '("January" "February" "March" "April" "May" "June" "July" "August"
1602 "September" "October" "November" "December"))
1604 (defvar gnus-button-regexp nil)
1605 (defvar gnus-button-marker-list nil)
1606 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1608 (defvar gnus-button-last nil)
1609 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1611 (defvar article-goto-body-goes-to-point-min-p nil)
1612 (defvar gnus-article-wash-types nil)
1613 (defvar gnus-article-emphasis-alist nil)
1614 (defvar gnus-article-image-alist nil)
1616 (defvar gnus-article-mime-handle-alist-1 nil)
1617 (defvar gnus-treatment-function-alist
1618 '((gnus-treat-decode-article-as-default-mime-charset
1619 gnus-article-decode-article-as-default-mime-charset)
1620 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1621 (gnus-treat-monafy gnus-article-monafy)
1622 (gnus-treat-strip-banner gnus-article-strip-banner)
1623 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1624 (gnus-treat-buttonize gnus-article-add-buttons)
1625 (gnus-treat-fill-article gnus-article-fill-cited-article)
1626 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1627 (gnus-treat-strip-cr gnus-article-remove-cr)
1628 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1629 (gnus-treat-date-ut gnus-article-date-ut)
1630 (gnus-treat-date-local gnus-article-date-local)
1631 (gnus-treat-date-english gnus-article-date-english)
1632 (gnus-treat-date-original gnus-article-date-original)
1633 (gnus-treat-date-user-defined gnus-article-date-user)
1634 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1635 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1636 (gnus-treat-display-face gnus-article-display-face)
1637 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1638 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1639 (gnus-treat-hide-signature gnus-article-hide-signature)
1640 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1641 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1642 (gnus-treat-strip-pem gnus-article-hide-pem)
1643 (gnus-treat-from-picon gnus-treat-from-picon)
1644 (gnus-treat-mail-picon gnus-treat-mail-picon)
1645 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1646 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1647 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1648 (gnus-treat-strip-trailing-blank-lines
1649 gnus-article-remove-trailing-blank-lines)
1650 (gnus-treat-strip-leading-blank-lines
1651 gnus-article-strip-leading-blank-lines)
1652 (gnus-treat-strip-multiple-blank-lines
1653 gnus-article-strip-multiple-blank-lines)
1654 (gnus-treat-overstrike gnus-article-treat-overstrike)
1655 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1656 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1657 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1658 ;; Displaying X-Face should be done after unfolding headers
1659 ;; to protect bitmap lines.
1660 (gnus-treat-display-x-face gnus-article-display-x-face)
1661 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1662 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1663 (gnus-treat-display-smileys gnus-treat-smiley)
1664 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1665 (gnus-treat-wash-html gnus-article-wash-html)
1666 (gnus-treat-emphasize gnus-article-emphasize)
1667 (gnus-treat-hide-citation gnus-article-hide-citation)
1668 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1669 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1670 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1671 (gnus-treat-play-sounds gnus-earcon-display)))
1673 (defvar gnus-article-mime-handle-alist nil)
1674 (defvar article-lapsed-timer nil)
1675 (defvar gnus-article-current-summary nil)
1677 (defvar gnus-article-mode-syntax-table
1678 (let ((table (copy-syntax-table text-mode-syntax-table)))
1679 ;; This causes the citation match run O(2^n).
1680 ;; (modify-syntax-entry ?- "w" table)
1681 (modify-syntax-entry ?> ")<" table)
1682 (modify-syntax-entry ?< "(>" table)
1683 ;; make M-. in article buffers work for `foo' strings
1684 (modify-syntax-entry ?' " " table)
1685 (modify-syntax-entry ?` " " table)
1687 "Syntax table used in article mode buffers.
1688 Initialized from `text-mode-syntax-table.")
1690 (defvar gnus-save-article-buffer nil)
1692 (defvar gnus-article-mode-line-format-alist
1693 (nconc '((?w (gnus-article-wash-status) ?s)
1694 (?m (gnus-article-mime-part-status) ?s))
1695 gnus-summary-mode-line-format-alist))
1697 (defvar gnus-number-of-articles-to-be-saved nil)
1699 (defvar gnus-inhibit-hiding nil)
1701 (defvar gnus-article-edit-mode nil)
1703 ;;; Macros for dealing with the article buffer.
1705 (defmacro gnus-with-article-headers (&rest forms)
1707 (set-buffer gnus-article-buffer)
1709 (let ((inhibit-read-only t)
1710 (inhibit-point-motion-hooks t)
1711 (case-fold-search t))
1712 (article-narrow-to-head)
1715 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1716 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1718 (defmacro gnus-with-article-buffer (&rest forms)
1720 (set-buffer gnus-article-buffer)
1721 (let ((inhibit-read-only t))
1724 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1725 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1727 (defun gnus-article-goto-header (header)
1728 "Go to HEADER, which is a regular expression."
1729 (re-search-forward (concat "^\\(" header "\\):") nil t))
1731 (defsubst gnus-article-hide-text (b e props)
1732 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1733 (gnus-add-text-properties-when 'article-type nil b e props)
1734 (when (memq 'intangible props)
1736 (max (1- b) (point-min))
1737 b 'intangible (cddr (memq 'intangible props)))))
1739 (defsubst gnus-article-unhide-text (b e)
1740 "Remove hidden text properties from region between B and E."
1741 (remove-text-properties b e gnus-hidden-properties)
1742 (when (memq 'intangible gnus-hidden-properties)
1743 (put-text-property (max (1- b) (point-min))
1744 b 'intangible nil)))
1746 (defun gnus-article-hide-text-type (b e type)
1747 "Hide text of TYPE between B and E."
1748 (gnus-add-wash-type type)
1749 (gnus-article-hide-text
1750 b e (cons 'article-type (cons type gnus-hidden-properties))))
1752 (defun gnus-article-unhide-text-type (b e type)
1753 "Unhide text of TYPE between B and E."
1754 (gnus-delete-wash-type type)
1755 (remove-text-properties
1756 b e (cons 'article-type (cons type gnus-hidden-properties)))
1757 (when (memq 'intangible gnus-hidden-properties)
1758 (put-text-property (max (1- b) (point-min))
1759 b 'intangible nil)))
1761 (defun gnus-article-hide-text-of-type (type)
1762 "Hide text of TYPE in the current buffer."
1764 (let ((b (point-min))
1766 (while (setq b (text-property-any b e 'article-type type))
1767 (add-text-properties b (incf b) gnus-hidden-properties)))))
1769 (defun gnus-article-delete-text-of-type (type)
1770 "Delete text of TYPE in the current buffer."
1772 (let ((b (point-min)))
1773 (if (eq type 'multipart)
1774 ;; Remove MIME buttons associated with multipart/alternative parts.
1777 (while (if (get-text-property (point) 'gnus-part)
1779 (when (setq b (next-single-property-change (point)
1784 (skip-chars-forward "\n")
1785 (when (eq (get-text-property b 'article-type) 'multipart)
1786 (delete-region b (point)))))
1787 (while (setq b (text-property-any b (point-max) 'article-type type))
1789 b (or (text-property-not-all b (point-max) 'article-type type)
1792 (defun gnus-article-delete-invisible-text ()
1793 "Delete all invisible text in the current buffer."
1795 (let ((b (point-min)))
1796 (while (setq b (text-property-any b (point-max) 'invisible t))
1798 b (or (text-property-not-all b (point-max) 'invisible t)
1801 (defun gnus-article-text-type-exists-p (type)
1802 "Say whether any text of type TYPE exists in the buffer."
1803 (text-property-any (point-min) (point-max) 'article-type type))
1805 (defsubst gnus-article-header-rank ()
1806 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1807 (let ((list gnus-sorted-header-list)
1810 (if (looking-at (car list))
1812 (setq list (cdr list))
1816 (defun article-hide-headers (&optional arg delete)
1817 "Hide unwanted headers and possibly sort them as well."
1818 (interactive (gnus-article-hidden-arg))
1819 ;; Lars said that this function might be inhibited.
1820 (if (gnus-article-check-hidden-text 'headers arg)
1822 ;; Show boring headers as well.
1823 (gnus-article-show-hidden-text 'boring-headers)
1824 (when (eq 1 (point-min))
1825 (set-window-start (get-buffer-window (current-buffer)) 1)))
1826 (unless gnus-inhibit-hiding
1827 (let ((inhibit-read-only t)
1828 (case-fold-search t)
1829 (max (1+ (length gnus-sorted-header-list)))
1830 (inhibit-point-motion-hooks t)
1831 (cur (current-buffer))
1832 ignored visible beg)
1834 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1835 ;; group parameters, so we should go to the summary buffer.
1838 (progn (set-buffer gnus-summary-buffer) t)
1840 (setq ignored (when (not gnus-visible-headers)
1841 (cond ((stringp gnus-ignored-headers)
1842 gnus-ignored-headers)
1843 ((listp gnus-ignored-headers)
1844 (mapconcat 'identity
1845 gnus-ignored-headers
1847 visible (cond ((stringp gnus-visible-headers)
1848 gnus-visible-headers)
1849 ((and gnus-visible-headers
1850 (listp gnus-visible-headers))
1851 (mapconcat 'identity
1852 gnus-visible-headers
1856 ;; First we narrow to just the headers.
1857 (article-narrow-to-head)
1858 ;; Hide any "From " lines at the beginning of (mail) articles.
1859 (while (looking-at "From ")
1863 (delete-region (point-min) (point))
1864 (gnus-article-hide-text (point-min) (point)
1865 (nconc (list 'article-type 'headers)
1866 gnus-hidden-properties))))
1867 ;; Then treat the rest of the header lines.
1868 ;; Then we use the two regular expressions
1869 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1870 ;; select which header lines is to remain visible in the
1872 (while (re-search-forward "^[^ \t:]*:" nil t)
1874 ;; Mark the rank of the header.
1876 (point) (1+ (point)) 'message-rank
1877 (if (or (and visible (looking-at visible))
1879 (not (looking-at ignored))))
1880 (gnus-article-header-rank)
1883 (message-sort-headers-1)
1884 (when (setq beg (text-property-any
1885 (point-min) (point-max) 'message-rank (+ 2 max)))
1886 ;; We delete or make invisible the unwanted headers.
1887 (gnus-add-wash-type 'headers)
1890 (add-text-properties
1891 (point-min) (+ 5 (point-min))
1892 '(article-type headers dummy-invisible t))
1893 (delete-region beg (point-max)))
1894 (gnus-article-hide-text-type beg (point-max) 'headers)))))))))
1896 (defun article-hide-boring-headers (&optional arg)
1897 "Toggle hiding of headers that aren't very interesting.
1898 If given a negative prefix, always show; if given a positive prefix,
1900 (interactive (gnus-article-hidden-arg))
1901 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1902 (not gnus-show-all-headers))
1905 (let ((inhibit-read-only t)
1906 (inhibit-point-motion-hooks t))
1907 (article-narrow-to-head)
1908 (dolist (elem gnus-boring-article-headers)
1909 (goto-char (point-min))
1911 ;; Hide empty headers.
1913 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1915 (gnus-article-hide-text-type
1919 (if (re-search-forward "^[^ \t]" nil t)
1923 ;; Hide boring Newsgroups header.
1924 ((eq elem 'newsgroups)
1925 (when (gnus-string-equal
1926 (gnus-fetch-field "newsgroups")
1927 (gnus-group-real-name
1928 (if (boundp 'gnus-newsgroup-name)
1931 (gnus-article-hide-header "newsgroups")))
1932 ((eq elem 'to-address)
1933 (let ((to (message-fetch-field "to"))
1935 (gnus-parameter-to-address
1936 (if (boundp 'gnus-newsgroup-name)
1937 gnus-newsgroup-name ""))))
1938 (when (and to to-address
1941 ;; only one address in To
1942 (nth 1 (mail-extract-address-components to))
1944 (gnus-article-hide-header "to"))))
1946 (let ((to (message-fetch-field "to"))
1948 (gnus-parameter-to-list
1949 (if (boundp 'gnus-newsgroup-name)
1950 gnus-newsgroup-name ""))))
1951 (when (and to to-list
1954 ;; only one address in To
1955 (nth 1 (mail-extract-address-components to))
1957 (gnus-article-hide-header "to"))))
1959 (let ((cc (message-fetch-field "cc"))
1961 (gnus-parameter-to-list
1962 (if (boundp 'gnus-newsgroup-name)
1963 gnus-newsgroup-name ""))))
1964 (when (and cc to-list
1967 ;; only one address in CC
1968 (nth 1 (mail-extract-address-components cc))
1970 (gnus-article-hide-header "cc"))))
1971 ((eq elem 'followup-to)
1972 (when (gnus-string-equal
1973 (message-fetch-field "followup-to")
1974 (message-fetch-field "newsgroups"))
1975 (gnus-article-hide-header "followup-to")))
1976 ((eq elem 'reply-to)
1977 (if (gnus-group-find-parameter
1978 gnus-newsgroup-name 'broken-reply-to)
1979 (gnus-article-hide-header "reply-to")
1980 (let ((from (message-fetch-field "from"))
1981 (reply-to (message-fetch-field "reply-to")))
1988 (lambda (x) (downcase (cadr x)))
1989 (mail-extract-address-components from t))
1992 (lambda (x) (downcase (cadr x)))
1993 (mail-extract-address-components reply-to t))
1995 (gnus-article-hide-header "reply-to")))))
1997 (let ((date (message-fetch-field "date")))
1999 (< (days-between (current-time-string) date)
2001 (gnus-article-hide-header "date"))))
2003 (let ((to (message-fetch-field "to"))
2004 (cc (message-fetch-field "cc")))
2005 (when (> (length to) 1024)
2006 (gnus-article-hide-header "to"))
2007 (when (> (length cc) 1024)
2008 (gnus-article-hide-header "cc"))))
2012 (goto-char (point-min))
2013 (while (re-search-forward "^to:" nil t)
2014 (setq to-count (1+ to-count)))
2015 (when (> to-count 1)
2016 (while (> to-count 0)
2017 (goto-char (point-min))
2019 (re-search-forward "^to:" nil nil to-count)
2021 (narrow-to-region (point) (point-max))
2022 (gnus-article-hide-header "to"))
2023 (setq to-count (1- to-count))))
2024 (goto-char (point-min))
2025 (while (re-search-forward "^cc:" nil t)
2026 (setq cc-count (1+ cc-count)))
2027 (when (> cc-count 1)
2028 (while (> cc-count 0)
2029 (goto-char (point-min))
2031 (re-search-forward "^cc:" nil nil cc-count)
2033 (narrow-to-region (point) (point-max))
2034 (gnus-article-hide-header "cc"))
2035 (setq cc-count (1- cc-count)))))))))))))
2037 (defun gnus-article-hide-header (header)
2039 (goto-char (point-min))
2040 (when (re-search-forward (concat "^" header ":") nil t)
2041 (gnus-article-hide-text-type
2045 (if (re-search-forward "^[^ \t]" nil t)
2050 (defvar gnus-article-normalized-header-length 40
2051 "Length of normalized headers.")
2053 (defun article-normalize-headers ()
2054 "Make all header lines 40 characters long."
2056 (let ((inhibit-read-only t)
2060 (article-narrow-to-head)
2063 ((< (setq column (- (point-at-eol) (point)))
2064 gnus-article-normalized-header-length)
2066 (insert (make-string
2067 (- gnus-article-normalized-header-length column)
2069 ((> column gnus-article-normalized-header-length)
2070 (gnus-put-text-property
2072 (forward-char gnus-article-normalized-header-length)
2079 (forward-line 1))))))
2081 (defun article-treat-dumbquotes ()
2082 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2083 Note that this function guesses whether a character is a sm*rtq**t* or
2084 not, so it should only be used interactively.
2086 Sm*rtq**t*s are M****s***'s unilateral extension to the
2087 iso-8859-1 character map in an attempt to provide more quoting
2088 characters. If you see something like \\222 or \\264 where
2089 you're expecting some kind of apostrophe or quotation mark, then
2092 (article-translate-strings gnus-article-dumbquotes-map))
2094 (defun article-translate-characters (from to)
2095 "Translate all characters in the body of the article according to FROM and TO.
2096 FROM is a string of characters to translate from; to is a string of
2097 characters to translate to."
2099 (when (article-goto-body)
2100 (let ((inhibit-read-only t)
2101 (x (make-string 225 ?x))
2103 (while (< (incf i) (length x))
2106 (while (< i (length from))
2107 (aset x (aref from i) (aref to i))
2109 (translate-region (point) (point-max) x)))))
2111 (defun article-translate-strings (map)
2112 "Translate all string in the body of the article according to MAP.
2113 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2115 (when (article-goto-body)
2116 (let ((inhibit-read-only t))
2119 (while (search-forward (car elem) nil t)
2120 (replace-match (cadr elem)))))))))
2122 (defun article-treat-overstrike ()
2123 "Translate overstrikes into bold text."
2126 (when (article-goto-body)
2127 (let ((inhibit-read-only t))
2128 (while (search-forward "\b" nil t)
2129 (let ((next (char-after))
2133 previous (char-after))
2137 ;; We do the boldification/underlining by hiding the
2138 ;; overstrikes and putting the proper text property
2142 (gnus-article-hide-text-type start (point) 'overstrike)
2143 (put-text-property (point) end 'face 'bold))
2145 (gnus-article-hide-text-type
2146 (1- (point)) (1+ (point)) 'overstrike)
2148 start (1- (point)) 'face 'underline))
2150 (gnus-article-hide-text-type start (point) 'overstrike)
2152 (point) end 'face 'underline)))))))))
2154 (defun article-treat-ansi-sequences ()
2155 "Translate ANSI SGR control sequences into overlays or extents."
2158 (when (article-goto-body)
2159 (let ((inhibit-read-only t))
2160 (ansi-color-apply-on-region (point) (point-max))))))
2162 (defun gnus-article-treat-unfold-headers ()
2163 "Unfold folded message headers.
2164 Only the headers that fit into the current window width will be
2167 (gnus-with-article-headers
2171 (mail-header-narrow-to-field)
2172 (let ((header (buffer-string)))
2175 (goto-char (point-min))
2176 (while (re-search-forward "\n[\t ]" nil t)
2177 (replace-match " " t t)))
2178 (setq length (- (point-max) (point-min) 1)))
2179 (when (< length (window-width))
2180 (while (re-search-forward "\n[\t ]" nil t)
2181 (replace-match " " t t)))
2182 (goto-char (point-max)))))))
2184 (defun gnus-article-treat-fold-headers ()
2185 "Fold message headers."
2187 (gnus-with-article-headers
2190 (mail-header-narrow-to-field)
2191 (mail-header-fold-field)
2192 (goto-char (point-max))))))
2194 (defun gnus-treat-smiley ()
2195 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2197 (unless (featurep 'xemacs)
2198 (when (and (not gnus-article-should-use-smiley-mule)
2199 gnus-article-smiley-mule-loaded-p)
2200 (load "smiley" nil t)
2201 (setq gnus-article-smiley-mule-loaded-p nil))
2202 (when (and gnus-article-should-use-smiley-mule
2203 (not gnus-article-smiley-mule-loaded-p))
2204 (load "smiley-mule" nil t)
2205 (setq gnus-article-smiley-mule-loaded-p t)))
2206 (gnus-with-article-buffer
2207 (if (memq 'smiley gnus-article-wash-types)
2208 (gnus-delete-images 'smiley)
2210 (let ((images (smiley-region (point) (point-max))))
2212 (gnus-add-wash-type 'smiley)
2213 (dolist (image images)
2214 (gnus-add-image 'smiley image)))))))
2216 (defun gnus-article-remove-images ()
2217 "Remove all images from the article buffer."
2219 (gnus-with-article-buffer
2220 (dolist (elem gnus-article-image-alist)
2221 (gnus-delete-images (car elem)))))
2223 (defun gnus-article-treat-fold-newsgroups ()
2224 "Unfold folded message headers.
2225 Only the headers that fit into the current window width will be
2228 (gnus-with-article-headers
2229 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2231 (mail-header-narrow-to-field)
2232 (while (re-search-forward ", *" nil t)
2233 (replace-match ", " t t))
2234 (mail-header-fold-field)
2235 (goto-char (point-max))))))
2237 (defun gnus-article-treat-body-boundary ()
2238 "Place a boundary line at the end of the headers."
2240 (when (and gnus-body-boundary-delimiter
2241 (> (length gnus-body-boundary-delimiter) 0))
2242 (gnus-with-article-headers
2243 (goto-char (point-max))
2244 (let ((start (point)))
2245 (insert "X-Boundary: ")
2246 (gnus-add-text-properties start (point) '(invisible t intangible t))
2248 (while (>= (1- (window-width)) (length str))
2249 (setq str (concat str gnus-body-boundary-delimiter)))
2250 (substring str 0 (1- (window-width))))
2252 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2254 (defun article-fill-long-lines ()
2255 "Fill lines that are wider than the window width."
2258 (let ((inhibit-read-only t)
2259 (width (window-width (get-buffer-window (current-buffer)))))
2262 (let ((adaptive-fill-mode nil)) ;Why? -sm
2265 (when (>= (current-column) (min fill-column width))
2266 (narrow-to-region (min (1+ (point)) (point-max))
2268 (let ((goback (point-marker)))
2269 (fill-paragraph nil)
2270 (goto-char (marker-position goback)))
2272 (forward-line 1)))))))
2274 (defun article-capitalize-sentences ()
2275 "Capitalize the first word in each sentence."
2278 (let ((inhibit-read-only t)
2279 (paragraph-start "^[\n\^L]"))
2283 (forward-sentence)))))
2285 (defun article-remove-cr ()
2286 "Remove trailing CRs and then translate remaining CRs into LFs."
2289 (let ((inhibit-read-only t))
2290 (goto-char (point-min))
2291 (while (re-search-forward "\r+$" nil t)
2292 (replace-match "" t t))
2293 (goto-char (point-min))
2294 (while (search-forward "\r" nil t)
2295 (replace-match "\n" t t)))))
2297 (defun article-remove-trailing-blank-lines ()
2298 "Remove all trailing blank lines from the article."
2301 (let ((inhibit-read-only t))
2302 (goto-char (point-max))
2306 (while (and (not (bobp))
2307 (looking-at "^[ \t]*$")
2308 (not (gnus-annotation-in-region-p
2309 (point) (point-at-eol))))
2315 (defvar gnus-face-properties-alist))
2317 (defun article-display-face ()
2318 "Display any Face headers in the header."
2320 (let ((wash-face-p buffer-read-only))
2321 (gnus-with-article-headers
2322 ;; When displaying parts, this function can be called several times on
2323 ;; the same article, without any intended toggle semantic (as typing `W
2324 ;; D d' would have). So face deletion must occur only when we come from
2325 ;; an interactive command, that is when the *Article* buffer is
2327 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2328 (gnus-delete-images 'face)
2329 (let (face faces from)
2330 (save-current-buffer
2331 (when (and wash-face-p
2332 (gnus-buffer-live-p gnus-original-article-buffer)
2333 (not (re-search-forward "^Face:[\t ]*" nil t)))
2334 (set-buffer gnus-original-article-buffer))
2336 (mail-narrow-to-head)
2337 (while (gnus-article-goto-header "Face")
2338 (push (mail-header-field-value) faces))))
2340 (goto-char (point-min))
2341 (let ((from (gnus-article-goto-header "from"))
2346 (insert "[no `from' set]\n"))
2348 (when (setq png (gnus-convert-face-to-png (pop faces)))
2350 (apply 'gnus-create-image png 'png t
2351 (cdr (assq 'png gnus-face-properties-alist))))
2353 (gnus-add-wash-type 'face)
2354 (gnus-add-image 'face image)
2355 (gnus-put-image image nil 'face))))))))))
2357 (defun article-display-x-face (&optional force)
2358 "Look for an X-Face header and display it if present."
2359 (interactive (list 'force))
2360 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2361 (gnus-with-article-headers
2362 ;; Delete the old process, if any.
2363 (when (process-status "article-x-face")
2364 (delete-process "article-x-face"))
2365 ;; See the comment in `article-display-face'.
2366 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2367 ;; We have already displayed X-Faces, so we remove them
2369 (gnus-delete-images 'xface)
2371 (let (x-faces from face)
2372 (save-current-buffer
2373 (when (and wash-face-p
2374 (gnus-buffer-live-p gnus-original-article-buffer)
2375 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2376 ;; If type `W f', use gnus-original-article-buffer,
2377 ;; otherwise use the current buffer because displaying
2378 ;; RFC822 parts calls this function too.
2379 (set-buffer gnus-original-article-buffer))
2381 (mail-narrow-to-head)
2382 (while (gnus-article-goto-header "X-Face")
2383 (push (mail-header-field-value) x-faces))
2384 (setq from (message-fetch-field "from"))))
2385 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2386 ;; single external face.
2387 (when (stringp gnus-article-x-face-command)
2388 (setq x-faces (list (car x-faces))))
2390 gnus-article-x-face-command
2392 ;; Check whether this face is censored.
2393 (not gnus-article-x-face-too-ugly)
2395 (not (string-match gnus-article-x-face-too-ugly
2397 (while (setq face (pop x-faces))
2398 ;; We display the face.
2399 (cond ((stringp gnus-article-x-face-command)
2400 ;; The command is a string, so we interpret the command
2401 ;; as a, well, command, and fork it off.
2402 (let ((process-connection-type nil))
2403 (gnus-set-process-query-on-exit-flag
2405 "article-x-face" nil shell-file-name
2406 shell-command-switch gnus-article-x-face-command)
2410 (process-send-region "article-x-face"
2411 (point-min) (point-max)))
2412 (process-send-eof "article-x-face")))
2413 ((functionp gnus-article-x-face-command)
2414 ;; The command is a lisp function, so we call it.
2415 (funcall gnus-article-x-face-command face))
2417 (error "%s is not a function"
2418 gnus-article-x-face-command))))))))))
2420 (defun article-decode-mime-words ()
2421 "Decode all MIME-encoded words in the article."
2423 (gnus-with-article-buffer
2424 (let ((inhibit-point-motion-hooks t)
2425 (mail-parse-charset gnus-newsgroup-charset)
2426 (mail-parse-ignored-charsets
2427 (with-current-buffer gnus-summary-buffer
2428 gnus-newsgroup-ignored-charsets)))
2429 (mail-decode-encoded-word-region (point-min) (point-max)))))
2431 (defun article-decode-charset (&optional prompt)
2432 "Decode charset-encoded text in the article.
2433 If PROMPT (the prefix), prompt for a coding system to use."
2435 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2436 (inhibit-read-only t)
2437 (mail-parse-charset gnus-newsgroup-charset)
2438 (mail-parse-ignored-charsets
2439 (save-excursion (condition-case nil
2440 (set-buffer gnus-summary-buffer)
2442 gnus-newsgroup-ignored-charsets))
2443 ct cte ctl charset format)
2446 (article-narrow-to-head)
2447 (setq ct (message-fetch-field "Content-Type" t)
2448 cte (message-fetch-field "Content-Transfer-Encoding" t)
2449 ctl (and ct (mail-header-parse-content-type ct))
2452 (mm-read-coding-system "Charset to decode: "))
2454 (mail-content-type-get ctl 'charset)))
2455 format (and ctl (mail-content-type-get ctl 'format)))
2457 (setq cte (mail-header-strip cte)))
2458 (if (and ctl (not (string-match "/" (car ctl))))
2460 (goto-char (point-max)))
2463 (narrow-to-region (point) (point-max))
2464 (when (and (eq mail-parse-charset 'gnus-decoded)
2465 (eq (mm-body-7-or-8) '8bit))
2466 ;; The text code could have been decoded.
2467 (setq charset mail-parse-charset))
2468 (when (and (or (not ctl)
2469 (equal (car ctl) "text/plain"))
2470 (not format)) ;; article with format will decode later.
2472 charset (and cte (intern (downcase
2473 (gnus-strip-whitespace cte))))
2476 (defun article-decode-encoded-words ()
2477 "Remove encoded-word encoding from headers."
2478 (let ((charset (save-excursion
2479 (set-buffer gnus-summary-buffer)
2480 default-mime-charset))
2481 (inhibit-read-only t))
2482 (mime-decode-header-in-buffer charset)))
2484 (defun article-decode-group-name ()
2485 "Decode group names in `Newsgroups:'."
2486 (let ((inhibit-point-motion-hooks t)
2487 (inhibit-read-only t)
2488 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2489 (when (and (or gnus-group-name-charset-method-alist
2490 gnus-group-name-charset-group-alist)
2491 (gnus-buffer-live-p gnus-original-article-buffer))
2493 (article-narrow-to-head)
2494 (with-current-buffer gnus-original-article-buffer
2495 (goto-char (point-min)))
2496 (while (re-search-forward
2497 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2498 (replace-match (save-match-data
2499 (gnus-decode-newsgroups
2500 ;; XXX how to use data in article buffer?
2501 (with-current-buffer gnus-original-article-buffer
2503 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2506 gnus-newsgroup-name method))
2508 (goto-char (point-min))
2509 (with-current-buffer gnus-original-article-buffer
2510 (goto-char (point-min)))
2511 (while (re-search-forward
2512 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2513 (replace-match (save-match-data
2514 (gnus-decode-newsgroups
2515 ;; XXX how to use data in article buffer?
2516 (with-current-buffer gnus-original-article-buffer
2518 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2521 gnus-newsgroup-name method))
2524 (autoload 'idna-to-unicode "idna")
2526 (defun article-decode-idna-rhs ()
2527 "Decode IDNA strings in RHS in various headers in current buffer.
2528 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2529 Mail-Reply-To: and Mail-Followup-To:."
2532 (let ((inhibit-point-motion-hooks t)
2533 (inhibit-read-only t))
2534 (article-narrow-to-head)
2535 (goto-char (point-min))
2536 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2538 (when (save-match-data
2539 (and (setq ace (match-string 1))
2541 (and (re-search-backward "^[^ \t]" nil t)
2542 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2543 (setq unicode (idna-to-unicode ace))))
2544 (unless (string= ace unicode)
2545 (replace-match unicode nil nil nil 1)))))))))
2547 (defun article-de-quoted-unreadable (&optional force read-charset)
2548 "Translate a quoted-printable-encoded article.
2549 If FORCE, decode the article whether it is marked as quoted-printable
2551 If READ-CHARSET, ask for a coding system."
2552 (interactive (list 'force current-prefix-arg))
2554 (let ((inhibit-read-only t) type charset)
2555 (if (gnus-buffer-live-p gnus-original-article-buffer)
2556 (with-current-buffer gnus-original-article-buffer
2558 (gnus-fetch-field "content-transfer-encoding"))
2559 (let* ((ct (gnus-fetch-field "content-type"))
2560 (ctl (and ct (mail-header-parse-content-type ct))))
2561 (setq charset (and ctl
2562 (mail-content-type-get ctl 'charset)))
2563 (if (stringp charset)
2564 (setq charset (intern (downcase charset)))))))
2566 (setq charset (mm-read-coding-system "Charset: " charset)))
2568 (setq charset gnus-newsgroup-charset))
2570 (and type (let ((case-fold-search t))
2571 (string-match "quoted-printable" type))))
2573 (quoted-printable-decode-region
2574 (point) (point-max) (mm-charset-to-coding-system charset))))))
2576 (defun article-de-base64-unreadable (&optional force read-charset)
2577 "Translate a base64 article.
2578 If FORCE, decode the article whether it is marked as base64 not.
2579 If READ-CHARSET, ask for a coding system."
2580 (interactive (list 'force current-prefix-arg))
2582 (let ((inhibit-read-only t) type charset)
2583 (if (gnus-buffer-live-p gnus-original-article-buffer)
2584 (with-current-buffer gnus-original-article-buffer
2586 (gnus-fetch-field "content-transfer-encoding"))
2587 (let* ((ct (gnus-fetch-field "content-type"))
2588 (ctl (and ct (mail-header-parse-content-type ct))))
2589 (setq charset (and ctl
2590 (mail-content-type-get ctl 'charset)))
2591 (if (stringp charset)
2592 (setq charset (intern (downcase charset)))))))
2594 (setq charset (mm-read-coding-system "Charset: " charset)))
2596 (setq charset gnus-newsgroup-charset))
2598 (and type (let ((case-fold-search t))
2599 (string-match "base64" type))))
2602 (narrow-to-region (point) (point-max))
2603 (base64-decode-region (point-min) (point-max))
2604 (mm-decode-coding-region
2605 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2610 (defun article-decode-HZ ()
2611 "Translate a HZ-encoded article."
2615 (let ((inhibit-read-only t))
2616 (rfc1843-decode-region (point-min) (point-max)))))
2618 (defun article-unsplit-urls ()
2619 "Remove the newlines that some other mailers insert into URLs."
2622 (let ((inhibit-read-only t))
2623 (goto-char (point-min))
2624 (while (re-search-forward
2625 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2626 (replace-match "\\1\\3" t)))
2627 (when (interactive-p)
2628 (gnus-treat-article nil))))
2631 (defun article-wash-html (&optional read-charset)
2632 "Format an HTML article.
2633 If READ-CHARSET, ask for a coding system. If it is a number, the
2634 charset defined in `gnus-summary-show-article-charset-alist' is used."
2637 (let ((inhibit-read-only t)
2640 (if (or (and (numberp read-charset)
2644 gnus-summary-show-article-charset-alist))))
2645 (setq charset (mm-read-coding-system "Charset: ")))
2646 (let ((gnus-summary-show-article-charset-alist
2647 (list (cons 1 charset))))
2648 (with-current-buffer gnus-summary-buffer
2649 (gnus-summary-show-article 1)))
2650 (error "No charset is given"))
2651 (when (gnus-buffer-live-p gnus-original-article-buffer)
2652 (with-current-buffer gnus-original-article-buffer
2653 (let* ((ct (gnus-fetch-field "content-type"))
2654 (ctl (and ct (mail-header-parse-content-type ct))))
2655 (setq charset (and ctl
2656 (mail-content-type-get ctl 'charset)))
2657 (when (stringp charset)
2658 (setq charset (intern (downcase charset)))))))
2660 (setq charset gnus-newsgroup-charset)))
2662 (save-window-excursion
2664 (narrow-to-region (point) (point-max))
2665 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2666 (entry (assq func mm-text-html-washer-alist)))
2668 (setq func (cdr entry)))
2673 (apply (car func) (cdr func))))))))))
2675 (defun gnus-article-wash-html-with-w3 ()
2676 "Wash the current buffer with w3."
2678 (let ((w3-strict-width (window-width))
2679 (url-standalone-mode t)
2680 (url-gateway-unplugged t)
2681 (w3-honor-stylesheets nil))
2683 (w3-region (point-min) (point-max))
2686 (defun gnus-article-wash-html-with-w3m ()
2687 "Wash the current buffer with emacs-w3m."
2689 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2690 w3m-force-redisplay)
2691 (w3m-region (point-min) (point-max)))
2692 (when (and mm-inline-text-html-with-w3m-keymap
2693 (boundp 'w3m-minor-mode-map)
2695 (add-text-properties
2696 (point-min) (point-max)
2697 (list 'keymap w3m-minor-mode-map
2698 ;; Put the mark meaning this part was rendered by emacs-w3m.
2699 'mm-inline-text-html-with-w3m t))))
2701 (eval-when-compile (defvar charset)) ;; Bound by `article-wash-html'.
2703 (defun gnus-article-wash-html-with-w3m-standalone ()
2704 "Wash the current buffer with w3m."
2705 (if (mm-w3m-standalone-supports-m17n-p)
2707 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2709 (setq charset 'iso-8859-1))
2710 (let ((coding-system-for-write charset)
2711 (coding-system-for-read charset))
2712 (call-process-region
2713 (point-min) (point-max)
2714 "w3m" t t nil "-dump" "-T" "text/html"
2715 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2716 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2718 (defun article-hide-list-identifiers ()
2719 "Remove list identifies from the Subject header.
2720 The `gnus-list-identifiers' variable specifies what to do."
2722 (let ((inhibit-point-motion-hooks t)
2723 (regexp (if (consp gnus-list-identifiers)
2724 (mapconcat 'identity gnus-list-identifiers " *\\|")
2725 gnus-list-identifiers))
2726 (inhibit-read-only t))
2730 (article-narrow-to-head)
2731 (goto-char (point-min))
2732 (while (re-search-forward
2733 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2735 (delete-region (match-beginning 2) (match-end 0))
2736 (beginning-of-line))
2737 (when (re-search-forward
2738 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2739 (delete-region (match-beginning 1) (match-end 1))))))))
2741 (defun article-hide-pem (&optional arg)
2742 "Toggle hiding of any PEM headers and signatures in the current article.
2743 If given a negative prefix, always show; if given a positive prefix,
2745 (interactive (gnus-article-hidden-arg))
2746 (unless (gnus-article-check-hidden-text 'pem arg)
2748 (let ((inhibit-read-only t) end)
2749 (goto-char (point-min))
2750 ;; Hide the horrendously ugly "header".
2751 (when (and (search-forward
2752 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2754 (setq end (1+ (match-beginning 0))))
2755 (gnus-add-wash-type 'pem)
2756 (gnus-article-hide-text-type
2758 (if (search-forward "\n\n" nil t)
2762 ;; Hide the trailer as well
2763 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2765 (gnus-article-hide-text-type
2766 (match-beginning 0) (match-end 0) 'pem)))))))
2768 (defun article-strip-banner ()
2769 "Strip the banners specified by the `banner' group parameter and by
2770 `gnus-article-address-banner-alist'."
2774 (let ((inhibit-point-motion-hooks t))
2775 (when (gnus-parameter-banner gnus-newsgroup-name)
2776 (article-really-strip-banner
2777 (gnus-parameter-banner gnus-newsgroup-name)))
2778 (when gnus-article-address-banner-alist
2779 ;; It is necessary to encode from fields before checking,
2780 ;; because `mail-header-parse-addresses' does not work
2781 ;; (reliably) on decoded headers. And more, it is
2782 ;; impossible to use `gnus-fetch-original-field' here,
2783 ;; because `article-strip-banner' may be called in draft
2784 ;; buffers to preview them.
2785 (let ((from (save-restriction
2787 (article-narrow-to-head)
2788 (mail-fetch-field "from"))))
2791 (caar (mail-header-parse-addresses
2792 (mail-encode-encoded-word-string from)))))
2794 (dolist (pair gnus-article-address-banner-alist)
2795 (when (string-match (car pair) from)
2797 (article-really-strip-banner (cdr pair)))))))))))))
2799 (defun article-really-strip-banner (banner)
2800 "Strip the banner specified by the argument."
2803 (let ((inhibit-point-motion-hooks t)
2804 (gnus-signature-limit nil)
2805 (inhibit-read-only t))
2808 ((eq banner 'signature)
2809 (when (gnus-article-narrow-to-signature)
2812 (delete-region (point) (point-max))))
2814 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2815 (while (re-search-forward banner nil t)
2816 (delete-region (match-beginning 0) (match-end 0)))))
2818 (while (re-search-forward banner nil t)
2819 (delete-region (match-beginning 0) (match-end 0)))))))))
2821 (defun article-babel ()
2822 "Translate article using an online translation service."
2825 (gnus-with-article-buffer
2826 (when (article-goto-body)
2827 (let* ((start (point))
2829 (orig (buffer-substring start end))
2830 (trans (babel-as-string orig)))
2832 (narrow-to-region start end)
2833 (delete-region start end)
2836 (defun article-hide-signature (&optional arg)
2837 "Hide the signature in the current article.
2838 If given a negative prefix, always show; if given a positive prefix,
2840 (interactive (gnus-article-hidden-arg))
2846 (article-goto-body))
2847 (goto-char (point-min)))
2848 (unless (gnus-article-check-hidden-text 'signature arg)
2849 (let ((inhibit-read-only t)
2851 (while (setq button (text-property-any button (point-max)
2853 'gnus-signature-toggle))
2854 (setq button (text-property-not-all button (point-max)
2856 'gnus-signature-toggle))
2857 (when (and button (not (eobp)))
2858 (gnus-article-hide-text-type
2860 (next-single-property-change (1+ button) 'mime-view-entity
2863 (gnus-set-mode-line 'article))
2865 (defun article-strip-headers-in-body ()
2866 "Strip offensive headers from bodies."
2870 (let ((case-fold-search t))
2871 (when (looking-at "x-no-archive:")
2872 (gnus-delete-line)))))
2874 (defun article-strip-leading-blank-lines ()
2875 "Remove all blank lines from the beginning of the article."
2878 (let ((inhibit-point-motion-hooks t)
2879 (inhibit-read-only t))
2880 (when (article-goto-body)
2881 (while (and (not (eobp))
2882 (looking-at "[ \t]*$"))
2883 (gnus-delete-line))))))
2885 (defun article-narrow-to-head ()
2886 "Narrow the buffer to the head of the message.
2887 Point is left at the beginning of the narrowed-to region."
2889 (goto-char (point-min))
2890 (if (search-forward "\n\n" nil 1)
2893 (goto-char (point-min)))
2895 (defun article-goto-body ()
2896 "Place point at the start of the body."
2897 (goto-char (point-min))
2899 ;; This variable is only bound when dealing with separate
2901 (article-goto-body-goes-to-point-min-p
2903 ((search-forward "\n\n" nil t)
2906 (goto-char (point-max))
2909 (defun article-strip-multiple-blank-lines ()
2910 "Replace consecutive blank lines with one empty line."
2913 (let ((inhibit-point-motion-hooks t)
2914 (inhibit-read-only t))
2915 ;; First make all blank lines empty.
2917 (while (re-search-forward "^[ \t]+$" nil t)
2918 (unless (gnus-annotation-in-region-p
2919 (match-beginning 0) (match-end 0))
2920 (replace-match "" nil t)))
2921 ;; Then replace multiple empty lines with a single empty line.
2923 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2924 (unless (gnus-annotation-in-region-p
2925 (match-beginning 0) (match-end 0))
2926 (delete-region (match-beginning 1) (match-end 1)))))))
2928 (defun article-strip-leading-space ()
2929 "Remove all white space from the beginning of the lines in the article."
2932 (let ((inhibit-point-motion-hooks t)
2933 (inhibit-read-only t))
2935 (while (re-search-forward "^[ \t]+" nil t)
2936 (replace-match "" t t)))))
2938 (defun article-strip-trailing-space ()
2939 "Remove all white space from the end of the lines in the article."
2942 (let ((inhibit-point-motion-hooks t)
2943 (inhibit-read-only t))
2945 (while (re-search-forward "[ \t]+$" nil t)
2946 (replace-match "" t t)))))
2948 (defun article-strip-blank-lines ()
2949 "Strip leading, trailing and multiple blank lines."
2951 (article-strip-leading-blank-lines)
2952 (article-remove-trailing-blank-lines)
2953 (article-strip-multiple-blank-lines))
2955 (defun article-strip-all-blank-lines ()
2956 "Strip all blank lines."
2959 (let ((inhibit-point-motion-hooks t)
2960 (inhibit-read-only t))
2962 (while (re-search-forward "^[ \t]*\n" nil t)
2963 (replace-match "" t t)))))
2965 (defun gnus-article-narrow-to-signature ()
2966 "Narrow to the signature; return t if a signature is found, else nil."
2967 (let ((inhibit-point-motion-hooks t))
2968 (when (gnus-article-search-signature)
2970 ;; Check whether we have some limits to what we consider
2971 ;; to be a signature.
2972 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2973 (list gnus-signature-limit)))
2975 (while (setq limit (pop limits))
2976 (if (or (and (integerp limit)
2977 (< (- (point-max) (point)) limit))
2979 (< (count-lines (point) (point-max)) limit))
2980 (and (functionp limit)
2982 (and (stringp limit)
2983 (not (re-search-forward limit nil t))))
2984 () ; This limit did not succeed.
2988 (narrow-to-region (point) (point-max))
2991 (defun gnus-article-search-signature ()
2992 "Search the current buffer for the signature separator.
2993 Put point at the beginning of the signature separator."
2994 (let ((cur (point)))
2995 (goto-char (point-max))
2996 (if (if (stringp gnus-signature-separator)
2997 (re-search-backward gnus-signature-separator nil t)
2998 (let ((seps gnus-signature-separator))
3000 (not (re-search-backward (car seps) nil t)))
3007 (defun gnus-article-hidden-arg ()
3008 "Return the current prefix arg as a number, or 0 if no prefix."
3009 (list (if current-prefix-arg
3010 (prefix-numeric-value current-prefix-arg)
3013 (defun gnus-article-check-hidden-text (type arg)
3014 "Return nil if hiding is necessary.
3015 Arg can be nil or a number. nil and positive means hide, negative
3016 means show, 0 means toggle."
3019 (let ((hide (gnus-article-hidden-text-p type)))
3025 (gnus-article-show-hidden-text type)
3028 (if (eq hide 'hidden)
3030 (gnus-article-show-hidden-text type)
3034 (defun gnus-article-hidden-text-p (type)
3035 "Say whether the current buffer contains hidden text of type TYPE."
3036 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3038 (not (get-text-property pos 'invisible))
3039 (not (get-text-property pos 'dummy-invisible)))
3041 (text-property-any (1+ pos) (point-max) 'article-type type)))
3046 (defun gnus-article-show-hidden-text (type &optional dummy)
3047 "Show all hidden text of type TYPE.
3048 Originally it is hide instead of DUMMY."
3049 (let ((inhibit-read-only t)
3050 (inhibit-point-motion-hooks t))
3051 (gnus-remove-text-properties-when
3053 (point-min) (point-max)
3054 (cons 'article-type (cons type
3055 gnus-hidden-properties)))
3056 (gnus-delete-wash-type type)))
3058 (defconst article-time-units
3059 `((year . ,(* 365.25 24 60 60))
3060 (week . ,(* 7 24 60 60))
3061 (day . ,(* 24 60 60))
3065 "Mapping from time units to seconds.")
3067 (defun gnus-article-forward-header ()
3068 "Move point to the start of the next header.
3069 If the current header is a continuation header, this can be several
3074 (if (looking-at "[ \t]+[^ \t]")
3078 (defun article-date-ut (&optional type highlight)
3079 "Convert DATE date to universal time in the current article.
3080 If TYPE is `local', convert to local time; if it is `lapsed', output
3081 how much time has lapsed since DATE. For `lapsed', the value of
3082 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3083 should replace the \"Date:\" one, or should be added below it."
3084 (interactive (list 'ut t))
3085 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3086 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3090 (article-lapsed-timer
3094 (case-fold-search t)
3095 (inhibit-read-only t)
3096 (inhibit-point-motion-hooks t)
3097 pos date bface eface)
3101 (goto-char (point-min))
3102 (while (or (setq date (get-text-property (setq pos (point))
3104 (when (setq pos (next-single-property-change
3105 (point) 'original-date))
3106 (setq date (get-text-property pos 'original-date))
3108 (narrow-to-region pos (or (text-property-any pos (point-max)
3111 (goto-char (point-min))
3112 (when (re-search-forward tdate-regexp nil t)
3113 (setq bface (get-text-property (point-at-bol) 'face)
3114 eface (get-text-property (1- (point-at-eol)) 'face)))
3115 (goto-char (point-min))
3117 ;; Delete any old Date headers.
3118 (while (re-search-forward date-regexp nil t)
3120 (delete-region (point-at-bol) (progn
3121 (gnus-article-forward-header)
3123 (delete-region (point-at-bol) (progn
3124 (gnus-article-forward-header)
3127 (setq pos (point))))
3128 (when (and (not pos)
3129 (re-search-forward tdate-regexp nil t))
3131 (gnus-goto-char pos)
3132 (insert (article-make-date-line date (or type 'ut)))
3138 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3139 (put-text-property (match-beginning 1) (1+ (match-end 1))
3141 (put-text-property (match-beginning 2) (match-end 2)
3143 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3144 (goto-char (point-max))
3147 (defun article-make-date-line (date type)
3148 "Return a DATE line of TYPE."
3149 (unless (memq type '(local ut original user iso8601 lapsed english))
3150 (error "Unknown conversion type: %s" type))
3152 (let ((time (date-to-time date)))
3154 ;; Convert to the local timezone.
3156 (concat "Date: " (message-make-date time)))
3157 ;; Convert to Universal Time.
3162 (let* ((e (parse-time-string date))
3163 (tm (apply 'encode-time e))
3165 (ls (- (cadr tm) (car (current-time-zone time)))))
3166 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3167 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3171 ;; Get the original date from the article.
3172 ((eq type 'original)
3173 (concat "Date: " (if (string-match "\n+$" date)
3174 (substring date 0 (match-beginning 0))
3176 ;; Let the user define the format.
3178 (let ((format (or (condition-case nil
3179 (with-current-buffer gnus-summary-buffer
3180 gnus-article-time-format)
3182 gnus-article-time-format)))
3183 (if (functionp format)
3184 (funcall format time)
3185 (concat "Date: " (format-time-string format time)))))
3188 (let ((tz (car (current-time-zone time))))
3191 (format-time-string "%Y%m%dT%H%M%S" time)
3192 (format "%s%02d%02d"
3193 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3194 (/ (% (abs tz) 3600) 60)))))
3195 ;; Do an X-Sent lapsed format.
3197 ;; If the date is seriously mangled, the timezone functions are
3198 ;; liable to bug out, so we ignore all errors.
3199 (let* ((now (current-time))
3200 (real-time (subtract-time now time))
3201 (real-sec (and real-time
3202 (+ (* (float (car real-time)) 65536)
3204 (sec (and real-time (abs real-sec)))
3214 ;; This is a bit convoluted, but basically we go
3215 ;; through the time units for years, weeks, etc,
3216 ;; and divide things to see whether that results
3217 ;; in positive answers.
3220 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3221 ;; The (remaining) seconds are too few to
3222 ;; be divided into this time unit.
3224 ;; It's big enough, so we output it.
3225 (setq sec (- sec (* num (cdr unit))))
3227 (concat (if prev ", " "") (int-to-string
3229 " " (symbol-name (car unit))
3230 (if (> num 1) "s" ""))
3232 article-time-units "")
3233 ;; If dates are odd, then it might appear like the
3234 ;; article was sent in the future.
3237 " in the future"))))))
3238 ;; Display the date in proper English
3240 (let ((dtime (decode-time time)))
3243 (number-to-string (nth 3 dtime))
3244 (let ((digit (% (nth 3 dtime) 10)))
3246 ((memq (nth 3 dtime) '(11 12 13)) "th")
3252 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3254 (number-to-string (nth 5 dtime))
3256 (format "%02d" (nth 2 dtime))
3258 (format "%02d" (nth 1 dtime)))))))
3260 (format "Date: %s (from T-gnus)" date))))
3262 (defun article-date-local (&optional highlight)
3263 "Convert the current article date to the local timezone."
3264 (interactive (list t))
3265 (article-date-ut 'local highlight))
3267 (defun article-date-english (&optional highlight)
3268 "Convert the current article date to something that is proper English."
3269 (interactive (list t))
3270 (article-date-ut 'english highlight))
3272 (defun article-date-original (&optional highlight)
3273 "Convert the current article date to what it was originally.
3274 This is only useful if you have used some other date conversion
3275 function and want to see what the date was before converting."
3276 (interactive (list t))
3277 (article-date-ut 'original highlight))
3279 (defun article-date-lapsed (&optional highlight)
3280 "Convert the current article date to time lapsed since it was sent."
3281 (interactive (list t))
3282 (article-date-ut 'lapsed highlight))
3284 (defun article-update-date-lapsed ()
3285 "Function to be run from a timer to update the lapsed time line."
3287 (let (deactivate-mark)
3292 (set-buffer (window-buffer w))
3293 (when (or (and (eq major-mode 'mime-view-mode)
3294 (eq (mime-preview-original-major-mode)
3295 'gnus-original-article-mode))
3296 (eq major-mode 'gnus-article-mode))
3297 (let ((mark (point-marker)))
3298 (goto-char (point-min))
3299 (when (re-search-forward "^X-Sent:" nil t)
3300 (article-date-lapsed t))
3301 (goto-char (marker-position mark))
3302 (move-marker mark nil))))
3305 (defun gnus-start-date-timer (&optional n)
3306 "Start a timer to update the X-Sent header in the article buffers.
3307 The numerical prefix says how frequently (in seconds) the function
3312 (gnus-stop-date-timer)
3313 (setq article-lapsed-timer
3314 (run-at-time 1 n 'article-update-date-lapsed)))
3316 (defun gnus-stop-date-timer ()
3317 "Stop the X-Sent timer."
3319 (when article-lapsed-timer
3320 (nnheader-cancel-timer article-lapsed-timer)
3321 (setq article-lapsed-timer nil)))
3323 (defun article-date-user (&optional highlight)
3324 "Convert the current article date to the user-defined format.
3325 This format is defined by the `gnus-article-time-format' variable."
3326 (interactive (list t))
3327 (article-date-ut 'user highlight))
3329 (defun article-date-iso8601 (&optional highlight)
3330 "Convert the current article date to ISO8601."
3331 (interactive (list t))
3332 (article-date-ut 'iso8601 highlight))
3334 (defmacro gnus-article-save-original-date (&rest forms)
3335 "Save the original date as a text property and evaluate FORMS."
3336 `(let* ((case-fold-search t)
3338 (goto-char (point-min))
3339 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3342 (date (when (and start
3343 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3345 (buffer-substring-no-properties start
3346 (match-beginning 0)))))
3347 (goto-char (point-max))
3348 (skip-chars-backward "\n")
3349 (put-text-property (point-min) (point) 'original-date date)
3351 (goto-char (point-max))
3352 (skip-chars-backward "\n")
3353 (put-text-property (point-min) (point) 'original-date date)))
3355 ;; (defun article-show-all ()
3356 ;; "Show all hidden text in the article buffer."
3360 ;; (let ((inhibit-read-only t))
3361 ;; (gnus-article-unhide-text (point-min) (point-max))
3362 ;; (gnus-remove-text-with-property 'gnus-prev)
3363 ;; (gnus-remove-text-with-property 'gnus-next))))
3365 (defun article-show-all-headers ()
3366 "Show all hidden headers in the article buffer."
3371 (article-narrow-to-head)
3372 (let ((inhibit-read-only t))
3373 (gnus-article-unhide-text (point-min) (point-max))))))
3375 (defun article-remove-leading-whitespace ()
3376 "Remove excessive whitespace from all headers."
3380 (let ((inhibit-read-only t))
3381 (article-narrow-to-head)
3382 (goto-char (point-min))
3383 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3384 (delete-region (match-beginning 1) (match-end 1)))))))
3386 (defun article-emphasize (&optional arg)
3387 "Emphasize text according to `gnus-emphasis-alist'."
3388 (interactive (gnus-article-hidden-arg))
3389 (unless (gnus-article-check-hidden-text 'emphasis arg)
3393 (with-current-buffer gnus-summary-buffer
3394 gnus-article-emphasis-alist)
3396 gnus-emphasis-alist))
3397 (inhibit-read-only t)
3398 (props (append '(article-type emphasis)
3399 gnus-hidden-properties))
3400 regexp elem beg invisible visible face)
3403 (while (setq elem (pop alist))
3405 (setq regexp (car elem)
3406 invisible (nth 1 elem)
3407 visible (nth 2 elem)
3409 (while (re-search-forward regexp nil t)
3410 (when (and (match-beginning visible) (match-beginning invisible))
3411 (gnus-article-hide-text
3412 (match-beginning invisible) (match-end invisible) props)
3413 (gnus-article-unhide-text-type
3414 (match-beginning visible) (match-end visible) 'emphasis)
3415 (gnus-put-overlay-excluding-newlines
3416 (match-beginning visible) (match-end visible) 'face face)
3417 (gnus-add-wash-type 'emphasis)
3418 (goto-char (match-end invisible)))))))))
3420 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3421 "Setup newsgroup emphasis alist."
3422 (unless gnus-article-emphasis-alist
3423 (let ((name (and gnus-newsgroup-name
3424 (gnus-group-real-name gnus-newsgroup-name))))
3425 (make-local-variable 'gnus-article-emphasis-alist)
3426 (setq gnus-article-emphasis-alist
3428 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3429 (while (setq elem (pop alist))
3430 (when (and name (string-match (car elem) name))
3432 highlight (copy-sequence (cdr elem)))))
3434 (copy-sequence highlight-words)
3435 (if gnus-newsgroup-name
3436 (copy-sequence (gnus-group-find-parameter
3437 gnus-newsgroup-name 'highlight-words t)))
3438 gnus-emphasis-alist)))))
3441 (defvar gnus-summary-article-menu)
3442 (defvar gnus-summary-post-menu))
3444 ;;; Saving functions.
3446 (defun gnus-article-save (save-buffer file &optional num)
3447 "Save the currently selected article."
3448 (unless gnus-save-all-headers
3449 ;; Remove headers according to `gnus-saved-headers'.
3450 (let ((gnus-visible-headers
3451 (or gnus-saved-headers gnus-visible-headers))
3452 (gnus-article-buffer save-buffer))
3454 (set-buffer save-buffer)
3455 (article-hide-headers 1 t))))
3456 (save-window-excursion
3457 (if (not gnus-default-article-saver)
3458 (error "No default saver is defined")
3459 ;; !!! Magic! The saving functions all save
3460 ;; `gnus-save-article-buffer' (or so they think), but we
3461 ;; bind that variable to our save-buffer.
3462 (set-buffer gnus-article-buffer)
3463 (let* ((gnus-save-article-buffer save-buffer)
3466 ((not gnus-prompt-before-saving) 'default)
3467 ((eq gnus-prompt-before-saving 'always) nil)
3469 (gnus-number-of-articles-to-be-saved
3470 (when (eq gnus-prompt-before-saving t)
3472 (set-buffer gnus-article-current-summary)
3473 (funcall gnus-default-article-saver filename)))))
3475 (defun gnus-read-save-file-name (prompt &optional filename
3476 function group headers variable)
3478 (funcall function group headers (symbol-value variable)))
3483 ((eq filename 'default)
3489 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3492 (if (and gnus-number-of-articles-to-be-saved
3493 (> gnus-number-of-articles-to-be-saved 1))
3494 (format "these %d articles"
3495 gnus-number-of-articles-to-be-saved)
3498 ;; Let the split methods have their say.
3500 ;; No split name was found.
3503 (concat prompt " (default "
3504 (file-name-nondirectory default-name) "): ")
3505 (file-name-directory default-name)
3507 ;; A single group name is returned.
3508 ((stringp split-name)
3510 (funcall function split-name headers
3511 (symbol-value variable)))
3513 (concat prompt " (default "
3514 (file-name-nondirectory default-name) "): ")
3515 (file-name-directory default-name)
3517 ;; A single split name was found
3518 ((= 1 (length split-name))
3519 (let* ((name (expand-file-name
3521 gnus-article-save-directory))
3522 (dir (cond ((file-directory-p name)
3523 (file-name-as-directory name))
3524 ((file-exists-p name) name)
3525 (t gnus-article-save-directory))))
3527 (concat prompt " (default " name "): ")
3529 ;; A list of splits was found.
3531 (setq split-name (nreverse split-name))
3533 (let ((file-name-history
3534 (nconc split-name file-name-history)))
3538 (concat prompt " (`M-p' for defaults): ")
3539 gnus-article-save-directory
3541 gnus-article-save-directory)))
3542 (car (push result file-name-history)))))))
3543 ;; Create the directory.
3544 (gnus-make-directory (file-name-directory file))
3545 ;; If we have read a directory, we append the default file name.
3546 (when (file-directory-p file)
3547 (setq file (expand-file-name (file-name-nondirectory
3549 (file-name-as-directory file))))
3550 ;; Possibly translate some characters.
3551 (nnheader-translate-file-chars file))))))
3552 (gnus-make-directory (file-name-directory result))
3553 (set variable result)))
3555 (defun gnus-article-archive-name (group)
3556 "Return the first instance of an \"Archive-name\" in the current buffer."
3557 (let ((case-fold-search t))
3558 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3559 (nnheader-concat gnus-article-save-directory
3560 (match-string 1)))))
3562 (defun gnus-article-nndoc-name (group)
3563 "If GROUP is an nndoc group, return the name of the parent group."
3564 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3565 (gnus-group-get-parameter group 'save-article-group)))
3567 (defun gnus-summary-save-in-rmail (&optional filename)
3568 "Append this article to Rmail file.
3569 Optional argument FILENAME specifies file name.
3570 Directory to save to is default to `gnus-article-save-directory'."
3571 (setq filename (gnus-read-save-file-name
3572 "Save %s in rmail file" filename
3573 gnus-rmail-save-name gnus-newsgroup-name
3574 gnus-current-headers 'gnus-newsgroup-last-rmail))
3575 (gnus-eval-in-buffer-window gnus-save-article-buffer
3579 (gnus-output-to-rmail filename))))
3582 (defun gnus-summary-save-in-mail (&optional filename)
3583 "Append this article to Unix mail file.
3584 Optional argument FILENAME specifies file name.
3585 Directory to save to is default to `gnus-article-save-directory'."
3586 (setq filename (gnus-read-save-file-name
3587 "Save %s in Unix mail file" filename
3588 gnus-mail-save-name gnus-newsgroup-name
3589 gnus-current-headers 'gnus-newsgroup-last-mail))
3590 (gnus-eval-in-buffer-window gnus-save-article-buffer
3594 (if (and (file-readable-p filename)
3595 (file-regular-p filename)
3596 (mail-file-babyl-p filename))
3597 (rmail-output-to-rmail-file filename t)
3598 (gnus-output-to-mail filename)))))
3601 (defun gnus-summary-save-in-file (&optional filename overwrite)
3602 "Append this article to file.
3603 Optional argument FILENAME specifies file name.
3604 Directory to save to is default to `gnus-article-save-directory'."
3605 (setq filename (gnus-read-save-file-name
3606 "Save %s in file" filename
3607 gnus-file-save-name gnus-newsgroup-name
3608 gnus-current-headers 'gnus-newsgroup-last-file))
3609 (gnus-eval-in-buffer-window gnus-save-article-buffer
3613 (when (and overwrite
3614 (file-exists-p filename))
3615 (delete-file filename))
3616 (gnus-output-to-file filename))))
3619 (defun gnus-summary-write-to-file (&optional filename)
3620 "Write this article to a file, overwriting it if the file exists.
3621 Optional argument FILENAME specifies file name.
3622 The directory to save in defaults to `gnus-article-save-directory'."
3623 (gnus-summary-save-in-file nil t))
3625 (defun gnus-summary-save-body-in-file (&optional filename)
3626 "Append this article body to a file.
3627 Optional argument FILENAME specifies file name.
3628 The directory to save in defaults to `gnus-article-save-directory'."
3629 (setq filename (gnus-read-save-file-name
3630 "Save %s body in file" filename
3631 gnus-file-save-name gnus-newsgroup-name
3632 gnus-current-headers 'gnus-newsgroup-last-file))
3633 (gnus-eval-in-buffer-window gnus-save-article-buffer
3637 (when (article-goto-body)
3638 (narrow-to-region (point) (point-max)))
3639 (gnus-output-to-file filename))))
3642 (defun gnus-summary-save-in-pipe (&optional command)
3643 "Pipe this article to subprocess."
3645 (cond ((and (eq command 'default)
3646 gnus-last-shell-command)
3647 gnus-last-shell-command)
3652 "Shell command on %s: "
3653 (if (and gnus-number-of-articles-to-be-saved
3654 (> gnus-number-of-articles-to-be-saved 1))
3655 (format "these %d articles"
3656 gnus-number-of-articles-to-be-saved)
3658 gnus-last-shell-command))))
3659 (when (string-equal command "")
3660 (if gnus-last-shell-command
3661 (setq command gnus-last-shell-command)
3662 (error "A command is required")))
3663 (gnus-eval-in-buffer-window gnus-article-buffer
3666 (shell-command-on-region (point-min) (point-max) command nil)))
3667 (setq gnus-last-shell-command command))
3669 (defun gnus-summary-pipe-to-muttprint (&optional command)
3670 "Pipe this article to muttprint."
3671 (setq command (read-string
3672 "Print using command: " gnus-summary-muttprint-program
3673 nil gnus-summary-muttprint-program))
3674 (gnus-summary-save-in-pipe command))
3676 ;;; Article file names when saving.
3678 (defun gnus-capitalize-newsgroup (newsgroup)
3679 "Capitalize NEWSGROUP name."
3680 (when (not (zerop (length newsgroup)))
3681 (concat (char-to-string (upcase (aref newsgroup 0)))
3682 (substring newsgroup 1))))
3684 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3685 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3686 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3687 Otherwise, it is like ~/News/news/group/num."
3690 (concat (if (gnus-use-long-file-name 'not-save)
3691 (gnus-capitalize-newsgroup newsgroup)
3692 (gnus-newsgroup-directory-form newsgroup))
3693 "/" (int-to-string (mail-header-number headers)))
3694 gnus-article-save-directory)))
3696 (string-equal (file-name-directory default)
3697 (file-name-directory last-file))
3698 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3700 (or last-file default))))
3702 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3703 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3704 If variable `gnus-use-long-file-name' is non-nil, it is
3705 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3708 (concat (if (gnus-use-long-file-name 'not-save)
3710 (gnus-newsgroup-directory-form newsgroup))
3711 "/" (int-to-string (mail-header-number headers)))
3712 gnus-article-save-directory)))
3714 (string-equal (file-name-directory default)
3715 (file-name-directory last-file))
3716 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3718 (or last-file default))))
3720 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3721 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3722 If variable `gnus-use-long-file-name' is non-nil, it is
3723 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3726 (if (gnus-use-long-file-name 'not-save)
3729 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3731 gnus-article-save-directory)))
3733 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3734 "Generate file name from sender."
3735 (let ((from (mail-header-from headers)))
3737 (if (and from (string-match "\\([^ <]+\\)@" from))
3738 (match-string 1 from)
3740 gnus-article-save-directory)))
3742 (defun article-verify-x-pgp-sig ()
3745 (if (gnus-buffer-live-p gnus-original-article-buffer)
3746 (let ((sig (with-current-buffer gnus-original-article-buffer
3747 (gnus-fetch-field "X-PGP-Sig")))
3751 (mml2015-clear-verify-function))
3753 (insert-buffer-substring gnus-original-article-buffer)
3754 (setq items (split-string sig))
3755 (message-narrow-to-head)
3756 (let ((inhibit-point-motion-hooks t)
3757 (case-fold-search t))
3758 ;; Don't verify multiple headers.
3759 (setq headers (mapconcat (lambda (header)
3761 (mail-fetch-field header)
3763 (split-string (nth 1 items) ",") "")))
3764 (delete-region (point-min) (point-max))
3765 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3766 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3771 (if (looking-at "^-")
3774 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3775 (insert "Version: " (car items) "\n\n")
3776 (insert (mapconcat 'identity (cddr items) "\n"))
3777 (insert "\n-----END PGP SIGNATURE-----\n")
3778 (let ((mm-security-handle (list (format "multipart/signed"))))
3779 (mml2015-clean-buffer)
3780 (let ((coding-system-for-write (or gnus-newsgroup-charset
3782 (funcall (mml2015-clear-verify-function)))
3784 (or (mm-handle-multipart-ctl-parameter
3785 mm-security-handle 'gnus-details)
3786 (mm-handle-multipart-ctl-parameter
3787 mm-security-handle 'gnus-info)))))
3789 (let ((inhibit-read-only t) bface eface)
3791 (message-narrow-to-head)
3792 (goto-char (point-max))
3794 (setq bface (get-text-property (point-at-bol) 'face)
3795 eface (get-text-property (1- (point-at-eol)) 'face))
3796 (message-remove-header "X-Gnus-PGP-Verify")
3797 (if (re-search-forward "^X-PGP-Sig:" nil t)
3799 (goto-char (point-max)))
3800 (narrow-to-region (point) (point))
3801 (insert "X-Gnus-PGP-Verify: " info "\n")
3802 (goto-char (point-min))
3805 (if (not (looking-at "^[ \t]"))
3809 (goto-char (point-min))
3810 (when (looking-at "\\([^:]+\\): *")
3811 (put-text-property (match-beginning 1) (1+ (match-end 1))
3813 (put-text-property (match-end 0) (point-max)
3814 'face eface)))))))))
3816 (defun article-verify-cancel-lock ()
3817 "Verify Cancel-Lock header."
3819 (if (gnus-buffer-live-p gnus-original-article-buffer)
3820 (canlock-verify gnus-original-article-buffer)))
3822 (defun article-monafy ()
3823 "Display body part with mona font."
3825 (unless (if (featurep 'xemacs)
3826 (find-face 'gnus-mona-face)
3827 (facep 'gnus-mona-face))
3828 (require 'navi2ch-mona)
3829 (set-face-font (make-face 'gnus-mona-face) navi2ch-mona-font))
3831 (let ((inhibit-read-only t))
3834 (gnus-make-overlay (point) (point-max))
3835 'face 'gnus-mona-face))))
3842 (setq afunc (car func)
3845 gfunc (intern (format "gnus-%s" func))))
3847 (when (fboundp afunc)
3848 `(lambda (&optional interactive &rest args)
3849 ,(documentation afunc t)
3850 (interactive (list t))
3852 (set-buffer gnus-article-buffer)
3854 (call-interactively ',afunc)
3855 (apply ',afunc args))))))))
3856 '(article-hide-headers
3857 article-verify-x-pgp-sig
3858 article-verify-cancel-lock
3860 article-hide-boring-headers
3861 article-treat-overstrike
3862 article-treat-ansi-sequences
3863 article-fill-long-lines
3864 article-capitalize-sentences
3866 article-remove-leading-whitespace
3867 article-display-x-face
3868 article-display-face
3869 article-de-quoted-unreadable
3870 article-de-base64-unreadable
3873 article-unsplit-urls
3874 article-hide-list-identifiers
3875 article-strip-banner
3878 article-hide-signature
3879 article-strip-headers-in-body
3880 article-remove-trailing-blank-lines
3881 article-strip-leading-blank-lines
3882 article-strip-multiple-blank-lines
3883 article-strip-leading-space
3884 article-strip-trailing-space
3885 article-strip-blank-lines
3886 article-strip-all-blank-lines
3888 article-date-english
3889 article-date-iso8601
3890 article-date-original
3892 article-decode-mime-words
3893 article-decode-charset
3894 article-decode-encoded-words
3898 article-treat-dumbquotes
3899 article-normalize-headers
3900 (article-show-all-headers . gnus-article-show-all-headers)
3901 ;; (article-show-all . gnus-article-show-all)
3905 ;;; Gnus article mode
3908 (put 'gnus-article-mode 'mode-class 'special)
3910 (gnus-define-keys gnus-article-mode-map
3911 " " gnus-article-goto-next-page
3912 "\177" gnus-article-goto-prev-page
3913 [delete] gnus-article-goto-prev-page
3914 [backspace] gnus-article-goto-prev-page
3915 "\C-c^" gnus-article-refer-article
3916 "h" gnus-article-show-summary
3917 "s" gnus-article-show-summary
3918 "\C-c\C-m" gnus-article-mail
3919 "?" gnus-article-describe-briefly
3920 "e" gnus-summary-edit-article
3921 "<" beginning-of-buffer
3923 "\C-c\C-i" gnus-info-find-node
3925 "R" gnus-article-reply-with-original
3926 "F" gnus-article-followup-with-original
3927 "\C-hk" gnus-article-describe-key
3928 "\C-hc" gnus-article-describe-key-briefly
3930 "\C-d" gnus-article-read-summary-keys
3931 "\M-*" gnus-article-read-summary-keys
3932 "\M-#" gnus-article-read-summary-keys
3933 "\M-^" gnus-article-read-summary-keys
3934 "\M-g" gnus-article-read-summary-keys)
3936 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3940 (push (char-to-string key) keys)
3942 (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3943 (setq key (car elem))
3944 (when (and (> (length key) 0)
3945 (not (eq 'menu-bar (aref key 0)))
3946 (symbolp (lookup-key gnus-summary-mode-map key)))
3949 (unless (lookup-key gnus-article-mode-map key)
3950 (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3952 (defun gnus-article-make-menu-bar ()
3953 (unless (boundp 'gnus-article-commands-menu)
3954 (gnus-summary-make-menu-bar))
3955 (gnus-turn-off-edit-menu 'article)
3956 (unless (boundp 'gnus-article-article-menu)
3958 gnus-article-article-menu gnus-article-mode-map ""
3960 ["Scroll forwards" gnus-article-goto-next-page t]
3961 ["Scroll backwards" gnus-article-goto-prev-page t]
3962 ["Show summary" gnus-article-show-summary t]
3963 ["Fetch Message-ID at point" gnus-article-refer-article t]
3964 ["Mail to address at point" gnus-article-mail t]
3965 ["Send a bug report" gnus-bug t]))
3968 gnus-article-treatment-menu gnus-article-mode-map ""
3969 ;; Fixme: this should use :active (and maybe :visible).
3971 ["Hide headers" gnus-article-hide-headers t]
3972 ["Hide signature" gnus-article-hide-signature t]
3973 ["Hide citation" gnus-article-hide-citation t]
3974 ["Treat overstrike" gnus-article-treat-overstrike t]
3975 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3976 ["Remove carriage return" gnus-article-remove-cr t]
3977 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3978 ["Treat html" gnus-article-wash-html t]
3979 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3980 ["Decode HZ" gnus-article-decode-HZ t]))
3982 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3984 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3986 (gnus-run-hooks 'gnus-article-menu-hook)))
3988 (defun gnus-article-mode ()
3989 "Major mode for displaying an article.
3991 All normal editing commands are switched off.
3993 The following commands are available in addition to all summary mode
3995 \\<gnus-article-mode-map>
3996 \\[gnus-article-next-page]\t Scroll the article one page forwards
3997 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3998 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3999 \\[gnus-article-show-summary]\t Display the summary buffer
4000 \\[gnus-article-mail]\t Send a reply to the address near point
4001 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4002 \\[gnus-info-find-node]\t Go to the Gnus info node"
4004 (kill-all-local-variables)
4005 (gnus-simplify-mode-line)
4006 (setq mode-name "Article")
4007 (setq major-mode 'gnus-article-mode)
4008 (make-local-variable 'minor-mode-alist)
4009 (unless (assq 'gnus-show-mime minor-mode-alist)
4010 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
4011 (use-local-map gnus-article-mode-map)
4012 (when (gnus-visual-p 'article-menu 'menu)
4013 (gnus-article-make-menu-bar)
4014 (when gnus-summary-tool-bar-map
4015 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4016 (gnus-update-format-specifications nil 'article-mode)
4017 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4018 (set (make-local-variable 'gnus-page-broken) nil)
4019 (make-local-variable 'gnus-button-marker-list)
4020 (make-local-variable 'gnus-article-current-summary)
4021 (make-local-variable 'gnus-article-mime-handles)
4022 (make-local-variable 'gnus-article-decoded-p)
4023 (make-local-variable 'gnus-article-mime-handle-alist)
4024 (make-local-variable 'gnus-article-wash-types)
4025 (make-local-variable 'gnus-article-image-alist)
4026 (make-local-variable 'gnus-article-charset)
4027 (make-local-variable 'gnus-article-ignored-charsets)
4028 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
4029 (set (make-local-variable 'nobreak-char-display) nil)
4030 (gnus-set-default-directory)
4031 (buffer-disable-undo)
4032 (setq buffer-read-only t
4033 show-trailing-whitespace nil)
4034 (set-syntax-table gnus-article-mode-syntax-table)
4035 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4037 (defun gnus-article-setup-buffer ()
4038 "Initialize the article buffer."
4039 (let* ((name (if gnus-single-article-buffer "*Article*"
4040 (concat "*Article " gnus-newsgroup-name "*")))
4042 (progn (string-match "\\*Article" name)
4043 (concat " *Original Article"
4044 (substring name (match-end 0))))))
4045 (setq gnus-article-buffer name)
4046 (setq gnus-original-article-buffer original)
4047 (setq gnus-article-mime-handle-alist nil)
4048 ;; This might be a variable local to the summary buffer.
4049 (unless gnus-single-article-buffer
4051 (set-buffer gnus-summary-buffer)
4052 (setq gnus-article-buffer name)
4053 (setq gnus-original-article-buffer original)
4054 (gnus-set-global-variables)))
4055 (gnus-article-setup-highlight-words)
4056 ;; Init original article buffer.
4058 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4059 (set-buffer-multibyte t)
4060 (setq major-mode 'gnus-original-article-mode)
4061 (make-local-variable 'gnus-original-article))
4062 (if (and (get-buffer name)
4063 (with-current-buffer name
4064 (if gnus-article-edit-mode
4065 (if (y-or-n-p "Article mode edit in progress; discard? ")
4067 (set-buffer-modified-p nil)
4068 (gnus-kill-buffer name)
4071 (error "Action aborted"))
4075 (set (make-local-variable 'gnus-article-edit-mode) nil)
4076 (buffer-disable-undo)
4077 (setq buffer-read-only t)
4078 ;; This list just keeps growing if we don't reset it.
4079 (setq gnus-button-marker-list nil)
4080 (unless (eq major-mode 'gnus-article-mode)
4081 (gnus-article-mode))
4084 (set-buffer (gnus-get-buffer-create name))
4086 (make-local-variable 'gnus-summary-buffer)
4087 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4088 (current-buffer)))))
4090 ;; Set article window start at LINE, where LINE is the number of lines
4091 ;; from the head of the article.
4092 (defun gnus-article-set-window-start (&optional line)
4094 (gnus-get-buffer-window gnus-article-buffer t)
4096 (set-buffer gnus-article-buffer)
4097 (goto-char (point-min))
4100 (gnus-message 6 "Moved to bookmark")
4101 (search-forward "\n\n" nil t)
4105 ;;; @@ article filters
4108 (defun gnus-article-display-mime-message ()
4109 "Article display method for MIME message."
4110 ;; called from `gnus-original-article-buffer'.
4111 (let (charset all-headers)
4112 (with-current-buffer gnus-summary-buffer
4113 (setq charset default-mime-charset
4114 all-headers gnus-have-all-headers))
4115 (make-local-variable 'default-mime-charset)
4116 (setq default-mime-charset charset)
4117 (with-current-buffer (get-buffer-create gnus-article-buffer)
4118 (make-local-variable 'default-mime-charset)
4119 (setq default-mime-charset charset))
4120 (mime-display-message mime-message-structure
4121 gnus-article-buffer nil gnus-article-mode-map)
4123 (gnus-article-hide-headers nil -1)))
4124 (run-hooks 'gnus-mime-article-prepare-hook))
4126 (defun gnus-article-display-traditional-message ()
4127 "Article display method for traditional message."
4128 (set-buffer gnus-article-buffer)
4129 (let ((inhibit-read-only t))
4131 (insert-buffer-substring gnus-original-article-buffer)))
4133 (defun gnus-article-make-full-mail-header (&optional number charset)
4134 "Create a new mail header structure in a raw article buffer."
4135 (unless (and number charset)
4136 (save-current-buffer
4137 (set-buffer gnus-summary-buffer)
4139 (setq number (or (cdr gnus-article-current) 0)))
4141 (setq charset (or default-mime-charset 'x-ctext)))))
4142 (goto-char (point-min))
4143 (let ((header-end (if (search-forward "\n\n" nil t)
4145 (goto-char (point-max))))
4146 (chars (- (point-max) (point)))
4147 (lines (count-lines (point) (point-max)))
4148 (default-mime-charset charset)
4150 (narrow-to-region (point-min) header-end)
4151 (setq xref (std11-fetch-field "xref"))
4153 (make-full-mail-header
4155 (std11-fetch-field "subject")
4156 (std11-fetch-field "from")
4157 (std11-fetch-field "date")
4158 (std11-fetch-field "message-id")
4159 (std11-fetch-field "references")
4162 (when xref (concat "Xref: " xref)))
4165 (defun gnus-article-prepare (article &optional all-headers header)
4166 "Prepare ARTICLE in article mode buffer.
4167 ARTICLE should either be an article number or a Message-ID.
4168 If ARTICLE is an id, HEADER should be the article headers.
4169 If ALL-HEADERS is non-nil, no headers are hidden."
4171 ;; Make sure we start in a summary buffer.
4172 (unless (eq major-mode 'gnus-summary-mode)
4173 (set-buffer gnus-summary-buffer))
4174 (setq gnus-summary-buffer (current-buffer))
4175 (let* ((gnus-article (if header (mail-header-number header) article))
4176 (summary-buffer (current-buffer))
4177 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4178 (group gnus-newsgroup-name)
4181 (gnus-article-setup-buffer)
4182 (set-buffer gnus-article-buffer)
4183 ;; Deactivate active regions.
4184 (when (and (boundp 'transient-mark-mode)
4185 transient-mark-mode)
4186 (setq mark-active nil))
4187 (if (not (setq result (let ((inhibit-read-only t))
4188 (gnus-request-article-this-buffer
4190 ;; There is no such article.
4192 (when (and (numberp article)
4193 (not (memq article gnus-newsgroup-sparse)))
4194 (setq gnus-article-current
4195 (cons gnus-newsgroup-name article))
4196 (set-buffer gnus-summary-buffer)
4197 (setq gnus-current-article article)
4198 (if (and (memq article gnus-newsgroup-undownloaded)
4199 (not (gnus-online (gnus-find-method-for-group
4200 gnus-newsgroup-name))))
4202 (gnus-summary-set-agent-mark article)
4203 (message "Message marked for downloading"))
4204 (gnus-summary-mark-article article gnus-canceled-mark)
4205 (unless (memq article gnus-newsgroup-sparse)
4206 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4207 (if (or (eq result 'pseudo)
4208 (eq result 'nneething))
4211 (set-buffer summary-buffer)
4212 (push article gnus-newsgroup-history)
4213 (setq gnus-last-article gnus-current-article
4214 gnus-current-article 0
4215 gnus-current-headers nil
4216 gnus-article-current nil)
4217 (if (eq result 'nneething)
4218 (gnus-configure-windows 'summary)
4219 (gnus-configure-windows 'article))
4220 (gnus-set-global-variables))
4221 (let ((gnus-article-mime-handle-alist-1
4222 gnus-article-mime-handle-alist))
4223 (gnus-set-mode-line 'article)))
4224 ;; The result from the `request' was an actual article -
4225 ;; or at least some text that is now displayed in the
4227 (when (and (numberp article)
4228 (not (eq article gnus-current-article)))
4229 ;; Seems like a new article has been selected.
4230 ;; `gnus-current-article' must be an article number.
4232 (set-buffer summary-buffer)
4233 (push article gnus-newsgroup-history)
4234 (setq gnus-last-article gnus-current-article
4235 gnus-current-article article
4236 gnus-current-headers
4237 (gnus-summary-article-header gnus-current-article)
4238 gnus-article-current
4239 (cons gnus-newsgroup-name gnus-current-article))
4240 (unless (vectorp gnus-current-headers)
4241 (setq gnus-current-headers nil))
4242 (gnus-summary-goto-subject gnus-current-article)
4243 (when (gnus-summary-show-thread)
4244 ;; If the summary buffer really was folded, the
4245 ;; previous goto may not actually have gone to
4246 ;; the right article, but the thread root instead.
4248 (gnus-summary-goto-subject gnus-current-article))
4249 (gnus-run-hooks 'gnus-mark-article-hook)
4250 (gnus-set-mode-line 'summary)
4251 (when (gnus-visual-p 'article-highlight 'highlight)
4252 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4253 ;; Set the global newsgroup variables here.
4254 (gnus-set-global-variables)
4255 (setq gnus-have-all-headers
4256 (or all-headers gnus-show-all-headers))))
4258 (gnus-configure-windows 'article))
4259 (when (or (numberp article)
4261 (gnus-article-prepare-display)
4263 (goto-char (point-min))
4264 (when gnus-break-pages
4265 (gnus-narrow-to-page)))
4266 (let ((gnus-article-mime-handle-alist-1
4267 gnus-article-mime-handle-alist))
4268 (gnus-set-mode-line 'article))
4272 (set-window-point (get-buffer-window (current-buffer)) (point))
4273 (gnus-configure-windows 'article)
4276 (defun gnus-article-prepare-mime-display (&optional number)
4277 (goto-char (point-min))
4278 (when (re-search-forward "^[^\t ]+:" nil t)
4279 (goto-char (match-beginning 0)))
4280 (let ((entity (if (eq 1 (point-min))
4281 (get-text-property 1 'mime-view-entity)
4282 (get-text-property (point) 'mime-view-entity)))
4283 last-entity child-entity next type)
4284 (setq child-entity (mime-entity-children entity))
4286 (setq last-entity (nth (1- (length child-entity))
4288 (setq last-entity entity))
4290 (narrow-to-region (point)
4291 (if (search-forward "\n\n" nil t)
4294 (gnus-article-save-original-date (gnus-treat-article 'head))
4295 (put-text-property (point-min) (point-max) 'article-treated-header t)
4296 (goto-char (point-max)))
4297 (while (and (not (eobp)) entity)
4298 (setq next (set-marker
4300 (next-single-property-change (point) 'mime-view-entity
4302 (let ((types (mime-entity-content-type entity)))
4303 (while (eq 'multipart (mime-content-type-primary-type types))
4304 (setq entity (car (mime-entity-children entity))
4305 types (mime-entity-content-type entity)))
4307 (setq type (format "%s/%s"
4308 (mime-content-type-primary-type types)
4309 (mime-content-type-subtype types)))))
4310 (if (string-equal type "message/rfc822")
4313 (let ((children (mime-entity-children entity))
4316 (setq last-children (nth (1- (length children)) children))
4319 (not (eq last-children
4320 (get-text-property next 'mime-view-entity)))
4322 (next-single-property-change next
4324 nil (point-max)))))))
4325 (setq next (next-single-property-change next 'mime-view-entity
4328 (narrow-to-region (point) next)
4329 (gnus-article-prepare-mime-display)
4330 (goto-char (point-max)))
4331 (setq entity (get-text-property (point) 'mime-view-entity)))
4333 (narrow-to-region (point) next)
4334 ;; Kludge. We have to count true number, but for now,
4335 ;; part number is here only to achieve `last'.
4336 (gnus-treat-article nil 1
4337 (if (eq entity last-entity)
4340 (goto-char (point-max)))
4341 (setq entity (get-text-property next 'mime-view-entity))))))
4344 (defun gnus-article-prepare-display ()
4345 "Make the current buffer look like a nice article."
4346 (let ((gnus-article-buffer (current-buffer))
4348 (inhibit-read-only t))
4349 (unless (eq major-mode 'gnus-article-mode)
4350 (gnus-article-mode))
4351 (setq buffer-read-only nil
4352 gnus-button-marker-list nil
4353 gnus-article-wash-types nil
4354 gnus-article-image-alist nil)
4357 (static-if (featurep 'xemacs)
4358 (map-extents (lambda (extent maparg) (delete-extent extent)))
4359 (let ((lists (overlay-lists)))
4360 (dolist (overlay (nconc (car lists) (cdr lists)))
4361 (delete-overlay overlay)))))
4362 (gnus-run-hooks 'gnus-tmp-internal-hook))
4363 (let ((show-mime (unless (member gnus-newsgroup-name '("nndraft:delayed"
4366 (inhibit-read-only t))
4367 (set-buffer gnus-original-article-buffer)
4369 (setq mime-message-structure gnus-current-headers)
4370 (mime-buffer-entity-set-buffer-internal mime-message-structure
4371 gnus-original-article-buffer)
4372 (mime-entity-set-representation-type-internal mime-message-structure
4373 'mime-buffer-entity)
4374 (luna-send mime-message-structure 'initialize-instance
4375 mime-message-structure)
4377 (let (mime-display-header-hook mime-display-text/plain-hook)
4378 (funcall gnus-article-display-method-for-mime))
4379 (funcall gnus-article-display-method-for-traditional))
4380 ;; Call the treatment functions.
4384 (gnus-article-prepare-mime-display)
4385 (narrow-to-region (goto-char (point-min))
4386 (if (search-forward "\n\n" nil t)
4389 (gnus-article-save-original-date (gnus-treat-article 'head))
4390 (put-text-property (point-min) (point-max) 'article-treated-header t)
4391 (goto-char (point-max))
4393 (narrow-to-region (point) (point-max))
4394 (gnus-treat-article nil))
4395 (put-text-property (point-min) (point-max) 'read-only nil)))
4396 (gnus-run-hooks 'gnus-article-prepare-hook))
4398 (defun gnus-article-decode-article-as-default-mime-charset ()
4399 "Decode an article as `default-mime-charset'. It won't work if the
4400 value of the variable `gnus-show-mime' is non-nil."
4401 (unless (or gnus-show-mime
4402 (member gnus-newsgroup-name '("nndraft:delayed"
4404 (set (make-local-variable 'default-mime-charset)
4405 (with-current-buffer gnus-summary-buffer
4406 default-mime-charset))
4407 (decode-mime-charset-region (point-min) (point-max)
4408 default-mime-charset)))
4411 ;;; Gnus MIME viewing functions
4414 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4415 "Format of the MIME buttons.
4417 Valid specifiers include:
4419 %T MIME type, along with additional info
4420 %n The `name' parameter
4421 %d The description, if any
4422 %l The length of the encoded part
4423 %p The part identifier number
4424 %e Dots if the part isn't displayed
4426 General format specifiers can also be used. See Info node
4427 `(gnus)Formatting Variables'.")
4429 (defvar gnus-mime-button-line-format-alist
4430 '((?t gnus-tmp-type ?s)
4431 (?T gnus-tmp-type-long ?s)
4432 (?n gnus-tmp-name ?s)
4433 (?d gnus-tmp-description ?s)
4435 (?l gnus-tmp-length ?d)
4436 (?e gnus-tmp-dots ?s)))
4438 (defvar gnus-mime-button-commands
4439 '((gnus-article-press-button "\r" "Toggle Display")
4440 (gnus-mime-view-part "v" "View Interactively...")
4441 (gnus-mime-view-part-as-type "t" "View As Type...")
4442 (gnus-mime-view-part-as-charset "C" "View As charset...")
4443 (gnus-mime-save-part "o" "Save...")
4444 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4445 (gnus-mime-replace-part "r" "Replace part")
4446 (gnus-mime-delete-part "d" "Delete part")
4447 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4448 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4449 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4450 (gnus-mime-view-part-externally "e" "View Externally")
4451 (gnus-mime-print-part "p" "Print")
4452 (gnus-mime-pipe-part "|" "Pipe To Command...")
4453 (gnus-mime-action-on-part "." "Take action on the part...")))
4455 (defun gnus-article-mime-part-status ()
4456 (with-current-buffer gnus-article-buffer
4457 (let ((entity (get-text-property (point-min) 'mime-view-entity))
4460 (setq children (mime-entity-children entity))
4461 (setq children (length children)))
4464 (format " (%d parts)" children))
4467 (defvar gnus-mime-button-map
4468 (let ((map (make-sparse-keymap)))
4469 (define-key map gnus-mouse-2 'gnus-article-push-button)
4470 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4471 (dolist (c gnus-mime-button-commands)
4472 (define-key map (cadr c) (car c)))
4476 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4478 ,@(mapcar (lambda (c)
4479 (vector (caddr c) (car c) :enable t))
4480 gnus-mime-button-commands)))
4482 (defun gnus-mime-button-menu (event prefix)
4483 "Construct a context-sensitive menu of MIME commands."
4484 (interactive "e\nP")
4485 (save-window-excursion
4486 (let ((pos (event-start event)))
4487 (select-window (posn-window pos))
4488 (goto-char (posn-point pos))
4489 (gnus-article-check-buffer)
4490 (popup-menu gnus-mime-button-menu nil prefix))))
4492 (defun gnus-mime-view-all-parts (&optional handles)
4493 "View all the MIME parts."
4495 (with-current-buffer gnus-article-buffer
4496 (let ((handles (or handles gnus-article-mime-handles))
4497 (mail-parse-charset gnus-newsgroup-charset)
4498 (mail-parse-ignored-charsets
4499 (with-current-buffer gnus-summary-buffer
4500 gnus-newsgroup-ignored-charsets)))
4502 (mm-remove-parts handles)
4503 (goto-char (point-min))
4504 (or (search-forward "\n\n") (goto-char (point-max)))
4505 (let ((inhibit-read-only t))
4506 (delete-region (point) (point-max))
4507 (mm-display-parts handles))))))
4509 (defun gnus-article-jump-to-part (n)
4510 "Jump to MIME part N."
4512 (pop-to-buffer gnus-article-buffer)
4513 ;; FIXME: why is it necessary?
4515 (let ((parts (length gnus-article-mime-handle-alist)))
4518 (read-string ;; Emacs 21 doesn't have `read-number'.
4519 (format "Jump to part (2..%s): " parts)))))
4520 (unless (and (integerp n) (<= n parts) (>= n 1))
4523 (gnus-message 7 "Invalid part `%s', using %s instead."
4526 (gnus-message 9 "Jumping to part %s." n)
4527 (cond ((>= gnus-auto-select-part 1)
4528 (while (and (<= n parts)
4529 (not (gnus-article-goto-part n)))
4531 ((< gnus-auto-select-part 0)
4532 (while (and (>= n 1)
4533 (not (gnus-article-goto-part n)))
4536 (gnus-article-goto-part n)))))
4539 (defsubst gnus-article-edit-part (handles &optional current-id)
4540 "Edit an article in order to delete a mime part.
4541 This function is exclusively used by `gnus-mime-save-part-and-strip'
4542 and `gnus-mime-delete-part', and not provided at run-time normally."
4543 (gnus-article-edit-article
4545 (buffer-disable-undo)
4547 (let ((mail-parse-charset (or gnus-article-charset
4548 ',gnus-newsgroup-charset))
4549 (mail-parse-ignored-charsets
4550 (or gnus-article-ignored-charsets
4551 ',gnus-newsgroup-ignored-charsets))
4552 (mbl mml-buffer-list))
4553 (setq mml-buffer-list nil)
4554 (insert-buffer-substring gnus-original-article-buffer)
4555 (mime-to-mml ',handles)
4556 (setq gnus-article-mime-handles nil)
4557 (let ((mbl1 mml-buffer-list))
4558 (setq mml-buffer-list mbl)
4559 (set (make-local-variable 'mml-buffer-list) mbl1))
4560 (gnus-make-local-hook 'kill-buffer-hook)
4561 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4562 `(lambda (no-highlight)
4563 (let ((mail-parse-charset (or gnus-article-charset
4564 ',gnus-newsgroup-charset))
4565 (message-options message-options)
4566 (message-options-set-recipient)
4567 (mail-parse-ignored-charsets
4568 (or gnus-article-ignored-charsets
4569 ',gnus-newsgroup-ignored-charsets)))
4571 (mml-destroy-buffers)
4572 (remove-hook 'kill-buffer-hook
4573 'mml-destroy-buffers t)
4574 (kill-local-variable 'mml-buffer-list))
4575 (gnus-summary-edit-article-done
4576 ,(or (mail-header-references gnus-current-headers) "")
4577 ,(gnus-group-read-only-p)
4578 ,gnus-summary-buffer no-highlight))
4580 (gnus-article-edit-done)
4581 (gnus-summary-expand-window)
4582 (gnus-summary-show-article)
4583 (when (and current-id (integerp gnus-auto-select-part))
4584 (gnus-article-jump-to-part
4585 (+ current-id gnus-auto-select-part)))))
4587 (defun gnus-mime-replace-part (file)
4588 "Replace MIME part under point with an external body."
4589 ;; Useful if file has already been saved to disk
4593 (read-file-name "Replace MIME part with file: "
4594 (or mm-default-directory default-directory)
4596 (gnus-mime-save-part-and-strip file))
4598 (defun gnus-mime-save-part-and-strip (&optional file)
4599 "Save the MIME part under point then replace it with an external body.
4600 If FILE is given, use it for the external part."
4602 (gnus-article-check-buffer)
4603 (when (gnus-group-read-only-p)
4604 (error "The current group does not support deleting of parts"))
4605 (when (mm-complicated-handles gnus-article-mime-handles)
4607 The current article has a complicated MIME structure, giving up..."))
4608 (let* ((data (get-text-property (point) 'gnus-data))
4609 (id (get-text-property (point) 'gnus-part))
4611 (handles gnus-article-mime-handles))
4614 (and data (mm-save-part data "Delete MIME part and save to: "))))
4616 (with-current-buffer (mm-handle-buffer data)
4618 (insert "Content-Type: " (mm-handle-media-type data))
4619 (mml-insert-parameter-string (cdr (mm-handle-type data))
4622 (insert "Content-ID: " (message-make-message-id) "\n")
4623 (insert "Content-Transfer-Encoding: binary\n")
4626 (cdr (mm-make-handle nil
4627 `("message/external-body"
4628 (access-type . "LOCAL-FILE")
4630 ;; (set-buffer gnus-summary-buffer)
4631 (gnus-article-edit-part handles id))))
4633 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4634 ;; parts...>') but with stripping would be nice.
4636 (defun gnus-mime-delete-part ()
4637 "Delete the MIME part under point.
4638 Replace it with some information about the removed part."
4640 (gnus-article-check-buffer)
4641 (when (gnus-group-read-only-p)
4642 (error "The current group does not support deleting of parts"))
4643 (when (mm-complicated-handles gnus-article-mime-handles)
4645 The current article has a complicated MIME structure, giving up..."))
4646 (when (or gnus-expert-user
4647 (gnus-yes-or-no-p "\
4648 Deleting parts may malfunction or destroy the article; continue? "))
4649 (let* ((data (get-text-property (point) 'gnus-data))
4650 (id (get-text-property (point) 'gnus-part))
4651 (handles gnus-article-mime-handles)
4655 (mail-decode-encoded-word-string (or (mm-handle-description data)
4658 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4660 (type (mm-handle-media-type data)))
4662 (error "No MIME part under point"))
4663 (with-current-buffer (mm-handle-buffer data)
4664 (let ((bsize (format "%s" (buffer-size))))
4669 "| The following attachment has been deleted:\n"
4671 "| Type: " type "\n"
4672 "| Filename: " filename "\n"
4673 "| Size (encoded): " bsize " Byte\n"
4674 "| Description: " description "\n"
4677 (cdr (mm-make-handle
4678 nil `("text/plain") nil nil
4680 (format "Deleted attachment (%s bytes)" bsize))))))
4681 ;; (set-buffer gnus-summary-buffer)
4682 (gnus-article-edit-part handles id))))
4684 (defun gnus-mime-save-part ()
4685 "Save the MIME part under point."
4687 (gnus-article-check-buffer)
4688 (let ((data (get-text-property (point) 'gnus-data)))
4690 (mm-save-part data))))
4692 (defun gnus-mime-pipe-part ()
4693 "Pipe the MIME part under point to a process."
4695 (gnus-article-check-buffer)
4696 (let ((data (get-text-property (point) 'gnus-data)))
4698 (mm-pipe-part data))))
4700 (defun gnus-mime-view-part ()
4701 "Interactively choose a viewing method for the MIME part under point."
4703 (gnus-article-check-buffer)
4704 (let ((data (get-text-property (point) 'gnus-data)))
4706 (setq gnus-article-mime-handles
4708 gnus-article-mime-handles (setq data (copy-sequence data))))
4709 (mm-interactively-view-part data))))
4711 (defun gnus-mime-view-part-as-type-internal ()
4712 (gnus-article-check-buffer)
4713 (let* ((handle (get-text-property (point) 'gnus-data))
4715 ;; Content-Type: foo/bar; name=...
4716 (mail-content-type-get (mm-handle-type handle) 'name)
4717 ;; Content-Disposition: attachment; filename=...
4718 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4719 (def-type (and name (mm-default-file-encoding name))))
4720 (and def-type (cons def-type 0))))
4722 (defun gnus-mime-view-part-as-type (&optional mime-type)
4723 "Choose a MIME media type, and view the part as such."
4727 (let ((default (gnus-mime-view-part-as-type-internal)))
4729 (format "View as MIME type (default %s): "
4731 (mapcar #'list (mailcap-mime-types))
4734 (gnus-article-check-buffer)
4735 (let ((handle (get-text-property (point) 'gnus-data)))
4738 (mm-make-handle (mm-handle-buffer handle)
4739 (cons mime-type (cdr (mm-handle-type handle)))
4740 (mm-handle-encoding handle)
4741 (mm-handle-undisplayer handle)
4742 (mm-handle-disposition handle)
4743 (mm-handle-description handle)
4745 (mm-handle-id handle)))
4746 (setq gnus-article-mime-handles
4747 (mm-merge-handles gnus-article-mime-handles handle))
4748 (gnus-mm-display-part handle))))
4750 (defun gnus-mime-copy-part (&optional handle arg)
4751 "Put the MIME part under point into a new buffer.
4752 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4754 (interactive (list nil current-prefix-arg))
4755 (gnus-article-check-buffer)
4757 (setq handle (get-text-property (point) 'gnus-data)))
4759 (let ((filename (or (mail-content-type-get (mm-handle-disposition handle)
4761 (mail-content-type-get (mm-handle-disposition handle)
4763 contents dont-decode charset coding-system)
4764 (mm-with-unibyte-buffer
4765 (mm-insert-part handle)
4766 (setq contents (or (condition-case nil
4767 (mm-decompress-buffer filename nil 'sig)
4769 (setq dont-decode t)
4772 (setq filename (cond (filename (file-name-nondirectory filename))
4773 (dont-decode "*raw data*")
4778 (unless (setq charset (mail-content-type-get
4779 (mm-handle-type handle) 'charset))
4780 (unless (setq coding-system (mm-with-unibyte-buffer
4782 (mm-find-buffer-file-coding-system)))
4783 (setq charset gnus-newsgroup-charset))))
4785 (setq charset (or (cdr (assq arg
4786 gnus-summary-show-article-charset-alist))
4787 (mm-read-coding-system "Charset: ")))))
4788 (switch-to-buffer (generate-new-buffer filename))
4789 (if (or coding-system
4791 (setq coding-system (mm-charset-to-coding-system charset))
4792 (not (eq charset 'ascii))))
4794 (mm-enable-multibyte)
4795 (insert (mm-decode-coding-string contents coding-system))
4796 (setq buffer-file-coding-system
4797 (if (boundp 'last-coding-system-used)
4798 (symbol-value 'last-coding-system-used)
4800 (mm-disable-multibyte)
4802 (setq buffer-file-coding-system mm-binary-coding-system))
4803 ;; We do it this way to make `normal-mode' set the appropriate mode.
4806 (setq buffer-file-name (expand-file-name filename))
4808 (setq buffer-file-name nil))
4809 (goto-char (point-min)))))
4811 (defun gnus-mime-print-part (&optional handle filename)
4812 "Print the MIME part under point."
4813 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4814 (gnus-article-check-buffer)
4815 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4816 (contents (and handle (mm-get-part handle)))
4817 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4818 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4823 (mm-save-part-to-file handle file)
4824 (call-process shell-file-name nil
4825 (generate-new-buffer " *mm*")
4827 shell-command-switch
4829 printer file (mm-handle-type handle))))
4833 (gnus-print-buffer))
4834 (ps-despool filename)))))
4836 (defun gnus-mime-inline-part (&optional handle arg)
4837 "Insert the MIME part under point into the current buffer.
4838 Compressed files like .gz and .bz2 are decompressed."
4839 (interactive (list nil current-prefix-arg))
4840 (gnus-article-check-buffer)
4842 (setq handle (get-text-property (point) 'gnus-data)))
4845 (inhibit-read-only t)
4846 contents charset coding-system)
4847 (if (and (not arg) (mm-handle-undisplayer handle))
4848 (mm-remove-part handle)
4849 (mm-with-unibyte-buffer
4850 (mm-insert-part handle)
4852 (or (mm-decompress-buffer
4853 (or (mail-content-type-get (mm-handle-disposition handle)
4855 (mail-content-type-get (mm-handle-disposition handle)
4861 (unless (setq charset (mail-content-type-get
4862 (mm-handle-type handle) 'charset))
4863 (unless (setq coding-system
4864 (mm-with-unibyte-buffer
4866 (mm-find-buffer-file-coding-system)))
4867 (setq charset gnus-newsgroup-charset))))
4869 (if (mm-handle-undisplayer handle)
4870 (mm-remove-part handle))
4873 gnus-summary-show-article-charset-alist))
4874 (mm-read-coding-system "Charset: "))))
4876 (if (mm-handle-undisplayer handle)
4877 (mm-remove-part handle))))
4881 (if (or coding-system
4884 (mm-charset-to-coding-system charset))
4885 (not (eq coding-system 'ascii))))
4886 (mm-decode-coding-string contents coding-system)
4887 (mm-string-to-multibyte contents)))
4890 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4891 "Insert the MIME part under point into the current buffer using the
4893 (interactive (list nil current-prefix-arg))
4894 (gnus-article-check-buffer)
4895 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4898 (inhibit-read-only t))
4900 (if (mm-handle-undisplayer handle)
4901 (mm-remove-part handle))
4902 (let ((gnus-newsgroup-charset
4904 gnus-summary-show-article-charset-alist))
4905 (mm-read-coding-system "Charset: ")))
4906 (gnus-newsgroup-ignored-charsets 'gnus-all))
4907 (gnus-article-press-button)))))
4909 (defun gnus-mime-view-part-externally (&optional handle)
4910 "View the MIME part under point with an external viewer."
4912 (gnus-article-check-buffer)
4913 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4914 (mm-user-display-methods nil)
4915 (mm-inlined-types nil)
4916 (mail-parse-charset gnus-newsgroup-charset)
4917 (mail-parse-ignored-charsets
4918 (with-current-buffer gnus-summary-buffer
4919 gnus-newsgroup-ignored-charsets)))
4921 (if (mm-handle-undisplayer handle)
4922 (mm-remove-part handle)
4923 (mm-display-part handle)))))
4925 (defun gnus-mime-view-part-internally (&optional handle)
4926 "View the MIME part under point with an internal viewer.
4927 If no internal viewer is available, use an external viewer."
4929 (gnus-article-check-buffer)
4930 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4931 (mm-inlined-types '(".*"))
4932 (mm-inline-large-images t)
4933 (mail-parse-charset gnus-newsgroup-charset)
4934 (mail-parse-ignored-charsets
4935 (with-current-buffer gnus-summary-buffer
4936 gnus-newsgroup-ignored-charsets))
4937 (inhibit-read-only t))
4939 (if (mm-handle-undisplayer handle)
4940 (mm-remove-part handle)
4941 (mm-display-part handle)))))
4943 (defun gnus-mime-action-on-part (&optional action)
4944 "Do something with the MIME attachment at \(point\)."
4946 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4947 (gnus-article-check-buffer)
4948 (let ((action-pair (assoc action gnus-mime-action-alist)))
4950 (funcall (cdr action-pair)))))
4952 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
4953 "Call FUNCTION on MIME part N.
4954 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
4955 If INTERACTIVE, call FUNCTION interactivly."
4957 ;; Check whether the article is displayed.
4958 (unless (and (gnus-buffer-live-p gnus-article-buffer)
4959 (setq window (get-buffer-window gnus-article-buffer t))
4960 (frame-visible-p (setq frame (window-frame window))))
4961 (error "No article is displayed"))
4962 (with-current-buffer gnus-article-buffer
4963 ;; Check whether the article displays the right contents.
4964 (unless (with-current-buffer gnus-summary-buffer
4965 (eq gnus-current-article (gnus-summary-article-number)))
4966 (error "You should select the right article first"))
4967 ;; Check whether the specified part exists.
4968 (when (> n (length gnus-article-mime-handle-alist))
4969 (error "No such part")))
4972 ;; To select the window is needed so that the cursor
4973 ;; might be visible on the MIME button.
4974 (select-window (prog1
4976 (setq window (selected-window))
4977 ;; Article may be displayed in the other frame.
4978 (gnus-select-frame-set-input-focus
4981 (setq frame (selected-frame))))))
4982 (when (gnus-article-goto-part n)
4983 ;; We point the cursor and the arrow at the MIME button
4984 ;; when the `function' prompt the user for something.
4985 (let ((cursor-in-non-selected-windows t)
4986 (overlay-arrow-string "=>")
4987 (overlay-arrow-position (point-marker)))
4990 ((and no-handle interactive)
4991 (call-interactively function))
4997 (cdr (assq n gnus-article-mime-handle-alist))))
5000 (cdr (assq n gnus-article-mime-handle-alist)))))
5001 (set-marker overlay-arrow-position nil)
5002 (unless gnus-auto-select-part
5003 (gnus-select-frame-set-input-focus frame)
5004 (select-window window))))
5006 (if gnus-inhibit-mime-unbuttonizing
5007 ;; This is the default though the program shouldn't reach here.
5008 (error "No such part")
5009 ;; The part which doesn't have the MIME button is selected.
5010 ;; So, we display all the buttons and redo it.
5011 (let ((gnus-inhibit-mime-unbuttonizing t))
5012 (gnus-summary-show-article)
5013 (gnus-article-part-wrapper n function no-handle))))))
5015 (defun gnus-article-pipe-part (n)
5016 "Pipe MIME part N, which is the numerical prefix."
5018 (gnus-article-part-wrapper n 'mm-pipe-part))
5020 (defun gnus-article-save-part (n)
5021 "Save MIME part N, which is the numerical prefix."
5023 (gnus-article-part-wrapper n 'mm-save-part))
5025 (defun gnus-article-interactively-view-part (n)
5026 "View MIME part N interactively, which is the numerical prefix."
5028 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5030 (defun gnus-article-copy-part (n)
5031 "Copy MIME part N, which is the numerical prefix."
5033 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5035 (defun gnus-article-view-part-as-charset (n)
5036 "View MIME part N using a specified charset.
5037 N is the numerical prefix."
5039 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5041 (defun gnus-article-view-part-externally (n)
5042 "View MIME part N externally, which is the numerical prefix."
5044 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5046 (defun gnus-article-inline-part (n)
5047 "Inline MIME part N, which is the numerical prefix."
5049 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5051 (defun gnus-article-save-part-and-strip (n)
5052 "Save MIME part N and replace it with an external body.
5053 N is the numerical prefix."
5055 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5057 (defun gnus-article-replace-part (n)
5058 "Replace MIME part N with an external body.
5059 N is the numerical prefix."
5061 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5063 (defun gnus-article-delete-part (n)
5064 "Delete MIME part N and add some information about the removed part.
5065 N is the numerical prefix."
5067 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5069 (defun gnus-article-mime-match-handle-first (condition)
5072 (dolist (ihandle gnus-article-mime-handle-alist)
5074 ((functionp condition)
5075 (funcall condition (cdr ihandle)))
5076 ((eq condition 'undisplayed)
5077 (not (or (mm-handle-undisplayer (cdr ihandle))
5078 (equal (mm-handle-media-type (cdr ihandle))
5079 "multipart/alternative"))))
5080 ((eq condition 'undisplayed-alternative)
5081 (not (mm-handle-undisplayer (cdr ihandle))))
5083 (gnus-article-goto-part (car ihandle))
5084 (or (not n) (< (car ihandle) n)))
5085 (setq n (car ihandle))))
5089 (defun gnus-article-view-part (&optional n)
5090 "View MIME part N, which is the numerical prefix."
5092 (with-current-buffer gnus-article-buffer
5093 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5094 gnus-article-mime-match-handle-function)))
5095 (when (> n (length gnus-article-mime-handle-alist))
5096 (error "No such part"))
5097 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5098 (when (gnus-article-goto-part n)
5099 (if (equal (car handle) "multipart/alternative")
5100 (gnus-article-press-button)
5101 (when (eq (gnus-mm-display-part handle) 'internal)
5102 (gnus-set-window-start)))))))
5104 (defsubst gnus-article-mime-total-parts ()
5105 (if (bufferp (car gnus-article-mime-handles))
5107 (1- (length gnus-article-mime-handles))))
5109 (defun gnus-mm-display-part (handle)
5110 "Display HANDLE and fix MIME button."
5111 (let ((id (get-text-property (point) 'gnus-part))
5113 (inhibit-read-only t))
5116 (let ((window (selected-window))
5117 (mail-parse-charset gnus-newsgroup-charset)
5118 (mail-parse-ignored-charsets
5119 (if (gnus-buffer-live-p gnus-summary-buffer)
5120 (with-current-buffer gnus-summary-buffer
5121 gnus-newsgroup-ignored-charsets)
5125 (let ((win (gnus-get-buffer-window (current-buffer) t))
5128 (select-window win))
5131 (if (mm-handle-displayed-p handle)
5132 ;; This will remove the part.
5133 (mm-display-part handle)
5135 (narrow-to-region (point)
5136 (if (eobp) (point) (1+ (point))))
5137 (mm-display-part handle)
5138 ;; We narrow to the part itself and
5139 ;; then call the treatment functions.
5140 (goto-char (point-min))
5142 (narrow-to-region (point) (point-max))
5145 (gnus-article-mime-total-parts)
5146 (mm-handle-media-type handle)))))
5147 (if (window-live-p window)
5148 (select-window window)))))
5151 (gnus-insert-mime-button
5152 handle id (list (mm-handle-displayed-p handle)))
5153 (goto-char point))))
5155 (defun gnus-article-goto-part (n)
5156 "Go to MIME part N."
5157 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5159 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5160 (let ((gnus-tmp-name
5161 (or (mail-content-type-get (mm-handle-type handle) 'name)
5162 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5163 (mail-content-type-get (mm-handle-type handle) 'url)
5165 (gnus-tmp-type (mm-handle-media-type handle))
5166 (gnus-tmp-description
5167 (mail-decode-encoded-word-string (or (mm-handle-description handle)
5170 (if (if displayed (car displayed)
5171 (mm-handle-displayed-p handle))
5173 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5175 gnus-tmp-type-long b e)
5176 (when (string-match ".*/" gnus-tmp-name)
5177 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5178 (setq gnus-tmp-type-long (concat gnus-tmp-type
5179 (and (not (equal gnus-tmp-name ""))
5180 (concat "; " gnus-tmp-name))))
5181 (unless (equal gnus-tmp-description "")
5182 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5187 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5188 `(keymap ,gnus-mime-button-map
5189 gnus-callback gnus-mm-display-part
5190 gnus-part ,gnus-tmp-id
5191 article-type annotation
5194 ;; Exclude a newline.
5197 (widget-convert-button
5200 :action 'gnus-widget-press-button
5201 :button-keymap gnus-mime-button-map
5203 (lambda (widget/window &optional overlay pos)
5204 ;; Needed to properly clear the message due to a bug in
5205 ;; wid-edit (XEmacs only).
5206 (if (boundp 'help-echo-owns-message)
5207 (setq help-echo-owns-message t))
5209 "%S: %s the MIME part; %S: more options"
5210 (aref gnus-mouse-2 0)
5211 ;; XEmacs will get a single widget arg; Emacs 21 will get
5212 ;; window, overlay, position.
5213 (if (mm-handle-displayed-p
5215 (with-current-buffer (gnus-overlay-buffer overlay)
5216 (widget-get (widget-at (gnus-overlay-start overlay))
5218 (widget-get widget/window :mime-handle)))
5220 (aref gnus-down-mouse-3 0))))))
5222 (defun gnus-widget-press-button (elems el)
5223 (goto-char (widget-get elems :from))
5224 (gnus-article-press-button))
5226 (defvar gnus-displaying-mime nil)
5228 (defun gnus-display-mime (&optional ihandles)
5229 "Display the MIME parts."
5231 (save-selected-window
5232 (let ((window (get-buffer-window gnus-article-buffer))
5235 (select-window window)
5236 ;; We have to do this since selecting the window
5237 ;; may change the point. So we set the window point.
5238 (set-window-point window point)))
5239 (let ((handles ihandles)
5240 (inhibit-read-only t)
5243 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5244 (when gnus-article-emulate-mime
5245 (mm-uu-dissect-text-parts handles)))
5246 (gnus-article-emulate-mime
5247 (setq handles (mm-uu-dissect))))
5248 (when (and (not ihandles)
5249 (not gnus-displaying-mime))
5250 ;; Top-level call; we clean up.
5251 (when gnus-article-mime-handles
5252 (mm-destroy-parts gnus-article-mime-handles)
5253 (setq gnus-article-mime-handle-alist nil));; A trick.
5254 (setq gnus-article-mime-handles handles)
5255 ;; We allow users to glean info from the handles.
5256 (when gnus-article-mime-part-function
5257 (gnus-mime-part-function handles)))
5259 (or (not (stringp (car handles)))
5262 (when (and (not ihandles)
5263 (not gnus-displaying-mime))
5264 ;; Clean up for mime parts.
5266 (delete-region (point) (point-max)))
5267 (let ((gnus-displaying-mime t))
5268 (gnus-mime-display-part handles)))
5271 (narrow-to-region (point) (point-max))
5272 (gnus-treat-article nil 1 1)
5275 ;; Highlight the headers.
5279 (narrow-to-region (point-min) (point))
5280 (gnus-article-save-original-date
5281 (gnus-treat-article 'head)))))))))
5283 (defcustom gnus-mime-display-multipart-as-mixed nil
5284 "Display \"multipart\" parts as \"multipart/mixed\".
5286 If t, it overrides nil values of
5287 `gnus-mime-display-multipart-alternative-as-mixed' and
5288 `gnus-mime-display-multipart-related-as-mixed'."
5289 :group 'gnus-article-mime
5292 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5293 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5295 :group 'gnus-article-mime
5298 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5299 "Display \"multipart/related\" parts as \"multipart/mixed\".
5301 If displaying \"text/html\" is discouraged \(see
5302 `mm-discouraged-alternatives'\) images or other material inside a
5303 \"multipart/related\" part might be overlooked when this variable is nil."
5305 :group 'gnus-article-mime
5308 (defun gnus-mime-display-part (handle)
5310 ;; Maybe a broken MIME message.
5313 ((not (stringp (car handle)))
5314 (gnus-mime-display-single handle))
5315 ;; User-defined multipart
5316 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5317 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5319 ;; multipart/alternative
5320 ((and (equal (car handle) "multipart/alternative")
5321 (not (or gnus-mime-display-multipart-as-mixed
5322 gnus-mime-display-multipart-alternative-as-mixed)))
5323 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5324 (push (cons id handle) gnus-article-mime-handle-alist)
5325 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5326 ;; multipart/related
5327 ((and (equal (car handle) "multipart/related")
5328 (not (or gnus-mime-display-multipart-as-mixed
5329 gnus-mime-display-multipart-related-as-mixed)))
5330 ;;;!!!We should find the start part, but we just default
5331 ;;;!!!to the first part.
5332 ;;(gnus-mime-display-part (cadr handle))
5333 ;;;!!! Most multipart/related is an HTML message plus images.
5334 ;;;!!! Unfortunately we are unable to let W3 display those
5335 ;;;!!! included images, so we just display it as a mixed multipart.
5336 ;;(gnus-mime-display-mixed (cdr handle))
5337 ;;;!!! No, w3 can display everything just fine.
5338 (gnus-mime-display-part (cadr handle)))
5339 ((equal (car handle) "multipart/signed")
5340 (gnus-add-wash-type 'signed)
5341 (gnus-mime-display-security handle))
5342 ((equal (car handle) "multipart/encrypted")
5343 (gnus-add-wash-type 'encrypted)
5344 (gnus-mime-display-security handle))
5345 ;; Other multiparts are handled like multipart/mixed.
5347 (gnus-mime-display-mixed (cdr handle)))))
5349 (defun gnus-mime-part-function (handles)
5350 (if (stringp (car handles))
5351 (mapcar 'gnus-mime-part-function (cdr handles))
5352 (funcall gnus-article-mime-part-function handles)))
5354 (defun gnus-mime-display-mixed (handles)
5355 (mapcar 'gnus-mime-display-part handles))
5357 (defun gnus-mime-display-single (handle)
5358 (let ((type (mm-handle-media-type handle))
5359 (ignored gnus-ignored-mime-types)
5366 (when (string-match (pop ignored) type)
5367 (throw 'ignored nil)))
5368 (if (and (setq not-attachment
5369 (and (not (mm-inline-override-p handle))
5370 (or (not (mm-handle-disposition handle))
5371 (equal (car (mm-handle-disposition handle))
5373 (mm-attachment-override-p handle))))
5374 (mm-automatic-display-p handle)
5376 (mm-inlinable-p handle)
5377 (mm-inlined-p handle))
5378 (mm-automatic-external-display-p type)))
5380 (when (equal (mm-handle-media-supertype handle) "text")
5382 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5384 (push (cons id handle) gnus-article-mime-handle-alist)
5385 (when (or (not display)
5386 (not (gnus-unbuttonized-mime-type-p type)))
5387 (gnus-insert-mime-button
5388 handle id (list (or display (and not-attachment text))))
5389 (gnus-article-insert-newline)
5390 ;; Remember modify the number of forward lines.
5398 (let ((mail-parse-charset gnus-newsgroup-charset)
5399 (mail-parse-ignored-charsets
5400 (save-excursion (condition-case ()
5401 (set-buffer gnus-summary-buffer)
5403 gnus-newsgroup-ignored-charsets)))
5404 (mm-display-part handle t))
5405 (goto-char (point-max)))
5406 ((and text not-attachment)
5410 (gnus-article-insert-newline)
5413 (let ((charset (mail-content-type-get (mm-handle-type handle)
5415 (cond ((not charset)
5416 (mm-string-as-multibyte (mm-get-part handle)))
5417 ((eq charset 'gnus-decoded)
5418 (with-current-buffer (mm-handle-buffer handle)
5421 (mm-decode-string (mm-get-part handle) charset)))))
5422 (goto-char (point-max))))
5426 (narrow-to-region beg (point))
5429 (gnus-article-mime-total-parts)
5430 (mm-handle-media-type handle)))))))))
5432 (defun gnus-unbuttonized-mime-type-p (type)
5433 "Say whether TYPE is to be unbuttonized."
5434 (unless gnus-inhibit-mime-unbuttonizing
5436 (let ((types gnus-unbuttonized-mime-types))
5438 (when (string-match (pop types) type)
5439 (throw 'found t)))))
5441 (let ((types gnus-buttonized-mime-types))
5443 (when (string-match (pop types) type)
5444 (throw 'found t)))))))))
5446 (defun gnus-article-insert-newline ()
5447 "Insert a newline, but mark it as undeletable."
5448 (gnus-put-text-property
5449 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5451 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5452 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5455 handle (inhibit-read-only t) from props begend not-pref)
5456 (save-window-excursion
5459 (narrow-to-region (car ibegend)
5462 (goto-char (car ibegend))
5465 (delete-region (point-min) (point-max))
5466 (mm-remove-parts handles))
5467 (setq begend (list (point-marker)))
5469 (unless (setq not-pref (cadr (member preferred ihandles)))
5470 (setq not-pref (car ihandles)))
5473 (not (gnus-unbuttonized-mime-type-p
5474 "multipart/alternative")))
5475 (gnus-add-text-properties
5478 (insert (format "%d. " id))
5482 (unless ,(not ibegend)
5483 (setq gnus-article-mime-handle-alist
5484 ',gnus-article-mime-handle-alist))
5485 (gnus-mime-display-alternative
5486 ',ihandles ',not-pref ',begend ,id))
5487 keymap ,gnus-mime-button-map
5488 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5489 face ,gnus-article-button-face
5491 article-type multipart))
5492 (widget-convert-button 'link from (point)
5493 :action 'gnus-widget-press-button
5494 :button-keymap gnus-widget-button-keymap)
5496 (while (setq handle (pop handles))
5497 (gnus-add-text-properties
5500 (insert (format "(%c) %-18s"
5501 (if (equal handle preferred) ?* ? )
5502 (mm-handle-media-type handle)))
5506 (unless ,(not ibegend)
5507 (setq gnus-article-mime-handle-alist
5508 ',gnus-article-mime-handle-alist))
5509 (gnus-mime-display-alternative
5510 ',ihandles ',handle ',begend ,id))
5511 keymap ,gnus-mime-button-map
5512 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5513 face ,gnus-article-button-face
5516 (widget-convert-button 'link from (point)
5517 :action 'gnus-widget-press-button
5518 :button-keymap gnus-widget-button-keymap)
5522 (if (stringp (car preferred))
5523 (gnus-display-mime preferred)
5524 (let ((mail-parse-charset gnus-newsgroup-charset)
5525 (mail-parse-ignored-charsets
5526 (with-current-buffer gnus-summary-buffer
5527 gnus-newsgroup-ignored-charsets)))
5528 (mm-display-part preferred)
5532 (narrow-to-region (car begend) (point-max))
5534 nil (length gnus-article-mime-handle-alist)
5535 (gnus-article-mime-total-parts)
5536 (mm-handle-media-type handle))))))
5537 (goto-char (point-max))
5538 (setcdr begend (point-marker)))))
5540 (goto-char point))))
5542 (defconst gnus-article-wash-status-strings
5543 (let ((alist '((cite "c" "Possible hidden citation text"
5544 " " "All citation text visible")
5545 (headers "h" "Hidden headers"
5546 " " "All headers visible.")
5547 (pgp "p" "Encrypted or signed message status hidden"
5548 " " "No hidden encryption nor digital signature status")
5549 (signature "s" "Signature has been hidden"
5550 " " "Signature is visible")
5551 (overstrike "o" "Overstrike (^H) characters applied"
5552 " " "No overstrike characters applied")
5553 (gnus-show-mime "m" "Mime processing is activated"
5554 " " "Mime processing is not activated")
5555 (emphasis "e" "/*_Emphasis_*/ characters applied"
5556 " " "No /*_emphasis_*/ characters applied")))
5558 (dolist (entry alist result)
5559 (let ((key (nth 0 entry))
5560 (on (copy-sequence (nth 1 entry)))
5561 (on-help (nth 2 entry))
5562 (off (copy-sequence (nth 3 entry)))
5563 (off-help (nth 4 entry)))
5564 (put-text-property 0 1 'help-echo on-help on)
5565 (put-text-property 0 1 'help-echo off-help off)
5566 (push (list key on off) result))))
5567 "Alist of strings describing wash status in the mode line.
5568 Each entry has the form (KEY ON OF), where the KEY is a symbol
5569 representing the particular washing function, ON is the string to use
5570 in the article mode line when the washing function is active, and OFF
5571 is the string to use when it is inactive.")
5573 (defun gnus-article-wash-status-entry (key value)
5574 (let ((entry (assoc key gnus-article-wash-status-strings)))
5575 (if value (nth 1 entry) (nth 2 entry))))
5577 (defun gnus-article-wash-status ()
5578 "Return a string which display status of article washing."
5579 (with-current-buffer gnus-article-buffer
5580 (let ((cite (memq 'cite gnus-article-wash-types))
5581 (headers (memq 'headers gnus-article-wash-types))
5582 (boring (memq 'boring-headers gnus-article-wash-types))
5583 (pgp (memq 'pgp gnus-article-wash-types))
5584 (pem (memq 'pem gnus-article-wash-types))
5585 (signed (memq 'signed gnus-article-wash-types))
5586 (encrypted (memq 'encrypted gnus-article-wash-types))
5587 (signature (memq 'signature gnus-article-wash-types))
5588 (overstrike (memq 'overstrike gnus-article-wash-types))
5589 (emphasis (memq 'emphasis gnus-article-wash-types)))
5591 (gnus-article-wash-status-entry 'cite cite)
5592 (gnus-article-wash-status-entry 'headers (or headers boring))
5593 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5594 (gnus-article-wash-status-entry 'signature signature)
5595 (gnus-article-wash-status-entry 'overstrike overstrike)
5596 (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
5597 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5599 (defun gnus-add-wash-type (type)
5600 "Add a washing of TYPE to the current status."
5601 (add-to-list 'gnus-article-wash-types type))
5603 (defun gnus-delete-wash-type (type)
5604 "Add a washing of TYPE to the current status."
5605 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5607 (defun gnus-add-image (category image)
5608 "Add IMAGE of CATEGORY to the list of displayed images."
5609 (let ((entry (assq category gnus-article-image-alist)))
5611 (setq entry (list category))
5612 (push entry gnus-article-image-alist))
5613 (nconc entry (list image))))
5615 (defun gnus-delete-images (category)
5616 "Delete all images in CATEGORY."
5617 (let ((entry (assq category gnus-article-image-alist)))
5618 (dolist (image (cdr entry))
5619 (gnus-remove-image image category))
5620 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5621 (gnus-delete-wash-type category)))
5623 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5625 (defun gnus-article-maybe-hide-headers ()
5626 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5627 Provided for backwards compatibility."
5628 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5629 (not (with-current-buffer gnus-summary-buffer
5630 gnus-have-all-headers)))
5631 (not gnus-inhibit-hiding))
5632 (gnus-article-hide-headers)))
5636 (defun gnus-output-to-file (file-name)
5637 "Append the current article to a file named FILE-NAME."
5638 (let ((artbuf (current-buffer)))
5640 (insert-buffer-substring artbuf)
5641 ;; Append newline at end of the buffer as separator, and then
5643 (goto-char (point-max))
5645 (let ((file-name-coding-system nnmail-pathname-coding-system))
5646 (write-region-as-binary (point-min) (point-max) file-name 'append))
5649 (defun gnus-narrow-to-page (&optional arg)
5650 "Narrow the article buffer to a page.
5651 If given a numerical ARG, move forward ARG pages."
5653 (setq arg (if arg (prefix-numeric-value arg) 0))
5655 (set-buffer gnus-article-buffer)
5656 (goto-char (point-min))
5658 ;; Remove any old next/prev buttons.
5659 (when (gnus-visual-p 'page-marker)
5660 (let ((inhibit-read-only t))
5661 (gnus-remove-text-with-property 'gnus-prev)
5662 (gnus-remove-text-with-property 'gnus-next)))
5665 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5667 (re-search-forward page-delimiter nil 'move arg)))
5668 (goto-char (match-end 0))
5670 (goto-char (point-min))
5671 (setq gnus-page-broken
5672 (and (re-search-forward page-delimiter nil t) t))))
5673 (when gnus-page-broken
5676 (if (re-search-forward page-delimiter nil 'move)
5679 (when (and (gnus-visual-p 'page-marker)
5680 (> (point-min) (save-restriction (widen) (point-min))))
5682 (goto-char (point-min))
5683 (gnus-insert-prev-page-button)))
5684 (when (and (gnus-visual-p 'page-marker)
5685 (< (point-max) (save-restriction (widen) (point-max))))
5687 (goto-char (point-max))
5688 (gnus-insert-next-page-button))))))
5690 ;; Article mode commands
5692 (defun gnus-article-goto-next-page ()
5693 "Show the next page of the article."
5695 (when (gnus-article-next-page)
5696 (goto-char (point-min))
5697 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5700 (defun gnus-article-goto-prev-page ()
5701 "Show the previous page of the article."
5704 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5705 (gnus-article-prev-page nil)))
5707 ;; This is cleaner but currently breaks `gnus-pick-mode':
5709 ;; (defun gnus-article-goto-next-page ()
5710 ;; "Show the next page of the article."
5712 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5713 ;; (gnus-summary-next-page)))
5715 ;; (defun gnus-article-goto-prev-page ()
5716 ;; "Show the next page of the article."
5718 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5719 ;; (gnus-summary-prev-page)))
5721 (defun gnus-article-next-page (&optional lines)
5722 "Show the next page of the current article.
5723 If end of article, return non-nil. Otherwise return nil.
5724 Argument LINES specifies lines to be scrolled up."
5726 (move-to-window-line -1)
5729 (and (pos-visible-in-window-p) ;Not continuation line.
5730 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5731 ;; Nothing in this page.
5732 (if (or (not gnus-page-broken)
5737 (eobp)))) ;Real end-of-buffer?
5739 (when gnus-article-over-scroll
5740 (gnus-article-next-page-1 lines))
5742 (gnus-narrow-to-page 1) ;Go to next page.
5744 ;; More in this page.
5745 (gnus-article-next-page-1 lines)
5748 (defmacro gnus-article-beginning-of-window ()
5749 "Move point to the beginning of the window.
5750 In Emacs, the point is placed at the line number which `scroll-margin'
5752 (if (featurep 'xemacs)
5753 '(move-to-window-line 0)
5754 '(move-to-window-line
5755 (min (max 0 scroll-margin)
5756 (max 1 (- (window-height)
5757 (if mode-line-format 1 0)
5758 (if header-line-format 1 0)))))))
5760 (defun gnus-article-next-page-1 (lines)
5761 (when (and (not (featurep 'xemacs))
5764 (numberp (symbol-value 'scroll-margin))
5765 (> (symbol-value 'scroll-margin) 0))
5766 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5767 ;; too many number of lines if `scroll-margin' is set as two or greater.
5768 (setq lines (min lines
5769 (max 0 (- (count-lines (window-start) (point-max))
5770 (symbol-value 'scroll-margin))))))
5772 (let ((scroll-in-place nil))
5775 ;; Long lines may cause an end-of-buffer error.
5776 (goto-char (point-max))))
5777 (gnus-article-beginning-of-window))
5779 (defun gnus-article-prev-page (&optional lines)
5780 "Show previous page of current article.
5781 Argument LINES specifies lines to be scrolled down."
5783 (move-to-window-line 0)
5784 (if (and gnus-page-broken
5786 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5788 (gnus-narrow-to-page -1) ;Go to previous page.
5789 (goto-char (point-max))
5793 (let ((scroll-in-place nil))
5794 (scroll-down lines))
5795 (beginning-of-buffer
5796 (goto-char (point-min))))
5797 (gnus-article-beginning-of-window))))
5799 (defun gnus-article-only-boring-p ()
5800 "Decide whether there is only boring text remaining in the article.
5801 Something \"interesting\" is a word of at least two letters that does
5802 not have a face in `gnus-article-boring-faces'."
5803 (when (and gnus-article-skip-boring
5804 (boundp 'gnus-article-boring-faces)
5805 (symbol-value 'gnus-article-boring-faces))
5808 (while (re-search-forward "\\b\\w\\w" nil t)
5810 (when (not (gnus-intersection
5811 (gnus-faces-at (point))
5812 (symbol-value 'gnus-article-boring-faces)))
5813 (throw 'only-boring nil)))
5814 (throw 'only-boring t)))))
5816 (defun gnus-article-refer-article ()
5817 "Read article specified by message-id around point."
5820 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5821 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5822 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5823 (let ((msg-id (concat "<" (match-string 0) ">")))
5824 (set-buffer gnus-summary-buffer)
5825 (gnus-summary-refer-article msg-id))
5826 (error "No references around point"))))
5828 (defun gnus-article-show-summary ()
5829 "Reconfigure windows to show summary buffer."
5831 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5832 (error "There is no summary buffer for this article buffer")
5833 (gnus-article-set-globals)
5834 (gnus-configure-windows 'article)
5835 (gnus-summary-goto-subject gnus-current-article)
5836 (gnus-summary-position-point)))
5838 (defun gnus-article-describe-briefly ()
5839 "Describe article mode commands briefly."
5841 (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")))
5843 (defun gnus-article-summary-command ()
5844 "Execute the last keystroke in the summary buffer."
5846 (let ((obuf (current-buffer))
5847 (owin (current-window-configuration))
5849 (switch-to-buffer gnus-article-current-summary 'norecord)
5850 (setq func (lookup-key (current-local-map) (this-command-keys)))
5851 (call-interactively func)
5853 (set-window-configuration owin)
5854 (set-window-point (get-buffer-window (current-buffer)) (point))))
5856 (defun gnus-article-summary-command-nosave ()
5857 "Execute the last keystroke in the summary buffer."
5860 (pop-to-buffer gnus-article-current-summary 'norecord)
5861 (setq func (lookup-key (current-local-map) (this-command-keys)))
5862 (call-interactively func)))
5864 (defun gnus-article-check-buffer ()
5865 "Beep if not in an article buffer."
5866 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5867 (error "Command invoked outside of a Gnus article buffer")))
5869 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5870 "Read a summary buffer key sequence and execute it from the article buffer."
5872 (gnus-article-check-buffer)
5874 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5875 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5876 "=" "^" "\M-^" "|"))
5882 '("n" "Gn" "p" "Gp"))
5885 (set-buffer gnus-article-current-summary)
5886 (let (gnus-pick-mode)
5887 (push (or key last-command-event) unread-command-events)
5888 (setq keys (static-if (featurep 'xemacs)
5889 (events-to-keys (read-key-sequence nil))
5890 (read-key-sequence nil)))))
5893 (if (or (member keys nosaves)
5894 (member keys nosave-but-article)
5895 (member keys nosave-in-article))
5897 (save-window-excursion
5898 (pop-to-buffer gnus-article-current-summary 'norecord)
5899 ;; We disable the pick minor mode commands.
5900 (let (gnus-pick-mode)
5901 (setq func (lookup-key (current-local-map) keys))))
5905 (unless (member keys nosave-in-article)
5906 (set-buffer gnus-article-current-summary))
5907 (call-interactively func)
5908 (setq new-sum-point (point)))
5909 (when (member keys nosave-but-article)
5910 (pop-to-buffer gnus-article-buffer 'norecord)))
5911 ;; These commands should restore window configuration.
5912 (let ((obuf (current-buffer))
5913 (owin (current-window-configuration))
5915 win func in-buffer selected new-sum-start new-sum-hscroll)
5916 (cond (not-restore-window
5917 (pop-to-buffer gnus-article-current-summary 'norecord))
5918 ((setq win (get-buffer-window gnus-article-current-summary))
5919 (select-window win))
5921 (switch-to-buffer gnus-article-current-summary 'norecord)))
5922 (setq in-buffer (current-buffer))
5923 ;; We disable the pick minor mode commands.
5924 (if (and (setq func (let (gnus-pick-mode)
5925 (lookup-key (current-local-map) keys)))
5928 (call-interactively func)
5929 (when (eq win (selected-window))
5930 (setq new-sum-point (point)
5931 new-sum-start (window-start win)
5932 new-sum-hscroll (window-hscroll win)))
5933 (when (eq in-buffer (current-buffer))
5934 (setq selected (gnus-summary-select-article))
5936 (unless not-restore-window
5937 (set-window-configuration owin))
5938 (when (eq selected 'old)
5940 (set-window-start (get-buffer-window (current-buffer))
5942 (set-window-point (get-buffer-window (current-buffer))
5944 (when (and (not not-restore-window)
5946 (set-window-point win new-sum-point)
5947 (set-window-start win new-sum-start)
5948 (set-window-hscroll win new-sum-hscroll))))
5949 (set-window-configuration owin)
5952 (defun gnus-article-describe-key (key)
5953 "Display documentation of the function invoked by KEY. KEY is a string."
5954 (interactive "kDescribe key: ")
5955 (gnus-article-check-buffer)
5956 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5958 (set-buffer gnus-article-current-summary)
5959 (let (gnus-pick-mode)
5960 (if (featurep 'xemacs)
5962 (push (elt key 0) unread-command-events)
5963 (setq key (events-to-keys
5964 (read-key-sequence "Describe key: "))))
5965 (setq unread-command-events
5967 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5969 (setq key (read-key-sequence "Describe key: "))))
5971 (describe-key key)))
5973 (defun gnus-article-describe-key-briefly (key &optional insert)
5974 "Display documentation of the function invoked by KEY. KEY is a string."
5975 (interactive "kDescribe key: \nP")
5976 (gnus-article-check-buffer)
5977 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5979 (set-buffer gnus-article-current-summary)
5980 (let (gnus-pick-mode)
5981 (if (featurep 'xemacs)
5983 (push (elt key 0) unread-command-events)
5984 (setq key (events-to-keys
5985 (read-key-sequence "Describe key: "))))
5986 (setq unread-command-events
5988 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5990 (setq key (read-key-sequence "Describe key: "))))
5991 (describe-key-briefly key insert))
5992 (describe-key-briefly key insert)))
5994 (defun gnus-article-reply-with-original (&optional wide)
5995 "Start composing a reply mail to the current message.
5996 The text in the region will be yanked. If the region isn't active,
5997 the entire article will be yanked."
5999 (let ((article (cdr gnus-article-current))
6001 (if (not (gnus-region-active-p))
6002 (with-current-buffer gnus-summary-buffer
6003 (gnus-summary-reply (list (list article)) wide))
6004 (setq contents (buffer-substring (point) (mark t)))
6005 ;; Deactivate active regions.
6006 (when (and (boundp 'transient-mark-mode)
6007 transient-mark-mode)
6008 (setq mark-active nil))
6009 (with-current-buffer gnus-summary-buffer
6011 (list (list article contents)) wide)))))
6013 (defun gnus-article-followup-with-original ()
6014 "Compose a followup to the current article.
6015 The text in the region will be yanked. If the region isn't active,
6016 the entire article will be yanked."
6018 (let ((article (cdr gnus-article-current))
6020 (if (not (gnus-region-active-p))
6021 (with-current-buffer gnus-summary-buffer
6022 (gnus-summary-followup (list (list article))))
6023 (setq contents (buffer-substring (point) (mark t)))
6024 ;; Deactivate active regions.
6025 (when (and (boundp 'transient-mark-mode)
6026 transient-mark-mode)
6027 (setq mark-active nil))
6028 (with-current-buffer gnus-summary-buffer
6029 (gnus-summary-followup
6030 (list (list article contents)))))))
6032 (defun gnus-article-hide (&optional arg force)
6033 "Hide all the gruft in the current article.
6034 This means that signatures, cited text and (some) headers will be
6036 If given a prefix, show the hidden text instead."
6037 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6038 (gnus-article-hide-headers arg)
6039 (gnus-article-hide-list-identifiers arg)
6040 (gnus-article-hide-citation-maybe arg force)
6041 (gnus-article-hide-signature arg))
6043 (defun gnus-article-maybe-highlight ()
6044 "Do some article highlighting if article highlighting is requested."
6045 (when (gnus-visual-p 'article-highlight 'highlight)
6046 (gnus-article-highlight-some)))
6048 (defun gnus-check-group-server ()
6049 ;; Make sure the connection to the server is alive.
6050 (unless (gnus-server-opened
6051 (gnus-find-method-for-group gnus-newsgroup-name))
6052 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6053 (gnus-request-group gnus-newsgroup-name t)))
6056 (autoload 'nneething-get-file-name "nneething"))
6058 (defun gnus-request-article-this-buffer (article group)
6059 "Get an article and insert it into this buffer."
6060 (let (do-update-line sparse-header)
6064 (gnus-kill-all-overlays)
6065 (setq group (or group gnus-newsgroup-name))
6067 ;; Using `gnus-request-article' directly will insert the article into
6068 ;; `nntp-server-buffer' - so we'll save some time by not having to
6069 ;; copy it from the server buffer into the article buffer.
6071 ;; We only request an article by message-id when we do not have the
6072 ;; headers for it, so we'll have to get those.
6073 (when (stringp article)
6074 (gnus-read-header article))
6076 ;; If the article number is negative, that means that this article
6077 ;; doesn't belong in this newsgroup (possibly), so we find its
6078 ;; message-id and request it by id instead of number.
6079 (when (and (numberp article)
6081 (get-buffer gnus-summary-buffer)
6082 (gnus-buffer-exists-p gnus-summary-buffer))
6084 (set-buffer gnus-summary-buffer)
6085 (let ((header (gnus-summary-article-header article)))
6088 ((memq article gnus-newsgroup-sparse)
6089 ;; This is a sparse gap article.
6090 (setq do-update-line article)
6091 (setq article (mail-header-id header))
6092 (setq sparse-header (gnus-read-header article))
6093 (setq gnus-newsgroup-sparse
6094 (delq article gnus-newsgroup-sparse)))
6096 ;; It's a real article.
6097 (setq article (mail-header-id header)))
6099 ;; It is an extracted pseudo-article.
6100 (setq article 'pseudo)
6101 (gnus-request-pseudo-article header))))
6103 (let ((method (gnus-find-method-for-group
6104 gnus-newsgroup-name)))
6105 (when (and (eq (car method) 'nneething)
6107 (let ((dir (nneething-get-file-name
6108 (mail-header-id header))))
6109 (when (and (stringp dir)
6110 (file-directory-p dir))
6111 (setq article 'nneething)
6112 (gnus-group-enter-directory dir))))))))
6115 ;; Refuse to select canceled articles.
6116 ((and (numberp article)
6118 (get-buffer gnus-summary-buffer)
6119 (gnus-buffer-exists-p gnus-summary-buffer)
6120 (eq (cdr (with-current-buffer gnus-summary-buffer
6121 (assq article gnus-newsgroup-reads)))
6122 gnus-canceled-mark))
6124 ;; We first check `gnus-original-article-buffer'.
6125 ((and (get-buffer gnus-original-article-buffer)
6127 (with-current-buffer gnus-original-article-buffer
6128 (and (equal (car gnus-original-article) group)
6129 (eq (cdr gnus-original-article) article))))
6130 (insert-buffer-substring gnus-original-article-buffer)
6132 ;; Check the backlog.
6133 ((and gnus-keep-backlog
6134 (gnus-backlog-request-article group article (current-buffer)))
6136 ;; Check asynchronous pre-fetch.
6137 ((gnus-async-request-fetched-article group article (current-buffer))
6138 (gnus-async-prefetch-next group article gnus-summary-buffer)
6139 (when (and (numberp article) gnus-keep-backlog)
6140 (gnus-backlog-enter-article group article (current-buffer)))
6143 ((and gnus-use-cache
6145 (gnus-cache-request-article article group))
6147 ;; Check the agent cache.
6148 ((gnus-agent-request-article article group)
6150 ;; Get the article and put into the article buffer.
6151 ((or (stringp article)
6153 (let ((gnus-override-method gnus-override-method)
6154 (methods (and (stringp article)
6155 gnus-refer-article-method))
6156 (backend (car (gnus-find-method-for-group
6157 gnus-newsgroup-name)))
6159 (inhibit-read-only t))
6160 (if (or (not (listp methods))
6161 (and (symbolp (car methods))
6162 (assq (car methods) nnoo-definition-alist)))
6163 (setq methods (list methods)))
6164 (when (and (null gnus-override-method)
6166 (setq gnus-override-method (pop methods)))
6168 (when (eq gnus-override-method 'current)
6169 (setq gnus-override-method
6170 (with-current-buffer gnus-summary-buffer
6171 gnus-current-select-method)))
6173 (gnus-kill-all-overlays)
6174 (let ((gnus-newsgroup-name group))
6175 (gnus-check-group-server))
6177 ((gnus-request-article article group (current-buffer))
6178 (when (numberp article)
6179 (gnus-async-prefetch-next group article
6180 gnus-summary-buffer)
6181 (when gnus-keep-backlog
6182 (gnus-backlog-enter-article
6183 group article (current-buffer))))
6184 (setq result 'article))
6186 (setq gnus-override-method (pop methods)))
6187 ((not (string-match "^400 "
6188 (nnheader-get-report backend)))
6189 ;; If we get 400 server disconnect, reconnect and
6190 ;; retry; otherwise, assume the article has expired.
6191 (setq result 'done))))
6192 (and (eq result 'article) 'article)))
6196 ;; Associate this article with the current summary buffer.
6197 (setq gnus-article-current-summary gnus-summary-buffer)
6199 ;; Take the article from the original article buffer
6200 ;; and place it in the buffer it's supposed to be in.
6201 (when (and (get-buffer gnus-article-buffer)
6202 (equal (buffer-name (current-buffer))
6203 (buffer-name (get-buffer gnus-article-buffer))))
6205 (if (get-buffer gnus-original-article-buffer)
6206 (set-buffer gnus-original-article-buffer)
6207 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6208 (buffer-disable-undo)
6209 (setq major-mode 'gnus-original-article-mode)
6210 (setq buffer-read-only t))
6211 (let ((inhibit-read-only t))
6213 (insert-buffer-substring gnus-article-buffer))
6214 (setq gnus-original-article (cons group article)))
6217 (run-hooks 'gnus-article-decode-hook)
6218 ;; Mark article as decoded or not.
6219 (setq gnus-article-decoded-p gnus-article-decode-hook))
6221 ;; Update sparse articles.
6222 (when (and do-update-line
6223 (or (numberp article)
6225 (let ((buf (current-buffer)))
6226 (set-buffer gnus-summary-buffer)
6227 (gnus-summary-update-article do-update-line sparse-header)
6228 (gnus-summary-goto-subject do-update-line nil t)
6229 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6231 (set-buffer buf))))))
6237 (defcustom gnus-article-edit-mode-hook nil
6238 "Hook run in article edit mode buffers."
6239 :group 'gnus-article-various
6242 (defcustom gnus-article-edit-article-setup-function
6243 'gnus-article-mime-edit-article-setup
6244 "Function called to setup an editing article buffer."
6245 :group 'gnus-article-various
6248 (defvar gnus-article-edit-done-function nil)
6250 (defvar gnus-article-edit-mode-map nil)
6252 ;; Should we be using derived.el for this?
6253 (unless gnus-article-edit-mode-map
6254 (setq gnus-article-edit-mode-map (make-keymap))
6255 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6257 (gnus-define-keys gnus-article-edit-mode-map
6258 "\C-c?" describe-mode
6259 "\C-c\C-c" gnus-article-edit-done
6260 "\C-c\C-k" gnus-article-edit-exit
6261 "\C-c\C-f\C-t" message-goto-to
6262 "\C-c\C-f\C-o" message-goto-from
6263 "\C-c\C-f\C-b" message-goto-bcc
6264 ;;"\C-c\C-f\C-w" message-goto-fcc
6265 "\C-c\C-f\C-c" message-goto-cc
6266 "\C-c\C-f\C-s" message-goto-subject
6267 "\C-c\C-f\C-r" message-goto-reply-to
6268 "\C-c\C-f\C-n" message-goto-newsgroups
6269 "\C-c\C-f\C-d" message-goto-distribution
6270 "\C-c\C-f\C-f" message-goto-followup-to
6271 "\C-c\C-f\C-m" message-goto-mail-followup-to
6272 "\C-c\C-f\C-k" message-goto-keywords
6273 "\C-c\C-f\C-u" message-goto-summary
6274 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6275 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6276 "\C-c\C-b" message-goto-body
6277 "\C-c\C-i" message-goto-signature
6279 "\C-c\C-t" message-insert-to
6280 "\C-c\C-n" message-insert-newsgroups
6281 "\C-c\C-o" message-sort-headers
6282 "\C-c\C-e" message-elide-region
6283 "\C-c\C-v" message-delete-not-region
6284 "\C-c\C-z" message-kill-to-signature
6285 "\M-\r" message-newline-and-reformat
6286 "\C-c\C-a" mml-attach-file
6287 "\C-a" message-beginning-of-line
6289 "\M-;" comment-region)
6291 (gnus-define-keys (gnus-article-edit-wash-map
6292 "\C-c\C-w" gnus-article-edit-mode-map)
6293 "f" gnus-article-edit-full-stops))
6296 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6298 ["Fetch To" message-insert-to t]
6299 ["Fetch Newsgroups" message-insert-newsgroups t]
6301 ["To" message-goto-to t]
6302 ["From" message-goto-from t]
6303 ["Subject" message-goto-subject t]
6304 ["Cc" message-goto-cc t]
6305 ["Reply-To" message-goto-reply-to t]
6306 ["Summary" message-goto-summary t]
6307 ["Keywords" message-goto-keywords t]
6308 ["Newsgroups" message-goto-newsgroups t]
6309 ["Followup-To" message-goto-followup-to t]
6310 ["Mail-Followup-To" message-goto-mail-followup-to t]
6311 ["Distribution" message-goto-distribution t]
6312 ["Body" message-goto-body t]
6313 ["Signature" message-goto-signature t]))
6315 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6316 "Major mode for editing articles.
6317 This is an extended text-mode.
6319 \\{gnus-article-edit-mode-map}"
6320 (make-local-variable 'gnus-article-edit-done-function)
6321 (make-local-variable 'gnus-prev-winconf)
6322 (set (make-local-variable 'font-lock-defaults)
6323 '(message-font-lock-keywords t))
6324 (set (make-local-variable 'mail-header-separator) "")
6325 (set (make-local-variable 'gnus-article-edit-mode) t)
6326 (easy-menu-add message-mode-field-menu message-mode-map)
6327 (setq buffer-read-only nil)
6328 (buffer-enable-undo)
6331 (defun gnus-article-edit (&optional force)
6332 "Edit the current article.
6333 This will have permanent effect only in mail groups.
6334 If FORCE is non-nil, allow editing of articles even in read-only
6337 (when (and (not force)
6338 (gnus-group-read-only-p))
6339 (error "The current newsgroup does not support article editing"))
6340 (gnus-article-date-original)
6341 (gnus-article-edit-article
6343 `(lambda (no-highlight)
6345 (gnus-summary-edit-article-done
6346 ,(or (mail-header-references gnus-current-headers) "")
6347 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6349 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6350 "Start editing the contents of the current article buffer."
6351 (let ((winconf (current-window-configuration)))
6352 (set-buffer gnus-article-buffer)
6353 (let ((message-auto-save-directory
6354 ;; Don't associate the article buffer with a draft file.
6356 (gnus-article-edit-mode))
6357 (funcall start-func)
6358 (set-buffer-modified-p nil)
6359 (gnus-configure-windows 'edit-article)
6360 (setq gnus-article-edit-done-function exit-func)
6361 (setq gnus-prev-winconf winconf)
6362 (when gnus-article-edit-article-setup-function
6363 (funcall gnus-article-edit-article-setup-function))
6365 (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit"))))
6367 (defun gnus-article-edit-done (&optional arg)
6368 "Update the article edits and exit."
6370 (let ((func gnus-article-edit-done-function)
6371 (buf (current-buffer))
6372 (start (window-start))
6374 (winconf gnus-prev-winconf))
6375 (remove-hook 'gnus-article-mode-hook
6376 'gnus-article-mime-edit-article-unwind)
6377 (widen) ;; Widen it in case that users narrowed the buffer.
6380 ;; The cache and backlog have to be flushed somewhat.
6381 (when gnus-keep-backlog
6382 (gnus-backlog-remove-article
6383 (car gnus-article-current) (cdr gnus-article-current)))
6384 ;; Flush original article as well.
6386 (when (get-buffer gnus-original-article-buffer)
6387 (set-buffer gnus-original-article-buffer)
6388 (setq gnus-original-article nil)))
6389 (when gnus-use-cache
6390 (gnus-cache-update-article
6391 (car gnus-article-current) (cdr gnus-article-current)))
6392 ;; We remove all text props from the article buffer.
6393 (kill-all-local-variables)
6394 (set-text-properties (point-min) (point-max) nil)
6396 (set-window-configuration winconf)
6398 (set-window-start (get-buffer-window buf) start)
6399 (set-window-point (get-buffer-window buf) (point)))
6400 (gnus-summary-show-article))
6402 (defun gnus-article-edit-exit ()
6403 "Exit the article editing without updating."
6405 (when (or (not (buffer-modified-p))
6406 (yes-or-no-p "Article modified; kill anyway? "))
6407 (let ((curbuf (current-buffer))
6409 (window-start (window-start)))
6411 (if (gnus-buffer-live-p gnus-original-article-buffer)
6412 (insert-buffer-substring gnus-original-article-buffer))
6413 (let ((winconf gnus-prev-winconf))
6414 (kill-all-local-variables)
6416 (set-window-configuration winconf)
6417 ;; Tippy-toe some to make sure that point remains where it was.
6418 (save-current-buffer
6420 (set-window-start (get-buffer-window (current-buffer)) window-start)
6422 (gnus-summary-show-article)))
6424 (defun gnus-article-edit-full-stops ()
6425 "Interactively repair spacing at end of sentences."
6428 (goto-char (point-min))
6429 (search-forward-regexp "^$" nil t)
6430 (let ((case-fold-search nil))
6431 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6434 ;;; Article editing with MIME-Edit
6437 (defcustom gnus-article-mime-edit-article-setup-hook nil
6438 "Hook run after setting up a MIME editing article buffer."
6439 :group 'gnus-article-various
6442 (defun gnus-article-mime-edit-article-unwind ()
6443 "Unwind `gnus-article-buffer' if article editing was given up."
6444 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6445 (when (featurep 'font-lock)
6446 (setq font-lock-defaults nil)
6447 (font-lock-mode -1))
6448 (when mime-edit-mode-flag
6449 (mime-edit-exit 'nomime 'no-error)
6452 (defun gnus-article-mime-edit-article-setup ()
6453 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
6454 after replacing with the original article."
6455 (setq gnus-show-mime t)
6456 (setq gnus-article-edit-done-function
6457 `(lambda (&rest args)
6458 (when mime-edit-mode-flag
6459 (let (mime-edit-insert-user-agent-field)
6462 (goto-char (point-min))
6463 (let (case-fold-search)
6464 (when (re-search-forward
6465 (format "^%s$" (regexp-quote mail-header-separator))
6467 (replace-match "")))
6468 (apply ,gnus-article-edit-done-function args)
6471 (buffer-substring-no-properties (point-min) (point-max))
6472 (set-buffer (get-buffer-create gnus-original-article-buffer))
6474 (setq gnus-current-headers (gnus-article-make-full-mail-header))
6475 (set-buffer gnus-article-buffer)
6476 (gnus-article-prepare-display)))
6477 (substitute-key-definition 'gnus-article-edit-done
6478 'gnus-article-mime-edit-done
6479 gnus-article-edit-mode-map)
6480 (substitute-key-definition 'gnus-article-edit-exit
6481 'gnus-article-mime-edit-exit
6482 gnus-article-edit-mode-map)
6484 (insert-buffer-substring gnus-original-article-buffer)
6485 (unless (member (with-current-buffer gnus-summary-buffer
6486 gnus-newsgroup-name)
6487 '("nndraft:delayed" "nndraft:drafts"))
6488 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
6489 (fset 'mime-edit-decode-single-part-in-buffer
6490 (lambda (&rest args)
6491 (if (let ((content-type (car args)))
6492 (and (eq 'message (mime-content-type-primary-type
6494 (eq 'rfc822 (mime-content-type-subtype
6496 (setcar (cdr args) 'not-decode-text))
6500 (fset 'mime-edit-decode-single-part-in-buffer ofn))))
6501 (when (featurep 'font-lock)
6502 (set (make-local-variable 'font-lock-defaults)
6503 '(message-font-lock-keywords t))
6504 (font-lock-set-defaults)
6505 (turn-on-font-lock))
6506 (set-buffer-modified-p nil)
6507 (delete-other-windows)
6508 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6509 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
6511 (defun gnus-article-mime-edit-done (&optional arg)
6512 "Update the article MIME edits and exit."
6514 (when (featurep 'font-lock)
6515 (setq font-lock-defaults nil)
6516 (font-lock-mode -1))
6517 (let ((inhibit-read-only t))
6518 (gnus-article-edit-done arg)))
6520 (defun gnus-article-mime-edit-exit ()
6521 "Exit the article MIME editing without updating."
6523 (when (or (not (buffer-modified-p))
6524 (yes-or-no-p "Article modified; kill anyway? "))
6525 (when (featurep 'font-lock)
6526 (setq font-lock-defaults nil)
6527 (font-lock-mode -1))
6528 (when mime-edit-mode-flag
6529 (let (mime-edit-insert-user-agent-field)
6532 (goto-char (point-min))
6533 (let (case-fold-search)
6534 (when (re-search-forward
6535 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
6536 (replace-match "")))
6537 (let ((winconf gnus-prev-winconf))
6539 (buffer-substring-no-properties (point-min) (point-max))
6540 (set-buffer (get-buffer-create gnus-original-article-buffer))
6542 (setq gnus-current-headers (gnus-article-make-full-mail-header))
6543 (set-buffer gnus-article-buffer)
6544 (gnus-article-prepare-display)
6545 (set-window-configuration winconf))))
6548 ;;; Article highlights
6551 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6553 ;;; Internal Variables:
6555 (defcustom gnus-button-url-regexp
6556 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6557 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]\\)"
6558 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)\\)")
6559 "Regular expression that matches URLs."
6560 :group 'gnus-article-buttons
6563 (defcustom gnus-button-valid-fqdn-regexp
6564 message-valid-fqdn-regexp
6565 "Regular expression that matches a valid FQDN."
6567 :group 'gnus-article-buttons
6570 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6571 (defcustom gnus-button-valid-localpart-regexp
6572 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*"
6573 "Regular expression that matches a localpart of mail addresses or MIDs."
6575 :group 'gnus-article-buttons
6578 (defcustom gnus-button-man-handler 'manual-entry
6579 "Function to use for displaying man pages.
6580 The function must take at least one argument with a string naming the
6583 :type '(choice (function-item :tag "Man" manual-entry)
6584 (function-item :tag "Woman" woman)
6585 (function :tag "Other"))
6586 :group 'gnus-article-buttons)
6588 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6589 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6590 If the default site is too slow, try to find a CTAN mirror, see
6591 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6592 the variable `gnus-button-handle-ctan'."
6594 :group 'gnus-article-buttons
6595 :link '(custom-manual "(gnus)Group Parameters")
6596 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6597 (const "http://tug.ctan.org/tex-archive/")
6598 (const "http://www.dante.de/CTAN/")
6599 (string :tag "Other")))
6601 (defcustom gnus-button-ctan-handler 'browse-url
6602 "Function to use for displaying CTAN links.
6603 The function must take one argument, the string naming the URL."
6605 :type '(choice (function-item :tag "Browse Url" browse-url)
6606 (function :tag "Other"))
6607 :group 'gnus-article-buttons)
6609 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6610 "Bogus strings removed from CTAN URLs."
6612 :group 'gnus-article-buttons
6613 :type '(choice (const "^/?tex-archive/\\|/")
6614 (regexp :tag "Other")))
6616 (defcustom gnus-button-ctan-directory-regexp
6618 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6619 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6620 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6621 "tds" "tools" "usergrps" "web") t)
6622 "Regular expression for ctan directories.
6623 It should match all directories in the top level of `gnus-ctan-url'."
6625 :group 'gnus-article-buttons
6628 (defcustom gnus-button-mid-or-mail-regexp
6629 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6630 gnus-button-valid-fqdn-regexp
6632 "Regular expression that matches a message ID or a mail address."
6634 :group 'gnus-article-buttons
6637 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6638 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6639 Strings like this can be either a message ID or a mail address. If it is one
6640 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6641 message ID or a mail address, respectively. If this variable is set to the
6642 symbol `ask', always query the user what do do. If it is a function, this
6643 function will be called with the string as it's only argument. The function
6644 must return `mid', `mail', `invalid' or `ask'."
6646 :group 'gnus-article-buttons
6647 :type '(choice (function-item :tag "Heuristic function"
6648 gnus-button-mid-or-mail-heuristic)
6653 (defcustom gnus-button-mid-or-mail-heuristic-alist
6654 '((-10.0 . ".+\\$.+@")
6657 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6658 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6659 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6660 (-1.0 . "^[^a-z]+@")
6662 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6663 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6664 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6665 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6668 (-1.0 . "^[0-9][0-9]")
6670 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6671 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6672 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6673 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6675 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6676 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6679 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6681 ;; compensation for TDMA dated mail addresses:
6682 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6684 (-20.0 . "\\.fsf@") ;; Gnus
6687 (-20.0 . "_-_") ;; Subject change in thread
6689 (-20.0 . "\\.ln@") ;; leafnode
6690 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6691 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6693 ;; (5.0 . "") ;; $local_part_len <= 7
6694 (10.0 . "^[^0-9]+@")
6695 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6696 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6699 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6701 (0.5 . "^[A-Z][a-z]")
6702 (0.5 . "^[A-Z][a-z][a-z]")
6703 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6704 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6705 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6707 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6708 address. The REGEXP is processed with `case-fold-search' set to nil."
6710 :group 'gnus-article-buttons
6711 :type '(repeat (cons (number :tag "Rate")
6712 (regexp :tag "Regexp"))))
6714 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6715 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6716 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6717 address, `ask' if unsure and `invalid' if the string is invalid."
6718 (let ((case-fold-search nil)
6719 (list gnus-button-mid-or-mail-heuristic-alist)
6720 (result 0) rate regexp lpartlen elem)
6722 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6723 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6724 ;; Certain special cases...
6727 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6728 "^[0-9]+\\.[0-9]+@compuserve\\|"
6729 "@public\\.gmane\\.org")
6731 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6732 (setq result 'mail))
6733 (when (string-match "@.*@\\| " mid-or-mail)
6734 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6735 (setq result 'invalid))
6736 ;; Nothing more to do, if result is not a number here...
6737 (when (numberp result)
6739 (setq elem (car list)
6743 (when (string-match regexp mid-or-mail)
6744 (setq result (+ result rate))
6746 9 "`%s' matched `%s', rate `%s', result `%s'."
6747 mid-or-mail regexp rate result)))
6748 (when (<= lpartlen 7)
6749 (setq result (+ result 5.0))
6750 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6751 mid-or-mail result))
6752 (when (>= lpartlen 12)
6753 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6755 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6756 ;; Long local part should contain realname if e-mail address,
6757 ;; too many digits: message-id.
6758 ;; $score -= 5.0 + 0.1 * $local_part_len;
6759 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6760 (setq result (+ result rate))
6762 9 "Many digits in `%s', rate `%s', result `%s'."
6763 mid-or-mail rate result))
6764 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6766 ;; Too few vowels [^aeiouy]{4,}.*\@
6767 (setq result (+ result -5.0))
6769 9 "Few vowels in `%s', rate `%s', result `%s'."
6770 mid-or-mail -5.0 result))
6772 (setq result (+ result 5.0))
6774 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6775 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6776 ;; Maybe we should make this a customizable alist: (condition . 'result)
6778 ((symbolp result) result)
6779 ;; Now convert number into proper results:
6780 ((< result -10.0) 'mid)
6781 ((> result 10.0) 'mail)
6784 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6785 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6786 (url-mid (concat "news" ":" mid-or-mail))
6787 (url-mailto (concat "mailto" ":" mid-or-mail)))
6788 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6789 (when (fboundp pref)
6791 ;; get rid of surrounding angles...
6793 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6794 (if (or (eq 'mid guessed) (eq 'mail guessed))
6798 (save-window-excursion
6799 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6802 (cond ((eq pref 'mid)
6803 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6804 (gnus-button-handle-news url-mid))
6806 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6807 (gnus-url-mailto url-mailto))
6808 (t (gnus-message 3 "Invalid string.")))))
6810 (defun gnus-button-handle-custom (fun arg)
6811 "Call function FUN on argument ARG.
6812 Both FUN and ARG are supposed to be strings. ARG will be passed
6813 as a symbol to FUN."
6814 (funcall (intern fun) (intern arg)))
6816 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6818 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6821 (defun gnus-button-handle-describe-function (url)
6822 "Call `describe-function' when pushing the corresponding URL button."
6825 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6827 (defun gnus-button-handle-describe-variable (url)
6828 "Call `describe-variable' when pushing the corresponding URL button."
6831 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6833 (defun gnus-button-handle-symbol (url)
6834 "Display help on variable or function.
6835 Calls `describe-variable' or `describe-function'."
6836 (let ((sym (intern url)))
6838 ((fboundp sym) (describe-function sym))
6839 ((boundp sym) (describe-variable sym))
6840 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6842 (defun gnus-button-handle-describe-key (url)
6843 "Call `describe-key' when pushing the corresponding URL button."
6845 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6846 (keys (ignore-errors (eval `(kbd ,key-string)))))
6849 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6851 (defun gnus-button-handle-apropos (url)
6852 "Call `apropos' when pushing the corresponding URL button."
6853 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6855 (defun gnus-button-handle-apropos-command (url)
6856 "Call `apropos' when pushing the corresponding URL button."
6858 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6860 (defun gnus-button-handle-apropos-variable (url)
6861 "Call `apropos' when pushing the corresponding URL button."
6863 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6864 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6866 (defun gnus-button-handle-apropos-documentation (url)
6867 "Call `apropos' when pushing the corresponding URL button."
6869 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6870 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6872 (defun gnus-button-handle-library (url)
6873 "Call `locate-library' when pushing the corresponding URL button."
6874 (gnus-message 9 "url=`%s'" url)
6875 (let* ((lib (locate-library url))
6876 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6878 (gnus-message 1 "Cannot locale library `%s'." url)
6879 (find-file-read-only file))))
6881 (defun gnus-button-handle-ctan (url)
6882 "Call `browse-url' when pushing a CTAN URL button."
6884 gnus-button-ctan-handler
6887 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6889 (defcustom gnus-button-tex-level 5
6890 "*Integer that says how many TeX-related buttons Gnus will show.
6891 The higher the number, the more buttons will appear and the more false
6892 positives are possible. Note that you can set this variable local to
6893 specific groups. Setting it higher in TeX groups is probably a good idea.
6894 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6895 how to set variables in specific groups."
6897 :group 'gnus-article-buttons
6898 :link '(custom-manual "(gnus)Group Parameters")
6901 (defcustom gnus-button-man-level 5
6902 "*Integer that says how many man-related buttons Gnus will show.
6903 The higher the number, the more buttons will appear and the more false
6904 positives are possible. Note that you can set this variable local to
6905 specific groups. Setting it higher in Unix groups is probably a good idea.
6906 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6907 how to set variables in specific groups."
6909 :group 'gnus-article-buttons
6910 :link '(custom-manual "(gnus)Group Parameters")
6913 (defcustom gnus-button-emacs-level 5
6914 "*Integer that says how many emacs-related buttons Gnus will show.
6915 The higher the number, the more buttons will appear and the more false
6916 positives are possible. Note that you can set this variable local to
6917 specific groups. Setting it higher in Emacs or Gnus related groups is
6918 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6919 `gnus-parameters' on how to set variables in specific groups."
6921 :group 'gnus-article-buttons
6922 :link '(custom-manual "(gnus)Group Parameters")
6925 (defcustom gnus-button-message-level 5
6926 "*Integer that says how many buttons for news or mail messages will appear.
6927 The higher the number, the more buttons will appear and the more false
6928 positives are possible."
6929 ;; mail addresses, MIDs, URLs for news, ...
6931 :group 'gnus-article-buttons
6934 (defcustom gnus-button-browse-level 5
6935 "*Integer that says how many buttons for browsing will appear.
6936 The higher the number, the more buttons will appear and the more false
6937 positives are possible."
6938 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6940 :group 'gnus-article-buttons
6943 (defcustom gnus-button-alist
6944 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6945 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6946 ((concat "\\b\\(nntp\\|news\\):\\("
6947 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6948 0 t gnus-button-handle-news 2)
6949 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6950 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6951 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6952 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6953 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6954 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6955 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6956 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6957 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6958 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6959 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6960 ;; RFC 2368 (The mailto URL scheme)
6961 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6962 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6963 ("\\bmailto:\\([^ \n\t]+\\)"
6964 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6966 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6967 gnus-button-ctan-directory-regexp
6968 "[^][>)!;:,'\n\t ]+\\)")
6969 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6970 ((concat "\\btex-archive/\\("
6971 gnus-button-ctan-directory-regexp
6972 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6973 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6976 gnus-button-ctan-directory-regexp
6977 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6978 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6979 ;; This is info (home-grown style) <info://foo/bar+baz>
6980 ("\\binfo://\\([^'\">\n\t ]+\\)"
6981 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6982 ;; Info GNOME style <info:foo#bar_baz>
6983 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6984 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6985 ;; Info KDE style <info:(foo)bar baz>
6986 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6987 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6988 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6989 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6990 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6991 ;; Info links like `C-h i d m CC Mode RET'
6992 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6994 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6995 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
6996 ;; Emacs help commands
6997 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6998 ;; regexp doesn't match arguments containing ` '.
6999 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7000 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7001 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7002 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7003 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7004 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7005 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7006 ;; The following entries may lead to many false positives so don't enable
7007 ;; them by default (use a high button level).
7008 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7009 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7010 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7011 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7012 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7013 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7014 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7015 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7016 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7017 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7018 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7019 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7020 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7021 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7022 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7023 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7024 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7025 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7026 ;; Unlike the other regexps we really have to require quoting
7027 ;; here to determine where it ends.
7028 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7029 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7030 ("<URL: *\\([^<>]*\\)>"
7031 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7032 ;; RFC 2396 (2.4.3., delims) ...
7033 ("\"URL: *\\([^\"]*\\)\""
7034 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7035 ;; RFC 2396 (2.4.3., delims) ...
7036 ("\"URL: *\\([^\"]*\\)\""
7037 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7039 (gnus-button-url-regexp
7040 0 (>= gnus-button-browse-level 0) browse-url 0)
7042 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7043 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7044 gnus-button-handle-man 1)
7045 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7046 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7047 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7048 gnus-button-handle-man 1)
7049 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7050 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7051 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7052 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7053 ;; MID or mail: To avoid too many false positives we don't try to catch
7054 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7055 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7056 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7057 ;; so that non-ambiguous entries (see above) match first.
7058 (gnus-button-mid-or-mail-regexp
7059 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7060 "*Alist of regexps matching buttons in article bodies.
7062 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7063 REGEXP: is the string (case insensitive) matching text around the button (can
7064 also be Lisp expression evaluating to a string),
7065 BUTTON: is the number of the regexp grouping actually matching the button,
7066 FORM: is a Lisp expression which must eval to true for the button to
7068 CALLBACK: is the function to call when the user push this button, and each
7069 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7071 CALLBACK can also be a variable, in that case the value of that
7072 variable it the real callback function."
7073 :group 'gnus-article-buttons
7074 :type '(repeat (list (choice regexp variable sexp)
7075 (integer :tag "Button")
7077 (function :tag "Callback")
7080 (integer :tag "Regexp group")))))
7082 (defcustom gnus-header-button-alist
7083 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7084 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7085 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7086 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7087 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7088 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7089 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7090 0 (>= gnus-button-browse-level 0) browse-url 0)
7091 ("^Subject:" gnus-button-url-regexp
7092 0 (>= gnus-button-browse-level 0) browse-url 0)
7093 ("^[^:]+:" gnus-button-url-regexp
7094 0 (>= gnus-button-browse-level 0) browse-url 0)
7095 ("^OpenPGP:.*url=" gnus-button-url-regexp
7096 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7097 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7098 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7099 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7100 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7101 "*Alist of headers and regexps to match buttons in article heads.
7103 This alist is very similar to `gnus-button-alist', except that each
7104 alist has an additional HEADER element first in each entry:
7106 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7108 HEADER is a regexp to match a header. For a fuller explanation, see
7109 `gnus-button-alist'."
7110 :group 'gnus-article-buttons
7111 :group 'gnus-article-headers
7112 :type '(repeat (list (regexp :tag "Header")
7113 (choice regexp variable)
7114 (integer :tag "Button")
7116 (function :tag "Callback")
7119 (integer :tag "Regexp group")))))
7123 (defun gnus-article-push-button (event)
7124 "Check text under the mouse pointer for a callback function.
7125 If the text under the mouse pointer has a `gnus-callback' property,
7126 call it with the value of the `gnus-data' text property."
7128 (set-buffer (window-buffer (posn-window (event-start event))))
7129 (let* ((pos (posn-point (event-start event)))
7130 (data (get-text-property pos 'gnus-data))
7131 (fun (get-text-property pos 'gnus-callback)))
7134 (funcall fun data))))
7136 (defun gnus-article-press-button ()
7137 "Check text at point for a callback function.
7138 If the text at point has a `gnus-callback' property,
7139 call it with the value of the `gnus-data' text property."
7141 (let ((data (get-text-property (point) 'gnus-data))
7142 (fun (get-text-property (point) 'gnus-callback)))
7144 (funcall fun data))))
7146 (defun gnus-article-prev-button (n)
7147 "Move point to N buttons backward.
7148 If N is negative, move forward instead."
7150 (gnus-article-next-button (- n)))
7152 (defun gnus-article-next-button (n)
7153 "Move point to N buttons forward.
7154 If N is negative, move backward instead."
7156 (let ((function (if (< n 0) 'previous-single-property-change
7157 'next-single-property-change))
7158 (inhibit-point-motion-hooks t)
7160 (limit (if (< n 0) (point-min) (point-max))))
7162 (while (and (not (= limit (point)))
7164 ;; Skip past the current button.
7165 (when (get-text-property (point) 'gnus-callback)
7166 (goto-char (funcall function (point) 'gnus-callback nil limit)))
7167 ;; Go to the next (or previous) button.
7168 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
7169 ;; Put point at the start of the button.
7170 (when (and backward (not (get-text-property (point) 'gnus-callback)))
7171 (goto-char (funcall function (point) 'gnus-callback nil limit)))
7172 ;; Skip past intangible buttons.
7173 (when (get-text-property (point) 'intangible)
7177 (gnus-message 5 "No more buttons"))
7180 (defun gnus-article-highlight (&optional force)
7181 "Highlight current article.
7182 This function calls `gnus-article-highlight-headers',
7183 `gnus-article-highlight-citation',
7184 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7185 do the highlighting. See the documentation for those functions."
7186 (interactive (list 'force))
7187 (gnus-article-highlight-headers)
7188 (gnus-article-highlight-citation force)
7189 (gnus-article-highlight-signature)
7190 (gnus-article-add-buttons force)
7191 (gnus-article-add-buttons-to-head))
7193 (defun gnus-article-highlight-some (&optional force)
7194 "Highlight current article.
7195 This function calls `gnus-article-highlight-headers',
7196 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7197 do the highlighting. See the documentation for those functions."
7198 (interactive (list 'force))
7199 (gnus-article-highlight-headers)
7200 (gnus-article-highlight-signature)
7201 (gnus-article-add-buttons))
7203 (defun gnus-article-highlight-headers ()
7204 "Highlight article headers as specified by `gnus-header-face-alist'."
7206 (gnus-with-article-headers
7207 (let (regexp header-face field-face from hpoints fpoints)
7208 (dolist (entry gnus-header-face-alist)
7209 (goto-char (point-min))
7210 (setq regexp (concat "^\\("
7211 (if (string-equal "" (nth 0 entry))
7215 header-face (nth 1 entry)
7216 field-face (nth 2 entry))
7217 (while (and (re-search-forward regexp nil t)
7221 (unless (search-forward ":" nil t)
7223 (when (and header-face
7224 (not (memq (point) hpoints)))
7225 (push (point) hpoints)
7226 (gnus-put-text-property from (point) 'face header-face))
7227 (when (and field-face
7228 (not (memq (setq from (point)) fpoints)))
7230 (if (re-search-forward "^[^ \t]" nil t)
7232 (goto-char (point-max)))
7233 (gnus-put-text-property from (point) 'face field-face)))))))
7235 (defun gnus-article-highlight-signature ()
7236 "Highlight the signature in an article.
7237 It does this by highlighting everything after
7238 `gnus-signature-separator' using the face `gnus-signature'."
7240 (when gnus-signature-face
7241 (gnus-with-article-buffer
7242 (let ((inhibit-point-motion-hooks t))
7244 (when (gnus-article-narrow-to-signature)
7245 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
7246 'face gnus-signature-face)))))))
7248 (defun gnus-article-buttonize-signature ()
7249 "Add button to the signature."
7252 (set-buffer gnus-article-buffer)
7253 (let ((inhibit-read-only t)
7254 (inhibit-point-motion-hooks t))
7255 (when (gnus-article-search-signature)
7256 (gnus-article-add-button (match-beginning 0) (match-end 0)
7257 'gnus-signature-toggle
7258 (set-marker (make-marker)
7259 (1+ (match-end 0))))))))
7261 (defun gnus-button-in-region-p (b e prop)
7262 "Say whether PROP exists in the region."
7263 (text-property-not-all b e prop nil))
7265 (defun gnus-article-add-buttons (&optional force)
7266 "Find external references in the article and make buttons of them.
7267 \"External references\" are things like Message-IDs and URLs, as
7268 specified by `gnus-button-alist'."
7269 (interactive (list 'force))
7270 (gnus-with-article-buffer
7271 (let ((inhibit-point-motion-hooks t)
7272 (case-fold-search t)
7273 (alist gnus-button-alist)
7275 ;; Remove all old markers.
7276 (let (marker entry new-list)
7277 (while (setq marker (pop gnus-button-marker-list))
7278 (if (or (< marker (point-min)) (>= marker (point-max)))
7279 (push marker new-list)
7281 (when (setq entry (gnus-button-entry))
7282 (put-text-property (match-beginning (nth 1 entry))
7283 (match-end (nth 1 entry))
7284 'gnus-callback nil))
7285 (set-marker marker nil)))
7286 (setq gnus-button-marker-list new-list))
7287 ;; We skip the headers.
7290 (while (setq entry (pop alist))
7291 (setq regexp (eval (car entry)))
7293 (while (re-search-forward regexp nil t)
7294 (let* ((start (and entry (match-beginning (nth 1 entry))))
7295 (end (and entry (match-end (nth 1 entry))))
7296 (from (match-beginning 0)))
7297 (when (and (or (eq t (nth 2 entry))
7298 (eval (nth 2 entry)))
7299 (not (gnus-button-in-region-p
7300 start end 'gnus-callback)))
7301 ;; That optional form returned non-nil, so we add the
7303 (gnus-article-add-button
7304 start end 'gnus-button-push
7305 (car (push (set-marker (make-marker) from)
7306 gnus-button-marker-list))))))))))
7308 ;; Add buttons to the head of an article.
7309 (defun gnus-article-add-buttons-to-head ()
7310 "Add buttons to the head of the article."
7312 (gnus-with-article-headers
7314 (dolist (entry gnus-header-button-alist)
7315 ;; Each alist entry.
7316 (goto-char (point-min))
7317 (while (re-search-forward (car entry) nil t)
7318 ;; Each header matching the entry.
7319 (setq beg (match-beginning 0))
7320 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7321 (match-beginning 0))
7324 (while (re-search-forward (eval (nth 1 entry)) end t)
7325 ;; Each match within a header.
7326 (let* ((entry (cdr entry))
7327 (start (match-beginning (nth 1 entry)))
7328 (end (match-end (nth 1 entry)))
7329 (form (nth 2 entry)))
7330 (goto-char (match-end 0))
7332 (gnus-article-add-button
7333 start end (nth 3 entry)
7334 (buffer-substring (match-beginning (nth 4 entry))
7335 (match-end (nth 4 entry)))))))
7336 (goto-char end))))))
7338 ;;; External functions:
7340 (defun gnus-article-add-button (from to fun &optional data)
7341 "Create a button between FROM and TO with callback FUN and data DATA."
7342 (when gnus-article-button-face
7343 (gnus-overlay-put (gnus-make-overlay from to)
7344 'face gnus-article-button-face))
7345 (gnus-add-text-properties
7347 (nconc (and gnus-article-mouse-face
7348 (list gnus-mouse-face-prop gnus-article-mouse-face))
7349 (list 'gnus-callback fun)
7350 (and data (list 'gnus-data data))))
7351 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7352 :button-keymap gnus-widget-button-keymap))
7354 ;;; Internal functions:
7356 (defun gnus-article-set-globals ()
7357 (with-current-buffer gnus-summary-buffer
7358 (gnus-set-global-variables)))
7360 (defun gnus-signature-toggle (end)
7361 (gnus-with-article-buffer
7362 (let ((inhibit-point-motion-hooks t)
7363 (limit (next-single-property-change end 'mime-view-entity
7365 (if (text-property-any end limit 'article-type 'signature)
7367 (gnus-delete-wash-type 'signature)
7368 (gnus-remove-text-properties-when
7369 'article-type 'signature end limit
7370 (cons 'article-type (cons 'signature
7371 gnus-hidden-properties))))
7372 (gnus-add-wash-type 'signature)
7373 (gnus-add-text-properties-when
7374 'article-type nil end limit
7375 (cons 'article-type (cons 'signature
7376 gnus-hidden-properties)))))
7377 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7378 (gnus-set-mode-line 'article))))
7380 (defun gnus-button-entry ()
7381 ;; Return the first entry in `gnus-button-alist' matching this place.
7382 (let ((alist gnus-button-alist)
7385 (setq entry (pop alist))
7386 (if (looking-at (eval (car entry)))
7391 (defun gnus-button-push (marker)
7392 ;; Push button starting at MARKER.
7395 (let* ((entry (gnus-button-entry))
7396 (inhibit-point-motion-hooks t)
7398 (args (mapcar (lambda (group)
7399 (let ((string (match-string group)))
7400 (set-text-properties
7401 0 (length string) nil string)
7408 (fboundp (symbol-value fun)))
7409 (apply (symbol-value fun) args))
7411 (gnus-message 1 "You must define `%S' to use this button"
7412 (cons fun args)))))))
7414 (defun gnus-parse-news-url (url)
7415 (let (scheme server port group message-id articles)
7418 (goto-char (point-min))
7419 (when (looking-at "\\([A-Za-z]+\\):")
7420 (setq scheme (match-string 1))
7421 (goto-char (match-end 0)))
7422 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7423 (setq server (match-string 1))
7424 (setq port (if (stringp (match-string 3))
7425 (string-to-number (match-string 3))
7427 (goto-char (match-end 0)))
7430 ((looking-at "\\(.*@.*\\)")
7431 (setq message-id (match-string 1)))
7432 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7433 (setq group (match-string 1)
7434 articles (split-string (match-string 2) "-")))
7435 ((looking-at "\\([^/]+\\)/?")
7436 (setq group (match-string 1)))
7438 (error "Unknown news URL syntax"))))
7439 (list scheme server port group message-id articles)))
7441 (defun gnus-button-handle-news (url)
7443 (destructuring-bind (scheme server port group message-id articles)
7444 (gnus-parse-news-url url)
7448 (set-buffer gnus-summary-buffer)
7450 (let ((gnus-refer-article-method
7451 (nconc (list (list 'nntp server))
7452 gnus-refer-article-method))
7453 (nntp-port-number (or port "nntp")))
7454 (gnus-message 7 "Fetching %s with %s"
7455 message-id gnus-refer-article-method)
7456 (gnus-summary-refer-article message-id))
7457 (gnus-summary-refer-article message-id))))
7459 (gnus-button-fetch-group url)))))
7461 (defun gnus-button-handle-man (url)
7463 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7464 (when (eq gnus-button-man-handler 'woman)
7465 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7466 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7467 (funcall gnus-button-man-handler url))
7469 (defun gnus-button-handle-info-url (url)
7470 "Fetch an info URL."
7471 (setq url (mm-subst-char-in-string ?+ ?\ url))
7473 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7474 (gnus-info-find-node
7475 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7477 ")" (gnus-url-unhex-string (match-string 2 url)))))
7478 ((string-match "([^)\"]+)[^\"]+" url)
7480 (gnus-replace-in-string
7481 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7482 (gnus-info-find-node url))
7483 (t (error "Can't parse %s" url))))
7485 (defun gnus-button-handle-info-url-gnome (url)
7486 "Fetch GNOME style info URL."
7487 (setq url (mm-subst-char-in-string ?_ ?\ url))
7488 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7489 (gnus-info-find-node
7491 (gnus-url-unhex-string
7492 (match-string 1 url))
7494 (or (gnus-url-unhex-string
7495 (match-string 2 url))
7497 (error "Can't parse %s" url)))
7499 (defun gnus-button-handle-info-url-kde (url)
7500 "Fetch KDE style info URL."
7501 (gnus-info-find-node (gnus-url-unhex-string url)))
7503 (defun gnus-button-handle-info-keystrokes (url)
7504 "Call `info' when pushing the corresponding URL button."
7505 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7510 (defun gnus-button-openpgp (url)
7511 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7513 (mm-url-insert-file-contents-external url)
7514 (pgg-snarf-keys-region (point-min) (point-max))
7515 (pgg-display-output-buffer nil nil nil)))
7517 (defun gnus-button-message-id (message-id)
7519 (with-current-buffer gnus-summary-buffer
7520 (gnus-summary-refer-article message-id)))
7522 (defun gnus-button-fetch-group (address)
7523 "Fetch GROUP specified by ADDRESS."
7524 (if (not (string-match "[:/]" address))
7525 ;; This is just a simple group url.
7526 (gnus-group-read-ephemeral-group address gnus-select-method)
7529 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7531 (error "Can't parse %s" address)
7532 (gnus-group-read-ephemeral-group
7533 (match-string 4 address)
7534 `(nntp ,(match-string 1 address)
7535 (nntp-address ,(match-string 1 address))
7536 (nntp-port-number ,(if (match-end 3)
7537 (match-string 3 address)
7540 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7542 (defun gnus-url-parse-query-string (query &optional downcase)
7543 (let (retval pairs cur key val)
7544 (setq pairs (split-string query "&"))
7546 (setq cur (car pairs)
7548 (if (not (string-match "=" cur))
7550 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7551 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7553 (setq key (downcase key)))
7554 (setq cur (assoc key retval))
7556 (setcdr cur (cons val (cdr cur)))
7557 (setq retval (cons (list key val) retval)))))
7560 (defun gnus-url-mailto (url)
7561 ;; Send mail to someone
7562 (when (string-match "mailto:/*\\(.*\\)" url)
7563 (setq url (substring url (match-beginning 1) nil)))
7564 (let (to args subject func)
7565 (setq args (gnus-url-parse-query-string
7566 (if (string-match "^\\?" url)
7568 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7569 (concat "to=" (match-string 1 url) "&"
7570 (match-string 2 url))
7571 (concat "to=" url)))
7573 subject (cdr-safe (assoc "subject" args)))
7576 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7579 (message-position-on-field (caar args)))
7580 (insert (gnus-replace-in-string
7581 (mapconcat 'identity (reverse (cdar args)) ", ")
7583 (setq args (cdr args)))
7586 (message-goto-subject))))
7588 (defun gnus-button-embedded-url (address)
7589 "Activate ADDRESS with `browse-url'."
7590 (browse-url (gnus-strip-whitespace address)))
7592 ;;; Next/prev buttons in the article buffer.
7594 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7595 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7597 (defvar gnus-prev-page-map
7598 (let ((map (make-sparse-keymap)))
7599 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7600 (define-key map "\r" 'gnus-button-prev-page)
7603 (defvar gnus-next-page-map
7604 (let ((map (make-sparse-keymap)))
7605 (unless (>= emacs-major-version 21)
7606 ;; XEmacs doesn't care.
7607 (set-keymap-parent map gnus-article-mode-map))
7608 (define-key map gnus-mouse-2 'gnus-button-next-page)
7609 (define-key map "\r" 'gnus-button-next-page)
7612 (defun gnus-insert-prev-page-button ()
7614 (inhibit-read-only t)
7615 (situation (get-text-property (point-min) 'mime-view-situation)))
7617 gnus-prev-page-line-format nil
7618 `(keymap ,gnus-prev-page-map
7620 gnus-callback gnus-article-button-prev-page
7621 article-type annotation
7622 mime-view-situation ,situation))
7623 (widget-convert-button
7625 ;; Exclude a newline.
7628 :action 'gnus-button-prev-page
7629 :button-keymap gnus-prev-page-map)))
7631 (defun gnus-button-next-page (&optional args more-args)
7632 "Go to the next page."
7634 (let ((win (selected-window)))
7635 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7636 (gnus-article-next-page)
7637 (select-window win)))
7639 (defun gnus-button-prev-page (&optional args more-args)
7640 "Go to the prev page."
7642 (let ((win (selected-window)))
7643 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7644 (gnus-article-prev-page)
7645 (select-window win)))
7647 (defun gnus-insert-next-page-button ()
7649 (inhibit-read-only t)
7650 (situation (get-text-property (point-min) 'mime-view-situation)))
7651 (gnus-eval-format gnus-next-page-line-format nil
7652 `(keymap ,gnus-next-page-map
7654 gnus-callback gnus-article-button-next-page
7655 article-type annotation
7656 mime-view-situation ,situation))
7657 (widget-convert-button
7659 ;; Exclude a newline.
7662 :action 'gnus-button-next-page
7663 :button-keymap gnus-next-page-map)))
7665 (defun gnus-article-button-next-page (arg)
7666 "Go to the next page."
7668 (let ((win (selected-window)))
7669 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7670 (gnus-article-next-page)
7671 (select-window win)))
7673 (defun gnus-article-button-prev-page (arg)
7674 "Go to the prev page."
7676 (let ((win (selected-window)))
7677 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7678 (gnus-article-prev-page)
7679 (select-window win)))
7681 (defvar gnus-decode-header-methods
7682 '(mail-decode-encoded-word-region)
7683 "List of methods used to decode headers.
7685 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7686 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7687 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7688 whose names match REGEXP.
7691 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7692 mail-decode-encoded-word-region
7693 (\"chinese\" . rfc1843-decode-region))
7696 (defvar gnus-decode-header-methods-cache nil)
7698 (defun gnus-multi-decode-header (start end)
7699 "Apply the functions from `gnus-encoded-word-methods' that match."
7700 (unless (and gnus-decode-header-methods-cache
7701 (eq gnus-newsgroup-name
7702 (car gnus-decode-header-methods-cache)))
7703 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7706 (nconc gnus-decode-header-methods-cache (list x))
7707 (if (and gnus-newsgroup-name
7708 (string-match (car x) gnus-newsgroup-name))
7709 (nconc gnus-decode-header-methods-cache
7711 gnus-decode-header-methods))
7712 (let ((xlist gnus-decode-header-methods-cache))
7715 (narrow-to-region start end)
7717 (funcall (pop xlist) (point-min) (point-max))))))
7720 ;;; Treatment top-level handling.
7723 (defun gnus-treat-article (condition &optional part-number total-parts type)
7724 (let ((length (- (point-max) (point-min)))
7725 (alist gnus-treatment-function-alist)
7726 (article-goto-body-goes-to-point-min-p t)
7730 (let ((list gnus-article-treat-types))
7732 (when (string-match (pop list) type)
7733 (throw 'found t)))))))
7734 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7735 (entity (static-unless (featurep 'xemacs)
7736 (when (eq 'head condition)
7737 (get-text-property (point-min) 'mime-view-entity))))
7738 val elem buttonized)
7739 (gnus-run-hooks 'gnus-part-display-hook)
7740 (unless gnus-inhibit-treatment
7741 (dolist (elem alist)
7744 (when (gnus-buffer-live-p gnus-summary-buffer)
7745 (set-buffer gnus-summary-buffer))
7746 (symbol-value (car elem))))
7747 (when (and (or (consp val)
7749 (gnus-treat-predicate val)
7750 (or (not (get (car elem) 'highlight))
7752 (when (and (not buttonized)
7754 '(gnus-treat-hide-signature
7755 gnus-treat-highlight-signature)))
7756 (gnus-article-buttonize-signature)
7757 (setq buttonized t))
7759 (funcall (cadr elem)))))
7760 ;; FSF Emacsen does not inherit the existing text properties
7761 ;; in the new text, so we should do it for `mime-view-entity'.
7762 (static-unless (featurep 'xemacs)
7764 (put-text-property (point-min) (point-max)
7765 'mime-view-entity entity))))))
7767 ;; Dynamic variables.
7769 (defvar part-number)
7770 (defvar total-parts)
7775 (defun gnus-treat-predicate (val)
7780 (stringp (car val)))
7781 (apply 'gnus-or (mapcar `(lambda (s)
7782 (string-match s ,(or gnus-newsgroup-name "")))
7785 (let ((pred (pop val)))
7788 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7790 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7792 (not (gnus-treat-predicate (car val))))
7794 (equal (car val) type))
7796 (error "%S is not a valid predicate" pred)))))
7808 (eq part-number total-parts))
7812 (error "%S is not a valid value" val))))
7814 (defun gnus-article-encrypt-body (protocol &optional n)
7815 "Encrypt the article body."
7818 (or gnus-article-encrypt-protocol
7819 (completing-read "Encrypt protocol: "
7820 gnus-article-encrypt-protocol-alist
7822 current-prefix-arg))
7823 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7825 (error "Can't find the encrypt protocol %s" protocol))
7826 (if (member gnus-newsgroup-name '("nndraft:delayed"
7829 (error "Can't encrypt the article in group %s"
7830 gnus-newsgroup-name))
7831 (gnus-summary-iterate n
7833 (set-buffer gnus-summary-buffer)
7834 (let ((mail-parse-charset gnus-newsgroup-charset)
7835 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7836 (summary-buffer gnus-summary-buffer)
7838 (gnus-set-global-variables)
7839 (when (gnus-group-read-only-p)
7840 (error "The current newsgroup does not support article encrypt"))
7841 (gnus-summary-show-article t)
7843 (or (mail-header-references gnus-current-headers) ""))
7844 (set-buffer gnus-article-buffer)
7845 (let* ((inhibit-read-only t)
7847 (mapcar (lambda (field)
7848 (and (save-restriction
7849 (message-narrow-to-head)
7850 (goto-char (point-min))
7851 (search-forward field nil t))
7853 (message-narrow-to-field)
7855 (delete-region (point-min) (point-max))
7857 '("Content-Type:" "Content-Transfer-Encoding:"
7858 "Content-Disposition:"))))
7859 (message-narrow-to-head)
7860 (message-remove-header "MIME-Version")
7861 (goto-char (point-max))
7862 (setq point (point))
7863 (insert (apply 'concat headers))
7865 (narrow-to-region point (point-max))
7866 (let ((message-options message-options))
7867 (message-options-set 'message-sender user-mail-address)
7868 (message-options-set 'message-recipients user-mail-address)
7869 (message-options-set 'message-sign-encrypt 'not)
7871 (goto-char (point-min))
7872 (insert "MIME-Version: 1.0\n")
7874 (gnus-summary-edit-article-done
7875 references nil summary-buffer t))
7876 (when gnus-keep-backlog
7877 (gnus-backlog-remove-article
7878 (car gnus-article-current) (cdr gnus-article-current)))
7880 (when (get-buffer gnus-original-article-buffer)
7881 (set-buffer gnus-original-article-buffer)
7882 (setq gnus-original-article nil)))
7883 (when gnus-use-cache
7884 (gnus-cache-update-article
7885 (car gnus-article-current) (cdr gnus-article-current))))))))
7887 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7888 "The following specs can be used:
7889 %t The security MIME type
7892 %D Details if button is pressed")
7894 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7895 "The following specs can be used:
7896 %t The security MIME type
7899 %D Details if button is pressed")
7901 (defvar gnus-mime-security-button-line-format-alist
7902 '((?t gnus-tmp-type ?s)
7903 (?i gnus-tmp-info ?s)
7904 (?d gnus-tmp-details ?s)
7905 (?D gnus-tmp-pressed-details ?s)))
7907 (defvar gnus-mime-security-button-commands
7908 '((gnus-article-press-button "\r" "Show Detail")
7912 (gnus-mime-security-save-part "o" "Save...")
7921 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
7924 (defvar gnus-mime-security-button-map
7925 (let ((map (make-sparse-keymap)))
7926 (define-key map gnus-mouse-2 'gnus-article-push-button)
7927 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
7928 (dolist (c gnus-mime-security-button-commands)
7929 (define-key map (cadr c) (car c)))
7933 gnus-mime-security-button-menu gnus-mime-security-button-map
7934 "Security button menu."
7938 (unless (eq (car c) 'undefined)
7939 (vector (caddr c) (car c) :enable t)))
7940 gnus-mime-security-button-commands))))
7942 (defun gnus-mime-security-button-menu (event prefix)
7943 "Construct a context-sensitive menu of security commands."
7944 (interactive "e\nP")
7945 (save-window-excursion
7946 (let ((pos (event-start event)))
7947 (select-window (posn-window pos))
7948 (goto-char (posn-point pos))
7949 (gnus-article-check-buffer)
7950 (popup-menu gnus-mime-security-button-menu nil prefix))))
7952 (defvar gnus-mime-security-details-buffer nil)
7954 (defvar gnus-mime-security-button-pressed nil)
7956 (defvar gnus-mime-security-show-details-inline t
7957 "If non-nil, show details in the article buffer.")
7959 (defun gnus-mime-security-verify-or-decrypt (handle)
7960 (mm-remove-parts (cdr handle))
7961 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7962 point (inhibit-read-only t))
7964 (goto-char (car region)))
7966 (narrow-to-region (point) (point))
7967 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7968 (let* ((mm-verify-option 'known)
7969 (mm-decrypt-option 'known)
7970 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7971 (unless (eq nparts (cdr handle))
7972 (mm-destroy-parts (cdr handle))
7973 (setcdr handle nparts))))
7974 (setq point (point))
7975 (gnus-mime-display-security handle)
7976 (goto-char (point-max)))
7978 (delete-region (point) (cdr region))
7979 (set-marker (car region) nil)
7980 (set-marker (cdr region) nil))
7983 (defun gnus-mime-security-show-details (handle)
7984 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7986 (gnus-message 5 "No details.")
7987 (if gnus-mime-security-show-details-inline
7988 (let ((gnus-mime-security-button-pressed
7989 (not (get-text-property (point) 'gnus-mime-details)))
7990 (gnus-mime-security-button-line-format
7991 (get-text-property (point) 'gnus-line-format))
7992 (inhibit-read-only t))
7994 (while (eq (get-text-property (point) 'gnus-line-format)
7995 gnus-mime-security-button-line-format)
7999 (narrow-to-region (point) (point))
8000 (gnus-insert-mime-security-button handle))
8001 (delete-region (point)
8002 (or (text-property-not-all
8005 gnus-mime-security-button-line-format)
8008 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8009 (with-current-buffer gnus-mime-security-details-buffer
8012 (setq gnus-mime-security-details-buffer
8013 (gnus-get-buffer-create "*MIME Security Details*")))
8014 (with-current-buffer gnus-mime-security-details-buffer
8016 (goto-char (point-min)))
8017 (pop-to-buffer gnus-mime-security-details-buffer)))))
8019 (defun gnus-mime-security-press-button (handle)
8021 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8022 (gnus-mime-security-show-details handle)
8023 (gnus-mime-security-verify-or-decrypt handle))))
8025 (defun gnus-insert-mime-security-button (handle &optional displayed)
8026 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8029 (or (nth 2 (assoc protocol mm-verify-function-alist))
8030 (nth 2 (assoc protocol mm-decrypt-function-alist))
8032 (if (equal (car handle) "multipart/signed")
8033 " Signed" " Encrypted")
8036 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8039 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8040 gnus-tmp-pressed-details
8042 (setq gnus-tmp-details
8043 (if gnus-tmp-details
8044 (concat "\n" gnus-tmp-details)
8046 (setq gnus-tmp-pressed-details
8047 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8052 gnus-mime-security-button-line-format
8053 gnus-mime-security-button-line-format-alist
8054 `(keymap ,gnus-mime-security-button-map
8055 gnus-callback gnus-mime-security-press-button
8056 gnus-line-format ,gnus-mime-security-button-line-format
8057 gnus-mime-details ,gnus-mime-security-button-pressed
8058 article-type annotation
8061 ;; Exclude a newline.
8064 (widget-convert-button
8067 :action 'gnus-widget-press-button
8068 :button-keymap gnus-mime-security-button-map
8070 (lambda (widget/window &optional overlay pos)
8071 ;; Needed to properly clear the message due to a bug in
8072 ;; wid-edit (XEmacs only).
8073 (when (boundp 'help-echo-owns-message)
8074 (setq help-echo-owns-message t))
8076 "%S: show detail; %S: more options"
8077 (aref gnus-mouse-2 0)
8078 (aref gnus-down-mouse-3 0))))))
8080 (defun gnus-mime-display-security (handle)
8082 (narrow-to-region (point) (point))
8083 (unless (gnus-unbuttonized-mime-type-p (car handle))
8084 (gnus-insert-mime-security-button handle))
8085 (gnus-mime-display-part (cadr handle))
8088 (unless (gnus-unbuttonized-mime-type-p (car handle))
8089 (let ((gnus-mime-security-button-line-format
8090 gnus-mime-security-button-end-line-format))
8091 (gnus-insert-mime-security-button handle)))
8092 (mm-set-handle-multipart-parameter
8094 (cons (set-marker (make-marker) (point-min))
8095 (set-marker (make-marker) (point-max))))))
8101 (defun gnus-article-header-presentation-method (entity situation)
8102 (mime-insert-header entity)
8103 (article-decode-group-name))
8105 (set-alist 'mime-header-presentation-method-alist
8106 'gnus-original-article-mode
8107 #'gnus-article-header-presentation-method)
8109 (defun gnus-mime-preview-quitting-method ()
8110 (mime-preview-kill-buffer)
8111 (delete-other-windows)
8112 (gnus-article-show-summary)
8113 (gnus-summary-select-article gnus-show-all-headers t))
8115 (set-alist 'mime-preview-quitting-method-alist
8116 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
8118 (set-alist 'mime-preview-following-method-alist
8119 'gnus-original-article-mode #'gnus-following-method)
8121 (set-alist 'mime-preview-over-to-previous-method-alist
8122 'gnus-original-article-mode
8124 (if (> (point-min) 1)
8125 (gnus-article-prev-page)
8126 (gnus-article-read-summary-keys
8127 nil (gnus-character-to-event ?P)))))
8129 (set-alist 'mime-preview-over-to-next-method-alist
8130 'gnus-original-article-mode'
8132 (if (< (point-max) (buffer-size))
8133 (gnus-article-next-page)
8134 (gnus-article-read-summary-keys
8135 nil (gnus-character-to-event ?N)))))
8141 (defun gnus-mime-security-run-function (function)
8142 "Run FUNCTION with the security part under point."
8143 (gnus-article-check-buffer)
8144 (let ((data (get-text-property (point) 'gnus-data))
8146 (when (and (stringp (car-safe data))
8147 (setq buffer (mm-handle-multipart-original-buffer data))
8148 (setq handle (cadr data)))
8149 (if (bufferp (mm-handle-buffer handle))
8151 (setq handle (cons buffer (copy-sequence (cdr handle))))
8152 (mm-handle-set-undisplayer handle nil))
8153 (setq handle (mm-make-handle
8155 (mm-handle-multipart-ctl-parameter handle 'protocol)
8156 nil nil nil nil nil nil)))
8157 (funcall function handle))))
8159 (defun gnus-mime-security-save-part ()
8160 "Save the security part under point."
8162 (gnus-mime-security-run-function 'mm-save-part))
8164 (defun gnus-mime-security-pipe-part ()
8165 "Pipe the security part under point to a process."
8167 (gnus-mime-security-run-function 'mm-pipe-part))
8173 (run-hooks 'gnus-art-load-hook)
8175 ;;; gnus-art.el ends here