1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; For Emacs <22.2 and XEmacs.
29 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
33 (defvar w3m-minor-mode-map)
49 (autoload 'gnus-msg-mail "gnus-msg" nil t)
50 (autoload 'gnus-button-mailto "gnus-msg")
51 (autoload 'gnus-button-reply "gnus-msg" nil t)
52 (autoload 'parse-time-string "parse-time" nil nil)
53 (autoload 'ansi-color-apply-on-region "ansi-color")
54 (autoload 'mm-url-insert-file-contents-external "mm-url")
55 (autoload 'mm-extern-cache-contents "mm-extern")
57 (defgroup gnus-article nil
59 :link '(custom-manual "(gnus)Article Buffer")
62 (defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
67 (defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
72 (defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
78 (defgroup gnus-article-signature nil
80 :link '(custom-manual "(gnus)Article Signature")
83 (defgroup gnus-article-headers nil
85 :link '(custom-manual "(gnus)Hiding Headers")
88 (defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
93 (defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
98 (defgroup gnus-article-saving nil
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
103 (defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
108 (defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
113 (defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
118 (defcustom gnus-ignored-headers
121 (concat "^" header ":"))
122 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128 "X-Attribution" "X-Originating-IP" "Delivered-To"
129 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145 "List-[A-Za-z]+" "X-Listprocessor-Version"
146 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148 "X-Received" "Content-length" "X-precedence"
149 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154 "X-Content-length" "X-Posting-Agent" "Original-Received"
155 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
159 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
160 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
161 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
162 "Envelope-Sender" "Envelope-Recipients"))
163 "*All headers that start with this regexp will be hidden.
164 This variable can also be a list of regexps of headers to be ignored.
165 If `gnus-visible-headers' is non-nil, this variable will be ignored."
166 :type '(choice regexp
168 :group 'gnus-article-hiding)
170 (defcustom gnus-visible-headers
171 "^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:"
172 "*All headers that do not match this regexp will be hidden.
173 This variable can also be a list of regexp of headers to remain visible.
174 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
176 (repeat :value-to-internal (lambda (widget value)
177 (custom-split-regexp-maybe value))
178 :match (lambda (widget value)
180 (widget-editable-list-match widget value)))
182 (const :tag "Use gnus-ignored-headers" nil)
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
272 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
273 ; uncompface; } | icontopbm | ee -")
274 (if (gnus-image-type-available-p 'pbm)
275 'gnus-display-x-face-in-from
277 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
278 ; uncompface; } | icontopbm | display -"))
279 "*String or function to be executed to display an X-Face header.
280 If it is a string, the command will be executed in a sub-shell
281 asynchronously. The compressed face will be piped to this command."
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
291 :type '(choice regexp (const nil))
292 :group 'gnus-article-washing)
294 (defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
302 (gnus-define-group-parameter
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
308 '(choice :tag "Banner"
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
313 (const :tag "None" nil))
315 "If non-nil, specify how to remove `banners' from articles.
317 Symbol `signature' means to remove signatures delimited by
318 `gnus-signature-separator'. Any other symbol is used to look up a
319 regular expression to match the banner in `gnus-article-banner-alist'.
320 A string is used as a regular expression to match the banner
323 (defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326 to match a mail address in the From: header, BANNER is one of a symbol
327 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
328 If ADDRESS matches author's mail address, it will remove things like
329 advertisements. For example:
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
340 (const :tag "None" nil))))
342 :group 'gnus-article-washing)
344 (defmacro gnus-emphasis-custom-with-format (&rest body)
346 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
350 (defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
355 (if (nth 1 value) 2 3)
359 (defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
372 (defcustom gnus-emphasis-alist
374 '(("\\*" "\\*" bold nil 2)
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
397 "*Alist that says how to fontify certain phrases.
398 Each item looks like this:
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
402 The first element is a regular expression to be matched. The second
403 is a number that says what regular expression grouping used to find
404 the entire emphasized word. The third is a number that says what
405 regexp grouping should be displayed and highlighted. The fourth
406 is the face used for highlighting."
410 :format "%[Customizing Style%]\n%v"
412 (group :tag "Default"
413 :value ("" 0 0 default)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
420 (if (not (eq (nth 2 value) 'default))
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
427 (integer :format "Match group: %v")
428 (integer :format "Emphasize group: %v")
431 :value (("_" . "_") nil default)
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
444 :group 'gnus-article-emphasis)
446 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449 The former avoids underlining of leading and trailing whitespace,
450 and the latter avoids underlining any whitespace at all."
452 :group 'gnus-article-emphasis
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
472 "Face used for displaying underlined italic emphasized text (_/word/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline-bold-italic
480 '((t (:bold t :italic t :underline t)))
481 "Face used for displaying underlined bold italic emphasized text.
482 Example: (_/*word*/_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
486 '((t (:strikethru t)))
487 '((t (:strike-through t))))
488 "Face used for displaying strike-through text (-word-)."
489 :group 'gnus-article-emphasis)
491 (defface gnus-emphasis-highlight-words
492 '((t (:background "black" :foreground "yellow")))
493 "Face used for displaying highlighted words."
494 :group 'gnus-article-emphasis)
496 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
497 "Format for display of Date headers in article bodies.
498 See `format-time-string' for the possible values.
500 The variable can also be function, which should return a complete Date
501 header. The function is called with one argument, the time, which can
502 be fed to `format-time-string'."
503 :type '(choice string function)
504 :link '(custom-manual "(gnus)Article Date")
505 :group 'gnus-article-washing)
507 (defcustom gnus-save-all-headers t
508 "*If non-nil, don't remove any headers before saving.
509 This will be overridden by the `:headers' property that the symbol of
510 the saver function, which is specified by `gnus-default-article-saver',
512 :group 'gnus-article-saving
515 (defcustom gnus-prompt-before-saving 'always
516 "*This variable says how much prompting is to be done when saving articles.
517 If it is nil, no prompting will be done, and the articles will be
518 saved to the default files. If this variable is `always', each and
519 every article that is saved will be preceded by a prompt, even when
520 saving large batches of articles. If this variable is neither nil not
521 `always', there the user will be prompted once for a file name for
522 each invocation of the saving commands."
523 :group 'gnus-article-saving
524 :type '(choice (item always)
525 (item :tag "never" nil)
526 (sexp :tag "once" :format "%t\n" :value t)))
528 (defcustom gnus-saved-headers gnus-visible-headers
529 "Headers to keep if `gnus-save-all-headers' is nil.
530 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
531 If that variable is nil, however, all headers that match this regexp
532 will be kept while the rest will be deleted before saving. This and
533 `gnus-save-all-headers' will be overridden by the `:headers' property
534 that the symbol of the saver function, which is specified by
535 `gnus-default-article-saver', might have."
536 :group 'gnus-article-saving
539 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
540 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
541 "A function to save articles in your favorite format.
542 The function will be called by way of the `gnus-summary-save-article'
543 command, and friends such as `gnus-summary-save-article-rmail'.
545 Gnus provides the following functions:
547 * gnus-summary-save-in-rmail (Rmail format)
548 * gnus-summary-save-in-mail (Unix mail format)
549 * gnus-summary-save-in-folder (MH folder)
550 * gnus-summary-save-in-file (article format)
551 * gnus-summary-save-body-in-file (article body)
552 * gnus-summary-save-in-vm (use VM's folder format)
553 * gnus-summary-write-to-file (article format -- overwrite)
554 * gnus-summary-write-body-to-file (article body -- overwrite)
555 * gnus-summary-save-in-pipe (article format)
557 The symbol of each function may have the following properties:
560 The value non-nil means save decoded articles. This is meaningful
561 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
562 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
563 `gnus-summary-save-in-pipe'.
566 The value specifies an alternative function which appends, not
567 overwrites, articles to a file. This implies that when saving many
568 articles at a time, `gnus-prompt-before-saving' is bound to t and all
569 articles are saved in a single file. This is meaningful only with
570 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
573 The value specifies the symbol of a variable of which the value
574 specifies headers to be saved. If it is omitted,
575 `gnus-save-all-headers' and `gnus-saved-headers' control what
576 headers should be saved."
577 :group 'gnus-article-saving
578 :type '(radio (function-item gnus-summary-save-in-rmail)
579 (function-item gnus-summary-save-in-mail)
580 (function-item gnus-summary-save-in-folder)
581 (function-item gnus-summary-save-in-file)
582 (function-item gnus-summary-save-body-in-file)
583 (function-item gnus-summary-save-in-vm)
584 (function-item gnus-summary-write-to-file)
585 (function-item gnus-summary-write-body-to-file)
586 (function-item gnus-summary-save-in-pipe)
589 (defcustom gnus-article-save-coding-system
590 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
591 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
592 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
593 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
594 "Coding system used to save decoded articles to a file.
596 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
597 which can safely encode any characters in text. This is used by the
600 * gnus-summary-save-article-file
601 * gnus-summary-save-article-body-file
602 * gnus-summary-write-article-file
603 * gnus-summary-write-article-body-file
605 and the functions to which you may set `gnus-default-article-saver':
607 * gnus-summary-save-in-file
608 * gnus-summary-save-body-in-file
609 * gnus-summary-write-to-file
610 * gnus-summary-write-body-to-file
612 Those commands and functions save just text displayed in the article
613 buffer to a file if the value of this variable is non-nil. Note that
614 buttonized MIME parts will be lost in a saved file in that case.
615 Otherwise, raw articles will be saved."
616 :group 'gnus-article-saving
618 :format "%{%t%}:\n %[Value Menu%] %v"
619 (const :tag "Save raw articles" nil)
622 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
623 '((const :tag "UTF-8" utf-8)
624 (const :tag "iso-2022-7bit" iso-2022-7bit)
625 (const :tag "Emacs internal" emacs-mule)
626 (const :tag "escape-quoted" escape-quoted))))
627 (symbol :tag "Coding system")))
629 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
630 "A function generating a file name to save articles in Rmail format.
631 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
632 :group 'gnus-article-saving
635 (defcustom gnus-mail-save-name 'gnus-plain-save-name
636 "A function generating a file name to save articles in Unix mail format.
637 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
638 :group 'gnus-article-saving
641 (defcustom gnus-folder-save-name 'gnus-folder-save-name
642 "A function generating a file name to save articles in MH folder.
643 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
644 :group 'gnus-article-saving
647 (defcustom gnus-file-save-name 'gnus-numeric-save-name
648 "A function generating a file name to save articles in article format.
649 The function is called with NEWSGROUP, HEADERS, and optional
651 :group 'gnus-article-saving
654 (defcustom gnus-split-methods
655 '((gnus-article-archive-name)
656 (gnus-article-nndoc-name))
657 "*Variable used to suggest where articles are to be saved.
658 For instance, if you would like to save articles related to Gnus in
659 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
660 you could set this variable to something like:
662 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
663 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
665 This variable is an alist where the key is the match and the
666 value is a list of possible files to save in if the match is
669 If the match is a string, it is used as a regexp match on the
670 article. If the match is a symbol, that symbol will be funcalled
671 from the buffer of the article to be saved with the newsgroup as the
672 parameter. If it is a list, it will be evalled in the same buffer.
674 If this form or function returns a string, this string will be used as a
675 possible file name; and if it returns a non-nil list, that list will be
676 used as possible file names."
677 :group 'gnus-article-saving
678 :type '(repeat (choice (list :value (fun) function)
679 (cons :value ("" "") regexp (repeat string))
682 (defcustom gnus-page-delimiter "^\^L"
683 "*Regexp describing what to use as article page delimiters.
684 The default value is \"^\^L\", which is a form linefeed at the
685 beginning of a line."
687 :group 'gnus-article-various)
689 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
690 "*The format specification for the article mode line.
691 See `gnus-summary-mode-line-format' for a closer description.
693 The following additional specs are available:
695 %w The article washing status.
696 %m The number of MIME parts in the article."
699 :group 'gnus-article-various)
701 (defcustom gnus-article-mode-hook nil
702 "*A hook for Gnus article mode."
704 :group 'gnus-article-various)
706 (when (featurep 'xemacs)
707 ;; Extracted from gnus-xmas-define in order to preserve user settings
708 (when (fboundp 'turn-off-scroll-in-place)
709 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
710 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
711 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
713 (defcustom gnus-article-menu-hook nil
714 "*Hook run after the creation of the article mode menu."
716 :group 'gnus-article-various)
718 (defcustom gnus-article-prepare-hook nil
719 "*A hook called after an article has been prepared in the article buffer."
721 :group 'gnus-article-various)
723 (defcustom gnus-copy-article-ignored-headers nil
724 "List of headers to be removed when copying an article.
725 Each element is a regular expression."
726 :version "23.1" ;; No Gnus
727 :type '(repeat regexp)
728 :group 'gnus-article-various)
730 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
731 "Gnus 5.10 (Emacs 22.1)")
734 '((t (:weight bold)))
735 "Face used for highlighting a button in the article buffer."
736 :group 'gnus-article-buttons)
738 (defcustom gnus-article-button-face 'gnus-button
739 "Face used for highlighting buttons in the article buffer.
741 An article button is a piece of text that you can activate by pressing
742 `RET' or `mouse-2' above it."
744 :group 'gnus-article-buttons)
746 (defcustom gnus-article-mouse-face 'highlight
747 "Face used for mouse highlighting in the article buffer.
749 Article buttons will be displayed in this face when the cursor is
752 :group 'gnus-article-buttons)
754 (defcustom gnus-signature-face 'gnus-signature
755 "Face used for highlighting a signature in the article buffer.
756 Obsolete; use the face `gnus-signature' for customizations instead."
758 :group 'gnus-article-highlight
759 :group 'gnus-article-signature)
761 (defface gnus-signature
764 "Face used for highlighting a signature in the article buffer."
765 :group 'gnus-article-highlight
766 :group 'gnus-article-signature)
767 ;; backward-compatibility alias
768 (put 'gnus-signature-face 'face-alias 'gnus-signature)
769 (put 'gnus-signature-face 'obsolete-face "22.1")
771 (defface gnus-header-from
774 (:foreground "PaleGreen1"))
777 (:foreground "red3"))
780 "Face used for displaying from headers."
781 :group 'gnus-article-headers
782 :group 'gnus-article-highlight)
783 ;; backward-compatibility alias
784 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
785 (put 'gnus-header-from-face 'obsolete-face "22.1")
787 (defface gnus-header-subject
790 (:foreground "SeaGreen1"))
793 (:foreground "red4"))
795 (:bold t :italic t)))
796 "Face used for displaying subject headers."
797 :group 'gnus-article-headers
798 :group 'gnus-article-highlight)
799 ;; backward-compatibility alias
800 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
801 (put 'gnus-header-subject-face 'obsolete-face "22.1")
803 (defface gnus-header-newsgroups
806 (:foreground "yellow" :italic t))
809 (:foreground "MidnightBlue" :italic t))
812 "Face used for displaying newsgroups headers.
813 In the default setup this face is only used for crossposted
815 :group 'gnus-article-headers
816 :group 'gnus-article-highlight)
817 ;; backward-compatibility alias
818 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
819 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
821 (defface gnus-header-name
824 (:foreground "SpringGreen2"))
827 (:foreground "maroon"))
830 "Face used for displaying header names."
831 :group 'gnus-article-headers
832 :group 'gnus-article-highlight)
833 ;; backward-compatibility alias
834 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
835 (put 'gnus-header-name-face 'obsolete-face "22.1")
837 (defface gnus-header-content
840 (:foreground "SpringGreen1" :italic t))
843 (:foreground "indianred4" :italic t))
845 (:italic t))) "Face used for displaying header content."
846 :group 'gnus-article-headers
847 :group 'gnus-article-highlight)
848 ;; backward-compatibility alias
849 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
850 (put 'gnus-header-content-face 'obsolete-face "22.1")
852 (defcustom gnus-header-face-alist
853 '(("From" nil gnus-header-from)
854 ("Subject" nil gnus-header-subject)
855 ("Newsgroups:.*," nil gnus-header-newsgroups)
856 ("" gnus-header-name gnus-header-content))
857 "*Controls highlighting of article headers.
859 An alist of the form (HEADER NAME CONTENT).
861 HEADER is a regular expression which should match the name of a
862 header and NAME and CONTENT are either face names or nil.
864 The name of each header field will be displayed using the face
865 specified by the first element in the list where HEADER matches
866 the header name and NAME is non-nil. Similarly, the content will
867 be displayed by the first non-nil matching CONTENT face."
868 :group 'gnus-article-headers
869 :group 'gnus-article-highlight
870 :type '(repeat (list (regexp :tag "Header")
872 (item :tag "skip" nil)
873 (face :value default))
874 (choice :tag "Content"
875 (item :tag "skip" nil)
876 (face :value default)))))
878 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
879 '((xface . (:face gnus-x-face)))
880 '((pbm . (:face gnus-x-face))
882 "Alist of image types and properties applied to Face and X-Face images.
885 ;; Specify the altitude of Face images in the From header.
886 \(setq gnus-face-properties-alist
887 '((pbm . (:face gnus-x-face :ascent 80))
888 (png . (:ascent 80))))
890 ;; Show Face images as pressed buttons.
891 \(setq gnus-face-properties-alist
892 '((pbm . (:face gnus-x-face :relief -2))
893 (png . (:relief -2))))
895 See the manual for the valid properties for various image types.
896 Currently, `pbm' is used for X-Face images and `png' is used for Face
897 images in Emacs. Only the `:face' property is effective on the `xface'
898 image type in XEmacs if it is built with the libcompface library."
899 :version "23.1" ;; No Gnus
900 :group 'gnus-article-headers
901 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
903 (defcustom gnus-article-decode-hook
904 '(article-decode-charset article-decode-encoded-words
905 article-decode-group-name article-decode-idna-rhs)
906 "*Hook run to decode charsets in articles."
907 :group 'gnus-article-headers
910 (defcustom gnus-display-mime-function 'gnus-display-mime
911 "Function to display MIME articles."
912 :group 'gnus-article-mime
915 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
916 "Function used to decode headers.")
918 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
919 "Function used to decode addresses.")
921 (defvar gnus-article-dumbquotes-map
941 "Table for MS-to-Latin1 translation.")
943 (defcustom gnus-ignored-mime-types nil
944 "List of MIME types that should be ignored by Gnus."
946 :group 'gnus-article-mime
947 :type '(repeat regexp))
949 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
950 "List of MIME types that should not be given buttons when rendered inline.
951 See also `gnus-buttonized-mime-types' which may override this variable.
952 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
954 :group 'gnus-article-mime
955 :type '(repeat regexp))
957 (defcustom gnus-buttonized-mime-types nil
958 "List of MIME types that should be given buttons when rendered inline.
959 If set, this variable overrides `gnus-unbuttonized-mime-types'.
960 To see e.g. security buttons you could set this to
961 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
962 this list to display radio buttons that allow you to choose one of two
963 media types those mails include. See also `mm-discouraged-alternatives'.
964 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
966 :group 'gnus-article-mime
967 :type '(repeat regexp))
969 (defcustom gnus-inhibit-mime-unbuttonizing nil
970 "If non-nil, all MIME parts get buttons.
971 When nil (the default value), then some MIME parts do not get buttons,
972 as described by the variables `gnus-buttonized-mime-types' and
973 `gnus-unbuttonized-mime-types'."
975 :group 'gnus-article-mime
978 (defcustom gnus-body-boundary-delimiter "_"
979 "String used to delimit header and body.
980 This variable is used by `gnus-article-treat-body-boundary' which can
981 be controlled by `gnus-treat-body-boundary'."
983 :group 'gnus-article-various
984 :type '(choice (item :tag "None" :value nil)
987 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
989 "Defines the location of the faces database.
990 For information on obtaining this database of pretty pictures, please
991 see http://www.cs.indiana.edu/picons/ftp/index.html"
993 :type '(repeat directory)
994 :link '(url-link :tag "download"
995 "http://www.cs.indiana.edu/picons/ftp/index.html")
996 :link '(custom-manual "(gnus)Picons")
999 (defun gnus-picons-installed-p ()
1000 "Say whether picons are installed on your machine."
1001 (let ((installed nil))
1002 (dolist (database gnus-picon-databases)
1003 (when (file-exists-p database)
1004 (setq installed t)))
1007 (defcustom gnus-article-mime-part-function nil
1008 "Function called with a MIME handle as the argument.
1009 This is meant for people who want to do something automatic based
1010 on parts -- for instance, adding Vcard info to a database."
1011 :group 'gnus-article-mime
1012 :type '(choice (const nil)
1015 (defcustom gnus-mime-multipart-functions nil
1016 "An alist of MIME types to functions to display them."
1018 :group 'gnus-article-mime
1019 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1021 (defcustom gnus-article-date-headers '(combined-lapsed)
1022 "A list of Date header formats to display.
1023 Valid formats are `ut' (universal time), `local' (local time
1024 zone), `english' (readable English), `lapsed' (elapsed time),
1025 `combined-lapsed' (both the original date and the elapsed time),
1026 `original' (the original date header), `iso8601' (ISO8601
1027 format), and `user-defined' (a user-defined format defined by the
1028 `gnus-article-time-format' variable).
1030 You have as many date headers as you want in the article buffer.
1031 Some of these headers are updated automatically. See
1032 `gnus-article-update-date-headers' for details."
1034 :group 'gnus-article-headers
1036 (item :tag "Universal time (UT)" :value 'ut)
1037 (item :tag "Local time zone" :value 'local)
1038 (item :tag "Readable English" :value 'english)
1039 (item :tag "Elapsed time" :value 'lapsed)
1040 (item :tag "Original and elapsed time" :value 'combined-lapsed)
1041 (item :tag "Original date header" :value 'original)
1042 (item :tag "ISO8601 format" :value 'iso8601)
1043 (item :tag "User-defined" :value 'user-defined)))
1045 (defcustom gnus-article-update-date-headers nil
1046 "A number that says how often to update the date header (in seconds).
1047 If nil, don't update it at all."
1049 :group 'gnus-article-headers
1051 (item :tag "Don't update" :value nil)
1054 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1055 "Function called with a MIME handle as the argument.
1056 This is meant for people who want to view first matched part.
1057 For `undisplayed-alternative' (default), the first undisplayed
1058 part or alternative part is used. For `undisplayed', the first
1059 undisplayed part is used. For a function, the first part which
1060 the function return t is used. For nil, the first part is
1063 :group 'gnus-article-mime
1065 (item :tag "first" :value nil)
1066 (item :tag "undisplayed" :value undisplayed)
1067 (item :tag "undisplayed or alternative"
1068 :value undisplayed-alternative)
1071 (defcustom gnus-mime-action-alist
1072 '(("save to file" . gnus-mime-save-part)
1073 ("save and strip" . gnus-mime-save-part-and-strip)
1074 ("replace with file" . gnus-mime-replace-part)
1075 ("delete part" . gnus-mime-delete-part)
1076 ("display as text" . gnus-mime-inline-part)
1077 ("view the part" . gnus-mime-view-part)
1078 ("pipe to command" . gnus-mime-pipe-part)
1079 ("toggle display" . gnus-article-press-button)
1080 ("toggle display" . gnus-article-view-part-as-charset)
1081 ("view as type" . gnus-mime-view-part-as-type)
1082 ("view internally" . gnus-mime-view-part-internally)
1083 ("view externally" . gnus-mime-view-part-externally))
1084 "An alist of actions that run on the MIME attachment."
1085 :group 'gnus-article-mime
1086 :type '(repeat (cons (string :tag "name")
1089 (defcustom gnus-auto-select-part 1
1090 "Advance to next MIME part when deleting or stripping parts.
1092 When 0, point will be placed on the same part as before. When
1093 positive (negative), move point forward (backwards) this many
1094 parts. When nil, redisplay article."
1095 :version "23.1" ;; No Gnus
1096 :group 'gnus-article-mime
1097 :type '(choice (const nil :tag "Redisplay article.")
1098 (const 1 :tag "Next part.")
1099 (const 0 :tag "Current part.")
1103 ;;; The treatment variables
1106 (defvar gnus-part-display-hook nil
1107 "Hook called on parts that are to receive treatment.")
1109 (defvar gnus-article-treat-custom
1110 '(choice (const :tag "Off" nil)
1112 (const :tag "Header" head)
1113 (const :tag "First" first)
1114 (const :tag "Last" last)
1115 (integer :tag "Less")
1116 (repeat :tag "Groups" regexp)
1117 (sexp :tag "Predicate")))
1119 (defvar gnus-article-treat-head-custom
1120 '(choice (const :tag "Off" nil)
1121 (const :tag "Header" head)))
1123 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1127 (defvar gnus-inhibit-treatment nil
1128 "Whether to inhibit treatment.")
1130 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1131 "Highlight the signature.
1132 Valid values are nil, t, `head', `first', `last', an integer or a
1133 predicate. See Info node `(gnus)Customizing Articles'."
1134 :group 'gnus-article-treat
1135 :link '(custom-manual "(gnus)Customizing Articles")
1136 :type gnus-article-treat-custom)
1137 (put 'gnus-treat-highlight-signature 'highlight t)
1139 (defcustom gnus-treat-buttonize 100000
1141 Valid values are nil, t, `head', `first', `last', an integer or a
1142 predicate. See Info node `(gnus)Customizing Articles'."
1143 :group 'gnus-article-treat
1144 :link '(custom-manual "(gnus)Customizing Articles")
1145 :type gnus-article-treat-custom)
1146 (put 'gnus-treat-buttonize 'highlight t)
1148 (defcustom gnus-treat-buttonize-head 'head
1149 "Add buttons to the head.
1150 Valid values are nil, t, `head', `first', `last', an integer or a
1151 predicate. See Info node `(gnus)Customizing Articles'."
1152 :group 'gnus-article-treat
1153 :link '(custom-manual "(gnus)Customizing Articles")
1154 :type gnus-article-treat-head-custom)
1155 (put 'gnus-treat-buttonize-head 'highlight t)
1157 (defcustom gnus-treat-date 'head
1158 "Display dates according to the `gnus-article-date-headers' variable.
1159 Valid values are nil, t, `head', `first', `last', an integer or a
1160 predicate. See Info node `(gnus)Customizing Articles'."
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1166 (defcustom gnus-treat-emphasize 50000
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate. See Info node `(gnus)Customizing Articles'."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-custom)
1173 (put 'gnus-treat-emphasize 'highlight t)
1175 (defcustom gnus-treat-strip-cr nil
1176 "Remove carriage returns.
1177 Valid values are nil, t, `head', `first', `last', an integer or a
1178 predicate. See Info node `(gnus)Customizing Articles'."
1180 :group 'gnus-article-treat
1181 :link '(custom-manual "(gnus)Customizing Articles")
1182 :type gnus-article-treat-custom)
1184 (defcustom gnus-treat-unsplit-urls nil
1185 "Remove newlines from within URLs.
1186 Valid values are nil, t, `head', `first', `last', an integer or a
1187 predicate. See Info node `(gnus)Customizing Articles'."
1189 :group 'gnus-article-treat
1190 :link '(custom-manual "(gnus)Customizing Articles")
1191 :type gnus-article-treat-custom)
1193 (defcustom gnus-treat-leading-whitespace nil
1194 "Remove leading whitespace in headers.
1195 Valid values are nil, t, `head', `first', `last', an integer or a
1196 predicate. See Info node `(gnus)Customizing Articles'."
1198 :group 'gnus-article-treat
1199 :link '(custom-manual "(gnus)Customizing Articles")
1200 :type gnus-article-treat-custom)
1202 (defcustom gnus-treat-hide-headers 'head
1204 Valid values are nil, t, `head', `first', `last', an integer or a
1205 predicate. See Info node `(gnus)Customizing Articles'."
1206 :group 'gnus-article-treat
1207 :link '(custom-manual "(gnus)Customizing Articles")
1208 :type gnus-article-treat-head-custom)
1210 (defcustom gnus-treat-hide-boring-headers nil
1211 "Hide boring headers.
1212 Valid values are nil, t, `head', `first', `last', an integer or a
1213 predicate. See Info node `(gnus)Customizing Articles'."
1214 :group 'gnus-article-treat
1215 :link '(custom-manual "(gnus)Customizing Articles")
1216 :type gnus-article-treat-head-custom)
1218 (defcustom gnus-treat-hide-signature nil
1219 "Hide the signature.
1220 Valid values are nil, t, `head', `first', `last', an integer or a
1221 predicate. See Info node `(gnus)Customizing Articles'."
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-custom)
1226 (defcustom gnus-treat-fill-article nil
1228 Valid values are nil, t, `head', `first', `last', an integer or a
1229 predicate. See Info node `(gnus)Customizing Articles'."
1230 :group 'gnus-article-treat
1231 :link '(custom-manual "(gnus)Customizing Articles")
1232 :type gnus-article-treat-custom)
1234 (defcustom gnus-treat-hide-citation nil
1236 Valid values are nil, t, `head', `first', `last', an integer or a
1237 predicate. See Info node `(gnus)Customizing Articles'.
1239 See `gnus-article-highlight-citation' for variables used to
1240 control what it hides."
1241 :group 'gnus-article-treat
1242 :link '(custom-manual "(gnus)Customizing Articles")
1243 :type gnus-article-treat-custom)
1245 (defcustom gnus-treat-hide-citation-maybe nil
1246 "Hide cited text according to certain conditions.
1247 Valid values are nil, t, `head', `first', `last', an integer or a
1248 predicate. See Info node `(gnus)Customizing Articles'.
1250 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1251 how to control what it hides."
1252 :group 'gnus-article-treat
1253 :link '(custom-manual "(gnus)Customizing Articles")
1254 :type gnus-article-treat-custom)
1256 (defcustom gnus-treat-strip-list-identifiers 'head
1257 "Strip list identifiers from `gnus-list-identifiers`.
1258 Valid values are nil, t, `head', `first', `last', an integer or a
1259 predicate. See Info node `(gnus)Customizing Articles'."
1261 :group 'gnus-article-treat
1262 :link '(custom-manual "(gnus)Customizing Articles")
1263 :type gnus-article-treat-custom)
1265 (gnus-define-group-parameter
1268 "Alist of regexps and correspondent identifiers."
1269 :variable-group gnus-article-washing
1271 '(choice :tag "Identifier"
1273 (symbol :tag "Item in `gnus-list-identifiers'" none)
1275 (const :tag "None" nil))
1277 "If non-nil, specify how to remove `identifiers' from articles' subject.
1279 Any symbol is used to look up a regular expression to match the
1280 banner in `gnus-list-identifiers'. A string is used as a regular
1281 expression to match the identifier directly.")
1283 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1284 "Gnus 5.10 (Emacs 22.1)")
1286 (defcustom gnus-treat-strip-pem nil
1287 "Strip PEM signatures.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-custom)
1294 (defcustom gnus-treat-strip-banner t
1295 "Strip banners from articles.
1296 The banner to be stripped is specified in the `banner' group parameter.
1297 Valid values are nil, t, `head', `first', `last', an integer or a
1298 predicate. See Info node `(gnus)Customizing Articles'."
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-custom)
1303 (defcustom gnus-treat-highlight-headers 'head
1304 "Highlight the headers.
1305 Valid values are nil, t, `head', `first', `last', an integer or a
1306 predicate. See Info node `(gnus)Customizing Articles'."
1307 :group 'gnus-article-treat
1308 :link '(custom-manual "(gnus)Customizing Articles")
1309 :type gnus-article-treat-head-custom)
1310 (put 'gnus-treat-highlight-headers 'highlight t)
1312 (defcustom gnus-treat-highlight-citation t
1313 "Highlight cited text.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1316 :group 'gnus-article-treat
1317 :link '(custom-manual "(gnus)Customizing Articles")
1318 :type gnus-article-treat-custom)
1319 (put 'gnus-treat-highlight-citation 'highlight t)
1321 (defcustom gnus-treat-strip-headers-in-body t
1322 "Strip the X-No-Archive header line from the beginning of the body.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate. See Info node `(gnus)Customizing Articles'."
1326 :group 'gnus-article-treat
1327 :link '(custom-manual "(gnus)Customizing Articles")
1328 :type gnus-article-treat-custom)
1330 (defcustom gnus-treat-strip-trailing-blank-lines nil
1331 "Strip trailing blank lines.
1332 Valid values are nil, t, `head', `first', `last', an integer or a
1333 predicate. See Info node `(gnus)Customizing Articles'.
1335 When set to t, it also strips trailing blanks in all MIME parts.
1336 Consider to use `last' instead."
1337 :group 'gnus-article-treat
1338 :link '(custom-manual "(gnus)Customizing Articles")
1339 :type gnus-article-treat-custom)
1341 (defcustom gnus-treat-strip-leading-blank-lines nil
1342 "Strip leading blank lines.
1343 Valid values are nil, t, `head', `first', `last', an integer or a
1344 predicate. See Info node `(gnus)Customizing Articles'.
1346 When set to t, it also strips trailing blanks in all MIME parts."
1347 :group 'gnus-article-treat
1348 :link '(custom-manual "(gnus)Customizing Articles")
1349 :type gnus-article-treat-custom)
1351 (defcustom gnus-treat-strip-multiple-blank-lines nil
1352 "Strip multiple blank lines.
1353 Valid values are nil, t, `head', `first', `last', an integer or a
1354 predicate. See Info node `(gnus)Customizing Articles'."
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1359 (defcustom gnus-treat-unfold-headers 'head
1360 "Unfold folded header lines.
1361 Valid values are nil, t, `head', `first', `last', an integer or a
1362 predicate. See Info node `(gnus)Customizing Articles'."
1364 :group 'gnus-article-treat
1365 :link '(custom-manual "(gnus)Customizing Articles")
1366 :type gnus-article-treat-custom)
1368 (defcustom gnus-article-unfold-long-headers nil
1369 "If non-nil, allow unfolding headers even if the header is long.
1370 If it is a regexp, only long headers matching this regexp are unfolded.
1371 If it is t, all long headers are unfolded.
1373 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1374 :version "23.1" ;; No Gnus
1375 :group 'gnus-article-treat
1376 :type '(choice (const nil)
1377 (const :tag "all" t)
1380 (defcustom gnus-treat-fold-headers nil
1382 Valid values are nil, t, `head', `first', `last', an integer or a
1383 predicate. See Info node `(gnus)Customizing Articles'."
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1389 (defcustom gnus-treat-fold-newsgroups 'head
1390 "Fold the Newsgroups and Followup-To headers.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate. See Info node `(gnus)Customizing Articles'."
1394 :group 'gnus-article-treat
1395 :link '(custom-manual "(gnus)Customizing Articles")
1396 :type gnus-article-treat-custom)
1398 (defcustom gnus-treat-overstrike t
1399 "Treat overstrike highlighting.
1400 Valid values are nil, t, `head', `first', `last', an integer or a
1401 predicate. See Info node `(gnus)Customizing Articles'."
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1405 (put 'gnus-treat-overstrike 'highlight t)
1407 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1408 "Treat ANSI SGR control sequences.
1409 Valid values are nil, t, `head', `first', `last', an integer or a
1410 predicate. See Info node `(gnus)Customizing Articles'."
1411 :group 'gnus-article-treat
1412 :link '(custom-manual "(gnus)Customizing Articles")
1413 :type gnus-article-treat-custom)
1415 (make-obsolete-variable 'gnus-treat-display-xface
1416 'gnus-treat-display-x-face "Emacs 22.1")
1418 (defcustom gnus-treat-display-x-face
1419 (and (not noninteractive)
1420 (gnus-image-type-available-p 'xbm)
1421 (if (featurep 'xemacs)
1424 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1425 (executable-find "icontopbm"))
1426 ;; shell-command-to-string may signal an error, e.g. if
1427 ;; shell-file-name is not found.
1430 "Display X-Face headers.
1431 Valid values are nil and `head'.
1432 See Info node `(gnus)Customizing Articles' and Info node
1433 `(gnus)X-Face' for details."
1434 :group 'gnus-article-treat
1436 :link '(custom-manual "(gnus)Customizing Articles")
1437 :link '(custom-manual "(gnus)X-Face")
1438 :type gnus-article-treat-head-custom
1439 :set (lambda (symbol value)
1442 (cond ((or (boundp symbol) (get symbol 'saved-value))
1444 ((boundp 'gnus-treat-display-xface)
1446 ** gnus-treat-display-xface is an obsolete variable;\
1447 use gnus-treat-display-x-face instead")
1448 (default-value 'gnus-treat-display-xface))
1449 ((get 'gnus-treat-display-xface 'saved-value)
1451 ** gnus-treat-display-xface is an obsolete variable;\
1452 use gnus-treat-display-x-face instead")
1453 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1456 (put 'gnus-treat-display-x-face 'highlight t)
1458 (defcustom gnus-treat-display-face
1459 (and (not noninteractive)
1460 (gnus-image-type-available-p 'png)
1462 "Display Face headers.
1463 Valid values are nil, t, `head', `first', `last', an integer or a
1464 predicate. See Info node `(gnus)Customizing Articles' and Info
1465 node `(gnus)Face' for details."
1466 :group 'gnus-article-treat
1468 :link '(custom-manual "(gnus)Customizing Articles")
1469 :link '(custom-manual "(gnus)X-Face")
1470 :type gnus-article-treat-head-custom)
1471 (put 'gnus-treat-display-face 'highlight t)
1473 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1475 Valid values are nil, t, `head', `first', `last', an integer or a
1476 predicate. See Info node `(gnus)Customizing Articles' and Info
1477 node `(gnus)Smileys' for details."
1478 :group 'gnus-article-treat
1480 :link '(custom-manual "(gnus)Customizing Articles")
1481 :link '(custom-manual "(gnus)Smileys")
1482 :type gnus-article-treat-custom)
1483 (put 'gnus-treat-display-smileys 'highlight t)
1485 (defcustom gnus-treat-from-picon
1486 (if (and (gnus-image-type-available-p 'xpm)
1487 (gnus-picons-installed-p))
1489 "Display picons in the From header.
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-from-picon 'highlight t)
1501 (defcustom gnus-treat-mail-picon
1502 (if (and (gnus-image-type-available-p 'xpm)
1503 (gnus-picons-installed-p))
1505 "Display picons in To and Cc 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-mail-picon 'highlight t)
1517 (defcustom gnus-treat-newsgroups-picon
1518 (if (and (gnus-image-type-available-p 'xpm)
1519 (gnus-picons-installed-p))
1521 "Display picons in the Newsgroups and Followup-To headers.
1522 Valid values are nil, t, `head', `first', `last', an integer or a
1523 predicate. See Info node `(gnus)Customizing Articles' and Info
1524 node `(gnus)Picons' for details."
1526 :group 'gnus-article-treat
1528 :link '(custom-manual "(gnus)Customizing Articles")
1529 :link '(custom-manual "(gnus)Picons")
1530 :type gnus-article-treat-head-custom)
1531 (put 'gnus-treat-newsgroups-picon 'highlight t)
1533 (defcustom gnus-treat-from-gravatar nil
1534 "Display gravatars in the From header.
1535 Valid values are nil, t, `head', `first', `last', an integer or a
1536 predicate. See Info node `(gnus)Customizing Articles' and Info
1537 node `(gnus)Gravatars' for details."
1539 :group 'gnus-article-treat
1540 :group 'gnus-gravatar
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :link '(custom-manual "(gnus)Gravatars")
1543 :type gnus-article-treat-head-custom)
1544 (put 'gnus-treat-from-gravatar 'highlight t)
1546 (defcustom gnus-treat-mail-gravatar nil
1547 "Display gravatars in To and Cc headers.
1548 Valid values are nil, t, `head', `first', `last', an integer or a
1549 predicate. See Info node `(gnus)Customizing Articles' and Info
1550 node `(gnus)Gravatars' for details."
1552 :group 'gnus-article-treat
1553 :group 'gnus-gravatar
1554 :link '(custom-manual "(gnus)Customizing Articles")
1555 :link '(custom-manual "(gnus)Gravatars")
1556 :type gnus-article-treat-head-custom)
1557 (put 'gnus-treat-mail-gravatar 'highlight t)
1559 (defcustom gnus-treat-body-boundary
1560 (if (or gnus-treat-newsgroups-picon
1561 gnus-treat-mail-picon
1562 gnus-treat-from-picon
1563 gnus-treat-from-gravatar
1564 gnus-treat-mail-gravatar)
1565 ;; If there's much decoration, the user might prefer a boundary.
1568 "Draw a boundary at the end of the headers.
1569 Valid values are nil and `head'.
1570 See Info node `(gnus)Customizing Articles' for details."
1572 :group 'gnus-article-treat
1573 :link '(custom-manual "(gnus)Customizing Articles")
1574 :type gnus-article-treat-head-custom)
1576 (defcustom gnus-treat-capitalize-sentences nil
1577 "Capitalize sentence-starting words.
1578 Valid values are nil, t, `head', `first', `last', an integer or a
1579 predicate. See Info node `(gnus)Customizing Articles'."
1581 :group 'gnus-article-treat
1582 :link '(custom-manual "(gnus)Customizing Articles")
1583 :type gnus-article-treat-custom)
1585 (defcustom gnus-treat-wash-html nil
1587 Valid values are nil, t, `head', `first', `last', an integer or a
1588 predicate. See Info node `(gnus)Customizing Articles'."
1590 :group 'gnus-article-treat
1591 :link '(custom-manual "(gnus)Customizing Articles")
1592 :type gnus-article-treat-custom)
1594 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1596 Valid values are nil, t, `head', `first', `last', an integer or a
1597 predicate. See Info node `(gnus)Customizing Articles'."
1599 :group 'gnus-article-treat
1600 :link '(custom-manual "(gnus)Customizing Articles")
1601 :type gnus-article-treat-custom)
1603 (defcustom gnus-treat-x-pgp-sig nil
1605 To automatically treat X-PGP-Sig, set it to head.
1606 Valid values are nil, t, `head', `first', `last', an integer or a
1607 predicate. See Info node `(gnus)Customizing Articles'."
1609 :group 'gnus-article-treat
1610 :group 'mime-security
1611 :link '(custom-manual "(gnus)Customizing Articles")
1612 :type gnus-article-treat-custom)
1614 (defvar gnus-article-encrypt-protocol-alist
1615 '(("PGP" . mml2015-self-encrypt)))
1617 ;; Set to nil if more than one protocol added to
1618 ;; gnus-article-encrypt-protocol-alist.
1619 (defcustom gnus-article-encrypt-protocol "PGP"
1620 "The protocol used for encrypt articles.
1621 It is a string, such as \"PGP\". If nil, ask user."
1624 :group 'mime-security)
1626 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1627 (mm-coding-system-p 'utf-8)
1628 (executable-find idna-program))
1629 "Whether IDNA decoding of headers is used when viewing messages.
1630 This requires GNU Libidn, and by default only enabled if it is found."
1632 :group 'gnus-article-headers
1635 (defcustom gnus-article-over-scroll nil
1636 "If non-nil, allow scrolling the article buffer even when there no more text."
1638 :group 'gnus-article
1641 (defcustom gnus-inhibit-images nil
1642 "Non-nil means inhibit displaying of images inline in the article body."
1644 :group 'gnus-article
1647 (defcustom gnus-blocked-images 'gnus-block-private-groups
1648 "Images that have URLs matching this regexp will be blocked.
1649 This can also be a function to be evaluated. If so, it will be
1650 called with the group name as the parameter, and should return a
1656 ;;; Internal variables
1658 (defvar gnus-english-month-names
1659 '("January" "February" "March" "April" "May" "June" "July" "August"
1660 "September" "October" "November" "December"))
1662 (defvar article-goto-body-goes-to-point-min-p nil)
1663 (defvar gnus-article-wash-types nil)
1664 (defvar gnus-article-emphasis-alist nil)
1665 (defvar gnus-article-image-alist nil)
1667 (defvar gnus-article-mime-handle-alist-1 nil)
1668 (defvar gnus-treatment-function-alist
1669 '((gnus-treat-strip-cr gnus-article-remove-cr)
1670 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1671 (gnus-treat-strip-banner gnus-article-strip-banner)
1672 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1673 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1674 (gnus-treat-buttonize gnus-article-add-buttons)
1675 (gnus-treat-fill-article gnus-article-fill-cited-article)
1676 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1677 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1678 (gnus-treat-display-x-face gnus-article-display-x-face)
1679 (gnus-treat-display-face gnus-article-display-face)
1680 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1681 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1682 (gnus-treat-hide-signature gnus-article-hide-signature)
1683 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1684 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1685 (gnus-treat-from-picon gnus-treat-from-picon)
1686 (gnus-treat-mail-picon gnus-treat-mail-picon)
1687 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1688 (gnus-treat-strip-pem gnus-article-hide-pem)
1689 (gnus-treat-date gnus-article-treat-date)
1690 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1691 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1692 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1693 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1694 (gnus-treat-strip-trailing-blank-lines
1695 gnus-article-remove-trailing-blank-lines)
1696 (gnus-treat-strip-leading-blank-lines
1697 gnus-article-strip-leading-blank-lines)
1698 (gnus-treat-strip-multiple-blank-lines
1699 gnus-article-strip-multiple-blank-lines)
1700 (gnus-treat-overstrike gnus-article-treat-overstrike)
1701 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1702 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1703 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1704 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1705 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1706 (gnus-treat-display-smileys gnus-treat-smiley)
1707 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1708 (gnus-treat-wash-html gnus-article-wash-html)
1709 (gnus-treat-emphasize gnus-article-emphasize)
1710 (gnus-treat-hide-citation gnus-article-hide-citation)
1711 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1712 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1713 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1715 (defvar gnus-article-mime-handle-alist nil)
1716 (defvar article-lapsed-timer nil)
1717 (defvar gnus-article-current-summary nil)
1719 (defvar gnus-article-mode-syntax-table
1720 (let ((table (copy-syntax-table text-mode-syntax-table)))
1721 ;; This causes the citation match run O(2^n).
1722 ;; (modify-syntax-entry ?- "w" table)
1723 (modify-syntax-entry ?> ")<" table)
1724 (modify-syntax-entry ?< "(>" table)
1725 ;; make M-. in article buffers work for `foo' strings
1726 (modify-syntax-entry ?' " " table)
1727 (modify-syntax-entry ?` " " table)
1729 "Syntax table used in article mode buffers.
1730 Initialized from `text-mode-syntax-table.")
1732 (defvar gnus-save-article-buffer nil)
1734 (defvar gnus-number-of-articles-to-be-saved nil)
1736 (defvar gnus-inhibit-hiding nil)
1738 (defvar gnus-article-edit-mode nil)
1740 ;;; Macros for dealing with the article buffer.
1742 (defmacro gnus-with-article-headers (&rest forms)
1743 `(with-current-buffer gnus-article-buffer
1745 (let ((inhibit-read-only t)
1746 (inhibit-point-motion-hooks t)
1747 (case-fold-search t))
1748 (article-narrow-to-head)
1751 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1752 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1754 (defmacro gnus-with-article-buffer (&rest forms)
1755 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1756 (with-current-buffer gnus-article-buffer
1757 (let ((inhibit-read-only t))
1760 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1761 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1763 (defun gnus-article-goto-header (header)
1764 "Go to HEADER, which is a regular expression."
1765 (re-search-forward (concat "^\\(" header "\\):") nil t))
1767 (defsubst gnus-article-hide-text (b e props)
1768 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1769 (gnus-add-text-properties-when 'article-type nil b e props)
1770 (when (memq 'intangible props)
1772 (max (1- b) (point-min))
1773 b 'intangible (cddr (memq 'intangible props)))))
1775 (defsubst gnus-article-unhide-text (b e)
1776 "Remove hidden text properties from region between B and E."
1777 (remove-text-properties b e gnus-hidden-properties)
1778 (when (memq 'intangible gnus-hidden-properties)
1779 (put-text-property (max (1- b) (point-min))
1780 b 'intangible nil)))
1782 (defun gnus-article-hide-text-type (b e type)
1783 "Hide text of TYPE between B and E."
1784 (gnus-add-wash-type type)
1785 (gnus-article-hide-text
1786 b e (cons 'article-type (cons type gnus-hidden-properties))))
1788 (defun gnus-article-unhide-text-type (b e type)
1789 "Unhide text of TYPE between B and E."
1790 (gnus-delete-wash-type type)
1791 (remove-text-properties
1792 b e (cons 'article-type (cons type gnus-hidden-properties)))
1793 (when (memq 'intangible gnus-hidden-properties)
1794 (put-text-property (max (1- b) (point-min))
1795 b 'intangible nil)))
1797 (defun gnus-article-delete-text-of-type (type)
1798 "Delete text of TYPE in the current buffer."
1800 (let ((b (point-min)))
1801 (if (eq type 'multipart)
1802 ;; Remove MIME buttons associated with multipart/alternative parts.
1805 (while (if (get-text-property (point) 'gnus-part)
1807 (when (setq b (next-single-property-change (point)
1812 (skip-chars-forward "\n")
1813 (when (eq (get-text-property b 'article-type) 'multipart)
1814 (delete-region b (point)))))
1815 (while (setq b (text-property-any b (point-max) 'article-type type))
1817 b (or (text-property-not-all b (point-max) 'article-type type)
1820 (defun gnus-article-delete-invisible-text ()
1821 "Delete all invisible text in the current buffer."
1823 (let ((b (point-min)))
1824 (while (setq b (text-property-any b (point-max) 'invisible t))
1826 b (or (text-property-not-all b (point-max) 'invisible t)
1829 (defsubst gnus-article-header-rank ()
1830 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1831 (let ((list gnus-sorted-header-list)
1834 (if (looking-at (car list))
1836 (setq list (cdr list))
1840 (defun article-hide-headers (&optional arg delete)
1841 "Hide unwanted headers and possibly sort them as well."
1843 ;; This function might be inhibited.
1844 (unless gnus-inhibit-hiding
1845 (let ((inhibit-read-only t)
1846 (case-fold-search t)
1847 (max (1+ (length gnus-sorted-header-list)))
1848 (inhibit-point-motion-hooks t)
1849 (cur (current-buffer))
1850 ignored visible beg)
1852 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1853 ;; group parameters, so we should go to the summary buffer.
1856 (progn (set-buffer gnus-summary-buffer) t)
1858 (setq ignored (when (not gnus-visible-headers)
1859 (cond ((stringp gnus-ignored-headers)
1860 gnus-ignored-headers)
1861 ((listp gnus-ignored-headers)
1862 (mapconcat 'identity
1863 gnus-ignored-headers
1865 visible (cond ((stringp gnus-visible-headers)
1866 gnus-visible-headers)
1867 ((and gnus-visible-headers
1868 (listp gnus-visible-headers))
1869 (mapconcat 'identity
1870 gnus-visible-headers
1874 ;; First we narrow to just the headers.
1875 (article-narrow-to-head)
1876 ;; Hide any "From " lines at the beginning of (mail) articles.
1877 (while (looking-at "From ")
1880 (delete-region (point-min) (point)))
1881 ;; Then treat the rest of the header lines.
1882 ;; Then we use the two regular expressions
1883 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1884 ;; select which header lines is to remain visible in the
1886 (while (re-search-forward "^[^ \t:]*:" nil t)
1888 ;; Mark the rank of the header.
1890 (point) (1+ (point)) 'message-rank
1891 (if (or (and visible (looking-at visible))
1893 (not (looking-at ignored))))
1894 (gnus-article-header-rank)
1897 (message-sort-headers-1)
1898 (when (setq beg (text-property-any
1899 (point-min) (point-max) 'message-rank (+ 2 max)))
1900 ;; We delete the unwanted headers.
1901 (gnus-add-wash-type 'headers)
1902 (add-text-properties (point-min) (+ 5 (point-min))
1903 '(article-type headers dummy-invisible t))
1904 (delete-region beg (point-max))))))))
1906 (defun article-hide-boring-headers (&optional arg)
1907 "Toggle hiding of headers that aren't very interesting.
1908 If given a negative prefix, always show; if given a positive prefix,
1910 (interactive (gnus-article-hidden-arg))
1911 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1912 (not gnus-show-all-headers))
1915 (let ((inhibit-read-only t)
1916 (inhibit-point-motion-hooks t))
1917 (article-narrow-to-head)
1918 (dolist (elem gnus-boring-article-headers)
1919 (goto-char (point-min))
1921 ;; Hide empty headers.
1923 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1925 (gnus-article-hide-text-type
1929 (if (re-search-forward "^[^ \t]" nil t)
1933 ;; Hide boring Newsgroups header.
1934 ((eq elem 'newsgroups)
1935 (when (gnus-string-equal
1936 (gnus-fetch-field "newsgroups")
1937 (gnus-group-real-name
1938 (if (boundp 'gnus-newsgroup-name)
1941 (gnus-article-hide-header "newsgroups")))
1942 ((eq elem 'to-address)
1943 (let ((to (message-fetch-field "to"))
1945 (gnus-parameter-to-address
1946 (if (boundp 'gnus-newsgroup-name)
1947 gnus-newsgroup-name ""))))
1948 (when (and to to-address
1951 ;; only one address in To
1952 (nth 1 (mail-extract-address-components to))
1954 (gnus-article-hide-header "to"))))
1956 (let ((to (message-fetch-field "to"))
1958 (gnus-parameter-to-list
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and to to-list
1964 ;; only one address in To
1965 (nth 1 (mail-extract-address-components to))
1967 (gnus-article-hide-header "to"))))
1969 (let ((cc (message-fetch-field "cc"))
1971 (gnus-parameter-to-list
1972 (if (boundp 'gnus-newsgroup-name)
1973 gnus-newsgroup-name ""))))
1974 (when (and cc to-list
1977 ;; only one address in CC
1978 (nth 1 (mail-extract-address-components cc))
1980 (gnus-article-hide-header "cc"))))
1981 ((eq elem 'followup-to)
1982 (when (gnus-string-equal
1983 (message-fetch-field "followup-to")
1984 (message-fetch-field "newsgroups"))
1985 (gnus-article-hide-header "followup-to")))
1986 ((eq elem 'reply-to)
1987 (if (gnus-group-find-parameter
1988 gnus-newsgroup-name 'broken-reply-to)
1989 (gnus-article-hide-header "reply-to")
1990 (let ((from (message-fetch-field "from"))
1991 (reply-to (message-fetch-field "reply-to")))
1998 (lambda (x) (downcase (cadr x)))
1999 (mail-extract-address-components from t))
2002 (lambda (x) (downcase (cadr x)))
2003 (mail-extract-address-components reply-to t))
2005 (gnus-article-hide-header "reply-to")))))
2007 (let ((date (with-current-buffer gnus-original-article-buffer
2008 ;; If date in `gnus-article-buffer' is localized
2009 ;; (`gnus-treat-date-user-defined'),
2010 ;; `days-between' might fail.
2011 (message-fetch-field "date"))))
2013 (< (days-between (current-time-string) date)
2015 (gnus-article-hide-header "date"))))
2017 (let ((to (message-fetch-field "to"))
2018 (cc (message-fetch-field "cc")))
2019 (when (> (length to) 1024)
2020 (gnus-article-hide-header "to"))
2021 (when (> (length cc) 1024)
2022 (gnus-article-hide-header "cc"))))
2026 (goto-char (point-min))
2027 (while (re-search-forward "^to:" nil t)
2028 (setq to-count (1+ to-count)))
2029 (when (> to-count 1)
2030 (while (> to-count 0)
2031 (goto-char (point-min))
2033 (re-search-forward "^to:" nil nil to-count)
2035 (narrow-to-region (point) (point-max))
2036 (gnus-article-hide-header "to"))
2037 (setq to-count (1- to-count))))
2038 (goto-char (point-min))
2039 (while (re-search-forward "^cc:" nil t)
2040 (setq cc-count (1+ cc-count)))
2041 (when (> cc-count 1)
2042 (while (> cc-count 0)
2043 (goto-char (point-min))
2045 (re-search-forward "^cc:" nil nil cc-count)
2047 (narrow-to-region (point) (point-max))
2048 (gnus-article-hide-header "cc"))
2049 (setq cc-count (1- cc-count)))))))))))))
2051 (defun gnus-article-hide-header (header)
2053 (goto-char (point-min))
2054 (when (re-search-forward (concat "^" header ":") nil t)
2055 (gnus-article-hide-text-type
2059 (if (re-search-forward "^[^ \t]" nil t)
2064 (defvar gnus-article-normalized-header-length 40
2065 "Length of normalized headers.")
2067 (defun article-normalize-headers ()
2068 "Make all header lines 40 characters long."
2070 (let ((inhibit-read-only t)
2074 (article-narrow-to-head)
2077 ((< (setq column (- (point-at-eol) (point)))
2078 gnus-article-normalized-header-length)
2080 (insert (make-string
2081 (- gnus-article-normalized-header-length column)
2083 ((> column gnus-article-normalized-header-length)
2084 (gnus-put-text-property
2086 (forward-char gnus-article-normalized-header-length)
2093 (forward-line 1))))))
2095 (defun article-treat-dumbquotes ()
2096 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2097 Note that this function guesses whether a character is a sm*rtq**t* or
2098 not, so it should only be used interactively.
2100 Sm*rtq**t*s are M****s***'s unilateral extension to the
2101 iso-8859-1 character map in an attempt to provide more quoting
2102 characters. If you see something like \\222 or \\264 where
2103 you're expecting some kind of apostrophe or quotation mark, then
2106 (article-translate-strings gnus-article-dumbquotes-map))
2108 (defvar org-entities)
2110 (defun article-treat-non-ascii ()
2111 "Translate many Unicode characters into their ASCII equivalents."
2113 (require 'org-entities)
2114 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2115 (dolist (elem org-entities)
2116 (when (and (listp elem)
2117 (= (length (nth 6 elem)) 1))
2118 (if (featurep 'xemacs)
2119 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2120 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2122 (when (article-goto-body)
2123 (let ((inhibit-read-only t)
2126 (if (not (setq replace (if (featurep 'xemacs)
2127 (get-char-table (following-char) table)
2128 (aref table (following-char)))))
2131 (setq props (text-properties-at (point)))
2133 (add-text-properties (point) (progn (insert replace) (point))
2135 (insert replace)))))))))
2137 (defun article-translate-strings (map)
2138 "Translate all string in the body of the article according to MAP.
2139 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2141 (when (article-goto-body)
2142 (let ((inhibit-read-only t))
2144 (let ((from (car elem))
2148 (while (search-forward from nil t)
2151 (if (eq (following-char) from)
2155 (forward-char 1)))))))))))
2157 (defun article-treat-overstrike ()
2158 "Translate overstrikes into bold text."
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2163 (while (search-forward "\b" nil t)
2164 (let ((next (char-after))
2165 (previous (char-after (- (point) 2))))
2166 ;; We do the boldification/underlining by hiding the
2167 ;; overstrikes and putting the proper text property
2171 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2172 (put-text-property (point) (1+ (point)) 'face 'bold))
2174 (gnus-article-hide-text-type
2175 (1- (point)) (1+ (point)) 'overstrike)
2177 (- (point) 2) (1- (point)) 'face 'underline))
2179 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2181 (point) (1+ (point)) 'face 'underline)))))))))
2183 (defun article-treat-ansi-sequences ()
2184 "Translate ANSI SGR control sequences into overlays or extents."
2187 (when (article-goto-body)
2188 (let ((inhibit-read-only t))
2189 (ansi-color-apply-on-region (point) (point-max))))))
2191 (defun gnus-article-treat-unfold-headers ()
2192 "Unfold folded message headers.
2193 Only the headers that fit into the current window width will be
2196 (gnus-with-article-headers
2200 (mail-header-narrow-to-field)
2201 (let* ((header (buffer-string))
2203 (or (equal gnus-article-unfold-long-headers t)
2204 (and (stringp gnus-article-unfold-long-headers)
2205 (string-match gnus-article-unfold-long-headers
2209 (goto-char (point-min))
2210 (while (re-search-forward "\n[\t ]" nil t)
2211 (replace-match " " t t)))
2212 (setq length (- (point-max) (point-min) 1))
2213 (when (or unfoldable
2214 (< length (window-width)))
2215 (while (re-search-forward "\n[\t ]" nil t)
2216 (replace-match " " t t))))
2217 (goto-char (point-max)))))))
2219 (defun gnus-article-treat-fold-headers ()
2220 "Fold message headers."
2222 (gnus-with-article-headers
2225 (mail-header-narrow-to-field)
2226 (mail-header-fold-field)
2227 (goto-char (point-max))))))
2229 (defun gnus-treat-smiley ()
2230 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2232 (gnus-with-article-buffer
2233 (if (memq 'smiley gnus-article-wash-types)
2234 (gnus-delete-images 'smiley)
2236 (let ((images (smiley-region (point) (point-max))))
2238 (gnus-add-wash-type 'smiley)
2239 (dolist (image images)
2240 (gnus-add-image 'smiley image)))))))
2242 (defun gnus-article-remove-images ()
2243 "Remove all images from the article buffer."
2245 (gnus-with-article-buffer
2248 (dolist (elem gnus-article-image-alist)
2249 (gnus-delete-images (car elem))))))
2251 (autoload 'w3m-toggle-inline-images "w3m")
2253 (defun gnus-article-show-images ()
2254 "Show any images that are in the HTML-rendered article buffer.
2255 This only works if the article in question is HTML."
2257 (gnus-with-article-buffer
2260 (if (eq mm-text-html-renderer 'w3m)
2261 (let ((mm-inline-text-html-with-images nil))
2262 (w3m-toggle-inline-images))
2263 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2265 (destructuring-bind (start end function) region
2266 (funcall function (get-text-property start 'image-url)
2269 (defun gnus-article-treat-fold-newsgroups ()
2270 "Unfold folded message headers.
2271 Only the headers that fit into the current window width will be
2274 (gnus-with-article-headers
2275 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2277 (mail-header-narrow-to-field)
2278 (while (re-search-forward ", *" nil t)
2279 (replace-match ", " t t))
2280 (mail-header-fold-field)
2281 (goto-char (point-max))))))
2283 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2284 "Value of `truncate-lines' in Gnus Article buffer.
2285 Valid values are nil, t, `head', `first', `last', an integer or a
2286 predicate. See Info node `(gnus)Customizing Articles'."
2287 :version "23.1" ;; No Gnus
2288 :group 'gnus-article
2289 ;; :link '(custom-manual "(gnus)Customizing Articles")
2292 (defun gnus-article-toggle-truncate-lines (&optional arg)
2293 "Toggle whether to fold or truncate long lines in article the buffer.
2294 If ARG is non-nil and not a number, toggle
2295 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2296 long lines if and only if arg is positive."
2299 ((and (numberp arg) (> arg 0))
2300 (setq gnus-article-truncate-lines t))
2302 (setq gnus-article-truncate-lines nil))
2304 (setq gnus-article-truncate-lines
2305 (not gnus-article-truncate-lines))))
2306 (gnus-with-article-buffer
2308 ((and (numberp arg) (> arg 0))
2309 (setq truncate-lines nil))
2311 (setq truncate-lines t)))
2312 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2313 ;; `toggle-truncate-lines' needs an argument.
2314 (toggle-truncate-lines)))
2316 (defun gnus-article-treat-body-boundary ()
2317 "Place a boundary line at the end of the headers."
2319 (when (and gnus-body-boundary-delimiter
2320 (> (length gnus-body-boundary-delimiter) 0))
2321 (gnus-with-article-headers
2322 (goto-char (point-max))
2323 (let ((start (point)))
2324 (insert "X-Boundary: ")
2325 (gnus-add-text-properties start (point) '(invisible t intangible t))
2326 (insert (let (str (max (window-width)))
2327 (if (featurep 'xemacs)
2328 (setq max (1- max)))
2329 (while (>= max (length str))
2330 (setq str (concat str gnus-body-boundary-delimiter)))
2331 (substring str 0 max))
2333 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2335 (defun article-fill-long-lines ()
2336 "Fill lines that are wider than the window width."
2339 (let ((inhibit-read-only t)
2340 (width (window-width (get-buffer-window (current-buffer)))))
2343 (let ((adaptive-fill-mode nil)) ;Why? -sm
2346 (when (>= (current-column) (min fill-column width))
2347 (narrow-to-region (min (1+ (point)) (point-max))
2349 (let ((goback (point-marker)))
2350 (fill-paragraph nil)
2351 (goto-char (marker-position goback)))
2353 (forward-line 1)))))))
2355 (defun article-capitalize-sentences ()
2356 "Capitalize the first word in each sentence."
2359 (let ((inhibit-read-only t)
2360 (paragraph-start "^[\n\^L]"))
2364 (forward-sentence)))))
2366 (defun article-remove-cr ()
2367 "Remove trailing CRs and then translate remaining CRs into LFs."
2370 (let ((inhibit-read-only t))
2371 (goto-char (point-min))
2372 (while (re-search-forward "\r+$" nil t)
2373 (replace-match "" t t))
2374 (goto-char (point-min))
2375 (while (search-forward "\r" nil t)
2376 (replace-match "\n" t t)))))
2378 (defun article-remove-trailing-blank-lines ()
2379 "Remove all trailing blank lines from the article."
2382 (let ((inhibit-read-only t))
2383 (goto-char (point-max))
2387 (while (and (not (bobp))
2388 (looking-at "^[ \t]*$")
2389 (not (gnus-annotation-in-region-p
2390 (point) (point-at-eol))))
2395 (defvar gnus-face-properties-alist)
2397 (defun article-display-face (&optional force)
2398 "Display any Face headers in the header."
2399 (interactive (list 'force))
2400 (let ((wash-face-p buffer-read-only))
2401 (gnus-with-article-headers
2402 ;; When displaying parts, this function can be called several times on
2403 ;; the same article, without any intended toggle semantic (as typing `W
2404 ;; D d' would have). So face deletion must occur only when we come from
2405 ;; an interactive command, that is when the *Article* buffer is
2407 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2408 (gnus-delete-images 'face)
2409 (let ((from (message-fetch-field "from"))
2411 (save-current-buffer
2412 (when (and wash-face-p
2413 (gnus-buffer-live-p gnus-original-article-buffer)
2414 (not (re-search-forward "^Face:[\t ]*" nil t)))
2415 (set-buffer gnus-original-article-buffer))
2417 (mail-narrow-to-head)
2419 ;; Check whether this face is censored.
2420 (not (and gnus-article-x-face-too-ugly
2422 (setq from (message-fetch-field "from")))
2423 (string-match gnus-article-x-face-too-ugly
2425 (while (gnus-article-goto-header "Face")
2426 (push (mail-header-field-value) faces)))))
2428 (goto-char (point-min))
2430 (unless (setq from (gnus-article-goto-header "from"))
2433 (insert " [no `from' set]\n"))
2435 (when (setq png (gnus-convert-face-to-png (pop faces)))
2437 (apply 'gnus-create-image png 'png t
2438 (cdr (assq 'png gnus-face-properties-alist))))
2441 (gnus-add-wash-type 'face)
2442 (gnus-add-image 'face image)
2443 (gnus-put-image image nil 'face)))))))))))
2445 (defun article-display-x-face (&optional force)
2446 "Look for an X-Face header and display it if present."
2447 (interactive (list 'force))
2448 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2449 (gnus-with-article-headers
2450 ;; Delete the old process, if any.
2451 (when (process-status "article-x-face")
2452 (delete-process "article-x-face"))
2453 ;; See the comment in `article-display-face'.
2454 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2455 ;; We have already displayed X-Faces, so we remove them
2457 (gnus-delete-images 'xface)
2459 (let ((from (message-fetch-field "from"))
2461 (save-current-buffer
2462 (when (and wash-face-p
2463 (gnus-buffer-live-p gnus-original-article-buffer)
2464 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2465 ;; If type `W f', use gnus-original-article-buffer,
2466 ;; otherwise use the current buffer because displaying
2467 ;; RFC822 parts calls this function too.
2468 (set-buffer gnus-original-article-buffer))
2470 (mail-narrow-to-head)
2471 (and gnus-article-x-face-command
2473 ;; Check whether this face is censored.
2474 (not (and gnus-article-x-face-too-ugly
2476 (setq from (message-fetch-field "from")))
2477 (string-match gnus-article-x-face-too-ugly
2479 (while (gnus-article-goto-header "X-Face")
2480 (push (mail-header-field-value) x-faces)))))
2482 ;; We display the face.
2483 (cond ((functionp gnus-article-x-face-command)
2484 ;; The command is a lisp function, so we call it.
2485 (mapc gnus-article-x-face-command x-faces))
2486 ((stringp gnus-article-x-face-command)
2487 ;; The command is a string, so we interpret the command
2488 ;; as a, well, command, and fork it off.
2489 (let ((process-connection-type nil))
2490 (gnus-set-process-query-on-exit-flag
2492 "article-x-face" nil shell-file-name
2493 shell-command-switch gnus-article-x-face-command)
2495 ;; Sending multiple EOFs to xv doesn't work,
2496 ;; so we only do a single external face.
2498 (insert (car x-faces))
2499 (process-send-region "article-x-face"
2500 (point-min) (point-max)))
2501 (process-send-eof "article-x-face")))
2503 (error "`%s' set to `%s' is not a function"
2504 gnus-article-x-face-command
2505 'gnus-article-x-face-command)))))))))
2507 (defun article-decode-mime-words ()
2508 "Decode all MIME-encoded words in the article."
2510 (gnus-with-article-buffer
2511 (let ((inhibit-point-motion-hooks t)
2512 (mail-parse-charset gnus-newsgroup-charset)
2513 (mail-parse-ignored-charsets
2514 (with-current-buffer gnus-summary-buffer
2515 gnus-newsgroup-ignored-charsets)))
2516 (mail-decode-encoded-word-region (point-min) (point-max)))))
2518 (defun article-decode-charset (&optional prompt)
2519 "Decode charset-encoded text in the article.
2520 If PROMPT (the prefix), prompt for a coding system to use."
2522 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2523 (inhibit-read-only t)
2524 (mail-parse-charset gnus-newsgroup-charset)
2525 (mail-parse-ignored-charsets
2526 (save-excursion (condition-case nil
2527 (set-buffer gnus-summary-buffer)
2529 gnus-newsgroup-ignored-charsets))
2530 ct cte ctl charset format)
2533 (article-narrow-to-head)
2534 (setq ct (message-fetch-field "Content-Type" t)
2535 cte (message-fetch-field "Content-Transfer-Encoding" t)
2536 ctl (and ct (mail-header-parse-content-type ct))
2539 (mm-read-coding-system "Charset to decode: "))
2541 (mail-content-type-get ctl 'charset)))
2542 format (and ctl (mail-content-type-get ctl 'format)))
2544 (setq cte (mail-header-strip cte)))
2545 (if (and ctl (not (string-match "/" (car ctl))))
2547 (goto-char (point-max)))
2550 (narrow-to-region (point) (point-max))
2551 (when (and (eq mail-parse-charset 'gnus-decoded)
2552 (eq (mm-body-7-or-8) '8bit))
2553 ;; The text code could have been decoded.
2554 (setq charset mail-parse-charset))
2555 (when (and (or (not ctl)
2556 (equal (car ctl) "text/plain"))
2557 (not format)) ;; article with format will decode later.
2559 charset (and cte (intern (downcase
2560 (gnus-strip-whitespace cte))))
2563 (defun article-decode-encoded-words ()
2564 "Remove encoded-word encoding from headers."
2565 (let ((inhibit-point-motion-hooks t)
2566 (mail-parse-charset gnus-newsgroup-charset)
2567 (mail-parse-ignored-charsets
2568 (save-excursion (condition-case nil
2569 (set-buffer gnus-summary-buffer)
2571 gnus-newsgroup-ignored-charsets))
2572 (inhibit-read-only t)
2574 (goto-char (point-min))
2575 (when (search-forward "\n\n" nil 'move)
2582 (memq (char-after) '(?\t ? )))))
2583 (setq start (point))
2585 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2586 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2587 (funcall gnus-decode-address-function start end)
2588 (funcall gnus-decode-header-function start end))
2589 (goto-char (setq end start)))))
2591 (defun article-decode-group-name ()
2592 "Decode group names in Newsgroups, Followup-To and Xref headers."
2593 (let ((inhibit-point-motion-hooks t)
2594 (inhibit-read-only t)
2595 (method (gnus-find-method-for-group gnus-newsgroup-name))
2597 (when (and (or gnus-group-name-charset-method-alist
2598 gnus-group-name-charset-group-alist)
2599 (gnus-buffer-live-p gnus-original-article-buffer))
2601 (article-narrow-to-head)
2602 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2603 (with-current-buffer gnus-original-article-buffer
2604 (goto-char (point-min)))
2605 (setq regexp (concat "^" header
2606 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2607 (while (re-search-forward regexp nil t)
2608 (replace-match (save-match-data
2609 (gnus-decode-newsgroups
2610 ;; XXX how to use data in article buffer?
2611 (with-current-buffer gnus-original-article-buffer
2612 (re-search-forward regexp nil t)
2614 gnus-newsgroup-name method))
2616 (goto-char (point-min)))))))
2618 (autoload 'idna-to-unicode "idna")
2620 (defun article-decode-idna-rhs ()
2621 "Decode IDNA strings in RHS in various headers in current buffer.
2622 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2623 Mail-Reply-To: and Mail-Followup-To:."
2626 (let ((inhibit-point-motion-hooks t)
2627 (inhibit-read-only t))
2628 (article-narrow-to-head)
2629 (goto-char (point-min))
2630 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2632 (when (save-match-data
2633 (and (setq ace (match-string 1))
2635 (and (re-search-backward "^[^ \t]" nil t)
2636 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2637 (setq unicode (idna-to-unicode ace))))
2638 (unless (string= ace unicode)
2639 (replace-match unicode nil nil nil 1)))))))))
2641 (defun article-de-quoted-unreadable (&optional force read-charset)
2642 "Translate a quoted-printable-encoded article.
2643 If FORCE, decode the article whether it is marked as quoted-printable
2645 If READ-CHARSET, ask for a coding system."
2646 (interactive (list 'force current-prefix-arg))
2648 (let ((inhibit-read-only t) type charset)
2649 (if (gnus-buffer-live-p gnus-original-article-buffer)
2650 (with-current-buffer gnus-original-article-buffer
2652 (gnus-fetch-field "content-transfer-encoding"))
2653 (let* ((ct (gnus-fetch-field "content-type"))
2654 (ctl (and ct (mail-header-parse-content-type ct))))
2655 (setq charset (and ctl
2656 (mail-content-type-get ctl 'charset)))
2657 (if (stringp charset)
2658 (setq charset (intern (downcase charset)))))))
2660 (setq charset (mm-read-coding-system "Charset: " charset)))
2662 (setq charset gnus-newsgroup-charset))
2664 (and type (let ((case-fold-search t))
2665 (string-match "quoted-printable" type))))
2667 (quoted-printable-decode-region
2668 (point) (point-max) (mm-charset-to-coding-system charset))))))
2670 (defun article-de-base64-unreadable (&optional force read-charset)
2671 "Translate a base64 article.
2672 If FORCE, decode the article whether it is marked as base64 not.
2673 If READ-CHARSET, ask for a coding system."
2674 (interactive (list 'force current-prefix-arg))
2676 (let ((inhibit-read-only t) type charset)
2677 (if (gnus-buffer-live-p gnus-original-article-buffer)
2678 (with-current-buffer gnus-original-article-buffer
2680 (gnus-fetch-field "content-transfer-encoding"))
2681 (let* ((ct (gnus-fetch-field "content-type"))
2682 (ctl (and ct (mail-header-parse-content-type ct))))
2683 (setq charset (and ctl
2684 (mail-content-type-get ctl 'charset)))
2685 (if (stringp charset)
2686 (setq charset (intern (downcase charset)))))))
2688 (setq charset (mm-read-coding-system "Charset: " charset)))
2690 (setq charset gnus-newsgroup-charset))
2692 (and type (let ((case-fold-search t))
2693 (string-match "base64" type))))
2696 (narrow-to-region (point) (point-max))
2697 (base64-decode-region (point-min) (point-max))
2698 (mm-decode-coding-region
2699 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2704 (defun article-decode-HZ ()
2705 "Translate a HZ-encoded article."
2709 (let ((inhibit-read-only t))
2710 (rfc1843-decode-region (point-min) (point-max)))))
2712 (defun article-unsplit-urls ()
2713 "Remove the newlines that some other mailers insert into URLs."
2716 (let ((inhibit-read-only t))
2717 (goto-char (point-min))
2718 (while (re-search-forward
2719 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2720 (replace-match "\\1\\3" t)))
2721 (when (interactive-p)
2722 (gnus-treat-article nil))))
2724 (defun article-wash-html ()
2725 "Format an HTML article."
2728 (buffer-read-only nil))
2729 (when (gnus-buffer-live-p gnus-original-article-buffer)
2730 (with-current-buffer gnus-original-article-buffer
2731 (setq handles (mm-dissect-buffer t t))))
2733 (delete-region (point) (point-max))
2734 (mm-enable-multibyte)
2735 (mm-inline-text-html handles)))
2737 (defvar gnus-article-browse-html-temp-list nil
2738 "List of temporary files created by `gnus-article-browse-html-parts'.
2739 Internal variable.")
2741 (defcustom gnus-article-browse-delete-temp 'ask
2742 "What to do with temporary files from `gnus-article-browse-html-parts'.
2743 If nil, don't delete temporary files. If it is t, delete them on
2744 exit from the summary buffer. If it is the symbol `file', query
2745 on each file, if it is `ask' ask once when exiting from the
2747 :group 'gnus-article
2748 :version "23.1" ;; No Gnus
2749 :type '(choice (const :tag "Don't delete" nil)
2750 (const :tag "Don't ask" t)
2751 (const :tag "Ask" ask)
2752 (const :tag "Ask for each file" file)))
2754 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2756 (defun gnus-article-browse-delete-temp-files (&optional how)
2757 "Delete temp-files created by `gnus-article-browse-html-parts'."
2758 (when (and gnus-article-browse-html-temp-list
2760 (or how (setq how gnus-article-browse-delete-temp))
2762 (let* ((files (length gnus-article-browse-html-temp-list))
2765 "Delete the temporary HTML file? "
2767 "Delete all %s temporary HTML files? "
2770 (setq gnus-article-browse-html-temp-list nil)))
2772 (dolist (file gnus-article-browse-html-temp-list)
2773 (cond ((file-directory-p file)
2774 (when (or (not (eq how 'file))
2777 "Delete temporary HTML file(s) in directory `%s'? "
2778 (file-name-as-directory file))))
2779 (gnus-delete-directory file)))
2780 ((file-exists-p file)
2781 (when (or (not (eq how 'file))
2783 (format "Delete temporary HTML file `%s'? " file)))
2784 (delete-file file)))))
2785 ;; Also remove file from the list when not deleted or if file doesn't
2787 (setq gnus-article-browse-html-temp-list nil))
2788 gnus-article-browse-html-temp-list)
2790 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2791 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2796 (dolist (handle handles)
2798 ((not (listp handle)))
2799 ((equal (mm-handle-media-supertype handle) "multipart")
2800 (when (setq file (gnus-article-browse-html-save-cid-content
2801 cid handle directory))
2802 (throw 'found file)))
2803 ((equal (concat "<" cid ">") (mm-handle-id handle))
2806 (or (mm-handle-filename handle)
2808 (make-temp-name "cid")
2809 (car (rassoc (car (mm-handle-type handle)) mailcap-mime-extensions))))
2811 (mm-save-part-to-file handle file)
2812 (throw 'found file))))))))
2814 (defun gnus-article-browse-html-parts (list &optional header)
2815 "View all \"text/html\" parts from LIST.
2816 Recurse into multiparts. The optional HEADER that should be a decoded
2817 message header will be added to the bodies of the \"text/html\" parts."
2818 ;; Internal function used by `gnus-article-browse-html-article'.
2819 (let (type file charset content cid-dir tmp-file showed)
2820 ;; Find and show the html-parts.
2821 (dolist (handle list)
2822 ;; If HTML, show it:
2823 (cond ((not (listp handle)))
2824 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2825 (and (equal (car type) "message/external-body")
2827 (setq file (mm-handle-filename handle)))
2828 (or (mm-handle-cache handle)
2829 (condition-case code
2830 (progn (mm-extern-cache-contents handle) t)
2832 (gnus-message 3 "%s" (error-message-string code))
2833 (when (>= gnus-verbose 3) (sit-for 2))
2836 (setq handle (mm-handle-cache handle)
2837 type (mm-handle-type handle))
2838 (equal (car type) "text/html"))))
2839 (setq charset (mail-content-type-get type 'charset)
2840 content (mm-get-part handle))
2842 (if (eq charset 'gnus-decoded)
2843 (mm-enable-multibyte)
2844 (mm-disable-multibyte))
2846 ;; resolve cid contents
2847 (let ((case-fold-search t)
2849 (goto-char (point-min))
2850 (while (re-search-forward "\
2851 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2854 (setq cid-dir (mm-make-temp-file "cid" t))
2855 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2858 (when (setq cid-file
2859 (gnus-article-browse-html-save-cid-content
2861 (with-current-buffer gnus-article-buffer
2862 gnus-article-mime-handles)
2864 (when (eq system-type 'cygwin)
2866 (concat "/" (substring
2867 (with-output-to-string
2868 (call-process "cygpath" nil
2872 (replace-match (concat "file://" cid-file)
2874 (unless content (setq content (buffer-string))))
2875 (when (or charset header (not file))
2876 (setq tmp-file (mm-make-temp-file
2877 ;; Do we need to care for 8.3 filenames?
2878 "mm-" nil ".html")))
2879 ;; Add a meta html tag to specify charset and a header.
2882 (let (title eheader body hcharset coding force-charset)
2884 (mm-enable-multibyte)
2885 (setq case-fold-search t)
2886 (insert header "\n")
2887 (setq title (message-fetch-field "subject"))
2888 (goto-char (point-min))
2889 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2890 (replace-match (cond ((match-beginning 1) "<")
2891 ((match-beginning 2) ">")
2893 (goto-char (point-min))
2895 (goto-char (point-max))
2896 (insert "</pre>\n<hr>\n")
2897 ;; We have to examine charset one by one since
2898 ;; charset specified in parts might be different.
2899 (if (eq charset 'gnus-decoded)
2900 (setq charset 'utf-8
2901 eheader (mm-encode-coding-string (buffer-string)
2904 (mm-encode-coding-string title charset))
2905 body (mm-encode-coding-string content charset)
2907 (setq hcharset (mm-find-mime-charset-region (point-min)
2909 (cond ((= (length hcharset) 1)
2910 (setq hcharset (car hcharset)
2911 coding (mm-charset-to-coding-system
2913 ((> (length hcharset) 1)
2914 (setq hcharset 'utf-8
2920 (mm-charset-to-coding-system charset))
2921 (if (eq coding body)
2922 (setq eheader (mm-encode-coding-string
2923 (buffer-string) coding)
2925 (mm-encode-coding-string
2928 (setq charset 'utf-8
2929 eheader (mm-encode-coding-string
2930 (buffer-string) charset)
2932 (mm-encode-coding-string
2934 body (mm-encode-coding-string
2935 (mm-decode-coding-string
2939 (setq charset hcharset
2940 eheader (mm-encode-coding-string
2941 (buffer-string) coding)
2943 (mm-encode-coding-string
2946 (setq eheader (mm-string-as-unibyte (buffer-string))
2949 (mm-disable-multibyte)
2952 (mm-add-meta-html-tag handle charset force-charset))
2954 (goto-char (point-min))
2955 (unless (search-forward "<title>" nil t)
2956 (re-search-forward "<head>\\s-*" nil t)
2957 (insert "<title>" title "</title>\n")))
2958 (goto-char (point-min))
2959 (or (re-search-forward
2960 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2962 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2964 (mm-write-region (point-min) (point-max)
2965 tmp-file nil nil nil 'binary t))))
2967 (mm-with-unibyte-buffer
2968 (insert (if (eq charset 'gnus-decoded)
2969 (mm-encode-coding-string content
2970 (setq charset 'utf-8))
2972 (if (or (mm-add-meta-html-tag handle charset)
2974 (mm-write-region (point-min) (point-max)
2975 tmp-file nil nil nil 'binary t)
2976 (setq tmp-file nil))))
2978 (mm-save-part-to-file handle tmp-file)))
2980 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2981 (add-hook 'gnus-summary-prepare-exit-hook
2982 'gnus-article-browse-delete-temp-files)
2983 (add-hook 'gnus-exit-gnus-hook
2985 (gnus-article-browse-delete-temp-files t)))
2986 ;; FIXME: Warn if there's an <img> tag?
2987 (browse-url-of-file (or tmp-file (expand-file-name file)))
2989 ;; If multipart, recurse
2990 ((equal (mm-handle-media-supertype handle) "multipart")
2991 (when (gnus-article-browse-html-parts handle header)
2993 ((equal (mm-handle-media-type handle) "message/rfc822")
2994 (mm-with-multibyte-buffer
2995 (mm-insert-part handle)
2996 (setq handle (mm-dissect-buffer t t))
2997 (when (and (bufferp (car handle))
2998 (stringp (car (mm-handle-type handle))))
2999 (setq handle (list handle)))
3001 (article-decode-encoded-words)
3002 (let ((gnus-visible-headers
3003 (or (get 'gnus-visible-headers 'standard-value)
3004 gnus-visible-headers)))
3005 (article-hide-headers))
3006 (goto-char (point-min))
3007 (search-forward "\n\n" nil 'move)
3008 (skip-chars-backward "\t\n ")
3009 (setq header (buffer-substring (point-min) (point)))))
3011 (gnus-article-browse-html-parts handle header)
3012 (mm-destroy-parts handle))
3016 (defun gnus-article-browse-html-article (&optional arg)
3017 "View \"text/html\" parts of the current article with a WWW browser.
3018 Inline images embedded in a message using the cid scheme, as they are
3019 generally considered to be safe, will be processed properly.
3020 The message header is added to the beginning of every html part unless
3021 the prefix argument ARG is given.
3023 Warning: Spammers use links to images (using the http scheme) in HTML
3024 articles to verify whether you have read the message. As
3025 `gnus-article-browse-html-article' passes the HTML content to the
3026 browser without eliminating these \"web bugs\" you should only
3027 use it for mails from trusted senders.
3029 If you always want to display HTML parts in the browser, set
3030 `mm-text-html-renderer' to nil.
3032 This command creates temporary files to pass HTML contents including
3033 images if any to the browser, and deletes them when exiting the group
3035 ;; Cf. `mm-w3m-safe-url-regexp'
3038 (gnus-summary-show-article)
3039 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3040 gnus-visible-headers))
3041 ;; As we insert a <hr>, there's no need for the body boundary.
3042 (gnus-treat-body-boundary nil))
3043 (gnus-summary-show-article)))
3044 (with-current-buffer gnus-article-buffer
3045 (let ((header (unless arg
3048 (buffer-substring-no-properties
3049 (goto-char (point-min))
3050 (if (search-forward "\n\n" nil t)
3052 (goto-char (point-max))
3053 (skip-chars-backward "\t\n ")
3056 (set-buffer gnus-original-article-buffer)
3057 (setq parts (mm-dissect-buffer t t))
3058 ;; If singlepart, enforce a list.
3059 (when (and (bufferp (car parts))
3060 (stringp (car (mm-handle-type parts))))
3061 (setq parts (list parts)))
3063 (unless (gnus-article-browse-html-parts parts header)
3064 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3065 (mm-destroy-parts parts)
3067 (gnus-summary-show-article)))))
3069 (defun article-hide-list-identifiers ()
3070 "Remove list identifies from the Subject header.
3071 The `gnus-list-identifiers' variable specifies what to do."
3073 (let ((inhibit-point-motion-hooks t)
3074 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3075 (inhibit-read-only t))
3079 (article-narrow-to-head)
3080 (goto-char (point-min))
3081 (while (re-search-forward
3082 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3084 (delete-region (match-beginning 2) (match-end 0))
3085 (beginning-of-line))
3086 (when (re-search-forward
3087 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3088 (delete-region (match-beginning 1) (match-end 1))))))))
3090 (defun article-hide-pem (&optional arg)
3091 "Toggle hiding of any PEM headers and signatures in the current article.
3092 If given a negative prefix, always show; if given a positive prefix,
3094 (interactive (gnus-article-hidden-arg))
3095 (unless (gnus-article-check-hidden-text 'pem arg)
3097 (let ((inhibit-read-only t) end)
3098 (goto-char (point-min))
3099 ;; Hide the horrendously ugly "header".
3100 (when (and (search-forward
3101 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3103 (setq end (1+ (match-beginning 0))))
3104 (gnus-add-wash-type 'pem)
3105 (gnus-article-hide-text-type
3107 (if (search-forward "\n\n" nil t)
3111 ;; Hide the trailer as well
3112 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3114 (gnus-article-hide-text-type
3115 (match-beginning 0) (match-end 0) 'pem)))))))
3117 (defun article-strip-banner ()
3118 "Strip the banners specified by the `banner' group parameter and by
3119 `gnus-article-address-banner-alist'."
3123 (let ((inhibit-point-motion-hooks t))
3124 (when (gnus-parameter-banner gnus-newsgroup-name)
3125 (article-really-strip-banner
3126 (gnus-parameter-banner gnus-newsgroup-name)))
3127 (when gnus-article-address-banner-alist
3128 ;; Note that the From header is decoded here, so it is
3129 ;; required that the *-extract-address-components function
3130 ;; supports non-ASCII text.
3131 (let ((from (save-restriction
3133 (article-narrow-to-head)
3134 (mail-fetch-field "from"))))
3137 (cadr (funcall gnus-extract-address-components
3140 (dolist (pair gnus-article-address-banner-alist)
3141 (when (string-match (car pair) from)
3143 (article-really-strip-banner (cdr pair)))))))))))))
3145 (defun article-really-strip-banner (banner)
3146 "Strip the banner specified by the argument."
3149 (let ((inhibit-point-motion-hooks t)
3150 (gnus-signature-limit nil)
3151 (inhibit-read-only t))
3154 ((eq banner 'signature)
3155 (when (gnus-article-narrow-to-signature)
3158 (delete-region (point) (point-max))))
3160 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3161 (while (re-search-forward banner nil t)
3162 (delete-region (match-beginning 0) (match-end 0)))))
3164 (while (re-search-forward banner nil t)
3165 (delete-region (match-beginning 0) (match-end 0)))))))))
3167 (defun article-babel ()
3168 "Translate article using an online translation service."
3171 (gnus-with-article-buffer
3172 (when (article-goto-body)
3173 (let* ((start (point))
3175 (orig (buffer-substring start end))
3176 (trans (babel-as-string orig)))
3178 (narrow-to-region start end)
3179 (delete-region start end)
3182 (defun article-hide-signature (&optional arg)
3183 "Hide the signature in the current article.
3184 If given a negative prefix, always show; if given a positive prefix,
3186 (interactive (gnus-article-hidden-arg))
3187 (unless (gnus-article-check-hidden-text 'signature arg)
3190 (let ((inhibit-read-only t))
3191 (when (gnus-article-narrow-to-signature)
3192 (gnus-article-hide-text-type
3193 (point-min) (point-max) 'signature))))))
3194 (gnus-set-mode-line 'article))
3196 (defun article-strip-headers-in-body ()
3197 "Strip offensive headers from bodies."
3201 (let ((case-fold-search t))
3202 (when (looking-at "x-no-archive:")
3203 (gnus-delete-line)))))
3205 (defun article-strip-leading-blank-lines ()
3206 "Remove all blank lines from the beginning of the article."
3209 (let ((inhibit-point-motion-hooks t)
3210 (inhibit-read-only t))
3211 (when (article-goto-body)
3212 (while (and (not (eobp))
3213 (looking-at "[ \t]*$"))
3214 (gnus-delete-line))))))
3216 (defun article-narrow-to-head ()
3217 "Narrow the buffer to the head of the message.
3218 Point is left at the beginning of the narrowed-to region."
3220 (goto-char (point-min))
3222 ;; Absolutely no headers displayed.
3226 ((search-forward "\n\n" nil 1)
3228 ;; Nothing but headers.
3231 (goto-char (point-min)))
3233 (defun article-goto-body ()
3234 "Place point at the start of the body."
3235 (goto-char (point-min))
3237 ;; This variable is only bound when dealing with separate
3239 (article-goto-body-goes-to-point-min-p
3241 ((search-forward "\n\n" nil t)
3244 (goto-char (point-max))
3247 (defun article-strip-multiple-blank-lines ()
3248 "Replace consecutive blank lines with one empty line."
3251 (let ((inhibit-point-motion-hooks t)
3252 (inhibit-read-only t))
3253 ;; First make all blank lines empty.
3255 (while (re-search-forward "^[ \t]+$" nil t)
3256 (unless (gnus-annotation-in-region-p
3257 (match-beginning 0) (match-end 0))
3258 (replace-match "" nil t)))
3259 ;; Then replace multiple empty lines with a single empty line.
3261 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3262 (unless (gnus-annotation-in-region-p
3263 (match-beginning 0) (match-end 0))
3264 (delete-region (match-beginning 1) (match-end 1)))))))
3266 (defun article-strip-leading-space ()
3267 "Remove all white space from the beginning of the lines in the article."
3270 (let ((inhibit-point-motion-hooks t)
3271 (inhibit-read-only t))
3273 (while (re-search-forward "^[ \t]+" nil t)
3274 (replace-match "" t t)))))
3276 (defun article-strip-trailing-space ()
3277 "Remove all white space from the end of the lines in the article."
3280 (let ((inhibit-point-motion-hooks t)
3281 (inhibit-read-only t))
3283 (while (re-search-forward "[ \t]+$" nil t)
3284 (replace-match "" t t)))))
3286 (defun article-strip-blank-lines ()
3287 "Strip leading, trailing and multiple blank lines."
3289 (article-strip-leading-blank-lines)
3290 (article-remove-trailing-blank-lines)
3291 (article-strip-multiple-blank-lines))
3293 (defun article-strip-all-blank-lines ()
3294 "Strip all blank lines."
3297 (let ((inhibit-point-motion-hooks t)
3298 (inhibit-read-only t))
3300 (while (re-search-forward "^[ \t]*\n" nil t)
3301 (replace-match "" t t)))))
3303 (defun gnus-article-narrow-to-signature ()
3304 "Narrow to the signature; return t if a signature is found, else nil."
3305 (let ((inhibit-point-motion-hooks t))
3306 (when (gnus-article-search-signature)
3308 ;; Check whether we have some limits to what we consider
3309 ;; to be a signature.
3310 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3311 (list gnus-signature-limit)))
3313 (while (setq limit (pop limits))
3314 (if (or (and (integerp limit)
3315 (< (- (point-max) (point)) limit))
3317 (< (count-lines (point) (point-max)) limit))
3318 (and (functionp limit)
3320 (and (stringp limit)
3321 (not (re-search-forward limit nil t))))
3322 () ; This limit did not succeed.
3326 (narrow-to-region (point) (point-max))
3329 (defun gnus-article-search-signature ()
3330 "Search the current buffer for the signature separator.
3331 Put point at the beginning of the signature separator."
3332 (let ((cur (point)))
3333 (goto-char (point-max))
3334 (if (if (stringp gnus-signature-separator)
3335 (re-search-backward gnus-signature-separator nil t)
3336 (let ((seps gnus-signature-separator))
3338 (not (re-search-backward (car seps) nil t)))
3345 (defun gnus-article-hidden-arg ()
3346 "Return the current prefix arg as a number, or 0 if no prefix."
3347 (list (if current-prefix-arg
3348 (prefix-numeric-value current-prefix-arg)
3351 (defun gnus-article-check-hidden-text (type arg)
3352 "Return nil if hiding is necessary.
3353 Arg can be nil or a number. nil and positive means hide, negative
3354 means show, 0 means toggle."
3357 (let ((hide (gnus-article-hidden-text-p type)))
3363 (gnus-article-show-hidden-text type)
3366 (if (eq hide 'hidden)
3368 (gnus-article-show-hidden-text type)
3372 (defun gnus-article-hidden-text-p (type)
3373 "Say whether the current buffer contains hidden text of type TYPE."
3374 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3376 (not (get-text-property pos 'invisible))
3377 (not (get-text-property pos 'dummy-invisible)))
3379 (text-property-any (1+ pos) (point-max) 'article-type type)))
3384 (defun gnus-article-show-hidden-text (type &optional dummy)
3385 "Show all hidden text of type TYPE.
3386 Originally it is hide instead of DUMMY."
3387 (let ((inhibit-read-only t)
3388 (inhibit-point-motion-hooks t))
3389 (gnus-remove-text-properties-when
3391 (point-min) (point-max)
3392 (cons 'article-type (cons type
3393 gnus-hidden-properties)))
3394 (gnus-delete-wash-type type)))
3396 (defconst article-time-units
3397 `((year . ,(* 365.25 24 60 60))
3398 (week . ,(* 7 24 60 60))
3399 (day . ,(* 24 60 60))
3403 "Mapping from time units to seconds.")
3405 (defun gnus-article-forward-header ()
3406 "Move point to the start of the next header.
3407 If the current header is a continuation header, this can be several
3412 (if (looking-at "[ \t]+[^ \t]")
3416 (defun article-treat-date ()
3417 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3418 (with-current-buffer gnus-summary-buffer
3419 gnus-article-date-headers)
3420 gnus-article-date-headers)
3423 (defun article-date-ut (&optional type highlight date-position)
3424 "Convert DATE date to TYPE in the current article.
3425 The default type is `ut'. See `gnus-article-date-headers' for
3427 (interactive (list 'ut t))
3428 (let* ((case-fold-search t)
3429 (inhibit-read-only t)
3430 (inhibit-point-motion-hooks t)
3432 (visible-date (mail-fetch-field "Date"))
3433 pos date bface eface)
3435 (goto-char (point-min))
3436 (when (re-search-forward "^Date:" nil t)
3437 (setq bface (get-text-property (point-at-bol) 'face)
3438 eface (get-text-property (1- (point-at-eol)) 'face)))
3439 ;; Delete any old Date headers.
3442 (goto-char date-position)
3443 (setq date (get-text-property (point) 'original-date))
3444 (delete-region (point)
3446 (gnus-article-forward-header)
3448 (article-transform-date date type bface eface))
3451 (goto-char (point-min))
3452 (while (or (get-text-property (setq pos (point)) 'original-date)
3453 (and (setq pos (next-single-property-change
3454 (point) 'original-date))
3456 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3457 (1+ (match-beginning 0))
3459 (goto-char (point-min))
3460 (while (re-search-forward "^Date:" nil t)
3461 (setq date (get-text-property (match-beginning 0) 'original-date))
3462 (delete-region (point-at-bol) (progn
3463 (gnus-article-forward-header)
3465 (when (and (not date)
3467 (setq date visible-date))
3469 (article-transform-date date type bface eface))
3470 (goto-char (point-max))
3473 (defun article-transform-date (date type bface eface)
3474 (dolist (this-type (cond
3481 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3484 (put-text-property (point) (1+ (point))
3485 'original-date date)
3486 (put-text-property (point) (1+ (point))
3487 'gnus-date-type this-type)
3489 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3490 (put-text-property (match-beginning 1) (1+ (match-end 1))
3492 (put-text-property (match-beginning 2) (match-end 2)
3496 (defun article-make-date-line (date type)
3497 "Return a DATE line of TYPE."
3498 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3500 (error "Unknown conversion type: %s" type))
3502 (let ((time (ignore-errors (date-to-time date))))
3504 ;; Convert to the local timezone.
3506 (concat "Date: " (message-make-date time)))
3507 ;; Convert to Universal Time.
3512 (let* ((e (parse-time-string date))
3513 (tm (apply 'encode-time e))
3515 (ls (- (cadr tm) (car (current-time-zone time)))))
3516 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3517 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3521 ;; Get the original date from the article.
3522 ((eq type 'original)
3523 (concat "Date: " (if (string-match "\n+$" date)
3524 (substring date 0 (match-beginning 0))
3526 ;; Let the user define the format.
3527 ((eq type 'user-defined)
3528 (let ((format (or (condition-case nil
3529 (with-current-buffer gnus-summary-buffer
3530 gnus-article-time-format)
3532 gnus-article-time-format)))
3533 (if (functionp format)
3534 (funcall format time)
3535 (concat "Date: " (format-time-string format time)))))
3538 (let ((tz (car (current-time-zone time))))
3541 (format-time-string "%Y%m%dT%H%M%S" time)
3542 (format "%s%02d%02d"
3543 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3544 (/ (% (abs tz) 3600) 60)))))
3545 ;; Do a lapsed format.
3547 (concat "Date: " (article-lapsed-string time)))
3548 ;; A combined date/lapsed format.
3549 ((eq type 'combined-lapsed)
3550 (let ((date-string (article-make-date-line date 'original))
3556 (concat " (" (article-lapsed-string time segments) ")"))
3557 (> (+ (length date-string)
3558 (length lapsed-string))
3561 (setq segments (1- segments)))
3563 (concat date-string lapsed-string)
3565 ;; Display the date in proper English
3567 (let ((dtime (decode-time time)))
3570 (number-to-string (nth 3 dtime))
3571 (let ((digit (% (nth 3 dtime) 10)))
3573 ((memq (nth 3 dtime) '(11 12 13)) "th")
3579 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3581 (number-to-string (nth 5 dtime))
3583 (format "%02d" (nth 2 dtime))
3585 (format "%02d" (nth 1 dtime)))))))
3587 (format "Date: %s (from Gnus)" date))))
3589 (defun article-lapsed-string (time &optional max-segments)
3590 ;; If the date is seriously mangled, the timezone functions are
3591 ;; liable to bug out, so we ignore all errors.
3592 (let* ((now (current-time))
3593 (real-time (subtract-time now time))
3594 (real-sec (and real-time
3595 (+ (* (float (car real-time)) 65536)
3597 (sec (and real-time (abs real-sec)))
3600 (unless max-segments
3601 (setq max-segments (length article-time-units)))
3609 ;; This is a bit convoluted, but basically we go
3610 ;; through the time units for years, weeks, etc,
3611 ;; and divide things to see whether that results
3612 ;; in positive answers.
3615 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3616 (>= segments max-segments))
3617 ;; The (remaining) seconds are too few to
3618 ;; be divided into this time unit.
3620 ;; It's big enough, so we output it.
3621 (setq sec (- sec (* num (cdr unit))))
3623 (concat (if prev ", " "") (int-to-string
3625 " " (symbol-name (car unit))
3626 (if (> num 1) "s" ""))
3628 segments (1+ segments)))))
3629 article-time-units "")
3630 ;; If dates are odd, then it might appear like the
3631 ;; article was sent in the future.
3634 " in the future"))))))
3636 (defun article-date-local (&optional highlight)
3637 "Convert the current article date to the local timezone."
3638 (interactive (list t))
3639 (article-date-ut 'local highlight))
3641 (defun article-date-english (&optional highlight)
3642 "Convert the current article date to something that is proper English."
3643 (interactive (list t))
3644 (article-date-ut 'english highlight))
3646 (defun article-date-original (&optional highlight)
3647 "Convert the current article date to what it was originally.
3648 This is only useful if you have used some other date conversion
3649 function and want to see what the date was before converting."
3650 (interactive (list t))
3651 (article-date-ut 'original highlight))
3653 (defun article-date-lapsed (&optional highlight)
3654 "Convert the current article date to time lapsed since it was sent."
3655 (interactive (list t))
3656 (article-date-ut 'lapsed highlight))
3658 (defun article-date-combined-lapsed (&optional highlight)
3659 "Convert the current article date to time lapsed since it was sent."
3660 (interactive (list t))
3661 (article-date-ut 'combined-lapsed highlight))
3663 (defun article-update-date-lapsed ()
3664 "Function to be run from a timer to update the lapsed time line."
3666 (let ((buffer (current-buffer)))
3670 (set-buffer (window-buffer w))
3671 (when (eq major-mode 'gnus-article-mode)
3672 (let ((old-line (count-lines (point-min) (point)))
3673 (old-column (- (point) (line-beginning-position)))
3675 (window-start (get-buffer-window (current-buffer)))))
3676 (goto-char (point-min))
3677 (while (re-search-forward "^Date:" nil t)
3678 (let ((type (get-text-property (match-beginning 0)
3680 (when (memq type '(lapsed combined-lapsed user-format))
3681 (when (and window-start
3682 (not (= window-start
3686 (setq window-start nil))
3688 (article-date-ut type t (match-beginning 0)))
3691 (set-window-start (get-buffer-window (current-buffer))
3693 (goto-char (point-min))
3694 (when (> old-column 0)
3695 (setq old-line (1- old-line)))
3696 (forward-line old-line)
3698 (when (> (current-column) old-column)
3700 (forward-char old-column)))))
3702 (set-buffer buffer))))
3704 (defun gnus-start-date-timer (&optional n)
3705 "Start a timer to update the Date headers in the article buffers.
3706 The numerical prefix says how frequently (in seconds) the function
3711 (gnus-stop-date-timer)
3712 (setq article-lapsed-timer
3713 (run-at-time 1 n 'article-update-date-lapsed)))
3715 (defun gnus-stop-date-timer ()
3716 "Stop the Date timer."
3718 (when article-lapsed-timer
3719 (nnheader-cancel-timer article-lapsed-timer)
3720 (setq article-lapsed-timer nil)))
3722 (defun article-date-user (&optional highlight)
3723 "Convert the current article date to the user-defined format.
3724 This format is defined by the `gnus-article-time-format' variable."
3725 (interactive (list t))
3726 (article-date-ut 'user highlight))
3728 (defun article-date-iso8601 (&optional highlight)
3729 "Convert the current article date to ISO8601."
3730 (interactive (list t))
3731 (article-date-ut 'iso8601 highlight))
3733 (defmacro gnus-article-save-original-date (&rest forms)
3734 "Save the original date as a text property and evaluate FORMS."
3735 `(let* ((case-fold-search t)
3737 (goto-char (point-min))
3738 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3741 (date (when (and start
3742 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3744 (buffer-substring-no-properties start
3745 (match-beginning 0)))))
3746 (goto-char (point-max))
3747 (skip-chars-backward "\n")
3748 (put-text-property (point-min) (point) 'original-date date)
3750 (goto-char (point-max))
3751 (skip-chars-backward "\n")
3752 (put-text-property (point-min) (point) 'original-date date)))
3754 ;; (defun article-show-all ()
3755 ;; "Show all hidden text in the article buffer."
3758 ;; (let ((inhibit-read-only t))
3759 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3761 (defun article-remove-leading-whitespace ()
3762 "Remove excessive whitespace from all headers."
3766 (let ((inhibit-read-only t))
3767 (article-narrow-to-head)
3768 (goto-char (point-min))
3769 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3770 (delete-region (match-beginning 1) (match-end 1)))))))
3772 (defun article-emphasize (&optional arg)
3773 "Emphasize text according to `gnus-emphasis-alist'."
3774 (interactive (gnus-article-hidden-arg))
3775 (unless (gnus-article-check-hidden-text 'emphasis arg)
3779 (with-current-buffer gnus-summary-buffer
3780 gnus-article-emphasis-alist)
3782 gnus-emphasis-alist))
3783 (inhibit-read-only t)
3784 (props (append '(article-type emphasis)
3785 gnus-hidden-properties))
3786 regexp elem beg invisible visible face)
3789 (while (setq elem (pop alist))
3791 (setq regexp (car elem)
3792 invisible (nth 1 elem)
3793 visible (nth 2 elem)
3795 (while (re-search-forward regexp nil t)
3796 (when (and (match-beginning visible) (match-beginning invisible))
3797 (gnus-article-hide-text
3798 (match-beginning invisible) (match-end invisible) props)
3799 (gnus-article-unhide-text-type
3800 (match-beginning visible) (match-end visible) 'emphasis)
3801 (gnus-put-overlay-excluding-newlines
3802 (match-beginning visible) (match-end visible) 'face face)
3803 (gnus-add-wash-type 'emphasis)
3804 (goto-char (match-end invisible)))))))))
3806 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3807 "Setup newsgroup emphasis alist."
3808 (unless gnus-article-emphasis-alist
3809 (let ((name (and gnus-newsgroup-name
3810 (gnus-group-real-name gnus-newsgroup-name))))
3811 (make-local-variable 'gnus-article-emphasis-alist)
3812 (setq gnus-article-emphasis-alist
3814 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3815 (while (setq elem (pop alist))
3816 (when (and name (string-match (car elem) name))
3818 highlight (copy-sequence (cdr elem)))))
3820 (copy-sequence highlight-words)
3821 (if gnus-newsgroup-name
3822 (copy-sequence (gnus-group-find-parameter
3823 gnus-newsgroup-name 'highlight-words t)))
3824 gnus-emphasis-alist)))))
3826 (defvar gnus-summary-article-menu)
3827 (defvar gnus-summary-post-menu)
3829 ;;; Saving functions.
3831 (defun gnus-article-save (save-buffer file &optional num)
3832 "Save the currently selected article."
3833 (when (or (get gnus-default-article-saver :headers)
3834 (not gnus-save-all-headers))
3835 ;; Remove headers according to `gnus-saved-headers' or the value
3836 ;; of the `:headers' property that the saver function might have.
3837 (let ((gnus-visible-headers
3838 (or (symbol-value (get gnus-default-article-saver :headers))
3839 gnus-saved-headers gnus-visible-headers))
3840 ;; Ignore group parameter. See `article-hide-headers'.
3841 (gnus-summary-buffer nil))
3842 (with-current-buffer save-buffer
3843 (article-hide-headers 1 t))))
3844 (save-window-excursion
3845 (if (not gnus-default-article-saver)
3846 (error "No default saver is defined")
3847 ;; !!! Magic! The saving functions all save
3848 ;; `gnus-save-article-buffer' (or so they think), but we
3849 ;; bind that variable to our save-buffer.
3850 (set-buffer gnus-article-buffer)
3851 (let* ((gnus-save-article-buffer save-buffer)
3854 ((not gnus-prompt-before-saving) 'default)
3855 ((eq gnus-prompt-before-saving 'always) nil)
3857 (gnus-number-of-articles-to-be-saved
3858 (when (eq gnus-prompt-before-saving t)
3860 (set-buffer gnus-article-current-summary)
3861 (funcall gnus-default-article-saver filename)))))
3863 (defun gnus-read-save-file-name (prompt &optional filename
3864 function group headers variable
3867 (funcall function group headers (symbol-value variable)))
3872 ((eq filename 'default)
3878 (when (symbol-value dir-var)
3879 (setq default-name (expand-file-name
3880 (file-name-nondirectory default-name)
3881 (symbol-value dir-var))))
3882 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3885 (if (and gnus-number-of-articles-to-be-saved
3886 (> gnus-number-of-articles-to-be-saved 1))
3887 (format "these %d articles"
3888 gnus-number-of-articles-to-be-saved)
3891 ;; Let the split methods have their say.
3893 ;; No split name was found.
3896 (concat prompt " (default "
3897 (file-name-nondirectory default-name) "): ")
3898 (file-name-directory default-name)
3900 ;; A single group name is returned.
3901 ((stringp split-name)
3903 (funcall function split-name headers
3904 (symbol-value variable)))
3906 (concat prompt " (default "
3907 (file-name-nondirectory default-name) "): ")
3908 (file-name-directory default-name)
3910 ;; A single split name was found
3911 ((= 1 (length split-name))
3912 (let* ((name (expand-file-name
3914 gnus-article-save-directory))
3915 (dir (cond ((file-directory-p name)
3916 (file-name-as-directory name))
3917 ((file-exists-p name) name)
3918 (t gnus-article-save-directory))))
3920 (concat prompt " (default " name "): ")
3922 ;; A list of splits was found.
3924 (setq split-name (nreverse split-name))
3926 (let ((file-name-history
3927 (nconc split-name file-name-history)))
3931 (concat prompt " (`M-p' for defaults): ")
3932 gnus-article-save-directory
3934 gnus-article-save-directory)))
3935 (car (push result file-name-history)))))))
3936 ;; Create the directory.
3937 (gnus-make-directory (file-name-directory file))
3938 ;; If we have read a directory, we append the default file name.
3939 (when (file-directory-p file)
3940 (setq file (expand-file-name (file-name-nondirectory
3942 (file-name-as-directory file))))
3943 ;; Possibly translate some characters.
3944 (nnheader-translate-file-chars file))))))
3945 (gnus-make-directory (file-name-directory result))
3947 (set variable result))
3949 (set dir-var (file-name-directory result)))
3952 (defun gnus-article-archive-name (group)
3953 "Return the first instance of an \"Archive-name\" in the current buffer."
3954 (let ((case-fold-search t))
3955 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3956 (nnheader-concat gnus-article-save-directory
3957 (match-string 1)))))
3959 (defun gnus-article-nndoc-name (group)
3960 "If GROUP is an nndoc group, return the name of the parent group."
3961 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3962 (gnus-group-get-parameter group 'save-article-group)))
3964 (defun gnus-summary-save-in-rmail (&optional filename)
3965 "Append this article to Rmail file.
3966 Optional argument FILENAME specifies file name.
3967 Directory to save to is default to `gnus-article-save-directory'."
3968 (setq filename (gnus-read-save-file-name
3969 "Save %s in rmail file" filename
3970 gnus-rmail-save-name gnus-newsgroup-name
3971 gnus-current-headers 'gnus-newsgroup-last-rmail))
3972 (with-current-buffer gnus-save-article-buffer
3976 ;; Note that unlike gnus-summary-save-in-mail, there is no
3977 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3979 (gnus-output-to-rmail filename))))
3982 (defun gnus-summary-save-in-mail (&optional filename)
3983 "Append this article to Unix mail file.
3984 Optional argument FILENAME specifies file name.
3985 Directory to save to is default to `gnus-article-save-directory'."
3986 (setq filename (gnus-read-save-file-name
3987 "Save %s in Unix mail file" filename
3988 gnus-mail-save-name gnus-newsgroup-name
3989 gnus-current-headers 'gnus-newsgroup-last-mail))
3990 (with-current-buffer gnus-save-article-buffer
3994 (if (and (file-readable-p filename)
3995 (file-regular-p filename)
3996 (mail-file-babyl-p filename))
3997 (gnus-output-to-rmail filename)
3998 (gnus-output-to-mail filename)))))
4001 (put 'gnus-summary-save-in-file :decode t)
4002 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4003 (defun gnus-summary-save-in-file (&optional filename overwrite)
4004 "Append this article to file.
4005 Optional argument FILENAME specifies file name.
4006 Directory to save to is default to `gnus-article-save-directory'."
4007 (setq filename (gnus-read-save-file-name
4008 "Save %s in file" filename
4009 gnus-file-save-name gnus-newsgroup-name
4010 gnus-current-headers 'gnus-newsgroup-last-file))
4011 (with-current-buffer gnus-save-article-buffer
4015 (when (and overwrite
4016 (file-exists-p filename))
4017 (delete-file filename))
4018 (gnus-output-to-file filename))))
4021 (put 'gnus-summary-write-to-file :decode t)
4022 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4023 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4024 (defun gnus-summary-write-to-file (&optional filename)
4025 "Write this article to a file, overwriting it if the file exists.
4026 Optional argument FILENAME specifies file name.
4027 The directory to save in defaults to `gnus-article-save-directory'."
4028 (setq filename (gnus-read-save-file-name
4029 "Save %s in file" filename
4030 gnus-file-save-name gnus-newsgroup-name
4031 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4032 (gnus-summary-save-in-file filename t))
4034 (put 'gnus-summary-save-body-in-file :decode t)
4035 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4036 "Append this article body to a file.
4037 Optional argument FILENAME specifies file name.
4038 The directory to save in defaults to `gnus-article-save-directory'."
4039 (setq filename (gnus-read-save-file-name
4040 "Save %s body in file" filename
4041 gnus-file-save-name gnus-newsgroup-name
4042 gnus-current-headers 'gnus-newsgroup-last-file))
4043 (with-current-buffer gnus-save-article-buffer
4047 (when (article-goto-body)
4048 (narrow-to-region (point) (point-max)))
4049 (when (and overwrite
4050 (file-exists-p filename))
4051 (delete-file filename))
4052 (gnus-output-to-file filename))))
4055 (put 'gnus-summary-write-body-to-file :decode t)
4056 (put 'gnus-summary-write-body-to-file
4057 :function 'gnus-summary-save-body-in-file)
4058 (defun gnus-summary-write-body-to-file (&optional filename)
4059 "Write this article body to a file, overwriting it if the file exists.
4060 Optional argument FILENAME specifies file name.
4061 The directory to save in defaults to `gnus-article-save-directory'."
4062 (setq filename (gnus-read-save-file-name
4063 "Save %s body in file" filename
4064 gnus-file-save-name gnus-newsgroup-name
4065 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4066 (gnus-summary-save-body-in-file filename t))
4068 (put 'gnus-summary-save-in-pipe :decode t)
4069 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4070 (defun gnus-summary-save-in-pipe (&optional command raw)
4071 "Pipe this article to subprocess COMMAND.
4072 Valid values for COMMAND include:
4074 The executable command name and possibly arguments.
4076 You will be prompted for the command in the minibuffer.
4077 the symbol `default'
4078 It will be replaced with the command which the variable
4079 `gnus-summary-pipe-output-default-command' holds or the command
4080 last used for saving.
4081 Non-nil value for RAW overrides `:decode' and `:headers' properties
4082 and the raw article including all headers will be piped."
4083 (let ((article (gnus-summary-article-number))
4085 (get 'gnus-summary-save-in-pipe :decode)))
4086 save-buffer default)
4088 (if (vectorp (gnus-summary-article-header article))
4089 (save-current-buffer
4090 (gnus-summary-select-article decode decode nil article)
4091 (insert-buffer-substring
4095 gnus-original-article-buffer)
4097 (nnheader-set-temp-buffer " *Gnus Save*"))))
4098 ;; Remove unwanted headers.
4099 (when (and (not raw)
4100 (or (get 'gnus-summary-save-in-pipe :headers)
4101 (not gnus-save-all-headers)))
4102 (let ((gnus-visible-headers
4103 (or (symbol-value (get 'gnus-summary-save-in-pipe
4105 gnus-saved-headers gnus-visible-headers))
4106 (gnus-summary-buffer nil))
4107 (article-hide-headers 1 t))))
4108 (error "%d is not a real article" article))
4109 (error "No article to pipe"))
4110 (setq default (or gnus-summary-pipe-output-default-command
4111 gnus-last-shell-command))
4112 (unless (stringp command)
4114 (if (and (eq command 'default) default)
4116 (gnus-read-shell-command "Shell command on this article: "
4118 (when (string-equal command "")
4120 (setq command default)
4121 (error "A command is required")))
4122 (with-current-buffer save-buffer
4125 (shell-command-on-region (point-min) (point-max) command nil)))
4126 (gnus-kill-buffer save-buffer))
4127 (setq gnus-summary-pipe-output-default-command command))
4129 (defun gnus-summary-pipe-to-muttprint (&optional command)
4130 "Pipe this article to muttprint."
4131 (unless (stringp command)
4132 (setq command (read-string
4133 "Print using command: " gnus-summary-muttprint-program
4134 nil gnus-summary-muttprint-program)))
4135 (let ((gnus-summary-pipe-output-default-command
4136 gnus-summary-pipe-output-default-command))
4137 (gnus-summary-save-in-pipe command))
4138 (setq gnus-summary-muttprint-program command))
4140 ;;; Article file names when saving.
4142 (defun gnus-capitalize-newsgroup (newsgroup)
4143 "Capitalize NEWSGROUP name."
4144 (when (not (zerop (length newsgroup)))
4145 (concat (char-to-string (upcase (aref newsgroup 0)))
4146 (substring newsgroup 1))))
4148 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4149 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4150 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4151 Otherwise, it is like ~/News/news/group/num."
4154 (concat (if (gnus-use-long-file-name 'not-save)
4155 (gnus-capitalize-newsgroup newsgroup)
4156 (gnus-newsgroup-directory-form newsgroup))
4157 "/" (int-to-string (mail-header-number headers)))
4158 gnus-article-save-directory)))
4160 (string-equal (file-name-directory default)
4161 (file-name-directory last-file))
4162 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4164 (or last-file default))))
4166 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4167 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4168 If variable `gnus-use-long-file-name' is non-nil, it is
4169 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4172 (concat (if (gnus-use-long-file-name 'not-save)
4174 (gnus-newsgroup-directory-form newsgroup))
4175 "/" (int-to-string (mail-header-number headers)))
4176 gnus-article-save-directory)))
4178 (string-equal (file-name-directory default)
4179 (file-name-directory last-file))
4180 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4182 (or last-file default))))
4184 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4185 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4186 If variable `gnus-use-long-file-name' is non-nil, it is
4187 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4190 (if (gnus-use-long-file-name 'not-save)
4193 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4195 gnus-article-save-directory)))
4197 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4198 "Generate file name from sender."
4199 (let ((from (mail-header-from headers)))
4201 (if (and from (string-match "\\([^ <]+\\)@" from))
4202 (match-string 1 from)
4204 gnus-article-save-directory)))
4206 (defun article-verify-x-pgp-sig ()
4208 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4210 (if (gnus-buffer-live-p gnus-original-article-buffer)
4211 (let ((sig (with-current-buffer gnus-original-article-buffer
4212 (gnus-fetch-field "X-PGP-Sig")))
4216 (mml2015-clear-verify-function))
4218 (insert-buffer-substring gnus-original-article-buffer)
4219 (setq items (split-string sig))
4220 (message-narrow-to-head)
4221 (let ((inhibit-point-motion-hooks t)
4222 (case-fold-search t))
4223 ;; Don't verify multiple headers.
4224 (setq headers (mapconcat (lambda (header)
4226 (mail-fetch-field header)
4228 (split-string (nth 1 items) ",") "")))
4229 (delete-region (point-min) (point-max))
4230 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4231 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4236 (if (looking-at "^-")
4239 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4240 (insert "Version: " (car items) "\n\n")
4241 (insert (mapconcat 'identity (cddr items) "\n"))
4242 (insert "\n-----END PGP SIGNATURE-----\n")
4243 (let ((mm-security-handle (list (format "multipart/signed"))))
4244 (mml2015-clean-buffer)
4245 (let ((coding-system-for-write (or gnus-newsgroup-charset
4247 (funcall (mml2015-clear-verify-function)))
4249 (or (mm-handle-multipart-ctl-parameter
4250 mm-security-handle 'gnus-details)
4251 (mm-handle-multipart-ctl-parameter
4252 mm-security-handle 'gnus-info)))))
4254 (let ((inhibit-read-only t) bface eface)
4256 (message-narrow-to-head)
4257 (goto-char (point-max))
4259 (setq bface (get-text-property (point-at-bol) 'face)
4260 eface (get-text-property (1- (point-at-eol)) 'face))
4261 (message-remove-header "X-Gnus-PGP-Verify")
4262 (if (re-search-forward "^X-PGP-Sig:" nil t)
4264 (goto-char (point-max)))
4265 (narrow-to-region (point) (point))
4266 (insert "X-Gnus-PGP-Verify: " info "\n")
4267 (goto-char (point-min))
4270 (if (not (looking-at "^[ \t]"))
4274 (goto-char (point-min))
4275 (when (looking-at "\\([^:]+\\): *")
4276 (put-text-property (match-beginning 1) (1+ (match-end 1))
4278 (put-text-property (match-end 0) (point-max)
4279 'face eface)))))))))
4281 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4283 (defun article-verify-cancel-lock ()
4284 "Verify Cancel-Lock header."
4286 (if (gnus-buffer-live-p gnus-original-article-buffer)
4287 (canlock-verify gnus-original-article-buffer)))
4294 (setq afunc (car func)
4297 gfunc (intern (format "gnus-%s" func))))
4299 (when (fboundp afunc)
4300 `(lambda (&optional interactive &rest args)
4301 ,(documentation afunc t)
4302 (interactive (list t))
4303 (with-current-buffer gnus-article-buffer
4305 (call-interactively ',afunc)
4306 (apply ',afunc args))))))))
4307 '(article-hide-headers
4308 article-verify-x-pgp-sig
4309 article-verify-cancel-lock
4310 article-hide-boring-headers
4311 article-treat-overstrike
4312 article-treat-ansi-sequences
4313 article-fill-long-lines
4314 article-capitalize-sentences
4316 article-remove-leading-whitespace
4317 article-display-x-face
4318 article-display-face
4319 article-de-quoted-unreadable
4320 article-de-base64-unreadable
4323 article-unsplit-urls
4324 article-hide-list-identifiers
4325 article-strip-banner
4328 article-hide-signature
4329 article-strip-headers-in-body
4330 article-remove-trailing-blank-lines
4331 article-strip-leading-blank-lines
4332 article-strip-multiple-blank-lines
4333 article-strip-leading-space
4334 article-strip-trailing-space
4335 article-strip-blank-lines
4336 article-strip-all-blank-lines
4338 article-date-english
4339 article-date-iso8601
4340 article-date-original
4343 article-decode-mime-words
4344 article-decode-charset
4345 article-decode-encoded-words
4348 article-date-combined-lapsed
4350 article-treat-dumbquotes
4351 article-treat-non-ascii
4352 article-normalize-headers
4353 ;;(article-show-all . gnus-article-show-all-headers)
4357 ;;; Gnus article mode
4360 (put 'gnus-article-mode 'mode-class 'special)
4362 (set-keymap-parent gnus-article-mode-map widget-keymap)
4364 (gnus-define-keys gnus-article-mode-map
4365 " " gnus-article-goto-next-page
4366 "\177" gnus-article-goto-prev-page
4367 [delete] gnus-article-goto-prev-page
4368 [backspace] gnus-article-goto-prev-page
4369 "\C-c^" gnus-article-refer-article
4370 "h" gnus-article-show-summary
4371 "s" gnus-article-show-summary
4372 "\C-c\C-m" gnus-article-mail
4373 "?" gnus-article-describe-briefly
4374 "<" beginning-of-buffer
4376 "\C-c\C-i" gnus-info-find-node
4378 "R" gnus-article-reply-with-original
4379 "F" gnus-article-followup-with-original
4380 "\C-hk" gnus-article-describe-key
4381 "\C-hc" gnus-article-describe-key-briefly
4382 "\C-hb" gnus-article-describe-bindings
4384 "e" gnus-article-read-summary-keys
4385 "\C-d" gnus-article-read-summary-keys
4386 "\M-*" gnus-article-read-summary-keys
4387 "\M-#" gnus-article-read-summary-keys
4388 "\M-^" gnus-article-read-summary-keys
4389 "\M-g" gnus-article-read-summary-keys)
4391 (substitute-key-definition
4392 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4394 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4395 "W" gnus-article-wide-reply-with-original)
4396 (if (featurep 'xemacs)
4397 (set-keymap-default-binding gnus-article-send-map
4398 'gnus-article-read-summary-send-keys)
4399 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4401 (defun gnus-article-make-menu-bar ()
4402 (unless (boundp 'gnus-article-commands-menu)
4403 (gnus-summary-make-menu-bar))
4404 (unless (boundp 'gnus-article-article-menu)
4406 gnus-article-article-menu gnus-article-mode-map ""
4408 ["Scroll forwards" gnus-article-goto-next-page t]
4409 ["Scroll backwards" gnus-article-goto-prev-page t]
4410 ["Show summary" gnus-article-show-summary t]
4411 ["Fetch Message-ID at point" gnus-article-refer-article t]
4412 ["Mail to address at point" gnus-article-mail t]
4413 ["Send a bug report" gnus-bug t]))
4416 gnus-article-treatment-menu gnus-article-mode-map ""
4417 ;; Fixme: this should use :active (and maybe :visible).
4419 ["Hide headers" gnus-article-hide-headers t]
4420 ["Hide signature" gnus-article-hide-signature t]
4421 ["Hide citation" gnus-article-hide-citation t]
4422 ["Treat overstrike" gnus-article-treat-overstrike t]
4423 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4424 ["Remove carriage return" gnus-article-remove-cr t]
4425 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4426 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4427 ["Remove base64" gnus-article-de-base64-unreadable t]
4428 ["Treat html" gnus-article-wash-html t]
4429 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4430 ["Decode HZ" gnus-article-decode-HZ t]))
4432 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4434 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4436 (gnus-run-hooks 'gnus-article-menu-hook)))
4438 (defvar bookmark-make-record-function)
4439 (defvar shr-put-image-function)
4441 (defun gnus-article-mode ()
4442 "Major mode for displaying an article.
4444 All normal editing commands are switched off.
4446 The following commands are available in addition to all summary mode
4448 \\<gnus-article-mode-map>
4449 \\[gnus-article-next-page]\t Scroll the article one page forwards
4450 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4451 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4452 \\[gnus-article-show-summary]\t Display the summary buffer
4453 \\[gnus-article-mail]\t Send a reply to the address near point
4454 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4455 \\[gnus-info-find-node]\t Go to the Gnus info node"
4457 (kill-all-local-variables)
4458 (gnus-simplify-mode-line)
4459 (setq mode-name "Article")
4460 (setq major-mode 'gnus-article-mode)
4461 (make-local-variable 'minor-mode-alist)
4462 (use-local-map gnus-article-mode-map)
4463 (when (gnus-visual-p 'article-menu 'menu)
4464 (gnus-article-make-menu-bar)
4465 (when gnus-summary-tool-bar-map
4466 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4467 (gnus-update-format-specifications nil 'article-mode)
4468 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4469 (set (make-local-variable 'gnus-page-broken) nil)
4470 (make-local-variable 'gnus-article-current-summary)
4471 (make-local-variable 'gnus-article-mime-handles)
4472 (make-local-variable 'gnus-article-decoded-p)
4473 (make-local-variable 'gnus-article-mime-handle-alist)
4474 (make-local-variable 'gnus-article-wash-types)
4475 (make-local-variable 'gnus-article-image-alist)
4476 (make-local-variable 'gnus-article-charset)
4477 (make-local-variable 'gnus-article-ignored-charsets)
4478 (set (make-local-variable 'bookmark-make-record-function)
4479 'gnus-summary-bookmark-make-record)
4480 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4482 (set (make-local-variable 'nobreak-char-display) nil)
4483 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4484 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4485 (setq cursor-in-non-selected-windows nil)
4486 (gnus-set-default-directory)
4487 (buffer-disable-undo)
4488 (setq buffer-read-only t
4489 show-trailing-whitespace nil)
4490 (set-syntax-table gnus-article-mode-syntax-table)
4491 (mm-enable-multibyte)
4492 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4494 (defun gnus-article-setup-buffer ()
4495 "Initialize the article buffer."
4496 (let* ((name (if gnus-single-article-buffer "*Article*"
4498 (gnus-group-decoded-name gnus-newsgroup-name)
4501 (progn (string-match "\\*Article" name)
4502 (concat " *Original Article"
4503 (substring name (match-end 0))))))
4504 (setq gnus-article-buffer name)
4505 (setq gnus-original-article-buffer original)
4506 (setq gnus-article-mime-handle-alist nil)
4507 (with-current-buffer gnus-summary-buffer
4508 ;; This might be a variable local to the summary buffer.
4509 (unless gnus-single-article-buffer
4510 (setq gnus-article-buffer name)
4511 (setq gnus-original-article-buffer original)
4512 (gnus-set-global-variables)))
4513 (gnus-article-setup-highlight-words)
4514 ;; Init original article buffer.
4515 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4516 (mm-enable-multibyte)
4517 (setq major-mode 'gnus-original-article-mode)
4518 (make-local-variable 'gnus-original-article))
4519 (if (and (get-buffer name)
4520 (with-current-buffer name
4521 (if gnus-article-edit-mode
4522 (if (y-or-n-p "Article mode edit in progress; discard? ")
4524 (set-buffer-modified-p nil)
4525 (gnus-kill-buffer name)
4528 (error "Action aborted"))
4530 (with-current-buffer name
4531 (set (make-local-variable 'gnus-article-edit-mode) nil)
4532 (gnus-article-stop-animations)
4533 (when gnus-article-mime-handles
4534 (mm-destroy-parts gnus-article-mime-handles)
4535 (setq gnus-article-mime-handles nil))
4536 ;; Set it to nil in article-buffer!
4537 (setq gnus-article-mime-handle-alist nil)
4538 (buffer-disable-undo)
4539 (setq buffer-read-only t)
4540 (unless (eq major-mode 'gnus-article-mode)
4541 (gnus-article-mode))
4542 (setq truncate-lines gnus-article-truncate-lines)
4544 (with-current-buffer (gnus-get-buffer-create name)
4546 (setq truncate-lines gnus-article-truncate-lines)
4547 (make-local-variable 'gnus-summary-buffer)
4548 (setq gnus-summary-buffer
4549 (gnus-summary-buffer-name gnus-newsgroup-name))
4550 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4551 (when article-lapsed-timer
4552 (gnus-stop-date-timer))
4553 (when gnus-article-update-date-headers
4554 (gnus-start-date-timer gnus-article-update-date-headers))
4555 (current-buffer)))))
4557 (defun gnus-article-stop-animations ()
4558 (dolist (timer (and (boundp 'timer-list)
4560 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4561 (cancel-timer timer))))
4563 (defun gnus-stop-downloads ()
4564 (when (boundp 'url-queue)
4565 (set (intern "url-queue" obarray) nil)))
4567 ;; Set article window start at LINE, where LINE is the number of lines
4568 ;; from the head of the article.
4569 (defun gnus-article-set-window-start (&optional line)
4570 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4571 (when article-window
4574 (with-current-buffer gnus-article-buffer
4575 (goto-char (point-min))
4578 (gnus-message 6 "Moved to bookmark")
4579 (search-forward "\n\n" nil t)
4583 (defun gnus-article-prepare (article &optional all-headers header)
4584 "Prepare ARTICLE in article mode buffer.
4585 ARTICLE should either be an article number or a Message-ID.
4586 If ARTICLE is an id, HEADER should be the article headers.
4587 If ALL-HEADERS is non-nil, no headers are hidden."
4589 ;; Make sure we start in a summary buffer.
4590 (unless (eq major-mode 'gnus-summary-mode)
4591 (set-buffer gnus-summary-buffer))
4592 (setq gnus-summary-buffer (current-buffer))
4593 (let* ((gnus-article (if header (mail-header-number header) article))
4594 (summary-buffer (current-buffer))
4595 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4596 (group gnus-newsgroup-name)
4599 (gnus-article-setup-buffer)
4600 (set-buffer gnus-article-buffer)
4601 ;; Deactivate active regions.
4602 (when (and (boundp 'transient-mark-mode)
4603 transient-mark-mode)
4604 (setq mark-active nil))
4605 (if (not (setq result (let ((inhibit-read-only t))
4606 (gnus-request-article-this-buffer
4608 ;; There is no such article.
4610 (when (and (numberp article)
4611 (not (memq article gnus-newsgroup-sparse)))
4612 (setq gnus-article-current
4613 (cons gnus-newsgroup-name article))
4614 (set-buffer gnus-summary-buffer)
4615 (setq gnus-current-article article)
4616 (if (and (memq article gnus-newsgroup-undownloaded)
4617 (not (gnus-online (gnus-find-method-for-group
4618 gnus-newsgroup-name))))
4620 (gnus-summary-set-agent-mark article)
4621 (message "Message marked for downloading"))
4622 (gnus-summary-mark-article article gnus-canceled-mark)
4623 (unless (memq article gnus-newsgroup-sparse)
4624 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4625 (if (or (eq result 'pseudo)
4626 (eq result 'nneething))
4628 (with-current-buffer summary-buffer
4629 (push article gnus-newsgroup-history)
4630 (setq gnus-last-article gnus-current-article
4631 gnus-current-article 0
4632 gnus-current-headers nil
4633 gnus-article-current nil)
4634 (if (eq result 'nneething)
4635 (gnus-configure-windows 'summary)
4636 (gnus-configure-windows 'article))
4637 (gnus-set-global-variables))
4638 (let ((gnus-article-mime-handle-alist-1
4639 gnus-article-mime-handle-alist))
4640 (gnus-set-mode-line 'article)))
4641 ;; The result from the `request' was an actual article -
4642 ;; or at least some text that is now displayed in the
4644 (when (and (numberp article)
4645 (not (eq article gnus-current-article)))
4646 ;; Seems like a new article has been selected.
4647 ;; `gnus-current-article' must be an article number.
4648 (with-current-buffer summary-buffer
4649 (push article gnus-newsgroup-history)
4650 (setq gnus-last-article gnus-current-article
4651 gnus-current-article article
4652 gnus-current-headers
4653 (gnus-summary-article-header gnus-current-article)
4654 gnus-article-current
4655 (cons gnus-newsgroup-name gnus-current-article))
4656 (unless (vectorp gnus-current-headers)
4657 (setq gnus-current-headers nil))
4658 (gnus-summary-goto-subject gnus-current-article)
4659 (when (gnus-summary-show-thread)
4660 ;; If the summary buffer really was folded, the
4661 ;; previous goto may not actually have gone to
4662 ;; the right article, but the thread root instead.
4664 (gnus-summary-goto-subject gnus-current-article))
4665 (gnus-run-hooks 'gnus-mark-article-hook)
4666 (gnus-set-mode-line 'summary)
4667 (when (gnus-visual-p 'article-highlight 'highlight)
4668 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4669 ;; Set the global newsgroup variables here.
4670 (gnus-set-global-variables)
4671 (setq gnus-have-all-headers
4672 (or all-headers gnus-show-all-headers))))
4674 (gnus-configure-windows 'article))
4675 (when (or (numberp article)
4677 (gnus-article-prepare-display)
4679 (goto-char (point-min))
4680 (when gnus-break-pages
4681 (gnus-narrow-to-page)))
4682 (let ((gnus-article-mime-handle-alist-1
4683 gnus-article-mime-handle-alist))
4684 (gnus-set-mode-line 'article))
4688 (set-window-point (get-buffer-window (current-buffer)) (point))
4689 (gnus-configure-windows 'article)
4690 (gnus-run-hooks 'gnus-article-prepare-hook)
4694 (defun gnus-article-prepare-display ()
4695 "Make the current buffer look like a nice article."
4696 ;; Hooks for getting information from the article.
4697 ;; This hook must be called before being narrowed.
4698 (let ((gnus-article-buffer (current-buffer))
4700 (inhibit-read-only t))
4701 (unless (eq major-mode 'gnus-article-mode)
4702 (gnus-article-mode))
4703 (setq buffer-read-only nil
4704 gnus-article-wash-types nil
4705 gnus-article-image-alist nil)
4706 (gnus-run-hooks 'gnus-tmp-internal-hook)
4707 (when gnus-display-mime-function
4708 (funcall gnus-display-mime-function))))
4711 ;;; Gnus Sticky Article Mode
4714 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4715 "Mode for sticky articles."
4716 ;; Release bindings that won't work.
4717 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4718 gnus-sticky-article-mode-map)
4719 (substitute-key-definition 'gnus-article-refer-article 'undefined
4720 gnus-sticky-article-mode-map)
4721 (dolist (k '("e" "h" "s" "F" "R"))
4722 (define-key gnus-sticky-article-mode-map k nil))
4723 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4724 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4725 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4726 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4728 (defun gnus-sticky-article (arg)
4729 "Make the current article sticky.
4730 If a prefix ARG is given, ask for a name for this sticky article buffer."
4732 (gnus-summary-show-thread)
4733 (gnus-summary-select-article nil nil 'pseudo)
4734 (let (new-art-buf-name)
4735 (gnus-eval-in-buffer-window gnus-article-buffer
4736 (setq new-art-buf-name
4740 (read-from-minibuffer "Sticky article buffer name: ")
4741 (gnus-with-article-headers
4742 (gnus-article-goto-header "subject")
4743 (setq new-art-buf-name
4744 (buffer-substring-no-properties
4745 (line-beginning-position) (line-end-position)))
4746 (goto-char (point-min))
4747 (gnus-article-goto-header "from")
4748 (setq new-art-buf-name
4750 new-art-buf-name ", "
4751 (buffer-substring-no-properties
4752 (line-beginning-position) (line-end-position))))
4753 (goto-char (point-min))
4754 (gnus-article-goto-header "date")
4755 (setq new-art-buf-name
4757 new-art-buf-name ", "
4758 (buffer-substring-no-properties
4759 (line-beginning-position) (line-end-position))))))
4761 (if (and (gnus-buffer-live-p new-art-buf-name)
4762 (with-current-buffer new-art-buf-name
4763 (eq major-mode 'gnus-sticky-article-mode)))
4764 (switch-to-buffer new-art-buf-name)
4765 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4766 (gnus-sticky-article-mode))
4767 (setq gnus-article-buffer new-art-buf-name))
4768 (gnus-summary-recenter)
4769 (gnus-summary-position-point))
4771 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4772 "Kill the given sticky article BUFFER.
4773 If none is given, assume the current buffer and kill it if it has
4774 `gnus-sticky-article-mode'."
4777 (setq buffer (current-buffer)))
4778 (with-current-buffer buffer
4779 (when (eq major-mode 'gnus-sticky-article-mode)
4780 (gnus-kill-buffer buffer))))
4782 (defun gnus-kill-sticky-article-buffers (arg)
4783 "Kill all sticky article buffers.
4784 If a prefix ARG is given, ask for confirmation."
4786 (dolist (buf (gnus-buffers))
4787 (with-current-buffer buf
4788 (when (eq major-mode 'gnus-sticky-article-mode)
4790 (gnus-kill-buffer buf)
4791 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4792 (gnus-kill-buffer buf)))))))
4795 ;;; Gnus MIME viewing functions
4798 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4799 "Format of the MIME buttons.
4801 Valid specifiers include:
4803 %T MIME type, along with additional info
4804 %n The `name' parameter
4805 %d The description, if any
4806 %l The length of the encoded part
4807 %p The part identifier number
4808 %e Dots if the part isn't displayed
4810 General format specifiers can also be used. See Info node
4811 `(gnus)Formatting Variables'.")
4813 (defvar gnus-mime-button-line-format-alist
4814 '((?t gnus-tmp-type ?s)
4815 (?T gnus-tmp-type-long ?s)
4816 (?n gnus-tmp-name ?s)
4817 (?d gnus-tmp-description ?s)
4819 (?l gnus-tmp-length ?d)
4820 (?e gnus-tmp-dots ?s)))
4822 (defvar gnus-mime-button-commands
4823 '((gnus-article-press-button "\r" "Toggle Display")
4824 (gnus-mime-view-part "v" "View Interactively...")
4825 (gnus-mime-view-part-as-type "t" "View As Type...")
4826 (gnus-mime-view-part-as-charset "C" "View As charset...")
4827 (gnus-mime-save-part "o" "Save...")
4828 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4829 (gnus-mime-replace-part "r" "Replace part")
4830 (gnus-mime-delete-part "d" "Delete part")
4831 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4832 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4833 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4834 (gnus-mime-view-part-externally "e" "View Externally")
4835 (gnus-mime-print-part "p" "Print")
4836 (gnus-mime-pipe-part "|" "Pipe To Command...")
4837 (gnus-mime-action-on-part "." "Take action on the part...")))
4839 (defun gnus-article-mime-part-status ()
4840 (if gnus-article-mime-handle-alist-1
4841 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4843 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4846 (defvar gnus-mime-button-map
4847 (let ((map (make-sparse-keymap)))
4848 (define-key map gnus-mouse-2 'gnus-article-push-button)
4849 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4850 (dolist (c gnus-mime-button-commands)
4851 (define-key map (cadr c) (car c)))
4855 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4857 ,@(mapcar (lambda (c)
4858 (vector (caddr c) (car c) :active t))
4859 gnus-mime-button-commands)))
4861 (defvar gnus-url-button-commands
4862 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4864 (defvar gnus-url-button-map
4865 (let ((map (make-sparse-keymap)))
4866 (dolist (c gnus-url-button-commands)
4867 (define-key map (cadr c) (car c)))
4871 gnus-url-button-menu gnus-url-button-map "URL button menu."
4873 ,@(mapcar (lambda (c)
4874 (vector (caddr c) (car c) :active t))
4875 gnus-url-button-commands)))
4877 (defmacro gnus-bind-safe-url-regexp (&rest body)
4878 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4879 `(let ((mm-w3m-safe-url-regexp
4880 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4882 gnus-article-current-summary))
4883 (with-current-buffer gnus-article-current-summary
4884 gnus-newsgroup-name)
4885 gnus-newsgroup-name)))
4886 (if (cond ((not group)
4887 ;; Maybe we're in a mml-preview buffer
4888 ;; and no group is selected.
4890 ((stringp gnus-safe-html-newsgroups)
4891 (string-match gnus-safe-html-newsgroups group))
4892 ((consp gnus-safe-html-newsgroups)
4893 (member group gnus-safe-html-newsgroups)))
4895 mm-w3m-safe-url-regexp))))
4898 (defun gnus-mime-button-menu (event prefix)
4899 "Construct a context-sensitive menu of MIME commands."
4900 (interactive "e\nP")
4901 (save-window-excursion
4902 (let ((pos (event-start event)))
4903 (select-window (posn-window pos))
4904 (goto-char (posn-point pos))
4905 (gnus-article-check-buffer)
4906 (popup-menu gnus-mime-button-menu nil prefix))))
4908 (defun gnus-mime-view-all-parts (&optional handles)
4909 "View all the MIME parts."
4911 (with-current-buffer gnus-article-buffer
4912 (let ((handles (or handles gnus-article-mime-handles))
4913 (mail-parse-charset gnus-newsgroup-charset)
4914 (mail-parse-ignored-charsets
4915 (with-current-buffer gnus-summary-buffer
4916 gnus-newsgroup-ignored-charsets)))
4918 (mm-remove-parts handles)
4919 (goto-char (point-min))
4920 (or (search-forward "\n\n") (goto-char (point-max)))
4921 (let ((inhibit-read-only t))
4922 (delete-region (point) (point-max))
4923 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4925 (defun gnus-article-jump-to-part (n)
4926 "Jump to MIME part N."
4928 (let ((parts (with-current-buffer gnus-article-buffer
4929 (length gnus-article-mime-handle-alist))))
4931 (error "No such part"))
4932 (pop-to-buffer gnus-article-buffer)
4934 (setq n (if (= parts 1)
4936 (read-number (format "Jump to part (1..%s): " parts)))))
4937 (unless (and (integerp n) (<= n parts) (>= n 1))
4940 (gnus-message 7 "Invalid part `%s', using %s instead."
4943 (gnus-message 9 "Jumping to part %s." n)
4944 (cond ((>= gnus-auto-select-part 1)
4945 (while (and (<= n parts)
4946 (not (gnus-article-goto-part n)))
4948 ((< gnus-auto-select-part 0)
4949 (while (and (>= n 1)
4950 (not (gnus-article-goto-part n)))
4953 (gnus-article-goto-part n)))))
4955 (defvar gnus-mime-buttonized-part-id nil
4956 "ID of a mime part that should be buttonized.
4957 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4960 (defsubst gnus-article-edit-part (handles &optional current-id)
4961 "Edit an article in order to delete a mime part.
4962 This function is exclusively used by `gnus-mime-save-part-and-strip'
4963 and `gnus-mime-delete-part', and not provided at run-time normally."
4964 (gnus-article-edit-article
4966 (buffer-disable-undo)
4968 (let ((mail-parse-charset (or gnus-article-charset
4969 ',gnus-newsgroup-charset))
4970 (mail-parse-ignored-charsets
4971 (or gnus-article-ignored-charsets
4972 ',gnus-newsgroup-ignored-charsets))
4973 (mbl mml-buffer-list))
4974 (setq mml-buffer-list nil)
4975 (insert-buffer-substring gnus-original-article-buffer)
4976 (mime-to-mml ',handles)
4977 (setq gnus-article-mime-handles nil)
4978 (let ((mbl1 mml-buffer-list))
4979 (setq mml-buffer-list mbl)
4980 (set (make-local-variable 'mml-buffer-list) mbl1))
4981 (gnus-make-local-hook 'kill-buffer-hook)
4982 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4983 `(lambda (no-highlight)
4984 (let ((mail-parse-charset (or gnus-article-charset
4985 ',gnus-newsgroup-charset))
4986 (message-options message-options)
4987 (message-options-set-recipient)
4988 (mail-parse-ignored-charsets
4989 (or gnus-article-ignored-charsets
4990 ',gnus-newsgroup-ignored-charsets)))
4992 (mml-destroy-buffers)
4993 (remove-hook 'kill-buffer-hook
4994 'mml-destroy-buffers t)
4995 (kill-local-variable 'mml-buffer-list))
4996 (gnus-summary-edit-article-done
4997 ,(or (mail-header-references gnus-current-headers) "")
4998 ,(gnus-group-read-only-p)
4999 ,gnus-summary-buffer no-highlight))
5001 ;; Force buttonizing this part.
5002 (let ((gnus-mime-buttonized-part-id current-id))
5003 (gnus-article-edit-done))
5004 (gnus-configure-windows 'article)
5005 (when (and current-id (integerp gnus-auto-select-part))
5006 (gnus-article-jump-to-part
5007 (min (max (+ current-id gnus-auto-select-part) 1)
5008 (with-current-buffer gnus-article-buffer
5009 (length gnus-article-mime-handle-alist)))))))
5011 (defun gnus-mime-replace-part (file)
5012 "Replace MIME part under point with an external body."
5013 ;; Useful if file has already been saved to disk
5016 (read-file-name "Replace MIME part with file: "
5017 (or mm-default-directory default-directory)
5019 (gnus-mime-save-part-and-strip file))
5021 (defun gnus-mime-save-part-and-strip (&optional file)
5022 "Save the MIME part under point then replace it with an external body.
5023 If FILE is given, use it for the external part."
5025 (gnus-article-check-buffer)
5026 (when (gnus-group-read-only-p)
5027 (error "The current group does not support deleting of parts"))
5028 (when (mm-complicated-handles gnus-article-mime-handles)
5030 The current article has a complicated MIME structure, giving up..."))
5031 (let* ((data (get-text-property (point) 'gnus-data))
5032 (id (get-text-property (point) 'gnus-part))
5034 (handles gnus-article-mime-handles))
5037 (and data (mm-save-part data "Delete MIME part and save to: "))))
5039 (with-current-buffer (mm-handle-buffer data)
5041 (insert "Content-Type: " (mm-handle-media-type data))
5042 (mml-insert-parameter-string (cdr (mm-handle-type data))
5044 ;; Add a filename for the sake of saving the part again.
5045 (mml-insert-parameter
5046 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5048 (insert "Content-ID: " (message-make-message-id) "\n")
5049 (insert "Content-Transfer-Encoding: binary\n")
5052 (cdr (mm-make-handle nil
5053 `("message/external-body"
5054 (access-type . "LOCAL-FILE")
5056 ;; (set-buffer gnus-summary-buffer)
5057 (gnus-article-edit-part handles id))))
5059 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5060 ;; parts...>') but with stripping would be nice.
5062 (defun gnus-mime-delete-part ()
5063 "Delete the MIME part under point.
5064 Replace it with some information about the removed part."
5066 (gnus-article-check-buffer)
5067 (when (gnus-group-read-only-p)
5068 (error "The current group does not support deleting of parts"))
5069 (when (mm-complicated-handles gnus-article-mime-handles)
5071 The current article has a complicated MIME structure, giving up..."))
5072 (when (or gnus-expert-user
5073 (gnus-yes-or-no-p "\
5074 Deleting parts may malfunction or destroy the article; continue? "))
5075 (let* ((data (get-text-property (point) 'gnus-data))
5076 (id (get-text-property (point) 'gnus-part))
5077 (handles gnus-article-mime-handles)
5079 (let ((desc (mm-handle-description data)))
5081 (mail-decode-encoded-word-string desc))))
5082 (filename (or (mm-handle-filename data) "(none)"))
5083 (type (mm-handle-media-type data)))
5085 (error "No MIME part under point"))
5086 (with-current-buffer (mm-handle-buffer data)
5087 (let ((bsize (buffer-size)))
5092 "| The following attachment has been deleted:\n"
5094 "| Type: " type "\n"
5095 "| Filename: " filename "\n"
5096 "| Size (encoded): " (format "%s byte%s\n"
5097 bsize (if (= bsize 1)
5101 (concat "| Description: " description "\n"))
5104 (cdr (mm-make-handle
5105 nil `("text/plain" (charset . gnus-decoded)) nil nil
5107 (format "Deleted attachment (%s bytes)" bsize))))))
5108 ;; (set-buffer gnus-summary-buffer)
5109 (gnus-article-edit-part handles id))))
5111 (defun gnus-mime-save-part ()
5112 "Save the MIME part under point."
5114 (gnus-article-check-buffer)
5115 (let ((data (get-text-property (point) 'gnus-data)))
5117 (mm-save-part data))))
5119 (defun gnus-mime-pipe-part (&optional cmd)
5120 "Pipe the MIME part under point to a process.
5121 Use CMD as the process."
5123 (gnus-article-check-buffer)
5124 (let ((data (get-text-property (point) 'gnus-data)))
5126 (mm-pipe-part data cmd))))
5128 (defun gnus-mime-view-part ()
5129 "Interactively choose a viewing method for the MIME part under point."
5131 (gnus-article-check-buffer)
5132 (let ((data (get-text-property (point) 'gnus-data)))
5134 (setq gnus-article-mime-handles
5136 gnus-article-mime-handles (setq data (copy-sequence data))))
5137 (mm-interactively-view-part data))))
5139 (defun gnus-mime-view-part-as-type-internal ()
5140 (gnus-article-check-buffer)
5141 (let* ((handle (get-text-property (point) 'gnus-data))
5143 ;; Content-Type: foo/bar; name=...
5144 (mail-content-type-get (mm-handle-type handle) 'name)
5145 ;; Content-Disposition: attachment; filename=...
5146 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5147 (def-type (and name (mm-default-file-encoding name))))
5148 (or (and def-type (cons def-type 0))
5150 (equal (mm-handle-media-supertype handle) "text")
5151 '("text/plain" . 0))
5152 '("application/octet-stream" . 0))))
5154 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5155 "Choose a MIME media type, and view the part as such.
5156 If non-nil, PRED is a predicate to use during completion to limit the
5157 available media-types."
5161 (let ((default (gnus-mime-view-part-as-type-internal)))
5162 (gnus-completing-read
5165 (gnus-remove-if-not pred (mailcap-mime-types))
5166 (mailcap-mime-types))
5169 (gnus-article-check-buffer)
5170 (let ((handle (get-text-property (point) 'gnus-data)))
5172 (when (equal (mm-handle-media-type handle) "message/external-body")
5173 (unless (mm-handle-cache handle)
5174 (mm-extern-cache-contents handle))
5175 (setq handle (mm-handle-cache handle)))
5177 (mm-make-handle (mm-handle-buffer handle)
5178 (cons mime-type (cdr (mm-handle-type handle)))
5179 (mm-handle-encoding handle)
5180 (mm-handle-undisplayer handle)
5181 (mm-handle-disposition handle)
5182 (mm-handle-description handle)
5184 (mm-handle-id handle)))
5185 (setq gnus-article-mime-handles
5186 (mm-merge-handles gnus-article-mime-handles handle))
5187 (when (mm-handle-displayed-p handle)
5188 (mm-remove-part handle))
5189 (gnus-mm-display-part handle))))
5191 (defun gnus-mime-copy-part (&optional handle arg)
5192 "Put the MIME part under point into a new buffer.
5193 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5195 (interactive (list nil current-prefix-arg))
5196 (gnus-article-check-buffer)
5198 (setq handle (get-text-property (point) 'gnus-data)))
5200 (let ((filename (mm-handle-filename handle))
5201 contents dont-decode charset coding-system)
5202 (mm-with-unibyte-buffer
5203 (mm-insert-part handle)
5204 (setq contents (or (condition-case nil
5205 (mm-decompress-buffer filename nil 'sig)
5207 (setq dont-decode t)
5210 (setq filename (cond (filename (file-name-nondirectory filename))
5211 (dont-decode "*raw data*")
5216 (unless (setq charset (mail-content-type-get
5217 (mm-handle-type handle) 'charset))
5218 (unless (setq coding-system (mm-with-unibyte-buffer
5220 (mm-find-buffer-file-coding-system)))
5221 (setq charset gnus-newsgroup-charset))))
5223 (setq charset (or (cdr (assq arg
5224 gnus-summary-show-article-charset-alist))
5225 (mm-read-coding-system "Charset: ")))))
5226 (switch-to-buffer (generate-new-buffer filename))
5227 (if (or coding-system
5229 (setq coding-system (mm-charset-to-coding-system charset))
5230 (not (eq coding-system 'ascii))))
5232 (mm-enable-multibyte)
5233 (insert (mm-decode-coding-string contents coding-system))
5234 (setq buffer-file-coding-system
5235 (if (boundp 'last-coding-system-used)
5236 (symbol-value 'last-coding-system-used)
5238 (mm-disable-multibyte)
5240 (setq buffer-file-coding-system mm-binary-coding-system))
5241 ;; We do it this way to make `normal-mode' set the appropriate mode.
5244 (setq buffer-file-name (expand-file-name filename))
5246 (setq buffer-file-name nil))
5247 (goto-char (point-min)))))
5249 (defun gnus-mime-print-part (&optional handle filename)
5250 "Print the MIME part under point."
5251 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5252 (gnus-article-check-buffer)
5253 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5254 (contents (and handle (mm-get-part handle)))
5255 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5256 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5261 (mm-save-part-to-file handle file)
5262 (call-process shell-file-name nil
5263 (generate-new-buffer " *mm*")
5265 shell-command-switch
5267 printer file (mm-handle-type handle))))
5271 (gnus-print-buffer))
5272 (ps-despool filename)))))
5274 (defun gnus-mime-inline-part (&optional handle arg)
5275 "Insert the MIME part under point into the current buffer.
5276 Compressed files like .gz and .bz2 are decompressed."
5277 (interactive (list nil current-prefix-arg))
5278 (gnus-article-check-buffer)
5280 (setq handle (get-text-property (point) 'gnus-data)))
5283 (inhibit-read-only t)
5284 contents charset coding-system)
5285 (if (and (not arg) (mm-handle-undisplayer handle))
5286 (mm-remove-part handle)
5287 (mm-with-unibyte-buffer
5288 (mm-insert-part handle)
5290 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5294 (unless (setq charset (mail-content-type-get
5295 (mm-handle-type handle) 'charset))
5296 (unless (setq coding-system
5297 (mm-with-unibyte-buffer
5299 (mm-find-buffer-file-coding-system)))
5300 (setq charset gnus-newsgroup-charset))))
5302 (if (mm-handle-undisplayer handle)
5303 (mm-remove-part handle))
5306 gnus-summary-show-article-charset-alist))
5307 (mm-read-coding-system "Charset: "))))
5308 ((mm-handle-undisplayer handle)
5309 (mm-remove-part handle)))
5311 (mm-display-inline handle)
5314 (defun gnus-mime-set-charset-parameters (handle charset)
5315 "Set CHARSET to parameters in HANDLE.
5316 CHARSET may either be a string or a symbol."
5317 (unless (stringp charset)
5318 (setq charset (symbol-name charset)))
5319 (if (stringp (car handle))
5320 (dolist (h (cdr handle))
5321 (gnus-mime-set-charset-parameters h charset))
5322 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5323 "message/external-body")
5325 (unless (mm-handle-cache handle)
5326 (mm-extern-cache-contents handle))
5327 (mm-handle-cache handle))
5329 (param (assq 'charset (cdr type))))
5331 (setcdr param charset)
5332 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5334 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5335 "Insert the MIME part under point into the current buffer using the
5337 (interactive (list nil current-prefix-arg))
5338 (gnus-article-check-buffer)
5339 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5340 (fun (get-text-property (point) 'gnus-callback))
5341 (gnus-newsgroup-ignored-charsets 'gnus-all)
5342 charset form preferred parts)
5349 gnus-summary-show-article-charset-alist))
5350 (mm-read-coding-system "Charset: "))))
5351 (if (mm-handle-undisplayer handle)
5352 (mm-remove-part handle)))
5353 (gnus-mime-set-charset-parameters handle charset)
5354 (when (and (consp (setq form (cdr-safe fun)))
5355 (setq form (ignore-errors
5356 (assq 'gnus-mime-display-alternative form)))
5357 (setq preferred (caddr form))
5359 (when (eq (car preferred) 'quote)
5360 (setq preferred (cadr preferred)))
5361 (not (equal preferred
5362 (get-text-property (point) 'gnus-data))))
5363 (setq parts (get-text-property (point) 'gnus-part))
5364 (setq parts (cdr (assq parts
5365 gnus-article-mime-handle-alist)))
5366 (equal (mm-handle-media-type parts) "multipart/alternative")
5367 (setq parts (reverse (cdr parts))))
5369 (list 'quote (or (cadr (member preferred parts))
5371 (funcall fun handle)))))
5373 (defun gnus-mime-view-part-externally (&optional handle)
5374 "View the MIME part under point with an external viewer."
5376 (gnus-article-check-buffer)
5377 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5378 (mm-user-display-methods nil)
5379 (mm-inlined-types nil)
5380 (mail-parse-charset gnus-newsgroup-charset)
5381 (mail-parse-ignored-charsets
5382 (with-current-buffer gnus-summary-buffer
5383 gnus-newsgroup-ignored-charsets))
5384 (type (mm-handle-media-type handle))
5385 (method (mailcap-mime-info type))
5386 (mm-enable-external t))
5387 (if (not (stringp method))
5388 (gnus-mime-view-part-as-type
5389 nil (lambda (type) (stringp (mailcap-mime-info type))))
5391 (mm-display-part handle nil t)))))
5393 (defun gnus-mime-view-part-internally (&optional handle)
5394 "View the MIME part under point with an internal viewer.
5395 If no internal viewer is available, use an external viewer."
5397 (gnus-article-check-buffer)
5398 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5399 (mm-inlined-types '(".*"))
5400 (mm-inline-large-images t)
5401 (mail-parse-charset gnus-newsgroup-charset)
5402 (mail-parse-ignored-charsets
5403 (with-current-buffer gnus-summary-buffer
5404 gnus-newsgroup-ignored-charsets))
5405 (inhibit-read-only t))
5406 (if (not (mm-inlinable-p handle))
5407 (gnus-mime-view-part-as-type
5408 nil (lambda (type) (mm-inlinable-p handle type)))
5410 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5412 (defun gnus-mime-action-on-part (&optional action)
5413 "Do something with the MIME attachment at \(point\)."
5415 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5416 (gnus-article-check-buffer)
5417 (let ((action-pair (assoc action gnus-mime-action-alist)))
5419 (funcall (cdr action-pair)))))
5421 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5422 "Call FUNCTION on MIME part N.
5423 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5424 If INTERACTIVE, call FUNCTION interactively."
5426 ;; Check whether the article is displayed.
5427 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5428 (setq window (get-buffer-window gnus-article-buffer t))
5429 (frame-visible-p (setq frame (window-frame window))))
5430 (error "No article is displayed"))
5431 (with-current-buffer gnus-article-buffer
5432 ;; Check whether the article displays the right contents.
5433 (unless (with-current-buffer gnus-summary-buffer
5434 (eq gnus-current-article (gnus-summary-article-number)))
5435 (error "You should select the right article first"))
5437 (setq n (prefix-numeric-value n))
5439 (setq n (or (get-text-property pt 'gnus-part)
5441 (get-text-property (1- pt) 'gnus-part))
5442 (get-text-property (prog2
5448 (or (and (setq pt (previous-single-property-change
5451 (next-single-property-change (point) 'gnus-part)
5455 ;; Check whether the specified part exists.
5456 (when (> n (length gnus-article-mime-handle-alist))
5457 (error "No such part")))
5460 ;; To select the window is needed so that the cursor
5461 ;; might be visible on the MIME button.
5462 (select-window (prog1
5464 (setq window (selected-window))
5465 ;; Article may be displayed in the other frame.
5466 (gnus-select-frame-set-input-focus
5469 (setq frame (selected-frame))))))
5470 (when (gnus-article-goto-part n)
5471 ;; We point the cursor and the arrow at the MIME button
5472 ;; when the `function' prompt the user for something.
5473 (unless (and (pos-visible-in-window-p)
5474 (> (count-lines (point) (window-end))
5475 (/ (1- (window-height)) 3)))
5476 (recenter (/ (1- (window-height)) 3)))
5477 (let ((cursor-in-non-selected-windows t)
5478 (overlay-arrow-string "=>")
5479 (overlay-arrow-position (point-marker)))
5482 ((and no-handle interactive)
5483 (call-interactively function))
5488 function (get-text-property (point) 'gnus-data)))
5491 (get-text-property (point) 'gnus-data))))
5492 (set-marker overlay-arrow-position nil)
5493 (unless gnus-auto-select-part
5494 (gnus-select-frame-set-input-focus frame)
5495 (select-window window))))
5497 (if gnus-inhibit-mime-unbuttonizing
5498 ;; This is the default though the program shouldn't reach here.
5499 (error "No such part")
5500 ;; The part which doesn't have the MIME button is selected.
5501 ;; So, we display all the buttons and redo it.
5502 (let ((gnus-inhibit-mime-unbuttonizing t))
5503 (gnus-summary-show-article)
5504 (gnus-article-part-wrapper n function no-handle))))))
5506 (defun gnus-article-pipe-part (n)
5507 "Pipe MIME part N, which is the numerical prefix."
5509 (gnus-article-part-wrapper n 'mm-pipe-part))
5511 (defun gnus-article-save-part (n)
5512 "Save MIME part N, which is the numerical prefix."
5514 (gnus-article-part-wrapper n 'mm-save-part))
5516 (defun gnus-article-interactively-view-part (n)
5517 "View MIME part N interactively, which is the numerical prefix."
5519 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5521 (defun gnus-article-copy-part (n)
5522 "Copy MIME part N, which is the numerical prefix."
5524 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5526 (defun gnus-article-view-part-as-charset (n)
5527 "View MIME part N using a specified charset.
5528 N is the numerical prefix."
5530 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5532 (defun gnus-article-view-part-externally (n)
5533 "View MIME part N externally, which is the numerical prefix."
5535 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5537 (defun gnus-article-inline-part (n)
5538 "Inline MIME part N, which is the numerical prefix."
5540 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5542 (defun gnus-article-save-part-and-strip (n)
5543 "Save MIME part N and replace it with an external body.
5544 N is the numerical prefix."
5546 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5548 (defun gnus-article-replace-part (n)
5549 "Replace MIME part N with an external body.
5550 N is the numerical prefix."
5552 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5554 (defun gnus-article-delete-part (n)
5555 "Delete MIME part N and add some information about the removed part.
5556 N is the numerical prefix."
5558 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5560 (defun gnus-article-view-part-as-type (n)
5561 "Choose a MIME media type, and view part N as such.
5562 N is the numerical prefix."
5564 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5566 (defun gnus-article-mime-match-handle-first (condition)
5569 (dolist (ihandle gnus-article-mime-handle-alist)
5571 ((functionp condition)
5572 (funcall condition (cdr ihandle)))
5573 ((eq condition 'undisplayed)
5574 (not (or (mm-handle-undisplayer (cdr ihandle))
5575 (equal (mm-handle-media-type (cdr ihandle))
5576 "multipart/alternative"))))
5577 ((eq condition 'undisplayed-alternative)
5578 (not (mm-handle-undisplayer (cdr ihandle))))
5580 (gnus-article-goto-part (car ihandle))
5581 (or (not n) (< (car ihandle) n)))
5582 (setq n (car ihandle))))
5586 (defun gnus-article-view-part (&optional n)
5587 "View MIME part N, which is the numerical prefix.
5588 If the part is already shown, hide the part. If N is nil, view
5591 (with-current-buffer gnus-article-buffer
5592 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5593 gnus-article-mime-match-handle-function)))
5594 (when (> n (length gnus-article-mime-handle-alist))
5595 (error "No such part"))
5596 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5597 (when (gnus-article-goto-part n)
5598 (if (equal (car handle) "multipart/alternative")
5600 (beginning-of-line) ;; Make it toggle subparts
5601 (gnus-article-press-button))
5602 (when (eq (gnus-mm-display-part handle) 'internal)
5603 (gnus-set-window-start)))))))
5605 (defsubst gnus-article-mime-total-parts ()
5606 (if (bufferp (car gnus-article-mime-handles))
5608 (1- (length gnus-article-mime-handles))))
5610 (defun gnus-mm-display-part (handle)
5611 "Display HANDLE and fix MIME button."
5612 (let ((id (get-text-property (point) 'gnus-part))
5614 (inhibit-read-only t))
5617 (let ((window (selected-window))
5618 (mail-parse-charset gnus-newsgroup-charset)
5619 (mail-parse-ignored-charsets
5620 (if (gnus-buffer-live-p gnus-summary-buffer)
5621 (with-current-buffer gnus-summary-buffer
5622 gnus-newsgroup-ignored-charsets)
5626 (let ((win (gnus-get-buffer-window (current-buffer) t))
5629 (select-window win))
5632 (if (mm-handle-displayed-p handle)
5633 ;; This will remove the part.
5634 (mm-display-part handle)
5636 (narrow-to-region (point)
5637 (if (eobp) (point) (1+ (point))))
5638 (gnus-bind-safe-url-regexp (mm-display-part handle))
5639 ;; We narrow to the part itself and
5640 ;; then call the treatment functions.
5641 (goto-char (point-min))
5643 (narrow-to-region (point) (point-max))
5646 (gnus-article-mime-total-parts)
5647 (mm-handle-media-type handle)))))
5648 (if (window-live-p window)
5649 (select-window window)))))
5652 (gnus-insert-mime-button
5653 handle id (list (mm-handle-displayed-p handle)))
5654 (goto-char point))))
5656 (defun gnus-article-goto-part (n)
5657 "Go to MIME part N."
5658 (when gnus-break-pages
5661 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5662 part handle end next handles)
5665 (if (setq handle (get-text-property start 'gnus-data))
5667 ;; Go to the displayed subpart, assuming this is
5668 ;; multipart/alternative.
5671 (while (and (not handle)
5674 (setq next (text-property-not-all part end
5677 handle (get-text-property part 'gnus-data))
5678 (push (cons handle part) handles)
5679 (unless (mm-handle-displayed-p handle)
5681 part (text-property-any part end 'gnus-data nil))))
5683 ;; No subpart is displayed, so we find preferred one.
5685 (cdr (assq (mm-preferred-alternative
5686 (nreverse (mapcar 'car handles)))
5689 (goto-char (1+ part))
5691 (when gnus-break-pages
5692 (gnus-narrow-to-page))))
5694 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5695 (let ((gnus-tmp-name
5696 (or (mm-handle-filename handle)
5697 (mail-content-type-get (mm-handle-type handle) 'url)
5699 (gnus-tmp-type (mm-handle-media-type handle))
5700 (gnus-tmp-description (or (mm-handle-description handle) ""))
5702 (if (if displayed (car displayed)
5703 (mm-handle-displayed-p handle))
5705 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5707 gnus-tmp-type-long b e)
5708 (when (string-match ".*/" gnus-tmp-name)
5709 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5710 (setq gnus-tmp-type-long (concat gnus-tmp-type
5711 (and (not (equal gnus-tmp-name ""))
5712 (concat "; " gnus-tmp-name))))
5713 (unless (equal gnus-tmp-description "")
5714 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5719 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5720 `(keymap ,gnus-mime-button-map
5721 gnus-callback gnus-mm-display-part
5722 gnus-part ,gnus-tmp-id
5723 article-type annotation
5727 ;; Exclude a newline.
5730 (when gnus-article-button-face
5731 (gnus-overlay-put (gnus-make-overlay b e nil t)
5732 'face gnus-article-button-face))
5733 (widget-convert-button
5736 :action 'gnus-widget-press-button
5737 :button-keymap gnus-mime-button-map
5740 ;; Needed to properly clear the message due to a bug in
5741 ;; wid-edit (XEmacs only).
5742 (if (boundp 'help-echo-owns-message)
5743 (setq help-echo-owns-message t))
5745 "%S: %s the MIME part; %S: more options"
5746 (aref gnus-mouse-2 0)
5747 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5749 (aref gnus-down-mouse-3 0))))))
5751 (defun gnus-widget-press-button (elems el)
5752 (goto-char (widget-get elems :from))
5753 (gnus-article-press-button))
5755 (defvar gnus-displaying-mime nil)
5757 (defun gnus-display-mime (&optional ihandles)
5758 "Display the MIME parts."
5760 (save-selected-window
5761 (let ((window (get-buffer-window gnus-article-buffer))
5764 (select-window window)
5765 ;; We have to do this since selecting the window
5766 ;; may change the point. So we set the window point.
5767 (set-window-point window point)))
5768 (let ((handles ihandles)
5769 (inhibit-read-only t)
5772 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5773 (when gnus-article-emulate-mime
5774 (mm-uu-dissect-text-parts handles)))
5775 (gnus-article-emulate-mime
5776 (setq handles (mm-uu-dissect))))
5777 (when (and (not ihandles)
5778 (not gnus-displaying-mime))
5779 ;; Top-level call; we clean up.
5780 (when gnus-article-mime-handles
5781 (mm-destroy-parts gnus-article-mime-handles)
5782 (setq gnus-article-mime-handle-alist nil));; A trick.
5783 (setq gnus-article-mime-handles handles)
5784 ;; We allow users to glean info from the handles.
5785 (when gnus-article-mime-part-function
5786 (gnus-mime-part-function handles)))
5788 (or (not (stringp (car handles)))
5791 (when (and (not ihandles)
5792 (not gnus-displaying-mime))
5793 ;; Clean up for mime parts.
5795 (delete-region (point) (point-max)))
5796 (let ((gnus-displaying-mime t))
5797 (gnus-mime-display-part handles)))
5800 (narrow-to-region (point) (point-max))
5801 (gnus-treat-article nil 1 1 "text/plain")
5804 ;; Highlight the headers.
5808 (narrow-to-region (point-min) (point))
5809 (gnus-article-save-original-date
5810 (gnus-treat-article 'head)))))))
5811 ;; Cope with broken MIME messages.
5812 (goto-char (point-max))
5816 (defcustom gnus-mime-display-multipart-as-mixed nil
5817 "Display \"multipart\" parts as \"multipart/mixed\".
5819 If t, it overrides nil values of
5820 `gnus-mime-display-multipart-alternative-as-mixed' and
5821 `gnus-mime-display-multipart-related-as-mixed'."
5822 :group 'gnus-article-mime
5825 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5826 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5828 :group 'gnus-article-mime
5831 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5832 "Display \"multipart/related\" parts as \"multipart/mixed\".
5834 If displaying \"text/html\" is discouraged \(see
5835 `mm-discouraged-alternatives'\) images or other material inside a
5836 \"multipart/related\" part might be overlooked when this variable is nil."
5838 :group 'gnus-article-mime
5841 (defun gnus-mime-display-part (handle)
5843 ;; Maybe a broken MIME message.
5846 ((not (stringp (car handle)))
5847 (gnus-mime-display-single handle))
5848 ;; User-defined multipart
5849 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5850 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5852 ;; multipart/alternative
5853 ((and (equal (car handle) "multipart/alternative")
5854 (not (or gnus-mime-display-multipart-as-mixed
5855 gnus-mime-display-multipart-alternative-as-mixed)))
5856 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5857 (push (cons id handle) gnus-article-mime-handle-alist)
5858 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5859 ;; multipart/related
5860 ((and (equal (car handle) "multipart/related")
5861 (not (or gnus-mime-display-multipart-as-mixed
5862 gnus-mime-display-multipart-related-as-mixed)))
5863 ;;;!!!We should find the start part, but we just default
5864 ;;;!!!to the first part.
5865 ;;(gnus-mime-display-part (cadr handle))
5866 ;;;!!! Most multipart/related is an HTML message plus images.
5867 ;;;!!! Unfortunately we are unable to let W3 display those
5868 ;;;!!! included images, so we just display it as a mixed multipart.
5869 ;;(gnus-mime-display-mixed (cdr handle))
5870 ;;;!!! No, w3 can display everything just fine.
5871 (gnus-mime-display-part (cadr handle)))
5872 ((equal (car handle) "multipart/signed")
5873 (gnus-add-wash-type 'signed)
5874 (gnus-mime-display-security handle))
5875 ((equal (car handle) "multipart/encrypted")
5876 (gnus-add-wash-type 'encrypted)
5877 (gnus-mime-display-security handle))
5878 ;; Other multiparts are handled like multipart/mixed.
5880 (gnus-mime-display-mixed (cdr handle)))))
5882 (defun gnus-mime-part-function (handles)
5883 (if (stringp (car handles))
5884 (mapcar 'gnus-mime-part-function (cdr handles))
5885 (funcall gnus-article-mime-part-function handles)))
5887 (defun gnus-mime-display-mixed (handles)
5888 (mapcar 'gnus-mime-display-part handles))
5890 (defun gnus-mime-display-single (handle)
5891 (let ((type (mm-handle-media-type handle))
5892 (ignored gnus-ignored-mime-types)
5899 (when (string-match (pop ignored) type)
5900 (throw 'ignored nil)))
5901 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5902 (with-current-buffer gnus-summary-buffer
5903 gnus-inhibit-images)
5904 gnus-inhibit-images)
5905 (string-match "\\`image/" type)))
5906 (setq not-attachment
5907 (and (not (mm-inline-override-p handle))
5908 (or (not (mm-handle-disposition handle))
5909 (equal (car (mm-handle-disposition handle))
5911 (mm-attachment-override-p handle))))
5912 (mm-automatic-display-p handle)
5914 (mm-inlinable-p handle)
5915 (mm-inlined-p handle))
5916 (mm-automatic-external-display-p type)))
5918 (when (equal (mm-handle-media-supertype handle) "text")
5920 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5922 (push (cons id handle) gnus-article-mime-handle-alist)
5924 (equal (mm-handle-media-supertype handle) "message"))
5927 (cond ((not (bolp)) 2)
5928 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5930 (when (or (not display)
5931 (not (gnus-unbuttonized-mime-type-p type))
5932 (eq id gnus-mime-buttonized-part-id))
5933 (gnus-insert-mime-button
5934 handle id (list (or display (and not-attachment text))))
5935 (gnus-article-insert-newline)
5936 ;; Remember modify the number of forward lines.
5944 (let ((mail-parse-charset gnus-newsgroup-charset)
5945 (mail-parse-ignored-charsets
5946 (save-excursion (condition-case ()
5947 (set-buffer gnus-summary-buffer)
5949 gnus-newsgroup-ignored-charsets)))
5950 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5951 (goto-char (point-max)))
5952 ((and text not-attachment)
5956 (gnus-article-insert-newline)
5957 (mm-display-inline handle)
5958 (goto-char (point-max))))
5962 (narrow-to-region beg (point))
5963 (if (eq handle gnus-article-mime-handles)
5964 ;; The format=flowed case.
5965 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5966 ;; Don't count signature parts that are never displayed.
5967 ;; The part number should be re-calculated supposing this
5968 ;; might be a message/rfc822 part.
5970 (dolist (part gnus-article-mime-handles)
5971 (unless (or (stringp part)
5972 (equal (car (mm-handle-type part))
5973 "application/pgp-signature"))
5974 (push part handles)))
5976 nil (length (memq handle handles)) (length handles)
5977 (mm-handle-media-type handle)))))))))))
5979 (defun gnus-unbuttonized-mime-type-p (type)
5980 "Say whether TYPE is to be unbuttonized."
5981 (unless gnus-inhibit-mime-unbuttonizing
5983 (let ((types gnus-unbuttonized-mime-types))
5985 (when (string-match (pop types) type)
5986 (throw 'found t)))))
5988 (let ((types gnus-buttonized-mime-types))
5990 (when (string-match (pop types) type)
5991 (throw 'found t)))))))))
5993 (defun gnus-article-insert-newline ()
5994 "Insert a newline, but mark it as undeletable."
5995 (gnus-put-text-property
5996 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5998 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5999 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6002 handle (inhibit-read-only t) from props begend not-pref)
6003 (save-window-excursion
6006 (narrow-to-region (car ibegend)
6009 (goto-char (car ibegend))
6012 (delete-region (point-min) (point-max))
6013 (mm-remove-parts handles))
6014 (setq begend (list (point-marker)))
6016 (unless (setq not-pref (cadr (member preferred ihandles)))
6017 (setq not-pref (car ihandles)))
6020 (not (gnus-unbuttonized-mime-type-p
6021 "multipart/alternative")))
6022 (gnus-add-text-properties
6025 (insert (format "%d. " id))
6029 (unless ,(not ibegend)
6030 (setq gnus-article-mime-handle-alist
6031 ',gnus-article-mime-handle-alist))
6032 (gnus-mime-display-alternative
6033 ',ihandles ',not-pref ',begend ,id))
6034 keymap ,gnus-mime-button-map
6035 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6036 face ,gnus-article-button-face
6038 article-type multipart
6040 (widget-convert-button 'link from (point)
6041 :action 'gnus-widget-press-button
6042 :button-keymap gnus-widget-button-keymap)
6044 (while (setq handle (pop handles))
6045 (gnus-add-text-properties
6048 (insert (format "(%c) %-18s"
6049 (if (equal handle preferred) ?* ? )
6050 (mm-handle-media-type handle)))
6054 (unless ,(not ibegend)
6055 (setq gnus-article-mime-handle-alist
6056 ',gnus-article-mime-handle-alist))
6057 (gnus-mime-display-alternative
6058 ',ihandles ',handle ',begend ,id))
6059 keymap ,gnus-mime-button-map
6060 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6061 face ,gnus-article-button-face
6065 (widget-convert-button 'link from (point)
6066 :action 'gnus-widget-press-button
6067 :button-keymap gnus-widget-button-keymap)
6071 (if (stringp (car preferred))
6072 (gnus-display-mime preferred)
6073 (let ((mail-parse-charset gnus-newsgroup-charset)
6074 (mail-parse-ignored-charsets
6075 (with-current-buffer gnus-summary-buffer
6076 gnus-newsgroup-ignored-charsets)))
6077 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6081 (narrow-to-region (car begend) (point-max))
6083 nil (length gnus-article-mime-handle-alist)
6084 (gnus-article-mime-total-parts)
6085 (mm-handle-media-type preferred))))))
6086 (goto-char (point-max))
6087 (setcdr begend (point-marker)))))
6089 (goto-char point))))
6091 (defconst gnus-article-wash-status-strings
6092 (let ((alist '((cite "c" "Possible hidden citation text"
6093 " " "All citation text visible")
6094 (headers "h" "Hidden headers"
6095 " " "All headers visible.")
6096 (pgp "p" "Encrypted or signed message status hidden"
6097 " " "No hidden encryption nor digital signature status")
6098 (signature "s" "Signature has been hidden"
6099 " " "Signature is visible")
6100 (overstrike "o" "Overstrike (^H) characters applied"
6101 " " "No overstrike characters applied")
6102 (emphasis "e" "/*_Emphasis_*/ characters applied"
6103 " " "No /*_emphasis_*/ characters applied")))
6105 (dolist (entry alist result)
6106 (let ((key (nth 0 entry))
6107 (on (copy-sequence (nth 1 entry)))
6108 (on-help (nth 2 entry))
6109 (off (copy-sequence (nth 3 entry)))
6110 (off-help (nth 4 entry)))
6111 (put-text-property 0 1 'help-echo on-help on)
6112 (put-text-property 0 1 'help-echo off-help off)
6113 (push (list key on off) result))))
6114 "Alist of strings describing wash status in the mode line.
6115 Each entry has the form (KEY ON OF), where the KEY is a symbol
6116 representing the particular washing function, ON is the string to use
6117 in the article mode line when the washing function is active, and OFF
6118 is the string to use when it is inactive.")
6120 (defun gnus-article-wash-status-entry (key value)
6121 (let ((entry (assoc key gnus-article-wash-status-strings)))
6122 (if value (nth 1 entry) (nth 2 entry))))
6124 (defun gnus-article-wash-status ()
6125 "Return a string which display status of article washing."
6126 (with-current-buffer gnus-article-buffer
6127 (let ((cite (memq 'cite gnus-article-wash-types))
6128 (headers (memq 'headers gnus-article-wash-types))
6129 (boring (memq 'boring-headers gnus-article-wash-types))
6130 (pgp (memq 'pgp gnus-article-wash-types))
6131 (pem (memq 'pem gnus-article-wash-types))
6132 (signed (memq 'signed gnus-article-wash-types))
6133 (encrypted (memq 'encrypted gnus-article-wash-types))
6134 (signature (memq 'signature gnus-article-wash-types))
6135 (overstrike (memq 'overstrike gnus-article-wash-types))
6136 (emphasis (memq 'emphasis gnus-article-wash-types)))
6138 (gnus-article-wash-status-entry 'cite cite)
6139 (gnus-article-wash-status-entry 'headers (or headers boring))
6140 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6141 (gnus-article-wash-status-entry 'signature signature)
6142 (gnus-article-wash-status-entry 'overstrike overstrike)
6143 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6145 (defun gnus-add-wash-type (type)
6146 "Add a washing of TYPE to the current status."
6147 (add-to-list 'gnus-article-wash-types type))
6149 (defun gnus-delete-wash-type (type)
6150 "Add a washing of TYPE to the current status."
6151 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6153 (defun gnus-add-image (category image)
6154 "Add IMAGE of CATEGORY to the list of displayed images."
6155 (let ((entry (assq category gnus-article-image-alist)))
6157 (setq entry (list category))
6158 (push entry gnus-article-image-alist))
6159 (nconc entry (list image))))
6161 (defun gnus-delete-images (category)
6162 "Delete all images in CATEGORY."
6163 (let ((entry (assq category gnus-article-image-alist)))
6164 (dolist (image (cdr entry))
6165 (gnus-remove-image image category))
6166 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6167 (gnus-delete-wash-type category)))
6169 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6171 (defun gnus-article-maybe-hide-headers ()
6172 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6173 Provided for backwards compatibility."
6174 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6175 (not (with-current-buffer gnus-summary-buffer
6176 gnus-have-all-headers)))
6177 (not gnus-inhibit-hiding))
6178 (gnus-article-hide-headers)))
6180 (declare-function shr-put-image "shr" (data alt &optional flags))
6182 (defun gnus-shr-put-image (data alt &optional flags)
6183 "Put image DATA with a string ALT. Enable image to be deleted."
6184 (let ((image (shr-put-image data (propertize (or alt "*")
6185 'gnus-image-category 'shr)
6188 (gnus-add-image 'shr image))))
6192 (defun gnus-output-to-file (file-name)
6193 "Append the current article to a file named FILE-NAME.
6194 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6195 text and used as the value of the coding cookie which is added to the
6196 top of a file. Otherwise, this function saves a raw article without
6198 (let* ((artbuf (current-buffer))
6199 (file-name-coding-system nnmail-pathname-coding-system)
6200 (coding gnus-article-save-coding-system)
6201 (coding-system-for-read (if coding
6202 nil ;; Rely on the coding cookie.
6203 mm-text-coding-system))
6204 (coding-system-for-write (or coding
6205 mm-text-coding-system-for-write
6206 mm-text-coding-system))
6207 (exists (file-exists-p file-name)))
6210 (insert-file-contents file-name)
6211 (goto-char (point-min))
6212 ;; Remove the existing coding cookie.
6213 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6214 (delete-region (match-beginning 0) (match-end 0))))
6215 (goto-char (point-max))
6216 (insert-buffer-substring artbuf)
6217 ;; Append newline at end of the buffer as separator, and then
6219 (goto-char (point-max))
6222 ;; If the coding system is not suitable to encode the text,
6223 ;; ask a user for a proper one.
6224 (when (fboundp 'select-safe-coding-system)
6225 (setq coding (coding-system-base
6226 (save-window-excursion
6227 (select-safe-coding-system (point-min) (point-max)
6229 (setq coding-system-for-write
6230 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6232 (goto-char (point-min))
6233 ;; Add the coding cookie.
6234 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6235 coding-system-for-write)))
6238 (write-region (point-min) (point-max) file-name nil 'no-message)
6239 (message "Appended to %s" file-name))
6240 (write-region (point-min) (point-max) file-name))))
6243 (defun gnus-narrow-to-page (&optional arg)
6244 "Narrow the article buffer to a page.
6245 If given a numerical ARG, move forward ARG pages."
6247 (setq arg (if arg (prefix-numeric-value arg) 0))
6248 (with-current-buffer gnus-article-buffer
6250 ;; Remove any old next/prev buttons.
6251 (when (gnus-visual-p 'page-marker)
6252 (let ((inhibit-read-only t))
6253 (gnus-remove-text-with-property 'gnus-prev)
6254 (gnus-remove-text-with-property 'gnus-next)))
6256 (when (save-excursion
6258 (if (re-search-backward page-delimiter nil 'move (abs arg))
6260 (setq nd (match-beginning 0)
6262 (when (re-search-backward page-delimiter nil t)
6263 (setq st (match-end 0))))
6264 (when (re-search-forward page-delimiter nil t)
6265 (setq nd (match-beginning 0)
6268 (if (re-search-forward page-delimiter nil 'move arg)
6270 (setq st (match-end 0)
6272 (when (re-search-forward page-delimiter nil t)
6273 (setq nd (match-beginning 0))))
6274 (when (re-search-backward page-delimiter nil t)
6275 (setq st (match-end 0)
6278 (when (re-search-backward page-delimiter nil t)
6279 (goto-char (setq st (match-end 0))))
6280 (when (re-search-forward page-delimiter nil t)
6281 (setq nd (match-beginning 0)))
6283 (setq gnus-page-broken t)
6284 (when pt (goto-char pt))
6285 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6286 (when (gnus-visual-p 'page-marker)
6290 (gnus-insert-next-page-button))
6293 (gnus-insert-prev-page-button))))))))
6295 ;; Article mode commands
6297 (defun gnus-article-goto-next-page ()
6298 "Show the next page of the article."
6300 (when (gnus-article-next-page)
6301 (goto-char (point-min))
6302 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6305 (defun gnus-article-goto-prev-page ()
6306 "Show the previous page of the article."
6308 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6309 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6310 (gnus-article-prev-page nil)))
6312 ;; This is cleaner but currently breaks `gnus-pick-mode':
6314 ;; (defun gnus-article-goto-next-page ()
6315 ;; "Show the next page of the article."
6317 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6318 ;; (gnus-summary-next-page)))
6320 ;; (defun gnus-article-goto-prev-page ()
6321 ;; "Show the next page of the article."
6323 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6324 ;; (gnus-summary-prev-page)))
6326 (defun gnus-article-next-page (&optional lines)
6327 "Show the next page of the current article.
6328 If end of article, return non-nil. Otherwise return nil.
6329 Argument LINES specifies lines to be scrolled up."
6331 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6332 (if (and (not (and gnus-article-over-scroll
6333 (> (count-lines (window-start) (point-max))
6334 (if (featurep 'xemacs)
6335 (or lines (1- (window-height)))
6336 (+ (or lines (1- (window-height))) scroll-margin)))))
6339 (and (pos-visible-in-window-p) ;Not continuation line.
6340 (>= (point) (point-max)))))
6341 ;; Nothing in this page.
6342 (if (or (not gnus-page-broken)
6347 (eobp)))) ;Real end-of-buffer?
6349 (when gnus-article-over-scroll
6350 (gnus-article-next-page-1 lines))
6352 (gnus-narrow-to-page 1) ;Go to next page.
6354 ;; More in this page.
6355 (gnus-article-next-page-1 lines)
6358 (defun gnus-article-beginning-of-window ()
6359 "Move point to the beginning of the window.
6360 In Emacs, the point is placed at the line number which `scroll-margin'
6362 (if (featurep 'xemacs)
6363 (move-to-window-line 0)
6364 ;; There is an obscure bug in Emacs that makes it impossible to
6365 ;; scroll past big pictures in the article buffer. Try to fix
6366 ;; this by adding a sanity check by counting the lines visible.
6367 (when (> (count-lines (window-start) (window-end)) 30)
6368 (move-to-window-line
6369 (min (max 0 scroll-margin)
6370 (max 1 (- (window-height)
6371 (if mode-line-format 1 0)
6372 (if header-line-format 1 0)
6375 (defun gnus-article-next-page-1 (lines)
6377 (let ((scroll-in-place nil)
6378 (auto-window-vscroll nil))
6381 ;; Long lines may cause an end-of-buffer error.
6382 (goto-char (point-max))))
6383 (gnus-article-beginning-of-window))
6385 (defun gnus-article-prev-page (&optional lines)
6386 "Show previous page of current article.
6387 Argument LINES specifies lines to be scrolled down."
6389 (move-to-window-line 0)
6390 (if (and gnus-page-broken
6392 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6394 (gnus-narrow-to-page -1) ;Go to previous page.
6395 (goto-char (point-max))
6396 (recenter (if gnus-article-over-scroll
6398 (max (if (featurep 'xemacs)
6400 (+ lines scroll-margin))
6402 (- (window-height) 2))
6406 (let ((scroll-in-place nil))
6407 (scroll-down lines))
6408 (beginning-of-buffer
6409 (goto-char (point-min))))
6410 (gnus-article-beginning-of-window))))
6412 (defun gnus-article-only-boring-p ()
6413 "Decide whether there is only boring text remaining in the article.
6414 Something \"interesting\" is a word of at least two letters that does
6415 not have a face in `gnus-article-boring-faces'."
6416 (when (and gnus-article-skip-boring
6417 (boundp 'gnus-article-boring-faces)
6418 (symbol-value 'gnus-article-boring-faces))
6420 (let ((inhibit-point-motion-hooks t))
6422 (while (re-search-forward "\\b\\w\\w" nil t)
6424 (when (not (gnus-intersection
6425 (gnus-faces-at (point))
6426 (symbol-value 'gnus-article-boring-faces)))
6427 (throw 'only-boring nil)))
6428 (throw 'only-boring t))))))
6430 (defun gnus-article-refer-article ()
6431 "Read article specified by message-id around point."
6434 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6435 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6436 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6437 (let ((msg-id (concat "<" (match-string 0) ">")))
6438 (set-buffer gnus-summary-buffer)
6439 (gnus-summary-refer-article msg-id))
6440 (error "No references around point"))))
6442 (defun gnus-article-show-summary ()
6443 "Reconfigure windows to show summary buffer."
6445 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6446 (error "There is no summary buffer for this article buffer")
6447 (gnus-article-set-globals)
6448 (gnus-configure-windows 'article)
6449 (gnus-summary-goto-subject gnus-current-article)
6450 (gnus-summary-position-point)))
6452 (defun gnus-article-describe-briefly ()
6453 "Describe article mode commands briefly."
6455 (gnus-message 6 "%s" (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")))
6457 (defun gnus-article-check-buffer ()
6458 "Beep if not in an article buffer."
6459 (unless (equal major-mode 'gnus-article-mode)
6460 (error "Command invoked outside of a Gnus article buffer")))
6462 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6463 "Read a summary buffer key sequence and execute it from the article buffer."
6465 (gnus-article-check-buffer)
6467 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6468 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6469 "=" "^" "\M-^" "|"))
6471 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6472 "An" "Ap" [?A (meta return)] [?A delete]))
6476 '("n" "Gn" "p" "Gp"))
6478 (with-current-buffer gnus-article-current-summary
6479 (let (gnus-pick-mode)
6480 (setq unread-command-events (nconc unread-command-events
6481 (list (or key last-command-event)))
6482 keys (if (featurep 'xemacs)
6483 (events-to-keys (read-key-sequence nil t))
6484 (read-key-sequence nil t)))))
6489 ((eq (aref keys (1- (length keys))) ?\C-h)
6490 (gnus-article-describe-bindings (substring keys 0 -1)))
6491 ((or (member keys nosaves)
6492 (member keys nosave-but-article)
6493 (member keys nosave-in-article))
6495 (save-window-excursion
6496 (pop-to-buffer gnus-article-current-summary)
6497 ;; We disable the pick minor mode commands.
6498 (let (gnus-pick-mode)
6499 (setq func (key-binding keys t))))
6503 (unless (member keys nosave-in-article)
6504 (set-buffer gnus-article-current-summary))
6505 (when (and (symbolp func)
6506 (get func 'disabled))
6507 (error "Function %s disabled" func))
6508 (call-interactively func)
6509 (setq new-sum-point (point)))
6510 (when (member keys nosave-but-article)
6511 (pop-to-buffer gnus-article-buffer))))
6513 ;; These commands should restore window configuration.
6514 (let ((obuf (current-buffer))
6515 (owin (current-window-configuration))
6516 win func in-buffer selected new-sum-start new-sum-hscroll err)
6517 (cond (not-restore-window
6518 (pop-to-buffer gnus-article-current-summary)
6519 (setq win (selected-window)))
6520 ((setq win (get-buffer-window gnus-article-current-summary))
6521 (select-window win))
6523 (let ((summary-buffer gnus-article-current-summary))
6524 (gnus-configure-windows 'article)
6525 (unless (setq win (get-buffer-window summary-buffer 'visible))
6526 (let ((gnus-buffer-configuration
6527 '((article ((vertical 1.0
6528 (summary 0.25 point)
6530 (gnus-configure-windows 'article))
6531 (setq win (get-buffer-window summary-buffer 'visible)))
6532 (gnus-select-frame-set-input-focus (window-frame win))
6533 (select-window win))))
6534 (setq in-buffer (current-buffer))
6535 ;; We disable the pick minor mode commands.
6536 (setq func (let (gnus-pick-mode)
6537 (key-binding keys t)))
6538 (when (get func 'disabled)
6539 (error "Function %s disabled" func))
6542 (condition-case code
6544 (call-interactively func)
6550 (when (eq win (selected-window))
6551 (setq new-sum-point (point)
6552 new-sum-start (window-start win)
6553 new-sum-hscroll (window-hscroll win)))
6554 (when (or (eq in-buffer (current-buffer))
6555 (when (eq obuf (current-buffer))
6556 (set-buffer in-buffer)
6558 (setq selected (gnus-summary-select-article))
6560 (unless not-restore-window
6561 (set-window-configuration owin))
6562 (when (and (eq selected 'old)
6564 (set-window-start (get-buffer-window (current-buffer))
6566 (set-window-point (get-buffer-window (current-buffer))
6567 (if (article-goto-body)
6570 (when (and (not not-restore-window)
6573 (with-current-buffer (window-buffer win)
6574 (eq major-mode 'gnus-summary-mode)))
6575 (set-window-point win new-sum-point)
6576 (set-window-start win new-sum-start)
6577 (set-window-hscroll win new-sum-hscroll))))
6578 (set-window-configuration owin)
6580 (signal (car err) (cdr err))
6583 (defun gnus-article-read-summary-send-keys ()
6585 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6586 (gnus-article-read-summary-keys)))
6588 (defun gnus-article-describe-key (key)
6589 "Display documentation of the function invoked by KEY.
6590 KEY is a string or a vector."
6591 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6592 (read-key-sequence "Describe key: "))))
6593 (gnus-article-check-buffer)
6594 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6595 gnus-article-read-summary-send-keys))
6596 (with-current-buffer gnus-article-current-summary
6597 (setq unread-command-events
6598 (if (featurep 'xemacs)
6600 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6601 (list 'meta (- x 128))
6604 (let ((cursor-in-echo-area t)
6606 (describe-key (read-key-sequence nil t))))
6607 (describe-key key)))
6609 (defun gnus-article-describe-key-briefly (key &optional insert)
6610 "Display documentation of the function invoked by KEY.
6611 KEY is a string or a vector."
6612 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6613 (read-key-sequence "Describe key: "))
6614 current-prefix-arg))
6615 (gnus-article-check-buffer)
6616 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6617 gnus-article-read-summary-send-keys))
6618 (with-current-buffer gnus-article-current-summary
6619 (setq unread-command-events
6620 (if (featurep 'xemacs)
6622 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6623 (list 'meta (- x 128))
6626 (let ((cursor-in-echo-area t)
6628 (describe-key-briefly (read-key-sequence nil t) insert)))
6629 (describe-key-briefly key insert)))
6631 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6632 (defvar gnus-agent-summary-mode)
6633 (defvar gnus-draft-mode)
6634 ;; Calling help-buffer will autoload help-mode.
6635 (defvar help-xref-stack-item)
6636 ;; Emacs 22 doesn't load it in the batch mode.
6638 (autoload 'help-buffer "help-mode"))
6640 (defun gnus-article-describe-bindings (&optional prefix)
6641 "Show a list of all defined keys, and their definitions.
6642 The optional argument PREFIX, if non-nil, should be a key sequence;
6643 then we display only bindings that start with that prefix."
6645 (gnus-article-check-buffer)
6646 (let ((keymap (copy-keymap gnus-article-mode-map))
6647 (map (copy-keymap gnus-article-send-map))
6648 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6650 (define-key keymap "S" map)
6651 (define-key map [t] nil)
6652 (with-current-buffer gnus-article-current-summary
6655 (if (setq parent (keymap-parent gnus-article-mode-map))
6657 (setq parent (copy-keymap parent))
6658 (set-keymap-parent parent (current-local-map)))
6659 (current-local-map)))
6660 (set-keymap-parent map (key-binding "S"))
6661 (let (key def gnus-pick-mode)
6663 (setq key (pop sumkeys))
6664 (cond ((and (vectorp key) (= (length key) 1)
6665 (consp (setq def (aref key 0)))
6666 (numberp (car def)) (numberp (cdr def)))
6667 (when (< (max (car def) (cdr def)) 128)
6671 (nreverse (gnus-uncompress-range def)))
6673 ((setq def (key-binding key))
6674 (unless (eq def 'undefined)
6675 (define-key keymap key def))))))
6676 (when (boundp 'gnus-agent-summary-mode)
6677 (setq agent gnus-agent-summary-mode))
6678 (when (boundp 'gnus-draft-mode)
6679 (setq draft gnus-draft-mode)))
6681 (use-local-map keymap)
6682 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6683 (set (make-local-variable 'gnus-draft-mode) draft)
6684 (describe-bindings prefix))
6685 (let ((item `((lambda (prefix)
6686 (with-current-buffer ,(current-buffer)
6687 (gnus-article-describe-bindings prefix)))
6689 (with-current-buffer (let (help-xref-following) (help-buffer))
6690 (setq help-xref-stack-item item)))))
6692 (defun gnus-article-reply-with-original (&optional wide)
6693 "Start composing a reply mail to the current message.
6694 The text in the region will be yanked. If the region isn't active,
6695 the entire article will be yanked."
6697 (let ((article (cdr gnus-article-current))
6699 (if (not (gnus-region-active-p))
6700 (with-current-buffer gnus-summary-buffer
6701 (gnus-summary-reply (list (list article)) wide))
6702 (setq contents (buffer-substring (point) (mark t)))
6703 ;; Deactivate active regions.
6704 (when (and (boundp 'transient-mark-mode)
6705 transient-mark-mode)
6706 (setq mark-active nil))
6707 (with-current-buffer gnus-summary-buffer
6709 (list (list article contents)) wide)))))
6711 (defun gnus-article-wide-reply-with-original ()
6712 "Start composing a wide reply mail to the current message.
6713 The text in the region will be yanked. If the region isn't active,
6714 the entire article will be yanked."
6716 (gnus-article-reply-with-original t))
6718 (defun gnus-article-followup-with-original ()
6719 "Compose a followup to the current article.
6720 The text in the region will be yanked. If the region isn't active,
6721 the entire article will be yanked."
6723 (let ((article (cdr gnus-article-current))
6725 (if (not (gnus-region-active-p))
6726 (with-current-buffer gnus-summary-buffer
6727 (gnus-summary-followup (list (list article))))
6728 (setq contents (buffer-substring (point) (mark t)))
6729 ;; Deactivate active regions.
6730 (when (and (boundp 'transient-mark-mode)
6731 transient-mark-mode)
6732 (setq mark-active nil))
6733 (with-current-buffer gnus-summary-buffer
6734 (gnus-summary-followup
6735 (list (list article contents)))))))
6737 (defun gnus-article-hide (&optional arg force)
6738 "Hide all the gruft in the current article.
6739 This means that signatures, cited text and (some) headers will be
6741 If given a prefix, show the hidden text instead."
6742 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6743 (gnus-article-hide-headers arg)
6744 (gnus-article-hide-list-identifiers arg)
6745 (gnus-article-hide-citation-maybe arg force)
6746 (gnus-article-hide-signature arg))
6748 (defun gnus-check-group-server ()
6749 ;; Make sure the connection to the server is alive.
6750 (unless (gnus-server-opened
6751 (gnus-find-method-for-group gnus-newsgroup-name))
6752 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6753 (gnus-request-group gnus-newsgroup-name t)))
6756 (autoload 'nneething-get-file-name "nneething"))
6758 (defun gnus-request-article-this-buffer (article group)
6759 "Get an article and insert it into this buffer."
6760 (let (do-update-line sparse-header)
6764 (gnus-kill-all-overlays)
6765 (setq group (or group gnus-newsgroup-name))
6767 ;; Using `gnus-request-article' directly will insert the article into
6768 ;; `nntp-server-buffer' - so we'll save some time by not having to
6769 ;; copy it from the server buffer into the article buffer.
6771 ;; We only request an article by message-id when we do not have the
6772 ;; headers for it, so we'll have to get those.
6773 (when (stringp article)
6774 (gnus-read-header article))
6776 ;; If the article number is negative, that means that this article
6777 ;; doesn't belong in this newsgroup (possibly), so we find its
6778 ;; message-id and request it by id instead of number.
6779 (when (and (numberp article)
6781 (get-buffer gnus-summary-buffer)
6782 (gnus-buffer-exists-p gnus-summary-buffer))
6783 (with-current-buffer gnus-summary-buffer
6784 (let ((header (gnus-summary-article-header article)))
6787 ((memq article gnus-newsgroup-sparse)
6788 ;; This is a sparse gap article.
6789 (setq do-update-line article)
6790 (setq article (mail-header-id header))
6791 (setq sparse-header (gnus-read-header article))
6792 (setq gnus-newsgroup-sparse
6793 (delq article gnus-newsgroup-sparse)))
6795 ;; It's a real article.
6796 (setq article (mail-header-id header)))
6798 ;; It is an extracted pseudo-article.
6799 (setq article 'pseudo)
6800 (gnus-request-pseudo-article header))))
6802 (let ((method (gnus-find-method-for-group
6803 gnus-newsgroup-name)))
6804 (when (and (eq (car method) 'nneething)
6806 (let ((dir (nneething-get-file-name
6807 (mail-header-id header))))
6808 (when (and (stringp dir)
6809 (file-directory-p dir))
6810 (setq article 'nneething)
6811 (gnus-group-enter-directory dir))))))))
6814 ;; Refuse to select canceled articles.
6815 ((and (numberp article)
6817 (get-buffer gnus-summary-buffer)
6818 (gnus-buffer-exists-p gnus-summary-buffer)
6819 (eq (cdr (with-current-buffer gnus-summary-buffer
6820 (assq article gnus-newsgroup-reads)))
6821 gnus-canceled-mark))
6823 ;; We first check `gnus-original-article-buffer'.
6824 ((and (get-buffer gnus-original-article-buffer)
6826 (with-current-buffer gnus-original-article-buffer
6827 (and (equal (car gnus-original-article) group)
6828 (eq (cdr gnus-original-article) article))))
6829 ;; `insert-buffer-substring' would incorrectly use the
6830 ;; equivalent of string-make-multibyte which amount to decoding
6831 ;; with locale-coding-system, causing failure of
6832 ;; subsequent decoding.
6833 (insert (mm-string-to-multibyte
6834 (with-current-buffer gnus-original-article-buffer
6835 (buffer-substring (point-min) (point-max)))))
6837 ;; Check the backlog.
6838 ((and gnus-keep-backlog
6839 (gnus-backlog-request-article group article (current-buffer)))
6841 ;; Check asynchronous pre-fetch.
6842 ((gnus-async-request-fetched-article group article (current-buffer))
6843 (gnus-async-prefetch-next group article gnus-summary-buffer)
6844 (when (and (numberp article) gnus-keep-backlog)
6845 (gnus-backlog-enter-article group article (current-buffer)))
6848 ((and gnus-use-cache
6850 (gnus-cache-request-article article group))
6852 ;; Check the agent cache.
6853 ((gnus-agent-request-article article group)
6855 ;; Get the article and put into the article buffer.
6856 ((or (stringp article)
6858 (let ((gnus-override-method gnus-override-method)
6859 (methods (and (stringp article)
6860 (with-current-buffer gnus-summary-buffer
6861 (gnus-refer-article-methods))))
6862 (backend (car (gnus-find-method-for-group
6863 gnus-newsgroup-name)))
6865 (inhibit-read-only t))
6866 (when (and (null gnus-override-method)
6868 (setq gnus-override-method (pop methods)))
6871 (gnus-kill-all-overlays)
6872 (let ((gnus-newsgroup-name group))
6873 (gnus-check-group-server))
6875 ((gnus-request-article article group (current-buffer))
6876 (when (numberp article)
6877 (gnus-async-prefetch-next group article
6878 gnus-summary-buffer)
6879 (when gnus-keep-backlog
6880 (gnus-backlog-enter-article
6881 group article (current-buffer)))
6882 (when (and gnus-agent
6883 (gnus-agent-group-covered-p group))
6884 (gnus-agent-store-article article group)))
6885 (setq result 'article))
6887 (setq gnus-override-method (pop methods)))
6888 ((not (string-match "^400 "
6889 (nnheader-get-report backend)))
6890 ;; If we get 400 server disconnect, reconnect and
6891 ;; retry; otherwise, assume the article has expired.
6892 (setq result 'done))))
6893 (and (eq result 'article) 'article)))
6897 ;; Associate this article with the current summary buffer.
6898 (setq gnus-article-current-summary gnus-summary-buffer)
6900 ;; Take the article from the original article buffer
6901 ;; and place it in the buffer it's supposed to be in.
6902 (when (and (get-buffer gnus-article-buffer)
6903 (equal (buffer-name (current-buffer))
6904 (buffer-name (get-buffer gnus-article-buffer))))
6906 (if (get-buffer gnus-original-article-buffer)
6907 (set-buffer gnus-original-article-buffer)
6908 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6909 (buffer-disable-undo)
6910 (setq major-mode 'gnus-original-article-mode)
6911 (setq buffer-read-only t))
6912 (let ((inhibit-read-only t))
6914 (insert-buffer-substring gnus-article-buffer))
6915 (setq gnus-original-article (cons group article)))
6918 (run-hooks 'gnus-article-decode-hook)
6919 ;; Mark article as decoded or not.
6920 (setq gnus-article-decoded-p gnus-article-decode-hook))
6922 ;; Update sparse articles.
6923 (when (and do-update-line
6924 (or (numberp article)
6926 (let ((buf (current-buffer)))
6927 (set-buffer gnus-summary-buffer)
6928 (gnus-summary-update-article do-update-line sparse-header)
6929 (gnus-summary-goto-subject do-update-line nil t)
6930 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6932 (set-buffer buf))))))
6934 (defun gnus-block-private-groups (group)
6935 (if (gnus-news-group-p group)
6936 ;; Block nothing in news groups.
6938 ;; Block everything anywhere else.
6941 (defun gnus-blocked-images ()
6942 (if (functionp gnus-blocked-images)
6943 (funcall gnus-blocked-images gnus-newsgroup-name)
6944 gnus-blocked-images))
6950 (defcustom gnus-article-edit-mode-hook nil
6951 "Hook run in article edit mode buffers."
6952 :group 'gnus-article-various
6955 (defvar gnus-article-edit-done-function nil)
6957 (defvar gnus-article-edit-mode-map nil)
6959 ;; Should we be using derived.el for this?
6960 (unless gnus-article-edit-mode-map
6961 (setq gnus-article-edit-mode-map (make-keymap))
6962 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6964 (gnus-define-keys gnus-article-edit-mode-map
6965 "\C-c?" describe-mode
6966 "\C-c\C-c" gnus-article-edit-done
6967 "\C-c\C-k" gnus-article-edit-exit
6968 "\C-c\C-f\C-t" message-goto-to
6969 "\C-c\C-f\C-o" message-goto-from
6970 "\C-c\C-f\C-b" message-goto-bcc
6971 ;;"\C-c\C-f\C-w" message-goto-fcc
6972 "\C-c\C-f\C-c" message-goto-cc
6973 "\C-c\C-f\C-s" message-goto-subject
6974 "\C-c\C-f\C-r" message-goto-reply-to
6975 "\C-c\C-f\C-n" message-goto-newsgroups
6976 "\C-c\C-f\C-d" message-goto-distribution
6977 "\C-c\C-f\C-f" message-goto-followup-to
6978 "\C-c\C-f\C-m" message-goto-mail-followup-to
6979 "\C-c\C-f\C-k" message-goto-keywords
6980 "\C-c\C-f\C-u" message-goto-summary
6981 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6982 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6983 "\C-c\C-b" message-goto-body
6984 "\C-c\C-i" message-goto-signature
6986 "\C-c\C-t" message-insert-to
6987 "\C-c\C-n" message-insert-newsgroups
6988 "\C-c\C-o" message-sort-headers
6989 "\C-c\C-e" message-elide-region
6990 "\C-c\C-v" message-delete-not-region
6991 "\C-c\C-z" message-kill-to-signature
6992 "\M-\r" message-newline-and-reformat
6993 "\C-c\C-a" mml-attach-file
6994 "\C-a" message-beginning-of-line
6996 "\M-;" comment-region)
6998 (gnus-define-keys (gnus-article-edit-wash-map
6999 "\C-c\C-w" gnus-article-edit-mode-map)
7000 "f" gnus-article-edit-full-stops))
7003 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7005 ["Fetch To" message-insert-to t]
7006 ["Fetch Newsgroups" message-insert-newsgroups t]
7008 ["To" message-goto-to t]
7009 ["From" message-goto-from t]
7010 ["Subject" message-goto-subject t]
7011 ["Cc" message-goto-cc t]
7012 ["Reply-To" message-goto-reply-to t]
7013 ["Summary" message-goto-summary t]
7014 ["Keywords" message-goto-keywords t]
7015 ["Newsgroups" message-goto-newsgroups t]
7016 ["Followup-To" message-goto-followup-to t]
7017 ["Mail-Followup-To" message-goto-mail-followup-to t]
7018 ["Distribution" message-goto-distribution t]
7019 ["Body" message-goto-body t]
7020 ["Signature" message-goto-signature t]))
7022 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7023 "Major mode for editing articles.
7024 This is an extended text-mode.
7026 \\{gnus-article-edit-mode-map}"
7027 (make-local-variable 'gnus-article-edit-done-function)
7028 (make-local-variable 'gnus-prev-winconf)
7029 (set (make-local-variable 'font-lock-defaults)
7030 '(message-font-lock-keywords t))
7031 (set (make-local-variable 'mail-header-separator) "")
7032 (set (make-local-variable 'gnus-article-edit-mode) t)
7033 (easy-menu-add message-mode-field-menu message-mode-map)
7035 (setq buffer-read-only nil)
7036 (buffer-enable-undo)
7039 (defun gnus-article-edit (&optional force)
7040 "Edit the current article.
7041 This will have permanent effect only in mail groups.
7042 If FORCE is non-nil, allow editing of articles even in read-only
7045 (when (and (not force)
7046 (gnus-group-read-only-p))
7047 (error "The current newsgroup does not support article editing"))
7048 (gnus-article-date-original)
7049 (gnus-article-edit-article
7051 `(lambda (no-highlight)
7053 (gnus-summary-edit-article-done
7054 ,(or (mail-header-references gnus-current-headers) "")
7055 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7057 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7058 "Start editing the contents of the current article buffer."
7059 (let ((winconf (current-window-configuration)))
7060 (set-buffer gnus-article-buffer)
7061 (let ((message-auto-save-directory
7062 ;; Don't associate the article buffer with a draft file.
7064 (gnus-article-edit-mode))
7065 (funcall start-func)
7066 (set-buffer-modified-p nil)
7067 (gnus-configure-windows 'edit-article)
7068 (setq gnus-article-edit-done-function exit-func)
7069 (setq gnus-prev-winconf winconf)
7071 (gnus-message 6 "C-c C-c to end edits"))))
7073 (defun gnus-article-edit-done (&optional arg)
7074 "Update the article edits and exit."
7076 (let ((func gnus-article-edit-done-function)
7077 (buf (current-buffer))
7078 (start (window-start))
7080 (winconf gnus-prev-winconf))
7081 (widen) ;; Widen it in case that users narrowed the buffer.
7084 ;; The cache and backlog have to be flushed somewhat.
7085 (when gnus-keep-backlog
7086 (gnus-backlog-remove-article
7087 (car gnus-article-current) (cdr gnus-article-current)))
7088 ;; Flush original article as well.
7089 (gnus-flush-original-article-buffer)
7090 (when gnus-use-cache
7091 (gnus-cache-update-article
7092 (car gnus-article-current) (cdr gnus-article-current)))
7093 ;; We remove all text props from the article buffer.
7094 (kill-all-local-variables)
7095 (set-text-properties (point-min) (point-max) nil)
7097 (set-window-configuration winconf)
7099 (set-window-start (get-buffer-window buf) start)
7100 (set-window-point (get-buffer-window buf) (point)))
7101 (gnus-summary-show-article))
7103 (defun gnus-flush-original-article-buffer ()
7104 (when (get-buffer gnus-original-article-buffer)
7105 (with-current-buffer gnus-original-article-buffer
7106 (setq gnus-original-article nil))))
7108 (defun gnus-article-edit-exit ()
7109 "Exit the article editing without updating."
7111 (when (or (not (buffer-modified-p))
7112 (yes-or-no-p "Article modified; kill anyway? "))
7113 (let ((curbuf (current-buffer))
7115 (window-start (window-start)))
7117 (if (gnus-buffer-live-p gnus-original-article-buffer)
7118 (insert-buffer-substring gnus-original-article-buffer))
7119 (let ((winconf gnus-prev-winconf))
7120 (kill-all-local-variables)
7122 (set-window-configuration winconf)
7123 ;; Tippy-toe some to make sure that point remains where it was.
7124 (save-current-buffer
7126 (set-window-start (get-buffer-window (current-buffer)) window-start)
7128 (gnus-summary-show-article)))
7130 (defun gnus-article-edit-full-stops ()
7131 "Interactively repair spacing at end of sentences."
7134 (goto-char (point-min))
7135 (search-forward-regexp "^$" nil t)
7136 (let ((case-fold-search nil))
7137 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7140 ;;; Article highlights
7143 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7145 ;;; Internal Variables:
7147 (defcustom gnus-button-url-regexp
7149 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7150 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7151 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7152 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7153 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7157 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7158 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7159 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7161 "[" chars punct "]+" "[" chars "]"
7163 (concat ;; XEmacs 21.4 doesn't support POSIX.
7164 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7165 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7167 "Regular expression that matches URLs."
7168 :group 'gnus-article-buttons
7171 (defcustom gnus-button-valid-fqdn-regexp
7172 message-valid-fqdn-regexp
7173 "Regular expression that matches a valid FQDN."
7175 :group 'gnus-article-buttons
7178 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7179 (defcustom gnus-button-valid-localpart-regexp
7180 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7181 "Regular expression that matches a localpart of mail addresses or MIDs."
7183 :group 'gnus-article-buttons
7186 (defcustom gnus-button-man-handler 'manual-entry
7187 "Function to use for displaying man pages.
7188 The function must take at least one argument with a string naming the
7191 :type '(choice (function-item :tag "Man" manual-entry)
7192 (function-item :tag "Woman" woman)
7193 (function :tag "Other"))
7194 :group 'gnus-article-buttons)
7196 (defcustom gnus-button-mid-or-mail-regexp
7197 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7198 gnus-button-valid-fqdn-regexp
7200 "Regular expression that matches a message ID or a mail address."
7202 :group 'gnus-article-buttons
7205 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7206 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7207 Strings like this can be either a message ID or a mail address. If it is one
7208 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7209 message ID or a mail address, respectively. If this variable is set to the
7210 symbol `ask', always query the user what do do. If it is a function, this
7211 function will be called with the string as its only argument. The function
7212 must return `mid', `mail', `invalid' or `ask'."
7214 :group 'gnus-article-buttons
7215 :type '(choice (function-item :tag "Heuristic function"
7216 gnus-button-mid-or-mail-heuristic)
7221 (defcustom gnus-button-mid-or-mail-heuristic-alist
7222 '((-10.0 . ".+\\$.+@")
7225 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7226 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7227 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7228 (-1.0 . "^[^a-z]+@")
7230 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7231 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7232 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7233 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7236 (-1.0 . "^[0-9][0-9]")
7238 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7239 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7240 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7241 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7243 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7244 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7247 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7249 ;; compensation for TDMA dated mail addresses:
7250 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7252 (-20.0 . "\\.fsf@") ;; Gnus
7255 (-20.0 . "^alpine\\.")
7256 (-20.0 . "_-_") ;; Subject change in thread
7258 (-20.0 . "\\.ln@") ;; leafnode
7259 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7260 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7262 ;; (5.0 . "") ;; $local_part_len <= 7
7263 (10.0 . "^[^0-9]+@")
7264 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7265 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7268 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7270 (0.5 . "^[A-Z][a-z]")
7271 (0.5 . "^[A-Z][a-z][a-z]")
7272 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7273 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7274 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7276 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7277 address. The REGEXP is processed with `case-fold-search' set to nil."
7279 :group 'gnus-article-buttons
7280 :type '(repeat (cons (number :tag "Rate")
7281 (regexp :tag "Regexp"))))
7283 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7284 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7285 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7286 address, `ask' if unsure and `invalid' if the string is invalid."
7287 (let ((case-fold-search nil)
7288 (list gnus-button-mid-or-mail-heuristic-alist)
7289 (result 0) rate regexp lpartlen elem)
7291 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7292 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7293 ;; Certain special cases...
7296 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7297 "^[0-9]+\\.[0-9]+@compuserve\\|"
7298 "@public\\.gmane\\.org")
7300 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7301 (setq result 'mail))
7302 (when (string-match "@.*@\\| " mid-or-mail)
7303 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7304 (setq result 'invalid))
7305 ;; Nothing more to do, if result is not a number here...
7306 (when (numberp result)
7308 (setq elem (car list)
7312 (when (string-match regexp mid-or-mail)
7313 (setq result (+ result rate))
7315 9 "`%s' matched `%s', rate `%s', result `%s'."
7316 mid-or-mail regexp rate result)))
7317 (when (<= lpartlen 7)
7318 (setq result (+ result 5.0))
7319 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7320 mid-or-mail result))
7321 (when (>= lpartlen 12)
7322 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7324 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7325 ;; Long local part should contain realname if e-mail address,
7326 ;; too many digits: message-id.
7327 ;; $score -= 5.0 + 0.1 * $local_part_len;
7328 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7329 (setq result (+ result rate))
7331 9 "Many digits in `%s', rate `%s', result `%s'."
7332 mid-or-mail rate result))
7333 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7335 ;; Too few vowels [^aeiouy]{4,}.*\@
7336 (setq result (+ result -5.0))
7338 9 "Few vowels in `%s', rate `%s', result `%s'."
7339 mid-or-mail -5.0 result))
7341 (setq result (+ result 5.0))
7343 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7344 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7345 ;; Maybe we should make this a customizable alist: (condition . 'result)
7347 ((symbolp result) result)
7348 ;; Now convert number into proper results:
7349 ((< result -10.0) 'mid)
7350 ((> result 10.0) 'mail)
7353 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7354 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7355 (url-mid (concat "news" ":" mid-or-mail))
7356 (url-mailto (concat "mailto" ":" mid-or-mail)))
7357 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7358 (when (fboundp pref)
7360 ;; get rid of surrounding angles...
7362 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7363 (if (or (eq 'mid guessed) (eq 'mail guessed))
7367 (save-window-excursion
7368 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7371 (cond ((eq pref 'mid)
7372 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7373 (gnus-button-handle-news url-mid))
7375 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7376 (gnus-url-mailto url-mailto))
7377 (t (gnus-message 3 "Invalid string.")))))
7379 (defun gnus-button-handle-custom (fun arg)
7380 "Call function FUN on argument ARG.
7381 Both FUN and ARG are supposed to be strings. ARG will be passed
7382 as a symbol to FUN."
7383 (funcall (intern fun)
7384 (if (string-match "^customize-apropos" fun)
7388 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7390 (defun gnus-button-handle-describe-function (url)
7391 "Call `describe-function' when pushing the corresponding URL button."
7394 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7396 (defun gnus-button-handle-describe-variable (url)
7397 "Call `describe-variable' when pushing the corresponding URL button."
7400 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7402 (defun gnus-button-handle-symbol (url)
7403 "Display help on variable or function.
7404 Calls `describe-variable' or `describe-function'."
7405 (let ((sym (intern url)))
7407 ((fboundp sym) (describe-function sym))
7408 ((boundp sym) (describe-variable sym))
7409 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7411 (defun gnus-button-handle-describe-key (url)
7412 "Call `describe-key' when pushing the corresponding URL button."
7414 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7415 (keys (ignore-errors (eval `(kbd ,key-string)))))
7418 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7420 (defun gnus-button-handle-apropos (url)
7421 "Call `apropos' when pushing the corresponding URL button."
7422 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7424 (defun gnus-button-handle-apropos-command (url)
7425 "Call `apropos' when pushing the corresponding URL button."
7427 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7429 (defun gnus-button-handle-apropos-variable (url)
7430 "Call `apropos' when pushing the corresponding URL button."
7432 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7433 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7435 (defun gnus-button-handle-apropos-documentation (url)
7436 "Call `apropos' when pushing the corresponding URL button."
7438 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7439 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7441 (defun gnus-button-handle-library (url)
7442 "Call `locate-library' when pushing the corresponding URL button."
7443 (gnus-message 9 "url=`%s'" url)
7444 (let* ((lib (locate-library url))
7445 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7447 (gnus-message 1 "Cannot locale library `%s'." url)
7448 (find-file-read-only file))))
7450 (defcustom gnus-button-man-level 5
7451 "*Integer that says how many man-related buttons Gnus will show.
7452 The higher the number, the more buttons will appear and the more false
7453 positives are possible. Note that you can set this variable local to
7454 specific groups. Setting it higher in Unix groups is probably a good idea.
7455 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7456 how to set variables in specific groups."
7458 :group 'gnus-article-buttons
7459 :link '(custom-manual "(gnus)Group Parameters")
7462 (defcustom gnus-button-emacs-level 5
7463 "*Integer that says how many emacs-related buttons Gnus will show.
7464 The higher the number, the more buttons will appear and the more false
7465 positives are possible. Note that you can set this variable local to
7466 specific groups. Setting it higher in Emacs or Gnus related groups is
7467 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7468 `gnus-parameters' on how to set variables in specific groups."
7470 :group 'gnus-article-buttons
7471 :link '(custom-manual "(gnus)Group Parameters")
7474 (defcustom gnus-button-message-level 5
7475 "*Integer that says how many buttons for news or mail messages will appear.
7476 The higher the number, the more buttons will appear and the more false
7477 positives are possible."
7478 ;; mail addresses, MIDs, URLs for news, ...
7480 :group 'gnus-article-buttons
7483 (defcustom gnus-button-browse-level 5
7484 "*Integer that says how many buttons for browsing will appear.
7485 The higher the number, the more buttons will appear and the more false
7486 positives are possible."
7487 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7489 :group 'gnus-article-buttons
7492 (defcustom gnus-button-alist
7493 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7494 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7495 ((concat "\\b\\(nntp\\|news\\):\\("
7496 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7497 0 t gnus-button-handle-news 2)
7498 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7499 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7500 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7501 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7502 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7503 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7504 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7505 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7506 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7507 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7508 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7509 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7510 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7511 ;; RFC 2368 (The mailto URL scheme)
7512 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7513 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7514 ("\\bmailto:\\([^ \n\t]+\\)"
7515 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7516 ;; Info Konqueror style <info:/foo/bar baz>.
7517 ;; Must come before " Gnus home-grown style".
7518 ("\\binfo://?\\([^'\">\n\t]+\\)"
7519 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7520 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7521 ("\\binfo://\\([^'\">\n\t ]+\\)"
7522 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7523 ;; Info GNOME style <info:foo#bar_baz>
7524 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7525 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7526 ;; Info KDE style <info:(foo)bar baz>
7527 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7528 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7529 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7530 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7531 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
7532 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7533 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7535 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7536 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7537 ;; Emacs help commands
7538 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7539 ;; regexp doesn't match arguments containing ` '.
7540 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7541 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7542 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7543 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7544 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7545 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7546 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7547 ;; The following entries may lead to many false positives so don't enable
7548 ;; them by default (use a high button level).
7549 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7550 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7551 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7552 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7553 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7554 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7555 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7556 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7557 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7558 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7559 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7560 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7561 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7562 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7563 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7564 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7565 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7566 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7567 ;; Unlike the other regexps we really have to require quoting
7568 ;; here to determine where it ends.
7569 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7570 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7571 ("<URL: *\\([^\n<>]*\\)>"
7572 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7573 ;; RFC 2396 (2.4.3., delims) ...
7574 ("\"URL: *\\([^\n\"]*\\)\""
7575 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7577 (gnus-button-url-regexp
7578 0 (>= gnus-button-browse-level 0) browse-url 0)
7580 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7581 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7582 gnus-button-handle-man 1)
7583 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7584 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7585 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7586 gnus-button-handle-man 1)
7587 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7588 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7589 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7590 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7591 ;; Recognizing patches to .el files. This is somewhat obscure,
7592 ;; but considering the percentage of Gnus users who hack Emacs
7594 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7595 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7596 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7597 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7598 ;; MID or mail: To avoid too many false positives we don't try to catch
7599 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7600 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7601 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7602 ;; so that non-ambiguous entries (see above) match first.
7603 (gnus-button-mid-or-mail-regexp
7604 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7605 "*Alist of regexps matching buttons in article bodies.
7607 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7608 REGEXP: is the string (case insensitive) matching text around the button (can
7609 also be Lisp expression evaluating to a string),
7610 BUTTON: is the number of the regexp grouping actually matching the button,
7611 FORM: is a Lisp expression which must eval to true for the button to
7613 CALLBACK: is the function to call when the user push this button, and each
7614 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7616 CALLBACK can also be a variable, in that case the value of that
7617 variable it the real callback function."
7618 :group 'gnus-article-buttons
7619 :type '(repeat (list (choice regexp variable sexp)
7620 (integer :tag "Button")
7622 (function :tag "Callback")
7625 (integer :tag "Regexp group")))))
7626 (put 'gnus-button-alist 'risky-local-variable t)
7628 (defcustom gnus-header-button-alist
7629 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7630 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7631 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7632 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7633 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7634 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7635 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7636 0 (>= gnus-button-browse-level 0) browse-url 0)
7637 ("^Subject:" gnus-button-url-regexp
7638 0 (>= gnus-button-browse-level 0) browse-url 0)
7639 ("^[^:]+:" gnus-button-url-regexp
7640 0 (>= gnus-button-browse-level 0) browse-url 0)
7641 ("^OpenPGP:.*url=" gnus-button-url-regexp
7642 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7643 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7644 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7645 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7646 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7647 "*Alist of headers and regexps to match buttons in article heads.
7649 This alist is very similar to `gnus-button-alist', except that each
7650 alist has an additional HEADER element first in each entry:
7652 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7654 HEADER is a regexp to match a header. For a fuller explanation, see
7655 `gnus-button-alist'."
7656 :group 'gnus-article-buttons
7657 :group 'gnus-article-headers
7658 :type '(repeat (list (regexp :tag "Header")
7659 (choice regexp variable)
7660 (integer :tag "Button")
7662 (function :tag "Callback")
7665 (integer :tag "Regexp group")))))
7666 (put 'gnus-header-button-alist 'risky-local-variable t)
7670 (defun gnus-article-push-button (event)
7671 "Check text under the mouse pointer for a callback function.
7672 If the text under the mouse pointer has a `gnus-callback' property,
7673 call it with the value of the `gnus-data' text property."
7675 (set-buffer (window-buffer (posn-window (event-start event))))
7676 (let* ((pos (posn-point (event-start event)))
7677 (data (get-text-property pos 'gnus-data))
7678 (fun (get-text-property pos 'gnus-callback)))
7681 (funcall fun data))))
7683 (defun gnus-article-press-button ()
7684 "Check text at point for a callback function.
7685 If the text at point has a `gnus-callback' property,
7686 call it with the value of the `gnus-data' text property."
7688 (let ((data (get-text-property (point) 'gnus-data))
7689 (fun (get-text-property (point) 'gnus-callback)))
7691 (funcall fun data))))
7693 (defun gnus-article-highlight (&optional force)
7694 "Highlight current article.
7695 This function calls `gnus-article-highlight-headers',
7696 `gnus-article-highlight-citation',
7697 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7698 do the highlighting. See the documentation for those functions."
7699 (interactive (list 'force))
7700 (gnus-article-highlight-headers)
7701 (gnus-article-highlight-citation force)
7702 (gnus-article-highlight-signature)
7703 (gnus-article-add-buttons)
7704 (gnus-article-add-buttons-to-head))
7706 (defun gnus-article-highlight-some (&optional force)
7707 "Highlight current article.
7708 This function calls `gnus-article-highlight-headers',
7709 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7710 do the highlighting. See the documentation for those functions."
7711 (interactive (list 'force))
7712 (gnus-article-highlight-headers)
7713 (gnus-article-highlight-signature)
7714 (gnus-article-add-buttons))
7716 (defun gnus-article-highlight-headers ()
7717 "Highlight article headers as specified by `gnus-header-face-alist'."
7719 (gnus-with-article-headers
7720 (let (regexp header-face field-face from hpoints fpoints)
7721 (dolist (entry gnus-header-face-alist)
7722 (goto-char (point-min))
7723 (setq regexp (concat "^\\("
7724 (if (string-equal "" (nth 0 entry))
7728 header-face (nth 1 entry)
7729 field-face (nth 2 entry))
7730 (while (and (re-search-forward regexp nil t)
7734 (unless (search-forward ":" nil t)
7736 (when (and header-face
7737 (not (memq (point) hpoints)))
7738 (push (point) hpoints)
7739 (gnus-put-text-property from (point) 'face header-face))
7740 (when (and field-face
7741 (not (memq (setq from (point)) fpoints)))
7743 (if (re-search-forward "^[^ \t]" nil t)
7745 (goto-char (point-max)))
7746 (gnus-put-text-property from (point) 'face field-face)))))))
7748 (defun gnus-article-highlight-signature ()
7749 "Highlight the signature in an article.
7750 It does this by highlighting everything after
7751 `gnus-signature-separator' using the face `gnus-signature'."
7753 (gnus-with-article-buffer
7754 (let ((inhibit-point-motion-hooks t))
7756 (when (and gnus-signature-face
7757 (gnus-article-narrow-to-signature))
7758 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7759 'face gnus-signature-face)
7761 (gnus-article-search-signature)
7762 (let ((start (match-beginning 0))
7763 (end (set-marker (make-marker) (1+ (match-end 0)))))
7764 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7767 (defun gnus-button-in-region-p (b e prop)
7768 "Say whether PROP exists in the region."
7769 (text-property-not-all b e prop nil))
7771 (defun gnus-article-add-buttons ()
7772 "Find external references in the article and make buttons of them.
7773 \"External references\" are things like Message-IDs and URLs, as
7774 specified by `gnus-button-alist'."
7776 (gnus-with-article-buffer
7777 (let ((inhibit-point-motion-hooks t)
7778 (case-fold-search t)
7779 (alist gnus-button-alist)
7781 ;; We skip the headers.
7784 (while (setq entry (pop alist))
7785 (setq regexp (eval (car entry)))
7787 (while (re-search-forward regexp nil t)
7788 (let ((start (match-beginning (nth 1 entry)))
7789 (end (match-end (nth 1 entry)))
7790 (from (match-beginning 0)))
7791 (when (and (eval (nth 2 entry))
7792 (not (gnus-button-in-region-p
7793 start end 'gnus-callback)))
7794 ;; That optional form returned non-nil, so we add the
7796 (setq from (set-marker (make-marker) from))
7797 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7798 (gnus-article-extend-url-button from start end))
7799 (gnus-article-add-button start end
7800 'gnus-button-push (list from entry))
7801 (gnus-put-text-property
7803 'gnus-string (buffer-substring-no-properties
7806 (defun gnus-article-extend-url-button (beg start end)
7807 "Extend url button if url is folded into two or more lines.
7808 Return non-nil if button is extended. BEG is a marker that points to
7809 the beginning position of a text containing url. START and END are
7810 the endpoints of a url button before it is extended. The concatenated
7811 url is put as the `gnus-button-url' overlay property on the button."
7812 (let ((opoint (point))
7813 (points (list start end))
7818 (not (looking-at "[\t ]*[\">]")))
7822 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7823 (buffer-substring (point-at-bol) start)))
7825 (setq url (list (buffer-substring start end))
7826 delim (if (match-beginning 1) ">" "\""))
7828 (setq regexp (concat
7829 (when (and (looking-at
7830 message-cite-prefix-regexp)
7831 (< (match-end 0) start))
7832 (regexp-quote (match-string 0)))
7834 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7838 (and (looking-at regexp)
7841 (push (or (match-string 2)
7844 (push (setq end (or (match-end 2)
7847 (push (or (match-beginning 2)
7848 (match-beginning 1))
7850 (match-beginning 2)))
7851 (let (gnus-article-mouse-face widget-mouse-face)
7853 (gnus-article-add-button (pop points) (pop points)
7854 'gnus-button-push beg)))
7855 (let ((overlay (gnus-make-overlay start end)))
7856 (gnus-overlay-put overlay 'evaporate t)
7857 (gnus-overlay-put overlay 'gnus-button-url
7858 (list (mapconcat 'identity (nreverse url) "")))
7859 (when gnus-article-mouse-face
7860 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7862 (goto-char opoint))))
7864 ;; Add buttons to the head of an article.
7865 (defun gnus-article-add-buttons-to-head ()
7866 "Add buttons to the head of the article."
7868 (gnus-with-article-headers
7870 (dolist (entry gnus-header-button-alist)
7871 ;; Each alist entry.
7872 (goto-char (point-min))
7873 (while (re-search-forward (car entry) nil t)
7874 ;; Each header matching the entry.
7875 (setq beg (match-beginning 0))
7876 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7877 (match-beginning 0))
7880 (while (re-search-forward (eval (nth 1 entry)) end t)
7881 ;; Each match within a header.
7882 (let* ((entry (cdr entry))
7883 (start (match-beginning (nth 1 entry)))
7884 (end (match-end (nth 1 entry)))
7885 (form (nth 2 entry)))
7886 (goto-char (match-end 0))
7888 (gnus-article-add-button
7889 start end (nth 3 entry)
7890 (buffer-substring (match-beginning (nth 4 entry))
7891 (match-end (nth 4 entry)))))))
7892 (goto-char end))))))
7894 ;;; External functions:
7896 (defun gnus-article-add-button (from to fun &optional data text)
7897 "Create a button between FROM and TO with callback FUN and data DATA."
7898 (when gnus-article-button-face
7899 (gnus-overlay-put (gnus-make-overlay from to nil t)
7900 'face gnus-article-button-face))
7901 (gnus-add-text-properties
7903 (nconc (and gnus-article-mouse-face
7904 (list gnus-mouse-face-prop gnus-article-mouse-face))
7905 (list 'gnus-callback fun)
7906 (and data (list 'gnus-data data))))
7907 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7908 :help-echo (or text "Follow the link")
7909 :keymap gnus-url-button-map
7910 :button-keymap gnus-widget-button-keymap))
7912 (defun gnus-article-copy-string ()
7913 "Copy the string in the button to the kill ring."
7915 (gnus-article-check-buffer)
7916 (let ((data (get-text-property (point) 'gnus-string)))
7920 (copy-region-as-kill (point-min) (point-max))
7921 (message "Copied %s" data)))))
7923 ;;; Internal functions:
7925 (defun gnus-article-set-globals ()
7926 (with-current-buffer gnus-summary-buffer
7927 (gnus-set-global-variables)))
7929 (defun gnus-signature-toggle (end)
7930 (gnus-with-article-buffer
7931 (let ((inhibit-point-motion-hooks t))
7932 (if (text-property-any end (point-max) 'article-type 'signature)
7934 (gnus-delete-wash-type 'signature)
7935 (gnus-remove-text-properties-when
7936 'article-type 'signature end (point-max)
7937 (cons 'article-type (cons 'signature
7938 gnus-hidden-properties))))
7939 (gnus-add-wash-type 'signature)
7940 (gnus-add-text-properties-when
7941 'article-type nil end (point-max)
7942 (cons 'article-type (cons 'signature
7943 gnus-hidden-properties)))))
7944 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7945 (gnus-set-mode-line 'article))))
7947 (defun gnus-button-push (marker-and-entry)
7948 ;; Push button starting at MARKER.
7950 (let* ((marker (car marker-and-entry))
7951 (entry (cadr marker-and-entry))
7952 (regexp (car entry))
7953 (inhibit-point-motion-hooks t))
7955 ;; This is obviously true, or something bad is happening :)
7956 ;; But we need it to have the match-data
7957 (when (looking-at (or (if (symbolp regexp)
7958 (symbol-value regexp)
7960 (let ((fun (nth 3 entry))
7961 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7962 (get-char-property marker 'gnus-button-url))
7963 (mapcar (lambda (group)
7964 (let ((string (match-string group)))
7965 (set-text-properties
7966 0 (length string) nil string)
7968 (nthcdr 4 entry)))))
7974 (fboundp (symbol-value fun)))
7975 (apply (symbol-value fun) args))
7977 (gnus-message 1 "You must define `%S' to use this button"
7978 (cons fun args)))))))))
7980 (defun gnus-parse-news-url (url)
7981 (let (scheme server port group message-id articles)
7984 (goto-char (point-min))
7985 (when (looking-at "\\([A-Za-z]+\\):")
7986 (setq scheme (match-string 1))
7987 (goto-char (match-end 0)))
7988 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7989 (setq server (match-string 1))
7990 (setq port (if (stringp (match-string 3))
7991 (string-to-number (match-string 3))
7993 (goto-char (match-end 0)))
7996 ((looking-at "\\(.*@.*\\)")
7997 (setq message-id (match-string 1)))
7998 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7999 (setq group (match-string 1)
8000 articles (split-string (match-string 2) "-")))
8001 ((looking-at "\\([^/]+\\)/?")
8002 (setq group (match-string 1)))
8004 (error "Unknown news URL syntax"))))
8005 (list scheme server port group message-id articles)))
8007 (defun gnus-button-handle-news (url)
8009 (destructuring-bind (scheme server port group message-id articles)
8010 (gnus-parse-news-url url)
8013 (with-current-buffer gnus-summary-buffer
8015 (let ((gnus-refer-article-method
8016 (nconc (list (list 'nntp server))
8017 gnus-refer-article-method))
8018 (nntp-port-number (or port "nntp")))
8019 (gnus-message 7 "Fetching %s with %s"
8020 message-id gnus-refer-article-method)
8021 (gnus-summary-refer-article message-id))
8022 (gnus-summary-refer-article message-id))))
8024 (gnus-button-fetch-group url)))))
8026 (defun gnus-button-patch (library line)
8027 "Visit an Emacs Lisp library LIBRARY on line LINE."
8029 (let ((file (locate-library (file-name-nondirectory library))))
8031 (error "Couldn't find library %s" library))
8033 (goto-char (point-min))
8034 (forward-line (1- (string-to-number line)))))
8036 (defun gnus-button-handle-man (url)
8038 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8039 (when (eq gnus-button-man-handler 'woman)
8040 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8041 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8042 (funcall gnus-button-man-handler url))
8044 (defun gnus-button-handle-info-url (url)
8045 "Fetch an info URL."
8046 (setq url (mm-subst-char-in-string ?+ ?\ url))
8048 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8049 (gnus-info-find-node
8050 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8052 ")" (gnus-url-unhex-string (match-string 2 url)))))
8053 ((string-match "([^)\"]+)[^\"]+" url)
8055 (gnus-replace-in-string
8056 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8057 (gnus-info-find-node url))
8058 (t (error "Can't parse %s" url))))
8060 (defun gnus-button-handle-info-url-gnome (url)
8061 "Fetch GNOME style info URL."
8062 (setq url (mm-subst-char-in-string ?_ ?\ url))
8063 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8064 (gnus-info-find-node
8066 (gnus-url-unhex-string
8067 (match-string 1 url))
8069 (or (gnus-url-unhex-string
8070 (match-string 2 url))
8072 (error "Can't parse %s" url)))
8074 (defun gnus-button-handle-info-url-kde (url)
8075 "Fetch KDE style info URL."
8076 (gnus-info-find-node (gnus-url-unhex-string url)))
8078 ;; (info) will autoload info.el
8079 (declare-function Info-menu "info" (menu-item &optional fork))
8080 (declare-function Info-index-next "info" (num))
8082 (defun gnus-button-handle-info-keystrokes (url)
8083 "Call `info' when pushing the corresponding URL button."
8084 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8085 (let (node indx comma)
8087 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8088 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8089 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8090 "\\(?:[ \t\n,]*\\)\\)?")
8092 (setq node (match-string 2 url)
8093 indx (match-string 3 url))
8094 (error "Can't parse %s" url))
8098 (when (> (length indx) 0)
8099 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8102 (setq comma (match-string 2 indx))
8103 (setq indx (match-string 1 indx))
8106 (dotimes (i (with-temp-buffer
8108 ;; Note: the XEmacs version of `how-many' takes
8109 ;; no optional argument.
8110 (goto-char (point-min))
8112 (Info-index-next 1)))
8115 (autoload 'pgg-snarf-keys-region "pgg")
8116 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8117 (declare-function pgg-display-output-buffer "pgg" (start end status))
8119 (defun gnus-button-openpgp (url)
8120 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8122 (mm-url-insert-file-contents-external url)
8123 (pgg-snarf-keys-region (point-min) (point-max))
8124 (pgg-display-output-buffer nil nil nil)))
8126 (defun gnus-button-message-id (message-id)
8128 (with-current-buffer gnus-summary-buffer
8129 (gnus-summary-refer-article message-id)))
8131 (defun gnus-button-fetch-group (address &rest ignore)
8132 "Fetch GROUP specified by ADDRESS."
8133 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8135 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8136 ;; for nntp:// and news://
8137 (setq address (match-string 3 address)))
8138 (if (not (string-match "[:/]" address))
8139 ;; This is just a simple group url.
8140 (gnus-group-read-ephemeral-group address gnus-select-method)
8143 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8145 (error "Can't parse %s" address)
8146 (gnus-group-read-ephemeral-group
8147 (match-string 4 address)
8148 `(nntp ,(match-string 1 address)
8149 (nntp-address ,(match-string 1 address))
8150 (nntp-port-number ,(if (match-end 3)
8151 (match-string 3 address)
8154 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8156 (defun gnus-url-parse-query-string (query &optional downcase)
8157 (let (retval pairs cur key val)
8158 (setq pairs (split-string query "&"))
8160 (setq cur (car pairs)
8162 (if (not (string-match "=" cur))
8164 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8165 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8167 (setq key (downcase key)))
8168 (setq cur (assoc key retval))
8170 (setcdr cur (cons val (cdr cur)))
8171 (setq retval (cons (list key val) retval)))))
8174 (defun gnus-url-mailto (url)
8175 ;; Send mail to someone
8176 (setq url (replace-regexp-in-string "\n" " " url))
8177 (when (string-match "mailto:/*\\(.*\\)" url)
8178 (setq url (substring url (match-beginning 1) nil)))
8179 (let (to args subject func)
8180 (setq args (gnus-url-parse-query-string
8181 (if (string-match "^\\?" url)
8183 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8184 (concat "to=" (match-string 1 url) "&"
8185 (match-string 2 url))
8186 (concat "to=" url))))
8187 subject (cdr-safe (assoc "subject" args)))
8190 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8193 (message-position-on-field (caar args)))
8194 (insert (gnus-replace-in-string
8195 (mapconcat 'identity (reverse (cdar args)) ", ")
8197 (setq args (cdr args)))
8200 (message-goto-subject))))
8202 (defun gnus-button-embedded-url (address)
8203 "Activate ADDRESS with `browse-url'."
8204 (browse-url (gnus-strip-whitespace address)))
8206 ;;; Next/prev buttons in the article buffer.
8208 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8209 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8211 (defvar gnus-prev-page-map
8212 (let ((map (make-sparse-keymap)))
8213 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8214 (define-key map "\r" 'gnus-button-prev-page)
8217 (defvar gnus-next-page-map
8218 (let ((map (make-sparse-keymap)))
8219 (define-key map gnus-mouse-2 'gnus-button-next-page)
8220 (define-key map "\r" 'gnus-button-next-page)
8223 (defun gnus-insert-prev-page-button ()
8225 (inhibit-read-only t))
8227 gnus-prev-page-line-format nil
8228 `(keymap ,gnus-prev-page-map
8230 gnus-callback gnus-article-button-prev-page
8231 article-type annotation))
8233 ;; Exclude a newline.
8236 (when gnus-article-button-face
8237 (gnus-overlay-put (gnus-make-overlay b e nil t)
8238 'face gnus-article-button-face))
8239 (widget-convert-button
8241 :action 'gnus-button-prev-page
8242 :button-keymap gnus-prev-page-map)))
8244 (defun gnus-button-next-page (&optional args more-args)
8245 "Go to the next page."
8247 (let ((win (selected-window)))
8248 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8249 (gnus-article-next-page)
8250 (select-window win)))
8252 (defun gnus-button-prev-page (&optional args more-args)
8253 "Go to the prev page."
8255 (let ((win (selected-window)))
8256 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8257 (gnus-article-prev-page)
8258 (select-window win)))
8260 (defun gnus-insert-next-page-button ()
8262 (inhibit-read-only t))
8263 (gnus-eval-format gnus-next-page-line-format nil
8264 `(keymap ,gnus-next-page-map
8266 gnus-callback gnus-article-button-next-page
8267 article-type annotation))
8269 ;; Exclude a newline.
8272 (when gnus-article-button-face
8273 (gnus-overlay-put (gnus-make-overlay b e nil t)
8274 'face gnus-article-button-face))
8275 (widget-convert-button
8277 :action 'gnus-button-next-page
8278 :button-keymap gnus-next-page-map)))
8280 (defun gnus-article-button-next-page (arg)
8281 "Go to the next page."
8283 (let ((win (selected-window)))
8284 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8285 (gnus-article-next-page)
8286 (select-window win)))
8288 (defun gnus-article-button-prev-page (arg)
8289 "Go to the prev page."
8291 (let ((win (selected-window)))
8292 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8293 (gnus-article-prev-page)
8294 (select-window win)))
8296 (defvar gnus-decode-header-methods
8297 '(mail-decode-encoded-word-region)
8298 "List of methods used to decode headers.
8300 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8301 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8302 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8303 whose names match REGEXP.
8306 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8307 mail-decode-encoded-word-region
8308 (\"chinese\" . rfc1843-decode-region))
8311 (defvar gnus-decode-header-methods-cache nil)
8313 (defun gnus-multi-decode-header (start end)
8314 "Apply the functions from `gnus-encoded-word-methods' that match."
8315 (unless (and gnus-decode-header-methods-cache
8316 (eq gnus-newsgroup-name
8317 (car gnus-decode-header-methods-cache)))
8318 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8319 (dolist (x gnus-decode-header-methods)
8321 (nconc gnus-decode-header-methods-cache (list x))
8322 (if (and gnus-newsgroup-name
8323 (string-match (car x) gnus-newsgroup-name))
8324 (nconc gnus-decode-header-methods-cache
8326 (let ((xlist gnus-decode-header-methods-cache))
8329 (narrow-to-region start end)
8331 (funcall (pop xlist) (point-min) (point-max))))))
8334 ;;; Treatment top-level handling.
8337 (defvar gnus-inhibit-article-treatments nil)
8339 (defun gnus-treat-article (gnus-treat-condition
8340 &optional part-number total-parts gnus-treat-type)
8341 (let ((gnus-treat-length (- (point-max) (point-min)))
8342 (alist gnus-treatment-function-alist)
8343 (article-goto-body-goes-to-point-min-p t)
8345 (or (not gnus-treat-type)
8347 (let ((list gnus-article-treat-types))
8349 (when (string-match (pop list) gnus-treat-type)
8350 (throw 'found t)))))))
8351 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8353 (gnus-run-hooks 'gnus-part-display-hook)
8354 (dolist (elem alist)
8357 (when (gnus-buffer-live-p gnus-summary-buffer)
8358 (set-buffer gnus-summary-buffer))
8359 (symbol-value (car elem))))
8360 (when (and (or (consp val)
8362 (or (not gnus-inhibit-article-treatments)
8363 (eq gnus-treat-condition 'head))
8364 (gnus-treat-predicate val)
8365 (or (not (get (car elem) 'highlight))
8368 (funcall (cadr elem)))))))
8370 ;; Dynamic variables.
8371 (defvar part-number)
8372 (defvar total-parts)
8373 (defvar gnus-treat-type)
8374 (defvar gnus-treat-condition)
8375 (defvar gnus-treat-length)
8377 (defun gnus-treat-predicate (val)
8381 (gnus-treat-condition
8382 (eq gnus-treat-condition val))
8384 (stringp (car val)))
8385 (apply 'gnus-or (mapcar `(lambda (s)
8386 (string-match s ,(or gnus-newsgroup-name "")))
8389 (let ((pred (pop val)))
8392 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8394 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8396 (not (gnus-treat-predicate (car val))))
8398 (equal (car val) gnus-treat-type))
8400 (error "%S is not a valid predicate" pred)))))
8408 (eq part-number total-parts))
8410 (< gnus-treat-length val))
8412 (error "%S is not a valid value" val))))
8414 (defun gnus-article-encrypt-body (protocol &optional n)
8415 "Encrypt the article body."
8418 (or gnus-article-encrypt-protocol
8419 (gnus-completing-read "Encrypt protocol"
8420 (mapcar 'car gnus-article-encrypt-protocol-alist)
8422 current-prefix-arg))
8423 ;; User might hit `K E' instead of `K e', so prompt once.
8424 (when (and gnus-article-encrypt-protocol
8426 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8427 (error "Encrypt aborted")))
8428 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8430 (error "Can't find the encrypt protocol %s" protocol))
8431 (if (member gnus-newsgroup-name '("nndraft:delayed"
8434 (error "Can't encrypt the article in group %s"
8435 gnus-newsgroup-name))
8436 (gnus-summary-iterate n
8437 (with-current-buffer gnus-summary-buffer
8438 (let ((mail-parse-charset gnus-newsgroup-charset)
8439 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8440 (summary-buffer gnus-summary-buffer)
8442 (gnus-set-global-variables)
8443 (when (gnus-group-read-only-p)
8444 (error "The current newsgroup does not support article encrypt"))
8445 (gnus-summary-show-article t)
8447 (or (mail-header-references gnus-current-headers) ""))
8448 (set-buffer gnus-article-buffer)
8449 (let* ((inhibit-read-only t)
8451 (mapcar (lambda (field)
8452 (and (save-restriction
8453 (message-narrow-to-head)
8454 (goto-char (point-min))
8455 (search-forward field nil t))
8457 (message-narrow-to-field)
8459 (delete-region (point-min) (point-max))
8461 '("Content-Type:" "Content-Transfer-Encoding:"
8462 "Content-Disposition:"))))
8463 (message-narrow-to-head)
8464 (message-remove-header "MIME-Version")
8465 (goto-char (point-max))
8466 (setq point (point))
8467 (insert (apply 'concat headers))
8469 (narrow-to-region point (point-max))
8470 (let ((message-options message-options))
8471 (message-options-set 'message-sender user-mail-address)
8472 (message-options-set 'message-recipients user-mail-address)
8473 (message-options-set 'message-sign-encrypt 'not)
8475 (goto-char (point-min))
8476 (insert "MIME-Version: 1.0\n")
8478 (gnus-summary-edit-article-done
8479 references nil summary-buffer t))
8480 (when gnus-keep-backlog
8481 (gnus-backlog-remove-article
8482 (car gnus-article-current) (cdr gnus-article-current)))
8483 (gnus-flush-original-article-buffer)
8484 (when gnus-use-cache
8485 (gnus-cache-update-article
8486 (car gnus-article-current) (cdr gnus-article-current))))))))
8488 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8489 "The following specs can be used:
8490 %t The security MIME type
8493 %D Details if button is pressed")
8495 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8496 "The following specs can be used:
8497 %t The security MIME type
8500 %D Details if button is pressed")
8502 (defvar gnus-mime-security-button-line-format-alist
8503 '((?t gnus-tmp-type ?s)
8504 (?i gnus-tmp-info ?s)
8505 (?d gnus-tmp-details ?s)
8506 (?D gnus-tmp-pressed-details ?s)))
8508 (defvar gnus-mime-security-button-commands
8509 '((gnus-article-press-button "\r" "Show Detail")
8513 (gnus-mime-security-save-part "o" "Save...")
8522 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8525 (defvar gnus-mime-security-button-map
8526 (let ((map (make-sparse-keymap)))
8527 (define-key map gnus-mouse-2 'gnus-article-push-button)
8528 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8529 (dolist (c gnus-mime-security-button-commands)
8530 (define-key map (cadr c) (car c)))
8534 gnus-mime-security-button-menu gnus-mime-security-button-map
8535 "Security button menu."
8539 (unless (eq (car c) 'undefined)
8540 (vector (caddr c) (car c) :active t)))
8541 gnus-mime-security-button-commands))))
8543 (defun gnus-mime-security-button-menu (event prefix)
8544 "Construct a context-sensitive menu of security commands."
8545 (interactive "e\nP")
8546 (save-window-excursion
8547 (let ((pos (event-start event)))
8548 (select-window (posn-window pos))
8549 (goto-char (posn-point pos))
8550 (gnus-article-check-buffer)
8551 (popup-menu gnus-mime-security-button-menu nil prefix))))
8553 (defvar gnus-mime-security-details-buffer nil)
8555 (defvar gnus-mime-security-button-pressed nil)
8557 (defvar gnus-mime-security-show-details-inline t
8558 "If non-nil, show details in the article buffer.")
8560 (defun gnus-mime-security-verify-or-decrypt (handle)
8561 (mm-remove-parts (cdr handle))
8562 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8563 point (inhibit-read-only t))
8565 (goto-char (car region)))
8566 (setq point (point))
8567 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8568 (let* ((mm-verify-option 'known)
8569 (mm-decrypt-option 'known)
8570 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8571 (unless (eq nparts (cdr handle))
8572 (mm-destroy-parts (cdr handle))
8573 (setcdr handle nparts))))
8574 (gnus-mime-display-security handle)
8576 (delete-region (point) (cdr region))
8577 (set-marker (car region) nil)
8578 (set-marker (cdr region) nil))
8581 (defun gnus-mime-security-show-details (handle)
8582 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8584 (gnus-message 5 "No details.")
8585 (if gnus-mime-security-show-details-inline
8586 (let ((gnus-mime-security-button-pressed
8587 (not (get-text-property (point) 'gnus-mime-details)))
8588 (gnus-mime-security-button-line-format
8589 (get-text-property (point) 'gnus-line-format))
8590 (inhibit-read-only t))
8592 (while (eq (get-text-property (point) 'gnus-line-format)
8593 gnus-mime-security-button-line-format)
8597 (narrow-to-region (point) (point))
8598 (gnus-insert-mime-security-button handle))
8599 (delete-region (point)
8600 (or (text-property-not-all
8603 gnus-mime-security-button-line-format)
8606 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8607 (with-current-buffer gnus-mime-security-details-buffer
8610 (setq gnus-mime-security-details-buffer
8611 (gnus-get-buffer-create "*MIME Security Details*")))
8612 (with-current-buffer gnus-mime-security-details-buffer
8614 (goto-char (point-min)))
8615 (pop-to-buffer gnus-mime-security-details-buffer)))))
8617 (defun gnus-mime-security-press-button (handle)
8619 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8620 (gnus-mime-security-show-details handle)
8621 (gnus-mime-security-verify-or-decrypt handle))))
8623 (defun gnus-insert-mime-security-button (handle &optional displayed)
8624 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8627 (or (nth 2 (assoc protocol mm-verify-function-alist))
8628 (nth 2 (assoc protocol mm-decrypt-function-alist))
8630 (if (equal (car handle) "multipart/signed")
8631 " Signed" " Encrypted")
8634 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8637 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8638 gnus-tmp-pressed-details
8640 (setq gnus-tmp-details
8641 (if gnus-tmp-details
8642 (concat "\n" gnus-tmp-details)
8644 (setq gnus-tmp-pressed-details
8645 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8650 gnus-mime-security-button-line-format
8651 gnus-mime-security-button-line-format-alist
8652 `(keymap ,gnus-mime-security-button-map
8653 gnus-callback gnus-mime-security-press-button
8654 gnus-line-format ,gnus-mime-security-button-line-format
8655 gnus-mime-details ,gnus-mime-security-button-pressed
8656 article-type annotation
8659 ;; Exclude a newline.
8662 (when gnus-article-button-face
8663 (gnus-overlay-put (gnus-make-overlay b e nil t)
8664 'face gnus-article-button-face))
8665 (widget-convert-button
8668 :action 'gnus-widget-press-button
8669 :button-keymap gnus-mime-security-button-map
8672 ;; Needed to properly clear the message due to a bug in
8673 ;; wid-edit (XEmacs only).
8674 (when (boundp 'help-echo-owns-message)
8675 (setq help-echo-owns-message t))
8677 "%S: show detail; %S: more options"
8678 (aref gnus-mouse-2 0)
8679 (aref gnus-down-mouse-3 0))))))
8681 (defun gnus-mime-display-security (handle)
8683 (narrow-to-region (point) (point))
8684 (unless (gnus-unbuttonized-mime-type-p (car handle))
8685 (gnus-insert-mime-security-button handle))
8686 (gnus-mime-display-part (cadr handle))
8689 (unless (gnus-unbuttonized-mime-type-p (car handle))
8690 (let ((gnus-mime-security-button-line-format
8691 gnus-mime-security-button-end-line-format))
8692 (gnus-insert-mime-security-button handle)))
8693 (mm-set-handle-multipart-parameter
8695 (cons (set-marker (make-marker) (point-min))
8696 (set-marker (make-marker) (point-max))))
8697 (goto-char (point-max))))
8699 (defun gnus-mime-security-run-function (function)
8700 "Run FUNCTION with the security part under point."
8701 (gnus-article-check-buffer)
8702 (let ((data (get-text-property (point) 'gnus-data))
8704 (when (and (stringp (car-safe data))
8705 (setq buffer (mm-handle-multipart-original-buffer data))
8706 (setq handle (cadr data)))
8707 (if (bufferp (mm-handle-buffer handle))
8709 (setq handle (cons buffer (copy-sequence (cdr handle))))
8710 (mm-handle-set-undisplayer handle nil))
8711 (setq handle (mm-make-handle
8713 (mm-handle-multipart-ctl-parameter handle 'protocol)
8714 nil nil nil nil nil nil)))
8715 (funcall function handle))))
8717 (defun gnus-mime-security-save-part ()
8718 "Save the security part under point."
8720 (gnus-mime-security-run-function 'mm-save-part))
8722 (defun gnus-mime-security-pipe-part ()
8723 "Pipe the security part under point to a process."
8725 (gnus-mime-security-run-function 'mm-pipe-part))
8731 (run-hooks 'gnus-art-load-hook)
8733 ;;; gnus-art.el ends here