1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 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 3, 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.
32 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
36 (defvar w3m-minor-mode-map)
39 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
41 (let ((recursive-load-depth-limit 100))
54 (autoload 'gnus-msg-mail "gnus-msg" nil t)
55 (autoload 'gnus-button-mailto "gnus-msg")
56 (autoload 'gnus-button-reply "gnus-msg" nil t)
57 (autoload 'parse-time-string "parse-time" nil nil)
58 (autoload 'ansi-color-apply-on-region "ansi-color")
59 (autoload 'mm-url-insert-file-contents-external "mm-url")
60 (autoload 'mm-extern-cache-contents "mm-extern")
62 (defgroup gnus-article nil
64 :link '(custom-manual "(gnus)Article Buffer")
67 (defgroup gnus-article-treat nil
68 "Treating article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
72 (defgroup gnus-article-hiding nil
73 "Hiding article parts."
74 :link '(custom-manual "(gnus)Article Hiding")
77 (defgroup gnus-article-highlight nil
78 "Article highlighting."
79 :link '(custom-manual "(gnus)Article Highlighting")
83 (defgroup gnus-article-signature nil
85 :link '(custom-manual "(gnus)Article Signature")
88 (defgroup gnus-article-headers nil
90 :link '(custom-manual "(gnus)Hiding Headers")
93 (defgroup gnus-article-washing nil
94 "Special commands on articles."
95 :link '(custom-manual "(gnus)Article Washing")
98 (defgroup gnus-article-emphasis nil
99 "Fontisizing articles."
100 :link '(custom-manual "(gnus)Article Fontisizing")
101 :group 'gnus-article)
103 (defgroup gnus-article-saving nil
105 :link '(custom-manual "(gnus)Saving Articles")
106 :group 'gnus-article)
108 (defgroup gnus-article-mime nil
109 "Worshiping the MIME wonder."
110 :link '(custom-manual "(gnus)Using MIME")
111 :group 'gnus-article)
113 (defgroup gnus-article-buttons nil
114 "Pushable buttons in the article buffer."
115 :link '(custom-manual "(gnus)Article Buttons")
116 :group 'gnus-article)
118 (defgroup gnus-article-various nil
119 "Other article options."
120 :link '(custom-manual "(gnus)Misc Article")
121 :group 'gnus-article)
123 (defcustom gnus-ignored-headers
126 (concat "^" header ":"))
127 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
128 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
129 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
130 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
131 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
132 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
133 "X-Attribution" "X-Originating-IP" "Delivered-To"
134 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
135 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
136 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
137 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
138 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
139 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
140 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
141 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
142 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
143 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
144 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
145 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
146 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
147 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
148 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
149 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
150 "List-[A-Za-z]+" "X-Listprocessor-Version"
151 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
152 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
153 "X-Received" "Content-length" "X-precedence"
154 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
155 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
156 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
157 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
158 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
159 "X-Content-length" "X-Posting-Agent" "Original-Received"
160 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
161 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
162 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
163 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
164 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
165 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
166 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
167 "Envelope-Sender" "Envelope-Recipients"))
168 "*All headers that start with this regexp will be hidden.
169 This variable can also be a list of regexps of headers to be ignored.
170 If `gnus-visible-headers' is non-nil, this variable will be ignored."
171 :type '(choice :custom-show nil
174 :group 'gnus-article-hiding)
176 (defcustom gnus-visible-headers
177 "^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:"
178 "*All headers that do not match this regexp will be hidden.
179 This variable can also be a list of regexp of headers to remain visible.
180 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
181 :type '(repeat :value-to-internal (lambda (widget value)
182 (custom-split-regexp-maybe value))
183 :match (lambda (widget value)
185 (widget-editable-list-match widget value)))
187 :group 'gnus-article-hiding)
189 (defcustom gnus-sorted-header-list
190 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
191 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
192 "*This variable is a list of regular expressions.
193 If it is non-nil, headers that match the regular expressions will
194 be placed first in the article buffer in the sequence specified by
196 :type '(repeat regexp)
197 :group 'gnus-article-hiding)
199 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
200 "Headers that are only to be displayed if they have interesting data.
201 Possible values in this list are:
203 'empty Headers with no content.
204 'newsgroups Newsgroup identical to Gnus group.
205 'to-address To identical to To-address.
206 'to-list To identical to To-list.
207 'cc-list CC identical to To-list.
208 'followup-to Followup-to identical to Newsgroups.
209 'reply-to Reply-to identical to From.
210 'date Date less than four days old.
211 'long-to To and/or Cc longer than 1024 characters.
212 'many-to Multiple To and/or Cc."
213 :type '(set (const :tag "Headers with no content." empty)
214 (const :tag "Newsgroups identical to Gnus group." newsgroups)
215 (const :tag "To identical to To-address." to-address)
216 (const :tag "To identical to To-list." to-list)
217 (const :tag "CC identical to To-list." cc-list)
218 (const :tag "Followup-to identical to Newsgroups." followup-to)
219 (const :tag "Reply-to identical to From." reply-to)
220 (const :tag "Date less than four days old." date)
221 (const :tag "To and/or Cc longer than 1024 characters." long-to)
222 (const :tag "Multiple To and/or Cc headers." many-to))
223 :group 'gnus-article-hiding)
225 (defcustom gnus-article-skip-boring nil
226 "Skip over text that is not worth reading.
227 By default, if you set this t, then Gnus will display citations and
228 signatures, but will never scroll down to show you a page consisting
229 only of boring text. Boring text is controlled by
230 `gnus-article-boring-faces'."
233 :group 'gnus-article-hiding)
235 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
236 "Regexp matching signature separator.
237 This can also be a list of regexps. In that case, it will be checked
238 from head to tail looking for a separator. Searches will be done from
239 the end of the buffer."
240 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
242 (repeat :tag "List of regexp" regexp))
243 :group 'gnus-article-signature)
245 (defcustom gnus-signature-limit nil
246 "Provide a limit to what is considered a signature.
247 If it is a number, no signature may not be longer (in characters) than
248 that number. If it is a floating point number, no signature may be
249 longer (in lines) than that number. If it is a function, the function
250 will be called without any parameters, and if it returns nil, there is
251 no signature in the buffer. If it is a string, it will be used as a
252 regexp. If it matches, the text in question is not a signature.
254 This can also be a list of the above values."
255 :type '(choice (const nil)
259 (regexp :value ".*"))
260 :group 'gnus-article-signature)
262 (defcustom gnus-hidden-properties '(invisible t intangible t)
263 "Property list to use for hiding text."
265 :group 'gnus-article-hiding)
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270 (if (featurep 'xemacs)
271 (if (or (gnus-image-type-available-p 'xface)
272 (gnus-image-type-available-p 'pbm))
273 'gnus-display-x-face-in-from
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
275 (if (gnus-image-type-available-p 'pbm)
276 'gnus-display-x-face-in-from
277 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
279 "*String or function to be executed to display an X-Face header.
280 If it is a string, the command will be executed in a sub-shell
281 asynchronously. The compressed face will be piped to this command."
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
291 :type '(choice regexp (const nil))
292 :group 'gnus-article-washing)
294 (defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
302 (gnus-define-group-parameter
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
308 '(choice :tag "Banner"
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
313 (const :tag "None" nil))
315 "If non-nil, specify how to remove `banners' from articles.
317 Symbol `signature' means to remove signatures delimited by
318 `gnus-signature-separator'. Any other symbol is used to look up a
319 regular expression to match the banner in `gnus-article-banner-alist'.
320 A string is used as a regular expression to match the banner
323 (defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326 to match a mail address in the From: header, BANNER is one of a symbol
327 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
328 If ADDRESS matches author's mail address, it will remove things like
329 advertisements. For example:
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
340 (const :tag "None" nil))))
342 :group 'gnus-article-washing)
344 (defmacro gnus-emphasis-custom-with-format (&rest body)
346 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
350 (defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
355 (if (nth 1 value) 2 3)
359 (defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
372 (defcustom gnus-emphasis-alist
374 '(("\\*" "\\*" bold nil 2)
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
397 "*Alist that says how to fontify certain phrases.
398 Each item looks like this:
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
402 The first element is a regular expression to be matched. The second
403 is a number that says what regular expression grouping used to find
404 the entire emphasized word. The third is a number that says what
405 regexp grouping should be displayed and highlighted. The fourth
406 is the face used for highlighting."
410 :format "%[Customizing Style%]\n%v"
412 (group :tag "Default"
413 :value ("" 0 0 default)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
420 (if (not (eq (nth 2 value) 'default))
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
427 (integer :format "Match group: %v")
428 (integer :format "Emphasize group: %v")
431 :value (("_" . "_") nil default)
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
444 :group 'gnus-article-emphasis)
446 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449 The former avoids underlining of leading and trailing whitespace,
450 and the latter avoids underlining any whitespace at all."
452 :group 'gnus-article-emphasis
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
472 "Face used for displaying underlined italic emphasized text (_/word/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline-bold-italic
480 '((t (:bold t :italic t :underline t)))
481 "Face used for displaying underlined bold italic emphasized text.
482 Example: (_/*word*/_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
486 '((t (:strikethru t)))
487 '((t (:strike-through t))))
488 "Face used for displaying strike-through text (-word-)."
489 :group 'gnus-article-emphasis)
491 (defface gnus-emphasis-highlight-words
492 '((t (:background "black" :foreground "yellow")))
493 "Face used for displaying highlighted words."
494 :group 'gnus-article-emphasis)
496 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
497 "Format for display of Date headers in article bodies.
498 See `format-time-string' for the possible values.
500 The variable can also be function, which should return a complete Date
501 header. The function is called with one argument, the time, which can
502 be fed to `format-time-string'."
503 :type '(choice string function)
504 :link '(custom-manual "(gnus)Article Date")
505 :group 'gnus-article-washing)
507 (defcustom gnus-save-all-headers t
508 "*If non-nil, don't remove any headers before saving.
509 This will be overridden by the `:headers' property that the symbol of
510 the saver function, which is specified by `gnus-default-article-saver',
512 :group 'gnus-article-saving
515 (defcustom gnus-prompt-before-saving 'always
516 "*This variable says how much prompting is to be done when saving articles.
517 If it is nil, no prompting will be done, and the articles will be
518 saved to the default files. If this variable is `always', each and
519 every article that is saved will be preceded by a prompt, even when
520 saving large batches of articles. If this variable is neither nil not
521 `always', there the user will be prompted once for a file name for
522 each invocation of the saving commands."
523 :group 'gnus-article-saving
524 :type '(choice (item always)
525 (item :tag "never" nil)
526 (sexp :tag "once" :format "%t\n" :value t)))
528 (defcustom gnus-saved-headers gnus-visible-headers
529 "Headers to keep if `gnus-save-all-headers' is nil.
530 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
531 If that variable is nil, however, all headers that match this regexp
532 will be kept while the rest will be deleted before saving. This and
533 `gnus-save-all-headers' will be overridden by the `:headers' property
534 that the symbol of the saver function, which is specified by
535 `gnus-default-article-saver', might have."
536 :group 'gnus-article-saving
539 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
540 "A function to save articles in your favourite format.
541 The function will be called by way of the `gnus-summary-save-article'
542 command, and friends such as `gnus-summary-save-article-rmail'.
544 Gnus provides the following functions:
546 * gnus-summary-save-in-rmail (Rmail format)
547 * gnus-summary-save-in-mail (Unix mail format)
548 * gnus-summary-save-in-folder (MH folder)
549 * gnus-summary-save-in-file (article format)
550 * gnus-summary-save-body-in-file (article body)
551 * gnus-summary-save-in-vm (use VM's folder format)
552 * gnus-summary-write-to-file (article format -- overwrite)
553 * gnus-summary-write-body-to-file (article body -- overwrite)
555 The symbol of each function may have the following properties:
558 The value non-nil means save decoded articles. This is meaningful
559 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560 `gnus-summary-write-to-file', and `gnus-summary-write-body-to-file'.
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
585 (defcustom gnus-article-save-coding-system
586 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
587 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
588 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
589 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
590 "Coding system used to save decoded articles to a file.
592 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
593 which can safely encode any characters in text. This is used by the
596 * gnus-summary-save-article-file
597 * gnus-summary-save-article-body-file
598 * gnus-summary-write-article-file
599 * gnus-summary-write-article-body-file
601 and the functions to which you may set `gnus-default-article-saver':
603 * gnus-summary-save-in-file
604 * gnus-summary-save-body-in-file
605 * gnus-summary-write-to-file
606 * gnus-summary-write-body-to-file
608 Those commands and functions save just text displayed in the article
609 buffer to a file if the value of this variable is non-nil. Note that
610 buttonized MIME parts will be lost in a saved file in that case.
611 Otherwise, raw articles will be saved."
612 :group 'gnus-article-saving
614 :format "%{%t%}:\n %[Value Menu%] %v"
615 (const :tag "Save raw articles" nil)
618 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
619 '((const :tag "UTF-8" utf-8)
620 (const :tag "iso-2022-7bit" iso-2022-7bit)
621 (const :tag "Emacs internal" emacs-mule)
622 (const :tag "escape-quoted" escape-quoted))))
623 (symbol :tag "Coding system")))
625 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
626 "A function generating a file name to save articles in Rmail format.
627 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
628 :group 'gnus-article-saving
631 (defcustom gnus-mail-save-name 'gnus-plain-save-name
632 "A function generating a file name to save articles in Unix mail format.
633 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
634 :group 'gnus-article-saving
637 (defcustom gnus-folder-save-name 'gnus-folder-save-name
638 "A function generating a file name to save articles in MH folder.
639 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
640 :group 'gnus-article-saving
643 (defcustom gnus-file-save-name 'gnus-numeric-save-name
644 "A function generating a file name to save articles in article format.
645 The function is called with NEWSGROUP, HEADERS, and optional
647 :group 'gnus-article-saving
650 (defcustom gnus-split-methods
651 '((gnus-article-archive-name)
652 (gnus-article-nndoc-name))
653 "*Variable used to suggest where articles are to be saved.
654 For instance, if you would like to save articles related to Gnus in
655 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
656 you could set this variable to something like:
658 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
659 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
661 This variable is an alist where the key is the match and the
662 value is a list of possible files to save in if the match is
665 If the match is a string, it is used as a regexp match on the
666 article. If the match is a symbol, that symbol will be funcalled
667 from the buffer of the article to be saved with the newsgroup as the
668 parameter. If it is a list, it will be evaled in the same buffer.
670 If this form or function returns a string, this string will be used as a
671 possible file name; and if it returns a non-nil list, that list will be
672 used as possible file names."
673 :group 'gnus-article-saving
674 :type '(repeat (choice (list :value (fun) function)
675 (cons :value ("" "") regexp (repeat string))
678 (defcustom gnus-page-delimiter "^\^L"
679 "*Regexp describing what to use as article page delimiters.
680 The default value is \"^\^L\", which is a form linefeed at the
681 beginning of a line."
683 :group 'gnus-article-various)
685 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
686 "*The format specification for the article mode line.
687 See `gnus-summary-mode-line-format' for a closer description.
689 The following additional specs are available:
691 %w The article washing status.
692 %m The number of MIME parts in the article."
694 :group 'gnus-article-various)
696 (defcustom gnus-article-mode-hook nil
697 "*A hook for Gnus article mode."
699 :group 'gnus-article-various)
701 (when (featurep 'xemacs)
702 ;; Extracted from gnus-xmas-define in order to preserve user settings
703 (when (fboundp 'turn-off-scroll-in-place)
704 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
705 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
706 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
708 (defcustom gnus-article-menu-hook nil
709 "*Hook run after the creation of the article mode menu."
711 :group 'gnus-article-various)
713 (defcustom gnus-article-prepare-hook nil
714 "*A hook called after an article has been prepared in the article buffer."
716 :group 'gnus-article-various)
718 (defcustom gnus-copy-article-ignored-headers nil
719 "List of headers to be removed when copying an article.
720 Each element is a regular expression."
721 :version "23.0" ;; No Gnus
722 :type '(repeat regexp)
723 :group 'gnus-article-various)
725 (make-obsolete-variable 'gnus-article-hide-pgp-hook
726 "This variable is obsolete in Gnus 5.10.")
729 '((t (:weight bold)))
730 "Face used for highlighting a button in the article buffer."
731 :group 'gnus-article-buttons)
733 (defcustom gnus-article-button-face 'gnus-button
734 "Face used for highlighting buttons in the article buffer.
736 An article button is a piece of text that you can activate by pressing
737 `RET' or `mouse-2' above it."
739 :group 'gnus-article-buttons)
741 (defcustom gnus-article-mouse-face 'highlight
742 "Face used for mouse highlighting in the article buffer.
744 Article buttons will be displayed in this face when the cursor is
747 :group 'gnus-article-buttons)
749 (defcustom gnus-signature-face 'gnus-signature
750 "Face used for highlighting a signature in the article buffer.
751 Obsolete; use the face `gnus-signature' for customizations instead."
753 :group 'gnus-article-highlight
754 :group 'gnus-article-signature)
756 (defface gnus-signature
759 "Face used for highlighting a signature in the article buffer."
760 :group 'gnus-article-highlight
761 :group 'gnus-article-signature)
762 ;; backward-compatibility alias
763 (put 'gnus-signature-face 'face-alias 'gnus-signature)
765 (defface gnus-header-from
768 (:foreground "PaleGreen1"))
771 (:foreground "red3"))
774 "Face used for displaying from headers."
775 :group 'gnus-article-headers
776 :group 'gnus-article-highlight)
777 ;; backward-compatibility alias
778 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
780 (defface gnus-header-subject
783 (:foreground "SeaGreen1"))
786 (:foreground "red4"))
788 (:bold t :italic t)))
789 "Face used for displaying subject headers."
790 :group 'gnus-article-headers
791 :group 'gnus-article-highlight)
792 ;; backward-compatibility alias
793 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
795 (defface gnus-header-newsgroups
798 (:foreground "yellow" :italic t))
801 (:foreground "MidnightBlue" :italic t))
804 "Face used for displaying newsgroups headers.
805 In the default setup this face is only used for crossposted
807 :group 'gnus-article-headers
808 :group 'gnus-article-highlight)
809 ;; backward-compatibility alias
810 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
812 (defface gnus-header-name
815 (:foreground "SpringGreen2"))
818 (:foreground "maroon"))
821 "Face used for displaying header names."
822 :group 'gnus-article-headers
823 :group 'gnus-article-highlight)
824 ;; backward-compatibility alias
825 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
827 (defface gnus-header-content
830 (:foreground "SpringGreen1" :italic t))
833 (:foreground "indianred4" :italic t))
835 (:italic t))) "Face used for displaying header content."
836 :group 'gnus-article-headers
837 :group 'gnus-article-highlight)
838 ;; backward-compatibility alias
839 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
841 (defcustom gnus-header-face-alist
842 '(("From" nil gnus-header-from)
843 ("Subject" nil gnus-header-subject)
844 ("Newsgroups:.*," nil gnus-header-newsgroups)
845 ("" gnus-header-name gnus-header-content))
846 "*Controls highlighting of article headers.
848 An alist of the form (HEADER NAME CONTENT).
850 HEADER is a regular expression which should match the name of a
851 header and NAME and CONTENT are either face names or nil.
853 The name of each header field will be displayed using the face
854 specified by the first element in the list where HEADER matches
855 the header name and NAME is non-nil. Similarly, the content will
856 be displayed by the first non-nil matching CONTENT face."
857 :group 'gnus-article-headers
858 :group 'gnus-article-highlight
859 :type '(repeat (list (regexp :tag "Header")
861 (item :tag "skip" nil)
862 (face :value default))
863 (choice :tag "Content"
864 (item :tag "skip" nil)
865 (face :value default)))))
867 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
868 '((xface . (:face gnus-x-face)))
869 '((pbm . (:face gnus-x-face))
871 "Alist of image types and properties applied to Face and X-Face images.
874 ;; Specify the altitude of Face images in the From header.
875 \(setq gnus-face-properties-alist
876 '((pbm . (:face gnus-x-face :ascent 80))
877 (png . (:ascent 80))))
879 ;; Show Face images as pressed buttons.
880 \(setq gnus-face-properties-alist
881 '((pbm . (:face gnus-x-face :relief -2))
882 (png . (:relief -2))))
884 See the manual for the valid properties for various image types.
885 Currently, `pbm' is used for X-Face images and `png' is used for Face
886 images in Emacs. Only the `:face' property is effective on the `xface'
887 image type in XEmacs if it is built with the libcompface library."
888 :version "23.0" ;; No Gnus
889 :group 'gnus-article-headers
890 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
892 (defcustom gnus-article-decode-hook
893 '(article-decode-charset article-decode-encoded-words
894 article-decode-group-name article-decode-idna-rhs)
895 "*Hook run to decode charsets in articles."
896 :group 'gnus-article-headers
899 (defcustom gnus-display-mime-function 'gnus-display-mime
900 "Function to display MIME articles."
901 :group 'gnus-article-mime
904 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
905 "Function used to decode headers.")
907 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
908 "Function used to decode addresses.")
910 (defvar gnus-article-dumbquotes-map
930 "Table for MS-to-Latin1 translation.")
932 (defcustom gnus-ignored-mime-types nil
933 "List of MIME types that should be ignored by Gnus."
935 :group 'gnus-article-mime
936 :type '(repeat regexp))
938 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
939 "List of MIME types that should not be given buttons when rendered inline.
940 See also `gnus-buttonized-mime-types' which may override this variable.
941 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
946 (defcustom gnus-buttonized-mime-types nil
947 "List of MIME types that should be given buttons when rendered inline.
948 If set, this variable overrides `gnus-unbuttonized-mime-types'.
949 To see e.g. security buttons you could set this to
950 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
951 this list to display radio buttons that allow you to choose one of two
952 media types those mails include. See also `mm-discouraged-alternatives'.
953 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
955 :group 'gnus-article-mime
956 :type '(repeat regexp))
958 (defcustom gnus-inhibit-mime-unbuttonizing nil
959 "If non-nil, all MIME parts get buttons.
960 When nil (the default value), then some MIME parts do not get buttons,
961 as described by the variables `gnus-buttonized-mime-types' and
962 `gnus-unbuttonized-mime-types'."
964 :group 'gnus-article-mime
967 (defcustom gnus-body-boundary-delimiter "_"
968 "String used to delimit header and body.
969 This variable is used by `gnus-article-treat-body-boundary' which can
970 be controlled by `gnus-treat-body-boundary'."
972 :group 'gnus-article-various
973 :type '(choice (item :tag "None" :value nil)
976 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
978 "Defines the location of the faces database.
979 For information on obtaining this database of pretty pictures, please
980 see http://www.cs.indiana.edu/picons/ftp/index.html"
982 :type '(repeat directory)
983 :link '(url-link :tag "download"
984 "http://www.cs.indiana.edu/picons/ftp/index.html")
985 :link '(custom-manual "(gnus)Picons")
988 (defun gnus-picons-installed-p ()
989 "Say whether picons are installed on your machine."
990 (let ((installed nil))
991 (dolist (database gnus-picon-databases)
992 (when (file-exists-p database)
996 (defcustom gnus-article-mime-part-function nil
997 "Function called with a MIME handle as the argument.
998 This is meant for people who want to do something automatic based
999 on parts -- for instance, adding Vcard info to a database."
1000 :group 'gnus-article-mime
1001 :type '(choice (const nil)
1004 (defcustom gnus-mime-multipart-functions nil
1005 "An alist of MIME types to functions to display them."
1007 :group 'gnus-article-mime
1008 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1010 (defcustom gnus-article-date-lapsed-new-header nil
1011 "Whether the X-Sent and Date headers can coexist.
1012 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1013 either replace the old \"Date:\" header (if this variable is nil), or
1014 be added below it (otherwise)."
1016 :group 'gnus-article-headers
1019 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1020 "Function called with a MIME handle as the argument.
1021 This is meant for people who want to view first matched part.
1022 For `undisplayed-alternative' (default), the first undisplayed
1023 part or alternative part is used. For `undisplayed', the first
1024 undisplayed part is used. For a function, the first part which
1025 the function return t is used. For nil, the first part is
1028 :group 'gnus-article-mime
1030 (item :tag "first" :value nil)
1031 (item :tag "undisplayed" :value undisplayed)
1032 (item :tag "undisplayed or alternative"
1033 :value undisplayed-alternative)
1036 (defcustom gnus-mime-action-alist
1037 '(("save to file" . gnus-mime-save-part)
1038 ("save and strip" . gnus-mime-save-part-and-strip)
1039 ("replace with file" . gnus-mime-replace-part)
1040 ("delete part" . gnus-mime-delete-part)
1041 ("display as text" . gnus-mime-inline-part)
1042 ("view the part" . gnus-mime-view-part)
1043 ("pipe to command" . gnus-mime-pipe-part)
1044 ("toggle display" . gnus-article-press-button)
1045 ("toggle display" . gnus-article-view-part-as-charset)
1046 ("view as type" . gnus-mime-view-part-as-type)
1047 ("view internally" . gnus-mime-view-part-internally)
1048 ("view externally" . gnus-mime-view-part-externally))
1049 "An alist of actions that run on the MIME attachment."
1050 :group 'gnus-article-mime
1051 :type '(repeat (cons (string :tag "name")
1054 (defcustom gnus-auto-select-part 1
1055 "Advance to next MIME part when deleting or stripping parts.
1057 When 0, point will be placed on the same part as before. When
1058 positive (negative), move point forward (backwards) this many
1059 parts. When nil, redisplay article."
1060 :version "23.0" ;; No Gnus
1061 :group 'gnus-article-mime
1062 :type '(choice (const nil :tag "Redisplay article.")
1063 (const 1 :tag "Next part.")
1064 (const 0 :tag "Current part.")
1068 ;;; The treatment variables
1071 (defvar gnus-part-display-hook nil
1072 "Hook called on parts that are to receive treatment.")
1074 (defvar gnus-article-treat-custom
1075 '(choice (const :tag "Off" nil)
1077 (const :tag "Header" head)
1078 (const :tag "First" first)
1079 (const :tag "Last" last)
1080 (integer :tag "Less")
1081 (repeat :tag "Groups" regexp)
1082 (sexp :tag "Predicate")))
1084 (defvar gnus-article-treat-head-custom
1085 '(choice (const :tag "Off" nil)
1086 (const :tag "Header" head)))
1088 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1092 (defvar gnus-inhibit-treatment nil
1093 "Whether to inhibit treatment.")
1095 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1096 "Highlight the signature.
1097 Valid values are nil, t, `head', `first', `last', an integer or a
1098 predicate. See Info node `(gnus)Customizing Articles'."
1099 :group 'gnus-article-treat
1100 :link '(custom-manual "(gnus)Customizing Articles")
1101 :type gnus-article-treat-custom)
1102 (put 'gnus-treat-highlight-signature 'highlight t)
1104 (defcustom gnus-treat-buttonize 100000
1106 Valid values are nil, t, `head', `first', `last', an integer or a
1107 predicate. See Info node `(gnus)Customizing Articles'."
1108 :group 'gnus-article-treat
1109 :link '(custom-manual "(gnus)Customizing Articles")
1110 :type gnus-article-treat-custom)
1111 (put 'gnus-treat-buttonize 'highlight t)
1113 (defcustom gnus-treat-buttonize-head 'head
1114 "Add buttons to the head.
1115 Valid values are nil, t, `head', `first', `last', an integer or a
1116 predicate. See Info node `(gnus)Customizing Articles'."
1117 :group 'gnus-article-treat
1118 :link '(custom-manual "(gnus)Customizing Articles")
1119 :type gnus-article-treat-head-custom)
1120 (put 'gnus-treat-buttonize-head 'highlight t)
1122 (defcustom gnus-treat-emphasize 50000
1124 Valid values are nil, t, `head', `first', `last', an integer or a
1125 predicate. See Info node `(gnus)Customizing Articles'."
1126 :group 'gnus-article-treat
1127 :link '(custom-manual "(gnus)Customizing Articles")
1128 :type gnus-article-treat-custom)
1129 (put 'gnus-treat-emphasize 'highlight t)
1131 (defcustom gnus-treat-strip-cr nil
1132 "Remove carriage returns.
1133 Valid values are nil, t, `head', `first', `last', an integer or a
1134 predicate. See Info node `(gnus)Customizing Articles'."
1136 :group 'gnus-article-treat
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-custom)
1140 (defcustom gnus-treat-unsplit-urls nil
1141 "Remove newlines from within URLs.
1142 Valid values are nil, t, `head', `first', `last', an integer or a
1143 predicate. See Info node `(gnus)Customizing Articles'."
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-custom)
1149 (defcustom gnus-treat-leading-whitespace nil
1150 "Remove leading whitespace in headers.
1151 Valid values are nil, t, `head', `first', `last', an integer or a
1152 predicate. See Info node `(gnus)Customizing Articles'."
1154 :group 'gnus-article-treat
1155 :link '(custom-manual "(gnus)Customizing Articles")
1156 :type gnus-article-treat-custom)
1158 (defcustom gnus-treat-hide-headers 'head
1160 Valid values are nil, t, `head', `first', `last', an integer or a
1161 predicate. See Info node `(gnus)Customizing Articles'."
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1166 (defcustom gnus-treat-hide-boring-headers nil
1167 "Hide boring headers.
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate. See Info node `(gnus)Customizing Articles'."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-head-custom)
1174 (defcustom gnus-treat-hide-signature nil
1175 "Hide the signature.
1176 Valid values are nil, t, `head', `first', `last', an integer or a
1177 predicate. See Info node `(gnus)Customizing Articles'."
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-custom)
1182 (defcustom gnus-treat-fill-article nil
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate. See Info node `(gnus)Customizing Articles'."
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1190 (defcustom gnus-treat-hide-citation nil
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :group 'gnus-article-treat
1195 :link '(custom-manual "(gnus)Customizing Articles")
1196 :type gnus-article-treat-custom)
1198 (defcustom gnus-treat-hide-citation-maybe nil
1200 Valid values are nil, t, `head', `first', `last', an integer or a
1201 predicate. See Info node `(gnus)Customizing Articles'."
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-custom)
1206 (defcustom gnus-treat-strip-list-identifiers 'head
1207 "Strip list identifiers from `gnus-list-identifiers`.
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate. See Info node `(gnus)Customizing Articles'."
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-custom)
1215 (make-obsolete-variable 'gnus-treat-strip-pgp
1216 "This option is obsolete in Gnus 5.10.")
1218 (defcustom gnus-treat-strip-pem nil
1219 "Strip PEM signatures.
1220 Valid values are nil, t, `head', `first', `last', an integer or a
1221 predicate. See Info node `(gnus)Customizing Articles'."
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-custom)
1226 (defcustom gnus-treat-strip-banner t
1227 "Strip banners from articles.
1228 The banner to be stripped is specified in the `banner' group parameter.
1229 Valid values are nil, t, `head', `first', `last', an integer or a
1230 predicate. See Info node `(gnus)Customizing Articles'."
1231 :group 'gnus-article-treat
1232 :link '(custom-manual "(gnus)Customizing Articles")
1233 :type gnus-article-treat-custom)
1235 (defcustom gnus-treat-highlight-headers 'head
1236 "Highlight the headers.
1237 Valid values are nil, t, `head', `first', `last', an integer or a
1238 predicate. See Info node `(gnus)Customizing Articles'."
1239 :group 'gnus-article-treat
1240 :link '(custom-manual "(gnus)Customizing Articles")
1241 :type gnus-article-treat-head-custom)
1242 (put 'gnus-treat-highlight-headers 'highlight t)
1244 (defcustom gnus-treat-highlight-citation t
1245 "Highlight cited text.
1246 Valid values are nil, t, `head', `first', `last', an integer or a
1247 predicate. See Info node `(gnus)Customizing Articles'."
1248 :group 'gnus-article-treat
1249 :link '(custom-manual "(gnus)Customizing Articles")
1250 :type gnus-article-treat-custom)
1251 (put 'gnus-treat-highlight-citation 'highlight t)
1253 (defcustom gnus-treat-date-ut nil
1254 "Display the Date in UT (GMT).
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate. See Info node `(gnus)Customizing Articles'."
1257 :group 'gnus-article-treat
1258 :link '(custom-manual "(gnus)Customizing Articles")
1259 :type gnus-article-treat-head-custom)
1261 (defcustom gnus-treat-date-local nil
1262 "Display the Date in the local timezone.
1263 Valid values are nil, t, `head', `first', `last', an integer or a
1264 predicate. See Info node `(gnus)Customizing Articles'."
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-head-custom)
1269 (defcustom gnus-treat-date-english nil
1270 "Display the Date in a format that can be read aloud in English.
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate. See Info node `(gnus)Customizing Articles'."
1274 :group 'gnus-article-treat
1275 :link '(custom-manual "(gnus)Customizing Articles")
1276 :type gnus-article-treat-head-custom)
1278 (defcustom gnus-treat-date-lapsed nil
1279 "Display the Date header in a way that says how much time has elapsed.
1280 Valid values are nil, t, `head', `first', `last', an integer or a
1281 predicate. See Info node `(gnus)Customizing Articles'."
1282 :group 'gnus-article-treat
1283 :link '(custom-manual "(gnus)Customizing Articles")
1284 :type gnus-article-treat-head-custom)
1286 (defcustom gnus-treat-date-original nil
1287 "Display the date in the original timezone.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-head-custom)
1294 (defcustom gnus-treat-date-iso8601 nil
1295 "Display the date in the ISO8601 format.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate. See Info node `(gnus)Customizing Articles'."
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-head-custom)
1303 (defcustom gnus-treat-date-user-defined nil
1304 "Display the date in a user-defined format.
1305 The format is defined by the `gnus-article-time-format' variable.
1306 Valid values are nil, t, `head', `first', `last', an integer or a
1307 predicate. See Info node `(gnus)Customizing Articles'."
1308 :group 'gnus-article-treat
1309 :link '(custom-manual "(gnus)Customizing Articles")
1310 :type gnus-article-treat-head-custom)
1312 (defcustom gnus-treat-strip-headers-in-body t
1313 "Strip the X-No-Archive header line from the beginning of the body.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1317 :group 'gnus-article-treat
1318 :link '(custom-manual "(gnus)Customizing Articles")
1319 :type gnus-article-treat-custom)
1321 (defcustom gnus-treat-strip-trailing-blank-lines nil
1322 "Strip trailing blank lines.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate. See Info node `(gnus)Customizing Articles'.
1326 When set to t, it also strips trailing blanks in all MIME parts.
1327 Consider to use `last' instead."
1328 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :type gnus-article-treat-custom)
1332 (defcustom gnus-treat-strip-leading-blank-lines nil
1333 "Strip leading blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate. See Info node `(gnus)Customizing Articles'.
1337 When set to t, it also strips trailing blanks in all MIME parts."
1338 :group 'gnus-article-treat
1339 :link '(custom-manual "(gnus)Customizing Articles")
1340 :type gnus-article-treat-custom)
1342 (defcustom gnus-treat-strip-multiple-blank-lines nil
1343 "Strip multiple blank lines.
1344 Valid values are nil, t, `head', `first', `last', an integer or a
1345 predicate. See Info node `(gnus)Customizing Articles'."
1346 :group 'gnus-article-treat
1347 :link '(custom-manual "(gnus)Customizing Articles")
1348 :type gnus-article-treat-custom)
1350 (defcustom gnus-treat-unfold-headers 'head
1351 "Unfold folded header lines.
1352 Valid values are nil, t, `head', `first', `last', an integer or a
1353 predicate. See Info node `(gnus)Customizing Articles'."
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1359 (defcustom gnus-article-unfold-long-headers nil
1360 "If non-nil, allow unfolding headers even if the header is long.
1361 If it is a regexp, only long headers matching this regexp are unfolded.
1362 If it is t, all long headers are unfolded.
1364 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1365 :version "23.0" ;; No Gnus
1366 :group 'gnus-article-treat
1367 :type '(choice (const nil)
1368 (const :tag "all" t)
1371 (defcustom gnus-treat-fold-headers nil
1373 Valid values are nil, t, `head', `first', `last', an integer or a
1374 predicate. See Info node `(gnus)Customizing Articles'."
1376 :group 'gnus-article-treat
1377 :link '(custom-manual "(gnus)Customizing Articles")
1378 :type gnus-article-treat-custom)
1380 (defcustom gnus-treat-fold-newsgroups 'head
1381 "Fold the Newsgroups and Followup-To headers.
1382 Valid values are nil, t, `head', `first', `last', an integer or a
1383 predicate. See Info node `(gnus)Customizing Articles'."
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1389 (defcustom gnus-treat-overstrike t
1390 "Treat overstrike highlighting.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate. See Info node `(gnus)Customizing Articles'."
1393 :group 'gnus-article-treat
1394 :link '(custom-manual "(gnus)Customizing Articles")
1395 :type gnus-article-treat-custom)
1396 (put 'gnus-treat-overstrike 'highlight t)
1398 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1399 "Treat ANSI SGR control sequences.
1400 Valid values are nil, t, `head', `first', `last', an integer or a
1401 predicate. See Info node `(gnus)Customizing Articles'."
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1406 (make-obsolete-variable 'gnus-treat-display-xface
1407 'gnus-treat-display-x-face)
1409 (defcustom gnus-treat-display-x-face
1410 (and (not noninteractive)
1411 (gnus-image-type-available-p 'xbm)
1412 (if (featurep 'xemacs)
1414 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1415 (executable-find "icontopbm")))
1417 "Display X-Face headers.
1418 Valid values are nil and `head'.
1419 See Info node `(gnus)Customizing Articles' and Info node
1420 `(gnus)X-Face' for details."
1421 :group 'gnus-article-treat
1423 :link '(custom-manual "(gnus)Customizing Articles")
1424 :link '(custom-manual "(gnus)X-Face")
1425 :type gnus-article-treat-head-custom
1426 :set (lambda (symbol value)
1429 (cond ((or (boundp symbol) (get symbol 'saved-value))
1431 ((boundp 'gnus-treat-display-xface)
1433 ** gnus-treat-display-xface is an obsolete variable;\
1434 use gnus-treat-display-x-face instead")
1435 (default-value 'gnus-treat-display-xface))
1436 ((get 'gnus-treat-display-xface 'saved-value)
1438 ** gnus-treat-display-xface is an obsolete variable;\
1439 use gnus-treat-display-x-face instead")
1440 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1443 (put 'gnus-treat-display-x-face 'highlight t)
1445 (defcustom gnus-treat-display-face
1446 (and (not noninteractive)
1447 (gnus-image-type-available-p 'png)
1449 "Display Face headers.
1450 Valid values are nil, t, `head', `first', `last', an integer or a
1451 predicate. See Info node `(gnus)Customizing Articles' and Info
1452 node `(gnus)X-Face' for details."
1453 :group 'gnus-article-treat
1455 :link '(custom-manual "(gnus)Customizing Articles")
1456 :link '(custom-manual "(gnus)X-Face")
1457 :type gnus-article-treat-head-custom)
1458 (put 'gnus-treat-display-face 'highlight t)
1460 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1462 Valid values are nil, t, `head', `first', `last', an integer or a
1463 predicate. See Info node `(gnus)Customizing Articles' and Info
1464 node `(gnus)Smileys' for details."
1465 :group 'gnus-article-treat
1467 :link '(custom-manual "(gnus)Customizing Articles")
1468 :link '(custom-manual "(gnus)Smileys")
1469 :type gnus-article-treat-custom)
1470 (put 'gnus-treat-display-smileys 'highlight t)
1472 (defcustom gnus-treat-from-picon
1473 (if (and (gnus-image-type-available-p 'xpm)
1474 (gnus-picons-installed-p))
1476 "Display picons in the From header.
1477 Valid values are nil, t, `head', `first', `last', an integer or a
1478 predicate. See Info node `(gnus)Customizing Articles' and Info
1479 node `(gnus)Picons' for details."
1481 :group 'gnus-article-treat
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Picons")
1485 :type gnus-article-treat-head-custom)
1486 (put 'gnus-treat-from-picon 'highlight t)
1488 (defcustom gnus-treat-mail-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1492 "Display picons in To and Cc headers.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate. See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1497 :group 'gnus-article-treat
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-mail-picon 'highlight t)
1504 (defcustom gnus-treat-newsgroups-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1508 "Display picons in the Newsgroups and Followup-To headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate. See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1513 :group 'gnus-article-treat
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-newsgroups-picon 'highlight t)
1520 (defcustom gnus-treat-body-boundary
1521 (if (or gnus-treat-newsgroups-picon
1522 gnus-treat-mail-picon
1523 gnus-treat-from-picon)
1524 ;; If there's much decoration, the user might prefer a boundery.
1527 "Draw a boundary at the end of the headers.
1528 Valid values are nil and `head'.
1529 See Info node `(gnus)Customizing Articles' for details."
1531 :group 'gnus-article-treat
1532 :link '(custom-manual "(gnus)Customizing Articles")
1533 :type gnus-article-treat-head-custom)
1535 (defcustom gnus-treat-capitalize-sentences nil
1536 "Capitalize sentence-starting words.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate. See Info node `(gnus)Customizing Articles'."
1540 :group 'gnus-article-treat
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :type gnus-article-treat-custom)
1544 (defcustom gnus-treat-wash-html nil
1546 Valid values are nil, t, `head', `first', `last', an integer or a
1547 predicate. See Info node `(gnus)Customizing Articles'."
1549 :group 'gnus-article-treat
1550 :link '(custom-manual "(gnus)Customizing Articles")
1551 :type gnus-article-treat-custom)
1553 (defcustom gnus-treat-fill-long-lines nil
1555 Valid values are nil, t, `head', `first', `last', an integer or a
1556 predicate. See Info node `(gnus)Customizing Articles'."
1557 :group 'gnus-article-treat
1558 :link '(custom-manual "(gnus)Customizing Articles")
1559 :type gnus-article-treat-custom)
1561 (defcustom gnus-treat-play-sounds nil
1563 Valid values are nil, t, `head', `first', `last', an integer or a
1564 predicate. See Info node `(gnus)Customizing Articles'."
1566 :group 'gnus-article-treat
1567 :link '(custom-manual "(gnus)Customizing Articles")
1568 :type gnus-article-treat-custom)
1570 (defcustom gnus-treat-translate nil
1571 "Translate articles from one language to another.
1572 Valid values are nil, t, `head', `first', `last', an integer or a
1573 predicate. See Info node `(gnus)Customizing Articles'."
1575 :group 'gnus-article-treat
1576 :link '(custom-manual "(gnus)Customizing Articles")
1577 :type gnus-article-treat-custom)
1579 (defcustom gnus-treat-x-pgp-sig nil
1581 To automatically treat X-PGP-Sig, set it to head.
1582 Valid values are nil, t, `head', `first', `last', an integer or a
1583 predicate. See Info node `(gnus)Customizing Articles'."
1585 :group 'gnus-article-treat
1586 :group 'mime-security
1587 :link '(custom-manual "(gnus)Customizing Articles")
1588 :type gnus-article-treat-custom)
1590 (defvar gnus-article-encrypt-protocol-alist
1591 '(("PGP" . mml2015-self-encrypt)))
1593 ;; Set to nil if more than one protocol added to
1594 ;; gnus-article-encrypt-protocol-alist.
1595 (defcustom gnus-article-encrypt-protocol "PGP"
1596 "The protocol used for encrypt articles.
1597 It is a string, such as \"PGP\". If nil, ask user."
1600 :group 'mime-security)
1602 (defvar gnus-article-wash-function nil
1603 "Function used for converting HTML into text.")
1605 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1606 (mm-coding-system-p 'utf-8)
1607 (executable-find idna-program))
1608 "Whether IDNA decoding of headers is used when viewing messages.
1609 This requires GNU Libidn, and by default only enabled if it is found."
1611 :group 'gnus-article-headers
1614 (defcustom gnus-article-over-scroll nil
1615 "If non-nil, allow scrolling the article buffer even when there no more text."
1617 :group 'gnus-article
1620 ;;; Internal variables
1622 (defvar gnus-english-month-names
1623 '("January" "February" "March" "April" "May" "June" "July" "August"
1624 "September" "October" "November" "December"))
1626 (defvar article-goto-body-goes-to-point-min-p nil)
1627 (defvar gnus-article-wash-types nil)
1628 (defvar gnus-article-emphasis-alist nil)
1629 (defvar gnus-article-image-alist nil)
1631 (defvar gnus-article-mime-handle-alist-1 nil)
1632 (defvar gnus-treatment-function-alist
1633 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1634 (gnus-treat-strip-banner gnus-article-strip-banner)
1635 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1636 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1637 (gnus-treat-buttonize gnus-article-add-buttons)
1638 (gnus-treat-fill-article gnus-article-fill-cited-article)
1639 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1640 (gnus-treat-strip-cr gnus-article-remove-cr)
1641 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1642 (gnus-treat-date-ut gnus-article-date-ut)
1643 (gnus-treat-date-local gnus-article-date-local)
1644 (gnus-treat-date-english gnus-article-date-english)
1645 (gnus-treat-date-original gnus-article-date-original)
1646 (gnus-treat-date-user-defined gnus-article-date-user)
1647 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1648 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1649 (gnus-treat-display-x-face gnus-article-display-x-face)
1650 (gnus-treat-display-face gnus-article-display-face)
1651 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1652 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1653 (gnus-treat-hide-signature gnus-article-hide-signature)
1654 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1655 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1656 (gnus-treat-strip-pem gnus-article-hide-pem)
1657 (gnus-treat-from-picon gnus-treat-from-picon)
1658 (gnus-treat-mail-picon gnus-treat-mail-picon)
1659 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1660 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1661 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1662 (gnus-treat-strip-trailing-blank-lines
1663 gnus-article-remove-trailing-blank-lines)
1664 (gnus-treat-strip-leading-blank-lines
1665 gnus-article-strip-leading-blank-lines)
1666 (gnus-treat-strip-multiple-blank-lines
1667 gnus-article-strip-multiple-blank-lines)
1668 (gnus-treat-overstrike gnus-article-treat-overstrike)
1669 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1670 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1671 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1672 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1673 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1674 (gnus-treat-display-smileys gnus-treat-smiley)
1675 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1676 (gnus-treat-wash-html gnus-article-wash-html)
1677 (gnus-treat-emphasize gnus-article-emphasize)
1678 (gnus-treat-hide-citation gnus-article-hide-citation)
1679 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1680 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1681 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1682 (gnus-treat-play-sounds gnus-earcon-display)))
1684 (defvar gnus-article-mime-handle-alist nil)
1685 (defvar article-lapsed-timer nil)
1686 (defvar gnus-article-current-summary nil)
1688 (defvar gnus-article-mode-syntax-table
1689 (let ((table (copy-syntax-table text-mode-syntax-table)))
1690 ;; This causes the citation match run O(2^n).
1691 ;; (modify-syntax-entry ?- "w" table)
1692 (modify-syntax-entry ?> ")<" table)
1693 (modify-syntax-entry ?< "(>" table)
1694 ;; make M-. in article buffers work for `foo' strings
1695 (modify-syntax-entry ?' " " table)
1696 (modify-syntax-entry ?` " " table)
1698 "Syntax table used in article mode buffers.
1699 Initialized from `text-mode-syntax-table.")
1701 (defvar gnus-save-article-buffer nil)
1703 (defvar gnus-article-mode-line-format-alist
1704 (nconc '((?w (gnus-article-wash-status) ?s)
1705 (?m (gnus-article-mime-part-status) ?s))
1706 gnus-summary-mode-line-format-alist))
1708 (defvar gnus-number-of-articles-to-be-saved nil)
1710 (defvar gnus-inhibit-hiding nil)
1712 (defvar gnus-article-edit-mode nil)
1714 ;;; Macros for dealing with the article buffer.
1716 (defmacro gnus-with-article-headers (&rest forms)
1718 (set-buffer gnus-article-buffer)
1720 (let ((inhibit-read-only t)
1721 (inhibit-point-motion-hooks t)
1722 (case-fold-search t))
1723 (article-narrow-to-head)
1726 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1727 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1729 (defmacro gnus-with-article-buffer (&rest forms)
1731 (set-buffer gnus-article-buffer)
1732 (let ((inhibit-read-only t))
1735 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1736 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1738 (defun gnus-article-goto-header (header)
1739 "Go to HEADER, which is a regular expression."
1740 (re-search-forward (concat "^\\(" header "\\):") nil t))
1742 (defsubst gnus-article-hide-text (b e props)
1743 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1744 (gnus-add-text-properties-when 'article-type nil b e props)
1745 (when (memq 'intangible props)
1747 (max (1- b) (point-min))
1748 b 'intangible (cddr (memq 'intangible props)))))
1750 (defsubst gnus-article-unhide-text (b e)
1751 "Remove hidden text properties from region between B and E."
1752 (remove-text-properties b e gnus-hidden-properties)
1753 (when (memq 'intangible gnus-hidden-properties)
1754 (put-text-property (max (1- b) (point-min))
1755 b 'intangible nil)))
1757 (defun gnus-article-hide-text-type (b e type)
1758 "Hide text of TYPE between B and E."
1759 (gnus-add-wash-type type)
1760 (gnus-article-hide-text
1761 b e (cons 'article-type (cons type gnus-hidden-properties))))
1763 (defun gnus-article-unhide-text-type (b e type)
1764 "Unhide text of TYPE between B and E."
1765 (gnus-delete-wash-type type)
1766 (remove-text-properties
1767 b e (cons 'article-type (cons type gnus-hidden-properties)))
1768 (when (memq 'intangible gnus-hidden-properties)
1769 (put-text-property (max (1- b) (point-min))
1770 b 'intangible nil)))
1772 (defun gnus-article-hide-text-of-type (type)
1773 "Hide text of TYPE in the current buffer."
1775 (let ((b (point-min))
1777 (while (setq b (text-property-any b e 'article-type type))
1778 (add-text-properties b (incf b) gnus-hidden-properties)))))
1780 (defun gnus-article-delete-text-of-type (type)
1781 "Delete text of TYPE in the current buffer."
1783 (let ((b (point-min)))
1784 (if (eq type 'multipart)
1785 ;; Remove MIME buttons associated with multipart/alternative parts.
1788 (while (if (get-text-property (point) 'gnus-part)
1790 (when (setq b (next-single-property-change (point)
1795 (skip-chars-forward "\n")
1796 (when (eq (get-text-property b 'article-type) 'multipart)
1797 (delete-region b (point)))))
1798 (while (setq b (text-property-any b (point-max) 'article-type type))
1800 b (or (text-property-not-all b (point-max) 'article-type type)
1803 (defun gnus-article-delete-invisible-text ()
1804 "Delete all invisible text in the current buffer."
1806 (let ((b (point-min)))
1807 (while (setq b (text-property-any b (point-max) 'invisible t))
1809 b (or (text-property-not-all b (point-max) 'invisible t)
1812 (defun gnus-article-text-type-exists-p (type)
1813 "Say whether any text of type TYPE exists in the buffer."
1814 (text-property-any (point-min) (point-max) 'article-type type))
1816 (defsubst gnus-article-header-rank ()
1817 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1818 (let ((list gnus-sorted-header-list)
1821 (if (looking-at (car list))
1823 (setq list (cdr list))
1827 (defun article-hide-headers (&optional arg delete)
1828 "Hide unwanted headers and possibly sort them as well."
1830 ;; This function might be inhibited.
1831 (unless gnus-inhibit-hiding
1832 (let ((inhibit-read-only t)
1833 (case-fold-search t)
1834 (max (1+ (length gnus-sorted-header-list)))
1835 (inhibit-point-motion-hooks t)
1836 (cur (current-buffer))
1837 ignored visible beg)
1839 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1840 ;; group parameters, so we should go to the summary buffer.
1843 (progn (set-buffer gnus-summary-buffer) t)
1845 (setq ignored (when (not gnus-visible-headers)
1846 (cond ((stringp gnus-ignored-headers)
1847 gnus-ignored-headers)
1848 ((listp gnus-ignored-headers)
1849 (mapconcat 'identity
1850 gnus-ignored-headers
1852 visible (cond ((stringp gnus-visible-headers)
1853 gnus-visible-headers)
1854 ((and gnus-visible-headers
1855 (listp gnus-visible-headers))
1856 (mapconcat 'identity
1857 gnus-visible-headers
1861 ;; First we narrow to just the headers.
1862 (article-narrow-to-head)
1863 ;; Hide any "From " lines at the beginning of (mail) articles.
1864 (while (looking-at "From ")
1867 (delete-region (point-min) (point)))
1868 ;; Then treat the rest of the header lines.
1869 ;; Then we use the two regular expressions
1870 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1871 ;; select which header lines is to remain visible in the
1873 (while (re-search-forward "^[^ \t:]*:" nil t)
1875 ;; Mark the rank of the header.
1877 (point) (1+ (point)) 'message-rank
1878 (if (or (and visible (looking-at visible))
1880 (not (looking-at ignored))))
1881 (gnus-article-header-rank)
1884 (message-sort-headers-1)
1885 (when (setq beg (text-property-any
1886 (point-min) (point-max) 'message-rank (+ 2 max)))
1887 ;; We delete the unwanted headers.
1888 (gnus-add-wash-type 'headers)
1889 (add-text-properties (point-min) (+ 5 (point-min))
1890 '(article-type headers dummy-invisible t))
1891 (delete-region beg (point-max))))))))
1893 (defun article-hide-boring-headers (&optional arg)
1894 "Toggle hiding of headers that aren't very interesting.
1895 If given a negative prefix, always show; if given a positive prefix,
1897 (interactive (gnus-article-hidden-arg))
1898 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1899 (not gnus-show-all-headers))
1902 (let ((inhibit-read-only t)
1903 (inhibit-point-motion-hooks t))
1904 (article-narrow-to-head)
1905 (dolist (elem gnus-boring-article-headers)
1906 (goto-char (point-min))
1908 ;; Hide empty headers.
1910 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1912 (gnus-article-hide-text-type
1916 (if (re-search-forward "^[^ \t]" nil t)
1920 ;; Hide boring Newsgroups header.
1921 ((eq elem 'newsgroups)
1922 (when (gnus-string-equal
1923 (gnus-fetch-field "newsgroups")
1924 (gnus-group-real-name
1925 (if (boundp 'gnus-newsgroup-name)
1928 (gnus-article-hide-header "newsgroups")))
1929 ((eq elem 'to-address)
1930 (let ((to (message-fetch-field "to"))
1932 (gnus-parameter-to-address
1933 (if (boundp 'gnus-newsgroup-name)
1934 gnus-newsgroup-name ""))))
1935 (when (and to to-address
1938 ;; only one address in To
1939 (nth 1 (mail-extract-address-components to))
1941 (gnus-article-hide-header "to"))))
1943 (let ((to (message-fetch-field "to"))
1945 (gnus-parameter-to-list
1946 (if (boundp 'gnus-newsgroup-name)
1947 gnus-newsgroup-name ""))))
1948 (when (and to to-list
1951 ;; only one address in To
1952 (nth 1 (mail-extract-address-components to))
1954 (gnus-article-hide-header "to"))))
1956 (let ((cc (message-fetch-field "cc"))
1958 (gnus-parameter-to-list
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and cc to-list
1964 ;; only one address in CC
1965 (nth 1 (mail-extract-address-components cc))
1967 (gnus-article-hide-header "cc"))))
1968 ((eq elem 'followup-to)
1969 (when (gnus-string-equal
1970 (message-fetch-field "followup-to")
1971 (message-fetch-field "newsgroups"))
1972 (gnus-article-hide-header "followup-to")))
1973 ((eq elem 'reply-to)
1974 (if (gnus-group-find-parameter
1975 gnus-newsgroup-name 'broken-reply-to)
1976 (gnus-article-hide-header "reply-to")
1977 (let ((from (message-fetch-field "from"))
1978 (reply-to (message-fetch-field "reply-to")))
1985 (lambda (x) (downcase (cadr x)))
1986 (mail-extract-address-components from t))
1989 (lambda (x) (downcase (cadr x)))
1990 (mail-extract-address-components reply-to t))
1992 (gnus-article-hide-header "reply-to")))))
1994 (let ((date (with-current-buffer gnus-original-article-buffer
1995 ;; If date in `gnus-article-buffer' is localized
1996 ;; (`gnus-treat-date-user-defined'),
1997 ;; `days-between' might fail.
1998 (message-fetch-field "date"))))
2000 (< (days-between (current-time-string) date)
2002 (gnus-article-hide-header "date"))))
2004 (let ((to (message-fetch-field "to"))
2005 (cc (message-fetch-field "cc")))
2006 (when (> (length to) 1024)
2007 (gnus-article-hide-header "to"))
2008 (when (> (length cc) 1024)
2009 (gnus-article-hide-header "cc"))))
2013 (goto-char (point-min))
2014 (while (re-search-forward "^to:" nil t)
2015 (setq to-count (1+ to-count)))
2016 (when (> to-count 1)
2017 (while (> to-count 0)
2018 (goto-char (point-min))
2020 (re-search-forward "^to:" nil nil to-count)
2022 (narrow-to-region (point) (point-max))
2023 (gnus-article-hide-header "to"))
2024 (setq to-count (1- to-count))))
2025 (goto-char (point-min))
2026 (while (re-search-forward "^cc:" nil t)
2027 (setq cc-count (1+ cc-count)))
2028 (when (> cc-count 1)
2029 (while (> cc-count 0)
2030 (goto-char (point-min))
2032 (re-search-forward "^cc:" nil nil cc-count)
2034 (narrow-to-region (point) (point-max))
2035 (gnus-article-hide-header "cc"))
2036 (setq cc-count (1- cc-count)))))))))))))
2038 (defun gnus-article-hide-header (header)
2040 (goto-char (point-min))
2041 (when (re-search-forward (concat "^" header ":") nil t)
2042 (gnus-article-hide-text-type
2046 (if (re-search-forward "^[^ \t]" nil t)
2051 (defvar gnus-article-normalized-header-length 40
2052 "Length of normalized headers.")
2054 (defun article-normalize-headers ()
2055 "Make all header lines 40 characters long."
2057 (let ((inhibit-read-only t)
2061 (article-narrow-to-head)
2064 ((< (setq column (- (point-at-eol) (point)))
2065 gnus-article-normalized-header-length)
2067 (insert (make-string
2068 (- gnus-article-normalized-header-length column)
2070 ((> column gnus-article-normalized-header-length)
2071 (gnus-put-text-property
2073 (forward-char gnus-article-normalized-header-length)
2080 (forward-line 1))))))
2082 (defun article-treat-dumbquotes ()
2083 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2084 Note that this function guesses whether a character is a sm*rtq**t* or
2085 not, so it should only be used interactively.
2087 Sm*rtq**t*s are M****s***'s unilateral extension to the
2088 iso-8859-1 character map in an attempt to provide more quoting
2089 characters. If you see something like \\222 or \\264 where
2090 you're expecting some kind of apostrophe or quotation mark, then
2093 (article-translate-strings gnus-article-dumbquotes-map))
2095 (defun article-translate-characters (from to)
2096 "Translate all characters in the body of the article according to FROM and TO.
2097 FROM is a string of characters to translate from; to is a string of
2098 characters to translate to."
2100 (when (article-goto-body)
2101 (let ((inhibit-read-only t)
2102 (x (make-string 225 ?x))
2104 (while (< (incf i) (length x))
2107 (while (< i (length from))
2108 (aset x (aref from i) (aref to i))
2110 (translate-region (point) (point-max) x)))))
2112 (defun article-translate-strings (map)
2113 "Translate all string in the body of the article according to MAP.
2114 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2116 (when (article-goto-body)
2117 (let ((inhibit-read-only t))
2120 (while (search-forward (car elem) nil t)
2121 (replace-match (cadr elem)))))))))
2123 (defun article-treat-overstrike ()
2124 "Translate overstrikes into bold text."
2127 (when (article-goto-body)
2128 (let ((inhibit-read-only t))
2129 (while (search-forward "\b" nil t)
2130 (let ((next (char-after))
2131 (previous (char-after (- (point) 2))))
2132 ;; We do the boldification/underlining by hiding the
2133 ;; overstrikes and putting the proper text property
2137 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2138 (put-text-property (point) (1+ (point)) 'face 'bold))
2140 (gnus-article-hide-text-type
2141 (1- (point)) (1+ (point)) 'overstrike)
2143 (- (point) 2) (1- (point)) 'face 'underline))
2145 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2147 (point) (1+ (point)) 'face 'underline)))))))))
2149 (defun article-treat-ansi-sequences ()
2150 "Translate ANSI SGR control sequences into overlays or extents."
2153 (when (article-goto-body)
2154 (let ((inhibit-read-only t))
2155 (ansi-color-apply-on-region (point) (point-max))))))
2157 (defun gnus-article-treat-unfold-headers ()
2158 "Unfold folded message headers.
2159 Only the headers that fit into the current window width will be
2162 (gnus-with-article-headers
2166 (mail-header-narrow-to-field)
2167 (let* ((header (buffer-string))
2169 (or (equal gnus-article-unfold-long-headers t)
2170 (and (stringp gnus-article-unfold-long-headers)
2171 (string-match gnus-article-unfold-long-headers header)))))
2174 (goto-char (point-min))
2175 (while (re-search-forward "\n[\t ]" nil t)
2176 (replace-match " " t t)))
2177 (setq length (- (point-max) (point-min) 1))
2178 (when (or unfoldable
2179 (< length (window-width)))
2180 (while (re-search-forward "\n[\t ]" nil t)
2181 (replace-match " " t t))))
2182 (goto-char (point-max)))))))
2184 (defun gnus-article-treat-fold-headers ()
2185 "Fold message headers."
2187 (gnus-with-article-headers
2190 (mail-header-narrow-to-field)
2191 (mail-header-fold-field)
2192 (goto-char (point-max))))))
2194 (defun gnus-treat-smiley ()
2195 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2197 (gnus-with-article-buffer
2198 (if (memq 'smiley gnus-article-wash-types)
2199 (gnus-delete-images 'smiley)
2201 (let ((images (smiley-region (point) (point-max))))
2203 (gnus-add-wash-type 'smiley)
2204 (dolist (image images)
2205 (gnus-add-image 'smiley image)))))))
2207 (defun gnus-article-remove-images ()
2208 "Remove all images from the article buffer."
2210 (gnus-with-article-buffer
2211 (dolist (elem gnus-article-image-alist)
2212 (gnus-delete-images (car elem)))))
2214 (defun gnus-article-treat-fold-newsgroups ()
2215 "Unfold folded message headers.
2216 Only the headers that fit into the current window width will be
2219 (gnus-with-article-headers
2220 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2222 (mail-header-narrow-to-field)
2223 (while (re-search-forward ", *" nil t)
2224 (replace-match ", " t t))
2225 (mail-header-fold-field)
2226 (goto-char (point-max))))))
2228 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2229 "Value of `truncate-lines' in Gnus Article buffer.
2230 Valid values are nil, t, `head', `first', `last', an integer or a
2231 predicate. See Info node `(gnus)Customizing Articles'."
2232 :version "23.0" ;; No Gnus
2233 :group 'gnus-article
2234 ;; :link '(custom-manual "(gnus)Customizing Articles")
2237 (defun gnus-article-toggle-truncate-lines (&optional arg)
2238 "Toggle whether to fold or truncate long lines in article the buffer.
2239 If ARG is non-nil and not a number, toggle
2240 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2241 long lines iff arg is positive."
2244 ((and (numberp arg) (> arg 0))
2245 (setq gnus-article-truncate-lines t))
2247 (setq gnus-article-truncate-lines nil))
2249 (setq gnus-article-truncate-lines
2250 (not gnus-article-truncate-lines))))
2251 (gnus-with-article-buffer
2253 ((and (numberp arg) (> arg 0))
2254 (setq truncate-lines nil))
2256 (setq truncate-lines t)))
2257 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2258 ;; `toggle-truncate-lines' needs an argument.
2259 (toggle-truncate-lines)))
2261 (defun gnus-article-treat-body-boundary ()
2262 "Place a boundary line at the end of the headers."
2264 (when (and gnus-body-boundary-delimiter
2265 (> (length gnus-body-boundary-delimiter) 0))
2266 (gnus-with-article-headers
2267 (goto-char (point-max))
2268 (let ((start (point)))
2269 (insert "X-Boundary: ")
2270 (gnus-add-text-properties start (point) '(invisible t intangible t))
2272 (while (>= (1- (window-width)) (length str))
2273 (setq str (concat str gnus-body-boundary-delimiter)))
2274 (substring str 0 (1- (window-width))))
2276 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2278 (defun article-fill-long-lines ()
2279 "Fill lines that are wider than the window width."
2282 (let ((inhibit-read-only t)
2283 (width (window-width (get-buffer-window (current-buffer)))))
2286 (let ((adaptive-fill-mode nil)) ;Why? -sm
2289 (when (>= (current-column) (min fill-column width))
2290 (narrow-to-region (min (1+ (point)) (point-max))
2292 (let ((goback (point-marker)))
2293 (fill-paragraph nil)
2294 (goto-char (marker-position goback)))
2296 (forward-line 1)))))))
2298 (defun article-capitalize-sentences ()
2299 "Capitalize the first word in each sentence."
2302 (let ((inhibit-read-only t)
2303 (paragraph-start "^[\n\^L]"))
2307 (forward-sentence)))))
2309 (defun article-remove-cr ()
2310 "Remove trailing CRs and then translate remaining CRs into LFs."
2313 (let ((inhibit-read-only t))
2314 (goto-char (point-min))
2315 (while (re-search-forward "\r+$" nil t)
2316 (replace-match "" t t))
2317 (goto-char (point-min))
2318 (while (search-forward "\r" nil t)
2319 (replace-match "\n" t t)))))
2321 (defun article-remove-trailing-blank-lines ()
2322 "Remove all trailing blank lines from the article."
2325 (let ((inhibit-read-only t))
2326 (goto-char (point-max))
2330 (while (and (not (bobp))
2331 (looking-at "^[ \t]*$")
2332 (not (gnus-annotation-in-region-p
2333 (point) (point-at-eol))))
2338 (defvar gnus-face-properties-alist)
2340 (defun article-display-face (&optional force)
2341 "Display any Face headers in the header."
2342 (interactive (list 'force))
2343 (let ((wash-face-p buffer-read-only))
2344 (gnus-with-article-headers
2345 ;; When displaying parts, this function can be called several times on
2346 ;; the same article, without any intended toggle semantic (as typing `W
2347 ;; D d' would have). So face deletion must occur only when we come from
2348 ;; an interactive command, that is when the *Article* buffer is
2350 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2351 (gnus-delete-images 'face)
2352 (let ((from (message-fetch-field "from"))
2354 (save-current-buffer
2355 (when (and wash-face-p
2356 (gnus-buffer-live-p gnus-original-article-buffer)
2357 (not (re-search-forward "^Face:[\t ]*" nil t)))
2358 (set-buffer gnus-original-article-buffer))
2360 (mail-narrow-to-head)
2362 ;; Check whether this face is censored.
2363 (not (and gnus-article-x-face-too-ugly
2365 (setq from (message-fetch-field "from")))
2366 (string-match gnus-article-x-face-too-ugly
2368 (while (gnus-article-goto-header "Face")
2369 (push (mail-header-field-value) faces)))))
2371 (goto-char (point-min))
2373 (unless (setq from (gnus-article-goto-header "from"))
2376 (insert " [no `from' set]\n"))
2378 (when (setq png (gnus-convert-face-to-png (pop faces)))
2380 (apply 'gnus-create-image png 'png t
2381 (cdr (assq 'png gnus-face-properties-alist))))
2383 (gnus-add-wash-type 'face)
2384 (gnus-add-image 'face image)
2385 (gnus-put-image image nil 'face))))))))))
2387 (defun article-display-x-face (&optional force)
2388 "Look for an X-Face header and display it if present."
2389 (interactive (list 'force))
2390 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2391 (gnus-with-article-headers
2392 ;; Delete the old process, if any.
2393 (when (process-status "article-x-face")
2394 (delete-process "article-x-face"))
2395 ;; See the comment in `article-display-face'.
2396 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2397 ;; We have already displayed X-Faces, so we remove them
2399 (gnus-delete-images 'xface)
2401 (let ((from (message-fetch-field "from"))
2403 (save-current-buffer
2404 (when (and wash-face-p
2405 (gnus-buffer-live-p gnus-original-article-buffer)
2406 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2407 ;; If type `W f', use gnus-original-article-buffer,
2408 ;; otherwise use the current buffer because displaying
2409 ;; RFC822 parts calls this function too.
2410 (set-buffer gnus-original-article-buffer))
2412 (mail-narrow-to-head)
2413 (and gnus-article-x-face-command
2415 ;; Check whether this face is censored.
2416 (not (and gnus-article-x-face-too-ugly
2418 (setq from (message-fetch-field "from")))
2419 (string-match gnus-article-x-face-too-ugly
2421 (while (gnus-article-goto-header "X-Face")
2422 (push (mail-header-field-value) x-faces)))))
2424 ;; We display the face.
2425 (cond ((functionp gnus-article-x-face-command)
2426 ;; The command is a lisp function, so we call it.
2427 (mapc gnus-article-x-face-command x-faces))
2428 ((stringp gnus-article-x-face-command)
2429 ;; The command is a string, so we interpret the command
2430 ;; as a, well, command, and fork it off.
2431 (let ((process-connection-type nil))
2432 (gnus-set-process-query-on-exit-flag
2434 "article-x-face" nil shell-file-name
2435 shell-command-switch gnus-article-x-face-command)
2437 ;; Sending multiple EOFs to xv doesn't work,
2438 ;; so we only do a single external face.
2440 (insert (car x-faces))
2441 (process-send-region "article-x-face"
2442 (point-min) (point-max)))
2443 (process-send-eof "article-x-face")))
2445 (error "`%s' set to `%s' is not a function"
2446 gnus-article-x-face-command
2447 'gnus-article-x-face-command)))))))))
2449 (defun article-decode-mime-words ()
2450 "Decode all MIME-encoded words in the article."
2452 (gnus-with-article-buffer
2453 (let ((inhibit-point-motion-hooks t)
2454 (mail-parse-charset gnus-newsgroup-charset)
2455 (mail-parse-ignored-charsets
2456 (with-current-buffer gnus-summary-buffer
2457 gnus-newsgroup-ignored-charsets)))
2458 (mail-decode-encoded-word-region (point-min) (point-max)))))
2460 (defun article-decode-charset (&optional prompt)
2461 "Decode charset-encoded text in the article.
2462 If PROMPT (the prefix), prompt for a coding system to use."
2464 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2465 (inhibit-read-only t)
2466 (mail-parse-charset gnus-newsgroup-charset)
2467 (mail-parse-ignored-charsets
2468 (save-excursion (condition-case nil
2469 (set-buffer gnus-summary-buffer)
2471 gnus-newsgroup-ignored-charsets))
2472 ct cte ctl charset format)
2475 (article-narrow-to-head)
2476 (setq ct (message-fetch-field "Content-Type" t)
2477 cte (message-fetch-field "Content-Transfer-Encoding" t)
2478 ctl (and ct (mail-header-parse-content-type ct))
2481 (mm-read-coding-system "Charset to decode: "))
2483 (mail-content-type-get ctl 'charset)))
2484 format (and ctl (mail-content-type-get ctl 'format)))
2486 (setq cte (mail-header-strip cte)))
2487 (if (and ctl (not (string-match "/" (car ctl))))
2489 (goto-char (point-max)))
2492 (narrow-to-region (point) (point-max))
2493 (when (and (eq mail-parse-charset 'gnus-decoded)
2494 (eq (mm-body-7-or-8) '8bit))
2495 ;; The text code could have been decoded.
2496 (setq charset mail-parse-charset))
2497 (when (and (or (not ctl)
2498 (equal (car ctl) "text/plain"))
2499 (not format)) ;; article with format will decode later.
2501 charset (and cte (intern (downcase
2502 (gnus-strip-whitespace cte))))
2505 (defun article-decode-encoded-words ()
2506 "Remove encoded-word encoding from headers."
2507 (let ((inhibit-point-motion-hooks t)
2508 (mail-parse-charset gnus-newsgroup-charset)
2509 (mail-parse-ignored-charsets
2510 (save-excursion (condition-case nil
2511 (set-buffer gnus-summary-buffer)
2513 gnus-newsgroup-ignored-charsets))
2514 (inhibit-read-only t)
2516 (goto-char (point-min))
2517 (when (search-forward "\n\n" nil 'move)
2524 (memq (char-after) '(?\t ? )))))
2525 (setq start (point))
2527 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2528 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2529 (funcall gnus-decode-address-function start end)
2530 (funcall gnus-decode-header-function start end))
2531 (goto-char (setq end start)))))
2533 (defun article-decode-group-name ()
2534 "Decode group names in Newsgroups, Followup-To and Xref headers."
2535 (let ((inhibit-point-motion-hooks t)
2536 (inhibit-read-only t)
2537 (method (gnus-find-method-for-group gnus-newsgroup-name))
2539 (when (and (or gnus-group-name-charset-method-alist
2540 gnus-group-name-charset-group-alist)
2541 (gnus-buffer-live-p gnus-original-article-buffer))
2543 (article-narrow-to-head)
2544 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2545 (with-current-buffer gnus-original-article-buffer
2546 (goto-char (point-min)))
2547 (setq regexp (concat "^" header
2548 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2549 (while (re-search-forward regexp nil t)
2550 (replace-match (save-match-data
2551 (gnus-decode-newsgroups
2552 ;; XXX how to use data in article buffer?
2553 (with-current-buffer gnus-original-article-buffer
2554 (re-search-forward regexp nil t)
2556 gnus-newsgroup-name method))
2558 (goto-char (point-min)))))))
2560 (autoload 'idna-to-unicode "idna")
2562 (defun article-decode-idna-rhs ()
2563 "Decode IDNA strings in RHS in various headers in current buffer.
2564 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2565 Mail-Reply-To: and Mail-Followup-To:."
2568 (let ((inhibit-point-motion-hooks t)
2569 (inhibit-read-only t))
2570 (article-narrow-to-head)
2571 (goto-char (point-min))
2572 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2574 (when (save-match-data
2575 (and (setq ace (match-string 1))
2577 (and (re-search-backward "^[^ \t]" nil t)
2578 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2579 (setq unicode (idna-to-unicode ace))))
2580 (unless (string= ace unicode)
2581 (replace-match unicode nil nil nil 1)))))))))
2583 (defun article-de-quoted-unreadable (&optional force read-charset)
2584 "Translate a quoted-printable-encoded article.
2585 If FORCE, decode the article whether it is marked as quoted-printable
2587 If READ-CHARSET, ask for a coding system."
2588 (interactive (list 'force current-prefix-arg))
2590 (let ((inhibit-read-only t) type charset)
2591 (if (gnus-buffer-live-p gnus-original-article-buffer)
2592 (with-current-buffer gnus-original-article-buffer
2594 (gnus-fetch-field "content-transfer-encoding"))
2595 (let* ((ct (gnus-fetch-field "content-type"))
2596 (ctl (and ct (mail-header-parse-content-type ct))))
2597 (setq charset (and ctl
2598 (mail-content-type-get ctl 'charset)))
2599 (if (stringp charset)
2600 (setq charset (intern (downcase charset)))))))
2602 (setq charset (mm-read-coding-system "Charset: " charset)))
2604 (setq charset gnus-newsgroup-charset))
2606 (and type (let ((case-fold-search t))
2607 (string-match "quoted-printable" type))))
2609 (quoted-printable-decode-region
2610 (point) (point-max) (mm-charset-to-coding-system charset))))))
2612 (defun article-de-base64-unreadable (&optional force read-charset)
2613 "Translate a base64 article.
2614 If FORCE, decode the article whether it is marked as base64 not.
2615 If READ-CHARSET, ask for a coding system."
2616 (interactive (list 'force current-prefix-arg))
2618 (let ((inhibit-read-only t) type charset)
2619 (if (gnus-buffer-live-p gnus-original-article-buffer)
2620 (with-current-buffer gnus-original-article-buffer
2622 (gnus-fetch-field "content-transfer-encoding"))
2623 (let* ((ct (gnus-fetch-field "content-type"))
2624 (ctl (and ct (mail-header-parse-content-type ct))))
2625 (setq charset (and ctl
2626 (mail-content-type-get ctl 'charset)))
2627 (if (stringp charset)
2628 (setq charset (intern (downcase charset)))))))
2630 (setq charset (mm-read-coding-system "Charset: " charset)))
2632 (setq charset gnus-newsgroup-charset))
2634 (and type (let ((case-fold-search t))
2635 (string-match "base64" type))))
2638 (narrow-to-region (point) (point-max))
2639 (base64-decode-region (point-min) (point-max))
2640 (mm-decode-coding-region
2641 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2646 (defun article-decode-HZ ()
2647 "Translate a HZ-encoded article."
2651 (let ((inhibit-read-only t))
2652 (rfc1843-decode-region (point-min) (point-max)))))
2654 (defun article-unsplit-urls ()
2655 "Remove the newlines that some other mailers insert into URLs."
2658 (let ((inhibit-read-only t))
2659 (goto-char (point-min))
2660 (while (re-search-forward
2661 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2662 (replace-match "\\1\\3" t)))
2663 (when (interactive-p)
2664 (gnus-treat-article nil))))
2667 (defun article-wash-html (&optional read-charset)
2668 "Format an HTML article.
2669 If READ-CHARSET, ask for a coding system. If it is a number, the
2670 charset defined in `gnus-summary-show-article-charset-alist' is used."
2673 (let ((inhibit-read-only t)
2676 (if (or (and (numberp read-charset)
2680 gnus-summary-show-article-charset-alist))))
2681 (setq charset (mm-read-coding-system "Charset: ")))
2682 (let ((gnus-summary-show-article-charset-alist
2683 (list (cons 1 charset))))
2684 (with-current-buffer gnus-summary-buffer
2685 (gnus-summary-show-article 1)))
2686 (error "No charset is given"))
2687 (when (gnus-buffer-live-p gnus-original-article-buffer)
2688 (with-current-buffer gnus-original-article-buffer
2689 (let* ((ct (gnus-fetch-field "content-type"))
2690 (ctl (and ct (mail-header-parse-content-type ct))))
2691 (setq charset (and ctl
2692 (mail-content-type-get ctl 'charset)))
2693 (when (stringp charset)
2694 (setq charset (intern (downcase charset)))))))
2696 (setq charset gnus-newsgroup-charset)))
2698 (save-window-excursion
2700 (narrow-to-region (point) (point-max))
2701 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2702 (entry (assq func mm-text-html-washer-alist)))
2704 (setq func (cdr entry)))
2709 (apply (car func) (cdr func))))))))))
2712 (declare-function w3-region "ext:w3-display" (st nd))
2714 (defun gnus-article-wash-html-with-w3 ()
2715 "Wash the current buffer with w3."
2717 (let ((w3-strict-width (window-width))
2718 (url-standalone-mode t)
2719 (url-gateway-unplugged t)
2720 (w3-honor-stylesheets nil))
2722 (w3-region (point-min) (point-max))
2726 (declare-function w3m-region "ext:w3m" (start end &optional url charset))
2728 (defun gnus-article-wash-html-with-w3m ()
2729 "Wash the current buffer with emacs-w3m."
2731 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2732 w3m-force-redisplay)
2733 (w3m-region (point-min) (point-max)))
2734 (when (and mm-inline-text-html-with-w3m-keymap
2735 (boundp 'w3m-minor-mode-map)
2737 (add-text-properties
2738 (point-min) (point-max)
2739 (list 'keymap w3m-minor-mode-map
2740 ;; Put the mark meaning this part was rendered by emacs-w3m.
2741 'mm-inline-text-html-with-w3m t))))
2743 (defvar charset) ;; Bound by `article-wash-html'.
2745 (defun gnus-article-wash-html-with-w3m-standalone ()
2746 "Wash the current buffer with w3m."
2747 (if (mm-w3m-standalone-supports-m17n-p)
2749 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2751 (setq charset 'iso-8859-1))
2752 (let ((coding-system-for-write charset)
2753 (coding-system-for-read charset))
2754 (call-process-region
2755 (point-min) (point-max)
2756 "w3m" t t nil "-dump" "-T" "text/html"
2757 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2758 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2760 (defvar gnus-article-browse-html-temp-list nil
2761 "List of temporary files created by `gnus-article-browse-html-parts'.
2762 Internal variable.")
2764 (defcustom gnus-article-browse-delete-temp 'ask
2765 "What to do with temporary files from `gnus-article-browse-html-parts'.
2766 If nil, don't delete temporary files. If it is t, delete them on
2767 exit from the summary buffer. If it is the symbol `file', query
2768 on each file, if it is `ask' ask once when exiting from the
2770 :group 'gnus-article
2771 :version "23.0" ;; No Gnus
2772 :type '(choice (const :tag "Don't delete" nil)
2773 (const :tag "Don't ask" t)
2774 (const :tag "Ask" ask)
2775 (const :tag "Ask for each file" file)))
2777 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2779 (defun gnus-article-browse-delete-temp-files (&optional how)
2780 "Delete temp-files created by `gnus-article-browse-html-parts'."
2781 (when (and gnus-article-browse-html-temp-list
2783 (setq how gnus-article-browse-delete-temp)))
2784 (when (and (eq how 'ask)
2786 "Delete all %s temporary HTML file(s)? "
2787 (length gnus-article-browse-html-temp-list)))
2789 (dolist (file gnus-article-browse-html-temp-list)
2790 (when (and (file-exists-p file)
2792 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2794 (format "Delete temporary HTML file `%s'? " file))))
2795 (delete-file file)))
2796 ;; Also remove file from the list when not deleted or if file doesn't
2798 (setq gnus-article-browse-html-temp-list nil))
2799 gnus-article-browse-html-temp-list)
2801 (defun gnus-article-browse-html-parts (list)
2802 "View all \"text/html\" parts from LIST.
2803 Recurse into multiparts."
2804 ;; Internal function used by `gnus-article-browse-html-article'.
2806 ;; Find and show the html-parts.
2807 (dolist (handle list)
2808 ;; If HTML, show it:
2809 (when (listp handle)
2810 (cond ((and (bufferp (car handle))
2811 (string-match "text/html" (car (mm-handle-type handle))))
2812 (let ((tmp-file (mm-make-temp-file
2813 ;; Do we need to care for 8.3 filenames?
2815 (charset (mail-content-type-get (mm-handle-type handle)
2818 ;; Add a meta html tag to specify charset.
2819 (mm-with-unibyte-buffer
2820 (insert (with-current-buffer (mm-handle-buffer handle)
2821 (if (eq charset 'gnus-decoded)
2822 (mm-encode-coding-string
2824 (setq charset 'utf-8))
2826 (setq charset (format "\
2827 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">"
2829 (goto-char (point-min))
2830 (let ((case-fold-search t))
2831 (cond (;; Don't modify existing meta tag.
2832 (re-search-forward "\
2833 <meta[\t\n\r ]+http-equiv=\"content-type\"[^>]+>"
2835 ((re-search-forward "<head>[\t\n\r ]*" nil t)
2836 (insert charset "\n"))
2838 (re-search-forward "\
2839 <html\\(?:[\t\n\r ]+[^>]+\\|[\t\n\r ]*\\)>[\t\n\r ]*"
2841 (insert "<head>\n" charset "\n</head>\n"))))
2842 (mm-write-region (point-min) (point-max)
2843 tmp-file nil nil nil 'binary t))
2844 (mm-save-part-to-file handle tmp-file))
2845 (add-to-list 'gnus-article-browse-html-temp-list tmp-file)
2846 (add-hook 'gnus-summary-prepare-exit-hook
2847 'gnus-article-browse-delete-temp-files)
2848 (add-hook 'gnus-exit-gnus-hook
2850 (gnus-article-browse-delete-temp-files t)))
2851 ;; FIXME: Warn if there's an <img> tag?
2852 (browse-url-of-file tmp-file)
2854 ;; If multipart, recurse
2855 ((and (stringp (car handle))
2856 (string-match "^multipart/" (car handle))
2859 (gnus-article-browse-html-parts handle))))))))
2862 ;; FIXME: Documentation in texi/gnus.texi missing.
2863 (defun gnus-article-browse-html-article ()
2864 "View \"text/html\" parts of the current article with a WWW browser.
2866 Warning: Spammers use links to images in HTML articles to verify
2867 whether you have read the message. As
2868 `gnus-article-browse-html-article' passes the unmodified HTML
2869 content to the browser without eliminating these \"web bugs\" you
2870 should only use it for mails from trusted senders.
2872 If you alwasy want to display HTML part in the browser, set
2873 `mm-text-html-renderer' to nil."
2874 ;; Cf. `mm-w3m-safe-url-regexp'
2876 (save-window-excursion
2877 ;; Open raw article and select the buffer
2878 (gnus-summary-show-article t)
2879 (gnus-summary-select-article-buffer)
2880 (let ((parts (mm-dissect-buffer t t)))
2881 ;; If singlepart, enforce a list.
2882 (when (and (bufferp (car parts))
2883 (stringp (car (mm-handle-type parts))))
2884 (setq parts (list parts)))
2886 (unless (gnus-article-browse-html-parts parts)
2887 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
2888 (gnus-summary-show-article))))
2890 (defun article-hide-list-identifiers ()
2891 "Remove list identifies from the Subject header.
2892 The `gnus-list-identifiers' variable specifies what to do."
2894 (let ((inhibit-point-motion-hooks t)
2895 (regexp (if (consp gnus-list-identifiers)
2896 (mapconcat 'identity gnus-list-identifiers " *\\|")
2897 gnus-list-identifiers))
2898 (inhibit-read-only t))
2902 (article-narrow-to-head)
2903 (goto-char (point-min))
2904 (while (re-search-forward
2905 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2907 (delete-region (match-beginning 2) (match-end 0))
2908 (beginning-of-line))
2909 (when (re-search-forward
2910 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2911 (delete-region (match-beginning 1) (match-end 1))))))))
2913 (defun article-hide-pem (&optional arg)
2914 "Toggle hiding of any PEM headers and signatures in the current article.
2915 If given a negative prefix, always show; if given a positive prefix,
2917 (interactive (gnus-article-hidden-arg))
2918 (unless (gnus-article-check-hidden-text 'pem arg)
2920 (let ((inhibit-read-only t) end)
2921 (goto-char (point-min))
2922 ;; Hide the horrendously ugly "header".
2923 (when (and (search-forward
2924 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2926 (setq end (1+ (match-beginning 0))))
2927 (gnus-add-wash-type 'pem)
2928 (gnus-article-hide-text-type
2930 (if (search-forward "\n\n" nil t)
2934 ;; Hide the trailer as well
2935 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2937 (gnus-article-hide-text-type
2938 (match-beginning 0) (match-end 0) 'pem)))))))
2940 (defun article-strip-banner ()
2941 "Strip the banners specified by the `banner' group parameter and by
2942 `gnus-article-address-banner-alist'."
2946 (let ((inhibit-point-motion-hooks t))
2947 (when (gnus-parameter-banner gnus-newsgroup-name)
2948 (article-really-strip-banner
2949 (gnus-parameter-banner gnus-newsgroup-name)))
2950 (when gnus-article-address-banner-alist
2951 ;; Note that the From header is decoded here, so it is
2952 ;; required that the *-extract-address-components function
2953 ;; supports non-ASCII text.
2954 (let ((from (save-restriction
2956 (article-narrow-to-head)
2957 (mail-fetch-field "from"))))
2960 (cadr (funcall gnus-extract-address-components
2963 (dolist (pair gnus-article-address-banner-alist)
2964 (when (string-match (car pair) from)
2966 (article-really-strip-banner (cdr pair)))))))))))))
2968 (defun article-really-strip-banner (banner)
2969 "Strip the banner specified by the argument."
2972 (let ((inhibit-point-motion-hooks t)
2973 (gnus-signature-limit nil)
2974 (inhibit-read-only t))
2977 ((eq banner 'signature)
2978 (when (gnus-article-narrow-to-signature)
2981 (delete-region (point) (point-max))))
2983 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2984 (while (re-search-forward banner nil t)
2985 (delete-region (match-beginning 0) (match-end 0)))))
2987 (while (re-search-forward banner nil t)
2988 (delete-region (match-beginning 0) (match-end 0)))))))))
2990 (defun article-babel ()
2991 "Translate article using an online translation service."
2994 (gnus-with-article-buffer
2995 (when (article-goto-body)
2996 (let* ((start (point))
2998 (orig (buffer-substring start end))
2999 (trans (babel-as-string orig)))
3001 (narrow-to-region start end)
3002 (delete-region start end)
3005 (defun article-hide-signature (&optional arg)
3006 "Hide the signature in the current article.
3007 If given a negative prefix, always show; if given a positive prefix,
3009 (interactive (gnus-article-hidden-arg))
3010 (unless (gnus-article-check-hidden-text 'signature arg)
3013 (let ((inhibit-read-only t))
3014 (when (gnus-article-narrow-to-signature)
3015 (gnus-article-hide-text-type
3016 (point-min) (point-max) 'signature))))))
3017 (gnus-set-mode-line 'article))
3019 (defun article-strip-headers-in-body ()
3020 "Strip offensive headers from bodies."
3024 (let ((case-fold-search t))
3025 (when (looking-at "x-no-archive:")
3026 (gnus-delete-line)))))
3028 (defun article-strip-leading-blank-lines ()
3029 "Remove all blank lines from the beginning of the article."
3032 (let ((inhibit-point-motion-hooks t)
3033 (inhibit-read-only t))
3034 (when (article-goto-body)
3035 (while (and (not (eobp))
3036 (looking-at "[ \t]*$"))
3037 (gnus-delete-line))))))
3039 (defun article-narrow-to-head ()
3040 "Narrow the buffer to the head of the message.
3041 Point is left at the beginning of the narrowed-to region."
3043 (goto-char (point-min))
3044 (if (search-forward "\n\n" nil 1)
3047 (goto-char (point-min)))
3049 (defun article-goto-body ()
3050 "Place point at the start of the body."
3051 (goto-char (point-min))
3053 ;; This variable is only bound when dealing with separate
3055 (article-goto-body-goes-to-point-min-p
3057 ((search-forward "\n\n" nil t)
3060 (goto-char (point-max))
3063 (defun article-strip-multiple-blank-lines ()
3064 "Replace consecutive blank lines with one empty line."
3067 (let ((inhibit-point-motion-hooks t)
3068 (inhibit-read-only t))
3069 ;; First make all blank lines empty.
3071 (while (re-search-forward "^[ \t]+$" nil t)
3072 (unless (gnus-annotation-in-region-p
3073 (match-beginning 0) (match-end 0))
3074 (replace-match "" nil t)))
3075 ;; Then replace multiple empty lines with a single empty line.
3077 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3078 (unless (gnus-annotation-in-region-p
3079 (match-beginning 0) (match-end 0))
3080 (delete-region (match-beginning 1) (match-end 1)))))))
3082 (defun article-strip-leading-space ()
3083 "Remove all white space from the beginning of the lines in the article."
3086 (let ((inhibit-point-motion-hooks t)
3087 (inhibit-read-only t))
3089 (while (re-search-forward "^[ \t]+" nil t)
3090 (replace-match "" t t)))))
3092 (defun article-strip-trailing-space ()
3093 "Remove all white space from the end of the lines in the article."
3096 (let ((inhibit-point-motion-hooks t)
3097 (inhibit-read-only t))
3099 (while (re-search-forward "[ \t]+$" nil t)
3100 (replace-match "" t t)))))
3102 (defun article-strip-blank-lines ()
3103 "Strip leading, trailing and multiple blank lines."
3105 (article-strip-leading-blank-lines)
3106 (article-remove-trailing-blank-lines)
3107 (article-strip-multiple-blank-lines))
3109 (defun article-strip-all-blank-lines ()
3110 "Strip all blank lines."
3113 (let ((inhibit-point-motion-hooks t)
3114 (inhibit-read-only t))
3116 (while (re-search-forward "^[ \t]*\n" nil t)
3117 (replace-match "" t t)))))
3119 (defun gnus-article-narrow-to-signature ()
3120 "Narrow to the signature; return t if a signature is found, else nil."
3121 (let ((inhibit-point-motion-hooks t))
3122 (when (gnus-article-search-signature)
3124 ;; Check whether we have some limits to what we consider
3125 ;; to be a signature.
3126 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3127 (list gnus-signature-limit)))
3129 (while (setq limit (pop limits))
3130 (if (or (and (integerp limit)
3131 (< (- (point-max) (point)) limit))
3133 (< (count-lines (point) (point-max)) limit))
3134 (and (functionp limit)
3136 (and (stringp limit)
3137 (not (re-search-forward limit nil t))))
3138 () ; This limit did not succeed.
3142 (narrow-to-region (point) (point-max))
3145 (defun gnus-article-search-signature ()
3146 "Search the current buffer for the signature separator.
3147 Put point at the beginning of the signature separator."
3148 (let ((cur (point)))
3149 (goto-char (point-max))
3150 (if (if (stringp gnus-signature-separator)
3151 (re-search-backward gnus-signature-separator nil t)
3152 (let ((seps gnus-signature-separator))
3154 (not (re-search-backward (car seps) nil t)))
3161 (defun gnus-article-hidden-arg ()
3162 "Return the current prefix arg as a number, or 0 if no prefix."
3163 (list (if current-prefix-arg
3164 (prefix-numeric-value current-prefix-arg)
3167 (defun gnus-article-check-hidden-text (type arg)
3168 "Return nil if hiding is necessary.
3169 Arg can be nil or a number. nil and positive means hide, negative
3170 means show, 0 means toggle."
3173 (let ((hide (gnus-article-hidden-text-p type)))
3179 (gnus-article-show-hidden-text type)
3182 (if (eq hide 'hidden)
3184 (gnus-article-show-hidden-text type)
3188 (defun gnus-article-hidden-text-p (type)
3189 "Say whether the current buffer contains hidden text of type TYPE."
3190 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3192 (not (get-text-property pos 'invisible))
3193 (not (get-text-property pos 'dummy-invisible)))
3195 (text-property-any (1+ pos) (point-max) 'article-type type)))
3200 (defun gnus-article-show-hidden-text (type &optional dummy)
3201 "Show all hidden text of type TYPE.
3202 Originally it is hide instead of DUMMY."
3203 (let ((inhibit-read-only t)
3204 (inhibit-point-motion-hooks t))
3205 (gnus-remove-text-properties-when
3207 (point-min) (point-max)
3208 (cons 'article-type (cons type
3209 gnus-hidden-properties)))
3210 (gnus-delete-wash-type type)))
3212 (defconst article-time-units
3213 `((year . ,(* 365.25 24 60 60))
3214 (week . ,(* 7 24 60 60))
3215 (day . ,(* 24 60 60))
3219 "Mapping from time units to seconds.")
3221 (defun gnus-article-forward-header ()
3222 "Move point to the start of the next header.
3223 If the current header is a continuation header, this can be several
3228 (if (looking-at "[ \t]+[^ \t]")
3232 (defun article-date-ut (&optional type highlight)
3233 "Convert DATE date to universal time in the current article.
3234 If TYPE is `local', convert to local time; if it is `lapsed', output
3235 how much time has lapsed since DATE. For `lapsed', the value of
3236 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3237 should replace the \"Date:\" one, or should be added below it."
3238 (interactive (list 'ut t))
3239 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3240 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3244 (article-lapsed-timer
3248 (case-fold-search t)
3249 (inhibit-read-only t)
3250 (inhibit-point-motion-hooks t)
3251 pos date bface eface)
3255 (goto-char (point-min))
3256 (while (or (setq date (get-text-property (setq pos (point))
3258 (when (setq pos (next-single-property-change
3259 (point) 'original-date))
3260 (setq date (get-text-property pos 'original-date))
3262 (narrow-to-region pos (or (text-property-any pos (point-max)
3265 (goto-char (point-min))
3266 (when (re-search-forward tdate-regexp nil t)
3267 (setq bface (get-text-property (point-at-bol) 'face)
3268 eface (get-text-property (1- (point-at-eol)) 'face)))
3269 (goto-char (point-min))
3271 ;; Delete any old Date headers.
3272 (while (re-search-forward date-regexp nil t)
3274 (delete-region (point-at-bol) (progn
3275 (gnus-article-forward-header)
3277 (delete-region (point-at-bol) (progn
3278 (gnus-article-forward-header)
3281 (setq pos (point))))
3282 (when (and (not pos)
3283 (re-search-forward tdate-regexp nil t))
3285 (gnus-goto-char pos)
3286 (insert (article-make-date-line date (or type 'ut)))
3292 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3293 (put-text-property (match-beginning 1) (1+ (match-end 1))
3295 (put-text-property (match-beginning 2) (match-end 2)
3297 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3298 (goto-char (point-max))
3301 (defun article-make-date-line (date type)
3302 "Return a DATE line of TYPE."
3303 (unless (memq type '(local ut original user iso8601 lapsed english))
3304 (error "Unknown conversion type: %s" type))
3306 (let ((time (date-to-time date)))
3308 ;; Convert to the local timezone.
3310 (concat "Date: " (message-make-date time)))
3311 ;; Convert to Universal Time.
3316 (let* ((e (parse-time-string date))
3317 (tm (apply 'encode-time e))
3319 (ls (- (cadr tm) (car (current-time-zone time)))))
3320 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3321 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3325 ;; Get the original date from the article.
3326 ((eq type 'original)
3327 (concat "Date: " (if (string-match "\n+$" date)
3328 (substring date 0 (match-beginning 0))
3330 ;; Let the user define the format.
3332 (let ((format (or (condition-case nil
3333 (with-current-buffer gnus-summary-buffer
3334 gnus-article-time-format)
3336 gnus-article-time-format)))
3337 (if (functionp format)
3338 (funcall format time)
3339 (concat "Date: " (format-time-string format time)))))
3342 (let ((tz (car (current-time-zone time))))
3345 (format-time-string "%Y%m%dT%H%M%S" time)
3346 (format "%s%02d%02d"
3347 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3348 (/ (% (abs tz) 3600) 60)))))
3349 ;; Do an X-Sent lapsed format.
3351 ;; If the date is seriously mangled, the timezone functions are
3352 ;; liable to bug out, so we ignore all errors.
3353 (let* ((now (current-time))
3354 (real-time (subtract-time now time))
3355 (real-sec (and real-time
3356 (+ (* (float (car real-time)) 65536)
3358 (sec (and real-time (abs real-sec)))
3368 ;; This is a bit convoluted, but basically we go
3369 ;; through the time units for years, weeks, etc,
3370 ;; and divide things to see whether that results
3371 ;; in positive answers.
3374 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3375 ;; The (remaining) seconds are too few to
3376 ;; be divided into this time unit.
3378 ;; It's big enough, so we output it.
3379 (setq sec (- sec (* num (cdr unit))))
3381 (concat (if prev ", " "") (int-to-string
3383 " " (symbol-name (car unit))
3384 (if (> num 1) "s" ""))
3386 article-time-units "")
3387 ;; If dates are odd, then it might appear like the
3388 ;; article was sent in the future.
3391 " in the future"))))))
3392 ;; Display the date in proper English
3394 (let ((dtime (decode-time time)))
3397 (number-to-string (nth 3 dtime))
3398 (let ((digit (% (nth 3 dtime) 10)))
3400 ((memq (nth 3 dtime) '(11 12 13)) "th")
3406 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3408 (number-to-string (nth 5 dtime))
3410 (format "%02d" (nth 2 dtime))
3412 (format "%02d" (nth 1 dtime)))))))
3414 (format "Date: %s (from Gnus)" date))))
3416 (defun article-date-local (&optional highlight)
3417 "Convert the current article date to the local timezone."
3418 (interactive (list t))
3419 (article-date-ut 'local highlight))
3421 (defun article-date-english (&optional highlight)
3422 "Convert the current article date to something that is proper English."
3423 (interactive (list t))
3424 (article-date-ut 'english highlight))
3426 (defun article-date-original (&optional highlight)
3427 "Convert the current article date to what it was originally.
3428 This is only useful if you have used some other date conversion
3429 function and want to see what the date was before converting."
3430 (interactive (list t))
3431 (article-date-ut 'original highlight))
3433 (defun article-date-lapsed (&optional highlight)
3434 "Convert the current article date to time lapsed since it was sent."
3435 (interactive (list t))
3436 (article-date-ut 'lapsed highlight))
3438 (defun article-update-date-lapsed ()
3439 "Function to be run from a timer to update the lapsed time line."
3441 (let (deactivate-mark)
3446 (set-buffer (window-buffer w))
3447 (when (eq major-mode 'gnus-article-mode)
3448 (let ((mark (point-marker)))
3449 (goto-char (point-min))
3450 (when (re-search-forward "^X-Sent:" nil t)
3451 (article-date-lapsed t))
3452 (goto-char (marker-position mark))
3453 (move-marker mark nil))))
3456 (defun gnus-start-date-timer (&optional n)
3457 "Start a timer to update the X-Sent header in the article buffers.
3458 The numerical prefix says how frequently (in seconds) the function
3463 (gnus-stop-date-timer)
3464 (setq article-lapsed-timer
3465 (run-at-time 1 n 'article-update-date-lapsed)))
3467 (defun gnus-stop-date-timer ()
3468 "Stop the X-Sent timer."
3470 (when article-lapsed-timer
3471 (nnheader-cancel-timer article-lapsed-timer)
3472 (setq article-lapsed-timer nil)))
3474 (defun article-date-user (&optional highlight)
3475 "Convert the current article date to the user-defined format.
3476 This format is defined by the `gnus-article-time-format' variable."
3477 (interactive (list t))
3478 (article-date-ut 'user highlight))
3480 (defun article-date-iso8601 (&optional highlight)
3481 "Convert the current article date to ISO8601."
3482 (interactive (list t))
3483 (article-date-ut 'iso8601 highlight))
3485 (defmacro gnus-article-save-original-date (&rest forms)
3486 "Save the original date as a text property and evaluate FORMS."
3487 `(let* ((case-fold-search t)
3489 (goto-char (point-min))
3490 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3493 (date (when (and start
3494 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3496 (buffer-substring-no-properties start
3497 (match-beginning 0)))))
3498 (goto-char (point-max))
3499 (skip-chars-backward "\n")
3500 (put-text-property (point-min) (point) 'original-date date)
3502 (goto-char (point-max))
3503 (skip-chars-backward "\n")
3504 (put-text-property (point-min) (point) 'original-date date)))
3506 ;; (defun article-show-all ()
3507 ;; "Show all hidden text in the article buffer."
3510 ;; (let ((inhibit-read-only t))
3511 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3513 (defun article-remove-leading-whitespace ()
3514 "Remove excessive whitespace from all headers."
3518 (let ((inhibit-read-only t))
3519 (article-narrow-to-head)
3520 (goto-char (point-min))
3521 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3522 (delete-region (match-beginning 1) (match-end 1)))))))
3524 (defun article-emphasize (&optional arg)
3525 "Emphasize text according to `gnus-emphasis-alist'."
3526 (interactive (gnus-article-hidden-arg))
3527 (unless (gnus-article-check-hidden-text 'emphasis arg)
3531 (with-current-buffer gnus-summary-buffer
3532 gnus-article-emphasis-alist)
3534 gnus-emphasis-alist))
3535 (inhibit-read-only t)
3536 (props (append '(article-type emphasis)
3537 gnus-hidden-properties))
3538 regexp elem beg invisible visible face)
3541 (while (setq elem (pop alist))
3543 (setq regexp (car elem)
3544 invisible (nth 1 elem)
3545 visible (nth 2 elem)
3547 (while (re-search-forward regexp nil t)
3548 (when (and (match-beginning visible) (match-beginning invisible))
3549 (gnus-article-hide-text
3550 (match-beginning invisible) (match-end invisible) props)
3551 (gnus-article-unhide-text-type
3552 (match-beginning visible) (match-end visible) 'emphasis)
3553 (gnus-put-overlay-excluding-newlines
3554 (match-beginning visible) (match-end visible) 'face face)
3555 (gnus-add-wash-type 'emphasis)
3556 (goto-char (match-end invisible)))))))))
3558 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3559 "Setup newsgroup emphasis alist."
3560 (unless gnus-article-emphasis-alist
3561 (let ((name (and gnus-newsgroup-name
3562 (gnus-group-real-name gnus-newsgroup-name))))
3563 (make-local-variable 'gnus-article-emphasis-alist)
3564 (setq gnus-article-emphasis-alist
3566 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3567 (while (setq elem (pop alist))
3568 (when (and name (string-match (car elem) name))
3570 highlight (copy-sequence (cdr elem)))))
3572 (copy-sequence highlight-words)
3573 (if gnus-newsgroup-name
3574 (copy-sequence (gnus-group-find-parameter
3575 gnus-newsgroup-name 'highlight-words t)))
3576 gnus-emphasis-alist)))))
3578 (defvar gnus-summary-article-menu)
3579 (defvar gnus-summary-post-menu)
3581 ;;; Saving functions.
3583 (defun gnus-article-save (save-buffer file &optional num)
3584 "Save the currently selected article."
3585 (when (or (get gnus-default-article-saver :headers)
3586 (not gnus-save-all-headers))
3587 ;; Remove headers according to `gnus-saved-headers' or the value
3588 ;; of the `:headers' property that the saver function might have.
3589 (let ((gnus-visible-headers
3590 (or (symbol-value (get gnus-default-article-saver :headers))
3591 gnus-saved-headers gnus-visible-headers))
3592 (gnus-article-buffer save-buffer))
3594 (set-buffer save-buffer)
3595 (article-hide-headers 1 t))))
3596 (save-window-excursion
3597 (if (not gnus-default-article-saver)
3598 (error "No default saver is defined")
3599 ;; !!! Magic! The saving functions all save
3600 ;; `gnus-save-article-buffer' (or so they think), but we
3601 ;; bind that variable to our save-buffer.
3602 (set-buffer gnus-article-buffer)
3603 (let* ((gnus-save-article-buffer save-buffer)
3606 ((not gnus-prompt-before-saving) 'default)
3607 ((eq gnus-prompt-before-saving 'always) nil)
3609 (gnus-number-of-articles-to-be-saved
3610 (when (eq gnus-prompt-before-saving t)
3612 (set-buffer gnus-article-current-summary)
3613 (funcall gnus-default-article-saver filename)))))
3615 (defun gnus-read-save-file-name (prompt &optional filename
3616 function group headers variable
3619 (funcall function group headers (symbol-value variable)))
3624 ((eq filename 'default)
3630 (when (symbol-value dir-var)
3631 (setq default-name (expand-file-name
3632 (file-name-nondirectory default-name)
3633 (symbol-value dir-var))))
3634 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3637 (if (and gnus-number-of-articles-to-be-saved
3638 (> gnus-number-of-articles-to-be-saved 1))
3639 (format "these %d articles"
3640 gnus-number-of-articles-to-be-saved)
3643 ;; Let the split methods have their say.
3645 ;; No split name was found.
3648 (concat prompt " (default "
3649 (file-name-nondirectory default-name) "): ")
3650 (file-name-directory default-name)
3652 ;; A single group name is returned.
3653 ((stringp split-name)
3655 (funcall function split-name headers
3656 (symbol-value variable)))
3658 (concat prompt " (default "
3659 (file-name-nondirectory default-name) "): ")
3660 (file-name-directory default-name)
3662 ;; A single split name was found
3663 ((= 1 (length split-name))
3664 (let* ((name (expand-file-name
3666 gnus-article-save-directory))
3667 (dir (cond ((file-directory-p name)
3668 (file-name-as-directory name))
3669 ((file-exists-p name) name)
3670 (t gnus-article-save-directory))))
3672 (concat prompt " (default " name "): ")
3674 ;; A list of splits was found.
3676 (setq split-name (nreverse split-name))
3678 (let ((file-name-history
3679 (nconc split-name file-name-history)))
3683 (concat prompt " (`M-p' for defaults): ")
3684 gnus-article-save-directory
3686 gnus-article-save-directory)))
3687 (car (push result file-name-history)))))))
3688 ;; Create the directory.
3689 (gnus-make-directory (file-name-directory file))
3690 ;; If we have read a directory, we append the default file name.
3691 (when (file-directory-p file)
3692 (setq file (expand-file-name (file-name-nondirectory
3694 (file-name-as-directory file))))
3695 ;; Possibly translate some characters.
3696 (nnheader-translate-file-chars file))))))
3697 (gnus-make-directory (file-name-directory result))
3699 (set variable result))
3701 (set dir-var (file-name-directory result)))
3704 (defun gnus-article-archive-name (group)
3705 "Return the first instance of an \"Archive-name\" in the current buffer."
3706 (let ((case-fold-search t))
3707 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3708 (nnheader-concat gnus-article-save-directory
3709 (match-string 1)))))
3711 (defun gnus-article-nndoc-name (group)
3712 "If GROUP is an nndoc group, return the name of the parent group."
3713 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3714 (gnus-group-get-parameter group 'save-article-group)))
3716 (defun gnus-summary-save-in-rmail (&optional filename)
3717 "Append this article to Rmail file.
3718 Optional argument FILENAME specifies file name.
3719 Directory to save to is default to `gnus-article-save-directory'."
3720 (setq filename (gnus-read-save-file-name
3721 "Save %s in rmail file" filename
3722 gnus-rmail-save-name gnus-newsgroup-name
3723 gnus-current-headers 'gnus-newsgroup-last-rmail))
3724 (gnus-eval-in-buffer-window gnus-save-article-buffer
3728 (gnus-output-to-rmail filename))))
3731 (defun gnus-summary-save-in-mail (&optional filename)
3732 "Append this article to Unix mail file.
3733 Optional argument FILENAME specifies file name.
3734 Directory to save to is default to `gnus-article-save-directory'."
3735 (setq filename (gnus-read-save-file-name
3736 "Save %s in Unix mail file" filename
3737 gnus-mail-save-name gnus-newsgroup-name
3738 gnus-current-headers 'gnus-newsgroup-last-mail))
3739 (gnus-eval-in-buffer-window gnus-save-article-buffer
3743 (if (and (file-readable-p filename)
3744 (file-regular-p filename)
3745 (mail-file-babyl-p filename))
3746 (rmail-output-to-rmail-file filename t)
3747 (gnus-output-to-mail filename)))))
3750 (put 'gnus-summary-save-in-file :decode t)
3751 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3752 (defun gnus-summary-save-in-file (&optional filename overwrite)
3753 "Append this article to file.
3754 Optional argument FILENAME specifies file name.
3755 Directory to save to is default to `gnus-article-save-directory'."
3756 (setq filename (gnus-read-save-file-name
3757 "Save %s in file" filename
3758 gnus-file-save-name gnus-newsgroup-name
3759 gnus-current-headers 'gnus-newsgroup-last-file))
3760 (gnus-eval-in-buffer-window gnus-save-article-buffer
3764 (when (and overwrite
3765 (file-exists-p filename))
3766 (delete-file filename))
3767 (gnus-output-to-file filename))))
3770 (put 'gnus-summary-write-to-file :decode t)
3771 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3772 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3773 (defun gnus-summary-write-to-file (&optional filename)
3774 "Write this article to a file, overwriting it if the file exists.
3775 Optional argument FILENAME specifies file name.
3776 The directory to save in defaults to `gnus-article-save-directory'."
3777 (setq filename (gnus-read-save-file-name
3778 "Save %s in file" filename
3779 gnus-file-save-name gnus-newsgroup-name
3780 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3781 (gnus-summary-save-in-file filename t))
3783 (put 'gnus-summary-save-body-in-file :decode t)
3784 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3785 "Append this article body to a file.
3786 Optional argument FILENAME specifies file name.
3787 The directory to save in defaults to `gnus-article-save-directory'."
3788 (setq filename (gnus-read-save-file-name
3789 "Save %s body in file" filename
3790 gnus-file-save-name gnus-newsgroup-name
3791 gnus-current-headers 'gnus-newsgroup-last-file))
3792 (gnus-eval-in-buffer-window gnus-save-article-buffer
3796 (when (article-goto-body)
3797 (narrow-to-region (point) (point-max)))
3798 (when (and overwrite
3799 (file-exists-p filename))
3800 (delete-file filename))
3801 (gnus-output-to-file filename))))
3804 (put 'gnus-summary-write-body-to-file :decode t)
3805 (put 'gnus-summary-write-body-to-file
3806 :function 'gnus-summary-save-body-in-file)
3807 (defun gnus-summary-write-body-to-file (&optional filename)
3808 "Write this article body to a file, overwriting it if the file exists.
3809 Optional argument FILENAME specifies file name.
3810 The directory to save in defaults to `gnus-article-save-directory'."
3811 (setq filename (gnus-read-save-file-name
3812 "Save %s body in file" filename
3813 gnus-file-save-name gnus-newsgroup-name
3814 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3815 (gnus-summary-save-body-in-file filename t))
3817 (defun gnus-summary-save-in-pipe (&optional command)
3818 "Pipe this article to subprocess."
3820 (cond ((and (eq command 'default)
3821 gnus-last-shell-command)
3822 gnus-last-shell-command)
3827 "Shell command on %s: "
3828 (if (and gnus-number-of-articles-to-be-saved
3829 (> gnus-number-of-articles-to-be-saved 1))
3830 (format "these %d articles"
3831 gnus-number-of-articles-to-be-saved)
3833 gnus-last-shell-command))))
3834 (when (string-equal command "")
3835 (if gnus-last-shell-command
3836 (setq command gnus-last-shell-command)
3837 (error "A command is required")))
3838 (gnus-eval-in-buffer-window gnus-article-buffer
3841 (shell-command-on-region (point-min) (point-max) command nil)))
3842 (setq gnus-last-shell-command command))
3844 (defun gnus-summary-pipe-to-muttprint (&optional command)
3845 "Pipe this article to muttprint."
3846 (setq command (read-string
3847 "Print using command: " gnus-summary-muttprint-program
3848 nil gnus-summary-muttprint-program))
3849 (gnus-summary-save-in-pipe command))
3851 ;;; Article file names when saving.
3853 (defun gnus-capitalize-newsgroup (newsgroup)
3854 "Capitalize NEWSGROUP name."
3855 (when (not (zerop (length newsgroup)))
3856 (concat (char-to-string (upcase (aref newsgroup 0)))
3857 (substring newsgroup 1))))
3859 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3860 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3861 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3862 Otherwise, it is like ~/News/news/group/num."
3865 (concat (if (gnus-use-long-file-name 'not-save)
3866 (gnus-capitalize-newsgroup newsgroup)
3867 (gnus-newsgroup-directory-form newsgroup))
3868 "/" (int-to-string (mail-header-number headers)))
3869 gnus-article-save-directory)))
3871 (string-equal (file-name-directory default)
3872 (file-name-directory last-file))
3873 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3875 (or last-file default))))
3877 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3878 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3879 If variable `gnus-use-long-file-name' is non-nil, it is
3880 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3883 (concat (if (gnus-use-long-file-name 'not-save)
3885 (gnus-newsgroup-directory-form newsgroup))
3886 "/" (int-to-string (mail-header-number headers)))
3887 gnus-article-save-directory)))
3889 (string-equal (file-name-directory default)
3890 (file-name-directory last-file))
3891 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3893 (or last-file default))))
3895 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3896 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3897 If variable `gnus-use-long-file-name' is non-nil, it is
3898 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3901 (if (gnus-use-long-file-name 'not-save)
3904 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3906 gnus-article-save-directory)))
3908 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3909 "Generate file name from sender."
3910 (let ((from (mail-header-from headers)))
3912 (if (and from (string-match "\\([^ <]+\\)@" from))
3913 (match-string 1 from)
3915 gnus-article-save-directory)))
3917 (defun article-verify-x-pgp-sig ()
3920 (if (gnus-buffer-live-p gnus-original-article-buffer)
3921 (let ((sig (with-current-buffer gnus-original-article-buffer
3922 (gnus-fetch-field "X-PGP-Sig")))
3926 (mml2015-clear-verify-function))
3928 (insert-buffer-substring gnus-original-article-buffer)
3929 (setq items (split-string sig))
3930 (message-narrow-to-head)
3931 (let ((inhibit-point-motion-hooks t)
3932 (case-fold-search t))
3933 ;; Don't verify multiple headers.
3934 (setq headers (mapconcat (lambda (header)
3936 (mail-fetch-field header)
3938 (split-string (nth 1 items) ",") "")))
3939 (delete-region (point-min) (point-max))
3940 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3941 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3946 (if (looking-at "^-")
3949 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3950 (insert "Version: " (car items) "\n\n")
3951 (insert (mapconcat 'identity (cddr items) "\n"))
3952 (insert "\n-----END PGP SIGNATURE-----\n")
3953 (let ((mm-security-handle (list (format "multipart/signed"))))
3954 (mml2015-clean-buffer)
3955 (let ((coding-system-for-write (or gnus-newsgroup-charset
3957 (funcall (mml2015-clear-verify-function)))
3959 (or (mm-handle-multipart-ctl-parameter
3960 mm-security-handle 'gnus-details)
3961 (mm-handle-multipart-ctl-parameter
3962 mm-security-handle 'gnus-info)))))
3964 (let ((inhibit-read-only t) bface eface)
3966 (message-narrow-to-head)
3967 (goto-char (point-max))
3969 (setq bface (get-text-property (point-at-bol) 'face)
3970 eface (get-text-property (1- (point-at-eol)) 'face))
3971 (message-remove-header "X-Gnus-PGP-Verify")
3972 (if (re-search-forward "^X-PGP-Sig:" nil t)
3974 (goto-char (point-max)))
3975 (narrow-to-region (point) (point))
3976 (insert "X-Gnus-PGP-Verify: " info "\n")
3977 (goto-char (point-min))
3980 (if (not (looking-at "^[ \t]"))
3984 (goto-char (point-min))
3985 (when (looking-at "\\([^:]+\\): *")
3986 (put-text-property (match-beginning 1) (1+ (match-end 1))
3988 (put-text-property (match-end 0) (point-max)
3989 'face eface)))))))))
3991 (defun article-verify-cancel-lock ()
3992 "Verify Cancel-Lock header."
3994 (if (gnus-buffer-live-p gnus-original-article-buffer)
3995 (canlock-verify gnus-original-article-buffer)))
4002 (setq afunc (car func)
4005 gfunc (intern (format "gnus-%s" func))))
4007 (when (fboundp afunc)
4008 `(lambda (&optional interactive &rest args)
4009 ,(documentation afunc t)
4010 (interactive (list t))
4012 (set-buffer gnus-article-buffer)
4014 (call-interactively ',afunc)
4015 (apply ',afunc args))))))))
4016 '(article-hide-headers
4017 article-verify-x-pgp-sig
4018 article-verify-cancel-lock
4019 article-hide-boring-headers
4020 article-treat-overstrike
4021 article-treat-ansi-sequences
4022 article-fill-long-lines
4023 article-capitalize-sentences
4025 article-remove-leading-whitespace
4026 article-display-x-face
4027 article-display-face
4028 article-de-quoted-unreadable
4029 article-de-base64-unreadable
4032 article-unsplit-urls
4033 article-hide-list-identifiers
4034 article-strip-banner
4037 article-hide-signature
4038 article-strip-headers-in-body
4039 article-remove-trailing-blank-lines
4040 article-strip-leading-blank-lines
4041 article-strip-multiple-blank-lines
4042 article-strip-leading-space
4043 article-strip-trailing-space
4044 article-strip-blank-lines
4045 article-strip-all-blank-lines
4047 article-date-english
4048 article-date-iso8601
4049 article-date-original
4051 article-decode-mime-words
4052 article-decode-charset
4053 article-decode-encoded-words
4057 article-treat-dumbquotes
4058 article-normalize-headers
4059 ;;(article-show-all . gnus-article-show-all-headers)
4063 ;;; Gnus article mode
4066 (put 'gnus-article-mode 'mode-class 'special)
4068 (set-keymap-parent gnus-article-mode-map widget-keymap)
4070 (gnus-define-keys gnus-article-mode-map
4071 " " gnus-article-goto-next-page
4072 "\177" gnus-article-goto-prev-page
4073 [delete] gnus-article-goto-prev-page
4074 [backspace] gnus-article-goto-prev-page
4075 "\C-c^" gnus-article-refer-article
4076 "h" gnus-article-show-summary
4077 "s" gnus-article-show-summary
4078 "\C-c\C-m" gnus-article-mail
4079 "?" gnus-article-describe-briefly
4080 "e" gnus-summary-edit-article
4081 "<" beginning-of-buffer
4083 "\C-c\C-i" gnus-info-find-node
4085 "R" gnus-article-reply-with-original
4086 "F" gnus-article-followup-with-original
4087 "\C-hk" gnus-article-describe-key
4088 "\C-hc" gnus-article-describe-key-briefly
4090 "\C-d" gnus-article-read-summary-keys
4091 "\M-*" gnus-article-read-summary-keys
4092 "\M-#" gnus-article-read-summary-keys
4093 "\M-^" gnus-article-read-summary-keys
4094 "\M-g" gnus-article-read-summary-keys)
4096 (substitute-key-definition
4097 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4099 (defun gnus-article-make-menu-bar ()
4100 (unless (boundp 'gnus-article-commands-menu)
4101 (gnus-summary-make-menu-bar))
4102 (gnus-turn-off-edit-menu 'article)
4103 (unless (boundp 'gnus-article-article-menu)
4105 gnus-article-article-menu gnus-article-mode-map ""
4107 ["Scroll forwards" gnus-article-goto-next-page t]
4108 ["Scroll backwards" gnus-article-goto-prev-page t]
4109 ["Show summary" gnus-article-show-summary t]
4110 ["Fetch Message-ID at point" gnus-article-refer-article t]
4111 ["Mail to address at point" gnus-article-mail t]
4112 ["Send a bug report" gnus-bug t]))
4115 gnus-article-treatment-menu gnus-article-mode-map ""
4116 ;; Fixme: this should use :active (and maybe :visible).
4118 ["Hide headers" gnus-article-hide-headers t]
4119 ["Hide signature" gnus-article-hide-signature t]
4120 ["Hide citation" gnus-article-hide-citation t]
4121 ["Treat overstrike" gnus-article-treat-overstrike t]
4122 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4123 ["Remove carriage return" gnus-article-remove-cr t]
4124 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4125 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4126 ["Remove base64" gnus-article-de-base64-unreadable t]
4127 ["Treat html" gnus-article-wash-html t]
4128 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4129 ["Decode HZ" gnus-article-decode-HZ t]))
4131 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4133 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4135 (gnus-run-hooks 'gnus-article-menu-hook)))
4137 (defun gnus-article-mode ()
4138 "Major mode for displaying an article.
4140 All normal editing commands are switched off.
4142 The following commands are available in addition to all summary mode
4144 \\<gnus-article-mode-map>
4145 \\[gnus-article-next-page]\t Scroll the article one page forwards
4146 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4147 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4148 \\[gnus-article-show-summary]\t Display the summary buffer
4149 \\[gnus-article-mail]\t Send a reply to the address near point
4150 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4151 \\[gnus-info-find-node]\t Go to the Gnus info node"
4153 (kill-all-local-variables)
4154 (gnus-simplify-mode-line)
4155 (setq mode-name "Article")
4156 (setq major-mode 'gnus-article-mode)
4157 (make-local-variable 'minor-mode-alist)
4158 (use-local-map gnus-article-mode-map)
4159 (when (gnus-visual-p 'article-menu 'menu)
4160 (gnus-article-make-menu-bar)
4161 (when gnus-summary-tool-bar-map
4162 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4163 (gnus-update-format-specifications nil 'article-mode)
4164 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4165 (set (make-local-variable 'gnus-page-broken) nil)
4166 (make-local-variable 'gnus-button-marker-list)
4167 (make-local-variable 'gnus-article-current-summary)
4168 (make-local-variable 'gnus-article-mime-handles)
4169 (make-local-variable 'gnus-article-decoded-p)
4170 (make-local-variable 'gnus-article-mime-handle-alist)
4171 (make-local-variable 'gnus-article-wash-types)
4172 (make-local-variable 'gnus-article-image-alist)
4173 (make-local-variable 'gnus-article-charset)
4174 (make-local-variable 'gnus-article-ignored-charsets)
4175 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4177 (set (make-local-variable 'nobreak-char-display) nil)
4178 (setq cursor-in-non-selected-windows nil)
4179 (setq truncate-lines gnus-article-truncate-lines)
4180 (gnus-set-default-directory)
4181 (buffer-disable-undo)
4182 (setq buffer-read-only t
4183 show-trailing-whitespace nil)
4184 (set-syntax-table gnus-article-mode-syntax-table)
4185 (mm-enable-multibyte)
4186 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4188 (defvar gnus-button-marker-list nil
4189 "Regexp matching any of the regexps from `gnus-button-alist'.
4190 Internal variable.")
4192 (defun gnus-article-setup-buffer ()
4193 "Initialize the article buffer."
4194 (let* ((name (if gnus-single-article-buffer "*Article*"
4195 (concat "*Article " gnus-newsgroup-name "*")))
4197 (progn (string-match "\\*Article" name)
4198 (concat " *Original Article"
4199 (substring name (match-end 0))))))
4200 (setq gnus-article-buffer name)
4201 (setq gnus-original-article-buffer original)
4202 (setq gnus-article-mime-handle-alist nil)
4203 (with-current-buffer gnus-summary-buffer
4204 ;; This might be a variable local to the summary buffer.
4205 (unless gnus-single-article-buffer
4206 (setq gnus-article-buffer name)
4207 (setq gnus-original-article-buffer original)
4208 (gnus-set-global-variables)))
4209 (gnus-article-setup-highlight-words)
4210 ;; Init original article buffer.
4212 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4213 (mm-enable-multibyte)
4214 (setq major-mode 'gnus-original-article-mode)
4215 (make-local-variable 'gnus-original-article))
4216 (if (and (get-buffer name)
4217 (with-current-buffer name
4218 (if gnus-article-edit-mode
4219 (if (y-or-n-p "Article mode edit in progress; discard? ")
4221 (set-buffer-modified-p nil)
4222 (gnus-kill-buffer name)
4225 (error "Action aborted"))
4229 (set (make-local-variable 'gnus-article-edit-mode) nil)
4230 (when gnus-article-mime-handles
4231 (mm-destroy-parts gnus-article-mime-handles)
4232 (setq gnus-article-mime-handles nil))
4233 ;; Set it to nil in article-buffer!
4234 (setq gnus-article-mime-handle-alist nil)
4235 (buffer-disable-undo)
4236 (setq buffer-read-only t)
4237 ;; This list just keeps growing if we don't reset it.
4238 (setq gnus-button-marker-list nil)
4239 (unless (eq major-mode 'gnus-article-mode)
4240 (gnus-article-mode))
4243 (set-buffer (gnus-get-buffer-create name))
4245 (make-local-variable 'gnus-summary-buffer)
4246 (setq gnus-summary-buffer
4247 (gnus-summary-buffer-name gnus-newsgroup-name))
4248 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4249 (current-buffer)))))
4251 ;; Set article window start at LINE, where LINE is the number of lines
4252 ;; from the head of the article.
4253 (defun gnus-article-set-window-start (&optional line)
4254 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4255 (when article-window
4259 (set-buffer gnus-article-buffer)
4260 (goto-char (point-min))
4263 (gnus-message 6 "Moved to bookmark")
4264 (search-forward "\n\n" nil t)
4268 (defun gnus-article-prepare (article &optional all-headers header)
4269 "Prepare ARTICLE in article mode buffer.
4270 ARTICLE should either be an article number or a Message-ID.
4271 If ARTICLE is an id, HEADER should be the article headers.
4272 If ALL-HEADERS is non-nil, no headers are hidden."
4274 ;; Make sure we start in a summary buffer.
4275 (unless (eq major-mode 'gnus-summary-mode)
4276 (set-buffer gnus-summary-buffer))
4277 (setq gnus-summary-buffer (current-buffer))
4278 (let* ((gnus-article (if header (mail-header-number header) article))
4279 (summary-buffer (current-buffer))
4280 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4281 (group gnus-newsgroup-name)
4284 (gnus-article-setup-buffer)
4285 (set-buffer gnus-article-buffer)
4286 ;; Deactivate active regions.
4287 (when (and (boundp 'transient-mark-mode)
4288 transient-mark-mode)
4289 (setq mark-active nil))
4290 (if (not (setq result (let ((inhibit-read-only t))
4291 (gnus-request-article-this-buffer
4293 ;; There is no such article.
4295 (when (and (numberp article)
4296 (not (memq article gnus-newsgroup-sparse)))
4297 (setq gnus-article-current
4298 (cons gnus-newsgroup-name article))
4299 (set-buffer gnus-summary-buffer)
4300 (setq gnus-current-article article)
4301 (if (and (memq article gnus-newsgroup-undownloaded)
4302 (not (gnus-online (gnus-find-method-for-group
4303 gnus-newsgroup-name))))
4305 (gnus-summary-set-agent-mark article)
4306 (message "Message marked for downloading"))
4307 (gnus-summary-mark-article article gnus-canceled-mark)
4308 (unless (memq article gnus-newsgroup-sparse)
4309 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4310 (if (or (eq result 'pseudo)
4311 (eq result 'nneething))
4314 (set-buffer summary-buffer)
4315 (push article gnus-newsgroup-history)
4316 (setq gnus-last-article gnus-current-article
4317 gnus-current-article 0
4318 gnus-current-headers nil
4319 gnus-article-current nil)
4320 (if (eq result 'nneething)
4321 (gnus-configure-windows 'summary)
4322 (gnus-configure-windows 'article))
4323 (gnus-set-global-variables))
4324 (let ((gnus-article-mime-handle-alist-1
4325 gnus-article-mime-handle-alist))
4326 (gnus-set-mode-line 'article)))
4327 ;; The result from the `request' was an actual article -
4328 ;; or at least some text that is now displayed in the
4330 (when (and (numberp article)
4331 (not (eq article gnus-current-article)))
4332 ;; Seems like a new article has been selected.
4333 ;; `gnus-current-article' must be an article number.
4335 (set-buffer summary-buffer)
4336 (push article gnus-newsgroup-history)
4337 (setq gnus-last-article gnus-current-article
4338 gnus-current-article article
4339 gnus-current-headers
4340 (gnus-summary-article-header gnus-current-article)
4341 gnus-article-current
4342 (cons gnus-newsgroup-name gnus-current-article))
4343 (unless (vectorp gnus-current-headers)
4344 (setq gnus-current-headers nil))
4345 (gnus-summary-goto-subject gnus-current-article)
4346 (when (gnus-summary-show-thread)
4347 ;; If the summary buffer really was folded, the
4348 ;; previous goto may not actually have gone to
4349 ;; the right article, but the thread root instead.
4351 (gnus-summary-goto-subject gnus-current-article))
4352 (gnus-run-hooks 'gnus-mark-article-hook)
4353 (gnus-set-mode-line 'summary)
4354 (when (gnus-visual-p 'article-highlight 'highlight)
4355 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4356 ;; Set the global newsgroup variables here.
4357 (gnus-set-global-variables)
4358 (setq gnus-have-all-headers
4359 (or all-headers gnus-show-all-headers))))
4361 (gnus-configure-windows 'article))
4362 (when (or (numberp article)
4364 (gnus-article-prepare-display)
4366 (goto-char (point-min))
4367 (when gnus-break-pages
4368 (gnus-narrow-to-page)))
4369 (let ((gnus-article-mime-handle-alist-1
4370 gnus-article-mime-handle-alist))
4371 (gnus-set-mode-line 'article))
4375 (set-window-point (get-buffer-window (current-buffer)) (point))
4376 (gnus-configure-windows 'article)
4380 (defun gnus-article-prepare-display ()
4381 "Make the current buffer look like a nice article."
4382 ;; Hooks for getting information from the article.
4383 ;; This hook must be called before being narrowed.
4384 (let ((gnus-article-buffer (current-buffer))
4386 (inhibit-read-only t))
4387 (unless (eq major-mode 'gnus-article-mode)
4388 (gnus-article-mode))
4389 (setq buffer-read-only nil
4390 gnus-article-wash-types nil
4391 gnus-article-image-alist nil)
4392 (gnus-run-hooks 'gnus-tmp-internal-hook)
4393 (when gnus-display-mime-function
4394 (funcall gnus-display-mime-function))
4395 (gnus-run-hooks 'gnus-article-prepare-hook)))
4398 ;;; Gnus Sticky Article Mode
4401 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4402 "Mode for sticky articles."
4403 ;; Release bindings that won't work.
4404 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4405 gnus-sticky-article-mode-map)
4406 (substitute-key-definition 'gnus-article-refer-article 'undefined
4407 gnus-sticky-article-mode-map)
4408 (dolist (k '("e" "h" "s" "F" "R"))
4409 (define-key gnus-sticky-article-mode-map k nil))
4410 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4411 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4412 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4413 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4415 (defun gnus-sticky-article (arg)
4416 "Make the current article sticky.
4417 If a prefix ARG is given, ask for a name for this sticky article buffer."
4419 (gnus-summary-show-thread)
4420 (gnus-summary-select-article nil nil 'pseudo)
4421 (let (new-art-buf-name)
4422 (gnus-eval-in-buffer-window gnus-article-buffer
4423 (setq new-art-buf-name
4427 (read-from-minibuffer "Sticky article buffer name: ")
4428 (gnus-with-article-headers
4429 (gnus-article-goto-header "subject")
4430 (setq new-art-buf-name
4431 (buffer-substring-no-properties
4432 (line-beginning-position) (line-end-position)))
4433 (goto-char (point-min))
4434 (gnus-article-goto-header "from")
4435 (setq new-art-buf-name
4437 new-art-buf-name ", "
4438 (buffer-substring-no-properties
4439 (line-beginning-position) (line-end-position))))
4440 (goto-char (point-min))
4441 (gnus-article-goto-header "date")
4442 (setq new-art-buf-name
4444 new-art-buf-name ", "
4445 (buffer-substring-no-properties
4446 (line-beginning-position) (line-end-position))))))
4448 (if (and (gnus-buffer-live-p new-art-buf-name)
4449 (with-current-buffer new-art-buf-name
4450 (eq major-mode 'gnus-sticky-article-mode)))
4451 (switch-to-buffer new-art-buf-name)
4452 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4453 (gnus-sticky-article-mode))
4454 (setq gnus-article-buffer new-art-buf-name))
4455 (gnus-summary-recenter)
4456 (gnus-summary-position-point))
4458 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4459 "Kill the given sticky article BUFFER.
4460 If none is given, assume the current buffer and kill it if it has
4461 `gnus-sticky-article-mode'."
4464 (setq buffer (current-buffer)))
4465 (with-current-buffer buffer
4466 (when (eq major-mode 'gnus-sticky-article-mode)
4467 (gnus-kill-buffer buffer))))
4469 (defun gnus-kill-sticky-article-buffers (arg)
4470 "Kill all sticky article buffers.
4471 If a prefix ARG is given, ask for confirmation."
4473 (dolist (buf (gnus-buffers))
4474 (with-current-buffer buf
4475 (when (eq major-mode 'gnus-sticky-article-mode)
4477 (gnus-kill-buffer buf)
4478 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4479 (gnus-kill-buffer buf)))))))
4482 ;;; Gnus MIME viewing functions
4485 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4486 "Format of the MIME buttons.
4488 Valid specifiers include:
4490 %T MIME type, along with additional info
4491 %n The `name' parameter
4492 %d The description, if any
4493 %l The length of the encoded part
4494 %p The part identifier number
4495 %e Dots if the part isn't displayed
4497 General format specifiers can also be used. See Info node
4498 `(gnus)Formatting Variables'.")
4500 (defvar gnus-mime-button-line-format-alist
4501 '((?t gnus-tmp-type ?s)
4502 (?T gnus-tmp-type-long ?s)
4503 (?n gnus-tmp-name ?s)
4504 (?d gnus-tmp-description ?s)
4506 (?l gnus-tmp-length ?d)
4507 (?e gnus-tmp-dots ?s)))
4509 (defvar gnus-mime-button-commands
4510 '((gnus-article-press-button "\r" "Toggle Display")
4511 (gnus-mime-view-part "v" "View Interactively...")
4512 (gnus-mime-view-part-as-type "t" "View As Type...")
4513 (gnus-mime-view-part-as-charset "C" "View As charset...")
4514 (gnus-mime-save-part "o" "Save...")
4515 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4516 (gnus-mime-replace-part "r" "Replace part")
4517 (gnus-mime-delete-part "d" "Delete part")
4518 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4519 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4520 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4521 (gnus-mime-view-part-externally "e" "View Externally")
4522 (gnus-mime-print-part "p" "Print")
4523 (gnus-mime-pipe-part "|" "Pipe To Command...")
4524 (gnus-mime-action-on-part "." "Take action on the part...")))
4526 (defun gnus-article-mime-part-status ()
4527 (if gnus-article-mime-handle-alist-1
4528 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4530 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4533 (defvar gnus-mime-button-map
4534 (let ((map (make-sparse-keymap)))
4535 (define-key map gnus-mouse-2 'gnus-article-push-button)
4536 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4537 (dolist (c gnus-mime-button-commands)
4538 (define-key map (cadr c) (car c)))
4542 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4544 ,@(mapcar (lambda (c)
4545 (vector (caddr c) (car c) :active t))
4546 gnus-mime-button-commands)))
4548 (defun gnus-mime-button-menu (event prefix)
4549 "Construct a context-sensitive menu of MIME commands."
4550 (interactive "e\nP")
4551 (save-window-excursion
4552 (let ((pos (event-start event)))
4553 (select-window (posn-window pos))
4554 (goto-char (posn-point pos))
4555 (gnus-article-check-buffer)
4556 (popup-menu gnus-mime-button-menu nil prefix))))
4558 (defun gnus-mime-view-all-parts (&optional handles)
4559 "View all the MIME parts."
4561 (with-current-buffer gnus-article-buffer
4562 (let ((handles (or handles gnus-article-mime-handles))
4563 (mail-parse-charset gnus-newsgroup-charset)
4564 (mail-parse-ignored-charsets
4565 (with-current-buffer gnus-summary-buffer
4566 gnus-newsgroup-ignored-charsets)))
4568 (mm-remove-parts handles)
4569 (goto-char (point-min))
4570 (or (search-forward "\n\n") (goto-char (point-max)))
4571 (let ((inhibit-read-only t))
4572 (delete-region (point) (point-max))
4573 (mm-display-parts handles))))))
4575 (defun gnus-article-jump-to-part (n)
4576 "Jump to MIME part N."
4578 (pop-to-buffer gnus-article-buffer)
4579 ;; FIXME: why is it necessary?
4581 (let ((parts (length gnus-article-mime-handle-alist)))
4584 (read-string ;; Emacs 21 doesn't have `read-number'.
4585 (format "Jump to part (2..%s): " parts)))))
4586 (unless (and (integerp n) (<= n parts) (>= n 1))
4589 (gnus-message 7 "Invalid part `%s', using %s instead."
4592 (gnus-message 9 "Jumping to part %s." n)
4593 (cond ((>= gnus-auto-select-part 1)
4594 (while (and (<= n parts)
4595 (not (gnus-article-goto-part n)))
4597 ((< gnus-auto-select-part 0)
4598 (while (and (>= n 1)
4599 (not (gnus-article-goto-part n)))
4602 (gnus-article-goto-part n)))))
4605 (defsubst gnus-article-edit-part (handles &optional current-id)
4606 "Edit an article in order to delete a mime part.
4607 This function is exclusively used by `gnus-mime-save-part-and-strip'
4608 and `gnus-mime-delete-part', and not provided at run-time normally."
4609 (gnus-article-edit-article
4611 (buffer-disable-undo)
4613 (let ((mail-parse-charset (or gnus-article-charset
4614 ',gnus-newsgroup-charset))
4615 (mail-parse-ignored-charsets
4616 (or gnus-article-ignored-charsets
4617 ',gnus-newsgroup-ignored-charsets))
4618 (mbl mml-buffer-list))
4619 (setq mml-buffer-list nil)
4620 (insert-buffer-substring gnus-original-article-buffer)
4621 (mime-to-mml ',handles)
4622 (setq gnus-article-mime-handles nil)
4623 (let ((mbl1 mml-buffer-list))
4624 (setq mml-buffer-list mbl)
4625 (set (make-local-variable 'mml-buffer-list) mbl1))
4626 (gnus-make-local-hook 'kill-buffer-hook)
4627 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4628 `(lambda (no-highlight)
4629 (let ((mail-parse-charset (or gnus-article-charset
4630 ',gnus-newsgroup-charset))
4631 (message-options message-options)
4632 (message-options-set-recipient)
4633 (mail-parse-ignored-charsets
4634 (or gnus-article-ignored-charsets
4635 ',gnus-newsgroup-ignored-charsets)))
4637 (mml-destroy-buffers)
4638 (remove-hook 'kill-buffer-hook
4639 'mml-destroy-buffers t)
4640 (kill-local-variable 'mml-buffer-list))
4641 (gnus-summary-edit-article-done
4642 ,(or (mail-header-references gnus-current-headers) "")
4643 ,(gnus-group-read-only-p)
4644 ,gnus-summary-buffer no-highlight))
4646 (gnus-article-edit-done)
4647 (gnus-summary-expand-window)
4648 (gnus-summary-show-article)
4649 (when (and current-id (integerp gnus-auto-select-part))
4650 (gnus-article-jump-to-part
4651 (if (text-property-any (point-min) (point-max)
4652 'gnus-part (+ current-id gnus-auto-select-part))
4653 (+ current-id gnus-auto-select-part)
4654 (with-current-buffer gnus-article-buffer
4655 (length gnus-article-mime-handle-alist)))))))
4657 (defun gnus-mime-replace-part (file)
4658 "Replace MIME part under point with an external body."
4659 ;; Useful if file has already been saved to disk
4663 (read-file-name "Replace MIME part with file: "
4664 (or mm-default-directory default-directory)
4666 (gnus-mime-save-part-and-strip file))
4668 (defun gnus-mime-save-part-and-strip (&optional file)
4669 "Save the MIME part under point then replace it with an external body.
4670 If FILE is given, use it for the external part."
4672 (gnus-article-check-buffer)
4673 (when (gnus-group-read-only-p)
4674 (error "The current group does not support deleting of parts"))
4675 (when (mm-complicated-handles gnus-article-mime-handles)
4677 The current article has a complicated MIME structure, giving up..."))
4678 (let* ((data (get-text-property (point) 'gnus-data))
4679 (id (get-text-property (point) 'gnus-part))
4681 (handles gnus-article-mime-handles))
4684 (and data (mm-save-part data "Delete MIME part and save to: "))))
4686 (with-current-buffer (mm-handle-buffer data)
4688 (insert "Content-Type: " (mm-handle-media-type data))
4689 (mml-insert-parameter-string (cdr (mm-handle-type data))
4691 ;; Add a filename for the sake of saving the part again.
4692 (mml-insert-parameter
4693 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4695 (insert "Content-ID: " (message-make-message-id) "\n")
4696 (insert "Content-Transfer-Encoding: binary\n")
4699 (cdr (mm-make-handle nil
4700 `("message/external-body"
4701 (access-type . "LOCAL-FILE")
4703 ;; (set-buffer gnus-summary-buffer)
4704 (gnus-article-edit-part handles id))))
4706 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4707 ;; parts...>') but with stripping would be nice.
4709 (defun gnus-mime-delete-part ()
4710 "Delete the MIME part under point.
4711 Replace it with some information about the removed part."
4713 (gnus-article-check-buffer)
4714 (when (gnus-group-read-only-p)
4715 (error "The current group does not support deleting of parts"))
4716 (when (mm-complicated-handles gnus-article-mime-handles)
4718 The current article has a complicated MIME structure, giving up..."))
4719 (when (or gnus-expert-user
4720 (gnus-yes-or-no-p "\
4721 Deleting parts may malfunction or destroy the article; continue? "))
4722 (let* ((data (get-text-property (point) 'gnus-data))
4723 (id (get-text-property (point) 'gnus-part))
4724 (handles gnus-article-mime-handles)
4727 (mail-decode-encoded-word-string (or (mm-handle-description data)
4730 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4732 (type (mm-handle-media-type data)))
4734 (error "No MIME part under point"))
4735 (with-current-buffer (mm-handle-buffer data)
4736 (let ((bsize (format "%s" (buffer-size))))
4741 "| The following attachment has been deleted:\n"
4743 "| Type: " type "\n"
4744 "| Filename: " filename "\n"
4745 "| Size (encoded): " bsize " Byte\n"
4746 "| Description: " description "\n"
4749 (cdr (mm-make-handle
4750 nil `("text/plain") nil nil
4752 (format "Deleted attachment (%s bytes)" bsize))))))
4753 ;; (set-buffer gnus-summary-buffer)
4754 (gnus-article-edit-part handles id))))
4756 (defun gnus-mime-save-part ()
4757 "Save the MIME part under point."
4759 (gnus-article-check-buffer)
4760 (let ((data (get-text-property (point) 'gnus-data)))
4762 (mm-save-part data))))
4764 (defun gnus-mime-pipe-part ()
4765 "Pipe the MIME part under point to a process."
4767 (gnus-article-check-buffer)
4768 (let ((data (get-text-property (point) 'gnus-data)))
4770 (mm-pipe-part data))))
4772 (defun gnus-mime-view-part ()
4773 "Interactively choose a viewing method for the MIME part under point."
4775 (gnus-article-check-buffer)
4776 (let ((data (get-text-property (point) 'gnus-data)))
4778 (setq gnus-article-mime-handles
4780 gnus-article-mime-handles (setq data (copy-sequence data))))
4781 (mm-interactively-view-part data))))
4783 (defun gnus-mime-view-part-as-type-internal ()
4784 (gnus-article-check-buffer)
4785 (let* ((handle (get-text-property (point) 'gnus-data))
4787 ;; Content-Type: foo/bar; name=...
4788 (mail-content-type-get (mm-handle-type handle) 'name)
4789 ;; Content-Disposition: attachment; filename=...
4790 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4791 (def-type (and name (mm-default-file-encoding name))))
4792 (or (and def-type (cons def-type 0))
4794 (equal (mm-handle-media-supertype handle) "text")
4795 '("text/plain" . 0))
4796 '("application/octet-stream" . 0))))
4798 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4799 "Choose a MIME media type, and view the part as such.
4800 If non-nil, PRED is a predicate to use during completion to limit the
4801 available media-types."
4805 (let ((default (gnus-mime-view-part-as-type-internal)))
4807 (format "View as MIME type (default %s): "
4809 (mapcar #'list (mailcap-mime-types))
4812 (gnus-article-check-buffer)
4813 (let ((handle (get-text-property (point) 'gnus-data)))
4815 (when (equal (mm-handle-media-type handle) "message/external-body")
4816 (unless (mm-handle-cache handle)
4817 (mm-extern-cache-contents handle))
4818 (setq handle (mm-handle-cache handle)))
4820 (mm-make-handle (mm-handle-buffer handle)
4821 (cons mime-type (cdr (mm-handle-type handle)))
4822 (mm-handle-encoding handle)
4823 (mm-handle-undisplayer handle)
4824 (mm-handle-disposition handle)
4825 (mm-handle-description handle)
4827 (mm-handle-id handle)))
4828 (setq gnus-article-mime-handles
4829 (mm-merge-handles gnus-article-mime-handles handle))
4830 (when (mm-handle-displayed-p handle)
4831 (mm-remove-part handle))
4832 (gnus-mm-display-part handle))))
4834 (defun gnus-mime-copy-part (&optional handle arg)
4835 "Put the MIME part under point into a new buffer.
4836 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4838 (interactive (list nil current-prefix-arg))
4839 (gnus-article-check-buffer)
4841 (setq handle (get-text-property (point) 'gnus-data)))
4843 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4845 (mail-content-type-get (mm-handle-disposition handle)
4847 contents dont-decode charset coding-system)
4848 (mm-with-unibyte-buffer
4849 (mm-insert-part handle)
4850 (setq contents (or (condition-case nil
4851 (mm-decompress-buffer filename nil 'sig)
4853 (setq dont-decode t)
4856 (setq filename (cond (filename (file-name-nondirectory filename))
4857 (dont-decode "*raw data*")
4862 (unless (setq charset (mail-content-type-get
4863 (mm-handle-type handle) 'charset))
4864 (unless (setq coding-system (mm-with-unibyte-buffer
4866 (mm-find-buffer-file-coding-system)))
4867 (setq charset gnus-newsgroup-charset))))
4869 (setq charset (or (cdr (assq arg
4870 gnus-summary-show-article-charset-alist))
4871 (mm-read-coding-system "Charset: ")))))
4872 (switch-to-buffer (generate-new-buffer filename))
4873 (if (or coding-system
4875 (setq coding-system (mm-charset-to-coding-system charset))
4876 (not (eq charset 'ascii))))
4878 (mm-enable-multibyte)
4879 (insert (mm-decode-coding-string contents coding-system))
4880 (setq buffer-file-coding-system
4881 (if (boundp 'last-coding-system-used)
4882 (symbol-value 'last-coding-system-used)
4884 (mm-disable-multibyte)
4886 (setq buffer-file-coding-system mm-binary-coding-system))
4887 ;; We do it this way to make `normal-mode' set the appropriate mode.
4890 (setq buffer-file-name (expand-file-name filename))
4892 (setq buffer-file-name nil))
4893 (goto-char (point-min)))))
4895 (defun gnus-mime-print-part (&optional handle filename)
4896 "Print the MIME part under point."
4897 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4898 (gnus-article-check-buffer)
4899 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4900 (contents (and handle (mm-get-part handle)))
4901 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4902 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4907 (mm-save-part-to-file handle file)
4908 (call-process shell-file-name nil
4909 (generate-new-buffer " *mm*")
4911 shell-command-switch
4913 printer file (mm-handle-type handle))))
4917 (gnus-print-buffer))
4918 (ps-despool filename)))))
4920 (defun gnus-mime-inline-part (&optional handle arg)
4921 "Insert the MIME part under point into the current buffer.
4922 Compressed files like .gz and .bz2 are decompressed."
4923 (interactive (list nil current-prefix-arg))
4924 (gnus-article-check-buffer)
4926 (setq handle (get-text-property (point) 'gnus-data)))
4929 (inhibit-read-only t)
4930 contents charset coding-system)
4931 (if (and (not arg) (mm-handle-undisplayer handle))
4932 (mm-remove-part handle)
4933 (mm-with-unibyte-buffer
4934 (mm-insert-part handle)
4936 (or (mm-decompress-buffer
4937 (or (mail-content-type-get (mm-handle-type handle)
4939 (mail-content-type-get (mm-handle-disposition handle)
4945 (unless (setq charset (mail-content-type-get
4946 (mm-handle-type handle) 'charset))
4947 (unless (setq coding-system
4948 (mm-with-unibyte-buffer
4950 (mm-find-buffer-file-coding-system)))
4951 (setq charset gnus-newsgroup-charset))))
4953 (if (mm-handle-undisplayer handle)
4954 (mm-remove-part handle))
4957 gnus-summary-show-article-charset-alist))
4958 (mm-read-coding-system "Charset: "))))
4960 (if (mm-handle-undisplayer handle)
4961 (mm-remove-part handle))))
4965 (if (or coding-system
4968 (mm-charset-to-coding-system charset))
4969 (not (eq coding-system 'ascii))))
4970 (mm-decode-coding-string contents coding-system)
4971 (mm-string-to-multibyte contents)))
4974 (defun gnus-mime-strip-charset-parameters (handle)
4975 "Strip charset parameters from HANDLE."
4976 (if (stringp (car handle))
4977 (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
4978 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
4979 "message/external-body")
4981 (unless (mm-handle-cache handle)
4982 (mm-extern-cache-contents handle))
4983 (mm-handle-cache handle))
4985 (charset (assq 'charset (cdr type))))
4987 (delq charset type)))))
4989 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4990 "Insert the MIME part under point into the current buffer using the
4992 (interactive (list nil current-prefix-arg))
4993 (gnus-article-check-buffer)
4994 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4995 (fun (get-text-property (point) 'gnus-callback))
4996 (gnus-newsgroup-ignored-charsets 'gnus-all)
4997 gnus-newsgroup-charset form preferred parts)
5001 (setq gnus-newsgroup-charset
5004 gnus-summary-show-article-charset-alist))
5005 (mm-read-coding-system "Charset: "))))
5006 (if (mm-handle-undisplayer handle)
5007 (mm-remove-part handle)))
5008 (gnus-mime-strip-charset-parameters handle)
5009 (when (and (consp (setq form (cdr-safe fun)))
5010 (setq form (ignore-errors
5011 (assq 'gnus-mime-display-alternative form)))
5012 (setq preferred (caddr form))
5014 (when (eq (car preferred) 'quote)
5015 (setq preferred (cadr preferred)))
5016 (not (equal preferred
5017 (get-text-property (point) 'gnus-data))))
5018 (setq parts (get-text-property (point) 'gnus-part))
5019 (setq parts (cdr (assq parts
5020 gnus-article-mime-handle-alist)))
5021 (equal (mm-handle-media-type parts) "multipart/alternative")
5022 (setq parts (reverse (cdr parts))))
5024 (list 'quote (or (cadr (member preferred parts))
5026 (funcall fun handle)))))
5028 (defun gnus-mime-view-part-externally (&optional handle)
5029 "View the MIME part under point with an external viewer."
5031 (gnus-article-check-buffer)
5032 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5033 (mm-user-display-methods nil)
5034 (mm-inlined-types nil)
5035 (mail-parse-charset gnus-newsgroup-charset)
5036 (mail-parse-ignored-charsets
5037 (with-current-buffer gnus-summary-buffer
5038 gnus-newsgroup-ignored-charsets))
5039 (type (mm-handle-media-type handle))
5040 (method (mailcap-mime-info type))
5041 (mm-enable-external t))
5042 (if (not (stringp method))
5043 (gnus-mime-view-part-as-type
5044 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
5046 (if (mm-handle-undisplayer handle)
5047 (mm-remove-part handle)
5048 (mm-display-part handle))))))
5050 (defun gnus-mime-view-part-internally (&optional handle)
5051 "View the MIME part under point with an internal viewer.
5052 If no internal viewer is available, use an external viewer."
5054 (gnus-article-check-buffer)
5055 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5056 (mm-inlined-types '(".*"))
5057 (mm-inline-large-images t)
5058 (mail-parse-charset gnus-newsgroup-charset)
5059 (mail-parse-ignored-charsets
5060 (with-current-buffer gnus-summary-buffer
5061 gnus-newsgroup-ignored-charsets))
5062 (inhibit-read-only t))
5063 (if (not (mm-inlinable-p handle))
5064 (gnus-mime-view-part-as-type
5065 nil (lambda (types) (mm-inlinable-p handle (car types))))
5067 (if (mm-handle-undisplayer handle)
5068 (mm-remove-part handle)
5069 (mm-display-part handle))))))
5071 (defun gnus-mime-action-on-part (&optional action)
5072 "Do something with the MIME attachment at \(point\)."
5074 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
5075 (gnus-article-check-buffer)
5076 (let ((action-pair (assoc action gnus-mime-action-alist)))
5078 (funcall (cdr action-pair)))))
5080 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5081 "Call FUNCTION on MIME part N.
5082 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5083 If INTERACTIVE, call FUNCTION interactivly."
5085 ;; Check whether the article is displayed.
5086 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5087 (setq window (get-buffer-window gnus-article-buffer t))
5088 (frame-visible-p (setq frame (window-frame window))))
5089 (error "No article is displayed"))
5090 (with-current-buffer gnus-article-buffer
5091 ;; Check whether the article displays the right contents.
5092 (unless (with-current-buffer gnus-summary-buffer
5093 (eq gnus-current-article (gnus-summary-article-number)))
5094 (error "You should select the right article first"))
5096 (setq n (prefix-numeric-value n))
5098 (setq n (or (get-text-property pt 'gnus-part)
5100 (get-text-property (1- pt) 'gnus-part))
5101 (get-text-property (prog2
5107 (or (and (setq pt (previous-single-property-change
5110 (next-single-property-change (point) 'gnus-part)
5114 ;; Check whether the specified part exists.
5115 (when (> n (length gnus-article-mime-handle-alist))
5116 (error "No such part")))
5119 ;; To select the window is needed so that the cursor
5120 ;; might be visible on the MIME button.
5121 (select-window (prog1
5123 (setq window (selected-window))
5124 ;; Article may be displayed in the other frame.
5125 (gnus-select-frame-set-input-focus
5128 (setq frame (selected-frame))))))
5129 (when (gnus-article-goto-part n)
5130 ;; We point the cursor and the arrow at the MIME button
5131 ;; when the `function' prompt the user for something.
5132 (let ((cursor-in-non-selected-windows t)
5133 (overlay-arrow-string "=>")
5134 (overlay-arrow-position (point-marker)))
5137 ((and no-handle interactive)
5138 (call-interactively function))
5144 (cdr (assq n gnus-article-mime-handle-alist))))
5147 (cdr (assq n gnus-article-mime-handle-alist)))))
5148 (set-marker overlay-arrow-position nil)
5149 (unless gnus-auto-select-part
5150 (gnus-select-frame-set-input-focus frame)
5151 (select-window window))))
5153 (if gnus-inhibit-mime-unbuttonizing
5154 ;; This is the default though the program shouldn't reach here.
5155 (error "No such part")
5156 ;; The part which doesn't have the MIME button is selected.
5157 ;; So, we display all the buttons and redo it.
5158 (let ((gnus-inhibit-mime-unbuttonizing t))
5159 (gnus-summary-show-article)
5160 (gnus-article-part-wrapper n function no-handle))))))
5162 (defun gnus-article-pipe-part (n)
5163 "Pipe MIME part N, which is the numerical prefix."
5165 (gnus-article-part-wrapper n 'mm-pipe-part))
5167 (defun gnus-article-save-part (n)
5168 "Save MIME part N, which is the numerical prefix."
5170 (gnus-article-part-wrapper n 'mm-save-part))
5172 (defun gnus-article-interactively-view-part (n)
5173 "View MIME part N interactively, which is the numerical prefix."
5175 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5177 (defun gnus-article-copy-part (n)
5178 "Copy MIME part N, which is the numerical prefix."
5180 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5182 (defun gnus-article-view-part-as-charset (n)
5183 "View MIME part N using a specified charset.
5184 N is the numerical prefix."
5186 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5188 (defun gnus-article-view-part-externally (n)
5189 "View MIME part N externally, which is the numerical prefix."
5191 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5193 (defun gnus-article-inline-part (n)
5194 "Inline MIME part N, which is the numerical prefix."
5196 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5198 (defun gnus-article-save-part-and-strip (n)
5199 "Save MIME part N and replace it with an external body.
5200 N is the numerical prefix."
5202 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5204 (defun gnus-article-replace-part (n)
5205 "Replace MIME part N with an external body.
5206 N is the numerical prefix."
5208 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5210 (defun gnus-article-delete-part (n)
5211 "Delete MIME part N and add some information about the removed part.
5212 N is the numerical prefix."
5214 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5216 (defun gnus-article-view-part-as-type (n)
5217 "Choose a MIME media type, and view part N as such.
5218 N is the numerical prefix."
5220 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5222 (defun gnus-article-mime-match-handle-first (condition)
5225 (dolist (ihandle gnus-article-mime-handle-alist)
5227 ((functionp condition)
5228 (funcall condition (cdr ihandle)))
5229 ((eq condition 'undisplayed)
5230 (not (or (mm-handle-undisplayer (cdr ihandle))
5231 (equal (mm-handle-media-type (cdr ihandle))
5232 "multipart/alternative"))))
5233 ((eq condition 'undisplayed-alternative)
5234 (not (mm-handle-undisplayer (cdr ihandle))))
5236 (gnus-article-goto-part (car ihandle))
5237 (or (not n) (< (car ihandle) n)))
5238 (setq n (car ihandle))))
5242 (defun gnus-article-view-part (&optional n)
5243 "View MIME part N, which is the numerical prefix."
5245 (with-current-buffer gnus-article-buffer
5246 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5247 gnus-article-mime-match-handle-function)))
5248 (when (> n (length gnus-article-mime-handle-alist))
5249 (error "No such part"))
5250 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5251 (when (gnus-article-goto-part n)
5252 (if (equal (car handle) "multipart/alternative")
5253 (gnus-article-press-button)
5254 (when (eq (gnus-mm-display-part handle) 'internal)
5255 (gnus-set-window-start)))))))
5257 (defsubst gnus-article-mime-total-parts ()
5258 (if (bufferp (car gnus-article-mime-handles))
5260 (1- (length gnus-article-mime-handles))))
5262 (defun gnus-mm-display-part (handle)
5263 "Display HANDLE and fix MIME button."
5264 (let ((id (get-text-property (point) 'gnus-part))
5266 (inhibit-read-only t))
5269 (let ((window (selected-window))
5270 (mail-parse-charset gnus-newsgroup-charset)
5271 (mail-parse-ignored-charsets
5272 (if (gnus-buffer-live-p gnus-summary-buffer)
5273 (with-current-buffer gnus-summary-buffer
5274 gnus-newsgroup-ignored-charsets)
5278 (let ((win (gnus-get-buffer-window (current-buffer) t))
5281 (select-window win))
5284 (if (mm-handle-displayed-p handle)
5285 ;; This will remove the part.
5286 (mm-display-part handle)
5288 (narrow-to-region (point)
5289 (if (eobp) (point) (1+ (point))))
5290 (mm-display-part handle)
5291 ;; We narrow to the part itself and
5292 ;; then call the treatment functions.
5293 (goto-char (point-min))
5295 (narrow-to-region (point) (point-max))
5298 (gnus-article-mime-total-parts)
5299 (mm-handle-media-type handle)))))
5300 (if (window-live-p window)
5301 (select-window window)))))
5304 (gnus-insert-mime-button
5305 handle id (list (mm-handle-displayed-p handle)))
5306 (goto-char point))))
5308 (defun gnus-article-goto-part (n)
5309 "Go to MIME part N."
5310 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5312 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5313 (let ((gnus-tmp-name
5314 (or (mail-content-type-get (mm-handle-type handle) 'name)
5315 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5316 (mail-content-type-get (mm-handle-type handle) 'url)
5318 (gnus-tmp-type (mm-handle-media-type handle))
5319 (gnus-tmp-description
5320 (mail-decode-encoded-word-string (or (mm-handle-description handle)
5323 (if (if displayed (car displayed)
5324 (mm-handle-displayed-p handle))
5326 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5328 gnus-tmp-type-long b e)
5329 (when (string-match ".*/" gnus-tmp-name)
5330 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5331 (setq gnus-tmp-type-long (concat gnus-tmp-type
5332 (and (not (equal gnus-tmp-name ""))
5333 (concat "; " gnus-tmp-name))))
5334 (unless (equal gnus-tmp-description "")
5335 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5340 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5341 `(keymap ,gnus-mime-button-map
5342 gnus-callback gnus-mm-display-part
5343 gnus-part ,gnus-tmp-id
5344 article-type annotation
5347 ;; Exclude a newline.
5350 (when gnus-article-button-face
5351 (gnus-overlay-put (gnus-make-overlay b e nil t)
5352 'face gnus-article-button-face))
5353 (widget-convert-button
5356 :action 'gnus-widget-press-button
5357 :button-keymap gnus-mime-button-map
5359 (lambda (widget/window &optional overlay pos)
5360 ;; Needed to properly clear the message due to a bug in
5361 ;; wid-edit (XEmacs only).
5362 (if (boundp 'help-echo-owns-message)
5363 (setq help-echo-owns-message t))
5365 "%S: %s the MIME part; %S: more options"
5366 (aref gnus-mouse-2 0)
5367 ;; XEmacs will get a single widget arg; Emacs 21 will get
5368 ;; window, overlay, position.
5369 (if (mm-handle-displayed-p
5371 (with-current-buffer (gnus-overlay-buffer overlay)
5372 (widget-get (widget-at (gnus-overlay-start overlay))
5374 (widget-get widget/window :mime-handle)))
5376 (aref gnus-down-mouse-3 0))))))
5378 (defun gnus-widget-press-button (elems el)
5379 (goto-char (widget-get elems :from))
5380 (gnus-article-press-button))
5382 (defvar gnus-displaying-mime nil)
5384 (defun gnus-display-mime (&optional ihandles)
5385 "Display the MIME parts."
5387 (save-selected-window
5388 (let ((window (get-buffer-window gnus-article-buffer))
5391 (select-window window)
5392 ;; We have to do this since selecting the window
5393 ;; may change the point. So we set the window point.
5394 (set-window-point window point)))
5395 (let ((handles ihandles)
5396 (inhibit-read-only t)
5399 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5400 (when gnus-article-emulate-mime
5401 (mm-uu-dissect-text-parts handles)))
5402 (gnus-article-emulate-mime
5403 (setq handles (mm-uu-dissect))))
5404 (when (and (not ihandles)
5405 (not gnus-displaying-mime))
5406 ;; Top-level call; we clean up.
5407 (when gnus-article-mime-handles
5408 (mm-destroy-parts gnus-article-mime-handles)
5409 (setq gnus-article-mime-handle-alist nil));; A trick.
5410 (setq gnus-article-mime-handles handles)
5411 ;; We allow users to glean info from the handles.
5412 (when gnus-article-mime-part-function
5413 (gnus-mime-part-function handles)))
5415 (or (not (stringp (car handles)))
5418 (when (and (not ihandles)
5419 (not gnus-displaying-mime))
5420 ;; Clean up for mime parts.
5422 (delete-region (point) (point-max)))
5423 (let ((gnus-displaying-mime t))
5424 (gnus-mime-display-part handles)))
5427 (narrow-to-region (point) (point-max))
5428 (gnus-treat-article nil 1 1)
5431 ;; Highlight the headers.
5435 (narrow-to-region (point-min) (point))
5436 (gnus-article-save-original-date
5437 (gnus-treat-article 'head)))))))
5438 ;; Cope with broken MIME messages.
5439 (goto-char (point-max))
5443 (defcustom gnus-mime-display-multipart-as-mixed nil
5444 "Display \"multipart\" parts as \"multipart/mixed\".
5446 If t, it overrides nil values of
5447 `gnus-mime-display-multipart-alternative-as-mixed' and
5448 `gnus-mime-display-multipart-related-as-mixed'."
5449 :group 'gnus-article-mime
5452 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5453 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5455 :group 'gnus-article-mime
5458 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5459 "Display \"multipart/related\" parts as \"multipart/mixed\".
5461 If displaying \"text/html\" is discouraged \(see
5462 `mm-discouraged-alternatives'\) images or other material inside a
5463 \"multipart/related\" part might be overlooked when this variable is nil."
5465 :group 'gnus-article-mime
5468 (defun gnus-mime-display-part (handle)
5470 ;; Maybe a broken MIME message.
5473 ((not (stringp (car handle)))
5474 (gnus-mime-display-single handle))
5475 ;; User-defined multipart
5476 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5477 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5479 ;; multipart/alternative
5480 ((and (equal (car handle) "multipart/alternative")
5481 (not (or gnus-mime-display-multipart-as-mixed
5482 gnus-mime-display-multipart-alternative-as-mixed)))
5483 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5484 (push (cons id handle) gnus-article-mime-handle-alist)
5485 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5486 ;; multipart/related
5487 ((and (equal (car handle) "multipart/related")
5488 (not (or gnus-mime-display-multipart-as-mixed
5489 gnus-mime-display-multipart-related-as-mixed)))
5490 ;;;!!!We should find the start part, but we just default
5491 ;;;!!!to the first part.
5492 ;;(gnus-mime-display-part (cadr handle))
5493 ;;;!!! Most multipart/related is an HTML message plus images.
5494 ;;;!!! Unfortunately we are unable to let W3 display those
5495 ;;;!!! included images, so we just display it as a mixed multipart.
5496 ;;(gnus-mime-display-mixed (cdr handle))
5497 ;;;!!! No, w3 can display everything just fine.
5498 (gnus-mime-display-part (cadr handle)))
5499 ((equal (car handle) "multipart/signed")
5500 (gnus-add-wash-type 'signed)
5501 (gnus-mime-display-security handle))
5502 ((equal (car handle) "multipart/encrypted")
5503 (gnus-add-wash-type 'encrypted)
5504 (gnus-mime-display-security handle))
5505 ;; Other multiparts are handled like multipart/mixed.
5507 (gnus-mime-display-mixed (cdr handle)))))
5509 (defun gnus-mime-part-function (handles)
5510 (if (stringp (car handles))
5511 (mapcar 'gnus-mime-part-function (cdr handles))
5512 (funcall gnus-article-mime-part-function handles)))
5514 (defun gnus-mime-display-mixed (handles)
5515 (mapcar 'gnus-mime-display-part handles))
5517 (defun gnus-mime-display-single (handle)
5518 (let ((type (mm-handle-media-type handle))
5519 (ignored gnus-ignored-mime-types)
5526 (when (string-match (pop ignored) type)
5527 (throw 'ignored nil)))
5528 (if (and (setq not-attachment
5529 (and (not (mm-inline-override-p handle))
5530 (or (not (mm-handle-disposition handle))
5531 (equal (car (mm-handle-disposition handle))
5533 (mm-attachment-override-p handle))))
5534 (mm-automatic-display-p handle)
5536 (mm-inlinable-p handle)
5537 (mm-inlined-p handle))
5538 (mm-automatic-external-display-p type)))
5540 (when (equal (mm-handle-media-supertype handle) "text")
5542 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5544 (push (cons id handle) gnus-article-mime-handle-alist)
5546 (equal (mm-handle-media-supertype handle) "message"))
5549 (cond ((not (bolp)) 2)
5550 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5552 (when (or (not display)
5553 (not (gnus-unbuttonized-mime-type-p type)))
5554 (gnus-insert-mime-button
5555 handle id (list (or display (and not-attachment text))))
5556 (gnus-article-insert-newline)
5557 ;; Remember modify the number of forward lines.
5565 (let ((mail-parse-charset gnus-newsgroup-charset)
5566 (mail-parse-ignored-charsets
5567 (save-excursion (condition-case ()
5568 (set-buffer gnus-summary-buffer)
5570 gnus-newsgroup-ignored-charsets)))
5571 (mm-display-part handle t))
5572 (goto-char (point-max)))
5573 ((and text not-attachment)
5577 (gnus-article-insert-newline)
5580 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5582 (and (equal type "text/calendar") 'utf-8))))
5583 (cond ((not charset)
5584 (mm-string-as-multibyte (mm-get-part handle)))
5585 ((eq charset 'gnus-decoded)
5586 (with-current-buffer (mm-handle-buffer handle)
5589 (mm-decode-string (mm-get-part handle) charset)))))
5590 (goto-char (point-max))))
5594 (narrow-to-region beg (point))
5595 (if (eq handle gnus-article-mime-handles)
5596 ;; The format=flowed case.
5597 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5598 ;; Don't count signature parts that are never displayed.
5599 ;; The part number should be re-calculated supposing this
5600 ;; might be a message/rfc822 part.
5602 (dolist (part gnus-article-mime-handles)
5603 (unless (or (stringp part)
5604 (equal (car (mm-handle-type part))
5605 "application/pgp-signature"))
5606 (push part handles)))
5608 nil (length (memq handle handles)) (length handles)
5609 (mm-handle-media-type handle)))))))))))
5611 (defun gnus-unbuttonized-mime-type-p (type)
5612 "Say whether TYPE is to be unbuttonized."
5613 (unless gnus-inhibit-mime-unbuttonizing
5615 (let ((types gnus-unbuttonized-mime-types))
5617 (when (string-match (pop types) type)
5618 (throw 'found t)))))
5620 (let ((types gnus-buttonized-mime-types))
5622 (when (string-match (pop types) type)
5623 (throw 'found t)))))))))
5625 (defun gnus-article-insert-newline ()
5626 "Insert a newline, but mark it as undeletable."
5627 (gnus-put-text-property
5628 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5630 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5631 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5634 handle (inhibit-read-only t) from props begend not-pref)
5635 (save-window-excursion
5638 (narrow-to-region (car ibegend)
5641 (goto-char (car ibegend))
5644 (delete-region (point-min) (point-max))
5645 (mm-remove-parts handles))
5646 (setq begend (list (point-marker)))
5648 (unless (setq not-pref (cadr (member preferred ihandles)))
5649 (setq not-pref (car ihandles)))
5652 (not (gnus-unbuttonized-mime-type-p
5653 "multipart/alternative")))
5654 (gnus-add-text-properties
5657 (insert (format "%d. " id))
5661 (unless ,(not ibegend)
5662 (setq gnus-article-mime-handle-alist
5663 ',gnus-article-mime-handle-alist))
5664 (gnus-mime-display-alternative
5665 ',ihandles ',not-pref ',begend ,id))
5666 keymap ,gnus-mime-button-map
5667 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5668 face ,gnus-article-button-face
5670 article-type multipart))
5671 (widget-convert-button 'link from (point)
5672 :action 'gnus-widget-press-button
5673 :button-keymap gnus-widget-button-keymap)
5675 (while (setq handle (pop handles))
5676 (gnus-add-text-properties
5679 (insert (format "(%c) %-18s"
5680 (if (equal handle preferred) ?* ? )
5681 (mm-handle-media-type handle)))
5685 (unless ,(not ibegend)
5686 (setq gnus-article-mime-handle-alist
5687 ',gnus-article-mime-handle-alist))
5688 (gnus-mime-display-alternative
5689 ',ihandles ',handle ',begend ,id))
5690 keymap ,gnus-mime-button-map
5691 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5692 face ,gnus-article-button-face
5695 (widget-convert-button 'link from (point)
5696 :action 'gnus-widget-press-button
5697 :button-keymap gnus-widget-button-keymap)
5701 (if (stringp (car preferred))
5702 (gnus-display-mime preferred)
5703 (let ((mail-parse-charset gnus-newsgroup-charset)
5704 (mail-parse-ignored-charsets
5705 (with-current-buffer gnus-summary-buffer
5706 gnus-newsgroup-ignored-charsets)))
5707 (mm-display-part preferred)
5711 (narrow-to-region (car begend) (point-max))
5713 nil (length gnus-article-mime-handle-alist)
5714 (gnus-article-mime-total-parts)
5715 (mm-handle-media-type handle))))))
5716 (goto-char (point-max))
5717 (setcdr begend (point-marker)))))
5719 (goto-char point))))
5721 (defconst gnus-article-wash-status-strings
5722 (let ((alist '((cite "c" "Possible hidden citation text"
5723 " " "All citation text visible")
5724 (headers "h" "Hidden headers"
5725 " " "All headers visible.")
5726 (pgp "p" "Encrypted or signed message status hidden"
5727 " " "No hidden encryption nor digital signature status")
5728 (signature "s" "Signature has been hidden"
5729 " " "Signature is visible")
5730 (overstrike "o" "Overstrike (^H) characters applied"
5731 " " "No overstrike characters applied")
5732 (emphasis "e" "/*_Emphasis_*/ characters applied"
5733 " " "No /*_emphasis_*/ characters applied")))
5735 (dolist (entry alist result)
5736 (let ((key (nth 0 entry))
5737 (on (copy-sequence (nth 1 entry)))
5738 (on-help (nth 2 entry))
5739 (off (copy-sequence (nth 3 entry)))
5740 (off-help (nth 4 entry)))
5741 (put-text-property 0 1 'help-echo on-help on)
5742 (put-text-property 0 1 'help-echo off-help off)
5743 (push (list key on off) result))))
5744 "Alist of strings describing wash status in the mode line.
5745 Each entry has the form (KEY ON OF), where the KEY is a symbol
5746 representing the particular washing function, ON is the string to use
5747 in the article mode line when the washing function is active, and OFF
5748 is the string to use when it is inactive.")
5750 (defun gnus-article-wash-status-entry (key value)
5751 (let ((entry (assoc key gnus-article-wash-status-strings)))
5752 (if value (nth 1 entry) (nth 2 entry))))
5754 (defun gnus-article-wash-status ()
5755 "Return a string which display status of article washing."
5756 (with-current-buffer gnus-article-buffer
5757 (let ((cite (memq 'cite gnus-article-wash-types))
5758 (headers (memq 'headers gnus-article-wash-types))
5759 (boring (memq 'boring-headers gnus-article-wash-types))
5760 (pgp (memq 'pgp gnus-article-wash-types))
5761 (pem (memq 'pem gnus-article-wash-types))
5762 (signed (memq 'signed gnus-article-wash-types))
5763 (encrypted (memq 'encrypted gnus-article-wash-types))
5764 (signature (memq 'signature gnus-article-wash-types))
5765 (overstrike (memq 'overstrike gnus-article-wash-types))
5766 (emphasis (memq 'emphasis gnus-article-wash-types)))
5768 (gnus-article-wash-status-entry 'cite cite)
5769 (gnus-article-wash-status-entry 'headers (or headers boring))
5770 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5771 (gnus-article-wash-status-entry 'signature signature)
5772 (gnus-article-wash-status-entry 'overstrike overstrike)
5773 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5775 (defun gnus-add-wash-type (type)
5776 "Add a washing of TYPE to the current status."
5777 (add-to-list 'gnus-article-wash-types type))
5779 (defun gnus-delete-wash-type (type)
5780 "Add a washing of TYPE to the current status."
5781 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5783 (defun gnus-add-image (category image)
5784 "Add IMAGE of CATEGORY to the list of displayed images."
5785 (let ((entry (assq category gnus-article-image-alist)))
5787 (setq entry (list category))
5788 (push entry gnus-article-image-alist))
5789 (nconc entry (list image))))
5791 (defun gnus-delete-images (category)
5792 "Delete all images in CATEGORY."
5793 (let ((entry (assq category gnus-article-image-alist)))
5794 (dolist (image (cdr entry))
5795 (gnus-remove-image image category))
5796 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5797 (gnus-delete-wash-type category)))
5799 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5801 (defun gnus-article-maybe-hide-headers ()
5802 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5803 Provided for backwards compatibility."
5804 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5805 (not (with-current-buffer gnus-summary-buffer
5806 gnus-have-all-headers)))
5807 (not gnus-inhibit-hiding))
5808 (gnus-article-hide-headers)))
5812 (defun gnus-output-to-file (file-name)
5813 "Append the current article to a file named FILE-NAME.
5814 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5815 text and used as the value of the coding cookie which is added to the
5816 top of a file. Otherwise, this function saves a raw article without
5818 (let* ((artbuf (current-buffer))
5819 (file-name-coding-system nnmail-pathname-coding-system)
5820 (coding gnus-article-save-coding-system)
5821 (coding-system-for-read (if coding
5822 nil ;; Rely on the coding cookie.
5823 mm-text-coding-system))
5824 (coding-system-for-write (or coding
5825 mm-text-coding-system-for-write
5826 mm-text-coding-system))
5827 (exists (file-exists-p file-name)))
5830 (insert-file-contents file-name)
5831 (goto-char (point-min))
5832 ;; Remove the existing coding cookie.
5833 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5834 (delete-region (match-beginning 0) (match-end 0))))
5835 (goto-char (point-max))
5836 (insert-buffer-substring artbuf)
5837 ;; Append newline at end of the buffer as separator, and then
5839 (goto-char (point-max))
5842 ;; If the coding system is not suitable to encode the text,
5843 ;; ask a user for a proper one.
5844 (when (fboundp 'select-safe-coding-system)
5845 (setq coding (coding-system-base
5846 (save-window-excursion
5847 (select-safe-coding-system (point-min) (point-max)
5849 (setq coding-system-for-write
5850 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5852 (goto-char (point-min))
5853 ;; Add the coding cookie.
5854 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5855 coding-system-for-write)))
5858 (write-region (point-min) (point-max) file-name nil 'no-message)
5859 (message "Appended to %s" file-name))
5860 (write-region (point-min) (point-max) file-name))))
5863 (defun gnus-narrow-to-page (&optional arg)
5864 "Narrow the article buffer to a page.
5865 If given a numerical ARG, move forward ARG pages."
5867 (setq arg (if arg (prefix-numeric-value arg) 0))
5869 (set-buffer gnus-article-buffer)
5870 (goto-char (point-min))
5872 ;; Remove any old next/prev buttons.
5873 (when (gnus-visual-p 'page-marker)
5874 (let ((inhibit-read-only t))
5875 (gnus-remove-text-with-property 'gnus-prev)
5876 (gnus-remove-text-with-property 'gnus-next)))
5879 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5881 (re-search-forward page-delimiter nil 'move arg)))
5882 (goto-char (match-end 0))
5884 (goto-char (point-min))
5885 (setq gnus-page-broken
5886 (and (re-search-forward page-delimiter nil t) t))))
5887 (when gnus-page-broken
5890 (if (re-search-forward page-delimiter nil 'move)
5893 (when (and (gnus-visual-p 'page-marker)
5894 (> (point-min) (save-restriction (widen) (point-min))))
5896 (goto-char (point-min))
5897 (gnus-insert-prev-page-button)))
5898 (when (and (gnus-visual-p 'page-marker)
5899 (< (point-max) (save-restriction (widen) (point-max))))
5901 (goto-char (point-max))
5902 (gnus-insert-next-page-button))))))
5904 ;; Article mode commands
5906 (defun gnus-article-goto-next-page ()
5907 "Show the next page of the article."
5909 (when (gnus-article-next-page)
5910 (goto-char (point-min))
5911 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5914 (defun gnus-article-goto-prev-page ()
5915 "Show the previous page of the article."
5918 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5919 (gnus-article-prev-page nil)))
5921 ;; This is cleaner but currently breaks `gnus-pick-mode':
5923 ;; (defun gnus-article-goto-next-page ()
5924 ;; "Show the next page of the article."
5926 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5927 ;; (gnus-summary-next-page)))
5929 ;; (defun gnus-article-goto-prev-page ()
5930 ;; "Show the next page of the article."
5932 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5933 ;; (gnus-summary-prev-page)))
5935 (defun gnus-article-next-page (&optional lines)
5936 "Show the next page of the current article.
5937 If end of article, return non-nil. Otherwise return nil.
5938 Argument LINES specifies lines to be scrolled up."
5940 (move-to-window-line -1)
5941 (if (and (not (and gnus-article-over-scroll
5942 (> (count-lines (window-start) (point-max))
5943 (+ (or lines (1- (window-height)))
5944 (or (and (boundp 'scroll-margin)
5945 (symbol-value 'scroll-margin))
5949 (and (pos-visible-in-window-p) ;Not continuation line.
5950 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
5951 ;; Nothing in this page.
5952 (if (or (not gnus-page-broken)
5957 (eobp)))) ;Real end-of-buffer?
5959 (when gnus-article-over-scroll
5960 (gnus-article-next-page-1 lines))
5962 (gnus-narrow-to-page 1) ;Go to next page.
5964 ;; More in this page.
5965 (gnus-article-next-page-1 lines)
5968 (defmacro gnus-article-beginning-of-window ()
5969 "Move point to the beginning of the window.
5970 In Emacs, the point is placed at the line number which `scroll-margin'
5972 (if (featurep 'xemacs)
5973 '(move-to-window-line 0)
5974 '(move-to-window-line
5975 (min (max 0 scroll-margin)
5976 (max 1 (- (window-height)
5977 (if mode-line-format 1 0)
5978 (if header-line-format 1 0)))))))
5980 (defun gnus-article-next-page-1 (lines)
5981 (when (and (not (featurep 'xemacs))
5984 (numberp (symbol-value 'scroll-margin))
5985 (> (symbol-value 'scroll-margin) 0))
5986 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5987 ;; too many number of lines if `scroll-margin' is set as two or greater.
5988 (setq lines (min lines
5989 (max 0 (- (count-lines (window-start) (point-max))
5990 (symbol-value 'scroll-margin))))))
5992 (let ((scroll-in-place nil))
5995 ;; Long lines may cause an end-of-buffer error.
5996 (goto-char (point-max))))
5997 (gnus-article-beginning-of-window))
5999 (defun gnus-article-prev-page (&optional lines)
6000 "Show previous page of current article.
6001 Argument LINES specifies lines to be scrolled down."
6003 (move-to-window-line 0)
6004 (if (and gnus-page-broken
6006 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6008 (gnus-narrow-to-page -1) ;Go to previous page.
6009 (goto-char (point-max))
6010 (recenter (if gnus-article-over-scroll
6012 (max (+ lines (or (and (boundp 'scroll-margin)
6013 (symbol-value 'scroll-margin))
6016 (- (window-height) 2))
6020 (let ((scroll-in-place nil))
6021 (scroll-down lines))
6022 (beginning-of-buffer
6023 (goto-char (point-min))))
6024 (gnus-article-beginning-of-window))))
6026 (defun gnus-article-only-boring-p ()
6027 "Decide whether there is only boring text remaining in the article.
6028 Something \"interesting\" is a word of at least two letters that does
6029 not have a face in `gnus-article-boring-faces'."
6030 (when (and gnus-article-skip-boring
6031 (boundp 'gnus-article-boring-faces)
6032 (symbol-value 'gnus-article-boring-faces))
6034 (let ((inhibit-point-motion-hooks t))
6036 (while (re-search-forward "\\b\\w\\w" nil t)
6038 (when (not (gnus-intersection
6039 (gnus-faces-at (point))
6040 (symbol-value 'gnus-article-boring-faces)))
6041 (throw 'only-boring nil)))
6042 (throw 'only-boring t))))))
6044 (defun gnus-article-refer-article ()
6045 "Read article specified by message-id around point."
6048 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6049 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6050 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6051 (let ((msg-id (concat "<" (match-string 0) ">")))
6052 (set-buffer gnus-summary-buffer)
6053 (gnus-summary-refer-article msg-id))
6054 (error "No references around point"))))
6056 (defun gnus-article-show-summary ()
6057 "Reconfigure windows to show summary buffer."
6059 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6060 (error "There is no summary buffer for this article buffer")
6061 (gnus-article-set-globals)
6062 (gnus-configure-windows 'article)
6063 (gnus-summary-goto-subject gnus-current-article)
6064 (gnus-summary-position-point)))
6066 (defun gnus-article-describe-briefly ()
6067 "Describe article mode commands briefly."
6069 (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")))
6071 (defun gnus-article-summary-command ()
6072 "Execute the last keystroke in the summary buffer."
6074 (let ((obuf (current-buffer))
6075 (owin (current-window-configuration))
6077 (switch-to-buffer gnus-article-current-summary 'norecord)
6078 (setq func (lookup-key (current-local-map) (this-command-keys)))
6079 (call-interactively func)
6081 (set-window-configuration owin)
6082 (set-window-point (get-buffer-window (current-buffer)) (point))))
6084 (defun gnus-article-summary-command-nosave ()
6085 "Execute the last keystroke in the summary buffer."
6088 (pop-to-buffer gnus-article-current-summary)
6089 (setq func (lookup-key (current-local-map) (this-command-keys)))
6090 (call-interactively func)))
6092 (defun gnus-article-check-buffer ()
6093 "Beep if not in an article buffer."
6094 (unless (equal major-mode 'gnus-article-mode)
6095 (error "Command invoked outside of a Gnus article buffer")))
6097 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6098 "Read a summary buffer key sequence and execute it from the article buffer."
6100 (gnus-article-check-buffer)
6102 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6103 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6104 "=" "^" "\M-^" "|"))
6110 '("n" "Gn" "p" "Gp"))
6113 (set-buffer gnus-article-current-summary)
6114 (let (gnus-pick-mode)
6115 (push (or key last-command-event) unread-command-events)
6116 (setq keys (if (featurep 'xemacs)
6117 (events-to-keys (read-key-sequence nil))
6118 (read-key-sequence nil)))))
6123 ((eq (aref keys (1- (length keys))) ?\C-h)
6124 (with-current-buffer gnus-article-current-summary
6125 (describe-bindings (substring keys 0 -1))))
6126 ((or (member keys nosaves)
6127 (member keys nosave-but-article)
6128 (member keys nosave-in-article))
6130 (save-window-excursion
6131 (pop-to-buffer gnus-article-current-summary)
6132 ;; We disable the pick minor mode commands.
6133 (let (gnus-pick-mode)
6134 (setq func (lookup-key (current-local-map) keys))))
6138 (unless (member keys nosave-in-article)
6139 (set-buffer gnus-article-current-summary))
6140 (call-interactively func)
6141 (setq new-sum-point (point)))
6142 (when (member keys nosave-but-article)
6143 (pop-to-buffer gnus-article-buffer))))
6145 ;; These commands should restore window configuration.
6146 (let ((obuf (current-buffer))
6147 (owin (current-window-configuration))
6148 win func in-buffer selected new-sum-start new-sum-hscroll err)
6149 (cond (not-restore-window
6150 (pop-to-buffer gnus-article-current-summary)
6151 (setq win (selected-window)))
6152 ((setq win (get-buffer-window gnus-article-current-summary))
6153 (select-window win))
6155 (let ((summary-buffer gnus-article-current-summary))
6156 (gnus-configure-windows 'article)
6157 (unless (setq win (get-buffer-window summary-buffer 'visible))
6158 (let ((gnus-buffer-configuration
6159 '(article ((vertical 1.0
6160 (summary 0.25 point)
6162 (gnus-configure-windows 'article))
6163 (setq win (get-buffer-window summary-buffer 'visible)))
6164 (gnus-select-frame-set-input-focus (window-frame win))
6165 (select-window win))))
6166 (setq in-buffer (current-buffer))
6167 ;; We disable the pick minor mode commands.
6168 (if (and (setq func (let (gnus-pick-mode)
6169 (lookup-key (current-local-map) keys)))
6171 (condition-case code
6173 (call-interactively func)
6179 (when (eq win (selected-window))
6180 (setq new-sum-point (point)
6181 new-sum-start (window-start win)
6182 new-sum-hscroll (window-hscroll win)))
6183 (when (or (eq in-buffer (current-buffer))
6184 (when (eq obuf (current-buffer))
6185 (set-buffer in-buffer)
6187 (setq selected (gnus-summary-select-article))
6189 (unless not-restore-window
6190 (set-window-configuration owin))
6191 (when (and (eq selected 'old)
6193 (set-window-start (get-buffer-window (current-buffer))
6195 (set-window-point (get-buffer-window (current-buffer))
6196 (if (article-goto-body)
6199 (when (and (not not-restore-window)
6201 (with-current-buffer (window-buffer win)
6202 (eq major-mode 'gnus-summary-mode)))
6203 (set-window-point win new-sum-point)
6204 (set-window-start win new-sum-start)
6205 (set-window-hscroll win new-sum-hscroll))))
6206 (set-window-configuration owin)
6208 (signal (car err) (cdr err))
6211 (defun gnus-article-describe-key (key)
6212 "Display documentation of the function invoked by KEY. KEY is a string."
6213 (interactive "kDescribe key: ")
6214 (gnus-article-check-buffer)
6215 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
6217 (set-buffer gnus-article-current-summary)
6218 (let (gnus-pick-mode)
6219 (if (featurep 'xemacs)
6221 (push (elt key 0) unread-command-events)
6222 (setq key (events-to-keys
6223 (read-key-sequence "Describe key: "))))
6224 (setq unread-command-events
6226 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6227 (string-to-list key)))
6228 (setq key (read-key-sequence "Describe key: "))))
6230 (describe-key key)))
6232 (defun gnus-article-describe-key-briefly (key &optional insert)
6233 "Display documentation of the function invoked by KEY. KEY is a string."
6234 (interactive "kDescribe key: \nP")
6235 (gnus-article-check-buffer)
6236 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
6238 (set-buffer gnus-article-current-summary)
6239 (let (gnus-pick-mode)
6240 (if (featurep 'xemacs)
6242 (push (elt key 0) unread-command-events)
6243 (setq key (events-to-keys
6244 (read-key-sequence "Describe key: "))))
6245 (setq unread-command-events
6247 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6248 (string-to-list key)))
6249 (setq key (read-key-sequence "Describe key: "))))
6250 (describe-key-briefly key insert))
6251 (describe-key-briefly key insert)))
6253 (defun gnus-article-reply-with-original (&optional wide)
6254 "Start composing a reply mail to the current message.
6255 The text in the region will be yanked. If the region isn't active,
6256 the entire article will be yanked."
6258 (let ((article (cdr gnus-article-current))
6260 (if (not (gnus-region-active-p))
6261 (with-current-buffer gnus-summary-buffer
6262 (gnus-summary-reply (list (list article)) wide))
6263 (setq contents (buffer-substring (point) (mark t)))
6264 ;; Deactivate active regions.
6265 (when (and (boundp 'transient-mark-mode)
6266 transient-mark-mode)
6267 (setq mark-active nil))
6268 (with-current-buffer gnus-summary-buffer
6270 (list (list article contents)) wide)))))
6272 (defun gnus-article-followup-with-original ()
6273 "Compose a followup to the current article.
6274 The text in the region will be yanked. If the region isn't active,
6275 the entire article will be yanked."
6277 (let ((article (cdr gnus-article-current))
6279 (if (not (gnus-region-active-p))
6280 (with-current-buffer gnus-summary-buffer
6281 (gnus-summary-followup (list (list article))))
6282 (setq contents (buffer-substring (point) (mark t)))
6283 ;; Deactivate active regions.
6284 (when (and (boundp 'transient-mark-mode)
6285 transient-mark-mode)
6286 (setq mark-active nil))
6287 (with-current-buffer gnus-summary-buffer
6288 (gnus-summary-followup
6289 (list (list article contents)))))))
6291 (defun gnus-article-hide (&optional arg force)
6292 "Hide all the gruft in the current article.
6293 This means that signatures, cited text and (some) headers will be
6295 If given a prefix, show the hidden text instead."
6296 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6297 (gnus-article-hide-headers arg)
6298 (gnus-article-hide-list-identifiers arg)
6299 (gnus-article-hide-citation-maybe arg force)
6300 (gnus-article-hide-signature arg))
6302 (defun gnus-article-maybe-highlight ()
6303 "Do some article highlighting if article highlighting is requested."
6304 (when (gnus-visual-p 'article-highlight 'highlight)
6305 (gnus-article-highlight-some)))
6307 (defun gnus-check-group-server ()
6308 ;; Make sure the connection to the server is alive.
6309 (unless (gnus-server-opened
6310 (gnus-find-method-for-group gnus-newsgroup-name))
6311 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6312 (gnus-request-group gnus-newsgroup-name t)))
6315 (autoload 'nneething-get-file-name "nneething"))
6317 (defun gnus-request-article-this-buffer (article group)
6318 "Get an article and insert it into this buffer."
6319 (let (do-update-line sparse-header)
6323 (gnus-kill-all-overlays)
6324 (setq group (or group gnus-newsgroup-name))
6326 ;; Using `gnus-request-article' directly will insert the article into
6327 ;; `nntp-server-buffer' - so we'll save some time by not having to
6328 ;; copy it from the server buffer into the article buffer.
6330 ;; We only request an article by message-id when we do not have the
6331 ;; headers for it, so we'll have to get those.
6332 (when (stringp article)
6333 (gnus-read-header article))
6335 ;; If the article number is negative, that means that this article
6336 ;; doesn't belong in this newsgroup (possibly), so we find its
6337 ;; message-id and request it by id instead of number.
6338 (when (and (numberp article)
6340 (get-buffer gnus-summary-buffer)
6341 (gnus-buffer-exists-p gnus-summary-buffer))
6343 (set-buffer gnus-summary-buffer)
6344 (let ((header (gnus-summary-article-header article)))
6347 ((memq article gnus-newsgroup-sparse)
6348 ;; This is a sparse gap article.
6349 (setq do-update-line article)
6350 (setq article (mail-header-id header))
6351 (setq sparse-header (gnus-read-header article))
6352 (setq gnus-newsgroup-sparse
6353 (delq article gnus-newsgroup-sparse)))
6355 ;; It's a real article.
6356 (setq article (mail-header-id header)))
6358 ;; It is an extracted pseudo-article.
6359 (setq article 'pseudo)
6360 (gnus-request-pseudo-article header))))
6362 (let ((method (gnus-find-method-for-group
6363 gnus-newsgroup-name)))
6364 (when (and (eq (car method) 'nneething)
6366 (let ((dir (nneething-get-file-name
6367 (mail-header-id header))))
6368 (when (and (stringp dir)
6369 (file-directory-p dir))
6370 (setq article 'nneething)
6371 (gnus-group-enter-directory dir))))))))
6374 ;; Refuse to select canceled articles.
6375 ((and (numberp article)
6377 (get-buffer gnus-summary-buffer)
6378 (gnus-buffer-exists-p gnus-summary-buffer)
6379 (eq (cdr (with-current-buffer gnus-summary-buffer
6380 (assq article gnus-newsgroup-reads)))
6381 gnus-canceled-mark))
6383 ;; We first check `gnus-original-article-buffer'.
6384 ((and (get-buffer gnus-original-article-buffer)
6386 (with-current-buffer gnus-original-article-buffer
6387 (and (equal (car gnus-original-article) group)
6388 (eq (cdr gnus-original-article) article))))
6389 (insert-buffer-substring gnus-original-article-buffer)
6391 ;; Check the backlog.
6392 ((and gnus-keep-backlog
6393 (gnus-backlog-request-article group article (current-buffer)))
6395 ;; Check asynchronous pre-fetch.
6396 ((gnus-async-request-fetched-article group article (current-buffer))
6397 (gnus-async-prefetch-next group article gnus-summary-buffer)
6398 (when (and (numberp article) gnus-keep-backlog)
6399 (gnus-backlog-enter-article group article (current-buffer)))
6402 ((and gnus-use-cache
6404 (gnus-cache-request-article article group))
6406 ;; Check the agent cache.
6407 ((gnus-agent-request-article article group)
6409 ;; Get the article and put into the article buffer.
6410 ((or (stringp article)
6412 (let ((gnus-override-method gnus-override-method)
6413 (methods (and (stringp article)
6414 gnus-refer-article-method))
6415 (backend (car (gnus-find-method-for-group
6416 gnus-newsgroup-name)))
6418 (inhibit-read-only t))
6419 (if (or (not (listp methods))
6420 (and (symbolp (car methods))
6421 (assq (car methods) nnoo-definition-alist)))
6422 (setq methods (list methods)))
6423 (when (and (null gnus-override-method)
6425 (setq gnus-override-method (pop methods)))
6427 (when (eq gnus-override-method 'current)
6428 (setq gnus-override-method
6429 (with-current-buffer gnus-summary-buffer
6430 gnus-current-select-method)))
6432 (gnus-kill-all-overlays)
6433 (let ((gnus-newsgroup-name group))
6434 (gnus-check-group-server))
6436 ((gnus-request-article article group (current-buffer))
6437 (when (numberp article)
6438 (gnus-async-prefetch-next group article
6439 gnus-summary-buffer)
6440 (when gnus-keep-backlog
6441 (gnus-backlog-enter-article
6442 group article (current-buffer))))
6443 (setq result 'article))
6445 (setq gnus-override-method (pop methods)))
6446 ((not (string-match "^400 "
6447 (nnheader-get-report backend)))
6448 ;; If we get 400 server disconnect, reconnect and
6449 ;; retry; otherwise, assume the article has expired.
6450 (setq result 'done))))
6451 (and (eq result 'article) 'article)))
6455 ;; Associate this article with the current summary buffer.
6456 (setq gnus-article-current-summary gnus-summary-buffer)
6458 ;; Take the article from the original article buffer
6459 ;; and place it in the buffer it's supposed to be in.
6460 (when (and (get-buffer gnus-article-buffer)
6461 (equal (buffer-name (current-buffer))
6462 (buffer-name (get-buffer gnus-article-buffer))))
6464 (if (get-buffer gnus-original-article-buffer)
6465 (set-buffer gnus-original-article-buffer)
6466 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6467 (buffer-disable-undo)
6468 (setq major-mode 'gnus-original-article-mode)
6469 (setq buffer-read-only t))
6470 (let ((inhibit-read-only t))
6472 (insert-buffer-substring gnus-article-buffer))
6473 (setq gnus-original-article (cons group article)))
6476 (run-hooks 'gnus-article-decode-hook)
6477 ;; Mark article as decoded or not.
6478 (setq gnus-article-decoded-p gnus-article-decode-hook))
6480 ;; Update sparse articles.
6481 (when (and do-update-line
6482 (or (numberp article)
6484 (let ((buf (current-buffer)))
6485 (set-buffer gnus-summary-buffer)
6486 (gnus-summary-update-article do-update-line sparse-header)
6487 (gnus-summary-goto-subject do-update-line nil t)
6488 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6490 (set-buffer buf))))))
6496 (defcustom gnus-article-edit-mode-hook nil
6497 "Hook run in article edit mode buffers."
6498 :group 'gnus-article-various
6501 (defvar gnus-article-edit-done-function nil)
6503 (defvar gnus-article-edit-mode-map nil)
6505 ;; Should we be using derived.el for this?
6506 (unless gnus-article-edit-mode-map
6507 (setq gnus-article-edit-mode-map (make-keymap))
6508 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6510 (gnus-define-keys gnus-article-edit-mode-map
6511 "\C-c?" describe-mode
6512 "\C-c\C-c" gnus-article-edit-done
6513 "\C-c\C-k" gnus-article-edit-exit
6514 "\C-c\C-f\C-t" message-goto-to
6515 "\C-c\C-f\C-o" message-goto-from
6516 "\C-c\C-f\C-b" message-goto-bcc
6517 ;;"\C-c\C-f\C-w" message-goto-fcc
6518 "\C-c\C-f\C-c" message-goto-cc
6519 "\C-c\C-f\C-s" message-goto-subject
6520 "\C-c\C-f\C-r" message-goto-reply-to
6521 "\C-c\C-f\C-n" message-goto-newsgroups
6522 "\C-c\C-f\C-d" message-goto-distribution
6523 "\C-c\C-f\C-f" message-goto-followup-to
6524 "\C-c\C-f\C-m" message-goto-mail-followup-to
6525 "\C-c\C-f\C-k" message-goto-keywords
6526 "\C-c\C-f\C-u" message-goto-summary
6527 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6528 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6529 "\C-c\C-b" message-goto-body
6530 "\C-c\C-i" message-goto-signature
6532 "\C-c\C-t" message-insert-to
6533 "\C-c\C-n" message-insert-newsgroups
6534 "\C-c\C-o" message-sort-headers
6535 "\C-c\C-e" message-elide-region
6536 "\C-c\C-v" message-delete-not-region
6537 "\C-c\C-z" message-kill-to-signature
6538 "\M-\r" message-newline-and-reformat
6539 "\C-c\C-a" mml-attach-file
6540 "\C-a" message-beginning-of-line
6542 "\M-;" comment-region)
6544 (gnus-define-keys (gnus-article-edit-wash-map
6545 "\C-c\C-w" gnus-article-edit-mode-map)
6546 "f" gnus-article-edit-full-stops))
6549 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6551 ["Fetch To" message-insert-to t]
6552 ["Fetch Newsgroups" message-insert-newsgroups t]
6554 ["To" message-goto-to t]
6555 ["From" message-goto-from t]
6556 ["Subject" message-goto-subject t]
6557 ["Cc" message-goto-cc t]
6558 ["Reply-To" message-goto-reply-to t]
6559 ["Summary" message-goto-summary t]
6560 ["Keywords" message-goto-keywords t]
6561 ["Newsgroups" message-goto-newsgroups t]
6562 ["Followup-To" message-goto-followup-to t]
6563 ["Mail-Followup-To" message-goto-mail-followup-to t]
6564 ["Distribution" message-goto-distribution t]
6565 ["Body" message-goto-body t]
6566 ["Signature" message-goto-signature t]))
6568 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6569 "Major mode for editing articles.
6570 This is an extended text-mode.
6572 \\{gnus-article-edit-mode-map}"
6573 (make-local-variable 'gnus-article-edit-done-function)
6574 (make-local-variable 'gnus-prev-winconf)
6575 (set (make-local-variable 'font-lock-defaults)
6576 '(message-font-lock-keywords t))
6577 (set (make-local-variable 'mail-header-separator) "")
6578 (set (make-local-variable 'gnus-article-edit-mode) t)
6579 (easy-menu-add message-mode-field-menu message-mode-map)
6581 (setq buffer-read-only nil)
6582 (buffer-enable-undo)
6585 (defun gnus-article-edit (&optional force)
6586 "Edit the current article.
6587 This will have permanent effect only in mail groups.
6588 If FORCE is non-nil, allow editing of articles even in read-only
6591 (when (and (not force)
6592 (gnus-group-read-only-p))
6593 (error "The current newsgroup does not support article editing"))
6594 (gnus-article-date-original)
6595 (gnus-article-edit-article
6597 `(lambda (no-highlight)
6599 (gnus-summary-edit-article-done
6600 ,(or (mail-header-references gnus-current-headers) "")
6601 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6603 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6604 "Start editing the contents of the current article buffer."
6605 (let ((winconf (current-window-configuration)))
6606 (set-buffer gnus-article-buffer)
6607 (let ((message-auto-save-directory
6608 ;; Don't associate the article buffer with a draft file.
6610 (gnus-article-edit-mode))
6611 (funcall start-func)
6612 (set-buffer-modified-p nil)
6613 (gnus-configure-windows 'edit-article)
6614 (setq gnus-article-edit-done-function exit-func)
6615 (setq gnus-prev-winconf winconf)
6617 (gnus-message 6 "C-c C-c to end edits"))))
6619 (defun gnus-article-edit-done (&optional arg)
6620 "Update the article edits and exit."
6622 (let ((func gnus-article-edit-done-function)
6623 (buf (current-buffer))
6624 (start (window-start))
6626 (winconf gnus-prev-winconf))
6627 (widen) ;; Widen it in case that users narrowed the buffer.
6630 ;; The cache and backlog have to be flushed somewhat.
6631 (when gnus-keep-backlog
6632 (gnus-backlog-remove-article
6633 (car gnus-article-current) (cdr gnus-article-current)))
6634 ;; Flush original article as well.
6636 (when (get-buffer gnus-original-article-buffer)
6637 (set-buffer gnus-original-article-buffer)
6638 (setq gnus-original-article nil)))
6639 (when gnus-use-cache
6640 (gnus-cache-update-article
6641 (car gnus-article-current) (cdr gnus-article-current)))
6642 ;; We remove all text props from the article buffer.
6643 (kill-all-local-variables)
6644 (set-text-properties (point-min) (point-max) nil)
6646 (set-window-configuration winconf)
6648 (set-window-start (get-buffer-window buf) start)
6649 (set-window-point (get-buffer-window buf) (point)))
6650 (gnus-summary-show-article))
6652 (defun gnus-article-edit-exit ()
6653 "Exit the article editing without updating."
6655 (when (or (not (buffer-modified-p))
6656 (yes-or-no-p "Article modified; kill anyway? "))
6657 (let ((curbuf (current-buffer))
6659 (window-start (window-start)))
6661 (if (gnus-buffer-live-p gnus-original-article-buffer)
6662 (insert-buffer-substring gnus-original-article-buffer))
6663 (let ((winconf gnus-prev-winconf))
6664 (kill-all-local-variables)
6666 (set-window-configuration winconf)
6667 ;; Tippy-toe some to make sure that point remains where it was.
6668 (save-current-buffer
6670 (set-window-start (get-buffer-window (current-buffer)) window-start)
6672 (gnus-summary-show-article)))
6674 (defun gnus-article-edit-full-stops ()
6675 "Interactively repair spacing at end of sentences."
6678 (goto-char (point-min))
6679 (search-forward-regexp "^$" nil t)
6680 (let ((case-fold-search nil))
6681 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6684 ;;; Article highlights
6687 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6689 ;;; Internal Variables:
6691 (defcustom gnus-button-url-regexp
6693 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6694 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6695 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6696 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6697 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6701 ;; Match paired parentheses, e.g. in Wikipedia URLs:
6702 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6704 "[" chars punct "]+" "[" chars "]"
6706 (concat ;; XEmacs 21.4 doesn't support POSIX.
6707 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6708 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6710 "Regular expression that matches URLs."
6711 :group 'gnus-article-buttons
6714 (defcustom gnus-button-valid-fqdn-regexp
6715 message-valid-fqdn-regexp
6716 "Regular expression that matches a valid FQDN."
6718 :group 'gnus-article-buttons
6721 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6722 (defcustom gnus-button-valid-localpart-regexp
6723 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6724 "Regular expression that matches a localpart of mail addresses or MIDs."
6726 :group 'gnus-article-buttons
6729 (defcustom gnus-button-man-handler 'manual-entry
6730 "Function to use for displaying man pages.
6731 The function must take at least one argument with a string naming the
6734 :type '(choice (function-item :tag "Man" manual-entry)
6735 (function-item :tag "Woman" woman)
6736 (function :tag "Other"))
6737 :group 'gnus-article-buttons)
6739 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6740 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6741 If the default site is too slow, try to find a CTAN mirror, see
6742 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6743 the variable `gnus-button-handle-ctan'."
6745 :group 'gnus-article-buttons
6746 :link '(custom-manual "(gnus)Group Parameters")
6747 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6748 (const "http://tug.ctan.org/tex-archive/")
6749 (const "http://www.dante.de/CTAN/")
6750 (string :tag "Other")))
6752 (defcustom gnus-button-ctan-handler 'browse-url
6753 "Function to use for displaying CTAN links.
6754 The function must take one argument, the string naming the URL."
6756 :type '(choice (function-item :tag "Browse Url" browse-url)
6757 (function :tag "Other"))
6758 :group 'gnus-article-buttons)
6760 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6761 "Bogus strings removed from CTAN URLs."
6763 :group 'gnus-article-buttons
6764 :type '(choice (const "^/?tex-archive/\\|/")
6765 (regexp :tag "Other")))
6767 (defcustom gnus-button-ctan-directory-regexp
6769 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6770 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6771 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6772 "tds" "tools" "usergrps" "web") t)
6773 "Regular expression for ctan directories.
6774 It should match all directories in the top level of `gnus-ctan-url'."
6776 :group 'gnus-article-buttons
6779 (defcustom gnus-button-mid-or-mail-regexp
6780 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6781 gnus-button-valid-fqdn-regexp
6783 "Regular expression that matches a message ID or a mail address."
6785 :group 'gnus-article-buttons
6788 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6789 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6790 Strings like this can be either a message ID or a mail address. If it is one
6791 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6792 message ID or a mail address, respectively. If this variable is set to the
6793 symbol `ask', always query the user what do do. If it is a function, this
6794 function will be called with the string as its only argument. The function
6795 must return `mid', `mail', `invalid' or `ask'."
6797 :group 'gnus-article-buttons
6798 :type '(choice (function-item :tag "Heuristic function"
6799 gnus-button-mid-or-mail-heuristic)
6804 (defcustom gnus-button-mid-or-mail-heuristic-alist
6805 '((-10.0 . ".+\\$.+@")
6808 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6809 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6810 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6811 (-1.0 . "^[^a-z]+@")
6813 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6814 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6815 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6816 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6819 (-1.0 . "^[0-9][0-9]")
6821 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6822 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6823 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6824 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6826 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6827 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6830 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6832 ;; compensation for TDMA dated mail addresses:
6833 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6835 (-20.0 . "\\.fsf@") ;; Gnus
6838 (-20.0 . "^alpine\\.")
6839 (-20.0 . "_-_") ;; Subject change in thread
6841 (-20.0 . "\\.ln@") ;; leafnode
6842 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6843 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6845 ;; (5.0 . "") ;; $local_part_len <= 7
6846 (10.0 . "^[^0-9]+@")
6847 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6848 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6851 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6853 (0.5 . "^[A-Z][a-z]")
6854 (0.5 . "^[A-Z][a-z][a-z]")
6855 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6856 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6857 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6859 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6860 address. The REGEXP is processed with `case-fold-search' set to nil."
6862 :group 'gnus-article-buttons
6863 :type '(repeat (cons (number :tag "Rate")
6864 (regexp :tag "Regexp"))))
6866 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6867 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6868 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6869 address, `ask' if unsure and `invalid' if the string is invalid."
6870 (let ((case-fold-search nil)
6871 (list gnus-button-mid-or-mail-heuristic-alist)
6872 (result 0) rate regexp lpartlen elem)
6874 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6875 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6876 ;; Certain special cases...
6879 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6880 "^[0-9]+\\.[0-9]+@compuserve\\|"
6881 "@public\\.gmane\\.org")
6883 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6884 (setq result 'mail))
6885 (when (string-match "@.*@\\| " mid-or-mail)
6886 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6887 (setq result 'invalid))
6888 ;; Nothing more to do, if result is not a number here...
6889 (when (numberp result)
6891 (setq elem (car list)
6895 (when (string-match regexp mid-or-mail)
6896 (setq result (+ result rate))
6898 9 "`%s' matched `%s', rate `%s', result `%s'."
6899 mid-or-mail regexp rate result)))
6900 (when (<= lpartlen 7)
6901 (setq result (+ result 5.0))
6902 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6903 mid-or-mail result))
6904 (when (>= lpartlen 12)
6905 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6907 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6908 ;; Long local part should contain realname if e-mail address,
6909 ;; too many digits: message-id.
6910 ;; $score -= 5.0 + 0.1 * $local_part_len;
6911 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6912 (setq result (+ result rate))
6914 9 "Many digits in `%s', rate `%s', result `%s'."
6915 mid-or-mail rate result))
6916 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6918 ;; Too few vowels [^aeiouy]{4,}.*\@
6919 (setq result (+ result -5.0))
6921 9 "Few vowels in `%s', rate `%s', result `%s'."
6922 mid-or-mail -5.0 result))
6924 (setq result (+ result 5.0))
6926 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6927 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6928 ;; Maybe we should make this a customizable alist: (condition . 'result)
6930 ((symbolp result) result)
6931 ;; Now convert number into proper results:
6932 ((< result -10.0) 'mid)
6933 ((> result 10.0) 'mail)
6936 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6937 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6938 (url-mid (concat "news" ":" mid-or-mail))
6939 (url-mailto (concat "mailto" ":" mid-or-mail)))
6940 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6941 (when (fboundp pref)
6943 ;; get rid of surrounding angles...
6945 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6946 (if (or (eq 'mid guessed) (eq 'mail guessed))
6950 (save-window-excursion
6951 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6954 (cond ((eq pref 'mid)
6955 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6956 (gnus-button-handle-news url-mid))
6958 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6959 (gnus-url-mailto url-mailto))
6960 (t (gnus-message 3 "Invalid string.")))))
6962 (defun gnus-button-handle-custom (fun arg)
6963 "Call function FUN on argument ARG.
6964 Both FUN and ARG are supposed to be strings. ARG will be passed
6965 as a symbol to FUN."
6966 (funcall (intern fun)
6967 (if (string-match "^customize-apropos" fun)
6971 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6973 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6976 (defun gnus-button-handle-describe-function (url)
6977 "Call `describe-function' when pushing the corresponding URL button."
6980 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6982 (defun gnus-button-handle-describe-variable (url)
6983 "Call `describe-variable' when pushing the corresponding URL button."
6986 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6988 (defun gnus-button-handle-symbol (url)
6989 "Display help on variable or function.
6990 Calls `describe-variable' or `describe-function'."
6991 (let ((sym (intern url)))
6993 ((fboundp sym) (describe-function sym))
6994 ((boundp sym) (describe-variable sym))
6995 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6997 (defun gnus-button-handle-describe-key (url)
6998 "Call `describe-key' when pushing the corresponding URL button."
7000 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7001 (keys (ignore-errors (eval `(kbd ,key-string)))))
7004 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7006 (defun gnus-button-handle-apropos (url)
7007 "Call `apropos' when pushing the corresponding URL button."
7008 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7010 (defun gnus-button-handle-apropos-command (url)
7011 "Call `apropos' when pushing the corresponding URL button."
7013 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7015 (defun gnus-button-handle-apropos-variable (url)
7016 "Call `apropos' when pushing the corresponding URL button."
7018 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7019 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7021 (defun gnus-button-handle-apropos-documentation (url)
7022 "Call `apropos' when pushing the corresponding URL button."
7024 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7025 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7027 (defun gnus-button-handle-library (url)
7028 "Call `locate-library' when pushing the corresponding URL button."
7029 (gnus-message 9 "url=`%s'" url)
7030 (let* ((lib (locate-library url))
7031 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7033 (gnus-message 1 "Cannot locale library `%s'." url)
7034 (find-file-read-only file))))
7036 (defun gnus-button-handle-ctan (url)
7037 "Call `browse-url' when pushing a CTAN URL button."
7039 gnus-button-ctan-handler
7042 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7044 (defcustom gnus-button-tex-level 5
7045 "*Integer that says how many TeX-related buttons Gnus will show.
7046 The higher the number, the more buttons will appear and the more false
7047 positives are possible. Note that you can set this variable local to
7048 specific groups. Setting it higher in TeX groups is probably a good idea.
7049 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7050 how to set variables in specific groups."
7052 :group 'gnus-article-buttons
7053 :link '(custom-manual "(gnus)Group Parameters")
7056 (defcustom gnus-button-man-level 5
7057 "*Integer that says how many man-related buttons Gnus will show.
7058 The higher the number, the more buttons will appear and the more false
7059 positives are possible. Note that you can set this variable local to
7060 specific groups. Setting it higher in Unix groups is probably a good idea.
7061 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7062 how to set variables in specific groups."
7064 :group 'gnus-article-buttons
7065 :link '(custom-manual "(gnus)Group Parameters")
7068 (defcustom gnus-button-emacs-level 5
7069 "*Integer that says how many emacs-related buttons Gnus will show.
7070 The higher the number, the more buttons will appear and the more false
7071 positives are possible. Note that you can set this variable local to
7072 specific groups. Setting it higher in Emacs or Gnus related groups is
7073 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7074 `gnus-parameters' on how to set variables in specific groups."
7076 :group 'gnus-article-buttons
7077 :link '(custom-manual "(gnus)Group Parameters")
7080 (defcustom gnus-button-message-level 5
7081 "*Integer that says how many buttons for news or mail messages will appear.
7082 The higher the number, the more buttons will appear and the more false
7083 positives are possible."
7084 ;; mail addresses, MIDs, URLs for news, ...
7086 :group 'gnus-article-buttons
7089 (defcustom gnus-button-browse-level 5
7090 "*Integer that says how many buttons for browsing will appear.
7091 The higher the number, the more buttons will appear and the more false
7092 positives are possible."
7093 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7095 :group 'gnus-article-buttons
7098 (defcustom gnus-button-alist
7099 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7100 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7101 ((concat "\\b\\(nntp\\|news\\):\\("
7102 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7103 0 t gnus-button-handle-news 2)
7104 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7105 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7106 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7107 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7108 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7109 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7110 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7111 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7112 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7113 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7114 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7115 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7116 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7117 ;; RFC 2368 (The mailto URL scheme)
7118 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7119 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7120 ("\\bmailto:\\([^ \n\t]+\\)"
7121 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7123 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7124 gnus-button-ctan-directory-regexp
7125 "[^][>)!;:,'\n\t ]+\\)")
7126 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7127 ((concat "\\btex-archive/\\("
7128 gnus-button-ctan-directory-regexp
7129 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7130 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7133 gnus-button-ctan-directory-regexp
7134 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7135 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7136 ;; This is info (home-grown style) <info://foo/bar+baz>
7137 ("\\binfo://\\([^'\">\n\t ]+\\)"
7138 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7139 ;; Info GNOME style <info:foo#bar_baz>
7140 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7141 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7142 ;; Info KDE style <info:(foo)bar baz>
7143 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7144 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7145 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7146 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7147 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7148 ;; Info links like `C-h i d m CC Mode RET'
7149 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
7151 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7152 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7153 ;; Emacs help commands
7154 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7155 ;; regexp doesn't match arguments containing ` '.
7156 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7157 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7158 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7159 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7160 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7161 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7162 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7163 ;; The following entries may lead to many false positives so don't enable
7164 ;; them by default (use a high button level).
7165 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7166 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7167 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7168 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7169 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7170 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7171 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7172 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7173 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7174 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7175 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7176 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7177 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7178 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7179 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7180 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7181 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7182 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7183 ;; Unlike the other regexps we really have to require quoting
7184 ;; here to determine where it ends.
7185 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7186 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7187 ("<URL: *\\([^\n<>]*\\)>"
7188 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7189 ;; RFC 2396 (2.4.3., delims) ...
7190 ("\"URL: *\\([^\n\"]*\\)\""
7191 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7193 (gnus-button-url-regexp
7194 0 (>= gnus-button-browse-level 0) browse-url 0)
7196 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7197 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7198 gnus-button-handle-man 1)
7199 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7200 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7201 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7202 gnus-button-handle-man 1)
7203 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7204 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7205 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7206 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7207 ;; Recognizing patches to .el files. This is somewhat obscure,
7208 ;; but considering the percentage of Gnus users who hack Emacs
7210 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7211 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7212 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7213 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7214 ;; MID or mail: To avoid too many false positives we don't try to catch
7215 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7216 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7217 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7218 ;; so that non-ambiguous entries (see above) match first.
7219 (gnus-button-mid-or-mail-regexp
7220 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7221 "*Alist of regexps matching buttons in article bodies.
7223 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7224 REGEXP: is the string (case insensitive) matching text around the button (can
7225 also be Lisp expression evaluating to a string),
7226 BUTTON: is the number of the regexp grouping actually matching the button,
7227 FORM: is a Lisp expression which must eval to true for the button to
7229 CALLBACK: is the function to call when the user push this button, and each
7230 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7232 CALLBACK can also be a variable, in that case the value of that
7233 variable it the real callback function."
7234 :group 'gnus-article-buttons
7235 :type '(repeat (list (choice regexp variable sexp)
7236 (integer :tag "Button")
7238 (function :tag "Callback")
7241 (integer :tag "Regexp group")))))
7242 (put 'gnus-button-alist 'risky-local-variable t)
7244 (defcustom gnus-header-button-alist
7245 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7246 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7247 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7248 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7249 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7250 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7251 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7252 0 (>= gnus-button-browse-level 0) browse-url 0)
7253 ("^Subject:" gnus-button-url-regexp
7254 0 (>= gnus-button-browse-level 0) browse-url 0)
7255 ("^[^:]+:" gnus-button-url-regexp
7256 0 (>= gnus-button-browse-level 0) browse-url 0)
7257 ("^OpenPGP:.*url=" gnus-button-url-regexp
7258 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7259 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7260 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7261 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7262 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7263 "*Alist of headers and regexps to match buttons in article heads.
7265 This alist is very similar to `gnus-button-alist', except that each
7266 alist has an additional HEADER element first in each entry:
7268 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7270 HEADER is a regexp to match a header. For a fuller explanation, see
7271 `gnus-button-alist'."
7272 :group 'gnus-article-buttons
7273 :group 'gnus-article-headers
7274 :type '(repeat (list (regexp :tag "Header")
7275 (choice regexp variable)
7276 (integer :tag "Button")
7278 (function :tag "Callback")
7281 (integer :tag "Regexp group")))))
7282 (put 'gnus-header-button-alist 'risky-local-variable t)
7286 (defun gnus-article-push-button (event)
7287 "Check text under the mouse pointer for a callback function.
7288 If the text under the mouse pointer has a `gnus-callback' property,
7289 call it with the value of the `gnus-data' text property."
7291 (set-buffer (window-buffer (posn-window (event-start event))))
7292 (let* ((pos (posn-point (event-start event)))
7293 (data (get-text-property pos 'gnus-data))
7294 (fun (get-text-property pos 'gnus-callback)))
7297 (funcall fun data))))
7299 (defun gnus-article-press-button ()
7300 "Check text at point for a callback function.
7301 If the text at point has a `gnus-callback' property,
7302 call it with the value of the `gnus-data' text property."
7304 (let ((data (get-text-property (point) 'gnus-data))
7305 (fun (get-text-property (point) 'gnus-callback)))
7307 (funcall fun data))))
7309 (defun gnus-article-highlight (&optional force)
7310 "Highlight current article.
7311 This function calls `gnus-article-highlight-headers',
7312 `gnus-article-highlight-citation',
7313 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7314 do the highlighting. See the documentation for those functions."
7315 (interactive (list 'force))
7316 (gnus-article-highlight-headers)
7317 (gnus-article-highlight-citation force)
7318 (gnus-article-highlight-signature)
7319 (gnus-article-add-buttons force)
7320 (gnus-article-add-buttons-to-head))
7322 (defun gnus-article-highlight-some (&optional force)
7323 "Highlight current article.
7324 This function calls `gnus-article-highlight-headers',
7325 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7326 do the highlighting. See the documentation for those functions."
7327 (interactive (list 'force))
7328 (gnus-article-highlight-headers)
7329 (gnus-article-highlight-signature)
7330 (gnus-article-add-buttons))
7332 (defun gnus-article-highlight-headers ()
7333 "Highlight article headers as specified by `gnus-header-face-alist'."
7335 (gnus-with-article-headers
7336 (let (regexp header-face field-face from hpoints fpoints)
7337 (dolist (entry gnus-header-face-alist)
7338 (goto-char (point-min))
7339 (setq regexp (concat "^\\("
7340 (if (string-equal "" (nth 0 entry))
7344 header-face (nth 1 entry)
7345 field-face (nth 2 entry))
7346 (while (and (re-search-forward regexp nil t)
7350 (unless (search-forward ":" nil t)
7352 (when (and header-face
7353 (not (memq (point) hpoints)))
7354 (push (point) hpoints)
7355 (gnus-put-text-property from (point) 'face header-face))
7356 (when (and field-face
7357 (not (memq (setq from (point)) fpoints)))
7359 (if (re-search-forward "^[^ \t]" nil t)
7361 (goto-char (point-max)))
7362 (gnus-put-text-property from (point) 'face field-face)))))))
7364 (defun gnus-article-highlight-signature ()
7365 "Highlight the signature in an article.
7366 It does this by highlighting everything after
7367 `gnus-signature-separator' using the face `gnus-signature'."
7369 (gnus-with-article-buffer
7370 (let ((inhibit-point-motion-hooks t))
7372 (when (and gnus-signature-face
7373 (gnus-article-narrow-to-signature))
7374 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7375 'face gnus-signature-face)
7377 (gnus-article-search-signature)
7378 (let ((start (match-beginning 0))
7379 (end (set-marker (make-marker) (1+ (match-end 0)))))
7380 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7383 (defun gnus-button-in-region-p (b e prop)
7384 "Say whether PROP exists in the region."
7385 (text-property-not-all b e prop nil))
7387 (defun gnus-article-add-buttons (&optional force)
7388 "Find external references in the article and make buttons of them.
7389 \"External references\" are things like Message-IDs and URLs, as
7390 specified by `gnus-button-alist'."
7391 (interactive (list 'force))
7392 (gnus-with-article-buffer
7393 (let ((inhibit-point-motion-hooks t)
7394 (case-fold-search t)
7395 (alist gnus-button-alist)
7397 ;; Remove all old markers.
7398 (let (marker entry new-list)
7399 (while (setq marker (pop gnus-button-marker-list))
7400 (if (or (< marker (point-min)) (>= marker (point-max)))
7401 (push marker new-list)
7403 (when (setq entry (gnus-button-entry))
7404 (put-text-property (match-beginning (nth 1 entry))
7405 (match-end (nth 1 entry))
7406 'gnus-callback nil))
7407 (set-marker marker nil)))
7408 (setq gnus-button-marker-list new-list))
7409 ;; We skip the headers.
7412 (while (setq entry (pop alist))
7413 (setq regexp (eval (car entry)))
7415 (while (re-search-forward regexp nil t)
7416 (let ((start (match-beginning (nth 1 entry)))
7417 (end (match-end (nth 1 entry)))
7418 (from (match-beginning 0)))
7419 (when (and (or (eq t (nth 2 entry))
7420 (eval (nth 2 entry)))
7421 (not (gnus-button-in-region-p
7422 start end 'gnus-callback)))
7423 ;; That optional form returned non-nil, so we add the
7425 (setq from (set-marker (make-marker) from))
7426 (push from gnus-button-marker-list)
7427 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7428 (gnus-article-extend-url-button from start end))
7429 (gnus-article-add-button start end
7430 'gnus-button-push from)))))))))
7432 (defun gnus-article-extend-url-button (beg start end)
7433 "Extend url button if url is folded into two or more lines.
7434 Return non-nil if button is extended. BEG is a marker that points to
7435 the beginning position of a text containing url. START and END are
7436 the endpoints of a url button before it is extended. The concatenated
7437 url is put as the `gnus-button-url' overlay property on the button."
7438 (let ((opoint (point))
7439 (points (list start end))
7444 (not (looking-at "[\t ]*[\">]")))
7448 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7449 (buffer-substring (point-at-bol) start)))
7451 (setq url (list (buffer-substring start end))
7452 delim (if (match-beginning 1) ">" "\""))
7454 (setq regexp (concat
7455 (when (and (looking-at
7456 message-cite-prefix-regexp)
7457 (< (match-end 0) start))
7458 (regexp-quote (match-string 0)))
7460 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7464 (and (looking-at regexp)
7467 (push (or (match-string 2)
7470 (push (setq end (or (match-end 2)
7473 (push (or (match-beginning 2)
7474 (match-beginning 1))
7476 (match-beginning 2)))
7477 (let (gnus-article-mouse-face widget-mouse-face)
7479 (gnus-article-add-button (pop points) (pop points)
7480 'gnus-button-push beg)))
7481 (let ((overlay (gnus-make-overlay start end)))
7482 (gnus-overlay-put overlay 'evaporate t)
7483 (gnus-overlay-put overlay 'gnus-button-url
7484 (list (mapconcat 'identity (nreverse url) "")))
7485 (when gnus-article-mouse-face
7486 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7488 (goto-char opoint))))
7490 ;; Add buttons to the head of an article.
7491 (defun gnus-article-add-buttons-to-head ()
7492 "Add buttons to the head of the article."
7494 (gnus-with-article-headers
7496 (dolist (entry gnus-header-button-alist)
7497 ;; Each alist entry.
7498 (goto-char (point-min))
7499 (while (re-search-forward (car entry) nil t)
7500 ;; Each header matching the entry.
7501 (setq beg (match-beginning 0))
7502 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7503 (match-beginning 0))
7506 (while (re-search-forward (eval (nth 1 entry)) end t)
7507 ;; Each match within a header.
7508 (let* ((entry (cdr entry))
7509 (start (match-beginning (nth 1 entry)))
7510 (end (match-end (nth 1 entry)))
7511 (form (nth 2 entry)))
7512 (goto-char (match-end 0))
7514 (gnus-article-add-button
7515 start end (nth 3 entry)
7516 (buffer-substring (match-beginning (nth 4 entry))
7517 (match-end (nth 4 entry)))))))
7518 (goto-char end))))))
7520 ;;; External functions:
7522 (defun gnus-article-add-button (from to fun &optional data)
7523 "Create a button between FROM and TO with callback FUN and data DATA."
7524 (when gnus-article-button-face
7525 (gnus-overlay-put (gnus-make-overlay from to nil t)
7526 'face gnus-article-button-face))
7527 (gnus-add-text-properties
7529 (nconc (and gnus-article-mouse-face
7530 (list gnus-mouse-face-prop gnus-article-mouse-face))
7531 (list 'gnus-callback fun)
7532 (and data (list 'gnus-data data))))
7533 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7534 :button-keymap gnus-widget-button-keymap))
7536 ;;; Internal functions:
7538 (defun gnus-article-set-globals ()
7539 (with-current-buffer gnus-summary-buffer
7540 (gnus-set-global-variables)))
7542 (defun gnus-signature-toggle (end)
7543 (gnus-with-article-buffer
7544 (let ((inhibit-point-motion-hooks t))
7545 (if (text-property-any end (point-max) 'article-type 'signature)
7547 (gnus-delete-wash-type 'signature)
7548 (gnus-remove-text-properties-when
7549 'article-type 'signature end (point-max)
7550 (cons 'article-type (cons 'signature
7551 gnus-hidden-properties))))
7552 (gnus-add-wash-type 'signature)
7553 (gnus-add-text-properties-when
7554 'article-type nil end (point-max)
7555 (cons 'article-type (cons 'signature
7556 gnus-hidden-properties)))))
7557 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7558 (gnus-set-mode-line 'article))))
7560 (defun gnus-button-entry ()
7561 ;; Return the first entry in `gnus-button-alist' matching this place.
7562 (let ((alist gnus-button-alist)
7565 (setq entry (pop alist))
7566 (if (looking-at (eval (car entry)))
7571 (defun gnus-button-push (marker)
7572 ;; Push button starting at MARKER.
7575 (let* ((entry (gnus-button-entry))
7576 (inhibit-point-motion-hooks t)
7578 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7579 (get-char-property marker 'gnus-button-url))
7580 (mapcar (lambda (group)
7581 (let ((string (match-string group)))
7582 (set-text-properties
7583 0 (length string) nil string)
7585 (nthcdr 4 entry)))))
7590 (fboundp (symbol-value fun)))
7591 (apply (symbol-value fun) args))
7593 (gnus-message 1 "You must define `%S' to use this button"
7594 (cons fun args)))))))
7596 (defun gnus-parse-news-url (url)
7597 (let (scheme server port group message-id articles)
7600 (goto-char (point-min))
7601 (when (looking-at "\\([A-Za-z]+\\):")
7602 (setq scheme (match-string 1))
7603 (goto-char (match-end 0)))
7604 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7605 (setq server (match-string 1))
7606 (setq port (if (stringp (match-string 3))
7607 (string-to-number (match-string 3))
7609 (goto-char (match-end 0)))
7612 ((looking-at "\\(.*@.*\\)")
7613 (setq message-id (match-string 1)))
7614 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7615 (setq group (match-string 1)
7616 articles (split-string (match-string 2) "-")))
7617 ((looking-at "\\([^/]+\\)/?")
7618 (setq group (match-string 1)))
7620 (error "Unknown news URL syntax"))))
7621 (list scheme server port group message-id articles)))
7623 (defun gnus-button-handle-news (url)
7625 (destructuring-bind (scheme server port group message-id articles)
7626 (gnus-parse-news-url url)
7630 (set-buffer gnus-summary-buffer)
7632 (let ((gnus-refer-article-method
7633 (nconc (list (list 'nntp server))
7634 gnus-refer-article-method))
7635 (nntp-port-number (or port "nntp")))
7636 (gnus-message 7 "Fetching %s with %s"
7637 message-id gnus-refer-article-method)
7638 (gnus-summary-refer-article message-id))
7639 (gnus-summary-refer-article message-id))))
7641 (gnus-button-fetch-group url)))))
7643 (defun gnus-button-patch (library line)
7644 "Visit an Emacs Lisp library LIBRARY on line LINE."
7646 (let ((file (locate-library (file-name-nondirectory library))))
7648 (error "Couldn't find library %s" library))
7650 (goto-line (string-to-number line))))
7652 (defun gnus-button-handle-man (url)
7654 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7655 (when (eq gnus-button-man-handler 'woman)
7656 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7657 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7658 (funcall gnus-button-man-handler url))
7660 (defun gnus-button-handle-info-url (url)
7661 "Fetch an info URL."
7662 (setq url (mm-subst-char-in-string ?+ ?\ url))
7664 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7665 (gnus-info-find-node
7666 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7668 ")" (gnus-url-unhex-string (match-string 2 url)))))
7669 ((string-match "([^)\"]+)[^\"]+" url)
7671 (gnus-replace-in-string
7672 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7673 (gnus-info-find-node url))
7674 (t (error "Can't parse %s" url))))
7676 (defun gnus-button-handle-info-url-gnome (url)
7677 "Fetch GNOME style info URL."
7678 (setq url (mm-subst-char-in-string ?_ ?\ url))
7679 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7680 (gnus-info-find-node
7682 (gnus-url-unhex-string
7683 (match-string 1 url))
7685 (or (gnus-url-unhex-string
7686 (match-string 2 url))
7688 (error "Can't parse %s" url)))
7690 (defun gnus-button-handle-info-url-kde (url)
7691 "Fetch KDE style info URL."
7692 (gnus-info-find-node (gnus-url-unhex-string url)))
7694 ;; (info) will autoload info.el
7695 (declare-function Info-menu "info" (menu-item &optional fork))
7697 (defun gnus-button-handle-info-keystrokes (url)
7698 "Call `info' when pushing the corresponding URL button."
7699 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7704 (defun gnus-button-openpgp (url)
7705 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7707 (mm-url-insert-file-contents-external url)
7708 (pgg-snarf-keys-region (point-min) (point-max))
7709 (pgg-display-output-buffer nil nil nil)))
7711 (defun gnus-button-message-id (message-id)
7713 (with-current-buffer gnus-summary-buffer
7714 (gnus-summary-refer-article message-id)))
7716 (defun gnus-button-fetch-group (address &rest ignore)
7717 "Fetch GROUP specified by ADDRESS."
7718 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7720 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7721 ;; for nntp:// and news://
7722 (setq address (match-string 3 address)))
7723 (if (not (string-match "[:/]" address))
7724 ;; This is just a simple group url.
7725 (gnus-group-read-ephemeral-group address gnus-select-method)
7728 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7730 (error "Can't parse %s" address)
7731 (gnus-group-read-ephemeral-group
7732 (match-string 4 address)
7733 `(nntp ,(match-string 1 address)
7734 (nntp-address ,(match-string 1 address))
7735 (nntp-port-number ,(if (match-end 3)
7736 (match-string 3 address)
7739 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7741 (defun gnus-url-parse-query-string (query &optional downcase)
7742 (let (retval pairs cur key val)
7743 (setq pairs (split-string query "&"))
7745 (setq cur (car pairs)
7747 (if (not (string-match "=" cur))
7749 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7750 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7752 (setq key (downcase key)))
7753 (setq cur (assoc key retval))
7755 (setcdr cur (cons val (cdr cur)))
7756 (setq retval (cons (list key val) retval)))))
7759 (defun gnus-url-mailto (url)
7760 ;; Send mail to someone
7761 (when (string-match "mailto:/*\\(.*\\)" url)
7762 (setq url (substring url (match-beginning 1) nil)))
7763 (let (to args subject func)
7764 (setq args (gnus-url-parse-query-string
7765 (if (string-match "^\\?" url)
7767 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7768 (concat "to=" (match-string 1 url) "&"
7769 (match-string 2 url))
7770 (concat "to=" url)))
7772 subject (cdr-safe (assoc "subject" args)))
7775 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7778 (message-position-on-field (caar args)))
7779 (insert (gnus-replace-in-string
7780 (mapconcat 'identity (reverse (cdar args)) ", ")
7782 (setq args (cdr args)))
7785 (message-goto-subject))))
7787 (defun gnus-button-embedded-url (address)
7788 "Activate ADDRESS with `browse-url'."
7789 (browse-url (gnus-strip-whitespace address)))
7791 ;;; Next/prev buttons in the article buffer.
7793 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7794 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7796 (defvar gnus-prev-page-map
7797 (let ((map (make-sparse-keymap)))
7798 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7799 (define-key map "\r" 'gnus-button-prev-page)
7802 (defvar gnus-next-page-map
7803 (let ((map (make-sparse-keymap)))
7804 (unless (>= emacs-major-version 21)
7805 ;; XEmacs doesn't care.
7806 (set-keymap-parent map gnus-article-mode-map))
7807 (define-key map gnus-mouse-2 'gnus-button-next-page)
7808 (define-key map "\r" 'gnus-button-next-page)
7811 (defun gnus-insert-prev-page-button ()
7813 (inhibit-read-only t))
7815 gnus-prev-page-line-format nil
7816 `(keymap ,gnus-prev-page-map
7818 gnus-callback gnus-article-button-prev-page
7819 article-type annotation))
7821 ;; Exclude a newline.
7824 (when gnus-article-button-face
7825 (gnus-overlay-put (gnus-make-overlay b e nil t)
7826 'face gnus-article-button-face))
7827 (widget-convert-button
7829 :action 'gnus-button-prev-page
7830 :button-keymap gnus-prev-page-map)))
7832 (defun gnus-button-next-page (&optional args more-args)
7833 "Go to the next page."
7835 (let ((win (selected-window)))
7836 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7837 (gnus-article-next-page)
7838 (select-window win)))
7840 (defun gnus-button-prev-page (&optional args more-args)
7841 "Go to the prev page."
7843 (let ((win (selected-window)))
7844 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7845 (gnus-article-prev-page)
7846 (select-window win)))
7848 (defun gnus-insert-next-page-button ()
7850 (inhibit-read-only t))
7851 (gnus-eval-format gnus-next-page-line-format nil
7852 `(keymap ,gnus-next-page-map
7854 gnus-callback gnus-article-button-next-page
7855 article-type annotation))
7857 ;; Exclude a newline.
7860 (when gnus-article-button-face
7861 (gnus-overlay-put (gnus-make-overlay b e nil t)
7862 'face gnus-article-button-face))
7863 (widget-convert-button
7865 :action 'gnus-button-next-page
7866 :button-keymap gnus-next-page-map)))
7868 (defun gnus-article-button-next-page (arg)
7869 "Go to the next page."
7871 (let ((win (selected-window)))
7872 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7873 (gnus-article-next-page)
7874 (select-window win)))
7876 (defun gnus-article-button-prev-page (arg)
7877 "Go to the prev page."
7879 (let ((win (selected-window)))
7880 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7881 (gnus-article-prev-page)
7882 (select-window win)))
7884 (defvar gnus-decode-header-methods
7885 '(mail-decode-encoded-word-region)
7886 "List of methods used to decode headers.
7888 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7889 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7890 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7891 whose names match REGEXP.
7894 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7895 mail-decode-encoded-word-region
7896 (\"chinese\" . rfc1843-decode-region))
7899 (defvar gnus-decode-header-methods-cache nil)
7901 (defun gnus-multi-decode-header (start end)
7902 "Apply the functions from `gnus-encoded-word-methods' that match."
7903 (unless (and gnus-decode-header-methods-cache
7904 (eq gnus-newsgroup-name
7905 (car gnus-decode-header-methods-cache)))
7906 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7907 (dolist (x gnus-decode-header-methods)
7909 (nconc gnus-decode-header-methods-cache (list x))
7910 (if (and gnus-newsgroup-name
7911 (string-match (car x) gnus-newsgroup-name))
7912 (nconc gnus-decode-header-methods-cache
7914 (let ((xlist gnus-decode-header-methods-cache))
7917 (narrow-to-region start end)
7919 (funcall (pop xlist) (point-min) (point-max))))))
7922 ;;; Treatment top-level handling.
7925 (defun gnus-treat-article (condition &optional part-number total-parts type)
7926 (let ((length (- (point-max) (point-min)))
7927 (alist gnus-treatment-function-alist)
7928 (article-goto-body-goes-to-point-min-p t)
7932 (let ((list gnus-article-treat-types))
7934 (when (string-match (pop list) type)
7935 (throw 'found t)))))))
7936 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7938 (gnus-run-hooks 'gnus-part-display-hook)
7939 (dolist (elem alist)
7942 (when (gnus-buffer-live-p gnus-summary-buffer)
7943 (set-buffer gnus-summary-buffer))
7944 (symbol-value (car elem))))
7945 (when (and (or (consp val)
7947 (gnus-treat-predicate val)
7948 (or (not (get (car elem) 'highlight))
7951 (funcall (cadr elem)))))))
7953 ;; Dynamic variables.
7954 (defvar part-number)
7955 (defvar total-parts)
7960 (defun gnus-treat-predicate (val)
7967 (stringp (car val)))
7968 (apply 'gnus-or (mapcar `(lambda (s)
7969 (string-match s ,(or gnus-newsgroup-name "")))
7972 (let ((pred (pop val)))
7975 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7977 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7979 (not (gnus-treat-predicate (car val))))
7981 (equal (car val) type))
7983 (error "%S is not a valid predicate" pred)))))
7991 (eq part-number total-parts))
7995 (error "%S is not a valid value" val))))
7997 (defun gnus-article-encrypt-body (protocol &optional n)
7998 "Encrypt the article body."
8001 (or gnus-article-encrypt-protocol
8002 (completing-read "Encrypt protocol: "
8003 gnus-article-encrypt-protocol-alist
8005 current-prefix-arg))
8006 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8008 (error "Can't find the encrypt protocol %s" protocol))
8009 (if (member gnus-newsgroup-name '("nndraft:delayed"
8012 (error "Can't encrypt the article in group %s"
8013 gnus-newsgroup-name))
8014 (gnus-summary-iterate n
8016 (set-buffer gnus-summary-buffer)
8017 (let ((mail-parse-charset gnus-newsgroup-charset)
8018 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8019 (summary-buffer gnus-summary-buffer)
8021 (gnus-set-global-variables)
8022 (when (gnus-group-read-only-p)
8023 (error "The current newsgroup does not support article encrypt"))
8024 (gnus-summary-show-article t)
8026 (or (mail-header-references gnus-current-headers) ""))
8027 (set-buffer gnus-article-buffer)
8028 (let* ((inhibit-read-only t)
8030 (mapcar (lambda (field)
8031 (and (save-restriction
8032 (message-narrow-to-head)
8033 (goto-char (point-min))
8034 (search-forward field nil t))
8036 (message-narrow-to-field)
8038 (delete-region (point-min) (point-max))
8040 '("Content-Type:" "Content-Transfer-Encoding:"
8041 "Content-Disposition:"))))
8042 (message-narrow-to-head)
8043 (message-remove-header "MIME-Version")
8044 (goto-char (point-max))
8045 (setq point (point))
8046 (insert (apply 'concat headers))
8048 (narrow-to-region point (point-max))
8049 (let ((message-options message-options))
8050 (message-options-set 'message-sender user-mail-address)
8051 (message-options-set 'message-recipients user-mail-address)
8052 (message-options-set 'message-sign-encrypt 'not)
8054 (goto-char (point-min))
8055 (insert "MIME-Version: 1.0\n")
8057 (gnus-summary-edit-article-done
8058 references nil summary-buffer t))
8059 (when gnus-keep-backlog
8060 (gnus-backlog-remove-article
8061 (car gnus-article-current) (cdr gnus-article-current)))
8063 (when (get-buffer gnus-original-article-buffer)
8064 (set-buffer gnus-original-article-buffer)
8065 (setq gnus-original-article nil)))
8066 (when gnus-use-cache
8067 (gnus-cache-update-article
8068 (car gnus-article-current) (cdr gnus-article-current))))))))
8070 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8071 "The following specs can be used:
8072 %t The security MIME type
8075 %D Details if button is pressed")
8077 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8078 "The following specs can be used:
8079 %t The security MIME type
8082 %D Details if button is pressed")
8084 (defvar gnus-mime-security-button-line-format-alist
8085 '((?t gnus-tmp-type ?s)
8086 (?i gnus-tmp-info ?s)
8087 (?d gnus-tmp-details ?s)
8088 (?D gnus-tmp-pressed-details ?s)))
8090 (defvar gnus-mime-security-button-commands
8091 '((gnus-article-press-button "\r" "Show Detail")
8095 (gnus-mime-security-save-part "o" "Save...")
8104 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8107 (defvar gnus-mime-security-button-map
8108 (let ((map (make-sparse-keymap)))
8109 (define-key map gnus-mouse-2 'gnus-article-push-button)
8110 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8111 (dolist (c gnus-mime-security-button-commands)
8112 (define-key map (cadr c) (car c)))
8116 gnus-mime-security-button-menu gnus-mime-security-button-map
8117 "Security button menu."
8121 (unless (eq (car c) 'undefined)
8122 (vector (caddr c) (car c) :active t)))
8123 gnus-mime-security-button-commands))))
8125 (defun gnus-mime-security-button-menu (event prefix)
8126 "Construct a context-sensitive menu of security commands."
8127 (interactive "e\nP")
8128 (save-window-excursion
8129 (let ((pos (event-start event)))
8130 (select-window (posn-window pos))
8131 (goto-char (posn-point pos))
8132 (gnus-article-check-buffer)
8133 (popup-menu gnus-mime-security-button-menu nil prefix))))
8135 (defvar gnus-mime-security-details-buffer nil)
8137 (defvar gnus-mime-security-button-pressed nil)
8139 (defvar gnus-mime-security-show-details-inline t
8140 "If non-nil, show details in the article buffer.")
8142 (defun gnus-mime-security-verify-or-decrypt (handle)
8143 (mm-remove-parts (cdr handle))
8144 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8145 point (inhibit-read-only t))
8147 (goto-char (car region)))
8148 (setq point (point))
8149 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8150 (let* ((mm-verify-option 'known)
8151 (mm-decrypt-option 'known)
8152 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8153 (unless (eq nparts (cdr handle))
8154 (mm-destroy-parts (cdr handle))
8155 (setcdr handle nparts))))
8156 (gnus-mime-display-security handle)
8158 (delete-region (point) (cdr region))
8159 (set-marker (car region) nil)
8160 (set-marker (cdr region) nil))
8163 (defun gnus-mime-security-show-details (handle)
8164 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8166 (gnus-message 5 "No details.")
8167 (if gnus-mime-security-show-details-inline
8168 (let ((gnus-mime-security-button-pressed
8169 (not (get-text-property (point) 'gnus-mime-details)))
8170 (gnus-mime-security-button-line-format
8171 (get-text-property (point) 'gnus-line-format))
8172 (inhibit-read-only t))
8174 (while (eq (get-text-property (point) 'gnus-line-format)
8175 gnus-mime-security-button-line-format)
8179 (narrow-to-region (point) (point))
8180 (gnus-insert-mime-security-button handle))
8181 (delete-region (point)
8182 (or (text-property-not-all
8185 gnus-mime-security-button-line-format)
8188 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8189 (with-current-buffer gnus-mime-security-details-buffer
8192 (setq gnus-mime-security-details-buffer
8193 (gnus-get-buffer-create "*MIME Security Details*")))
8194 (with-current-buffer gnus-mime-security-details-buffer
8196 (goto-char (point-min)))
8197 (pop-to-buffer gnus-mime-security-details-buffer)))))
8199 (defun gnus-mime-security-press-button (handle)
8201 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8202 (gnus-mime-security-show-details handle)
8203 (gnus-mime-security-verify-or-decrypt handle))))
8205 (defun gnus-insert-mime-security-button (handle &optional displayed)
8206 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8209 (or (nth 2 (assoc protocol mm-verify-function-alist))
8210 (nth 2 (assoc protocol mm-decrypt-function-alist))
8212 (if (equal (car handle) "multipart/signed")
8213 " Signed" " Encrypted")
8216 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8219 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8220 gnus-tmp-pressed-details
8222 (setq gnus-tmp-details
8223 (if gnus-tmp-details
8224 (concat "\n" gnus-tmp-details)
8226 (setq gnus-tmp-pressed-details
8227 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8232 gnus-mime-security-button-line-format
8233 gnus-mime-security-button-line-format-alist
8234 `(keymap ,gnus-mime-security-button-map
8235 gnus-callback gnus-mime-security-press-button
8236 gnus-line-format ,gnus-mime-security-button-line-format
8237 gnus-mime-details ,gnus-mime-security-button-pressed
8238 article-type annotation
8241 ;; Exclude a newline.
8244 (when gnus-article-button-face
8245 (gnus-overlay-put (gnus-make-overlay b e nil t)
8246 'face gnus-article-button-face))
8247 (widget-convert-button
8250 :action 'gnus-widget-press-button
8251 :button-keymap gnus-mime-security-button-map
8253 (lambda (widget/window &optional overlay pos)
8254 ;; Needed to properly clear the message due to a bug in
8255 ;; wid-edit (XEmacs only).
8256 (when (boundp 'help-echo-owns-message)
8257 (setq help-echo-owns-message t))
8259 "%S: show detail; %S: more options"
8260 (aref gnus-mouse-2 0)
8261 (aref gnus-down-mouse-3 0))))))
8263 (defun gnus-mime-display-security (handle)
8265 (narrow-to-region (point) (point))
8266 (unless (gnus-unbuttonized-mime-type-p (car handle))
8267 (gnus-insert-mime-security-button handle))
8268 (gnus-mime-display-part (cadr handle))
8271 (unless (gnus-unbuttonized-mime-type-p (car handle))
8272 (let ((gnus-mime-security-button-line-format
8273 gnus-mime-security-button-end-line-format))
8274 (gnus-insert-mime-security-button handle)))
8275 (mm-set-handle-multipart-parameter
8277 (cons (set-marker (make-marker) (point-min))
8278 (set-marker (make-marker) (point-max))))
8279 (goto-char (point-max))))
8281 (defun gnus-mime-security-run-function (function)
8282 "Run FUNCTION with the security part under point."
8283 (gnus-article-check-buffer)
8284 (let ((data (get-text-property (point) 'gnus-data))
8286 (when (and (stringp (car-safe data))
8287 (setq buffer (mm-handle-multipart-original-buffer data))
8288 (setq handle (cadr data)))
8289 (if (bufferp (mm-handle-buffer handle))
8291 (setq handle (cons buffer (copy-sequence (cdr handle))))
8292 (mm-handle-set-undisplayer handle nil))
8293 (setq handle (mm-make-handle
8295 (mm-handle-multipart-ctl-parameter handle 'protocol)
8296 nil nil nil nil nil nil)))
8297 (funcall function handle))))
8299 (defun gnus-mime-security-save-part ()
8300 "Save the security part under point."
8302 (gnus-mime-security-run-function 'mm-save-part))
8304 (defun gnus-mime-security-pipe-part ()
8305 "Pipe the security part under point to a process."
8307 (gnus-mime-security-run-function 'mm-pipe-part))
8313 (run-hooks 'gnus-art-load-hook)
8315 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8316 ;;; gnus-art.el ends here