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.
33 (defvar w3m-minor-mode-map))
36 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
38 (let ((recursive-load-depth-limit 100))
51 (autoload 'gnus-msg-mail "gnus-msg" nil t)
52 (autoload 'gnus-button-mailto "gnus-msg")
53 (autoload 'gnus-button-reply "gnus-msg" nil t)
54 (autoload 'parse-time-string "parse-time" nil nil)
55 (autoload 'ansi-color-apply-on-region "ansi-color")
56 (autoload 'mm-url-insert-file-contents-external "mm-url")
57 (autoload 'mm-extern-cache-contents "mm-extern")
59 (defgroup gnus-article nil
61 :link '(custom-manual "(gnus)Article Buffer")
64 (defgroup gnus-article-treat nil
65 "Treating article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
69 (defgroup gnus-article-hiding nil
70 "Hiding article parts."
71 :link '(custom-manual "(gnus)Article Hiding")
74 (defgroup gnus-article-highlight nil
75 "Article highlighting."
76 :link '(custom-manual "(gnus)Article Highlighting")
80 (defgroup gnus-article-signature nil
82 :link '(custom-manual "(gnus)Article Signature")
85 (defgroup gnus-article-headers nil
87 :link '(custom-manual "(gnus)Hiding Headers")
90 (defgroup gnus-article-washing nil
91 "Special commands on articles."
92 :link '(custom-manual "(gnus)Article Washing")
95 (defgroup gnus-article-emphasis nil
96 "Fontisizing articles."
97 :link '(custom-manual "(gnus)Article Fontisizing")
100 (defgroup gnus-article-saving nil
102 :link '(custom-manual "(gnus)Saving Articles")
103 :group 'gnus-article)
105 (defgroup gnus-article-mime nil
106 "Worshiping the MIME wonder."
107 :link '(custom-manual "(gnus)Using MIME")
108 :group 'gnus-article)
110 (defgroup gnus-article-buttons nil
111 "Pushable buttons in the article buffer."
112 :link '(custom-manual "(gnus)Article Buttons")
113 :group 'gnus-article)
115 (defgroup gnus-article-various nil
116 "Other article options."
117 :link '(custom-manual "(gnus)Misc Article")
118 :group 'gnus-article)
120 (defcustom gnus-ignored-headers
123 (concat "^" header ":"))
124 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
125 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
126 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
127 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
128 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
129 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
130 "X-Attribution" "X-Originating-IP" "Delivered-To"
131 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
132 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
133 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
134 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
135 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
136 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
137 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
138 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
139 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
140 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
141 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
142 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
143 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
144 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
145 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
146 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
147 "List-[A-Za-z]+" "X-Listprocessor-Version"
148 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
149 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
150 "X-Received" "Content-length" "X-precedence"
151 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
152 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
153 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
154 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
155 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
156 "X-Content-length" "X-Posting-Agent" "Original-Received"
157 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
158 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
159 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
160 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
161 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
162 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
163 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
164 "Envelope-Sender" "Envelope-Recipients"))
165 "*All headers that start with this regexp will be hidden.
166 This variable can also be a list of regexps of headers to be ignored.
167 If `gnus-visible-headers' is non-nil, this variable will be ignored."
168 :type '(choice :custom-show nil
171 :group 'gnus-article-hiding)
173 (defcustom gnus-visible-headers
174 "^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:"
175 "*All headers that do not match this regexp will be hidden.
176 This variable can also be a list of regexp of headers to remain visible.
177 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
178 :type '(repeat :value-to-internal (lambda (widget value)
179 (custom-split-regexp-maybe value))
180 :match (lambda (widget value)
182 (widget-editable-list-match widget value)))
184 :group 'gnus-article-hiding)
186 (defcustom gnus-sorted-header-list
187 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189 "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
193 :type '(repeat regexp)
194 :group 'gnus-article-hiding)
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197 "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
200 'empty Headers with no content.
201 'newsgroups Newsgroup identical to Gnus group.
202 'to-address To identical to To-address.
203 'to-list To identical to To-list.
204 'cc-list CC identical to To-list.
205 'followup-to Followup-to identical to Newsgroups.
206 'reply-to Reply-to identical to From.
207 'date Date less than four days old.
208 'long-to To and/or Cc longer than 1024 characters.
209 'many-to Multiple To and/or Cc."
210 :type '(set (const :tag "Headers with no content." empty)
211 (const :tag "Newsgroups identical to Gnus group." newsgroups)
212 (const :tag "To identical to To-address." to-address)
213 (const :tag "To identical to To-list." to-list)
214 (const :tag "CC identical to To-list." cc-list)
215 (const :tag "Followup-to identical to Newsgroups." followup-to)
216 (const :tag "Reply-to identical to From." reply-to)
217 (const :tag "Date less than four days old." date)
218 (const :tag "To and/or Cc longer than 1024 characters." long-to)
219 (const :tag "Multiple To and/or Cc headers." many-to))
220 :group 'gnus-article-hiding)
222 (defcustom gnus-article-skip-boring nil
223 "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text. Boring text is controlled by
227 `gnus-article-boring-faces'."
230 :group 'gnus-article-hiding)
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233 "Regexp matching signature separator.
234 This can also be a list of regexps. In that case, it will be checked
235 from head to tail looking for a separator. Searches will be done from
236 the end of the buffer."
237 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
239 (repeat :tag "List of regexp" regexp))
240 :group 'gnus-article-signature)
242 (defcustom gnus-signature-limit nil
243 "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number. If it is a floating point number, no signature may be
246 longer (in lines) than that number. If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer. If it is a string, it will be used as a
249 regexp. If it matches, the text in question is not a signature.
251 This can also be a list of the above values."
252 :type '(choice (const nil)
256 (regexp :value ".*"))
257 :group 'gnus-article-signature)
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260 "Property list to use for hiding text."
262 :group 'gnus-article-hiding)
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267 (if (featurep 'xemacs)
268 (if (or (gnus-image-type-available-p 'xface)
269 (gnus-image-type-available-p 'pbm))
270 'gnus-display-x-face-in-from
271 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
272 (if (gnus-image-type-available-p 'pbm)
273 'gnus-display-x-face-in-from
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
276 "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously. The compressed face will be piped to this command."
279 :type `(choice string
280 (function-item gnus-display-x-face-in-from)
284 :group 'gnus-article-washing)
286 (defcustom gnus-article-x-face-too-ugly nil
287 "Regexp matching posters whose face shouldn't be shown automatically."
288 :type '(choice regexp (const nil))
289 :group 'gnus-article-washing)
291 (defcustom gnus-article-banner-alist nil
292 "Banner alist for stripping.
294 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
296 :type '(repeat (cons symbol regexp))
297 :group 'gnus-article-washing)
299 (gnus-define-group-parameter
302 "Alist of regexps (to match group names) and banner."
303 :variable-group gnus-article-washing
305 '(choice :tag "Banner"
307 (const :tag "Remove signature" signature)
308 (symbol :tag "Item in `gnus-article-banner-alist'" none)
310 (const :tag "None" nil))
312 "If non-nil, specify how to remove `banners' from articles.
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'. Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
320 (defcustom gnus-article-address-banner-alist nil
321 "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements. For example:
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
332 (regexp :tag "Address")
333 (choice :tag "Banner" :value nil
334 (const :tag "Remove signature" signature)
335 (symbol :tag "Item in `gnus-article-banner-alist'" none)
337 (const :tag "None" nil))))
339 :group 'gnus-article-washing)
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
347 (defun gnus-emphasis-custom-value-to-external (value)
348 (gnus-emphasis-custom-with-format
349 (if (consp (car value))
350 (list (format format (car (car value)) (cdr (car value)))
352 (if (nth 1 value) 2 3)
356 (defun gnus-emphasis-custom-value-to-internal (value)
357 (gnus-emphasis-custom-with-format
358 (let ((regexp (concat "\\`"
359 (format (regexp-quote format)
360 "\\([^()]+\\)" "\\([^()]+\\)")
363 (if (string-match regexp (setq pattern (car value)))
364 (list (cons (match-string 1 pattern) (match-string 2 pattern))
369 (defcustom gnus-emphasis-alist
371 '(("\\*" "\\*" bold nil 2)
374 ("_/" "/_" underline-italic)
375 ("_\\*" "\\*_" underline-bold)
376 ("\\*/" "/\\*" bold-italic)
377 ("_\\*/" "/\\*_" underline-bold-italic))))
379 (gnus-emphasis-custom-with-format
380 (mapcar (lambda (spec)
381 (list (format format (car spec) (cadr spec))
384 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
386 '(;; I've never seen anyone use this strikethru convention whereas I've
387 ;; several times seen it triggered by normal text. --Stef
388 ;; Miles suggests that this form is sometimes used but for italics,
389 ;; so maybe we should map it to `italic'.
390 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391 ;; 2 3 gnus-emphasis-strikethru)
392 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393 2 3 gnus-emphasis-underline))))
394 "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
397 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399 The first element is a regular expression to be matched. The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word. The third is a number that says what
402 regexp grouping should be displayed and highlighted. The fourth
403 is the face used for highlighting."
407 :format "%[Customizing Style%]\n%v"
409 (group :tag "Default"
410 :value ("" 0 0 default)
413 (let ((value (widget-get
414 (cadr (widget-get (widget-get widget :parent)
417 (if (not (eq (nth 2 value) 'default))
421 (gnus-emphasis-custom-value-to-external value))))
422 (widget-group-value-create widget))
424 (integer :format "Match group: %v")
425 (integer :format "Emphasize group: %v")
428 :value (("_" . "_") nil default)
430 (regexp :format "Start regexp: %v")
431 (regexp :format "End regexp: %v"))
432 (boolean :format "Show start and end patterns: %[%v%]\n"
433 :on " On " :off " Off ")
435 :get (lambda (symbol)
436 (mapcar 'gnus-emphasis-custom-value-to-internal
437 (default-value symbol)))
438 :set (lambda (symbol value)
439 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
441 :group 'gnus-article-emphasis)
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444 "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
449 :group 'gnus-article-emphasis
452 (defface gnus-emphasis-bold '((t (:bold t)))
453 "Face used for displaying strong emphasized text (*word*)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-italic '((t (:italic t)))
457 "Face used for displaying italic emphasized text (/word/)."
458 :group 'gnus-article-emphasis)
460 (defface gnus-emphasis-underline '((t (:underline t)))
461 "Face used for displaying underlined emphasized text (_word_)."
462 :group 'gnus-article-emphasis)
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465 "Face used for displaying underlined bold emphasized text (_*word*_)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469 "Face used for displaying underlined italic emphasized text (_/word/_)."
470 :group 'gnus-article-emphasis)
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473 "Face used for displaying bold italic emphasized text (/*word*/)."
474 :group 'gnus-article-emphasis)
476 (defface gnus-emphasis-underline-bold-italic
477 '((t (:bold t :italic t :underline t)))
478 "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483 '((t (:strikethru t)))
484 '((t (:strike-through t))))
485 "Face used for displaying strike-through text (-word-)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494 "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
497 The variable can also be function, which should return a complete Date
498 header. The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500 :type '(choice string function)
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
504 (defcustom gnus-save-all-headers t
505 "*If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
509 :group 'gnus-article-saving
512 (defcustom gnus-prompt-before-saving 'always
513 "*This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files. If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles. If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
523 (sexp :tag "once" :format "%t\n" :value t)))
525 (defcustom gnus-saved-headers gnus-visible-headers
526 "Headers to keep if `gnus-save-all-headers' is nil.
527 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528 If that variable is nil, however, all headers that match this regexp
529 will be kept while the rest will be deleted before saving. This and
530 `gnus-save-all-headers' will be overridden by the `:headers' property
531 that the symbol of the saver function, which is specified by
532 `gnus-default-article-saver', might have."
533 :group 'gnus-article-saving
536 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
537 "A function to save articles in your favourite format.
538 The function will be called by way of the `gnus-summary-save-article'
539 command, and friends such as `gnus-summary-save-article-rmail'.
541 Gnus provides the following functions:
543 * gnus-summary-save-in-rmail (Rmail format)
544 * gnus-summary-save-in-mail (Unix mail format)
545 * gnus-summary-save-in-folder (MH folder)
546 * gnus-summary-save-in-file (article format)
547 * gnus-summary-save-body-in-file (article body)
548 * gnus-summary-save-in-vm (use VM's folder format)
549 * gnus-summary-write-to-file (article format -- overwrite)
550 * gnus-summary-write-body-to-file (article body -- overwrite)
552 The symbol of each function may have the following properties:
555 The value non-nil means save decoded articles. This is meaningful
556 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
557 `gnus-summary-write-to-file', and `gnus-summary-write-body-to-file'.
560 The value specifies an alternative function which appends, not
561 overwrites, articles to a file. This implies that when saving many
562 articles at a time, `gnus-prompt-before-saving' is bound to t and all
563 articles are saved in a single file. This is meaningful only with
564 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
567 The value specifies the symbol of a variable of which the value
568 specifies headers to be saved. If it is omitted,
569 `gnus-save-all-headers' and `gnus-saved-headers' control what
570 headers should be saved."
571 :group 'gnus-article-saving
572 :type '(radio (function-item gnus-summary-save-in-rmail)
573 (function-item gnus-summary-save-in-mail)
574 (function-item gnus-summary-save-in-folder)
575 (function-item gnus-summary-save-in-file)
576 (function-item gnus-summary-save-body-in-file)
577 (function-item gnus-summary-save-in-vm)
578 (function-item gnus-summary-write-to-file)
579 (function-item gnus-summary-write-body-to-file)
582 (defcustom gnus-article-save-coding-system
583 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
584 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
585 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
586 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
587 "Coding system used to save decoded articles to a file.
589 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
590 which can safely encode any characters in text. This is used by the
593 * gnus-summary-save-article-file
594 * gnus-summary-save-article-body-file
595 * gnus-summary-write-article-file
596 * gnus-summary-write-article-body-file
598 and the functions to which you may set `gnus-default-article-saver':
600 * gnus-summary-save-in-file
601 * gnus-summary-save-body-in-file
602 * gnus-summary-write-to-file
603 * gnus-summary-write-body-to-file
605 Those commands and functions save just text displayed in the article
606 buffer to a file if the value of this variable is non-nil. Note that
607 buttonized MIME parts will be lost in a saved file in that case.
608 Otherwise, raw articles will be saved."
609 :group 'gnus-article-saving
611 :format "%{%t%}:\n %[Value Menu%] %v"
612 (const :tag "Save raw articles" nil)
615 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
616 '((const :tag "UTF-8" utf-8)
617 (const :tag "iso-2022-7bit" iso-2022-7bit)
618 (const :tag "Emacs internal" emacs-mule)
619 (const :tag "escape-quoted" escape-quoted))))
620 (symbol :tag "Coding system")))
622 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
623 "A function generating a file name to save articles in Rmail format.
624 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
625 :group 'gnus-article-saving
628 (defcustom gnus-mail-save-name 'gnus-plain-save-name
629 "A function generating a file name to save articles in Unix mail format.
630 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
631 :group 'gnus-article-saving
634 (defcustom gnus-folder-save-name 'gnus-folder-save-name
635 "A function generating a file name to save articles in MH folder.
636 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
637 :group 'gnus-article-saving
640 (defcustom gnus-file-save-name 'gnus-numeric-save-name
641 "A function generating a file name to save articles in article format.
642 The function is called with NEWSGROUP, HEADERS, and optional
644 :group 'gnus-article-saving
647 (defcustom gnus-split-methods
648 '((gnus-article-archive-name)
649 (gnus-article-nndoc-name))
650 "*Variable used to suggest where articles are to be saved.
651 For instance, if you would like to save articles related to Gnus in
652 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
653 you could set this variable to something like:
655 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
656 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
658 This variable is an alist where the key is the match and the
659 value is a list of possible files to save in if the match is
662 If the match is a string, it is used as a regexp match on the
663 article. If the match is a symbol, that symbol will be funcalled
664 from the buffer of the article to be saved with the newsgroup as the
665 parameter. If it is a list, it will be evaled in the same buffer.
667 If this form or function returns a string, this string will be used as a
668 possible file name; and if it returns a non-nil list, that list will be
669 used as possible file names."
670 :group 'gnus-article-saving
671 :type '(repeat (choice (list :value (fun) function)
672 (cons :value ("" "") regexp (repeat string))
675 (defcustom gnus-page-delimiter "^\^L"
676 "*Regexp describing what to use as article page delimiters.
677 The default value is \"^\^L\", which is a form linefeed at the
678 beginning of a line."
680 :group 'gnus-article-various)
682 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
683 "*The format specification for the article mode line.
684 See `gnus-summary-mode-line-format' for a closer description.
686 The following additional specs are available:
688 %w The article washing status.
689 %m The number of MIME parts in the article."
691 :group 'gnus-article-various)
693 (defcustom gnus-article-mode-hook nil
694 "*A hook for Gnus article mode."
696 :group 'gnus-article-various)
698 (when (featurep 'xemacs)
699 ;; Extracted from gnus-xmas-define in order to preserve user settings
700 (when (fboundp 'turn-off-scroll-in-place)
701 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
702 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
703 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
705 (defcustom gnus-article-menu-hook nil
706 "*Hook run after the creation of the article mode menu."
708 :group 'gnus-article-various)
710 (defcustom gnus-article-prepare-hook nil
711 "*A hook called after an article has been prepared in the article buffer."
713 :group 'gnus-article-various)
715 (defcustom gnus-copy-article-ignored-headers nil
716 "List of headers to be removed when copying an article.
717 Each element is a regular expression."
718 :version "23.0" ;; No Gnus
719 :type '(repeat regexp)
720 :group 'gnus-article-various)
722 (make-obsolete-variable 'gnus-article-hide-pgp-hook
723 "This variable is obsolete in Gnus 5.10.")
726 '((t (:weight bold)))
727 "Face used for highlighting a button in the article buffer."
728 :group 'gnus-article-buttons)
730 (defcustom gnus-article-button-face 'gnus-button
731 "Face used for highlighting buttons in the article buffer.
733 An article button is a piece of text that you can activate by pressing
734 `RET' or `mouse-2' above it."
736 :group 'gnus-article-buttons)
738 (defcustom gnus-article-mouse-face 'highlight
739 "Face used for mouse highlighting in the article buffer.
741 Article buttons will be displayed in this face when the cursor is
744 :group 'gnus-article-buttons)
746 (defcustom gnus-signature-face 'gnus-signature
747 "Face used for highlighting a signature in the article buffer.
748 Obsolete; use the face `gnus-signature' for customizations instead."
750 :group 'gnus-article-highlight
751 :group 'gnus-article-signature)
753 (defface gnus-signature
756 "Face used for highlighting a signature in the article buffer."
757 :group 'gnus-article-highlight
758 :group 'gnus-article-signature)
759 ;; backward-compatibility alias
760 (put 'gnus-signature-face 'face-alias 'gnus-signature)
762 (defface gnus-header-from
765 (:foreground "PaleGreen1"))
768 (:foreground "red3"))
771 "Face used for displaying from headers."
772 :group 'gnus-article-headers
773 :group 'gnus-article-highlight)
774 ;; backward-compatibility alias
775 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
777 (defface gnus-header-subject
780 (:foreground "SeaGreen1"))
783 (:foreground "red4"))
785 (:bold t :italic t)))
786 "Face used for displaying subject headers."
787 :group 'gnus-article-headers
788 :group 'gnus-article-highlight)
789 ;; backward-compatibility alias
790 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
792 (defface gnus-header-newsgroups
795 (:foreground "yellow" :italic t))
798 (:foreground "MidnightBlue" :italic t))
801 "Face used for displaying newsgroups headers.
802 In the default setup this face is only used for crossposted
804 :group 'gnus-article-headers
805 :group 'gnus-article-highlight)
806 ;; backward-compatibility alias
807 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
809 (defface gnus-header-name
812 (:foreground "SpringGreen2"))
815 (:foreground "maroon"))
818 "Face used for displaying header names."
819 :group 'gnus-article-headers
820 :group 'gnus-article-highlight)
821 ;; backward-compatibility alias
822 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
824 (defface gnus-header-content
827 (:foreground "SpringGreen1" :italic t))
830 (:foreground "indianred4" :italic t))
832 (:italic t))) "Face used for displaying header content."
833 :group 'gnus-article-headers
834 :group 'gnus-article-highlight)
835 ;; backward-compatibility alias
836 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
838 (defcustom gnus-header-face-alist
839 '(("From" nil gnus-header-from)
840 ("Subject" nil gnus-header-subject)
841 ("Newsgroups:.*," nil gnus-header-newsgroups)
842 ("" gnus-header-name gnus-header-content))
843 "*Controls highlighting of article headers.
845 An alist of the form (HEADER NAME CONTENT).
847 HEADER is a regular expression which should match the name of a
848 header and NAME and CONTENT are either face names or nil.
850 The name of each header field will be displayed using the face
851 specified by the first element in the list where HEADER matches
852 the header name and NAME is non-nil. Similarly, the content will
853 be displayed by the first non-nil matching CONTENT face."
854 :group 'gnus-article-headers
855 :group 'gnus-article-highlight
856 :type '(repeat (list (regexp :tag "Header")
858 (item :tag "skip" nil)
859 (face :value default))
860 (choice :tag "Content"
861 (item :tag "skip" nil)
862 (face :value default)))))
864 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
865 '((xface . (:face gnus-x-face)))
866 '((pbm . (:face gnus-x-face))
868 "Alist of image types and properties applied to Face and X-Face images.
871 ;; Specify the altitude of Face images in the From header.
872 \(setq gnus-face-properties-alist
873 '((pbm . (:face gnus-x-face :ascent 80))
874 (png . (:ascent 80))))
876 ;; Show Face images as pressed buttons.
877 \(setq gnus-face-properties-alist
878 '((pbm . (:face gnus-x-face :relief -2))
879 (png . (:relief -2))))
881 See the manual for the valid properties for various image types.
882 Currently, `pbm' is used for X-Face images and `png' is used for Face
883 images in Emacs. Only the `:face' property is effective on the `xface'
884 image type in XEmacs if it is built with the libcompface library."
885 :version "23.0" ;; No Gnus
886 :group 'gnus-article-headers
887 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
889 (defcustom gnus-article-decode-hook
890 '(article-decode-charset article-decode-encoded-words
891 article-decode-group-name article-decode-idna-rhs)
892 "*Hook run to decode charsets in articles."
893 :group 'gnus-article-headers
896 (defcustom gnus-display-mime-function 'gnus-display-mime
897 "Function to display MIME articles."
898 :group 'gnus-article-mime
901 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
902 "Function used to decode headers.")
904 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
905 "Function used to decode addresses.")
907 (defvar gnus-article-dumbquotes-map
927 "Table for MS-to-Latin1 translation.")
929 (defcustom gnus-ignored-mime-types nil
930 "List of MIME types that should be ignored by Gnus."
932 :group 'gnus-article-mime
933 :type '(repeat regexp))
935 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
936 "List of MIME types that should not be given buttons when rendered inline.
937 See also `gnus-buttonized-mime-types' which may override this variable.
938 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
940 :group 'gnus-article-mime
941 :type '(repeat regexp))
943 (defcustom gnus-buttonized-mime-types nil
944 "List of MIME types that should be given buttons when rendered inline.
945 If set, this variable overrides `gnus-unbuttonized-mime-types'.
946 To see e.g. security buttons you could set this to
947 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
948 this list to display radio buttons that allow you to choose one of two
949 media types those mails include. See also `mm-discouraged-alternatives'.
950 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
952 :group 'gnus-article-mime
953 :type '(repeat regexp))
955 (defcustom gnus-inhibit-mime-unbuttonizing nil
956 "If non-nil, all MIME parts get buttons.
957 When nil (the default value), then some MIME parts do not get buttons,
958 as described by the variables `gnus-buttonized-mime-types' and
959 `gnus-unbuttonized-mime-types'."
961 :group 'gnus-article-mime
964 (defcustom gnus-body-boundary-delimiter "_"
965 "String used to delimit header and body.
966 This variable is used by `gnus-article-treat-body-boundary' which can
967 be controlled by `gnus-treat-body-boundary'."
969 :group 'gnus-article-various
970 :type '(choice (item :tag "None" :value nil)
973 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
975 "Defines the location of the faces database.
976 For information on obtaining this database of pretty pictures, please
977 see http://www.cs.indiana.edu/picons/ftp/index.html"
979 :type '(repeat directory)
980 :link '(url-link :tag "download"
981 "http://www.cs.indiana.edu/picons/ftp/index.html")
982 :link '(custom-manual "(gnus)Picons")
985 (defun gnus-picons-installed-p ()
986 "Say whether picons are installed on your machine."
987 (let ((installed nil))
988 (dolist (database gnus-picon-databases)
989 (when (file-exists-p database)
993 (defcustom gnus-article-mime-part-function nil
994 "Function called with a MIME handle as the argument.
995 This is meant for people who want to do something automatic based
996 on parts -- for instance, adding Vcard info to a database."
997 :group 'gnus-article-mime
998 :type '(choice (const nil)
1001 (defcustom gnus-mime-multipart-functions nil
1002 "An alist of MIME types to functions to display them."
1004 :group 'gnus-article-mime
1005 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1007 (defcustom gnus-article-date-lapsed-new-header nil
1008 "Whether the X-Sent and Date headers can coexist.
1009 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1010 either replace the old \"Date:\" header (if this variable is nil), or
1011 be added below it (otherwise)."
1013 :group 'gnus-article-headers
1016 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1017 "Function called with a MIME handle as the argument.
1018 This is meant for people who want to view first matched part.
1019 For `undisplayed-alternative' (default), the first undisplayed
1020 part or alternative part is used. For `undisplayed', the first
1021 undisplayed part is used. For a function, the first part which
1022 the function return t is used. For nil, the first part is
1025 :group 'gnus-article-mime
1027 (item :tag "first" :value nil)
1028 (item :tag "undisplayed" :value undisplayed)
1029 (item :tag "undisplayed or alternative"
1030 :value undisplayed-alternative)
1033 (defcustom gnus-mime-action-alist
1034 '(("save to file" . gnus-mime-save-part)
1035 ("save and strip" . gnus-mime-save-part-and-strip)
1036 ("replace with file" . gnus-mime-replace-part)
1037 ("delete part" . gnus-mime-delete-part)
1038 ("display as text" . gnus-mime-inline-part)
1039 ("view the part" . gnus-mime-view-part)
1040 ("pipe to command" . gnus-mime-pipe-part)
1041 ("toggle display" . gnus-article-press-button)
1042 ("toggle display" . gnus-article-view-part-as-charset)
1043 ("view as type" . gnus-mime-view-part-as-type)
1044 ("view internally" . gnus-mime-view-part-internally)
1045 ("view externally" . gnus-mime-view-part-externally))
1046 "An alist of actions that run on the MIME attachment."
1047 :group 'gnus-article-mime
1048 :type '(repeat (cons (string :tag "name")
1051 (defcustom gnus-auto-select-part 1
1052 "Advance to next MIME part when deleting or stripping parts.
1054 When 0, point will be placed on the same part as before. When
1055 positive (negative), move point forward (backwards) this many
1056 parts. When nil, redisplay article."
1057 :version "23.0" ;; No Gnus
1058 :group 'gnus-article-mime
1059 :type '(choice (const nil :tag "Redisplay article.")
1060 (const 1 :tag "Next part.")
1061 (const 0 :tag "Current part.")
1065 ;;; The treatment variables
1068 (defvar gnus-part-display-hook nil
1069 "Hook called on parts that are to receive treatment.")
1071 (defvar gnus-article-treat-custom
1072 '(choice (const :tag "Off" nil)
1074 (const :tag "Header" head)
1075 (const :tag "First" first)
1076 (const :tag "Last" last)
1077 (integer :tag "Less")
1078 (repeat :tag "Groups" regexp)
1079 (sexp :tag "Predicate")))
1081 (defvar gnus-article-treat-head-custom
1082 '(choice (const :tag "Off" nil)
1083 (const :tag "Header" head)))
1085 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1089 (defvar gnus-inhibit-treatment nil
1090 "Whether to inhibit treatment.")
1092 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1093 "Highlight the signature.
1094 Valid values are nil, t, `head', `first', `last', an integer or a
1095 predicate. See Info node `(gnus)Customizing Articles'."
1096 :group 'gnus-article-treat
1097 :link '(custom-manual "(gnus)Customizing Articles")
1098 :type gnus-article-treat-custom)
1099 (put 'gnus-treat-highlight-signature 'highlight t)
1101 (defcustom gnus-treat-buttonize 100000
1103 Valid values are nil, t, `head', `first', `last', an integer or a
1104 predicate. See Info node `(gnus)Customizing Articles'."
1105 :group 'gnus-article-treat
1106 :link '(custom-manual "(gnus)Customizing Articles")
1107 :type gnus-article-treat-custom)
1108 (put 'gnus-treat-buttonize 'highlight t)
1110 (defcustom gnus-treat-buttonize-head 'head
1111 "Add buttons to the head.
1112 Valid values are nil, t, `head', `first', `last', an integer or a
1113 predicate. See Info node `(gnus)Customizing Articles'."
1114 :group 'gnus-article-treat
1115 :link '(custom-manual "(gnus)Customizing Articles")
1116 :type gnus-article-treat-head-custom)
1117 (put 'gnus-treat-buttonize-head 'highlight t)
1119 (defcustom gnus-treat-emphasize 50000
1121 Valid values are nil, t, `head', `first', `last', an integer or a
1122 predicate. See Info node `(gnus)Customizing Articles'."
1123 :group 'gnus-article-treat
1124 :link '(custom-manual "(gnus)Customizing Articles")
1125 :type gnus-article-treat-custom)
1126 (put 'gnus-treat-emphasize 'highlight t)
1128 (defcustom gnus-treat-strip-cr nil
1129 "Remove carriage returns.
1130 Valid values are nil, t, `head', `first', `last', an integer or a
1131 predicate. See Info node `(gnus)Customizing Articles'."
1133 :group 'gnus-article-treat
1134 :link '(custom-manual "(gnus)Customizing Articles")
1135 :type gnus-article-treat-custom)
1137 (defcustom gnus-treat-unsplit-urls nil
1138 "Remove newlines from within URLs.
1139 Valid values are nil, t, `head', `first', `last', an integer or a
1140 predicate. See Info node `(gnus)Customizing Articles'."
1142 :group 'gnus-article-treat
1143 :link '(custom-manual "(gnus)Customizing Articles")
1144 :type gnus-article-treat-custom)
1146 (defcustom gnus-treat-leading-whitespace nil
1147 "Remove leading whitespace in headers.
1148 Valid values are nil, t, `head', `first', `last', an integer or a
1149 predicate. See Info node `(gnus)Customizing Articles'."
1151 :group 'gnus-article-treat
1152 :link '(custom-manual "(gnus)Customizing Articles")
1153 :type gnus-article-treat-custom)
1155 (defcustom gnus-treat-hide-headers 'head
1157 Valid values are nil, t, `head', `first', `last', an integer or a
1158 predicate. See Info node `(gnus)Customizing Articles'."
1159 :group 'gnus-article-treat
1160 :link '(custom-manual "(gnus)Customizing Articles")
1161 :type gnus-article-treat-head-custom)
1163 (defcustom gnus-treat-hide-boring-headers nil
1164 "Hide boring headers.
1165 Valid values are nil, t, `head', `first', `last', an integer or a
1166 predicate. See Info node `(gnus)Customizing Articles'."
1167 :group 'gnus-article-treat
1168 :link '(custom-manual "(gnus)Customizing Articles")
1169 :type gnus-article-treat-head-custom)
1171 (defcustom gnus-treat-hide-signature nil
1172 "Hide the signature.
1173 Valid values are nil, t, `head', `first', `last', an integer or a
1174 predicate. See Info node `(gnus)Customizing Articles'."
1175 :group 'gnus-article-treat
1176 :link '(custom-manual "(gnus)Customizing Articles")
1177 :type gnus-article-treat-custom)
1179 (defcustom gnus-treat-fill-article nil
1181 Valid values are nil, t, `head', `first', `last', an integer or a
1182 predicate. See Info node `(gnus)Customizing Articles'."
1183 :group 'gnus-article-treat
1184 :link '(custom-manual "(gnus)Customizing Articles")
1185 :type gnus-article-treat-custom)
1187 (defcustom gnus-treat-hide-citation nil
1189 Valid values are nil, t, `head', `first', `last', an integer or a
1190 predicate. See Info node `(gnus)Customizing Articles'."
1191 :group 'gnus-article-treat
1192 :link '(custom-manual "(gnus)Customizing Articles")
1193 :type gnus-article-treat-custom)
1195 (defcustom gnus-treat-hide-citation-maybe nil
1197 Valid values are nil, t, `head', `first', `last', an integer or a
1198 predicate. See Info node `(gnus)Customizing Articles'."
1199 :group 'gnus-article-treat
1200 :link '(custom-manual "(gnus)Customizing Articles")
1201 :type gnus-article-treat-custom)
1203 (defcustom gnus-treat-strip-list-identifiers 'head
1204 "Strip list identifiers from `gnus-list-identifiers`.
1205 Valid values are nil, t, `head', `first', `last', an integer or a
1206 predicate. See Info node `(gnus)Customizing Articles'."
1208 :group 'gnus-article-treat
1209 :link '(custom-manual "(gnus)Customizing Articles")
1210 :type gnus-article-treat-custom)
1212 (make-obsolete-variable 'gnus-treat-strip-pgp
1213 "This option is obsolete in Gnus 5.10.")
1215 (defcustom gnus-treat-strip-pem nil
1216 "Strip PEM signatures.
1217 Valid values are nil, t, `head', `first', `last', an integer or a
1218 predicate. See Info node `(gnus)Customizing Articles'."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-custom)
1223 (defcustom gnus-treat-strip-banner t
1224 "Strip banners from articles.
1225 The banner to be stripped is specified in the `banner' group parameter.
1226 Valid values are nil, t, `head', `first', `last', an integer or a
1227 predicate. See Info node `(gnus)Customizing Articles'."
1228 :group 'gnus-article-treat
1229 :link '(custom-manual "(gnus)Customizing Articles")
1230 :type gnus-article-treat-custom)
1232 (defcustom gnus-treat-highlight-headers 'head
1233 "Highlight the headers.
1234 Valid values are nil, t, `head', `first', `last', an integer or a
1235 predicate. See Info node `(gnus)Customizing Articles'."
1236 :group 'gnus-article-treat
1237 :link '(custom-manual "(gnus)Customizing Articles")
1238 :type gnus-article-treat-head-custom)
1239 (put 'gnus-treat-highlight-headers 'highlight t)
1241 (defcustom gnus-treat-highlight-citation t
1242 "Highlight cited text.
1243 Valid values are nil, t, `head', `first', `last', an integer or a
1244 predicate. See Info node `(gnus)Customizing Articles'."
1245 :group 'gnus-article-treat
1246 :link '(custom-manual "(gnus)Customizing Articles")
1247 :type gnus-article-treat-custom)
1248 (put 'gnus-treat-highlight-citation 'highlight t)
1250 (defcustom gnus-treat-date-ut nil
1251 "Display the Date in UT (GMT).
1252 Valid values are nil, t, `head', `first', `last', an integer or a
1253 predicate. See Info node `(gnus)Customizing Articles'."
1254 :group 'gnus-article-treat
1255 :link '(custom-manual "(gnus)Customizing Articles")
1256 :type gnus-article-treat-head-custom)
1258 (defcustom gnus-treat-date-local nil
1259 "Display the Date in the local timezone.
1260 Valid values are nil, t, `head', `first', `last', an integer or a
1261 predicate. See Info node `(gnus)Customizing Articles'."
1262 :group 'gnus-article-treat
1263 :link '(custom-manual "(gnus)Customizing Articles")
1264 :type gnus-article-treat-head-custom)
1266 (defcustom gnus-treat-date-english nil
1267 "Display the Date in a format that can be read aloud in English.
1268 Valid values are nil, t, `head', `first', `last', an integer or a
1269 predicate. See Info node `(gnus)Customizing Articles'."
1271 :group 'gnus-article-treat
1272 :link '(custom-manual "(gnus)Customizing Articles")
1273 :type gnus-article-treat-head-custom)
1275 (defcustom gnus-treat-date-lapsed nil
1276 "Display the Date header in a way that says how much time has elapsed.
1277 Valid values are nil, t, `head', `first', `last', an integer or a
1278 predicate. See Info node `(gnus)Customizing Articles'."
1279 :group 'gnus-article-treat
1280 :link '(custom-manual "(gnus)Customizing Articles")
1281 :type gnus-article-treat-head-custom)
1283 (defcustom gnus-treat-date-original nil
1284 "Display the date in the original timezone.
1285 Valid values are nil, t, `head', `first', `last', an integer or a
1286 predicate. See Info node `(gnus)Customizing Articles'."
1287 :group 'gnus-article-treat
1288 :link '(custom-manual "(gnus)Customizing Articles")
1289 :type gnus-article-treat-head-custom)
1291 (defcustom gnus-treat-date-iso8601 nil
1292 "Display the date in the ISO8601 format.
1293 Valid values are nil, t, `head', `first', `last', an integer or a
1294 predicate. See Info node `(gnus)Customizing Articles'."
1296 :group 'gnus-article-treat
1297 :link '(custom-manual "(gnus)Customizing Articles")
1298 :type gnus-article-treat-head-custom)
1300 (defcustom gnus-treat-date-user-defined nil
1301 "Display the date in a user-defined format.
1302 The format is defined by the `gnus-article-time-format' variable.
1303 Valid values are nil, t, `head', `first', `last', an integer or a
1304 predicate. See Info node `(gnus)Customizing Articles'."
1305 :group 'gnus-article-treat
1306 :link '(custom-manual "(gnus)Customizing Articles")
1307 :type gnus-article-treat-head-custom)
1309 (defcustom gnus-treat-strip-headers-in-body t
1310 "Strip the X-No-Archive header line from the beginning of the body.
1311 Valid values are nil, t, `head', `first', `last', an integer or a
1312 predicate. See Info node `(gnus)Customizing Articles'."
1314 :group 'gnus-article-treat
1315 :link '(custom-manual "(gnus)Customizing Articles")
1316 :type gnus-article-treat-custom)
1318 (defcustom gnus-treat-strip-trailing-blank-lines nil
1319 "Strip trailing blank lines.
1320 Valid values are nil, t, `head', `first', `last', an integer or a
1321 predicate. See Info node `(gnus)Customizing Articles'.
1323 When set to t, it also strips trailing blanks in all MIME parts.
1324 Consider to use `last' instead."
1325 :group 'gnus-article-treat
1326 :link '(custom-manual "(gnus)Customizing Articles")
1327 :type gnus-article-treat-custom)
1329 (defcustom gnus-treat-strip-leading-blank-lines nil
1330 "Strip leading blank lines.
1331 Valid values are nil, t, `head', `first', `last', an integer or a
1332 predicate. See Info node `(gnus)Customizing Articles'.
1334 When set to t, it also strips trailing blanks in all MIME parts."
1335 :group 'gnus-article-treat
1336 :link '(custom-manual "(gnus)Customizing Articles")
1337 :type gnus-article-treat-custom)
1339 (defcustom gnus-treat-strip-multiple-blank-lines nil
1340 "Strip multiple blank lines.
1341 Valid values are nil, t, `head', `first', `last', an integer or a
1342 predicate. See Info node `(gnus)Customizing Articles'."
1343 :group 'gnus-article-treat
1344 :link '(custom-manual "(gnus)Customizing Articles")
1345 :type gnus-article-treat-custom)
1347 (defcustom gnus-treat-unfold-headers 'head
1348 "Unfold folded header lines.
1349 Valid values are nil, t, `head', `first', `last', an integer or a
1350 predicate. See Info node `(gnus)Customizing Articles'."
1352 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :type gnus-article-treat-custom)
1356 (defcustom gnus-article-unfold-long-headers nil
1357 "If non-nil, allow unfolding headers even if the header is long.
1358 If it is a regexp, only long headers matching this regexp are unfolded.
1359 If it is t, all long headers are unfolded.
1361 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1362 :version "23.0" ;; No Gnus
1363 :group 'gnus-article-treat
1364 :type '(choice (const nil)
1365 (const :tag "all" t)
1368 (defcustom gnus-treat-fold-headers nil
1370 Valid values are nil, t, `head', `first', `last', an integer or a
1371 predicate. See Info node `(gnus)Customizing Articles'."
1373 :group 'gnus-article-treat
1374 :link '(custom-manual "(gnus)Customizing Articles")
1375 :type gnus-article-treat-custom)
1377 (defcustom gnus-treat-fold-newsgroups 'head
1378 "Fold the Newsgroups and Followup-To headers.
1379 Valid values are nil, t, `head', `first', `last', an integer or a
1380 predicate. See Info node `(gnus)Customizing Articles'."
1382 :group 'gnus-article-treat
1383 :link '(custom-manual "(gnus)Customizing Articles")
1384 :type gnus-article-treat-custom)
1386 (defcustom gnus-treat-overstrike t
1387 "Treat overstrike highlighting.
1388 Valid values are nil, t, `head', `first', `last', an integer or a
1389 predicate. See Info node `(gnus)Customizing Articles'."
1390 :group 'gnus-article-treat
1391 :link '(custom-manual "(gnus)Customizing Articles")
1392 :type gnus-article-treat-custom)
1393 (put 'gnus-treat-overstrike 'highlight t)
1395 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1396 "Treat ANSI SGR control sequences.
1397 Valid values are nil, t, `head', `first', `last', an integer or a
1398 predicate. See Info node `(gnus)Customizing Articles'."
1399 :group 'gnus-article-treat
1400 :link '(custom-manual "(gnus)Customizing Articles")
1401 :type gnus-article-treat-custom)
1403 (make-obsolete-variable 'gnus-treat-display-xface
1404 'gnus-treat-display-x-face)
1406 (defcustom gnus-treat-display-x-face
1407 (and (not noninteractive)
1408 (gnus-image-type-available-p 'xbm)
1409 (if (featurep 'xemacs)
1411 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1412 (executable-find "icontopbm")))
1414 "Display X-Face headers.
1415 Valid values are nil and `head'.
1416 See Info node `(gnus)Customizing Articles' and Info node
1417 `(gnus)X-Face' for details."
1418 :group 'gnus-article-treat
1420 :link '(custom-manual "(gnus)Customizing Articles")
1421 :link '(custom-manual "(gnus)X-Face")
1422 :type gnus-article-treat-head-custom
1423 :set (lambda (symbol value)
1426 (cond ((or (boundp symbol) (get symbol 'saved-value))
1428 ((boundp 'gnus-treat-display-xface)
1430 ** gnus-treat-display-xface is an obsolete variable;\
1431 use gnus-treat-display-x-face instead")
1432 (default-value 'gnus-treat-display-xface))
1433 ((get 'gnus-treat-display-xface 'saved-value)
1435 ** gnus-treat-display-xface is an obsolete variable;\
1436 use gnus-treat-display-x-face instead")
1437 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1440 (put 'gnus-treat-display-x-face 'highlight t)
1442 (defcustom gnus-treat-display-face
1443 (and (not noninteractive)
1444 (gnus-image-type-available-p 'png)
1446 "Display Face headers.
1447 Valid values are nil, t, `head', `first', `last', an integer or a
1448 predicate. See Info node `(gnus)Customizing Articles' and Info
1449 node `(gnus)X-Face' for details."
1450 :group 'gnus-article-treat
1452 :link '(custom-manual "(gnus)Customizing Articles")
1453 :link '(custom-manual "(gnus)X-Face")
1454 :type gnus-article-treat-head-custom)
1455 (put 'gnus-treat-display-face 'highlight t)
1457 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1459 Valid values are nil, t, `head', `first', `last', an integer or a
1460 predicate. See Info node `(gnus)Customizing Articles' and Info
1461 node `(gnus)Smileys' for details."
1462 :group 'gnus-article-treat
1464 :link '(custom-manual "(gnus)Customizing Articles")
1465 :link '(custom-manual "(gnus)Smileys")
1466 :type gnus-article-treat-custom)
1467 (put 'gnus-treat-display-smileys 'highlight t)
1469 (defcustom gnus-treat-from-picon
1470 (if (and (gnus-image-type-available-p 'xpm)
1471 (gnus-picons-installed-p))
1473 "Display picons in the From header.
1474 Valid values are nil, t, `head', `first', `last', an integer or a
1475 predicate. See Info node `(gnus)Customizing Articles' and Info
1476 node `(gnus)Picons' for details."
1478 :group 'gnus-article-treat
1480 :link '(custom-manual "(gnus)Customizing Articles")
1481 :link '(custom-manual "(gnus)Picons")
1482 :type gnus-article-treat-head-custom)
1483 (put 'gnus-treat-from-picon 'highlight t)
1485 (defcustom gnus-treat-mail-picon
1486 (if (and (gnus-image-type-available-p 'xpm)
1487 (gnus-picons-installed-p))
1489 "Display picons in To and Cc headers.
1490 Valid values are nil, t, `head', `first', `last', an integer or a
1491 predicate. See Info node `(gnus)Customizing Articles' and Info
1492 node `(gnus)Picons' for details."
1494 :group 'gnus-article-treat
1496 :link '(custom-manual "(gnus)Customizing Articles")
1497 :link '(custom-manual "(gnus)Picons")
1498 :type gnus-article-treat-head-custom)
1499 (put 'gnus-treat-mail-picon 'highlight t)
1501 (defcustom gnus-treat-newsgroups-picon
1502 (if (and (gnus-image-type-available-p 'xpm)
1503 (gnus-picons-installed-p))
1505 "Display picons in the Newsgroups and Followup-To headers.
1506 Valid values are nil, t, `head', `first', `last', an integer or a
1507 predicate. See Info node `(gnus)Customizing Articles' and Info
1508 node `(gnus)Picons' for details."
1510 :group 'gnus-article-treat
1512 :link '(custom-manual "(gnus)Customizing Articles")
1513 :link '(custom-manual "(gnus)Picons")
1514 :type gnus-article-treat-head-custom)
1515 (put 'gnus-treat-newsgroups-picon 'highlight t)
1517 (defcustom gnus-treat-body-boundary
1518 (if (or gnus-treat-newsgroups-picon
1519 gnus-treat-mail-picon
1520 gnus-treat-from-picon)
1521 ;; If there's much decoration, the user might prefer a boundery.
1524 "Draw a boundary at the end of the headers.
1525 Valid values are nil and `head'.
1526 See Info node `(gnus)Customizing Articles' for details."
1528 :group 'gnus-article-treat
1529 :link '(custom-manual "(gnus)Customizing Articles")
1530 :type gnus-article-treat-head-custom)
1532 (defcustom gnus-treat-capitalize-sentences nil
1533 "Capitalize sentence-starting words.
1534 Valid values are nil, t, `head', `first', `last', an integer or a
1535 predicate. See Info node `(gnus)Customizing Articles'."
1537 :group 'gnus-article-treat
1538 :link '(custom-manual "(gnus)Customizing Articles")
1539 :type gnus-article-treat-custom)
1541 (defcustom gnus-treat-wash-html nil
1543 Valid values are nil, t, `head', `first', `last', an integer or a
1544 predicate. See Info node `(gnus)Customizing Articles'."
1546 :group 'gnus-article-treat
1547 :link '(custom-manual "(gnus)Customizing Articles")
1548 :type gnus-article-treat-custom)
1550 (defcustom gnus-treat-fill-long-lines nil
1552 Valid values are nil, t, `head', `first', `last', an integer or a
1553 predicate. See Info node `(gnus)Customizing Articles'."
1554 :group 'gnus-article-treat
1555 :link '(custom-manual "(gnus)Customizing Articles")
1556 :type gnus-article-treat-custom)
1558 (defcustom gnus-treat-play-sounds nil
1560 Valid values are nil, t, `head', `first', `last', an integer or a
1561 predicate. See Info node `(gnus)Customizing Articles'."
1563 :group 'gnus-article-treat
1564 :link '(custom-manual "(gnus)Customizing Articles")
1565 :type gnus-article-treat-custom)
1567 (defcustom gnus-treat-translate nil
1568 "Translate articles from one language to another.
1569 Valid values are nil, t, `head', `first', `last', an integer or a
1570 predicate. See Info node `(gnus)Customizing Articles'."
1572 :group 'gnus-article-treat
1573 :link '(custom-manual "(gnus)Customizing Articles")
1574 :type gnus-article-treat-custom)
1576 (defcustom gnus-treat-x-pgp-sig nil
1578 To automatically treat X-PGP-Sig, set it to head.
1579 Valid values are nil, t, `head', `first', `last', an integer or a
1580 predicate. See Info node `(gnus)Customizing Articles'."
1582 :group 'gnus-article-treat
1583 :group 'mime-security
1584 :link '(custom-manual "(gnus)Customizing Articles")
1585 :type gnus-article-treat-custom)
1587 (defvar gnus-article-encrypt-protocol-alist
1588 '(("PGP" . mml2015-self-encrypt)))
1590 ;; Set to nil if more than one protocol added to
1591 ;; gnus-article-encrypt-protocol-alist.
1592 (defcustom gnus-article-encrypt-protocol "PGP"
1593 "The protocol used for encrypt articles.
1594 It is a string, such as \"PGP\". If nil, ask user."
1597 :group 'mime-security)
1599 (defvar gnus-article-wash-function nil
1600 "Function used for converting HTML into text.")
1602 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1603 (mm-coding-system-p 'utf-8)
1604 (executable-find idna-program))
1605 "Whether IDNA decoding of headers is used when viewing messages.
1606 This requires GNU Libidn, and by default only enabled if it is found."
1608 :group 'gnus-article-headers
1611 (defcustom gnus-article-over-scroll nil
1612 "If non-nil, allow scrolling the article buffer even when there no more text."
1614 :group 'gnus-article
1617 ;;; Internal variables
1619 (defvar gnus-english-month-names
1620 '("January" "February" "March" "April" "May" "June" "July" "August"
1621 "September" "October" "November" "December"))
1623 (defvar article-goto-body-goes-to-point-min-p nil)
1624 (defvar gnus-article-wash-types nil)
1625 (defvar gnus-article-emphasis-alist nil)
1626 (defvar gnus-article-image-alist nil)
1628 (defvar gnus-article-mime-handle-alist-1 nil)
1629 (defvar gnus-treatment-function-alist
1630 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1631 (gnus-treat-strip-banner gnus-article-strip-banner)
1632 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1633 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1634 (gnus-treat-buttonize gnus-article-add-buttons)
1635 (gnus-treat-fill-article gnus-article-fill-cited-article)
1636 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1637 (gnus-treat-strip-cr gnus-article-remove-cr)
1638 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1639 (gnus-treat-date-ut gnus-article-date-ut)
1640 (gnus-treat-date-local gnus-article-date-local)
1641 (gnus-treat-date-english gnus-article-date-english)
1642 (gnus-treat-date-original gnus-article-date-original)
1643 (gnus-treat-date-user-defined gnus-article-date-user)
1644 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1645 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1646 (gnus-treat-display-x-face gnus-article-display-x-face)
1647 (gnus-treat-display-face gnus-article-display-face)
1648 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1649 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1650 (gnus-treat-hide-signature gnus-article-hide-signature)
1651 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1652 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1653 (gnus-treat-strip-pem gnus-article-hide-pem)
1654 (gnus-treat-from-picon gnus-treat-from-picon)
1655 (gnus-treat-mail-picon gnus-treat-mail-picon)
1656 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1657 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1658 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1659 (gnus-treat-strip-trailing-blank-lines
1660 gnus-article-remove-trailing-blank-lines)
1661 (gnus-treat-strip-leading-blank-lines
1662 gnus-article-strip-leading-blank-lines)
1663 (gnus-treat-strip-multiple-blank-lines
1664 gnus-article-strip-multiple-blank-lines)
1665 (gnus-treat-overstrike gnus-article-treat-overstrike)
1666 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1667 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1668 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1669 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1670 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1671 (gnus-treat-display-smileys gnus-treat-smiley)
1672 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1673 (gnus-treat-wash-html gnus-article-wash-html)
1674 (gnus-treat-emphasize gnus-article-emphasize)
1675 (gnus-treat-hide-citation gnus-article-hide-citation)
1676 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1677 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1678 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1679 (gnus-treat-play-sounds gnus-earcon-display)))
1681 (defvar gnus-article-mime-handle-alist nil)
1682 (defvar article-lapsed-timer nil)
1683 (defvar gnus-article-current-summary nil)
1685 (defvar gnus-article-mode-syntax-table
1686 (let ((table (copy-syntax-table text-mode-syntax-table)))
1687 ;; This causes the citation match run O(2^n).
1688 ;; (modify-syntax-entry ?- "w" table)
1689 (modify-syntax-entry ?> ")<" table)
1690 (modify-syntax-entry ?< "(>" table)
1691 ;; make M-. in article buffers work for `foo' strings
1692 (modify-syntax-entry ?' " " table)
1693 (modify-syntax-entry ?` " " table)
1695 "Syntax table used in article mode buffers.
1696 Initialized from `text-mode-syntax-table.")
1698 (defvar gnus-save-article-buffer nil)
1700 (defvar gnus-article-mode-line-format-alist
1701 (nconc '((?w (gnus-article-wash-status) ?s)
1702 (?m (gnus-article-mime-part-status) ?s))
1703 gnus-summary-mode-line-format-alist))
1705 (defvar gnus-number-of-articles-to-be-saved nil)
1707 (defvar gnus-inhibit-hiding nil)
1709 (defvar gnus-article-edit-mode nil)
1711 ;;; Macros for dealing with the article buffer.
1713 (defmacro gnus-with-article-headers (&rest forms)
1715 (set-buffer gnus-article-buffer)
1717 (let ((inhibit-read-only t)
1718 (inhibit-point-motion-hooks t)
1719 (case-fold-search t))
1720 (article-narrow-to-head)
1723 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1724 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1726 (defmacro gnus-with-article-buffer (&rest forms)
1728 (set-buffer gnus-article-buffer)
1729 (let ((inhibit-read-only t))
1732 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1733 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1735 (defun gnus-article-goto-header (header)
1736 "Go to HEADER, which is a regular expression."
1737 (re-search-forward (concat "^\\(" header "\\):") nil t))
1739 (defsubst gnus-article-hide-text (b e props)
1740 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1741 (gnus-add-text-properties-when 'article-type nil b e props)
1742 (when (memq 'intangible props)
1744 (max (1- b) (point-min))
1745 b 'intangible (cddr (memq 'intangible props)))))
1747 (defsubst gnus-article-unhide-text (b e)
1748 "Remove hidden text properties from region between B and E."
1749 (remove-text-properties b e gnus-hidden-properties)
1750 (when (memq 'intangible gnus-hidden-properties)
1751 (put-text-property (max (1- b) (point-min))
1752 b 'intangible nil)))
1754 (defun gnus-article-hide-text-type (b e type)
1755 "Hide text of TYPE between B and E."
1756 (gnus-add-wash-type type)
1757 (gnus-article-hide-text
1758 b e (cons 'article-type (cons type gnus-hidden-properties))))
1760 (defun gnus-article-unhide-text-type (b e type)
1761 "Unhide text of TYPE between B and E."
1762 (gnus-delete-wash-type type)
1763 (remove-text-properties
1764 b e (cons 'article-type (cons type gnus-hidden-properties)))
1765 (when (memq 'intangible gnus-hidden-properties)
1766 (put-text-property (max (1- b) (point-min))
1767 b 'intangible nil)))
1769 (defun gnus-article-hide-text-of-type (type)
1770 "Hide text of TYPE in the current buffer."
1772 (let ((b (point-min))
1774 (while (setq b (text-property-any b e 'article-type type))
1775 (add-text-properties b (incf b) gnus-hidden-properties)))))
1777 (defun gnus-article-delete-text-of-type (type)
1778 "Delete text of TYPE in the current buffer."
1780 (let ((b (point-min)))
1781 (if (eq type 'multipart)
1782 ;; Remove MIME buttons associated with multipart/alternative parts.
1785 (while (if (get-text-property (point) 'gnus-part)
1787 (when (setq b (next-single-property-change (point)
1792 (skip-chars-forward "\n")
1793 (when (eq (get-text-property b 'article-type) 'multipart)
1794 (delete-region b (point)))))
1795 (while (setq b (text-property-any b (point-max) 'article-type type))
1797 b (or (text-property-not-all b (point-max) 'article-type type)
1800 (defun gnus-article-delete-invisible-text ()
1801 "Delete all invisible text in the current buffer."
1803 (let ((b (point-min)))
1804 (while (setq b (text-property-any b (point-max) 'invisible t))
1806 b (or (text-property-not-all b (point-max) 'invisible t)
1809 (defun gnus-article-text-type-exists-p (type)
1810 "Say whether any text of type TYPE exists in the buffer."
1811 (text-property-any (point-min) (point-max) 'article-type type))
1813 (defsubst gnus-article-header-rank ()
1814 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1815 (let ((list gnus-sorted-header-list)
1818 (if (looking-at (car list))
1820 (setq list (cdr list))
1824 (defun article-hide-headers (&optional arg delete)
1825 "Hide unwanted headers and possibly sort them as well."
1827 ;; This function might be inhibited.
1828 (unless gnus-inhibit-hiding
1829 (let ((inhibit-read-only t)
1830 (case-fold-search t)
1831 (max (1+ (length gnus-sorted-header-list)))
1832 (inhibit-point-motion-hooks t)
1833 (cur (current-buffer))
1834 ignored visible beg)
1836 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1837 ;; group parameters, so we should go to the summary buffer.
1840 (progn (set-buffer gnus-summary-buffer) t)
1842 (setq ignored (when (not gnus-visible-headers)
1843 (cond ((stringp gnus-ignored-headers)
1844 gnus-ignored-headers)
1845 ((listp gnus-ignored-headers)
1846 (mapconcat 'identity
1847 gnus-ignored-headers
1849 visible (cond ((stringp gnus-visible-headers)
1850 gnus-visible-headers)
1851 ((and gnus-visible-headers
1852 (listp gnus-visible-headers))
1853 (mapconcat 'identity
1854 gnus-visible-headers
1858 ;; First we narrow to just the headers.
1859 (article-narrow-to-head)
1860 ;; Hide any "From " lines at the beginning of (mail) articles.
1861 (while (looking-at "From ")
1864 (delete-region (point-min) (point)))
1865 ;; Then treat the rest of the header lines.
1866 ;; Then we use the two regular expressions
1867 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1868 ;; select which header lines is to remain visible in the
1870 (while (re-search-forward "^[^ \t:]*:" nil t)
1872 ;; Mark the rank of the header.
1874 (point) (1+ (point)) 'message-rank
1875 (if (or (and visible (looking-at visible))
1877 (not (looking-at ignored))))
1878 (gnus-article-header-rank)
1881 (message-sort-headers-1)
1882 (when (setq beg (text-property-any
1883 (point-min) (point-max) 'message-rank (+ 2 max)))
1884 ;; We delete the unwanted headers.
1885 (gnus-add-wash-type 'headers)
1886 (add-text-properties (point-min) (+ 5 (point-min))
1887 '(article-type headers dummy-invisible t))
1888 (delete-region beg (point-max))))))))
1890 (defun article-hide-boring-headers (&optional arg)
1891 "Toggle hiding of headers that aren't very interesting.
1892 If given a negative prefix, always show; if given a positive prefix,
1894 (interactive (gnus-article-hidden-arg))
1895 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1896 (not gnus-show-all-headers))
1899 (let ((inhibit-read-only t)
1900 (inhibit-point-motion-hooks t))
1901 (article-narrow-to-head)
1902 (dolist (elem gnus-boring-article-headers)
1903 (goto-char (point-min))
1905 ;; Hide empty headers.
1907 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1909 (gnus-article-hide-text-type
1913 (if (re-search-forward "^[^ \t]" nil t)
1917 ;; Hide boring Newsgroups header.
1918 ((eq elem 'newsgroups)
1919 (when (gnus-string-equal
1920 (gnus-fetch-field "newsgroups")
1921 (gnus-group-real-name
1922 (if (boundp 'gnus-newsgroup-name)
1925 (gnus-article-hide-header "newsgroups")))
1926 ((eq elem 'to-address)
1927 (let ((to (message-fetch-field "to"))
1929 (gnus-parameter-to-address
1930 (if (boundp 'gnus-newsgroup-name)
1931 gnus-newsgroup-name ""))))
1932 (when (and to to-address
1935 ;; only one address in To
1936 (nth 1 (mail-extract-address-components to))
1938 (gnus-article-hide-header "to"))))
1940 (let ((to (message-fetch-field "to"))
1942 (gnus-parameter-to-list
1943 (if (boundp 'gnus-newsgroup-name)
1944 gnus-newsgroup-name ""))))
1945 (when (and to to-list
1948 ;; only one address in To
1949 (nth 1 (mail-extract-address-components to))
1951 (gnus-article-hide-header "to"))))
1953 (let ((cc (message-fetch-field "cc"))
1955 (gnus-parameter-to-list
1956 (if (boundp 'gnus-newsgroup-name)
1957 gnus-newsgroup-name ""))))
1958 (when (and cc to-list
1961 ;; only one address in CC
1962 (nth 1 (mail-extract-address-components cc))
1964 (gnus-article-hide-header "cc"))))
1965 ((eq elem 'followup-to)
1966 (when (gnus-string-equal
1967 (message-fetch-field "followup-to")
1968 (message-fetch-field "newsgroups"))
1969 (gnus-article-hide-header "followup-to")))
1970 ((eq elem 'reply-to)
1971 (if (gnus-group-find-parameter
1972 gnus-newsgroup-name 'broken-reply-to)
1973 (gnus-article-hide-header "reply-to")
1974 (let ((from (message-fetch-field "from"))
1975 (reply-to (message-fetch-field "reply-to")))
1982 (lambda (x) (downcase (cadr x)))
1983 (mail-extract-address-components from t))
1986 (lambda (x) (downcase (cadr x)))
1987 (mail-extract-address-components reply-to t))
1989 (gnus-article-hide-header "reply-to")))))
1991 (let ((date (with-current-buffer gnus-original-article-buffer
1992 ;; If date in `gnus-article-buffer' is localized
1993 ;; (`gnus-treat-date-user-defined'),
1994 ;; `days-between' might fail.
1995 (message-fetch-field "date"))))
1997 (< (days-between (current-time-string) date)
1999 (gnus-article-hide-header "date"))))
2001 (let ((to (message-fetch-field "to"))
2002 (cc (message-fetch-field "cc")))
2003 (when (> (length to) 1024)
2004 (gnus-article-hide-header "to"))
2005 (when (> (length cc) 1024)
2006 (gnus-article-hide-header "cc"))))
2010 (goto-char (point-min))
2011 (while (re-search-forward "^to:" nil t)
2012 (setq to-count (1+ to-count)))
2013 (when (> to-count 1)
2014 (while (> to-count 0)
2015 (goto-char (point-min))
2017 (re-search-forward "^to:" nil nil to-count)
2019 (narrow-to-region (point) (point-max))
2020 (gnus-article-hide-header "to"))
2021 (setq to-count (1- to-count))))
2022 (goto-char (point-min))
2023 (while (re-search-forward "^cc:" nil t)
2024 (setq cc-count (1+ cc-count)))
2025 (when (> cc-count 1)
2026 (while (> cc-count 0)
2027 (goto-char (point-min))
2029 (re-search-forward "^cc:" nil nil cc-count)
2031 (narrow-to-region (point) (point-max))
2032 (gnus-article-hide-header "cc"))
2033 (setq cc-count (1- cc-count)))))))))))))
2035 (defun gnus-article-hide-header (header)
2037 (goto-char (point-min))
2038 (when (re-search-forward (concat "^" header ":") nil t)
2039 (gnus-article-hide-text-type
2043 (if (re-search-forward "^[^ \t]" nil t)
2048 (defvar gnus-article-normalized-header-length 40
2049 "Length of normalized headers.")
2051 (defun article-normalize-headers ()
2052 "Make all header lines 40 characters long."
2054 (let ((inhibit-read-only t)
2058 (article-narrow-to-head)
2061 ((< (setq column (- (point-at-eol) (point)))
2062 gnus-article-normalized-header-length)
2064 (insert (make-string
2065 (- gnus-article-normalized-header-length column)
2067 ((> column gnus-article-normalized-header-length)
2068 (gnus-put-text-property
2070 (forward-char gnus-article-normalized-header-length)
2077 (forward-line 1))))))
2079 (defun article-treat-dumbquotes ()
2080 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2081 Note that this function guesses whether a character is a sm*rtq**t* or
2082 not, so it should only be used interactively.
2084 Sm*rtq**t*s are M****s***'s unilateral extension to the
2085 iso-8859-1 character map in an attempt to provide more quoting
2086 characters. If you see something like \\222 or \\264 where
2087 you're expecting some kind of apostrophe or quotation mark, then
2090 (article-translate-strings gnus-article-dumbquotes-map))
2092 (defun article-translate-characters (from to)
2093 "Translate all characters in the body of the article according to FROM and TO.
2094 FROM is a string of characters to translate from; to is a string of
2095 characters to translate to."
2097 (when (article-goto-body)
2098 (let ((inhibit-read-only t)
2099 (x (make-string 225 ?x))
2101 (while (< (incf i) (length x))
2104 (while (< i (length from))
2105 (aset x (aref from i) (aref to i))
2107 (translate-region (point) (point-max) x)))))
2109 (defun article-translate-strings (map)
2110 "Translate all string in the body of the article according to MAP.
2111 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2113 (when (article-goto-body)
2114 (let ((inhibit-read-only t))
2117 (while (search-forward (car elem) nil t)
2118 (replace-match (cadr elem)))))))))
2120 (defun article-treat-overstrike ()
2121 "Translate overstrikes into bold text."
2124 (when (article-goto-body)
2125 (let ((inhibit-read-only t))
2126 (while (search-forward "\b" nil t)
2127 (let ((next (char-after))
2128 (previous (char-after (- (point) 2))))
2129 ;; We do the boldification/underlining by hiding the
2130 ;; overstrikes and putting the proper text property
2134 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2135 (put-text-property (point) (1+ (point)) 'face 'bold))
2137 (gnus-article-hide-text-type
2138 (1- (point)) (1+ (point)) 'overstrike)
2140 (- (point) 2) (1- (point)) 'face 'underline))
2142 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2144 (point) (1+ (point)) 'face 'underline)))))))))
2146 (defun article-treat-ansi-sequences ()
2147 "Translate ANSI SGR control sequences into overlays or extents."
2150 (when (article-goto-body)
2151 (let ((inhibit-read-only t))
2152 (ansi-color-apply-on-region (point) (point-max))))))
2154 (defun gnus-article-treat-unfold-headers ()
2155 "Unfold folded message headers.
2156 Only the headers that fit into the current window width will be
2159 (gnus-with-article-headers
2163 (mail-header-narrow-to-field)
2164 (let* ((header (buffer-string))
2166 (or (equal gnus-article-unfold-long-headers t)
2167 (and (stringp gnus-article-unfold-long-headers)
2168 (string-match gnus-article-unfold-long-headers header)))))
2171 (goto-char (point-min))
2172 (while (re-search-forward "\n[\t ]" nil t)
2173 (replace-match " " t t)))
2174 (setq length (- (point-max) (point-min) 1))
2175 (when (or unfoldable
2176 (< length (window-width)))
2177 (while (re-search-forward "\n[\t ]" nil t)
2178 (replace-match " " t t))))
2179 (goto-char (point-max)))))))
2181 (defun gnus-article-treat-fold-headers ()
2182 "Fold message headers."
2184 (gnus-with-article-headers
2187 (mail-header-narrow-to-field)
2188 (mail-header-fold-field)
2189 (goto-char (point-max))))))
2191 (defun gnus-treat-smiley ()
2192 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2194 (gnus-with-article-buffer
2195 (if (memq 'smiley gnus-article-wash-types)
2196 (gnus-delete-images 'smiley)
2198 (let ((images (smiley-region (point) (point-max))))
2200 (gnus-add-wash-type 'smiley)
2201 (dolist (image images)
2202 (gnus-add-image 'smiley image)))))))
2204 (defun gnus-article-remove-images ()
2205 "Remove all images from the article buffer."
2207 (gnus-with-article-buffer
2208 (dolist (elem gnus-article-image-alist)
2209 (gnus-delete-images (car elem)))))
2211 (defun gnus-article-treat-fold-newsgroups ()
2212 "Unfold folded message headers.
2213 Only the headers that fit into the current window width will be
2216 (gnus-with-article-headers
2217 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2219 (mail-header-narrow-to-field)
2220 (while (re-search-forward ", *" nil t)
2221 (replace-match ", " t t))
2222 (mail-header-fold-field)
2223 (goto-char (point-max))))))
2225 (defcustom gnus-article-truncate-lines default-truncate-lines
2226 "Value of `truncate-lines' in Gnus Article buffer.
2227 Valid values are nil, t, `head', `first', `last', an integer or a
2228 predicate. See Info node `(gnus)Customizing Articles'."
2229 :version "23.0" ;; No Gnus
2230 :group 'gnus-article
2231 ;; :link '(custom-manual "(gnus)Customizing Articles")
2234 (defun gnus-article-toggle-truncate-lines (&optional arg)
2235 "Toggle whether to fold or truncate long lines in article the buffer.
2236 If ARG is non-nil and not a number, toggle
2237 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2238 long lines iff arg is positive."
2241 ((and (numberp arg) (> arg 0))
2242 (setq gnus-article-truncate-lines t))
2244 (setq gnus-article-truncate-lines nil))
2246 (setq gnus-article-truncate-lines
2247 (not gnus-article-truncate-lines))))
2248 (gnus-with-article-buffer
2250 ((and (numberp arg) (> arg 0))
2251 (setq truncate-lines nil))
2253 (setq truncate-lines t)))
2254 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2255 ;; `toggle-truncate-lines' needs an argument.
2256 (toggle-truncate-lines)))
2258 (defun gnus-article-treat-body-boundary ()
2259 "Place a boundary line at the end of the headers."
2261 (when (and gnus-body-boundary-delimiter
2262 (> (length gnus-body-boundary-delimiter) 0))
2263 (gnus-with-article-headers
2264 (goto-char (point-max))
2265 (let ((start (point)))
2266 (insert "X-Boundary: ")
2267 (gnus-add-text-properties start (point) '(invisible t intangible t))
2269 (while (>= (1- (window-width)) (length str))
2270 (setq str (concat str gnus-body-boundary-delimiter)))
2271 (substring str 0 (1- (window-width))))
2273 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2275 (defun article-fill-long-lines ()
2276 "Fill lines that are wider than the window width."
2279 (let ((inhibit-read-only t)
2280 (width (window-width (get-buffer-window (current-buffer)))))
2283 (let ((adaptive-fill-mode nil)) ;Why? -sm
2286 (when (>= (current-column) (min fill-column width))
2287 (narrow-to-region (min (1+ (point)) (point-max))
2289 (let ((goback (point-marker)))
2290 (fill-paragraph nil)
2291 (goto-char (marker-position goback)))
2293 (forward-line 1)))))))
2295 (defun article-capitalize-sentences ()
2296 "Capitalize the first word in each sentence."
2299 (let ((inhibit-read-only t)
2300 (paragraph-start "^[\n\^L]"))
2304 (forward-sentence)))))
2306 (defun article-remove-cr ()
2307 "Remove trailing CRs and then translate remaining CRs into LFs."
2310 (let ((inhibit-read-only t))
2311 (goto-char (point-min))
2312 (while (re-search-forward "\r+$" nil t)
2313 (replace-match "" t t))
2314 (goto-char (point-min))
2315 (while (search-forward "\r" nil t)
2316 (replace-match "\n" t t)))))
2318 (defun article-remove-trailing-blank-lines ()
2319 "Remove all trailing blank lines from the article."
2322 (let ((inhibit-read-only t))
2323 (goto-char (point-max))
2327 (while (and (not (bobp))
2328 (looking-at "^[ \t]*$")
2329 (not (gnus-annotation-in-region-p
2330 (point) (point-at-eol))))
2336 (defvar gnus-face-properties-alist))
2338 (defun article-display-face (&optional force)
2339 "Display any Face headers in the header."
2340 (interactive (list 'force))
2341 (let ((wash-face-p buffer-read-only))
2342 (gnus-with-article-headers
2343 ;; When displaying parts, this function can be called several times on
2344 ;; the same article, without any intended toggle semantic (as typing `W
2345 ;; D d' would have). So face deletion must occur only when we come from
2346 ;; an interactive command, that is when the *Article* buffer is
2348 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2349 (gnus-delete-images 'face)
2350 (let ((from (message-fetch-field "from"))
2352 (save-current-buffer
2353 (when (and wash-face-p
2354 (gnus-buffer-live-p gnus-original-article-buffer)
2355 (not (re-search-forward "^Face:[\t ]*" nil t)))
2356 (set-buffer gnus-original-article-buffer))
2358 (mail-narrow-to-head)
2360 ;; Check whether this face is censored.
2361 (not (and gnus-article-x-face-too-ugly
2363 (setq from (message-fetch-field "from")))
2364 (string-match gnus-article-x-face-too-ugly
2366 (while (gnus-article-goto-header "Face")
2367 (push (mail-header-field-value) faces)))))
2369 (goto-char (point-min))
2371 (unless (setq from (gnus-article-goto-header "from"))
2374 (insert " [no `from' set]\n"))
2376 (when (setq png (gnus-convert-face-to-png (pop faces)))
2378 (apply 'gnus-create-image png 'png t
2379 (cdr (assq 'png gnus-face-properties-alist))))
2381 (gnus-add-wash-type 'face)
2382 (gnus-add-image 'face image)
2383 (gnus-put-image image nil 'face))))))))))
2385 (defun article-display-x-face (&optional force)
2386 "Look for an X-Face header and display it if present."
2387 (interactive (list 'force))
2388 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2389 (gnus-with-article-headers
2390 ;; Delete the old process, if any.
2391 (when (process-status "article-x-face")
2392 (delete-process "article-x-face"))
2393 ;; See the comment in `article-display-face'.
2394 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2395 ;; We have already displayed X-Faces, so we remove them
2397 (gnus-delete-images 'xface)
2399 (let ((from (message-fetch-field "from"))
2401 (save-current-buffer
2402 (when (and wash-face-p
2403 (gnus-buffer-live-p gnus-original-article-buffer)
2404 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2405 ;; If type `W f', use gnus-original-article-buffer,
2406 ;; otherwise use the current buffer because displaying
2407 ;; RFC822 parts calls this function too.
2408 (set-buffer gnus-original-article-buffer))
2410 (mail-narrow-to-head)
2411 (and gnus-article-x-face-command
2413 ;; Check whether this face is censored.
2414 (not (and gnus-article-x-face-too-ugly
2416 (setq from (message-fetch-field "from")))
2417 (string-match gnus-article-x-face-too-ugly
2419 (while (gnus-article-goto-header "X-Face")
2420 (push (mail-header-field-value) x-faces)))))
2422 ;; We display the face.
2423 (cond ((functionp gnus-article-x-face-command)
2424 ;; The command is a lisp function, so we call it.
2425 (mapc gnus-article-x-face-command x-faces))
2426 ((stringp gnus-article-x-face-command)
2427 ;; The command is a string, so we interpret the command
2428 ;; as a, well, command, and fork it off.
2429 (let ((process-connection-type nil))
2430 (gnus-set-process-query-on-exit-flag
2432 "article-x-face" nil shell-file-name
2433 shell-command-switch gnus-article-x-face-command)
2435 ;; Sending multiple EOFs to xv doesn't work,
2436 ;; so we only do a single external face.
2438 (insert (car x-faces))
2439 (process-send-region "article-x-face"
2440 (point-min) (point-max)))
2441 (process-send-eof "article-x-face")))
2443 (error "`%s' set to `%s' is not a function"
2444 gnus-article-x-face-command
2445 'gnus-article-x-face-command)))))))))
2447 (defun article-decode-mime-words ()
2448 "Decode all MIME-encoded words in the article."
2450 (gnus-with-article-buffer
2451 (let ((inhibit-point-motion-hooks t)
2452 (mail-parse-charset gnus-newsgroup-charset)
2453 (mail-parse-ignored-charsets
2454 (with-current-buffer gnus-summary-buffer
2455 gnus-newsgroup-ignored-charsets)))
2456 (mail-decode-encoded-word-region (point-min) (point-max)))))
2458 (defun article-decode-charset (&optional prompt)
2459 "Decode charset-encoded text in the article.
2460 If PROMPT (the prefix), prompt for a coding system to use."
2462 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2463 (inhibit-read-only t)
2464 (mail-parse-charset gnus-newsgroup-charset)
2465 (mail-parse-ignored-charsets
2466 (save-excursion (condition-case nil
2467 (set-buffer gnus-summary-buffer)
2469 gnus-newsgroup-ignored-charsets))
2470 ct cte ctl charset format)
2473 (article-narrow-to-head)
2474 (setq ct (message-fetch-field "Content-Type" t)
2475 cte (message-fetch-field "Content-Transfer-Encoding" t)
2476 ctl (and ct (mail-header-parse-content-type ct))
2479 (mm-read-coding-system "Charset to decode: "))
2481 (mail-content-type-get ctl 'charset)))
2482 format (and ctl (mail-content-type-get ctl 'format)))
2484 (setq cte (mail-header-strip cte)))
2485 (if (and ctl (not (string-match "/" (car ctl))))
2487 (goto-char (point-max)))
2490 (narrow-to-region (point) (point-max))
2491 (when (and (eq mail-parse-charset 'gnus-decoded)
2492 (eq (mm-body-7-or-8) '8bit))
2493 ;; The text code could have been decoded.
2494 (setq charset mail-parse-charset))
2495 (when (and (or (not ctl)
2496 (equal (car ctl) "text/plain"))
2497 (not format)) ;; article with format will decode later.
2499 charset (and cte (intern (downcase
2500 (gnus-strip-whitespace cte))))
2503 (defun article-decode-encoded-words ()
2504 "Remove encoded-word encoding from headers."
2505 (let ((inhibit-point-motion-hooks t)
2506 (mail-parse-charset gnus-newsgroup-charset)
2507 (mail-parse-ignored-charsets
2508 (save-excursion (condition-case nil
2509 (set-buffer gnus-summary-buffer)
2511 gnus-newsgroup-ignored-charsets))
2512 (inhibit-read-only t)
2514 (goto-char (point-min))
2515 (when (search-forward "\n\n" nil 'move)
2522 (memq (char-after) '(?\t ? )))))
2523 (setq start (point))
2525 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2526 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2527 (funcall gnus-decode-address-function start end)
2528 (funcall gnus-decode-header-function start end))
2529 (goto-char (setq end start)))))
2531 (defun article-decode-group-name ()
2532 "Decode group names in Newsgroups, Followup-To and Xref headers."
2533 (let ((inhibit-point-motion-hooks t)
2534 (inhibit-read-only t)
2535 (method (gnus-find-method-for-group gnus-newsgroup-name))
2537 (when (and (or gnus-group-name-charset-method-alist
2538 gnus-group-name-charset-group-alist)
2539 (gnus-buffer-live-p gnus-original-article-buffer))
2541 (article-narrow-to-head)
2542 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2543 (with-current-buffer gnus-original-article-buffer
2544 (goto-char (point-min)))
2545 (setq regexp (concat "^" header
2546 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2547 (while (re-search-forward regexp nil t)
2548 (replace-match (save-match-data
2549 (gnus-decode-newsgroups
2550 ;; XXX how to use data in article buffer?
2551 (with-current-buffer gnus-original-article-buffer
2552 (re-search-forward regexp nil t)
2554 gnus-newsgroup-name method))
2556 (goto-char (point-min)))))))
2558 (autoload 'idna-to-unicode "idna")
2560 (defun article-decode-idna-rhs ()
2561 "Decode IDNA strings in RHS in various headers in current buffer.
2562 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2563 Mail-Reply-To: and Mail-Followup-To:."
2566 (let ((inhibit-point-motion-hooks t)
2567 (inhibit-read-only t))
2568 (article-narrow-to-head)
2569 (goto-char (point-min))
2570 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2572 (when (save-match-data
2573 (and (setq ace (match-string 1))
2575 (and (re-search-backward "^[^ \t]" nil t)
2576 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2577 (setq unicode (idna-to-unicode ace))))
2578 (unless (string= ace unicode)
2579 (replace-match unicode nil nil nil 1)))))))))
2581 (defun article-de-quoted-unreadable (&optional force read-charset)
2582 "Translate a quoted-printable-encoded article.
2583 If FORCE, decode the article whether it is marked as quoted-printable
2585 If READ-CHARSET, ask for a coding system."
2586 (interactive (list 'force current-prefix-arg))
2588 (let ((inhibit-read-only t) type charset)
2589 (if (gnus-buffer-live-p gnus-original-article-buffer)
2590 (with-current-buffer gnus-original-article-buffer
2592 (gnus-fetch-field "content-transfer-encoding"))
2593 (let* ((ct (gnus-fetch-field "content-type"))
2594 (ctl (and ct (mail-header-parse-content-type ct))))
2595 (setq charset (and ctl
2596 (mail-content-type-get ctl 'charset)))
2597 (if (stringp charset)
2598 (setq charset (intern (downcase charset)))))))
2600 (setq charset (mm-read-coding-system "Charset: " charset)))
2602 (setq charset gnus-newsgroup-charset))
2604 (and type (let ((case-fold-search t))
2605 (string-match "quoted-printable" type))))
2607 (quoted-printable-decode-region
2608 (point) (point-max) (mm-charset-to-coding-system charset))))))
2610 (defun article-de-base64-unreadable (&optional force read-charset)
2611 "Translate a base64 article.
2612 If FORCE, decode the article whether it is marked as base64 not.
2613 If READ-CHARSET, ask for a coding system."
2614 (interactive (list 'force current-prefix-arg))
2616 (let ((inhibit-read-only t) type charset)
2617 (if (gnus-buffer-live-p gnus-original-article-buffer)
2618 (with-current-buffer gnus-original-article-buffer
2620 (gnus-fetch-field "content-transfer-encoding"))
2621 (let* ((ct (gnus-fetch-field "content-type"))
2622 (ctl (and ct (mail-header-parse-content-type ct))))
2623 (setq charset (and ctl
2624 (mail-content-type-get ctl 'charset)))
2625 (if (stringp charset)
2626 (setq charset (intern (downcase charset)))))))
2628 (setq charset (mm-read-coding-system "Charset: " charset)))
2630 (setq charset gnus-newsgroup-charset))
2632 (and type (let ((case-fold-search t))
2633 (string-match "base64" type))))
2636 (narrow-to-region (point) (point-max))
2637 (base64-decode-region (point-min) (point-max))
2638 (mm-decode-coding-region
2639 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2644 (defun article-decode-HZ ()
2645 "Translate a HZ-encoded article."
2649 (let ((inhibit-read-only t))
2650 (rfc1843-decode-region (point-min) (point-max)))))
2652 (defun article-unsplit-urls ()
2653 "Remove the newlines that some other mailers insert into URLs."
2656 (let ((inhibit-read-only t))
2657 (goto-char (point-min))
2658 (while (re-search-forward
2659 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2660 (replace-match "\\1\\3" t)))
2661 (when (interactive-p)
2662 (gnus-treat-article nil))))
2665 (defun article-wash-html (&optional read-charset)
2666 "Format an HTML article.
2667 If READ-CHARSET, ask for a coding system. If it is a number, the
2668 charset defined in `gnus-summary-show-article-charset-alist' is used."
2671 (let ((inhibit-read-only t)
2674 (if (or (and (numberp read-charset)
2678 gnus-summary-show-article-charset-alist))))
2679 (setq charset (mm-read-coding-system "Charset: ")))
2680 (let ((gnus-summary-show-article-charset-alist
2681 (list (cons 1 charset))))
2682 (with-current-buffer gnus-summary-buffer
2683 (gnus-summary-show-article 1)))
2684 (error "No charset is given"))
2685 (when (gnus-buffer-live-p gnus-original-article-buffer)
2686 (with-current-buffer gnus-original-article-buffer
2687 (let* ((ct (gnus-fetch-field "content-type"))
2688 (ctl (and ct (mail-header-parse-content-type ct))))
2689 (setq charset (and ctl
2690 (mail-content-type-get ctl 'charset)))
2691 (when (stringp charset)
2692 (setq charset (intern (downcase charset)))))))
2694 (setq charset gnus-newsgroup-charset)))
2696 (save-window-excursion
2698 (narrow-to-region (point) (point-max))
2699 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2700 (entry (assq func mm-text-html-washer-alist)))
2702 (setq func (cdr entry)))
2707 (apply (car func) (cdr func))))))))))
2709 (defun gnus-article-wash-html-with-w3 ()
2710 "Wash the current buffer with w3."
2712 (let ((w3-strict-width (window-width))
2713 (url-standalone-mode t)
2714 (url-gateway-unplugged t)
2715 (w3-honor-stylesheets nil))
2717 (w3-region (point-min) (point-max))
2720 (defun gnus-article-wash-html-with-w3m ()
2721 "Wash the current buffer with emacs-w3m."
2723 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2724 w3m-force-redisplay)
2725 (w3m-region (point-min) (point-max)))
2726 (when (and mm-inline-text-html-with-w3m-keymap
2727 (boundp 'w3m-minor-mode-map)
2729 (add-text-properties
2730 (point-min) (point-max)
2731 (list 'keymap w3m-minor-mode-map
2732 ;; Put the mark meaning this part was rendered by emacs-w3m.
2733 'mm-inline-text-html-with-w3m t))))
2735 (eval-when-compile (defvar charset)) ;; Bound by `article-wash-html'.
2737 (defun gnus-article-wash-html-with-w3m-standalone ()
2738 "Wash the current buffer with w3m."
2739 (if (mm-w3m-standalone-supports-m17n-p)
2741 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2743 (setq charset 'iso-8859-1))
2744 (let ((coding-system-for-write charset)
2745 (coding-system-for-read charset))
2746 (call-process-region
2747 (point-min) (point-max)
2748 "w3m" t t nil "-dump" "-T" "text/html"
2749 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2750 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2752 (defvar gnus-article-browse-html-temp-list nil
2753 "List of temporary files created by `gnus-article-browse-html-parts'.
2754 Internal variable.")
2756 (defcustom gnus-article-browse-delete-temp 'ask
2757 "What to do with temporary files from `gnus-article-browse-html-parts'.
2758 If nil, don't delete temporary files. If it is t, delete them on
2759 exit from the summary buffer. If it is the symbol `file', query
2760 on each file, if it is `ask' ask once when exiting from the
2762 :group 'gnus-article
2763 :version "23.0" ;; No Gnus
2764 :type '(choice (const :tag "Don't delete" nil)
2765 (const :tag "Don't ask" t)
2766 (const :tag "Ask" ask)
2767 (const :tag "Ask for each file" file)))
2769 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2771 (defun gnus-article-browse-delete-temp-files (&optional how)
2772 "Delete temp-files created by `gnus-article-browse-html-parts'."
2773 (when (and gnus-article-browse-html-temp-list
2775 (setq how gnus-article-browse-delete-temp)))
2776 (when (and (eq how 'ask)
2778 "Delete all %s temporary HTML file(s)? "
2779 (length gnus-article-browse-html-temp-list)))
2781 (dolist (file gnus-article-browse-html-temp-list)
2782 (when (and (file-exists-p file)
2784 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2786 (format "Delete temporary HTML file `%s'? " file))))
2787 (delete-file file)))
2788 ;; Also remove file from the list when not deleted or if file doesn't
2790 (setq gnus-article-browse-html-temp-list nil))
2791 gnus-article-browse-html-temp-list)
2793 (defun gnus-article-browse-html-parts (list)
2794 "View all \"text/html\" parts from LIST.
2795 Recurse into multiparts."
2796 ;; Internal function used by `gnus-article-browse-html-article'.
2798 ;; Find and show the html-parts.
2799 (dolist (handle list)
2800 ;; If HTML, show it:
2801 (when (listp handle)
2802 (cond ((and (bufferp (car handle))
2803 (string-match "text/html" (car (mm-handle-type handle))))
2804 (let ((tmp-file (mm-make-temp-file
2805 ;; Do we need to care for 8.3 filenames?
2807 (charset (mail-content-type-get (mm-handle-type handle)
2810 ;; Add a meta html tag to specify charset.
2811 (mm-with-unibyte-buffer
2812 (insert (with-current-buffer (mm-handle-buffer handle)
2813 (if (eq charset 'gnus-decoded)
2814 (mm-encode-coding-string
2816 (setq charset 'utf-8))
2818 (setq charset (format "\
2819 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">"
2821 (goto-char (point-min))
2822 (let ((case-fold-search t))
2823 (cond (;; Don't modify existing meta tag.
2824 (re-search-forward "\
2825 <meta[\t\n\r ]+http-equiv=\"content-type\"[^>]+>"
2827 ((re-search-forward "<head>[\t\n\r ]*" nil t)
2828 (insert charset "\n"))
2830 (re-search-forward "\
2831 <html\\(?:[\t\n\r ]+[^>]+\\|[\t\n\r ]*\\)>[\t\n\r ]*"
2833 (insert "<head>\n" charset "\n</head>\n"))))
2834 (mm-write-region (point-min) (point-max)
2835 tmp-file nil nil nil 'binary t))
2836 (mm-save-part-to-file handle tmp-file))
2837 (add-to-list 'gnus-article-browse-html-temp-list tmp-file)
2838 (add-hook 'gnus-summary-prepare-exit-hook
2839 'gnus-article-browse-delete-temp-files)
2840 (add-hook 'gnus-exit-gnus-hook
2842 (gnus-article-browse-delete-temp-files t)))
2843 ;; FIXME: Warn if there's an <img> tag?
2844 (browse-url-of-file tmp-file)
2846 ;; If multipart, recurse
2847 ((and (stringp (car handle))
2848 (string-match "^multipart/" (car handle))
2851 (gnus-article-browse-html-parts handle))))))))
2854 ;; FIXME: Documentation in texi/gnus.texi missing.
2855 (defun gnus-article-browse-html-article ()
2856 "View \"text/html\" parts of the current article with a WWW browser.
2858 Warning: Spammers use links to images in HTML articles to verify
2859 whether you have read the message. As
2860 `gnus-article-browse-html-article' passes the unmodified HTML
2861 content to the browser without eliminating these \"web bugs\" you
2862 should only use it for mails from trusted senders.
2864 If you alwasy want to display HTML part in the browser, set
2865 `mm-text-html-renderer' to nil."
2866 ;; Cf. `mm-w3m-safe-url-regexp'
2868 (save-window-excursion
2869 ;; Open raw article and select the buffer
2870 (gnus-summary-show-article t)
2871 (gnus-summary-select-article-buffer)
2872 (let ((parts (mm-dissect-buffer t t)))
2873 ;; If singlepart, enforce a list.
2874 (when (and (bufferp (car parts))
2875 (stringp (car (mm-handle-type parts))))
2876 (setq parts (list parts)))
2878 (unless (gnus-article-browse-html-parts parts)
2879 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
2880 (gnus-summary-show-article))))
2882 (defun article-hide-list-identifiers ()
2883 "Remove list identifies from the Subject header.
2884 The `gnus-list-identifiers' variable specifies what to do."
2886 (let ((inhibit-point-motion-hooks t)
2887 (regexp (if (consp gnus-list-identifiers)
2888 (mapconcat 'identity gnus-list-identifiers " *\\|")
2889 gnus-list-identifiers))
2890 (inhibit-read-only t))
2894 (article-narrow-to-head)
2895 (goto-char (point-min))
2896 (while (re-search-forward
2897 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2899 (delete-region (match-beginning 2) (match-end 0))
2900 (beginning-of-line))
2901 (when (re-search-forward
2902 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2903 (delete-region (match-beginning 1) (match-end 1))))))))
2905 (defun article-hide-pem (&optional arg)
2906 "Toggle hiding of any PEM headers and signatures in the current article.
2907 If given a negative prefix, always show; if given a positive prefix,
2909 (interactive (gnus-article-hidden-arg))
2910 (unless (gnus-article-check-hidden-text 'pem arg)
2912 (let ((inhibit-read-only t) end)
2913 (goto-char (point-min))
2914 ;; Hide the horrendously ugly "header".
2915 (when (and (search-forward
2916 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2918 (setq end (1+ (match-beginning 0))))
2919 (gnus-add-wash-type 'pem)
2920 (gnus-article-hide-text-type
2922 (if (search-forward "\n\n" nil t)
2926 ;; Hide the trailer as well
2927 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2929 (gnus-article-hide-text-type
2930 (match-beginning 0) (match-end 0) 'pem)))))))
2932 (defun article-strip-banner ()
2933 "Strip the banners specified by the `banner' group parameter and by
2934 `gnus-article-address-banner-alist'."
2938 (let ((inhibit-point-motion-hooks t))
2939 (when (gnus-parameter-banner gnus-newsgroup-name)
2940 (article-really-strip-banner
2941 (gnus-parameter-banner gnus-newsgroup-name)))
2942 (when gnus-article-address-banner-alist
2943 ;; Note that the From header is decoded here, so it is
2944 ;; required that the *-extract-address-components function
2945 ;; supports non-ASCII text.
2946 (let ((from (save-restriction
2948 (article-narrow-to-head)
2949 (mail-fetch-field "from"))))
2952 (cadr (funcall gnus-extract-address-components
2955 (dolist (pair gnus-article-address-banner-alist)
2956 (when (string-match (car pair) from)
2958 (article-really-strip-banner (cdr pair)))))))))))))
2960 (defun article-really-strip-banner (banner)
2961 "Strip the banner specified by the argument."
2964 (let ((inhibit-point-motion-hooks t)
2965 (gnus-signature-limit nil)
2966 (inhibit-read-only t))
2969 ((eq banner 'signature)
2970 (when (gnus-article-narrow-to-signature)
2973 (delete-region (point) (point-max))))
2975 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2976 (while (re-search-forward banner nil t)
2977 (delete-region (match-beginning 0) (match-end 0)))))
2979 (while (re-search-forward banner nil t)
2980 (delete-region (match-beginning 0) (match-end 0)))))))))
2982 (defun article-babel ()
2983 "Translate article using an online translation service."
2986 (gnus-with-article-buffer
2987 (when (article-goto-body)
2988 (let* ((start (point))
2990 (orig (buffer-substring start end))
2991 (trans (babel-as-string orig)))
2993 (narrow-to-region start end)
2994 (delete-region start end)
2997 (defun article-hide-signature (&optional arg)
2998 "Hide the signature in the current article.
2999 If given a negative prefix, always show; if given a positive prefix,
3001 (interactive (gnus-article-hidden-arg))
3002 (unless (gnus-article-check-hidden-text 'signature arg)
3005 (let ((inhibit-read-only t))
3006 (when (gnus-article-narrow-to-signature)
3007 (gnus-article-hide-text-type
3008 (point-min) (point-max) 'signature))))))
3009 (gnus-set-mode-line 'article))
3011 (defun article-strip-headers-in-body ()
3012 "Strip offensive headers from bodies."
3016 (let ((case-fold-search t))
3017 (when (looking-at "x-no-archive:")
3018 (gnus-delete-line)))))
3020 (defun article-strip-leading-blank-lines ()
3021 "Remove all blank lines from the beginning of the article."
3024 (let ((inhibit-point-motion-hooks t)
3025 (inhibit-read-only t))
3026 (when (article-goto-body)
3027 (while (and (not (eobp))
3028 (looking-at "[ \t]*$"))
3029 (gnus-delete-line))))))
3031 (defun article-narrow-to-head ()
3032 "Narrow the buffer to the head of the message.
3033 Point is left at the beginning of the narrowed-to region."
3035 (goto-char (point-min))
3036 (if (search-forward "\n\n" nil 1)
3039 (goto-char (point-min)))
3041 (defun article-goto-body ()
3042 "Place point at the start of the body."
3043 (goto-char (point-min))
3045 ;; This variable is only bound when dealing with separate
3047 (article-goto-body-goes-to-point-min-p
3049 ((search-forward "\n\n" nil t)
3052 (goto-char (point-max))
3055 (defun article-strip-multiple-blank-lines ()
3056 "Replace consecutive blank lines with one empty line."
3059 (let ((inhibit-point-motion-hooks t)
3060 (inhibit-read-only t))
3061 ;; First make all blank lines empty.
3063 (while (re-search-forward "^[ \t]+$" nil t)
3064 (unless (gnus-annotation-in-region-p
3065 (match-beginning 0) (match-end 0))
3066 (replace-match "" nil t)))
3067 ;; Then replace multiple empty lines with a single empty line.
3069 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3070 (unless (gnus-annotation-in-region-p
3071 (match-beginning 0) (match-end 0))
3072 (delete-region (match-beginning 1) (match-end 1)))))))
3074 (defun article-strip-leading-space ()
3075 "Remove all white space from the beginning of the lines in the article."
3078 (let ((inhibit-point-motion-hooks t)
3079 (inhibit-read-only t))
3081 (while (re-search-forward "^[ \t]+" nil t)
3082 (replace-match "" t t)))))
3084 (defun article-strip-trailing-space ()
3085 "Remove all white space from the end of the lines in the article."
3088 (let ((inhibit-point-motion-hooks t)
3089 (inhibit-read-only t))
3091 (while (re-search-forward "[ \t]+$" nil t)
3092 (replace-match "" t t)))))
3094 (defun article-strip-blank-lines ()
3095 "Strip leading, trailing and multiple blank lines."
3097 (article-strip-leading-blank-lines)
3098 (article-remove-trailing-blank-lines)
3099 (article-strip-multiple-blank-lines))
3101 (defun article-strip-all-blank-lines ()
3102 "Strip all blank lines."
3105 (let ((inhibit-point-motion-hooks t)
3106 (inhibit-read-only t))
3108 (while (re-search-forward "^[ \t]*\n" nil t)
3109 (replace-match "" t t)))))
3111 (defun gnus-article-narrow-to-signature ()
3112 "Narrow to the signature; return t if a signature is found, else nil."
3113 (let ((inhibit-point-motion-hooks t))
3114 (when (gnus-article-search-signature)
3116 ;; Check whether we have some limits to what we consider
3117 ;; to be a signature.
3118 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3119 (list gnus-signature-limit)))
3121 (while (setq limit (pop limits))
3122 (if (or (and (integerp limit)
3123 (< (- (point-max) (point)) limit))
3125 (< (count-lines (point) (point-max)) limit))
3126 (and (functionp limit)
3128 (and (stringp limit)
3129 (not (re-search-forward limit nil t))))
3130 () ; This limit did not succeed.
3134 (narrow-to-region (point) (point-max))
3137 (defun gnus-article-search-signature ()
3138 "Search the current buffer for the signature separator.
3139 Put point at the beginning of the signature separator."
3140 (let ((cur (point)))
3141 (goto-char (point-max))
3142 (if (if (stringp gnus-signature-separator)
3143 (re-search-backward gnus-signature-separator nil t)
3144 (let ((seps gnus-signature-separator))
3146 (not (re-search-backward (car seps) nil t)))
3153 (defun gnus-article-hidden-arg ()
3154 "Return the current prefix arg as a number, or 0 if no prefix."
3155 (list (if current-prefix-arg
3156 (prefix-numeric-value current-prefix-arg)
3159 (defun gnus-article-check-hidden-text (type arg)
3160 "Return nil if hiding is necessary.
3161 Arg can be nil or a number. nil and positive means hide, negative
3162 means show, 0 means toggle."
3165 (let ((hide (gnus-article-hidden-text-p type)))
3171 (gnus-article-show-hidden-text type)
3174 (if (eq hide 'hidden)
3176 (gnus-article-show-hidden-text type)
3180 (defun gnus-article-hidden-text-p (type)
3181 "Say whether the current buffer contains hidden text of type TYPE."
3182 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3184 (not (get-text-property pos 'invisible))
3185 (not (get-text-property pos 'dummy-invisible)))
3187 (text-property-any (1+ pos) (point-max) 'article-type type)))
3192 (defun gnus-article-show-hidden-text (type &optional dummy)
3193 "Show all hidden text of type TYPE.
3194 Originally it is hide instead of DUMMY."
3195 (let ((inhibit-read-only t)
3196 (inhibit-point-motion-hooks t))
3197 (gnus-remove-text-properties-when
3199 (point-min) (point-max)
3200 (cons 'article-type (cons type
3201 gnus-hidden-properties)))
3202 (gnus-delete-wash-type type)))
3204 (defconst article-time-units
3205 `((year . ,(* 365.25 24 60 60))
3206 (week . ,(* 7 24 60 60))
3207 (day . ,(* 24 60 60))
3211 "Mapping from time units to seconds.")
3213 (defun gnus-article-forward-header ()
3214 "Move point to the start of the next header.
3215 If the current header is a continuation header, this can be several
3220 (if (looking-at "[ \t]+[^ \t]")
3224 (defun article-date-ut (&optional type highlight)
3225 "Convert DATE date to universal time in the current article.
3226 If TYPE is `local', convert to local time; if it is `lapsed', output
3227 how much time has lapsed since DATE. For `lapsed', the value of
3228 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3229 should replace the \"Date:\" one, or should be added below it."
3230 (interactive (list 'ut t))
3231 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3232 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3236 (article-lapsed-timer
3240 (case-fold-search t)
3241 (inhibit-read-only t)
3242 (inhibit-point-motion-hooks t)
3243 pos date bface eface)
3247 (goto-char (point-min))
3248 (while (or (setq date (get-text-property (setq pos (point))
3250 (when (setq pos (next-single-property-change
3251 (point) 'original-date))
3252 (setq date (get-text-property pos 'original-date))
3254 (narrow-to-region pos (or (text-property-any pos (point-max)
3257 (goto-char (point-min))
3258 (when (re-search-forward tdate-regexp nil t)
3259 (setq bface (get-text-property (point-at-bol) 'face)
3260 eface (get-text-property (1- (point-at-eol)) 'face)))
3261 (goto-char (point-min))
3263 ;; Delete any old Date headers.
3264 (while (re-search-forward date-regexp nil t)
3266 (delete-region (point-at-bol) (progn
3267 (gnus-article-forward-header)
3269 (delete-region (point-at-bol) (progn
3270 (gnus-article-forward-header)
3273 (setq pos (point))))
3274 (when (and (not pos)
3275 (re-search-forward tdate-regexp nil t))
3277 (gnus-goto-char pos)
3278 (insert (article-make-date-line date (or type 'ut)))
3284 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3285 (put-text-property (match-beginning 1) (1+ (match-end 1))
3287 (put-text-property (match-beginning 2) (match-end 2)
3289 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3290 (goto-char (point-max))
3293 (defun article-make-date-line (date type)
3294 "Return a DATE line of TYPE."
3295 (unless (memq type '(local ut original user iso8601 lapsed english))
3296 (error "Unknown conversion type: %s" type))
3298 (let ((time (date-to-time date)))
3300 ;; Convert to the local timezone.
3302 (concat "Date: " (message-make-date time)))
3303 ;; Convert to Universal Time.
3308 (let* ((e (parse-time-string date))
3309 (tm (apply 'encode-time e))
3311 (ls (- (cadr tm) (car (current-time-zone time)))))
3312 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3313 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3317 ;; Get the original date from the article.
3318 ((eq type 'original)
3319 (concat "Date: " (if (string-match "\n+$" date)
3320 (substring date 0 (match-beginning 0))
3322 ;; Let the user define the format.
3324 (let ((format (or (condition-case nil
3325 (with-current-buffer gnus-summary-buffer
3326 gnus-article-time-format)
3328 gnus-article-time-format)))
3329 (if (functionp format)
3330 (funcall format time)
3331 (concat "Date: " (format-time-string format time)))))
3334 (let ((tz (car (current-time-zone time))))
3337 (format-time-string "%Y%m%dT%H%M%S" time)
3338 (format "%s%02d%02d"
3339 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3340 (/ (% (abs tz) 3600) 60)))))
3341 ;; Do an X-Sent lapsed format.
3343 ;; If the date is seriously mangled, the timezone functions are
3344 ;; liable to bug out, so we ignore all errors.
3345 (let* ((now (current-time))
3346 (real-time (subtract-time now time))
3347 (real-sec (and real-time
3348 (+ (* (float (car real-time)) 65536)
3350 (sec (and real-time (abs real-sec)))
3360 ;; This is a bit convoluted, but basically we go
3361 ;; through the time units for years, weeks, etc,
3362 ;; and divide things to see whether that results
3363 ;; in positive answers.
3366 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3367 ;; The (remaining) seconds are too few to
3368 ;; be divided into this time unit.
3370 ;; It's big enough, so we output it.
3371 (setq sec (- sec (* num (cdr unit))))
3373 (concat (if prev ", " "") (int-to-string
3375 " " (symbol-name (car unit))
3376 (if (> num 1) "s" ""))
3378 article-time-units "")
3379 ;; If dates are odd, then it might appear like the
3380 ;; article was sent in the future.
3383 " in the future"))))))
3384 ;; Display the date in proper English
3386 (let ((dtime (decode-time time)))
3389 (number-to-string (nth 3 dtime))
3390 (let ((digit (% (nth 3 dtime) 10)))
3392 ((memq (nth 3 dtime) '(11 12 13)) "th")
3398 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3400 (number-to-string (nth 5 dtime))
3402 (format "%02d" (nth 2 dtime))
3404 (format "%02d" (nth 1 dtime)))))))
3406 (format "Date: %s (from Gnus)" date))))
3408 (defun article-date-local (&optional highlight)
3409 "Convert the current article date to the local timezone."
3410 (interactive (list t))
3411 (article-date-ut 'local highlight))
3413 (defun article-date-english (&optional highlight)
3414 "Convert the current article date to something that is proper English."
3415 (interactive (list t))
3416 (article-date-ut 'english highlight))
3418 (defun article-date-original (&optional highlight)
3419 "Convert the current article date to what it was originally.
3420 This is only useful if you have used some other date conversion
3421 function and want to see what the date was before converting."
3422 (interactive (list t))
3423 (article-date-ut 'original highlight))
3425 (defun article-date-lapsed (&optional highlight)
3426 "Convert the current article date to time lapsed since it was sent."
3427 (interactive (list t))
3428 (article-date-ut 'lapsed highlight))
3430 (defun article-update-date-lapsed ()
3431 "Function to be run from a timer to update the lapsed time line."
3433 (let (deactivate-mark)
3438 (set-buffer (window-buffer w))
3439 (when (eq major-mode 'gnus-article-mode)
3440 (let ((mark (point-marker)))
3441 (goto-char (point-min))
3442 (when (re-search-forward "^X-Sent:" nil t)
3443 (article-date-lapsed t))
3444 (goto-char (marker-position mark))
3445 (move-marker mark nil))))
3448 (defun gnus-start-date-timer (&optional n)
3449 "Start a timer to update the X-Sent header in the article buffers.
3450 The numerical prefix says how frequently (in seconds) the function
3455 (gnus-stop-date-timer)
3456 (setq article-lapsed-timer
3457 (run-at-time 1 n 'article-update-date-lapsed)))
3459 (defun gnus-stop-date-timer ()
3460 "Stop the X-Sent timer."
3462 (when article-lapsed-timer
3463 (nnheader-cancel-timer article-lapsed-timer)
3464 (setq article-lapsed-timer nil)))
3466 (defun article-date-user (&optional highlight)
3467 "Convert the current article date to the user-defined format.
3468 This format is defined by the `gnus-article-time-format' variable."
3469 (interactive (list t))
3470 (article-date-ut 'user highlight))
3472 (defun article-date-iso8601 (&optional highlight)
3473 "Convert the current article date to ISO8601."
3474 (interactive (list t))
3475 (article-date-ut 'iso8601 highlight))
3477 (defmacro gnus-article-save-original-date (&rest forms)
3478 "Save the original date as a text property and evaluate FORMS."
3479 `(let* ((case-fold-search t)
3481 (goto-char (point-min))
3482 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3485 (date (when (and start
3486 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3488 (buffer-substring-no-properties start
3489 (match-beginning 0)))))
3490 (goto-char (point-max))
3491 (skip-chars-backward "\n")
3492 (put-text-property (point-min) (point) 'original-date date)
3494 (goto-char (point-max))
3495 (skip-chars-backward "\n")
3496 (put-text-property (point-min) (point) 'original-date date)))
3498 ;; (defun article-show-all ()
3499 ;; "Show all hidden text in the article buffer."
3502 ;; (let ((inhibit-read-only t))
3503 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3505 (defun article-remove-leading-whitespace ()
3506 "Remove excessive whitespace from all headers."
3510 (let ((inhibit-read-only t))
3511 (article-narrow-to-head)
3512 (goto-char (point-min))
3513 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3514 (delete-region (match-beginning 1) (match-end 1)))))))
3516 (defun article-emphasize (&optional arg)
3517 "Emphasize text according to `gnus-emphasis-alist'."
3518 (interactive (gnus-article-hidden-arg))
3519 (unless (gnus-article-check-hidden-text 'emphasis arg)
3523 (with-current-buffer gnus-summary-buffer
3524 gnus-article-emphasis-alist)
3526 gnus-emphasis-alist))
3527 (inhibit-read-only t)
3528 (props (append '(article-type emphasis)
3529 gnus-hidden-properties))
3530 regexp elem beg invisible visible face)
3533 (while (setq elem (pop alist))
3535 (setq regexp (car elem)
3536 invisible (nth 1 elem)
3537 visible (nth 2 elem)
3539 (while (re-search-forward regexp nil t)
3540 (when (and (match-beginning visible) (match-beginning invisible))
3541 (gnus-article-hide-text
3542 (match-beginning invisible) (match-end invisible) props)
3543 (gnus-article-unhide-text-type
3544 (match-beginning visible) (match-end visible) 'emphasis)
3545 (gnus-put-overlay-excluding-newlines
3546 (match-beginning visible) (match-end visible) 'face face)
3547 (gnus-add-wash-type 'emphasis)
3548 (goto-char (match-end invisible)))))))))
3550 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3551 "Setup newsgroup emphasis alist."
3552 (unless gnus-article-emphasis-alist
3553 (let ((name (and gnus-newsgroup-name
3554 (gnus-group-real-name gnus-newsgroup-name))))
3555 (make-local-variable 'gnus-article-emphasis-alist)
3556 (setq gnus-article-emphasis-alist
3558 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3559 (while (setq elem (pop alist))
3560 (when (and name (string-match (car elem) name))
3562 highlight (copy-sequence (cdr elem)))))
3564 (copy-sequence highlight-words)
3565 (if gnus-newsgroup-name
3566 (copy-sequence (gnus-group-find-parameter
3567 gnus-newsgroup-name 'highlight-words t)))
3568 gnus-emphasis-alist)))))
3571 (defvar gnus-summary-article-menu)
3572 (defvar gnus-summary-post-menu))
3574 ;;; Saving functions.
3576 (defun gnus-article-save (save-buffer file &optional num)
3577 "Save the currently selected article."
3578 (when (or (get gnus-default-article-saver :headers)
3579 (not gnus-save-all-headers))
3580 ;; Remove headers according to `gnus-saved-headers' or the value
3581 ;; of the `:headers' property that the saver function might have.
3582 (let ((gnus-visible-headers
3583 (or (symbol-value (get gnus-default-article-saver :headers))
3584 gnus-saved-headers gnus-visible-headers))
3585 (gnus-article-buffer save-buffer))
3587 (set-buffer save-buffer)
3588 (article-hide-headers 1 t))))
3589 (save-window-excursion
3590 (if (not gnus-default-article-saver)
3591 (error "No default saver is defined")
3592 ;; !!! Magic! The saving functions all save
3593 ;; `gnus-save-article-buffer' (or so they think), but we
3594 ;; bind that variable to our save-buffer.
3595 (set-buffer gnus-article-buffer)
3596 (let* ((gnus-save-article-buffer save-buffer)
3599 ((not gnus-prompt-before-saving) 'default)
3600 ((eq gnus-prompt-before-saving 'always) nil)
3602 (gnus-number-of-articles-to-be-saved
3603 (when (eq gnus-prompt-before-saving t)
3605 (set-buffer gnus-article-current-summary)
3606 (funcall gnus-default-article-saver filename)))))
3608 (defun gnus-read-save-file-name (prompt &optional filename
3609 function group headers variable
3612 (funcall function group headers (symbol-value variable)))
3617 ((eq filename 'default)
3623 (when (symbol-value dir-var)
3624 (setq default-name (expand-file-name
3625 (file-name-nondirectory default-name)
3626 (symbol-value dir-var))))
3627 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3630 (if (and gnus-number-of-articles-to-be-saved
3631 (> gnus-number-of-articles-to-be-saved 1))
3632 (format "these %d articles"
3633 gnus-number-of-articles-to-be-saved)
3636 ;; Let the split methods have their say.
3638 ;; No split name was found.
3641 (concat prompt " (default "
3642 (file-name-nondirectory default-name) "): ")
3643 (file-name-directory default-name)
3645 ;; A single group name is returned.
3646 ((stringp split-name)
3648 (funcall function split-name headers
3649 (symbol-value variable)))
3651 (concat prompt " (default "
3652 (file-name-nondirectory default-name) "): ")
3653 (file-name-directory default-name)
3655 ;; A single split name was found
3656 ((= 1 (length split-name))
3657 (let* ((name (expand-file-name
3659 gnus-article-save-directory))
3660 (dir (cond ((file-directory-p name)
3661 (file-name-as-directory name))
3662 ((file-exists-p name) name)
3663 (t gnus-article-save-directory))))
3665 (concat prompt " (default " name "): ")
3667 ;; A list of splits was found.
3669 (setq split-name (nreverse split-name))
3671 (let ((file-name-history
3672 (nconc split-name file-name-history)))
3676 (concat prompt " (`M-p' for defaults): ")
3677 gnus-article-save-directory
3679 gnus-article-save-directory)))
3680 (car (push result file-name-history)))))))
3681 ;; Create the directory.
3682 (gnus-make-directory (file-name-directory file))
3683 ;; If we have read a directory, we append the default file name.
3684 (when (file-directory-p file)
3685 (setq file (expand-file-name (file-name-nondirectory
3687 (file-name-as-directory file))))
3688 ;; Possibly translate some characters.
3689 (nnheader-translate-file-chars file))))))
3690 (gnus-make-directory (file-name-directory result))
3692 (set variable result))
3694 (set dir-var (file-name-directory result)))
3697 (defun gnus-article-archive-name (group)
3698 "Return the first instance of an \"Archive-name\" in the current buffer."
3699 (let ((case-fold-search t))
3700 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3701 (nnheader-concat gnus-article-save-directory
3702 (match-string 1)))))
3704 (defun gnus-article-nndoc-name (group)
3705 "If GROUP is an nndoc group, return the name of the parent group."
3706 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3707 (gnus-group-get-parameter group 'save-article-group)))
3709 (defun gnus-summary-save-in-rmail (&optional filename)
3710 "Append this article to Rmail file.
3711 Optional argument FILENAME specifies file name.
3712 Directory to save to is default to `gnus-article-save-directory'."
3713 (setq filename (gnus-read-save-file-name
3714 "Save %s in rmail file" filename
3715 gnus-rmail-save-name gnus-newsgroup-name
3716 gnus-current-headers 'gnus-newsgroup-last-rmail))
3717 (gnus-eval-in-buffer-window gnus-save-article-buffer
3721 (gnus-output-to-rmail filename))))
3724 (defun gnus-summary-save-in-mail (&optional filename)
3725 "Append this article to Unix mail file.
3726 Optional argument FILENAME specifies file name.
3727 Directory to save to is default to `gnus-article-save-directory'."
3728 (setq filename (gnus-read-save-file-name
3729 "Save %s in Unix mail file" filename
3730 gnus-mail-save-name gnus-newsgroup-name
3731 gnus-current-headers 'gnus-newsgroup-last-mail))
3732 (gnus-eval-in-buffer-window gnus-save-article-buffer
3736 (if (and (file-readable-p filename)
3737 (file-regular-p filename)
3738 (mail-file-babyl-p filename))
3739 (rmail-output-to-rmail-file filename t)
3740 (gnus-output-to-mail filename)))))
3743 (put 'gnus-summary-save-in-file :decode t)
3744 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3745 (defun gnus-summary-save-in-file (&optional filename overwrite)
3746 "Append this article to file.
3747 Optional argument FILENAME specifies file name.
3748 Directory to save to is default to `gnus-article-save-directory'."
3749 (setq filename (gnus-read-save-file-name
3750 "Save %s in file" filename
3751 gnus-file-save-name gnus-newsgroup-name
3752 gnus-current-headers 'gnus-newsgroup-last-file))
3753 (gnus-eval-in-buffer-window gnus-save-article-buffer
3757 (when (and overwrite
3758 (file-exists-p filename))
3759 (delete-file filename))
3760 (gnus-output-to-file filename))))
3763 (put 'gnus-summary-write-to-file :decode t)
3764 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3765 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3766 (defun gnus-summary-write-to-file (&optional filename)
3767 "Write this article to a file, overwriting it if the file exists.
3768 Optional argument FILENAME specifies file name.
3769 The directory to save in defaults to `gnus-article-save-directory'."
3770 (setq filename (gnus-read-save-file-name
3771 "Save %s in file" filename
3772 gnus-file-save-name gnus-newsgroup-name
3773 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3774 (gnus-summary-save-in-file filename t))
3776 (put 'gnus-summary-save-body-in-file :decode t)
3777 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3778 "Append this article body to a file.
3779 Optional argument FILENAME specifies file name.
3780 The directory to save in defaults to `gnus-article-save-directory'."
3781 (setq filename (gnus-read-save-file-name
3782 "Save %s body in file" filename
3783 gnus-file-save-name gnus-newsgroup-name
3784 gnus-current-headers 'gnus-newsgroup-last-file))
3785 (gnus-eval-in-buffer-window gnus-save-article-buffer
3789 (when (article-goto-body)
3790 (narrow-to-region (point) (point-max)))
3791 (when (and overwrite
3792 (file-exists-p filename))
3793 (delete-file filename))
3794 (gnus-output-to-file filename))))
3797 (put 'gnus-summary-write-body-to-file :decode t)
3798 (put 'gnus-summary-write-body-to-file
3799 :function 'gnus-summary-save-body-in-file)
3800 (defun gnus-summary-write-body-to-file (&optional filename)
3801 "Write this article body to a file, overwriting it if the file exists.
3802 Optional argument FILENAME specifies file name.
3803 The directory to save in defaults to `gnus-article-save-directory'."
3804 (setq filename (gnus-read-save-file-name
3805 "Save %s body in file" filename
3806 gnus-file-save-name gnus-newsgroup-name
3807 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3808 (gnus-summary-save-body-in-file filename t))
3810 (defun gnus-summary-save-in-pipe (&optional command)
3811 "Pipe this article to subprocess."
3813 (cond ((and (eq command 'default)
3814 gnus-last-shell-command)
3815 gnus-last-shell-command)
3820 "Shell command on %s: "
3821 (if (and gnus-number-of-articles-to-be-saved
3822 (> gnus-number-of-articles-to-be-saved 1))
3823 (format "these %d articles"
3824 gnus-number-of-articles-to-be-saved)
3826 gnus-last-shell-command))))
3827 (when (string-equal command "")
3828 (if gnus-last-shell-command
3829 (setq command gnus-last-shell-command)
3830 (error "A command is required")))
3831 (gnus-eval-in-buffer-window gnus-article-buffer
3834 (shell-command-on-region (point-min) (point-max) command nil)))
3835 (setq gnus-last-shell-command command))
3837 (defun gnus-summary-pipe-to-muttprint (&optional command)
3838 "Pipe this article to muttprint."
3839 (setq command (read-string
3840 "Print using command: " gnus-summary-muttprint-program
3841 nil gnus-summary-muttprint-program))
3842 (gnus-summary-save-in-pipe command))
3844 ;;; Article file names when saving.
3846 (defun gnus-capitalize-newsgroup (newsgroup)
3847 "Capitalize NEWSGROUP name."
3848 (when (not (zerop (length newsgroup)))
3849 (concat (char-to-string (upcase (aref newsgroup 0)))
3850 (substring newsgroup 1))))
3852 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3853 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3854 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3855 Otherwise, it is like ~/News/news/group/num."
3858 (concat (if (gnus-use-long-file-name 'not-save)
3859 (gnus-capitalize-newsgroup newsgroup)
3860 (gnus-newsgroup-directory-form newsgroup))
3861 "/" (int-to-string (mail-header-number headers)))
3862 gnus-article-save-directory)))
3864 (string-equal (file-name-directory default)
3865 (file-name-directory last-file))
3866 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3868 (or last-file default))))
3870 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3871 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3872 If variable `gnus-use-long-file-name' is non-nil, it is
3873 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3876 (concat (if (gnus-use-long-file-name 'not-save)
3878 (gnus-newsgroup-directory-form newsgroup))
3879 "/" (int-to-string (mail-header-number headers)))
3880 gnus-article-save-directory)))
3882 (string-equal (file-name-directory default)
3883 (file-name-directory last-file))
3884 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3886 (or last-file default))))
3888 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3889 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3890 If variable `gnus-use-long-file-name' is non-nil, it is
3891 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3894 (if (gnus-use-long-file-name 'not-save)
3897 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3899 gnus-article-save-directory)))
3901 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3902 "Generate file name from sender."
3903 (let ((from (mail-header-from headers)))
3905 (if (and from (string-match "\\([^ <]+\\)@" from))
3906 (match-string 1 from)
3908 gnus-article-save-directory)))
3910 (defun article-verify-x-pgp-sig ()
3913 (if (gnus-buffer-live-p gnus-original-article-buffer)
3914 (let ((sig (with-current-buffer gnus-original-article-buffer
3915 (gnus-fetch-field "X-PGP-Sig")))
3919 (mml2015-clear-verify-function))
3921 (insert-buffer-substring gnus-original-article-buffer)
3922 (setq items (split-string sig))
3923 (message-narrow-to-head)
3924 (let ((inhibit-point-motion-hooks t)
3925 (case-fold-search t))
3926 ;; Don't verify multiple headers.
3927 (setq headers (mapconcat (lambda (header)
3929 (mail-fetch-field header)
3931 (split-string (nth 1 items) ",") "")))
3932 (delete-region (point-min) (point-max))
3933 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3934 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3939 (if (looking-at "^-")
3942 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3943 (insert "Version: " (car items) "\n\n")
3944 (insert (mapconcat 'identity (cddr items) "\n"))
3945 (insert "\n-----END PGP SIGNATURE-----\n")
3946 (let ((mm-security-handle (list (format "multipart/signed"))))
3947 (mml2015-clean-buffer)
3948 (let ((coding-system-for-write (or gnus-newsgroup-charset
3950 (funcall (mml2015-clear-verify-function)))
3952 (or (mm-handle-multipart-ctl-parameter
3953 mm-security-handle 'gnus-details)
3954 (mm-handle-multipart-ctl-parameter
3955 mm-security-handle 'gnus-info)))))
3957 (let ((inhibit-read-only t) bface eface)
3959 (message-narrow-to-head)
3960 (goto-char (point-max))
3962 (setq bface (get-text-property (point-at-bol) 'face)
3963 eface (get-text-property (1- (point-at-eol)) 'face))
3964 (message-remove-header "X-Gnus-PGP-Verify")
3965 (if (re-search-forward "^X-PGP-Sig:" nil t)
3967 (goto-char (point-max)))
3968 (narrow-to-region (point) (point))
3969 (insert "X-Gnus-PGP-Verify: " info "\n")
3970 (goto-char (point-min))
3973 (if (not (looking-at "^[ \t]"))
3977 (goto-char (point-min))
3978 (when (looking-at "\\([^:]+\\): *")
3979 (put-text-property (match-beginning 1) (1+ (match-end 1))
3981 (put-text-property (match-end 0) (point-max)
3982 'face eface)))))))))
3984 (defun article-verify-cancel-lock ()
3985 "Verify Cancel-Lock header."
3987 (if (gnus-buffer-live-p gnus-original-article-buffer)
3988 (canlock-verify gnus-original-article-buffer)))
3995 (setq afunc (car func)
3998 gfunc (intern (format "gnus-%s" func))))
4000 (when (fboundp afunc)
4001 `(lambda (&optional interactive &rest args)
4002 ,(documentation afunc t)
4003 (interactive (list t))
4005 (set-buffer gnus-article-buffer)
4007 (call-interactively ',afunc)
4008 (apply ',afunc args))))))))
4009 '(article-hide-headers
4010 article-verify-x-pgp-sig
4011 article-verify-cancel-lock
4012 article-hide-boring-headers
4013 article-treat-overstrike
4014 article-treat-ansi-sequences
4015 article-fill-long-lines
4016 article-capitalize-sentences
4018 article-remove-leading-whitespace
4019 article-display-x-face
4020 article-display-face
4021 article-de-quoted-unreadable
4022 article-de-base64-unreadable
4025 article-unsplit-urls
4026 article-hide-list-identifiers
4027 article-strip-banner
4030 article-hide-signature
4031 article-strip-headers-in-body
4032 article-remove-trailing-blank-lines
4033 article-strip-leading-blank-lines
4034 article-strip-multiple-blank-lines
4035 article-strip-leading-space
4036 article-strip-trailing-space
4037 article-strip-blank-lines
4038 article-strip-all-blank-lines
4040 article-date-english
4041 article-date-iso8601
4042 article-date-original
4044 article-decode-mime-words
4045 article-decode-charset
4046 article-decode-encoded-words
4050 article-treat-dumbquotes
4051 article-normalize-headers
4052 ;;(article-show-all . gnus-article-show-all-headers)
4056 ;;; Gnus article mode
4059 (put 'gnus-article-mode 'mode-class 'special)
4061 (set-keymap-parent gnus-article-mode-map widget-keymap)
4063 (gnus-define-keys gnus-article-mode-map
4064 " " gnus-article-goto-next-page
4065 "\177" gnus-article-goto-prev-page
4066 [delete] gnus-article-goto-prev-page
4067 [backspace] gnus-article-goto-prev-page
4068 "\C-c^" gnus-article-refer-article
4069 "h" gnus-article-show-summary
4070 "s" gnus-article-show-summary
4071 "\C-c\C-m" gnus-article-mail
4072 "?" gnus-article-describe-briefly
4073 "e" gnus-summary-edit-article
4074 "<" beginning-of-buffer
4076 "\C-c\C-i" gnus-info-find-node
4078 "R" gnus-article-reply-with-original
4079 "F" gnus-article-followup-with-original
4080 "\C-hk" gnus-article-describe-key
4081 "\C-hc" gnus-article-describe-key-briefly
4083 "\C-d" gnus-article-read-summary-keys
4084 "\M-*" gnus-article-read-summary-keys
4085 "\M-#" gnus-article-read-summary-keys
4086 "\M-^" gnus-article-read-summary-keys
4087 "\M-g" gnus-article-read-summary-keys)
4089 (substitute-key-definition
4090 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4092 (defun gnus-article-make-menu-bar ()
4093 (unless (boundp 'gnus-article-commands-menu)
4094 (gnus-summary-make-menu-bar))
4095 (gnus-turn-off-edit-menu 'article)
4096 (unless (boundp 'gnus-article-article-menu)
4098 gnus-article-article-menu gnus-article-mode-map ""
4100 ["Scroll forwards" gnus-article-goto-next-page t]
4101 ["Scroll backwards" gnus-article-goto-prev-page t]
4102 ["Show summary" gnus-article-show-summary t]
4103 ["Fetch Message-ID at point" gnus-article-refer-article t]
4104 ["Mail to address at point" gnus-article-mail t]
4105 ["Send a bug report" gnus-bug t]))
4108 gnus-article-treatment-menu gnus-article-mode-map ""
4109 ;; Fixme: this should use :active (and maybe :visible).
4111 ["Hide headers" gnus-article-hide-headers t]
4112 ["Hide signature" gnus-article-hide-signature t]
4113 ["Hide citation" gnus-article-hide-citation t]
4114 ["Treat overstrike" gnus-article-treat-overstrike t]
4115 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4116 ["Remove carriage return" gnus-article-remove-cr t]
4117 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4118 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4119 ["Remove base64" gnus-article-de-base64-unreadable t]
4120 ["Treat html" gnus-article-wash-html t]
4121 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4122 ["Decode HZ" gnus-article-decode-HZ t]))
4124 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4126 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4128 (gnus-run-hooks 'gnus-article-menu-hook)))
4130 (defun gnus-article-mode ()
4131 "Major mode for displaying an article.
4133 All normal editing commands are switched off.
4135 The following commands are available in addition to all summary mode
4137 \\<gnus-article-mode-map>
4138 \\[gnus-article-next-page]\t Scroll the article one page forwards
4139 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4140 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4141 \\[gnus-article-show-summary]\t Display the summary buffer
4142 \\[gnus-article-mail]\t Send a reply to the address near point
4143 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4144 \\[gnus-info-find-node]\t Go to the Gnus info node"
4146 (kill-all-local-variables)
4147 (gnus-simplify-mode-line)
4148 (setq mode-name "Article")
4149 (setq major-mode 'gnus-article-mode)
4150 (make-local-variable 'minor-mode-alist)
4151 (use-local-map gnus-article-mode-map)
4152 (when (gnus-visual-p 'article-menu 'menu)
4153 (gnus-article-make-menu-bar)
4154 (when gnus-summary-tool-bar-map
4155 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4156 (gnus-update-format-specifications nil 'article-mode)
4157 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4158 (set (make-local-variable 'gnus-page-broken) nil)
4159 (make-local-variable 'gnus-button-marker-list)
4160 (make-local-variable 'gnus-article-current-summary)
4161 (make-local-variable 'gnus-article-mime-handles)
4162 (make-local-variable 'gnus-article-decoded-p)
4163 (make-local-variable 'gnus-article-mime-handle-alist)
4164 (make-local-variable 'gnus-article-wash-types)
4165 (make-local-variable 'gnus-article-image-alist)
4166 (make-local-variable 'gnus-article-charset)
4167 (make-local-variable 'gnus-article-ignored-charsets)
4168 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4170 (set (make-local-variable 'nobreak-char-display) nil)
4171 (setq cursor-in-non-selected-windows nil)
4172 (setq truncate-lines gnus-article-truncate-lines)
4173 (gnus-set-default-directory)
4174 (buffer-disable-undo)
4175 (setq buffer-read-only t
4176 show-trailing-whitespace nil)
4177 (set-syntax-table gnus-article-mode-syntax-table)
4178 (mm-enable-multibyte)
4179 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4181 (defvar gnus-button-marker-list nil
4182 "Regexp matching any of the regexps from `gnus-button-alist'.
4183 Internal variable.")
4185 (defun gnus-article-setup-buffer ()
4186 "Initialize the article buffer."
4187 (let* ((name (if gnus-single-article-buffer "*Article*"
4188 (concat "*Article " gnus-newsgroup-name "*")))
4190 (progn (string-match "\\*Article" name)
4191 (concat " *Original Article"
4192 (substring name (match-end 0))))))
4193 (setq gnus-article-buffer name)
4194 (setq gnus-original-article-buffer original)
4195 (setq gnus-article-mime-handle-alist nil)
4196 (with-current-buffer gnus-summary-buffer
4197 ;; This might be a variable local to the summary buffer.
4198 (unless gnus-single-article-buffer
4199 (setq gnus-article-buffer name)
4200 (setq gnus-original-article-buffer original)
4201 (gnus-set-global-variables)))
4202 (gnus-article-setup-highlight-words)
4203 ;; Init original article buffer.
4205 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4206 (mm-enable-multibyte)
4207 (setq major-mode 'gnus-original-article-mode)
4208 (make-local-variable 'gnus-original-article))
4209 (if (and (get-buffer name)
4210 (with-current-buffer name
4211 (if gnus-article-edit-mode
4212 (if (y-or-n-p "Article mode edit in progress; discard? ")
4214 (set-buffer-modified-p nil)
4215 (gnus-kill-buffer name)
4218 (error "Action aborted"))
4222 (set (make-local-variable 'gnus-article-edit-mode) nil)
4223 (when gnus-article-mime-handles
4224 (mm-destroy-parts gnus-article-mime-handles)
4225 (setq gnus-article-mime-handles nil))
4226 ;; Set it to nil in article-buffer!
4227 (setq gnus-article-mime-handle-alist nil)
4228 (buffer-disable-undo)
4229 (setq buffer-read-only t)
4230 ;; This list just keeps growing if we don't reset it.
4231 (setq gnus-button-marker-list nil)
4232 (unless (eq major-mode 'gnus-article-mode)
4233 (gnus-article-mode))
4236 (set-buffer (gnus-get-buffer-create name))
4238 (make-local-variable 'gnus-summary-buffer)
4239 (setq gnus-summary-buffer
4240 (gnus-summary-buffer-name gnus-newsgroup-name))
4241 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4242 (current-buffer)))))
4244 ;; Set article window start at LINE, where LINE is the number of lines
4245 ;; from the head of the article.
4246 (defun gnus-article-set-window-start (&optional line)
4247 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4248 (when article-window
4252 (set-buffer gnus-article-buffer)
4253 (goto-char (point-min))
4256 (gnus-message 6 "Moved to bookmark")
4257 (search-forward "\n\n" nil t)
4261 (defun gnus-article-prepare (article &optional all-headers header)
4262 "Prepare ARTICLE in article mode buffer.
4263 ARTICLE should either be an article number or a Message-ID.
4264 If ARTICLE is an id, HEADER should be the article headers.
4265 If ALL-HEADERS is non-nil, no headers are hidden."
4267 ;; Make sure we start in a summary buffer.
4268 (unless (eq major-mode 'gnus-summary-mode)
4269 (set-buffer gnus-summary-buffer))
4270 (setq gnus-summary-buffer (current-buffer))
4271 (let* ((gnus-article (if header (mail-header-number header) article))
4272 (summary-buffer (current-buffer))
4273 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4274 (group gnus-newsgroup-name)
4277 (gnus-article-setup-buffer)
4278 (set-buffer gnus-article-buffer)
4279 ;; Deactivate active regions.
4280 (when (and (boundp 'transient-mark-mode)
4281 transient-mark-mode)
4282 (setq mark-active nil))
4283 (if (not (setq result (let ((inhibit-read-only t))
4284 (gnus-request-article-this-buffer
4286 ;; There is no such article.
4288 (when (and (numberp article)
4289 (not (memq article gnus-newsgroup-sparse)))
4290 (setq gnus-article-current
4291 (cons gnus-newsgroup-name article))
4292 (set-buffer gnus-summary-buffer)
4293 (setq gnus-current-article article)
4294 (if (and (memq article gnus-newsgroup-undownloaded)
4295 (not (gnus-online (gnus-find-method-for-group
4296 gnus-newsgroup-name))))
4298 (gnus-summary-set-agent-mark article)
4299 (message "Message marked for downloading"))
4300 (gnus-summary-mark-article article gnus-canceled-mark)
4301 (unless (memq article gnus-newsgroup-sparse)
4302 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4303 (if (or (eq result 'pseudo)
4304 (eq result 'nneething))
4307 (set-buffer summary-buffer)
4308 (push article gnus-newsgroup-history)
4309 (setq gnus-last-article gnus-current-article
4310 gnus-current-article 0
4311 gnus-current-headers nil
4312 gnus-article-current nil)
4313 (if (eq result 'nneething)
4314 (gnus-configure-windows 'summary)
4315 (gnus-configure-windows 'article))
4316 (gnus-set-global-variables))
4317 (let ((gnus-article-mime-handle-alist-1
4318 gnus-article-mime-handle-alist))
4319 (gnus-set-mode-line 'article)))
4320 ;; The result from the `request' was an actual article -
4321 ;; or at least some text that is now displayed in the
4323 (when (and (numberp article)
4324 (not (eq article gnus-current-article)))
4325 ;; Seems like a new article has been selected.
4326 ;; `gnus-current-article' must be an article number.
4328 (set-buffer summary-buffer)
4329 (push article gnus-newsgroup-history)
4330 (setq gnus-last-article gnus-current-article
4331 gnus-current-article article
4332 gnus-current-headers
4333 (gnus-summary-article-header gnus-current-article)
4334 gnus-article-current
4335 (cons gnus-newsgroup-name gnus-current-article))
4336 (unless (vectorp gnus-current-headers)
4337 (setq gnus-current-headers nil))
4338 (gnus-summary-goto-subject gnus-current-article)
4339 (when (gnus-summary-show-thread)
4340 ;; If the summary buffer really was folded, the
4341 ;; previous goto may not actually have gone to
4342 ;; the right article, but the thread root instead.
4344 (gnus-summary-goto-subject gnus-current-article))
4345 (gnus-run-hooks 'gnus-mark-article-hook)
4346 (gnus-set-mode-line 'summary)
4347 (when (gnus-visual-p 'article-highlight 'highlight)
4348 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4349 ;; Set the global newsgroup variables here.
4350 (gnus-set-global-variables)
4351 (setq gnus-have-all-headers
4352 (or all-headers gnus-show-all-headers))))
4354 (gnus-configure-windows 'article))
4355 (when (or (numberp article)
4357 (gnus-article-prepare-display)
4359 (goto-char (point-min))
4360 (when gnus-break-pages
4361 (gnus-narrow-to-page)))
4362 (let ((gnus-article-mime-handle-alist-1
4363 gnus-article-mime-handle-alist))
4364 (gnus-set-mode-line 'article))
4368 (set-window-point (get-buffer-window (current-buffer)) (point))
4369 (gnus-configure-windows 'article)
4373 (defun gnus-article-prepare-display ()
4374 "Make the current buffer look like a nice article."
4375 ;; Hooks for getting information from the article.
4376 ;; This hook must be called before being narrowed.
4377 (let ((gnus-article-buffer (current-buffer))
4379 (inhibit-read-only t))
4380 (unless (eq major-mode 'gnus-article-mode)
4381 (gnus-article-mode))
4382 (setq buffer-read-only nil
4383 gnus-article-wash-types nil
4384 gnus-article-image-alist nil)
4385 (gnus-run-hooks 'gnus-tmp-internal-hook)
4386 (when gnus-display-mime-function
4387 (funcall gnus-display-mime-function))
4388 (gnus-run-hooks 'gnus-article-prepare-hook)))
4391 ;;; Gnus Sticky Article Mode
4394 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4395 "Mode for sticky articles."
4396 ;; Release bindings that won't work.
4397 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4398 gnus-sticky-article-mode-map)
4399 (substitute-key-definition 'gnus-article-refer-article 'undefined
4400 gnus-sticky-article-mode-map)
4401 (dolist (k '("e" "h" "s" "F" "R"))
4402 (define-key gnus-sticky-article-mode-map k nil))
4403 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4404 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4405 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4406 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4408 (defun gnus-sticky-article (arg)
4409 "Make the current article sticky.
4410 If a prefix ARG is given, ask for a name for this sticky article buffer."
4412 (gnus-summary-show-thread)
4413 (gnus-summary-select-article nil nil 'pseudo)
4414 (let (new-art-buf-name)
4415 (gnus-eval-in-buffer-window gnus-article-buffer
4416 (setq new-art-buf-name
4420 (read-from-minibuffer "Sticky article buffer name: ")
4421 (gnus-with-article-headers
4422 (gnus-article-goto-header "subject")
4423 (setq new-art-buf-name
4424 (buffer-substring-no-properties
4425 (line-beginning-position) (line-end-position)))
4426 (goto-char (point-min))
4427 (gnus-article-goto-header "from")
4428 (setq new-art-buf-name
4430 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 "date")
4435 (setq new-art-buf-name
4437 new-art-buf-name ", "
4438 (buffer-substring-no-properties
4439 (line-beginning-position) (line-end-position))))))
4441 (if (and (gnus-buffer-live-p new-art-buf-name)
4442 (with-current-buffer new-art-buf-name
4443 (eq major-mode 'gnus-sticky-article-mode)))
4444 (switch-to-buffer new-art-buf-name)
4445 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4446 (gnus-sticky-article-mode))
4447 (setq gnus-article-buffer new-art-buf-name))
4448 (gnus-summary-recenter)
4449 (gnus-summary-position-point))
4451 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4452 "Kill the given sticky article BUFFER.
4453 If none is given, assume the current buffer and kill it if it has
4454 `gnus-sticky-article-mode'."
4457 (setq buffer (current-buffer)))
4458 (with-current-buffer buffer
4459 (when (eq major-mode 'gnus-sticky-article-mode)
4460 (gnus-kill-buffer buffer))))
4462 (defun gnus-kill-sticky-article-buffers (arg)
4463 "Kill all sticky article buffers.
4464 If a prefix ARG is given, ask for confirmation."
4466 (dolist (buf (gnus-buffers))
4467 (with-current-buffer buf
4468 (when (eq major-mode 'gnus-sticky-article-mode)
4470 (gnus-kill-buffer buf)
4471 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4472 (gnus-kill-buffer buf)))))))
4475 ;;; Gnus MIME viewing functions
4478 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4479 "Format of the MIME buttons.
4481 Valid specifiers include:
4483 %T MIME type, along with additional info
4484 %n The `name' parameter
4485 %d The description, if any
4486 %l The length of the encoded part
4487 %p The part identifier number
4488 %e Dots if the part isn't displayed
4490 General format specifiers can also be used. See Info node
4491 `(gnus)Formatting Variables'.")
4493 (defvar gnus-mime-button-line-format-alist
4494 '((?t gnus-tmp-type ?s)
4495 (?T gnus-tmp-type-long ?s)
4496 (?n gnus-tmp-name ?s)
4497 (?d gnus-tmp-description ?s)
4499 (?l gnus-tmp-length ?d)
4500 (?e gnus-tmp-dots ?s)))
4502 (defvar gnus-mime-button-commands
4503 '((gnus-article-press-button "\r" "Toggle Display")
4504 (gnus-mime-view-part "v" "View Interactively...")
4505 (gnus-mime-view-part-as-type "t" "View As Type...")
4506 (gnus-mime-view-part-as-charset "C" "View As charset...")
4507 (gnus-mime-save-part "o" "Save...")
4508 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4509 (gnus-mime-replace-part "r" "Replace part")
4510 (gnus-mime-delete-part "d" "Delete part")
4511 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4512 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4513 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4514 (gnus-mime-view-part-externally "e" "View Externally")
4515 (gnus-mime-print-part "p" "Print")
4516 (gnus-mime-pipe-part "|" "Pipe To Command...")
4517 (gnus-mime-action-on-part "." "Take action on the part...")))
4519 (defun gnus-article-mime-part-status ()
4520 (if gnus-article-mime-handle-alist-1
4521 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4523 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4526 (defvar gnus-mime-button-map
4527 (let ((map (make-sparse-keymap)))
4528 (define-key map gnus-mouse-2 'gnus-article-push-button)
4529 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4530 (dolist (c gnus-mime-button-commands)
4531 (define-key map (cadr c) (car c)))
4535 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4537 ,@(mapcar (lambda (c)
4538 (vector (caddr c) (car c) :active t))
4539 gnus-mime-button-commands)))
4541 (defun gnus-mime-button-menu (event prefix)
4542 "Construct a context-sensitive menu of MIME commands."
4543 (interactive "e\nP")
4544 (save-window-excursion
4545 (let ((pos (event-start event)))
4546 (select-window (posn-window pos))
4547 (goto-char (posn-point pos))
4548 (gnus-article-check-buffer)
4549 (popup-menu gnus-mime-button-menu nil prefix))))
4551 (defun gnus-mime-view-all-parts (&optional handles)
4552 "View all the MIME parts."
4554 (with-current-buffer gnus-article-buffer
4555 (let ((handles (or handles gnus-article-mime-handles))
4556 (mail-parse-charset gnus-newsgroup-charset)
4557 (mail-parse-ignored-charsets
4558 (with-current-buffer gnus-summary-buffer
4559 gnus-newsgroup-ignored-charsets)))
4561 (mm-remove-parts handles)
4562 (goto-char (point-min))
4563 (or (search-forward "\n\n") (goto-char (point-max)))
4564 (let ((inhibit-read-only t))
4565 (delete-region (point) (point-max))
4566 (mm-display-parts handles))))))
4568 (defun gnus-article-jump-to-part (n)
4569 "Jump to MIME part N."
4571 (pop-to-buffer gnus-article-buffer)
4572 ;; FIXME: why is it necessary?
4574 (let ((parts (length gnus-article-mime-handle-alist)))
4577 (read-string ;; Emacs 21 doesn't have `read-number'.
4578 (format "Jump to part (2..%s): " parts)))))
4579 (unless (and (integerp n) (<= n parts) (>= n 1))
4582 (gnus-message 7 "Invalid part `%s', using %s instead."
4585 (gnus-message 9 "Jumping to part %s." n)
4586 (cond ((>= gnus-auto-select-part 1)
4587 (while (and (<= n parts)
4588 (not (gnus-article-goto-part n)))
4590 ((< gnus-auto-select-part 0)
4591 (while (and (>= n 1)
4592 (not (gnus-article-goto-part n)))
4595 (gnus-article-goto-part n)))))
4598 (defsubst gnus-article-edit-part (handles &optional current-id)
4599 "Edit an article in order to delete a mime part.
4600 This function is exclusively used by `gnus-mime-save-part-and-strip'
4601 and `gnus-mime-delete-part', and not provided at run-time normally."
4602 (gnus-article-edit-article
4604 (buffer-disable-undo)
4606 (let ((mail-parse-charset (or gnus-article-charset
4607 ',gnus-newsgroup-charset))
4608 (mail-parse-ignored-charsets
4609 (or gnus-article-ignored-charsets
4610 ',gnus-newsgroup-ignored-charsets))
4611 (mbl mml-buffer-list))
4612 (setq mml-buffer-list nil)
4613 (insert-buffer-substring gnus-original-article-buffer)
4614 (mime-to-mml ',handles)
4615 (setq gnus-article-mime-handles nil)
4616 (let ((mbl1 mml-buffer-list))
4617 (setq mml-buffer-list mbl)
4618 (set (make-local-variable 'mml-buffer-list) mbl1))
4619 (gnus-make-local-hook 'kill-buffer-hook)
4620 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4621 `(lambda (no-highlight)
4622 (let ((mail-parse-charset (or gnus-article-charset
4623 ',gnus-newsgroup-charset))
4624 (message-options message-options)
4625 (message-options-set-recipient)
4626 (mail-parse-ignored-charsets
4627 (or gnus-article-ignored-charsets
4628 ',gnus-newsgroup-ignored-charsets)))
4630 (mml-destroy-buffers)
4631 (remove-hook 'kill-buffer-hook
4632 'mml-destroy-buffers t)
4633 (kill-local-variable 'mml-buffer-list))
4634 (gnus-summary-edit-article-done
4635 ,(or (mail-header-references gnus-current-headers) "")
4636 ,(gnus-group-read-only-p)
4637 ,gnus-summary-buffer no-highlight))
4639 (gnus-article-edit-done)
4640 (gnus-summary-expand-window)
4641 (gnus-summary-show-article)
4642 (when (and current-id (integerp gnus-auto-select-part))
4643 (gnus-article-jump-to-part
4644 (if (text-property-any (point-min) (point-max)
4645 'gnus-part (+ current-id gnus-auto-select-part))
4646 (+ current-id gnus-auto-select-part)
4647 (with-current-buffer gnus-article-buffer
4648 (length gnus-article-mime-handle-alist)))))))
4650 (defun gnus-mime-replace-part (file)
4651 "Replace MIME part under point with an external body."
4652 ;; Useful if file has already been saved to disk
4656 (read-file-name "Replace MIME part with file: "
4657 (or mm-default-directory default-directory)
4659 (gnus-mime-save-part-and-strip file))
4661 (defun gnus-mime-save-part-and-strip (&optional file)
4662 "Save the MIME part under point then replace it with an external body.
4663 If FILE is given, use it for the external part."
4665 (gnus-article-check-buffer)
4666 (when (gnus-group-read-only-p)
4667 (error "The current group does not support deleting of parts"))
4668 (when (mm-complicated-handles gnus-article-mime-handles)
4670 The current article has a complicated MIME structure, giving up..."))
4671 (let* ((data (get-text-property (point) 'gnus-data))
4672 (id (get-text-property (point) 'gnus-part))
4674 (handles gnus-article-mime-handles))
4677 (and data (mm-save-part data "Delete MIME part and save to: "))))
4679 (with-current-buffer (mm-handle-buffer data)
4681 (insert "Content-Type: " (mm-handle-media-type data))
4682 (mml-insert-parameter-string (cdr (mm-handle-type data))
4684 ;; Add a filename for the sake of saving the part again.
4685 (mml-insert-parameter
4686 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4688 (insert "Content-ID: " (message-make-message-id) "\n")
4689 (insert "Content-Transfer-Encoding: binary\n")
4692 (cdr (mm-make-handle nil
4693 `("message/external-body"
4694 (access-type . "LOCAL-FILE")
4696 ;; (set-buffer gnus-summary-buffer)
4697 (gnus-article-edit-part handles id))))
4699 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4700 ;; parts...>') but with stripping would be nice.
4702 (defun gnus-mime-delete-part ()
4703 "Delete the MIME part under point.
4704 Replace it with some information about the removed part."
4706 (gnus-article-check-buffer)
4707 (when (gnus-group-read-only-p)
4708 (error "The current group does not support deleting of parts"))
4709 (when (mm-complicated-handles gnus-article-mime-handles)
4711 The current article has a complicated MIME structure, giving up..."))
4712 (when (or gnus-expert-user
4713 (gnus-yes-or-no-p "\
4714 Deleting parts may malfunction or destroy the article; continue? "))
4715 (let* ((data (get-text-property (point) 'gnus-data))
4716 (id (get-text-property (point) 'gnus-part))
4717 (handles gnus-article-mime-handles)
4720 (mail-decode-encoded-word-string (or (mm-handle-description data)
4723 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4725 (type (mm-handle-media-type data)))
4727 (error "No MIME part under point"))
4728 (with-current-buffer (mm-handle-buffer data)
4729 (let ((bsize (format "%s" (buffer-size))))
4734 "| The following attachment has been deleted:\n"
4736 "| Type: " type "\n"
4737 "| Filename: " filename "\n"
4738 "| Size (encoded): " bsize " Byte\n"
4739 "| Description: " description "\n"
4742 (cdr (mm-make-handle
4743 nil `("text/plain") nil nil
4745 (format "Deleted attachment (%s bytes)" bsize))))))
4746 ;; (set-buffer gnus-summary-buffer)
4747 (gnus-article-edit-part handles id))))
4749 (defun gnus-mime-save-part ()
4750 "Save the MIME part under point."
4752 (gnus-article-check-buffer)
4753 (let ((data (get-text-property (point) 'gnus-data)))
4755 (mm-save-part data))))
4757 (defun gnus-mime-pipe-part ()
4758 "Pipe the MIME part under point to a process."
4760 (gnus-article-check-buffer)
4761 (let ((data (get-text-property (point) 'gnus-data)))
4763 (mm-pipe-part data))))
4765 (defun gnus-mime-view-part ()
4766 "Interactively choose a viewing method for the MIME part under point."
4768 (gnus-article-check-buffer)
4769 (let ((data (get-text-property (point) 'gnus-data)))
4771 (setq gnus-article-mime-handles
4773 gnus-article-mime-handles (setq data (copy-sequence data))))
4774 (mm-interactively-view-part data))))
4776 (defun gnus-mime-view-part-as-type-internal ()
4777 (gnus-article-check-buffer)
4778 (let* ((handle (get-text-property (point) 'gnus-data))
4780 ;; Content-Type: foo/bar; name=...
4781 (mail-content-type-get (mm-handle-type handle) 'name)
4782 ;; Content-Disposition: attachment; filename=...
4783 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4784 (def-type (and name (mm-default-file-encoding name))))
4785 (or (and def-type (cons def-type 0))
4787 (equal (mm-handle-media-supertype handle) "text")
4788 '("text/plain" . 0))
4789 '("application/octet-stream" . 0))))
4791 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4792 "Choose a MIME media type, and view the part as such.
4793 If non-nil, PRED is a predicate to use during completion to limit the
4794 available media-types."
4798 (let ((default (gnus-mime-view-part-as-type-internal)))
4800 (format "View as MIME type (default %s): "
4802 (mapcar #'list (mailcap-mime-types))
4805 (gnus-article-check-buffer)
4806 (let ((handle (get-text-property (point) 'gnus-data)))
4808 (when (equal (mm-handle-media-type handle) "message/external-body")
4809 (unless (mm-handle-cache handle)
4810 (mm-extern-cache-contents handle))
4811 (setq handle (mm-handle-cache handle)))
4813 (mm-make-handle (mm-handle-buffer handle)
4814 (cons mime-type (cdr (mm-handle-type handle)))
4815 (mm-handle-encoding handle)
4816 (mm-handle-undisplayer handle)
4817 (mm-handle-disposition handle)
4818 (mm-handle-description handle)
4820 (mm-handle-id handle)))
4821 (setq gnus-article-mime-handles
4822 (mm-merge-handles gnus-article-mime-handles handle))
4823 (when (mm-handle-displayed-p handle)
4824 (mm-remove-part handle))
4825 (gnus-mm-display-part handle))))
4827 (defun gnus-mime-copy-part (&optional handle arg)
4828 "Put the MIME part under point into a new buffer.
4829 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4831 (interactive (list nil current-prefix-arg))
4832 (gnus-article-check-buffer)
4834 (setq handle (get-text-property (point) 'gnus-data)))
4836 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4838 (mail-content-type-get (mm-handle-disposition handle)
4840 contents dont-decode charset coding-system)
4841 (mm-with-unibyte-buffer
4842 (mm-insert-part handle)
4843 (setq contents (or (condition-case nil
4844 (mm-decompress-buffer filename nil 'sig)
4846 (setq dont-decode t)
4849 (setq filename (cond (filename (file-name-nondirectory filename))
4850 (dont-decode "*raw data*")
4855 (unless (setq charset (mail-content-type-get
4856 (mm-handle-type handle) 'charset))
4857 (unless (setq coding-system (mm-with-unibyte-buffer
4859 (mm-find-buffer-file-coding-system)))
4860 (setq charset gnus-newsgroup-charset))))
4862 (setq charset (or (cdr (assq arg
4863 gnus-summary-show-article-charset-alist))
4864 (mm-read-coding-system "Charset: ")))))
4865 (switch-to-buffer (generate-new-buffer filename))
4866 (if (or coding-system
4868 (setq coding-system (mm-charset-to-coding-system charset))
4869 (not (eq charset 'ascii))))
4871 (mm-enable-multibyte)
4872 (insert (mm-decode-coding-string contents coding-system))
4873 (setq buffer-file-coding-system
4874 (if (boundp 'last-coding-system-used)
4875 (symbol-value 'last-coding-system-used)
4877 (mm-disable-multibyte)
4879 (setq buffer-file-coding-system mm-binary-coding-system))
4880 ;; We do it this way to make `normal-mode' set the appropriate mode.
4883 (setq buffer-file-name (expand-file-name filename))
4885 (setq buffer-file-name nil))
4886 (goto-char (point-min)))))
4888 (defun gnus-mime-print-part (&optional handle filename)
4889 "Print the MIME part under point."
4890 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4891 (gnus-article-check-buffer)
4892 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4893 (contents (and handle (mm-get-part handle)))
4894 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4895 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4900 (mm-save-part-to-file handle file)
4901 (call-process shell-file-name nil
4902 (generate-new-buffer " *mm*")
4904 shell-command-switch
4906 printer file (mm-handle-type handle))))
4910 (gnus-print-buffer))
4911 (ps-despool filename)))))
4913 (defun gnus-mime-inline-part (&optional handle arg)
4914 "Insert the MIME part under point into the current buffer.
4915 Compressed files like .gz and .bz2 are decompressed."
4916 (interactive (list nil current-prefix-arg))
4917 (gnus-article-check-buffer)
4919 (setq handle (get-text-property (point) 'gnus-data)))
4922 (inhibit-read-only t)
4923 contents charset coding-system)
4924 (if (and (not arg) (mm-handle-undisplayer handle))
4925 (mm-remove-part handle)
4926 (mm-with-unibyte-buffer
4927 (mm-insert-part handle)
4929 (or (mm-decompress-buffer
4930 (or (mail-content-type-get (mm-handle-type handle)
4932 (mail-content-type-get (mm-handle-disposition handle)
4938 (unless (setq charset (mail-content-type-get
4939 (mm-handle-type handle) 'charset))
4940 (unless (setq coding-system
4941 (mm-with-unibyte-buffer
4943 (mm-find-buffer-file-coding-system)))
4944 (setq charset gnus-newsgroup-charset))))
4946 (if (mm-handle-undisplayer handle)
4947 (mm-remove-part handle))
4950 gnus-summary-show-article-charset-alist))
4951 (mm-read-coding-system "Charset: "))))
4953 (if (mm-handle-undisplayer handle)
4954 (mm-remove-part handle))))
4958 (if (or coding-system
4961 (mm-charset-to-coding-system charset))
4962 (not (eq coding-system 'ascii))))
4963 (mm-decode-coding-string contents coding-system)
4964 (mm-string-to-multibyte contents)))
4967 (defun gnus-mime-strip-charset-parameters (handle)
4968 "Strip charset parameters from HANDLE."
4969 (if (stringp (car handle))
4970 (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
4971 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
4972 "message/external-body")
4974 (unless (mm-handle-cache handle)
4975 (mm-extern-cache-contents handle))
4976 (mm-handle-cache handle))
4978 (charset (assq 'charset (cdr type))))
4980 (delq charset type)))))
4982 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4983 "Insert the MIME part under point into the current buffer using the
4985 (interactive (list nil current-prefix-arg))
4986 (gnus-article-check-buffer)
4987 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4988 (fun (get-text-property (point) 'gnus-callback))
4989 (gnus-newsgroup-ignored-charsets 'gnus-all)
4990 gnus-newsgroup-charset form preferred parts)
4994 (setq gnus-newsgroup-charset
4997 gnus-summary-show-article-charset-alist))
4998 (mm-read-coding-system "Charset: "))))
4999 (if (mm-handle-undisplayer handle)
5000 (mm-remove-part handle)))
5001 (gnus-mime-strip-charset-parameters handle)
5002 (when (and (consp (setq form (cdr-safe fun)))
5003 (setq form (ignore-errors
5004 (assq 'gnus-mime-display-alternative form)))
5005 (setq preferred (caddr form))
5007 (when (eq (car preferred) 'quote)
5008 (setq preferred (cadr preferred)))
5009 (not (equal preferred
5010 (get-text-property (point) 'gnus-data))))
5011 (setq parts (get-text-property (point) 'gnus-part))
5012 (setq parts (cdr (assq parts
5013 gnus-article-mime-handle-alist)))
5014 (equal (mm-handle-media-type parts) "multipart/alternative")
5015 (setq parts (reverse (cdr parts))))
5017 (list 'quote (or (cadr (member preferred parts))
5019 (funcall fun handle)))))
5021 (defun gnus-mime-view-part-externally (&optional handle)
5022 "View the MIME part under point with an external viewer."
5024 (gnus-article-check-buffer)
5025 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5026 (mm-user-display-methods nil)
5027 (mm-inlined-types nil)
5028 (mail-parse-charset gnus-newsgroup-charset)
5029 (mail-parse-ignored-charsets
5030 (with-current-buffer gnus-summary-buffer
5031 gnus-newsgroup-ignored-charsets))
5032 (type (mm-handle-media-type handle))
5033 (method (mailcap-mime-info type))
5034 (mm-enable-external t))
5035 (if (not (stringp method))
5036 (gnus-mime-view-part-as-type
5037 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
5039 (if (mm-handle-undisplayer handle)
5040 (mm-remove-part handle)
5041 (mm-display-part handle))))))
5043 (defun gnus-mime-view-part-internally (&optional handle)
5044 "View the MIME part under point with an internal viewer.
5045 If no internal viewer is available, use an external viewer."
5047 (gnus-article-check-buffer)
5048 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5049 (mm-inlined-types '(".*"))
5050 (mm-inline-large-images t)
5051 (mail-parse-charset gnus-newsgroup-charset)
5052 (mail-parse-ignored-charsets
5053 (with-current-buffer gnus-summary-buffer
5054 gnus-newsgroup-ignored-charsets))
5055 (inhibit-read-only t))
5056 (if (not (mm-inlinable-p handle))
5057 (gnus-mime-view-part-as-type
5058 nil (lambda (types) (mm-inlinable-p handle (car types))))
5060 (if (mm-handle-undisplayer handle)
5061 (mm-remove-part handle)
5062 (mm-display-part handle))))))
5064 (defun gnus-mime-action-on-part (&optional action)
5065 "Do something with the MIME attachment at \(point\)."
5067 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
5068 (gnus-article-check-buffer)
5069 (let ((action-pair (assoc action gnus-mime-action-alist)))
5071 (funcall (cdr action-pair)))))
5073 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5074 "Call FUNCTION on MIME part N.
5075 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5076 If INTERACTIVE, call FUNCTION interactivly."
5078 ;; Check whether the article is displayed.
5079 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5080 (setq window (get-buffer-window gnus-article-buffer t))
5081 (frame-visible-p (setq frame (window-frame window))))
5082 (error "No article is displayed"))
5083 (with-current-buffer gnus-article-buffer
5084 ;; Check whether the article displays the right contents.
5085 (unless (with-current-buffer gnus-summary-buffer
5086 (eq gnus-current-article (gnus-summary-article-number)))
5087 (error "You should select the right article first"))
5089 (setq n (prefix-numeric-value n))
5091 (setq n (or (get-text-property pt 'gnus-part)
5093 (get-text-property (1- pt) 'gnus-part))
5094 (get-text-property (prog2
5100 (or (and (setq pt (previous-single-property-change
5103 (next-single-property-change (point) 'gnus-part)
5107 ;; Check whether the specified part exists.
5108 (when (> n (length gnus-article-mime-handle-alist))
5109 (error "No such part")))
5112 ;; To select the window is needed so that the cursor
5113 ;; might be visible on the MIME button.
5114 (select-window (prog1
5116 (setq window (selected-window))
5117 ;; Article may be displayed in the other frame.
5118 (gnus-select-frame-set-input-focus
5121 (setq frame (selected-frame))))))
5122 (when (gnus-article-goto-part n)
5123 ;; We point the cursor and the arrow at the MIME button
5124 ;; when the `function' prompt the user for something.
5125 (let ((cursor-in-non-selected-windows t)
5126 (overlay-arrow-string "=>")
5127 (overlay-arrow-position (point-marker)))
5130 ((and no-handle interactive)
5131 (call-interactively function))
5137 (cdr (assq n gnus-article-mime-handle-alist))))
5140 (cdr (assq n gnus-article-mime-handle-alist)))))
5141 (set-marker overlay-arrow-position nil)
5142 (unless gnus-auto-select-part
5143 (gnus-select-frame-set-input-focus frame)
5144 (select-window window))))
5146 (if gnus-inhibit-mime-unbuttonizing
5147 ;; This is the default though the program shouldn't reach here.
5148 (error "No such part")
5149 ;; The part which doesn't have the MIME button is selected.
5150 ;; So, we display all the buttons and redo it.
5151 (let ((gnus-inhibit-mime-unbuttonizing t))
5152 (gnus-summary-show-article)
5153 (gnus-article-part-wrapper n function no-handle))))))
5155 (defun gnus-article-pipe-part (n)
5156 "Pipe MIME part N, which is the numerical prefix."
5158 (gnus-article-part-wrapper n 'mm-pipe-part))
5160 (defun gnus-article-save-part (n)
5161 "Save MIME part N, which is the numerical prefix."
5163 (gnus-article-part-wrapper n 'mm-save-part))
5165 (defun gnus-article-interactively-view-part (n)
5166 "View MIME part N interactively, which is the numerical prefix."
5168 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5170 (defun gnus-article-copy-part (n)
5171 "Copy MIME part N, which is the numerical prefix."
5173 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5175 (defun gnus-article-view-part-as-charset (n)
5176 "View MIME part N using a specified charset.
5177 N is the numerical prefix."
5179 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5181 (defun gnus-article-view-part-externally (n)
5182 "View MIME part N externally, which is the numerical prefix."
5184 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5186 (defun gnus-article-inline-part (n)
5187 "Inline MIME part N, which is the numerical prefix."
5189 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5191 (defun gnus-article-save-part-and-strip (n)
5192 "Save MIME part N and replace it with an external body.
5193 N is the numerical prefix."
5195 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5197 (defun gnus-article-replace-part (n)
5198 "Replace MIME part N with an external body.
5199 N is the numerical prefix."
5201 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5203 (defun gnus-article-delete-part (n)
5204 "Delete MIME part N and add some information about the removed part.
5205 N is the numerical prefix."
5207 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5209 (defun gnus-article-view-part-as-type (n)
5210 "Choose a MIME media type, and view part N as such.
5211 N is the numerical prefix."
5213 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5215 (defun gnus-article-mime-match-handle-first (condition)
5218 (dolist (ihandle gnus-article-mime-handle-alist)
5220 ((functionp condition)
5221 (funcall condition (cdr ihandle)))
5222 ((eq condition 'undisplayed)
5223 (not (or (mm-handle-undisplayer (cdr ihandle))
5224 (equal (mm-handle-media-type (cdr ihandle))
5225 "multipart/alternative"))))
5226 ((eq condition 'undisplayed-alternative)
5227 (not (mm-handle-undisplayer (cdr ihandle))))
5229 (gnus-article-goto-part (car ihandle))
5230 (or (not n) (< (car ihandle) n)))
5231 (setq n (car ihandle))))
5235 (defun gnus-article-view-part (&optional n)
5236 "View MIME part N, which is the numerical prefix."
5238 (with-current-buffer gnus-article-buffer
5239 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5240 gnus-article-mime-match-handle-function)))
5241 (when (> n (length gnus-article-mime-handle-alist))
5242 (error "No such part"))
5243 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5244 (when (gnus-article-goto-part n)
5245 (if (equal (car handle) "multipart/alternative")
5246 (gnus-article-press-button)
5247 (when (eq (gnus-mm-display-part handle) 'internal)
5248 (gnus-set-window-start)))))))
5250 (defsubst gnus-article-mime-total-parts ()
5251 (if (bufferp (car gnus-article-mime-handles))
5253 (1- (length gnus-article-mime-handles))))
5255 (defun gnus-mm-display-part (handle)
5256 "Display HANDLE and fix MIME button."
5257 (let ((id (get-text-property (point) 'gnus-part))
5259 (inhibit-read-only t))
5262 (let ((window (selected-window))
5263 (mail-parse-charset gnus-newsgroup-charset)
5264 (mail-parse-ignored-charsets
5265 (if (gnus-buffer-live-p gnus-summary-buffer)
5266 (with-current-buffer gnus-summary-buffer
5267 gnus-newsgroup-ignored-charsets)
5271 (let ((win (gnus-get-buffer-window (current-buffer) t))
5274 (select-window win))
5277 (if (mm-handle-displayed-p handle)
5278 ;; This will remove the part.
5279 (mm-display-part handle)
5281 (narrow-to-region (point)
5282 (if (eobp) (point) (1+ (point))))
5283 (mm-display-part handle)
5284 ;; We narrow to the part itself and
5285 ;; then call the treatment functions.
5286 (goto-char (point-min))
5288 (narrow-to-region (point) (point-max))
5291 (gnus-article-mime-total-parts)
5292 (mm-handle-media-type handle)))))
5293 (if (window-live-p window)
5294 (select-window window)))))
5297 (gnus-insert-mime-button
5298 handle id (list (mm-handle-displayed-p handle)))
5299 (goto-char point))))
5301 (defun gnus-article-goto-part (n)
5302 "Go to MIME part N."
5303 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5305 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5306 (let ((gnus-tmp-name
5307 (or (mail-content-type-get (mm-handle-type handle) 'name)
5308 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5309 (mail-content-type-get (mm-handle-type handle) 'url)
5311 (gnus-tmp-type (mm-handle-media-type handle))
5312 (gnus-tmp-description
5313 (mail-decode-encoded-word-string (or (mm-handle-description handle)
5316 (if (if displayed (car displayed)
5317 (mm-handle-displayed-p handle))
5319 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5321 gnus-tmp-type-long b e)
5322 (when (string-match ".*/" gnus-tmp-name)
5323 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5324 (setq gnus-tmp-type-long (concat gnus-tmp-type
5325 (and (not (equal gnus-tmp-name ""))
5326 (concat "; " gnus-tmp-name))))
5327 (unless (equal gnus-tmp-description "")
5328 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5333 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5334 `(keymap ,gnus-mime-button-map
5335 gnus-callback gnus-mm-display-part
5336 gnus-part ,gnus-tmp-id
5337 article-type annotation
5340 ;; Exclude a newline.
5343 (when gnus-article-button-face
5344 (gnus-overlay-put (gnus-make-overlay b e nil t)
5345 'face gnus-article-button-face))
5346 (widget-convert-button
5349 :action 'gnus-widget-press-button
5350 :button-keymap gnus-mime-button-map
5352 (lambda (widget/window &optional overlay pos)
5353 ;; Needed to properly clear the message due to a bug in
5354 ;; wid-edit (XEmacs only).
5355 (if (boundp 'help-echo-owns-message)
5356 (setq help-echo-owns-message t))
5358 "%S: %s the MIME part; %S: more options"
5359 (aref gnus-mouse-2 0)
5360 ;; XEmacs will get a single widget arg; Emacs 21 will get
5361 ;; window, overlay, position.
5362 (if (mm-handle-displayed-p
5364 (with-current-buffer (gnus-overlay-buffer overlay)
5365 (widget-get (widget-at (gnus-overlay-start overlay))
5367 (widget-get widget/window :mime-handle)))
5369 (aref gnus-down-mouse-3 0))))))
5371 (defun gnus-widget-press-button (elems el)
5372 (goto-char (widget-get elems :from))
5373 (gnus-article-press-button))
5375 (defvar gnus-displaying-mime nil)
5377 (defun gnus-display-mime (&optional ihandles)
5378 "Display the MIME parts."
5380 (save-selected-window
5381 (let ((window (get-buffer-window gnus-article-buffer))
5384 (select-window window)
5385 ;; We have to do this since selecting the window
5386 ;; may change the point. So we set the window point.
5387 (set-window-point window point)))
5388 (let ((handles ihandles)
5389 (inhibit-read-only t)
5392 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5393 (when gnus-article-emulate-mime
5394 (mm-uu-dissect-text-parts handles)))
5395 (gnus-article-emulate-mime
5396 (setq handles (mm-uu-dissect))))
5397 (when (and (not ihandles)
5398 (not gnus-displaying-mime))
5399 ;; Top-level call; we clean up.
5400 (when gnus-article-mime-handles
5401 (mm-destroy-parts gnus-article-mime-handles)
5402 (setq gnus-article-mime-handle-alist nil));; A trick.
5403 (setq gnus-article-mime-handles handles)
5404 ;; We allow users to glean info from the handles.
5405 (when gnus-article-mime-part-function
5406 (gnus-mime-part-function handles)))
5408 (or (not (stringp (car handles)))
5411 (when (and (not ihandles)
5412 (not gnus-displaying-mime))
5413 ;; Clean up for mime parts.
5415 (delete-region (point) (point-max)))
5416 (let ((gnus-displaying-mime t))
5417 (gnus-mime-display-part handles)))
5420 (narrow-to-region (point) (point-max))
5421 (gnus-treat-article nil 1 1)
5424 ;; Highlight the headers.
5428 (narrow-to-region (point-min) (point))
5429 (gnus-article-save-original-date
5430 (gnus-treat-article 'head)))))))
5431 ;; Cope with broken MIME messages.
5432 (goto-char (point-max))
5436 (defcustom gnus-mime-display-multipart-as-mixed nil
5437 "Display \"multipart\" parts as \"multipart/mixed\".
5439 If t, it overrides nil values of
5440 `gnus-mime-display-multipart-alternative-as-mixed' and
5441 `gnus-mime-display-multipart-related-as-mixed'."
5442 :group 'gnus-article-mime
5445 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5446 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5448 :group 'gnus-article-mime
5451 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5452 "Display \"multipart/related\" parts as \"multipart/mixed\".
5454 If displaying \"text/html\" is discouraged \(see
5455 `mm-discouraged-alternatives'\) images or other material inside a
5456 \"multipart/related\" part might be overlooked when this variable is nil."
5458 :group 'gnus-article-mime
5461 (defun gnus-mime-display-part (handle)
5463 ;; Maybe a broken MIME message.
5466 ((not (stringp (car handle)))
5467 (gnus-mime-display-single handle))
5468 ;; User-defined multipart
5469 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5470 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5472 ;; multipart/alternative
5473 ((and (equal (car handle) "multipart/alternative")
5474 (not (or gnus-mime-display-multipart-as-mixed
5475 gnus-mime-display-multipart-alternative-as-mixed)))
5476 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5477 (push (cons id handle) gnus-article-mime-handle-alist)
5478 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5479 ;; multipart/related
5480 ((and (equal (car handle) "multipart/related")
5481 (not (or gnus-mime-display-multipart-as-mixed
5482 gnus-mime-display-multipart-related-as-mixed)))
5483 ;;;!!!We should find the start part, but we just default
5484 ;;;!!!to the first part.
5485 ;;(gnus-mime-display-part (cadr handle))
5486 ;;;!!! Most multipart/related is an HTML message plus images.
5487 ;;;!!! Unfortunately we are unable to let W3 display those
5488 ;;;!!! included images, so we just display it as a mixed multipart.
5489 ;;(gnus-mime-display-mixed (cdr handle))
5490 ;;;!!! No, w3 can display everything just fine.
5491 (gnus-mime-display-part (cadr handle)))
5492 ((equal (car handle) "multipart/signed")
5493 (gnus-add-wash-type 'signed)
5494 (gnus-mime-display-security handle))
5495 ((equal (car handle) "multipart/encrypted")
5496 (gnus-add-wash-type 'encrypted)
5497 (gnus-mime-display-security handle))
5498 ;; Other multiparts are handled like multipart/mixed.
5500 (gnus-mime-display-mixed (cdr handle)))))
5502 (defun gnus-mime-part-function (handles)
5503 (if (stringp (car handles))
5504 (mapcar 'gnus-mime-part-function (cdr handles))
5505 (funcall gnus-article-mime-part-function handles)))
5507 (defun gnus-mime-display-mixed (handles)
5508 (mapcar 'gnus-mime-display-part handles))
5510 (defun gnus-mime-display-single (handle)
5511 (let ((type (mm-handle-media-type handle))
5512 (ignored gnus-ignored-mime-types)
5519 (when (string-match (pop ignored) type)
5520 (throw 'ignored nil)))
5521 (if (and (setq not-attachment
5522 (and (not (mm-inline-override-p handle))
5523 (or (not (mm-handle-disposition handle))
5524 (equal (car (mm-handle-disposition handle))
5526 (mm-attachment-override-p handle))))
5527 (mm-automatic-display-p handle)
5529 (mm-inlinable-p handle)
5530 (mm-inlined-p handle))
5531 (mm-automatic-external-display-p type)))
5533 (when (equal (mm-handle-media-supertype handle) "text")
5535 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5537 (push (cons id handle) gnus-article-mime-handle-alist)
5539 (equal (mm-handle-media-supertype handle) "message"))
5542 (cond ((not (bolp)) 2)
5543 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5545 (when (or (not display)
5546 (not (gnus-unbuttonized-mime-type-p type)))
5547 (gnus-insert-mime-button
5548 handle id (list (or display (and not-attachment text))))
5549 (gnus-article-insert-newline)
5550 ;; Remember modify the number of forward lines.
5558 (let ((mail-parse-charset gnus-newsgroup-charset)
5559 (mail-parse-ignored-charsets
5560 (save-excursion (condition-case ()
5561 (set-buffer gnus-summary-buffer)
5563 gnus-newsgroup-ignored-charsets)))
5564 (mm-display-part handle t))
5565 (goto-char (point-max)))
5566 ((and text not-attachment)
5570 (gnus-article-insert-newline)
5573 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5575 (and (equal type "text/calendar") 'utf-8))))
5576 (cond ((not charset)
5577 (mm-string-as-multibyte (mm-get-part handle)))
5578 ((eq charset 'gnus-decoded)
5579 (with-current-buffer (mm-handle-buffer handle)
5582 (mm-decode-string (mm-get-part handle) charset)))))
5583 (goto-char (point-max))))
5587 (narrow-to-region beg (point))
5588 (if (eq handle gnus-article-mime-handles)
5589 ;; The format=flowed case.
5590 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5591 ;; Don't count signature parts that are never displayed.
5592 ;; The part number should be re-calculated supposing this
5593 ;; might be a message/rfc822 part.
5595 (dolist (part gnus-article-mime-handles)
5596 (unless (or (stringp part)
5597 (equal (car (mm-handle-type part))
5598 "application/pgp-signature"))
5599 (push part handles)))
5601 nil (length (memq handle handles)) (length handles)
5602 (mm-handle-media-type handle)))))))))))
5604 (defun gnus-unbuttonized-mime-type-p (type)
5605 "Say whether TYPE is to be unbuttonized."
5606 (unless gnus-inhibit-mime-unbuttonizing
5608 (let ((types gnus-unbuttonized-mime-types))
5610 (when (string-match (pop types) type)
5611 (throw 'found t)))))
5613 (let ((types gnus-buttonized-mime-types))
5615 (when (string-match (pop types) type)
5616 (throw 'found t)))))))))
5618 (defun gnus-article-insert-newline ()
5619 "Insert a newline, but mark it as undeletable."
5620 (gnus-put-text-property
5621 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5623 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5624 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5627 handle (inhibit-read-only t) from props begend not-pref)
5628 (save-window-excursion
5631 (narrow-to-region (car ibegend)
5634 (goto-char (car ibegend))
5637 (delete-region (point-min) (point-max))
5638 (mm-remove-parts handles))
5639 (setq begend (list (point-marker)))
5641 (unless (setq not-pref (cadr (member preferred ihandles)))
5642 (setq not-pref (car ihandles)))
5645 (not (gnus-unbuttonized-mime-type-p
5646 "multipart/alternative")))
5647 (gnus-add-text-properties
5650 (insert (format "%d. " id))
5654 (unless ,(not ibegend)
5655 (setq gnus-article-mime-handle-alist
5656 ',gnus-article-mime-handle-alist))
5657 (gnus-mime-display-alternative
5658 ',ihandles ',not-pref ',begend ,id))
5659 keymap ,gnus-mime-button-map
5660 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5661 face ,gnus-article-button-face
5663 article-type multipart))
5664 (widget-convert-button 'link from (point)
5665 :action 'gnus-widget-press-button
5666 :button-keymap gnus-widget-button-keymap)
5668 (while (setq handle (pop handles))
5669 (gnus-add-text-properties
5672 (insert (format "(%c) %-18s"
5673 (if (equal handle preferred) ?* ? )
5674 (mm-handle-media-type handle)))
5678 (unless ,(not ibegend)
5679 (setq gnus-article-mime-handle-alist
5680 ',gnus-article-mime-handle-alist))
5681 (gnus-mime-display-alternative
5682 ',ihandles ',handle ',begend ,id))
5683 keymap ,gnus-mime-button-map
5684 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5685 face ,gnus-article-button-face
5688 (widget-convert-button 'link from (point)
5689 :action 'gnus-widget-press-button
5690 :button-keymap gnus-widget-button-keymap)
5694 (if (stringp (car preferred))
5695 (gnus-display-mime preferred)
5696 (let ((mail-parse-charset gnus-newsgroup-charset)
5697 (mail-parse-ignored-charsets
5698 (with-current-buffer gnus-summary-buffer
5699 gnus-newsgroup-ignored-charsets)))
5700 (mm-display-part preferred)
5704 (narrow-to-region (car begend) (point-max))
5706 nil (length gnus-article-mime-handle-alist)
5707 (gnus-article-mime-total-parts)
5708 (mm-handle-media-type handle))))))
5709 (goto-char (point-max))
5710 (setcdr begend (point-marker)))))
5712 (goto-char point))))
5714 (defconst gnus-article-wash-status-strings
5715 (let ((alist '((cite "c" "Possible hidden citation text"
5716 " " "All citation text visible")
5717 (headers "h" "Hidden headers"
5718 " " "All headers visible.")
5719 (pgp "p" "Encrypted or signed message status hidden"
5720 " " "No hidden encryption nor digital signature status")
5721 (signature "s" "Signature has been hidden"
5722 " " "Signature is visible")
5723 (overstrike "o" "Overstrike (^H) characters applied"
5724 " " "No overstrike characters applied")
5725 (emphasis "e" "/*_Emphasis_*/ characters applied"
5726 " " "No /*_emphasis_*/ characters applied")))
5728 (dolist (entry alist result)
5729 (let ((key (nth 0 entry))
5730 (on (copy-sequence (nth 1 entry)))
5731 (on-help (nth 2 entry))
5732 (off (copy-sequence (nth 3 entry)))
5733 (off-help (nth 4 entry)))
5734 (put-text-property 0 1 'help-echo on-help on)
5735 (put-text-property 0 1 'help-echo off-help off)
5736 (push (list key on off) result))))
5737 "Alist of strings describing wash status in the mode line.
5738 Each entry has the form (KEY ON OF), where the KEY is a symbol
5739 representing the particular washing function, ON is the string to use
5740 in the article mode line when the washing function is active, and OFF
5741 is the string to use when it is inactive.")
5743 (defun gnus-article-wash-status-entry (key value)
5744 (let ((entry (assoc key gnus-article-wash-status-strings)))
5745 (if value (nth 1 entry) (nth 2 entry))))
5747 (defun gnus-article-wash-status ()
5748 "Return a string which display status of article washing."
5749 (with-current-buffer gnus-article-buffer
5750 (let ((cite (memq 'cite gnus-article-wash-types))
5751 (headers (memq 'headers gnus-article-wash-types))
5752 (boring (memq 'boring-headers gnus-article-wash-types))
5753 (pgp (memq 'pgp gnus-article-wash-types))
5754 (pem (memq 'pem gnus-article-wash-types))
5755 (signed (memq 'signed gnus-article-wash-types))
5756 (encrypted (memq 'encrypted gnus-article-wash-types))
5757 (signature (memq 'signature gnus-article-wash-types))
5758 (overstrike (memq 'overstrike gnus-article-wash-types))
5759 (emphasis (memq 'emphasis gnus-article-wash-types)))
5761 (gnus-article-wash-status-entry 'cite cite)
5762 (gnus-article-wash-status-entry 'headers (or headers boring))
5763 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5764 (gnus-article-wash-status-entry 'signature signature)
5765 (gnus-article-wash-status-entry 'overstrike overstrike)
5766 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5768 (defun gnus-add-wash-type (type)
5769 "Add a washing of TYPE to the current status."
5770 (add-to-list 'gnus-article-wash-types type))
5772 (defun gnus-delete-wash-type (type)
5773 "Add a washing of TYPE to the current status."
5774 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5776 (defun gnus-add-image (category image)
5777 "Add IMAGE of CATEGORY to the list of displayed images."
5778 (let ((entry (assq category gnus-article-image-alist)))
5780 (setq entry (list category))
5781 (push entry gnus-article-image-alist))
5782 (nconc entry (list image))))
5784 (defun gnus-delete-images (category)
5785 "Delete all images in CATEGORY."
5786 (let ((entry (assq category gnus-article-image-alist)))
5787 (dolist (image (cdr entry))
5788 (gnus-remove-image image category))
5789 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5790 (gnus-delete-wash-type category)))
5792 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5794 (defun gnus-article-maybe-hide-headers ()
5795 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5796 Provided for backwards compatibility."
5797 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5798 (not (with-current-buffer gnus-summary-buffer
5799 gnus-have-all-headers)))
5800 (not gnus-inhibit-hiding))
5801 (gnus-article-hide-headers)))
5805 (defun gnus-output-to-file (file-name)
5806 "Append the current article to a file named FILE-NAME.
5807 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5808 text and used as the value of the coding cookie which is added to the
5809 top of a file. Otherwise, this function saves a raw article without
5811 (let* ((artbuf (current-buffer))
5812 (file-name-coding-system nnmail-pathname-coding-system)
5813 (coding gnus-article-save-coding-system)
5814 (coding-system-for-read (if coding
5815 nil ;; Rely on the coding cookie.
5816 mm-text-coding-system))
5817 (coding-system-for-write (or coding
5818 mm-text-coding-system-for-write
5819 mm-text-coding-system))
5820 (exists (file-exists-p file-name)))
5823 (insert-file-contents file-name)
5824 (goto-char (point-min))
5825 ;; Remove the existing coding cookie.
5826 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5827 (delete-region (match-beginning 0) (match-end 0))))
5828 (goto-char (point-max))
5829 (insert-buffer-substring artbuf)
5830 ;; Append newline at end of the buffer as separator, and then
5832 (goto-char (point-max))
5835 ;; If the coding system is not suitable to encode the text,
5836 ;; ask a user for a proper one.
5837 (when (fboundp 'select-safe-coding-system)
5838 (setq coding (coding-system-base
5839 (save-window-excursion
5840 (select-safe-coding-system (point-min) (point-max)
5842 (setq coding-system-for-write
5843 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5845 (goto-char (point-min))
5846 ;; Add the coding cookie.
5847 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5848 coding-system-for-write)))
5851 (write-region (point-min) (point-max) file-name nil 'no-message)
5852 (message "Appended to %s" file-name))
5853 (write-region (point-min) (point-max) file-name))))
5856 (defun gnus-narrow-to-page (&optional arg)
5857 "Narrow the article buffer to a page.
5858 If given a numerical ARG, move forward ARG pages."
5860 (setq arg (if arg (prefix-numeric-value arg) 0))
5862 (set-buffer gnus-article-buffer)
5863 (goto-char (point-min))
5865 ;; Remove any old next/prev buttons.
5866 (when (gnus-visual-p 'page-marker)
5867 (let ((inhibit-read-only t))
5868 (gnus-remove-text-with-property 'gnus-prev)
5869 (gnus-remove-text-with-property 'gnus-next)))
5872 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5874 (re-search-forward page-delimiter nil 'move arg)))
5875 (goto-char (match-end 0))
5877 (goto-char (point-min))
5878 (setq gnus-page-broken
5879 (and (re-search-forward page-delimiter nil t) t))))
5880 (when gnus-page-broken
5883 (if (re-search-forward page-delimiter nil 'move)
5886 (when (and (gnus-visual-p 'page-marker)
5887 (> (point-min) (save-restriction (widen) (point-min))))
5889 (goto-char (point-min))
5890 (gnus-insert-prev-page-button)))
5891 (when (and (gnus-visual-p 'page-marker)
5892 (< (point-max) (save-restriction (widen) (point-max))))
5894 (goto-char (point-max))
5895 (gnus-insert-next-page-button))))))
5897 ;; Article mode commands
5899 (defun gnus-article-goto-next-page ()
5900 "Show the next page of the article."
5902 (when (gnus-article-next-page)
5903 (goto-char (point-min))
5904 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5907 (defun gnus-article-goto-prev-page ()
5908 "Show the previous page of the article."
5911 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5912 (gnus-article-prev-page nil)))
5914 ;; This is cleaner but currently breaks `gnus-pick-mode':
5916 ;; (defun gnus-article-goto-next-page ()
5917 ;; "Show the next page of the article."
5919 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5920 ;; (gnus-summary-next-page)))
5922 ;; (defun gnus-article-goto-prev-page ()
5923 ;; "Show the next page of the article."
5925 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5926 ;; (gnus-summary-prev-page)))
5928 (defun gnus-article-next-page (&optional lines)
5929 "Show the next page of the current article.
5930 If end of article, return non-nil. Otherwise return nil.
5931 Argument LINES specifies lines to be scrolled up."
5933 (move-to-window-line -1)
5934 (if (and (not (and gnus-article-over-scroll
5935 (> (count-lines (window-start) (point-max))
5936 (+ (or lines (1- (window-height)))
5937 (or (and (boundp 'scroll-margin)
5938 (symbol-value 'scroll-margin))
5942 (and (pos-visible-in-window-p) ;Not continuation line.
5943 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
5944 ;; Nothing in this page.
5945 (if (or (not gnus-page-broken)
5950 (eobp)))) ;Real end-of-buffer?
5952 (when gnus-article-over-scroll
5953 (gnus-article-next-page-1 lines))
5955 (gnus-narrow-to-page 1) ;Go to next page.
5957 ;; More in this page.
5958 (gnus-article-next-page-1 lines)
5961 (defmacro gnus-article-beginning-of-window ()
5962 "Move point to the beginning of the window.
5963 In Emacs, the point is placed at the line number which `scroll-margin'
5965 (if (featurep 'xemacs)
5966 '(move-to-window-line 0)
5967 '(move-to-window-line
5968 (min (max 0 scroll-margin)
5969 (max 1 (- (window-height)
5970 (if mode-line-format 1 0)
5971 (if header-line-format 1 0)))))))
5973 (defun gnus-article-next-page-1 (lines)
5974 (when (and (not (featurep 'xemacs))
5977 (numberp (symbol-value 'scroll-margin))
5978 (> (symbol-value 'scroll-margin) 0))
5979 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5980 ;; too many number of lines if `scroll-margin' is set as two or greater.
5981 (setq lines (min lines
5982 (max 0 (- (count-lines (window-start) (point-max))
5983 (symbol-value 'scroll-margin))))))
5985 (let ((scroll-in-place nil))
5988 ;; Long lines may cause an end-of-buffer error.
5989 (goto-char (point-max))))
5990 (gnus-article-beginning-of-window))
5992 (defun gnus-article-prev-page (&optional lines)
5993 "Show previous page of current article.
5994 Argument LINES specifies lines to be scrolled down."
5996 (move-to-window-line 0)
5997 (if (and gnus-page-broken
5999 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6001 (gnus-narrow-to-page -1) ;Go to previous page.
6002 (goto-char (point-max))
6003 (recenter (if gnus-article-over-scroll
6005 (max (+ lines (or (and (boundp 'scroll-margin)
6006 (symbol-value 'scroll-margin))
6009 (- (window-height) 2))
6013 (let ((scroll-in-place nil))
6014 (scroll-down lines))
6015 (beginning-of-buffer
6016 (goto-char (point-min))))
6017 (gnus-article-beginning-of-window))))
6019 (defun gnus-article-only-boring-p ()
6020 "Decide whether there is only boring text remaining in the article.
6021 Something \"interesting\" is a word of at least two letters that does
6022 not have a face in `gnus-article-boring-faces'."
6023 (when (and gnus-article-skip-boring
6024 (boundp 'gnus-article-boring-faces)
6025 (symbol-value 'gnus-article-boring-faces))
6027 (let ((inhibit-point-motion-hooks t))
6029 (while (re-search-forward "\\b\\w\\w" nil t)
6031 (when (not (gnus-intersection
6032 (gnus-faces-at (point))
6033 (symbol-value 'gnus-article-boring-faces)))
6034 (throw 'only-boring nil)))
6035 (throw 'only-boring t))))))
6037 (defun gnus-article-refer-article ()
6038 "Read article specified by message-id around point."
6041 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6042 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6043 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6044 (let ((msg-id (concat "<" (match-string 0) ">")))
6045 (set-buffer gnus-summary-buffer)
6046 (gnus-summary-refer-article msg-id))
6047 (error "No references around point"))))
6049 (defun gnus-article-show-summary ()
6050 "Reconfigure windows to show summary buffer."
6052 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6053 (error "There is no summary buffer for this article buffer")
6054 (gnus-article-set-globals)
6055 (gnus-configure-windows 'article)
6056 (gnus-summary-goto-subject gnus-current-article)
6057 (gnus-summary-position-point)))
6059 (defun gnus-article-describe-briefly ()
6060 "Describe article mode commands briefly."
6062 (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")))
6064 (defun gnus-article-summary-command ()
6065 "Execute the last keystroke in the summary buffer."
6067 (let ((obuf (current-buffer))
6068 (owin (current-window-configuration))
6070 (switch-to-buffer gnus-article-current-summary 'norecord)
6071 (setq func (lookup-key (current-local-map) (this-command-keys)))
6072 (call-interactively func)
6074 (set-window-configuration owin)
6075 (set-window-point (get-buffer-window (current-buffer)) (point))))
6077 (defun gnus-article-summary-command-nosave ()
6078 "Execute the last keystroke in the summary buffer."
6081 (pop-to-buffer gnus-article-current-summary)
6082 (setq func (lookup-key (current-local-map) (this-command-keys)))
6083 (call-interactively func)))
6085 (defun gnus-article-check-buffer ()
6086 "Beep if not in an article buffer."
6087 (unless (equal major-mode 'gnus-article-mode)
6088 (error "Command invoked outside of a Gnus article buffer")))
6090 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6091 "Read a summary buffer key sequence and execute it from the article buffer."
6093 (gnus-article-check-buffer)
6095 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6096 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6097 "=" "^" "\M-^" "|"))
6103 '("n" "Gn" "p" "Gp"))
6106 (set-buffer gnus-article-current-summary)
6107 (let (gnus-pick-mode)
6108 (push (or key last-command-event) unread-command-events)
6109 (setq keys (if (featurep 'xemacs)
6110 (events-to-keys (read-key-sequence nil))
6111 (read-key-sequence nil)))))
6116 ((eq (aref keys (1- (length keys))) ?\C-h)
6117 (with-current-buffer gnus-article-current-summary
6118 (describe-bindings (substring keys 0 -1))))
6119 ((or (member keys nosaves)
6120 (member keys nosave-but-article)
6121 (member keys nosave-in-article))
6123 (save-window-excursion
6124 (pop-to-buffer gnus-article-current-summary)
6125 ;; We disable the pick minor mode commands.
6126 (let (gnus-pick-mode)
6127 (setq func (lookup-key (current-local-map) keys))))
6131 (unless (member keys nosave-in-article)
6132 (set-buffer gnus-article-current-summary))
6133 (call-interactively func)
6134 (setq new-sum-point (point)))
6135 (when (member keys nosave-but-article)
6136 (pop-to-buffer gnus-article-buffer))))
6138 ;; These commands should restore window configuration.
6139 (let ((obuf (current-buffer))
6140 (owin (current-window-configuration))
6141 win func in-buffer selected new-sum-start new-sum-hscroll err)
6142 (cond (not-restore-window
6143 (pop-to-buffer gnus-article-current-summary)
6144 (setq win (selected-window)))
6145 ((setq win (get-buffer-window gnus-article-current-summary))
6146 (select-window win))
6148 (let ((summary-buffer gnus-article-current-summary))
6149 (gnus-configure-windows 'article)
6150 (unless (setq win (get-buffer-window summary-buffer 'visible))
6151 (let ((gnus-buffer-configuration
6152 '(article ((vertical 1.0
6153 (summary 0.25 point)
6155 (gnus-configure-windows 'article))
6156 (setq win (get-buffer-window summary-buffer 'visible)))
6157 (gnus-select-frame-set-input-focus (window-frame win))
6158 (select-window win))))
6159 (setq in-buffer (current-buffer))
6160 ;; We disable the pick minor mode commands.
6161 (if (and (setq func (let (gnus-pick-mode)
6162 (lookup-key (current-local-map) keys)))
6164 (condition-case code
6166 (call-interactively func)
6172 (when (eq win (selected-window))
6173 (setq new-sum-point (point)
6174 new-sum-start (window-start win)
6175 new-sum-hscroll (window-hscroll win)))
6176 (when (or (eq in-buffer (current-buffer))
6177 (when (eq obuf (current-buffer))
6178 (set-buffer in-buffer)
6180 (setq selected (gnus-summary-select-article))
6182 (unless not-restore-window
6183 (set-window-configuration owin))
6184 (when (and (eq selected 'old)
6186 (set-window-start (get-buffer-window (current-buffer))
6188 (set-window-point (get-buffer-window (current-buffer))
6189 (if (article-goto-body)
6192 (when (and (not not-restore-window)
6194 (with-current-buffer (window-buffer win)
6195 (eq major-mode 'gnus-summary-mode)))
6196 (set-window-point win new-sum-point)
6197 (set-window-start win new-sum-start)
6198 (set-window-hscroll win new-sum-hscroll))))
6199 (set-window-configuration owin)
6201 (signal (car err) (cdr err))
6204 (defun gnus-article-describe-key (key)
6205 "Display documentation of the function invoked by KEY. KEY is a string."
6206 (interactive "kDescribe key: ")
6207 (gnus-article-check-buffer)
6208 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
6210 (set-buffer gnus-article-current-summary)
6211 (let (gnus-pick-mode)
6212 (if (featurep 'xemacs)
6214 (push (elt key 0) unread-command-events)
6215 (setq key (events-to-keys
6216 (read-key-sequence "Describe key: "))))
6217 (setq unread-command-events
6219 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6220 (string-to-list key)))
6221 (setq key (read-key-sequence "Describe key: "))))
6223 (describe-key key)))
6225 (defun gnus-article-describe-key-briefly (key &optional insert)
6226 "Display documentation of the function invoked by KEY. KEY is a string."
6227 (interactive "kDescribe key: \nP")
6228 (gnus-article-check-buffer)
6229 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
6231 (set-buffer gnus-article-current-summary)
6232 (let (gnus-pick-mode)
6233 (if (featurep 'xemacs)
6235 (push (elt key 0) unread-command-events)
6236 (setq key (events-to-keys
6237 (read-key-sequence "Describe key: "))))
6238 (setq unread-command-events
6240 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6241 (string-to-list key)))
6242 (setq key (read-key-sequence "Describe key: "))))
6243 (describe-key-briefly key insert))
6244 (describe-key-briefly key insert)))
6246 (defun gnus-article-reply-with-original (&optional wide)
6247 "Start composing a reply mail to the current message.
6248 The text in the region will be yanked. If the region isn't active,
6249 the entire article will be yanked."
6251 (let ((article (cdr gnus-article-current))
6253 (if (not (gnus-region-active-p))
6254 (with-current-buffer gnus-summary-buffer
6255 (gnus-summary-reply (list (list article)) wide))
6256 (setq contents (buffer-substring (point) (mark t)))
6257 ;; Deactivate active regions.
6258 (when (and (boundp 'transient-mark-mode)
6259 transient-mark-mode)
6260 (setq mark-active nil))
6261 (with-current-buffer gnus-summary-buffer
6263 (list (list article contents)) wide)))))
6265 (defun gnus-article-followup-with-original ()
6266 "Compose a followup to the current article.
6267 The text in the region will be yanked. If the region isn't active,
6268 the entire article will be yanked."
6270 (let ((article (cdr gnus-article-current))
6272 (if (not (gnus-region-active-p))
6273 (with-current-buffer gnus-summary-buffer
6274 (gnus-summary-followup (list (list article))))
6275 (setq contents (buffer-substring (point) (mark t)))
6276 ;; Deactivate active regions.
6277 (when (and (boundp 'transient-mark-mode)
6278 transient-mark-mode)
6279 (setq mark-active nil))
6280 (with-current-buffer gnus-summary-buffer
6281 (gnus-summary-followup
6282 (list (list article contents)))))))
6284 (defun gnus-article-hide (&optional arg force)
6285 "Hide all the gruft in the current article.
6286 This means that signatures, cited text and (some) headers will be
6288 If given a prefix, show the hidden text instead."
6289 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6290 (gnus-article-hide-headers arg)
6291 (gnus-article-hide-list-identifiers arg)
6292 (gnus-article-hide-citation-maybe arg force)
6293 (gnus-article-hide-signature arg))
6295 (defun gnus-article-maybe-highlight ()
6296 "Do some article highlighting if article highlighting is requested."
6297 (when (gnus-visual-p 'article-highlight 'highlight)
6298 (gnus-article-highlight-some)))
6300 (defun gnus-check-group-server ()
6301 ;; Make sure the connection to the server is alive.
6302 (unless (gnus-server-opened
6303 (gnus-find-method-for-group gnus-newsgroup-name))
6304 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6305 (gnus-request-group gnus-newsgroup-name t)))
6308 (autoload 'nneething-get-file-name "nneething"))
6310 (defun gnus-request-article-this-buffer (article group)
6311 "Get an article and insert it into this buffer."
6312 (let (do-update-line sparse-header)
6316 (gnus-kill-all-overlays)
6317 (setq group (or group gnus-newsgroup-name))
6319 ;; Using `gnus-request-article' directly will insert the article into
6320 ;; `nntp-server-buffer' - so we'll save some time by not having to
6321 ;; copy it from the server buffer into the article buffer.
6323 ;; We only request an article by message-id when we do not have the
6324 ;; headers for it, so we'll have to get those.
6325 (when (stringp article)
6326 (gnus-read-header article))
6328 ;; If the article number is negative, that means that this article
6329 ;; doesn't belong in this newsgroup (possibly), so we find its
6330 ;; message-id and request it by id instead of number.
6331 (when (and (numberp article)
6333 (get-buffer gnus-summary-buffer)
6334 (gnus-buffer-exists-p gnus-summary-buffer))
6336 (set-buffer gnus-summary-buffer)
6337 (let ((header (gnus-summary-article-header article)))
6340 ((memq article gnus-newsgroup-sparse)
6341 ;; This is a sparse gap article.
6342 (setq do-update-line article)
6343 (setq article (mail-header-id header))
6344 (setq sparse-header (gnus-read-header article))
6345 (setq gnus-newsgroup-sparse
6346 (delq article gnus-newsgroup-sparse)))
6348 ;; It's a real article.
6349 (setq article (mail-header-id header)))
6351 ;; It is an extracted pseudo-article.
6352 (setq article 'pseudo)
6353 (gnus-request-pseudo-article header))))
6355 (let ((method (gnus-find-method-for-group
6356 gnus-newsgroup-name)))
6357 (when (and (eq (car method) 'nneething)
6359 (let ((dir (nneething-get-file-name
6360 (mail-header-id header))))
6361 (when (and (stringp dir)
6362 (file-directory-p dir))
6363 (setq article 'nneething)
6364 (gnus-group-enter-directory dir))))))))
6367 ;; Refuse to select canceled articles.
6368 ((and (numberp article)
6370 (get-buffer gnus-summary-buffer)
6371 (gnus-buffer-exists-p gnus-summary-buffer)
6372 (eq (cdr (with-current-buffer gnus-summary-buffer
6373 (assq article gnus-newsgroup-reads)))
6374 gnus-canceled-mark))
6376 ;; We first check `gnus-original-article-buffer'.
6377 ((and (get-buffer gnus-original-article-buffer)
6379 (with-current-buffer gnus-original-article-buffer
6380 (and (equal (car gnus-original-article) group)
6381 (eq (cdr gnus-original-article) article))))
6382 (insert-buffer-substring gnus-original-article-buffer)
6384 ;; Check the backlog.
6385 ((and gnus-keep-backlog
6386 (gnus-backlog-request-article group article (current-buffer)))
6388 ;; Check asynchronous pre-fetch.
6389 ((gnus-async-request-fetched-article group article (current-buffer))
6390 (gnus-async-prefetch-next group article gnus-summary-buffer)
6391 (when (and (numberp article) gnus-keep-backlog)
6392 (gnus-backlog-enter-article group article (current-buffer)))
6395 ((and gnus-use-cache
6397 (gnus-cache-request-article article group))
6399 ;; Check the agent cache.
6400 ((gnus-agent-request-article article group)
6402 ;; Get the article and put into the article buffer.
6403 ((or (stringp article)
6405 (let ((gnus-override-method gnus-override-method)
6406 (methods (and (stringp article)
6407 gnus-refer-article-method))
6408 (backend (car (gnus-find-method-for-group
6409 gnus-newsgroup-name)))
6411 (inhibit-read-only t))
6412 (if (or (not (listp methods))
6413 (and (symbolp (car methods))
6414 (assq (car methods) nnoo-definition-alist)))
6415 (setq methods (list methods)))
6416 (when (and (null gnus-override-method)
6418 (setq gnus-override-method (pop methods)))
6420 (when (eq gnus-override-method 'current)
6421 (setq gnus-override-method
6422 (with-current-buffer gnus-summary-buffer
6423 gnus-current-select-method)))
6425 (gnus-kill-all-overlays)
6426 (let ((gnus-newsgroup-name group))
6427 (gnus-check-group-server))
6429 ((gnus-request-article article group (current-buffer))
6430 (when (numberp article)
6431 (gnus-async-prefetch-next group article
6432 gnus-summary-buffer)
6433 (when gnus-keep-backlog
6434 (gnus-backlog-enter-article
6435 group article (current-buffer))))
6436 (setq result 'article))
6438 (setq gnus-override-method (pop methods)))
6439 ((not (string-match "^400 "
6440 (nnheader-get-report backend)))
6441 ;; If we get 400 server disconnect, reconnect and
6442 ;; retry; otherwise, assume the article has expired.
6443 (setq result 'done))))
6444 (and (eq result 'article) 'article)))
6448 ;; Associate this article with the current summary buffer.
6449 (setq gnus-article-current-summary gnus-summary-buffer)
6451 ;; Take the article from the original article buffer
6452 ;; and place it in the buffer it's supposed to be in.
6453 (when (and (get-buffer gnus-article-buffer)
6454 (equal (buffer-name (current-buffer))
6455 (buffer-name (get-buffer gnus-article-buffer))))
6457 (if (get-buffer gnus-original-article-buffer)
6458 (set-buffer gnus-original-article-buffer)
6459 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6460 (buffer-disable-undo)
6461 (setq major-mode 'gnus-original-article-mode)
6462 (setq buffer-read-only t))
6463 (let ((inhibit-read-only t))
6465 (insert-buffer-substring gnus-article-buffer))
6466 (setq gnus-original-article (cons group article)))
6469 (run-hooks 'gnus-article-decode-hook)
6470 ;; Mark article as decoded or not.
6471 (setq gnus-article-decoded-p gnus-article-decode-hook))
6473 ;; Update sparse articles.
6474 (when (and do-update-line
6475 (or (numberp article)
6477 (let ((buf (current-buffer)))
6478 (set-buffer gnus-summary-buffer)
6479 (gnus-summary-update-article do-update-line sparse-header)
6480 (gnus-summary-goto-subject do-update-line nil t)
6481 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6483 (set-buffer buf))))))
6489 (defcustom gnus-article-edit-mode-hook nil
6490 "Hook run in article edit mode buffers."
6491 :group 'gnus-article-various
6494 (defvar gnus-article-edit-done-function nil)
6496 (defvar gnus-article-edit-mode-map nil)
6498 ;; Should we be using derived.el for this?
6499 (unless gnus-article-edit-mode-map
6500 (setq gnus-article-edit-mode-map (make-keymap))
6501 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6503 (gnus-define-keys gnus-article-edit-mode-map
6504 "\C-c?" describe-mode
6505 "\C-c\C-c" gnus-article-edit-done
6506 "\C-c\C-k" gnus-article-edit-exit
6507 "\C-c\C-f\C-t" message-goto-to
6508 "\C-c\C-f\C-o" message-goto-from
6509 "\C-c\C-f\C-b" message-goto-bcc
6510 ;;"\C-c\C-f\C-w" message-goto-fcc
6511 "\C-c\C-f\C-c" message-goto-cc
6512 "\C-c\C-f\C-s" message-goto-subject
6513 "\C-c\C-f\C-r" message-goto-reply-to
6514 "\C-c\C-f\C-n" message-goto-newsgroups
6515 "\C-c\C-f\C-d" message-goto-distribution
6516 "\C-c\C-f\C-f" message-goto-followup-to
6517 "\C-c\C-f\C-m" message-goto-mail-followup-to
6518 "\C-c\C-f\C-k" message-goto-keywords
6519 "\C-c\C-f\C-u" message-goto-summary
6520 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6521 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6522 "\C-c\C-b" message-goto-body
6523 "\C-c\C-i" message-goto-signature
6525 "\C-c\C-t" message-insert-to
6526 "\C-c\C-n" message-insert-newsgroups
6527 "\C-c\C-o" message-sort-headers
6528 "\C-c\C-e" message-elide-region
6529 "\C-c\C-v" message-delete-not-region
6530 "\C-c\C-z" message-kill-to-signature
6531 "\M-\r" message-newline-and-reformat
6532 "\C-c\C-a" mml-attach-file
6533 "\C-a" message-beginning-of-line
6535 "\M-;" comment-region)
6537 (gnus-define-keys (gnus-article-edit-wash-map
6538 "\C-c\C-w" gnus-article-edit-mode-map)
6539 "f" gnus-article-edit-full-stops))
6542 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6544 ["Fetch To" message-insert-to t]
6545 ["Fetch Newsgroups" message-insert-newsgroups t]
6547 ["To" message-goto-to t]
6548 ["From" message-goto-from t]
6549 ["Subject" message-goto-subject t]
6550 ["Cc" message-goto-cc t]
6551 ["Reply-To" message-goto-reply-to t]
6552 ["Summary" message-goto-summary t]
6553 ["Keywords" message-goto-keywords t]
6554 ["Newsgroups" message-goto-newsgroups t]
6555 ["Followup-To" message-goto-followup-to t]
6556 ["Mail-Followup-To" message-goto-mail-followup-to t]
6557 ["Distribution" message-goto-distribution t]
6558 ["Body" message-goto-body t]
6559 ["Signature" message-goto-signature t]))
6561 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6562 "Major mode for editing articles.
6563 This is an extended text-mode.
6565 \\{gnus-article-edit-mode-map}"
6566 (make-local-variable 'gnus-article-edit-done-function)
6567 (make-local-variable 'gnus-prev-winconf)
6568 (set (make-local-variable 'font-lock-defaults)
6569 '(message-font-lock-keywords t))
6570 (set (make-local-variable 'mail-header-separator) "")
6571 (set (make-local-variable 'gnus-article-edit-mode) t)
6572 (easy-menu-add message-mode-field-menu message-mode-map)
6574 (setq buffer-read-only nil)
6575 (buffer-enable-undo)
6578 (defun gnus-article-edit (&optional force)
6579 "Edit the current article.
6580 This will have permanent effect only in mail groups.
6581 If FORCE is non-nil, allow editing of articles even in read-only
6584 (when (and (not force)
6585 (gnus-group-read-only-p))
6586 (error "The current newsgroup does not support article editing"))
6587 (gnus-article-date-original)
6588 (gnus-article-edit-article
6590 `(lambda (no-highlight)
6592 (gnus-summary-edit-article-done
6593 ,(or (mail-header-references gnus-current-headers) "")
6594 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6596 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6597 "Start editing the contents of the current article buffer."
6598 (let ((winconf (current-window-configuration)))
6599 (set-buffer gnus-article-buffer)
6600 (let ((message-auto-save-directory
6601 ;; Don't associate the article buffer with a draft file.
6603 (gnus-article-edit-mode))
6604 (funcall start-func)
6605 (set-buffer-modified-p nil)
6606 (gnus-configure-windows 'edit-article)
6607 (setq gnus-article-edit-done-function exit-func)
6608 (setq gnus-prev-winconf winconf)
6610 (gnus-message 6 "C-c C-c to end edits"))))
6612 (defun gnus-article-edit-done (&optional arg)
6613 "Update the article edits and exit."
6615 (let ((func gnus-article-edit-done-function)
6616 (buf (current-buffer))
6617 (start (window-start))
6619 (winconf gnus-prev-winconf))
6620 (widen) ;; Widen it in case that users narrowed the buffer.
6623 ;; The cache and backlog have to be flushed somewhat.
6624 (when gnus-keep-backlog
6625 (gnus-backlog-remove-article
6626 (car gnus-article-current) (cdr gnus-article-current)))
6627 ;; Flush original article as well.
6629 (when (get-buffer gnus-original-article-buffer)
6630 (set-buffer gnus-original-article-buffer)
6631 (setq gnus-original-article nil)))
6632 (when gnus-use-cache
6633 (gnus-cache-update-article
6634 (car gnus-article-current) (cdr gnus-article-current)))
6635 ;; We remove all text props from the article buffer.
6636 (kill-all-local-variables)
6637 (set-text-properties (point-min) (point-max) nil)
6639 (set-window-configuration winconf)
6641 (set-window-start (get-buffer-window buf) start)
6642 (set-window-point (get-buffer-window buf) (point)))
6643 (gnus-summary-show-article))
6645 (defun gnus-article-edit-exit ()
6646 "Exit the article editing without updating."
6648 (when (or (not (buffer-modified-p))
6649 (yes-or-no-p "Article modified; kill anyway? "))
6650 (let ((curbuf (current-buffer))
6652 (window-start (window-start)))
6654 (if (gnus-buffer-live-p gnus-original-article-buffer)
6655 (insert-buffer-substring gnus-original-article-buffer))
6656 (let ((winconf gnus-prev-winconf))
6657 (kill-all-local-variables)
6659 (set-window-configuration winconf)
6660 ;; Tippy-toe some to make sure that point remains where it was.
6661 (save-current-buffer
6663 (set-window-start (get-buffer-window (current-buffer)) window-start)
6665 (gnus-summary-show-article)))
6667 (defun gnus-article-edit-full-stops ()
6668 "Interactively repair spacing at end of sentences."
6671 (goto-char (point-min))
6672 (search-forward-regexp "^$" nil t)
6673 (let ((case-fold-search nil))
6674 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6677 ;;; Article highlights
6680 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6682 ;;; Internal Variables:
6684 (defcustom gnus-button-url-regexp
6686 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6687 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6688 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6689 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6690 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6694 ;; Match paired parentheses, e.g. in Wikipedia URLs:
6695 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6697 "[" chars punct "]+" "[" chars "]"
6699 (concat ;; XEmacs 21.4 doesn't support POSIX.
6700 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6701 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6703 "Regular expression that matches URLs."
6704 :group 'gnus-article-buttons
6707 (defcustom gnus-button-valid-fqdn-regexp
6708 message-valid-fqdn-regexp
6709 "Regular expression that matches a valid FQDN."
6711 :group 'gnus-article-buttons
6714 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6715 (defcustom gnus-button-valid-localpart-regexp
6716 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6717 "Regular expression that matches a localpart of mail addresses or MIDs."
6719 :group 'gnus-article-buttons
6722 (defcustom gnus-button-man-handler 'manual-entry
6723 "Function to use for displaying man pages.
6724 The function must take at least one argument with a string naming the
6727 :type '(choice (function-item :tag "Man" manual-entry)
6728 (function-item :tag "Woman" woman)
6729 (function :tag "Other"))
6730 :group 'gnus-article-buttons)
6732 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6733 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6734 If the default site is too slow, try to find a CTAN mirror, see
6735 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6736 the variable `gnus-button-handle-ctan'."
6738 :group 'gnus-article-buttons
6739 :link '(custom-manual "(gnus)Group Parameters")
6740 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6741 (const "http://tug.ctan.org/tex-archive/")
6742 (const "http://www.dante.de/CTAN/")
6743 (string :tag "Other")))
6745 (defcustom gnus-button-ctan-handler 'browse-url
6746 "Function to use for displaying CTAN links.
6747 The function must take one argument, the string naming the URL."
6749 :type '(choice (function-item :tag "Browse Url" browse-url)
6750 (function :tag "Other"))
6751 :group 'gnus-article-buttons)
6753 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6754 "Bogus strings removed from CTAN URLs."
6756 :group 'gnus-article-buttons
6757 :type '(choice (const "^/?tex-archive/\\|/")
6758 (regexp :tag "Other")))
6760 (defcustom gnus-button-ctan-directory-regexp
6762 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6763 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6764 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6765 "tds" "tools" "usergrps" "web") t)
6766 "Regular expression for ctan directories.
6767 It should match all directories in the top level of `gnus-ctan-url'."
6769 :group 'gnus-article-buttons
6772 (defcustom gnus-button-mid-or-mail-regexp
6773 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6774 gnus-button-valid-fqdn-regexp
6776 "Regular expression that matches a message ID or a mail address."
6778 :group 'gnus-article-buttons
6781 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6782 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6783 Strings like this can be either a message ID or a mail address. If it is one
6784 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6785 message ID or a mail address, respectively. If this variable is set to the
6786 symbol `ask', always query the user what do do. If it is a function, this
6787 function will be called with the string as its only argument. The function
6788 must return `mid', `mail', `invalid' or `ask'."
6790 :group 'gnus-article-buttons
6791 :type '(choice (function-item :tag "Heuristic function"
6792 gnus-button-mid-or-mail-heuristic)
6797 (defcustom gnus-button-mid-or-mail-heuristic-alist
6798 '((-10.0 . ".+\\$.+@")
6801 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6802 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6803 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6804 (-1.0 . "^[^a-z]+@")
6806 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6807 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6808 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6809 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6812 (-1.0 . "^[0-9][0-9]")
6814 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6815 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6816 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6817 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6819 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6820 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6823 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6825 ;; compensation for TDMA dated mail addresses:
6826 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6828 (-20.0 . "\\.fsf@") ;; Gnus
6831 (-20.0 . "^alpine\\.")
6832 (-20.0 . "_-_") ;; Subject change in thread
6834 (-20.0 . "\\.ln@") ;; leafnode
6835 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6836 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6838 ;; (5.0 . "") ;; $local_part_len <= 7
6839 (10.0 . "^[^0-9]+@")
6840 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6841 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6844 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6846 (0.5 . "^[A-Z][a-z]")
6847 (0.5 . "^[A-Z][a-z][a-z]")
6848 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6849 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6850 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6852 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6853 address. The REGEXP is processed with `case-fold-search' set to nil."
6855 :group 'gnus-article-buttons
6856 :type '(repeat (cons (number :tag "Rate")
6857 (regexp :tag "Regexp"))))
6859 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6860 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6861 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6862 address, `ask' if unsure and `invalid' if the string is invalid."
6863 (let ((case-fold-search nil)
6864 (list gnus-button-mid-or-mail-heuristic-alist)
6865 (result 0) rate regexp lpartlen elem)
6867 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6868 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6869 ;; Certain special cases...
6872 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6873 "^[0-9]+\\.[0-9]+@compuserve\\|"
6874 "@public\\.gmane\\.org")
6876 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6877 (setq result 'mail))
6878 (when (string-match "@.*@\\| " mid-or-mail)
6879 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6880 (setq result 'invalid))
6881 ;; Nothing more to do, if result is not a number here...
6882 (when (numberp result)
6884 (setq elem (car list)
6888 (when (string-match regexp mid-or-mail)
6889 (setq result (+ result rate))
6891 9 "`%s' matched `%s', rate `%s', result `%s'."
6892 mid-or-mail regexp rate result)))
6893 (when (<= lpartlen 7)
6894 (setq result (+ result 5.0))
6895 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6896 mid-or-mail result))
6897 (when (>= lpartlen 12)
6898 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6900 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6901 ;; Long local part should contain realname if e-mail address,
6902 ;; too many digits: message-id.
6903 ;; $score -= 5.0 + 0.1 * $local_part_len;
6904 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6905 (setq result (+ result rate))
6907 9 "Many digits in `%s', rate `%s', result `%s'."
6908 mid-or-mail rate result))
6909 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6911 ;; Too few vowels [^aeiouy]{4,}.*\@
6912 (setq result (+ result -5.0))
6914 9 "Few vowels in `%s', rate `%s', result `%s'."
6915 mid-or-mail -5.0 result))
6917 (setq result (+ result 5.0))
6919 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6920 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6921 ;; Maybe we should make this a customizable alist: (condition . 'result)
6923 ((symbolp result) result)
6924 ;; Now convert number into proper results:
6925 ((< result -10.0) 'mid)
6926 ((> result 10.0) 'mail)
6929 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6930 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6931 (url-mid (concat "news" ":" mid-or-mail))
6932 (url-mailto (concat "mailto" ":" mid-or-mail)))
6933 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6934 (when (fboundp pref)
6936 ;; get rid of surrounding angles...
6938 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6939 (if (or (eq 'mid guessed) (eq 'mail guessed))
6943 (save-window-excursion
6944 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6947 (cond ((eq pref 'mid)
6948 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6949 (gnus-button-handle-news url-mid))
6951 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6952 (gnus-url-mailto url-mailto))
6953 (t (gnus-message 3 "Invalid string.")))))
6955 (defun gnus-button-handle-custom (fun arg)
6956 "Call function FUN on argument ARG.
6957 Both FUN and ARG are supposed to be strings. ARG will be passed
6958 as a symbol to FUN."
6959 (funcall (intern fun)
6960 (if (string-match "^customize-apropos" fun)
6964 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6966 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6969 (defun gnus-button-handle-describe-function (url)
6970 "Call `describe-function' when pushing the corresponding URL button."
6973 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6975 (defun gnus-button-handle-describe-variable (url)
6976 "Call `describe-variable' when pushing the corresponding URL button."
6979 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6981 (defun gnus-button-handle-symbol (url)
6982 "Display help on variable or function.
6983 Calls `describe-variable' or `describe-function'."
6984 (let ((sym (intern url)))
6986 ((fboundp sym) (describe-function sym))
6987 ((boundp sym) (describe-variable sym))
6988 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6990 (defun gnus-button-handle-describe-key (url)
6991 "Call `describe-key' when pushing the corresponding URL button."
6993 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6994 (keys (ignore-errors (eval `(kbd ,key-string)))))
6997 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6999 (defun gnus-button-handle-apropos (url)
7000 "Call `apropos' when pushing the corresponding URL button."
7001 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7003 (defun gnus-button-handle-apropos-command (url)
7004 "Call `apropos' when pushing the corresponding URL button."
7006 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7008 (defun gnus-button-handle-apropos-variable (url)
7009 "Call `apropos' when pushing the corresponding URL button."
7011 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7012 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7014 (defun gnus-button-handle-apropos-documentation (url)
7015 "Call `apropos' when pushing the corresponding URL button."
7017 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7018 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7020 (defun gnus-button-handle-library (url)
7021 "Call `locate-library' when pushing the corresponding URL button."
7022 (gnus-message 9 "url=`%s'" url)
7023 (let* ((lib (locate-library url))
7024 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7026 (gnus-message 1 "Cannot locale library `%s'." url)
7027 (find-file-read-only file))))
7029 (defun gnus-button-handle-ctan (url)
7030 "Call `browse-url' when pushing a CTAN URL button."
7032 gnus-button-ctan-handler
7035 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7037 (defcustom gnus-button-tex-level 5
7038 "*Integer that says how many TeX-related buttons Gnus will show.
7039 The higher the number, the more buttons will appear and the more false
7040 positives are possible. Note that you can set this variable local to
7041 specific groups. Setting it higher in TeX groups is probably a good idea.
7042 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7043 how to set variables in specific groups."
7045 :group 'gnus-article-buttons
7046 :link '(custom-manual "(gnus)Group Parameters")
7049 (defcustom gnus-button-man-level 5
7050 "*Integer that says how many man-related buttons Gnus will show.
7051 The higher the number, the more buttons will appear and the more false
7052 positives are possible. Note that you can set this variable local to
7053 specific groups. Setting it higher in Unix groups is probably a good idea.
7054 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7055 how to set variables in specific groups."
7057 :group 'gnus-article-buttons
7058 :link '(custom-manual "(gnus)Group Parameters")
7061 (defcustom gnus-button-emacs-level 5
7062 "*Integer that says how many emacs-related buttons Gnus will show.
7063 The higher the number, the more buttons will appear and the more false
7064 positives are possible. Note that you can set this variable local to
7065 specific groups. Setting it higher in Emacs or Gnus related groups is
7066 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7067 `gnus-parameters' on how to set variables in specific groups."
7069 :group 'gnus-article-buttons
7070 :link '(custom-manual "(gnus)Group Parameters")
7073 (defcustom gnus-button-message-level 5
7074 "*Integer that says how many buttons for news or mail messages will appear.
7075 The higher the number, the more buttons will appear and the more false
7076 positives are possible."
7077 ;; mail addresses, MIDs, URLs for news, ...
7079 :group 'gnus-article-buttons
7082 (defcustom gnus-button-browse-level 5
7083 "*Integer that says how many buttons for browsing will appear.
7084 The higher the number, the more buttons will appear and the more false
7085 positives are possible."
7086 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7088 :group 'gnus-article-buttons
7091 (defcustom gnus-button-alist
7092 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7093 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7094 ((concat "\\b\\(nntp\\|news\\):\\("
7095 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7096 0 t gnus-button-handle-news 2)
7097 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7098 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7099 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7100 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7101 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7102 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7103 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7104 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7105 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7106 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7107 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7108 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7109 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7110 ;; RFC 2368 (The mailto URL scheme)
7111 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7112 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7113 ("\\bmailto:\\([^ \n\t]+\\)"
7114 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7116 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7117 gnus-button-ctan-directory-regexp
7118 "[^][>)!;:,'\n\t ]+\\)")
7119 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7120 ((concat "\\btex-archive/\\("
7121 gnus-button-ctan-directory-regexp
7122 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7123 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7126 gnus-button-ctan-directory-regexp
7127 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7128 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7129 ;; This is info (home-grown style) <info://foo/bar+baz>
7130 ("\\binfo://\\([^'\">\n\t ]+\\)"
7131 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7132 ;; Info GNOME style <info:foo#bar_baz>
7133 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7134 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7135 ;; Info KDE style <info:(foo)bar baz>
7136 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7137 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7138 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7139 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7140 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7141 ;; Info links like `C-h i d m CC Mode RET'
7142 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
7144 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7145 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7146 ;; Emacs help commands
7147 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7148 ;; regexp doesn't match arguments containing ` '.
7149 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7150 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7151 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7152 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7153 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7154 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7155 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7156 ;; The following entries may lead to many false positives so don't enable
7157 ;; them by default (use a high button level).
7158 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7159 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7160 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7161 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7162 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7163 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7164 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7165 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7166 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7167 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7168 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7169 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7170 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7171 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7172 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7173 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7174 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7175 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7176 ;; Unlike the other regexps we really have to require quoting
7177 ;; here to determine where it ends.
7178 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7179 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7180 ("<URL: *\\([^\n<>]*\\)>"
7181 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7182 ;; RFC 2396 (2.4.3., delims) ...
7183 ("\"URL: *\\([^\n\"]*\\)\""
7184 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7186 (gnus-button-url-regexp
7187 0 (>= gnus-button-browse-level 0) browse-url 0)
7189 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7190 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7191 gnus-button-handle-man 1)
7192 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7193 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7194 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7195 gnus-button-handle-man 1)
7196 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7197 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7198 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7199 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7200 ;; Recognizing patches to .el files. This is somewhat obscure,
7201 ;; but considering the percentage of Gnus users who hack Emacs
7203 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7204 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7205 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7206 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7207 ;; MID or mail: To avoid too many false positives we don't try to catch
7208 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7209 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7210 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7211 ;; so that non-ambiguous entries (see above) match first.
7212 (gnus-button-mid-or-mail-regexp
7213 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7214 "*Alist of regexps matching buttons in article bodies.
7216 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7217 REGEXP: is the string (case insensitive) matching text around the button (can
7218 also be Lisp expression evaluating to a string),
7219 BUTTON: is the number of the regexp grouping actually matching the button,
7220 FORM: is a Lisp expression which must eval to true for the button to
7222 CALLBACK: is the function to call when the user push this button, and each
7223 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7225 CALLBACK can also be a variable, in that case the value of that
7226 variable it the real callback function."
7227 :group 'gnus-article-buttons
7228 :type '(repeat (list (choice regexp variable sexp)
7229 (integer :tag "Button")
7231 (function :tag "Callback")
7234 (integer :tag "Regexp group")))))
7235 (put 'gnus-button-alist 'risky-local-variable t)
7237 (defcustom gnus-header-button-alist
7238 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7239 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7240 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7241 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7242 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7243 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7244 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7245 0 (>= gnus-button-browse-level 0) browse-url 0)
7246 ("^Subject:" gnus-button-url-regexp
7247 0 (>= gnus-button-browse-level 0) browse-url 0)
7248 ("^[^:]+:" gnus-button-url-regexp
7249 0 (>= gnus-button-browse-level 0) browse-url 0)
7250 ("^OpenPGP:.*url=" gnus-button-url-regexp
7251 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7252 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7253 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7254 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7255 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7256 "*Alist of headers and regexps to match buttons in article heads.
7258 This alist is very similar to `gnus-button-alist', except that each
7259 alist has an additional HEADER element first in each entry:
7261 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7263 HEADER is a regexp to match a header. For a fuller explanation, see
7264 `gnus-button-alist'."
7265 :group 'gnus-article-buttons
7266 :group 'gnus-article-headers
7267 :type '(repeat (list (regexp :tag "Header")
7268 (choice regexp variable)
7269 (integer :tag "Button")
7271 (function :tag "Callback")
7274 (integer :tag "Regexp group")))))
7275 (put 'gnus-header-button-alist 'risky-local-variable t)
7279 (defun gnus-article-push-button (event)
7280 "Check text under the mouse pointer for a callback function.
7281 If the text under the mouse pointer has a `gnus-callback' property,
7282 call it with the value of the `gnus-data' text property."
7284 (set-buffer (window-buffer (posn-window (event-start event))))
7285 (let* ((pos (posn-point (event-start event)))
7286 (data (get-text-property pos 'gnus-data))
7287 (fun (get-text-property pos 'gnus-callback)))
7290 (funcall fun data))))
7292 (defun gnus-article-press-button ()
7293 "Check text at point for a callback function.
7294 If the text at point has a `gnus-callback' property,
7295 call it with the value of the `gnus-data' text property."
7297 (let ((data (get-text-property (point) 'gnus-data))
7298 (fun (get-text-property (point) 'gnus-callback)))
7300 (funcall fun data))))
7302 (defun gnus-article-highlight (&optional force)
7303 "Highlight current article.
7304 This function calls `gnus-article-highlight-headers',
7305 `gnus-article-highlight-citation',
7306 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7307 do the highlighting. See the documentation for those functions."
7308 (interactive (list 'force))
7309 (gnus-article-highlight-headers)
7310 (gnus-article-highlight-citation force)
7311 (gnus-article-highlight-signature)
7312 (gnus-article-add-buttons force)
7313 (gnus-article-add-buttons-to-head))
7315 (defun gnus-article-highlight-some (&optional force)
7316 "Highlight current article.
7317 This function calls `gnus-article-highlight-headers',
7318 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7319 do the highlighting. See the documentation for those functions."
7320 (interactive (list 'force))
7321 (gnus-article-highlight-headers)
7322 (gnus-article-highlight-signature)
7323 (gnus-article-add-buttons))
7325 (defun gnus-article-highlight-headers ()
7326 "Highlight article headers as specified by `gnus-header-face-alist'."
7328 (gnus-with-article-headers
7329 (let (regexp header-face field-face from hpoints fpoints)
7330 (dolist (entry gnus-header-face-alist)
7331 (goto-char (point-min))
7332 (setq regexp (concat "^\\("
7333 (if (string-equal "" (nth 0 entry))
7337 header-face (nth 1 entry)
7338 field-face (nth 2 entry))
7339 (while (and (re-search-forward regexp nil t)
7343 (unless (search-forward ":" nil t)
7345 (when (and header-face
7346 (not (memq (point) hpoints)))
7347 (push (point) hpoints)
7348 (gnus-put-text-property from (point) 'face header-face))
7349 (when (and field-face
7350 (not (memq (setq from (point)) fpoints)))
7352 (if (re-search-forward "^[^ \t]" nil t)
7354 (goto-char (point-max)))
7355 (gnus-put-text-property from (point) 'face field-face)))))))
7357 (defun gnus-article-highlight-signature ()
7358 "Highlight the signature in an article.
7359 It does this by highlighting everything after
7360 `gnus-signature-separator' using the face `gnus-signature'."
7362 (gnus-with-article-buffer
7363 (let ((inhibit-point-motion-hooks t))
7365 (when (and gnus-signature-face
7366 (gnus-article-narrow-to-signature))
7367 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7368 'face gnus-signature-face)
7370 (gnus-article-search-signature)
7371 (let ((start (match-beginning 0))
7372 (end (set-marker (make-marker) (1+ (match-end 0)))))
7373 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7376 (defun gnus-button-in-region-p (b e prop)
7377 "Say whether PROP exists in the region."
7378 (text-property-not-all b e prop nil))
7380 (defun gnus-article-add-buttons (&optional force)
7381 "Find external references in the article and make buttons of them.
7382 \"External references\" are things like Message-IDs and URLs, as
7383 specified by `gnus-button-alist'."
7384 (interactive (list 'force))
7385 (gnus-with-article-buffer
7386 (let ((inhibit-point-motion-hooks t)
7387 (case-fold-search t)
7388 (alist gnus-button-alist)
7390 ;; Remove all old markers.
7391 (let (marker entry new-list)
7392 (while (setq marker (pop gnus-button-marker-list))
7393 (if (or (< marker (point-min)) (>= marker (point-max)))
7394 (push marker new-list)
7396 (when (setq entry (gnus-button-entry))
7397 (put-text-property (match-beginning (nth 1 entry))
7398 (match-end (nth 1 entry))
7399 'gnus-callback nil))
7400 (set-marker marker nil)))
7401 (setq gnus-button-marker-list new-list))
7402 ;; We skip the headers.
7405 (while (setq entry (pop alist))
7406 (setq regexp (eval (car entry)))
7408 (while (re-search-forward regexp nil t)
7409 (let ((start (match-beginning (nth 1 entry)))
7410 (end (match-end (nth 1 entry)))
7411 (from (match-beginning 0)))
7412 (when (and (or (eq t (nth 2 entry))
7413 (eval (nth 2 entry)))
7414 (not (gnus-button-in-region-p
7415 start end 'gnus-callback)))
7416 ;; That optional form returned non-nil, so we add the
7418 (setq from (set-marker (make-marker) from))
7419 (push from gnus-button-marker-list)
7420 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7421 (gnus-article-extend-url-button from start end))
7422 (gnus-article-add-button start end
7423 'gnus-button-push from)))))))))
7425 (defun gnus-article-extend-url-button (beg start end)
7426 "Extend url button if url is folded into two or more lines.
7427 Return non-nil if button is extended. BEG is a marker that points to
7428 the beginning position of a text containing url. START and END are
7429 the endpoints of a url button before it is extended. The concatenated
7430 url is put as the `gnus-button-url' overlay property on the button."
7431 (let ((opoint (point))
7432 (points (list start end))
7437 (not (looking-at "[\t ]*[\">]")))
7441 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7442 (buffer-substring (point-at-bol) start)))
7444 (setq url (list (buffer-substring start end))
7445 delim (if (match-beginning 1) ">" "\""))
7447 (setq regexp (concat
7448 (when (and (looking-at
7449 message-cite-prefix-regexp)
7450 (< (match-end 0) start))
7451 (regexp-quote (match-string 0)))
7453 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7457 (and (looking-at regexp)
7460 (push (or (match-string 2)
7463 (push (setq end (or (match-end 2)
7466 (push (or (match-beginning 2)
7467 (match-beginning 1))
7469 (match-beginning 2)))
7470 (let (gnus-article-mouse-face widget-mouse-face)
7472 (gnus-article-add-button (pop points) (pop points)
7473 'gnus-button-push beg)))
7474 (let ((overlay (gnus-make-overlay start end)))
7475 (gnus-overlay-put overlay 'evaporate t)
7476 (gnus-overlay-put overlay 'gnus-button-url
7477 (list (mapconcat 'identity (nreverse url) "")))
7478 (when gnus-article-mouse-face
7479 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7481 (goto-char opoint))))
7483 ;; Add buttons to the head of an article.
7484 (defun gnus-article-add-buttons-to-head ()
7485 "Add buttons to the head of the article."
7487 (gnus-with-article-headers
7489 (dolist (entry gnus-header-button-alist)
7490 ;; Each alist entry.
7491 (goto-char (point-min))
7492 (while (re-search-forward (car entry) nil t)
7493 ;; Each header matching the entry.
7494 (setq beg (match-beginning 0))
7495 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7496 (match-beginning 0))
7499 (while (re-search-forward (eval (nth 1 entry)) end t)
7500 ;; Each match within a header.
7501 (let* ((entry (cdr entry))
7502 (start (match-beginning (nth 1 entry)))
7503 (end (match-end (nth 1 entry)))
7504 (form (nth 2 entry)))
7505 (goto-char (match-end 0))
7507 (gnus-article-add-button
7508 start end (nth 3 entry)
7509 (buffer-substring (match-beginning (nth 4 entry))
7510 (match-end (nth 4 entry)))))))
7511 (goto-char end))))))
7513 ;;; External functions:
7515 (defun gnus-article-add-button (from to fun &optional data)
7516 "Create a button between FROM and TO with callback FUN and data DATA."
7517 (when gnus-article-button-face
7518 (gnus-overlay-put (gnus-make-overlay from to nil t)
7519 'face gnus-article-button-face))
7520 (gnus-add-text-properties
7522 (nconc (and gnus-article-mouse-face
7523 (list gnus-mouse-face-prop gnus-article-mouse-face))
7524 (list 'gnus-callback fun)
7525 (and data (list 'gnus-data data))))
7526 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7527 :button-keymap gnus-widget-button-keymap))
7529 ;;; Internal functions:
7531 (defun gnus-article-set-globals ()
7532 (with-current-buffer gnus-summary-buffer
7533 (gnus-set-global-variables)))
7535 (defun gnus-signature-toggle (end)
7536 (gnus-with-article-buffer
7537 (let ((inhibit-point-motion-hooks t))
7538 (if (text-property-any end (point-max) 'article-type 'signature)
7540 (gnus-delete-wash-type 'signature)
7541 (gnus-remove-text-properties-when
7542 'article-type 'signature end (point-max)
7543 (cons 'article-type (cons 'signature
7544 gnus-hidden-properties))))
7545 (gnus-add-wash-type 'signature)
7546 (gnus-add-text-properties-when
7547 'article-type nil end (point-max)
7548 (cons 'article-type (cons 'signature
7549 gnus-hidden-properties)))))
7550 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7551 (gnus-set-mode-line 'article))))
7553 (defun gnus-button-entry ()
7554 ;; Return the first entry in `gnus-button-alist' matching this place.
7555 (let ((alist gnus-button-alist)
7558 (setq entry (pop alist))
7559 (if (looking-at (eval (car entry)))
7564 (defun gnus-button-push (marker)
7565 ;; Push button starting at MARKER.
7568 (let* ((entry (gnus-button-entry))
7569 (inhibit-point-motion-hooks t)
7571 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7572 (get-char-property marker 'gnus-button-url))
7573 (mapcar (lambda (group)
7574 (let ((string (match-string group)))
7575 (set-text-properties
7576 0 (length string) nil string)
7578 (nthcdr 4 entry)))))
7583 (fboundp (symbol-value fun)))
7584 (apply (symbol-value fun) args))
7586 (gnus-message 1 "You must define `%S' to use this button"
7587 (cons fun args)))))))
7589 (defun gnus-parse-news-url (url)
7590 (let (scheme server port group message-id articles)
7593 (goto-char (point-min))
7594 (when (looking-at "\\([A-Za-z]+\\):")
7595 (setq scheme (match-string 1))
7596 (goto-char (match-end 0)))
7597 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7598 (setq server (match-string 1))
7599 (setq port (if (stringp (match-string 3))
7600 (string-to-number (match-string 3))
7602 (goto-char (match-end 0)))
7605 ((looking-at "\\(.*@.*\\)")
7606 (setq message-id (match-string 1)))
7607 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7608 (setq group (match-string 1)
7609 articles (split-string (match-string 2) "-")))
7610 ((looking-at "\\([^/]+\\)/?")
7611 (setq group (match-string 1)))
7613 (error "Unknown news URL syntax"))))
7614 (list scheme server port group message-id articles)))
7616 (defun gnus-button-handle-news (url)
7618 (destructuring-bind (scheme server port group message-id articles)
7619 (gnus-parse-news-url url)
7623 (set-buffer gnus-summary-buffer)
7625 (let ((gnus-refer-article-method
7626 (nconc (list (list 'nntp server))
7627 gnus-refer-article-method))
7628 (nntp-port-number (or port "nntp")))
7629 (gnus-message 7 "Fetching %s with %s"
7630 message-id gnus-refer-article-method)
7631 (gnus-summary-refer-article message-id))
7632 (gnus-summary-refer-article message-id))))
7634 (gnus-button-fetch-group url)))))
7636 (defun gnus-button-patch (library line)
7637 "Visit an Emacs Lisp library LIBRARY on line LINE."
7639 (let ((file (locate-library (file-name-nondirectory library))))
7641 (error "Couldn't find library %s" library))
7643 (goto-line (string-to-number line))))
7645 (defun gnus-button-handle-man (url)
7647 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7648 (when (eq gnus-button-man-handler 'woman)
7649 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7650 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7651 (funcall gnus-button-man-handler url))
7653 (defun gnus-button-handle-info-url (url)
7654 "Fetch an info URL."
7655 (setq url (mm-subst-char-in-string ?+ ?\ url))
7657 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7658 (gnus-info-find-node
7659 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7661 ")" (gnus-url-unhex-string (match-string 2 url)))))
7662 ((string-match "([^)\"]+)[^\"]+" url)
7664 (gnus-replace-in-string
7665 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7666 (gnus-info-find-node url))
7667 (t (error "Can't parse %s" url))))
7669 (defun gnus-button-handle-info-url-gnome (url)
7670 "Fetch GNOME style info URL."
7671 (setq url (mm-subst-char-in-string ?_ ?\ url))
7672 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7673 (gnus-info-find-node
7675 (gnus-url-unhex-string
7676 (match-string 1 url))
7678 (or (gnus-url-unhex-string
7679 (match-string 2 url))
7681 (error "Can't parse %s" url)))
7683 (defun gnus-button-handle-info-url-kde (url)
7684 "Fetch KDE style info URL."
7685 (gnus-info-find-node (gnus-url-unhex-string url)))
7687 (defun gnus-button-handle-info-keystrokes (url)
7688 "Call `info' when pushing the corresponding URL button."
7689 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7694 (defun gnus-button-openpgp (url)
7695 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7697 (mm-url-insert-file-contents-external url)
7698 (pgg-snarf-keys-region (point-min) (point-max))
7699 (pgg-display-output-buffer nil nil nil)))
7701 (defun gnus-button-message-id (message-id)
7703 (with-current-buffer gnus-summary-buffer
7704 (gnus-summary-refer-article message-id)))
7706 (defun gnus-button-fetch-group (address &rest ignore)
7707 "Fetch GROUP specified by ADDRESS."
7708 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7710 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7711 ;; for nntp:// and news://
7712 (setq address (match-string 3 address)))
7713 (if (not (string-match "[:/]" address))
7714 ;; This is just a simple group url.
7715 (gnus-group-read-ephemeral-group address gnus-select-method)
7718 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7720 (error "Can't parse %s" address)
7721 (gnus-group-read-ephemeral-group
7722 (match-string 4 address)
7723 `(nntp ,(match-string 1 address)
7724 (nntp-address ,(match-string 1 address))
7725 (nntp-port-number ,(if (match-end 3)
7726 (match-string 3 address)
7729 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7731 (defun gnus-url-parse-query-string (query &optional downcase)
7732 (let (retval pairs cur key val)
7733 (setq pairs (split-string query "&"))
7735 (setq cur (car pairs)
7737 (if (not (string-match "=" cur))
7739 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7740 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7742 (setq key (downcase key)))
7743 (setq cur (assoc key retval))
7745 (setcdr cur (cons val (cdr cur)))
7746 (setq retval (cons (list key val) retval)))))
7749 (defun gnus-url-mailto (url)
7750 ;; Send mail to someone
7751 (when (string-match "mailto:/*\\(.*\\)" url)
7752 (setq url (substring url (match-beginning 1) nil)))
7753 (let (to args subject func)
7754 (setq args (gnus-url-parse-query-string
7755 (if (string-match "^\\?" url)
7757 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7758 (concat "to=" (match-string 1 url) "&"
7759 (match-string 2 url))
7760 (concat "to=" url)))
7762 subject (cdr-safe (assoc "subject" args)))
7765 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7768 (message-position-on-field (caar args)))
7769 (insert (gnus-replace-in-string
7770 (mapconcat 'identity (reverse (cdar args)) ", ")
7772 (setq args (cdr args)))
7775 (message-goto-subject))))
7777 (defun gnus-button-embedded-url (address)
7778 "Activate ADDRESS with `browse-url'."
7779 (browse-url (gnus-strip-whitespace address)))
7781 ;;; Next/prev buttons in the article buffer.
7783 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7784 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7786 (defvar gnus-prev-page-map
7787 (let ((map (make-sparse-keymap)))
7788 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7789 (define-key map "\r" 'gnus-button-prev-page)
7792 (defvar gnus-next-page-map
7793 (let ((map (make-sparse-keymap)))
7794 (unless (>= emacs-major-version 21)
7795 ;; XEmacs doesn't care.
7796 (set-keymap-parent map gnus-article-mode-map))
7797 (define-key map gnus-mouse-2 'gnus-button-next-page)
7798 (define-key map "\r" 'gnus-button-next-page)
7801 (defun gnus-insert-prev-page-button ()
7803 (inhibit-read-only t))
7805 gnus-prev-page-line-format nil
7806 `(keymap ,gnus-prev-page-map
7808 gnus-callback gnus-article-button-prev-page
7809 article-type annotation))
7811 ;; Exclude a newline.
7814 (when gnus-article-button-face
7815 (gnus-overlay-put (gnus-make-overlay b e nil t)
7816 'face gnus-article-button-face))
7817 (widget-convert-button
7819 :action 'gnus-button-prev-page
7820 :button-keymap gnus-prev-page-map)))
7822 (defun gnus-button-next-page (&optional args more-args)
7823 "Go to the next page."
7825 (let ((win (selected-window)))
7826 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7827 (gnus-article-next-page)
7828 (select-window win)))
7830 (defun gnus-button-prev-page (&optional args more-args)
7831 "Go to the prev page."
7833 (let ((win (selected-window)))
7834 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7835 (gnus-article-prev-page)
7836 (select-window win)))
7838 (defun gnus-insert-next-page-button ()
7840 (inhibit-read-only t))
7841 (gnus-eval-format gnus-next-page-line-format nil
7842 `(keymap ,gnus-next-page-map
7844 gnus-callback gnus-article-button-next-page
7845 article-type annotation))
7847 ;; Exclude a newline.
7850 (when gnus-article-button-face
7851 (gnus-overlay-put (gnus-make-overlay b e nil t)
7852 'face gnus-article-button-face))
7853 (widget-convert-button
7855 :action 'gnus-button-next-page
7856 :button-keymap gnus-next-page-map)))
7858 (defun gnus-article-button-next-page (arg)
7859 "Go to the next page."
7861 (let ((win (selected-window)))
7862 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7863 (gnus-article-next-page)
7864 (select-window win)))
7866 (defun gnus-article-button-prev-page (arg)
7867 "Go to the prev page."
7869 (let ((win (selected-window)))
7870 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7871 (gnus-article-prev-page)
7872 (select-window win)))
7874 (defvar gnus-decode-header-methods
7875 '(mail-decode-encoded-word-region)
7876 "List of methods used to decode headers.
7878 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7879 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7880 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7881 whose names match REGEXP.
7884 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7885 mail-decode-encoded-word-region
7886 (\"chinese\" . rfc1843-decode-region))
7889 (defvar gnus-decode-header-methods-cache nil)
7891 (defun gnus-multi-decode-header (start end)
7892 "Apply the functions from `gnus-encoded-word-methods' that match."
7893 (unless (and gnus-decode-header-methods-cache
7894 (eq gnus-newsgroup-name
7895 (car gnus-decode-header-methods-cache)))
7896 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7897 (dolist (x gnus-decode-header-methods)
7899 (nconc gnus-decode-header-methods-cache (list x))
7900 (if (and gnus-newsgroup-name
7901 (string-match (car x) gnus-newsgroup-name))
7902 (nconc gnus-decode-header-methods-cache
7904 (let ((xlist gnus-decode-header-methods-cache))
7907 (narrow-to-region start end)
7909 (funcall (pop xlist) (point-min) (point-max))))))
7912 ;;; Treatment top-level handling.
7915 (defun gnus-treat-article (condition &optional part-number total-parts type)
7916 (let ((length (- (point-max) (point-min)))
7917 (alist gnus-treatment-function-alist)
7918 (article-goto-body-goes-to-point-min-p t)
7922 (let ((list gnus-article-treat-types))
7924 (when (string-match (pop list) type)
7925 (throw 'found t)))))))
7926 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7928 (gnus-run-hooks 'gnus-part-display-hook)
7929 (dolist (elem alist)
7932 (when (gnus-buffer-live-p gnus-summary-buffer)
7933 (set-buffer gnus-summary-buffer))
7934 (symbol-value (car elem))))
7935 (when (and (or (consp val)
7937 (gnus-treat-predicate val)
7938 (or (not (get (car elem) 'highlight))
7941 (funcall (cadr elem)))))))
7943 ;; Dynamic variables.
7945 (defvar part-number)
7946 (defvar total-parts)
7951 (defun gnus-treat-predicate (val)
7958 (stringp (car val)))
7959 (apply 'gnus-or (mapcar `(lambda (s)
7960 (string-match s ,(or gnus-newsgroup-name "")))
7963 (let ((pred (pop val)))
7966 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7968 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7970 (not (gnus-treat-predicate (car val))))
7972 (equal (car val) type))
7974 (error "%S is not a valid predicate" pred)))))
7982 (eq part-number total-parts))
7986 (error "%S is not a valid value" val))))
7988 (defun gnus-article-encrypt-body (protocol &optional n)
7989 "Encrypt the article body."
7992 (or gnus-article-encrypt-protocol
7993 (completing-read "Encrypt protocol: "
7994 gnus-article-encrypt-protocol-alist
7996 current-prefix-arg))
7997 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7999 (error "Can't find the encrypt protocol %s" protocol))
8000 (if (member gnus-newsgroup-name '("nndraft:delayed"
8003 (error "Can't encrypt the article in group %s"
8004 gnus-newsgroup-name))
8005 (gnus-summary-iterate n
8007 (set-buffer gnus-summary-buffer)
8008 (let ((mail-parse-charset gnus-newsgroup-charset)
8009 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8010 (summary-buffer gnus-summary-buffer)
8012 (gnus-set-global-variables)
8013 (when (gnus-group-read-only-p)
8014 (error "The current newsgroup does not support article encrypt"))
8015 (gnus-summary-show-article t)
8017 (or (mail-header-references gnus-current-headers) ""))
8018 (set-buffer gnus-article-buffer)
8019 (let* ((inhibit-read-only t)
8021 (mapcar (lambda (field)
8022 (and (save-restriction
8023 (message-narrow-to-head)
8024 (goto-char (point-min))
8025 (search-forward field nil t))
8027 (message-narrow-to-field)
8029 (delete-region (point-min) (point-max))
8031 '("Content-Type:" "Content-Transfer-Encoding:"
8032 "Content-Disposition:"))))
8033 (message-narrow-to-head)
8034 (message-remove-header "MIME-Version")
8035 (goto-char (point-max))
8036 (setq point (point))
8037 (insert (apply 'concat headers))
8039 (narrow-to-region point (point-max))
8040 (let ((message-options message-options))
8041 (message-options-set 'message-sender user-mail-address)
8042 (message-options-set 'message-recipients user-mail-address)
8043 (message-options-set 'message-sign-encrypt 'not)
8045 (goto-char (point-min))
8046 (insert "MIME-Version: 1.0\n")
8048 (gnus-summary-edit-article-done
8049 references nil summary-buffer t))
8050 (when gnus-keep-backlog
8051 (gnus-backlog-remove-article
8052 (car gnus-article-current) (cdr gnus-article-current)))
8054 (when (get-buffer gnus-original-article-buffer)
8055 (set-buffer gnus-original-article-buffer)
8056 (setq gnus-original-article nil)))
8057 (when gnus-use-cache
8058 (gnus-cache-update-article
8059 (car gnus-article-current) (cdr gnus-article-current))))))))
8061 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8062 "The following specs can be used:
8063 %t The security MIME type
8066 %D Details if button is pressed")
8068 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8069 "The following specs can be used:
8070 %t The security MIME type
8073 %D Details if button is pressed")
8075 (defvar gnus-mime-security-button-line-format-alist
8076 '((?t gnus-tmp-type ?s)
8077 (?i gnus-tmp-info ?s)
8078 (?d gnus-tmp-details ?s)
8079 (?D gnus-tmp-pressed-details ?s)))
8081 (defvar gnus-mime-security-button-commands
8082 '((gnus-article-press-button "\r" "Show Detail")
8086 (gnus-mime-security-save-part "o" "Save...")
8095 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8098 (defvar gnus-mime-security-button-map
8099 (let ((map (make-sparse-keymap)))
8100 (define-key map gnus-mouse-2 'gnus-article-push-button)
8101 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8102 (dolist (c gnus-mime-security-button-commands)
8103 (define-key map (cadr c) (car c)))
8107 gnus-mime-security-button-menu gnus-mime-security-button-map
8108 "Security button menu."
8112 (unless (eq (car c) 'undefined)
8113 (vector (caddr c) (car c) :active t)))
8114 gnus-mime-security-button-commands))))
8116 (defun gnus-mime-security-button-menu (event prefix)
8117 "Construct a context-sensitive menu of security commands."
8118 (interactive "e\nP")
8119 (save-window-excursion
8120 (let ((pos (event-start event)))
8121 (select-window (posn-window pos))
8122 (goto-char (posn-point pos))
8123 (gnus-article-check-buffer)
8124 (popup-menu gnus-mime-security-button-menu nil prefix))))
8126 (defvar gnus-mime-security-details-buffer nil)
8128 (defvar gnus-mime-security-button-pressed nil)
8130 (defvar gnus-mime-security-show-details-inline t
8131 "If non-nil, show details in the article buffer.")
8133 (defun gnus-mime-security-verify-or-decrypt (handle)
8134 (mm-remove-parts (cdr handle))
8135 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8136 point (inhibit-read-only t))
8138 (goto-char (car region)))
8139 (setq point (point))
8140 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8141 (let* ((mm-verify-option 'known)
8142 (mm-decrypt-option 'known)
8143 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8144 (unless (eq nparts (cdr handle))
8145 (mm-destroy-parts (cdr handle))
8146 (setcdr handle nparts))))
8147 (gnus-mime-display-security handle)
8149 (delete-region (point) (cdr region))
8150 (set-marker (car region) nil)
8151 (set-marker (cdr region) nil))
8154 (defun gnus-mime-security-show-details (handle)
8155 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8157 (gnus-message 5 "No details.")
8158 (if gnus-mime-security-show-details-inline
8159 (let ((gnus-mime-security-button-pressed
8160 (not (get-text-property (point) 'gnus-mime-details)))
8161 (gnus-mime-security-button-line-format
8162 (get-text-property (point) 'gnus-line-format))
8163 (inhibit-read-only t))
8165 (while (eq (get-text-property (point) 'gnus-line-format)
8166 gnus-mime-security-button-line-format)
8170 (narrow-to-region (point) (point))
8171 (gnus-insert-mime-security-button handle))
8172 (delete-region (point)
8173 (or (text-property-not-all
8176 gnus-mime-security-button-line-format)
8179 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8180 (with-current-buffer gnus-mime-security-details-buffer
8183 (setq gnus-mime-security-details-buffer
8184 (gnus-get-buffer-create "*MIME Security Details*")))
8185 (with-current-buffer gnus-mime-security-details-buffer
8187 (goto-char (point-min)))
8188 (pop-to-buffer gnus-mime-security-details-buffer)))))
8190 (defun gnus-mime-security-press-button (handle)
8192 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8193 (gnus-mime-security-show-details handle)
8194 (gnus-mime-security-verify-or-decrypt handle))))
8196 (defun gnus-insert-mime-security-button (handle &optional displayed)
8197 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8200 (or (nth 2 (assoc protocol mm-verify-function-alist))
8201 (nth 2 (assoc protocol mm-decrypt-function-alist))
8203 (if (equal (car handle) "multipart/signed")
8204 " Signed" " Encrypted")
8207 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8210 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8211 gnus-tmp-pressed-details
8213 (setq gnus-tmp-details
8214 (if gnus-tmp-details
8215 (concat "\n" gnus-tmp-details)
8217 (setq gnus-tmp-pressed-details
8218 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8223 gnus-mime-security-button-line-format
8224 gnus-mime-security-button-line-format-alist
8225 `(keymap ,gnus-mime-security-button-map
8226 gnus-callback gnus-mime-security-press-button
8227 gnus-line-format ,gnus-mime-security-button-line-format
8228 gnus-mime-details ,gnus-mime-security-button-pressed
8229 article-type annotation
8232 ;; Exclude a newline.
8235 (when gnus-article-button-face
8236 (gnus-overlay-put (gnus-make-overlay b e nil t)
8237 'face gnus-article-button-face))
8238 (widget-convert-button
8241 :action 'gnus-widget-press-button
8242 :button-keymap gnus-mime-security-button-map
8244 (lambda (widget/window &optional overlay pos)
8245 ;; Needed to properly clear the message due to a bug in
8246 ;; wid-edit (XEmacs only).
8247 (when (boundp 'help-echo-owns-message)
8248 (setq help-echo-owns-message t))
8250 "%S: show detail; %S: more options"
8251 (aref gnus-mouse-2 0)
8252 (aref gnus-down-mouse-3 0))))))
8254 (defun gnus-mime-display-security (handle)
8256 (narrow-to-region (point) (point))
8257 (unless (gnus-unbuttonized-mime-type-p (car handle))
8258 (gnus-insert-mime-security-button handle))
8259 (gnus-mime-display-part (cadr handle))
8262 (unless (gnus-unbuttonized-mime-type-p (car handle))
8263 (let ((gnus-mime-security-button-line-format
8264 gnus-mime-security-button-end-line-format))
8265 (gnus-insert-mime-security-button handle)))
8266 (mm-set-handle-multipart-parameter
8268 (cons (set-marker (make-marker) (point-min))
8269 (set-marker (make-marker) (point-max))))
8270 (goto-char (point-max))))
8272 (defun gnus-mime-security-run-function (function)
8273 "Run FUNCTION with the security part under point."
8274 (gnus-article-check-buffer)
8275 (let ((data (get-text-property (point) 'gnus-data))
8277 (when (and (stringp (car-safe data))
8278 (setq buffer (mm-handle-multipart-original-buffer data))
8279 (setq handle (cadr data)))
8280 (if (bufferp (mm-handle-buffer handle))
8282 (setq handle (cons buffer (copy-sequence (cdr handle))))
8283 (mm-handle-set-undisplayer handle nil))
8284 (setq handle (mm-make-handle
8286 (mm-handle-multipart-ctl-parameter handle 'protocol)
8287 nil nil nil nil nil nil)))
8288 (funcall function handle))))
8290 (defun gnus-mime-security-save-part ()
8291 "Save the security part under point."
8293 (gnus-mime-security-run-function 'mm-save-part))
8295 (defun gnus-mime-security-pipe-part ()
8296 "Pipe the security part under point to a process."
8298 (gnus-mime-security-run-function 'mm-pipe-part))
8304 (run-hooks 'gnus-art-load-hook)
8306 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8307 ;;; gnus-art.el ends here