1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 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")
57 (defgroup gnus-article nil
59 :link '(custom-manual "(gnus)Article Buffer")
62 (defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
67 (defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
72 (defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
78 (defgroup gnus-article-signature nil
80 :link '(custom-manual "(gnus)Article Signature")
83 (defgroup gnus-article-headers nil
85 :link '(custom-manual "(gnus)Hiding Headers")
88 (defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
93 (defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
98 (defgroup gnus-article-saving nil
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
103 (defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
108 (defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
113 (defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
118 (defcustom gnus-ignored-headers
121 (concat "^" header ":"))
122 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128 "X-Attribution" "X-Originating-IP" "Delivered-To"
129 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145 "List-[A-Za-z]+" "X-Listprocessor-Version"
146 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148 "X-Received" "Content-length" "X-precedence"
149 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154 "X-Content-length" "X-Posting-Agent" "Original-Received"
155 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
159 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
160 "*All headers that start with this regexp will be hidden.
161 This variable can also be a list of regexps of headers to be ignored.
162 If `gnus-visible-headers' is non-nil, this variable will be ignored."
163 :type '(choice :custom-show nil
166 :group 'gnus-article-hiding)
168 (defcustom gnus-visible-headers
169 "^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:"
170 "*All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
173 :type '(repeat :value-to-internal (lambda (widget value)
174 (custom-split-regexp-maybe value))
175 :match (lambda (widget value)
177 (widget-editable-list-match widget value)))
179 :group 'gnus-article-hiding)
181 (defcustom gnus-sorted-header-list
182 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
183 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
184 "*This variable is a list of regular expressions.
185 If it is non-nil, headers that match the regular expressions will
186 be placed first in the article buffer in the sequence specified by
188 :type '(repeat regexp)
189 :group 'gnus-article-hiding)
191 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
192 "Headers that are only to be displayed if they have interesting data.
193 Possible values in this list are:
195 'empty Headers with no content.
196 'newsgroups Newsgroup identical to Gnus group.
197 'to-address To identical to To-address.
198 'to-list To identical to To-list.
199 'cc-list CC identical to To-list.
200 'followup-to Followup-to identical to Newsgroups.
201 'reply-to Reply-to identical to From.
202 'date Date less than four days old.
203 'long-to To and/or Cc longer than 1024 characters.
204 'many-to Multiple To and/or Cc."
205 :type '(set (const :tag "Headers with no content." empty)
206 (const :tag "Newsgroups identical to Gnus group." newsgroups)
207 (const :tag "To identical to To-address." to-address)
208 (const :tag "To identical to To-list." to-list)
209 (const :tag "CC identical to To-list." cc-list)
210 (const :tag "Followup-to identical to Newsgroups." followup-to)
211 (const :tag "Reply-to identical to From." reply-to)
212 (const :tag "Date less than four days old." date)
213 (const :tag "To and/or Cc longer than 1024 characters." long-to)
214 (const :tag "Multiple To and/or Cc headers." many-to))
215 :group 'gnus-article-hiding)
217 (defcustom gnus-article-skip-boring nil
218 "Skip over text that is not worth reading.
219 By default, if you set this t, then Gnus will display citations and
220 signatures, but will never scroll down to show you a page consisting
221 only of boring text. Boring text is controlled by
222 `gnus-article-boring-faces'."
225 :group 'gnus-article-hiding)
227 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
228 "Regexp matching signature separator.
229 This can also be a list of regexps. In that case, it will be checked
230 from head to tail looking for a separator. Searches will be done from
231 the end of the buffer."
232 :type '(repeat string)
233 :group 'gnus-article-signature)
235 (defcustom gnus-signature-limit nil
236 "Provide a limit to what is considered a signature.
237 If it is a number, no signature may not be longer (in characters) than
238 that number. If it is a floating point number, no signature may be
239 longer (in lines) than that number. If it is a function, the function
240 will be called without any parameters, and if it returns nil, there is
241 no signature in the buffer. If it is a string, it will be used as a
242 regexp. If it matches, the text in question is not a signature.
244 This can also be a list of the above values."
245 :type '(choice (const nil)
248 (function :value fun)
249 (regexp :value ".*"))
250 :group 'gnus-article-signature)
252 (defcustom gnus-hidden-properties '(invisible t intangible t)
253 "Property list to use for hiding text."
255 :group 'gnus-article-hiding)
257 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
258 ;; frames in a session.
259 (defcustom gnus-article-x-face-command
260 (if (featurep 'xemacs)
261 (if (or (gnus-image-type-available-p 'xface)
262 (gnus-image-type-available-p 'pbm))
263 'gnus-display-x-face-in-from
264 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
265 (if (gnus-image-type-available-p 'pbm)
266 'gnus-display-x-face-in-from
267 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
269 "*String or function to be executed to display an X-Face header.
270 If it is a string, the command will be executed in a sub-shell
271 asynchronously. The compressed face will be piped to this command."
272 :type `(choice string
273 (function-item gnus-display-x-face-in-from)
277 :group 'gnus-article-washing)
279 (defcustom gnus-article-x-face-too-ugly nil
280 "Regexp matching posters whose face shouldn't be shown automatically."
281 :type '(choice regexp (const nil))
282 :group 'gnus-article-washing)
284 (defcustom gnus-article-banner-alist nil
285 "Banner alist for stripping.
287 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
289 :type '(repeat (cons symbol regexp))
290 :group 'gnus-article-washing)
292 (gnus-define-group-parameter
295 "Alist of regexps (to match group names) and banner."
296 :variable-group gnus-article-washing
298 '(choice :tag "Banner"
300 (const :tag "Remove signature" signature)
301 (symbol :tag "Item in `gnus-article-banner-alist'" none)
303 (const :tag "None" nil))
305 "If non-nil, specify how to remove `banners' from articles.
307 Symbol `signature' means to remove signatures delimited by
308 `gnus-signature-separator'. Any other symbol is used to look up a
309 regular expression to match the banner in `gnus-article-banner-alist'.
310 A string is used as a regular expression to match the banner
313 (defcustom gnus-article-address-banner-alist nil
314 "Alist of mail addresses and banners.
315 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
316 to match a mail address in the From: header, BANNER is one of a symbol
317 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
318 If ADDRESS matches author's mail address, it will remove things like
319 advertisements. For example:
321 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
325 (regexp :tag "Address")
326 (choice :tag "Banner" :value nil
327 (const :tag "Remove signature" signature)
328 (symbol :tag "Item in `gnus-article-banner-alist'" none)
330 (const :tag "None" nil))))
332 :group 'gnus-article-washing)
334 (defmacro gnus-emphasis-custom-with-format (&rest body)
336 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
337 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
340 (defun gnus-emphasis-custom-value-to-external (value)
341 (gnus-emphasis-custom-with-format
342 (if (consp (car value))
343 (list (format format (car (car value)) (cdr (car value)))
345 (if (nth 1 value) 2 3)
349 (defun gnus-emphasis-custom-value-to-internal (value)
350 (gnus-emphasis-custom-with-format
351 (let ((regexp (concat "\\`"
352 (format (regexp-quote format)
353 "\\([^()]+\\)" "\\([^()]+\\)")
356 (if (string-match regexp (setq pattern (car value)))
357 (list (cons (match-string 1 pattern) (match-string 2 pattern))
362 (defcustom gnus-emphasis-alist
364 '(("\\*" "\\*" bold nil 2)
367 ("_/" "/_" underline-italic)
368 ("_\\*" "\\*_" underline-bold)
369 ("\\*/" "/\\*" bold-italic)
370 ("_\\*/" "/\\*_" underline-bold-italic))))
372 (gnus-emphasis-custom-with-format
373 (mapcar (lambda (spec)
374 (list (format format (car spec) (cadr spec))
377 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
379 '(;; I've never seen anyone use this strikethru convention whereas I've
380 ;; several times seen it triggered by normal text. --Stef
381 ;; Miles suggests that this form is sometimes used but for italics,
382 ;; so maybe we should map it to `italic'.
383 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
384 ;; 2 3 gnus-emphasis-strikethru)
385 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
386 2 3 gnus-emphasis-underline))))
387 "*Alist that says how to fontify certain phrases.
388 Each item looks like this:
390 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
392 The first element is a regular expression to be matched. The second
393 is a number that says what regular expression grouping used to find
394 the entire emphasized word. The third is a number that says what
395 regexp grouping should be displayed and highlighted. The fourth
396 is the face used for highlighting."
400 :format "%[Customizing Style%]\n%v"
402 (group :tag "Default"
403 :value ("" 0 0 default)
406 (let ((value (widget-get
407 (cadr (widget-get (widget-get widget :parent)
410 (if (not (eq (nth 2 value) 'default))
414 (gnus-emphasis-custom-value-to-external value))))
415 (widget-group-value-create widget))
417 (integer :format "Match group: %v")
418 (integer :format "Emphasize group: %v")
421 :value (("_" . "_") nil default)
423 (regexp :format "Start regexp: %v")
424 (regexp :format "End regexp: %v"))
425 (boolean :format "Show start and end patterns: %[%v%]\n"
426 :on " On " :off " Off ")
428 :get (lambda (symbol)
429 (mapcar 'gnus-emphasis-custom-value-to-internal
430 (default-value symbol)))
431 :set (lambda (symbol value)
432 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
434 :group 'gnus-article-emphasis)
436 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
437 "A regexp to describe whitespace which should not be emphasized.
438 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
439 The former avoids underlining of leading and trailing whitespace,
440 and the latter avoids underlining any whitespace at all."
442 :group 'gnus-article-emphasis
445 (defface gnus-emphasis-bold '((t (:bold t)))
446 "Face used for displaying strong emphasized text (*word*)."
447 :group 'gnus-article-emphasis)
449 (defface gnus-emphasis-italic '((t (:italic t)))
450 "Face used for displaying italic emphasized text (/word/)."
451 :group 'gnus-article-emphasis)
453 (defface gnus-emphasis-underline '((t (:underline t)))
454 "Face used for displaying underlined emphasized text (_word_)."
455 :group 'gnus-article-emphasis)
457 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
458 "Face used for displaying underlined bold emphasized text (_*word*_)."
459 :group 'gnus-article-emphasis)
461 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
462 "Face used for displaying underlined italic emphasized text (_/word/_)."
463 :group 'gnus-article-emphasis)
465 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
466 "Face used for displaying bold italic emphasized text (/*word*/)."
467 :group 'gnus-article-emphasis)
469 (defface gnus-emphasis-underline-bold-italic
470 '((t (:bold t :italic t :underline t)))
471 "Face used for displaying underlined bold italic emphasized text.
472 Example: (_/*word*/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
476 '((t (:strikethru t)))
477 '((t (:strike-through t))))
478 "Face used for displaying strike-through text (-word-)."
479 :group 'gnus-article-emphasis)
481 (defface gnus-emphasis-highlight-words
482 '((t (:background "black" :foreground "yellow")))
483 "Face used for displaying highlighted words."
484 :group 'gnus-article-emphasis)
486 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
487 "Format for display of Date headers in article bodies.
488 See `format-time-string' for the possible values.
490 The variable can also be function, which should return a complete Date
491 header. The function is called with one argument, the time, which can
492 be fed to `format-time-string'."
493 :type '(choice string function)
494 :link '(custom-manual "(gnus)Article Date")
495 :group 'gnus-article-washing)
497 (defcustom gnus-save-all-headers t
498 "*If non-nil, don't remove any headers before saving."
499 :group 'gnus-article-saving
502 (defcustom gnus-prompt-before-saving 'always
503 "*This variable says how much prompting is to be done when saving articles.
504 If it is nil, no prompting will be done, and the articles will be
505 saved to the default files. If this variable is `always', each and
506 every article that is saved will be preceded by a prompt, even when
507 saving large batches of articles. If this variable is neither nil not
508 `always', there the user will be prompted once for a file name for
509 each invocation of the saving commands."
510 :group 'gnus-article-saving
511 :type '(choice (item always)
512 (item :tag "never" nil)
513 (sexp :tag "once" :format "%t\n" :value t)))
515 (defcustom gnus-saved-headers gnus-visible-headers
516 "Headers to keep if `gnus-save-all-headers' is nil.
517 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
518 If that variable is nil, however, all headers that match this regexp
519 will be kept while the rest will be deleted before saving."
520 :group 'gnus-article-saving
523 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
524 "A function to save articles in your favourite format.
525 The function must be interactively callable (in other words, it must
526 be an Emacs command).
528 Gnus provides the following functions:
530 * gnus-summary-save-in-rmail (Rmail format)
531 * gnus-summary-save-in-mail (Unix mail format)
532 * gnus-summary-save-in-folder (MH folder)
533 * gnus-summary-save-in-file (article format)
534 * gnus-summary-save-body-in-file (article body)
535 * gnus-summary-save-in-vm (use VM's folder format)
536 * gnus-summary-write-to-file (article format -- overwrite)."
537 :group 'gnus-article-saving
538 :type '(radio (function-item gnus-summary-save-in-rmail)
539 (function-item gnus-summary-save-in-mail)
540 (function-item gnus-summary-save-in-folder)
541 (function-item gnus-summary-save-in-file)
542 (function-item gnus-summary-save-body-in-file)
543 (function-item gnus-summary-save-in-vm)
544 (function-item gnus-summary-write-to-file)))
546 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
547 "A function generating a file name to save articles in Rmail format.
548 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
549 :group 'gnus-article-saving
552 (defcustom gnus-mail-save-name 'gnus-plain-save-name
553 "A function generating a file name to save articles in Unix mail format.
554 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
555 :group 'gnus-article-saving
558 (defcustom gnus-folder-save-name 'gnus-folder-save-name
559 "A function generating a file name to save articles in MH folder.
560 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
561 :group 'gnus-article-saving
564 (defcustom gnus-file-save-name 'gnus-numeric-save-name
565 "A function generating a file name to save articles in article format.
566 The function is called with NEWSGROUP, HEADERS, and optional
568 :group 'gnus-article-saving
571 (defcustom gnus-split-methods
572 '((gnus-article-archive-name)
573 (gnus-article-nndoc-name))
574 "*Variable used to suggest where articles are to be saved.
575 For instance, if you would like to save articles related to Gnus in
576 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
577 you could set this variable to something like:
579 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
580 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
582 This variable is an alist where the key is the match and the
583 value is a list of possible files to save in if the match is
586 If the match is a string, it is used as a regexp match on the
587 article. If the match is a symbol, that symbol will be funcalled
588 from the buffer of the article to be saved with the newsgroup as
589 the parameter. If it is a list, it will be evaled in the same
592 If this form or function returns a string, this string will be
593 used as a possible file name; and if it returns a non-nil list,
594 that list will be used as possible file names."
595 :group 'gnus-article-saving
596 :type '(repeat (choice (list :value (fun) function)
597 (cons :value ("" "") regexp (repeat string))
600 (defcustom gnus-page-delimiter "^\^L"
601 "*Regexp describing what to use as article page delimiters.
602 The default value is \"^\^L\", which is a form linefeed at the
603 beginning of a line."
605 :group 'gnus-article-various)
607 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
608 "*The format specification for the article mode line.
609 See `gnus-summary-mode-line-format' for a closer description.
611 The following additional specs are available:
613 %w The article washing status.
614 %m The number of MIME parts in the article."
616 :group 'gnus-article-various)
618 (defcustom gnus-article-mode-hook nil
619 "*A hook for Gnus article mode."
621 :group 'gnus-article-various)
623 (when (featurep 'xemacs)
624 ;; Extracted from gnus-xmas-define in order to preserve user settings
625 (when (fboundp 'turn-off-scroll-in-place)
626 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
627 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
628 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
630 (defcustom gnus-article-menu-hook nil
631 "*Hook run after the creation of the article mode menu."
633 :group 'gnus-article-various)
635 (defcustom gnus-article-prepare-hook nil
636 "*A hook called after an article has been prepared in the article buffer."
638 :group 'gnus-article-various)
640 (defcustom gnus-copy-article-ignored-headers nil
641 "List of headers to be removed when copying an article.
642 Each element is a regular expression."
643 :version "23.0" ;; No Gnus
644 :type '(repeat regexp)
645 :group 'gnus-article-various)
647 (make-obsolete-variable 'gnus-article-hide-pgp-hook
648 "This variable is obsolete in Gnus 5.10.")
650 (defcustom gnus-article-button-face 'bold
651 "Face used for highlighting buttons in the article buffer.
653 An article button is a piece of text that you can activate by pressing
654 `RET' or `mouse-2' above it."
656 :group 'gnus-article-buttons)
658 (defcustom gnus-article-mouse-face 'highlight
659 "Face used for mouse highlighting in the article buffer.
661 Article buttons will be displayed in this face when the cursor is
664 :group 'gnus-article-buttons)
666 (defcustom gnus-signature-face 'gnus-signature
667 "Face used for highlighting a signature in the article buffer.
668 Obsolete; use the face `gnus-signature' for customizations instead."
670 :group 'gnus-article-highlight
671 :group 'gnus-article-signature)
673 (defface gnus-signature
676 "Face used for highlighting a signature in the article buffer."
677 :group 'gnus-article-highlight
678 :group 'gnus-article-signature)
679 ;; backward-compatibility alias
680 (put 'gnus-signature-face 'face-alias 'gnus-signature)
682 (defface gnus-header-from
685 (:foreground "spring green"))
688 (:foreground "red3"))
691 "Face used for displaying from headers."
692 :group 'gnus-article-headers
693 :group 'gnus-article-highlight)
694 ;; backward-compatibility alias
695 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
697 (defface gnus-header-subject
700 (:foreground "SeaGreen3"))
703 (:foreground "red4"))
705 (:bold t :italic t)))
706 "Face used for displaying subject headers."
707 :group 'gnus-article-headers
708 :group 'gnus-article-highlight)
709 ;; backward-compatibility alias
710 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
712 (defface gnus-header-newsgroups
715 (:foreground "yellow" :italic t))
718 (:foreground "MidnightBlue" :italic t))
721 "Face used for displaying newsgroups headers.
722 In the default setup this face is only used for crossposted
724 :group 'gnus-article-headers
725 :group 'gnus-article-highlight)
726 ;; backward-compatibility alias
727 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
729 (defface gnus-header-name
732 (:foreground "SeaGreen"))
735 (:foreground "maroon"))
738 "Face used for displaying header names."
739 :group 'gnus-article-headers
740 :group 'gnus-article-highlight)
741 ;; backward-compatibility alias
742 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
744 (defface gnus-header-content
747 (:foreground "forest green" :italic t))
750 (:foreground "indianred4" :italic t))
752 (:italic t))) "Face used for displaying header content."
753 :group 'gnus-article-headers
754 :group 'gnus-article-highlight)
755 ;; backward-compatibility alias
756 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
758 (defcustom gnus-header-face-alist
759 '(("From" nil gnus-header-from)
760 ("Subject" nil gnus-header-subject)
761 ("Newsgroups:.*," nil gnus-header-newsgroups)
762 ("" gnus-header-name gnus-header-content))
763 "*Controls highlighting of article headers.
765 An alist of the form (HEADER NAME CONTENT).
767 HEADER is a regular expression which should match the name of a
768 header and NAME and CONTENT are either face names or nil.
770 The name of each header field will be displayed using the face
771 specified by the first element in the list where HEADER matches
772 the header name and NAME is non-nil. Similarly, the content will
773 be displayed by the first non-nil matching CONTENT face."
774 :group 'gnus-article-headers
775 :group 'gnus-article-highlight
776 :type '(repeat (list (regexp :tag "Header")
778 (item :tag "skip" nil)
779 (face :value default))
780 (choice :tag "Content"
781 (item :tag "skip" nil)
782 (face :value default)))))
784 (defcustom gnus-article-decode-hook
785 '(article-decode-charset article-decode-encoded-words
786 article-decode-group-name article-decode-idna-rhs)
787 "*Hook run to decode charsets in articles."
788 :group 'gnus-article-headers
791 (defcustom gnus-display-mime-function 'gnus-display-mime
792 "Function to display MIME articles."
793 :group 'gnus-article-mime
796 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
797 "Function used to decode headers.")
799 (defvar gnus-article-dumbquotes-map
819 "Table for MS-to-Latin1 translation.")
821 (defcustom gnus-ignored-mime-types nil
822 "List of MIME types that should be ignored by Gnus."
824 :group 'gnus-article-mime
825 :type '(repeat regexp))
827 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
828 "List of MIME types that should not be given buttons when rendered inline.
829 See also `gnus-buttonized-mime-types' which may override this variable.
830 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
832 :group 'gnus-article-mime
833 :type '(repeat regexp))
835 (defcustom gnus-buttonized-mime-types nil
836 "List of MIME types that should be given buttons when rendered inline.
837 If set, this variable overrides `gnus-unbuttonized-mime-types'.
838 To see e.g. security buttons you could set this to
839 `(\"multipart/signed\")'.
840 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
842 :group 'gnus-article-mime
843 :type '(repeat regexp))
845 (defcustom gnus-inhibit-mime-unbuttonizing nil
846 "If non-nil, all MIME parts get buttons.
847 When nil (the default value), then some MIME parts do not get buttons,
848 as described by the variables `gnus-buttonized-mime-types' and
849 `gnus-unbuttonized-mime-types'."
851 :group 'gnus-article-mime
854 (defcustom gnus-body-boundary-delimiter "_"
855 "String used to delimit header and body.
856 This variable is used by `gnus-article-treat-body-boundary' which can
857 be controlled by `gnus-treat-body-boundary'."
859 :group 'gnus-article-various
860 :type '(choice (item :tag "None" :value nil)
863 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
865 "Defines the location of the faces database.
866 For information on obtaining this database of pretty pictures, please
867 see http://www.cs.indiana.edu/picons/ftp/index.html"
869 :type '(repeat directory)
870 :link '(url-link :tag "download"
871 "http://www.cs.indiana.edu/picons/ftp/index.html")
872 :link '(custom-manual "(gnus)Picons")
875 (defun gnus-picons-installed-p ()
876 "Say whether picons are installed on your machine."
877 (let ((installed nil))
878 (dolist (database gnus-picon-databases)
879 (when (file-exists-p database)
883 (defcustom gnus-article-mime-part-function nil
884 "Function called with a MIME handle as the argument.
885 This is meant for people who want to do something automatic based
886 on parts -- for instance, adding Vcard info to a database."
887 :group 'gnus-article-mime
888 :type '(choice (const nil)
891 (defcustom gnus-mime-multipart-functions nil
892 "An alist of MIME types to functions to display them."
894 :group 'gnus-article-mime
895 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
897 (defcustom gnus-article-date-lapsed-new-header nil
898 "Whether the X-Sent and Date headers can coexist.
899 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
900 either replace the old \"Date:\" header (if this variable is nil), or
901 be added below it (otherwise)."
903 :group 'gnus-article-headers
906 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
907 "Function called with a MIME handle as the argument.
908 This is meant for people who want to view first matched part.
909 For `undisplayed-alternative' (default), the first undisplayed
910 part or alternative part is used. For `undisplayed', the first
911 undisplayed part is used. For a function, the first part which
912 the function return t is used. For nil, the first part is
915 :group 'gnus-article-mime
917 (item :tag "first" :value nil)
918 (item :tag "undisplayed" :value undisplayed)
919 (item :tag "undisplayed or alternative"
920 :value undisplayed-alternative)
923 (defcustom gnus-mime-action-alist
924 '(("save to file" . gnus-mime-save-part)
925 ("save and strip" . gnus-mime-save-part-and-strip)
926 ("replace with file" . gnus-mime-replace-part)
927 ("delete part" . gnus-mime-delete-part)
928 ("display as text" . gnus-mime-inline-part)
929 ("view the part" . gnus-mime-view-part)
930 ("pipe to command" . gnus-mime-pipe-part)
931 ("toggle display" . gnus-article-press-button)
932 ("toggle display" . gnus-article-view-part-as-charset)
933 ("view as type" . gnus-mime-view-part-as-type)
934 ("view internally" . gnus-mime-view-part-internally)
935 ("view externally" . gnus-mime-view-part-externally))
936 "An alist of actions that run on the MIME attachment."
937 :group 'gnus-article-mime
938 :type '(repeat (cons (string :tag "name")
941 (defcustom gnus-auto-select-part 1
942 "Advance to next MIME part when deleting or stripping parts.
944 When 0, point will be placed on the same part as before. When
945 positive (negative), move point forward (backwards) this many
946 parts. When nil, redisplay article."
947 :version "23.0" ;; No Gnus
948 :group 'gnus-article-mime
949 :type '(choice (const nil :tag "Redisplay article.")
950 (const 1 :tag "Next part.")
951 (const 0 :tag "Current part.")
955 ;;; The treatment variables
958 (defvar gnus-part-display-hook nil
959 "Hook called on parts that are to receive treatment.")
961 (defvar gnus-article-treat-custom
962 '(choice (const :tag "Off" nil)
964 (const :tag "Header" head)
965 (const :tag "First" first)
966 (const :tag "Last" last)
967 (integer :tag "Less")
968 (repeat :tag "Groups" regexp)
969 (sexp :tag "Predicate")))
971 (defvar gnus-article-treat-head-custom
972 '(choice (const :tag "Off" nil)
973 (const :tag "Header" head)))
975 (defvar gnus-article-treat-types '("text/plain")
978 (defvar gnus-inhibit-treatment nil
979 "Whether to inhibit treatment.")
981 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
982 "Highlight the signature.
983 Valid values are nil, t, `head', `first', `last', an integer or a
984 predicate. See Info node `(gnus)Customizing Articles'."
985 :group 'gnus-article-treat
986 :link '(custom-manual "(gnus)Customizing Articles")
987 :type gnus-article-treat-custom)
988 (put 'gnus-treat-highlight-signature 'highlight t)
990 (defcustom gnus-treat-buttonize 100000
992 Valid values are nil, t, `head', `first', `last', an integer or a
993 predicate. See Info node `(gnus)Customizing Articles'."
994 :group 'gnus-article-treat
995 :link '(custom-manual "(gnus)Customizing Articles")
996 :type gnus-article-treat-custom)
997 (put 'gnus-treat-buttonize 'highlight t)
999 (defcustom gnus-treat-buttonize-head 'head
1000 "Add buttons to the head.
1001 Valid values are nil, t, `head', `first', `last', an integer or a
1002 predicate. See Info node `(gnus)Customizing Articles'."
1003 :group 'gnus-article-treat
1004 :link '(custom-manual "(gnus)Customizing Articles")
1005 :type gnus-article-treat-head-custom)
1006 (put 'gnus-treat-buttonize-head 'highlight t)
1008 (defcustom gnus-treat-emphasize
1009 (and (or window-system
1013 Valid values are nil, t, `head', `first', `last', an integer or a
1014 predicate. See Info node `(gnus)Customizing Articles'."
1015 :group 'gnus-article-treat
1016 :link '(custom-manual "(gnus)Customizing Articles")
1017 :type gnus-article-treat-custom)
1018 (put 'gnus-treat-emphasize 'highlight t)
1020 (defcustom gnus-treat-strip-cr nil
1021 "Remove carriage returns.
1022 Valid values are nil, t, `head', `first', `last', an integer or a
1023 predicate. See Info node `(gnus)Customizing Articles'."
1025 :group 'gnus-article-treat
1026 :link '(custom-manual "(gnus)Customizing Articles")
1027 :type gnus-article-treat-custom)
1029 (defcustom gnus-treat-unsplit-urls nil
1030 "Remove newlines from within URLs.
1031 Valid values are nil, t, `head', `first', `last', an integer or a
1032 predicate. See Info node `(gnus)Customizing Articles'."
1034 :group 'gnus-article-treat
1035 :link '(custom-manual "(gnus)Customizing Articles")
1036 :type gnus-article-treat-custom)
1038 (defcustom gnus-treat-leading-whitespace nil
1039 "Remove leading whitespace in headers.
1040 Valid values are nil, t, `head', `first', `last', an integer or a
1041 predicate. See Info node `(gnus)Customizing Articles'."
1043 :group 'gnus-article-treat
1044 :link '(custom-manual "(gnus)Customizing Articles")
1045 :type gnus-article-treat-custom)
1047 (defcustom gnus-treat-hide-headers 'head
1049 Valid values are nil, t, `head', `first', `last', an integer or a
1050 predicate. See Info node `(gnus)Customizing Articles'."
1051 :group 'gnus-article-treat
1052 :link '(custom-manual "(gnus)Customizing Articles")
1053 :type gnus-article-treat-head-custom)
1055 (defcustom gnus-treat-hide-boring-headers nil
1056 "Hide boring headers.
1057 Valid values are nil, t, `head', `first', `last', an integer or a
1058 predicate. See Info node `(gnus)Customizing Articles'."
1059 :group 'gnus-article-treat
1060 :link '(custom-manual "(gnus)Customizing Articles")
1061 :type gnus-article-treat-head-custom)
1063 (defcustom gnus-treat-hide-signature nil
1064 "Hide the signature.
1065 Valid values are nil, t, `head', `first', `last', an integer or a
1066 predicate. See Info node `(gnus)Customizing Articles'."
1067 :group 'gnus-article-treat
1068 :link '(custom-manual "(gnus)Customizing Articles")
1069 :type gnus-article-treat-custom)
1071 (defcustom gnus-treat-fill-article nil
1073 Valid values are nil, t, `head', `first', `last', an integer or a
1074 predicate. See Info node `(gnus)Customizing Articles'."
1075 :group 'gnus-article-treat
1076 :link '(custom-manual "(gnus)Customizing Articles")
1077 :type gnus-article-treat-custom)
1079 (defcustom gnus-treat-hide-citation nil
1081 Valid values are nil, t, `head', `first', `last', an integer or a
1082 predicate. See Info node `(gnus)Customizing Articles'."
1083 :group 'gnus-article-treat
1084 :link '(custom-manual "(gnus)Customizing Articles")
1085 :type gnus-article-treat-custom)
1087 (defcustom gnus-treat-hide-citation-maybe nil
1089 Valid values are nil, t, `head', `first', `last', an integer or a
1090 predicate. See Info node `(gnus)Customizing Articles'."
1091 :group 'gnus-article-treat
1092 :link '(custom-manual "(gnus)Customizing Articles")
1093 :type gnus-article-treat-custom)
1095 (defcustom gnus-treat-strip-list-identifiers 'head
1096 "Strip list identifiers from `gnus-list-identifiers`.
1097 Valid values are nil, t, `head', `first', `last', an integer or a
1098 predicate. See Info node `(gnus)Customizing Articles'."
1100 :group 'gnus-article-treat
1101 :link '(custom-manual "(gnus)Customizing Articles")
1102 :type gnus-article-treat-custom)
1104 (make-obsolete-variable 'gnus-treat-strip-pgp
1105 "This option is obsolete in Gnus 5.10.")
1107 (defcustom gnus-treat-strip-pem nil
1108 "Strip PEM signatures.
1109 Valid values are nil, t, `head', `first', `last', an integer or a
1110 predicate. See Info node `(gnus)Customizing Articles'."
1111 :group 'gnus-article-treat
1112 :link '(custom-manual "(gnus)Customizing Articles")
1113 :type gnus-article-treat-custom)
1115 (defcustom gnus-treat-strip-banner t
1116 "Strip banners from articles.
1117 The banner to be stripped is specified in the `banner' group parameter.
1118 Valid values are nil, t, `head', `first', `last', an integer or a
1119 predicate. See Info node `(gnus)Customizing Articles'."
1120 :group 'gnus-article-treat
1121 :link '(custom-manual "(gnus)Customizing Articles")
1122 :type gnus-article-treat-custom)
1124 (defcustom gnus-treat-highlight-headers 'head
1125 "Highlight the headers.
1126 Valid values are nil, t, `head', `first', `last', an integer or a
1127 predicate. See Info node `(gnus)Customizing Articles'."
1128 :group 'gnus-article-treat
1129 :link '(custom-manual "(gnus)Customizing Articles")
1130 :type gnus-article-treat-head-custom)
1131 (put 'gnus-treat-highlight-headers 'highlight t)
1133 (defcustom gnus-treat-highlight-citation t
1134 "Highlight cited text.
1135 Valid values are nil, t, `head', `first', `last', an integer or a
1136 predicate. See Info node `(gnus)Customizing Articles'."
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-custom)
1140 (put 'gnus-treat-highlight-citation 'highlight t)
1142 (defcustom gnus-treat-date-ut nil
1143 "Display the Date in UT (GMT).
1144 Valid values are nil, t, `head', `first', `last', an integer or a
1145 predicate. See Info node `(gnus)Customizing Articles'."
1146 :group 'gnus-article-treat
1147 :link '(custom-manual "(gnus)Customizing Articles")
1148 :type gnus-article-treat-head-custom)
1150 (defcustom gnus-treat-date-local nil
1151 "Display the Date in the local timezone.
1152 Valid values are nil, t, `head', `first', `last', an integer or a
1153 predicate. See Info node `(gnus)Customizing Articles'."
1154 :group 'gnus-article-treat
1155 :link '(custom-manual "(gnus)Customizing Articles")
1156 :type gnus-article-treat-head-custom)
1158 (defcustom gnus-treat-date-english nil
1159 "Display the Date in a format that can be read aloud in English.
1160 Valid values are nil, t, `head', `first', `last', an integer or a
1161 predicate. See Info node `(gnus)Customizing Articles'."
1163 :group 'gnus-article-treat
1164 :link '(custom-manual "(gnus)Customizing Articles")
1165 :type gnus-article-treat-head-custom)
1167 (defcustom gnus-treat-date-lapsed nil
1168 "Display the Date header in a way that says how much time has elapsed.
1169 Valid values are nil, t, `head', `first', `last', an integer or a
1170 predicate. See Info node `(gnus)Customizing Articles'."
1171 :group 'gnus-article-treat
1172 :link '(custom-manual "(gnus)Customizing Articles")
1173 :type gnus-article-treat-head-custom)
1175 (defcustom gnus-treat-date-original nil
1176 "Display the date in the original timezone.
1177 Valid values are nil, t, `head', `first', `last', an integer or a
1178 predicate. See Info node `(gnus)Customizing Articles'."
1179 :group 'gnus-article-treat
1180 :link '(custom-manual "(gnus)Customizing Articles")
1181 :type gnus-article-treat-head-custom)
1183 (defcustom gnus-treat-date-iso8601 nil
1184 "Display the date in the ISO8601 format.
1185 Valid values are nil, t, `head', `first', `last', an integer or a
1186 predicate. See Info node `(gnus)Customizing Articles'."
1188 :group 'gnus-article-treat
1189 :link '(custom-manual "(gnus)Customizing Articles")
1190 :type gnus-article-treat-head-custom)
1192 (defcustom gnus-treat-date-user-defined nil
1193 "Display the date in a user-defined format.
1194 The format is defined by the `gnus-article-time-format' variable.
1195 Valid values are nil, t, `head', `first', `last', an integer or a
1196 predicate. See Info node `(gnus)Customizing Articles'."
1197 :group 'gnus-article-treat
1198 :link '(custom-manual "(gnus)Customizing Articles")
1199 :type gnus-article-treat-head-custom)
1201 (defcustom gnus-treat-strip-headers-in-body t
1202 "Strip the X-No-Archive header line from the beginning of the body.
1203 Valid values are nil, t, `head', `first', `last', an integer or a
1204 predicate. See Info node `(gnus)Customizing Articles'."
1206 :group 'gnus-article-treat
1207 :link '(custom-manual "(gnus)Customizing Articles")
1208 :type gnus-article-treat-custom)
1210 (defcustom gnus-treat-strip-trailing-blank-lines nil
1211 "Strip trailing blank lines.
1212 Valid values are nil, t, `head', `first', `last', an integer or a
1213 predicate. See Info node `(gnus)Customizing Articles'.
1215 When set to t, it also strips trailing blanks in all MIME parts.
1216 Consider to use `last' instead."
1217 :group 'gnus-article-treat
1218 :link '(custom-manual "(gnus)Customizing Articles")
1219 :type gnus-article-treat-custom)
1221 (defcustom gnus-treat-strip-leading-blank-lines nil
1222 "Strip leading blank lines.
1223 Valid values are nil, t, `head', `first', `last', an integer or a
1224 predicate. See Info node `(gnus)Customizing Articles'.
1226 When set to t, it also strips trailing blanks in all MIME parts."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-custom)
1231 (defcustom gnus-treat-strip-multiple-blank-lines nil
1232 "Strip multiple blank lines.
1233 Valid values are nil, t, `head', `first', `last', an integer or a
1234 predicate. See Info node `(gnus)Customizing Articles'."
1235 :group 'gnus-article-treat
1236 :link '(custom-manual "(gnus)Customizing Articles")
1237 :type gnus-article-treat-custom)
1239 (defcustom gnus-treat-unfold-headers 'head
1240 "Unfold folded header lines.
1241 Valid values are nil, t, `head', `first', `last', an integer or a
1242 predicate. See Info node `(gnus)Customizing Articles'."
1244 :group 'gnus-article-treat
1245 :link '(custom-manual "(gnus)Customizing Articles")
1246 :type gnus-article-treat-custom)
1248 (defcustom gnus-treat-fold-headers nil
1250 Valid values are nil, t, `head', `first', `last', an integer or a
1251 predicate. See Info node `(gnus)Customizing Articles'."
1253 :group 'gnus-article-treat
1254 :link '(custom-manual "(gnus)Customizing Articles")
1255 :type gnus-article-treat-custom)
1257 (defcustom gnus-treat-fold-newsgroups 'head
1258 "Fold the Newsgroups and Followup-To headers.
1259 Valid values are nil, t, `head', `first', `last', an integer or a
1260 predicate. See Info node `(gnus)Customizing Articles'."
1262 :group 'gnus-article-treat
1263 :link '(custom-manual "(gnus)Customizing Articles")
1264 :type gnus-article-treat-custom)
1266 (defcustom gnus-treat-overstrike t
1267 "Treat overstrike highlighting.
1268 Valid values are nil, t, `head', `first', `last', an integer or a
1269 predicate. See Info node `(gnus)Customizing Articles'."
1270 :group 'gnus-article-treat
1271 :link '(custom-manual "(gnus)Customizing Articles")
1272 :type gnus-article-treat-custom)
1273 (put 'gnus-treat-overstrike 'highlight t)
1275 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1276 "Treat ANSI SGR control sequences.
1277 Valid values are nil, t, `head', `first', `last', an integer or a
1278 predicate. See Info node `(gnus)Customizing Articles'."
1279 :group 'gnus-article-treat
1280 :link '(custom-manual "(gnus)Customizing Articles")
1281 :type gnus-article-treat-custom)
1283 (make-obsolete-variable 'gnus-treat-display-xface
1284 'gnus-treat-display-x-face)
1286 (defcustom gnus-treat-display-x-face
1287 (and (not noninteractive)
1288 (or (and (fboundp 'image-type-available-p)
1289 (image-type-available-p 'xbm)
1290 (string-match "^0x" (shell-command-to-string "uncompface"))
1291 (executable-find "icontopbm"))
1292 (and (featurep 'xemacs)
1295 "Display X-Face headers.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate. See Info node `(gnus)Customizing Articles' and Info
1298 node `(gnus)X-Face' for details."
1299 :group 'gnus-article-treat
1301 :link '(custom-manual "(gnus)Customizing Articles")
1302 :link '(custom-manual "(gnus)X-Face")
1303 :type gnus-article-treat-head-custom
1304 :set (lambda (symbol value)
1307 (cond ((or (boundp symbol) (get symbol 'saved-value))
1309 ((boundp 'gnus-treat-display-xface)
1311 ** gnus-treat-display-xface is an obsolete variable;\
1312 use gnus-treat-display-x-face instead")
1313 (default-value 'gnus-treat-display-xface))
1314 ((get 'gnus-treat-display-xface 'saved-value)
1316 ** gnus-treat-display-xface is an obsolete variable;\
1317 use gnus-treat-display-x-face instead")
1318 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1321 (put 'gnus-treat-display-x-face 'highlight t)
1323 (defcustom gnus-treat-display-face
1324 (and (not noninteractive)
1325 (or (and (fboundp 'image-type-available-p)
1326 (image-type-available-p 'png))
1327 (and (featurep 'xemacs)
1330 "Display Face headers.
1331 Valid values are nil, t, `head', `first', `last', an integer or a
1332 predicate. See Info node `(gnus)Customizing Articles' and Info
1333 node `(gnus)X-Face' for details."
1334 :group 'gnus-article-treat
1336 :link '(custom-manual "(gnus)Customizing Articles")
1337 :link '(custom-manual "(gnus)X-Face")
1338 :type gnus-article-treat-head-custom)
1339 (put 'gnus-treat-display-face 'highlight t)
1341 (defcustom gnus-treat-display-smileys
1342 (if (or (and (featurep 'xemacs)
1344 (and (fboundp 'image-type-available-p)
1345 (image-type-available-p 'pbm)))
1348 Valid values are nil, t, `head', `first', `last', an integer or a
1349 predicate. See Info node `(gnus)Customizing Articles' and Info
1350 node `(gnus)Smileys' for details."
1351 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :link '(custom-manual "(gnus)Smileys")
1355 :type gnus-article-treat-custom)
1356 (put 'gnus-treat-display-smileys 'highlight t)
1358 (defcustom gnus-treat-from-picon
1359 (if (and (gnus-image-type-available-p 'xpm)
1360 (gnus-picons-installed-p))
1362 "Display picons in the From header.
1363 Valid values are nil, t, `head', `first', `last', an integer or a
1364 predicate. See Info node `(gnus)Customizing Articles' and Info
1365 node `(gnus)Picons' for details."
1367 :group 'gnus-article-treat
1369 :link '(custom-manual "(gnus)Customizing Articles")
1370 :link '(custom-manual "(gnus)Picons")
1371 :type gnus-article-treat-head-custom)
1372 (put 'gnus-treat-from-picon 'highlight t)
1374 (defcustom gnus-treat-mail-picon
1375 (if (and (gnus-image-type-available-p 'xpm)
1376 (gnus-picons-installed-p))
1378 "Display picons in To and Cc headers.
1379 Valid values are nil, t, `head', `first', `last', an integer or a
1380 predicate. See Info node `(gnus)Customizing Articles' and Info
1381 node `(gnus)Picons' for details."
1383 :group 'gnus-article-treat
1385 :link '(custom-manual "(gnus)Customizing Articles")
1386 :link '(custom-manual "(gnus)Picons")
1387 :type gnus-article-treat-head-custom)
1388 (put 'gnus-treat-mail-picon 'highlight t)
1390 (defcustom gnus-treat-newsgroups-picon
1391 (if (and (gnus-image-type-available-p 'xpm)
1392 (gnus-picons-installed-p))
1394 "Display picons in the Newsgroups and Followup-To headers.
1395 Valid values are nil, t, `head', `first', `last', an integer or a
1396 predicate. See Info node `(gnus)Customizing Articles' and Info
1397 node `(gnus)Picons' for details."
1399 :group 'gnus-article-treat
1401 :link '(custom-manual "(gnus)Customizing Articles")
1402 :link '(custom-manual "(gnus)Picons")
1403 :type gnus-article-treat-head-custom)
1404 (put 'gnus-treat-newsgroups-picon 'highlight t)
1406 (defcustom gnus-treat-body-boundary
1407 (if (and (eq window-system 'x)
1408 (or gnus-treat-newsgroups-picon
1409 gnus-treat-mail-picon
1410 gnus-treat-from-picon))
1412 "Draw a boundary at the end of the headers.
1413 Valid values are nil and `head'.
1414 See Info node `(gnus)Customizing Articles' for details."
1416 :group 'gnus-article-treat
1417 :link '(custom-manual "(gnus)Customizing Articles")
1418 :type gnus-article-treat-head-custom)
1420 (defcustom gnus-treat-capitalize-sentences nil
1421 "Capitalize sentence-starting words.
1422 Valid values are nil, t, `head', `first', `last', an integer or a
1423 predicate. See Info node `(gnus)Customizing Articles'."
1425 :group 'gnus-article-treat
1426 :link '(custom-manual "(gnus)Customizing Articles")
1427 :type gnus-article-treat-custom)
1429 (defcustom gnus-treat-wash-html nil
1431 Valid values are nil, t, `head', `first', `last', an integer or a
1432 predicate. See Info node `(gnus)Customizing Articles'."
1434 :group 'gnus-article-treat
1435 :link '(custom-manual "(gnus)Customizing Articles")
1436 :type gnus-article-treat-custom)
1438 (defcustom gnus-treat-fill-long-lines nil
1440 Valid values are nil, t, `head', `first', `last', an integer or a
1441 predicate. See Info node `(gnus)Customizing Articles'."
1442 :group 'gnus-article-treat
1443 :link '(custom-manual "(gnus)Customizing Articles")
1444 :type gnus-article-treat-custom)
1446 (defcustom gnus-treat-play-sounds nil
1448 Valid values are nil, t, `head', `first', `last', an integer or a
1449 predicate. See Info node `(gnus)Customizing Articles'."
1451 :group 'gnus-article-treat
1452 :link '(custom-manual "(gnus)Customizing Articles")
1453 :type gnus-article-treat-custom)
1455 (defcustom gnus-treat-translate nil
1456 "Translate articles from one language to another.
1457 Valid values are nil, t, `head', `first', `last', an integer or a
1458 predicate. See Info node `(gnus)Customizing Articles'."
1460 :group 'gnus-article-treat
1461 :link '(custom-manual "(gnus)Customizing Articles")
1462 :type gnus-article-treat-custom)
1464 (defcustom gnus-treat-x-pgp-sig nil
1466 To automatically treat X-PGP-Sig, set it to head.
1467 Valid values are nil, t, `head', `first', `last', an integer or a
1468 predicate. See Info node `(gnus)Customizing Articles'."
1470 :group 'gnus-article-treat
1471 :group 'mime-security
1472 :link '(custom-manual "(gnus)Customizing Articles")
1473 :type gnus-article-treat-custom)
1475 (defvar gnus-article-encrypt-protocol-alist
1476 '(("PGP" . mml2015-self-encrypt)))
1478 ;; Set to nil if more than one protocol added to
1479 ;; gnus-article-encrypt-protocol-alist.
1480 (defcustom gnus-article-encrypt-protocol "PGP"
1481 "The protocol used for encrypt articles.
1482 It is a string, such as \"PGP\". If nil, ask user."
1485 :group 'mime-security)
1487 (defvar gnus-article-wash-function nil
1488 "Function used for converting HTML into text.")
1490 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1491 (mm-coding-system-p 'utf-8)
1492 (executable-find idna-program))
1493 "Whether IDNA decoding of headers is used when viewing messages.
1494 This requires GNU Libidn, and by default only enabled if it is found."
1496 :group 'gnus-article-headers
1499 (defcustom gnus-article-over-scroll nil
1500 "If non-nil, allow scrolling the article buffer even when there no more text."
1502 :group 'gnus-article
1505 ;;; Internal variables
1507 (defvar gnus-english-month-names
1508 '("January" "February" "March" "April" "May" "June" "July" "August"
1509 "September" "October" "November" "December"))
1511 (defvar gnus-button-regexp nil)
1512 (defvar gnus-button-marker-list nil)
1513 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1515 (defvar gnus-button-last nil)
1516 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1518 (defvar article-goto-body-goes-to-point-min-p nil)
1519 (defvar gnus-article-wash-types nil)
1520 (defvar gnus-article-emphasis-alist nil)
1521 (defvar gnus-article-image-alist nil)
1523 (defvar gnus-article-mime-handle-alist-1 nil)
1524 (defvar gnus-treatment-function-alist
1525 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1526 (gnus-treat-strip-banner gnus-article-strip-banner)
1527 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1528 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1529 (gnus-treat-buttonize gnus-article-add-buttons)
1530 (gnus-treat-fill-article gnus-article-fill-cited-article)
1531 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1532 (gnus-treat-strip-cr gnus-article-remove-cr)
1533 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1534 (gnus-treat-date-ut gnus-article-date-ut)
1535 (gnus-treat-date-local gnus-article-date-local)
1536 (gnus-treat-date-english gnus-article-date-english)
1537 (gnus-treat-date-original gnus-article-date-original)
1538 (gnus-treat-date-user-defined gnus-article-date-user)
1539 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1540 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1541 (gnus-treat-display-x-face gnus-article-display-x-face)
1542 (gnus-treat-display-face gnus-article-display-face)
1543 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1544 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1545 (gnus-treat-hide-signature gnus-article-hide-signature)
1546 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1547 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1548 (gnus-treat-strip-pem gnus-article-hide-pem)
1549 (gnus-treat-from-picon gnus-treat-from-picon)
1550 (gnus-treat-mail-picon gnus-treat-mail-picon)
1551 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1552 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1553 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1554 (gnus-treat-strip-trailing-blank-lines
1555 gnus-article-remove-trailing-blank-lines)
1556 (gnus-treat-strip-leading-blank-lines
1557 gnus-article-strip-leading-blank-lines)
1558 (gnus-treat-strip-multiple-blank-lines
1559 gnus-article-strip-multiple-blank-lines)
1560 (gnus-treat-overstrike gnus-article-treat-overstrike)
1561 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1562 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1563 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1564 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1565 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1566 (gnus-treat-display-smileys gnus-treat-smiley)
1567 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1568 (gnus-treat-wash-html gnus-article-wash-html)
1569 (gnus-treat-emphasize gnus-article-emphasize)
1570 (gnus-treat-hide-citation gnus-article-hide-citation)
1571 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1572 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1573 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1574 (gnus-treat-play-sounds gnus-earcon-display)))
1576 (defvar gnus-article-mime-handle-alist nil)
1577 (defvar article-lapsed-timer nil)
1578 (defvar gnus-article-current-summary nil)
1580 (defvar gnus-article-mode-syntax-table
1581 (let ((table (copy-syntax-table text-mode-syntax-table)))
1582 ;; This causes the citation match run O(2^n).
1583 ;; (modify-syntax-entry ?- "w" table)
1584 (modify-syntax-entry ?> ")<" table)
1585 (modify-syntax-entry ?< "(>" table)
1586 ;; make M-. in article buffers work for `foo' strings
1587 (modify-syntax-entry ?' " " table)
1588 (modify-syntax-entry ?` " " table)
1590 "Syntax table used in article mode buffers.
1591 Initialized from `text-mode-syntax-table.")
1593 (defvar gnus-save-article-buffer nil)
1595 (defvar gnus-article-mode-line-format-alist
1596 (nconc '((?w (gnus-article-wash-status) ?s)
1597 (?m (gnus-article-mime-part-status) ?s))
1598 gnus-summary-mode-line-format-alist))
1600 (defvar gnus-number-of-articles-to-be-saved nil)
1602 (defvar gnus-inhibit-hiding nil)
1604 (defvar gnus-article-edit-mode nil)
1606 ;;; Macros for dealing with the article buffer.
1608 (defmacro gnus-with-article-headers (&rest forms)
1610 (set-buffer gnus-article-buffer)
1612 (let ((inhibit-read-only t)
1613 (inhibit-point-motion-hooks t)
1614 (case-fold-search t))
1615 (article-narrow-to-head)
1618 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1619 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1621 (defmacro gnus-with-article-buffer (&rest forms)
1623 (set-buffer gnus-article-buffer)
1624 (let ((inhibit-read-only t))
1627 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1628 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1630 (defun gnus-article-goto-header (header)
1631 "Go to HEADER, which is a regular expression."
1632 (re-search-forward (concat "^\\(" header "\\):") nil t))
1634 (defsubst gnus-article-hide-text (b e props)
1635 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1636 (gnus-add-text-properties-when 'article-type nil b e props)
1637 (when (memq 'intangible props)
1639 (max (1- b) (point-min))
1640 b 'intangible (cddr (memq 'intangible props)))))
1642 (defsubst gnus-article-unhide-text (b e)
1643 "Remove hidden text properties from region between B and E."
1644 (remove-text-properties b e gnus-hidden-properties)
1645 (when (memq 'intangible gnus-hidden-properties)
1646 (put-text-property (max (1- b) (point-min))
1647 b 'intangible nil)))
1649 (defun gnus-article-hide-text-type (b e type)
1650 "Hide text of TYPE between B and E."
1651 (gnus-add-wash-type type)
1652 (gnus-article-hide-text
1653 b e (cons 'article-type (cons type gnus-hidden-properties))))
1655 (defun gnus-article-unhide-text-type (b e type)
1656 "Unhide text of TYPE between B and E."
1657 (gnus-delete-wash-type type)
1658 (remove-text-properties
1659 b e (cons 'article-type (cons type gnus-hidden-properties)))
1660 (when (memq 'intangible gnus-hidden-properties)
1661 (put-text-property (max (1- b) (point-min))
1662 b 'intangible nil)))
1664 (defun gnus-article-hide-text-of-type (type)
1665 "Hide text of TYPE in the current buffer."
1667 (let ((b (point-min))
1669 (while (setq b (text-property-any b e 'article-type type))
1670 (add-text-properties b (incf b) gnus-hidden-properties)))))
1672 (defun gnus-article-delete-text-of-type (type)
1673 "Delete text of TYPE in the current buffer."
1675 (let ((b (point-min)))
1676 (while (setq b (text-property-any b (point-max) 'article-type type))
1678 b (or (text-property-not-all b (point-max) 'article-type type)
1681 (defun gnus-article-delete-invisible-text ()
1682 "Delete all invisible text in the current buffer."
1684 (let ((b (point-min)))
1685 (while (setq b (text-property-any b (point-max) 'invisible t))
1687 b (or (text-property-not-all b (point-max) 'invisible t)
1690 (defun gnus-article-text-type-exists-p (type)
1691 "Say whether any text of type TYPE exists in the buffer."
1692 (text-property-any (point-min) (point-max) 'article-type type))
1694 (defsubst gnus-article-header-rank ()
1695 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1696 (let ((list gnus-sorted-header-list)
1699 (if (looking-at (car list))
1701 (setq list (cdr list))
1705 (defun article-hide-headers (&optional arg delete)
1706 "Hide unwanted headers and possibly sort them as well."
1708 ;; This function might be inhibited.
1709 (unless gnus-inhibit-hiding
1710 (let ((inhibit-read-only nil)
1711 (case-fold-search t)
1712 (max (1+ (length gnus-sorted-header-list)))
1713 (inhibit-point-motion-hooks t)
1714 (cur (current-buffer))
1715 ignored visible beg)
1717 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1718 ;; group parameters, so we should go to the summary buffer.
1721 (progn (set-buffer gnus-summary-buffer) t)
1723 (setq ignored (when (not gnus-visible-headers)
1724 (cond ((stringp gnus-ignored-headers)
1725 gnus-ignored-headers)
1726 ((listp gnus-ignored-headers)
1727 (mapconcat 'identity
1728 gnus-ignored-headers
1730 visible (cond ((stringp gnus-visible-headers)
1731 gnus-visible-headers)
1732 ((and gnus-visible-headers
1733 (listp gnus-visible-headers))
1734 (mapconcat 'identity
1735 gnus-visible-headers
1739 ;; First we narrow to just the headers.
1740 (article-narrow-to-head)
1741 ;; Hide any "From " lines at the beginning of (mail) articles.
1742 (while (looking-at "From ")
1745 (delete-region (point-min) (point)))
1746 ;; Then treat the rest of the header lines.
1747 ;; Then we use the two regular expressions
1748 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1749 ;; select which header lines is to remain visible in the
1751 (while (re-search-forward "^[^ \t:]*:" nil t)
1753 ;; Mark the rank of the header.
1755 (point) (1+ (point)) 'message-rank
1756 (if (or (and visible (looking-at visible))
1758 (not (looking-at ignored))))
1759 (gnus-article-header-rank)
1762 (message-sort-headers-1)
1763 (when (setq beg (text-property-any
1764 (point-min) (point-max) 'message-rank (+ 2 max)))
1765 ;; We delete the unwanted headers.
1766 (gnus-add-wash-type 'headers)
1767 (add-text-properties (point-min) (+ 5 (point-min))
1768 '(article-type headers dummy-invisible t))
1769 (delete-region beg (point-max))))))))
1771 (defun article-hide-boring-headers (&optional arg)
1772 "Toggle hiding of headers that aren't very interesting.
1773 If given a negative prefix, always show; if given a positive prefix,
1775 (interactive (gnus-article-hidden-arg))
1776 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1777 (not gnus-show-all-headers))
1780 (let ((inhibit-read-only t)
1781 (inhibit-point-motion-hooks t))
1782 (article-narrow-to-head)
1783 (dolist (elem gnus-boring-article-headers)
1784 (goto-char (point-min))
1786 ;; Hide empty headers.
1788 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1790 (gnus-article-hide-text-type
1794 (if (re-search-forward "^[^ \t]" nil t)
1798 ;; Hide boring Newsgroups header.
1799 ((eq elem 'newsgroups)
1800 (when (gnus-string-equal
1801 (gnus-fetch-field "newsgroups")
1802 (gnus-group-real-name
1803 (if (boundp 'gnus-newsgroup-name)
1806 (gnus-article-hide-header "newsgroups")))
1807 ((eq elem 'to-address)
1808 (let ((to (message-fetch-field "to"))
1810 (gnus-parameter-to-address
1811 (if (boundp 'gnus-newsgroup-name)
1812 gnus-newsgroup-name ""))))
1813 (when (and to to-address
1816 ;; only one address in To
1817 (nth 1 (mail-extract-address-components to))
1819 (gnus-article-hide-header "to"))))
1821 (let ((to (message-fetch-field "to"))
1823 (gnus-parameter-to-list
1824 (if (boundp 'gnus-newsgroup-name)
1825 gnus-newsgroup-name ""))))
1826 (when (and to to-list
1829 ;; only one address in To
1830 (nth 1 (mail-extract-address-components to))
1832 (gnus-article-hide-header "to"))))
1834 (let ((cc (message-fetch-field "cc"))
1836 (gnus-parameter-to-list
1837 (if (boundp 'gnus-newsgroup-name)
1838 gnus-newsgroup-name ""))))
1839 (when (and cc to-list
1842 ;; only one address in CC
1843 (nth 1 (mail-extract-address-components cc))
1845 (gnus-article-hide-header "cc"))))
1846 ((eq elem 'followup-to)
1847 (when (gnus-string-equal
1848 (message-fetch-field "followup-to")
1849 (message-fetch-field "newsgroups"))
1850 (gnus-article-hide-header "followup-to")))
1851 ((eq elem 'reply-to)
1852 (if (gnus-group-find-parameter
1853 gnus-newsgroup-name 'broken-reply-to)
1854 (gnus-article-hide-header "reply-to")
1855 (let ((from (message-fetch-field "from"))
1856 (reply-to (message-fetch-field "reply-to")))
1863 (lambda (x) (downcase (cadr x)))
1864 (mail-extract-address-components from t))
1867 (lambda (x) (downcase (cadr x)))
1868 (mail-extract-address-components reply-to t))
1870 (gnus-article-hide-header "reply-to")))))
1872 (let ((date (message-fetch-field "date")))
1874 (< (days-between (current-time-string) date)
1876 (gnus-article-hide-header "date"))))
1878 (let ((to (message-fetch-field "to"))
1879 (cc (message-fetch-field "cc")))
1880 (when (> (length to) 1024)
1881 (gnus-article-hide-header "to"))
1882 (when (> (length cc) 1024)
1883 (gnus-article-hide-header "cc"))))
1887 (goto-char (point-min))
1888 (while (re-search-forward "^to:" nil t)
1889 (setq to-count (1+ to-count)))
1890 (when (> to-count 1)
1891 (while (> to-count 0)
1892 (goto-char (point-min))
1894 (re-search-forward "^to:" nil nil to-count)
1896 (narrow-to-region (point) (point-max))
1897 (gnus-article-hide-header "to"))
1898 (setq to-count (1- to-count))))
1899 (goto-char (point-min))
1900 (while (re-search-forward "^cc:" nil t)
1901 (setq cc-count (1+ cc-count)))
1902 (when (> cc-count 1)
1903 (while (> cc-count 0)
1904 (goto-char (point-min))
1906 (re-search-forward "^cc:" nil nil cc-count)
1908 (narrow-to-region (point) (point-max))
1909 (gnus-article-hide-header "cc"))
1910 (setq cc-count (1- cc-count)))))))))))))
1912 (defun gnus-article-hide-header (header)
1914 (goto-char (point-min))
1915 (when (re-search-forward (concat "^" header ":") nil t)
1916 (gnus-article-hide-text-type
1920 (if (re-search-forward "^[^ \t]" nil t)
1925 (defvar gnus-article-normalized-header-length 40
1926 "Length of normalized headers.")
1928 (defun article-normalize-headers ()
1929 "Make all header lines 40 characters long."
1931 (let ((inhibit-read-only t)
1935 (article-narrow-to-head)
1938 ((< (setq column (- (point-at-eol) (point)))
1939 gnus-article-normalized-header-length)
1941 (insert (make-string
1942 (- gnus-article-normalized-header-length column)
1944 ((> column gnus-article-normalized-header-length)
1945 (gnus-put-text-property
1947 (forward-char gnus-article-normalized-header-length)
1954 (forward-line 1))))))
1956 (defun article-treat-dumbquotes ()
1957 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1958 Note that this function guesses whether a character is a sm*rtq**t* or
1959 not, so it should only be used interactively.
1961 Sm*rtq**t*s are M****s***'s unilateral extension to the
1962 iso-8859-1 character map in an attempt to provide more quoting
1963 characters. If you see something like \\222 or \\264 where
1964 you're expecting some kind of apostrophe or quotation mark, then
1967 (article-translate-strings gnus-article-dumbquotes-map))
1969 (defun article-translate-characters (from to)
1970 "Translate all characters in the body of the article according to FROM and TO.
1971 FROM is a string of characters to translate from; to is a string of
1972 characters to translate to."
1974 (when (article-goto-body)
1975 (let ((inhibit-read-only t)
1976 (x (make-string 225 ?x))
1978 (while (< (incf i) (length x))
1981 (while (< i (length from))
1982 (aset x (aref from i) (aref to i))
1984 (translate-region (point) (point-max) x)))))
1986 (defun article-translate-strings (map)
1987 "Translate all string in the body of the article according to MAP.
1988 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1990 (when (article-goto-body)
1991 (let ((inhibit-read-only t))
1994 (while (search-forward (car elem) nil t)
1995 (replace-match (cadr elem)))))))))
1997 (defun article-treat-overstrike ()
1998 "Translate overstrikes into bold text."
2001 (when (article-goto-body)
2002 (let ((inhibit-read-only t))
2003 (while (search-forward "\b" nil t)
2004 (let ((next (char-after))
2005 (previous (char-after (- (point) 2))))
2006 ;; We do the boldification/underlining by hiding the
2007 ;; overstrikes and putting the proper text property
2011 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2012 (put-text-property (point) (1+ (point)) 'face 'bold))
2014 (gnus-article-hide-text-type
2015 (1- (point)) (1+ (point)) 'overstrike)
2017 (- (point) 2) (1- (point)) 'face 'underline))
2019 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2021 (point) (1+ (point)) 'face 'underline)))))))))
2023 (defun article-treat-ansi-sequences ()
2024 "Translate ANSI SGR control sequences into overlays or extents."
2027 (when (article-goto-body)
2028 (let ((inhibit-read-only t))
2029 (ansi-color-apply-on-region (point) (point-max))))))
2031 (defun gnus-article-treat-unfold-headers ()
2032 "Unfold folded message headers.
2033 Only the headers that fit into the current window width will be
2036 (gnus-with-article-headers
2040 (mail-header-narrow-to-field)
2041 (let ((header (buffer-string)))
2044 (goto-char (point-min))
2045 (while (re-search-forward "\n[\t ]" nil t)
2046 (replace-match " " t t)))
2047 (setq length (- (point-max) (point-min) 1)))
2048 (when (< length (window-width))
2049 (while (re-search-forward "\n[\t ]" nil t)
2050 (replace-match " " t t)))
2051 (goto-char (point-max)))))))
2053 (defun gnus-article-treat-fold-headers ()
2054 "Fold message headers."
2056 (gnus-with-article-headers
2059 (mail-header-narrow-to-field)
2060 (mail-header-fold-field)
2061 (goto-char (point-max))))))
2063 (defun gnus-treat-smiley ()
2064 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2066 (gnus-with-article-buffer
2067 (if (memq 'smiley gnus-article-wash-types)
2068 (gnus-delete-images 'smiley)
2070 (let ((images (smiley-region (point) (point-max))))
2072 (gnus-add-wash-type 'smiley)
2073 (dolist (image images)
2074 (gnus-add-image 'smiley image)))))))
2076 (defun gnus-article-remove-images ()
2077 "Remove all images from the article buffer."
2079 (gnus-with-article-buffer
2080 (dolist (elem gnus-article-image-alist)
2081 (gnus-delete-images (car elem)))))
2083 (defun gnus-article-treat-fold-newsgroups ()
2084 "Unfold folded message headers.
2085 Only the headers that fit into the current window width will be
2088 (gnus-with-article-headers
2089 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2091 (mail-header-narrow-to-field)
2092 (while (re-search-forward ", *" nil t)
2093 (replace-match ", " t t))
2094 (mail-header-fold-field)
2095 (goto-char (point-max))))))
2097 (defun gnus-article-treat-body-boundary ()
2098 "Place a boundary line at the end of the headers."
2100 (when (and gnus-body-boundary-delimiter
2101 (> (length gnus-body-boundary-delimiter) 0))
2102 (gnus-with-article-headers
2103 (goto-char (point-max))
2104 (let ((start (point)))
2105 (insert "X-Boundary: ")
2106 (gnus-add-text-properties start (point) '(invisible t intangible t))
2108 (while (>= (1- (window-width)) (length str))
2109 (setq str (concat str gnus-body-boundary-delimiter)))
2110 (substring str 0 (1- (window-width))))
2112 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2114 (defun article-fill-long-lines ()
2115 "Fill lines that are wider than the window width."
2118 (let ((inhibit-read-only t)
2119 (width (window-width (get-buffer-window (current-buffer)))))
2122 (let ((adaptive-fill-mode nil)) ;Why? -sm
2125 (when (>= (current-column) (min fill-column width))
2126 (narrow-to-region (min (1+ (point)) (point-max))
2128 (let ((goback (point-marker)))
2129 (fill-paragraph nil)
2130 (goto-char (marker-position goback)))
2132 (forward-line 1)))))))
2134 (defun article-capitalize-sentences ()
2135 "Capitalize the first word in each sentence."
2138 (let ((inhibit-read-only t)
2139 (paragraph-start "^[\n\^L]"))
2143 (forward-sentence)))))
2145 (defun article-remove-cr ()
2146 "Remove trailing CRs and then translate remaining CRs into LFs."
2149 (let ((inhibit-read-only t))
2150 (goto-char (point-min))
2151 (while (re-search-forward "\r+$" nil t)
2152 (replace-match "" t t))
2153 (goto-char (point-min))
2154 (while (search-forward "\r" nil t)
2155 (replace-match "\n" t t)))))
2157 (defun article-remove-trailing-blank-lines ()
2158 "Remove all trailing blank lines from the article."
2161 (let ((inhibit-read-only t))
2162 (goto-char (point-max))
2166 (while (and (not (bobp))
2167 (looking-at "^[ \t]*$")
2168 (not (gnus-annotation-in-region-p
2169 (point) (point-at-eol))))
2175 (defvar gnus-face-properties-alist))
2177 (defun article-display-face ()
2178 "Display any Face headers in the header."
2180 (let ((wash-face-p buffer-read-only))
2181 (gnus-with-article-headers
2182 ;; When displaying parts, this function can be called several times on
2183 ;; the same article, without any intended toggle semantic (as typing `W
2184 ;; D d' would have). So face deletion must occur only when we come from
2185 ;; an interactive command, that is when the *Article* buffer is
2187 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2188 (gnus-delete-images 'face)
2189 (let (face faces from)
2190 (save-current-buffer
2191 (when (and wash-face-p
2192 (gnus-buffer-live-p gnus-original-article-buffer)
2193 (not (re-search-forward "^Face:[\t ]*" nil t)))
2194 (set-buffer gnus-original-article-buffer))
2196 (mail-narrow-to-head)
2197 (while (gnus-article-goto-header "Face")
2198 (push (mail-header-field-value) faces))))
2200 (goto-char (point-min))
2201 (let ((from (gnus-article-goto-header "from"))
2206 (insert "[no `from' set]\n"))
2208 (when (setq png (gnus-convert-face-to-png (pop faces)))
2210 (apply 'gnus-create-image png 'png t
2211 (cdr (assq 'png gnus-face-properties-alist))))
2213 (gnus-add-wash-type 'face)
2214 (gnus-add-image 'face image)
2215 (gnus-put-image image nil 'face))))))))))
2217 (defun article-display-x-face (&optional force)
2218 "Look for an X-Face header and display it if present."
2219 (interactive (list 'force))
2220 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2221 (gnus-with-article-headers
2222 ;; Delete the old process, if any.
2223 (when (process-status "article-x-face")
2224 (delete-process "article-x-face"))
2225 ;; See the comment in `article-display-face'.
2226 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2227 ;; We have already displayed X-Faces, so we remove them
2229 (gnus-delete-images 'xface)
2231 (let (x-faces from face)
2232 (save-current-buffer
2233 (when (and wash-face-p
2234 (gnus-buffer-live-p gnus-original-article-buffer)
2235 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2236 ;; If type `W f', use gnus-original-article-buffer,
2237 ;; otherwise use the current buffer because displaying
2238 ;; RFC822 parts calls this function too.
2239 (set-buffer gnus-original-article-buffer))
2241 (mail-narrow-to-head)
2242 (while (gnus-article-goto-header "X-Face")
2243 (push (mail-header-field-value) x-faces))
2244 (setq from (message-fetch-field "from"))))
2245 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2246 ;; single external face.
2247 (when (stringp gnus-article-x-face-command)
2248 (setq x-faces (list (car x-faces))))
2250 gnus-article-x-face-command
2252 ;; Check whether this face is censored.
2253 (not gnus-article-x-face-too-ugly)
2255 (not (string-match gnus-article-x-face-too-ugly
2257 (while (setq face (pop x-faces))
2258 ;; We display the face.
2259 (cond ((stringp gnus-article-x-face-command)
2260 ;; The command is a string, so we interpret the command
2261 ;; as a, well, command, and fork it off.
2262 (let ((process-connection-type nil))
2263 (gnus-set-process-query-on-exit-flag
2265 "article-x-face" nil shell-file-name
2266 shell-command-switch gnus-article-x-face-command)
2270 (process-send-region "article-x-face"
2271 (point-min) (point-max)))
2272 (process-send-eof "article-x-face")))
2273 ((functionp gnus-article-x-face-command)
2274 ;; The command is a lisp function, so we call it.
2275 (funcall gnus-article-x-face-command face))
2277 (error "%s is not a function"
2278 gnus-article-x-face-command))))))))))
2280 (defun article-decode-mime-words ()
2281 "Decode all MIME-encoded words in the article."
2283 (gnus-with-article-buffer
2284 (let ((inhibit-point-motion-hooks t)
2285 (mail-parse-charset gnus-newsgroup-charset)
2286 (mail-parse-ignored-charsets
2287 (with-current-buffer gnus-summary-buffer
2288 gnus-newsgroup-ignored-charsets)))
2289 (mail-decode-encoded-word-region (point-min) (point-max)))))
2291 (defun article-decode-charset (&optional prompt)
2292 "Decode charset-encoded text in the article.
2293 If PROMPT (the prefix), prompt for a coding system to use."
2295 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2296 (inhibit-read-only t)
2297 (mail-parse-charset gnus-newsgroup-charset)
2298 (mail-parse-ignored-charsets
2299 (save-excursion (condition-case nil
2300 (set-buffer gnus-summary-buffer)
2302 gnus-newsgroup-ignored-charsets))
2303 ct cte ctl charset format)
2306 (article-narrow-to-head)
2307 (setq ct (message-fetch-field "Content-Type" t)
2308 cte (message-fetch-field "Content-Transfer-Encoding" t)
2309 ctl (and ct (ignore-errors
2310 (mail-header-parse-content-type ct)))
2313 (mm-read-coding-system "Charset to decode: "))
2315 (mail-content-type-get ctl 'charset)))
2316 format (and ctl (mail-content-type-get ctl 'format)))
2318 (setq cte (mail-header-strip cte)))
2319 (if (and ctl (not (string-match "/" (car ctl))))
2321 (goto-char (point-max)))
2324 (narrow-to-region (point) (point-max))
2325 (when (and (eq mail-parse-charset 'gnus-decoded)
2326 (eq (mm-body-7-or-8) '8bit))
2327 ;; The text code could have been decoded.
2328 (setq charset mail-parse-charset))
2329 (when (and (or (not ctl)
2330 (equal (car ctl) "text/plain"))
2331 (not format)) ;; article with format will decode later.
2333 charset (and cte (intern (downcase
2334 (gnus-strip-whitespace cte))))
2337 (defun article-decode-encoded-words ()
2338 "Remove encoded-word encoding from headers."
2339 (let ((inhibit-point-motion-hooks t)
2340 (mail-parse-charset gnus-newsgroup-charset)
2341 (mail-parse-ignored-charsets
2342 (save-excursion (condition-case nil
2343 (set-buffer gnus-summary-buffer)
2345 gnus-newsgroup-ignored-charsets))
2346 (inhibit-read-only t))
2348 (article-narrow-to-head)
2349 (funcall gnus-decode-header-function (point-min) (point-max)))))
2351 (defun article-decode-group-name ()
2352 "Decode group names in `Newsgroups:'."
2353 (let ((inhibit-point-motion-hooks t)
2354 (inhibit-read-only t)
2355 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2356 (when (and (or gnus-group-name-charset-method-alist
2357 gnus-group-name-charset-group-alist)
2358 (gnus-buffer-live-p gnus-original-article-buffer))
2360 (article-narrow-to-head)
2361 (with-current-buffer gnus-original-article-buffer
2362 (goto-char (point-min)))
2363 (while (re-search-forward
2364 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2365 (replace-match (save-match-data
2366 (gnus-decode-newsgroups
2367 ;; XXX how to use data in article buffer?
2368 (with-current-buffer gnus-original-article-buffer
2370 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2373 gnus-newsgroup-name method))
2375 (goto-char (point-min))
2376 (with-current-buffer gnus-original-article-buffer
2377 (goto-char (point-min)))
2378 (while (re-search-forward
2379 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2380 (replace-match (save-match-data
2381 (gnus-decode-newsgroups
2382 ;; XXX how to use data in article buffer?
2383 (with-current-buffer gnus-original-article-buffer
2385 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2388 gnus-newsgroup-name method))
2391 (autoload 'idna-to-unicode "idna")
2393 (defun article-decode-idna-rhs ()
2394 "Decode IDNA strings in RHS in various headers in current buffer.
2395 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2396 Mail-Reply-To: and Mail-Followup-To:."
2399 (let ((inhibit-point-motion-hooks t)
2400 (inhibit-read-only t))
2401 (article-narrow-to-head)
2402 (goto-char (point-min))
2403 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2405 (when (save-match-data
2406 (and (setq ace (match-string 1))
2408 (and (re-search-backward "^[^ \t]" nil t)
2409 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2410 (setq unicode (idna-to-unicode ace))))
2411 (unless (string= ace unicode)
2412 (replace-match unicode nil nil nil 1)))))))))
2414 (defun article-de-quoted-unreadable (&optional force read-charset)
2415 "Translate a quoted-printable-encoded article.
2416 If FORCE, decode the article whether it is marked as quoted-printable
2418 If READ-CHARSET, ask for a coding system."
2419 (interactive (list 'force current-prefix-arg))
2421 (let ((inhibit-read-only t) type charset)
2422 (if (gnus-buffer-live-p gnus-original-article-buffer)
2423 (with-current-buffer gnus-original-article-buffer
2425 (gnus-fetch-field "content-transfer-encoding"))
2426 (let* ((ct (gnus-fetch-field "content-type"))
2429 (mail-header-parse-content-type ct)))))
2430 (setq charset (and ctl
2431 (mail-content-type-get ctl 'charset)))
2432 (if (stringp charset)
2433 (setq charset (intern (downcase charset)))))))
2435 (setq charset (mm-read-coding-system "Charset: " charset)))
2437 (setq charset gnus-newsgroup-charset))
2439 (and type (let ((case-fold-search t))
2440 (string-match "quoted-printable" type))))
2442 (quoted-printable-decode-region
2443 (point) (point-max) (mm-charset-to-coding-system charset))))))
2445 (defun article-de-base64-unreadable (&optional force read-charset)
2446 "Translate a base64 article.
2447 If FORCE, decode the article whether it is marked as base64 not.
2448 If READ-CHARSET, ask for a coding system."
2449 (interactive (list 'force current-prefix-arg))
2451 (let ((inhibit-read-only t) type charset)
2452 (if (gnus-buffer-live-p gnus-original-article-buffer)
2453 (with-current-buffer gnus-original-article-buffer
2455 (gnus-fetch-field "content-transfer-encoding"))
2456 (let* ((ct (gnus-fetch-field "content-type"))
2459 (mail-header-parse-content-type ct)))))
2460 (setq charset (and ctl
2461 (mail-content-type-get ctl 'charset)))
2462 (if (stringp charset)
2463 (setq charset (intern (downcase charset)))))))
2465 (setq charset (mm-read-coding-system "Charset: " charset)))
2467 (setq charset gnus-newsgroup-charset))
2469 (and type (let ((case-fold-search t))
2470 (string-match "base64" type))))
2473 (narrow-to-region (point) (point-max))
2474 (base64-decode-region (point-min) (point-max))
2475 (mm-decode-coding-region
2476 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2481 (defun article-decode-HZ ()
2482 "Translate a HZ-encoded article."
2486 (let ((inhibit-read-only t))
2487 (rfc1843-decode-region (point-min) (point-max)))))
2489 (defun article-unsplit-urls ()
2490 "Remove the newlines that some other mailers insert into URLs."
2493 (let ((inhibit-read-only t))
2494 (goto-char (point-min))
2495 (while (re-search-forward
2496 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2497 (replace-match "\\1\\3" t)))
2498 (when (interactive-p)
2499 (gnus-treat-article nil))))
2502 (defun article-wash-html (&optional read-charset)
2503 "Format an HTML article.
2504 If READ-CHARSET, ask for a coding system."
2507 (let ((inhibit-read-only t)
2509 (when (gnus-buffer-live-p gnus-original-article-buffer)
2510 (with-current-buffer gnus-original-article-buffer
2511 (let* ((ct (gnus-fetch-field "content-type"))
2514 (mail-header-parse-content-type ct)))))
2515 (setq charset (and ctl
2516 (mail-content-type-get ctl 'charset)))
2517 (when (stringp charset)
2518 (setq charset (intern (downcase charset)))))))
2520 (setq charset (mm-read-coding-system "Charset: " charset)))
2522 (setq charset gnus-newsgroup-charset))
2524 (save-window-excursion
2526 (narrow-to-region (point) (point-max))
2527 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2528 (entry (assq func mm-text-html-washer-alist)))
2530 (setq func (cdr entry)))
2535 (apply (car func) (cdr func))))))))))
2537 (defun gnus-article-wash-html-with-w3 ()
2538 "Wash the current buffer with w3."
2540 (let ((w3-strict-width (window-width))
2541 (url-standalone-mode t)
2542 (url-gateway-unplugged t)
2543 (w3-honor-stylesheets nil))
2545 (w3-region (point-min) (point-max))
2548 (defun gnus-article-wash-html-with-w3m ()
2549 "Wash the current buffer with emacs-w3m."
2552 (narrow-to-region (point) (point-max))
2553 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2554 w3m-force-redisplay)
2555 (w3m-region (point-min) (point-max)))
2556 (when (and mm-inline-text-html-with-w3m-keymap
2557 (boundp 'w3m-minor-mode-map)
2559 (add-text-properties
2560 (point-min) (point-max)
2561 (list 'keymap w3m-minor-mode-map
2562 ;; Put the mark meaning this part was rendered by emacs-w3m.
2563 'mm-inline-text-html-with-w3m t)))))
2565 (defun article-hide-list-identifiers ()
2566 "Remove list identifies from the Subject header.
2567 The `gnus-list-identifiers' variable specifies what to do."
2569 (let ((inhibit-point-motion-hooks t)
2570 (regexp (if (consp gnus-list-identifiers)
2571 (mapconcat 'identity gnus-list-identifiers " *\\|")
2572 gnus-list-identifiers))
2573 (inhibit-read-only t))
2577 (article-narrow-to-head)
2578 (goto-char (point-min))
2579 (while (re-search-forward
2580 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2582 (delete-region (match-beginning 2) (match-end 0))
2583 (beginning-of-line))
2584 (when (re-search-forward
2585 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2586 (delete-region (match-beginning 1) (match-end 1))))))))
2588 (defun article-hide-pem (&optional arg)
2589 "Toggle hiding of any PEM headers and signatures in the current article.
2590 If given a negative prefix, always show; if given a positive prefix,
2592 (interactive (gnus-article-hidden-arg))
2593 (unless (gnus-article-check-hidden-text 'pem arg)
2595 (let ((inhibit-read-only t) end)
2596 (goto-char (point-min))
2597 ;; Hide the horrendously ugly "header".
2598 (when (and (search-forward
2599 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2601 (setq end (1+ (match-beginning 0))))
2602 (gnus-add-wash-type 'pem)
2603 (gnus-article-hide-text-type
2605 (if (search-forward "\n\n" nil t)
2609 ;; Hide the trailer as well
2610 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2612 (gnus-article-hide-text-type
2613 (match-beginning 0) (match-end 0) 'pem)))))))
2615 (defun article-strip-banner ()
2616 "Strip the banners specified by the `banner' group parameter and by
2617 `gnus-article-address-banner-alist'."
2621 (let ((inhibit-point-motion-hooks t))
2622 (when (gnus-parameter-banner gnus-newsgroup-name)
2623 (article-really-strip-banner
2624 (gnus-parameter-banner gnus-newsgroup-name)))
2625 (when gnus-article-address-banner-alist
2626 ;; It is necessary to encode from fields before checking,
2627 ;; because `mail-header-parse-addresses' does not work
2628 ;; (reliably) on decoded headers. And more, it is
2629 ;; impossible to use `gnus-fetch-original-field' here,
2630 ;; because `article-strip-banner' may be called in draft
2631 ;; buffers to preview them.
2632 (let ((from (save-restriction
2634 (article-narrow-to-head)
2635 (mail-fetch-field "from"))))
2638 (caar (mail-header-parse-addresses
2639 (mail-encode-encoded-word-string from)))))
2641 (dolist (pair gnus-article-address-banner-alist)
2642 (when (string-match (car pair) from)
2644 (article-really-strip-banner (cdr pair)))))))))))))
2646 (defun article-really-strip-banner (banner)
2647 "Strip the banner specified by the argument."
2650 (let ((inhibit-point-motion-hooks t)
2651 (gnus-signature-limit nil)
2652 (inhibit-read-only t))
2655 ((eq banner 'signature)
2656 (when (gnus-article-narrow-to-signature)
2659 (delete-region (point) (point-max))))
2661 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2662 (while (re-search-forward banner nil t)
2663 (delete-region (match-beginning 0) (match-end 0)))))
2665 (while (re-search-forward banner nil t)
2666 (delete-region (match-beginning 0) (match-end 0)))))))))
2668 (defun article-babel ()
2669 "Translate article using an online translation service."
2672 (gnus-with-article-buffer
2673 (when (article-goto-body)
2674 (let* ((start (point))
2676 (orig (buffer-substring start end))
2677 (trans (babel-as-string orig)))
2679 (narrow-to-region start end)
2680 (delete-region start end)
2683 (defun article-hide-signature (&optional arg)
2684 "Hide the signature in the current article.
2685 If given a negative prefix, always show; if given a positive prefix,
2687 (interactive (gnus-article-hidden-arg))
2688 (unless (gnus-article-check-hidden-text 'signature arg)
2691 (let ((inhibit-read-only t))
2692 (when (gnus-article-narrow-to-signature)
2693 (gnus-article-hide-text-type
2694 (point-min) (point-max) 'signature))))))
2695 (gnus-set-mode-line 'article))
2697 (defun article-strip-headers-in-body ()
2698 "Strip offensive headers from bodies."
2702 (let ((case-fold-search t))
2703 (when (looking-at "x-no-archive:")
2704 (gnus-delete-line)))))
2706 (defun article-strip-leading-blank-lines ()
2707 "Remove all blank lines from the beginning of the article."
2710 (let ((inhibit-point-motion-hooks t)
2711 (inhibit-read-only t))
2712 (when (article-goto-body)
2713 (while (and (not (eobp))
2714 (looking-at "[ \t]*$"))
2715 (gnus-delete-line))))))
2717 (defun article-narrow-to-head ()
2718 "Narrow the buffer to the head of the message.
2719 Point is left at the beginning of the narrowed-to region."
2721 (goto-char (point-min))
2722 (if (search-forward "\n\n" nil 1)
2725 (goto-char (point-min)))
2727 (defun article-goto-body ()
2728 "Place point at the start of the body."
2729 (goto-char (point-min))
2731 ;; This variable is only bound when dealing with separate
2733 (article-goto-body-goes-to-point-min-p
2735 ((search-forward "\n\n" nil t)
2738 (goto-char (point-max))
2741 (defun article-strip-multiple-blank-lines ()
2742 "Replace consecutive blank lines with one empty line."
2745 (let ((inhibit-point-motion-hooks t)
2746 (inhibit-read-only t))
2747 ;; First make all blank lines empty.
2749 (while (re-search-forward "^[ \t]+$" nil t)
2750 (unless (gnus-annotation-in-region-p
2751 (match-beginning 0) (match-end 0))
2752 (replace-match "" nil t)))
2753 ;; Then replace multiple empty lines with a single empty line.
2755 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2756 (unless (gnus-annotation-in-region-p
2757 (match-beginning 0) (match-end 0))
2758 (delete-region (match-beginning 1) (match-end 1)))))))
2760 (defun article-strip-leading-space ()
2761 "Remove all white space from the beginning of the lines in the article."
2764 (let ((inhibit-point-motion-hooks t)
2765 (inhibit-read-only t))
2767 (while (re-search-forward "^[ \t]+" nil t)
2768 (replace-match "" t t)))))
2770 (defun article-strip-trailing-space ()
2771 "Remove all white space from the end of the lines in the article."
2774 (let ((inhibit-point-motion-hooks t)
2775 (inhibit-read-only t))
2777 (while (re-search-forward "[ \t]+$" nil t)
2778 (replace-match "" t t)))))
2780 (defun article-strip-blank-lines ()
2781 "Strip leading, trailing and multiple blank lines."
2783 (article-strip-leading-blank-lines)
2784 (article-remove-trailing-blank-lines)
2785 (article-strip-multiple-blank-lines))
2787 (defun article-strip-all-blank-lines ()
2788 "Strip all blank lines."
2791 (let ((inhibit-point-motion-hooks t)
2792 (inhibit-read-only t))
2794 (while (re-search-forward "^[ \t]*\n" nil t)
2795 (replace-match "" t t)))))
2797 (defun gnus-article-narrow-to-signature ()
2798 "Narrow to the signature; return t if a signature is found, else nil."
2799 (let ((inhibit-point-motion-hooks t))
2800 (when (gnus-article-search-signature)
2802 ;; Check whether we have some limits to what we consider
2803 ;; to be a signature.
2804 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2805 (list gnus-signature-limit)))
2807 (while (setq limit (pop limits))
2808 (if (or (and (integerp limit)
2809 (< (- (point-max) (point)) limit))
2811 (< (count-lines (point) (point-max)) limit))
2812 (and (functionp limit)
2814 (and (stringp limit)
2815 (not (re-search-forward limit nil t))))
2816 () ; This limit did not succeed.
2820 (narrow-to-region (point) (point-max))
2823 (defun gnus-article-search-signature ()
2824 "Search the current buffer for the signature separator.
2825 Put point at the beginning of the signature separator."
2826 (let ((cur (point)))
2827 (goto-char (point-max))
2828 (if (if (stringp gnus-signature-separator)
2829 (re-search-backward gnus-signature-separator nil t)
2830 (let ((seps gnus-signature-separator))
2832 (not (re-search-backward (car seps) nil t)))
2839 (defun gnus-article-hidden-arg ()
2840 "Return the current prefix arg as a number, or 0 if no prefix."
2841 (list (if current-prefix-arg
2842 (prefix-numeric-value current-prefix-arg)
2845 (defun gnus-article-check-hidden-text (type arg)
2846 "Return nil if hiding is necessary.
2847 Arg can be nil or a number. nil and positive means hide, negative
2848 means show, 0 means toggle."
2851 (let ((hide (gnus-article-hidden-text-p type)))
2857 (gnus-article-show-hidden-text type)
2860 (if (eq hide 'hidden)
2862 (gnus-article-show-hidden-text type)
2866 (defun gnus-article-hidden-text-p (type)
2867 "Say whether the current buffer contains hidden text of type TYPE."
2868 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2870 (not (get-text-property pos 'invisible))
2871 (not (get-text-property pos 'dummy-invisible)))
2873 (text-property-any (1+ pos) (point-max) 'article-type type)))
2878 (defun gnus-article-show-hidden-text (type &optional dummy)
2879 "Show all hidden text of type TYPE.
2880 Originally it is hide instead of DUMMY."
2881 (let ((inhibit-read-only t)
2882 (inhibit-point-motion-hooks t))
2883 (gnus-remove-text-properties-when
2885 (point-min) (point-max)
2886 (cons 'article-type (cons type
2887 gnus-hidden-properties)))
2888 (gnus-delete-wash-type type)))
2890 (defconst article-time-units
2891 `((year . ,(* 365.25 24 60 60))
2892 (week . ,(* 7 24 60 60))
2893 (day . ,(* 24 60 60))
2897 "Mapping from time units to seconds.")
2899 (defun gnus-article-forward-header ()
2900 "Move point to the start of the next header.
2901 If the current header is a continuation header, this can be several
2906 (if (looking-at "[ \t]+[^ \t]")
2910 (defun article-date-ut (&optional type highlight)
2911 "Convert DATE date to universal time in the current article.
2912 If TYPE is `local', convert to local time; if it is `lapsed', output
2913 how much time has lapsed since DATE. For `lapsed', the value of
2914 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2915 should replace the \"Date:\" one, or should be added below it."
2916 (interactive (list 'ut t))
2917 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2918 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
2922 (article-lapsed-timer
2926 (case-fold-search t)
2927 (inhibit-read-only t)
2928 (inhibit-point-motion-hooks t)
2929 pos date bface eface)
2933 (goto-char (point-min))
2934 (while (or (setq date (get-text-property (setq pos (point))
2936 (when (setq pos (next-single-property-change
2937 (point) 'original-date))
2938 (setq date (get-text-property pos 'original-date))
2940 (narrow-to-region pos (or (text-property-any pos (point-max)
2943 (goto-char (point-min))
2944 (when (re-search-forward tdate-regexp nil t)
2945 (setq bface (get-text-property (point-at-bol) 'face)
2946 eface (get-text-property (1- (point-at-eol)) 'face)))
2947 (goto-char (point-min))
2949 ;; Delete any old Date headers.
2950 (while (re-search-forward date-regexp nil t)
2952 (delete-region (point-at-bol) (progn
2953 (gnus-article-forward-header)
2955 (delete-region (point-at-bol) (progn
2956 (gnus-article-forward-header)
2959 (setq pos (point))))
2960 (when (and (not pos)
2961 (re-search-forward tdate-regexp nil t))
2963 (gnus-goto-char pos)
2964 (insert (article-make-date-line date (or type 'ut)))
2970 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2971 (put-text-property (match-beginning 1) (1+ (match-end 1))
2973 (put-text-property (match-beginning 2) (match-end 2)
2975 (put-text-property (point-min) (1- (point-max)) 'original-date date)
2976 (goto-char (point-max))
2979 (defun article-make-date-line (date type)
2980 "Return a DATE line of TYPE."
2981 (unless (memq type '(local ut original user iso8601 lapsed english))
2982 (error "Unknown conversion type: %s" type))
2984 (let ((time (date-to-time date)))
2986 ;; Convert to the local timezone.
2988 (concat "Date: " (message-make-date time)))
2989 ;; Convert to Universal Time.
2994 (let* ((e (parse-time-string date))
2995 (tm (apply 'encode-time e))
2997 (ls (- (cadr tm) (car (current-time-zone time)))))
2998 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2999 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3003 ;; Get the original date from the article.
3004 ((eq type 'original)
3005 (concat "Date: " (if (string-match "\n+$" date)
3006 (substring date 0 (match-beginning 0))
3008 ;; Let the user define the format.
3010 (let ((format (or (condition-case nil
3011 (with-current-buffer gnus-summary-buffer
3012 gnus-article-time-format)
3014 gnus-article-time-format)))
3015 (if (functionp format)
3016 (funcall format time)
3017 (concat "Date: " (format-time-string format time)))))
3020 (let ((tz (car (current-time-zone time))))
3023 (format-time-string "%Y%m%dT%H%M%S" time)
3024 (format "%s%02d%02d"
3025 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3026 (/ (% (abs tz) 3600) 60)))))
3027 ;; Do an X-Sent lapsed format.
3029 ;; If the date is seriously mangled, the timezone functions are
3030 ;; liable to bug out, so we ignore all errors.
3031 (let* ((now (current-time))
3032 (real-time (subtract-time now time))
3033 (real-sec (and real-time
3034 (+ (* (float (car real-time)) 65536)
3036 (sec (and real-time (abs real-sec)))
3046 ;; This is a bit convoluted, but basically we go
3047 ;; through the time units for years, weeks, etc,
3048 ;; and divide things to see whether that results
3049 ;; in positive answers.
3052 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3053 ;; The (remaining) seconds are too few to
3054 ;; be divided into this time unit.
3056 ;; It's big enough, so we output it.
3057 (setq sec (- sec (* num (cdr unit))))
3059 (concat (if prev ", " "") (int-to-string
3061 " " (symbol-name (car unit))
3062 (if (> num 1) "s" ""))
3064 article-time-units "")
3065 ;; If dates are odd, then it might appear like the
3066 ;; article was sent in the future.
3069 " in the future"))))))
3070 ;; Display the date in proper English
3072 (let ((dtime (decode-time time)))
3075 (number-to-string (nth 3 dtime))
3076 (let ((digit (% (nth 3 dtime) 10)))
3078 ((memq (nth 3 dtime) '(11 12 13)) "th")
3084 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3086 (number-to-string (nth 5 dtime))
3088 (format "%02d" (nth 2 dtime))
3090 (format "%02d" (nth 1 dtime)))))))
3092 (format "Date: %s (from Gnus)" date))))
3094 (defun article-date-local (&optional highlight)
3095 "Convert the current article date to the local timezone."
3096 (interactive (list t))
3097 (article-date-ut 'local highlight))
3099 (defun article-date-english (&optional highlight)
3100 "Convert the current article date to something that is proper English."
3101 (interactive (list t))
3102 (article-date-ut 'english highlight))
3104 (defun article-date-original (&optional highlight)
3105 "Convert the current article date to what it was originally.
3106 This is only useful if you have used some other date conversion
3107 function and want to see what the date was before converting."
3108 (interactive (list t))
3109 (article-date-ut 'original highlight))
3111 (defun article-date-lapsed (&optional highlight)
3112 "Convert the current article date to time lapsed since it was sent."
3113 (interactive (list t))
3114 (article-date-ut 'lapsed highlight))
3116 (defun article-update-date-lapsed ()
3117 "Function to be run from a timer to update the lapsed time line."
3119 (let (deactivate-mark)
3124 (set-buffer (window-buffer w))
3125 (when (eq major-mode 'gnus-article-mode)
3126 (let ((mark (point-marker)))
3127 (goto-char (point-min))
3128 (when (re-search-forward "^X-Sent:" nil t)
3129 (article-date-lapsed t))
3130 (goto-char (marker-position mark))
3131 (move-marker mark nil))))
3134 (defun gnus-start-date-timer (&optional n)
3135 "Start a timer to update the X-Sent header in the article buffers.
3136 The numerical prefix says how frequently (in seconds) the function
3141 (gnus-stop-date-timer)
3142 (setq article-lapsed-timer
3143 (run-at-time 1 n 'article-update-date-lapsed)))
3145 (defun gnus-stop-date-timer ()
3146 "Stop the X-Sent timer."
3148 (when article-lapsed-timer
3149 (nnheader-cancel-timer article-lapsed-timer)
3150 (setq article-lapsed-timer nil)))
3152 (defun article-date-user (&optional highlight)
3153 "Convert the current article date to the user-defined format.
3154 This format is defined by the `gnus-article-time-format' variable."
3155 (interactive (list t))
3156 (article-date-ut 'user highlight))
3158 (defun article-date-iso8601 (&optional highlight)
3159 "Convert the current article date to ISO8601."
3160 (interactive (list t))
3161 (article-date-ut 'iso8601 highlight))
3163 (defmacro gnus-article-save-original-date (&rest forms)
3164 "Save the original date as a text property and evaluate FORMS."
3165 `(let* ((case-fold-search t)
3167 (goto-char (point-min))
3168 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3171 (date (when (and start
3172 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3174 (buffer-substring-no-properties start
3175 (match-beginning 0)))))
3176 (goto-char (point-max))
3177 (skip-chars-backward "\n")
3178 (put-text-property (point-min) (point) 'original-date date)
3180 (goto-char (point-max))
3181 (skip-chars-backward "\n")
3182 (put-text-property (point-min) (point) 'original-date date)))
3184 ;; (defun article-show-all ()
3185 ;; "Show all hidden text in the article buffer."
3188 ;; (let ((inhibit-read-only t))
3189 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3191 (defun article-remove-leading-whitespace ()
3192 "Remove excessive whitespace from all headers."
3196 (let ((inhibit-read-only t))
3197 (article-narrow-to-head)
3198 (goto-char (point-min))
3199 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3200 (delete-region (match-beginning 1) (match-end 1)))))))
3202 (defun article-emphasize (&optional arg)
3203 "Emphasize text according to `gnus-emphasis-alist'."
3204 (interactive (gnus-article-hidden-arg))
3205 (unless (gnus-article-check-hidden-text 'emphasis arg)
3209 (with-current-buffer gnus-summary-buffer
3210 gnus-article-emphasis-alist)
3212 gnus-emphasis-alist))
3213 (inhibit-read-only t)
3214 (props (append '(article-type emphasis)
3215 gnus-hidden-properties))
3216 regexp elem beg invisible visible face)
3219 (while (setq elem (pop alist))
3221 (setq regexp (car elem)
3222 invisible (nth 1 elem)
3223 visible (nth 2 elem)
3225 (while (re-search-forward regexp nil t)
3226 (when (and (match-beginning visible) (match-beginning invisible))
3227 (gnus-article-hide-text
3228 (match-beginning invisible) (match-end invisible) props)
3229 (gnus-article-unhide-text-type
3230 (match-beginning visible) (match-end visible) 'emphasis)
3231 (gnus-put-overlay-excluding-newlines
3232 (match-beginning visible) (match-end visible) 'face face)
3233 (gnus-add-wash-type 'emphasis)
3234 (goto-char (match-end invisible)))))))))
3236 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3237 "Setup newsgroup emphasis alist."
3238 (unless gnus-article-emphasis-alist
3239 (let ((name (and gnus-newsgroup-name
3240 (gnus-group-real-name gnus-newsgroup-name))))
3241 (make-local-variable 'gnus-article-emphasis-alist)
3242 (setq gnus-article-emphasis-alist
3244 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3245 (while (setq elem (pop alist))
3246 (when (and name (string-match (car elem) name))
3248 highlight (copy-sequence (cdr elem)))))
3250 (copy-sequence highlight-words)
3251 (if gnus-newsgroup-name
3252 (copy-sequence (gnus-group-find-parameter
3253 gnus-newsgroup-name 'highlight-words t)))
3254 gnus-emphasis-alist)))))
3257 (defvar gnus-summary-article-menu)
3258 (defvar gnus-summary-post-menu))
3260 ;;; Saving functions.
3262 (defun gnus-article-save (save-buffer file &optional num)
3263 "Save the currently selected article."
3264 (unless gnus-save-all-headers
3265 ;; Remove headers according to `gnus-saved-headers'.
3266 (let ((gnus-visible-headers
3267 (or gnus-saved-headers gnus-visible-headers))
3268 (gnus-article-buffer save-buffer))
3270 (set-buffer save-buffer)
3271 (article-hide-headers 1 t))))
3272 (save-window-excursion
3273 (if (not gnus-default-article-saver)
3274 (error "No default saver is defined")
3275 ;; !!! Magic! The saving functions all save
3276 ;; `gnus-save-article-buffer' (or so they think), but we
3277 ;; bind that variable to our save-buffer.
3278 (set-buffer gnus-article-buffer)
3279 (let* ((gnus-save-article-buffer save-buffer)
3282 ((not gnus-prompt-before-saving) 'default)
3283 ((eq gnus-prompt-before-saving 'always) nil)
3285 (gnus-number-of-articles-to-be-saved
3286 (when (eq gnus-prompt-before-saving t)
3288 (set-buffer gnus-article-current-summary)
3289 (funcall gnus-default-article-saver filename)))))
3291 (defun gnus-read-save-file-name (prompt &optional filename
3292 function group headers variable)
3294 (funcall function group headers (symbol-value variable)))
3299 ((eq filename 'default)
3305 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3308 (if (and gnus-number-of-articles-to-be-saved
3309 (> gnus-number-of-articles-to-be-saved 1))
3310 (format "these %d articles"
3311 gnus-number-of-articles-to-be-saved)
3314 ;; Let the split methods have their say.
3316 ;; No split name was found.
3319 (concat prompt " (default "
3320 (file-name-nondirectory default-name) "): ")
3321 (file-name-directory default-name)
3323 ;; A single group name is returned.
3324 ((stringp split-name)
3326 (funcall function split-name headers
3327 (symbol-value variable)))
3329 (concat prompt " (default "
3330 (file-name-nondirectory default-name) "): ")
3331 (file-name-directory default-name)
3333 ;; A single split name was found
3334 ((= 1 (length split-name))
3335 (let* ((name (expand-file-name
3337 gnus-article-save-directory))
3338 (dir (cond ((file-directory-p name)
3339 (file-name-as-directory name))
3340 ((file-exists-p name) name)
3341 (t gnus-article-save-directory))))
3343 (concat prompt " (default " name "): ")
3345 ;; A list of splits was found.
3347 (setq split-name (nreverse split-name))
3349 (let ((file-name-history
3350 (nconc split-name file-name-history)))
3354 (concat prompt " (`M-p' for defaults): ")
3355 gnus-article-save-directory
3357 gnus-article-save-directory)))
3358 (car (push result file-name-history)))))))
3359 ;; Create the directory.
3360 (gnus-make-directory (file-name-directory file))
3361 ;; If we have read a directory, we append the default file name.
3362 (when (file-directory-p file)
3363 (setq file (expand-file-name (file-name-nondirectory
3365 (file-name-as-directory file))))
3366 ;; Possibly translate some characters.
3367 (nnheader-translate-file-chars file))))))
3368 (gnus-make-directory (file-name-directory result))
3369 (set variable result)))
3371 (defun gnus-article-archive-name (group)
3372 "Return the first instance of an \"Archive-name\" in the current buffer."
3373 (let ((case-fold-search t))
3374 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3375 (nnheader-concat gnus-article-save-directory
3376 (match-string 1)))))
3378 (defun gnus-article-nndoc-name (group)
3379 "If GROUP is an nndoc group, return the name of the parent group."
3380 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3381 (gnus-group-get-parameter group 'save-article-group)))
3383 (defun gnus-summary-save-in-rmail (&optional filename)
3384 "Append this article to Rmail file.
3385 Optional argument FILENAME specifies file name.
3386 Directory to save to is default to `gnus-article-save-directory'."
3387 (setq filename (gnus-read-save-file-name
3388 "Save %s in rmail file" filename
3389 gnus-rmail-save-name gnus-newsgroup-name
3390 gnus-current-headers 'gnus-newsgroup-last-rmail))
3391 (gnus-eval-in-buffer-window gnus-save-article-buffer
3395 (gnus-output-to-rmail filename))))
3398 (defun gnus-summary-save-in-mail (&optional filename)
3399 "Append this article to Unix mail file.
3400 Optional argument FILENAME specifies file name.
3401 Directory to save to is default to `gnus-article-save-directory'."
3402 (setq filename (gnus-read-save-file-name
3403 "Save %s in Unix mail file" filename
3404 gnus-mail-save-name gnus-newsgroup-name
3405 gnus-current-headers 'gnus-newsgroup-last-mail))
3406 (gnus-eval-in-buffer-window gnus-save-article-buffer
3410 (if (and (file-readable-p filename)
3411 (file-regular-p filename)
3412 (mail-file-babyl-p filename))
3413 (rmail-output-to-rmail-file filename t)
3414 (gnus-output-to-mail filename)))))
3417 (defun gnus-summary-save-in-file (&optional filename overwrite)
3418 "Append this article to file.
3419 Optional argument FILENAME specifies file name.
3420 Directory to save to is default to `gnus-article-save-directory'."
3421 (setq filename (gnus-read-save-file-name
3422 "Save %s in file" filename
3423 gnus-file-save-name gnus-newsgroup-name
3424 gnus-current-headers 'gnus-newsgroup-last-file))
3425 (gnus-eval-in-buffer-window gnus-save-article-buffer
3429 (when (and overwrite
3430 (file-exists-p filename))
3431 (delete-file filename))
3432 (gnus-output-to-file filename))))
3435 (defun gnus-summary-write-to-file (&optional filename)
3436 "Write this article to a file, overwriting it if the file exists.
3437 Optional argument FILENAME specifies file name.
3438 The directory to save in defaults to `gnus-article-save-directory'."
3439 (gnus-summary-save-in-file nil t))
3441 (defun gnus-summary-save-body-in-file (&optional filename)
3442 "Append this article body to a file.
3443 Optional argument FILENAME specifies file name.
3444 The directory to save in defaults to `gnus-article-save-directory'."
3445 (setq filename (gnus-read-save-file-name
3446 "Save %s body in file" filename
3447 gnus-file-save-name gnus-newsgroup-name
3448 gnus-current-headers 'gnus-newsgroup-last-file))
3449 (gnus-eval-in-buffer-window gnus-save-article-buffer
3453 (when (article-goto-body)
3454 (narrow-to-region (point) (point-max)))
3455 (gnus-output-to-file filename))))
3458 (defun gnus-summary-save-in-pipe (&optional command)
3459 "Pipe this article to subprocess."
3461 (cond ((and (eq command 'default)
3462 gnus-last-shell-command)
3463 gnus-last-shell-command)
3468 "Shell command on %s: "
3469 (if (and gnus-number-of-articles-to-be-saved
3470 (> gnus-number-of-articles-to-be-saved 1))
3471 (format "these %d articles"
3472 gnus-number-of-articles-to-be-saved)
3474 gnus-last-shell-command))))
3475 (when (string-equal command "")
3476 (if gnus-last-shell-command
3477 (setq command gnus-last-shell-command)
3478 (error "A command is required")))
3479 (gnus-eval-in-buffer-window gnus-article-buffer
3482 (shell-command-on-region (point-min) (point-max) command nil)))
3483 (setq gnus-last-shell-command command))
3485 (defun gnus-summary-pipe-to-muttprint (&optional command)
3486 "Pipe this article to muttprint."
3487 (setq command (read-string
3488 "Print using command: " gnus-summary-muttprint-program
3489 nil gnus-summary-muttprint-program))
3490 (gnus-summary-save-in-pipe command))
3492 ;;; Article file names when saving.
3494 (defun gnus-capitalize-newsgroup (newsgroup)
3495 "Capitalize NEWSGROUP name."
3496 (when (not (zerop (length newsgroup)))
3497 (concat (char-to-string (upcase (aref newsgroup 0)))
3498 (substring newsgroup 1))))
3500 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3501 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3502 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3503 Otherwise, it is like ~/News/news/group/num."
3506 (concat (if (gnus-use-long-file-name 'not-save)
3507 (gnus-capitalize-newsgroup newsgroup)
3508 (gnus-newsgroup-directory-form newsgroup))
3509 "/" (int-to-string (mail-header-number headers)))
3510 gnus-article-save-directory)))
3512 (string-equal (file-name-directory default)
3513 (file-name-directory last-file))
3514 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3516 (or last-file default))))
3518 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3519 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3520 If variable `gnus-use-long-file-name' is non-nil, it is
3521 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3524 (concat (if (gnus-use-long-file-name 'not-save)
3526 (gnus-newsgroup-directory-form newsgroup))
3527 "/" (int-to-string (mail-header-number headers)))
3528 gnus-article-save-directory)))
3530 (string-equal (file-name-directory default)
3531 (file-name-directory last-file))
3532 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3534 (or last-file default))))
3536 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3537 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3538 If variable `gnus-use-long-file-name' is non-nil, it is
3539 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3542 (if (gnus-use-long-file-name 'not-save)
3545 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3547 gnus-article-save-directory)))
3549 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3550 "Generate file name from sender."
3551 (let ((from (mail-header-from headers)))
3553 (if (and from (string-match "\\([^ <]+\\)@" from))
3554 (match-string 1 from)
3556 gnus-article-save-directory)))
3558 (defun article-verify-x-pgp-sig ()
3561 (if (gnus-buffer-live-p gnus-original-article-buffer)
3562 (let ((sig (with-current-buffer gnus-original-article-buffer
3563 (gnus-fetch-field "X-PGP-Sig")))
3567 (mml2015-clear-verify-function))
3569 (insert-buffer-substring gnus-original-article-buffer)
3570 (setq items (split-string sig))
3571 (message-narrow-to-head)
3572 (let ((inhibit-point-motion-hooks t)
3573 (case-fold-search t))
3574 ;; Don't verify multiple headers.
3575 (setq headers (mapconcat (lambda (header)
3577 (mail-fetch-field header)
3579 (split-string (nth 1 items) ",") "")))
3580 (delete-region (point-min) (point-max))
3581 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3582 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3587 (if (looking-at "^-")
3590 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3591 (insert "Version: " (car items) "\n\n")
3592 (insert (mapconcat 'identity (cddr items) "\n"))
3593 (insert "\n-----END PGP SIGNATURE-----\n")
3594 (let ((mm-security-handle (list (format "multipart/signed"))))
3595 (mml2015-clean-buffer)
3596 (let ((coding-system-for-write (or gnus-newsgroup-charset
3598 (funcall (mml2015-clear-verify-function)))
3600 (or (mm-handle-multipart-ctl-parameter
3601 mm-security-handle 'gnus-details)
3602 (mm-handle-multipart-ctl-parameter
3603 mm-security-handle 'gnus-info)))))
3605 (let ((inhibit-read-only t) bface eface)
3607 (message-narrow-to-head)
3608 (goto-char (point-max))
3610 (setq bface (get-text-property (point-at-bol) 'face)
3611 eface (get-text-property (1- (point-at-eol)) 'face))
3612 (message-remove-header "X-Gnus-PGP-Verify")
3613 (if (re-search-forward "^X-PGP-Sig:" nil t)
3615 (goto-char (point-max)))
3616 (narrow-to-region (point) (point))
3617 (insert "X-Gnus-PGP-Verify: " info "\n")
3618 (goto-char (point-min))
3621 (if (not (looking-at "^[ \t]"))
3625 (goto-char (point-min))
3626 (when (looking-at "\\([^:]+\\): *")
3627 (put-text-property (match-beginning 1) (1+ (match-end 1))
3629 (put-text-property (match-end 0) (point-max)
3630 'face eface)))))))))
3632 (defun article-verify-cancel-lock ()
3633 "Verify Cancel-Lock header."
3635 (if (gnus-buffer-live-p gnus-original-article-buffer)
3636 (canlock-verify gnus-original-article-buffer)))
3643 (setq afunc (car func)
3646 gfunc (intern (format "gnus-%s" func))))
3648 (when (fboundp afunc)
3649 `(lambda (&optional interactive &rest args)
3650 ,(documentation afunc t)
3651 (interactive (list t))
3653 (set-buffer gnus-article-buffer)
3655 (call-interactively ',afunc)
3656 (apply ',afunc args))))))))
3657 '(article-hide-headers
3658 article-verify-x-pgp-sig
3659 article-verify-cancel-lock
3660 article-hide-boring-headers
3661 article-treat-overstrike
3662 article-treat-ansi-sequences
3663 article-fill-long-lines
3664 article-capitalize-sentences
3666 article-remove-leading-whitespace
3667 article-display-x-face
3668 article-display-face
3669 article-de-quoted-unreadable
3670 article-de-base64-unreadable
3673 article-unsplit-urls
3674 article-hide-list-identifiers
3675 article-strip-banner
3678 article-hide-signature
3679 article-strip-headers-in-body
3680 article-remove-trailing-blank-lines
3681 article-strip-leading-blank-lines
3682 article-strip-multiple-blank-lines
3683 article-strip-leading-space
3684 article-strip-trailing-space
3685 article-strip-blank-lines
3686 article-strip-all-blank-lines
3688 article-date-english
3689 article-date-iso8601
3690 article-date-original
3692 article-decode-mime-words
3693 article-decode-charset
3694 article-decode-encoded-words
3698 article-treat-dumbquotes
3699 article-normalize-headers
3700 ;; (article-show-all . gnus-article-show-all-headers)
3704 ;;; Gnus article mode
3707 (put 'gnus-article-mode 'mode-class 'special)
3709 (set-keymap-parent gnus-article-mode-map widget-keymap)
3711 (gnus-define-keys gnus-article-mode-map
3712 " " gnus-article-goto-next-page
3713 "\177" gnus-article-goto-prev-page
3714 [delete] gnus-article-goto-prev-page
3715 [backspace] gnus-article-goto-prev-page
3716 "\C-c^" gnus-article-refer-article
3717 "h" gnus-article-show-summary
3718 "s" gnus-article-show-summary
3719 "\C-c\C-m" gnus-article-mail
3720 "?" gnus-article-describe-briefly
3721 "e" gnus-summary-edit-article
3722 "<" beginning-of-buffer
3724 "\C-c\C-i" gnus-info-find-node
3726 "R" gnus-article-reply-with-original
3727 "F" gnus-article-followup-with-original
3728 "\C-hk" gnus-article-describe-key
3729 "\C-hc" gnus-article-describe-key-briefly
3731 "\C-d" gnus-article-read-summary-keys
3732 "\M-*" gnus-article-read-summary-keys
3733 "\M-#" gnus-article-read-summary-keys
3734 "\M-^" gnus-article-read-summary-keys
3735 "\M-g" gnus-article-read-summary-keys)
3737 (substitute-key-definition
3738 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3740 (defun gnus-article-make-menu-bar ()
3741 (unless (boundp 'gnus-article-commands-menu)
3742 (gnus-summary-make-menu-bar))
3743 (gnus-turn-off-edit-menu 'article)
3744 (unless (boundp 'gnus-article-article-menu)
3746 gnus-article-article-menu gnus-article-mode-map ""
3748 ["Scroll forwards" gnus-article-goto-next-page t]
3749 ["Scroll backwards" gnus-article-goto-prev-page t]
3750 ["Show summary" gnus-article-show-summary t]
3751 ["Fetch Message-ID at point" gnus-article-refer-article t]
3752 ["Mail to address at point" gnus-article-mail t]
3753 ["Send a bug report" gnus-bug t]))
3756 gnus-article-treatment-menu gnus-article-mode-map ""
3757 ;; Fixme: this should use :active (and maybe :visible).
3759 ["Hide headers" gnus-article-hide-headers t]
3760 ["Hide signature" gnus-article-hide-signature t]
3761 ["Hide citation" gnus-article-hide-citation t]
3762 ["Treat overstrike" gnus-article-treat-overstrike t]
3763 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3764 ["Remove carriage return" gnus-article-remove-cr t]
3765 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3766 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3767 ["Remove base64" gnus-article-de-base64-unreadable t]
3768 ["Treat html" gnus-article-wash-html t]
3769 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3770 ["Decode HZ" gnus-article-decode-HZ t]))
3772 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3774 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3776 (gnus-run-hooks 'gnus-article-menu-hook)))
3778 (defun gnus-article-mode ()
3779 "Major mode for displaying an article.
3781 All normal editing commands are switched off.
3783 The following commands are available in addition to all summary mode
3785 \\<gnus-article-mode-map>
3786 \\[gnus-article-next-page]\t Scroll the article one page forwards
3787 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3788 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3789 \\[gnus-article-show-summary]\t Display the summary buffer
3790 \\[gnus-article-mail]\t Send a reply to the address near point
3791 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3792 \\[gnus-info-find-node]\t Go to the Gnus info node"
3794 (kill-all-local-variables)
3795 (gnus-simplify-mode-line)
3796 (setq mode-name "Article")
3797 (setq major-mode 'gnus-article-mode)
3798 (make-local-variable 'minor-mode-alist)
3799 (use-local-map gnus-article-mode-map)
3800 (when (gnus-visual-p 'article-menu 'menu)
3801 (gnus-article-make-menu-bar)
3802 (when gnus-summary-tool-bar-map
3803 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3804 (gnus-update-format-specifications nil 'article-mode)
3805 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3806 (set (make-local-variable 'gnus-page-broken) nil)
3807 (make-local-variable 'gnus-button-marker-list)
3808 (make-local-variable 'gnus-article-current-summary)
3809 (make-local-variable 'gnus-article-mime-handles)
3810 (make-local-variable 'gnus-article-decoded-p)
3811 (make-local-variable 'gnus-article-mime-handle-alist)
3812 (make-local-variable 'gnus-article-wash-types)
3813 (make-local-variable 'gnus-article-image-alist)
3814 (make-local-variable 'gnus-article-charset)
3815 (make-local-variable 'gnus-article-ignored-charsets)
3816 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
3817 (set (make-local-variable 'nobreak-char-display) nil)
3818 (gnus-set-default-directory)
3819 (buffer-disable-undo)
3820 (setq buffer-read-only t
3821 show-trailing-whitespace nil)
3822 (set-syntax-table gnus-article-mode-syntax-table)
3823 (mm-enable-multibyte)
3824 (gnus-run-mode-hooks 'gnus-article-mode-hook))
3826 (defun gnus-article-setup-buffer ()
3827 "Initialize the article buffer."
3828 (let* ((name (if gnus-single-article-buffer "*Article*"
3829 (concat "*Article " gnus-newsgroup-name "*")))
3831 (progn (string-match "\\*Article" name)
3832 (concat " *Original Article"
3833 (substring name (match-end 0))))))
3834 (setq gnus-article-buffer name)
3835 (setq gnus-original-article-buffer original)
3836 (setq gnus-article-mime-handle-alist nil)
3837 ;; This might be a variable local to the summary buffer.
3838 (unless gnus-single-article-buffer
3840 (set-buffer gnus-summary-buffer)
3841 (setq gnus-article-buffer name)
3842 (setq gnus-original-article-buffer original)
3843 (gnus-set-global-variables)))
3844 (gnus-article-setup-highlight-words)
3845 ;; Init original article buffer.
3847 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3848 (mm-enable-multibyte)
3849 (setq major-mode 'gnus-original-article-mode)
3850 (make-local-variable 'gnus-original-article))
3851 (if (and (get-buffer name)
3852 (with-current-buffer name
3853 (if gnus-article-edit-mode
3854 (if (y-or-n-p "Article mode edit in progress; discard? ")
3856 (set-buffer-modified-p nil)
3857 (gnus-kill-buffer name)
3860 (error "Action aborted"))
3864 (set (make-local-variable 'gnus-article-edit-mode) nil)
3865 (when gnus-article-mime-handles
3866 (mm-destroy-parts gnus-article-mime-handles)
3867 (setq gnus-article-mime-handles nil))
3868 ;; Set it to nil in article-buffer!
3869 (setq gnus-article-mime-handle-alist nil)
3870 (buffer-disable-undo)
3871 (setq buffer-read-only t)
3872 ;; This list just keeps growing if we don't reset it.
3873 (setq gnus-button-marker-list nil)
3874 (unless (eq major-mode 'gnus-article-mode)
3875 (gnus-article-mode))
3878 (set-buffer (gnus-get-buffer-create name))
3880 (make-local-variable 'gnus-summary-buffer)
3881 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3882 (current-buffer)))))
3884 ;; Set article window start at LINE, where LINE is the number of lines
3885 ;; from the head of the article.
3886 (defun gnus-article-set-window-start (&optional line)
3888 (gnus-get-buffer-window gnus-article-buffer t)
3890 (set-buffer gnus-article-buffer)
3891 (goto-char (point-min))
3894 (gnus-message 6 "Moved to bookmark")
3895 (search-forward "\n\n" nil t)
3899 (defun gnus-article-prepare (article &optional all-headers header)
3900 "Prepare ARTICLE in article mode buffer.
3901 ARTICLE should either be an article number or a Message-ID.
3902 If ARTICLE is an id, HEADER should be the article headers.
3903 If ALL-HEADERS is non-nil, no headers are hidden."
3905 ;; Make sure we start in a summary buffer.
3906 (unless (eq major-mode 'gnus-summary-mode)
3907 (set-buffer gnus-summary-buffer))
3908 (setq gnus-summary-buffer (current-buffer))
3909 (let* ((gnus-article (if header (mail-header-number header) article))
3910 (summary-buffer (current-buffer))
3911 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3912 (group gnus-newsgroup-name)
3915 (gnus-article-setup-buffer)
3916 (set-buffer gnus-article-buffer)
3917 ;; Deactivate active regions.
3918 (when (and (boundp 'transient-mark-mode)
3919 transient-mark-mode)
3920 (setq mark-active nil))
3921 (if (not (setq result (let ((inhibit-read-only t))
3922 (gnus-request-article-this-buffer
3924 ;; There is no such article.
3926 (when (and (numberp article)
3927 (not (memq article gnus-newsgroup-sparse)))
3928 (setq gnus-article-current
3929 (cons gnus-newsgroup-name article))
3930 (set-buffer gnus-summary-buffer)
3931 (setq gnus-current-article article)
3932 (if (and (memq article gnus-newsgroup-undownloaded)
3933 (not (gnus-online (gnus-find-method-for-group
3934 gnus-newsgroup-name))))
3936 (gnus-summary-set-agent-mark article)
3937 (message "Message marked for downloading"))
3938 (gnus-summary-mark-article article gnus-canceled-mark)
3939 (unless (memq article gnus-newsgroup-sparse)
3940 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3941 (if (or (eq result 'pseudo)
3942 (eq result 'nneething))
3945 (set-buffer summary-buffer)
3946 (push article gnus-newsgroup-history)
3947 (setq gnus-last-article gnus-current-article
3948 gnus-current-article 0
3949 gnus-current-headers nil
3950 gnus-article-current nil)
3951 (if (eq result 'nneething)
3952 (gnus-configure-windows 'summary)
3953 (gnus-configure-windows 'article))
3954 (gnus-set-global-variables))
3955 (let ((gnus-article-mime-handle-alist-1
3956 gnus-article-mime-handle-alist))
3957 (gnus-set-mode-line 'article)))
3958 ;; The result from the `request' was an actual article -
3959 ;; or at least some text that is now displayed in the
3961 (when (and (numberp article)
3962 (not (eq article gnus-current-article)))
3963 ;; Seems like a new article has been selected.
3964 ;; `gnus-current-article' must be an article number.
3966 (set-buffer summary-buffer)
3967 (push article gnus-newsgroup-history)
3968 (setq gnus-last-article gnus-current-article
3969 gnus-current-article article
3970 gnus-current-headers
3971 (gnus-summary-article-header gnus-current-article)
3972 gnus-article-current
3973 (cons gnus-newsgroup-name gnus-current-article))
3974 (unless (vectorp gnus-current-headers)
3975 (setq gnus-current-headers nil))
3976 (gnus-summary-goto-subject gnus-current-article)
3977 (when (gnus-summary-show-thread)
3978 ;; If the summary buffer really was folded, the
3979 ;; previous goto may not actually have gone to
3980 ;; the right article, but the thread root instead.
3982 (gnus-summary-goto-subject gnus-current-article))
3983 (gnus-run-hooks 'gnus-mark-article-hook)
3984 (gnus-set-mode-line 'summary)
3985 (when (gnus-visual-p 'article-highlight 'highlight)
3986 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3987 ;; Set the global newsgroup variables here.
3988 (gnus-set-global-variables)
3989 (setq gnus-have-all-headers
3990 (or all-headers gnus-show-all-headers))))
3992 (gnus-configure-windows 'article))
3993 (when (or (numberp article)
3995 (gnus-article-prepare-display)
3997 (goto-char (point-min))
3998 (when gnus-break-pages
3999 (gnus-narrow-to-page)))
4000 (let ((gnus-article-mime-handle-alist-1
4001 gnus-article-mime-handle-alist))
4002 (gnus-set-mode-line 'article))
4006 (set-window-point (get-buffer-window (current-buffer)) (point))
4007 (gnus-configure-windows 'article)
4011 (defun gnus-article-prepare-display ()
4012 "Make the current buffer look like a nice article."
4013 ;; Hooks for getting information from the article.
4014 ;; This hook must be called before being narrowed.
4015 (let ((gnus-article-buffer (current-buffer))
4017 (inhibit-read-only t))
4018 (unless (eq major-mode 'gnus-article-mode)
4019 (gnus-article-mode))
4020 (setq buffer-read-only nil
4021 gnus-article-wash-types nil
4022 gnus-article-image-alist nil)
4023 (gnus-run-hooks 'gnus-tmp-internal-hook)
4024 (when gnus-display-mime-function
4025 (funcall gnus-display-mime-function))
4026 (gnus-run-hooks 'gnus-article-prepare-hook)))
4029 ;;; Gnus MIME viewing functions
4032 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4033 "Format of the MIME buttons.
4035 Valid specifiers include:
4037 %T MIME type, along with additional info
4038 %n The `name' parameter
4039 %d The description, if any
4040 %l The length of the encoded part
4041 %p The part identifier number
4042 %e Dots if the part isn't displayed
4044 General format specifiers can also be used. See Info node
4045 `(gnus)Formatting Variables'.")
4047 (defvar gnus-mime-button-line-format-alist
4048 '((?t gnus-tmp-type ?s)
4049 (?T gnus-tmp-type-long ?s)
4050 (?n gnus-tmp-name ?s)
4051 (?d gnus-tmp-description ?s)
4053 (?l gnus-tmp-length ?d)
4054 (?e gnus-tmp-dots ?s)))
4056 (defvar gnus-mime-button-commands
4057 '((gnus-article-press-button "\r" "Toggle Display")
4058 (gnus-mime-view-part "v" "View Interactively...")
4059 (gnus-mime-view-part-as-type "t" "View As Type...")
4060 (gnus-mime-view-part-as-charset "C" "View As charset...")
4061 (gnus-mime-save-part "o" "Save...")
4062 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4063 (gnus-mime-replace-part "r" "Replace part")
4064 (gnus-mime-delete-part "d" "Delete part")
4065 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4066 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4067 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4068 (gnus-mime-view-part-externally "e" "View Externally")
4069 (gnus-mime-print-part "p" "Print")
4070 (gnus-mime-pipe-part "|" "Pipe To Command...")
4071 (gnus-mime-action-on-part "." "Take action on the part...")))
4073 (defun gnus-article-mime-part-status ()
4074 (if gnus-article-mime-handle-alist-1
4075 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4077 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4080 (defvar gnus-mime-button-map
4081 (let ((map (make-sparse-keymap)))
4082 (define-key map gnus-mouse-2 'gnus-article-push-button)
4083 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4084 (dolist (c gnus-mime-button-commands)
4085 (define-key map (cadr c) (car c)))
4089 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4091 ,@(mapcar (lambda (c)
4092 (vector (caddr c) (car c) :enable t))
4093 gnus-mime-button-commands)))
4095 (defun gnus-mime-button-menu (event prefix)
4096 "Construct a context-sensitive menu of MIME commands."
4097 (interactive "e\nP")
4098 (save-window-excursion
4099 (let ((pos (event-start event)))
4100 (select-window (posn-window pos))
4101 (goto-char (posn-point pos))
4102 (gnus-article-check-buffer)
4103 (popup-menu gnus-mime-button-menu nil prefix))))
4105 (defun gnus-mime-view-all-parts (&optional handles)
4106 "View all the MIME parts."
4108 (with-current-buffer gnus-article-buffer
4109 (let ((handles (or handles gnus-article-mime-handles))
4110 (mail-parse-charset gnus-newsgroup-charset)
4111 (mail-parse-ignored-charsets
4112 (with-current-buffer gnus-summary-buffer
4113 gnus-newsgroup-ignored-charsets)))
4115 (mm-remove-parts handles)
4116 (goto-char (point-min))
4117 (or (search-forward "\n\n") (goto-char (point-max)))
4118 (let ((inhibit-read-only t))
4119 (delete-region (point) (point-max))
4120 (mm-display-parts handles))))))
4122 (defun gnus-article-jump-to-part (n)
4123 "Jump to MIME part N."
4125 (pop-to-buffer gnus-article-buffer)
4126 ;; FIXME: why is it necessary?
4128 (let ((parts (length gnus-article-mime-handle-alist)))
4131 (read-string ;; Emacs 21 doesn't have `read-number'.
4132 (format "Jump to part (2..%s): " parts)))))
4133 (unless (and (integerp n) (<= n parts) (>= n 1))
4136 (gnus-message 7 "Invalid part `%s', using %s instead."
4139 (gnus-message 9 "Jumping to part %s." n)
4140 (cond ((>= gnus-auto-select-part 1)
4141 (while (and (<= n parts)
4142 (not (gnus-article-goto-part n)))
4144 ((< gnus-auto-select-part 0)
4145 (while (and (>= n 1)
4146 (not (gnus-article-goto-part n)))
4149 (gnus-article-goto-part n)))))
4152 (defsubst gnus-article-edit-part (handles &optional current-id)
4153 "Edit an article in order to delete a mime part.
4154 This function is exclusively used by `gnus-mime-save-part-and-strip'
4155 and `gnus-mime-delete-part', and not provided at run-time normally."
4156 (gnus-article-edit-article
4158 (buffer-disable-undo)
4160 (let ((mail-parse-charset (or gnus-article-charset
4161 ',gnus-newsgroup-charset))
4162 (mail-parse-ignored-charsets
4163 (or gnus-article-ignored-charsets
4164 ',gnus-newsgroup-ignored-charsets))
4165 (mbl mml-buffer-list))
4166 (setq mml-buffer-list nil)
4167 (insert-buffer-substring gnus-original-article-buffer)
4168 (mime-to-mml ',handles)
4169 (setq gnus-article-mime-handles nil)
4170 (let ((mbl1 mml-buffer-list))
4171 (setq mml-buffer-list mbl)
4172 (set (make-local-variable 'mml-buffer-list) mbl1))
4173 (gnus-make-local-hook 'kill-buffer-hook)
4174 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4175 `(lambda (no-highlight)
4176 (let ((mail-parse-charset (or gnus-article-charset
4177 ',gnus-newsgroup-charset))
4178 (message-options message-options)
4179 (message-options-set-recipient)
4180 (mail-parse-ignored-charsets
4181 (or gnus-article-ignored-charsets
4182 ',gnus-newsgroup-ignored-charsets)))
4184 (mml-destroy-buffers)
4185 (remove-hook 'kill-buffer-hook
4186 'mml-destroy-buffers t)
4187 (kill-local-variable 'mml-buffer-list))
4188 (gnus-summary-edit-article-done
4189 ,(or (mail-header-references gnus-current-headers) "")
4190 ,(gnus-group-read-only-p)
4191 ,gnus-summary-buffer no-highlight))
4193 (gnus-article-edit-done)
4194 (gnus-summary-expand-window)
4195 (gnus-summary-show-article)
4196 (when (and current-id (integerp gnus-auto-select-part))
4197 (gnus-article-jump-to-part
4198 (+ current-id gnus-auto-select-part)))))
4200 (defun gnus-mime-replace-part (file)
4201 "Replace MIME part under point with an external body."
4202 ;; Useful if file has already been saved to disk
4206 (read-file-name "Replace MIME part with file: "
4207 (or mm-default-directory default-directory)
4209 (gnus-mime-save-part-and-strip file))
4211 (defun gnus-mime-save-part-and-strip (&optional file)
4212 "Save the MIME part under point then replace it with an external body.
4213 If FILE is given, use it for the external part."
4215 (gnus-article-check-buffer)
4216 (when (gnus-group-read-only-p)
4217 (error "The current group does not support deleting of parts"))
4218 (when (mm-complicated-handles gnus-article-mime-handles)
4220 The current article has a complicated MIME structure, giving up..."))
4221 (let* ((data (get-text-property (point) 'gnus-data))
4222 (id (get-text-property (point) 'gnus-part))
4224 (handles gnus-article-mime-handles))
4227 (and data (mm-save-part data "Delete MIME part and save to: "))))
4229 (with-current-buffer (mm-handle-buffer data)
4231 (insert "Content-Type: " (mm-handle-media-type data))
4232 (mml-insert-parameter-string (cdr (mm-handle-type data))
4235 (insert "Content-ID: " (message-make-message-id) "\n")
4236 (insert "Content-Transfer-Encoding: binary\n")
4239 (cdr (mm-make-handle nil
4240 `("message/external-body"
4241 (access-type . "LOCAL-FILE")
4243 ;; (set-buffer gnus-summary-buffer)
4244 (gnus-article-edit-part handles id))))
4246 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4247 ;; parts...>') but with stripping would be nice.
4249 (defun gnus-mime-delete-part ()
4250 "Delete the MIME part under point.
4251 Replace it with some information about the removed part."
4253 (gnus-article-check-buffer)
4254 (when (gnus-group-read-only-p)
4255 (error "The current group does not support deleting of parts"))
4256 (when (mm-complicated-handles gnus-article-mime-handles)
4258 The current article has a complicated MIME structure, giving up..."))
4259 (when (or gnus-expert-user
4260 (gnus-yes-or-no-p "\
4261 Deleting parts may malfunction or destroy the article; continue? "))
4262 (let* ((data (get-text-property (point) 'gnus-data))
4263 (id (get-text-property (point) 'gnus-part))
4264 (handles gnus-article-mime-handles)
4268 (mail-decode-encoded-word-string (or (mm-handle-description data)
4271 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4273 (type (mm-handle-media-type data)))
4275 (error "No MIME part under point"))
4276 (with-current-buffer (mm-handle-buffer data)
4277 (let ((bsize (format "%s" (buffer-size))))
4282 "| The following attachment has been deleted:\n"
4284 "| Type: " type "\n"
4285 "| Filename: " filename "\n"
4286 "| Size (encoded): " bsize " Byte\n"
4287 "| Description: " description "\n"
4290 (cdr (mm-make-handle
4291 nil `("text/plain") nil nil
4293 (format "Deleted attachment (%s bytes)" bsize))))))
4294 ;; (set-buffer gnus-summary-buffer)
4295 (gnus-article-edit-part handles id))))
4297 (defun gnus-mime-save-part ()
4298 "Save the MIME part under point."
4300 (gnus-article-check-buffer)
4301 (let ((data (get-text-property (point) 'gnus-data)))
4303 (mm-save-part data))))
4305 (defun gnus-mime-pipe-part ()
4306 "Pipe the MIME part under point to a process."
4308 (gnus-article-check-buffer)
4309 (let ((data (get-text-property (point) 'gnus-data)))
4311 (mm-pipe-part data))))
4313 (defun gnus-mime-view-part ()
4314 "Interactively choose a viewing method for the MIME part under point."
4316 (gnus-article-check-buffer)
4317 (let ((data (get-text-property (point) 'gnus-data)))
4319 (setq gnus-article-mime-handles
4321 gnus-article-mime-handles (setq data (copy-sequence data))))
4322 (mm-interactively-view-part data))))
4324 (defun gnus-mime-view-part-as-type-internal ()
4325 (gnus-article-check-buffer)
4326 (let* ((handle (get-text-property (point) 'gnus-data))
4328 ;; Content-Type: foo/bar; name=...
4329 (mail-content-type-get (mm-handle-type handle) 'name)
4330 ;; Content-Disposition: attachment; filename=...
4331 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4332 (def-type (and name (mm-default-file-encoding name))))
4333 (and def-type (cons def-type 0))))
4335 (defun gnus-mime-view-part-as-type (&optional mime-type)
4336 "Choose a MIME media type, and view the part as such."
4340 (let ((default (gnus-mime-view-part-as-type-internal)))
4342 (format "View as MIME type (default %s): "
4344 (mapcar #'list (mailcap-mime-types))
4347 (gnus-article-check-buffer)
4348 (let ((handle (get-text-property (point) 'gnus-data)))
4351 (mm-make-handle (mm-handle-buffer handle)
4352 (cons mime-type (cdr (mm-handle-type handle)))
4353 (mm-handle-encoding handle)
4354 (mm-handle-undisplayer handle)
4355 (mm-handle-disposition handle)
4356 (mm-handle-description handle)
4358 (mm-handle-id handle)))
4359 (setq gnus-article-mime-handles
4360 (mm-merge-handles gnus-article-mime-handles handle))
4361 (gnus-mm-display-part handle))))
4363 (defun gnus-mime-copy-part (&optional handle arg)
4364 "Put the MIME part under point into a new buffer.
4365 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4367 (interactive (list nil current-prefix-arg))
4368 (gnus-article-check-buffer)
4370 (setq handle (get-text-property (point) 'gnus-data)))
4372 (let ((filename (or (mail-content-type-get (mm-handle-disposition handle)
4374 (mail-content-type-get (mm-handle-disposition handle)
4376 contents dont-decode charset coding-system)
4377 (mm-with-unibyte-buffer
4378 (mm-insert-part handle)
4379 (setq contents (or (condition-case nil
4380 (mm-decompress-buffer filename nil 'sig)
4382 (setq dont-decode t)
4385 (setq filename (cond (filename (file-name-nondirectory filename))
4386 (dont-decode "*raw data*")
4391 (unless (setq charset (mail-content-type-get
4392 (mm-handle-type handle) 'charset))
4393 (unless (setq coding-system (mm-with-unibyte-buffer
4395 (mm-find-buffer-file-coding-system)))
4396 (setq charset gnus-newsgroup-charset))))
4398 (setq charset (or (cdr (assq arg
4399 gnus-summary-show-article-charset-alist))
4400 (mm-read-coding-system "Charset: ")))))
4401 (switch-to-buffer (generate-new-buffer filename))
4402 (if (or coding-system
4404 (setq coding-system (mm-charset-to-coding-system charset))
4405 (not (eq charset 'ascii))))
4407 (mm-enable-multibyte)
4408 (insert (mm-decode-coding-string contents coding-system))
4409 (setq buffer-file-coding-system
4410 (if (boundp 'last-coding-system-used)
4411 (symbol-value 'last-coding-system-used)
4413 (mm-disable-multibyte)
4415 (setq buffer-file-coding-system mm-binary-coding-system))
4416 ;; We do it this way to make `normal-mode' set the appropriate mode.
4419 (setq buffer-file-name (expand-file-name filename))
4421 (setq buffer-file-name nil))
4422 (goto-char (point-min)))))
4424 (defun gnus-mime-print-part (&optional handle filename)
4425 "Print the MIME part under point."
4426 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4427 (gnus-article-check-buffer)
4428 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4429 (contents (and handle (mm-get-part handle)))
4430 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4431 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4436 (mm-save-part-to-file handle file)
4437 (call-process shell-file-name nil
4438 (generate-new-buffer " *mm*")
4440 shell-command-switch
4442 printer file (mm-handle-type handle))))
4446 (gnus-print-buffer))
4447 (ps-despool filename)))))
4449 (defun gnus-mime-inline-part (&optional handle arg)
4450 "Insert the MIME part under point into the current buffer.
4451 Compressed files like .gz and .bz2 are decompressed."
4452 (interactive (list nil current-prefix-arg))
4453 (gnus-article-check-buffer)
4455 (setq handle (get-text-property (point) 'gnus-data)))
4458 (inhibit-read-only t)
4459 contents charset coding-system)
4460 (if (and (not arg) (mm-handle-undisplayer handle))
4461 (mm-remove-part handle)
4462 (mm-with-unibyte-buffer
4463 (mm-insert-part handle)
4465 (or (mm-decompress-buffer
4466 (or (mail-content-type-get (mm-handle-disposition handle)
4468 (mail-content-type-get (mm-handle-disposition handle)
4474 (unless (setq charset (mail-content-type-get
4475 (mm-handle-type handle) 'charset))
4476 (unless (setq coding-system
4477 (mm-with-unibyte-buffer
4479 (mm-find-buffer-file-coding-system)))
4480 (setq charset gnus-newsgroup-charset))))
4482 (if (mm-handle-undisplayer handle)
4483 (mm-remove-part handle))
4486 gnus-summary-show-article-charset-alist))
4487 (mm-read-coding-system "Charset: "))))
4489 (if (mm-handle-undisplayer handle)
4490 (mm-remove-part handle))))
4494 (if (or coding-system
4497 (mm-charset-to-coding-system charset))
4498 (not (eq coding-system 'ascii))))
4499 (mm-decode-coding-string contents coding-system)
4500 (mm-string-to-multibyte contents)))
4503 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4504 "Insert the MIME part under point into the current buffer using the
4506 (interactive (list nil current-prefix-arg))
4507 (gnus-article-check-buffer)
4508 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4511 (inhibit-read-only t))
4513 (if (mm-handle-undisplayer handle)
4514 (mm-remove-part handle))
4515 (let ((gnus-newsgroup-charset
4517 gnus-summary-show-article-charset-alist))
4518 (mm-read-coding-system "Charset: ")))
4519 (gnus-newsgroup-ignored-charsets 'gnus-all))
4520 (gnus-article-press-button)))))
4522 (defun gnus-mime-view-part-externally (&optional handle)
4523 "View the MIME part under point with an external viewer."
4525 (gnus-article-check-buffer)
4526 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4527 (mm-user-display-methods nil)
4528 (mm-inlined-types nil)
4529 (mail-parse-charset gnus-newsgroup-charset)
4530 (mail-parse-ignored-charsets
4531 (with-current-buffer gnus-summary-buffer
4532 gnus-newsgroup-ignored-charsets)))
4534 (if (mm-handle-undisplayer handle)
4535 (mm-remove-part handle)
4536 (mm-display-part handle)))))
4538 (defun gnus-mime-view-part-internally (&optional handle)
4539 "View the MIME part under point with an internal viewer.
4540 If no internal viewer is available, use an external viewer."
4542 (gnus-article-check-buffer)
4543 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4544 (mm-inlined-types '(".*"))
4545 (mm-inline-large-images t)
4546 (mail-parse-charset gnus-newsgroup-charset)
4547 (mail-parse-ignored-charsets
4548 (with-current-buffer gnus-summary-buffer
4549 gnus-newsgroup-ignored-charsets))
4550 (inhibit-read-only t))
4552 (if (mm-handle-undisplayer handle)
4553 (mm-remove-part handle)
4554 (mm-display-part handle)))))
4556 (defun gnus-mime-action-on-part (&optional action)
4557 "Do something with the MIME attachment at \(point\)."
4559 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4560 (gnus-article-check-buffer)
4561 (let ((action-pair (assoc action gnus-mime-action-alist)))
4563 (funcall (cdr action-pair)))))
4565 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
4566 "Call FUNCTION on MIME part N.
4567 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
4568 If INTERACTIVE, call FUNCTION interactivly."
4570 ;; Check whether the article is displayed.
4571 (unless (and (gnus-buffer-live-p gnus-article-buffer)
4572 (setq window (get-buffer-window gnus-article-buffer t))
4573 (frame-visible-p (setq frame (window-frame window))))
4574 (error "No article is displayed"))
4575 (with-current-buffer gnus-article-buffer
4576 ;; Check whether the article displays the right contents.
4577 (unless (with-current-buffer gnus-summary-buffer
4578 (eq gnus-current-article (gnus-summary-article-number)))
4579 (error "You should select the right article first"))
4580 ;; Check whether the specified part exists.
4581 (when (> n (length gnus-article-mime-handle-alist))
4582 (error "No such part")))
4585 ;; To select the window is needed so that the cursor
4586 ;; might be visible on the MIME button.
4587 (select-window (prog1
4589 (setq window (selected-window))
4590 ;; Article may be displayed in the other frame.
4591 (gnus-select-frame-set-input-focus
4594 (setq frame (selected-frame))))))
4595 (when (gnus-article-goto-part n)
4596 ;; We point the cursor and the arrow at the MIME button
4597 ;; when the `function' prompt the user for something.
4598 (let ((cursor-in-non-selected-windows t)
4599 (overlay-arrow-string "=>")
4600 (overlay-arrow-position (point-marker)))
4603 ((and no-handle interactive)
4604 (call-interactively function))
4610 (cdr (assq n gnus-article-mime-handle-alist))))
4613 (cdr (assq n gnus-article-mime-handle-alist)))))
4614 (set-marker overlay-arrow-position nil)
4615 (unless gnus-auto-select-part
4616 (gnus-select-frame-set-input-focus frame)
4617 (select-window window))))
4619 (if gnus-inhibit-mime-unbuttonizing
4620 ;; This is the default though the program shouldn't reach here.
4621 (error "No such part")
4622 ;; The part which doesn't have the MIME button is selected.
4623 ;; So, we display all the buttons and redo it.
4624 (let ((gnus-inhibit-mime-unbuttonizing t))
4625 (gnus-summary-show-article)
4626 (gnus-article-part-wrapper n function no-handle))))))
4628 (defun gnus-article-pipe-part (n)
4629 "Pipe MIME part N, which is the numerical prefix."
4631 (gnus-article-part-wrapper n 'mm-pipe-part))
4633 (defun gnus-article-save-part (n)
4634 "Save MIME part N, which is the numerical prefix."
4636 (gnus-article-part-wrapper n 'mm-save-part))
4638 (defun gnus-article-interactively-view-part (n)
4639 "View MIME part N interactively, which is the numerical prefix."
4641 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4643 (defun gnus-article-copy-part (n)
4644 "Copy MIME part N, which is the numerical prefix."
4646 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4648 (defun gnus-article-view-part-as-charset (n)
4649 "View MIME part N using a specified charset.
4650 N is the numerical prefix."
4652 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4654 (defun gnus-article-view-part-externally (n)
4655 "View MIME part N externally, which is the numerical prefix."
4657 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4659 (defun gnus-article-inline-part (n)
4660 "Inline MIME part N, which is the numerical prefix."
4662 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4664 (defun gnus-article-save-part-and-strip (n)
4665 "Save MIME part N and replace it with an external body.
4666 N is the numerical prefix."
4668 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
4670 (defun gnus-article-replace-part (n)
4671 "Replace MIME part N with an external body.
4672 N is the numerical prefix."
4674 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
4676 (defun gnus-article-delete-part (n)
4677 "Delete MIME part N and add some information about the removed part.
4678 N is the numerical prefix."
4680 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
4682 (defun gnus-article-mime-match-handle-first (condition)
4685 (dolist (ihandle gnus-article-mime-handle-alist)
4687 ((functionp condition)
4688 (funcall condition (cdr ihandle)))
4689 ((eq condition 'undisplayed)
4690 (not (or (mm-handle-undisplayer (cdr ihandle))
4691 (equal (mm-handle-media-type (cdr ihandle))
4692 "multipart/alternative"))))
4693 ((eq condition 'undisplayed-alternative)
4694 (not (mm-handle-undisplayer (cdr ihandle))))
4696 (gnus-article-goto-part (car ihandle))
4697 (or (not n) (< (car ihandle) n)))
4698 (setq n (car ihandle))))
4702 (defun gnus-article-view-part (&optional n)
4703 "View MIME part N, which is the numerical prefix."
4705 (with-current-buffer gnus-article-buffer
4706 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4707 gnus-article-mime-match-handle-function)))
4708 (when (> n (length gnus-article-mime-handle-alist))
4709 (error "No such part"))
4710 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4711 (when (gnus-article-goto-part n)
4712 (if (equal (car handle) "multipart/alternative")
4713 (gnus-article-press-button)
4714 (when (eq (gnus-mm-display-part handle) 'internal)
4715 (gnus-set-window-start)))))))
4717 (defsubst gnus-article-mime-total-parts ()
4718 (if (bufferp (car gnus-article-mime-handles))
4720 (1- (length gnus-article-mime-handles))))
4722 (defun gnus-mm-display-part (handle)
4723 "Display HANDLE and fix MIME button."
4724 (let ((id (get-text-property (point) 'gnus-part))
4726 (inhibit-read-only t))
4729 (let ((window (selected-window))
4730 (mail-parse-charset gnus-newsgroup-charset)
4731 (mail-parse-ignored-charsets
4732 (if (gnus-buffer-live-p gnus-summary-buffer)
4733 (with-current-buffer gnus-summary-buffer
4734 gnus-newsgroup-ignored-charsets)
4738 (let ((win (gnus-get-buffer-window (current-buffer) t))
4741 (select-window win))
4744 (if (mm-handle-displayed-p handle)
4745 ;; This will remove the part.
4746 (mm-display-part handle)
4748 (narrow-to-region (point)
4749 (if (eobp) (point) (1+ (point))))
4750 (mm-display-part handle)
4751 ;; We narrow to the part itself and
4752 ;; then call the treatment functions.
4753 (goto-char (point-min))
4755 (narrow-to-region (point) (point-max))
4758 (gnus-article-mime-total-parts)
4759 (mm-handle-media-type handle)))))
4760 (if (window-live-p window)
4761 (select-window window)))))
4764 (gnus-insert-mime-button
4765 handle id (list (mm-handle-displayed-p handle)))
4766 (goto-char point))))
4768 (defun gnus-article-goto-part (n)
4769 "Go to MIME part N."
4770 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4772 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4773 (let ((gnus-tmp-name
4774 (or (mail-content-type-get (mm-handle-type handle) 'name)
4775 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4776 (mail-content-type-get (mm-handle-type handle) 'url)
4778 (gnus-tmp-type (mm-handle-media-type handle))
4779 (gnus-tmp-description
4780 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4783 (if (if displayed (car displayed)
4784 (mm-handle-displayed-p handle))
4786 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4788 gnus-tmp-type-long b e)
4789 (when (string-match ".*/" gnus-tmp-name)
4790 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4791 (setq gnus-tmp-type-long (concat gnus-tmp-type
4792 (and (not (equal gnus-tmp-name ""))
4793 (concat "; " gnus-tmp-name))))
4794 (unless (equal gnus-tmp-description "")
4795 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4800 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4801 `(keymap ,gnus-mime-button-map
4802 gnus-callback gnus-mm-display-part
4803 gnus-part ,gnus-tmp-id
4804 article-type annotation
4807 ;; Exclude a newline.
4810 (widget-convert-button
4813 :action 'gnus-widget-press-button
4814 :button-keymap gnus-mime-button-map
4816 (lambda (widget/window &optional overlay pos)
4817 ;; Needed to properly clear the message due to a bug in
4818 ;; wid-edit (XEmacs only).
4819 (if (boundp 'help-echo-owns-message)
4820 (setq help-echo-owns-message t))
4822 "%S: %s the MIME part; %S: more options"
4823 (aref gnus-mouse-2 0)
4824 ;; XEmacs will get a single widget arg; Emacs 21 will get
4825 ;; window, overlay, position.
4826 (if (mm-handle-displayed-p
4828 (with-current-buffer (gnus-overlay-buffer overlay)
4829 (widget-get (widget-at (gnus-overlay-start overlay))
4831 (widget-get widget/window :mime-handle)))
4833 (aref gnus-down-mouse-3 0))))))
4835 (defun gnus-widget-press-button (elems el)
4836 (goto-char (widget-get elems :from))
4837 (gnus-article-press-button))
4839 (defvar gnus-displaying-mime nil)
4841 (defun gnus-display-mime (&optional ihandles)
4842 "Display the MIME parts."
4844 (save-selected-window
4845 (let ((window (get-buffer-window gnus-article-buffer))
4848 (select-window window)
4849 ;; We have to do this since selecting the window
4850 ;; may change the point. So we set the window point.
4851 (set-window-point window point)))
4852 (let ((handles ihandles)
4853 (inhibit-read-only t)
4856 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
4857 (when gnus-article-emulate-mime
4858 (mm-uu-dissect-text-parts handles)))
4859 (gnus-article-emulate-mime
4860 (setq handles (mm-uu-dissect))))
4861 (when (and (not ihandles)
4862 (not gnus-displaying-mime))
4863 ;; Top-level call; we clean up.
4864 (when gnus-article-mime-handles
4865 (mm-destroy-parts gnus-article-mime-handles)
4866 (setq gnus-article-mime-handle-alist nil));; A trick.
4867 (setq gnus-article-mime-handles handles)
4868 ;; We allow users to glean info from the handles.
4869 (when gnus-article-mime-part-function
4870 (gnus-mime-part-function handles)))
4872 (or (not (stringp (car handles)))
4875 (when (and (not ihandles)
4876 (not gnus-displaying-mime))
4877 ;; Clean up for mime parts.
4879 (delete-region (point) (point-max)))
4880 (let ((gnus-displaying-mime t))
4881 (gnus-mime-display-part handles)))
4884 (narrow-to-region (point) (point-max))
4885 (gnus-treat-article nil 1 1)
4888 ;; Highlight the headers.
4892 (narrow-to-region (point-min) (point))
4893 (gnus-article-save-original-date
4894 (gnus-treat-article 'head)))))))))
4896 (defcustom gnus-mime-display-multipart-as-mixed nil
4897 "Display \"multipart\" parts as \"multipart/mixed\".
4899 If t, it overrides nil values of
4900 `gnus-mime-display-multipart-alternative-as-mixed' and
4901 `gnus-mime-display-multipart-related-as-mixed'."
4902 :group 'gnus-article-mime
4905 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4906 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4908 :group 'gnus-article-mime
4911 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4912 "Display \"multipart/related\" parts as \"multipart/mixed\".
4914 If displaying \"text/html\" is discouraged \(see
4915 `mm-discouraged-alternatives'\) images or other material inside a
4916 \"multipart/related\" part might be overlooked when this variable is nil."
4918 :group 'gnus-article-mime
4921 (defun gnus-mime-display-part (handle)
4923 ;; Maybe a broken MIME message.
4926 ((not (stringp (car handle)))
4927 (gnus-mime-display-single handle))
4928 ;; User-defined multipart
4929 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4930 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4932 ;; multipart/alternative
4933 ((and (equal (car handle) "multipart/alternative")
4934 (not (or gnus-mime-display-multipart-as-mixed
4935 gnus-mime-display-multipart-alternative-as-mixed)))
4936 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4937 (push (cons id handle) gnus-article-mime-handle-alist)
4938 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4939 ;; multipart/related
4940 ((and (equal (car handle) "multipart/related")
4941 (not (or gnus-mime-display-multipart-as-mixed
4942 gnus-mime-display-multipart-related-as-mixed)))
4943 ;;;!!!We should find the start part, but we just default
4944 ;;;!!!to the first part.
4945 ;;(gnus-mime-display-part (cadr handle))
4946 ;;;!!! Most multipart/related is an HTML message plus images.
4947 ;;;!!! Unfortunately we are unable to let W3 display those
4948 ;;;!!! included images, so we just display it as a mixed multipart.
4949 ;;(gnus-mime-display-mixed (cdr handle))
4950 ;;;!!! No, w3 can display everything just fine.
4951 (gnus-mime-display-part (cadr handle)))
4952 ((equal (car handle) "multipart/signed")
4953 (gnus-add-wash-type 'signed)
4954 (gnus-mime-display-security handle))
4955 ((equal (car handle) "multipart/encrypted")
4956 (gnus-add-wash-type 'encrypted)
4957 (gnus-mime-display-security handle))
4958 ;; Other multiparts are handled like multipart/mixed.
4960 (gnus-mime-display-mixed (cdr handle)))))
4962 (defun gnus-mime-part-function (handles)
4963 (if (stringp (car handles))
4964 (mapcar 'gnus-mime-part-function (cdr handles))
4965 (funcall gnus-article-mime-part-function handles)))
4967 (defun gnus-mime-display-mixed (handles)
4968 (mapcar 'gnus-mime-display-part handles))
4970 (defun gnus-mime-display-single (handle)
4971 (let ((type (mm-handle-media-type handle))
4972 (ignored gnus-ignored-mime-types)
4979 (when (string-match (pop ignored) type)
4980 (throw 'ignored nil)))
4981 (if (and (setq not-attachment
4982 (and (not (mm-inline-override-p handle))
4983 (or (not (mm-handle-disposition handle))
4984 (equal (car (mm-handle-disposition handle))
4986 (mm-attachment-override-p handle))))
4987 (mm-automatic-display-p handle)
4989 (mm-inlinable-p handle)
4990 (mm-inlined-p handle))
4991 (mm-automatic-external-display-p type)))
4993 (when (equal (mm-handle-media-supertype handle) "text")
4995 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4997 (push (cons id handle) gnus-article-mime-handle-alist)
4998 (when (or (not display)
4999 (not (gnus-unbuttonized-mime-type-p type)))
5000 (gnus-insert-mime-button
5001 handle id (list (or display (and not-attachment text))))
5002 (gnus-article-insert-newline)
5003 ;; Remember modify the number of forward lines.
5011 (let ((mail-parse-charset gnus-newsgroup-charset)
5012 (mail-parse-ignored-charsets
5013 (save-excursion (condition-case ()
5014 (set-buffer gnus-summary-buffer)
5016 gnus-newsgroup-ignored-charsets)))
5017 (mm-display-part handle t))
5018 (goto-char (point-max)))
5019 ((and text not-attachment)
5023 (gnus-article-insert-newline)
5026 (let ((charset (mail-content-type-get (mm-handle-type handle)
5028 (cond ((not charset)
5029 (mm-string-as-multibyte (mm-get-part handle)))
5030 ((eq charset 'gnus-decoded)
5031 (with-current-buffer (mm-handle-buffer handle)
5034 (mm-decode-string (mm-get-part handle) charset)))))
5035 (goto-char (point-max))))
5039 (narrow-to-region beg (point))
5042 (gnus-article-mime-total-parts)
5043 (mm-handle-media-type handle)))))))))
5045 (defun gnus-unbuttonized-mime-type-p (type)
5046 "Say whether TYPE is to be unbuttonized."
5047 (unless gnus-inhibit-mime-unbuttonizing
5049 (let ((types gnus-unbuttonized-mime-types))
5051 (when (string-match (pop types) type)
5052 (throw 'found t)))))
5054 (let ((types gnus-buttonized-mime-types))
5056 (when (string-match (pop types) type)
5057 (throw 'found t)))))))))
5059 (defun gnus-article-insert-newline ()
5060 "Insert a newline, but mark it as undeletable."
5061 (gnus-put-text-property
5062 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5064 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5065 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5068 handle (inhibit-read-only t) from props begend not-pref)
5069 (save-window-excursion
5072 (narrow-to-region (car ibegend)
5075 (goto-char (car ibegend))
5078 (delete-region (point-min) (point-max))
5079 (mm-remove-parts handles))
5080 (setq begend (list (point-marker)))
5082 (unless (setq not-pref (cadr (member preferred ihandles)))
5083 (setq not-pref (car ihandles)))
5086 (not (gnus-unbuttonized-mime-type-p
5087 "multipart/alternative")))
5088 (gnus-add-text-properties
5091 (insert (format "%d. " id))
5095 (unless ,(not ibegend)
5096 (setq gnus-article-mime-handle-alist
5097 ',gnus-article-mime-handle-alist))
5098 (gnus-mime-display-alternative
5099 ',ihandles ',not-pref ',begend ,id))
5100 keymap ,gnus-mime-button-map
5101 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5102 face ,gnus-article-button-face
5105 (widget-convert-button 'link from (point)
5106 :action 'gnus-widget-press-button
5107 :button-keymap gnus-widget-button-keymap)
5109 (while (setq handle (pop handles))
5110 (gnus-add-text-properties
5113 (insert (format "(%c) %-18s"
5114 (if (equal handle preferred) ?* ? )
5115 (mm-handle-media-type handle)))
5119 (unless ,(not ibegend)
5120 (setq gnus-article-mime-handle-alist
5121 ',gnus-article-mime-handle-alist))
5122 (gnus-mime-display-alternative
5123 ',ihandles ',handle ',begend ,id))
5124 keymap ,gnus-mime-button-map
5125 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5126 face ,gnus-article-button-face
5129 (widget-convert-button 'link from (point)
5130 :action 'gnus-widget-press-button
5131 :button-keymap gnus-widget-button-keymap)
5135 (if (stringp (car preferred))
5136 (gnus-display-mime preferred)
5137 (let ((mail-parse-charset gnus-newsgroup-charset)
5138 (mail-parse-ignored-charsets
5139 (with-current-buffer gnus-summary-buffer
5140 gnus-newsgroup-ignored-charsets)))
5141 (mm-display-part preferred)
5145 (narrow-to-region (car begend) (point-max))
5147 nil (length gnus-article-mime-handle-alist)
5148 (gnus-article-mime-total-parts)
5149 (mm-handle-media-type handle))))))
5150 (goto-char (point-max))
5151 (setcdr begend (point-marker)))))
5153 (goto-char point))))
5155 (defconst gnus-article-wash-status-strings
5156 (let ((alist '((cite "c" "Possible hidden citation text"
5157 " " "All citation text visible")
5158 (headers "h" "Hidden headers"
5159 " " "All headers visible.")
5160 (pgp "p" "Encrypted or signed message status hidden"
5161 " " "No hidden encryption nor digital signature status")
5162 (signature "s" "Signature has been hidden"
5163 " " "Signature is visible")
5164 (overstrike "o" "Overstrike (^H) characters applied"
5165 " " "No overstrike characters applied")
5166 (emphasis "e" "/*_Emphasis_*/ characters applied"
5167 " " "No /*_emphasis_*/ characters applied")))
5169 (dolist (entry alist result)
5170 (let ((key (nth 0 entry))
5171 (on (copy-sequence (nth 1 entry)))
5172 (on-help (nth 2 entry))
5173 (off (copy-sequence (nth 3 entry)))
5174 (off-help (nth 4 entry)))
5175 (put-text-property 0 1 'help-echo on-help on)
5176 (put-text-property 0 1 'help-echo off-help off)
5177 (push (list key on off) result))))
5178 "Alist of strings describing wash status in the mode line.
5179 Each entry has the form (KEY ON OF), where the KEY is a symbol
5180 representing the particular washing function, ON is the string to use
5181 in the article mode line when the washing function is active, and OFF
5182 is the string to use when it is inactive.")
5184 (defun gnus-article-wash-status-entry (key value)
5185 (let ((entry (assoc key gnus-article-wash-status-strings)))
5186 (if value (nth 1 entry) (nth 2 entry))))
5188 (defun gnus-article-wash-status ()
5189 "Return a string which display status of article washing."
5190 (with-current-buffer gnus-article-buffer
5191 (let ((cite (memq 'cite gnus-article-wash-types))
5192 (headers (memq 'headers gnus-article-wash-types))
5193 (boring (memq 'boring-headers gnus-article-wash-types))
5194 (pgp (memq 'pgp gnus-article-wash-types))
5195 (pem (memq 'pem gnus-article-wash-types))
5196 (signed (memq 'signed gnus-article-wash-types))
5197 (encrypted (memq 'encrypted gnus-article-wash-types))
5198 (signature (memq 'signature gnus-article-wash-types))
5199 (overstrike (memq 'overstrike gnus-article-wash-types))
5200 (emphasis (memq 'emphasis gnus-article-wash-types)))
5202 (gnus-article-wash-status-entry 'cite cite)
5203 (gnus-article-wash-status-entry 'headers (or headers boring))
5204 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5205 (gnus-article-wash-status-entry 'signature signature)
5206 (gnus-article-wash-status-entry 'overstrike overstrike)
5207 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5209 (defun gnus-add-wash-type (type)
5210 "Add a washing of TYPE to the current status."
5211 (add-to-list 'gnus-article-wash-types type))
5213 (defun gnus-delete-wash-type (type)
5214 "Add a washing of TYPE to the current status."
5215 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5217 (defun gnus-add-image (category image)
5218 "Add IMAGE of CATEGORY to the list of displayed images."
5219 (let ((entry (assq category gnus-article-image-alist)))
5221 (setq entry (list category))
5222 (push entry gnus-article-image-alist))
5223 (nconc entry (list image))))
5225 (defun gnus-delete-images (category)
5226 "Delete all images in CATEGORY."
5227 (let ((entry (assq category gnus-article-image-alist)))
5228 (dolist (image (cdr entry))
5229 (gnus-remove-image image category))
5230 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5231 (gnus-delete-wash-type category)))
5233 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5235 (defun gnus-article-maybe-hide-headers ()
5236 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5237 Provided for backwards compatibility."
5238 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5239 (not (with-current-buffer gnus-summary-buffer
5240 gnus-have-all-headers)))
5241 (not gnus-inhibit-hiding))
5242 (gnus-article-hide-headers)))
5246 (defun gnus-output-to-file (file-name)
5247 "Append the current article to a file named FILE-NAME."
5248 (let ((artbuf (current-buffer)))
5250 (insert-buffer-substring artbuf)
5251 ;; Append newline at end of the buffer as separator, and then
5253 (goto-char (point-max))
5255 (let ((file-name-coding-system nnmail-pathname-coding-system))
5256 (mm-append-to-file (point-min) (point-max) file-name))
5259 (defun gnus-narrow-to-page (&optional arg)
5260 "Narrow the article buffer to a page.
5261 If given a numerical ARG, move forward ARG pages."
5263 (setq arg (if arg (prefix-numeric-value arg) 0))
5265 (set-buffer gnus-article-buffer)
5266 (goto-char (point-min))
5268 ;; Remove any old next/prev buttons.
5269 (when (gnus-visual-p 'page-marker)
5270 (let ((inhibit-read-only t))
5271 (gnus-remove-text-with-property 'gnus-prev)
5272 (gnus-remove-text-with-property 'gnus-next)))
5275 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5277 (re-search-forward page-delimiter nil 'move arg)))
5278 (goto-char (match-end 0))
5280 (goto-char (point-min))
5281 (setq gnus-page-broken
5282 (and (re-search-forward page-delimiter nil t) t))))
5283 (when gnus-page-broken
5286 (if (re-search-forward page-delimiter nil 'move)
5289 (when (and (gnus-visual-p 'page-marker)
5290 (> (point-min) (save-restriction (widen) (point-min))))
5292 (goto-char (point-min))
5293 (gnus-insert-prev-page-button)))
5294 (when (and (gnus-visual-p 'page-marker)
5295 (< (point-max) (save-restriction (widen) (point-max))))
5297 (goto-char (point-max))
5298 (gnus-insert-next-page-button))))))
5300 ;; Article mode commands
5302 (defun gnus-article-goto-next-page ()
5303 "Show the next page of the article."
5305 (when (gnus-article-next-page)
5306 (goto-char (point-min))
5307 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5310 (defun gnus-article-goto-prev-page ()
5311 "Show the previous page of the article."
5314 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5315 (gnus-article-prev-page nil)))
5317 ;; This is cleaner but currently breaks `gnus-pick-mode':
5319 ;; (defun gnus-article-goto-next-page ()
5320 ;; "Show the next page of the article."
5322 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5323 ;; (gnus-summary-next-page)))
5325 ;; (defun gnus-article-goto-prev-page ()
5326 ;; "Show the next page of the article."
5328 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5329 ;; (gnus-summary-prev-page)))
5331 (defun gnus-article-next-page (&optional lines)
5332 "Show the next page of the current article.
5333 If end of article, return non-nil. Otherwise return nil.
5334 Argument LINES specifies lines to be scrolled up."
5336 (move-to-window-line -1)
5339 (and (pos-visible-in-window-p) ;Not continuation line.
5340 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5341 ;; Nothing in this page.
5342 (if (or (not gnus-page-broken)
5347 (eobp)))) ;Real end-of-buffer?
5349 (when gnus-article-over-scroll
5350 (gnus-article-next-page-1 lines))
5352 (gnus-narrow-to-page 1) ;Go to next page.
5354 ;; More in this page.
5355 (gnus-article-next-page-1 lines)
5358 (defmacro gnus-article-beginning-of-window ()
5359 "Move point to the beginning of the window.
5360 In Emacs, the point is placed at the line number which `scroll-margin'
5362 (if (featurep 'xemacs)
5363 '(move-to-window-line 0)
5364 '(move-to-window-line
5365 (min (max 0 scroll-margin)
5366 (max 1 (- (window-height)
5367 (if mode-line-format 1 0)
5368 (if header-line-format 1 0)))))))
5370 (defun gnus-article-next-page-1 (lines)
5371 (when (and (not (featurep 'xemacs))
5374 (numberp (symbol-value 'scroll-margin))
5375 (> (symbol-value 'scroll-margin) 0))
5376 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5377 ;; too many number of lines if `scroll-margin' is set as two or greater.
5378 (setq lines (min lines
5379 (max 0 (- (count-lines (window-start) (point-max))
5380 (symbol-value 'scroll-margin))))))
5382 (let ((scroll-in-place nil))
5385 ;; Long lines may cause an end-of-buffer error.
5386 (goto-char (point-max))))
5387 (gnus-article-beginning-of-window))
5389 (defun gnus-article-prev-page (&optional lines)
5390 "Show previous page of current article.
5391 Argument LINES specifies lines to be scrolled down."
5393 (move-to-window-line 0)
5394 (if (and gnus-page-broken
5396 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5398 (gnus-narrow-to-page -1) ;Go to previous page.
5399 (goto-char (point-max))
5403 (let ((scroll-in-place nil))
5404 (scroll-down lines))
5405 (beginning-of-buffer
5406 (goto-char (point-min))))
5407 (gnus-article-beginning-of-window))))
5409 (defun gnus-article-only-boring-p ()
5410 "Decide whether there is only boring text remaining in the article.
5411 Something \"interesting\" is a word of at least two letters that does
5412 not have a face in `gnus-article-boring-faces'."
5413 (when (and gnus-article-skip-boring
5414 (boundp 'gnus-article-boring-faces)
5415 (symbol-value 'gnus-article-boring-faces))
5418 (while (re-search-forward "\\b\\w\\w" nil t)
5420 (when (not (gnus-intersection
5421 (gnus-faces-at (point))
5422 (symbol-value 'gnus-article-boring-faces)))
5423 (throw 'only-boring nil)))
5424 (throw 'only-boring t)))))
5426 (defun gnus-article-refer-article ()
5427 "Read article specified by message-id around point."
5430 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5431 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5432 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5433 (let ((msg-id (concat "<" (match-string 0) ">")))
5434 (set-buffer gnus-summary-buffer)
5435 (gnus-summary-refer-article msg-id))
5436 (error "No references around point"))))
5438 (defun gnus-article-show-summary ()
5439 "Reconfigure windows to show summary buffer."
5441 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5442 (error "There is no summary buffer for this article buffer")
5443 (gnus-article-set-globals)
5444 (gnus-configure-windows 'article)
5445 (gnus-summary-goto-subject gnus-current-article)
5446 (gnus-summary-position-point)))
5448 (defun gnus-article-describe-briefly ()
5449 "Describe article mode commands briefly."
5451 (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")))
5453 (defun gnus-article-summary-command ()
5454 "Execute the last keystroke in the summary buffer."
5456 (let ((obuf (current-buffer))
5457 (owin (current-window-configuration))
5459 (switch-to-buffer gnus-article-current-summary 'norecord)
5460 (setq func (lookup-key (current-local-map) (this-command-keys)))
5461 (call-interactively func)
5463 (set-window-configuration owin)
5464 (set-window-point (get-buffer-window (current-buffer)) (point))))
5466 (defun gnus-article-summary-command-nosave ()
5467 "Execute the last keystroke in the summary buffer."
5470 (pop-to-buffer gnus-article-current-summary 'norecord)
5471 (setq func (lookup-key (current-local-map) (this-command-keys)))
5472 (call-interactively func)))
5474 (defun gnus-article-check-buffer ()
5475 "Beep if not in an article buffer."
5476 (unless (equal major-mode 'gnus-article-mode)
5477 (error "Command invoked outside of a Gnus article buffer")))
5479 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5480 "Read a summary buffer key sequence and execute it from the article buffer."
5482 (gnus-article-check-buffer)
5484 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5485 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5486 "=" "^" "\M-^" "|"))
5492 '("n" "Gn" "p" "Gp"))
5495 (set-buffer gnus-article-current-summary)
5496 (let (gnus-pick-mode)
5497 (push (or key last-command-event) unread-command-events)
5498 (setq keys (if (featurep 'xemacs)
5499 (events-to-keys (read-key-sequence nil))
5500 (read-key-sequence nil)))))
5504 (if (or (member keys nosaves)
5505 (member keys nosave-but-article)
5506 (member keys nosave-in-article))
5508 (save-window-excursion
5509 (pop-to-buffer gnus-article-current-summary 'norecord)
5510 ;; We disable the pick minor mode commands.
5511 (let (gnus-pick-mode)
5512 (setq func (lookup-key (current-local-map) keys))))
5516 (unless (member keys nosave-in-article)
5517 (set-buffer gnus-article-current-summary))
5518 (call-interactively func)
5519 (setq new-sum-point (point)))
5520 (when (member keys nosave-but-article)
5521 (pop-to-buffer gnus-article-buffer 'norecord)))
5522 ;; These commands should restore window configuration.
5523 (let ((obuf (current-buffer))
5524 (owin (current-window-configuration))
5526 win func in-buffer selected new-sum-start new-sum-hscroll)
5527 (cond (not-restore-window
5528 (pop-to-buffer gnus-article-current-summary 'norecord))
5529 ((setq win (get-buffer-window gnus-article-current-summary))
5530 (select-window win))
5532 (switch-to-buffer gnus-article-current-summary 'norecord)))
5533 (setq in-buffer (current-buffer))
5534 ;; We disable the pick minor mode commands.
5535 (if (and (setq func (let (gnus-pick-mode)
5536 (lookup-key (current-local-map) keys)))
5539 (call-interactively func)
5540 (when (eq win (selected-window))
5541 (setq new-sum-point (point)
5542 new-sum-start (window-start win)
5543 new-sum-hscroll (window-hscroll win)))
5544 (when (eq in-buffer (current-buffer))
5545 (setq selected (gnus-summary-select-article))
5547 (unless not-restore-window
5548 (set-window-configuration owin))
5549 (when (eq selected 'old)
5551 (set-window-start (get-buffer-window (current-buffer))
5553 (set-window-point (get-buffer-window (current-buffer))
5555 (when (and (not not-restore-window)
5557 (set-window-point win new-sum-point)
5558 (set-window-start win new-sum-start)
5559 (set-window-hscroll win new-sum-hscroll))))
5560 (set-window-configuration owin)
5563 (defun gnus-article-describe-key (key)
5564 "Display documentation of the function invoked by KEY. KEY is a string."
5565 (interactive "kDescribe key: ")
5566 (gnus-article-check-buffer)
5567 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5569 (set-buffer gnus-article-current-summary)
5570 (let (gnus-pick-mode)
5571 (if (featurep 'xemacs)
5573 (push (elt key 0) unread-command-events)
5574 (setq key (events-to-keys
5575 (read-key-sequence "Describe key: "))))
5576 (setq unread-command-events
5578 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5579 (string-to-list key)))
5580 (setq key (read-key-sequence "Describe key: "))))
5582 (describe-key key)))
5584 (defun gnus-article-describe-key-briefly (key &optional insert)
5585 "Display documentation of the function invoked by KEY. KEY is a string."
5586 (interactive "kDescribe key: \nP")
5587 (gnus-article-check-buffer)
5588 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5590 (set-buffer gnus-article-current-summary)
5591 (let (gnus-pick-mode)
5592 (if (featurep 'xemacs)
5594 (push (elt key 0) unread-command-events)
5595 (setq key (events-to-keys
5596 (read-key-sequence "Describe key: "))))
5597 (setq unread-command-events
5599 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5600 (string-to-list key)))
5601 (setq key (read-key-sequence "Describe key: "))))
5602 (describe-key-briefly key insert))
5603 (describe-key-briefly key insert)))
5605 (defun gnus-article-reply-with-original (&optional wide)
5606 "Start composing a reply mail to the current message.
5607 The text in the region will be yanked. If the region isn't active,
5608 the entire article will be yanked."
5610 (let ((article (cdr gnus-article-current))
5612 (if (not (gnus-region-active-p))
5613 (with-current-buffer gnus-summary-buffer
5614 (gnus-summary-reply (list (list article)) wide))
5615 (setq contents (buffer-substring (point) (mark t)))
5616 ;; Deactivate active regions.
5617 (when (and (boundp 'transient-mark-mode)
5618 transient-mark-mode)
5619 (setq mark-active nil))
5620 (with-current-buffer gnus-summary-buffer
5622 (list (list article contents)) wide)))))
5624 (defun gnus-article-followup-with-original ()
5625 "Compose a followup to the current article.
5626 The text in the region will be yanked. If the region isn't active,
5627 the entire article will be yanked."
5629 (let ((article (cdr gnus-article-current))
5631 (if (not (gnus-region-active-p))
5632 (with-current-buffer gnus-summary-buffer
5633 (gnus-summary-followup (list (list article))))
5634 (setq contents (buffer-substring (point) (mark t)))
5635 ;; Deactivate active regions.
5636 (when (and (boundp 'transient-mark-mode)
5637 transient-mark-mode)
5638 (setq mark-active nil))
5639 (with-current-buffer gnus-summary-buffer
5640 (gnus-summary-followup
5641 (list (list article contents)))))))
5643 (defun gnus-article-hide (&optional arg force)
5644 "Hide all the gruft in the current article.
5645 This means that signatures, cited text and (some) headers will be
5647 If given a prefix, show the hidden text instead."
5648 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5649 (gnus-article-hide-headers arg)
5650 (gnus-article-hide-list-identifiers arg)
5651 (gnus-article-hide-citation-maybe arg force)
5652 (gnus-article-hide-signature arg))
5654 (defun gnus-article-maybe-highlight ()
5655 "Do some article highlighting if article highlighting is requested."
5656 (when (gnus-visual-p 'article-highlight 'highlight)
5657 (gnus-article-highlight-some)))
5659 (defun gnus-check-group-server ()
5660 ;; Make sure the connection to the server is alive.
5661 (unless (gnus-server-opened
5662 (gnus-find-method-for-group gnus-newsgroup-name))
5663 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5664 (gnus-request-group gnus-newsgroup-name t)))
5667 (autoload 'nneething-get-file-name "nneething"))
5669 (defun gnus-request-article-this-buffer (article group)
5670 "Get an article and insert it into this buffer."
5671 (let (do-update-line sparse-header)
5675 (gnus-kill-all-overlays)
5676 (setq group (or group gnus-newsgroup-name))
5678 ;; Using `gnus-request-article' directly will insert the article into
5679 ;; `nntp-server-buffer' - so we'll save some time by not having to
5680 ;; copy it from the server buffer into the article buffer.
5682 ;; We only request an article by message-id when we do not have the
5683 ;; headers for it, so we'll have to get those.
5684 (when (stringp article)
5685 (gnus-read-header article))
5687 ;; If the article number is negative, that means that this article
5688 ;; doesn't belong in this newsgroup (possibly), so we find its
5689 ;; message-id and request it by id instead of number.
5690 (when (and (numberp article)
5692 (get-buffer gnus-summary-buffer)
5693 (gnus-buffer-exists-p gnus-summary-buffer))
5695 (set-buffer gnus-summary-buffer)
5696 (let ((header (gnus-summary-article-header article)))
5699 ((memq article gnus-newsgroup-sparse)
5700 ;; This is a sparse gap article.
5701 (setq do-update-line article)
5702 (setq article (mail-header-id header))
5703 (setq sparse-header (gnus-read-header article))
5704 (setq gnus-newsgroup-sparse
5705 (delq article gnus-newsgroup-sparse)))
5707 ;; It's a real article.
5708 (setq article (mail-header-id header)))
5710 ;; It is an extracted pseudo-article.
5711 (setq article 'pseudo)
5712 (gnus-request-pseudo-article header))))
5714 (let ((method (gnus-find-method-for-group
5715 gnus-newsgroup-name)))
5716 (when (and (eq (car method) 'nneething)
5718 (let ((dir (nneething-get-file-name
5719 (mail-header-id header))))
5720 (when (and (stringp dir)
5721 (file-directory-p dir))
5722 (setq article 'nneething)
5723 (gnus-group-enter-directory dir))))))))
5726 ;; Refuse to select canceled articles.
5727 ((and (numberp article)
5729 (get-buffer gnus-summary-buffer)
5730 (gnus-buffer-exists-p gnus-summary-buffer)
5731 (eq (cdr (with-current-buffer gnus-summary-buffer
5732 (assq article gnus-newsgroup-reads)))
5733 gnus-canceled-mark))
5735 ;; We first check `gnus-original-article-buffer'.
5736 ((and (get-buffer gnus-original-article-buffer)
5738 (with-current-buffer gnus-original-article-buffer
5739 (and (equal (car gnus-original-article) group)
5740 (eq (cdr gnus-original-article) article))))
5741 (insert-buffer-substring gnus-original-article-buffer)
5743 ;; Check the backlog.
5744 ((and gnus-keep-backlog
5745 (gnus-backlog-request-article group article (current-buffer)))
5747 ;; Check asynchronous pre-fetch.
5748 ((gnus-async-request-fetched-article group article (current-buffer))
5749 (gnus-async-prefetch-next group article gnus-summary-buffer)
5750 (when (and (numberp article) gnus-keep-backlog)
5751 (gnus-backlog-enter-article group article (current-buffer)))
5754 ((and gnus-use-cache
5756 (gnus-cache-request-article article group))
5758 ;; Check the agent cache.
5759 ((gnus-agent-request-article article group)
5761 ;; Get the article and put into the article buffer.
5762 ((or (stringp article)
5764 (let ((gnus-override-method gnus-override-method)
5765 (methods (and (stringp article)
5766 gnus-refer-article-method))
5767 (backend (car (gnus-find-method-for-group
5768 gnus-newsgroup-name)))
5770 (inhibit-read-only t))
5771 (if (or (not (listp methods))
5772 (and (symbolp (car methods))
5773 (assq (car methods) nnoo-definition-alist)))
5774 (setq methods (list methods)))
5775 (when (and (null gnus-override-method)
5777 (setq gnus-override-method (pop methods)))
5779 (when (eq gnus-override-method 'current)
5780 (setq gnus-override-method
5781 (with-current-buffer gnus-summary-buffer
5782 gnus-current-select-method)))
5784 (gnus-kill-all-overlays)
5785 (let ((gnus-newsgroup-name group))
5786 (gnus-check-group-server))
5788 ((gnus-request-article article group (current-buffer))
5789 (when (numberp article)
5790 (gnus-async-prefetch-next group article
5791 gnus-summary-buffer)
5792 (when gnus-keep-backlog
5793 (gnus-backlog-enter-article
5794 group article (current-buffer))))
5795 (setq result 'article))
5797 (setq gnus-override-method (pop methods)))
5798 ((not (string-match "^400 "
5799 (nnheader-get-report backend)))
5800 ;; If we get 400 server disconnect, reconnect and
5801 ;; retry; otherwise, assume the article has expired.
5802 (setq result 'done))))
5803 (and (eq result 'article) 'article)))
5807 ;; Associate this article with the current summary buffer.
5808 (setq gnus-article-current-summary gnus-summary-buffer)
5810 ;; Take the article from the original article buffer
5811 ;; and place it in the buffer it's supposed to be in.
5812 (when (and (get-buffer gnus-article-buffer)
5813 (equal (buffer-name (current-buffer))
5814 (buffer-name (get-buffer gnus-article-buffer))))
5816 (if (get-buffer gnus-original-article-buffer)
5817 (set-buffer gnus-original-article-buffer)
5818 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5819 (buffer-disable-undo)
5820 (setq major-mode 'gnus-original-article-mode)
5821 (setq buffer-read-only t))
5822 (let ((inhibit-read-only t))
5824 (insert-buffer-substring gnus-article-buffer))
5825 (setq gnus-original-article (cons group article)))
5828 (run-hooks 'gnus-article-decode-hook)
5829 ;; Mark article as decoded or not.
5830 (setq gnus-article-decoded-p gnus-article-decode-hook))
5832 ;; Update sparse articles.
5833 (when (and do-update-line
5834 (or (numberp article)
5836 (let ((buf (current-buffer)))
5837 (set-buffer gnus-summary-buffer)
5838 (gnus-summary-update-article do-update-line sparse-header)
5839 (gnus-summary-goto-subject do-update-line nil t)
5840 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5842 (set-buffer buf))))))
5848 (defcustom gnus-article-edit-mode-hook nil
5849 "Hook run in article edit mode buffers."
5850 :group 'gnus-article-various
5853 (defvar gnus-article-edit-done-function nil)
5855 (defvar gnus-article-edit-mode-map nil)
5857 ;; Should we be using derived.el for this?
5858 (unless gnus-article-edit-mode-map
5859 (setq gnus-article-edit-mode-map (make-keymap))
5860 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5862 (gnus-define-keys gnus-article-edit-mode-map
5863 "\C-c?" describe-mode
5864 "\C-c\C-c" gnus-article-edit-done
5865 "\C-c\C-k" gnus-article-edit-exit
5866 "\C-c\C-f\C-t" message-goto-to
5867 "\C-c\C-f\C-o" message-goto-from
5868 "\C-c\C-f\C-b" message-goto-bcc
5869 ;;"\C-c\C-f\C-w" message-goto-fcc
5870 "\C-c\C-f\C-c" message-goto-cc
5871 "\C-c\C-f\C-s" message-goto-subject
5872 "\C-c\C-f\C-r" message-goto-reply-to
5873 "\C-c\C-f\C-n" message-goto-newsgroups
5874 "\C-c\C-f\C-d" message-goto-distribution
5875 "\C-c\C-f\C-f" message-goto-followup-to
5876 "\C-c\C-f\C-m" message-goto-mail-followup-to
5877 "\C-c\C-f\C-k" message-goto-keywords
5878 "\C-c\C-f\C-u" message-goto-summary
5879 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5880 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5881 "\C-c\C-b" message-goto-body
5882 "\C-c\C-i" message-goto-signature
5884 "\C-c\C-t" message-insert-to
5885 "\C-c\C-n" message-insert-newsgroups
5886 "\C-c\C-o" message-sort-headers
5887 "\C-c\C-e" message-elide-region
5888 "\C-c\C-v" message-delete-not-region
5889 "\C-c\C-z" message-kill-to-signature
5890 "\M-\r" message-newline-and-reformat
5891 "\C-c\C-a" mml-attach-file
5892 "\C-a" message-beginning-of-line
5894 "\M-;" comment-region)
5896 (gnus-define-keys (gnus-article-edit-wash-map
5897 "\C-c\C-w" gnus-article-edit-mode-map)
5898 "f" gnus-article-edit-full-stops))
5901 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5903 ["Fetch To" message-insert-to t]
5904 ["Fetch Newsgroups" message-insert-newsgroups t]
5906 ["To" message-goto-to t]
5907 ["From" message-goto-from t]
5908 ["Subject" message-goto-subject t]
5909 ["Cc" message-goto-cc t]
5910 ["Reply-To" message-goto-reply-to t]
5911 ["Summary" message-goto-summary t]
5912 ["Keywords" message-goto-keywords t]
5913 ["Newsgroups" message-goto-newsgroups t]
5914 ["Followup-To" message-goto-followup-to t]
5915 ["Mail-Followup-To" message-goto-mail-followup-to t]
5916 ["Distribution" message-goto-distribution t]
5917 ["Body" message-goto-body t]
5918 ["Signature" message-goto-signature t]))
5920 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
5921 "Major mode for editing articles.
5922 This is an extended text-mode.
5924 \\{gnus-article-edit-mode-map}"
5925 (make-local-variable 'gnus-article-edit-done-function)
5926 (make-local-variable 'gnus-prev-winconf)
5927 (set (make-local-variable 'font-lock-defaults)
5928 '(message-font-lock-keywords t))
5929 (set (make-local-variable 'mail-header-separator) "")
5930 (set (make-local-variable 'gnus-article-edit-mode) t)
5931 (easy-menu-add message-mode-field-menu message-mode-map)
5933 (setq buffer-read-only nil)
5934 (buffer-enable-undo)
5937 (defun gnus-article-edit (&optional force)
5938 "Edit the current article.
5939 This will have permanent effect only in mail groups.
5940 If FORCE is non-nil, allow editing of articles even in read-only
5943 (when (and (not force)
5944 (gnus-group-read-only-p))
5945 (error "The current newsgroup does not support article editing"))
5946 (gnus-article-date-original)
5947 (gnus-article-edit-article
5949 `(lambda (no-highlight)
5951 (gnus-summary-edit-article-done
5952 ,(or (mail-header-references gnus-current-headers) "")
5953 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5955 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
5956 "Start editing the contents of the current article buffer."
5957 (let ((winconf (current-window-configuration)))
5958 (set-buffer gnus-article-buffer)
5959 (let ((message-auto-save-directory
5960 ;; Don't associate the article buffer with a draft file.
5962 (gnus-article-edit-mode))
5963 (funcall start-func)
5964 (set-buffer-modified-p nil)
5965 (gnus-configure-windows 'edit-article)
5966 (setq gnus-article-edit-done-function exit-func)
5967 (setq gnus-prev-winconf winconf)
5969 (gnus-message 6 "C-c C-c to end edits"))))
5971 (defun gnus-article-edit-done (&optional arg)
5972 "Update the article edits and exit."
5974 (let ((func gnus-article-edit-done-function)
5975 (buf (current-buffer))
5976 (start (window-start))
5978 (winconf gnus-prev-winconf))
5979 (widen) ;; Widen it in case that users narrowed the buffer.
5982 ;; The cache and backlog have to be flushed somewhat.
5983 (when gnus-keep-backlog
5984 (gnus-backlog-remove-article
5985 (car gnus-article-current) (cdr gnus-article-current)))
5986 ;; Flush original article as well.
5988 (when (get-buffer gnus-original-article-buffer)
5989 (set-buffer gnus-original-article-buffer)
5990 (setq gnus-original-article nil)))
5991 (when gnus-use-cache
5992 (gnus-cache-update-article
5993 (car gnus-article-current) (cdr gnus-article-current)))
5994 ;; We remove all text props from the article buffer.
5995 (kill-all-local-variables)
5996 (set-text-properties (point-min) (point-max) nil)
5998 (set-window-configuration winconf)
6000 (set-window-start (get-buffer-window buf) start)
6001 (set-window-point (get-buffer-window buf) (point)))
6002 (gnus-summary-show-article))
6004 (defun gnus-article-edit-exit ()
6005 "Exit the article editing without updating."
6007 (when (or (not (buffer-modified-p))
6008 (yes-or-no-p "Article modified; kill anyway? "))
6009 (let ((curbuf (current-buffer))
6011 (window-start (window-start)))
6013 (if (gnus-buffer-live-p gnus-original-article-buffer)
6014 (insert-buffer-substring gnus-original-article-buffer))
6015 (let ((winconf gnus-prev-winconf))
6016 (kill-all-local-variables)
6018 (set-window-configuration winconf)
6019 ;; Tippy-toe some to make sure that point remains where it was.
6020 (save-current-buffer
6022 (set-window-start (get-buffer-window (current-buffer)) window-start)
6024 (gnus-summary-show-article)))
6026 (defun gnus-article-edit-full-stops ()
6027 "Interactively repair spacing at end of sentences."
6030 (goto-char (point-min))
6031 (search-forward-regexp "^$" nil t)
6032 (let ((case-fold-search nil))
6033 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6036 ;;; Article highlights
6039 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6041 ;;; Internal Variables:
6043 (defcustom gnus-button-url-regexp
6044 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6045 "\\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:]]\\)"
6046 "\\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\\)\\)")
6047 "Regular expression that matches URLs."
6048 :group 'gnus-article-buttons
6051 (defcustom gnus-button-valid-fqdn-regexp
6052 message-valid-fqdn-regexp
6053 "Regular expression that matches a valid FQDN."
6055 :group 'gnus-article-buttons
6058 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6059 (defcustom gnus-button-valid-localpart-regexp
6060 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*"
6061 "Regular expression that matches a localpart of mail addresses or MIDs."
6063 :group 'gnus-article-buttons
6066 (defcustom gnus-button-man-handler 'manual-entry
6067 "Function to use for displaying man pages.
6068 The function must take at least one argument with a string naming the
6071 :type '(choice (function-item :tag "Man" manual-entry)
6072 (function-item :tag "Woman" woman)
6073 (function :tag "Other"))
6074 :group 'gnus-article-buttons)
6076 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6077 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6078 If the default site is too slow, try to find a CTAN mirror, see
6079 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6080 the variable `gnus-button-handle-ctan'."
6082 :group 'gnus-article-buttons
6083 :link '(custom-manual "(gnus)Group Parameters")
6084 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6085 (const "http://tug.ctan.org/tex-archive/")
6086 (const "http://www.dante.de/CTAN/")
6087 (string :tag "Other")))
6089 (defcustom gnus-button-ctan-handler 'browse-url
6090 "Function to use for displaying CTAN links.
6091 The function must take one argument, the string naming the URL."
6093 :type '(choice (function-item :tag "Browse Url" browse-url)
6094 (function :tag "Other"))
6095 :group 'gnus-article-buttons)
6097 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6098 "Bogus strings removed from CTAN URLs."
6100 :group 'gnus-article-buttons
6101 :type '(choice (const "^/?tex-archive/\\|/")
6102 (regexp :tag "Other")))
6104 (defcustom gnus-button-ctan-directory-regexp
6106 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6107 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6108 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6109 "tds" "tools" "usergrps" "web") t)
6110 "Regular expression for ctan directories.
6111 It should match all directories in the top level of `gnus-ctan-url'."
6113 :group 'gnus-article-buttons
6116 (defcustom gnus-button-mid-or-mail-regexp
6117 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6118 gnus-button-valid-fqdn-regexp
6120 "Regular expression that matches a message ID or a mail address."
6122 :group 'gnus-article-buttons
6125 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6126 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6127 Strings like this can be either a message ID or a mail address. If it is one
6128 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6129 message ID or a mail address, respectively. If this variable is set to the
6130 symbol `ask', always query the user what do do. If it is a function, this
6131 function will be called with the string as it's only argument. The function
6132 must return `mid', `mail', `invalid' or `ask'."
6134 :group 'gnus-article-buttons
6135 :type '(choice (function-item :tag "Heuristic function"
6136 gnus-button-mid-or-mail-heuristic)
6141 (defcustom gnus-button-mid-or-mail-heuristic-alist
6142 '((-10.0 . ".+\\$.+@")
6145 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6146 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6147 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6148 (-1.0 . "^[^a-z]+@")
6150 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6151 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6152 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6153 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6156 (-1.0 . "^[0-9][0-9]")
6158 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6159 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6160 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6161 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6163 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6164 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6167 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6169 ;; compensation for TDMA dated mail addresses:
6170 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6172 (-20.0 . "\\.fsf@") ;; Gnus
6175 (-20.0 . "_-_") ;; Subject change in thread
6177 (-20.0 . "\\.ln@") ;; leafnode
6178 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6179 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6181 ;; (5.0 . "") ;; $local_part_len <= 7
6182 (10.0 . "^[^0-9]+@")
6183 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6184 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6187 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6189 (0.5 . "^[A-Z][a-z]")
6190 (0.5 . "^[A-Z][a-z][a-z]")
6191 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6192 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6193 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6195 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6196 address. The REGEXP is processed with `case-fold-search' set to nil."
6198 :group 'gnus-article-buttons
6199 :type '(repeat (cons (number :tag "Rate")
6200 (regexp :tag "Regexp"))))
6202 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6203 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6204 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6205 address, `ask' if unsure and `invalid' if the string is invalid."
6206 (let ((case-fold-search nil)
6207 (list gnus-button-mid-or-mail-heuristic-alist)
6208 (result 0) rate regexp lpartlen elem)
6210 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6211 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6212 ;; Certain special cases...
6215 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6216 "^[0-9]+\\.[0-9]+@compuserve\\|"
6217 "@public\\.gmane\\.org")
6219 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6220 (setq result 'mail))
6221 (when (string-match "@.*@\\| " mid-or-mail)
6222 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6223 (setq result 'invalid))
6224 ;; Nothing more to do, if result is not a number here...
6225 (when (numberp result)
6227 (setq elem (car list)
6231 (when (string-match regexp mid-or-mail)
6232 (setq result (+ result rate))
6234 9 "`%s' matched `%s', rate `%s', result `%s'."
6235 mid-or-mail regexp rate result)))
6236 (when (<= lpartlen 7)
6237 (setq result (+ result 5.0))
6238 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6239 mid-or-mail result))
6240 (when (>= lpartlen 12)
6241 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6243 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6244 ;; Long local part should contain realname if e-mail address,
6245 ;; too many digits: message-id.
6246 ;; $score -= 5.0 + 0.1 * $local_part_len;
6247 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6248 (setq result (+ result rate))
6250 9 "Many digits in `%s', rate `%s', result `%s'."
6251 mid-or-mail rate result))
6252 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6254 ;; Too few vowels [^aeiouy]{4,}.*\@
6255 (setq result (+ result -5.0))
6257 9 "Few vowels in `%s', rate `%s', result `%s'."
6258 mid-or-mail -5.0 result))
6260 (setq result (+ result 5.0))
6262 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6263 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6264 ;; Maybe we should make this a customizable alist: (condition . 'result)
6266 ((symbolp result) result)
6267 ;; Now convert number into proper results:
6268 ((< result -10.0) 'mid)
6269 ((> result 10.0) 'mail)
6272 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6273 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6274 (url-mid (concat "news" ":" mid-or-mail))
6275 (url-mailto (concat "mailto" ":" mid-or-mail)))
6276 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6277 (when (fboundp pref)
6279 ;; get rid of surrounding angles...
6281 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6282 (if (or (eq 'mid guessed) (eq 'mail guessed))
6286 (save-window-excursion
6287 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6290 (cond ((eq pref 'mid)
6291 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6292 (gnus-button-handle-news url-mid))
6294 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6295 (gnus-url-mailto url-mailto))
6296 (t (gnus-message 3 "Invalid string.")))))
6298 (defun gnus-button-handle-custom (url)
6299 "Follow a Custom URL."
6300 (customize-apropos (gnus-url-unhex-string url)))
6302 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6304 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6307 (defun gnus-button-handle-describe-function (url)
6308 "Call `describe-function' when pushing the corresponding URL button."
6311 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6313 (defun gnus-button-handle-describe-variable (url)
6314 "Call `describe-variable' when pushing the corresponding URL button."
6317 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6319 (defun gnus-button-handle-symbol (url)
6320 "Display help on variable or function.
6321 Calls `describe-variable' or `describe-function'."
6322 (let ((sym (intern url)))
6324 ((fboundp sym) (describe-function sym))
6325 ((boundp sym) (describe-variable sym))
6326 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6328 (defun gnus-button-handle-describe-key (url)
6329 "Call `describe-key' when pushing the corresponding URL button."
6331 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6332 (keys (ignore-errors (eval `(kbd ,key-string)))))
6335 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6337 (defun gnus-button-handle-apropos (url)
6338 "Call `apropos' when pushing the corresponding URL button."
6339 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6341 (defun gnus-button-handle-apropos-command (url)
6342 "Call `apropos' when pushing the corresponding URL button."
6344 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6346 (defun gnus-button-handle-apropos-variable (url)
6347 "Call `apropos' when pushing the corresponding URL button."
6349 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6350 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6352 (defun gnus-button-handle-apropos-documentation (url)
6353 "Call `apropos' when pushing the corresponding URL button."
6355 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6356 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6358 (defun gnus-button-handle-library (url)
6359 "Call `locate-library' when pushing the corresponding URL button."
6360 (gnus-message 9 "url=`%s'" url)
6361 (let* ((lib (locate-library url))
6362 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6364 (gnus-message 1 "Cannot locale library `%s'." url)
6365 (find-file-read-only file))))
6367 (defun gnus-button-handle-ctan (url)
6368 "Call `browse-url' when pushing a CTAN URL button."
6370 gnus-button-ctan-handler
6373 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6375 (defcustom gnus-button-tex-level 5
6376 "*Integer that says how many TeX-related buttons Gnus will show.
6377 The higher the number, the more buttons will appear and the more false
6378 positives are possible. Note that you can set this variable local to
6379 specific groups. Setting it higher in TeX groups is probably a good idea.
6380 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6381 how to set variables in specific groups."
6383 :group 'gnus-article-buttons
6384 :link '(custom-manual "(gnus)Group Parameters")
6387 (defcustom gnus-button-man-level 5
6388 "*Integer that says how many man-related buttons Gnus will show.
6389 The higher the number, the more buttons will appear and the more false
6390 positives are possible. Note that you can set this variable local to
6391 specific groups. Setting it higher in Unix groups is probably a good idea.
6392 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6393 how to set variables in specific groups."
6395 :group 'gnus-article-buttons
6396 :link '(custom-manual "(gnus)Group Parameters")
6399 (defcustom gnus-button-emacs-level 5
6400 "*Integer that says how many emacs-related buttons Gnus will show.
6401 The higher the number, the more buttons will appear and the more false
6402 positives are possible. Note that you can set this variable local to
6403 specific groups. Setting it higher in Emacs or Gnus related groups is
6404 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6405 `gnus-parameters' on how to set variables in specific groups."
6407 :group 'gnus-article-buttons
6408 :link '(custom-manual "(gnus)Group Parameters")
6411 (defcustom gnus-button-message-level 5
6412 "*Integer that says how many buttons for news or mail messages will appear.
6413 The higher the number, the more buttons will appear and the more false
6414 positives are possible."
6415 ;; mail addresses, MIDs, URLs for news, ...
6417 :group 'gnus-article-buttons
6420 (defcustom gnus-button-browse-level 5
6421 "*Integer that says how many buttons for browsing will appear.
6422 The higher the number, the more buttons will appear and the more false
6423 positives are possible."
6424 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6426 :group 'gnus-article-buttons
6429 (defcustom gnus-button-alist
6430 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6431 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6432 ((concat "\\b\\(nntp\\|news\\):\\("
6433 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6434 0 t gnus-button-handle-news 2)
6435 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6436 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6437 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6438 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6439 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6440 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6441 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6442 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6443 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6444 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6445 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6446 ;; RFC 2368 (The mailto URL scheme)
6447 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6448 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6449 ("\\bmailto:\\([^ \n\t]+\\)"
6450 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6452 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6453 gnus-button-ctan-directory-regexp
6454 "[^][>)!;:,'\n\t ]+\\)")
6455 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6456 ((concat "\\btex-archive/\\("
6457 gnus-button-ctan-directory-regexp
6458 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6459 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6462 gnus-button-ctan-directory-regexp
6463 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6464 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6465 ;; This is info (home-grown style) <info://foo/bar+baz>
6466 ("\\binfo://\\([^'\">\n\t ]+\\)"
6467 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6468 ;; Info GNOME style <info:foo#bar_baz>
6469 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6470 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6471 ;; Info KDE style <info:(foo)bar baz>
6472 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6473 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6474 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6475 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6476 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6477 ;; Info links like `C-h i d m CC Mode RET'
6478 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6480 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6481 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6482 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6483 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6484 ;; Emacs help commands
6485 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6486 ;; regexp doesn't match arguments containing ` '.
6487 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6488 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6489 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6490 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6491 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6492 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6493 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6494 ;; The following entries may lead to many false positives so don't enable
6495 ;; them by default (use a high button level).
6496 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6497 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6498 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6499 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6500 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6501 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6502 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6503 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6504 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6505 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6506 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6507 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6508 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6509 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6510 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6511 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6512 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6513 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6514 ;; Unlike the other regexps we really have to require quoting
6515 ;; here to determine where it ends.
6516 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6517 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6518 ("<URL: *\\([^<>]*\\)>"
6519 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6520 ;; RFC 2396 (2.4.3., delims) ...
6521 ("\"URL: *\\([^\"]*\\)\""
6522 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6523 ;; RFC 2396 (2.4.3., delims) ...
6524 ("\"URL: *\\([^\"]*\\)\""
6525 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6527 (gnus-button-url-regexp
6528 0 (>= gnus-button-browse-level 0) browse-url 0)
6530 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6531 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6532 gnus-button-handle-man 1)
6533 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6534 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6535 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6536 gnus-button-handle-man 1)
6537 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6538 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6539 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6540 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6541 ;; MID or mail: To avoid too many false positives we don't try to catch
6542 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6543 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6544 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6545 ;; so that non-ambiguous entries (see above) match first.
6546 (gnus-button-mid-or-mail-regexp
6547 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6548 "*Alist of regexps matching buttons in article bodies.
6550 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6551 REGEXP: is the string (case insensitive) matching text around the button (can
6552 also be Lisp expression evaluating to a string),
6553 BUTTON: is the number of the regexp grouping actually matching the button,
6554 FORM: is a Lisp expression which must eval to true for the button to
6556 CALLBACK: is the function to call when the user push this button, and each
6557 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6559 CALLBACK can also be a variable, in that case the value of that
6560 variable it the real callback function."
6561 :group 'gnus-article-buttons
6562 :type '(repeat (list (choice regexp variable sexp)
6563 (integer :tag "Button")
6565 (function :tag "Callback")
6568 (integer :tag "Regexp group")))))
6570 (defcustom gnus-header-button-alist
6571 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6572 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6573 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6574 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6575 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6576 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
6577 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6578 0 (>= gnus-button-browse-level 0) browse-url 0)
6579 ("^Subject:" gnus-button-url-regexp
6580 0 (>= gnus-button-browse-level 0) browse-url 0)
6581 ("^[^:]+:" gnus-button-url-regexp
6582 0 (>= gnus-button-browse-level 0) browse-url 0)
6583 ("^OpenPGP:.*url=" gnus-button-url-regexp
6584 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
6585 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6586 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6587 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6588 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6589 "*Alist of headers and regexps to match buttons in article heads.
6591 This alist is very similar to `gnus-button-alist', except that each
6592 alist has an additional HEADER element first in each entry:
6594 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6596 HEADER is a regexp to match a header. For a fuller explanation, see
6597 `gnus-button-alist'."
6598 :group 'gnus-article-buttons
6599 :group 'gnus-article-headers
6600 :type '(repeat (list (regexp :tag "Header")
6601 (choice regexp variable)
6602 (integer :tag "Button")
6604 (function :tag "Callback")
6607 (integer :tag "Regexp group")))))
6611 (defun gnus-article-push-button (event)
6612 "Check text under the mouse pointer for a callback function.
6613 If the text under the mouse pointer has a `gnus-callback' property,
6614 call it with the value of the `gnus-data' text property."
6616 (set-buffer (window-buffer (posn-window (event-start event))))
6617 (let* ((pos (posn-point (event-start event)))
6618 (data (get-text-property pos 'gnus-data))
6619 (fun (get-text-property pos 'gnus-callback)))
6622 (funcall fun data))))
6624 (defun gnus-article-press-button ()
6625 "Check text at point for a callback function.
6626 If the text at point has a `gnus-callback' property,
6627 call it with the value of the `gnus-data' text property."
6629 (let ((data (get-text-property (point) 'gnus-data))
6630 (fun (get-text-property (point) 'gnus-callback)))
6632 (funcall fun data))))
6634 (defun gnus-article-highlight (&optional force)
6635 "Highlight current article.
6636 This function calls `gnus-article-highlight-headers',
6637 `gnus-article-highlight-citation',
6638 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6639 do the highlighting. See the documentation for those functions."
6640 (interactive (list 'force))
6641 (gnus-article-highlight-headers)
6642 (gnus-article-highlight-citation force)
6643 (gnus-article-highlight-signature)
6644 (gnus-article-add-buttons force)
6645 (gnus-article-add-buttons-to-head))
6647 (defun gnus-article-highlight-some (&optional force)
6648 "Highlight current article.
6649 This function calls `gnus-article-highlight-headers',
6650 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6651 do the highlighting. See the documentation for those functions."
6652 (interactive (list 'force))
6653 (gnus-article-highlight-headers)
6654 (gnus-article-highlight-signature)
6655 (gnus-article-add-buttons))
6657 (defun gnus-article-highlight-headers ()
6658 "Highlight article headers as specified by `gnus-header-face-alist'."
6660 (gnus-with-article-headers
6661 (let (regexp header-face field-face from hpoints fpoints)
6662 (dolist (entry gnus-header-face-alist)
6663 (goto-char (point-min))
6664 (setq regexp (concat "^\\("
6665 (if (string-equal "" (nth 0 entry))
6669 header-face (nth 1 entry)
6670 field-face (nth 2 entry))
6671 (while (and (re-search-forward regexp nil t)
6675 (unless (search-forward ":" nil t)
6677 (when (and header-face
6678 (not (memq (point) hpoints)))
6679 (push (point) hpoints)
6680 (gnus-put-text-property from (point) 'face header-face))
6681 (when (and field-face
6682 (not (memq (setq from (point)) fpoints)))
6684 (if (re-search-forward "^[^ \t]" nil t)
6686 (goto-char (point-max)))
6687 (gnus-put-text-property from (point) 'face field-face)))))))
6689 (defun gnus-article-highlight-signature ()
6690 "Highlight the signature in an article.
6691 It does this by highlighting everything after
6692 `gnus-signature-separator' using the face `gnus-signature'."
6694 (gnus-with-article-buffer
6695 (let ((inhibit-point-motion-hooks t))
6697 (when (and gnus-signature-face
6698 (gnus-article-narrow-to-signature))
6699 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6700 'face gnus-signature-face)
6702 (gnus-article-search-signature)
6703 (let ((start (match-beginning 0))
6704 (end (set-marker (make-marker) (1+ (match-end 0)))))
6705 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6708 (defun gnus-button-in-region-p (b e prop)
6709 "Say whether PROP exists in the region."
6710 (text-property-not-all b e prop nil))
6712 (defun gnus-article-add-buttons (&optional force)
6713 "Find external references in the article and make buttons of them.
6714 \"External references\" are things like Message-IDs and URLs, as
6715 specified by `gnus-button-alist'."
6716 (interactive (list 'force))
6717 (gnus-with-article-buffer
6718 (let ((inhibit-point-motion-hooks t)
6719 (case-fold-search t)
6720 (alist gnus-button-alist)
6722 ;; Remove all old markers.
6723 (let (marker entry new-list)
6724 (while (setq marker (pop gnus-button-marker-list))
6725 (if (or (< marker (point-min)) (>= marker (point-max)))
6726 (push marker new-list)
6728 (when (setq entry (gnus-button-entry))
6729 (put-text-property (match-beginning (nth 1 entry))
6730 (match-end (nth 1 entry))
6731 'gnus-callback nil))
6732 (set-marker marker nil)))
6733 (setq gnus-button-marker-list new-list))
6734 ;; We skip the headers.
6737 (while (setq entry (pop alist))
6738 (setq regexp (eval (car entry)))
6740 (while (re-search-forward regexp nil t)
6741 (let* ((start (and entry (match-beginning (nth 1 entry))))
6742 (end (and entry (match-end (nth 1 entry))))
6743 (from (match-beginning 0)))
6744 (when (and (or (eq t (nth 2 entry))
6745 (eval (nth 2 entry)))
6746 (not (gnus-button-in-region-p
6747 start end 'gnus-callback)))
6748 ;; That optional form returned non-nil, so we add the
6750 (gnus-article-add-button
6751 start end 'gnus-button-push
6752 (car (push (set-marker (make-marker) from)
6753 gnus-button-marker-list))))))))))
6755 ;; Add buttons to the head of an article.
6756 (defun gnus-article-add-buttons-to-head ()
6757 "Add buttons to the head of the article."
6759 (gnus-with-article-headers
6761 (dolist (entry gnus-header-button-alist)
6762 ;; Each alist entry.
6763 (goto-char (point-min))
6764 (while (re-search-forward (car entry) nil t)
6765 ;; Each header matching the entry.
6766 (setq beg (match-beginning 0))
6767 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6768 (match-beginning 0))
6771 (while (re-search-forward (eval (nth 1 entry)) end t)
6772 ;; Each match within a header.
6773 (let* ((entry (cdr entry))
6774 (start (match-beginning (nth 1 entry)))
6775 (end (match-end (nth 1 entry)))
6776 (form (nth 2 entry)))
6777 (goto-char (match-end 0))
6779 (gnus-article-add-button
6780 start end (nth 3 entry)
6781 (buffer-substring (match-beginning (nth 4 entry))
6782 (match-end (nth 4 entry)))))))
6783 (goto-char end))))))
6785 ;;; External functions:
6787 (defun gnus-article-add-button (from to fun &optional data)
6788 "Create a button between FROM and TO with callback FUN and data DATA."
6789 (when gnus-article-button-face
6790 (gnus-overlay-put (gnus-make-overlay from to)
6791 'face gnus-article-button-face))
6792 (gnus-add-text-properties
6794 (nconc (and gnus-article-mouse-face
6795 (list gnus-mouse-face-prop gnus-article-mouse-face))
6796 (list 'gnus-callback fun)
6797 (and data (list 'gnus-data data))))
6798 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6799 :button-keymap gnus-widget-button-keymap))
6801 ;;; Internal functions:
6803 (defun gnus-article-set-globals ()
6804 (with-current-buffer gnus-summary-buffer
6805 (gnus-set-global-variables)))
6807 (defun gnus-signature-toggle (end)
6808 (gnus-with-article-buffer
6809 (let ((inhibit-point-motion-hooks t))
6810 (if (text-property-any end (point-max) 'article-type 'signature)
6812 (gnus-delete-wash-type 'signature)
6813 (gnus-remove-text-properties-when
6814 'article-type 'signature end (point-max)
6815 (cons 'article-type (cons 'signature
6816 gnus-hidden-properties))))
6817 (gnus-add-wash-type 'signature)
6818 (gnus-add-text-properties-when
6819 'article-type nil end (point-max)
6820 (cons 'article-type (cons 'signature
6821 gnus-hidden-properties)))))
6822 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6823 (gnus-set-mode-line 'article))))
6825 (defun gnus-button-entry ()
6826 ;; Return the first entry in `gnus-button-alist' matching this place.
6827 (let ((alist gnus-button-alist)
6830 (setq entry (pop alist))
6831 (if (looking-at (eval (car entry)))
6836 (defun gnus-button-push (marker)
6837 ;; Push button starting at MARKER.
6840 (let* ((entry (gnus-button-entry))
6841 (inhibit-point-motion-hooks t)
6843 (args (mapcar (lambda (group)
6844 (let ((string (match-string group)))
6845 (set-text-properties
6846 0 (length string) nil string)
6853 (fboundp (symbol-value fun)))
6854 (apply (symbol-value fun) args))
6856 (gnus-message 1 "You must define `%S' to use this button"
6857 (cons fun args)))))))
6859 (defun gnus-parse-news-url (url)
6860 (let (scheme server port group message-id articles)
6863 (goto-char (point-min))
6864 (when (looking-at "\\([A-Za-z]+\\):")
6865 (setq scheme (match-string 1))
6866 (goto-char (match-end 0)))
6867 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
6868 (setq server (match-string 1))
6869 (setq port (if (stringp (match-string 3))
6870 (string-to-number (match-string 3))
6872 (goto-char (match-end 0)))
6875 ((looking-at "\\(.*@.*\\)")
6876 (setq message-id (match-string 1)))
6877 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6878 (setq group (match-string 1)
6879 articles (split-string (match-string 2) "-")))
6880 ((looking-at "\\([^/]+\\)/?")
6881 (setq group (match-string 1)))
6883 (error "Unknown news URL syntax"))))
6884 (list scheme server port group message-id articles)))
6886 (defun gnus-button-handle-news (url)
6888 (destructuring-bind (scheme server port group message-id articles)
6889 (gnus-parse-news-url url)
6893 (set-buffer gnus-summary-buffer)
6895 (let ((gnus-refer-article-method
6896 (nconc (list (list 'nntp server))
6897 gnus-refer-article-method))
6898 (nntp-port-number (or port "nntp")))
6899 (gnus-message 7 "Fetching %s with %s"
6900 message-id gnus-refer-article-method)
6901 (gnus-summary-refer-article message-id))
6902 (gnus-summary-refer-article message-id))))
6904 (gnus-button-fetch-group url)))))
6906 (defun gnus-button-handle-man (url)
6908 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6909 (when (eq gnus-button-man-handler 'woman)
6910 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
6911 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6912 (funcall gnus-button-man-handler url))
6914 (defun gnus-button-handle-info-url (url)
6915 "Fetch an info URL."
6916 (setq url (mm-subst-char-in-string ?+ ?\ url))
6918 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6919 (gnus-info-find-node
6920 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6922 ")" (gnus-url-unhex-string (match-string 2 url)))))
6923 ((string-match "([^)\"]+)[^\"]+" url)
6925 (gnus-replace-in-string
6926 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
6927 (gnus-info-find-node url))
6928 (t (error "Can't parse %s" url))))
6930 (defun gnus-button-handle-info-url-gnome (url)
6931 "Fetch GNOME style info URL."
6932 (setq url (mm-subst-char-in-string ?_ ?\ url))
6933 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
6934 (gnus-info-find-node
6936 (gnus-url-unhex-string
6937 (match-string 1 url))
6939 (or (gnus-url-unhex-string
6940 (match-string 2 url))
6942 (error "Can't parse %s" url)))
6944 (defun gnus-button-handle-info-url-kde (url)
6945 "Fetch KDE style info URL."
6946 (gnus-info-find-node (gnus-url-unhex-string url)))
6948 (defun gnus-button-handle-info-keystrokes (url)
6949 "Call `info' when pushing the corresponding URL button."
6950 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
6955 (defun gnus-button-openpgp (url)
6956 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
6958 (mm-url-insert-file-contents-external url)
6959 (pgg-snarf-keys-region (point-min) (point-max))
6960 (pgg-display-output-buffer nil nil nil)))
6962 (defun gnus-button-message-id (message-id)
6964 (with-current-buffer gnus-summary-buffer
6965 (gnus-summary-refer-article message-id)))
6967 (defun gnus-button-fetch-group (address)
6968 "Fetch GROUP specified by ADDRESS."
6969 (if (not (string-match "[:/]" address))
6970 ;; This is just a simple group url.
6971 (gnus-group-read-ephemeral-group address gnus-select-method)
6974 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6976 (error "Can't parse %s" address)
6977 (gnus-group-read-ephemeral-group
6978 (match-string 4 address)
6979 `(nntp ,(match-string 1 address)
6980 (nntp-address ,(match-string 1 address))
6981 (nntp-port-number ,(if (match-end 3)
6982 (match-string 3 address)
6985 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
6987 (defun gnus-url-parse-query-string (query &optional downcase)
6988 (let (retval pairs cur key val)
6989 (setq pairs (split-string query "&"))
6991 (setq cur (car pairs)
6993 (if (not (string-match "=" cur))
6995 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6996 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6998 (setq key (downcase key)))
6999 (setq cur (assoc key retval))
7001 (setcdr cur (cons val (cdr cur)))
7002 (setq retval (cons (list key val) retval)))))
7005 (defun gnus-url-mailto (url)
7006 ;; Send mail to someone
7007 (when (string-match "mailto:/*\\(.*\\)" url)
7008 (setq url (substring url (match-beginning 1) nil)))
7009 (let (to args subject func)
7010 (setq args (gnus-url-parse-query-string
7011 (if (string-match "^\\?" url)
7013 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7014 (concat "to=" (match-string 1 url) "&"
7015 (match-string 2 url))
7016 (concat "to=" url)))
7018 subject (cdr-safe (assoc "subject" args)))
7021 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7024 (message-position-on-field (caar args)))
7025 (insert (gnus-replace-in-string
7026 (mapconcat 'identity (reverse (cdar args)) ", ")
7028 (setq args (cdr args)))
7031 (message-goto-subject))))
7033 (defun gnus-button-embedded-url (address)
7034 "Activate ADDRESS with `browse-url'."
7035 (browse-url (gnus-strip-whitespace address)))
7037 ;;; Next/prev buttons in the article buffer.
7039 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7040 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7042 (defvar gnus-prev-page-map
7043 (let ((map (make-sparse-keymap)))
7044 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7045 (define-key map "\r" 'gnus-button-prev-page)
7048 (defvar gnus-next-page-map
7049 (let ((map (make-sparse-keymap)))
7050 (unless (>= emacs-major-version 21)
7051 ;; XEmacs doesn't care.
7052 (set-keymap-parent map gnus-article-mode-map))
7053 (define-key map gnus-mouse-2 'gnus-button-next-page)
7054 (define-key map "\r" 'gnus-button-next-page)
7057 (defun gnus-insert-prev-page-button ()
7059 (inhibit-read-only t))
7061 gnus-prev-page-line-format nil
7062 `(keymap ,gnus-prev-page-map
7064 gnus-callback gnus-article-button-prev-page
7065 article-type annotation))
7066 (widget-convert-button
7068 ;; Exclude a newline.
7071 :action 'gnus-button-prev-page
7072 :button-keymap gnus-prev-page-map)))
7074 (defun gnus-button-next-page (&optional args more-args)
7075 "Go to the next page."
7077 (let ((win (selected-window)))
7078 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7079 (gnus-article-next-page)
7080 (select-window win)))
7082 (defun gnus-button-prev-page (&optional args more-args)
7083 "Go to the prev page."
7085 (let ((win (selected-window)))
7086 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7087 (gnus-article-prev-page)
7088 (select-window win)))
7090 (defun gnus-insert-next-page-button ()
7092 (inhibit-read-only t))
7093 (gnus-eval-format gnus-next-page-line-format nil
7094 `(keymap ,gnus-next-page-map
7096 gnus-callback gnus-article-button-next-page
7097 article-type annotation))
7098 (widget-convert-button
7100 ;; Exclude a newline.
7103 :action 'gnus-button-next-page
7104 :button-keymap gnus-next-page-map)))
7106 (defun gnus-article-button-next-page (arg)
7107 "Go to the next page."
7109 (let ((win (selected-window)))
7110 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7111 (gnus-article-next-page)
7112 (select-window win)))
7114 (defun gnus-article-button-prev-page (arg)
7115 "Go to the prev page."
7117 (let ((win (selected-window)))
7118 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7119 (gnus-article-prev-page)
7120 (select-window win)))
7122 (defvar gnus-decode-header-methods
7123 '(mail-decode-encoded-word-region)
7124 "List of methods used to decode headers.
7126 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7127 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7128 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7129 whose names match REGEXP.
7132 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7133 mail-decode-encoded-word-region
7134 (\"chinese\" . rfc1843-decode-region))
7137 (defvar gnus-decode-header-methods-cache nil)
7139 (defun gnus-multi-decode-header (start end)
7140 "Apply the functions from `gnus-encoded-word-methods' that match."
7141 (unless (and gnus-decode-header-methods-cache
7142 (eq gnus-newsgroup-name
7143 (car gnus-decode-header-methods-cache)))
7144 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7147 (nconc gnus-decode-header-methods-cache (list x))
7148 (if (and gnus-newsgroup-name
7149 (string-match (car x) gnus-newsgroup-name))
7150 (nconc gnus-decode-header-methods-cache
7152 gnus-decode-header-methods))
7153 (let ((xlist gnus-decode-header-methods-cache))
7156 (narrow-to-region start end)
7158 (funcall (pop xlist) (point-min) (point-max))))))
7161 ;;; Treatment top-level handling.
7164 (defun gnus-treat-article (condition &optional part-number total-parts type)
7165 (let ((length (- (point-max) (point-min)))
7166 (alist gnus-treatment-function-alist)
7167 (article-goto-body-goes-to-point-min-p t)
7171 (let ((list gnus-article-treat-types))
7173 (when (string-match (pop list) type)
7174 (throw 'found t)))))))
7175 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7177 (gnus-run-hooks 'gnus-part-display-hook)
7178 (dolist (elem alist)
7181 (when (gnus-buffer-live-p gnus-summary-buffer)
7182 (set-buffer gnus-summary-buffer))
7183 (symbol-value (car elem))))
7184 (when (and (or (consp val)
7186 (gnus-treat-predicate val)
7187 (or (not (get (car elem) 'highlight))
7190 (funcall (cadr elem)))))))
7192 ;; Dynamic variables.
7194 (defvar part-number)
7195 (defvar total-parts)
7200 (defun gnus-treat-predicate (val)
7207 (stringp (car val)))
7208 (apply 'gnus-or (mapcar `(lambda (s)
7209 (string-match s ,(or gnus-newsgroup-name "")))
7212 (let ((pred (pop val)))
7215 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7217 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7219 (not (gnus-treat-predicate (car val))))
7221 (equal (car val) type))
7223 (error "%S is not a valid predicate" pred)))))
7231 (eq part-number total-parts))
7235 (error "%S is not a valid value" val))))
7237 (defun gnus-article-encrypt-body (protocol &optional n)
7238 "Encrypt the article body."
7241 (or gnus-article-encrypt-protocol
7242 (completing-read "Encrypt protocol: "
7243 gnus-article-encrypt-protocol-alist
7245 current-prefix-arg))
7246 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7248 (error "Can't find the encrypt protocol %s" protocol))
7249 (if (member gnus-newsgroup-name '("nndraft:delayed"
7252 (error "Can't encrypt the article in group %s"
7253 gnus-newsgroup-name))
7254 (gnus-summary-iterate n
7256 (set-buffer gnus-summary-buffer)
7257 (let ((mail-parse-charset gnus-newsgroup-charset)
7258 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7259 (summary-buffer gnus-summary-buffer)
7261 (gnus-set-global-variables)
7262 (when (gnus-group-read-only-p)
7263 (error "The current newsgroup does not support article encrypt"))
7264 (gnus-summary-show-article t)
7266 (or (mail-header-references gnus-current-headers) ""))
7267 (set-buffer gnus-article-buffer)
7268 (let* ((inhibit-read-only t)
7270 (mapcar (lambda (field)
7271 (and (save-restriction
7272 (message-narrow-to-head)
7273 (goto-char (point-min))
7274 (search-forward field nil t))
7276 (message-narrow-to-field)
7278 (delete-region (point-min) (point-max))
7280 '("Content-Type:" "Content-Transfer-Encoding:"
7281 "Content-Disposition:"))))
7282 (message-narrow-to-head)
7283 (message-remove-header "MIME-Version")
7284 (goto-char (point-max))
7285 (setq point (point))
7286 (insert (apply 'concat headers))
7288 (narrow-to-region point (point-max))
7289 (let ((message-options message-options))
7290 (message-options-set 'message-sender user-mail-address)
7291 (message-options-set 'message-recipients user-mail-address)
7292 (message-options-set 'message-sign-encrypt 'not)
7294 (goto-char (point-min))
7295 (insert "MIME-Version: 1.0\n")
7297 (gnus-summary-edit-article-done
7298 references nil summary-buffer t))
7299 (when gnus-keep-backlog
7300 (gnus-backlog-remove-article
7301 (car gnus-article-current) (cdr gnus-article-current)))
7303 (when (get-buffer gnus-original-article-buffer)
7304 (set-buffer gnus-original-article-buffer)
7305 (setq gnus-original-article nil)))
7306 (when gnus-use-cache
7307 (gnus-cache-update-article
7308 (car gnus-article-current) (cdr gnus-article-current))))))))
7310 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7311 "The following specs can be used:
7312 %t The security MIME type
7315 %D Details if button is pressed")
7317 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7318 "The following specs can be used:
7319 %t The security MIME type
7322 %D Details if button is pressed")
7324 (defvar gnus-mime-security-button-line-format-alist
7325 '((?t gnus-tmp-type ?s)
7326 (?i gnus-tmp-info ?s)
7327 (?d gnus-tmp-details ?s)
7328 (?D gnus-tmp-pressed-details ?s)))
7330 (defvar gnus-mime-security-button-map
7331 (let ((map (make-sparse-keymap)))
7332 (define-key map gnus-mouse-2 'gnus-article-push-button)
7333 (define-key map "\r" 'gnus-article-press-button)
7336 (defvar gnus-mime-security-details-buffer nil)
7338 (defvar gnus-mime-security-button-pressed nil)
7340 (defvar gnus-mime-security-show-details-inline t
7341 "If non-nil, show details in the article buffer.")
7343 (defun gnus-mime-security-verify-or-decrypt (handle)
7344 (mm-remove-parts (cdr handle))
7345 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7346 point (inhibit-read-only t))
7348 (goto-char (car region)))
7350 (narrow-to-region (point) (point))
7351 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7352 (let* ((mm-verify-option 'known)
7353 (mm-decrypt-option 'known)
7354 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7355 (unless (eq nparts (cdr handle))
7356 (mm-destroy-parts (cdr handle))
7357 (setcdr handle nparts))))
7358 (setq point (point))
7359 (gnus-mime-display-security handle)
7360 (goto-char (point-max)))
7362 (delete-region (point) (cdr region))
7363 (set-marker (car region) nil)
7364 (set-marker (cdr region) nil))
7367 (defun gnus-mime-security-show-details (handle)
7368 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7370 (gnus-message 5 "No details.")
7371 (if gnus-mime-security-show-details-inline
7372 (let ((gnus-mime-security-button-pressed
7373 (not (get-text-property (point) 'gnus-mime-details)))
7374 (gnus-mime-security-button-line-format
7375 (get-text-property (point) 'gnus-line-format))
7376 (inhibit-read-only t))
7378 (while (eq (get-text-property (point) 'gnus-line-format)
7379 gnus-mime-security-button-line-format)
7383 (narrow-to-region (point) (point))
7384 (gnus-insert-mime-security-button handle))
7385 (delete-region (point)
7386 (or (text-property-not-all
7389 gnus-mime-security-button-line-format)
7392 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7393 (with-current-buffer gnus-mime-security-details-buffer
7396 (setq gnus-mime-security-details-buffer
7397 (gnus-get-buffer-create "*MIME Security Details*")))
7398 (with-current-buffer gnus-mime-security-details-buffer
7400 (goto-char (point-min)))
7401 (pop-to-buffer gnus-mime-security-details-buffer)))))
7403 (defun gnus-mime-security-press-button (handle)
7405 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7406 (gnus-mime-security-show-details handle)
7407 (gnus-mime-security-verify-or-decrypt handle))))
7409 (defun gnus-insert-mime-security-button (handle &optional displayed)
7410 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7413 (or (nth 2 (assoc protocol mm-verify-function-alist))
7414 (nth 2 (assoc protocol mm-decrypt-function-alist))
7416 (if (equal (car handle) "multipart/signed")
7417 " Signed" " Encrypted")
7420 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7423 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7424 gnus-tmp-pressed-details
7426 (setq gnus-tmp-details
7427 (if gnus-tmp-details
7428 (concat "\n" gnus-tmp-details)
7430 (setq gnus-tmp-pressed-details
7431 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7436 gnus-mime-security-button-line-format
7437 gnus-mime-security-button-line-format-alist
7438 `(keymap ,gnus-mime-security-button-map
7439 gnus-callback gnus-mime-security-press-button
7440 gnus-line-format ,gnus-mime-security-button-line-format
7441 gnus-mime-details ,gnus-mime-security-button-pressed
7442 article-type annotation
7445 ;; Exclude a newline.
7448 (widget-convert-button
7451 :action 'gnus-widget-press-button
7452 :button-keymap gnus-mime-security-button-map
7454 (lambda (widget/window &optional overlay pos)
7455 ;; Needed to properly clear the message due to a bug in
7456 ;; wid-edit (XEmacs only).
7457 (when (boundp 'help-echo-owns-message)
7458 (setq help-echo-owns-message t))
7461 (aref gnus-mouse-2 0))))))
7463 (defun gnus-mime-display-security (handle)
7465 (narrow-to-region (point) (point))
7466 (unless (gnus-unbuttonized-mime-type-p (car handle))
7467 (gnus-insert-mime-security-button handle))
7468 (gnus-mime-display-part (cadr handle))
7471 (unless (gnus-unbuttonized-mime-type-p (car handle))
7472 (let ((gnus-mime-security-button-line-format
7473 gnus-mime-security-button-end-line-format))
7474 (gnus-insert-mime-security-button handle)))
7475 (mm-set-handle-multipart-parameter
7477 (cons (set-marker (make-marker) (point-min))
7478 (set-marker (make-marker) (point-max))))))
7484 (run-hooks 'gnus-art-load-hook)
7486 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7487 ;;; gnus-art.el ends here