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)
50 (autoload 'gnus-msg-mail "gnus-msg" nil t)
51 (autoload 'gnus-button-mailto "gnus-msg")
52 (autoload 'gnus-button-reply "gnus-msg" nil t)
53 (autoload 'parse-time-string "parse-time" nil nil)
54 (autoload 'ansi-color-apply-on-region "ansi-color")
55 (autoload 'mm-url-insert-file-contents-external "mm-url")
56 (autoload 'mm-extern-cache-contents "mm-extern")
58 (defgroup gnus-article nil
60 :link '(custom-manual "(gnus)Article Buffer")
63 (defgroup gnus-article-treat nil
64 "Treating article parts."
65 :link '(custom-manual "(gnus)Article Hiding")
68 (defgroup gnus-article-hiding nil
69 "Hiding article parts."
70 :link '(custom-manual "(gnus)Article Hiding")
73 (defgroup gnus-article-highlight nil
74 "Article highlighting."
75 :link '(custom-manual "(gnus)Article Highlighting")
79 (defgroup gnus-article-signature nil
81 :link '(custom-manual "(gnus)Article Signature")
84 (defgroup gnus-article-headers nil
86 :link '(custom-manual "(gnus)Hiding Headers")
89 (defgroup gnus-article-washing nil
90 "Special commands on articles."
91 :link '(custom-manual "(gnus)Article Washing")
94 (defgroup gnus-article-emphasis nil
95 "Fontisizing articles."
96 :link '(custom-manual "(gnus)Article Fontisizing")
99 (defgroup gnus-article-saving nil
101 :link '(custom-manual "(gnus)Saving Articles")
102 :group 'gnus-article)
104 (defgroup gnus-article-mime nil
105 "Worshiping the MIME wonder."
106 :link '(custom-manual "(gnus)Using MIME")
107 :group 'gnus-article)
109 (defgroup gnus-article-buttons nil
110 "Pushable buttons in the article buffer."
111 :link '(custom-manual "(gnus)Article Buttons")
112 :group 'gnus-article)
114 (defgroup gnus-article-various nil
115 "Other article options."
116 :link '(custom-manual "(gnus)Misc Article")
117 :group 'gnus-article)
119 (defcustom gnus-ignored-headers
122 (concat "^" header ":"))
123 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
124 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
125 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
126 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
127 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
128 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
129 "X-Attribution" "X-Originating-IP" "Delivered-To"
130 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
131 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
132 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
133 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
134 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
135 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
136 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
137 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
138 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
139 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
140 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
141 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
142 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
143 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
144 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
145 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
146 "List-[A-Za-z]+" "X-Listprocessor-Version"
147 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
148 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
149 "X-Received" "Content-length" "X-precedence"
150 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
151 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
152 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
153 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
154 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
155 "X-Content-length" "X-Posting-Agent" "Original-Received"
156 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
157 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
158 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
159 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
160 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
161 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
162 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
163 "Envelope-Sender" "Envelope-Recipients"))
164 "*All headers that start with this regexp will be hidden.
165 This variable can also be a list of regexps of headers to be ignored.
166 If `gnus-visible-headers' is non-nil, this variable will be ignored."
167 :type '(choice regexp
169 :group 'gnus-article-hiding)
171 (defcustom gnus-visible-headers
172 "^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:"
173 "*All headers that do not match this regexp will be hidden.
174 This variable can also be a list of regexp of headers to remain visible.
175 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
177 (repeat :value-to-internal (lambda (widget value)
178 (custom-split-regexp-maybe value))
179 :match (lambda (widget value)
181 (widget-editable-list-match widget value)))
183 (const :tag "Use gnus-ignored-headers" nil)
185 :group 'gnus-article-hiding)
187 (defcustom gnus-sorted-header-list
188 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
189 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
190 "*This variable is a list of regular expressions.
191 If it is non-nil, headers that match the regular expressions will
192 be placed first in the article buffer in the sequence specified by
194 :type '(repeat regexp)
195 :group 'gnus-article-hiding)
197 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
198 "Headers that are only to be displayed if they have interesting data.
199 Possible values in this list are:
201 'empty Headers with no content.
202 'newsgroups Newsgroup identical to Gnus group.
203 'to-address To identical to To-address.
204 'to-list To identical to To-list.
205 'cc-list CC identical to To-list.
206 'followup-to Followup-to identical to Newsgroups.
207 'reply-to Reply-to identical to From.
208 'date Date less than four days old.
209 'long-to To and/or Cc longer than 1024 characters.
210 'many-to Multiple To and/or Cc."
211 :type '(set (const :tag "Headers with no content." empty)
212 (const :tag "Newsgroups identical to Gnus group." newsgroups)
213 (const :tag "To identical to To-address." to-address)
214 (const :tag "To identical to To-list." to-list)
215 (const :tag "CC identical to To-list." cc-list)
216 (const :tag "Followup-to identical to Newsgroups." followup-to)
217 (const :tag "Reply-to identical to From." reply-to)
218 (const :tag "Date less than four days old." date)
219 (const :tag "To and/or Cc longer than 1024 characters." long-to)
220 (const :tag "Multiple To and/or Cc headers." many-to))
221 :group 'gnus-article-hiding)
223 (defcustom gnus-article-skip-boring nil
224 "Skip over text that is not worth reading.
225 By default, if you set this t, then Gnus will display citations and
226 signatures, but will never scroll down to show you a page consisting
227 only of boring text. Boring text is controlled by
228 `gnus-article-boring-faces'."
231 :group 'gnus-article-hiding)
233 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
234 "Regexp matching signature separator.
235 This can also be a list of regexps. In that case, it will be checked
236 from head to tail looking for a separator. Searches will be done from
237 the end of the buffer."
238 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
240 (repeat :tag "List of regexp" regexp))
241 :group 'gnus-article-signature)
243 (defcustom gnus-signature-limit nil
244 "Provide a limit to what is considered a signature.
245 If it is a number, no signature may not be longer (in characters) than
246 that number. If it is a floating point number, no signature may be
247 longer (in lines) than that number. If it is a function, the function
248 will be called without any parameters, and if it returns nil, there is
249 no signature in the buffer. If it is a string, it will be used as a
250 regexp. If it matches, the text in question is not a signature.
252 This can also be a list of the above values."
253 :type '(choice (const nil)
257 (regexp :value ".*"))
258 :group 'gnus-article-signature)
260 (defcustom gnus-hidden-properties '(invisible t intangible t)
261 "Property list to use for hiding text."
263 :group 'gnus-article-hiding)
265 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
266 ;; frames in a session.
267 (defcustom gnus-article-x-face-command
268 (if (featurep 'xemacs)
269 (if (or (gnus-image-type-available-p 'xface)
270 (gnus-image-type-available-p 'pbm))
271 'gnus-display-x-face-in-from
273 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
274 ; uncompface; } | icontopbm | ee -")
275 (if (gnus-image-type-available-p 'pbm)
276 'gnus-display-x-face-in-from
278 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
279 ; uncompface; } | icontopbm | display -"))
280 "*String or function to be executed to display an X-Face header.
281 If it is a string, the command will be executed in a sub-shell
282 asynchronously. The compressed face will be piped to this command."
283 :type `(choice string
284 (function-item gnus-display-x-face-in-from)
288 :group 'gnus-article-washing)
290 (defcustom gnus-article-x-face-too-ugly nil
291 "Regexp matching posters whose face shouldn't be shown automatically."
292 :type '(choice regexp (const nil))
293 :group 'gnus-article-washing)
295 (defcustom gnus-article-banner-alist nil
296 "Banner alist for stripping.
298 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
300 :type '(repeat (cons symbol regexp))
301 :group 'gnus-article-washing)
303 (gnus-define-group-parameter
306 "Alist of regexps (to match group names) and banner."
307 :variable-group gnus-article-washing
309 '(choice :tag "Banner"
311 (const :tag "Remove signature" signature)
312 (symbol :tag "Item in `gnus-article-banner-alist'" none)
314 (const :tag "None" nil))
316 "If non-nil, specify how to remove `banners' from articles.
318 Symbol `signature' means to remove signatures delimited by
319 `gnus-signature-separator'. Any other symbol is used to look up a
320 regular expression to match the banner in `gnus-article-banner-alist'.
321 A string is used as a regular expression to match the banner
324 (defcustom gnus-article-address-banner-alist nil
325 "Alist of mail addresses and banners.
326 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
327 to match a mail address in the From: header, BANNER is one of a symbol
328 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
329 If ADDRESS matches author's mail address, it will remove things like
330 advertisements. For example:
332 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
336 (regexp :tag "Address")
337 (choice :tag "Banner" :value nil
338 (const :tag "Remove signature" signature)
339 (symbol :tag "Item in `gnus-article-banner-alist'" none)
341 (const :tag "None" nil))))
343 :group 'gnus-article-washing)
345 (defmacro gnus-emphasis-custom-with-format (&rest body)
347 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
348 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
351 (defun gnus-emphasis-custom-value-to-external (value)
352 (gnus-emphasis-custom-with-format
353 (if (consp (car value))
354 (list (format format (car (car value)) (cdr (car value)))
356 (if (nth 1 value) 2 3)
360 (defun gnus-emphasis-custom-value-to-internal (value)
361 (gnus-emphasis-custom-with-format
362 (let ((regexp (concat "\\`"
363 (format (regexp-quote format)
364 "\\([^()]+\\)" "\\([^()]+\\)")
367 (if (string-match regexp (setq pattern (car value)))
368 (list (cons (match-string 1 pattern) (match-string 2 pattern))
373 (defcustom gnus-emphasis-alist
375 '(("\\*" "\\*" bold nil 2)
378 ("_/" "/_" underline-italic)
379 ("_\\*" "\\*_" underline-bold)
380 ("\\*/" "/\\*" bold-italic)
381 ("_\\*/" "/\\*_" underline-bold-italic))))
383 (gnus-emphasis-custom-with-format
384 (mapcar (lambda (spec)
385 (list (format format (car spec) (cadr spec))
388 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
390 '(;; I've never seen anyone use this strikethru convention whereas I've
391 ;; several times seen it triggered by normal text. --Stef
392 ;; Miles suggests that this form is sometimes used but for italics,
393 ;; so maybe we should map it to `italic'.
394 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
395 ;; 2 3 gnus-emphasis-strikethru)
396 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
397 2 3 gnus-emphasis-underline))))
398 "*Alist that says how to fontify certain phrases.
399 Each item looks like this:
401 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
403 The first element is a regular expression to be matched. The second
404 is a number that says what regular expression grouping used to find
405 the entire emphasized word. The third is a number that says what
406 regexp grouping should be displayed and highlighted. The fourth
407 is the face used for highlighting."
411 :format "%[Customizing Style%]\n%v"
413 (group :tag "Default"
414 :value ("" 0 0 default)
417 (let ((value (widget-get
418 (cadr (widget-get (widget-get widget :parent)
421 (if (not (eq (nth 2 value) 'default))
425 (gnus-emphasis-custom-value-to-external value))))
426 (widget-group-value-create widget))
428 (integer :format "Match group: %v")
429 (integer :format "Emphasize group: %v")
432 :value (("_" . "_") nil default)
434 (regexp :format "Start regexp: %v")
435 (regexp :format "End regexp: %v"))
436 (boolean :format "Show start and end patterns: %[%v%]\n"
437 :on " On " :off " Off ")
439 :get (lambda (symbol)
440 (mapcar 'gnus-emphasis-custom-value-to-internal
441 (default-value symbol)))
442 :set (lambda (symbol value)
443 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
445 :group 'gnus-article-emphasis)
447 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
448 "A regexp to describe whitespace which should not be emphasized.
449 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
450 The former avoids underlining of leading and trailing whitespace,
451 and the latter avoids underlining any whitespace at all."
453 :group 'gnus-article-emphasis
456 (defface gnus-emphasis-bold '((t (:bold t)))
457 "Face used for displaying strong emphasized text (*word*)."
458 :group 'gnus-article-emphasis)
460 (defface gnus-emphasis-italic '((t (:italic t)))
461 "Face used for displaying italic emphasized text (/word/)."
462 :group 'gnus-article-emphasis)
464 (defface gnus-emphasis-underline '((t (:underline t)))
465 "Face used for displaying underlined emphasized text (_word_)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
469 "Face used for displaying underlined bold emphasized text (_*word*_)."
470 :group 'gnus-article-emphasis)
472 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
473 "Face used for displaying underlined italic emphasized text (_/word/_)."
474 :group 'gnus-article-emphasis)
476 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
477 "Face used for displaying bold italic emphasized text (/*word*/)."
478 :group 'gnus-article-emphasis)
480 (defface gnus-emphasis-underline-bold-italic
481 '((t (:bold t :italic t :underline t)))
482 "Face used for displaying underlined bold italic emphasized text.
483 Example: (_/*word*/_)."
484 :group 'gnus-article-emphasis)
486 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
487 '((t (:strikethru t)))
488 '((t (:strike-through t))))
489 "Face used for displaying strike-through text (-word-)."
490 :group 'gnus-article-emphasis)
492 (defface gnus-emphasis-highlight-words
493 '((t (:background "black" :foreground "yellow")))
494 "Face used for displaying highlighted words."
495 :group 'gnus-article-emphasis)
497 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
498 "Format for display of Date headers in article bodies.
499 See `format-time-string' for the possible values.
501 The variable can also be function, which should return a complete Date
502 header. The function is called with one argument, the time, which can
503 be fed to `format-time-string'."
504 :type '(choice string function)
505 :link '(custom-manual "(gnus)Article Date")
506 :group 'gnus-article-washing)
508 (defcustom gnus-save-all-headers t
509 "*If non-nil, don't remove any headers before saving.
510 This will be overridden by the `:headers' property that the symbol of
511 the saver function, which is specified by `gnus-default-article-saver',
513 :group 'gnus-article-saving
516 (defcustom gnus-prompt-before-saving 'always
517 "*This variable says how much prompting is to be done when saving articles.
518 If it is nil, no prompting will be done, and the articles will be
519 saved to the default files. If this variable is `always', each and
520 every article that is saved will be preceded by a prompt, even when
521 saving large batches of articles. If this variable is neither nil not
522 `always', there the user will be prompted once for a file name for
523 each invocation of the saving commands."
524 :group 'gnus-article-saving
525 :type '(choice (item always)
526 (item :tag "never" nil)
527 (sexp :tag "once" :format "%t\n" :value t)))
529 (defcustom gnus-saved-headers gnus-visible-headers
530 "Headers to keep if `gnus-save-all-headers' is nil.
531 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
532 If that variable is nil, however, all headers that match this regexp
533 will be kept while the rest will be deleted before saving. This and
534 `gnus-save-all-headers' will be overridden by the `:headers' property
535 that the symbol of the saver function, which is specified by
536 `gnus-default-article-saver', might have."
537 :group 'gnus-article-saving
540 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
541 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
542 "A function to save articles in your favorite format.
543 The function will be called by way of the `gnus-summary-save-article'
544 command, and friends such as `gnus-summary-save-article-rmail'.
546 Gnus provides the following functions:
548 * gnus-summary-save-in-rmail (Rmail format)
549 * gnus-summary-save-in-mail (Unix mail format)
550 * gnus-summary-save-in-folder (MH folder)
551 * gnus-summary-save-in-file (article format)
552 * gnus-summary-save-body-in-file (article body)
553 * gnus-summary-save-in-vm (use VM's folder format)
554 * gnus-summary-write-to-file (article format -- overwrite)
555 * gnus-summary-write-body-to-file (article body -- overwrite)
556 * gnus-summary-save-in-pipe (article format)
558 The symbol of each function may have the following properties:
561 The value non-nil means save decoded articles. This is meaningful
562 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
563 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
564 `gnus-summary-save-in-pipe'.
567 The value specifies an alternative function which appends, not
568 overwrites, articles to a file. This implies that when saving many
569 articles at a time, `gnus-prompt-before-saving' is bound to t and all
570 articles are saved in a single file. This is meaningful only with
571 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
574 The value specifies the symbol of a variable of which the value
575 specifies headers to be saved. If it is omitted,
576 `gnus-save-all-headers' and `gnus-saved-headers' control what
577 headers should be saved."
578 :group 'gnus-article-saving
579 :type '(radio (function-item gnus-summary-save-in-rmail)
580 (function-item gnus-summary-save-in-mail)
581 (function-item gnus-summary-save-in-folder)
582 (function-item gnus-summary-save-in-file)
583 (function-item gnus-summary-save-body-in-file)
584 (function-item gnus-summary-save-in-vm)
585 (function-item gnus-summary-write-to-file)
586 (function-item gnus-summary-write-body-to-file)
587 (function-item gnus-summary-save-in-pipe)
590 (defcustom gnus-article-save-coding-system
591 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
592 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
593 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
594 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
595 "Coding system used to save decoded articles to a file.
597 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
598 which can safely encode any characters in text. This is used by the
601 * gnus-summary-save-article-file
602 * gnus-summary-save-article-body-file
603 * gnus-summary-write-article-file
604 * gnus-summary-write-article-body-file
606 and the functions to which you may set `gnus-default-article-saver':
608 * gnus-summary-save-in-file
609 * gnus-summary-save-body-in-file
610 * gnus-summary-write-to-file
611 * gnus-summary-write-body-to-file
613 Those commands and functions save just text displayed in the article
614 buffer to a file if the value of this variable is non-nil. Note that
615 buttonized MIME parts will be lost in a saved file in that case.
616 Otherwise, raw articles will be saved."
617 :group 'gnus-article-saving
619 :format "%{%t%}:\n %[Value Menu%] %v"
620 (const :tag "Save raw articles" nil)
623 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
624 '((const :tag "UTF-8" utf-8)
625 (const :tag "iso-2022-7bit" iso-2022-7bit)
626 (const :tag "Emacs internal" emacs-mule)
627 (const :tag "escape-quoted" escape-quoted))))
628 (symbol :tag "Coding system")))
630 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
631 "A function generating a file name to save articles in Rmail format.
632 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
633 :group 'gnus-article-saving
636 (defcustom gnus-mail-save-name 'gnus-plain-save-name
637 "A function generating a file name to save articles in Unix mail format.
638 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
639 :group 'gnus-article-saving
642 (defcustom gnus-folder-save-name 'gnus-folder-save-name
643 "A function generating a file name to save articles in MH folder.
644 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
645 :group 'gnus-article-saving
648 (defcustom gnus-file-save-name 'gnus-numeric-save-name
649 "A function generating a file name to save articles in article format.
650 The function is called with NEWSGROUP, HEADERS, and optional
652 :group 'gnus-article-saving
655 (defcustom gnus-split-methods
656 '((gnus-article-archive-name)
657 (gnus-article-nndoc-name))
658 "*Variable used to suggest where articles are to be saved.
659 For instance, if you would like to save articles related to Gnus in
660 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
661 you could set this variable to something like:
663 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
664 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
666 This variable is an alist where the key is the match and the
667 value is a list of possible files to save in if the match is
670 If the match is a string, it is used as a regexp match on the
671 article. If the match is a symbol, that symbol will be funcalled
672 from the buffer of the article to be saved with the newsgroup as the
673 parameter. If it is a list, it will be evalled in the same buffer.
675 If this form or function returns a string, this string will be used as a
676 possible file name; and if it returns a non-nil list, that list will be
677 used as possible file names."
678 :group 'gnus-article-saving
679 :type '(repeat (choice (list :value (fun) function)
680 (cons :value ("" "") regexp (repeat string))
683 (defcustom gnus-page-delimiter "^\^L"
684 "*Regexp describing what to use as article page delimiters.
685 The default value is \"^\^L\", which is a form linefeed at the
686 beginning of a line."
688 :group 'gnus-article-various)
690 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
691 "*The format specification for the article mode line.
692 See `gnus-summary-mode-line-format' for a closer description.
694 The following additional specs are available:
696 %w The article washing status.
697 %m The number of MIME parts in the article."
700 :group 'gnus-article-various)
702 (defcustom gnus-article-mode-hook nil
703 "*A hook for Gnus article mode."
705 :group 'gnus-article-various)
707 (when (featurep 'xemacs)
708 ;; Extracted from gnus-xmas-define in order to preserve user settings
709 (when (fboundp 'turn-off-scroll-in-place)
710 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
711 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
712 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
714 (defcustom gnus-article-menu-hook nil
715 "*Hook run after the creation of the article mode menu."
717 :group 'gnus-article-various)
719 (defcustom gnus-article-prepare-hook nil
720 "*A hook called after an article has been prepared in the article buffer."
722 :group 'gnus-article-various)
724 (defcustom gnus-copy-article-ignored-headers nil
725 "List of headers to be removed when copying an article.
726 Each element is a regular expression."
727 :version "23.1" ;; No Gnus
728 :type '(repeat regexp)
729 :group 'gnus-article-various)
731 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
732 "Gnus 5.10 (Emacs 22.1)")
735 '((t (:weight bold)))
736 "Face used for highlighting a button in the article buffer."
737 :group 'gnus-article-buttons)
739 (defcustom gnus-article-button-face 'gnus-button
740 "Face used for highlighting buttons in the article buffer.
742 An article button is a piece of text that you can activate by pressing
743 `RET' or `mouse-2' above it."
745 :group 'gnus-article-buttons)
747 (defcustom gnus-article-mouse-face 'highlight
748 "Face used for mouse highlighting in the article buffer.
750 Article buttons will be displayed in this face when the cursor is
753 :group 'gnus-article-buttons)
755 (defcustom gnus-signature-face 'gnus-signature
756 "Face used for highlighting a signature in the article buffer.
757 Obsolete; use the face `gnus-signature' for customizations instead."
759 :group 'gnus-article-highlight
760 :group 'gnus-article-signature)
762 (defface gnus-signature
765 "Face used for highlighting a signature in the article buffer."
766 :group 'gnus-article-highlight
767 :group 'gnus-article-signature)
768 ;; backward-compatibility alias
769 (put 'gnus-signature-face 'face-alias 'gnus-signature)
770 (put 'gnus-signature-face 'obsolete-face "22.1")
772 (defface gnus-header-from
775 (:foreground "PaleGreen1"))
778 (:foreground "red3"))
781 "Face used for displaying from headers."
782 :group 'gnus-article-headers
783 :group 'gnus-article-highlight)
784 ;; backward-compatibility alias
785 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
786 (put 'gnus-header-from-face 'obsolete-face "22.1")
788 (defface gnus-header-subject
791 (:foreground "SeaGreen1"))
794 (:foreground "red4"))
796 (:bold t :italic t)))
797 "Face used for displaying subject headers."
798 :group 'gnus-article-headers
799 :group 'gnus-article-highlight)
800 ;; backward-compatibility alias
801 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
802 (put 'gnus-header-subject-face 'obsolete-face "22.1")
804 (defface gnus-header-newsgroups
807 (:foreground "yellow" :italic t))
810 (:foreground "MidnightBlue" :italic t))
813 "Face used for displaying newsgroups headers.
814 In the default setup this face is only used for crossposted
816 :group 'gnus-article-headers
817 :group 'gnus-article-highlight)
818 ;; backward-compatibility alias
819 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
820 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
822 (defface gnus-header-name
825 (:foreground "SpringGreen2"))
828 (:foreground "maroon"))
831 "Face used for displaying header names."
832 :group 'gnus-article-headers
833 :group 'gnus-article-highlight)
834 ;; backward-compatibility alias
835 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
836 (put 'gnus-header-name-face 'obsolete-face "22.1")
838 (defface gnus-header-content
841 (:foreground "SpringGreen1" :italic t))
844 (:foreground "indianred4" :italic t))
846 (:italic t))) "Face used for displaying header content."
847 :group 'gnus-article-headers
848 :group 'gnus-article-highlight)
849 ;; backward-compatibility alias
850 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
851 (put 'gnus-header-content-face 'obsolete-face "22.1")
853 (defcustom gnus-header-face-alist
854 '(("From" nil gnus-header-from)
855 ("Subject" nil gnus-header-subject)
856 ("Newsgroups:.*," nil gnus-header-newsgroups)
857 ("" gnus-header-name gnus-header-content))
858 "*Controls highlighting of article headers.
860 An alist of the form (HEADER NAME CONTENT).
862 HEADER is a regular expression which should match the name of a
863 header and NAME and CONTENT are either face names or nil.
865 The name of each header field will be displayed using the face
866 specified by the first element in the list where HEADER matches
867 the header name and NAME is non-nil. Similarly, the content will
868 be displayed by the first non-nil matching CONTENT face."
869 :group 'gnus-article-headers
870 :group 'gnus-article-highlight
871 :type '(repeat (list (regexp :tag "Header")
873 (item :tag "skip" nil)
874 (face :value default))
875 (choice :tag "Content"
876 (item :tag "skip" nil)
877 (face :value default)))))
879 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
880 '((xface . (:face gnus-x-face)))
881 '((pbm . (:face gnus-x-face))
883 "Alist of image types and properties applied to Face and X-Face images.
886 ;; Specify the altitude of Face images in the From header.
887 \(setq gnus-face-properties-alist
888 '((pbm . (:face gnus-x-face :ascent 80))
889 (png . (:ascent 80))))
891 ;; Show Face images as pressed buttons.
892 \(setq gnus-face-properties-alist
893 '((pbm . (:face gnus-x-face :relief -2))
894 (png . (:relief -2))))
896 See the manual for the valid properties for various image types.
897 Currently, `pbm' is used for X-Face images and `png' is used for Face
898 images in Emacs. Only the `:face' property is effective on the `xface'
899 image type in XEmacs if it is built with the libcompface library."
900 :version "23.1" ;; No Gnus
901 :group 'gnus-article-headers
902 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
904 (defcustom gnus-article-decode-hook
905 '(article-decode-charset article-decode-encoded-words
906 article-decode-group-name article-decode-idna-rhs)
907 "*Hook run to decode charsets in articles."
908 :group 'gnus-article-headers
911 (defcustom gnus-display-mime-function 'gnus-display-mime
912 "Function to display MIME articles."
913 :group 'gnus-article-mime
916 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
917 "Function used to decode headers.")
919 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
920 "Function used to decode addresses.")
922 (defvar gnus-article-dumbquotes-map
942 "Table for MS-to-Latin1 translation.")
944 (defcustom gnus-ignored-mime-types nil
945 "List of MIME types that should be ignored by Gnus."
947 :group 'gnus-article-mime
948 :type '(repeat regexp))
950 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
951 "List of MIME types that should not be given buttons when rendered inline.
952 See also `gnus-buttonized-mime-types' which may override this variable.
953 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
955 :group 'gnus-article-mime
956 :type '(repeat regexp))
958 (defcustom gnus-buttonized-mime-types nil
959 "List of MIME types that should be given buttons when rendered inline.
960 If set, this variable overrides `gnus-unbuttonized-mime-types'.
961 To see e.g. security buttons you could set this to
962 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
963 this list to display radio buttons that allow you to choose one of two
964 media types those mails include. See also `mm-discouraged-alternatives'.
965 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
967 :group 'gnus-article-mime
968 :type '(repeat regexp))
970 (defcustom gnus-inhibit-mime-unbuttonizing nil
971 "If non-nil, all MIME parts get buttons.
972 When nil (the default value), then some MIME parts do not get buttons,
973 as described by the variables `gnus-buttonized-mime-types' and
974 `gnus-unbuttonized-mime-types'."
976 :group 'gnus-article-mime
979 (defcustom gnus-body-boundary-delimiter "_"
980 "String used to delimit header and body.
981 This variable is used by `gnus-article-treat-body-boundary' which can
982 be controlled by `gnus-treat-body-boundary'."
984 :group 'gnus-article-various
985 :type '(choice (item :tag "None" :value nil)
988 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
990 "Defines the location of the faces database.
991 For information on obtaining this database of pretty pictures, please
992 see http://www.cs.indiana.edu/picons/ftp/index.html"
994 :type '(repeat directory)
995 :link '(url-link :tag "download"
996 "http://www.cs.indiana.edu/picons/ftp/index.html")
997 :link '(custom-manual "(gnus)Picons")
1000 (defun gnus-picons-installed-p ()
1001 "Say whether picons are installed on your machine."
1002 (let ((installed nil))
1003 (dolist (database gnus-picon-databases)
1004 (when (file-exists-p database)
1005 (setq installed t)))
1008 (defcustom gnus-article-mime-part-function nil
1009 "Function called with a MIME handle as the argument.
1010 This is meant for people who want to do something automatic based
1011 on parts -- for instance, adding Vcard info to a database."
1012 :group 'gnus-article-mime
1013 :type '(choice (const nil)
1016 (defcustom gnus-mime-multipart-functions nil
1017 "An alist of MIME types to functions to display them."
1019 :group 'gnus-article-mime
1020 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1022 (defcustom gnus-article-date-headers '(combined-lapsed)
1023 "A list of Date header formats to display.
1024 Valid formats are `ut' (universal time), `local' (local time
1025 zone), `english' (readable English), `lapsed' (elapsed time),
1026 `combined-lapsed' (both the original date and the elapsed time),
1027 `original' (the original date header), `iso8601' (ISO8601
1028 format), and `user-defined' (a user-defined format defined by the
1029 `gnus-article-time-format' variable).
1031 You have as many date headers as you want in the article buffer.
1032 Some of these headers are updated automatically. See
1033 `gnus-article-update-date-headers' for details."
1035 :group 'gnus-article-headers
1037 (item :tag "Universal time (UT)" :value 'ut)
1038 (item :tag "Local time zone" :value 'local)
1039 (item :tag "Readable English" :value 'english)
1040 (item :tag "Elapsed time" :value 'lapsed)
1041 (item :tag "Original and elapsed time" :value 'combined-lapsed)
1042 (item :tag "Original date header" :value 'original)
1043 (item :tag "ISO8601 format" :value 'iso8601)
1044 (item :tag "User-defined" :value 'user-defined)))
1046 (defcustom gnus-article-update-date-headers nil
1047 "A number that says how often to update the date header (in seconds).
1048 If nil, don't update it at all."
1050 :group 'gnus-article-headers
1052 (item :tag "Don't update" :value nil)
1055 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1056 "Function called with a MIME handle as the argument.
1057 This is meant for people who want to view first matched part.
1058 For `undisplayed-alternative' (default), the first undisplayed
1059 part or alternative part is used. For `undisplayed', the first
1060 undisplayed part is used. For a function, the first part which
1061 the function return t is used. For nil, the first part is
1064 :group 'gnus-article-mime
1066 (item :tag "first" :value nil)
1067 (item :tag "undisplayed" :value undisplayed)
1068 (item :tag "undisplayed or alternative"
1069 :value undisplayed-alternative)
1072 (defcustom gnus-mime-action-alist
1073 '(("save to file" . gnus-mime-save-part)
1074 ("save and strip" . gnus-mime-save-part-and-strip)
1075 ("replace with file" . gnus-mime-replace-part)
1076 ("delete part" . gnus-mime-delete-part)
1077 ("display as text" . gnus-mime-inline-part)
1078 ("view the part" . gnus-mime-view-part)
1079 ("pipe to command" . gnus-mime-pipe-part)
1080 ("toggle display" . gnus-article-press-button)
1081 ("toggle display" . gnus-article-view-part-as-charset)
1082 ("view as type" . gnus-mime-view-part-as-type)
1083 ("view internally" . gnus-mime-view-part-internally)
1084 ("view externally" . gnus-mime-view-part-externally))
1085 "An alist of actions that run on the MIME attachment."
1086 :group 'gnus-article-mime
1087 :type '(repeat (cons (string :tag "name")
1090 (defcustom gnus-auto-select-part 1
1091 "Advance to next MIME part when deleting or stripping parts.
1093 When 0, point will be placed on the same part as before. When
1094 positive (negative), move point forward (backwards) this many
1095 parts. When nil, redisplay article."
1096 :version "23.1" ;; No Gnus
1097 :group 'gnus-article-mime
1098 :type '(choice (const nil :tag "Redisplay article.")
1099 (const 1 :tag "Next part.")
1100 (const 0 :tag "Current part.")
1104 ;;; The treatment variables
1107 (defvar gnus-part-display-hook nil
1108 "Hook called on parts that are to receive treatment.")
1110 (defvar gnus-article-treat-custom
1111 '(choice (const :tag "Off" nil)
1113 (const :tag "Header" head)
1114 (const :tag "First" first)
1115 (const :tag "Last" last)
1116 (integer :tag "Less")
1117 (repeat :tag "Groups" regexp)
1118 (sexp :tag "Predicate")))
1120 (defvar gnus-article-treat-head-custom
1121 '(choice (const :tag "Off" nil)
1122 (const :tag "Header" head)))
1124 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1128 (defvar gnus-inhibit-treatment nil
1129 "Whether to inhibit treatment.")
1131 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1132 "Highlight the signature.
1133 Valid values are nil, t, `head', `first', `last', an integer or a
1134 predicate. See Info node `(gnus)Customizing Articles'."
1135 :group 'gnus-article-treat
1136 :link '(custom-manual "(gnus)Customizing Articles")
1137 :type gnus-article-treat-custom)
1138 (put 'gnus-treat-highlight-signature 'highlight t)
1140 (defcustom gnus-treat-buttonize 100000
1142 Valid values are nil, t, `head', `first', `last', an integer or a
1143 predicate. See Info node `(gnus)Customizing Articles'."
1144 :group 'gnus-article-treat
1145 :link '(custom-manual "(gnus)Customizing Articles")
1146 :type gnus-article-treat-custom)
1147 (put 'gnus-treat-buttonize 'highlight t)
1149 (defcustom gnus-treat-buttonize-head 'head
1150 "Add buttons to the head.
1151 Valid values are nil, t, `head', `first', `last', an integer or a
1152 predicate. See Info node `(gnus)Customizing Articles'."
1153 :group 'gnus-article-treat
1154 :link '(custom-manual "(gnus)Customizing Articles")
1155 :type gnus-article-treat-head-custom)
1156 (put 'gnus-treat-buttonize-head 'highlight t)
1158 (defcustom gnus-treat-date 'head
1159 "Display dates according to the `gnus-article-date-headers' variable.
1160 Valid values are nil, t, `head', `first', `last', an integer or a
1161 predicate. See Info node `(gnus)Customizing Articles'."
1163 :group 'gnus-article-treat
1164 :link '(custom-manual "(gnus)Customizing Articles")
1165 :type gnus-article-treat-head-custom)
1167 (defcustom gnus-treat-emphasize 50000
1169 Valid values are nil, t, `head', `first', `last', an integer or a
1170 predicate. See Info node `(gnus)Customizing Articles'."
1171 :group 'gnus-article-treat
1172 :link '(custom-manual "(gnus)Customizing Articles")
1173 :type gnus-article-treat-custom)
1174 (put 'gnus-treat-emphasize 'highlight t)
1176 (defcustom gnus-treat-strip-cr nil
1177 "Remove carriage returns.
1178 Valid values are nil, t, `head', `first', `last', an integer or a
1179 predicate. See Info node `(gnus)Customizing Articles'."
1181 :group 'gnus-article-treat
1182 :link '(custom-manual "(gnus)Customizing Articles")
1183 :type gnus-article-treat-custom)
1185 (defcustom gnus-treat-unsplit-urls nil
1186 "Remove newlines from within URLs.
1187 Valid values are nil, t, `head', `first', `last', an integer or a
1188 predicate. See Info node `(gnus)Customizing Articles'."
1190 :group 'gnus-article-treat
1191 :link '(custom-manual "(gnus)Customizing Articles")
1192 :type gnus-article-treat-custom)
1194 (defcustom gnus-treat-leading-whitespace nil
1195 "Remove leading whitespace in headers.
1196 Valid values are nil, t, `head', `first', `last', an integer or a
1197 predicate. See Info node `(gnus)Customizing Articles'."
1199 :group 'gnus-article-treat
1200 :link '(custom-manual "(gnus)Customizing Articles")
1201 :type gnus-article-treat-custom)
1203 (defcustom gnus-treat-hide-headers 'head
1205 Valid values are nil, t, `head', `first', `last', an integer or a
1206 predicate. See Info node `(gnus)Customizing Articles'."
1207 :group 'gnus-article-treat
1208 :link '(custom-manual "(gnus)Customizing Articles")
1209 :type gnus-article-treat-head-custom)
1211 (defcustom gnus-treat-hide-boring-headers nil
1212 "Hide boring headers.
1213 Valid values are nil, t, `head', `first', `last', an integer or a
1214 predicate. See Info node `(gnus)Customizing Articles'."
1215 :group 'gnus-article-treat
1216 :link '(custom-manual "(gnus)Customizing Articles")
1217 :type gnus-article-treat-head-custom)
1219 (defcustom gnus-treat-hide-signature nil
1220 "Hide the signature.
1221 Valid values are nil, t, `head', `first', `last', an integer or a
1222 predicate. See Info node `(gnus)Customizing Articles'."
1223 :group 'gnus-article-treat
1224 :link '(custom-manual "(gnus)Customizing Articles")
1225 :type gnus-article-treat-custom)
1227 (defcustom gnus-treat-fill-article nil
1229 Valid values are nil, t, `head', `first', `last', an integer or a
1230 predicate. See Info node `(gnus)Customizing Articles'."
1231 :group 'gnus-article-treat
1232 :link '(custom-manual "(gnus)Customizing Articles")
1233 :type gnus-article-treat-custom)
1235 (defcustom gnus-treat-hide-citation nil
1237 Valid values are nil, t, `head', `first', `last', an integer or a
1238 predicate. See Info node `(gnus)Customizing Articles'.
1240 See `gnus-article-highlight-citation' for variables used to
1241 control what it hides."
1242 :group 'gnus-article-treat
1243 :link '(custom-manual "(gnus)Customizing Articles")
1244 :type gnus-article-treat-custom)
1246 (defcustom gnus-treat-hide-citation-maybe nil
1247 "Hide cited text according to certain conditions.
1248 Valid values are nil, t, `head', `first', `last', an integer or a
1249 predicate. See Info node `(gnus)Customizing Articles'.
1251 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1252 how to control what it hides."
1253 :group 'gnus-article-treat
1254 :link '(custom-manual "(gnus)Customizing Articles")
1255 :type gnus-article-treat-custom)
1257 (defcustom gnus-treat-strip-list-identifiers 'head
1258 "Strip list identifiers from `gnus-list-identifiers`.
1259 Valid values are nil, t, `head', `first', `last', an integer or a
1260 predicate. See Info node `(gnus)Customizing Articles'."
1262 :group 'gnus-article-treat
1263 :link '(custom-manual "(gnus)Customizing Articles")
1264 :type gnus-article-treat-custom)
1266 (gnus-define-group-parameter
1269 "Alist of regexps and correspondent identifiers."
1270 :variable-group gnus-article-washing
1272 '(choice :tag "Identifier"
1274 (symbol :tag "Item in `gnus-list-identifiers'" none)
1276 (const :tag "None" nil))
1278 "If non-nil, specify how to remove `identifiers' from articles' subject.
1280 Any symbol is used to look up a regular expression to match the
1281 banner in `gnus-list-identifiers'. A string is used as a regular
1282 expression to match the identifier directly.")
1284 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1285 "Gnus 5.10 (Emacs 22.1)")
1287 (defcustom gnus-treat-strip-pem nil
1288 "Strip PEM signatures.
1289 Valid values are nil, t, `head', `first', `last', an integer or a
1290 predicate. See Info node `(gnus)Customizing Articles'."
1291 :group 'gnus-article-treat
1292 :link '(custom-manual "(gnus)Customizing Articles")
1293 :type gnus-article-treat-custom)
1295 (defcustom gnus-treat-strip-banner t
1296 "Strip banners from articles.
1297 The banner to be stripped is specified in the `banner' group parameter.
1298 Valid values are nil, t, `head', `first', `last', an integer or a
1299 predicate. See Info node `(gnus)Customizing Articles'."
1300 :group 'gnus-article-treat
1301 :link '(custom-manual "(gnus)Customizing Articles")
1302 :type gnus-article-treat-custom)
1304 (defcustom gnus-treat-highlight-headers 'head
1305 "Highlight the headers.
1306 Valid values are nil, t, `head', `first', `last', an integer or a
1307 predicate. See Info node `(gnus)Customizing Articles'."
1308 :group 'gnus-article-treat
1309 :link '(custom-manual "(gnus)Customizing Articles")
1310 :type gnus-article-treat-head-custom)
1311 (put 'gnus-treat-highlight-headers 'highlight t)
1313 (defcustom gnus-treat-highlight-citation t
1314 "Highlight cited text.
1315 Valid values are nil, t, `head', `first', `last', an integer or a
1316 predicate. See Info node `(gnus)Customizing Articles'."
1317 :group 'gnus-article-treat
1318 :link '(custom-manual "(gnus)Customizing Articles")
1319 :type gnus-article-treat-custom)
1320 (put 'gnus-treat-highlight-citation 'highlight t)
1322 (defcustom gnus-treat-strip-headers-in-body t
1323 "Strip the X-No-Archive header line from the beginning of the body.
1324 Valid values are nil, t, `head', `first', `last', an integer or a
1325 predicate. See Info node `(gnus)Customizing Articles'."
1327 :group 'gnus-article-treat
1328 :link '(custom-manual "(gnus)Customizing Articles")
1329 :type gnus-article-treat-custom)
1331 (defcustom gnus-treat-strip-trailing-blank-lines nil
1332 "Strip trailing blank lines.
1333 Valid values are nil, t, `head', `first', `last', an integer or a
1334 predicate. See Info node `(gnus)Customizing Articles'.
1336 When set to t, it also strips trailing blanks in all MIME parts.
1337 Consider to use `last' instead."
1338 :group 'gnus-article-treat
1339 :link '(custom-manual "(gnus)Customizing Articles")
1340 :type gnus-article-treat-custom)
1342 (defcustom gnus-treat-strip-leading-blank-lines nil
1343 "Strip leading blank lines.
1344 Valid values are nil, t, `head', `first', `last', an integer or a
1345 predicate. See Info node `(gnus)Customizing Articles'.
1347 When set to t, it also strips trailing blanks in all MIME parts."
1348 :group 'gnus-article-treat
1349 :link '(custom-manual "(gnus)Customizing Articles")
1350 :type gnus-article-treat-custom)
1352 (defcustom gnus-treat-strip-multiple-blank-lines nil
1353 "Strip multiple blank lines.
1354 Valid values are nil, t, `head', `first', `last', an integer or a
1355 predicate. See Info node `(gnus)Customizing Articles'."
1356 :group 'gnus-article-treat
1357 :link '(custom-manual "(gnus)Customizing Articles")
1358 :type gnus-article-treat-custom)
1360 (defcustom gnus-treat-unfold-headers 'head
1361 "Unfold folded header lines.
1362 Valid values are nil, t, `head', `first', `last', an integer or a
1363 predicate. See Info node `(gnus)Customizing Articles'."
1365 :group 'gnus-article-treat
1366 :link '(custom-manual "(gnus)Customizing Articles")
1367 :type gnus-article-treat-custom)
1369 (defcustom gnus-article-unfold-long-headers nil
1370 "If non-nil, allow unfolding headers even if the header is long.
1371 If it is a regexp, only long headers matching this regexp are unfolded.
1372 If it is t, all long headers are unfolded.
1374 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1375 :version "23.1" ;; No Gnus
1376 :group 'gnus-article-treat
1377 :type '(choice (const nil)
1378 (const :tag "all" t)
1381 (defcustom gnus-treat-fold-headers nil
1383 Valid values are nil, t, `head', `first', `last', an integer or a
1384 predicate. See Info node `(gnus)Customizing Articles'."
1386 :group 'gnus-article-treat
1387 :link '(custom-manual "(gnus)Customizing Articles")
1388 :type gnus-article-treat-custom)
1390 (defcustom gnus-treat-fold-newsgroups 'head
1391 "Fold the Newsgroups and Followup-To headers.
1392 Valid values are nil, t, `head', `first', `last', an integer or a
1393 predicate. See Info node `(gnus)Customizing Articles'."
1395 :group 'gnus-article-treat
1396 :link '(custom-manual "(gnus)Customizing Articles")
1397 :type gnus-article-treat-custom)
1399 (defcustom gnus-treat-overstrike t
1400 "Treat overstrike highlighting.
1401 Valid values are nil, t, `head', `first', `last', an integer or a
1402 predicate. See Info node `(gnus)Customizing Articles'."
1403 :group 'gnus-article-treat
1404 :link '(custom-manual "(gnus)Customizing Articles")
1405 :type gnus-article-treat-custom)
1406 (put 'gnus-treat-overstrike 'highlight t)
1408 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1409 "Treat ANSI SGR control sequences.
1410 Valid values are nil, t, `head', `first', `last', an integer or a
1411 predicate. See Info node `(gnus)Customizing Articles'."
1412 :group 'gnus-article-treat
1413 :link '(custom-manual "(gnus)Customizing Articles")
1414 :type gnus-article-treat-custom)
1416 (make-obsolete-variable 'gnus-treat-display-xface
1417 'gnus-treat-display-x-face "Emacs 22.1")
1419 (defcustom gnus-treat-display-x-face
1420 (and (not noninteractive)
1421 (gnus-image-type-available-p 'xbm)
1422 (if (featurep 'xemacs)
1425 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1426 (executable-find "icontopbm"))
1427 ;; shell-command-to-string may signal an error, e.g. if
1428 ;; shell-file-name is not found.
1431 "Display X-Face headers.
1432 Valid values are nil and `head'.
1433 See Info node `(gnus)Customizing Articles' and Info node
1434 `(gnus)X-Face' for details."
1435 :group 'gnus-article-treat
1437 :link '(custom-manual "(gnus)Customizing Articles")
1438 :link '(custom-manual "(gnus)X-Face")
1439 :type gnus-article-treat-head-custom
1440 :set (lambda (symbol value)
1443 (cond ((or (boundp symbol) (get symbol 'saved-value))
1445 ((boundp 'gnus-treat-display-xface)
1447 ** gnus-treat-display-xface is an obsolete variable;\
1448 use gnus-treat-display-x-face instead")
1449 (default-value 'gnus-treat-display-xface))
1450 ((get 'gnus-treat-display-xface 'saved-value)
1452 ** gnus-treat-display-xface is an obsolete variable;\
1453 use gnus-treat-display-x-face instead")
1454 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1457 (put 'gnus-treat-display-x-face 'highlight t)
1459 (defcustom gnus-treat-display-face
1460 (and (not noninteractive)
1461 (gnus-image-type-available-p 'png)
1463 "Display Face headers.
1464 Valid values are nil, t, `head', `first', `last', an integer or a
1465 predicate. See Info node `(gnus)Customizing Articles' and Info
1466 node `(gnus)Face' for details."
1467 :group 'gnus-article-treat
1469 :link '(custom-manual "(gnus)Customizing Articles")
1470 :link '(custom-manual "(gnus)X-Face")
1471 :type gnus-article-treat-head-custom)
1472 (put 'gnus-treat-display-face 'highlight t)
1474 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1476 Valid values are nil, t, `head', `first', `last', an integer or a
1477 predicate. See Info node `(gnus)Customizing Articles' and Info
1478 node `(gnus)Smileys' for details."
1479 :group 'gnus-article-treat
1481 :link '(custom-manual "(gnus)Customizing Articles")
1482 :link '(custom-manual "(gnus)Smileys")
1483 :type gnus-article-treat-custom)
1484 (put 'gnus-treat-display-smileys 'highlight t)
1486 (defcustom gnus-treat-from-picon
1487 (if (and (gnus-image-type-available-p 'xpm)
1488 (gnus-picons-installed-p))
1490 "Display picons in the From header.
1491 Valid values are nil, t, `head', `first', `last', an integer or a
1492 predicate. See Info node `(gnus)Customizing Articles' and Info
1493 node `(gnus)Picons' for details."
1495 :group 'gnus-article-treat
1497 :link '(custom-manual "(gnus)Customizing Articles")
1498 :link '(custom-manual "(gnus)Picons")
1499 :type gnus-article-treat-head-custom)
1500 (put 'gnus-treat-from-picon 'highlight t)
1502 (defcustom gnus-treat-mail-picon
1503 (if (and (gnus-image-type-available-p 'xpm)
1504 (gnus-picons-installed-p))
1506 "Display picons in To and Cc headers.
1507 Valid values are nil, t, `head', `first', `last', an integer or a
1508 predicate. See Info node `(gnus)Customizing Articles' and Info
1509 node `(gnus)Picons' for details."
1511 :group 'gnus-article-treat
1513 :link '(custom-manual "(gnus)Customizing Articles")
1514 :link '(custom-manual "(gnus)Picons")
1515 :type gnus-article-treat-head-custom)
1516 (put 'gnus-treat-mail-picon 'highlight t)
1518 (defcustom gnus-treat-newsgroups-picon
1519 (if (and (gnus-image-type-available-p 'xpm)
1520 (gnus-picons-installed-p))
1522 "Display picons in the Newsgroups and Followup-To headers.
1523 Valid values are nil, t, `head', `first', `last', an integer or a
1524 predicate. See Info node `(gnus)Customizing Articles' and Info
1525 node `(gnus)Picons' for details."
1527 :group 'gnus-article-treat
1529 :link '(custom-manual "(gnus)Customizing Articles")
1530 :link '(custom-manual "(gnus)Picons")
1531 :type gnus-article-treat-head-custom)
1532 (put 'gnus-treat-newsgroups-picon 'highlight t)
1534 (defcustom gnus-treat-from-gravatar nil
1535 "Display gravatars in the From header.
1536 Valid values are nil, t, `head', `first', `last', an integer or a
1537 predicate. See Info node `(gnus)Customizing Articles' and Info
1538 node `(gnus)Gravatars' for details."
1540 :group 'gnus-article-treat
1541 :group 'gnus-gravatar
1542 :link '(custom-manual "(gnus)Customizing Articles")
1543 :link '(custom-manual "(gnus)Gravatars")
1544 :type gnus-article-treat-head-custom)
1545 (put 'gnus-treat-from-gravatar 'highlight t)
1547 (defcustom gnus-treat-mail-gravatar nil
1548 "Display gravatars in To and Cc headers.
1549 Valid values are nil, t, `head', `first', `last', an integer or a
1550 predicate. See Info node `(gnus)Customizing Articles' and Info
1551 node `(gnus)Gravatars' for details."
1553 :group 'gnus-article-treat
1554 :group 'gnus-gravatar
1555 :link '(custom-manual "(gnus)Customizing Articles")
1556 :link '(custom-manual "(gnus)Gravatars")
1557 :type gnus-article-treat-head-custom)
1558 (put 'gnus-treat-mail-gravatar 'highlight t)
1560 (defcustom gnus-treat-body-boundary
1561 (if (or gnus-treat-newsgroups-picon
1562 gnus-treat-mail-picon
1563 gnus-treat-from-picon
1564 gnus-treat-from-gravatar
1565 gnus-treat-mail-gravatar)
1566 ;; If there's much decoration, the user might prefer a boundary.
1569 "Draw a boundary at the end of the headers.
1570 Valid values are nil and `head'.
1571 See Info node `(gnus)Customizing Articles' for details."
1573 :group 'gnus-article-treat
1574 :link '(custom-manual "(gnus)Customizing Articles")
1575 :type gnus-article-treat-head-custom)
1577 (defcustom gnus-treat-capitalize-sentences nil
1578 "Capitalize sentence-starting words.
1579 Valid values are nil, t, `head', `first', `last', an integer or a
1580 predicate. See Info node `(gnus)Customizing Articles'."
1582 :group 'gnus-article-treat
1583 :link '(custom-manual "(gnus)Customizing Articles")
1584 :type gnus-article-treat-custom)
1586 (defcustom gnus-treat-wash-html nil
1588 Valid values are nil, t, `head', `first', `last', an integer or a
1589 predicate. See Info node `(gnus)Customizing Articles'."
1591 :group 'gnus-article-treat
1592 :link '(custom-manual "(gnus)Customizing Articles")
1593 :type gnus-article-treat-custom)
1595 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1597 Valid values are nil, t, `head', `first', `last', an integer or a
1598 predicate. See Info node `(gnus)Customizing Articles'."
1600 :group 'gnus-article-treat
1601 :link '(custom-manual "(gnus)Customizing Articles")
1602 :type gnus-article-treat-custom)
1604 (defcustom gnus-treat-x-pgp-sig nil
1606 To automatically treat X-PGP-Sig, set it to head.
1607 Valid values are nil, t, `head', `first', `last', an integer or a
1608 predicate. See Info node `(gnus)Customizing Articles'."
1610 :group 'gnus-article-treat
1611 :group 'mime-security
1612 :link '(custom-manual "(gnus)Customizing Articles")
1613 :type gnus-article-treat-custom)
1615 (defvar gnus-article-encrypt-protocol-alist
1616 '(("PGP" . mml2015-self-encrypt)))
1618 ;; Set to nil if more than one protocol added to
1619 ;; gnus-article-encrypt-protocol-alist.
1620 (defcustom gnus-article-encrypt-protocol "PGP"
1621 "The protocol used for encrypt articles.
1622 It is a string, such as \"PGP\". If nil, ask user."
1625 :group 'mime-security)
1627 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1628 (mm-coding-system-p 'utf-8)
1629 (executable-find idna-program))
1630 "Whether IDNA decoding of headers is used when viewing messages.
1631 This requires GNU Libidn, and by default only enabled if it is found."
1633 :group 'gnus-article-headers
1636 (defcustom gnus-article-over-scroll nil
1637 "If non-nil, allow scrolling the article buffer even when there no more text."
1639 :group 'gnus-article
1642 (defcustom gnus-inhibit-images nil
1643 "Non-nil means inhibit displaying of images inline in the article body."
1645 :group 'gnus-article
1648 (defcustom gnus-blocked-images 'gnus-block-private-groups
1649 "Images that have URLs matching this regexp will be blocked.
1650 This can also be a function to be evaluated. If so, it will be
1651 called with the group name as the parameter, and should return a
1657 ;;; Internal variables
1659 (defvar gnus-english-month-names
1660 '("January" "February" "March" "April" "May" "June" "July" "August"
1661 "September" "October" "November" "December"))
1663 (defvar article-goto-body-goes-to-point-min-p nil)
1664 (defvar gnus-article-wash-types nil)
1665 (defvar gnus-article-emphasis-alist nil)
1666 (defvar gnus-article-image-alist nil)
1668 (defvar gnus-article-mime-handle-alist-1 nil)
1669 (defvar gnus-treatment-function-alist
1670 '((gnus-treat-strip-cr gnus-article-remove-cr)
1671 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1672 (gnus-treat-strip-banner gnus-article-strip-banner)
1673 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1674 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1675 (gnus-treat-buttonize gnus-article-add-buttons)
1676 (gnus-treat-fill-article gnus-article-fill-cited-article)
1677 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1678 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1679 (gnus-treat-display-x-face gnus-article-display-x-face)
1680 (gnus-treat-display-face gnus-article-display-face)
1681 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1682 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1683 (gnus-treat-hide-signature gnus-article-hide-signature)
1684 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1685 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1686 (gnus-treat-from-picon gnus-treat-from-picon)
1687 (gnus-treat-mail-picon gnus-treat-mail-picon)
1688 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1689 (gnus-treat-strip-pem gnus-article-hide-pem)
1690 (gnus-treat-date gnus-article-treat-date)
1691 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1692 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1693 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1694 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1695 (gnus-treat-strip-trailing-blank-lines
1696 gnus-article-remove-trailing-blank-lines)
1697 (gnus-treat-strip-leading-blank-lines
1698 gnus-article-strip-leading-blank-lines)
1699 (gnus-treat-strip-multiple-blank-lines
1700 gnus-article-strip-multiple-blank-lines)
1701 (gnus-treat-overstrike gnus-article-treat-overstrike)
1702 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1703 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1704 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1705 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1706 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1707 (gnus-treat-display-smileys gnus-treat-smiley)
1708 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1709 (gnus-treat-wash-html gnus-article-wash-html)
1710 (gnus-treat-emphasize gnus-article-emphasize)
1711 (gnus-treat-hide-citation gnus-article-hide-citation)
1712 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1713 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1714 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1716 (defvar gnus-article-mime-handle-alist nil)
1717 (defvar article-lapsed-timer nil)
1718 (defvar gnus-article-current-summary nil)
1720 (defvar gnus-article-mode-syntax-table
1721 (let ((table (copy-syntax-table text-mode-syntax-table)))
1722 ;; This causes the citation match run O(2^n).
1723 ;; (modify-syntax-entry ?- "w" table)
1724 (modify-syntax-entry ?> ")<" table)
1725 (modify-syntax-entry ?< "(>" table)
1726 ;; make M-. in article buffers work for `foo' strings
1727 (modify-syntax-entry ?' " " table)
1728 (modify-syntax-entry ?` " " table)
1730 "Syntax table used in article mode buffers.
1731 Initialized from `text-mode-syntax-table.")
1733 (defvar gnus-save-article-buffer nil)
1735 (defvar gnus-number-of-articles-to-be-saved nil)
1737 (defvar gnus-inhibit-hiding nil)
1739 (defvar gnus-article-edit-mode nil)
1741 ;;; Macros for dealing with the article buffer.
1743 (defmacro gnus-with-article-headers (&rest forms)
1744 `(with-current-buffer gnus-article-buffer
1746 (let ((inhibit-read-only t)
1747 (inhibit-point-motion-hooks t)
1748 (case-fold-search t))
1749 (article-narrow-to-head)
1752 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1753 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1755 (defmacro gnus-with-article-buffer (&rest forms)
1756 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1757 (with-current-buffer gnus-article-buffer
1758 (let ((inhibit-read-only t))
1761 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1762 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1764 (defun gnus-article-goto-header (header)
1765 "Go to HEADER, which is a regular expression."
1766 (re-search-forward (concat "^\\(" header "\\):") nil t))
1768 (defsubst gnus-article-hide-text (b e props)
1769 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1770 (gnus-add-text-properties-when 'article-type nil b e props)
1771 (when (memq 'intangible props)
1773 (max (1- b) (point-min))
1774 b 'intangible (cddr (memq 'intangible props)))))
1776 (defsubst gnus-article-unhide-text (b e)
1777 "Remove hidden text properties from region between B and E."
1778 (remove-text-properties b e gnus-hidden-properties)
1779 (when (memq 'intangible gnus-hidden-properties)
1780 (put-text-property (max (1- b) (point-min))
1781 b 'intangible nil)))
1783 (defun gnus-article-hide-text-type (b e type)
1784 "Hide text of TYPE between B and E."
1785 (gnus-add-wash-type type)
1786 (gnus-article-hide-text
1787 b e (cons 'article-type (cons type gnus-hidden-properties))))
1789 (defun gnus-article-unhide-text-type (b e type)
1790 "Unhide text of TYPE between B and E."
1791 (gnus-delete-wash-type type)
1792 (remove-text-properties
1793 b e (cons 'article-type (cons type gnus-hidden-properties)))
1794 (when (memq 'intangible gnus-hidden-properties)
1795 (put-text-property (max (1- b) (point-min))
1796 b 'intangible nil)))
1798 (defun gnus-article-hide-text-of-type (type)
1799 "Hide text of TYPE in the current buffer."
1801 (let ((b (point-min))
1803 (while (setq b (text-property-any b e 'article-type type))
1804 (add-text-properties b (incf b) gnus-hidden-properties)))))
1806 (defun gnus-article-delete-text-of-type (type)
1807 "Delete text of TYPE in the current buffer."
1809 (let ((b (point-min)))
1810 (if (eq type 'multipart)
1811 ;; Remove MIME buttons associated with multipart/alternative parts.
1814 (while (if (get-text-property (point) 'gnus-part)
1816 (when (setq b (next-single-property-change (point)
1821 (skip-chars-forward "\n")
1822 (when (eq (get-text-property b 'article-type) 'multipart)
1823 (delete-region b (point)))))
1824 (while (setq b (text-property-any b (point-max) 'article-type type))
1826 b (or (text-property-not-all b (point-max) 'article-type type)
1829 (defun gnus-article-delete-invisible-text ()
1830 "Delete all invisible text in the current buffer."
1832 (let ((b (point-min)))
1833 (while (setq b (text-property-any b (point-max) 'invisible t))
1835 b (or (text-property-not-all b (point-max) 'invisible t)
1838 (defun gnus-article-text-type-exists-p (type)
1839 "Say whether any text of type TYPE exists in the buffer."
1840 (text-property-any (point-min) (point-max) 'article-type type))
1842 (defsubst gnus-article-header-rank ()
1843 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1844 (let ((list gnus-sorted-header-list)
1847 (if (looking-at (car list))
1849 (setq list (cdr list))
1853 (defun article-hide-headers (&optional arg delete)
1854 "Hide unwanted headers and possibly sort them as well."
1856 ;; This function might be inhibited.
1857 (unless gnus-inhibit-hiding
1858 (let ((inhibit-read-only t)
1859 (case-fold-search t)
1860 (max (1+ (length gnus-sorted-header-list)))
1861 (inhibit-point-motion-hooks t)
1862 (cur (current-buffer))
1863 ignored visible beg)
1865 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1866 ;; group parameters, so we should go to the summary buffer.
1869 (progn (set-buffer gnus-summary-buffer) t)
1871 (setq ignored (when (not gnus-visible-headers)
1872 (cond ((stringp gnus-ignored-headers)
1873 gnus-ignored-headers)
1874 ((listp gnus-ignored-headers)
1875 (mapconcat 'identity
1876 gnus-ignored-headers
1878 visible (cond ((stringp gnus-visible-headers)
1879 gnus-visible-headers)
1880 ((and gnus-visible-headers
1881 (listp gnus-visible-headers))
1882 (mapconcat 'identity
1883 gnus-visible-headers
1887 ;; First we narrow to just the headers.
1888 (article-narrow-to-head)
1889 ;; Hide any "From " lines at the beginning of (mail) articles.
1890 (while (looking-at "From ")
1893 (delete-region (point-min) (point)))
1894 ;; Then treat the rest of the header lines.
1895 ;; Then we use the two regular expressions
1896 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1897 ;; select which header lines is to remain visible in the
1899 (while (re-search-forward "^[^ \t:]*:" nil t)
1901 ;; Mark the rank of the header.
1903 (point) (1+ (point)) 'message-rank
1904 (if (or (and visible (looking-at visible))
1906 (not (looking-at ignored))))
1907 (gnus-article-header-rank)
1910 (message-sort-headers-1)
1911 (when (setq beg (text-property-any
1912 (point-min) (point-max) 'message-rank (+ 2 max)))
1913 ;; We delete the unwanted headers.
1914 (gnus-add-wash-type 'headers)
1915 (add-text-properties (point-min) (+ 5 (point-min))
1916 '(article-type headers dummy-invisible t))
1917 (delete-region beg (point-max))))))))
1919 (defun article-hide-boring-headers (&optional arg)
1920 "Toggle hiding of headers that aren't very interesting.
1921 If given a negative prefix, always show; if given a positive prefix,
1923 (interactive (gnus-article-hidden-arg))
1924 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1925 (not gnus-show-all-headers))
1928 (let ((inhibit-read-only t)
1929 (inhibit-point-motion-hooks t))
1930 (article-narrow-to-head)
1931 (dolist (elem gnus-boring-article-headers)
1932 (goto-char (point-min))
1934 ;; Hide empty headers.
1936 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1938 (gnus-article-hide-text-type
1942 (if (re-search-forward "^[^ \t]" nil t)
1946 ;; Hide boring Newsgroups header.
1947 ((eq elem 'newsgroups)
1948 (when (gnus-string-equal
1949 (gnus-fetch-field "newsgroups")
1950 (gnus-group-real-name
1951 (if (boundp 'gnus-newsgroup-name)
1954 (gnus-article-hide-header "newsgroups")))
1955 ((eq elem 'to-address)
1956 (let ((to (message-fetch-field "to"))
1958 (gnus-parameter-to-address
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and to to-address
1964 ;; only one address in To
1965 (nth 1 (mail-extract-address-components to))
1967 (gnus-article-hide-header "to"))))
1969 (let ((to (message-fetch-field "to"))
1971 (gnus-parameter-to-list
1972 (if (boundp 'gnus-newsgroup-name)
1973 gnus-newsgroup-name ""))))
1974 (when (and to to-list
1977 ;; only one address in To
1978 (nth 1 (mail-extract-address-components to))
1980 (gnus-article-hide-header "to"))))
1982 (let ((cc (message-fetch-field "cc"))
1984 (gnus-parameter-to-list
1985 (if (boundp 'gnus-newsgroup-name)
1986 gnus-newsgroup-name ""))))
1987 (when (and cc to-list
1990 ;; only one address in CC
1991 (nth 1 (mail-extract-address-components cc))
1993 (gnus-article-hide-header "cc"))))
1994 ((eq elem 'followup-to)
1995 (when (gnus-string-equal
1996 (message-fetch-field "followup-to")
1997 (message-fetch-field "newsgroups"))
1998 (gnus-article-hide-header "followup-to")))
1999 ((eq elem 'reply-to)
2000 (if (gnus-group-find-parameter
2001 gnus-newsgroup-name 'broken-reply-to)
2002 (gnus-article-hide-header "reply-to")
2003 (let ((from (message-fetch-field "from"))
2004 (reply-to (message-fetch-field "reply-to")))
2011 (lambda (x) (downcase (cadr x)))
2012 (mail-extract-address-components from t))
2015 (lambda (x) (downcase (cadr x)))
2016 (mail-extract-address-components reply-to t))
2018 (gnus-article-hide-header "reply-to")))))
2020 (let ((date (with-current-buffer gnus-original-article-buffer
2021 ;; If date in `gnus-article-buffer' is localized
2022 ;; (`gnus-treat-date-user-defined'),
2023 ;; `days-between' might fail.
2024 (message-fetch-field "date"))))
2026 (< (days-between (current-time-string) date)
2028 (gnus-article-hide-header "date"))))
2030 (let ((to (message-fetch-field "to"))
2031 (cc (message-fetch-field "cc")))
2032 (when (> (length to) 1024)
2033 (gnus-article-hide-header "to"))
2034 (when (> (length cc) 1024)
2035 (gnus-article-hide-header "cc"))))
2039 (goto-char (point-min))
2040 (while (re-search-forward "^to:" nil t)
2041 (setq to-count (1+ to-count)))
2042 (when (> to-count 1)
2043 (while (> to-count 0)
2044 (goto-char (point-min))
2046 (re-search-forward "^to:" nil nil to-count)
2048 (narrow-to-region (point) (point-max))
2049 (gnus-article-hide-header "to"))
2050 (setq to-count (1- to-count))))
2051 (goto-char (point-min))
2052 (while (re-search-forward "^cc:" nil t)
2053 (setq cc-count (1+ cc-count)))
2054 (when (> cc-count 1)
2055 (while (> cc-count 0)
2056 (goto-char (point-min))
2058 (re-search-forward "^cc:" nil nil cc-count)
2060 (narrow-to-region (point) (point-max))
2061 (gnus-article-hide-header "cc"))
2062 (setq cc-count (1- cc-count)))))))))))))
2064 (defun gnus-article-hide-header (header)
2066 (goto-char (point-min))
2067 (when (re-search-forward (concat "^" header ":") nil t)
2068 (gnus-article-hide-text-type
2072 (if (re-search-forward "^[^ \t]" nil t)
2077 (defvar gnus-article-normalized-header-length 40
2078 "Length of normalized headers.")
2080 (defun article-normalize-headers ()
2081 "Make all header lines 40 characters long."
2083 (let ((inhibit-read-only t)
2087 (article-narrow-to-head)
2090 ((< (setq column (- (point-at-eol) (point)))
2091 gnus-article-normalized-header-length)
2093 (insert (make-string
2094 (- gnus-article-normalized-header-length column)
2096 ((> column gnus-article-normalized-header-length)
2097 (gnus-put-text-property
2099 (forward-char gnus-article-normalized-header-length)
2106 (forward-line 1))))))
2108 (defun article-treat-dumbquotes ()
2109 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2110 Note that this function guesses whether a character is a sm*rtq**t* or
2111 not, so it should only be used interactively.
2113 Sm*rtq**t*s are M****s***'s unilateral extension to the
2114 iso-8859-1 character map in an attempt to provide more quoting
2115 characters. If you see something like \\222 or \\264 where
2116 you're expecting some kind of apostrophe or quotation mark, then
2119 (article-translate-strings gnus-article-dumbquotes-map))
2121 (defvar org-entities)
2123 (defun article-treat-non-ascii ()
2124 "Translate many Unicode characters into their ASCII equivalents."
2126 (require 'org-entities)
2127 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2128 (dolist (elem org-entities)
2129 (when (and (listp elem)
2130 (= (length (nth 6 elem)) 1))
2131 (if (featurep 'xemacs)
2132 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2133 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2135 (when (article-goto-body)
2136 (let ((inhibit-read-only t)
2139 (if (not (setq replace (if (featurep 'xemacs)
2140 (get-char-table (following-char) table)
2141 (aref table (following-char)))))
2144 (setq props (text-properties-at (point)))
2146 (add-text-properties (point) (progn (insert replace) (point))
2148 (insert replace)))))))))
2150 (defun article-translate-characters (from to)
2151 "Translate all characters in the body of the article according to FROM and TO.
2152 FROM is a string of characters to translate from; to is a string of
2153 characters to translate to."
2155 (when (article-goto-body)
2156 (let ((inhibit-read-only t)
2157 (x (make-string 225 ?x))
2159 (while (< (incf i) (length x))
2162 (while (< i (length from))
2163 (aset x (aref from i) (aref to i))
2165 (translate-region (point) (point-max) x)))))
2167 (defun article-translate-strings (map)
2168 "Translate all string in the body of the article according to MAP.
2169 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2171 (when (article-goto-body)
2172 (let ((inhibit-read-only t))
2174 (let ((from (car elem))
2178 (while (search-forward from nil t)
2181 (if (eq (following-char) from)
2185 (forward-char 1)))))))))))
2187 (defun article-treat-overstrike ()
2188 "Translate overstrikes into bold text."
2191 (when (article-goto-body)
2192 (let ((inhibit-read-only t))
2193 (while (search-forward "\b" nil t)
2194 (let ((next (char-after))
2195 (previous (char-after (- (point) 2))))
2196 ;; We do the boldification/underlining by hiding the
2197 ;; overstrikes and putting the proper text property
2201 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2202 (put-text-property (point) (1+ (point)) 'face 'bold))
2204 (gnus-article-hide-text-type
2205 (1- (point)) (1+ (point)) 'overstrike)
2207 (- (point) 2) (1- (point)) 'face 'underline))
2209 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2211 (point) (1+ (point)) 'face 'underline)))))))))
2213 (defun article-treat-ansi-sequences ()
2214 "Translate ANSI SGR control sequences into overlays or extents."
2217 (when (article-goto-body)
2218 (let ((inhibit-read-only t))
2219 (ansi-color-apply-on-region (point) (point-max))))))
2221 (defun gnus-article-treat-unfold-headers ()
2222 "Unfold folded message headers.
2223 Only the headers that fit into the current window width will be
2226 (gnus-with-article-headers
2230 (mail-header-narrow-to-field)
2231 (let* ((header (buffer-string))
2233 (or (equal gnus-article-unfold-long-headers t)
2234 (and (stringp gnus-article-unfold-long-headers)
2235 (string-match gnus-article-unfold-long-headers header)))))
2238 (goto-char (point-min))
2239 (while (re-search-forward "\n[\t ]" nil t)
2240 (replace-match " " t t)))
2241 (setq length (- (point-max) (point-min) 1))
2242 (when (or unfoldable
2243 (< length (window-width)))
2244 (while (re-search-forward "\n[\t ]" nil t)
2245 (replace-match " " t t))))
2246 (goto-char (point-max)))))))
2248 (defun gnus-article-treat-fold-headers ()
2249 "Fold message headers."
2251 (gnus-with-article-headers
2254 (mail-header-narrow-to-field)
2255 (mail-header-fold-field)
2256 (goto-char (point-max))))))
2258 (defun gnus-treat-smiley ()
2259 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2261 (gnus-with-article-buffer
2262 (if (memq 'smiley gnus-article-wash-types)
2263 (gnus-delete-images 'smiley)
2265 (let ((images (smiley-region (point) (point-max))))
2267 (gnus-add-wash-type 'smiley)
2268 (dolist (image images)
2269 (gnus-add-image 'smiley image)))))))
2271 (defun gnus-article-remove-images ()
2272 "Remove all images from the article buffer."
2274 (gnus-with-article-buffer
2277 (dolist (elem gnus-article-image-alist)
2278 (gnus-delete-images (car elem))))))
2280 (autoload 'w3m-toggle-inline-images "w3m")
2282 (defun gnus-article-show-images ()
2283 "Show any images that are in the HTML-rendered article buffer.
2284 This only works if the article in question is HTML."
2286 (gnus-with-article-buffer
2289 (if (eq mm-text-html-renderer 'w3m)
2290 (let ((mm-inline-text-html-with-images nil))
2291 (w3m-toggle-inline-images))
2292 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2294 (destructuring-bind (start end function) region
2295 (funcall function (get-text-property start 'image-url)
2298 (defun gnus-article-treat-fold-newsgroups ()
2299 "Unfold folded message headers.
2300 Only the headers that fit into the current window width will be
2303 (gnus-with-article-headers
2304 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2306 (mail-header-narrow-to-field)
2307 (while (re-search-forward ", *" nil t)
2308 (replace-match ", " t t))
2309 (mail-header-fold-field)
2310 (goto-char (point-max))))))
2312 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2313 "Value of `truncate-lines' in Gnus Article buffer.
2314 Valid values are nil, t, `head', `first', `last', an integer or a
2315 predicate. See Info node `(gnus)Customizing Articles'."
2316 :version "23.1" ;; No Gnus
2317 :group 'gnus-article
2318 ;; :link '(custom-manual "(gnus)Customizing Articles")
2321 (defun gnus-article-toggle-truncate-lines (&optional arg)
2322 "Toggle whether to fold or truncate long lines in article the buffer.
2323 If ARG is non-nil and not a number, toggle
2324 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2325 long lines if and only if arg is positive."
2328 ((and (numberp arg) (> arg 0))
2329 (setq gnus-article-truncate-lines t))
2331 (setq gnus-article-truncate-lines nil))
2333 (setq gnus-article-truncate-lines
2334 (not gnus-article-truncate-lines))))
2335 (gnus-with-article-buffer
2337 ((and (numberp arg) (> arg 0))
2338 (setq truncate-lines nil))
2340 (setq truncate-lines t)))
2341 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2342 ;; `toggle-truncate-lines' needs an argument.
2343 (toggle-truncate-lines)))
2345 (defun gnus-article-treat-body-boundary ()
2346 "Place a boundary line at the end of the headers."
2348 (when (and gnus-body-boundary-delimiter
2349 (> (length gnus-body-boundary-delimiter) 0))
2350 (gnus-with-article-headers
2351 (goto-char (point-max))
2352 (let ((start (point)))
2353 (insert "X-Boundary: ")
2354 (gnus-add-text-properties start (point) '(invisible t intangible t))
2355 (insert (let (str (max (window-width)))
2356 (if (featurep 'xemacs)
2357 (setq max (1- max)))
2358 (while (>= max (length str))
2359 (setq str (concat str gnus-body-boundary-delimiter)))
2360 (substring str 0 max))
2362 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2364 (defun article-fill-long-lines ()
2365 "Fill lines that are wider than the window width."
2368 (let ((inhibit-read-only t)
2369 (width (window-width (get-buffer-window (current-buffer)))))
2372 (let ((adaptive-fill-mode nil)) ;Why? -sm
2375 (when (>= (current-column) (min fill-column width))
2376 (narrow-to-region (min (1+ (point)) (point-max))
2378 (let ((goback (point-marker)))
2379 (fill-paragraph nil)
2380 (goto-char (marker-position goback)))
2382 (forward-line 1)))))))
2384 (defun article-capitalize-sentences ()
2385 "Capitalize the first word in each sentence."
2388 (let ((inhibit-read-only t)
2389 (paragraph-start "^[\n\^L]"))
2393 (forward-sentence)))))
2395 (defun article-remove-cr ()
2396 "Remove trailing CRs and then translate remaining CRs into LFs."
2399 (let ((inhibit-read-only t))
2400 (goto-char (point-min))
2401 (while (re-search-forward "\r+$" nil t)
2402 (replace-match "" t t))
2403 (goto-char (point-min))
2404 (while (search-forward "\r" nil t)
2405 (replace-match "\n" t t)))))
2407 (defun article-remove-trailing-blank-lines ()
2408 "Remove all trailing blank lines from the article."
2411 (let ((inhibit-read-only t))
2412 (goto-char (point-max))
2416 (while (and (not (bobp))
2417 (looking-at "^[ \t]*$")
2418 (not (gnus-annotation-in-region-p
2419 (point) (point-at-eol))))
2424 (defvar gnus-face-properties-alist)
2426 (defun article-display-face (&optional force)
2427 "Display any Face headers in the header."
2428 (interactive (list 'force))
2429 (let ((wash-face-p buffer-read-only))
2430 (gnus-with-article-headers
2431 ;; When displaying parts, this function can be called several times on
2432 ;; the same article, without any intended toggle semantic (as typing `W
2433 ;; D d' would have). So face deletion must occur only when we come from
2434 ;; an interactive command, that is when the *Article* buffer is
2436 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2437 (gnus-delete-images 'face)
2438 (let ((from (message-fetch-field "from"))
2440 (save-current-buffer
2441 (when (and wash-face-p
2442 (gnus-buffer-live-p gnus-original-article-buffer)
2443 (not (re-search-forward "^Face:[\t ]*" nil t)))
2444 (set-buffer gnus-original-article-buffer))
2446 (mail-narrow-to-head)
2448 ;; Check whether this face is censored.
2449 (not (and gnus-article-x-face-too-ugly
2451 (setq from (message-fetch-field "from")))
2452 (string-match gnus-article-x-face-too-ugly
2454 (while (gnus-article-goto-header "Face")
2455 (push (mail-header-field-value) faces)))))
2457 (goto-char (point-min))
2459 (unless (setq from (gnus-article-goto-header "from"))
2462 (insert " [no `from' set]\n"))
2464 (when (setq png (gnus-convert-face-to-png (pop faces)))
2466 (apply 'gnus-create-image png 'png t
2467 (cdr (assq 'png gnus-face-properties-alist))))
2469 (gnus-add-wash-type 'face)
2470 (gnus-add-image 'face image)
2471 (gnus-put-image image nil 'face))))))))))
2473 (defun article-display-x-face (&optional force)
2474 "Look for an X-Face header and display it if present."
2475 (interactive (list 'force))
2476 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2477 (gnus-with-article-headers
2478 ;; Delete the old process, if any.
2479 (when (process-status "article-x-face")
2480 (delete-process "article-x-face"))
2481 ;; See the comment in `article-display-face'.
2482 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2483 ;; We have already displayed X-Faces, so we remove them
2485 (gnus-delete-images 'xface)
2487 (let ((from (message-fetch-field "from"))
2489 (save-current-buffer
2490 (when (and wash-face-p
2491 (gnus-buffer-live-p gnus-original-article-buffer)
2492 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2493 ;; If type `W f', use gnus-original-article-buffer,
2494 ;; otherwise use the current buffer because displaying
2495 ;; RFC822 parts calls this function too.
2496 (set-buffer gnus-original-article-buffer))
2498 (mail-narrow-to-head)
2499 (and gnus-article-x-face-command
2501 ;; Check whether this face is censored.
2502 (not (and gnus-article-x-face-too-ugly
2504 (setq from (message-fetch-field "from")))
2505 (string-match gnus-article-x-face-too-ugly
2507 (while (gnus-article-goto-header "X-Face")
2508 (push (mail-header-field-value) x-faces)))))
2510 ;; We display the face.
2511 (cond ((functionp gnus-article-x-face-command)
2512 ;; The command is a lisp function, so we call it.
2513 (mapc gnus-article-x-face-command x-faces))
2514 ((stringp gnus-article-x-face-command)
2515 ;; The command is a string, so we interpret the command
2516 ;; as a, well, command, and fork it off.
2517 (let ((process-connection-type nil))
2518 (gnus-set-process-query-on-exit-flag
2520 "article-x-face" nil shell-file-name
2521 shell-command-switch gnus-article-x-face-command)
2523 ;; Sending multiple EOFs to xv doesn't work,
2524 ;; so we only do a single external face.
2526 (insert (car x-faces))
2527 (process-send-region "article-x-face"
2528 (point-min) (point-max)))
2529 (process-send-eof "article-x-face")))
2531 (error "`%s' set to `%s' is not a function"
2532 gnus-article-x-face-command
2533 'gnus-article-x-face-command)))))))))
2535 (defun article-decode-mime-words ()
2536 "Decode all MIME-encoded words in the article."
2538 (gnus-with-article-buffer
2539 (let ((inhibit-point-motion-hooks t)
2540 (mail-parse-charset gnus-newsgroup-charset)
2541 (mail-parse-ignored-charsets
2542 (with-current-buffer gnus-summary-buffer
2543 gnus-newsgroup-ignored-charsets)))
2544 (mail-decode-encoded-word-region (point-min) (point-max)))))
2546 (defun article-decode-charset (&optional prompt)
2547 "Decode charset-encoded text in the article.
2548 If PROMPT (the prefix), prompt for a coding system to use."
2550 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2551 (inhibit-read-only t)
2552 (mail-parse-charset gnus-newsgroup-charset)
2553 (mail-parse-ignored-charsets
2554 (save-excursion (condition-case nil
2555 (set-buffer gnus-summary-buffer)
2557 gnus-newsgroup-ignored-charsets))
2558 ct cte ctl charset format)
2561 (article-narrow-to-head)
2562 (setq ct (message-fetch-field "Content-Type" t)
2563 cte (message-fetch-field "Content-Transfer-Encoding" t)
2564 ctl (and ct (mail-header-parse-content-type ct))
2567 (mm-read-coding-system "Charset to decode: "))
2569 (mail-content-type-get ctl 'charset)))
2570 format (and ctl (mail-content-type-get ctl 'format)))
2572 (setq cte (mail-header-strip cte)))
2573 (if (and ctl (not (string-match "/" (car ctl))))
2575 (goto-char (point-max)))
2578 (narrow-to-region (point) (point-max))
2579 (when (and (eq mail-parse-charset 'gnus-decoded)
2580 (eq (mm-body-7-or-8) '8bit))
2581 ;; The text code could have been decoded.
2582 (setq charset mail-parse-charset))
2583 (when (and (or (not ctl)
2584 (equal (car ctl) "text/plain"))
2585 (not format)) ;; article with format will decode later.
2587 charset (and cte (intern (downcase
2588 (gnus-strip-whitespace cte))))
2591 (defun article-decode-encoded-words ()
2592 "Remove encoded-word encoding from headers."
2593 (let ((inhibit-point-motion-hooks t)
2594 (mail-parse-charset gnus-newsgroup-charset)
2595 (mail-parse-ignored-charsets
2596 (save-excursion (condition-case nil
2597 (set-buffer gnus-summary-buffer)
2599 gnus-newsgroup-ignored-charsets))
2600 (inhibit-read-only t)
2602 (goto-char (point-min))
2603 (when (search-forward "\n\n" nil 'move)
2610 (memq (char-after) '(?\t ? )))))
2611 (setq start (point))
2613 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2614 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2615 (funcall gnus-decode-address-function start end)
2616 (funcall gnus-decode-header-function start end))
2617 (goto-char (setq end start)))))
2619 (defun article-decode-group-name ()
2620 "Decode group names in Newsgroups, Followup-To and Xref headers."
2621 (let ((inhibit-point-motion-hooks t)
2622 (inhibit-read-only t)
2623 (method (gnus-find-method-for-group gnus-newsgroup-name))
2625 (when (and (or gnus-group-name-charset-method-alist
2626 gnus-group-name-charset-group-alist)
2627 (gnus-buffer-live-p gnus-original-article-buffer))
2629 (article-narrow-to-head)
2630 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2631 (with-current-buffer gnus-original-article-buffer
2632 (goto-char (point-min)))
2633 (setq regexp (concat "^" header
2634 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2635 (while (re-search-forward regexp nil t)
2636 (replace-match (save-match-data
2637 (gnus-decode-newsgroups
2638 ;; XXX how to use data in article buffer?
2639 (with-current-buffer gnus-original-article-buffer
2640 (re-search-forward regexp nil t)
2642 gnus-newsgroup-name method))
2644 (goto-char (point-min)))))))
2646 (autoload 'idna-to-unicode "idna")
2648 (defun article-decode-idna-rhs ()
2649 "Decode IDNA strings in RHS in various headers in current buffer.
2650 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2651 Mail-Reply-To: and Mail-Followup-To:."
2654 (let ((inhibit-point-motion-hooks t)
2655 (inhibit-read-only t))
2656 (article-narrow-to-head)
2657 (goto-char (point-min))
2658 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2660 (when (save-match-data
2661 (and (setq ace (match-string 1))
2663 (and (re-search-backward "^[^ \t]" nil t)
2664 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2665 (setq unicode (idna-to-unicode ace))))
2666 (unless (string= ace unicode)
2667 (replace-match unicode nil nil nil 1)))))))))
2669 (defun article-de-quoted-unreadable (&optional force read-charset)
2670 "Translate a quoted-printable-encoded article.
2671 If FORCE, decode the article whether it is marked as quoted-printable
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 "quoted-printable" type))))
2695 (quoted-printable-decode-region
2696 (point) (point-max) (mm-charset-to-coding-system charset))))))
2698 (defun article-de-base64-unreadable (&optional force read-charset)
2699 "Translate a base64 article.
2700 If FORCE, decode the article whether it is marked as base64 not.
2701 If READ-CHARSET, ask for a coding system."
2702 (interactive (list 'force current-prefix-arg))
2704 (let ((inhibit-read-only t) type charset)
2705 (if (gnus-buffer-live-p gnus-original-article-buffer)
2706 (with-current-buffer gnus-original-article-buffer
2708 (gnus-fetch-field "content-transfer-encoding"))
2709 (let* ((ct (gnus-fetch-field "content-type"))
2710 (ctl (and ct (mail-header-parse-content-type ct))))
2711 (setq charset (and ctl
2712 (mail-content-type-get ctl 'charset)))
2713 (if (stringp charset)
2714 (setq charset (intern (downcase charset)))))))
2716 (setq charset (mm-read-coding-system "Charset: " charset)))
2718 (setq charset gnus-newsgroup-charset))
2720 (and type (let ((case-fold-search t))
2721 (string-match "base64" type))))
2724 (narrow-to-region (point) (point-max))
2725 (base64-decode-region (point-min) (point-max))
2726 (mm-decode-coding-region
2727 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2732 (defun article-decode-HZ ()
2733 "Translate a HZ-encoded article."
2737 (let ((inhibit-read-only t))
2738 (rfc1843-decode-region (point-min) (point-max)))))
2740 (defun article-unsplit-urls ()
2741 "Remove the newlines that some other mailers insert into URLs."
2744 (let ((inhibit-read-only t))
2745 (goto-char (point-min))
2746 (while (re-search-forward
2747 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2748 (replace-match "\\1\\3" t)))
2749 (when (interactive-p)
2750 (gnus-treat-article nil))))
2752 (defun article-wash-html ()
2753 "Format an HTML article."
2756 (buffer-read-only nil))
2757 (when (gnus-buffer-live-p gnus-original-article-buffer)
2758 (setq handles (mm-dissect-buffer t t)))
2760 (delete-region (point) (point-max))
2761 (mm-inline-text-html handles)))
2763 (defvar gnus-article-browse-html-temp-list nil
2764 "List of temporary files created by `gnus-article-browse-html-parts'.
2765 Internal variable.")
2767 (defcustom gnus-article-browse-delete-temp 'ask
2768 "What to do with temporary files from `gnus-article-browse-html-parts'.
2769 If nil, don't delete temporary files. If it is t, delete them on
2770 exit from the summary buffer. If it is the symbol `file', query
2771 on each file, if it is `ask' ask once when exiting from the
2773 :group 'gnus-article
2774 :version "23.1" ;; No Gnus
2775 :type '(choice (const :tag "Don't delete" nil)
2776 (const :tag "Don't ask" t)
2777 (const :tag "Ask" ask)
2778 (const :tag "Ask for each file" file)))
2780 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2782 (defun gnus-article-browse-delete-temp-files (&optional how)
2783 "Delete temp-files created by `gnus-article-browse-html-parts'."
2784 (when (and gnus-article-browse-html-temp-list
2786 (or how (setq how gnus-article-browse-delete-temp))
2788 (let ((files (length gnus-article-browse-html-temp-list)))
2791 "Delete the temporary HTML file? "
2792 (format "Delete all %s temporary HTML files? "
2795 (dolist (file gnus-article-browse-html-temp-list)
2796 (cond ((file-directory-p file)
2797 (when (or (not (eq how 'file))
2800 "Delete temporary HTML file(s) in directory `%s'? "
2801 (file-name-as-directory file))))
2802 (gnus-delete-directory file)))
2803 ((file-exists-p file)
2804 (when (or (not (eq how 'file))
2806 (format "Delete temporary HTML file `%s'? " file)))
2807 (delete-file file)))))
2808 ;; Also remove file from the list when not deleted or if file doesn't
2810 (setq gnus-article-browse-html-temp-list nil))
2811 gnus-article-browse-html-temp-list)
2813 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2814 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2819 (dolist (handle handles)
2821 ((not (listp handle)))
2822 ((equal (mm-handle-media-supertype handle) "multipart")
2823 (when (setq file (gnus-article-browse-html-save-cid-content
2824 cid handle directory))
2825 (throw 'found file)))
2826 ((equal (concat "<" cid ">") (mm-handle-id handle))
2829 (or (mm-handle-filename handle)
2831 (make-temp-name "cid")
2832 (car (rassoc (car (mm-handle-type handle)) mailcap-mime-extensions))))
2834 (mm-save-part-to-file handle file)
2835 (throw 'found file))))))))
2837 (defun gnus-article-browse-html-parts (list &optional header)
2838 "View all \"text/html\" parts from LIST.
2839 Recurse into multiparts. The optional HEADER that should be a decoded
2840 message header will be added to the bodies of the \"text/html\" parts."
2841 ;; Internal function used by `gnus-article-browse-html-article'.
2842 (let (type file charset content cid-dir tmp-file showed)
2843 ;; Find and show the html-parts.
2844 (dolist (handle list)
2845 ;; If HTML, show it:
2846 (cond ((not (listp handle)))
2847 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2848 (and (equal (car type) "message/external-body")
2850 (setq file (mm-handle-filename handle)))
2851 (or (mm-handle-cache handle)
2852 (condition-case code
2853 (progn (mm-extern-cache-contents handle) t)
2855 (gnus-message 3 "%s" (error-message-string code))
2856 (when (>= gnus-verbose 3) (sit-for 2))
2859 (setq handle (mm-handle-cache handle)
2860 type (mm-handle-type handle))
2861 (equal (car type) "text/html"))))
2862 (setq charset (mail-content-type-get type 'charset)
2863 content (mm-get-part handle))
2865 (if (eq charset 'gnus-decoded)
2866 (mm-enable-multibyte)
2867 (mm-disable-multibyte))
2869 ;; resolve cid contents
2870 (let ((case-fold-search t)
2872 (goto-char (point-min))
2873 (while (re-search-forward "\
2874 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2877 (setq cid-dir (mm-make-temp-file "cid" t))
2878 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2881 (when (setq cid-file
2882 (gnus-article-browse-html-save-cid-content
2884 (with-current-buffer gnus-article-buffer
2885 gnus-article-mime-handles)
2887 (when (eq system-type 'cygwin)
2889 (concat "/" (substring
2890 (with-output-to-string
2891 (call-process "cygpath" nil
2895 (replace-match (concat "file://" cid-file)
2897 (unless content (setq content (buffer-string))))
2898 (when (or charset header (not file))
2899 (setq tmp-file (mm-make-temp-file
2900 ;; Do we need to care for 8.3 filenames?
2901 "mm-" nil ".html")))
2902 ;; Add a meta html tag to specify charset and a header.
2905 (let (title eheader body hcharset coding force-charset)
2907 (mm-enable-multibyte)
2908 (setq case-fold-search t)
2909 (insert header "\n")
2910 (setq title (message-fetch-field "subject"))
2911 (goto-char (point-min))
2912 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2913 (replace-match (cond ((match-beginning 1) "<")
2914 ((match-beginning 2) ">")
2916 (goto-char (point-min))
2918 (goto-char (point-max))
2919 (insert "</pre>\n<hr>\n")
2920 ;; We have to examine charset one by one since
2921 ;; charset specified in parts might be different.
2922 (if (eq charset 'gnus-decoded)
2923 (setq charset 'utf-8
2924 eheader (mm-encode-coding-string (buffer-string)
2927 (mm-encode-coding-string title charset))
2928 body (mm-encode-coding-string content charset)
2930 (setq hcharset (mm-find-mime-charset-region (point-min)
2932 (cond ((= (length hcharset) 1)
2933 (setq hcharset (car hcharset)
2934 coding (mm-charset-to-coding-system
2936 ((> (length hcharset) 1)
2937 (setq hcharset 'utf-8
2943 (mm-charset-to-coding-system charset))
2944 (if (eq coding body)
2945 (setq eheader (mm-encode-coding-string
2946 (buffer-string) coding)
2948 (mm-encode-coding-string
2951 (setq charset 'utf-8
2952 eheader (mm-encode-coding-string
2953 (buffer-string) charset)
2955 (mm-encode-coding-string
2957 body (mm-encode-coding-string
2958 (mm-decode-coding-string
2962 (setq charset hcharset
2963 eheader (mm-encode-coding-string
2964 (buffer-string) coding)
2966 (mm-encode-coding-string
2969 (setq eheader (mm-string-as-unibyte (buffer-string))
2972 (mm-disable-multibyte)
2975 (mm-add-meta-html-tag handle charset force-charset))
2977 (goto-char (point-min))
2978 (unless (search-forward "<title>" nil t)
2979 (re-search-forward "<head>\\s-*" nil t)
2980 (insert "<title>" title "</title>\n")))
2981 (goto-char (point-min))
2982 (or (re-search-forward
2983 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2985 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2987 (mm-write-region (point-min) (point-max)
2988 tmp-file nil nil nil 'binary t))))
2990 (mm-with-unibyte-buffer
2991 (insert (if (eq charset 'gnus-decoded)
2992 (mm-encode-coding-string content
2993 (setq charset 'utf-8))
2995 (if (or (mm-add-meta-html-tag handle charset)
2997 (mm-write-region (point-min) (point-max)
2998 tmp-file nil nil nil 'binary t)
2999 (setq tmp-file nil))))
3001 (mm-save-part-to-file handle tmp-file)))
3003 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3004 (add-hook 'gnus-summary-prepare-exit-hook
3005 'gnus-article-browse-delete-temp-files)
3006 (add-hook 'gnus-exit-gnus-hook
3008 (gnus-article-browse-delete-temp-files t)))
3009 ;; FIXME: Warn if there's an <img> tag?
3010 (browse-url-of-file (or tmp-file (expand-file-name file)))
3012 ;; If multipart, recurse
3013 ((equal (mm-handle-media-supertype handle) "multipart")
3014 (when (gnus-article-browse-html-parts handle header)
3016 ((equal (mm-handle-media-type handle) "message/rfc822")
3017 (mm-with-multibyte-buffer
3018 (mm-insert-part handle)
3019 (setq handle (mm-dissect-buffer t t))
3020 (when (and (bufferp (car handle))
3021 (stringp (car (mm-handle-type handle))))
3022 (setq handle (list handle)))
3024 (article-decode-encoded-words)
3025 (let ((gnus-visible-headers
3026 (or (get 'gnus-visible-headers 'standard-value)
3027 gnus-visible-headers)))
3028 (article-hide-headers))
3029 (goto-char (point-min))
3030 (search-forward "\n\n" nil 'move)
3031 (skip-chars-backward "\t\n ")
3032 (setq header (buffer-substring (point-min) (point)))))
3034 (gnus-article-browse-html-parts handle header)
3035 (mm-destroy-parts handle))
3039 (defun gnus-article-browse-html-article (&optional arg)
3040 "View \"text/html\" parts of the current article with a WWW browser.
3041 Inline images embedded in a message using the cid scheme, as they are
3042 generally considered to be safe, will be processed properly.
3043 The message header is added to the beginning of every html part unless
3044 the prefix argument ARG is given.
3046 Warning: Spammers use links to images (using the http scheme) in HTML
3047 articles to verify whether you have read the message. As
3048 `gnus-article-browse-html-article' passes the HTML content to the
3049 browser without eliminating these \"web bugs\" you should only
3050 use it for mails from trusted senders.
3052 If you always want to display HTML parts in the browser, set
3053 `mm-text-html-renderer' to nil.
3055 This command creates temporary files to pass HTML contents including
3056 images if any to the browser, and deletes them when exiting the group
3058 ;; Cf. `mm-w3m-safe-url-regexp'
3061 (gnus-summary-show-article)
3062 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3063 gnus-visible-headers))
3064 ;; As we insert a <hr>, there's no need for the body boundary.
3065 (gnus-treat-body-boundary nil))
3066 (gnus-summary-show-article)))
3067 (with-current-buffer gnus-article-buffer
3068 (let ((header (unless arg
3071 (buffer-substring-no-properties
3072 (goto-char (point-min))
3073 (if (search-forward "\n\n" nil t)
3075 (goto-char (point-max))
3076 (skip-chars-backward "\t\n ")
3079 (set-buffer gnus-original-article-buffer)
3080 (setq parts (mm-dissect-buffer t t))
3081 ;; If singlepart, enforce a list.
3082 (when (and (bufferp (car parts))
3083 (stringp (car (mm-handle-type parts))))
3084 (setq parts (list parts)))
3086 (unless (gnus-article-browse-html-parts parts header)
3087 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3088 (mm-destroy-parts parts)
3090 (gnus-summary-show-article)))))
3092 (defun article-hide-list-identifiers ()
3093 "Remove list identifies from the Subject header.
3094 The `gnus-list-identifiers' variable specifies what to do."
3096 (let ((inhibit-point-motion-hooks t)
3097 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3098 (inhibit-read-only t))
3102 (article-narrow-to-head)
3103 (goto-char (point-min))
3104 (while (re-search-forward
3105 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3107 (delete-region (match-beginning 2) (match-end 0))
3108 (beginning-of-line))
3109 (when (re-search-forward
3110 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3111 (delete-region (match-beginning 1) (match-end 1))))))))
3113 (defun article-hide-pem (&optional arg)
3114 "Toggle hiding of any PEM headers and signatures in the current article.
3115 If given a negative prefix, always show; if given a positive prefix,
3117 (interactive (gnus-article-hidden-arg))
3118 (unless (gnus-article-check-hidden-text 'pem arg)
3120 (let ((inhibit-read-only t) end)
3121 (goto-char (point-min))
3122 ;; Hide the horrendously ugly "header".
3123 (when (and (search-forward
3124 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3126 (setq end (1+ (match-beginning 0))))
3127 (gnus-add-wash-type 'pem)
3128 (gnus-article-hide-text-type
3130 (if (search-forward "\n\n" nil t)
3134 ;; Hide the trailer as well
3135 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3137 (gnus-article-hide-text-type
3138 (match-beginning 0) (match-end 0) 'pem)))))))
3140 (defun article-strip-banner ()
3141 "Strip the banners specified by the `banner' group parameter and by
3142 `gnus-article-address-banner-alist'."
3146 (let ((inhibit-point-motion-hooks t))
3147 (when (gnus-parameter-banner gnus-newsgroup-name)
3148 (article-really-strip-banner
3149 (gnus-parameter-banner gnus-newsgroup-name)))
3150 (when gnus-article-address-banner-alist
3151 ;; Note that the From header is decoded here, so it is
3152 ;; required that the *-extract-address-components function
3153 ;; supports non-ASCII text.
3154 (let ((from (save-restriction
3156 (article-narrow-to-head)
3157 (mail-fetch-field "from"))))
3160 (cadr (funcall gnus-extract-address-components
3163 (dolist (pair gnus-article-address-banner-alist)
3164 (when (string-match (car pair) from)
3166 (article-really-strip-banner (cdr pair)))))))))))))
3168 (defun article-really-strip-banner (banner)
3169 "Strip the banner specified by the argument."
3172 (let ((inhibit-point-motion-hooks t)
3173 (gnus-signature-limit nil)
3174 (inhibit-read-only t))
3177 ((eq banner 'signature)
3178 (when (gnus-article-narrow-to-signature)
3181 (delete-region (point) (point-max))))
3183 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3184 (while (re-search-forward banner nil t)
3185 (delete-region (match-beginning 0) (match-end 0)))))
3187 (while (re-search-forward banner nil t)
3188 (delete-region (match-beginning 0) (match-end 0)))))))))
3190 (defun article-babel ()
3191 "Translate article using an online translation service."
3194 (gnus-with-article-buffer
3195 (when (article-goto-body)
3196 (let* ((start (point))
3198 (orig (buffer-substring start end))
3199 (trans (babel-as-string orig)))
3201 (narrow-to-region start end)
3202 (delete-region start end)
3205 (defun article-hide-signature (&optional arg)
3206 "Hide the signature in the current article.
3207 If given a negative prefix, always show; if given a positive prefix,
3209 (interactive (gnus-article-hidden-arg))
3210 (unless (gnus-article-check-hidden-text 'signature arg)
3213 (let ((inhibit-read-only t))
3214 (when (gnus-article-narrow-to-signature)
3215 (gnus-article-hide-text-type
3216 (point-min) (point-max) 'signature))))))
3217 (gnus-set-mode-line 'article))
3219 (defun article-strip-headers-in-body ()
3220 "Strip offensive headers from bodies."
3224 (let ((case-fold-search t))
3225 (when (looking-at "x-no-archive:")
3226 (gnus-delete-line)))))
3228 (defun article-strip-leading-blank-lines ()
3229 "Remove all blank lines from the beginning of the article."
3232 (let ((inhibit-point-motion-hooks t)
3233 (inhibit-read-only t))
3234 (when (article-goto-body)
3235 (while (and (not (eobp))
3236 (looking-at "[ \t]*$"))
3237 (gnus-delete-line))))))
3239 (defun article-narrow-to-head ()
3240 "Narrow the buffer to the head of the message.
3241 Point is left at the beginning of the narrowed-to region."
3243 (goto-char (point-min))
3245 ;; Absolutely no headers displayed.
3249 ((search-forward "\n\n" nil 1)
3251 ;; Nothing but headers.
3254 (goto-char (point-min)))
3256 (defun article-goto-body ()
3257 "Place point at the start of the body."
3258 (goto-char (point-min))
3260 ;; This variable is only bound when dealing with separate
3262 (article-goto-body-goes-to-point-min-p
3264 ((search-forward "\n\n" nil t)
3267 (goto-char (point-max))
3270 (defun article-strip-multiple-blank-lines ()
3271 "Replace consecutive blank lines with one empty line."
3274 (let ((inhibit-point-motion-hooks t)
3275 (inhibit-read-only t))
3276 ;; First make all blank lines empty.
3278 (while (re-search-forward "^[ \t]+$" nil t)
3279 (unless (gnus-annotation-in-region-p
3280 (match-beginning 0) (match-end 0))
3281 (replace-match "" nil t)))
3282 ;; Then replace multiple empty lines with a single empty line.
3284 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3285 (unless (gnus-annotation-in-region-p
3286 (match-beginning 0) (match-end 0))
3287 (delete-region (match-beginning 1) (match-end 1)))))))
3289 (defun article-strip-leading-space ()
3290 "Remove all white space from the beginning of the lines in the article."
3293 (let ((inhibit-point-motion-hooks t)
3294 (inhibit-read-only t))
3296 (while (re-search-forward "^[ \t]+" nil t)
3297 (replace-match "" t t)))))
3299 (defun article-strip-trailing-space ()
3300 "Remove all white space from the end of the lines in the article."
3303 (let ((inhibit-point-motion-hooks t)
3304 (inhibit-read-only t))
3306 (while (re-search-forward "[ \t]+$" nil t)
3307 (replace-match "" t t)))))
3309 (defun article-strip-blank-lines ()
3310 "Strip leading, trailing and multiple blank lines."
3312 (article-strip-leading-blank-lines)
3313 (article-remove-trailing-blank-lines)
3314 (article-strip-multiple-blank-lines))
3316 (defun article-strip-all-blank-lines ()
3317 "Strip all blank lines."
3320 (let ((inhibit-point-motion-hooks t)
3321 (inhibit-read-only t))
3323 (while (re-search-forward "^[ \t]*\n" nil t)
3324 (replace-match "" t t)))))
3326 (defun gnus-article-narrow-to-signature ()
3327 "Narrow to the signature; return t if a signature is found, else nil."
3328 (let ((inhibit-point-motion-hooks t))
3329 (when (gnus-article-search-signature)
3331 ;; Check whether we have some limits to what we consider
3332 ;; to be a signature.
3333 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3334 (list gnus-signature-limit)))
3336 (while (setq limit (pop limits))
3337 (if (or (and (integerp limit)
3338 (< (- (point-max) (point)) limit))
3340 (< (count-lines (point) (point-max)) limit))
3341 (and (functionp limit)
3343 (and (stringp limit)
3344 (not (re-search-forward limit nil t))))
3345 () ; This limit did not succeed.
3349 (narrow-to-region (point) (point-max))
3352 (defun gnus-article-search-signature ()
3353 "Search the current buffer for the signature separator.
3354 Put point at the beginning of the signature separator."
3355 (let ((cur (point)))
3356 (goto-char (point-max))
3357 (if (if (stringp gnus-signature-separator)
3358 (re-search-backward gnus-signature-separator nil t)
3359 (let ((seps gnus-signature-separator))
3361 (not (re-search-backward (car seps) nil t)))
3368 (defun gnus-article-hidden-arg ()
3369 "Return the current prefix arg as a number, or 0 if no prefix."
3370 (list (if current-prefix-arg
3371 (prefix-numeric-value current-prefix-arg)
3374 (defun gnus-article-check-hidden-text (type arg)
3375 "Return nil if hiding is necessary.
3376 Arg can be nil or a number. nil and positive means hide, negative
3377 means show, 0 means toggle."
3380 (let ((hide (gnus-article-hidden-text-p type)))
3386 (gnus-article-show-hidden-text type)
3389 (if (eq hide 'hidden)
3391 (gnus-article-show-hidden-text type)
3395 (defun gnus-article-hidden-text-p (type)
3396 "Say whether the current buffer contains hidden text of type TYPE."
3397 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3399 (not (get-text-property pos 'invisible))
3400 (not (get-text-property pos 'dummy-invisible)))
3402 (text-property-any (1+ pos) (point-max) 'article-type type)))
3407 (defun gnus-article-show-hidden-text (type &optional dummy)
3408 "Show all hidden text of type TYPE.
3409 Originally it is hide instead of DUMMY."
3410 (let ((inhibit-read-only t)
3411 (inhibit-point-motion-hooks t))
3412 (gnus-remove-text-properties-when
3414 (point-min) (point-max)
3415 (cons 'article-type (cons type
3416 gnus-hidden-properties)))
3417 (gnus-delete-wash-type type)))
3419 (defconst article-time-units
3420 `((year . ,(* 365.25 24 60 60))
3421 (week . ,(* 7 24 60 60))
3422 (day . ,(* 24 60 60))
3426 "Mapping from time units to seconds.")
3428 (defun gnus-article-forward-header ()
3429 "Move point to the start of the next header.
3430 If the current header is a continuation header, this can be several
3435 (if (looking-at "[ \t]+[^ \t]")
3439 (defun article-treat-date ()
3440 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3441 (with-current-buffer gnus-summary-buffer
3442 gnus-article-date-headers)
3443 gnus-article-date-headers)
3446 (defun article-date-ut (&optional type highlight date-position)
3447 "Convert DATE date to TYPE in the current article.
3448 The default type is `ut'. See `gnus-article-date-headers' for
3450 (interactive (list 'ut t))
3451 (let* ((case-fold-search t)
3452 (inhibit-read-only t)
3453 (inhibit-point-motion-hooks t)
3455 (visible-date (mail-fetch-field "Date"))
3456 pos date bface eface)
3458 (goto-char (point-min))
3459 (when (re-search-forward "^Date:" nil t)
3460 (setq bface (get-text-property (point-at-bol) 'face)
3461 eface (get-text-property (1- (point-at-eol)) 'face)))
3462 ;; Delete any old Date headers.
3465 (goto-char date-position)
3466 (setq date (get-text-property (point) 'original-date))
3467 (delete-region (point)
3469 (gnus-article-forward-header)
3471 (article-transform-date date type bface eface))
3474 (goto-char (point-min))
3475 (while (or (get-text-property (setq pos (point)) 'original-date)
3476 (and (setq pos (next-single-property-change
3477 (point) 'original-date))
3479 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3480 (1+ (match-beginning 0))
3482 (goto-char (point-min))
3483 (while (re-search-forward "^Date:" nil t)
3484 (setq date (get-text-property (match-beginning 0) 'original-date))
3485 (delete-region (point-at-bol) (progn
3486 (gnus-article-forward-header)
3488 (when (and (not date)
3490 (setq date visible-date))
3492 (article-transform-date date type bface eface))
3493 (goto-char (point-max))
3496 (defun article-transform-date (date type bface eface)
3497 (dolist (this-type (cond
3504 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3507 (put-text-property (point) (1+ (point))
3508 'original-date date)
3509 (put-text-property (point) (1+ (point))
3510 'gnus-date-type this-type)
3512 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3513 (put-text-property (match-beginning 1) (1+ (match-end 1))
3515 (put-text-property (match-beginning 2) (match-end 2)
3519 (defun article-make-date-line (date type)
3520 "Return a DATE line of TYPE."
3521 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3523 (error "Unknown conversion type: %s" type))
3525 (let ((time (ignore-errors (date-to-time date))))
3527 ;; Convert to the local timezone.
3529 (concat "Date: " (message-make-date time)))
3530 ;; Convert to Universal Time.
3535 (let* ((e (parse-time-string date))
3536 (tm (apply 'encode-time e))
3538 (ls (- (cadr tm) (car (current-time-zone time)))))
3539 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3540 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3544 ;; Get the original date from the article.
3545 ((eq type 'original)
3546 (concat "Date: " (if (string-match "\n+$" date)
3547 (substring date 0 (match-beginning 0))
3549 ;; Let the user define the format.
3550 ((eq type 'user-defined)
3551 (let ((format (or (condition-case nil
3552 (with-current-buffer gnus-summary-buffer
3553 gnus-article-time-format)
3555 gnus-article-time-format)))
3556 (if (functionp format)
3557 (funcall format time)
3558 (concat "Date: " (format-time-string format time)))))
3561 (let ((tz (car (current-time-zone time))))
3564 (format-time-string "%Y%m%dT%H%M%S" time)
3565 (format "%s%02d%02d"
3566 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3567 (/ (% (abs tz) 3600) 60)))))
3568 ;; Do a lapsed format.
3570 (concat "Date: " (article-lapsed-string time)))
3571 ;; A combined date/lapsed format.
3572 ((eq type 'combined-lapsed)
3573 (let ((date-string (article-make-date-line date 'original))
3579 (concat " (" (article-lapsed-string time segments) ")"))
3580 (> (+ (length date-string)
3581 (length lapsed-string))
3584 (setq segments (1- segments)))
3586 (concat date-string lapsed-string)
3588 ;; Display the date in proper English
3590 (let ((dtime (decode-time time)))
3593 (number-to-string (nth 3 dtime))
3594 (let ((digit (% (nth 3 dtime) 10)))
3596 ((memq (nth 3 dtime) '(11 12 13)) "th")
3602 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3604 (number-to-string (nth 5 dtime))
3606 (format "%02d" (nth 2 dtime))
3608 (format "%02d" (nth 1 dtime)))))))
3610 (format "Date: %s (from Gnus)" date))))
3612 (defun article-lapsed-string (time &optional max-segments)
3613 ;; If the date is seriously mangled, the timezone functions are
3614 ;; liable to bug out, so we ignore all errors.
3615 (let* ((now (current-time))
3616 (real-time (subtract-time now time))
3617 (real-sec (and real-time
3618 (+ (* (float (car real-time)) 65536)
3620 (sec (and real-time (abs real-sec)))
3623 (unless max-segments
3624 (setq max-segments (length article-time-units)))
3632 ;; This is a bit convoluted, but basically we go
3633 ;; through the time units for years, weeks, etc,
3634 ;; and divide things to see whether that results
3635 ;; in positive answers.
3638 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3639 (>= segments max-segments))
3640 ;; The (remaining) seconds are too few to
3641 ;; be divided into this time unit.
3643 ;; It's big enough, so we output it.
3644 (setq sec (- sec (* num (cdr unit))))
3646 (concat (if prev ", " "") (int-to-string
3648 " " (symbol-name (car unit))
3649 (if (> num 1) "s" ""))
3651 segments (1+ segments)))))
3652 article-time-units "")
3653 ;; If dates are odd, then it might appear like the
3654 ;; article was sent in the future.
3657 " in the future"))))))
3659 (defun article-date-local (&optional highlight)
3660 "Convert the current article date to the local timezone."
3661 (interactive (list t))
3662 (article-date-ut 'local highlight))
3664 (defun article-date-english (&optional highlight)
3665 "Convert the current article date to something that is proper English."
3666 (interactive (list t))
3667 (article-date-ut 'english highlight))
3669 (defun article-date-original (&optional highlight)
3670 "Convert the current article date to what it was originally.
3671 This is only useful if you have used some other date conversion
3672 function and want to see what the date was before converting."
3673 (interactive (list t))
3674 (article-date-ut 'original highlight))
3676 (defun article-date-lapsed (&optional highlight)
3677 "Convert the current article date to time lapsed since it was sent."
3678 (interactive (list t))
3679 (article-date-ut 'lapsed highlight))
3681 (defun article-date-combined-lapsed (&optional highlight)
3682 "Convert the current article date to time lapsed since it was sent."
3683 (interactive (list t))
3684 (article-date-ut 'combined-lapsed highlight))
3686 (defun article-update-date-lapsed ()
3687 "Function to be run from a timer to update the lapsed time line."
3689 (let ((buffer (current-buffer)))
3693 (set-buffer (window-buffer w))
3694 (when (eq major-mode 'gnus-article-mode)
3695 (let ((old-line (count-lines (point-min) (point)))
3696 (old-column (- (point) (line-beginning-position)))
3698 (window-start (get-buffer-window (current-buffer)))))
3699 (goto-char (point-min))
3700 (while (re-search-forward "^Date:" nil t)
3701 (let ((type (get-text-property (match-beginning 0)
3703 (when (memq type '(lapsed combined-lapsed user-format))
3704 (when (and window-start
3705 (not (= window-start
3709 (setq window-start nil))
3711 (article-date-ut type t (match-beginning 0)))
3714 (set-window-start (get-buffer-window (current-buffer))
3716 (goto-char (point-min))
3717 (when (> old-column 0)
3718 (setq old-line (1- old-line)))
3719 (forward-line old-line)
3721 (when (> (current-column) old-column)
3723 (forward-char old-column)))))
3725 (set-buffer buffer))))
3727 (defun gnus-start-date-timer (&optional n)
3728 "Start a timer to update the Date headers in the article buffers.
3729 The numerical prefix says how frequently (in seconds) the function
3734 (gnus-stop-date-timer)
3735 (setq article-lapsed-timer
3736 (run-at-time 1 n 'article-update-date-lapsed)))
3738 (defun gnus-stop-date-timer ()
3739 "Stop the Date timer."
3741 (when article-lapsed-timer
3742 (nnheader-cancel-timer article-lapsed-timer)
3743 (setq article-lapsed-timer nil)))
3745 (defun article-date-user (&optional highlight)
3746 "Convert the current article date to the user-defined format.
3747 This format is defined by the `gnus-article-time-format' variable."
3748 (interactive (list t))
3749 (article-date-ut 'user highlight))
3751 (defun article-date-iso8601 (&optional highlight)
3752 "Convert the current article date to ISO8601."
3753 (interactive (list t))
3754 (article-date-ut 'iso8601 highlight))
3756 (defmacro gnus-article-save-original-date (&rest forms)
3757 "Save the original date as a text property and evaluate FORMS."
3758 `(let* ((case-fold-search t)
3760 (goto-char (point-min))
3761 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3764 (date (when (and start
3765 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3767 (buffer-substring-no-properties start
3768 (match-beginning 0)))))
3769 (goto-char (point-max))
3770 (skip-chars-backward "\n")
3771 (put-text-property (point-min) (point) 'original-date date)
3773 (goto-char (point-max))
3774 (skip-chars-backward "\n")
3775 (put-text-property (point-min) (point) 'original-date date)))
3777 ;; (defun article-show-all ()
3778 ;; "Show all hidden text in the article buffer."
3781 ;; (let ((inhibit-read-only t))
3782 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3784 (defun article-remove-leading-whitespace ()
3785 "Remove excessive whitespace from all headers."
3789 (let ((inhibit-read-only t))
3790 (article-narrow-to-head)
3791 (goto-char (point-min))
3792 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3793 (delete-region (match-beginning 1) (match-end 1)))))))
3795 (defun article-emphasize (&optional arg)
3796 "Emphasize text according to `gnus-emphasis-alist'."
3797 (interactive (gnus-article-hidden-arg))
3798 (unless (gnus-article-check-hidden-text 'emphasis arg)
3802 (with-current-buffer gnus-summary-buffer
3803 gnus-article-emphasis-alist)
3805 gnus-emphasis-alist))
3806 (inhibit-read-only t)
3807 (props (append '(article-type emphasis)
3808 gnus-hidden-properties))
3809 regexp elem beg invisible visible face)
3812 (while (setq elem (pop alist))
3814 (setq regexp (car elem)
3815 invisible (nth 1 elem)
3816 visible (nth 2 elem)
3818 (while (re-search-forward regexp nil t)
3819 (when (and (match-beginning visible) (match-beginning invisible))
3820 (gnus-article-hide-text
3821 (match-beginning invisible) (match-end invisible) props)
3822 (gnus-article-unhide-text-type
3823 (match-beginning visible) (match-end visible) 'emphasis)
3824 (gnus-put-overlay-excluding-newlines
3825 (match-beginning visible) (match-end visible) 'face face)
3826 (gnus-add-wash-type 'emphasis)
3827 (goto-char (match-end invisible)))))))))
3829 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3830 "Setup newsgroup emphasis alist."
3831 (unless gnus-article-emphasis-alist
3832 (let ((name (and gnus-newsgroup-name
3833 (gnus-group-real-name gnus-newsgroup-name))))
3834 (make-local-variable 'gnus-article-emphasis-alist)
3835 (setq gnus-article-emphasis-alist
3837 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3838 (while (setq elem (pop alist))
3839 (when (and name (string-match (car elem) name))
3841 highlight (copy-sequence (cdr elem)))))
3843 (copy-sequence highlight-words)
3844 (if gnus-newsgroup-name
3845 (copy-sequence (gnus-group-find-parameter
3846 gnus-newsgroup-name 'highlight-words t)))
3847 gnus-emphasis-alist)))))
3849 (defvar gnus-summary-article-menu)
3850 (defvar gnus-summary-post-menu)
3852 ;;; Saving functions.
3854 (defun gnus-article-save (save-buffer file &optional num)
3855 "Save the currently selected article."
3856 (when (or (get gnus-default-article-saver :headers)
3857 (not gnus-save-all-headers))
3858 ;; Remove headers according to `gnus-saved-headers' or the value
3859 ;; of the `:headers' property that the saver function might have.
3860 (let ((gnus-visible-headers
3861 (or (symbol-value (get gnus-default-article-saver :headers))
3862 gnus-saved-headers gnus-visible-headers))
3863 ;; Ignore group parameter. See `article-hide-headers'.
3864 (gnus-summary-buffer nil))
3865 (with-current-buffer save-buffer
3866 (article-hide-headers 1 t))))
3867 (save-window-excursion
3868 (if (not gnus-default-article-saver)
3869 (error "No default saver is defined")
3870 ;; !!! Magic! The saving functions all save
3871 ;; `gnus-save-article-buffer' (or so they think), but we
3872 ;; bind that variable to our save-buffer.
3873 (set-buffer gnus-article-buffer)
3874 (let* ((gnus-save-article-buffer save-buffer)
3877 ((not gnus-prompt-before-saving) 'default)
3878 ((eq gnus-prompt-before-saving 'always) nil)
3880 (gnus-number-of-articles-to-be-saved
3881 (when (eq gnus-prompt-before-saving t)
3883 (set-buffer gnus-article-current-summary)
3884 (funcall gnus-default-article-saver filename)))))
3886 (defun gnus-read-save-file-name (prompt &optional filename
3887 function group headers variable
3890 (funcall function group headers (symbol-value variable)))
3895 ((eq filename 'default)
3901 (when (symbol-value dir-var)
3902 (setq default-name (expand-file-name
3903 (file-name-nondirectory default-name)
3904 (symbol-value dir-var))))
3905 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3908 (if (and gnus-number-of-articles-to-be-saved
3909 (> gnus-number-of-articles-to-be-saved 1))
3910 (format "these %d articles"
3911 gnus-number-of-articles-to-be-saved)
3914 ;; Let the split methods have their say.
3916 ;; No split name was found.
3919 (concat prompt " (default "
3920 (file-name-nondirectory default-name) "): ")
3921 (file-name-directory default-name)
3923 ;; A single group name is returned.
3924 ((stringp split-name)
3926 (funcall function split-name headers
3927 (symbol-value variable)))
3929 (concat prompt " (default "
3930 (file-name-nondirectory default-name) "): ")
3931 (file-name-directory default-name)
3933 ;; A single split name was found
3934 ((= 1 (length split-name))
3935 (let* ((name (expand-file-name
3937 gnus-article-save-directory))
3938 (dir (cond ((file-directory-p name)
3939 (file-name-as-directory name))
3940 ((file-exists-p name) name)
3941 (t gnus-article-save-directory))))
3943 (concat prompt " (default " name "): ")
3945 ;; A list of splits was found.
3947 (setq split-name (nreverse split-name))
3949 (let ((file-name-history
3950 (nconc split-name file-name-history)))
3954 (concat prompt " (`M-p' for defaults): ")
3955 gnus-article-save-directory
3957 gnus-article-save-directory)))
3958 (car (push result file-name-history)))))))
3959 ;; Create the directory.
3960 (gnus-make-directory (file-name-directory file))
3961 ;; If we have read a directory, we append the default file name.
3962 (when (file-directory-p file)
3963 (setq file (expand-file-name (file-name-nondirectory
3965 (file-name-as-directory file))))
3966 ;; Possibly translate some characters.
3967 (nnheader-translate-file-chars file))))))
3968 (gnus-make-directory (file-name-directory result))
3970 (set variable result))
3972 (set dir-var (file-name-directory result)))
3975 (defun gnus-article-archive-name (group)
3976 "Return the first instance of an \"Archive-name\" in the current buffer."
3977 (let ((case-fold-search t))
3978 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3979 (nnheader-concat gnus-article-save-directory
3980 (match-string 1)))))
3982 (defun gnus-article-nndoc-name (group)
3983 "If GROUP is an nndoc group, return the name of the parent group."
3984 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3985 (gnus-group-get-parameter group 'save-article-group)))
3987 (defun gnus-summary-save-in-rmail (&optional filename)
3988 "Append this article to Rmail file.
3989 Optional argument FILENAME specifies file name.
3990 Directory to save to is default to `gnus-article-save-directory'."
3991 (setq filename (gnus-read-save-file-name
3992 "Save %s in rmail file" filename
3993 gnus-rmail-save-name gnus-newsgroup-name
3994 gnus-current-headers 'gnus-newsgroup-last-rmail))
3995 (with-current-buffer gnus-save-article-buffer
3999 ;; Note that unlike gnus-summary-save-in-mail, there is no
4000 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4002 (gnus-output-to-rmail filename))))
4005 (defun gnus-summary-save-in-mail (&optional filename)
4006 "Append this article to Unix mail file.
4007 Optional argument FILENAME specifies file name.
4008 Directory to save to is default to `gnus-article-save-directory'."
4009 (setq filename (gnus-read-save-file-name
4010 "Save %s in Unix mail file" filename
4011 gnus-mail-save-name gnus-newsgroup-name
4012 gnus-current-headers 'gnus-newsgroup-last-mail))
4013 (with-current-buffer gnus-save-article-buffer
4017 (if (and (file-readable-p filename)
4018 (file-regular-p filename)
4019 (mail-file-babyl-p filename))
4020 (gnus-output-to-rmail filename)
4021 (gnus-output-to-mail filename)))))
4024 (put 'gnus-summary-save-in-file :decode t)
4025 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4026 (defun gnus-summary-save-in-file (&optional filename overwrite)
4027 "Append this article to file.
4028 Optional argument FILENAME specifies file name.
4029 Directory to save to is default to `gnus-article-save-directory'."
4030 (setq filename (gnus-read-save-file-name
4031 "Save %s in file" filename
4032 gnus-file-save-name gnus-newsgroup-name
4033 gnus-current-headers 'gnus-newsgroup-last-file))
4034 (with-current-buffer gnus-save-article-buffer
4038 (when (and overwrite
4039 (file-exists-p filename))
4040 (delete-file filename))
4041 (gnus-output-to-file filename))))
4044 (put 'gnus-summary-write-to-file :decode t)
4045 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4046 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4047 (defun gnus-summary-write-to-file (&optional filename)
4048 "Write this article to a file, overwriting it if the file exists.
4049 Optional argument FILENAME specifies file name.
4050 The directory to save in defaults to `gnus-article-save-directory'."
4051 (setq filename (gnus-read-save-file-name
4052 "Save %s in file" filename
4053 gnus-file-save-name gnus-newsgroup-name
4054 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4055 (gnus-summary-save-in-file filename t))
4057 (put 'gnus-summary-save-body-in-file :decode t)
4058 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4059 "Append this article body to a file.
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 'gnus-newsgroup-last-file))
4066 (with-current-buffer gnus-save-article-buffer
4070 (when (article-goto-body)
4071 (narrow-to-region (point) (point-max)))
4072 (when (and overwrite
4073 (file-exists-p filename))
4074 (delete-file filename))
4075 (gnus-output-to-file filename))))
4078 (put 'gnus-summary-write-body-to-file :decode t)
4079 (put 'gnus-summary-write-body-to-file
4080 :function 'gnus-summary-save-body-in-file)
4081 (defun gnus-summary-write-body-to-file (&optional filename)
4082 "Write this article body to a file, overwriting it if the file exists.
4083 Optional argument FILENAME specifies file name.
4084 The directory to save in defaults to `gnus-article-save-directory'."
4085 (setq filename (gnus-read-save-file-name
4086 "Save %s body in file" filename
4087 gnus-file-save-name gnus-newsgroup-name
4088 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4089 (gnus-summary-save-body-in-file filename t))
4091 (put 'gnus-summary-save-in-pipe :decode t)
4092 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4093 (defun gnus-summary-save-in-pipe (&optional command raw)
4094 "Pipe this article to subprocess COMMAND.
4095 Valid values for COMMAND include:
4097 The executable command name and possibly arguments.
4099 You will be prompted for the command in the minibuffer.
4100 the symbol `default'
4101 It will be replaced with the command which the variable
4102 `gnus-summary-pipe-output-default-command' holds or the command
4103 last used for saving.
4104 Non-nil value for RAW overrides `:decode' and `:headers' properties
4105 and the raw article including all headers will be piped."
4106 (let ((article (gnus-summary-article-number))
4108 (get 'gnus-summary-save-in-pipe :decode)))
4109 save-buffer default)
4111 (if (vectorp (gnus-summary-article-header article))
4112 (save-current-buffer
4113 (gnus-summary-select-article decode decode nil article)
4114 (insert-buffer-substring
4118 gnus-original-article-buffer)
4120 (nnheader-set-temp-buffer " *Gnus Save*"))))
4121 ;; Remove unwanted headers.
4122 (when (and (not raw)
4123 (or (get 'gnus-summary-save-in-pipe :headers)
4124 (not gnus-save-all-headers)))
4125 (let ((gnus-visible-headers
4126 (or (symbol-value (get 'gnus-summary-save-in-pipe
4128 gnus-saved-headers gnus-visible-headers))
4129 (gnus-summary-buffer nil))
4130 (article-hide-headers 1 t))))
4131 (error "%d is not a real article" article))
4132 (error "No article to pipe"))
4133 (setq default (or gnus-summary-pipe-output-default-command
4134 gnus-last-shell-command))
4135 (unless (stringp command)
4137 (if (and (eq command 'default) default)
4139 (gnus-read-shell-command "Shell command on this article: "
4141 (when (string-equal command "")
4143 (setq command default)
4144 (error "A command is required")))
4145 (with-current-buffer save-buffer
4148 (shell-command-on-region (point-min) (point-max) command nil)))
4149 (gnus-kill-buffer save-buffer))
4150 (setq gnus-summary-pipe-output-default-command command))
4152 (defun gnus-summary-pipe-to-muttprint (&optional command)
4153 "Pipe this article to muttprint."
4154 (unless (stringp command)
4155 (setq command (read-string
4156 "Print using command: " gnus-summary-muttprint-program
4157 nil gnus-summary-muttprint-program)))
4158 (let ((gnus-summary-pipe-output-default-command
4159 gnus-summary-pipe-output-default-command))
4160 (gnus-summary-save-in-pipe command))
4161 (setq gnus-summary-muttprint-program command))
4163 ;;; Article file names when saving.
4165 (defun gnus-capitalize-newsgroup (newsgroup)
4166 "Capitalize NEWSGROUP name."
4167 (when (not (zerop (length newsgroup)))
4168 (concat (char-to-string (upcase (aref newsgroup 0)))
4169 (substring newsgroup 1))))
4171 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4172 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4173 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4174 Otherwise, it is like ~/News/news/group/num."
4177 (concat (if (gnus-use-long-file-name 'not-save)
4178 (gnus-capitalize-newsgroup newsgroup)
4179 (gnus-newsgroup-directory-form newsgroup))
4180 "/" (int-to-string (mail-header-number headers)))
4181 gnus-article-save-directory)))
4183 (string-equal (file-name-directory default)
4184 (file-name-directory last-file))
4185 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4187 (or last-file default))))
4189 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4190 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4191 If variable `gnus-use-long-file-name' is non-nil, it is
4192 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4195 (concat (if (gnus-use-long-file-name 'not-save)
4197 (gnus-newsgroup-directory-form newsgroup))
4198 "/" (int-to-string (mail-header-number headers)))
4199 gnus-article-save-directory)))
4201 (string-equal (file-name-directory default)
4202 (file-name-directory last-file))
4203 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4205 (or last-file default))))
4207 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4208 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4209 If variable `gnus-use-long-file-name' is non-nil, it is
4210 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4213 (if (gnus-use-long-file-name 'not-save)
4216 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4218 gnus-article-save-directory)))
4220 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4221 "Generate file name from sender."
4222 (let ((from (mail-header-from headers)))
4224 (if (and from (string-match "\\([^ <]+\\)@" from))
4225 (match-string 1 from)
4227 gnus-article-save-directory)))
4229 (defun article-verify-x-pgp-sig ()
4231 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4233 (if (gnus-buffer-live-p gnus-original-article-buffer)
4234 (let ((sig (with-current-buffer gnus-original-article-buffer
4235 (gnus-fetch-field "X-PGP-Sig")))
4239 (mml2015-clear-verify-function))
4241 (insert-buffer-substring gnus-original-article-buffer)
4242 (setq items (split-string sig))
4243 (message-narrow-to-head)
4244 (let ((inhibit-point-motion-hooks t)
4245 (case-fold-search t))
4246 ;; Don't verify multiple headers.
4247 (setq headers (mapconcat (lambda (header)
4249 (mail-fetch-field header)
4251 (split-string (nth 1 items) ",") "")))
4252 (delete-region (point-min) (point-max))
4253 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4254 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4259 (if (looking-at "^-")
4262 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4263 (insert "Version: " (car items) "\n\n")
4264 (insert (mapconcat 'identity (cddr items) "\n"))
4265 (insert "\n-----END PGP SIGNATURE-----\n")
4266 (let ((mm-security-handle (list (format "multipart/signed"))))
4267 (mml2015-clean-buffer)
4268 (let ((coding-system-for-write (or gnus-newsgroup-charset
4270 (funcall (mml2015-clear-verify-function)))
4272 (or (mm-handle-multipart-ctl-parameter
4273 mm-security-handle 'gnus-details)
4274 (mm-handle-multipart-ctl-parameter
4275 mm-security-handle 'gnus-info)))))
4277 (let ((inhibit-read-only t) bface eface)
4279 (message-narrow-to-head)
4280 (goto-char (point-max))
4282 (setq bface (get-text-property (point-at-bol) 'face)
4283 eface (get-text-property (1- (point-at-eol)) 'face))
4284 (message-remove-header "X-Gnus-PGP-Verify")
4285 (if (re-search-forward "^X-PGP-Sig:" nil t)
4287 (goto-char (point-max)))
4288 (narrow-to-region (point) (point))
4289 (insert "X-Gnus-PGP-Verify: " info "\n")
4290 (goto-char (point-min))
4293 (if (not (looking-at "^[ \t]"))
4297 (goto-char (point-min))
4298 (when (looking-at "\\([^:]+\\): *")
4299 (put-text-property (match-beginning 1) (1+ (match-end 1))
4301 (put-text-property (match-end 0) (point-max)
4302 'face eface)))))))))
4304 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4306 (defun article-verify-cancel-lock ()
4307 "Verify Cancel-Lock header."
4309 (if (gnus-buffer-live-p gnus-original-article-buffer)
4310 (canlock-verify gnus-original-article-buffer)))
4317 (setq afunc (car func)
4320 gfunc (intern (format "gnus-%s" func))))
4322 (when (fboundp afunc)
4323 `(lambda (&optional interactive &rest args)
4324 ,(documentation afunc t)
4325 (interactive (list t))
4326 (with-current-buffer gnus-article-buffer
4328 (call-interactively ',afunc)
4329 (apply ',afunc args))))))))
4330 '(article-hide-headers
4331 article-verify-x-pgp-sig
4332 article-verify-cancel-lock
4333 article-hide-boring-headers
4334 article-treat-overstrike
4335 article-treat-ansi-sequences
4336 article-fill-long-lines
4337 article-capitalize-sentences
4339 article-remove-leading-whitespace
4340 article-display-x-face
4341 article-display-face
4342 article-de-quoted-unreadable
4343 article-de-base64-unreadable
4346 article-unsplit-urls
4347 article-hide-list-identifiers
4348 article-strip-banner
4351 article-hide-signature
4352 article-strip-headers-in-body
4353 article-remove-trailing-blank-lines
4354 article-strip-leading-blank-lines
4355 article-strip-multiple-blank-lines
4356 article-strip-leading-space
4357 article-strip-trailing-space
4358 article-strip-blank-lines
4359 article-strip-all-blank-lines
4361 article-date-english
4362 article-date-iso8601
4363 article-date-original
4366 article-decode-mime-words
4367 article-decode-charset
4368 article-decode-encoded-words
4371 article-date-combined-lapsed
4373 article-treat-dumbquotes
4374 article-treat-non-ascii
4375 article-normalize-headers
4376 ;;(article-show-all . gnus-article-show-all-headers)
4380 ;;; Gnus article mode
4383 (put 'gnus-article-mode 'mode-class 'special)
4385 (set-keymap-parent gnus-article-mode-map widget-keymap)
4387 (gnus-define-keys gnus-article-mode-map
4388 " " gnus-article-goto-next-page
4389 "\177" gnus-article-goto-prev-page
4390 [delete] gnus-article-goto-prev-page
4391 [backspace] gnus-article-goto-prev-page
4392 "\C-c^" gnus-article-refer-article
4393 "h" gnus-article-show-summary
4394 "s" gnus-article-show-summary
4395 "\C-c\C-m" gnus-article-mail
4396 "?" gnus-article-describe-briefly
4397 "<" beginning-of-buffer
4399 "\C-c\C-i" gnus-info-find-node
4401 "R" gnus-article-reply-with-original
4402 "F" gnus-article-followup-with-original
4403 "\C-hk" gnus-article-describe-key
4404 "\C-hc" gnus-article-describe-key-briefly
4405 "\C-hb" gnus-article-describe-bindings
4407 "e" gnus-article-read-summary-keys
4408 "\C-d" gnus-article-read-summary-keys
4409 "\M-*" gnus-article-read-summary-keys
4410 "\M-#" gnus-article-read-summary-keys
4411 "\M-^" gnus-article-read-summary-keys
4412 "\M-g" gnus-article-read-summary-keys)
4414 (substitute-key-definition
4415 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4417 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4418 "W" gnus-article-wide-reply-with-original)
4419 (if (featurep 'xemacs)
4420 (set-keymap-default-binding gnus-article-send-map
4421 'gnus-article-read-summary-send-keys)
4422 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4424 (defun gnus-article-make-menu-bar ()
4425 (unless (boundp 'gnus-article-commands-menu)
4426 (gnus-summary-make-menu-bar))
4427 (unless (boundp 'gnus-article-article-menu)
4429 gnus-article-article-menu gnus-article-mode-map ""
4431 ["Scroll forwards" gnus-article-goto-next-page t]
4432 ["Scroll backwards" gnus-article-goto-prev-page t]
4433 ["Show summary" gnus-article-show-summary t]
4434 ["Fetch Message-ID at point" gnus-article-refer-article t]
4435 ["Mail to address at point" gnus-article-mail t]
4436 ["Send a bug report" gnus-bug t]))
4439 gnus-article-treatment-menu gnus-article-mode-map ""
4440 ;; Fixme: this should use :active (and maybe :visible).
4442 ["Hide headers" gnus-article-hide-headers t]
4443 ["Hide signature" gnus-article-hide-signature t]
4444 ["Hide citation" gnus-article-hide-citation t]
4445 ["Treat overstrike" gnus-article-treat-overstrike t]
4446 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4447 ["Remove carriage return" gnus-article-remove-cr t]
4448 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4449 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4450 ["Remove base64" gnus-article-de-base64-unreadable t]
4451 ["Treat html" gnus-article-wash-html t]
4452 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4453 ["Decode HZ" gnus-article-decode-HZ t]))
4455 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4457 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4459 (gnus-run-hooks 'gnus-article-menu-hook)))
4461 (defvar bookmark-make-record-function)
4462 (defvar shr-put-image-function)
4464 (defun gnus-article-mode ()
4465 "Major mode for displaying an article.
4467 All normal editing commands are switched off.
4469 The following commands are available in addition to all summary mode
4471 \\<gnus-article-mode-map>
4472 \\[gnus-article-next-page]\t Scroll the article one page forwards
4473 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4474 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4475 \\[gnus-article-show-summary]\t Display the summary buffer
4476 \\[gnus-article-mail]\t Send a reply to the address near point
4477 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4478 \\[gnus-info-find-node]\t Go to the Gnus info node"
4480 (kill-all-local-variables)
4481 (gnus-simplify-mode-line)
4482 (setq mode-name "Article")
4483 (setq major-mode 'gnus-article-mode)
4484 (make-local-variable 'minor-mode-alist)
4485 (use-local-map gnus-article-mode-map)
4486 (when (gnus-visual-p 'article-menu 'menu)
4487 (gnus-article-make-menu-bar)
4488 (when gnus-summary-tool-bar-map
4489 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4490 (gnus-update-format-specifications nil 'article-mode)
4491 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4492 (set (make-local-variable 'gnus-page-broken) nil)
4493 (make-local-variable 'gnus-article-current-summary)
4494 (make-local-variable 'gnus-article-mime-handles)
4495 (make-local-variable 'gnus-article-decoded-p)
4496 (make-local-variable 'gnus-article-mime-handle-alist)
4497 (make-local-variable 'gnus-article-wash-types)
4498 (make-local-variable 'gnus-article-image-alist)
4499 (make-local-variable 'gnus-article-charset)
4500 (make-local-variable 'gnus-article-ignored-charsets)
4501 (set (make-local-variable 'bookmark-make-record-function)
4502 'gnus-summary-bookmark-make-record)
4503 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4505 (set (make-local-variable 'nobreak-char-display) nil)
4506 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4507 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4508 (setq cursor-in-non-selected-windows nil)
4509 (gnus-set-default-directory)
4510 (buffer-disable-undo)
4511 (setq buffer-read-only t
4512 show-trailing-whitespace nil)
4513 (set-syntax-table gnus-article-mode-syntax-table)
4514 (mm-enable-multibyte)
4515 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4517 (defun gnus-article-setup-buffer ()
4518 "Initialize the article buffer."
4519 (let* ((name (if gnus-single-article-buffer "*Article*"
4521 (gnus-group-decoded-name gnus-newsgroup-name)
4524 (progn (string-match "\\*Article" name)
4525 (concat " *Original Article"
4526 (substring name (match-end 0))))))
4527 (setq gnus-article-buffer name)
4528 (setq gnus-original-article-buffer original)
4529 (setq gnus-article-mime-handle-alist nil)
4530 (with-current-buffer gnus-summary-buffer
4531 ;; This might be a variable local to the summary buffer.
4532 (unless gnus-single-article-buffer
4533 (setq gnus-article-buffer name)
4534 (setq gnus-original-article-buffer original)
4535 (gnus-set-global-variables)))
4536 (gnus-article-setup-highlight-words)
4537 ;; Init original article buffer.
4538 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4539 (mm-enable-multibyte)
4540 (setq major-mode 'gnus-original-article-mode)
4541 (make-local-variable 'gnus-original-article))
4542 (if (and (get-buffer name)
4543 (with-current-buffer name
4544 (if gnus-article-edit-mode
4545 (if (y-or-n-p "Article mode edit in progress; discard? ")
4547 (set-buffer-modified-p nil)
4548 (gnus-kill-buffer name)
4551 (error "Action aborted"))
4553 (with-current-buffer name
4554 (set (make-local-variable 'gnus-article-edit-mode) nil)
4555 (gnus-article-stop-animations)
4556 (when gnus-article-mime-handles
4557 (mm-destroy-parts gnus-article-mime-handles)
4558 (setq gnus-article-mime-handles nil))
4559 ;; Set it to nil in article-buffer!
4560 (setq gnus-article-mime-handle-alist nil)
4561 (buffer-disable-undo)
4562 (setq buffer-read-only t)
4563 (unless (eq major-mode 'gnus-article-mode)
4564 (gnus-article-mode))
4565 (setq truncate-lines gnus-article-truncate-lines)
4567 (with-current-buffer (gnus-get-buffer-create name)
4569 (setq truncate-lines gnus-article-truncate-lines)
4570 (make-local-variable 'gnus-summary-buffer)
4571 (setq gnus-summary-buffer
4572 (gnus-summary-buffer-name gnus-newsgroup-name))
4573 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4574 (when article-lapsed-timer
4575 (gnus-stop-date-timer))
4576 (when gnus-article-update-date-headers
4577 (gnus-start-date-timer gnus-article-update-date-headers))
4578 (current-buffer)))))
4580 (defun gnus-article-stop-animations ()
4581 (dolist (timer (and (boundp 'timer-list)
4583 (when (eq (elt timer 5) 'image-animate-timeout)
4584 (cancel-timer timer))))
4586 (defun gnus-stop-downloads ()
4587 (setq url-queue nil))
4589 ;; Set article window start at LINE, where LINE is the number of lines
4590 ;; from the head of the article.
4591 (defun gnus-article-set-window-start (&optional line)
4592 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4593 (when article-window
4596 (with-current-buffer gnus-article-buffer
4597 (goto-char (point-min))
4600 (gnus-message 6 "Moved to bookmark")
4601 (search-forward "\n\n" nil t)
4605 (defun gnus-article-prepare (article &optional all-headers header)
4606 "Prepare ARTICLE in article mode buffer.
4607 ARTICLE should either be an article number or a Message-ID.
4608 If ARTICLE is an id, HEADER should be the article headers.
4609 If ALL-HEADERS is non-nil, no headers are hidden."
4611 ;; Make sure we start in a summary buffer.
4612 (unless (eq major-mode 'gnus-summary-mode)
4613 (set-buffer gnus-summary-buffer))
4614 (setq gnus-summary-buffer (current-buffer))
4615 (let* ((gnus-article (if header (mail-header-number header) article))
4616 (summary-buffer (current-buffer))
4617 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4618 (group gnus-newsgroup-name)
4621 (gnus-article-setup-buffer)
4622 (set-buffer gnus-article-buffer)
4623 ;; Deactivate active regions.
4624 (when (and (boundp 'transient-mark-mode)
4625 transient-mark-mode)
4626 (setq mark-active nil))
4627 (if (not (setq result (let ((inhibit-read-only t))
4628 (gnus-request-article-this-buffer
4630 ;; There is no such article.
4632 (when (and (numberp article)
4633 (not (memq article gnus-newsgroup-sparse)))
4634 (setq gnus-article-current
4635 (cons gnus-newsgroup-name article))
4636 (set-buffer gnus-summary-buffer)
4637 (setq gnus-current-article article)
4638 (if (and (memq article gnus-newsgroup-undownloaded)
4639 (not (gnus-online (gnus-find-method-for-group
4640 gnus-newsgroup-name))))
4642 (gnus-summary-set-agent-mark article)
4643 (message "Message marked for downloading"))
4644 (gnus-summary-mark-article article gnus-canceled-mark)
4645 (unless (memq article gnus-newsgroup-sparse)
4646 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4647 (if (or (eq result 'pseudo)
4648 (eq result 'nneething))
4650 (with-current-buffer summary-buffer
4651 (push article gnus-newsgroup-history)
4652 (setq gnus-last-article gnus-current-article
4653 gnus-current-article 0
4654 gnus-current-headers nil
4655 gnus-article-current nil)
4656 (if (eq result 'nneething)
4657 (gnus-configure-windows 'summary)
4658 (gnus-configure-windows 'article))
4659 (gnus-set-global-variables))
4660 (let ((gnus-article-mime-handle-alist-1
4661 gnus-article-mime-handle-alist))
4662 (gnus-set-mode-line 'article)))
4663 ;; The result from the `request' was an actual article -
4664 ;; or at least some text that is now displayed in the
4666 (when (and (numberp article)
4667 (not (eq article gnus-current-article)))
4668 ;; Seems like a new article has been selected.
4669 ;; `gnus-current-article' must be an article number.
4670 (with-current-buffer summary-buffer
4671 (push article gnus-newsgroup-history)
4672 (setq gnus-last-article gnus-current-article
4673 gnus-current-article article
4674 gnus-current-headers
4675 (gnus-summary-article-header gnus-current-article)
4676 gnus-article-current
4677 (cons gnus-newsgroup-name gnus-current-article))
4678 (unless (vectorp gnus-current-headers)
4679 (setq gnus-current-headers nil))
4680 (gnus-summary-goto-subject gnus-current-article)
4681 (when (gnus-summary-show-thread)
4682 ;; If the summary buffer really was folded, the
4683 ;; previous goto may not actually have gone to
4684 ;; the right article, but the thread root instead.
4686 (gnus-summary-goto-subject gnus-current-article))
4687 (gnus-run-hooks 'gnus-mark-article-hook)
4688 (gnus-set-mode-line 'summary)
4689 (when (gnus-visual-p 'article-highlight 'highlight)
4690 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4691 ;; Set the global newsgroup variables here.
4692 (gnus-set-global-variables)
4693 (setq gnus-have-all-headers
4694 (or all-headers gnus-show-all-headers))))
4696 (gnus-configure-windows 'article))
4697 (when (or (numberp article)
4699 (gnus-article-prepare-display)
4701 (goto-char (point-min))
4702 (when gnus-break-pages
4703 (gnus-narrow-to-page)))
4704 (let ((gnus-article-mime-handle-alist-1
4705 gnus-article-mime-handle-alist))
4706 (gnus-set-mode-line 'article))
4710 (set-window-point (get-buffer-window (current-buffer)) (point))
4711 (gnus-configure-windows 'article)
4712 (gnus-run-hooks 'gnus-article-prepare-hook)
4716 (defun gnus-article-prepare-display ()
4717 "Make the current buffer look like a nice article."
4718 ;; Hooks for getting information from the article.
4719 ;; This hook must be called before being narrowed.
4720 (let ((gnus-article-buffer (current-buffer))
4722 (inhibit-read-only t))
4723 (unless (eq major-mode 'gnus-article-mode)
4724 (gnus-article-mode))
4725 (setq buffer-read-only nil
4726 gnus-article-wash-types nil
4727 gnus-article-image-alist nil)
4728 (gnus-run-hooks 'gnus-tmp-internal-hook)
4729 (when gnus-display-mime-function
4730 (funcall gnus-display-mime-function))))
4733 ;;; Gnus Sticky Article Mode
4736 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4737 "Mode for sticky articles."
4738 ;; Release bindings that won't work.
4739 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4740 gnus-sticky-article-mode-map)
4741 (substitute-key-definition 'gnus-article-refer-article 'undefined
4742 gnus-sticky-article-mode-map)
4743 (dolist (k '("e" "h" "s" "F" "R"))
4744 (define-key gnus-sticky-article-mode-map k nil))
4745 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4746 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4747 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4748 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4750 (defun gnus-sticky-article (arg)
4751 "Make the current article sticky.
4752 If a prefix ARG is given, ask for a name for this sticky article buffer."
4754 (gnus-summary-show-thread)
4755 (gnus-summary-select-article nil nil 'pseudo)
4756 (let (new-art-buf-name)
4757 (gnus-eval-in-buffer-window gnus-article-buffer
4758 (setq new-art-buf-name
4762 (read-from-minibuffer "Sticky article buffer name: ")
4763 (gnus-with-article-headers
4764 (gnus-article-goto-header "subject")
4765 (setq new-art-buf-name
4766 (buffer-substring-no-properties
4767 (line-beginning-position) (line-end-position)))
4768 (goto-char (point-min))
4769 (gnus-article-goto-header "from")
4770 (setq new-art-buf-name
4772 new-art-buf-name ", "
4773 (buffer-substring-no-properties
4774 (line-beginning-position) (line-end-position))))
4775 (goto-char (point-min))
4776 (gnus-article-goto-header "date")
4777 (setq new-art-buf-name
4779 new-art-buf-name ", "
4780 (buffer-substring-no-properties
4781 (line-beginning-position) (line-end-position))))))
4783 (if (and (gnus-buffer-live-p new-art-buf-name)
4784 (with-current-buffer new-art-buf-name
4785 (eq major-mode 'gnus-sticky-article-mode)))
4786 (switch-to-buffer new-art-buf-name)
4787 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4788 (gnus-sticky-article-mode))
4789 (setq gnus-article-buffer new-art-buf-name))
4790 (gnus-summary-recenter)
4791 (gnus-summary-position-point))
4793 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4794 "Kill the given sticky article BUFFER.
4795 If none is given, assume the current buffer and kill it if it has
4796 `gnus-sticky-article-mode'."
4799 (setq buffer (current-buffer)))
4800 (with-current-buffer buffer
4801 (when (eq major-mode 'gnus-sticky-article-mode)
4802 (gnus-kill-buffer buffer))))
4804 (defun gnus-kill-sticky-article-buffers (arg)
4805 "Kill all sticky article buffers.
4806 If a prefix ARG is given, ask for confirmation."
4808 (dolist (buf (gnus-buffers))
4809 (with-current-buffer buf
4810 (when (eq major-mode 'gnus-sticky-article-mode)
4812 (gnus-kill-buffer buf)
4813 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4814 (gnus-kill-buffer buf)))))))
4817 ;;; Gnus MIME viewing functions
4820 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4821 "Format of the MIME buttons.
4823 Valid specifiers include:
4825 %T MIME type, along with additional info
4826 %n The `name' parameter
4827 %d The description, if any
4828 %l The length of the encoded part
4829 %p The part identifier number
4830 %e Dots if the part isn't displayed
4832 General format specifiers can also be used. See Info node
4833 `(gnus)Formatting Variables'.")
4835 (defvar gnus-mime-button-line-format-alist
4836 '((?t gnus-tmp-type ?s)
4837 (?T gnus-tmp-type-long ?s)
4838 (?n gnus-tmp-name ?s)
4839 (?d gnus-tmp-description ?s)
4841 (?l gnus-tmp-length ?d)
4842 (?e gnus-tmp-dots ?s)))
4844 (defvar gnus-mime-button-commands
4845 '((gnus-article-press-button "\r" "Toggle Display")
4846 (gnus-mime-view-part "v" "View Interactively...")
4847 (gnus-mime-view-part-as-type "t" "View As Type...")
4848 (gnus-mime-view-part-as-charset "C" "View As charset...")
4849 (gnus-mime-save-part "o" "Save...")
4850 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4851 (gnus-mime-replace-part "r" "Replace part")
4852 (gnus-mime-delete-part "d" "Delete part")
4853 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4854 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4855 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4856 (gnus-mime-view-part-externally "e" "View Externally")
4857 (gnus-mime-print-part "p" "Print")
4858 (gnus-mime-pipe-part "|" "Pipe To Command...")
4859 (gnus-mime-action-on-part "." "Take action on the part...")))
4861 (defun gnus-article-mime-part-status ()
4862 (if gnus-article-mime-handle-alist-1
4863 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4865 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4868 (defvar gnus-mime-button-map
4869 (let ((map (make-sparse-keymap)))
4870 (define-key map gnus-mouse-2 'gnus-article-push-button)
4871 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4872 (dolist (c gnus-mime-button-commands)
4873 (define-key map (cadr c) (car c)))
4877 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4879 ,@(mapcar (lambda (c)
4880 (vector (caddr c) (car c) :active t))
4881 gnus-mime-button-commands)))
4883 (defvar gnus-url-button-commands
4884 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4886 (defvar gnus-url-button-map
4887 (let ((map (make-sparse-keymap)))
4888 (dolist (c gnus-url-button-commands)
4889 (define-key map (cadr c) (car c)))
4893 gnus-url-button-menu gnus-url-button-map "URL button menu."
4895 ,@(mapcar (lambda (c)
4896 (vector (caddr c) (car c) :active t))
4897 gnus-url-button-commands)))
4899 (defmacro gnus-bind-safe-url-regexp (&rest body)
4900 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4901 `(let ((mm-w3m-safe-url-regexp
4902 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4904 gnus-article-current-summary))
4905 (with-current-buffer gnus-article-current-summary
4906 gnus-newsgroup-name)
4907 gnus-newsgroup-name)))
4908 (if (cond ((not group)
4909 ;; Maybe we're in a mml-preview buffer
4910 ;; and no group is selected.
4912 ((stringp gnus-safe-html-newsgroups)
4913 (string-match gnus-safe-html-newsgroups group))
4914 ((consp gnus-safe-html-newsgroups)
4915 (member group gnus-safe-html-newsgroups)))
4917 mm-w3m-safe-url-regexp))))
4920 (defun gnus-mime-button-menu (event prefix)
4921 "Construct a context-sensitive menu of MIME commands."
4922 (interactive "e\nP")
4923 (save-window-excursion
4924 (let ((pos (event-start event)))
4925 (select-window (posn-window pos))
4926 (goto-char (posn-point pos))
4927 (gnus-article-check-buffer)
4928 (popup-menu gnus-mime-button-menu nil prefix))))
4930 (defun gnus-mime-view-all-parts (&optional handles)
4931 "View all the MIME parts."
4933 (with-current-buffer gnus-article-buffer
4934 (let ((handles (or handles gnus-article-mime-handles))
4935 (mail-parse-charset gnus-newsgroup-charset)
4936 (mail-parse-ignored-charsets
4937 (with-current-buffer gnus-summary-buffer
4938 gnus-newsgroup-ignored-charsets)))
4940 (mm-remove-parts handles)
4941 (goto-char (point-min))
4942 (or (search-forward "\n\n") (goto-char (point-max)))
4943 (let ((inhibit-read-only t))
4944 (delete-region (point) (point-max))
4945 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4947 (defun gnus-article-jump-to-part (n)
4948 "Jump to MIME part N."
4950 (let ((parts (with-current-buffer gnus-article-buffer
4951 (length gnus-article-mime-handle-alist))))
4953 (error "No such part"))
4954 (pop-to-buffer gnus-article-buffer)
4956 (setq n (if (= parts 1)
4958 (read-number (format "Jump to part (1..%s): " parts)))))
4959 (unless (and (integerp n) (<= n parts) (>= n 1))
4962 (gnus-message 7 "Invalid part `%s', using %s instead."
4965 (gnus-message 9 "Jumping to part %s." n)
4966 (cond ((>= gnus-auto-select-part 1)
4967 (while (and (<= n parts)
4968 (not (gnus-article-goto-part n)))
4970 ((< gnus-auto-select-part 0)
4971 (while (and (>= n 1)
4972 (not (gnus-article-goto-part n)))
4975 (gnus-article-goto-part n)))))
4977 (defvar gnus-mime-buttonized-part-id nil
4978 "ID of a mime part that should be buttonized.
4979 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4982 (defsubst gnus-article-edit-part (handles &optional current-id)
4983 "Edit an article in order to delete a mime part.
4984 This function is exclusively used by `gnus-mime-save-part-and-strip'
4985 and `gnus-mime-delete-part', and not provided at run-time normally."
4986 (gnus-article-edit-article
4988 (buffer-disable-undo)
4990 (let ((mail-parse-charset (or gnus-article-charset
4991 ',gnus-newsgroup-charset))
4992 (mail-parse-ignored-charsets
4993 (or gnus-article-ignored-charsets
4994 ',gnus-newsgroup-ignored-charsets))
4995 (mbl mml-buffer-list))
4996 (setq mml-buffer-list nil)
4997 (insert-buffer-substring gnus-original-article-buffer)
4998 (mime-to-mml ',handles)
4999 (setq gnus-article-mime-handles nil)
5000 (let ((mbl1 mml-buffer-list))
5001 (setq mml-buffer-list mbl)
5002 (set (make-local-variable 'mml-buffer-list) mbl1))
5003 (gnus-make-local-hook 'kill-buffer-hook)
5004 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5005 `(lambda (no-highlight)
5006 (let ((mail-parse-charset (or gnus-article-charset
5007 ',gnus-newsgroup-charset))
5008 (message-options message-options)
5009 (message-options-set-recipient)
5010 (mail-parse-ignored-charsets
5011 (or gnus-article-ignored-charsets
5012 ',gnus-newsgroup-ignored-charsets)))
5014 (mml-destroy-buffers)
5015 (remove-hook 'kill-buffer-hook
5016 'mml-destroy-buffers t)
5017 (kill-local-variable 'mml-buffer-list))
5018 (gnus-summary-edit-article-done
5019 ,(or (mail-header-references gnus-current-headers) "")
5020 ,(gnus-group-read-only-p)
5021 ,gnus-summary-buffer no-highlight))
5023 ;; Force buttonizing this part.
5024 (let ((gnus-mime-buttonized-part-id current-id))
5025 (gnus-article-edit-done))
5026 (gnus-configure-windows 'article)
5027 (when (and current-id (integerp gnus-auto-select-part))
5028 (gnus-article-jump-to-part
5029 (min (max (+ current-id gnus-auto-select-part) 1)
5030 (with-current-buffer gnus-article-buffer
5031 (length gnus-article-mime-handle-alist)))))))
5033 (defun gnus-mime-replace-part (file)
5034 "Replace MIME part under point with an external body."
5035 ;; Useful if file has already been saved to disk
5038 (read-file-name "Replace MIME part with file: "
5039 (or mm-default-directory default-directory)
5041 (gnus-mime-save-part-and-strip file))
5043 (defun gnus-mime-save-part-and-strip (&optional file)
5044 "Save the MIME part under point then replace it with an external body.
5045 If FILE is given, use it for the external part."
5047 (gnus-article-check-buffer)
5048 (when (gnus-group-read-only-p)
5049 (error "The current group does not support deleting of parts"))
5050 (when (mm-complicated-handles gnus-article-mime-handles)
5052 The current article has a complicated MIME structure, giving up..."))
5053 (let* ((data (get-text-property (point) 'gnus-data))
5054 (id (get-text-property (point) 'gnus-part))
5056 (handles gnus-article-mime-handles))
5059 (and data (mm-save-part data "Delete MIME part and save to: "))))
5061 (with-current-buffer (mm-handle-buffer data)
5063 (insert "Content-Type: " (mm-handle-media-type data))
5064 (mml-insert-parameter-string (cdr (mm-handle-type data))
5066 ;; Add a filename for the sake of saving the part again.
5067 (mml-insert-parameter
5068 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5070 (insert "Content-ID: " (message-make-message-id) "\n")
5071 (insert "Content-Transfer-Encoding: binary\n")
5074 (cdr (mm-make-handle nil
5075 `("message/external-body"
5076 (access-type . "LOCAL-FILE")
5078 ;; (set-buffer gnus-summary-buffer)
5079 (gnus-article-edit-part handles id))))
5081 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5082 ;; parts...>') but with stripping would be nice.
5084 (defun gnus-mime-delete-part ()
5085 "Delete the MIME part under point.
5086 Replace it with some information about the removed part."
5088 (gnus-article-check-buffer)
5089 (when (gnus-group-read-only-p)
5090 (error "The current group does not support deleting of parts"))
5091 (when (mm-complicated-handles gnus-article-mime-handles)
5093 The current article has a complicated MIME structure, giving up..."))
5094 (when (or gnus-expert-user
5095 (gnus-yes-or-no-p "\
5096 Deleting parts may malfunction or destroy the article; continue? "))
5097 (let* ((data (get-text-property (point) 'gnus-data))
5098 (id (get-text-property (point) 'gnus-part))
5099 (handles gnus-article-mime-handles)
5101 (let ((desc (mm-handle-description data)))
5103 (mail-decode-encoded-word-string desc))))
5104 (filename (or (mm-handle-filename data) "(none)"))
5105 (type (mm-handle-media-type data)))
5107 (error "No MIME part under point"))
5108 (with-current-buffer (mm-handle-buffer data)
5109 (let ((bsize (buffer-size)))
5114 "| The following attachment has been deleted:\n"
5116 "| Type: " type "\n"
5117 "| Filename: " filename "\n"
5118 "| Size (encoded): " (format "%s byte%s\n"
5119 bsize (if (= bsize 1)
5123 (concat "| Description: " description "\n"))
5126 (cdr (mm-make-handle
5127 nil `("text/plain" (charset . gnus-decoded)) nil nil
5129 (format "Deleted attachment (%s bytes)" bsize))))))
5130 ;; (set-buffer gnus-summary-buffer)
5131 (gnus-article-edit-part handles id))))
5133 (defun gnus-mime-save-part ()
5134 "Save the MIME part under point."
5136 (gnus-article-check-buffer)
5137 (let ((data (get-text-property (point) 'gnus-data)))
5139 (mm-save-part data))))
5141 (defun gnus-mime-pipe-part (&optional cmd)
5142 "Pipe the MIME part under point to a process.
5143 Use CMD as the process."
5145 (gnus-article-check-buffer)
5146 (let ((data (get-text-property (point) 'gnus-data)))
5148 (mm-pipe-part data cmd))))
5150 (defun gnus-mime-view-part ()
5151 "Interactively choose a viewing method for the MIME part under point."
5153 (gnus-article-check-buffer)
5154 (let ((data (get-text-property (point) 'gnus-data)))
5156 (setq gnus-article-mime-handles
5158 gnus-article-mime-handles (setq data (copy-sequence data))))
5159 (mm-interactively-view-part data))))
5161 (defun gnus-mime-view-part-as-type-internal ()
5162 (gnus-article-check-buffer)
5163 (let* ((handle (get-text-property (point) 'gnus-data))
5165 ;; Content-Type: foo/bar; name=...
5166 (mail-content-type-get (mm-handle-type handle) 'name)
5167 ;; Content-Disposition: attachment; filename=...
5168 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5169 (def-type (and name (mm-default-file-encoding name))))
5170 (or (and def-type (cons def-type 0))
5172 (equal (mm-handle-media-supertype handle) "text")
5173 '("text/plain" . 0))
5174 '("application/octet-stream" . 0))))
5176 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5177 "Choose a MIME media type, and view the part as such.
5178 If non-nil, PRED is a predicate to use during completion to limit the
5179 available media-types."
5183 (let ((default (gnus-mime-view-part-as-type-internal)))
5184 (gnus-completing-read
5187 (gnus-remove-if-not pred (mailcap-mime-types))
5188 (mailcap-mime-types))
5191 (gnus-article-check-buffer)
5192 (let ((handle (get-text-property (point) 'gnus-data)))
5194 (when (equal (mm-handle-media-type handle) "message/external-body")
5195 (unless (mm-handle-cache handle)
5196 (mm-extern-cache-contents handle))
5197 (setq handle (mm-handle-cache handle)))
5199 (mm-make-handle (mm-handle-buffer handle)
5200 (cons mime-type (cdr (mm-handle-type handle)))
5201 (mm-handle-encoding handle)
5202 (mm-handle-undisplayer handle)
5203 (mm-handle-disposition handle)
5204 (mm-handle-description handle)
5206 (mm-handle-id handle)))
5207 (setq gnus-article-mime-handles
5208 (mm-merge-handles gnus-article-mime-handles handle))
5209 (when (mm-handle-displayed-p handle)
5210 (mm-remove-part handle))
5211 (gnus-mm-display-part handle))))
5213 (defun gnus-mime-copy-part (&optional handle arg)
5214 "Put the MIME part under point into a new buffer.
5215 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5217 (interactive (list nil current-prefix-arg))
5218 (gnus-article-check-buffer)
5220 (setq handle (get-text-property (point) 'gnus-data)))
5222 (let ((filename (mm-handle-filename handle))
5223 contents dont-decode charset coding-system)
5224 (mm-with-unibyte-buffer
5225 (mm-insert-part handle)
5226 (setq contents (or (condition-case nil
5227 (mm-decompress-buffer filename nil 'sig)
5229 (setq dont-decode t)
5232 (setq filename (cond (filename (file-name-nondirectory filename))
5233 (dont-decode "*raw data*")
5238 (unless (setq charset (mail-content-type-get
5239 (mm-handle-type handle) 'charset))
5240 (unless (setq coding-system (mm-with-unibyte-buffer
5242 (mm-find-buffer-file-coding-system)))
5243 (setq charset gnus-newsgroup-charset))))
5245 (setq charset (or (cdr (assq arg
5246 gnus-summary-show-article-charset-alist))
5247 (mm-read-coding-system "Charset: ")))))
5248 (switch-to-buffer (generate-new-buffer filename))
5249 (if (or coding-system
5251 (setq coding-system (mm-charset-to-coding-system charset))
5252 (not (eq coding-system 'ascii))))
5254 (mm-enable-multibyte)
5255 (insert (mm-decode-coding-string contents coding-system))
5256 (setq buffer-file-coding-system
5257 (if (boundp 'last-coding-system-used)
5258 (symbol-value 'last-coding-system-used)
5260 (mm-disable-multibyte)
5262 (setq buffer-file-coding-system mm-binary-coding-system))
5263 ;; We do it this way to make `normal-mode' set the appropriate mode.
5266 (setq buffer-file-name (expand-file-name filename))
5268 (setq buffer-file-name nil))
5269 (goto-char (point-min)))))
5271 (defun gnus-mime-print-part (&optional handle filename)
5272 "Print the MIME part under point."
5273 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5274 (gnus-article-check-buffer)
5275 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5276 (contents (and handle (mm-get-part handle)))
5277 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5278 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5283 (mm-save-part-to-file handle file)
5284 (call-process shell-file-name nil
5285 (generate-new-buffer " *mm*")
5287 shell-command-switch
5289 printer file (mm-handle-type handle))))
5293 (gnus-print-buffer))
5294 (ps-despool filename)))))
5296 (defun gnus-mime-inline-part (&optional handle arg)
5297 "Insert the MIME part under point into the current buffer.
5298 Compressed files like .gz and .bz2 are decompressed."
5299 (interactive (list nil current-prefix-arg))
5300 (gnus-article-check-buffer)
5302 (setq handle (get-text-property (point) 'gnus-data)))
5305 (inhibit-read-only t)
5306 contents charset coding-system)
5307 (if (and (not arg) (mm-handle-undisplayer handle))
5308 (mm-remove-part handle)
5309 (mm-with-unibyte-buffer
5310 (mm-insert-part handle)
5312 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5316 (unless (setq charset (mail-content-type-get
5317 (mm-handle-type handle) 'charset))
5318 (unless (setq coding-system
5319 (mm-with-unibyte-buffer
5321 (mm-find-buffer-file-coding-system)))
5322 (setq charset gnus-newsgroup-charset))))
5324 (if (mm-handle-undisplayer handle)
5325 (mm-remove-part handle))
5328 gnus-summary-show-article-charset-alist))
5329 (mm-read-coding-system "Charset: "))))
5331 (if (mm-handle-undisplayer handle)
5332 (mm-remove-part handle))))
5334 (mm-display-inline handle)
5337 (defun gnus-mime-set-charset-parameters (handle charset)
5338 "Set CHARSET to parameters in HANDLE.
5339 CHARSET may either be a string or a symbol."
5340 (unless (stringp charset)
5341 (setq charset (symbol-name charset)))
5342 (if (stringp (car handle))
5343 (dolist (h (cdr handle))
5344 (gnus-mime-set-charset-parameters h charset))
5345 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5346 "message/external-body")
5348 (unless (mm-handle-cache handle)
5349 (mm-extern-cache-contents handle))
5350 (mm-handle-cache handle))
5352 (param (assq 'charset (cdr type))))
5354 (setcdr param charset)
5355 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5357 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5358 "Insert the MIME part under point into the current buffer using the
5360 (interactive (list nil current-prefix-arg))
5361 (gnus-article-check-buffer)
5362 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5363 (fun (get-text-property (point) 'gnus-callback))
5364 (gnus-newsgroup-ignored-charsets 'gnus-all)
5365 charset form preferred parts)
5372 gnus-summary-show-article-charset-alist))
5373 (mm-read-coding-system "Charset: "))))
5374 (if (mm-handle-undisplayer handle)
5375 (mm-remove-part handle)))
5376 (gnus-mime-set-charset-parameters handle charset)
5377 (when (and (consp (setq form (cdr-safe fun)))
5378 (setq form (ignore-errors
5379 (assq 'gnus-mime-display-alternative form)))
5380 (setq preferred (caddr form))
5382 (when (eq (car preferred) 'quote)
5383 (setq preferred (cadr preferred)))
5384 (not (equal preferred
5385 (get-text-property (point) 'gnus-data))))
5386 (setq parts (get-text-property (point) 'gnus-part))
5387 (setq parts (cdr (assq parts
5388 gnus-article-mime-handle-alist)))
5389 (equal (mm-handle-media-type parts) "multipart/alternative")
5390 (setq parts (reverse (cdr parts))))
5392 (list 'quote (or (cadr (member preferred parts))
5394 (funcall fun handle)))))
5396 (defun gnus-mime-view-part-externally (&optional handle)
5397 "View the MIME part under point with an external viewer."
5399 (gnus-article-check-buffer)
5400 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5401 (mm-user-display-methods nil)
5402 (mm-inlined-types nil)
5403 (mail-parse-charset gnus-newsgroup-charset)
5404 (mail-parse-ignored-charsets
5405 (with-current-buffer gnus-summary-buffer
5406 gnus-newsgroup-ignored-charsets))
5407 (type (mm-handle-media-type handle))
5408 (method (mailcap-mime-info type))
5409 (mm-enable-external t))
5410 (if (not (stringp method))
5411 (gnus-mime-view-part-as-type
5412 nil (lambda (type) (stringp (mailcap-mime-info type))))
5414 (mm-display-part handle nil t)))))
5416 (defun gnus-mime-view-part-internally (&optional handle)
5417 "View the MIME part under point with an internal viewer.
5418 If no internal viewer is available, use an external viewer."
5420 (gnus-article-check-buffer)
5421 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5422 (mm-inlined-types '(".*"))
5423 (mm-inline-large-images t)
5424 (mail-parse-charset gnus-newsgroup-charset)
5425 (mail-parse-ignored-charsets
5426 (with-current-buffer gnus-summary-buffer
5427 gnus-newsgroup-ignored-charsets))
5428 (inhibit-read-only t))
5429 (if (not (mm-inlinable-p handle))
5430 (gnus-mime-view-part-as-type
5431 nil (lambda (type) (mm-inlinable-p handle type)))
5433 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5435 (defun gnus-mime-action-on-part (&optional action)
5436 "Do something with the MIME attachment at \(point\)."
5438 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5439 (gnus-article-check-buffer)
5440 (let ((action-pair (assoc action gnus-mime-action-alist)))
5442 (funcall (cdr action-pair)))))
5444 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5445 "Call FUNCTION on MIME part N.
5446 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5447 If INTERACTIVE, call FUNCTION interactively."
5449 ;; Check whether the article is displayed.
5450 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5451 (setq window (get-buffer-window gnus-article-buffer t))
5452 (frame-visible-p (setq frame (window-frame window))))
5453 (error "No article is displayed"))
5454 (with-current-buffer gnus-article-buffer
5455 ;; Check whether the article displays the right contents.
5456 (unless (with-current-buffer gnus-summary-buffer
5457 (eq gnus-current-article (gnus-summary-article-number)))
5458 (error "You should select the right article first"))
5460 (setq n (prefix-numeric-value n))
5462 (setq n (or (get-text-property pt 'gnus-part)
5464 (get-text-property (1- pt) 'gnus-part))
5465 (get-text-property (prog2
5471 (or (and (setq pt (previous-single-property-change
5474 (next-single-property-change (point) 'gnus-part)
5478 ;; Check whether the specified part exists.
5479 (when (> n (length gnus-article-mime-handle-alist))
5480 (error "No such part")))
5483 ;; To select the window is needed so that the cursor
5484 ;; might be visible on the MIME button.
5485 (select-window (prog1
5487 (setq window (selected-window))
5488 ;; Article may be displayed in the other frame.
5489 (gnus-select-frame-set-input-focus
5492 (setq frame (selected-frame))))))
5493 (when (gnus-article-goto-part n)
5494 ;; We point the cursor and the arrow at the MIME button
5495 ;; when the `function' prompt the user for something.
5496 (unless (and (pos-visible-in-window-p)
5497 (> (count-lines (point) (window-end))
5498 (/ (1- (window-height)) 3)))
5499 (recenter (/ (1- (window-height)) 3)))
5500 (let ((cursor-in-non-selected-windows t)
5501 (overlay-arrow-string "=>")
5502 (overlay-arrow-position (point-marker)))
5505 ((and no-handle interactive)
5506 (call-interactively function))
5511 function (get-text-property (point) 'gnus-data)))
5514 (get-text-property (point) 'gnus-data))))
5515 (set-marker overlay-arrow-position nil)
5516 (unless gnus-auto-select-part
5517 (gnus-select-frame-set-input-focus frame)
5518 (select-window window))))
5520 (if gnus-inhibit-mime-unbuttonizing
5521 ;; This is the default though the program shouldn't reach here.
5522 (error "No such part")
5523 ;; The part which doesn't have the MIME button is selected.
5524 ;; So, we display all the buttons and redo it.
5525 (let ((gnus-inhibit-mime-unbuttonizing t))
5526 (gnus-summary-show-article)
5527 (gnus-article-part-wrapper n function no-handle))))))
5529 (defun gnus-article-pipe-part (n)
5530 "Pipe MIME part N, which is the numerical prefix."
5532 (gnus-article-part-wrapper n 'mm-pipe-part))
5534 (defun gnus-article-save-part (n)
5535 "Save MIME part N, which is the numerical prefix."
5537 (gnus-article-part-wrapper n 'mm-save-part))
5539 (defun gnus-article-interactively-view-part (n)
5540 "View MIME part N interactively, which is the numerical prefix."
5542 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5544 (defun gnus-article-copy-part (n)
5545 "Copy MIME part N, which is the numerical prefix."
5547 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5549 (defun gnus-article-view-part-as-charset (n)
5550 "View MIME part N using a specified charset.
5551 N is the numerical prefix."
5553 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5555 (defun gnus-article-view-part-externally (n)
5556 "View MIME part N externally, which is the numerical prefix."
5558 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5560 (defun gnus-article-inline-part (n)
5561 "Inline MIME part N, which is the numerical prefix."
5563 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5565 (defun gnus-article-save-part-and-strip (n)
5566 "Save MIME part N and replace it with an external body.
5567 N is the numerical prefix."
5569 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5571 (defun gnus-article-replace-part (n)
5572 "Replace MIME part N with an external body.
5573 N is the numerical prefix."
5575 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5577 (defun gnus-article-delete-part (n)
5578 "Delete MIME part N and add some information about the removed part.
5579 N is the numerical prefix."
5581 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5583 (defun gnus-article-view-part-as-type (n)
5584 "Choose a MIME media type, and view part N as such.
5585 N is the numerical prefix."
5587 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5589 (defun gnus-article-mime-match-handle-first (condition)
5592 (dolist (ihandle gnus-article-mime-handle-alist)
5594 ((functionp condition)
5595 (funcall condition (cdr ihandle)))
5596 ((eq condition 'undisplayed)
5597 (not (or (mm-handle-undisplayer (cdr ihandle))
5598 (equal (mm-handle-media-type (cdr ihandle))
5599 "multipart/alternative"))))
5600 ((eq condition 'undisplayed-alternative)
5601 (not (mm-handle-undisplayer (cdr ihandle))))
5603 (gnus-article-goto-part (car ihandle))
5604 (or (not n) (< (car ihandle) n)))
5605 (setq n (car ihandle))))
5609 (defun gnus-article-view-part (&optional n)
5610 "View MIME part N, which is the numerical prefix.
5611 If the part is already shown, hide the part. If N is nil, view
5614 (with-current-buffer gnus-article-buffer
5615 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5616 gnus-article-mime-match-handle-function)))
5617 (when (> n (length gnus-article-mime-handle-alist))
5618 (error "No such part"))
5619 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5620 (when (gnus-article-goto-part n)
5621 (if (equal (car handle) "multipart/alternative")
5622 (gnus-article-press-button)
5623 (when (eq (gnus-mm-display-part handle) 'internal)
5624 (gnus-set-window-start)))))))
5626 (defsubst gnus-article-mime-total-parts ()
5627 (if (bufferp (car gnus-article-mime-handles))
5629 (1- (length gnus-article-mime-handles))))
5631 (defun gnus-mm-display-part (handle)
5632 "Display HANDLE and fix MIME button."
5633 (let ((id (get-text-property (point) 'gnus-part))
5635 (inhibit-read-only t))
5638 (let ((window (selected-window))
5639 (mail-parse-charset gnus-newsgroup-charset)
5640 (mail-parse-ignored-charsets
5641 (if (gnus-buffer-live-p gnus-summary-buffer)
5642 (with-current-buffer gnus-summary-buffer
5643 gnus-newsgroup-ignored-charsets)
5647 (let ((win (gnus-get-buffer-window (current-buffer) t))
5650 (select-window win))
5653 (if (mm-handle-displayed-p handle)
5654 ;; This will remove the part.
5655 (mm-display-part handle)
5657 (narrow-to-region (point)
5658 (if (eobp) (point) (1+ (point))))
5659 (gnus-bind-safe-url-regexp (mm-display-part handle))
5660 ;; We narrow to the part itself and
5661 ;; then call the treatment functions.
5662 (goto-char (point-min))
5664 (narrow-to-region (point) (point-max))
5667 (gnus-article-mime-total-parts)
5668 (mm-handle-media-type handle)))))
5669 (if (window-live-p window)
5670 (select-window window)))))
5673 (gnus-insert-mime-button
5674 handle id (list (mm-handle-displayed-p handle)))
5675 (goto-char point))))
5677 (defun gnus-article-goto-part (n)
5678 "Go to MIME part N."
5679 (when gnus-break-pages
5682 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5683 part handle end next handles)
5686 (if (setq handle (get-text-property start 'gnus-data))
5688 ;; Go to the displayed subpart, assuming this is
5689 ;; multipart/alternative.
5692 (while (and (not handle)
5695 (setq next (text-property-not-all part end
5698 handle (get-text-property part 'gnus-data))
5699 (push (cons handle part) handles)
5700 (unless (mm-handle-displayed-p handle)
5702 part (text-property-any part end 'gnus-data nil))))
5704 ;; No subpart is displayed, so we find preferred one.
5706 (cdr (assq (mm-preferred-alternative
5707 (nreverse (mapcar 'car handles)))
5710 (goto-char (1+ part))
5712 (when gnus-break-pages
5713 (gnus-narrow-to-page))))
5715 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5716 (let ((gnus-tmp-name
5717 (or (mm-handle-filename handle)
5718 (mail-content-type-get (mm-handle-type handle) 'url)
5720 (gnus-tmp-type (mm-handle-media-type handle))
5721 (gnus-tmp-description (or (mm-handle-description handle) ""))
5723 (if (if displayed (car displayed)
5724 (mm-handle-displayed-p handle))
5726 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5728 gnus-tmp-type-long b e)
5729 (when (string-match ".*/" gnus-tmp-name)
5730 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5731 (setq gnus-tmp-type-long (concat gnus-tmp-type
5732 (and (not (equal gnus-tmp-name ""))
5733 (concat "; " gnus-tmp-name))))
5734 (unless (equal gnus-tmp-description "")
5735 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5740 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5741 `(keymap ,gnus-mime-button-map
5742 gnus-callback gnus-mm-display-part
5743 gnus-part ,gnus-tmp-id
5744 article-type annotation
5748 ;; Exclude a newline.
5751 (when gnus-article-button-face
5752 (gnus-overlay-put (gnus-make-overlay b e nil t)
5753 'face gnus-article-button-face))
5754 (widget-convert-button
5757 :action 'gnus-widget-press-button
5758 :button-keymap gnus-mime-button-map
5761 ;; Needed to properly clear the message due to a bug in
5762 ;; wid-edit (XEmacs only).
5763 (if (boundp 'help-echo-owns-message)
5764 (setq help-echo-owns-message t))
5766 "%S: %s the MIME part; %S: more options"
5767 (aref gnus-mouse-2 0)
5768 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5770 (aref gnus-down-mouse-3 0))))))
5772 (defun gnus-widget-press-button (elems el)
5773 (goto-char (widget-get elems :from))
5774 (gnus-article-press-button))
5776 (defvar gnus-displaying-mime nil)
5778 (defun gnus-display-mime (&optional ihandles)
5779 "Display the MIME parts."
5781 (save-selected-window
5782 (let ((window (get-buffer-window gnus-article-buffer))
5785 (select-window window)
5786 ;; We have to do this since selecting the window
5787 ;; may change the point. So we set the window point.
5788 (set-window-point window point)))
5789 (let ((handles ihandles)
5790 (inhibit-read-only t)
5793 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5794 (when gnus-article-emulate-mime
5795 (mm-uu-dissect-text-parts handles)))
5796 (gnus-article-emulate-mime
5797 (setq handles (mm-uu-dissect))))
5798 (when (and (not ihandles)
5799 (not gnus-displaying-mime))
5800 ;; Top-level call; we clean up.
5801 (when gnus-article-mime-handles
5802 (mm-destroy-parts gnus-article-mime-handles)
5803 (setq gnus-article-mime-handle-alist nil));; A trick.
5804 (setq gnus-article-mime-handles handles)
5805 ;; We allow users to glean info from the handles.
5806 (when gnus-article-mime-part-function
5807 (gnus-mime-part-function handles)))
5809 (or (not (stringp (car handles)))
5812 (when (and (not ihandles)
5813 (not gnus-displaying-mime))
5814 ;; Clean up for mime parts.
5816 (delete-region (point) (point-max)))
5817 (let ((gnus-displaying-mime t))
5818 (gnus-mime-display-part handles)))
5821 (narrow-to-region (point) (point-max))
5822 (gnus-treat-article nil 1 1 "text/plain")
5825 ;; Highlight the headers.
5829 (narrow-to-region (point-min) (point))
5830 (gnus-article-save-original-date
5831 (gnus-treat-article 'head)))))))
5832 ;; Cope with broken MIME messages.
5833 (goto-char (point-max))
5837 (defcustom gnus-mime-display-multipart-as-mixed nil
5838 "Display \"multipart\" parts as \"multipart/mixed\".
5840 If t, it overrides nil values of
5841 `gnus-mime-display-multipart-alternative-as-mixed' and
5842 `gnus-mime-display-multipart-related-as-mixed'."
5843 :group 'gnus-article-mime
5846 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5847 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5849 :group 'gnus-article-mime
5852 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5853 "Display \"multipart/related\" parts as \"multipart/mixed\".
5855 If displaying \"text/html\" is discouraged \(see
5856 `mm-discouraged-alternatives'\) images or other material inside a
5857 \"multipart/related\" part might be overlooked when this variable is nil."
5859 :group 'gnus-article-mime
5862 (defun gnus-mime-display-part (handle)
5864 ;; Maybe a broken MIME message.
5867 ((not (stringp (car handle)))
5868 (gnus-mime-display-single handle))
5869 ;; User-defined multipart
5870 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5871 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5873 ;; multipart/alternative
5874 ((and (equal (car handle) "multipart/alternative")
5875 (not (or gnus-mime-display-multipart-as-mixed
5876 gnus-mime-display-multipart-alternative-as-mixed)))
5877 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5878 (push (cons id handle) gnus-article-mime-handle-alist)
5879 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5880 ;; multipart/related
5881 ((and (equal (car handle) "multipart/related")
5882 (not (or gnus-mime-display-multipart-as-mixed
5883 gnus-mime-display-multipart-related-as-mixed)))
5884 ;;;!!!We should find the start part, but we just default
5885 ;;;!!!to the first part.
5886 ;;(gnus-mime-display-part (cadr handle))
5887 ;;;!!! Most multipart/related is an HTML message plus images.
5888 ;;;!!! Unfortunately we are unable to let W3 display those
5889 ;;;!!! included images, so we just display it as a mixed multipart.
5890 ;;(gnus-mime-display-mixed (cdr handle))
5891 ;;;!!! No, w3 can display everything just fine.
5892 (gnus-mime-display-part (cadr handle)))
5893 ((equal (car handle) "multipart/signed")
5894 (gnus-add-wash-type 'signed)
5895 (gnus-mime-display-security handle))
5896 ((equal (car handle) "multipart/encrypted")
5897 (gnus-add-wash-type 'encrypted)
5898 (gnus-mime-display-security handle))
5899 ;; Other multiparts are handled like multipart/mixed.
5901 (gnus-mime-display-mixed (cdr handle)))))
5903 (defun gnus-mime-part-function (handles)
5904 (if (stringp (car handles))
5905 (mapcar 'gnus-mime-part-function (cdr handles))
5906 (funcall gnus-article-mime-part-function handles)))
5908 (defun gnus-mime-display-mixed (handles)
5909 (mapcar 'gnus-mime-display-part handles))
5911 (defun gnus-mime-display-single (handle)
5912 (let ((type (mm-handle-media-type handle))
5913 (ignored gnus-ignored-mime-types)
5920 (when (string-match (pop ignored) type)
5921 (throw 'ignored nil)))
5922 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5923 (with-current-buffer gnus-summary-buffer
5924 gnus-inhibit-images)
5925 gnus-inhibit-images)
5926 (string-match "\\`image/" type)))
5927 (setq not-attachment
5928 (and (not (mm-inline-override-p handle))
5929 (or (not (mm-handle-disposition handle))
5930 (equal (car (mm-handle-disposition handle))
5932 (mm-attachment-override-p handle))))
5933 (mm-automatic-display-p handle)
5935 (mm-inlinable-p handle)
5936 (mm-inlined-p handle))
5937 (mm-automatic-external-display-p type)))
5939 (when (equal (mm-handle-media-supertype handle) "text")
5941 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5943 (push (cons id handle) gnus-article-mime-handle-alist)
5945 (equal (mm-handle-media-supertype handle) "message"))
5948 (cond ((not (bolp)) 2)
5949 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5951 (when (or (not display)
5952 (not (gnus-unbuttonized-mime-type-p type))
5953 (eq id gnus-mime-buttonized-part-id))
5954 (gnus-insert-mime-button
5955 handle id (list (or display (and not-attachment text))))
5956 (gnus-article-insert-newline)
5957 ;; Remember modify the number of forward lines.
5965 (let ((mail-parse-charset gnus-newsgroup-charset)
5966 (mail-parse-ignored-charsets
5967 (save-excursion (condition-case ()
5968 (set-buffer gnus-summary-buffer)
5970 gnus-newsgroup-ignored-charsets)))
5971 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5972 (goto-char (point-max)))
5973 ((and text not-attachment)
5977 (gnus-article-insert-newline)
5978 (mm-display-inline handle)
5979 (goto-char (point-max))))
5983 (narrow-to-region beg (point))
5984 (if (eq handle gnus-article-mime-handles)
5985 ;; The format=flowed case.
5986 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5987 ;; Don't count signature parts that are never displayed.
5988 ;; The part number should be re-calculated supposing this
5989 ;; might be a message/rfc822 part.
5991 (dolist (part gnus-article-mime-handles)
5992 (unless (or (stringp part)
5993 (equal (car (mm-handle-type part))
5994 "application/pgp-signature"))
5995 (push part handles)))
5997 nil (length (memq handle handles)) (length handles)
5998 (mm-handle-media-type handle)))))))))))
6000 (defun gnus-unbuttonized-mime-type-p (type)
6001 "Say whether TYPE is to be unbuttonized."
6002 (unless gnus-inhibit-mime-unbuttonizing
6004 (let ((types gnus-unbuttonized-mime-types))
6006 (when (string-match (pop types) type)
6007 (throw 'found t)))))
6009 (let ((types gnus-buttonized-mime-types))
6011 (when (string-match (pop types) type)
6012 (throw 'found t)))))))))
6014 (defun gnus-article-insert-newline ()
6015 "Insert a newline, but mark it as undeletable."
6016 (gnus-put-text-property
6017 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6019 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6020 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6023 handle (inhibit-read-only t) from props begend not-pref)
6024 (save-window-excursion
6027 (narrow-to-region (car ibegend)
6030 (goto-char (car ibegend))
6033 (delete-region (point-min) (point-max))
6034 (mm-remove-parts handles))
6035 (setq begend (list (point-marker)))
6037 (unless (setq not-pref (cadr (member preferred ihandles)))
6038 (setq not-pref (car ihandles)))
6041 (not (gnus-unbuttonized-mime-type-p
6042 "multipart/alternative")))
6043 (gnus-add-text-properties
6046 (insert (format "%d. " id))
6050 (unless ,(not ibegend)
6051 (setq gnus-article-mime-handle-alist
6052 ',gnus-article-mime-handle-alist))
6053 (gnus-mime-display-alternative
6054 ',ihandles ',not-pref ',begend ,id))
6055 keymap ,gnus-mime-button-map
6056 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6057 face ,gnus-article-button-face
6059 article-type multipart
6061 (widget-convert-button 'link from (point)
6062 :action 'gnus-widget-press-button
6063 :button-keymap gnus-widget-button-keymap)
6065 (while (setq handle (pop handles))
6066 (gnus-add-text-properties
6069 (insert (format "(%c) %-18s"
6070 (if (equal handle preferred) ?* ? )
6071 (mm-handle-media-type handle)))
6075 (unless ,(not ibegend)
6076 (setq gnus-article-mime-handle-alist
6077 ',gnus-article-mime-handle-alist))
6078 (gnus-mime-display-alternative
6079 ',ihandles ',handle ',begend ,id))
6080 keymap ,gnus-mime-button-map
6081 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6082 face ,gnus-article-button-face
6086 (widget-convert-button 'link from (point)
6087 :action 'gnus-widget-press-button
6088 :button-keymap gnus-widget-button-keymap)
6092 (if (stringp (car preferred))
6093 (gnus-display-mime preferred)
6094 (let ((mail-parse-charset gnus-newsgroup-charset)
6095 (mail-parse-ignored-charsets
6096 (with-current-buffer gnus-summary-buffer
6097 gnus-newsgroup-ignored-charsets)))
6098 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6102 (narrow-to-region (car begend) (point-max))
6104 nil (length gnus-article-mime-handle-alist)
6105 (gnus-article-mime-total-parts)
6106 (mm-handle-media-type preferred))))))
6107 (goto-char (point-max))
6108 (setcdr begend (point-marker)))))
6110 (goto-char point))))
6112 (defconst gnus-article-wash-status-strings
6113 (let ((alist '((cite "c" "Possible hidden citation text"
6114 " " "All citation text visible")
6115 (headers "h" "Hidden headers"
6116 " " "All headers visible.")
6117 (pgp "p" "Encrypted or signed message status hidden"
6118 " " "No hidden encryption nor digital signature status")
6119 (signature "s" "Signature has been hidden"
6120 " " "Signature is visible")
6121 (overstrike "o" "Overstrike (^H) characters applied"
6122 " " "No overstrike characters applied")
6123 (emphasis "e" "/*_Emphasis_*/ characters applied"
6124 " " "No /*_emphasis_*/ characters applied")))
6126 (dolist (entry alist result)
6127 (let ((key (nth 0 entry))
6128 (on (copy-sequence (nth 1 entry)))
6129 (on-help (nth 2 entry))
6130 (off (copy-sequence (nth 3 entry)))
6131 (off-help (nth 4 entry)))
6132 (put-text-property 0 1 'help-echo on-help on)
6133 (put-text-property 0 1 'help-echo off-help off)
6134 (push (list key on off) result))))
6135 "Alist of strings describing wash status in the mode line.
6136 Each entry has the form (KEY ON OF), where the KEY is a symbol
6137 representing the particular washing function, ON is the string to use
6138 in the article mode line when the washing function is active, and OFF
6139 is the string to use when it is inactive.")
6141 (defun gnus-article-wash-status-entry (key value)
6142 (let ((entry (assoc key gnus-article-wash-status-strings)))
6143 (if value (nth 1 entry) (nth 2 entry))))
6145 (defun gnus-article-wash-status ()
6146 "Return a string which display status of article washing."
6147 (with-current-buffer gnus-article-buffer
6148 (let ((cite (memq 'cite gnus-article-wash-types))
6149 (headers (memq 'headers gnus-article-wash-types))
6150 (boring (memq 'boring-headers gnus-article-wash-types))
6151 (pgp (memq 'pgp gnus-article-wash-types))
6152 (pem (memq 'pem gnus-article-wash-types))
6153 (signed (memq 'signed gnus-article-wash-types))
6154 (encrypted (memq 'encrypted gnus-article-wash-types))
6155 (signature (memq 'signature gnus-article-wash-types))
6156 (overstrike (memq 'overstrike gnus-article-wash-types))
6157 (emphasis (memq 'emphasis gnus-article-wash-types)))
6159 (gnus-article-wash-status-entry 'cite cite)
6160 (gnus-article-wash-status-entry 'headers (or headers boring))
6161 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6162 (gnus-article-wash-status-entry 'signature signature)
6163 (gnus-article-wash-status-entry 'overstrike overstrike)
6164 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6166 (defun gnus-add-wash-type (type)
6167 "Add a washing of TYPE to the current status."
6168 (add-to-list 'gnus-article-wash-types type))
6170 (defun gnus-delete-wash-type (type)
6171 "Add a washing of TYPE to the current status."
6172 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6174 (defun gnus-add-image (category image)
6175 "Add IMAGE of CATEGORY to the list of displayed images."
6176 (let ((entry (assq category gnus-article-image-alist)))
6178 (setq entry (list category))
6179 (push entry gnus-article-image-alist))
6180 (nconc entry (list image))))
6182 (defun gnus-delete-images (category)
6183 "Delete all images in CATEGORY."
6184 (let ((entry (assq category gnus-article-image-alist)))
6185 (dolist (image (cdr entry))
6186 (gnus-remove-image image category))
6187 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6188 (gnus-delete-wash-type category)))
6190 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6192 (defun gnus-article-maybe-hide-headers ()
6193 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6194 Provided for backwards compatibility."
6195 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6196 (not (with-current-buffer gnus-summary-buffer
6197 gnus-have-all-headers)))
6198 (not gnus-inhibit-hiding))
6199 (gnus-article-hide-headers)))
6201 (declare-function shr-put-image "shr" (data alt))
6203 (defun gnus-shr-put-image (data alt)
6204 "Put image DATA with a string ALT. Enable image to be deleted."
6205 (let ((image (shr-put-image data (propertize (or alt "*")
6206 'gnus-image-category 'shr))))
6208 (gnus-add-image 'shr image))))
6212 (defun gnus-output-to-file (file-name)
6213 "Append the current article to a file named FILE-NAME.
6214 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6215 text and used as the value of the coding cookie which is added to the
6216 top of a file. Otherwise, this function saves a raw article without
6218 (let* ((artbuf (current-buffer))
6219 (file-name-coding-system nnmail-pathname-coding-system)
6220 (coding gnus-article-save-coding-system)
6221 (coding-system-for-read (if coding
6222 nil ;; Rely on the coding cookie.
6223 mm-text-coding-system))
6224 (coding-system-for-write (or coding
6225 mm-text-coding-system-for-write
6226 mm-text-coding-system))
6227 (exists (file-exists-p file-name)))
6230 (insert-file-contents file-name)
6231 (goto-char (point-min))
6232 ;; Remove the existing coding cookie.
6233 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6234 (delete-region (match-beginning 0) (match-end 0))))
6235 (goto-char (point-max))
6236 (insert-buffer-substring artbuf)
6237 ;; Append newline at end of the buffer as separator, and then
6239 (goto-char (point-max))
6242 ;; If the coding system is not suitable to encode the text,
6243 ;; ask a user for a proper one.
6244 (when (fboundp 'select-safe-coding-system)
6245 (setq coding (coding-system-base
6246 (save-window-excursion
6247 (select-safe-coding-system (point-min) (point-max)
6249 (setq coding-system-for-write
6250 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6252 (goto-char (point-min))
6253 ;; Add the coding cookie.
6254 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6255 coding-system-for-write)))
6258 (write-region (point-min) (point-max) file-name nil 'no-message)
6259 (message "Appended to %s" file-name))
6260 (write-region (point-min) (point-max) file-name))))
6263 (defun gnus-narrow-to-page (&optional arg)
6264 "Narrow the article buffer to a page.
6265 If given a numerical ARG, move forward ARG pages."
6267 (setq arg (if arg (prefix-numeric-value arg) 0))
6268 (with-current-buffer gnus-article-buffer
6270 ;; Remove any old next/prev buttons.
6271 (when (gnus-visual-p 'page-marker)
6272 (let ((inhibit-read-only t))
6273 (gnus-remove-text-with-property 'gnus-prev)
6274 (gnus-remove-text-with-property 'gnus-next)))
6276 (when (save-excursion
6278 (if (re-search-backward page-delimiter nil 'move (abs arg))
6280 (setq nd (match-beginning 0)
6282 (when (re-search-backward page-delimiter nil t)
6283 (setq st (match-end 0))))
6284 (when (re-search-forward page-delimiter nil t)
6285 (setq nd (match-beginning 0)
6288 (if (re-search-forward page-delimiter nil 'move arg)
6290 (setq st (match-end 0)
6292 (when (re-search-forward page-delimiter nil t)
6293 (setq nd (match-beginning 0))))
6294 (when (re-search-backward page-delimiter nil t)
6295 (setq st (match-end 0)
6298 (when (re-search-backward page-delimiter nil t)
6299 (goto-char (setq st (match-end 0))))
6300 (when (re-search-forward page-delimiter nil t)
6301 (setq nd (match-beginning 0)))
6303 (setq gnus-page-broken t)
6304 (when pt (goto-char pt))
6305 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6306 (when (gnus-visual-p 'page-marker)
6310 (gnus-insert-next-page-button))
6313 (gnus-insert-prev-page-button))))))))
6315 ;; Article mode commands
6317 (defun gnus-article-goto-next-page ()
6318 "Show the next page of the article."
6320 (when (gnus-article-next-page)
6321 (goto-char (point-min))
6322 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6325 (defun gnus-article-goto-prev-page ()
6326 "Show the previous page of the article."
6328 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6329 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6330 (gnus-article-prev-page nil)))
6332 ;; This is cleaner but currently breaks `gnus-pick-mode':
6334 ;; (defun gnus-article-goto-next-page ()
6335 ;; "Show the next page of the article."
6337 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6338 ;; (gnus-summary-next-page)))
6340 ;; (defun gnus-article-goto-prev-page ()
6341 ;; "Show the next page of the article."
6343 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6344 ;; (gnus-summary-prev-page)))
6346 (defun gnus-article-next-page (&optional lines)
6347 "Show the next page of the current article.
6348 If end of article, return non-nil. Otherwise return nil.
6349 Argument LINES specifies lines to be scrolled up."
6351 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6352 (if (and (not (and gnus-article-over-scroll
6353 (> (count-lines (window-start) (point-max))
6354 (if (featurep 'xemacs)
6355 (or lines (1- (window-height)))
6356 (+ (or lines (1- (window-height))) scroll-margin)))))
6359 (and (pos-visible-in-window-p) ;Not continuation line.
6360 (>= (point) (point-max)))))
6361 ;; Nothing in this page.
6362 (if (or (not gnus-page-broken)
6367 (eobp)))) ;Real end-of-buffer?
6369 (when gnus-article-over-scroll
6370 (gnus-article-next-page-1 lines))
6372 (gnus-narrow-to-page 1) ;Go to next page.
6374 ;; More in this page.
6375 (gnus-article-next-page-1 lines)
6378 (defun gnus-article-beginning-of-window ()
6379 "Move point to the beginning of the window.
6380 In Emacs, the point is placed at the line number which `scroll-margin'
6382 (if (featurep 'xemacs)
6383 (move-to-window-line 0)
6384 ;; There is an obscure bug in Emacs that makes it impossible to
6385 ;; scroll past big pictures in the article buffer. Try to fix
6386 ;; this by adding a sanity check by counting the lines visible.
6387 (when (> (count-lines (window-start) (window-end)) 30)
6388 (move-to-window-line
6389 (min (max 0 scroll-margin)
6390 (max 1 (- (window-height)
6391 (if mode-line-format 1 0)
6392 (if header-line-format 1 0)
6395 (defun gnus-article-next-page-1 (lines)
6397 (let ((scroll-in-place nil)
6398 (auto-window-vscroll nil))
6401 ;; Long lines may cause an end-of-buffer error.
6402 (goto-char (point-max))))
6403 (gnus-article-beginning-of-window))
6405 (defun gnus-article-prev-page (&optional lines)
6406 "Show previous page of current article.
6407 Argument LINES specifies lines to be scrolled down."
6409 (move-to-window-line 0)
6410 (if (and gnus-page-broken
6412 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6414 (gnus-narrow-to-page -1) ;Go to previous page.
6415 (goto-char (point-max))
6416 (recenter (if gnus-article-over-scroll
6418 (max (if (featurep 'xemacs)
6420 (+ lines scroll-margin))
6422 (- (window-height) 2))
6426 (let ((scroll-in-place nil))
6427 (scroll-down lines))
6428 (beginning-of-buffer
6429 (goto-char (point-min))))
6430 (gnus-article-beginning-of-window))))
6432 (defun gnus-article-only-boring-p ()
6433 "Decide whether there is only boring text remaining in the article.
6434 Something \"interesting\" is a word of at least two letters that does
6435 not have a face in `gnus-article-boring-faces'."
6436 (when (and gnus-article-skip-boring
6437 (boundp 'gnus-article-boring-faces)
6438 (symbol-value 'gnus-article-boring-faces))
6440 (let ((inhibit-point-motion-hooks t))
6442 (while (re-search-forward "\\b\\w\\w" nil t)
6444 (when (not (gnus-intersection
6445 (gnus-faces-at (point))
6446 (symbol-value 'gnus-article-boring-faces)))
6447 (throw 'only-boring nil)))
6448 (throw 'only-boring t))))))
6450 (defun gnus-article-refer-article ()
6451 "Read article specified by message-id around point."
6454 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6455 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6456 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6457 (let ((msg-id (concat "<" (match-string 0) ">")))
6458 (set-buffer gnus-summary-buffer)
6459 (gnus-summary-refer-article msg-id))
6460 (error "No references around point"))))
6462 (defun gnus-article-show-summary ()
6463 "Reconfigure windows to show summary buffer."
6465 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6466 (error "There is no summary buffer for this article buffer")
6467 (gnus-article-set-globals)
6468 (gnus-configure-windows 'article)
6469 (gnus-summary-goto-subject gnus-current-article)
6470 (gnus-summary-position-point)))
6472 (defun gnus-article-describe-briefly ()
6473 "Describe article mode commands briefly."
6475 (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")))
6477 (defun gnus-article-check-buffer ()
6478 "Beep if not in an article buffer."
6479 (unless (equal major-mode 'gnus-article-mode)
6480 (error "Command invoked outside of a Gnus article buffer")))
6482 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6483 "Read a summary buffer key sequence and execute it from the article buffer."
6485 (gnus-article-check-buffer)
6487 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6488 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6489 "=" "^" "\M-^" "|"))
6491 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6492 "An" "Ap" [?A (meta return)] [?A delete]))
6496 '("n" "Gn" "p" "Gp"))
6498 (with-current-buffer gnus-article-current-summary
6499 (let (gnus-pick-mode)
6500 (setq unread-command-events (nconc unread-command-events
6501 (list (or key last-command-event)))
6502 keys (if (featurep 'xemacs)
6503 (events-to-keys (read-key-sequence nil t))
6504 (read-key-sequence nil t)))))
6509 ((eq (aref keys (1- (length keys))) ?\C-h)
6510 (gnus-article-describe-bindings (substring keys 0 -1)))
6511 ((or (member keys nosaves)
6512 (member keys nosave-but-article)
6513 (member keys nosave-in-article))
6515 (save-window-excursion
6516 (pop-to-buffer gnus-article-current-summary)
6517 ;; We disable the pick minor mode commands.
6518 (let (gnus-pick-mode)
6519 (setq func (key-binding keys t))))
6523 (unless (member keys nosave-in-article)
6524 (set-buffer gnus-article-current-summary))
6525 (when (get func 'disabled)
6526 (error "Function %s disabled" func))
6527 (call-interactively func)
6528 (setq new-sum-point (point)))
6529 (when (member keys nosave-but-article)
6530 (pop-to-buffer gnus-article-buffer))))
6532 ;; These commands should restore window configuration.
6533 (let ((obuf (current-buffer))
6534 (owin (current-window-configuration))
6535 win func in-buffer selected new-sum-start new-sum-hscroll err)
6536 (cond (not-restore-window
6537 (pop-to-buffer gnus-article-current-summary)
6538 (setq win (selected-window)))
6539 ((setq win (get-buffer-window gnus-article-current-summary))
6540 (select-window win))
6542 (let ((summary-buffer gnus-article-current-summary))
6543 (gnus-configure-windows 'article)
6544 (unless (setq win (get-buffer-window summary-buffer 'visible))
6545 (let ((gnus-buffer-configuration
6546 '((article ((vertical 1.0
6547 (summary 0.25 point)
6549 (gnus-configure-windows 'article))
6550 (setq win (get-buffer-window summary-buffer 'visible)))
6551 (gnus-select-frame-set-input-focus (window-frame win))
6552 (select-window win))))
6553 (setq in-buffer (current-buffer))
6554 ;; We disable the pick minor mode commands.
6555 (setq func (let (gnus-pick-mode)
6556 (key-binding keys t)))
6557 (when (get func 'disabled)
6558 (error "Function %s disabled" func))
6561 (condition-case code
6563 (call-interactively func)
6569 (when (eq win (selected-window))
6570 (setq new-sum-point (point)
6571 new-sum-start (window-start win)
6572 new-sum-hscroll (window-hscroll win)))
6573 (when (or (eq in-buffer (current-buffer))
6574 (when (eq obuf (current-buffer))
6575 (set-buffer in-buffer)
6577 (setq selected (gnus-summary-select-article))
6579 (unless not-restore-window
6580 (set-window-configuration owin))
6581 (when (and (eq selected 'old)
6583 (set-window-start (get-buffer-window (current-buffer))
6585 (set-window-point (get-buffer-window (current-buffer))
6586 (if (article-goto-body)
6589 (when (and (not not-restore-window)
6592 (with-current-buffer (window-buffer win)
6593 (eq major-mode 'gnus-summary-mode)))
6594 (set-window-point win new-sum-point)
6595 (set-window-start win new-sum-start)
6596 (set-window-hscroll win new-sum-hscroll))))
6597 (set-window-configuration owin)
6599 (signal (car err) (cdr err))
6602 (defun gnus-article-read-summary-send-keys ()
6604 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6605 (gnus-article-read-summary-keys)))
6607 (defun gnus-article-describe-key (key)
6608 "Display documentation of the function invoked by KEY.
6609 KEY is a string or a vector."
6610 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6611 (read-key-sequence "Describe key: "))))
6612 (gnus-article-check-buffer)
6613 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6614 gnus-article-read-summary-send-keys))
6615 (with-current-buffer gnus-article-current-summary
6616 (setq unread-command-events
6617 (if (featurep 'xemacs)
6619 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6620 (list 'meta (- x 128))
6623 (let ((cursor-in-echo-area t)
6625 (describe-key (read-key-sequence nil t))))
6626 (describe-key key)))
6628 (defun gnus-article-describe-key-briefly (key &optional insert)
6629 "Display documentation of the function invoked by KEY.
6630 KEY is a string or a vector."
6631 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6632 (read-key-sequence "Describe key: "))
6633 current-prefix-arg))
6634 (gnus-article-check-buffer)
6635 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6636 gnus-article-read-summary-send-keys))
6637 (with-current-buffer gnus-article-current-summary
6638 (setq unread-command-events
6639 (if (featurep 'xemacs)
6641 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6642 (list 'meta (- x 128))
6645 (let ((cursor-in-echo-area t)
6647 (describe-key-briefly (read-key-sequence nil t) insert)))
6648 (describe-key-briefly key insert)))
6650 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6651 (defvar gnus-agent-summary-mode)
6652 (defvar gnus-draft-mode)
6653 ;; Calling help-buffer will autoload help-mode.
6654 (defvar help-xref-stack-item)
6655 ;; Emacs 22 doesn't load it in the batch mode.
6657 (autoload 'help-buffer "help-mode"))
6659 (defun gnus-article-describe-bindings (&optional prefix)
6660 "Show a list of all defined keys, and their definitions.
6661 The optional argument PREFIX, if non-nil, should be a key sequence;
6662 then we display only bindings that start with that prefix."
6664 (gnus-article-check-buffer)
6665 (let ((keymap (copy-keymap gnus-article-mode-map))
6666 (map (copy-keymap gnus-article-send-map))
6667 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6669 (define-key keymap "S" map)
6670 (define-key map [t] nil)
6671 (with-current-buffer gnus-article-current-summary
6674 (if (setq parent (keymap-parent gnus-article-mode-map))
6676 (setq parent (copy-keymap parent))
6677 (set-keymap-parent parent (current-local-map)))
6678 (current-local-map)))
6679 (set-keymap-parent map (key-binding "S"))
6680 (let (key def gnus-pick-mode)
6682 (setq key (pop sumkeys))
6683 (cond ((and (vectorp key) (= (length key) 1)
6684 (consp (setq def (aref key 0)))
6685 (numberp (car def)) (numberp (cdr def)))
6686 (when (< (max (car def) (cdr def)) 128)
6690 (nreverse (gnus-uncompress-range def)))
6692 ((setq def (key-binding key))
6693 (unless (eq def 'undefined)
6694 (define-key keymap key def))))))
6695 (when (boundp 'gnus-agent-summary-mode)
6696 (setq agent gnus-agent-summary-mode))
6697 (when (boundp 'gnus-draft-mode)
6698 (setq draft gnus-draft-mode)))
6700 (use-local-map keymap)
6701 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6702 (set (make-local-variable 'gnus-draft-mode) draft)
6703 (describe-bindings prefix))
6704 (let ((item `((lambda (prefix)
6705 (with-current-buffer ,(current-buffer)
6706 (gnus-article-describe-bindings prefix)))
6708 (with-current-buffer (let (help-xref-following) (help-buffer))
6709 (setq help-xref-stack-item item)))))
6711 (defun gnus-article-reply-with-original (&optional wide)
6712 "Start composing a 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 (let ((article (cdr gnus-article-current))
6718 (if (not (gnus-region-active-p))
6719 (with-current-buffer gnus-summary-buffer
6720 (gnus-summary-reply (list (list article)) wide))
6721 (setq contents (buffer-substring (point) (mark t)))
6722 ;; Deactivate active regions.
6723 (when (and (boundp 'transient-mark-mode)
6724 transient-mark-mode)
6725 (setq mark-active nil))
6726 (with-current-buffer gnus-summary-buffer
6728 (list (list article contents)) wide)))))
6730 (defun gnus-article-wide-reply-with-original ()
6731 "Start composing a wide reply mail to the current message.
6732 The text in the region will be yanked. If the region isn't active,
6733 the entire article will be yanked."
6735 (gnus-article-reply-with-original t))
6737 (defun gnus-article-followup-with-original ()
6738 "Compose a followup to the current article.
6739 The text in the region will be yanked. If the region isn't active,
6740 the entire article will be yanked."
6742 (let ((article (cdr gnus-article-current))
6744 (if (not (gnus-region-active-p))
6745 (with-current-buffer gnus-summary-buffer
6746 (gnus-summary-followup (list (list article))))
6747 (setq contents (buffer-substring (point) (mark t)))
6748 ;; Deactivate active regions.
6749 (when (and (boundp 'transient-mark-mode)
6750 transient-mark-mode)
6751 (setq mark-active nil))
6752 (with-current-buffer gnus-summary-buffer
6753 (gnus-summary-followup
6754 (list (list article contents)))))))
6756 (defun gnus-article-hide (&optional arg force)
6757 "Hide all the gruft in the current article.
6758 This means that signatures, cited text and (some) headers will be
6760 If given a prefix, show the hidden text instead."
6761 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6762 (gnus-article-hide-headers arg)
6763 (gnus-article-hide-list-identifiers arg)
6764 (gnus-article-hide-citation-maybe arg force)
6765 (gnus-article-hide-signature arg))
6767 (defun gnus-article-maybe-highlight ()
6768 "Do some article highlighting if article highlighting is requested."
6769 (when (gnus-visual-p 'article-highlight 'highlight)
6770 (gnus-article-highlight-some)))
6772 (defun gnus-check-group-server ()
6773 ;; Make sure the connection to the server is alive.
6774 (unless (gnus-server-opened
6775 (gnus-find-method-for-group gnus-newsgroup-name))
6776 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6777 (gnus-request-group gnus-newsgroup-name t)))
6780 (autoload 'nneething-get-file-name "nneething"))
6782 (defun gnus-request-article-this-buffer (article group)
6783 "Get an article and insert it into this buffer."
6784 (let (do-update-line sparse-header)
6788 (gnus-kill-all-overlays)
6789 (setq group (or group gnus-newsgroup-name))
6791 ;; Using `gnus-request-article' directly will insert the article into
6792 ;; `nntp-server-buffer' - so we'll save some time by not having to
6793 ;; copy it from the server buffer into the article buffer.
6795 ;; We only request an article by message-id when we do not have the
6796 ;; headers for it, so we'll have to get those.
6797 (when (stringp article)
6798 (gnus-read-header article))
6800 ;; If the article number is negative, that means that this article
6801 ;; doesn't belong in this newsgroup (possibly), so we find its
6802 ;; message-id and request it by id instead of number.
6803 (when (and (numberp article)
6805 (get-buffer gnus-summary-buffer)
6806 (gnus-buffer-exists-p gnus-summary-buffer))
6807 (with-current-buffer gnus-summary-buffer
6808 (let ((header (gnus-summary-article-header article)))
6811 ((memq article gnus-newsgroup-sparse)
6812 ;; This is a sparse gap article.
6813 (setq do-update-line article)
6814 (setq article (mail-header-id header))
6815 (setq sparse-header (gnus-read-header article))
6816 (setq gnus-newsgroup-sparse
6817 (delq article gnus-newsgroup-sparse)))
6819 ;; It's a real article.
6820 (setq article (mail-header-id header)))
6822 ;; It is an extracted pseudo-article.
6823 (setq article 'pseudo)
6824 (gnus-request-pseudo-article header))))
6826 (let ((method (gnus-find-method-for-group
6827 gnus-newsgroup-name)))
6828 (when (and (eq (car method) 'nneething)
6830 (let ((dir (nneething-get-file-name
6831 (mail-header-id header))))
6832 (when (and (stringp dir)
6833 (file-directory-p dir))
6834 (setq article 'nneething)
6835 (gnus-group-enter-directory dir))))))))
6838 ;; Refuse to select canceled articles.
6839 ((and (numberp article)
6841 (get-buffer gnus-summary-buffer)
6842 (gnus-buffer-exists-p gnus-summary-buffer)
6843 (eq (cdr (with-current-buffer gnus-summary-buffer
6844 (assq article gnus-newsgroup-reads)))
6845 gnus-canceled-mark))
6847 ;; We first check `gnus-original-article-buffer'.
6848 ((and (get-buffer gnus-original-article-buffer)
6850 (with-current-buffer gnus-original-article-buffer
6851 (and (equal (car gnus-original-article) group)
6852 (eq (cdr gnus-original-article) article))))
6853 ;; `insert-buffer-substring' would incorrectly use the
6854 ;; equivalent of string-make-multibyte which amount to decoding
6855 ;; with locale-coding-system, causing failure of
6856 ;; subsequent decoding.
6857 (insert (mm-string-to-multibyte
6858 (with-current-buffer gnus-original-article-buffer
6859 (buffer-substring (point-min) (point-max)))))
6861 ;; Check the backlog.
6862 ((and gnus-keep-backlog
6863 (gnus-backlog-request-article group article (current-buffer)))
6865 ;; Check asynchronous pre-fetch.
6866 ((gnus-async-request-fetched-article group article (current-buffer))
6867 (gnus-async-prefetch-next group article gnus-summary-buffer)
6868 (when (and (numberp article) gnus-keep-backlog)
6869 (gnus-backlog-enter-article group article (current-buffer)))
6872 ((and gnus-use-cache
6874 (gnus-cache-request-article article group))
6876 ;; Check the agent cache.
6877 ((gnus-agent-request-article article group)
6879 ;; Get the article and put into the article buffer.
6880 ((or (stringp article)
6882 (let ((gnus-override-method gnus-override-method)
6883 (methods (and (stringp article)
6884 (with-current-buffer gnus-summary-buffer
6885 (gnus-refer-article-methods))))
6886 (backend (car (gnus-find-method-for-group
6887 gnus-newsgroup-name)))
6889 (inhibit-read-only t))
6890 (when (and (null gnus-override-method)
6892 (setq gnus-override-method (pop methods)))
6895 (gnus-kill-all-overlays)
6896 (let ((gnus-newsgroup-name group))
6897 (gnus-check-group-server))
6899 ((gnus-request-article article group (current-buffer))
6900 (when (numberp article)
6901 (gnus-async-prefetch-next group article
6902 gnus-summary-buffer)
6903 (when gnus-keep-backlog
6904 (gnus-backlog-enter-article
6905 group article (current-buffer)))
6906 (when (and gnus-agent
6907 (gnus-agent-group-covered-p group))
6908 (gnus-agent-store-article article group)))
6909 (setq result 'article))
6911 (setq gnus-override-method (pop methods)))
6912 ((not (string-match "^400 "
6913 (nnheader-get-report backend)))
6914 ;; If we get 400 server disconnect, reconnect and
6915 ;; retry; otherwise, assume the article has expired.
6916 (setq result 'done))))
6917 (and (eq result 'article) 'article)))
6921 ;; Associate this article with the current summary buffer.
6922 (setq gnus-article-current-summary gnus-summary-buffer)
6924 ;; Take the article from the original article buffer
6925 ;; and place it in the buffer it's supposed to be in.
6926 (when (and (get-buffer gnus-article-buffer)
6927 (equal (buffer-name (current-buffer))
6928 (buffer-name (get-buffer gnus-article-buffer))))
6930 (if (get-buffer gnus-original-article-buffer)
6931 (set-buffer gnus-original-article-buffer)
6932 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6933 (buffer-disable-undo)
6934 (setq major-mode 'gnus-original-article-mode)
6935 (setq buffer-read-only t))
6936 (let ((inhibit-read-only t))
6938 (insert-buffer-substring gnus-article-buffer))
6939 (setq gnus-original-article (cons group article)))
6942 (run-hooks 'gnus-article-decode-hook)
6943 ;; Mark article as decoded or not.
6944 (setq gnus-article-decoded-p gnus-article-decode-hook))
6946 ;; Update sparse articles.
6947 (when (and do-update-line
6948 (or (numberp article)
6950 (let ((buf (current-buffer)))
6951 (set-buffer gnus-summary-buffer)
6952 (gnus-summary-update-article do-update-line sparse-header)
6953 (gnus-summary-goto-subject do-update-line nil t)
6954 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6956 (set-buffer buf))))))
6958 (defun gnus-block-private-groups (group)
6959 (if (gnus-news-group-p group)
6960 ;; Block nothing in news groups.
6962 ;; Block everything anywhere else.
6965 (defun gnus-blocked-images ()
6966 (if (functionp gnus-blocked-images)
6967 (funcall gnus-blocked-images gnus-newsgroup-name)
6968 gnus-blocked-images))
6974 (defcustom gnus-article-edit-mode-hook nil
6975 "Hook run in article edit mode buffers."
6976 :group 'gnus-article-various
6979 (defvar gnus-article-edit-done-function nil)
6981 (defvar gnus-article-edit-mode-map nil)
6983 ;; Should we be using derived.el for this?
6984 (unless gnus-article-edit-mode-map
6985 (setq gnus-article-edit-mode-map (make-keymap))
6986 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6988 (gnus-define-keys gnus-article-edit-mode-map
6989 "\C-c?" describe-mode
6990 "\C-c\C-c" gnus-article-edit-done
6991 "\C-c\C-k" gnus-article-edit-exit
6992 "\C-c\C-f\C-t" message-goto-to
6993 "\C-c\C-f\C-o" message-goto-from
6994 "\C-c\C-f\C-b" message-goto-bcc
6995 ;;"\C-c\C-f\C-w" message-goto-fcc
6996 "\C-c\C-f\C-c" message-goto-cc
6997 "\C-c\C-f\C-s" message-goto-subject
6998 "\C-c\C-f\C-r" message-goto-reply-to
6999 "\C-c\C-f\C-n" message-goto-newsgroups
7000 "\C-c\C-f\C-d" message-goto-distribution
7001 "\C-c\C-f\C-f" message-goto-followup-to
7002 "\C-c\C-f\C-m" message-goto-mail-followup-to
7003 "\C-c\C-f\C-k" message-goto-keywords
7004 "\C-c\C-f\C-u" message-goto-summary
7005 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7006 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7007 "\C-c\C-b" message-goto-body
7008 "\C-c\C-i" message-goto-signature
7010 "\C-c\C-t" message-insert-to
7011 "\C-c\C-n" message-insert-newsgroups
7012 "\C-c\C-o" message-sort-headers
7013 "\C-c\C-e" message-elide-region
7014 "\C-c\C-v" message-delete-not-region
7015 "\C-c\C-z" message-kill-to-signature
7016 "\M-\r" message-newline-and-reformat
7017 "\C-c\C-a" mml-attach-file
7018 "\C-a" message-beginning-of-line
7020 "\M-;" comment-region)
7022 (gnus-define-keys (gnus-article-edit-wash-map
7023 "\C-c\C-w" gnus-article-edit-mode-map)
7024 "f" gnus-article-edit-full-stops))
7027 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7029 ["Fetch To" message-insert-to t]
7030 ["Fetch Newsgroups" message-insert-newsgroups t]
7032 ["To" message-goto-to t]
7033 ["From" message-goto-from t]
7034 ["Subject" message-goto-subject t]
7035 ["Cc" message-goto-cc t]
7036 ["Reply-To" message-goto-reply-to t]
7037 ["Summary" message-goto-summary t]
7038 ["Keywords" message-goto-keywords t]
7039 ["Newsgroups" message-goto-newsgroups t]
7040 ["Followup-To" message-goto-followup-to t]
7041 ["Mail-Followup-To" message-goto-mail-followup-to t]
7042 ["Distribution" message-goto-distribution t]
7043 ["Body" message-goto-body t]
7044 ["Signature" message-goto-signature t]))
7046 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7047 "Major mode for editing articles.
7048 This is an extended text-mode.
7050 \\{gnus-article-edit-mode-map}"
7051 (make-local-variable 'gnus-article-edit-done-function)
7052 (make-local-variable 'gnus-prev-winconf)
7053 (set (make-local-variable 'font-lock-defaults)
7054 '(message-font-lock-keywords t))
7055 (set (make-local-variable 'mail-header-separator) "")
7056 (set (make-local-variable 'gnus-article-edit-mode) t)
7057 (easy-menu-add message-mode-field-menu message-mode-map)
7059 (setq buffer-read-only nil)
7060 (buffer-enable-undo)
7063 (defun gnus-article-edit (&optional force)
7064 "Edit the current article.
7065 This will have permanent effect only in mail groups.
7066 If FORCE is non-nil, allow editing of articles even in read-only
7069 (when (and (not force)
7070 (gnus-group-read-only-p))
7071 (error "The current newsgroup does not support article editing"))
7072 (gnus-article-date-original)
7073 (gnus-article-edit-article
7075 `(lambda (no-highlight)
7077 (gnus-summary-edit-article-done
7078 ,(or (mail-header-references gnus-current-headers) "")
7079 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7081 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7082 "Start editing the contents of the current article buffer."
7083 (let ((winconf (current-window-configuration)))
7084 (set-buffer gnus-article-buffer)
7085 (let ((message-auto-save-directory
7086 ;; Don't associate the article buffer with a draft file.
7088 (gnus-article-edit-mode))
7089 (funcall start-func)
7090 (set-buffer-modified-p nil)
7091 (gnus-configure-windows 'edit-article)
7092 (setq gnus-article-edit-done-function exit-func)
7093 (setq gnus-prev-winconf winconf)
7095 (gnus-message 6 "C-c C-c to end edits"))))
7097 (defun gnus-article-edit-done (&optional arg)
7098 "Update the article edits and exit."
7100 (let ((func gnus-article-edit-done-function)
7101 (buf (current-buffer))
7102 (start (window-start))
7104 (winconf gnus-prev-winconf))
7105 (widen) ;; Widen it in case that users narrowed the buffer.
7108 ;; The cache and backlog have to be flushed somewhat.
7109 (when gnus-keep-backlog
7110 (gnus-backlog-remove-article
7111 (car gnus-article-current) (cdr gnus-article-current)))
7112 ;; Flush original article as well.
7113 (gnus-flush-original-article-buffer)
7114 (when gnus-use-cache
7115 (gnus-cache-update-article
7116 (car gnus-article-current) (cdr gnus-article-current)))
7117 ;; We remove all text props from the article buffer.
7118 (kill-all-local-variables)
7119 (set-text-properties (point-min) (point-max) nil)
7121 (set-window-configuration winconf)
7123 (set-window-start (get-buffer-window buf) start)
7124 (set-window-point (get-buffer-window buf) (point)))
7125 (gnus-summary-show-article))
7127 (defun gnus-flush-original-article-buffer ()
7128 (when (get-buffer gnus-original-article-buffer)
7129 (with-current-buffer gnus-original-article-buffer
7130 (setq gnus-original-article nil))))
7132 (defun gnus-article-edit-exit ()
7133 "Exit the article editing without updating."
7135 (when (or (not (buffer-modified-p))
7136 (yes-or-no-p "Article modified; kill anyway? "))
7137 (let ((curbuf (current-buffer))
7139 (window-start (window-start)))
7141 (if (gnus-buffer-live-p gnus-original-article-buffer)
7142 (insert-buffer-substring gnus-original-article-buffer))
7143 (let ((winconf gnus-prev-winconf))
7144 (kill-all-local-variables)
7146 (set-window-configuration winconf)
7147 ;; Tippy-toe some to make sure that point remains where it was.
7148 (save-current-buffer
7150 (set-window-start (get-buffer-window (current-buffer)) window-start)
7152 (gnus-summary-show-article)))
7154 (defun gnus-article-edit-full-stops ()
7155 "Interactively repair spacing at end of sentences."
7158 (goto-char (point-min))
7159 (search-forward-regexp "^$" nil t)
7160 (let ((case-fold-search nil))
7161 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7164 ;;; Article highlights
7167 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7169 ;;; Internal Variables:
7171 (defcustom gnus-button-url-regexp
7173 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7174 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7175 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7176 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7177 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7181 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7182 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7183 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7185 "[" chars punct "]+" "[" chars "]"
7187 (concat ;; XEmacs 21.4 doesn't support POSIX.
7188 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7189 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7191 "Regular expression that matches URLs."
7192 :group 'gnus-article-buttons
7195 (defcustom gnus-button-valid-fqdn-regexp
7196 message-valid-fqdn-regexp
7197 "Regular expression that matches a valid FQDN."
7199 :group 'gnus-article-buttons
7202 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7203 (defcustom gnus-button-valid-localpart-regexp
7204 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7205 "Regular expression that matches a localpart of mail addresses or MIDs."
7207 :group 'gnus-article-buttons
7210 (defcustom gnus-button-man-handler 'manual-entry
7211 "Function to use for displaying man pages.
7212 The function must take at least one argument with a string naming the
7215 :type '(choice (function-item :tag "Man" manual-entry)
7216 (function-item :tag "Woman" woman)
7217 (function :tag "Other"))
7218 :group 'gnus-article-buttons)
7220 (defcustom gnus-button-mid-or-mail-regexp
7221 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7222 gnus-button-valid-fqdn-regexp
7224 "Regular expression that matches a message ID or a mail address."
7226 :group 'gnus-article-buttons
7229 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7230 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7231 Strings like this can be either a message ID or a mail address. If it is one
7232 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7233 message ID or a mail address, respectively. If this variable is set to the
7234 symbol `ask', always query the user what do do. If it is a function, this
7235 function will be called with the string as its only argument. The function
7236 must return `mid', `mail', `invalid' or `ask'."
7238 :group 'gnus-article-buttons
7239 :type '(choice (function-item :tag "Heuristic function"
7240 gnus-button-mid-or-mail-heuristic)
7245 (defcustom gnus-button-mid-or-mail-heuristic-alist
7246 '((-10.0 . ".+\\$.+@")
7249 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7250 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7251 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7252 (-1.0 . "^[^a-z]+@")
7254 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7255 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7256 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7257 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7260 (-1.0 . "^[0-9][0-9]")
7262 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7263 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7264 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7265 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7267 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7268 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7271 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7273 ;; compensation for TDMA dated mail addresses:
7274 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7276 (-20.0 . "\\.fsf@") ;; Gnus
7279 (-20.0 . "^alpine\\.")
7280 (-20.0 . "_-_") ;; Subject change in thread
7282 (-20.0 . "\\.ln@") ;; leafnode
7283 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7284 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7286 ;; (5.0 . "") ;; $local_part_len <= 7
7287 (10.0 . "^[^0-9]+@")
7288 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7289 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7292 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7294 (0.5 . "^[A-Z][a-z]")
7295 (0.5 . "^[A-Z][a-z][a-z]")
7296 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7297 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7298 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7300 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7301 address. The REGEXP is processed with `case-fold-search' set to nil."
7303 :group 'gnus-article-buttons
7304 :type '(repeat (cons (number :tag "Rate")
7305 (regexp :tag "Regexp"))))
7307 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7308 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7309 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7310 address, `ask' if unsure and `invalid' if the string is invalid."
7311 (let ((case-fold-search nil)
7312 (list gnus-button-mid-or-mail-heuristic-alist)
7313 (result 0) rate regexp lpartlen elem)
7315 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7316 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7317 ;; Certain special cases...
7320 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7321 "^[0-9]+\\.[0-9]+@compuserve\\|"
7322 "@public\\.gmane\\.org")
7324 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7325 (setq result 'mail))
7326 (when (string-match "@.*@\\| " mid-or-mail)
7327 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7328 (setq result 'invalid))
7329 ;; Nothing more to do, if result is not a number here...
7330 (when (numberp result)
7332 (setq elem (car list)
7336 (when (string-match regexp mid-or-mail)
7337 (setq result (+ result rate))
7339 9 "`%s' matched `%s', rate `%s', result `%s'."
7340 mid-or-mail regexp rate result)))
7341 (when (<= lpartlen 7)
7342 (setq result (+ result 5.0))
7343 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7344 mid-or-mail result))
7345 (when (>= lpartlen 12)
7346 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7348 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7349 ;; Long local part should contain realname if e-mail address,
7350 ;; too many digits: message-id.
7351 ;; $score -= 5.0 + 0.1 * $local_part_len;
7352 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7353 (setq result (+ result rate))
7355 9 "Many digits in `%s', rate `%s', result `%s'."
7356 mid-or-mail rate result))
7357 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7359 ;; Too few vowels [^aeiouy]{4,}.*\@
7360 (setq result (+ result -5.0))
7362 9 "Few vowels in `%s', rate `%s', result `%s'."
7363 mid-or-mail -5.0 result))
7365 (setq result (+ result 5.0))
7367 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7368 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7369 ;; Maybe we should make this a customizable alist: (condition . 'result)
7371 ((symbolp result) result)
7372 ;; Now convert number into proper results:
7373 ((< result -10.0) 'mid)
7374 ((> result 10.0) 'mail)
7377 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7378 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7379 (url-mid (concat "news" ":" mid-or-mail))
7380 (url-mailto (concat "mailto" ":" mid-or-mail)))
7381 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7382 (when (fboundp pref)
7384 ;; get rid of surrounding angles...
7386 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7387 (if (or (eq 'mid guessed) (eq 'mail guessed))
7391 (save-window-excursion
7392 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7395 (cond ((eq pref 'mid)
7396 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7397 (gnus-button-handle-news url-mid))
7399 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7400 (gnus-url-mailto url-mailto))
7401 (t (gnus-message 3 "Invalid string.")))))
7403 (defun gnus-button-handle-custom (fun arg)
7404 "Call function FUN on argument ARG.
7405 Both FUN and ARG are supposed to be strings. ARG will be passed
7406 as a symbol to FUN."
7407 (funcall (intern fun)
7408 (if (string-match "^customize-apropos" fun)
7412 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7414 (defun gnus-button-handle-describe-function (url)
7415 "Call `describe-function' when pushing the corresponding URL button."
7418 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7420 (defun gnus-button-handle-describe-variable (url)
7421 "Call `describe-variable' when pushing the corresponding URL button."
7424 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7426 (defun gnus-button-handle-symbol (url)
7427 "Display help on variable or function.
7428 Calls `describe-variable' or `describe-function'."
7429 (let ((sym (intern url)))
7431 ((fboundp sym) (describe-function sym))
7432 ((boundp sym) (describe-variable sym))
7433 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7435 (defun gnus-button-handle-describe-key (url)
7436 "Call `describe-key' when pushing the corresponding URL button."
7438 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7439 (keys (ignore-errors (eval `(kbd ,key-string)))))
7442 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7444 (defun gnus-button-handle-apropos (url)
7445 "Call `apropos' when pushing the corresponding URL button."
7446 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7448 (defun gnus-button-handle-apropos-command (url)
7449 "Call `apropos' when pushing the corresponding URL button."
7451 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7453 (defun gnus-button-handle-apropos-variable (url)
7454 "Call `apropos' when pushing the corresponding URL button."
7456 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7457 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7459 (defun gnus-button-handle-apropos-documentation (url)
7460 "Call `apropos' when pushing the corresponding URL button."
7462 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7463 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7465 (defun gnus-button-handle-library (url)
7466 "Call `locate-library' when pushing the corresponding URL button."
7467 (gnus-message 9 "url=`%s'" url)
7468 (let* ((lib (locate-library url))
7469 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7471 (gnus-message 1 "Cannot locale library `%s'." url)
7472 (find-file-read-only file))))
7474 (defcustom gnus-button-man-level 5
7475 "*Integer that says how many man-related buttons Gnus will show.
7476 The higher the number, the more buttons will appear and the more false
7477 positives are possible. Note that you can set this variable local to
7478 specific groups. Setting it higher in Unix groups is probably a good idea.
7479 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7480 how to set variables in specific groups."
7482 :group 'gnus-article-buttons
7483 :link '(custom-manual "(gnus)Group Parameters")
7486 (defcustom gnus-button-emacs-level 5
7487 "*Integer that says how many emacs-related buttons Gnus will show.
7488 The higher the number, the more buttons will appear and the more false
7489 positives are possible. Note that you can set this variable local to
7490 specific groups. Setting it higher in Emacs or Gnus related groups is
7491 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7492 `gnus-parameters' on how to set variables in specific groups."
7494 :group 'gnus-article-buttons
7495 :link '(custom-manual "(gnus)Group Parameters")
7498 (defcustom gnus-button-message-level 5
7499 "*Integer that says how many buttons for news or mail messages will appear.
7500 The higher the number, the more buttons will appear and the more false
7501 positives are possible."
7502 ;; mail addresses, MIDs, URLs for news, ...
7504 :group 'gnus-article-buttons
7507 (defcustom gnus-button-browse-level 5
7508 "*Integer that says how many buttons for browsing will appear.
7509 The higher the number, the more buttons will appear and the more false
7510 positives are possible."
7511 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7513 :group 'gnus-article-buttons
7516 (defcustom gnus-button-alist
7517 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7518 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7519 ((concat "\\b\\(nntp\\|news\\):\\("
7520 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7521 0 t gnus-button-handle-news 2)
7522 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7523 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7524 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7525 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7526 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7527 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7528 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7529 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7530 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7531 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7532 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7533 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7534 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7535 ;; RFC 2368 (The mailto URL scheme)
7536 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7537 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7538 ("\\bmailto:\\([^ \n\t]+\\)"
7539 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7540 ;; Info Konqueror style <info:/foo/bar baz>.
7541 ;; Must come before " Gnus home-grown style".
7542 ("\\binfo://?\\([^'\">\n\t]+\\)"
7543 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7544 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7545 ("\\binfo://\\([^'\">\n\t ]+\\)"
7546 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7547 ;; Info GNOME style <info:foo#bar_baz>
7548 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7549 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7550 ;; Info KDE style <info:(foo)bar baz>
7551 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7552 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7553 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7554 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7555 ("\\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,]*\\)\\)?"
7556 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7557 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7559 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7560 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7561 ;; Emacs help commands
7562 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7563 ;; regexp doesn't match arguments containing ` '.
7564 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7565 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7566 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7567 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7568 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7569 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7570 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7571 ;; The following entries may lead to many false positives so don't enable
7572 ;; them by default (use a high button level).
7573 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7574 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7575 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7576 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7577 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7578 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7579 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7580 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7581 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7582 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7583 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7584 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7585 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7586 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7587 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7588 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7589 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7590 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7591 ;; Unlike the other regexps we really have to require quoting
7592 ;; here to determine where it ends.
7593 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7594 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7595 ("<URL: *\\([^\n<>]*\\)>"
7596 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7597 ;; RFC 2396 (2.4.3., delims) ...
7598 ("\"URL: *\\([^\n\"]*\\)\""
7599 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7601 (gnus-button-url-regexp
7602 0 (>= gnus-button-browse-level 0) browse-url 0)
7604 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7605 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7606 gnus-button-handle-man 1)
7607 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7608 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7609 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7610 gnus-button-handle-man 1)
7611 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7612 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7613 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7614 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7615 ;; Recognizing patches to .el files. This is somewhat obscure,
7616 ;; but considering the percentage of Gnus users who hack Emacs
7618 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7619 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7620 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7621 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7622 ;; MID or mail: To avoid too many false positives we don't try to catch
7623 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7624 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7625 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7626 ;; so that non-ambiguous entries (see above) match first.
7627 (gnus-button-mid-or-mail-regexp
7628 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7629 "*Alist of regexps matching buttons in article bodies.
7631 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7632 REGEXP: is the string (case insensitive) matching text around the button (can
7633 also be Lisp expression evaluating to a string),
7634 BUTTON: is the number of the regexp grouping actually matching the button,
7635 FORM: is a Lisp expression which must eval to true for the button to
7637 CALLBACK: is the function to call when the user push this button, and each
7638 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7640 CALLBACK can also be a variable, in that case the value of that
7641 variable it the real callback function."
7642 :group 'gnus-article-buttons
7643 :type '(repeat (list (choice regexp variable sexp)
7644 (integer :tag "Button")
7646 (function :tag "Callback")
7649 (integer :tag "Regexp group")))))
7650 (put 'gnus-button-alist 'risky-local-variable t)
7652 (defcustom gnus-header-button-alist
7653 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7654 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7655 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7656 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7657 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7658 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7659 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7660 0 (>= gnus-button-browse-level 0) browse-url 0)
7661 ("^Subject:" gnus-button-url-regexp
7662 0 (>= gnus-button-browse-level 0) browse-url 0)
7663 ("^[^:]+:" gnus-button-url-regexp
7664 0 (>= gnus-button-browse-level 0) browse-url 0)
7665 ("^OpenPGP:.*url=" gnus-button-url-regexp
7666 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7667 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7668 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7669 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7670 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7671 "*Alist of headers and regexps to match buttons in article heads.
7673 This alist is very similar to `gnus-button-alist', except that each
7674 alist has an additional HEADER element first in each entry:
7676 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7678 HEADER is a regexp to match a header. For a fuller explanation, see
7679 `gnus-button-alist'."
7680 :group 'gnus-article-buttons
7681 :group 'gnus-article-headers
7682 :type '(repeat (list (regexp :tag "Header")
7683 (choice regexp variable)
7684 (integer :tag "Button")
7686 (function :tag "Callback")
7689 (integer :tag "Regexp group")))))
7690 (put 'gnus-header-button-alist 'risky-local-variable t)
7694 (defun gnus-article-push-button (event)
7695 "Check text under the mouse pointer for a callback function.
7696 If the text under the mouse pointer has a `gnus-callback' property,
7697 call it with the value of the `gnus-data' text property."
7699 (set-buffer (window-buffer (posn-window (event-start event))))
7700 (let* ((pos (posn-point (event-start event)))
7701 (data (get-text-property pos 'gnus-data))
7702 (fun (get-text-property pos 'gnus-callback)))
7705 (funcall fun data))))
7707 (defun gnus-article-press-button ()
7708 "Check text at point for a callback function.
7709 If the text at point has a `gnus-callback' property,
7710 call it with the value of the `gnus-data' text property."
7712 (let ((data (get-text-property (point) 'gnus-data))
7713 (fun (get-text-property (point) 'gnus-callback)))
7715 (funcall fun data))))
7717 (defun gnus-article-highlight (&optional force)
7718 "Highlight current article.
7719 This function calls `gnus-article-highlight-headers',
7720 `gnus-article-highlight-citation',
7721 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7722 do the highlighting. See the documentation for those functions."
7723 (interactive (list 'force))
7724 (gnus-article-highlight-headers)
7725 (gnus-article-highlight-citation force)
7726 (gnus-article-highlight-signature)
7727 (gnus-article-add-buttons)
7728 (gnus-article-add-buttons-to-head))
7730 (defun gnus-article-highlight-some (&optional force)
7731 "Highlight current article.
7732 This function calls `gnus-article-highlight-headers',
7733 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7734 do the highlighting. See the documentation for those functions."
7735 (interactive (list 'force))
7736 (gnus-article-highlight-headers)
7737 (gnus-article-highlight-signature)
7738 (gnus-article-add-buttons))
7740 (defun gnus-article-highlight-headers ()
7741 "Highlight article headers as specified by `gnus-header-face-alist'."
7743 (gnus-with-article-headers
7744 (let (regexp header-face field-face from hpoints fpoints)
7745 (dolist (entry gnus-header-face-alist)
7746 (goto-char (point-min))
7747 (setq regexp (concat "^\\("
7748 (if (string-equal "" (nth 0 entry))
7752 header-face (nth 1 entry)
7753 field-face (nth 2 entry))
7754 (while (and (re-search-forward regexp nil t)
7758 (unless (search-forward ":" nil t)
7760 (when (and header-face
7761 (not (memq (point) hpoints)))
7762 (push (point) hpoints)
7763 (gnus-put-text-property from (point) 'face header-face))
7764 (when (and field-face
7765 (not (memq (setq from (point)) fpoints)))
7767 (if (re-search-forward "^[^ \t]" nil t)
7769 (goto-char (point-max)))
7770 (gnus-put-text-property from (point) 'face field-face)))))))
7772 (defun gnus-article-highlight-signature ()
7773 "Highlight the signature in an article.
7774 It does this by highlighting everything after
7775 `gnus-signature-separator' using the face `gnus-signature'."
7777 (gnus-with-article-buffer
7778 (let ((inhibit-point-motion-hooks t))
7780 (when (and gnus-signature-face
7781 (gnus-article-narrow-to-signature))
7782 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7783 'face gnus-signature-face)
7785 (gnus-article-search-signature)
7786 (let ((start (match-beginning 0))
7787 (end (set-marker (make-marker) (1+ (match-end 0)))))
7788 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7791 (defun gnus-button-in-region-p (b e prop)
7792 "Say whether PROP exists in the region."
7793 (text-property-not-all b e prop nil))
7795 (defun gnus-article-add-buttons ()
7796 "Find external references in the article and make buttons of them.
7797 \"External references\" are things like Message-IDs and URLs, as
7798 specified by `gnus-button-alist'."
7800 (gnus-with-article-buffer
7801 (let ((inhibit-point-motion-hooks t)
7802 (case-fold-search t)
7803 (alist gnus-button-alist)
7805 ;; We skip the headers.
7808 (while (setq entry (pop alist))
7809 (setq regexp (eval (car entry)))
7811 (while (re-search-forward regexp nil t)
7812 (let ((start (match-beginning (nth 1 entry)))
7813 (end (match-end (nth 1 entry)))
7814 (from (match-beginning 0)))
7815 (when (and (eval (nth 2 entry))
7816 (not (gnus-button-in-region-p
7817 start end 'gnus-callback)))
7818 ;; That optional form returned non-nil, so we add the
7820 (setq from (set-marker (make-marker) from))
7821 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7822 (gnus-article-extend-url-button from start end))
7823 (gnus-article-add-button start end
7824 'gnus-button-push (list from entry))
7825 (gnus-put-text-property
7827 'gnus-string (buffer-substring-no-properties
7830 (defun gnus-article-extend-url-button (beg start end)
7831 "Extend url button if url is folded into two or more lines.
7832 Return non-nil if button is extended. BEG is a marker that points to
7833 the beginning position of a text containing url. START and END are
7834 the endpoints of a url button before it is extended. The concatenated
7835 url is put as the `gnus-button-url' overlay property on the button."
7836 (let ((opoint (point))
7837 (points (list start end))
7842 (not (looking-at "[\t ]*[\">]")))
7846 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7847 (buffer-substring (point-at-bol) start)))
7849 (setq url (list (buffer-substring start end))
7850 delim (if (match-beginning 1) ">" "\""))
7852 (setq regexp (concat
7853 (when (and (looking-at
7854 message-cite-prefix-regexp)
7855 (< (match-end 0) start))
7856 (regexp-quote (match-string 0)))
7858 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7862 (and (looking-at regexp)
7865 (push (or (match-string 2)
7868 (push (setq end (or (match-end 2)
7871 (push (or (match-beginning 2)
7872 (match-beginning 1))
7874 (match-beginning 2)))
7875 (let (gnus-article-mouse-face widget-mouse-face)
7877 (gnus-article-add-button (pop points) (pop points)
7878 'gnus-button-push beg)))
7879 (let ((overlay (gnus-make-overlay start end)))
7880 (gnus-overlay-put overlay 'evaporate t)
7881 (gnus-overlay-put overlay 'gnus-button-url
7882 (list (mapconcat 'identity (nreverse url) "")))
7883 (when gnus-article-mouse-face
7884 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7886 (goto-char opoint))))
7888 ;; Add buttons to the head of an article.
7889 (defun gnus-article-add-buttons-to-head ()
7890 "Add buttons to the head of the article."
7892 (gnus-with-article-headers
7894 (dolist (entry gnus-header-button-alist)
7895 ;; Each alist entry.
7896 (goto-char (point-min))
7897 (while (re-search-forward (car entry) nil t)
7898 ;; Each header matching the entry.
7899 (setq beg (match-beginning 0))
7900 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7901 (match-beginning 0))
7904 (while (re-search-forward (eval (nth 1 entry)) end t)
7905 ;; Each match within a header.
7906 (let* ((entry (cdr entry))
7907 (start (match-beginning (nth 1 entry)))
7908 (end (match-end (nth 1 entry)))
7909 (form (nth 2 entry)))
7910 (goto-char (match-end 0))
7912 (gnus-article-add-button
7913 start end (nth 3 entry)
7914 (buffer-substring (match-beginning (nth 4 entry))
7915 (match-end (nth 4 entry)))))))
7916 (goto-char end))))))
7918 ;;; External functions:
7920 (defun gnus-article-add-button (from to fun &optional data text)
7921 "Create a button between FROM and TO with callback FUN and data DATA."
7922 (when gnus-article-button-face
7923 (gnus-overlay-put (gnus-make-overlay from to nil t)
7924 'face gnus-article-button-face))
7925 (gnus-add-text-properties
7927 (nconc (and gnus-article-mouse-face
7928 (list gnus-mouse-face-prop gnus-article-mouse-face))
7929 (list 'gnus-callback fun)
7930 (and data (list 'gnus-data data))))
7931 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7932 :help-echo (or text "Follow the link")
7933 :keymap gnus-url-button-map
7934 :button-keymap gnus-widget-button-keymap))
7936 (defun gnus-article-copy-string ()
7937 "Copy the string in the button to the kill ring."
7939 (gnus-article-check-buffer)
7940 (let ((data (get-text-property (point) 'gnus-string)))
7944 (copy-region-as-kill (point-min) (point-max))
7945 (message "Copied %s" data)))))
7947 ;;; Internal functions:
7949 (defun gnus-article-set-globals ()
7950 (with-current-buffer gnus-summary-buffer
7951 (gnus-set-global-variables)))
7953 (defun gnus-signature-toggle (end)
7954 (gnus-with-article-buffer
7955 (let ((inhibit-point-motion-hooks t))
7956 (if (text-property-any end (point-max) 'article-type 'signature)
7958 (gnus-delete-wash-type 'signature)
7959 (gnus-remove-text-properties-when
7960 'article-type 'signature end (point-max)
7961 (cons 'article-type (cons 'signature
7962 gnus-hidden-properties))))
7963 (gnus-add-wash-type 'signature)
7964 (gnus-add-text-properties-when
7965 'article-type nil end (point-max)
7966 (cons 'article-type (cons 'signature
7967 gnus-hidden-properties)))))
7968 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7969 (gnus-set-mode-line 'article))))
7971 (defun gnus-button-push (marker-and-entry)
7972 ;; Push button starting at MARKER.
7974 (let* ((marker (car marker-and-entry))
7975 (entry (cadr marker-and-entry))
7976 (regexp (car entry))
7977 (inhibit-point-motion-hooks t))
7979 ;; This is obviously true, or something bad is happening :)
7980 ;; But we need it to have the match-data
7981 (when (looking-at (or (if (symbolp regexp)
7982 (symbol-value regexp)
7984 (let ((fun (nth 3 entry))
7985 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7986 (get-char-property marker 'gnus-button-url))
7987 (mapcar (lambda (group)
7988 (let ((string (match-string group)))
7989 (set-text-properties
7990 0 (length string) nil string)
7992 (nthcdr 4 entry)))))
7998 (fboundp (symbol-value fun)))
7999 (apply (symbol-value fun) args))
8001 (gnus-message 1 "You must define `%S' to use this button"
8002 (cons fun args)))))))))
8004 (defun gnus-parse-news-url (url)
8005 (let (scheme server port group message-id articles)
8008 (goto-char (point-min))
8009 (when (looking-at "\\([A-Za-z]+\\):")
8010 (setq scheme (match-string 1))
8011 (goto-char (match-end 0)))
8012 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8013 (setq server (match-string 1))
8014 (setq port (if (stringp (match-string 3))
8015 (string-to-number (match-string 3))
8017 (goto-char (match-end 0)))
8020 ((looking-at "\\(.*@.*\\)")
8021 (setq message-id (match-string 1)))
8022 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8023 (setq group (match-string 1)
8024 articles (split-string (match-string 2) "-")))
8025 ((looking-at "\\([^/]+\\)/?")
8026 (setq group (match-string 1)))
8028 (error "Unknown news URL syntax"))))
8029 (list scheme server port group message-id articles)))
8031 (defun gnus-button-handle-news (url)
8033 (destructuring-bind (scheme server port group message-id articles)
8034 (gnus-parse-news-url url)
8037 (with-current-buffer gnus-summary-buffer
8039 (let ((gnus-refer-article-method
8040 (nconc (list (list 'nntp server))
8041 gnus-refer-article-method))
8042 (nntp-port-number (or port "nntp")))
8043 (gnus-message 7 "Fetching %s with %s"
8044 message-id gnus-refer-article-method)
8045 (gnus-summary-refer-article message-id))
8046 (gnus-summary-refer-article message-id))))
8048 (gnus-button-fetch-group url)))))
8050 (defun gnus-button-patch (library line)
8051 "Visit an Emacs Lisp library LIBRARY on line LINE."
8053 (let ((file (locate-library (file-name-nondirectory library))))
8055 (error "Couldn't find library %s" library))
8057 (goto-char (point-min))
8058 (forward-line (1- (string-to-number line)))))
8060 (defun gnus-button-handle-man (url)
8062 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8063 (when (eq gnus-button-man-handler 'woman)
8064 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8065 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8066 (funcall gnus-button-man-handler url))
8068 (defun gnus-button-handle-info-url (url)
8069 "Fetch an info URL."
8070 (setq url (mm-subst-char-in-string ?+ ?\ url))
8072 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8073 (gnus-info-find-node
8074 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8076 ")" (gnus-url-unhex-string (match-string 2 url)))))
8077 ((string-match "([^)\"]+)[^\"]+" url)
8079 (gnus-replace-in-string
8080 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8081 (gnus-info-find-node url))
8082 (t (error "Can't parse %s" url))))
8084 (defun gnus-button-handle-info-url-gnome (url)
8085 "Fetch GNOME style info URL."
8086 (setq url (mm-subst-char-in-string ?_ ?\ url))
8087 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8088 (gnus-info-find-node
8090 (gnus-url-unhex-string
8091 (match-string 1 url))
8093 (or (gnus-url-unhex-string
8094 (match-string 2 url))
8096 (error "Can't parse %s" url)))
8098 (defun gnus-button-handle-info-url-kde (url)
8099 "Fetch KDE style info URL."
8100 (gnus-info-find-node (gnus-url-unhex-string url)))
8102 ;; (info) will autoload info.el
8103 (declare-function Info-menu "info" (menu-item &optional fork))
8104 (declare-function Info-index-next "info" (num))
8106 (defun gnus-button-handle-info-keystrokes (url)
8107 "Call `info' when pushing the corresponding URL button."
8108 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8109 (let (node indx comma)
8111 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8112 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8113 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8114 "\\(?:[ \t\n,]*\\)\\)?")
8116 (setq node (match-string 2 url)
8117 indx (match-string 3 url))
8118 (error "Can't parse %s" url))
8122 (when (> (length indx) 0)
8123 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8126 (setq comma (match-string 2 indx))
8127 (setq indx (match-string 1 indx))
8130 (dotimes (i (with-temp-buffer
8132 ;; Note: the XEmacs version of `how-many' takes
8133 ;; no optional argument.
8134 (goto-char (point-min))
8136 (Info-index-next 1)))
8139 (autoload 'pgg-snarf-keys-region "pgg")
8140 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8141 (declare-function pgg-display-output-buffer "pgg" (start end status))
8143 (defun gnus-button-openpgp (url)
8144 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8146 (mm-url-insert-file-contents-external url)
8147 (pgg-snarf-keys-region (point-min) (point-max))
8148 (pgg-display-output-buffer nil nil nil)))
8150 (defun gnus-button-message-id (message-id)
8152 (with-current-buffer gnus-summary-buffer
8153 (gnus-summary-refer-article message-id)))
8155 (defun gnus-button-fetch-group (address &rest ignore)
8156 "Fetch GROUP specified by ADDRESS."
8157 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8159 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8160 ;; for nntp:// and news://
8161 (setq address (match-string 3 address)))
8162 (if (not (string-match "[:/]" address))
8163 ;; This is just a simple group url.
8164 (gnus-group-read-ephemeral-group address gnus-select-method)
8167 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8169 (error "Can't parse %s" address)
8170 (gnus-group-read-ephemeral-group
8171 (match-string 4 address)
8172 `(nntp ,(match-string 1 address)
8173 (nntp-address ,(match-string 1 address))
8174 (nntp-port-number ,(if (match-end 3)
8175 (match-string 3 address)
8178 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8180 (defun gnus-url-parse-query-string (query &optional downcase)
8181 (let (retval pairs cur key val)
8182 (setq pairs (split-string query "&"))
8184 (setq cur (car pairs)
8186 (if (not (string-match "=" cur))
8188 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8189 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8191 (setq key (downcase key)))
8192 (setq cur (assoc key retval))
8194 (setcdr cur (cons val (cdr cur)))
8195 (setq retval (cons (list key val) retval)))))
8198 (defun gnus-url-mailto (url)
8199 ;; Send mail to someone
8200 (setq url (replace-regexp-in-string "\n" " " url))
8201 (when (string-match "mailto:/*\\(.*\\)" url)
8202 (setq url (substring url (match-beginning 1) nil)))
8203 (let (to args subject func)
8204 (setq args (gnus-url-parse-query-string
8205 (if (string-match "^\\?" url)
8207 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8208 (concat "to=" (match-string 1 url) "&"
8209 (match-string 2 url))
8210 (concat "to=" url))))
8211 subject (cdr-safe (assoc "subject" args)))
8214 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8217 (message-position-on-field (caar args)))
8218 (insert (gnus-replace-in-string
8219 (mapconcat 'identity (reverse (cdar args)) ", ")
8221 (setq args (cdr args)))
8224 (message-goto-subject))))
8226 (defun gnus-button-embedded-url (address)
8227 "Activate ADDRESS with `browse-url'."
8228 (browse-url (gnus-strip-whitespace address)))
8230 ;;; Next/prev buttons in the article buffer.
8232 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8233 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8235 (defvar gnus-prev-page-map
8236 (let ((map (make-sparse-keymap)))
8237 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8238 (define-key map "\r" 'gnus-button-prev-page)
8241 (defvar gnus-next-page-map
8242 (let ((map (make-sparse-keymap)))
8243 (define-key map gnus-mouse-2 'gnus-button-next-page)
8244 (define-key map "\r" 'gnus-button-next-page)
8247 (defun gnus-insert-prev-page-button ()
8249 (inhibit-read-only t))
8251 gnus-prev-page-line-format nil
8252 `(keymap ,gnus-prev-page-map
8254 gnus-callback gnus-article-button-prev-page
8255 article-type annotation))
8257 ;; Exclude a newline.
8260 (when gnus-article-button-face
8261 (gnus-overlay-put (gnus-make-overlay b e nil t)
8262 'face gnus-article-button-face))
8263 (widget-convert-button
8265 :action 'gnus-button-prev-page
8266 :button-keymap gnus-prev-page-map)))
8268 (defun gnus-button-next-page (&optional args more-args)
8269 "Go to the next page."
8271 (let ((win (selected-window)))
8272 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8273 (gnus-article-next-page)
8274 (select-window win)))
8276 (defun gnus-button-prev-page (&optional args more-args)
8277 "Go to the prev page."
8279 (let ((win (selected-window)))
8280 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8281 (gnus-article-prev-page)
8282 (select-window win)))
8284 (defun gnus-insert-next-page-button ()
8286 (inhibit-read-only t))
8287 (gnus-eval-format gnus-next-page-line-format nil
8288 `(keymap ,gnus-next-page-map
8290 gnus-callback gnus-article-button-next-page
8291 article-type annotation))
8293 ;; Exclude a newline.
8296 (when gnus-article-button-face
8297 (gnus-overlay-put (gnus-make-overlay b e nil t)
8298 'face gnus-article-button-face))
8299 (widget-convert-button
8301 :action 'gnus-button-next-page
8302 :button-keymap gnus-next-page-map)))
8304 (defun gnus-article-button-next-page (arg)
8305 "Go to the next page."
8307 (let ((win (selected-window)))
8308 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8309 (gnus-article-next-page)
8310 (select-window win)))
8312 (defun gnus-article-button-prev-page (arg)
8313 "Go to the prev page."
8315 (let ((win (selected-window)))
8316 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8317 (gnus-article-prev-page)
8318 (select-window win)))
8320 (defvar gnus-decode-header-methods
8321 '(mail-decode-encoded-word-region)
8322 "List of methods used to decode headers.
8324 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8325 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8326 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8327 whose names match REGEXP.
8330 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8331 mail-decode-encoded-word-region
8332 (\"chinese\" . rfc1843-decode-region))
8335 (defvar gnus-decode-header-methods-cache nil)
8337 (defun gnus-multi-decode-header (start end)
8338 "Apply the functions from `gnus-encoded-word-methods' that match."
8339 (unless (and gnus-decode-header-methods-cache
8340 (eq gnus-newsgroup-name
8341 (car gnus-decode-header-methods-cache)))
8342 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8343 (dolist (x gnus-decode-header-methods)
8345 (nconc gnus-decode-header-methods-cache (list x))
8346 (if (and gnus-newsgroup-name
8347 (string-match (car x) gnus-newsgroup-name))
8348 (nconc gnus-decode-header-methods-cache
8350 (let ((xlist gnus-decode-header-methods-cache))
8353 (narrow-to-region start end)
8355 (funcall (pop xlist) (point-min) (point-max))))))
8358 ;;; Treatment top-level handling.
8361 (defvar gnus-inhibit-article-treatments nil)
8363 (defun gnus-treat-article (gnus-treat-condition
8364 &optional part-number total-parts gnus-treat-type)
8365 (let ((gnus-treat-length (- (point-max) (point-min)))
8366 (alist gnus-treatment-function-alist)
8367 (article-goto-body-goes-to-point-min-p t)
8369 (or (not gnus-treat-type)
8371 (let ((list gnus-article-treat-types))
8373 (when (string-match (pop list) gnus-treat-type)
8374 (throw 'found t)))))))
8375 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8377 (gnus-run-hooks 'gnus-part-display-hook)
8378 (dolist (elem alist)
8381 (when (gnus-buffer-live-p gnus-summary-buffer)
8382 (set-buffer gnus-summary-buffer))
8383 (symbol-value (car elem))))
8384 (when (and (or (consp val)
8386 (or (not gnus-inhibit-article-treatments)
8387 (eq gnus-treat-condition 'head))
8388 (gnus-treat-predicate val)
8389 (or (not (get (car elem) 'highlight))
8392 (funcall (cadr elem)))))))
8394 ;; Dynamic variables.
8395 (defvar part-number)
8396 (defvar total-parts)
8397 (defvar gnus-treat-type)
8398 (defvar gnus-treat-condition)
8399 (defvar gnus-treat-length)
8401 (defun gnus-treat-predicate (val)
8405 (gnus-treat-condition
8406 (eq gnus-treat-condition val))
8408 (stringp (car val)))
8409 (apply 'gnus-or (mapcar `(lambda (s)
8410 (string-match s ,(or gnus-newsgroup-name "")))
8413 (let ((pred (pop val)))
8416 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8418 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8420 (not (gnus-treat-predicate (car val))))
8422 (equal (car val) gnus-treat-type))
8424 (error "%S is not a valid predicate" pred)))))
8432 (eq part-number total-parts))
8434 (< gnus-treat-length val))
8436 (error "%S is not a valid value" val))))
8438 (defun gnus-article-encrypt-body (protocol &optional n)
8439 "Encrypt the article body."
8442 (or gnus-article-encrypt-protocol
8443 (gnus-completing-read "Encrypt protocol"
8444 (mapcar 'car gnus-article-encrypt-protocol-alist)
8446 current-prefix-arg))
8447 ;; User might hit `K E' instead of `K e', so prompt once.
8448 (when (and gnus-article-encrypt-protocol
8450 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8451 (error "Encrypt aborted")))
8452 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8454 (error "Can't find the encrypt protocol %s" protocol))
8455 (if (member gnus-newsgroup-name '("nndraft:delayed"
8458 (error "Can't encrypt the article in group %s"
8459 gnus-newsgroup-name))
8460 (gnus-summary-iterate n
8461 (with-current-buffer gnus-summary-buffer
8462 (let ((mail-parse-charset gnus-newsgroup-charset)
8463 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8464 (summary-buffer gnus-summary-buffer)
8466 (gnus-set-global-variables)
8467 (when (gnus-group-read-only-p)
8468 (error "The current newsgroup does not support article encrypt"))
8469 (gnus-summary-show-article t)
8471 (or (mail-header-references gnus-current-headers) ""))
8472 (set-buffer gnus-article-buffer)
8473 (let* ((inhibit-read-only t)
8475 (mapcar (lambda (field)
8476 (and (save-restriction
8477 (message-narrow-to-head)
8478 (goto-char (point-min))
8479 (search-forward field nil t))
8481 (message-narrow-to-field)
8483 (delete-region (point-min) (point-max))
8485 '("Content-Type:" "Content-Transfer-Encoding:"
8486 "Content-Disposition:"))))
8487 (message-narrow-to-head)
8488 (message-remove-header "MIME-Version")
8489 (goto-char (point-max))
8490 (setq point (point))
8491 (insert (apply 'concat headers))
8493 (narrow-to-region point (point-max))
8494 (let ((message-options message-options))
8495 (message-options-set 'message-sender user-mail-address)
8496 (message-options-set 'message-recipients user-mail-address)
8497 (message-options-set 'message-sign-encrypt 'not)
8499 (goto-char (point-min))
8500 (insert "MIME-Version: 1.0\n")
8502 (gnus-summary-edit-article-done
8503 references nil summary-buffer t))
8504 (when gnus-keep-backlog
8505 (gnus-backlog-remove-article
8506 (car gnus-article-current) (cdr gnus-article-current)))
8507 (gnus-flush-original-article-buffer)
8508 (when gnus-use-cache
8509 (gnus-cache-update-article
8510 (car gnus-article-current) (cdr gnus-article-current))))))))
8512 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8513 "The following specs can be used:
8514 %t The security MIME type
8517 %D Details if button is pressed")
8519 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8520 "The following specs can be used:
8521 %t The security MIME type
8524 %D Details if button is pressed")
8526 (defvar gnus-mime-security-button-line-format-alist
8527 '((?t gnus-tmp-type ?s)
8528 (?i gnus-tmp-info ?s)
8529 (?d gnus-tmp-details ?s)
8530 (?D gnus-tmp-pressed-details ?s)))
8532 (defvar gnus-mime-security-button-commands
8533 '((gnus-article-press-button "\r" "Show Detail")
8537 (gnus-mime-security-save-part "o" "Save...")
8546 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8549 (defvar gnus-mime-security-button-map
8550 (let ((map (make-sparse-keymap)))
8551 (define-key map gnus-mouse-2 'gnus-article-push-button)
8552 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8553 (dolist (c gnus-mime-security-button-commands)
8554 (define-key map (cadr c) (car c)))
8558 gnus-mime-security-button-menu gnus-mime-security-button-map
8559 "Security button menu."
8563 (unless (eq (car c) 'undefined)
8564 (vector (caddr c) (car c) :active t)))
8565 gnus-mime-security-button-commands))))
8567 (defun gnus-mime-security-button-menu (event prefix)
8568 "Construct a context-sensitive menu of security commands."
8569 (interactive "e\nP")
8570 (save-window-excursion
8571 (let ((pos (event-start event)))
8572 (select-window (posn-window pos))
8573 (goto-char (posn-point pos))
8574 (gnus-article-check-buffer)
8575 (popup-menu gnus-mime-security-button-menu nil prefix))))
8577 (defvar gnus-mime-security-details-buffer nil)
8579 (defvar gnus-mime-security-button-pressed nil)
8581 (defvar gnus-mime-security-show-details-inline t
8582 "If non-nil, show details in the article buffer.")
8584 (defun gnus-mime-security-verify-or-decrypt (handle)
8585 (mm-remove-parts (cdr handle))
8586 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8587 point (inhibit-read-only t))
8589 (goto-char (car region)))
8590 (setq point (point))
8591 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8592 (let* ((mm-verify-option 'known)
8593 (mm-decrypt-option 'known)
8594 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8595 (unless (eq nparts (cdr handle))
8596 (mm-destroy-parts (cdr handle))
8597 (setcdr handle nparts))))
8598 (gnus-mime-display-security handle)
8600 (delete-region (point) (cdr region))
8601 (set-marker (car region) nil)
8602 (set-marker (cdr region) nil))
8605 (defun gnus-mime-security-show-details (handle)
8606 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8608 (gnus-message 5 "No details.")
8609 (if gnus-mime-security-show-details-inline
8610 (let ((gnus-mime-security-button-pressed
8611 (not (get-text-property (point) 'gnus-mime-details)))
8612 (gnus-mime-security-button-line-format
8613 (get-text-property (point) 'gnus-line-format))
8614 (inhibit-read-only t))
8616 (while (eq (get-text-property (point) 'gnus-line-format)
8617 gnus-mime-security-button-line-format)
8621 (narrow-to-region (point) (point))
8622 (gnus-insert-mime-security-button handle))
8623 (delete-region (point)
8624 (or (text-property-not-all
8627 gnus-mime-security-button-line-format)
8630 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8631 (with-current-buffer gnus-mime-security-details-buffer
8634 (setq gnus-mime-security-details-buffer
8635 (gnus-get-buffer-create "*MIME Security Details*")))
8636 (with-current-buffer gnus-mime-security-details-buffer
8638 (goto-char (point-min)))
8639 (pop-to-buffer gnus-mime-security-details-buffer)))))
8641 (defun gnus-mime-security-press-button (handle)
8643 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8644 (gnus-mime-security-show-details handle)
8645 (gnus-mime-security-verify-or-decrypt handle))))
8647 (defun gnus-insert-mime-security-button (handle &optional displayed)
8648 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8651 (or (nth 2 (assoc protocol mm-verify-function-alist))
8652 (nth 2 (assoc protocol mm-decrypt-function-alist))
8654 (if (equal (car handle) "multipart/signed")
8655 " Signed" " Encrypted")
8658 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8661 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8662 gnus-tmp-pressed-details
8664 (setq gnus-tmp-details
8665 (if gnus-tmp-details
8666 (concat "\n" gnus-tmp-details)
8668 (setq gnus-tmp-pressed-details
8669 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8674 gnus-mime-security-button-line-format
8675 gnus-mime-security-button-line-format-alist
8676 `(keymap ,gnus-mime-security-button-map
8677 gnus-callback gnus-mime-security-press-button
8678 gnus-line-format ,gnus-mime-security-button-line-format
8679 gnus-mime-details ,gnus-mime-security-button-pressed
8680 article-type annotation
8683 ;; Exclude a newline.
8686 (when gnus-article-button-face
8687 (gnus-overlay-put (gnus-make-overlay b e nil t)
8688 'face gnus-article-button-face))
8689 (widget-convert-button
8692 :action 'gnus-widget-press-button
8693 :button-keymap gnus-mime-security-button-map
8696 ;; Needed to properly clear the message due to a bug in
8697 ;; wid-edit (XEmacs only).
8698 (when (boundp 'help-echo-owns-message)
8699 (setq help-echo-owns-message t))
8701 "%S: show detail; %S: more options"
8702 (aref gnus-mouse-2 0)
8703 (aref gnus-down-mouse-3 0))))))
8705 (defun gnus-mime-display-security (handle)
8707 (narrow-to-region (point) (point))
8708 (unless (gnus-unbuttonized-mime-type-p (car handle))
8709 (gnus-insert-mime-security-button handle))
8710 (gnus-mime-display-part (cadr handle))
8713 (unless (gnus-unbuttonized-mime-type-p (car handle))
8714 (let ((gnus-mime-security-button-line-format
8715 gnus-mime-security-button-end-line-format))
8716 (gnus-insert-mime-security-button handle)))
8717 (mm-set-handle-multipart-parameter
8719 (cons (set-marker (make-marker) (point-min))
8720 (set-marker (make-marker) (point-max))))
8721 (goto-char (point-max))))
8723 (defun gnus-mime-security-run-function (function)
8724 "Run FUNCTION with the security part under point."
8725 (gnus-article-check-buffer)
8726 (let ((data (get-text-property (point) 'gnus-data))
8728 (when (and (stringp (car-safe data))
8729 (setq buffer (mm-handle-multipart-original-buffer data))
8730 (setq handle (cadr data)))
8731 (if (bufferp (mm-handle-buffer handle))
8733 (setq handle (cons buffer (copy-sequence (cdr handle))))
8734 (mm-handle-set-undisplayer handle nil))
8735 (setq handle (mm-make-handle
8737 (mm-handle-multipart-ctl-parameter handle 'protocol)
8738 nil nil nil nil nil nil)))
8739 (funcall function handle))))
8741 (defun gnus-mime-security-save-part ()
8742 "Save the security part under point."
8744 (gnus-mime-security-run-function 'mm-save-part))
8746 (defun gnus-mime-security-pipe-part ()
8747 "Pipe the security part under point to a process."
8749 (gnus-mime-security-run-function 'mm-pipe-part))
8755 (run-hooks 'gnus-art-load-hook)
8757 ;;; gnus-art.el ends here