1 ;;; gnus-art.el --- article mode commands for 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>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
33 (defvar w3m-minor-mode-map))
36 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
38 (let ((recursive-load-depth-limit 100))
51 (autoload 'gnus-msg-mail "gnus-msg" nil t)
52 (autoload 'gnus-button-mailto "gnus-msg")
53 (autoload 'gnus-button-reply "gnus-msg" nil t)
54 (autoload 'parse-time-string "parse-time" nil nil)
55 (autoload 'ansi-color-apply-on-region "ansi-color")
56 (autoload 'mm-url-insert-file-contents-external "mm-url")
58 (defgroup gnus-article nil
60 :link '(custom-manual "(gnus)Article Buffer")
63 (defgroup gnus-article-treat nil
64 "Treating article parts."
65 :link '(custom-manual "(gnus)Article Hiding")
68 (defgroup gnus-article-hiding nil
69 "Hiding article parts."
70 :link '(custom-manual "(gnus)Article Hiding")
73 (defgroup gnus-article-highlight nil
74 "Article highlighting."
75 :link '(custom-manual "(gnus)Article Highlighting")
79 (defgroup gnus-article-signature nil
81 :link '(custom-manual "(gnus)Article Signature")
84 (defgroup gnus-article-headers nil
86 :link '(custom-manual "(gnus)Hiding Headers")
89 (defgroup gnus-article-washing nil
90 "Special commands on articles."
91 :link '(custom-manual "(gnus)Article Washing")
94 (defgroup gnus-article-emphasis nil
95 "Fontisizing articles."
96 :link '(custom-manual "(gnus)Article Fontisizing")
99 (defgroup gnus-article-saving nil
101 :link '(custom-manual "(gnus)Saving Articles")
102 :group 'gnus-article)
104 (defgroup gnus-article-mime nil
105 "Worshiping the MIME wonder."
106 :link '(custom-manual "(gnus)Using MIME")
107 :group 'gnus-article)
109 (defgroup gnus-article-buttons nil
110 "Pushable buttons in the article buffer."
111 :link '(custom-manual "(gnus)Article Buttons")
112 :group 'gnus-article)
114 (defgroup gnus-article-various nil
115 "Other article options."
116 :link '(custom-manual "(gnus)Misc Article")
117 :group 'gnus-article)
119 (defcustom gnus-ignored-headers
122 (concat "^" header ":"))
123 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
124 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
125 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
126 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
127 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
128 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
129 "X-Attribution" "X-Originating-IP" "Delivered-To"
130 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
131 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
132 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
133 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
134 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
135 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
136 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
137 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
138 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
139 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
140 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
141 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
142 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
143 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
144 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
145 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
146 "List-[A-Za-z]+" "X-Listprocessor-Version"
147 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
148 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
149 "X-Received" "Content-length" "X-precedence"
150 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
151 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
152 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
153 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
154 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
155 "X-Content-length" "X-Posting-Agent" "Original-Received"
156 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
157 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
158 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
159 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
160 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
161 "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice :custom-show nil
167 :group 'gnus-article-hiding)
169 (defcustom gnus-visible-headers
170 "^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:"
171 "*All headers that do not match this regexp will be hidden.
172 This variable can also be a list of regexp of headers to remain visible.
173 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
174 :type '(repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
178 (widget-editable-list-match widget value)))
180 :group 'gnus-article-hiding)
182 (defcustom gnus-sorted-header-list
183 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
184 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
185 "*This variable is a list of regular expressions.
186 If it is non-nil, headers that match the regular expressions will
187 be placed first in the article buffer in the sequence specified by
189 :type '(repeat regexp)
190 :group 'gnus-article-hiding)
192 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
193 "Headers that are only to be displayed if they have interesting data.
194 Possible values in this list are:
196 'empty Headers with no content.
197 'newsgroups Newsgroup identical to Gnus group.
198 'to-address To identical to To-address.
199 'to-list To identical to To-list.
200 'cc-list CC identical to To-list.
201 'followup-to Followup-to identical to Newsgroups.
202 'reply-to Reply-to identical to From.
203 'date Date less than four days old.
204 'long-to To and/or Cc longer than 1024 characters.
205 'many-to Multiple To and/or Cc."
206 :type '(set (const :tag "Headers with no content." empty)
207 (const :tag "Newsgroups identical to Gnus group." newsgroups)
208 (const :tag "To identical to To-address." to-address)
209 (const :tag "To identical to To-list." to-list)
210 (const :tag "CC identical to To-list." cc-list)
211 (const :tag "Followup-to identical to Newsgroups." followup-to)
212 (const :tag "Reply-to identical to From." reply-to)
213 (const :tag "Date less than four days old." date)
214 (const :tag "To and/or Cc longer than 1024 characters." long-to)
215 (const :tag "Multiple To and/or Cc headers." many-to))
216 :group 'gnus-article-hiding)
218 (defcustom gnus-article-skip-boring nil
219 "Skip over text that is not worth reading.
220 By default, if you set this t, then Gnus will display citations and
221 signatures, but will never scroll down to show you a page consisting
222 only of boring text. Boring text is controlled by
223 `gnus-article-boring-faces'."
226 :group 'gnus-article-hiding)
228 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
229 "Regexp matching signature separator.
230 This can also be a list of regexps. In that case, it will be checked
231 from head to tail looking for a separator. Searches will be done from
232 the end of the buffer."
233 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
235 (repeat :tag "List of regexp" regexp))
236 :group 'gnus-article-signature)
238 (defcustom gnus-signature-limit nil
239 "Provide a limit to what is considered a signature.
240 If it is a number, no signature may not be longer (in characters) than
241 that number. If it is a floating point number, no signature may be
242 longer (in lines) than that number. If it is a function, the function
243 will be called without any parameters, and if it returns nil, there is
244 no signature in the buffer. If it is a string, it will be used as a
245 regexp. If it matches, the text in question is not a signature.
247 This can also be a list of the above values."
248 :type '(choice (const nil)
251 (function :value fun)
252 (regexp :value ".*"))
253 :group 'gnus-article-signature)
255 (defcustom gnus-hidden-properties '(invisible t intangible t)
256 "Property list to use for hiding text."
258 :group 'gnus-article-hiding)
260 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
261 ;; frames in a session.
262 (defcustom gnus-article-x-face-command
263 (if (featurep 'xemacs)
264 (if (or (gnus-image-type-available-p 'xface)
265 (gnus-image-type-available-p 'pbm))
266 'gnus-display-x-face-in-from
267 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
268 (if (gnus-image-type-available-p 'pbm)
269 'gnus-display-x-face-in-from
270 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
272 "*String or function to be executed to display an X-Face header.
273 If it is a string, the command will be executed in a sub-shell
274 asynchronously. The compressed face will be piped to this command."
275 :type `(choice string
276 (function-item gnus-display-x-face-in-from)
280 :group 'gnus-article-washing)
282 (defcustom gnus-article-x-face-too-ugly nil
283 "Regexp matching posters whose face shouldn't be shown automatically."
284 :type '(choice regexp (const nil))
285 :group 'gnus-article-washing)
287 (defcustom gnus-article-banner-alist nil
288 "Banner alist for stripping.
290 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
292 :type '(repeat (cons symbol regexp))
293 :group 'gnus-article-washing)
295 (gnus-define-group-parameter
298 "Alist of regexps (to match group names) and banner."
299 :variable-group gnus-article-washing
301 '(choice :tag "Banner"
303 (const :tag "Remove signature" signature)
304 (symbol :tag "Item in `gnus-article-banner-alist'" none)
306 (const :tag "None" nil))
308 "If non-nil, specify how to remove `banners' from articles.
310 Symbol `signature' means to remove signatures delimited by
311 `gnus-signature-separator'. Any other symbol is used to look up a
312 regular expression to match the banner in `gnus-article-banner-alist'.
313 A string is used as a regular expression to match the banner
316 (defcustom gnus-article-address-banner-alist nil
317 "Alist of mail addresses and banners.
318 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
319 to match a mail address in the From: header, BANNER is one of a symbol
320 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
321 If ADDRESS matches author's mail address, it will remove things like
322 advertisements. For example:
324 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
328 (regexp :tag "Address")
329 (choice :tag "Banner" :value nil
330 (const :tag "Remove signature" signature)
331 (symbol :tag "Item in `gnus-article-banner-alist'" none)
333 (const :tag "None" nil))))
335 :group 'gnus-article-washing)
337 (defmacro gnus-emphasis-custom-with-format (&rest body)
339 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
340 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
343 (defun gnus-emphasis-custom-value-to-external (value)
344 (gnus-emphasis-custom-with-format
345 (if (consp (car value))
346 (list (format format (car (car value)) (cdr (car value)))
348 (if (nth 1 value) 2 3)
352 (defun gnus-emphasis-custom-value-to-internal (value)
353 (gnus-emphasis-custom-with-format
354 (let ((regexp (concat "\\`"
355 (format (regexp-quote format)
356 "\\([^()]+\\)" "\\([^()]+\\)")
359 (if (string-match regexp (setq pattern (car value)))
360 (list (cons (match-string 1 pattern) (match-string 2 pattern))
365 (defcustom gnus-emphasis-alist
367 '(("\\*" "\\*" bold nil 2)
370 ("_/" "/_" underline-italic)
371 ("_\\*" "\\*_" underline-bold)
372 ("\\*/" "/\\*" bold-italic)
373 ("_\\*/" "/\\*_" underline-bold-italic))))
375 (gnus-emphasis-custom-with-format
376 (mapcar (lambda (spec)
377 (list (format format (car spec) (cadr spec))
380 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
382 '(;; I've never seen anyone use this strikethru convention whereas I've
383 ;; several times seen it triggered by normal text. --Stef
384 ;; Miles suggests that this form is sometimes used but for italics,
385 ;; so maybe we should map it to `italic'.
386 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
387 ;; 2 3 gnus-emphasis-strikethru)
388 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
389 2 3 gnus-emphasis-underline))))
390 "*Alist that says how to fontify certain phrases.
391 Each item looks like this:
393 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
395 The first element is a regular expression to be matched. The second
396 is a number that says what regular expression grouping used to find
397 the entire emphasized word. The third is a number that says what
398 regexp grouping should be displayed and highlighted. The fourth
399 is the face used for highlighting."
403 :format "%[Customizing Style%]\n%v"
405 (group :tag "Default"
406 :value ("" 0 0 default)
409 (let ((value (widget-get
410 (cadr (widget-get (widget-get widget :parent)
413 (if (not (eq (nth 2 value) 'default))
417 (gnus-emphasis-custom-value-to-external value))))
418 (widget-group-value-create widget))
420 (integer :format "Match group: %v")
421 (integer :format "Emphasize group: %v")
424 :value (("_" . "_") nil default)
426 (regexp :format "Start regexp: %v")
427 (regexp :format "End regexp: %v"))
428 (boolean :format "Show start and end patterns: %[%v%]\n"
429 :on " On " :off " Off ")
431 :get (lambda (symbol)
432 (mapcar 'gnus-emphasis-custom-value-to-internal
433 (default-value symbol)))
434 :set (lambda (symbol value)
435 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
437 :group 'gnus-article-emphasis)
439 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
440 "A regexp to describe whitespace which should not be emphasized.
441 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
442 The former avoids underlining of leading and trailing whitespace,
443 and the latter avoids underlining any whitespace at all."
445 :group 'gnus-article-emphasis
448 (defface gnus-emphasis-bold '((t (:bold t)))
449 "Face used for displaying strong emphasized text (*word*)."
450 :group 'gnus-article-emphasis)
452 (defface gnus-emphasis-italic '((t (:italic t)))
453 "Face used for displaying italic emphasized text (/word/)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-underline '((t (:underline t)))
457 "Face used for displaying underlined emphasized text (_word_)."
458 :group 'gnus-article-emphasis)
460 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
461 "Face used for displaying underlined bold emphasized text (_*word*_)."
462 :group 'gnus-article-emphasis)
464 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
465 "Face used for displaying underlined italic emphasized text (_/word/_)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
469 "Face used for displaying bold italic emphasized text (/*word*/)."
470 :group 'gnus-article-emphasis)
472 (defface gnus-emphasis-underline-bold-italic
473 '((t (:bold t :italic t :underline t)))
474 "Face used for displaying underlined bold italic emphasized text.
475 Example: (_/*word*/_)."
476 :group 'gnus-article-emphasis)
478 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
479 '((t (:strikethru t)))
480 '((t (:strike-through t))))
481 "Face used for displaying strike-through text (-word-)."
482 :group 'gnus-article-emphasis)
484 (defface gnus-emphasis-highlight-words
485 '((t (:background "black" :foreground "yellow")))
486 "Face used for displaying highlighted words."
487 :group 'gnus-article-emphasis)
489 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
490 "Format for display of Date headers in article bodies.
491 See `format-time-string' for the possible values.
493 The variable can also be function, which should return a complete Date
494 header. The function is called with one argument, the time, which can
495 be fed to `format-time-string'."
496 :type '(choice string function)
497 :link '(custom-manual "(gnus)Article Date")
498 :group 'gnus-article-washing)
500 (defcustom gnus-save-all-headers t
501 "*If non-nil, don't remove any headers before saving."
502 :group 'gnus-article-saving
505 (defcustom gnus-prompt-before-saving 'always
506 "*This variable says how much prompting is to be done when saving articles.
507 If it is nil, no prompting will be done, and the articles will be
508 saved to the default files. If this variable is `always', each and
509 every article that is saved will be preceded by a prompt, even when
510 saving large batches of articles. If this variable is neither nil not
511 `always', there the user will be prompted once for a file name for
512 each invocation of the saving commands."
513 :group 'gnus-article-saving
514 :type '(choice (item always)
515 (item :tag "never" nil)
516 (sexp :tag "once" :format "%t\n" :value t)))
518 (defcustom gnus-saved-headers gnus-visible-headers
519 "Headers to keep if `gnus-save-all-headers' is nil.
520 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
521 If that variable is nil, however, all headers that match this regexp
522 will be kept while the rest will be deleted before saving."
523 :group 'gnus-article-saving
526 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
527 "A function to save articles in your favourite format.
528 The function must be interactively callable (in other words, it must
529 be an Emacs command).
531 Gnus provides the following functions:
533 * gnus-summary-save-in-rmail (Rmail format)
534 * gnus-summary-save-in-mail (Unix mail format)
535 * gnus-summary-save-in-folder (MH folder)
536 * gnus-summary-save-in-file (article format)
537 * gnus-summary-save-body-in-file (article body)
538 * gnus-summary-save-in-vm (use VM's folder format)
539 * gnus-summary-write-to-file (article format -- overwrite)."
540 :group 'gnus-article-saving
541 :type '(radio (function-item gnus-summary-save-in-rmail)
542 (function-item gnus-summary-save-in-mail)
543 (function-item gnus-summary-save-in-folder)
544 (function-item gnus-summary-save-in-file)
545 (function-item gnus-summary-save-body-in-file)
546 (function-item gnus-summary-save-in-vm)
547 (function-item gnus-summary-write-to-file)
550 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
551 "A function generating a file name to save articles in Rmail format.
552 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
553 :group 'gnus-article-saving
556 (defcustom gnus-mail-save-name 'gnus-plain-save-name
557 "A function generating a file name to save articles in Unix mail format.
558 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
559 :group 'gnus-article-saving
562 (defcustom gnus-folder-save-name 'gnus-folder-save-name
563 "A function generating a file name to save articles in MH folder.
564 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
565 :group 'gnus-article-saving
568 (defcustom gnus-file-save-name 'gnus-numeric-save-name
569 "A function generating a file name to save articles in article format.
570 The function is called with NEWSGROUP, HEADERS, and optional
572 :group 'gnus-article-saving
575 (defcustom gnus-split-methods
576 '((gnus-article-archive-name)
577 (gnus-article-nndoc-name))
578 "*Variable used to suggest where articles are to be saved.
579 For instance, if you would like to save articles related to Gnus in
580 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
581 you could set this variable to something like:
583 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
584 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
586 This variable is an alist where the key is the match and the
587 value is a list of possible files to save in if the match is
590 If the match is a string, it is used as a regexp match on the
591 article. If the match is a symbol, that symbol will be funcalled
592 from the buffer of the article to be saved with the newsgroup as
593 the parameter. If it is a list, it will be evaled in the same
596 If this form or function returns a string, this string will be
597 used as a possible file name; and if it returns a non-nil list,
598 that list will be used as possible file names."
599 :group 'gnus-article-saving
600 :type '(repeat (choice (list :value (fun) function)
601 (cons :value ("" "") regexp (repeat string))
604 (defcustom gnus-page-delimiter "^\^L"
605 "*Regexp describing what to use as article page delimiters.
606 The default value is \"^\^L\", which is a form linefeed at the
607 beginning of a line."
609 :group 'gnus-article-various)
611 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
612 "*The format specification for the article mode line.
613 See `gnus-summary-mode-line-format' for a closer description.
615 The following additional specs are available:
617 %w The article washing status.
618 %m The number of MIME parts in the article."
620 :group 'gnus-article-various)
622 (defcustom gnus-article-mode-hook nil
623 "*A hook for Gnus article mode."
625 :group 'gnus-article-various)
627 (when (featurep 'xemacs)
628 ;; Extracted from gnus-xmas-define in order to preserve user settings
629 (when (fboundp 'turn-off-scroll-in-place)
630 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
631 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
632 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
634 (defcustom gnus-article-menu-hook nil
635 "*Hook run after the creation of the article mode menu."
637 :group 'gnus-article-various)
639 (defcustom gnus-article-prepare-hook nil
640 "*A hook called after an article has been prepared in the article buffer."
642 :group 'gnus-article-various)
644 (defcustom gnus-copy-article-ignored-headers nil
645 "List of headers to be removed when copying an article.
646 Each element is a regular expression."
647 :version "23.0" ;; No Gnus
648 :type '(repeat regexp)
649 :group 'gnus-article-various)
651 (make-obsolete-variable 'gnus-article-hide-pgp-hook
652 "This variable is obsolete in Gnus 5.10.")
654 (defcustom gnus-article-button-face 'bold
655 "Face used for highlighting buttons in the article buffer.
657 An article button is a piece of text that you can activate by pressing
658 `RET' or `mouse-2' above it."
660 :group 'gnus-article-buttons)
662 (defcustom gnus-article-mouse-face 'highlight
663 "Face used for mouse highlighting in the article buffer.
665 Article buttons will be displayed in this face when the cursor is
668 :group 'gnus-article-buttons)
670 (defcustom gnus-signature-face 'gnus-signature
671 "Face used for highlighting a signature in the article buffer.
672 Obsolete; use the face `gnus-signature' for customizations instead."
674 :group 'gnus-article-highlight
675 :group 'gnus-article-signature)
677 (defface gnus-signature
680 "Face used for highlighting a signature in the article buffer."
681 :group 'gnus-article-highlight
682 :group 'gnus-article-signature)
683 ;; backward-compatibility alias
684 (put 'gnus-signature-face 'face-alias 'gnus-signature)
686 (defface gnus-header-from
689 (:foreground "spring green"))
692 (:foreground "red3"))
695 "Face used for displaying from headers."
696 :group 'gnus-article-headers
697 :group 'gnus-article-highlight)
698 ;; backward-compatibility alias
699 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
701 (defface gnus-header-subject
704 (:foreground "SeaGreen3"))
707 (:foreground "red4"))
709 (:bold t :italic t)))
710 "Face used for displaying subject headers."
711 :group 'gnus-article-headers
712 :group 'gnus-article-highlight)
713 ;; backward-compatibility alias
714 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
716 (defface gnus-header-newsgroups
719 (:foreground "yellow" :italic t))
722 (:foreground "MidnightBlue" :italic t))
725 "Face used for displaying newsgroups headers.
726 In the default setup this face is only used for crossposted
728 :group 'gnus-article-headers
729 :group 'gnus-article-highlight)
730 ;; backward-compatibility alias
731 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
733 (defface gnus-header-name
736 (:foreground "SeaGreen"))
739 (:foreground "maroon"))
742 "Face used for displaying header names."
743 :group 'gnus-article-headers
744 :group 'gnus-article-highlight)
745 ;; backward-compatibility alias
746 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
748 (defface gnus-header-content
751 (:foreground "forest green" :italic t))
754 (:foreground "indianred4" :italic t))
756 (:italic t))) "Face used for displaying header content."
757 :group 'gnus-article-headers
758 :group 'gnus-article-highlight)
759 ;; backward-compatibility alias
760 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
762 (defcustom gnus-header-face-alist
763 '(("From" nil gnus-header-from)
764 ("Subject" nil gnus-header-subject)
765 ("Newsgroups:.*," nil gnus-header-newsgroups)
766 ("" gnus-header-name gnus-header-content))
767 "*Controls highlighting of article headers.
769 An alist of the form (HEADER NAME CONTENT).
771 HEADER is a regular expression which should match the name of a
772 header and NAME and CONTENT are either face names or nil.
774 The name of each header field will be displayed using the face
775 specified by the first element in the list where HEADER matches
776 the header name and NAME is non-nil. Similarly, the content will
777 be displayed by the first non-nil matching CONTENT face."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight
780 :type '(repeat (list (regexp :tag "Header")
782 (item :tag "skip" nil)
783 (face :value default))
784 (choice :tag "Content"
785 (item :tag "skip" nil)
786 (face :value default)))))
788 (defcustom gnus-article-decode-hook
789 '(article-decode-charset article-decode-encoded-words
790 article-decode-group-name article-decode-idna-rhs)
791 "*Hook run to decode charsets in articles."
792 :group 'gnus-article-headers
795 (defcustom gnus-display-mime-function 'gnus-display-mime
796 "Function to display MIME articles."
797 :group 'gnus-article-mime
800 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
801 "Function used to decode headers.")
803 (defvar gnus-article-dumbquotes-map
823 "Table for MS-to-Latin1 translation.")
825 (defcustom gnus-ignored-mime-types nil
826 "List of MIME types that should be ignored by Gnus."
828 :group 'gnus-article-mime
829 :type '(repeat regexp))
831 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
832 "List of MIME types that should not be given buttons when rendered inline.
833 See also `gnus-buttonized-mime-types' which may override this variable.
834 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
836 :group 'gnus-article-mime
837 :type '(repeat regexp))
839 (defcustom gnus-buttonized-mime-types nil
840 "List of MIME types that should be given buttons when rendered inline.
841 If set, this variable overrides `gnus-unbuttonized-mime-types'.
842 To see e.g. security buttons you could set this to
843 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
844 this list to display radio buttons that allow you to choose one of two
845 media types those mails include. See also `mm-discouraged-alternatives'.
846 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
848 :group 'gnus-article-mime
849 :type '(repeat regexp))
851 (defcustom gnus-inhibit-mime-unbuttonizing nil
852 "If non-nil, all MIME parts get buttons.
853 When nil (the default value), then some MIME parts do not get buttons,
854 as described by the variables `gnus-buttonized-mime-types' and
855 `gnus-unbuttonized-mime-types'."
857 :group 'gnus-article-mime
860 (defcustom gnus-body-boundary-delimiter "_"
861 "String used to delimit header and body.
862 This variable is used by `gnus-article-treat-body-boundary' which can
863 be controlled by `gnus-treat-body-boundary'."
865 :group 'gnus-article-various
866 :type '(choice (item :tag "None" :value nil)
869 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
871 "Defines the location of the faces database.
872 For information on obtaining this database of pretty pictures, please
873 see http://www.cs.indiana.edu/picons/ftp/index.html"
875 :type '(repeat directory)
876 :link '(url-link :tag "download"
877 "http://www.cs.indiana.edu/picons/ftp/index.html")
878 :link '(custom-manual "(gnus)Picons")
881 (defun gnus-picons-installed-p ()
882 "Say whether picons are installed on your machine."
883 (let ((installed nil))
884 (dolist (database gnus-picon-databases)
885 (when (file-exists-p database)
889 (defcustom gnus-article-mime-part-function nil
890 "Function called with a MIME handle as the argument.
891 This is meant for people who want to do something automatic based
892 on parts -- for instance, adding Vcard info to a database."
893 :group 'gnus-article-mime
894 :type '(choice (const nil)
897 (defcustom gnus-mime-multipart-functions nil
898 "An alist of MIME types to functions to display them."
900 :group 'gnus-article-mime
901 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
903 (defcustom gnus-article-date-lapsed-new-header nil
904 "Whether the X-Sent and Date headers can coexist.
905 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
906 either replace the old \"Date:\" header (if this variable is nil), or
907 be added below it (otherwise)."
909 :group 'gnus-article-headers
912 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
913 "Function called with a MIME handle as the argument.
914 This is meant for people who want to view first matched part.
915 For `undisplayed-alternative' (default), the first undisplayed
916 part or alternative part is used. For `undisplayed', the first
917 undisplayed part is used. For a function, the first part which
918 the function return t is used. For nil, the first part is
921 :group 'gnus-article-mime
923 (item :tag "first" :value nil)
924 (item :tag "undisplayed" :value undisplayed)
925 (item :tag "undisplayed or alternative"
926 :value undisplayed-alternative)
929 (defcustom gnus-mime-action-alist
930 '(("save to file" . gnus-mime-save-part)
931 ("save and strip" . gnus-mime-save-part-and-strip)
932 ("replace with file" . gnus-mime-replace-part)
933 ("delete part" . gnus-mime-delete-part)
934 ("display as text" . gnus-mime-inline-part)
935 ("view the part" . gnus-mime-view-part)
936 ("pipe to command" . gnus-mime-pipe-part)
937 ("toggle display" . gnus-article-press-button)
938 ("toggle display" . gnus-article-view-part-as-charset)
939 ("view as type" . gnus-mime-view-part-as-type)
940 ("view internally" . gnus-mime-view-part-internally)
941 ("view externally" . gnus-mime-view-part-externally))
942 "An alist of actions that run on the MIME attachment."
943 :group 'gnus-article-mime
944 :type '(repeat (cons (string :tag "name")
947 (defcustom gnus-auto-select-part 1
948 "Advance to next MIME part when deleting or stripping parts.
950 When 0, point will be placed on the same part as before. When
951 positive (negative), move point forward (backwards) this many
952 parts. When nil, redisplay article."
953 :version "23.0" ;; No Gnus
954 :group 'gnus-article-mime
955 :type '(choice (const nil :tag "Redisplay article.")
956 (const 1 :tag "Next part.")
957 (const 0 :tag "Current part.")
961 ;;; The treatment variables
964 (defvar gnus-part-display-hook nil
965 "Hook called on parts that are to receive treatment.")
967 (defvar gnus-article-treat-custom
968 '(choice (const :tag "Off" nil)
970 (const :tag "Header" head)
971 (const :tag "First" first)
972 (const :tag "Last" last)
973 (integer :tag "Less")
974 (repeat :tag "Groups" regexp)
975 (sexp :tag "Predicate")))
977 (defvar gnus-article-treat-head-custom
978 '(choice (const :tag "Off" nil)
979 (const :tag "Header" head)))
981 (defvar gnus-article-treat-types '("text/plain")
984 (defvar gnus-inhibit-treatment nil
985 "Whether to inhibit treatment.")
987 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
988 "Highlight the signature.
989 Valid values are nil, t, `head', `first', `last', an integer or a
990 predicate. See Info node `(gnus)Customizing Articles'."
991 :group 'gnus-article-treat
992 :link '(custom-manual "(gnus)Customizing Articles")
993 :type gnus-article-treat-custom)
994 (put 'gnus-treat-highlight-signature 'highlight t)
996 (defcustom gnus-treat-buttonize 100000
998 Valid values are nil, t, `head', `first', `last', an integer or a
999 predicate. See Info node `(gnus)Customizing Articles'."
1000 :group 'gnus-article-treat
1001 :link '(custom-manual "(gnus)Customizing Articles")
1002 :type gnus-article-treat-custom)
1003 (put 'gnus-treat-buttonize 'highlight t)
1005 (defcustom gnus-treat-buttonize-head 'head
1006 "Add buttons to the head.
1007 Valid values are nil, t, `head', `first', `last', an integer or a
1008 predicate. See Info node `(gnus)Customizing Articles'."
1009 :group 'gnus-article-treat
1010 :link '(custom-manual "(gnus)Customizing Articles")
1011 :type gnus-article-treat-head-custom)
1012 (put 'gnus-treat-buttonize-head 'highlight t)
1014 (defcustom gnus-treat-emphasize
1015 (and (or window-system
1019 Valid values are nil, t, `head', `first', `last', an integer or a
1020 predicate. See Info node `(gnus)Customizing Articles'."
1021 :group 'gnus-article-treat
1022 :link '(custom-manual "(gnus)Customizing Articles")
1023 :type gnus-article-treat-custom)
1024 (put 'gnus-treat-emphasize 'highlight t)
1026 (defcustom gnus-treat-strip-cr nil
1027 "Remove carriage returns.
1028 Valid values are nil, t, `head', `first', `last', an integer or a
1029 predicate. See Info node `(gnus)Customizing Articles'."
1031 :group 'gnus-article-treat
1032 :link '(custom-manual "(gnus)Customizing Articles")
1033 :type gnus-article-treat-custom)
1035 (defcustom gnus-treat-unsplit-urls nil
1036 "Remove newlines from within URLs.
1037 Valid values are nil, t, `head', `first', `last', an integer or a
1038 predicate. See Info node `(gnus)Customizing Articles'."
1040 :group 'gnus-article-treat
1041 :link '(custom-manual "(gnus)Customizing Articles")
1042 :type gnus-article-treat-custom)
1044 (defcustom gnus-treat-leading-whitespace nil
1045 "Remove leading whitespace in headers.
1046 Valid values are nil, t, `head', `first', `last', an integer or a
1047 predicate. See Info node `(gnus)Customizing Articles'."
1049 :group 'gnus-article-treat
1050 :link '(custom-manual "(gnus)Customizing Articles")
1051 :type gnus-article-treat-custom)
1053 (defcustom gnus-treat-hide-headers 'head
1055 Valid values are nil, t, `head', `first', `last', an integer or a
1056 predicate. See Info node `(gnus)Customizing Articles'."
1057 :group 'gnus-article-treat
1058 :link '(custom-manual "(gnus)Customizing Articles")
1059 :type gnus-article-treat-head-custom)
1061 (defcustom gnus-treat-hide-boring-headers nil
1062 "Hide boring headers.
1063 Valid values are nil, t, `head', `first', `last', an integer or a
1064 predicate. See Info node `(gnus)Customizing Articles'."
1065 :group 'gnus-article-treat
1066 :link '(custom-manual "(gnus)Customizing Articles")
1067 :type gnus-article-treat-head-custom)
1069 (defcustom gnus-treat-hide-signature nil
1070 "Hide the signature.
1071 Valid values are nil, t, `head', `first', `last', an integer or a
1072 predicate. See Info node `(gnus)Customizing Articles'."
1073 :group 'gnus-article-treat
1074 :link '(custom-manual "(gnus)Customizing Articles")
1075 :type gnus-article-treat-custom)
1077 (defcustom gnus-treat-fill-article nil
1079 Valid values are nil, t, `head', `first', `last', an integer or a
1080 predicate. See Info node `(gnus)Customizing Articles'."
1081 :group 'gnus-article-treat
1082 :link '(custom-manual "(gnus)Customizing Articles")
1083 :type gnus-article-treat-custom)
1085 (defcustom gnus-treat-hide-citation nil
1087 Valid values are nil, t, `head', `first', `last', an integer or a
1088 predicate. See Info node `(gnus)Customizing Articles'."
1089 :group 'gnus-article-treat
1090 :link '(custom-manual "(gnus)Customizing Articles")
1091 :type gnus-article-treat-custom)
1093 (defcustom gnus-treat-hide-citation-maybe nil
1095 Valid values are nil, t, `head', `first', `last', an integer or a
1096 predicate. See Info node `(gnus)Customizing Articles'."
1097 :group 'gnus-article-treat
1098 :link '(custom-manual "(gnus)Customizing Articles")
1099 :type gnus-article-treat-custom)
1101 (defcustom gnus-treat-strip-list-identifiers 'head
1102 "Strip list identifiers from `gnus-list-identifiers`.
1103 Valid values are nil, t, `head', `first', `last', an integer or a
1104 predicate. See Info node `(gnus)Customizing Articles'."
1106 :group 'gnus-article-treat
1107 :link '(custom-manual "(gnus)Customizing Articles")
1108 :type gnus-article-treat-custom)
1110 (make-obsolete-variable 'gnus-treat-strip-pgp
1111 "This option is obsolete in Gnus 5.10.")
1113 (defcustom gnus-treat-strip-pem nil
1114 "Strip PEM signatures.
1115 Valid values are nil, t, `head', `first', `last', an integer or a
1116 predicate. See Info node `(gnus)Customizing Articles'."
1117 :group 'gnus-article-treat
1118 :link '(custom-manual "(gnus)Customizing Articles")
1119 :type gnus-article-treat-custom)
1121 (defcustom gnus-treat-strip-banner t
1122 "Strip banners from articles.
1123 The banner to be stripped is specified in the `banner' group parameter.
1124 Valid values are nil, t, `head', `first', `last', an integer or a
1125 predicate. See Info node `(gnus)Customizing Articles'."
1126 :group 'gnus-article-treat
1127 :link '(custom-manual "(gnus)Customizing Articles")
1128 :type gnus-article-treat-custom)
1130 (defcustom gnus-treat-highlight-headers 'head
1131 "Highlight the headers.
1132 Valid values are nil, t, `head', `first', `last', an integer or a
1133 predicate. See Info node `(gnus)Customizing Articles'."
1134 :group 'gnus-article-treat
1135 :link '(custom-manual "(gnus)Customizing Articles")
1136 :type gnus-article-treat-head-custom)
1137 (put 'gnus-treat-highlight-headers 'highlight t)
1139 (defcustom gnus-treat-highlight-citation t
1140 "Highlight cited text.
1141 Valid values are nil, t, `head', `first', `last', an integer or a
1142 predicate. See Info node `(gnus)Customizing Articles'."
1143 :group 'gnus-article-treat
1144 :link '(custom-manual "(gnus)Customizing Articles")
1145 :type gnus-article-treat-custom)
1146 (put 'gnus-treat-highlight-citation 'highlight t)
1148 (defcustom gnus-treat-date-ut nil
1149 "Display the Date in UT (GMT).
1150 Valid values are nil, t, `head', `first', `last', an integer or a
1151 predicate. See Info node `(gnus)Customizing Articles'."
1152 :group 'gnus-article-treat
1153 :link '(custom-manual "(gnus)Customizing Articles")
1154 :type gnus-article-treat-head-custom)
1156 (defcustom gnus-treat-date-local nil
1157 "Display the Date in the local timezone.
1158 Valid values are nil, t, `head', `first', `last', an integer or a
1159 predicate. See Info node `(gnus)Customizing Articles'."
1160 :group 'gnus-article-treat
1161 :link '(custom-manual "(gnus)Customizing Articles")
1162 :type gnus-article-treat-head-custom)
1164 (defcustom gnus-treat-date-english nil
1165 "Display the Date in a format that can be read aloud in English.
1166 Valid values are nil, t, `head', `first', `last', an integer or a
1167 predicate. See Info node `(gnus)Customizing Articles'."
1169 :group 'gnus-article-treat
1170 :link '(custom-manual "(gnus)Customizing Articles")
1171 :type gnus-article-treat-head-custom)
1173 (defcustom gnus-treat-date-lapsed nil
1174 "Display the Date header in a way that says how much time has elapsed.
1175 Valid values are nil, t, `head', `first', `last', an integer or a
1176 predicate. See Info node `(gnus)Customizing Articles'."
1177 :group 'gnus-article-treat
1178 :link '(custom-manual "(gnus)Customizing Articles")
1179 :type gnus-article-treat-head-custom)
1181 (defcustom gnus-treat-date-original nil
1182 "Display the date in the original timezone.
1183 Valid values are nil, t, `head', `first', `last', an integer or a
1184 predicate. See Info node `(gnus)Customizing Articles'."
1185 :group 'gnus-article-treat
1186 :link '(custom-manual "(gnus)Customizing Articles")
1187 :type gnus-article-treat-head-custom)
1189 (defcustom gnus-treat-date-iso8601 nil
1190 "Display the date in the ISO8601 format.
1191 Valid values are nil, t, `head', `first', `last', an integer or a
1192 predicate. See Info node `(gnus)Customizing Articles'."
1194 :group 'gnus-article-treat
1195 :link '(custom-manual "(gnus)Customizing Articles")
1196 :type gnus-article-treat-head-custom)
1198 (defcustom gnus-treat-date-user-defined nil
1199 "Display the date in a user-defined format.
1200 The format is defined by the `gnus-article-time-format' variable.
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate. See Info node `(gnus)Customizing Articles'."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-head-custom)
1207 (defcustom gnus-treat-strip-headers-in-body t
1208 "Strip the X-No-Archive header line from the beginning of the body.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate. See Info node `(gnus)Customizing Articles'."
1212 :group 'gnus-article-treat
1213 :link '(custom-manual "(gnus)Customizing Articles")
1214 :type gnus-article-treat-custom)
1216 (defcustom gnus-treat-strip-trailing-blank-lines nil
1217 "Strip trailing blank lines.
1218 Valid values are nil, t, `head', `first', `last', an integer or a
1219 predicate. See Info node `(gnus)Customizing Articles'.
1221 When set to t, it also strips trailing blanks in all MIME parts.
1222 Consider to use `last' instead."
1223 :group 'gnus-article-treat
1224 :link '(custom-manual "(gnus)Customizing Articles")
1225 :type gnus-article-treat-custom)
1227 (defcustom gnus-treat-strip-leading-blank-lines nil
1228 "Strip leading blank lines.
1229 Valid values are nil, t, `head', `first', `last', an integer or a
1230 predicate. See Info node `(gnus)Customizing Articles'.
1232 When set to t, it also strips trailing blanks in all MIME parts."
1233 :group 'gnus-article-treat
1234 :link '(custom-manual "(gnus)Customizing Articles")
1235 :type gnus-article-treat-custom)
1237 (defcustom gnus-treat-strip-multiple-blank-lines nil
1238 "Strip multiple blank lines.
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-custom)
1245 (defcustom gnus-treat-unfold-headers 'head
1246 "Unfold folded header lines.
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-fold-headers nil
1256 Valid values are nil, t, `head', `first', `last', an integer or a
1257 predicate. See Info node `(gnus)Customizing Articles'."
1259 :group 'gnus-article-treat
1260 :link '(custom-manual "(gnus)Customizing Articles")
1261 :type gnus-article-treat-custom)
1263 (defcustom gnus-treat-fold-newsgroups 'head
1264 "Fold the Newsgroups and Followup-To headers.
1265 Valid values are nil, t, `head', `first', `last', an integer or a
1266 predicate. See Info node `(gnus)Customizing Articles'."
1268 :group 'gnus-article-treat
1269 :link '(custom-manual "(gnus)Customizing Articles")
1270 :type gnus-article-treat-custom)
1272 (defcustom gnus-treat-overstrike t
1273 "Treat overstrike highlighting.
1274 Valid values are nil, t, `head', `first', `last', an integer or a
1275 predicate. See Info node `(gnus)Customizing Articles'."
1276 :group 'gnus-article-treat
1277 :link '(custom-manual "(gnus)Customizing Articles")
1278 :type gnus-article-treat-custom)
1279 (put 'gnus-treat-overstrike 'highlight t)
1281 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1282 "Treat ANSI SGR control sequences.
1283 Valid values are nil, t, `head', `first', `last', an integer or a
1284 predicate. See Info node `(gnus)Customizing Articles'."
1285 :group 'gnus-article-treat
1286 :link '(custom-manual "(gnus)Customizing Articles")
1287 :type gnus-article-treat-custom)
1289 (make-obsolete-variable 'gnus-treat-display-xface
1290 'gnus-treat-display-x-face)
1292 (defcustom gnus-treat-display-x-face
1293 (and (not noninteractive)
1294 (or (and (fboundp 'image-type-available-p)
1295 (image-type-available-p 'xbm)
1296 (string-match "^0x" (shell-command-to-string "uncompface"))
1297 (executable-find "icontopbm"))
1298 (and (featurep 'xemacs)
1301 "Display X-Face headers.
1302 Valid values are nil, t, `head', `first', `last', an integer or a
1303 predicate. See Info node `(gnus)Customizing Articles' and Info
1304 node `(gnus)X-Face' for details."
1305 :group 'gnus-article-treat
1307 :link '(custom-manual "(gnus)Customizing Articles")
1308 :link '(custom-manual "(gnus)X-Face")
1309 :type gnus-article-treat-head-custom
1310 :set (lambda (symbol value)
1313 (cond ((or (boundp symbol) (get symbol 'saved-value))
1315 ((boundp 'gnus-treat-display-xface)
1317 ** gnus-treat-display-xface is an obsolete variable;\
1318 use gnus-treat-display-x-face instead")
1319 (default-value 'gnus-treat-display-xface))
1320 ((get 'gnus-treat-display-xface 'saved-value)
1322 ** gnus-treat-display-xface is an obsolete variable;\
1323 use gnus-treat-display-x-face instead")
1324 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1327 (put 'gnus-treat-display-x-face 'highlight t)
1329 (defcustom gnus-treat-display-face
1330 (and (not noninteractive)
1331 (or (and (fboundp 'image-type-available-p)
1332 (image-type-available-p 'png))
1333 (and (featurep 'xemacs)
1336 "Display Face headers.
1337 Valid values are nil, t, `head', `first', `last', an integer or a
1338 predicate. See Info node `(gnus)Customizing Articles' and Info
1339 node `(gnus)X-Face' for details."
1340 :group 'gnus-article-treat
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :link '(custom-manual "(gnus)X-Face")
1344 :type gnus-article-treat-head-custom)
1345 (put 'gnus-treat-display-face 'highlight t)
1347 (defcustom gnus-treat-display-smileys
1348 (if (or (and (featurep 'xemacs)
1350 (and (fboundp 'image-type-available-p)
1351 (image-type-available-p 'pbm)))
1354 Valid values are nil, t, `head', `first', `last', an integer or a
1355 predicate. See Info node `(gnus)Customizing Articles' and Info
1356 node `(gnus)Smileys' for details."
1357 :group 'gnus-article-treat
1359 :link '(custom-manual "(gnus)Customizing Articles")
1360 :link '(custom-manual "(gnus)Smileys")
1361 :type gnus-article-treat-custom)
1362 (put 'gnus-treat-display-smileys 'highlight t)
1364 (defcustom gnus-treat-from-picon
1365 (if (and (gnus-image-type-available-p 'xpm)
1366 (gnus-picons-installed-p))
1368 "Display picons in the From header.
1369 Valid values are nil, t, `head', `first', `last', an integer or a
1370 predicate. See Info node `(gnus)Customizing Articles' and Info
1371 node `(gnus)Picons' for details."
1373 :group 'gnus-article-treat
1375 :link '(custom-manual "(gnus)Customizing Articles")
1376 :link '(custom-manual "(gnus)Picons")
1377 :type gnus-article-treat-head-custom)
1378 (put 'gnus-treat-from-picon 'highlight t)
1380 (defcustom gnus-treat-mail-picon
1381 (if (and (gnus-image-type-available-p 'xpm)
1382 (gnus-picons-installed-p))
1384 "Display picons in To and Cc headers.
1385 Valid values are nil, t, `head', `first', `last', an integer or a
1386 predicate. See Info node `(gnus)Customizing Articles' and Info
1387 node `(gnus)Picons' for details."
1389 :group 'gnus-article-treat
1391 :link '(custom-manual "(gnus)Customizing Articles")
1392 :link '(custom-manual "(gnus)Picons")
1393 :type gnus-article-treat-head-custom)
1394 (put 'gnus-treat-mail-picon 'highlight t)
1396 (defcustom gnus-treat-newsgroups-picon
1397 (if (and (gnus-image-type-available-p 'xpm)
1398 (gnus-picons-installed-p))
1400 "Display picons in the Newsgroups and Followup-To 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)Picons' for details."
1405 :group 'gnus-article-treat
1407 :link '(custom-manual "(gnus)Customizing Articles")
1408 :link '(custom-manual "(gnus)Picons")
1409 :type gnus-article-treat-head-custom)
1410 (put 'gnus-treat-newsgroups-picon 'highlight t)
1412 (defcustom gnus-treat-body-boundary
1413 (if (and (eq window-system 'x)
1414 (or gnus-treat-newsgroups-picon
1415 gnus-treat-mail-picon
1416 gnus-treat-from-picon))
1418 "Draw a boundary at the end of the headers.
1419 Valid values are nil and `head'.
1420 See Info node `(gnus)Customizing Articles' for details."
1422 :group 'gnus-article-treat
1423 :link '(custom-manual "(gnus)Customizing Articles")
1424 :type gnus-article-treat-head-custom)
1426 (defcustom gnus-treat-capitalize-sentences nil
1427 "Capitalize sentence-starting words.
1428 Valid values are nil, t, `head', `first', `last', an integer or a
1429 predicate. See Info node `(gnus)Customizing Articles'."
1431 :group 'gnus-article-treat
1432 :link '(custom-manual "(gnus)Customizing Articles")
1433 :type gnus-article-treat-custom)
1435 (defcustom gnus-treat-wash-html nil
1437 Valid values are nil, t, `head', `first', `last', an integer or a
1438 predicate. See Info node `(gnus)Customizing Articles'."
1440 :group 'gnus-article-treat
1441 :link '(custom-manual "(gnus)Customizing Articles")
1442 :type gnus-article-treat-custom)
1444 (defcustom gnus-treat-fill-long-lines nil
1446 Valid values are nil, t, `head', `first', `last', an integer or a
1447 predicate. See Info node `(gnus)Customizing Articles'."
1448 :group 'gnus-article-treat
1449 :link '(custom-manual "(gnus)Customizing Articles")
1450 :type gnus-article-treat-custom)
1452 (defcustom gnus-treat-play-sounds nil
1454 Valid values are nil, t, `head', `first', `last', an integer or a
1455 predicate. See Info node `(gnus)Customizing Articles'."
1457 :group 'gnus-article-treat
1458 :link '(custom-manual "(gnus)Customizing Articles")
1459 :type gnus-article-treat-custom)
1461 (defcustom gnus-treat-translate nil
1462 "Translate articles from one language to another.
1463 Valid values are nil, t, `head', `first', `last', an integer or a
1464 predicate. See Info node `(gnus)Customizing Articles'."
1466 :group 'gnus-article-treat
1467 :link '(custom-manual "(gnus)Customizing Articles")
1468 :type gnus-article-treat-custom)
1470 (defcustom gnus-treat-x-pgp-sig nil
1472 To automatically treat X-PGP-Sig, set it to head.
1473 Valid values are nil, t, `head', `first', `last', an integer or a
1474 predicate. See Info node `(gnus)Customizing Articles'."
1476 :group 'gnus-article-treat
1477 :group 'mime-security
1478 :link '(custom-manual "(gnus)Customizing Articles")
1479 :type gnus-article-treat-custom)
1481 (defvar gnus-article-encrypt-protocol-alist
1482 '(("PGP" . mml2015-self-encrypt)))
1484 ;; Set to nil if more than one protocol added to
1485 ;; gnus-article-encrypt-protocol-alist.
1486 (defcustom gnus-article-encrypt-protocol "PGP"
1487 "The protocol used for encrypt articles.
1488 It is a string, such as \"PGP\". If nil, ask user."
1491 :group 'mime-security)
1493 (defvar gnus-article-wash-function nil
1494 "Function used for converting HTML into text.")
1496 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1497 (mm-coding-system-p 'utf-8)
1498 (executable-find idna-program))
1499 "Whether IDNA decoding of headers is used when viewing messages.
1500 This requires GNU Libidn, and by default only enabled if it is found."
1502 :group 'gnus-article-headers
1505 (defcustom gnus-article-over-scroll nil
1506 "If non-nil, allow scrolling the article buffer even when there no more text."
1508 :group 'gnus-article
1511 ;;; Internal variables
1513 (defvar gnus-english-month-names
1514 '("January" "February" "March" "April" "May" "June" "July" "August"
1515 "September" "October" "November" "December"))
1517 (defvar gnus-button-regexp nil)
1518 (defvar gnus-button-marker-list nil)
1519 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1521 (defvar gnus-button-last nil)
1522 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1524 (defvar article-goto-body-goes-to-point-min-p nil)
1525 (defvar gnus-article-wash-types nil)
1526 (defvar gnus-article-emphasis-alist nil)
1527 (defvar gnus-article-image-alist nil)
1529 (defvar gnus-article-mime-handle-alist-1 nil)
1530 (defvar gnus-treatment-function-alist
1531 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1532 (gnus-treat-strip-banner gnus-article-strip-banner)
1533 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1534 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1535 (gnus-treat-buttonize gnus-article-add-buttons)
1536 (gnus-treat-fill-article gnus-article-fill-cited-article)
1537 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1538 (gnus-treat-strip-cr gnus-article-remove-cr)
1539 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1540 (gnus-treat-date-ut gnus-article-date-ut)
1541 (gnus-treat-date-local gnus-article-date-local)
1542 (gnus-treat-date-english gnus-article-date-english)
1543 (gnus-treat-date-original gnus-article-date-original)
1544 (gnus-treat-date-user-defined gnus-article-date-user)
1545 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1546 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1547 (gnus-treat-display-x-face gnus-article-display-x-face)
1548 (gnus-treat-display-face gnus-article-display-face)
1549 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1550 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1551 (gnus-treat-hide-signature gnus-article-hide-signature)
1552 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1553 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1554 (gnus-treat-strip-pem gnus-article-hide-pem)
1555 (gnus-treat-from-picon gnus-treat-from-picon)
1556 (gnus-treat-mail-picon gnus-treat-mail-picon)
1557 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1558 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1559 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1560 (gnus-treat-strip-trailing-blank-lines
1561 gnus-article-remove-trailing-blank-lines)
1562 (gnus-treat-strip-leading-blank-lines
1563 gnus-article-strip-leading-blank-lines)
1564 (gnus-treat-strip-multiple-blank-lines
1565 gnus-article-strip-multiple-blank-lines)
1566 (gnus-treat-overstrike gnus-article-treat-overstrike)
1567 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1568 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1569 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1570 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1571 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1572 (gnus-treat-display-smileys gnus-treat-smiley)
1573 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1574 (gnus-treat-wash-html gnus-article-wash-html)
1575 (gnus-treat-emphasize gnus-article-emphasize)
1576 (gnus-treat-hide-citation gnus-article-hide-citation)
1577 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1578 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1579 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1580 (gnus-treat-play-sounds gnus-earcon-display)))
1582 (defvar gnus-article-mime-handle-alist nil)
1583 (defvar article-lapsed-timer nil)
1584 (defvar gnus-article-current-summary nil)
1586 (defvar gnus-article-mode-syntax-table
1587 (let ((table (copy-syntax-table text-mode-syntax-table)))
1588 ;; This causes the citation match run O(2^n).
1589 ;; (modify-syntax-entry ?- "w" table)
1590 (modify-syntax-entry ?> ")<" table)
1591 (modify-syntax-entry ?< "(>" table)
1592 ;; make M-. in article buffers work for `foo' strings
1593 (modify-syntax-entry ?' " " table)
1594 (modify-syntax-entry ?` " " table)
1596 "Syntax table used in article mode buffers.
1597 Initialized from `text-mode-syntax-table.")
1599 (defvar gnus-save-article-buffer nil)
1601 (defvar gnus-article-mode-line-format-alist
1602 (nconc '((?w (gnus-article-wash-status) ?s)
1603 (?m (gnus-article-mime-part-status) ?s))
1604 gnus-summary-mode-line-format-alist))
1606 (defvar gnus-number-of-articles-to-be-saved nil)
1608 (defvar gnus-inhibit-hiding nil)
1610 (defvar gnus-article-edit-mode nil)
1612 ;;; Macros for dealing with the article buffer.
1614 (defmacro gnus-with-article-headers (&rest forms)
1616 (set-buffer gnus-article-buffer)
1618 (let ((inhibit-read-only t)
1619 (inhibit-point-motion-hooks t)
1620 (case-fold-search t))
1621 (article-narrow-to-head)
1624 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1625 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1627 (defmacro gnus-with-article-buffer (&rest forms)
1629 (set-buffer gnus-article-buffer)
1630 (let ((inhibit-read-only t))
1633 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1634 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1636 (defun gnus-article-goto-header (header)
1637 "Go to HEADER, which is a regular expression."
1638 (re-search-forward (concat "^\\(" header "\\):") nil t))
1640 (defsubst gnus-article-hide-text (b e props)
1641 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1642 (gnus-add-text-properties-when 'article-type nil b e props)
1643 (when (memq 'intangible props)
1645 (max (1- b) (point-min))
1646 b 'intangible (cddr (memq 'intangible props)))))
1648 (defsubst gnus-article-unhide-text (b e)
1649 "Remove hidden text properties from region between B and E."
1650 (remove-text-properties b e gnus-hidden-properties)
1651 (when (memq 'intangible gnus-hidden-properties)
1652 (put-text-property (max (1- b) (point-min))
1653 b 'intangible nil)))
1655 (defun gnus-article-hide-text-type (b e type)
1656 "Hide text of TYPE between B and E."
1657 (gnus-add-wash-type type)
1658 (gnus-article-hide-text
1659 b e (cons 'article-type (cons type gnus-hidden-properties))))
1661 (defun gnus-article-unhide-text-type (b e type)
1662 "Unhide text of TYPE between B and E."
1663 (gnus-delete-wash-type type)
1664 (remove-text-properties
1665 b e (cons 'article-type (cons type gnus-hidden-properties)))
1666 (when (memq 'intangible gnus-hidden-properties)
1667 (put-text-property (max (1- b) (point-min))
1668 b 'intangible nil)))
1670 (defun gnus-article-hide-text-of-type (type)
1671 "Hide text of TYPE in the current buffer."
1673 (let ((b (point-min))
1675 (while (setq b (text-property-any b e 'article-type type))
1676 (add-text-properties b (incf b) gnus-hidden-properties)))))
1678 (defun gnus-article-delete-text-of-type (type)
1679 "Delete text of TYPE in the current buffer."
1681 (let ((b (point-min)))
1682 (if (eq type 'multipart)
1683 ;; Remove MIME buttons associated with multipart/alternative parts.
1686 (while (if (get-text-property (point) 'gnus-part)
1688 (when (setq b (next-single-property-change (point)
1693 (skip-chars-forward "\n")
1694 (when (eq (get-text-property b 'article-type) 'multipart)
1695 (delete-region b (point)))))
1696 (while (setq b (text-property-any b (point-max) 'article-type type))
1698 b (or (text-property-not-all b (point-max) 'article-type type)
1701 (defun gnus-article-delete-invisible-text ()
1702 "Delete all invisible text in the current buffer."
1704 (let ((b (point-min)))
1705 (while (setq b (text-property-any b (point-max) 'invisible t))
1707 b (or (text-property-not-all b (point-max) 'invisible t)
1710 (defun gnus-article-text-type-exists-p (type)
1711 "Say whether any text of type TYPE exists in the buffer."
1712 (text-property-any (point-min) (point-max) 'article-type type))
1714 (defsubst gnus-article-header-rank ()
1715 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1716 (let ((list gnus-sorted-header-list)
1719 (if (looking-at (car list))
1721 (setq list (cdr list))
1725 (defun article-hide-headers (&optional arg delete)
1726 "Hide unwanted headers and possibly sort them as well."
1728 ;; This function might be inhibited.
1729 (unless gnus-inhibit-hiding
1730 (let ((inhibit-read-only nil)
1731 (case-fold-search t)
1732 (max (1+ (length gnus-sorted-header-list)))
1733 (inhibit-point-motion-hooks t)
1734 (cur (current-buffer))
1735 ignored visible beg)
1737 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1738 ;; group parameters, so we should go to the summary buffer.
1741 (progn (set-buffer gnus-summary-buffer) t)
1743 (setq ignored (when (not gnus-visible-headers)
1744 (cond ((stringp gnus-ignored-headers)
1745 gnus-ignored-headers)
1746 ((listp gnus-ignored-headers)
1747 (mapconcat 'identity
1748 gnus-ignored-headers
1750 visible (cond ((stringp gnus-visible-headers)
1751 gnus-visible-headers)
1752 ((and gnus-visible-headers
1753 (listp gnus-visible-headers))
1754 (mapconcat 'identity
1755 gnus-visible-headers
1759 ;; First we narrow to just the headers.
1760 (article-narrow-to-head)
1761 ;; Hide any "From " lines at the beginning of (mail) articles.
1762 (while (looking-at "From ")
1765 (delete-region (point-min) (point)))
1766 ;; Then treat the rest of the header lines.
1767 ;; Then we use the two regular expressions
1768 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1769 ;; select which header lines is to remain visible in the
1771 (while (re-search-forward "^[^ \t:]*:" nil t)
1773 ;; Mark the rank of the header.
1775 (point) (1+ (point)) 'message-rank
1776 (if (or (and visible (looking-at visible))
1778 (not (looking-at ignored))))
1779 (gnus-article-header-rank)
1782 (message-sort-headers-1)
1783 (when (setq beg (text-property-any
1784 (point-min) (point-max) 'message-rank (+ 2 max)))
1785 ;; We delete the unwanted headers.
1786 (gnus-add-wash-type 'headers)
1787 (add-text-properties (point-min) (+ 5 (point-min))
1788 '(article-type headers dummy-invisible t))
1789 (delete-region beg (point-max))))))))
1791 (defun article-hide-boring-headers (&optional arg)
1792 "Toggle hiding of headers that aren't very interesting.
1793 If given a negative prefix, always show; if given a positive prefix,
1795 (interactive (gnus-article-hidden-arg))
1796 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1797 (not gnus-show-all-headers))
1800 (let ((inhibit-read-only t)
1801 (inhibit-point-motion-hooks t))
1802 (article-narrow-to-head)
1803 (dolist (elem gnus-boring-article-headers)
1804 (goto-char (point-min))
1806 ;; Hide empty headers.
1808 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1810 (gnus-article-hide-text-type
1814 (if (re-search-forward "^[^ \t]" nil t)
1818 ;; Hide boring Newsgroups header.
1819 ((eq elem 'newsgroups)
1820 (when (gnus-string-equal
1821 (gnus-fetch-field "newsgroups")
1822 (gnus-group-real-name
1823 (if (boundp 'gnus-newsgroup-name)
1826 (gnus-article-hide-header "newsgroups")))
1827 ((eq elem 'to-address)
1828 (let ((to (message-fetch-field "to"))
1830 (gnus-parameter-to-address
1831 (if (boundp 'gnus-newsgroup-name)
1832 gnus-newsgroup-name ""))))
1833 (when (and to to-address
1836 ;; only one address in To
1837 (nth 1 (mail-extract-address-components to))
1839 (gnus-article-hide-header "to"))))
1841 (let ((to (message-fetch-field "to"))
1843 (gnus-parameter-to-list
1844 (if (boundp 'gnus-newsgroup-name)
1845 gnus-newsgroup-name ""))))
1846 (when (and to to-list
1849 ;; only one address in To
1850 (nth 1 (mail-extract-address-components to))
1852 (gnus-article-hide-header "to"))))
1854 (let ((cc (message-fetch-field "cc"))
1856 (gnus-parameter-to-list
1857 (if (boundp 'gnus-newsgroup-name)
1858 gnus-newsgroup-name ""))))
1859 (when (and cc to-list
1862 ;; only one address in CC
1863 (nth 1 (mail-extract-address-components cc))
1865 (gnus-article-hide-header "cc"))))
1866 ((eq elem 'followup-to)
1867 (when (gnus-string-equal
1868 (message-fetch-field "followup-to")
1869 (message-fetch-field "newsgroups"))
1870 (gnus-article-hide-header "followup-to")))
1871 ((eq elem 'reply-to)
1872 (if (gnus-group-find-parameter
1873 gnus-newsgroup-name 'broken-reply-to)
1874 (gnus-article-hide-header "reply-to")
1875 (let ((from (message-fetch-field "from"))
1876 (reply-to (message-fetch-field "reply-to")))
1883 (lambda (x) (downcase (cadr x)))
1884 (mail-extract-address-components from t))
1887 (lambda (x) (downcase (cadr x)))
1888 (mail-extract-address-components reply-to t))
1890 (gnus-article-hide-header "reply-to")))))
1892 (let ((date (message-fetch-field "date")))
1894 (< (days-between (current-time-string) date)
1896 (gnus-article-hide-header "date"))))
1898 (let ((to (message-fetch-field "to"))
1899 (cc (message-fetch-field "cc")))
1900 (when (> (length to) 1024)
1901 (gnus-article-hide-header "to"))
1902 (when (> (length cc) 1024)
1903 (gnus-article-hide-header "cc"))))
1907 (goto-char (point-min))
1908 (while (re-search-forward "^to:" nil t)
1909 (setq to-count (1+ to-count)))
1910 (when (> to-count 1)
1911 (while (> to-count 0)
1912 (goto-char (point-min))
1914 (re-search-forward "^to:" nil nil to-count)
1916 (narrow-to-region (point) (point-max))
1917 (gnus-article-hide-header "to"))
1918 (setq to-count (1- to-count))))
1919 (goto-char (point-min))
1920 (while (re-search-forward "^cc:" nil t)
1921 (setq cc-count (1+ cc-count)))
1922 (when (> cc-count 1)
1923 (while (> cc-count 0)
1924 (goto-char (point-min))
1926 (re-search-forward "^cc:" nil nil cc-count)
1928 (narrow-to-region (point) (point-max))
1929 (gnus-article-hide-header "cc"))
1930 (setq cc-count (1- cc-count)))))))))))))
1932 (defun gnus-article-hide-header (header)
1934 (goto-char (point-min))
1935 (when (re-search-forward (concat "^" header ":") nil t)
1936 (gnus-article-hide-text-type
1940 (if (re-search-forward "^[^ \t]" nil t)
1945 (defvar gnus-article-normalized-header-length 40
1946 "Length of normalized headers.")
1948 (defun article-normalize-headers ()
1949 "Make all header lines 40 characters long."
1951 (let ((inhibit-read-only t)
1955 (article-narrow-to-head)
1958 ((< (setq column (- (point-at-eol) (point)))
1959 gnus-article-normalized-header-length)
1961 (insert (make-string
1962 (- gnus-article-normalized-header-length column)
1964 ((> column gnus-article-normalized-header-length)
1965 (gnus-put-text-property
1967 (forward-char gnus-article-normalized-header-length)
1974 (forward-line 1))))))
1976 (defun article-treat-dumbquotes ()
1977 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1978 Note that this function guesses whether a character is a sm*rtq**t* or
1979 not, so it should only be used interactively.
1981 Sm*rtq**t*s are M****s***'s unilateral extension to the
1982 iso-8859-1 character map in an attempt to provide more quoting
1983 characters. If you see something like \\222 or \\264 where
1984 you're expecting some kind of apostrophe or quotation mark, then
1987 (article-translate-strings gnus-article-dumbquotes-map))
1989 (defun article-translate-characters (from to)
1990 "Translate all characters in the body of the article according to FROM and TO.
1991 FROM is a string of characters to translate from; to is a string of
1992 characters to translate to."
1994 (when (article-goto-body)
1995 (let ((inhibit-read-only t)
1996 (x (make-string 225 ?x))
1998 (while (< (incf i) (length x))
2001 (while (< i (length from))
2002 (aset x (aref from i) (aref to i))
2004 (translate-region (point) (point-max) x)))))
2006 (defun article-translate-strings (map)
2007 "Translate all string in the body of the article according to MAP.
2008 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2010 (when (article-goto-body)
2011 (let ((inhibit-read-only t))
2014 (while (search-forward (car elem) nil t)
2015 (replace-match (cadr elem)))))))))
2017 (defun article-treat-overstrike ()
2018 "Translate overstrikes into bold text."
2021 (when (article-goto-body)
2022 (let ((inhibit-read-only t))
2023 (while (search-forward "\b" nil t)
2024 (let ((next (char-after))
2025 (previous (char-after (- (point) 2))))
2026 ;; We do the boldification/underlining by hiding the
2027 ;; overstrikes and putting the proper text property
2031 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2032 (put-text-property (point) (1+ (point)) 'face 'bold))
2034 (gnus-article-hide-text-type
2035 (1- (point)) (1+ (point)) 'overstrike)
2037 (- (point) 2) (1- (point)) 'face 'underline))
2039 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2041 (point) (1+ (point)) 'face 'underline)))))))))
2043 (defun article-treat-ansi-sequences ()
2044 "Translate ANSI SGR control sequences into overlays or extents."
2047 (when (article-goto-body)
2048 (let ((inhibit-read-only t))
2049 (ansi-color-apply-on-region (point) (point-max))))))
2051 (defun gnus-article-treat-unfold-headers ()
2052 "Unfold folded message headers.
2053 Only the headers that fit into the current window width will be
2056 (gnus-with-article-headers
2060 (mail-header-narrow-to-field)
2061 (let ((header (buffer-string)))
2064 (goto-char (point-min))
2065 (while (re-search-forward "\n[\t ]" nil t)
2066 (replace-match " " t t)))
2067 (setq length (- (point-max) (point-min) 1)))
2068 (when (< length (window-width))
2069 (while (re-search-forward "\n[\t ]" nil t)
2070 (replace-match " " t t)))
2071 (goto-char (point-max)))))))
2073 (defun gnus-article-treat-fold-headers ()
2074 "Fold message headers."
2076 (gnus-with-article-headers
2079 (mail-header-narrow-to-field)
2080 (mail-header-fold-field)
2081 (goto-char (point-max))))))
2083 (defun gnus-treat-smiley ()
2084 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2086 (gnus-with-article-buffer
2087 (if (memq 'smiley gnus-article-wash-types)
2088 (gnus-delete-images 'smiley)
2090 (let ((images (smiley-region (point) (point-max))))
2092 (gnus-add-wash-type 'smiley)
2093 (dolist (image images)
2094 (gnus-add-image 'smiley image)))))))
2096 (defun gnus-article-remove-images ()
2097 "Remove all images from the article buffer."
2099 (gnus-with-article-buffer
2100 (dolist (elem gnus-article-image-alist)
2101 (gnus-delete-images (car elem)))))
2103 (defun gnus-article-treat-fold-newsgroups ()
2104 "Unfold folded message headers.
2105 Only the headers that fit into the current window width will be
2108 (gnus-with-article-headers
2109 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2111 (mail-header-narrow-to-field)
2112 (while (re-search-forward ", *" nil t)
2113 (replace-match ", " t t))
2114 (mail-header-fold-field)
2115 (goto-char (point-max))))))
2117 (defun gnus-article-treat-body-boundary ()
2118 "Place a boundary line at the end of the headers."
2120 (when (and gnus-body-boundary-delimiter
2121 (> (length gnus-body-boundary-delimiter) 0))
2122 (gnus-with-article-headers
2123 (goto-char (point-max))
2124 (let ((start (point)))
2125 (insert "X-Boundary: ")
2126 (gnus-add-text-properties start (point) '(invisible t intangible t))
2128 (while (>= (1- (window-width)) (length str))
2129 (setq str (concat str gnus-body-boundary-delimiter)))
2130 (substring str 0 (1- (window-width))))
2132 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2134 (defun article-fill-long-lines ()
2135 "Fill lines that are wider than the window width."
2138 (let ((inhibit-read-only t)
2139 (width (window-width (get-buffer-window (current-buffer)))))
2142 (let ((adaptive-fill-mode nil)) ;Why? -sm
2145 (when (>= (current-column) (min fill-column width))
2146 (narrow-to-region (min (1+ (point)) (point-max))
2148 (let ((goback (point-marker)))
2149 (fill-paragraph nil)
2150 (goto-char (marker-position goback)))
2152 (forward-line 1)))))))
2154 (defun article-capitalize-sentences ()
2155 "Capitalize the first word in each sentence."
2158 (let ((inhibit-read-only t)
2159 (paragraph-start "^[\n\^L]"))
2163 (forward-sentence)))))
2165 (defun article-remove-cr ()
2166 "Remove trailing CRs and then translate remaining CRs into LFs."
2169 (let ((inhibit-read-only t))
2170 (goto-char (point-min))
2171 (while (re-search-forward "\r+$" nil t)
2172 (replace-match "" t t))
2173 (goto-char (point-min))
2174 (while (search-forward "\r" nil t)
2175 (replace-match "\n" t t)))))
2177 (defun article-remove-trailing-blank-lines ()
2178 "Remove all trailing blank lines from the article."
2181 (let ((inhibit-read-only t))
2182 (goto-char (point-max))
2186 (while (and (not (bobp))
2187 (looking-at "^[ \t]*$")
2188 (not (gnus-annotation-in-region-p
2189 (point) (point-at-eol))))
2195 (defvar gnus-face-properties-alist))
2197 (defun article-display-face ()
2198 "Display any Face headers in the header."
2200 (let ((wash-face-p buffer-read-only))
2201 (gnus-with-article-headers
2202 ;; When displaying parts, this function can be called several times on
2203 ;; the same article, without any intended toggle semantic (as typing `W
2204 ;; D d' would have). So face deletion must occur only when we come from
2205 ;; an interactive command, that is when the *Article* buffer is
2207 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2208 (gnus-delete-images 'face)
2209 (let (face faces from)
2210 (save-current-buffer
2211 (when (and wash-face-p
2212 (gnus-buffer-live-p gnus-original-article-buffer)
2213 (not (re-search-forward "^Face:[\t ]*" nil t)))
2214 (set-buffer gnus-original-article-buffer))
2216 (mail-narrow-to-head)
2217 (while (gnus-article-goto-header "Face")
2218 (push (mail-header-field-value) faces))))
2220 (goto-char (point-min))
2221 (let ((from (gnus-article-goto-header "from"))
2226 (insert "[no `from' set]\n"))
2228 (when (setq png (gnus-convert-face-to-png (pop faces)))
2230 (apply 'gnus-create-image png 'png t
2231 (cdr (assq 'png gnus-face-properties-alist))))
2233 (gnus-add-wash-type 'face)
2234 (gnus-add-image 'face image)
2235 (gnus-put-image image nil 'face))))))))))
2237 (defun article-display-x-face (&optional force)
2238 "Look for an X-Face header and display it if present."
2239 (interactive (list 'force))
2240 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2241 (gnus-with-article-headers
2242 ;; Delete the old process, if any.
2243 (when (process-status "article-x-face")
2244 (delete-process "article-x-face"))
2245 ;; See the comment in `article-display-face'.
2246 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2247 ;; We have already displayed X-Faces, so we remove them
2249 (gnus-delete-images 'xface)
2251 (let (x-faces from face)
2252 (save-current-buffer
2253 (when (and wash-face-p
2254 (gnus-buffer-live-p gnus-original-article-buffer)
2255 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2256 ;; If type `W f', use gnus-original-article-buffer,
2257 ;; otherwise use the current buffer because displaying
2258 ;; RFC822 parts calls this function too.
2259 (set-buffer gnus-original-article-buffer))
2261 (mail-narrow-to-head)
2262 (while (gnus-article-goto-header "X-Face")
2263 (push (mail-header-field-value) x-faces))
2264 (setq from (message-fetch-field "from"))))
2265 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2266 ;; single external face.
2267 (when (stringp gnus-article-x-face-command)
2268 (setq x-faces (list (car x-faces))))
2270 gnus-article-x-face-command
2272 ;; Check whether this face is censored.
2273 (not gnus-article-x-face-too-ugly)
2275 (not (string-match gnus-article-x-face-too-ugly
2277 (while (setq face (pop x-faces))
2278 ;; We display the face.
2279 (cond ((stringp gnus-article-x-face-command)
2280 ;; The command is a string, so we interpret the command
2281 ;; as a, well, command, and fork it off.
2282 (let ((process-connection-type nil))
2283 (gnus-set-process-query-on-exit-flag
2285 "article-x-face" nil shell-file-name
2286 shell-command-switch gnus-article-x-face-command)
2290 (process-send-region "article-x-face"
2291 (point-min) (point-max)))
2292 (process-send-eof "article-x-face")))
2293 ((functionp gnus-article-x-face-command)
2294 ;; The command is a lisp function, so we call it.
2295 (funcall gnus-article-x-face-command face))
2297 (error "%s is not a function"
2298 gnus-article-x-face-command))))))))))
2300 (defun article-decode-mime-words ()
2301 "Decode all MIME-encoded words in the article."
2303 (gnus-with-article-buffer
2304 (let ((inhibit-point-motion-hooks t)
2305 (mail-parse-charset gnus-newsgroup-charset)
2306 (mail-parse-ignored-charsets
2307 (with-current-buffer gnus-summary-buffer
2308 gnus-newsgroup-ignored-charsets)))
2309 (mail-decode-encoded-word-region (point-min) (point-max)))))
2311 (defun article-decode-charset (&optional prompt)
2312 "Decode charset-encoded text in the article.
2313 If PROMPT (the prefix), prompt for a coding system to use."
2315 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2316 (inhibit-read-only t)
2317 (mail-parse-charset gnus-newsgroup-charset)
2318 (mail-parse-ignored-charsets
2319 (save-excursion (condition-case nil
2320 (set-buffer gnus-summary-buffer)
2322 gnus-newsgroup-ignored-charsets))
2323 ct cte ctl charset format)
2326 (article-narrow-to-head)
2327 (setq ct (message-fetch-field "Content-Type" t)
2328 cte (message-fetch-field "Content-Transfer-Encoding" t)
2329 ctl (and ct (mail-header-parse-content-type ct))
2332 (mm-read-coding-system "Charset to decode: "))
2334 (mail-content-type-get ctl 'charset)))
2335 format (and ctl (mail-content-type-get ctl 'format)))
2337 (setq cte (mail-header-strip cte)))
2338 (if (and ctl (not (string-match "/" (car ctl))))
2340 (goto-char (point-max)))
2343 (narrow-to-region (point) (point-max))
2344 (when (and (eq mail-parse-charset 'gnus-decoded)
2345 (eq (mm-body-7-or-8) '8bit))
2346 ;; The text code could have been decoded.
2347 (setq charset mail-parse-charset))
2348 (when (and (or (not ctl)
2349 (equal (car ctl) "text/plain"))
2350 (not format)) ;; article with format will decode later.
2352 charset (and cte (intern (downcase
2353 (gnus-strip-whitespace cte))))
2356 (defun article-decode-encoded-words ()
2357 "Remove encoded-word encoding from headers."
2358 (let ((inhibit-point-motion-hooks t)
2359 (mail-parse-charset gnus-newsgroup-charset)
2360 (mail-parse-ignored-charsets
2361 (save-excursion (condition-case nil
2362 (set-buffer gnus-summary-buffer)
2364 gnus-newsgroup-ignored-charsets))
2365 (inhibit-read-only t))
2367 (article-narrow-to-head)
2368 (funcall gnus-decode-header-function (point-min) (point-max)))))
2370 (defun article-decode-group-name ()
2371 "Decode group names in `Newsgroups:'."
2372 (let ((inhibit-point-motion-hooks t)
2373 (inhibit-read-only t)
2374 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2375 (when (and (or gnus-group-name-charset-method-alist
2376 gnus-group-name-charset-group-alist)
2377 (gnus-buffer-live-p gnus-original-article-buffer))
2379 (article-narrow-to-head)
2380 (with-current-buffer gnus-original-article-buffer
2381 (goto-char (point-min)))
2382 (while (re-search-forward
2383 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2384 (replace-match (save-match-data
2385 (gnus-decode-newsgroups
2386 ;; XXX how to use data in article buffer?
2387 (with-current-buffer gnus-original-article-buffer
2389 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2392 gnus-newsgroup-name method))
2394 (goto-char (point-min))
2395 (with-current-buffer gnus-original-article-buffer
2396 (goto-char (point-min)))
2397 (while (re-search-forward
2398 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2399 (replace-match (save-match-data
2400 (gnus-decode-newsgroups
2401 ;; XXX how to use data in article buffer?
2402 (with-current-buffer gnus-original-article-buffer
2404 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2407 gnus-newsgroup-name method))
2410 (autoload 'idna-to-unicode "idna")
2412 (defun article-decode-idna-rhs ()
2413 "Decode IDNA strings in RHS in various headers in current buffer.
2414 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2415 Mail-Reply-To: and Mail-Followup-To:."
2418 (let ((inhibit-point-motion-hooks t)
2419 (inhibit-read-only t))
2420 (article-narrow-to-head)
2421 (goto-char (point-min))
2422 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2424 (when (save-match-data
2425 (and (setq ace (match-string 1))
2427 (and (re-search-backward "^[^ \t]" nil t)
2428 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2429 (setq unicode (idna-to-unicode ace))))
2430 (unless (string= ace unicode)
2431 (replace-match unicode nil nil nil 1)))))))))
2433 (defun article-de-quoted-unreadable (&optional force read-charset)
2434 "Translate a quoted-printable-encoded article.
2435 If FORCE, decode the article whether it is marked as quoted-printable
2437 If READ-CHARSET, ask for a coding system."
2438 (interactive (list 'force current-prefix-arg))
2440 (let ((inhibit-read-only t) type charset)
2441 (if (gnus-buffer-live-p gnus-original-article-buffer)
2442 (with-current-buffer gnus-original-article-buffer
2444 (gnus-fetch-field "content-transfer-encoding"))
2445 (let* ((ct (gnus-fetch-field "content-type"))
2446 (ctl (and ct (mail-header-parse-content-type ct))))
2447 (setq charset (and ctl
2448 (mail-content-type-get ctl 'charset)))
2449 (if (stringp charset)
2450 (setq charset (intern (downcase charset)))))))
2452 (setq charset (mm-read-coding-system "Charset: " charset)))
2454 (setq charset gnus-newsgroup-charset))
2456 (and type (let ((case-fold-search t))
2457 (string-match "quoted-printable" type))))
2459 (quoted-printable-decode-region
2460 (point) (point-max) (mm-charset-to-coding-system charset))))))
2462 (defun article-de-base64-unreadable (&optional force read-charset)
2463 "Translate a base64 article.
2464 If FORCE, decode the article whether it is marked as base64 not.
2465 If READ-CHARSET, ask for a coding system."
2466 (interactive (list 'force current-prefix-arg))
2468 (let ((inhibit-read-only t) type charset)
2469 (if (gnus-buffer-live-p gnus-original-article-buffer)
2470 (with-current-buffer gnus-original-article-buffer
2472 (gnus-fetch-field "content-transfer-encoding"))
2473 (let* ((ct (gnus-fetch-field "content-type"))
2474 (ctl (and ct (mail-header-parse-content-type ct))))
2475 (setq charset (and ctl
2476 (mail-content-type-get ctl 'charset)))
2477 (if (stringp charset)
2478 (setq charset (intern (downcase charset)))))))
2480 (setq charset (mm-read-coding-system "Charset: " charset)))
2482 (setq charset gnus-newsgroup-charset))
2484 (and type (let ((case-fold-search t))
2485 (string-match "base64" type))))
2488 (narrow-to-region (point) (point-max))
2489 (base64-decode-region (point-min) (point-max))
2490 (mm-decode-coding-region
2491 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2496 (defun article-decode-HZ ()
2497 "Translate a HZ-encoded article."
2501 (let ((inhibit-read-only t))
2502 (rfc1843-decode-region (point-min) (point-max)))))
2504 (defun article-unsplit-urls ()
2505 "Remove the newlines that some other mailers insert into URLs."
2508 (let ((inhibit-read-only t))
2509 (goto-char (point-min))
2510 (while (re-search-forward
2511 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2512 (replace-match "\\1\\3" t)))
2513 (when (interactive-p)
2514 (gnus-treat-article nil))))
2517 (defun article-wash-html (&optional read-charset)
2518 "Format an HTML article.
2519 If READ-CHARSET, ask for a coding system. If it is a number, the
2520 charset defined in `gnus-summary-show-article-charset-alist' is used."
2523 (let ((inhibit-read-only t)
2526 (if (or (and (numberp read-charset)
2530 gnus-summary-show-article-charset-alist))))
2531 (setq charset (mm-read-coding-system "Charset: ")))
2532 (let ((gnus-summary-show-article-charset-alist
2533 (list (cons 1 charset))))
2534 (with-current-buffer gnus-summary-buffer
2535 (gnus-summary-show-article 1)))
2536 (error "No charset is given"))
2537 (when (gnus-buffer-live-p gnus-original-article-buffer)
2538 (with-current-buffer gnus-original-article-buffer
2539 (let* ((ct (gnus-fetch-field "content-type"))
2540 (ctl (and ct (mail-header-parse-content-type ct))))
2541 (setq charset (and ctl
2542 (mail-content-type-get ctl 'charset)))
2543 (when (stringp charset)
2544 (setq charset (intern (downcase charset)))))))
2546 (setq charset gnus-newsgroup-charset)))
2548 (save-window-excursion
2550 (narrow-to-region (point) (point-max))
2551 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2552 (entry (assq func mm-text-html-washer-alist)))
2554 (setq func (cdr entry)))
2559 (apply (car func) (cdr func))))))))))
2561 (defun gnus-article-wash-html-with-w3 ()
2562 "Wash the current buffer with w3."
2564 (let ((w3-strict-width (window-width))
2565 (url-standalone-mode t)
2566 (url-gateway-unplugged t)
2567 (w3-honor-stylesheets nil))
2569 (w3-region (point-min) (point-max))
2572 (defun gnus-article-wash-html-with-w3m ()
2573 "Wash the current buffer with emacs-w3m."
2575 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2576 w3m-force-redisplay)
2577 (w3m-region (point-min) (point-max)))
2578 (when (and mm-inline-text-html-with-w3m-keymap
2579 (boundp 'w3m-minor-mode-map)
2581 (add-text-properties
2582 (point-min) (point-max)
2583 (list 'keymap w3m-minor-mode-map
2584 ;; Put the mark meaning this part was rendered by emacs-w3m.
2585 'mm-inline-text-html-with-w3m t))))
2587 (eval-when-compile (defvar charset)) ;; Bound by `article-wash-html'.
2589 (defun gnus-article-wash-html-with-w3m-standalone ()
2590 "Wash the current buffer with w3m."
2591 (if (mm-w3m-standalone-supports-m17n-p)
2593 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2595 (setq charset 'iso-8859-1))
2596 (let ((coding-system-for-write charset)
2597 (coding-system-for-read charset))
2598 (call-process-region
2599 (point-min) (point-max)
2600 "w3m" t t nil "-dump" "-T" "text/html"
2601 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2602 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2604 (defun gnus-article-browse-html-parts (list)
2605 "View all \"text/html\" parts from LIST.
2606 Recurse into multiparts."
2607 ;; Internal function used by `gnus-article-browse-html-article'.
2609 ;; Find and show the html-parts.
2610 (dolist (handle list)
2611 ;; If HTML, show it:
2612 (when (listp handle)
2613 (cond ((and (bufferp (car handle))
2614 (string-match "text/html" (car (mm-handle-type handle))))
2615 (let ((tmp-file (mm-make-temp-file
2616 ;; Do we need to care for 8.3 filenames?
2617 "mm-" nil ".html")))
2618 (mm-save-part-to-file handle tmp-file)
2619 (browse-url tmp-file)
2621 ;; If multipart, recurse
2622 ((and (stringp (car handle))
2623 (string-match "^multipart/" (car handle))
2626 (gnus-article-browse-html-parts handle))))))))
2629 ;; TODO: Key binding; Remove temp files.
2630 (defun gnus-article-browse-html-article ()
2631 "View \"text/html\" parts of the current article with a WWW browser."
2633 (save-window-excursion
2634 ;; Open raw article and select the buffer
2635 (gnus-summary-show-article t)
2636 (gnus-summary-select-article-buffer)
2637 (let ((parts (mm-dissect-buffer t t)))
2638 ;; If singlepart, enforce a list.
2639 (when (and (bufferp (car parts))
2640 (stringp (car (mm-handle-type parts))))
2641 (setq parts (list parts)))
2643 (unless (gnus-article-browse-html-parts parts)
2644 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
2645 (gnus-summary-show-article))))
2647 (defun article-hide-list-identifiers ()
2648 "Remove list identifies from the Subject header.
2649 The `gnus-list-identifiers' variable specifies what to do."
2651 (let ((inhibit-point-motion-hooks t)
2652 (regexp (if (consp gnus-list-identifiers)
2653 (mapconcat 'identity gnus-list-identifiers " *\\|")
2654 gnus-list-identifiers))
2655 (inhibit-read-only t))
2659 (article-narrow-to-head)
2660 (goto-char (point-min))
2661 (while (re-search-forward
2662 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2664 (delete-region (match-beginning 2) (match-end 0))
2665 (beginning-of-line))
2666 (when (re-search-forward
2667 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2668 (delete-region (match-beginning 1) (match-end 1))))))))
2670 (defun article-hide-pem (&optional arg)
2671 "Toggle hiding of any PEM headers and signatures in the current article.
2672 If given a negative prefix, always show; if given a positive prefix,
2674 (interactive (gnus-article-hidden-arg))
2675 (unless (gnus-article-check-hidden-text 'pem arg)
2677 (let ((inhibit-read-only t) end)
2678 (goto-char (point-min))
2679 ;; Hide the horrendously ugly "header".
2680 (when (and (search-forward
2681 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2683 (setq end (1+ (match-beginning 0))))
2684 (gnus-add-wash-type 'pem)
2685 (gnus-article-hide-text-type
2687 (if (search-forward "\n\n" nil t)
2691 ;; Hide the trailer as well
2692 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2694 (gnus-article-hide-text-type
2695 (match-beginning 0) (match-end 0) 'pem)))))))
2697 (defun article-strip-banner ()
2698 "Strip the banners specified by the `banner' group parameter and by
2699 `gnus-article-address-banner-alist'."
2703 (let ((inhibit-point-motion-hooks t))
2704 (when (gnus-parameter-banner gnus-newsgroup-name)
2705 (article-really-strip-banner
2706 (gnus-parameter-banner gnus-newsgroup-name)))
2707 (when gnus-article-address-banner-alist
2708 ;; Note that the From header is decoded here, so it is
2709 ;; required that the *-extract-address-components function
2710 ;; supports non-ASCII text.
2711 (let ((from (save-restriction
2713 (article-narrow-to-head)
2714 (mail-fetch-field "from"))))
2717 (cadr (funcall gnus-extract-address-components
2720 (dolist (pair gnus-article-address-banner-alist)
2721 (when (string-match (car pair) from)
2723 (article-really-strip-banner (cdr pair)))))))))))))
2725 (defun article-really-strip-banner (banner)
2726 "Strip the banner specified by the argument."
2729 (let ((inhibit-point-motion-hooks t)
2730 (gnus-signature-limit nil)
2731 (inhibit-read-only t))
2734 ((eq banner 'signature)
2735 (when (gnus-article-narrow-to-signature)
2738 (delete-region (point) (point-max))))
2740 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2741 (while (re-search-forward banner nil t)
2742 (delete-region (match-beginning 0) (match-end 0)))))
2744 (while (re-search-forward banner nil t)
2745 (delete-region (match-beginning 0) (match-end 0)))))))))
2747 (defun article-babel ()
2748 "Translate article using an online translation service."
2751 (gnus-with-article-buffer
2752 (when (article-goto-body)
2753 (let* ((start (point))
2755 (orig (buffer-substring start end))
2756 (trans (babel-as-string orig)))
2758 (narrow-to-region start end)
2759 (delete-region start end)
2762 (defun article-hide-signature (&optional arg)
2763 "Hide the signature in the current article.
2764 If given a negative prefix, always show; if given a positive prefix,
2766 (interactive (gnus-article-hidden-arg))
2767 (unless (gnus-article-check-hidden-text 'signature arg)
2770 (let ((inhibit-read-only t))
2771 (when (gnus-article-narrow-to-signature)
2772 (gnus-article-hide-text-type
2773 (point-min) (point-max) 'signature))))))
2774 (gnus-set-mode-line 'article))
2776 (defun article-strip-headers-in-body ()
2777 "Strip offensive headers from bodies."
2781 (let ((case-fold-search t))
2782 (when (looking-at "x-no-archive:")
2783 (gnus-delete-line)))))
2785 (defun article-strip-leading-blank-lines ()
2786 "Remove all blank lines from the beginning of the article."
2789 (let ((inhibit-point-motion-hooks t)
2790 (inhibit-read-only t))
2791 (when (article-goto-body)
2792 (while (and (not (eobp))
2793 (looking-at "[ \t]*$"))
2794 (gnus-delete-line))))))
2796 (defun article-narrow-to-head ()
2797 "Narrow the buffer to the head of the message.
2798 Point is left at the beginning of the narrowed-to region."
2800 (goto-char (point-min))
2801 (if (search-forward "\n\n" nil 1)
2804 (goto-char (point-min)))
2806 (defun article-goto-body ()
2807 "Place point at the start of the body."
2808 (goto-char (point-min))
2810 ;; This variable is only bound when dealing with separate
2812 (article-goto-body-goes-to-point-min-p
2814 ((search-forward "\n\n" nil t)
2817 (goto-char (point-max))
2820 (defun article-strip-multiple-blank-lines ()
2821 "Replace consecutive blank lines with one empty line."
2824 (let ((inhibit-point-motion-hooks t)
2825 (inhibit-read-only t))
2826 ;; First make all blank lines empty.
2828 (while (re-search-forward "^[ \t]+$" nil t)
2829 (unless (gnus-annotation-in-region-p
2830 (match-beginning 0) (match-end 0))
2831 (replace-match "" nil t)))
2832 ;; Then replace multiple empty lines with a single empty line.
2834 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2835 (unless (gnus-annotation-in-region-p
2836 (match-beginning 0) (match-end 0))
2837 (delete-region (match-beginning 1) (match-end 1)))))))
2839 (defun article-strip-leading-space ()
2840 "Remove all white space from the beginning of the lines in the article."
2843 (let ((inhibit-point-motion-hooks t)
2844 (inhibit-read-only t))
2846 (while (re-search-forward "^[ \t]+" nil t)
2847 (replace-match "" t t)))))
2849 (defun article-strip-trailing-space ()
2850 "Remove all white space from the end of the lines in the article."
2853 (let ((inhibit-point-motion-hooks t)
2854 (inhibit-read-only t))
2856 (while (re-search-forward "[ \t]+$" nil t)
2857 (replace-match "" t t)))))
2859 (defun article-strip-blank-lines ()
2860 "Strip leading, trailing and multiple blank lines."
2862 (article-strip-leading-blank-lines)
2863 (article-remove-trailing-blank-lines)
2864 (article-strip-multiple-blank-lines))
2866 (defun article-strip-all-blank-lines ()
2867 "Strip all blank lines."
2870 (let ((inhibit-point-motion-hooks t)
2871 (inhibit-read-only t))
2873 (while (re-search-forward "^[ \t]*\n" nil t)
2874 (replace-match "" t t)))))
2876 (defun gnus-article-narrow-to-signature ()
2877 "Narrow to the signature; return t if a signature is found, else nil."
2878 (let ((inhibit-point-motion-hooks t))
2879 (when (gnus-article-search-signature)
2881 ;; Check whether we have some limits to what we consider
2882 ;; to be a signature.
2883 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2884 (list gnus-signature-limit)))
2886 (while (setq limit (pop limits))
2887 (if (or (and (integerp limit)
2888 (< (- (point-max) (point)) limit))
2890 (< (count-lines (point) (point-max)) limit))
2891 (and (functionp limit)
2893 (and (stringp limit)
2894 (not (re-search-forward limit nil t))))
2895 () ; This limit did not succeed.
2899 (narrow-to-region (point) (point-max))
2902 (defun gnus-article-search-signature ()
2903 "Search the current buffer for the signature separator.
2904 Put point at the beginning of the signature separator."
2905 (let ((cur (point)))
2906 (goto-char (point-max))
2907 (if (if (stringp gnus-signature-separator)
2908 (re-search-backward gnus-signature-separator nil t)
2909 (let ((seps gnus-signature-separator))
2911 (not (re-search-backward (car seps) nil t)))
2918 (defun gnus-article-hidden-arg ()
2919 "Return the current prefix arg as a number, or 0 if no prefix."
2920 (list (if current-prefix-arg
2921 (prefix-numeric-value current-prefix-arg)
2924 (defun gnus-article-check-hidden-text (type arg)
2925 "Return nil if hiding is necessary.
2926 Arg can be nil or a number. nil and positive means hide, negative
2927 means show, 0 means toggle."
2930 (let ((hide (gnus-article-hidden-text-p type)))
2936 (gnus-article-show-hidden-text type)
2939 (if (eq hide 'hidden)
2941 (gnus-article-show-hidden-text type)
2945 (defun gnus-article-hidden-text-p (type)
2946 "Say whether the current buffer contains hidden text of type TYPE."
2947 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2949 (not (get-text-property pos 'invisible))
2950 (not (get-text-property pos 'dummy-invisible)))
2952 (text-property-any (1+ pos) (point-max) 'article-type type)))
2957 (defun gnus-article-show-hidden-text (type &optional dummy)
2958 "Show all hidden text of type TYPE.
2959 Originally it is hide instead of DUMMY."
2960 (let ((inhibit-read-only t)
2961 (inhibit-point-motion-hooks t))
2962 (gnus-remove-text-properties-when
2964 (point-min) (point-max)
2965 (cons 'article-type (cons type
2966 gnus-hidden-properties)))
2967 (gnus-delete-wash-type type)))
2969 (defconst article-time-units
2970 `((year . ,(* 365.25 24 60 60))
2971 (week . ,(* 7 24 60 60))
2972 (day . ,(* 24 60 60))
2976 "Mapping from time units to seconds.")
2978 (defun gnus-article-forward-header ()
2979 "Move point to the start of the next header.
2980 If the current header is a continuation header, this can be several
2985 (if (looking-at "[ \t]+[^ \t]")
2989 (defun article-date-ut (&optional type highlight)
2990 "Convert DATE date to universal time in the current article.
2991 If TYPE is `local', convert to local time; if it is `lapsed', output
2992 how much time has lapsed since DATE. For `lapsed', the value of
2993 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2994 should replace the \"Date:\" one, or should be added below it."
2995 (interactive (list 'ut t))
2996 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2997 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3001 (article-lapsed-timer
3005 (case-fold-search t)
3006 (inhibit-read-only t)
3007 (inhibit-point-motion-hooks t)
3008 pos date bface eface)
3012 (goto-char (point-min))
3013 (while (or (setq date (get-text-property (setq pos (point))
3015 (when (setq pos (next-single-property-change
3016 (point) 'original-date))
3017 (setq date (get-text-property pos 'original-date))
3019 (narrow-to-region pos (or (text-property-any pos (point-max)
3022 (goto-char (point-min))
3023 (when (re-search-forward tdate-regexp nil t)
3024 (setq bface (get-text-property (point-at-bol) 'face)
3025 eface (get-text-property (1- (point-at-eol)) 'face)))
3026 (goto-char (point-min))
3028 ;; Delete any old Date headers.
3029 (while (re-search-forward date-regexp nil t)
3031 (delete-region (point-at-bol) (progn
3032 (gnus-article-forward-header)
3034 (delete-region (point-at-bol) (progn
3035 (gnus-article-forward-header)
3038 (setq pos (point))))
3039 (when (and (not pos)
3040 (re-search-forward tdate-regexp nil t))
3042 (gnus-goto-char pos)
3043 (insert (article-make-date-line date (or type 'ut)))
3049 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3050 (put-text-property (match-beginning 1) (1+ (match-end 1))
3052 (put-text-property (match-beginning 2) (match-end 2)
3054 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3055 (goto-char (point-max))
3058 (defun article-make-date-line (date type)
3059 "Return a DATE line of TYPE."
3060 (unless (memq type '(local ut original user iso8601 lapsed english))
3061 (error "Unknown conversion type: %s" type))
3063 (let ((time (date-to-time date)))
3065 ;; Convert to the local timezone.
3067 (concat "Date: " (message-make-date time)))
3068 ;; Convert to Universal Time.
3073 (let* ((e (parse-time-string date))
3074 (tm (apply 'encode-time e))
3076 (ls (- (cadr tm) (car (current-time-zone time)))))
3077 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3078 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3082 ;; Get the original date from the article.
3083 ((eq type 'original)
3084 (concat "Date: " (if (string-match "\n+$" date)
3085 (substring date 0 (match-beginning 0))
3087 ;; Let the user define the format.
3089 (let ((format (or (condition-case nil
3090 (with-current-buffer gnus-summary-buffer
3091 gnus-article-time-format)
3093 gnus-article-time-format)))
3094 (if (functionp format)
3095 (funcall format time)
3096 (concat "Date: " (format-time-string format time)))))
3099 (let ((tz (car (current-time-zone time))))
3102 (format-time-string "%Y%m%dT%H%M%S" time)
3103 (format "%s%02d%02d"
3104 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3105 (/ (% (abs tz) 3600) 60)))))
3106 ;; Do an X-Sent lapsed format.
3108 ;; If the date is seriously mangled, the timezone functions are
3109 ;; liable to bug out, so we ignore all errors.
3110 (let* ((now (current-time))
3111 (real-time (subtract-time now time))
3112 (real-sec (and real-time
3113 (+ (* (float (car real-time)) 65536)
3115 (sec (and real-time (abs real-sec)))
3125 ;; This is a bit convoluted, but basically we go
3126 ;; through the time units for years, weeks, etc,
3127 ;; and divide things to see whether that results
3128 ;; in positive answers.
3131 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3132 ;; The (remaining) seconds are too few to
3133 ;; be divided into this time unit.
3135 ;; It's big enough, so we output it.
3136 (setq sec (- sec (* num (cdr unit))))
3138 (concat (if prev ", " "") (int-to-string
3140 " " (symbol-name (car unit))
3141 (if (> num 1) "s" ""))
3143 article-time-units "")
3144 ;; If dates are odd, then it might appear like the
3145 ;; article was sent in the future.
3148 " in the future"))))))
3149 ;; Display the date in proper English
3151 (let ((dtime (decode-time time)))
3154 (number-to-string (nth 3 dtime))
3155 (let ((digit (% (nth 3 dtime) 10)))
3157 ((memq (nth 3 dtime) '(11 12 13)) "th")
3163 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3165 (number-to-string (nth 5 dtime))
3167 (format "%02d" (nth 2 dtime))
3169 (format "%02d" (nth 1 dtime)))))))
3171 (format "Date: %s (from Gnus)" date))))
3173 (defun article-date-local (&optional highlight)
3174 "Convert the current article date to the local timezone."
3175 (interactive (list t))
3176 (article-date-ut 'local highlight))
3178 (defun article-date-english (&optional highlight)
3179 "Convert the current article date to something that is proper English."
3180 (interactive (list t))
3181 (article-date-ut 'english highlight))
3183 (defun article-date-original (&optional highlight)
3184 "Convert the current article date to what it was originally.
3185 This is only useful if you have used some other date conversion
3186 function and want to see what the date was before converting."
3187 (interactive (list t))
3188 (article-date-ut 'original highlight))
3190 (defun article-date-lapsed (&optional highlight)
3191 "Convert the current article date to time lapsed since it was sent."
3192 (interactive (list t))
3193 (article-date-ut 'lapsed highlight))
3195 (defun article-update-date-lapsed ()
3196 "Function to be run from a timer to update the lapsed time line."
3198 (let (deactivate-mark)
3203 (set-buffer (window-buffer w))
3204 (when (eq major-mode 'gnus-article-mode)
3205 (let ((mark (point-marker)))
3206 (goto-char (point-min))
3207 (when (re-search-forward "^X-Sent:" nil t)
3208 (article-date-lapsed t))
3209 (goto-char (marker-position mark))
3210 (move-marker mark nil))))
3213 (defun gnus-start-date-timer (&optional n)
3214 "Start a timer to update the X-Sent header in the article buffers.
3215 The numerical prefix says how frequently (in seconds) the function
3220 (gnus-stop-date-timer)
3221 (setq article-lapsed-timer
3222 (run-at-time 1 n 'article-update-date-lapsed)))
3224 (defun gnus-stop-date-timer ()
3225 "Stop the X-Sent timer."
3227 (when article-lapsed-timer
3228 (nnheader-cancel-timer article-lapsed-timer)
3229 (setq article-lapsed-timer nil)))
3231 (defun article-date-user (&optional highlight)
3232 "Convert the current article date to the user-defined format.
3233 This format is defined by the `gnus-article-time-format' variable."
3234 (interactive (list t))
3235 (article-date-ut 'user highlight))
3237 (defun article-date-iso8601 (&optional highlight)
3238 "Convert the current article date to ISO8601."
3239 (interactive (list t))
3240 (article-date-ut 'iso8601 highlight))
3242 (defmacro gnus-article-save-original-date (&rest forms)
3243 "Save the original date as a text property and evaluate FORMS."
3244 `(let* ((case-fold-search t)
3246 (goto-char (point-min))
3247 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3250 (date (when (and start
3251 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3253 (buffer-substring-no-properties start
3254 (match-beginning 0)))))
3255 (goto-char (point-max))
3256 (skip-chars-backward "\n")
3257 (put-text-property (point-min) (point) 'original-date date)
3259 (goto-char (point-max))
3260 (skip-chars-backward "\n")
3261 (put-text-property (point-min) (point) 'original-date date)))
3263 ;; (defun article-show-all ()
3264 ;; "Show all hidden text in the article buffer."
3267 ;; (let ((inhibit-read-only t))
3268 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3270 (defun article-remove-leading-whitespace ()
3271 "Remove excessive whitespace from all headers."
3275 (let ((inhibit-read-only t))
3276 (article-narrow-to-head)
3277 (goto-char (point-min))
3278 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3279 (delete-region (match-beginning 1) (match-end 1)))))))
3281 (defun article-emphasize (&optional arg)
3282 "Emphasize text according to `gnus-emphasis-alist'."
3283 (interactive (gnus-article-hidden-arg))
3284 (unless (gnus-article-check-hidden-text 'emphasis arg)
3288 (with-current-buffer gnus-summary-buffer
3289 gnus-article-emphasis-alist)
3291 gnus-emphasis-alist))
3292 (inhibit-read-only t)
3293 (props (append '(article-type emphasis)
3294 gnus-hidden-properties))
3295 regexp elem beg invisible visible face)
3298 (while (setq elem (pop alist))
3300 (setq regexp (car elem)
3301 invisible (nth 1 elem)
3302 visible (nth 2 elem)
3304 (while (re-search-forward regexp nil t)
3305 (when (and (match-beginning visible) (match-beginning invisible))
3306 (gnus-article-hide-text
3307 (match-beginning invisible) (match-end invisible) props)
3308 (gnus-article-unhide-text-type
3309 (match-beginning visible) (match-end visible) 'emphasis)
3310 (gnus-put-overlay-excluding-newlines
3311 (match-beginning visible) (match-end visible) 'face face)
3312 (gnus-add-wash-type 'emphasis)
3313 (goto-char (match-end invisible)))))))))
3315 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3316 "Setup newsgroup emphasis alist."
3317 (unless gnus-article-emphasis-alist
3318 (let ((name (and gnus-newsgroup-name
3319 (gnus-group-real-name gnus-newsgroup-name))))
3320 (make-local-variable 'gnus-article-emphasis-alist)
3321 (setq gnus-article-emphasis-alist
3323 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3324 (while (setq elem (pop alist))
3325 (when (and name (string-match (car elem) name))
3327 highlight (copy-sequence (cdr elem)))))
3329 (copy-sequence highlight-words)
3330 (if gnus-newsgroup-name
3331 (copy-sequence (gnus-group-find-parameter
3332 gnus-newsgroup-name 'highlight-words t)))
3333 gnus-emphasis-alist)))))
3336 (defvar gnus-summary-article-menu)
3337 (defvar gnus-summary-post-menu))
3339 ;;; Saving functions.
3341 (defun gnus-article-save (save-buffer file &optional num)
3342 "Save the currently selected article."
3343 (unless gnus-save-all-headers
3344 ;; Remove headers according to `gnus-saved-headers'.
3345 (let ((gnus-visible-headers
3346 (or gnus-saved-headers gnus-visible-headers))
3347 (gnus-article-buffer save-buffer))
3349 (set-buffer save-buffer)
3350 (article-hide-headers 1 t))))
3351 (save-window-excursion
3352 (if (not gnus-default-article-saver)
3353 (error "No default saver is defined")
3354 ;; !!! Magic! The saving functions all save
3355 ;; `gnus-save-article-buffer' (or so they think), but we
3356 ;; bind that variable to our save-buffer.
3357 (set-buffer gnus-article-buffer)
3358 (let* ((gnus-save-article-buffer save-buffer)
3361 ((not gnus-prompt-before-saving) 'default)
3362 ((eq gnus-prompt-before-saving 'always) nil)
3364 (gnus-number-of-articles-to-be-saved
3365 (when (eq gnus-prompt-before-saving t)
3367 (set-buffer gnus-article-current-summary)
3368 (funcall gnus-default-article-saver filename)))))
3370 (defun gnus-read-save-file-name (prompt &optional filename
3371 function group headers variable)
3373 (funcall function group headers (symbol-value variable)))
3378 ((eq filename 'default)
3384 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3387 (if (and gnus-number-of-articles-to-be-saved
3388 (> gnus-number-of-articles-to-be-saved 1))
3389 (format "these %d articles"
3390 gnus-number-of-articles-to-be-saved)
3393 ;; Let the split methods have their say.
3395 ;; No split name was found.
3398 (concat prompt " (default "
3399 (file-name-nondirectory default-name) "): ")
3400 (file-name-directory default-name)
3402 ;; A single group name is returned.
3403 ((stringp split-name)
3405 (funcall function split-name headers
3406 (symbol-value variable)))
3408 (concat prompt " (default "
3409 (file-name-nondirectory default-name) "): ")
3410 (file-name-directory default-name)
3412 ;; A single split name was found
3413 ((= 1 (length split-name))
3414 (let* ((name (expand-file-name
3416 gnus-article-save-directory))
3417 (dir (cond ((file-directory-p name)
3418 (file-name-as-directory name))
3419 ((file-exists-p name) name)
3420 (t gnus-article-save-directory))))
3422 (concat prompt " (default " name "): ")
3424 ;; A list of splits was found.
3426 (setq split-name (nreverse split-name))
3428 (let ((file-name-history
3429 (nconc split-name file-name-history)))
3433 (concat prompt " (`M-p' for defaults): ")
3434 gnus-article-save-directory
3436 gnus-article-save-directory)))
3437 (car (push result file-name-history)))))))
3438 ;; Create the directory.
3439 (gnus-make-directory (file-name-directory file))
3440 ;; If we have read a directory, we append the default file name.
3441 (when (file-directory-p file)
3442 (setq file (expand-file-name (file-name-nondirectory
3444 (file-name-as-directory file))))
3445 ;; Possibly translate some characters.
3446 (nnheader-translate-file-chars file))))))
3447 (gnus-make-directory (file-name-directory result))
3448 (set variable result)))
3450 (defun gnus-article-archive-name (group)
3451 "Return the first instance of an \"Archive-name\" in the current buffer."
3452 (let ((case-fold-search t))
3453 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3454 (nnheader-concat gnus-article-save-directory
3455 (match-string 1)))))
3457 (defun gnus-article-nndoc-name (group)
3458 "If GROUP is an nndoc group, return the name of the parent group."
3459 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3460 (gnus-group-get-parameter group 'save-article-group)))
3462 (defun gnus-summary-save-in-rmail (&optional filename)
3463 "Append this article to Rmail file.
3464 Optional argument FILENAME specifies file name.
3465 Directory to save to is default to `gnus-article-save-directory'."
3466 (setq filename (gnus-read-save-file-name
3467 "Save %s in rmail file" filename
3468 gnus-rmail-save-name gnus-newsgroup-name
3469 gnus-current-headers 'gnus-newsgroup-last-rmail))
3470 (gnus-eval-in-buffer-window gnus-save-article-buffer
3474 (gnus-output-to-rmail filename))))
3477 (defun gnus-summary-save-in-mail (&optional filename)
3478 "Append this article to Unix mail file.
3479 Optional argument FILENAME specifies file name.
3480 Directory to save to is default to `gnus-article-save-directory'."
3481 (setq filename (gnus-read-save-file-name
3482 "Save %s in Unix mail file" filename
3483 gnus-mail-save-name gnus-newsgroup-name
3484 gnus-current-headers 'gnus-newsgroup-last-mail))
3485 (gnus-eval-in-buffer-window gnus-save-article-buffer
3489 (if (and (file-readable-p filename)
3490 (file-regular-p filename)
3491 (mail-file-babyl-p filename))
3492 (rmail-output-to-rmail-file filename t)
3493 (gnus-output-to-mail filename)))))
3496 (defun gnus-summary-save-in-file (&optional filename overwrite)
3497 "Append this article to file.
3498 Optional argument FILENAME specifies file name.
3499 Directory to save to is default to `gnus-article-save-directory'."
3500 (setq filename (gnus-read-save-file-name
3501 "Save %s in file" filename
3502 gnus-file-save-name gnus-newsgroup-name
3503 gnus-current-headers 'gnus-newsgroup-last-file))
3504 (gnus-eval-in-buffer-window gnus-save-article-buffer
3508 (when (and overwrite
3509 (file-exists-p filename))
3510 (delete-file filename))
3511 (gnus-output-to-file filename))))
3514 (defun gnus-summary-write-to-file (&optional filename)
3515 "Write this article to a file, overwriting it if the file exists.
3516 Optional argument FILENAME specifies file name.
3517 The directory to save in defaults to `gnus-article-save-directory'."
3518 (gnus-summary-save-in-file nil t))
3520 (defun gnus-summary-save-body-in-file (&optional filename)
3521 "Append this article body to a file.
3522 Optional argument FILENAME specifies file name.
3523 The directory to save in defaults to `gnus-article-save-directory'."
3524 (setq filename (gnus-read-save-file-name
3525 "Save %s body in file" filename
3526 gnus-file-save-name gnus-newsgroup-name
3527 gnus-current-headers 'gnus-newsgroup-last-file))
3528 (gnus-eval-in-buffer-window gnus-save-article-buffer
3532 (when (article-goto-body)
3533 (narrow-to-region (point) (point-max)))
3534 (gnus-output-to-file filename))))
3537 (defun gnus-summary-save-in-pipe (&optional command)
3538 "Pipe this article to subprocess."
3540 (cond ((and (eq command 'default)
3541 gnus-last-shell-command)
3542 gnus-last-shell-command)
3547 "Shell command on %s: "
3548 (if (and gnus-number-of-articles-to-be-saved
3549 (> gnus-number-of-articles-to-be-saved 1))
3550 (format "these %d articles"
3551 gnus-number-of-articles-to-be-saved)
3553 gnus-last-shell-command))))
3554 (when (string-equal command "")
3555 (if gnus-last-shell-command
3556 (setq command gnus-last-shell-command)
3557 (error "A command is required")))
3558 (gnus-eval-in-buffer-window gnus-article-buffer
3561 (shell-command-on-region (point-min) (point-max) command nil)))
3562 (setq gnus-last-shell-command command))
3564 (defun gnus-summary-pipe-to-muttprint (&optional command)
3565 "Pipe this article to muttprint."
3566 (setq command (read-string
3567 "Print using command: " gnus-summary-muttprint-program
3568 nil gnus-summary-muttprint-program))
3569 (gnus-summary-save-in-pipe command))
3571 ;;; Article file names when saving.
3573 (defun gnus-capitalize-newsgroup (newsgroup)
3574 "Capitalize NEWSGROUP name."
3575 (when (not (zerop (length newsgroup)))
3576 (concat (char-to-string (upcase (aref newsgroup 0)))
3577 (substring newsgroup 1))))
3579 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3580 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3581 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3582 Otherwise, it is like ~/News/news/group/num."
3585 (concat (if (gnus-use-long-file-name 'not-save)
3586 (gnus-capitalize-newsgroup newsgroup)
3587 (gnus-newsgroup-directory-form newsgroup))
3588 "/" (int-to-string (mail-header-number headers)))
3589 gnus-article-save-directory)))
3591 (string-equal (file-name-directory default)
3592 (file-name-directory last-file))
3593 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3595 (or last-file default))))
3597 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3598 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3599 If variable `gnus-use-long-file-name' is non-nil, it is
3600 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3603 (concat (if (gnus-use-long-file-name 'not-save)
3605 (gnus-newsgroup-directory-form newsgroup))
3606 "/" (int-to-string (mail-header-number headers)))
3607 gnus-article-save-directory)))
3609 (string-equal (file-name-directory default)
3610 (file-name-directory last-file))
3611 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3613 (or last-file default))))
3615 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3616 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3617 If variable `gnus-use-long-file-name' is non-nil, it is
3618 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3621 (if (gnus-use-long-file-name 'not-save)
3624 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3626 gnus-article-save-directory)))
3628 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3629 "Generate file name from sender."
3630 (let ((from (mail-header-from headers)))
3632 (if (and from (string-match "\\([^ <]+\\)@" from))
3633 (match-string 1 from)
3635 gnus-article-save-directory)))
3637 (defun article-verify-x-pgp-sig ()
3640 (if (gnus-buffer-live-p gnus-original-article-buffer)
3641 (let ((sig (with-current-buffer gnus-original-article-buffer
3642 (gnus-fetch-field "X-PGP-Sig")))
3646 (mml2015-clear-verify-function))
3648 (insert-buffer-substring gnus-original-article-buffer)
3649 (setq items (split-string sig))
3650 (message-narrow-to-head)
3651 (let ((inhibit-point-motion-hooks t)
3652 (case-fold-search t))
3653 ;; Don't verify multiple headers.
3654 (setq headers (mapconcat (lambda (header)
3656 (mail-fetch-field header)
3658 (split-string (nth 1 items) ",") "")))
3659 (delete-region (point-min) (point-max))
3660 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3661 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3666 (if (looking-at "^-")
3669 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3670 (insert "Version: " (car items) "\n\n")
3671 (insert (mapconcat 'identity (cddr items) "\n"))
3672 (insert "\n-----END PGP SIGNATURE-----\n")
3673 (let ((mm-security-handle (list (format "multipart/signed"))))
3674 (mml2015-clean-buffer)
3675 (let ((coding-system-for-write (or gnus-newsgroup-charset
3677 (funcall (mml2015-clear-verify-function)))
3679 (or (mm-handle-multipart-ctl-parameter
3680 mm-security-handle 'gnus-details)
3681 (mm-handle-multipart-ctl-parameter
3682 mm-security-handle 'gnus-info)))))
3684 (let ((inhibit-read-only t) bface eface)
3686 (message-narrow-to-head)
3687 (goto-char (point-max))
3689 (setq bface (get-text-property (point-at-bol) 'face)
3690 eface (get-text-property (1- (point-at-eol)) 'face))
3691 (message-remove-header "X-Gnus-PGP-Verify")
3692 (if (re-search-forward "^X-PGP-Sig:" nil t)
3694 (goto-char (point-max)))
3695 (narrow-to-region (point) (point))
3696 (insert "X-Gnus-PGP-Verify: " info "\n")
3697 (goto-char (point-min))
3700 (if (not (looking-at "^[ \t]"))
3704 (goto-char (point-min))
3705 (when (looking-at "\\([^:]+\\): *")
3706 (put-text-property (match-beginning 1) (1+ (match-end 1))
3708 (put-text-property (match-end 0) (point-max)
3709 'face eface)))))))))
3711 (defun article-verify-cancel-lock ()
3712 "Verify Cancel-Lock header."
3714 (if (gnus-buffer-live-p gnus-original-article-buffer)
3715 (canlock-verify gnus-original-article-buffer)))
3722 (setq afunc (car func)
3725 gfunc (intern (format "gnus-%s" func))))
3727 (when (fboundp afunc)
3728 `(lambda (&optional interactive &rest args)
3729 ,(documentation afunc t)
3730 (interactive (list t))
3732 (set-buffer gnus-article-buffer)
3734 (call-interactively ',afunc)
3735 (apply ',afunc args))))))))
3736 '(article-hide-headers
3737 article-verify-x-pgp-sig
3738 article-verify-cancel-lock
3739 article-hide-boring-headers
3740 article-treat-overstrike
3741 article-treat-ansi-sequences
3742 article-fill-long-lines
3743 article-capitalize-sentences
3745 article-remove-leading-whitespace
3746 article-display-x-face
3747 article-display-face
3748 article-de-quoted-unreadable
3749 article-de-base64-unreadable
3752 article-unsplit-urls
3753 article-hide-list-identifiers
3754 article-strip-banner
3757 article-hide-signature
3758 article-strip-headers-in-body
3759 article-remove-trailing-blank-lines
3760 article-strip-leading-blank-lines
3761 article-strip-multiple-blank-lines
3762 article-strip-leading-space
3763 article-strip-trailing-space
3764 article-strip-blank-lines
3765 article-strip-all-blank-lines
3767 article-date-english
3768 article-date-iso8601
3769 article-date-original
3771 article-decode-mime-words
3772 article-decode-charset
3773 article-decode-encoded-words
3777 article-treat-dumbquotes
3778 article-normalize-headers
3779 ;; (article-show-all . gnus-article-show-all-headers)
3783 ;;; Gnus article mode
3786 (put 'gnus-article-mode 'mode-class 'special)
3788 (set-keymap-parent gnus-article-mode-map widget-keymap)
3790 (gnus-define-keys gnus-article-mode-map
3791 " " gnus-article-goto-next-page
3792 "\177" gnus-article-goto-prev-page
3793 [delete] gnus-article-goto-prev-page
3794 [backspace] gnus-article-goto-prev-page
3795 "\C-c^" gnus-article-refer-article
3796 "h" gnus-article-show-summary
3797 "s" gnus-article-show-summary
3798 "\C-c\C-m" gnus-article-mail
3799 "?" gnus-article-describe-briefly
3800 "e" gnus-summary-edit-article
3801 "<" beginning-of-buffer
3803 "\C-c\C-i" gnus-info-find-node
3805 "R" gnus-article-reply-with-original
3806 "F" gnus-article-followup-with-original
3807 "\C-hk" gnus-article-describe-key
3808 "\C-hc" gnus-article-describe-key-briefly
3810 "\C-d" gnus-article-read-summary-keys
3811 "\M-*" gnus-article-read-summary-keys
3812 "\M-#" gnus-article-read-summary-keys
3813 "\M-^" gnus-article-read-summary-keys
3814 "\M-g" gnus-article-read-summary-keys)
3816 (substitute-key-definition
3817 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3819 (defun gnus-article-make-menu-bar ()
3820 (unless (boundp 'gnus-article-commands-menu)
3821 (gnus-summary-make-menu-bar))
3822 (gnus-turn-off-edit-menu 'article)
3823 (unless (boundp 'gnus-article-article-menu)
3825 gnus-article-article-menu gnus-article-mode-map ""
3827 ["Scroll forwards" gnus-article-goto-next-page t]
3828 ["Scroll backwards" gnus-article-goto-prev-page t]
3829 ["Show summary" gnus-article-show-summary t]
3830 ["Fetch Message-ID at point" gnus-article-refer-article t]
3831 ["Mail to address at point" gnus-article-mail t]
3832 ["Send a bug report" gnus-bug t]))
3835 gnus-article-treatment-menu gnus-article-mode-map ""
3836 ;; Fixme: this should use :active (and maybe :visible).
3838 ["Hide headers" gnus-article-hide-headers t]
3839 ["Hide signature" gnus-article-hide-signature t]
3840 ["Hide citation" gnus-article-hide-citation t]
3841 ["Treat overstrike" gnus-article-treat-overstrike t]
3842 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3843 ["Remove carriage return" gnus-article-remove-cr t]
3844 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3845 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3846 ["Remove base64" gnus-article-de-base64-unreadable t]
3847 ["Treat html" gnus-article-wash-html t]
3848 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3849 ["Decode HZ" gnus-article-decode-HZ t]))
3851 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3853 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3855 (gnus-run-hooks 'gnus-article-menu-hook)))
3857 (defun gnus-article-mode ()
3858 "Major mode for displaying an article.
3860 All normal editing commands are switched off.
3862 The following commands are available in addition to all summary mode
3864 \\<gnus-article-mode-map>
3865 \\[gnus-article-next-page]\t Scroll the article one page forwards
3866 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3867 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3868 \\[gnus-article-show-summary]\t Display the summary buffer
3869 \\[gnus-article-mail]\t Send a reply to the address near point
3870 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3871 \\[gnus-info-find-node]\t Go to the Gnus info node"
3873 (kill-all-local-variables)
3874 (gnus-simplify-mode-line)
3875 (setq mode-name "Article")
3876 (setq major-mode 'gnus-article-mode)
3877 (make-local-variable 'minor-mode-alist)
3878 (use-local-map gnus-article-mode-map)
3879 (when (gnus-visual-p 'article-menu 'menu)
3880 (gnus-article-make-menu-bar)
3881 (when gnus-summary-tool-bar-map
3882 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3883 (gnus-update-format-specifications nil 'article-mode)
3884 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3885 (set (make-local-variable 'gnus-page-broken) nil)
3886 (make-local-variable 'gnus-button-marker-list)
3887 (make-local-variable 'gnus-article-current-summary)
3888 (make-local-variable 'gnus-article-mime-handles)
3889 (make-local-variable 'gnus-article-decoded-p)
3890 (make-local-variable 'gnus-article-mime-handle-alist)
3891 (make-local-variable 'gnus-article-wash-types)
3892 (make-local-variable 'gnus-article-image-alist)
3893 (make-local-variable 'gnus-article-charset)
3894 (make-local-variable 'gnus-article-ignored-charsets)
3895 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
3896 (set (make-local-variable 'nobreak-char-display) nil)
3897 (gnus-set-default-directory)
3898 (buffer-disable-undo)
3899 (setq buffer-read-only t
3900 show-trailing-whitespace nil)
3901 (set-syntax-table gnus-article-mode-syntax-table)
3902 (mm-enable-multibyte)
3903 (gnus-run-mode-hooks 'gnus-article-mode-hook))
3905 (defun gnus-article-setup-buffer ()
3906 "Initialize the article buffer."
3907 (let* ((name (if gnus-single-article-buffer "*Article*"
3908 (concat "*Article " gnus-newsgroup-name "*")))
3910 (progn (string-match "\\*Article" name)
3911 (concat " *Original Article"
3912 (substring name (match-end 0))))))
3913 (setq gnus-article-buffer name)
3914 (setq gnus-original-article-buffer original)
3915 (setq gnus-article-mime-handle-alist nil)
3916 ;; This might be a variable local to the summary buffer.
3917 (unless gnus-single-article-buffer
3919 (set-buffer gnus-summary-buffer)
3920 (setq gnus-article-buffer name)
3921 (setq gnus-original-article-buffer original)
3922 (gnus-set-global-variables)))
3923 (gnus-article-setup-highlight-words)
3924 ;; Init original article buffer.
3926 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3927 (mm-enable-multibyte)
3928 (setq major-mode 'gnus-original-article-mode)
3929 (make-local-variable 'gnus-original-article))
3930 (if (and (get-buffer name)
3931 (with-current-buffer name
3932 (if gnus-article-edit-mode
3933 (if (y-or-n-p "Article mode edit in progress; discard? ")
3935 (set-buffer-modified-p nil)
3936 (gnus-kill-buffer name)
3939 (error "Action aborted"))
3943 (set (make-local-variable 'gnus-article-edit-mode) nil)
3944 (when gnus-article-mime-handles
3945 (mm-destroy-parts gnus-article-mime-handles)
3946 (setq gnus-article-mime-handles nil))
3947 ;; Set it to nil in article-buffer!
3948 (setq gnus-article-mime-handle-alist nil)
3949 (buffer-disable-undo)
3950 (setq buffer-read-only t)
3951 ;; This list just keeps growing if we don't reset it.
3952 (setq gnus-button-marker-list nil)
3953 (unless (eq major-mode 'gnus-article-mode)
3954 (gnus-article-mode))
3957 (set-buffer (gnus-get-buffer-create name))
3959 (make-local-variable 'gnus-summary-buffer)
3960 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3961 (current-buffer)))))
3963 ;; Set article window start at LINE, where LINE is the number of lines
3964 ;; from the head of the article.
3965 (defun gnus-article-set-window-start (&optional line)
3967 (gnus-get-buffer-window gnus-article-buffer t)
3969 (set-buffer gnus-article-buffer)
3970 (goto-char (point-min))
3973 (gnus-message 6 "Moved to bookmark")
3974 (search-forward "\n\n" nil t)
3978 (defun gnus-article-prepare (article &optional all-headers header)
3979 "Prepare ARTICLE in article mode buffer.
3980 ARTICLE should either be an article number or a Message-ID.
3981 If ARTICLE is an id, HEADER should be the article headers.
3982 If ALL-HEADERS is non-nil, no headers are hidden."
3984 ;; Make sure we start in a summary buffer.
3985 (unless (eq major-mode 'gnus-summary-mode)
3986 (set-buffer gnus-summary-buffer))
3987 (setq gnus-summary-buffer (current-buffer))
3988 (let* ((gnus-article (if header (mail-header-number header) article))
3989 (summary-buffer (current-buffer))
3990 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3991 (group gnus-newsgroup-name)
3994 (gnus-article-setup-buffer)
3995 (set-buffer gnus-article-buffer)
3996 ;; Deactivate active regions.
3997 (when (and (boundp 'transient-mark-mode)
3998 transient-mark-mode)
3999 (setq mark-active nil))
4000 (if (not (setq result (let ((inhibit-read-only t))
4001 (gnus-request-article-this-buffer
4003 ;; There is no such article.
4005 (when (and (numberp article)
4006 (not (memq article gnus-newsgroup-sparse)))
4007 (setq gnus-article-current
4008 (cons gnus-newsgroup-name article))
4009 (set-buffer gnus-summary-buffer)
4010 (setq gnus-current-article article)
4011 (if (and (memq article gnus-newsgroup-undownloaded)
4012 (not (gnus-online (gnus-find-method-for-group
4013 gnus-newsgroup-name))))
4015 (gnus-summary-set-agent-mark article)
4016 (message "Message marked for downloading"))
4017 (gnus-summary-mark-article article gnus-canceled-mark)
4018 (unless (memq article gnus-newsgroup-sparse)
4019 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4020 (if (or (eq result 'pseudo)
4021 (eq result 'nneething))
4024 (set-buffer summary-buffer)
4025 (push article gnus-newsgroup-history)
4026 (setq gnus-last-article gnus-current-article
4027 gnus-current-article 0
4028 gnus-current-headers nil
4029 gnus-article-current nil)
4030 (if (eq result 'nneething)
4031 (gnus-configure-windows 'summary)
4032 (gnus-configure-windows 'article))
4033 (gnus-set-global-variables))
4034 (let ((gnus-article-mime-handle-alist-1
4035 gnus-article-mime-handle-alist))
4036 (gnus-set-mode-line 'article)))
4037 ;; The result from the `request' was an actual article -
4038 ;; or at least some text that is now displayed in the
4040 (when (and (numberp article)
4041 (not (eq article gnus-current-article)))
4042 ;; Seems like a new article has been selected.
4043 ;; `gnus-current-article' must be an article number.
4045 (set-buffer summary-buffer)
4046 (push article gnus-newsgroup-history)
4047 (setq gnus-last-article gnus-current-article
4048 gnus-current-article article
4049 gnus-current-headers
4050 (gnus-summary-article-header gnus-current-article)
4051 gnus-article-current
4052 (cons gnus-newsgroup-name gnus-current-article))
4053 (unless (vectorp gnus-current-headers)
4054 (setq gnus-current-headers nil))
4055 (gnus-summary-goto-subject gnus-current-article)
4056 (when (gnus-summary-show-thread)
4057 ;; If the summary buffer really was folded, the
4058 ;; previous goto may not actually have gone to
4059 ;; the right article, but the thread root instead.
4061 (gnus-summary-goto-subject gnus-current-article))
4062 (gnus-run-hooks 'gnus-mark-article-hook)
4063 (gnus-set-mode-line 'summary)
4064 (when (gnus-visual-p 'article-highlight 'highlight)
4065 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4066 ;; Set the global newsgroup variables here.
4067 (gnus-set-global-variables)
4068 (setq gnus-have-all-headers
4069 (or all-headers gnus-show-all-headers))))
4071 (gnus-configure-windows 'article))
4072 (when (or (numberp article)
4074 (gnus-article-prepare-display)
4076 (goto-char (point-min))
4077 (when gnus-break-pages
4078 (gnus-narrow-to-page)))
4079 (let ((gnus-article-mime-handle-alist-1
4080 gnus-article-mime-handle-alist))
4081 (gnus-set-mode-line 'article))
4085 (set-window-point (get-buffer-window (current-buffer)) (point))
4086 (gnus-configure-windows 'article)
4090 (defun gnus-article-prepare-display ()
4091 "Make the current buffer look like a nice article."
4092 ;; Hooks for getting information from the article.
4093 ;; This hook must be called before being narrowed.
4094 (let ((gnus-article-buffer (current-buffer))
4096 (inhibit-read-only t))
4097 (unless (eq major-mode 'gnus-article-mode)
4098 (gnus-article-mode))
4099 (setq buffer-read-only nil
4100 gnus-article-wash-types nil
4101 gnus-article-image-alist nil)
4102 (gnus-run-hooks 'gnus-tmp-internal-hook)
4103 (when gnus-display-mime-function
4104 (funcall gnus-display-mime-function))
4105 (gnus-run-hooks 'gnus-article-prepare-hook)))
4108 ;;; Gnus MIME viewing functions
4111 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4112 "Format of the MIME buttons.
4114 Valid specifiers include:
4116 %T MIME type, along with additional info
4117 %n The `name' parameter
4118 %d The description, if any
4119 %l The length of the encoded part
4120 %p The part identifier number
4121 %e Dots if the part isn't displayed
4123 General format specifiers can also be used. See Info node
4124 `(gnus)Formatting Variables'.")
4126 (defvar gnus-mime-button-line-format-alist
4127 '((?t gnus-tmp-type ?s)
4128 (?T gnus-tmp-type-long ?s)
4129 (?n gnus-tmp-name ?s)
4130 (?d gnus-tmp-description ?s)
4132 (?l gnus-tmp-length ?d)
4133 (?e gnus-tmp-dots ?s)))
4135 (defvar gnus-mime-button-commands
4136 '((gnus-article-press-button "\r" "Toggle Display")
4137 (gnus-mime-view-part "v" "View Interactively...")
4138 (gnus-mime-view-part-as-type "t" "View As Type...")
4139 (gnus-mime-view-part-as-charset "C" "View As charset...")
4140 (gnus-mime-save-part "o" "Save...")
4141 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4142 (gnus-mime-replace-part "r" "Replace part")
4143 (gnus-mime-delete-part "d" "Delete part")
4144 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4145 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4146 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4147 (gnus-mime-view-part-externally "e" "View Externally")
4148 (gnus-mime-print-part "p" "Print")
4149 (gnus-mime-pipe-part "|" "Pipe To Command...")
4150 (gnus-mime-action-on-part "." "Take action on the part...")))
4152 (defun gnus-article-mime-part-status ()
4153 (if gnus-article-mime-handle-alist-1
4154 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4156 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4159 (defvar gnus-mime-button-map
4160 (let ((map (make-sparse-keymap)))
4161 (define-key map gnus-mouse-2 'gnus-article-push-button)
4162 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4163 (dolist (c gnus-mime-button-commands)
4164 (define-key map (cadr c) (car c)))
4168 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4170 ,@(mapcar (lambda (c)
4171 (vector (caddr c) (car c) :enable t))
4172 gnus-mime-button-commands)))
4174 (defun gnus-mime-button-menu (event prefix)
4175 "Construct a context-sensitive menu of MIME commands."
4176 (interactive "e\nP")
4177 (save-window-excursion
4178 (let ((pos (event-start event)))
4179 (select-window (posn-window pos))
4180 (goto-char (posn-point pos))
4181 (gnus-article-check-buffer)
4182 (popup-menu gnus-mime-button-menu nil prefix))))
4184 (defun gnus-mime-view-all-parts (&optional handles)
4185 "View all the MIME parts."
4187 (with-current-buffer gnus-article-buffer
4188 (let ((handles (or handles gnus-article-mime-handles))
4189 (mail-parse-charset gnus-newsgroup-charset)
4190 (mail-parse-ignored-charsets
4191 (with-current-buffer gnus-summary-buffer
4192 gnus-newsgroup-ignored-charsets)))
4194 (mm-remove-parts handles)
4195 (goto-char (point-min))
4196 (or (search-forward "\n\n") (goto-char (point-max)))
4197 (let ((inhibit-read-only t))
4198 (delete-region (point) (point-max))
4199 (mm-display-parts handles))))))
4201 (defun gnus-article-jump-to-part (n)
4202 "Jump to MIME part N."
4204 (pop-to-buffer gnus-article-buffer)
4205 ;; FIXME: why is it necessary?
4207 (let ((parts (length gnus-article-mime-handle-alist)))
4210 (read-string ;; Emacs 21 doesn't have `read-number'.
4211 (format "Jump to part (2..%s): " parts)))))
4212 (unless (and (integerp n) (<= n parts) (>= n 1))
4215 (gnus-message 7 "Invalid part `%s', using %s instead."
4218 (gnus-message 9 "Jumping to part %s." n)
4219 (cond ((>= gnus-auto-select-part 1)
4220 (while (and (<= n parts)
4221 (not (gnus-article-goto-part n)))
4223 ((< gnus-auto-select-part 0)
4224 (while (and (>= n 1)
4225 (not (gnus-article-goto-part n)))
4228 (gnus-article-goto-part n)))))
4231 (defsubst gnus-article-edit-part (handles &optional current-id)
4232 "Edit an article in order to delete a mime part.
4233 This function is exclusively used by `gnus-mime-save-part-and-strip'
4234 and `gnus-mime-delete-part', and not provided at run-time normally."
4235 (gnus-article-edit-article
4237 (buffer-disable-undo)
4239 (let ((mail-parse-charset (or gnus-article-charset
4240 ',gnus-newsgroup-charset))
4241 (mail-parse-ignored-charsets
4242 (or gnus-article-ignored-charsets
4243 ',gnus-newsgroup-ignored-charsets))
4244 (mbl mml-buffer-list))
4245 (setq mml-buffer-list nil)
4246 (insert-buffer-substring gnus-original-article-buffer)
4247 (mime-to-mml ',handles)
4248 (setq gnus-article-mime-handles nil)
4249 (let ((mbl1 mml-buffer-list))
4250 (setq mml-buffer-list mbl)
4251 (set (make-local-variable 'mml-buffer-list) mbl1))
4252 (gnus-make-local-hook 'kill-buffer-hook)
4253 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4254 `(lambda (no-highlight)
4255 (let ((mail-parse-charset (or gnus-article-charset
4256 ',gnus-newsgroup-charset))
4257 (message-options message-options)
4258 (message-options-set-recipient)
4259 (mail-parse-ignored-charsets
4260 (or gnus-article-ignored-charsets
4261 ',gnus-newsgroup-ignored-charsets)))
4263 (mml-destroy-buffers)
4264 (remove-hook 'kill-buffer-hook
4265 'mml-destroy-buffers t)
4266 (kill-local-variable 'mml-buffer-list))
4267 (gnus-summary-edit-article-done
4268 ,(or (mail-header-references gnus-current-headers) "")
4269 ,(gnus-group-read-only-p)
4270 ,gnus-summary-buffer no-highlight))
4272 (gnus-article-edit-done)
4273 (gnus-summary-expand-window)
4274 (gnus-summary-show-article)
4275 (when (and current-id (integerp gnus-auto-select-part))
4276 (gnus-article-jump-to-part
4277 (+ current-id gnus-auto-select-part)))))
4279 (defun gnus-mime-replace-part (file)
4280 "Replace MIME part under point with an external body."
4281 ;; Useful if file has already been saved to disk
4285 (read-file-name "Replace MIME part with file: "
4286 (or mm-default-directory default-directory)
4288 (gnus-mime-save-part-and-strip file))
4290 (defun gnus-mime-save-part-and-strip (&optional file)
4291 "Save the MIME part under point then replace it with an external body.
4292 If FILE is given, use it for the external part."
4294 (gnus-article-check-buffer)
4295 (when (gnus-group-read-only-p)
4296 (error "The current group does not support deleting of parts"))
4297 (when (mm-complicated-handles gnus-article-mime-handles)
4299 The current article has a complicated MIME structure, giving up..."))
4300 (let* ((data (get-text-property (point) 'gnus-data))
4301 (id (get-text-property (point) 'gnus-part))
4303 (handles gnus-article-mime-handles))
4306 (and data (mm-save-part data "Delete MIME part and save to: "))))
4308 (with-current-buffer (mm-handle-buffer data)
4310 (insert "Content-Type: " (mm-handle-media-type data))
4311 (mml-insert-parameter-string (cdr (mm-handle-type data))
4314 (insert "Content-ID: " (message-make-message-id) "\n")
4315 (insert "Content-Transfer-Encoding: binary\n")
4318 (cdr (mm-make-handle nil
4319 `("message/external-body"
4320 (access-type . "LOCAL-FILE")
4322 ;; (set-buffer gnus-summary-buffer)
4323 (gnus-article-edit-part handles id))))
4325 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4326 ;; parts...>') but with stripping would be nice.
4328 (defun gnus-mime-delete-part ()
4329 "Delete the MIME part under point.
4330 Replace it with some information about the removed part."
4332 (gnus-article-check-buffer)
4333 (when (gnus-group-read-only-p)
4334 (error "The current group does not support deleting of parts"))
4335 (when (mm-complicated-handles gnus-article-mime-handles)
4337 The current article has a complicated MIME structure, giving up..."))
4338 (when (or gnus-expert-user
4339 (gnus-yes-or-no-p "\
4340 Deleting parts may malfunction or destroy the article; continue? "))
4341 (let* ((data (get-text-property (point) 'gnus-data))
4342 (id (get-text-property (point) 'gnus-part))
4343 (handles gnus-article-mime-handles)
4347 (mail-decode-encoded-word-string (or (mm-handle-description data)
4350 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4352 (type (mm-handle-media-type data)))
4354 (error "No MIME part under point"))
4355 (with-current-buffer (mm-handle-buffer data)
4356 (let ((bsize (format "%s" (buffer-size))))
4361 "| The following attachment has been deleted:\n"
4363 "| Type: " type "\n"
4364 "| Filename: " filename "\n"
4365 "| Size (encoded): " bsize " Byte\n"
4366 "| Description: " description "\n"
4369 (cdr (mm-make-handle
4370 nil `("text/plain") nil nil
4372 (format "Deleted attachment (%s bytes)" bsize))))))
4373 ;; (set-buffer gnus-summary-buffer)
4374 (gnus-article-edit-part handles id))))
4376 (defun gnus-mime-save-part ()
4377 "Save the MIME part under point."
4379 (gnus-article-check-buffer)
4380 (let ((data (get-text-property (point) 'gnus-data)))
4382 (mm-save-part data))))
4384 (defun gnus-mime-pipe-part ()
4385 "Pipe the MIME part under point to a process."
4387 (gnus-article-check-buffer)
4388 (let ((data (get-text-property (point) 'gnus-data)))
4390 (mm-pipe-part data))))
4392 (defun gnus-mime-view-part ()
4393 "Interactively choose a viewing method for the MIME part under point."
4395 (gnus-article-check-buffer)
4396 (let ((data (get-text-property (point) 'gnus-data)))
4398 (setq gnus-article-mime-handles
4400 gnus-article-mime-handles (setq data (copy-sequence data))))
4401 (mm-interactively-view-part data))))
4403 (defun gnus-mime-view-part-as-type-internal ()
4404 (gnus-article-check-buffer)
4405 (let* ((handle (get-text-property (point) 'gnus-data))
4407 ;; Content-Type: foo/bar; name=...
4408 (mail-content-type-get (mm-handle-type handle) 'name)
4409 ;; Content-Disposition: attachment; filename=...
4410 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4411 (def-type (and name (mm-default-file-encoding name))))
4412 (and def-type (cons def-type 0))))
4414 (defun gnus-mime-view-part-as-type (&optional mime-type)
4415 "Choose a MIME media type, and view the part as such."
4419 (let ((default (gnus-mime-view-part-as-type-internal)))
4421 (format "View as MIME type (default %s): "
4423 (mapcar #'list (mailcap-mime-types))
4426 (gnus-article-check-buffer)
4427 (let ((handle (get-text-property (point) 'gnus-data)))
4430 (mm-make-handle (mm-handle-buffer handle)
4431 (cons mime-type (cdr (mm-handle-type handle)))
4432 (mm-handle-encoding handle)
4433 (mm-handle-undisplayer handle)
4434 (mm-handle-disposition handle)
4435 (mm-handle-description handle)
4437 (mm-handle-id handle)))
4438 (setq gnus-article-mime-handles
4439 (mm-merge-handles gnus-article-mime-handles handle))
4440 (gnus-mm-display-part handle))))
4442 (defun gnus-mime-copy-part (&optional handle arg)
4443 "Put the MIME part under point into a new buffer.
4444 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4446 (interactive (list nil current-prefix-arg))
4447 (gnus-article-check-buffer)
4449 (setq handle (get-text-property (point) 'gnus-data)))
4451 (let ((filename (or (mail-content-type-get (mm-handle-disposition handle)
4453 (mail-content-type-get (mm-handle-disposition handle)
4455 contents dont-decode charset coding-system)
4456 (mm-with-unibyte-buffer
4457 (mm-insert-part handle)
4458 (setq contents (or (condition-case nil
4459 (mm-decompress-buffer filename nil 'sig)
4461 (setq dont-decode t)
4464 (setq filename (cond (filename (file-name-nondirectory filename))
4465 (dont-decode "*raw data*")
4470 (unless (setq charset (mail-content-type-get
4471 (mm-handle-type handle) 'charset))
4472 (unless (setq coding-system (mm-with-unibyte-buffer
4474 (mm-find-buffer-file-coding-system)))
4475 (setq charset gnus-newsgroup-charset))))
4477 (setq charset (or (cdr (assq arg
4478 gnus-summary-show-article-charset-alist))
4479 (mm-read-coding-system "Charset: ")))))
4480 (switch-to-buffer (generate-new-buffer filename))
4481 (if (or coding-system
4483 (setq coding-system (mm-charset-to-coding-system charset))
4484 (not (eq charset 'ascii))))
4486 (mm-enable-multibyte)
4487 (insert (mm-decode-coding-string contents coding-system))
4488 (setq buffer-file-coding-system
4489 (if (boundp 'last-coding-system-used)
4490 (symbol-value 'last-coding-system-used)
4492 (mm-disable-multibyte)
4494 (setq buffer-file-coding-system mm-binary-coding-system))
4495 ;; We do it this way to make `normal-mode' set the appropriate mode.
4498 (setq buffer-file-name (expand-file-name filename))
4500 (setq buffer-file-name nil))
4501 (goto-char (point-min)))))
4503 (defun gnus-mime-print-part (&optional handle filename)
4504 "Print the MIME part under point."
4505 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4506 (gnus-article-check-buffer)
4507 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4508 (contents (and handle (mm-get-part handle)))
4509 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4510 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4515 (mm-save-part-to-file handle file)
4516 (call-process shell-file-name nil
4517 (generate-new-buffer " *mm*")
4519 shell-command-switch
4521 printer file (mm-handle-type handle))))
4525 (gnus-print-buffer))
4526 (ps-despool filename)))))
4528 (defun gnus-mime-inline-part (&optional handle arg)
4529 "Insert the MIME part under point into the current buffer.
4530 Compressed files like .gz and .bz2 are decompressed."
4531 (interactive (list nil current-prefix-arg))
4532 (gnus-article-check-buffer)
4534 (setq handle (get-text-property (point) 'gnus-data)))
4537 (inhibit-read-only t)
4538 contents charset coding-system)
4539 (if (and (not arg) (mm-handle-undisplayer handle))
4540 (mm-remove-part handle)
4541 (mm-with-unibyte-buffer
4542 (mm-insert-part handle)
4544 (or (mm-decompress-buffer
4545 (or (mail-content-type-get (mm-handle-disposition handle)
4547 (mail-content-type-get (mm-handle-disposition handle)
4553 (unless (setq charset (mail-content-type-get
4554 (mm-handle-type handle) 'charset))
4555 (unless (setq coding-system
4556 (mm-with-unibyte-buffer
4558 (mm-find-buffer-file-coding-system)))
4559 (setq charset gnus-newsgroup-charset))))
4561 (if (mm-handle-undisplayer handle)
4562 (mm-remove-part handle))
4565 gnus-summary-show-article-charset-alist))
4566 (mm-read-coding-system "Charset: "))))
4568 (if (mm-handle-undisplayer handle)
4569 (mm-remove-part handle))))
4573 (if (or coding-system
4576 (mm-charset-to-coding-system charset))
4577 (not (eq coding-system 'ascii))))
4578 (mm-decode-coding-string contents coding-system)
4579 (mm-string-to-multibyte contents)))
4582 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4583 "Insert the MIME part under point into the current buffer using the
4585 (interactive (list nil current-prefix-arg))
4586 (gnus-article-check-buffer)
4587 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4590 (inhibit-read-only t))
4592 (if (mm-handle-undisplayer handle)
4593 (mm-remove-part handle))
4594 (let ((gnus-newsgroup-charset
4596 gnus-summary-show-article-charset-alist))
4597 (mm-read-coding-system "Charset: ")))
4598 (gnus-newsgroup-ignored-charsets 'gnus-all))
4599 (gnus-article-press-button)))))
4601 (defun gnus-mime-view-part-externally (&optional handle)
4602 "View the MIME part under point with an external viewer."
4604 (gnus-article-check-buffer)
4605 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4606 (mm-user-display-methods nil)
4607 (mm-inlined-types nil)
4608 (mail-parse-charset gnus-newsgroup-charset)
4609 (mail-parse-ignored-charsets
4610 (with-current-buffer gnus-summary-buffer
4611 gnus-newsgroup-ignored-charsets)))
4613 (if (mm-handle-undisplayer handle)
4614 (mm-remove-part handle)
4615 (mm-display-part handle)))))
4617 (defun gnus-mime-view-part-internally (&optional handle)
4618 "View the MIME part under point with an internal viewer.
4619 If no internal viewer is available, use an external viewer."
4621 (gnus-article-check-buffer)
4622 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4623 (mm-inlined-types '(".*"))
4624 (mm-inline-large-images t)
4625 (mail-parse-charset gnus-newsgroup-charset)
4626 (mail-parse-ignored-charsets
4627 (with-current-buffer gnus-summary-buffer
4628 gnus-newsgroup-ignored-charsets))
4629 (inhibit-read-only t))
4631 (if (mm-handle-undisplayer handle)
4632 (mm-remove-part handle)
4633 (mm-display-part handle)))))
4635 (defun gnus-mime-action-on-part (&optional action)
4636 "Do something with the MIME attachment at \(point\)."
4638 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4639 (gnus-article-check-buffer)
4640 (let ((action-pair (assoc action gnus-mime-action-alist)))
4642 (funcall (cdr action-pair)))))
4644 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
4645 "Call FUNCTION on MIME part N.
4646 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
4647 If INTERACTIVE, call FUNCTION interactivly."
4649 ;; Check whether the article is displayed.
4650 (unless (and (gnus-buffer-live-p gnus-article-buffer)
4651 (setq window (get-buffer-window gnus-article-buffer t))
4652 (frame-visible-p (setq frame (window-frame window))))
4653 (error "No article is displayed"))
4654 (with-current-buffer gnus-article-buffer
4655 ;; Check whether the article displays the right contents.
4656 (unless (with-current-buffer gnus-summary-buffer
4657 (eq gnus-current-article (gnus-summary-article-number)))
4658 (error "You should select the right article first"))
4659 ;; Check whether the specified part exists.
4660 (when (> n (length gnus-article-mime-handle-alist))
4661 (error "No such part")))
4664 ;; To select the window is needed so that the cursor
4665 ;; might be visible on the MIME button.
4666 (select-window (prog1
4668 (setq window (selected-window))
4669 ;; Article may be displayed in the other frame.
4670 (gnus-select-frame-set-input-focus
4673 (setq frame (selected-frame))))))
4674 (when (gnus-article-goto-part n)
4675 ;; We point the cursor and the arrow at the MIME button
4676 ;; when the `function' prompt the user for something.
4677 (let ((cursor-in-non-selected-windows t)
4678 (overlay-arrow-string "=>")
4679 (overlay-arrow-position (point-marker)))
4682 ((and no-handle interactive)
4683 (call-interactively function))
4689 (cdr (assq n gnus-article-mime-handle-alist))))
4692 (cdr (assq n gnus-article-mime-handle-alist)))))
4693 (set-marker overlay-arrow-position nil)
4694 (unless gnus-auto-select-part
4695 (gnus-select-frame-set-input-focus frame)
4696 (select-window window))))
4698 (if gnus-inhibit-mime-unbuttonizing
4699 ;; This is the default though the program shouldn't reach here.
4700 (error "No such part")
4701 ;; The part which doesn't have the MIME button is selected.
4702 ;; So, we display all the buttons and redo it.
4703 (let ((gnus-inhibit-mime-unbuttonizing t))
4704 (gnus-summary-show-article)
4705 (gnus-article-part-wrapper n function no-handle))))))
4707 (defun gnus-article-pipe-part (n)
4708 "Pipe MIME part N, which is the numerical prefix."
4710 (gnus-article-part-wrapper n 'mm-pipe-part))
4712 (defun gnus-article-save-part (n)
4713 "Save MIME part N, which is the numerical prefix."
4715 (gnus-article-part-wrapper n 'mm-save-part))
4717 (defun gnus-article-interactively-view-part (n)
4718 "View MIME part N interactively, which is the numerical prefix."
4720 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4722 (defun gnus-article-copy-part (n)
4723 "Copy MIME part N, which is the numerical prefix."
4725 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4727 (defun gnus-article-view-part-as-charset (n)
4728 "View MIME part N using a specified charset.
4729 N is the numerical prefix."
4731 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4733 (defun gnus-article-view-part-externally (n)
4734 "View MIME part N externally, which is the numerical prefix."
4736 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4738 (defun gnus-article-inline-part (n)
4739 "Inline MIME part N, which is the numerical prefix."
4741 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4743 (defun gnus-article-save-part-and-strip (n)
4744 "Save MIME part N and replace it with an external body.
4745 N is the numerical prefix."
4747 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
4749 (defun gnus-article-replace-part (n)
4750 "Replace MIME part N with an external body.
4751 N is the numerical prefix."
4753 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
4755 (defun gnus-article-delete-part (n)
4756 "Delete MIME part N and add some information about the removed part.
4757 N is the numerical prefix."
4759 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
4761 (defun gnus-article-mime-match-handle-first (condition)
4764 (dolist (ihandle gnus-article-mime-handle-alist)
4766 ((functionp condition)
4767 (funcall condition (cdr ihandle)))
4768 ((eq condition 'undisplayed)
4769 (not (or (mm-handle-undisplayer (cdr ihandle))
4770 (equal (mm-handle-media-type (cdr ihandle))
4771 "multipart/alternative"))))
4772 ((eq condition 'undisplayed-alternative)
4773 (not (mm-handle-undisplayer (cdr ihandle))))
4775 (gnus-article-goto-part (car ihandle))
4776 (or (not n) (< (car ihandle) n)))
4777 (setq n (car ihandle))))
4781 (defun gnus-article-view-part (&optional n)
4782 "View MIME part N, which is the numerical prefix."
4784 (with-current-buffer gnus-article-buffer
4785 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4786 gnus-article-mime-match-handle-function)))
4787 (when (> n (length gnus-article-mime-handle-alist))
4788 (error "No such part"))
4789 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4790 (when (gnus-article-goto-part n)
4791 (if (equal (car handle) "multipart/alternative")
4792 (gnus-article-press-button)
4793 (when (eq (gnus-mm-display-part handle) 'internal)
4794 (gnus-set-window-start)))))))
4796 (defsubst gnus-article-mime-total-parts ()
4797 (if (bufferp (car gnus-article-mime-handles))
4799 (1- (length gnus-article-mime-handles))))
4801 (defun gnus-mm-display-part (handle)
4802 "Display HANDLE and fix MIME button."
4803 (let ((id (get-text-property (point) 'gnus-part))
4805 (inhibit-read-only t))
4808 (let ((window (selected-window))
4809 (mail-parse-charset gnus-newsgroup-charset)
4810 (mail-parse-ignored-charsets
4811 (if (gnus-buffer-live-p gnus-summary-buffer)
4812 (with-current-buffer gnus-summary-buffer
4813 gnus-newsgroup-ignored-charsets)
4817 (let ((win (gnus-get-buffer-window (current-buffer) t))
4820 (select-window win))
4823 (if (mm-handle-displayed-p handle)
4824 ;; This will remove the part.
4825 (mm-display-part handle)
4827 (narrow-to-region (point)
4828 (if (eobp) (point) (1+ (point))))
4829 (mm-display-part handle)
4830 ;; We narrow to the part itself and
4831 ;; then call the treatment functions.
4832 (goto-char (point-min))
4834 (narrow-to-region (point) (point-max))
4837 (gnus-article-mime-total-parts)
4838 (mm-handle-media-type handle)))))
4839 (if (window-live-p window)
4840 (select-window window)))))
4843 (gnus-insert-mime-button
4844 handle id (list (mm-handle-displayed-p handle)))
4845 (goto-char point))))
4847 (defun gnus-article-goto-part (n)
4848 "Go to MIME part N."
4849 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4851 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4852 (let ((gnus-tmp-name
4853 (or (mail-content-type-get (mm-handle-type handle) 'name)
4854 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4855 (mail-content-type-get (mm-handle-type handle) 'url)
4857 (gnus-tmp-type (mm-handle-media-type handle))
4858 (gnus-tmp-description
4859 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4862 (if (if displayed (car displayed)
4863 (mm-handle-displayed-p handle))
4865 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4867 gnus-tmp-type-long b e)
4868 (when (string-match ".*/" gnus-tmp-name)
4869 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4870 (setq gnus-tmp-type-long (concat gnus-tmp-type
4871 (and (not (equal gnus-tmp-name ""))
4872 (concat "; " gnus-tmp-name))))
4873 (unless (equal gnus-tmp-description "")
4874 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4879 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4880 `(keymap ,gnus-mime-button-map
4881 gnus-callback gnus-mm-display-part
4882 gnus-part ,gnus-tmp-id
4883 article-type annotation
4886 ;; Exclude a newline.
4889 (widget-convert-button
4892 :action 'gnus-widget-press-button
4893 :button-keymap gnus-mime-button-map
4895 (lambda (widget/window &optional overlay pos)
4896 ;; Needed to properly clear the message due to a bug in
4897 ;; wid-edit (XEmacs only).
4898 (if (boundp 'help-echo-owns-message)
4899 (setq help-echo-owns-message t))
4901 "%S: %s the MIME part; %S: more options"
4902 (aref gnus-mouse-2 0)
4903 ;; XEmacs will get a single widget arg; Emacs 21 will get
4904 ;; window, overlay, position.
4905 (if (mm-handle-displayed-p
4907 (with-current-buffer (gnus-overlay-buffer overlay)
4908 (widget-get (widget-at (gnus-overlay-start overlay))
4910 (widget-get widget/window :mime-handle)))
4912 (aref gnus-down-mouse-3 0))))))
4914 (defun gnus-widget-press-button (elems el)
4915 (goto-char (widget-get elems :from))
4916 (gnus-article-press-button))
4918 (defvar gnus-displaying-mime nil)
4920 (defun gnus-display-mime (&optional ihandles)
4921 "Display the MIME parts."
4923 (save-selected-window
4924 (let ((window (get-buffer-window gnus-article-buffer))
4927 (select-window window)
4928 ;; We have to do this since selecting the window
4929 ;; may change the point. So we set the window point.
4930 (set-window-point window point)))
4931 (let ((handles ihandles)
4932 (inhibit-read-only t)
4935 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
4936 (when gnus-article-emulate-mime
4937 (mm-uu-dissect-text-parts handles)))
4938 (gnus-article-emulate-mime
4939 (setq handles (mm-uu-dissect))))
4940 (when (and (not ihandles)
4941 (not gnus-displaying-mime))
4942 ;; Top-level call; we clean up.
4943 (when gnus-article-mime-handles
4944 (mm-destroy-parts gnus-article-mime-handles)
4945 (setq gnus-article-mime-handle-alist nil));; A trick.
4946 (setq gnus-article-mime-handles handles)
4947 ;; We allow users to glean info from the handles.
4948 (when gnus-article-mime-part-function
4949 (gnus-mime-part-function handles)))
4951 (or (not (stringp (car handles)))
4954 (when (and (not ihandles)
4955 (not gnus-displaying-mime))
4956 ;; Clean up for mime parts.
4958 (delete-region (point) (point-max)))
4959 (let ((gnus-displaying-mime t))
4960 (gnus-mime-display-part handles)))
4963 (narrow-to-region (point) (point-max))
4964 (gnus-treat-article nil 1 1)
4967 ;; Highlight the headers.
4971 (narrow-to-region (point-min) (point))
4972 (gnus-article-save-original-date
4973 (gnus-treat-article 'head)))))))))
4975 (defcustom gnus-mime-display-multipart-as-mixed nil
4976 "Display \"multipart\" parts as \"multipart/mixed\".
4978 If t, it overrides nil values of
4979 `gnus-mime-display-multipart-alternative-as-mixed' and
4980 `gnus-mime-display-multipart-related-as-mixed'."
4981 :group 'gnus-article-mime
4984 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4985 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4987 :group 'gnus-article-mime
4990 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4991 "Display \"multipart/related\" parts as \"multipart/mixed\".
4993 If displaying \"text/html\" is discouraged \(see
4994 `mm-discouraged-alternatives'\) images or other material inside a
4995 \"multipart/related\" part might be overlooked when this variable is nil."
4997 :group 'gnus-article-mime
5000 (defun gnus-mime-display-part (handle)
5002 ;; Maybe a broken MIME message.
5005 ((not (stringp (car handle)))
5006 (gnus-mime-display-single handle))
5007 ;; User-defined multipart
5008 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5009 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5011 ;; multipart/alternative
5012 ((and (equal (car handle) "multipart/alternative")
5013 (not (or gnus-mime-display-multipart-as-mixed
5014 gnus-mime-display-multipart-alternative-as-mixed)))
5015 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5016 (push (cons id handle) gnus-article-mime-handle-alist)
5017 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5018 ;; multipart/related
5019 ((and (equal (car handle) "multipart/related")
5020 (not (or gnus-mime-display-multipart-as-mixed
5021 gnus-mime-display-multipart-related-as-mixed)))
5022 ;;;!!!We should find the start part, but we just default
5023 ;;;!!!to the first part.
5024 ;;(gnus-mime-display-part (cadr handle))
5025 ;;;!!! Most multipart/related is an HTML message plus images.
5026 ;;;!!! Unfortunately we are unable to let W3 display those
5027 ;;;!!! included images, so we just display it as a mixed multipart.
5028 ;;(gnus-mime-display-mixed (cdr handle))
5029 ;;;!!! No, w3 can display everything just fine.
5030 (gnus-mime-display-part (cadr handle)))
5031 ((equal (car handle) "multipart/signed")
5032 (gnus-add-wash-type 'signed)
5033 (gnus-mime-display-security handle))
5034 ((equal (car handle) "multipart/encrypted")
5035 (gnus-add-wash-type 'encrypted)
5036 (gnus-mime-display-security handle))
5037 ;; Other multiparts are handled like multipart/mixed.
5039 (gnus-mime-display-mixed (cdr handle)))))
5041 (defun gnus-mime-part-function (handles)
5042 (if (stringp (car handles))
5043 (mapcar 'gnus-mime-part-function (cdr handles))
5044 (funcall gnus-article-mime-part-function handles)))
5046 (defun gnus-mime-display-mixed (handles)
5047 (mapcar 'gnus-mime-display-part handles))
5049 (defun gnus-mime-display-single (handle)
5050 (let ((type (mm-handle-media-type handle))
5051 (ignored gnus-ignored-mime-types)
5058 (when (string-match (pop ignored) type)
5059 (throw 'ignored nil)))
5060 (if (and (setq not-attachment
5061 (and (not (mm-inline-override-p handle))
5062 (or (not (mm-handle-disposition handle))
5063 (equal (car (mm-handle-disposition handle))
5065 (mm-attachment-override-p handle))))
5066 (mm-automatic-display-p handle)
5068 (mm-inlinable-p handle)
5069 (mm-inlined-p handle))
5070 (mm-automatic-external-display-p type)))
5072 (when (equal (mm-handle-media-supertype handle) "text")
5074 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5076 (push (cons id handle) gnus-article-mime-handle-alist)
5077 (when (or (not display)
5078 (not (gnus-unbuttonized-mime-type-p type)))
5079 (gnus-insert-mime-button
5080 handle id (list (or display (and not-attachment text))))
5081 (gnus-article-insert-newline)
5082 ;; Remember modify the number of forward lines.
5090 (let ((mail-parse-charset gnus-newsgroup-charset)
5091 (mail-parse-ignored-charsets
5092 (save-excursion (condition-case ()
5093 (set-buffer gnus-summary-buffer)
5095 gnus-newsgroup-ignored-charsets)))
5096 (mm-display-part handle t))
5097 (goto-char (point-max)))
5098 ((and text not-attachment)
5102 (gnus-article-insert-newline)
5105 (let ((charset (mail-content-type-get (mm-handle-type handle)
5107 (cond ((not charset)
5108 (mm-string-as-multibyte (mm-get-part handle)))
5109 ((eq charset 'gnus-decoded)
5110 (with-current-buffer (mm-handle-buffer handle)
5113 (mm-decode-string (mm-get-part handle) charset)))))
5114 (goto-char (point-max))))
5118 (narrow-to-region beg (point))
5121 (gnus-article-mime-total-parts)
5122 (mm-handle-media-type handle)))))))))
5124 (defun gnus-unbuttonized-mime-type-p (type)
5125 "Say whether TYPE is to be unbuttonized."
5126 (unless gnus-inhibit-mime-unbuttonizing
5128 (let ((types gnus-unbuttonized-mime-types))
5130 (when (string-match (pop types) type)
5131 (throw 'found t)))))
5133 (let ((types gnus-buttonized-mime-types))
5135 (when (string-match (pop types) type)
5136 (throw 'found t)))))))))
5138 (defun gnus-article-insert-newline ()
5139 "Insert a newline, but mark it as undeletable."
5140 (gnus-put-text-property
5141 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5143 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5144 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5147 handle (inhibit-read-only t) from props begend not-pref)
5148 (save-window-excursion
5151 (narrow-to-region (car ibegend)
5154 (goto-char (car ibegend))
5157 (delete-region (point-min) (point-max))
5158 (mm-remove-parts handles))
5159 (setq begend (list (point-marker)))
5161 (unless (setq not-pref (cadr (member preferred ihandles)))
5162 (setq not-pref (car ihandles)))
5165 (not (gnus-unbuttonized-mime-type-p
5166 "multipart/alternative")))
5167 (gnus-add-text-properties
5170 (insert (format "%d. " id))
5174 (unless ,(not ibegend)
5175 (setq gnus-article-mime-handle-alist
5176 ',gnus-article-mime-handle-alist))
5177 (gnus-mime-display-alternative
5178 ',ihandles ',not-pref ',begend ,id))
5179 keymap ,gnus-mime-button-map
5180 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5181 face ,gnus-article-button-face
5183 article-type multipart))
5184 (widget-convert-button 'link from (point)
5185 :action 'gnus-widget-press-button
5186 :button-keymap gnus-widget-button-keymap)
5188 (while (setq handle (pop handles))
5189 (gnus-add-text-properties
5192 (insert (format "(%c) %-18s"
5193 (if (equal handle preferred) ?* ? )
5194 (mm-handle-media-type handle)))
5198 (unless ,(not ibegend)
5199 (setq gnus-article-mime-handle-alist
5200 ',gnus-article-mime-handle-alist))
5201 (gnus-mime-display-alternative
5202 ',ihandles ',handle ',begend ,id))
5203 keymap ,gnus-mime-button-map
5204 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5205 face ,gnus-article-button-face
5208 (widget-convert-button 'link from (point)
5209 :action 'gnus-widget-press-button
5210 :button-keymap gnus-widget-button-keymap)
5214 (if (stringp (car preferred))
5215 (gnus-display-mime preferred)
5216 (let ((mail-parse-charset gnus-newsgroup-charset)
5217 (mail-parse-ignored-charsets
5218 (with-current-buffer gnus-summary-buffer
5219 gnus-newsgroup-ignored-charsets)))
5220 (mm-display-part preferred)
5224 (narrow-to-region (car begend) (point-max))
5226 nil (length gnus-article-mime-handle-alist)
5227 (gnus-article-mime-total-parts)
5228 (mm-handle-media-type handle))))))
5229 (goto-char (point-max))
5230 (setcdr begend (point-marker)))))
5232 (goto-char point))))
5234 (defconst gnus-article-wash-status-strings
5235 (let ((alist '((cite "c" "Possible hidden citation text"
5236 " " "All citation text visible")
5237 (headers "h" "Hidden headers"
5238 " " "All headers visible.")
5239 (pgp "p" "Encrypted or signed message status hidden"
5240 " " "No hidden encryption nor digital signature status")
5241 (signature "s" "Signature has been hidden"
5242 " " "Signature is visible")
5243 (overstrike "o" "Overstrike (^H) characters applied"
5244 " " "No overstrike characters applied")
5245 (emphasis "e" "/*_Emphasis_*/ characters applied"
5246 " " "No /*_emphasis_*/ characters applied")))
5248 (dolist (entry alist result)
5249 (let ((key (nth 0 entry))
5250 (on (copy-sequence (nth 1 entry)))
5251 (on-help (nth 2 entry))
5252 (off (copy-sequence (nth 3 entry)))
5253 (off-help (nth 4 entry)))
5254 (put-text-property 0 1 'help-echo on-help on)
5255 (put-text-property 0 1 'help-echo off-help off)
5256 (push (list key on off) result))))
5257 "Alist of strings describing wash status in the mode line.
5258 Each entry has the form (KEY ON OF), where the KEY is a symbol
5259 representing the particular washing function, ON is the string to use
5260 in the article mode line when the washing function is active, and OFF
5261 is the string to use when it is inactive.")
5263 (defun gnus-article-wash-status-entry (key value)
5264 (let ((entry (assoc key gnus-article-wash-status-strings)))
5265 (if value (nth 1 entry) (nth 2 entry))))
5267 (defun gnus-article-wash-status ()
5268 "Return a string which display status of article washing."
5269 (with-current-buffer gnus-article-buffer
5270 (let ((cite (memq 'cite gnus-article-wash-types))
5271 (headers (memq 'headers gnus-article-wash-types))
5272 (boring (memq 'boring-headers gnus-article-wash-types))
5273 (pgp (memq 'pgp gnus-article-wash-types))
5274 (pem (memq 'pem gnus-article-wash-types))
5275 (signed (memq 'signed gnus-article-wash-types))
5276 (encrypted (memq 'encrypted gnus-article-wash-types))
5277 (signature (memq 'signature gnus-article-wash-types))
5278 (overstrike (memq 'overstrike gnus-article-wash-types))
5279 (emphasis (memq 'emphasis gnus-article-wash-types)))
5281 (gnus-article-wash-status-entry 'cite cite)
5282 (gnus-article-wash-status-entry 'headers (or headers boring))
5283 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5284 (gnus-article-wash-status-entry 'signature signature)
5285 (gnus-article-wash-status-entry 'overstrike overstrike)
5286 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5288 (defun gnus-add-wash-type (type)
5289 "Add a washing of TYPE to the current status."
5290 (add-to-list 'gnus-article-wash-types type))
5292 (defun gnus-delete-wash-type (type)
5293 "Add a washing of TYPE to the current status."
5294 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5296 (defun gnus-add-image (category image)
5297 "Add IMAGE of CATEGORY to the list of displayed images."
5298 (let ((entry (assq category gnus-article-image-alist)))
5300 (setq entry (list category))
5301 (push entry gnus-article-image-alist))
5302 (nconc entry (list image))))
5304 (defun gnus-delete-images (category)
5305 "Delete all images in CATEGORY."
5306 (let ((entry (assq category gnus-article-image-alist)))
5307 (dolist (image (cdr entry))
5308 (gnus-remove-image image category))
5309 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5310 (gnus-delete-wash-type category)))
5312 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5314 (defun gnus-article-maybe-hide-headers ()
5315 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5316 Provided for backwards compatibility."
5317 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5318 (not (with-current-buffer gnus-summary-buffer
5319 gnus-have-all-headers)))
5320 (not gnus-inhibit-hiding))
5321 (gnus-article-hide-headers)))
5325 (defun gnus-output-to-file (file-name)
5326 "Append the current article to a file named FILE-NAME."
5327 (let ((artbuf (current-buffer)))
5329 (insert-buffer-substring artbuf)
5330 ;; Append newline at end of the buffer as separator, and then
5332 (goto-char (point-max))
5334 (let ((file-name-coding-system nnmail-pathname-coding-system))
5335 (mm-append-to-file (point-min) (point-max) file-name))
5338 (defun gnus-narrow-to-page (&optional arg)
5339 "Narrow the article buffer to a page.
5340 If given a numerical ARG, move forward ARG pages."
5342 (setq arg (if arg (prefix-numeric-value arg) 0))
5344 (set-buffer gnus-article-buffer)
5345 (goto-char (point-min))
5347 ;; Remove any old next/prev buttons.
5348 (when (gnus-visual-p 'page-marker)
5349 (let ((inhibit-read-only t))
5350 (gnus-remove-text-with-property 'gnus-prev)
5351 (gnus-remove-text-with-property 'gnus-next)))
5354 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5356 (re-search-forward page-delimiter nil 'move arg)))
5357 (goto-char (match-end 0))
5359 (goto-char (point-min))
5360 (setq gnus-page-broken
5361 (and (re-search-forward page-delimiter nil t) t))))
5362 (when gnus-page-broken
5365 (if (re-search-forward page-delimiter nil 'move)
5368 (when (and (gnus-visual-p 'page-marker)
5369 (> (point-min) (save-restriction (widen) (point-min))))
5371 (goto-char (point-min))
5372 (gnus-insert-prev-page-button)))
5373 (when (and (gnus-visual-p 'page-marker)
5374 (< (point-max) (save-restriction (widen) (point-max))))
5376 (goto-char (point-max))
5377 (gnus-insert-next-page-button))))))
5379 ;; Article mode commands
5381 (defun gnus-article-goto-next-page ()
5382 "Show the next page of the article."
5384 (when (gnus-article-next-page)
5385 (goto-char (point-min))
5386 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5389 (defun gnus-article-goto-prev-page ()
5390 "Show the previous page of the article."
5393 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5394 (gnus-article-prev-page nil)))
5396 ;; This is cleaner but currently breaks `gnus-pick-mode':
5398 ;; (defun gnus-article-goto-next-page ()
5399 ;; "Show the next page of the article."
5401 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5402 ;; (gnus-summary-next-page)))
5404 ;; (defun gnus-article-goto-prev-page ()
5405 ;; "Show the next page of the article."
5407 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5408 ;; (gnus-summary-prev-page)))
5410 (defun gnus-article-next-page (&optional lines)
5411 "Show the next page of the current article.
5412 If end of article, return non-nil. Otherwise return nil.
5413 Argument LINES specifies lines to be scrolled up."
5415 (move-to-window-line -1)
5418 (and (pos-visible-in-window-p) ;Not continuation line.
5419 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5420 ;; Nothing in this page.
5421 (if (or (not gnus-page-broken)
5426 (eobp)))) ;Real end-of-buffer?
5428 (when gnus-article-over-scroll
5429 (gnus-article-next-page-1 lines))
5431 (gnus-narrow-to-page 1) ;Go to next page.
5433 ;; More in this page.
5434 (gnus-article-next-page-1 lines)
5437 (defmacro gnus-article-beginning-of-window ()
5438 "Move point to the beginning of the window.
5439 In Emacs, the point is placed at the line number which `scroll-margin'
5441 (if (featurep 'xemacs)
5442 '(move-to-window-line 0)
5443 '(move-to-window-line
5444 (min (max 0 scroll-margin)
5445 (max 1 (- (window-height)
5446 (if mode-line-format 1 0)
5447 (if header-line-format 1 0)))))))
5449 (defun gnus-article-next-page-1 (lines)
5450 (when (and (not (featurep 'xemacs))
5453 (numberp (symbol-value 'scroll-margin))
5454 (> (symbol-value 'scroll-margin) 0))
5455 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5456 ;; too many number of lines if `scroll-margin' is set as two or greater.
5457 (setq lines (min lines
5458 (max 0 (- (count-lines (window-start) (point-max))
5459 (symbol-value 'scroll-margin))))))
5461 (let ((scroll-in-place nil))
5464 ;; Long lines may cause an end-of-buffer error.
5465 (goto-char (point-max))))
5466 (gnus-article-beginning-of-window))
5468 (defun gnus-article-prev-page (&optional lines)
5469 "Show previous page of current article.
5470 Argument LINES specifies lines to be scrolled down."
5472 (move-to-window-line 0)
5473 (if (and gnus-page-broken
5475 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5477 (gnus-narrow-to-page -1) ;Go to previous page.
5478 (goto-char (point-max))
5482 (let ((scroll-in-place nil))
5483 (scroll-down lines))
5484 (beginning-of-buffer
5485 (goto-char (point-min))))
5486 (gnus-article-beginning-of-window))))
5488 (defun gnus-article-only-boring-p ()
5489 "Decide whether there is only boring text remaining in the article.
5490 Something \"interesting\" is a word of at least two letters that does
5491 not have a face in `gnus-article-boring-faces'."
5492 (when (and gnus-article-skip-boring
5493 (boundp 'gnus-article-boring-faces)
5494 (symbol-value 'gnus-article-boring-faces))
5497 (while (re-search-forward "\\b\\w\\w" nil t)
5499 (when (not (gnus-intersection
5500 (gnus-faces-at (point))
5501 (symbol-value 'gnus-article-boring-faces)))
5502 (throw 'only-boring nil)))
5503 (throw 'only-boring t)))))
5505 (defun gnus-article-refer-article ()
5506 "Read article specified by message-id around point."
5509 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5510 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5511 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5512 (let ((msg-id (concat "<" (match-string 0) ">")))
5513 (set-buffer gnus-summary-buffer)
5514 (gnus-summary-refer-article msg-id))
5515 (error "No references around point"))))
5517 (defun gnus-article-show-summary ()
5518 "Reconfigure windows to show summary buffer."
5520 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5521 (error "There is no summary buffer for this article buffer")
5522 (gnus-article-set-globals)
5523 (gnus-configure-windows 'article)
5524 (gnus-summary-goto-subject gnus-current-article)
5525 (gnus-summary-position-point)))
5527 (defun gnus-article-describe-briefly ()
5528 "Describe article mode commands briefly."
5530 (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")))
5532 (defun gnus-article-summary-command ()
5533 "Execute the last keystroke in the summary buffer."
5535 (let ((obuf (current-buffer))
5536 (owin (current-window-configuration))
5538 (switch-to-buffer gnus-article-current-summary 'norecord)
5539 (setq func (lookup-key (current-local-map) (this-command-keys)))
5540 (call-interactively func)
5542 (set-window-configuration owin)
5543 (set-window-point (get-buffer-window (current-buffer)) (point))))
5545 (defun gnus-article-summary-command-nosave ()
5546 "Execute the last keystroke in the summary buffer."
5549 (pop-to-buffer gnus-article-current-summary 'norecord)
5550 (setq func (lookup-key (current-local-map) (this-command-keys)))
5551 (call-interactively func)))
5553 (defun gnus-article-check-buffer ()
5554 "Beep if not in an article buffer."
5555 (unless (equal major-mode 'gnus-article-mode)
5556 (error "Command invoked outside of a Gnus article buffer")))
5558 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5559 "Read a summary buffer key sequence and execute it from the article buffer."
5561 (gnus-article-check-buffer)
5563 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5564 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5565 "=" "^" "\M-^" "|"))
5571 '("n" "Gn" "p" "Gp"))
5574 (set-buffer gnus-article-current-summary)
5575 (let (gnus-pick-mode)
5576 (push (or key last-command-event) unread-command-events)
5577 (setq keys (if (featurep 'xemacs)
5578 (events-to-keys (read-key-sequence nil))
5579 (read-key-sequence nil)))))
5583 (if (or (member keys nosaves)
5584 (member keys nosave-but-article)
5585 (member keys nosave-in-article))
5587 (save-window-excursion
5588 (pop-to-buffer gnus-article-current-summary 'norecord)
5589 ;; We disable the pick minor mode commands.
5590 (let (gnus-pick-mode)
5591 (setq func (lookup-key (current-local-map) keys))))
5595 (unless (member keys nosave-in-article)
5596 (set-buffer gnus-article-current-summary))
5597 (call-interactively func)
5598 (setq new-sum-point (point)))
5599 (when (member keys nosave-but-article)
5600 (pop-to-buffer gnus-article-buffer 'norecord)))
5601 ;; These commands should restore window configuration.
5602 (let ((obuf (current-buffer))
5603 (owin (current-window-configuration))
5605 win func in-buffer selected new-sum-start new-sum-hscroll)
5606 (cond (not-restore-window
5607 (pop-to-buffer gnus-article-current-summary 'norecord))
5608 ((setq win (get-buffer-window gnus-article-current-summary))
5609 (select-window win))
5611 (switch-to-buffer gnus-article-current-summary 'norecord)))
5612 (setq in-buffer (current-buffer))
5613 ;; We disable the pick minor mode commands.
5614 (if (and (setq func (let (gnus-pick-mode)
5615 (lookup-key (current-local-map) keys)))
5618 (call-interactively func)
5619 (when (eq win (selected-window))
5620 (setq new-sum-point (point)
5621 new-sum-start (window-start win)
5622 new-sum-hscroll (window-hscroll win)))
5623 (when (eq in-buffer (current-buffer))
5624 (setq selected (gnus-summary-select-article))
5626 (unless not-restore-window
5627 (set-window-configuration owin))
5628 (when (eq selected 'old)
5630 (set-window-start (get-buffer-window (current-buffer))
5632 (set-window-point (get-buffer-window (current-buffer))
5634 (when (and (not not-restore-window)
5636 (set-window-point win new-sum-point)
5637 (set-window-start win new-sum-start)
5638 (set-window-hscroll win new-sum-hscroll))))
5639 (set-window-configuration owin)
5642 (defun gnus-article-describe-key (key)
5643 "Display documentation of the function invoked by KEY. KEY is a string."
5644 (interactive "kDescribe key: ")
5645 (gnus-article-check-buffer)
5646 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5648 (set-buffer gnus-article-current-summary)
5649 (let (gnus-pick-mode)
5650 (if (featurep 'xemacs)
5652 (push (elt key 0) unread-command-events)
5653 (setq key (events-to-keys
5654 (read-key-sequence "Describe key: "))))
5655 (setq unread-command-events
5657 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5658 (string-to-list key)))
5659 (setq key (read-key-sequence "Describe key: "))))
5661 (describe-key key)))
5663 (defun gnus-article-describe-key-briefly (key &optional insert)
5664 "Display documentation of the function invoked by KEY. KEY is a string."
5665 (interactive "kDescribe key: \nP")
5666 (gnus-article-check-buffer)
5667 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5669 (set-buffer gnus-article-current-summary)
5670 (let (gnus-pick-mode)
5671 (if (featurep 'xemacs)
5673 (push (elt key 0) unread-command-events)
5674 (setq key (events-to-keys
5675 (read-key-sequence "Describe key: "))))
5676 (setq unread-command-events
5678 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5679 (string-to-list key)))
5680 (setq key (read-key-sequence "Describe key: "))))
5681 (describe-key-briefly key insert))
5682 (describe-key-briefly key insert)))
5684 (defun gnus-article-reply-with-original (&optional wide)
5685 "Start composing a reply mail to the current message.
5686 The text in the region will be yanked. If the region isn't active,
5687 the entire article will be yanked."
5689 (let ((article (cdr gnus-article-current))
5691 (if (not (gnus-region-active-p))
5692 (with-current-buffer gnus-summary-buffer
5693 (gnus-summary-reply (list (list article)) wide))
5694 (setq contents (buffer-substring (point) (mark t)))
5695 ;; Deactivate active regions.
5696 (when (and (boundp 'transient-mark-mode)
5697 transient-mark-mode)
5698 (setq mark-active nil))
5699 (with-current-buffer gnus-summary-buffer
5701 (list (list article contents)) wide)))))
5703 (defun gnus-article-followup-with-original ()
5704 "Compose a followup to the current article.
5705 The text in the region will be yanked. If the region isn't active,
5706 the entire article will be yanked."
5708 (let ((article (cdr gnus-article-current))
5710 (if (not (gnus-region-active-p))
5711 (with-current-buffer gnus-summary-buffer
5712 (gnus-summary-followup (list (list article))))
5713 (setq contents (buffer-substring (point) (mark t)))
5714 ;; Deactivate active regions.
5715 (when (and (boundp 'transient-mark-mode)
5716 transient-mark-mode)
5717 (setq mark-active nil))
5718 (with-current-buffer gnus-summary-buffer
5719 (gnus-summary-followup
5720 (list (list article contents)))))))
5722 (defun gnus-article-hide (&optional arg force)
5723 "Hide all the gruft in the current article.
5724 This means that signatures, cited text and (some) headers will be
5726 If given a prefix, show the hidden text instead."
5727 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5728 (gnus-article-hide-headers arg)
5729 (gnus-article-hide-list-identifiers arg)
5730 (gnus-article-hide-citation-maybe arg force)
5731 (gnus-article-hide-signature arg))
5733 (defun gnus-article-maybe-highlight ()
5734 "Do some article highlighting if article highlighting is requested."
5735 (when (gnus-visual-p 'article-highlight 'highlight)
5736 (gnus-article-highlight-some)))
5738 (defun gnus-check-group-server ()
5739 ;; Make sure the connection to the server is alive.
5740 (unless (gnus-server-opened
5741 (gnus-find-method-for-group gnus-newsgroup-name))
5742 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5743 (gnus-request-group gnus-newsgroup-name t)))
5746 (autoload 'nneething-get-file-name "nneething"))
5748 (defun gnus-request-article-this-buffer (article group)
5749 "Get an article and insert it into this buffer."
5750 (let (do-update-line sparse-header)
5754 (gnus-kill-all-overlays)
5755 (setq group (or group gnus-newsgroup-name))
5757 ;; Using `gnus-request-article' directly will insert the article into
5758 ;; `nntp-server-buffer' - so we'll save some time by not having to
5759 ;; copy it from the server buffer into the article buffer.
5761 ;; We only request an article by message-id when we do not have the
5762 ;; headers for it, so we'll have to get those.
5763 (when (stringp article)
5764 (gnus-read-header article))
5766 ;; If the article number is negative, that means that this article
5767 ;; doesn't belong in this newsgroup (possibly), so we find its
5768 ;; message-id and request it by id instead of number.
5769 (when (and (numberp article)
5771 (get-buffer gnus-summary-buffer)
5772 (gnus-buffer-exists-p gnus-summary-buffer))
5774 (set-buffer gnus-summary-buffer)
5775 (let ((header (gnus-summary-article-header article)))
5778 ((memq article gnus-newsgroup-sparse)
5779 ;; This is a sparse gap article.
5780 (setq do-update-line article)
5781 (setq article (mail-header-id header))
5782 (setq sparse-header (gnus-read-header article))
5783 (setq gnus-newsgroup-sparse
5784 (delq article gnus-newsgroup-sparse)))
5786 ;; It's a real article.
5787 (setq article (mail-header-id header)))
5789 ;; It is an extracted pseudo-article.
5790 (setq article 'pseudo)
5791 (gnus-request-pseudo-article header))))
5793 (let ((method (gnus-find-method-for-group
5794 gnus-newsgroup-name)))
5795 (when (and (eq (car method) 'nneething)
5797 (let ((dir (nneething-get-file-name
5798 (mail-header-id header))))
5799 (when (and (stringp dir)
5800 (file-directory-p dir))
5801 (setq article 'nneething)
5802 (gnus-group-enter-directory dir))))))))
5805 ;; Refuse to select canceled articles.
5806 ((and (numberp article)
5808 (get-buffer gnus-summary-buffer)
5809 (gnus-buffer-exists-p gnus-summary-buffer)
5810 (eq (cdr (with-current-buffer gnus-summary-buffer
5811 (assq article gnus-newsgroup-reads)))
5812 gnus-canceled-mark))
5814 ;; We first check `gnus-original-article-buffer'.
5815 ((and (get-buffer gnus-original-article-buffer)
5817 (with-current-buffer gnus-original-article-buffer
5818 (and (equal (car gnus-original-article) group)
5819 (eq (cdr gnus-original-article) article))))
5820 (insert-buffer-substring gnus-original-article-buffer)
5822 ;; Check the backlog.
5823 ((and gnus-keep-backlog
5824 (gnus-backlog-request-article group article (current-buffer)))
5826 ;; Check asynchronous pre-fetch.
5827 ((gnus-async-request-fetched-article group article (current-buffer))
5828 (gnus-async-prefetch-next group article gnus-summary-buffer)
5829 (when (and (numberp article) gnus-keep-backlog)
5830 (gnus-backlog-enter-article group article (current-buffer)))
5833 ((and gnus-use-cache
5835 (gnus-cache-request-article article group))
5837 ;; Check the agent cache.
5838 ((gnus-agent-request-article article group)
5840 ;; Get the article and put into the article buffer.
5841 ((or (stringp article)
5843 (let ((gnus-override-method gnus-override-method)
5844 (methods (and (stringp article)
5845 gnus-refer-article-method))
5846 (backend (car (gnus-find-method-for-group
5847 gnus-newsgroup-name)))
5849 (inhibit-read-only t))
5850 (if (or (not (listp methods))
5851 (and (symbolp (car methods))
5852 (assq (car methods) nnoo-definition-alist)))
5853 (setq methods (list methods)))
5854 (when (and (null gnus-override-method)
5856 (setq gnus-override-method (pop methods)))
5858 (when (eq gnus-override-method 'current)
5859 (setq gnus-override-method
5860 (with-current-buffer gnus-summary-buffer
5861 gnus-current-select-method)))
5863 (gnus-kill-all-overlays)
5864 (let ((gnus-newsgroup-name group))
5865 (gnus-check-group-server))
5867 ((gnus-request-article article group (current-buffer))
5868 (when (numberp article)
5869 (gnus-async-prefetch-next group article
5870 gnus-summary-buffer)
5871 (when gnus-keep-backlog
5872 (gnus-backlog-enter-article
5873 group article (current-buffer))))
5874 (setq result 'article))
5876 (setq gnus-override-method (pop methods)))
5877 ((not (string-match "^400 "
5878 (nnheader-get-report backend)))
5879 ;; If we get 400 server disconnect, reconnect and
5880 ;; retry; otherwise, assume the article has expired.
5881 (setq result 'done))))
5882 (and (eq result 'article) 'article)))
5886 ;; Associate this article with the current summary buffer.
5887 (setq gnus-article-current-summary gnus-summary-buffer)
5889 ;; Take the article from the original article buffer
5890 ;; and place it in the buffer it's supposed to be in.
5891 (when (and (get-buffer gnus-article-buffer)
5892 (equal (buffer-name (current-buffer))
5893 (buffer-name (get-buffer gnus-article-buffer))))
5895 (if (get-buffer gnus-original-article-buffer)
5896 (set-buffer gnus-original-article-buffer)
5897 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5898 (buffer-disable-undo)
5899 (setq major-mode 'gnus-original-article-mode)
5900 (setq buffer-read-only t))
5901 (let ((inhibit-read-only t))
5903 (insert-buffer-substring gnus-article-buffer))
5904 (setq gnus-original-article (cons group article)))
5907 (run-hooks 'gnus-article-decode-hook)
5908 ;; Mark article as decoded or not.
5909 (setq gnus-article-decoded-p gnus-article-decode-hook))
5911 ;; Update sparse articles.
5912 (when (and do-update-line
5913 (or (numberp article)
5915 (let ((buf (current-buffer)))
5916 (set-buffer gnus-summary-buffer)
5917 (gnus-summary-update-article do-update-line sparse-header)
5918 (gnus-summary-goto-subject do-update-line nil t)
5919 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5921 (set-buffer buf))))))
5927 (defcustom gnus-article-edit-mode-hook nil
5928 "Hook run in article edit mode buffers."
5929 :group 'gnus-article-various
5932 (defvar gnus-article-edit-done-function nil)
5934 (defvar gnus-article-edit-mode-map nil)
5936 ;; Should we be using derived.el for this?
5937 (unless gnus-article-edit-mode-map
5938 (setq gnus-article-edit-mode-map (make-keymap))
5939 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5941 (gnus-define-keys gnus-article-edit-mode-map
5942 "\C-c?" describe-mode
5943 "\C-c\C-c" gnus-article-edit-done
5944 "\C-c\C-k" gnus-article-edit-exit
5945 "\C-c\C-f\C-t" message-goto-to
5946 "\C-c\C-f\C-o" message-goto-from
5947 "\C-c\C-f\C-b" message-goto-bcc
5948 ;;"\C-c\C-f\C-w" message-goto-fcc
5949 "\C-c\C-f\C-c" message-goto-cc
5950 "\C-c\C-f\C-s" message-goto-subject
5951 "\C-c\C-f\C-r" message-goto-reply-to
5952 "\C-c\C-f\C-n" message-goto-newsgroups
5953 "\C-c\C-f\C-d" message-goto-distribution
5954 "\C-c\C-f\C-f" message-goto-followup-to
5955 "\C-c\C-f\C-m" message-goto-mail-followup-to
5956 "\C-c\C-f\C-k" message-goto-keywords
5957 "\C-c\C-f\C-u" message-goto-summary
5958 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5959 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5960 "\C-c\C-b" message-goto-body
5961 "\C-c\C-i" message-goto-signature
5963 "\C-c\C-t" message-insert-to
5964 "\C-c\C-n" message-insert-newsgroups
5965 "\C-c\C-o" message-sort-headers
5966 "\C-c\C-e" message-elide-region
5967 "\C-c\C-v" message-delete-not-region
5968 "\C-c\C-z" message-kill-to-signature
5969 "\M-\r" message-newline-and-reformat
5970 "\C-c\C-a" mml-attach-file
5971 "\C-a" message-beginning-of-line
5973 "\M-;" comment-region)
5975 (gnus-define-keys (gnus-article-edit-wash-map
5976 "\C-c\C-w" gnus-article-edit-mode-map)
5977 "f" gnus-article-edit-full-stops))
5980 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5982 ["Fetch To" message-insert-to t]
5983 ["Fetch Newsgroups" message-insert-newsgroups t]
5985 ["To" message-goto-to t]
5986 ["From" message-goto-from t]
5987 ["Subject" message-goto-subject t]
5988 ["Cc" message-goto-cc t]
5989 ["Reply-To" message-goto-reply-to t]
5990 ["Summary" message-goto-summary t]
5991 ["Keywords" message-goto-keywords t]
5992 ["Newsgroups" message-goto-newsgroups t]
5993 ["Followup-To" message-goto-followup-to t]
5994 ["Mail-Followup-To" message-goto-mail-followup-to t]
5995 ["Distribution" message-goto-distribution t]
5996 ["Body" message-goto-body t]
5997 ["Signature" message-goto-signature t]))
5999 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6000 "Major mode for editing articles.
6001 This is an extended text-mode.
6003 \\{gnus-article-edit-mode-map}"
6004 (make-local-variable 'gnus-article-edit-done-function)
6005 (make-local-variable 'gnus-prev-winconf)
6006 (set (make-local-variable 'font-lock-defaults)
6007 '(message-font-lock-keywords t))
6008 (set (make-local-variable 'mail-header-separator) "")
6009 (set (make-local-variable 'gnus-article-edit-mode) t)
6010 (easy-menu-add message-mode-field-menu message-mode-map)
6012 (setq buffer-read-only nil)
6013 (buffer-enable-undo)
6016 (defun gnus-article-edit (&optional force)
6017 "Edit the current article.
6018 This will have permanent effect only in mail groups.
6019 If FORCE is non-nil, allow editing of articles even in read-only
6022 (when (and (not force)
6023 (gnus-group-read-only-p))
6024 (error "The current newsgroup does not support article editing"))
6025 (gnus-article-date-original)
6026 (gnus-article-edit-article
6028 `(lambda (no-highlight)
6030 (gnus-summary-edit-article-done
6031 ,(or (mail-header-references gnus-current-headers) "")
6032 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6034 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6035 "Start editing the contents of the current article buffer."
6036 (let ((winconf (current-window-configuration)))
6037 (set-buffer gnus-article-buffer)
6038 (let ((message-auto-save-directory
6039 ;; Don't associate the article buffer with a draft file.
6041 (gnus-article-edit-mode))
6042 (funcall start-func)
6043 (set-buffer-modified-p nil)
6044 (gnus-configure-windows 'edit-article)
6045 (setq gnus-article-edit-done-function exit-func)
6046 (setq gnus-prev-winconf winconf)
6048 (gnus-message 6 "C-c C-c to end edits"))))
6050 (defun gnus-article-edit-done (&optional arg)
6051 "Update the article edits and exit."
6053 (let ((func gnus-article-edit-done-function)
6054 (buf (current-buffer))
6055 (start (window-start))
6057 (winconf gnus-prev-winconf))
6058 (widen) ;; Widen it in case that users narrowed the buffer.
6061 ;; The cache and backlog have to be flushed somewhat.
6062 (when gnus-keep-backlog
6063 (gnus-backlog-remove-article
6064 (car gnus-article-current) (cdr gnus-article-current)))
6065 ;; Flush original article as well.
6067 (when (get-buffer gnus-original-article-buffer)
6068 (set-buffer gnus-original-article-buffer)
6069 (setq gnus-original-article nil)))
6070 (when gnus-use-cache
6071 (gnus-cache-update-article
6072 (car gnus-article-current) (cdr gnus-article-current)))
6073 ;; We remove all text props from the article buffer.
6074 (kill-all-local-variables)
6075 (set-text-properties (point-min) (point-max) nil)
6077 (set-window-configuration winconf)
6079 (set-window-start (get-buffer-window buf) start)
6080 (set-window-point (get-buffer-window buf) (point)))
6081 (gnus-summary-show-article))
6083 (defun gnus-article-edit-exit ()
6084 "Exit the article editing without updating."
6086 (when (or (not (buffer-modified-p))
6087 (yes-or-no-p "Article modified; kill anyway? "))
6088 (let ((curbuf (current-buffer))
6090 (window-start (window-start)))
6092 (if (gnus-buffer-live-p gnus-original-article-buffer)
6093 (insert-buffer-substring gnus-original-article-buffer))
6094 (let ((winconf gnus-prev-winconf))
6095 (kill-all-local-variables)
6097 (set-window-configuration winconf)
6098 ;; Tippy-toe some to make sure that point remains where it was.
6099 (save-current-buffer
6101 (set-window-start (get-buffer-window (current-buffer)) window-start)
6103 (gnus-summary-show-article)))
6105 (defun gnus-article-edit-full-stops ()
6106 "Interactively repair spacing at end of sentences."
6109 (goto-char (point-min))
6110 (search-forward-regexp "^$" nil t)
6111 (let ((case-fold-search nil))
6112 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6115 ;;; Article highlights
6118 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6120 ;;; Internal Variables:
6122 (defcustom gnus-button-url-regexp
6123 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6124 "\\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:]]\\)"
6125 "\\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\\)\\)")
6126 "Regular expression that matches URLs."
6127 :group 'gnus-article-buttons
6130 (defcustom gnus-button-valid-fqdn-regexp
6131 message-valid-fqdn-regexp
6132 "Regular expression that matches a valid FQDN."
6134 :group 'gnus-article-buttons
6137 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6138 (defcustom gnus-button-valid-localpart-regexp
6139 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*"
6140 "Regular expression that matches a localpart of mail addresses or MIDs."
6142 :group 'gnus-article-buttons
6145 (defcustom gnus-button-man-handler 'manual-entry
6146 "Function to use for displaying man pages.
6147 The function must take at least one argument with a string naming the
6150 :type '(choice (function-item :tag "Man" manual-entry)
6151 (function-item :tag "Woman" woman)
6152 (function :tag "Other"))
6153 :group 'gnus-article-buttons)
6155 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6156 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6157 If the default site is too slow, try to find a CTAN mirror, see
6158 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6159 the variable `gnus-button-handle-ctan'."
6161 :group 'gnus-article-buttons
6162 :link '(custom-manual "(gnus)Group Parameters")
6163 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6164 (const "http://tug.ctan.org/tex-archive/")
6165 (const "http://www.dante.de/CTAN/")
6166 (string :tag "Other")))
6168 (defcustom gnus-button-ctan-handler 'browse-url
6169 "Function to use for displaying CTAN links.
6170 The function must take one argument, the string naming the URL."
6172 :type '(choice (function-item :tag "Browse Url" browse-url)
6173 (function :tag "Other"))
6174 :group 'gnus-article-buttons)
6176 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6177 "Bogus strings removed from CTAN URLs."
6179 :group 'gnus-article-buttons
6180 :type '(choice (const "^/?tex-archive/\\|/")
6181 (regexp :tag "Other")))
6183 (defcustom gnus-button-ctan-directory-regexp
6185 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6186 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6187 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6188 "tds" "tools" "usergrps" "web") t)
6189 "Regular expression for ctan directories.
6190 It should match all directories in the top level of `gnus-ctan-url'."
6192 :group 'gnus-article-buttons
6195 (defcustom gnus-button-mid-or-mail-regexp
6196 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6197 gnus-button-valid-fqdn-regexp
6199 "Regular expression that matches a message ID or a mail address."
6201 :group 'gnus-article-buttons
6204 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6205 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6206 Strings like this can be either a message ID or a mail address. If it is one
6207 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6208 message ID or a mail address, respectively. If this variable is set to the
6209 symbol `ask', always query the user what do do. If it is a function, this
6210 function will be called with the string as it's only argument. The function
6211 must return `mid', `mail', `invalid' or `ask'."
6213 :group 'gnus-article-buttons
6214 :type '(choice (function-item :tag "Heuristic function"
6215 gnus-button-mid-or-mail-heuristic)
6220 (defcustom gnus-button-mid-or-mail-heuristic-alist
6221 '((-10.0 . ".+\\$.+@")
6224 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6225 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6226 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6227 (-1.0 . "^[^a-z]+@")
6229 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6230 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6231 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6232 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6235 (-1.0 . "^[0-9][0-9]")
6237 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6238 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6239 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6240 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6242 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6243 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6246 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6248 ;; compensation for TDMA dated mail addresses:
6249 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6251 (-20.0 . "\\.fsf@") ;; Gnus
6254 (-20.0 . "_-_") ;; Subject change in thread
6256 (-20.0 . "\\.ln@") ;; leafnode
6257 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6258 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6260 ;; (5.0 . "") ;; $local_part_len <= 7
6261 (10.0 . "^[^0-9]+@")
6262 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6263 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6266 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6268 (0.5 . "^[A-Z][a-z]")
6269 (0.5 . "^[A-Z][a-z][a-z]")
6270 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6271 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6272 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6274 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6275 address. The REGEXP is processed with `case-fold-search' set to nil."
6277 :group 'gnus-article-buttons
6278 :type '(repeat (cons (number :tag "Rate")
6279 (regexp :tag "Regexp"))))
6281 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6282 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6283 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6284 address, `ask' if unsure and `invalid' if the string is invalid."
6285 (let ((case-fold-search nil)
6286 (list gnus-button-mid-or-mail-heuristic-alist)
6287 (result 0) rate regexp lpartlen elem)
6289 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6290 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6291 ;; Certain special cases...
6294 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6295 "^[0-9]+\\.[0-9]+@compuserve\\|"
6296 "@public\\.gmane\\.org")
6298 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6299 (setq result 'mail))
6300 (when (string-match "@.*@\\| " mid-or-mail)
6301 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6302 (setq result 'invalid))
6303 ;; Nothing more to do, if result is not a number here...
6304 (when (numberp result)
6306 (setq elem (car list)
6310 (when (string-match regexp mid-or-mail)
6311 (setq result (+ result rate))
6313 9 "`%s' matched `%s', rate `%s', result `%s'."
6314 mid-or-mail regexp rate result)))
6315 (when (<= lpartlen 7)
6316 (setq result (+ result 5.0))
6317 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6318 mid-or-mail result))
6319 (when (>= lpartlen 12)
6320 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6322 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6323 ;; Long local part should contain realname if e-mail address,
6324 ;; too many digits: message-id.
6325 ;; $score -= 5.0 + 0.1 * $local_part_len;
6326 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6327 (setq result (+ result rate))
6329 9 "Many digits in `%s', rate `%s', result `%s'."
6330 mid-or-mail rate result))
6331 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6333 ;; Too few vowels [^aeiouy]{4,}.*\@
6334 (setq result (+ result -5.0))
6336 9 "Few vowels in `%s', rate `%s', result `%s'."
6337 mid-or-mail -5.0 result))
6339 (setq result (+ result 5.0))
6341 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6342 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6343 ;; Maybe we should make this a customizable alist: (condition . 'result)
6345 ((symbolp result) result)
6346 ;; Now convert number into proper results:
6347 ((< result -10.0) 'mid)
6348 ((> result 10.0) 'mail)
6351 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6352 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6353 (url-mid (concat "news" ":" mid-or-mail))
6354 (url-mailto (concat "mailto" ":" mid-or-mail)))
6355 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6356 (when (fboundp pref)
6358 ;; get rid of surrounding angles...
6360 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6361 (if (or (eq 'mid guessed) (eq 'mail guessed))
6365 (save-window-excursion
6366 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6369 (cond ((eq pref 'mid)
6370 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6371 (gnus-button-handle-news url-mid))
6373 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6374 (gnus-url-mailto url-mailto))
6375 (t (gnus-message 3 "Invalid string.")))))
6377 (defun gnus-button-handle-custom (fun arg)
6378 "Call function FUN on argument ARG.
6379 Both FUN and ARG are supposed to be strings. ARG will be passed
6380 as a symbol to FUN."
6381 (funcall (intern fun) (intern arg)))
6383 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6385 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6388 (defun gnus-button-handle-describe-function (url)
6389 "Call `describe-function' when pushing the corresponding URL button."
6392 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6394 (defun gnus-button-handle-describe-variable (url)
6395 "Call `describe-variable' when pushing the corresponding URL button."
6398 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6400 (defun gnus-button-handle-symbol (url)
6401 "Display help on variable or function.
6402 Calls `describe-variable' or `describe-function'."
6403 (let ((sym (intern url)))
6405 ((fboundp sym) (describe-function sym))
6406 ((boundp sym) (describe-variable sym))
6407 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6409 (defun gnus-button-handle-describe-key (url)
6410 "Call `describe-key' when pushing the corresponding URL button."
6412 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6413 (keys (ignore-errors (eval `(kbd ,key-string)))))
6416 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6418 (defun gnus-button-handle-apropos (url)
6419 "Call `apropos' when pushing the corresponding URL button."
6420 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6422 (defun gnus-button-handle-apropos-command (url)
6423 "Call `apropos' when pushing the corresponding URL button."
6425 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6427 (defun gnus-button-handle-apropos-variable (url)
6428 "Call `apropos' when pushing the corresponding URL button."
6430 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6431 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6433 (defun gnus-button-handle-apropos-documentation (url)
6434 "Call `apropos' when pushing the corresponding URL button."
6436 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6437 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6439 (defun gnus-button-handle-library (url)
6440 "Call `locate-library' when pushing the corresponding URL button."
6441 (gnus-message 9 "url=`%s'" url)
6442 (let* ((lib (locate-library url))
6443 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6445 (gnus-message 1 "Cannot locale library `%s'." url)
6446 (find-file-read-only file))))
6448 (defun gnus-button-handle-ctan (url)
6449 "Call `browse-url' when pushing a CTAN URL button."
6451 gnus-button-ctan-handler
6454 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6456 (defcustom gnus-button-tex-level 5
6457 "*Integer that says how many TeX-related buttons Gnus will show.
6458 The higher the number, the more buttons will appear and the more false
6459 positives are possible. Note that you can set this variable local to
6460 specific groups. Setting it higher in TeX groups is probably a good idea.
6461 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6462 how to set variables in specific groups."
6464 :group 'gnus-article-buttons
6465 :link '(custom-manual "(gnus)Group Parameters")
6468 (defcustom gnus-button-man-level 5
6469 "*Integer that says how many man-related buttons Gnus will show.
6470 The higher the number, the more buttons will appear and the more false
6471 positives are possible. Note that you can set this variable local to
6472 specific groups. Setting it higher in Unix groups is probably a good idea.
6473 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6474 how to set variables in specific groups."
6476 :group 'gnus-article-buttons
6477 :link '(custom-manual "(gnus)Group Parameters")
6480 (defcustom gnus-button-emacs-level 5
6481 "*Integer that says how many emacs-related buttons Gnus will show.
6482 The higher the number, the more buttons will appear and the more false
6483 positives are possible. Note that you can set this variable local to
6484 specific groups. Setting it higher in Emacs or Gnus related groups is
6485 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6486 `gnus-parameters' on how to set variables in specific groups."
6488 :group 'gnus-article-buttons
6489 :link '(custom-manual "(gnus)Group Parameters")
6492 (defcustom gnus-button-message-level 5
6493 "*Integer that says how many buttons for news or mail messages will appear.
6494 The higher the number, the more buttons will appear and the more false
6495 positives are possible."
6496 ;; mail addresses, MIDs, URLs for news, ...
6498 :group 'gnus-article-buttons
6501 (defcustom gnus-button-browse-level 5
6502 "*Integer that says how many buttons for browsing will appear.
6503 The higher the number, the more buttons will appear and the more false
6504 positives are possible."
6505 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6507 :group 'gnus-article-buttons
6510 (defcustom gnus-button-alist
6511 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6512 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6513 ((concat "\\b\\(nntp\\|news\\):\\("
6514 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6515 0 t gnus-button-handle-news 2)
6516 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6517 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6518 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6519 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6520 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6521 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6522 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6523 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6524 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6525 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6526 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6527 ;; RFC 2368 (The mailto URL scheme)
6528 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6529 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6530 ("\\bmailto:\\([^ \n\t]+\\)"
6531 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6533 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6534 gnus-button-ctan-directory-regexp
6535 "[^][>)!;:,'\n\t ]+\\)")
6536 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6537 ((concat "\\btex-archive/\\("
6538 gnus-button-ctan-directory-regexp
6539 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6540 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6543 gnus-button-ctan-directory-regexp
6544 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6545 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6546 ;; This is info (home-grown style) <info://foo/bar+baz>
6547 ("\\binfo://\\([^'\">\n\t ]+\\)"
6548 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6549 ;; Info GNOME style <info:foo#bar_baz>
6550 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6551 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6552 ;; Info KDE style <info:(foo)bar baz>
6553 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6554 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6555 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6556 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6557 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6558 ;; Info links like `C-h i d m CC Mode RET'
6559 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6561 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6562 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
6563 ;; Emacs help commands
6564 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6565 ;; regexp doesn't match arguments containing ` '.
6566 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6567 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6568 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6569 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6570 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6571 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6572 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6573 ;; The following entries may lead to many false positives so don't enable
6574 ;; them by default (use a high button level).
6575 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6576 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6577 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6578 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6579 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6580 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6581 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6582 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6583 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6584 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6585 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6586 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6587 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6588 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6589 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6590 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6591 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6592 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6593 ;; Unlike the other regexps we really have to require quoting
6594 ;; here to determine where it ends.
6595 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6596 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6597 ("<URL: *\\([^<>]*\\)>"
6598 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6599 ;; RFC 2396 (2.4.3., delims) ...
6600 ("\"URL: *\\([^\"]*\\)\""
6601 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6602 ;; RFC 2396 (2.4.3., delims) ...
6603 ("\"URL: *\\([^\"]*\\)\""
6604 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6606 (gnus-button-url-regexp
6607 0 (>= gnus-button-browse-level 0) browse-url 0)
6609 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6610 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6611 gnus-button-handle-man 1)
6612 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6613 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6614 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6615 gnus-button-handle-man 1)
6616 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6617 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6618 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6619 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6620 ;; MID or mail: To avoid too many false positives we don't try to catch
6621 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6622 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6623 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6624 ;; so that non-ambiguous entries (see above) match first.
6625 (gnus-button-mid-or-mail-regexp
6626 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6627 "*Alist of regexps matching buttons in article bodies.
6629 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6630 REGEXP: is the string (case insensitive) matching text around the button (can
6631 also be Lisp expression evaluating to a string),
6632 BUTTON: is the number of the regexp grouping actually matching the button,
6633 FORM: is a Lisp expression which must eval to true for the button to
6635 CALLBACK: is the function to call when the user push this button, and each
6636 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6638 CALLBACK can also be a variable, in that case the value of that
6639 variable it the real callback function."
6640 :group 'gnus-article-buttons
6641 :type '(repeat (list (choice regexp variable sexp)
6642 (integer :tag "Button")
6644 (function :tag "Callback")
6647 (integer :tag "Regexp group")))))
6649 (defcustom gnus-header-button-alist
6650 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6651 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6652 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6653 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6654 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6655 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
6656 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6657 0 (>= gnus-button-browse-level 0) browse-url 0)
6658 ("^Subject:" gnus-button-url-regexp
6659 0 (>= gnus-button-browse-level 0) browse-url 0)
6660 ("^[^:]+:" gnus-button-url-regexp
6661 0 (>= gnus-button-browse-level 0) browse-url 0)
6662 ("^OpenPGP:.*url=" gnus-button-url-regexp
6663 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
6664 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6665 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6666 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6667 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6668 "*Alist of headers and regexps to match buttons in article heads.
6670 This alist is very similar to `gnus-button-alist', except that each
6671 alist has an additional HEADER element first in each entry:
6673 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6675 HEADER is a regexp to match a header. For a fuller explanation, see
6676 `gnus-button-alist'."
6677 :group 'gnus-article-buttons
6678 :group 'gnus-article-headers
6679 :type '(repeat (list (regexp :tag "Header")
6680 (choice regexp variable)
6681 (integer :tag "Button")
6683 (function :tag "Callback")
6686 (integer :tag "Regexp group")))))
6690 (defun gnus-article-push-button (event)
6691 "Check text under the mouse pointer for a callback function.
6692 If the text under the mouse pointer has a `gnus-callback' property,
6693 call it with the value of the `gnus-data' text property."
6695 (set-buffer (window-buffer (posn-window (event-start event))))
6696 (let* ((pos (posn-point (event-start event)))
6697 (data (get-text-property pos 'gnus-data))
6698 (fun (get-text-property pos 'gnus-callback)))
6701 (funcall fun data))))
6703 (defun gnus-article-press-button ()
6704 "Check text at point for a callback function.
6705 If the text at point has a `gnus-callback' property,
6706 call it with the value of the `gnus-data' text property."
6708 (let ((data (get-text-property (point) 'gnus-data))
6709 (fun (get-text-property (point) 'gnus-callback)))
6711 (funcall fun data))))
6713 (defun gnus-article-highlight (&optional force)
6714 "Highlight current article.
6715 This function calls `gnus-article-highlight-headers',
6716 `gnus-article-highlight-citation',
6717 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6718 do the highlighting. See the documentation for those functions."
6719 (interactive (list 'force))
6720 (gnus-article-highlight-headers)
6721 (gnus-article-highlight-citation force)
6722 (gnus-article-highlight-signature)
6723 (gnus-article-add-buttons force)
6724 (gnus-article-add-buttons-to-head))
6726 (defun gnus-article-highlight-some (&optional force)
6727 "Highlight current article.
6728 This function calls `gnus-article-highlight-headers',
6729 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6730 do the highlighting. See the documentation for those functions."
6731 (interactive (list 'force))
6732 (gnus-article-highlight-headers)
6733 (gnus-article-highlight-signature)
6734 (gnus-article-add-buttons))
6736 (defun gnus-article-highlight-headers ()
6737 "Highlight article headers as specified by `gnus-header-face-alist'."
6739 (gnus-with-article-headers
6740 (let (regexp header-face field-face from hpoints fpoints)
6741 (dolist (entry gnus-header-face-alist)
6742 (goto-char (point-min))
6743 (setq regexp (concat "^\\("
6744 (if (string-equal "" (nth 0 entry))
6748 header-face (nth 1 entry)
6749 field-face (nth 2 entry))
6750 (while (and (re-search-forward regexp nil t)
6754 (unless (search-forward ":" nil t)
6756 (when (and header-face
6757 (not (memq (point) hpoints)))
6758 (push (point) hpoints)
6759 (gnus-put-text-property from (point) 'face header-face))
6760 (when (and field-face
6761 (not (memq (setq from (point)) fpoints)))
6763 (if (re-search-forward "^[^ \t]" nil t)
6765 (goto-char (point-max)))
6766 (gnus-put-text-property from (point) 'face field-face)))))))
6768 (defun gnus-article-highlight-signature ()
6769 "Highlight the signature in an article.
6770 It does this by highlighting everything after
6771 `gnus-signature-separator' using the face `gnus-signature'."
6773 (gnus-with-article-buffer
6774 (let ((inhibit-point-motion-hooks t))
6776 (when (and gnus-signature-face
6777 (gnus-article-narrow-to-signature))
6778 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6779 'face gnus-signature-face)
6781 (gnus-article-search-signature)
6782 (let ((start (match-beginning 0))
6783 (end (set-marker (make-marker) (1+ (match-end 0)))))
6784 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6787 (defun gnus-button-in-region-p (b e prop)
6788 "Say whether PROP exists in the region."
6789 (text-property-not-all b e prop nil))
6791 (defun gnus-article-add-buttons (&optional force)
6792 "Find external references in the article and make buttons of them.
6793 \"External references\" are things like Message-IDs and URLs, as
6794 specified by `gnus-button-alist'."
6795 (interactive (list 'force))
6796 (gnus-with-article-buffer
6797 (let ((inhibit-point-motion-hooks t)
6798 (case-fold-search t)
6799 (alist gnus-button-alist)
6801 ;; Remove all old markers.
6802 (let (marker entry new-list)
6803 (while (setq marker (pop gnus-button-marker-list))
6804 (if (or (< marker (point-min)) (>= marker (point-max)))
6805 (push marker new-list)
6807 (when (setq entry (gnus-button-entry))
6808 (put-text-property (match-beginning (nth 1 entry))
6809 (match-end (nth 1 entry))
6810 'gnus-callback nil))
6811 (set-marker marker nil)))
6812 (setq gnus-button-marker-list new-list))
6813 ;; We skip the headers.
6816 (while (setq entry (pop alist))
6817 (setq regexp (eval (car entry)))
6819 (while (re-search-forward regexp nil t)
6820 (let* ((start (and entry (match-beginning (nth 1 entry))))
6821 (end (and entry (match-end (nth 1 entry))))
6822 (from (match-beginning 0)))
6823 (when (and (or (eq t (nth 2 entry))
6824 (eval (nth 2 entry)))
6825 (not (gnus-button-in-region-p
6826 start end 'gnus-callback)))
6827 ;; That optional form returned non-nil, so we add the
6829 (gnus-article-add-button
6830 start end 'gnus-button-push
6831 (car (push (set-marker (make-marker) from)
6832 gnus-button-marker-list))))))))))
6834 ;; Add buttons to the head of an article.
6835 (defun gnus-article-add-buttons-to-head ()
6836 "Add buttons to the head of the article."
6838 (gnus-with-article-headers
6840 (dolist (entry gnus-header-button-alist)
6841 ;; Each alist entry.
6842 (goto-char (point-min))
6843 (while (re-search-forward (car entry) nil t)
6844 ;; Each header matching the entry.
6845 (setq beg (match-beginning 0))
6846 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6847 (match-beginning 0))
6850 (while (re-search-forward (eval (nth 1 entry)) end t)
6851 ;; Each match within a header.
6852 (let* ((entry (cdr entry))
6853 (start (match-beginning (nth 1 entry)))
6854 (end (match-end (nth 1 entry)))
6855 (form (nth 2 entry)))
6856 (goto-char (match-end 0))
6858 (gnus-article-add-button
6859 start end (nth 3 entry)
6860 (buffer-substring (match-beginning (nth 4 entry))
6861 (match-end (nth 4 entry)))))))
6862 (goto-char end))))))
6864 ;;; External functions:
6866 (defun gnus-article-add-button (from to fun &optional data)
6867 "Create a button between FROM and TO with callback FUN and data DATA."
6868 (when gnus-article-button-face
6869 (gnus-overlay-put (gnus-make-overlay from to)
6870 'face gnus-article-button-face))
6871 (gnus-add-text-properties
6873 (nconc (and gnus-article-mouse-face
6874 (list gnus-mouse-face-prop gnus-article-mouse-face))
6875 (list 'gnus-callback fun)
6876 (and data (list 'gnus-data data))))
6877 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6878 :button-keymap gnus-widget-button-keymap))
6880 ;;; Internal functions:
6882 (defun gnus-article-set-globals ()
6883 (with-current-buffer gnus-summary-buffer
6884 (gnus-set-global-variables)))
6886 (defun gnus-signature-toggle (end)
6887 (gnus-with-article-buffer
6888 (let ((inhibit-point-motion-hooks t))
6889 (if (text-property-any end (point-max) 'article-type 'signature)
6891 (gnus-delete-wash-type 'signature)
6892 (gnus-remove-text-properties-when
6893 'article-type 'signature end (point-max)
6894 (cons 'article-type (cons 'signature
6895 gnus-hidden-properties))))
6896 (gnus-add-wash-type 'signature)
6897 (gnus-add-text-properties-when
6898 'article-type nil end (point-max)
6899 (cons 'article-type (cons 'signature
6900 gnus-hidden-properties)))))
6901 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6902 (gnus-set-mode-line 'article))))
6904 (defun gnus-button-entry ()
6905 ;; Return the first entry in `gnus-button-alist' matching this place.
6906 (let ((alist gnus-button-alist)
6909 (setq entry (pop alist))
6910 (if (looking-at (eval (car entry)))
6915 (defun gnus-button-push (marker)
6916 ;; Push button starting at MARKER.
6919 (let* ((entry (gnus-button-entry))
6920 (inhibit-point-motion-hooks t)
6922 (args (mapcar (lambda (group)
6923 (let ((string (match-string group)))
6924 (set-text-properties
6925 0 (length string) nil string)
6932 (fboundp (symbol-value fun)))
6933 (apply (symbol-value fun) args))
6935 (gnus-message 1 "You must define `%S' to use this button"
6936 (cons fun args)))))))
6938 (defun gnus-parse-news-url (url)
6939 (let (scheme server port group message-id articles)
6942 (goto-char (point-min))
6943 (when (looking-at "\\([A-Za-z]+\\):")
6944 (setq scheme (match-string 1))
6945 (goto-char (match-end 0)))
6946 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
6947 (setq server (match-string 1))
6948 (setq port (if (stringp (match-string 3))
6949 (string-to-number (match-string 3))
6951 (goto-char (match-end 0)))
6954 ((looking-at "\\(.*@.*\\)")
6955 (setq message-id (match-string 1)))
6956 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6957 (setq group (match-string 1)
6958 articles (split-string (match-string 2) "-")))
6959 ((looking-at "\\([^/]+\\)/?")
6960 (setq group (match-string 1)))
6962 (error "Unknown news URL syntax"))))
6963 (list scheme server port group message-id articles)))
6965 (defun gnus-button-handle-news (url)
6967 (destructuring-bind (scheme server port group message-id articles)
6968 (gnus-parse-news-url url)
6972 (set-buffer gnus-summary-buffer)
6974 (let ((gnus-refer-article-method
6975 (nconc (list (list 'nntp server))
6976 gnus-refer-article-method))
6977 (nntp-port-number (or port "nntp")))
6978 (gnus-message 7 "Fetching %s with %s"
6979 message-id gnus-refer-article-method)
6980 (gnus-summary-refer-article message-id))
6981 (gnus-summary-refer-article message-id))))
6983 (gnus-button-fetch-group url)))))
6985 (defun gnus-button-handle-man (url)
6987 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6988 (when (eq gnus-button-man-handler 'woman)
6989 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
6990 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6991 (funcall gnus-button-man-handler url))
6993 (defun gnus-button-handle-info-url (url)
6994 "Fetch an info URL."
6995 (setq url (mm-subst-char-in-string ?+ ?\ url))
6997 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6998 (gnus-info-find-node
6999 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7001 ")" (gnus-url-unhex-string (match-string 2 url)))))
7002 ((string-match "([^)\"]+)[^\"]+" url)
7004 (gnus-replace-in-string
7005 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7006 (gnus-info-find-node url))
7007 (t (error "Can't parse %s" url))))
7009 (defun gnus-button-handle-info-url-gnome (url)
7010 "Fetch GNOME style info URL."
7011 (setq url (mm-subst-char-in-string ?_ ?\ url))
7012 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7013 (gnus-info-find-node
7015 (gnus-url-unhex-string
7016 (match-string 1 url))
7018 (or (gnus-url-unhex-string
7019 (match-string 2 url))
7021 (error "Can't parse %s" url)))
7023 (defun gnus-button-handle-info-url-kde (url)
7024 "Fetch KDE style info URL."
7025 (gnus-info-find-node (gnus-url-unhex-string url)))
7027 (defun gnus-button-handle-info-keystrokes (url)
7028 "Call `info' when pushing the corresponding URL button."
7029 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7034 (defun gnus-button-openpgp (url)
7035 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7037 (mm-url-insert-file-contents-external url)
7038 (pgg-snarf-keys-region (point-min) (point-max))
7039 (pgg-display-output-buffer nil nil nil)))
7041 (defun gnus-button-message-id (message-id)
7043 (with-current-buffer gnus-summary-buffer
7044 (gnus-summary-refer-article message-id)))
7046 (defun gnus-button-fetch-group (address)
7047 "Fetch GROUP specified by ADDRESS."
7048 (if (not (string-match "[:/]" address))
7049 ;; This is just a simple group url.
7050 (gnus-group-read-ephemeral-group address gnus-select-method)
7053 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7055 (error "Can't parse %s" address)
7056 (gnus-group-read-ephemeral-group
7057 (match-string 4 address)
7058 `(nntp ,(match-string 1 address)
7059 (nntp-address ,(match-string 1 address))
7060 (nntp-port-number ,(if (match-end 3)
7061 (match-string 3 address)
7064 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7066 (defun gnus-url-parse-query-string (query &optional downcase)
7067 (let (retval pairs cur key val)
7068 (setq pairs (split-string query "&"))
7070 (setq cur (car pairs)
7072 (if (not (string-match "=" cur))
7074 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7075 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7077 (setq key (downcase key)))
7078 (setq cur (assoc key retval))
7080 (setcdr cur (cons val (cdr cur)))
7081 (setq retval (cons (list key val) retval)))))
7084 (defun gnus-url-mailto (url)
7085 ;; Send mail to someone
7086 (when (string-match "mailto:/*\\(.*\\)" url)
7087 (setq url (substring url (match-beginning 1) nil)))
7088 (let (to args subject func)
7089 (setq args (gnus-url-parse-query-string
7090 (if (string-match "^\\?" url)
7092 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7093 (concat "to=" (match-string 1 url) "&"
7094 (match-string 2 url))
7095 (concat "to=" url)))
7097 subject (cdr-safe (assoc "subject" args)))
7100 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7103 (message-position-on-field (caar args)))
7104 (insert (gnus-replace-in-string
7105 (mapconcat 'identity (reverse (cdar args)) ", ")
7107 (setq args (cdr args)))
7110 (message-goto-subject))))
7112 (defun gnus-button-embedded-url (address)
7113 "Activate ADDRESS with `browse-url'."
7114 (browse-url (gnus-strip-whitespace address)))
7116 ;;; Next/prev buttons in the article buffer.
7118 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7119 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7121 (defvar gnus-prev-page-map
7122 (let ((map (make-sparse-keymap)))
7123 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7124 (define-key map "\r" 'gnus-button-prev-page)
7127 (defvar gnus-next-page-map
7128 (let ((map (make-sparse-keymap)))
7129 (unless (>= emacs-major-version 21)
7130 ;; XEmacs doesn't care.
7131 (set-keymap-parent map gnus-article-mode-map))
7132 (define-key map gnus-mouse-2 'gnus-button-next-page)
7133 (define-key map "\r" 'gnus-button-next-page)
7136 (defun gnus-insert-prev-page-button ()
7138 (inhibit-read-only t))
7140 gnus-prev-page-line-format nil
7141 `(keymap ,gnus-prev-page-map
7143 gnus-callback gnus-article-button-prev-page
7144 article-type annotation))
7145 (widget-convert-button
7147 ;; Exclude a newline.
7150 :action 'gnus-button-prev-page
7151 :button-keymap gnus-prev-page-map)))
7153 (defun gnus-button-next-page (&optional args more-args)
7154 "Go to the next page."
7156 (let ((win (selected-window)))
7157 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7158 (gnus-article-next-page)
7159 (select-window win)))
7161 (defun gnus-button-prev-page (&optional args more-args)
7162 "Go to the prev page."
7164 (let ((win (selected-window)))
7165 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7166 (gnus-article-prev-page)
7167 (select-window win)))
7169 (defun gnus-insert-next-page-button ()
7171 (inhibit-read-only t))
7172 (gnus-eval-format gnus-next-page-line-format nil
7173 `(keymap ,gnus-next-page-map
7175 gnus-callback gnus-article-button-next-page
7176 article-type annotation))
7177 (widget-convert-button
7179 ;; Exclude a newline.
7182 :action 'gnus-button-next-page
7183 :button-keymap gnus-next-page-map)))
7185 (defun gnus-article-button-next-page (arg)
7186 "Go to the next page."
7188 (let ((win (selected-window)))
7189 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7190 (gnus-article-next-page)
7191 (select-window win)))
7193 (defun gnus-article-button-prev-page (arg)
7194 "Go to the prev page."
7196 (let ((win (selected-window)))
7197 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7198 (gnus-article-prev-page)
7199 (select-window win)))
7201 (defvar gnus-decode-header-methods
7202 '(mail-decode-encoded-word-region)
7203 "List of methods used to decode headers.
7205 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7206 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7207 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7208 whose names match REGEXP.
7211 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7212 mail-decode-encoded-word-region
7213 (\"chinese\" . rfc1843-decode-region))
7216 (defvar gnus-decode-header-methods-cache nil)
7218 (defun gnus-multi-decode-header (start end)
7219 "Apply the functions from `gnus-encoded-word-methods' that match."
7220 (unless (and gnus-decode-header-methods-cache
7221 (eq gnus-newsgroup-name
7222 (car gnus-decode-header-methods-cache)))
7223 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7226 (nconc gnus-decode-header-methods-cache (list x))
7227 (if (and gnus-newsgroup-name
7228 (string-match (car x) gnus-newsgroup-name))
7229 (nconc gnus-decode-header-methods-cache
7231 gnus-decode-header-methods))
7232 (let ((xlist gnus-decode-header-methods-cache))
7235 (narrow-to-region start end)
7237 (funcall (pop xlist) (point-min) (point-max))))))
7240 ;;; Treatment top-level handling.
7243 (defun gnus-treat-article (condition &optional part-number total-parts type)
7244 (let ((length (- (point-max) (point-min)))
7245 (alist gnus-treatment-function-alist)
7246 (article-goto-body-goes-to-point-min-p t)
7250 (let ((list gnus-article-treat-types))
7252 (when (string-match (pop list) type)
7253 (throw 'found t)))))))
7254 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7256 (gnus-run-hooks 'gnus-part-display-hook)
7257 (dolist (elem alist)
7260 (when (gnus-buffer-live-p gnus-summary-buffer)
7261 (set-buffer gnus-summary-buffer))
7262 (symbol-value (car elem))))
7263 (when (and (or (consp val)
7265 (gnus-treat-predicate val)
7266 (or (not (get (car elem) 'highlight))
7269 (funcall (cadr elem)))))))
7271 ;; Dynamic variables.
7273 (defvar part-number)
7274 (defvar total-parts)
7279 (defun gnus-treat-predicate (val)
7286 (stringp (car val)))
7287 (apply 'gnus-or (mapcar `(lambda (s)
7288 (string-match s ,(or gnus-newsgroup-name "")))
7291 (let ((pred (pop val)))
7294 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7296 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7298 (not (gnus-treat-predicate (car val))))
7300 (equal (car val) type))
7302 (error "%S is not a valid predicate" pred)))))
7310 (eq part-number total-parts))
7314 (error "%S is not a valid value" val))))
7316 (defun gnus-article-encrypt-body (protocol &optional n)
7317 "Encrypt the article body."
7320 (or gnus-article-encrypt-protocol
7321 (completing-read "Encrypt protocol: "
7322 gnus-article-encrypt-protocol-alist
7324 current-prefix-arg))
7325 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7327 (error "Can't find the encrypt protocol %s" protocol))
7328 (if (member gnus-newsgroup-name '("nndraft:delayed"
7331 (error "Can't encrypt the article in group %s"
7332 gnus-newsgroup-name))
7333 (gnus-summary-iterate n
7335 (set-buffer gnus-summary-buffer)
7336 (let ((mail-parse-charset gnus-newsgroup-charset)
7337 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7338 (summary-buffer gnus-summary-buffer)
7340 (gnus-set-global-variables)
7341 (when (gnus-group-read-only-p)
7342 (error "The current newsgroup does not support article encrypt"))
7343 (gnus-summary-show-article t)
7345 (or (mail-header-references gnus-current-headers) ""))
7346 (set-buffer gnus-article-buffer)
7347 (let* ((inhibit-read-only t)
7349 (mapcar (lambda (field)
7350 (and (save-restriction
7351 (message-narrow-to-head)
7352 (goto-char (point-min))
7353 (search-forward field nil t))
7355 (message-narrow-to-field)
7357 (delete-region (point-min) (point-max))
7359 '("Content-Type:" "Content-Transfer-Encoding:"
7360 "Content-Disposition:"))))
7361 (message-narrow-to-head)
7362 (message-remove-header "MIME-Version")
7363 (goto-char (point-max))
7364 (setq point (point))
7365 (insert (apply 'concat headers))
7367 (narrow-to-region point (point-max))
7368 (let ((message-options message-options))
7369 (message-options-set 'message-sender user-mail-address)
7370 (message-options-set 'message-recipients user-mail-address)
7371 (message-options-set 'message-sign-encrypt 'not)
7373 (goto-char (point-min))
7374 (insert "MIME-Version: 1.0\n")
7376 (gnus-summary-edit-article-done
7377 references nil summary-buffer t))
7378 (when gnus-keep-backlog
7379 (gnus-backlog-remove-article
7380 (car gnus-article-current) (cdr gnus-article-current)))
7382 (when (get-buffer gnus-original-article-buffer)
7383 (set-buffer gnus-original-article-buffer)
7384 (setq gnus-original-article nil)))
7385 (when gnus-use-cache
7386 (gnus-cache-update-article
7387 (car gnus-article-current) (cdr gnus-article-current))))))))
7389 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7390 "The following specs can be used:
7391 %t The security MIME type
7394 %D Details if button is pressed")
7396 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7397 "The following specs can be used:
7398 %t The security MIME type
7401 %D Details if button is pressed")
7403 (defvar gnus-mime-security-button-line-format-alist
7404 '((?t gnus-tmp-type ?s)
7405 (?i gnus-tmp-info ?s)
7406 (?d gnus-tmp-details ?s)
7407 (?D gnus-tmp-pressed-details ?s)))
7409 (defvar gnus-mime-security-button-commands
7410 '((gnus-article-press-button "\r" "Show Detail")
7414 (gnus-mime-security-save-part "o" "Save...")
7423 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
7426 (defvar gnus-mime-security-button-map
7427 (let ((map (make-sparse-keymap)))
7428 (define-key map gnus-mouse-2 'gnus-article-push-button)
7429 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
7430 (dolist (c gnus-mime-security-button-commands)
7431 (define-key map (cadr c) (car c)))
7435 gnus-mime-security-button-menu gnus-mime-security-button-map
7436 "Security button menu."
7440 (unless (eq (car c) 'undefined)
7441 (vector (caddr c) (car c) :enable t)))
7442 gnus-mime-security-button-commands))))
7444 (defun gnus-mime-security-button-menu (event prefix)
7445 "Construct a context-sensitive menu of security commands."
7446 (interactive "e\nP")
7447 (save-window-excursion
7448 (let ((pos (event-start event)))
7449 (select-window (posn-window pos))
7450 (goto-char (posn-point pos))
7451 (gnus-article-check-buffer)
7452 (popup-menu gnus-mime-security-button-menu nil prefix))))
7454 (defvar gnus-mime-security-details-buffer nil)
7456 (defvar gnus-mime-security-button-pressed nil)
7458 (defvar gnus-mime-security-show-details-inline t
7459 "If non-nil, show details in the article buffer.")
7461 (defun gnus-mime-security-verify-or-decrypt (handle)
7462 (mm-remove-parts (cdr handle))
7463 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7464 point (inhibit-read-only t))
7466 (goto-char (car region)))
7468 (narrow-to-region (point) (point))
7469 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7470 (let* ((mm-verify-option 'known)
7471 (mm-decrypt-option 'known)
7472 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7473 (unless (eq nparts (cdr handle))
7474 (mm-destroy-parts (cdr handle))
7475 (setcdr handle nparts))))
7476 (setq point (point))
7477 (gnus-mime-display-security handle)
7478 (goto-char (point-max)))
7480 (delete-region (point) (cdr region))
7481 (set-marker (car region) nil)
7482 (set-marker (cdr region) nil))
7485 (defun gnus-mime-security-show-details (handle)
7486 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7488 (gnus-message 5 "No details.")
7489 (if gnus-mime-security-show-details-inline
7490 (let ((gnus-mime-security-button-pressed
7491 (not (get-text-property (point) 'gnus-mime-details)))
7492 (gnus-mime-security-button-line-format
7493 (get-text-property (point) 'gnus-line-format))
7494 (inhibit-read-only t))
7496 (while (eq (get-text-property (point) 'gnus-line-format)
7497 gnus-mime-security-button-line-format)
7501 (narrow-to-region (point) (point))
7502 (gnus-insert-mime-security-button handle))
7503 (delete-region (point)
7504 (or (text-property-not-all
7507 gnus-mime-security-button-line-format)
7510 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7511 (with-current-buffer gnus-mime-security-details-buffer
7514 (setq gnus-mime-security-details-buffer
7515 (gnus-get-buffer-create "*MIME Security Details*")))
7516 (with-current-buffer gnus-mime-security-details-buffer
7518 (goto-char (point-min)))
7519 (pop-to-buffer gnus-mime-security-details-buffer)))))
7521 (defun gnus-mime-security-press-button (handle)
7523 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7524 (gnus-mime-security-show-details handle)
7525 (gnus-mime-security-verify-or-decrypt handle))))
7527 (defun gnus-insert-mime-security-button (handle &optional displayed)
7528 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7531 (or (nth 2 (assoc protocol mm-verify-function-alist))
7532 (nth 2 (assoc protocol mm-decrypt-function-alist))
7534 (if (equal (car handle) "multipart/signed")
7535 " Signed" " Encrypted")
7538 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7541 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7542 gnus-tmp-pressed-details
7544 (setq gnus-tmp-details
7545 (if gnus-tmp-details
7546 (concat "\n" gnus-tmp-details)
7548 (setq gnus-tmp-pressed-details
7549 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7554 gnus-mime-security-button-line-format
7555 gnus-mime-security-button-line-format-alist
7556 `(keymap ,gnus-mime-security-button-map
7557 gnus-callback gnus-mime-security-press-button
7558 gnus-line-format ,gnus-mime-security-button-line-format
7559 gnus-mime-details ,gnus-mime-security-button-pressed
7560 article-type annotation
7563 ;; Exclude a newline.
7566 (widget-convert-button
7569 :action 'gnus-widget-press-button
7570 :button-keymap gnus-mime-security-button-map
7572 (lambda (widget/window &optional overlay pos)
7573 ;; Needed to properly clear the message due to a bug in
7574 ;; wid-edit (XEmacs only).
7575 (when (boundp 'help-echo-owns-message)
7576 (setq help-echo-owns-message t))
7578 "%S: show detail; %S: more options"
7579 (aref gnus-mouse-2 0)
7580 (aref gnus-down-mouse-3 0))))))
7582 (defun gnus-mime-display-security (handle)
7584 (narrow-to-region (point) (point))
7585 (unless (gnus-unbuttonized-mime-type-p (car handle))
7586 (gnus-insert-mime-security-button handle))
7587 (gnus-mime-display-part (cadr handle))
7590 (unless (gnus-unbuttonized-mime-type-p (car handle))
7591 (let ((gnus-mime-security-button-line-format
7592 gnus-mime-security-button-end-line-format))
7593 (gnus-insert-mime-security-button handle)))
7594 (mm-set-handle-multipart-parameter
7596 (cons (set-marker (make-marker) (point-min))
7597 (set-marker (make-marker) (point-max))))))
7599 (defun gnus-mime-security-run-function (function)
7600 "Run FUNCTION with the security part under point."
7601 (gnus-article-check-buffer)
7602 (let ((data (get-text-property (point) 'gnus-data))
7604 (when (and (stringp (car-safe data))
7605 (setq buffer (mm-handle-multipart-original-buffer data))
7606 (setq handle (cadr data)))
7607 (if (bufferp (mm-handle-buffer handle))
7609 (setq handle (cons buffer (copy-sequence (cdr handle))))
7610 (mm-handle-set-undisplayer handle nil))
7611 (setq handle (mm-make-handle
7613 (mm-handle-multipart-ctl-parameter handle 'protocol)
7614 nil nil nil nil nil nil)))
7615 (funcall function handle))))
7617 (defun gnus-mime-security-save-part ()
7618 "Save the security part under point."
7620 (gnus-mime-security-run-function 'mm-save-part))
7622 (defun gnus-mime-security-pipe-part ()
7623 "Pipe the security part under point to a process."
7625 (gnus-mime-security-run-function 'mm-pipe-part))
7631 (run-hooks 'gnus-art-load-hook)
7633 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7634 ;;; gnus-art.el ends here