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 "Last" last)
966 (integer :tag "Less")
967 (repeat :tag "Groups" regexp)
968 (sexp :tag "Predicate")))
970 (defvar gnus-article-treat-head-custom
971 '(choice (const :tag "Off" nil)
972 (const :tag "Header" head)))
974 (defvar gnus-article-treat-types '("text/plain")
977 (defvar gnus-inhibit-treatment nil
978 "Whether to inhibit treatment.")
980 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
981 "Highlight the signature.
982 Valid values are nil, t, `head', `last', an integer or a predicate.
983 See Info node `(gnus)Customizing Articles'."
984 :group 'gnus-article-treat
985 :link '(custom-manual "(gnus)Customizing Articles")
986 :type gnus-article-treat-custom)
987 (put 'gnus-treat-highlight-signature 'highlight t)
989 (defcustom gnus-treat-buttonize 100000
991 Valid values are nil, t, `head', `last', an integer or a predicate.
992 See Info node `(gnus)Customizing Articles'."
993 :group 'gnus-article-treat
994 :link '(custom-manual "(gnus)Customizing Articles")
995 :type gnus-article-treat-custom)
996 (put 'gnus-treat-buttonize 'highlight t)
998 (defcustom gnus-treat-buttonize-head 'head
999 "Add buttons to the head.
1000 Valid values are nil, t, `head', `last', an integer or a predicate.
1001 See Info node `(gnus)Customizing Articles' for details."
1002 :group 'gnus-article-treat
1003 :link '(custom-manual "(gnus)Customizing Articles")
1004 :type gnus-article-treat-head-custom)
1005 (put 'gnus-treat-buttonize-head 'highlight t)
1007 (defcustom gnus-treat-emphasize
1008 (and (or window-system
1012 Valid values are nil, t, `head', `last', an integer or a predicate.
1013 See Info node `(gnus)Customizing Articles' for details."
1014 :group 'gnus-article-treat
1015 :link '(custom-manual "(gnus)Customizing Articles")
1016 :type gnus-article-treat-custom)
1017 (put 'gnus-treat-emphasize 'highlight t)
1019 (defcustom gnus-treat-strip-cr nil
1020 "Remove carriage returns.
1021 Valid values are nil, t, `head', `last', an integer or a predicate.
1022 See Info node `(gnus)Customizing Articles' for details."
1024 :group 'gnus-article-treat
1025 :link '(custom-manual "(gnus)Customizing Articles")
1026 :type gnus-article-treat-custom)
1028 (defcustom gnus-treat-unsplit-urls nil
1029 "Remove newlines from within URLs.
1030 Valid values are nil, t, `head', `last', an integer or a predicate.
1031 See Info node `(gnus)Customizing Articles' for details."
1033 :group 'gnus-article-treat
1034 :link '(custom-manual "(gnus)Customizing Articles")
1035 :type gnus-article-treat-custom)
1037 (defcustom gnus-treat-leading-whitespace nil
1038 "Remove leading whitespace in headers.
1039 Valid values are nil, t, `head', `last', an integer or a predicate.
1040 See Info node `(gnus)Customizing Articles' for details."
1042 :group 'gnus-article-treat
1043 :link '(custom-manual "(gnus)Customizing Articles")
1044 :type gnus-article-treat-custom)
1046 (defcustom gnus-treat-hide-headers 'head
1048 Valid values are nil, t, `head', `last', an integer or a predicate.
1049 See Info node `(gnus)Customizing Articles' for details."
1050 :group 'gnus-article-treat
1051 :link '(custom-manual "(gnus)Customizing Articles")
1052 :type gnus-article-treat-head-custom)
1054 (defcustom gnus-treat-hide-boring-headers nil
1055 "Hide boring headers.
1056 Valid values are nil, t, `head', `last', an integer or a predicate.
1057 See Info node `(gnus)Customizing Articles' for details."
1058 :group 'gnus-article-treat
1059 :link '(custom-manual "(gnus)Customizing Articles")
1060 :type gnus-article-treat-head-custom)
1062 (defcustom gnus-treat-hide-signature nil
1063 "Hide the signature.
1064 Valid values are nil, t, `head', `last', an integer or a predicate.
1065 See Info node `(gnus)Customizing Articles' for details."
1066 :group 'gnus-article-treat
1067 :link '(custom-manual "(gnus)Customizing Articles")
1068 :type gnus-article-treat-custom)
1070 (defcustom gnus-treat-fill-article nil
1072 Valid values are nil, t, `head', `last', an integer or a predicate.
1073 See Info node `(gnus)Customizing Articles' for details."
1074 :group 'gnus-article-treat
1075 :link '(custom-manual "(gnus)Customizing Articles")
1076 :type gnus-article-treat-custom)
1078 (defcustom gnus-treat-hide-citation nil
1080 Valid values are nil, t, `head', `last', an integer or a predicate.
1081 See Info node `(gnus)Customizing Articles' for details."
1082 :group 'gnus-article-treat
1083 :link '(custom-manual "(gnus)Customizing Articles")
1084 :type gnus-article-treat-custom)
1086 (defcustom gnus-treat-hide-citation-maybe nil
1088 Valid values are nil, t, `head', `last', an integer or a predicate.
1089 See Info node `(gnus)Customizing Articles' for details."
1090 :group 'gnus-article-treat
1091 :link '(custom-manual "(gnus)Customizing Articles")
1092 :type gnus-article-treat-custom)
1094 (defcustom gnus-treat-strip-list-identifiers 'head
1095 "Strip list identifiers from `gnus-list-identifiers`.
1096 Valid values are nil, t, `head', `last', an integer or a predicate.
1097 See Info node `(gnus)Customizing Articles' for details."
1099 :group 'gnus-article-treat
1100 :link '(custom-manual "(gnus)Customizing Articles")
1101 :type gnus-article-treat-custom)
1103 (make-obsolete-variable 'gnus-treat-strip-pgp
1104 "This option is obsolete in Gnus 5.10.")
1106 (defcustom gnus-treat-strip-pem nil
1107 "Strip PEM signatures.
1108 Valid values are nil, t, `head', `last', an integer or a predicate.
1109 See Info node `(gnus)Customizing Articles' for details."
1110 :group 'gnus-article-treat
1111 :link '(custom-manual "(gnus)Customizing Articles")
1112 :type gnus-article-treat-custom)
1114 (defcustom gnus-treat-strip-banner t
1115 "Strip banners from articles.
1116 The banner to be stripped is specified in the `banner' group parameter.
1117 Valid values are nil, t, `head', `last', an integer or a predicate.
1118 See Info node `(gnus)Customizing Articles' for details."
1119 :group 'gnus-article-treat
1120 :link '(custom-manual "(gnus)Customizing Articles")
1121 :type gnus-article-treat-custom)
1123 (defcustom gnus-treat-highlight-headers 'head
1124 "Highlight the headers.
1125 Valid values are nil, t, `head', `last', an integer or a predicate.
1126 See Info node `(gnus)Customizing Articles' for details."
1127 :group 'gnus-article-treat
1128 :link '(custom-manual "(gnus)Customizing Articles")
1129 :type gnus-article-treat-head-custom)
1130 (put 'gnus-treat-highlight-headers 'highlight t)
1132 (defcustom gnus-treat-highlight-citation t
1133 "Highlight cited text.
1134 Valid values are nil, t, `head', `last', an integer or a predicate.
1135 See Info node `(gnus)Customizing Articles' for details."
1136 :group 'gnus-article-treat
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-custom)
1139 (put 'gnus-treat-highlight-citation 'highlight t)
1141 (defcustom gnus-treat-date-ut nil
1142 "Display the Date in UT (GMT).
1143 Valid values are nil, t, `head', `last', an integer or a predicate.
1144 See Info node `(gnus)Customizing Articles' for details."
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-head-custom)
1149 (defcustom gnus-treat-date-local nil
1150 "Display the Date in the local timezone.
1151 Valid values are nil, t, `head', `last', an integer or a predicate.
1152 See Info node `(gnus)Customizing Articles' for details."
1153 :group 'gnus-article-treat
1154 :link '(custom-manual "(gnus)Customizing Articles")
1155 :type gnus-article-treat-head-custom)
1157 (defcustom gnus-treat-date-english nil
1158 "Display the Date in a format that can be read aloud in English.
1159 Valid values are nil, t, `head', `last', an integer or a predicate.
1160 See Info node `(gnus)Customizing Articles' for details."
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1166 (defcustom gnus-treat-date-lapsed nil
1167 "Display the Date header in a way that says how much time has elapsed.
1168 Valid values are nil, t, `head', `last', an integer or a predicate.
1169 See Info node `(gnus)Customizing Articles' for details."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-head-custom)
1174 (defcustom gnus-treat-date-original nil
1175 "Display the date in the original timezone.
1176 Valid values are nil, t, `head', `last', an integer or a predicate.
1177 See Info node `(gnus)Customizing Articles' for details."
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-head-custom)
1182 (defcustom gnus-treat-date-iso8601 nil
1183 "Display the date in the ISO8601 format.
1184 Valid values are nil, t, `head', `last', an integer or a predicate.
1185 See Info node `(gnus)Customizing Articles' for details."
1187 :group 'gnus-article-treat
1188 :link '(custom-manual "(gnus)Customizing Articles")
1189 :type gnus-article-treat-head-custom)
1191 (defcustom gnus-treat-date-user-defined nil
1192 "Display the date in a user-defined format.
1193 The format is defined by the `gnus-article-time-format' variable.
1194 Valid values are nil, t, `head', `last', an integer or a predicate.
1195 See Info node `(gnus)Customizing Articles' for details."
1196 :group 'gnus-article-treat
1197 :link '(custom-manual "(gnus)Customizing Articles")
1198 :type gnus-article-treat-head-custom)
1200 (defcustom gnus-treat-strip-headers-in-body t
1201 "Strip the X-No-Archive header line from the beginning of the body.
1202 Valid values are nil, t, `head', `last', an integer or a predicate.
1203 See Info node `(gnus)Customizing Articles' for details."
1205 :group 'gnus-article-treat
1206 :link '(custom-manual "(gnus)Customizing Articles")
1207 :type gnus-article-treat-custom)
1209 (defcustom gnus-treat-strip-trailing-blank-lines nil
1210 "Strip trailing blank lines.
1211 Valid values are nil, t, `head', `last', an integer or a predicate.
1212 See Info node `(gnus)Customizing Articles' for details.
1214 When set to t, it also strips trailing blanks in all MIME parts.
1215 Consider to use `last' instead."
1216 :group 'gnus-article-treat
1217 :link '(custom-manual "(gnus)Customizing Articles")
1218 :type gnus-article-treat-custom)
1220 (defcustom gnus-treat-strip-leading-blank-lines nil
1221 "Strip leading blank lines.
1222 Valid values are nil, t, `head', `last', an integer or a predicate.
1223 See Info node `(gnus)Customizing Articles' for details.
1225 When set to t, it also strips trailing blanks in all MIME parts."
1226 :group 'gnus-article-treat
1227 :link '(custom-manual "(gnus)Customizing Articles")
1228 :type gnus-article-treat-custom)
1230 (defcustom gnus-treat-strip-multiple-blank-lines nil
1231 "Strip multiple blank lines.
1232 Valid values are nil, t, `head', `last', an integer or a predicate.
1233 See Info node `(gnus)Customizing Articles' for details."
1234 :group 'gnus-article-treat
1235 :link '(custom-manual "(gnus)Customizing Articles")
1236 :type gnus-article-treat-custom)
1238 (defcustom gnus-treat-unfold-headers 'head
1239 "Unfold folded header lines.
1240 Valid values are nil, t, `head', `last', an integer or a predicate.
1241 See Info node `(gnus)Customizing Articles' for details."
1243 :group 'gnus-article-treat
1244 :link '(custom-manual "(gnus)Customizing Articles")
1245 :type gnus-article-treat-custom)
1247 (defcustom gnus-treat-fold-headers nil
1249 Valid values are nil, t, `head', `last', an integer or a predicate.
1250 See Info node `(gnus)Customizing Articles' for details."
1252 :group 'gnus-article-treat
1253 :link '(custom-manual "(gnus)Customizing Articles")
1254 :type gnus-article-treat-custom)
1256 (defcustom gnus-treat-fold-newsgroups 'head
1257 "Fold the Newsgroups and Followup-To headers.
1258 Valid values are nil, t, `head', `last', an integer or a predicate.
1259 See Info node `(gnus)Customizing Articles' for details."
1261 :group 'gnus-article-treat
1262 :link '(custom-manual "(gnus)Customizing Articles")
1263 :type gnus-article-treat-custom)
1265 (defcustom gnus-treat-overstrike t
1266 "Treat overstrike highlighting.
1267 Valid values are nil, t, `head', `last', an integer or a predicate.
1268 See Info node `(gnus)Customizing Articles' for details."
1269 :group 'gnus-article-treat
1270 :link '(custom-manual "(gnus)Customizing Articles")
1271 :type gnus-article-treat-custom)
1272 (put 'gnus-treat-overstrike 'highlight t)
1274 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1275 "Treat ANSI SGR control sequences.
1276 Valid values are nil, t, `head', `last', an integer or a predicate.
1277 See Info node `(gnus)Customizing Articles' for details."
1278 :group 'gnus-article-treat
1279 :link '(custom-manual "(gnus)Customizing Articles")
1280 :type gnus-article-treat-custom)
1282 (make-obsolete-variable 'gnus-treat-display-xface
1283 'gnus-treat-display-x-face)
1285 (defcustom gnus-treat-display-x-face
1286 (and (not noninteractive)
1287 (or (and (fboundp 'image-type-available-p)
1288 (image-type-available-p 'xbm)
1289 (string-match "^0x" (shell-command-to-string "uncompface"))
1290 (executable-find "icontopbm"))
1291 (and (featurep 'xemacs)
1294 "Display X-Face headers.
1295 Valid values are nil, t, `head', `last', an integer or a predicate.
1296 See Info node `(gnus)Customizing Articles' and Info node
1297 `(gnus)X-Face' for details."
1298 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :link '(custom-manual "(gnus)X-Face")
1302 :type gnus-article-treat-head-custom
1303 :set (lambda (symbol value)
1306 (cond ((or (boundp symbol) (get symbol 'saved-value))
1308 ((boundp 'gnus-treat-display-xface)
1310 ** gnus-treat-display-xface is an obsolete variable;\
1311 use gnus-treat-display-x-face instead")
1312 (default-value 'gnus-treat-display-xface))
1313 ((get 'gnus-treat-display-xface 'saved-value)
1315 ** gnus-treat-display-xface is an obsolete variable;\
1316 use gnus-treat-display-x-face instead")
1317 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1320 (put 'gnus-treat-display-x-face 'highlight t)
1322 (defcustom gnus-treat-display-face
1323 (and (not noninteractive)
1324 (or (and (fboundp 'image-type-available-p)
1325 (image-type-available-p 'png))
1326 (and (featurep 'xemacs)
1329 "Display Face headers.
1330 Valid values are nil, t, `head', `last', an integer or a predicate.
1331 See Info node `(gnus)Customizing Articles' and Info node
1332 `(gnus)X-Face' for details."
1333 :group 'gnus-article-treat
1335 :link '(custom-manual "(gnus)Customizing Articles")
1336 :link '(custom-manual "(gnus)X-Face")
1337 :type gnus-article-treat-head-custom)
1338 (put 'gnus-treat-display-face 'highlight t)
1340 (defcustom gnus-treat-display-smileys
1341 (if (or (and (featurep 'xemacs)
1343 (and (fboundp 'image-type-available-p)
1344 (image-type-available-p 'pbm)))
1347 Valid values are nil, t, `head', `last', an integer or a predicate.
1348 See Info node `(gnus)Customizing Articles' and Info node
1349 `(gnus)Smileys' for details."
1350 :group 'gnus-article-treat
1352 :link '(custom-manual "(gnus)Customizing Articles")
1353 :link '(custom-manual "(gnus)Smileys")
1354 :type gnus-article-treat-custom)
1355 (put 'gnus-treat-display-smileys 'highlight t)
1357 (defcustom gnus-treat-from-picon
1358 (if (and (gnus-image-type-available-p 'xpm)
1359 (gnus-picons-installed-p))
1361 "Display picons in the From header.
1362 Valid values are nil, t, `head', `last', an integer or a predicate.
1363 See Info node `(gnus)Customizing Articles' and Info node
1364 `(gnus)Picons' for details."
1366 :group 'gnus-article-treat
1368 :link '(custom-manual "(gnus)Customizing Articles")
1369 :link '(custom-manual "(gnus)Picons")
1370 :type gnus-article-treat-head-custom)
1371 (put 'gnus-treat-from-picon 'highlight t)
1373 (defcustom gnus-treat-mail-picon
1374 (if (and (gnus-image-type-available-p 'xpm)
1375 (gnus-picons-installed-p))
1377 "Display picons in To and Cc headers.
1378 Valid values are nil, t, `head', `last', an integer or a predicate.
1379 See Info node `(gnus)Customizing Articles' and Info node
1380 `(gnus)Picons' for details."
1382 :group 'gnus-article-treat
1384 :link '(custom-manual "(gnus)Customizing Articles")
1385 :link '(custom-manual "(gnus)Picons")
1386 :type gnus-article-treat-head-custom)
1387 (put 'gnus-treat-mail-picon 'highlight t)
1389 (defcustom gnus-treat-newsgroups-picon
1390 (if (and (gnus-image-type-available-p 'xpm)
1391 (gnus-picons-installed-p))
1393 "Display picons in the Newsgroups and Followup-To headers.
1394 Valid values are nil, t, `head', `last', an integer or a predicate.
1395 See Info node `(gnus)Customizing Articles' and Info node
1396 `(gnus)Picons' for details."
1398 :group 'gnus-article-treat
1400 :link '(custom-manual "(gnus)Customizing Articles")
1401 :link '(custom-manual "(gnus)Picons")
1402 :type gnus-article-treat-head-custom)
1403 (put 'gnus-treat-newsgroups-picon 'highlight t)
1405 (defcustom gnus-treat-body-boundary
1406 (if (and (eq window-system 'x)
1407 (or gnus-treat-newsgroups-picon
1408 gnus-treat-mail-picon
1409 gnus-treat-from-picon))
1411 "Draw a boundary at the end of the headers.
1412 Valid values are nil and `head'.
1413 See Info node `(gnus)Customizing Articles' for details."
1415 :group 'gnus-article-treat
1416 :link '(custom-manual "(gnus)Customizing Articles")
1417 :type gnus-article-treat-head-custom)
1419 (defcustom gnus-treat-capitalize-sentences nil
1420 "Capitalize sentence-starting words.
1421 Valid values are nil, t, `head', `last', an integer or a predicate.
1422 See Info node `(gnus)Customizing Articles' for details."
1424 :group 'gnus-article-treat
1425 :link '(custom-manual "(gnus)Customizing Articles")
1426 :type gnus-article-treat-custom)
1428 (defcustom gnus-treat-wash-html nil
1430 Valid values are nil, t, `head', `last', an integer or a predicate.
1431 See Info node `(gnus)Customizing Articles' for details."
1433 :group 'gnus-article-treat
1434 :link '(custom-manual "(gnus)Customizing Articles")
1435 :type gnus-article-treat-custom)
1437 (defcustom gnus-treat-fill-long-lines nil
1439 Valid values are nil, t, `head', `last', an integer or a predicate.
1440 See Info node `(gnus)Customizing Articles' for details."
1441 :group 'gnus-article-treat
1442 :link '(custom-manual "(gnus)Customizing Articles")
1443 :type gnus-article-treat-custom)
1445 (defcustom gnus-treat-play-sounds nil
1447 Valid values are nil, t, `head', `last', an integer or a predicate.
1448 See Info node `(gnus)Customizing Articles' for details."
1450 :group 'gnus-article-treat
1451 :link '(custom-manual "(gnus)Customizing Articles")
1452 :type gnus-article-treat-custom)
1454 (defcustom gnus-treat-translate nil
1455 "Translate articles from one language to another.
1456 Valid values are nil, t, `head', `last', an integer or a predicate.
1457 See Info node `(gnus)Customizing Articles' for details."
1459 :group 'gnus-article-treat
1460 :link '(custom-manual "(gnus)Customizing Articles")
1461 :type gnus-article-treat-custom)
1463 (defcustom gnus-treat-x-pgp-sig nil
1465 To automatically treat X-PGP-Sig, set it to head.
1466 Valid values are nil, t, `head', `last', an integer or a predicate.
1467 See Info node `(gnus)Customizing Articles' for details."
1469 :group 'gnus-article-treat
1470 :group 'mime-security
1471 :link '(custom-manual "(gnus)Customizing Articles")
1472 :type gnus-article-treat-custom)
1474 (defvar gnus-article-encrypt-protocol-alist
1475 '(("PGP" . mml2015-self-encrypt)))
1477 ;; Set to nil if more than one protocol added to
1478 ;; gnus-article-encrypt-protocol-alist.
1479 (defcustom gnus-article-encrypt-protocol "PGP"
1480 "The protocol used for encrypt articles.
1481 It is a string, such as \"PGP\". If nil, ask user."
1484 :group 'mime-security)
1486 (defvar gnus-article-wash-function nil
1487 "Function used for converting HTML into text.")
1489 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1490 (mm-coding-system-p 'utf-8)
1491 (executable-find idna-program))
1492 "Whether IDNA decoding of headers is used when viewing messages.
1493 This requires GNU Libidn, and by default only enabled if it is found."
1495 :group 'gnus-article-headers
1498 (defcustom gnus-article-over-scroll nil
1499 "If non-nil, allow scrolling the article buffer even when there no more text."
1501 :group 'gnus-article
1504 ;;; Internal variables
1506 (defvar gnus-english-month-names
1507 '("January" "February" "March" "April" "May" "June" "July" "August"
1508 "September" "October" "November" "December"))
1510 (defvar gnus-button-regexp nil)
1511 (defvar gnus-button-marker-list nil)
1512 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1514 (defvar gnus-button-last nil)
1515 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1517 (defvar article-goto-body-goes-to-point-min-p nil)
1518 (defvar gnus-article-wash-types nil)
1519 (defvar gnus-article-emphasis-alist nil)
1520 (defvar gnus-article-image-alist nil)
1522 (defvar gnus-article-mime-handle-alist-1 nil)
1523 (defvar gnus-treatment-function-alist
1524 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1525 (gnus-treat-strip-banner gnus-article-strip-banner)
1526 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1527 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1528 (gnus-treat-buttonize gnus-article-add-buttons)
1529 (gnus-treat-fill-article gnus-article-fill-cited-article)
1530 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1531 (gnus-treat-strip-cr gnus-article-remove-cr)
1532 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1533 (gnus-treat-date-ut gnus-article-date-ut)
1534 (gnus-treat-date-local gnus-article-date-local)
1535 (gnus-treat-date-english gnus-article-date-english)
1536 (gnus-treat-date-original gnus-article-date-original)
1537 (gnus-treat-date-user-defined gnus-article-date-user)
1538 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1539 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1540 (gnus-treat-display-x-face gnus-article-display-x-face)
1541 (gnus-treat-display-face gnus-article-display-face)
1542 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1543 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1544 (gnus-treat-hide-signature gnus-article-hide-signature)
1545 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1546 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1547 (gnus-treat-strip-pem gnus-article-hide-pem)
1548 (gnus-treat-from-picon gnus-treat-from-picon)
1549 (gnus-treat-mail-picon gnus-treat-mail-picon)
1550 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1551 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1552 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1553 (gnus-treat-strip-trailing-blank-lines
1554 gnus-article-remove-trailing-blank-lines)
1555 (gnus-treat-strip-leading-blank-lines
1556 gnus-article-strip-leading-blank-lines)
1557 (gnus-treat-strip-multiple-blank-lines
1558 gnus-article-strip-multiple-blank-lines)
1559 (gnus-treat-overstrike gnus-article-treat-overstrike)
1560 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1561 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1562 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1563 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1564 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1565 (gnus-treat-display-smileys gnus-treat-smiley)
1566 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1567 (gnus-treat-wash-html gnus-article-wash-html)
1568 (gnus-treat-emphasize gnus-article-emphasize)
1569 (gnus-treat-hide-citation gnus-article-hide-citation)
1570 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1571 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1572 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1573 (gnus-treat-play-sounds gnus-earcon-display)))
1575 (defvar gnus-article-mime-handle-alist nil)
1576 (defvar article-lapsed-timer nil)
1577 (defvar gnus-article-current-summary nil)
1579 (defvar gnus-article-mode-syntax-table
1580 (let ((table (copy-syntax-table text-mode-syntax-table)))
1581 ;; This causes the citation match run O(2^n).
1582 ;; (modify-syntax-entry ?- "w" table)
1583 (modify-syntax-entry ?> ")<" table)
1584 (modify-syntax-entry ?< "(>" table)
1585 ;; make M-. in article buffers work for `foo' strings
1586 (modify-syntax-entry ?' " " table)
1587 (modify-syntax-entry ?` " " table)
1589 "Syntax table used in article mode buffers.
1590 Initialized from `text-mode-syntax-table.")
1592 (defvar gnus-save-article-buffer nil)
1594 (defvar gnus-article-mode-line-format-alist
1595 (nconc '((?w (gnus-article-wash-status) ?s)
1596 (?m (gnus-article-mime-part-status) ?s))
1597 gnus-summary-mode-line-format-alist))
1599 (defvar gnus-number-of-articles-to-be-saved nil)
1601 (defvar gnus-inhibit-hiding nil)
1603 (defvar gnus-article-edit-mode nil)
1605 ;;; Macros for dealing with the article buffer.
1607 (defmacro gnus-with-article-headers (&rest forms)
1609 (set-buffer gnus-article-buffer)
1611 (let ((inhibit-read-only t)
1612 (inhibit-point-motion-hooks t)
1613 (case-fold-search t))
1614 (article-narrow-to-head)
1617 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1618 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1620 (defmacro gnus-with-article-buffer (&rest forms)
1622 (set-buffer gnus-article-buffer)
1623 (let ((inhibit-read-only t))
1626 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1627 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1629 (defun gnus-article-goto-header (header)
1630 "Go to HEADER, which is a regular expression."
1631 (re-search-forward (concat "^\\(" header "\\):") nil t))
1633 (defsubst gnus-article-hide-text (b e props)
1634 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1635 (gnus-add-text-properties-when 'article-type nil b e props)
1636 (when (memq 'intangible props)
1638 (max (1- b) (point-min))
1639 b 'intangible (cddr (memq 'intangible props)))))
1641 (defsubst gnus-article-unhide-text (b e)
1642 "Remove hidden text properties from region between B and E."
1643 (remove-text-properties b e gnus-hidden-properties)
1644 (when (memq 'intangible gnus-hidden-properties)
1645 (put-text-property (max (1- b) (point-min))
1646 b 'intangible nil)))
1648 (defun gnus-article-hide-text-type (b e type)
1649 "Hide text of TYPE between B and E."
1650 (gnus-add-wash-type type)
1651 (gnus-article-hide-text
1652 b e (cons 'article-type (cons type gnus-hidden-properties))))
1654 (defun gnus-article-unhide-text-type (b e type)
1655 "Unhide text of TYPE between B and E."
1656 (gnus-delete-wash-type type)
1657 (remove-text-properties
1658 b e (cons 'article-type (cons type gnus-hidden-properties)))
1659 (when (memq 'intangible gnus-hidden-properties)
1660 (put-text-property (max (1- b) (point-min))
1661 b 'intangible nil)))
1663 (defun gnus-article-hide-text-of-type (type)
1664 "Hide text of TYPE in the current buffer."
1666 (let ((b (point-min))
1668 (while (setq b (text-property-any b e 'article-type type))
1669 (add-text-properties b (incf b) gnus-hidden-properties)))))
1671 (defun gnus-article-delete-text-of-type (type)
1672 "Delete text of TYPE in the current buffer."
1674 (let ((b (point-min)))
1675 (while (setq b (text-property-any b (point-max) 'article-type type))
1677 b (or (text-property-not-all b (point-max) 'article-type type)
1680 (defun gnus-article-delete-invisible-text ()
1681 "Delete all invisible text in the current buffer."
1683 (let ((b (point-min)))
1684 (while (setq b (text-property-any b (point-max) 'invisible t))
1686 b (or (text-property-not-all b (point-max) 'invisible t)
1689 (defun gnus-article-text-type-exists-p (type)
1690 "Say whether any text of type TYPE exists in the buffer."
1691 (text-property-any (point-min) (point-max) 'article-type type))
1693 (defsubst gnus-article-header-rank ()
1694 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1695 (let ((list gnus-sorted-header-list)
1698 (if (looking-at (car list))
1700 (setq list (cdr list))
1704 (defun article-hide-headers (&optional arg delete)
1705 "Hide unwanted headers and possibly sort them as well."
1707 ;; This function might be inhibited.
1708 (unless gnus-inhibit-hiding
1709 (let ((inhibit-read-only nil)
1710 (case-fold-search t)
1711 (max (1+ (length gnus-sorted-header-list)))
1712 (inhibit-point-motion-hooks t)
1713 (cur (current-buffer))
1714 ignored visible beg)
1716 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1717 ;; group parameters, so we should go to the summary buffer.
1720 (progn (set-buffer gnus-summary-buffer) t)
1722 (setq ignored (when (not gnus-visible-headers)
1723 (cond ((stringp gnus-ignored-headers)
1724 gnus-ignored-headers)
1725 ((listp gnus-ignored-headers)
1726 (mapconcat 'identity
1727 gnus-ignored-headers
1729 visible (cond ((stringp gnus-visible-headers)
1730 gnus-visible-headers)
1731 ((and gnus-visible-headers
1732 (listp gnus-visible-headers))
1733 (mapconcat 'identity
1734 gnus-visible-headers
1738 ;; First we narrow to just the headers.
1739 (article-narrow-to-head)
1740 ;; Hide any "From " lines at the beginning of (mail) articles.
1741 (while (looking-at "From ")
1744 (delete-region (point-min) (point)))
1745 ;; Then treat the rest of the header lines.
1746 ;; Then we use the two regular expressions
1747 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1748 ;; select which header lines is to remain visible in the
1750 (while (re-search-forward "^[^ \t:]*:" nil t)
1752 ;; Mark the rank of the header.
1754 (point) (1+ (point)) 'message-rank
1755 (if (or (and visible (looking-at visible))
1757 (not (looking-at ignored))))
1758 (gnus-article-header-rank)
1761 (message-sort-headers-1)
1762 (when (setq beg (text-property-any
1763 (point-min) (point-max) 'message-rank (+ 2 max)))
1764 ;; We delete the unwanted headers.
1765 (gnus-add-wash-type 'headers)
1766 (add-text-properties (point-min) (+ 5 (point-min))
1767 '(article-type headers dummy-invisible t))
1768 (delete-region beg (point-max))))))))
1770 (defun article-hide-boring-headers (&optional arg)
1771 "Toggle hiding of headers that aren't very interesting.
1772 If given a negative prefix, always show; if given a positive prefix,
1774 (interactive (gnus-article-hidden-arg))
1775 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1776 (not gnus-show-all-headers))
1779 (let ((inhibit-read-only t)
1780 (inhibit-point-motion-hooks t))
1781 (article-narrow-to-head)
1782 (dolist (elem gnus-boring-article-headers)
1783 (goto-char (point-min))
1785 ;; Hide empty headers.
1787 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1789 (gnus-article-hide-text-type
1793 (if (re-search-forward "^[^ \t]" nil t)
1797 ;; Hide boring Newsgroups header.
1798 ((eq elem 'newsgroups)
1799 (when (gnus-string-equal
1800 (gnus-fetch-field "newsgroups")
1801 (gnus-group-real-name
1802 (if (boundp 'gnus-newsgroup-name)
1805 (gnus-article-hide-header "newsgroups")))
1806 ((eq elem 'to-address)
1807 (let ((to (message-fetch-field "to"))
1809 (gnus-parameter-to-address
1810 (if (boundp 'gnus-newsgroup-name)
1811 gnus-newsgroup-name ""))))
1812 (when (and to to-address
1815 ;; only one address in To
1816 (nth 1 (mail-extract-address-components to))
1818 (gnus-article-hide-header "to"))))
1820 (let ((to (message-fetch-field "to"))
1822 (gnus-parameter-to-list
1823 (if (boundp 'gnus-newsgroup-name)
1824 gnus-newsgroup-name ""))))
1825 (when (and to to-list
1828 ;; only one address in To
1829 (nth 1 (mail-extract-address-components to))
1831 (gnus-article-hide-header "to"))))
1833 (let ((cc (message-fetch-field "cc"))
1835 (gnus-parameter-to-list
1836 (if (boundp 'gnus-newsgroup-name)
1837 gnus-newsgroup-name ""))))
1838 (when (and cc to-list
1841 ;; only one address in CC
1842 (nth 1 (mail-extract-address-components cc))
1844 (gnus-article-hide-header "cc"))))
1845 ((eq elem 'followup-to)
1846 (when (gnus-string-equal
1847 (message-fetch-field "followup-to")
1848 (message-fetch-field "newsgroups"))
1849 (gnus-article-hide-header "followup-to")))
1850 ((eq elem 'reply-to)
1851 (if (gnus-group-find-parameter
1852 gnus-newsgroup-name 'broken-reply-to)
1853 (gnus-article-hide-header "reply-to")
1854 (let ((from (message-fetch-field "from"))
1855 (reply-to (message-fetch-field "reply-to")))
1862 (lambda (x) (downcase (cadr x)))
1863 (mail-extract-address-components from t))
1866 (lambda (x) (downcase (cadr x)))
1867 (mail-extract-address-components reply-to t))
1869 (gnus-article-hide-header "reply-to")))))
1871 (let ((date (message-fetch-field "date")))
1873 (< (days-between (current-time-string) date)
1875 (gnus-article-hide-header "date"))))
1877 (let ((to (message-fetch-field "to"))
1878 (cc (message-fetch-field "cc")))
1879 (when (> (length to) 1024)
1880 (gnus-article-hide-header "to"))
1881 (when (> (length cc) 1024)
1882 (gnus-article-hide-header "cc"))))
1886 (goto-char (point-min))
1887 (while (re-search-forward "^to:" nil t)
1888 (setq to-count (1+ to-count)))
1889 (when (> to-count 1)
1890 (while (> to-count 0)
1891 (goto-char (point-min))
1893 (re-search-forward "^to:" nil nil to-count)
1895 (narrow-to-region (point) (point-max))
1896 (gnus-article-hide-header "to"))
1897 (setq to-count (1- to-count))))
1898 (goto-char (point-min))
1899 (while (re-search-forward "^cc:" nil t)
1900 (setq cc-count (1+ cc-count)))
1901 (when (> cc-count 1)
1902 (while (> cc-count 0)
1903 (goto-char (point-min))
1905 (re-search-forward "^cc:" nil nil cc-count)
1907 (narrow-to-region (point) (point-max))
1908 (gnus-article-hide-header "cc"))
1909 (setq cc-count (1- cc-count)))))))))))))
1911 (defun gnus-article-hide-header (header)
1913 (goto-char (point-min))
1914 (when (re-search-forward (concat "^" header ":") nil t)
1915 (gnus-article-hide-text-type
1919 (if (re-search-forward "^[^ \t]" nil t)
1924 (defvar gnus-article-normalized-header-length 40
1925 "Length of normalized headers.")
1927 (defun article-normalize-headers ()
1928 "Make all header lines 40 characters long."
1930 (let ((inhibit-read-only t)
1934 (article-narrow-to-head)
1937 ((< (setq column (- (point-at-eol) (point)))
1938 gnus-article-normalized-header-length)
1940 (insert (make-string
1941 (- gnus-article-normalized-header-length column)
1943 ((> column gnus-article-normalized-header-length)
1944 (gnus-put-text-property
1946 (forward-char gnus-article-normalized-header-length)
1953 (forward-line 1))))))
1955 (defun article-treat-dumbquotes ()
1956 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1957 Note that this function guesses whether a character is a sm*rtq**t* or
1958 not, so it should only be used interactively.
1960 Sm*rtq**t*s are M****s***'s unilateral extension to the
1961 iso-8859-1 character map in an attempt to provide more quoting
1962 characters. If you see something like \\222 or \\264 where
1963 you're expecting some kind of apostrophe or quotation mark, then
1966 (article-translate-strings gnus-article-dumbquotes-map))
1968 (defun article-translate-characters (from to)
1969 "Translate all characters in the body of the article according to FROM and TO.
1970 FROM is a string of characters to translate from; to is a string of
1971 characters to translate to."
1973 (when (article-goto-body)
1974 (let ((inhibit-read-only t)
1975 (x (make-string 225 ?x))
1977 (while (< (incf i) (length x))
1980 (while (< i (length from))
1981 (aset x (aref from i) (aref to i))
1983 (translate-region (point) (point-max) x)))))
1985 (defun article-translate-strings (map)
1986 "Translate all string in the body of the article according to MAP.
1987 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1989 (when (article-goto-body)
1990 (let ((inhibit-read-only t))
1993 (while (search-forward (car elem) nil t)
1994 (replace-match (cadr elem)))))))))
1996 (defun article-treat-overstrike ()
1997 "Translate overstrikes into bold text."
2000 (when (article-goto-body)
2001 (let ((inhibit-read-only t))
2002 (while (search-forward "\b" nil t)
2003 (let ((next (char-after))
2004 (previous (char-after (- (point) 2))))
2005 ;; We do the boldification/underlining by hiding the
2006 ;; overstrikes and putting the proper text property
2010 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2011 (put-text-property (point) (1+ (point)) 'face 'bold))
2013 (gnus-article-hide-text-type
2014 (1- (point)) (1+ (point)) 'overstrike)
2016 (- (point) 2) (1- (point)) 'face 'underline))
2018 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2020 (point) (1+ (point)) 'face 'underline)))))))))
2022 (defun article-treat-ansi-sequences ()
2023 "Translate ANSI SGR control sequences into overlays or extents."
2026 (when (article-goto-body)
2027 (let ((inhibit-read-only t))
2028 (ansi-color-apply-on-region (point) (point-max))))))
2030 (defun gnus-article-treat-unfold-headers ()
2031 "Unfold folded message headers.
2032 Only the headers that fit into the current window width will be
2035 (gnus-with-article-headers
2039 (mail-header-narrow-to-field)
2040 (let ((header (buffer-string)))
2043 (goto-char (point-min))
2044 (while (re-search-forward "\n[\t ]" nil t)
2045 (replace-match " " t t)))
2046 (setq length (- (point-max) (point-min) 1)))
2047 (when (< length (window-width))
2048 (while (re-search-forward "\n[\t ]" nil t)
2049 (replace-match " " t t)))
2050 (goto-char (point-max)))))))
2052 (defun gnus-article-treat-fold-headers ()
2053 "Fold message headers."
2055 (gnus-with-article-headers
2058 (mail-header-narrow-to-field)
2059 (mail-header-fold-field)
2060 (goto-char (point-max))))))
2062 (defun gnus-treat-smiley ()
2063 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2065 (gnus-with-article-buffer
2066 (if (memq 'smiley gnus-article-wash-types)
2067 (gnus-delete-images 'smiley)
2069 (let ((images (smiley-region (point) (point-max))))
2071 (gnus-add-wash-type 'smiley)
2072 (dolist (image images)
2073 (gnus-add-image 'smiley image)))))))
2075 (defun gnus-article-remove-images ()
2076 "Remove all images from the article buffer."
2078 (gnus-with-article-buffer
2079 (dolist (elem gnus-article-image-alist)
2080 (gnus-delete-images (car elem)))))
2082 (defun gnus-article-treat-fold-newsgroups ()
2083 "Unfold folded message headers.
2084 Only the headers that fit into the current window width will be
2087 (gnus-with-article-headers
2088 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2090 (mail-header-narrow-to-field)
2091 (while (re-search-forward ", *" nil t)
2092 (replace-match ", " t t))
2093 (mail-header-fold-field)
2094 (goto-char (point-max))))))
2096 (defun gnus-article-treat-body-boundary ()
2097 "Place a boundary line at the end of the headers."
2099 (when (and gnus-body-boundary-delimiter
2100 (> (length gnus-body-boundary-delimiter) 0))
2101 (gnus-with-article-headers
2102 (goto-char (point-max))
2103 (let ((start (point)))
2104 (insert "X-Boundary: ")
2105 (gnus-add-text-properties start (point) '(invisible t intangible t))
2107 (while (>= (1- (window-width)) (length str))
2108 (setq str (concat str gnus-body-boundary-delimiter)))
2109 (substring str 0 (1- (window-width))))
2111 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2113 (defun article-fill-long-lines ()
2114 "Fill lines that are wider than the window width."
2117 (let ((inhibit-read-only t)
2118 (width (window-width (get-buffer-window (current-buffer)))))
2121 (let ((adaptive-fill-mode nil)) ;Why? -sm
2124 (when (>= (current-column) (min fill-column width))
2125 (narrow-to-region (min (1+ (point)) (point-max))
2127 (let ((goback (point-marker)))
2128 (fill-paragraph nil)
2129 (goto-char (marker-position goback)))
2131 (forward-line 1)))))))
2133 (defun article-capitalize-sentences ()
2134 "Capitalize the first word in each sentence."
2137 (let ((inhibit-read-only t)
2138 (paragraph-start "^[\n\^L]"))
2142 (forward-sentence)))))
2144 (defun article-remove-cr ()
2145 "Remove trailing CRs and then translate remaining CRs into LFs."
2148 (let ((inhibit-read-only t))
2149 (goto-char (point-min))
2150 (while (re-search-forward "\r+$" nil t)
2151 (replace-match "" t t))
2152 (goto-char (point-min))
2153 (while (search-forward "\r" nil t)
2154 (replace-match "\n" t t)))))
2156 (defun article-remove-trailing-blank-lines ()
2157 "Remove all trailing blank lines from the article."
2160 (let ((inhibit-read-only t))
2161 (goto-char (point-max))
2165 (while (and (not (bobp))
2166 (looking-at "^[ \t]*$")
2167 (not (gnus-annotation-in-region-p
2168 (point) (point-at-eol))))
2174 (defvar gnus-face-properties-alist))
2176 (defun article-display-face ()
2177 "Display any Face headers in the header."
2179 (let ((wash-face-p buffer-read-only))
2180 (gnus-with-article-headers
2181 ;; When displaying parts, this function can be called several times on
2182 ;; the same article, without any intended toggle semantic (as typing `W
2183 ;; D d' would have). So face deletion must occur only when we come from
2184 ;; an interactive command, that is when the *Article* buffer is
2186 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2187 (gnus-delete-images 'face)
2188 (let (face faces from)
2189 (save-current-buffer
2190 (when (and wash-face-p
2191 (gnus-buffer-live-p gnus-original-article-buffer)
2192 (not (re-search-forward "^Face:[\t ]*" nil t)))
2193 (set-buffer gnus-original-article-buffer))
2195 (mail-narrow-to-head)
2196 (while (gnus-article-goto-header "Face")
2197 (push (mail-header-field-value) faces))))
2199 (goto-char (point-min))
2200 (let ((from (gnus-article-goto-header "from"))
2205 (insert "[no `from' set]\n"))
2207 (when (setq png (gnus-convert-face-to-png (pop faces)))
2209 (apply 'gnus-create-image png 'png t
2210 (cdr (assq 'png gnus-face-properties-alist))))
2212 (gnus-add-wash-type 'face)
2213 (gnus-add-image 'face image)
2214 (gnus-put-image image nil 'face))))))))))
2216 (defun article-display-x-face (&optional force)
2217 "Look for an X-Face header and display it if present."
2218 (interactive (list 'force))
2219 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2220 (gnus-with-article-headers
2221 ;; Delete the old process, if any.
2222 (when (process-status "article-x-face")
2223 (delete-process "article-x-face"))
2224 ;; See the comment in `article-display-face'.
2225 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2226 ;; We have already displayed X-Faces, so we remove them
2228 (gnus-delete-images 'xface)
2230 (let (x-faces from face)
2231 (save-current-buffer
2232 (when (and wash-face-p
2233 (gnus-buffer-live-p gnus-original-article-buffer)
2234 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2235 ;; If type `W f', use gnus-original-article-buffer,
2236 ;; otherwise use the current buffer because displaying
2237 ;; RFC822 parts calls this function too.
2238 (set-buffer gnus-original-article-buffer))
2240 (mail-narrow-to-head)
2241 (while (gnus-article-goto-header "X-Face")
2242 (push (mail-header-field-value) x-faces))
2243 (setq from (message-fetch-field "from"))))
2244 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2245 ;; single external face.
2246 (when (stringp gnus-article-x-face-command)
2247 (setq x-faces (list (car x-faces))))
2249 gnus-article-x-face-command
2251 ;; Check whether this face is censored.
2252 (not gnus-article-x-face-too-ugly)
2254 (not (string-match gnus-article-x-face-too-ugly
2256 (while (setq face (pop x-faces))
2257 ;; We display the face.
2258 (cond ((stringp gnus-article-x-face-command)
2259 ;; The command is a string, so we interpret the command
2260 ;; as a, well, command, and fork it off.
2261 (let ((process-connection-type nil))
2262 (gnus-set-process-query-on-exit-flag
2264 "article-x-face" nil shell-file-name
2265 shell-command-switch gnus-article-x-face-command)
2269 (process-send-region "article-x-face"
2270 (point-min) (point-max)))
2271 (process-send-eof "article-x-face")))
2272 ((functionp gnus-article-x-face-command)
2273 ;; The command is a lisp function, so we call it.
2274 (funcall gnus-article-x-face-command face))
2276 (error "%s is not a function"
2277 gnus-article-x-face-command))))))))))
2279 (defun article-decode-mime-words ()
2280 "Decode all MIME-encoded words in the article."
2282 (gnus-with-article-buffer
2283 (let ((inhibit-point-motion-hooks t)
2284 (mail-parse-charset gnus-newsgroup-charset)
2285 (mail-parse-ignored-charsets
2286 (with-current-buffer gnus-summary-buffer
2287 gnus-newsgroup-ignored-charsets)))
2288 (mail-decode-encoded-word-region (point-min) (point-max)))))
2290 (defun article-decode-charset (&optional prompt)
2291 "Decode charset-encoded text in the article.
2292 If PROMPT (the prefix), prompt for a coding system to use."
2294 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2295 (inhibit-read-only t)
2296 (mail-parse-charset gnus-newsgroup-charset)
2297 (mail-parse-ignored-charsets
2298 (save-excursion (condition-case nil
2299 (set-buffer gnus-summary-buffer)
2301 gnus-newsgroup-ignored-charsets))
2302 ct cte ctl charset format)
2305 (article-narrow-to-head)
2306 (setq ct (message-fetch-field "Content-Type" t)
2307 cte (message-fetch-field "Content-Transfer-Encoding" t)
2308 ctl (and ct (ignore-errors
2309 (mail-header-parse-content-type ct)))
2312 (mm-read-coding-system "Charset to decode: "))
2314 (mail-content-type-get ctl 'charset)))
2315 format (and ctl (mail-content-type-get ctl 'format)))
2317 (setq cte (mail-header-strip cte)))
2318 (if (and ctl (not (string-match "/" (car ctl))))
2320 (goto-char (point-max)))
2323 (narrow-to-region (point) (point-max))
2324 (when (and (eq mail-parse-charset 'gnus-decoded)
2325 (eq (mm-body-7-or-8) '8bit))
2326 ;; The text code could have been decoded.
2327 (setq charset mail-parse-charset))
2328 (when (and (or (not ctl)
2329 (equal (car ctl) "text/plain"))
2330 (not format)) ;; article with format will decode later.
2332 charset (and cte (intern (downcase
2333 (gnus-strip-whitespace cte))))
2336 (defun article-decode-encoded-words ()
2337 "Remove encoded-word encoding from headers."
2338 (let ((inhibit-point-motion-hooks t)
2339 (mail-parse-charset gnus-newsgroup-charset)
2340 (mail-parse-ignored-charsets
2341 (save-excursion (condition-case nil
2342 (set-buffer gnus-summary-buffer)
2344 gnus-newsgroup-ignored-charsets))
2345 (inhibit-read-only t))
2347 (article-narrow-to-head)
2348 (funcall gnus-decode-header-function (point-min) (point-max)))))
2350 (defun article-decode-group-name ()
2351 "Decode group names in `Newsgroups:'."
2352 (let ((inhibit-point-motion-hooks t)
2353 (inhibit-read-only t)
2354 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2355 (when (and (or gnus-group-name-charset-method-alist
2356 gnus-group-name-charset-group-alist)
2357 (gnus-buffer-live-p gnus-original-article-buffer))
2359 (article-narrow-to-head)
2360 (with-current-buffer gnus-original-article-buffer
2361 (goto-char (point-min)))
2362 (while (re-search-forward
2363 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2364 (replace-match (save-match-data
2365 (gnus-decode-newsgroups
2366 ;; XXX how to use data in article buffer?
2367 (with-current-buffer gnus-original-article-buffer
2369 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2372 gnus-newsgroup-name method))
2374 (goto-char (point-min))
2375 (with-current-buffer gnus-original-article-buffer
2376 (goto-char (point-min)))
2377 (while (re-search-forward
2378 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2379 (replace-match (save-match-data
2380 (gnus-decode-newsgroups
2381 ;; XXX how to use data in article buffer?
2382 (with-current-buffer gnus-original-article-buffer
2384 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2387 gnus-newsgroup-name method))
2390 (autoload 'idna-to-unicode "idna")
2392 (defun article-decode-idna-rhs ()
2393 "Decode IDNA strings in RHS in various headers in current buffer.
2394 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2395 Mail-Reply-To: and Mail-Followup-To:."
2398 (let ((inhibit-point-motion-hooks t)
2399 (inhibit-read-only t))
2400 (article-narrow-to-head)
2401 (goto-char (point-min))
2402 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2404 (when (save-match-data
2405 (and (setq ace (match-string 1))
2407 (and (re-search-backward "^[^ \t]" nil t)
2408 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2409 (setq unicode (idna-to-unicode ace))))
2410 (unless (string= ace unicode)
2411 (replace-match unicode nil nil nil 1)))))))))
2413 (defun article-de-quoted-unreadable (&optional force read-charset)
2414 "Translate a quoted-printable-encoded article.
2415 If FORCE, decode the article whether it is marked as quoted-printable
2417 If READ-CHARSET, ask for a coding system."
2418 (interactive (list 'force current-prefix-arg))
2420 (let ((inhibit-read-only t) type charset)
2421 (if (gnus-buffer-live-p gnus-original-article-buffer)
2422 (with-current-buffer gnus-original-article-buffer
2424 (gnus-fetch-field "content-transfer-encoding"))
2425 (let* ((ct (gnus-fetch-field "content-type"))
2428 (mail-header-parse-content-type ct)))))
2429 (setq charset (and ctl
2430 (mail-content-type-get ctl 'charset)))
2431 (if (stringp charset)
2432 (setq charset (intern (downcase charset)))))))
2434 (setq charset (mm-read-coding-system "Charset: " charset)))
2436 (setq charset gnus-newsgroup-charset))
2438 (and type (let ((case-fold-search t))
2439 (string-match "quoted-printable" type))))
2441 (quoted-printable-decode-region
2442 (point) (point-max) (mm-charset-to-coding-system charset))))))
2444 (defun article-de-base64-unreadable (&optional force read-charset)
2445 "Translate a base64 article.
2446 If FORCE, decode the article whether it is marked as base64 not.
2447 If READ-CHARSET, ask for a coding system."
2448 (interactive (list 'force current-prefix-arg))
2450 (let ((inhibit-read-only t) type charset)
2451 (if (gnus-buffer-live-p gnus-original-article-buffer)
2452 (with-current-buffer gnus-original-article-buffer
2454 (gnus-fetch-field "content-transfer-encoding"))
2455 (let* ((ct (gnus-fetch-field "content-type"))
2458 (mail-header-parse-content-type ct)))))
2459 (setq charset (and ctl
2460 (mail-content-type-get ctl 'charset)))
2461 (if (stringp charset)
2462 (setq charset (intern (downcase charset)))))))
2464 (setq charset (mm-read-coding-system "Charset: " charset)))
2466 (setq charset gnus-newsgroup-charset))
2468 (and type (let ((case-fold-search t))
2469 (string-match "base64" type))))
2472 (narrow-to-region (point) (point-max))
2473 (base64-decode-region (point-min) (point-max))
2474 (mm-decode-coding-region
2475 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2480 (defun article-decode-HZ ()
2481 "Translate a HZ-encoded article."
2485 (let ((inhibit-read-only t))
2486 (rfc1843-decode-region (point-min) (point-max)))))
2488 (defun article-unsplit-urls ()
2489 "Remove the newlines that some other mailers insert into URLs."
2492 (let ((inhibit-read-only t))
2493 (goto-char (point-min))
2494 (while (re-search-forward
2495 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2496 (replace-match "\\1\\3" t)))
2497 (when (interactive-p)
2498 (gnus-treat-article nil))))
2501 (defun article-wash-html (&optional read-charset)
2502 "Format an HTML article.
2503 If READ-CHARSET, ask for a coding system."
2506 (let ((inhibit-read-only t)
2508 (when (gnus-buffer-live-p gnus-original-article-buffer)
2509 (with-current-buffer gnus-original-article-buffer
2510 (let* ((ct (gnus-fetch-field "content-type"))
2513 (mail-header-parse-content-type ct)))))
2514 (setq charset (and ctl
2515 (mail-content-type-get ctl 'charset)))
2516 (when (stringp charset)
2517 (setq charset (intern (downcase charset)))))))
2519 (setq charset (mm-read-coding-system "Charset: " charset)))
2521 (setq charset gnus-newsgroup-charset))
2523 (save-window-excursion
2525 (narrow-to-region (point) (point-max))
2526 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2527 (entry (assq func mm-text-html-washer-alist)))
2529 (setq func (cdr entry)))
2534 (apply (car func) (cdr func))))))))))
2536 (defun gnus-article-wash-html-with-w3 ()
2537 "Wash the current buffer with w3."
2539 (let ((w3-strict-width (window-width))
2540 (url-standalone-mode t)
2541 (url-gateway-unplugged t)
2542 (w3-honor-stylesheets nil))
2544 (w3-region (point-min) (point-max))
2547 (defun gnus-article-wash-html-with-w3m ()
2548 "Wash the current buffer with emacs-w3m."
2551 (narrow-to-region (point) (point-max))
2552 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2553 w3m-force-redisplay)
2554 (w3m-region (point-min) (point-max)))
2555 (when (and mm-inline-text-html-with-w3m-keymap
2556 (boundp 'w3m-minor-mode-map)
2558 (add-text-properties
2559 (point-min) (point-max)
2560 (list 'keymap w3m-minor-mode-map
2561 ;; Put the mark meaning this part was rendered by emacs-w3m.
2562 'mm-inline-text-html-with-w3m t)))))
2564 (defun article-hide-list-identifiers ()
2565 "Remove list identifies from the Subject header.
2566 The `gnus-list-identifiers' variable specifies what to do."
2568 (let ((inhibit-point-motion-hooks t)
2569 (regexp (if (consp gnus-list-identifiers)
2570 (mapconcat 'identity gnus-list-identifiers " *\\|")
2571 gnus-list-identifiers))
2572 (inhibit-read-only t))
2576 (article-narrow-to-head)
2577 (goto-char (point-min))
2578 (while (re-search-forward
2579 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2581 (delete-region (match-beginning 2) (match-end 0))
2582 (beginning-of-line))
2583 (when (re-search-forward
2584 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2585 (delete-region (match-beginning 1) (match-end 1))))))))
2587 (defun article-hide-pem (&optional arg)
2588 "Toggle hiding of any PEM headers and signatures in the current article.
2589 If given a negative prefix, always show; if given a positive prefix,
2591 (interactive (gnus-article-hidden-arg))
2592 (unless (gnus-article-check-hidden-text 'pem arg)
2594 (let ((inhibit-read-only t) end)
2595 (goto-char (point-min))
2596 ;; Hide the horrendously ugly "header".
2597 (when (and (search-forward
2598 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2600 (setq end (1+ (match-beginning 0))))
2601 (gnus-add-wash-type 'pem)
2602 (gnus-article-hide-text-type
2604 (if (search-forward "\n\n" nil t)
2608 ;; Hide the trailer as well
2609 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2611 (gnus-article-hide-text-type
2612 (match-beginning 0) (match-end 0) 'pem)))))))
2614 (defun article-strip-banner ()
2615 "Strip the banners specified by the `banner' group parameter and by
2616 `gnus-article-address-banner-alist'."
2620 (let ((inhibit-point-motion-hooks t))
2621 (when (gnus-parameter-banner gnus-newsgroup-name)
2622 (article-really-strip-banner
2623 (gnus-parameter-banner gnus-newsgroup-name)))
2624 (when gnus-article-address-banner-alist
2625 ;; It is necessary to encode from fields before checking,
2626 ;; because `mail-header-parse-addresses' does not work
2627 ;; (reliably) on decoded headers. And more, it is
2628 ;; impossible to use `gnus-fetch-original-field' here,
2629 ;; because `article-strip-banner' may be called in draft
2630 ;; buffers to preview them.
2631 (let ((from (save-restriction
2633 (article-narrow-to-head)
2634 (mail-fetch-field "from"))))
2637 (caar (mail-header-parse-addresses
2638 (mail-encode-encoded-word-string from)))))
2640 (dolist (pair gnus-article-address-banner-alist)
2641 (when (string-match (car pair) from)
2643 (article-really-strip-banner (cdr pair)))))))))))))
2645 (defun article-really-strip-banner (banner)
2646 "Strip the banner specified by the argument."
2649 (let ((inhibit-point-motion-hooks t)
2650 (gnus-signature-limit nil)
2651 (inhibit-read-only t))
2654 ((eq banner 'signature)
2655 (when (gnus-article-narrow-to-signature)
2658 (delete-region (point) (point-max))))
2660 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2661 (while (re-search-forward banner nil t)
2662 (delete-region (match-beginning 0) (match-end 0)))))
2664 (while (re-search-forward banner nil t)
2665 (delete-region (match-beginning 0) (match-end 0)))))))))
2667 (defun article-babel ()
2668 "Translate article using an online translation service."
2671 (gnus-with-article-buffer
2672 (when (article-goto-body)
2673 (let* ((start (point))
2675 (orig (buffer-substring start end))
2676 (trans (babel-as-string orig)))
2678 (narrow-to-region start end)
2679 (delete-region start end)
2682 (defun article-hide-signature (&optional arg)
2683 "Hide the signature in the current article.
2684 If given a negative prefix, always show; if given a positive prefix,
2686 (interactive (gnus-article-hidden-arg))
2687 (unless (gnus-article-check-hidden-text 'signature arg)
2690 (let ((inhibit-read-only t))
2691 (when (gnus-article-narrow-to-signature)
2692 (gnus-article-hide-text-type
2693 (point-min) (point-max) 'signature))))))
2694 (gnus-set-mode-line 'article))
2696 (defun article-strip-headers-in-body ()
2697 "Strip offensive headers from bodies."
2701 (let ((case-fold-search t))
2702 (when (looking-at "x-no-archive:")
2703 (gnus-delete-line)))))
2705 (defun article-strip-leading-blank-lines ()
2706 "Remove all blank lines from the beginning of the article."
2709 (let ((inhibit-point-motion-hooks t)
2710 (inhibit-read-only t))
2711 (when (article-goto-body)
2712 (while (and (not (eobp))
2713 (looking-at "[ \t]*$"))
2714 (gnus-delete-line))))))
2716 (defun article-narrow-to-head ()
2717 "Narrow the buffer to the head of the message.
2718 Point is left at the beginning of the narrowed-to region."
2720 (goto-char (point-min))
2721 (if (search-forward "\n\n" nil 1)
2724 (goto-char (point-min)))
2726 (defun article-goto-body ()
2727 "Place point at the start of the body."
2728 (goto-char (point-min))
2730 ;; This variable is only bound when dealing with separate
2732 (article-goto-body-goes-to-point-min-p
2734 ((search-forward "\n\n" nil t)
2737 (goto-char (point-max))
2740 (defun article-strip-multiple-blank-lines ()
2741 "Replace consecutive blank lines with one empty line."
2744 (let ((inhibit-point-motion-hooks t)
2745 (inhibit-read-only t))
2746 ;; First make all blank lines empty.
2748 (while (re-search-forward "^[ \t]+$" nil t)
2749 (unless (gnus-annotation-in-region-p
2750 (match-beginning 0) (match-end 0))
2751 (replace-match "" nil t)))
2752 ;; Then replace multiple empty lines with a single empty line.
2754 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2755 (unless (gnus-annotation-in-region-p
2756 (match-beginning 0) (match-end 0))
2757 (delete-region (match-beginning 1) (match-end 1)))))))
2759 (defun article-strip-leading-space ()
2760 "Remove all white space from the beginning of the lines in the article."
2763 (let ((inhibit-point-motion-hooks t)
2764 (inhibit-read-only t))
2766 (while (re-search-forward "^[ \t]+" nil t)
2767 (replace-match "" t t)))))
2769 (defun article-strip-trailing-space ()
2770 "Remove all white space from the end of the lines in the article."
2773 (let ((inhibit-point-motion-hooks t)
2774 (inhibit-read-only t))
2776 (while (re-search-forward "[ \t]+$" nil t)
2777 (replace-match "" t t)))))
2779 (defun article-strip-blank-lines ()
2780 "Strip leading, trailing and multiple blank lines."
2782 (article-strip-leading-blank-lines)
2783 (article-remove-trailing-blank-lines)
2784 (article-strip-multiple-blank-lines))
2786 (defun article-strip-all-blank-lines ()
2787 "Strip all blank lines."
2790 (let ((inhibit-point-motion-hooks t)
2791 (inhibit-read-only t))
2793 (while (re-search-forward "^[ \t]*\n" nil t)
2794 (replace-match "" t t)))))
2796 (defun gnus-article-narrow-to-signature ()
2797 "Narrow to the signature; return t if a signature is found, else nil."
2798 (let ((inhibit-point-motion-hooks t))
2799 (when (gnus-article-search-signature)
2801 ;; Check whether we have some limits to what we consider
2802 ;; to be a signature.
2803 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2804 (list gnus-signature-limit)))
2806 (while (setq limit (pop limits))
2807 (if (or (and (integerp limit)
2808 (< (- (point-max) (point)) limit))
2810 (< (count-lines (point) (point-max)) limit))
2811 (and (functionp limit)
2813 (and (stringp limit)
2814 (not (re-search-forward limit nil t))))
2815 () ; This limit did not succeed.
2819 (narrow-to-region (point) (point-max))
2822 (defun gnus-article-search-signature ()
2823 "Search the current buffer for the signature separator.
2824 Put point at the beginning of the signature separator."
2825 (let ((cur (point)))
2826 (goto-char (point-max))
2827 (if (if (stringp gnus-signature-separator)
2828 (re-search-backward gnus-signature-separator nil t)
2829 (let ((seps gnus-signature-separator))
2831 (not (re-search-backward (car seps) nil t)))
2838 (defun gnus-article-hidden-arg ()
2839 "Return the current prefix arg as a number, or 0 if no prefix."
2840 (list (if current-prefix-arg
2841 (prefix-numeric-value current-prefix-arg)
2844 (defun gnus-article-check-hidden-text (type arg)
2845 "Return nil if hiding is necessary.
2846 Arg can be nil or a number. nil and positive means hide, negative
2847 means show, 0 means toggle."
2850 (let ((hide (gnus-article-hidden-text-p type)))
2856 (gnus-article-show-hidden-text type)
2859 (if (eq hide 'hidden)
2861 (gnus-article-show-hidden-text type)
2865 (defun gnus-article-hidden-text-p (type)
2866 "Say whether the current buffer contains hidden text of type TYPE."
2867 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2869 (not (get-text-property pos 'invisible))
2870 (not (get-text-property pos 'dummy-invisible)))
2872 (text-property-any (1+ pos) (point-max) 'article-type type)))
2877 (defun gnus-article-show-hidden-text (type &optional dummy)
2878 "Show all hidden text of type TYPE.
2879 Originally it is hide instead of DUMMY."
2880 (let ((inhibit-read-only t)
2881 (inhibit-point-motion-hooks t))
2882 (gnus-remove-text-properties-when
2884 (point-min) (point-max)
2885 (cons 'article-type (cons type
2886 gnus-hidden-properties)))
2887 (gnus-delete-wash-type type)))
2889 (defconst article-time-units
2890 `((year . ,(* 365.25 24 60 60))
2891 (week . ,(* 7 24 60 60))
2892 (day . ,(* 24 60 60))
2896 "Mapping from time units to seconds.")
2898 (defun gnus-article-forward-header ()
2899 "Move point to the start of the next header.
2900 If the current header is a continuation header, this can be several
2905 (if (looking-at "[ \t]+[^ \t]")
2909 (defun article-date-ut (&optional type highlight)
2910 "Convert DATE date to universal time in the current article.
2911 If TYPE is `local', convert to local time; if it is `lapsed', output
2912 how much time has lapsed since DATE. For `lapsed', the value of
2913 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2914 should replace the \"Date:\" one, or should be added below it."
2915 (interactive (list 'ut t))
2916 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2917 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
2921 (article-lapsed-timer
2925 (case-fold-search t)
2926 (inhibit-read-only t)
2927 (inhibit-point-motion-hooks t)
2928 pos date bface eface)
2932 (goto-char (point-min))
2933 (while (or (setq date (get-text-property (setq pos (point))
2935 (when (setq pos (next-single-property-change
2936 (point) 'original-date))
2937 (setq date (get-text-property pos 'original-date))
2939 (narrow-to-region pos (or (text-property-any pos (point-max)
2942 (goto-char (point-min))
2943 (when (re-search-forward tdate-regexp nil t)
2944 (setq bface (get-text-property (point-at-bol) 'face)
2945 eface (get-text-property (1- (point-at-eol)) 'face)))
2946 (goto-char (point-min))
2948 ;; Delete any old Date headers.
2949 (while (re-search-forward date-regexp nil t)
2951 (delete-region (point-at-bol) (progn
2952 (gnus-article-forward-header)
2954 (delete-region (point-at-bol) (progn
2955 (gnus-article-forward-header)
2958 (setq pos (point))))
2959 (when (and (not pos)
2960 (re-search-forward tdate-regexp nil t))
2962 (gnus-goto-char pos)
2963 (insert (article-make-date-line date (or type 'ut)))
2969 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2970 (put-text-property (match-beginning 1) (1+ (match-end 1))
2972 (put-text-property (match-beginning 2) (match-end 2)
2974 (put-text-property (point-min) (1- (point-max)) 'original-date date)
2975 (goto-char (point-max))
2978 (defun article-make-date-line (date type)
2979 "Return a DATE line of TYPE."
2980 (unless (memq type '(local ut original user iso8601 lapsed english))
2981 (error "Unknown conversion type: %s" type))
2983 (let ((time (date-to-time date)))
2985 ;; Convert to the local timezone.
2987 (concat "Date: " (message-make-date time)))
2988 ;; Convert to Universal Time.
2993 (let* ((e (parse-time-string date))
2994 (tm (apply 'encode-time e))
2996 (ls (- (cadr tm) (car (current-time-zone time)))))
2997 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2998 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3002 ;; Get the original date from the article.
3003 ((eq type 'original)
3004 (concat "Date: " (if (string-match "\n+$" date)
3005 (substring date 0 (match-beginning 0))
3007 ;; Let the user define the format.
3009 (let ((format (or (condition-case nil
3010 (with-current-buffer gnus-summary-buffer
3011 gnus-article-time-format)
3013 gnus-article-time-format)))
3014 (if (functionp format)
3015 (funcall format time)
3016 (concat "Date: " (format-time-string format time)))))
3019 (let ((tz (car (current-time-zone time))))
3022 (format-time-string "%Y%m%dT%H%M%S" time)
3023 (format "%s%02d%02d"
3024 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3025 (/ (% (abs tz) 3600) 60)))))
3026 ;; Do an X-Sent lapsed format.
3028 ;; If the date is seriously mangled, the timezone functions are
3029 ;; liable to bug out, so we ignore all errors.
3030 (let* ((now (current-time))
3031 (real-time (subtract-time now time))
3032 (real-sec (and real-time
3033 (+ (* (float (car real-time)) 65536)
3035 (sec (and real-time (abs real-sec)))
3045 ;; This is a bit convoluted, but basically we go
3046 ;; through the time units for years, weeks, etc,
3047 ;; and divide things to see whether that results
3048 ;; in positive answers.
3051 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3052 ;; The (remaining) seconds are too few to
3053 ;; be divided into this time unit.
3055 ;; It's big enough, so we output it.
3056 (setq sec (- sec (* num (cdr unit))))
3058 (concat (if prev ", " "") (int-to-string
3060 " " (symbol-name (car unit))
3061 (if (> num 1) "s" ""))
3063 article-time-units "")
3064 ;; If dates are odd, then it might appear like the
3065 ;; article was sent in the future.
3068 " in the future"))))))
3069 ;; Display the date in proper English
3071 (let ((dtime (decode-time time)))
3074 (number-to-string (nth 3 dtime))
3075 (let ((digit (% (nth 3 dtime) 10)))
3077 ((memq (nth 3 dtime) '(11 12 13)) "th")
3083 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3085 (number-to-string (nth 5 dtime))
3087 (format "%02d" (nth 2 dtime))
3089 (format "%02d" (nth 1 dtime)))))))
3091 (format "Date: %s (from Gnus)" date))))
3093 (defun article-date-local (&optional highlight)
3094 "Convert the current article date to the local timezone."
3095 (interactive (list t))
3096 (article-date-ut 'local highlight))
3098 (defun article-date-english (&optional highlight)
3099 "Convert the current article date to something that is proper English."
3100 (interactive (list t))
3101 (article-date-ut 'english highlight))
3103 (defun article-date-original (&optional highlight)
3104 "Convert the current article date to what it was originally.
3105 This is only useful if you have used some other date conversion
3106 function and want to see what the date was before converting."
3107 (interactive (list t))
3108 (article-date-ut 'original highlight))
3110 (defun article-date-lapsed (&optional highlight)
3111 "Convert the current article date to time lapsed since it was sent."
3112 (interactive (list t))
3113 (article-date-ut 'lapsed highlight))
3115 (defun article-update-date-lapsed ()
3116 "Function to be run from a timer to update the lapsed time line."
3118 (let (deactivate-mark)
3123 (set-buffer (window-buffer w))
3124 (when (eq major-mode 'gnus-article-mode)
3125 (let ((mark (point-marker)))
3126 (goto-char (point-min))
3127 (when (re-search-forward "^X-Sent:" nil t)
3128 (article-date-lapsed t))
3129 (goto-char (marker-position mark))
3130 (move-marker mark nil))))
3133 (defun gnus-start-date-timer (&optional n)
3134 "Start a timer to update the X-Sent header in the article buffers.
3135 The numerical prefix says how frequently (in seconds) the function
3140 (gnus-stop-date-timer)
3141 (setq article-lapsed-timer
3142 (run-at-time 1 n 'article-update-date-lapsed)))
3144 (defun gnus-stop-date-timer ()
3145 "Stop the X-Sent timer."
3147 (when article-lapsed-timer
3148 (nnheader-cancel-timer article-lapsed-timer)
3149 (setq article-lapsed-timer nil)))
3151 (defun article-date-user (&optional highlight)
3152 "Convert the current article date to the user-defined format.
3153 This format is defined by the `gnus-article-time-format' variable."
3154 (interactive (list t))
3155 (article-date-ut 'user highlight))
3157 (defun article-date-iso8601 (&optional highlight)
3158 "Convert the current article date to ISO8601."
3159 (interactive (list t))
3160 (article-date-ut 'iso8601 highlight))
3162 (defmacro gnus-article-save-original-date (&rest forms)
3163 "Save the original date as a text property and evaluate FORMS."
3164 `(let* ((case-fold-search t)
3166 (goto-char (point-min))
3167 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3170 (date (when (and start
3171 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3173 (buffer-substring-no-properties start
3174 (match-beginning 0)))))
3175 (goto-char (point-max))
3176 (skip-chars-backward "\n")
3177 (put-text-property (point-min) (point) 'original-date date)
3179 (goto-char (point-max))
3180 (skip-chars-backward "\n")
3181 (put-text-property (point-min) (point) 'original-date date)))
3183 ;; (defun article-show-all ()
3184 ;; "Show all hidden text in the article buffer."
3187 ;; (let ((inhibit-read-only t))
3188 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3190 (defun article-remove-leading-whitespace ()
3191 "Remove excessive whitespace from all headers."
3195 (let ((inhibit-read-only t))
3196 (article-narrow-to-head)
3197 (goto-char (point-min))
3198 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3199 (delete-region (match-beginning 1) (match-end 1)))))))
3201 (defun article-emphasize (&optional arg)
3202 "Emphasize text according to `gnus-emphasis-alist'."
3203 (interactive (gnus-article-hidden-arg))
3204 (unless (gnus-article-check-hidden-text 'emphasis arg)
3208 (with-current-buffer gnus-summary-buffer
3209 gnus-article-emphasis-alist)
3211 gnus-emphasis-alist))
3212 (inhibit-read-only t)
3213 (props (append '(article-type emphasis)
3214 gnus-hidden-properties))
3215 regexp elem beg invisible visible face)
3218 (while (setq elem (pop alist))
3220 (setq regexp (car elem)
3221 invisible (nth 1 elem)
3222 visible (nth 2 elem)
3224 (while (re-search-forward regexp nil t)
3225 (when (and (match-beginning visible) (match-beginning invisible))
3226 (gnus-article-hide-text
3227 (match-beginning invisible) (match-end invisible) props)
3228 (gnus-article-unhide-text-type
3229 (match-beginning visible) (match-end visible) 'emphasis)
3230 (gnus-put-overlay-excluding-newlines
3231 (match-beginning visible) (match-end visible) 'face face)
3232 (gnus-add-wash-type 'emphasis)
3233 (goto-char (match-end invisible)))))))))
3235 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3236 "Setup newsgroup emphasis alist."
3237 (unless gnus-article-emphasis-alist
3238 (let ((name (and gnus-newsgroup-name
3239 (gnus-group-real-name gnus-newsgroup-name))))
3240 (make-local-variable 'gnus-article-emphasis-alist)
3241 (setq gnus-article-emphasis-alist
3243 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3244 (while (setq elem (pop alist))
3245 (when (and name (string-match (car elem) name))
3247 highlight (copy-sequence (cdr elem)))))
3249 (copy-sequence highlight-words)
3250 (if gnus-newsgroup-name
3251 (copy-sequence (gnus-group-find-parameter
3252 gnus-newsgroup-name 'highlight-words t)))
3253 gnus-emphasis-alist)))))
3256 (defvar gnus-summary-article-menu)
3257 (defvar gnus-summary-post-menu))
3259 ;;; Saving functions.
3261 (defun gnus-article-save (save-buffer file &optional num)
3262 "Save the currently selected article."
3263 (unless gnus-save-all-headers
3264 ;; Remove headers according to `gnus-saved-headers'.
3265 (let ((gnus-visible-headers
3266 (or gnus-saved-headers gnus-visible-headers))
3267 (gnus-article-buffer save-buffer))
3269 (set-buffer save-buffer)
3270 (article-hide-headers 1 t))))
3271 (save-window-excursion
3272 (if (not gnus-default-article-saver)
3273 (error "No default saver is defined")
3274 ;; !!! Magic! The saving functions all save
3275 ;; `gnus-save-article-buffer' (or so they think), but we
3276 ;; bind that variable to our save-buffer.
3277 (set-buffer gnus-article-buffer)
3278 (let* ((gnus-save-article-buffer save-buffer)
3281 ((not gnus-prompt-before-saving) 'default)
3282 ((eq gnus-prompt-before-saving 'always) nil)
3284 (gnus-number-of-articles-to-be-saved
3285 (when (eq gnus-prompt-before-saving t)
3287 (set-buffer gnus-article-current-summary)
3288 (funcall gnus-default-article-saver filename)))))
3290 (defun gnus-read-save-file-name (prompt &optional filename
3291 function group headers variable)
3293 (funcall function group headers (symbol-value variable)))
3298 ((eq filename 'default)
3304 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3307 (if (and gnus-number-of-articles-to-be-saved
3308 (> gnus-number-of-articles-to-be-saved 1))
3309 (format "these %d articles"
3310 gnus-number-of-articles-to-be-saved)
3313 ;; Let the split methods have their say.
3315 ;; No split name was found.
3318 (concat prompt " (default "
3319 (file-name-nondirectory default-name) "): ")
3320 (file-name-directory default-name)
3322 ;; A single group name is returned.
3323 ((stringp split-name)
3325 (funcall function split-name headers
3326 (symbol-value variable)))
3328 (concat prompt " (default "
3329 (file-name-nondirectory default-name) "): ")
3330 (file-name-directory default-name)
3332 ;; A single split name was found
3333 ((= 1 (length split-name))
3334 (let* ((name (expand-file-name
3336 gnus-article-save-directory))
3337 (dir (cond ((file-directory-p name)
3338 (file-name-as-directory name))
3339 ((file-exists-p name) name)
3340 (t gnus-article-save-directory))))
3342 (concat prompt " (default " name "): ")
3344 ;; A list of splits was found.
3346 (setq split-name (nreverse split-name))
3348 (let ((file-name-history
3349 (nconc split-name file-name-history)))
3353 (concat prompt " (`M-p' for defaults): ")
3354 gnus-article-save-directory
3356 gnus-article-save-directory)))
3357 (car (push result file-name-history)))))))
3358 ;; Create the directory.
3359 (gnus-make-directory (file-name-directory file))
3360 ;; If we have read a directory, we append the default file name.
3361 (when (file-directory-p file)
3362 (setq file (expand-file-name (file-name-nondirectory
3364 (file-name-as-directory file))))
3365 ;; Possibly translate some characters.
3366 (nnheader-translate-file-chars file))))))
3367 (gnus-make-directory (file-name-directory result))
3368 (set variable result)))
3370 (defun gnus-article-archive-name (group)
3371 "Return the first instance of an \"Archive-name\" in the current buffer."
3372 (let ((case-fold-search t))
3373 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3374 (nnheader-concat gnus-article-save-directory
3375 (match-string 1)))))
3377 (defun gnus-article-nndoc-name (group)
3378 "If GROUP is an nndoc group, return the name of the parent group."
3379 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3380 (gnus-group-get-parameter group 'save-article-group)))
3382 (defun gnus-summary-save-in-rmail (&optional filename)
3383 "Append this article to Rmail file.
3384 Optional argument FILENAME specifies file name.
3385 Directory to save to is default to `gnus-article-save-directory'."
3386 (setq filename (gnus-read-save-file-name
3387 "Save %s in rmail file" filename
3388 gnus-rmail-save-name gnus-newsgroup-name
3389 gnus-current-headers 'gnus-newsgroup-last-rmail))
3390 (gnus-eval-in-buffer-window gnus-save-article-buffer
3394 (gnus-output-to-rmail filename))))
3397 (defun gnus-summary-save-in-mail (&optional filename)
3398 "Append this article to Unix mail file.
3399 Optional argument FILENAME specifies file name.
3400 Directory to save to is default to `gnus-article-save-directory'."
3401 (setq filename (gnus-read-save-file-name
3402 "Save %s in Unix mail file" filename
3403 gnus-mail-save-name gnus-newsgroup-name
3404 gnus-current-headers 'gnus-newsgroup-last-mail))
3405 (gnus-eval-in-buffer-window gnus-save-article-buffer
3409 (if (and (file-readable-p filename)
3410 (file-regular-p filename)
3411 (mail-file-babyl-p filename))
3412 (rmail-output-to-rmail-file filename t)
3413 (gnus-output-to-mail filename)))))
3416 (defun gnus-summary-save-in-file (&optional filename overwrite)
3417 "Append this article to file.
3418 Optional argument FILENAME specifies file name.
3419 Directory to save to is default to `gnus-article-save-directory'."
3420 (setq filename (gnus-read-save-file-name
3421 "Save %s in file" filename
3422 gnus-file-save-name gnus-newsgroup-name
3423 gnus-current-headers 'gnus-newsgroup-last-file))
3424 (gnus-eval-in-buffer-window gnus-save-article-buffer
3428 (when (and overwrite
3429 (file-exists-p filename))
3430 (delete-file filename))
3431 (gnus-output-to-file filename))))
3434 (defun gnus-summary-write-to-file (&optional filename)
3435 "Write this article to a file, overwriting it if the file exists.
3436 Optional argument FILENAME specifies file name.
3437 The directory to save in defaults to `gnus-article-save-directory'."
3438 (gnus-summary-save-in-file nil t))
3440 (defun gnus-summary-save-body-in-file (&optional filename)
3441 "Append this article body to a file.
3442 Optional argument FILENAME specifies file name.
3443 The directory to save in defaults to `gnus-article-save-directory'."
3444 (setq filename (gnus-read-save-file-name
3445 "Save %s body in file" filename
3446 gnus-file-save-name gnus-newsgroup-name
3447 gnus-current-headers 'gnus-newsgroup-last-file))
3448 (gnus-eval-in-buffer-window gnus-save-article-buffer
3452 (when (article-goto-body)
3453 (narrow-to-region (point) (point-max)))
3454 (gnus-output-to-file filename))))
3457 (defun gnus-summary-save-in-pipe (&optional command)
3458 "Pipe this article to subprocess."
3460 (cond ((and (eq command 'default)
3461 gnus-last-shell-command)
3462 gnus-last-shell-command)
3467 "Shell command on %s: "
3468 (if (and gnus-number-of-articles-to-be-saved
3469 (> gnus-number-of-articles-to-be-saved 1))
3470 (format "these %d articles"
3471 gnus-number-of-articles-to-be-saved)
3473 gnus-last-shell-command))))
3474 (when (string-equal command "")
3475 (if gnus-last-shell-command
3476 (setq command gnus-last-shell-command)
3477 (error "A command is required")))
3478 (gnus-eval-in-buffer-window gnus-article-buffer
3481 (shell-command-on-region (point-min) (point-max) command nil)))
3482 (setq gnus-last-shell-command command))
3484 (defun gnus-summary-pipe-to-muttprint (&optional command)
3485 "Pipe this article to muttprint."
3486 (setq command (read-string
3487 "Print using command: " gnus-summary-muttprint-program
3488 nil gnus-summary-muttprint-program))
3489 (gnus-summary-save-in-pipe command))
3491 ;;; Article file names when saving.
3493 (defun gnus-capitalize-newsgroup (newsgroup)
3494 "Capitalize NEWSGROUP name."
3495 (when (not (zerop (length newsgroup)))
3496 (concat (char-to-string (upcase (aref newsgroup 0)))
3497 (substring newsgroup 1))))
3499 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3500 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3501 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3502 Otherwise, it is like ~/News/news/group/num."
3505 (concat (if (gnus-use-long-file-name 'not-save)
3506 (gnus-capitalize-newsgroup newsgroup)
3507 (gnus-newsgroup-directory-form newsgroup))
3508 "/" (int-to-string (mail-header-number headers)))
3509 gnus-article-save-directory)))
3511 (string-equal (file-name-directory default)
3512 (file-name-directory last-file))
3513 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3515 (or last-file default))))
3517 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3518 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3519 If variable `gnus-use-long-file-name' is non-nil, it is
3520 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3523 (concat (if (gnus-use-long-file-name 'not-save)
3525 (gnus-newsgroup-directory-form newsgroup))
3526 "/" (int-to-string (mail-header-number headers)))
3527 gnus-article-save-directory)))
3529 (string-equal (file-name-directory default)
3530 (file-name-directory last-file))
3531 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3533 (or last-file default))))
3535 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3536 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3537 If variable `gnus-use-long-file-name' is non-nil, it is
3538 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3541 (if (gnus-use-long-file-name 'not-save)
3544 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3546 gnus-article-save-directory)))
3548 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3549 "Generate file name from sender."
3550 (let ((from (mail-header-from headers)))
3552 (if (and from (string-match "\\([^ <]+\\)@" from))
3553 (match-string 1 from)
3555 gnus-article-save-directory)))
3557 (defun article-verify-x-pgp-sig ()
3560 (if (gnus-buffer-live-p gnus-original-article-buffer)
3561 (let ((sig (with-current-buffer gnus-original-article-buffer
3562 (gnus-fetch-field "X-PGP-Sig")))
3566 (mml2015-clear-verify-function))
3568 (insert-buffer-substring gnus-original-article-buffer)
3569 (setq items (split-string sig))
3570 (message-narrow-to-head)
3571 (let ((inhibit-point-motion-hooks t)
3572 (case-fold-search t))
3573 ;; Don't verify multiple headers.
3574 (setq headers (mapconcat (lambda (header)
3576 (mail-fetch-field header)
3578 (split-string (nth 1 items) ",") "")))
3579 (delete-region (point-min) (point-max))
3580 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3581 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3586 (if (looking-at "^-")
3589 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3590 (insert "Version: " (car items) "\n\n")
3591 (insert (mapconcat 'identity (cddr items) "\n"))
3592 (insert "\n-----END PGP SIGNATURE-----\n")
3593 (let ((mm-security-handle (list (format "multipart/signed"))))
3594 (mml2015-clean-buffer)
3595 (let ((coding-system-for-write (or gnus-newsgroup-charset
3597 (funcall (mml2015-clear-verify-function)))
3599 (or (mm-handle-multipart-ctl-parameter
3600 mm-security-handle 'gnus-details)
3601 (mm-handle-multipart-ctl-parameter
3602 mm-security-handle 'gnus-info)))))
3604 (let ((inhibit-read-only t) bface eface)
3606 (message-narrow-to-head)
3607 (goto-char (point-max))
3609 (setq bface (get-text-property (point-at-bol) 'face)
3610 eface (get-text-property (1- (point-at-eol)) 'face))
3611 (message-remove-header "X-Gnus-PGP-Verify")
3612 (if (re-search-forward "^X-PGP-Sig:" nil t)
3614 (goto-char (point-max)))
3615 (narrow-to-region (point) (point))
3616 (insert "X-Gnus-PGP-Verify: " info "\n")
3617 (goto-char (point-min))
3620 (if (not (looking-at "^[ \t]"))
3624 (goto-char (point-min))
3625 (when (looking-at "\\([^:]+\\): *")
3626 (put-text-property (match-beginning 1) (1+ (match-end 1))
3628 (put-text-property (match-end 0) (point-max)
3629 'face eface)))))))))
3631 (defun article-verify-cancel-lock ()
3632 "Verify Cancel-Lock header."
3634 (if (gnus-buffer-live-p gnus-original-article-buffer)
3635 (canlock-verify gnus-original-article-buffer)))
3642 (setq afunc (car func)
3645 gfunc (intern (format "gnus-%s" func))))
3647 (when (fboundp afunc)
3648 `(lambda (&optional interactive &rest args)
3649 ,(documentation afunc t)
3650 (interactive (list t))
3652 (set-buffer gnus-article-buffer)
3654 (call-interactively ',afunc)
3655 (apply ',afunc args))))))))
3656 '(article-hide-headers
3657 article-verify-x-pgp-sig
3658 article-verify-cancel-lock
3659 article-hide-boring-headers
3660 article-treat-overstrike
3661 article-treat-ansi-sequences
3662 article-fill-long-lines
3663 article-capitalize-sentences
3665 article-remove-leading-whitespace
3666 article-display-x-face
3667 article-display-face
3668 article-de-quoted-unreadable
3669 article-de-base64-unreadable
3672 article-unsplit-urls
3673 article-hide-list-identifiers
3674 article-strip-banner
3677 article-hide-signature
3678 article-strip-headers-in-body
3679 article-remove-trailing-blank-lines
3680 article-strip-leading-blank-lines
3681 article-strip-multiple-blank-lines
3682 article-strip-leading-space
3683 article-strip-trailing-space
3684 article-strip-blank-lines
3685 article-strip-all-blank-lines
3687 article-date-english
3688 article-date-iso8601
3689 article-date-original
3691 article-decode-mime-words
3692 article-decode-charset
3693 article-decode-encoded-words
3697 article-treat-dumbquotes
3698 article-normalize-headers
3699 ;; (article-show-all . gnus-article-show-all-headers)
3703 ;;; Gnus article mode
3706 (put 'gnus-article-mode 'mode-class 'special)
3708 (set-keymap-parent gnus-article-mode-map widget-keymap)
3710 (gnus-define-keys gnus-article-mode-map
3711 " " gnus-article-goto-next-page
3712 "\177" gnus-article-goto-prev-page
3713 [delete] gnus-article-goto-prev-page
3714 [backspace] gnus-article-goto-prev-page
3715 "\C-c^" gnus-article-refer-article
3716 "h" gnus-article-show-summary
3717 "s" gnus-article-show-summary
3718 "\C-c\C-m" gnus-article-mail
3719 "?" gnus-article-describe-briefly
3720 "e" gnus-summary-edit-article
3721 "<" beginning-of-buffer
3723 "\C-c\C-i" gnus-info-find-node
3725 "R" gnus-article-reply-with-original
3726 "F" gnus-article-followup-with-original
3727 "\C-hk" gnus-article-describe-key
3728 "\C-hc" gnus-article-describe-key-briefly
3730 "\C-d" gnus-article-read-summary-keys
3731 "\M-*" gnus-article-read-summary-keys
3732 "\M-#" gnus-article-read-summary-keys
3733 "\M-^" gnus-article-read-summary-keys
3734 "\M-g" gnus-article-read-summary-keys)
3736 (substitute-key-definition
3737 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3739 (defun gnus-article-make-menu-bar ()
3740 (unless (boundp 'gnus-article-commands-menu)
3741 (gnus-summary-make-menu-bar))
3742 (gnus-turn-off-edit-menu 'article)
3743 (unless (boundp 'gnus-article-article-menu)
3745 gnus-article-article-menu gnus-article-mode-map ""
3747 ["Scroll forwards" gnus-article-goto-next-page t]
3748 ["Scroll backwards" gnus-article-goto-prev-page t]
3749 ["Show summary" gnus-article-show-summary t]
3750 ["Fetch Message-ID at point" gnus-article-refer-article t]
3751 ["Mail to address at point" gnus-article-mail t]
3752 ["Send a bug report" gnus-bug t]))
3755 gnus-article-treatment-menu gnus-article-mode-map ""
3756 ;; Fixme: this should use :active (and maybe :visible).
3758 ["Hide headers" gnus-article-hide-headers t]
3759 ["Hide signature" gnus-article-hide-signature t]
3760 ["Hide citation" gnus-article-hide-citation t]
3761 ["Treat overstrike" gnus-article-treat-overstrike t]
3762 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3763 ["Remove carriage return" gnus-article-remove-cr t]
3764 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3765 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3766 ["Remove base64" gnus-article-de-base64-unreadable t]
3767 ["Treat html" gnus-article-wash-html t]
3768 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3769 ["Decode HZ" gnus-article-decode-HZ t]))
3771 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3773 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3775 (gnus-run-hooks 'gnus-article-menu-hook)))
3777 (defun gnus-article-mode ()
3778 "Major mode for displaying an article.
3780 All normal editing commands are switched off.
3782 The following commands are available in addition to all summary mode
3784 \\<gnus-article-mode-map>
3785 \\[gnus-article-next-page]\t Scroll the article one page forwards
3786 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3787 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3788 \\[gnus-article-show-summary]\t Display the summary buffer
3789 \\[gnus-article-mail]\t Send a reply to the address near point
3790 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3791 \\[gnus-info-find-node]\t Go to the Gnus info node"
3793 (kill-all-local-variables)
3794 (gnus-simplify-mode-line)
3795 (setq mode-name "Article")
3796 (setq major-mode 'gnus-article-mode)
3797 (make-local-variable 'minor-mode-alist)
3798 (use-local-map gnus-article-mode-map)
3799 (when (gnus-visual-p 'article-menu 'menu)
3800 (gnus-article-make-menu-bar)
3801 (when gnus-summary-tool-bar-map
3802 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3803 (gnus-update-format-specifications nil 'article-mode)
3804 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3805 (set (make-local-variable 'gnus-page-broken) nil)
3806 (make-local-variable 'gnus-button-marker-list)
3807 (make-local-variable 'gnus-article-current-summary)
3808 (make-local-variable 'gnus-article-mime-handles)
3809 (make-local-variable 'gnus-article-decoded-p)
3810 (make-local-variable 'gnus-article-mime-handle-alist)
3811 (make-local-variable 'gnus-article-wash-types)
3812 (make-local-variable 'gnus-article-image-alist)
3813 (make-local-variable 'gnus-article-charset)
3814 (make-local-variable 'gnus-article-ignored-charsets)
3815 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
3816 (set (make-local-variable 'nobreak-char-display) nil)
3817 (gnus-set-default-directory)
3818 (buffer-disable-undo)
3819 (setq buffer-read-only t
3820 show-trailing-whitespace nil)
3821 (set-syntax-table gnus-article-mode-syntax-table)
3822 (mm-enable-multibyte)
3823 (gnus-run-mode-hooks 'gnus-article-mode-hook))
3825 (defun gnus-article-setup-buffer ()
3826 "Initialize the article buffer."
3827 (let* ((name (if gnus-single-article-buffer "*Article*"
3828 (concat "*Article " gnus-newsgroup-name "*")))
3830 (progn (string-match "\\*Article" name)
3831 (concat " *Original Article"
3832 (substring name (match-end 0))))))
3833 (setq gnus-article-buffer name)
3834 (setq gnus-original-article-buffer original)
3835 (setq gnus-article-mime-handle-alist nil)
3836 ;; This might be a variable local to the summary buffer.
3837 (unless gnus-single-article-buffer
3839 (set-buffer gnus-summary-buffer)
3840 (setq gnus-article-buffer name)
3841 (setq gnus-original-article-buffer original)
3842 (gnus-set-global-variables)))
3843 (gnus-article-setup-highlight-words)
3844 ;; Init original article buffer.
3846 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3847 (mm-enable-multibyte)
3848 (setq major-mode 'gnus-original-article-mode)
3849 (make-local-variable 'gnus-original-article))
3850 (if (and (get-buffer name)
3851 (with-current-buffer name
3852 (if gnus-article-edit-mode
3853 (if (y-or-n-p "Article mode edit in progress; discard? ")
3855 (set-buffer-modified-p nil)
3856 (gnus-kill-buffer name)
3859 (error "Action aborted"))
3863 (set (make-local-variable 'gnus-article-edit-mode) nil)
3864 (when gnus-article-mime-handles
3865 (mm-destroy-parts gnus-article-mime-handles)
3866 (setq gnus-article-mime-handles nil))
3867 ;; Set it to nil in article-buffer!
3868 (setq gnus-article-mime-handle-alist nil)
3869 (buffer-disable-undo)
3870 (setq buffer-read-only t)
3871 ;; This list just keeps growing if we don't reset it.
3872 (setq gnus-button-marker-list nil)
3873 (unless (eq major-mode 'gnus-article-mode)
3874 (gnus-article-mode))
3877 (set-buffer (gnus-get-buffer-create name))
3879 (make-local-variable 'gnus-summary-buffer)
3880 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3881 (current-buffer)))))
3883 ;; Set article window start at LINE, where LINE is the number of lines
3884 ;; from the head of the article.
3885 (defun gnus-article-set-window-start (&optional line)
3887 (gnus-get-buffer-window gnus-article-buffer t)
3889 (set-buffer gnus-article-buffer)
3890 (goto-char (point-min))
3893 (gnus-message 6 "Moved to bookmark")
3894 (search-forward "\n\n" nil t)
3898 (defun gnus-article-prepare (article &optional all-headers header)
3899 "Prepare ARTICLE in article mode buffer.
3900 ARTICLE should either be an article number or a Message-ID.
3901 If ARTICLE is an id, HEADER should be the article headers.
3902 If ALL-HEADERS is non-nil, no headers are hidden."
3904 ;; Make sure we start in a summary buffer.
3905 (unless (eq major-mode 'gnus-summary-mode)
3906 (set-buffer gnus-summary-buffer))
3907 (setq gnus-summary-buffer (current-buffer))
3908 (let* ((gnus-article (if header (mail-header-number header) article))
3909 (summary-buffer (current-buffer))
3910 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3911 (group gnus-newsgroup-name)
3914 (gnus-article-setup-buffer)
3915 (set-buffer gnus-article-buffer)
3916 ;; Deactivate active regions.
3917 (when (and (boundp 'transient-mark-mode)
3918 transient-mark-mode)
3919 (setq mark-active nil))
3920 (if (not (setq result (let ((inhibit-read-only t))
3921 (gnus-request-article-this-buffer
3923 ;; There is no such article.
3925 (when (and (numberp article)
3926 (not (memq article gnus-newsgroup-sparse)))
3927 (setq gnus-article-current
3928 (cons gnus-newsgroup-name article))
3929 (set-buffer gnus-summary-buffer)
3930 (setq gnus-current-article article)
3931 (if (and (memq article gnus-newsgroup-undownloaded)
3932 (not (gnus-online (gnus-find-method-for-group
3933 gnus-newsgroup-name))))
3935 (gnus-summary-set-agent-mark article)
3936 (message "Message marked for downloading"))
3937 (gnus-summary-mark-article article gnus-canceled-mark)
3938 (unless (memq article gnus-newsgroup-sparse)
3939 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3940 (if (or (eq result 'pseudo)
3941 (eq result 'nneething))
3944 (set-buffer summary-buffer)
3945 (push article gnus-newsgroup-history)
3946 (setq gnus-last-article gnus-current-article
3947 gnus-current-article 0
3948 gnus-current-headers nil
3949 gnus-article-current nil)
3950 (if (eq result 'nneething)
3951 (gnus-configure-windows 'summary)
3952 (gnus-configure-windows 'article))
3953 (gnus-set-global-variables))
3954 (let ((gnus-article-mime-handle-alist-1
3955 gnus-article-mime-handle-alist))
3956 (gnus-set-mode-line 'article)))
3957 ;; The result from the `request' was an actual article -
3958 ;; or at least some text that is now displayed in the
3960 (when (and (numberp article)
3961 (not (eq article gnus-current-article)))
3962 ;; Seems like a new article has been selected.
3963 ;; `gnus-current-article' must be an article number.
3965 (set-buffer summary-buffer)
3966 (push article gnus-newsgroup-history)
3967 (setq gnus-last-article gnus-current-article
3968 gnus-current-article article
3969 gnus-current-headers
3970 (gnus-summary-article-header gnus-current-article)
3971 gnus-article-current
3972 (cons gnus-newsgroup-name gnus-current-article))
3973 (unless (vectorp gnus-current-headers)
3974 (setq gnus-current-headers nil))
3975 (gnus-summary-goto-subject gnus-current-article)
3976 (when (gnus-summary-show-thread)
3977 ;; If the summary buffer really was folded, the
3978 ;; previous goto may not actually have gone to
3979 ;; the right article, but the thread root instead.
3981 (gnus-summary-goto-subject gnus-current-article))
3982 (gnus-run-hooks 'gnus-mark-article-hook)
3983 (gnus-set-mode-line 'summary)
3984 (when (gnus-visual-p 'article-highlight 'highlight)
3985 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3986 ;; Set the global newsgroup variables here.
3987 (gnus-set-global-variables)
3988 (setq gnus-have-all-headers
3989 (or all-headers gnus-show-all-headers))))
3991 (gnus-configure-windows 'article))
3992 (when (or (numberp article)
3994 (gnus-article-prepare-display)
3996 (goto-char (point-min))
3997 (when gnus-break-pages
3998 (gnus-narrow-to-page)))
3999 (let ((gnus-article-mime-handle-alist-1
4000 gnus-article-mime-handle-alist))
4001 (gnus-set-mode-line 'article))
4005 (set-window-point (get-buffer-window (current-buffer)) (point))
4006 (gnus-configure-windows 'article)
4010 (defun gnus-article-prepare-display ()
4011 "Make the current buffer look like a nice article."
4012 ;; Hooks for getting information from the article.
4013 ;; This hook must be called before being narrowed.
4014 (let ((gnus-article-buffer (current-buffer))
4016 (inhibit-read-only t))
4017 (unless (eq major-mode 'gnus-article-mode)
4018 (gnus-article-mode))
4019 (setq buffer-read-only nil
4020 gnus-article-wash-types nil
4021 gnus-article-image-alist nil)
4022 (gnus-run-hooks 'gnus-tmp-internal-hook)
4023 (when gnus-display-mime-function
4024 (funcall gnus-display-mime-function))
4025 (gnus-run-hooks 'gnus-article-prepare-hook)))
4028 ;;; Gnus MIME viewing functions
4031 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4032 "Format of the MIME buttons.
4034 Valid specifiers include:
4036 %T MIME type, along with additional info
4037 %n The `name' parameter
4038 %d The description, if any
4039 %l The length of the encoded part
4040 %p The part identifier number
4041 %e Dots if the part isn't displayed
4043 General format specifiers can also be used. See Info node
4044 `(gnus)Formatting Variables'.")
4046 (defvar gnus-mime-button-line-format-alist
4047 '((?t gnus-tmp-type ?s)
4048 (?T gnus-tmp-type-long ?s)
4049 (?n gnus-tmp-name ?s)
4050 (?d gnus-tmp-description ?s)
4052 (?l gnus-tmp-length ?d)
4053 (?e gnus-tmp-dots ?s)))
4055 (defvar gnus-mime-button-commands
4056 '((gnus-article-press-button "\r" "Toggle Display")
4057 (gnus-mime-view-part "v" "View Interactively...")
4058 (gnus-mime-view-part-as-type "t" "View As Type...")
4059 (gnus-mime-view-part-as-charset "C" "View As charset...")
4060 (gnus-mime-save-part "o" "Save...")
4061 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4062 (gnus-mime-replace-part "r" "Replace part")
4063 (gnus-mime-delete-part "d" "Delete part")
4064 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4065 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4066 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4067 (gnus-mime-view-part-externally "e" "View Externally")
4068 (gnus-mime-print-part "p" "Print")
4069 (gnus-mime-pipe-part "|" "Pipe To Command...")
4070 (gnus-mime-action-on-part "." "Take action on the part...")))
4072 (defun gnus-article-mime-part-status ()
4073 (if gnus-article-mime-handle-alist-1
4074 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4076 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4079 (defvar gnus-mime-button-map
4080 (let ((map (make-sparse-keymap)))
4081 (define-key map gnus-mouse-2 'gnus-article-push-button)
4082 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4083 (dolist (c gnus-mime-button-commands)
4084 (define-key map (cadr c) (car c)))
4088 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4090 ,@(mapcar (lambda (c)
4091 (vector (caddr c) (car c) :enable t))
4092 gnus-mime-button-commands)))
4094 (defun gnus-mime-button-menu (event prefix)
4095 "Construct a context-sensitive menu of MIME commands."
4096 (interactive "e\nP")
4097 (save-window-excursion
4098 (let ((pos (event-start event)))
4099 (select-window (posn-window pos))
4100 (goto-char (posn-point pos))
4101 (gnus-article-check-buffer)
4102 (popup-menu gnus-mime-button-menu nil prefix))))
4104 (defun gnus-mime-view-all-parts (&optional handles)
4105 "View all the MIME parts."
4107 (with-current-buffer gnus-article-buffer
4108 (let ((handles (or handles gnus-article-mime-handles))
4109 (mail-parse-charset gnus-newsgroup-charset)
4110 (mail-parse-ignored-charsets
4111 (with-current-buffer gnus-summary-buffer
4112 gnus-newsgroup-ignored-charsets)))
4114 (mm-remove-parts handles)
4115 (goto-char (point-min))
4116 (or (search-forward "\n\n") (goto-char (point-max)))
4117 (let ((inhibit-read-only t))
4118 (delete-region (point) (point-max))
4119 (mm-display-parts handles))))))
4121 (defun gnus-article-jump-to-part (n)
4122 "Jump to MIME part N."
4124 (pop-to-buffer gnus-article-buffer)
4125 ;; FIXME: why is it necessary?
4127 (let ((parts (length gnus-article-mime-handle-alist)))
4130 (read-string ;; Emacs 21 doesn't have `read-number'.
4131 (format "Jump to part (2..%s): " parts)))))
4132 (unless (and (integerp n) (<= n parts) (>= n 1))
4135 (gnus-message 7 "Invalid part `%s', using %s instead."
4138 (gnus-message 9 "Jumping to part %s." n)
4139 (cond ((>= gnus-auto-select-part 1)
4140 (while (and (<= n parts)
4141 (not (gnus-article-goto-part n)))
4143 ((< gnus-auto-select-part 0)
4144 (while (and (>= n 1)
4145 (not (gnus-article-goto-part n)))
4148 (gnus-article-goto-part n)))))
4151 (defsubst gnus-article-edit-part (handles &optional current-id)
4152 "Edit an article in order to delete a mime part.
4153 This function is exclusively used by `gnus-mime-save-part-and-strip'
4154 and `gnus-mime-delete-part', and not provided at run-time normally."
4155 (gnus-article-edit-article
4157 (buffer-disable-undo)
4159 (let ((mail-parse-charset (or gnus-article-charset
4160 ',gnus-newsgroup-charset))
4161 (mail-parse-ignored-charsets
4162 (or gnus-article-ignored-charsets
4163 ',gnus-newsgroup-ignored-charsets))
4164 (mbl mml-buffer-list))
4165 (setq mml-buffer-list nil)
4166 (insert-buffer-substring gnus-original-article-buffer)
4167 (mime-to-mml ',handles)
4168 (setq gnus-article-mime-handles nil)
4169 (let ((mbl1 mml-buffer-list))
4170 (setq mml-buffer-list mbl)
4171 (set (make-local-variable 'mml-buffer-list) mbl1))
4172 (gnus-make-local-hook 'kill-buffer-hook)
4173 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4174 `(lambda (no-highlight)
4175 (let ((mail-parse-charset (or gnus-article-charset
4176 ',gnus-newsgroup-charset))
4177 (message-options message-options)
4178 (message-options-set-recipient)
4179 (mail-parse-ignored-charsets
4180 (or gnus-article-ignored-charsets
4181 ',gnus-newsgroup-ignored-charsets)))
4183 (mml-destroy-buffers)
4184 (remove-hook 'kill-buffer-hook
4185 'mml-destroy-buffers t)
4186 (kill-local-variable 'mml-buffer-list))
4187 (gnus-summary-edit-article-done
4188 ,(or (mail-header-references gnus-current-headers) "")
4189 ,(gnus-group-read-only-p)
4190 ,gnus-summary-buffer no-highlight))
4192 (gnus-article-edit-done)
4193 (gnus-summary-expand-window)
4194 (gnus-summary-show-article)
4195 (when (and current-id (integerp gnus-auto-select-part))
4196 (gnus-article-jump-to-part
4197 (+ current-id gnus-auto-select-part)))))
4199 (defun gnus-mime-replace-part (file)
4200 "Replace MIME part under point with an external body."
4201 ;; Useful if file has already been saved to disk
4205 (read-file-name "Replace MIME part with file: "
4206 (or mm-default-directory default-directory)
4208 (gnus-mime-save-part-and-strip file))
4210 (defun gnus-mime-save-part-and-strip (&optional file)
4211 "Save the MIME part under point then replace it with an external body.
4212 If FILE is given, use it for the external part."
4214 (gnus-article-check-buffer)
4215 (when (gnus-group-read-only-p)
4216 (error "The current group does not support deleting of parts"))
4217 (when (mm-complicated-handles gnus-article-mime-handles)
4219 The current article has a complicated MIME structure, giving up..."))
4220 (let* ((data (get-text-property (point) 'gnus-data))
4221 (id (get-text-property (point) 'gnus-part))
4223 (handles gnus-article-mime-handles))
4226 (and data (mm-save-part data "Delete MIME part and save to: "))))
4228 (with-current-buffer (mm-handle-buffer data)
4230 (insert "Content-Type: " (mm-handle-media-type data))
4231 (mml-insert-parameter-string (cdr (mm-handle-type data))
4234 (insert "Content-ID: " (message-make-message-id) "\n")
4235 (insert "Content-Transfer-Encoding: binary\n")
4238 (cdr (mm-make-handle nil
4239 `("message/external-body"
4240 (access-type . "LOCAL-FILE")
4242 ;; (set-buffer gnus-summary-buffer)
4243 (gnus-article-edit-part handles id))))
4245 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4246 ;; parts...>') but with stripping would be nice.
4248 (defun gnus-mime-delete-part ()
4249 "Delete the MIME part under point.
4250 Replace it with some information about the removed part."
4252 (gnus-article-check-buffer)
4253 (when (gnus-group-read-only-p)
4254 (error "The current group does not support deleting of parts"))
4255 (when (mm-complicated-handles gnus-article-mime-handles)
4257 The current article has a complicated MIME structure, giving up..."))
4258 (when (or gnus-expert-user
4259 (gnus-yes-or-no-p "\
4260 Deleting parts may malfunction or destroy the article; continue? "))
4261 (let* ((data (get-text-property (point) 'gnus-data))
4262 (id (get-text-property (point) 'gnus-part))
4263 (handles gnus-article-mime-handles)
4267 (mail-decode-encoded-word-string (or (mm-handle-description data)
4270 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4272 (type (mm-handle-media-type data)))
4274 (error "No MIME part under point"))
4275 (with-current-buffer (mm-handle-buffer data)
4276 (let ((bsize (format "%s" (buffer-size))))
4281 "| The following attachment has been deleted:\n"
4283 "| Type: " type "\n"
4284 "| Filename: " filename "\n"
4285 "| Size (encoded): " bsize " Byte\n"
4286 "| Description: " description "\n"
4289 (cdr (mm-make-handle
4290 nil `("text/plain") nil nil
4292 (format "Deleted attachment (%s bytes)" bsize))))))
4293 ;; (set-buffer gnus-summary-buffer)
4294 (gnus-article-edit-part handles id))))
4296 (defun gnus-mime-save-part ()
4297 "Save the MIME part under point."
4299 (gnus-article-check-buffer)
4300 (let ((data (get-text-property (point) 'gnus-data)))
4302 (mm-save-part data))))
4304 (defun gnus-mime-pipe-part ()
4305 "Pipe the MIME part under point to a process."
4307 (gnus-article-check-buffer)
4308 (let ((data (get-text-property (point) 'gnus-data)))
4310 (mm-pipe-part data))))
4312 (defun gnus-mime-view-part ()
4313 "Interactively choose a viewing method for the MIME part under point."
4315 (gnus-article-check-buffer)
4316 (let ((data (get-text-property (point) 'gnus-data)))
4318 (setq gnus-article-mime-handles
4320 gnus-article-mime-handles (setq data (copy-sequence data))))
4321 (mm-interactively-view-part data))))
4323 (defun gnus-mime-view-part-as-type-internal ()
4324 (gnus-article-check-buffer)
4325 (let* ((handle (get-text-property (point) 'gnus-data))
4327 ;; Content-Type: foo/bar; name=...
4328 (mail-content-type-get (mm-handle-type handle) 'name)
4329 ;; Content-Disposition: attachment; filename=...
4330 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4331 (def-type (and name (mm-default-file-encoding name))))
4332 (and def-type (cons def-type 0))))
4334 (defun gnus-mime-view-part-as-type (&optional mime-type)
4335 "Choose a MIME media type, and view the part as such."
4339 (let ((default (gnus-mime-view-part-as-type-internal)))
4341 (format "View as MIME type (default %s): "
4343 (mapcar #'list (mailcap-mime-types))
4346 (gnus-article-check-buffer)
4347 (let ((handle (get-text-property (point) 'gnus-data)))
4350 (mm-make-handle (mm-handle-buffer handle)
4351 (cons mime-type (cdr (mm-handle-type handle)))
4352 (mm-handle-encoding handle)
4353 (mm-handle-undisplayer handle)
4354 (mm-handle-disposition handle)
4355 (mm-handle-description handle)
4357 (mm-handle-id handle)))
4358 (setq gnus-article-mime-handles
4359 (mm-merge-handles gnus-article-mime-handles handle))
4360 (gnus-mm-display-part handle))))
4362 (defun gnus-mime-copy-part (&optional handle arg)
4363 "Put the MIME part under point into a new buffer.
4364 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4366 (interactive (list nil current-prefix-arg))
4367 (gnus-article-check-buffer)
4369 (setq handle (get-text-property (point) 'gnus-data)))
4371 (let ((filename (or (mail-content-type-get (mm-handle-disposition handle)
4373 (mail-content-type-get (mm-handle-disposition handle)
4375 contents dont-decode charset coding-system)
4376 (mm-with-unibyte-buffer
4377 (mm-insert-part handle)
4378 (setq contents (or (condition-case nil
4379 (mm-decompress-buffer filename nil 'sig)
4381 (setq dont-decode t)
4384 (setq filename (cond (filename (file-name-nondirectory filename))
4385 (dont-decode "*raw data*")
4390 (unless (setq charset (mail-content-type-get
4391 (mm-handle-type handle) 'charset))
4392 (unless (setq coding-system (mm-with-unibyte-buffer
4394 (mm-find-buffer-file-coding-system)))
4395 (setq charset gnus-newsgroup-charset))))
4397 (setq charset (or (cdr (assq arg
4398 gnus-summary-show-article-charset-alist))
4399 (mm-read-coding-system "Charset: ")))))
4400 (switch-to-buffer (generate-new-buffer filename))
4401 (if (or coding-system
4403 (setq coding-system (mm-charset-to-coding-system charset))
4404 (not (eq charset 'ascii))))
4406 (mm-enable-multibyte)
4407 (insert (mm-decode-coding-string contents coding-system))
4408 (setq buffer-file-coding-system
4409 (if (boundp 'last-coding-system-used)
4410 (symbol-value 'last-coding-system-used)
4412 (mm-disable-multibyte)
4414 (setq buffer-file-coding-system mm-binary-coding-system))
4415 ;; We do it this way to make `normal-mode' set the appropriate mode.
4418 (setq buffer-file-name (expand-file-name filename))
4420 (setq buffer-file-name nil))
4421 (goto-char (point-min)))))
4423 (defun gnus-mime-print-part (&optional handle filename)
4424 "Print the MIME part under point."
4425 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4426 (gnus-article-check-buffer)
4427 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4428 (contents (and handle (mm-get-part handle)))
4429 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4430 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4435 (mm-save-part-to-file handle file)
4436 (call-process shell-file-name nil
4437 (generate-new-buffer " *mm*")
4439 shell-command-switch
4441 printer file (mm-handle-type handle))))
4445 (gnus-print-buffer))
4446 (ps-despool filename)))))
4448 (defun gnus-mime-inline-part (&optional handle arg)
4449 "Insert the MIME part under point into the current buffer.
4450 Compressed files like .gz and .bz2 are decompressed."
4451 (interactive (list nil current-prefix-arg))
4452 (gnus-article-check-buffer)
4454 (setq handle (get-text-property (point) 'gnus-data)))
4457 (inhibit-read-only t)
4458 contents charset coding-system)
4459 (if (and (not arg) (mm-handle-undisplayer handle))
4460 (mm-remove-part handle)
4461 (mm-with-unibyte-buffer
4462 (mm-insert-part handle)
4464 (or (mm-decompress-buffer
4465 (or (mail-content-type-get (mm-handle-disposition handle)
4467 (mail-content-type-get (mm-handle-disposition handle)
4473 (unless (setq charset (mail-content-type-get
4474 (mm-handle-type handle) 'charset))
4475 (unless (setq coding-system
4476 (mm-with-unibyte-buffer
4478 (mm-find-buffer-file-coding-system)))
4479 (setq charset gnus-newsgroup-charset))))
4481 (if (mm-handle-undisplayer handle)
4482 (mm-remove-part handle))
4485 gnus-summary-show-article-charset-alist))
4486 (mm-read-coding-system "Charset: "))))
4488 (if (mm-handle-undisplayer handle)
4489 (mm-remove-part handle))))
4493 (if (or coding-system
4496 (mm-charset-to-coding-system charset))
4497 (not (eq coding-system 'ascii))))
4498 (mm-decode-coding-string contents coding-system)
4499 (mm-string-to-multibyte contents)))
4502 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4503 "Insert the MIME part under point into the current buffer using the
4505 (interactive (list nil current-prefix-arg))
4506 (gnus-article-check-buffer)
4507 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4510 (inhibit-read-only t))
4512 (if (mm-handle-undisplayer handle)
4513 (mm-remove-part handle))
4514 (let ((gnus-newsgroup-charset
4516 gnus-summary-show-article-charset-alist))
4517 (mm-read-coding-system "Charset: ")))
4518 (gnus-newsgroup-ignored-charsets 'gnus-all))
4519 (gnus-article-press-button)))))
4521 (defun gnus-mime-view-part-externally (&optional handle)
4522 "View the MIME part under point with an external viewer."
4524 (gnus-article-check-buffer)
4525 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4526 (mm-user-display-methods nil)
4527 (mm-inlined-types nil)
4528 (mail-parse-charset gnus-newsgroup-charset)
4529 (mail-parse-ignored-charsets
4530 (with-current-buffer gnus-summary-buffer
4531 gnus-newsgroup-ignored-charsets)))
4533 (if (mm-handle-undisplayer handle)
4534 (mm-remove-part handle)
4535 (mm-display-part handle)))))
4537 (defun gnus-mime-view-part-internally (&optional handle)
4538 "View the MIME part under point with an internal viewer.
4539 If no internal viewer is available, use an external viewer."
4541 (gnus-article-check-buffer)
4542 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4543 (mm-inlined-types '(".*"))
4544 (mm-inline-large-images t)
4545 (mail-parse-charset gnus-newsgroup-charset)
4546 (mail-parse-ignored-charsets
4547 (with-current-buffer gnus-summary-buffer
4548 gnus-newsgroup-ignored-charsets))
4549 (inhibit-read-only t))
4551 (if (mm-handle-undisplayer handle)
4552 (mm-remove-part handle)
4553 (mm-display-part handle)))))
4555 (defun gnus-mime-action-on-part (&optional action)
4556 "Do something with the MIME attachment at \(point\)."
4558 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4559 (gnus-article-check-buffer)
4560 (let ((action-pair (assoc action gnus-mime-action-alist)))
4562 (funcall (cdr action-pair)))))
4564 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
4565 "Call FUNCTION on MIME part N.
4566 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
4567 If INTERACTIVE, call FUNCTION interactivly."
4569 ;; Check whether the article is displayed.
4570 (unless (and (gnus-buffer-live-p gnus-article-buffer)
4571 (setq window (get-buffer-window gnus-article-buffer t))
4572 (frame-visible-p (setq frame (window-frame window))))
4573 (error "No article is displayed"))
4574 (with-current-buffer gnus-article-buffer
4575 ;; Check whether the article displays the right contents.
4576 (unless (with-current-buffer gnus-summary-buffer
4577 (eq gnus-current-article (gnus-summary-article-number)))
4578 (error "You should select the right article first"))
4579 ;; Check whether the specified part exists.
4580 (when (> n (length gnus-article-mime-handle-alist))
4581 (error "No such part")))
4584 ;; To select the window is needed so that the cursor
4585 ;; might be visible on the MIME button.
4586 (select-window (prog1
4588 (setq window (selected-window))
4589 ;; Article may be displayed in the other frame.
4590 (gnus-select-frame-set-input-focus
4593 (setq frame (selected-frame))))))
4594 (when (gnus-article-goto-part n)
4595 ;; We point the cursor and the arrow at the MIME button
4596 ;; when the `function' prompt the user for something.
4597 (let ((cursor-in-non-selected-windows t)
4598 (overlay-arrow-string "=>")
4599 (overlay-arrow-position (point-marker)))
4602 ((and no-handle interactive)
4603 (call-interactively function))
4609 (cdr (assq n gnus-article-mime-handle-alist))))
4612 (cdr (assq n gnus-article-mime-handle-alist)))))
4613 (set-marker overlay-arrow-position nil)
4614 (unless gnus-auto-select-part
4615 (gnus-select-frame-set-input-focus frame)
4616 (select-window window))))
4618 (if gnus-inhibit-mime-unbuttonizing
4619 ;; This is the default though the program shouldn't reach here.
4620 (error "No such part")
4621 ;; The part which doesn't have the MIME button is selected.
4622 ;; So, we display all the buttons and redo it.
4623 (let ((gnus-inhibit-mime-unbuttonizing t))
4624 (gnus-summary-show-article)
4625 (gnus-article-part-wrapper n function no-handle))))))
4627 (defun gnus-article-pipe-part (n)
4628 "Pipe MIME part N, which is the numerical prefix."
4630 (gnus-article-part-wrapper n 'mm-pipe-part))
4632 (defun gnus-article-save-part (n)
4633 "Save MIME part N, which is the numerical prefix."
4635 (gnus-article-part-wrapper n 'mm-save-part))
4637 (defun gnus-article-interactively-view-part (n)
4638 "View MIME part N interactively, which is the numerical prefix."
4640 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4642 (defun gnus-article-copy-part (n)
4643 "Copy MIME part N, which is the numerical prefix."
4645 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4647 (defun gnus-article-view-part-as-charset (n)
4648 "View MIME part N using a specified charset.
4649 N is the numerical prefix."
4651 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4653 (defun gnus-article-view-part-externally (n)
4654 "View MIME part N externally, which is the numerical prefix."
4656 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4658 (defun gnus-article-inline-part (n)
4659 "Inline MIME part N, which is the numerical prefix."
4661 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4663 (defun gnus-article-save-part-and-strip (n)
4664 "Save MIME part N and replace it with an external body.
4665 N is the numerical prefix."
4667 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
4669 (defun gnus-article-replace-part (n)
4670 "Replace MIME part N with an external body.
4671 N is the numerical prefix."
4673 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
4675 (defun gnus-article-delete-part (n)
4676 "Delete MIME part N and add some information about the removed part.
4677 N is the numerical prefix."
4679 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
4681 (defun gnus-article-mime-match-handle-first (condition)
4684 (dolist (ihandle gnus-article-mime-handle-alist)
4686 ((functionp condition)
4687 (funcall condition (cdr ihandle)))
4688 ((eq condition 'undisplayed)
4689 (not (or (mm-handle-undisplayer (cdr ihandle))
4690 (equal (mm-handle-media-type (cdr ihandle))
4691 "multipart/alternative"))))
4692 ((eq condition 'undisplayed-alternative)
4693 (not (mm-handle-undisplayer (cdr ihandle))))
4695 (gnus-article-goto-part (car ihandle))
4696 (or (not n) (< (car ihandle) n)))
4697 (setq n (car ihandle))))
4701 (defun gnus-article-view-part (&optional n)
4702 "View MIME part N, which is the numerical prefix."
4704 (with-current-buffer gnus-article-buffer
4705 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4706 gnus-article-mime-match-handle-function)))
4707 (when (> n (length gnus-article-mime-handle-alist))
4708 (error "No such part"))
4709 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4710 (when (gnus-article-goto-part n)
4711 (if (equal (car handle) "multipart/alternative")
4712 (gnus-article-press-button)
4713 (when (eq (gnus-mm-display-part handle) 'internal)
4714 (gnus-set-window-start)))))))
4716 (defsubst gnus-article-mime-total-parts ()
4717 (if (bufferp (car gnus-article-mime-handles))
4719 (1- (length gnus-article-mime-handles))))
4721 (defun gnus-mm-display-part (handle)
4722 "Display HANDLE and fix MIME button."
4723 (let ((id (get-text-property (point) 'gnus-part))
4725 (inhibit-read-only t))
4728 (let ((window (selected-window))
4729 (mail-parse-charset gnus-newsgroup-charset)
4730 (mail-parse-ignored-charsets
4731 (if (gnus-buffer-live-p gnus-summary-buffer)
4732 (with-current-buffer gnus-summary-buffer
4733 gnus-newsgroup-ignored-charsets)
4737 (let ((win (gnus-get-buffer-window (current-buffer) t))
4740 (select-window win))
4743 (if (mm-handle-displayed-p handle)
4744 ;; This will remove the part.
4745 (mm-display-part handle)
4747 (narrow-to-region (point)
4748 (if (eobp) (point) (1+ (point))))
4749 (mm-display-part handle)
4750 ;; We narrow to the part itself and
4751 ;; then call the treatment functions.
4752 (goto-char (point-min))
4754 (narrow-to-region (point) (point-max))
4757 (gnus-article-mime-total-parts)
4758 (mm-handle-media-type handle)))))
4759 (if (window-live-p window)
4760 (select-window window)))))
4763 (gnus-insert-mime-button
4764 handle id (list (mm-handle-displayed-p handle)))
4765 (goto-char point))))
4767 (defun gnus-article-goto-part (n)
4768 "Go to MIME part N."
4769 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4771 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4772 (let ((gnus-tmp-name
4773 (or (mail-content-type-get (mm-handle-type handle) 'name)
4774 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4775 (mail-content-type-get (mm-handle-type handle) 'url)
4777 (gnus-tmp-type (mm-handle-media-type handle))
4778 (gnus-tmp-description
4779 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4782 (if (if displayed (car displayed)
4783 (mm-handle-displayed-p handle))
4785 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4787 gnus-tmp-type-long b e)
4788 (when (string-match ".*/" gnus-tmp-name)
4789 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4790 (setq gnus-tmp-type-long (concat gnus-tmp-type
4791 (and (not (equal gnus-tmp-name ""))
4792 (concat "; " gnus-tmp-name))))
4793 (unless (equal gnus-tmp-description "")
4794 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4799 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4800 `(keymap ,gnus-mime-button-map
4801 gnus-callback gnus-mm-display-part
4802 gnus-part ,gnus-tmp-id
4803 article-type annotation
4806 ;; Exclude a newline.
4809 (widget-convert-button
4812 :action 'gnus-widget-press-button
4813 :button-keymap gnus-mime-button-map
4815 (lambda (widget/window &optional overlay pos)
4816 ;; Needed to properly clear the message due to a bug in
4817 ;; wid-edit (XEmacs only).
4818 (if (boundp 'help-echo-owns-message)
4819 (setq help-echo-owns-message t))
4821 "%S: %s the MIME part; %S: more options"
4822 (aref gnus-mouse-2 0)
4823 ;; XEmacs will get a single widget arg; Emacs 21 will get
4824 ;; window, overlay, position.
4825 (if (mm-handle-displayed-p
4827 (with-current-buffer (gnus-overlay-buffer overlay)
4828 (widget-get (widget-at (gnus-overlay-start overlay))
4830 (widget-get widget/window :mime-handle)))
4832 (aref gnus-down-mouse-3 0))))))
4834 (defun gnus-widget-press-button (elems el)
4835 (goto-char (widget-get elems :from))
4836 (gnus-article-press-button))
4838 (defvar gnus-displaying-mime nil)
4840 (defun gnus-display-mime (&optional ihandles)
4841 "Display the MIME parts."
4843 (save-selected-window
4844 (let ((window (get-buffer-window gnus-article-buffer))
4847 (select-window window)
4848 ;; We have to do this since selecting the window
4849 ;; may change the point. So we set the window point.
4850 (set-window-point window point)))
4851 (let ((handles ihandles)
4852 (inhibit-read-only t)
4855 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
4856 (when gnus-article-emulate-mime
4857 (mm-uu-dissect-text-parts handles)))
4858 (gnus-article-emulate-mime
4859 (setq handles (mm-uu-dissect))))
4860 (when (and (not ihandles)
4861 (not gnus-displaying-mime))
4862 ;; Top-level call; we clean up.
4863 (when gnus-article-mime-handles
4864 (mm-destroy-parts gnus-article-mime-handles)
4865 (setq gnus-article-mime-handle-alist nil));; A trick.
4866 (setq gnus-article-mime-handles handles)
4867 ;; We allow users to glean info from the handles.
4868 (when gnus-article-mime-part-function
4869 (gnus-mime-part-function handles)))
4871 (or (not (stringp (car handles)))
4874 (when (and (not ihandles)
4875 (not gnus-displaying-mime))
4876 ;; Clean up for mime parts.
4878 (delete-region (point) (point-max)))
4879 (let ((gnus-displaying-mime t))
4880 (gnus-mime-display-part handles)))
4883 (narrow-to-region (point) (point-max))
4884 (gnus-treat-article nil 1 1)
4887 ;; Highlight the headers.
4891 (narrow-to-region (point-min) (point))
4892 (gnus-article-save-original-date
4893 (gnus-treat-article 'head)))))))))
4895 (defcustom gnus-mime-display-multipart-as-mixed nil
4896 "Display \"multipart\" parts as \"multipart/mixed\".
4898 If t, it overrides nil values of
4899 `gnus-mime-display-multipart-alternative-as-mixed' and
4900 `gnus-mime-display-multipart-related-as-mixed'."
4901 :group 'gnus-article-mime
4904 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4905 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4907 :group 'gnus-article-mime
4910 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4911 "Display \"multipart/related\" parts as \"multipart/mixed\".
4913 If displaying \"text/html\" is discouraged \(see
4914 `mm-discouraged-alternatives'\) images or other material inside a
4915 \"multipart/related\" part might be overlooked when this variable is nil."
4917 :group 'gnus-article-mime
4920 (defun gnus-mime-display-part (handle)
4922 ;; Maybe a broken MIME message.
4925 ((not (stringp (car handle)))
4926 (gnus-mime-display-single handle))
4927 ;; User-defined multipart
4928 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4929 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4931 ;; multipart/alternative
4932 ((and (equal (car handle) "multipart/alternative")
4933 (not (or gnus-mime-display-multipart-as-mixed
4934 gnus-mime-display-multipart-alternative-as-mixed)))
4935 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4936 (push (cons id handle) gnus-article-mime-handle-alist)
4937 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4938 ;; multipart/related
4939 ((and (equal (car handle) "multipart/related")
4940 (not (or gnus-mime-display-multipart-as-mixed
4941 gnus-mime-display-multipart-related-as-mixed)))
4942 ;;;!!!We should find the start part, but we just default
4943 ;;;!!!to the first part.
4944 ;;(gnus-mime-display-part (cadr handle))
4945 ;;;!!! Most multipart/related is an HTML message plus images.
4946 ;;;!!! Unfortunately we are unable to let W3 display those
4947 ;;;!!! included images, so we just display it as a mixed multipart.
4948 ;;(gnus-mime-display-mixed (cdr handle))
4949 ;;;!!! No, w3 can display everything just fine.
4950 (gnus-mime-display-part (cadr handle)))
4951 ((equal (car handle) "multipart/signed")
4952 (gnus-add-wash-type 'signed)
4953 (gnus-mime-display-security handle))
4954 ((equal (car handle) "multipart/encrypted")
4955 (gnus-add-wash-type 'encrypted)
4956 (gnus-mime-display-security handle))
4957 ;; Other multiparts are handled like multipart/mixed.
4959 (gnus-mime-display-mixed (cdr handle)))))
4961 (defun gnus-mime-part-function (handles)
4962 (if (stringp (car handles))
4963 (mapcar 'gnus-mime-part-function (cdr handles))
4964 (funcall gnus-article-mime-part-function handles)))
4966 (defun gnus-mime-display-mixed (handles)
4967 (mapcar 'gnus-mime-display-part handles))
4969 (defun gnus-mime-display-single (handle)
4970 (let ((type (mm-handle-media-type handle))
4971 (ignored gnus-ignored-mime-types)
4978 (when (string-match (pop ignored) type)
4979 (throw 'ignored nil)))
4980 (if (and (setq not-attachment
4981 (and (not (mm-inline-override-p handle))
4982 (or (not (mm-handle-disposition handle))
4983 (equal (car (mm-handle-disposition handle))
4985 (mm-attachment-override-p handle))))
4986 (mm-automatic-display-p handle)
4988 (mm-inlinable-p handle)
4989 (mm-inlined-p handle))
4990 (mm-automatic-external-display-p type)))
4992 (when (equal (mm-handle-media-supertype handle) "text")
4994 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4996 (push (cons id handle) gnus-article-mime-handle-alist)
4997 (when (or (not display)
4998 (not (gnus-unbuttonized-mime-type-p type)))
4999 (gnus-insert-mime-button
5000 handle id (list (or display (and not-attachment text))))
5001 (gnus-article-insert-newline)
5002 ;; Remember modify the number of forward lines.
5010 (let ((mail-parse-charset gnus-newsgroup-charset)
5011 (mail-parse-ignored-charsets
5012 (save-excursion (condition-case ()
5013 (set-buffer gnus-summary-buffer)
5015 gnus-newsgroup-ignored-charsets)))
5016 (mm-display-part handle t))
5017 (goto-char (point-max)))
5018 ((and text not-attachment)
5022 (gnus-article-insert-newline)
5025 (let ((charset (mail-content-type-get (mm-handle-type handle)
5027 (cond ((not charset)
5028 (mm-string-as-multibyte (mm-get-part handle)))
5029 ((eq charset 'gnus-decoded)
5030 (with-current-buffer (mm-handle-buffer handle)
5033 (mm-decode-string (mm-get-part handle) charset)))))
5034 (goto-char (point-max))))
5038 (narrow-to-region beg (point))
5041 (gnus-article-mime-total-parts)
5042 (mm-handle-media-type handle)))))))))
5044 (defun gnus-unbuttonized-mime-type-p (type)
5045 "Say whether TYPE is to be unbuttonized."
5046 (unless gnus-inhibit-mime-unbuttonizing
5048 (let ((types gnus-unbuttonized-mime-types))
5050 (when (string-match (pop types) type)
5051 (throw 'found t)))))
5053 (let ((types gnus-buttonized-mime-types))
5055 (when (string-match (pop types) type)
5056 (throw 'found t)))))))))
5058 (defun gnus-article-insert-newline ()
5059 "Insert a newline, but mark it as undeletable."
5060 (gnus-put-text-property
5061 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5063 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5064 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5067 handle (inhibit-read-only t) from props begend not-pref)
5068 (save-window-excursion
5071 (narrow-to-region (car ibegend)
5074 (goto-char (car ibegend))
5077 (delete-region (point-min) (point-max))
5078 (mm-remove-parts handles))
5079 (setq begend (list (point-marker)))
5081 (unless (setq not-pref (cadr (member preferred ihandles)))
5082 (setq not-pref (car ihandles)))
5085 (not (gnus-unbuttonized-mime-type-p
5086 "multipart/alternative")))
5087 (gnus-add-text-properties
5090 (insert (format "%d. " id))
5094 (unless ,(not ibegend)
5095 (setq gnus-article-mime-handle-alist
5096 ',gnus-article-mime-handle-alist))
5097 (gnus-mime-display-alternative
5098 ',ihandles ',not-pref ',begend ,id))
5099 keymap ,gnus-mime-button-map
5100 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5101 face ,gnus-article-button-face
5104 (widget-convert-button 'link from (point)
5105 :action 'gnus-widget-press-button
5106 :button-keymap gnus-widget-button-keymap)
5108 (while (setq handle (pop handles))
5109 (gnus-add-text-properties
5112 (insert (format "(%c) %-18s"
5113 (if (equal handle preferred) ?* ? )
5114 (mm-handle-media-type handle)))
5118 (unless ,(not ibegend)
5119 (setq gnus-article-mime-handle-alist
5120 ',gnus-article-mime-handle-alist))
5121 (gnus-mime-display-alternative
5122 ',ihandles ',handle ',begend ,id))
5123 keymap ,gnus-mime-button-map
5124 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5125 face ,gnus-article-button-face
5128 (widget-convert-button 'link from (point)
5129 :action 'gnus-widget-press-button
5130 :button-keymap gnus-widget-button-keymap)
5134 (if (stringp (car preferred))
5135 (gnus-display-mime preferred)
5136 (let ((mail-parse-charset gnus-newsgroup-charset)
5137 (mail-parse-ignored-charsets
5138 (with-current-buffer gnus-summary-buffer
5139 gnus-newsgroup-ignored-charsets)))
5140 (mm-display-part preferred)
5144 (narrow-to-region (car begend) (point-max))
5146 nil (length gnus-article-mime-handle-alist)
5147 (gnus-article-mime-total-parts)
5148 (mm-handle-media-type handle))))))
5149 (goto-char (point-max))
5150 (setcdr begend (point-marker)))))
5152 (goto-char point))))
5154 (defconst gnus-article-wash-status-strings
5155 (let ((alist '((cite "c" "Possible hidden citation text"
5156 " " "All citation text visible")
5157 (headers "h" "Hidden headers"
5158 " " "All headers visible.")
5159 (pgp "p" "Encrypted or signed message status hidden"
5160 " " "No hidden encryption nor digital signature status")
5161 (signature "s" "Signature has been hidden"
5162 " " "Signature is visible")
5163 (overstrike "o" "Overstrike (^H) characters applied"
5164 " " "No overstrike characters applied")
5165 (emphasis "e" "/*_Emphasis_*/ characters applied"
5166 " " "No /*_emphasis_*/ characters applied")))
5168 (dolist (entry alist result)
5169 (let ((key (nth 0 entry))
5170 (on (copy-sequence (nth 1 entry)))
5171 (on-help (nth 2 entry))
5172 (off (copy-sequence (nth 3 entry)))
5173 (off-help (nth 4 entry)))
5174 (put-text-property 0 1 'help-echo on-help on)
5175 (put-text-property 0 1 'help-echo off-help off)
5176 (push (list key on off) result))))
5177 "Alist of strings describing wash status in the mode line.
5178 Each entry has the form (KEY ON OF), where the KEY is a symbol
5179 representing the particular washing function, ON is the string to use
5180 in the article mode line when the washing function is active, and OFF
5181 is the string to use when it is inactive.")
5183 (defun gnus-article-wash-status-entry (key value)
5184 (let ((entry (assoc key gnus-article-wash-status-strings)))
5185 (if value (nth 1 entry) (nth 2 entry))))
5187 (defun gnus-article-wash-status ()
5188 "Return a string which display status of article washing."
5189 (with-current-buffer gnus-article-buffer
5190 (let ((cite (memq 'cite gnus-article-wash-types))
5191 (headers (memq 'headers gnus-article-wash-types))
5192 (boring (memq 'boring-headers gnus-article-wash-types))
5193 (pgp (memq 'pgp gnus-article-wash-types))
5194 (pem (memq 'pem gnus-article-wash-types))
5195 (signed (memq 'signed gnus-article-wash-types))
5196 (encrypted (memq 'encrypted gnus-article-wash-types))
5197 (signature (memq 'signature gnus-article-wash-types))
5198 (overstrike (memq 'overstrike gnus-article-wash-types))
5199 (emphasis (memq 'emphasis gnus-article-wash-types)))
5201 (gnus-article-wash-status-entry 'cite cite)
5202 (gnus-article-wash-status-entry 'headers (or headers boring))
5203 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5204 (gnus-article-wash-status-entry 'signature signature)
5205 (gnus-article-wash-status-entry 'overstrike overstrike)
5206 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5208 (defun gnus-add-wash-type (type)
5209 "Add a washing of TYPE to the current status."
5210 (add-to-list 'gnus-article-wash-types type))
5212 (defun gnus-delete-wash-type (type)
5213 "Add a washing of TYPE to the current status."
5214 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5216 (defun gnus-add-image (category image)
5217 "Add IMAGE of CATEGORY to the list of displayed images."
5218 (let ((entry (assq category gnus-article-image-alist)))
5220 (setq entry (list category))
5221 (push entry gnus-article-image-alist))
5222 (nconc entry (list image))))
5224 (defun gnus-delete-images (category)
5225 "Delete all images in CATEGORY."
5226 (let ((entry (assq category gnus-article-image-alist)))
5227 (dolist (image (cdr entry))
5228 (gnus-remove-image image category))
5229 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5230 (gnus-delete-wash-type category)))
5232 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5234 (defun gnus-article-maybe-hide-headers ()
5235 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5236 Provided for backwards compatibility."
5237 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5238 (not (with-current-buffer gnus-summary-buffer
5239 gnus-have-all-headers)))
5240 (not gnus-inhibit-hiding))
5241 (gnus-article-hide-headers)))
5245 (defun gnus-output-to-file (file-name)
5246 "Append the current article to a file named FILE-NAME."
5247 (let ((artbuf (current-buffer)))
5249 (insert-buffer-substring artbuf)
5250 ;; Append newline at end of the buffer as separator, and then
5252 (goto-char (point-max))
5254 (let ((file-name-coding-system nnmail-pathname-coding-system))
5255 (mm-append-to-file (point-min) (point-max) file-name))
5258 (defun gnus-narrow-to-page (&optional arg)
5259 "Narrow the article buffer to a page.
5260 If given a numerical ARG, move forward ARG pages."
5262 (setq arg (if arg (prefix-numeric-value arg) 0))
5264 (set-buffer gnus-article-buffer)
5265 (goto-char (point-min))
5267 ;; Remove any old next/prev buttons.
5268 (when (gnus-visual-p 'page-marker)
5269 (let ((inhibit-read-only t))
5270 (gnus-remove-text-with-property 'gnus-prev)
5271 (gnus-remove-text-with-property 'gnus-next)))
5274 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5276 (re-search-forward page-delimiter nil 'move arg)))
5277 (goto-char (match-end 0))
5279 (goto-char (point-min))
5280 (setq gnus-page-broken
5281 (and (re-search-forward page-delimiter nil t) t))))
5282 (when gnus-page-broken
5285 (if (re-search-forward page-delimiter nil 'move)
5288 (when (and (gnus-visual-p 'page-marker)
5289 (> (point-min) (save-restriction (widen) (point-min))))
5291 (goto-char (point-min))
5292 (gnus-insert-prev-page-button)))
5293 (when (and (gnus-visual-p 'page-marker)
5294 (< (point-max) (save-restriction (widen) (point-max))))
5296 (goto-char (point-max))
5297 (gnus-insert-next-page-button))))))
5299 ;; Article mode commands
5301 (defun gnus-article-goto-next-page ()
5302 "Show the next page of the article."
5304 (when (gnus-article-next-page)
5305 (goto-char (point-min))
5306 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5309 (defun gnus-article-goto-prev-page ()
5310 "Show the previous page of the article."
5313 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5314 (gnus-article-prev-page nil)))
5316 ;; This is cleaner but currently breaks `gnus-pick-mode':
5318 ;; (defun gnus-article-goto-next-page ()
5319 ;; "Show the next page of the article."
5321 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5322 ;; (gnus-summary-next-page)))
5324 ;; (defun gnus-article-goto-prev-page ()
5325 ;; "Show the next page of the article."
5327 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5328 ;; (gnus-summary-prev-page)))
5330 (defun gnus-article-next-page (&optional lines)
5331 "Show the next page of the current article.
5332 If end of article, return non-nil. Otherwise return nil.
5333 Argument LINES specifies lines to be scrolled up."
5335 (move-to-window-line -1)
5338 (and (pos-visible-in-window-p) ;Not continuation line.
5339 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5340 ;; Nothing in this page.
5341 (if (or (not gnus-page-broken)
5346 (eobp)))) ;Real end-of-buffer?
5348 (when gnus-article-over-scroll
5349 (gnus-article-next-page-1 lines))
5351 (gnus-narrow-to-page 1) ;Go to next page.
5353 ;; More in this page.
5354 (gnus-article-next-page-1 lines)
5357 (defmacro gnus-article-beginning-of-window ()
5358 "Move point to the beginning of the window.
5359 In Emacs, the point is placed at the line number which `scroll-margin'
5361 (if (featurep 'xemacs)
5362 '(move-to-window-line 0)
5363 '(move-to-window-line
5364 (min (max 0 scroll-margin)
5365 (max 1 (- (window-height)
5366 (if mode-line-format 1 0)
5367 (if header-line-format 1 0)))))))
5369 (defun gnus-article-next-page-1 (lines)
5370 (when (and (not (featurep 'xemacs))
5373 (numberp (symbol-value 'scroll-margin))
5374 (> (symbol-value 'scroll-margin) 0))
5375 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5376 ;; too many number of lines if `scroll-margin' is set as two or greater.
5377 (setq lines (min lines
5378 (max 0 (- (count-lines (window-start) (point-max))
5379 (symbol-value 'scroll-margin))))))
5381 (let ((scroll-in-place nil))
5384 ;; Long lines may cause an end-of-buffer error.
5385 (goto-char (point-max))))
5386 (gnus-article-beginning-of-window))
5388 (defun gnus-article-prev-page (&optional lines)
5389 "Show previous page of current article.
5390 Argument LINES specifies lines to be scrolled down."
5392 (move-to-window-line 0)
5393 (if (and gnus-page-broken
5395 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5397 (gnus-narrow-to-page -1) ;Go to previous page.
5398 (goto-char (point-max))
5402 (let ((scroll-in-place nil))
5403 (scroll-down lines))
5404 (beginning-of-buffer
5405 (goto-char (point-min))))
5406 (gnus-article-beginning-of-window))))
5408 (defun gnus-article-only-boring-p ()
5409 "Decide whether there is only boring text remaining in the article.
5410 Something \"interesting\" is a word of at least two letters that does
5411 not have a face in `gnus-article-boring-faces'."
5412 (when (and gnus-article-skip-boring
5413 (boundp 'gnus-article-boring-faces)
5414 (symbol-value 'gnus-article-boring-faces))
5417 (while (re-search-forward "\\b\\w\\w" nil t)
5419 (when (not (gnus-intersection
5420 (gnus-faces-at (point))
5421 (symbol-value 'gnus-article-boring-faces)))
5422 (throw 'only-boring nil)))
5423 (throw 'only-boring t)))))
5425 (defun gnus-article-refer-article ()
5426 "Read article specified by message-id around point."
5429 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5430 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5431 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5432 (let ((msg-id (concat "<" (match-string 0) ">")))
5433 (set-buffer gnus-summary-buffer)
5434 (gnus-summary-refer-article msg-id))
5435 (error "No references around point"))))
5437 (defun gnus-article-show-summary ()
5438 "Reconfigure windows to show summary buffer."
5440 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5441 (error "There is no summary buffer for this article buffer")
5442 (gnus-article-set-globals)
5443 (gnus-configure-windows 'article)
5444 (gnus-summary-goto-subject gnus-current-article)
5445 (gnus-summary-position-point)))
5447 (defun gnus-article-describe-briefly ()
5448 "Describe article mode commands briefly."
5450 (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")))
5452 (defun gnus-article-summary-command ()
5453 "Execute the last keystroke in the summary buffer."
5455 (let ((obuf (current-buffer))
5456 (owin (current-window-configuration))
5458 (switch-to-buffer gnus-article-current-summary 'norecord)
5459 (setq func (lookup-key (current-local-map) (this-command-keys)))
5460 (call-interactively func)
5462 (set-window-configuration owin)
5463 (set-window-point (get-buffer-window (current-buffer)) (point))))
5465 (defun gnus-article-summary-command-nosave ()
5466 "Execute the last keystroke in the summary buffer."
5469 (pop-to-buffer gnus-article-current-summary 'norecord)
5470 (setq func (lookup-key (current-local-map) (this-command-keys)))
5471 (call-interactively func)))
5473 (defun gnus-article-check-buffer ()
5474 "Beep if not in an article buffer."
5475 (unless (equal major-mode 'gnus-article-mode)
5476 (error "Command invoked outside of a Gnus article buffer")))
5478 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5479 "Read a summary buffer key sequence and execute it from the article buffer."
5481 (gnus-article-check-buffer)
5483 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5484 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5485 "=" "^" "\M-^" "|"))
5491 '("n" "Gn" "p" "Gp"))
5494 (set-buffer gnus-article-current-summary)
5495 (let (gnus-pick-mode)
5496 (push (or key last-command-event) unread-command-events)
5497 (setq keys (if (featurep 'xemacs)
5498 (events-to-keys (read-key-sequence nil))
5499 (read-key-sequence nil)))))
5503 (if (or (member keys nosaves)
5504 (member keys nosave-but-article)
5505 (member keys nosave-in-article))
5507 (save-window-excursion
5508 (pop-to-buffer gnus-article-current-summary 'norecord)
5509 ;; We disable the pick minor mode commands.
5510 (let (gnus-pick-mode)
5511 (setq func (lookup-key (current-local-map) keys))))
5515 (unless (member keys nosave-in-article)
5516 (set-buffer gnus-article-current-summary))
5517 (call-interactively func)
5518 (setq new-sum-point (point)))
5519 (when (member keys nosave-but-article)
5520 (pop-to-buffer gnus-article-buffer 'norecord)))
5521 ;; These commands should restore window configuration.
5522 (let ((obuf (current-buffer))
5523 (owin (current-window-configuration))
5525 win func in-buffer selected new-sum-start new-sum-hscroll)
5526 (cond (not-restore-window
5527 (pop-to-buffer gnus-article-current-summary 'norecord))
5528 ((setq win (get-buffer-window gnus-article-current-summary))
5529 (select-window win))
5531 (switch-to-buffer gnus-article-current-summary 'norecord)))
5532 (setq in-buffer (current-buffer))
5533 ;; We disable the pick minor mode commands.
5534 (if (and (setq func (let (gnus-pick-mode)
5535 (lookup-key (current-local-map) keys)))
5538 (call-interactively func)
5539 (when (eq win (selected-window))
5540 (setq new-sum-point (point)
5541 new-sum-start (window-start win)
5542 new-sum-hscroll (window-hscroll win)))
5543 (when (eq in-buffer (current-buffer))
5544 (setq selected (gnus-summary-select-article))
5546 (unless not-restore-window
5547 (set-window-configuration owin))
5548 (when (eq selected 'old)
5550 (set-window-start (get-buffer-window (current-buffer))
5552 (set-window-point (get-buffer-window (current-buffer))
5554 (when (and (not not-restore-window)
5556 (set-window-point win new-sum-point)
5557 (set-window-start win new-sum-start)
5558 (set-window-hscroll win new-sum-hscroll))))
5559 (set-window-configuration owin)
5562 (defun gnus-article-describe-key (key)
5563 "Display documentation of the function invoked by KEY. KEY is a string."
5564 (interactive "kDescribe key: ")
5565 (gnus-article-check-buffer)
5566 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5568 (set-buffer gnus-article-current-summary)
5569 (let (gnus-pick-mode)
5570 (if (featurep 'xemacs)
5572 (push (elt key 0) unread-command-events)
5573 (setq key (events-to-keys
5574 (read-key-sequence "Describe key: "))))
5575 (setq unread-command-events
5577 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5578 (string-to-list key)))
5579 (setq key (read-key-sequence "Describe key: "))))
5581 (describe-key key)))
5583 (defun gnus-article-describe-key-briefly (key &optional insert)
5584 "Display documentation of the function invoked by KEY. KEY is a string."
5585 (interactive "kDescribe key: \nP")
5586 (gnus-article-check-buffer)
5587 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5589 (set-buffer gnus-article-current-summary)
5590 (let (gnus-pick-mode)
5591 (if (featurep 'xemacs)
5593 (push (elt key 0) unread-command-events)
5594 (setq key (events-to-keys
5595 (read-key-sequence "Describe key: "))))
5596 (setq unread-command-events
5598 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5599 (string-to-list key)))
5600 (setq key (read-key-sequence "Describe key: "))))
5601 (describe-key-briefly key insert))
5602 (describe-key-briefly key insert)))
5604 (defun gnus-article-reply-with-original (&optional wide)
5605 "Start composing a reply mail to the current message.
5606 The text in the region will be yanked. If the region isn't active,
5607 the entire article will be yanked."
5609 (let ((article (cdr gnus-article-current))
5611 (if (not (gnus-region-active-p))
5612 (with-current-buffer gnus-summary-buffer
5613 (gnus-summary-reply (list (list article)) wide))
5614 (setq contents (buffer-substring (point) (mark t)))
5615 ;; Deactivate active regions.
5616 (when (and (boundp 'transient-mark-mode)
5617 transient-mark-mode)
5618 (setq mark-active nil))
5619 (with-current-buffer gnus-summary-buffer
5621 (list (list article contents)) wide)))))
5623 (defun gnus-article-followup-with-original ()
5624 "Compose a followup to the current article.
5625 The text in the region will be yanked. If the region isn't active,
5626 the entire article will be yanked."
5628 (let ((article (cdr gnus-article-current))
5630 (if (not (gnus-region-active-p))
5631 (with-current-buffer gnus-summary-buffer
5632 (gnus-summary-followup (list (list article))))
5633 (setq contents (buffer-substring (point) (mark t)))
5634 ;; Deactivate active regions.
5635 (when (and (boundp 'transient-mark-mode)
5636 transient-mark-mode)
5637 (setq mark-active nil))
5638 (with-current-buffer gnus-summary-buffer
5639 (gnus-summary-followup
5640 (list (list article contents)))))))
5642 (defun gnus-article-hide (&optional arg force)
5643 "Hide all the gruft in the current article.
5644 This means that signatures, cited text and (some) headers will be
5646 If given a prefix, show the hidden text instead."
5647 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5648 (gnus-article-hide-headers arg)
5649 (gnus-article-hide-list-identifiers arg)
5650 (gnus-article-hide-citation-maybe arg force)
5651 (gnus-article-hide-signature arg))
5653 (defun gnus-article-maybe-highlight ()
5654 "Do some article highlighting if article highlighting is requested."
5655 (when (gnus-visual-p 'article-highlight 'highlight)
5656 (gnus-article-highlight-some)))
5658 (defun gnus-check-group-server ()
5659 ;; Make sure the connection to the server is alive.
5660 (unless (gnus-server-opened
5661 (gnus-find-method-for-group gnus-newsgroup-name))
5662 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5663 (gnus-request-group gnus-newsgroup-name t)))
5666 (autoload 'nneething-get-file-name "nneething"))
5668 (defun gnus-request-article-this-buffer (article group)
5669 "Get an article and insert it into this buffer."
5670 (let (do-update-line sparse-header)
5674 (gnus-kill-all-overlays)
5675 (setq group (or group gnus-newsgroup-name))
5677 ;; Using `gnus-request-article' directly will insert the article into
5678 ;; `nntp-server-buffer' - so we'll save some time by not having to
5679 ;; copy it from the server buffer into the article buffer.
5681 ;; We only request an article by message-id when we do not have the
5682 ;; headers for it, so we'll have to get those.
5683 (when (stringp article)
5684 (gnus-read-header article))
5686 ;; If the article number is negative, that means that this article
5687 ;; doesn't belong in this newsgroup (possibly), so we find its
5688 ;; message-id and request it by id instead of number.
5689 (when (and (numberp article)
5691 (get-buffer gnus-summary-buffer)
5692 (gnus-buffer-exists-p gnus-summary-buffer))
5694 (set-buffer gnus-summary-buffer)
5695 (let ((header (gnus-summary-article-header article)))
5698 ((memq article gnus-newsgroup-sparse)
5699 ;; This is a sparse gap article.
5700 (setq do-update-line article)
5701 (setq article (mail-header-id header))
5702 (setq sparse-header (gnus-read-header article))
5703 (setq gnus-newsgroup-sparse
5704 (delq article gnus-newsgroup-sparse)))
5706 ;; It's a real article.
5707 (setq article (mail-header-id header)))
5709 ;; It is an extracted pseudo-article.
5710 (setq article 'pseudo)
5711 (gnus-request-pseudo-article header))))
5713 (let ((method (gnus-find-method-for-group
5714 gnus-newsgroup-name)))
5715 (when (and (eq (car method) 'nneething)
5717 (let ((dir (nneething-get-file-name
5718 (mail-header-id header))))
5719 (when (and (stringp dir)
5720 (file-directory-p dir))
5721 (setq article 'nneething)
5722 (gnus-group-enter-directory dir))))))))
5725 ;; Refuse to select canceled articles.
5726 ((and (numberp article)
5728 (get-buffer gnus-summary-buffer)
5729 (gnus-buffer-exists-p gnus-summary-buffer)
5730 (eq (cdr (with-current-buffer gnus-summary-buffer
5731 (assq article gnus-newsgroup-reads)))
5732 gnus-canceled-mark))
5734 ;; We first check `gnus-original-article-buffer'.
5735 ((and (get-buffer gnus-original-article-buffer)
5737 (with-current-buffer gnus-original-article-buffer
5738 (and (equal (car gnus-original-article) group)
5739 (eq (cdr gnus-original-article) article))))
5740 (insert-buffer-substring gnus-original-article-buffer)
5742 ;; Check the backlog.
5743 ((and gnus-keep-backlog
5744 (gnus-backlog-request-article group article (current-buffer)))
5746 ;; Check asynchronous pre-fetch.
5747 ((gnus-async-request-fetched-article group article (current-buffer))
5748 (gnus-async-prefetch-next group article gnus-summary-buffer)
5749 (when (and (numberp article) gnus-keep-backlog)
5750 (gnus-backlog-enter-article group article (current-buffer)))
5753 ((and gnus-use-cache
5755 (gnus-cache-request-article article group))
5757 ;; Check the agent cache.
5758 ((gnus-agent-request-article article group)
5760 ;; Get the article and put into the article buffer.
5761 ((or (stringp article)
5763 (let ((gnus-override-method gnus-override-method)
5764 (methods (and (stringp article)
5765 gnus-refer-article-method))
5766 (backend (car (gnus-find-method-for-group
5767 gnus-newsgroup-name)))
5769 (inhibit-read-only t))
5770 (if (or (not (listp methods))
5771 (and (symbolp (car methods))
5772 (assq (car methods) nnoo-definition-alist)))
5773 (setq methods (list methods)))
5774 (when (and (null gnus-override-method)
5776 (setq gnus-override-method (pop methods)))
5778 (when (eq gnus-override-method 'current)
5779 (setq gnus-override-method
5780 (with-current-buffer gnus-summary-buffer
5781 gnus-current-select-method)))
5783 (gnus-kill-all-overlays)
5784 (let ((gnus-newsgroup-name group))
5785 (gnus-check-group-server))
5787 ((gnus-request-article article group (current-buffer))
5788 (when (numberp article)
5789 (gnus-async-prefetch-next group article
5790 gnus-summary-buffer)
5791 (when gnus-keep-backlog
5792 (gnus-backlog-enter-article
5793 group article (current-buffer))))
5794 (setq result 'article))
5796 (setq gnus-override-method (pop methods)))
5797 ((not (string-match "^400 "
5798 (nnheader-get-report backend)))
5799 ;; If we get 400 server disconnect, reconnect and
5800 ;; retry; otherwise, assume the article has expired.
5801 (setq result 'done))))
5802 (and (eq result 'article) 'article)))
5806 ;; Associate this article with the current summary buffer.
5807 (setq gnus-article-current-summary gnus-summary-buffer)
5809 ;; Take the article from the original article buffer
5810 ;; and place it in the buffer it's supposed to be in.
5811 (when (and (get-buffer gnus-article-buffer)
5812 (equal (buffer-name (current-buffer))
5813 (buffer-name (get-buffer gnus-article-buffer))))
5815 (if (get-buffer gnus-original-article-buffer)
5816 (set-buffer gnus-original-article-buffer)
5817 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5818 (buffer-disable-undo)
5819 (setq major-mode 'gnus-original-article-mode)
5820 (setq buffer-read-only t))
5821 (let ((inhibit-read-only t))
5823 (insert-buffer-substring gnus-article-buffer))
5824 (setq gnus-original-article (cons group article)))
5827 (run-hooks 'gnus-article-decode-hook)
5828 ;; Mark article as decoded or not.
5829 (setq gnus-article-decoded-p gnus-article-decode-hook))
5831 ;; Update sparse articles.
5832 (when (and do-update-line
5833 (or (numberp article)
5835 (let ((buf (current-buffer)))
5836 (set-buffer gnus-summary-buffer)
5837 (gnus-summary-update-article do-update-line sparse-header)
5838 (gnus-summary-goto-subject do-update-line nil t)
5839 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5841 (set-buffer buf))))))
5847 (defcustom gnus-article-edit-mode-hook nil
5848 "Hook run in article edit mode buffers."
5849 :group 'gnus-article-various
5852 (defvar gnus-article-edit-done-function nil)
5854 (defvar gnus-article-edit-mode-map nil)
5856 ;; Should we be using derived.el for this?
5857 (unless gnus-article-edit-mode-map
5858 (setq gnus-article-edit-mode-map (make-keymap))
5859 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5861 (gnus-define-keys gnus-article-edit-mode-map
5862 "\C-c?" describe-mode
5863 "\C-c\C-c" gnus-article-edit-done
5864 "\C-c\C-k" gnus-article-edit-exit
5865 "\C-c\C-f\C-t" message-goto-to
5866 "\C-c\C-f\C-o" message-goto-from
5867 "\C-c\C-f\C-b" message-goto-bcc
5868 ;;"\C-c\C-f\C-w" message-goto-fcc
5869 "\C-c\C-f\C-c" message-goto-cc
5870 "\C-c\C-f\C-s" message-goto-subject
5871 "\C-c\C-f\C-r" message-goto-reply-to
5872 "\C-c\C-f\C-n" message-goto-newsgroups
5873 "\C-c\C-f\C-d" message-goto-distribution
5874 "\C-c\C-f\C-f" message-goto-followup-to
5875 "\C-c\C-f\C-m" message-goto-mail-followup-to
5876 "\C-c\C-f\C-k" message-goto-keywords
5877 "\C-c\C-f\C-u" message-goto-summary
5878 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5879 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5880 "\C-c\C-b" message-goto-body
5881 "\C-c\C-i" message-goto-signature
5883 "\C-c\C-t" message-insert-to
5884 "\C-c\C-n" message-insert-newsgroups
5885 "\C-c\C-o" message-sort-headers
5886 "\C-c\C-e" message-elide-region
5887 "\C-c\C-v" message-delete-not-region
5888 "\C-c\C-z" message-kill-to-signature
5889 "\M-\r" message-newline-and-reformat
5890 "\C-c\C-a" mml-attach-file
5891 "\C-a" message-beginning-of-line
5893 "\M-;" comment-region)
5895 (gnus-define-keys (gnus-article-edit-wash-map
5896 "\C-c\C-w" gnus-article-edit-mode-map)
5897 "f" gnus-article-edit-full-stops))
5900 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5902 ["Fetch To" message-insert-to t]
5903 ["Fetch Newsgroups" message-insert-newsgroups t]
5905 ["To" message-goto-to t]
5906 ["From" message-goto-from t]
5907 ["Subject" message-goto-subject t]
5908 ["Cc" message-goto-cc t]
5909 ["Reply-To" message-goto-reply-to t]
5910 ["Summary" message-goto-summary t]
5911 ["Keywords" message-goto-keywords t]
5912 ["Newsgroups" message-goto-newsgroups t]
5913 ["Followup-To" message-goto-followup-to t]
5914 ["Mail-Followup-To" message-goto-mail-followup-to t]
5915 ["Distribution" message-goto-distribution t]
5916 ["Body" message-goto-body t]
5917 ["Signature" message-goto-signature t]))
5919 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
5920 "Major mode for editing articles.
5921 This is an extended text-mode.
5923 \\{gnus-article-edit-mode-map}"
5924 (make-local-variable 'gnus-article-edit-done-function)
5925 (make-local-variable 'gnus-prev-winconf)
5926 (set (make-local-variable 'font-lock-defaults)
5927 '(message-font-lock-keywords t))
5928 (set (make-local-variable 'mail-header-separator) "")
5929 (set (make-local-variable 'gnus-article-edit-mode) t)
5930 (easy-menu-add message-mode-field-menu message-mode-map)
5932 (setq buffer-read-only nil)
5933 (buffer-enable-undo)
5936 (defun gnus-article-edit (&optional force)
5937 "Edit the current article.
5938 This will have permanent effect only in mail groups.
5939 If FORCE is non-nil, allow editing of articles even in read-only
5942 (when (and (not force)
5943 (gnus-group-read-only-p))
5944 (error "The current newsgroup does not support article editing"))
5945 (gnus-article-date-original)
5946 (gnus-article-edit-article
5948 `(lambda (no-highlight)
5950 (gnus-summary-edit-article-done
5951 ,(or (mail-header-references gnus-current-headers) "")
5952 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5954 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
5955 "Start editing the contents of the current article buffer."
5956 (let ((winconf (current-window-configuration)))
5957 (set-buffer gnus-article-buffer)
5958 (let ((message-auto-save-directory
5959 ;; Don't associate the article buffer with a draft file.
5961 (gnus-article-edit-mode))
5962 (funcall start-func)
5963 (set-buffer-modified-p nil)
5964 (gnus-configure-windows 'edit-article)
5965 (setq gnus-article-edit-done-function exit-func)
5966 (setq gnus-prev-winconf winconf)
5968 (gnus-message 6 "C-c C-c to end edits"))))
5970 (defun gnus-article-edit-done (&optional arg)
5971 "Update the article edits and exit."
5973 (let ((func gnus-article-edit-done-function)
5974 (buf (current-buffer))
5975 (start (window-start))
5977 (winconf gnus-prev-winconf))
5978 (widen) ;; Widen it in case that users narrowed the buffer.
5981 ;; The cache and backlog have to be flushed somewhat.
5982 (when gnus-keep-backlog
5983 (gnus-backlog-remove-article
5984 (car gnus-article-current) (cdr gnus-article-current)))
5985 ;; Flush original article as well.
5987 (when (get-buffer gnus-original-article-buffer)
5988 (set-buffer gnus-original-article-buffer)
5989 (setq gnus-original-article nil)))
5990 (when gnus-use-cache
5991 (gnus-cache-update-article
5992 (car gnus-article-current) (cdr gnus-article-current)))
5993 ;; We remove all text props from the article buffer.
5994 (kill-all-local-variables)
5995 (set-text-properties (point-min) (point-max) nil)
5997 (set-window-configuration winconf)
5999 (set-window-start (get-buffer-window buf) start)
6000 (set-window-point (get-buffer-window buf) (point)))
6001 (gnus-summary-show-article))
6003 (defun gnus-article-edit-exit ()
6004 "Exit the article editing without updating."
6006 (when (or (not (buffer-modified-p))
6007 (yes-or-no-p "Article modified; kill anyway? "))
6008 (let ((curbuf (current-buffer))
6010 (window-start (window-start)))
6012 (if (gnus-buffer-live-p gnus-original-article-buffer)
6013 (insert-buffer-substring gnus-original-article-buffer))
6014 (let ((winconf gnus-prev-winconf))
6015 (kill-all-local-variables)
6017 (set-window-configuration winconf)
6018 ;; Tippy-toe some to make sure that point remains where it was.
6019 (save-current-buffer
6021 (set-window-start (get-buffer-window (current-buffer)) window-start)
6023 (gnus-summary-show-article)))
6025 (defun gnus-article-edit-full-stops ()
6026 "Interactively repair spacing at end of sentences."
6029 (goto-char (point-min))
6030 (search-forward-regexp "^$" nil t)
6031 (let ((case-fold-search nil))
6032 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6035 ;;; Article highlights
6038 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6040 ;;; Internal Variables:
6042 (defcustom gnus-button-url-regexp
6043 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6044 "\\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:]]\\)"
6045 "\\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\\)\\)")
6046 "Regular expression that matches URLs."
6047 :group 'gnus-article-buttons
6050 (defcustom gnus-button-valid-fqdn-regexp
6051 message-valid-fqdn-regexp
6052 "Regular expression that matches a valid FQDN."
6054 :group 'gnus-article-buttons
6057 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6058 (defcustom gnus-button-valid-localpart-regexp
6059 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*"
6060 "Regular expression that matches a localpart of mail addresses or MIDs."
6062 :group 'gnus-article-buttons
6065 (defcustom gnus-button-man-handler 'manual-entry
6066 "Function to use for displaying man pages.
6067 The function must take at least one argument with a string naming the
6070 :type '(choice (function-item :tag "Man" manual-entry)
6071 (function-item :tag "Woman" woman)
6072 (function :tag "Other"))
6073 :group 'gnus-article-buttons)
6075 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6076 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6077 If the default site is too slow, try to find a CTAN mirror, see
6078 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6079 the variable `gnus-button-handle-ctan'."
6081 :group 'gnus-article-buttons
6082 :link '(custom-manual "(gnus)Group Parameters")
6083 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6084 (const "http://tug.ctan.org/tex-archive/")
6085 (const "http://www.dante.de/CTAN/")
6086 (string :tag "Other")))
6088 (defcustom gnus-button-ctan-handler 'browse-url
6089 "Function to use for displaying CTAN links.
6090 The function must take one argument, the string naming the URL."
6092 :type '(choice (function-item :tag "Browse Url" browse-url)
6093 (function :tag "Other"))
6094 :group 'gnus-article-buttons)
6096 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6097 "Bogus strings removed from CTAN URLs."
6099 :group 'gnus-article-buttons
6100 :type '(choice (const "^/?tex-archive/\\|/")
6101 (regexp :tag "Other")))
6103 (defcustom gnus-button-ctan-directory-regexp
6105 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6106 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6107 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6108 "tds" "tools" "usergrps" "web") t)
6109 "Regular expression for ctan directories.
6110 It should match all directories in the top level of `gnus-ctan-url'."
6112 :group 'gnus-article-buttons
6115 (defcustom gnus-button-mid-or-mail-regexp
6116 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6117 gnus-button-valid-fqdn-regexp
6119 "Regular expression that matches a message ID or a mail address."
6121 :group 'gnus-article-buttons
6124 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6125 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6126 Strings like this can be either a message ID or a mail address. If it is one
6127 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6128 message ID or a mail address, respectively. If this variable is set to the
6129 symbol `ask', always query the user what do do. If it is a function, this
6130 function will be called with the string as it's only argument. The function
6131 must return `mid', `mail', `invalid' or `ask'."
6133 :group 'gnus-article-buttons
6134 :type '(choice (function-item :tag "Heuristic function"
6135 gnus-button-mid-or-mail-heuristic)
6140 (defcustom gnus-button-mid-or-mail-heuristic-alist
6141 '((-10.0 . ".+\\$.+@")
6144 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6145 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6146 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6147 (-1.0 . "^[^a-z]+@")
6149 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6150 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6151 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6152 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6155 (-1.0 . "^[0-9][0-9]")
6157 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6158 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6159 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6160 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6162 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6163 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6166 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6168 ;; compensation for TDMA dated mail addresses:
6169 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6171 (-20.0 . "\\.fsf@") ;; Gnus
6174 (-20.0 . "_-_") ;; Subject change in thread
6176 (-20.0 . "\\.ln@") ;; leafnode
6177 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6178 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6180 ;; (5.0 . "") ;; $local_part_len <= 7
6181 (10.0 . "^[^0-9]+@")
6182 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6183 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6186 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6188 (0.5 . "^[A-Z][a-z]")
6189 (0.5 . "^[A-Z][a-z][a-z]")
6190 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6191 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6192 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6194 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6195 address. The REGEXP is processed with `case-fold-search' set to nil."
6197 :group 'gnus-article-buttons
6198 :type '(repeat (cons (number :tag "Rate")
6199 (regexp :tag "Regexp"))))
6201 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6202 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6203 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6204 address, `ask' if unsure and `invalid' if the string is invalid."
6205 (let ((case-fold-search nil)
6206 (list gnus-button-mid-or-mail-heuristic-alist)
6207 (result 0) rate regexp lpartlen elem)
6209 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6210 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6211 ;; Certain special cases...
6214 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6215 "^[0-9]+\\.[0-9]+@compuserve\\|"
6216 "@public\\.gmane\\.org")
6218 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6219 (setq result 'mail))
6220 (when (string-match "@.*@\\| " mid-or-mail)
6221 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6222 (setq result 'invalid))
6223 ;; Nothing more to do, if result is not a number here...
6224 (when (numberp result)
6226 (setq elem (car list)
6230 (when (string-match regexp mid-or-mail)
6231 (setq result (+ result rate))
6233 9 "`%s' matched `%s', rate `%s', result `%s'."
6234 mid-or-mail regexp rate result)))
6235 (when (<= lpartlen 7)
6236 (setq result (+ result 5.0))
6237 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6238 mid-or-mail result))
6239 (when (>= lpartlen 12)
6240 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6242 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6243 ;; Long local part should contain realname if e-mail address,
6244 ;; too many digits: message-id.
6245 ;; $score -= 5.0 + 0.1 * $local_part_len;
6246 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6247 (setq result (+ result rate))
6249 9 "Many digits in `%s', rate `%s', result `%s'."
6250 mid-or-mail rate result))
6251 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6253 ;; Too few vowels [^aeiouy]{4,}.*\@
6254 (setq result (+ result -5.0))
6256 9 "Few vowels in `%s', rate `%s', result `%s'."
6257 mid-or-mail -5.0 result))
6259 (setq result (+ result 5.0))
6261 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6262 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6263 ;; Maybe we should make this a customizable alist: (condition . 'result)
6265 ((symbolp result) result)
6266 ;; Now convert number into proper results:
6267 ((< result -10.0) 'mid)
6268 ((> result 10.0) 'mail)
6271 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6272 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6273 (url-mid (concat "news" ":" mid-or-mail))
6274 (url-mailto (concat "mailto" ":" mid-or-mail)))
6275 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6276 (when (fboundp pref)
6278 ;; get rid of surrounding angles...
6280 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6281 (if (or (eq 'mid guessed) (eq 'mail guessed))
6285 (save-window-excursion
6286 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6289 (cond ((eq pref 'mid)
6290 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6291 (gnus-button-handle-news url-mid))
6293 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6294 (gnus-url-mailto url-mailto))
6295 (t (gnus-message 3 "Invalid string.")))))
6297 (defun gnus-button-handle-custom (url)
6298 "Follow a Custom URL."
6299 (customize-apropos (gnus-url-unhex-string url)))
6301 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6303 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6306 (defun gnus-button-handle-describe-function (url)
6307 "Call `describe-function' when pushing the corresponding URL button."
6310 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6312 (defun gnus-button-handle-describe-variable (url)
6313 "Call `describe-variable' when pushing the corresponding URL button."
6316 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6318 (defun gnus-button-handle-symbol (url)
6319 "Display help on variable or function.
6320 Calls `describe-variable' or `describe-function'."
6321 (let ((sym (intern url)))
6323 ((fboundp sym) (describe-function sym))
6324 ((boundp sym) (describe-variable sym))
6325 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6327 (defun gnus-button-handle-describe-key (url)
6328 "Call `describe-key' when pushing the corresponding URL button."
6330 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6331 (keys (ignore-errors (eval `(kbd ,key-string)))))
6334 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6336 (defun gnus-button-handle-apropos (url)
6337 "Call `apropos' when pushing the corresponding URL button."
6338 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6340 (defun gnus-button-handle-apropos-command (url)
6341 "Call `apropos' when pushing the corresponding URL button."
6343 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6345 (defun gnus-button-handle-apropos-variable (url)
6346 "Call `apropos' when pushing the corresponding URL button."
6348 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6349 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6351 (defun gnus-button-handle-apropos-documentation (url)
6352 "Call `apropos' when pushing the corresponding URL button."
6354 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6355 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6357 (defun gnus-button-handle-library (url)
6358 "Call `locate-library' when pushing the corresponding URL button."
6359 (gnus-message 9 "url=`%s'" url)
6360 (let* ((lib (locate-library url))
6361 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6363 (gnus-message 1 "Cannot locale library `%s'." url)
6364 (find-file-read-only file))))
6366 (defun gnus-button-handle-ctan (url)
6367 "Call `browse-url' when pushing a CTAN URL button."
6369 gnus-button-ctan-handler
6372 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6374 (defcustom gnus-button-tex-level 5
6375 "*Integer that says how many TeX-related buttons Gnus will show.
6376 The higher the number, the more buttons will appear and the more false
6377 positives are possible. Note that you can set this variable local to
6378 specific groups. Setting it higher in TeX groups is probably a good idea.
6379 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6380 how to set variables in specific groups."
6382 :group 'gnus-article-buttons
6383 :link '(custom-manual "(gnus)Group Parameters")
6386 (defcustom gnus-button-man-level 5
6387 "*Integer that says how many man-related buttons Gnus will show.
6388 The higher the number, the more buttons will appear and the more false
6389 positives are possible. Note that you can set this variable local to
6390 specific groups. Setting it higher in Unix groups is probably a good idea.
6391 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6392 how to set variables in specific groups."
6394 :group 'gnus-article-buttons
6395 :link '(custom-manual "(gnus)Group Parameters")
6398 (defcustom gnus-button-emacs-level 5
6399 "*Integer that says how many emacs-related buttons Gnus will show.
6400 The higher the number, the more buttons will appear and the more false
6401 positives are possible. Note that you can set this variable local to
6402 specific groups. Setting it higher in Emacs or Gnus related groups is
6403 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6404 `gnus-parameters' on how to set variables in specific groups."
6406 :group 'gnus-article-buttons
6407 :link '(custom-manual "(gnus)Group Parameters")
6410 (defcustom gnus-button-message-level 5
6411 "*Integer that says how many buttons for news or mail messages will appear.
6412 The higher the number, the more buttons will appear and the more false
6413 positives are possible."
6414 ;; mail addresses, MIDs, URLs for news, ...
6416 :group 'gnus-article-buttons
6419 (defcustom gnus-button-browse-level 5
6420 "*Integer that says how many buttons for browsing will appear.
6421 The higher the number, the more buttons will appear and the more false
6422 positives are possible."
6423 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6425 :group 'gnus-article-buttons
6428 (defcustom gnus-button-alist
6429 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6430 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6431 ((concat "\\b\\(nntp\\|news\\):\\("
6432 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6433 0 t gnus-button-handle-news 2)
6434 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6435 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6436 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6437 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6438 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6439 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6440 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6441 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6442 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6443 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6444 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6445 ;; RFC 2368 (The mailto URL scheme)
6446 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6447 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6448 ("\\bmailto:\\([^ \n\t]+\\)"
6449 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6451 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6452 gnus-button-ctan-directory-regexp
6453 "[^][>)!;:,'\n\t ]+\\)")
6454 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6455 ((concat "\\btex-archive/\\("
6456 gnus-button-ctan-directory-regexp
6457 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6458 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6461 gnus-button-ctan-directory-regexp
6462 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6463 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6464 ;; This is info (home-grown style) <info://foo/bar+baz>
6465 ("\\binfo://\\([^'\">\n\t ]+\\)"
6466 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6467 ;; Info GNOME style <info:foo#bar_baz>
6468 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6469 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6470 ;; Info KDE style <info:(foo)bar baz>
6471 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6472 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6473 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6474 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6475 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6476 ;; Info links like `C-h i d m CC Mode RET'
6477 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6479 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6480 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6481 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6482 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6483 ;; Emacs help commands
6484 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6485 ;; regexp doesn't match arguments containing ` '.
6486 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6487 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6488 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6489 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6490 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6491 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6492 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6493 ;; The following entries may lead to many false positives so don't enable
6494 ;; them by default (use a high button level).
6495 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6496 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6497 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6498 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6499 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6500 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6501 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6502 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6503 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6504 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6505 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6506 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6507 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6508 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6509 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6510 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6511 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6512 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6513 ;; Unlike the other regexps we really have to require quoting
6514 ;; here to determine where it ends.
6515 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6516 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6517 ("<URL: *\\([^<>]*\\)>"
6518 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6519 ;; RFC 2396 (2.4.3., delims) ...
6520 ("\"URL: *\\([^\"]*\\)\""
6521 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6522 ;; RFC 2396 (2.4.3., delims) ...
6523 ("\"URL: *\\([^\"]*\\)\""
6524 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6526 (gnus-button-url-regexp
6527 0 (>= gnus-button-browse-level 0) browse-url 0)
6529 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6530 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6531 gnus-button-handle-man 1)
6532 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6533 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6534 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6535 gnus-button-handle-man 1)
6536 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6537 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6538 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6539 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6540 ;; MID or mail: To avoid too many false positives we don't try to catch
6541 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6542 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6543 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6544 ;; so that non-ambiguous entries (see above) match first.
6545 (gnus-button-mid-or-mail-regexp
6546 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6547 "*Alist of regexps matching buttons in article bodies.
6549 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6550 REGEXP: is the string (case insensitive) matching text around the button (can
6551 also be Lisp expression evaluating to a string),
6552 BUTTON: is the number of the regexp grouping actually matching the button,
6553 FORM: is a Lisp expression which must eval to true for the button to
6555 CALLBACK: is the function to call when the user push this button, and each
6556 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6558 CALLBACK can also be a variable, in that case the value of that
6559 variable it the real callback function."
6560 :group 'gnus-article-buttons
6561 :type '(repeat (list (choice regexp variable sexp)
6562 (integer :tag "Button")
6564 (function :tag "Callback")
6567 (integer :tag "Regexp group")))))
6569 (defcustom gnus-header-button-alist
6570 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6571 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6572 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6573 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6574 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6575 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
6576 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6577 0 (>= gnus-button-browse-level 0) browse-url 0)
6578 ("^Subject:" gnus-button-url-regexp
6579 0 (>= gnus-button-browse-level 0) browse-url 0)
6580 ("^[^:]+:" gnus-button-url-regexp
6581 0 (>= gnus-button-browse-level 0) browse-url 0)
6582 ("^OpenPGP:.*url=" gnus-button-url-regexp
6583 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
6584 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6585 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6586 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6587 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6588 "*Alist of headers and regexps to match buttons in article heads.
6590 This alist is very similar to `gnus-button-alist', except that each
6591 alist has an additional HEADER element first in each entry:
6593 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6595 HEADER is a regexp to match a header. For a fuller explanation, see
6596 `gnus-button-alist'."
6597 :group 'gnus-article-buttons
6598 :group 'gnus-article-headers
6599 :type '(repeat (list (regexp :tag "Header")
6600 (choice regexp variable)
6601 (integer :tag "Button")
6603 (function :tag "Callback")
6606 (integer :tag "Regexp group")))))
6610 (defun gnus-article-push-button (event)
6611 "Check text under the mouse pointer for a callback function.
6612 If the text under the mouse pointer has a `gnus-callback' property,
6613 call it with the value of the `gnus-data' text property."
6615 (set-buffer (window-buffer (posn-window (event-start event))))
6616 (let* ((pos (posn-point (event-start event)))
6617 (data (get-text-property pos 'gnus-data))
6618 (fun (get-text-property pos 'gnus-callback)))
6621 (funcall fun data))))
6623 (defun gnus-article-press-button ()
6624 "Check text at point for a callback function.
6625 If the text at point has a `gnus-callback' property,
6626 call it with the value of the `gnus-data' text property."
6628 (let ((data (get-text-property (point) 'gnus-data))
6629 (fun (get-text-property (point) 'gnus-callback)))
6631 (funcall fun data))))
6633 (defun gnus-article-highlight (&optional force)
6634 "Highlight current article.
6635 This function calls `gnus-article-highlight-headers',
6636 `gnus-article-highlight-citation',
6637 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6638 do the highlighting. See the documentation for those functions."
6639 (interactive (list 'force))
6640 (gnus-article-highlight-headers)
6641 (gnus-article-highlight-citation force)
6642 (gnus-article-highlight-signature)
6643 (gnus-article-add-buttons force)
6644 (gnus-article-add-buttons-to-head))
6646 (defun gnus-article-highlight-some (&optional force)
6647 "Highlight current article.
6648 This function calls `gnus-article-highlight-headers',
6649 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6650 do the highlighting. See the documentation for those functions."
6651 (interactive (list 'force))
6652 (gnus-article-highlight-headers)
6653 (gnus-article-highlight-signature)
6654 (gnus-article-add-buttons))
6656 (defun gnus-article-highlight-headers ()
6657 "Highlight article headers as specified by `gnus-header-face-alist'."
6659 (gnus-with-article-headers
6660 (let (regexp header-face field-face from hpoints fpoints)
6661 (dolist (entry gnus-header-face-alist)
6662 (goto-char (point-min))
6663 (setq regexp (concat "^\\("
6664 (if (string-equal "" (nth 0 entry))
6668 header-face (nth 1 entry)
6669 field-face (nth 2 entry))
6670 (while (and (re-search-forward regexp nil t)
6674 (unless (search-forward ":" nil t)
6676 (when (and header-face
6677 (not (memq (point) hpoints)))
6678 (push (point) hpoints)
6679 (gnus-put-text-property from (point) 'face header-face))
6680 (when (and field-face
6681 (not (memq (setq from (point)) fpoints)))
6683 (if (re-search-forward "^[^ \t]" nil t)
6685 (goto-char (point-max)))
6686 (gnus-put-text-property from (point) 'face field-face)))))))
6688 (defun gnus-article-highlight-signature ()
6689 "Highlight the signature in an article.
6690 It does this by highlighting everything after
6691 `gnus-signature-separator' using the face `gnus-signature'."
6693 (gnus-with-article-buffer
6694 (let ((inhibit-point-motion-hooks t))
6696 (when (and gnus-signature-face
6697 (gnus-article-narrow-to-signature))
6698 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6699 'face gnus-signature-face)
6701 (gnus-article-search-signature)
6702 (let ((start (match-beginning 0))
6703 (end (set-marker (make-marker) (1+ (match-end 0)))))
6704 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6707 (defun gnus-button-in-region-p (b e prop)
6708 "Say whether PROP exists in the region."
6709 (text-property-not-all b e prop nil))
6711 (defun gnus-article-add-buttons (&optional force)
6712 "Find external references in the article and make buttons of them.
6713 \"External references\" are things like Message-IDs and URLs, as
6714 specified by `gnus-button-alist'."
6715 (interactive (list 'force))
6716 (gnus-with-article-buffer
6717 (let ((inhibit-point-motion-hooks t)
6718 (case-fold-search t)
6719 (alist gnus-button-alist)
6721 ;; Remove all old markers.
6722 (let (marker entry new-list)
6723 (while (setq marker (pop gnus-button-marker-list))
6724 (if (or (< marker (point-min)) (>= marker (point-max)))
6725 (push marker new-list)
6727 (when (setq entry (gnus-button-entry))
6728 (put-text-property (match-beginning (nth 1 entry))
6729 (match-end (nth 1 entry))
6730 'gnus-callback nil))
6731 (set-marker marker nil)))
6732 (setq gnus-button-marker-list new-list))
6733 ;; We skip the headers.
6736 (while (setq entry (pop alist))
6737 (setq regexp (eval (car entry)))
6739 (while (re-search-forward regexp nil t)
6740 (let* ((start (and entry (match-beginning (nth 1 entry))))
6741 (end (and entry (match-end (nth 1 entry))))
6742 (from (match-beginning 0)))
6743 (when (and (or (eq t (nth 2 entry))
6744 (eval (nth 2 entry)))
6745 (not (gnus-button-in-region-p
6746 start end 'gnus-callback)))
6747 ;; That optional form returned non-nil, so we add the
6749 (gnus-article-add-button
6750 start end 'gnus-button-push
6751 (car (push (set-marker (make-marker) from)
6752 gnus-button-marker-list))))))))))
6754 ;; Add buttons to the head of an article.
6755 (defun gnus-article-add-buttons-to-head ()
6756 "Add buttons to the head of the article."
6758 (gnus-with-article-headers
6760 (dolist (entry gnus-header-button-alist)
6761 ;; Each alist entry.
6762 (goto-char (point-min))
6763 (while (re-search-forward (car entry) nil t)
6764 ;; Each header matching the entry.
6765 (setq beg (match-beginning 0))
6766 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6767 (match-beginning 0))
6770 (while (re-search-forward (eval (nth 1 entry)) end t)
6771 ;; Each match within a header.
6772 (let* ((entry (cdr entry))
6773 (start (match-beginning (nth 1 entry)))
6774 (end (match-end (nth 1 entry)))
6775 (form (nth 2 entry)))
6776 (goto-char (match-end 0))
6778 (gnus-article-add-button
6779 start end (nth 3 entry)
6780 (buffer-substring (match-beginning (nth 4 entry))
6781 (match-end (nth 4 entry)))))))
6782 (goto-char end))))))
6784 ;;; External functions:
6786 (defun gnus-article-add-button (from to fun &optional data)
6787 "Create a button between FROM and TO with callback FUN and data DATA."
6788 (when gnus-article-button-face
6789 (gnus-overlay-put (gnus-make-overlay from to)
6790 'face gnus-article-button-face))
6791 (gnus-add-text-properties
6793 (nconc (and gnus-article-mouse-face
6794 (list gnus-mouse-face-prop gnus-article-mouse-face))
6795 (list 'gnus-callback fun)
6796 (and data (list 'gnus-data data))))
6797 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6798 :button-keymap gnus-widget-button-keymap))
6800 ;;; Internal functions:
6802 (defun gnus-article-set-globals ()
6803 (with-current-buffer gnus-summary-buffer
6804 (gnus-set-global-variables)))
6806 (defun gnus-signature-toggle (end)
6807 (gnus-with-article-buffer
6808 (let ((inhibit-point-motion-hooks t))
6809 (if (text-property-any end (point-max) 'article-type 'signature)
6811 (gnus-delete-wash-type 'signature)
6812 (gnus-remove-text-properties-when
6813 'article-type 'signature end (point-max)
6814 (cons 'article-type (cons 'signature
6815 gnus-hidden-properties))))
6816 (gnus-add-wash-type 'signature)
6817 (gnus-add-text-properties-when
6818 'article-type nil end (point-max)
6819 (cons 'article-type (cons 'signature
6820 gnus-hidden-properties)))))
6821 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6822 (gnus-set-mode-line 'article))))
6824 (defun gnus-button-entry ()
6825 ;; Return the first entry in `gnus-button-alist' matching this place.
6826 (let ((alist gnus-button-alist)
6829 (setq entry (pop alist))
6830 (if (looking-at (eval (car entry)))
6835 (defun gnus-button-push (marker)
6836 ;; Push button starting at MARKER.
6839 (let* ((entry (gnus-button-entry))
6840 (inhibit-point-motion-hooks t)
6842 (args (mapcar (lambda (group)
6843 (let ((string (match-string group)))
6844 (set-text-properties
6845 0 (length string) nil string)
6852 (fboundp (symbol-value fun)))
6853 (apply (symbol-value fun) args))
6855 (gnus-message 1 "You must define `%S' to use this button"
6856 (cons fun args)))))))
6858 (defun gnus-parse-news-url (url)
6859 (let (scheme server port group message-id articles)
6862 (goto-char (point-min))
6863 (when (looking-at "\\([A-Za-z]+\\):")
6864 (setq scheme (match-string 1))
6865 (goto-char (match-end 0)))
6866 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
6867 (setq server (match-string 1))
6868 (setq port (if (stringp (match-string 3))
6869 (string-to-number (match-string 3))
6871 (goto-char (match-end 0)))
6874 ((looking-at "\\(.*@.*\\)")
6875 (setq message-id (match-string 1)))
6876 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6877 (setq group (match-string 1)
6878 articles (split-string (match-string 2) "-")))
6879 ((looking-at "\\([^/]+\\)/?")
6880 (setq group (match-string 1)))
6882 (error "Unknown news URL syntax"))))
6883 (list scheme server port group message-id articles)))
6885 (defun gnus-button-handle-news (url)
6887 (destructuring-bind (scheme server port group message-id articles)
6888 (gnus-parse-news-url url)
6892 (set-buffer gnus-summary-buffer)
6894 (let ((gnus-refer-article-method
6895 (nconc (list (list 'nntp server))
6896 gnus-refer-article-method))
6897 (nntp-port-number (or port "nntp")))
6898 (gnus-message 7 "Fetching %s with %s"
6899 message-id gnus-refer-article-method)
6900 (gnus-summary-refer-article message-id))
6901 (gnus-summary-refer-article message-id))))
6903 (gnus-button-fetch-group url)))))
6905 (defun gnus-button-handle-man (url)
6907 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6908 (when (eq gnus-button-man-handler 'woman)
6909 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
6910 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6911 (funcall gnus-button-man-handler url))
6913 (defun gnus-button-handle-info-url (url)
6914 "Fetch an info URL."
6915 (setq url (mm-subst-char-in-string ?+ ?\ url))
6917 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6918 (gnus-info-find-node
6919 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6921 ")" (gnus-url-unhex-string (match-string 2 url)))))
6922 ((string-match "([^)\"]+)[^\"]+" url)
6924 (gnus-replace-in-string
6925 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
6926 (gnus-info-find-node url))
6927 (t (error "Can't parse %s" url))))
6929 (defun gnus-button-handle-info-url-gnome (url)
6930 "Fetch GNOME style info URL."
6931 (setq url (mm-subst-char-in-string ?_ ?\ url))
6932 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
6933 (gnus-info-find-node
6935 (gnus-url-unhex-string
6936 (match-string 1 url))
6938 (or (gnus-url-unhex-string
6939 (match-string 2 url))
6941 (error "Can't parse %s" url)))
6943 (defun gnus-button-handle-info-url-kde (url)
6944 "Fetch KDE style info URL."
6945 (gnus-info-find-node (gnus-url-unhex-string url)))
6947 (defun gnus-button-handle-info-keystrokes (url)
6948 "Call `info' when pushing the corresponding URL button."
6949 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
6954 (defun gnus-button-openpgp (url)
6955 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
6957 (mm-url-insert-file-contents-external url)
6958 (pgg-snarf-keys-region (point-min) (point-max))
6959 (pgg-display-output-buffer nil nil nil)))
6961 (defun gnus-button-message-id (message-id)
6963 (with-current-buffer gnus-summary-buffer
6964 (gnus-summary-refer-article message-id)))
6966 (defun gnus-button-fetch-group (address)
6967 "Fetch GROUP specified by ADDRESS."
6968 (if (not (string-match "[:/]" address))
6969 ;; This is just a simple group url.
6970 (gnus-group-read-ephemeral-group address gnus-select-method)
6973 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6975 (error "Can't parse %s" address)
6976 (gnus-group-read-ephemeral-group
6977 (match-string 4 address)
6978 `(nntp ,(match-string 1 address)
6979 (nntp-address ,(match-string 1 address))
6980 (nntp-port-number ,(if (match-end 3)
6981 (match-string 3 address)
6984 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
6986 (defun gnus-url-parse-query-string (query &optional downcase)
6987 (let (retval pairs cur key val)
6988 (setq pairs (split-string query "&"))
6990 (setq cur (car pairs)
6992 (if (not (string-match "=" cur))
6994 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6995 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6997 (setq key (downcase key)))
6998 (setq cur (assoc key retval))
7000 (setcdr cur (cons val (cdr cur)))
7001 (setq retval (cons (list key val) retval)))))
7004 (defun gnus-url-mailto (url)
7005 ;; Send mail to someone
7006 (when (string-match "mailto:/*\\(.*\\)" url)
7007 (setq url (substring url (match-beginning 1) nil)))
7008 (let (to args subject func)
7009 (setq args (gnus-url-parse-query-string
7010 (if (string-match "^\\?" url)
7012 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7013 (concat "to=" (match-string 1 url) "&"
7014 (match-string 2 url))
7015 (concat "to=" url)))
7017 subject (cdr-safe (assoc "subject" args)))
7020 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7023 (message-position-on-field (caar args)))
7024 (insert (gnus-replace-in-string
7025 (mapconcat 'identity (reverse (cdar args)) ", ")
7027 (setq args (cdr args)))
7030 (message-goto-subject))))
7032 (defun gnus-button-embedded-url (address)
7033 "Activate ADDRESS with `browse-url'."
7034 (browse-url (gnus-strip-whitespace address)))
7036 ;;; Next/prev buttons in the article buffer.
7038 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7039 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7041 (defvar gnus-prev-page-map
7042 (let ((map (make-sparse-keymap)))
7043 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7044 (define-key map "\r" 'gnus-button-prev-page)
7047 (defvar gnus-next-page-map
7048 (let ((map (make-sparse-keymap)))
7049 (unless (>= emacs-major-version 21)
7050 ;; XEmacs doesn't care.
7051 (set-keymap-parent map gnus-article-mode-map))
7052 (define-key map gnus-mouse-2 'gnus-button-next-page)
7053 (define-key map "\r" 'gnus-button-next-page)
7056 (defun gnus-insert-prev-page-button ()
7058 (inhibit-read-only t))
7060 gnus-prev-page-line-format nil
7061 `(keymap ,gnus-prev-page-map
7063 gnus-callback gnus-article-button-prev-page
7064 article-type annotation))
7065 (widget-convert-button
7067 ;; Exclude a newline.
7070 :action 'gnus-button-prev-page
7071 :button-keymap gnus-prev-page-map)))
7073 (defun gnus-button-next-page (&optional args more-args)
7074 "Go to the next page."
7076 (let ((win (selected-window)))
7077 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7078 (gnus-article-next-page)
7079 (select-window win)))
7081 (defun gnus-button-prev-page (&optional args more-args)
7082 "Go to the prev page."
7084 (let ((win (selected-window)))
7085 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7086 (gnus-article-prev-page)
7087 (select-window win)))
7089 (defun gnus-insert-next-page-button ()
7091 (inhibit-read-only t))
7092 (gnus-eval-format gnus-next-page-line-format nil
7093 `(keymap ,gnus-next-page-map
7095 gnus-callback gnus-article-button-next-page
7096 article-type annotation))
7097 (widget-convert-button
7099 ;; Exclude a newline.
7102 :action 'gnus-button-next-page
7103 :button-keymap gnus-next-page-map)))
7105 (defun gnus-article-button-next-page (arg)
7106 "Go to the next page."
7108 (let ((win (selected-window)))
7109 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7110 (gnus-article-next-page)
7111 (select-window win)))
7113 (defun gnus-article-button-prev-page (arg)
7114 "Go to the prev page."
7116 (let ((win (selected-window)))
7117 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7118 (gnus-article-prev-page)
7119 (select-window win)))
7121 (defvar gnus-decode-header-methods
7122 '(mail-decode-encoded-word-region)
7123 "List of methods used to decode headers.
7125 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7126 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7127 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7128 whose names match REGEXP.
7131 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7132 mail-decode-encoded-word-region
7133 (\"chinese\" . rfc1843-decode-region))
7136 (defvar gnus-decode-header-methods-cache nil)
7138 (defun gnus-multi-decode-header (start end)
7139 "Apply the functions from `gnus-encoded-word-methods' that match."
7140 (unless (and gnus-decode-header-methods-cache
7141 (eq gnus-newsgroup-name
7142 (car gnus-decode-header-methods-cache)))
7143 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7146 (nconc gnus-decode-header-methods-cache (list x))
7147 (if (and gnus-newsgroup-name
7148 (string-match (car x) gnus-newsgroup-name))
7149 (nconc gnus-decode-header-methods-cache
7151 gnus-decode-header-methods))
7152 (let ((xlist gnus-decode-header-methods-cache))
7155 (narrow-to-region start end)
7157 (funcall (pop xlist) (point-min) (point-max))))))
7160 ;;; Treatment top-level handling.
7163 (defun gnus-treat-article (condition &optional part-number total-parts type)
7164 (let ((length (- (point-max) (point-min)))
7165 (alist gnus-treatment-function-alist)
7166 (article-goto-body-goes-to-point-min-p t)
7170 (let ((list gnus-article-treat-types))
7172 (when (string-match (pop list) type)
7173 (throw 'found t)))))))
7174 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7176 (gnus-run-hooks 'gnus-part-display-hook)
7177 (dolist (elem alist)
7180 (when (gnus-buffer-live-p gnus-summary-buffer)
7181 (set-buffer gnus-summary-buffer))
7182 (symbol-value (car elem))))
7183 (when (and (or (consp val)
7185 (gnus-treat-predicate val)
7186 (or (not (get (car elem) 'highlight))
7189 (funcall (cadr elem)))))))
7191 ;; Dynamic variables.
7193 (defvar part-number)
7194 (defvar total-parts)
7199 (defun gnus-treat-predicate (val)
7206 (stringp (car val)))
7207 (apply 'gnus-or (mapcar `(lambda (s)
7208 (string-match s ,(or gnus-newsgroup-name "")))
7211 (let ((pred (pop val)))
7214 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7216 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7218 (not (gnus-treat-predicate (car val))))
7220 (equal (car val) type))
7222 (error "%S is not a valid predicate" pred)))))
7230 (eq part-number total-parts))
7234 (error "%S is not a valid value" val))))
7236 (defun gnus-article-encrypt-body (protocol &optional n)
7237 "Encrypt the article body."
7240 (or gnus-article-encrypt-protocol
7241 (completing-read "Encrypt protocol: "
7242 gnus-article-encrypt-protocol-alist
7244 current-prefix-arg))
7245 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7247 (error "Can't find the encrypt protocol %s" protocol))
7248 (if (member gnus-newsgroup-name '("nndraft:delayed"
7251 (error "Can't encrypt the article in group %s"
7252 gnus-newsgroup-name))
7253 (gnus-summary-iterate n
7255 (set-buffer gnus-summary-buffer)
7256 (let ((mail-parse-charset gnus-newsgroup-charset)
7257 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7258 (summary-buffer gnus-summary-buffer)
7260 (gnus-set-global-variables)
7261 (when (gnus-group-read-only-p)
7262 (error "The current newsgroup does not support article encrypt"))
7263 (gnus-summary-show-article t)
7265 (or (mail-header-references gnus-current-headers) ""))
7266 (set-buffer gnus-article-buffer)
7267 (let* ((inhibit-read-only t)
7269 (mapcar (lambda (field)
7270 (and (save-restriction
7271 (message-narrow-to-head)
7272 (goto-char (point-min))
7273 (search-forward field nil t))
7275 (message-narrow-to-field)
7277 (delete-region (point-min) (point-max))
7279 '("Content-Type:" "Content-Transfer-Encoding:"
7280 "Content-Disposition:"))))
7281 (message-narrow-to-head)
7282 (message-remove-header "MIME-Version")
7283 (goto-char (point-max))
7284 (setq point (point))
7285 (insert (apply 'concat headers))
7287 (narrow-to-region point (point-max))
7288 (let ((message-options message-options))
7289 (message-options-set 'message-sender user-mail-address)
7290 (message-options-set 'message-recipients user-mail-address)
7291 (message-options-set 'message-sign-encrypt 'not)
7293 (goto-char (point-min))
7294 (insert "MIME-Version: 1.0\n")
7296 (gnus-summary-edit-article-done
7297 references nil summary-buffer t))
7298 (when gnus-keep-backlog
7299 (gnus-backlog-remove-article
7300 (car gnus-article-current) (cdr gnus-article-current)))
7302 (when (get-buffer gnus-original-article-buffer)
7303 (set-buffer gnus-original-article-buffer)
7304 (setq gnus-original-article nil)))
7305 (when gnus-use-cache
7306 (gnus-cache-update-article
7307 (car gnus-article-current) (cdr gnus-article-current))))))))
7309 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7310 "The following specs can be used:
7311 %t The security MIME type
7314 %D Details if button is pressed")
7316 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7317 "The following specs can be used:
7318 %t The security MIME type
7321 %D Details if button is pressed")
7323 (defvar gnus-mime-security-button-line-format-alist
7324 '((?t gnus-tmp-type ?s)
7325 (?i gnus-tmp-info ?s)
7326 (?d gnus-tmp-details ?s)
7327 (?D gnus-tmp-pressed-details ?s)))
7329 (defvar gnus-mime-security-button-map
7330 (let ((map (make-sparse-keymap)))
7331 (define-key map gnus-mouse-2 'gnus-article-push-button)
7332 (define-key map "\r" 'gnus-article-press-button)
7335 (defvar gnus-mime-security-details-buffer nil)
7337 (defvar gnus-mime-security-button-pressed nil)
7339 (defvar gnus-mime-security-show-details-inline t
7340 "If non-nil, show details in the article buffer.")
7342 (defun gnus-mime-security-verify-or-decrypt (handle)
7343 (mm-remove-parts (cdr handle))
7344 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7345 point (inhibit-read-only t))
7347 (goto-char (car region)))
7349 (narrow-to-region (point) (point))
7350 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7351 (let* ((mm-verify-option 'known)
7352 (mm-decrypt-option 'known)
7353 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7354 (unless (eq nparts (cdr handle))
7355 (mm-destroy-parts (cdr handle))
7356 (setcdr handle nparts))))
7357 (setq point (point))
7358 (gnus-mime-display-security handle)
7359 (goto-char (point-max)))
7361 (delete-region (point) (cdr region))
7362 (set-marker (car region) nil)
7363 (set-marker (cdr region) nil))
7366 (defun gnus-mime-security-show-details (handle)
7367 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7369 (gnus-message 5 "No details.")
7370 (if gnus-mime-security-show-details-inline
7371 (let ((gnus-mime-security-button-pressed
7372 (not (get-text-property (point) 'gnus-mime-details)))
7373 (gnus-mime-security-button-line-format
7374 (get-text-property (point) 'gnus-line-format))
7375 (inhibit-read-only t))
7377 (while (eq (get-text-property (point) 'gnus-line-format)
7378 gnus-mime-security-button-line-format)
7382 (narrow-to-region (point) (point))
7383 (gnus-insert-mime-security-button handle))
7384 (delete-region (point)
7385 (or (text-property-not-all
7388 gnus-mime-security-button-line-format)
7391 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7392 (with-current-buffer gnus-mime-security-details-buffer
7395 (setq gnus-mime-security-details-buffer
7396 (gnus-get-buffer-create "*MIME Security Details*")))
7397 (with-current-buffer gnus-mime-security-details-buffer
7399 (goto-char (point-min)))
7400 (pop-to-buffer gnus-mime-security-details-buffer)))))
7402 (defun gnus-mime-security-press-button (handle)
7404 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7405 (gnus-mime-security-show-details handle)
7406 (gnus-mime-security-verify-or-decrypt handle))))
7408 (defun gnus-insert-mime-security-button (handle &optional displayed)
7409 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7412 (or (nth 2 (assoc protocol mm-verify-function-alist))
7413 (nth 2 (assoc protocol mm-decrypt-function-alist))
7415 (if (equal (car handle) "multipart/signed")
7416 " Signed" " Encrypted")
7419 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7422 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7423 gnus-tmp-pressed-details
7425 (setq gnus-tmp-details
7426 (if gnus-tmp-details
7427 (concat "\n" gnus-tmp-details)
7429 (setq gnus-tmp-pressed-details
7430 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7435 gnus-mime-security-button-line-format
7436 gnus-mime-security-button-line-format-alist
7437 `(keymap ,gnus-mime-security-button-map
7438 gnus-callback gnus-mime-security-press-button
7439 gnus-line-format ,gnus-mime-security-button-line-format
7440 gnus-mime-details ,gnus-mime-security-button-pressed
7441 article-type annotation
7444 ;; Exclude a newline.
7447 (widget-convert-button
7450 :action 'gnus-widget-press-button
7451 :button-keymap gnus-mime-security-button-map
7453 (lambda (widget/window &optional overlay pos)
7454 ;; Needed to properly clear the message due to a bug in
7455 ;; wid-edit (XEmacs only).
7456 (when (boundp 'help-echo-owns-message)
7457 (setq help-echo-owns-message t))
7460 (aref gnus-mouse-2 0))))))
7462 (defun gnus-mime-display-security (handle)
7464 (narrow-to-region (point) (point))
7465 (unless (gnus-unbuttonized-mime-type-p (car handle))
7466 (gnus-insert-mime-security-button handle))
7467 (gnus-mime-display-part (cadr handle))
7470 (unless (gnus-unbuttonized-mime-type-p (car handle))
7471 (let ((gnus-mime-security-button-line-format
7472 gnus-mime-security-button-end-line-format))
7473 (gnus-insert-mime-security-button handle)))
7474 (mm-set-handle-multipart-parameter
7476 (cons (set-marker (make-marker) (point-min))
7477 (set-marker (make-marker) (point-max))))))
7483 (run-hooks 'gnus-art-load-hook)
7485 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7486 ;;; gnus-art.el ends here